blob: 8021c9e1fb9f4a17734edae173c8c0c14c25429f [file] [log] [blame]
James Smart9a6b09c2012-03-01 22:37:42 -05001/******************************************************************r
dea31012005-04-17 16:05:31 -05002 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartacd68592012-01-18 16:25:09 -05004 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * 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. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
dea31012005-04-17 16:05:31 -050021#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050023#include <linux/interrupt.h>
Paul Gortmaker09703662011-05-27 09:37:25 -040024#include <linux/export.h>
James Smarta90f5682006-08-17 11:58:04 -040025#include <linux/delay.h>
James Smarte2a0a9d2008-12-04 22:40:02 -050026#include <asm/unaligned.h>
dea31012005-04-17 16:05:31 -050027
28#include <scsi/scsi.h>
29#include <scsi/scsi_device.h>
James Smarte2a0a9d2008-12-04 22:40:02 -050030#include <scsi/scsi_eh.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_host.h>
32#include <scsi/scsi_tcq.h>
33#include <scsi/scsi_transport_fc.h>
34
35#include "lpfc_version.h"
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc.h"
James Smart9a6b09c2012-03-01 22:37:42 -050043#include "lpfc_scsi.h"
dea31012005-04-17 16:05:31 -050044#include "lpfc_logmsg.h"
45#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050046#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050047
48#define LPFC_RESET_WAIT 2
49#define LPFC_ABORT_WAIT 2
50
James Smarte2a0a9d2008-12-04 22:40:02 -050051int _dump_buf_done;
52
53static char *dif_op_str[] = {
James Smart9a6b09c2012-03-01 22:37:42 -050054 "PROT_NORMAL",
55 "PROT_READ_INSERT",
56 "PROT_WRITE_STRIP",
57 "PROT_READ_STRIP",
58 "PROT_WRITE_INSERT",
59 "PROT_READ_PASS",
60 "PROT_WRITE_PASS",
61};
62
63static char *dif_grd_str[] = {
64 "NO_GUARD",
65 "DIF_CRC",
66 "DIX_IP",
James Smarte2a0a9d2008-12-04 22:40:02 -050067};
James Smartf9bb2da2011-10-10 21:34:11 -040068
69struct scsi_dif_tuple {
70 __be16 guard_tag; /* Checksum */
71 __be16 app_tag; /* Opaque storage */
72 __be32 ref_tag; /* Target LBA or indirect LBA */
73};
74
James Smartda0436e2009-05-22 14:51:39 -040075static void
76lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
James Smart1c6f4ef52009-11-18 15:40:49 -050077static void
78lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
James Smarte2a0a9d2008-12-04 22:40:02 -050079
80static void
James Smart6a9c52c2009-10-02 15:16:51 -040081lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
James Smarte2a0a9d2008-12-04 22:40:02 -050082{
83 void *src, *dst;
84 struct scatterlist *sgde = scsi_sglist(cmnd);
85
86 if (!_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040087 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
88 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
James Smarte2a0a9d2008-12-04 22:40:02 -050089 __func__);
90 return;
91 }
92
93
94 if (!sgde) {
James Smart6a9c52c2009-10-02 15:16:51 -040095 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
96 "9051 BLKGRD: ERROR: data scatterlist is null\n");
James Smarte2a0a9d2008-12-04 22:40:02 -050097 return;
98 }
99
100 dst = (void *) _dump_buf_data;
101 while (sgde) {
102 src = sg_virt(sgde);
103 memcpy(dst, src, sgde->length);
104 dst += sgde->length;
105 sgde = sg_next(sgde);
106 }
107}
108
109static void
James Smart6a9c52c2009-10-02 15:16:51 -0400110lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
James Smarte2a0a9d2008-12-04 22:40:02 -0500111{
112 void *src, *dst;
113 struct scatterlist *sgde = scsi_prot_sglist(cmnd);
114
115 if (!_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -0400116 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
117 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500118 __func__);
119 return;
120 }
121
122 if (!sgde) {
James Smart6a9c52c2009-10-02 15:16:51 -0400123 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
124 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
James Smarte2a0a9d2008-12-04 22:40:02 -0500125 return;
126 }
127
128 dst = _dump_buf_dif;
129 while (sgde) {
130 src = sg_virt(sgde);
131 memcpy(dst, src, sgde->length);
132 dst += sgde->length;
133 sgde = sg_next(sgde);
134 }
135}
136
James Smartea2151b2008-09-07 11:52:10 -0400137/**
James Smartf1126682009-06-10 17:22:44 -0400138 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
139 * @phba: Pointer to HBA object.
140 * @lpfc_cmd: lpfc scsi command object pointer.
141 *
142 * This function is called from the lpfc_prep_task_mgmt_cmd function to
143 * set the last bit in the response sge entry.
144 **/
145static void
146lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
147 struct lpfc_scsi_buf *lpfc_cmd)
148{
149 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
150 if (sgl) {
151 sgl += 1;
152 sgl->word2 = le32_to_cpu(sgl->word2);
153 bf_set(lpfc_sli4_sge_last, sgl, 1);
154 sgl->word2 = cpu_to_le32(sgl->word2);
155 }
156}
157
158/**
James Smart3621a712009-04-06 18:47:14 -0400159 * lpfc_update_stats - Update statistical data for the command completion
James Smartea2151b2008-09-07 11:52:10 -0400160 * @phba: Pointer to HBA object.
161 * @lpfc_cmd: lpfc scsi command object pointer.
162 *
163 * This function is called when there is a command completion and this
164 * function updates the statistical data for the command completion.
165 **/
166static void
167lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
168{
169 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
170 struct lpfc_nodelist *pnode = rdata->pnode;
171 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
172 unsigned long flags;
173 struct Scsi_Host *shost = cmd->device->host;
174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
175 unsigned long latency;
176 int i;
177
178 if (cmd->result)
179 return;
180
James Smart9f1e1b52008-12-04 22:39:40 -0500181 latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
182
James Smartea2151b2008-09-07 11:52:10 -0400183 spin_lock_irqsave(shost->host_lock, flags);
184 if (!vport->stat_data_enabled ||
185 vport->stat_data_blocked ||
James Smart5989b8d2010-10-22 11:06:56 -0400186 !pnode ||
James Smartea2151b2008-09-07 11:52:10 -0400187 !pnode->lat_data ||
188 (phba->bucket_type == LPFC_NO_BUCKET)) {
189 spin_unlock_irqrestore(shost->host_lock, flags);
190 return;
191 }
James Smartea2151b2008-09-07 11:52:10 -0400192
193 if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
194 i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
195 phba->bucket_step;
James Smart9f1e1b52008-12-04 22:39:40 -0500196 /* check array subscript bounds */
197 if (i < 0)
198 i = 0;
199 else if (i >= LPFC_MAX_BUCKET_COUNT)
200 i = LPFC_MAX_BUCKET_COUNT - 1;
James Smartea2151b2008-09-07 11:52:10 -0400201 } else {
202 for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
203 if (latency <= (phba->bucket_base +
204 ((1<<i)*phba->bucket_step)))
205 break;
206 }
207
208 pnode->lat_data[i].cmd_count++;
209 spin_unlock_irqrestore(shost->host_lock, flags);
210}
211
James Smartea2151b2008-09-07 11:52:10 -0400212/**
James Smart3621a712009-04-06 18:47:14 -0400213 * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
James Smartea2151b2008-09-07 11:52:10 -0400214 * @phba: Pointer to HBA context object.
215 * @vport: Pointer to vport object.
216 * @ndlp: Pointer to FC node associated with the target.
217 * @lun: Lun number of the scsi device.
218 * @old_val: Old value of the queue depth.
219 * @new_val: New value of the queue depth.
220 *
221 * This function sends an event to the mgmt application indicating
222 * there is a change in the scsi device queue depth.
223 **/
224static void
225lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba,
226 struct lpfc_vport *vport,
227 struct lpfc_nodelist *ndlp,
228 uint32_t lun,
229 uint32_t old_val,
230 uint32_t new_val)
231{
232 struct lpfc_fast_path_event *fast_path_evt;
233 unsigned long flags;
234
235 fast_path_evt = lpfc_alloc_fast_evt(phba);
236 if (!fast_path_evt)
237 return;
238
239 fast_path_evt->un.queue_depth_evt.scsi_event.event_type =
240 FC_REG_SCSI_EVENT;
241 fast_path_evt->un.queue_depth_evt.scsi_event.subcategory =
242 LPFC_EVENT_VARQUEDEPTH;
243
244 /* Report all luns with change in queue depth */
245 fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun;
246 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
247 memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn,
248 &ndlp->nlp_portname, sizeof(struct lpfc_name));
249 memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn,
250 &ndlp->nlp_nodename, sizeof(struct lpfc_name));
251 }
252
253 fast_path_evt->un.queue_depth_evt.oldval = old_val;
254 fast_path_evt->un.queue_depth_evt.newval = new_val;
255 fast_path_evt->vport = vport;
256
257 fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
258 spin_lock_irqsave(&phba->hbalock, flags);
259 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
260 spin_unlock_irqrestore(&phba->hbalock, flags);
261 lpfc_worker_wake_up(phba);
262
263 return;
264}
265
James Smart9bad7672008-12-04 22:39:02 -0500266/**
James Smart5ffc2662009-11-18 15:39:44 -0500267 * lpfc_change_queue_depth - Alter scsi device queue depth
268 * @sdev: Pointer the scsi device on which to change the queue depth.
269 * @qdepth: New queue depth to set the sdev to.
270 * @reason: The reason for the queue depth change.
271 *
272 * This function is called by the midlayer and the LLD to alter the queue
273 * depth for a scsi device. This function sets the queue depth to the new
274 * value and sends an event out to log the queue depth change.
275 **/
276int
277lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
278{
279 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
280 struct lpfc_hba *phba = vport->phba;
281 struct lpfc_rport_data *rdata;
282 unsigned long new_queue_depth, old_queue_depth;
283
284 old_queue_depth = sdev->queue_depth;
285 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
286 new_queue_depth = sdev->queue_depth;
287 rdata = sdev->hostdata;
288 if (rdata)
289 lpfc_send_sdev_queuedepth_change_event(phba, vport,
290 rdata->pnode, sdev->lun,
291 old_queue_depth,
292 new_queue_depth);
293 return sdev->queue_depth;
294}
295
296/**
James Smart3621a712009-04-06 18:47:14 -0400297 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
James Smart9bad7672008-12-04 22:39:02 -0500298 * @phba: The Hba for which this call is being executed.
299 *
300 * This routine is called when there is resource error in driver or firmware.
301 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
302 * posts at most 1 event each second. This routine wakes up worker thread of
303 * @phba to process WORKER_RAM_DOWN_EVENT event.
304 *
305 * This routine should be called with no lock held.
306 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500307void
James Smarteaf15d52008-12-04 22:39:29 -0500308lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
James Smart92d7f7b2007-06-17 19:56:38 -0500309{
310 unsigned long flags;
James Smart5e9d9b82008-06-14 22:52:53 -0400311 uint32_t evt_posted;
James Smart92d7f7b2007-06-17 19:56:38 -0500312
313 spin_lock_irqsave(&phba->hbalock, flags);
314 atomic_inc(&phba->num_rsrc_err);
315 phba->last_rsrc_error_time = jiffies;
316
317 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
318 spin_unlock_irqrestore(&phba->hbalock, flags);
319 return;
320 }
321
322 phba->last_ramp_down_time = jiffies;
323
324 spin_unlock_irqrestore(&phba->hbalock, flags);
325
326 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
James Smart5e9d9b82008-06-14 22:52:53 -0400327 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
328 if (!evt_posted)
James Smart92d7f7b2007-06-17 19:56:38 -0500329 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
James Smart92d7f7b2007-06-17 19:56:38 -0500330 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
331
James Smart5e9d9b82008-06-14 22:52:53 -0400332 if (!evt_posted)
333 lpfc_worker_wake_up(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500334 return;
335}
336
James Smart9bad7672008-12-04 22:39:02 -0500337/**
James Smart3621a712009-04-06 18:47:14 -0400338 * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread
James Smart9bad7672008-12-04 22:39:02 -0500339 * @phba: The Hba for which this call is being executed.
340 *
341 * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine
342 * post at most 1 event every 5 minute after last_ramp_up_time or
343 * last_rsrc_error_time. This routine wakes up worker thread of @phba
344 * to process WORKER_RAM_DOWN_EVENT event.
345 *
346 * This routine should be called with no lock held.
347 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500348static inline void
James Smart3de2a652007-08-02 11:09:59 -0400349lpfc_rampup_queue_depth(struct lpfc_vport *vport,
James Smarta257bf92009-04-06 18:48:10 -0400350 uint32_t queue_depth)
James Smart92d7f7b2007-06-17 19:56:38 -0500351{
352 unsigned long flags;
James Smart3de2a652007-08-02 11:09:59 -0400353 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400354 uint32_t evt_posted;
James Smart92d7f7b2007-06-17 19:56:38 -0500355 atomic_inc(&phba->num_cmd_success);
356
James Smarta257bf92009-04-06 18:48:10 -0400357 if (vport->cfg_lun_queue_depth <= queue_depth)
James Smart92d7f7b2007-06-17 19:56:38 -0500358 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500359 spin_lock_irqsave(&phba->hbalock, flags);
James Smart5ffc2662009-11-18 15:39:44 -0500360 if (time_before(jiffies,
361 phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) ||
362 time_before(jiffies,
363 phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500364 spin_unlock_irqrestore(&phba->hbalock, flags);
365 return;
366 }
James Smart92d7f7b2007-06-17 19:56:38 -0500367 phba->last_ramp_up_time = jiffies;
368 spin_unlock_irqrestore(&phba->hbalock, flags);
369
370 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
James Smart5e9d9b82008-06-14 22:52:53 -0400371 evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
372 if (!evt_posted)
James Smart92d7f7b2007-06-17 19:56:38 -0500373 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
James Smart92d7f7b2007-06-17 19:56:38 -0500374 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
375
James Smart5e9d9b82008-06-14 22:52:53 -0400376 if (!evt_posted)
377 lpfc_worker_wake_up(phba);
378 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500379}
380
James Smart9bad7672008-12-04 22:39:02 -0500381/**
James Smart3621a712009-04-06 18:47:14 -0400382 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
James Smart9bad7672008-12-04 22:39:02 -0500383 * @phba: The Hba for which this call is being executed.
384 *
385 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
386 * thread.This routine reduces queue depth for all scsi device on each vport
387 * associated with @phba.
388 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500389void
390lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
391{
James Smart549e55c2007-08-02 11:09:51 -0400392 struct lpfc_vport **vports;
393 struct Scsi_Host *shost;
James Smart92d7f7b2007-06-17 19:56:38 -0500394 struct scsi_device *sdev;
James Smart5ffc2662009-11-18 15:39:44 -0500395 unsigned long new_queue_depth;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 unsigned long num_rsrc_err, num_cmd_success;
James Smart549e55c2007-08-02 11:09:51 -0400397 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
400 num_cmd_success = atomic_read(&phba->num_cmd_success);
401
James Smart549e55c2007-08-02 11:09:51 -0400402 vports = lpfc_create_vport_work_array(phba);
403 if (vports != NULL)
James Smart21e9a0a2009-05-22 14:53:21 -0400404 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400405 shost = lpfc_shost_from_vport(vports[i]);
406 shost_for_each_device(sdev, shost) {
James Smart92d7f7b2007-06-17 19:56:38 -0500407 new_queue_depth =
James Smart549e55c2007-08-02 11:09:51 -0400408 sdev->queue_depth * num_rsrc_err /
409 (num_rsrc_err + num_cmd_success);
410 if (!new_queue_depth)
411 new_queue_depth = sdev->queue_depth - 1;
412 else
413 new_queue_depth = sdev->queue_depth -
414 new_queue_depth;
James Smart5ffc2662009-11-18 15:39:44 -0500415 lpfc_change_queue_depth(sdev, new_queue_depth,
416 SCSI_QDEPTH_DEFAULT);
James Smart549e55c2007-08-02 11:09:51 -0400417 }
James Smart92d7f7b2007-06-17 19:56:38 -0500418 }
James Smart09372822008-01-11 01:52:54 -0500419 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500420 atomic_set(&phba->num_rsrc_err, 0);
421 atomic_set(&phba->num_cmd_success, 0);
422}
423
James Smart9bad7672008-12-04 22:39:02 -0500424/**
James Smart3621a712009-04-06 18:47:14 -0400425 * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler
James Smart9bad7672008-12-04 22:39:02 -0500426 * @phba: The Hba for which this call is being executed.
427 *
428 * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker
429 * thread.This routine increases queue depth for all scsi device on each vport
430 * associated with @phba by 1. This routine also sets @phba num_rsrc_err and
431 * num_cmd_success to zero.
432 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500433void
434lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
435{
James Smart549e55c2007-08-02 11:09:51 -0400436 struct lpfc_vport **vports;
437 struct Scsi_Host *shost;
James Smart92d7f7b2007-06-17 19:56:38 -0500438 struct scsi_device *sdev;
James Smart549e55c2007-08-02 11:09:51 -0400439 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500440
James Smart549e55c2007-08-02 11:09:51 -0400441 vports = lpfc_create_vport_work_array(phba);
442 if (vports != NULL)
James Smart21e9a0a2009-05-22 14:53:21 -0400443 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400444 shost = lpfc_shost_from_vport(vports[i]);
445 shost_for_each_device(sdev, shost) {
James Smart97eab632008-04-07 10:16:05 -0400446 if (vports[i]->cfg_lun_queue_depth <=
447 sdev->queue_depth)
448 continue;
James Smart5ffc2662009-11-18 15:39:44 -0500449 lpfc_change_queue_depth(sdev,
450 sdev->queue_depth+1,
451 SCSI_QDEPTH_RAMP_UP);
James Smart549e55c2007-08-02 11:09:51 -0400452 }
James Smart92d7f7b2007-06-17 19:56:38 -0500453 }
James Smart09372822008-01-11 01:52:54 -0500454 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500455 atomic_set(&phba->num_rsrc_err, 0);
456 atomic_set(&phba->num_cmd_success, 0);
457}
458
James Smarta8e497d2008-08-24 21:50:11 -0400459/**
James Smart3621a712009-04-06 18:47:14 -0400460 * lpfc_scsi_dev_block - set all scsi hosts to block state
James Smarta8e497d2008-08-24 21:50:11 -0400461 * @phba: Pointer to HBA context object.
462 *
463 * This function walks vport list and set each SCSI host to block state
464 * by invoking fc_remote_port_delete() routine. This function is invoked
465 * with EEH when device's PCI slot has been permanently disabled.
466 **/
467void
468lpfc_scsi_dev_block(struct lpfc_hba *phba)
469{
470 struct lpfc_vport **vports;
471 struct Scsi_Host *shost;
472 struct scsi_device *sdev;
473 struct fc_rport *rport;
474 int i;
475
476 vports = lpfc_create_vport_work_array(phba);
477 if (vports != NULL)
James Smart21e9a0a2009-05-22 14:53:21 -0400478 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8e497d2008-08-24 21:50:11 -0400479 shost = lpfc_shost_from_vport(vports[i]);
480 shost_for_each_device(sdev, shost) {
481 rport = starget_to_rport(scsi_target(sdev));
482 fc_remote_port_delete(rport);
483 }
484 }
485 lpfc_destroy_vport_work_array(phba, vports);
486}
487
James Smart9bad7672008-12-04 22:39:02 -0500488/**
James Smart3772a992009-05-22 14:50:54 -0400489 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
James Smart9bad7672008-12-04 22:39:02 -0500490 * @vport: The virtual port for which this call being executed.
James Smart3772a992009-05-22 14:50:54 -0400491 * @num_to_allocate: The requested number of buffers to allocate.
James Smart9bad7672008-12-04 22:39:02 -0500492 *
James Smart3772a992009-05-22 14:50:54 -0400493 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
494 * the scsi buffer contains all the necessary information needed to initiate
495 * a SCSI I/O. The non-DMAable buffer region contains information to build
496 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
497 * and the initial BPL. In addition to allocating memory, the FCP CMND and
498 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
James Smart9bad7672008-12-04 22:39:02 -0500499 *
500 * Return codes:
James Smart3772a992009-05-22 14:50:54 -0400501 * int - number of scsi buffers that were allocated.
502 * 0 = failure, less than num_to_alloc is a partial failure.
James Smart9bad7672008-12-04 22:39:02 -0500503 **/
James Smart3772a992009-05-22 14:50:54 -0400504static int
505lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500508 struct lpfc_scsi_buf *psb;
509 struct ulp_bde64 *bpl;
510 IOCB_t *iocb;
James Smart34b02dc2008-08-24 21:49:55 -0400511 dma_addr_t pdma_phys_fcp_cmd;
512 dma_addr_t pdma_phys_fcp_rsp;
513 dma_addr_t pdma_phys_bpl;
James Bottomley604a3e32005-10-29 10:28:33 -0500514 uint16_t iotag;
James Smart3772a992009-05-22 14:50:54 -0400515 int bcnt;
dea31012005-04-17 16:05:31 -0500516
James Smart3772a992009-05-22 14:50:54 -0400517 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
518 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
519 if (!psb)
520 break;
dea31012005-04-17 16:05:31 -0500521
James Smart3772a992009-05-22 14:50:54 -0400522 /*
523 * Get memory from the pci pool to map the virt space to pci
524 * bus space for an I/O. The DMA buffer includes space for the
525 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
526 * necessary to support the sg_tablesize.
527 */
528 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
529 GFP_KERNEL, &psb->dma_handle);
530 if (!psb->data) {
531 kfree(psb);
532 break;
533 }
dea31012005-04-17 16:05:31 -0500534
James Smart3772a992009-05-22 14:50:54 -0400535 /* Initialize virtual ptrs to dma_buf region. */
536 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
dea31012005-04-17 16:05:31 -0500537
James Smart3772a992009-05-22 14:50:54 -0400538 /* Allocate iotag for psb->cur_iocbq. */
539 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
540 if (iotag == 0) {
541 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
542 psb->data, psb->dma_handle);
543 kfree(psb);
544 break;
545 }
546 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
James Bottomley604a3e32005-10-29 10:28:33 -0500547
James Smart3772a992009-05-22 14:50:54 -0400548 psb->fcp_cmnd = psb->data;
549 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
550 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
James Smart34b02dc2008-08-24 21:49:55 -0400551 sizeof(struct fcp_rsp);
dea31012005-04-17 16:05:31 -0500552
James Smart3772a992009-05-22 14:50:54 -0400553 /* Initialize local short-hand pointers. */
554 bpl = psb->fcp_bpl;
555 pdma_phys_fcp_cmd = psb->dma_handle;
556 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
557 pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
558 sizeof(struct fcp_rsp);
dea31012005-04-17 16:05:31 -0500559
James Smart3772a992009-05-22 14:50:54 -0400560 /*
561 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
562 * are sg list bdes. Initialize the first two and leave the
563 * rest for queuecommand.
564 */
565 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
566 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
567 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
568 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
569 bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
dea31012005-04-17 16:05:31 -0500570
James Smart3772a992009-05-22 14:50:54 -0400571 /* Setup the physical region for the FCP RSP */
572 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
573 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
574 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
575 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
576 bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
577
578 /*
579 * Since the IOCB for the FCP I/O is built into this
580 * lpfc_scsi_buf, initialize it with all known data now.
581 */
582 iocb = &psb->cur_iocbq.iocb;
583 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
584 if ((phba->sli_rev == 3) &&
585 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
586 /* fill in immediate fcp command BDE */
587 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
588 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
589 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
590 unsli3.fcp_ext.icd);
591 iocb->un.fcpi64.bdl.addrHigh = 0;
592 iocb->ulpBdeCount = 0;
593 iocb->ulpLe = 0;
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300594 /* fill in response BDE */
James Smart3772a992009-05-22 14:50:54 -0400595 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
596 BUFF_TYPE_BDE_64;
597 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
598 sizeof(struct fcp_rsp);
599 iocb->unsli3.fcp_ext.rbde.addrLow =
600 putPaddrLow(pdma_phys_fcp_rsp);
601 iocb->unsli3.fcp_ext.rbde.addrHigh =
602 putPaddrHigh(pdma_phys_fcp_rsp);
603 } else {
604 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
605 iocb->un.fcpi64.bdl.bdeSize =
606 (2 * sizeof(struct ulp_bde64));
607 iocb->un.fcpi64.bdl.addrLow =
608 putPaddrLow(pdma_phys_bpl);
609 iocb->un.fcpi64.bdl.addrHigh =
610 putPaddrHigh(pdma_phys_bpl);
611 iocb->ulpBdeCount = 1;
612 iocb->ulpLe = 1;
613 }
614 iocb->ulpClass = CLASS3;
615 psb->status = IOSTAT_SUCCESS;
James Smartda0436e2009-05-22 14:51:39 -0400616 /* Put it back into the SCSI buffer list */
James Smarteee88772010-09-29 11:19:08 -0400617 psb->cur_iocbq.context1 = psb;
James Smart1c6f4ef52009-11-18 15:40:49 -0500618 lpfc_release_scsi_buf_s3(phba, psb);
James Smart3772a992009-05-22 14:50:54 -0400619
James Smart34b02dc2008-08-24 21:49:55 -0400620 }
dea31012005-04-17 16:05:31 -0500621
James Smart3772a992009-05-22 14:50:54 -0400622 return bcnt;
dea31012005-04-17 16:05:31 -0500623}
624
James Smart9bad7672008-12-04 22:39:02 -0500625/**
James Smart1151e3e2011-02-16 12:39:35 -0500626 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
627 * @vport: pointer to lpfc vport data structure.
628 *
629 * This routine is invoked by the vport cleanup for deletions and the cleanup
630 * for an ndlp on removal.
631 **/
632void
633lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
634{
635 struct lpfc_hba *phba = vport->phba;
636 struct lpfc_scsi_buf *psb, *next_psb;
637 unsigned long iflag = 0;
638
639 spin_lock_irqsave(&phba->hbalock, iflag);
640 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
641 list_for_each_entry_safe(psb, next_psb,
642 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
643 if (psb->rdata && psb->rdata->pnode
644 && psb->rdata->pnode->vport == vport)
645 psb->rdata = NULL;
646 }
647 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
648 spin_unlock_irqrestore(&phba->hbalock, iflag);
649}
650
651/**
James Smartda0436e2009-05-22 14:51:39 -0400652 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
653 * @phba: pointer to lpfc hba data structure.
654 * @axri: pointer to the fcp xri abort wcqe structure.
655 *
656 * This routine is invoked by the worker thread to process a SLI4 fast-path
657 * FCP aborted xri.
658 **/
659void
660lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
661 struct sli4_wcqe_xri_aborted *axri)
662{
663 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -0500664 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smartda0436e2009-05-22 14:51:39 -0400665 struct lpfc_scsi_buf *psb, *next_psb;
666 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500667 struct lpfc_iocbq *iocbq;
668 int i;
James Smart19ca7602010-11-20 23:11:55 -0500669 struct lpfc_nodelist *ndlp;
670 int rrq_empty = 0;
James Smart589a52d2010-07-14 15:30:54 -0400671 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smartda0436e2009-05-22 14:51:39 -0400672
James Smart0f65ff62010-02-26 14:14:23 -0500673 spin_lock_irqsave(&phba->hbalock, iflag);
674 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
James Smartda0436e2009-05-22 14:51:39 -0400675 list_for_each_entry_safe(psb, next_psb,
676 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
677 if (psb->cur_iocbq.sli4_xritag == xri) {
678 list_del(&psb->list);
James Smart341af102010-01-26 23:07:37 -0500679 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400680 psb->status = IOSTAT_SUCCESS;
James Smart0f65ff62010-02-26 14:14:23 -0500681 spin_unlock(
682 &phba->sli4_hba.abts_scsi_buf_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -0500683 if (psb->rdata && psb->rdata->pnode)
684 ndlp = psb->rdata->pnode;
685 else
686 ndlp = NULL;
687
James Smart19ca7602010-11-20 23:11:55 -0500688 rrq_empty = list_empty(&phba->active_rrq_list);
James Smart0f65ff62010-02-26 14:14:23 -0500689 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartcb69f7d2011-12-13 13:21:57 -0500690 if (ndlp) {
James Smart19ca7602010-11-20 23:11:55 -0500691 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smartcb69f7d2011-12-13 13:21:57 -0500692 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
693 }
James Smartda0436e2009-05-22 14:51:39 -0400694 lpfc_release_scsi_buf_s4(phba, psb);
James Smart19ca7602010-11-20 23:11:55 -0500695 if (rrq_empty)
696 lpfc_worker_wake_up(phba);
James Smartda0436e2009-05-22 14:51:39 -0400697 return;
698 }
699 }
James Smart0f65ff62010-02-26 14:14:23 -0500700 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
701 for (i = 1; i <= phba->sli.last_iotag; i++) {
702 iocbq = phba->sli.iocbq_lookup[i];
703
704 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
705 (iocbq->iocb_flag & LPFC_IO_LIBDFC))
706 continue;
707 if (iocbq->sli4_xritag != xri)
708 continue;
709 psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
710 psb->exch_busy = 0;
711 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -0400712 if (pring->txq_cnt)
713 lpfc_worker_wake_up(phba);
James Smart0f65ff62010-02-26 14:14:23 -0500714 return;
715
716 }
717 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartda0436e2009-05-22 14:51:39 -0400718}
719
720/**
721 * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block
722 * @phba: pointer to lpfc hba data structure.
723 *
724 * This routine walks the list of scsi buffers that have been allocated and
725 * repost them to the HBA by using SGL block post. This is needed after a
726 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
727 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
728 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
729 *
730 * Returns: 0 = success, non-zero failure.
731 **/
732int
733lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba)
734{
735 struct lpfc_scsi_buf *psb;
736 int index, status, bcnt = 0, rcnt = 0, rc = 0;
737 LIST_HEAD(sblist);
738
739 for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) {
740 psb = phba->sli4_hba.lpfc_scsi_psb_array[index];
741 if (psb) {
742 /* Remove from SCSI buffer list */
743 list_del(&psb->list);
744 /* Add it to a local SCSI buffer list */
745 list_add_tail(&psb->list, &sblist);
746 if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) {
747 bcnt = rcnt;
748 rcnt = 0;
749 }
750 } else
751 /* A hole present in the XRI array, need to skip */
752 bcnt = rcnt;
753
754 if (index == phba->sli4_hba.scsi_xri_cnt - 1)
755 /* End of XRI array for SCSI buffer, complete */
756 bcnt = rcnt;
757
758 /* Continue until collect up to a nembed page worth of sgls */
759 if (bcnt == 0)
760 continue;
761 /* Now, post the SCSI buffer list sgls as a block */
James Smart6d368e52011-05-24 11:44:12 -0400762 if (!phba->sli4_hba.extents_in_use)
763 status = lpfc_sli4_post_scsi_sgl_block(phba,
764 &sblist,
765 bcnt);
766 else
767 status = lpfc_sli4_post_scsi_sgl_blk_ext(phba,
768 &sblist,
769 bcnt);
James Smartda0436e2009-05-22 14:51:39 -0400770 /* Reset SCSI buffer count for next round of posting */
771 bcnt = 0;
772 while (!list_empty(&sblist)) {
773 list_remove_head(&sblist, psb, struct lpfc_scsi_buf,
774 list);
775 if (status) {
776 /* Put this back on the abort scsi list */
James Smart341af102010-01-26 23:07:37 -0500777 psb->exch_busy = 1;
James Smartda0436e2009-05-22 14:51:39 -0400778 rc++;
James Smart341af102010-01-26 23:07:37 -0500779 } else {
780 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400781 psb->status = IOSTAT_SUCCESS;
James Smart341af102010-01-26 23:07:37 -0500782 }
James Smartda0436e2009-05-22 14:51:39 -0400783 /* Put it back into the SCSI buffer list */
784 lpfc_release_scsi_buf_s4(phba, psb);
785 }
786 }
787 return rc;
788}
789
790/**
791 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
792 * @vport: The virtual port for which this call being executed.
793 * @num_to_allocate: The requested number of buffers to allocate.
794 *
795 * This routine allocates a scsi buffer for device with SLI-4 interface spec,
796 * the scsi buffer contains all the necessary information needed to initiate
797 * a SCSI I/O.
798 *
799 * Return codes:
800 * int - number of scsi buffers that were allocated.
801 * 0 = failure, less than num_to_alloc is a partial failure.
802 **/
803static int
804lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
805{
806 struct lpfc_hba *phba = vport->phba;
807 struct lpfc_scsi_buf *psb;
808 struct sli4_sge *sgl;
809 IOCB_t *iocb;
810 dma_addr_t pdma_phys_fcp_cmd;
811 dma_addr_t pdma_phys_fcp_rsp;
812 dma_addr_t pdma_phys_bpl, pdma_phys_bpl1;
James Smart6d368e52011-05-24 11:44:12 -0400813 uint16_t iotag, last_xritag = NO_XRI, lxri = 0;
James Smartda0436e2009-05-22 14:51:39 -0400814 int status = 0, index;
815 int bcnt;
816 int non_sequential_xri = 0;
James Smartda0436e2009-05-22 14:51:39 -0400817 LIST_HEAD(sblist);
818
819 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
820 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
821 if (!psb)
822 break;
823
824 /*
825 * Get memory from the pci pool to map the virt space to pci bus
826 * space for an I/O. The DMA buffer includes space for the
827 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
828 * necessary to support the sg_tablesize.
829 */
830 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
831 GFP_KERNEL, &psb->dma_handle);
832 if (!psb->data) {
833 kfree(psb);
834 break;
835 }
836
837 /* Initialize virtual ptrs to dma_buf region. */
838 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
839
840 /* Allocate iotag for psb->cur_iocbq. */
841 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
842 if (iotag == 0) {
James Smartb92938b2010-06-07 15:24:12 -0400843 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
844 psb->data, psb->dma_handle);
James Smartda0436e2009-05-22 14:51:39 -0400845 kfree(psb);
846 break;
847 }
848
James Smart6d368e52011-05-24 11:44:12 -0400849 lxri = lpfc_sli4_next_xritag(phba);
850 if (lxri == NO_XRI) {
James Smartda0436e2009-05-22 14:51:39 -0400851 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
852 psb->data, psb->dma_handle);
853 kfree(psb);
854 break;
855 }
James Smart6d368e52011-05-24 11:44:12 -0400856 psb->cur_iocbq.sli4_lxritag = lxri;
857 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
James Smartda0436e2009-05-22 14:51:39 -0400858 if (last_xritag != NO_XRI
859 && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) {
860 non_sequential_xri = 1;
861 } else
862 list_add_tail(&psb->list, &sblist);
863 last_xritag = psb->cur_iocbq.sli4_xritag;
864
865 index = phba->sli4_hba.scsi_xri_cnt++;
866 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
867
868 psb->fcp_bpl = psb->data;
869 psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size)
870 - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
871 psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd +
872 sizeof(struct fcp_cmnd));
873
874 /* Initialize local short-hand pointers. */
875 sgl = (struct sli4_sge *)psb->fcp_bpl;
876 pdma_phys_bpl = psb->dma_handle;
877 pdma_phys_fcp_cmd =
878 (psb->dma_handle + phba->cfg_sg_dma_buf_size)
879 - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
880 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
881
882 /*
883 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
884 * are sg list bdes. Initialize the first two and leave the
885 * rest for queuecommand.
886 */
887 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
888 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
James Smart05580562011-05-24 11:40:48 -0400889 sgl->word2 = le32_to_cpu(sgl->word2);
James Smartda0436e2009-05-22 14:51:39 -0400890 bf_set(lpfc_sli4_sge_last, sgl, 0);
891 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart28baac72010-02-12 14:42:03 -0500892 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
James Smartda0436e2009-05-22 14:51:39 -0400893 sgl++;
894
895 /* Setup the physical region for the FCP RSP */
896 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
897 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
James Smart05580562011-05-24 11:40:48 -0400898 sgl->word2 = le32_to_cpu(sgl->word2);
James Smartda0436e2009-05-22 14:51:39 -0400899 bf_set(lpfc_sli4_sge_last, sgl, 1);
900 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart28baac72010-02-12 14:42:03 -0500901 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
James Smartda0436e2009-05-22 14:51:39 -0400902
903 /*
904 * Since the IOCB for the FCP I/O is built into this
905 * lpfc_scsi_buf, initialize it with all known data now.
906 */
907 iocb = &psb->cur_iocbq.iocb;
908 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
909 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
910 /* setting the BLP size to 2 * sizeof BDE may not be correct.
911 * We are setting the bpl to point to out sgl. An sgl's
912 * entries are 16 bytes, a bpl entries are 12 bytes.
913 */
914 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
915 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
916 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
917 iocb->ulpBdeCount = 1;
918 iocb->ulpLe = 1;
919 iocb->ulpClass = CLASS3;
James Smarteee88772010-09-29 11:19:08 -0400920 psb->cur_iocbq.context1 = psb;
James Smartda0436e2009-05-22 14:51:39 -0400921 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
922 pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE;
923 else
924 pdma_phys_bpl1 = 0;
925 psb->dma_phys_bpl = pdma_phys_bpl;
926 phba->sli4_hba.lpfc_scsi_psb_array[index] = psb;
927 if (non_sequential_xri) {
928 status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl,
929 pdma_phys_bpl1,
930 psb->cur_iocbq.sli4_xritag);
931 if (status) {
932 /* Put this back on the abort scsi list */
James Smart341af102010-01-26 23:07:37 -0500933 psb->exch_busy = 1;
James Smart341af102010-01-26 23:07:37 -0500934 } else {
935 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400936 psb->status = IOSTAT_SUCCESS;
James Smart341af102010-01-26 23:07:37 -0500937 }
James Smartda0436e2009-05-22 14:51:39 -0400938 /* Put it back into the SCSI buffer list */
939 lpfc_release_scsi_buf_s4(phba, psb);
940 break;
941 }
942 }
943 if (bcnt) {
James Smart6d368e52011-05-24 11:44:12 -0400944 if (!phba->sli4_hba.extents_in_use)
945 status = lpfc_sli4_post_scsi_sgl_block(phba,
946 &sblist,
947 bcnt);
948 else
949 status = lpfc_sli4_post_scsi_sgl_blk_ext(phba,
950 &sblist,
951 bcnt);
952
953 if (status) {
954 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
955 "3021 SCSI SGL post error %d\n",
956 status);
957 bcnt = 0;
958 }
James Smartda0436e2009-05-22 14:51:39 -0400959 /* Reset SCSI buffer count for next round of posting */
960 while (!list_empty(&sblist)) {
961 list_remove_head(&sblist, psb, struct lpfc_scsi_buf,
962 list);
963 if (status) {
964 /* Put this back on the abort scsi list */
James Smart341af102010-01-26 23:07:37 -0500965 psb->exch_busy = 1;
James Smart341af102010-01-26 23:07:37 -0500966 } else {
967 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400968 psb->status = IOSTAT_SUCCESS;
James Smart341af102010-01-26 23:07:37 -0500969 }
James Smartda0436e2009-05-22 14:51:39 -0400970 /* Put it back into the SCSI buffer list */
971 lpfc_release_scsi_buf_s4(phba, psb);
972 }
973 }
974
James Smartd7c47992010-06-08 18:31:54 -0400975 return bcnt + non_sequential_xri;
James Smartda0436e2009-05-22 14:51:39 -0400976}
977
978/**
James Smart3772a992009-05-22 14:50:54 -0400979 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
980 * @vport: The virtual port for which this call being executed.
981 * @num_to_allocate: The requested number of buffers to allocate.
982 *
983 * This routine wraps the actual SCSI buffer allocator function pointer from
984 * the lpfc_hba struct.
985 *
986 * Return codes:
987 * int - number of scsi buffers that were allocated.
988 * 0 = failure, less than num_to_alloc is a partial failure.
989 **/
990static inline int
991lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc)
992{
993 return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc);
994}
995
996/**
James Smart19ca7602010-11-20 23:11:55 -0500997 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
James Smart3772a992009-05-22 14:50:54 -0400998 * @phba: The HBA for which this call is being executed.
James Smart9bad7672008-12-04 22:39:02 -0500999 *
1000 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1001 * and returns to caller.
1002 *
1003 * Return codes:
1004 * NULL - Error
1005 * Pointer to lpfc_scsi_buf - Success
1006 **/
Adrian Bunk455c53e2006-01-06 20:21:28 +01001007static struct lpfc_scsi_buf*
James Smart19ca7602010-11-20 23:11:55 -05001008lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001009{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001010 struct lpfc_scsi_buf * lpfc_cmd = NULL;
1011 struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001012 unsigned long iflag = 0;
dea31012005-04-17 16:05:31 -05001013
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001014 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001015 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
James Smart1dcb58e2007-04-25 09:51:30 -04001016 if (lpfc_cmd) {
1017 lpfc_cmd->seg_cnt = 0;
1018 lpfc_cmd->nonsg_phys = 0;
James Smarte2a0a9d2008-12-04 22:40:02 -05001019 lpfc_cmd->prot_seg_cnt = 0;
James Smart1dcb58e2007-04-25 09:51:30 -04001020 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001021 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001022 return lpfc_cmd;
1023}
James Smart19ca7602010-11-20 23:11:55 -05001024/**
1025 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1026 * @phba: The HBA for which this call is being executed.
1027 *
1028 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1029 * and returns to caller.
1030 *
1031 * Return codes:
1032 * NULL - Error
1033 * Pointer to lpfc_scsi_buf - Success
1034 **/
1035static struct lpfc_scsi_buf*
1036lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1037{
James Smart1151e3e2011-02-16 12:39:35 -05001038 struct lpfc_scsi_buf *lpfc_cmd ;
James Smart19ca7602010-11-20 23:11:55 -05001039 unsigned long iflag = 0;
1040 int found = 0;
1041
1042 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -05001043 list_for_each_entry(lpfc_cmd, &phba->lpfc_scsi_buf_list,
1044 list) {
James Smart19ca7602010-11-20 23:11:55 -05001045 if (lpfc_test_rrq_active(phba, ndlp,
James Smart1151e3e2011-02-16 12:39:35 -05001046 lpfc_cmd->cur_iocbq.sli4_xritag))
1047 continue;
1048 list_del(&lpfc_cmd->list);
James Smart19ca7602010-11-20 23:11:55 -05001049 found = 1;
1050 lpfc_cmd->seg_cnt = 0;
1051 lpfc_cmd->nonsg_phys = 0;
1052 lpfc_cmd->prot_seg_cnt = 0;
James Smart1151e3e2011-02-16 12:39:35 -05001053 break;
James Smart19ca7602010-11-20 23:11:55 -05001054 }
James Smart1151e3e2011-02-16 12:39:35 -05001055 spin_unlock_irqrestore(&phba->scsi_buf_list_lock,
1056 iflag);
1057 if (!found)
1058 return NULL;
1059 else
1060 return lpfc_cmd;
James Smart19ca7602010-11-20 23:11:55 -05001061}
1062/**
1063 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1064 * @phba: The HBA for which this call is being executed.
1065 *
1066 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1067 * and returns to caller.
1068 *
1069 * Return codes:
1070 * NULL - Error
1071 * Pointer to lpfc_scsi_buf - Success
1072 **/
1073static struct lpfc_scsi_buf*
1074lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1075{
1076 return phba->lpfc_get_scsi_buf(phba, ndlp);
1077}
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001078
James Smart9bad7672008-12-04 22:39:02 -05001079/**
James Smart3772a992009-05-22 14:50:54 -04001080 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
James Smart9bad7672008-12-04 22:39:02 -05001081 * @phba: The Hba for which this call is being executed.
1082 * @psb: The scsi buffer which is being released.
1083 *
1084 * This routine releases @psb scsi buffer by adding it to tail of @phba
1085 * lpfc_scsi_buf_list list.
1086 **/
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001087static void
James Smart3772a992009-05-22 14:50:54 -04001088lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001089{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001090 unsigned long iflag = 0;
dea31012005-04-17 16:05:31 -05001091
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001092 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001093 psb->pCmd = NULL;
dea31012005-04-17 16:05:31 -05001094 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001095 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
dea31012005-04-17 16:05:31 -05001096}
1097
James Smart9bad7672008-12-04 22:39:02 -05001098/**
James Smartda0436e2009-05-22 14:51:39 -04001099 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
1100 * @phba: The Hba for which this call is being executed.
1101 * @psb: The scsi buffer which is being released.
1102 *
1103 * This routine releases @psb scsi buffer by adding it to tail of @phba
1104 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
1105 * and cannot be reused for at least RA_TOV amount of time if it was
1106 * aborted.
1107 **/
1108static void
1109lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1110{
1111 unsigned long iflag = 0;
1112
James Smart341af102010-01-26 23:07:37 -05001113 if (psb->exch_busy) {
James Smartda0436e2009-05-22 14:51:39 -04001114 spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
1115 iflag);
1116 psb->pCmd = NULL;
1117 list_add_tail(&psb->list,
1118 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
1119 spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock,
1120 iflag);
1121 } else {
1122
1123 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
1124 psb->pCmd = NULL;
1125 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
1126 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
1127 }
1128}
1129
1130/**
James Smart3772a992009-05-22 14:50:54 -04001131 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
1132 * @phba: The Hba for which this call is being executed.
1133 * @psb: The scsi buffer which is being released.
1134 *
1135 * This routine releases @psb scsi buffer by adding it to tail of @phba
1136 * lpfc_scsi_buf_list list.
1137 **/
1138static void
1139lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1140{
1141
1142 phba->lpfc_release_scsi_buf(phba, psb);
1143}
1144
1145/**
1146 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
James Smart9bad7672008-12-04 22:39:02 -05001147 * @phba: The Hba for which this call is being executed.
1148 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1149 *
1150 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
James Smart3772a992009-05-22 14:50:54 -04001151 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1152 * through sg elements and format the bdea. This routine also initializes all
1153 * IOCB fields which are dependent on scsi command request buffer.
James Smart9bad7672008-12-04 22:39:02 -05001154 *
1155 * Return codes:
1156 * 1 - Error
1157 * 0 - Success
1158 **/
dea31012005-04-17 16:05:31 -05001159static int
James Smart3772a992009-05-22 14:50:54 -04001160lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
dea31012005-04-17 16:05:31 -05001161{
1162 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
1163 struct scatterlist *sgel = NULL;
1164 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
1165 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
James Smart0f65ff62010-02-26 14:14:23 -05001166 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
dea31012005-04-17 16:05:31 -05001167 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
James Smart34b02dc2008-08-24 21:49:55 -04001168 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
dea31012005-04-17 16:05:31 -05001169 dma_addr_t physaddr;
James Smart34b02dc2008-08-24 21:49:55 -04001170 uint32_t num_bde = 0;
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05001171 int nseg, datadir = scsi_cmnd->sc_data_direction;
dea31012005-04-17 16:05:31 -05001172
1173 /*
1174 * There are three possibilities here - use scatter-gather segment, use
1175 * the single mapping, or neither. Start the lpfc command prep by
1176 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1177 * data bde entry.
1178 */
1179 bpl += 2;
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -07001180 if (scsi_sg_count(scsi_cmnd)) {
dea31012005-04-17 16:05:31 -05001181 /*
1182 * The driver stores the segment count returned from pci_map_sg
1183 * because this a count of dma-mappings used to map the use_sg
1184 * pages. They are not guaranteed to be the same for those
1185 * architectures that implement an IOMMU.
1186 */
dea31012005-04-17 16:05:31 -05001187
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -07001188 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
1189 scsi_sg_count(scsi_cmnd), datadir);
1190 if (unlikely(!nseg))
1191 return 1;
1192
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05001193 lpfc_cmd->seg_cnt = nseg;
dea31012005-04-17 16:05:31 -05001194 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04001195 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1196 "9064 BLKGRD: %s: Too many sg segments from "
James Smarte2a0a9d2008-12-04 22:40:02 -05001197 "dma_map_sg. Config %d, seg_cnt %d\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07001198 __func__, phba->cfg_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05001199 lpfc_cmd->seg_cnt);
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05001200 scsi_dma_unmap(scsi_cmnd);
dea31012005-04-17 16:05:31 -05001201 return 1;
1202 }
1203
1204 /*
1205 * The driver established a maximum scatter-gather segment count
1206 * during probe that limits the number of sg elements in any
1207 * single scsi command. Just run through the seg_cnt and format
1208 * the bde's.
James Smart34b02dc2008-08-24 21:49:55 -04001209 * When using SLI-3 the driver will try to fit all the BDEs into
1210 * the IOCB. If it can't then the BDEs get added to a BPL as it
1211 * does for SLI-2 mode.
dea31012005-04-17 16:05:31 -05001212 */
James Smart34b02dc2008-08-24 21:49:55 -04001213 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
dea31012005-04-17 16:05:31 -05001214 physaddr = sg_dma_address(sgel);
James Smart34b02dc2008-08-24 21:49:55 -04001215 if (phba->sli_rev == 3 &&
James Smarte2a0a9d2008-12-04 22:40:02 -05001216 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
James Smart0f65ff62010-02-26 14:14:23 -05001217 !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
James Smart34b02dc2008-08-24 21:49:55 -04001218 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
1219 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1220 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
1221 data_bde->addrLow = putPaddrLow(physaddr);
1222 data_bde->addrHigh = putPaddrHigh(physaddr);
1223 data_bde++;
1224 } else {
1225 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1226 bpl->tus.f.bdeSize = sg_dma_len(sgel);
1227 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1228 bpl->addrLow =
1229 le32_to_cpu(putPaddrLow(physaddr));
1230 bpl->addrHigh =
1231 le32_to_cpu(putPaddrHigh(physaddr));
1232 bpl++;
1233 }
dea31012005-04-17 16:05:31 -05001234 }
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -07001235 }
dea31012005-04-17 16:05:31 -05001236
1237 /*
1238 * Finish initializing those IOCB fields that are dependent on the
James Smart34b02dc2008-08-24 21:49:55 -04001239 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1240 * explicitly reinitialized and for SLI-3 the extended bde count is
1241 * explicitly reinitialized since all iocb memory resources are reused.
dea31012005-04-17 16:05:31 -05001242 */
James Smarte2a0a9d2008-12-04 22:40:02 -05001243 if (phba->sli_rev == 3 &&
James Smart0f65ff62010-02-26 14:14:23 -05001244 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
1245 !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
James Smart34b02dc2008-08-24 21:49:55 -04001246 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
1247 /*
1248 * The extended IOCB format can only fit 3 BDE or a BPL.
1249 * This I/O has more than 3 BDE so the 1st data bde will
1250 * be a BPL that is filled in here.
1251 */
1252 physaddr = lpfc_cmd->dma_handle;
1253 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
1254 data_bde->tus.f.bdeSize = (num_bde *
1255 sizeof(struct ulp_bde64));
1256 physaddr += (sizeof(struct fcp_cmnd) +
1257 sizeof(struct fcp_rsp) +
1258 (2 * sizeof(struct ulp_bde64)));
1259 data_bde->addrHigh = putPaddrHigh(physaddr);
1260 data_bde->addrLow = putPaddrLow(physaddr);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001261 /* ebde count includes the response bde and data bpl */
James Smart34b02dc2008-08-24 21:49:55 -04001262 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
1263 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001264 /* ebde count includes the response bde and data bdes */
James Smart34b02dc2008-08-24 21:49:55 -04001265 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1266 }
1267 } else {
1268 iocb_cmd->un.fcpi64.bdl.bdeSize =
1269 ((num_bde + 2) * sizeof(struct ulp_bde64));
James Smart0f65ff62010-02-26 14:14:23 -05001270 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
James Smart34b02dc2008-08-24 21:49:55 -04001271 }
James Smart09372822008-01-11 01:52:54 -05001272 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
James Smarte2a0a9d2008-12-04 22:40:02 -05001273
1274 /*
1275 * Due to difference in data length between DIF/non-DIF paths,
1276 * we need to set word 4 of IOCB here
1277 */
James Smarta257bf92009-04-06 18:48:10 -04001278 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
dea31012005-04-17 16:05:31 -05001279 return 0;
1280}
1281
James Smartf9bb2da2011-10-10 21:34:11 -04001282static inline unsigned
1283lpfc_cmd_blksize(struct scsi_cmnd *sc)
1284{
1285 return sc->device->sector_size;
1286}
1287
1288#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smartacd68592012-01-18 16:25:09 -05001289
James Smart9a6b09c2012-03-01 22:37:42 -05001290/* Return if if error injection is detected by Initiator */
1291#define BG_ERR_INIT 0x1
1292/* Return if if error injection is detected by Target */
1293#define BG_ERR_TGT 0x2
1294/* Return if if swapping CSUM<-->CRC is required for error injection */
1295#define BG_ERR_SWAP 0x10
1296/* Return if disabling Guard/Ref/App checking is required for error injection */
1297#define BG_ERR_CHECK 0x20
James Smartacd68592012-01-18 16:25:09 -05001298
1299/**
1300 * lpfc_bg_err_inject - Determine if we should inject an error
1301 * @phba: The Hba for which this call is being executed.
James Smartf9bb2da2011-10-10 21:34:11 -04001302 * @sc: The SCSI command to examine
1303 * @reftag: (out) BlockGuard reference tag for transmitted data
1304 * @apptag: (out) BlockGuard application tag for transmitted data
1305 * @new_guard (in) Value to replace CRC with if needed
1306 *
James Smart9a6b09c2012-03-01 22:37:42 -05001307 * Returns BG_ERR_* bit mask or 0 if request ignored
James Smartacd68592012-01-18 16:25:09 -05001308 **/
James Smartf9bb2da2011-10-10 21:34:11 -04001309static int
1310lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1311 uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
1312{
1313 struct scatterlist *sgpe; /* s/g prot entry */
1314 struct scatterlist *sgde; /* s/g data entry */
James Smart9a6b09c2012-03-01 22:37:42 -05001315 struct lpfc_scsi_buf *lpfc_cmd = NULL;
James Smartacd68592012-01-18 16:25:09 -05001316 struct scsi_dif_tuple *src = NULL;
James Smartf9bb2da2011-10-10 21:34:11 -04001317 uint32_t op = scsi_get_prot_op(sc);
1318 uint32_t blksize;
1319 uint32_t numblks;
1320 sector_t lba;
1321 int rc = 0;
James Smartacd68592012-01-18 16:25:09 -05001322 int blockoff = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04001323
1324 if (op == SCSI_PROT_NORMAL)
1325 return 0;
1326
James Smartacd68592012-01-18 16:25:09 -05001327 sgpe = scsi_prot_sglist(sc);
1328 sgde = scsi_sglist(sc);
1329
James Smartf9bb2da2011-10-10 21:34:11 -04001330 lba = scsi_get_lba(sc);
1331 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
1332 blksize = lpfc_cmd_blksize(sc);
1333 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
1334
1335 /* Make sure we have the right LBA if one is specified */
1336 if ((phba->lpfc_injerr_lba < lba) ||
1337 (phba->lpfc_injerr_lba >= (lba + numblks)))
1338 return 0;
James Smartacd68592012-01-18 16:25:09 -05001339 if (sgpe) {
1340 blockoff = phba->lpfc_injerr_lba - lba;
1341 numblks = sg_dma_len(sgpe) /
1342 sizeof(struct scsi_dif_tuple);
1343 if (numblks < blockoff)
1344 blockoff = numblks;
1345 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1346 src += blockoff;
James Smart9a6b09c2012-03-01 22:37:42 -05001347 lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble;
James Smartacd68592012-01-18 16:25:09 -05001348 }
James Smartf9bb2da2011-10-10 21:34:11 -04001349 }
1350
James Smartf9bb2da2011-10-10 21:34:11 -04001351 /* Should we change the Reference Tag */
1352 if (reftag) {
James Smartacd68592012-01-18 16:25:09 -05001353 if (phba->lpfc_injerr_wref_cnt) {
1354 switch (op) {
1355 case SCSI_PROT_WRITE_PASS:
James Smart9a6b09c2012-03-01 22:37:42 -05001356 if (src) {
1357 /*
1358 * For WRITE_PASS, force the error
1359 * to be sent on the wire. It should
1360 * be detected by the Target.
1361 * If blockoff != 0 error will be
1362 * inserted in middle of the IO.
1363 */
James Smartf9bb2da2011-10-10 21:34:11 -04001364
James Smartacd68592012-01-18 16:25:09 -05001365 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1366 "9076 BLKGRD: Injecting reftag error: "
1367 "write lba x%lx + x%x oldrefTag x%x\n",
1368 (unsigned long)lba, blockoff,
James Smart9a6b09c2012-03-01 22:37:42 -05001369 be32_to_cpu(src->ref_tag));
James Smartacd68592012-01-18 16:25:09 -05001370
1371 /*
James Smart9a6b09c2012-03-01 22:37:42 -05001372 * Save the old ref_tag so we can
1373 * restore it on completion.
James Smartacd68592012-01-18 16:25:09 -05001374 */
James Smart9a6b09c2012-03-01 22:37:42 -05001375 if (lpfc_cmd) {
1376 lpfc_cmd->prot_data_type =
1377 LPFC_INJERR_REFTAG;
1378 lpfc_cmd->prot_data_segment =
1379 src;
1380 lpfc_cmd->prot_data =
1381 src->ref_tag;
1382 }
1383 src->ref_tag = cpu_to_be32(0xDEADBEEF);
James Smartacd68592012-01-18 16:25:09 -05001384 phba->lpfc_injerr_wref_cnt--;
1385 phba->lpfc_injerr_lba =
1386 LPFC_INJERR_LBA_OFF;
James Smart9a6b09c2012-03-01 22:37:42 -05001387 rc = BG_ERR_TGT | BG_ERR_CHECK;
1388
James Smartacd68592012-01-18 16:25:09 -05001389 break;
1390 }
1391 /* Drop thru */
James Smart9a6b09c2012-03-01 22:37:42 -05001392 case SCSI_PROT_WRITE_INSERT:
1393 /*
1394 * For WRITE_INSERT, force the error
1395 * to be sent on the wire. It should be
1396 * detected by the Target.
1397 */
1398 /* DEADBEEF will be the reftag on the wire */
1399 *reftag = 0xDEADBEEF;
1400 phba->lpfc_injerr_wref_cnt--;
1401 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1402 rc = BG_ERR_TGT | BG_ERR_CHECK;
1403
1404 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1405 "9078 BLKGRD: Injecting reftag error: "
1406 "write lba x%lx\n", (unsigned long)lba);
1407 break;
James Smartacd68592012-01-18 16:25:09 -05001408 case SCSI_PROT_WRITE_STRIP:
1409 /*
1410 * For WRITE_STRIP and WRITE_PASS,
1411 * force the error on data
1412 * being copied from SLI-Host to SLI-Port.
1413 */
1414 *reftag = 0xDEADBEEF;
1415 phba->lpfc_injerr_wref_cnt--;
1416 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1417 rc = BG_ERR_INIT;
1418
1419 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1420 "9077 BLKGRD: Injecting reftag error: "
1421 "write lba x%lx\n", (unsigned long)lba);
1422 break;
James Smartf9bb2da2011-10-10 21:34:11 -04001423 }
James Smartacd68592012-01-18 16:25:09 -05001424 }
1425 if (phba->lpfc_injerr_rref_cnt) {
1426 switch (op) {
1427 case SCSI_PROT_READ_INSERT:
1428 /*
1429 * For READ_INSERT, it doesn't make sense
1430 * to change the reftag.
1431 */
1432 break;
1433 case SCSI_PROT_READ_STRIP:
1434 case SCSI_PROT_READ_PASS:
1435 /*
1436 * For READ_STRIP and READ_PASS, force the
1437 * error on data being read off the wire. It
1438 * should force an IO error to the driver.
1439 */
James Smartf9bb2da2011-10-10 21:34:11 -04001440 *reftag = 0xDEADBEEF;
1441 phba->lpfc_injerr_rref_cnt--;
1442 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
James Smartacd68592012-01-18 16:25:09 -05001443 rc = BG_ERR_INIT;
James Smartf9bb2da2011-10-10 21:34:11 -04001444
1445 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
James Smartacd68592012-01-18 16:25:09 -05001446 "9079 BLKGRD: Injecting reftag error: "
James Smartf9bb2da2011-10-10 21:34:11 -04001447 "read lba x%lx\n", (unsigned long)lba);
James Smartacd68592012-01-18 16:25:09 -05001448 break;
James Smartf9bb2da2011-10-10 21:34:11 -04001449 }
1450 }
1451 }
1452
1453 /* Should we change the Application Tag */
1454 if (apptag) {
James Smartacd68592012-01-18 16:25:09 -05001455 if (phba->lpfc_injerr_wapp_cnt) {
1456 switch (op) {
1457 case SCSI_PROT_WRITE_PASS:
1458 if (blockoff && src) {
James Smart9a6b09c2012-03-01 22:37:42 -05001459 /*
1460 * For WRITE_PASS, force the error
1461 * to be sent on the wire. It should
1462 * be detected by the Target.
1463 * If blockoff != 0 error will be
1464 * inserted in middle of the IO.
1465 */
1466
James Smartf9bb2da2011-10-10 21:34:11 -04001467
James Smartacd68592012-01-18 16:25:09 -05001468 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1469 "9080 BLKGRD: Injecting apptag error: "
1470 "write lba x%lx + x%x oldappTag x%x\n",
1471 (unsigned long)lba, blockoff,
James Smart9a6b09c2012-03-01 22:37:42 -05001472 be16_to_cpu(src->app_tag));
James Smartacd68592012-01-18 16:25:09 -05001473
1474 /*
James Smart9a6b09c2012-03-01 22:37:42 -05001475 * Save the old app_tag so we can
1476 * restore it on completion.
James Smartacd68592012-01-18 16:25:09 -05001477 */
James Smart9a6b09c2012-03-01 22:37:42 -05001478 if (lpfc_cmd) {
1479 lpfc_cmd->prot_data_type =
1480 LPFC_INJERR_APPTAG;
1481 lpfc_cmd->prot_data_segment =
1482 src;
1483 lpfc_cmd->prot_data =
1484 src->app_tag;
1485 }
1486 src->app_tag = cpu_to_be16(0xDEAD);
James Smartacd68592012-01-18 16:25:09 -05001487 phba->lpfc_injerr_wapp_cnt--;
1488 phba->lpfc_injerr_lba =
1489 LPFC_INJERR_LBA_OFF;
James Smart9a6b09c2012-03-01 22:37:42 -05001490 rc = BG_ERR_TGT | BG_ERR_CHECK;
James Smartacd68592012-01-18 16:25:09 -05001491 break;
1492 }
1493 /* Drop thru */
James Smart9a6b09c2012-03-01 22:37:42 -05001494 case SCSI_PROT_WRITE_INSERT:
1495 /*
1496 * For WRITE_INSERT, force the
1497 * error to be sent on the wire. It should be
1498 * detected by the Target.
1499 */
1500 /* DEAD will be the apptag on the wire */
1501 *apptag = 0xDEAD;
1502 phba->lpfc_injerr_wapp_cnt--;
1503 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1504 rc = BG_ERR_TGT;
1505 rc = BG_ERR_TGT | BG_ERR_CHECK;
1506
1507 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1508 "0813 BLKGRD: Injecting apptag error: "
1509 "write lba x%lx\n", (unsigned long)lba);
1510 break;
James Smartacd68592012-01-18 16:25:09 -05001511 case SCSI_PROT_WRITE_STRIP:
1512 /*
1513 * For WRITE_STRIP and WRITE_PASS,
1514 * force the error on data
1515 * being copied from SLI-Host to SLI-Port.
1516 */
1517 *apptag = 0xDEAD;
1518 phba->lpfc_injerr_wapp_cnt--;
1519 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1520 rc = BG_ERR_INIT;
1521
1522 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1523 "0812 BLKGRD: Injecting apptag error: "
1524 "write lba x%lx\n", (unsigned long)lba);
1525 break;
James Smartf9bb2da2011-10-10 21:34:11 -04001526 }
James Smartacd68592012-01-18 16:25:09 -05001527 }
1528 if (phba->lpfc_injerr_rapp_cnt) {
1529 switch (op) {
1530 case SCSI_PROT_READ_INSERT:
1531 /*
1532 * For READ_INSERT, it doesn't make sense
1533 * to change the apptag.
1534 */
1535 break;
1536 case SCSI_PROT_READ_STRIP:
1537 case SCSI_PROT_READ_PASS:
1538 /*
1539 * For READ_STRIP and READ_PASS, force the
1540 * error on data being read off the wire. It
1541 * should force an IO error to the driver.
1542 */
James Smartf9bb2da2011-10-10 21:34:11 -04001543 *apptag = 0xDEAD;
1544 phba->lpfc_injerr_rapp_cnt--;
1545 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
James Smartacd68592012-01-18 16:25:09 -05001546 rc = BG_ERR_INIT;
James Smartf9bb2da2011-10-10 21:34:11 -04001547
1548 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
James Smartacd68592012-01-18 16:25:09 -05001549 "0814 BLKGRD: Injecting apptag error: "
1550 "read lba x%lx\n", (unsigned long)lba);
1551 break;
1552 }
1553 }
1554 }
1555
1556
1557 /* Should we change the Guard Tag */
1558 if (new_guard) {
1559 if (phba->lpfc_injerr_wgrd_cnt) {
1560 switch (op) {
1561 case SCSI_PROT_WRITE_PASS:
James Smart9a6b09c2012-03-01 22:37:42 -05001562 rc = BG_ERR_CHECK;
James Smartacd68592012-01-18 16:25:09 -05001563 /* Drop thru */
James Smartacd68592012-01-18 16:25:09 -05001564
James Smartacd68592012-01-18 16:25:09 -05001565 case SCSI_PROT_WRITE_INSERT:
1566 /*
1567 * For WRITE_INSERT, force the
1568 * error to be sent on the wire. It should be
1569 * detected by the Target.
1570 */
1571 phba->lpfc_injerr_wgrd_cnt--;
1572 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1573
James Smart9a6b09c2012-03-01 22:37:42 -05001574 rc |= BG_ERR_TGT | BG_ERR_SWAP;
James Smartacd68592012-01-18 16:25:09 -05001575 /* Signals the caller to swap CRC->CSUM */
1576
1577 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1578 "0817 BLKGRD: Injecting guard error: "
1579 "write lba x%lx\n", (unsigned long)lba);
1580 break;
James Smart9a6b09c2012-03-01 22:37:42 -05001581 case SCSI_PROT_WRITE_STRIP:
1582 /*
1583 * For WRITE_STRIP and WRITE_PASS,
1584 * force the error on data
1585 * being copied from SLI-Host to SLI-Port.
1586 */
1587 phba->lpfc_injerr_wgrd_cnt--;
1588 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1589
1590 rc = BG_ERR_INIT | BG_ERR_SWAP;
1591 /* Signals the caller to swap CRC->CSUM */
1592
1593 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1594 "0816 BLKGRD: Injecting guard error: "
1595 "write lba x%lx\n", (unsigned long)lba);
1596 break;
James Smartacd68592012-01-18 16:25:09 -05001597 }
1598 }
1599 if (phba->lpfc_injerr_rgrd_cnt) {
1600 switch (op) {
1601 case SCSI_PROT_READ_INSERT:
1602 /*
1603 * For READ_INSERT, it doesn't make sense
1604 * to change the guard tag.
1605 */
1606 break;
1607 case SCSI_PROT_READ_STRIP:
1608 case SCSI_PROT_READ_PASS:
1609 /*
1610 * For READ_STRIP and READ_PASS, force the
1611 * error on data being read off the wire. It
1612 * should force an IO error to the driver.
1613 */
James Smartacd68592012-01-18 16:25:09 -05001614 phba->lpfc_injerr_rgrd_cnt--;
1615 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1616
James Smart9a6b09c2012-03-01 22:37:42 -05001617 rc = BG_ERR_INIT | BG_ERR_SWAP;
James Smartacd68592012-01-18 16:25:09 -05001618 /* Signals the caller to swap CRC->CSUM */
1619
1620 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1621 "0818 BLKGRD: Injecting guard error: "
James Smartf9bb2da2011-10-10 21:34:11 -04001622 "read lba x%lx\n", (unsigned long)lba);
1623 }
1624 }
1625 }
1626
James Smartf9bb2da2011-10-10 21:34:11 -04001627 return rc;
1628}
1629#endif
1630
James Smartacd68592012-01-18 16:25:09 -05001631/**
1632 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1633 * the specified SCSI command.
1634 * @phba: The Hba for which this call is being executed.
James Smart6c8eea52010-04-06 14:49:53 -04001635 * @sc: The SCSI command to examine
1636 * @txopt: (out) BlockGuard operation for transmitted data
1637 * @rxopt: (out) BlockGuard operation for received data
1638 *
1639 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1640 *
James Smartacd68592012-01-18 16:25:09 -05001641 **/
James Smarte2a0a9d2008-12-04 22:40:02 -05001642static int
James Smart6c8eea52010-04-06 14:49:53 -04001643lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1644 uint8_t *txop, uint8_t *rxop)
James Smarte2a0a9d2008-12-04 22:40:02 -05001645{
1646 uint8_t guard_type = scsi_host_get_guard(sc->device->host);
James Smart6c8eea52010-04-06 14:49:53 -04001647 uint8_t ret = 0;
James Smarte2a0a9d2008-12-04 22:40:02 -05001648
1649 if (guard_type == SHOST_DIX_GUARD_IP) {
1650 switch (scsi_get_prot_op(sc)) {
1651 case SCSI_PROT_READ_INSERT:
1652 case SCSI_PROT_WRITE_STRIP:
James Smart6c8eea52010-04-06 14:49:53 -04001653 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1654 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
James Smarte2a0a9d2008-12-04 22:40:02 -05001655 break;
1656
1657 case SCSI_PROT_READ_STRIP:
1658 case SCSI_PROT_WRITE_INSERT:
James Smart6c8eea52010-04-06 14:49:53 -04001659 *txop = BG_OP_IN_NODIF_OUT_CRC;
1660 *rxop = BG_OP_IN_CRC_OUT_NODIF;
James Smarte2a0a9d2008-12-04 22:40:02 -05001661 break;
1662
Martin K. Petersenc6af4042009-09-18 17:32:59 -04001663 case SCSI_PROT_READ_PASS:
1664 case SCSI_PROT_WRITE_PASS:
James Smart6c8eea52010-04-06 14:49:53 -04001665 *txop = BG_OP_IN_CSUM_OUT_CRC;
1666 *rxop = BG_OP_IN_CRC_OUT_CSUM;
James Smarte2a0a9d2008-12-04 22:40:02 -05001667 break;
1668
James Smarte2a0a9d2008-12-04 22:40:02 -05001669 case SCSI_PROT_NORMAL:
1670 default:
James Smart6a9c52c2009-10-02 15:16:51 -04001671 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
James Smart7c56b9f2011-07-22 18:36:25 -04001672 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1673 scsi_get_prot_op(sc));
James Smart6c8eea52010-04-06 14:49:53 -04001674 ret = 1;
James Smarte2a0a9d2008-12-04 22:40:02 -05001675 break;
1676
1677 }
James Smart7c56b9f2011-07-22 18:36:25 -04001678 } else {
James Smarte2a0a9d2008-12-04 22:40:02 -05001679 switch (scsi_get_prot_op(sc)) {
1680 case SCSI_PROT_READ_STRIP:
1681 case SCSI_PROT_WRITE_INSERT:
James Smart6c8eea52010-04-06 14:49:53 -04001682 *txop = BG_OP_IN_NODIF_OUT_CRC;
1683 *rxop = BG_OP_IN_CRC_OUT_NODIF;
James Smarte2a0a9d2008-12-04 22:40:02 -05001684 break;
1685
1686 case SCSI_PROT_READ_PASS:
1687 case SCSI_PROT_WRITE_PASS:
James Smart6c8eea52010-04-06 14:49:53 -04001688 *txop = BG_OP_IN_CRC_OUT_CRC;
1689 *rxop = BG_OP_IN_CRC_OUT_CRC;
James Smarte2a0a9d2008-12-04 22:40:02 -05001690 break;
1691
James Smarte2a0a9d2008-12-04 22:40:02 -05001692 case SCSI_PROT_READ_INSERT:
1693 case SCSI_PROT_WRITE_STRIP:
James Smart7c56b9f2011-07-22 18:36:25 -04001694 *txop = BG_OP_IN_CRC_OUT_NODIF;
1695 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1696 break;
1697
James Smarte2a0a9d2008-12-04 22:40:02 -05001698 case SCSI_PROT_NORMAL:
1699 default:
James Smart6a9c52c2009-10-02 15:16:51 -04001700 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
James Smart7c56b9f2011-07-22 18:36:25 -04001701 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1702 scsi_get_prot_op(sc));
James Smart6c8eea52010-04-06 14:49:53 -04001703 ret = 1;
James Smarte2a0a9d2008-12-04 22:40:02 -05001704 break;
1705 }
James Smarte2a0a9d2008-12-04 22:40:02 -05001706 }
1707
James Smart6c8eea52010-04-06 14:49:53 -04001708 return ret;
James Smarte2a0a9d2008-12-04 22:40:02 -05001709}
1710
James Smartacd68592012-01-18 16:25:09 -05001711#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1712/**
1713 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1714 * the specified SCSI command in order to force a guard tag error.
1715 * @phba: The Hba for which this call is being executed.
1716 * @sc: The SCSI command to examine
1717 * @txopt: (out) BlockGuard operation for transmitted data
1718 * @rxopt: (out) BlockGuard operation for received data
1719 *
1720 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1721 *
1722 **/
1723static int
1724lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1725 uint8_t *txop, uint8_t *rxop)
1726{
1727 uint8_t guard_type = scsi_host_get_guard(sc->device->host);
1728 uint8_t ret = 0;
1729
1730 if (guard_type == SHOST_DIX_GUARD_IP) {
1731 switch (scsi_get_prot_op(sc)) {
1732 case SCSI_PROT_READ_INSERT:
1733 case SCSI_PROT_WRITE_STRIP:
1734 *txop = BG_OP_IN_CRC_OUT_NODIF;
1735 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1736 break;
1737
1738 case SCSI_PROT_READ_STRIP:
1739 case SCSI_PROT_WRITE_INSERT:
1740 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1741 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1742 break;
1743
1744 case SCSI_PROT_READ_PASS:
1745 case SCSI_PROT_WRITE_PASS:
James Smart9a6b09c2012-03-01 22:37:42 -05001746 *txop = BG_OP_IN_CRC_OUT_CSUM;
James Smartacd68592012-01-18 16:25:09 -05001747 *rxop = BG_OP_IN_CRC_OUT_CRC;
1748 break;
1749
1750 case SCSI_PROT_NORMAL:
1751 default:
1752 break;
1753
1754 }
1755 } else {
1756 switch (scsi_get_prot_op(sc)) {
1757 case SCSI_PROT_READ_STRIP:
1758 case SCSI_PROT_WRITE_INSERT:
1759 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1760 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1761 break;
1762
1763 case SCSI_PROT_READ_PASS:
1764 case SCSI_PROT_WRITE_PASS:
James Smart9a6b09c2012-03-01 22:37:42 -05001765 *txop = BG_OP_IN_CSUM_OUT_CSUM;
James Smartacd68592012-01-18 16:25:09 -05001766 *rxop = BG_OP_IN_CRC_OUT_CSUM;
1767 break;
1768
1769 case SCSI_PROT_READ_INSERT:
1770 case SCSI_PROT_WRITE_STRIP:
1771 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1772 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1773 break;
1774
1775 case SCSI_PROT_NORMAL:
1776 default:
1777 break;
1778 }
1779 }
1780
1781 return ret;
1782}
1783#endif
1784
1785/**
1786 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1787 * @phba: The Hba for which this call is being executed.
1788 * @sc: pointer to scsi command we're working on
1789 * @bpl: pointer to buffer list for protection groups
1790 * @datacnt: number of segments of data that have been dma mapped
1791 *
1792 * This function sets up BPL buffer list for protection groups of
James Smarte2a0a9d2008-12-04 22:40:02 -05001793 * type LPFC_PG_TYPE_NO_DIF
1794 *
1795 * This is usually used when the HBA is instructed to generate
1796 * DIFs and insert them into data stream (or strip DIF from
1797 * incoming data stream)
1798 *
1799 * The buffer list consists of just one protection group described
1800 * below:
1801 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001802 * start of prot group --> | PDE_5 |
1803 * +-------------------------+
1804 * | PDE_6 |
James Smarte2a0a9d2008-12-04 22:40:02 -05001805 * +-------------------------+
1806 * | Data BDE |
1807 * +-------------------------+
1808 * |more Data BDE's ... (opt)|
1809 * +-------------------------+
1810 *
James Smarte2a0a9d2008-12-04 22:40:02 -05001811 *
1812 * Note: Data s/g buffers have been dma mapped
James Smartacd68592012-01-18 16:25:09 -05001813 *
1814 * Returns the number of BDEs added to the BPL.
1815 **/
James Smarte2a0a9d2008-12-04 22:40:02 -05001816static int
1817lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1818 struct ulp_bde64 *bpl, int datasegcnt)
1819{
1820 struct scatterlist *sgde = NULL; /* s/g data entry */
James Smart6c8eea52010-04-06 14:49:53 -04001821 struct lpfc_pde5 *pde5 = NULL;
1822 struct lpfc_pde6 *pde6 = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05001823 dma_addr_t physaddr;
James Smart6c8eea52010-04-06 14:49:53 -04001824 int i = 0, num_bde = 0, status;
James Smarte2a0a9d2008-12-04 22:40:02 -05001825 int datadir = sc->sc_data_direction;
James Smartacd68592012-01-18 16:25:09 -05001826 uint32_t rc;
1827 uint32_t checking = 1;
James Smarte2a0a9d2008-12-04 22:40:02 -05001828 uint32_t reftag;
James Smart7c56b9f2011-07-22 18:36:25 -04001829 unsigned blksize;
James Smart6c8eea52010-04-06 14:49:53 -04001830 uint8_t txop, rxop;
James Smarte2a0a9d2008-12-04 22:40:02 -05001831
James Smart6c8eea52010-04-06 14:49:53 -04001832 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1833 if (status)
James Smarte2a0a9d2008-12-04 22:40:02 -05001834 goto out;
1835
James Smart6c8eea52010-04-06 14:49:53 -04001836 /* extract some info from the scsi command for pde*/
James Smarte2a0a9d2008-12-04 22:40:02 -05001837 blksize = lpfc_cmd_blksize(sc);
James Smartacd68592012-01-18 16:25:09 -05001838 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
James Smarte2a0a9d2008-12-04 22:40:02 -05001839
James Smartf9bb2da2011-10-10 21:34:11 -04001840#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smartacd68592012-01-18 16:25:09 -05001841 rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
1842 if (rc) {
James Smart9a6b09c2012-03-01 22:37:42 -05001843 if (rc & BG_ERR_SWAP)
James Smartacd68592012-01-18 16:25:09 -05001844 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
James Smart9a6b09c2012-03-01 22:37:42 -05001845 if (rc & BG_ERR_CHECK)
James Smartacd68592012-01-18 16:25:09 -05001846 checking = 0;
1847 }
James Smartf9bb2da2011-10-10 21:34:11 -04001848#endif
1849
James Smart6c8eea52010-04-06 14:49:53 -04001850 /* setup PDE5 with what we have */
1851 pde5 = (struct lpfc_pde5 *) bpl;
1852 memset(pde5, 0, sizeof(struct lpfc_pde5));
1853 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
James Smarte2a0a9d2008-12-04 22:40:02 -05001854
James Smartbc739052010-08-04 16:11:18 -04001855 /* Endianness conversion if necessary for PDE5 */
James Smart589a52d2010-07-14 15:30:54 -04001856 pde5->word0 = cpu_to_le32(pde5->word0);
James Smart7c56b9f2011-07-22 18:36:25 -04001857 pde5->reftag = cpu_to_le32(reftag);
James Smart589a52d2010-07-14 15:30:54 -04001858
James Smart6c8eea52010-04-06 14:49:53 -04001859 /* advance bpl and increment bde count */
1860 num_bde++;
1861 bpl++;
1862 pde6 = (struct lpfc_pde6 *) bpl;
1863
1864 /* setup PDE6 with the rest of the info */
1865 memset(pde6, 0, sizeof(struct lpfc_pde6));
1866 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1867 bf_set(pde6_optx, pde6, txop);
1868 bf_set(pde6_oprx, pde6, rxop);
1869 if (datadir == DMA_FROM_DEVICE) {
James Smartacd68592012-01-18 16:25:09 -05001870 bf_set(pde6_ce, pde6, checking);
1871 bf_set(pde6_re, pde6, checking);
James Smart6c8eea52010-04-06 14:49:53 -04001872 }
1873 bf_set(pde6_ai, pde6, 1);
James Smart7c56b9f2011-07-22 18:36:25 -04001874 bf_set(pde6_ae, pde6, 0);
1875 bf_set(pde6_apptagval, pde6, 0);
James Smart6c8eea52010-04-06 14:49:53 -04001876
James Smartbc739052010-08-04 16:11:18 -04001877 /* Endianness conversion if necessary for PDE6 */
James Smart589a52d2010-07-14 15:30:54 -04001878 pde6->word0 = cpu_to_le32(pde6->word0);
1879 pde6->word1 = cpu_to_le32(pde6->word1);
1880 pde6->word2 = cpu_to_le32(pde6->word2);
1881
James Smart6c8eea52010-04-06 14:49:53 -04001882 /* advance bpl and increment bde count */
James Smarte2a0a9d2008-12-04 22:40:02 -05001883 num_bde++;
1884 bpl++;
1885
1886 /* assumption: caller has already run dma_map_sg on command data */
1887 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
1888 physaddr = sg_dma_address(sgde);
1889 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
1890 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1891 bpl->tus.f.bdeSize = sg_dma_len(sgde);
1892 if (datadir == DMA_TO_DEVICE)
1893 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1894 else
1895 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1896 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1897 bpl++;
1898 num_bde++;
1899 }
1900
1901out:
1902 return num_bde;
1903}
1904
James Smartacd68592012-01-18 16:25:09 -05001905/**
1906 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1907 * @phba: The Hba for which this call is being executed.
1908 * @sc: pointer to scsi command we're working on
1909 * @bpl: pointer to buffer list for protection groups
1910 * @datacnt: number of segments of data that have been dma mapped
1911 * @protcnt: number of segment of protection data that have been dma mapped
1912 *
1913 * This function sets up BPL buffer list for protection groups of
1914 * type LPFC_PG_TYPE_DIF
James Smarte2a0a9d2008-12-04 22:40:02 -05001915 *
1916 * This is usually used when DIFs are in their own buffers,
1917 * separate from the data. The HBA can then by instructed
1918 * to place the DIFs in the outgoing stream. For read operations,
1919 * The HBA could extract the DIFs and place it in DIF buffers.
1920 *
1921 * The buffer list for this type consists of one or more of the
1922 * protection groups described below:
1923 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001924 * start of first prot group --> | PDE_5 |
James Smarte2a0a9d2008-12-04 22:40:02 -05001925 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001926 * | PDE_6 |
1927 * +-------------------------+
1928 * | PDE_7 (Prot BDE) |
James Smarte2a0a9d2008-12-04 22:40:02 -05001929 * +-------------------------+
1930 * | Data BDE |
1931 * +-------------------------+
1932 * |more Data BDE's ... (opt)|
1933 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001934 * start of new prot group --> | PDE_5 |
James Smarte2a0a9d2008-12-04 22:40:02 -05001935 * +-------------------------+
1936 * | ... |
1937 * +-------------------------+
1938 *
James Smarte2a0a9d2008-12-04 22:40:02 -05001939 * Note: It is assumed that both data and protection s/g buffers have been
1940 * mapped for DMA
James Smartacd68592012-01-18 16:25:09 -05001941 *
1942 * Returns the number of BDEs added to the BPL.
1943 **/
James Smarte2a0a9d2008-12-04 22:40:02 -05001944static int
1945lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1946 struct ulp_bde64 *bpl, int datacnt, int protcnt)
1947{
1948 struct scatterlist *sgde = NULL; /* s/g data entry */
1949 struct scatterlist *sgpe = NULL; /* s/g prot entry */
James Smart6c8eea52010-04-06 14:49:53 -04001950 struct lpfc_pde5 *pde5 = NULL;
1951 struct lpfc_pde6 *pde6 = NULL;
James Smart7f860592011-03-11 16:05:52 -05001952 struct lpfc_pde7 *pde7 = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05001953 dma_addr_t dataphysaddr, protphysaddr;
1954 unsigned short curr_data = 0, curr_prot = 0;
James Smart7f860592011-03-11 16:05:52 -05001955 unsigned int split_offset;
1956 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
James Smarte2a0a9d2008-12-04 22:40:02 -05001957 unsigned int protgrp_blks, protgrp_bytes;
1958 unsigned int remainder, subtotal;
James Smart6c8eea52010-04-06 14:49:53 -04001959 int status;
James Smarte2a0a9d2008-12-04 22:40:02 -05001960 int datadir = sc->sc_data_direction;
1961 unsigned char pgdone = 0, alldone = 0;
1962 unsigned blksize;
James Smartacd68592012-01-18 16:25:09 -05001963 uint32_t rc;
1964 uint32_t checking = 1;
James Smarte2a0a9d2008-12-04 22:40:02 -05001965 uint32_t reftag;
James Smart6c8eea52010-04-06 14:49:53 -04001966 uint8_t txop, rxop;
James Smarte2a0a9d2008-12-04 22:40:02 -05001967 int num_bde = 0;
1968
1969 sgpe = scsi_prot_sglist(sc);
1970 sgde = scsi_sglist(sc);
1971
1972 if (!sgpe || !sgde) {
1973 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1974 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
1975 sgpe, sgde);
1976 return 0;
1977 }
1978
James Smart6c8eea52010-04-06 14:49:53 -04001979 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1980 if (status)
James Smarte2a0a9d2008-12-04 22:40:02 -05001981 goto out;
1982
James Smart6c8eea52010-04-06 14:49:53 -04001983 /* extract some info from the scsi command */
James Smarte2a0a9d2008-12-04 22:40:02 -05001984 blksize = lpfc_cmd_blksize(sc);
James Smartacd68592012-01-18 16:25:09 -05001985 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
James Smarte2a0a9d2008-12-04 22:40:02 -05001986
James Smartf9bb2da2011-10-10 21:34:11 -04001987#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smartacd68592012-01-18 16:25:09 -05001988 rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
1989 if (rc) {
James Smart9a6b09c2012-03-01 22:37:42 -05001990 if (rc & BG_ERR_SWAP)
James Smartacd68592012-01-18 16:25:09 -05001991 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
James Smart9a6b09c2012-03-01 22:37:42 -05001992 if (rc & BG_ERR_CHECK)
James Smartacd68592012-01-18 16:25:09 -05001993 checking = 0;
1994 }
James Smartf9bb2da2011-10-10 21:34:11 -04001995#endif
1996
James Smarte2a0a9d2008-12-04 22:40:02 -05001997 split_offset = 0;
1998 do {
James Smart6c8eea52010-04-06 14:49:53 -04001999 /* setup PDE5 with what we have */
2000 pde5 = (struct lpfc_pde5 *) bpl;
2001 memset(pde5, 0, sizeof(struct lpfc_pde5));
2002 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
James Smarte2a0a9d2008-12-04 22:40:02 -05002003
James Smartbc739052010-08-04 16:11:18 -04002004 /* Endianness conversion if necessary for PDE5 */
James Smart589a52d2010-07-14 15:30:54 -04002005 pde5->word0 = cpu_to_le32(pde5->word0);
James Smart7c56b9f2011-07-22 18:36:25 -04002006 pde5->reftag = cpu_to_le32(reftag);
James Smart589a52d2010-07-14 15:30:54 -04002007
James Smart6c8eea52010-04-06 14:49:53 -04002008 /* advance bpl and increment bde count */
2009 num_bde++;
2010 bpl++;
2011 pde6 = (struct lpfc_pde6 *) bpl;
James Smarte2a0a9d2008-12-04 22:40:02 -05002012
James Smart6c8eea52010-04-06 14:49:53 -04002013 /* setup PDE6 with the rest of the info */
2014 memset(pde6, 0, sizeof(struct lpfc_pde6));
2015 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
2016 bf_set(pde6_optx, pde6, txop);
2017 bf_set(pde6_oprx, pde6, rxop);
James Smartacd68592012-01-18 16:25:09 -05002018 bf_set(pde6_ce, pde6, checking);
2019 bf_set(pde6_re, pde6, checking);
James Smart6c8eea52010-04-06 14:49:53 -04002020 bf_set(pde6_ai, pde6, 1);
James Smart7c56b9f2011-07-22 18:36:25 -04002021 bf_set(pde6_ae, pde6, 0);
2022 bf_set(pde6_apptagval, pde6, 0);
James Smart6c8eea52010-04-06 14:49:53 -04002023
James Smartbc739052010-08-04 16:11:18 -04002024 /* Endianness conversion if necessary for PDE6 */
James Smart589a52d2010-07-14 15:30:54 -04002025 pde6->word0 = cpu_to_le32(pde6->word0);
2026 pde6->word1 = cpu_to_le32(pde6->word1);
2027 pde6->word2 = cpu_to_le32(pde6->word2);
2028
James Smart6c8eea52010-04-06 14:49:53 -04002029 /* advance bpl and increment bde count */
James Smarte2a0a9d2008-12-04 22:40:02 -05002030 num_bde++;
2031 bpl++;
2032
2033 /* setup the first BDE that points to protection buffer */
James Smart7f860592011-03-11 16:05:52 -05002034 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2035 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
James Smarte2a0a9d2008-12-04 22:40:02 -05002036
James Smarte2a0a9d2008-12-04 22:40:02 -05002037 /* must be integer multiple of the DIF block length */
2038 BUG_ON(protgroup_len % 8);
2039
James Smart7f860592011-03-11 16:05:52 -05002040 pde7 = (struct lpfc_pde7 *) bpl;
2041 memset(pde7, 0, sizeof(struct lpfc_pde7));
2042 bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
2043
James Smart7c56b9f2011-07-22 18:36:25 -04002044 pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr));
2045 pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr));
James Smart7f860592011-03-11 16:05:52 -05002046
James Smarte2a0a9d2008-12-04 22:40:02 -05002047 protgrp_blks = protgroup_len / 8;
2048 protgrp_bytes = protgrp_blks * blksize;
2049
James Smart7f860592011-03-11 16:05:52 -05002050 /* check if this pde is crossing the 4K boundary; if so split */
2051 if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
2052 protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
2053 protgroup_offset += protgroup_remainder;
2054 protgrp_blks = protgroup_remainder / 8;
James Smart7c56b9f2011-07-22 18:36:25 -04002055 protgrp_bytes = protgrp_blks * blksize;
James Smart7f860592011-03-11 16:05:52 -05002056 } else {
2057 protgroup_offset = 0;
2058 curr_prot++;
2059 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002060
James Smarte2a0a9d2008-12-04 22:40:02 -05002061 num_bde++;
2062
2063 /* setup BDE's for data blocks associated with DIF data */
2064 pgdone = 0;
2065 subtotal = 0; /* total bytes processed for current prot grp */
2066 while (!pgdone) {
2067 if (!sgde) {
James Smart6a9c52c2009-10-02 15:16:51 -04002068 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2069 "9065 BLKGRD:%s Invalid data segment\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002070 __func__);
2071 return 0;
2072 }
2073 bpl++;
2074 dataphysaddr = sg_dma_address(sgde) + split_offset;
2075 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
2076 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
2077
2078 remainder = sg_dma_len(sgde) - split_offset;
2079
2080 if ((subtotal + remainder) <= protgrp_bytes) {
2081 /* we can use this whole buffer */
2082 bpl->tus.f.bdeSize = remainder;
2083 split_offset = 0;
2084
2085 if ((subtotal + remainder) == protgrp_bytes)
2086 pgdone = 1;
2087 } else {
2088 /* must split this buffer with next prot grp */
2089 bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
2090 split_offset += bpl->tus.f.bdeSize;
2091 }
2092
2093 subtotal += bpl->tus.f.bdeSize;
2094
2095 if (datadir == DMA_TO_DEVICE)
2096 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2097 else
2098 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
2099 bpl->tus.w = le32_to_cpu(bpl->tus.w);
2100
2101 num_bde++;
2102 curr_data++;
2103
2104 if (split_offset)
2105 break;
2106
2107 /* Move to the next s/g segment if possible */
2108 sgde = sg_next(sgde);
James Smart6c8eea52010-04-06 14:49:53 -04002109
James Smarte2a0a9d2008-12-04 22:40:02 -05002110 }
2111
James Smart7f860592011-03-11 16:05:52 -05002112 if (protgroup_offset) {
2113 /* update the reference tag */
2114 reftag += protgrp_blks;
2115 bpl++;
2116 continue;
2117 }
2118
James Smarte2a0a9d2008-12-04 22:40:02 -05002119 /* are we done ? */
2120 if (curr_prot == protcnt) {
2121 alldone = 1;
2122 } else if (curr_prot < protcnt) {
2123 /* advance to next prot buffer */
2124 sgpe = sg_next(sgpe);
2125 bpl++;
2126
2127 /* update the reference tag */
2128 reftag += protgrp_blks;
2129 } else {
2130 /* if we're here, we have a bug */
James Smart6a9c52c2009-10-02 15:16:51 -04002131 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2132 "9054 BLKGRD: bug in %s\n", __func__);
James Smarte2a0a9d2008-12-04 22:40:02 -05002133 }
2134
2135 } while (!alldone);
James Smarte2a0a9d2008-12-04 22:40:02 -05002136out:
2137
James Smarte2a0a9d2008-12-04 22:40:02 -05002138 return num_bde;
2139}
James Smart7f860592011-03-11 16:05:52 -05002140
James Smartacd68592012-01-18 16:25:09 -05002141/**
2142 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
2143 * @phba: The Hba for which this call is being executed.
2144 * @sc: pointer to scsi command we're working on
2145 * @sgl: pointer to buffer list for protection groups
2146 * @datacnt: number of segments of data that have been dma mapped
2147 *
2148 * This function sets up SGL buffer list for protection groups of
2149 * type LPFC_PG_TYPE_NO_DIF
2150 *
2151 * This is usually used when the HBA is instructed to generate
2152 * DIFs and insert them into data stream (or strip DIF from
2153 * incoming data stream)
2154 *
2155 * The buffer list consists of just one protection group described
2156 * below:
2157 * +-------------------------+
2158 * start of prot group --> | DI_SEED |
2159 * +-------------------------+
2160 * | Data SGE |
2161 * +-------------------------+
2162 * |more Data SGE's ... (opt)|
2163 * +-------------------------+
2164 *
2165 *
2166 * Note: Data s/g buffers have been dma mapped
2167 *
2168 * Returns the number of SGEs added to the SGL.
2169 **/
2170static int
2171lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2172 struct sli4_sge *sgl, int datasegcnt)
2173{
2174 struct scatterlist *sgde = NULL; /* s/g data entry */
2175 struct sli4_sge_diseed *diseed = NULL;
2176 dma_addr_t physaddr;
2177 int i = 0, num_sge = 0, status;
2178 int datadir = sc->sc_data_direction;
2179 uint32_t reftag;
2180 unsigned blksize;
2181 uint8_t txop, rxop;
2182 uint32_t rc;
2183 uint32_t checking = 1;
2184 uint32_t dma_len;
2185 uint32_t dma_offset = 0;
2186
2187 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2188 if (status)
2189 goto out;
2190
2191 /* extract some info from the scsi command for pde*/
2192 blksize = lpfc_cmd_blksize(sc);
2193 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2194
2195#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2196 rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
2197 if (rc) {
James Smart9a6b09c2012-03-01 22:37:42 -05002198 if (rc & BG_ERR_SWAP)
James Smartacd68592012-01-18 16:25:09 -05002199 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
James Smart9a6b09c2012-03-01 22:37:42 -05002200 if (rc & BG_ERR_CHECK)
James Smartacd68592012-01-18 16:25:09 -05002201 checking = 0;
2202 }
2203#endif
2204
2205 /* setup DISEED with what we have */
2206 diseed = (struct sli4_sge_diseed *) sgl;
2207 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2208 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2209
2210 /* Endianness conversion if necessary */
2211 diseed->ref_tag = cpu_to_le32(reftag);
2212 diseed->ref_tag_tran = diseed->ref_tag;
2213
2214 /* setup DISEED with the rest of the info */
2215 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2216 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2217 if (datadir == DMA_FROM_DEVICE) {
2218 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2219 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2220 }
2221 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2222 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2223
2224 /* Endianness conversion if necessary for DISEED */
2225 diseed->word2 = cpu_to_le32(diseed->word2);
2226 diseed->word3 = cpu_to_le32(diseed->word3);
2227
2228 /* advance bpl and increment sge count */
2229 num_sge++;
2230 sgl++;
2231
2232 /* assumption: caller has already run dma_map_sg on command data */
2233 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
2234 physaddr = sg_dma_address(sgde);
2235 dma_len = sg_dma_len(sgde);
2236 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
2237 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
2238 if ((i + 1) == datasegcnt)
2239 bf_set(lpfc_sli4_sge_last, sgl, 1);
2240 else
2241 bf_set(lpfc_sli4_sge_last, sgl, 0);
2242 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2243 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2244
2245 sgl->sge_len = cpu_to_le32(dma_len);
2246 dma_offset += dma_len;
2247
2248 sgl++;
2249 num_sge++;
2250 }
2251
2252out:
2253 return num_sge;
2254}
2255
2256/**
2257 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2258 * @phba: The Hba for which this call is being executed.
2259 * @sc: pointer to scsi command we're working on
2260 * @sgl: pointer to buffer list for protection groups
2261 * @datacnt: number of segments of data that have been dma mapped
2262 * @protcnt: number of segment of protection data that have been dma mapped
2263 *
2264 * This function sets up SGL buffer list for protection groups of
2265 * type LPFC_PG_TYPE_DIF
2266 *
2267 * This is usually used when DIFs are in their own buffers,
2268 * separate from the data. The HBA can then by instructed
2269 * to place the DIFs in the outgoing stream. For read operations,
2270 * The HBA could extract the DIFs and place it in DIF buffers.
2271 *
2272 * The buffer list for this type consists of one or more of the
2273 * protection groups described below:
2274 * +-------------------------+
2275 * start of first prot group --> | DISEED |
2276 * +-------------------------+
2277 * | DIF (Prot SGE) |
2278 * +-------------------------+
2279 * | Data SGE |
2280 * +-------------------------+
2281 * |more Data SGE's ... (opt)|
2282 * +-------------------------+
2283 * start of new prot group --> | DISEED |
2284 * +-------------------------+
2285 * | ... |
2286 * +-------------------------+
2287 *
2288 * Note: It is assumed that both data and protection s/g buffers have been
2289 * mapped for DMA
2290 *
2291 * Returns the number of SGEs added to the SGL.
2292 **/
2293static int
2294lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2295 struct sli4_sge *sgl, int datacnt, int protcnt)
2296{
2297 struct scatterlist *sgde = NULL; /* s/g data entry */
2298 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2299 struct sli4_sge_diseed *diseed = NULL;
2300 dma_addr_t dataphysaddr, protphysaddr;
2301 unsigned short curr_data = 0, curr_prot = 0;
2302 unsigned int split_offset;
2303 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2304 unsigned int protgrp_blks, protgrp_bytes;
2305 unsigned int remainder, subtotal;
2306 int status;
2307 unsigned char pgdone = 0, alldone = 0;
2308 unsigned blksize;
2309 uint32_t reftag;
2310 uint8_t txop, rxop;
2311 uint32_t dma_len;
2312 uint32_t rc;
2313 uint32_t checking = 1;
2314 uint32_t dma_offset = 0;
2315 int num_sge = 0;
2316
2317 sgpe = scsi_prot_sglist(sc);
2318 sgde = scsi_sglist(sc);
2319
2320 if (!sgpe || !sgde) {
2321 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2322 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2323 sgpe, sgde);
2324 return 0;
2325 }
2326
2327 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2328 if (status)
2329 goto out;
2330
2331 /* extract some info from the scsi command */
2332 blksize = lpfc_cmd_blksize(sc);
2333 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2334
2335#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2336 rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
2337 if (rc) {
James Smart9a6b09c2012-03-01 22:37:42 -05002338 if (rc & BG_ERR_SWAP)
James Smartacd68592012-01-18 16:25:09 -05002339 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
James Smart9a6b09c2012-03-01 22:37:42 -05002340 if (rc & BG_ERR_CHECK)
James Smartacd68592012-01-18 16:25:09 -05002341 checking = 0;
2342 }
2343#endif
2344
2345 split_offset = 0;
2346 do {
2347 /* setup DISEED with what we have */
2348 diseed = (struct sli4_sge_diseed *) sgl;
2349 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2350 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2351
2352 /* Endianness conversion if necessary */
2353 diseed->ref_tag = cpu_to_le32(reftag);
2354 diseed->ref_tag_tran = diseed->ref_tag;
2355
2356 /* setup DISEED with the rest of the info */
2357 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2358 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2359 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2360 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2361 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2362 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2363
2364 /* Endianness conversion if necessary for DISEED */
2365 diseed->word2 = cpu_to_le32(diseed->word2);
2366 diseed->word3 = cpu_to_le32(diseed->word3);
2367
2368 /* advance sgl and increment bde count */
2369 num_sge++;
2370 sgl++;
2371
2372 /* setup the first BDE that points to protection buffer */
2373 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2374 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2375
2376 /* must be integer multiple of the DIF block length */
2377 BUG_ON(protgroup_len % 8);
2378
2379 /* Now setup DIF SGE */
2380 sgl->word2 = 0;
2381 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF);
2382 sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr));
2383 sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr));
2384 sgl->word2 = cpu_to_le32(sgl->word2);
2385
2386 protgrp_blks = protgroup_len / 8;
2387 protgrp_bytes = protgrp_blks * blksize;
2388
2389 /* check if DIF SGE is crossing the 4K boundary; if so split */
2390 if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) {
2391 protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff);
2392 protgroup_offset += protgroup_remainder;
2393 protgrp_blks = protgroup_remainder / 8;
2394 protgrp_bytes = protgrp_blks * blksize;
2395 } else {
2396 protgroup_offset = 0;
2397 curr_prot++;
2398 }
2399
2400 num_sge++;
2401
2402 /* setup SGE's for data blocks associated with DIF data */
2403 pgdone = 0;
2404 subtotal = 0; /* total bytes processed for current prot grp */
2405 while (!pgdone) {
2406 if (!sgde) {
2407 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2408 "9086 BLKGRD:%s Invalid data segment\n",
2409 __func__);
2410 return 0;
2411 }
2412 sgl++;
2413 dataphysaddr = sg_dma_address(sgde) + split_offset;
2414
2415 remainder = sg_dma_len(sgde) - split_offset;
2416
2417 if ((subtotal + remainder) <= protgrp_bytes) {
2418 /* we can use this whole buffer */
2419 dma_len = remainder;
2420 split_offset = 0;
2421
2422 if ((subtotal + remainder) == protgrp_bytes)
2423 pgdone = 1;
2424 } else {
2425 /* must split this buffer with next prot grp */
2426 dma_len = protgrp_bytes - subtotal;
2427 split_offset += dma_len;
2428 }
2429
2430 subtotal += dma_len;
2431
2432 sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr));
2433 sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr));
2434 bf_set(lpfc_sli4_sge_last, sgl, 0);
2435 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2436 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2437
2438 sgl->sge_len = cpu_to_le32(dma_len);
2439 dma_offset += dma_len;
2440
2441 num_sge++;
2442 curr_data++;
2443
2444 if (split_offset)
2445 break;
2446
2447 /* Move to the next s/g segment if possible */
2448 sgde = sg_next(sgde);
2449 }
2450
2451 if (protgroup_offset) {
2452 /* update the reference tag */
2453 reftag += protgrp_blks;
2454 sgl++;
2455 continue;
2456 }
2457
2458 /* are we done ? */
2459 if (curr_prot == protcnt) {
2460 bf_set(lpfc_sli4_sge_last, sgl, 1);
2461 alldone = 1;
2462 } else if (curr_prot < protcnt) {
2463 /* advance to next prot buffer */
2464 sgpe = sg_next(sgpe);
2465 sgl++;
2466
2467 /* update the reference tag */
2468 reftag += protgrp_blks;
2469 } else {
2470 /* if we're here, we have a bug */
2471 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2472 "9085 BLKGRD: bug in %s\n", __func__);
2473 }
2474
2475 } while (!alldone);
2476
2477out:
2478
2479 return num_sge;
2480}
2481
2482/**
2483 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2484 * @phba: The Hba for which this call is being executed.
2485 * @sc: pointer to scsi command we're working on
2486 *
James Smarte2a0a9d2008-12-04 22:40:02 -05002487 * Given a SCSI command that supports DIF, determine composition of protection
2488 * groups involved in setting up buffer lists
2489 *
James Smartacd68592012-01-18 16:25:09 -05002490 * Returns: Protection group type (with or without DIF)
2491 *
2492 **/
James Smarte2a0a9d2008-12-04 22:40:02 -05002493static int
2494lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
2495{
2496 int ret = LPFC_PG_TYPE_INVALID;
2497 unsigned char op = scsi_get_prot_op(sc);
2498
2499 switch (op) {
2500 case SCSI_PROT_READ_STRIP:
2501 case SCSI_PROT_WRITE_INSERT:
2502 ret = LPFC_PG_TYPE_NO_DIF;
2503 break;
2504 case SCSI_PROT_READ_INSERT:
2505 case SCSI_PROT_WRITE_STRIP:
2506 case SCSI_PROT_READ_PASS:
2507 case SCSI_PROT_WRITE_PASS:
James Smarte2a0a9d2008-12-04 22:40:02 -05002508 ret = LPFC_PG_TYPE_DIF_BUF;
2509 break;
2510 default:
2511 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2512 "9021 Unsupported protection op:%d\n", op);
2513 break;
2514 }
2515
2516 return ret;
2517}
2518
James Smartacd68592012-01-18 16:25:09 -05002519/**
2520 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2521 * @phba: The Hba for which this call is being executed.
2522 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2523 *
James Smarte2a0a9d2008-12-04 22:40:02 -05002524 * This is the protection/DIF aware version of
2525 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2526 * two functions eventually, but for now, it's here
James Smartacd68592012-01-18 16:25:09 -05002527 **/
James Smarte2a0a9d2008-12-04 22:40:02 -05002528static int
James Smartacd68592012-01-18 16:25:09 -05002529lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba,
James Smarte2a0a9d2008-12-04 22:40:02 -05002530 struct lpfc_scsi_buf *lpfc_cmd)
2531{
2532 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2533 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2534 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
2535 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2536 uint32_t num_bde = 0;
2537 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
2538 int prot_group_type = 0;
2539 int diflen, fcpdl;
2540 unsigned blksize;
2541
2542 /*
2543 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2544 * fcp_rsp regions to the first data bde entry
2545 */
2546 bpl += 2;
2547 if (scsi_sg_count(scsi_cmnd)) {
2548 /*
2549 * The driver stores the segment count returned from pci_map_sg
2550 * because this a count of dma-mappings used to map the use_sg
2551 * pages. They are not guaranteed to be the same for those
2552 * architectures that implement an IOMMU.
2553 */
2554 datasegcnt = dma_map_sg(&phba->pcidev->dev,
2555 scsi_sglist(scsi_cmnd),
2556 scsi_sg_count(scsi_cmnd), datadir);
2557 if (unlikely(!datasegcnt))
2558 return 1;
2559
2560 lpfc_cmd->seg_cnt = datasegcnt;
2561 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04002562 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2563 "9067 BLKGRD: %s: Too many sg segments"
2564 " from dma_map_sg. Config %d, seg_cnt"
2565 " %d\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002566 __func__, phba->cfg_sg_seg_cnt,
2567 lpfc_cmd->seg_cnt);
2568 scsi_dma_unmap(scsi_cmnd);
2569 return 1;
2570 }
2571
2572 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
2573
2574 switch (prot_group_type) {
2575 case LPFC_PG_TYPE_NO_DIF:
2576 num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
2577 datasegcnt);
Adam Buchbinderc9404c92009-12-18 15:40:42 -05002578 /* we should have 2 or more entries in buffer list */
James Smarte2a0a9d2008-12-04 22:40:02 -05002579 if (num_bde < 2)
2580 goto err;
2581 break;
2582 case LPFC_PG_TYPE_DIF_BUF:{
2583 /*
2584 * This type indicates that protection buffers are
2585 * passed to the driver, so that needs to be prepared
2586 * for DMA
2587 */
2588 protsegcnt = dma_map_sg(&phba->pcidev->dev,
2589 scsi_prot_sglist(scsi_cmnd),
2590 scsi_prot_sg_count(scsi_cmnd), datadir);
2591 if (unlikely(!protsegcnt)) {
2592 scsi_dma_unmap(scsi_cmnd);
2593 return 1;
2594 }
2595
2596 lpfc_cmd->prot_seg_cnt = protsegcnt;
2597 if (lpfc_cmd->prot_seg_cnt
2598 > phba->cfg_prot_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04002599 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2600 "9068 BLKGRD: %s: Too many prot sg "
2601 "segments from dma_map_sg. Config %d,"
James Smarte2a0a9d2008-12-04 22:40:02 -05002602 "prot_seg_cnt %d\n", __func__,
2603 phba->cfg_prot_sg_seg_cnt,
2604 lpfc_cmd->prot_seg_cnt);
2605 dma_unmap_sg(&phba->pcidev->dev,
2606 scsi_prot_sglist(scsi_cmnd),
2607 scsi_prot_sg_count(scsi_cmnd),
2608 datadir);
2609 scsi_dma_unmap(scsi_cmnd);
2610 return 1;
2611 }
2612
2613 num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
2614 datasegcnt, protsegcnt);
Adam Buchbinderc9404c92009-12-18 15:40:42 -05002615 /* we should have 3 or more entries in buffer list */
James Smarte2a0a9d2008-12-04 22:40:02 -05002616 if (num_bde < 3)
2617 goto err;
2618 break;
2619 }
2620 case LPFC_PG_TYPE_INVALID:
2621 default:
2622 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2623 "9022 Unexpected protection group %i\n",
2624 prot_group_type);
2625 return 1;
2626 }
2627 }
2628
2629 /*
2630 * Finish initializing those IOCB fields that are dependent on the
2631 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2632 * reinitialized since all iocb memory resources are used many times
2633 * for transmit, receive, and continuation bpl's.
2634 */
2635 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
2636 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
2637 iocb_cmd->ulpBdeCount = 1;
2638 iocb_cmd->ulpLe = 1;
2639
2640 fcpdl = scsi_bufflen(scsi_cmnd);
2641
2642 if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) {
2643 /*
2644 * We are in DIF Type 1 mode
2645 * Every data block has a 8 byte DIF (trailer)
2646 * attached to it. Must ajust FCP data length
2647 */
2648 blksize = lpfc_cmd_blksize(scsi_cmnd);
2649 diflen = (fcpdl / blksize) * 8;
2650 fcpdl += diflen;
2651 }
2652 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
2653
2654 /*
2655 * Due to difference in data length between DIF/non-DIF paths,
2656 * we need to set word 4 of IOCB here
2657 */
2658 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
2659
2660 return 0;
2661err:
2662 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2663 "9023 Could not setup all needed BDE's"
2664 "prot_group_type=%d, num_bde=%d\n",
2665 prot_group_type, num_bde);
2666 return 1;
2667}
2668
2669/*
2670 * This function checks for BlockGuard errors detected by
2671 * the HBA. In case of errors, the ASC/ASCQ fields in the
2672 * sense buffer will be set accordingly, paired with
2673 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2674 * detected corruption.
2675 *
2676 * Returns:
2677 * 0 - No error found
2678 * 1 - BlockGuard error found
2679 * -1 - Internal error (bad profile, ...etc)
2680 */
2681static int
2682lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
2683 struct lpfc_iocbq *pIocbOut)
2684{
2685 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2686 struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
2687 int ret = 0;
2688 uint32_t bghm = bgf->bghm;
2689 uint32_t bgstat = bgf->bgstat;
2690 uint64_t failing_sector = 0;
2691
James Smart6a9c52c2009-10-02 15:16:51 -04002692 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9069 BLKGRD: BG ERROR in cmd"
2693 " 0x%x lba 0x%llx blk cnt 0x%x "
James Smarte2a0a9d2008-12-04 22:40:02 -05002694 "bgstat=0x%x bghm=0x%x\n",
James Smart87b5c322008-12-16 10:34:09 -05002695 cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd),
Tejun Heo83096eb2009-05-07 22:24:39 +09002696 blk_rq_sectors(cmd->request), bgstat, bghm);
James Smarte2a0a9d2008-12-04 22:40:02 -05002697
2698 spin_lock(&_dump_buf_lock);
2699 if (!_dump_buf_done) {
James Smart6a9c52c2009-10-02 15:16:51 -04002700 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving"
2701 " Data for %u blocks to debugfs\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002702 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
James Smart6a9c52c2009-10-02 15:16:51 -04002703 lpfc_debug_save_data(phba, cmd);
James Smarte2a0a9d2008-12-04 22:40:02 -05002704
2705 /* If we have a prot sgl, save the DIF buffer */
2706 if (lpfc_prot_group_type(phba, cmd) ==
2707 LPFC_PG_TYPE_DIF_BUF) {
James Smart6a9c52c2009-10-02 15:16:51 -04002708 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: "
2709 "Saving DIF for %u blocks to debugfs\n",
2710 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
2711 lpfc_debug_save_dif(phba, cmd);
James Smarte2a0a9d2008-12-04 22:40:02 -05002712 }
2713
2714 _dump_buf_done = 1;
2715 }
2716 spin_unlock(&_dump_buf_lock);
2717
2718 if (lpfc_bgs_get_invalid_prof(bgstat)) {
2719 cmd->result = ScsiResult(DID_ERROR, 0);
James Smart6a9c52c2009-10-02 15:16:51 -04002720 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9072 BLKGRD: Invalid"
2721 " BlockGuard profile. bgstat:0x%x\n",
2722 bgstat);
James Smarte2a0a9d2008-12-04 22:40:02 -05002723 ret = (-1);
2724 goto out;
2725 }
2726
2727 if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
2728 cmd->result = ScsiResult(DID_ERROR, 0);
James Smart6a9c52c2009-10-02 15:16:51 -04002729 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9073 BLKGRD: "
2730 "Invalid BlockGuard DIF Block. bgstat:0x%x\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002731 bgstat);
2732 ret = (-1);
2733 goto out;
2734 }
2735
2736 if (lpfc_bgs_get_guard_err(bgstat)) {
2737 ret = 1;
2738
2739 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2740 0x10, 0x1);
Martin K. Petersen1c9fbaf2009-01-04 03:14:11 -05002741 cmd->result = DRIVER_SENSE << 24
James Smarte2a0a9d2008-12-04 22:40:02 -05002742 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
2743 phba->bg_guard_err_cnt++;
James Smart6a9c52c2009-10-02 15:16:51 -04002744 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2745 "9055 BLKGRD: guard_tag error\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05002746 }
2747
2748 if (lpfc_bgs_get_reftag_err(bgstat)) {
2749 ret = 1;
2750
2751 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2752 0x10, 0x3);
Martin K. Petersen1c9fbaf2009-01-04 03:14:11 -05002753 cmd->result = DRIVER_SENSE << 24
James Smarte2a0a9d2008-12-04 22:40:02 -05002754 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
2755
2756 phba->bg_reftag_err_cnt++;
James Smart6a9c52c2009-10-02 15:16:51 -04002757 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2758 "9056 BLKGRD: ref_tag error\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05002759 }
2760
2761 if (lpfc_bgs_get_apptag_err(bgstat)) {
2762 ret = 1;
2763
2764 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2765 0x10, 0x2);
Martin K. Petersen1c9fbaf2009-01-04 03:14:11 -05002766 cmd->result = DRIVER_SENSE << 24
James Smarte2a0a9d2008-12-04 22:40:02 -05002767 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
2768
2769 phba->bg_apptag_err_cnt++;
James Smart6a9c52c2009-10-02 15:16:51 -04002770 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2771 "9061 BLKGRD: app_tag error\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05002772 }
2773
2774 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
2775 /*
2776 * setup sense data descriptor 0 per SPC-4 as an information
James Smart7c56b9f2011-07-22 18:36:25 -04002777 * field, and put the failing LBA in it.
2778 * This code assumes there was also a guard/app/ref tag error
2779 * indication.
James Smarte2a0a9d2008-12-04 22:40:02 -05002780 */
James Smart7c56b9f2011-07-22 18:36:25 -04002781 cmd->sense_buffer[7] = 0xc; /* Additional sense length */
2782 cmd->sense_buffer[8] = 0; /* Information descriptor type */
2783 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
2784 cmd->sense_buffer[10] = 0x80; /* Validity bit */
James Smartacd68592012-01-18 16:25:09 -05002785
2786 /* bghm is a "on the wire" FC frame based count */
2787 switch (scsi_get_prot_op(cmd)) {
2788 case SCSI_PROT_READ_INSERT:
2789 case SCSI_PROT_WRITE_STRIP:
2790 bghm /= cmd->device->sector_size;
2791 break;
2792 case SCSI_PROT_READ_STRIP:
2793 case SCSI_PROT_WRITE_INSERT:
2794 case SCSI_PROT_READ_PASS:
2795 case SCSI_PROT_WRITE_PASS:
2796 bghm /= (cmd->device->sector_size +
2797 sizeof(struct scsi_dif_tuple));
2798 break;
2799 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002800
2801 failing_sector = scsi_get_lba(cmd);
2802 failing_sector += bghm;
2803
James Smart7c56b9f2011-07-22 18:36:25 -04002804 /* Descriptor Information */
2805 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
James Smarte2a0a9d2008-12-04 22:40:02 -05002806 }
2807
2808 if (!ret) {
2809 /* No error was reported - problem in FW? */
2810 cmd->result = ScsiResult(DID_ERROR, 0);
James Smart6a9c52c2009-10-02 15:16:51 -04002811 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2812 "9057 BLKGRD: no errors reported!\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05002813 }
2814
2815out:
2816 return ret;
2817}
2818
James Smartea2151b2008-09-07 11:52:10 -04002819/**
James Smartda0436e2009-05-22 14:51:39 -04002820 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
2821 * @phba: The Hba for which this call is being executed.
2822 * @lpfc_cmd: The scsi buffer which is going to be mapped.
2823 *
2824 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
2825 * field of @lpfc_cmd for device with SLI-4 interface spec.
2826 *
2827 * Return codes:
James Smart6c8eea52010-04-06 14:49:53 -04002828 * 1 - Error
2829 * 0 - Success
James Smartda0436e2009-05-22 14:51:39 -04002830 **/
2831static int
2832lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
2833{
2834 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2835 struct scatterlist *sgel = NULL;
2836 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2837 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
James Smartfedd3b72011-02-16 12:39:24 -05002838 struct sli4_sge *first_data_sgl;
James Smartda0436e2009-05-22 14:51:39 -04002839 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2840 dma_addr_t physaddr;
2841 uint32_t num_bde = 0;
2842 uint32_t dma_len;
2843 uint32_t dma_offset = 0;
2844 int nseg;
James Smartfedd3b72011-02-16 12:39:24 -05002845 struct ulp_bde64 *bde;
James Smartda0436e2009-05-22 14:51:39 -04002846
2847 /*
2848 * There are three possibilities here - use scatter-gather segment, use
2849 * the single mapping, or neither. Start the lpfc command prep by
2850 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
2851 * data bde entry.
2852 */
2853 if (scsi_sg_count(scsi_cmnd)) {
2854 /*
2855 * The driver stores the segment count returned from pci_map_sg
2856 * because this a count of dma-mappings used to map the use_sg
2857 * pages. They are not guaranteed to be the same for those
2858 * architectures that implement an IOMMU.
2859 */
2860
2861 nseg = scsi_dma_map(scsi_cmnd);
2862 if (unlikely(!nseg))
2863 return 1;
2864 sgl += 1;
2865 /* clear the last flag in the fcp_rsp map entry */
2866 sgl->word2 = le32_to_cpu(sgl->word2);
2867 bf_set(lpfc_sli4_sge_last, sgl, 0);
2868 sgl->word2 = cpu_to_le32(sgl->word2);
2869 sgl += 1;
James Smartfedd3b72011-02-16 12:39:24 -05002870 first_data_sgl = sgl;
James Smartda0436e2009-05-22 14:51:39 -04002871 lpfc_cmd->seg_cnt = nseg;
2872 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04002873 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
2874 " %s: Too many sg segments from "
2875 "dma_map_sg. Config %d, seg_cnt %d\n",
2876 __func__, phba->cfg_sg_seg_cnt,
James Smartda0436e2009-05-22 14:51:39 -04002877 lpfc_cmd->seg_cnt);
2878 scsi_dma_unmap(scsi_cmnd);
2879 return 1;
2880 }
2881
2882 /*
2883 * The driver established a maximum scatter-gather segment count
2884 * during probe that limits the number of sg elements in any
2885 * single scsi command. Just run through the seg_cnt and format
2886 * the sge's.
2887 * When using SLI-3 the driver will try to fit all the BDEs into
2888 * the IOCB. If it can't then the BDEs get added to a BPL as it
2889 * does for SLI-2 mode.
2890 */
2891 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
2892 physaddr = sg_dma_address(sgel);
2893 dma_len = sg_dma_len(sgel);
James Smartda0436e2009-05-22 14:51:39 -04002894 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
2895 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
James Smart05580562011-05-24 11:40:48 -04002896 sgl->word2 = le32_to_cpu(sgl->word2);
James Smartda0436e2009-05-22 14:51:39 -04002897 if ((num_bde + 1) == nseg)
2898 bf_set(lpfc_sli4_sge_last, sgl, 1);
2899 else
2900 bf_set(lpfc_sli4_sge_last, sgl, 0);
2901 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
James Smartf9bb2da2011-10-10 21:34:11 -04002902 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
James Smartda0436e2009-05-22 14:51:39 -04002903 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart28baac72010-02-12 14:42:03 -05002904 sgl->sge_len = cpu_to_le32(dma_len);
James Smartda0436e2009-05-22 14:51:39 -04002905 dma_offset += dma_len;
2906 sgl++;
2907 }
James Smartfedd3b72011-02-16 12:39:24 -05002908 /* setup the performance hint (first data BDE) if enabled */
2909 if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) {
2910 bde = (struct ulp_bde64 *)
2911 &(iocb_cmd->unsli3.sli3Words[5]);
2912 bde->addrLow = first_data_sgl->addr_lo;
2913 bde->addrHigh = first_data_sgl->addr_hi;
2914 bde->tus.f.bdeSize =
2915 le32_to_cpu(first_data_sgl->sge_len);
2916 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2917 bde->tus.w = cpu_to_le32(bde->tus.w);
2918 }
James Smartda0436e2009-05-22 14:51:39 -04002919 } else {
2920 sgl += 1;
2921 /* clear the last flag in the fcp_rsp map entry */
2922 sgl->word2 = le32_to_cpu(sgl->word2);
2923 bf_set(lpfc_sli4_sge_last, sgl, 1);
2924 sgl->word2 = cpu_to_le32(sgl->word2);
2925 }
2926
2927 /*
2928 * Finish initializing those IOCB fields that are dependent on the
2929 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
2930 * explicitly reinitialized.
2931 * all iocb memory resources are reused.
2932 */
2933 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
2934
2935 /*
2936 * Due to difference in data length between DIF/non-DIF paths,
2937 * we need to set word 4 of IOCB here
2938 */
2939 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
2940 return 0;
2941}
2942
2943/**
James Smartacd68592012-01-18 16:25:09 -05002944 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2945 * @phba: The Hba for which this call is being executed.
2946 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2947 *
2948 * Adjust the data length to account for how much data
2949 * is actually on the wire.
2950 *
2951 * returns the adjusted data length
2952 **/
2953static int
2954lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
2955 struct lpfc_scsi_buf *lpfc_cmd)
2956{
2957 struct scsi_cmnd *sc = lpfc_cmd->pCmd;
2958 int diflen, fcpdl;
2959 unsigned blksize;
2960
2961 fcpdl = scsi_bufflen(sc);
2962
2963 /* Check if there is protection data on the wire */
2964 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2965 /* Read */
2966 if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT)
2967 return fcpdl;
2968
2969 } else {
2970 /* Write */
2971 if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP)
2972 return fcpdl;
2973 }
2974
2975 /* If protection data on the wire, adjust the count accordingly */
2976 blksize = lpfc_cmd_blksize(sc);
2977 diflen = (fcpdl / blksize) * 8;
2978 fcpdl += diflen;
2979 return fcpdl;
2980}
2981
2982/**
2983 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
2984 * @phba: The Hba for which this call is being executed.
2985 * @lpfc_cmd: The scsi buffer which is going to be mapped.
2986 *
2987 * This is the protection/DIF aware version of
2988 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2989 * two functions eventually, but for now, it's here
2990 **/
2991static int
2992lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba,
2993 struct lpfc_scsi_buf *lpfc_cmd)
2994{
2995 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2996 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2997 struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl);
2998 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2999 uint32_t num_bde = 0;
3000 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
3001 int prot_group_type = 0;
3002 int fcpdl;
3003
3004 /*
3005 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3006 * fcp_rsp regions to the first data bde entry
3007 */
3008 if (scsi_sg_count(scsi_cmnd)) {
3009 /*
3010 * The driver stores the segment count returned from pci_map_sg
3011 * because this a count of dma-mappings used to map the use_sg
3012 * pages. They are not guaranteed to be the same for those
3013 * architectures that implement an IOMMU.
3014 */
3015 datasegcnt = dma_map_sg(&phba->pcidev->dev,
3016 scsi_sglist(scsi_cmnd),
3017 scsi_sg_count(scsi_cmnd), datadir);
3018 if (unlikely(!datasegcnt))
3019 return 1;
3020
3021 sgl += 1;
3022 /* clear the last flag in the fcp_rsp map entry */
3023 sgl->word2 = le32_to_cpu(sgl->word2);
3024 bf_set(lpfc_sli4_sge_last, sgl, 0);
3025 sgl->word2 = cpu_to_le32(sgl->word2);
3026
3027 sgl += 1;
3028 lpfc_cmd->seg_cnt = datasegcnt;
3029 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
3030 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
3031 "9087 BLKGRD: %s: Too many sg segments"
3032 " from dma_map_sg. Config %d, seg_cnt"
3033 " %d\n",
3034 __func__, phba->cfg_sg_seg_cnt,
3035 lpfc_cmd->seg_cnt);
3036 scsi_dma_unmap(scsi_cmnd);
3037 return 1;
3038 }
3039
3040 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
3041
3042 switch (prot_group_type) {
3043 case LPFC_PG_TYPE_NO_DIF:
3044 num_bde = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl,
3045 datasegcnt);
3046 /* we should have 2 or more entries in buffer list */
3047 if (num_bde < 2)
3048 goto err;
3049 break;
3050 case LPFC_PG_TYPE_DIF_BUF:{
3051 /*
3052 * This type indicates that protection buffers are
3053 * passed to the driver, so that needs to be prepared
3054 * for DMA
3055 */
3056 protsegcnt = dma_map_sg(&phba->pcidev->dev,
3057 scsi_prot_sglist(scsi_cmnd),
3058 scsi_prot_sg_count(scsi_cmnd), datadir);
3059 if (unlikely(!protsegcnt)) {
3060 scsi_dma_unmap(scsi_cmnd);
3061 return 1;
3062 }
3063
3064 lpfc_cmd->prot_seg_cnt = protsegcnt;
3065 if (lpfc_cmd->prot_seg_cnt
3066 > phba->cfg_prot_sg_seg_cnt) {
3067 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
3068 "9088 BLKGRD: %s: Too many prot sg "
3069 "segments from dma_map_sg. Config %d,"
3070 "prot_seg_cnt %d\n", __func__,
3071 phba->cfg_prot_sg_seg_cnt,
3072 lpfc_cmd->prot_seg_cnt);
3073 dma_unmap_sg(&phba->pcidev->dev,
3074 scsi_prot_sglist(scsi_cmnd),
3075 scsi_prot_sg_count(scsi_cmnd),
3076 datadir);
3077 scsi_dma_unmap(scsi_cmnd);
3078 return 1;
3079 }
3080
3081 num_bde = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl,
3082 datasegcnt, protsegcnt);
3083 /* we should have 3 or more entries in buffer list */
3084 if (num_bde < 3)
3085 goto err;
3086 break;
3087 }
3088 case LPFC_PG_TYPE_INVALID:
3089 default:
3090 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3091 "9083 Unexpected protection group %i\n",
3092 prot_group_type);
3093 return 1;
3094 }
3095 }
3096
3097 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
3098
3099 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
3100
3101 /*
3102 * Due to difference in data length between DIF/non-DIF paths,
3103 * we need to set word 4 of IOCB here
3104 */
3105 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
3106 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF;
3107
3108 return 0;
3109err:
3110 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3111 "9084 Could not setup all needed BDE's"
3112 "prot_group_type=%d, num_bde=%d\n",
3113 prot_group_type, num_bde);
3114 return 1;
3115}
3116
3117/**
James Smart3772a992009-05-22 14:50:54 -04003118 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3119 * @phba: The Hba for which this call is being executed.
3120 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3121 *
3122 * This routine wraps the actual DMA mapping function pointer from the
3123 * lpfc_hba struct.
3124 *
3125 * Return codes:
James Smart6c8eea52010-04-06 14:49:53 -04003126 * 1 - Error
3127 * 0 - Success
James Smart3772a992009-05-22 14:50:54 -04003128 **/
3129static inline int
3130lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3131{
3132 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
3133}
3134
3135/**
James Smartacd68592012-01-18 16:25:09 -05003136 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3137 * using BlockGuard.
3138 * @phba: The Hba for which this call is being executed.
3139 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3140 *
3141 * This routine wraps the actual DMA mapping function pointer from the
3142 * lpfc_hba struct.
3143 *
3144 * Return codes:
3145 * 1 - Error
3146 * 0 - Success
3147 **/
3148static inline int
3149lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3150{
3151 return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
3152}
3153
3154/**
James Smart3621a712009-04-06 18:47:14 -04003155 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
James Smartea2151b2008-09-07 11:52:10 -04003156 * @phba: Pointer to hba context object.
3157 * @vport: Pointer to vport object.
3158 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3159 * @rsp_iocb: Pointer to response iocb object which reported error.
3160 *
3161 * This function posts an event when there is a SCSI command reporting
3162 * error from the scsi device.
3163 **/
3164static void
3165lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
3166 struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
3167 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3168 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3169 uint32_t resp_info = fcprsp->rspStatus2;
3170 uint32_t scsi_status = fcprsp->rspStatus3;
3171 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3172 struct lpfc_fast_path_event *fast_path_evt = NULL;
3173 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
3174 unsigned long flags;
3175
James Smart5989b8d2010-10-22 11:06:56 -04003176 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3177 return;
3178
James Smartea2151b2008-09-07 11:52:10 -04003179 /* If there is queuefull or busy condition send a scsi event */
3180 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
3181 (cmnd->result == SAM_STAT_BUSY)) {
3182 fast_path_evt = lpfc_alloc_fast_evt(phba);
3183 if (!fast_path_evt)
3184 return;
3185 fast_path_evt->un.scsi_evt.event_type =
3186 FC_REG_SCSI_EVENT;
3187 fast_path_evt->un.scsi_evt.subcategory =
3188 (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
3189 LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
3190 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
3191 memcpy(&fast_path_evt->un.scsi_evt.wwpn,
3192 &pnode->nlp_portname, sizeof(struct lpfc_name));
3193 memcpy(&fast_path_evt->un.scsi_evt.wwnn,
3194 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3195 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
3196 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
3197 fast_path_evt = lpfc_alloc_fast_evt(phba);
3198 if (!fast_path_evt)
3199 return;
3200 fast_path_evt->un.check_cond_evt.scsi_event.event_type =
3201 FC_REG_SCSI_EVENT;
3202 fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
3203 LPFC_EVENT_CHECK_COND;
3204 fast_path_evt->un.check_cond_evt.scsi_event.lun =
3205 cmnd->device->lun;
3206 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
3207 &pnode->nlp_portname, sizeof(struct lpfc_name));
3208 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
3209 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3210 fast_path_evt->un.check_cond_evt.sense_key =
3211 cmnd->sense_buffer[2] & 0xf;
3212 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
3213 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
3214 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3215 fcpi_parm &&
3216 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
3217 ((scsi_status == SAM_STAT_GOOD) &&
3218 !(resp_info & (RESID_UNDER | RESID_OVER))))) {
3219 /*
3220 * If status is good or resid does not match with fcp_param and
3221 * there is valid fcpi_parm, then there is a read_check error
3222 */
3223 fast_path_evt = lpfc_alloc_fast_evt(phba);
3224 if (!fast_path_evt)
3225 return;
3226 fast_path_evt->un.read_check_error.header.event_type =
3227 FC_REG_FABRIC_EVENT;
3228 fast_path_evt->un.read_check_error.header.subcategory =
3229 LPFC_EVENT_FCPRDCHKERR;
3230 memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
3231 &pnode->nlp_portname, sizeof(struct lpfc_name));
3232 memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
3233 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3234 fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
3235 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
3236 fast_path_evt->un.read_check_error.fcpiparam =
3237 fcpi_parm;
3238 } else
3239 return;
3240
3241 fast_path_evt->vport = vport;
3242 spin_lock_irqsave(&phba->hbalock, flags);
3243 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
3244 spin_unlock_irqrestore(&phba->hbalock, flags);
3245 lpfc_worker_wake_up(phba);
3246 return;
3247}
James Smart9bad7672008-12-04 22:39:02 -05003248
3249/**
James Smartf1126682009-06-10 17:22:44 -04003250 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
James Smart3772a992009-05-22 14:50:54 -04003251 * @phba: The HBA for which this call is being executed.
James Smart9bad7672008-12-04 22:39:02 -05003252 * @psb: The scsi buffer which is going to be un-mapped.
3253 *
3254 * This routine does DMA un-mapping of scatter gather list of scsi command
James Smart3772a992009-05-22 14:50:54 -04003255 * field of @lpfc_cmd for device with SLI-3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05003256 **/
dea31012005-04-17 16:05:31 -05003257static void
James Smartf1126682009-06-10 17:22:44 -04003258lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
James Smartbcf4dbf2006-07-06 15:50:08 -04003259{
3260 /*
3261 * There are only two special cases to consider. (1) the scsi command
3262 * requested scatter-gather usage or (2) the scsi command allocated
3263 * a request buffer, but did not request use_sg. There is a third
3264 * case, but it does not require resource deallocation.
3265 */
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003266 if (psb->seg_cnt > 0)
3267 scsi_dma_unmap(psb->pCmd);
James Smarte2a0a9d2008-12-04 22:40:02 -05003268 if (psb->prot_seg_cnt > 0)
3269 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
3270 scsi_prot_sg_count(psb->pCmd),
3271 psb->pCmd->sc_data_direction);
James Smartbcf4dbf2006-07-06 15:50:08 -04003272}
3273
James Smart9bad7672008-12-04 22:39:02 -05003274/**
James Smart3621a712009-04-06 18:47:14 -04003275 * lpfc_handler_fcp_err - FCP response handler
James Smart9bad7672008-12-04 22:39:02 -05003276 * @vport: The virtual port for which this call is being executed.
3277 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3278 * @rsp_iocb: The response IOCB which contains FCP error.
3279 *
3280 * This routine is called to process response IOCB with status field
3281 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3282 * based upon SCSI and FCP error.
3283 **/
James Smartbcf4dbf2006-07-06 15:50:08 -04003284static void
James Smart2e0fef82007-06-17 19:56:36 -05003285lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
3286 struct lpfc_iocbq *rsp_iocb)
dea31012005-04-17 16:05:31 -05003287{
3288 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3289 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
3290 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
James Smart7054a602007-04-25 09:52:34 -04003291 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
dea31012005-04-17 16:05:31 -05003292 uint32_t resp_info = fcprsp->rspStatus2;
3293 uint32_t scsi_status = fcprsp->rspStatus3;
James Smartc7743952006-12-02 13:34:42 -05003294 uint32_t *lp;
dea31012005-04-17 16:05:31 -05003295 uint32_t host_status = DID_OK;
3296 uint32_t rsplen = 0;
James Smartc7743952006-12-02 13:34:42 -05003297 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
dea31012005-04-17 16:05:31 -05003298
James Smartea2151b2008-09-07 11:52:10 -04003299
dea31012005-04-17 16:05:31 -05003300 /*
3301 * If this is a task management command, there is no
3302 * scsi packet associated with this lpfc_cmd. The driver
3303 * consumes it.
3304 */
3305 if (fcpcmd->fcpCntl2) {
3306 scsi_status = 0;
3307 goto out;
3308 }
3309
James Smart6a9c52c2009-10-02 15:16:51 -04003310 if (resp_info & RSP_LEN_VALID) {
3311 rsplen = be32_to_cpu(fcprsp->rspRspLen);
James Smarte40a02c2010-02-26 14:13:54 -05003312 if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
James Smart6a9c52c2009-10-02 15:16:51 -04003313 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3314 "2719 Invalid response length: "
3315 "tgt x%x lun x%x cmnd x%x rsplen x%x\n",
3316 cmnd->device->id,
3317 cmnd->device->lun, cmnd->cmnd[0],
3318 rsplen);
3319 host_status = DID_ERROR;
3320 goto out;
3321 }
James Smarte40a02c2010-02-26 14:13:54 -05003322 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
3323 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3324 "2757 Protocol failure detected during "
3325 "processing of FCP I/O op: "
3326 "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n",
3327 cmnd->device->id,
3328 cmnd->device->lun, cmnd->cmnd[0],
3329 fcprsp->rspInfo3);
3330 host_status = DID_ERROR;
3331 goto out;
3332 }
James Smart6a9c52c2009-10-02 15:16:51 -04003333 }
3334
James Smartc7743952006-12-02 13:34:42 -05003335 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
3336 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
3337 if (snslen > SCSI_SENSE_BUFFERSIZE)
3338 snslen = SCSI_SENSE_BUFFERSIZE;
3339
3340 if (resp_info & RSP_LEN_VALID)
3341 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3342 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
3343 }
3344 lp = (uint32_t *)cmnd->sense_buffer;
3345
James Smart73d91e52011-10-10 21:32:10 -04003346 if (!scsi_status && (resp_info & RESID_UNDER) &&
3347 vport->cfg_log_verbose & LOG_FCP_UNDER)
3348 logit = LOG_FCP_UNDER;
James Smartc7743952006-12-02 13:34:42 -05003349
James Smarte8b62012007-08-02 11:10:09 -04003350 lpfc_printf_vlog(vport, KERN_WARNING, logit,
James Smarte2a0a9d2008-12-04 22:40:02 -05003351 "9024 FCP command x%x failed: x%x SNS x%x x%x "
James Smarte8b62012007-08-02 11:10:09 -04003352 "Data: x%x x%x x%x x%x x%x\n",
3353 cmnd->cmnd[0], scsi_status,
3354 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
3355 be32_to_cpu(fcprsp->rspResId),
3356 be32_to_cpu(fcprsp->rspSnsLen),
3357 be32_to_cpu(fcprsp->rspRspLen),
3358 fcprsp->rspInfo3);
dea31012005-04-17 16:05:31 -05003359
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003360 scsi_set_resid(cmnd, 0);
dea31012005-04-17 16:05:31 -05003361 if (resp_info & RESID_UNDER) {
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003362 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
dea31012005-04-17 16:05:31 -05003363
James Smart73d91e52011-10-10 21:32:10 -04003364 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
James Smarte2a0a9d2008-12-04 22:40:02 -05003365 "9025 FCP Read Underrun, expected %d, "
James Smarte8b62012007-08-02 11:10:09 -04003366 "residual %d Data: x%x x%x x%x\n",
3367 be32_to_cpu(fcpcmd->fcpDl),
3368 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
3369 cmnd->underflow);
dea31012005-04-17 16:05:31 -05003370
3371 /*
James Smart7054a602007-04-25 09:52:34 -04003372 * If there is an under run check if under run reported by
3373 * storage array is same as the under run reported by HBA.
3374 * If this is not same, there is a dropped frame.
3375 */
3376 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3377 fcpi_parm &&
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003378 (scsi_get_resid(cmnd) != fcpi_parm)) {
James Smarte8b62012007-08-02 11:10:09 -04003379 lpfc_printf_vlog(vport, KERN_WARNING,
3380 LOG_FCP | LOG_FCP_ERROR,
James Smarte2a0a9d2008-12-04 22:40:02 -05003381 "9026 FCP Read Check Error "
James Smarte8b62012007-08-02 11:10:09 -04003382 "and Underrun Data: x%x x%x x%x x%x\n",
3383 be32_to_cpu(fcpcmd->fcpDl),
3384 scsi_get_resid(cmnd), fcpi_parm,
3385 cmnd->cmnd[0]);
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003386 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
James Smart7054a602007-04-25 09:52:34 -04003387 host_status = DID_ERROR;
3388 }
3389 /*
dea31012005-04-17 16:05:31 -05003390 * The cmnd->underflow is the minimum number of bytes that must
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003391 * be transferred for this command. Provided a sense condition
dea31012005-04-17 16:05:31 -05003392 * is not present, make sure the actual amount transferred is at
3393 * least the underflow value or fail.
3394 */
3395 if (!(resp_info & SNS_LEN_VALID) &&
3396 (scsi_status == SAM_STAT_GOOD) &&
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003397 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
3398 < cmnd->underflow)) {
James Smarte8b62012007-08-02 11:10:09 -04003399 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
James Smarte2a0a9d2008-12-04 22:40:02 -05003400 "9027 FCP command x%x residual "
James Smarte8b62012007-08-02 11:10:09 -04003401 "underrun converted to error "
3402 "Data: x%x x%x x%x\n",
James Smart66dbfbe2007-08-05 06:08:38 -04003403 cmnd->cmnd[0], scsi_bufflen(cmnd),
James Smarte8b62012007-08-02 11:10:09 -04003404 scsi_get_resid(cmnd), cmnd->underflow);
dea31012005-04-17 16:05:31 -05003405 host_status = DID_ERROR;
3406 }
3407 } else if (resp_info & RESID_OVER) {
James Smarte8b62012007-08-02 11:10:09 -04003408 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
James Smarte2a0a9d2008-12-04 22:40:02 -05003409 "9028 FCP command x%x residual overrun error. "
James Smarte4e74272009-07-19 10:01:38 -04003410 "Data: x%x x%x\n", cmnd->cmnd[0],
James Smarte8b62012007-08-02 11:10:09 -04003411 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
dea31012005-04-17 16:05:31 -05003412 host_status = DID_ERROR;
3413
3414 /*
3415 * Check SLI validation that all the transfer was actually done
3416 * (fcpi_parm should be zero). Apply check only to reads.
3417 */
James Smarteee88772010-09-29 11:19:08 -04003418 } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
James Smarte8b62012007-08-02 11:10:09 -04003419 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
James Smarte2a0a9d2008-12-04 22:40:02 -05003420 "9029 FCP Read Check Error Data: "
James Smarteee88772010-09-29 11:19:08 -04003421 "x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003422 be32_to_cpu(fcpcmd->fcpDl),
3423 be32_to_cpu(fcprsp->rspResId),
James Smarteee88772010-09-29 11:19:08 -04003424 fcpi_parm, cmnd->cmnd[0], scsi_status);
3425 switch (scsi_status) {
3426 case SAM_STAT_GOOD:
3427 case SAM_STAT_CHECK_CONDITION:
3428 /* Fabric dropped a data frame. Fail any successful
3429 * command in which we detected dropped frames.
3430 * A status of good or some check conditions could
3431 * be considered a successful command.
3432 */
3433 host_status = DID_ERROR;
3434 break;
3435 }
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003436 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
dea31012005-04-17 16:05:31 -05003437 }
3438
3439 out:
3440 cmnd->result = ScsiResult(host_status, scsi_status);
James Smartea2151b2008-09-07 11:52:10 -04003441 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
dea31012005-04-17 16:05:31 -05003442}
3443
James Smart9bad7672008-12-04 22:39:02 -05003444/**
James Smart3621a712009-04-06 18:47:14 -04003445 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
James Smart9bad7672008-12-04 22:39:02 -05003446 * @phba: The Hba for which this call is being executed.
3447 * @pIocbIn: The command IOCBQ for the scsi cmnd.
James Smart3772a992009-05-22 14:50:54 -04003448 * @pIocbOut: The response IOCBQ for the scsi cmnd.
James Smart9bad7672008-12-04 22:39:02 -05003449 *
3450 * This routine assigns scsi command result by looking into response IOCB
3451 * status field appropriately. This routine handles QUEUE FULL condition as
3452 * well by ramping down device queue depth.
3453 **/
dea31012005-04-17 16:05:31 -05003454static void
3455lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
3456 struct lpfc_iocbq *pIocbOut)
3457{
3458 struct lpfc_scsi_buf *lpfc_cmd =
3459 (struct lpfc_scsi_buf *) pIocbIn->context1;
James Smart2e0fef82007-06-17 19:56:36 -05003460 struct lpfc_vport *vport = pIocbIn->vport;
dea31012005-04-17 16:05:31 -05003461 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
3462 struct lpfc_nodelist *pnode = rdata->pnode;
James Smart75baf692010-06-08 18:31:21 -04003463 struct scsi_cmnd *cmd;
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05003464 int result;
James Smarta257bf92009-04-06 18:48:10 -04003465 struct scsi_device *tmp_sdev;
James Smart5ffc2662009-11-18 15:39:44 -05003466 int depth;
James Smartfa61a542008-01-11 01:52:42 -05003467 unsigned long flags;
James Smartea2151b2008-09-07 11:52:10 -04003468 struct lpfc_fast_path_event *fast_path_evt;
James Smart75baf692010-06-08 18:31:21 -04003469 struct Scsi_Host *shost;
James Smarta257bf92009-04-06 18:48:10 -04003470 uint32_t queue_depth, scsi_id;
James Smart73d91e52011-10-10 21:32:10 -04003471 uint32_t logit = LOG_FCP;
dea31012005-04-17 16:05:31 -05003472
James Smart75baf692010-06-08 18:31:21 -04003473 /* Sanity check on return of outstanding command */
3474 if (!(lpfc_cmd->pCmd))
3475 return;
3476 cmd = lpfc_cmd->pCmd;
3477 shost = cmd->device->host;
3478
dea31012005-04-17 16:05:31 -05003479 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
3480 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
James Smart341af102010-01-26 23:07:37 -05003481 /* pick up SLI4 exhange busy status from HBA */
3482 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
3483
James Smart9a6b09c2012-03-01 22:37:42 -05003484#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3485 if (lpfc_cmd->prot_data_type) {
3486 struct scsi_dif_tuple *src = NULL;
3487
3488 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
3489 /*
3490 * Used to restore any changes to protection
3491 * data for error injection.
3492 */
3493 switch (lpfc_cmd->prot_data_type) {
3494 case LPFC_INJERR_REFTAG:
3495 src->ref_tag =
3496 lpfc_cmd->prot_data;
3497 break;
3498 case LPFC_INJERR_APPTAG:
3499 src->app_tag =
3500 (uint16_t)lpfc_cmd->prot_data;
3501 break;
3502 case LPFC_INJERR_GUARD:
3503 src->guard_tag =
3504 (uint16_t)lpfc_cmd->prot_data;
3505 break;
3506 default:
3507 break;
3508 }
3509
3510 lpfc_cmd->prot_data = 0;
3511 lpfc_cmd->prot_data_type = 0;
3512 lpfc_cmd->prot_data_segment = NULL;
3513 }
3514#endif
James Smart109f6ed2008-12-04 22:39:08 -05003515 if (pnode && NLP_CHK_NODE_ACT(pnode))
3516 atomic_dec(&pnode->cmd_pending);
dea31012005-04-17 16:05:31 -05003517
3518 if (lpfc_cmd->status) {
3519 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
3520 (lpfc_cmd->result & IOERR_DRVR_MASK))
3521 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3522 else if (lpfc_cmd->status >= IOSTAT_CNT)
3523 lpfc_cmd->status = IOSTAT_DEFAULT;
James Smart73d91e52011-10-10 21:32:10 -04003524 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR
3525 && !lpfc_cmd->fcp_rsp->rspStatus3
3526 && (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER)
3527 && !(phba->cfg_log_verbose & LOG_FCP_UNDER))
3528 logit = 0;
3529 else
3530 logit = LOG_FCP | LOG_FCP_UNDER;
3531 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3532 "9030 FCP cmd x%x failed <%d/%d> "
3533 "status: x%x result: x%x Data: x%x x%x\n",
3534 cmd->cmnd[0],
3535 cmd->device ? cmd->device->id : 0xffff,
3536 cmd->device ? cmd->device->lun : 0xffff,
3537 lpfc_cmd->status, lpfc_cmd->result,
3538 pIocbOut->iocb.ulpContext,
3539 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05003540
3541 switch (lpfc_cmd->status) {
3542 case IOSTAT_FCP_RSP_ERROR:
3543 /* Call FCP RSP handler to determine result */
James Smart2e0fef82007-06-17 19:56:36 -05003544 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
dea31012005-04-17 16:05:31 -05003545 break;
3546 case IOSTAT_NPORT_BSY:
3547 case IOSTAT_FABRIC_BSY:
James Smart0f1f53a2008-08-24 21:50:18 -04003548 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
James Smartea2151b2008-09-07 11:52:10 -04003549 fast_path_evt = lpfc_alloc_fast_evt(phba);
3550 if (!fast_path_evt)
3551 break;
3552 fast_path_evt->un.fabric_evt.event_type =
3553 FC_REG_FABRIC_EVENT;
3554 fast_path_evt->un.fabric_evt.subcategory =
3555 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
3556 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
3557 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
3558 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
3559 &pnode->nlp_portname,
3560 sizeof(struct lpfc_name));
3561 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
3562 &pnode->nlp_nodename,
3563 sizeof(struct lpfc_name));
3564 }
3565 fast_path_evt->vport = vport;
3566 fast_path_evt->work_evt.evt =
3567 LPFC_EVT_FASTPATH_MGMT_EVT;
3568 spin_lock_irqsave(&phba->hbalock, flags);
3569 list_add_tail(&fast_path_evt->work_evt.evt_listp,
3570 &phba->work_list);
3571 spin_unlock_irqrestore(&phba->hbalock, flags);
3572 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05003573 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003574 case IOSTAT_LOCAL_REJECT:
James Smart1151e3e2011-02-16 12:39:35 -05003575 case IOSTAT_REMOTE_STOP:
James Smartab56dc22011-02-16 12:39:57 -05003576 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
3577 lpfc_cmd->result ==
3578 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
3579 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
3580 lpfc_cmd->result ==
3581 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
3582 cmd->result = ScsiResult(DID_NO_CONNECT, 0);
3583 break;
3584 }
James Smartd7c255b2008-08-24 21:50:00 -04003585 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
James Smart92d7f7b2007-06-17 19:56:38 -05003586 lpfc_cmd->result == IOERR_NO_RESOURCES ||
James Smartb92938b2010-06-07 15:24:12 -04003587 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
3588 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
James Smart92d7f7b2007-06-17 19:56:38 -05003589 cmd->result = ScsiResult(DID_REQUEUE, 0);
James Smart58da1ff2008-04-07 10:15:56 -04003590 break;
James Smarte2a0a9d2008-12-04 22:40:02 -05003591 }
James Smarte2a0a9d2008-12-04 22:40:02 -05003592 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
3593 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
3594 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
3595 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
3596 /*
3597 * This is a response for a BG enabled
3598 * cmd. Parse BG error
3599 */
3600 lpfc_parse_bg_err(phba, lpfc_cmd,
3601 pIocbOut);
3602 break;
3603 } else {
3604 lpfc_printf_vlog(vport, KERN_WARNING,
3605 LOG_BG,
3606 "9031 non-zero BGSTAT "
James Smart6a9c52c2009-10-02 15:16:51 -04003607 "on unprotected cmd\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05003608 }
3609 }
James Smart1151e3e2011-02-16 12:39:35 -05003610 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
3611 && (phba->sli_rev == LPFC_SLI_REV4)
3612 && (pnode && NLP_CHK_NODE_ACT(pnode))) {
3613 /* This IO was aborted by the target, we don't
3614 * know the rxid and because we did not send the
3615 * ABTS we cannot generate and RRQ.
3616 */
3617 lpfc_set_rrq_active(phba, pnode,
3618 lpfc_cmd->cur_iocbq.sli4_xritag,
3619 0, 0);
3620 }
James Smarte2a0a9d2008-12-04 22:40:02 -05003621 /* else: fall through */
dea31012005-04-17 16:05:31 -05003622 default:
3623 cmd->result = ScsiResult(DID_ERROR, 0);
3624 break;
3625 }
3626
James Smart58da1ff2008-04-07 10:15:56 -04003627 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003628 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
James Smart0f1f53a2008-08-24 21:50:18 -04003629 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
3630 SAM_STAT_BUSY);
James Smartab56dc22011-02-16 12:39:57 -05003631 } else
dea31012005-04-17 16:05:31 -05003632 cmd->result = ScsiResult(DID_OK, 0);
dea31012005-04-17 16:05:31 -05003633
3634 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
3635 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
3636
James Smarte8b62012007-08-02 11:10:09 -04003637 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3638 "0710 Iodone <%d/%d> cmd %p, error "
3639 "x%x SNS x%x x%x Data: x%x x%x\n",
3640 cmd->device->id, cmd->device->lun, cmd,
3641 cmd->result, *lp, *(lp + 3), cmd->retries,
3642 scsi_get_resid(cmd));
dea31012005-04-17 16:05:31 -05003643 }
3644
James Smartea2151b2008-09-07 11:52:10 -04003645 lpfc_update_stats(phba, lpfc_cmd);
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05003646 result = cmd->result;
James Smart977b5a02008-09-07 11:52:04 -04003647 if (vport->cfg_max_scsicmpl_time &&
3648 time_after(jiffies, lpfc_cmd->start_time +
3649 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
James Smarta257bf92009-04-06 18:48:10 -04003650 spin_lock_irqsave(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05003651 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
3652 if (pnode->cmd_qdepth >
3653 atomic_read(&pnode->cmd_pending) &&
3654 (atomic_read(&pnode->cmd_pending) >
3655 LPFC_MIN_TGT_QDEPTH) &&
3656 ((cmd->cmnd[0] == READ_10) ||
3657 (cmd->cmnd[0] == WRITE_10)))
3658 pnode->cmd_qdepth =
3659 atomic_read(&pnode->cmd_pending);
James Smart977b5a02008-09-07 11:52:04 -04003660
James Smart109f6ed2008-12-04 22:39:08 -05003661 pnode->last_change_time = jiffies;
3662 }
James Smarta257bf92009-04-06 18:48:10 -04003663 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05003664 } else if (pnode && NLP_CHK_NODE_ACT(pnode)) {
James Smart7dc517d2010-07-14 15:32:10 -04003665 if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) &&
James Smart977b5a02008-09-07 11:52:04 -04003666 time_after(jiffies, pnode->last_change_time +
James Smart109f6ed2008-12-04 22:39:08 -05003667 msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) {
James Smarta257bf92009-04-06 18:48:10 -04003668 spin_lock_irqsave(shost->host_lock, flags);
James Smart7dc517d2010-07-14 15:32:10 -04003669 depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT
3670 / 100;
3671 depth = depth ? depth : 1;
3672 pnode->cmd_qdepth += depth;
3673 if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth)
3674 pnode->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart109f6ed2008-12-04 22:39:08 -05003675 pnode->last_change_time = jiffies;
James Smarta257bf92009-04-06 18:48:10 -04003676 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05003677 }
James Smart977b5a02008-09-07 11:52:04 -04003678 }
3679
James Smart1dcb58e2007-04-25 09:51:30 -04003680 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
James Smarta257bf92009-04-06 18:48:10 -04003681
3682 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
3683 queue_depth = cmd->device->queue_depth;
3684 scsi_id = cmd->device->id;
dea31012005-04-17 16:05:31 -05003685 cmd->scsi_done(cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003686
Jamie Wellnitzb8086082006-02-28 22:33:12 -05003687 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smartfa61a542008-01-11 01:52:42 -05003688 /*
3689 * If there is a thread waiting for command completion
3690 * wake up the thread.
3691 */
James Smarta257bf92009-04-06 18:48:10 -04003692 spin_lock_irqsave(shost->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -04003693 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -05003694 if (lpfc_cmd->waitq)
3695 wake_up(lpfc_cmd->waitq);
James Smarta257bf92009-04-06 18:48:10 -04003696 spin_unlock_irqrestore(shost->host_lock, flags);
Jamie Wellnitzb8086082006-02-28 22:33:12 -05003697 lpfc_release_scsi_buf(phba, lpfc_cmd);
3698 return;
3699 }
3700
James Smart92d7f7b2007-06-17 19:56:38 -05003701 if (!result)
James Smarta257bf92009-04-06 18:48:10 -04003702 lpfc_rampup_queue_depth(vport, queue_depth);
James Smart92d7f7b2007-06-17 19:56:38 -05003703
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05003704 /*
3705 * Check for queue full. If the lun is reporting queue full, then
3706 * back off the lun queue depth to prevent target overloads.
3707 */
James Smart58da1ff2008-04-07 10:15:56 -04003708 if (result == SAM_STAT_TASK_SET_FULL && pnode &&
3709 NLP_CHK_NODE_ACT(pnode)) {
James Smarta257bf92009-04-06 18:48:10 -04003710 shost_for_each_device(tmp_sdev, shost) {
3711 if (tmp_sdev->id != scsi_id)
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05003712 continue;
3713 depth = scsi_track_queue_full(tmp_sdev,
James Smart5ffc2662009-11-18 15:39:44 -05003714 tmp_sdev->queue_depth-1);
3715 if (depth <= 0)
3716 continue;
James Smarte8b62012007-08-02 11:10:09 -04003717 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3718 "0711 detected queue full - lun queue "
3719 "depth adjusted to %d.\n", depth);
James Smartea2151b2008-09-07 11:52:10 -04003720 lpfc_send_sdev_queuedepth_change_event(phba, vport,
James Smart5ffc2662009-11-18 15:39:44 -05003721 pnode,
3722 tmp_sdev->lun,
3723 depth+1, depth);
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05003724 }
3725 }
3726
James Smartfa61a542008-01-11 01:52:42 -05003727 /*
3728 * If there is a thread waiting for command completion
3729 * wake up the thread.
3730 */
James Smarta257bf92009-04-06 18:48:10 -04003731 spin_lock_irqsave(shost->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -04003732 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -05003733 if (lpfc_cmd->waitq)
3734 wake_up(lpfc_cmd->waitq);
James Smarta257bf92009-04-06 18:48:10 -04003735 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartfa61a542008-01-11 01:52:42 -05003736
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003737 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05003738}
3739
James Smart34b02dc2008-08-24 21:49:55 -04003740/**
James Smart3621a712009-04-06 18:47:14 -04003741 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
James Smart34b02dc2008-08-24 21:49:55 -04003742 * @data: A pointer to the immediate command data portion of the IOCB.
3743 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
3744 *
3745 * The routine copies the entire FCP command from @fcp_cmnd to @data while
3746 * byte swapping the data to big endian format for transmission on the wire.
3747 **/
3748static void
3749lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
3750{
3751 int i, j;
3752 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
3753 i += sizeof(uint32_t), j++) {
3754 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
3755 }
3756}
3757
James Smart9bad7672008-12-04 22:39:02 -05003758/**
James Smartf1126682009-06-10 17:22:44 -04003759 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
James Smart9bad7672008-12-04 22:39:02 -05003760 * @vport: The virtual port for which this call is being executed.
3761 * @lpfc_cmd: The scsi command which needs to send.
3762 * @pnode: Pointer to lpfc_nodelist.
3763 *
3764 * This routine initializes fcp_cmnd and iocb data structure from scsi command
James Smart3772a992009-05-22 14:50:54 -04003765 * to transfer for device with SLI3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05003766 **/
dea31012005-04-17 16:05:31 -05003767static void
James Smartf1126682009-06-10 17:22:44 -04003768lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
James Smart2e0fef82007-06-17 19:56:36 -05003769 struct lpfc_nodelist *pnode)
dea31012005-04-17 16:05:31 -05003770{
James Smart2e0fef82007-06-17 19:56:36 -05003771 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003772 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3773 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3774 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3775 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
3776 int datadir = scsi_cmnd->sc_data_direction;
James Smart7e2b19f2007-10-29 11:00:39 -04003777 char tag[2];
dea31012005-04-17 16:05:31 -05003778
James Smart58da1ff2008-04-07 10:15:56 -04003779 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3780 return;
3781
dea31012005-04-17 16:05:31 -05003782 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
James.Smart@Emulex.Com69859dc2005-08-10 15:02:37 -04003783 /* clear task management bits */
3784 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
dea31012005-04-17 16:05:31 -05003785
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -04003786 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
3787 &lpfc_cmd->fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -05003788
James Smartdf9e1b52011-12-13 13:22:17 -05003789 memset(&fcp_cmnd->fcpCdb[0], 0, LPFC_FCP_CDB_LEN);
3790 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
James Smart7e2b19f2007-10-29 11:00:39 -04003791 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
3792 switch (tag[0]) {
dea31012005-04-17 16:05:31 -05003793 case HEAD_OF_QUEUE_TAG:
3794 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
3795 break;
3796 case ORDERED_QUEUE_TAG:
3797 fcp_cmnd->fcpCntl1 = ORDERED_Q;
3798 break;
3799 default:
3800 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
3801 break;
3802 }
3803 } else
3804 fcp_cmnd->fcpCntl1 = 0;
3805
3806 /*
3807 * There are three possibilities here - use scatter-gather segment, use
3808 * the single mapping, or neither. Start the lpfc command prep by
3809 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3810 * data bde entry.
3811 */
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05003812 if (scsi_sg_count(scsi_cmnd)) {
dea31012005-04-17 16:05:31 -05003813 if (datadir == DMA_TO_DEVICE) {
3814 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
James Smart3772a992009-05-22 14:50:54 -04003815 if (phba->sli_rev < LPFC_SLI_REV4) {
3816 iocb_cmd->un.fcpi.fcpi_parm = 0;
3817 iocb_cmd->ulpPU = 0;
3818 } else
3819 iocb_cmd->ulpPU = PARM_READ_CHECK;
dea31012005-04-17 16:05:31 -05003820 fcp_cmnd->fcpCntl3 = WRITE_DATA;
3821 phba->fc4OutputRequests++;
3822 } else {
3823 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
3824 iocb_cmd->ulpPU = PARM_READ_CHECK;
dea31012005-04-17 16:05:31 -05003825 fcp_cmnd->fcpCntl3 = READ_DATA;
3826 phba->fc4InputRequests++;
3827 }
3828 } else {
3829 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
3830 iocb_cmd->un.fcpi.fcpi_parm = 0;
3831 iocb_cmd->ulpPU = 0;
3832 fcp_cmnd->fcpCntl3 = 0;
3833 phba->fc4ControlRequests++;
3834 }
James Smarte2a0a9d2008-12-04 22:40:02 -05003835 if (phba->sli_rev == 3 &&
3836 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
James Smart34b02dc2008-08-24 21:49:55 -04003837 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -05003838 /*
3839 * Finish initializing those IOCB fields that are independent
3840 * of the scsi_cmnd request_buffer
3841 */
3842 piocbq->iocb.ulpContext = pnode->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -04003843 if (phba->sli_rev == LPFC_SLI_REV4)
3844 piocbq->iocb.ulpContext =
3845 phba->sli4_hba.rpi_ids[pnode->nlp_rpi];
dea31012005-04-17 16:05:31 -05003846 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
3847 piocbq->iocb.ulpFCP2Rcvy = 1;
James Smart09372822008-01-11 01:52:54 -05003848 else
3849 piocbq->iocb.ulpFCP2Rcvy = 0;
dea31012005-04-17 16:05:31 -05003850
3851 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
3852 piocbq->context1 = lpfc_cmd;
3853 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
3854 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003855 piocbq->vport = vport;
dea31012005-04-17 16:05:31 -05003856}
3857
James Smart9bad7672008-12-04 22:39:02 -05003858/**
James Smart6d368e52011-05-24 11:44:12 -04003859 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
James Smart9bad7672008-12-04 22:39:02 -05003860 * @vport: The virtual port for which this call is being executed.
3861 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3862 * @lun: Logical unit number.
3863 * @task_mgmt_cmd: SCSI task management command.
3864 *
James Smart3772a992009-05-22 14:50:54 -04003865 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
3866 * for device with SLI-3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05003867 *
3868 * Return codes:
3869 * 0 - Error
3870 * 1 - Success
3871 **/
dea31012005-04-17 16:05:31 -05003872static int
James Smartf1126682009-06-10 17:22:44 -04003873lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
dea31012005-04-17 16:05:31 -05003874 struct lpfc_scsi_buf *lpfc_cmd,
James Smart420b630d2006-07-06 15:50:16 -04003875 unsigned int lun,
dea31012005-04-17 16:05:31 -05003876 uint8_t task_mgmt_cmd)
3877{
dea31012005-04-17 16:05:31 -05003878 struct lpfc_iocbq *piocbq;
3879 IOCB_t *piocb;
3880 struct fcp_cmnd *fcp_cmnd;
James Smart0b18ac42006-05-01 21:50:40 -04003881 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
dea31012005-04-17 16:05:31 -05003882 struct lpfc_nodelist *ndlp = rdata->pnode;
3883
James Smart58da1ff2008-04-07 10:15:56 -04003884 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
3885 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
dea31012005-04-17 16:05:31 -05003886 return 0;
dea31012005-04-17 16:05:31 -05003887
dea31012005-04-17 16:05:31 -05003888 piocbq = &(lpfc_cmd->cur_iocbq);
James Smart2e0fef82007-06-17 19:56:36 -05003889 piocbq->vport = vport;
3890
dea31012005-04-17 16:05:31 -05003891 piocb = &piocbq->iocb;
3892
3893 fcp_cmnd = lpfc_cmd->fcp_cmnd;
James Smart34b02dc2008-08-24 21:49:55 -04003894 /* Clear out any old data in the FCP command area */
3895 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
3896 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -05003897 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
James Smarte2a0a9d2008-12-04 22:40:02 -05003898 if (vport->phba->sli_rev == 3 &&
3899 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
James Smart34b02dc2008-08-24 21:49:55 -04003900 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -05003901 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
dea31012005-04-17 16:05:31 -05003902 piocb->ulpContext = ndlp->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -04003903 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
3904 piocb->ulpContext =
3905 vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
3906 }
dea31012005-04-17 16:05:31 -05003907 if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
3908 piocb->ulpFCP2Rcvy = 1;
3909 }
3910 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
3911
3912 /* ulpTimeout is only one byte */
3913 if (lpfc_cmd->timeout > 0xff) {
3914 /*
3915 * Do not timeout the command at the firmware level.
3916 * The driver will provide the timeout mechanism.
3917 */
3918 piocb->ulpTimeout = 0;
James Smartf1126682009-06-10 17:22:44 -04003919 } else
dea31012005-04-17 16:05:31 -05003920 piocb->ulpTimeout = lpfc_cmd->timeout;
James Smartf1126682009-06-10 17:22:44 -04003921
3922 if (vport->phba->sli_rev == LPFC_SLI_REV4)
3923 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05003924
James Smart2e0fef82007-06-17 19:56:36 -05003925 return 1;
dea31012005-04-17 16:05:31 -05003926}
3927
James Smart9bad7672008-12-04 22:39:02 -05003928/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003929 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
James Smart3772a992009-05-22 14:50:54 -04003930 * @phba: The hba struct for which this call is being executed.
3931 * @dev_grp: The HBA PCI-Device group number.
3932 *
3933 * This routine sets up the SCSI interface API function jump table in @phba
3934 * struct.
3935 * Returns: 0 - success, -ENODEV - failure.
3936 **/
3937int
3938lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
3939{
3940
James Smartf1126682009-06-10 17:22:44 -04003941 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
3942 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
James Smartf1126682009-06-10 17:22:44 -04003943
James Smart3772a992009-05-22 14:50:54 -04003944 switch (dev_grp) {
3945 case LPFC_PCI_DEV_LP:
3946 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
3947 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
James Smartacd68592012-01-18 16:25:09 -05003948 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3;
James Smart3772a992009-05-22 14:50:54 -04003949 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
James Smart19ca7602010-11-20 23:11:55 -05003950 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
James Smart3772a992009-05-22 14:50:54 -04003951 break;
James Smartda0436e2009-05-22 14:51:39 -04003952 case LPFC_PCI_DEV_OC:
3953 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
3954 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
James Smartacd68592012-01-18 16:25:09 -05003955 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4;
James Smartda0436e2009-05-22 14:51:39 -04003956 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
James Smart19ca7602010-11-20 23:11:55 -05003957 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
James Smartda0436e2009-05-22 14:51:39 -04003958 break;
James Smart3772a992009-05-22 14:50:54 -04003959 default:
3960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3961 "1418 Invalid HBA PCI-device group: 0x%x\n",
3962 dev_grp);
3963 return -ENODEV;
3964 break;
3965 }
James Smart3772a992009-05-22 14:50:54 -04003966 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
James Smart84d1b002010-02-12 14:42:33 -05003967 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
James Smart3772a992009-05-22 14:50:54 -04003968 return 0;
3969}
3970
3971/**
James Smart3621a712009-04-06 18:47:14 -04003972 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
James Smart9bad7672008-12-04 22:39:02 -05003973 * @phba: The Hba for which this call is being executed.
3974 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
3975 * @rspiocbq: Pointer to lpfc_iocbq data structure.
3976 *
3977 * This routine is IOCB completion routine for device reset and target reset
3978 * routine. This routine release scsi buffer associated with lpfc_cmd.
3979 **/
James Smart7054a602007-04-25 09:52:34 -04003980static void
3981lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
3982 struct lpfc_iocbq *cmdiocbq,
3983 struct lpfc_iocbq *rspiocbq)
3984{
3985 struct lpfc_scsi_buf *lpfc_cmd =
3986 (struct lpfc_scsi_buf *) cmdiocbq->context1;
3987 if (lpfc_cmd)
3988 lpfc_release_scsi_buf(phba, lpfc_cmd);
3989 return;
3990}
3991
James Smart9bad7672008-12-04 22:39:02 -05003992/**
James Smart3621a712009-04-06 18:47:14 -04003993 * lpfc_info - Info entry point of scsi_host_template data structure
James Smart9bad7672008-12-04 22:39:02 -05003994 * @host: The scsi host for which this call is being executed.
3995 *
3996 * This routine provides module information about hba.
3997 *
3998 * Reutrn code:
3999 * Pointer to char - Success.
4000 **/
dea31012005-04-17 16:05:31 -05004001const char *
4002lpfc_info(struct Scsi_Host *host)
4003{
James Smart2e0fef82007-06-17 19:56:36 -05004004 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
4005 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004006 int len;
4007 static char lpfcinfobuf[384];
4008
4009 memset(lpfcinfobuf,0,384);
4010 if (phba && phba->pcidev){
4011 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
4012 len = strlen(lpfcinfobuf);
4013 snprintf(lpfcinfobuf + len,
4014 384-len,
4015 " on PCI bus %02x device %02x irq %d",
4016 phba->pcidev->bus->number,
4017 phba->pcidev->devfn,
4018 phba->pcidev->irq);
4019 len = strlen(lpfcinfobuf);
4020 if (phba->Port[0]) {
4021 snprintf(lpfcinfobuf + len,
4022 384-len,
4023 " port %s",
4024 phba->Port);
4025 }
James Smart65467b62010-01-26 23:08:29 -05004026 len = strlen(lpfcinfobuf);
4027 if (phba->sli4_hba.link_state.logical_speed) {
4028 snprintf(lpfcinfobuf + len,
4029 384-len,
4030 " Logical Link Speed: %d Mbps",
4031 phba->sli4_hba.link_state.logical_speed * 10);
4032 }
dea31012005-04-17 16:05:31 -05004033 }
4034 return lpfcinfobuf;
4035}
4036
James Smart9bad7672008-12-04 22:39:02 -05004037/**
James Smart3621a712009-04-06 18:47:14 -04004038 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
James Smart9bad7672008-12-04 22:39:02 -05004039 * @phba: The Hba for which this call is being executed.
4040 *
4041 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4042 * The default value of cfg_poll_tmo is 10 milliseconds.
4043 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004044static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
4045{
4046 unsigned long poll_tmo_expires =
4047 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
4048
4049 if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
4050 mod_timer(&phba->fcp_poll_timer,
4051 poll_tmo_expires);
4052}
4053
James Smart9bad7672008-12-04 22:39:02 -05004054/**
James Smart3621a712009-04-06 18:47:14 -04004055 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
James Smart9bad7672008-12-04 22:39:02 -05004056 * @phba: The Hba for which this call is being executed.
4057 *
4058 * This routine starts the fcp_poll_timer of @phba.
4059 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004060void lpfc_poll_start_timer(struct lpfc_hba * phba)
4061{
4062 lpfc_poll_rearm_timer(phba);
4063}
4064
James Smart9bad7672008-12-04 22:39:02 -05004065/**
James Smart3621a712009-04-06 18:47:14 -04004066 * lpfc_poll_timeout - Restart polling timer
James Smart9bad7672008-12-04 22:39:02 -05004067 * @ptr: Map to lpfc_hba data structure pointer.
4068 *
4069 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4070 * and FCP Ring interrupt is disable.
4071 **/
4072
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004073void lpfc_poll_timeout(unsigned long ptr)
4074{
James Smart2e0fef82007-06-17 19:56:36 -05004075 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004076
4077 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04004078 lpfc_sli_handle_fast_ring_event(phba,
4079 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4080
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004081 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4082 lpfc_poll_rearm_timer(phba);
4083 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004084}
4085
James Smart9bad7672008-12-04 22:39:02 -05004086/**
James Smart3621a712009-04-06 18:47:14 -04004087 * lpfc_queuecommand - scsi_host_template queuecommand entry point
James Smart9bad7672008-12-04 22:39:02 -05004088 * @cmnd: Pointer to scsi_cmnd data structure.
4089 * @done: Pointer to done routine.
4090 *
4091 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4092 * This routine prepares an IOCB from scsi command and provides to firmware.
4093 * The @done callback is invoked after driver finished processing the command.
4094 *
4095 * Return value :
4096 * 0 - Success
4097 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4098 **/
dea31012005-04-17 16:05:31 -05004099static int
Jeff Garzikf2812332010-11-16 02:10:29 -05004100lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
dea31012005-04-17 16:05:31 -05004101{
James Smart2e0fef82007-06-17 19:56:36 -05004102 struct Scsi_Host *shost = cmnd->device->host;
4103 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4104 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004105 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05004106 struct lpfc_nodelist *ndlp;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004107 struct lpfc_scsi_buf *lpfc_cmd;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004108 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004109 int err;
dea31012005-04-17 16:05:31 -05004110
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004111 err = fc_remote_port_chkready(rport);
4112 if (err) {
4113 cmnd->result = err;
dea31012005-04-17 16:05:31 -05004114 goto out_fail_command;
4115 }
James Smartdf9e1b52011-12-13 13:22:17 -05004116 /*
4117 * Do not let the mid-layer retry I/O too fast. If an I/O is retried
4118 * without waiting a bit then indicate that the device is busy.
4119 */
4120 if (cmnd->retries &&
4121 time_before(jiffies, (cmnd->jiffies_at_alloc +
4122 msecs_to_jiffies(LPFC_RETRY_PAUSE *
4123 cmnd->retries))))
4124 return SCSI_MLQUEUE_DEVICE_BUSY;
James Smart1c6f4ef52009-11-18 15:40:49 -05004125 ndlp = rdata->pnode;
dea31012005-04-17 16:05:31 -05004126
James Smartbf086112011-08-21 21:48:13 -04004127 if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
James Smartacd68592012-01-18 16:25:09 -05004128 (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) {
James Smarte2a0a9d2008-12-04 22:40:02 -05004129
James Smart6a9c52c2009-10-02 15:16:51 -04004130 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
4131 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4132 " op:%02x str=%s without registering for"
4133 " BlockGuard - Rejecting command\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05004134 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
4135 dif_op_str[scsi_get_prot_op(cmnd)]);
4136 goto out_fail_command;
4137 }
4138
dea31012005-04-17 16:05:31 -05004139 /*
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004140 * Catch race where our node has transitioned, but the
4141 * transport is still transitioning.
dea31012005-04-17 16:05:31 -05004142 */
James Smartb522d7d2008-09-07 11:51:56 -04004143 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
Mike Christief55ca84d2011-02-25 14:04:27 -06004144 cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
James Smartb522d7d2008-09-07 11:51:56 -04004145 goto out_fail_command;
4146 }
James Smart7dc517d2010-07-14 15:32:10 -04004147 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)
Mike Christie34963432011-02-25 14:04:28 -06004148 goto out_tgt_busy;
Mike Christiea93ce022008-08-17 15:24:41 -05004149
James Smart19ca7602010-11-20 23:11:55 -05004150 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp);
dea31012005-04-17 16:05:31 -05004151 if (lpfc_cmd == NULL) {
James Smarteaf15d52008-12-04 22:39:29 -05004152 lpfc_rampdown_queue_depth(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05004153
James Smarte8b62012007-08-02 11:10:09 -04004154 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4155 "0707 driver's buffer pool is empty, "
4156 "IO busied\n");
dea31012005-04-17 16:05:31 -05004157 goto out_host_busy;
4158 }
4159
4160 /*
4161 * Store the midlayer's command structure for the completion phase
4162 * and complete the command initialization.
4163 */
4164 lpfc_cmd->pCmd = cmnd;
4165 lpfc_cmd->rdata = rdata;
4166 lpfc_cmd->timeout = 0;
James Smart977b5a02008-09-07 11:52:04 -04004167 lpfc_cmd->start_time = jiffies;
dea31012005-04-17 16:05:31 -05004168 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
4169 cmnd->scsi_done = done;
4170
James Smarte2a0a9d2008-12-04 22:40:02 -05004171 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
James Smart6a9c52c2009-10-02 15:16:51 -04004172 if (vport->phba->cfg_enable_bg) {
4173 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smart9a6b09c2012-03-01 22:37:42 -05004174 "9033 BLKGRD: rcvd protected cmd:%02x op=%s "
4175 "guard=%s\n", cmnd->cmnd[0],
4176 dif_op_str[scsi_get_prot_op(cmnd)],
4177 dif_grd_str[scsi_host_get_guard(shost)]);
James Smart6a9c52c2009-10-02 15:16:51 -04004178 if (cmnd->cmnd[0] == READ_10)
4179 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05004180 "9035 BLKGRD: READ @ sector %llu, "
James Smart9a6b09c2012-03-01 22:37:42 -05004181 "cnt %u, rpt %d\n",
Tejun Heo83096eb2009-05-07 22:24:39 +09004182 (unsigned long long)scsi_get_lba(cmnd),
James Smart9a6b09c2012-03-01 22:37:42 -05004183 blk_rq_sectors(cmnd->request),
4184 (cmnd->cmnd[1]>>5));
James Smart6a9c52c2009-10-02 15:16:51 -04004185 else if (cmnd->cmnd[0] == WRITE_10)
4186 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05004187 "9036 BLKGRD: WRITE @ sector %llu, "
James Smart9a6b09c2012-03-01 22:37:42 -05004188 "cnt %u, wpt %d\n",
James Smart87b5c322008-12-16 10:34:09 -05004189 (unsigned long long)scsi_get_lba(cmnd),
Tejun Heo83096eb2009-05-07 22:24:39 +09004190 blk_rq_sectors(cmnd->request),
James Smart9a6b09c2012-03-01 22:37:42 -05004191 (cmnd->cmnd[1]>>5));
James Smart6a9c52c2009-10-02 15:16:51 -04004192 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004193
4194 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
4195 } else {
James Smart6a9c52c2009-10-02 15:16:51 -04004196 if (vport->phba->cfg_enable_bg) {
James Smarte2a0a9d2008-12-04 22:40:02 -05004197 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smart9a6b09c2012-03-01 22:37:42 -05004198 "9038 BLKGRD: rcvd unprotected cmd:"
4199 "%02x op=%s guard=%s\n", cmnd->cmnd[0],
4200 dif_op_str[scsi_get_prot_op(cmnd)],
4201 dif_grd_str[scsi_host_get_guard(shost)]);
James Smart6a9c52c2009-10-02 15:16:51 -04004202 if (cmnd->cmnd[0] == READ_10)
4203 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4204 "9040 dbg: READ @ sector %llu, "
James Smart9a6b09c2012-03-01 22:37:42 -05004205 "cnt %u, rpt %d\n",
James Smart6a9c52c2009-10-02 15:16:51 -04004206 (unsigned long long)scsi_get_lba(cmnd),
James Smart9a6b09c2012-03-01 22:37:42 -05004207 blk_rq_sectors(cmnd->request),
4208 (cmnd->cmnd[1]>>5));
James Smart6a9c52c2009-10-02 15:16:51 -04004209 else if (cmnd->cmnd[0] == WRITE_10)
4210 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smart9a6b09c2012-03-01 22:37:42 -05004211 "9041 dbg: WRITE @ sector %llu, "
4212 "cnt %u, wpt %d\n",
4213 (unsigned long long)scsi_get_lba(cmnd),
4214 blk_rq_sectors(cmnd->request),
4215 (cmnd->cmnd[1]>>5));
James Smart6a9c52c2009-10-02 15:16:51 -04004216 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004217 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
4218 }
4219
dea31012005-04-17 16:05:31 -05004220 if (err)
4221 goto out_host_busy_free_buf;
4222
James Smart2e0fef82007-06-17 19:56:36 -05004223 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
dea31012005-04-17 16:05:31 -05004224
James Smart977b5a02008-09-07 11:52:04 -04004225 atomic_inc(&ndlp->cmd_pending);
James Smart3772a992009-05-22 14:50:54 -04004226 err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
James Smart92d7f7b2007-06-17 19:56:38 -05004227 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
James Smarteaf15d52008-12-04 22:39:29 -05004228 if (err) {
4229 atomic_dec(&ndlp->cmd_pending);
dea31012005-04-17 16:05:31 -05004230 goto out_host_busy_free_buf;
James Smarteaf15d52008-12-04 22:39:29 -05004231 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004232 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04004233 spin_unlock(shost->host_lock);
4234 lpfc_sli_handle_fast_ring_event(phba,
4235 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4236
4237 spin_lock(shost->host_lock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004238 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4239 lpfc_poll_rearm_timer(phba);
4240 }
4241
dea31012005-04-17 16:05:31 -05004242 return 0;
4243
4244 out_host_busy_free_buf:
James Smartbcf4dbf2006-07-06 15:50:08 -04004245 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004246 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05004247 out_host_busy:
4248 return SCSI_MLQUEUE_HOST_BUSY;
4249
Mike Christie34963432011-02-25 14:04:28 -06004250 out_tgt_busy:
4251 return SCSI_MLQUEUE_TARGET_BUSY;
4252
dea31012005-04-17 16:05:31 -05004253 out_fail_command:
4254 done(cmnd);
4255 return 0;
4256}
4257
Jeff Garzikf2812332010-11-16 02:10:29 -05004258static DEF_SCSI_QCMD(lpfc_queuecommand)
4259
James Smart9bad7672008-12-04 22:39:02 -05004260/**
James Smart3621a712009-04-06 18:47:14 -04004261 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
James Smart9bad7672008-12-04 22:39:02 -05004262 * @cmnd: Pointer to scsi_cmnd data structure.
4263 *
4264 * This routine aborts @cmnd pending in base driver.
4265 *
4266 * Return code :
4267 * 0x2003 - Error
4268 * 0x2002 - Success
4269 **/
dea31012005-04-17 16:05:31 -05004270static int
James.Smart@Emulex.Com63c59c32005-11-28 11:41:53 -05004271lpfc_abort_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05004272{
James Smart2e0fef82007-06-17 19:56:36 -05004273 struct Scsi_Host *shost = cmnd->device->host;
4274 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4275 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004276 struct lpfc_iocbq *iocb;
4277 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05004278 struct lpfc_scsi_buf *lpfc_cmd;
dea31012005-04-17 16:05:31 -05004279 IOCB_t *cmd, *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004280 int ret = SUCCESS;
James Smartfa61a542008-01-11 01:52:42 -05004281 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004282
James Smart589a52d2010-07-14 15:30:54 -04004283 ret = fc_block_scsi_eh(cmnd);
4284 if (ret)
4285 return ret;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004286 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
James Smarteee88772010-09-29 11:19:08 -04004287 if (!lpfc_cmd) {
4288 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4289 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04004290 "x%x ID %d LUN %d\n",
4291 ret, cmnd->device->id, cmnd->device->lun);
James Smarteee88772010-09-29 11:19:08 -04004292 return SUCCESS;
4293 }
dea31012005-04-17 16:05:31 -05004294
4295 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004296 * If pCmd field of the corresponding lpfc_scsi_buf structure
4297 * points to a different SCSI command, then the driver has
4298 * already completed this command, but the midlayer did not
4299 * see the completion before the eh fired. Just return
4300 * SUCCESS.
dea31012005-04-17 16:05:31 -05004301 */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004302 iocb = &lpfc_cmd->cur_iocbq;
4303 if (lpfc_cmd->pCmd != cmnd)
4304 goto out;
dea31012005-04-17 16:05:31 -05004305
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004306 BUG_ON(iocb->context1 != lpfc_cmd);
dea31012005-04-17 16:05:31 -05004307
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004308 abtsiocb = lpfc_sli_get_iocbq(phba);
4309 if (abtsiocb == NULL) {
4310 ret = FAILED;
dea31012005-04-17 16:05:31 -05004311 goto out;
4312 }
4313
dea31012005-04-17 16:05:31 -05004314 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004315 * The scsi command can not be in txq and it is in flight because the
4316 * pCmd is still pointig at the SCSI command we have to abort. There
4317 * is no need to search the txcmplq. Just send an abort to the FW.
dea31012005-04-17 16:05:31 -05004318 */
dea31012005-04-17 16:05:31 -05004319
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004320 cmd = &iocb->iocb;
4321 icmd = &abtsiocb->iocb;
4322 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
4323 icmd->un.acxri.abortContextTag = cmd->ulpContext;
James Smart3772a992009-05-22 14:50:54 -04004324 if (phba->sli_rev == LPFC_SLI_REV4)
4325 icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
4326 else
4327 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05004328
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004329 icmd->ulpLe = 1;
4330 icmd->ulpClass = cmd->ulpClass;
James Smart5ffc2662009-11-18 15:39:44 -05004331
4332 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4333 abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
James Smart341af102010-01-26 23:07:37 -05004334 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
James Smart5ffc2662009-11-18 15:39:44 -05004335
James Smart2e0fef82007-06-17 19:56:36 -05004336 if (lpfc_is_link_up(phba))
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004337 icmd->ulpCommand = CMD_ABORT_XRI_CN;
4338 else
4339 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
dea31012005-04-17 16:05:31 -05004340
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004341 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
James Smart2e0fef82007-06-17 19:56:36 -05004342 abtsiocb->vport = vport;
James Smart3772a992009-05-22 14:50:54 -04004343 if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) ==
4344 IOCB_ERROR) {
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004345 lpfc_sli_release_iocbq(phba, abtsiocb);
4346 ret = FAILED;
4347 goto out;
4348 }
4349
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004350 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
James Smart45ed1192009-10-02 15:17:02 -04004351 lpfc_sli_handle_fast_ring_event(phba,
4352 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004353
James Smartfa61a542008-01-11 01:52:42 -05004354 lpfc_cmd->waitq = &waitq;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004355 /* Wait for abort to complete */
James Smartfa61a542008-01-11 01:52:42 -05004356 wait_event_timeout(waitq,
4357 (lpfc_cmd->pCmd != cmnd),
4358 (2*vport->cfg_devloss_tmo*HZ));
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004359
James Smartfa61a542008-01-11 01:52:42 -05004360 spin_lock_irq(shost->host_lock);
4361 lpfc_cmd->waitq = NULL;
4362 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004363
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004364 if (lpfc_cmd->pCmd == cmnd) {
4365 ret = FAILED;
James Smarte8b62012007-08-02 11:10:09 -04004366 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4367 "0748 abort handler timed out waiting "
4368 "for abort to complete: ret %#x, ID %d, "
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04004369 "LUN %d\n",
4370 ret, cmnd->device->id, cmnd->device->lun);
dea31012005-04-17 16:05:31 -05004371 }
4372
4373 out:
James Smarte8b62012007-08-02 11:10:09 -04004374 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4375 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04004376 "LUN %d\n", ret, cmnd->device->id,
4377 cmnd->device->lun);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04004378 return ret;
dea31012005-04-17 16:05:31 -05004379}
4380
James Smartbbb9d182009-06-10 17:23:16 -04004381static char *
4382lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
4383{
4384 switch (task_mgmt_cmd) {
4385 case FCP_ABORT_TASK_SET:
4386 return "ABORT_TASK_SET";
4387 case FCP_CLEAR_TASK_SET:
4388 return "FCP_CLEAR_TASK_SET";
4389 case FCP_BUS_RESET:
4390 return "FCP_BUS_RESET";
4391 case FCP_LUN_RESET:
4392 return "FCP_LUN_RESET";
4393 case FCP_TARGET_RESET:
4394 return "FCP_TARGET_RESET";
4395 case FCP_CLEAR_ACA:
4396 return "FCP_CLEAR_ACA";
4397 case FCP_TERMINATE_TASK:
4398 return "FCP_TERMINATE_TASK";
4399 default:
4400 return "unknown";
4401 }
4402}
4403
4404/**
4405 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4406 * @vport: The virtual port for which this call is being executed.
4407 * @rdata: Pointer to remote port local data
4408 * @tgt_id: Target ID of remote device.
4409 * @lun_id: Lun number for the TMF
4410 * @task_mgmt_cmd: type of TMF to send
4411 *
4412 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4413 * a remote port.
4414 *
4415 * Return Code:
4416 * 0x2003 - Error
4417 * 0x2002 - Success.
4418 **/
4419static int
4420lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
4421 unsigned tgt_id, unsigned int lun_id,
4422 uint8_t task_mgmt_cmd)
4423{
4424 struct lpfc_hba *phba = vport->phba;
4425 struct lpfc_scsi_buf *lpfc_cmd;
4426 struct lpfc_iocbq *iocbq;
4427 struct lpfc_iocbq *iocbqrsp;
James Smart5989b8d2010-10-22 11:06:56 -04004428 struct lpfc_nodelist *pnode = rdata->pnode;
James Smartbbb9d182009-06-10 17:23:16 -04004429 int ret;
4430 int status;
4431
James Smart5989b8d2010-10-22 11:06:56 -04004432 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
James Smartbbb9d182009-06-10 17:23:16 -04004433 return FAILED;
4434
James Smart19ca7602010-11-20 23:11:55 -05004435 lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode);
James Smartbbb9d182009-06-10 17:23:16 -04004436 if (lpfc_cmd == NULL)
4437 return FAILED;
4438 lpfc_cmd->timeout = 60;
4439 lpfc_cmd->rdata = rdata;
4440
4441 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
4442 task_mgmt_cmd);
4443 if (!status) {
4444 lpfc_release_scsi_buf(phba, lpfc_cmd);
4445 return FAILED;
4446 }
4447
4448 iocbq = &lpfc_cmd->cur_iocbq;
4449 iocbqrsp = lpfc_sli_get_iocbq(phba);
4450 if (iocbqrsp == NULL) {
4451 lpfc_release_scsi_buf(phba, lpfc_cmd);
4452 return FAILED;
4453 }
4454
4455 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4456 "0702 Issue %s to TGT %d LUN %d "
James Smart6d368e52011-05-24 11:44:12 -04004457 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
James Smartbbb9d182009-06-10 17:23:16 -04004458 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
James Smart6d368e52011-05-24 11:44:12 -04004459 pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
4460 iocbq->iocb_flag);
James Smartbbb9d182009-06-10 17:23:16 -04004461
4462 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
4463 iocbq, iocbqrsp, lpfc_cmd->timeout);
4464 if (status != IOCB_SUCCESS) {
4465 if (status == IOCB_TIMEDOUT) {
4466 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
4467 ret = TIMEOUT_ERROR;
4468 } else
4469 ret = FAILED;
4470 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
4471 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
James Smart6d368e52011-05-24 11:44:12 -04004472 "0727 TMF %s to TGT %d LUN %d failed (%d, %d) "
4473 "iocb_flag x%x\n",
James Smartbbb9d182009-06-10 17:23:16 -04004474 lpfc_taskmgmt_name(task_mgmt_cmd),
4475 tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
James Smart6d368e52011-05-24 11:44:12 -04004476 iocbqrsp->iocb.un.ulpWord[4],
4477 iocbq->iocb_flag);
James Smart2a9bf3d2010-06-07 15:24:45 -04004478 } else if (status == IOCB_BUSY)
4479 ret = FAILED;
4480 else
James Smartbbb9d182009-06-10 17:23:16 -04004481 ret = SUCCESS;
4482
4483 lpfc_sli_release_iocbq(phba, iocbqrsp);
4484
4485 if (ret != TIMEOUT_ERROR)
4486 lpfc_release_scsi_buf(phba, lpfc_cmd);
4487
4488 return ret;
4489}
4490
4491/**
4492 * lpfc_chk_tgt_mapped -
4493 * @vport: The virtual port to check on
4494 * @cmnd: Pointer to scsi_cmnd data structure.
4495 *
4496 * This routine delays until the scsi target (aka rport) for the
4497 * command exists (is present and logged in) or we declare it non-existent.
4498 *
4499 * Return code :
4500 * 0x2003 - Error
4501 * 0x2002 - Success
4502 **/
4503static int
4504lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
4505{
4506 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05004507 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04004508 unsigned long later;
4509
James Smart1c6f4ef52009-11-18 15:40:49 -05004510 if (!rdata) {
4511 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4512 "0797 Tgt Map rport failure: rdata x%p\n", rdata);
4513 return FAILED;
4514 }
4515 pnode = rdata->pnode;
James Smartbbb9d182009-06-10 17:23:16 -04004516 /*
4517 * If target is not in a MAPPED state, delay until
4518 * target is rediscovered or devloss timeout expires.
4519 */
4520 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
4521 while (time_after(later, jiffies)) {
4522 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
4523 return FAILED;
4524 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
4525 return SUCCESS;
4526 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
4527 rdata = cmnd->device->hostdata;
4528 if (!rdata)
4529 return FAILED;
4530 pnode = rdata->pnode;
4531 }
4532 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
4533 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
4534 return FAILED;
4535 return SUCCESS;
4536}
4537
4538/**
4539 * lpfc_reset_flush_io_context -
4540 * @vport: The virtual port (scsi_host) for the flush context
4541 * @tgt_id: If aborting by Target contect - specifies the target id
4542 * @lun_id: If aborting by Lun context - specifies the lun id
4543 * @context: specifies the context level to flush at.
4544 *
4545 * After a reset condition via TMF, we need to flush orphaned i/o
4546 * contexts from the adapter. This routine aborts any contexts
4547 * outstanding, then waits for their completions. The wait is
4548 * bounded by devloss_tmo though.
4549 *
4550 * Return code :
4551 * 0x2003 - Error
4552 * 0x2002 - Success
4553 **/
4554static int
4555lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
4556 uint64_t lun_id, lpfc_ctx_cmd context)
4557{
4558 struct lpfc_hba *phba = vport->phba;
4559 unsigned long later;
4560 int cnt;
4561
4562 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
4563 if (cnt)
4564 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
4565 tgt_id, lun_id, context);
4566 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
4567 while (time_after(later, jiffies) && cnt) {
4568 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
4569 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
4570 }
4571 if (cnt) {
4572 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4573 "0724 I/O flush failure for context %s : cnt x%x\n",
4574 ((context == LPFC_CTX_LUN) ? "LUN" :
4575 ((context == LPFC_CTX_TGT) ? "TGT" :
4576 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
4577 cnt);
4578 return FAILED;
4579 }
4580 return SUCCESS;
4581}
4582
James Smart9bad7672008-12-04 22:39:02 -05004583/**
James Smart3621a712009-04-06 18:47:14 -04004584 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
James Smart9bad7672008-12-04 22:39:02 -05004585 * @cmnd: Pointer to scsi_cmnd data structure.
4586 *
James Smartbbb9d182009-06-10 17:23:16 -04004587 * This routine does a device reset by sending a LUN_RESET task management
James Smart9bad7672008-12-04 22:39:02 -05004588 * command.
4589 *
4590 * Return code :
4591 * 0x2003 - Error
James Smart3621a712009-04-06 18:47:14 -04004592 * 0x2002 - Success
James Smart9bad7672008-12-04 22:39:02 -05004593 **/
dea31012005-04-17 16:05:31 -05004594static int
James Smart7054a602007-04-25 09:52:34 -04004595lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05004596{
James Smart2e0fef82007-06-17 19:56:36 -05004597 struct Scsi_Host *shost = cmnd->device->host;
4598 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
dea31012005-04-17 16:05:31 -05004599 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05004600 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04004601 unsigned tgt_id = cmnd->device->id;
4602 unsigned int lun_id = cmnd->device->lun;
James Smartea2151b2008-09-07 11:52:10 -04004603 struct lpfc_scsi_event_header scsi_event;
James Smartbbb9d182009-06-10 17:23:16 -04004604 int status;
dea31012005-04-17 16:05:31 -05004605
James Smart1c6f4ef52009-11-18 15:40:49 -05004606 if (!rdata) {
4607 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4608 "0798 Device Reset rport failure: rdata x%p\n", rdata);
4609 return FAILED;
4610 }
4611 pnode = rdata->pnode;
James Smart589a52d2010-07-14 15:30:54 -04004612 status = fc_block_scsi_eh(cmnd);
4613 if (status)
4614 return status;
James Smartbbb9d182009-06-10 17:23:16 -04004615
4616 status = lpfc_chk_tgt_mapped(vport, cmnd);
4617 if (status == FAILED) {
4618 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4619 "0721 Device Reset rport failure: rdata x%p\n", rdata);
4620 return FAILED;
4621 }
4622
4623 scsi_event.event_type = FC_REG_SCSI_EVENT;
4624 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
4625 scsi_event.lun = lun_id;
4626 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
4627 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
4628
4629 fc_host_post_vendor_event(shost, fc_get_event_number(),
4630 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
4631
4632 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
4633 FCP_LUN_RESET);
4634
4635 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4636 "0713 SCSI layer issued Device Reset (%d, %d) "
4637 "return x%x\n", tgt_id, lun_id, status);
4638
dea31012005-04-17 16:05:31 -05004639 /*
James Smartbbb9d182009-06-10 17:23:16 -04004640 * We have to clean up i/o as : they may be orphaned by the TMF;
4641 * or if the TMF failed, they may be in an indeterminate state.
4642 * So, continue on.
4643 * We will report success if all the i/o aborts successfully.
dea31012005-04-17 16:05:31 -05004644 */
James Smartbbb9d182009-06-10 17:23:16 -04004645 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
4646 LPFC_CTX_LUN);
4647 return status;
4648}
4649
4650/**
4651 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
4652 * @cmnd: Pointer to scsi_cmnd data structure.
4653 *
4654 * This routine does a target reset by sending a TARGET_RESET task management
4655 * command.
4656 *
4657 * Return code :
4658 * 0x2003 - Error
4659 * 0x2002 - Success
4660 **/
4661static int
4662lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
4663{
4664 struct Scsi_Host *shost = cmnd->device->host;
4665 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4666 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05004667 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04004668 unsigned tgt_id = cmnd->device->id;
4669 unsigned int lun_id = cmnd->device->lun;
4670 struct lpfc_scsi_event_header scsi_event;
4671 int status;
4672
James Smart1c6f4ef52009-11-18 15:40:49 -05004673 if (!rdata) {
4674 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4675 "0799 Target Reset rport failure: rdata x%p\n", rdata);
4676 return FAILED;
4677 }
4678 pnode = rdata->pnode;
James Smart589a52d2010-07-14 15:30:54 -04004679 status = fc_block_scsi_eh(cmnd);
4680 if (status)
4681 return status;
James Smartbbb9d182009-06-10 17:23:16 -04004682
4683 status = lpfc_chk_tgt_mapped(vport, cmnd);
4684 if (status == FAILED) {
4685 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4686 "0722 Target Reset rport failure: rdata x%p\n", rdata);
4687 return FAILED;
dea31012005-04-17 16:05:31 -05004688 }
James Smartea2151b2008-09-07 11:52:10 -04004689
4690 scsi_event.event_type = FC_REG_SCSI_EVENT;
4691 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
4692 scsi_event.lun = 0;
4693 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
4694 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
4695
James Smartbbb9d182009-06-10 17:23:16 -04004696 fc_host_post_vendor_event(shost, fc_get_event_number(),
4697 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04004698
James Smartbbb9d182009-06-10 17:23:16 -04004699 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
4700 FCP_TARGET_RESET);
dea31012005-04-17 16:05:31 -05004701
James Smarte8b62012007-08-02 11:10:09 -04004702 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
James Smartbbb9d182009-06-10 17:23:16 -04004703 "0723 SCSI layer issued Target Reset (%d, %d) "
4704 "return x%x\n", tgt_id, lun_id, status);
4705
4706 /*
4707 * We have to clean up i/o as : they may be orphaned by the TMF;
4708 * or if the TMF failed, they may be in an indeterminate state.
4709 * So, continue on.
4710 * We will report success if all the i/o aborts successfully.
4711 */
4712 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
4713 LPFC_CTX_TGT);
4714 return status;
dea31012005-04-17 16:05:31 -05004715}
4716
James Smart9bad7672008-12-04 22:39:02 -05004717/**
James Smart3621a712009-04-06 18:47:14 -04004718 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
James Smart9bad7672008-12-04 22:39:02 -05004719 * @cmnd: Pointer to scsi_cmnd data structure.
4720 *
James Smartbbb9d182009-06-10 17:23:16 -04004721 * This routine does target reset to all targets on @cmnd->device->host.
4722 * This emulates Parallel SCSI Bus Reset Semantics.
James Smart9bad7672008-12-04 22:39:02 -05004723 *
James Smartbbb9d182009-06-10 17:23:16 -04004724 * Return code :
4725 * 0x2003 - Error
4726 * 0x2002 - Success
James Smart9bad7672008-12-04 22:39:02 -05004727 **/
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04004728static int
James Smart7054a602007-04-25 09:52:34 -04004729lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05004730{
James Smart2e0fef82007-06-17 19:56:36 -05004731 struct Scsi_Host *shost = cmnd->device->host;
4732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
dea31012005-04-17 16:05:31 -05004733 struct lpfc_nodelist *ndlp = NULL;
James Smartea2151b2008-09-07 11:52:10 -04004734 struct lpfc_scsi_event_header scsi_event;
James Smartbbb9d182009-06-10 17:23:16 -04004735 int match;
4736 int ret = SUCCESS, status, i;
James Smartea2151b2008-09-07 11:52:10 -04004737
4738 scsi_event.event_type = FC_REG_SCSI_EVENT;
4739 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
4740 scsi_event.lun = 0;
4741 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
4742 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
4743
James Smartbbb9d182009-06-10 17:23:16 -04004744 fc_host_post_vendor_event(shost, fc_get_event_number(),
4745 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
dea31012005-04-17 16:05:31 -05004746
James Smartbf086112011-08-21 21:48:13 -04004747 status = fc_block_scsi_eh(cmnd);
4748 if (status)
4749 return status;
James Smartbbb9d182009-06-10 17:23:16 -04004750
dea31012005-04-17 16:05:31 -05004751 /*
4752 * Since the driver manages a single bus device, reset all
4753 * targets known to the driver. Should any target reset
4754 * fail, this routine returns failure to the midlayer.
4755 */
James Smarte17da182006-07-06 15:49:25 -04004756 for (i = 0; i < LPFC_MAX_TARGET; i++) {
James Smart685f0bf2007-04-25 09:53:08 -04004757 /* Search for mapped node by target ID */
dea31012005-04-17 16:05:31 -05004758 match = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004759 spin_lock_irq(shost->host_lock);
4760 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004761 if (!NLP_CHK_NODE_ACT(ndlp))
4762 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004763 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart915caaa2008-06-14 22:52:38 -04004764 ndlp->nlp_sid == i &&
James Smart685f0bf2007-04-25 09:53:08 -04004765 ndlp->rport) {
dea31012005-04-17 16:05:31 -05004766 match = 1;
4767 break;
4768 }
4769 }
James Smart2e0fef82007-06-17 19:56:36 -05004770 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004771 if (!match)
4772 continue;
James Smartbbb9d182009-06-10 17:23:16 -04004773
4774 status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
4775 i, 0, FCP_TARGET_RESET);
4776
4777 if (status != SUCCESS) {
James Smarte8b62012007-08-02 11:10:09 -04004778 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4779 "0700 Bus Reset on target %d failed\n",
4780 i);
James Smart915caaa2008-06-14 22:52:38 -04004781 ret = FAILED;
dea31012005-04-17 16:05:31 -05004782 }
4783 }
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05004784 /*
James Smartbbb9d182009-06-10 17:23:16 -04004785 * We have to clean up i/o as : they may be orphaned by the TMFs
4786 * above; or if any of the TMFs failed, they may be in an
4787 * indeterminate state.
4788 * We will report success if all the i/o aborts successfully.
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05004789 */
James Smartbbb9d182009-06-10 17:23:16 -04004790
4791 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
4792 if (status != SUCCESS)
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05004793 ret = FAILED;
James Smartbbb9d182009-06-10 17:23:16 -04004794
James Smarte8b62012007-08-02 11:10:09 -04004795 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4796 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
dea31012005-04-17 16:05:31 -05004797 return ret;
4798}
4799
James Smart9bad7672008-12-04 22:39:02 -05004800/**
James Smart3621a712009-04-06 18:47:14 -04004801 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
James Smart9bad7672008-12-04 22:39:02 -05004802 * @sdev: Pointer to scsi_device.
4803 *
4804 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
4805 * globally available list of scsi buffers. This routine also makes sure scsi
4806 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
4807 * of scsi buffer exists for the lifetime of the driver.
4808 *
4809 * Return codes:
4810 * non-0 - Error
4811 * 0 - Success
4812 **/
dea31012005-04-17 16:05:31 -05004813static int
dea31012005-04-17 16:05:31 -05004814lpfc_slave_alloc(struct scsi_device *sdev)
4815{
James Smart2e0fef82007-06-17 19:56:36 -05004816 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
4817 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004818 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
James Smart3772a992009-05-22 14:50:54 -04004819 uint32_t total = 0;
dea31012005-04-17 16:05:31 -05004820 uint32_t num_to_alloc = 0;
James Smart3772a992009-05-22 14:50:54 -04004821 int num_allocated = 0;
James Smartd7c47992010-06-08 18:31:54 -04004822 uint32_t sdev_cnt;
dea31012005-04-17 16:05:31 -05004823
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004824 if (!rport || fc_remote_port_chkready(rport))
dea31012005-04-17 16:05:31 -05004825 return -ENXIO;
4826
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004827 sdev->hostdata = rport->dd_data;
James Smartd7c47992010-06-08 18:31:54 -04004828 sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
dea31012005-04-17 16:05:31 -05004829
4830 /*
4831 * Populate the cmds_per_lun count scsi_bufs into this host's globally
4832 * available list of scsi buffers. Don't allocate more than the
James.Smart@Emulex.Coma784efb2005-10-28 20:29:51 -04004833 * HBA limit conveyed to the midlayer via the host structure. The
4834 * formula accounts for the lun_queue_depth + error handlers + 1
4835 * extra. This list of scsi bufs exists for the lifetime of the driver.
dea31012005-04-17 16:05:31 -05004836 */
4837 total = phba->total_scsi_bufs;
James Smart3de2a652007-08-02 11:09:59 -04004838 num_to_alloc = vport->cfg_lun_queue_depth + 2;
James Smart92d7f7b2007-06-17 19:56:38 -05004839
James Smartd7c47992010-06-08 18:31:54 -04004840 /* If allocated buffers are enough do nothing */
4841 if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
4842 return 0;
4843
James Smart92d7f7b2007-06-17 19:56:38 -05004844 /* Allow some exchanges to be available always to complete discovery */
4845 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04004846 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4847 "0704 At limitation of %d preallocated "
4848 "command buffers\n", total);
dea31012005-04-17 16:05:31 -05004849 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004850 /* Allow some exchanges to be available always to complete discovery */
4851 } else if (total + num_to_alloc >
4852 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04004853 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4854 "0705 Allocation request of %d "
4855 "command buffers will exceed max of %d. "
4856 "Reducing allocation request to %d.\n",
4857 num_to_alloc, phba->cfg_hba_queue_depth,
4858 (phba->cfg_hba_queue_depth - total));
dea31012005-04-17 16:05:31 -05004859 num_to_alloc = phba->cfg_hba_queue_depth - total;
4860 }
James Smart3772a992009-05-22 14:50:54 -04004861 num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc);
4862 if (num_to_alloc != num_allocated) {
4863 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4864 "0708 Allocation request of %d "
4865 "command buffers did not succeed. "
4866 "Allocated %d buffers.\n",
4867 num_to_alloc, num_allocated);
dea31012005-04-17 16:05:31 -05004868 }
James Smart1c6f4ef52009-11-18 15:40:49 -05004869 if (num_allocated > 0)
4870 phba->total_scsi_bufs += num_allocated;
dea31012005-04-17 16:05:31 -05004871 return 0;
4872}
4873
James Smart9bad7672008-12-04 22:39:02 -05004874/**
James Smart3621a712009-04-06 18:47:14 -04004875 * lpfc_slave_configure - scsi_host_template slave_configure entry point
James Smart9bad7672008-12-04 22:39:02 -05004876 * @sdev: Pointer to scsi_device.
4877 *
4878 * This routine configures following items
4879 * - Tag command queuing support for @sdev if supported.
James Smart9bad7672008-12-04 22:39:02 -05004880 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
4881 *
4882 * Return codes:
4883 * 0 - Success
4884 **/
dea31012005-04-17 16:05:31 -05004885static int
4886lpfc_slave_configure(struct scsi_device *sdev)
4887{
James Smart2e0fef82007-06-17 19:56:36 -05004888 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
4889 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004890
4891 if (sdev->tagged_supported)
James Smart3de2a652007-08-02 11:09:59 -04004892 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05004893 else
James Smart3de2a652007-08-02 11:09:59 -04004894 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05004895
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004896 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04004897 lpfc_sli_handle_fast_ring_event(phba,
4898 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004899 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4900 lpfc_poll_rearm_timer(phba);
4901 }
4902
dea31012005-04-17 16:05:31 -05004903 return 0;
4904}
4905
James Smart9bad7672008-12-04 22:39:02 -05004906/**
James Smart3621a712009-04-06 18:47:14 -04004907 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
James Smart9bad7672008-12-04 22:39:02 -05004908 * @sdev: Pointer to scsi_device.
4909 *
4910 * This routine sets @sdev hostatdata filed to null.
4911 **/
dea31012005-04-17 16:05:31 -05004912static void
4913lpfc_slave_destroy(struct scsi_device *sdev)
4914{
James Smartd7c47992010-06-08 18:31:54 -04004915 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
4916 struct lpfc_hba *phba = vport->phba;
4917 atomic_dec(&phba->sdev_cnt);
dea31012005-04-17 16:05:31 -05004918 sdev->hostdata = NULL;
4919 return;
4920}
4921
James Smart92d7f7b2007-06-17 19:56:38 -05004922
dea31012005-04-17 16:05:31 -05004923struct scsi_host_template lpfc_template = {
4924 .module = THIS_MODULE,
4925 .name = LPFC_DRIVER_NAME,
4926 .info = lpfc_info,
4927 .queuecommand = lpfc_queuecommand,
4928 .eh_abort_handler = lpfc_abort_handler,
James Smartbbb9d182009-06-10 17:23:16 -04004929 .eh_device_reset_handler = lpfc_device_reset_handler,
4930 .eh_target_reset_handler = lpfc_target_reset_handler,
James Smart7054a602007-04-25 09:52:34 -04004931 .eh_bus_reset_handler = lpfc_bus_reset_handler,
dea31012005-04-17 16:05:31 -05004932 .slave_alloc = lpfc_slave_alloc,
4933 .slave_configure = lpfc_slave_configure,
4934 .slave_destroy = lpfc_slave_destroy,
James Smart47a86172007-04-25 09:53:22 -04004935 .scan_finished = lpfc_scan_finished,
dea31012005-04-17 16:05:31 -05004936 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05004937 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
dea31012005-04-17 16:05:31 -05004938 .cmd_per_lun = LPFC_CMD_PER_LUN,
4939 .use_clustering = ENABLE_CLUSTERING,
James Smart2e0fef82007-06-17 19:56:36 -05004940 .shost_attrs = lpfc_hba_attrs,
James.Smart@Emulex.Com564b2962005-06-25 10:34:17 -04004941 .max_sectors = 0xFFFF,
James Smartf1c3b0f2009-07-19 10:01:32 -04004942 .vendor_id = LPFC_NL_VENDOR_ID,
James Smart5ffc2662009-11-18 15:39:44 -05004943 .change_queue_depth = lpfc_change_queue_depth,
dea31012005-04-17 16:05:31 -05004944};
James Smart3de2a652007-08-02 11:09:59 -04004945
4946struct scsi_host_template lpfc_vport_template = {
4947 .module = THIS_MODULE,
4948 .name = LPFC_DRIVER_NAME,
4949 .info = lpfc_info,
4950 .queuecommand = lpfc_queuecommand,
4951 .eh_abort_handler = lpfc_abort_handler,
James Smartbbb9d182009-06-10 17:23:16 -04004952 .eh_device_reset_handler = lpfc_device_reset_handler,
4953 .eh_target_reset_handler = lpfc_target_reset_handler,
James Smart3de2a652007-08-02 11:09:59 -04004954 .eh_bus_reset_handler = lpfc_bus_reset_handler,
4955 .slave_alloc = lpfc_slave_alloc,
4956 .slave_configure = lpfc_slave_configure,
4957 .slave_destroy = lpfc_slave_destroy,
4958 .scan_finished = lpfc_scan_finished,
4959 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05004960 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
James Smart3de2a652007-08-02 11:09:59 -04004961 .cmd_per_lun = LPFC_CMD_PER_LUN,
4962 .use_clustering = ENABLE_CLUSTERING,
4963 .shost_attrs = lpfc_vport_attrs,
4964 .max_sectors = 0xFFFF,
James Smart5ffc2662009-11-18 15:39:44 -05004965 .change_queue_depth = lpfc_change_queue_depth,
James Smart3de2a652007-08-02 11:09:59 -04004966};