1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
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. *
20 *******************************************************************/
21 #include <linux/pci.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/export.h>
25 #include <linux/delay.h>
26 #include <asm/unaligned.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_eh.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_tcq.h>
33 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_version.h"
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
48 #define LPFC_RESET_WAIT 2
49 #define LPFC_ABORT_WAIT 2
53 static char *dif_op_str
[] = {
63 static char *dif_grd_str
[] = {
69 struct scsi_dif_tuple
{
70 __be16 guard_tag
; /* Checksum */
71 __be16 app_tag
; /* Opaque storage */
72 __be32 ref_tag
; /* Target LBA or indirect LBA */
76 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
78 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
81 lpfc_debug_save_data(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
84 struct scatterlist
*sgde
= scsi_sglist(cmnd
);
86 if (!_dump_buf_data
) {
87 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
88 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
95 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
96 "9051 BLKGRD: ERROR: data scatterlist is null\n");
100 dst
= (void *) _dump_buf_data
;
103 memcpy(dst
, src
, sgde
->length
);
105 sgde
= sg_next(sgde
);
110 lpfc_debug_save_dif(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
113 struct scatterlist
*sgde
= scsi_prot_sglist(cmnd
);
115 if (!_dump_buf_dif
) {
116 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
117 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
123 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
124 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
131 memcpy(dst
, src
, sgde
->length
);
133 sgde
= sg_next(sgde
);
138 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
139 * @phba: Pointer to HBA object.
140 * @lpfc_cmd: lpfc scsi command object pointer.
142 * This function is called from the lpfc_prep_task_mgmt_cmd function to
143 * set the last bit in the response sge entry.
146 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba
*phba
,
147 struct lpfc_scsi_buf
*lpfc_cmd
)
149 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
152 sgl
->word2
= le32_to_cpu(sgl
->word2
);
153 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
154 sgl
->word2
= cpu_to_le32(sgl
->word2
);
159 * lpfc_update_stats - Update statistical data for the command completion
160 * @phba: Pointer to HBA object.
161 * @lpfc_cmd: lpfc scsi command object pointer.
163 * This function is called when there is a command completion and this
164 * function updates the statistical data for the command completion.
167 lpfc_update_stats(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
169 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
170 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
171 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
173 struct Scsi_Host
*shost
= cmd
->device
->host
;
174 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
175 unsigned long latency
;
181 latency
= jiffies_to_msecs((long)jiffies
- (long)lpfc_cmd
->start_time
);
183 spin_lock_irqsave(shost
->host_lock
, flags
);
184 if (!vport
->stat_data_enabled
||
185 vport
->stat_data_blocked
||
188 (phba
->bucket_type
== LPFC_NO_BUCKET
)) {
189 spin_unlock_irqrestore(shost
->host_lock
, flags
);
193 if (phba
->bucket_type
== LPFC_LINEAR_BUCKET
) {
194 i
= (latency
+ phba
->bucket_step
- 1 - phba
->bucket_base
)/
196 /* check array subscript bounds */
199 else if (i
>= LPFC_MAX_BUCKET_COUNT
)
200 i
= LPFC_MAX_BUCKET_COUNT
- 1;
202 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
-1; i
++)
203 if (latency
<= (phba
->bucket_base
+
204 ((1<<i
)*phba
->bucket_step
)))
208 pnode
->lat_data
[i
].cmd_count
++;
209 spin_unlock_irqrestore(shost
->host_lock
, flags
);
213 * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
214 * @phba: Pointer to HBA context object.
215 * @vport: Pointer to vport object.
216 * @ndlp: Pointer to FC node associated with the target.
217 * @lun: Lun number of the scsi device.
218 * @old_val: Old value of the queue depth.
219 * @new_val: New value of the queue depth.
221 * This function sends an event to the mgmt application indicating
222 * there is a change in the scsi device queue depth.
225 lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba
*phba
,
226 struct lpfc_vport
*vport
,
227 struct lpfc_nodelist
*ndlp
,
232 struct lpfc_fast_path_event
*fast_path_evt
;
235 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
239 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.event_type
=
241 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.subcategory
=
242 LPFC_EVENT_VARQUEDEPTH
;
244 /* Report all luns with change in queue depth */
245 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.lun
= lun
;
246 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
247 memcpy(&fast_path_evt
->un
.queue_depth_evt
.scsi_event
.wwpn
,
248 &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
249 memcpy(&fast_path_evt
->un
.queue_depth_evt
.scsi_event
.wwnn
,
250 &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
253 fast_path_evt
->un
.queue_depth_evt
.oldval
= old_val
;
254 fast_path_evt
->un
.queue_depth_evt
.newval
= new_val
;
255 fast_path_evt
->vport
= vport
;
257 fast_path_evt
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
258 spin_lock_irqsave(&phba
->hbalock
, flags
);
259 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
260 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
261 lpfc_worker_wake_up(phba
);
267 * lpfc_change_queue_depth - Alter scsi device queue depth
268 * @sdev: Pointer the scsi device on which to change the queue depth.
269 * @qdepth: New queue depth to set the sdev to.
270 * @reason: The reason for the queue depth change.
272 * This function is called by the midlayer and the LLD to alter the queue
273 * depth for a scsi device. This function sets the queue depth to the new
274 * value and sends an event out to log the queue depth change.
277 lpfc_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
279 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
280 struct lpfc_hba
*phba
= vport
->phba
;
281 struct lpfc_rport_data
*rdata
;
282 unsigned long new_queue_depth
, old_queue_depth
;
284 old_queue_depth
= sdev
->queue_depth
;
285 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
286 new_queue_depth
= sdev
->queue_depth
;
287 rdata
= sdev
->hostdata
;
289 lpfc_send_sdev_queuedepth_change_event(phba
, vport
,
290 rdata
->pnode
, sdev
->lun
,
293 return sdev
->queue_depth
;
297 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
298 * @phba: The Hba for which this call is being executed.
300 * This routine is called when there is resource error in driver or firmware.
301 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
302 * posts at most 1 event each second. This routine wakes up worker thread of
303 * @phba to process WORKER_RAM_DOWN_EVENT event.
305 * This routine should be called with no lock held.
308 lpfc_rampdown_queue_depth(struct lpfc_hba
*phba
)
313 spin_lock_irqsave(&phba
->hbalock
, flags
);
314 atomic_inc(&phba
->num_rsrc_err
);
315 phba
->last_rsrc_error_time
= jiffies
;
317 if ((phba
->last_ramp_down_time
+ QUEUE_RAMP_DOWN_INTERVAL
) > jiffies
) {
318 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
322 phba
->last_ramp_down_time
= jiffies
;
324 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
326 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
327 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_DOWN_QUEUE
;
329 phba
->pport
->work_port_events
|= WORKER_RAMP_DOWN_QUEUE
;
330 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
333 lpfc_worker_wake_up(phba
);
338 * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread
339 * @phba: The Hba for which this call is being executed.
341 * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine
342 * post at most 1 event every 5 minute after last_ramp_up_time or
343 * last_rsrc_error_time. This routine wakes up worker thread of @phba
344 * to process WORKER_RAM_DOWN_EVENT event.
346 * This routine should be called with no lock held.
349 lpfc_rampup_queue_depth(struct lpfc_vport
*vport
,
350 uint32_t queue_depth
)
353 struct lpfc_hba
*phba
= vport
->phba
;
355 atomic_inc(&phba
->num_cmd_success
);
357 if (vport
->cfg_lun_queue_depth
<= queue_depth
)
359 spin_lock_irqsave(&phba
->hbalock
, flags
);
360 if (time_before(jiffies
,
361 phba
->last_ramp_up_time
+ QUEUE_RAMP_UP_INTERVAL
) ||
363 phba
->last_rsrc_error_time
+ QUEUE_RAMP_UP_INTERVAL
)) {
364 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
367 phba
->last_ramp_up_time
= jiffies
;
368 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
370 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
371 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_UP_QUEUE
;
373 phba
->pport
->work_port_events
|= WORKER_RAMP_UP_QUEUE
;
374 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
377 lpfc_worker_wake_up(phba
);
382 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
383 * @phba: The Hba for which this call is being executed.
385 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
386 * thread.This routine reduces queue depth for all scsi device on each vport
387 * associated with @phba.
390 lpfc_ramp_down_queue_handler(struct lpfc_hba
*phba
)
392 struct lpfc_vport
**vports
;
393 struct Scsi_Host
*shost
;
394 struct scsi_device
*sdev
;
395 unsigned long new_queue_depth
;
396 unsigned long num_rsrc_err
, num_cmd_success
;
399 num_rsrc_err
= atomic_read(&phba
->num_rsrc_err
);
400 num_cmd_success
= atomic_read(&phba
->num_cmd_success
);
403 * The error and success command counters are global per
404 * driver instance. If another handler has already
405 * operated on this error event, just exit.
407 if (num_rsrc_err
== 0)
410 vports
= lpfc_create_vport_work_array(phba
);
412 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
413 shost
= lpfc_shost_from_vport(vports
[i
]);
414 shost_for_each_device(sdev
, shost
) {
416 sdev
->queue_depth
* num_rsrc_err
/
417 (num_rsrc_err
+ num_cmd_success
);
418 if (!new_queue_depth
)
419 new_queue_depth
= sdev
->queue_depth
- 1;
421 new_queue_depth
= sdev
->queue_depth
-
423 lpfc_change_queue_depth(sdev
, new_queue_depth
,
424 SCSI_QDEPTH_DEFAULT
);
427 lpfc_destroy_vport_work_array(phba
, vports
);
428 atomic_set(&phba
->num_rsrc_err
, 0);
429 atomic_set(&phba
->num_cmd_success
, 0);
433 * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler
434 * @phba: The Hba for which this call is being executed.
436 * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker
437 * thread.This routine increases queue depth for all scsi device on each vport
438 * associated with @phba by 1. This routine also sets @phba num_rsrc_err and
439 * num_cmd_success to zero.
442 lpfc_ramp_up_queue_handler(struct lpfc_hba
*phba
)
444 struct lpfc_vport
**vports
;
445 struct Scsi_Host
*shost
;
446 struct scsi_device
*sdev
;
449 vports
= lpfc_create_vport_work_array(phba
);
451 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
452 shost
= lpfc_shost_from_vport(vports
[i
]);
453 shost_for_each_device(sdev
, shost
) {
454 if (vports
[i
]->cfg_lun_queue_depth
<=
457 lpfc_change_queue_depth(sdev
,
459 SCSI_QDEPTH_RAMP_UP
);
462 lpfc_destroy_vport_work_array(phba
, vports
);
463 atomic_set(&phba
->num_rsrc_err
, 0);
464 atomic_set(&phba
->num_cmd_success
, 0);
468 * lpfc_scsi_dev_block - set all scsi hosts to block state
469 * @phba: Pointer to HBA context object.
471 * This function walks vport list and set each SCSI host to block state
472 * by invoking fc_remote_port_delete() routine. This function is invoked
473 * with EEH when device's PCI slot has been permanently disabled.
476 lpfc_scsi_dev_block(struct lpfc_hba
*phba
)
478 struct lpfc_vport
**vports
;
479 struct Scsi_Host
*shost
;
480 struct scsi_device
*sdev
;
481 struct fc_rport
*rport
;
484 vports
= lpfc_create_vport_work_array(phba
);
486 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
487 shost
= lpfc_shost_from_vport(vports
[i
]);
488 shost_for_each_device(sdev
, shost
) {
489 rport
= starget_to_rport(scsi_target(sdev
));
490 fc_remote_port_delete(rport
);
493 lpfc_destroy_vport_work_array(phba
, vports
);
497 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
498 * @vport: The virtual port for which this call being executed.
499 * @num_to_allocate: The requested number of buffers to allocate.
501 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
502 * the scsi buffer contains all the necessary information needed to initiate
503 * a SCSI I/O. The non-DMAable buffer region contains information to build
504 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
505 * and the initial BPL. In addition to allocating memory, the FCP CMND and
506 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
509 * int - number of scsi buffers that were allocated.
510 * 0 = failure, less than num_to_alloc is a partial failure.
513 lpfc_new_scsi_buf_s3(struct lpfc_vport
*vport
, int num_to_alloc
)
515 struct lpfc_hba
*phba
= vport
->phba
;
516 struct lpfc_scsi_buf
*psb
;
517 struct ulp_bde64
*bpl
;
519 dma_addr_t pdma_phys_fcp_cmd
;
520 dma_addr_t pdma_phys_fcp_rsp
;
521 dma_addr_t pdma_phys_bpl
;
525 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
526 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
531 * Get memory from the pci pool to map the virt space to pci
532 * bus space for an I/O. The DMA buffer includes space for the
533 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
534 * necessary to support the sg_tablesize.
536 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
537 GFP_KERNEL
, &psb
->dma_handle
);
543 /* Initialize virtual ptrs to dma_buf region. */
544 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
546 /* Allocate iotag for psb->cur_iocbq. */
547 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
549 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
550 psb
->data
, psb
->dma_handle
);
554 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
556 psb
->fcp_cmnd
= psb
->data
;
557 psb
->fcp_rsp
= psb
->data
+ sizeof(struct fcp_cmnd
);
558 psb
->fcp_bpl
= psb
->data
+ sizeof(struct fcp_cmnd
) +
559 sizeof(struct fcp_rsp
);
561 /* Initialize local short-hand pointers. */
563 pdma_phys_fcp_cmd
= psb
->dma_handle
;
564 pdma_phys_fcp_rsp
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
);
565 pdma_phys_bpl
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
) +
566 sizeof(struct fcp_rsp
);
569 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
570 * are sg list bdes. Initialize the first two and leave the
571 * rest for queuecommand.
573 bpl
[0].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd
));
574 bpl
[0].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd
));
575 bpl
[0].tus
.f
.bdeSize
= sizeof(struct fcp_cmnd
);
576 bpl
[0].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
577 bpl
[0].tus
.w
= le32_to_cpu(bpl
[0].tus
.w
);
579 /* Setup the physical region for the FCP RSP */
580 bpl
[1].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp
));
581 bpl
[1].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp
));
582 bpl
[1].tus
.f
.bdeSize
= sizeof(struct fcp_rsp
);
583 bpl
[1].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
584 bpl
[1].tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
587 * Since the IOCB for the FCP I/O is built into this
588 * lpfc_scsi_buf, initialize it with all known data now.
590 iocb
= &psb
->cur_iocbq
.iocb
;
591 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
592 if ((phba
->sli_rev
== 3) &&
593 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)) {
594 /* fill in immediate fcp command BDE */
595 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_IMMED
;
596 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
597 iocb
->un
.fcpi64
.bdl
.addrLow
= offsetof(IOCB_t
,
599 iocb
->un
.fcpi64
.bdl
.addrHigh
= 0;
600 iocb
->ulpBdeCount
= 0;
602 /* fill in response BDE */
603 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeFlags
=
605 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeSize
=
606 sizeof(struct fcp_rsp
);
607 iocb
->unsli3
.fcp_ext
.rbde
.addrLow
=
608 putPaddrLow(pdma_phys_fcp_rsp
);
609 iocb
->unsli3
.fcp_ext
.rbde
.addrHigh
=
610 putPaddrHigh(pdma_phys_fcp_rsp
);
612 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
613 iocb
->un
.fcpi64
.bdl
.bdeSize
=
614 (2 * sizeof(struct ulp_bde64
));
615 iocb
->un
.fcpi64
.bdl
.addrLow
=
616 putPaddrLow(pdma_phys_bpl
);
617 iocb
->un
.fcpi64
.bdl
.addrHigh
=
618 putPaddrHigh(pdma_phys_bpl
);
619 iocb
->ulpBdeCount
= 1;
622 iocb
->ulpClass
= CLASS3
;
623 psb
->status
= IOSTAT_SUCCESS
;
624 /* Put it back into the SCSI buffer list */
625 psb
->cur_iocbq
.context1
= psb
;
626 lpfc_release_scsi_buf_s3(phba
, psb
);
634 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
635 * @vport: pointer to lpfc vport data structure.
637 * This routine is invoked by the vport cleanup for deletions and the cleanup
638 * for an ndlp on removal.
641 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport
*vport
)
643 struct lpfc_hba
*phba
= vport
->phba
;
644 struct lpfc_scsi_buf
*psb
, *next_psb
;
645 unsigned long iflag
= 0;
647 spin_lock_irqsave(&phba
->hbalock
, iflag
);
648 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
649 list_for_each_entry_safe(psb
, next_psb
,
650 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
651 if (psb
->rdata
&& psb
->rdata
->pnode
652 && psb
->rdata
->pnode
->vport
== vport
)
655 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
656 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
660 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
661 * @phba: pointer to lpfc hba data structure.
662 * @axri: pointer to the fcp xri abort wcqe structure.
664 * This routine is invoked by the worker thread to process a SLI4 fast-path
668 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba
*phba
,
669 struct sli4_wcqe_xri_aborted
*axri
)
671 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
672 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
673 struct lpfc_scsi_buf
*psb
, *next_psb
;
674 unsigned long iflag
= 0;
675 struct lpfc_iocbq
*iocbq
;
677 struct lpfc_nodelist
*ndlp
;
679 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
681 spin_lock_irqsave(&phba
->hbalock
, iflag
);
682 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
683 list_for_each_entry_safe(psb
, next_psb
,
684 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
685 if (psb
->cur_iocbq
.sli4_xritag
== xri
) {
686 list_del(&psb
->list
);
688 psb
->status
= IOSTAT_SUCCESS
;
690 &phba
->sli4_hba
.abts_scsi_buf_list_lock
);
691 if (psb
->rdata
&& psb
->rdata
->pnode
)
692 ndlp
= psb
->rdata
->pnode
;
696 rrq_empty
= list_empty(&phba
->active_rrq_list
);
697 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
699 lpfc_set_rrq_active(phba
, ndlp
,
700 psb
->cur_iocbq
.sli4_lxritag
, rxid
, 1);
701 lpfc_sli4_abts_err_handler(phba
, ndlp
, axri
);
703 lpfc_release_scsi_buf_s4(phba
, psb
);
705 lpfc_worker_wake_up(phba
);
709 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
710 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
711 iocbq
= phba
->sli
.iocbq_lookup
[i
];
713 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
) ||
714 (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
716 if (iocbq
->sli4_xritag
!= xri
)
718 psb
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
720 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
722 lpfc_worker_wake_up(phba
);
726 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
730 * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list
731 * @phba: pointer to lpfc hba data structure.
732 * @post_sblist: pointer to the scsi buffer list.
734 * This routine walks a list of scsi buffers that was passed in. It attempts
735 * to construct blocks of scsi buffer sgls which contains contiguous xris and
736 * uses the non-embedded SGL block post mailbox commands to post to the port.
737 * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use
738 * embedded SGL post mailbox command for posting. The @post_sblist passed in
739 * must be local list, thus no lock is needed when manipulate the list.
741 * Returns: 0 = failure, non-zero number of successfully posted buffers.
744 lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba
*phba
,
745 struct list_head
*post_sblist
, int sb_count
)
747 struct lpfc_scsi_buf
*psb
, *psb_next
;
749 int post_cnt
= 0, block_cnt
= 0, num_posting
= 0, num_posted
= 0;
750 dma_addr_t pdma_phys_bpl1
;
751 int last_xritag
= NO_XRI
;
752 LIST_HEAD(prep_sblist
);
753 LIST_HEAD(blck_sblist
);
754 LIST_HEAD(scsi_sblist
);
760 list_for_each_entry_safe(psb
, psb_next
, post_sblist
, list
) {
761 list_del_init(&psb
->list
);
763 if ((last_xritag
!= NO_XRI
) &&
764 (psb
->cur_iocbq
.sli4_xritag
!= last_xritag
+ 1)) {
765 /* a hole in xri block, form a sgl posting block */
766 list_splice_init(&prep_sblist
, &blck_sblist
);
767 post_cnt
= block_cnt
- 1;
768 /* prepare list for next posting block */
769 list_add_tail(&psb
->list
, &prep_sblist
);
772 /* prepare list for next posting block */
773 list_add_tail(&psb
->list
, &prep_sblist
);
774 /* enough sgls for non-embed sgl mbox command */
775 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
776 list_splice_init(&prep_sblist
, &blck_sblist
);
777 post_cnt
= block_cnt
;
782 last_xritag
= psb
->cur_iocbq
.sli4_xritag
;
784 /* end of repost sgl list condition for SCSI buffers */
785 if (num_posting
== sb_count
) {
787 /* last sgl posting block */
788 list_splice_init(&prep_sblist
, &blck_sblist
);
789 post_cnt
= block_cnt
;
790 } else if (block_cnt
== 1) {
791 /* last single sgl with non-contiguous xri */
792 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
793 pdma_phys_bpl1
= psb
->dma_phys_bpl
+
797 status
= lpfc_sli4_post_sgl(phba
,
800 psb
->cur_iocbq
.sli4_xritag
);
802 /* failure, put on abort scsi list */
805 /* success, put on SCSI buffer list */
807 psb
->status
= IOSTAT_SUCCESS
;
810 /* success, put on SCSI buffer sgl list */
811 list_add_tail(&psb
->list
, &scsi_sblist
);
815 /* continue until a nembed page worth of sgls */
819 /* post block of SCSI buffer list sgls */
820 status
= lpfc_sli4_post_scsi_sgl_block(phba
, &blck_sblist
,
823 /* don't reset xirtag due to hole in xri block */
825 last_xritag
= NO_XRI
;
827 /* reset SCSI buffer post count for next round of posting */
830 /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */
831 while (!list_empty(&blck_sblist
)) {
832 list_remove_head(&blck_sblist
, psb
,
833 struct lpfc_scsi_buf
, list
);
835 /* failure, put on abort scsi list */
838 /* success, put on SCSI buffer list */
840 psb
->status
= IOSTAT_SUCCESS
;
843 list_add_tail(&psb
->list
, &scsi_sblist
);
846 /* Push SCSI buffers with sgl posted to the availble list */
847 while (!list_empty(&scsi_sblist
)) {
848 list_remove_head(&scsi_sblist
, psb
,
849 struct lpfc_scsi_buf
, list
);
850 lpfc_release_scsi_buf_s4(phba
, psb
);
856 * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls
857 * @phba: pointer to lpfc hba data structure.
859 * This routine walks the list of scsi buffers that have been allocated and
860 * repost them to the port by using SGL block post. This is needed after a
861 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
862 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
863 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
865 * Returns: 0 = success, non-zero failure.
868 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba
*phba
)
870 LIST_HEAD(post_sblist
);
871 int num_posted
, rc
= 0;
873 /* get all SCSI buffers need to repost to a local list */
874 spin_lock(&phba
->scsi_buf_list_lock
);
875 list_splice_init(&phba
->lpfc_scsi_buf_list
, &post_sblist
);
876 spin_unlock(&phba
->scsi_buf_list_lock
);
878 /* post the list of scsi buffer sgls to port if available */
879 if (!list_empty(&post_sblist
)) {
880 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
, &post_sblist
,
881 phba
->sli4_hba
.scsi_xri_cnt
);
882 /* failed to post any scsi buffer, return error */
890 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
891 * @vport: The virtual port for which this call being executed.
892 * @num_to_allocate: The requested number of buffers to allocate.
894 * This routine allocates scsi buffers for device with SLI-4 interface spec,
895 * the scsi buffer contains all the necessary information needed to initiate
896 * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put
897 * them on a list, it post them to the port by using SGL block post.
900 * int - number of scsi buffers that were allocated and posted.
901 * 0 = failure, less than num_to_alloc is a partial failure.
904 lpfc_new_scsi_buf_s4(struct lpfc_vport
*vport
, int num_to_alloc
)
906 struct lpfc_hba
*phba
= vport
->phba
;
907 struct lpfc_scsi_buf
*psb
;
908 struct sli4_sge
*sgl
;
910 dma_addr_t pdma_phys_fcp_cmd
;
911 dma_addr_t pdma_phys_fcp_rsp
;
912 dma_addr_t pdma_phys_bpl
, pdma_phys_bpl1
;
913 uint16_t iotag
, lxri
= 0;
914 int bcnt
, num_posted
;
915 LIST_HEAD(prep_sblist
);
916 LIST_HEAD(post_sblist
);
917 LIST_HEAD(scsi_sblist
);
919 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
920 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
924 * Get memory from the pci pool to map the virt space to
925 * pci bus space for an I/O. The DMA buffer includes space
926 * for the struct fcp_cmnd, struct fcp_rsp and the number
927 * of bde's necessary to support the sg_tablesize.
929 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
930 GFP_KERNEL
, &psb
->dma_handle
);
935 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
937 /* Allocate iotag for psb->cur_iocbq. */
938 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
940 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
941 psb
->data
, psb
->dma_handle
);
946 lxri
= lpfc_sli4_next_xritag(phba
);
947 if (lxri
== NO_XRI
) {
948 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
949 psb
->data
, psb
->dma_handle
);
953 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
954 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
955 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
956 psb
->fcp_bpl
= psb
->data
;
957 psb
->fcp_cmnd
= (psb
->data
+ phba
->cfg_sg_dma_buf_size
)
958 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
959 psb
->fcp_rsp
= (struct fcp_rsp
*)((uint8_t *)psb
->fcp_cmnd
+
960 sizeof(struct fcp_cmnd
));
962 /* Initialize local short-hand pointers. */
963 sgl
= (struct sli4_sge
*)psb
->fcp_bpl
;
964 pdma_phys_bpl
= psb
->dma_handle
;
966 (psb
->dma_handle
+ phba
->cfg_sg_dma_buf_size
)
967 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
968 pdma_phys_fcp_rsp
= pdma_phys_fcp_cmd
+ sizeof(struct fcp_cmnd
);
971 * The first two bdes are the FCP_CMD and FCP_RSP.
972 * The balance are sg list bdes. Initialize the
973 * first two and leave the rest for queuecommand.
975 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd
));
976 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd
));
977 sgl
->word2
= le32_to_cpu(sgl
->word2
);
978 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
979 sgl
->word2
= cpu_to_le32(sgl
->word2
);
980 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_cmnd
));
983 /* Setup the physical region for the FCP RSP */
984 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp
));
985 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp
));
986 sgl
->word2
= le32_to_cpu(sgl
->word2
);
987 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
988 sgl
->word2
= cpu_to_le32(sgl
->word2
);
989 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_rsp
));
992 * Since the IOCB for the FCP I/O is built into this
993 * lpfc_scsi_buf, initialize it with all known data now.
995 iocb
= &psb
->cur_iocbq
.iocb
;
996 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
997 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
998 /* setting the BLP size to 2 * sizeof BDE may not be correct.
999 * We are setting the bpl to point to out sgl. An sgl's
1000 * entries are 16 bytes, a bpl entries are 12 bytes.
1002 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
1003 iocb
->un
.fcpi64
.bdl
.addrLow
= putPaddrLow(pdma_phys_fcp_cmd
);
1004 iocb
->un
.fcpi64
.bdl
.addrHigh
= putPaddrHigh(pdma_phys_fcp_cmd
);
1005 iocb
->ulpBdeCount
= 1;
1007 iocb
->ulpClass
= CLASS3
;
1008 psb
->cur_iocbq
.context1
= psb
;
1009 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
1010 pdma_phys_bpl1
= pdma_phys_bpl
+ SGL_PAGE_SIZE
;
1013 psb
->dma_phys_bpl
= pdma_phys_bpl
;
1015 /* add the scsi buffer to a post list */
1016 list_add_tail(&psb
->list
, &post_sblist
);
1017 spin_lock_irq(&phba
->scsi_buf_list_lock
);
1018 phba
->sli4_hba
.scsi_xri_cnt
++;
1019 spin_unlock_irq(&phba
->scsi_buf_list_lock
);
1021 lpfc_printf_log(phba
, KERN_INFO
, LOG_BG
,
1022 "3021 Allocate %d out of %d requested new SCSI "
1023 "buffers\n", bcnt
, num_to_alloc
);
1025 /* post the list of scsi buffer sgls to port if available */
1026 if (!list_empty(&post_sblist
))
1027 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
,
1028 &post_sblist
, bcnt
);
1036 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
1037 * @vport: The virtual port for which this call being executed.
1038 * @num_to_allocate: The requested number of buffers to allocate.
1040 * This routine wraps the actual SCSI buffer allocator function pointer from
1041 * the lpfc_hba struct.
1044 * int - number of scsi buffers that were allocated.
1045 * 0 = failure, less than num_to_alloc is a partial failure.
1048 lpfc_new_scsi_buf(struct lpfc_vport
*vport
, int num_to_alloc
)
1050 return vport
->phba
->lpfc_new_scsi_buf(vport
, num_to_alloc
);
1054 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1055 * @phba: The HBA for which this call is being executed.
1057 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1058 * and returns to caller.
1062 * Pointer to lpfc_scsi_buf - Success
1064 static struct lpfc_scsi_buf
*
1065 lpfc_get_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1067 struct lpfc_scsi_buf
* lpfc_cmd
= NULL
;
1068 struct list_head
*scsi_buf_list
= &phba
->lpfc_scsi_buf_list
;
1069 unsigned long iflag
= 0;
1071 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1072 list_remove_head(scsi_buf_list
, lpfc_cmd
, struct lpfc_scsi_buf
, list
);
1074 lpfc_cmd
->seg_cnt
= 0;
1075 lpfc_cmd
->nonsg_phys
= 0;
1076 lpfc_cmd
->prot_seg_cnt
= 0;
1078 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1082 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1083 * @phba: The HBA for which this call is being executed.
1085 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1086 * and returns to caller.
1090 * Pointer to lpfc_scsi_buf - Success
1092 static struct lpfc_scsi_buf
*
1093 lpfc_get_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1095 struct lpfc_scsi_buf
*lpfc_cmd
;
1096 unsigned long iflag
= 0;
1099 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1100 list_for_each_entry(lpfc_cmd
, &phba
->lpfc_scsi_buf_list
,
1102 if (lpfc_test_rrq_active(phba
, ndlp
,
1103 lpfc_cmd
->cur_iocbq
.sli4_lxritag
))
1105 list_del(&lpfc_cmd
->list
);
1107 lpfc_cmd
->seg_cnt
= 0;
1108 lpfc_cmd
->nonsg_phys
= 0;
1109 lpfc_cmd
->prot_seg_cnt
= 0;
1112 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
,
1120 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1121 * @phba: The HBA for which this call is being executed.
1123 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1124 * and returns to caller.
1128 * Pointer to lpfc_scsi_buf - Success
1130 static struct lpfc_scsi_buf
*
1131 lpfc_get_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1133 return phba
->lpfc_get_scsi_buf(phba
, ndlp
);
1137 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
1138 * @phba: The Hba for which this call is being executed.
1139 * @psb: The scsi buffer which is being released.
1141 * This routine releases @psb scsi buffer by adding it to tail of @phba
1142 * lpfc_scsi_buf_list list.
1145 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1147 unsigned long iflag
= 0;
1149 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1151 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
1152 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1156 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
1157 * @phba: The Hba for which this call is being executed.
1158 * @psb: The scsi buffer which is being released.
1160 * This routine releases @psb scsi buffer by adding it to tail of @phba
1161 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
1162 * and cannot be reused for at least RA_TOV amount of time if it was
1166 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1168 unsigned long iflag
= 0;
1170 if (psb
->exch_busy
) {
1171 spin_lock_irqsave(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1174 list_add_tail(&psb
->list
,
1175 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
1176 spin_unlock_irqrestore(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1180 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1182 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
1183 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1188 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
1189 * @phba: The Hba for which this call is being executed.
1190 * @psb: The scsi buffer which is being released.
1192 * This routine releases @psb scsi buffer by adding it to tail of @phba
1193 * lpfc_scsi_buf_list list.
1196 lpfc_release_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1199 phba
->lpfc_release_scsi_buf(phba
, psb
);
1203 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
1204 * @phba: The Hba for which this call is being executed.
1205 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1207 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1208 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1209 * through sg elements and format the bdea. This routine also initializes all
1210 * IOCB fields which are dependent on scsi command request buffer.
1217 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
1219 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
1220 struct scatterlist
*sgel
= NULL
;
1221 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
1222 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
1223 struct lpfc_iocbq
*iocbq
= &lpfc_cmd
->cur_iocbq
;
1224 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
1225 struct ulp_bde64
*data_bde
= iocb_cmd
->unsli3
.fcp_ext
.dbde
;
1226 dma_addr_t physaddr
;
1227 uint32_t num_bde
= 0;
1228 int nseg
, datadir
= scsi_cmnd
->sc_data_direction
;
1231 * There are three possibilities here - use scatter-gather segment, use
1232 * the single mapping, or neither. Start the lpfc command prep by
1233 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1237 if (scsi_sg_count(scsi_cmnd
)) {
1239 * The driver stores the segment count returned from pci_map_sg
1240 * because this a count of dma-mappings used to map the use_sg
1241 * pages. They are not guaranteed to be the same for those
1242 * architectures that implement an IOMMU.
1245 nseg
= dma_map_sg(&phba
->pcidev
->dev
, scsi_sglist(scsi_cmnd
),
1246 scsi_sg_count(scsi_cmnd
), datadir
);
1247 if (unlikely(!nseg
))
1250 lpfc_cmd
->seg_cnt
= nseg
;
1251 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
1252 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1253 "9064 BLKGRD: %s: Too many sg segments from "
1254 "dma_map_sg. Config %d, seg_cnt %d\n",
1255 __func__
, phba
->cfg_sg_seg_cnt
,
1257 scsi_dma_unmap(scsi_cmnd
);
1262 * The driver established a maximum scatter-gather segment count
1263 * during probe that limits the number of sg elements in any
1264 * single scsi command. Just run through the seg_cnt and format
1266 * When using SLI-3 the driver will try to fit all the BDEs into
1267 * the IOCB. If it can't then the BDEs get added to a BPL as it
1268 * does for SLI-2 mode.
1270 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
1271 physaddr
= sg_dma_address(sgel
);
1272 if (phba
->sli_rev
== 3 &&
1273 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1274 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
) &&
1275 nseg
<= LPFC_EXT_DATA_BDE_COUNT
) {
1276 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1277 data_bde
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1278 data_bde
->addrLow
= putPaddrLow(physaddr
);
1279 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1282 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1283 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1284 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1286 le32_to_cpu(putPaddrLow(physaddr
));
1288 le32_to_cpu(putPaddrHigh(physaddr
));
1295 * Finish initializing those IOCB fields that are dependent on the
1296 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1297 * explicitly reinitialized and for SLI-3 the extended bde count is
1298 * explicitly reinitialized since all iocb memory resources are reused.
1300 if (phba
->sli_rev
== 3 &&
1301 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1302 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
)) {
1303 if (num_bde
> LPFC_EXT_DATA_BDE_COUNT
) {
1305 * The extended IOCB format can only fit 3 BDE or a BPL.
1306 * This I/O has more than 3 BDE so the 1st data bde will
1307 * be a BPL that is filled in here.
1309 physaddr
= lpfc_cmd
->dma_handle
;
1310 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BLP_64
;
1311 data_bde
->tus
.f
.bdeSize
= (num_bde
*
1312 sizeof(struct ulp_bde64
));
1313 physaddr
+= (sizeof(struct fcp_cmnd
) +
1314 sizeof(struct fcp_rsp
) +
1315 (2 * sizeof(struct ulp_bde64
)));
1316 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1317 data_bde
->addrLow
= putPaddrLow(physaddr
);
1318 /* ebde count includes the response bde and data bpl */
1319 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= 2;
1321 /* ebde count includes the response bde and data bdes */
1322 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1325 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
=
1326 ((num_bde
+ 2) * sizeof(struct ulp_bde64
));
1327 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1329 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
1332 * Due to difference in data length between DIF/non-DIF paths,
1333 * we need to set word 4 of IOCB here
1335 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
1339 static inline unsigned
1340 lpfc_cmd_blksize(struct scsi_cmnd
*sc
)
1342 return sc
->device
->sector_size
;
1345 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1347 /* Return if if error injection is detected by Initiator */
1348 #define BG_ERR_INIT 0x1
1349 /* Return if if error injection is detected by Target */
1350 #define BG_ERR_TGT 0x2
1351 /* Return if if swapping CSUM<-->CRC is required for error injection */
1352 #define BG_ERR_SWAP 0x10
1353 /* Return if disabling Guard/Ref/App checking is required for error injection */
1354 #define BG_ERR_CHECK 0x20
1357 * lpfc_bg_err_inject - Determine if we should inject an error
1358 * @phba: The Hba for which this call is being executed.
1359 * @sc: The SCSI command to examine
1360 * @reftag: (out) BlockGuard reference tag for transmitted data
1361 * @apptag: (out) BlockGuard application tag for transmitted data
1362 * @new_guard (in) Value to replace CRC with if needed
1364 * Returns BG_ERR_* bit mask or 0 if request ignored
1367 lpfc_bg_err_inject(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1368 uint32_t *reftag
, uint16_t *apptag
, uint32_t new_guard
)
1370 struct scatterlist
*sgpe
; /* s/g prot entry */
1371 struct scatterlist
*sgde
; /* s/g data entry */
1372 struct lpfc_scsi_buf
*lpfc_cmd
= NULL
;
1373 struct scsi_dif_tuple
*src
= NULL
;
1374 struct lpfc_nodelist
*ndlp
;
1375 struct lpfc_rport_data
*rdata
;
1376 uint32_t op
= scsi_get_prot_op(sc
);
1383 if (op
== SCSI_PROT_NORMAL
)
1386 sgpe
= scsi_prot_sglist(sc
);
1387 sgde
= scsi_sglist(sc
);
1388 lba
= scsi_get_lba(sc
);
1390 /* First check if we need to match the LBA */
1391 if (phba
->lpfc_injerr_lba
!= LPFC_INJERR_LBA_OFF
) {
1392 blksize
= lpfc_cmd_blksize(sc
);
1393 numblks
= (scsi_bufflen(sc
) + blksize
- 1) / blksize
;
1395 /* Make sure we have the right LBA if one is specified */
1396 if ((phba
->lpfc_injerr_lba
< lba
) ||
1397 (phba
->lpfc_injerr_lba
>= (lba
+ numblks
)))
1400 blockoff
= phba
->lpfc_injerr_lba
- lba
;
1401 numblks
= sg_dma_len(sgpe
) /
1402 sizeof(struct scsi_dif_tuple
);
1403 if (numblks
< blockoff
)
1408 /* Next check if we need to match the remote NPortID or WWPN */
1409 rdata
= sc
->device
->hostdata
;
1410 if (rdata
&& rdata
->pnode
) {
1411 ndlp
= rdata
->pnode
;
1413 /* Make sure we have the right NPortID if one is specified */
1414 if (phba
->lpfc_injerr_nportid
&&
1415 (phba
->lpfc_injerr_nportid
!= ndlp
->nlp_DID
))
1419 * Make sure we have the right WWPN if one is specified.
1420 * wwn[0] should be a non-zero NAA in a good WWPN.
1422 if (phba
->lpfc_injerr_wwpn
.u
.wwn
[0] &&
1423 (memcmp(&ndlp
->nlp_portname
, &phba
->lpfc_injerr_wwpn
,
1424 sizeof(struct lpfc_name
)) != 0))
1428 /* Setup a ptr to the protection data if the SCSI host provides it */
1430 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
1432 lpfc_cmd
= (struct lpfc_scsi_buf
*)sc
->host_scribble
;
1435 /* Should we change the Reference Tag */
1437 if (phba
->lpfc_injerr_wref_cnt
) {
1439 case SCSI_PROT_WRITE_PASS
:
1442 * For WRITE_PASS, force the error
1443 * to be sent on the wire. It should
1444 * be detected by the Target.
1445 * If blockoff != 0 error will be
1446 * inserted in middle of the IO.
1449 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1450 "9076 BLKGRD: Injecting reftag error: "
1451 "write lba x%lx + x%x oldrefTag x%x\n",
1452 (unsigned long)lba
, blockoff
,
1453 be32_to_cpu(src
->ref_tag
));
1456 * Save the old ref_tag so we can
1457 * restore it on completion.
1460 lpfc_cmd
->prot_data_type
=
1462 lpfc_cmd
->prot_data_segment
=
1464 lpfc_cmd
->prot_data
=
1467 src
->ref_tag
= cpu_to_be32(0xDEADBEEF);
1468 phba
->lpfc_injerr_wref_cnt
--;
1469 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1470 phba
->lpfc_injerr_nportid
= 0;
1471 phba
->lpfc_injerr_lba
=
1472 LPFC_INJERR_LBA_OFF
;
1473 memset(&phba
->lpfc_injerr_wwpn
,
1474 0, sizeof(struct lpfc_name
));
1476 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1481 case SCSI_PROT_WRITE_INSERT
:
1483 * For WRITE_INSERT, force the error
1484 * to be sent on the wire. It should be
1485 * detected by the Target.
1487 /* DEADBEEF will be the reftag on the wire */
1488 *reftag
= 0xDEADBEEF;
1489 phba
->lpfc_injerr_wref_cnt
--;
1490 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1491 phba
->lpfc_injerr_nportid
= 0;
1492 phba
->lpfc_injerr_lba
=
1493 LPFC_INJERR_LBA_OFF
;
1494 memset(&phba
->lpfc_injerr_wwpn
,
1495 0, sizeof(struct lpfc_name
));
1497 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1499 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1500 "9078 BLKGRD: Injecting reftag error: "
1501 "write lba x%lx\n", (unsigned long)lba
);
1503 case SCSI_PROT_WRITE_STRIP
:
1505 * For WRITE_STRIP and WRITE_PASS,
1506 * force the error on data
1507 * being copied from SLI-Host to SLI-Port.
1509 *reftag
= 0xDEADBEEF;
1510 phba
->lpfc_injerr_wref_cnt
--;
1511 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1512 phba
->lpfc_injerr_nportid
= 0;
1513 phba
->lpfc_injerr_lba
=
1514 LPFC_INJERR_LBA_OFF
;
1515 memset(&phba
->lpfc_injerr_wwpn
,
1516 0, sizeof(struct lpfc_name
));
1520 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1521 "9077 BLKGRD: Injecting reftag error: "
1522 "write lba x%lx\n", (unsigned long)lba
);
1526 if (phba
->lpfc_injerr_rref_cnt
) {
1528 case SCSI_PROT_READ_INSERT
:
1529 case SCSI_PROT_READ_STRIP
:
1530 case SCSI_PROT_READ_PASS
:
1532 * For READ_STRIP and READ_PASS, force the
1533 * error on data being read off the wire. It
1534 * should force an IO error to the driver.
1536 *reftag
= 0xDEADBEEF;
1537 phba
->lpfc_injerr_rref_cnt
--;
1538 if (phba
->lpfc_injerr_rref_cnt
== 0) {
1539 phba
->lpfc_injerr_nportid
= 0;
1540 phba
->lpfc_injerr_lba
=
1541 LPFC_INJERR_LBA_OFF
;
1542 memset(&phba
->lpfc_injerr_wwpn
,
1543 0, sizeof(struct lpfc_name
));
1547 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1548 "9079 BLKGRD: Injecting reftag error: "
1549 "read lba x%lx\n", (unsigned long)lba
);
1555 /* Should we change the Application Tag */
1557 if (phba
->lpfc_injerr_wapp_cnt
) {
1559 case SCSI_PROT_WRITE_PASS
:
1562 * For WRITE_PASS, force the error
1563 * to be sent on the wire. It should
1564 * be detected by the Target.
1565 * If blockoff != 0 error will be
1566 * inserted in middle of the IO.
1569 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1570 "9080 BLKGRD: Injecting apptag error: "
1571 "write lba x%lx + x%x oldappTag x%x\n",
1572 (unsigned long)lba
, blockoff
,
1573 be16_to_cpu(src
->app_tag
));
1576 * Save the old app_tag so we can
1577 * restore it on completion.
1580 lpfc_cmd
->prot_data_type
=
1582 lpfc_cmd
->prot_data_segment
=
1584 lpfc_cmd
->prot_data
=
1587 src
->app_tag
= cpu_to_be16(0xDEAD);
1588 phba
->lpfc_injerr_wapp_cnt
--;
1589 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1590 phba
->lpfc_injerr_nportid
= 0;
1591 phba
->lpfc_injerr_lba
=
1592 LPFC_INJERR_LBA_OFF
;
1593 memset(&phba
->lpfc_injerr_wwpn
,
1594 0, sizeof(struct lpfc_name
));
1596 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1600 case SCSI_PROT_WRITE_INSERT
:
1602 * For WRITE_INSERT, force the
1603 * error to be sent on the wire. It should be
1604 * detected by the Target.
1606 /* DEAD will be the apptag on the wire */
1608 phba
->lpfc_injerr_wapp_cnt
--;
1609 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1610 phba
->lpfc_injerr_nportid
= 0;
1611 phba
->lpfc_injerr_lba
=
1612 LPFC_INJERR_LBA_OFF
;
1613 memset(&phba
->lpfc_injerr_wwpn
,
1614 0, sizeof(struct lpfc_name
));
1616 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1618 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1619 "0813 BLKGRD: Injecting apptag error: "
1620 "write lba x%lx\n", (unsigned long)lba
);
1622 case SCSI_PROT_WRITE_STRIP
:
1624 * For WRITE_STRIP and WRITE_PASS,
1625 * force the error on data
1626 * being copied from SLI-Host to SLI-Port.
1629 phba
->lpfc_injerr_wapp_cnt
--;
1630 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1631 phba
->lpfc_injerr_nportid
= 0;
1632 phba
->lpfc_injerr_lba
=
1633 LPFC_INJERR_LBA_OFF
;
1634 memset(&phba
->lpfc_injerr_wwpn
,
1635 0, sizeof(struct lpfc_name
));
1639 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1640 "0812 BLKGRD: Injecting apptag error: "
1641 "write lba x%lx\n", (unsigned long)lba
);
1645 if (phba
->lpfc_injerr_rapp_cnt
) {
1647 case SCSI_PROT_READ_INSERT
:
1648 case SCSI_PROT_READ_STRIP
:
1649 case SCSI_PROT_READ_PASS
:
1651 * For READ_STRIP and READ_PASS, force the
1652 * error on data being read off the wire. It
1653 * should force an IO error to the driver.
1656 phba
->lpfc_injerr_rapp_cnt
--;
1657 if (phba
->lpfc_injerr_rapp_cnt
== 0) {
1658 phba
->lpfc_injerr_nportid
= 0;
1659 phba
->lpfc_injerr_lba
=
1660 LPFC_INJERR_LBA_OFF
;
1661 memset(&phba
->lpfc_injerr_wwpn
,
1662 0, sizeof(struct lpfc_name
));
1666 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1667 "0814 BLKGRD: Injecting apptag error: "
1668 "read lba x%lx\n", (unsigned long)lba
);
1675 /* Should we change the Guard Tag */
1677 if (phba
->lpfc_injerr_wgrd_cnt
) {
1679 case SCSI_PROT_WRITE_PASS
:
1683 case SCSI_PROT_WRITE_INSERT
:
1685 * For WRITE_INSERT, force the
1686 * error to be sent on the wire. It should be
1687 * detected by the Target.
1689 phba
->lpfc_injerr_wgrd_cnt
--;
1690 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1691 phba
->lpfc_injerr_nportid
= 0;
1692 phba
->lpfc_injerr_lba
=
1693 LPFC_INJERR_LBA_OFF
;
1694 memset(&phba
->lpfc_injerr_wwpn
,
1695 0, sizeof(struct lpfc_name
));
1698 rc
|= BG_ERR_TGT
| BG_ERR_SWAP
;
1699 /* Signals the caller to swap CRC->CSUM */
1701 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1702 "0817 BLKGRD: Injecting guard error: "
1703 "write lba x%lx\n", (unsigned long)lba
);
1705 case SCSI_PROT_WRITE_STRIP
:
1707 * For WRITE_STRIP and WRITE_PASS,
1708 * force the error on data
1709 * being copied from SLI-Host to SLI-Port.
1711 phba
->lpfc_injerr_wgrd_cnt
--;
1712 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1713 phba
->lpfc_injerr_nportid
= 0;
1714 phba
->lpfc_injerr_lba
=
1715 LPFC_INJERR_LBA_OFF
;
1716 memset(&phba
->lpfc_injerr_wwpn
,
1717 0, sizeof(struct lpfc_name
));
1720 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1721 /* Signals the caller to swap CRC->CSUM */
1723 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1724 "0816 BLKGRD: Injecting guard error: "
1725 "write lba x%lx\n", (unsigned long)lba
);
1729 if (phba
->lpfc_injerr_rgrd_cnt
) {
1731 case SCSI_PROT_READ_INSERT
:
1732 case SCSI_PROT_READ_STRIP
:
1733 case SCSI_PROT_READ_PASS
:
1735 * For READ_STRIP and READ_PASS, force the
1736 * error on data being read off the wire. It
1737 * should force an IO error to the driver.
1739 phba
->lpfc_injerr_rgrd_cnt
--;
1740 if (phba
->lpfc_injerr_rgrd_cnt
== 0) {
1741 phba
->lpfc_injerr_nportid
= 0;
1742 phba
->lpfc_injerr_lba
=
1743 LPFC_INJERR_LBA_OFF
;
1744 memset(&phba
->lpfc_injerr_wwpn
,
1745 0, sizeof(struct lpfc_name
));
1748 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1749 /* Signals the caller to swap CRC->CSUM */
1751 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1752 "0818 BLKGRD: Injecting guard error: "
1753 "read lba x%lx\n", (unsigned long)lba
);
1763 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1764 * the specified SCSI command.
1765 * @phba: The Hba for which this call is being executed.
1766 * @sc: The SCSI command to examine
1767 * @txopt: (out) BlockGuard operation for transmitted data
1768 * @rxopt: (out) BlockGuard operation for received data
1770 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1774 lpfc_sc_to_bg_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1775 uint8_t *txop
, uint8_t *rxop
)
1777 uint8_t guard_type
= scsi_host_get_guard(sc
->device
->host
);
1780 if (guard_type
== SHOST_DIX_GUARD_IP
) {
1781 switch (scsi_get_prot_op(sc
)) {
1782 case SCSI_PROT_READ_INSERT
:
1783 case SCSI_PROT_WRITE_STRIP
:
1784 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1785 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1788 case SCSI_PROT_READ_STRIP
:
1789 case SCSI_PROT_WRITE_INSERT
:
1790 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1791 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1794 case SCSI_PROT_READ_PASS
:
1795 case SCSI_PROT_WRITE_PASS
:
1796 *rxop
= BG_OP_IN_CRC_OUT_CSUM
;
1797 *txop
= BG_OP_IN_CSUM_OUT_CRC
;
1800 case SCSI_PROT_NORMAL
:
1802 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1803 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1804 scsi_get_prot_op(sc
));
1810 switch (scsi_get_prot_op(sc
)) {
1811 case SCSI_PROT_READ_STRIP
:
1812 case SCSI_PROT_WRITE_INSERT
:
1813 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1814 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1817 case SCSI_PROT_READ_PASS
:
1818 case SCSI_PROT_WRITE_PASS
:
1819 *rxop
= BG_OP_IN_CRC_OUT_CRC
;
1820 *txop
= BG_OP_IN_CRC_OUT_CRC
;
1823 case SCSI_PROT_READ_INSERT
:
1824 case SCSI_PROT_WRITE_STRIP
:
1825 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1826 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1829 case SCSI_PROT_NORMAL
:
1831 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1832 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1833 scsi_get_prot_op(sc
));
1842 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1844 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1845 * the specified SCSI command in order to force a guard tag error.
1846 * @phba: The Hba for which this call is being executed.
1847 * @sc: The SCSI command to examine
1848 * @txopt: (out) BlockGuard operation for transmitted data
1849 * @rxopt: (out) BlockGuard operation for received data
1851 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1855 lpfc_bg_err_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1856 uint8_t *txop
, uint8_t *rxop
)
1858 uint8_t guard_type
= scsi_host_get_guard(sc
->device
->host
);
1861 if (guard_type
== SHOST_DIX_GUARD_IP
) {
1862 switch (scsi_get_prot_op(sc
)) {
1863 case SCSI_PROT_READ_INSERT
:
1864 case SCSI_PROT_WRITE_STRIP
:
1865 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1866 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1869 case SCSI_PROT_READ_STRIP
:
1870 case SCSI_PROT_WRITE_INSERT
:
1871 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1872 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1875 case SCSI_PROT_READ_PASS
:
1876 case SCSI_PROT_WRITE_PASS
:
1877 *rxop
= BG_OP_IN_CSUM_OUT_CRC
;
1878 *txop
= BG_OP_IN_CRC_OUT_CSUM
;
1881 case SCSI_PROT_NORMAL
:
1887 switch (scsi_get_prot_op(sc
)) {
1888 case SCSI_PROT_READ_STRIP
:
1889 case SCSI_PROT_WRITE_INSERT
:
1890 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1891 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1894 case SCSI_PROT_READ_PASS
:
1895 case SCSI_PROT_WRITE_PASS
:
1896 *rxop
= BG_OP_IN_CSUM_OUT_CSUM
;
1897 *txop
= BG_OP_IN_CSUM_OUT_CSUM
;
1900 case SCSI_PROT_READ_INSERT
:
1901 case SCSI_PROT_WRITE_STRIP
:
1902 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1903 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1906 case SCSI_PROT_NORMAL
:
1917 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1918 * @phba: The Hba for which this call is being executed.
1919 * @sc: pointer to scsi command we're working on
1920 * @bpl: pointer to buffer list for protection groups
1921 * @datacnt: number of segments of data that have been dma mapped
1923 * This function sets up BPL buffer list for protection groups of
1924 * type LPFC_PG_TYPE_NO_DIF
1926 * This is usually used when the HBA is instructed to generate
1927 * DIFs and insert them into data stream (or strip DIF from
1928 * incoming data stream)
1930 * The buffer list consists of just one protection group described
1932 * +-------------------------+
1933 * start of prot group --> | PDE_5 |
1934 * +-------------------------+
1936 * +-------------------------+
1938 * +-------------------------+
1939 * |more Data BDE's ... (opt)|
1940 * +-------------------------+
1943 * Note: Data s/g buffers have been dma mapped
1945 * Returns the number of BDEs added to the BPL.
1948 lpfc_bg_setup_bpl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1949 struct ulp_bde64
*bpl
, int datasegcnt
)
1951 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1952 struct lpfc_pde5
*pde5
= NULL
;
1953 struct lpfc_pde6
*pde6
= NULL
;
1954 dma_addr_t physaddr
;
1955 int i
= 0, num_bde
= 0, status
;
1956 int datadir
= sc
->sc_data_direction
;
1957 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1960 uint32_t checking
= 1;
1965 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
1969 /* extract some info from the scsi command for pde*/
1970 blksize
= lpfc_cmd_blksize(sc
);
1971 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
1973 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1974 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
1976 if (rc
& BG_ERR_SWAP
)
1977 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
1978 if (rc
& BG_ERR_CHECK
)
1983 /* setup PDE5 with what we have */
1984 pde5
= (struct lpfc_pde5
*) bpl
;
1985 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
1986 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
1988 /* Endianness conversion if necessary for PDE5 */
1989 pde5
->word0
= cpu_to_le32(pde5
->word0
);
1990 pde5
->reftag
= cpu_to_le32(reftag
);
1992 /* advance bpl and increment bde count */
1995 pde6
= (struct lpfc_pde6
*) bpl
;
1997 /* setup PDE6 with the rest of the info */
1998 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
1999 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
2000 bf_set(pde6_optx
, pde6
, txop
);
2001 bf_set(pde6_oprx
, pde6
, rxop
);
2002 if (datadir
== DMA_FROM_DEVICE
) {
2003 bf_set(pde6_ce
, pde6
, checking
);
2004 bf_set(pde6_re
, pde6
, checking
);
2006 bf_set(pde6_ai
, pde6
, 1);
2007 bf_set(pde6_ae
, pde6
, 0);
2008 bf_set(pde6_apptagval
, pde6
, 0);
2010 /* Endianness conversion if necessary for PDE6 */
2011 pde6
->word0
= cpu_to_le32(pde6
->word0
);
2012 pde6
->word1
= cpu_to_le32(pde6
->word1
);
2013 pde6
->word2
= cpu_to_le32(pde6
->word2
);
2015 /* advance bpl and increment bde count */
2019 /* assumption: caller has already run dma_map_sg on command data */
2020 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
2021 physaddr
= sg_dma_address(sgde
);
2022 bpl
->addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
2023 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
2024 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgde
);
2025 if (datadir
== DMA_TO_DEVICE
)
2026 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2028 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2029 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2039 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
2040 * @phba: The Hba for which this call is being executed.
2041 * @sc: pointer to scsi command we're working on
2042 * @bpl: pointer to buffer list for protection groups
2043 * @datacnt: number of segments of data that have been dma mapped
2044 * @protcnt: number of segment of protection data that have been dma mapped
2046 * This function sets up BPL buffer list for protection groups of
2047 * type LPFC_PG_TYPE_DIF
2049 * This is usually used when DIFs are in their own buffers,
2050 * separate from the data. The HBA can then by instructed
2051 * to place the DIFs in the outgoing stream. For read operations,
2052 * The HBA could extract the DIFs and place it in DIF buffers.
2054 * The buffer list for this type consists of one or more of the
2055 * protection groups described below:
2056 * +-------------------------+
2057 * start of first prot group --> | PDE_5 |
2058 * +-------------------------+
2060 * +-------------------------+
2061 * | PDE_7 (Prot BDE) |
2062 * +-------------------------+
2064 * +-------------------------+
2065 * |more Data BDE's ... (opt)|
2066 * +-------------------------+
2067 * start of new prot group --> | PDE_5 |
2068 * +-------------------------+
2070 * +-------------------------+
2072 * Note: It is assumed that both data and protection s/g buffers have been
2075 * Returns the number of BDEs added to the BPL.
2078 lpfc_bg_setup_bpl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2079 struct ulp_bde64
*bpl
, int datacnt
, int protcnt
)
2081 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2082 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2083 struct lpfc_pde5
*pde5
= NULL
;
2084 struct lpfc_pde6
*pde6
= NULL
;
2085 struct lpfc_pde7
*pde7
= NULL
;
2086 dma_addr_t dataphysaddr
, protphysaddr
;
2087 unsigned short curr_data
= 0, curr_prot
= 0;
2088 unsigned int split_offset
;
2089 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2090 unsigned int protgrp_blks
, protgrp_bytes
;
2091 unsigned int remainder
, subtotal
;
2093 int datadir
= sc
->sc_data_direction
;
2094 unsigned char pgdone
= 0, alldone
= 0;
2096 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2099 uint32_t checking
= 1;
2104 sgpe
= scsi_prot_sglist(sc
);
2105 sgde
= scsi_sglist(sc
);
2107 if (!sgpe
|| !sgde
) {
2108 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2109 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
2114 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2118 /* extract some info from the scsi command */
2119 blksize
= lpfc_cmd_blksize(sc
);
2120 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2122 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2123 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2125 if (rc
& BG_ERR_SWAP
)
2126 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2127 if (rc
& BG_ERR_CHECK
)
2134 /* setup PDE5 with what we have */
2135 pde5
= (struct lpfc_pde5
*) bpl
;
2136 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
2137 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
2139 /* Endianness conversion if necessary for PDE5 */
2140 pde5
->word0
= cpu_to_le32(pde5
->word0
);
2141 pde5
->reftag
= cpu_to_le32(reftag
);
2143 /* advance bpl and increment bde count */
2146 pde6
= (struct lpfc_pde6
*) bpl
;
2148 /* setup PDE6 with the rest of the info */
2149 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
2150 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
2151 bf_set(pde6_optx
, pde6
, txop
);
2152 bf_set(pde6_oprx
, pde6
, rxop
);
2153 bf_set(pde6_ce
, pde6
, checking
);
2154 bf_set(pde6_re
, pde6
, checking
);
2155 bf_set(pde6_ai
, pde6
, 1);
2156 bf_set(pde6_ae
, pde6
, 0);
2157 bf_set(pde6_apptagval
, pde6
, 0);
2159 /* Endianness conversion if necessary for PDE6 */
2160 pde6
->word0
= cpu_to_le32(pde6
->word0
);
2161 pde6
->word1
= cpu_to_le32(pde6
->word1
);
2162 pde6
->word2
= cpu_to_le32(pde6
->word2
);
2164 /* advance bpl and increment bde count */
2168 /* setup the first BDE that points to protection buffer */
2169 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2170 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2172 /* must be integer multiple of the DIF block length */
2173 BUG_ON(protgroup_len
% 8);
2175 pde7
= (struct lpfc_pde7
*) bpl
;
2176 memset(pde7
, 0, sizeof(struct lpfc_pde7
));
2177 bf_set(pde7_type
, pde7
, LPFC_PDE7_DESCRIPTOR
);
2179 pde7
->addrHigh
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2180 pde7
->addrLow
= le32_to_cpu(putPaddrLow(protphysaddr
));
2182 protgrp_blks
= protgroup_len
/ 8;
2183 protgrp_bytes
= protgrp_blks
* blksize
;
2185 /* check if this pde is crossing the 4K boundary; if so split */
2186 if ((pde7
->addrLow
& 0xfff) + protgroup_len
> 0x1000) {
2187 protgroup_remainder
= 0x1000 - (pde7
->addrLow
& 0xfff);
2188 protgroup_offset
+= protgroup_remainder
;
2189 protgrp_blks
= protgroup_remainder
/ 8;
2190 protgrp_bytes
= protgrp_blks
* blksize
;
2192 protgroup_offset
= 0;
2198 /* setup BDE's for data blocks associated with DIF data */
2200 subtotal
= 0; /* total bytes processed for current prot grp */
2203 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2204 "9065 BLKGRD:%s Invalid data segment\n",
2209 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2210 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dataphysaddr
));
2211 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dataphysaddr
));
2213 remainder
= sg_dma_len(sgde
) - split_offset
;
2215 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2216 /* we can use this whole buffer */
2217 bpl
->tus
.f
.bdeSize
= remainder
;
2220 if ((subtotal
+ remainder
) == protgrp_bytes
)
2223 /* must split this buffer with next prot grp */
2224 bpl
->tus
.f
.bdeSize
= protgrp_bytes
- subtotal
;
2225 split_offset
+= bpl
->tus
.f
.bdeSize
;
2228 subtotal
+= bpl
->tus
.f
.bdeSize
;
2230 if (datadir
== DMA_TO_DEVICE
)
2231 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2233 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2234 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2242 /* Move to the next s/g segment if possible */
2243 sgde
= sg_next(sgde
);
2247 if (protgroup_offset
) {
2248 /* update the reference tag */
2249 reftag
+= protgrp_blks
;
2255 if (curr_prot
== protcnt
) {
2257 } else if (curr_prot
< protcnt
) {
2258 /* advance to next prot buffer */
2259 sgpe
= sg_next(sgpe
);
2262 /* update the reference tag */
2263 reftag
+= protgrp_blks
;
2265 /* if we're here, we have a bug */
2266 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2267 "9054 BLKGRD: bug in %s\n", __func__
);
2277 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
2278 * @phba: The Hba for which this call is being executed.
2279 * @sc: pointer to scsi command we're working on
2280 * @sgl: pointer to buffer list for protection groups
2281 * @datacnt: number of segments of data that have been dma mapped
2283 * This function sets up SGL buffer list for protection groups of
2284 * type LPFC_PG_TYPE_NO_DIF
2286 * This is usually used when the HBA is instructed to generate
2287 * DIFs and insert them into data stream (or strip DIF from
2288 * incoming data stream)
2290 * The buffer list consists of just one protection group described
2292 * +-------------------------+
2293 * start of prot group --> | DI_SEED |
2294 * +-------------------------+
2296 * +-------------------------+
2297 * |more Data SGE's ... (opt)|
2298 * +-------------------------+
2301 * Note: Data s/g buffers have been dma mapped
2303 * Returns the number of SGEs added to the SGL.
2306 lpfc_bg_setup_sgl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2307 struct sli4_sge
*sgl
, int datasegcnt
)
2309 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2310 struct sli4_sge_diseed
*diseed
= NULL
;
2311 dma_addr_t physaddr
;
2312 int i
= 0, num_sge
= 0, status
;
2313 int datadir
= sc
->sc_data_direction
;
2317 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2320 uint32_t checking
= 1;
2322 uint32_t dma_offset
= 0;
2324 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2328 /* extract some info from the scsi command for pde*/
2329 blksize
= lpfc_cmd_blksize(sc
);
2330 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2332 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2333 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2335 if (rc
& BG_ERR_SWAP
)
2336 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2337 if (rc
& BG_ERR_CHECK
)
2342 /* setup DISEED with what we have */
2343 diseed
= (struct sli4_sge_diseed
*) sgl
;
2344 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2345 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2347 /* Endianness conversion if necessary */
2348 diseed
->ref_tag
= cpu_to_le32(reftag
);
2349 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2351 /* setup DISEED with the rest of the info */
2352 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2353 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2354 if (datadir
== DMA_FROM_DEVICE
) {
2355 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2356 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2358 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2359 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2361 /* Endianness conversion if necessary for DISEED */
2362 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2363 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2365 /* advance bpl and increment sge count */
2369 /* assumption: caller has already run dma_map_sg on command data */
2370 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
2371 physaddr
= sg_dma_address(sgde
);
2372 dma_len
= sg_dma_len(sgde
);
2373 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
2374 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
2375 if ((i
+ 1) == datasegcnt
)
2376 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2378 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2379 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2380 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2382 sgl
->sge_len
= cpu_to_le32(dma_len
);
2383 dma_offset
+= dma_len
;
2394 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2395 * @phba: The Hba for which this call is being executed.
2396 * @sc: pointer to scsi command we're working on
2397 * @sgl: pointer to buffer list for protection groups
2398 * @datacnt: number of segments of data that have been dma mapped
2399 * @protcnt: number of segment of protection data that have been dma mapped
2401 * This function sets up SGL buffer list for protection groups of
2402 * type LPFC_PG_TYPE_DIF
2404 * This is usually used when DIFs are in their own buffers,
2405 * separate from the data. The HBA can then by instructed
2406 * to place the DIFs in the outgoing stream. For read operations,
2407 * The HBA could extract the DIFs and place it in DIF buffers.
2409 * The buffer list for this type consists of one or more of the
2410 * protection groups described below:
2411 * +-------------------------+
2412 * start of first prot group --> | DISEED |
2413 * +-------------------------+
2414 * | DIF (Prot SGE) |
2415 * +-------------------------+
2417 * +-------------------------+
2418 * |more Data SGE's ... (opt)|
2419 * +-------------------------+
2420 * start of new prot group --> | DISEED |
2421 * +-------------------------+
2423 * +-------------------------+
2425 * Note: It is assumed that both data and protection s/g buffers have been
2428 * Returns the number of SGEs added to the SGL.
2431 lpfc_bg_setup_sgl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2432 struct sli4_sge
*sgl
, int datacnt
, int protcnt
)
2434 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2435 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2436 struct sli4_sge_diseed
*diseed
= NULL
;
2437 dma_addr_t dataphysaddr
, protphysaddr
;
2438 unsigned short curr_data
= 0, curr_prot
= 0;
2439 unsigned int split_offset
;
2440 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2441 unsigned int protgrp_blks
, protgrp_bytes
;
2442 unsigned int remainder
, subtotal
;
2444 unsigned char pgdone
= 0, alldone
= 0;
2449 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2452 uint32_t checking
= 1;
2453 uint32_t dma_offset
= 0;
2456 sgpe
= scsi_prot_sglist(sc
);
2457 sgde
= scsi_sglist(sc
);
2459 if (!sgpe
|| !sgde
) {
2460 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2461 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2466 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2470 /* extract some info from the scsi command */
2471 blksize
= lpfc_cmd_blksize(sc
);
2472 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2474 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2475 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2477 if (rc
& BG_ERR_SWAP
)
2478 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2479 if (rc
& BG_ERR_CHECK
)
2486 /* setup DISEED with what we have */
2487 diseed
= (struct sli4_sge_diseed
*) sgl
;
2488 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2489 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2491 /* Endianness conversion if necessary */
2492 diseed
->ref_tag
= cpu_to_le32(reftag
);
2493 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2495 /* setup DISEED with the rest of the info */
2496 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2497 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2498 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2499 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2500 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2501 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2503 /* Endianness conversion if necessary for DISEED */
2504 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2505 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2507 /* advance sgl and increment bde count */
2511 /* setup the first BDE that points to protection buffer */
2512 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2513 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2515 /* must be integer multiple of the DIF block length */
2516 BUG_ON(protgroup_len
% 8);
2518 /* Now setup DIF SGE */
2520 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DIF
);
2521 sgl
->addr_hi
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2522 sgl
->addr_lo
= le32_to_cpu(putPaddrLow(protphysaddr
));
2523 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2525 protgrp_blks
= protgroup_len
/ 8;
2526 protgrp_bytes
= protgrp_blks
* blksize
;
2528 /* check if DIF SGE is crossing the 4K boundary; if so split */
2529 if ((sgl
->addr_lo
& 0xfff) + protgroup_len
> 0x1000) {
2530 protgroup_remainder
= 0x1000 - (sgl
->addr_lo
& 0xfff);
2531 protgroup_offset
+= protgroup_remainder
;
2532 protgrp_blks
= protgroup_remainder
/ 8;
2533 protgrp_bytes
= protgrp_blks
* blksize
;
2535 protgroup_offset
= 0;
2541 /* setup SGE's for data blocks associated with DIF data */
2543 subtotal
= 0; /* total bytes processed for current prot grp */
2546 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2547 "9086 BLKGRD:%s Invalid data segment\n",
2552 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2554 remainder
= sg_dma_len(sgde
) - split_offset
;
2556 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2557 /* we can use this whole buffer */
2558 dma_len
= remainder
;
2561 if ((subtotal
+ remainder
) == protgrp_bytes
)
2564 /* must split this buffer with next prot grp */
2565 dma_len
= protgrp_bytes
- subtotal
;
2566 split_offset
+= dma_len
;
2569 subtotal
+= dma_len
;
2571 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(dataphysaddr
));
2572 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(dataphysaddr
));
2573 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2574 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2575 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2577 sgl
->sge_len
= cpu_to_le32(dma_len
);
2578 dma_offset
+= dma_len
;
2586 /* Move to the next s/g segment if possible */
2587 sgde
= sg_next(sgde
);
2590 if (protgroup_offset
) {
2591 /* update the reference tag */
2592 reftag
+= protgrp_blks
;
2598 if (curr_prot
== protcnt
) {
2599 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2601 } else if (curr_prot
< protcnt
) {
2602 /* advance to next prot buffer */
2603 sgpe
= sg_next(sgpe
);
2606 /* update the reference tag */
2607 reftag
+= protgrp_blks
;
2609 /* if we're here, we have a bug */
2610 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2611 "9085 BLKGRD: bug in %s\n", __func__
);
2622 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2623 * @phba: The Hba for which this call is being executed.
2624 * @sc: pointer to scsi command we're working on
2626 * Given a SCSI command that supports DIF, determine composition of protection
2627 * groups involved in setting up buffer lists
2629 * Returns: Protection group type (with or without DIF)
2633 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
)
2635 int ret
= LPFC_PG_TYPE_INVALID
;
2636 unsigned char op
= scsi_get_prot_op(sc
);
2639 case SCSI_PROT_READ_STRIP
:
2640 case SCSI_PROT_WRITE_INSERT
:
2641 ret
= LPFC_PG_TYPE_NO_DIF
;
2643 case SCSI_PROT_READ_INSERT
:
2644 case SCSI_PROT_WRITE_STRIP
:
2645 case SCSI_PROT_READ_PASS
:
2646 case SCSI_PROT_WRITE_PASS
:
2647 ret
= LPFC_PG_TYPE_DIF_BUF
;
2650 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2651 "9021 Unsupported protection op:%d\n", op
);
2659 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2660 * @phba: The Hba for which this call is being executed.
2661 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2663 * This is the protection/DIF aware version of
2664 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2665 * two functions eventually, but for now, it's here
2668 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
,
2669 struct lpfc_scsi_buf
*lpfc_cmd
)
2671 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2672 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2673 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
2674 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2675 uint32_t num_bde
= 0;
2676 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
2677 int prot_group_type
= 0;
2682 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2683 * fcp_rsp regions to the first data bde entry
2686 if (scsi_sg_count(scsi_cmnd
)) {
2688 * The driver stores the segment count returned from pci_map_sg
2689 * because this a count of dma-mappings used to map the use_sg
2690 * pages. They are not guaranteed to be the same for those
2691 * architectures that implement an IOMMU.
2693 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2694 scsi_sglist(scsi_cmnd
),
2695 scsi_sg_count(scsi_cmnd
), datadir
);
2696 if (unlikely(!datasegcnt
))
2699 lpfc_cmd
->seg_cnt
= datasegcnt
;
2700 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
2701 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2702 "9067 BLKGRD: %s: Too many sg segments"
2703 " from dma_map_sg. Config %d, seg_cnt"
2705 __func__
, phba
->cfg_sg_seg_cnt
,
2707 scsi_dma_unmap(scsi_cmnd
);
2711 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
2713 switch (prot_group_type
) {
2714 case LPFC_PG_TYPE_NO_DIF
:
2715 num_bde
= lpfc_bg_setup_bpl(phba
, scsi_cmnd
, bpl
,
2717 /* we should have 2 or more entries in buffer list */
2721 case LPFC_PG_TYPE_DIF_BUF
:{
2723 * This type indicates that protection buffers are
2724 * passed to the driver, so that needs to be prepared
2727 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2728 scsi_prot_sglist(scsi_cmnd
),
2729 scsi_prot_sg_count(scsi_cmnd
), datadir
);
2730 if (unlikely(!protsegcnt
)) {
2731 scsi_dma_unmap(scsi_cmnd
);
2735 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
2736 if (lpfc_cmd
->prot_seg_cnt
2737 > phba
->cfg_prot_sg_seg_cnt
) {
2738 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2739 "9068 BLKGRD: %s: Too many prot sg "
2740 "segments from dma_map_sg. Config %d,"
2741 "prot_seg_cnt %d\n", __func__
,
2742 phba
->cfg_prot_sg_seg_cnt
,
2743 lpfc_cmd
->prot_seg_cnt
);
2744 dma_unmap_sg(&phba
->pcidev
->dev
,
2745 scsi_prot_sglist(scsi_cmnd
),
2746 scsi_prot_sg_count(scsi_cmnd
),
2748 scsi_dma_unmap(scsi_cmnd
);
2752 num_bde
= lpfc_bg_setup_bpl_prot(phba
, scsi_cmnd
, bpl
,
2753 datasegcnt
, protsegcnt
);
2754 /* we should have 3 or more entries in buffer list */
2759 case LPFC_PG_TYPE_INVALID
:
2761 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2762 "9022 Unexpected protection group %i\n",
2769 * Finish initializing those IOCB fields that are dependent on the
2770 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2771 * reinitialized since all iocb memory resources are used many times
2772 * for transmit, receive, and continuation bpl's.
2774 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
2775 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
+= (num_bde
* sizeof(struct ulp_bde64
));
2776 iocb_cmd
->ulpBdeCount
= 1;
2777 iocb_cmd
->ulpLe
= 1;
2779 fcpdl
= scsi_bufflen(scsi_cmnd
);
2781 if (scsi_get_prot_type(scsi_cmnd
) == SCSI_PROT_DIF_TYPE1
) {
2783 * We are in DIF Type 1 mode
2784 * Every data block has a 8 byte DIF (trailer)
2785 * attached to it. Must ajust FCP data length
2787 blksize
= lpfc_cmd_blksize(scsi_cmnd
);
2788 diflen
= (fcpdl
/ blksize
) * 8;
2791 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
2794 * Due to difference in data length between DIF/non-DIF paths,
2795 * we need to set word 4 of IOCB here
2797 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
2801 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2802 "9023 Could not setup all needed BDE's"
2803 "prot_group_type=%d, num_bde=%d\n",
2804 prot_group_type
, num_bde
);
2809 * This function checks for BlockGuard errors detected by
2810 * the HBA. In case of errors, the ASC/ASCQ fields in the
2811 * sense buffer will be set accordingly, paired with
2812 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2813 * detected corruption.
2816 * 0 - No error found
2817 * 1 - BlockGuard error found
2818 * -1 - Internal error (bad profile, ...etc)
2821 lpfc_parse_bg_err(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
,
2822 struct lpfc_iocbq
*pIocbOut
)
2824 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
2825 struct sli3_bg_fields
*bgf
= &pIocbOut
->iocb
.unsli3
.sli3_bg
;
2827 uint32_t bghm
= bgf
->bghm
;
2828 uint32_t bgstat
= bgf
->bgstat
;
2829 uint64_t failing_sector
= 0;
2831 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9069 BLKGRD: BG ERROR in cmd"
2832 " 0x%x lba 0x%llx blk cnt 0x%x "
2833 "bgstat=0x%x bghm=0x%x\n",
2834 cmd
->cmnd
[0], (unsigned long long)scsi_get_lba(cmd
),
2835 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
2837 spin_lock(&_dump_buf_lock
);
2838 if (!_dump_buf_done
) {
2839 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9070 BLKGRD: Saving"
2840 " Data for %u blocks to debugfs\n",
2841 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
2842 lpfc_debug_save_data(phba
, cmd
);
2844 /* If we have a prot sgl, save the DIF buffer */
2845 if (lpfc_prot_group_type(phba
, cmd
) ==
2846 LPFC_PG_TYPE_DIF_BUF
) {
2847 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9071 BLKGRD: "
2848 "Saving DIF for %u blocks to debugfs\n",
2849 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
2850 lpfc_debug_save_dif(phba
, cmd
);
2855 spin_unlock(&_dump_buf_lock
);
2857 if (lpfc_bgs_get_invalid_prof(bgstat
)) {
2858 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2859 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9072 BLKGRD: Invalid"
2860 " BlockGuard profile. bgstat:0x%x\n",
2866 if (lpfc_bgs_get_uninit_dif_block(bgstat
)) {
2867 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2868 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9073 BLKGRD: "
2869 "Invalid BlockGuard DIF Block. bgstat:0x%x\n",
2875 if (lpfc_bgs_get_guard_err(bgstat
)) {
2878 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2880 cmd
->result
= DRIVER_SENSE
<< 24
2881 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2882 phba
->bg_guard_err_cnt
++;
2883 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2884 "9055 BLKGRD: guard_tag error\n");
2887 if (lpfc_bgs_get_reftag_err(bgstat
)) {
2890 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2892 cmd
->result
= DRIVER_SENSE
<< 24
2893 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2895 phba
->bg_reftag_err_cnt
++;
2896 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2897 "9056 BLKGRD: ref_tag error\n");
2900 if (lpfc_bgs_get_apptag_err(bgstat
)) {
2903 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2905 cmd
->result
= DRIVER_SENSE
<< 24
2906 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2908 phba
->bg_apptag_err_cnt
++;
2909 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2910 "9061 BLKGRD: app_tag error\n");
2913 if (lpfc_bgs_get_hi_water_mark_present(bgstat
)) {
2915 * setup sense data descriptor 0 per SPC-4 as an information
2916 * field, and put the failing LBA in it.
2917 * This code assumes there was also a guard/app/ref tag error
2920 cmd
->sense_buffer
[7] = 0xc; /* Additional sense length */
2921 cmd
->sense_buffer
[8] = 0; /* Information descriptor type */
2922 cmd
->sense_buffer
[9] = 0xa; /* Additional descriptor length */
2923 cmd
->sense_buffer
[10] = 0x80; /* Validity bit */
2925 /* bghm is a "on the wire" FC frame based count */
2926 switch (scsi_get_prot_op(cmd
)) {
2927 case SCSI_PROT_READ_INSERT
:
2928 case SCSI_PROT_WRITE_STRIP
:
2929 bghm
/= cmd
->device
->sector_size
;
2931 case SCSI_PROT_READ_STRIP
:
2932 case SCSI_PROT_WRITE_INSERT
:
2933 case SCSI_PROT_READ_PASS
:
2934 case SCSI_PROT_WRITE_PASS
:
2935 bghm
/= (cmd
->device
->sector_size
+
2936 sizeof(struct scsi_dif_tuple
));
2940 failing_sector
= scsi_get_lba(cmd
);
2941 failing_sector
+= bghm
;
2943 /* Descriptor Information */
2944 put_unaligned_be64(failing_sector
, &cmd
->sense_buffer
[12]);
2948 /* No error was reported - problem in FW? */
2949 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2950 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2951 "9057 BLKGRD: Unknown error reported!\n");
2959 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
2960 * @phba: The Hba for which this call is being executed.
2961 * @lpfc_cmd: The scsi buffer which is going to be mapped.
2963 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
2964 * field of @lpfc_cmd for device with SLI-4 interface spec.
2971 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
2973 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2974 struct scatterlist
*sgel
= NULL
;
2975 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2976 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
2977 struct sli4_sge
*first_data_sgl
;
2978 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2979 dma_addr_t physaddr
;
2980 uint32_t num_bde
= 0;
2982 uint32_t dma_offset
= 0;
2984 struct ulp_bde64
*bde
;
2987 * There are three possibilities here - use scatter-gather segment, use
2988 * the single mapping, or neither. Start the lpfc command prep by
2989 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
2992 if (scsi_sg_count(scsi_cmnd
)) {
2994 * The driver stores the segment count returned from pci_map_sg
2995 * because this a count of dma-mappings used to map the use_sg
2996 * pages. They are not guaranteed to be the same for those
2997 * architectures that implement an IOMMU.
3000 nseg
= scsi_dma_map(scsi_cmnd
);
3001 if (unlikely(!nseg
))
3004 /* clear the last flag in the fcp_rsp map entry */
3005 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3006 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3007 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3009 first_data_sgl
= sgl
;
3010 lpfc_cmd
->seg_cnt
= nseg
;
3011 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
3012 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9074 BLKGRD:"
3013 " %s: Too many sg segments from "
3014 "dma_map_sg. Config %d, seg_cnt %d\n",
3015 __func__
, phba
->cfg_sg_seg_cnt
,
3017 scsi_dma_unmap(scsi_cmnd
);
3022 * The driver established a maximum scatter-gather segment count
3023 * during probe that limits the number of sg elements in any
3024 * single scsi command. Just run through the seg_cnt and format
3026 * When using SLI-3 the driver will try to fit all the BDEs into
3027 * the IOCB. If it can't then the BDEs get added to a BPL as it
3028 * does for SLI-2 mode.
3030 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
3031 physaddr
= sg_dma_address(sgel
);
3032 dma_len
= sg_dma_len(sgel
);
3033 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
3034 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
3035 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3036 if ((num_bde
+ 1) == nseg
)
3037 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3039 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3040 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
3041 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
3042 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3043 sgl
->sge_len
= cpu_to_le32(dma_len
);
3044 dma_offset
+= dma_len
;
3047 /* setup the performance hint (first data BDE) if enabled */
3048 if (phba
->sli3_options
& LPFC_SLI4_PERFH_ENABLED
) {
3049 bde
= (struct ulp_bde64
*)
3050 &(iocb_cmd
->unsli3
.sli3Words
[5]);
3051 bde
->addrLow
= first_data_sgl
->addr_lo
;
3052 bde
->addrHigh
= first_data_sgl
->addr_hi
;
3053 bde
->tus
.f
.bdeSize
=
3054 le32_to_cpu(first_data_sgl
->sge_len
);
3055 bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
3056 bde
->tus
.w
= cpu_to_le32(bde
->tus
.w
);
3060 /* clear the last flag in the fcp_rsp map entry */
3061 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3062 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3063 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3067 * Finish initializing those IOCB fields that are dependent on the
3068 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3069 * explicitly reinitialized.
3070 * all iocb memory resources are reused.
3072 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
3075 * Due to difference in data length between DIF/non-DIF paths,
3076 * we need to set word 4 of IOCB here
3078 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
3083 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
3084 * @phba: The Hba for which this call is being executed.
3085 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
3087 * Adjust the data length to account for how much data
3088 * is actually on the wire.
3090 * returns the adjusted data length
3093 lpfc_bg_scsi_adjust_dl(struct lpfc_hba
*phba
,
3094 struct lpfc_scsi_buf
*lpfc_cmd
)
3096 struct scsi_cmnd
*sc
= lpfc_cmd
->pCmd
;
3100 fcpdl
= scsi_bufflen(sc
);
3102 /* Check if there is protection data on the wire */
3103 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
3105 if (scsi_get_prot_op(sc
) == SCSI_PROT_READ_INSERT
)
3110 if (scsi_get_prot_op(sc
) == SCSI_PROT_WRITE_STRIP
)
3114 /* If protection data on the wire, adjust the count accordingly */
3115 blksize
= lpfc_cmd_blksize(sc
);
3116 diflen
= (fcpdl
/ blksize
) * 8;
3122 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3123 * @phba: The Hba for which this call is being executed.
3124 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3126 * This is the protection/DIF aware version of
3127 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3128 * two functions eventually, but for now, it's here
3131 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
,
3132 struct lpfc_scsi_buf
*lpfc_cmd
)
3134 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3135 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3136 struct sli4_sge
*sgl
= (struct sli4_sge
*)(lpfc_cmd
->fcp_bpl
);
3137 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3138 uint32_t num_bde
= 0;
3139 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
3140 int prot_group_type
= 0;
3144 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3145 * fcp_rsp regions to the first data bde entry
3147 if (scsi_sg_count(scsi_cmnd
)) {
3149 * The driver stores the segment count returned from pci_map_sg
3150 * because this a count of dma-mappings used to map the use_sg
3151 * pages. They are not guaranteed to be the same for those
3152 * architectures that implement an IOMMU.
3154 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3155 scsi_sglist(scsi_cmnd
),
3156 scsi_sg_count(scsi_cmnd
), datadir
);
3157 if (unlikely(!datasegcnt
))
3161 /* clear the last flag in the fcp_rsp map entry */
3162 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3163 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3164 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3167 lpfc_cmd
->seg_cnt
= datasegcnt
;
3168 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
3169 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
3170 "9087 BLKGRD: %s: Too many sg segments"
3171 " from dma_map_sg. Config %d, seg_cnt"
3173 __func__
, phba
->cfg_sg_seg_cnt
,
3175 scsi_dma_unmap(scsi_cmnd
);
3179 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
3181 switch (prot_group_type
) {
3182 case LPFC_PG_TYPE_NO_DIF
:
3183 num_bde
= lpfc_bg_setup_sgl(phba
, scsi_cmnd
, sgl
,
3185 /* we should have 2 or more entries in buffer list */
3189 case LPFC_PG_TYPE_DIF_BUF
:{
3191 * This type indicates that protection buffers are
3192 * passed to the driver, so that needs to be prepared
3195 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3196 scsi_prot_sglist(scsi_cmnd
),
3197 scsi_prot_sg_count(scsi_cmnd
), datadir
);
3198 if (unlikely(!protsegcnt
)) {
3199 scsi_dma_unmap(scsi_cmnd
);
3203 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
3204 if (lpfc_cmd
->prot_seg_cnt
3205 > phba
->cfg_prot_sg_seg_cnt
) {
3206 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
3207 "9088 BLKGRD: %s: Too many prot sg "
3208 "segments from dma_map_sg. Config %d,"
3209 "prot_seg_cnt %d\n", __func__
,
3210 phba
->cfg_prot_sg_seg_cnt
,
3211 lpfc_cmd
->prot_seg_cnt
);
3212 dma_unmap_sg(&phba
->pcidev
->dev
,
3213 scsi_prot_sglist(scsi_cmnd
),
3214 scsi_prot_sg_count(scsi_cmnd
),
3216 scsi_dma_unmap(scsi_cmnd
);
3220 num_bde
= lpfc_bg_setup_sgl_prot(phba
, scsi_cmnd
, sgl
,
3221 datasegcnt
, protsegcnt
);
3222 /* we should have 3 or more entries in buffer list */
3227 case LPFC_PG_TYPE_INVALID
:
3229 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3230 "9083 Unexpected protection group %i\n",
3236 fcpdl
= lpfc_bg_scsi_adjust_dl(phba
, lpfc_cmd
);
3238 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
3241 * Due to difference in data length between DIF/non-DIF paths,
3242 * we need to set word 4 of IOCB here
3244 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
3245 lpfc_cmd
->cur_iocbq
.iocb_flag
|= LPFC_IO_DIF
;
3249 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3250 "9084 Could not setup all needed BDE's"
3251 "prot_group_type=%d, num_bde=%d\n",
3252 prot_group_type
, num_bde
);
3257 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3258 * @phba: The Hba for which this call is being executed.
3259 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3261 * This routine wraps the actual DMA mapping function pointer from the
3269 lpfc_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3271 return phba
->lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3275 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3277 * @phba: The Hba for which this call is being executed.
3278 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3280 * This routine wraps the actual DMA mapping function pointer from the
3288 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3290 return phba
->lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3294 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3295 * @phba: Pointer to hba context object.
3296 * @vport: Pointer to vport object.
3297 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3298 * @rsp_iocb: Pointer to response iocb object which reported error.
3300 * This function posts an event when there is a SCSI command reporting
3301 * error from the scsi device.
3304 lpfc_send_scsi_error_event(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
3305 struct lpfc_scsi_buf
*lpfc_cmd
, struct lpfc_iocbq
*rsp_iocb
) {
3306 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3307 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3308 uint32_t resp_info
= fcprsp
->rspStatus2
;
3309 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3310 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3311 struct lpfc_fast_path_event
*fast_path_evt
= NULL
;
3312 struct lpfc_nodelist
*pnode
= lpfc_cmd
->rdata
->pnode
;
3313 unsigned long flags
;
3315 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3318 /* If there is queuefull or busy condition send a scsi event */
3319 if ((cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ||
3320 (cmnd
->result
== SAM_STAT_BUSY
)) {
3321 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3324 fast_path_evt
->un
.scsi_evt
.event_type
=
3326 fast_path_evt
->un
.scsi_evt
.subcategory
=
3327 (cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ?
3328 LPFC_EVENT_QFULL
: LPFC_EVENT_DEVBSY
;
3329 fast_path_evt
->un
.scsi_evt
.lun
= cmnd
->device
->lun
;
3330 memcpy(&fast_path_evt
->un
.scsi_evt
.wwpn
,
3331 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3332 memcpy(&fast_path_evt
->un
.scsi_evt
.wwnn
,
3333 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3334 } else if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
&&
3335 ((cmnd
->cmnd
[0] == READ_10
) || (cmnd
->cmnd
[0] == WRITE_10
))) {
3336 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3339 fast_path_evt
->un
.check_cond_evt
.scsi_event
.event_type
=
3341 fast_path_evt
->un
.check_cond_evt
.scsi_event
.subcategory
=
3342 LPFC_EVENT_CHECK_COND
;
3343 fast_path_evt
->un
.check_cond_evt
.scsi_event
.lun
=
3345 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwpn
,
3346 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3347 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwnn
,
3348 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3349 fast_path_evt
->un
.check_cond_evt
.sense_key
=
3350 cmnd
->sense_buffer
[2] & 0xf;
3351 fast_path_evt
->un
.check_cond_evt
.asc
= cmnd
->sense_buffer
[12];
3352 fast_path_evt
->un
.check_cond_evt
.ascq
= cmnd
->sense_buffer
[13];
3353 } else if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3355 ((be32_to_cpu(fcprsp
->rspResId
) != fcpi_parm
) ||
3356 ((scsi_status
== SAM_STAT_GOOD
) &&
3357 !(resp_info
& (RESID_UNDER
| RESID_OVER
))))) {
3359 * If status is good or resid does not match with fcp_param and
3360 * there is valid fcpi_parm, then there is a read_check error
3362 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3365 fast_path_evt
->un
.read_check_error
.header
.event_type
=
3366 FC_REG_FABRIC_EVENT
;
3367 fast_path_evt
->un
.read_check_error
.header
.subcategory
=
3368 LPFC_EVENT_FCPRDCHKERR
;
3369 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwpn
,
3370 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3371 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwnn
,
3372 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3373 fast_path_evt
->un
.read_check_error
.lun
= cmnd
->device
->lun
;
3374 fast_path_evt
->un
.read_check_error
.opcode
= cmnd
->cmnd
[0];
3375 fast_path_evt
->un
.read_check_error
.fcpiparam
=
3380 fast_path_evt
->vport
= vport
;
3381 spin_lock_irqsave(&phba
->hbalock
, flags
);
3382 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
3383 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3384 lpfc_worker_wake_up(phba
);
3389 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3390 * @phba: The HBA for which this call is being executed.
3391 * @psb: The scsi buffer which is going to be un-mapped.
3393 * This routine does DMA un-mapping of scatter gather list of scsi command
3394 * field of @lpfc_cmd for device with SLI-3 interface spec.
3397 lpfc_scsi_unprep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
3400 * There are only two special cases to consider. (1) the scsi command
3401 * requested scatter-gather usage or (2) the scsi command allocated
3402 * a request buffer, but did not request use_sg. There is a third
3403 * case, but it does not require resource deallocation.
3405 if (psb
->seg_cnt
> 0)
3406 scsi_dma_unmap(psb
->pCmd
);
3407 if (psb
->prot_seg_cnt
> 0)
3408 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(psb
->pCmd
),
3409 scsi_prot_sg_count(psb
->pCmd
),
3410 psb
->pCmd
->sc_data_direction
);
3414 * lpfc_handler_fcp_err - FCP response handler
3415 * @vport: The virtual port for which this call is being executed.
3416 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3417 * @rsp_iocb: The response IOCB which contains FCP error.
3419 * This routine is called to process response IOCB with status field
3420 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3421 * based upon SCSI and FCP error.
3424 lpfc_handle_fcp_err(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
3425 struct lpfc_iocbq
*rsp_iocb
)
3427 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3428 struct fcp_cmnd
*fcpcmd
= lpfc_cmd
->fcp_cmnd
;
3429 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3430 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3431 uint32_t resp_info
= fcprsp
->rspStatus2
;
3432 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3434 uint32_t host_status
= DID_OK
;
3435 uint32_t rsplen
= 0;
3436 uint32_t logit
= LOG_FCP
| LOG_FCP_ERROR
;
3440 * If this is a task management command, there is no
3441 * scsi packet associated with this lpfc_cmd. The driver
3444 if (fcpcmd
->fcpCntl2
) {
3449 if (resp_info
& RSP_LEN_VALID
) {
3450 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3451 if (rsplen
!= 0 && rsplen
!= 4 && rsplen
!= 8) {
3452 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3453 "2719 Invalid response length: "
3454 "tgt x%x lun x%x cmnd x%x rsplen x%x\n",
3456 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3458 host_status
= DID_ERROR
;
3461 if (fcprsp
->rspInfo3
!= RSP_NO_FAILURE
) {
3462 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3463 "2757 Protocol failure detected during "
3464 "processing of FCP I/O op: "
3465 "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n",
3467 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3469 host_status
= DID_ERROR
;
3474 if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
) {
3475 uint32_t snslen
= be32_to_cpu(fcprsp
->rspSnsLen
);
3476 if (snslen
> SCSI_SENSE_BUFFERSIZE
)
3477 snslen
= SCSI_SENSE_BUFFERSIZE
;
3479 if (resp_info
& RSP_LEN_VALID
)
3480 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3481 memcpy(cmnd
->sense_buffer
, &fcprsp
->rspInfo0
+ rsplen
, snslen
);
3483 lp
= (uint32_t *)cmnd
->sense_buffer
;
3485 if (!scsi_status
&& (resp_info
& RESID_UNDER
) &&
3486 vport
->cfg_log_verbose
& LOG_FCP_UNDER
)
3487 logit
= LOG_FCP_UNDER
;
3489 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3490 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3491 "Data: x%x x%x x%x x%x x%x\n",
3492 cmnd
->cmnd
[0], scsi_status
,
3493 be32_to_cpu(*lp
), be32_to_cpu(*(lp
+ 3)), resp_info
,
3494 be32_to_cpu(fcprsp
->rspResId
),
3495 be32_to_cpu(fcprsp
->rspSnsLen
),
3496 be32_to_cpu(fcprsp
->rspRspLen
),
3499 scsi_set_resid(cmnd
, 0);
3500 if (resp_info
& RESID_UNDER
) {
3501 scsi_set_resid(cmnd
, be32_to_cpu(fcprsp
->rspResId
));
3503 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_UNDER
,
3504 "9025 FCP Read Underrun, expected %d, "
3505 "residual %d Data: x%x x%x x%x\n",
3506 be32_to_cpu(fcpcmd
->fcpDl
),
3507 scsi_get_resid(cmnd
), fcpi_parm
, cmnd
->cmnd
[0],
3511 * If there is an under run check if under run reported by
3512 * storage array is same as the under run reported by HBA.
3513 * If this is not same, there is a dropped frame.
3515 if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3517 (scsi_get_resid(cmnd
) != fcpi_parm
)) {
3518 lpfc_printf_vlog(vport
, KERN_WARNING
,
3519 LOG_FCP
| LOG_FCP_ERROR
,
3520 "9026 FCP Read Check Error "
3521 "and Underrun Data: x%x x%x x%x x%x\n",
3522 be32_to_cpu(fcpcmd
->fcpDl
),
3523 scsi_get_resid(cmnd
), fcpi_parm
,
3525 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3526 host_status
= DID_ERROR
;
3529 * The cmnd->underflow is the minimum number of bytes that must
3530 * be transferred for this command. Provided a sense condition
3531 * is not present, make sure the actual amount transferred is at
3532 * least the underflow value or fail.
3534 if (!(resp_info
& SNS_LEN_VALID
) &&
3535 (scsi_status
== SAM_STAT_GOOD
) &&
3536 (scsi_bufflen(cmnd
) - scsi_get_resid(cmnd
)
3537 < cmnd
->underflow
)) {
3538 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3539 "9027 FCP command x%x residual "
3540 "underrun converted to error "
3541 "Data: x%x x%x x%x\n",
3542 cmnd
->cmnd
[0], scsi_bufflen(cmnd
),
3543 scsi_get_resid(cmnd
), cmnd
->underflow
);
3544 host_status
= DID_ERROR
;
3546 } else if (resp_info
& RESID_OVER
) {
3547 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3548 "9028 FCP command x%x residual overrun error. "
3549 "Data: x%x x%x\n", cmnd
->cmnd
[0],
3550 scsi_bufflen(cmnd
), scsi_get_resid(cmnd
));
3551 host_status
= DID_ERROR
;
3554 * Check SLI validation that all the transfer was actually done
3555 * (fcpi_parm should be zero). Apply check only to reads.
3557 } else if (fcpi_parm
&& (cmnd
->sc_data_direction
== DMA_FROM_DEVICE
)) {
3558 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
| LOG_FCP_ERROR
,
3559 "9029 FCP Read Check Error Data: "
3560 "x%x x%x x%x x%x x%x\n",
3561 be32_to_cpu(fcpcmd
->fcpDl
),
3562 be32_to_cpu(fcprsp
->rspResId
),
3563 fcpi_parm
, cmnd
->cmnd
[0], scsi_status
);
3564 switch (scsi_status
) {
3566 case SAM_STAT_CHECK_CONDITION
:
3567 /* Fabric dropped a data frame. Fail any successful
3568 * command in which we detected dropped frames.
3569 * A status of good or some check conditions could
3570 * be considered a successful command.
3572 host_status
= DID_ERROR
;
3575 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3579 cmnd
->result
= ScsiResult(host_status
, scsi_status
);
3580 lpfc_send_scsi_error_event(vport
->phba
, vport
, lpfc_cmd
, rsp_iocb
);
3584 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3585 * @phba: The Hba for which this call is being executed.
3586 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3587 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3589 * This routine assigns scsi command result by looking into response IOCB
3590 * status field appropriately. This routine handles QUEUE FULL condition as
3591 * well by ramping down device queue depth.
3594 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pIocbIn
,
3595 struct lpfc_iocbq
*pIocbOut
)
3597 struct lpfc_scsi_buf
*lpfc_cmd
=
3598 (struct lpfc_scsi_buf
*) pIocbIn
->context1
;
3599 struct lpfc_vport
*vport
= pIocbIn
->vport
;
3600 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
3601 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
3602 struct scsi_cmnd
*cmd
;
3604 struct scsi_device
*tmp_sdev
;
3606 unsigned long flags
;
3607 struct lpfc_fast_path_event
*fast_path_evt
;
3608 struct Scsi_Host
*shost
;
3609 uint32_t queue_depth
, scsi_id
;
3610 uint32_t logit
= LOG_FCP
;
3612 /* Sanity check on return of outstanding command */
3613 if (!(lpfc_cmd
->pCmd
))
3615 cmd
= lpfc_cmd
->pCmd
;
3616 shost
= cmd
->device
->host
;
3618 lpfc_cmd
->result
= pIocbOut
->iocb
.un
.ulpWord
[4];
3619 lpfc_cmd
->status
= pIocbOut
->iocb
.ulpStatus
;
3620 /* pick up SLI4 exhange busy status from HBA */
3621 lpfc_cmd
->exch_busy
= pIocbOut
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
3623 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3624 if (lpfc_cmd
->prot_data_type
) {
3625 struct scsi_dif_tuple
*src
= NULL
;
3627 src
= (struct scsi_dif_tuple
*)lpfc_cmd
->prot_data_segment
;
3629 * Used to restore any changes to protection
3630 * data for error injection.
3632 switch (lpfc_cmd
->prot_data_type
) {
3633 case LPFC_INJERR_REFTAG
:
3635 lpfc_cmd
->prot_data
;
3637 case LPFC_INJERR_APPTAG
:
3639 (uint16_t)lpfc_cmd
->prot_data
;
3641 case LPFC_INJERR_GUARD
:
3643 (uint16_t)lpfc_cmd
->prot_data
;
3649 lpfc_cmd
->prot_data
= 0;
3650 lpfc_cmd
->prot_data_type
= 0;
3651 lpfc_cmd
->prot_data_segment
= NULL
;
3654 if (pnode
&& NLP_CHK_NODE_ACT(pnode
))
3655 atomic_dec(&pnode
->cmd_pending
);
3657 if (lpfc_cmd
->status
) {
3658 if (lpfc_cmd
->status
== IOSTAT_LOCAL_REJECT
&&
3659 (lpfc_cmd
->result
& IOERR_DRVR_MASK
))
3660 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
3661 else if (lpfc_cmd
->status
>= IOSTAT_CNT
)
3662 lpfc_cmd
->status
= IOSTAT_DEFAULT
;
3663 if (lpfc_cmd
->status
== IOSTAT_FCP_RSP_ERROR
3664 && !lpfc_cmd
->fcp_rsp
->rspStatus3
3665 && (lpfc_cmd
->fcp_rsp
->rspStatus2
& RESID_UNDER
)
3666 && !(phba
->cfg_log_verbose
& LOG_FCP_UNDER
))
3669 logit
= LOG_FCP
| LOG_FCP_UNDER
;
3670 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3671 "9030 FCP cmd x%x failed <%d/%d> "
3672 "status: x%x result: x%x "
3673 "sid: x%x did: x%x oxid: x%x "
3676 cmd
->device
? cmd
->device
->id
: 0xffff,
3677 cmd
->device
? cmd
->device
->lun
: 0xffff,
3678 lpfc_cmd
->status
, lpfc_cmd
->result
,
3679 vport
->fc_myDID
, pnode
->nlp_DID
,
3680 phba
->sli_rev
== LPFC_SLI_REV4
?
3681 lpfc_cmd
->cur_iocbq
.sli4_xritag
: 0xffff,
3682 pIocbOut
->iocb
.ulpContext
,
3683 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
3685 switch (lpfc_cmd
->status
) {
3686 case IOSTAT_FCP_RSP_ERROR
:
3687 /* Call FCP RSP handler to determine result */
3688 lpfc_handle_fcp_err(vport
, lpfc_cmd
, pIocbOut
);
3690 case IOSTAT_NPORT_BSY
:
3691 case IOSTAT_FABRIC_BSY
:
3692 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
, 0);
3693 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3696 fast_path_evt
->un
.fabric_evt
.event_type
=
3697 FC_REG_FABRIC_EVENT
;
3698 fast_path_evt
->un
.fabric_evt
.subcategory
=
3699 (lpfc_cmd
->status
== IOSTAT_NPORT_BSY
) ?
3700 LPFC_EVENT_PORT_BUSY
: LPFC_EVENT_FABRIC_BUSY
;
3701 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3702 memcpy(&fast_path_evt
->un
.fabric_evt
.wwpn
,
3703 &pnode
->nlp_portname
,
3704 sizeof(struct lpfc_name
));
3705 memcpy(&fast_path_evt
->un
.fabric_evt
.wwnn
,
3706 &pnode
->nlp_nodename
,
3707 sizeof(struct lpfc_name
));
3709 fast_path_evt
->vport
= vport
;
3710 fast_path_evt
->work_evt
.evt
=
3711 LPFC_EVT_FASTPATH_MGMT_EVT
;
3712 spin_lock_irqsave(&phba
->hbalock
, flags
);
3713 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
,
3715 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3716 lpfc_worker_wake_up(phba
);
3718 case IOSTAT_LOCAL_REJECT
:
3719 case IOSTAT_REMOTE_STOP
:
3720 if (lpfc_cmd
->result
== IOERR_ELXSEC_KEY_UNWRAP_ERROR
||
3722 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR
||
3723 lpfc_cmd
->result
== IOERR_ELXSEC_CRYPTO_ERROR
||
3725 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR
) {
3726 cmd
->result
= ScsiResult(DID_NO_CONNECT
, 0);
3729 if (lpfc_cmd
->result
== IOERR_INVALID_RPI
||
3730 lpfc_cmd
->result
== IOERR_NO_RESOURCES
||
3731 lpfc_cmd
->result
== IOERR_ABORT_REQUESTED
||
3732 lpfc_cmd
->result
== IOERR_SLER_CMD_RCV_FAILURE
) {
3733 cmd
->result
= ScsiResult(DID_REQUEUE
, 0);
3736 if ((lpfc_cmd
->result
== IOERR_RX_DMA_FAILED
||
3737 lpfc_cmd
->result
== IOERR_TX_DMA_FAILED
) &&
3738 pIocbOut
->iocb
.unsli3
.sli3_bg
.bgstat
) {
3739 if (scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
3741 * This is a response for a BG enabled
3742 * cmd. Parse BG error
3744 lpfc_parse_bg_err(phba
, lpfc_cmd
,
3748 lpfc_printf_vlog(vport
, KERN_WARNING
,
3750 "9031 non-zero BGSTAT "
3751 "on unprotected cmd\n");
3754 if ((lpfc_cmd
->status
== IOSTAT_REMOTE_STOP
)
3755 && (phba
->sli_rev
== LPFC_SLI_REV4
)
3756 && (pnode
&& NLP_CHK_NODE_ACT(pnode
))) {
3757 /* This IO was aborted by the target, we don't
3758 * know the rxid and because we did not send the
3759 * ABTS we cannot generate and RRQ.
3761 lpfc_set_rrq_active(phba
, pnode
,
3762 lpfc_cmd
->cur_iocbq
.sli4_lxritag
,
3765 /* else: fall through */
3767 cmd
->result
= ScsiResult(DID_ERROR
, 0);
3771 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
)
3772 || (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
3773 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
,
3776 cmd
->result
= ScsiResult(DID_OK
, 0);
3778 if (cmd
->result
|| lpfc_cmd
->fcp_rsp
->rspSnsLen
) {
3779 uint32_t *lp
= (uint32_t *)cmd
->sense_buffer
;
3781 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3782 "0710 Iodone <%d/%d> cmd %p, error "
3783 "x%x SNS x%x x%x Data: x%x x%x\n",
3784 cmd
->device
->id
, cmd
->device
->lun
, cmd
,
3785 cmd
->result
, *lp
, *(lp
+ 3), cmd
->retries
,
3786 scsi_get_resid(cmd
));
3789 lpfc_update_stats(phba
, lpfc_cmd
);
3790 result
= cmd
->result
;
3791 if (vport
->cfg_max_scsicmpl_time
&&
3792 time_after(jiffies
, lpfc_cmd
->start_time
+
3793 msecs_to_jiffies(vport
->cfg_max_scsicmpl_time
))) {
3794 spin_lock_irqsave(shost
->host_lock
, flags
);
3795 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3796 if (pnode
->cmd_qdepth
>
3797 atomic_read(&pnode
->cmd_pending
) &&
3798 (atomic_read(&pnode
->cmd_pending
) >
3799 LPFC_MIN_TGT_QDEPTH
) &&
3800 ((cmd
->cmnd
[0] == READ_10
) ||
3801 (cmd
->cmnd
[0] == WRITE_10
)))
3803 atomic_read(&pnode
->cmd_pending
);
3805 pnode
->last_change_time
= jiffies
;
3807 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3808 } else if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3809 if ((pnode
->cmd_qdepth
< vport
->cfg_tgt_queue_depth
) &&
3810 time_after(jiffies
, pnode
->last_change_time
+
3811 msecs_to_jiffies(LPFC_TGTQ_INTERVAL
))) {
3812 spin_lock_irqsave(shost
->host_lock
, flags
);
3813 depth
= pnode
->cmd_qdepth
* LPFC_TGTQ_RAMPUP_PCENT
3815 depth
= depth
? depth
: 1;
3816 pnode
->cmd_qdepth
+= depth
;
3817 if (pnode
->cmd_qdepth
> vport
->cfg_tgt_queue_depth
)
3818 pnode
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
3819 pnode
->last_change_time
= jiffies
;
3820 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3824 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
3826 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
3827 queue_depth
= cmd
->device
->queue_depth
;
3828 scsi_id
= cmd
->device
->id
;
3829 cmd
->scsi_done(cmd
);
3831 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
3833 * If there is a thread waiting for command completion
3834 * wake up the thread.
3836 spin_lock_irqsave(shost
->host_lock
, flags
);
3837 lpfc_cmd
->pCmd
= NULL
;
3838 if (lpfc_cmd
->waitq
)
3839 wake_up(lpfc_cmd
->waitq
);
3840 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3841 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3846 lpfc_rampup_queue_depth(vport
, queue_depth
);
3849 * Check for queue full. If the lun is reporting queue full, then
3850 * back off the lun queue depth to prevent target overloads.
3852 if (result
== SAM_STAT_TASK_SET_FULL
&& pnode
&&
3853 NLP_CHK_NODE_ACT(pnode
)) {
3854 shost_for_each_device(tmp_sdev
, shost
) {
3855 if (tmp_sdev
->id
!= scsi_id
)
3857 depth
= scsi_track_queue_full(tmp_sdev
,
3858 tmp_sdev
->queue_depth
-1);
3861 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3862 "0711 detected queue full - lun queue "
3863 "depth adjusted to %d.\n", depth
);
3864 lpfc_send_sdev_queuedepth_change_event(phba
, vport
,
3872 * If there is a thread waiting for command completion
3873 * wake up the thread.
3875 spin_lock_irqsave(shost
->host_lock
, flags
);
3876 lpfc_cmd
->pCmd
= NULL
;
3877 if (lpfc_cmd
->waitq
)
3878 wake_up(lpfc_cmd
->waitq
);
3879 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3881 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3885 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
3886 * @data: A pointer to the immediate command data portion of the IOCB.
3887 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
3889 * The routine copies the entire FCP command from @fcp_cmnd to @data while
3890 * byte swapping the data to big endian format for transmission on the wire.
3893 lpfc_fcpcmd_to_iocb(uint8_t *data
, struct fcp_cmnd
*fcp_cmnd
)
3896 for (i
= 0, j
= 0; i
< sizeof(struct fcp_cmnd
);
3897 i
+= sizeof(uint32_t), j
++) {
3898 ((uint32_t *)data
)[j
] = cpu_to_be32(((uint32_t *)fcp_cmnd
)[j
]);
3903 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
3904 * @vport: The virtual port for which this call is being executed.
3905 * @lpfc_cmd: The scsi command which needs to send.
3906 * @pnode: Pointer to lpfc_nodelist.
3908 * This routine initializes fcp_cmnd and iocb data structure from scsi command
3909 * to transfer for device with SLI3 interface spec.
3912 lpfc_scsi_prep_cmnd(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
3913 struct lpfc_nodelist
*pnode
)
3915 struct lpfc_hba
*phba
= vport
->phba
;
3916 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3917 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3918 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3919 struct lpfc_iocbq
*piocbq
= &(lpfc_cmd
->cur_iocbq
);
3920 int datadir
= scsi_cmnd
->sc_data_direction
;
3923 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3926 lpfc_cmd
->fcp_rsp
->rspSnsLen
= 0;
3927 /* clear task management bits */
3928 lpfc_cmd
->fcp_cmnd
->fcpCntl2
= 0;
3930 int_to_scsilun(lpfc_cmd
->pCmd
->device
->lun
,
3931 &lpfc_cmd
->fcp_cmnd
->fcp_lun
);
3933 memset(&fcp_cmnd
->fcpCdb
[0], 0, LPFC_FCP_CDB_LEN
);
3934 memcpy(&fcp_cmnd
->fcpCdb
[0], scsi_cmnd
->cmnd
, scsi_cmnd
->cmd_len
);
3935 if (scsi_populate_tag_msg(scsi_cmnd
, tag
)) {
3937 case HEAD_OF_QUEUE_TAG
:
3938 fcp_cmnd
->fcpCntl1
= HEAD_OF_Q
;
3940 case ORDERED_QUEUE_TAG
:
3941 fcp_cmnd
->fcpCntl1
= ORDERED_Q
;
3944 fcp_cmnd
->fcpCntl1
= SIMPLE_Q
;
3948 fcp_cmnd
->fcpCntl1
= 0;
3951 * There are three possibilities here - use scatter-gather segment, use
3952 * the single mapping, or neither. Start the lpfc command prep by
3953 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3956 if (scsi_sg_count(scsi_cmnd
)) {
3957 if (datadir
== DMA_TO_DEVICE
) {
3958 iocb_cmd
->ulpCommand
= CMD_FCP_IWRITE64_CR
;
3959 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3960 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
3961 iocb_cmd
->ulpPU
= 0;
3963 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
3964 fcp_cmnd
->fcpCntl3
= WRITE_DATA
;
3965 phba
->fc4OutputRequests
++;
3967 iocb_cmd
->ulpCommand
= CMD_FCP_IREAD64_CR
;
3968 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
3969 fcp_cmnd
->fcpCntl3
= READ_DATA
;
3970 phba
->fc4InputRequests
++;
3973 iocb_cmd
->ulpCommand
= CMD_FCP_ICMND64_CR
;
3974 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
3975 iocb_cmd
->ulpPU
= 0;
3976 fcp_cmnd
->fcpCntl3
= 0;
3977 phba
->fc4ControlRequests
++;
3979 if (phba
->sli_rev
== 3 &&
3980 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
3981 lpfc_fcpcmd_to_iocb(iocb_cmd
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
3983 * Finish initializing those IOCB fields that are independent
3984 * of the scsi_cmnd request_buffer
3986 piocbq
->iocb
.ulpContext
= pnode
->nlp_rpi
;
3987 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3988 piocbq
->iocb
.ulpContext
=
3989 phba
->sli4_hba
.rpi_ids
[pnode
->nlp_rpi
];
3990 if (pnode
->nlp_fcp_info
& NLP_FCP_2_DEVICE
)
3991 piocbq
->iocb
.ulpFCP2Rcvy
= 1;
3993 piocbq
->iocb
.ulpFCP2Rcvy
= 0;
3995 piocbq
->iocb
.ulpClass
= (pnode
->nlp_fcp_info
& 0x0f);
3996 piocbq
->context1
= lpfc_cmd
;
3997 piocbq
->iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
3998 piocbq
->iocb
.ulpTimeout
= lpfc_cmd
->timeout
;
3999 piocbq
->vport
= vport
;
4003 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
4004 * @vport: The virtual port for which this call is being executed.
4005 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4006 * @lun: Logical unit number.
4007 * @task_mgmt_cmd: SCSI task management command.
4009 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4010 * for device with SLI-3 interface spec.
4017 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport
*vport
,
4018 struct lpfc_scsi_buf
*lpfc_cmd
,
4020 uint8_t task_mgmt_cmd
)
4022 struct lpfc_iocbq
*piocbq
;
4024 struct fcp_cmnd
*fcp_cmnd
;
4025 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
4026 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
4028 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) ||
4029 ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
4032 piocbq
= &(lpfc_cmd
->cur_iocbq
);
4033 piocbq
->vport
= vport
;
4035 piocb
= &piocbq
->iocb
;
4037 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4038 /* Clear out any old data in the FCP command area */
4039 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
4040 int_to_scsilun(lun
, &fcp_cmnd
->fcp_lun
);
4041 fcp_cmnd
->fcpCntl2
= task_mgmt_cmd
;
4042 if (vport
->phba
->sli_rev
== 3 &&
4043 !(vport
->phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
4044 lpfc_fcpcmd_to_iocb(piocb
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
4045 piocb
->ulpCommand
= CMD_FCP_ICMND64_CR
;
4046 piocb
->ulpContext
= ndlp
->nlp_rpi
;
4047 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4049 vport
->phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
4051 if (ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) {
4052 piocb
->ulpFCP2Rcvy
= 1;
4054 piocb
->ulpClass
= (ndlp
->nlp_fcp_info
& 0x0f);
4056 /* ulpTimeout is only one byte */
4057 if (lpfc_cmd
->timeout
> 0xff) {
4059 * Do not timeout the command at the firmware level.
4060 * The driver will provide the timeout mechanism.
4062 piocb
->ulpTimeout
= 0;
4064 piocb
->ulpTimeout
= lpfc_cmd
->timeout
;
4066 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
4067 lpfc_sli4_set_rsp_sgl_last(vport
->phba
, lpfc_cmd
);
4073 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4074 * @phba: The hba struct for which this call is being executed.
4075 * @dev_grp: The HBA PCI-Device group number.
4077 * This routine sets up the SCSI interface API function jump table in @phba
4079 * Returns: 0 - success, -ENODEV - failure.
4082 lpfc_scsi_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4085 phba
->lpfc_scsi_unprep_dma_buf
= lpfc_scsi_unprep_dma_buf
;
4086 phba
->lpfc_scsi_prep_cmnd
= lpfc_scsi_prep_cmnd
;
4089 case LPFC_PCI_DEV_LP
:
4090 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s3
;
4091 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s3
;
4092 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s3
;
4093 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s3
;
4094 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s3
;
4096 case LPFC_PCI_DEV_OC
:
4097 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s4
;
4098 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s4
;
4099 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s4
;
4100 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s4
;
4101 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s4
;
4104 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4105 "1418 Invalid HBA PCI-device group: 0x%x\n",
4110 phba
->lpfc_rampdown_queue_depth
= lpfc_rampdown_queue_depth
;
4111 phba
->lpfc_scsi_cmd_iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
4116 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4117 * @phba: The Hba for which this call is being executed.
4118 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4119 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4121 * This routine is IOCB completion routine for device reset and target reset
4122 * routine. This routine release scsi buffer associated with lpfc_cmd.
4125 lpfc_tskmgmt_def_cmpl(struct lpfc_hba
*phba
,
4126 struct lpfc_iocbq
*cmdiocbq
,
4127 struct lpfc_iocbq
*rspiocbq
)
4129 struct lpfc_scsi_buf
*lpfc_cmd
=
4130 (struct lpfc_scsi_buf
*) cmdiocbq
->context1
;
4132 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4137 * lpfc_info - Info entry point of scsi_host_template data structure
4138 * @host: The scsi host for which this call is being executed.
4140 * This routine provides module information about hba.
4143 * Pointer to char - Success.
4146 lpfc_info(struct Scsi_Host
*host
)
4148 struct lpfc_vport
*vport
= (struct lpfc_vport
*) host
->hostdata
;
4149 struct lpfc_hba
*phba
= vport
->phba
;
4151 static char lpfcinfobuf
[384];
4153 memset(lpfcinfobuf
,0,384);
4154 if (phba
&& phba
->pcidev
){
4155 strncpy(lpfcinfobuf
, phba
->ModelDesc
, 256);
4156 len
= strlen(lpfcinfobuf
);
4157 snprintf(lpfcinfobuf
+ len
,
4159 " on PCI bus %02x device %02x irq %d",
4160 phba
->pcidev
->bus
->number
,
4161 phba
->pcidev
->devfn
,
4163 len
= strlen(lpfcinfobuf
);
4164 if (phba
->Port
[0]) {
4165 snprintf(lpfcinfobuf
+ len
,
4170 len
= strlen(lpfcinfobuf
);
4171 if (phba
->sli4_hba
.link_state
.logical_speed
) {
4172 snprintf(lpfcinfobuf
+ len
,
4174 " Logical Link Speed: %d Mbps",
4175 phba
->sli4_hba
.link_state
.logical_speed
* 10);
4182 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4183 * @phba: The Hba for which this call is being executed.
4185 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4186 * The default value of cfg_poll_tmo is 10 milliseconds.
4188 static __inline__
void lpfc_poll_rearm_timer(struct lpfc_hba
* phba
)
4190 unsigned long poll_tmo_expires
=
4191 (jiffies
+ msecs_to_jiffies(phba
->cfg_poll_tmo
));
4193 if (phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
)
4194 mod_timer(&phba
->fcp_poll_timer
,
4199 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4200 * @phba: The Hba for which this call is being executed.
4202 * This routine starts the fcp_poll_timer of @phba.
4204 void lpfc_poll_start_timer(struct lpfc_hba
* phba
)
4206 lpfc_poll_rearm_timer(phba
);
4210 * lpfc_poll_timeout - Restart polling timer
4211 * @ptr: Map to lpfc_hba data structure pointer.
4213 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4214 * and FCP Ring interrupt is disable.
4217 void lpfc_poll_timeout(unsigned long ptr
)
4219 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4221 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4222 lpfc_sli_handle_fast_ring_event(phba
,
4223 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4225 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4226 lpfc_poll_rearm_timer(phba
);
4231 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4232 * @cmnd: Pointer to scsi_cmnd data structure.
4233 * @done: Pointer to done routine.
4235 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4236 * This routine prepares an IOCB from scsi command and provides to firmware.
4237 * The @done callback is invoked after driver finished processing the command.
4241 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4244 lpfc_queuecommand_lck(struct scsi_cmnd
*cmnd
, void (*done
) (struct scsi_cmnd
*))
4246 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4247 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4248 struct lpfc_hba
*phba
= vport
->phba
;
4249 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4250 struct lpfc_nodelist
*ndlp
;
4251 struct lpfc_scsi_buf
*lpfc_cmd
;
4252 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
4255 err
= fc_remote_port_chkready(rport
);
4258 goto out_fail_command
;
4260 ndlp
= rdata
->pnode
;
4262 if ((scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) &&
4263 (!(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))) {
4265 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4266 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4267 " op:%02x str=%s without registering for"
4268 " BlockGuard - Rejecting command\n",
4269 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
4270 dif_op_str
[scsi_get_prot_op(cmnd
)]);
4271 goto out_fail_command
;
4275 * Catch race where our node has transitioned, but the
4276 * transport is still transitioning.
4278 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
4279 cmnd
->result
= ScsiResult(DID_IMM_RETRY
, 0);
4280 goto out_fail_command
;
4282 if (atomic_read(&ndlp
->cmd_pending
) >= ndlp
->cmd_qdepth
)
4285 lpfc_cmd
= lpfc_get_scsi_buf(phba
, ndlp
);
4286 if (lpfc_cmd
== NULL
) {
4287 lpfc_rampdown_queue_depth(phba
);
4289 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4290 "0707 driver's buffer pool is empty, "
4296 * Store the midlayer's command structure for the completion phase
4297 * and complete the command initialization.
4299 lpfc_cmd
->pCmd
= cmnd
;
4300 lpfc_cmd
->rdata
= rdata
;
4301 lpfc_cmd
->timeout
= 0;
4302 lpfc_cmd
->start_time
= jiffies
;
4303 cmnd
->host_scribble
= (unsigned char *)lpfc_cmd
;
4304 cmnd
->scsi_done
= done
;
4306 if (scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) {
4307 if (vport
->phba
->cfg_enable_bg
) {
4308 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4309 "9033 BLKGRD: rcvd protected cmd:%02x op=%s "
4310 "guard=%s\n", cmnd
->cmnd
[0],
4311 dif_op_str
[scsi_get_prot_op(cmnd
)],
4312 dif_grd_str
[scsi_host_get_guard(shost
)]);
4313 if (cmnd
->cmnd
[0] == READ_10
)
4314 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4315 "9035 BLKGRD: READ @ sector %llu, "
4317 (unsigned long long)scsi_get_lba(cmnd
),
4318 blk_rq_sectors(cmnd
->request
),
4319 (cmnd
->cmnd
[1]>>5));
4320 else if (cmnd
->cmnd
[0] == WRITE_10
)
4321 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4322 "9036 BLKGRD: WRITE @ sector %llu, "
4324 (unsigned long long)scsi_get_lba(cmnd
),
4325 blk_rq_sectors(cmnd
->request
),
4326 (cmnd
->cmnd
[1]>>5));
4329 err
= lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4331 if (vport
->phba
->cfg_enable_bg
) {
4332 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4333 "9038 BLKGRD: rcvd unprotected cmd:"
4334 "%02x op=%s guard=%s\n", cmnd
->cmnd
[0],
4335 dif_op_str
[scsi_get_prot_op(cmnd
)],
4336 dif_grd_str
[scsi_host_get_guard(shost
)]);
4337 if (cmnd
->cmnd
[0] == READ_10
)
4338 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4339 "9040 dbg: READ @ sector %llu, "
4341 (unsigned long long)scsi_get_lba(cmnd
),
4342 blk_rq_sectors(cmnd
->request
),
4343 (cmnd
->cmnd
[1]>>5));
4344 else if (cmnd
->cmnd
[0] == WRITE_10
)
4345 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4346 "9041 dbg: WRITE @ sector %llu, "
4348 (unsigned long long)scsi_get_lba(cmnd
),
4349 blk_rq_sectors(cmnd
->request
),
4350 (cmnd
->cmnd
[1]>>5));
4352 err
= lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4356 goto out_host_busy_free_buf
;
4358 lpfc_scsi_prep_cmnd(vport
, lpfc_cmd
, ndlp
);
4360 atomic_inc(&ndlp
->cmd_pending
);
4361 err
= lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
,
4362 &lpfc_cmd
->cur_iocbq
, SLI_IOCB_RET_IOCB
);
4364 atomic_dec(&ndlp
->cmd_pending
);
4365 goto out_host_busy_free_buf
;
4367 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4368 spin_unlock(shost
->host_lock
);
4369 lpfc_sli_handle_fast_ring_event(phba
,
4370 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4372 spin_lock(shost
->host_lock
);
4373 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4374 lpfc_poll_rearm_timer(phba
);
4379 out_host_busy_free_buf
:
4380 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
4381 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4383 return SCSI_MLQUEUE_HOST_BUSY
;
4386 return SCSI_MLQUEUE_TARGET_BUSY
;
4393 static DEF_SCSI_QCMD(lpfc_queuecommand
)
4396 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4397 * @cmnd: Pointer to scsi_cmnd data structure.
4399 * This routine aborts @cmnd pending in base driver.
4406 lpfc_abort_handler(struct scsi_cmnd
*cmnd
)
4408 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4409 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4410 struct lpfc_hba
*phba
= vport
->phba
;
4411 struct lpfc_iocbq
*iocb
;
4412 struct lpfc_iocbq
*abtsiocb
;
4413 struct lpfc_scsi_buf
*lpfc_cmd
;
4416 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq
);
4418 ret
= fc_block_scsi_eh(cmnd
);
4422 spin_lock_irq(&phba
->hbalock
);
4423 /* driver queued commands are in process of being flushed */
4424 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
4425 spin_unlock_irq(&phba
->hbalock
);
4426 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4427 "3168 SCSI Layer abort requested I/O has been "
4428 "flushed by LLD.\n");
4432 lpfc_cmd
= (struct lpfc_scsi_buf
*)cmnd
->host_scribble
;
4434 spin_unlock_irq(&phba
->hbalock
);
4435 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4436 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4437 "x%x ID %d LUN %d\n",
4438 ret
, cmnd
->device
->id
, cmnd
->device
->lun
);
4442 iocb
= &lpfc_cmd
->cur_iocbq
;
4443 /* the command is in process of being cancelled */
4444 if (!(iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
)) {
4445 spin_unlock_irq(&phba
->hbalock
);
4446 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4447 "3169 SCSI Layer abort requested I/O has been "
4448 "cancelled by LLD.\n");
4452 * If pCmd field of the corresponding lpfc_scsi_buf structure
4453 * points to a different SCSI command, then the driver has
4454 * already completed this command, but the midlayer did not
4455 * see the completion before the eh fired. Just return SUCCESS.
4457 if (lpfc_cmd
->pCmd
!= cmnd
) {
4458 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4459 "3170 SCSI Layer abort requested I/O has been "
4460 "completed by LLD.\n");
4464 BUG_ON(iocb
->context1
!= lpfc_cmd
);
4466 abtsiocb
= __lpfc_sli_get_iocbq(phba
);
4467 if (abtsiocb
== NULL
) {
4473 * The scsi command can not be in txq and it is in flight because the
4474 * pCmd is still pointig at the SCSI command we have to abort. There
4475 * is no need to search the txcmplq. Just send an abort to the FW.
4479 icmd
= &abtsiocb
->iocb
;
4480 icmd
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
4481 icmd
->un
.acxri
.abortContextTag
= cmd
->ulpContext
;
4482 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4483 icmd
->un
.acxri
.abortIoTag
= iocb
->sli4_xritag
;
4485 icmd
->un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
4488 icmd
->ulpClass
= cmd
->ulpClass
;
4490 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4491 abtsiocb
->fcp_wqidx
= iocb
->fcp_wqidx
;
4492 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
4494 if (lpfc_is_link_up(phba
))
4495 icmd
->ulpCommand
= CMD_ABORT_XRI_CN
;
4497 icmd
->ulpCommand
= CMD_CLOSE_XRI_CN
;
4499 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
4500 abtsiocb
->vport
= vport
;
4501 /* no longer need the lock after this point */
4502 spin_unlock_irq(&phba
->hbalock
);
4504 if (lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
, abtsiocb
, 0) ==
4506 lpfc_sli_release_iocbq(phba
, abtsiocb
);
4511 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4512 lpfc_sli_handle_fast_ring_event(phba
,
4513 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4515 lpfc_cmd
->waitq
= &waitq
;
4516 /* Wait for abort to complete */
4517 wait_event_timeout(waitq
,
4518 (lpfc_cmd
->pCmd
!= cmnd
),
4519 (2*vport
->cfg_devloss_tmo
*HZ
));
4520 lpfc_cmd
->waitq
= NULL
;
4522 if (lpfc_cmd
->pCmd
== cmnd
) {
4524 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4525 "0748 abort handler timed out waiting "
4526 "for abort to complete: ret %#x, ID %d, "
4528 ret
, cmnd
->device
->id
, cmnd
->device
->lun
);
4533 spin_unlock_irq(&phba
->hbalock
);
4535 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4536 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4537 "LUN %d\n", ret
, cmnd
->device
->id
,
4543 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd
)
4545 switch (task_mgmt_cmd
) {
4546 case FCP_ABORT_TASK_SET
:
4547 return "ABORT_TASK_SET";
4548 case FCP_CLEAR_TASK_SET
:
4549 return "FCP_CLEAR_TASK_SET";
4551 return "FCP_BUS_RESET";
4553 return "FCP_LUN_RESET";
4554 case FCP_TARGET_RESET
:
4555 return "FCP_TARGET_RESET";
4557 return "FCP_CLEAR_ACA";
4558 case FCP_TERMINATE_TASK
:
4559 return "FCP_TERMINATE_TASK";
4566 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4567 * @vport: The virtual port for which this call is being executed.
4568 * @rdata: Pointer to remote port local data
4569 * @tgt_id: Target ID of remote device.
4570 * @lun_id: Lun number for the TMF
4571 * @task_mgmt_cmd: type of TMF to send
4573 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4581 lpfc_send_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_rport_data
*rdata
,
4582 unsigned tgt_id
, unsigned int lun_id
,
4583 uint8_t task_mgmt_cmd
)
4585 struct lpfc_hba
*phba
= vport
->phba
;
4586 struct lpfc_scsi_buf
*lpfc_cmd
;
4587 struct lpfc_iocbq
*iocbq
;
4588 struct lpfc_iocbq
*iocbqrsp
;
4589 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
4593 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
4596 lpfc_cmd
= lpfc_get_scsi_buf(phba
, rdata
->pnode
);
4597 if (lpfc_cmd
== NULL
)
4599 lpfc_cmd
->timeout
= 60;
4600 lpfc_cmd
->rdata
= rdata
;
4602 status
= lpfc_scsi_prep_task_mgmt_cmd(vport
, lpfc_cmd
, lun_id
,
4605 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4609 iocbq
= &lpfc_cmd
->cur_iocbq
;
4610 iocbqrsp
= lpfc_sli_get_iocbq(phba
);
4611 if (iocbqrsp
== NULL
) {
4612 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4616 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4617 "0702 Issue %s to TGT %d LUN %d "
4618 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
4619 lpfc_taskmgmt_name(task_mgmt_cmd
), tgt_id
, lun_id
,
4620 pnode
->nlp_rpi
, pnode
->nlp_flag
, iocbq
->sli4_xritag
,
4623 status
= lpfc_sli_issue_iocb_wait(phba
, LPFC_FCP_RING
,
4624 iocbq
, iocbqrsp
, lpfc_cmd
->timeout
);
4625 if (status
!= IOCB_SUCCESS
) {
4626 if (status
== IOCB_TIMEDOUT
) {
4627 iocbq
->iocb_cmpl
= lpfc_tskmgmt_def_cmpl
;
4628 ret
= TIMEOUT_ERROR
;
4631 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
4632 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4633 "0727 TMF %s to TGT %d LUN %d failed (%d, %d) "
4635 lpfc_taskmgmt_name(task_mgmt_cmd
),
4636 tgt_id
, lun_id
, iocbqrsp
->iocb
.ulpStatus
,
4637 iocbqrsp
->iocb
.un
.ulpWord
[4],
4639 } else if (status
== IOCB_BUSY
)
4644 lpfc_sli_release_iocbq(phba
, iocbqrsp
);
4646 if (ret
!= TIMEOUT_ERROR
)
4647 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4653 * lpfc_chk_tgt_mapped -
4654 * @vport: The virtual port to check on
4655 * @cmnd: Pointer to scsi_cmnd data structure.
4657 * This routine delays until the scsi target (aka rport) for the
4658 * command exists (is present and logged in) or we declare it non-existent.
4665 lpfc_chk_tgt_mapped(struct lpfc_vport
*vport
, struct scsi_cmnd
*cmnd
)
4667 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4668 struct lpfc_nodelist
*pnode
;
4669 unsigned long later
;
4672 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4673 "0797 Tgt Map rport failure: rdata x%p\n", rdata
);
4676 pnode
= rdata
->pnode
;
4678 * If target is not in a MAPPED state, delay until
4679 * target is rediscovered or devloss timeout expires.
4681 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
4682 while (time_after(later
, jiffies
)) {
4683 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
4685 if (pnode
->nlp_state
== NLP_STE_MAPPED_NODE
)
4687 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
4688 rdata
= cmnd
->device
->hostdata
;
4691 pnode
= rdata
->pnode
;
4693 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
) ||
4694 (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4700 * lpfc_reset_flush_io_context -
4701 * @vport: The virtual port (scsi_host) for the flush context
4702 * @tgt_id: If aborting by Target contect - specifies the target id
4703 * @lun_id: If aborting by Lun context - specifies the lun id
4704 * @context: specifies the context level to flush at.
4706 * After a reset condition via TMF, we need to flush orphaned i/o
4707 * contexts from the adapter. This routine aborts any contexts
4708 * outstanding, then waits for their completions. The wait is
4709 * bounded by devloss_tmo though.
4716 lpfc_reset_flush_io_context(struct lpfc_vport
*vport
, uint16_t tgt_id
,
4717 uint64_t lun_id
, lpfc_ctx_cmd context
)
4719 struct lpfc_hba
*phba
= vport
->phba
;
4720 unsigned long later
;
4723 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
4725 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
4726 tgt_id
, lun_id
, context
);
4727 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
4728 while (time_after(later
, jiffies
) && cnt
) {
4729 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
4730 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
4733 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4734 "0724 I/O flush failure for context %s : cnt x%x\n",
4735 ((context
== LPFC_CTX_LUN
) ? "LUN" :
4736 ((context
== LPFC_CTX_TGT
) ? "TGT" :
4737 ((context
== LPFC_CTX_HOST
) ? "HOST" : "Unknown"))),
4745 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
4746 * @cmnd: Pointer to scsi_cmnd data structure.
4748 * This routine does a device reset by sending a LUN_RESET task management
4756 lpfc_device_reset_handler(struct scsi_cmnd
*cmnd
)
4758 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4759 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4760 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4761 struct lpfc_nodelist
*pnode
;
4762 unsigned tgt_id
= cmnd
->device
->id
;
4763 unsigned int lun_id
= cmnd
->device
->lun
;
4764 struct lpfc_scsi_event_header scsi_event
;
4768 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4769 "0798 Device Reset rport failure: rdata x%p\n", rdata
);
4772 pnode
= rdata
->pnode
;
4773 status
= fc_block_scsi_eh(cmnd
);
4777 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
4778 if (status
== FAILED
) {
4779 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4780 "0721 Device Reset rport failure: rdata x%p\n", rdata
);
4784 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4785 scsi_event
.subcategory
= LPFC_EVENT_LUNRESET
;
4786 scsi_event
.lun
= lun_id
;
4787 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
4788 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
4790 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4791 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4793 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
4796 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4797 "0713 SCSI layer issued Device Reset (%d, %d) "
4798 "return x%x\n", tgt_id
, lun_id
, status
);
4801 * We have to clean up i/o as : they may be orphaned by the TMF;
4802 * or if the TMF failed, they may be in an indeterminate state.
4804 * We will report success if all the i/o aborts successfully.
4806 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
4812 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
4813 * @cmnd: Pointer to scsi_cmnd data structure.
4815 * This routine does a target reset by sending a TARGET_RESET task management
4823 lpfc_target_reset_handler(struct scsi_cmnd
*cmnd
)
4825 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4826 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4827 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4828 struct lpfc_nodelist
*pnode
;
4829 unsigned tgt_id
= cmnd
->device
->id
;
4830 unsigned int lun_id
= cmnd
->device
->lun
;
4831 struct lpfc_scsi_event_header scsi_event
;
4835 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4836 "0799 Target Reset rport failure: rdata x%p\n", rdata
);
4839 pnode
= rdata
->pnode
;
4840 status
= fc_block_scsi_eh(cmnd
);
4844 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
4845 if (status
== FAILED
) {
4846 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4847 "0722 Target Reset rport failure: rdata x%p\n", rdata
);
4851 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4852 scsi_event
.subcategory
= LPFC_EVENT_TGTRESET
;
4854 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
4855 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
4857 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4858 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4860 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
4863 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4864 "0723 SCSI layer issued Target Reset (%d, %d) "
4865 "return x%x\n", tgt_id
, lun_id
, status
);
4868 * We have to clean up i/o as : they may be orphaned by the TMF;
4869 * or if the TMF failed, they may be in an indeterminate state.
4871 * We will report success if all the i/o aborts successfully.
4873 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
4879 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
4880 * @cmnd: Pointer to scsi_cmnd data structure.
4882 * This routine does target reset to all targets on @cmnd->device->host.
4883 * This emulates Parallel SCSI Bus Reset Semantics.
4890 lpfc_bus_reset_handler(struct scsi_cmnd
*cmnd
)
4892 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4893 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4894 struct lpfc_nodelist
*ndlp
= NULL
;
4895 struct lpfc_scsi_event_header scsi_event
;
4897 int ret
= SUCCESS
, status
, i
;
4899 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4900 scsi_event
.subcategory
= LPFC_EVENT_BUSRESET
;
4902 memcpy(scsi_event
.wwpn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4903 memcpy(scsi_event
.wwnn
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4905 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4906 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4908 status
= fc_block_scsi_eh(cmnd
);
4913 * Since the driver manages a single bus device, reset all
4914 * targets known to the driver. Should any target reset
4915 * fail, this routine returns failure to the midlayer.
4917 for (i
= 0; i
< LPFC_MAX_TARGET
; i
++) {
4918 /* Search for mapped node by target ID */
4920 spin_lock_irq(shost
->host_lock
);
4921 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4922 if (!NLP_CHK_NODE_ACT(ndlp
))
4924 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
4925 ndlp
->nlp_sid
== i
&&
4931 spin_unlock_irq(shost
->host_lock
);
4935 status
= lpfc_send_taskmgmt(vport
, ndlp
->rport
->dd_data
,
4936 i
, 0, FCP_TARGET_RESET
);
4938 if (status
!= SUCCESS
) {
4939 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4940 "0700 Bus Reset on target %d failed\n",
4946 * We have to clean up i/o as : they may be orphaned by the TMFs
4947 * above; or if any of the TMFs failed, they may be in an
4948 * indeterminate state.
4949 * We will report success if all the i/o aborts successfully.
4952 status
= lpfc_reset_flush_io_context(vport
, 0, 0, LPFC_CTX_HOST
);
4953 if (status
!= SUCCESS
)
4956 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4957 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret
);
4962 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
4963 * @cmnd: Pointer to scsi_cmnd data structure.
4965 * This routine does host reset to the adaptor port. It brings the HBA
4966 * offline, performs a board restart, and then brings the board back online.
4967 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
4968 * reject all outstanding SCSI commands to the host and error returned
4969 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
4970 * of error handling, it will only return error if resetting of the adapter
4971 * is not successful; in all other cases, will return success.
4978 lpfc_host_reset_handler(struct scsi_cmnd
*cmnd
)
4980 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4981 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4982 struct lpfc_hba
*phba
= vport
->phba
;
4983 int rc
, ret
= SUCCESS
;
4985 lpfc_offline_prep(phba
);
4987 rc
= lpfc_sli_brdrestart(phba
);
4991 lpfc_unblock_mgmt_io(phba
);
4993 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
4994 "3172 SCSI layer issued Host Reset Data: x%x\n", ret
);
4999 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
5000 * @sdev: Pointer to scsi_device.
5002 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
5003 * globally available list of scsi buffers. This routine also makes sure scsi
5004 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
5005 * of scsi buffer exists for the lifetime of the driver.
5012 lpfc_slave_alloc(struct scsi_device
*sdev
)
5014 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5015 struct lpfc_hba
*phba
= vport
->phba
;
5016 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
5018 uint32_t num_to_alloc
= 0;
5019 int num_allocated
= 0;
5022 if (!rport
|| fc_remote_port_chkready(rport
))
5025 sdev
->hostdata
= rport
->dd_data
;
5026 sdev_cnt
= atomic_inc_return(&phba
->sdev_cnt
);
5029 * Populate the cmds_per_lun count scsi_bufs into this host's globally
5030 * available list of scsi buffers. Don't allocate more than the
5031 * HBA limit conveyed to the midlayer via the host structure. The
5032 * formula accounts for the lun_queue_depth + error handlers + 1
5033 * extra. This list of scsi bufs exists for the lifetime of the driver.
5035 total
= phba
->total_scsi_bufs
;
5036 num_to_alloc
= vport
->cfg_lun_queue_depth
+ 2;
5038 /* If allocated buffers are enough do nothing */
5039 if ((sdev_cnt
* (vport
->cfg_lun_queue_depth
+ 2)) < total
)
5042 /* Allow some exchanges to be available always to complete discovery */
5043 if (total
>= phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
5044 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5045 "0704 At limitation of %d preallocated "
5046 "command buffers\n", total
);
5048 /* Allow some exchanges to be available always to complete discovery */
5049 } else if (total
+ num_to_alloc
>
5050 phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
5051 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5052 "0705 Allocation request of %d "
5053 "command buffers will exceed max of %d. "
5054 "Reducing allocation request to %d.\n",
5055 num_to_alloc
, phba
->cfg_hba_queue_depth
,
5056 (phba
->cfg_hba_queue_depth
- total
));
5057 num_to_alloc
= phba
->cfg_hba_queue_depth
- total
;
5059 num_allocated
= lpfc_new_scsi_buf(vport
, num_to_alloc
);
5060 if (num_to_alloc
!= num_allocated
) {
5061 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5062 "0708 Allocation request of %d "
5063 "command buffers did not succeed. "
5064 "Allocated %d buffers.\n",
5065 num_to_alloc
, num_allocated
);
5067 if (num_allocated
> 0)
5068 phba
->total_scsi_bufs
+= num_allocated
;
5073 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5074 * @sdev: Pointer to scsi_device.
5076 * This routine configures following items
5077 * - Tag command queuing support for @sdev if supported.
5078 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5084 lpfc_slave_configure(struct scsi_device
*sdev
)
5086 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5087 struct lpfc_hba
*phba
= vport
->phba
;
5089 if (sdev
->tagged_supported
)
5090 scsi_activate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
5092 scsi_deactivate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
5094 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
5095 lpfc_sli_handle_fast_ring_event(phba
,
5096 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
5097 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
5098 lpfc_poll_rearm_timer(phba
);
5105 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5106 * @sdev: Pointer to scsi_device.
5108 * This routine sets @sdev hostatdata filed to null.
5111 lpfc_slave_destroy(struct scsi_device
*sdev
)
5113 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5114 struct lpfc_hba
*phba
= vport
->phba
;
5115 atomic_dec(&phba
->sdev_cnt
);
5116 sdev
->hostdata
= NULL
;
5121 struct scsi_host_template lpfc_template
= {
5122 .module
= THIS_MODULE
,
5123 .name
= LPFC_DRIVER_NAME
,
5125 .queuecommand
= lpfc_queuecommand
,
5126 .eh_abort_handler
= lpfc_abort_handler
,
5127 .eh_device_reset_handler
= lpfc_device_reset_handler
,
5128 .eh_target_reset_handler
= lpfc_target_reset_handler
,
5129 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
5130 .eh_host_reset_handler
= lpfc_host_reset_handler
,
5131 .slave_alloc
= lpfc_slave_alloc
,
5132 .slave_configure
= lpfc_slave_configure
,
5133 .slave_destroy
= lpfc_slave_destroy
,
5134 .scan_finished
= lpfc_scan_finished
,
5136 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
5137 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
5138 .use_clustering
= ENABLE_CLUSTERING
,
5139 .shost_attrs
= lpfc_hba_attrs
,
5140 .max_sectors
= 0xFFFF,
5141 .vendor_id
= LPFC_NL_VENDOR_ID
,
5142 .change_queue_depth
= lpfc_change_queue_depth
,
5145 struct scsi_host_template lpfc_vport_template
= {
5146 .module
= THIS_MODULE
,
5147 .name
= LPFC_DRIVER_NAME
,
5149 .queuecommand
= lpfc_queuecommand
,
5150 .eh_abort_handler
= lpfc_abort_handler
,
5151 .eh_device_reset_handler
= lpfc_device_reset_handler
,
5152 .eh_target_reset_handler
= lpfc_target_reset_handler
,
5153 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
5154 .slave_alloc
= lpfc_slave_alloc
,
5155 .slave_configure
= lpfc_slave_configure
,
5156 .slave_destroy
= lpfc_slave_destroy
,
5157 .scan_finished
= lpfc_scan_finished
,
5159 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
5160 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
5161 .use_clustering
= ENABLE_CLUSTERING
,
5162 .shost_attrs
= lpfc_vport_attrs
,
5163 .max_sectors
= 0xFFFF,
5164 .change_queue_depth
= lpfc_change_queue_depth
,