blob: f68753ea941fe905a14c6454029c3fff42601540 [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;
James Smart75baf692010-06-08 18:31:21 -04002298 struct scsi_cmnd *cmd;
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 Smart75baf692010-06-08 18:31:21 -04002304 struct Scsi_Host *shost;
James Smarta257bf92009-04-06 18:48:10 -04002305 uint32_t queue_depth, scsi_id;
dea31012005-04-17 16:05:31 -05002306
James Smart75baf692010-06-08 18:31:21 -04002307 /* Sanity check on return of outstanding command */
2308 if (!(lpfc_cmd->pCmd))
2309 return;
2310 cmd = lpfc_cmd->pCmd;
2311 shost = cmd->device->host;
2312
dea31012005-04-17 16:05:31 -05002313 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
2314 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
James Smart341af102010-01-26 23:07:37 -05002315 /* pick up SLI4 exhange busy status from HBA */
2316 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
2317
James Smart109f6ed2008-12-04 22:39:08 -05002318 if (pnode && NLP_CHK_NODE_ACT(pnode))
2319 atomic_dec(&pnode->cmd_pending);
dea31012005-04-17 16:05:31 -05002320
2321 if (lpfc_cmd->status) {
2322 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
2323 (lpfc_cmd->result & IOERR_DRVR_MASK))
2324 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
2325 else if (lpfc_cmd->status >= IOSTAT_CNT)
2326 lpfc_cmd->status = IOSTAT_DEFAULT;
2327
James Smarte8b62012007-08-02 11:10:09 -04002328 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
James Smarte2a0a9d2008-12-04 22:40:02 -05002329 "9030 FCP cmd x%x failed <%d/%d> "
James Smarte8b62012007-08-02 11:10:09 -04002330 "status: x%x result: x%x Data: x%x x%x\n",
2331 cmd->cmnd[0],
2332 cmd->device ? cmd->device->id : 0xffff,
2333 cmd->device ? cmd->device->lun : 0xffff,
2334 lpfc_cmd->status, lpfc_cmd->result,
2335 pIocbOut->iocb.ulpContext,
2336 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05002337
2338 switch (lpfc_cmd->status) {
2339 case IOSTAT_FCP_RSP_ERROR:
2340 /* Call FCP RSP handler to determine result */
James Smart2e0fef82007-06-17 19:56:36 -05002341 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
dea31012005-04-17 16:05:31 -05002342 break;
2343 case IOSTAT_NPORT_BSY:
2344 case IOSTAT_FABRIC_BSY:
James Smart0f1f53a2008-08-24 21:50:18 -04002345 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
James Smartea2151b2008-09-07 11:52:10 -04002346 fast_path_evt = lpfc_alloc_fast_evt(phba);
2347 if (!fast_path_evt)
2348 break;
2349 fast_path_evt->un.fabric_evt.event_type =
2350 FC_REG_FABRIC_EVENT;
2351 fast_path_evt->un.fabric_evt.subcategory =
2352 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
2353 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
2354 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
2355 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
2356 &pnode->nlp_portname,
2357 sizeof(struct lpfc_name));
2358 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
2359 &pnode->nlp_nodename,
2360 sizeof(struct lpfc_name));
2361 }
2362 fast_path_evt->vport = vport;
2363 fast_path_evt->work_evt.evt =
2364 LPFC_EVT_FASTPATH_MGMT_EVT;
2365 spin_lock_irqsave(&phba->hbalock, flags);
2366 list_add_tail(&fast_path_evt->work_evt.evt_listp,
2367 &phba->work_list);
2368 spin_unlock_irqrestore(&phba->hbalock, flags);
2369 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05002370 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002371 case IOSTAT_LOCAL_REJECT:
James Smartd7c255b2008-08-24 21:50:00 -04002372 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
James Smart92d7f7b2007-06-17 19:56:38 -05002373 lpfc_cmd->result == IOERR_NO_RESOURCES ||
James Smartb92938b2010-06-07 15:24:12 -04002374 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
2375 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
James Smart92d7f7b2007-06-17 19:56:38 -05002376 cmd->result = ScsiResult(DID_REQUEUE, 0);
James Smart58da1ff2008-04-07 10:15:56 -04002377 break;
James Smarte2a0a9d2008-12-04 22:40:02 -05002378 }
2379
2380 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
2381 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
2382 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
2383 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
2384 /*
2385 * This is a response for a BG enabled
2386 * cmd. Parse BG error
2387 */
2388 lpfc_parse_bg_err(phba, lpfc_cmd,
2389 pIocbOut);
2390 break;
2391 } else {
2392 lpfc_printf_vlog(vport, KERN_WARNING,
2393 LOG_BG,
2394 "9031 non-zero BGSTAT "
James Smart6a9c52c2009-10-02 15:16:51 -04002395 "on unprotected cmd\n");
James Smarte2a0a9d2008-12-04 22:40:02 -05002396 }
2397 }
2398
2399 /* else: fall through */
dea31012005-04-17 16:05:31 -05002400 default:
2401 cmd->result = ScsiResult(DID_ERROR, 0);
2402 break;
2403 }
2404
James Smart58da1ff2008-04-07 10:15:56 -04002405 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002406 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
James Smart0f1f53a2008-08-24 21:50:18 -04002407 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
2408 SAM_STAT_BUSY);
dea31012005-04-17 16:05:31 -05002409 } else {
2410 cmd->result = ScsiResult(DID_OK, 0);
2411 }
2412
2413 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
2414 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
2415
James Smarte8b62012007-08-02 11:10:09 -04002416 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
2417 "0710 Iodone <%d/%d> cmd %p, error "
2418 "x%x SNS x%x x%x Data: x%x x%x\n",
2419 cmd->device->id, cmd->device->lun, cmd,
2420 cmd->result, *lp, *(lp + 3), cmd->retries,
2421 scsi_get_resid(cmd));
dea31012005-04-17 16:05:31 -05002422 }
2423
James Smartea2151b2008-09-07 11:52:10 -04002424 lpfc_update_stats(phba, lpfc_cmd);
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002425 result = cmd->result;
James Smart977b5a02008-09-07 11:52:04 -04002426 if (vport->cfg_max_scsicmpl_time &&
2427 time_after(jiffies, lpfc_cmd->start_time +
2428 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
James Smarta257bf92009-04-06 18:48:10 -04002429 spin_lock_irqsave(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002430 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
2431 if (pnode->cmd_qdepth >
2432 atomic_read(&pnode->cmd_pending) &&
2433 (atomic_read(&pnode->cmd_pending) >
2434 LPFC_MIN_TGT_QDEPTH) &&
2435 ((cmd->cmnd[0] == READ_10) ||
2436 (cmd->cmnd[0] == WRITE_10)))
2437 pnode->cmd_qdepth =
2438 atomic_read(&pnode->cmd_pending);
James Smart977b5a02008-09-07 11:52:04 -04002439
James Smart109f6ed2008-12-04 22:39:08 -05002440 pnode->last_change_time = jiffies;
2441 }
James Smarta257bf92009-04-06 18:48:10 -04002442 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002443 } else if (pnode && NLP_CHK_NODE_ACT(pnode)) {
2444 if ((pnode->cmd_qdepth < LPFC_MAX_TGT_QDEPTH) &&
James Smart977b5a02008-09-07 11:52:04 -04002445 time_after(jiffies, pnode->last_change_time +
James Smart109f6ed2008-12-04 22:39:08 -05002446 msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) {
James Smarta257bf92009-04-06 18:48:10 -04002447 spin_lock_irqsave(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002448 pnode->cmd_qdepth += pnode->cmd_qdepth *
2449 LPFC_TGTQ_RAMPUP_PCENT / 100;
2450 if (pnode->cmd_qdepth > LPFC_MAX_TGT_QDEPTH)
2451 pnode->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2452 pnode->last_change_time = jiffies;
James Smarta257bf92009-04-06 18:48:10 -04002453 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart109f6ed2008-12-04 22:39:08 -05002454 }
James Smart977b5a02008-09-07 11:52:04 -04002455 }
2456
James Smart1dcb58e2007-04-25 09:51:30 -04002457 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
James Smarta257bf92009-04-06 18:48:10 -04002458
2459 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
2460 queue_depth = cmd->device->queue_depth;
2461 scsi_id = cmd->device->id;
dea31012005-04-17 16:05:31 -05002462 cmd->scsi_done(cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002463
Jamie Wellnitzb8086082006-02-28 22:33:12 -05002464 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smartfa61a542008-01-11 01:52:42 -05002465 /*
2466 * If there is a thread waiting for command completion
2467 * wake up the thread.
2468 */
James Smarta257bf92009-04-06 18:48:10 -04002469 spin_lock_irqsave(shost->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -04002470 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -05002471 if (lpfc_cmd->waitq)
2472 wake_up(lpfc_cmd->waitq);
James Smarta257bf92009-04-06 18:48:10 -04002473 spin_unlock_irqrestore(shost->host_lock, flags);
Jamie Wellnitzb8086082006-02-28 22:33:12 -05002474 lpfc_release_scsi_buf(phba, lpfc_cmd);
2475 return;
2476 }
2477
James Smart92d7f7b2007-06-17 19:56:38 -05002478 if (!result)
James Smarta257bf92009-04-06 18:48:10 -04002479 lpfc_rampup_queue_depth(vport, queue_depth);
James Smart92d7f7b2007-06-17 19:56:38 -05002480
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002481 /*
2482 * Check for queue full. If the lun is reporting queue full, then
2483 * back off the lun queue depth to prevent target overloads.
2484 */
James Smart58da1ff2008-04-07 10:15:56 -04002485 if (result == SAM_STAT_TASK_SET_FULL && pnode &&
2486 NLP_CHK_NODE_ACT(pnode)) {
James Smarta257bf92009-04-06 18:48:10 -04002487 shost_for_each_device(tmp_sdev, shost) {
2488 if (tmp_sdev->id != scsi_id)
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002489 continue;
2490 depth = scsi_track_queue_full(tmp_sdev,
James Smart5ffc2662009-11-18 15:39:44 -05002491 tmp_sdev->queue_depth-1);
2492 if (depth <= 0)
2493 continue;
James Smarte8b62012007-08-02 11:10:09 -04002494 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
2495 "0711 detected queue full - lun queue "
2496 "depth adjusted to %d.\n", depth);
James Smartea2151b2008-09-07 11:52:10 -04002497 lpfc_send_sdev_queuedepth_change_event(phba, vport,
James Smart5ffc2662009-11-18 15:39:44 -05002498 pnode,
2499 tmp_sdev->lun,
2500 depth+1, depth);
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -05002501 }
2502 }
2503
James Smartfa61a542008-01-11 01:52:42 -05002504 /*
2505 * If there is a thread waiting for command completion
2506 * wake up the thread.
2507 */
James Smarta257bf92009-04-06 18:48:10 -04002508 spin_lock_irqsave(shost->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -04002509 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -05002510 if (lpfc_cmd->waitq)
2511 wake_up(lpfc_cmd->waitq);
James Smarta257bf92009-04-06 18:48:10 -04002512 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartfa61a542008-01-11 01:52:42 -05002513
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002514 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05002515}
2516
James Smart34b02dc2008-08-24 21:49:55 -04002517/**
James Smart3621a712009-04-06 18:47:14 -04002518 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
James Smart34b02dc2008-08-24 21:49:55 -04002519 * @data: A pointer to the immediate command data portion of the IOCB.
2520 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
2521 *
2522 * The routine copies the entire FCP command from @fcp_cmnd to @data while
2523 * byte swapping the data to big endian format for transmission on the wire.
2524 **/
2525static void
2526lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
2527{
2528 int i, j;
2529 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
2530 i += sizeof(uint32_t), j++) {
2531 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
2532 }
2533}
2534
James Smart9bad7672008-12-04 22:39:02 -05002535/**
James Smartf1126682009-06-10 17:22:44 -04002536 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
James Smart9bad7672008-12-04 22:39:02 -05002537 * @vport: The virtual port for which this call is being executed.
2538 * @lpfc_cmd: The scsi command which needs to send.
2539 * @pnode: Pointer to lpfc_nodelist.
2540 *
2541 * This routine initializes fcp_cmnd and iocb data structure from scsi command
James Smart3772a992009-05-22 14:50:54 -04002542 * to transfer for device with SLI3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05002543 **/
dea31012005-04-17 16:05:31 -05002544static void
James Smartf1126682009-06-10 17:22:44 -04002545lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
James Smart2e0fef82007-06-17 19:56:36 -05002546 struct lpfc_nodelist *pnode)
dea31012005-04-17 16:05:31 -05002547{
James Smart2e0fef82007-06-17 19:56:36 -05002548 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002549 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2550 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2551 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2552 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
2553 int datadir = scsi_cmnd->sc_data_direction;
James Smart7e2b19f2007-10-29 11:00:39 -04002554 char tag[2];
dea31012005-04-17 16:05:31 -05002555
James Smart58da1ff2008-04-07 10:15:56 -04002556 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
2557 return;
2558
dea31012005-04-17 16:05:31 -05002559 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
James.Smart@Emulex.Com69859dc2005-08-10 15:02:37 -04002560 /* clear task management bits */
2561 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
dea31012005-04-17 16:05:31 -05002562
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -04002563 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
2564 &lpfc_cmd->fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -05002565
2566 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
2567
James Smart7e2b19f2007-10-29 11:00:39 -04002568 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
2569 switch (tag[0]) {
dea31012005-04-17 16:05:31 -05002570 case HEAD_OF_QUEUE_TAG:
2571 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
2572 break;
2573 case ORDERED_QUEUE_TAG:
2574 fcp_cmnd->fcpCntl1 = ORDERED_Q;
2575 break;
2576 default:
2577 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
2578 break;
2579 }
2580 } else
2581 fcp_cmnd->fcpCntl1 = 0;
2582
2583 /*
2584 * There are three possibilities here - use scatter-gather segment, use
2585 * the single mapping, or neither. Start the lpfc command prep by
2586 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
2587 * data bde entry.
2588 */
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -05002589 if (scsi_sg_count(scsi_cmnd)) {
dea31012005-04-17 16:05:31 -05002590 if (datadir == DMA_TO_DEVICE) {
2591 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
James Smart3772a992009-05-22 14:50:54 -04002592 if (phba->sli_rev < LPFC_SLI_REV4) {
2593 iocb_cmd->un.fcpi.fcpi_parm = 0;
2594 iocb_cmd->ulpPU = 0;
2595 } else
2596 iocb_cmd->ulpPU = PARM_READ_CHECK;
dea31012005-04-17 16:05:31 -05002597 fcp_cmnd->fcpCntl3 = WRITE_DATA;
2598 phba->fc4OutputRequests++;
2599 } else {
2600 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
2601 iocb_cmd->ulpPU = PARM_READ_CHECK;
dea31012005-04-17 16:05:31 -05002602 fcp_cmnd->fcpCntl3 = READ_DATA;
2603 phba->fc4InputRequests++;
2604 }
2605 } else {
2606 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
2607 iocb_cmd->un.fcpi.fcpi_parm = 0;
2608 iocb_cmd->ulpPU = 0;
2609 fcp_cmnd->fcpCntl3 = 0;
2610 phba->fc4ControlRequests++;
2611 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002612 if (phba->sli_rev == 3 &&
2613 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
James Smart34b02dc2008-08-24 21:49:55 -04002614 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -05002615 /*
2616 * Finish initializing those IOCB fields that are independent
2617 * of the scsi_cmnd request_buffer
2618 */
2619 piocbq->iocb.ulpContext = pnode->nlp_rpi;
2620 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
2621 piocbq->iocb.ulpFCP2Rcvy = 1;
James Smart09372822008-01-11 01:52:54 -05002622 else
2623 piocbq->iocb.ulpFCP2Rcvy = 0;
dea31012005-04-17 16:05:31 -05002624
2625 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
2626 piocbq->context1 = lpfc_cmd;
2627 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
2628 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002629 piocbq->vport = vport;
dea31012005-04-17 16:05:31 -05002630}
2631
James Smart9bad7672008-12-04 22:39:02 -05002632/**
James Smartf1126682009-06-10 17:22:44 -04002633 * lpfc_scsi_prep_task_mgmt_cmnd - Convert SLI3 scsi TM cmd to FCP info unit
James Smart9bad7672008-12-04 22:39:02 -05002634 * @vport: The virtual port for which this call is being executed.
2635 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2636 * @lun: Logical unit number.
2637 * @task_mgmt_cmd: SCSI task management command.
2638 *
James Smart3772a992009-05-22 14:50:54 -04002639 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
2640 * for device with SLI-3 interface spec.
James Smart9bad7672008-12-04 22:39:02 -05002641 *
2642 * Return codes:
2643 * 0 - Error
2644 * 1 - Success
2645 **/
dea31012005-04-17 16:05:31 -05002646static int
James Smartf1126682009-06-10 17:22:44 -04002647lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
dea31012005-04-17 16:05:31 -05002648 struct lpfc_scsi_buf *lpfc_cmd,
James Smart420b630d2006-07-06 15:50:16 -04002649 unsigned int lun,
dea31012005-04-17 16:05:31 -05002650 uint8_t task_mgmt_cmd)
2651{
dea31012005-04-17 16:05:31 -05002652 struct lpfc_iocbq *piocbq;
2653 IOCB_t *piocb;
2654 struct fcp_cmnd *fcp_cmnd;
James Smart0b18ac42006-05-01 21:50:40 -04002655 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
dea31012005-04-17 16:05:31 -05002656 struct lpfc_nodelist *ndlp = rdata->pnode;
2657
James Smart58da1ff2008-04-07 10:15:56 -04002658 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
2659 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
dea31012005-04-17 16:05:31 -05002660 return 0;
dea31012005-04-17 16:05:31 -05002661
dea31012005-04-17 16:05:31 -05002662 piocbq = &(lpfc_cmd->cur_iocbq);
James Smart2e0fef82007-06-17 19:56:36 -05002663 piocbq->vport = vport;
2664
dea31012005-04-17 16:05:31 -05002665 piocb = &piocbq->iocb;
2666
2667 fcp_cmnd = lpfc_cmd->fcp_cmnd;
James Smart34b02dc2008-08-24 21:49:55 -04002668 /* Clear out any old data in the FCP command area */
2669 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
2670 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -05002671 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
James Smarte2a0a9d2008-12-04 22:40:02 -05002672 if (vport->phba->sli_rev == 3 &&
2673 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
James Smart34b02dc2008-08-24 21:49:55 -04002674 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -05002675 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
dea31012005-04-17 16:05:31 -05002676 piocb->ulpContext = ndlp->nlp_rpi;
2677 if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
2678 piocb->ulpFCP2Rcvy = 1;
2679 }
2680 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
2681
2682 /* ulpTimeout is only one byte */
2683 if (lpfc_cmd->timeout > 0xff) {
2684 /*
2685 * Do not timeout the command at the firmware level.
2686 * The driver will provide the timeout mechanism.
2687 */
2688 piocb->ulpTimeout = 0;
James Smartf1126682009-06-10 17:22:44 -04002689 } else
dea31012005-04-17 16:05:31 -05002690 piocb->ulpTimeout = lpfc_cmd->timeout;
James Smartf1126682009-06-10 17:22:44 -04002691
2692 if (vport->phba->sli_rev == LPFC_SLI_REV4)
2693 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05002694
James Smart2e0fef82007-06-17 19:56:36 -05002695 return 1;
dea31012005-04-17 16:05:31 -05002696}
2697
James Smart9bad7672008-12-04 22:39:02 -05002698/**
James Smart3772a992009-05-22 14:50:54 -04002699 * lpfc_scsi_api_table_setup - Set up scsi api fucntion jump table
2700 * @phba: The hba struct for which this call is being executed.
2701 * @dev_grp: The HBA PCI-Device group number.
2702 *
2703 * This routine sets up the SCSI interface API function jump table in @phba
2704 * struct.
2705 * Returns: 0 - success, -ENODEV - failure.
2706 **/
2707int
2708lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
2709{
2710
James Smartf1126682009-06-10 17:22:44 -04002711 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
2712 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
2713 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf;
2714
James Smart3772a992009-05-22 14:50:54 -04002715 switch (dev_grp) {
2716 case LPFC_PCI_DEV_LP:
2717 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
2718 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
James Smart3772a992009-05-22 14:50:54 -04002719 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
2720 break;
James Smartda0436e2009-05-22 14:51:39 -04002721 case LPFC_PCI_DEV_OC:
2722 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
2723 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
James Smartda0436e2009-05-22 14:51:39 -04002724 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
2725 break;
James Smart3772a992009-05-22 14:50:54 -04002726 default:
2727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2728 "1418 Invalid HBA PCI-device group: 0x%x\n",
2729 dev_grp);
2730 return -ENODEV;
2731 break;
2732 }
2733 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf;
2734 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
James Smart84d1b002010-02-12 14:42:33 -05002735 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
James Smart3772a992009-05-22 14:50:54 -04002736 return 0;
2737}
2738
2739/**
James Smart3621a712009-04-06 18:47:14 -04002740 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
James Smart9bad7672008-12-04 22:39:02 -05002741 * @phba: The Hba for which this call is being executed.
2742 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
2743 * @rspiocbq: Pointer to lpfc_iocbq data structure.
2744 *
2745 * This routine is IOCB completion routine for device reset and target reset
2746 * routine. This routine release scsi buffer associated with lpfc_cmd.
2747 **/
James Smart7054a602007-04-25 09:52:34 -04002748static void
2749lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
2750 struct lpfc_iocbq *cmdiocbq,
2751 struct lpfc_iocbq *rspiocbq)
2752{
2753 struct lpfc_scsi_buf *lpfc_cmd =
2754 (struct lpfc_scsi_buf *) cmdiocbq->context1;
2755 if (lpfc_cmd)
2756 lpfc_release_scsi_buf(phba, lpfc_cmd);
2757 return;
2758}
2759
James Smart9bad7672008-12-04 22:39:02 -05002760/**
James Smart3621a712009-04-06 18:47:14 -04002761 * lpfc_info - Info entry point of scsi_host_template data structure
James Smart9bad7672008-12-04 22:39:02 -05002762 * @host: The scsi host for which this call is being executed.
2763 *
2764 * This routine provides module information about hba.
2765 *
2766 * Reutrn code:
2767 * Pointer to char - Success.
2768 **/
dea31012005-04-17 16:05:31 -05002769const char *
2770lpfc_info(struct Scsi_Host *host)
2771{
James Smart2e0fef82007-06-17 19:56:36 -05002772 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
2773 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002774 int len;
2775 static char lpfcinfobuf[384];
2776
2777 memset(lpfcinfobuf,0,384);
2778 if (phba && phba->pcidev){
2779 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
2780 len = strlen(lpfcinfobuf);
2781 snprintf(lpfcinfobuf + len,
2782 384-len,
2783 " on PCI bus %02x device %02x irq %d",
2784 phba->pcidev->bus->number,
2785 phba->pcidev->devfn,
2786 phba->pcidev->irq);
2787 len = strlen(lpfcinfobuf);
2788 if (phba->Port[0]) {
2789 snprintf(lpfcinfobuf + len,
2790 384-len,
2791 " port %s",
2792 phba->Port);
2793 }
James Smart65467b62010-01-26 23:08:29 -05002794 len = strlen(lpfcinfobuf);
2795 if (phba->sli4_hba.link_state.logical_speed) {
2796 snprintf(lpfcinfobuf + len,
2797 384-len,
2798 " Logical Link Speed: %d Mbps",
2799 phba->sli4_hba.link_state.logical_speed * 10);
2800 }
dea31012005-04-17 16:05:31 -05002801 }
2802 return lpfcinfobuf;
2803}
2804
James Smart9bad7672008-12-04 22:39:02 -05002805/**
James Smart3621a712009-04-06 18:47:14 -04002806 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
James Smart9bad7672008-12-04 22:39:02 -05002807 * @phba: The Hba for which this call is being executed.
2808 *
2809 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
2810 * The default value of cfg_poll_tmo is 10 milliseconds.
2811 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002812static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
2813{
2814 unsigned long poll_tmo_expires =
2815 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
2816
2817 if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
2818 mod_timer(&phba->fcp_poll_timer,
2819 poll_tmo_expires);
2820}
2821
James Smart9bad7672008-12-04 22:39:02 -05002822/**
James Smart3621a712009-04-06 18:47:14 -04002823 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
James Smart9bad7672008-12-04 22:39:02 -05002824 * @phba: The Hba for which this call is being executed.
2825 *
2826 * This routine starts the fcp_poll_timer of @phba.
2827 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002828void lpfc_poll_start_timer(struct lpfc_hba * phba)
2829{
2830 lpfc_poll_rearm_timer(phba);
2831}
2832
James Smart9bad7672008-12-04 22:39:02 -05002833/**
James Smart3621a712009-04-06 18:47:14 -04002834 * lpfc_poll_timeout - Restart polling timer
James Smart9bad7672008-12-04 22:39:02 -05002835 * @ptr: Map to lpfc_hba data structure pointer.
2836 *
2837 * This routine restarts fcp_poll timer, when FCP ring polling is enable
2838 * and FCP Ring interrupt is disable.
2839 **/
2840
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002841void lpfc_poll_timeout(unsigned long ptr)
2842{
James Smart2e0fef82007-06-17 19:56:36 -05002843 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002844
2845 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04002846 lpfc_sli_handle_fast_ring_event(phba,
2847 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
2848
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002849 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
2850 lpfc_poll_rearm_timer(phba);
2851 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002852}
2853
James Smart9bad7672008-12-04 22:39:02 -05002854/**
James Smart3621a712009-04-06 18:47:14 -04002855 * lpfc_queuecommand - scsi_host_template queuecommand entry point
James Smart9bad7672008-12-04 22:39:02 -05002856 * @cmnd: Pointer to scsi_cmnd data structure.
2857 * @done: Pointer to done routine.
2858 *
2859 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
2860 * This routine prepares an IOCB from scsi command and provides to firmware.
2861 * The @done callback is invoked after driver finished processing the command.
2862 *
2863 * Return value :
2864 * 0 - Success
2865 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
2866 **/
dea31012005-04-17 16:05:31 -05002867static int
2868lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
2869{
James Smart2e0fef82007-06-17 19:56:36 -05002870 struct Scsi_Host *shost = cmnd->device->host;
2871 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2872 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002873 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05002874 struct lpfc_nodelist *ndlp;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002875 struct lpfc_scsi_buf *lpfc_cmd;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002876 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002877 int err;
dea31012005-04-17 16:05:31 -05002878
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002879 err = fc_remote_port_chkready(rport);
2880 if (err) {
2881 cmnd->result = err;
dea31012005-04-17 16:05:31 -05002882 goto out_fail_command;
2883 }
James Smart1c6f4ef52009-11-18 15:40:49 -05002884 ndlp = rdata->pnode;
dea31012005-04-17 16:05:31 -05002885
James Smarte2a0a9d2008-12-04 22:40:02 -05002886 if (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
2887 scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
2888
James Smart6a9c52c2009-10-02 15:16:51 -04002889 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2890 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
2891 " op:%02x str=%s without registering for"
2892 " BlockGuard - Rejecting command\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002893 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
2894 dif_op_str[scsi_get_prot_op(cmnd)]);
2895 goto out_fail_command;
2896 }
2897
dea31012005-04-17 16:05:31 -05002898 /*
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002899 * Catch race where our node has transitioned, but the
2900 * transport is still transitioning.
dea31012005-04-17 16:05:31 -05002901 */
James Smartb522d7d2008-09-07 11:51:56 -04002902 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
2903 cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
2904 goto out_fail_command;
2905 }
James Smart109f6ed2008-12-04 22:39:08 -05002906 if (vport->cfg_max_scsicmpl_time &&
2907 (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth))
James Smart977b5a02008-09-07 11:52:04 -04002908 goto out_host_busy;
Mike Christiea93ce022008-08-17 15:24:41 -05002909
James Smarted957682007-06-17 19:56:37 -05002910 lpfc_cmd = lpfc_get_scsi_buf(phba);
dea31012005-04-17 16:05:31 -05002911 if (lpfc_cmd == NULL) {
James Smarteaf15d52008-12-04 22:39:29 -05002912 lpfc_rampdown_queue_depth(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002913
James Smarte8b62012007-08-02 11:10:09 -04002914 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
2915 "0707 driver's buffer pool is empty, "
2916 "IO busied\n");
dea31012005-04-17 16:05:31 -05002917 goto out_host_busy;
2918 }
2919
2920 /*
2921 * Store the midlayer's command structure for the completion phase
2922 * and complete the command initialization.
2923 */
2924 lpfc_cmd->pCmd = cmnd;
2925 lpfc_cmd->rdata = rdata;
2926 lpfc_cmd->timeout = 0;
James Smart977b5a02008-09-07 11:52:04 -04002927 lpfc_cmd->start_time = jiffies;
dea31012005-04-17 16:05:31 -05002928 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
2929 cmnd->scsi_done = done;
2930
James Smarte2a0a9d2008-12-04 22:40:02 -05002931 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
James Smart6a9c52c2009-10-02 15:16:51 -04002932 if (vport->phba->cfg_enable_bg) {
2933 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002934 "9033 BLKGRD: rcvd protected cmd:%02x op:%02x "
2935 "str=%s\n",
2936 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
2937 dif_op_str[scsi_get_prot_op(cmnd)]);
James Smart6a9c52c2009-10-02 15:16:51 -04002938 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002939 "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x "
James Smarte4e74272009-07-19 10:01:38 -04002940 "%02x %02x %02x %02x %02x\n",
James Smarte2a0a9d2008-12-04 22:40:02 -05002941 cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2],
2942 cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5],
2943 cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8],
2944 cmnd->cmnd[9]);
James Smart6a9c52c2009-10-02 15:16:51 -04002945 if (cmnd->cmnd[0] == READ_10)
2946 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002947 "9035 BLKGRD: READ @ sector %llu, "
Tejun Heo83096eb2009-05-07 22:24:39 +09002948 "count %u\n",
2949 (unsigned long long)scsi_get_lba(cmnd),
2950 blk_rq_sectors(cmnd->request));
James Smart6a9c52c2009-10-02 15:16:51 -04002951 else if (cmnd->cmnd[0] == WRITE_10)
2952 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002953 "9036 BLKGRD: WRITE @ sector %llu, "
Tejun Heo83096eb2009-05-07 22:24:39 +09002954 "count %u cmd=%p\n",
James Smart87b5c322008-12-16 10:34:09 -05002955 (unsigned long long)scsi_get_lba(cmnd),
Tejun Heo83096eb2009-05-07 22:24:39 +09002956 blk_rq_sectors(cmnd->request),
James Smarte2a0a9d2008-12-04 22:40:02 -05002957 cmnd);
James Smart6a9c52c2009-10-02 15:16:51 -04002958 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002959
2960 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
2961 } else {
James Smart6a9c52c2009-10-02 15:16:51 -04002962 if (vport->phba->cfg_enable_bg) {
James Smarte2a0a9d2008-12-04 22:40:02 -05002963 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smart6a9c52c2009-10-02 15:16:51 -04002964 "9038 BLKGRD: rcvd unprotected cmd:"
2965 "%02x op:%02x str=%s\n",
2966 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
2967 dif_op_str[scsi_get_prot_op(cmnd)]);
2968 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2969 "9039 BLKGRD: CDB: %02x %02x %02x "
2970 "%02x %02x %02x %02x %02x %02x %02x\n",
2971 cmnd->cmnd[0], cmnd->cmnd[1],
2972 cmnd->cmnd[2], cmnd->cmnd[3],
2973 cmnd->cmnd[4], cmnd->cmnd[5],
2974 cmnd->cmnd[6], cmnd->cmnd[7],
2975 cmnd->cmnd[8], cmnd->cmnd[9]);
2976 if (cmnd->cmnd[0] == READ_10)
2977 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2978 "9040 dbg: READ @ sector %llu, "
2979 "count %u\n",
2980 (unsigned long long)scsi_get_lba(cmnd),
Tejun Heo83096eb2009-05-07 22:24:39 +09002981 blk_rq_sectors(cmnd->request));
James Smart6a9c52c2009-10-02 15:16:51 -04002982 else if (cmnd->cmnd[0] == WRITE_10)
2983 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002984 "9041 dbg: WRITE @ sector %llu, "
Tejun Heo83096eb2009-05-07 22:24:39 +09002985 "count %u cmd=%p\n",
James Smart87b5c322008-12-16 10:34:09 -05002986 (unsigned long long)scsi_get_lba(cmnd),
Tejun Heo83096eb2009-05-07 22:24:39 +09002987 blk_rq_sectors(cmnd->request), cmnd);
James Smart6a9c52c2009-10-02 15:16:51 -04002988 else
2989 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
James Smarte2a0a9d2008-12-04 22:40:02 -05002990 "9042 dbg: parser not implemented\n");
James Smart6a9c52c2009-10-02 15:16:51 -04002991 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002992 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
2993 }
2994
dea31012005-04-17 16:05:31 -05002995 if (err)
2996 goto out_host_busy_free_buf;
2997
James Smart2e0fef82007-06-17 19:56:36 -05002998 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
dea31012005-04-17 16:05:31 -05002999
James Smart977b5a02008-09-07 11:52:04 -04003000 atomic_inc(&ndlp->cmd_pending);
James Smart3772a992009-05-22 14:50:54 -04003001 err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
James Smart92d7f7b2007-06-17 19:56:38 -05003002 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
James Smarteaf15d52008-12-04 22:39:29 -05003003 if (err) {
3004 atomic_dec(&ndlp->cmd_pending);
dea31012005-04-17 16:05:31 -05003005 goto out_host_busy_free_buf;
James Smarteaf15d52008-12-04 22:39:29 -05003006 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003007 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04003008 spin_unlock(shost->host_lock);
3009 lpfc_sli_handle_fast_ring_event(phba,
3010 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
3011
3012 spin_lock(shost->host_lock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003013 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
3014 lpfc_poll_rearm_timer(phba);
3015 }
3016
dea31012005-04-17 16:05:31 -05003017 return 0;
3018
3019 out_host_busy_free_buf:
James Smartbcf4dbf2006-07-06 15:50:08 -04003020 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003021 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05003022 out_host_busy:
3023 return SCSI_MLQUEUE_HOST_BUSY;
3024
3025 out_fail_command:
3026 done(cmnd);
3027 return 0;
3028}
3029
James Smart9bad7672008-12-04 22:39:02 -05003030/**
James Smart3621a712009-04-06 18:47:14 -04003031 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
James Smart9bad7672008-12-04 22:39:02 -05003032 * @cmnd: Pointer to scsi_cmnd data structure.
3033 *
3034 * This routine aborts @cmnd pending in base driver.
3035 *
3036 * Return code :
3037 * 0x2003 - Error
3038 * 0x2002 - Success
3039 **/
dea31012005-04-17 16:05:31 -05003040static int
James.Smart@Emulex.Com63c59c32005-11-28 11:41:53 -05003041lpfc_abort_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05003042{
James Smart2e0fef82007-06-17 19:56:36 -05003043 struct Scsi_Host *shost = cmnd->device->host;
3044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3045 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003046 struct lpfc_iocbq *iocb;
3047 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05003048 struct lpfc_scsi_buf *lpfc_cmd;
dea31012005-04-17 16:05:31 -05003049 IOCB_t *cmd, *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003050 int ret = SUCCESS;
James Smartfa61a542008-01-11 01:52:42 -05003051 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003052
Christof Schmitt65d430f2009-10-30 17:59:29 +01003053 fc_block_scsi_eh(cmnd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003054 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
3055 BUG_ON(!lpfc_cmd);
dea31012005-04-17 16:05:31 -05003056
3057 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003058 * If pCmd field of the corresponding lpfc_scsi_buf structure
3059 * points to a different SCSI command, then the driver has
3060 * already completed this command, but the midlayer did not
3061 * see the completion before the eh fired. Just return
3062 * SUCCESS.
dea31012005-04-17 16:05:31 -05003063 */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003064 iocb = &lpfc_cmd->cur_iocbq;
3065 if (lpfc_cmd->pCmd != cmnd)
3066 goto out;
dea31012005-04-17 16:05:31 -05003067
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003068 BUG_ON(iocb->context1 != lpfc_cmd);
dea31012005-04-17 16:05:31 -05003069
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003070 abtsiocb = lpfc_sli_get_iocbq(phba);
3071 if (abtsiocb == NULL) {
3072 ret = FAILED;
dea31012005-04-17 16:05:31 -05003073 goto out;
3074 }
3075
dea31012005-04-17 16:05:31 -05003076 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003077 * The scsi command can not be in txq and it is in flight because the
3078 * pCmd is still pointig at the SCSI command we have to abort. There
3079 * is no need to search the txcmplq. Just send an abort to the FW.
dea31012005-04-17 16:05:31 -05003080 */
dea31012005-04-17 16:05:31 -05003081
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003082 cmd = &iocb->iocb;
3083 icmd = &abtsiocb->iocb;
3084 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
3085 icmd->un.acxri.abortContextTag = cmd->ulpContext;
James Smart3772a992009-05-22 14:50:54 -04003086 if (phba->sli_rev == LPFC_SLI_REV4)
3087 icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
3088 else
3089 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05003090
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003091 icmd->ulpLe = 1;
3092 icmd->ulpClass = cmd->ulpClass;
James Smart5ffc2662009-11-18 15:39:44 -05003093
3094 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
3095 abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
James Smart341af102010-01-26 23:07:37 -05003096 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
James Smart5ffc2662009-11-18 15:39:44 -05003097
James Smart2e0fef82007-06-17 19:56:36 -05003098 if (lpfc_is_link_up(phba))
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003099 icmd->ulpCommand = CMD_ABORT_XRI_CN;
3100 else
3101 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
dea31012005-04-17 16:05:31 -05003102
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003103 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
James Smart2e0fef82007-06-17 19:56:36 -05003104 abtsiocb->vport = vport;
James Smart3772a992009-05-22 14:50:54 -04003105 if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) ==
3106 IOCB_ERROR) {
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003107 lpfc_sli_release_iocbq(phba, abtsiocb);
3108 ret = FAILED;
3109 goto out;
3110 }
3111
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003112 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
James Smart45ed1192009-10-02 15:17:02 -04003113 lpfc_sli_handle_fast_ring_event(phba,
3114 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003115
James Smartfa61a542008-01-11 01:52:42 -05003116 lpfc_cmd->waitq = &waitq;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003117 /* Wait for abort to complete */
James Smartfa61a542008-01-11 01:52:42 -05003118 wait_event_timeout(waitq,
3119 (lpfc_cmd->pCmd != cmnd),
3120 (2*vport->cfg_devloss_tmo*HZ));
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003121
James Smartfa61a542008-01-11 01:52:42 -05003122 spin_lock_irq(shost->host_lock);
3123 lpfc_cmd->waitq = NULL;
3124 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003125
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003126 if (lpfc_cmd->pCmd == cmnd) {
3127 ret = FAILED;
James Smarte8b62012007-08-02 11:10:09 -04003128 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3129 "0748 abort handler timed out waiting "
3130 "for abort to complete: ret %#x, ID %d, "
3131 "LUN %d, snum %#lx\n",
3132 ret, cmnd->device->id, cmnd->device->lun,
3133 cmnd->serial_number);
dea31012005-04-17 16:05:31 -05003134 }
3135
3136 out:
James Smarte8b62012007-08-02 11:10:09 -04003137 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3138 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
3139 "LUN %d snum %#lx\n", ret, cmnd->device->id,
3140 cmnd->device->lun, cmnd->serial_number);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04003141 return ret;
dea31012005-04-17 16:05:31 -05003142}
3143
James Smartbbb9d182009-06-10 17:23:16 -04003144static char *
3145lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
3146{
3147 switch (task_mgmt_cmd) {
3148 case FCP_ABORT_TASK_SET:
3149 return "ABORT_TASK_SET";
3150 case FCP_CLEAR_TASK_SET:
3151 return "FCP_CLEAR_TASK_SET";
3152 case FCP_BUS_RESET:
3153 return "FCP_BUS_RESET";
3154 case FCP_LUN_RESET:
3155 return "FCP_LUN_RESET";
3156 case FCP_TARGET_RESET:
3157 return "FCP_TARGET_RESET";
3158 case FCP_CLEAR_ACA:
3159 return "FCP_CLEAR_ACA";
3160 case FCP_TERMINATE_TASK:
3161 return "FCP_TERMINATE_TASK";
3162 default:
3163 return "unknown";
3164 }
3165}
3166
3167/**
3168 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
3169 * @vport: The virtual port for which this call is being executed.
3170 * @rdata: Pointer to remote port local data
3171 * @tgt_id: Target ID of remote device.
3172 * @lun_id: Lun number for the TMF
3173 * @task_mgmt_cmd: type of TMF to send
3174 *
3175 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
3176 * a remote port.
3177 *
3178 * Return Code:
3179 * 0x2003 - Error
3180 * 0x2002 - Success.
3181 **/
3182static int
3183lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
3184 unsigned tgt_id, unsigned int lun_id,
3185 uint8_t task_mgmt_cmd)
3186{
3187 struct lpfc_hba *phba = vport->phba;
3188 struct lpfc_scsi_buf *lpfc_cmd;
3189 struct lpfc_iocbq *iocbq;
3190 struct lpfc_iocbq *iocbqrsp;
3191 int ret;
3192 int status;
3193
3194 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
3195 return FAILED;
3196
3197 lpfc_cmd = lpfc_get_scsi_buf(phba);
3198 if (lpfc_cmd == NULL)
3199 return FAILED;
3200 lpfc_cmd->timeout = 60;
3201 lpfc_cmd->rdata = rdata;
3202
3203 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
3204 task_mgmt_cmd);
3205 if (!status) {
3206 lpfc_release_scsi_buf(phba, lpfc_cmd);
3207 return FAILED;
3208 }
3209
3210 iocbq = &lpfc_cmd->cur_iocbq;
3211 iocbqrsp = lpfc_sli_get_iocbq(phba);
3212 if (iocbqrsp == NULL) {
3213 lpfc_release_scsi_buf(phba, lpfc_cmd);
3214 return FAILED;
3215 }
3216
3217 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3218 "0702 Issue %s to TGT %d LUN %d "
3219 "rpi x%x nlp_flag x%x\n",
3220 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
3221 rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
3222
3223 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
3224 iocbq, iocbqrsp, lpfc_cmd->timeout);
3225 if (status != IOCB_SUCCESS) {
3226 if (status == IOCB_TIMEDOUT) {
3227 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
3228 ret = TIMEOUT_ERROR;
3229 } else
3230 ret = FAILED;
3231 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3232 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3233 "0727 TMF %s to TGT %d LUN %d failed (%d, %d)\n",
3234 lpfc_taskmgmt_name(task_mgmt_cmd),
3235 tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
3236 iocbqrsp->iocb.un.ulpWord[4]);
James Smart2a9bf3d2010-06-07 15:24:45 -04003237 } else if (status == IOCB_BUSY)
3238 ret = FAILED;
3239 else
James Smartbbb9d182009-06-10 17:23:16 -04003240 ret = SUCCESS;
3241
3242 lpfc_sli_release_iocbq(phba, iocbqrsp);
3243
3244 if (ret != TIMEOUT_ERROR)
3245 lpfc_release_scsi_buf(phba, lpfc_cmd);
3246
3247 return ret;
3248}
3249
3250/**
3251 * lpfc_chk_tgt_mapped -
3252 * @vport: The virtual port to check on
3253 * @cmnd: Pointer to scsi_cmnd data structure.
3254 *
3255 * This routine delays until the scsi target (aka rport) for the
3256 * command exists (is present and logged in) or we declare it non-existent.
3257 *
3258 * Return code :
3259 * 0x2003 - Error
3260 * 0x2002 - Success
3261 **/
3262static int
3263lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
3264{
3265 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05003266 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003267 unsigned long later;
3268
James Smart1c6f4ef52009-11-18 15:40:49 -05003269 if (!rdata) {
3270 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3271 "0797 Tgt Map rport failure: rdata x%p\n", rdata);
3272 return FAILED;
3273 }
3274 pnode = rdata->pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003275 /*
3276 * If target is not in a MAPPED state, delay until
3277 * target is rediscovered or devloss timeout expires.
3278 */
3279 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3280 while (time_after(later, jiffies)) {
3281 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3282 return FAILED;
3283 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
3284 return SUCCESS;
3285 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
3286 rdata = cmnd->device->hostdata;
3287 if (!rdata)
3288 return FAILED;
3289 pnode = rdata->pnode;
3290 }
3291 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
3292 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
3293 return FAILED;
3294 return SUCCESS;
3295}
3296
3297/**
3298 * lpfc_reset_flush_io_context -
3299 * @vport: The virtual port (scsi_host) for the flush context
3300 * @tgt_id: If aborting by Target contect - specifies the target id
3301 * @lun_id: If aborting by Lun context - specifies the lun id
3302 * @context: specifies the context level to flush at.
3303 *
3304 * After a reset condition via TMF, we need to flush orphaned i/o
3305 * contexts from the adapter. This routine aborts any contexts
3306 * outstanding, then waits for their completions. The wait is
3307 * bounded by devloss_tmo though.
3308 *
3309 * Return code :
3310 * 0x2003 - Error
3311 * 0x2002 - Success
3312 **/
3313static int
3314lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
3315 uint64_t lun_id, lpfc_ctx_cmd context)
3316{
3317 struct lpfc_hba *phba = vport->phba;
3318 unsigned long later;
3319 int cnt;
3320
3321 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
3322 if (cnt)
3323 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
3324 tgt_id, lun_id, context);
3325 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
3326 while (time_after(later, jiffies) && cnt) {
3327 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
3328 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
3329 }
3330 if (cnt) {
3331 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3332 "0724 I/O flush failure for context %s : cnt x%x\n",
3333 ((context == LPFC_CTX_LUN) ? "LUN" :
3334 ((context == LPFC_CTX_TGT) ? "TGT" :
3335 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
3336 cnt);
3337 return FAILED;
3338 }
3339 return SUCCESS;
3340}
3341
James Smart9bad7672008-12-04 22:39:02 -05003342/**
James Smart3621a712009-04-06 18:47:14 -04003343 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
James Smart9bad7672008-12-04 22:39:02 -05003344 * @cmnd: Pointer to scsi_cmnd data structure.
3345 *
James Smartbbb9d182009-06-10 17:23:16 -04003346 * This routine does a device reset by sending a LUN_RESET task management
James Smart9bad7672008-12-04 22:39:02 -05003347 * command.
3348 *
3349 * Return code :
3350 * 0x2003 - Error
James Smart3621a712009-04-06 18:47:14 -04003351 * 0x2002 - Success
James Smart9bad7672008-12-04 22:39:02 -05003352 **/
dea31012005-04-17 16:05:31 -05003353static int
James Smart7054a602007-04-25 09:52:34 -04003354lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05003355{
James Smart2e0fef82007-06-17 19:56:36 -05003356 struct Scsi_Host *shost = cmnd->device->host;
3357 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
dea31012005-04-17 16:05:31 -05003358 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05003359 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003360 unsigned tgt_id = cmnd->device->id;
3361 unsigned int lun_id = cmnd->device->lun;
James Smartea2151b2008-09-07 11:52:10 -04003362 struct lpfc_scsi_event_header scsi_event;
James Smartbbb9d182009-06-10 17:23:16 -04003363 int status;
dea31012005-04-17 16:05:31 -05003364
James Smart1c6f4ef52009-11-18 15:40:49 -05003365 if (!rdata) {
3366 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3367 "0798 Device Reset rport failure: rdata x%p\n", rdata);
3368 return FAILED;
3369 }
3370 pnode = rdata->pnode;
Christof Schmitt65d430f2009-10-30 17:59:29 +01003371 fc_block_scsi_eh(cmnd);
James Smartbbb9d182009-06-10 17:23:16 -04003372
3373 status = lpfc_chk_tgt_mapped(vport, cmnd);
3374 if (status == FAILED) {
3375 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3376 "0721 Device Reset rport failure: rdata x%p\n", rdata);
3377 return FAILED;
3378 }
3379
3380 scsi_event.event_type = FC_REG_SCSI_EVENT;
3381 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
3382 scsi_event.lun = lun_id;
3383 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
3384 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
3385
3386 fc_host_post_vendor_event(shost, fc_get_event_number(),
3387 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
3388
3389 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
3390 FCP_LUN_RESET);
3391
3392 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3393 "0713 SCSI layer issued Device Reset (%d, %d) "
3394 "return x%x\n", tgt_id, lun_id, status);
3395
dea31012005-04-17 16:05:31 -05003396 /*
James Smartbbb9d182009-06-10 17:23:16 -04003397 * We have to clean up i/o as : they may be orphaned by the TMF;
3398 * or if the TMF failed, they may be in an indeterminate state.
3399 * So, continue on.
3400 * We will report success if all the i/o aborts successfully.
dea31012005-04-17 16:05:31 -05003401 */
James Smartbbb9d182009-06-10 17:23:16 -04003402 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
3403 LPFC_CTX_LUN);
3404 return status;
3405}
3406
3407/**
3408 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
3409 * @cmnd: Pointer to scsi_cmnd data structure.
3410 *
3411 * This routine does a target reset by sending a TARGET_RESET task management
3412 * command.
3413 *
3414 * Return code :
3415 * 0x2003 - Error
3416 * 0x2002 - Success
3417 **/
3418static int
3419lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
3420{
3421 struct Scsi_Host *shost = cmnd->device->host;
3422 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3423 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
James Smart1c6f4ef52009-11-18 15:40:49 -05003424 struct lpfc_nodelist *pnode;
James Smartbbb9d182009-06-10 17:23:16 -04003425 unsigned tgt_id = cmnd->device->id;
3426 unsigned int lun_id = cmnd->device->lun;
3427 struct lpfc_scsi_event_header scsi_event;
3428 int status;
3429
James Smart1c6f4ef52009-11-18 15:40:49 -05003430 if (!rdata) {
3431 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3432 "0799 Target Reset rport failure: rdata x%p\n", rdata);
3433 return FAILED;
3434 }
3435 pnode = rdata->pnode;
Christof Schmitt65d430f2009-10-30 17:59:29 +01003436 fc_block_scsi_eh(cmnd);
James Smartbbb9d182009-06-10 17:23:16 -04003437
3438 status = lpfc_chk_tgt_mapped(vport, cmnd);
3439 if (status == FAILED) {
3440 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3441 "0722 Target Reset rport failure: rdata x%p\n", rdata);
3442 return FAILED;
dea31012005-04-17 16:05:31 -05003443 }
James Smartea2151b2008-09-07 11:52:10 -04003444
3445 scsi_event.event_type = FC_REG_SCSI_EVENT;
3446 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
3447 scsi_event.lun = 0;
3448 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
3449 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
3450
James Smartbbb9d182009-06-10 17:23:16 -04003451 fc_host_post_vendor_event(shost, fc_get_event_number(),
3452 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04003453
James Smartbbb9d182009-06-10 17:23:16 -04003454 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
3455 FCP_TARGET_RESET);
dea31012005-04-17 16:05:31 -05003456
James Smarte8b62012007-08-02 11:10:09 -04003457 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
James Smartbbb9d182009-06-10 17:23:16 -04003458 "0723 SCSI layer issued Target Reset (%d, %d) "
3459 "return x%x\n", tgt_id, lun_id, status);
3460
3461 /*
3462 * We have to clean up i/o as : they may be orphaned by the TMF;
3463 * or if the TMF failed, they may be in an indeterminate state.
3464 * So, continue on.
3465 * We will report success if all the i/o aborts successfully.
3466 */
3467 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
3468 LPFC_CTX_TGT);
3469 return status;
dea31012005-04-17 16:05:31 -05003470}
3471
James Smart9bad7672008-12-04 22:39:02 -05003472/**
James Smart3621a712009-04-06 18:47:14 -04003473 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
James Smart9bad7672008-12-04 22:39:02 -05003474 * @cmnd: Pointer to scsi_cmnd data structure.
3475 *
James Smartbbb9d182009-06-10 17:23:16 -04003476 * This routine does target reset to all targets on @cmnd->device->host.
3477 * This emulates Parallel SCSI Bus Reset Semantics.
James Smart9bad7672008-12-04 22:39:02 -05003478 *
James Smartbbb9d182009-06-10 17:23:16 -04003479 * Return code :
3480 * 0x2003 - Error
3481 * 0x2002 - Success
James Smart9bad7672008-12-04 22:39:02 -05003482 **/
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04003483static int
James Smart7054a602007-04-25 09:52:34 -04003484lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05003485{
James Smart2e0fef82007-06-17 19:56:36 -05003486 struct Scsi_Host *shost = cmnd->device->host;
3487 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
dea31012005-04-17 16:05:31 -05003488 struct lpfc_nodelist *ndlp = NULL;
James Smartea2151b2008-09-07 11:52:10 -04003489 struct lpfc_scsi_event_header scsi_event;
James Smartbbb9d182009-06-10 17:23:16 -04003490 int match;
3491 int ret = SUCCESS, status, i;
James Smartea2151b2008-09-07 11:52:10 -04003492
3493 scsi_event.event_type = FC_REG_SCSI_EVENT;
3494 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
3495 scsi_event.lun = 0;
3496 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
3497 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
3498
James Smartbbb9d182009-06-10 17:23:16 -04003499 fc_host_post_vendor_event(shost, fc_get_event_number(),
3500 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
dea31012005-04-17 16:05:31 -05003501
Christof Schmitt65d430f2009-10-30 17:59:29 +01003502 fc_block_scsi_eh(cmnd);
James Smartbbb9d182009-06-10 17:23:16 -04003503
dea31012005-04-17 16:05:31 -05003504 /*
3505 * Since the driver manages a single bus device, reset all
3506 * targets known to the driver. Should any target reset
3507 * fail, this routine returns failure to the midlayer.
3508 */
James Smarte17da182006-07-06 15:49:25 -04003509 for (i = 0; i < LPFC_MAX_TARGET; i++) {
James Smart685f0bf2007-04-25 09:53:08 -04003510 /* Search for mapped node by target ID */
dea31012005-04-17 16:05:31 -05003511 match = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003512 spin_lock_irq(shost->host_lock);
3513 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003514 if (!NLP_CHK_NODE_ACT(ndlp))
3515 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003516 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart915caaa2008-06-14 22:52:38 -04003517 ndlp->nlp_sid == i &&
James Smart685f0bf2007-04-25 09:53:08 -04003518 ndlp->rport) {
dea31012005-04-17 16:05:31 -05003519 match = 1;
3520 break;
3521 }
3522 }
James Smart2e0fef82007-06-17 19:56:36 -05003523 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003524 if (!match)
3525 continue;
James Smartbbb9d182009-06-10 17:23:16 -04003526
3527 status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
3528 i, 0, FCP_TARGET_RESET);
3529
3530 if (status != SUCCESS) {
James Smarte8b62012007-08-02 11:10:09 -04003531 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3532 "0700 Bus Reset on target %d failed\n",
3533 i);
James Smart915caaa2008-06-14 22:52:38 -04003534 ret = FAILED;
dea31012005-04-17 16:05:31 -05003535 }
3536 }
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05003537 /*
James Smartbbb9d182009-06-10 17:23:16 -04003538 * We have to clean up i/o as : they may be orphaned by the TMFs
3539 * above; or if any of the TMFs failed, they may be in an
3540 * indeterminate state.
3541 * We will report success if all the i/o aborts successfully.
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05003542 */
James Smartbbb9d182009-06-10 17:23:16 -04003543
3544 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
3545 if (status != SUCCESS)
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05003546 ret = FAILED;
James Smartbbb9d182009-06-10 17:23:16 -04003547
James Smarte8b62012007-08-02 11:10:09 -04003548 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3549 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
dea31012005-04-17 16:05:31 -05003550 return ret;
3551}
3552
James Smart9bad7672008-12-04 22:39:02 -05003553/**
James Smart3621a712009-04-06 18:47:14 -04003554 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
James Smart9bad7672008-12-04 22:39:02 -05003555 * @sdev: Pointer to scsi_device.
3556 *
3557 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
3558 * globally available list of scsi buffers. This routine also makes sure scsi
3559 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
3560 * of scsi buffer exists for the lifetime of the driver.
3561 *
3562 * Return codes:
3563 * non-0 - Error
3564 * 0 - Success
3565 **/
dea31012005-04-17 16:05:31 -05003566static int
dea31012005-04-17 16:05:31 -05003567lpfc_slave_alloc(struct scsi_device *sdev)
3568{
James Smart2e0fef82007-06-17 19:56:36 -05003569 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
3570 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003571 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
James Smart3772a992009-05-22 14:50:54 -04003572 uint32_t total = 0;
dea31012005-04-17 16:05:31 -05003573 uint32_t num_to_alloc = 0;
James Smart3772a992009-05-22 14:50:54 -04003574 int num_allocated = 0;
dea31012005-04-17 16:05:31 -05003575
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003576 if (!rport || fc_remote_port_chkready(rport))
dea31012005-04-17 16:05:31 -05003577 return -ENXIO;
3578
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003579 sdev->hostdata = rport->dd_data;
dea31012005-04-17 16:05:31 -05003580
3581 /*
3582 * Populate the cmds_per_lun count scsi_bufs into this host's globally
3583 * available list of scsi buffers. Don't allocate more than the
James.Smart@Emulex.Coma784efb2005-10-28 20:29:51 -04003584 * HBA limit conveyed to the midlayer via the host structure. The
3585 * formula accounts for the lun_queue_depth + error handlers + 1
3586 * extra. This list of scsi bufs exists for the lifetime of the driver.
dea31012005-04-17 16:05:31 -05003587 */
3588 total = phba->total_scsi_bufs;
James Smart3de2a652007-08-02 11:09:59 -04003589 num_to_alloc = vport->cfg_lun_queue_depth + 2;
James Smart92d7f7b2007-06-17 19:56:38 -05003590
3591 /* Allow some exchanges to be available always to complete discovery */
3592 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04003593 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3594 "0704 At limitation of %d preallocated "
3595 "command buffers\n", total);
dea31012005-04-17 16:05:31 -05003596 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003597 /* Allow some exchanges to be available always to complete discovery */
3598 } else if (total + num_to_alloc >
3599 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04003600 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3601 "0705 Allocation request of %d "
3602 "command buffers will exceed max of %d. "
3603 "Reducing allocation request to %d.\n",
3604 num_to_alloc, phba->cfg_hba_queue_depth,
3605 (phba->cfg_hba_queue_depth - total));
dea31012005-04-17 16:05:31 -05003606 num_to_alloc = phba->cfg_hba_queue_depth - total;
3607 }
James Smart3772a992009-05-22 14:50:54 -04003608 num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc);
3609 if (num_to_alloc != num_allocated) {
3610 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3611 "0708 Allocation request of %d "
3612 "command buffers did not succeed. "
3613 "Allocated %d buffers.\n",
3614 num_to_alloc, num_allocated);
dea31012005-04-17 16:05:31 -05003615 }
James Smart1c6f4ef52009-11-18 15:40:49 -05003616 if (num_allocated > 0)
3617 phba->total_scsi_bufs += num_allocated;
dea31012005-04-17 16:05:31 -05003618 return 0;
3619}
3620
James Smart9bad7672008-12-04 22:39:02 -05003621/**
James Smart3621a712009-04-06 18:47:14 -04003622 * lpfc_slave_configure - scsi_host_template slave_configure entry point
James Smart9bad7672008-12-04 22:39:02 -05003623 * @sdev: Pointer to scsi_device.
3624 *
3625 * This routine configures following items
3626 * - Tag command queuing support for @sdev if supported.
3627 * - Dev loss time out value of fc_rport.
3628 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
3629 *
3630 * Return codes:
3631 * 0 - Success
3632 **/
dea31012005-04-17 16:05:31 -05003633static int
3634lpfc_slave_configure(struct scsi_device *sdev)
3635{
James Smart2e0fef82007-06-17 19:56:36 -05003636 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
3637 struct lpfc_hba *phba = vport->phba;
3638 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
dea31012005-04-17 16:05:31 -05003639
3640 if (sdev->tagged_supported)
James Smart3de2a652007-08-02 11:09:59 -04003641 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05003642 else
James Smart3de2a652007-08-02 11:09:59 -04003643 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05003644
3645 /*
3646 * Initialize the fc transport attributes for the target
3647 * containing this scsi device. Also note that the driver's
3648 * target pointer is stored in the starget_data for the
3649 * driver's sysfs entry point functions.
3650 */
James Smart3de2a652007-08-02 11:09:59 -04003651 rport->dev_loss_tmo = vport->cfg_devloss_tmo;
dea31012005-04-17 16:05:31 -05003652
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003653 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smart45ed1192009-10-02 15:17:02 -04003654 lpfc_sli_handle_fast_ring_event(phba,
3655 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003656 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
3657 lpfc_poll_rearm_timer(phba);
3658 }
3659
dea31012005-04-17 16:05:31 -05003660 return 0;
3661}
3662
James Smart9bad7672008-12-04 22:39:02 -05003663/**
James Smart3621a712009-04-06 18:47:14 -04003664 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
James Smart9bad7672008-12-04 22:39:02 -05003665 * @sdev: Pointer to scsi_device.
3666 *
3667 * This routine sets @sdev hostatdata filed to null.
3668 **/
dea31012005-04-17 16:05:31 -05003669static void
3670lpfc_slave_destroy(struct scsi_device *sdev)
3671{
3672 sdev->hostdata = NULL;
3673 return;
3674}
3675
James Smart92d7f7b2007-06-17 19:56:38 -05003676
dea31012005-04-17 16:05:31 -05003677struct scsi_host_template lpfc_template = {
3678 .module = THIS_MODULE,
3679 .name = LPFC_DRIVER_NAME,
3680 .info = lpfc_info,
3681 .queuecommand = lpfc_queuecommand,
3682 .eh_abort_handler = lpfc_abort_handler,
James Smartbbb9d182009-06-10 17:23:16 -04003683 .eh_device_reset_handler = lpfc_device_reset_handler,
3684 .eh_target_reset_handler = lpfc_target_reset_handler,
James Smart7054a602007-04-25 09:52:34 -04003685 .eh_bus_reset_handler = lpfc_bus_reset_handler,
dea31012005-04-17 16:05:31 -05003686 .slave_alloc = lpfc_slave_alloc,
3687 .slave_configure = lpfc_slave_configure,
3688 .slave_destroy = lpfc_slave_destroy,
James Smart47a86172007-04-25 09:53:22 -04003689 .scan_finished = lpfc_scan_finished,
dea31012005-04-17 16:05:31 -05003690 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05003691 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
dea31012005-04-17 16:05:31 -05003692 .cmd_per_lun = LPFC_CMD_PER_LUN,
3693 .use_clustering = ENABLE_CLUSTERING,
James Smart2e0fef82007-06-17 19:56:36 -05003694 .shost_attrs = lpfc_hba_attrs,
James.Smart@Emulex.Com564b2962005-06-25 10:34:17 -04003695 .max_sectors = 0xFFFF,
James Smartf1c3b0f2009-07-19 10:01:32 -04003696 .vendor_id = LPFC_NL_VENDOR_ID,
James Smart5ffc2662009-11-18 15:39:44 -05003697 .change_queue_depth = lpfc_change_queue_depth,
dea31012005-04-17 16:05:31 -05003698};
James Smart3de2a652007-08-02 11:09:59 -04003699
3700struct scsi_host_template lpfc_vport_template = {
3701 .module = THIS_MODULE,
3702 .name = LPFC_DRIVER_NAME,
3703 .info = lpfc_info,
3704 .queuecommand = lpfc_queuecommand,
3705 .eh_abort_handler = lpfc_abort_handler,
James Smartbbb9d182009-06-10 17:23:16 -04003706 .eh_device_reset_handler = lpfc_device_reset_handler,
3707 .eh_target_reset_handler = lpfc_target_reset_handler,
James Smart3de2a652007-08-02 11:09:59 -04003708 .eh_bus_reset_handler = lpfc_bus_reset_handler,
3709 .slave_alloc = lpfc_slave_alloc,
3710 .slave_configure = lpfc_slave_configure,
3711 .slave_destroy = lpfc_slave_destroy,
3712 .scan_finished = lpfc_scan_finished,
3713 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05003714 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
James Smart3de2a652007-08-02 11:09:59 -04003715 .cmd_per_lun = LPFC_CMD_PER_LUN,
3716 .use_clustering = ENABLE_CLUSTERING,
3717 .shost_attrs = lpfc_vport_attrs,
3718 .max_sectors = 0xFFFF,
James Smart5ffc2662009-11-18 15:39:44 -05003719 .change_queue_depth = lpfc_change_queue_depth,
James Smart3de2a652007-08-02 11:09:59 -04003720};