blob: 72eef7e4a891e3583a03de8ece5c5108cd511143 [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 Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 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 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/pci.h>
23#include <linux/interrupt.h>
James Smarta90f5682006-08-17 11:58:04 -040024#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050025
26#include <scsi/scsi.h>
27#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_tcq.h>
30#include <scsi/scsi_transport_fc.h>
31
32#include "lpfc_version.h"
33#include "lpfc_hw.h"
34#include "lpfc_sli.h"
35#include "lpfc_disc.h"
36#include "lpfc_scsi.h"
37#include "lpfc.h"
38#include "lpfc_logmsg.h"
39#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050040#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050041
42#define LPFC_RESET_WAIT 2
43#define LPFC_ABORT_WAIT 2
44
dea31012005-04-17 16:05:31 -050045/*
James Smart92d7f7b2007-06-17 19:56:38 -050046 * This function is called with no lock held when there is a resource
47 * error in driver or in firmware.
48 */
49void
50lpfc_adjust_queue_depth(struct lpfc_hba *phba)
51{
52 unsigned long flags;
James Smart5e9d9b82008-06-14 22:52:53 -040053 uint32_t evt_posted;
James Smart92d7f7b2007-06-17 19:56:38 -050054
55 spin_lock_irqsave(&phba->hbalock, flags);
56 atomic_inc(&phba->num_rsrc_err);
57 phba->last_rsrc_error_time = jiffies;
58
59 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
60 spin_unlock_irqrestore(&phba->hbalock, flags);
61 return;
62 }
63
64 phba->last_ramp_down_time = jiffies;
65
66 spin_unlock_irqrestore(&phba->hbalock, flags);
67
68 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
James Smart5e9d9b82008-06-14 22:52:53 -040069 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
70 if (!evt_posted)
James Smart92d7f7b2007-06-17 19:56:38 -050071 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
James Smart92d7f7b2007-06-17 19:56:38 -050072 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
73
James Smart5e9d9b82008-06-14 22:52:53 -040074 if (!evt_posted)
75 lpfc_worker_wake_up(phba);
James Smart92d7f7b2007-06-17 19:56:38 -050076 return;
77}
78
79/*
80 * This function is called with no lock held when there is a successful
81 * SCSI command completion.
82 */
83static inline void
James Smart3de2a652007-08-02 11:09:59 -040084lpfc_rampup_queue_depth(struct lpfc_vport *vport,
James Smart92d7f7b2007-06-17 19:56:38 -050085 struct scsi_device *sdev)
86{
87 unsigned long flags;
James Smart3de2a652007-08-02 11:09:59 -040088 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -040089 uint32_t evt_posted;
James Smart92d7f7b2007-06-17 19:56:38 -050090 atomic_inc(&phba->num_cmd_success);
91
James Smart3de2a652007-08-02 11:09:59 -040092 if (vport->cfg_lun_queue_depth <= sdev->queue_depth)
James Smart92d7f7b2007-06-17 19:56:38 -050093 return;
James Smart92d7f7b2007-06-17 19:56:38 -050094 spin_lock_irqsave(&phba->hbalock, flags);
95 if (((phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) > jiffies) ||
96 ((phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL ) > jiffies)) {
97 spin_unlock_irqrestore(&phba->hbalock, flags);
98 return;
99 }
James Smart92d7f7b2007-06-17 19:56:38 -0500100 phba->last_ramp_up_time = jiffies;
101 spin_unlock_irqrestore(&phba->hbalock, flags);
102
103 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
James Smart5e9d9b82008-06-14 22:52:53 -0400104 evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
105 if (!evt_posted)
James Smart92d7f7b2007-06-17 19:56:38 -0500106 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
James Smart92d7f7b2007-06-17 19:56:38 -0500107 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
108
James Smart5e9d9b82008-06-14 22:52:53 -0400109 if (!evt_posted)
110 lpfc_worker_wake_up(phba);
111 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500112}
113
114void
115lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
116{
James Smart549e55c2007-08-02 11:09:51 -0400117 struct lpfc_vport **vports;
118 struct Scsi_Host *shost;
James Smart92d7f7b2007-06-17 19:56:38 -0500119 struct scsi_device *sdev;
120 unsigned long new_queue_depth;
121 unsigned long num_rsrc_err, num_cmd_success;
James Smart549e55c2007-08-02 11:09:51 -0400122 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500123
124 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
125 num_cmd_success = atomic_read(&phba->num_cmd_success);
126
James Smart549e55c2007-08-02 11:09:51 -0400127 vports = lpfc_create_vport_work_array(phba);
128 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500129 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400130 shost = lpfc_shost_from_vport(vports[i]);
131 shost_for_each_device(sdev, shost) {
James Smart92d7f7b2007-06-17 19:56:38 -0500132 new_queue_depth =
James Smart549e55c2007-08-02 11:09:51 -0400133 sdev->queue_depth * num_rsrc_err /
134 (num_rsrc_err + num_cmd_success);
135 if (!new_queue_depth)
136 new_queue_depth = sdev->queue_depth - 1;
137 else
138 new_queue_depth = sdev->queue_depth -
139 new_queue_depth;
140 if (sdev->ordered_tags)
141 scsi_adjust_queue_depth(sdev,
142 MSG_ORDERED_TAG,
143 new_queue_depth);
144 else
145 scsi_adjust_queue_depth(sdev,
146 MSG_SIMPLE_TAG,
147 new_queue_depth);
148 }
James Smart92d7f7b2007-06-17 19:56:38 -0500149 }
James Smart09372822008-01-11 01:52:54 -0500150 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500151 atomic_set(&phba->num_rsrc_err, 0);
152 atomic_set(&phba->num_cmd_success, 0);
153}
154
155void
156lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
157{
James Smart549e55c2007-08-02 11:09:51 -0400158 struct lpfc_vport **vports;
159 struct Scsi_Host *shost;
James Smart92d7f7b2007-06-17 19:56:38 -0500160 struct scsi_device *sdev;
James Smart549e55c2007-08-02 11:09:51 -0400161 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500162
James Smart549e55c2007-08-02 11:09:51 -0400163 vports = lpfc_create_vport_work_array(phba);
164 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500165 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400166 shost = lpfc_shost_from_vport(vports[i]);
167 shost_for_each_device(sdev, shost) {
James Smart97eab632008-04-07 10:16:05 -0400168 if (vports[i]->cfg_lun_queue_depth <=
169 sdev->queue_depth)
170 continue;
James Smart549e55c2007-08-02 11:09:51 -0400171 if (sdev->ordered_tags)
172 scsi_adjust_queue_depth(sdev,
173 MSG_ORDERED_TAG,
174 sdev->queue_depth+1);
175 else
176 scsi_adjust_queue_depth(sdev,
177 MSG_SIMPLE_TAG,
178 sdev->queue_depth+1);
179 }
James Smart92d7f7b2007-06-17 19:56:38 -0500180 }
James Smart09372822008-01-11 01:52:54 -0500181 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500182 atomic_set(&phba->num_rsrc_err, 0);
183 atomic_set(&phba->num_cmd_success, 0);
184}
185
James Smarta8e497d2008-08-24 21:50:11 -0400186/**
187 * lpfc_scsi_dev_block: set all scsi hosts to block state.
188 * @phba: Pointer to HBA context object.
189 *
190 * This function walks vport list and set each SCSI host to block state
191 * by invoking fc_remote_port_delete() routine. This function is invoked
192 * with EEH when device's PCI slot has been permanently disabled.
193 **/
194void
195lpfc_scsi_dev_block(struct lpfc_hba *phba)
196{
197 struct lpfc_vport **vports;
198 struct Scsi_Host *shost;
199 struct scsi_device *sdev;
200 struct fc_rport *rport;
201 int i;
202
203 vports = lpfc_create_vport_work_array(phba);
204 if (vports != NULL)
205 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
206 shost = lpfc_shost_from_vport(vports[i]);
207 shost_for_each_device(sdev, shost) {
208 rport = starget_to_rport(scsi_target(sdev));
209 fc_remote_port_delete(rport);
210 }
211 }
212 lpfc_destroy_vport_work_array(phba, vports);
213}
214
James Smart92d7f7b2007-06-17 19:56:38 -0500215/*
dea31012005-04-17 16:05:31 -0500216 * This routine allocates a scsi buffer, which contains all the necessary
217 * information needed to initiate a SCSI I/O. The non-DMAable buffer region
218 * contains information to build the IOCB. The DMAable region contains
219 * memory for the FCP CMND, FCP RSP, and the inital BPL. In addition to
220 * allocating memeory, the FCP CMND and FCP RSP BDEs are setup in the BPL
221 * and the BPL BDE is setup in the IOCB.
222 */
223static struct lpfc_scsi_buf *
James Smart2e0fef82007-06-17 19:56:36 -0500224lpfc_new_scsi_buf(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500225{
James Smart2e0fef82007-06-17 19:56:36 -0500226 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500227 struct lpfc_scsi_buf *psb;
228 struct ulp_bde64 *bpl;
229 IOCB_t *iocb;
James Smart34b02dc2008-08-24 21:49:55 -0400230 dma_addr_t pdma_phys_fcp_cmd;
231 dma_addr_t pdma_phys_fcp_rsp;
232 dma_addr_t pdma_phys_bpl;
James Bottomley604a3e32005-10-29 10:28:33 -0500233 uint16_t iotag;
dea31012005-04-17 16:05:31 -0500234
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +0200235 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500236 if (!psb)
237 return NULL;
dea31012005-04-17 16:05:31 -0500238
239 /*
240 * Get memory from the pci pool to map the virt space to pci bus space
241 * for an I/O. The DMA buffer includes space for the struct fcp_cmnd,
242 * struct fcp_rsp and the number of bde's necessary to support the
243 * sg_tablesize.
244 */
245 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL,
246 &psb->dma_handle);
247 if (!psb->data) {
248 kfree(psb);
249 return NULL;
250 }
251
252 /* Initialize virtual ptrs to dma_buf region. */
253 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
254
James Bottomley604a3e32005-10-29 10:28:33 -0500255 /* Allocate iotag for psb->cur_iocbq. */
256 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
257 if (iotag == 0) {
258 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
259 psb->data, psb->dma_handle);
260 kfree (psb);
261 return NULL;
262 }
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400263 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
James Bottomley604a3e32005-10-29 10:28:33 -0500264
dea31012005-04-17 16:05:31 -0500265 psb->fcp_cmnd = psb->data;
266 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
267 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
268 sizeof(struct fcp_rsp);
269
270 /* Initialize local short-hand pointers. */
271 bpl = psb->fcp_bpl;
James Smart34b02dc2008-08-24 21:49:55 -0400272 pdma_phys_fcp_cmd = psb->dma_handle;
273 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
274 pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
275 sizeof(struct fcp_rsp);
dea31012005-04-17 16:05:31 -0500276
277 /*
278 * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg
279 * list bdes. Initialize the first two and leave the rest for
280 * queuecommand.
281 */
James Smart34b02dc2008-08-24 21:49:55 -0400282 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
283 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
284 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
285 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
286 bpl[0].tus.w = le32_to_cpu(bpl->tus.w);
dea31012005-04-17 16:05:31 -0500287
288 /* Setup the physical region for the FCP RSP */
James Smart34b02dc2008-08-24 21:49:55 -0400289 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
290 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
291 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
292 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
293 bpl[1].tus.w = le32_to_cpu(bpl->tus.w);
dea31012005-04-17 16:05:31 -0500294
295 /*
296 * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf,
297 * initialize it with all known data now.
298 */
dea31012005-04-17 16:05:31 -0500299 iocb = &psb->cur_iocbq.iocb;
300 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
James Smart34b02dc2008-08-24 21:49:55 -0400301 if (phba->sli_rev == 3) {
302 /* fill in immediate fcp command BDE */
303 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
304 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
305 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
306 unsli3.fcp_ext.icd);
307 iocb->un.fcpi64.bdl.addrHigh = 0;
308 iocb->ulpBdeCount = 0;
309 iocb->ulpLe = 0;
310 /* fill in responce BDE */
311 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
312 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
313 sizeof(struct fcp_rsp);
314 iocb->unsli3.fcp_ext.rbde.addrLow =
315 putPaddrLow(pdma_phys_fcp_rsp);
316 iocb->unsli3.fcp_ext.rbde.addrHigh =
317 putPaddrHigh(pdma_phys_fcp_rsp);
318 } else {
319 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
320 iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
321 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_bpl);
322 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_bpl);
323 iocb->ulpBdeCount = 1;
324 iocb->ulpLe = 1;
325 }
dea31012005-04-17 16:05:31 -0500326 iocb->ulpClass = CLASS3;
327
328 return psb;
329}
330
Adrian Bunk455c53e2006-01-06 20:21:28 +0100331static struct lpfc_scsi_buf*
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500332lpfc_get_scsi_buf(struct lpfc_hba * phba)
dea31012005-04-17 16:05:31 -0500333{
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400334 struct lpfc_scsi_buf * lpfc_cmd = NULL;
335 struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500336 unsigned long iflag = 0;
dea31012005-04-17 16:05:31 -0500337
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500338 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400339 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
James Smart1dcb58e2007-04-25 09:51:30 -0400340 if (lpfc_cmd) {
341 lpfc_cmd->seg_cnt = 0;
342 lpfc_cmd->nonsg_phys = 0;
343 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500344 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400345 return lpfc_cmd;
346}
347
348static void
James Smart92d7f7b2007-06-17 19:56:38 -0500349lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400350{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500351 unsigned long iflag = 0;
dea31012005-04-17 16:05:31 -0500352
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500353 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400354 psb->pCmd = NULL;
dea31012005-04-17 16:05:31 -0500355 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500356 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
dea31012005-04-17 16:05:31 -0500357}
358
359static int
James Smart92d7f7b2007-06-17 19:56:38 -0500360lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
dea31012005-04-17 16:05:31 -0500361{
362 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
363 struct scatterlist *sgel = NULL;
364 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
365 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
366 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
James Smart34b02dc2008-08-24 21:49:55 -0400367 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
dea31012005-04-17 16:05:31 -0500368 dma_addr_t physaddr;
James Smart34b02dc2008-08-24 21:49:55 -0400369 uint32_t num_bde = 0;
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500370 int nseg, datadir = scsi_cmnd->sc_data_direction;
dea31012005-04-17 16:05:31 -0500371
372 /*
373 * There are three possibilities here - use scatter-gather segment, use
374 * the single mapping, or neither. Start the lpfc command prep by
375 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
376 * data bde entry.
377 */
378 bpl += 2;
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -0700379 if (scsi_sg_count(scsi_cmnd)) {
dea31012005-04-17 16:05:31 -0500380 /*
381 * The driver stores the segment count returned from pci_map_sg
382 * because this a count of dma-mappings used to map the use_sg
383 * pages. They are not guaranteed to be the same for those
384 * architectures that implement an IOMMU.
385 */
dea31012005-04-17 16:05:31 -0500386
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -0700387 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
388 scsi_sg_count(scsi_cmnd), datadir);
389 if (unlikely(!nseg))
390 return 1;
391
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500392 lpfc_cmd->seg_cnt = nseg;
dea31012005-04-17 16:05:31 -0500393 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
394 printk(KERN_ERR "%s: Too many sg segments from "
395 "dma_map_sg. Config %d, seg_cnt %d",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700396 __func__, phba->cfg_sg_seg_cnt,
dea31012005-04-17 16:05:31 -0500397 lpfc_cmd->seg_cnt);
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500398 scsi_dma_unmap(scsi_cmnd);
dea31012005-04-17 16:05:31 -0500399 return 1;
400 }
401
402 /*
403 * The driver established a maximum scatter-gather segment count
404 * during probe that limits the number of sg elements in any
405 * single scsi command. Just run through the seg_cnt and format
406 * the bde's.
James Smart34b02dc2008-08-24 21:49:55 -0400407 * When using SLI-3 the driver will try to fit all the BDEs into
408 * the IOCB. If it can't then the BDEs get added to a BPL as it
409 * does for SLI-2 mode.
dea31012005-04-17 16:05:31 -0500410 */
James Smart34b02dc2008-08-24 21:49:55 -0400411 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
dea31012005-04-17 16:05:31 -0500412 physaddr = sg_dma_address(sgel);
James Smart34b02dc2008-08-24 21:49:55 -0400413 if (phba->sli_rev == 3 &&
414 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
415 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
416 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
417 data_bde->addrLow = putPaddrLow(physaddr);
418 data_bde->addrHigh = putPaddrHigh(physaddr);
419 data_bde++;
420 } else {
421 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
422 bpl->tus.f.bdeSize = sg_dma_len(sgel);
423 bpl->tus.w = le32_to_cpu(bpl->tus.w);
424 bpl->addrLow =
425 le32_to_cpu(putPaddrLow(physaddr));
426 bpl->addrHigh =
427 le32_to_cpu(putPaddrHigh(physaddr));
428 bpl++;
429 }
dea31012005-04-17 16:05:31 -0500430 }
FUJITA Tomonoric59fd9e2007-07-04 06:03:11 -0700431 }
dea31012005-04-17 16:05:31 -0500432
433 /*
434 * Finish initializing those IOCB fields that are dependent on the
James Smart34b02dc2008-08-24 21:49:55 -0400435 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
436 * explicitly reinitialized and for SLI-3 the extended bde count is
437 * explicitly reinitialized since all iocb memory resources are reused.
dea31012005-04-17 16:05:31 -0500438 */
James Smart34b02dc2008-08-24 21:49:55 -0400439 if (phba->sli_rev == 3) {
440 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
441 /*
442 * The extended IOCB format can only fit 3 BDE or a BPL.
443 * This I/O has more than 3 BDE so the 1st data bde will
444 * be a BPL that is filled in here.
445 */
446 physaddr = lpfc_cmd->dma_handle;
447 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
448 data_bde->tus.f.bdeSize = (num_bde *
449 sizeof(struct ulp_bde64));
450 physaddr += (sizeof(struct fcp_cmnd) +
451 sizeof(struct fcp_rsp) +
452 (2 * sizeof(struct ulp_bde64)));
453 data_bde->addrHigh = putPaddrHigh(physaddr);
454 data_bde->addrLow = putPaddrLow(physaddr);
455 /* ebde count includes the responce bde and data bpl */
456 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
457 } else {
458 /* ebde count includes the responce bde and data bdes */
459 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
460 }
461 } else {
462 iocb_cmd->un.fcpi64.bdl.bdeSize =
463 ((num_bde + 2) * sizeof(struct ulp_bde64));
464 }
James Smart09372822008-01-11 01:52:54 -0500465 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
dea31012005-04-17 16:05:31 -0500466 return 0;
467}
468
469static void
James Smartbcf4dbf2006-07-06 15:50:08 -0400470lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
471{
472 /*
473 * There are only two special cases to consider. (1) the scsi command
474 * requested scatter-gather usage or (2) the scsi command allocated
475 * a request buffer, but did not request use_sg. There is a third
476 * case, but it does not require resource deallocation.
477 */
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500478 if (psb->seg_cnt > 0)
479 scsi_dma_unmap(psb->pCmd);
James Smartbcf4dbf2006-07-06 15:50:08 -0400480}
481
482static void
James Smart2e0fef82007-06-17 19:56:36 -0500483lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
484 struct lpfc_iocbq *rsp_iocb)
dea31012005-04-17 16:05:31 -0500485{
486 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
487 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
488 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
James Smart7054a602007-04-25 09:52:34 -0400489 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
dea31012005-04-17 16:05:31 -0500490 uint32_t resp_info = fcprsp->rspStatus2;
491 uint32_t scsi_status = fcprsp->rspStatus3;
James Smartc7743952006-12-02 13:34:42 -0500492 uint32_t *lp;
dea31012005-04-17 16:05:31 -0500493 uint32_t host_status = DID_OK;
494 uint32_t rsplen = 0;
James Smartc7743952006-12-02 13:34:42 -0500495 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
dea31012005-04-17 16:05:31 -0500496
497 /*
498 * If this is a task management command, there is no
499 * scsi packet associated with this lpfc_cmd. The driver
500 * consumes it.
501 */
502 if (fcpcmd->fcpCntl2) {
503 scsi_status = 0;
504 goto out;
505 }
506
James Smartc7743952006-12-02 13:34:42 -0500507 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
508 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
509 if (snslen > SCSI_SENSE_BUFFERSIZE)
510 snslen = SCSI_SENSE_BUFFERSIZE;
511
512 if (resp_info & RSP_LEN_VALID)
513 rsplen = be32_to_cpu(fcprsp->rspRspLen);
514 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
515 }
516 lp = (uint32_t *)cmnd->sense_buffer;
517
518 if (!scsi_status && (resp_info & RESID_UNDER))
519 logit = LOG_FCP;
520
James Smarte8b62012007-08-02 11:10:09 -0400521 lpfc_printf_vlog(vport, KERN_WARNING, logit,
522 "0730 FCP command x%x failed: x%x SNS x%x x%x "
523 "Data: x%x x%x x%x x%x x%x\n",
524 cmnd->cmnd[0], scsi_status,
525 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
526 be32_to_cpu(fcprsp->rspResId),
527 be32_to_cpu(fcprsp->rspSnsLen),
528 be32_to_cpu(fcprsp->rspRspLen),
529 fcprsp->rspInfo3);
dea31012005-04-17 16:05:31 -0500530
531 if (resp_info & RSP_LEN_VALID) {
532 rsplen = be32_to_cpu(fcprsp->rspRspLen);
533 if ((rsplen != 0 && rsplen != 4 && rsplen != 8) ||
534 (fcprsp->rspInfo3 != RSP_NO_FAILURE)) {
535 host_status = DID_ERROR;
536 goto out;
537 }
538 }
539
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500540 scsi_set_resid(cmnd, 0);
dea31012005-04-17 16:05:31 -0500541 if (resp_info & RESID_UNDER) {
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500542 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
dea31012005-04-17 16:05:31 -0500543
James Smarte8b62012007-08-02 11:10:09 -0400544 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
545 "0716 FCP Read Underrun, expected %d, "
546 "residual %d Data: x%x x%x x%x\n",
547 be32_to_cpu(fcpcmd->fcpDl),
548 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
549 cmnd->underflow);
dea31012005-04-17 16:05:31 -0500550
551 /*
James Smart7054a602007-04-25 09:52:34 -0400552 * If there is an under run check if under run reported by
553 * storage array is same as the under run reported by HBA.
554 * If this is not same, there is a dropped frame.
555 */
556 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
557 fcpi_parm &&
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500558 (scsi_get_resid(cmnd) != fcpi_parm)) {
James Smarte8b62012007-08-02 11:10:09 -0400559 lpfc_printf_vlog(vport, KERN_WARNING,
560 LOG_FCP | LOG_FCP_ERROR,
561 "0735 FCP Read Check Error "
562 "and Underrun Data: x%x x%x x%x x%x\n",
563 be32_to_cpu(fcpcmd->fcpDl),
564 scsi_get_resid(cmnd), fcpi_parm,
565 cmnd->cmnd[0]);
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500566 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
James Smart7054a602007-04-25 09:52:34 -0400567 host_status = DID_ERROR;
568 }
569 /*
dea31012005-04-17 16:05:31 -0500570 * The cmnd->underflow is the minimum number of bytes that must
571 * be transfered for this command. Provided a sense condition
572 * is not present, make sure the actual amount transferred is at
573 * least the underflow value or fail.
574 */
575 if (!(resp_info & SNS_LEN_VALID) &&
576 (scsi_status == SAM_STAT_GOOD) &&
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500577 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
578 < cmnd->underflow)) {
James Smarte8b62012007-08-02 11:10:09 -0400579 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
580 "0717 FCP command x%x residual "
581 "underrun converted to error "
582 "Data: x%x x%x x%x\n",
James Smart66dbfbe2007-08-05 06:08:38 -0400583 cmnd->cmnd[0], scsi_bufflen(cmnd),
James Smarte8b62012007-08-02 11:10:09 -0400584 scsi_get_resid(cmnd), cmnd->underflow);
dea31012005-04-17 16:05:31 -0500585 host_status = DID_ERROR;
586 }
587 } else if (resp_info & RESID_OVER) {
James Smarte8b62012007-08-02 11:10:09 -0400588 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
589 "0720 FCP command x%x residual overrun error. "
590 "Data: x%x x%x \n", cmnd->cmnd[0],
591 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
dea31012005-04-17 16:05:31 -0500592 host_status = DID_ERROR;
593
594 /*
595 * Check SLI validation that all the transfer was actually done
596 * (fcpi_parm should be zero). Apply check only to reads.
597 */
598 } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm &&
599 (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
James Smarte8b62012007-08-02 11:10:09 -0400600 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
601 "0734 FCP Read Check Error Data: "
602 "x%x x%x x%x x%x\n",
603 be32_to_cpu(fcpcmd->fcpDl),
604 be32_to_cpu(fcprsp->rspResId),
605 fcpi_parm, cmnd->cmnd[0]);
dea31012005-04-17 16:05:31 -0500606 host_status = DID_ERROR;
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500607 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
dea31012005-04-17 16:05:31 -0500608 }
609
610 out:
611 cmnd->result = ScsiResult(host_status, scsi_status);
612}
613
614static void
615lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
616 struct lpfc_iocbq *pIocbOut)
617{
618 struct lpfc_scsi_buf *lpfc_cmd =
619 (struct lpfc_scsi_buf *) pIocbIn->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500620 struct lpfc_vport *vport = pIocbIn->vport;
dea31012005-04-17 16:05:31 -0500621 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
622 struct lpfc_nodelist *pnode = rdata->pnode;
623 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500624 int result;
625 struct scsi_device *sdev, *tmp_sdev;
626 int depth = 0;
James Smartfa61a542008-01-11 01:52:42 -0500627 unsigned long flags;
dea31012005-04-17 16:05:31 -0500628
629 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
630 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
631
632 if (lpfc_cmd->status) {
633 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
634 (lpfc_cmd->result & IOERR_DRVR_MASK))
635 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
636 else if (lpfc_cmd->status >= IOSTAT_CNT)
637 lpfc_cmd->status = IOSTAT_DEFAULT;
638
James Smarte8b62012007-08-02 11:10:09 -0400639 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
640 "0729 FCP cmd x%x failed <%d/%d> "
641 "status: x%x result: x%x Data: x%x x%x\n",
642 cmd->cmnd[0],
643 cmd->device ? cmd->device->id : 0xffff,
644 cmd->device ? cmd->device->lun : 0xffff,
645 lpfc_cmd->status, lpfc_cmd->result,
646 pIocbOut->iocb.ulpContext,
647 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500648
649 switch (lpfc_cmd->status) {
650 case IOSTAT_FCP_RSP_ERROR:
651 /* Call FCP RSP handler to determine result */
James Smart2e0fef82007-06-17 19:56:36 -0500652 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
dea31012005-04-17 16:05:31 -0500653 break;
654 case IOSTAT_NPORT_BSY:
655 case IOSTAT_FABRIC_BSY:
James Smart0f1f53a2008-08-24 21:50:18 -0400656 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
dea31012005-04-17 16:05:31 -0500657 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500658 case IOSTAT_LOCAL_REJECT:
James Smartd7c255b2008-08-24 21:50:00 -0400659 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
James Smart92d7f7b2007-06-17 19:56:38 -0500660 lpfc_cmd->result == IOERR_NO_RESOURCES ||
James Smartd7c255b2008-08-24 21:50:00 -0400661 lpfc_cmd->result == IOERR_ABORT_REQUESTED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500662 cmd->result = ScsiResult(DID_REQUEUE, 0);
James Smart58da1ff2008-04-07 10:15:56 -0400663 break;
664 } /* else: fall through */
dea31012005-04-17 16:05:31 -0500665 default:
666 cmd->result = ScsiResult(DID_ERROR, 0);
667 break;
668 }
669
James Smart58da1ff2008-04-07 10:15:56 -0400670 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400671 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
James Smart0f1f53a2008-08-24 21:50:18 -0400672 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
673 SAM_STAT_BUSY);
dea31012005-04-17 16:05:31 -0500674 } else {
675 cmd->result = ScsiResult(DID_OK, 0);
676 }
677
678 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
679 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
680
James Smarte8b62012007-08-02 11:10:09 -0400681 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
682 "0710 Iodone <%d/%d> cmd %p, error "
683 "x%x SNS x%x x%x Data: x%x x%x\n",
684 cmd->device->id, cmd->device->lun, cmd,
685 cmd->result, *lp, *(lp + 3), cmd->retries,
686 scsi_get_resid(cmd));
dea31012005-04-17 16:05:31 -0500687 }
688
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500689 result = cmd->result;
690 sdev = cmd->device;
James Smart1dcb58e2007-04-25 09:51:30 -0400691 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -0500692 cmd->scsi_done(cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400693
Jamie Wellnitzb8086082006-02-28 22:33:12 -0500694 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
James Smartfa61a542008-01-11 01:52:42 -0500695 /*
696 * If there is a thread waiting for command completion
697 * wake up the thread.
698 */
699 spin_lock_irqsave(sdev->host->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -0400700 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -0500701 if (lpfc_cmd->waitq)
702 wake_up(lpfc_cmd->waitq);
703 spin_unlock_irqrestore(sdev->host->host_lock, flags);
Jamie Wellnitzb8086082006-02-28 22:33:12 -0500704 lpfc_release_scsi_buf(phba, lpfc_cmd);
705 return;
706 }
707
James Smart92d7f7b2007-06-17 19:56:38 -0500708
709 if (!result)
James Smart3de2a652007-08-02 11:09:59 -0400710 lpfc_rampup_queue_depth(vport, sdev);
James Smart92d7f7b2007-06-17 19:56:38 -0500711
James Smart58da1ff2008-04-07 10:15:56 -0400712 if (!result && pnode && NLP_CHK_NODE_ACT(pnode) &&
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500713 ((jiffies - pnode->last_ramp_up_time) >
714 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
715 ((jiffies - pnode->last_q_full_time) >
716 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
James Smart3de2a652007-08-02 11:09:59 -0400717 (vport->cfg_lun_queue_depth > sdev->queue_depth)) {
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500718 shost_for_each_device(tmp_sdev, sdev->host) {
James Smart3de2a652007-08-02 11:09:59 -0400719 if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500720 if (tmp_sdev->id != sdev->id)
721 continue;
722 if (tmp_sdev->ordered_tags)
723 scsi_adjust_queue_depth(tmp_sdev,
724 MSG_ORDERED_TAG,
725 tmp_sdev->queue_depth+1);
726 else
727 scsi_adjust_queue_depth(tmp_sdev,
728 MSG_SIMPLE_TAG,
729 tmp_sdev->queue_depth+1);
730
731 pnode->last_ramp_up_time = jiffies;
732 }
733 }
734 }
735
736 /*
737 * Check for queue full. If the lun is reporting queue full, then
738 * back off the lun queue depth to prevent target overloads.
739 */
James Smart58da1ff2008-04-07 10:15:56 -0400740 if (result == SAM_STAT_TASK_SET_FULL && pnode &&
741 NLP_CHK_NODE_ACT(pnode)) {
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500742 pnode->last_q_full_time = jiffies;
743
744 shost_for_each_device(tmp_sdev, sdev->host) {
745 if (tmp_sdev->id != sdev->id)
746 continue;
747 depth = scsi_track_queue_full(tmp_sdev,
748 tmp_sdev->queue_depth - 1);
749 }
750 /*
James Smart2e0fef82007-06-17 19:56:36 -0500751 * The queue depth cannot be lowered any more.
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500752 * Modify the returned error code to store
753 * the final depth value set by
754 * scsi_track_queue_full.
755 */
756 if (depth == -1)
757 depth = sdev->host->cmd_per_lun;
758
759 if (depth) {
James Smarte8b62012007-08-02 11:10:09 -0400760 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
761 "0711 detected queue full - lun queue "
762 "depth adjusted to %d.\n", depth);
James.Smart@Emulex.Com445cf4f2005-11-28 11:42:38 -0500763 }
764 }
765
James Smartfa61a542008-01-11 01:52:42 -0500766 /*
767 * If there is a thread waiting for command completion
768 * wake up the thread.
769 */
770 spin_lock_irqsave(sdev->host->host_lock, flags);
James Smart495a7142008-06-14 22:52:59 -0400771 lpfc_cmd->pCmd = NULL;
James Smartfa61a542008-01-11 01:52:42 -0500772 if (lpfc_cmd->waitq)
773 wake_up(lpfc_cmd->waitq);
774 spin_unlock_irqrestore(sdev->host->host_lock, flags);
775
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400776 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -0500777}
778
James Smart34b02dc2008-08-24 21:49:55 -0400779/**
780 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB.
781 * @data: A pointer to the immediate command data portion of the IOCB.
782 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
783 *
784 * The routine copies the entire FCP command from @fcp_cmnd to @data while
785 * byte swapping the data to big endian format for transmission on the wire.
786 **/
787static void
788lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
789{
790 int i, j;
791 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
792 i += sizeof(uint32_t), j++) {
793 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
794 }
795}
796
dea31012005-04-17 16:05:31 -0500797static void
James Smart2e0fef82007-06-17 19:56:36 -0500798lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
799 struct lpfc_nodelist *pnode)
dea31012005-04-17 16:05:31 -0500800{
James Smart2e0fef82007-06-17 19:56:36 -0500801 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500802 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
803 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
804 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
805 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
806 int datadir = scsi_cmnd->sc_data_direction;
James Smart7e2b19f2007-10-29 11:00:39 -0400807 char tag[2];
dea31012005-04-17 16:05:31 -0500808
James Smart58da1ff2008-04-07 10:15:56 -0400809 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
810 return;
811
dea31012005-04-17 16:05:31 -0500812 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
James.Smart@Emulex.Com69859dc2005-08-10 15:02:37 -0400813 /* clear task management bits */
814 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
dea31012005-04-17 16:05:31 -0500815
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -0400816 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
817 &lpfc_cmd->fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -0500818
819 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
820
James Smart7e2b19f2007-10-29 11:00:39 -0400821 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
822 switch (tag[0]) {
dea31012005-04-17 16:05:31 -0500823 case HEAD_OF_QUEUE_TAG:
824 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
825 break;
826 case ORDERED_QUEUE_TAG:
827 fcp_cmnd->fcpCntl1 = ORDERED_Q;
828 break;
829 default:
830 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
831 break;
832 }
833 } else
834 fcp_cmnd->fcpCntl1 = 0;
835
836 /*
837 * There are three possibilities here - use scatter-gather segment, use
838 * the single mapping, or neither. Start the lpfc command prep by
839 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
840 * data bde entry.
841 */
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500842 if (scsi_sg_count(scsi_cmnd)) {
dea31012005-04-17 16:05:31 -0500843 if (datadir == DMA_TO_DEVICE) {
844 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
845 iocb_cmd->un.fcpi.fcpi_parm = 0;
846 iocb_cmd->ulpPU = 0;
847 fcp_cmnd->fcpCntl3 = WRITE_DATA;
848 phba->fc4OutputRequests++;
849 } else {
850 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
851 iocb_cmd->ulpPU = PARM_READ_CHECK;
FUJITA Tomonoria0b4f782007-06-17 19:56:39 -0500852 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
dea31012005-04-17 16:05:31 -0500853 fcp_cmnd->fcpCntl3 = READ_DATA;
854 phba->fc4InputRequests++;
855 }
856 } else {
857 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
858 iocb_cmd->un.fcpi.fcpi_parm = 0;
859 iocb_cmd->ulpPU = 0;
860 fcp_cmnd->fcpCntl3 = 0;
861 phba->fc4ControlRequests++;
862 }
James Smart34b02dc2008-08-24 21:49:55 -0400863 if (phba->sli_rev == 3)
864 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -0500865 /*
866 * Finish initializing those IOCB fields that are independent
867 * of the scsi_cmnd request_buffer
868 */
869 piocbq->iocb.ulpContext = pnode->nlp_rpi;
870 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
871 piocbq->iocb.ulpFCP2Rcvy = 1;
James Smart09372822008-01-11 01:52:54 -0500872 else
873 piocbq->iocb.ulpFCP2Rcvy = 0;
dea31012005-04-17 16:05:31 -0500874
875 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
876 piocbq->context1 = lpfc_cmd;
877 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
878 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500879 piocbq->vport = vport;
dea31012005-04-17 16:05:31 -0500880}
881
882static int
James Smart2e0fef82007-06-17 19:56:36 -0500883lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
dea31012005-04-17 16:05:31 -0500884 struct lpfc_scsi_buf *lpfc_cmd,
James Smart420b630d2006-07-06 15:50:16 -0400885 unsigned int lun,
dea31012005-04-17 16:05:31 -0500886 uint8_t task_mgmt_cmd)
887{
dea31012005-04-17 16:05:31 -0500888 struct lpfc_iocbq *piocbq;
889 IOCB_t *piocb;
890 struct fcp_cmnd *fcp_cmnd;
James Smart0b18ac42006-05-01 21:50:40 -0400891 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
dea31012005-04-17 16:05:31 -0500892 struct lpfc_nodelist *ndlp = rdata->pnode;
893
James Smart58da1ff2008-04-07 10:15:56 -0400894 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
895 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
dea31012005-04-17 16:05:31 -0500896 return 0;
dea31012005-04-17 16:05:31 -0500897
dea31012005-04-17 16:05:31 -0500898 piocbq = &(lpfc_cmd->cur_iocbq);
James Smart2e0fef82007-06-17 19:56:36 -0500899 piocbq->vport = vport;
900
dea31012005-04-17 16:05:31 -0500901 piocb = &piocbq->iocb;
902
903 fcp_cmnd = lpfc_cmd->fcp_cmnd;
James Smart34b02dc2008-08-24 21:49:55 -0400904 /* Clear out any old data in the FCP command area */
905 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
906 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
dea31012005-04-17 16:05:31 -0500907 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
James Smart34b02dc2008-08-24 21:49:55 -0400908 if (vport->phba->sli_rev == 3)
909 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
dea31012005-04-17 16:05:31 -0500910 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
dea31012005-04-17 16:05:31 -0500911 piocb->ulpContext = ndlp->nlp_rpi;
912 if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
913 piocb->ulpFCP2Rcvy = 1;
914 }
915 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
916
917 /* ulpTimeout is only one byte */
918 if (lpfc_cmd->timeout > 0xff) {
919 /*
920 * Do not timeout the command at the firmware level.
921 * The driver will provide the timeout mechanism.
922 */
923 piocb->ulpTimeout = 0;
924 } else {
925 piocb->ulpTimeout = lpfc_cmd->timeout;
926 }
927
James Smart2e0fef82007-06-17 19:56:36 -0500928 return 1;
dea31012005-04-17 16:05:31 -0500929}
930
James Smart7054a602007-04-25 09:52:34 -0400931static void
932lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
933 struct lpfc_iocbq *cmdiocbq,
934 struct lpfc_iocbq *rspiocbq)
935{
936 struct lpfc_scsi_buf *lpfc_cmd =
937 (struct lpfc_scsi_buf *) cmdiocbq->context1;
938 if (lpfc_cmd)
939 lpfc_release_scsi_buf(phba, lpfc_cmd);
940 return;
941}
942
dea31012005-04-17 16:05:31 -0500943static int
James Smart2e0fef82007-06-17 19:56:36 -0500944lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
James Smart420b630d2006-07-06 15:50:16 -0400945 unsigned tgt_id, unsigned int lun,
946 struct lpfc_rport_data *rdata)
dea31012005-04-17 16:05:31 -0500947{
James Smart2e0fef82007-06-17 19:56:36 -0500948 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500949 struct lpfc_iocbq *iocbq;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400950 struct lpfc_iocbq *iocbqrsp;
dea31012005-04-17 16:05:31 -0500951 int ret;
James Smart915caaa2008-06-14 22:52:38 -0400952 int status;
dea31012005-04-17 16:05:31 -0500953
James Smart58da1ff2008-04-07 10:15:56 -0400954 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
James Smartf5603512006-12-02 13:35:43 -0500955 return FAILED;
956
James Smart0b18ac42006-05-01 21:50:40 -0400957 lpfc_cmd->rdata = rdata;
James Smart915caaa2008-06-14 22:52:38 -0400958 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
James Smart420b630d2006-07-06 15:50:16 -0400959 FCP_TARGET_RESET);
James Smart915caaa2008-06-14 22:52:38 -0400960 if (!status)
dea31012005-04-17 16:05:31 -0500961 return FAILED;
962
dea31012005-04-17 16:05:31 -0500963 iocbq = &lpfc_cmd->cur_iocbq;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400964 iocbqrsp = lpfc_sli_get_iocbq(phba);
965
dea31012005-04-17 16:05:31 -0500966 if (!iocbqrsp)
967 return FAILED;
dea31012005-04-17 16:05:31 -0500968
James Smart0b18ac42006-05-01 21:50:40 -0400969 /* Issue Target Reset to TGT <num> */
James Smarte8b62012007-08-02 11:10:09 -0400970 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
971 "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
972 tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
James Smart915caaa2008-06-14 22:52:38 -0400973 status = lpfc_sli_issue_iocb_wait(phba,
James.Smart@Emulex.Com68876922005-10-28 20:29:47 -0400974 &phba->sli.ring[phba->sli.fcp_ring],
975 iocbq, iocbqrsp, lpfc_cmd->timeout);
James Smart915caaa2008-06-14 22:52:38 -0400976 if (status != IOCB_SUCCESS) {
977 if (status == IOCB_TIMEDOUT) {
James Smart7054a602007-04-25 09:52:34 -0400978 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
James Smart915caaa2008-06-14 22:52:38 -0400979 ret = TIMEOUT_ERROR;
980 } else
981 ret = FAILED;
dea31012005-04-17 16:05:31 -0500982 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
dea31012005-04-17 16:05:31 -0500983 } else {
984 ret = SUCCESS;
985 lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
986 lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
987 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
988 (lpfc_cmd->result & IOERR_DRVR_MASK))
989 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
990 }
991
James Bottomley604a3e32005-10-29 10:28:33 -0500992 lpfc_sli_release_iocbq(phba, iocbqrsp);
dea31012005-04-17 16:05:31 -0500993 return ret;
994}
995
dea31012005-04-17 16:05:31 -0500996const char *
997lpfc_info(struct Scsi_Host *host)
998{
James Smart2e0fef82007-06-17 19:56:36 -0500999 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
1000 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001001 int len;
1002 static char lpfcinfobuf[384];
1003
1004 memset(lpfcinfobuf,0,384);
1005 if (phba && phba->pcidev){
1006 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
1007 len = strlen(lpfcinfobuf);
1008 snprintf(lpfcinfobuf + len,
1009 384-len,
1010 " on PCI bus %02x device %02x irq %d",
1011 phba->pcidev->bus->number,
1012 phba->pcidev->devfn,
1013 phba->pcidev->irq);
1014 len = strlen(lpfcinfobuf);
1015 if (phba->Port[0]) {
1016 snprintf(lpfcinfobuf + len,
1017 384-len,
1018 " port %s",
1019 phba->Port);
1020 }
1021 }
1022 return lpfcinfobuf;
1023}
1024
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001025static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
1026{
1027 unsigned long poll_tmo_expires =
1028 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
1029
1030 if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
1031 mod_timer(&phba->fcp_poll_timer,
1032 poll_tmo_expires);
1033}
1034
1035void lpfc_poll_start_timer(struct lpfc_hba * phba)
1036{
1037 lpfc_poll_rearm_timer(phba);
1038}
1039
1040void lpfc_poll_timeout(unsigned long ptr)
1041{
James Smart2e0fef82007-06-17 19:56:36 -05001042 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001043
1044 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1045 lpfc_sli_poll_fcp_ring (phba);
1046 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1047 lpfc_poll_rearm_timer(phba);
1048 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001049}
1050
dea31012005-04-17 16:05:31 -05001051static int
1052lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
1053{
James Smart2e0fef82007-06-17 19:56:36 -05001054 struct Scsi_Host *shost = cmnd->device->host;
1055 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1056 struct lpfc_hba *phba = vport->phba;
1057 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001058 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
1059 struct lpfc_nodelist *ndlp = rdata->pnode;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001060 struct lpfc_scsi_buf *lpfc_cmd;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001061 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001062 int err;
dea31012005-04-17 16:05:31 -05001063
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001064 err = fc_remote_port_chkready(rport);
1065 if (err) {
1066 cmnd->result = err;
dea31012005-04-17 16:05:31 -05001067 goto out_fail_command;
1068 }
1069
1070 /*
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001071 * Catch race where our node has transitioned, but the
1072 * transport is still transitioning.
dea31012005-04-17 16:05:31 -05001073 */
James Smartb522d7d2008-09-07 11:51:56 -04001074 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1075 cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
1076 goto out_fail_command;
1077 }
Mike Christiea93ce022008-08-17 15:24:41 -05001078
James Smarted957682007-06-17 19:56:37 -05001079 lpfc_cmd = lpfc_get_scsi_buf(phba);
dea31012005-04-17 16:05:31 -05001080 if (lpfc_cmd == NULL) {
James Smart92d7f7b2007-06-17 19:56:38 -05001081 lpfc_adjust_queue_depth(phba);
1082
James Smarte8b62012007-08-02 11:10:09 -04001083 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
1084 "0707 driver's buffer pool is empty, "
1085 "IO busied\n");
dea31012005-04-17 16:05:31 -05001086 goto out_host_busy;
1087 }
1088
1089 /*
1090 * Store the midlayer's command structure for the completion phase
1091 * and complete the command initialization.
1092 */
1093 lpfc_cmd->pCmd = cmnd;
1094 lpfc_cmd->rdata = rdata;
1095 lpfc_cmd->timeout = 0;
1096 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
1097 cmnd->scsi_done = done;
1098
1099 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
1100 if (err)
1101 goto out_host_busy_free_buf;
1102
James Smart2e0fef82007-06-17 19:56:36 -05001103 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
dea31012005-04-17 16:05:31 -05001104
1105 err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring],
James Smart92d7f7b2007-06-17 19:56:38 -05001106 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
dea31012005-04-17 16:05:31 -05001107 if (err)
1108 goto out_host_busy_free_buf;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001109
1110 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1111 lpfc_sli_poll_fcp_ring(phba);
1112 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1113 lpfc_poll_rearm_timer(phba);
1114 }
1115
dea31012005-04-17 16:05:31 -05001116 return 0;
1117
1118 out_host_busy_free_buf:
James Smartbcf4dbf2006-07-06 15:50:08 -04001119 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001120 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea31012005-04-17 16:05:31 -05001121 out_host_busy:
1122 return SCSI_MLQUEUE_HOST_BUSY;
1123
1124 out_fail_command:
1125 done(cmnd);
1126 return 0;
1127}
1128
James Smarta90f5682006-08-17 11:58:04 -04001129static void
1130lpfc_block_error_handler(struct scsi_cmnd *cmnd)
1131{
1132 struct Scsi_Host *shost = cmnd->device->host;
1133 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
1134
1135 spin_lock_irq(shost->host_lock);
1136 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
1137 spin_unlock_irq(shost->host_lock);
1138 msleep(1000);
1139 spin_lock_irq(shost->host_lock);
1140 }
1141 spin_unlock_irq(shost->host_lock);
1142 return;
1143}
James.Smart@Emulex.Com63c59c32005-11-28 11:41:53 -05001144
dea31012005-04-17 16:05:31 -05001145static int
James.Smart@Emulex.Com63c59c32005-11-28 11:41:53 -05001146lpfc_abort_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05001147{
James Smart2e0fef82007-06-17 19:56:36 -05001148 struct Scsi_Host *shost = cmnd->device->host;
1149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1150 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001151 struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001152 struct lpfc_iocbq *iocb;
1153 struct lpfc_iocbq *abtsiocb;
dea31012005-04-17 16:05:31 -05001154 struct lpfc_scsi_buf *lpfc_cmd;
dea31012005-04-17 16:05:31 -05001155 IOCB_t *cmd, *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001156 int ret = SUCCESS;
James Smartfa61a542008-01-11 01:52:42 -05001157 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001158
James Smarta90f5682006-08-17 11:58:04 -04001159 lpfc_block_error_handler(cmnd);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001160 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
1161 BUG_ON(!lpfc_cmd);
dea31012005-04-17 16:05:31 -05001162
1163 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001164 * If pCmd field of the corresponding lpfc_scsi_buf structure
1165 * points to a different SCSI command, then the driver has
1166 * already completed this command, but the midlayer did not
1167 * see the completion before the eh fired. Just return
1168 * SUCCESS.
dea31012005-04-17 16:05:31 -05001169 */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001170 iocb = &lpfc_cmd->cur_iocbq;
1171 if (lpfc_cmd->pCmd != cmnd)
1172 goto out;
dea31012005-04-17 16:05:31 -05001173
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001174 BUG_ON(iocb->context1 != lpfc_cmd);
dea31012005-04-17 16:05:31 -05001175
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001176 abtsiocb = lpfc_sli_get_iocbq(phba);
1177 if (abtsiocb == NULL) {
1178 ret = FAILED;
dea31012005-04-17 16:05:31 -05001179 goto out;
1180 }
1181
dea31012005-04-17 16:05:31 -05001182 /*
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001183 * The scsi command can not be in txq and it is in flight because the
1184 * pCmd is still pointig at the SCSI command we have to abort. There
1185 * is no need to search the txcmplq. Just send an abort to the FW.
dea31012005-04-17 16:05:31 -05001186 */
dea31012005-04-17 16:05:31 -05001187
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001188 cmd = &iocb->iocb;
1189 icmd = &abtsiocb->iocb;
1190 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
1191 icmd->un.acxri.abortContextTag = cmd->ulpContext;
1192 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
dea31012005-04-17 16:05:31 -05001193
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001194 icmd->ulpLe = 1;
1195 icmd->ulpClass = cmd->ulpClass;
James Smart2e0fef82007-06-17 19:56:36 -05001196 if (lpfc_is_link_up(phba))
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001197 icmd->ulpCommand = CMD_ABORT_XRI_CN;
1198 else
1199 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
dea31012005-04-17 16:05:31 -05001200
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001201 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
James Smart2e0fef82007-06-17 19:56:36 -05001202 abtsiocb->vport = vport;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001203 if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) {
1204 lpfc_sli_release_iocbq(phba, abtsiocb);
1205 ret = FAILED;
1206 goto out;
1207 }
1208
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001209 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1210 lpfc_sli_poll_fcp_ring (phba);
1211
James Smartfa61a542008-01-11 01:52:42 -05001212 lpfc_cmd->waitq = &waitq;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001213 /* Wait for abort to complete */
James Smartfa61a542008-01-11 01:52:42 -05001214 wait_event_timeout(waitq,
1215 (lpfc_cmd->pCmd != cmnd),
1216 (2*vport->cfg_devloss_tmo*HZ));
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001217
James Smartfa61a542008-01-11 01:52:42 -05001218 spin_lock_irq(shost->host_lock);
1219 lpfc_cmd->waitq = NULL;
1220 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001221
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001222 if (lpfc_cmd->pCmd == cmnd) {
1223 ret = FAILED;
James Smarte8b62012007-08-02 11:10:09 -04001224 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1225 "0748 abort handler timed out waiting "
1226 "for abort to complete: ret %#x, ID %d, "
1227 "LUN %d, snum %#lx\n",
1228 ret, cmnd->device->id, cmnd->device->lun,
1229 cmnd->serial_number);
dea31012005-04-17 16:05:31 -05001230 }
1231
1232 out:
James Smarte8b62012007-08-02 11:10:09 -04001233 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1234 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
1235 "LUN %d snum %#lx\n", ret, cmnd->device->id,
1236 cmnd->device->lun, cmnd->serial_number);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001237 return ret;
dea31012005-04-17 16:05:31 -05001238}
1239
1240static int
James Smart7054a602007-04-25 09:52:34 -04001241lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05001242{
James Smart2e0fef82007-06-17 19:56:36 -05001243 struct Scsi_Host *shost = cmnd->device->host;
1244 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1245 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001246 struct lpfc_scsi_buf *lpfc_cmd;
1247 struct lpfc_iocbq *iocbq, *iocbqrsp;
dea31012005-04-17 16:05:31 -05001248 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
1249 struct lpfc_nodelist *pnode = rdata->pnode;
James Smart915caaa2008-06-14 22:52:38 -04001250 unsigned long later;
1251 int ret = SUCCESS;
1252 int status;
1253 int cnt;
dea31012005-04-17 16:05:31 -05001254
James Smarta90f5682006-08-17 11:58:04 -04001255 lpfc_block_error_handler(cmnd);
dea31012005-04-17 16:05:31 -05001256 /*
1257 * If target is not in a MAPPED state, delay the reset until
James Smartc01f3202006-08-18 17:47:08 -04001258 * target is rediscovered or devloss timeout expires.
dea31012005-04-17 16:05:31 -05001259 */
James Smart915caaa2008-06-14 22:52:38 -04001260 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1261 while (time_after(later, jiffies)) {
James Smart58da1ff2008-04-07 10:15:56 -04001262 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
James Smart915caaa2008-06-14 22:52:38 -04001263 return FAILED;
James Smartf5603512006-12-02 13:35:43 -05001264 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
dea31012005-04-17 16:05:31 -05001265 break;
James Smart915caaa2008-06-14 22:52:38 -04001266 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1267 rdata = cmnd->device->hostdata;
1268 if (!rdata)
1269 break;
1270 pnode = rdata->pnode;
dea31012005-04-17 16:05:31 -05001271 }
James Smart915caaa2008-06-14 22:52:38 -04001272 if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1273 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1274 "0721 LUN Reset rport "
1275 "failure: msec x%x rdata x%p\n",
1276 jiffies_to_msecs(jiffies - later), rdata);
1277 return FAILED;
1278 }
James Smart2e0fef82007-06-17 19:56:36 -05001279 lpfc_cmd = lpfc_get_scsi_buf(phba);
dea31012005-04-17 16:05:31 -05001280 if (lpfc_cmd == NULL)
James Smart915caaa2008-06-14 22:52:38 -04001281 return FAILED;
dea31012005-04-17 16:05:31 -05001282 lpfc_cmd->timeout = 60;
James Smart0b18ac42006-05-01 21:50:40 -04001283 lpfc_cmd->rdata = rdata;
dea31012005-04-17 16:05:31 -05001284
James Smart915caaa2008-06-14 22:52:38 -04001285 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd,
1286 cmnd->device->lun,
1287 FCP_TARGET_RESET);
1288 if (!status) {
1289 lpfc_release_scsi_buf(phba, lpfc_cmd);
1290 return FAILED;
1291 }
dea31012005-04-17 16:05:31 -05001292 iocbq = &lpfc_cmd->cur_iocbq;
1293
1294 /* get a buffer for this IOCB command response */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001295 iocbqrsp = lpfc_sli_get_iocbq(phba);
James Smart915caaa2008-06-14 22:52:38 -04001296 if (iocbqrsp == NULL) {
1297 lpfc_release_scsi_buf(phba, lpfc_cmd);
1298 return FAILED;
1299 }
James Smarte8b62012007-08-02 11:10:09 -04001300 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
1301 "0703 Issue target reset to TGT %d LUN %d "
1302 "rpi x%x nlp_flag x%x\n", cmnd->device->id,
1303 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
James Smart915caaa2008-06-14 22:52:38 -04001304 status = lpfc_sli_issue_iocb_wait(phba,
1305 &phba->sli.ring[phba->sli.fcp_ring],
1306 iocbq, iocbqrsp, lpfc_cmd->timeout);
1307 if (status == IOCB_TIMEDOUT) {
James Smart7054a602007-04-25 09:52:34 -04001308 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
James Smart915caaa2008-06-14 22:52:38 -04001309 ret = TIMEOUT_ERROR;
1310 } else {
1311 if (status != IOCB_SUCCESS)
1312 ret = FAILED;
James Smart7054a602007-04-25 09:52:34 -04001313 lpfc_release_scsi_buf(phba, lpfc_cmd);
1314 }
James Smarte8b62012007-08-02 11:10:09 -04001315 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1316 "0713 SCSI layer issued device reset (%d, %d) "
1317 "return x%x status x%x result x%x\n",
1318 cmnd->device->id, cmnd->device->lun, ret,
James Smart915caaa2008-06-14 22:52:38 -04001319 iocbqrsp->iocb.ulpStatus,
1320 iocbqrsp->iocb.un.ulpWord[4]);
1321 lpfc_sli_release_iocbq(phba, iocbqrsp);
1322 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
1323 LPFC_CTX_TGT);
1324 if (cnt)
1325 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1326 cmnd->device->id, cmnd->device->lun,
1327 LPFC_CTX_TGT);
1328 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1329 while (time_after(later, jiffies) && cnt) {
1330 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
1331 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
1332 cmnd->device->lun, LPFC_CTX_TGT);
1333 }
1334 if (cnt) {
1335 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1336 "0719 device reset I/O flush failure: "
1337 "cnt x%x\n", cnt);
1338 ret = FAILED;
1339 }
dea31012005-04-17 16:05:31 -05001340 return ret;
1341}
1342
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04001343static int
James Smart7054a602007-04-25 09:52:34 -04001344lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
dea31012005-04-17 16:05:31 -05001345{
James Smart2e0fef82007-06-17 19:56:36 -05001346 struct Scsi_Host *shost = cmnd->device->host;
1347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1348 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001349 struct lpfc_nodelist *ndlp = NULL;
1350 int match;
James Smartd7c255b2008-08-24 21:50:00 -04001351 int ret = SUCCESS, status = SUCCESS, i;
James Smart915caaa2008-06-14 22:52:38 -04001352 int cnt;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001353 struct lpfc_scsi_buf * lpfc_cmd;
James Smart915caaa2008-06-14 22:52:38 -04001354 unsigned long later;
dea31012005-04-17 16:05:31 -05001355
James Smarta90f5682006-08-17 11:58:04 -04001356 lpfc_block_error_handler(cmnd);
dea31012005-04-17 16:05:31 -05001357 /*
1358 * Since the driver manages a single bus device, reset all
1359 * targets known to the driver. Should any target reset
1360 * fail, this routine returns failure to the midlayer.
1361 */
James Smarte17da182006-07-06 15:49:25 -04001362 for (i = 0; i < LPFC_MAX_TARGET; i++) {
James Smart685f0bf2007-04-25 09:53:08 -04001363 /* Search for mapped node by target ID */
dea31012005-04-17 16:05:31 -05001364 match = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001365 spin_lock_irq(shost->host_lock);
1366 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001367 if (!NLP_CHK_NODE_ACT(ndlp))
1368 continue;
James Smart685f0bf2007-04-25 09:53:08 -04001369 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart915caaa2008-06-14 22:52:38 -04001370 ndlp->nlp_sid == i &&
James Smart685f0bf2007-04-25 09:53:08 -04001371 ndlp->rport) {
dea31012005-04-17 16:05:31 -05001372 match = 1;
1373 break;
1374 }
1375 }
James Smart2e0fef82007-06-17 19:56:36 -05001376 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001377 if (!match)
1378 continue;
James Smart915caaa2008-06-14 22:52:38 -04001379 lpfc_cmd = lpfc_get_scsi_buf(phba);
1380 if (lpfc_cmd) {
1381 lpfc_cmd->timeout = 60;
1382 status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
1383 cmnd->device->lun,
1384 ndlp->rport->dd_data);
1385 if (status != TIMEOUT_ERROR)
1386 lpfc_release_scsi_buf(phba, lpfc_cmd);
1387 }
1388 if (!lpfc_cmd || status != SUCCESS) {
James Smarte8b62012007-08-02 11:10:09 -04001389 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1390 "0700 Bus Reset on target %d failed\n",
1391 i);
James Smart915caaa2008-06-14 22:52:38 -04001392 ret = FAILED;
dea31012005-04-17 16:05:31 -05001393 }
1394 }
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05001395 /*
1396 * All outstanding txcmplq I/Os should have been aborted by
1397 * the targets. Unfortunately, some targets do not abide by
1398 * this forcing the driver to double check.
1399 */
James Smart51ef4c22007-08-02 11:10:31 -04001400 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05001401 if (cnt)
James Smart51ef4c22007-08-02 11:10:31 -04001402 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1403 0, 0, LPFC_CTX_HOST);
James Smart915caaa2008-06-14 22:52:38 -04001404 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1405 while (time_after(later, jiffies) && cnt) {
1406 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
James Smart51ef4c22007-08-02 11:10:31 -04001407 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
dea31012005-04-17 16:05:31 -05001408 }
dea31012005-04-17 16:05:31 -05001409 if (cnt) {
James Smarte8b62012007-08-02 11:10:09 -04001410 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1411 "0715 Bus Reset I/O flush failure: "
1412 "cnt x%x left x%x\n", cnt, i);
James.Smart@Emulex.Com6175c022005-11-28 11:42:05 -05001413 ret = FAILED;
dea31012005-04-17 16:05:31 -05001414 }
James Smarte8b62012007-08-02 11:10:09 -04001415 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1416 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
dea31012005-04-17 16:05:31 -05001417 return ret;
1418}
1419
1420static int
dea31012005-04-17 16:05:31 -05001421lpfc_slave_alloc(struct scsi_device *sdev)
1422{
James Smart2e0fef82007-06-17 19:56:36 -05001423 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1424 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001425 struct lpfc_scsi_buf *scsi_buf = NULL;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001426 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
dea31012005-04-17 16:05:31 -05001427 uint32_t total = 0, i;
1428 uint32_t num_to_alloc = 0;
1429 unsigned long flags;
dea31012005-04-17 16:05:31 -05001430
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001431 if (!rport || fc_remote_port_chkready(rport))
dea31012005-04-17 16:05:31 -05001432 return -ENXIO;
1433
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001434 sdev->hostdata = rport->dd_data;
dea31012005-04-17 16:05:31 -05001435
1436 /*
1437 * Populate the cmds_per_lun count scsi_bufs into this host's globally
1438 * available list of scsi buffers. Don't allocate more than the
James.Smart@Emulex.Coma784efb2005-10-28 20:29:51 -04001439 * HBA limit conveyed to the midlayer via the host structure. The
1440 * formula accounts for the lun_queue_depth + error handlers + 1
1441 * extra. This list of scsi bufs exists for the lifetime of the driver.
dea31012005-04-17 16:05:31 -05001442 */
1443 total = phba->total_scsi_bufs;
James Smart3de2a652007-08-02 11:09:59 -04001444 num_to_alloc = vport->cfg_lun_queue_depth + 2;
James Smart92d7f7b2007-06-17 19:56:38 -05001445
1446 /* Allow some exchanges to be available always to complete discovery */
1447 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04001448 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1449 "0704 At limitation of %d preallocated "
1450 "command buffers\n", total);
dea31012005-04-17 16:05:31 -05001451 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001452 /* Allow some exchanges to be available always to complete discovery */
1453 } else if (total + num_to_alloc >
1454 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
James Smarte8b62012007-08-02 11:10:09 -04001455 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1456 "0705 Allocation request of %d "
1457 "command buffers will exceed max of %d. "
1458 "Reducing allocation request to %d.\n",
1459 num_to_alloc, phba->cfg_hba_queue_depth,
1460 (phba->cfg_hba_queue_depth - total));
dea31012005-04-17 16:05:31 -05001461 num_to_alloc = phba->cfg_hba_queue_depth - total;
1462 }
1463
1464 for (i = 0; i < num_to_alloc; i++) {
James Smart2e0fef82007-06-17 19:56:36 -05001465 scsi_buf = lpfc_new_scsi_buf(vport);
dea31012005-04-17 16:05:31 -05001466 if (!scsi_buf) {
James Smarte8b62012007-08-02 11:10:09 -04001467 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1468 "0706 Failed to allocate "
1469 "command buffer\n");
dea31012005-04-17 16:05:31 -05001470 break;
1471 }
1472
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001473 spin_lock_irqsave(&phba->scsi_buf_list_lock, flags);
dea31012005-04-17 16:05:31 -05001474 phba->total_scsi_bufs++;
1475 list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001476 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags);
dea31012005-04-17 16:05:31 -05001477 }
1478 return 0;
1479}
1480
1481static int
1482lpfc_slave_configure(struct scsi_device *sdev)
1483{
James Smart2e0fef82007-06-17 19:56:36 -05001484 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1485 struct lpfc_hba *phba = vport->phba;
1486 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
dea31012005-04-17 16:05:31 -05001487
1488 if (sdev->tagged_supported)
James Smart3de2a652007-08-02 11:09:59 -04001489 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05001490 else
James Smart3de2a652007-08-02 11:09:59 -04001491 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
dea31012005-04-17 16:05:31 -05001492
1493 /*
1494 * Initialize the fc transport attributes for the target
1495 * containing this scsi device. Also note that the driver's
1496 * target pointer is stored in the starget_data for the
1497 * driver's sysfs entry point functions.
1498 */
James Smart3de2a652007-08-02 11:09:59 -04001499 rport->dev_loss_tmo = vport->cfg_devloss_tmo;
dea31012005-04-17 16:05:31 -05001500
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001501 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1502 lpfc_sli_poll_fcp_ring(phba);
1503 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1504 lpfc_poll_rearm_timer(phba);
1505 }
1506
dea31012005-04-17 16:05:31 -05001507 return 0;
1508}
1509
1510static void
1511lpfc_slave_destroy(struct scsi_device *sdev)
1512{
1513 sdev->hostdata = NULL;
1514 return;
1515}
1516
James Smart92d7f7b2007-06-17 19:56:38 -05001517
dea31012005-04-17 16:05:31 -05001518struct scsi_host_template lpfc_template = {
1519 .module = THIS_MODULE,
1520 .name = LPFC_DRIVER_NAME,
1521 .info = lpfc_info,
1522 .queuecommand = lpfc_queuecommand,
1523 .eh_abort_handler = lpfc_abort_handler,
James Smart7054a602007-04-25 09:52:34 -04001524 .eh_device_reset_handler= lpfc_device_reset_handler,
1525 .eh_bus_reset_handler = lpfc_bus_reset_handler,
dea31012005-04-17 16:05:31 -05001526 .slave_alloc = lpfc_slave_alloc,
1527 .slave_configure = lpfc_slave_configure,
1528 .slave_destroy = lpfc_slave_destroy,
James Smart47a86172007-04-25 09:53:22 -04001529 .scan_finished = lpfc_scan_finished,
dea31012005-04-17 16:05:31 -05001530 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05001531 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
dea31012005-04-17 16:05:31 -05001532 .cmd_per_lun = LPFC_CMD_PER_LUN,
1533 .use_clustering = ENABLE_CLUSTERING,
James Smart2e0fef82007-06-17 19:56:36 -05001534 .shost_attrs = lpfc_hba_attrs,
James.Smart@Emulex.Com564b2962005-06-25 10:34:17 -04001535 .max_sectors = 0xFFFF,
dea31012005-04-17 16:05:31 -05001536};
James Smart3de2a652007-08-02 11:09:59 -04001537
1538struct scsi_host_template lpfc_vport_template = {
1539 .module = THIS_MODULE,
1540 .name = LPFC_DRIVER_NAME,
1541 .info = lpfc_info,
1542 .queuecommand = lpfc_queuecommand,
1543 .eh_abort_handler = lpfc_abort_handler,
1544 .eh_device_reset_handler= lpfc_device_reset_handler,
1545 .eh_bus_reset_handler = lpfc_bus_reset_handler,
1546 .slave_alloc = lpfc_slave_alloc,
1547 .slave_configure = lpfc_slave_configure,
1548 .slave_destroy = lpfc_slave_destroy,
1549 .scan_finished = lpfc_scan_finished,
1550 .this_id = -1,
James Smart83108bd2008-01-11 01:53:09 -05001551 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
James Smart3de2a652007-08-02 11:09:59 -04001552 .cmd_per_lun = LPFC_CMD_PER_LUN,
1553 .use_clustering = ENABLE_CLUSTERING,
1554 .shost_attrs = lpfc_vport_attrs,
1555 .max_sectors = 0xFFFF,
1556};