]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/scsi/lpfc/lpfc_scsi.c
[SCSI] lpfc 8.2.7 : Miscellaneous Fixes
[mirror_ubuntu-zesty-kernel.git] / drivers / scsi / lpfc / lpfc_scsi.c
CommitLineData
dea3101e
JB
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
e47c9093 4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e
JB
8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea3101e
JB
20 *******************************************************************/
21
dea3101e
JB
22#include <linux/pci.h>
23#include <linux/interrupt.h>
a90f5684 24#include <linux/delay.h>
dea3101e
JB
25
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"
92d7f7b0 40#include "lpfc_vport.h"
dea3101e
JB
41
42#define LPFC_RESET_WAIT 2
43#define LPFC_ABORT_WAIT 2
44
92d7f7b0
JS
45/*
46 * 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;
5e9d9b82 53 uint32_t evt_posted;
92d7f7b0
JS
54
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);
5e9d9b82
JS
69 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
70 if (!evt_posted)
92d7f7b0 71 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
92d7f7b0
JS
72 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
73
5e9d9b82
JS
74 if (!evt_posted)
75 lpfc_worker_wake_up(phba);
92d7f7b0
JS
76 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
3de2a653 84lpfc_rampup_queue_depth(struct lpfc_vport *vport,
92d7f7b0
JS
85 struct scsi_device *sdev)
86{
87 unsigned long flags;
3de2a653 88 struct lpfc_hba *phba = vport->phba;
5e9d9b82 89 uint32_t evt_posted;
92d7f7b0
JS
90 atomic_inc(&phba->num_cmd_success);
91
3de2a653 92 if (vport->cfg_lun_queue_depth <= sdev->queue_depth)
92d7f7b0 93 return;
92d7f7b0
JS
94 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 }
92d7f7b0
JS
100 phba->last_ramp_up_time = jiffies;
101 spin_unlock_irqrestore(&phba->hbalock, flags);
102
103 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
5e9d9b82
JS
104 evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
105 if (!evt_posted)
92d7f7b0 106 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
92d7f7b0
JS
107 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
108
5e9d9b82
JS
109 if (!evt_posted)
110 lpfc_worker_wake_up(phba);
111 return;
92d7f7b0
JS
112}
113
114void
115lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
116{
549e55cd
JS
117 struct lpfc_vport **vports;
118 struct Scsi_Host *shost;
92d7f7b0
JS
119 struct scsi_device *sdev;
120 unsigned long new_queue_depth;
121 unsigned long num_rsrc_err, num_cmd_success;
549e55cd 122 int i;
92d7f7b0
JS
123
124 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
125 num_cmd_success = atomic_read(&phba->num_cmd_success);
126
549e55cd
JS
127 vports = lpfc_create_vport_work_array(phba);
128 if (vports != NULL)
09372820 129 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
549e55cd
JS
130 shost = lpfc_shost_from_vport(vports[i]);
131 shost_for_each_device(sdev, shost) {
92d7f7b0 132 new_queue_depth =
549e55cd
JS
133 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 }
92d7f7b0 149 }
09372820 150 lpfc_destroy_vport_work_array(phba, vports);
92d7f7b0
JS
151 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{
549e55cd
JS
158 struct lpfc_vport **vports;
159 struct Scsi_Host *shost;
92d7f7b0 160 struct scsi_device *sdev;
549e55cd
JS
161 int i;
162
163 vports = lpfc_create_vport_work_array(phba);
164 if (vports != NULL)
09372820 165 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
549e55cd
JS
166 shost = lpfc_shost_from_vport(vports[i]);
167 shost_for_each_device(sdev, shost) {
97eab634
JS
168 if (vports[i]->cfg_lun_queue_depth <=
169 sdev->queue_depth)
170 continue;
549e55cd
JS
171 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 }
92d7f7b0 180 }
09372820 181 lpfc_destroy_vport_work_array(phba, vports);
92d7f7b0
JS
182 atomic_set(&phba->num_rsrc_err, 0);
183 atomic_set(&phba->num_cmd_success, 0);
184}
185
dea3101e
JB
186/*
187 * This routine allocates a scsi buffer, which contains all the necessary
188 * information needed to initiate a SCSI I/O. The non-DMAable buffer region
189 * contains information to build the IOCB. The DMAable region contains
190 * memory for the FCP CMND, FCP RSP, and the inital BPL. In addition to
191 * allocating memeory, the FCP CMND and FCP RSP BDEs are setup in the BPL
192 * and the BPL BDE is setup in the IOCB.
193 */
194static struct lpfc_scsi_buf *
2e0fef85 195lpfc_new_scsi_buf(struct lpfc_vport *vport)
dea3101e 196{
2e0fef85 197 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
198 struct lpfc_scsi_buf *psb;
199 struct ulp_bde64 *bpl;
200 IOCB_t *iocb;
201 dma_addr_t pdma_phys;
604a3e30 202 uint16_t iotag;
dea3101e 203
bbfbbbc1 204 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
dea3101e
JB
205 if (!psb)
206 return NULL;
dea3101e
JB
207
208 /*
209 * Get memory from the pci pool to map the virt space to pci bus space
210 * for an I/O. The DMA buffer includes space for the struct fcp_cmnd,
211 * struct fcp_rsp and the number of bde's necessary to support the
212 * sg_tablesize.
213 */
214 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL,
215 &psb->dma_handle);
216 if (!psb->data) {
217 kfree(psb);
218 return NULL;
219 }
220
221 /* Initialize virtual ptrs to dma_buf region. */
222 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
223
604a3e30
JB
224 /* Allocate iotag for psb->cur_iocbq. */
225 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
226 if (iotag == 0) {
227 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
228 psb->data, psb->dma_handle);
229 kfree (psb);
230 return NULL;
231 }
0bd4ca25 232 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
604a3e30 233
dea3101e
JB
234 psb->fcp_cmnd = psb->data;
235 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
236 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
237 sizeof(struct fcp_rsp);
238
239 /* Initialize local short-hand pointers. */
240 bpl = psb->fcp_bpl;
241 pdma_phys = psb->dma_handle;
242
243 /*
244 * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg
245 * list bdes. Initialize the first two and leave the rest for
246 * queuecommand.
247 */
248 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
249 bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
250 bpl->tus.f.bdeSize = sizeof (struct fcp_cmnd);
251 bpl->tus.f.bdeFlags = BUFF_USE_CMND;
252 bpl->tus.w = le32_to_cpu(bpl->tus.w);
253 bpl++;
254
255 /* Setup the physical region for the FCP RSP */
256 pdma_phys += sizeof (struct fcp_cmnd);
257 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
258 bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
259 bpl->tus.f.bdeSize = sizeof (struct fcp_rsp);
260 bpl->tus.f.bdeFlags = (BUFF_USE_CMND | BUFF_USE_RCV);
261 bpl->tus.w = le32_to_cpu(bpl->tus.w);
262
263 /*
264 * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf,
265 * initialize it with all known data now.
266 */
267 pdma_phys += (sizeof (struct fcp_rsp));
268 iocb = &psb->cur_iocbq.iocb;
269 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
270 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys);
271 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys);
272 iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
273 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDL;
274 iocb->ulpBdeCount = 1;
275 iocb->ulpClass = CLASS3;
276
277 return psb;
278}
279
455c53ec 280static struct lpfc_scsi_buf*
875fbdfe 281lpfc_get_scsi_buf(struct lpfc_hba * phba)
dea3101e 282{
0bd4ca25
JSEC
283 struct lpfc_scsi_buf * lpfc_cmd = NULL;
284 struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
875fbdfe 285 unsigned long iflag = 0;
0bd4ca25 286
875fbdfe 287 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
0bd4ca25 288 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
1dcb58e5
JS
289 if (lpfc_cmd) {
290 lpfc_cmd->seg_cnt = 0;
291 lpfc_cmd->nonsg_phys = 0;
292 }
875fbdfe 293 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
0bd4ca25
JSEC
294 return lpfc_cmd;
295}
dea3101e 296
0bd4ca25 297static void
92d7f7b0 298lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
0bd4ca25 299{
875fbdfe 300 unsigned long iflag = 0;
dea3101e 301
875fbdfe 302 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
0bd4ca25 303 psb->pCmd = NULL;
dea3101e 304 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
875fbdfe 305 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
dea3101e
JB
306}
307
308static int
92d7f7b0 309lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
dea3101e
JB
310{
311 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
312 struct scatterlist *sgel = NULL;
313 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
314 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
315 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
316 dma_addr_t physaddr;
317 uint32_t i, num_bde = 0;
a0b4f78f 318 int nseg, datadir = scsi_cmnd->sc_data_direction;
dea3101e
JB
319
320 /*
321 * There are three possibilities here - use scatter-gather segment, use
322 * the single mapping, or neither. Start the lpfc command prep by
323 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
324 * data bde entry.
325 */
326 bpl += 2;
c59fd9eb 327 if (scsi_sg_count(scsi_cmnd)) {
dea3101e
JB
328 /*
329 * The driver stores the segment count returned from pci_map_sg
330 * because this a count of dma-mappings used to map the use_sg
331 * pages. They are not guaranteed to be the same for those
332 * architectures that implement an IOMMU.
333 */
dea3101e 334
c59fd9eb
FT
335 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
336 scsi_sg_count(scsi_cmnd), datadir);
337 if (unlikely(!nseg))
338 return 1;
339
a0b4f78f 340 lpfc_cmd->seg_cnt = nseg;
dea3101e
JB
341 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
342 printk(KERN_ERR "%s: Too many sg segments from "
343 "dma_map_sg. Config %d, seg_cnt %d",
344 __FUNCTION__, phba->cfg_sg_seg_cnt,
345 lpfc_cmd->seg_cnt);
a0b4f78f 346 scsi_dma_unmap(scsi_cmnd);
dea3101e
JB
347 return 1;
348 }
349
350 /*
351 * The driver established a maximum scatter-gather segment count
352 * during probe that limits the number of sg elements in any
353 * single scsi command. Just run through the seg_cnt and format
354 * the bde's.
355 */
a0b4f78f 356 scsi_for_each_sg(scsi_cmnd, sgel, nseg, i) {
dea3101e
JB
357 physaddr = sg_dma_address(sgel);
358 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
359 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
360 bpl->tus.f.bdeSize = sg_dma_len(sgel);
361 if (datadir == DMA_TO_DEVICE)
362 bpl->tus.f.bdeFlags = 0;
363 else
364 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
365 bpl->tus.w = le32_to_cpu(bpl->tus.w);
366 bpl++;
dea3101e
JB
367 num_bde++;
368 }
c59fd9eb 369 }
dea3101e
JB
370
371 /*
372 * Finish initializing those IOCB fields that are dependent on the
483f05f0
JSEC
373 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
374 * reinitialized since all iocb memory resources are used many times
375 * for transmit, receive, and continuation bpl's.
dea3101e 376 */
483f05f0 377 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
dea3101e
JB
378 iocb_cmd->un.fcpi64.bdl.bdeSize +=
379 (num_bde * sizeof (struct ulp_bde64));
380 iocb_cmd->ulpBdeCount = 1;
381 iocb_cmd->ulpLe = 1;
09372820 382 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
dea3101e
JB
383 return 0;
384}
385
bcf4dbfa
JS
386static void
387lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
388{
389 /*
390 * There are only two special cases to consider. (1) the scsi command
391 * requested scatter-gather usage or (2) the scsi command allocated
392 * a request buffer, but did not request use_sg. There is a third
393 * case, but it does not require resource deallocation.
394 */
a0b4f78f
FT
395 if (psb->seg_cnt > 0)
396 scsi_dma_unmap(psb->pCmd);
bcf4dbfa
JS
397}
398
dea3101e 399static void
2e0fef85
JS
400lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
401 struct lpfc_iocbq *rsp_iocb)
dea3101e
JB
402{
403 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
404 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
405 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
7054a606 406 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
dea3101e
JB
407 uint32_t resp_info = fcprsp->rspStatus2;
408 uint32_t scsi_status = fcprsp->rspStatus3;
c7743956 409 uint32_t *lp;
dea3101e
JB
410 uint32_t host_status = DID_OK;
411 uint32_t rsplen = 0;
c7743956 412 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
dea3101e
JB
413
414 /*
415 * If this is a task management command, there is no
416 * scsi packet associated with this lpfc_cmd. The driver
417 * consumes it.
418 */
419 if (fcpcmd->fcpCntl2) {
420 scsi_status = 0;
421 goto out;
422 }
423
c7743956
JS
424 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
425 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
426 if (snslen > SCSI_SENSE_BUFFERSIZE)
427 snslen = SCSI_SENSE_BUFFERSIZE;
428
429 if (resp_info & RSP_LEN_VALID)
430 rsplen = be32_to_cpu(fcprsp->rspRspLen);
431 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
432 }
433 lp = (uint32_t *)cmnd->sense_buffer;
434
435 if (!scsi_status && (resp_info & RESID_UNDER))
436 logit = LOG_FCP;
437
e8b62011
JS
438 lpfc_printf_vlog(vport, KERN_WARNING, logit,
439 "0730 FCP command x%x failed: x%x SNS x%x x%x "
440 "Data: x%x x%x x%x x%x x%x\n",
441 cmnd->cmnd[0], scsi_status,
442 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
443 be32_to_cpu(fcprsp->rspResId),
444 be32_to_cpu(fcprsp->rspSnsLen),
445 be32_to_cpu(fcprsp->rspRspLen),
446 fcprsp->rspInfo3);
dea3101e
JB
447
448 if (resp_info & RSP_LEN_VALID) {
449 rsplen = be32_to_cpu(fcprsp->rspRspLen);
450 if ((rsplen != 0 && rsplen != 4 && rsplen != 8) ||
451 (fcprsp->rspInfo3 != RSP_NO_FAILURE)) {
452 host_status = DID_ERROR;
453 goto out;
454 }
455 }
456
a0b4f78f 457 scsi_set_resid(cmnd, 0);
dea3101e 458 if (resp_info & RESID_UNDER) {
a0b4f78f 459 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
dea3101e 460
e8b62011
JS
461 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
462 "0716 FCP Read Underrun, expected %d, "
463 "residual %d Data: x%x x%x x%x\n",
464 be32_to_cpu(fcpcmd->fcpDl),
465 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
466 cmnd->underflow);
dea3101e 467
7054a606
JS
468 /*
469 * If there is an under run check if under run reported by
470 * storage array is same as the under run reported by HBA.
471 * If this is not same, there is a dropped frame.
472 */
473 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
474 fcpi_parm &&
a0b4f78f 475 (scsi_get_resid(cmnd) != fcpi_parm)) {
e8b62011
JS
476 lpfc_printf_vlog(vport, KERN_WARNING,
477 LOG_FCP | LOG_FCP_ERROR,
478 "0735 FCP Read Check Error "
479 "and Underrun Data: x%x x%x x%x x%x\n",
480 be32_to_cpu(fcpcmd->fcpDl),
481 scsi_get_resid(cmnd), fcpi_parm,
482 cmnd->cmnd[0]);
a0b4f78f 483 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
7054a606
JS
484 host_status = DID_ERROR;
485 }
dea3101e
JB
486 /*
487 * The cmnd->underflow is the minimum number of bytes that must
488 * be transfered for this command. Provided a sense condition
489 * is not present, make sure the actual amount transferred is at
490 * least the underflow value or fail.
491 */
492 if (!(resp_info & SNS_LEN_VALID) &&
493 (scsi_status == SAM_STAT_GOOD) &&
a0b4f78f
FT
494 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
495 < cmnd->underflow)) {
e8b62011
JS
496 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
497 "0717 FCP command x%x residual "
498 "underrun converted to error "
499 "Data: x%x x%x x%x\n",
66dbfbe6 500 cmnd->cmnd[0], scsi_bufflen(cmnd),
e8b62011 501 scsi_get_resid(cmnd), cmnd->underflow);
dea3101e
JB
502 host_status = DID_ERROR;
503 }
504 } else if (resp_info & RESID_OVER) {
e8b62011
JS
505 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
506 "0720 FCP command x%x residual overrun error. "
507 "Data: x%x x%x \n", cmnd->cmnd[0],
508 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
dea3101e
JB
509 host_status = DID_ERROR;
510
511 /*
512 * Check SLI validation that all the transfer was actually done
513 * (fcpi_parm should be zero). Apply check only to reads.
514 */
515 } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm &&
516 (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
e8b62011
JS
517 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
518 "0734 FCP Read Check Error Data: "
519 "x%x x%x x%x x%x\n",
520 be32_to_cpu(fcpcmd->fcpDl),
521 be32_to_cpu(fcprsp->rspResId),
522 fcpi_parm, cmnd->cmnd[0]);
dea3101e 523 host_status = DID_ERROR;
a0b4f78f 524 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
dea3101e
JB
525 }
526
527 out:
528 cmnd->result = ScsiResult(host_status, scsi_status);
529}
530
531static void
532lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
533 struct lpfc_iocbq *pIocbOut)
534{
535 struct lpfc_scsi_buf *lpfc_cmd =
536 (struct lpfc_scsi_buf *) pIocbIn->context1;
2e0fef85 537 struct lpfc_vport *vport = pIocbIn->vport;
dea3101e
JB
538 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
539 struct lpfc_nodelist *pnode = rdata->pnode;
540 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
445cf4f4
JSEC
541 int result;
542 struct scsi_device *sdev, *tmp_sdev;
543 int depth = 0;
fa61a54e 544 unsigned long flags;
dea3101e
JB
545
546 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
547 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
548
549 if (lpfc_cmd->status) {
550 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
551 (lpfc_cmd->result & IOERR_DRVR_MASK))
552 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
553 else if (lpfc_cmd->status >= IOSTAT_CNT)
554 lpfc_cmd->status = IOSTAT_DEFAULT;
555
e8b62011
JS
556 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
557 "0729 FCP cmd x%x failed <%d/%d> "
558 "status: x%x result: x%x Data: x%x x%x\n",
559 cmd->cmnd[0],
560 cmd->device ? cmd->device->id : 0xffff,
561 cmd->device ? cmd->device->lun : 0xffff,
562 lpfc_cmd->status, lpfc_cmd->result,
563 pIocbOut->iocb.ulpContext,
564 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
dea3101e
JB
565
566 switch (lpfc_cmd->status) {
567 case IOSTAT_FCP_RSP_ERROR:
568 /* Call FCP RSP handler to determine result */
2e0fef85 569 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
dea3101e
JB
570 break;
571 case IOSTAT_NPORT_BSY:
572 case IOSTAT_FABRIC_BSY:
573 cmd->result = ScsiResult(DID_BUS_BUSY, 0);
574 break;
92d7f7b0
JS
575 case IOSTAT_LOCAL_REJECT:
576 if (lpfc_cmd->result == RJT_UNAVAIL_PERM ||
577 lpfc_cmd->result == IOERR_NO_RESOURCES ||
578 lpfc_cmd->result == RJT_LOGIN_REQUIRED) {
579 cmd->result = ScsiResult(DID_REQUEUE, 0);
58da1ffb
JS
580 break;
581 } /* else: fall through */
dea3101e
JB
582 default:
583 cmd->result = ScsiResult(DID_ERROR, 0);
584 break;
585 }
586
58da1ffb 587 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
19a7b4ae
JSEC
588 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
589 cmd->result = ScsiResult(DID_BUS_BUSY, SAM_STAT_BUSY);
dea3101e
JB
590 } else {
591 cmd->result = ScsiResult(DID_OK, 0);
592 }
593
594 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
595 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
596
e8b62011
JS
597 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
598 "0710 Iodone <%d/%d> cmd %p, error "
599 "x%x SNS x%x x%x Data: x%x x%x\n",
600 cmd->device->id, cmd->device->lun, cmd,
601 cmd->result, *lp, *(lp + 3), cmd->retries,
602 scsi_get_resid(cmd));
dea3101e
JB
603 }
604
445cf4f4
JSEC
605 result = cmd->result;
606 sdev = cmd->device;
1dcb58e5 607 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
0bd4ca25
JSEC
608 cmd->scsi_done(cmd);
609
b808608b 610 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
fa61a54e
JS
611 /*
612 * If there is a thread waiting for command completion
613 * wake up the thread.
614 */
615 spin_lock_irqsave(sdev->host->host_lock, flags);
495a714c 616 lpfc_cmd->pCmd = NULL;
fa61a54e
JS
617 if (lpfc_cmd->waitq)
618 wake_up(lpfc_cmd->waitq);
619 spin_unlock_irqrestore(sdev->host->host_lock, flags);
b808608b
JW
620 lpfc_release_scsi_buf(phba, lpfc_cmd);
621 return;
622 }
623
92d7f7b0
JS
624
625 if (!result)
3de2a653 626 lpfc_rampup_queue_depth(vport, sdev);
92d7f7b0 627
58da1ffb 628 if (!result && pnode && NLP_CHK_NODE_ACT(pnode) &&
445cf4f4
JSEC
629 ((jiffies - pnode->last_ramp_up_time) >
630 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
631 ((jiffies - pnode->last_q_full_time) >
632 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
3de2a653 633 (vport->cfg_lun_queue_depth > sdev->queue_depth)) {
445cf4f4 634 shost_for_each_device(tmp_sdev, sdev->host) {
3de2a653 635 if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){
445cf4f4
JSEC
636 if (tmp_sdev->id != sdev->id)
637 continue;
638 if (tmp_sdev->ordered_tags)
639 scsi_adjust_queue_depth(tmp_sdev,
640 MSG_ORDERED_TAG,
641 tmp_sdev->queue_depth+1);
642 else
643 scsi_adjust_queue_depth(tmp_sdev,
644 MSG_SIMPLE_TAG,
645 tmp_sdev->queue_depth+1);
646
647 pnode->last_ramp_up_time = jiffies;
648 }
649 }
650 }
651
652 /*
653 * Check for queue full. If the lun is reporting queue full, then
654 * back off the lun queue depth to prevent target overloads.
655 */
58da1ffb
JS
656 if (result == SAM_STAT_TASK_SET_FULL && pnode &&
657 NLP_CHK_NODE_ACT(pnode)) {
445cf4f4
JSEC
658 pnode->last_q_full_time = jiffies;
659
660 shost_for_each_device(tmp_sdev, sdev->host) {
661 if (tmp_sdev->id != sdev->id)
662 continue;
663 depth = scsi_track_queue_full(tmp_sdev,
664 tmp_sdev->queue_depth - 1);
665 }
666 /*
2e0fef85 667 * The queue depth cannot be lowered any more.
445cf4f4
JSEC
668 * Modify the returned error code to store
669 * the final depth value set by
670 * scsi_track_queue_full.
671 */
672 if (depth == -1)
673 depth = sdev->host->cmd_per_lun;
674
675 if (depth) {
e8b62011
JS
676 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
677 "0711 detected queue full - lun queue "
678 "depth adjusted to %d.\n", depth);
445cf4f4
JSEC
679 }
680 }
681
fa61a54e
JS
682 /*
683 * If there is a thread waiting for command completion
684 * wake up the thread.
685 */
686 spin_lock_irqsave(sdev->host->host_lock, flags);
495a714c 687 lpfc_cmd->pCmd = NULL;
fa61a54e
JS
688 if (lpfc_cmd->waitq)
689 wake_up(lpfc_cmd->waitq);
690 spin_unlock_irqrestore(sdev->host->host_lock, flags);
691
0bd4ca25 692 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea3101e
JB
693}
694
695static void
2e0fef85
JS
696lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
697 struct lpfc_nodelist *pnode)
dea3101e 698{
2e0fef85 699 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
700 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
701 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
702 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
703 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
704 int datadir = scsi_cmnd->sc_data_direction;
7e2b19fb 705 char tag[2];
dea3101e 706
58da1ffb
JS
707 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
708 return;
709
dea3101e 710 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
69859dc4
JSEC
711 /* clear task management bits */
712 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
dea3101e 713
91886523
JSEC
714 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
715 &lpfc_cmd->fcp_cmnd->fcp_lun);
dea3101e
JB
716
717 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
718
7e2b19fb
JS
719 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
720 switch (tag[0]) {
dea3101e
JB
721 case HEAD_OF_QUEUE_TAG:
722 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
723 break;
724 case ORDERED_QUEUE_TAG:
725 fcp_cmnd->fcpCntl1 = ORDERED_Q;
726 break;
727 default:
728 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
729 break;
730 }
731 } else
732 fcp_cmnd->fcpCntl1 = 0;
733
734 /*
735 * There are three possibilities here - use scatter-gather segment, use
736 * the single mapping, or neither. Start the lpfc command prep by
737 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
738 * data bde entry.
739 */
a0b4f78f 740 if (scsi_sg_count(scsi_cmnd)) {
dea3101e
JB
741 if (datadir == DMA_TO_DEVICE) {
742 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
743 iocb_cmd->un.fcpi.fcpi_parm = 0;
744 iocb_cmd->ulpPU = 0;
745 fcp_cmnd->fcpCntl3 = WRITE_DATA;
746 phba->fc4OutputRequests++;
747 } else {
748 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
749 iocb_cmd->ulpPU = PARM_READ_CHECK;
a0b4f78f 750 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
dea3101e
JB
751 fcp_cmnd->fcpCntl3 = READ_DATA;
752 phba->fc4InputRequests++;
753 }
754 } else {
755 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
756 iocb_cmd->un.fcpi.fcpi_parm = 0;
757 iocb_cmd->ulpPU = 0;
758 fcp_cmnd->fcpCntl3 = 0;
759 phba->fc4ControlRequests++;
760 }
761
762 /*
763 * Finish initializing those IOCB fields that are independent
764 * of the scsi_cmnd request_buffer
765 */
766 piocbq->iocb.ulpContext = pnode->nlp_rpi;
767 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
768 piocbq->iocb.ulpFCP2Rcvy = 1;
09372820
JS
769 else
770 piocbq->iocb.ulpFCP2Rcvy = 0;
dea3101e
JB
771
772 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
773 piocbq->context1 = lpfc_cmd;
774 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
775 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
2e0fef85 776 piocbq->vport = vport;
dea3101e
JB
777}
778
779static int
2e0fef85 780lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
dea3101e 781 struct lpfc_scsi_buf *lpfc_cmd,
420b630d 782 unsigned int lun,
dea3101e
JB
783 uint8_t task_mgmt_cmd)
784{
dea3101e
JB
785 struct lpfc_iocbq *piocbq;
786 IOCB_t *piocb;
787 struct fcp_cmnd *fcp_cmnd;
0b18ac42 788 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
dea3101e
JB
789 struct lpfc_nodelist *ndlp = rdata->pnode;
790
58da1ffb
JS
791 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
792 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
dea3101e 793 return 0;
dea3101e 794
dea3101e 795 piocbq = &(lpfc_cmd->cur_iocbq);
2e0fef85
JS
796 piocbq->vport = vport;
797
dea3101e
JB
798 piocb = &piocbq->iocb;
799
800 fcp_cmnd = lpfc_cmd->fcp_cmnd;
420b630d 801 int_to_scsilun(lun, &lpfc_cmd->fcp_cmnd->fcp_lun);
dea3101e
JB
802 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
803
804 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
805
806 piocb->ulpContext = ndlp->nlp_rpi;
807 if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
808 piocb->ulpFCP2Rcvy = 1;
809 }
810 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
811
812 /* ulpTimeout is only one byte */
813 if (lpfc_cmd->timeout > 0xff) {
814 /*
815 * Do not timeout the command at the firmware level.
816 * The driver will provide the timeout mechanism.
817 */
818 piocb->ulpTimeout = 0;
819 } else {
820 piocb->ulpTimeout = lpfc_cmd->timeout;
821 }
822
2e0fef85 823 return 1;
dea3101e
JB
824}
825
7054a606
JS
826static void
827lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
828 struct lpfc_iocbq *cmdiocbq,
829 struct lpfc_iocbq *rspiocbq)
830{
831 struct lpfc_scsi_buf *lpfc_cmd =
832 (struct lpfc_scsi_buf *) cmdiocbq->context1;
833 if (lpfc_cmd)
834 lpfc_release_scsi_buf(phba, lpfc_cmd);
835 return;
836}
837
dea3101e 838static int
2e0fef85 839lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
420b630d
JS
840 unsigned tgt_id, unsigned int lun,
841 struct lpfc_rport_data *rdata)
dea3101e 842{
2e0fef85 843 struct lpfc_hba *phba = vport->phba;
dea3101e 844 struct lpfc_iocbq *iocbq;
0bd4ca25 845 struct lpfc_iocbq *iocbqrsp;
dea3101e 846 int ret;
915caaaf 847 int status;
dea3101e 848
58da1ffb 849 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
f5603511
JS
850 return FAILED;
851
0b18ac42 852 lpfc_cmd->rdata = rdata;
915caaaf 853 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
420b630d 854 FCP_TARGET_RESET);
915caaaf 855 if (!status)
dea3101e
JB
856 return FAILED;
857
dea3101e 858 iocbq = &lpfc_cmd->cur_iocbq;
0bd4ca25
JSEC
859 iocbqrsp = lpfc_sli_get_iocbq(phba);
860
dea3101e
JB
861 if (!iocbqrsp)
862 return FAILED;
dea3101e 863
0b18ac42 864 /* Issue Target Reset to TGT <num> */
e8b62011
JS
865 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
866 "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
867 tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
915caaaf 868 status = lpfc_sli_issue_iocb_wait(phba,
68876920
JSEC
869 &phba->sli.ring[phba->sli.fcp_ring],
870 iocbq, iocbqrsp, lpfc_cmd->timeout);
915caaaf
JS
871 if (status != IOCB_SUCCESS) {
872 if (status == IOCB_TIMEDOUT) {
7054a606 873 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
915caaaf
JS
874 ret = TIMEOUT_ERROR;
875 } else
876 ret = FAILED;
dea3101e 877 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
dea3101e
JB
878 } else {
879 ret = SUCCESS;
880 lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
881 lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
882 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
883 (lpfc_cmd->result & IOERR_DRVR_MASK))
884 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
885 }
886
604a3e30 887 lpfc_sli_release_iocbq(phba, iocbqrsp);
dea3101e
JB
888 return ret;
889}
890
dea3101e
JB
891const char *
892lpfc_info(struct Scsi_Host *host)
893{
2e0fef85
JS
894 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
895 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
896 int len;
897 static char lpfcinfobuf[384];
898
899 memset(lpfcinfobuf,0,384);
900 if (phba && phba->pcidev){
901 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
902 len = strlen(lpfcinfobuf);
903 snprintf(lpfcinfobuf + len,
904 384-len,
905 " on PCI bus %02x device %02x irq %d",
906 phba->pcidev->bus->number,
907 phba->pcidev->devfn,
908 phba->pcidev->irq);
909 len = strlen(lpfcinfobuf);
910 if (phba->Port[0]) {
911 snprintf(lpfcinfobuf + len,
912 384-len,
913 " port %s",
914 phba->Port);
915 }
916 }
917 return lpfcinfobuf;
918}
919
875fbdfe
JSEC
920static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
921{
922 unsigned long poll_tmo_expires =
923 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
924
925 if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
926 mod_timer(&phba->fcp_poll_timer,
927 poll_tmo_expires);
928}
929
930void lpfc_poll_start_timer(struct lpfc_hba * phba)
931{
932 lpfc_poll_rearm_timer(phba);
933}
934
935void lpfc_poll_timeout(unsigned long ptr)
936{
2e0fef85 937 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
875fbdfe
JSEC
938
939 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
940 lpfc_sli_poll_fcp_ring (phba);
941 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
942 lpfc_poll_rearm_timer(phba);
943 }
875fbdfe
JSEC
944}
945
dea3101e
JB
946static int
947lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
948{
2e0fef85
JS
949 struct Scsi_Host *shost = cmnd->device->host;
950 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
951 struct lpfc_hba *phba = vport->phba;
952 struct lpfc_sli *psli = &phba->sli;
dea3101e
JB
953 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
954 struct lpfc_nodelist *ndlp = rdata->pnode;
0bd4ca25 955 struct lpfc_scsi_buf *lpfc_cmd;
19a7b4ae 956 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
19a7b4ae 957 int err;
dea3101e 958
19a7b4ae
JSEC
959 err = fc_remote_port_chkready(rport);
960 if (err) {
961 cmnd->result = err;
dea3101e
JB
962 goto out_fail_command;
963 }
964
965 /*
19a7b4ae
JSEC
966 * Catch race where our node has transitioned, but the
967 * transport is still transitioning.
dea3101e 968 */
58da1ffb 969 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
19a7b4ae
JSEC
970 cmnd->result = ScsiResult(DID_BUS_BUSY, 0);
971 goto out_fail_command;
dea3101e 972 }
ed957684 973 lpfc_cmd = lpfc_get_scsi_buf(phba);
dea3101e 974 if (lpfc_cmd == NULL) {
92d7f7b0
JS
975 lpfc_adjust_queue_depth(phba);
976
e8b62011
JS
977 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
978 "0707 driver's buffer pool is empty, "
979 "IO busied\n");
dea3101e
JB
980 goto out_host_busy;
981 }
982
983 /*
984 * Store the midlayer's command structure for the completion phase
985 * and complete the command initialization.
986 */
987 lpfc_cmd->pCmd = cmnd;
988 lpfc_cmd->rdata = rdata;
989 lpfc_cmd->timeout = 0;
990 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
991 cmnd->scsi_done = done;
992
993 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
994 if (err)
995 goto out_host_busy_free_buf;
996
2e0fef85 997 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
dea3101e
JB
998
999 err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring],
92d7f7b0 1000 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
dea3101e
JB
1001 if (err)
1002 goto out_host_busy_free_buf;
875fbdfe
JSEC
1003
1004 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1005 lpfc_sli_poll_fcp_ring(phba);
1006 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1007 lpfc_poll_rearm_timer(phba);
1008 }
1009
dea3101e
JB
1010 return 0;
1011
1012 out_host_busy_free_buf:
bcf4dbfa 1013 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
0bd4ca25 1014 lpfc_release_scsi_buf(phba, lpfc_cmd);
dea3101e
JB
1015 out_host_busy:
1016 return SCSI_MLQUEUE_HOST_BUSY;
1017
1018 out_fail_command:
1019 done(cmnd);
1020 return 0;
1021}
1022
a90f5684
JS
1023static void
1024lpfc_block_error_handler(struct scsi_cmnd *cmnd)
1025{
1026 struct Scsi_Host *shost = cmnd->device->host;
1027 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
1028
1029 spin_lock_irq(shost->host_lock);
1030 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
1031 spin_unlock_irq(shost->host_lock);
1032 msleep(1000);
1033 spin_lock_irq(shost->host_lock);
1034 }
1035 spin_unlock_irq(shost->host_lock);
1036 return;
1037}
63c59c3b 1038
dea3101e 1039static int
63c59c3b 1040lpfc_abort_handler(struct scsi_cmnd *cmnd)
dea3101e 1041{
2e0fef85
JS
1042 struct Scsi_Host *shost = cmnd->device->host;
1043 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1044 struct lpfc_hba *phba = vport->phba;
dea3101e 1045 struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
0bd4ca25
JSEC
1046 struct lpfc_iocbq *iocb;
1047 struct lpfc_iocbq *abtsiocb;
dea3101e 1048 struct lpfc_scsi_buf *lpfc_cmd;
dea3101e 1049 IOCB_t *cmd, *icmd;
0bd4ca25 1050 int ret = SUCCESS;
fa61a54e 1051 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
dea3101e 1052
a90f5684 1053 lpfc_block_error_handler(cmnd);
0bd4ca25
JSEC
1054 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
1055 BUG_ON(!lpfc_cmd);
dea3101e 1056
0bd4ca25
JSEC
1057 /*
1058 * If pCmd field of the corresponding lpfc_scsi_buf structure
1059 * points to a different SCSI command, then the driver has
1060 * already completed this command, but the midlayer did not
1061 * see the completion before the eh fired. Just return
1062 * SUCCESS.
1063 */
1064 iocb = &lpfc_cmd->cur_iocbq;
1065 if (lpfc_cmd->pCmd != cmnd)
1066 goto out;
dea3101e 1067
0bd4ca25 1068 BUG_ON(iocb->context1 != lpfc_cmd);
dea3101e 1069
0bd4ca25
JSEC
1070 abtsiocb = lpfc_sli_get_iocbq(phba);
1071 if (abtsiocb == NULL) {
1072 ret = FAILED;
dea3101e
JB
1073 goto out;
1074 }
1075
dea3101e 1076 /*
0bd4ca25
JSEC
1077 * The scsi command can not be in txq and it is in flight because the
1078 * pCmd is still pointig at the SCSI command we have to abort. There
1079 * is no need to search the txcmplq. Just send an abort to the FW.
dea3101e 1080 */
dea3101e 1081
0bd4ca25
JSEC
1082 cmd = &iocb->iocb;
1083 icmd = &abtsiocb->iocb;
1084 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
1085 icmd->un.acxri.abortContextTag = cmd->ulpContext;
1086 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
dea3101e 1087
0bd4ca25
JSEC
1088 icmd->ulpLe = 1;
1089 icmd->ulpClass = cmd->ulpClass;
2e0fef85 1090 if (lpfc_is_link_up(phba))
0bd4ca25
JSEC
1091 icmd->ulpCommand = CMD_ABORT_XRI_CN;
1092 else
1093 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
dea3101e 1094
0bd4ca25 1095 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
2e0fef85 1096 abtsiocb->vport = vport;
0bd4ca25
JSEC
1097 if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) {
1098 lpfc_sli_release_iocbq(phba, abtsiocb);
1099 ret = FAILED;
1100 goto out;
1101 }
dea3101e 1102
875fbdfe
JSEC
1103 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1104 lpfc_sli_poll_fcp_ring (phba);
1105
fa61a54e 1106 lpfc_cmd->waitq = &waitq;
0bd4ca25 1107 /* Wait for abort to complete */
fa61a54e
JS
1108 wait_event_timeout(waitq,
1109 (lpfc_cmd->pCmd != cmnd),
1110 (2*vport->cfg_devloss_tmo*HZ));
875fbdfe 1111
fa61a54e
JS
1112 spin_lock_irq(shost->host_lock);
1113 lpfc_cmd->waitq = NULL;
1114 spin_unlock_irq(shost->host_lock);
dea3101e 1115
0bd4ca25
JSEC
1116 if (lpfc_cmd->pCmd == cmnd) {
1117 ret = FAILED;
e8b62011
JS
1118 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1119 "0748 abort handler timed out waiting "
1120 "for abort to complete: ret %#x, ID %d, "
1121 "LUN %d, snum %#lx\n",
1122 ret, cmnd->device->id, cmnd->device->lun,
1123 cmnd->serial_number);
dea3101e
JB
1124 }
1125
1126 out:
e8b62011
JS
1127 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1128 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
1129 "LUN %d snum %#lx\n", ret, cmnd->device->id,
1130 cmnd->device->lun, cmnd->serial_number);
63c59c3b 1131 return ret;
8fa728a2
JG
1132}
1133
dea3101e 1134static int
7054a606 1135lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
dea3101e 1136{
2e0fef85
JS
1137 struct Scsi_Host *shost = cmnd->device->host;
1138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1139 struct lpfc_hba *phba = vport->phba;
0bd4ca25
JSEC
1140 struct lpfc_scsi_buf *lpfc_cmd;
1141 struct lpfc_iocbq *iocbq, *iocbqrsp;
dea3101e
JB
1142 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
1143 struct lpfc_nodelist *pnode = rdata->pnode;
915caaaf
JS
1144 unsigned long later;
1145 int ret = SUCCESS;
1146 int status;
1147 int cnt;
dea3101e 1148
a90f5684 1149 lpfc_block_error_handler(cmnd);
dea3101e
JB
1150 /*
1151 * If target is not in a MAPPED state, delay the reset until
c01f3208 1152 * target is rediscovered or devloss timeout expires.
dea3101e 1153 */
915caaaf
JS
1154 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1155 while (time_after(later, jiffies)) {
58da1ffb 1156 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
915caaaf 1157 return FAILED;
f5603511 1158 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
dea3101e 1159 break;
915caaaf
JS
1160 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1161 rdata = cmnd->device->hostdata;
1162 if (!rdata)
1163 break;
1164 pnode = rdata->pnode;
1165 }
1166 if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1167 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1168 "0721 LUN Reset rport "
1169 "failure: msec x%x rdata x%p\n",
1170 jiffies_to_msecs(jiffies - later), rdata);
1171 return FAILED;
dea3101e 1172 }
2e0fef85 1173 lpfc_cmd = lpfc_get_scsi_buf(phba);
dea3101e 1174 if (lpfc_cmd == NULL)
915caaaf 1175 return FAILED;
dea3101e 1176 lpfc_cmd->timeout = 60;
0b18ac42 1177 lpfc_cmd->rdata = rdata;
dea3101e 1178
915caaaf
JS
1179 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd,
1180 cmnd->device->lun,
1181 FCP_TARGET_RESET);
1182 if (!status) {
1183 lpfc_release_scsi_buf(phba, lpfc_cmd);
1184 return FAILED;
1185 }
dea3101e
JB
1186 iocbq = &lpfc_cmd->cur_iocbq;
1187
1188 /* get a buffer for this IOCB command response */
0bd4ca25 1189 iocbqrsp = lpfc_sli_get_iocbq(phba);
915caaaf
JS
1190 if (iocbqrsp == NULL) {
1191 lpfc_release_scsi_buf(phba, lpfc_cmd);
1192 return FAILED;
1193 }
e8b62011
JS
1194 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
1195 "0703 Issue target reset to TGT %d LUN %d "
1196 "rpi x%x nlp_flag x%x\n", cmnd->device->id,
1197 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
915caaaf
JS
1198 status = lpfc_sli_issue_iocb_wait(phba,
1199 &phba->sli.ring[phba->sli.fcp_ring],
1200 iocbq, iocbqrsp, lpfc_cmd->timeout);
1201 if (status == IOCB_TIMEDOUT) {
7054a606 1202 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
915caaaf
JS
1203 ret = TIMEOUT_ERROR;
1204 } else {
1205 if (status != IOCB_SUCCESS)
1206 ret = FAILED;
1207 lpfc_release_scsi_buf(phba, lpfc_cmd);
1208 }
1209 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1210 "0713 SCSI layer issued device reset (%d, %d) "
1211 "return x%x status x%x result x%x\n",
1212 cmnd->device->id, cmnd->device->lun, ret,
1213 iocbqrsp->iocb.ulpStatus,
1214 iocbqrsp->iocb.un.ulpWord[4]);
6175c02a 1215 lpfc_sli_release_iocbq(phba, iocbqrsp);
51ef4c26 1216 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
915caaaf 1217 LPFC_CTX_TGT);
6175c02a 1218 if (cnt)
51ef4c26 1219 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
6175c02a 1220 cmnd->device->id, cmnd->device->lun,
915caaaf
JS
1221 LPFC_CTX_TGT);
1222 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1223 while (time_after(later, jiffies) && cnt) {
1224 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
51ef4c26 1225 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
915caaaf 1226 cmnd->device->lun, LPFC_CTX_TGT);
dea3101e 1227 }
dea3101e 1228 if (cnt) {
e8b62011
JS
1229 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1230 "0719 device reset I/O flush failure: "
1231 "cnt x%x\n", cnt);
0bd4ca25 1232 ret = FAILED;
dea3101e 1233 }
dea3101e
JB
1234 return ret;
1235}
1236
94d0e7b8 1237static int
7054a606 1238lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
dea3101e 1239{
2e0fef85
JS
1240 struct Scsi_Host *shost = cmnd->device->host;
1241 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1242 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1243 struct lpfc_nodelist *ndlp = NULL;
1244 int match;
915caaaf
JS
1245 int ret = SUCCESS, status, i;
1246 int cnt;
0bd4ca25 1247 struct lpfc_scsi_buf * lpfc_cmd;
915caaaf 1248 unsigned long later;
dea3101e 1249
a90f5684 1250 lpfc_block_error_handler(cmnd);
dea3101e
JB
1251 /*
1252 * Since the driver manages a single bus device, reset all
1253 * targets known to the driver. Should any target reset
1254 * fail, this routine returns failure to the midlayer.
1255 */
e17da18e 1256 for (i = 0; i < LPFC_MAX_TARGET; i++) {
685f0bf7 1257 /* Search for mapped node by target ID */
dea3101e 1258 match = 0;
2e0fef85
JS
1259 spin_lock_irq(shost->host_lock);
1260 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
e47c9093
JS
1261 if (!NLP_CHK_NODE_ACT(ndlp))
1262 continue;
685f0bf7 1263 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
915caaaf 1264 ndlp->nlp_sid == i &&
685f0bf7 1265 ndlp->rport) {
dea3101e
JB
1266 match = 1;
1267 break;
1268 }
1269 }
2e0fef85 1270 spin_unlock_irq(shost->host_lock);
dea3101e
JB
1271 if (!match)
1272 continue;
915caaaf
JS
1273 lpfc_cmd = lpfc_get_scsi_buf(phba);
1274 if (lpfc_cmd) {
1275 lpfc_cmd->timeout = 60;
1276 status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
1277 cmnd->device->lun,
1278 ndlp->rport->dd_data);
1279 if (status != TIMEOUT_ERROR)
1280 lpfc_release_scsi_buf(phba, lpfc_cmd);
1281 }
1282 if (!lpfc_cmd || status != SUCCESS) {
e8b62011
JS
1283 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1284 "0700 Bus Reset on target %d failed\n",
1285 i);
915caaaf 1286 ret = FAILED;
dea3101e
JB
1287 }
1288 }
6175c02a
JSEC
1289 /*
1290 * All outstanding txcmplq I/Os should have been aborted by
1291 * the targets. Unfortunately, some targets do not abide by
1292 * this forcing the driver to double check.
1293 */
51ef4c26 1294 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
6175c02a 1295 if (cnt)
51ef4c26
JS
1296 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1297 0, 0, LPFC_CTX_HOST);
915caaaf
JS
1298 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1299 while (time_after(later, jiffies) && cnt) {
1300 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
51ef4c26 1301 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
dea3101e 1302 }
dea3101e 1303 if (cnt) {
e8b62011
JS
1304 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1305 "0715 Bus Reset I/O flush failure: "
1306 "cnt x%x left x%x\n", cnt, i);
0bd4ca25 1307 ret = FAILED;
6175c02a 1308 }
e8b62011
JS
1309 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1310 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
dea3101e
JB
1311 return ret;
1312}
1313
1314static int
1315lpfc_slave_alloc(struct scsi_device *sdev)
1316{
2e0fef85
JS
1317 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1318 struct lpfc_hba *phba = vport->phba;
dea3101e 1319 struct lpfc_scsi_buf *scsi_buf = NULL;
19a7b4ae 1320 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
dea3101e
JB
1321 uint32_t total = 0, i;
1322 uint32_t num_to_alloc = 0;
1323 unsigned long flags;
dea3101e 1324
19a7b4ae 1325 if (!rport || fc_remote_port_chkready(rport))
dea3101e
JB
1326 return -ENXIO;
1327
19a7b4ae 1328 sdev->hostdata = rport->dd_data;
dea3101e
JB
1329
1330 /*
1331 * Populate the cmds_per_lun count scsi_bufs into this host's globally
1332 * available list of scsi buffers. Don't allocate more than the
a784efbf
JSEC
1333 * HBA limit conveyed to the midlayer via the host structure. The
1334 * formula accounts for the lun_queue_depth + error handlers + 1
1335 * extra. This list of scsi bufs exists for the lifetime of the driver.
dea3101e
JB
1336 */
1337 total = phba->total_scsi_bufs;
3de2a653 1338 num_to_alloc = vport->cfg_lun_queue_depth + 2;
92d7f7b0
JS
1339
1340 /* Allow some exchanges to be available always to complete discovery */
1341 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
e8b62011
JS
1342 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1343 "0704 At limitation of %d preallocated "
1344 "command buffers\n", total);
dea3101e 1345 return 0;
92d7f7b0
JS
1346 /* Allow some exchanges to be available always to complete discovery */
1347 } else if (total + num_to_alloc >
1348 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
e8b62011
JS
1349 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1350 "0705 Allocation request of %d "
1351 "command buffers will exceed max of %d. "
1352 "Reducing allocation request to %d.\n",
1353 num_to_alloc, phba->cfg_hba_queue_depth,
1354 (phba->cfg_hba_queue_depth - total));
dea3101e
JB
1355 num_to_alloc = phba->cfg_hba_queue_depth - total;
1356 }
1357
1358 for (i = 0; i < num_to_alloc; i++) {
2e0fef85 1359 scsi_buf = lpfc_new_scsi_buf(vport);
dea3101e 1360 if (!scsi_buf) {
e8b62011
JS
1361 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1362 "0706 Failed to allocate "
1363 "command buffer\n");
dea3101e
JB
1364 break;
1365 }
1366
875fbdfe 1367 spin_lock_irqsave(&phba->scsi_buf_list_lock, flags);
dea3101e
JB
1368 phba->total_scsi_bufs++;
1369 list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list);
875fbdfe 1370 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags);
dea3101e
JB
1371 }
1372 return 0;
1373}
1374
1375static int
1376lpfc_slave_configure(struct scsi_device *sdev)
1377{
2e0fef85
JS
1378 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1379 struct lpfc_hba *phba = vport->phba;
1380 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
dea3101e
JB
1381
1382 if (sdev->tagged_supported)
3de2a653 1383 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
dea3101e 1384 else
3de2a653 1385 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
dea3101e
JB
1386
1387 /*
1388 * Initialize the fc transport attributes for the target
1389 * containing this scsi device. Also note that the driver's
1390 * target pointer is stored in the starget_data for the
1391 * driver's sysfs entry point functions.
1392 */
3de2a653 1393 rport->dev_loss_tmo = vport->cfg_devloss_tmo;
dea3101e 1394
875fbdfe
JSEC
1395 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1396 lpfc_sli_poll_fcp_ring(phba);
1397 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1398 lpfc_poll_rearm_timer(phba);
1399 }
1400
dea3101e
JB
1401 return 0;
1402}
1403
1404static void
1405lpfc_slave_destroy(struct scsi_device *sdev)
1406{
1407 sdev->hostdata = NULL;
1408 return;
1409}
1410
92d7f7b0 1411
dea3101e
JB
1412struct scsi_host_template lpfc_template = {
1413 .module = THIS_MODULE,
1414 .name = LPFC_DRIVER_NAME,
1415 .info = lpfc_info,
1416 .queuecommand = lpfc_queuecommand,
1417 .eh_abort_handler = lpfc_abort_handler,
7054a606
JS
1418 .eh_device_reset_handler= lpfc_device_reset_handler,
1419 .eh_bus_reset_handler = lpfc_bus_reset_handler,
dea3101e
JB
1420 .slave_alloc = lpfc_slave_alloc,
1421 .slave_configure = lpfc_slave_configure,
1422 .slave_destroy = lpfc_slave_destroy,
47a8617c 1423 .scan_finished = lpfc_scan_finished,
dea3101e 1424 .this_id = -1,
83108bd3 1425 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
dea3101e
JB
1426 .cmd_per_lun = LPFC_CMD_PER_LUN,
1427 .use_clustering = ENABLE_CLUSTERING,
2e0fef85 1428 .shost_attrs = lpfc_hba_attrs,
564b2960 1429 .max_sectors = 0xFFFF,
dea3101e 1430};
3de2a653
JS
1431
1432struct scsi_host_template lpfc_vport_template = {
1433 .module = THIS_MODULE,
1434 .name = LPFC_DRIVER_NAME,
1435 .info = lpfc_info,
1436 .queuecommand = lpfc_queuecommand,
1437 .eh_abort_handler = lpfc_abort_handler,
1438 .eh_device_reset_handler= lpfc_device_reset_handler,
1439 .eh_bus_reset_handler = lpfc_bus_reset_handler,
1440 .slave_alloc = lpfc_slave_alloc,
1441 .slave_configure = lpfc_slave_configure,
1442 .slave_destroy = lpfc_slave_destroy,
1443 .scan_finished = lpfc_scan_finished,
1444 .this_id = -1,
83108bd3 1445 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
3de2a653
JS
1446 .cmd_per_lun = LPFC_CMD_PER_LUN,
1447 .use_clustering = ENABLE_CLUSTERING,
1448 .shost_attrs = lpfc_vport_attrs,
1449 .max_sectors = 0xFFFF,
1450};