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