blob: f7a92653467a2888c71cabc977cecd1de61ee347 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * 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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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>
James Smarta90f5682006-08-17 11:58:04 -040024#include <linux/delay.h>
James Smarte2a0a9d2008-12-04 22:40:02 -050025#include <asm/unaligned.h>
dea31012005-04-17 16:05:31 -050026
27#include <scsi/scsi.h>
28#include <scsi/scsi_device.h>
James Smarte2a0a9d2008-12-04 22:40:02 -050029#include <scsi/scsi_eh.h>
dea31012005-04-17 16:05:31 -050030#include <scsi/scsi_host.h>
31#include <scsi/scsi_tcq.h>
32#include <scsi/scsi_transport_fc.h>
33
34#include "lpfc_version.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_hw.h"
37#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040039#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_disc.h"
41#include "lpfc_scsi.h"
42#include "lpfc.h"
43#include "lpfc_logmsg.h"
44#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050045#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050046
47#define LPFC_RESET_WAIT 2
48#define LPFC_ABORT_WAIT 2
49
James Smarte2a0a9d2008-12-04 22:40:02 -050050int _dump_buf_done;
51
52static char *dif_op_str[] = {
53 "SCSI_PROT_NORMAL",
54 "SCSI_PROT_READ_INSERT",
55 "SCSI_PROT_WRITE_STRIP",
56 "SCSI_PROT_READ_STRIP",
57 "SCSI_PROT_WRITE_INSERT",
58 "SCSI_PROT_READ_PASS",
59 "SCSI_PROT_WRITE_PASS",
James Smarte2a0a9d2008-12-04 22:40:02 -050060};
James Smartda0436e2009-05-22 14:51:39 -040061static void
62lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
James Smart1c6f4ef52009-11-18 15:40:49 -050063static void
64lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
James Smarte2a0a9d2008-12-04 22:40:02 -050065
66static void
James Smart6a9c52c2009-10-02 15:16:51 -040067lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
James Smarte2a0a9d2008-12-04 22:40:02 -050068{
69 void *src, *dst;
70 struct scatterlist *sgde = scsi_sglist(cmnd);
71
72 if (!_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040073 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
74 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
James Smarte2a0a9d2008-12-04 22:40:02 -050075 __func__);
76 return;
77 }
78
79
80 if (!sgde) {
James Smart6a9c52c2009-10-02 15:16:51 -040081 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
82 "9051 BLKGRD: ERROR: data scatterlist is null\n");
James Smarte2a0a9d2008-12-04 22:40:02 -050083 return;
84 }
85
86 dst = (void *) _dump_buf_data;
87 while (sgde) {
88 src = sg_virt(sgde);
89 memcpy(dst, src, sgde->length);
90 dst += sgde->length;
91 sgde = sg_next(sgde);
92 }
93}
94
95static void
James Smart6a9c52c2009-10-02 15:16:51 -040096lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
James Smarte2a0a9d2008-12-04 22:40:02 -050097{
98 void *src, *dst;
99 struct scatterlist *sgde = scsi_prot_sglist(cmnd);
100
101 if (!_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -0400102 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
103 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500104 __func__);
105 return;
106 }
107
108 if (!sgde) {
James Smart6a9c52c2009-10-02 15:16:51 -0400109 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
110 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
James Smarte2a0a9d2008-12-04 22:40:02 -0500111 return;
112 }
113
114 dst = _dump_buf_dif;
115 while (sgde) {
116 src = sg_virt(sgde);
117 memcpy(dst, src, sgde->length);
118 dst += sgde->length;
119 sgde = sg_next(sgde);
120 }
121}
122
James Smartea2151b2008-09-07 11:52:10 -0400123/**
James Smartf1126682009-06-10 17:22:44 -0400124 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
125 * @phba: Pointer to HBA object.
126 * @lpfc_cmd: lpfc scsi command object pointer.
127 *
128 * This function is called from the lpfc_prep_task_mgmt_cmd function to
129 * set the last bit in the response sge entry.
130 **/
131static void
132lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
133 struct lpfc_scsi_buf *lpfc_cmd)
134{
135 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
136 if (sgl) {
137 sgl += 1;
138 sgl->word2 = le32_to_cpu(sgl->word2);
139 bf_set(lpfc_sli4_sge_last, sgl, 1);
140 sgl->word2 = cpu_to_le32(sgl->word2);
141 }
142}
143
144/**
James Smart3621a712009-04-06 18:47:14 -0400145 * lpfc_update_stats - Update statistical data for the command completion
James Smartea2151b2008-09-07 11:52:10 -0400146 * @phba: Pointer to HBA object.
147 * @lpfc_cmd: lpfc scsi command object pointer.
148 *
149 * This function is called when there is a command completion and this
150 * function updates the statistical data for the command completion.
151 **/
152static void
153lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
154{
155 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
156 struct lpfc_nodelist *pnode = rdata->pnode;
157 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
158 unsigned long flags;
159 struct Scsi_Host *shost = cmd->device->host;
160 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
161 unsigned long latency;
162 int i;
163
164 if (cmd->result)
165 return;
166
James Smart9f1e1b52008-12-04 22:39:40 -0500167 latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
168
James Smartea2151b2008-09-07 11:52:10 -0400169 spin_lock_irqsave(shost->host_lock, flags);
170 if (!vport->stat_data_enabled ||
171 vport->stat_data_blocked ||
172 !pnode->lat_data ||
173 (phba->bucket_type == LPFC_NO_BUCKET)) {
174 spin_unlock_irqrestore(shost->host_lock, flags);
175 return;
176 }
James Smartea2151b2008-09-07 11:52:10 -0400177
178 if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
179 i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
180 phba->bucket_step;
James Smart9f1e1b52008-12-04 22:39:40 -0500181 /* check array subscript bounds */
182 if (i < 0)
183 i = 0;
184 else if (i >= LPFC_MAX_BUCKET_COUNT)
185 i = LPFC_MAX_BUCKET_COUNT - 1;
James Smartea2151b2008-09-07 11:52:10 -0400186 } else {
187 for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
188 if (latency <= (phba->bucket_base +
189 ((1<<i)*phba->bucket_step)))
190 break;
191 }
192
193 pnode->lat_data[i].cmd_count++;
194 spin_unlock_irqrestore(shost->host_lock, flags);
195}
196
James Smartea2151b2008-09-07 11:52:10 -0400197/**
James Smart3621a712009-04-06 18:47:14 -0400198 * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
James Smartea2151b2008-09-07 11:52:10 -0400199 * @phba: Pointer to HBA context object.
200 * @vport: Pointer to vport object.
201 * @ndlp: Pointer to FC node associated with the target.
202 * @lun: Lun number of the scsi device.
203 * @old_val: Old value of the queue depth.
204 * @new_val: New value of the queue depth.
205 *
206 * This function sends an event to the mgmt application indicating
207 * there is a change in the scsi device queue depth.
208 **/
209static void
210lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba,
211 struct lpfc_vport *vport,
212 struct lpfc_nodelist *ndlp,
213 uint32_t lun,
214 uint32_t old_val,
215 uint32_t new_val)
216{
217 struct lpfc_fast_path_event *fast_path_evt;
218 unsigned long flags;
219
220 fast_path_evt = lpfc_alloc_fast_evt(phba);
221 if (!fast_path_evt)
222 return;
223
224 fast_path_evt->un.queue_depth_evt.scsi_event.event_type =
225 FC_REG_SCSI_EVENT;
226 fast_path_evt->un.queue_depth_evt.scsi_event.subcategory =
227 LPFC_EVENT_VARQUEDEPTH;
228
229 /* Report all luns with change in queue depth */
230 fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun;
231 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
232 memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn,
233 &ndlp->nlp_portname, sizeof(struct lpfc_name));
234 memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn,
235 &ndlp->nlp_nodename, sizeof(struct lpfc_name));
236 }
237
238 fast_path_evt->un.queue_depth_evt.oldval = old_val;
239 fast_path_evt->un.queue_depth_evt.newval = new_val;
240 fast_path_evt->vport = vport;
241
242 fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
243 spin_lock_irqsave(&phba->hbalock, flags);
244 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
245 spin_unlock_irqrestore(&phba->hbalock, flags);
246 lpfc_worker_wake_up(phba);
247
248 return;
249}
250
James Smart9bad7672008-12-04 22:39:02 -0500251/**
James Smart5ffc2662009-11-18 15:39:44 -0500252 * lpfc_change_queue_depth - Alter scsi device queue depth
253 * @sdev: Pointer the scsi device on which to change the queue depth.
254 * @qdepth: New queue depth to set the sdev to.
255 * @reason: The reason for the queue depth change.
256 *
257 * This function is called by the midlayer and the LLD to alter the queue
258 * depth for a scsi device. This function sets the queue depth to the new
259 * value and sends an event out to log the queue depth change.
260 **/
261int
262lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
263{
264 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
265 struct lpfc_hba *phba = vport->phba;
266 struct lpfc_rport_data *rdata;
267 unsigned long new_queue_depth, old_queue_depth;
268
269 old_queue_depth = sdev->queue_depth;
270 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
271 new_queue_depth = sdev->queue_depth;
272 rdata = sdev->hostdata;
273 if (rdata)
274 lpfc_send_sdev_queuedepth_change_event(phba, vport,
275 rdata->pnode, sdev->lun,
276 old_queue_depth,
277 new_queue_depth);
278 return sdev->queue_depth;
279}
280
281/**
James Smart3621a712009-04-06 18:47:14 -0400282 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
James Smart9bad7672008-12-04 22:39:02 -0500283 * @phba: The Hba for which this call is being executed.
284 *
285 * This routine is called when there is resource error in driver or firmware.
286 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
287 * posts at most 1 event each second. This routine wakes up worker thread of
288 * @phba to process WORKER_RAM_DOWN_EVENT event.
289 *
290 * This routine should be called with no lock held.
291 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500292void
James Smarteaf15d52008-12-04 22:39:29 -0500293lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
James Smart92d7f7b2007-06-17 19:56:38 -0500294{
295 unsigned long flags;
James Smart5e9d9b82008-06-14 22:52:53 -0400296 uint32_t evt_posted;
James Smart92d7f7b2007-06-17 19:56:38 -0500297
298 spin_lock_irqsave(&phba->hbalock, flags);
299 atomic_inc(&phba->num_rsrc_err);
300 phba->last_rsrc_error_time = jiffies;
301
302 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
303 spin_unlock_irqrestore(&phba->hbalock, flags);
304 return;
305 }
306
307 phba->last_ramp_down_time = jiffies;
308
309 spin_unlock_irqrestore(&phba->hbalock, flags);
310
311 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
James Smart5e9d9b82008-06-14 22:52:53 -0400312 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
313 if (!evt_posted)
James Smart92d7f7b2007-06-17 19:56:38 -0500314 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
James Smart92d7f7b2007-06-17 19:56:38 -0500315 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
316
James Smart5e9d9b82008-06-14 22:52:53 -0400317 if (!evt_posted)
318 lpfc_worker_wake_up(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500319 return;
320}
321
James Smart9bad7672008-12-04 22:39:02 -0500322/**
James Smart3621a712009-04-06 18:47:14 -0400323 * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread
James Smart9bad7672008-12-04 22:39:02 -0500324 * @phba: The Hba for which this call is being executed.
325 *
326 * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine
327 * post at most 1 event every 5 minute after last_ramp_up_time or
328 * last_rsrc_error_time. This routine wakes up worker thread of @phba
329 * to process WORKER_RAM_DOWN_EVENT event.
330 *
331 * This routine should be called with no lock held.
332 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500333static inline void
James Smart3de2a652007-08-02 11:09:59 -0400334lpfc_rampup_queue_depth(struct lpfc_vport *vport,
James Smarta257bf92009-04-06 18:48:10 -0400335 uint32_t queue_depth)
James Smart92d7f7b2007-06-17 19:56:38 -0500336{
337 unsigned long flags;
James Smart3de2a652007-08-02 11:09:59 -0400338 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400339 uint32_t evt_posted;
James Smart92d7f7b2007-06-17 19:56:38 -0500340 atomic_inc(&phba->num_cmd_success);
341
James Smarta257bf92009-04-06 18:48:10 -0400342 if (vport->cfg_lun_queue_depth <= queue_depth)
James Smart92d7f7b2007-06-17 19:56:38 -0500343 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500344 spin_lock_irqsave(&phba->hbalock, flags);
James Smart5ffc2662009-11-18 15:39:44 -0500345 if (time_before(jiffies,
346 phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) ||
347 time_before(jiffies,
348 phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500349 spin_unlock_irqrestore(&phba->hbalock, flags);
350 return;
351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352 phba->last_ramp_up_time = jiffies;
353 spin_unlock_irqrestore(&phba->hbalock, flags);
354
355 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
James Smart5e9d9b82008-06-14 22:52:53 -0400356 evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
357 if (!evt_posted)
James Smart92d7f7b2007-06-17 19:56:38 -0500358 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
James Smart92d7f7b2007-06-17 19:56:38 -0500359 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
360
James Smart5e9d9b82008-06-14 22:52:53 -0400361 if (!evt_posted)
362 lpfc_worker_wake_up(phba);
363 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500364}
365
James Smart9bad7672008-12-04 22:39:02 -0500366/**
James Smart3621a712009-04-06 18:47:14 -0400367 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
James Smart9bad7672008-12-04 22:39:02 -0500368 * @phba: The Hba for which this call is being executed.
369 *
370 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
371 * thread.This routine reduces queue depth for all scsi device on each vport
372 * associated with @phba.
373 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500374void
375lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
376{
James Smart549e55c2007-08-02 11:09:51 -0400377 struct lpfc_vport **vports;
378 struct Scsi_Host *shost;
James Smart92d7f7b2007-06-17 19:56:38 -0500379 struct scsi_device *sdev;
James Smart5ffc2662009-11-18 15:39:44 -0500380 unsigned long new_queue_depth;
James Smart92d7f7b2007-06-17 19:56:38 -0500381 unsigned long num_rsrc_err, num_cmd_success;
James Smart549e55c2007-08-02 11:09:51 -0400382 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500383
384 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
385 num_cmd_success = atomic_read(&phba->num_cmd_success);
386
James Smart549e55c2007-08-02 11:09:51 -0400387 vports = lpfc_create_vport_work_array(phba);
388 if (vports != NULL)
James Smart21e9a0a2009-05-22 14:53:21 -0400389 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400390 shost = lpfc_shost_from_vport(vports[i]);
391 shost_for_each_device(sdev, shost) {
James Smart92d7f7b2007-06-17 19:56:38 -0500392 new_queue_depth =
James Smart549e55c2007-08-02 11:09:51 -0400393 sdev->queue_depth * num_rsrc_err /
394 (num_rsrc_err + num_cmd_success);
395 if (!new_queue_depth)
396 new_queue_depth = sdev->queue_depth - 1;
397 else
398 new_queue_depth = sdev->queue_depth -
399 new_queue_depth;
James Smart5ffc2662009-11-18 15:39:44 -0500400 lpfc_change_queue_depth(sdev, new_queue_depth,
401 SCSI_QDEPTH_DEFAULT);
James Smart549e55c2007-08-02 11:09:51 -0400402 }
James Smart92d7f7b2007-06-17 19:56:38 -0500403 }
James Smart09372822008-01-11 01:52:54 -0500404 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500405 atomic_set(&phba->num_rsrc_err, 0);
406 atomic_set(&phba->num_cmd_success, 0);
407}
408
James Smart9bad7672008-12-04 22:39:02 -0500409/**
James Smart3621a712009-04-06 18:47:14 -0400410 * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler
James Smart9bad7672008-12-04 22:39:02 -0500411 * @phba: The Hba for which this call is being executed.
412 *
413 * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker
414 * thread.This routine increases queue depth for all scsi device on each vport
415 * associated with @phba by 1. This routine also sets @phba num_rsrc_err and
416 * num_cmd_success to zero.
417 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500418void
419lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
420{
James Smart549e55c2007-08-02 11:09:51 -0400421 struct lpfc_vport **vports;
422 struct Scsi_Host *shost;
James Smart92d7f7b2007-06-17 19:56:38 -0500423 struct scsi_device *sdev;
James Smart549e55c2007-08-02 11:09:51 -0400424 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500425
James Smart549e55c2007-08-02 11:09:51 -0400426 vports = lpfc_create_vport_work_array(phba);
427 if (vports != NULL)
James Smart21e9a0a2009-05-22 14:53:21 -0400428 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400429 shost = lpfc_shost_from_vport(vports[i]);
430 shost_for_each_device(sdev, shost) {
James Smart97eab632008-04-07 10:16:05 -0400431 if (vports[i]->cfg_lun_queue_depth <=
432 sdev->queue_depth)
433 continue;
James Smart5ffc2662009-11-18 15:39:44 -0500434 lpfc_change_queue_depth(sdev,
435 sdev->queue_depth+1,
436 SCSI_QDEPTH_RAMP_UP);
James Smart549e55c2007-08-02 11:09:51 -0400437 }
James Smart92d7f7b2007-06-17 19:56:38 -0500438 }
James Smart09372822008-01-11 01:52:54 -0500439 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500440 atomic_set(&phba->num_rsrc_err, 0);
441 atomic_set(&phba->num_cmd_success, 0);
442}
443
James Smarta8e497d2008-08-24 21:50:11 -0400444/**
James Smart3621a712009-04-06 18:47:14 -0400445 * lpfc_scsi_dev_block - set all scsi hosts to block state
James Smarta8e497d2008-08-24 21:50:11 -0400446 * @phba: Pointer to HBA context object.
447 *
448 * This function walks vport list and set each SCSI host to block state
449 * by invoking fc_remote_port_delete() routine. This function is invoked
450 * with EEH when device's PCI slot has been permanently disabled.
451 **/
452void
453lpfc_scsi_dev_block(struct lpfc_hba *phba)
454{
455 struct lpfc_vport **vports;
456 struct Scsi_Host *shost;
457 struct scsi_device *sdev;
458 struct fc_rport *rport;
459 int i;
460
461 vports = lpfc_create_vport_work_array(phba);
462 if (vports != NULL)
James Smart21e9a0a2009-05-22 14:53:21 -0400463 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8e497d2008-08-24 21:50:11 -0400464 shost = lpfc_shost_from_vport(vports[i]);
465 shost_for_each_device(sdev, shost) {
466 rport = starget_to_rport(scsi_target(sdev));
467 fc_remote_port_delete(rport);
468 }
469 }
470 lpfc_destroy_vport_work_array(phba, vports);
471}
472
James Smart9bad7672008-12-04 22:39:02 -0500473/**
James Smart3772a992009-05-22 14:50:54 -0400474 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
James Smart9bad7672008-12-04 22:39:02 -0500475 * @vport: The virtual port for which this call being executed.
James Smart3772a992009-05-22 14:50:54 -0400476 * @num_to_allocate: The requested number of buffers to allocate.
James Smart9bad7672008-12-04 22:39:02 -0500477 *
James Smart3772a992009-05-22 14:50:54 -0400478 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
479 * the scsi buffer contains all the necessary information needed to initiate
480 * a SCSI I/O. The non-DMAable buffer region contains information to build
481 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
482 * and the initial BPL. In addition to allocating memory, the FCP CMND and
483 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
James Smart9bad7672008-12-04 22:39:02 -0500484 *
485 * Return codes:
James Smart3772a992009-05-22 14:50:54 -0400486 * int - number of scsi buffers that were allocated.
487 * 0 = failure, less than num_to_alloc is a partial failure.
James Smart9bad7672008-12-04 22:39:02 -0500488 **/
James Smart3772a992009-05-22 14:50:54 -0400489static int
490lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
dea31012005-04-17 16:05:31 -0500491{
James Smart2e0fef82007-06-17 19:56:36 -0500492 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500493 struct lpfc_scsi_buf *psb;
494 struct ulp_bde64 *bpl;
495 IOCB_t *iocb;
James Smart34b02dc2008-08-24 21:49:55 -0400496 dma_addr_t pdma_phys_fcp_cmd;
497 dma_addr_t pdma_phys_fcp_rsp;
498 dma_addr_t pdma_phys_bpl;
James Bottomley604a3e32005-10-29 10:28:33 -0500499 uint16_t iotag;
James Smart3772a992009-05-22 14:50:54 -0400500 int bcnt;
dea31012005-04-17 16:05:31 -0500501
James Smart3772a992009-05-22 14:50:54 -0400502 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
503 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
504 if (!psb)
505 break;
dea31012005-04-17 16:05:31 -0500506
James Smart3772a992009-05-22 14:50:54 -0400507 /*
508 * Get memory from the pci pool to map the virt space to pci
509 * bus space for an I/O. The DMA buffer includes space for the
510 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
511 * necessary to support the sg_tablesize.
512 */
513 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
514 GFP_KERNEL, &psb->dma_handle);
515 if (!psb->data) {
516 kfree(psb);
517 break;
518 }
dea31012005-04-17 16:05:31 -0500519
James Smart3772a992009-05-22 14:50:54 -0400520 /* Initialize virtual ptrs to dma_buf region. */
521 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
dea31012005-04-17 16:05:31 -0500522
James Smart3772a992009-05-22 14:50:54 -0400523 /* Allocate iotag for psb->cur_iocbq. */
524 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
525 if (iotag == 0) {
526 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
527 psb->data, psb->dma_handle);
528 kfree(psb);
529 break;
530 }
531 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
James Bottomley604a3e32005-10-29 10:28:33 -0500532
James Smart3772a992009-05-22 14:50:54 -0400533 psb->fcp_cmnd = psb->data;
534 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
535 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
James Smart34b02dc2008-08-24 21:49:55 -0400536 sizeof(struct fcp_rsp);
dea31012005-04-17 16:05:31 -0500537
James Smart3772a992009-05-22 14:50:54 -0400538 /* Initialize local short-hand pointers. */
539 bpl = psb->fcp_bpl;
540 pdma_phys_fcp_cmd = psb->dma_handle;
541 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
542 pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
543 sizeof(struct fcp_rsp);
dea31012005-04-17 16:05:31 -0500544
James Smart3772a992009-05-22 14:50:54 -0400545 /*
546 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
547 * are sg list bdes. Initialize the first two and leave the
548 * rest for queuecommand.
549 */
550 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
551 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
552 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
553 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
554 bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
dea31012005-04-17 16:05:31 -0500555
James Smart3772a992009-05-22 14:50:54 -0400556 /* Setup the physical region for the FCP RSP */
557 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
558 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
559 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
560 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
561 bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
562
563 /*
564 * Since the IOCB for the FCP I/O is built into this
565 * lpfc_scsi_buf, initialize it with all known data now.
566 */
567 iocb = &psb->cur_iocbq.iocb;
568 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
569 if ((phba->sli_rev == 3) &&
570 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
571 /* fill in immediate fcp command BDE */
572 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
573 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
574 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
575 unsli3.fcp_ext.icd);
576 iocb->un.fcpi64.bdl.addrHigh = 0;
577 iocb->ulpBdeCount = 0;
578 iocb->ulpLe = 0;
579 /* fill in responce BDE */
580 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
581 BUFF_TYPE_BDE_64;
582 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
583 sizeof(struct fcp_rsp);
584 iocb->unsli3.fcp_ext.rbde.addrLow =
585 putPaddrLow(pdma_phys_fcp_rsp);
586 iocb->unsli3.fcp_ext.rbde.addrHigh =
587 putPaddrHigh(pdma_phys_fcp_rsp);
588 } else {
589 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
590 iocb->un.fcpi64.bdl.bdeSize =
591 (2 * sizeof(struct ulp_bde64));
592 iocb->un.fcpi64.bdl.addrLow =
593 putPaddrLow(pdma_phys_bpl);
594 iocb->un.fcpi64.bdl.addrHigh =
595 putPaddrHigh(pdma_phys_bpl);
596 iocb->ulpBdeCount = 1;
597 iocb->ulpLe = 1;
598 }
599 iocb->ulpClass = CLASS3;
600 psb->status = IOSTAT_SUCCESS;
James Smartda0436e2009-05-22 14:51:39 -0400601 /* Put it back into the SCSI buffer list */
James Smart1c6f4ef52009-11-18 15:40:49 -0500602 lpfc_release_scsi_buf_s3(phba, psb);
James Smart3772a992009-05-22 14:50:54 -0400603
James Smart34b02dc2008-08-24 21:49:55 -0400604 }
dea31012005-04-17 16:05:31 -0500605
James Smart3772a992009-05-22 14:50:54 -0400606 return bcnt;
dea31012005-04-17 16:05:31 -0500607}
608
James Smart9bad7672008-12-04 22:39:02 -0500609/**
James Smartda0436e2009-05-22 14:51:39 -0400610 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
611 * @phba: pointer to lpfc hba data structure.
612 * @axri: pointer to the fcp xri abort wcqe structure.
613 *
614 * This routine is invoked by the worker thread to process a SLI4 fast-path
615 * FCP aborted xri.
616 **/
617void
618lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
619 struct sli4_wcqe_xri_aborted *axri)
620{
621 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
622 struct lpfc_scsi_buf *psb, *next_psb;
623 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500624 struct lpfc_iocbq *iocbq;
625 int i;
James Smartda0436e2009-05-22 14:51:39 -0400626
James Smart0f65ff62010-02-26 14:14:23 -0500627 spin_lock_irqsave(&phba->hbalock, iflag);
628 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
James Smartda0436e2009-05-22 14:51:39 -0400629 list_for_each_entry_safe(psb, next_psb,
630 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
631 if (psb->cur_iocbq.sli4_xritag == xri) {
632 list_del(&psb->list);
James Smart341af102010-01-26 23:07:37 -0500633 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400634 psb->status = IOSTAT_SUCCESS;
James Smart0f65ff62010-02-26 14:14:23 -0500635 spin_unlock(
636 &phba->sli4_hba.abts_scsi_buf_list_lock);
637 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartda0436e2009-05-22 14:51:39 -0400638 lpfc_release_scsi_buf_s4(phba, psb);
639 return;
640 }
641 }
James Smart0f65ff62010-02-26 14:14:23 -0500642 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
643 for (i = 1; i <= phba->sli.last_iotag; i++) {
644 iocbq = phba->sli.iocbq_lookup[i];
645
646 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
647 (iocbq->iocb_flag & LPFC_IO_LIBDFC))
648 continue;
649 if (iocbq->sli4_xritag != xri)
650 continue;
651 psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
652 psb->exch_busy = 0;
653 spin_unlock_irqrestore(&phba->hbalock, iflag);
654 return;
655
656 }
657 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartda0436e2009-05-22 14:51:39 -0400658}
659
660/**
661 * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block
662 * @phba: pointer to lpfc hba data structure.
663 *
664 * This routine walks the list of scsi buffers that have been allocated and
665 * repost them to the HBA by using SGL block post. This is needed after a
666 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
667 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
668 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
669 *
670 * Returns: 0 = success, non-zero failure.
671 **/
672int
673lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba)
674{
675 struct lpfc_scsi_buf *psb;
676 int index, status, bcnt = 0, rcnt = 0, rc = 0;
677 LIST_HEAD(sblist);
678
679 for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) {
680 psb = phba->sli4_hba.lpfc_scsi_psb_array[index];
681 if (psb) {
682 /* Remove from SCSI buffer list */
683 list_del(&psb->list);
684 /* Add it to a local SCSI buffer list */
685 list_add_tail(&psb->list, &sblist);
686 if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) {
687 bcnt = rcnt;
688 rcnt = 0;
689 }
690 } else
691 /* A hole present in the XRI array, need to skip */
692 bcnt = rcnt;
693
694 if (index == phba->sli4_hba.scsi_xri_cnt - 1)
695 /* End of XRI array for SCSI buffer, complete */
696 bcnt = rcnt;
697
698 /* Continue until collect up to a nembed page worth of sgls */
699 if (bcnt == 0)
700 continue;
701 /* Now, post the SCSI buffer list sgls as a block */
702 status = lpfc_sli4_post_scsi_sgl_block(phba, &sblist, bcnt);
703 /* Reset SCSI buffer count for next round of posting */
704 bcnt = 0;
705 while (!list_empty(&sblist)) {
706 list_remove_head(&sblist, psb, struct lpfc_scsi_buf,
707 list);
708 if (status) {
709 /* Put this back on the abort scsi list */
James Smart341af102010-01-26 23:07:37 -0500710 psb->exch_busy = 1;
James Smartda0436e2009-05-22 14:51:39 -0400711 rc++;
James Smart341af102010-01-26 23:07:37 -0500712 } else {
713 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400714 psb->status = IOSTAT_SUCCESS;
James Smart341af102010-01-26 23:07:37 -0500715 }
James Smartda0436e2009-05-22 14:51:39 -0400716 /* Put it back into the SCSI buffer list */
717 lpfc_release_scsi_buf_s4(phba, psb);
718 }
719 }
720 return rc;
721}
722
723/**
724 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
725 * @vport: The virtual port for which this call being executed.
726 * @num_to_allocate: The requested number of buffers to allocate.
727 *
728 * This routine allocates a scsi buffer for device with SLI-4 interface spec,
729 * the scsi buffer contains all the necessary information needed to initiate
730 * a SCSI I/O.
731 *
732 * Return codes:
733 * int - number of scsi buffers that were allocated.
734 * 0 = failure, less than num_to_alloc is a partial failure.
735 **/
736static int
737lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
738{
739 struct lpfc_hba *phba = vport->phba;
740 struct lpfc_scsi_buf *psb;
741 struct sli4_sge *sgl;
742 IOCB_t *iocb;
743 dma_addr_t pdma_phys_fcp_cmd;
744 dma_addr_t pdma_phys_fcp_rsp;
745 dma_addr_t pdma_phys_bpl, pdma_phys_bpl1;
746 uint16_t iotag, last_xritag = NO_XRI;
747 int status = 0, index;
748 int bcnt;
749 int non_sequential_xri = 0;
750 int rc = 0;
751 LIST_HEAD(sblist);
752
753 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
754 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
755 if (!psb)
756 break;
757
758 /*
759 * Get memory from the pci pool to map the virt space to pci bus
760 * space for an I/O. The DMA buffer includes space for the
761 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
762 * necessary to support the sg_tablesize.
763 */
764 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
765 GFP_KERNEL, &psb->dma_handle);
766 if (!psb->data) {
767 kfree(psb);
768 break;
769 }
770
771 /* Initialize virtual ptrs to dma_buf region. */
772 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
773
774 /* Allocate iotag for psb->cur_iocbq. */
775 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
776 if (iotag == 0) {
James Smartb92938b2010-06-07 15:24:12 -0400777 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
778 psb->data, psb->dma_handle);
James Smartda0436e2009-05-22 14:51:39 -0400779 kfree(psb);
780 break;
781 }
782
783 psb->cur_iocbq.sli4_xritag = lpfc_sli4_next_xritag(phba);
784 if (psb->cur_iocbq.sli4_xritag == NO_XRI) {
785 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
786 psb->data, psb->dma_handle);
787 kfree(psb);
788 break;
789 }
790 if (last_xritag != NO_XRI
791 && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) {
792 non_sequential_xri = 1;
793 } else
794 list_add_tail(&psb->list, &sblist);
795 last_xritag = psb->cur_iocbq.sli4_xritag;
796
797 index = phba->sli4_hba.scsi_xri_cnt++;
798 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
799
800 psb->fcp_bpl = psb->data;
801 psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size)
802 - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
803 psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd +
804 sizeof(struct fcp_cmnd));
805
806 /* Initialize local short-hand pointers. */
807 sgl = (struct sli4_sge *)psb->fcp_bpl;
808 pdma_phys_bpl = psb->dma_handle;
809 pdma_phys_fcp_cmd =
810 (psb->dma_handle + phba->cfg_sg_dma_buf_size)
811 - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
812 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
813
814 /*
815 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
816 * are sg list bdes. Initialize the first two and leave the
817 * rest for queuecommand.
818 */
819 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
820 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
James Smartda0436e2009-05-22 14:51:39 -0400821 bf_set(lpfc_sli4_sge_last, sgl, 0);
822 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart28baac72010-02-12 14:42:03 -0500823 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
James Smartda0436e2009-05-22 14:51:39 -0400824 sgl++;
825
826 /* Setup the physical region for the FCP RSP */
827 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
828 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
James Smartda0436e2009-05-22 14:51:39 -0400829 bf_set(lpfc_sli4_sge_last, sgl, 1);
830 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart28baac72010-02-12 14:42:03 -0500831 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
James Smartda0436e2009-05-22 14:51:39 -0400832
833 /*
834 * Since the IOCB for the FCP I/O is built into this
835 * lpfc_scsi_buf, initialize it with all known data now.
836 */
837 iocb = &psb->cur_iocbq.iocb;
838 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
839 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
840 /* setting the BLP size to 2 * sizeof BDE may not be correct.
841 * We are setting the bpl to point to out sgl. An sgl's
842 * entries are 16 bytes, a bpl entries are 12 bytes.
843 */
844 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
845 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
846 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
847 iocb->ulpBdeCount = 1;
848 iocb->ulpLe = 1;
849 iocb->ulpClass = CLASS3;
850 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
851 pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE;
852 else
853 pdma_phys_bpl1 = 0;
854 psb->dma_phys_bpl = pdma_phys_bpl;
855 phba->sli4_hba.lpfc_scsi_psb_array[index] = psb;
856 if (non_sequential_xri) {
857 status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl,
858 pdma_phys_bpl1,
859 psb->cur_iocbq.sli4_xritag);
860 if (status) {
861 /* Put this back on the abort scsi list */
James Smart341af102010-01-26 23:07:37 -0500862 psb->exch_busy = 1;
James Smartda0436e2009-05-22 14:51:39 -0400863 rc++;
James Smart341af102010-01-26 23:07:37 -0500864 } else {
865 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400866 psb->status = IOSTAT_SUCCESS;
James Smart341af102010-01-26 23:07:37 -0500867 }
James Smartda0436e2009-05-22 14:51:39 -0400868 /* Put it back into the SCSI buffer list */
869 lpfc_release_scsi_buf_s4(phba, psb);
870 break;
871 }
872 }
873 if (bcnt) {
874 status = lpfc_sli4_post_scsi_sgl_block(phba, &sblist, bcnt);
875 /* Reset SCSI buffer count for next round of posting */
876 while (!list_empty(&sblist)) {
877 list_remove_head(&sblist, psb, struct lpfc_scsi_buf,
878 list);
879 if (status) {
880 /* Put this back on the abort scsi list */
James Smart341af102010-01-26 23:07:37 -0500881 psb->exch_busy = 1;
James Smartda0436e2009-05-22 14:51:39 -0400882 rc++;
James Smart341af102010-01-26 23:07:37 -0500883 } else {
884 psb->exch_busy = 0;
James Smartda0436e2009-05-22 14:51:39 -0400885 psb->status = IOSTAT_SUCCESS;
James Smart341af102010-01-26 23:07:37 -0500886 }
James Smartda0436e2009-05-22 14:51:39 -0400887 /* Put it back into the SCSI buffer list */
888 lpfc_release_scsi_buf_s4(phba, psb);
889 }
890 }
891
892 return bcnt + non_sequential_xri - rc;
893}
894
895/**
James Smart3772a992009-05-22 14:50:54 -0400896 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
897 * @vport: The virtual port for which this call being executed.
898 * @num_to_allocate: The requested number of buffers to allocate.
899 *
900 * This routine wraps the actual SCSI buffer allocator function pointer from
901 * the lpfc_hba struct.
902 *
903 * Return codes:
904 * int - number of scsi buffers that were allocated.
905 * 0 = failure, less than num_to_alloc is a partial failure.
906 **/
907static inline int
908lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc)
909{
910 return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc);
911}
912
913/**
914 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
915 * @phba: The HBA for which this call is being executed.
James Smart9bad7672008-12-04 22:39:02 -0500916 *
917 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
918 * and returns to caller.
919 *
920 * Return codes:
921 * NULL - Error
922 * Pointer to lpfc_scsi_buf - Success
923 **/
Adrian Bunk455c53e2006-01-06 20:21:28 +0100924static struct lpfc_scsi_buf*
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500925lpfc_get_scsi_buf(struct lpfc_hba * phba)
dea31012005-04-17 16:05:31 -0500926{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400927 struct lpfc_scsi_buf * lpfc_cmd = NULL;
928 struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500929 unsigned long iflag = 0;
dea31012005-04-17 16:05:31 -0500930
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500931 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400932 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
James Smart1dcb58e2007-04-25 09:51:30 -0400933 if (lpfc_cmd) {
934 lpfc_cmd->seg_cnt = 0;
935 lpfc_cmd->nonsg_phys = 0;
James Smarte2a0a9d2008-12-04 22:40:02 -0500936 lpfc_cmd->prot_seg_cnt = 0;
James Smart1dcb58e2007-04-25 09:51:30 -0400937 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500938 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400939 return lpfc_cmd;
940}
941
James Smart9bad7672008-12-04 22:39:02 -0500942/**
James Smart3772a992009-05-22 14:50:54 -0400943 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
James Smart9bad7672008-12-04 22:39:02 -0500944 * @phba: The Hba for which this call is being executed.
945 * @psb: The scsi buffer which is being released.
946 *
947 * This routine releases @psb scsi buffer by adding it to tail of @phba
948 * lpfc_scsi_buf_list list.
949 **/
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400950static void
James Smart3772a992009-05-22 14:50:54 -0400951lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400952{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500953 unsigned long iflag = 0;
dea31012005-04-17 16:05:31 -0500954
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500955 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400956 psb->pCmd = NULL;
dea31012005-04-17 16:05:31 -0500957 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500958 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
dea31012005-04-17 16:05:31 -0500959}
960
James Smart9bad7672008-12-04 22:39:02 -0500961/**
James Smartda0436e2009-05-22 14:51:39 -0400962 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
963 * @phba: The Hba for which this call is being executed.
964 * @psb: The scsi buffer which is being released.
965 *
966 * This routine releases @psb scsi buffer by adding it to tail of @phba
967 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
968 * and cannot be reused for at least RA_TOV amount of time if it was
969 * aborted.
970 **/
971static void
972lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
973{
974 unsigned long iflag = 0;
975
James Smart341af102010-01-26 23:07:37 -0500976 if (psb->exch_busy) {
James Smartda0436e2009-05-22 14:51:39 -0400977 spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
978 iflag);
979 psb->pCmd = NULL;
980 list_add_tail(&psb->list,
981 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
982 spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock,
983 iflag);
984 } else {
985
986 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
987 psb->pCmd = NULL;
988 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
989 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
990 }
991}
992
993/**
James Smart3772a992009-05-22 14:50:54 -0400994 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
995 * @phba: The Hba for which this call is being executed.
996 * @psb: The scsi buffer which is being released.
997 *
998 * This routine releases @psb scsi buffer by adding it to tail of @phba
999 * lpfc_scsi_buf_list list.
1000 **/
1001static void
1002lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1003{
1004
1005 phba->lpfc_release_scsi_buf(phba, psb);
1006}
1007
1008/**
1009 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
James Smart9bad7672008-12-04 22:39:02 -05001010 * @phba: The Hba for which this call is being executed.
1011 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1012 *
1013 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
James Smart3772a992009-05-22 14:50:54 -04001014 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1015 * through sg elements and format the bdea. This routine also initializes all
1016 * IOCB fields which are dependent on scsi command request buffer.
James Smart9bad7672008-12-04 22:39:02 -05001017 *
1018 * Return codes:
1019 * 1 - Error
1020 * 0 - Success
1021 **/
dea31012005-04-17 16:05:31 -05001022static int
James Smart3772a992009-05-22 14:50:54 -04001023lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
dea31012005-04-17 16:05:31 -05001024{
1025 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
1026 struct scatterlist *sgel = NULL;
1027 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
1028 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
James Smart0f65ff62010-02-26 14:14:23 -05001029 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
dea31012005-04-17 16:05:31 -05001030 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
James Smart34b02dc2008-08-24 21:49:55 -04001031 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
dea31012005-04-17 16:05:31 -05001032 dma_addr_t physaddr;
James Smart34b02dc2008-08-24 21:49:55 -04001033 uint32_t num_bde = 0;
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05001034 int nseg, datadir = scsi_cmnd->sc_data_direction;
dea31012005-04-17 16:05:31 -05001035
1036 /*
1037 * There are three possibilities here - use scatter-gather segment, use
1038 * the single mapping, or neither. Start the lpfc command prep by
1039 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1040 * data bde entry.
1041 */
1042 bpl += 2;
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -07001043 if (scsi_sg_count(scsi_cmnd)) {
dea31012005-04-17 16:05:31 -05001044 /*
1045 * The driver stores the segment count returned from pci_map_sg
1046 * because this a count of dma-mappings used to map the use_sg
1047 * pages. They are not guaranteed to be the same for those
1048 * architectures that implement an IOMMU.
1049 */
dea31012005-04-17 16:05:31 -05001050
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -07001051 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
1052 scsi_sg_count(scsi_cmnd), datadir);
1053 if (unlikely(!nseg))
1054 return 1;
1055
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05001056 lpfc_cmd->seg_cnt = nseg;
dea31012005-04-17 16:05:31 -05001057 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04001058 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1059 "9064 BLKGRD: %s: Too many sg segments from "
James Smarte2a0a9d2008-12-04 22:40:02 -05001060 "dma_map_sg. Config %d, seg_cnt %d\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07001061 __func__, phba->cfg_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05001062 lpfc_cmd->seg_cnt);
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05001063 scsi_dma_unmap(scsi_cmnd);
dea31012005-04-17 16:05:31 -05001064 return 1;
1065 }
1066
1067 /*
1068 * The driver established a maximum scatter-gather segment count
1069 * during probe that limits the number of sg elements in any
1070 * single scsi command. Just run through the seg_cnt and format
1071 * the bde's.
James Smart34b02dc2008-08-24 21:49:55 -04001072 * When using SLI-3 the driver will try to fit all the BDEs into
1073 * the IOCB. If it can't then the BDEs get added to a BPL as it
1074 * does for SLI-2 mode.
dea31012005-04-17 16:05:31 -05001075 */
James Smart34b02dc2008-08-24 21:49:55 -04001076 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
dea31012005-04-17 16:05:31 -05001077 physaddr = sg_dma_address(sgel);
James Smart34b02dc2008-08-24 21:49:55 -04001078 if (phba->sli_rev == 3 &&
James Smarte2a0a9d2008-12-04 22:40:02 -05001079 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
James Smart0f65ff62010-02-26 14:14:23 -05001080 !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
James Smart34b02dc2008-08-24 21:49:55 -04001081 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
1082 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1083 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
1084 data_bde->addrLow = putPaddrLow(physaddr);
1085 data_bde->addrHigh = putPaddrHigh(physaddr);
1086 data_bde++;
1087 } else {
1088 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1089 bpl->tus.f.bdeSize = sg_dma_len(sgel);
1090 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1091 bpl->addrLow =
1092 le32_to_cpu(putPaddrLow(physaddr));
1093 bpl->addrHigh =
1094 le32_to_cpu(putPaddrHigh(physaddr));
1095 bpl++;
1096 }
dea31012005-04-17 16:05:31 -05001097 }
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -07001098 }
dea31012005-04-17 16:05:31 -05001099
1100 /*
1101 * Finish initializing those IOCB fields that are dependent on the
James Smart34b02dc2008-08-24 21:49:55 -04001102 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1103 * explicitly reinitialized and for SLI-3 the extended bde count is
1104 * explicitly reinitialized since all iocb memory resources are reused.
dea31012005-04-17 16:05:31 -05001105 */
James Smarte2a0a9d2008-12-04 22:40:02 -05001106 if (phba->sli_rev == 3 &&
James Smart0f65ff62010-02-26 14:14:23 -05001107 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
1108 !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
James Smart34b02dc2008-08-24 21:49:55 -04001109 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
1110 /*
1111 * The extended IOCB format can only fit 3 BDE or a BPL.
1112 * This I/O has more than 3 BDE so the 1st data bde will
1113 * be a BPL that is filled in here.
1114 */
1115 physaddr = lpfc_cmd->dma_handle;
1116 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
1117 data_bde->tus.f.bdeSize = (num_bde *
1118 sizeof(struct ulp_bde64));
1119 physaddr += (sizeof(struct fcp_cmnd) +
1120 sizeof(struct fcp_rsp) +
1121 (2 * sizeof(struct ulp_bde64)));
1122 data_bde->addrHigh = putPaddrHigh(physaddr);
1123 data_bde->addrLow = putPaddrLow(physaddr);
1124 /* ebde count includes the responce bde and data bpl */
1125 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
1126 } else {
1127 /* ebde count includes the responce bde and data bdes */
1128 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1129 }
1130 } else {
1131 iocb_cmd->un.fcpi64.bdl.bdeSize =
1132 ((num_bde + 2) * sizeof(struct ulp_bde64));
James Smart0f65ff62010-02-26 14:14:23 -05001133 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
James Smart34b02dc2008-08-24 21:49:55 -04001134 }
James Smart09372822008-01-11 01:52:54 -05001135 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
James Smarte2a0a9d2008-12-04 22:40:02 -05001136
1137 /*
1138 * Due to difference in data length between DIF/non-DIF paths,
1139 * we need to set word 4 of IOCB here
1140 */
James Smarta257bf92009-04-06 18:48:10 -04001141 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
dea31012005-04-17 16:05:31 -05001142 return 0;
1143}
1144
James Smarte2a0a9d2008-12-04 22:40:02 -05001145/*
James Smart6c8eea52010-04-06 14:49:53 -04001146 * Given a scsi cmnd, determine the BlockGuard opcodes to be used with it
1147 * @sc: The SCSI command to examine
1148 * @txopt: (out) BlockGuard operation for transmitted data
1149 * @rxopt: (out) BlockGuard operation for received data
1150 *
1151 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1152 *
James Smarte2a0a9d2008-12-04 22:40:02 -05001153 */
1154static int
James Smart6c8eea52010-04-06 14:49:53 -04001155lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1156 uint8_t *txop, uint8_t *rxop)
James Smarte2a0a9d2008-12-04 22:40:02 -05001157{
1158 uint8_t guard_type = scsi_host_get_guard(sc->device->host);
James Smart6c8eea52010-04-06 14:49:53 -04001159 uint8_t ret = 0;
James Smarte2a0a9d2008-12-04 22:40:02 -05001160
1161 if (guard_type == SHOST_DIX_GUARD_IP) {
1162 switch (scsi_get_prot_op(sc)) {
1163 case SCSI_PROT_READ_INSERT:
1164 case SCSI_PROT_WRITE_STRIP:
James Smart6c8eea52010-04-06 14:49:53 -04001165 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1166 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
James Smarte2a0a9d2008-12-04 22:40:02 -05001167 break;
1168
1169 case SCSI_PROT_READ_STRIP:
1170 case SCSI_PROT_WRITE_INSERT:
James Smart6c8eea52010-04-06 14:49:53 -04001171 *txop = BG_OP_IN_NODIF_OUT_CRC;
1172 *rxop = BG_OP_IN_CRC_OUT_NODIF;
James Smarte2a0a9d2008-12-04 22:40:02 -05001173 break;
1174
Martin K. Petersenc6af4042009-09-18 17:32:59 -04001175 case SCSI_PROT_READ_PASS:
1176 case SCSI_PROT_WRITE_PASS:
James Smart6c8eea52010-04-06 14:49:53 -04001177 *txop = BG_OP_IN_CSUM_OUT_CRC;
1178 *rxop = BG_OP_IN_CRC_OUT_CSUM;
James Smarte2a0a9d2008-12-04 22:40:02 -05001179 break;
1180
James Smarte2a0a9d2008-12-04 22:40:02 -05001181 case SCSI_PROT_NORMAL:
1182 default:
James Smart6a9c52c2009-10-02 15:16:51 -04001183 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
James Smart6c8eea52010-04-06 14:49:53 -04001184 "9063 BLKGRD: Bad op/guard:%d/%d combination\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05001185 scsi_get_prot_op(sc), guard_type);
James Smart6c8eea52010-04-06 14:49:53 -04001186 ret = 1;
James Smarte2a0a9d2008-12-04 22:40:02 -05001187 break;
1188
1189 }
1190 } else if (guard_type == SHOST_DIX_GUARD_CRC) {
1191 switch (scsi_get_prot_op(sc)) {
1192 case SCSI_PROT_READ_STRIP:
1193 case SCSI_PROT_WRITE_INSERT:
James Smart6c8eea52010-04-06 14:49:53 -04001194 *txop = BG_OP_IN_NODIF_OUT_CRC;
1195 *rxop = BG_OP_IN_CRC_OUT_NODIF;
James Smarte2a0a9d2008-12-04 22:40:02 -05001196 break;
1197
1198 case SCSI_PROT_READ_PASS:
1199 case SCSI_PROT_WRITE_PASS:
James Smart6c8eea52010-04-06 14:49:53 -04001200 *txop = BG_OP_IN_CRC_OUT_CRC;
1201 *rxop = BG_OP_IN_CRC_OUT_CRC;
James Smarte2a0a9d2008-12-04 22:40:02 -05001202 break;
1203
James Smarte2a0a9d2008-12-04 22:40:02 -05001204 case SCSI_PROT_READ_INSERT:
1205 case SCSI_PROT_WRITE_STRIP:
1206 case SCSI_PROT_NORMAL:
1207 default:
James Smart6a9c52c2009-10-02 15:16:51 -04001208 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1209 "9075 BLKGRD: Bad op/guard:%d/%d combination\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05001210 scsi_get_prot_op(sc), guard_type);
James Smart6c8eea52010-04-06 14:49:53 -04001211 ret = 1;
James Smarte2a0a9d2008-12-04 22:40:02 -05001212 break;
1213 }
1214 } else {
1215 /* unsupported format */
1216 BUG();
1217 }
1218
James Smart6c8eea52010-04-06 14:49:53 -04001219 return ret;
James Smarte2a0a9d2008-12-04 22:40:02 -05001220}
1221
1222struct scsi_dif_tuple {
1223 __be16 guard_tag; /* Checksum */
1224 __be16 app_tag; /* Opaque storage */
1225 __be32 ref_tag; /* Target LBA or indirect LBA */
1226};
1227
1228static inline unsigned
1229lpfc_cmd_blksize(struct scsi_cmnd *sc)
1230{
1231 return sc->device->sector_size;
1232}
1233
1234/**
1235 * lpfc_get_cmd_dif_parms - Extract DIF parameters from SCSI command
1236 * @sc: in: SCSI command
James Smart3621a712009-04-06 18:47:14 -04001237 * @apptagmask: out: app tag mask
1238 * @apptagval: out: app tag value
1239 * @reftag: out: ref tag (reference tag)
James Smarte2a0a9d2008-12-04 22:40:02 -05001240 *
1241 * Description:
Martin Olsson98a17082009-04-22 18:21:29 +02001242 * Extract DIF parameters from the command if possible. Otherwise,
1243 * use default parameters.
James Smarte2a0a9d2008-12-04 22:40:02 -05001244 *
1245 **/
1246static inline void
1247lpfc_get_cmd_dif_parms(struct scsi_cmnd *sc, uint16_t *apptagmask,
1248 uint16_t *apptagval, uint32_t *reftag)
1249{
1250 struct scsi_dif_tuple *spt;
1251 unsigned char op = scsi_get_prot_op(sc);
1252 unsigned int protcnt = scsi_prot_sg_count(sc);
1253 static int cnt;
1254
1255 if (protcnt && (op == SCSI_PROT_WRITE_STRIP ||
Martin K. Petersenc6af4042009-09-18 17:32:59 -04001256 op == SCSI_PROT_WRITE_PASS)) {
James Smarte2a0a9d2008-12-04 22:40:02 -05001257
1258 cnt++;
1259 spt = page_address(sg_page(scsi_prot_sglist(sc))) +
1260 scsi_prot_sglist(sc)[0].offset;
1261 *apptagmask = 0;
1262 *apptagval = 0;
1263 *reftag = cpu_to_be32(spt->ref_tag);
1264
1265 } else {
1266 /* SBC defines ref tag to be lower 32bits of LBA */
1267 *reftag = (uint32_t) (0xffffffff & scsi_get_lba(sc));
1268 *apptagmask = 0;
1269 *apptagval = 0;
1270 }
1271}
1272
1273/*
1274 * This function sets up buffer list for protection groups of
1275 * type LPFC_PG_TYPE_NO_DIF
1276 *
1277 * This is usually used when the HBA is instructed to generate
1278 * DIFs and insert them into data stream (or strip DIF from
1279 * incoming data stream)
1280 *
1281 * The buffer list consists of just one protection group described
1282 * below:
1283 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001284 * start of prot group --> | PDE_5 |
1285 * +-------------------------+
1286 * | PDE_6 |
James Smarte2a0a9d2008-12-04 22:40:02 -05001287 * +-------------------------+
1288 * | Data BDE |
1289 * +-------------------------+
1290 * |more Data BDE's ... (opt)|
1291 * +-------------------------+
1292 *
1293 * @sc: pointer to scsi command we're working on
1294 * @bpl: pointer to buffer list for protection groups
1295 * @datacnt: number of segments of data that have been dma mapped
1296 *
1297 * Note: Data s/g buffers have been dma mapped
1298 */
1299static int
1300lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1301 struct ulp_bde64 *bpl, int datasegcnt)
1302{
1303 struct scatterlist *sgde = NULL; /* s/g data entry */
James Smart6c8eea52010-04-06 14:49:53 -04001304 struct lpfc_pde5 *pde5 = NULL;
1305 struct lpfc_pde6 *pde6 = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05001306 dma_addr_t physaddr;
James Smart6c8eea52010-04-06 14:49:53 -04001307 int i = 0, num_bde = 0, status;
James Smarte2a0a9d2008-12-04 22:40:02 -05001308 int datadir = sc->sc_data_direction;
James Smarte2a0a9d2008-12-04 22:40:02 -05001309 unsigned blksize;
1310 uint32_t reftag;
1311 uint16_t apptagmask, apptagval;
James Smart6c8eea52010-04-06 14:49:53 -04001312 uint8_t txop, rxop;
James Smarte2a0a9d2008-12-04 22:40:02 -05001313
James Smart6c8eea52010-04-06 14:49:53 -04001314 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1315 if (status)
James Smarte2a0a9d2008-12-04 22:40:02 -05001316 goto out;
1317
James Smart6c8eea52010-04-06 14:49:53 -04001318 /* extract some info from the scsi command for pde*/
James Smarte2a0a9d2008-12-04 22:40:02 -05001319 blksize = lpfc_cmd_blksize(sc);
1320 lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag);
1321
James Smart6c8eea52010-04-06 14:49:53 -04001322 /* setup PDE5 with what we have */
1323 pde5 = (struct lpfc_pde5 *) bpl;
1324 memset(pde5, 0, sizeof(struct lpfc_pde5));
1325 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1326 pde5->reftag = reftag;
James Smarte2a0a9d2008-12-04 22:40:02 -05001327
James Smart6c8eea52010-04-06 14:49:53 -04001328 /* advance bpl and increment bde count */
1329 num_bde++;
1330 bpl++;
1331 pde6 = (struct lpfc_pde6 *) bpl;
1332
1333 /* setup PDE6 with the rest of the info */
1334 memset(pde6, 0, sizeof(struct lpfc_pde6));
1335 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1336 bf_set(pde6_optx, pde6, txop);
1337 bf_set(pde6_oprx, pde6, rxop);
1338 if (datadir == DMA_FROM_DEVICE) {
1339 bf_set(pde6_ce, pde6, 1);
1340 bf_set(pde6_re, pde6, 1);
1341 bf_set(pde6_ae, pde6, 1);
1342 }
1343 bf_set(pde6_ai, pde6, 1);
1344 bf_set(pde6_apptagval, pde6, apptagval);
1345
1346 /* advance bpl and increment bde count */
James Smarte2a0a9d2008-12-04 22:40:02 -05001347 num_bde++;
1348 bpl++;
1349
1350 /* assumption: caller has already run dma_map_sg on command data */
1351 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
1352 physaddr = sg_dma_address(sgde);
1353 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
1354 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1355 bpl->tus.f.bdeSize = sg_dma_len(sgde);
1356 if (datadir == DMA_TO_DEVICE)
1357 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1358 else
1359 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1360 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1361 bpl++;
1362 num_bde++;
1363 }
1364
1365out:
1366 return num_bde;
1367}
1368
1369/*
1370 * This function sets up buffer list for protection groups of
1371 * type LPFC_PG_TYPE_DIF_BUF
1372 *
1373 * This is usually used when DIFs are in their own buffers,
1374 * separate from the data. The HBA can then by instructed
1375 * to place the DIFs in the outgoing stream. For read operations,
1376 * The HBA could extract the DIFs and place it in DIF buffers.
1377 *
1378 * The buffer list for this type consists of one or more of the
1379 * protection groups described below:
1380 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001381 * start of first prot group --> | PDE_5 |
James Smarte2a0a9d2008-12-04 22:40:02 -05001382 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001383 * | PDE_6 |
1384 * +-------------------------+
1385 * | PDE_7 (Prot BDE) |
James Smarte2a0a9d2008-12-04 22:40:02 -05001386 * +-------------------------+
1387 * | Data BDE |
1388 * +-------------------------+
1389 * |more Data BDE's ... (opt)|
1390 * +-------------------------+
James Smart6c8eea52010-04-06 14:49:53 -04001391 * start of new prot group --> | PDE_5 |
James Smarte2a0a9d2008-12-04 22:40:02 -05001392 * +-------------------------+
1393 * | ... |
1394 * +-------------------------+
1395 *
1396 * @sc: pointer to scsi command we're working on
1397 * @bpl: pointer to buffer list for protection groups
1398 * @datacnt: number of segments of data that have been dma mapped
1399 * @protcnt: number of segment of protection data that have been dma mapped
1400 *
1401 * Note: It is assumed that both data and protection s/g buffers have been
1402 * mapped for DMA
1403 */
1404static int
1405lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1406 struct ulp_bde64 *bpl, int datacnt, int protcnt)
1407{
1408 struct scatterlist *sgde = NULL; /* s/g data entry */
1409 struct scatterlist *sgpe = NULL; /* s/g prot entry */
James Smart6c8eea52010-04-06 14:49:53 -04001410 struct lpfc_pde5 *pde5 = NULL;
1411 struct lpfc_pde6 *pde6 = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05001412 struct ulp_bde64 *prot_bde = NULL;
1413 dma_addr_t dataphysaddr, protphysaddr;
1414 unsigned short curr_data = 0, curr_prot = 0;
1415 unsigned int split_offset, protgroup_len;
1416 unsigned int protgrp_blks, protgrp_bytes;
1417 unsigned int remainder, subtotal;
James Smart6c8eea52010-04-06 14:49:53 -04001418 int status;
James Smarte2a0a9d2008-12-04 22:40:02 -05001419 int datadir = sc->sc_data_direction;
1420 unsigned char pgdone = 0, alldone = 0;
1421 unsigned blksize;
1422 uint32_t reftag;
1423 uint16_t apptagmask, apptagval;
James Smart6c8eea52010-04-06 14:49:53 -04001424 uint8_t txop, rxop;
James Smarte2a0a9d2008-12-04 22:40:02 -05001425 int num_bde = 0;
1426
1427 sgpe = scsi_prot_sglist(sc);
1428 sgde = scsi_sglist(sc);
1429
1430 if (!sgpe || !sgde) {
1431 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1432 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
1433 sgpe, sgde);
1434 return 0;
1435 }
1436
James Smart6c8eea52010-04-06 14:49:53 -04001437 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1438 if (status)
James Smarte2a0a9d2008-12-04 22:40:02 -05001439 goto out;
1440
James Smart6c8eea52010-04-06 14:49:53 -04001441 /* extract some info from the scsi command */
James Smarte2a0a9d2008-12-04 22:40:02 -05001442 blksize = lpfc_cmd_blksize(sc);
1443 lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag);
1444
1445 split_offset = 0;
1446 do {
James Smart6c8eea52010-04-06 14:49:53 -04001447 /* setup PDE5 with what we have */
1448 pde5 = (struct lpfc_pde5 *) bpl;
1449 memset(pde5, 0, sizeof(struct lpfc_pde5));
1450 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1451 pde5->reftag = reftag;
James Smarte2a0a9d2008-12-04 22:40:02 -05001452
James Smart6c8eea52010-04-06 14:49:53 -04001453 /* advance bpl and increment bde count */
1454 num_bde++;
1455 bpl++;
1456 pde6 = (struct lpfc_pde6 *) bpl;
James Smarte2a0a9d2008-12-04 22:40:02 -05001457
James Smart6c8eea52010-04-06 14:49:53 -04001458 /* setup PDE6 with the rest of the info */
1459 memset(pde6, 0, sizeof(struct lpfc_pde6));
1460 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1461 bf_set(pde6_optx, pde6, txop);
1462 bf_set(pde6_oprx, pde6, rxop);
1463 bf_set(pde6_ce, pde6, 1);
1464 bf_set(pde6_re, pde6, 1);
1465 bf_set(pde6_ae, pde6, 1);
1466 bf_set(pde6_ai, pde6, 1);
1467 bf_set(pde6_apptagval, pde6, apptagval);
1468
1469 /* advance bpl and increment bde count */
James Smarte2a0a9d2008-12-04 22:40:02 -05001470 num_bde++;
1471 bpl++;
1472
1473 /* setup the first BDE that points to protection buffer */
1474 prot_bde = (struct ulp_bde64 *) bpl;
1475 protphysaddr = sg_dma_address(sgpe);
James Smart6c8eea52010-04-06 14:49:53 -04001476 prot_bde->addrHigh = le32_to_cpu(putPaddrLow(protphysaddr));
1477 prot_bde->addrLow = le32_to_cpu(putPaddrHigh(protphysaddr));
James Smarte2a0a9d2008-12-04 22:40:02 -05001478 protgroup_len = sg_dma_len(sgpe);
1479
1480
1481 /* must be integer multiple of the DIF block length */
1482 BUG_ON(protgroup_len % 8);
1483
1484 protgrp_blks = protgroup_len / 8;
1485 protgrp_bytes = protgrp_blks * blksize;
1486
1487 prot_bde->tus.f.bdeSize = protgroup_len;
James Smart6c8eea52010-04-06 14:49:53 -04001488 prot_bde->tus.f.bdeFlags = LPFC_PDE7_DESCRIPTOR;
James Smarte2a0a9d2008-12-04 22:40:02 -05001489 prot_bde->tus.w = le32_to_cpu(bpl->tus.w);
1490
1491 curr_prot++;
1492 num_bde++;
1493
1494 /* setup BDE's for data blocks associated with DIF data */
1495 pgdone = 0;
1496 subtotal = 0; /* total bytes processed for current prot grp */
1497 while (!pgdone) {
1498 if (!sgde) {
James Smart6a9c52c2009-10-02 15:16:51 -04001499 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1500 "9065 BLKGRD:%s Invalid data segment\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05001501 __func__);
1502 return 0;
1503 }
1504 bpl++;
1505 dataphysaddr = sg_dma_address(sgde) + split_offset;
1506 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
1507 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
1508
1509 remainder = sg_dma_len(sgde) - split_offset;
1510
1511 if ((subtotal + remainder) <= protgrp_bytes) {
1512 /* we can use this whole buffer */
1513 bpl->tus.f.bdeSize = remainder;
1514 split_offset = 0;
1515
1516 if ((subtotal + remainder) == protgrp_bytes)
1517 pgdone = 1;
1518 } else {
1519 /* must split this buffer with next prot grp */
1520 bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
1521 split_offset += bpl->tus.f.bdeSize;
1522 }
1523
1524 subtotal += bpl->tus.f.bdeSize;
1525
1526 if (datadir == DMA_TO_DEVICE)
1527 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1528 else
1529 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1530 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1531
1532 num_bde++;
1533 curr_data++;
1534
1535 if (split_offset)
1536 break;
1537
1538 /* Move to the next s/g segment if possible */
1539 sgde = sg_next(sgde);
James Smart6c8eea52010-04-06 14:49:53 -04001540
James Smarte2a0a9d2008-12-04 22:40:02 -05001541 }
1542
1543 /* are we done ? */
1544 if (curr_prot == protcnt) {
1545 alldone = 1;
1546 } else if (curr_prot < protcnt) {
1547 /* advance to next prot buffer */
1548 sgpe = sg_next(sgpe);
1549 bpl++;
1550
1551 /* update the reference tag */
1552 reftag += protgrp_blks;
1553 } else {
1554 /* if we're here, we have a bug */
James Smart6a9c52c2009-10-02 15:16:51 -04001555 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1556 "9054 BLKGRD: bug in %s\n", __func__);
James Smarte2a0a9d2008-12-04 22:40:02 -05001557 }
1558
1559 } while (!alldone);
1560
1561out:
1562
James Smarte2a0a9d2008-12-04 22:40:02 -05001563 return num_bde;
1564}
1565/*
1566 * Given a SCSI command that supports DIF, determine composition of protection
1567 * groups involved in setting up buffer lists
1568 *
1569 * Returns:
1570 * for DIF (for both read and write)
1571 * */
1572static int
1573lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
1574{
1575 int ret = LPFC_PG_TYPE_INVALID;
1576 unsigned char op = scsi_get_prot_op(sc);
1577
1578 switch (op) {
1579 case SCSI_PROT_READ_STRIP:
1580 case SCSI_PROT_WRITE_INSERT:
1581 ret = LPFC_PG_TYPE_NO_DIF;
1582 break;
1583 case SCSI_PROT_READ_INSERT:
1584 case SCSI_PROT_WRITE_STRIP:
1585 case SCSI_PROT_READ_PASS:
1586 case SCSI_PROT_WRITE_PASS:
James Smarte2a0a9d2008-12-04 22:40:02 -05001587 ret = LPFC_PG_TYPE_DIF_BUF;
1588 break;
1589 default:
1590 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1591 "9021 Unsupported protection op:%d\n", op);
1592 break;
1593 }
1594
1595 return ret;
1596}
1597
1598/*
1599 * This is the protection/DIF aware version of
1600 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
1601 * two functions eventually, but for now, it's here
1602 */
1603static int
1604lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba,
1605 struct lpfc_scsi_buf *lpfc_cmd)
1606{
1607 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
1608 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
1609 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
1610 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
1611 uint32_t num_bde = 0;
1612 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
1613 int prot_group_type = 0;
1614 int diflen, fcpdl;
1615 unsigned blksize;
1616
1617 /*
1618 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
1619 * fcp_rsp regions to the first data bde entry
1620 */
1621 bpl += 2;
1622 if (scsi_sg_count(scsi_cmnd)) {
1623 /*
1624 * The driver stores the segment count returned from pci_map_sg
1625 * because this a count of dma-mappings used to map the use_sg
1626 * pages. They are not guaranteed to be the same for those
1627 * architectures that implement an IOMMU.
1628 */
1629 datasegcnt = dma_map_sg(&phba->pcidev->dev,
1630 scsi_sglist(scsi_cmnd),
1631 scsi_sg_count(scsi_cmnd), datadir);
1632 if (unlikely(!datasegcnt))
1633 return 1;
1634
1635 lpfc_cmd->seg_cnt = datasegcnt;
1636 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04001637 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1638 "9067 BLKGRD: %s: Too many sg segments"
1639 " from dma_map_sg. Config %d, seg_cnt"
1640 " %d\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05001641 __func__, phba->cfg_sg_seg_cnt,
1642 lpfc_cmd->seg_cnt);
1643 scsi_dma_unmap(scsi_cmnd);
1644 return 1;
1645 }
1646
1647 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
1648
1649 switch (prot_group_type) {
1650 case LPFC_PG_TYPE_NO_DIF:
1651 num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
1652 datasegcnt);
Adam Buchbinderc9404c92009-12-18 15:40:42 -05001653 /* we should have 2 or more entries in buffer list */
James Smarte2a0a9d2008-12-04 22:40:02 -05001654 if (num_bde < 2)
1655 goto err;
1656 break;
1657 case LPFC_PG_TYPE_DIF_BUF:{
1658 /*
1659 * This type indicates that protection buffers are
1660 * passed to the driver, so that needs to be prepared
1661 * for DMA
1662 */
1663 protsegcnt = dma_map_sg(&phba->pcidev->dev,
1664 scsi_prot_sglist(scsi_cmnd),
1665 scsi_prot_sg_count(scsi_cmnd), datadir);
1666 if (unlikely(!protsegcnt)) {
1667 scsi_dma_unmap(scsi_cmnd);
1668 return 1;
1669 }
1670
1671 lpfc_cmd->prot_seg_cnt = protsegcnt;
1672 if (lpfc_cmd->prot_seg_cnt
1673 > phba->cfg_prot_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04001674 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1675 "9068 BLKGRD: %s: Too many prot sg "
1676 "segments from dma_map_sg. Config %d,"
James Smarte2a0a9d2008-12-04 22:40:02 -05001677 "prot_seg_cnt %d\n", __func__,
1678 phba->cfg_prot_sg_seg_cnt,
1679 lpfc_cmd->prot_seg_cnt);
1680 dma_unmap_sg(&phba->pcidev->dev,
1681 scsi_prot_sglist(scsi_cmnd),
1682 scsi_prot_sg_count(scsi_cmnd),
1683 datadir);
1684 scsi_dma_unmap(scsi_cmnd);
1685 return 1;
1686 }
1687
1688 num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
1689 datasegcnt, protsegcnt);
Adam Buchbinderc9404c92009-12-18 15:40:42 -05001690 /* we should have 3 or more entries in buffer list */
James Smarte2a0a9d2008-12-04 22:40:02 -05001691 if (num_bde < 3)
1692 goto err;
1693 break;
1694 }
1695 case LPFC_PG_TYPE_INVALID:
1696 default:
1697 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1698 "9022 Unexpected protection group %i\n",
1699 prot_group_type);
1700 return 1;
1701 }
1702 }
1703
1704 /*
1705 * Finish initializing those IOCB fields that are dependent on the
1706 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
1707 * reinitialized since all iocb memory resources are used many times
1708 * for transmit, receive, and continuation bpl's.
1709 */
1710 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
1711 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
1712 iocb_cmd->ulpBdeCount = 1;
1713 iocb_cmd->ulpLe = 1;
1714
1715 fcpdl = scsi_bufflen(scsi_cmnd);
1716
1717 if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) {
1718 /*
1719 * We are in DIF Type 1 mode
1720 * Every data block has a 8 byte DIF (trailer)
1721 * attached to it. Must ajust FCP data length
1722 */
1723 blksize = lpfc_cmd_blksize(scsi_cmnd);
1724 diflen = (fcpdl / blksize) * 8;
1725 fcpdl += diflen;
1726 }
1727 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
1728
1729 /*
1730 * Due to difference in data length between DIF/non-DIF paths,
1731 * we need to set word 4 of IOCB here
1732 */
1733 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
1734
1735 return 0;
1736err:
1737 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1738 "9023 Could not setup all needed BDE's"
1739 "prot_group_type=%d, num_bde=%d\n",
1740 prot_group_type, num_bde);
1741 return 1;
1742}
1743
1744/*
1745 * This function checks for BlockGuard errors detected by
1746 * the HBA. In case of errors, the ASC/ASCQ fields in the
1747 * sense buffer will be set accordingly, paired with
1748 * ILLEGAL_REQUEST to signal to the kernel that the HBA
1749 * detected corruption.
1750 *
1751 * Returns:
1752 * 0 - No error found
1753 * 1 - BlockGuard error found
1754 * -1 - Internal error (bad profile, ...etc)
1755 */
1756static int
1757lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
1758 struct lpfc_iocbq *pIocbOut)
1759{
1760 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
1761 struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
1762 int ret = 0;
1763 uint32_t bghm = bgf->bghm;
1764 uint32_t bgstat = bgf->bgstat;
1765 uint64_t failing_sector = 0;
1766
James Smart6a9c52c2009-10-02 15:16:51 -04001767 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9069 BLKGRD: BG ERROR in cmd"
1768 " 0x%x lba 0x%llx blk cnt 0x%x "
James Smarte2a0a9d2008-12-04 22:40:02 -05001769 "bgstat=0x%x bghm=0x%x\n",
James Smart87b5c322008-12-16 10:34:09 -05001770 cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd),
Tejun Heo83096eb2009-05-07 22:24:39 +09001771 blk_rq_sectors(cmd->request), bgstat, bghm);
James Smarte2a0a9d2008-12-04 22:40:02 -05001772
1773 spin_lock(&_dump_buf_lock);
1774 if (!_dump_buf_done) {
James Smart6a9c52c2009-10-02 15:16:51 -04001775 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving"
1776 " Data for %u blocks to debugfs\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05001777 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
James Smart6a9c52c2009-10-02 15:16:51 -04001778 lpfc_debug_save_data(phba, cmd);
James Smarte2a0a9d2008-12-04 22:40:02 -05001779
1780 /* If we have a prot sgl, save the DIF buffer */
1781 if (lpfc_prot_group_type(phba, cmd) ==
1782 LPFC_PG_TYPE_DIF_BUF) {
James Smart6a9c52c2009-10-02 15:16:51 -04001783 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: "
1784 "Saving DIF for %u blocks to debugfs\n",
1785 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
1786 lpfc_debug_save_dif(phba, cmd);
James Smarte2a0a9d2008-12-04 22:40:02 -05001787 }
1788
1789 _dump_buf_done = 1;
1790 }
1791 spin_unlock(&_dump_buf_lock);
1792
1793 if (lpfc_bgs_get_invalid_prof(bgstat)) {
1794 cmd->result = ScsiResult(DID_ERROR, 0);
James Smart6a9c52c2009-10-02 15:16:51 -04001795 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9072 BLKGRD: Invalid"
1796 " BlockGuard profile. bgstat:0x%x\n",
1797 bgstat);
James Smarte2a0a9d2008-12-04 22:40:02 -05001798 ret = (-1);
1799 goto out;
1800 }
1801
1802 if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
1803 cmd->result = ScsiResult(DID_ERROR, 0);
James Smart6a9c52c2009-10-02 15:16:51 -04001804 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9073 BLKGRD: "
1805 "Invalid BlockGuard DIF Block. bgstat:0x%x\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05001806 bgstat);
1807 ret = (-1);
1808 goto out;
1809 }
1810
1811 if (lpfc_bgs_get_guard_err(bgstat)) {
1812 ret = 1;
1813
1814 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1815 0x10, 0x1);
Martin K. Petersen1c9fbaf2009-01-04 03:14:11 -05001816 cmd->result = DRIVER_SENSE << 24
James Smarte2a0a9d2008-12-04 22:40:02 -05001817 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
1818 phba->bg_guard_err_cnt++;
James Smart6a9c52c2009-10-02 15:16:51 -04001819 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1820 "9055 BLKGRD: guard_tag error\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05001821 }
1822
1823 if (lpfc_bgs_get_reftag_err(bgstat)) {
1824 ret = 1;
1825
1826 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1827 0x10, 0x3);
Martin K. Petersen1c9fbaf2009-01-04 03:14:11 -05001828 cmd->result = DRIVER_SENSE << 24
James Smarte2a0a9d2008-12-04 22:40:02 -05001829 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
1830
1831 phba->bg_reftag_err_cnt++;
James Smart6a9c52c2009-10-02 15:16:51 -04001832 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1833 "9056 BLKGRD: ref_tag error\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05001834 }
1835
1836 if (lpfc_bgs_get_apptag_err(bgstat)) {
1837 ret = 1;
1838
1839 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1840 0x10, 0x2);
Martin K. Petersen1c9fbaf2009-01-04 03:14:11 -05001841 cmd->result = DRIVER_SENSE << 24
James Smarte2a0a9d2008-12-04 22:40:02 -05001842 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
1843
1844 phba->bg_apptag_err_cnt++;
James Smart6a9c52c2009-10-02 15:16:51 -04001845 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1846 "9061 BLKGRD: app_tag error\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05001847 }
1848
1849 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
1850 /*
1851 * setup sense data descriptor 0 per SPC-4 as an information
1852 * field, and put the failing LBA in it
1853 */
1854 cmd->sense_buffer[8] = 0; /* Information */
1855 cmd->sense_buffer[9] = 0xa; /* Add. length */
David Howells2344b5b2009-04-14 17:08:34 +01001856 bghm /= cmd->device->sector_size;
James Smarte2a0a9d2008-12-04 22:40:02 -05001857
1858 failing_sector = scsi_get_lba(cmd);
1859 failing_sector += bghm;
1860
1861 put_unaligned_be64(failing_sector, &cmd->sense_buffer[10]);
1862 }
1863
1864 if (!ret) {
1865 /* No error was reported - problem in FW? */
1866 cmd->result = ScsiResult(DID_ERROR, 0);
James Smart6a9c52c2009-10-02 15:16:51 -04001867 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1868 "9057 BLKGRD: no errors reported!\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05001869 }
1870
1871out:
1872 return ret;
1873}
1874
James Smartea2151b2008-09-07 11:52:10 -04001875/**
James Smartda0436e2009-05-22 14:51:39 -04001876 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
1877 * @phba: The Hba for which this call is being executed.
1878 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1879 *
1880 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1881 * field of @lpfc_cmd for device with SLI-4 interface spec.
1882 *
1883 * Return codes:
James Smart6c8eea52010-04-06 14:49:53 -04001884 * 1 - Error
1885 * 0 - Success
James Smartda0436e2009-05-22 14:51:39 -04001886 **/
1887static int
1888lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1889{
1890 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
1891 struct scatterlist *sgel = NULL;
1892 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
1893 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
1894 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
1895 dma_addr_t physaddr;
1896 uint32_t num_bde = 0;
1897 uint32_t dma_len;
1898 uint32_t dma_offset = 0;
1899 int nseg;
1900
1901 /*
1902 * There are three possibilities here - use scatter-gather segment, use
1903 * the single mapping, or neither. Start the lpfc command prep by
1904 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1905 * data bde entry.
1906 */
1907 if (scsi_sg_count(scsi_cmnd)) {
1908 /*
1909 * The driver stores the segment count returned from pci_map_sg
1910 * because this a count of dma-mappings used to map the use_sg
1911 * pages. They are not guaranteed to be the same for those
1912 * architectures that implement an IOMMU.
1913 */
1914
1915 nseg = scsi_dma_map(scsi_cmnd);
1916 if (unlikely(!nseg))
1917 return 1;
1918 sgl += 1;
1919 /* clear the last flag in the fcp_rsp map entry */
1920 sgl->word2 = le32_to_cpu(sgl->word2);
1921 bf_set(lpfc_sli4_sge_last, sgl, 0);
1922 sgl->word2 = cpu_to_le32(sgl->word2);
1923 sgl += 1;
1924
1925 lpfc_cmd->seg_cnt = nseg;
1926 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
James Smart6a9c52c2009-10-02 15:16:51 -04001927 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
1928 " %s: Too many sg segments from "
1929 "dma_map_sg. Config %d, seg_cnt %d\n",
1930 __func__, phba->cfg_sg_seg_cnt,
James Smartda0436e2009-05-22 14:51:39 -04001931 lpfc_cmd->seg_cnt);
1932 scsi_dma_unmap(scsi_cmnd);
1933 return 1;
1934 }
1935
1936 /*
1937 * The driver established a maximum scatter-gather segment count
1938 * during probe that limits the number of sg elements in any
1939 * single scsi command. Just run through the seg_cnt and format
1940 * the sge's.
1941 * When using SLI-3 the driver will try to fit all the BDEs into
1942 * the IOCB. If it can't then the BDEs get added to a BPL as it
1943 * does for SLI-2 mode.
1944 */
1945 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
1946 physaddr = sg_dma_address(sgel);
1947 dma_len = sg_dma_len(sgel);
James Smartda0436e2009-05-22 14:51:39 -04001948 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
1949 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
1950 if ((num_bde + 1) == nseg)
1951 bf_set(lpfc_sli4_sge_last, sgl, 1);
1952 else
1953 bf_set(lpfc_sli4_sge_last, sgl, 0);
1954 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
1955 sgl->word2 = cpu_to_le32(sgl->word2);
James Smart28baac72010-02-12 14:42:03 -05001956 sgl->sge_len = cpu_to_le32(dma_len);
James Smartda0436e2009-05-22 14:51:39 -04001957 dma_offset += dma_len;
1958 sgl++;
1959 }
1960 } else {
1961 sgl += 1;
1962 /* clear the last flag in the fcp_rsp map entry */
1963 sgl->word2 = le32_to_cpu(sgl->word2);
1964 bf_set(lpfc_sli4_sge_last, sgl, 1);
1965 sgl->word2 = cpu_to_le32(sgl->word2);
1966 }
1967
1968 /*
1969 * Finish initializing those IOCB fields that are dependent on the
1970 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1971 * explicitly reinitialized.
1972 * all iocb memory resources are reused.
1973 */
1974 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
1975
1976 /*
1977 * Due to difference in data length between DIF/non-DIF paths,
1978 * we need to set word 4 of IOCB here
1979 */
1980 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
1981 return 0;
1982}
1983
1984/**
James Smart3772a992009-05-22 14:50:54 -04001985 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
1986 * @phba: The Hba for which this call is being executed.
1987 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1988 *
1989 * This routine wraps the actual DMA mapping function pointer from the
1990 * lpfc_hba struct.
1991 *
1992 * Return codes:
James Smart6c8eea52010-04-06 14:49:53 -04001993 * 1 - Error
1994 * 0 - Success
James Smart3772a992009-05-22 14:50:54 -04001995 **/
1996static inline int
1997lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1998{
1999 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
2000}
2001
2002/**
James Smart3621a712009-04-06 18:47:14 -04002003 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
James Smartea2151b2008-09-07 11:52:10 -04002004 * @phba: Pointer to hba context object.
2005 * @vport: Pointer to vport object.
2006 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
2007 * @rsp_iocb: Pointer to response iocb object which reported error.
2008 *
2009 * This function posts an event when there is a SCSI command reporting
2010 * error from the scsi device.
2011 **/
2012static void
2013lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
2014 struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
2015 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
2016 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
2017 uint32_t resp_info = fcprsp->rspStatus2;
2018 uint32_t scsi_status = fcprsp->rspStatus3;
2019 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
2020 struct lpfc_fast_path_event *fast_path_evt = NULL;
2021 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
2022 unsigned long flags;
2023
2024 /* If there is queuefull or busy condition send a scsi event */
2025 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
2026 (cmnd->result == SAM_STAT_BUSY)) {
2027 fast_path_evt = lpfc_alloc_fast_evt(phba);
2028 if (!fast_path_evt)
2029 return;
2030 fast_path_evt->un.scsi_evt.event_type =
2031 FC_REG_SCSI_EVENT;
2032 fast_path_evt->un.scsi_evt.subcategory =
2033 (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
2034 LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
2035 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
2036 memcpy(&fast_path_evt->un.scsi_evt.wwpn,
2037 &pnode->nlp_portname, sizeof(struct lpfc_name));
2038 memcpy(&fast_path_evt->un.scsi_evt.wwnn,
2039 &pnode->nlp_nodename, sizeof(struct lpfc_name));
2040 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
2041 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
2042 fast_path_evt = lpfc_alloc_fast_evt(phba);
2043 if (!fast_path_evt)
2044 return;
2045 fast_path_evt->un.check_cond_evt.scsi_event.event_type =
2046 FC_REG_SCSI_EVENT;
2047 fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
2048 LPFC_EVENT_CHECK_COND;
2049 fast_path_evt->un.check_cond_evt.scsi_event.lun =
2050 cmnd->device->lun;
2051 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
2052 &pnode->nlp_portname, sizeof(struct lpfc_name));
2053 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
2054 &pnode->nlp_nodename, sizeof(struct lpfc_name));
2055 fast_path_evt->un.check_cond_evt.sense_key =
2056 cmnd->sense_buffer[2] & 0xf;
2057 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
2058 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
2059 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
2060 fcpi_parm &&
2061 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
2062 ((scsi_status == SAM_STAT_GOOD) &&
2063 !(resp_info & (RESID_UNDER | RESID_OVER))))) {
2064 /*
2065 * If status is good or resid does not match with fcp_param and
2066 * there is valid fcpi_parm, then there is a read_check error
2067 */
2068 fast_path_evt = lpfc_alloc_fast_evt(phba);
2069 if (!fast_path_evt)
2070 return;
2071 fast_path_evt->un.read_check_error.header.event_type =
2072 FC_REG_FABRIC_EVENT;
2073 fast_path_evt->un.read_check_error.header.subcategory =
2074 LPFC_EVENT_FCPRDCHKERR;
2075 memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
2076 &pnode->nlp_portname, sizeof(struct lpfc_name));
2077 memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
2078 &pnode->nlp_nodename, sizeof(struct lpfc_name));
2079 fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
2080 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
2081 fast_path_evt->un.read_check_error.fcpiparam =
2082 fcpi_parm;
2083 } else
2084 return;
2085
2086 fast_path_evt->vport = vport;
2087 spin_lock_irqsave(&phba->hbalock, flags);
2088 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
2089 spin_unlock_irqrestore(&phba->hbalock, flags);
2090 lpfc_worker_wake_up(phba);
2091 return;
2092}
James Smart9bad7672008-12-04 22:39:02 -05002093
2094/**
James Smartf1126682009-06-10 17:22:44 -04002095 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
James Smart3772a992009-05-22 14:50:54 -04002096 * @phba: The HBA for which this call is being executed.
James Smart9bad7672008-12-04 22:39:02 -05002097 * @psb: The scsi buffer which is going to be un-mapped.
2098 *
2099 * This routine does DMA un-mapping of scatter gather list of scsi command
James Smart3772a992009-05-22 14:50:54 -04002100 * field of @lpfc_cmd for device with SLI-3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05002101 **/
dea31012005-04-17 16:05:31 -05002102static void
James Smartf1126682009-06-10 17:22:44 -04002103lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
James Smartbcf4dbf2006-07-06 15:50:08 -04002104{
2105 /*
2106 * There are only two special cases to consider. (1) the scsi command
2107 * requested scatter-gather usage or (2) the scsi command allocated
2108 * a request buffer, but did not request use_sg. There is a third
2109 * case, but it does not require resource deallocation.
2110 */
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002111 if (psb->seg_cnt > 0)
2112 scsi_dma_unmap(psb->pCmd);
James Smarte2a0a9d2008-12-04 22:40:02 -05002113 if (psb->prot_seg_cnt > 0)
2114 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
2115 scsi_prot_sg_count(psb->pCmd),
2116 psb->pCmd->sc_data_direction);
James Smartbcf4dbf2006-07-06 15:50:08 -04002117}
2118
James Smart9bad7672008-12-04 22:39:02 -05002119/**
James Smart3621a712009-04-06 18:47:14 -04002120 * lpfc_handler_fcp_err - FCP response handler
James Smart9bad7672008-12-04 22:39:02 -05002121 * @vport: The virtual port for which this call is being executed.
2122 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2123 * @rsp_iocb: The response IOCB which contains FCP error.
2124 *
2125 * This routine is called to process response IOCB with status field
2126 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
2127 * based upon SCSI and FCP error.
2128 **/
James Smartbcf4dbf2006-07-06 15:50:08 -04002129static void
James Smart2e0fef82007-06-17 19:56:36 -05002130lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
2131 struct lpfc_iocbq *rsp_iocb)
dea31012005-04-17 16:05:31 -05002132{
2133 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
2134 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
2135 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
James Smart7054a602007-04-25 09:52:34 -04002136 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
dea31012005-04-17 16:05:31 -05002137 uint32_t resp_info = fcprsp->rspStatus2;
2138 uint32_t scsi_status = fcprsp->rspStatus3;
James Smartc7743952006-12-02 13:34:42 -05002139 uint32_t *lp;
dea31012005-04-17 16:05:31 -05002140 uint32_t host_status = DID_OK;
2141 uint32_t rsplen = 0;
James Smartc7743952006-12-02 13:34:42 -05002142 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
dea31012005-04-17 16:05:31 -05002143
James Smartea2151b2008-09-07 11:52:10 -04002144
dea31012005-04-17 16:05:31 -05002145 /*
2146 * If this is a task management command, there is no
2147 * scsi packet associated with this lpfc_cmd. The driver
2148 * consumes it.
2149 */
2150 if (fcpcmd->fcpCntl2) {
2151 scsi_status = 0;
2152 goto out;
2153 }
2154
James Smart6a9c52c2009-10-02 15:16:51 -04002155 if (resp_info & RSP_LEN_VALID) {
2156 rsplen = be32_to_cpu(fcprsp->rspRspLen);
James Smarte40a02c2010-02-26 14:13:54 -05002157 if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
James Smart6a9c52c2009-10-02 15:16:51 -04002158 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
2159 "2719 Invalid response length: "
2160 "tgt x%x lun x%x cmnd x%x rsplen x%x\n",
2161 cmnd->device->id,
2162 cmnd->device->lun, cmnd->cmnd[0],
2163 rsplen);
2164 host_status = DID_ERROR;
2165 goto out;
2166 }
James Smarte40a02c2010-02-26 14:13:54 -05002167 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
2168 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
2169 "2757 Protocol failure detected during "
2170 "processing of FCP I/O op: "
2171 "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n",
2172 cmnd->device->id,
2173 cmnd->device->lun, cmnd->cmnd[0],
2174 fcprsp->rspInfo3);
2175 host_status = DID_ERROR;
2176 goto out;
2177 }
James Smart6a9c52c2009-10-02 15:16:51 -04002178 }
2179
James Smartc7743952006-12-02 13:34:42 -05002180 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
2181 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
2182 if (snslen > SCSI_SENSE_BUFFERSIZE)
2183 snslen = SCSI_SENSE_BUFFERSIZE;
2184
2185 if (resp_info & RSP_LEN_VALID)
2186 rsplen = be32_to_cpu(fcprsp->rspRspLen);
2187 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
2188 }
2189 lp = (uint32_t *)cmnd->sense_buffer;
2190
2191 if (!scsi_status && (resp_info & RESID_UNDER))
2192 logit = LOG_FCP;
2193
James Smarte8b62012007-08-02 11:10:09 -04002194 lpfc_printf_vlog(vport, KERN_WARNING, logit,
James Smarte2a0a9d2008-12-04 22:40:02 -05002195 "9024 FCP command x%x failed: x%x SNS x%x x%x "
James Smarte8b62012007-08-02 11:10:09 -04002196 "Data: x%x x%x x%x x%x x%x\n",
2197 cmnd->cmnd[0], scsi_status,
2198 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
2199 be32_to_cpu(fcprsp->rspResId),
2200 be32_to_cpu(fcprsp->rspSnsLen),
2201 be32_to_cpu(fcprsp->rspRspLen),
2202 fcprsp->rspInfo3);
dea31012005-04-17 16:05:31 -05002203
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002204 scsi_set_resid(cmnd, 0);
dea31012005-04-17 16:05:31 -05002205 if (resp_info & RESID_UNDER) {
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002206 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
dea31012005-04-17 16:05:31 -05002207
James Smarte8b62012007-08-02 11:10:09 -04002208 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
James Smarte2a0a9d2008-12-04 22:40:02 -05002209 "9025 FCP Read Underrun, expected %d, "
James Smarte8b62012007-08-02 11:10:09 -04002210 "residual %d Data: x%x x%x x%x\n",
2211 be32_to_cpu(fcpcmd->fcpDl),
2212 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
2213 cmnd->underflow);
dea31012005-04-17 16:05:31 -05002214
2215 /*
James Smart7054a602007-04-25 09:52:34 -04002216 * If there is an under run check if under run reported by
2217 * storage array is same as the under run reported by HBA.
2218 * If this is not same, there is a dropped frame.
2219 */
2220 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
2221 fcpi_parm &&
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002222 (scsi_get_resid(cmnd) != fcpi_parm)) {
James Smarte8b62012007-08-02 11:10:09 -04002223 lpfc_printf_vlog(vport, KERN_WARNING,
2224 LOG_FCP | LOG_FCP_ERROR,
James Smarte2a0a9d2008-12-04 22:40:02 -05002225 "9026 FCP Read Check Error "
James Smarte8b62012007-08-02 11:10:09 -04002226 "and Underrun Data: x%x x%x x%x x%x\n",
2227 be32_to_cpu(fcpcmd->fcpDl),
2228 scsi_get_resid(cmnd), fcpi_parm,
2229 cmnd->cmnd[0]);
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002230 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
James Smart7054a602007-04-25 09:52:34 -04002231 host_status = DID_ERROR;
2232 }
2233 /*
dea31012005-04-17 16:05:31 -05002234 * The cmnd->underflow is the minimum number of bytes that must
2235 * be transfered for this command. Provided a sense condition
2236 * is not present, make sure the actual amount transferred is at
2237 * least the underflow value or fail.
2238 */
2239 if (!(resp_info & SNS_LEN_VALID) &&
2240 (scsi_status == SAM_STAT_GOOD) &&
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002241 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
2242 < cmnd->underflow)) {
James Smarte8b62012007-08-02 11:10:09 -04002243 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
James Smarte2a0a9d2008-12-04 22:40:02 -05002244 "9027 FCP command x%x residual "
James Smarte8b62012007-08-02 11:10:09 -04002245 "underrun converted to error "
2246 "Data: x%x x%x x%x\n",
James Smart66dbfbe2007-08-05 06:08:38 -04002247 cmnd->cmnd[0], scsi_bufflen(cmnd),
James Smarte8b62012007-08-02 11:10:09 -04002248 scsi_get_resid(cmnd), cmnd->underflow);
dea31012005-04-17 16:05:31 -05002249 host_status = DID_ERROR;
2250 }
2251 } else if (resp_info & RESID_OVER) {
James Smarte8b62012007-08-02 11:10:09 -04002252 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
James Smarte2a0a9d2008-12-04 22:40:02 -05002253 "9028 FCP command x%x residual overrun error. "
James Smarte4e74272009-07-19 10:01:38 -04002254 "Data: x%x x%x\n", cmnd->cmnd[0],
James Smarte8b62012007-08-02 11:10:09 -04002255 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
dea31012005-04-17 16:05:31 -05002256 host_status = DID_ERROR;
2257
2258 /*
2259 * Check SLI validation that all the transfer was actually done
2260 * (fcpi_parm should be zero). Apply check only to reads.
2261 */
2262 } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm &&
2263 (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
James Smarte8b62012007-08-02 11:10:09 -04002264 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
James Smarte2a0a9d2008-12-04 22:40:02 -05002265 "9029 FCP Read Check Error Data: "
James Smarte8b62012007-08-02 11:10:09 -04002266 "x%x x%x x%x x%x\n",
2267 be32_to_cpu(fcpcmd->fcpDl),
2268 be32_to_cpu(fcprsp->rspResId),
2269 fcpi_parm, cmnd->cmnd[0]);
dea31012005-04-17 16:05:31 -05002270 host_status = DID_ERROR;
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002271 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
dea31012005-04-17 16:05:31 -05002272 }
2273
2274 out:
2275 cmnd->result = ScsiResult(host_status, scsi_status);
James Smartea2151b2008-09-07 11:52:10 -04002276 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
dea31012005-04-17 16:05:31 -05002277}
2278
James Smart9bad7672008-12-04 22:39:02 -05002279/**
James Smart3621a712009-04-06 18:47:14 -04002280 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
James Smart9bad7672008-12-04 22:39:02 -05002281 * @phba: The Hba for which this call is being executed.
2282 * @pIocbIn: The command IOCBQ for the scsi cmnd.
James Smart3772a992009-05-22 14:50:54 -04002283 * @pIocbOut: The response IOCBQ for the scsi cmnd.
James Smart9bad7672008-12-04 22:39:02 -05002284 *
2285 * This routine assigns scsi command result by looking into response IOCB
2286 * status field appropriately. This routine handles QUEUE FULL condition as
2287 * well by ramping down device queue depth.
2288 **/
dea31012005-04-17 16:05:31 -05002289static void
2290lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
2291 struct lpfc_iocbq *pIocbOut)
2292{
2293 struct lpfc_scsi_buf *lpfc_cmd =
2294 (struct lpfc_scsi_buf *) pIocbIn->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002295 struct lpfc_vport *vport = pIocbIn->vport;
dea31012005-04-17 16:05:31 -05002296 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
2297 struct lpfc_nodelist *pnode = rdata->pnode;
2298 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002299 int result;
James Smarta257bf92009-04-06 18:48:10 -04002300 struct scsi_device *tmp_sdev;
James Smart5ffc2662009-11-18 15:39:44 -05002301 int depth;
James Smartfa61a542008-01-11 01:52:42 -05002302 unsigned long flags;
James Smartea2151b2008-09-07 11:52:10 -04002303 struct lpfc_fast_path_event *fast_path_evt;
James Smarta257bf92009-04-06 18:48:10 -04002304 struct Scsi_Host *shost = cmd->device->host;
2305 uint32_t queue_depth, scsi_id;
dea31012005-04-17 16:05:31 -05002306
2307 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
2308 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
James Smart341af102010-01-26 23:07:37 -05002309 /* pick up SLI4 exhange busy status from HBA */
2310 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
2311
James Smart109f6ed2008-12-04 22:39:08 -05002312 if (pnode && NLP_CHK_NODE_ACT(pnode))
2313 atomic_dec(&pnode->cmd_pending);
dea31012005-04-17 16:05:31 -05002314
2315 if (lpfc_cmd->status) {
2316 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
2317 (lpfc_cmd->result & IOERR_DRVR_MASK))
2318 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
2319 else if (lpfc_cmd->status >= IOSTAT_CNT)
2320 lpfc_cmd->status = IOSTAT_DEFAULT;
2321
James Smarte8b62012007-08-02 11:10:09 -04002322 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
James Smarte2a0a9d2008-12-04 22:40:02 -05002323 "9030 FCP cmd x%x failed <%d/%d> "
James Smarte8b62012007-08-02 11:10:09 -04002324 "status: x%x result: x%x Data: x%x x%x\n",
2325 cmd->cmnd[0],
2326 cmd->device ? cmd->device->id : 0xffff,
2327 cmd->device ? cmd->device->lun : 0xffff,
2328 lpfc_cmd->status, lpfc_cmd->result,
2329 pIocbOut->iocb.ulpContext,
2330 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05002331
2332 switch (lpfc_cmd->status) {
2333 case IOSTAT_FCP_RSP_ERROR:
2334 /* Call FCP RSP handler to determine result */
James Smart2e0fef82007-06-17 19:56:36 -05002335 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
dea31012005-04-17 16:05:31 -05002336 break;
2337 case IOSTAT_NPORT_BSY:
2338 case IOSTAT_FABRIC_BSY:
James Smart0f1f53a2008-08-24 21:50:18 -04002339 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
James Smartea2151b2008-09-07 11:52:10 -04002340 fast_path_evt = lpfc_alloc_fast_evt(phba);
2341 if (!fast_path_evt)
2342 break;
2343 fast_path_evt->un.fabric_evt.event_type =
2344 FC_REG_FABRIC_EVENT;
2345 fast_path_evt->un.fabric_evt.subcategory =
2346 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
2347 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
2348 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
2349 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
2350 &pnode->nlp_portname,
2351 sizeof(struct lpfc_name));
2352 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
2353 &pnode->nlp_nodename,
2354 sizeof(struct lpfc_name));
2355 }
2356 fast_path_evt->vport = vport;
2357 fast_path_evt->work_evt.evt =
2358 LPFC_EVT_FASTPATH_MGMT_EVT;
2359 spin_lock_irqsave(&phba->hbalock, flags);
2360 list_add_tail(&fast_path_evt->work_evt.evt_listp,
2361 &phba->work_list);
2362 spin_unlock_irqrestore(&phba->hbalock, flags);
2363 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05002364 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002365 case IOSTAT_LOCAL_REJECT:
James Smartd7c255b2008-08-24 21:50:00 -04002366 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
James Smart92d7f7b2007-06-17 19:56:38 -05002367 lpfc_cmd->result == IOERR_NO_RESOURCES ||
James Smartb92938b2010-06-07 15:24:12 -04002368 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
2369 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
James Smart92d7f7b2007-06-17 19:56:38 -05002370 cmd->result = ScsiResult(DID_REQUEUE, 0);
James Smart58da1ff2008-04-07 10:15:56 -04002371 break;
James Smarte2a0a9d2008-12-04 22:40:02 -05002372 }
2373
2374 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
2375 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
2376 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
2377 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
2378 /*
2379 * This is a response for a BG enabled
2380 * cmd. Parse BG error
2381 */
2382 lpfc_parse_bg_err(phba, lpfc_cmd,
2383 pIocbOut);
2384 break;
2385 } else {
2386 lpfc_printf_vlog(vport, KERN_WARNING,
2387 LOG_BG,
2388 "9031 non-zero BGSTAT "
James Smart6a9c52c2009-10-02 15:16:51 -04002389 "on unprotected cmd\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05002390 }
2391 }
2392
2393 /* else: fall through */
dea31012005-04-17 16:05:31 -05002394 default:
2395 cmd->result = ScsiResult(DID_ERROR, 0);
2396 break;
2397 }
2398
James Smart58da1ff2008-04-07 10:15:56 -04002399 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002400 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
James Smart0f1f53a2008-08-24 21:50:18 -04002401 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
2402 SAM_STAT_BUSY);
dea31012005-04-17 16:05:31 -05002403 } else {
2404 cmd->result = ScsiResult(DID_OK, 0);
2405 }
2406
2407 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
2408 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
2409
James Smarte8b62012007-08-02 11:10:09 -04002410 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
2411 "0710 Iodone <%d/%d> cmd %p, error "
2412 "x%x SNS x%x x%x Data: x%x x%x\n",
2413 cmd->device->id, cmd->device->lun, cmd,
2414 cmd->result, *lp, *(lp + 3), cmd->retries,
2415 scsi_get_resid(cmd));
dea31012005-04-17 16:05:31 -05002416 }
2417
James Smartea2151b2008-09-07 11:52:10 -04002418 lpfc_update_stats(phba, lpfc_cmd);
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002419 result = cmd->result;
James Smart977b5a02008-09-07 11:52:04 -04002420 if (vport->cfg_max_scsicmpl_time &&
2421 time_after(jiffies, lpfc_cmd->start_time +
2422 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
James Smarta257bf92009-04-06 18:48:10 -04002423 spin_lock_irqsave(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002424 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
2425 if (pnode->cmd_qdepth >
2426 atomic_read(&pnode->cmd_pending) &&
2427 (atomic_read(&pnode->cmd_pending) >
2428 LPFC_MIN_TGT_QDEPTH) &&
2429 ((cmd->cmnd[0] == READ_10) ||
2430 (cmd->cmnd[0] == WRITE_10)))
2431 pnode->cmd_qdepth =
2432 atomic_read(&pnode->cmd_pending);
James Smart977b5a02008-09-07 11:52:04 -04002433
James Smart109f6ed2008-12-04 22:39:08 -05002434 pnode->last_change_time = jiffies;
2435 }
James Smarta257bf92009-04-06 18:48:10 -04002436 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002437 } else if (pnode && NLP_CHK_NODE_ACT(pnode)) {
2438 if ((pnode->cmd_qdepth < LPFC_MAX_TGT_QDEPTH) &&
James Smart977b5a02008-09-07 11:52:04 -04002439 time_after(jiffies, pnode->last_change_time +
James Smart109f6ed2008-12-04 22:39:08 -05002440 msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) {
James Smarta257bf92009-04-06 18:48:10 -04002441 spin_lock_irqsave(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002442 pnode->cmd_qdepth += pnode->cmd_qdepth *
2443 LPFC_TGTQ_RAMPUP_PCENT / 100;
2444 if (pnode->cmd_qdepth > LPFC_MAX_TGT_QDEPTH)
2445 pnode->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2446 pnode->last_change_time = jiffies;
James Smarta257bf92009-04-06 18:48:10 -04002447 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002448 }
James Smart977b5a02008-09-07 11:52:04 -04002449 }
2450
James Smart1dcb58e2007-04-25 09:51:30 -04002451 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
James Smarta257bf92009-04-06 18:48:10 -04002452
2453 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
2454 queue_depth = cmd->device->queue_depth;
2455 scsi_id = cmd->device->id;
dea31012005-04-17 16:05:31 -05002456 cmd->scsi_done(cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002457
Jamie Wellnitzb8086082006-02-28 22:33:12 -05002458 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smartfa61a542008-01-11 01:52:42 -05002459 /*
2460 * If there is a thread waiting for command completion
2461 * wake up the thread.
2462 */
James Smarta257bf92009-04-06 18:48:10 -04002463 spin_lock_irqsave(shost->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -04002464 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -05002465 if (lpfc_cmd->waitq)
2466 wake_up(lpfc_cmd->waitq);
James Smarta257bf92009-04-06 18:48:10 -04002467 spin_unlock_irqrestore(shost->host_lock, flags);
Jamie Wellnitzb8086082006-02-28 22:33:12 -05002468 lpfc_release_scsi_buf(phba, lpfc_cmd);
2469 return;
2470 }
2471
James Smart92d7f7b2007-06-17 19:56:38 -05002472 if (!result)
James Smarta257bf92009-04-06 18:48:10 -04002473 lpfc_rampup_queue_depth(vport, queue_depth);
James Smart92d7f7b2007-06-17 19:56:38 -05002474
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002475 /*
2476 * Check for queue full. If the lun is reporting queue full, then
2477 * back off the lun queue depth to prevent target overloads.
2478 */
James Smart58da1ff2008-04-07 10:15:56 -04002479 if (result == SAM_STAT_TASK_SET_FULL && pnode &&
2480 NLP_CHK_NODE_ACT(pnode)) {
James Smarta257bf92009-04-06 18:48:10 -04002481 shost_for_each_device(tmp_sdev, shost) {
2482 if (tmp_sdev->id != scsi_id)
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002483 continue;
2484 depth = scsi_track_queue_full(tmp_sdev,
James Smart5ffc2662009-11-18 15:39:44 -05002485 tmp_sdev->queue_depth-1);
2486 if (depth <= 0)
2487 continue;
James Smarte8b62012007-08-02 11:10:09 -04002488 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
2489 "0711 detected queue full - lun queue "
2490 "depth adjusted to %d.\n", depth);
James Smartea2151b2008-09-07 11:52:10 -04002491 lpfc_send_sdev_queuedepth_change_event(phba, vport,
James Smart5ffc2662009-11-18 15:39:44 -05002492 pnode,
2493 tmp_sdev->lun,
2494 depth+1, depth);
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002495 }
2496 }
2497
James Smartfa61a542008-01-11 01:52:42 -05002498 /*
2499 * If there is a thread waiting for command completion
2500 * wake up the thread.
2501 */
James Smarta257bf92009-04-06 18:48:10 -04002502 spin_lock_irqsave(shost->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -04002503 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -05002504 if (lpfc_cmd->waitq)
2505 wake_up(lpfc_cmd->waitq);
James Smarta257bf92009-04-06 18:48:10 -04002506 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartfa61a542008-01-11 01:52:42 -05002507
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002508 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05002509}
2510
James Smart34b02dc2008-08-24 21:49:55 -04002511/**
James Smart3621a712009-04-06 18:47:14 -04002512 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
James Smart34b02dc2008-08-24 21:49:55 -04002513 * @data: A pointer to the immediate command data portion of the IOCB.
2514 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
2515 *
2516 * The routine copies the entire FCP command from @fcp_cmnd to @data while
2517 * byte swapping the data to big endian format for transmission on the wire.
2518 **/
2519static void
2520lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
2521{
2522 int i, j;
2523 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
2524 i += sizeof(uint32_t), j++) {
2525 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
2526 }
2527}
2528
James Smart9bad7672008-12-04 22:39:02 -05002529/**
James Smartf1126682009-06-10 17:22:44 -04002530 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
James Smart9bad7672008-12-04 22:39:02 -05002531 * @vport: The virtual port for which this call is being executed.
2532 * @lpfc_cmd: The scsi command which needs to send.
2533 * @pnode: Pointer to lpfc_nodelist.
2534 *
2535 * This routine initializes fcp_cmnd and iocb data structure from scsi command
James Smart3772a992009-05-22 14:50:54 -04002536 * to transfer for device with SLI3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05002537 **/
dea31012005-04-17 16:05:31 -05002538static void
James Smartf1126682009-06-10 17:22:44 -04002539lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
James Smart2e0fef82007-06-17 19:56:36 -05002540 struct lpfc_nodelist *pnode)
dea31012005-04-17 16:05:31 -05002541{
James Smart2e0fef82007-06-17 19:56:36 -05002542 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002543 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2544 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2545 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2546 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
2547 int datadir = scsi_cmnd->sc_data_direction;
James Smart7e2b19f2007-10-29 11:00:39 -04002548 char tag[2];
dea31012005-04-17 16:05:31 -05002549
James Smart58da1ff2008-04-07 10:15:56 -04002550 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
2551 return;
2552
dea31012005-04-17 16:05:31 -05002553 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
James.Smart@Emulex.Com69859dc2005-08-10 15:02:37 -04002554 /* clear task management bits */
2555 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
dea31012005-04-17 16:05:31 -05002556
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -04002557 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
2558 &lpfc_cmd->fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -05002559
2560 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
2561
James Smart7e2b19f2007-10-29 11:00:39 -04002562 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
2563 switch (tag[0]) {
dea31012005-04-17 16:05:31 -05002564 case HEAD_OF_QUEUE_TAG:
2565 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
2566 break;
2567 case ORDERED_QUEUE_TAG:
2568 fcp_cmnd->fcpCntl1 = ORDERED_Q;
2569 break;
2570 default:
2571 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
2572 break;
2573 }
2574 } else
2575 fcp_cmnd->fcpCntl1 = 0;
2576
2577 /*
2578 * There are three possibilities here - use scatter-gather segment, use
2579 * the single mapping, or neither. Start the lpfc command prep by
2580 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
2581 * data bde entry.
2582 */
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002583 if (scsi_sg_count(scsi_cmnd)) {
dea31012005-04-17 16:05:31 -05002584 if (datadir == DMA_TO_DEVICE) {
2585 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
James Smart3772a992009-05-22 14:50:54 -04002586 if (phba->sli_rev < LPFC_SLI_REV4) {
2587 iocb_cmd->un.fcpi.fcpi_parm = 0;
2588 iocb_cmd->ulpPU = 0;
2589 } else
2590 iocb_cmd->ulpPU = PARM_READ_CHECK;
dea31012005-04-17 16:05:31 -05002591 fcp_cmnd->fcpCntl3 = WRITE_DATA;
2592 phba->fc4OutputRequests++;
2593 } else {
2594 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
2595 iocb_cmd->ulpPU = PARM_READ_CHECK;
dea31012005-04-17 16:05:31 -05002596 fcp_cmnd->fcpCntl3 = READ_DATA;
2597 phba->fc4InputRequests++;
2598 }
2599 } else {
2600 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
2601 iocb_cmd->un.fcpi.fcpi_parm = 0;
2602 iocb_cmd->ulpPU = 0;
2603 fcp_cmnd->fcpCntl3 = 0;
2604 phba->fc4ControlRequests++;
2605 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002606 if (phba->sli_rev == 3 &&
2607 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
James Smart34b02dc2008-08-24 21:49:55 -04002608 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -05002609 /*
2610 * Finish initializing those IOCB fields that are independent
2611 * of the scsi_cmnd request_buffer
2612 */
2613 piocbq->iocb.ulpContext = pnode->nlp_rpi;
2614 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
2615 piocbq->iocb.ulpFCP2Rcvy = 1;
James Smart09372822008-01-11 01:52:54 -05002616 else
2617 piocbq->iocb.ulpFCP2Rcvy = 0;
dea31012005-04-17 16:05:31 -05002618
2619 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
2620 piocbq->context1 = lpfc_cmd;
2621 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
2622 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002623 piocbq->vport = vport;
dea31012005-04-17 16:05:31 -05002624}
2625
James Smart9bad7672008-12-04 22:39:02 -05002626/**
James Smartf1126682009-06-10 17:22:44 -04002627 * lpfc_scsi_prep_task_mgmt_cmnd - Convert SLI3 scsi TM cmd to FCP info unit
James Smart9bad7672008-12-04 22:39:02 -05002628 * @vport: The virtual port for which this call is being executed.
2629 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2630 * @lun: Logical unit number.
2631 * @task_mgmt_cmd: SCSI task management command.
2632 *
James Smart3772a992009-05-22 14:50:54 -04002633 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
2634 * for device with SLI-3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05002635 *
2636 * Return codes:
2637 * 0 - Error
2638 * 1 - Success
2639 **/
dea31012005-04-17 16:05:31 -05002640static int
James Smartf1126682009-06-10 17:22:44 -04002641lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
dea31012005-04-17 16:05:31 -05002642 struct lpfc_scsi_buf *lpfc_cmd,
James Smart420b630d2006-07-06 15:50:16 -04002643 unsigned int lun,
dea31012005-04-17 16:05:31 -05002644 uint8_t task_mgmt_cmd)
2645{
dea31012005-04-17 16:05:31 -05002646 struct lpfc_iocbq *piocbq;
2647 IOCB_t *piocb;
2648 struct fcp_cmnd *fcp_cmnd;
James Smart0b18ac42006-05-01 21:50:40 -04002649 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
dea31012005-04-17 16:05:31 -05002650 struct lpfc_nodelist *ndlp = rdata->pnode;
2651
James Smart58da1ff2008-04-07 10:15:56 -04002652 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
2653 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
dea31012005-04-17 16:05:31 -05002654 return 0;
dea31012005-04-17 16:05:31 -05002655
dea31012005-04-17 16:05:31 -05002656 piocbq = &(lpfc_cmd->cur_iocbq);
James Smart2e0fef82007-06-17 19:56:36 -05002657 piocbq->vport = vport;
2658
dea31012005-04-17 16:05:31 -05002659 piocb = &piocbq->iocb;
2660
2661 fcp_cmnd = lpfc_cmd->fcp_cmnd;
James Smart34b02dc2008-08-24 21:49:55 -04002662 /* Clear out any old data in the FCP command area */
2663 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
2664 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -05002665 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
James Smarte2a0a9d2008-12-04 22:40:02 -05002666 if (vport->phba->sli_rev == 3 &&
2667 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
James Smart34b02dc2008-08-24 21:49:55 -04002668 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -05002669 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
dea31012005-04-17 16:05:31 -05002670 piocb->ulpContext = ndlp->nlp_rpi;
2671 if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
2672 piocb->ulpFCP2Rcvy = 1;
2673 }
2674 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
2675
2676 /* ulpTimeout is only one byte */
2677 if (lpfc_cmd->timeout > 0xff) {
2678 /*
2679 * Do not timeout the command at the firmware level.
2680 * The driver will provide the timeout mechanism.
2681 */
2682 piocb->ulpTimeout = 0;
James Smartf1126682009-06-10 17:22:44 -04002683 } else
dea31012005-04-17 16:05:31 -05002684 piocb->ulpTimeout = lpfc_cmd->timeout;
James Smartf1126682009-06-10 17:22:44 -04002685
2686 if (vport->phba->sli_rev == LPFC_SLI_REV4)
2687 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05002688
James Smart2e0fef82007-06-17 19:56:36 -05002689 return 1;
dea31012005-04-17 16:05:31 -05002690}
2691
James Smart9bad7672008-12-04 22:39:02 -05002692/**
James Smart3772a992009-05-22 14:50:54 -04002693 * lpfc_scsi_api_table_setup - Set up scsi api fucntion jump table
2694 * @phba: The hba struct for which this call is being executed.
2695 * @dev_grp: The HBA PCI-Device group number.
2696 *
2697 * This routine sets up the SCSI interface API function jump table in @phba
2698 * struct.
2699 * Returns: 0 - success, -ENODEV - failure.
2700 **/
2701int
2702lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
2703{
2704
James Smartf1126682009-06-10 17:22:44 -04002705 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
2706 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
2707 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf;
2708
James Smart3772a992009-05-22 14:50:54 -04002709 switch (dev_grp) {
2710 case LPFC_PCI_DEV_LP:
2711 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
2712 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
James Smart3772a992009-05-22 14:50:54 -04002713 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
2714 break;
James Smartda0436e2009-05-22 14:51:39 -04002715 case LPFC_PCI_DEV_OC:
2716 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
2717 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
James Smartda0436e2009-05-22 14:51:39 -04002718 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
2719 break;
James Smart3772a992009-05-22 14:50:54 -04002720 default:
2721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2722 "1418 Invalid HBA PCI-device group: 0x%x\n",
2723 dev_grp);
2724 return -ENODEV;
2725 break;
2726 }
2727 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf;
2728 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
James Smart84d1b002010-02-12 14:42:33 -05002729 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
James Smart3772a992009-05-22 14:50:54 -04002730 return 0;
2731}
2732
2733/**
James Smart3621a712009-04-06 18:47:14 -04002734 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
James Smart9bad7672008-12-04 22:39:02 -05002735 * @phba: The Hba for which this call is being executed.
2736 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
2737 * @rspiocbq: Pointer to lpfc_iocbq data structure.
2738 *
2739 * This routine is IOCB completion routine for device reset and target reset
2740 * routine. This routine release scsi buffer associated with lpfc_cmd.
2741 **/
James Smart7054a602007-04-25 09:52:34 -04002742static void
2743lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
2744 struct lpfc_iocbq *cmdiocbq,
2745 struct lpfc_iocbq *rspiocbq)
2746{
2747 struct lpfc_scsi_buf *lpfc_cmd =
2748 (struct lpfc_scsi_buf *) cmdiocbq->context1;
2749 if (lpfc_cmd)
2750 lpfc_release_scsi_buf(phba, lpfc_cmd);
2751 return;
2752}
2753
James Smart9bad7672008-12-04 22:39:02 -05002754/**
James Smart3621a712009-04-06 18:47:14 -04002755 * lpfc_info - Info entry point of scsi_host_template data structure
James Smart9bad7672008-12-04 22:39:02 -05002756 * @host: The scsi host for which this call is being executed.
2757 *
2758 * This routine provides module information about hba.
2759 *
2760 * Reutrn code:
2761 * Pointer to char - Success.
2762 **/
dea31012005-04-17 16:05:31 -05002763const char *
2764lpfc_info(struct Scsi_Host *host)
2765{
James Smart2e0fef82007-06-17 19:56:36 -05002766 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
2767 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002768 int len;
2769 static char lpfcinfobuf[384];
2770
2771 memset(lpfcinfobuf,0,384);
2772 if (phba && phba->pcidev){
2773 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
2774 len = strlen(lpfcinfobuf);
2775 snprintf(lpfcinfobuf + len,
2776 384-len,
2777 " on PCI bus %02x device %02x irq %d",
2778 phba->pcidev->bus->number,
2779 phba->pcidev->devfn,
2780 phba->pcidev->irq);
2781 len = strlen(lpfcinfobuf);
2782 if (phba->Port[0]) {
2783 snprintf(lpfcinfobuf + len,
2784 384-len,
2785 " port %s",
2786 phba->Port);
2787 }
James Smart65467b62010-01-26 23:08:29 -05002788 len = strlen(lpfcinfobuf);
2789 if (phba->sli4_hba.link_state.logical_speed) {
2790 snprintf(lpfcinfobuf + len,
2791 384-len,
2792 " Logical Link Speed: %d Mbps",
2793 phba->sli4_hba.link_state.logical_speed * 10);
2794 }
dea31012005-04-17 16:05:31 -05002795 }
2796 return lpfcinfobuf;
2797}
2798
James Smart9bad7672008-12-04 22:39:02 -05002799/**
James Smart3621a712009-04-06 18:47:14 -04002800 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
James Smart9bad7672008-12-04 22:39:02 -05002801 * @phba: The Hba for which this call is being executed.
2802 *
2803 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
2804 * The default value of cfg_poll_tmo is 10 milliseconds.
2805 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002806static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
2807{
2808 unsigned long poll_tmo_expires =
2809 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
2810
2811 if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
2812 mod_timer(&phba->fcp_poll_timer,
2813 poll_tmo_expires);
2814}
2815
James Smart9bad7672008-12-04 22:39:02 -05002816/**
James Smart3621a712009-04-06 18:47:14 -04002817 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
James Smart9bad7672008-12-04 22:39:02 -05002818 * @phba: The Hba for which this call is being executed.
2819 *
2820 * This routine starts the fcp_poll_timer of @phba.
2821 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002822void lpfc_poll_start_timer(struct lpfc_hba * phba)
2823{
2824 lpfc_poll_rearm_timer(phba);
2825}
2826
James Smart9bad7672008-12-04 22:39:02 -05002827/**
James Smart3621a712009-04-06 18:47:14 -04002828 * lpfc_poll_timeout - Restart polling timer
James Smart9bad7672008-12-04 22:39:02 -05002829 * @ptr: Map to lpfc_hba data structure pointer.
2830 *
2831 * This routine restarts fcp_poll timer, when FCP ring polling is enable
2832 * and FCP Ring interrupt is disable.
2833 **/
2834
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002835void lpfc_poll_timeout(unsigned long ptr)
2836{
James Smart2e0fef82007-06-17 19:56:36 -05002837 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002838
2839 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04002840 lpfc_sli_handle_fast_ring_event(phba,
2841 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
2842
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002843 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
2844 lpfc_poll_rearm_timer(phba);
2845 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002846}
2847
James Smart9bad7672008-12-04 22:39:02 -05002848/**
James Smart3621a712009-04-06 18:47:14 -04002849 * lpfc_queuecommand - scsi_host_template queuecommand entry point
James Smart9bad7672008-12-04 22:39:02 -05002850 * @cmnd: Pointer to scsi_cmnd data structure.
2851 * @done: Pointer to done routine.
2852 *
2853 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
2854 * This routine prepares an IOCB from scsi command and provides to firmware.
2855 * The @done callback is invoked after driver finished processing the command.
2856 *
2857 * Return value :
2858 * 0 - Success
2859 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
2860 **/
dea31012005-04-17 16:05:31 -05002861static int
2862lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
2863{
James Smart2e0fef82007-06-17 19:56:36 -05002864 struct Scsi_Host *shost = cmnd->device->host;
2865 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2866 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002867 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05002868 struct lpfc_nodelist *ndlp;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002869 struct lpfc_scsi_buf *lpfc_cmd;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002870 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002871 int err;
dea31012005-04-17 16:05:31 -05002872
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002873 err = fc_remote_port_chkready(rport);
2874 if (err) {
2875 cmnd->result = err;
dea31012005-04-17 16:05:31 -05002876 goto out_fail_command;
2877 }
James Smart1c6f4ef52009-11-18 15:40:49 -05002878 ndlp = rdata->pnode;
dea31012005-04-17 16:05:31 -05002879
James Smarte2a0a9d2008-12-04 22:40:02 -05002880 if (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
2881 scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
2882
James Smart6a9c52c2009-10-02 15:16:51 -04002883 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2884 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
2885 " op:%02x str=%s without registering for"
2886 " BlockGuard - Rejecting command\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002887 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
2888 dif_op_str[scsi_get_prot_op(cmnd)]);
2889 goto out_fail_command;
2890 }
2891
dea31012005-04-17 16:05:31 -05002892 /*
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002893 * Catch race where our node has transitioned, but the
2894 * transport is still transitioning.
dea31012005-04-17 16:05:31 -05002895 */
James Smartb522d7d2008-09-07 11:51:56 -04002896 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
2897 cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
2898 goto out_fail_command;
2899 }
James Smart109f6ed2008-12-04 22:39:08 -05002900 if (vport->cfg_max_scsicmpl_time &&
2901 (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth))
James Smart977b5a02008-09-07 11:52:04 -04002902 goto out_host_busy;
Mike Christiea93ce022008-08-17 15:24:41 -05002903
James Smarted957682007-06-17 19:56:37 -05002904 lpfc_cmd = lpfc_get_scsi_buf(phba);
dea31012005-04-17 16:05:31 -05002905 if (lpfc_cmd == NULL) {
James Smarteaf15d52008-12-04 22:39:29 -05002906 lpfc_rampdown_queue_depth(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002907
James Smarte8b62012007-08-02 11:10:09 -04002908 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
2909 "0707 driver's buffer pool is empty, "
2910 "IO busied\n");
dea31012005-04-17 16:05:31 -05002911 goto out_host_busy;
2912 }
2913
2914 /*
2915 * Store the midlayer's command structure for the completion phase
2916 * and complete the command initialization.
2917 */
2918 lpfc_cmd->pCmd = cmnd;
2919 lpfc_cmd->rdata = rdata;
2920 lpfc_cmd->timeout = 0;
James Smart977b5a02008-09-07 11:52:04 -04002921 lpfc_cmd->start_time = jiffies;
dea31012005-04-17 16:05:31 -05002922 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
2923 cmnd->scsi_done = done;
2924
James Smarte2a0a9d2008-12-04 22:40:02 -05002925 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
James Smart6a9c52c2009-10-02 15:16:51 -04002926 if (vport->phba->cfg_enable_bg) {
2927 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002928 "9033 BLKGRD: rcvd protected cmd:%02x op:%02x "
2929 "str=%s\n",
2930 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
2931 dif_op_str[scsi_get_prot_op(cmnd)]);
James Smart6a9c52c2009-10-02 15:16:51 -04002932 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002933 "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x "
James Smarte4e74272009-07-19 10:01:38 -04002934 "%02x %02x %02x %02x %02x\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002935 cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2],
2936 cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5],
2937 cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8],
2938 cmnd->cmnd[9]);
James Smart6a9c52c2009-10-02 15:16:51 -04002939 if (cmnd->cmnd[0] == READ_10)
2940 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002941 "9035 BLKGRD: READ @ sector %llu, "
Tejun Heo83096eb2009-05-07 22:24:39 +09002942 "count %u\n",
2943 (unsigned long long)scsi_get_lba(cmnd),
2944 blk_rq_sectors(cmnd->request));
James Smart6a9c52c2009-10-02 15:16:51 -04002945 else if (cmnd->cmnd[0] == WRITE_10)
2946 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002947 "9036 BLKGRD: WRITE @ sector %llu, "
Tejun Heo83096eb2009-05-07 22:24:39 +09002948 "count %u cmd=%p\n",
James Smart87b5c322008-12-16 10:34:09 -05002949 (unsigned long long)scsi_get_lba(cmnd),
Tejun Heo83096eb2009-05-07 22:24:39 +09002950 blk_rq_sectors(cmnd->request),
James Smarte2a0a9d2008-12-04 22:40:02 -05002951 cmnd);
James Smart6a9c52c2009-10-02 15:16:51 -04002952 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002953
2954 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
2955 } else {
James Smart6a9c52c2009-10-02 15:16:51 -04002956 if (vport->phba->cfg_enable_bg) {
James Smarte2a0a9d2008-12-04 22:40:02 -05002957 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smart6a9c52c2009-10-02 15:16:51 -04002958 "9038 BLKGRD: rcvd unprotected cmd:"
2959 "%02x op:%02x str=%s\n",
2960 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
2961 dif_op_str[scsi_get_prot_op(cmnd)]);
2962 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2963 "9039 BLKGRD: CDB: %02x %02x %02x "
2964 "%02x %02x %02x %02x %02x %02x %02x\n",
2965 cmnd->cmnd[0], cmnd->cmnd[1],
2966 cmnd->cmnd[2], cmnd->cmnd[3],
2967 cmnd->cmnd[4], cmnd->cmnd[5],
2968 cmnd->cmnd[6], cmnd->cmnd[7],
2969 cmnd->cmnd[8], cmnd->cmnd[9]);
2970 if (cmnd->cmnd[0] == READ_10)
2971 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2972 "9040 dbg: READ @ sector %llu, "
2973 "count %u\n",
2974 (unsigned long long)scsi_get_lba(cmnd),
Tejun Heo83096eb2009-05-07 22:24:39 +09002975 blk_rq_sectors(cmnd->request));
James Smart6a9c52c2009-10-02 15:16:51 -04002976 else if (cmnd->cmnd[0] == WRITE_10)
2977 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002978 "9041 dbg: WRITE @ sector %llu, "
Tejun Heo83096eb2009-05-07 22:24:39 +09002979 "count %u cmd=%p\n",
James Smart87b5c322008-12-16 10:34:09 -05002980 (unsigned long long)scsi_get_lba(cmnd),
Tejun Heo83096eb2009-05-07 22:24:39 +09002981 blk_rq_sectors(cmnd->request), cmnd);
James Smart6a9c52c2009-10-02 15:16:51 -04002982 else
2983 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002984 "9042 dbg: parser not implemented\n");
James Smart6a9c52c2009-10-02 15:16:51 -04002985 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002986 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
2987 }
2988
dea31012005-04-17 16:05:31 -05002989 if (err)
2990 goto out_host_busy_free_buf;
2991
James Smart2e0fef82007-06-17 19:56:36 -05002992 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
dea31012005-04-17 16:05:31 -05002993
James Smart977b5a02008-09-07 11:52:04 -04002994 atomic_inc(&ndlp->cmd_pending);
James Smart3772a992009-05-22 14:50:54 -04002995 err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
James Smart92d7f7b2007-06-17 19:56:38 -05002996 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
James Smarteaf15d52008-12-04 22:39:29 -05002997 if (err) {
2998 atomic_dec(&ndlp->cmd_pending);
dea31012005-04-17 16:05:31 -05002999 goto out_host_busy_free_buf;
James Smarteaf15d52008-12-04 22:39:29 -05003000 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003001 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04003002 spin_unlock(shost->host_lock);
3003 lpfc_sli_handle_fast_ring_event(phba,
3004 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
3005
3006 spin_lock(shost->host_lock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003007 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
3008 lpfc_poll_rearm_timer(phba);
3009 }
3010
dea31012005-04-17 16:05:31 -05003011 return 0;
3012
3013 out_host_busy_free_buf:
James Smartbcf4dbf2006-07-06 15:50:08 -04003014 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003015 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05003016 out_host_busy:
3017 return SCSI_MLQUEUE_HOST_BUSY;
3018
3019 out_fail_command:
3020 done(cmnd);
3021 return 0;
3022}
3023
James Smart9bad7672008-12-04 22:39:02 -05003024/**
James Smart3621a712009-04-06 18:47:14 -04003025 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
James Smart9bad7672008-12-04 22:39:02 -05003026 * @cmnd: Pointer to scsi_cmnd data structure.
3027 *
3028 * This routine aborts @cmnd pending in base driver.
3029 *
3030 * Return code :
3031 * 0x2003 - Error
3032 * 0x2002 - Success
3033 **/
dea31012005-04-17 16:05:31 -05003034static int
James.Smart@Emulex.Com63c59c32005-11-28 11:41:53 -05003035lpfc_abort_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05003036{
James Smart2e0fef82007-06-17 19:56:36 -05003037 struct Scsi_Host *shost = cmnd->device->host;
3038 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3039 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003040 struct lpfc_iocbq *iocb;
3041 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05003042 struct lpfc_scsi_buf *lpfc_cmd;
dea31012005-04-17 16:05:31 -05003043 IOCB_t *cmd, *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003044 int ret = SUCCESS;
James Smartfa61a542008-01-11 01:52:42 -05003045 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003046
Christof Schmitt65d430f2009-10-30 17:59:29 +01003047 fc_block_scsi_eh(cmnd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003048 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
3049 BUG_ON(!lpfc_cmd);
dea31012005-04-17 16:05:31 -05003050
3051 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003052 * If pCmd field of the corresponding lpfc_scsi_buf structure
3053 * points to a different SCSI command, then the driver has
3054 * already completed this command, but the midlayer did not
3055 * see the completion before the eh fired. Just return
3056 * SUCCESS.
dea31012005-04-17 16:05:31 -05003057 */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003058 iocb = &lpfc_cmd->cur_iocbq;
3059 if (lpfc_cmd->pCmd != cmnd)
3060 goto out;
dea31012005-04-17 16:05:31 -05003061
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003062 BUG_ON(iocb->context1 != lpfc_cmd);
dea31012005-04-17 16:05:31 -05003063
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003064 abtsiocb = lpfc_sli_get_iocbq(phba);
3065 if (abtsiocb == NULL) {
3066 ret = FAILED;
dea31012005-04-17 16:05:31 -05003067 goto out;
3068 }
3069
dea31012005-04-17 16:05:31 -05003070 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003071 * The scsi command can not be in txq and it is in flight because the
3072 * pCmd is still pointig at the SCSI command we have to abort. There
3073 * is no need to search the txcmplq. Just send an abort to the FW.
dea31012005-04-17 16:05:31 -05003074 */
dea31012005-04-17 16:05:31 -05003075
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003076 cmd = &iocb->iocb;
3077 icmd = &abtsiocb->iocb;
3078 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
3079 icmd->un.acxri.abortContextTag = cmd->ulpContext;
James Smart3772a992009-05-22 14:50:54 -04003080 if (phba->sli_rev == LPFC_SLI_REV4)
3081 icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
3082 else
3083 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05003084
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003085 icmd->ulpLe = 1;
3086 icmd->ulpClass = cmd->ulpClass;
James Smart5ffc2662009-11-18 15:39:44 -05003087
3088 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
3089 abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
James Smart341af102010-01-26 23:07:37 -05003090 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
James Smart5ffc2662009-11-18 15:39:44 -05003091
James Smart2e0fef82007-06-17 19:56:36 -05003092 if (lpfc_is_link_up(phba))
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003093 icmd->ulpCommand = CMD_ABORT_XRI_CN;
3094 else
3095 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
dea31012005-04-17 16:05:31 -05003096
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003097 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
James Smart2e0fef82007-06-17 19:56:36 -05003098 abtsiocb->vport = vport;
James Smart3772a992009-05-22 14:50:54 -04003099 if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) ==
3100 IOCB_ERROR) {
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003101 lpfc_sli_release_iocbq(phba, abtsiocb);
3102 ret = FAILED;
3103 goto out;
3104 }
3105
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003106 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
James Smart45ed1192009-10-02 15:17:02 -04003107 lpfc_sli_handle_fast_ring_event(phba,
3108 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003109
James Smartfa61a542008-01-11 01:52:42 -05003110 lpfc_cmd->waitq = &waitq;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003111 /* Wait for abort to complete */
James Smartfa61a542008-01-11 01:52:42 -05003112 wait_event_timeout(waitq,
3113 (lpfc_cmd->pCmd != cmnd),
3114 (2*vport->cfg_devloss_tmo*HZ));
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003115
James Smartfa61a542008-01-11 01:52:42 -05003116 spin_lock_irq(shost->host_lock);
3117 lpfc_cmd->waitq = NULL;
3118 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003119
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003120 if (lpfc_cmd->pCmd == cmnd) {
3121 ret = FAILED;
James Smarte8b62012007-08-02 11:10:09 -04003122 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3123 "0748 abort handler timed out waiting "
3124 "for abort to complete: ret %#x, ID %d, "
3125 "LUN %d, snum %#lx\n",
3126 ret, cmnd->device->id, cmnd->device->lun,
3127 cmnd->serial_number);
dea31012005-04-17 16:05:31 -05003128 }
3129
3130 out:
James Smarte8b62012007-08-02 11:10:09 -04003131 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3132 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
3133 "LUN %d snum %#lx\n", ret, cmnd->device->id,
3134 cmnd->device->lun, cmnd->serial_number);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003135 return ret;
dea31012005-04-17 16:05:31 -05003136}
3137
James Smartbbb9d182009-06-10 17:23:16 -04003138static char *
3139lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
3140{
3141 switch (task_mgmt_cmd) {
3142 case FCP_ABORT_TASK_SET:
3143 return "ABORT_TASK_SET";
3144 case FCP_CLEAR_TASK_SET:
3145 return "FCP_CLEAR_TASK_SET";
3146 case FCP_BUS_RESET:
3147 return "FCP_BUS_RESET";
3148 case FCP_LUN_RESET:
3149 return "FCP_LUN_RESET";
3150 case FCP_TARGET_RESET:
3151 return "FCP_TARGET_RESET";
3152 case FCP_CLEAR_ACA:
3153 return "FCP_CLEAR_ACA";
3154 case FCP_TERMINATE_TASK:
3155 return "FCP_TERMINATE_TASK";
3156 default:
3157 return "unknown";
3158 }
3159}
3160
3161/**
3162 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
3163 * @vport: The virtual port for which this call is being executed.
3164 * @rdata: Pointer to remote port local data
3165 * @tgt_id: Target ID of remote device.
3166 * @lun_id: Lun number for the TMF
3167 * @task_mgmt_cmd: type of TMF to send
3168 *
3169 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
3170 * a remote port.
3171 *
3172 * Return Code:
3173 * 0x2003 - Error
3174 * 0x2002 - Success.
3175 **/
3176static int
3177lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
3178 unsigned tgt_id, unsigned int lun_id,
3179 uint8_t task_mgmt_cmd)
3180{
3181 struct lpfc_hba *phba = vport->phba;
3182 struct lpfc_scsi_buf *lpfc_cmd;
3183 struct lpfc_iocbq *iocbq;
3184 struct lpfc_iocbq *iocbqrsp;
3185 int ret;
3186 int status;
3187
3188 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
3189 return FAILED;
3190
3191 lpfc_cmd = lpfc_get_scsi_buf(phba);
3192 if (lpfc_cmd == NULL)
3193 return FAILED;
3194 lpfc_cmd->timeout = 60;
3195 lpfc_cmd->rdata = rdata;
3196
3197 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
3198 task_mgmt_cmd);
3199 if (!status) {
3200 lpfc_release_scsi_buf(phba, lpfc_cmd);
3201 return FAILED;
3202 }
3203
3204 iocbq = &lpfc_cmd->cur_iocbq;
3205 iocbqrsp = lpfc_sli_get_iocbq(phba);
3206 if (iocbqrsp == NULL) {
3207 lpfc_release_scsi_buf(phba, lpfc_cmd);
3208 return FAILED;
3209 }
3210
3211 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3212 "0702 Issue %s to TGT %d LUN %d "
3213 "rpi x%x nlp_flag x%x\n",
3214 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
3215 rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
3216
3217 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
3218 iocbq, iocbqrsp, lpfc_cmd->timeout);
3219 if (status != IOCB_SUCCESS) {
3220 if (status == IOCB_TIMEDOUT) {
3221 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
3222 ret = TIMEOUT_ERROR;
3223 } else
3224 ret = FAILED;
3225 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3226 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3227 "0727 TMF %s to TGT %d LUN %d failed (%d, %d)\n",
3228 lpfc_taskmgmt_name(task_mgmt_cmd),
3229 tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
3230 iocbqrsp->iocb.un.ulpWord[4]);
3231 } else
3232 ret = SUCCESS;
3233
3234 lpfc_sli_release_iocbq(phba, iocbqrsp);
3235
3236 if (ret != TIMEOUT_ERROR)
3237 lpfc_release_scsi_buf(phba, lpfc_cmd);
3238
3239 return ret;
3240}
3241
3242/**
3243 * lpfc_chk_tgt_mapped -
3244 * @vport: The virtual port to check on
3245 * @cmnd: Pointer to scsi_cmnd data structure.
3246 *
3247 * This routine delays until the scsi target (aka rport) for the
3248 * command exists (is present and logged in) or we declare it non-existent.
3249 *
3250 * Return code :
3251 * 0x2003 - Error
3252 * 0x2002 - Success
3253 **/
3254static int
3255lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
3256{
3257 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05003258 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003259 unsigned long later;
3260
James Smart1c6f4ef52009-11-18 15:40:49 -05003261 if (!rdata) {
3262 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3263 "0797 Tgt Map rport failure: rdata x%p\n", rdata);
3264 return FAILED;
3265 }
3266 pnode = rdata->pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003267 /*
3268 * If target is not in a MAPPED state, delay until
3269 * target is rediscovered or devloss timeout expires.
3270 */
3271 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3272 while (time_after(later, jiffies)) {
3273 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3274 return FAILED;
3275 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
3276 return SUCCESS;
3277 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
3278 rdata = cmnd->device->hostdata;
3279 if (!rdata)
3280 return FAILED;
3281 pnode = rdata->pnode;
3282 }
3283 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
3284 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
3285 return FAILED;
3286 return SUCCESS;
3287}
3288
3289/**
3290 * lpfc_reset_flush_io_context -
3291 * @vport: The virtual port (scsi_host) for the flush context
3292 * @tgt_id: If aborting by Target contect - specifies the target id
3293 * @lun_id: If aborting by Lun context - specifies the lun id
3294 * @context: specifies the context level to flush at.
3295 *
3296 * After a reset condition via TMF, we need to flush orphaned i/o
3297 * contexts from the adapter. This routine aborts any contexts
3298 * outstanding, then waits for their completions. The wait is
3299 * bounded by devloss_tmo though.
3300 *
3301 * Return code :
3302 * 0x2003 - Error
3303 * 0x2002 - Success
3304 **/
3305static int
3306lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
3307 uint64_t lun_id, lpfc_ctx_cmd context)
3308{
3309 struct lpfc_hba *phba = vport->phba;
3310 unsigned long later;
3311 int cnt;
3312
3313 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
3314 if (cnt)
3315 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
3316 tgt_id, lun_id, context);
3317 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3318 while (time_after(later, jiffies) && cnt) {
3319 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
3320 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
3321 }
3322 if (cnt) {
3323 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3324 "0724 I/O flush failure for context %s : cnt x%x\n",
3325 ((context == LPFC_CTX_LUN) ? "LUN" :
3326 ((context == LPFC_CTX_TGT) ? "TGT" :
3327 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
3328 cnt);
3329 return FAILED;
3330 }
3331 return SUCCESS;
3332}
3333
James Smart9bad7672008-12-04 22:39:02 -05003334/**
James Smart3621a712009-04-06 18:47:14 -04003335 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
James Smart9bad7672008-12-04 22:39:02 -05003336 * @cmnd: Pointer to scsi_cmnd data structure.
3337 *
James Smartbbb9d182009-06-10 17:23:16 -04003338 * This routine does a device reset by sending a LUN_RESET task management
James Smart9bad7672008-12-04 22:39:02 -05003339 * command.
3340 *
3341 * Return code :
3342 * 0x2003 - Error
James Smart3621a712009-04-06 18:47:14 -04003343 * 0x2002 - Success
James Smart9bad7672008-12-04 22:39:02 -05003344 **/
dea31012005-04-17 16:05:31 -05003345static int
James Smart7054a602007-04-25 09:52:34 -04003346lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05003347{
James Smart2e0fef82007-06-17 19:56:36 -05003348 struct Scsi_Host *shost = cmnd->device->host;
3349 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
dea31012005-04-17 16:05:31 -05003350 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05003351 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003352 unsigned tgt_id = cmnd->device->id;
3353 unsigned int lun_id = cmnd->device->lun;
James Smartea2151b2008-09-07 11:52:10 -04003354 struct lpfc_scsi_event_header scsi_event;
James Smartbbb9d182009-06-10 17:23:16 -04003355 int status;
dea31012005-04-17 16:05:31 -05003356
James Smart1c6f4ef52009-11-18 15:40:49 -05003357 if (!rdata) {
3358 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3359 "0798 Device Reset rport failure: rdata x%p\n", rdata);
3360 return FAILED;
3361 }
3362 pnode = rdata->pnode;
Christof Schmitt65d430f2009-10-30 17:59:29 +01003363 fc_block_scsi_eh(cmnd);
James Smartbbb9d182009-06-10 17:23:16 -04003364
3365 status = lpfc_chk_tgt_mapped(vport, cmnd);
3366 if (status == FAILED) {
3367 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3368 "0721 Device Reset rport failure: rdata x%p\n", rdata);
3369 return FAILED;
3370 }
3371
3372 scsi_event.event_type = FC_REG_SCSI_EVENT;
3373 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
3374 scsi_event.lun = lun_id;
3375 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
3376 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
3377
3378 fc_host_post_vendor_event(shost, fc_get_event_number(),
3379 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
3380
3381 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
3382 FCP_LUN_RESET);
3383
3384 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3385 "0713 SCSI layer issued Device Reset (%d, %d) "
3386 "return x%x\n", tgt_id, lun_id, status);
3387
dea31012005-04-17 16:05:31 -05003388 /*
James Smartbbb9d182009-06-10 17:23:16 -04003389 * We have to clean up i/o as : they may be orphaned by the TMF;
3390 * or if the TMF failed, they may be in an indeterminate state.
3391 * So, continue on.
3392 * We will report success if all the i/o aborts successfully.
dea31012005-04-17 16:05:31 -05003393 */
James Smartbbb9d182009-06-10 17:23:16 -04003394 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
3395 LPFC_CTX_LUN);
3396 return status;
3397}
3398
3399/**
3400 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
3401 * @cmnd: Pointer to scsi_cmnd data structure.
3402 *
3403 * This routine does a target reset by sending a TARGET_RESET task management
3404 * command.
3405 *
3406 * Return code :
3407 * 0x2003 - Error
3408 * 0x2002 - Success
3409 **/
3410static int
3411lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
3412{
3413 struct Scsi_Host *shost = cmnd->device->host;
3414 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3415 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05003416 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003417 unsigned tgt_id = cmnd->device->id;
3418 unsigned int lun_id = cmnd->device->lun;
3419 struct lpfc_scsi_event_header scsi_event;
3420 int status;
3421
James Smart1c6f4ef52009-11-18 15:40:49 -05003422 if (!rdata) {
3423 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3424 "0799 Target Reset rport failure: rdata x%p\n", rdata);
3425 return FAILED;
3426 }
3427 pnode = rdata->pnode;
Christof Schmitt65d430f2009-10-30 17:59:29 +01003428 fc_block_scsi_eh(cmnd);
James Smartbbb9d182009-06-10 17:23:16 -04003429
3430 status = lpfc_chk_tgt_mapped(vport, cmnd);
3431 if (status == FAILED) {
3432 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3433 "0722 Target Reset rport failure: rdata x%p\n", rdata);
3434 return FAILED;
dea31012005-04-17 16:05:31 -05003435 }
James Smartea2151b2008-09-07 11:52:10 -04003436
3437 scsi_event.event_type = FC_REG_SCSI_EVENT;
3438 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
3439 scsi_event.lun = 0;
3440 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
3441 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
3442
James Smartbbb9d182009-06-10 17:23:16 -04003443 fc_host_post_vendor_event(shost, fc_get_event_number(),
3444 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04003445
James Smartbbb9d182009-06-10 17:23:16 -04003446 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
3447 FCP_TARGET_RESET);
dea31012005-04-17 16:05:31 -05003448
James Smarte8b62012007-08-02 11:10:09 -04003449 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
James Smartbbb9d182009-06-10 17:23:16 -04003450 "0723 SCSI layer issued Target Reset (%d, %d) "
3451 "return x%x\n", tgt_id, lun_id, status);
3452
3453 /*
3454 * We have to clean up i/o as : they may be orphaned by the TMF;
3455 * or if the TMF failed, they may be in an indeterminate state.
3456 * So, continue on.
3457 * We will report success if all the i/o aborts successfully.
3458 */
3459 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
3460 LPFC_CTX_TGT);
3461 return status;
dea31012005-04-17 16:05:31 -05003462}
3463
James Smart9bad7672008-12-04 22:39:02 -05003464/**
James Smart3621a712009-04-06 18:47:14 -04003465 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
James Smart9bad7672008-12-04 22:39:02 -05003466 * @cmnd: Pointer to scsi_cmnd data structure.
3467 *
James Smartbbb9d182009-06-10 17:23:16 -04003468 * This routine does target reset to all targets on @cmnd->device->host.
3469 * This emulates Parallel SCSI Bus Reset Semantics.
James Smart9bad7672008-12-04 22:39:02 -05003470 *
James Smartbbb9d182009-06-10 17:23:16 -04003471 * Return code :
3472 * 0x2003 - Error
3473 * 0x2002 - Success
James Smart9bad7672008-12-04 22:39:02 -05003474 **/
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04003475static int
James Smart7054a602007-04-25 09:52:34 -04003476lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05003477{
James Smart2e0fef82007-06-17 19:56:36 -05003478 struct Scsi_Host *shost = cmnd->device->host;
3479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
dea31012005-04-17 16:05:31 -05003480 struct lpfc_nodelist *ndlp = NULL;
James Smartea2151b2008-09-07 11:52:10 -04003481 struct lpfc_scsi_event_header scsi_event;
James Smartbbb9d182009-06-10 17:23:16 -04003482 int match;
3483 int ret = SUCCESS, status, i;
James Smartea2151b2008-09-07 11:52:10 -04003484
3485 scsi_event.event_type = FC_REG_SCSI_EVENT;
3486 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
3487 scsi_event.lun = 0;
3488 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
3489 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
3490
James Smartbbb9d182009-06-10 17:23:16 -04003491 fc_host_post_vendor_event(shost, fc_get_event_number(),
3492 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
dea31012005-04-17 16:05:31 -05003493
Christof Schmitt65d430f2009-10-30 17:59:29 +01003494 fc_block_scsi_eh(cmnd);
James Smartbbb9d182009-06-10 17:23:16 -04003495
dea31012005-04-17 16:05:31 -05003496 /*
3497 * Since the driver manages a single bus device, reset all
3498 * targets known to the driver. Should any target reset
3499 * fail, this routine returns failure to the midlayer.
3500 */
James Smarte17da182006-07-06 15:49:25 -04003501 for (i = 0; i < LPFC_MAX_TARGET; i++) {
James Smart685f0bf2007-04-25 09:53:08 -04003502 /* Search for mapped node by target ID */
dea31012005-04-17 16:05:31 -05003503 match = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003504 spin_lock_irq(shost->host_lock);
3505 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003506 if (!NLP_CHK_NODE_ACT(ndlp))
3507 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003508 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart915caaa2008-06-14 22:52:38 -04003509 ndlp->nlp_sid == i &&
James Smart685f0bf2007-04-25 09:53:08 -04003510 ndlp->rport) {
dea31012005-04-17 16:05:31 -05003511 match = 1;
3512 break;
3513 }
3514 }
James Smart2e0fef82007-06-17 19:56:36 -05003515 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003516 if (!match)
3517 continue;
James Smartbbb9d182009-06-10 17:23:16 -04003518
3519 status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
3520 i, 0, FCP_TARGET_RESET);
3521
3522 if (status != SUCCESS) {
James Smarte8b62012007-08-02 11:10:09 -04003523 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3524 "0700 Bus Reset on target %d failed\n",
3525 i);
James Smart915caaa2008-06-14 22:52:38 -04003526 ret = FAILED;
dea31012005-04-17 16:05:31 -05003527 }
3528 }
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05003529 /*
James Smartbbb9d182009-06-10 17:23:16 -04003530 * We have to clean up i/o as : they may be orphaned by the TMFs
3531 * above; or if any of the TMFs failed, they may be in an
3532 * indeterminate state.
3533 * We will report success if all the i/o aborts successfully.
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05003534 */
James Smartbbb9d182009-06-10 17:23:16 -04003535
3536 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
3537 if (status != SUCCESS)
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05003538 ret = FAILED;
James Smartbbb9d182009-06-10 17:23:16 -04003539
James Smarte8b62012007-08-02 11:10:09 -04003540 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3541 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
dea31012005-04-17 16:05:31 -05003542 return ret;
3543}
3544
James Smart9bad7672008-12-04 22:39:02 -05003545/**
James Smart3621a712009-04-06 18:47:14 -04003546 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
James Smart9bad7672008-12-04 22:39:02 -05003547 * @sdev: Pointer to scsi_device.
3548 *
3549 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
3550 * globally available list of scsi buffers. This routine also makes sure scsi
3551 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
3552 * of scsi buffer exists for the lifetime of the driver.
3553 *
3554 * Return codes:
3555 * non-0 - Error
3556 * 0 - Success
3557 **/
dea31012005-04-17 16:05:31 -05003558static int
dea31012005-04-17 16:05:31 -05003559lpfc_slave_alloc(struct scsi_device *sdev)
3560{
James Smart2e0fef82007-06-17 19:56:36 -05003561 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
3562 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003563 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
James Smart3772a992009-05-22 14:50:54 -04003564 uint32_t total = 0;
dea31012005-04-17 16:05:31 -05003565 uint32_t num_to_alloc = 0;
James Smart3772a992009-05-22 14:50:54 -04003566 int num_allocated = 0;
dea31012005-04-17 16:05:31 -05003567
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003568 if (!rport || fc_remote_port_chkready(rport))
dea31012005-04-17 16:05:31 -05003569 return -ENXIO;
3570
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003571 sdev->hostdata = rport->dd_data;
dea31012005-04-17 16:05:31 -05003572
3573 /*
3574 * Populate the cmds_per_lun count scsi_bufs into this host's globally
3575 * available list of scsi buffers. Don't allocate more than the
James.Smart@Emulex.Coma784efb2005-10-28 20:29:51 -04003576 * HBA limit conveyed to the midlayer via the host structure. The
3577 * formula accounts for the lun_queue_depth + error handlers + 1
3578 * extra. This list of scsi bufs exists for the lifetime of the driver.
dea31012005-04-17 16:05:31 -05003579 */
3580 total = phba->total_scsi_bufs;
James Smart3de2a652007-08-02 11:09:59 -04003581 num_to_alloc = vport->cfg_lun_queue_depth + 2;
James Smart92d7f7b2007-06-17 19:56:38 -05003582
3583 /* Allow some exchanges to be available always to complete discovery */
3584 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04003585 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3586 "0704 At limitation of %d preallocated "
3587 "command buffers\n", total);
dea31012005-04-17 16:05:31 -05003588 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003589 /* Allow some exchanges to be available always to complete discovery */
3590 } else if (total + num_to_alloc >
3591 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04003592 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3593 "0705 Allocation request of %d "
3594 "command buffers will exceed max of %d. "
3595 "Reducing allocation request to %d.\n",
3596 num_to_alloc, phba->cfg_hba_queue_depth,
3597 (phba->cfg_hba_queue_depth - total));
dea31012005-04-17 16:05:31 -05003598 num_to_alloc = phba->cfg_hba_queue_depth - total;
3599 }
James Smart3772a992009-05-22 14:50:54 -04003600 num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc);
3601 if (num_to_alloc != num_allocated) {
3602 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3603 "0708 Allocation request of %d "
3604 "command buffers did not succeed. "
3605 "Allocated %d buffers.\n",
3606 num_to_alloc, num_allocated);
dea31012005-04-17 16:05:31 -05003607 }
James Smart1c6f4ef52009-11-18 15:40:49 -05003608 if (num_allocated > 0)
3609 phba->total_scsi_bufs += num_allocated;
dea31012005-04-17 16:05:31 -05003610 return 0;
3611}
3612
James Smart9bad7672008-12-04 22:39:02 -05003613/**
James Smart3621a712009-04-06 18:47:14 -04003614 * lpfc_slave_configure - scsi_host_template slave_configure entry point
James Smart9bad7672008-12-04 22:39:02 -05003615 * @sdev: Pointer to scsi_device.
3616 *
3617 * This routine configures following items
3618 * - Tag command queuing support for @sdev if supported.
3619 * - Dev loss time out value of fc_rport.
3620 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
3621 *
3622 * Return codes:
3623 * 0 - Success
3624 **/
dea31012005-04-17 16:05:31 -05003625static int
3626lpfc_slave_configure(struct scsi_device *sdev)
3627{
James Smart2e0fef82007-06-17 19:56:36 -05003628 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
3629 struct lpfc_hba *phba = vport->phba;
3630 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
dea31012005-04-17 16:05:31 -05003631
3632 if (sdev->tagged_supported)
James Smart3de2a652007-08-02 11:09:59 -04003633 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05003634 else
James Smart3de2a652007-08-02 11:09:59 -04003635 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05003636
3637 /*
3638 * Initialize the fc transport attributes for the target
3639 * containing this scsi device. Also note that the driver's
3640 * target pointer is stored in the starget_data for the
3641 * driver's sysfs entry point functions.
3642 */
James Smart3de2a652007-08-02 11:09:59 -04003643 rport->dev_loss_tmo = vport->cfg_devloss_tmo;
dea31012005-04-17 16:05:31 -05003644
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003645 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04003646 lpfc_sli_handle_fast_ring_event(phba,
3647 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003648 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
3649 lpfc_poll_rearm_timer(phba);
3650 }
3651
dea31012005-04-17 16:05:31 -05003652 return 0;
3653}
3654
James Smart9bad7672008-12-04 22:39:02 -05003655/**
James Smart3621a712009-04-06 18:47:14 -04003656 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
James Smart9bad7672008-12-04 22:39:02 -05003657 * @sdev: Pointer to scsi_device.
3658 *
3659 * This routine sets @sdev hostatdata filed to null.
3660 **/
dea31012005-04-17 16:05:31 -05003661static void
3662lpfc_slave_destroy(struct scsi_device *sdev)
3663{
3664 sdev->hostdata = NULL;
3665 return;
3666}
3667
James Smart92d7f7b2007-06-17 19:56:38 -05003668
dea31012005-04-17 16:05:31 -05003669struct scsi_host_template lpfc_template = {
3670 .module = THIS_MODULE,
3671 .name = LPFC_DRIVER_NAME,
3672 .info = lpfc_info,
3673 .queuecommand = lpfc_queuecommand,
3674 .eh_abort_handler = lpfc_abort_handler,
James Smartbbb9d182009-06-10 17:23:16 -04003675 .eh_device_reset_handler = lpfc_device_reset_handler,
3676 .eh_target_reset_handler = lpfc_target_reset_handler,
James Smart7054a602007-04-25 09:52:34 -04003677 .eh_bus_reset_handler = lpfc_bus_reset_handler,
dea31012005-04-17 16:05:31 -05003678 .slave_alloc = lpfc_slave_alloc,
3679 .slave_configure = lpfc_slave_configure,
3680 .slave_destroy = lpfc_slave_destroy,
James Smart47a86172007-04-25 09:53:22 -04003681 .scan_finished = lpfc_scan_finished,
dea31012005-04-17 16:05:31 -05003682 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05003683 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
dea31012005-04-17 16:05:31 -05003684 .cmd_per_lun = LPFC_CMD_PER_LUN,
3685 .use_clustering = ENABLE_CLUSTERING,
James Smart2e0fef82007-06-17 19:56:36 -05003686 .shost_attrs = lpfc_hba_attrs,
James.Smart@Emulex.Com564b2962005-06-25 10:34:17 -04003687 .max_sectors = 0xFFFF,
James Smartf1c3b0f2009-07-19 10:01:32 -04003688 .vendor_id = LPFC_NL_VENDOR_ID,
James Smart5ffc2662009-11-18 15:39:44 -05003689 .change_queue_depth = lpfc_change_queue_depth,
dea31012005-04-17 16:05:31 -05003690};
James Smart3de2a652007-08-02 11:09:59 -04003691
3692struct scsi_host_template lpfc_vport_template = {
3693 .module = THIS_MODULE,
3694 .name = LPFC_DRIVER_NAME,
3695 .info = lpfc_info,
3696 .queuecommand = lpfc_queuecommand,
3697 .eh_abort_handler = lpfc_abort_handler,
James Smartbbb9d182009-06-10 17:23:16 -04003698 .eh_device_reset_handler = lpfc_device_reset_handler,
3699 .eh_target_reset_handler = lpfc_target_reset_handler,
James Smart3de2a652007-08-02 11:09:59 -04003700 .eh_bus_reset_handler = lpfc_bus_reset_handler,
3701 .slave_alloc = lpfc_slave_alloc,
3702 .slave_configure = lpfc_slave_configure,
3703 .slave_destroy = lpfc_slave_destroy,
3704 .scan_finished = lpfc_scan_finished,
3705 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05003706 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
James Smart3de2a652007-08-02 11:09:59 -04003707 .cmd_per_lun = LPFC_CMD_PER_LUN,
3708 .use_clustering = ENABLE_CLUSTERING,
3709 .shost_attrs = lpfc_vport_attrs,
3710 .max_sectors = 0xFFFF,
James Smart5ffc2662009-11-18 15:39:44 -05003711 .change_queue_depth = lpfc_change_queue_depth,
James Smart3de2a652007-08-02 11:09:59 -04003712};