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
);
402 vports
= lpfc_create_vport_work_array(phba
);
404 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
405 shost
= lpfc_shost_from_vport(vports
[i
]);
406 shost_for_each_device(sdev
, shost
) {
408 sdev
->queue_depth
* num_rsrc_err
/
409 (num_rsrc_err
+ num_cmd_success
);
410 if (!new_queue_depth
)
411 new_queue_depth
= sdev
->queue_depth
- 1;
413 new_queue_depth
= sdev
->queue_depth
-
415 lpfc_change_queue_depth(sdev
, new_queue_depth
,
416 SCSI_QDEPTH_DEFAULT
);
419 lpfc_destroy_vport_work_array(phba
, vports
);
420 atomic_set(&phba
->num_rsrc_err
, 0);
421 atomic_set(&phba
->num_cmd_success
, 0);
425 * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler
426 * @phba: The Hba for which this call is being executed.
428 * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker
429 * thread.This routine increases queue depth for all scsi device on each vport
430 * associated with @phba by 1. This routine also sets @phba num_rsrc_err and
431 * num_cmd_success to zero.
434 lpfc_ramp_up_queue_handler(struct lpfc_hba
*phba
)
436 struct lpfc_vport
**vports
;
437 struct Scsi_Host
*shost
;
438 struct scsi_device
*sdev
;
441 vports
= lpfc_create_vport_work_array(phba
);
443 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
444 shost
= lpfc_shost_from_vport(vports
[i
]);
445 shost_for_each_device(sdev
, shost
) {
446 if (vports
[i
]->cfg_lun_queue_depth
<=
449 lpfc_change_queue_depth(sdev
,
451 SCSI_QDEPTH_RAMP_UP
);
454 lpfc_destroy_vport_work_array(phba
, vports
);
455 atomic_set(&phba
->num_rsrc_err
, 0);
456 atomic_set(&phba
->num_cmd_success
, 0);
460 * lpfc_scsi_dev_block - set all scsi hosts to block state
461 * @phba: Pointer to HBA context object.
463 * This function walks vport list and set each SCSI host to block state
464 * by invoking fc_remote_port_delete() routine. This function is invoked
465 * with EEH when device's PCI slot has been permanently disabled.
468 lpfc_scsi_dev_block(struct lpfc_hba
*phba
)
470 struct lpfc_vport
**vports
;
471 struct Scsi_Host
*shost
;
472 struct scsi_device
*sdev
;
473 struct fc_rport
*rport
;
476 vports
= lpfc_create_vport_work_array(phba
);
478 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
479 shost
= lpfc_shost_from_vport(vports
[i
]);
480 shost_for_each_device(sdev
, shost
) {
481 rport
= starget_to_rport(scsi_target(sdev
));
482 fc_remote_port_delete(rport
);
485 lpfc_destroy_vport_work_array(phba
, vports
);
489 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
490 * @vport: The virtual port for which this call being executed.
491 * @num_to_allocate: The requested number of buffers to allocate.
493 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
494 * the scsi buffer contains all the necessary information needed to initiate
495 * a SCSI I/O. The non-DMAable buffer region contains information to build
496 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
497 * and the initial BPL. In addition to allocating memory, the FCP CMND and
498 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
501 * int - number of scsi buffers that were allocated.
502 * 0 = failure, less than num_to_alloc is a partial failure.
505 lpfc_new_scsi_buf_s3(struct lpfc_vport
*vport
, int num_to_alloc
)
507 struct lpfc_hba
*phba
= vport
->phba
;
508 struct lpfc_scsi_buf
*psb
;
509 struct ulp_bde64
*bpl
;
511 dma_addr_t pdma_phys_fcp_cmd
;
512 dma_addr_t pdma_phys_fcp_rsp
;
513 dma_addr_t pdma_phys_bpl
;
517 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
518 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
523 * Get memory from the pci pool to map the virt space to pci
524 * bus space for an I/O. The DMA buffer includes space for the
525 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
526 * necessary to support the sg_tablesize.
528 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
529 GFP_KERNEL
, &psb
->dma_handle
);
535 /* Initialize virtual ptrs to dma_buf region. */
536 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
538 /* Allocate iotag for psb->cur_iocbq. */
539 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
541 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
542 psb
->data
, psb
->dma_handle
);
546 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
548 psb
->fcp_cmnd
= psb
->data
;
549 psb
->fcp_rsp
= psb
->data
+ sizeof(struct fcp_cmnd
);
550 psb
->fcp_bpl
= psb
->data
+ sizeof(struct fcp_cmnd
) +
551 sizeof(struct fcp_rsp
);
553 /* Initialize local short-hand pointers. */
555 pdma_phys_fcp_cmd
= psb
->dma_handle
;
556 pdma_phys_fcp_rsp
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
);
557 pdma_phys_bpl
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
) +
558 sizeof(struct fcp_rsp
);
561 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
562 * are sg list bdes. Initialize the first two and leave the
563 * rest for queuecommand.
565 bpl
[0].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd
));
566 bpl
[0].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd
));
567 bpl
[0].tus
.f
.bdeSize
= sizeof(struct fcp_cmnd
);
568 bpl
[0].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
569 bpl
[0].tus
.w
= le32_to_cpu(bpl
[0].tus
.w
);
571 /* Setup the physical region for the FCP RSP */
572 bpl
[1].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp
));
573 bpl
[1].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp
));
574 bpl
[1].tus
.f
.bdeSize
= sizeof(struct fcp_rsp
);
575 bpl
[1].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
576 bpl
[1].tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
579 * Since the IOCB for the FCP I/O is built into this
580 * lpfc_scsi_buf, initialize it with all known data now.
582 iocb
= &psb
->cur_iocbq
.iocb
;
583 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
584 if ((phba
->sli_rev
== 3) &&
585 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)) {
586 /* fill in immediate fcp command BDE */
587 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_IMMED
;
588 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
589 iocb
->un
.fcpi64
.bdl
.addrLow
= offsetof(IOCB_t
,
591 iocb
->un
.fcpi64
.bdl
.addrHigh
= 0;
592 iocb
->ulpBdeCount
= 0;
594 /* fill in response BDE */
595 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeFlags
=
597 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeSize
=
598 sizeof(struct fcp_rsp
);
599 iocb
->unsli3
.fcp_ext
.rbde
.addrLow
=
600 putPaddrLow(pdma_phys_fcp_rsp
);
601 iocb
->unsli3
.fcp_ext
.rbde
.addrHigh
=
602 putPaddrHigh(pdma_phys_fcp_rsp
);
604 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
605 iocb
->un
.fcpi64
.bdl
.bdeSize
=
606 (2 * sizeof(struct ulp_bde64
));
607 iocb
->un
.fcpi64
.bdl
.addrLow
=
608 putPaddrLow(pdma_phys_bpl
);
609 iocb
->un
.fcpi64
.bdl
.addrHigh
=
610 putPaddrHigh(pdma_phys_bpl
);
611 iocb
->ulpBdeCount
= 1;
614 iocb
->ulpClass
= CLASS3
;
615 psb
->status
= IOSTAT_SUCCESS
;
616 /* Put it back into the SCSI buffer list */
617 psb
->cur_iocbq
.context1
= psb
;
618 lpfc_release_scsi_buf_s3(phba
, psb
);
626 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
627 * @vport: pointer to lpfc vport data structure.
629 * This routine is invoked by the vport cleanup for deletions and the cleanup
630 * for an ndlp on removal.
633 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport
*vport
)
635 struct lpfc_hba
*phba
= vport
->phba
;
636 struct lpfc_scsi_buf
*psb
, *next_psb
;
637 unsigned long iflag
= 0;
639 spin_lock_irqsave(&phba
->hbalock
, iflag
);
640 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
641 list_for_each_entry_safe(psb
, next_psb
,
642 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
643 if (psb
->rdata
&& psb
->rdata
->pnode
644 && psb
->rdata
->pnode
->vport
== vport
)
647 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
648 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
652 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
653 * @phba: pointer to lpfc hba data structure.
654 * @axri: pointer to the fcp xri abort wcqe structure.
656 * This routine is invoked by the worker thread to process a SLI4 fast-path
660 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba
*phba
,
661 struct sli4_wcqe_xri_aborted
*axri
)
663 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
664 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
665 struct lpfc_scsi_buf
*psb
, *next_psb
;
666 unsigned long iflag
= 0;
667 struct lpfc_iocbq
*iocbq
;
669 struct lpfc_nodelist
*ndlp
;
671 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
673 spin_lock_irqsave(&phba
->hbalock
, iflag
);
674 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
675 list_for_each_entry_safe(psb
, next_psb
,
676 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
677 if (psb
->cur_iocbq
.sli4_xritag
== xri
) {
678 list_del(&psb
->list
);
680 psb
->status
= IOSTAT_SUCCESS
;
682 &phba
->sli4_hba
.abts_scsi_buf_list_lock
);
683 if (psb
->rdata
&& psb
->rdata
->pnode
)
684 ndlp
= psb
->rdata
->pnode
;
688 rrq_empty
= list_empty(&phba
->active_rrq_list
);
689 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
691 lpfc_set_rrq_active(phba
, ndlp
, xri
, rxid
, 1);
692 lpfc_sli4_abts_err_handler(phba
, ndlp
, axri
);
694 lpfc_release_scsi_buf_s4(phba
, psb
);
696 lpfc_worker_wake_up(phba
);
700 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
701 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
702 iocbq
= phba
->sli
.iocbq_lookup
[i
];
704 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
) ||
705 (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
707 if (iocbq
->sli4_xritag
!= xri
)
709 psb
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
711 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
713 lpfc_worker_wake_up(phba
);
717 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
721 * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list
722 * @phba: pointer to lpfc hba data structure.
723 * @post_sblist: pointer to the scsi buffer list.
725 * This routine walks a list of scsi buffers that was passed in. It attempts
726 * to construct blocks of scsi buffer sgls which contains contiguous xris and
727 * uses the non-embedded SGL block post mailbox commands to post to the port.
728 * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use
729 * embedded SGL post mailbox command for posting. The @post_sblist passed in
730 * must be local list, thus no lock is needed when manipulate the list.
732 * Returns: 0 = failure, non-zero number of successfully posted buffers.
735 lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba
*phba
,
736 struct list_head
*post_sblist
, int sb_count
)
738 struct lpfc_scsi_buf
*psb
, *psb_next
;
740 int post_cnt
= 0, block_cnt
= 0, num_posting
= 0, num_posted
= 0;
741 dma_addr_t pdma_phys_bpl1
;
742 int last_xritag
= NO_XRI
;
743 LIST_HEAD(prep_sblist
);
744 LIST_HEAD(blck_sblist
);
745 LIST_HEAD(scsi_sblist
);
751 list_for_each_entry_safe(psb
, psb_next
, post_sblist
, list
) {
752 list_del_init(&psb
->list
);
754 if ((last_xritag
!= NO_XRI
) &&
755 (psb
->cur_iocbq
.sli4_xritag
!= last_xritag
+ 1)) {
756 /* a hole in xri block, form a sgl posting block */
757 list_splice_init(&prep_sblist
, &blck_sblist
);
758 post_cnt
= block_cnt
- 1;
759 /* prepare list for next posting block */
760 list_add_tail(&psb
->list
, &prep_sblist
);
763 /* prepare list for next posting block */
764 list_add_tail(&psb
->list
, &prep_sblist
);
765 /* enough sgls for non-embed sgl mbox command */
766 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
767 list_splice_init(&prep_sblist
, &blck_sblist
);
768 post_cnt
= block_cnt
;
773 last_xritag
= psb
->cur_iocbq
.sli4_xritag
;
775 /* end of repost sgl list condition for SCSI buffers */
776 if (num_posting
== sb_count
) {
778 /* last sgl posting block */
779 list_splice_init(&prep_sblist
, &blck_sblist
);
780 post_cnt
= block_cnt
;
781 } else if (block_cnt
== 1) {
782 /* last single sgl with non-contiguous xri */
783 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
784 pdma_phys_bpl1
= psb
->dma_phys_bpl
+
788 status
= lpfc_sli4_post_sgl(phba
,
791 psb
->cur_iocbq
.sli4_xritag
);
793 /* failure, put on abort scsi list */
796 /* success, put on SCSI buffer list */
798 psb
->status
= IOSTAT_SUCCESS
;
801 /* success, put on SCSI buffer sgl list */
802 list_add_tail(&psb
->list
, &scsi_sblist
);
806 /* continue until a nembed page worth of sgls */
810 /* post block of SCSI buffer list sgls */
811 status
= lpfc_sli4_post_scsi_sgl_block(phba
, &blck_sblist
,
814 /* don't reset xirtag due to hole in xri block */
816 last_xritag
= NO_XRI
;
818 /* reset SCSI buffer post count for next round of posting */
821 /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */
822 while (!list_empty(&blck_sblist
)) {
823 list_remove_head(&blck_sblist
, psb
,
824 struct lpfc_scsi_buf
, list
);
826 /* failure, put on abort scsi list */
829 /* success, put on SCSI buffer list */
831 psb
->status
= IOSTAT_SUCCESS
;
834 list_add_tail(&psb
->list
, &scsi_sblist
);
837 /* Push SCSI buffers with sgl posted to the availble list */
838 while (!list_empty(&scsi_sblist
)) {
839 list_remove_head(&scsi_sblist
, psb
,
840 struct lpfc_scsi_buf
, list
);
841 lpfc_release_scsi_buf_s4(phba
, psb
);
847 * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls
848 * @phba: pointer to lpfc hba data structure.
850 * This routine walks the list of scsi buffers that have been allocated and
851 * repost them to the port by using SGL block post. This is needed after a
852 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
853 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
854 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
856 * Returns: 0 = success, non-zero failure.
859 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba
*phba
)
861 LIST_HEAD(post_sblist
);
862 int num_posted
, rc
= 0;
864 /* get all SCSI buffers need to repost to a local list */
865 spin_lock(&phba
->scsi_buf_list_lock
);
866 list_splice_init(&phba
->lpfc_scsi_buf_list
, &post_sblist
);
867 spin_unlock(&phba
->scsi_buf_list_lock
);
869 /* post the list of scsi buffer sgls to port if available */
870 if (!list_empty(&post_sblist
)) {
871 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
, &post_sblist
,
872 phba
->sli4_hba
.scsi_xri_cnt
);
873 /* failed to post any scsi buffer, return error */
881 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
882 * @vport: The virtual port for which this call being executed.
883 * @num_to_allocate: The requested number of buffers to allocate.
885 * This routine allocates scsi buffers for device with SLI-4 interface spec,
886 * the scsi buffer contains all the necessary information needed to initiate
887 * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put
888 * them on a list, it post them to the port by using SGL block post.
891 * int - number of scsi buffers that were allocated and posted.
892 * 0 = failure, less than num_to_alloc is a partial failure.
895 lpfc_new_scsi_buf_s4(struct lpfc_vport
*vport
, int num_to_alloc
)
897 struct lpfc_hba
*phba
= vport
->phba
;
898 struct lpfc_scsi_buf
*psb
;
899 struct sli4_sge
*sgl
;
901 dma_addr_t pdma_phys_fcp_cmd
;
902 dma_addr_t pdma_phys_fcp_rsp
;
903 dma_addr_t pdma_phys_bpl
, pdma_phys_bpl1
;
904 uint16_t iotag
, lxri
= 0;
905 int bcnt
, num_posted
;
906 LIST_HEAD(prep_sblist
);
907 LIST_HEAD(post_sblist
);
908 LIST_HEAD(scsi_sblist
);
910 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
911 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
915 * Get memory from the pci pool to map the virt space to
916 * pci bus space for an I/O. The DMA buffer includes space
917 * for the struct fcp_cmnd, struct fcp_rsp and the number
918 * of bde's necessary to support the sg_tablesize.
920 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
921 GFP_KERNEL
, &psb
->dma_handle
);
926 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
928 /* Allocate iotag for psb->cur_iocbq. */
929 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
931 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
932 psb
->data
, psb
->dma_handle
);
937 lxri
= lpfc_sli4_next_xritag(phba
);
938 if (lxri
== NO_XRI
) {
939 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
940 psb
->data
, psb
->dma_handle
);
944 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
945 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
946 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
947 psb
->fcp_bpl
= psb
->data
;
948 psb
->fcp_cmnd
= (psb
->data
+ phba
->cfg_sg_dma_buf_size
)
949 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
950 psb
->fcp_rsp
= (struct fcp_rsp
*)((uint8_t *)psb
->fcp_cmnd
+
951 sizeof(struct fcp_cmnd
));
953 /* Initialize local short-hand pointers. */
954 sgl
= (struct sli4_sge
*)psb
->fcp_bpl
;
955 pdma_phys_bpl
= psb
->dma_handle
;
957 (psb
->dma_handle
+ phba
->cfg_sg_dma_buf_size
)
958 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
959 pdma_phys_fcp_rsp
= pdma_phys_fcp_cmd
+ sizeof(struct fcp_cmnd
);
962 * The first two bdes are the FCP_CMD and FCP_RSP.
963 * The balance are sg list bdes. Initialize the
964 * first two and leave the rest for queuecommand.
966 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd
));
967 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd
));
968 sgl
->word2
= le32_to_cpu(sgl
->word2
);
969 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
970 sgl
->word2
= cpu_to_le32(sgl
->word2
);
971 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_cmnd
));
974 /* Setup the physical region for the FCP RSP */
975 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp
));
976 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp
));
977 sgl
->word2
= le32_to_cpu(sgl
->word2
);
978 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
979 sgl
->word2
= cpu_to_le32(sgl
->word2
);
980 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_rsp
));
983 * Since the IOCB for the FCP I/O is built into this
984 * lpfc_scsi_buf, initialize it with all known data now.
986 iocb
= &psb
->cur_iocbq
.iocb
;
987 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
988 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
989 /* setting the BLP size to 2 * sizeof BDE may not be correct.
990 * We are setting the bpl to point to out sgl. An sgl's
991 * entries are 16 bytes, a bpl entries are 12 bytes.
993 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
994 iocb
->un
.fcpi64
.bdl
.addrLow
= putPaddrLow(pdma_phys_fcp_cmd
);
995 iocb
->un
.fcpi64
.bdl
.addrHigh
= putPaddrHigh(pdma_phys_fcp_cmd
);
996 iocb
->ulpBdeCount
= 1;
998 iocb
->ulpClass
= CLASS3
;
999 psb
->cur_iocbq
.context1
= psb
;
1000 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
1001 pdma_phys_bpl1
= pdma_phys_bpl
+ SGL_PAGE_SIZE
;
1004 psb
->dma_phys_bpl
= pdma_phys_bpl
;
1006 /* add the scsi buffer to a post list */
1007 list_add_tail(&psb
->list
, &post_sblist
);
1008 spin_lock_irq(&phba
->scsi_buf_list_lock
);
1009 phba
->sli4_hba
.scsi_xri_cnt
++;
1010 spin_unlock_irq(&phba
->scsi_buf_list_lock
);
1012 lpfc_printf_log(phba
, KERN_INFO
, LOG_BG
,
1013 "3021 Allocate %d out of %d requested new SCSI "
1014 "buffers\n", bcnt
, num_to_alloc
);
1016 /* post the list of scsi buffer sgls to port if available */
1017 if (!list_empty(&post_sblist
))
1018 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
,
1019 &post_sblist
, bcnt
);
1027 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
1028 * @vport: The virtual port for which this call being executed.
1029 * @num_to_allocate: The requested number of buffers to allocate.
1031 * This routine wraps the actual SCSI buffer allocator function pointer from
1032 * the lpfc_hba struct.
1035 * int - number of scsi buffers that were allocated.
1036 * 0 = failure, less than num_to_alloc is a partial failure.
1039 lpfc_new_scsi_buf(struct lpfc_vport
*vport
, int num_to_alloc
)
1041 return vport
->phba
->lpfc_new_scsi_buf(vport
, num_to_alloc
);
1045 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1046 * @phba: The HBA for which this call is being executed.
1048 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1049 * and returns to caller.
1053 * Pointer to lpfc_scsi_buf - Success
1055 static struct lpfc_scsi_buf
*
1056 lpfc_get_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1058 struct lpfc_scsi_buf
* lpfc_cmd
= NULL
;
1059 struct list_head
*scsi_buf_list
= &phba
->lpfc_scsi_buf_list
;
1060 unsigned long iflag
= 0;
1062 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1063 list_remove_head(scsi_buf_list
, lpfc_cmd
, struct lpfc_scsi_buf
, list
);
1065 lpfc_cmd
->seg_cnt
= 0;
1066 lpfc_cmd
->nonsg_phys
= 0;
1067 lpfc_cmd
->prot_seg_cnt
= 0;
1069 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1073 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1074 * @phba: The HBA for which this call is being executed.
1076 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1077 * and returns to caller.
1081 * Pointer to lpfc_scsi_buf - Success
1083 static struct lpfc_scsi_buf
*
1084 lpfc_get_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1086 struct lpfc_scsi_buf
*lpfc_cmd
;
1087 unsigned long iflag
= 0;
1090 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1091 list_for_each_entry(lpfc_cmd
, &phba
->lpfc_scsi_buf_list
,
1093 if (lpfc_test_rrq_active(phba
, ndlp
,
1094 lpfc_cmd
->cur_iocbq
.sli4_xritag
))
1096 list_del(&lpfc_cmd
->list
);
1098 lpfc_cmd
->seg_cnt
= 0;
1099 lpfc_cmd
->nonsg_phys
= 0;
1100 lpfc_cmd
->prot_seg_cnt
= 0;
1103 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
,
1111 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1112 * @phba: The HBA for which this call is being executed.
1114 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1115 * and returns to caller.
1119 * Pointer to lpfc_scsi_buf - Success
1121 static struct lpfc_scsi_buf
*
1122 lpfc_get_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1124 return phba
->lpfc_get_scsi_buf(phba
, ndlp
);
1128 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
1129 * @phba: The Hba for which this call is being executed.
1130 * @psb: The scsi buffer which is being released.
1132 * This routine releases @psb scsi buffer by adding it to tail of @phba
1133 * lpfc_scsi_buf_list list.
1136 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1138 unsigned long iflag
= 0;
1140 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1142 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
1143 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1147 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
1148 * @phba: The Hba for which this call is being executed.
1149 * @psb: The scsi buffer which is being released.
1151 * This routine releases @psb scsi buffer by adding it to tail of @phba
1152 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
1153 * and cannot be reused for at least RA_TOV amount of time if it was
1157 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1159 unsigned long iflag
= 0;
1161 if (psb
->exch_busy
) {
1162 spin_lock_irqsave(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1165 list_add_tail(&psb
->list
,
1166 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
1167 spin_unlock_irqrestore(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1171 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1173 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
1174 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1179 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
1180 * @phba: The Hba for which this call is being executed.
1181 * @psb: The scsi buffer which is being released.
1183 * This routine releases @psb scsi buffer by adding it to tail of @phba
1184 * lpfc_scsi_buf_list list.
1187 lpfc_release_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1190 phba
->lpfc_release_scsi_buf(phba
, psb
);
1194 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
1195 * @phba: The Hba for which this call is being executed.
1196 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1198 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1199 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1200 * through sg elements and format the bdea. This routine also initializes all
1201 * IOCB fields which are dependent on scsi command request buffer.
1208 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
1210 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
1211 struct scatterlist
*sgel
= NULL
;
1212 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
1213 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
1214 struct lpfc_iocbq
*iocbq
= &lpfc_cmd
->cur_iocbq
;
1215 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
1216 struct ulp_bde64
*data_bde
= iocb_cmd
->unsli3
.fcp_ext
.dbde
;
1217 dma_addr_t physaddr
;
1218 uint32_t num_bde
= 0;
1219 int nseg
, datadir
= scsi_cmnd
->sc_data_direction
;
1222 * There are three possibilities here - use scatter-gather segment, use
1223 * the single mapping, or neither. Start the lpfc command prep by
1224 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1228 if (scsi_sg_count(scsi_cmnd
)) {
1230 * The driver stores the segment count returned from pci_map_sg
1231 * because this a count of dma-mappings used to map the use_sg
1232 * pages. They are not guaranteed to be the same for those
1233 * architectures that implement an IOMMU.
1236 nseg
= dma_map_sg(&phba
->pcidev
->dev
, scsi_sglist(scsi_cmnd
),
1237 scsi_sg_count(scsi_cmnd
), datadir
);
1238 if (unlikely(!nseg
))
1241 lpfc_cmd
->seg_cnt
= nseg
;
1242 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
1243 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1244 "9064 BLKGRD: %s: Too many sg segments from "
1245 "dma_map_sg. Config %d, seg_cnt %d\n",
1246 __func__
, phba
->cfg_sg_seg_cnt
,
1248 scsi_dma_unmap(scsi_cmnd
);
1253 * The driver established a maximum scatter-gather segment count
1254 * during probe that limits the number of sg elements in any
1255 * single scsi command. Just run through the seg_cnt and format
1257 * When using SLI-3 the driver will try to fit all the BDEs into
1258 * the IOCB. If it can't then the BDEs get added to a BPL as it
1259 * does for SLI-2 mode.
1261 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
1262 physaddr
= sg_dma_address(sgel
);
1263 if (phba
->sli_rev
== 3 &&
1264 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1265 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
) &&
1266 nseg
<= LPFC_EXT_DATA_BDE_COUNT
) {
1267 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1268 data_bde
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1269 data_bde
->addrLow
= putPaddrLow(physaddr
);
1270 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1273 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1274 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1275 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1277 le32_to_cpu(putPaddrLow(physaddr
));
1279 le32_to_cpu(putPaddrHigh(physaddr
));
1286 * Finish initializing those IOCB fields that are dependent on the
1287 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1288 * explicitly reinitialized and for SLI-3 the extended bde count is
1289 * explicitly reinitialized since all iocb memory resources are reused.
1291 if (phba
->sli_rev
== 3 &&
1292 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1293 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
)) {
1294 if (num_bde
> LPFC_EXT_DATA_BDE_COUNT
) {
1296 * The extended IOCB format can only fit 3 BDE or a BPL.
1297 * This I/O has more than 3 BDE so the 1st data bde will
1298 * be a BPL that is filled in here.
1300 physaddr
= lpfc_cmd
->dma_handle
;
1301 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BLP_64
;
1302 data_bde
->tus
.f
.bdeSize
= (num_bde
*
1303 sizeof(struct ulp_bde64
));
1304 physaddr
+= (sizeof(struct fcp_cmnd
) +
1305 sizeof(struct fcp_rsp
) +
1306 (2 * sizeof(struct ulp_bde64
)));
1307 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1308 data_bde
->addrLow
= putPaddrLow(physaddr
);
1309 /* ebde count includes the response bde and data bpl */
1310 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= 2;
1312 /* ebde count includes the response bde and data bdes */
1313 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1316 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
=
1317 ((num_bde
+ 2) * sizeof(struct ulp_bde64
));
1318 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1320 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
1323 * Due to difference in data length between DIF/non-DIF paths,
1324 * we need to set word 4 of IOCB here
1326 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
1330 static inline unsigned
1331 lpfc_cmd_blksize(struct scsi_cmnd
*sc
)
1333 return sc
->device
->sector_size
;
1336 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1338 /* Return if if error injection is detected by Initiator */
1339 #define BG_ERR_INIT 0x1
1340 /* Return if if error injection is detected by Target */
1341 #define BG_ERR_TGT 0x2
1342 /* Return if if swapping CSUM<-->CRC is required for error injection */
1343 #define BG_ERR_SWAP 0x10
1344 /* Return if disabling Guard/Ref/App checking is required for error injection */
1345 #define BG_ERR_CHECK 0x20
1348 * lpfc_bg_err_inject - Determine if we should inject an error
1349 * @phba: The Hba for which this call is being executed.
1350 * @sc: The SCSI command to examine
1351 * @reftag: (out) BlockGuard reference tag for transmitted data
1352 * @apptag: (out) BlockGuard application tag for transmitted data
1353 * @new_guard (in) Value to replace CRC with if needed
1355 * Returns BG_ERR_* bit mask or 0 if request ignored
1358 lpfc_bg_err_inject(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1359 uint32_t *reftag
, uint16_t *apptag
, uint32_t new_guard
)
1361 struct scatterlist
*sgpe
; /* s/g prot entry */
1362 struct scatterlist
*sgde
; /* s/g data entry */
1363 struct lpfc_scsi_buf
*lpfc_cmd
= NULL
;
1364 struct scsi_dif_tuple
*src
= NULL
;
1365 struct lpfc_nodelist
*ndlp
;
1366 struct lpfc_rport_data
*rdata
;
1367 uint32_t op
= scsi_get_prot_op(sc
);
1374 if (op
== SCSI_PROT_NORMAL
)
1377 sgpe
= scsi_prot_sglist(sc
);
1378 sgde
= scsi_sglist(sc
);
1379 lba
= scsi_get_lba(sc
);
1381 /* First check if we need to match the LBA */
1382 if (phba
->lpfc_injerr_lba
!= LPFC_INJERR_LBA_OFF
) {
1383 blksize
= lpfc_cmd_blksize(sc
);
1384 numblks
= (scsi_bufflen(sc
) + blksize
- 1) / blksize
;
1386 /* Make sure we have the right LBA if one is specified */
1387 if ((phba
->lpfc_injerr_lba
< lba
) ||
1388 (phba
->lpfc_injerr_lba
>= (lba
+ numblks
)))
1391 blockoff
= phba
->lpfc_injerr_lba
- lba
;
1392 numblks
= sg_dma_len(sgpe
) /
1393 sizeof(struct scsi_dif_tuple
);
1394 if (numblks
< blockoff
)
1399 /* Next check if we need to match the remote NPortID or WWPN */
1400 rdata
= sc
->device
->hostdata
;
1401 if (rdata
&& rdata
->pnode
) {
1402 ndlp
= rdata
->pnode
;
1404 /* Make sure we have the right NPortID if one is specified */
1405 if (phba
->lpfc_injerr_nportid
&&
1406 (phba
->lpfc_injerr_nportid
!= ndlp
->nlp_DID
))
1410 * Make sure we have the right WWPN if one is specified.
1411 * wwn[0] should be a non-zero NAA in a good WWPN.
1413 if (phba
->lpfc_injerr_wwpn
.u
.wwn
[0] &&
1414 (memcmp(&ndlp
->nlp_portname
, &phba
->lpfc_injerr_wwpn
,
1415 sizeof(struct lpfc_name
)) != 0))
1419 /* Setup a ptr to the protection data if the SCSI host provides it */
1421 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
1423 lpfc_cmd
= (struct lpfc_scsi_buf
*)sc
->host_scribble
;
1426 /* Should we change the Reference Tag */
1428 if (phba
->lpfc_injerr_wref_cnt
) {
1430 case SCSI_PROT_WRITE_PASS
:
1433 * For WRITE_PASS, force the error
1434 * to be sent on the wire. It should
1435 * be detected by the Target.
1436 * If blockoff != 0 error will be
1437 * inserted in middle of the IO.
1440 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1441 "9076 BLKGRD: Injecting reftag error: "
1442 "write lba x%lx + x%x oldrefTag x%x\n",
1443 (unsigned long)lba
, blockoff
,
1444 be32_to_cpu(src
->ref_tag
));
1447 * Save the old ref_tag so we can
1448 * restore it on completion.
1451 lpfc_cmd
->prot_data_type
=
1453 lpfc_cmd
->prot_data_segment
=
1455 lpfc_cmd
->prot_data
=
1458 src
->ref_tag
= cpu_to_be32(0xDEADBEEF);
1459 phba
->lpfc_injerr_wref_cnt
--;
1460 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1461 phba
->lpfc_injerr_nportid
= 0;
1462 phba
->lpfc_injerr_lba
=
1463 LPFC_INJERR_LBA_OFF
;
1464 memset(&phba
->lpfc_injerr_wwpn
,
1465 0, sizeof(struct lpfc_name
));
1467 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1472 case SCSI_PROT_WRITE_INSERT
:
1474 * For WRITE_INSERT, force the error
1475 * to be sent on the wire. It should be
1476 * detected by the Target.
1478 /* DEADBEEF will be the reftag on the wire */
1479 *reftag
= 0xDEADBEEF;
1480 phba
->lpfc_injerr_wref_cnt
--;
1481 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1482 phba
->lpfc_injerr_nportid
= 0;
1483 phba
->lpfc_injerr_lba
=
1484 LPFC_INJERR_LBA_OFF
;
1485 memset(&phba
->lpfc_injerr_wwpn
,
1486 0, sizeof(struct lpfc_name
));
1488 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1490 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1491 "9078 BLKGRD: Injecting reftag error: "
1492 "write lba x%lx\n", (unsigned long)lba
);
1494 case SCSI_PROT_WRITE_STRIP
:
1496 * For WRITE_STRIP and WRITE_PASS,
1497 * force the error on data
1498 * being copied from SLI-Host to SLI-Port.
1500 *reftag
= 0xDEADBEEF;
1501 phba
->lpfc_injerr_wref_cnt
--;
1502 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1503 phba
->lpfc_injerr_nportid
= 0;
1504 phba
->lpfc_injerr_lba
=
1505 LPFC_INJERR_LBA_OFF
;
1506 memset(&phba
->lpfc_injerr_wwpn
,
1507 0, sizeof(struct lpfc_name
));
1511 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1512 "9077 BLKGRD: Injecting reftag error: "
1513 "write lba x%lx\n", (unsigned long)lba
);
1517 if (phba
->lpfc_injerr_rref_cnt
) {
1519 case SCSI_PROT_READ_INSERT
:
1520 case SCSI_PROT_READ_STRIP
:
1521 case SCSI_PROT_READ_PASS
:
1523 * For READ_STRIP and READ_PASS, force the
1524 * error on data being read off the wire. It
1525 * should force an IO error to the driver.
1527 *reftag
= 0xDEADBEEF;
1528 phba
->lpfc_injerr_rref_cnt
--;
1529 if (phba
->lpfc_injerr_rref_cnt
== 0) {
1530 phba
->lpfc_injerr_nportid
= 0;
1531 phba
->lpfc_injerr_lba
=
1532 LPFC_INJERR_LBA_OFF
;
1533 memset(&phba
->lpfc_injerr_wwpn
,
1534 0, sizeof(struct lpfc_name
));
1538 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1539 "9079 BLKGRD: Injecting reftag error: "
1540 "read lba x%lx\n", (unsigned long)lba
);
1546 /* Should we change the Application Tag */
1548 if (phba
->lpfc_injerr_wapp_cnt
) {
1550 case SCSI_PROT_WRITE_PASS
:
1553 * For WRITE_PASS, force the error
1554 * to be sent on the wire. It should
1555 * be detected by the Target.
1556 * If blockoff != 0 error will be
1557 * inserted in middle of the IO.
1560 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1561 "9080 BLKGRD: Injecting apptag error: "
1562 "write lba x%lx + x%x oldappTag x%x\n",
1563 (unsigned long)lba
, blockoff
,
1564 be16_to_cpu(src
->app_tag
));
1567 * Save the old app_tag so we can
1568 * restore it on completion.
1571 lpfc_cmd
->prot_data_type
=
1573 lpfc_cmd
->prot_data_segment
=
1575 lpfc_cmd
->prot_data
=
1578 src
->app_tag
= cpu_to_be16(0xDEAD);
1579 phba
->lpfc_injerr_wapp_cnt
--;
1580 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1581 phba
->lpfc_injerr_nportid
= 0;
1582 phba
->lpfc_injerr_lba
=
1583 LPFC_INJERR_LBA_OFF
;
1584 memset(&phba
->lpfc_injerr_wwpn
,
1585 0, sizeof(struct lpfc_name
));
1587 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1591 case SCSI_PROT_WRITE_INSERT
:
1593 * For WRITE_INSERT, force the
1594 * error to be sent on the wire. It should be
1595 * detected by the Target.
1597 /* DEAD will be the apptag on the wire */
1599 phba
->lpfc_injerr_wapp_cnt
--;
1600 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1601 phba
->lpfc_injerr_nportid
= 0;
1602 phba
->lpfc_injerr_lba
=
1603 LPFC_INJERR_LBA_OFF
;
1604 memset(&phba
->lpfc_injerr_wwpn
,
1605 0, sizeof(struct lpfc_name
));
1607 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1609 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1610 "0813 BLKGRD: Injecting apptag error: "
1611 "write lba x%lx\n", (unsigned long)lba
);
1613 case SCSI_PROT_WRITE_STRIP
:
1615 * For WRITE_STRIP and WRITE_PASS,
1616 * force the error on data
1617 * being copied from SLI-Host to SLI-Port.
1620 phba
->lpfc_injerr_wapp_cnt
--;
1621 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1622 phba
->lpfc_injerr_nportid
= 0;
1623 phba
->lpfc_injerr_lba
=
1624 LPFC_INJERR_LBA_OFF
;
1625 memset(&phba
->lpfc_injerr_wwpn
,
1626 0, sizeof(struct lpfc_name
));
1630 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1631 "0812 BLKGRD: Injecting apptag error: "
1632 "write lba x%lx\n", (unsigned long)lba
);
1636 if (phba
->lpfc_injerr_rapp_cnt
) {
1638 case SCSI_PROT_READ_INSERT
:
1639 case SCSI_PROT_READ_STRIP
:
1640 case SCSI_PROT_READ_PASS
:
1642 * For READ_STRIP and READ_PASS, force the
1643 * error on data being read off the wire. It
1644 * should force an IO error to the driver.
1647 phba
->lpfc_injerr_rapp_cnt
--;
1648 if (phba
->lpfc_injerr_rapp_cnt
== 0) {
1649 phba
->lpfc_injerr_nportid
= 0;
1650 phba
->lpfc_injerr_lba
=
1651 LPFC_INJERR_LBA_OFF
;
1652 memset(&phba
->lpfc_injerr_wwpn
,
1653 0, sizeof(struct lpfc_name
));
1657 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1658 "0814 BLKGRD: Injecting apptag error: "
1659 "read lba x%lx\n", (unsigned long)lba
);
1666 /* Should we change the Guard Tag */
1668 if (phba
->lpfc_injerr_wgrd_cnt
) {
1670 case SCSI_PROT_WRITE_PASS
:
1674 case SCSI_PROT_WRITE_INSERT
:
1676 * For WRITE_INSERT, force the
1677 * error to be sent on the wire. It should be
1678 * detected by the Target.
1680 phba
->lpfc_injerr_wgrd_cnt
--;
1681 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1682 phba
->lpfc_injerr_nportid
= 0;
1683 phba
->lpfc_injerr_lba
=
1684 LPFC_INJERR_LBA_OFF
;
1685 memset(&phba
->lpfc_injerr_wwpn
,
1686 0, sizeof(struct lpfc_name
));
1689 rc
|= BG_ERR_TGT
| BG_ERR_SWAP
;
1690 /* Signals the caller to swap CRC->CSUM */
1692 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1693 "0817 BLKGRD: Injecting guard error: "
1694 "write lba x%lx\n", (unsigned long)lba
);
1696 case SCSI_PROT_WRITE_STRIP
:
1698 * For WRITE_STRIP and WRITE_PASS,
1699 * force the error on data
1700 * being copied from SLI-Host to SLI-Port.
1702 phba
->lpfc_injerr_wgrd_cnt
--;
1703 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1704 phba
->lpfc_injerr_nportid
= 0;
1705 phba
->lpfc_injerr_lba
=
1706 LPFC_INJERR_LBA_OFF
;
1707 memset(&phba
->lpfc_injerr_wwpn
,
1708 0, sizeof(struct lpfc_name
));
1711 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1712 /* Signals the caller to swap CRC->CSUM */
1714 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1715 "0816 BLKGRD: Injecting guard error: "
1716 "write lba x%lx\n", (unsigned long)lba
);
1720 if (phba
->lpfc_injerr_rgrd_cnt
) {
1722 case SCSI_PROT_READ_INSERT
:
1723 case SCSI_PROT_READ_STRIP
:
1724 case SCSI_PROT_READ_PASS
:
1726 * For READ_STRIP and READ_PASS, force the
1727 * error on data being read off the wire. It
1728 * should force an IO error to the driver.
1730 phba
->lpfc_injerr_rgrd_cnt
--;
1731 if (phba
->lpfc_injerr_rgrd_cnt
== 0) {
1732 phba
->lpfc_injerr_nportid
= 0;
1733 phba
->lpfc_injerr_lba
=
1734 LPFC_INJERR_LBA_OFF
;
1735 memset(&phba
->lpfc_injerr_wwpn
,
1736 0, sizeof(struct lpfc_name
));
1739 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1740 /* Signals the caller to swap CRC->CSUM */
1742 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1743 "0818 BLKGRD: Injecting guard error: "
1744 "read lba x%lx\n", (unsigned long)lba
);
1754 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1755 * the specified SCSI command.
1756 * @phba: The Hba for which this call is being executed.
1757 * @sc: The SCSI command to examine
1758 * @txopt: (out) BlockGuard operation for transmitted data
1759 * @rxopt: (out) BlockGuard operation for received data
1761 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1765 lpfc_sc_to_bg_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1766 uint8_t *txop
, uint8_t *rxop
)
1768 uint8_t guard_type
= scsi_host_get_guard(sc
->device
->host
);
1771 if (guard_type
== SHOST_DIX_GUARD_IP
) {
1772 switch (scsi_get_prot_op(sc
)) {
1773 case SCSI_PROT_READ_INSERT
:
1774 case SCSI_PROT_WRITE_STRIP
:
1775 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1776 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1779 case SCSI_PROT_READ_STRIP
:
1780 case SCSI_PROT_WRITE_INSERT
:
1781 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1782 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1785 case SCSI_PROT_READ_PASS
:
1786 case SCSI_PROT_WRITE_PASS
:
1787 *rxop
= BG_OP_IN_CRC_OUT_CSUM
;
1788 *txop
= BG_OP_IN_CSUM_OUT_CRC
;
1791 case SCSI_PROT_NORMAL
:
1793 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1794 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1795 scsi_get_prot_op(sc
));
1801 switch (scsi_get_prot_op(sc
)) {
1802 case SCSI_PROT_READ_STRIP
:
1803 case SCSI_PROT_WRITE_INSERT
:
1804 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1805 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1808 case SCSI_PROT_READ_PASS
:
1809 case SCSI_PROT_WRITE_PASS
:
1810 *rxop
= BG_OP_IN_CRC_OUT_CRC
;
1811 *txop
= BG_OP_IN_CRC_OUT_CRC
;
1814 case SCSI_PROT_READ_INSERT
:
1815 case SCSI_PROT_WRITE_STRIP
:
1816 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1817 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1820 case SCSI_PROT_NORMAL
:
1822 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1823 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1824 scsi_get_prot_op(sc
));
1833 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1835 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1836 * the specified SCSI command in order to force a guard tag error.
1837 * @phba: The Hba for which this call is being executed.
1838 * @sc: The SCSI command to examine
1839 * @txopt: (out) BlockGuard operation for transmitted data
1840 * @rxopt: (out) BlockGuard operation for received data
1842 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1846 lpfc_bg_err_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1847 uint8_t *txop
, uint8_t *rxop
)
1849 uint8_t guard_type
= scsi_host_get_guard(sc
->device
->host
);
1852 if (guard_type
== SHOST_DIX_GUARD_IP
) {
1853 switch (scsi_get_prot_op(sc
)) {
1854 case SCSI_PROT_READ_INSERT
:
1855 case SCSI_PROT_WRITE_STRIP
:
1856 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1857 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1860 case SCSI_PROT_READ_STRIP
:
1861 case SCSI_PROT_WRITE_INSERT
:
1862 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1863 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1866 case SCSI_PROT_READ_PASS
:
1867 case SCSI_PROT_WRITE_PASS
:
1868 *rxop
= BG_OP_IN_CSUM_OUT_CRC
;
1869 *txop
= BG_OP_IN_CRC_OUT_CSUM
;
1872 case SCSI_PROT_NORMAL
:
1878 switch (scsi_get_prot_op(sc
)) {
1879 case SCSI_PROT_READ_STRIP
:
1880 case SCSI_PROT_WRITE_INSERT
:
1881 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1882 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1885 case SCSI_PROT_READ_PASS
:
1886 case SCSI_PROT_WRITE_PASS
:
1887 *rxop
= BG_OP_IN_CSUM_OUT_CSUM
;
1888 *txop
= BG_OP_IN_CSUM_OUT_CSUM
;
1891 case SCSI_PROT_READ_INSERT
:
1892 case SCSI_PROT_WRITE_STRIP
:
1893 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1894 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1897 case SCSI_PROT_NORMAL
:
1908 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1909 * @phba: The Hba for which this call is being executed.
1910 * @sc: pointer to scsi command we're working on
1911 * @bpl: pointer to buffer list for protection groups
1912 * @datacnt: number of segments of data that have been dma mapped
1914 * This function sets up BPL buffer list for protection groups of
1915 * type LPFC_PG_TYPE_NO_DIF
1917 * This is usually used when the HBA is instructed to generate
1918 * DIFs and insert them into data stream (or strip DIF from
1919 * incoming data stream)
1921 * The buffer list consists of just one protection group described
1923 * +-------------------------+
1924 * start of prot group --> | PDE_5 |
1925 * +-------------------------+
1927 * +-------------------------+
1929 * +-------------------------+
1930 * |more Data BDE's ... (opt)|
1931 * +-------------------------+
1934 * Note: Data s/g buffers have been dma mapped
1936 * Returns the number of BDEs added to the BPL.
1939 lpfc_bg_setup_bpl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1940 struct ulp_bde64
*bpl
, int datasegcnt
)
1942 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1943 struct lpfc_pde5
*pde5
= NULL
;
1944 struct lpfc_pde6
*pde6
= NULL
;
1945 dma_addr_t physaddr
;
1946 int i
= 0, num_bde
= 0, status
;
1947 int datadir
= sc
->sc_data_direction
;
1949 uint32_t checking
= 1;
1954 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
1958 /* extract some info from the scsi command for pde*/
1959 blksize
= lpfc_cmd_blksize(sc
);
1960 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
1962 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1963 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
1965 if (rc
& BG_ERR_SWAP
)
1966 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
1967 if (rc
& BG_ERR_CHECK
)
1972 /* setup PDE5 with what we have */
1973 pde5
= (struct lpfc_pde5
*) bpl
;
1974 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
1975 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
1977 /* Endianness conversion if necessary for PDE5 */
1978 pde5
->word0
= cpu_to_le32(pde5
->word0
);
1979 pde5
->reftag
= cpu_to_le32(reftag
);
1981 /* advance bpl and increment bde count */
1984 pde6
= (struct lpfc_pde6
*) bpl
;
1986 /* setup PDE6 with the rest of the info */
1987 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
1988 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
1989 bf_set(pde6_optx
, pde6
, txop
);
1990 bf_set(pde6_oprx
, pde6
, rxop
);
1991 if (datadir
== DMA_FROM_DEVICE
) {
1992 bf_set(pde6_ce
, pde6
, checking
);
1993 bf_set(pde6_re
, pde6
, checking
);
1995 bf_set(pde6_ai
, pde6
, 1);
1996 bf_set(pde6_ae
, pde6
, 0);
1997 bf_set(pde6_apptagval
, pde6
, 0);
1999 /* Endianness conversion if necessary for PDE6 */
2000 pde6
->word0
= cpu_to_le32(pde6
->word0
);
2001 pde6
->word1
= cpu_to_le32(pde6
->word1
);
2002 pde6
->word2
= cpu_to_le32(pde6
->word2
);
2004 /* advance bpl and increment bde count */
2008 /* assumption: caller has already run dma_map_sg on command data */
2009 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
2010 physaddr
= sg_dma_address(sgde
);
2011 bpl
->addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
2012 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
2013 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgde
);
2014 if (datadir
== DMA_TO_DEVICE
)
2015 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2017 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2018 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2028 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
2029 * @phba: The Hba for which this call is being executed.
2030 * @sc: pointer to scsi command we're working on
2031 * @bpl: pointer to buffer list for protection groups
2032 * @datacnt: number of segments of data that have been dma mapped
2033 * @protcnt: number of segment of protection data that have been dma mapped
2035 * This function sets up BPL buffer list for protection groups of
2036 * type LPFC_PG_TYPE_DIF
2038 * This is usually used when DIFs are in their own buffers,
2039 * separate from the data. The HBA can then by instructed
2040 * to place the DIFs in the outgoing stream. For read operations,
2041 * The HBA could extract the DIFs and place it in DIF buffers.
2043 * The buffer list for this type consists of one or more of the
2044 * protection groups described below:
2045 * +-------------------------+
2046 * start of first prot group --> | PDE_5 |
2047 * +-------------------------+
2049 * +-------------------------+
2050 * | PDE_7 (Prot BDE) |
2051 * +-------------------------+
2053 * +-------------------------+
2054 * |more Data BDE's ... (opt)|
2055 * +-------------------------+
2056 * start of new prot group --> | PDE_5 |
2057 * +-------------------------+
2059 * +-------------------------+
2061 * Note: It is assumed that both data and protection s/g buffers have been
2064 * Returns the number of BDEs added to the BPL.
2067 lpfc_bg_setup_bpl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2068 struct ulp_bde64
*bpl
, int datacnt
, int protcnt
)
2070 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2071 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2072 struct lpfc_pde5
*pde5
= NULL
;
2073 struct lpfc_pde6
*pde6
= NULL
;
2074 struct lpfc_pde7
*pde7
= NULL
;
2075 dma_addr_t dataphysaddr
, protphysaddr
;
2076 unsigned short curr_data
= 0, curr_prot
= 0;
2077 unsigned int split_offset
;
2078 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2079 unsigned int protgrp_blks
, protgrp_bytes
;
2080 unsigned int remainder
, subtotal
;
2082 int datadir
= sc
->sc_data_direction
;
2083 unsigned char pgdone
= 0, alldone
= 0;
2086 uint32_t checking
= 1;
2091 sgpe
= scsi_prot_sglist(sc
);
2092 sgde
= scsi_sglist(sc
);
2094 if (!sgpe
|| !sgde
) {
2095 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2096 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
2101 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2105 /* extract some info from the scsi command */
2106 blksize
= lpfc_cmd_blksize(sc
);
2107 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2109 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2110 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2112 if (rc
& BG_ERR_SWAP
)
2113 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2114 if (rc
& BG_ERR_CHECK
)
2121 /* setup PDE5 with what we have */
2122 pde5
= (struct lpfc_pde5
*) bpl
;
2123 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
2124 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
2126 /* Endianness conversion if necessary for PDE5 */
2127 pde5
->word0
= cpu_to_le32(pde5
->word0
);
2128 pde5
->reftag
= cpu_to_le32(reftag
);
2130 /* advance bpl and increment bde count */
2133 pde6
= (struct lpfc_pde6
*) bpl
;
2135 /* setup PDE6 with the rest of the info */
2136 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
2137 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
2138 bf_set(pde6_optx
, pde6
, txop
);
2139 bf_set(pde6_oprx
, pde6
, rxop
);
2140 bf_set(pde6_ce
, pde6
, checking
);
2141 bf_set(pde6_re
, pde6
, checking
);
2142 bf_set(pde6_ai
, pde6
, 1);
2143 bf_set(pde6_ae
, pde6
, 0);
2144 bf_set(pde6_apptagval
, pde6
, 0);
2146 /* Endianness conversion if necessary for PDE6 */
2147 pde6
->word0
= cpu_to_le32(pde6
->word0
);
2148 pde6
->word1
= cpu_to_le32(pde6
->word1
);
2149 pde6
->word2
= cpu_to_le32(pde6
->word2
);
2151 /* advance bpl and increment bde count */
2155 /* setup the first BDE that points to protection buffer */
2156 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2157 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2159 /* must be integer multiple of the DIF block length */
2160 BUG_ON(protgroup_len
% 8);
2162 pde7
= (struct lpfc_pde7
*) bpl
;
2163 memset(pde7
, 0, sizeof(struct lpfc_pde7
));
2164 bf_set(pde7_type
, pde7
, LPFC_PDE7_DESCRIPTOR
);
2166 pde7
->addrHigh
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2167 pde7
->addrLow
= le32_to_cpu(putPaddrLow(protphysaddr
));
2169 protgrp_blks
= protgroup_len
/ 8;
2170 protgrp_bytes
= protgrp_blks
* blksize
;
2172 /* check if this pde is crossing the 4K boundary; if so split */
2173 if ((pde7
->addrLow
& 0xfff) + protgroup_len
> 0x1000) {
2174 protgroup_remainder
= 0x1000 - (pde7
->addrLow
& 0xfff);
2175 protgroup_offset
+= protgroup_remainder
;
2176 protgrp_blks
= protgroup_remainder
/ 8;
2177 protgrp_bytes
= protgrp_blks
* blksize
;
2179 protgroup_offset
= 0;
2185 /* setup BDE's for data blocks associated with DIF data */
2187 subtotal
= 0; /* total bytes processed for current prot grp */
2190 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2191 "9065 BLKGRD:%s Invalid data segment\n",
2196 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2197 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dataphysaddr
));
2198 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dataphysaddr
));
2200 remainder
= sg_dma_len(sgde
) - split_offset
;
2202 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2203 /* we can use this whole buffer */
2204 bpl
->tus
.f
.bdeSize
= remainder
;
2207 if ((subtotal
+ remainder
) == protgrp_bytes
)
2210 /* must split this buffer with next prot grp */
2211 bpl
->tus
.f
.bdeSize
= protgrp_bytes
- subtotal
;
2212 split_offset
+= bpl
->tus
.f
.bdeSize
;
2215 subtotal
+= bpl
->tus
.f
.bdeSize
;
2217 if (datadir
== DMA_TO_DEVICE
)
2218 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2220 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2221 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2229 /* Move to the next s/g segment if possible */
2230 sgde
= sg_next(sgde
);
2234 if (protgroup_offset
) {
2235 /* update the reference tag */
2236 reftag
+= protgrp_blks
;
2242 if (curr_prot
== protcnt
) {
2244 } else if (curr_prot
< protcnt
) {
2245 /* advance to next prot buffer */
2246 sgpe
= sg_next(sgpe
);
2249 /* update the reference tag */
2250 reftag
+= protgrp_blks
;
2252 /* if we're here, we have a bug */
2253 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2254 "9054 BLKGRD: bug in %s\n", __func__
);
2264 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
2265 * @phba: The Hba for which this call is being executed.
2266 * @sc: pointer to scsi command we're working on
2267 * @sgl: pointer to buffer list for protection groups
2268 * @datacnt: number of segments of data that have been dma mapped
2270 * This function sets up SGL buffer list for protection groups of
2271 * type LPFC_PG_TYPE_NO_DIF
2273 * This is usually used when the HBA is instructed to generate
2274 * DIFs and insert them into data stream (or strip DIF from
2275 * incoming data stream)
2277 * The buffer list consists of just one protection group described
2279 * +-------------------------+
2280 * start of prot group --> | DI_SEED |
2281 * +-------------------------+
2283 * +-------------------------+
2284 * |more Data SGE's ... (opt)|
2285 * +-------------------------+
2288 * Note: Data s/g buffers have been dma mapped
2290 * Returns the number of SGEs added to the SGL.
2293 lpfc_bg_setup_sgl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2294 struct sli4_sge
*sgl
, int datasegcnt
)
2296 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2297 struct sli4_sge_diseed
*diseed
= NULL
;
2298 dma_addr_t physaddr
;
2299 int i
= 0, num_sge
= 0, status
;
2300 int datadir
= sc
->sc_data_direction
;
2305 uint32_t checking
= 1;
2307 uint32_t dma_offset
= 0;
2309 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2313 /* extract some info from the scsi command for pde*/
2314 blksize
= lpfc_cmd_blksize(sc
);
2315 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2317 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2318 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2320 if (rc
& BG_ERR_SWAP
)
2321 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2322 if (rc
& BG_ERR_CHECK
)
2327 /* setup DISEED with what we have */
2328 diseed
= (struct sli4_sge_diseed
*) sgl
;
2329 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2330 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2332 /* Endianness conversion if necessary */
2333 diseed
->ref_tag
= cpu_to_le32(reftag
);
2334 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2336 /* setup DISEED with the rest of the info */
2337 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2338 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2339 if (datadir
== DMA_FROM_DEVICE
) {
2340 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2341 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2343 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2344 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2346 /* Endianness conversion if necessary for DISEED */
2347 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2348 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2350 /* advance bpl and increment sge count */
2354 /* assumption: caller has already run dma_map_sg on command data */
2355 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
2356 physaddr
= sg_dma_address(sgde
);
2357 dma_len
= sg_dma_len(sgde
);
2358 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
2359 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
2360 if ((i
+ 1) == datasegcnt
)
2361 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2363 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2364 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2365 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2367 sgl
->sge_len
= cpu_to_le32(dma_len
);
2368 dma_offset
+= dma_len
;
2379 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2380 * @phba: The Hba for which this call is being executed.
2381 * @sc: pointer to scsi command we're working on
2382 * @sgl: pointer to buffer list for protection groups
2383 * @datacnt: number of segments of data that have been dma mapped
2384 * @protcnt: number of segment of protection data that have been dma mapped
2386 * This function sets up SGL buffer list for protection groups of
2387 * type LPFC_PG_TYPE_DIF
2389 * This is usually used when DIFs are in their own buffers,
2390 * separate from the data. The HBA can then by instructed
2391 * to place the DIFs in the outgoing stream. For read operations,
2392 * The HBA could extract the DIFs and place it in DIF buffers.
2394 * The buffer list for this type consists of one or more of the
2395 * protection groups described below:
2396 * +-------------------------+
2397 * start of first prot group --> | DISEED |
2398 * +-------------------------+
2399 * | DIF (Prot SGE) |
2400 * +-------------------------+
2402 * +-------------------------+
2403 * |more Data SGE's ... (opt)|
2404 * +-------------------------+
2405 * start of new prot group --> | DISEED |
2406 * +-------------------------+
2408 * +-------------------------+
2410 * Note: It is assumed that both data and protection s/g buffers have been
2413 * Returns the number of SGEs added to the SGL.
2416 lpfc_bg_setup_sgl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2417 struct sli4_sge
*sgl
, int datacnt
, int protcnt
)
2419 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2420 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2421 struct sli4_sge_diseed
*diseed
= NULL
;
2422 dma_addr_t dataphysaddr
, protphysaddr
;
2423 unsigned short curr_data
= 0, curr_prot
= 0;
2424 unsigned int split_offset
;
2425 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2426 unsigned int protgrp_blks
, protgrp_bytes
;
2427 unsigned int remainder
, subtotal
;
2429 unsigned char pgdone
= 0, alldone
= 0;
2435 uint32_t checking
= 1;
2436 uint32_t dma_offset
= 0;
2439 sgpe
= scsi_prot_sglist(sc
);
2440 sgde
= scsi_sglist(sc
);
2442 if (!sgpe
|| !sgde
) {
2443 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2444 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2449 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2453 /* extract some info from the scsi command */
2454 blksize
= lpfc_cmd_blksize(sc
);
2455 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2457 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2458 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2460 if (rc
& BG_ERR_SWAP
)
2461 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2462 if (rc
& BG_ERR_CHECK
)
2469 /* setup DISEED with what we have */
2470 diseed
= (struct sli4_sge_diseed
*) sgl
;
2471 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2472 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2474 /* Endianness conversion if necessary */
2475 diseed
->ref_tag
= cpu_to_le32(reftag
);
2476 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2478 /* setup DISEED with the rest of the info */
2479 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2480 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2481 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2482 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2483 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2484 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2486 /* Endianness conversion if necessary for DISEED */
2487 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2488 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2490 /* advance sgl and increment bde count */
2494 /* setup the first BDE that points to protection buffer */
2495 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2496 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2498 /* must be integer multiple of the DIF block length */
2499 BUG_ON(protgroup_len
% 8);
2501 /* Now setup DIF SGE */
2503 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DIF
);
2504 sgl
->addr_hi
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2505 sgl
->addr_lo
= le32_to_cpu(putPaddrLow(protphysaddr
));
2506 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2508 protgrp_blks
= protgroup_len
/ 8;
2509 protgrp_bytes
= protgrp_blks
* blksize
;
2511 /* check if DIF SGE is crossing the 4K boundary; if so split */
2512 if ((sgl
->addr_lo
& 0xfff) + protgroup_len
> 0x1000) {
2513 protgroup_remainder
= 0x1000 - (sgl
->addr_lo
& 0xfff);
2514 protgroup_offset
+= protgroup_remainder
;
2515 protgrp_blks
= protgroup_remainder
/ 8;
2516 protgrp_bytes
= protgrp_blks
* blksize
;
2518 protgroup_offset
= 0;
2524 /* setup SGE's for data blocks associated with DIF data */
2526 subtotal
= 0; /* total bytes processed for current prot grp */
2529 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2530 "9086 BLKGRD:%s Invalid data segment\n",
2535 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2537 remainder
= sg_dma_len(sgde
) - split_offset
;
2539 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2540 /* we can use this whole buffer */
2541 dma_len
= remainder
;
2544 if ((subtotal
+ remainder
) == protgrp_bytes
)
2547 /* must split this buffer with next prot grp */
2548 dma_len
= protgrp_bytes
- subtotal
;
2549 split_offset
+= dma_len
;
2552 subtotal
+= dma_len
;
2554 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(dataphysaddr
));
2555 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(dataphysaddr
));
2556 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2557 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2558 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2560 sgl
->sge_len
= cpu_to_le32(dma_len
);
2561 dma_offset
+= dma_len
;
2569 /* Move to the next s/g segment if possible */
2570 sgde
= sg_next(sgde
);
2573 if (protgroup_offset
) {
2574 /* update the reference tag */
2575 reftag
+= protgrp_blks
;
2581 if (curr_prot
== protcnt
) {
2582 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2584 } else if (curr_prot
< protcnt
) {
2585 /* advance to next prot buffer */
2586 sgpe
= sg_next(sgpe
);
2589 /* update the reference tag */
2590 reftag
+= protgrp_blks
;
2592 /* if we're here, we have a bug */
2593 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2594 "9085 BLKGRD: bug in %s\n", __func__
);
2605 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2606 * @phba: The Hba for which this call is being executed.
2607 * @sc: pointer to scsi command we're working on
2609 * Given a SCSI command that supports DIF, determine composition of protection
2610 * groups involved in setting up buffer lists
2612 * Returns: Protection group type (with or without DIF)
2616 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
)
2618 int ret
= LPFC_PG_TYPE_INVALID
;
2619 unsigned char op
= scsi_get_prot_op(sc
);
2622 case SCSI_PROT_READ_STRIP
:
2623 case SCSI_PROT_WRITE_INSERT
:
2624 ret
= LPFC_PG_TYPE_NO_DIF
;
2626 case SCSI_PROT_READ_INSERT
:
2627 case SCSI_PROT_WRITE_STRIP
:
2628 case SCSI_PROT_READ_PASS
:
2629 case SCSI_PROT_WRITE_PASS
:
2630 ret
= LPFC_PG_TYPE_DIF_BUF
;
2633 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2634 "9021 Unsupported protection op:%d\n", op
);
2642 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2643 * @phba: The Hba for which this call is being executed.
2644 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2646 * This is the protection/DIF aware version of
2647 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2648 * two functions eventually, but for now, it's here
2651 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
,
2652 struct lpfc_scsi_buf
*lpfc_cmd
)
2654 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2655 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2656 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
2657 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2658 uint32_t num_bde
= 0;
2659 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
2660 int prot_group_type
= 0;
2665 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2666 * fcp_rsp regions to the first data bde entry
2669 if (scsi_sg_count(scsi_cmnd
)) {
2671 * The driver stores the segment count returned from pci_map_sg
2672 * because this a count of dma-mappings used to map the use_sg
2673 * pages. They are not guaranteed to be the same for those
2674 * architectures that implement an IOMMU.
2676 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2677 scsi_sglist(scsi_cmnd
),
2678 scsi_sg_count(scsi_cmnd
), datadir
);
2679 if (unlikely(!datasegcnt
))
2682 lpfc_cmd
->seg_cnt
= datasegcnt
;
2683 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
2684 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2685 "9067 BLKGRD: %s: Too many sg segments"
2686 " from dma_map_sg. Config %d, seg_cnt"
2688 __func__
, phba
->cfg_sg_seg_cnt
,
2690 scsi_dma_unmap(scsi_cmnd
);
2694 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
2696 switch (prot_group_type
) {
2697 case LPFC_PG_TYPE_NO_DIF
:
2698 num_bde
= lpfc_bg_setup_bpl(phba
, scsi_cmnd
, bpl
,
2700 /* we should have 2 or more entries in buffer list */
2704 case LPFC_PG_TYPE_DIF_BUF
:{
2706 * This type indicates that protection buffers are
2707 * passed to the driver, so that needs to be prepared
2710 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2711 scsi_prot_sglist(scsi_cmnd
),
2712 scsi_prot_sg_count(scsi_cmnd
), datadir
);
2713 if (unlikely(!protsegcnt
)) {
2714 scsi_dma_unmap(scsi_cmnd
);
2718 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
2719 if (lpfc_cmd
->prot_seg_cnt
2720 > phba
->cfg_prot_sg_seg_cnt
) {
2721 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2722 "9068 BLKGRD: %s: Too many prot sg "
2723 "segments from dma_map_sg. Config %d,"
2724 "prot_seg_cnt %d\n", __func__
,
2725 phba
->cfg_prot_sg_seg_cnt
,
2726 lpfc_cmd
->prot_seg_cnt
);
2727 dma_unmap_sg(&phba
->pcidev
->dev
,
2728 scsi_prot_sglist(scsi_cmnd
),
2729 scsi_prot_sg_count(scsi_cmnd
),
2731 scsi_dma_unmap(scsi_cmnd
);
2735 num_bde
= lpfc_bg_setup_bpl_prot(phba
, scsi_cmnd
, bpl
,
2736 datasegcnt
, protsegcnt
);
2737 /* we should have 3 or more entries in buffer list */
2742 case LPFC_PG_TYPE_INVALID
:
2744 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2745 "9022 Unexpected protection group %i\n",
2752 * Finish initializing those IOCB fields that are dependent on the
2753 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2754 * reinitialized since all iocb memory resources are used many times
2755 * for transmit, receive, and continuation bpl's.
2757 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
2758 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
+= (num_bde
* sizeof(struct ulp_bde64
));
2759 iocb_cmd
->ulpBdeCount
= 1;
2760 iocb_cmd
->ulpLe
= 1;
2762 fcpdl
= scsi_bufflen(scsi_cmnd
);
2764 if (scsi_get_prot_type(scsi_cmnd
) == SCSI_PROT_DIF_TYPE1
) {
2766 * We are in DIF Type 1 mode
2767 * Every data block has a 8 byte DIF (trailer)
2768 * attached to it. Must ajust FCP data length
2770 blksize
= lpfc_cmd_blksize(scsi_cmnd
);
2771 diflen
= (fcpdl
/ blksize
) * 8;
2774 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
2777 * Due to difference in data length between DIF/non-DIF paths,
2778 * we need to set word 4 of IOCB here
2780 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
2784 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2785 "9023 Could not setup all needed BDE's"
2786 "prot_group_type=%d, num_bde=%d\n",
2787 prot_group_type
, num_bde
);
2792 * This function checks for BlockGuard errors detected by
2793 * the HBA. In case of errors, the ASC/ASCQ fields in the
2794 * sense buffer will be set accordingly, paired with
2795 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2796 * detected corruption.
2799 * 0 - No error found
2800 * 1 - BlockGuard error found
2801 * -1 - Internal error (bad profile, ...etc)
2804 lpfc_parse_bg_err(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
,
2805 struct lpfc_iocbq
*pIocbOut
)
2807 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
2808 struct sli3_bg_fields
*bgf
= &pIocbOut
->iocb
.unsli3
.sli3_bg
;
2810 uint32_t bghm
= bgf
->bghm
;
2811 uint32_t bgstat
= bgf
->bgstat
;
2812 uint64_t failing_sector
= 0;
2814 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9069 BLKGRD: BG ERROR in cmd"
2815 " 0x%x lba 0x%llx blk cnt 0x%x "
2816 "bgstat=0x%x bghm=0x%x\n",
2817 cmd
->cmnd
[0], (unsigned long long)scsi_get_lba(cmd
),
2818 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
2820 spin_lock(&_dump_buf_lock
);
2821 if (!_dump_buf_done
) {
2822 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9070 BLKGRD: Saving"
2823 " Data for %u blocks to debugfs\n",
2824 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
2825 lpfc_debug_save_data(phba
, cmd
);
2827 /* If we have a prot sgl, save the DIF buffer */
2828 if (lpfc_prot_group_type(phba
, cmd
) ==
2829 LPFC_PG_TYPE_DIF_BUF
) {
2830 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9071 BLKGRD: "
2831 "Saving DIF for %u blocks to debugfs\n",
2832 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
2833 lpfc_debug_save_dif(phba
, cmd
);
2838 spin_unlock(&_dump_buf_lock
);
2840 if (lpfc_bgs_get_invalid_prof(bgstat
)) {
2841 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2842 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9072 BLKGRD: Invalid"
2843 " BlockGuard profile. bgstat:0x%x\n",
2849 if (lpfc_bgs_get_uninit_dif_block(bgstat
)) {
2850 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2851 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9073 BLKGRD: "
2852 "Invalid BlockGuard DIF Block. bgstat:0x%x\n",
2858 if (lpfc_bgs_get_guard_err(bgstat
)) {
2861 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2863 cmd
->result
= DRIVER_SENSE
<< 24
2864 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2865 phba
->bg_guard_err_cnt
++;
2866 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2867 "9055 BLKGRD: guard_tag error\n");
2870 if (lpfc_bgs_get_reftag_err(bgstat
)) {
2873 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2875 cmd
->result
= DRIVER_SENSE
<< 24
2876 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2878 phba
->bg_reftag_err_cnt
++;
2879 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2880 "9056 BLKGRD: ref_tag error\n");
2883 if (lpfc_bgs_get_apptag_err(bgstat
)) {
2886 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2888 cmd
->result
= DRIVER_SENSE
<< 24
2889 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2891 phba
->bg_apptag_err_cnt
++;
2892 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2893 "9061 BLKGRD: app_tag error\n");
2896 if (lpfc_bgs_get_hi_water_mark_present(bgstat
)) {
2898 * setup sense data descriptor 0 per SPC-4 as an information
2899 * field, and put the failing LBA in it.
2900 * This code assumes there was also a guard/app/ref tag error
2903 cmd
->sense_buffer
[7] = 0xc; /* Additional sense length */
2904 cmd
->sense_buffer
[8] = 0; /* Information descriptor type */
2905 cmd
->sense_buffer
[9] = 0xa; /* Additional descriptor length */
2906 cmd
->sense_buffer
[10] = 0x80; /* Validity bit */
2908 /* bghm is a "on the wire" FC frame based count */
2909 switch (scsi_get_prot_op(cmd
)) {
2910 case SCSI_PROT_READ_INSERT
:
2911 case SCSI_PROT_WRITE_STRIP
:
2912 bghm
/= cmd
->device
->sector_size
;
2914 case SCSI_PROT_READ_STRIP
:
2915 case SCSI_PROT_WRITE_INSERT
:
2916 case SCSI_PROT_READ_PASS
:
2917 case SCSI_PROT_WRITE_PASS
:
2918 bghm
/= (cmd
->device
->sector_size
+
2919 sizeof(struct scsi_dif_tuple
));
2923 failing_sector
= scsi_get_lba(cmd
);
2924 failing_sector
+= bghm
;
2926 /* Descriptor Information */
2927 put_unaligned_be64(failing_sector
, &cmd
->sense_buffer
[12]);
2931 /* No error was reported - problem in FW? */
2932 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2933 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2934 "9057 BLKGRD: Unknown error reported!\n");
2942 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
2943 * @phba: The Hba for which this call is being executed.
2944 * @lpfc_cmd: The scsi buffer which is going to be mapped.
2946 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
2947 * field of @lpfc_cmd for device with SLI-4 interface spec.
2954 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
2956 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2957 struct scatterlist
*sgel
= NULL
;
2958 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2959 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
2960 struct sli4_sge
*first_data_sgl
;
2961 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2962 dma_addr_t physaddr
;
2963 uint32_t num_bde
= 0;
2965 uint32_t dma_offset
= 0;
2967 struct ulp_bde64
*bde
;
2970 * There are three possibilities here - use scatter-gather segment, use
2971 * the single mapping, or neither. Start the lpfc command prep by
2972 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
2975 if (scsi_sg_count(scsi_cmnd
)) {
2977 * The driver stores the segment count returned from pci_map_sg
2978 * because this a count of dma-mappings used to map the use_sg
2979 * pages. They are not guaranteed to be the same for those
2980 * architectures that implement an IOMMU.
2983 nseg
= scsi_dma_map(scsi_cmnd
);
2984 if (unlikely(!nseg
))
2987 /* clear the last flag in the fcp_rsp map entry */
2988 sgl
->word2
= le32_to_cpu(sgl
->word2
);
2989 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2990 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2992 first_data_sgl
= sgl
;
2993 lpfc_cmd
->seg_cnt
= nseg
;
2994 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
2995 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9074 BLKGRD:"
2996 " %s: Too many sg segments from "
2997 "dma_map_sg. Config %d, seg_cnt %d\n",
2998 __func__
, phba
->cfg_sg_seg_cnt
,
3000 scsi_dma_unmap(scsi_cmnd
);
3005 * The driver established a maximum scatter-gather segment count
3006 * during probe that limits the number of sg elements in any
3007 * single scsi command. Just run through the seg_cnt and format
3009 * When using SLI-3 the driver will try to fit all the BDEs into
3010 * the IOCB. If it can't then the BDEs get added to a BPL as it
3011 * does for SLI-2 mode.
3013 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
3014 physaddr
= sg_dma_address(sgel
);
3015 dma_len
= sg_dma_len(sgel
);
3016 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
3017 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
3018 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3019 if ((num_bde
+ 1) == nseg
)
3020 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3022 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3023 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
3024 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
3025 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3026 sgl
->sge_len
= cpu_to_le32(dma_len
);
3027 dma_offset
+= dma_len
;
3030 /* setup the performance hint (first data BDE) if enabled */
3031 if (phba
->sli3_options
& LPFC_SLI4_PERFH_ENABLED
) {
3032 bde
= (struct ulp_bde64
*)
3033 &(iocb_cmd
->unsli3
.sli3Words
[5]);
3034 bde
->addrLow
= first_data_sgl
->addr_lo
;
3035 bde
->addrHigh
= first_data_sgl
->addr_hi
;
3036 bde
->tus
.f
.bdeSize
=
3037 le32_to_cpu(first_data_sgl
->sge_len
);
3038 bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
3039 bde
->tus
.w
= cpu_to_le32(bde
->tus
.w
);
3043 /* clear the last flag in the fcp_rsp map entry */
3044 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3045 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3046 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3050 * Finish initializing those IOCB fields that are dependent on the
3051 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3052 * explicitly reinitialized.
3053 * all iocb memory resources are reused.
3055 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
3058 * Due to difference in data length between DIF/non-DIF paths,
3059 * we need to set word 4 of IOCB here
3061 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
3066 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
3067 * @phba: The Hba for which this call is being executed.
3068 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
3070 * Adjust the data length to account for how much data
3071 * is actually on the wire.
3073 * returns the adjusted data length
3076 lpfc_bg_scsi_adjust_dl(struct lpfc_hba
*phba
,
3077 struct lpfc_scsi_buf
*lpfc_cmd
)
3079 struct scsi_cmnd
*sc
= lpfc_cmd
->pCmd
;
3083 fcpdl
= scsi_bufflen(sc
);
3085 /* Check if there is protection data on the wire */
3086 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
3088 if (scsi_get_prot_op(sc
) == SCSI_PROT_READ_INSERT
)
3093 if (scsi_get_prot_op(sc
) == SCSI_PROT_WRITE_STRIP
)
3097 /* If protection data on the wire, adjust the count accordingly */
3098 blksize
= lpfc_cmd_blksize(sc
);
3099 diflen
= (fcpdl
/ blksize
) * 8;
3105 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3106 * @phba: The Hba for which this call is being executed.
3107 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3109 * This is the protection/DIF aware version of
3110 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3111 * two functions eventually, but for now, it's here
3114 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
,
3115 struct lpfc_scsi_buf
*lpfc_cmd
)
3117 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3118 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3119 struct sli4_sge
*sgl
= (struct sli4_sge
*)(lpfc_cmd
->fcp_bpl
);
3120 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3121 uint32_t num_bde
= 0;
3122 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
3123 int prot_group_type
= 0;
3127 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3128 * fcp_rsp regions to the first data bde entry
3130 if (scsi_sg_count(scsi_cmnd
)) {
3132 * The driver stores the segment count returned from pci_map_sg
3133 * because this a count of dma-mappings used to map the use_sg
3134 * pages. They are not guaranteed to be the same for those
3135 * architectures that implement an IOMMU.
3137 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3138 scsi_sglist(scsi_cmnd
),
3139 scsi_sg_count(scsi_cmnd
), datadir
);
3140 if (unlikely(!datasegcnt
))
3144 /* clear the last flag in the fcp_rsp map entry */
3145 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3146 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3147 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3150 lpfc_cmd
->seg_cnt
= datasegcnt
;
3151 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
3152 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
3153 "9087 BLKGRD: %s: Too many sg segments"
3154 " from dma_map_sg. Config %d, seg_cnt"
3156 __func__
, phba
->cfg_sg_seg_cnt
,
3158 scsi_dma_unmap(scsi_cmnd
);
3162 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
3164 switch (prot_group_type
) {
3165 case LPFC_PG_TYPE_NO_DIF
:
3166 num_bde
= lpfc_bg_setup_sgl(phba
, scsi_cmnd
, sgl
,
3168 /* we should have 2 or more entries in buffer list */
3172 case LPFC_PG_TYPE_DIF_BUF
:{
3174 * This type indicates that protection buffers are
3175 * passed to the driver, so that needs to be prepared
3178 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3179 scsi_prot_sglist(scsi_cmnd
),
3180 scsi_prot_sg_count(scsi_cmnd
), datadir
);
3181 if (unlikely(!protsegcnt
)) {
3182 scsi_dma_unmap(scsi_cmnd
);
3186 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
3187 if (lpfc_cmd
->prot_seg_cnt
3188 > phba
->cfg_prot_sg_seg_cnt
) {
3189 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
3190 "9088 BLKGRD: %s: Too many prot sg "
3191 "segments from dma_map_sg. Config %d,"
3192 "prot_seg_cnt %d\n", __func__
,
3193 phba
->cfg_prot_sg_seg_cnt
,
3194 lpfc_cmd
->prot_seg_cnt
);
3195 dma_unmap_sg(&phba
->pcidev
->dev
,
3196 scsi_prot_sglist(scsi_cmnd
),
3197 scsi_prot_sg_count(scsi_cmnd
),
3199 scsi_dma_unmap(scsi_cmnd
);
3203 num_bde
= lpfc_bg_setup_sgl_prot(phba
, scsi_cmnd
, sgl
,
3204 datasegcnt
, protsegcnt
);
3205 /* we should have 3 or more entries in buffer list */
3210 case LPFC_PG_TYPE_INVALID
:
3212 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3213 "9083 Unexpected protection group %i\n",
3219 fcpdl
= lpfc_bg_scsi_adjust_dl(phba
, lpfc_cmd
);
3221 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
3224 * Due to difference in data length between DIF/non-DIF paths,
3225 * we need to set word 4 of IOCB here
3227 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
3228 lpfc_cmd
->cur_iocbq
.iocb_flag
|= LPFC_IO_DIF
;
3232 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3233 "9084 Could not setup all needed BDE's"
3234 "prot_group_type=%d, num_bde=%d\n",
3235 prot_group_type
, num_bde
);
3240 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3241 * @phba: The Hba for which this call is being executed.
3242 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3244 * This routine wraps the actual DMA mapping function pointer from the
3252 lpfc_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3254 return phba
->lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3258 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3260 * @phba: The Hba for which this call is being executed.
3261 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3263 * This routine wraps the actual DMA mapping function pointer from the
3271 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3273 return phba
->lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3277 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3278 * @phba: Pointer to hba context object.
3279 * @vport: Pointer to vport object.
3280 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3281 * @rsp_iocb: Pointer to response iocb object which reported error.
3283 * This function posts an event when there is a SCSI command reporting
3284 * error from the scsi device.
3287 lpfc_send_scsi_error_event(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
3288 struct lpfc_scsi_buf
*lpfc_cmd
, struct lpfc_iocbq
*rsp_iocb
) {
3289 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3290 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3291 uint32_t resp_info
= fcprsp
->rspStatus2
;
3292 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3293 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3294 struct lpfc_fast_path_event
*fast_path_evt
= NULL
;
3295 struct lpfc_nodelist
*pnode
= lpfc_cmd
->rdata
->pnode
;
3296 unsigned long flags
;
3298 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3301 /* If there is queuefull or busy condition send a scsi event */
3302 if ((cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ||
3303 (cmnd
->result
== SAM_STAT_BUSY
)) {
3304 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3307 fast_path_evt
->un
.scsi_evt
.event_type
=
3309 fast_path_evt
->un
.scsi_evt
.subcategory
=
3310 (cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ?
3311 LPFC_EVENT_QFULL
: LPFC_EVENT_DEVBSY
;
3312 fast_path_evt
->un
.scsi_evt
.lun
= cmnd
->device
->lun
;
3313 memcpy(&fast_path_evt
->un
.scsi_evt
.wwpn
,
3314 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3315 memcpy(&fast_path_evt
->un
.scsi_evt
.wwnn
,
3316 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3317 } else if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
&&
3318 ((cmnd
->cmnd
[0] == READ_10
) || (cmnd
->cmnd
[0] == WRITE_10
))) {
3319 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3322 fast_path_evt
->un
.check_cond_evt
.scsi_event
.event_type
=
3324 fast_path_evt
->un
.check_cond_evt
.scsi_event
.subcategory
=
3325 LPFC_EVENT_CHECK_COND
;
3326 fast_path_evt
->un
.check_cond_evt
.scsi_event
.lun
=
3328 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwpn
,
3329 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3330 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwnn
,
3331 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3332 fast_path_evt
->un
.check_cond_evt
.sense_key
=
3333 cmnd
->sense_buffer
[2] & 0xf;
3334 fast_path_evt
->un
.check_cond_evt
.asc
= cmnd
->sense_buffer
[12];
3335 fast_path_evt
->un
.check_cond_evt
.ascq
= cmnd
->sense_buffer
[13];
3336 } else if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3338 ((be32_to_cpu(fcprsp
->rspResId
) != fcpi_parm
) ||
3339 ((scsi_status
== SAM_STAT_GOOD
) &&
3340 !(resp_info
& (RESID_UNDER
| RESID_OVER
))))) {
3342 * If status is good or resid does not match with fcp_param and
3343 * there is valid fcpi_parm, then there is a read_check error
3345 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3348 fast_path_evt
->un
.read_check_error
.header
.event_type
=
3349 FC_REG_FABRIC_EVENT
;
3350 fast_path_evt
->un
.read_check_error
.header
.subcategory
=
3351 LPFC_EVENT_FCPRDCHKERR
;
3352 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwpn
,
3353 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3354 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwnn
,
3355 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3356 fast_path_evt
->un
.read_check_error
.lun
= cmnd
->device
->lun
;
3357 fast_path_evt
->un
.read_check_error
.opcode
= cmnd
->cmnd
[0];
3358 fast_path_evt
->un
.read_check_error
.fcpiparam
=
3363 fast_path_evt
->vport
= vport
;
3364 spin_lock_irqsave(&phba
->hbalock
, flags
);
3365 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
3366 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3367 lpfc_worker_wake_up(phba
);
3372 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3373 * @phba: The HBA for which this call is being executed.
3374 * @psb: The scsi buffer which is going to be un-mapped.
3376 * This routine does DMA un-mapping of scatter gather list of scsi command
3377 * field of @lpfc_cmd for device with SLI-3 interface spec.
3380 lpfc_scsi_unprep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
3383 * There are only two special cases to consider. (1) the scsi command
3384 * requested scatter-gather usage or (2) the scsi command allocated
3385 * a request buffer, but did not request use_sg. There is a third
3386 * case, but it does not require resource deallocation.
3388 if (psb
->seg_cnt
> 0)
3389 scsi_dma_unmap(psb
->pCmd
);
3390 if (psb
->prot_seg_cnt
> 0)
3391 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(psb
->pCmd
),
3392 scsi_prot_sg_count(psb
->pCmd
),
3393 psb
->pCmd
->sc_data_direction
);
3397 * lpfc_handler_fcp_err - FCP response handler
3398 * @vport: The virtual port for which this call is being executed.
3399 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3400 * @rsp_iocb: The response IOCB which contains FCP error.
3402 * This routine is called to process response IOCB with status field
3403 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3404 * based upon SCSI and FCP error.
3407 lpfc_handle_fcp_err(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
3408 struct lpfc_iocbq
*rsp_iocb
)
3410 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3411 struct fcp_cmnd
*fcpcmd
= lpfc_cmd
->fcp_cmnd
;
3412 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3413 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3414 uint32_t resp_info
= fcprsp
->rspStatus2
;
3415 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3417 uint32_t host_status
= DID_OK
;
3418 uint32_t rsplen
= 0;
3419 uint32_t logit
= LOG_FCP
| LOG_FCP_ERROR
;
3423 * If this is a task management command, there is no
3424 * scsi packet associated with this lpfc_cmd. The driver
3427 if (fcpcmd
->fcpCntl2
) {
3432 if (resp_info
& RSP_LEN_VALID
) {
3433 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3434 if (rsplen
!= 0 && rsplen
!= 4 && rsplen
!= 8) {
3435 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3436 "2719 Invalid response length: "
3437 "tgt x%x lun x%x cmnd x%x rsplen x%x\n",
3439 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3441 host_status
= DID_ERROR
;
3444 if (fcprsp
->rspInfo3
!= RSP_NO_FAILURE
) {
3445 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3446 "2757 Protocol failure detected during "
3447 "processing of FCP I/O op: "
3448 "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n",
3450 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3452 host_status
= DID_ERROR
;
3457 if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
) {
3458 uint32_t snslen
= be32_to_cpu(fcprsp
->rspSnsLen
);
3459 if (snslen
> SCSI_SENSE_BUFFERSIZE
)
3460 snslen
= SCSI_SENSE_BUFFERSIZE
;
3462 if (resp_info
& RSP_LEN_VALID
)
3463 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3464 memcpy(cmnd
->sense_buffer
, &fcprsp
->rspInfo0
+ rsplen
, snslen
);
3466 lp
= (uint32_t *)cmnd
->sense_buffer
;
3468 if (!scsi_status
&& (resp_info
& RESID_UNDER
) &&
3469 vport
->cfg_log_verbose
& LOG_FCP_UNDER
)
3470 logit
= LOG_FCP_UNDER
;
3472 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3473 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3474 "Data: x%x x%x x%x x%x x%x\n",
3475 cmnd
->cmnd
[0], scsi_status
,
3476 be32_to_cpu(*lp
), be32_to_cpu(*(lp
+ 3)), resp_info
,
3477 be32_to_cpu(fcprsp
->rspResId
),
3478 be32_to_cpu(fcprsp
->rspSnsLen
),
3479 be32_to_cpu(fcprsp
->rspRspLen
),
3482 scsi_set_resid(cmnd
, 0);
3483 if (resp_info
& RESID_UNDER
) {
3484 scsi_set_resid(cmnd
, be32_to_cpu(fcprsp
->rspResId
));
3486 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_UNDER
,
3487 "9025 FCP Read Underrun, expected %d, "
3488 "residual %d Data: x%x x%x x%x\n",
3489 be32_to_cpu(fcpcmd
->fcpDl
),
3490 scsi_get_resid(cmnd
), fcpi_parm
, cmnd
->cmnd
[0],
3494 * If there is an under run check if under run reported by
3495 * storage array is same as the under run reported by HBA.
3496 * If this is not same, there is a dropped frame.
3498 if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3500 (scsi_get_resid(cmnd
) != fcpi_parm
)) {
3501 lpfc_printf_vlog(vport
, KERN_WARNING
,
3502 LOG_FCP
| LOG_FCP_ERROR
,
3503 "9026 FCP Read Check Error "
3504 "and Underrun Data: x%x x%x x%x x%x\n",
3505 be32_to_cpu(fcpcmd
->fcpDl
),
3506 scsi_get_resid(cmnd
), fcpi_parm
,
3508 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3509 host_status
= DID_ERROR
;
3512 * The cmnd->underflow is the minimum number of bytes that must
3513 * be transferred for this command. Provided a sense condition
3514 * is not present, make sure the actual amount transferred is at
3515 * least the underflow value or fail.
3517 if (!(resp_info
& SNS_LEN_VALID
) &&
3518 (scsi_status
== SAM_STAT_GOOD
) &&
3519 (scsi_bufflen(cmnd
) - scsi_get_resid(cmnd
)
3520 < cmnd
->underflow
)) {
3521 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3522 "9027 FCP command x%x residual "
3523 "underrun converted to error "
3524 "Data: x%x x%x x%x\n",
3525 cmnd
->cmnd
[0], scsi_bufflen(cmnd
),
3526 scsi_get_resid(cmnd
), cmnd
->underflow
);
3527 host_status
= DID_ERROR
;
3529 } else if (resp_info
& RESID_OVER
) {
3530 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3531 "9028 FCP command x%x residual overrun error. "
3532 "Data: x%x x%x\n", cmnd
->cmnd
[0],
3533 scsi_bufflen(cmnd
), scsi_get_resid(cmnd
));
3534 host_status
= DID_ERROR
;
3537 * Check SLI validation that all the transfer was actually done
3538 * (fcpi_parm should be zero). Apply check only to reads.
3540 } else if (fcpi_parm
&& (cmnd
->sc_data_direction
== DMA_FROM_DEVICE
)) {
3541 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
| LOG_FCP_ERROR
,
3542 "9029 FCP Read Check Error Data: "
3543 "x%x x%x x%x x%x x%x\n",
3544 be32_to_cpu(fcpcmd
->fcpDl
),
3545 be32_to_cpu(fcprsp
->rspResId
),
3546 fcpi_parm
, cmnd
->cmnd
[0], scsi_status
);
3547 switch (scsi_status
) {
3549 case SAM_STAT_CHECK_CONDITION
:
3550 /* Fabric dropped a data frame. Fail any successful
3551 * command in which we detected dropped frames.
3552 * A status of good or some check conditions could
3553 * be considered a successful command.
3555 host_status
= DID_ERROR
;
3558 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3562 cmnd
->result
= ScsiResult(host_status
, scsi_status
);
3563 lpfc_send_scsi_error_event(vport
->phba
, vport
, lpfc_cmd
, rsp_iocb
);
3567 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3568 * @phba: The Hba for which this call is being executed.
3569 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3570 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3572 * This routine assigns scsi command result by looking into response IOCB
3573 * status field appropriately. This routine handles QUEUE FULL condition as
3574 * well by ramping down device queue depth.
3577 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pIocbIn
,
3578 struct lpfc_iocbq
*pIocbOut
)
3580 struct lpfc_scsi_buf
*lpfc_cmd
=
3581 (struct lpfc_scsi_buf
*) pIocbIn
->context1
;
3582 struct lpfc_vport
*vport
= pIocbIn
->vport
;
3583 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
3584 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
3585 struct scsi_cmnd
*cmd
;
3587 struct scsi_device
*tmp_sdev
;
3589 unsigned long flags
;
3590 struct lpfc_fast_path_event
*fast_path_evt
;
3591 struct Scsi_Host
*shost
;
3592 uint32_t queue_depth
, scsi_id
;
3593 uint32_t logit
= LOG_FCP
;
3595 /* Sanity check on return of outstanding command */
3596 if (!(lpfc_cmd
->pCmd
))
3598 cmd
= lpfc_cmd
->pCmd
;
3599 shost
= cmd
->device
->host
;
3601 lpfc_cmd
->result
= pIocbOut
->iocb
.un
.ulpWord
[4];
3602 lpfc_cmd
->status
= pIocbOut
->iocb
.ulpStatus
;
3603 /* pick up SLI4 exhange busy status from HBA */
3604 lpfc_cmd
->exch_busy
= pIocbOut
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
3606 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3607 if (lpfc_cmd
->prot_data_type
) {
3608 struct scsi_dif_tuple
*src
= NULL
;
3610 src
= (struct scsi_dif_tuple
*)lpfc_cmd
->prot_data_segment
;
3612 * Used to restore any changes to protection
3613 * data for error injection.
3615 switch (lpfc_cmd
->prot_data_type
) {
3616 case LPFC_INJERR_REFTAG
:
3618 lpfc_cmd
->prot_data
;
3620 case LPFC_INJERR_APPTAG
:
3622 (uint16_t)lpfc_cmd
->prot_data
;
3624 case LPFC_INJERR_GUARD
:
3626 (uint16_t)lpfc_cmd
->prot_data
;
3632 lpfc_cmd
->prot_data
= 0;
3633 lpfc_cmd
->prot_data_type
= 0;
3634 lpfc_cmd
->prot_data_segment
= NULL
;
3637 if (pnode
&& NLP_CHK_NODE_ACT(pnode
))
3638 atomic_dec(&pnode
->cmd_pending
);
3640 if (lpfc_cmd
->status
) {
3641 if (lpfc_cmd
->status
== IOSTAT_LOCAL_REJECT
&&
3642 (lpfc_cmd
->result
& IOERR_DRVR_MASK
))
3643 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
3644 else if (lpfc_cmd
->status
>= IOSTAT_CNT
)
3645 lpfc_cmd
->status
= IOSTAT_DEFAULT
;
3646 if (lpfc_cmd
->status
== IOSTAT_FCP_RSP_ERROR
3647 && !lpfc_cmd
->fcp_rsp
->rspStatus3
3648 && (lpfc_cmd
->fcp_rsp
->rspStatus2
& RESID_UNDER
)
3649 && !(phba
->cfg_log_verbose
& LOG_FCP_UNDER
))
3652 logit
= LOG_FCP
| LOG_FCP_UNDER
;
3653 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3654 "9030 FCP cmd x%x failed <%d/%d> "
3655 "status: x%x result: x%x Data: x%x x%x\n",
3657 cmd
->device
? cmd
->device
->id
: 0xffff,
3658 cmd
->device
? cmd
->device
->lun
: 0xffff,
3659 lpfc_cmd
->status
, lpfc_cmd
->result
,
3660 pIocbOut
->iocb
.ulpContext
,
3661 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
3663 switch (lpfc_cmd
->status
) {
3664 case IOSTAT_FCP_RSP_ERROR
:
3665 /* Call FCP RSP handler to determine result */
3666 lpfc_handle_fcp_err(vport
, lpfc_cmd
, pIocbOut
);
3668 case IOSTAT_NPORT_BSY
:
3669 case IOSTAT_FABRIC_BSY
:
3670 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
, 0);
3671 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3674 fast_path_evt
->un
.fabric_evt
.event_type
=
3675 FC_REG_FABRIC_EVENT
;
3676 fast_path_evt
->un
.fabric_evt
.subcategory
=
3677 (lpfc_cmd
->status
== IOSTAT_NPORT_BSY
) ?
3678 LPFC_EVENT_PORT_BUSY
: LPFC_EVENT_FABRIC_BUSY
;
3679 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3680 memcpy(&fast_path_evt
->un
.fabric_evt
.wwpn
,
3681 &pnode
->nlp_portname
,
3682 sizeof(struct lpfc_name
));
3683 memcpy(&fast_path_evt
->un
.fabric_evt
.wwnn
,
3684 &pnode
->nlp_nodename
,
3685 sizeof(struct lpfc_name
));
3687 fast_path_evt
->vport
= vport
;
3688 fast_path_evt
->work_evt
.evt
=
3689 LPFC_EVT_FASTPATH_MGMT_EVT
;
3690 spin_lock_irqsave(&phba
->hbalock
, flags
);
3691 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
,
3693 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3694 lpfc_worker_wake_up(phba
);
3696 case IOSTAT_LOCAL_REJECT
:
3697 case IOSTAT_REMOTE_STOP
:
3698 if (lpfc_cmd
->result
== IOERR_ELXSEC_KEY_UNWRAP_ERROR
||
3700 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR
||
3701 lpfc_cmd
->result
== IOERR_ELXSEC_CRYPTO_ERROR
||
3703 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR
) {
3704 cmd
->result
= ScsiResult(DID_NO_CONNECT
, 0);
3707 if (lpfc_cmd
->result
== IOERR_INVALID_RPI
||
3708 lpfc_cmd
->result
== IOERR_NO_RESOURCES
||
3709 lpfc_cmd
->result
== IOERR_ABORT_REQUESTED
||
3710 lpfc_cmd
->result
== IOERR_SLER_CMD_RCV_FAILURE
) {
3711 cmd
->result
= ScsiResult(DID_REQUEUE
, 0);
3714 if ((lpfc_cmd
->result
== IOERR_RX_DMA_FAILED
||
3715 lpfc_cmd
->result
== IOERR_TX_DMA_FAILED
) &&
3716 pIocbOut
->iocb
.unsli3
.sli3_bg
.bgstat
) {
3717 if (scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
3719 * This is a response for a BG enabled
3720 * cmd. Parse BG error
3722 lpfc_parse_bg_err(phba
, lpfc_cmd
,
3726 lpfc_printf_vlog(vport
, KERN_WARNING
,
3728 "9031 non-zero BGSTAT "
3729 "on unprotected cmd\n");
3732 if ((lpfc_cmd
->status
== IOSTAT_REMOTE_STOP
)
3733 && (phba
->sli_rev
== LPFC_SLI_REV4
)
3734 && (pnode
&& NLP_CHK_NODE_ACT(pnode
))) {
3735 /* This IO was aborted by the target, we don't
3736 * know the rxid and because we did not send the
3737 * ABTS we cannot generate and RRQ.
3739 lpfc_set_rrq_active(phba
, pnode
,
3740 lpfc_cmd
->cur_iocbq
.sli4_xritag
,
3743 /* else: fall through */
3745 cmd
->result
= ScsiResult(DID_ERROR
, 0);
3749 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
)
3750 || (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
3751 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
,
3754 cmd
->result
= ScsiResult(DID_OK
, 0);
3756 if (cmd
->result
|| lpfc_cmd
->fcp_rsp
->rspSnsLen
) {
3757 uint32_t *lp
= (uint32_t *)cmd
->sense_buffer
;
3759 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3760 "0710 Iodone <%d/%d> cmd %p, error "
3761 "x%x SNS x%x x%x Data: x%x x%x\n",
3762 cmd
->device
->id
, cmd
->device
->lun
, cmd
,
3763 cmd
->result
, *lp
, *(lp
+ 3), cmd
->retries
,
3764 scsi_get_resid(cmd
));
3767 lpfc_update_stats(phba
, lpfc_cmd
);
3768 result
= cmd
->result
;
3769 if (vport
->cfg_max_scsicmpl_time
&&
3770 time_after(jiffies
, lpfc_cmd
->start_time
+
3771 msecs_to_jiffies(vport
->cfg_max_scsicmpl_time
))) {
3772 spin_lock_irqsave(shost
->host_lock
, flags
);
3773 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3774 if (pnode
->cmd_qdepth
>
3775 atomic_read(&pnode
->cmd_pending
) &&
3776 (atomic_read(&pnode
->cmd_pending
) >
3777 LPFC_MIN_TGT_QDEPTH
) &&
3778 ((cmd
->cmnd
[0] == READ_10
) ||
3779 (cmd
->cmnd
[0] == WRITE_10
)))
3781 atomic_read(&pnode
->cmd_pending
);
3783 pnode
->last_change_time
= jiffies
;
3785 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3786 } else if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3787 if ((pnode
->cmd_qdepth
< vport
->cfg_tgt_queue_depth
) &&
3788 time_after(jiffies
, pnode
->last_change_time
+
3789 msecs_to_jiffies(LPFC_TGTQ_INTERVAL
))) {
3790 spin_lock_irqsave(shost
->host_lock
, flags
);
3791 depth
= pnode
->cmd_qdepth
* LPFC_TGTQ_RAMPUP_PCENT
3793 depth
= depth
? depth
: 1;
3794 pnode
->cmd_qdepth
+= depth
;
3795 if (pnode
->cmd_qdepth
> vport
->cfg_tgt_queue_depth
)
3796 pnode
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
3797 pnode
->last_change_time
= jiffies
;
3798 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3802 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
3804 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
3805 queue_depth
= cmd
->device
->queue_depth
;
3806 scsi_id
= cmd
->device
->id
;
3807 cmd
->scsi_done(cmd
);
3809 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
3811 * If there is a thread waiting for command completion
3812 * wake up the thread.
3814 spin_lock_irqsave(shost
->host_lock
, flags
);
3815 lpfc_cmd
->pCmd
= NULL
;
3816 if (lpfc_cmd
->waitq
)
3817 wake_up(lpfc_cmd
->waitq
);
3818 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3819 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3824 lpfc_rampup_queue_depth(vport
, queue_depth
);
3827 * Check for queue full. If the lun is reporting queue full, then
3828 * back off the lun queue depth to prevent target overloads.
3830 if (result
== SAM_STAT_TASK_SET_FULL
&& pnode
&&
3831 NLP_CHK_NODE_ACT(pnode
)) {
3832 shost_for_each_device(tmp_sdev
, shost
) {
3833 if (tmp_sdev
->id
!= scsi_id
)
3835 depth
= scsi_track_queue_full(tmp_sdev
,
3836 tmp_sdev
->queue_depth
-1);
3839 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3840 "0711 detected queue full - lun queue "
3841 "depth adjusted to %d.\n", depth
);
3842 lpfc_send_sdev_queuedepth_change_event(phba
, vport
,
3850 * If there is a thread waiting for command completion
3851 * wake up the thread.
3853 spin_lock_irqsave(shost
->host_lock
, flags
);
3854 lpfc_cmd
->pCmd
= NULL
;
3855 if (lpfc_cmd
->waitq
)
3856 wake_up(lpfc_cmd
->waitq
);
3857 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3859 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3863 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
3864 * @data: A pointer to the immediate command data portion of the IOCB.
3865 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
3867 * The routine copies the entire FCP command from @fcp_cmnd to @data while
3868 * byte swapping the data to big endian format for transmission on the wire.
3871 lpfc_fcpcmd_to_iocb(uint8_t *data
, struct fcp_cmnd
*fcp_cmnd
)
3874 for (i
= 0, j
= 0; i
< sizeof(struct fcp_cmnd
);
3875 i
+= sizeof(uint32_t), j
++) {
3876 ((uint32_t *)data
)[j
] = cpu_to_be32(((uint32_t *)fcp_cmnd
)[j
]);
3881 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
3882 * @vport: The virtual port for which this call is being executed.
3883 * @lpfc_cmd: The scsi command which needs to send.
3884 * @pnode: Pointer to lpfc_nodelist.
3886 * This routine initializes fcp_cmnd and iocb data structure from scsi command
3887 * to transfer for device with SLI3 interface spec.
3890 lpfc_scsi_prep_cmnd(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
3891 struct lpfc_nodelist
*pnode
)
3893 struct lpfc_hba
*phba
= vport
->phba
;
3894 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3895 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3896 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3897 struct lpfc_iocbq
*piocbq
= &(lpfc_cmd
->cur_iocbq
);
3898 int datadir
= scsi_cmnd
->sc_data_direction
;
3901 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3904 lpfc_cmd
->fcp_rsp
->rspSnsLen
= 0;
3905 /* clear task management bits */
3906 lpfc_cmd
->fcp_cmnd
->fcpCntl2
= 0;
3908 int_to_scsilun(lpfc_cmd
->pCmd
->device
->lun
,
3909 &lpfc_cmd
->fcp_cmnd
->fcp_lun
);
3911 memset(&fcp_cmnd
->fcpCdb
[0], 0, LPFC_FCP_CDB_LEN
);
3912 memcpy(&fcp_cmnd
->fcpCdb
[0], scsi_cmnd
->cmnd
, scsi_cmnd
->cmd_len
);
3913 if (scsi_populate_tag_msg(scsi_cmnd
, tag
)) {
3915 case HEAD_OF_QUEUE_TAG
:
3916 fcp_cmnd
->fcpCntl1
= HEAD_OF_Q
;
3918 case ORDERED_QUEUE_TAG
:
3919 fcp_cmnd
->fcpCntl1
= ORDERED_Q
;
3922 fcp_cmnd
->fcpCntl1
= SIMPLE_Q
;
3926 fcp_cmnd
->fcpCntl1
= 0;
3929 * There are three possibilities here - use scatter-gather segment, use
3930 * the single mapping, or neither. Start the lpfc command prep by
3931 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3934 if (scsi_sg_count(scsi_cmnd
)) {
3935 if (datadir
== DMA_TO_DEVICE
) {
3936 iocb_cmd
->ulpCommand
= CMD_FCP_IWRITE64_CR
;
3937 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3938 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
3939 iocb_cmd
->ulpPU
= 0;
3941 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
3942 fcp_cmnd
->fcpCntl3
= WRITE_DATA
;
3943 phba
->fc4OutputRequests
++;
3945 iocb_cmd
->ulpCommand
= CMD_FCP_IREAD64_CR
;
3946 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
3947 fcp_cmnd
->fcpCntl3
= READ_DATA
;
3948 phba
->fc4InputRequests
++;
3951 iocb_cmd
->ulpCommand
= CMD_FCP_ICMND64_CR
;
3952 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
3953 iocb_cmd
->ulpPU
= 0;
3954 fcp_cmnd
->fcpCntl3
= 0;
3955 phba
->fc4ControlRequests
++;
3957 if (phba
->sli_rev
== 3 &&
3958 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
3959 lpfc_fcpcmd_to_iocb(iocb_cmd
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
3961 * Finish initializing those IOCB fields that are independent
3962 * of the scsi_cmnd request_buffer
3964 piocbq
->iocb
.ulpContext
= pnode
->nlp_rpi
;
3965 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3966 piocbq
->iocb
.ulpContext
=
3967 phba
->sli4_hba
.rpi_ids
[pnode
->nlp_rpi
];
3968 if (pnode
->nlp_fcp_info
& NLP_FCP_2_DEVICE
)
3969 piocbq
->iocb
.ulpFCP2Rcvy
= 1;
3971 piocbq
->iocb
.ulpFCP2Rcvy
= 0;
3973 piocbq
->iocb
.ulpClass
= (pnode
->nlp_fcp_info
& 0x0f);
3974 piocbq
->context1
= lpfc_cmd
;
3975 piocbq
->iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
3976 piocbq
->iocb
.ulpTimeout
= lpfc_cmd
->timeout
;
3977 piocbq
->vport
= vport
;
3981 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
3982 * @vport: The virtual port for which this call is being executed.
3983 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3984 * @lun: Logical unit number.
3985 * @task_mgmt_cmd: SCSI task management command.
3987 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
3988 * for device with SLI-3 interface spec.
3995 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport
*vport
,
3996 struct lpfc_scsi_buf
*lpfc_cmd
,
3998 uint8_t task_mgmt_cmd
)
4000 struct lpfc_iocbq
*piocbq
;
4002 struct fcp_cmnd
*fcp_cmnd
;
4003 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
4004 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
4006 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) ||
4007 ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
4010 piocbq
= &(lpfc_cmd
->cur_iocbq
);
4011 piocbq
->vport
= vport
;
4013 piocb
= &piocbq
->iocb
;
4015 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4016 /* Clear out any old data in the FCP command area */
4017 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
4018 int_to_scsilun(lun
, &fcp_cmnd
->fcp_lun
);
4019 fcp_cmnd
->fcpCntl2
= task_mgmt_cmd
;
4020 if (vport
->phba
->sli_rev
== 3 &&
4021 !(vport
->phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
4022 lpfc_fcpcmd_to_iocb(piocb
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
4023 piocb
->ulpCommand
= CMD_FCP_ICMND64_CR
;
4024 piocb
->ulpContext
= ndlp
->nlp_rpi
;
4025 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4027 vport
->phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
4029 if (ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) {
4030 piocb
->ulpFCP2Rcvy
= 1;
4032 piocb
->ulpClass
= (ndlp
->nlp_fcp_info
& 0x0f);
4034 /* ulpTimeout is only one byte */
4035 if (lpfc_cmd
->timeout
> 0xff) {
4037 * Do not timeout the command at the firmware level.
4038 * The driver will provide the timeout mechanism.
4040 piocb
->ulpTimeout
= 0;
4042 piocb
->ulpTimeout
= lpfc_cmd
->timeout
;
4044 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
4045 lpfc_sli4_set_rsp_sgl_last(vport
->phba
, lpfc_cmd
);
4051 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4052 * @phba: The hba struct for which this call is being executed.
4053 * @dev_grp: The HBA PCI-Device group number.
4055 * This routine sets up the SCSI interface API function jump table in @phba
4057 * Returns: 0 - success, -ENODEV - failure.
4060 lpfc_scsi_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4063 phba
->lpfc_scsi_unprep_dma_buf
= lpfc_scsi_unprep_dma_buf
;
4064 phba
->lpfc_scsi_prep_cmnd
= lpfc_scsi_prep_cmnd
;
4067 case LPFC_PCI_DEV_LP
:
4068 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s3
;
4069 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s3
;
4070 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s3
;
4071 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s3
;
4072 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s3
;
4074 case LPFC_PCI_DEV_OC
:
4075 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s4
;
4076 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s4
;
4077 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s4
;
4078 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s4
;
4079 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s4
;
4082 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4083 "1418 Invalid HBA PCI-device group: 0x%x\n",
4088 phba
->lpfc_rampdown_queue_depth
= lpfc_rampdown_queue_depth
;
4089 phba
->lpfc_scsi_cmd_iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
4094 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4095 * @phba: The Hba for which this call is being executed.
4096 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4097 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4099 * This routine is IOCB completion routine for device reset and target reset
4100 * routine. This routine release scsi buffer associated with lpfc_cmd.
4103 lpfc_tskmgmt_def_cmpl(struct lpfc_hba
*phba
,
4104 struct lpfc_iocbq
*cmdiocbq
,
4105 struct lpfc_iocbq
*rspiocbq
)
4107 struct lpfc_scsi_buf
*lpfc_cmd
=
4108 (struct lpfc_scsi_buf
*) cmdiocbq
->context1
;
4110 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4115 * lpfc_info - Info entry point of scsi_host_template data structure
4116 * @host: The scsi host for which this call is being executed.
4118 * This routine provides module information about hba.
4121 * Pointer to char - Success.
4124 lpfc_info(struct Scsi_Host
*host
)
4126 struct lpfc_vport
*vport
= (struct lpfc_vport
*) host
->hostdata
;
4127 struct lpfc_hba
*phba
= vport
->phba
;
4129 static char lpfcinfobuf
[384];
4131 memset(lpfcinfobuf
,0,384);
4132 if (phba
&& phba
->pcidev
){
4133 strncpy(lpfcinfobuf
, phba
->ModelDesc
, 256);
4134 len
= strlen(lpfcinfobuf
);
4135 snprintf(lpfcinfobuf
+ len
,
4137 " on PCI bus %02x device %02x irq %d",
4138 phba
->pcidev
->bus
->number
,
4139 phba
->pcidev
->devfn
,
4141 len
= strlen(lpfcinfobuf
);
4142 if (phba
->Port
[0]) {
4143 snprintf(lpfcinfobuf
+ len
,
4148 len
= strlen(lpfcinfobuf
);
4149 if (phba
->sli4_hba
.link_state
.logical_speed
) {
4150 snprintf(lpfcinfobuf
+ len
,
4152 " Logical Link Speed: %d Mbps",
4153 phba
->sli4_hba
.link_state
.logical_speed
* 10);
4160 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4161 * @phba: The Hba for which this call is being executed.
4163 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4164 * The default value of cfg_poll_tmo is 10 milliseconds.
4166 static __inline__
void lpfc_poll_rearm_timer(struct lpfc_hba
* phba
)
4168 unsigned long poll_tmo_expires
=
4169 (jiffies
+ msecs_to_jiffies(phba
->cfg_poll_tmo
));
4171 if (phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
)
4172 mod_timer(&phba
->fcp_poll_timer
,
4177 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4178 * @phba: The Hba for which this call is being executed.
4180 * This routine starts the fcp_poll_timer of @phba.
4182 void lpfc_poll_start_timer(struct lpfc_hba
* phba
)
4184 lpfc_poll_rearm_timer(phba
);
4188 * lpfc_poll_timeout - Restart polling timer
4189 * @ptr: Map to lpfc_hba data structure pointer.
4191 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4192 * and FCP Ring interrupt is disable.
4195 void lpfc_poll_timeout(unsigned long ptr
)
4197 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4199 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4200 lpfc_sli_handle_fast_ring_event(phba
,
4201 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4203 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4204 lpfc_poll_rearm_timer(phba
);
4209 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4210 * @cmnd: Pointer to scsi_cmnd data structure.
4211 * @done: Pointer to done routine.
4213 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4214 * This routine prepares an IOCB from scsi command and provides to firmware.
4215 * The @done callback is invoked after driver finished processing the command.
4219 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4222 lpfc_queuecommand_lck(struct scsi_cmnd
*cmnd
, void (*done
) (struct scsi_cmnd
*))
4224 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4225 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4226 struct lpfc_hba
*phba
= vport
->phba
;
4227 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4228 struct lpfc_nodelist
*ndlp
;
4229 struct lpfc_scsi_buf
*lpfc_cmd
;
4230 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
4233 err
= fc_remote_port_chkready(rport
);
4236 goto out_fail_command
;
4238 ndlp
= rdata
->pnode
;
4240 if ((scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) &&
4241 (!(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))) {
4243 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4244 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4245 " op:%02x str=%s without registering for"
4246 " BlockGuard - Rejecting command\n",
4247 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
4248 dif_op_str
[scsi_get_prot_op(cmnd
)]);
4249 goto out_fail_command
;
4253 * Catch race where our node has transitioned, but the
4254 * transport is still transitioning.
4256 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
4257 cmnd
->result
= ScsiResult(DID_IMM_RETRY
, 0);
4258 goto out_fail_command
;
4260 if (atomic_read(&ndlp
->cmd_pending
) >= ndlp
->cmd_qdepth
)
4263 lpfc_cmd
= lpfc_get_scsi_buf(phba
, ndlp
);
4264 if (lpfc_cmd
== NULL
) {
4265 lpfc_rampdown_queue_depth(phba
);
4267 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4268 "0707 driver's buffer pool is empty, "
4274 * Store the midlayer's command structure for the completion phase
4275 * and complete the command initialization.
4277 lpfc_cmd
->pCmd
= cmnd
;
4278 lpfc_cmd
->rdata
= rdata
;
4279 lpfc_cmd
->timeout
= 0;
4280 lpfc_cmd
->start_time
= jiffies
;
4281 cmnd
->host_scribble
= (unsigned char *)lpfc_cmd
;
4282 cmnd
->scsi_done
= done
;
4284 if (scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) {
4285 if (vport
->phba
->cfg_enable_bg
) {
4286 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4287 "9033 BLKGRD: rcvd protected cmd:%02x op=%s "
4288 "guard=%s\n", cmnd
->cmnd
[0],
4289 dif_op_str
[scsi_get_prot_op(cmnd
)],
4290 dif_grd_str
[scsi_host_get_guard(shost
)]);
4291 if (cmnd
->cmnd
[0] == READ_10
)
4292 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4293 "9035 BLKGRD: READ @ sector %llu, "
4295 (unsigned long long)scsi_get_lba(cmnd
),
4296 blk_rq_sectors(cmnd
->request
),
4297 (cmnd
->cmnd
[1]>>5));
4298 else if (cmnd
->cmnd
[0] == WRITE_10
)
4299 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4300 "9036 BLKGRD: WRITE @ sector %llu, "
4302 (unsigned long long)scsi_get_lba(cmnd
),
4303 blk_rq_sectors(cmnd
->request
),
4304 (cmnd
->cmnd
[1]>>5));
4307 err
= lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4309 if (vport
->phba
->cfg_enable_bg
) {
4310 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4311 "9038 BLKGRD: rcvd unprotected cmd:"
4312 "%02x op=%s guard=%s\n", cmnd
->cmnd
[0],
4313 dif_op_str
[scsi_get_prot_op(cmnd
)],
4314 dif_grd_str
[scsi_host_get_guard(shost
)]);
4315 if (cmnd
->cmnd
[0] == READ_10
)
4316 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4317 "9040 dbg: READ @ sector %llu, "
4319 (unsigned long long)scsi_get_lba(cmnd
),
4320 blk_rq_sectors(cmnd
->request
),
4321 (cmnd
->cmnd
[1]>>5));
4322 else if (cmnd
->cmnd
[0] == WRITE_10
)
4323 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4324 "9041 dbg: WRITE @ sector %llu, "
4326 (unsigned long long)scsi_get_lba(cmnd
),
4327 blk_rq_sectors(cmnd
->request
),
4328 (cmnd
->cmnd
[1]>>5));
4330 err
= lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4334 goto out_host_busy_free_buf
;
4336 lpfc_scsi_prep_cmnd(vport
, lpfc_cmd
, ndlp
);
4338 atomic_inc(&ndlp
->cmd_pending
);
4339 err
= lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
,
4340 &lpfc_cmd
->cur_iocbq
, SLI_IOCB_RET_IOCB
);
4342 atomic_dec(&ndlp
->cmd_pending
);
4343 goto out_host_busy_free_buf
;
4345 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4346 spin_unlock(shost
->host_lock
);
4347 lpfc_sli_handle_fast_ring_event(phba
,
4348 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4350 spin_lock(shost
->host_lock
);
4351 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4352 lpfc_poll_rearm_timer(phba
);
4357 out_host_busy_free_buf
:
4358 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
4359 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4361 return SCSI_MLQUEUE_HOST_BUSY
;
4364 return SCSI_MLQUEUE_TARGET_BUSY
;
4371 static DEF_SCSI_QCMD(lpfc_queuecommand
)
4374 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4375 * @cmnd: Pointer to scsi_cmnd data structure.
4377 * This routine aborts @cmnd pending in base driver.
4384 lpfc_abort_handler(struct scsi_cmnd
*cmnd
)
4386 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4387 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4388 struct lpfc_hba
*phba
= vport
->phba
;
4389 struct lpfc_iocbq
*iocb
;
4390 struct lpfc_iocbq
*abtsiocb
;
4391 struct lpfc_scsi_buf
*lpfc_cmd
;
4394 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq
);
4396 ret
= fc_block_scsi_eh(cmnd
);
4400 spin_lock_irq(&phba
->hbalock
);
4401 /* driver queued commands are in process of being flushed */
4402 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
4403 spin_unlock_irq(&phba
->hbalock
);
4404 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4405 "3168 SCSI Layer abort requested I/O has been "
4406 "flushed by LLD.\n");
4410 lpfc_cmd
= (struct lpfc_scsi_buf
*)cmnd
->host_scribble
;
4412 spin_unlock_irq(&phba
->hbalock
);
4413 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4414 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4415 "x%x ID %d LUN %d\n",
4416 ret
, cmnd
->device
->id
, cmnd
->device
->lun
);
4420 iocb
= &lpfc_cmd
->cur_iocbq
;
4421 /* the command is in process of being cancelled */
4422 if (!(iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
)) {
4423 spin_unlock_irq(&phba
->hbalock
);
4424 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4425 "3169 SCSI Layer abort requested I/O has been "
4426 "cancelled by LLD.\n");
4430 * If pCmd field of the corresponding lpfc_scsi_buf structure
4431 * points to a different SCSI command, then the driver has
4432 * already completed this command, but the midlayer did not
4433 * see the completion before the eh fired. Just return SUCCESS.
4435 if (lpfc_cmd
->pCmd
!= cmnd
) {
4436 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4437 "3170 SCSI Layer abort requested I/O has been "
4438 "completed by LLD.\n");
4442 BUG_ON(iocb
->context1
!= lpfc_cmd
);
4444 abtsiocb
= __lpfc_sli_get_iocbq(phba
);
4445 if (abtsiocb
== NULL
) {
4451 * The scsi command can not be in txq and it is in flight because the
4452 * pCmd is still pointig at the SCSI command we have to abort. There
4453 * is no need to search the txcmplq. Just send an abort to the FW.
4457 icmd
= &abtsiocb
->iocb
;
4458 icmd
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
4459 icmd
->un
.acxri
.abortContextTag
= cmd
->ulpContext
;
4460 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4461 icmd
->un
.acxri
.abortIoTag
= iocb
->sli4_xritag
;
4463 icmd
->un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
4466 icmd
->ulpClass
= cmd
->ulpClass
;
4468 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4469 abtsiocb
->fcp_wqidx
= iocb
->fcp_wqidx
;
4470 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
4472 if (lpfc_is_link_up(phba
))
4473 icmd
->ulpCommand
= CMD_ABORT_XRI_CN
;
4475 icmd
->ulpCommand
= CMD_CLOSE_XRI_CN
;
4477 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
4478 abtsiocb
->vport
= vport
;
4479 /* no longer need the lock after this point */
4480 spin_unlock_irq(&phba
->hbalock
);
4482 if (lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
, abtsiocb
, 0) ==
4484 lpfc_sli_release_iocbq(phba
, abtsiocb
);
4489 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4490 lpfc_sli_handle_fast_ring_event(phba
,
4491 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4493 lpfc_cmd
->waitq
= &waitq
;
4494 /* Wait for abort to complete */
4495 wait_event_timeout(waitq
,
4496 (lpfc_cmd
->pCmd
!= cmnd
),
4497 (2*vport
->cfg_devloss_tmo
*HZ
));
4498 lpfc_cmd
->waitq
= NULL
;
4500 if (lpfc_cmd
->pCmd
== cmnd
) {
4502 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4503 "0748 abort handler timed out waiting "
4504 "for abort to complete: ret %#x, ID %d, "
4506 ret
, cmnd
->device
->id
, cmnd
->device
->lun
);
4511 spin_unlock_irq(&phba
->hbalock
);
4513 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4514 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4515 "LUN %d\n", ret
, cmnd
->device
->id
,
4521 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd
)
4523 switch (task_mgmt_cmd
) {
4524 case FCP_ABORT_TASK_SET
:
4525 return "ABORT_TASK_SET";
4526 case FCP_CLEAR_TASK_SET
:
4527 return "FCP_CLEAR_TASK_SET";
4529 return "FCP_BUS_RESET";
4531 return "FCP_LUN_RESET";
4532 case FCP_TARGET_RESET
:
4533 return "FCP_TARGET_RESET";
4535 return "FCP_CLEAR_ACA";
4536 case FCP_TERMINATE_TASK
:
4537 return "FCP_TERMINATE_TASK";
4544 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4545 * @vport: The virtual port for which this call is being executed.
4546 * @rdata: Pointer to remote port local data
4547 * @tgt_id: Target ID of remote device.
4548 * @lun_id: Lun number for the TMF
4549 * @task_mgmt_cmd: type of TMF to send
4551 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4559 lpfc_send_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_rport_data
*rdata
,
4560 unsigned tgt_id
, unsigned int lun_id
,
4561 uint8_t task_mgmt_cmd
)
4563 struct lpfc_hba
*phba
= vport
->phba
;
4564 struct lpfc_scsi_buf
*lpfc_cmd
;
4565 struct lpfc_iocbq
*iocbq
;
4566 struct lpfc_iocbq
*iocbqrsp
;
4567 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
4571 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
4574 lpfc_cmd
= lpfc_get_scsi_buf(phba
, rdata
->pnode
);
4575 if (lpfc_cmd
== NULL
)
4577 lpfc_cmd
->timeout
= 60;
4578 lpfc_cmd
->rdata
= rdata
;
4580 status
= lpfc_scsi_prep_task_mgmt_cmd(vport
, lpfc_cmd
, lun_id
,
4583 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4587 iocbq
= &lpfc_cmd
->cur_iocbq
;
4588 iocbqrsp
= lpfc_sli_get_iocbq(phba
);
4589 if (iocbqrsp
== NULL
) {
4590 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4594 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4595 "0702 Issue %s to TGT %d LUN %d "
4596 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
4597 lpfc_taskmgmt_name(task_mgmt_cmd
), tgt_id
, lun_id
,
4598 pnode
->nlp_rpi
, pnode
->nlp_flag
, iocbq
->sli4_xritag
,
4601 status
= lpfc_sli_issue_iocb_wait(phba
, LPFC_FCP_RING
,
4602 iocbq
, iocbqrsp
, lpfc_cmd
->timeout
);
4603 if (status
!= IOCB_SUCCESS
) {
4604 if (status
== IOCB_TIMEDOUT
) {
4605 iocbq
->iocb_cmpl
= lpfc_tskmgmt_def_cmpl
;
4606 ret
= TIMEOUT_ERROR
;
4609 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
4610 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4611 "0727 TMF %s to TGT %d LUN %d failed (%d, %d) "
4613 lpfc_taskmgmt_name(task_mgmt_cmd
),
4614 tgt_id
, lun_id
, iocbqrsp
->iocb
.ulpStatus
,
4615 iocbqrsp
->iocb
.un
.ulpWord
[4],
4617 } else if (status
== IOCB_BUSY
)
4622 lpfc_sli_release_iocbq(phba
, iocbqrsp
);
4624 if (ret
!= TIMEOUT_ERROR
)
4625 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4631 * lpfc_chk_tgt_mapped -
4632 * @vport: The virtual port to check on
4633 * @cmnd: Pointer to scsi_cmnd data structure.
4635 * This routine delays until the scsi target (aka rport) for the
4636 * command exists (is present and logged in) or we declare it non-existent.
4643 lpfc_chk_tgt_mapped(struct lpfc_vport
*vport
, struct scsi_cmnd
*cmnd
)
4645 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4646 struct lpfc_nodelist
*pnode
;
4647 unsigned long later
;
4650 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4651 "0797 Tgt Map rport failure: rdata x%p\n", rdata
);
4654 pnode
= rdata
->pnode
;
4656 * If target is not in a MAPPED state, delay until
4657 * target is rediscovered or devloss timeout expires.
4659 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
4660 while (time_after(later
, jiffies
)) {
4661 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
4663 if (pnode
->nlp_state
== NLP_STE_MAPPED_NODE
)
4665 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
4666 rdata
= cmnd
->device
->hostdata
;
4669 pnode
= rdata
->pnode
;
4671 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
) ||
4672 (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4678 * lpfc_reset_flush_io_context -
4679 * @vport: The virtual port (scsi_host) for the flush context
4680 * @tgt_id: If aborting by Target contect - specifies the target id
4681 * @lun_id: If aborting by Lun context - specifies the lun id
4682 * @context: specifies the context level to flush at.
4684 * After a reset condition via TMF, we need to flush orphaned i/o
4685 * contexts from the adapter. This routine aborts any contexts
4686 * outstanding, then waits for their completions. The wait is
4687 * bounded by devloss_tmo though.
4694 lpfc_reset_flush_io_context(struct lpfc_vport
*vport
, uint16_t tgt_id
,
4695 uint64_t lun_id
, lpfc_ctx_cmd context
)
4697 struct lpfc_hba
*phba
= vport
->phba
;
4698 unsigned long later
;
4701 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
4703 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
4704 tgt_id
, lun_id
, context
);
4705 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
4706 while (time_after(later
, jiffies
) && cnt
) {
4707 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
4708 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
4711 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4712 "0724 I/O flush failure for context %s : cnt x%x\n",
4713 ((context
== LPFC_CTX_LUN
) ? "LUN" :
4714 ((context
== LPFC_CTX_TGT
) ? "TGT" :
4715 ((context
== LPFC_CTX_HOST
) ? "HOST" : "Unknown"))),
4723 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
4724 * @cmnd: Pointer to scsi_cmnd data structure.
4726 * This routine does a device reset by sending a LUN_RESET task management
4734 lpfc_device_reset_handler(struct scsi_cmnd
*cmnd
)
4736 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4737 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4738 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4739 struct lpfc_nodelist
*pnode
;
4740 unsigned tgt_id
= cmnd
->device
->id
;
4741 unsigned int lun_id
= cmnd
->device
->lun
;
4742 struct lpfc_scsi_event_header scsi_event
;
4746 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4747 "0798 Device Reset rport failure: rdata x%p\n", rdata
);
4750 pnode
= rdata
->pnode
;
4751 status
= fc_block_scsi_eh(cmnd
);
4755 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
4756 if (status
== FAILED
) {
4757 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4758 "0721 Device Reset rport failure: rdata x%p\n", rdata
);
4762 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4763 scsi_event
.subcategory
= LPFC_EVENT_LUNRESET
;
4764 scsi_event
.lun
= lun_id
;
4765 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
4766 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
4768 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4769 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4771 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
4774 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4775 "0713 SCSI layer issued Device Reset (%d, %d) "
4776 "return x%x\n", tgt_id
, lun_id
, status
);
4779 * We have to clean up i/o as : they may be orphaned by the TMF;
4780 * or if the TMF failed, they may be in an indeterminate state.
4782 * We will report success if all the i/o aborts successfully.
4784 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
4790 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
4791 * @cmnd: Pointer to scsi_cmnd data structure.
4793 * This routine does a target reset by sending a TARGET_RESET task management
4801 lpfc_target_reset_handler(struct scsi_cmnd
*cmnd
)
4803 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4804 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4805 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4806 struct lpfc_nodelist
*pnode
;
4807 unsigned tgt_id
= cmnd
->device
->id
;
4808 unsigned int lun_id
= cmnd
->device
->lun
;
4809 struct lpfc_scsi_event_header scsi_event
;
4813 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4814 "0799 Target Reset rport failure: rdata x%p\n", rdata
);
4817 pnode
= rdata
->pnode
;
4818 status
= fc_block_scsi_eh(cmnd
);
4822 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
4823 if (status
== FAILED
) {
4824 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4825 "0722 Target Reset rport failure: rdata x%p\n", rdata
);
4829 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4830 scsi_event
.subcategory
= LPFC_EVENT_TGTRESET
;
4832 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
4833 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
4835 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4836 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4838 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
4841 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4842 "0723 SCSI layer issued Target Reset (%d, %d) "
4843 "return x%x\n", tgt_id
, lun_id
, status
);
4846 * We have to clean up i/o as : they may be orphaned by the TMF;
4847 * or if the TMF failed, they may be in an indeterminate state.
4849 * We will report success if all the i/o aborts successfully.
4851 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
4857 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
4858 * @cmnd: Pointer to scsi_cmnd data structure.
4860 * This routine does target reset to all targets on @cmnd->device->host.
4861 * This emulates Parallel SCSI Bus Reset Semantics.
4868 lpfc_bus_reset_handler(struct scsi_cmnd
*cmnd
)
4870 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4871 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4872 struct lpfc_nodelist
*ndlp
= NULL
;
4873 struct lpfc_scsi_event_header scsi_event
;
4875 int ret
= SUCCESS
, status
, i
;
4877 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4878 scsi_event
.subcategory
= LPFC_EVENT_BUSRESET
;
4880 memcpy(scsi_event
.wwpn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4881 memcpy(scsi_event
.wwnn
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4883 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4884 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4886 status
= fc_block_scsi_eh(cmnd
);
4891 * Since the driver manages a single bus device, reset all
4892 * targets known to the driver. Should any target reset
4893 * fail, this routine returns failure to the midlayer.
4895 for (i
= 0; i
< LPFC_MAX_TARGET
; i
++) {
4896 /* Search for mapped node by target ID */
4898 spin_lock_irq(shost
->host_lock
);
4899 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4900 if (!NLP_CHK_NODE_ACT(ndlp
))
4902 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
4903 ndlp
->nlp_sid
== i
&&
4909 spin_unlock_irq(shost
->host_lock
);
4913 status
= lpfc_send_taskmgmt(vport
, ndlp
->rport
->dd_data
,
4914 i
, 0, FCP_TARGET_RESET
);
4916 if (status
!= SUCCESS
) {
4917 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4918 "0700 Bus Reset on target %d failed\n",
4924 * We have to clean up i/o as : they may be orphaned by the TMFs
4925 * above; or if any of the TMFs failed, they may be in an
4926 * indeterminate state.
4927 * We will report success if all the i/o aborts successfully.
4930 status
= lpfc_reset_flush_io_context(vport
, 0, 0, LPFC_CTX_HOST
);
4931 if (status
!= SUCCESS
)
4934 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4935 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret
);
4940 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
4941 * @sdev: Pointer to scsi_device.
4943 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
4944 * globally available list of scsi buffers. This routine also makes sure scsi
4945 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
4946 * of scsi buffer exists for the lifetime of the driver.
4953 lpfc_slave_alloc(struct scsi_device
*sdev
)
4955 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
4956 struct lpfc_hba
*phba
= vport
->phba
;
4957 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
4959 uint32_t num_to_alloc
= 0;
4960 int num_allocated
= 0;
4963 if (!rport
|| fc_remote_port_chkready(rport
))
4966 sdev
->hostdata
= rport
->dd_data
;
4967 sdev_cnt
= atomic_inc_return(&phba
->sdev_cnt
);
4970 * Populate the cmds_per_lun count scsi_bufs into this host's globally
4971 * available list of scsi buffers. Don't allocate more than the
4972 * HBA limit conveyed to the midlayer via the host structure. The
4973 * formula accounts for the lun_queue_depth + error handlers + 1
4974 * extra. This list of scsi bufs exists for the lifetime of the driver.
4976 total
= phba
->total_scsi_bufs
;
4977 num_to_alloc
= vport
->cfg_lun_queue_depth
+ 2;
4979 /* If allocated buffers are enough do nothing */
4980 if ((sdev_cnt
* (vport
->cfg_lun_queue_depth
+ 2)) < total
)
4983 /* Allow some exchanges to be available always to complete discovery */
4984 if (total
>= phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
4985 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4986 "0704 At limitation of %d preallocated "
4987 "command buffers\n", total
);
4989 /* Allow some exchanges to be available always to complete discovery */
4990 } else if (total
+ num_to_alloc
>
4991 phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
4992 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4993 "0705 Allocation request of %d "
4994 "command buffers will exceed max of %d. "
4995 "Reducing allocation request to %d.\n",
4996 num_to_alloc
, phba
->cfg_hba_queue_depth
,
4997 (phba
->cfg_hba_queue_depth
- total
));
4998 num_to_alloc
= phba
->cfg_hba_queue_depth
- total
;
5000 num_allocated
= lpfc_new_scsi_buf(vport
, num_to_alloc
);
5001 if (num_to_alloc
!= num_allocated
) {
5002 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5003 "0708 Allocation request of %d "
5004 "command buffers did not succeed. "
5005 "Allocated %d buffers.\n",
5006 num_to_alloc
, num_allocated
);
5008 if (num_allocated
> 0)
5009 phba
->total_scsi_bufs
+= num_allocated
;
5014 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5015 * @sdev: Pointer to scsi_device.
5017 * This routine configures following items
5018 * - Tag command queuing support for @sdev if supported.
5019 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5025 lpfc_slave_configure(struct scsi_device
*sdev
)
5027 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5028 struct lpfc_hba
*phba
= vport
->phba
;
5030 if (sdev
->tagged_supported
)
5031 scsi_activate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
5033 scsi_deactivate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
5035 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
5036 lpfc_sli_handle_fast_ring_event(phba
,
5037 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
5038 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
5039 lpfc_poll_rearm_timer(phba
);
5046 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5047 * @sdev: Pointer to scsi_device.
5049 * This routine sets @sdev hostatdata filed to null.
5052 lpfc_slave_destroy(struct scsi_device
*sdev
)
5054 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5055 struct lpfc_hba
*phba
= vport
->phba
;
5056 atomic_dec(&phba
->sdev_cnt
);
5057 sdev
->hostdata
= NULL
;
5062 struct scsi_host_template lpfc_template
= {
5063 .module
= THIS_MODULE
,
5064 .name
= LPFC_DRIVER_NAME
,
5066 .queuecommand
= lpfc_queuecommand
,
5067 .eh_abort_handler
= lpfc_abort_handler
,
5068 .eh_device_reset_handler
= lpfc_device_reset_handler
,
5069 .eh_target_reset_handler
= lpfc_target_reset_handler
,
5070 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
5071 .slave_alloc
= lpfc_slave_alloc
,
5072 .slave_configure
= lpfc_slave_configure
,
5073 .slave_destroy
= lpfc_slave_destroy
,
5074 .scan_finished
= lpfc_scan_finished
,
5076 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
5077 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
5078 .use_clustering
= ENABLE_CLUSTERING
,
5079 .shost_attrs
= lpfc_hba_attrs
,
5080 .max_sectors
= 0xFFFF,
5081 .vendor_id
= LPFC_NL_VENDOR_ID
,
5082 .change_queue_depth
= lpfc_change_queue_depth
,
5085 struct scsi_host_template lpfc_vport_template
= {
5086 .module
= THIS_MODULE
,
5087 .name
= LPFC_DRIVER_NAME
,
5089 .queuecommand
= lpfc_queuecommand
,
5090 .eh_abort_handler
= lpfc_abort_handler
,
5091 .eh_device_reset_handler
= lpfc_device_reset_handler
,
5092 .eh_target_reset_handler
= lpfc_target_reset_handler
,
5093 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
5094 .slave_alloc
= lpfc_slave_alloc
,
5095 .slave_configure
= lpfc_slave_configure
,
5096 .slave_destroy
= lpfc_slave_destroy
,
5097 .scan_finished
= lpfc_scan_finished
,
5099 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
5100 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
5101 .use_clustering
= ENABLE_CLUSTERING
,
5102 .shost_attrs
= lpfc_vport_attrs
,
5103 .max_sectors
= 0xFFFF,
5104 .change_queue_depth
= lpfc_change_queue_depth
,