| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 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 | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 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> |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 24 | #include <linux/delay.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 26 | |
| 27 | #include <scsi/scsi.h> |
| 28 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 29 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <scsi/scsi_host.h> |
| 31 | #include <scsi/scsi_tcq.h> |
| 32 | #include <scsi/scsi_transport_fc.h> |
| 33 | |
| 34 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 35 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include "lpfc_hw.h" |
| 37 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 38 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 39 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | #include "lpfc_disc.h" |
| 41 | #include "lpfc_scsi.h" |
| 42 | #include "lpfc.h" |
| 43 | #include "lpfc_logmsg.h" |
| 44 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 45 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | |
| 47 | #define LPFC_RESET_WAIT 2 |
| 48 | #define LPFC_ABORT_WAIT 2 |
| 49 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 50 | int _dump_buf_done; |
| 51 | |
| 52 | static char *dif_op_str[] = { |
| 53 | "SCSI_PROT_NORMAL", |
| 54 | "SCSI_PROT_READ_INSERT", |
| 55 | "SCSI_PROT_WRITE_STRIP", |
| 56 | "SCSI_PROT_READ_STRIP", |
| 57 | "SCSI_PROT_WRITE_INSERT", |
| 58 | "SCSI_PROT_READ_PASS", |
| 59 | "SCSI_PROT_WRITE_PASS", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 60 | }; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 61 | static void |
| 62 | 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] | 63 | static void |
| 64 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 65 | |
| 66 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 67 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 68 | { |
| 69 | void *src, *dst; |
| 70 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 71 | |
| 72 | if (!_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 73 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 74 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 75 | __func__); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 81 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 82 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
| 86 | dst = (void *) _dump_buf_data; |
| 87 | while (sgde) { |
| 88 | src = sg_virt(sgde); |
| 89 | memcpy(dst, src, sgde->length); |
| 90 | dst += sgde->length; |
| 91 | sgde = sg_next(sgde); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 96 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 97 | { |
| 98 | void *src, *dst; |
| 99 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 100 | |
| 101 | if (!_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 102 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 103 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 104 | __func__); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 109 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 110 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 111 | return; |
| 112 | } |
| 113 | |
| 114 | dst = _dump_buf_dif; |
| 115 | while (sgde) { |
| 116 | src = sg_virt(sgde); |
| 117 | memcpy(dst, src, sgde->length); |
| 118 | dst += sgde->length; |
| 119 | sgde = sg_next(sgde); |
| 120 | } |
| 121 | } |
| 122 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 123 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 124 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 125 | * @phba: Pointer to HBA object. |
| 126 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 127 | * |
| 128 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 129 | * set the last bit in the response sge entry. |
| 130 | **/ |
| 131 | static void |
| 132 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
| 133 | struct lpfc_scsi_buf *lpfc_cmd) |
| 134 | { |
| 135 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 136 | if (sgl) { |
| 137 | sgl += 1; |
| 138 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 139 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 140 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 145 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 146 | * @phba: Pointer to HBA object. |
| 147 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 148 | * |
| 149 | * This function is called when there is a command completion and this |
| 150 | * function updates the statistical data for the command completion. |
| 151 | **/ |
| 152 | static void |
| 153 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 154 | { |
| 155 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 156 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 157 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 158 | unsigned long flags; |
| 159 | struct Scsi_Host *shost = cmd->device->host; |
| 160 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 161 | unsigned long latency; |
| 162 | int i; |
| 163 | |
| 164 | if (cmd->result) |
| 165 | return; |
| 166 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 167 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
| 168 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 169 | spin_lock_irqsave(shost->host_lock, flags); |
| 170 | if (!vport->stat_data_enabled || |
| 171 | vport->stat_data_blocked || |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 172 | !pnode || |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 173 | !pnode->lat_data || |
| 174 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
| 175 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 176 | return; |
| 177 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 178 | |
| 179 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 180 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 181 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 182 | /* check array subscript bounds */ |
| 183 | if (i < 0) |
| 184 | i = 0; |
| 185 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 186 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 187 | } else { |
| 188 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 189 | if (latency <= (phba->bucket_base + |
| 190 | ((1<<i)*phba->bucket_step))) |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | pnode->lat_data[i].cmd_count++; |
| 195 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 196 | } |
| 197 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 198 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 199 | * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 200 | * @phba: Pointer to HBA context object. |
| 201 | * @vport: Pointer to vport object. |
| 202 | * @ndlp: Pointer to FC node associated with the target. |
| 203 | * @lun: Lun number of the scsi device. |
| 204 | * @old_val: Old value of the queue depth. |
| 205 | * @new_val: New value of the queue depth. |
| 206 | * |
| 207 | * This function sends an event to the mgmt application indicating |
| 208 | * there is a change in the scsi device queue depth. |
| 209 | **/ |
| 210 | static void |
| 211 | lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba, |
| 212 | struct lpfc_vport *vport, |
| 213 | struct lpfc_nodelist *ndlp, |
| 214 | uint32_t lun, |
| 215 | uint32_t old_val, |
| 216 | uint32_t new_val) |
| 217 | { |
| 218 | struct lpfc_fast_path_event *fast_path_evt; |
| 219 | unsigned long flags; |
| 220 | |
| 221 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 222 | if (!fast_path_evt) |
| 223 | return; |
| 224 | |
| 225 | fast_path_evt->un.queue_depth_evt.scsi_event.event_type = |
| 226 | FC_REG_SCSI_EVENT; |
| 227 | fast_path_evt->un.queue_depth_evt.scsi_event.subcategory = |
| 228 | LPFC_EVENT_VARQUEDEPTH; |
| 229 | |
| 230 | /* Report all luns with change in queue depth */ |
| 231 | fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun; |
| 232 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
| 233 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn, |
| 234 | &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 235 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn, |
| 236 | &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 237 | } |
| 238 | |
| 239 | fast_path_evt->un.queue_depth_evt.oldval = old_val; |
| 240 | fast_path_evt->un.queue_depth_evt.newval = new_val; |
| 241 | fast_path_evt->vport = vport; |
| 242 | |
| 243 | fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 244 | spin_lock_irqsave(&phba->hbalock, flags); |
| 245 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 246 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 247 | lpfc_worker_wake_up(phba); |
| 248 | |
| 249 | return; |
| 250 | } |
| 251 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 252 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 253 | * lpfc_change_queue_depth - Alter scsi device queue depth |
| 254 | * @sdev: Pointer the scsi device on which to change the queue depth. |
| 255 | * @qdepth: New queue depth to set the sdev to. |
| 256 | * @reason: The reason for the queue depth change. |
| 257 | * |
| 258 | * This function is called by the midlayer and the LLD to alter the queue |
| 259 | * depth for a scsi device. This function sets the queue depth to the new |
| 260 | * value and sends an event out to log the queue depth change. |
| 261 | **/ |
| 262 | int |
| 263 | lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 264 | { |
| 265 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 266 | struct lpfc_hba *phba = vport->phba; |
| 267 | struct lpfc_rport_data *rdata; |
| 268 | unsigned long new_queue_depth, old_queue_depth; |
| 269 | |
| 270 | old_queue_depth = sdev->queue_depth; |
| 271 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 272 | new_queue_depth = sdev->queue_depth; |
| 273 | rdata = sdev->hostdata; |
| 274 | if (rdata) |
| 275 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
| 276 | rdata->pnode, sdev->lun, |
| 277 | old_queue_depth, |
| 278 | new_queue_depth); |
| 279 | return sdev->queue_depth; |
| 280 | } |
| 281 | |
| 282 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 283 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 284 | * @phba: The Hba for which this call is being executed. |
| 285 | * |
| 286 | * This routine is called when there is resource error in driver or firmware. |
| 287 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 288 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 289 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 290 | * |
| 291 | * This routine should be called with no lock held. |
| 292 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 293 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 294 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 295 | { |
| 296 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 297 | uint32_t evt_posted; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 298 | |
| 299 | spin_lock_irqsave(&phba->hbalock, flags); |
| 300 | atomic_inc(&phba->num_rsrc_err); |
| 301 | phba->last_rsrc_error_time = jiffies; |
| 302 | |
| 303 | if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) { |
| 304 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | phba->last_ramp_down_time = jiffies; |
| 309 | |
| 310 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 311 | |
| 312 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 313 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 314 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 315 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 316 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 317 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 318 | if (!evt_posted) |
| 319 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 320 | return; |
| 321 | } |
| 322 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 324 | * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 325 | * @phba: The Hba for which this call is being executed. |
| 326 | * |
| 327 | * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine |
| 328 | * post at most 1 event every 5 minute after last_ramp_up_time or |
| 329 | * last_rsrc_error_time. This routine wakes up worker thread of @phba |
| 330 | * to process WORKER_RAM_DOWN_EVENT event. |
| 331 | * |
| 332 | * This routine should be called with no lock held. |
| 333 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 334 | static inline void |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 335 | lpfc_rampup_queue_depth(struct lpfc_vport *vport, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 336 | uint32_t queue_depth) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 337 | { |
| 338 | unsigned long flags; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 339 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 340 | uint32_t evt_posted; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 341 | atomic_inc(&phba->num_cmd_success); |
| 342 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 343 | if (vport->cfg_lun_queue_depth <= queue_depth) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 344 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 346 | if (time_before(jiffies, |
| 347 | phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) || |
| 348 | time_before(jiffies, |
| 349 | phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 350 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 351 | return; |
| 352 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 353 | phba->last_ramp_up_time = jiffies; |
| 354 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 355 | |
| 356 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 357 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE; |
| 358 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 359 | phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 361 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 362 | if (!evt_posted) |
| 363 | lpfc_worker_wake_up(phba); |
| 364 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 365 | } |
| 366 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 367 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 368 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 369 | * @phba: The Hba for which this call is being executed. |
| 370 | * |
| 371 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 372 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 373 | * associated with @phba. |
| 374 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 375 | void |
| 376 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 377 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 378 | struct lpfc_vport **vports; |
| 379 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 381 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 382 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 383 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 384 | |
| 385 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 386 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 387 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 388 | vports = lpfc_create_vport_work_array(phba); |
| 389 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 390 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 391 | shost = lpfc_shost_from_vport(vports[i]); |
| 392 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 393 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 394 | sdev->queue_depth * num_rsrc_err / |
| 395 | (num_rsrc_err + num_cmd_success); |
| 396 | if (!new_queue_depth) |
| 397 | new_queue_depth = sdev->queue_depth - 1; |
| 398 | else |
| 399 | new_queue_depth = sdev->queue_depth - |
| 400 | new_queue_depth; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 401 | lpfc_change_queue_depth(sdev, new_queue_depth, |
| 402 | SCSI_QDEPTH_DEFAULT); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 403 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 404 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 405 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 406 | atomic_set(&phba->num_rsrc_err, 0); |
| 407 | atomic_set(&phba->num_cmd_success, 0); |
| 408 | } |
| 409 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 410 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 411 | * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 412 | * @phba: The Hba for which this call is being executed. |
| 413 | * |
| 414 | * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker |
| 415 | * thread.This routine increases queue depth for all scsi device on each vport |
| 416 | * associated with @phba by 1. This routine also sets @phba num_rsrc_err and |
| 417 | * num_cmd_success to zero. |
| 418 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 419 | void |
| 420 | lpfc_ramp_up_queue_handler(struct lpfc_hba *phba) |
| 421 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 422 | struct lpfc_vport **vports; |
| 423 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 424 | struct scsi_device *sdev; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 425 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 426 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 427 | vports = lpfc_create_vport_work_array(phba); |
| 428 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 429 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 430 | shost = lpfc_shost_from_vport(vports[i]); |
| 431 | shost_for_each_device(sdev, shost) { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 432 | if (vports[i]->cfg_lun_queue_depth <= |
| 433 | sdev->queue_depth) |
| 434 | continue; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 435 | lpfc_change_queue_depth(sdev, |
| 436 | sdev->queue_depth+1, |
| 437 | SCSI_QDEPTH_RAMP_UP); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 438 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 439 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 440 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 441 | atomic_set(&phba->num_rsrc_err, 0); |
| 442 | atomic_set(&phba->num_cmd_success, 0); |
| 443 | } |
| 444 | |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 445 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 446 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 447 | * @phba: Pointer to HBA context object. |
| 448 | * |
| 449 | * This function walks vport list and set each SCSI host to block state |
| 450 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 451 | * with EEH when device's PCI slot has been permanently disabled. |
| 452 | **/ |
| 453 | void |
| 454 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 455 | { |
| 456 | struct lpfc_vport **vports; |
| 457 | struct Scsi_Host *shost; |
| 458 | struct scsi_device *sdev; |
| 459 | struct fc_rport *rport; |
| 460 | int i; |
| 461 | |
| 462 | vports = lpfc_create_vport_work_array(phba); |
| 463 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 464 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 465 | shost = lpfc_shost_from_vport(vports[i]); |
| 466 | shost_for_each_device(sdev, shost) { |
| 467 | rport = starget_to_rport(scsi_target(sdev)); |
| 468 | fc_remote_port_delete(rport); |
| 469 | } |
| 470 | } |
| 471 | lpfc_destroy_vport_work_array(phba, vports); |
| 472 | } |
| 473 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 474 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 475 | * 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] | 476 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 477 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 478 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 479 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 480 | * the scsi buffer contains all the necessary information needed to initiate |
| 481 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 482 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 483 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 484 | * 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] | 485 | * |
| 486 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 487 | * int - number of scsi buffers that were allocated. |
| 488 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 489 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 490 | static int |
| 491 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 492 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 493 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 494 | struct lpfc_scsi_buf *psb; |
| 495 | struct ulp_bde64 *bpl; |
| 496 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 497 | dma_addr_t pdma_phys_fcp_cmd; |
| 498 | dma_addr_t pdma_phys_fcp_rsp; |
| 499 | dma_addr_t pdma_phys_bpl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 500 | uint16_t iotag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 501 | int bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 503 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 504 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 505 | if (!psb) |
| 506 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 508 | /* |
| 509 | * Get memory from the pci pool to map the virt space to pci |
| 510 | * bus space for an I/O. The DMA buffer includes space for the |
| 511 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 512 | * necessary to support the sg_tablesize. |
| 513 | */ |
| 514 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, |
| 515 | GFP_KERNEL, &psb->dma_handle); |
| 516 | if (!psb->data) { |
| 517 | kfree(psb); |
| 518 | break; |
| 519 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 520 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 521 | /* Initialize virtual ptrs to dma_buf region. */ |
| 522 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 523 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 524 | /* Allocate iotag for psb->cur_iocbq. */ |
| 525 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 526 | if (iotag == 0) { |
| 527 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 528 | psb->data, psb->dma_handle); |
| 529 | kfree(psb); |
| 530 | break; |
| 531 | } |
| 532 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 533 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 534 | psb->fcp_cmnd = psb->data; |
| 535 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 536 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 537 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 539 | /* Initialize local short-hand pointers. */ |
| 540 | bpl = psb->fcp_bpl; |
| 541 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 542 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
| 543 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
| 544 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 545 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 546 | /* |
| 547 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 548 | * are sg list bdes. Initialize the first two and leave the |
| 549 | * rest for queuecommand. |
| 550 | */ |
| 551 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 552 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 553 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 554 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 555 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 556 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 557 | /* Setup the physical region for the FCP RSP */ |
| 558 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 559 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 560 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 561 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 562 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 563 | |
| 564 | /* |
| 565 | * Since the IOCB for the FCP I/O is built into this |
| 566 | * lpfc_scsi_buf, initialize it with all known data now. |
| 567 | */ |
| 568 | iocb = &psb->cur_iocbq.iocb; |
| 569 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 570 | if ((phba->sli_rev == 3) && |
| 571 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 572 | /* fill in immediate fcp command BDE */ |
| 573 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 574 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 575 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 576 | unsli3.fcp_ext.icd); |
| 577 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 578 | iocb->ulpBdeCount = 0; |
| 579 | iocb->ulpLe = 0; |
| 580 | /* fill in responce BDE */ |
| 581 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 582 | BUFF_TYPE_BDE_64; |
| 583 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 584 | sizeof(struct fcp_rsp); |
| 585 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 586 | putPaddrLow(pdma_phys_fcp_rsp); |
| 587 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 588 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 589 | } else { |
| 590 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 591 | iocb->un.fcpi64.bdl.bdeSize = |
| 592 | (2 * sizeof(struct ulp_bde64)); |
| 593 | iocb->un.fcpi64.bdl.addrLow = |
| 594 | putPaddrLow(pdma_phys_bpl); |
| 595 | iocb->un.fcpi64.bdl.addrHigh = |
| 596 | putPaddrHigh(pdma_phys_bpl); |
| 597 | iocb->ulpBdeCount = 1; |
| 598 | iocb->ulpLe = 1; |
| 599 | } |
| 600 | iocb->ulpClass = CLASS3; |
| 601 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 602 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 603 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 604 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 605 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 606 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 607 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 608 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | } |
| 610 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 611 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 612 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 613 | * @phba: pointer to lpfc hba data structure. |
| 614 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 615 | * |
| 616 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 617 | * FCP aborted xri. |
| 618 | **/ |
| 619 | void |
| 620 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
| 621 | struct sli4_wcqe_xri_aborted *axri) |
| 622 | { |
| 623 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 624 | struct lpfc_scsi_buf *psb, *next_psb; |
| 625 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 626 | struct lpfc_iocbq *iocbq; |
| 627 | int i; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 628 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 629 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 630 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 631 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 632 | list_for_each_entry_safe(psb, next_psb, |
| 633 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 634 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 635 | list_del(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 636 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 637 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 638 | spin_unlock( |
| 639 | &phba->sli4_hba.abts_scsi_buf_list_lock); |
| 640 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 641 | lpfc_release_scsi_buf_s4(phba, psb); |
| 642 | return; |
| 643 | } |
| 644 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 645 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 646 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 647 | iocbq = phba->sli.iocbq_lookup[i]; |
| 648 | |
| 649 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 650 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 651 | continue; |
| 652 | if (iocbq->sli4_xritag != xri) |
| 653 | continue; |
| 654 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 655 | psb->exch_busy = 0; |
| 656 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 657 | if (pring->txq_cnt) |
| 658 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 659 | return; |
| 660 | |
| 661 | } |
| 662 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | /** |
| 666 | * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block |
| 667 | * @phba: pointer to lpfc hba data structure. |
| 668 | * |
| 669 | * This routine walks the list of scsi buffers that have been allocated and |
| 670 | * repost them to the HBA by using SGL block post. This is needed after a |
| 671 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 672 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list |
| 673 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. |
| 674 | * |
| 675 | * Returns: 0 = success, non-zero failure. |
| 676 | **/ |
| 677 | int |
| 678 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) |
| 679 | { |
| 680 | struct lpfc_scsi_buf *psb; |
| 681 | int index, status, bcnt = 0, rcnt = 0, rc = 0; |
| 682 | LIST_HEAD(sblist); |
| 683 | |
| 684 | for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) { |
| 685 | psb = phba->sli4_hba.lpfc_scsi_psb_array[index]; |
| 686 | if (psb) { |
| 687 | /* Remove from SCSI buffer list */ |
| 688 | list_del(&psb->list); |
| 689 | /* Add it to a local SCSI buffer list */ |
| 690 | list_add_tail(&psb->list, &sblist); |
| 691 | if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 692 | bcnt = rcnt; |
| 693 | rcnt = 0; |
| 694 | } |
| 695 | } else |
| 696 | /* A hole present in the XRI array, need to skip */ |
| 697 | bcnt = rcnt; |
| 698 | |
| 699 | if (index == phba->sli4_hba.scsi_xri_cnt - 1) |
| 700 | /* End of XRI array for SCSI buffer, complete */ |
| 701 | bcnt = rcnt; |
| 702 | |
| 703 | /* Continue until collect up to a nembed page worth of sgls */ |
| 704 | if (bcnt == 0) |
| 705 | continue; |
| 706 | /* Now, post the SCSI buffer list sgls as a block */ |
| 707 | status = lpfc_sli4_post_scsi_sgl_block(phba, &sblist, bcnt); |
| 708 | /* Reset SCSI buffer count for next round of posting */ |
| 709 | bcnt = 0; |
| 710 | while (!list_empty(&sblist)) { |
| 711 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, |
| 712 | list); |
| 713 | if (status) { |
| 714 | /* Put this back on the abort scsi list */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 715 | psb->exch_busy = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 716 | rc++; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 717 | } else { |
| 718 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 719 | psb->status = IOSTAT_SUCCESS; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 720 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 721 | /* Put it back into the SCSI buffer list */ |
| 722 | lpfc_release_scsi_buf_s4(phba, psb); |
| 723 | } |
| 724 | } |
| 725 | return rc; |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec |
| 730 | * @vport: The virtual port for which this call being executed. |
| 731 | * @num_to_allocate: The requested number of buffers to allocate. |
| 732 | * |
| 733 | * This routine allocates a scsi buffer for device with SLI-4 interface spec, |
| 734 | * the scsi buffer contains all the necessary information needed to initiate |
| 735 | * a SCSI I/O. |
| 736 | * |
| 737 | * Return codes: |
| 738 | * int - number of scsi buffers that were allocated. |
| 739 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 740 | **/ |
| 741 | static int |
| 742 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) |
| 743 | { |
| 744 | struct lpfc_hba *phba = vport->phba; |
| 745 | struct lpfc_scsi_buf *psb; |
| 746 | struct sli4_sge *sgl; |
| 747 | IOCB_t *iocb; |
| 748 | dma_addr_t pdma_phys_fcp_cmd; |
| 749 | dma_addr_t pdma_phys_fcp_rsp; |
| 750 | dma_addr_t pdma_phys_bpl, pdma_phys_bpl1; |
| 751 | uint16_t iotag, last_xritag = NO_XRI; |
| 752 | int status = 0, index; |
| 753 | int bcnt; |
| 754 | int non_sequential_xri = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 755 | LIST_HEAD(sblist); |
| 756 | |
| 757 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 758 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 759 | if (!psb) |
| 760 | break; |
| 761 | |
| 762 | /* |
| 763 | * Get memory from the pci pool to map the virt space to pci bus |
| 764 | * space for an I/O. The DMA buffer includes space for the |
| 765 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 766 | * necessary to support the sg_tablesize. |
| 767 | */ |
| 768 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, |
| 769 | GFP_KERNEL, &psb->dma_handle); |
| 770 | if (!psb->data) { |
| 771 | kfree(psb); |
| 772 | break; |
| 773 | } |
| 774 | |
| 775 | /* Initialize virtual ptrs to dma_buf region. */ |
| 776 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| 777 | |
| 778 | /* Allocate iotag for psb->cur_iocbq. */ |
| 779 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 780 | if (iotag == 0) { |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 781 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 782 | psb->data, psb->dma_handle); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 783 | kfree(psb); |
| 784 | break; |
| 785 | } |
| 786 | |
| 787 | psb->cur_iocbq.sli4_xritag = lpfc_sli4_next_xritag(phba); |
| 788 | if (psb->cur_iocbq.sli4_xritag == NO_XRI) { |
| 789 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 790 | psb->data, psb->dma_handle); |
| 791 | kfree(psb); |
| 792 | break; |
| 793 | } |
| 794 | if (last_xritag != NO_XRI |
| 795 | && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) { |
| 796 | non_sequential_xri = 1; |
| 797 | } else |
| 798 | list_add_tail(&psb->list, &sblist); |
| 799 | last_xritag = psb->cur_iocbq.sli4_xritag; |
| 800 | |
| 801 | index = phba->sli4_hba.scsi_xri_cnt++; |
| 802 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
| 803 | |
| 804 | psb->fcp_bpl = psb->data; |
| 805 | psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size) |
| 806 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 807 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + |
| 808 | sizeof(struct fcp_cmnd)); |
| 809 | |
| 810 | /* Initialize local short-hand pointers. */ |
| 811 | sgl = (struct sli4_sge *)psb->fcp_bpl; |
| 812 | pdma_phys_bpl = psb->dma_handle; |
| 813 | pdma_phys_fcp_cmd = |
| 814 | (psb->dma_handle + phba->cfg_sg_dma_buf_size) |
| 815 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 816 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 817 | |
| 818 | /* |
| 819 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 820 | * are sg list bdes. Initialize the first two and leave the |
| 821 | * rest for queuecommand. |
| 822 | */ |
| 823 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 824 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 825 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 826 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 827 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 828 | sgl++; |
| 829 | |
| 830 | /* Setup the physical region for the FCP RSP */ |
| 831 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 832 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 833 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 834 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 835 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 836 | |
| 837 | /* |
| 838 | * Since the IOCB for the FCP I/O is built into this |
| 839 | * lpfc_scsi_buf, initialize it with all known data now. |
| 840 | */ |
| 841 | iocb = &psb->cur_iocbq.iocb; |
| 842 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 843 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 844 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 845 | * We are setting the bpl to point to out sgl. An sgl's |
| 846 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 847 | */ |
| 848 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 849 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 850 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 851 | iocb->ulpBdeCount = 1; |
| 852 | iocb->ulpLe = 1; |
| 853 | iocb->ulpClass = CLASS3; |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 854 | psb->cur_iocbq.context1 = psb; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 855 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 856 | pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE; |
| 857 | else |
| 858 | pdma_phys_bpl1 = 0; |
| 859 | psb->dma_phys_bpl = pdma_phys_bpl; |
| 860 | phba->sli4_hba.lpfc_scsi_psb_array[index] = psb; |
| 861 | if (non_sequential_xri) { |
| 862 | status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl, |
| 863 | pdma_phys_bpl1, |
| 864 | psb->cur_iocbq.sli4_xritag); |
| 865 | if (status) { |
| 866 | /* Put this back on the abort scsi list */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 867 | psb->exch_busy = 1; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 868 | } else { |
| 869 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 870 | psb->status = IOSTAT_SUCCESS; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 871 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 872 | /* Put it back into the SCSI buffer list */ |
| 873 | lpfc_release_scsi_buf_s4(phba, psb); |
| 874 | break; |
| 875 | } |
| 876 | } |
| 877 | if (bcnt) { |
| 878 | status = lpfc_sli4_post_scsi_sgl_block(phba, &sblist, bcnt); |
| 879 | /* Reset SCSI buffer count for next round of posting */ |
| 880 | while (!list_empty(&sblist)) { |
| 881 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, |
| 882 | list); |
| 883 | if (status) { |
| 884 | /* Put this back on the abort scsi list */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 885 | psb->exch_busy = 1; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 886 | } else { |
| 887 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 888 | psb->status = IOSTAT_SUCCESS; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 889 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 890 | /* Put it back into the SCSI buffer list */ |
| 891 | lpfc_release_scsi_buf_s4(phba, psb); |
| 892 | } |
| 893 | } |
| 894 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 895 | return bcnt + non_sequential_xri; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 899 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
| 900 | * @vport: The virtual port for which this call being executed. |
| 901 | * @num_to_allocate: The requested number of buffers to allocate. |
| 902 | * |
| 903 | * This routine wraps the actual SCSI buffer allocator function pointer from |
| 904 | * the lpfc_hba struct. |
| 905 | * |
| 906 | * Return codes: |
| 907 | * int - number of scsi buffers that were allocated. |
| 908 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 909 | **/ |
| 910 | static inline int |
| 911 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) |
| 912 | { |
| 913 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); |
| 914 | } |
| 915 | |
| 916 | /** |
| 917 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 918 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 919 | * |
| 920 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 921 | * and returns to caller. |
| 922 | * |
| 923 | * Return codes: |
| 924 | * NULL - Error |
| 925 | * Pointer to lpfc_scsi_buf - Success |
| 926 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 927 | static struct lpfc_scsi_buf* |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 928 | lpfc_get_scsi_buf(struct lpfc_hba * phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 929 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 930 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
| 931 | struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 932 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 933 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 934 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 935 | list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 936 | if (lpfc_cmd) { |
| 937 | lpfc_cmd->seg_cnt = 0; |
| 938 | lpfc_cmd->nonsg_phys = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 939 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 940 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 941 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 942 | return lpfc_cmd; |
| 943 | } |
| 944 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 945 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 946 | * 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] | 947 | * @phba: The Hba for which this call is being executed. |
| 948 | * @psb: The scsi buffer which is being released. |
| 949 | * |
| 950 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 951 | * lpfc_scsi_buf_list list. |
| 952 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 953 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 954 | 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] | 955 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 956 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 957 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 958 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 959 | psb->pCmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 961 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 962 | } |
| 963 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 964 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 965 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 966 | * @phba: The Hba for which this call is being executed. |
| 967 | * @psb: The scsi buffer which is being released. |
| 968 | * |
| 969 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 970 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer |
| 971 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 972 | * aborted. |
| 973 | **/ |
| 974 | static void |
| 975 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 976 | { |
| 977 | unsigned long iflag = 0; |
| 978 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 979 | if (psb->exch_busy) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 980 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 981 | iflag); |
| 982 | psb->pCmd = NULL; |
| 983 | list_add_tail(&psb->list, |
| 984 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 985 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 986 | iflag); |
| 987 | } else { |
| 988 | |
| 989 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
| 990 | psb->pCmd = NULL; |
| 991 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
| 992 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 997 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 998 | * @phba: The Hba for which this call is being executed. |
| 999 | * @psb: The scsi buffer which is being released. |
| 1000 | * |
| 1001 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1002 | * lpfc_scsi_buf_list list. |
| 1003 | **/ |
| 1004 | static void |
| 1005 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1006 | { |
| 1007 | |
| 1008 | phba->lpfc_release_scsi_buf(phba, psb); |
| 1009 | } |
| 1010 | |
| 1011 | /** |
| 1012 | * 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] | 1013 | * @phba: The Hba for which this call is being executed. |
| 1014 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 1015 | * |
| 1016 | * 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] | 1017 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
| 1018 | * through sg elements and format the bdea. This routine also initializes all |
| 1019 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1020 | * |
| 1021 | * Return codes: |
| 1022 | * 1 - Error |
| 1023 | * 0 - Success |
| 1024 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1026 | 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] | 1027 | { |
| 1028 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1029 | struct scatterlist *sgel = NULL; |
| 1030 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1031 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1032 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1034 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1036 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1037 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | |
| 1039 | /* |
| 1040 | * There are three possibilities here - use scatter-gather segment, use |
| 1041 | * the single mapping, or neither. Start the lpfc command prep by |
| 1042 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 1043 | * data bde entry. |
| 1044 | */ |
| 1045 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1046 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | /* |
| 1048 | * The driver stores the segment count returned from pci_map_sg |
| 1049 | * because this a count of dma-mappings used to map the use_sg |
| 1050 | * pages. They are not guaranteed to be the same for those |
| 1051 | * architectures that implement an IOMMU. |
| 1052 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1054 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 1055 | scsi_sg_count(scsi_cmnd), datadir); |
| 1056 | if (unlikely(!nseg)) |
| 1057 | return 1; |
| 1058 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1059 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1061 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1062 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1063 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1064 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 | lpfc_cmd->seg_cnt); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1066 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | return 1; |
| 1068 | } |
| 1069 | |
| 1070 | /* |
| 1071 | * The driver established a maximum scatter-gather segment count |
| 1072 | * during probe that limits the number of sg elements in any |
| 1073 | * single scsi command. Just run through the seg_cnt and format |
| 1074 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1075 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 1076 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 1077 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1079 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1081 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1082 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1083 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1084 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 1085 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1086 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 1087 | data_bde->addrLow = putPaddrLow(physaddr); |
| 1088 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1089 | data_bde++; |
| 1090 | } else { |
| 1091 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1092 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 1093 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1094 | bpl->addrLow = |
| 1095 | le32_to_cpu(putPaddrLow(physaddr)); |
| 1096 | bpl->addrHigh = |
| 1097 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 1098 | bpl++; |
| 1099 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1100 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1101 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | |
| 1103 | /* |
| 1104 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1105 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 1106 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 1107 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1108 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1109 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1110 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 1111 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1112 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 1113 | /* |
| 1114 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 1115 | * This I/O has more than 3 BDE so the 1st data bde will |
| 1116 | * be a BPL that is filled in here. |
| 1117 | */ |
| 1118 | physaddr = lpfc_cmd->dma_handle; |
| 1119 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 1120 | data_bde->tus.f.bdeSize = (num_bde * |
| 1121 | sizeof(struct ulp_bde64)); |
| 1122 | physaddr += (sizeof(struct fcp_cmnd) + |
| 1123 | sizeof(struct fcp_rsp) + |
| 1124 | (2 * sizeof(struct ulp_bde64))); |
| 1125 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1126 | data_bde->addrLow = putPaddrLow(physaddr); |
| 1127 | /* ebde count includes the responce bde and data bpl */ |
| 1128 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 1129 | } else { |
| 1130 | /* ebde count includes the responce bde and data bdes */ |
| 1131 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1132 | } |
| 1133 | } else { |
| 1134 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1135 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1136 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1137 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1138 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1139 | |
| 1140 | /* |
| 1141 | * Due to difference in data length between DIF/non-DIF paths, |
| 1142 | * we need to set word 4 of IOCB here |
| 1143 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1144 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1145 | return 0; |
| 1146 | } |
| 1147 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1148 | /* |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1149 | * Given a scsi cmnd, determine the BlockGuard opcodes to be used with it |
| 1150 | * @sc: The SCSI command to examine |
| 1151 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1152 | * @rxopt: (out) BlockGuard operation for received data |
| 1153 | * |
| 1154 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1155 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1156 | */ |
| 1157 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1158 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1159 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1160 | { |
| 1161 | uint8_t guard_type = scsi_host_get_guard(sc->device->host); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1162 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1163 | |
| 1164 | if (guard_type == SHOST_DIX_GUARD_IP) { |
| 1165 | switch (scsi_get_prot_op(sc)) { |
| 1166 | case SCSI_PROT_READ_INSERT: |
| 1167 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1168 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
| 1169 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1170 | break; |
| 1171 | |
| 1172 | case SCSI_PROT_READ_STRIP: |
| 1173 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1174 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
| 1175 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1176 | break; |
| 1177 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1178 | case SCSI_PROT_READ_PASS: |
| 1179 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1180 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
| 1181 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1182 | break; |
| 1183 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1184 | case SCSI_PROT_NORMAL: |
| 1185 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1186 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1187 | "9063 BLKGRD: Bad op/guard:%d/%d combination\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1188 | scsi_get_prot_op(sc), guard_type); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1189 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1190 | break; |
| 1191 | |
| 1192 | } |
| 1193 | } else if (guard_type == SHOST_DIX_GUARD_CRC) { |
| 1194 | switch (scsi_get_prot_op(sc)) { |
| 1195 | case SCSI_PROT_READ_STRIP: |
| 1196 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1197 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
| 1198 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1199 | break; |
| 1200 | |
| 1201 | case SCSI_PROT_READ_PASS: |
| 1202 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1203 | *txop = BG_OP_IN_CRC_OUT_CRC; |
| 1204 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1205 | break; |
| 1206 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1207 | case SCSI_PROT_READ_INSERT: |
| 1208 | case SCSI_PROT_WRITE_STRIP: |
| 1209 | case SCSI_PROT_NORMAL: |
| 1210 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1211 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1212 | "9075 BLKGRD: Bad op/guard:%d/%d combination\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1213 | scsi_get_prot_op(sc), guard_type); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1214 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1215 | break; |
| 1216 | } |
| 1217 | } else { |
| 1218 | /* unsupported format */ |
| 1219 | BUG(); |
| 1220 | } |
| 1221 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1222 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | struct scsi_dif_tuple { |
| 1226 | __be16 guard_tag; /* Checksum */ |
| 1227 | __be16 app_tag; /* Opaque storage */ |
| 1228 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 1229 | }; |
| 1230 | |
| 1231 | static inline unsigned |
| 1232 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 1233 | { |
| 1234 | return sc->device->sector_size; |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * lpfc_get_cmd_dif_parms - Extract DIF parameters from SCSI command |
| 1239 | * @sc: in: SCSI command |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1240 | * @apptagmask: out: app tag mask |
| 1241 | * @apptagval: out: app tag value |
| 1242 | * @reftag: out: ref tag (reference tag) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1243 | * |
| 1244 | * Description: |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 1245 | * Extract DIF parameters from the command if possible. Otherwise, |
| 1246 | * use default parameters. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1247 | * |
| 1248 | **/ |
| 1249 | static inline void |
| 1250 | lpfc_get_cmd_dif_parms(struct scsi_cmnd *sc, uint16_t *apptagmask, |
| 1251 | uint16_t *apptagval, uint32_t *reftag) |
| 1252 | { |
| 1253 | struct scsi_dif_tuple *spt; |
| 1254 | unsigned char op = scsi_get_prot_op(sc); |
| 1255 | unsigned int protcnt = scsi_prot_sg_count(sc); |
| 1256 | static int cnt; |
| 1257 | |
| 1258 | if (protcnt && (op == SCSI_PROT_WRITE_STRIP || |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1259 | op == SCSI_PROT_WRITE_PASS)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1260 | |
| 1261 | cnt++; |
| 1262 | spt = page_address(sg_page(scsi_prot_sglist(sc))) + |
| 1263 | scsi_prot_sglist(sc)[0].offset; |
| 1264 | *apptagmask = 0; |
| 1265 | *apptagval = 0; |
| 1266 | *reftag = cpu_to_be32(spt->ref_tag); |
| 1267 | |
| 1268 | } else { |
| 1269 | /* SBC defines ref tag to be lower 32bits of LBA */ |
| 1270 | *reftag = (uint32_t) (0xffffffff & scsi_get_lba(sc)); |
| 1271 | *apptagmask = 0; |
| 1272 | *apptagval = 0; |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * This function sets up buffer list for protection groups of |
| 1278 | * type LPFC_PG_TYPE_NO_DIF |
| 1279 | * |
| 1280 | * This is usually used when the HBA is instructed to generate |
| 1281 | * DIFs and insert them into data stream (or strip DIF from |
| 1282 | * incoming data stream) |
| 1283 | * |
| 1284 | * The buffer list consists of just one protection group described |
| 1285 | * below: |
| 1286 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1287 | * start of prot group --> | PDE_5 | |
| 1288 | * +-------------------------+ |
| 1289 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1290 | * +-------------------------+ |
| 1291 | * | Data BDE | |
| 1292 | * +-------------------------+ |
| 1293 | * |more Data BDE's ... (opt)| |
| 1294 | * +-------------------------+ |
| 1295 | * |
| 1296 | * @sc: pointer to scsi command we're working on |
| 1297 | * @bpl: pointer to buffer list for protection groups |
| 1298 | * @datacnt: number of segments of data that have been dma mapped |
| 1299 | * |
| 1300 | * Note: Data s/g buffers have been dma mapped |
| 1301 | */ |
| 1302 | static int |
| 1303 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1304 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1305 | { |
| 1306 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1307 | struct lpfc_pde5 *pde5 = NULL; |
| 1308 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1309 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1310 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1311 | int datadir = sc->sc_data_direction; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1312 | unsigned blksize; |
| 1313 | uint32_t reftag; |
| 1314 | uint16_t apptagmask, apptagval; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1315 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1316 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1317 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1318 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1319 | goto out; |
| 1320 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1321 | /* extract some info from the scsi command for pde*/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1322 | blksize = lpfc_cmd_blksize(sc); |
| 1323 | lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag); |
| 1324 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1325 | /* setup PDE5 with what we have */ |
| 1326 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1327 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1328 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
| 1329 | pde5->reftag = reftag; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1330 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1331 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1332 | pde5->word0 = cpu_to_le32(pde5->word0); |
| 1333 | pde5->reftag = cpu_to_le32(pde5->reftag); |
| 1334 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1335 | /* advance bpl and increment bde count */ |
| 1336 | num_bde++; |
| 1337 | bpl++; |
| 1338 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1339 | |
| 1340 | /* setup PDE6 with the rest of the info */ |
| 1341 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1342 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1343 | bf_set(pde6_optx, pde6, txop); |
| 1344 | bf_set(pde6_oprx, pde6, rxop); |
| 1345 | if (datadir == DMA_FROM_DEVICE) { |
| 1346 | bf_set(pde6_ce, pde6, 1); |
| 1347 | bf_set(pde6_re, pde6, 1); |
| 1348 | bf_set(pde6_ae, pde6, 1); |
| 1349 | } |
| 1350 | bf_set(pde6_ai, pde6, 1); |
| 1351 | bf_set(pde6_apptagval, pde6, apptagval); |
| 1352 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1353 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1354 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1355 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1356 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1357 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1358 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1359 | num_bde++; |
| 1360 | bpl++; |
| 1361 | |
| 1362 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1363 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1364 | physaddr = sg_dma_address(sgde); |
| 1365 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1366 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1367 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1368 | if (datadir == DMA_TO_DEVICE) |
| 1369 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1370 | else |
| 1371 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1372 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1373 | bpl++; |
| 1374 | num_bde++; |
| 1375 | } |
| 1376 | |
| 1377 | out: |
| 1378 | return num_bde; |
| 1379 | } |
| 1380 | |
| 1381 | /* |
| 1382 | * This function sets up buffer list for protection groups of |
| 1383 | * type LPFC_PG_TYPE_DIF_BUF |
| 1384 | * |
| 1385 | * This is usually used when DIFs are in their own buffers, |
| 1386 | * separate from the data. The HBA can then by instructed |
| 1387 | * to place the DIFs in the outgoing stream. For read operations, |
| 1388 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1389 | * |
| 1390 | * The buffer list for this type consists of one or more of the |
| 1391 | * protection groups described below: |
| 1392 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1393 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1394 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1395 | * | PDE_6 | |
| 1396 | * +-------------------------+ |
| 1397 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1398 | * +-------------------------+ |
| 1399 | * | Data BDE | |
| 1400 | * +-------------------------+ |
| 1401 | * |more Data BDE's ... (opt)| |
| 1402 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1403 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1404 | * +-------------------------+ |
| 1405 | * | ... | |
| 1406 | * +-------------------------+ |
| 1407 | * |
| 1408 | * @sc: pointer to scsi command we're working on |
| 1409 | * @bpl: pointer to buffer list for protection groups |
| 1410 | * @datacnt: number of segments of data that have been dma mapped |
| 1411 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1412 | * |
| 1413 | * Note: It is assumed that both data and protection s/g buffers have been |
| 1414 | * mapped for DMA |
| 1415 | */ |
| 1416 | static int |
| 1417 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1418 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 1419 | { |
| 1420 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 1421 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1422 | struct lpfc_pde5 *pde5 = NULL; |
| 1423 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1424 | struct ulp_bde64 *prot_bde = NULL; |
| 1425 | dma_addr_t dataphysaddr, protphysaddr; |
| 1426 | unsigned short curr_data = 0, curr_prot = 0; |
| 1427 | unsigned int split_offset, protgroup_len; |
| 1428 | unsigned int protgrp_blks, protgrp_bytes; |
| 1429 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1430 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1431 | int datadir = sc->sc_data_direction; |
| 1432 | unsigned char pgdone = 0, alldone = 0; |
| 1433 | unsigned blksize; |
| 1434 | uint32_t reftag; |
| 1435 | uint16_t apptagmask, apptagval; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1436 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1437 | int num_bde = 0; |
| 1438 | |
| 1439 | sgpe = scsi_prot_sglist(sc); |
| 1440 | sgde = scsi_sglist(sc); |
| 1441 | |
| 1442 | if (!sgpe || !sgde) { |
| 1443 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1444 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 1445 | sgpe, sgde); |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1449 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1450 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1451 | goto out; |
| 1452 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1453 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1454 | blksize = lpfc_cmd_blksize(sc); |
| 1455 | lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag); |
| 1456 | |
| 1457 | split_offset = 0; |
| 1458 | do { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1459 | /* setup PDE5 with what we have */ |
| 1460 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1461 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1462 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
| 1463 | pde5->reftag = reftag; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1464 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1465 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1466 | pde5->word0 = cpu_to_le32(pde5->word0); |
| 1467 | pde5->reftag = cpu_to_le32(pde5->reftag); |
| 1468 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1469 | /* advance bpl and increment bde count */ |
| 1470 | num_bde++; |
| 1471 | bpl++; |
| 1472 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1473 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1474 | /* setup PDE6 with the rest of the info */ |
| 1475 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1476 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1477 | bf_set(pde6_optx, pde6, txop); |
| 1478 | bf_set(pde6_oprx, pde6, rxop); |
| 1479 | bf_set(pde6_ce, pde6, 1); |
| 1480 | bf_set(pde6_re, pde6, 1); |
| 1481 | bf_set(pde6_ae, pde6, 1); |
| 1482 | bf_set(pde6_ai, pde6, 1); |
| 1483 | bf_set(pde6_apptagval, pde6, apptagval); |
| 1484 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1485 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1486 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1487 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1488 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1489 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1490 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1491 | num_bde++; |
| 1492 | bpl++; |
| 1493 | |
| 1494 | /* setup the first BDE that points to protection buffer */ |
| 1495 | prot_bde = (struct ulp_bde64 *) bpl; |
| 1496 | protphysaddr = sg_dma_address(sgpe); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1497 | prot_bde->addrHigh = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 1498 | prot_bde->addrLow = le32_to_cpu(putPaddrHigh(protphysaddr)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1499 | protgroup_len = sg_dma_len(sgpe); |
| 1500 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1501 | /* must be integer multiple of the DIF block length */ |
| 1502 | BUG_ON(protgroup_len % 8); |
| 1503 | |
| 1504 | protgrp_blks = protgroup_len / 8; |
| 1505 | protgrp_bytes = protgrp_blks * blksize; |
| 1506 | |
| 1507 | prot_bde->tus.f.bdeSize = protgroup_len; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1508 | prot_bde->tus.f.bdeFlags = LPFC_PDE7_DESCRIPTOR; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1509 | prot_bde->tus.w = le32_to_cpu(bpl->tus.w); |
| 1510 | |
| 1511 | curr_prot++; |
| 1512 | num_bde++; |
| 1513 | |
| 1514 | /* setup BDE's for data blocks associated with DIF data */ |
| 1515 | pgdone = 0; |
| 1516 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 1517 | while (!pgdone) { |
| 1518 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1519 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1520 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1521 | __func__); |
| 1522 | return 0; |
| 1523 | } |
| 1524 | bpl++; |
| 1525 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 1526 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 1527 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 1528 | |
| 1529 | remainder = sg_dma_len(sgde) - split_offset; |
| 1530 | |
| 1531 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 1532 | /* we can use this whole buffer */ |
| 1533 | bpl->tus.f.bdeSize = remainder; |
| 1534 | split_offset = 0; |
| 1535 | |
| 1536 | if ((subtotal + remainder) == protgrp_bytes) |
| 1537 | pgdone = 1; |
| 1538 | } else { |
| 1539 | /* must split this buffer with next prot grp */ |
| 1540 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 1541 | split_offset += bpl->tus.f.bdeSize; |
| 1542 | } |
| 1543 | |
| 1544 | subtotal += bpl->tus.f.bdeSize; |
| 1545 | |
| 1546 | if (datadir == DMA_TO_DEVICE) |
| 1547 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1548 | else |
| 1549 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1550 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1551 | |
| 1552 | num_bde++; |
| 1553 | curr_data++; |
| 1554 | |
| 1555 | if (split_offset) |
| 1556 | break; |
| 1557 | |
| 1558 | /* Move to the next s/g segment if possible */ |
| 1559 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1560 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | /* are we done ? */ |
| 1564 | if (curr_prot == protcnt) { |
| 1565 | alldone = 1; |
| 1566 | } else if (curr_prot < protcnt) { |
| 1567 | /* advance to next prot buffer */ |
| 1568 | sgpe = sg_next(sgpe); |
| 1569 | bpl++; |
| 1570 | |
| 1571 | /* update the reference tag */ |
| 1572 | reftag += protgrp_blks; |
| 1573 | } else { |
| 1574 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1575 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1576 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | } while (!alldone); |
| 1580 | |
| 1581 | out: |
| 1582 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1583 | return num_bde; |
| 1584 | } |
| 1585 | /* |
| 1586 | * Given a SCSI command that supports DIF, determine composition of protection |
| 1587 | * groups involved in setting up buffer lists |
| 1588 | * |
| 1589 | * Returns: |
| 1590 | * for DIF (for both read and write) |
| 1591 | * */ |
| 1592 | static int |
| 1593 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 1594 | { |
| 1595 | int ret = LPFC_PG_TYPE_INVALID; |
| 1596 | unsigned char op = scsi_get_prot_op(sc); |
| 1597 | |
| 1598 | switch (op) { |
| 1599 | case SCSI_PROT_READ_STRIP: |
| 1600 | case SCSI_PROT_WRITE_INSERT: |
| 1601 | ret = LPFC_PG_TYPE_NO_DIF; |
| 1602 | break; |
| 1603 | case SCSI_PROT_READ_INSERT: |
| 1604 | case SCSI_PROT_WRITE_STRIP: |
| 1605 | case SCSI_PROT_READ_PASS: |
| 1606 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1607 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 1608 | break; |
| 1609 | default: |
| 1610 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1611 | "9021 Unsupported protection op:%d\n", op); |
| 1612 | break; |
| 1613 | } |
| 1614 | |
| 1615 | return ret; |
| 1616 | } |
| 1617 | |
| 1618 | /* |
| 1619 | * This is the protection/DIF aware version of |
| 1620 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 1621 | * two functions eventually, but for now, it's here |
| 1622 | */ |
| 1623 | static int |
| 1624 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, |
| 1625 | struct lpfc_scsi_buf *lpfc_cmd) |
| 1626 | { |
| 1627 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1628 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1629 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 1630 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 1631 | uint32_t num_bde = 0; |
| 1632 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 1633 | int prot_group_type = 0; |
| 1634 | int diflen, fcpdl; |
| 1635 | unsigned blksize; |
| 1636 | |
| 1637 | /* |
| 1638 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 1639 | * fcp_rsp regions to the first data bde entry |
| 1640 | */ |
| 1641 | bpl += 2; |
| 1642 | if (scsi_sg_count(scsi_cmnd)) { |
| 1643 | /* |
| 1644 | * The driver stores the segment count returned from pci_map_sg |
| 1645 | * because this a count of dma-mappings used to map the use_sg |
| 1646 | * pages. They are not guaranteed to be the same for those |
| 1647 | * architectures that implement an IOMMU. |
| 1648 | */ |
| 1649 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 1650 | scsi_sglist(scsi_cmnd), |
| 1651 | scsi_sg_count(scsi_cmnd), datadir); |
| 1652 | if (unlikely(!datasegcnt)) |
| 1653 | return 1; |
| 1654 | |
| 1655 | lpfc_cmd->seg_cnt = datasegcnt; |
| 1656 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1657 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1658 | "9067 BLKGRD: %s: Too many sg segments" |
| 1659 | " from dma_map_sg. Config %d, seg_cnt" |
| 1660 | " %d\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1661 | __func__, phba->cfg_sg_seg_cnt, |
| 1662 | lpfc_cmd->seg_cnt); |
| 1663 | scsi_dma_unmap(scsi_cmnd); |
| 1664 | return 1; |
| 1665 | } |
| 1666 | |
| 1667 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 1668 | |
| 1669 | switch (prot_group_type) { |
| 1670 | case LPFC_PG_TYPE_NO_DIF: |
| 1671 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 1672 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 1673 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1674 | if (num_bde < 2) |
| 1675 | goto err; |
| 1676 | break; |
| 1677 | case LPFC_PG_TYPE_DIF_BUF:{ |
| 1678 | /* |
| 1679 | * This type indicates that protection buffers are |
| 1680 | * passed to the driver, so that needs to be prepared |
| 1681 | * for DMA |
| 1682 | */ |
| 1683 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 1684 | scsi_prot_sglist(scsi_cmnd), |
| 1685 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 1686 | if (unlikely(!protsegcnt)) { |
| 1687 | scsi_dma_unmap(scsi_cmnd); |
| 1688 | return 1; |
| 1689 | } |
| 1690 | |
| 1691 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
| 1692 | if (lpfc_cmd->prot_seg_cnt |
| 1693 | > phba->cfg_prot_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1694 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1695 | "9068 BLKGRD: %s: Too many prot sg " |
| 1696 | "segments from dma_map_sg. Config %d," |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1697 | "prot_seg_cnt %d\n", __func__, |
| 1698 | phba->cfg_prot_sg_seg_cnt, |
| 1699 | lpfc_cmd->prot_seg_cnt); |
| 1700 | dma_unmap_sg(&phba->pcidev->dev, |
| 1701 | scsi_prot_sglist(scsi_cmnd), |
| 1702 | scsi_prot_sg_count(scsi_cmnd), |
| 1703 | datadir); |
| 1704 | scsi_dma_unmap(scsi_cmnd); |
| 1705 | return 1; |
| 1706 | } |
| 1707 | |
| 1708 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 1709 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 1710 | /* we should have 3 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1711 | if (num_bde < 3) |
| 1712 | goto err; |
| 1713 | break; |
| 1714 | } |
| 1715 | case LPFC_PG_TYPE_INVALID: |
| 1716 | default: |
| 1717 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1718 | "9022 Unexpected protection group %i\n", |
| 1719 | prot_group_type); |
| 1720 | return 1; |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | /* |
| 1725 | * Finish initializing those IOCB fields that are dependent on the |
| 1726 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 1727 | * reinitialized since all iocb memory resources are used many times |
| 1728 | * for transmit, receive, and continuation bpl's. |
| 1729 | */ |
| 1730 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 1731 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 1732 | iocb_cmd->ulpBdeCount = 1; |
| 1733 | iocb_cmd->ulpLe = 1; |
| 1734 | |
| 1735 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 1736 | |
| 1737 | if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) { |
| 1738 | /* |
| 1739 | * We are in DIF Type 1 mode |
| 1740 | * Every data block has a 8 byte DIF (trailer) |
| 1741 | * attached to it. Must ajust FCP data length |
| 1742 | */ |
| 1743 | blksize = lpfc_cmd_blksize(scsi_cmnd); |
| 1744 | diflen = (fcpdl / blksize) * 8; |
| 1745 | fcpdl += diflen; |
| 1746 | } |
| 1747 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 1748 | |
| 1749 | /* |
| 1750 | * Due to difference in data length between DIF/non-DIF paths, |
| 1751 | * we need to set word 4 of IOCB here |
| 1752 | */ |
| 1753 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 1754 | |
| 1755 | return 0; |
| 1756 | err: |
| 1757 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1758 | "9023 Could not setup all needed BDE's" |
| 1759 | "prot_group_type=%d, num_bde=%d\n", |
| 1760 | prot_group_type, num_bde); |
| 1761 | return 1; |
| 1762 | } |
| 1763 | |
| 1764 | /* |
| 1765 | * This function checks for BlockGuard errors detected by |
| 1766 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 1767 | * sense buffer will be set accordingly, paired with |
| 1768 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 1769 | * detected corruption. |
| 1770 | * |
| 1771 | * Returns: |
| 1772 | * 0 - No error found |
| 1773 | * 1 - BlockGuard error found |
| 1774 | * -1 - Internal error (bad profile, ...etc) |
| 1775 | */ |
| 1776 | static int |
| 1777 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 1778 | struct lpfc_iocbq *pIocbOut) |
| 1779 | { |
| 1780 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 1781 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 1782 | int ret = 0; |
| 1783 | uint32_t bghm = bgf->bghm; |
| 1784 | uint32_t bgstat = bgf->bgstat; |
| 1785 | uint64_t failing_sector = 0; |
| 1786 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1787 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9069 BLKGRD: BG ERROR in cmd" |
| 1788 | " 0x%x lba 0x%llx blk cnt 0x%x " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1789 | "bgstat=0x%x bghm=0x%x\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 1790 | cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 1791 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1792 | |
| 1793 | spin_lock(&_dump_buf_lock); |
| 1794 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1795 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 1796 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1797 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1798 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1799 | |
| 1800 | /* If we have a prot sgl, save the DIF buffer */ |
| 1801 | if (lpfc_prot_group_type(phba, cmd) == |
| 1802 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1803 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 1804 | "Saving DIF for %u blocks to debugfs\n", |
| 1805 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 1806 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | _dump_buf_done = 1; |
| 1810 | } |
| 1811 | spin_unlock(&_dump_buf_lock); |
| 1812 | |
| 1813 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
| 1814 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1815 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9072 BLKGRD: Invalid" |
| 1816 | " BlockGuard profile. bgstat:0x%x\n", |
| 1817 | bgstat); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1818 | ret = (-1); |
| 1819 | goto out; |
| 1820 | } |
| 1821 | |
| 1822 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
| 1823 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1824 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9073 BLKGRD: " |
| 1825 | "Invalid BlockGuard DIF Block. bgstat:0x%x\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1826 | bgstat); |
| 1827 | ret = (-1); |
| 1828 | goto out; |
| 1829 | } |
| 1830 | |
| 1831 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 1832 | ret = 1; |
| 1833 | |
| 1834 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 1835 | 0x10, 0x1); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 1836 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1837 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 1838 | phba->bg_guard_err_cnt++; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1839 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1840 | "9055 BLKGRD: guard_tag error\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 1844 | ret = 1; |
| 1845 | |
| 1846 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 1847 | 0x10, 0x3); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 1848 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1849 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 1850 | |
| 1851 | phba->bg_reftag_err_cnt++; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1852 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1853 | "9056 BLKGRD: ref_tag error\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 1857 | ret = 1; |
| 1858 | |
| 1859 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 1860 | 0x10, 0x2); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 1861 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1862 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 1863 | |
| 1864 | phba->bg_apptag_err_cnt++; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1865 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1866 | "9061 BLKGRD: app_tag error\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 1870 | /* |
| 1871 | * setup sense data descriptor 0 per SPC-4 as an information |
| 1872 | * field, and put the failing LBA in it |
| 1873 | */ |
| 1874 | cmd->sense_buffer[8] = 0; /* Information */ |
| 1875 | cmd->sense_buffer[9] = 0xa; /* Add. length */ |
David Howells | 2344b5b | 2009-04-14 17:08:34 +0100 | [diff] [blame] | 1876 | bghm /= cmd->device->sector_size; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1877 | |
| 1878 | failing_sector = scsi_get_lba(cmd); |
| 1879 | failing_sector += bghm; |
| 1880 | |
| 1881 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[10]); |
| 1882 | } |
| 1883 | |
| 1884 | if (!ret) { |
| 1885 | /* No error was reported - problem in FW? */ |
| 1886 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1887 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1888 | "9057 BLKGRD: no errors reported!\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | out: |
| 1892 | return ret; |
| 1893 | } |
| 1894 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1895 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1896 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 1897 | * @phba: The Hba for which this call is being executed. |
| 1898 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 1899 | * |
| 1900 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 1901 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 1902 | * |
| 1903 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1904 | * 1 - Error |
| 1905 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1906 | **/ |
| 1907 | static int |
| 1908 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 1909 | { |
| 1910 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1911 | struct scatterlist *sgel = NULL; |
| 1912 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1913 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 1914 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 1915 | dma_addr_t physaddr; |
| 1916 | uint32_t num_bde = 0; |
| 1917 | uint32_t dma_len; |
| 1918 | uint32_t dma_offset = 0; |
| 1919 | int nseg; |
| 1920 | |
| 1921 | /* |
| 1922 | * There are three possibilities here - use scatter-gather segment, use |
| 1923 | * the single mapping, or neither. Start the lpfc command prep by |
| 1924 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 1925 | * data bde entry. |
| 1926 | */ |
| 1927 | if (scsi_sg_count(scsi_cmnd)) { |
| 1928 | /* |
| 1929 | * The driver stores the segment count returned from pci_map_sg |
| 1930 | * because this a count of dma-mappings used to map the use_sg |
| 1931 | * pages. They are not guaranteed to be the same for those |
| 1932 | * architectures that implement an IOMMU. |
| 1933 | */ |
| 1934 | |
| 1935 | nseg = scsi_dma_map(scsi_cmnd); |
| 1936 | if (unlikely(!nseg)) |
| 1937 | return 1; |
| 1938 | sgl += 1; |
| 1939 | /* clear the last flag in the fcp_rsp map entry */ |
| 1940 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 1941 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 1942 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 1943 | sgl += 1; |
| 1944 | |
| 1945 | lpfc_cmd->seg_cnt = nseg; |
| 1946 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1947 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 1948 | " %s: Too many sg segments from " |
| 1949 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 1950 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1951 | lpfc_cmd->seg_cnt); |
| 1952 | scsi_dma_unmap(scsi_cmnd); |
| 1953 | return 1; |
| 1954 | } |
| 1955 | |
| 1956 | /* |
| 1957 | * The driver established a maximum scatter-gather segment count |
| 1958 | * during probe that limits the number of sg elements in any |
| 1959 | * single scsi command. Just run through the seg_cnt and format |
| 1960 | * the sge's. |
| 1961 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 1962 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 1963 | * does for SLI-2 mode. |
| 1964 | */ |
| 1965 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 1966 | physaddr = sg_dma_address(sgel); |
| 1967 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1968 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 1969 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 1970 | if ((num_bde + 1) == nseg) |
| 1971 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 1972 | else |
| 1973 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 1974 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 1975 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 1976 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1977 | dma_offset += dma_len; |
| 1978 | sgl++; |
| 1979 | } |
| 1980 | } else { |
| 1981 | sgl += 1; |
| 1982 | /* clear the last flag in the fcp_rsp map entry */ |
| 1983 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 1984 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 1985 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 1986 | } |
| 1987 | |
| 1988 | /* |
| 1989 | * Finish initializing those IOCB fields that are dependent on the |
| 1990 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 1991 | * explicitly reinitialized. |
| 1992 | * all iocb memory resources are reused. |
| 1993 | */ |
| 1994 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 1995 | |
| 1996 | /* |
| 1997 | * Due to difference in data length between DIF/non-DIF paths, |
| 1998 | * we need to set word 4 of IOCB here |
| 1999 | */ |
| 2000 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
| 2004 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2005 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 2006 | * @phba: The Hba for which this call is being executed. |
| 2007 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 2008 | * |
| 2009 | * This routine wraps the actual DMA mapping function pointer from the |
| 2010 | * lpfc_hba struct. |
| 2011 | * |
| 2012 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2013 | * 1 - Error |
| 2014 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2015 | **/ |
| 2016 | static inline int |
| 2017 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2018 | { |
| 2019 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 2020 | } |
| 2021 | |
| 2022 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2023 | * 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] | 2024 | * @phba: Pointer to hba context object. |
| 2025 | * @vport: Pointer to vport object. |
| 2026 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 2027 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 2028 | * |
| 2029 | * This function posts an event when there is a SCSI command reporting |
| 2030 | * error from the scsi device. |
| 2031 | **/ |
| 2032 | static void |
| 2033 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 2034 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 2035 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 2036 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 2037 | uint32_t resp_info = fcprsp->rspStatus2; |
| 2038 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 2039 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 2040 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 2041 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 2042 | unsigned long flags; |
| 2043 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 2044 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 2045 | return; |
| 2046 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2047 | /* If there is queuefull or busy condition send a scsi event */ |
| 2048 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 2049 | (cmnd->result == SAM_STAT_BUSY)) { |
| 2050 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 2051 | if (!fast_path_evt) |
| 2052 | return; |
| 2053 | fast_path_evt->un.scsi_evt.event_type = |
| 2054 | FC_REG_SCSI_EVENT; |
| 2055 | fast_path_evt->un.scsi_evt.subcategory = |
| 2056 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 2057 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 2058 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 2059 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 2060 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 2061 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 2062 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 2063 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 2064 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 2065 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 2066 | if (!fast_path_evt) |
| 2067 | return; |
| 2068 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 2069 | FC_REG_SCSI_EVENT; |
| 2070 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 2071 | LPFC_EVENT_CHECK_COND; |
| 2072 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 2073 | cmnd->device->lun; |
| 2074 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 2075 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 2076 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 2077 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 2078 | fast_path_evt->un.check_cond_evt.sense_key = |
| 2079 | cmnd->sense_buffer[2] & 0xf; |
| 2080 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 2081 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 2082 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 2083 | fcpi_parm && |
| 2084 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 2085 | ((scsi_status == SAM_STAT_GOOD) && |
| 2086 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 2087 | /* |
| 2088 | * If status is good or resid does not match with fcp_param and |
| 2089 | * there is valid fcpi_parm, then there is a read_check error |
| 2090 | */ |
| 2091 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 2092 | if (!fast_path_evt) |
| 2093 | return; |
| 2094 | fast_path_evt->un.read_check_error.header.event_type = |
| 2095 | FC_REG_FABRIC_EVENT; |
| 2096 | fast_path_evt->un.read_check_error.header.subcategory = |
| 2097 | LPFC_EVENT_FCPRDCHKERR; |
| 2098 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 2099 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 2100 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 2101 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 2102 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 2103 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 2104 | fast_path_evt->un.read_check_error.fcpiparam = |
| 2105 | fcpi_parm; |
| 2106 | } else |
| 2107 | return; |
| 2108 | |
| 2109 | fast_path_evt->vport = vport; |
| 2110 | spin_lock_irqsave(&phba->hbalock, flags); |
| 2111 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 2112 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2113 | lpfc_worker_wake_up(phba); |
| 2114 | return; |
| 2115 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2116 | |
| 2117 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2118 | * 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] | 2119 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2120 | * @psb: The scsi buffer which is going to be un-mapped. |
| 2121 | * |
| 2122 | * 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] | 2123 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2124 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2126 | 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] | 2127 | { |
| 2128 | /* |
| 2129 | * There are only two special cases to consider. (1) the scsi command |
| 2130 | * requested scatter-gather usage or (2) the scsi command allocated |
| 2131 | * a request buffer, but did not request use_sg. There is a third |
| 2132 | * case, but it does not require resource deallocation. |
| 2133 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2134 | if (psb->seg_cnt > 0) |
| 2135 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2136 | if (psb->prot_seg_cnt > 0) |
| 2137 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 2138 | scsi_prot_sg_count(psb->pCmd), |
| 2139 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 2140 | } |
| 2141 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2142 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2143 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2144 | * @vport: The virtual port for which this call is being executed. |
| 2145 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 2146 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 2147 | * |
| 2148 | * This routine is called to process response IOCB with status field |
| 2149 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 2150 | * based upon SCSI and FCP error. |
| 2151 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 2152 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2153 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 2154 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | { |
| 2156 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 2157 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 2158 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2159 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2160 | uint32_t resp_info = fcprsp->rspStatus2; |
| 2161 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 2162 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2163 | uint32_t host_status = DID_OK; |
| 2164 | uint32_t rsplen = 0; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 2165 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | /* |
| 2169 | * If this is a task management command, there is no |
| 2170 | * scsi packet associated with this lpfc_cmd. The driver |
| 2171 | * consumes it. |
| 2172 | */ |
| 2173 | if (fcpcmd->fcpCntl2) { |
| 2174 | scsi_status = 0; |
| 2175 | goto out; |
| 2176 | } |
| 2177 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2178 | if (resp_info & RSP_LEN_VALID) { |
| 2179 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2180 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2181 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2182 | "2719 Invalid response length: " |
| 2183 | "tgt x%x lun x%x cmnd x%x rsplen x%x\n", |
| 2184 | cmnd->device->id, |
| 2185 | cmnd->device->lun, cmnd->cmnd[0], |
| 2186 | rsplen); |
| 2187 | host_status = DID_ERROR; |
| 2188 | goto out; |
| 2189 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2190 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 2191 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2192 | "2757 Protocol failure detected during " |
| 2193 | "processing of FCP I/O op: " |
| 2194 | "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n", |
| 2195 | cmnd->device->id, |
| 2196 | cmnd->device->lun, cmnd->cmnd[0], |
| 2197 | fcprsp->rspInfo3); |
| 2198 | host_status = DID_ERROR; |
| 2199 | goto out; |
| 2200 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2201 | } |
| 2202 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 2203 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 2204 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 2205 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 2206 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 2207 | |
| 2208 | if (resp_info & RSP_LEN_VALID) |
| 2209 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 2210 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 2211 | } |
| 2212 | lp = (uint32_t *)cmnd->sense_buffer; |
| 2213 | |
| 2214 | if (!scsi_status && (resp_info & RESID_UNDER)) |
| 2215 | logit = LOG_FCP; |
| 2216 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2217 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2218 | "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] | 2219 | "Data: x%x x%x x%x x%x x%x\n", |
| 2220 | cmnd->cmnd[0], scsi_status, |
| 2221 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 2222 | be32_to_cpu(fcprsp->rspResId), |
| 2223 | be32_to_cpu(fcprsp->rspSnsLen), |
| 2224 | be32_to_cpu(fcprsp->rspRspLen), |
| 2225 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2227 | scsi_set_resid(cmnd, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2229 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2231 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2232 | "9025 FCP Read Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2233 | "residual %d Data: x%x x%x x%x\n", |
| 2234 | be32_to_cpu(fcpcmd->fcpDl), |
| 2235 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 2236 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | |
| 2238 | /* |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2239 | * If there is an under run check if under run reported by |
| 2240 | * storage array is same as the under run reported by HBA. |
| 2241 | * If this is not same, there is a dropped frame. |
| 2242 | */ |
| 2243 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 2244 | fcpi_parm && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2245 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2246 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 2247 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2248 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2249 | "and Underrun Data: x%x x%x x%x x%x\n", |
| 2250 | be32_to_cpu(fcpcmd->fcpDl), |
| 2251 | scsi_get_resid(cmnd), fcpi_parm, |
| 2252 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2253 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2254 | host_status = DID_ERROR; |
| 2255 | } |
| 2256 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | * The cmnd->underflow is the minimum number of bytes that must |
| 2258 | * be transfered for this command. Provided a sense condition |
| 2259 | * is not present, make sure the actual amount transferred is at |
| 2260 | * least the underflow value or fail. |
| 2261 | */ |
| 2262 | if (!(resp_info & SNS_LEN_VALID) && |
| 2263 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2264 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 2265 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2266 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2267 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2268 | "underrun converted to error " |
| 2269 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 2270 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2271 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | host_status = DID_ERROR; |
| 2273 | } |
| 2274 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2275 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2276 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 2277 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2278 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | host_status = DID_ERROR; |
| 2280 | |
| 2281 | /* |
| 2282 | * Check SLI validation that all the transfer was actually done |
| 2283 | * (fcpi_parm should be zero). Apply check only to reads. |
| 2284 | */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 2285 | } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2286 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2287 | "9029 FCP Read Check Error Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 2288 | "x%x x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2289 | be32_to_cpu(fcpcmd->fcpDl), |
| 2290 | be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 2291 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
| 2292 | switch (scsi_status) { |
| 2293 | case SAM_STAT_GOOD: |
| 2294 | case SAM_STAT_CHECK_CONDITION: |
| 2295 | /* Fabric dropped a data frame. Fail any successful |
| 2296 | * command in which we detected dropped frames. |
| 2297 | * A status of good or some check conditions could |
| 2298 | * be considered a successful command. |
| 2299 | */ |
| 2300 | host_status = DID_ERROR; |
| 2301 | break; |
| 2302 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2303 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | out: |
| 2307 | cmnd->result = ScsiResult(host_status, scsi_status); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2308 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | } |
| 2310 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2311 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2312 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2313 | * @phba: The Hba for which this call is being executed. |
| 2314 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2315 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2316 | * |
| 2317 | * This routine assigns scsi command result by looking into response IOCB |
| 2318 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 2319 | * well by ramping down device queue depth. |
| 2320 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | static void |
| 2322 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 2323 | struct lpfc_iocbq *pIocbOut) |
| 2324 | { |
| 2325 | struct lpfc_scsi_buf *lpfc_cmd = |
| 2326 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2327 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 2329 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 2330 | struct scsi_cmnd *cmd; |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 2331 | int result; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2332 | struct scsi_device *tmp_sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 2333 | int depth; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2334 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2335 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 2336 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2337 | uint32_t queue_depth, scsi_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 2339 | /* Sanity check on return of outstanding command */ |
| 2340 | if (!(lpfc_cmd->pCmd)) |
| 2341 | return; |
| 2342 | cmd = lpfc_cmd->pCmd; |
| 2343 | shost = cmd->device->host; |
| 2344 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4]; |
| 2346 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2347 | /* pick up SLI4 exhange busy status from HBA */ |
| 2348 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 2349 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2350 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
| 2351 | atomic_dec(&pnode->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | |
| 2353 | if (lpfc_cmd->status) { |
| 2354 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 2355 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 2356 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 2357 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 2358 | lpfc_cmd->status = IOSTAT_DEFAULT; |
| 2359 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2360 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2361 | "9030 FCP cmd x%x failed <%d/%d> " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2362 | "status: x%x result: x%x Data: x%x x%x\n", |
| 2363 | cmd->cmnd[0], |
| 2364 | cmd->device ? cmd->device->id : 0xffff, |
| 2365 | cmd->device ? cmd->device->lun : 0xffff, |
| 2366 | lpfc_cmd->status, lpfc_cmd->result, |
| 2367 | pIocbOut->iocb.ulpContext, |
| 2368 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | |
| 2370 | switch (lpfc_cmd->status) { |
| 2371 | case IOSTAT_FCP_RSP_ERROR: |
| 2372 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2373 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | break; |
| 2375 | case IOSTAT_NPORT_BSY: |
| 2376 | case IOSTAT_FABRIC_BSY: |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 2377 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2378 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 2379 | if (!fast_path_evt) |
| 2380 | break; |
| 2381 | fast_path_evt->un.fabric_evt.event_type = |
| 2382 | FC_REG_FABRIC_EVENT; |
| 2383 | fast_path_evt->un.fabric_evt.subcategory = |
| 2384 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 2385 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 2386 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 2387 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 2388 | &pnode->nlp_portname, |
| 2389 | sizeof(struct lpfc_name)); |
| 2390 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 2391 | &pnode->nlp_nodename, |
| 2392 | sizeof(struct lpfc_name)); |
| 2393 | } |
| 2394 | fast_path_evt->vport = vport; |
| 2395 | fast_path_evt->work_evt.evt = |
| 2396 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 2397 | spin_lock_irqsave(&phba->hbalock, flags); |
| 2398 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 2399 | &phba->work_list); |
| 2400 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2401 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2403 | case IOSTAT_LOCAL_REJECT: |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2404 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2405 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 2406 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 2407 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2408 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2409 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 2413 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 2414 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 2415 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 2416 | /* |
| 2417 | * This is a response for a BG enabled |
| 2418 | * cmd. Parse BG error |
| 2419 | */ |
| 2420 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 2421 | pIocbOut); |
| 2422 | break; |
| 2423 | } else { |
| 2424 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 2425 | LOG_BG, |
| 2426 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2427 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2432 | default: |
| 2433 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 2434 | break; |
| 2435 | } |
| 2436 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2437 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2438 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 2439 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
| 2440 | SAM_STAT_BUSY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | } else { |
| 2442 | cmd->result = ScsiResult(DID_OK, 0); |
| 2443 | } |
| 2444 | |
| 2445 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 2446 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 2447 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2448 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 2449 | "0710 Iodone <%d/%d> cmd %p, error " |
| 2450 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 2451 | cmd->device->id, cmd->device->lun, cmd, |
| 2452 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 2453 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | } |
| 2455 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2456 | lpfc_update_stats(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 2457 | result = cmd->result; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2458 | if (vport->cfg_max_scsicmpl_time && |
| 2459 | time_after(jiffies, lpfc_cmd->start_time + |
| 2460 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2461 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2462 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 2463 | if (pnode->cmd_qdepth > |
| 2464 | atomic_read(&pnode->cmd_pending) && |
| 2465 | (atomic_read(&pnode->cmd_pending) > |
| 2466 | LPFC_MIN_TGT_QDEPTH) && |
| 2467 | ((cmd->cmnd[0] == READ_10) || |
| 2468 | (cmd->cmnd[0] == WRITE_10))) |
| 2469 | pnode->cmd_qdepth = |
| 2470 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2471 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2472 | pnode->last_change_time = jiffies; |
| 2473 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2474 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2475 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 2476 | if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) && |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2477 | time_after(jiffies, pnode->last_change_time + |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2478 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2479 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 2480 | depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT |
| 2481 | / 100; |
| 2482 | depth = depth ? depth : 1; |
| 2483 | pnode->cmd_qdepth += depth; |
| 2484 | if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth) |
| 2485 | pnode->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2486 | pnode->last_change_time = jiffies; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2487 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2488 | } |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2489 | } |
| 2490 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2491 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2492 | |
| 2493 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 2494 | queue_depth = cmd->device->queue_depth; |
| 2495 | scsi_id = cmd->device->id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | cmd->scsi_done(cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2497 | |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2498 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2499 | /* |
| 2500 | * If there is a thread waiting for command completion |
| 2501 | * wake up the thread. |
| 2502 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2503 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2504 | lpfc_cmd->pCmd = NULL; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2505 | if (lpfc_cmd->waitq) |
| 2506 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2507 | spin_unlock_irqrestore(shost->host_lock, flags); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2508 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 2509 | return; |
| 2510 | } |
| 2511 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2512 | if (!result) |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2513 | lpfc_rampup_queue_depth(vport, queue_depth); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2514 | |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 2515 | /* |
| 2516 | * Check for queue full. If the lun is reporting queue full, then |
| 2517 | * back off the lun queue depth to prevent target overloads. |
| 2518 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2519 | if (result == SAM_STAT_TASK_SET_FULL && pnode && |
| 2520 | NLP_CHK_NODE_ACT(pnode)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2521 | shost_for_each_device(tmp_sdev, shost) { |
| 2522 | if (tmp_sdev->id != scsi_id) |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 2523 | continue; |
| 2524 | depth = scsi_track_queue_full(tmp_sdev, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 2525 | tmp_sdev->queue_depth-1); |
| 2526 | if (depth <= 0) |
| 2527 | continue; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2528 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 2529 | "0711 detected queue full - lun queue " |
| 2530 | "depth adjusted to %d.\n", depth); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2531 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 2532 | pnode, |
| 2533 | tmp_sdev->lun, |
| 2534 | depth+1, depth); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2538 | /* |
| 2539 | * If there is a thread waiting for command completion |
| 2540 | * wake up the thread. |
| 2541 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2542 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2543 | lpfc_cmd->pCmd = NULL; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2544 | if (lpfc_cmd->waitq) |
| 2545 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2546 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2547 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2548 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2549 | } |
| 2550 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2551 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2552 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2553 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 2554 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 2555 | * |
| 2556 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 2557 | * byte swapping the data to big endian format for transmission on the wire. |
| 2558 | **/ |
| 2559 | static void |
| 2560 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 2561 | { |
| 2562 | int i, j; |
| 2563 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 2564 | i += sizeof(uint32_t), j++) { |
| 2565 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 2566 | } |
| 2567 | } |
| 2568 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2569 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2570 | * 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] | 2571 | * @vport: The virtual port for which this call is being executed. |
| 2572 | * @lpfc_cmd: The scsi command which needs to send. |
| 2573 | * @pnode: Pointer to lpfc_nodelist. |
| 2574 | * |
| 2575 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2576 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2577 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2579 | 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] | 2580 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2582 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2584 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2585 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2586 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 2587 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 7e2b19f | 2007-10-29 11:00:39 -0400 | [diff] [blame] | 2588 | char tag[2]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2590 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 2591 | return; |
| 2592 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 2594 | /* clear task management bits */ |
| 2595 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 2597 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 2598 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | |
| 2600 | memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); |
| 2601 | |
James Smart | 7e2b19f | 2007-10-29 11:00:39 -0400 | [diff] [blame] | 2602 | if (scsi_populate_tag_msg(scsi_cmnd, tag)) { |
| 2603 | switch (tag[0]) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | case HEAD_OF_QUEUE_TAG: |
| 2605 | fcp_cmnd->fcpCntl1 = HEAD_OF_Q; |
| 2606 | break; |
| 2607 | case ORDERED_QUEUE_TAG: |
| 2608 | fcp_cmnd->fcpCntl1 = ORDERED_Q; |
| 2609 | break; |
| 2610 | default: |
| 2611 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| 2612 | break; |
| 2613 | } |
| 2614 | } else |
| 2615 | fcp_cmnd->fcpCntl1 = 0; |
| 2616 | |
| 2617 | /* |
| 2618 | * There are three possibilities here - use scatter-gather segment, use |
| 2619 | * the single mapping, or neither. Start the lpfc command prep by |
| 2620 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 2621 | * data bde entry. |
| 2622 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2623 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | if (datadir == DMA_TO_DEVICE) { |
| 2625 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2626 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 2627 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 2628 | iocb_cmd->ulpPU = 0; |
| 2629 | } else |
| 2630 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 2632 | phba->fc4OutputRequests++; |
| 2633 | } else { |
| 2634 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 2635 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 2637 | phba->fc4InputRequests++; |
| 2638 | } |
| 2639 | } else { |
| 2640 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 2641 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 2642 | iocb_cmd->ulpPU = 0; |
| 2643 | fcp_cmnd->fcpCntl3 = 0; |
| 2644 | phba->fc4ControlRequests++; |
| 2645 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2646 | if (phba->sli_rev == 3 && |
| 2647 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2648 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | /* |
| 2650 | * Finish initializing those IOCB fields that are independent |
| 2651 | * of the scsi_cmnd request_buffer |
| 2652 | */ |
| 2653 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
| 2654 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 2655 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2656 | else |
| 2657 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | |
| 2659 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 2660 | piocbq->context1 = lpfc_cmd; |
| 2661 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 2662 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2663 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | } |
| 2665 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2666 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2667 | * lpfc_scsi_prep_task_mgmt_cmnd - Convert SLI3 scsi TM cmd to FCP info unit |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2668 | * @vport: The virtual port for which this call is being executed. |
| 2669 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 2670 | * @lun: Logical unit number. |
| 2671 | * @task_mgmt_cmd: SCSI task management command. |
| 2672 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2673 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 2674 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2675 | * |
| 2676 | * Return codes: |
| 2677 | * 0 - Error |
| 2678 | * 1 - Success |
| 2679 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2681 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | struct lpfc_scsi_buf *lpfc_cmd, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 2683 | unsigned int lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | uint8_t task_mgmt_cmd) |
| 2685 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2686 | struct lpfc_iocbq *piocbq; |
| 2687 | IOCB_t *piocb; |
| 2688 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 2689 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 2691 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2692 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 2693 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2696 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2697 | piocbq->vport = vport; |
| 2698 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | piocb = &piocbq->iocb; |
| 2700 | |
| 2701 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2702 | /* Clear out any old data in the FCP command area */ |
| 2703 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 2704 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2705 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2706 | if (vport->phba->sli_rev == 3 && |
| 2707 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2708 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | piocb->ulpContext = ndlp->nlp_rpi; |
| 2711 | if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { |
| 2712 | piocb->ulpFCP2Rcvy = 1; |
| 2713 | } |
| 2714 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
| 2715 | |
| 2716 | /* ulpTimeout is only one byte */ |
| 2717 | if (lpfc_cmd->timeout > 0xff) { |
| 2718 | /* |
| 2719 | * Do not timeout the command at the firmware level. |
| 2720 | * The driver will provide the timeout mechanism. |
| 2721 | */ |
| 2722 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2723 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2724 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2725 | |
| 2726 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 2727 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2729 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | } |
| 2731 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2732 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2733 | * lpfc_scsi_api_table_setup - Set up scsi api fucntion jump table |
| 2734 | * @phba: The hba struct for which this call is being executed. |
| 2735 | * @dev_grp: The HBA PCI-Device group number. |
| 2736 | * |
| 2737 | * This routine sets up the SCSI interface API function jump table in @phba |
| 2738 | * struct. |
| 2739 | * Returns: 0 - success, -ENODEV - failure. |
| 2740 | **/ |
| 2741 | int |
| 2742 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 2743 | { |
| 2744 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2745 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 2746 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
| 2747 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf; |
| 2748 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2749 | switch (dev_grp) { |
| 2750 | case LPFC_PCI_DEV_LP: |
| 2751 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; |
| 2752 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2753 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
| 2754 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2755 | case LPFC_PCI_DEV_OC: |
| 2756 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; |
| 2757 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2758 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
| 2759 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2760 | default: |
| 2761 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2762 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 2763 | dev_grp); |
| 2764 | return -ENODEV; |
| 2765 | break; |
| 2766 | } |
| 2767 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf; |
| 2768 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 2769 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2770 | return 0; |
| 2771 | } |
| 2772 | |
| 2773 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2774 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2775 | * @phba: The Hba for which this call is being executed. |
| 2776 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 2777 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 2778 | * |
| 2779 | * This routine is IOCB completion routine for device reset and target reset |
| 2780 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 2781 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2782 | static void |
| 2783 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 2784 | struct lpfc_iocbq *cmdiocbq, |
| 2785 | struct lpfc_iocbq *rspiocbq) |
| 2786 | { |
| 2787 | struct lpfc_scsi_buf *lpfc_cmd = |
| 2788 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 2789 | if (lpfc_cmd) |
| 2790 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 2791 | return; |
| 2792 | } |
| 2793 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2794 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2795 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2796 | * @host: The scsi host for which this call is being executed. |
| 2797 | * |
| 2798 | * This routine provides module information about hba. |
| 2799 | * |
| 2800 | * Reutrn code: |
| 2801 | * Pointer to char - Success. |
| 2802 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | const char * |
| 2804 | lpfc_info(struct Scsi_Host *host) |
| 2805 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2806 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 2807 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2808 | int len; |
| 2809 | static char lpfcinfobuf[384]; |
| 2810 | |
| 2811 | memset(lpfcinfobuf,0,384); |
| 2812 | if (phba && phba->pcidev){ |
| 2813 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 2814 | len = strlen(lpfcinfobuf); |
| 2815 | snprintf(lpfcinfobuf + len, |
| 2816 | 384-len, |
| 2817 | " on PCI bus %02x device %02x irq %d", |
| 2818 | phba->pcidev->bus->number, |
| 2819 | phba->pcidev->devfn, |
| 2820 | phba->pcidev->irq); |
| 2821 | len = strlen(lpfcinfobuf); |
| 2822 | if (phba->Port[0]) { |
| 2823 | snprintf(lpfcinfobuf + len, |
| 2824 | 384-len, |
| 2825 | " port %s", |
| 2826 | phba->Port); |
| 2827 | } |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 2828 | len = strlen(lpfcinfobuf); |
| 2829 | if (phba->sli4_hba.link_state.logical_speed) { |
| 2830 | snprintf(lpfcinfobuf + len, |
| 2831 | 384-len, |
| 2832 | " Logical Link Speed: %d Mbps", |
| 2833 | phba->sli4_hba.link_state.logical_speed * 10); |
| 2834 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2835 | } |
| 2836 | return lpfcinfobuf; |
| 2837 | } |
| 2838 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2839 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2840 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2841 | * @phba: The Hba for which this call is being executed. |
| 2842 | * |
| 2843 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 2844 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 2845 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2846 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 2847 | { |
| 2848 | unsigned long poll_tmo_expires = |
| 2849 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 2850 | |
| 2851 | if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt) |
| 2852 | mod_timer(&phba->fcp_poll_timer, |
| 2853 | poll_tmo_expires); |
| 2854 | } |
| 2855 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2856 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2857 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2858 | * @phba: The Hba for which this call is being executed. |
| 2859 | * |
| 2860 | * This routine starts the fcp_poll_timer of @phba. |
| 2861 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2862 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 2863 | { |
| 2864 | lpfc_poll_rearm_timer(phba); |
| 2865 | } |
| 2866 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2867 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2868 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2869 | * @ptr: Map to lpfc_hba data structure pointer. |
| 2870 | * |
| 2871 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 2872 | * and FCP Ring interrupt is disable. |
| 2873 | **/ |
| 2874 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2875 | void lpfc_poll_timeout(unsigned long ptr) |
| 2876 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2877 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2878 | |
| 2879 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2880 | lpfc_sli_handle_fast_ring_event(phba, |
| 2881 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 2882 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2883 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 2884 | lpfc_poll_rearm_timer(phba); |
| 2885 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2886 | } |
| 2887 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2888 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2889 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2890 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 2891 | * @done: Pointer to done routine. |
| 2892 | * |
| 2893 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 2894 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 2895 | * The @done callback is invoked after driver finished processing the command. |
| 2896 | * |
| 2897 | * Return value : |
| 2898 | * 0 - Success |
| 2899 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 2900 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2901 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame^] | 2902 | lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2904 | struct Scsi_Host *shost = cmnd->device->host; |
| 2905 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2906 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2907 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2908 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2909 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2910 | 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] | 2911 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2913 | err = fc_remote_port_chkready(rport); |
| 2914 | if (err) { |
| 2915 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2916 | goto out_fail_command; |
| 2917 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2918 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2919 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2920 | if (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 2921 | scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
| 2922 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2923 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2924 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 2925 | " op:%02x str=%s without registering for" |
| 2926 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2927 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 2928 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 2929 | goto out_fail_command; |
| 2930 | } |
| 2931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2932 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2933 | * Catch race where our node has transitioned, but the |
| 2934 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2935 | */ |
James Smart | b522d7d | 2008-09-07 11:51:56 -0400 | [diff] [blame] | 2936 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 2937 | cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
| 2938 | goto out_fail_command; |
| 2939 | } |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 2940 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2941 | goto out_host_busy; |
Mike Christie | a93ce02 | 2008-08-17 15:24:41 -0500 | [diff] [blame] | 2942 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2943 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2944 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2945 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2946 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2947 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 2948 | "0707 driver's buffer pool is empty, " |
| 2949 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | goto out_host_busy; |
| 2951 | } |
| 2952 | |
| 2953 | /* |
| 2954 | * Store the midlayer's command structure for the completion phase |
| 2955 | * and complete the command initialization. |
| 2956 | */ |
| 2957 | lpfc_cmd->pCmd = cmnd; |
| 2958 | lpfc_cmd->rdata = rdata; |
| 2959 | lpfc_cmd->timeout = 0; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2960 | lpfc_cmd->start_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2961 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| 2962 | cmnd->scsi_done = done; |
| 2963 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2964 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2965 | if (vport->phba->cfg_enable_bg) { |
| 2966 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2967 | "9033 BLKGRD: rcvd protected cmd:%02x op:%02x " |
| 2968 | "str=%s\n", |
| 2969 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 2970 | dif_op_str[scsi_get_prot_op(cmnd)]); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2971 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2972 | "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 2973 | "%02x %02x %02x %02x %02x\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2974 | cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2], |
| 2975 | cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5], |
| 2976 | cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8], |
| 2977 | cmnd->cmnd[9]); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2978 | if (cmnd->cmnd[0] == READ_10) |
| 2979 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2980 | "9035 BLKGRD: READ @ sector %llu, " |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2981 | "count %u\n", |
| 2982 | (unsigned long long)scsi_get_lba(cmnd), |
| 2983 | blk_rq_sectors(cmnd->request)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2984 | else if (cmnd->cmnd[0] == WRITE_10) |
| 2985 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2986 | "9036 BLKGRD: WRITE @ sector %llu, " |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2987 | "count %u cmd=%p\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 2988 | (unsigned long long)scsi_get_lba(cmnd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2989 | blk_rq_sectors(cmnd->request), |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2990 | cmnd); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2991 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2992 | |
| 2993 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 2994 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2995 | if (vport->phba->cfg_enable_bg) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2996 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2997 | "9038 BLKGRD: rcvd unprotected cmd:" |
| 2998 | "%02x op:%02x str=%s\n", |
| 2999 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 3000 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 3001 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 3002 | "9039 BLKGRD: CDB: %02x %02x %02x " |
| 3003 | "%02x %02x %02x %02x %02x %02x %02x\n", |
| 3004 | cmnd->cmnd[0], cmnd->cmnd[1], |
| 3005 | cmnd->cmnd[2], cmnd->cmnd[3], |
| 3006 | cmnd->cmnd[4], cmnd->cmnd[5], |
| 3007 | cmnd->cmnd[6], cmnd->cmnd[7], |
| 3008 | cmnd->cmnd[8], cmnd->cmnd[9]); |
| 3009 | if (cmnd->cmnd[0] == READ_10) |
| 3010 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 3011 | "9040 dbg: READ @ sector %llu, " |
| 3012 | "count %u\n", |
| 3013 | (unsigned long long)scsi_get_lba(cmnd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 3014 | blk_rq_sectors(cmnd->request)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3015 | else if (cmnd->cmnd[0] == WRITE_10) |
| 3016 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3017 | "9041 dbg: WRITE @ sector %llu, " |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 3018 | "count %u cmd=%p\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 3019 | (unsigned long long)scsi_get_lba(cmnd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 3020 | blk_rq_sectors(cmnd->request), cmnd); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3021 | else |
| 3022 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3023 | "9042 dbg: parser not implemented\n"); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3024 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3025 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3026 | } |
| 3027 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | if (err) |
| 3029 | goto out_host_busy_free_buf; |
| 3030 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3031 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3033 | atomic_inc(&ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3034 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3035 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3036 | if (err) { |
| 3037 | atomic_dec(&ndlp->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3039 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3040 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3041 | spin_unlock(shost->host_lock); |
| 3042 | lpfc_sli_handle_fast_ring_event(phba, |
| 3043 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 3044 | |
| 3045 | spin_lock(shost->host_lock); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3046 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 3047 | lpfc_poll_rearm_timer(phba); |
| 3048 | } |
| 3049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | return 0; |
| 3051 | |
| 3052 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3053 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3054 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | out_host_busy: |
| 3056 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3057 | |
| 3058 | out_fail_command: |
| 3059 | done(cmnd); |
| 3060 | return 0; |
| 3061 | } |
| 3062 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame^] | 3063 | static DEF_SCSI_QCMD(lpfc_queuecommand) |
| 3064 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3065 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3066 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3067 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 3068 | * |
| 3069 | * This routine aborts @cmnd pending in base driver. |
| 3070 | * |
| 3071 | * Return code : |
| 3072 | * 0x2003 - Error |
| 3073 | * 0x2002 - Success |
| 3074 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3075 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 3076 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3078 | struct Scsi_Host *shost = cmnd->device->host; |
| 3079 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3080 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3081 | struct lpfc_iocbq *iocb; |
| 3082 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3083 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | IOCB_t *cmd, *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3085 | int ret = SUCCESS; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3086 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3087 | |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 3088 | ret = fc_block_scsi_eh(cmnd); |
| 3089 | if (ret) |
| 3090 | return ret; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3091 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3092 | if (!lpfc_cmd) { |
| 3093 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 3094 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
| 3095 | "x%x ID %d " |
| 3096 | "LUN %d snum %#lx\n", ret, cmnd->device->id, |
| 3097 | cmnd->device->lun, cmnd->serial_number); |
| 3098 | return SUCCESS; |
| 3099 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | |
| 3101 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3102 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 3103 | * points to a different SCSI command, then the driver has |
| 3104 | * already completed this command, but the midlayer did not |
| 3105 | * see the completion before the eh fired. Just return |
| 3106 | * SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3108 | iocb = &lpfc_cmd->cur_iocbq; |
| 3109 | if (lpfc_cmd->pCmd != cmnd) |
| 3110 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3111 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3112 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3113 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3114 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| 3115 | if (abtsiocb == NULL) { |
| 3116 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | goto out; |
| 3118 | } |
| 3119 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3120 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3121 | * The scsi command can not be in txq and it is in flight because the |
| 3122 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 3123 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3125 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3126 | cmd = &iocb->iocb; |
| 3127 | icmd = &abtsiocb->iocb; |
| 3128 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 3129 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3130 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3131 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 3132 | else |
| 3133 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3134 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3135 | icmd->ulpLe = 1; |
| 3136 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3137 | |
| 3138 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 3139 | abtsiocb->fcp_wqidx = iocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3140 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3141 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3142 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3143 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 3144 | else |
| 3145 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3147 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3148 | abtsiocb->vport = vport; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3149 | if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) == |
| 3150 | IOCB_ERROR) { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3151 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 3152 | ret = FAILED; |
| 3153 | goto out; |
| 3154 | } |
| 3155 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3156 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3157 | lpfc_sli_handle_fast_ring_event(phba, |
| 3158 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3159 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3160 | lpfc_cmd->waitq = &waitq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3161 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3162 | wait_event_timeout(waitq, |
| 3163 | (lpfc_cmd->pCmd != cmnd), |
| 3164 | (2*vport->cfg_devloss_tmo*HZ)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3165 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3166 | spin_lock_irq(shost->host_lock); |
| 3167 | lpfc_cmd->waitq = NULL; |
| 3168 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3170 | if (lpfc_cmd->pCmd == cmnd) { |
| 3171 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3172 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3173 | "0748 abort handler timed out waiting " |
| 3174 | "for abort to complete: ret %#x, ID %d, " |
| 3175 | "LUN %d, snum %#lx\n", |
| 3176 | ret, cmnd->device->id, cmnd->device->lun, |
| 3177 | cmnd->serial_number); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3181 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 3182 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
| 3183 | "LUN %d snum %#lx\n", ret, cmnd->device->id, |
| 3184 | cmnd->device->lun, cmnd->serial_number); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3185 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3186 | } |
| 3187 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3188 | static char * |
| 3189 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 3190 | { |
| 3191 | switch (task_mgmt_cmd) { |
| 3192 | case FCP_ABORT_TASK_SET: |
| 3193 | return "ABORT_TASK_SET"; |
| 3194 | case FCP_CLEAR_TASK_SET: |
| 3195 | return "FCP_CLEAR_TASK_SET"; |
| 3196 | case FCP_BUS_RESET: |
| 3197 | return "FCP_BUS_RESET"; |
| 3198 | case FCP_LUN_RESET: |
| 3199 | return "FCP_LUN_RESET"; |
| 3200 | case FCP_TARGET_RESET: |
| 3201 | return "FCP_TARGET_RESET"; |
| 3202 | case FCP_CLEAR_ACA: |
| 3203 | return "FCP_CLEAR_ACA"; |
| 3204 | case FCP_TERMINATE_TASK: |
| 3205 | return "FCP_TERMINATE_TASK"; |
| 3206 | default: |
| 3207 | return "unknown"; |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | /** |
| 3212 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 3213 | * @vport: The virtual port for which this call is being executed. |
| 3214 | * @rdata: Pointer to remote port local data |
| 3215 | * @tgt_id: Target ID of remote device. |
| 3216 | * @lun_id: Lun number for the TMF |
| 3217 | * @task_mgmt_cmd: type of TMF to send |
| 3218 | * |
| 3219 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 3220 | * a remote port. |
| 3221 | * |
| 3222 | * Return Code: |
| 3223 | * 0x2003 - Error |
| 3224 | * 0x2002 - Success. |
| 3225 | **/ |
| 3226 | static int |
| 3227 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata, |
| 3228 | unsigned tgt_id, unsigned int lun_id, |
| 3229 | uint8_t task_mgmt_cmd) |
| 3230 | { |
| 3231 | struct lpfc_hba *phba = vport->phba; |
| 3232 | struct lpfc_scsi_buf *lpfc_cmd; |
| 3233 | struct lpfc_iocbq *iocbq; |
| 3234 | struct lpfc_iocbq *iocbqrsp; |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3235 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3236 | int ret; |
| 3237 | int status; |
| 3238 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3239 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3240 | return FAILED; |
| 3241 | |
| 3242 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| 3243 | if (lpfc_cmd == NULL) |
| 3244 | return FAILED; |
| 3245 | lpfc_cmd->timeout = 60; |
| 3246 | lpfc_cmd->rdata = rdata; |
| 3247 | |
| 3248 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 3249 | task_mgmt_cmd); |
| 3250 | if (!status) { |
| 3251 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 3252 | return FAILED; |
| 3253 | } |
| 3254 | |
| 3255 | iocbq = &lpfc_cmd->cur_iocbq; |
| 3256 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 3257 | if (iocbqrsp == NULL) { |
| 3258 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 3259 | return FAILED; |
| 3260 | } |
| 3261 | |
| 3262 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 3263 | "0702 Issue %s to TGT %d LUN %d " |
| 3264 | "rpi x%x nlp_flag x%x\n", |
| 3265 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3266 | pnode->nlp_rpi, pnode->nlp_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3267 | |
| 3268 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 3269 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
| 3270 | if (status != IOCB_SUCCESS) { |
| 3271 | if (status == IOCB_TIMEDOUT) { |
| 3272 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
| 3273 | ret = TIMEOUT_ERROR; |
| 3274 | } else |
| 3275 | ret = FAILED; |
| 3276 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3277 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3278 | "0727 TMF %s to TGT %d LUN %d failed (%d, %d)\n", |
| 3279 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 3280 | tgt_id, lun_id, iocbqrsp->iocb.ulpStatus, |
| 3281 | iocbqrsp->iocb.un.ulpWord[4]); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3282 | } else if (status == IOCB_BUSY) |
| 3283 | ret = FAILED; |
| 3284 | else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3285 | ret = SUCCESS; |
| 3286 | |
| 3287 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 3288 | |
| 3289 | if (ret != TIMEOUT_ERROR) |
| 3290 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 3291 | |
| 3292 | return ret; |
| 3293 | } |
| 3294 | |
| 3295 | /** |
| 3296 | * lpfc_chk_tgt_mapped - |
| 3297 | * @vport: The virtual port to check on |
| 3298 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 3299 | * |
| 3300 | * This routine delays until the scsi target (aka rport) for the |
| 3301 | * command exists (is present and logged in) or we declare it non-existent. |
| 3302 | * |
| 3303 | * Return code : |
| 3304 | * 0x2003 - Error |
| 3305 | * 0x2002 - Success |
| 3306 | **/ |
| 3307 | static int |
| 3308 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 3309 | { |
| 3310 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3311 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3312 | unsigned long later; |
| 3313 | |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3314 | if (!rdata) { |
| 3315 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 3316 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 3317 | return FAILED; |
| 3318 | } |
| 3319 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3320 | /* |
| 3321 | * If target is not in a MAPPED state, delay until |
| 3322 | * target is rediscovered or devloss timeout expires. |
| 3323 | */ |
| 3324 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 3325 | while (time_after(later, jiffies)) { |
| 3326 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3327 | return FAILED; |
| 3328 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 3329 | return SUCCESS; |
| 3330 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
| 3331 | rdata = cmnd->device->hostdata; |
| 3332 | if (!rdata) |
| 3333 | return FAILED; |
| 3334 | pnode = rdata->pnode; |
| 3335 | } |
| 3336 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 3337 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 3338 | return FAILED; |
| 3339 | return SUCCESS; |
| 3340 | } |
| 3341 | |
| 3342 | /** |
| 3343 | * lpfc_reset_flush_io_context - |
| 3344 | * @vport: The virtual port (scsi_host) for the flush context |
| 3345 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 3346 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 3347 | * @context: specifies the context level to flush at. |
| 3348 | * |
| 3349 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 3350 | * contexts from the adapter. This routine aborts any contexts |
| 3351 | * outstanding, then waits for their completions. The wait is |
| 3352 | * bounded by devloss_tmo though. |
| 3353 | * |
| 3354 | * Return code : |
| 3355 | * 0x2003 - Error |
| 3356 | * 0x2002 - Success |
| 3357 | **/ |
| 3358 | static int |
| 3359 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 3360 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 3361 | { |
| 3362 | struct lpfc_hba *phba = vport->phba; |
| 3363 | unsigned long later; |
| 3364 | int cnt; |
| 3365 | |
| 3366 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 3367 | if (cnt) |
| 3368 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 3369 | tgt_id, lun_id, context); |
| 3370 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 3371 | while (time_after(later, jiffies) && cnt) { |
| 3372 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 3373 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 3374 | } |
| 3375 | if (cnt) { |
| 3376 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3377 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 3378 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 3379 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 3380 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 3381 | cnt); |
| 3382 | return FAILED; |
| 3383 | } |
| 3384 | return SUCCESS; |
| 3385 | } |
| 3386 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3387 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3388 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3389 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 3390 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3391 | * 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] | 3392 | * command. |
| 3393 | * |
| 3394 | * Return code : |
| 3395 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3396 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3397 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3399 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3401 | struct Scsi_Host *shost = cmnd->device->host; |
| 3402 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3404 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3405 | unsigned tgt_id = cmnd->device->id; |
| 3406 | unsigned int lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3407 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3408 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3410 | if (!rdata) { |
| 3411 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3412 | "0798 Device Reset rport failure: rdata x%p\n", rdata); |
| 3413 | return FAILED; |
| 3414 | } |
| 3415 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 3416 | status = fc_block_scsi_eh(cmnd); |
| 3417 | if (status) |
| 3418 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3419 | |
| 3420 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 3421 | if (status == FAILED) { |
| 3422 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3423 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 3424 | return FAILED; |
| 3425 | } |
| 3426 | |
| 3427 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 3428 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 3429 | scsi_event.lun = lun_id; |
| 3430 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3431 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3432 | |
| 3433 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 3434 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 3435 | |
| 3436 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, |
| 3437 | FCP_LUN_RESET); |
| 3438 | |
| 3439 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3440 | "0713 SCSI layer issued Device Reset (%d, %d) " |
| 3441 | "return x%x\n", tgt_id, lun_id, status); |
| 3442 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3444 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 3445 | * or if the TMF failed, they may be in an indeterminate state. |
| 3446 | * So, continue on. |
| 3447 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3449 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 3450 | LPFC_CTX_LUN); |
| 3451 | return status; |
| 3452 | } |
| 3453 | |
| 3454 | /** |
| 3455 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 3456 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 3457 | * |
| 3458 | * This routine does a target reset by sending a TARGET_RESET task management |
| 3459 | * command. |
| 3460 | * |
| 3461 | * Return code : |
| 3462 | * 0x2003 - Error |
| 3463 | * 0x2002 - Success |
| 3464 | **/ |
| 3465 | static int |
| 3466 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 3467 | { |
| 3468 | struct Scsi_Host *shost = cmnd->device->host; |
| 3469 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3470 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3471 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3472 | unsigned tgt_id = cmnd->device->id; |
| 3473 | unsigned int lun_id = cmnd->device->lun; |
| 3474 | struct lpfc_scsi_event_header scsi_event; |
| 3475 | int status; |
| 3476 | |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3477 | if (!rdata) { |
| 3478 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3479 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 3480 | return FAILED; |
| 3481 | } |
| 3482 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 3483 | status = fc_block_scsi_eh(cmnd); |
| 3484 | if (status) |
| 3485 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3486 | |
| 3487 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 3488 | if (status == FAILED) { |
| 3489 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3490 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
| 3491 | return FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3492 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3493 | |
| 3494 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 3495 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 3496 | scsi_event.lun = 0; |
| 3497 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3498 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3499 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3500 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 3501 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3502 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3503 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, |
| 3504 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3506 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3507 | "0723 SCSI layer issued Target Reset (%d, %d) " |
| 3508 | "return x%x\n", tgt_id, lun_id, status); |
| 3509 | |
| 3510 | /* |
| 3511 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 3512 | * or if the TMF failed, they may be in an indeterminate state. |
| 3513 | * So, continue on. |
| 3514 | * We will report success if all the i/o aborts successfully. |
| 3515 | */ |
| 3516 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 3517 | LPFC_CTX_TGT); |
| 3518 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | } |
| 3520 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3521 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3522 | * 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] | 3523 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 3524 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3525 | * This routine does target reset to all targets on @cmnd->device->host. |
| 3526 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3527 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3528 | * Return code : |
| 3529 | * 0x2003 - Error |
| 3530 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3531 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 3532 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3533 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3535 | struct Scsi_Host *shost = cmnd->device->host; |
| 3536 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3538 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3539 | int match; |
| 3540 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3541 | |
| 3542 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 3543 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 3544 | scsi_event.lun = 0; |
| 3545 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3546 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 3547 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3548 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 3549 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 3551 | ret = fc_block_scsi_eh(cmnd); |
| 3552 | if (ret) |
| 3553 | return ret; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | /* |
| 3556 | * Since the driver manages a single bus device, reset all |
| 3557 | * targets known to the driver. Should any target reset |
| 3558 | * fail, this routine returns failure to the midlayer. |
| 3559 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 3560 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3561 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3563 | spin_lock_irq(shost->host_lock); |
| 3564 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3565 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3566 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3567 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 3568 | ndlp->nlp_sid == i && |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3569 | ndlp->rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | match = 1; |
| 3571 | break; |
| 3572 | } |
| 3573 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3574 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | if (!match) |
| 3576 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3577 | |
| 3578 | status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data, |
| 3579 | i, 0, FCP_TARGET_RESET); |
| 3580 | |
| 3581 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3582 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3583 | "0700 Bus Reset on target %d failed\n", |
| 3584 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 3585 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | } |
| 3587 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 3588 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3589 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 3590 | * above; or if any of the TMFs failed, they may be in an |
| 3591 | * indeterminate state. |
| 3592 | * 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] | 3593 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3594 | |
| 3595 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 3596 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 3597 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3598 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3599 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3600 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | return ret; |
| 3602 | } |
| 3603 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3604 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3605 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3606 | * @sdev: Pointer to scsi_device. |
| 3607 | * |
| 3608 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 3609 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 3610 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 3611 | * of scsi buffer exists for the lifetime of the driver. |
| 3612 | * |
| 3613 | * Return codes: |
| 3614 | * non-0 - Error |
| 3615 | * 0 - Success |
| 3616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3617 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3618 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 3619 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3620 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 3621 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3622 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3623 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3625 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 3626 | uint32_t sdev_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3628 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | return -ENXIO; |
| 3630 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3631 | sdev->hostdata = rport->dd_data; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 3632 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | |
| 3634 | /* |
| 3635 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 3636 | * 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] | 3637 | * HBA limit conveyed to the midlayer via the host structure. The |
| 3638 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 3639 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 | */ |
| 3641 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3642 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3643 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 3644 | /* If allocated buffers are enough do nothing */ |
| 3645 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 3646 | return 0; |
| 3647 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3648 | /* Allow some exchanges to be available always to complete discovery */ |
| 3649 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3650 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 3651 | "0704 At limitation of %d preallocated " |
| 3652 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3654 | /* Allow some exchanges to be available always to complete discovery */ |
| 3655 | } else if (total + num_to_alloc > |
| 3656 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3657 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 3658 | "0705 Allocation request of %d " |
| 3659 | "command buffers will exceed max of %d. " |
| 3660 | "Reducing allocation request to %d.\n", |
| 3661 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 3662 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3663 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 3664 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3665 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
| 3666 | if (num_to_alloc != num_allocated) { |
| 3667 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 3668 | "0708 Allocation request of %d " |
| 3669 | "command buffers did not succeed. " |
| 3670 | "Allocated %d buffers.\n", |
| 3671 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3673 | if (num_allocated > 0) |
| 3674 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3675 | return 0; |
| 3676 | } |
| 3677 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3678 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3679 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3680 | * @sdev: Pointer to scsi_device. |
| 3681 | * |
| 3682 | * This routine configures following items |
| 3683 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3684 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 3685 | * |
| 3686 | * Return codes: |
| 3687 | * 0 - Success |
| 3688 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | static int |
| 3690 | lpfc_slave_configure(struct scsi_device *sdev) |
| 3691 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3692 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 3693 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | |
| 3695 | if (sdev->tagged_supported) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3696 | scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | else |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3698 | scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3700 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3701 | lpfc_sli_handle_fast_ring_event(phba, |
| 3702 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3703 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 3704 | lpfc_poll_rearm_timer(phba); |
| 3705 | } |
| 3706 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3707 | return 0; |
| 3708 | } |
| 3709 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3710 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3711 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3712 | * @sdev: Pointer to scsi_device. |
| 3713 | * |
| 3714 | * This routine sets @sdev hostatdata filed to null. |
| 3715 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | static void |
| 3717 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 3718 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 3719 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 3720 | struct lpfc_hba *phba = vport->phba; |
| 3721 | atomic_dec(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | sdev->hostdata = NULL; |
| 3723 | return; |
| 3724 | } |
| 3725 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3726 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | struct scsi_host_template lpfc_template = { |
| 3728 | .module = THIS_MODULE, |
| 3729 | .name = LPFC_DRIVER_NAME, |
| 3730 | .info = lpfc_info, |
| 3731 | .queuecommand = lpfc_queuecommand, |
| 3732 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3733 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 3734 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3735 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | .slave_alloc = lpfc_slave_alloc, |
| 3737 | .slave_configure = lpfc_slave_configure, |
| 3738 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3739 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 3741 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 3743 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3744 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 3745 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 3746 | .vendor_id = LPFC_NL_VENDOR_ID, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3747 | .change_queue_depth = lpfc_change_queue_depth, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3749 | |
| 3750 | struct scsi_host_template lpfc_vport_template = { |
| 3751 | .module = THIS_MODULE, |
| 3752 | .name = LPFC_DRIVER_NAME, |
| 3753 | .info = lpfc_info, |
| 3754 | .queuecommand = lpfc_queuecommand, |
| 3755 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 3756 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 3757 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3758 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 3759 | .slave_alloc = lpfc_slave_alloc, |
| 3760 | .slave_configure = lpfc_slave_configure, |
| 3761 | .slave_destroy = lpfc_slave_destroy, |
| 3762 | .scan_finished = lpfc_scan_finished, |
| 3763 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 3764 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3765 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 3766 | .use_clustering = ENABLE_CLUSTERING, |
| 3767 | .shost_attrs = lpfc_vport_attrs, |
| 3768 | .max_sectors = 0xFFFF, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3769 | .change_queue_depth = lpfc_change_queue_depth, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3770 | }; |