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 struct scsi_dif_tuple
{
64 __be16 guard_tag
; /* Checksum */
65 __be16 app_tag
; /* Opaque storage */
66 __be32 ref_tag
; /* Target LBA or indirect LBA */
70 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
72 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
75 lpfc_debug_save_data(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
78 struct scatterlist
*sgde
= scsi_sglist(cmnd
);
80 if (!_dump_buf_data
) {
81 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
82 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
89 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
90 "9051 BLKGRD: ERROR: data scatterlist is null\n");
94 dst
= (void *) _dump_buf_data
;
97 memcpy(dst
, src
, sgde
->length
);
104 lpfc_debug_save_dif(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
107 struct scatterlist
*sgde
= scsi_prot_sglist(cmnd
);
109 if (!_dump_buf_dif
) {
110 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
111 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
117 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
118 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
125 memcpy(dst
, src
, sgde
->length
);
127 sgde
= sg_next(sgde
);
132 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
133 * @phba: Pointer to HBA object.
134 * @lpfc_cmd: lpfc scsi command object pointer.
136 * This function is called from the lpfc_prep_task_mgmt_cmd function to
137 * set the last bit in the response sge entry.
140 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba
*phba
,
141 struct lpfc_scsi_buf
*lpfc_cmd
)
143 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
146 sgl
->word2
= le32_to_cpu(sgl
->word2
);
147 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
148 sgl
->word2
= cpu_to_le32(sgl
->word2
);
153 * lpfc_update_stats - Update statistical data for the command completion
154 * @phba: Pointer to HBA object.
155 * @lpfc_cmd: lpfc scsi command object pointer.
157 * This function is called when there is a command completion and this
158 * function updates the statistical data for the command completion.
161 lpfc_update_stats(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
163 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
164 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
165 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
167 struct Scsi_Host
*shost
= cmd
->device
->host
;
168 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
169 unsigned long latency
;
175 latency
= jiffies_to_msecs((long)jiffies
- (long)lpfc_cmd
->start_time
);
177 spin_lock_irqsave(shost
->host_lock
, flags
);
178 if (!vport
->stat_data_enabled
||
179 vport
->stat_data_blocked
||
182 (phba
->bucket_type
== LPFC_NO_BUCKET
)) {
183 spin_unlock_irqrestore(shost
->host_lock
, flags
);
187 if (phba
->bucket_type
== LPFC_LINEAR_BUCKET
) {
188 i
= (latency
+ phba
->bucket_step
- 1 - phba
->bucket_base
)/
190 /* check array subscript bounds */
193 else if (i
>= LPFC_MAX_BUCKET_COUNT
)
194 i
= LPFC_MAX_BUCKET_COUNT
- 1;
196 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
-1; i
++)
197 if (latency
<= (phba
->bucket_base
+
198 ((1<<i
)*phba
->bucket_step
)))
202 pnode
->lat_data
[i
].cmd_count
++;
203 spin_unlock_irqrestore(shost
->host_lock
, flags
);
207 * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
208 * @phba: Pointer to HBA context object.
209 * @vport: Pointer to vport object.
210 * @ndlp: Pointer to FC node associated with the target.
211 * @lun: Lun number of the scsi device.
212 * @old_val: Old value of the queue depth.
213 * @new_val: New value of the queue depth.
215 * This function sends an event to the mgmt application indicating
216 * there is a change in the scsi device queue depth.
219 lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba
*phba
,
220 struct lpfc_vport
*vport
,
221 struct lpfc_nodelist
*ndlp
,
226 struct lpfc_fast_path_event
*fast_path_evt
;
229 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
233 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.event_type
=
235 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.subcategory
=
236 LPFC_EVENT_VARQUEDEPTH
;
238 /* Report all luns with change in queue depth */
239 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.lun
= lun
;
240 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
241 memcpy(&fast_path_evt
->un
.queue_depth_evt
.scsi_event
.wwpn
,
242 &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
243 memcpy(&fast_path_evt
->un
.queue_depth_evt
.scsi_event
.wwnn
,
244 &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
247 fast_path_evt
->un
.queue_depth_evt
.oldval
= old_val
;
248 fast_path_evt
->un
.queue_depth_evt
.newval
= new_val
;
249 fast_path_evt
->vport
= vport
;
251 fast_path_evt
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
252 spin_lock_irqsave(&phba
->hbalock
, flags
);
253 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
254 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
255 lpfc_worker_wake_up(phba
);
261 * lpfc_change_queue_depth - Alter scsi device queue depth
262 * @sdev: Pointer the scsi device on which to change the queue depth.
263 * @qdepth: New queue depth to set the sdev to.
264 * @reason: The reason for the queue depth change.
266 * This function is called by the midlayer and the LLD to alter the queue
267 * depth for a scsi device. This function sets the queue depth to the new
268 * value and sends an event out to log the queue depth change.
271 lpfc_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
273 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
274 struct lpfc_hba
*phba
= vport
->phba
;
275 struct lpfc_rport_data
*rdata
;
276 unsigned long new_queue_depth
, old_queue_depth
;
278 old_queue_depth
= sdev
->queue_depth
;
279 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
280 new_queue_depth
= sdev
->queue_depth
;
281 rdata
= sdev
->hostdata
;
283 lpfc_send_sdev_queuedepth_change_event(phba
, vport
,
284 rdata
->pnode
, sdev
->lun
,
287 return sdev
->queue_depth
;
291 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
292 * @phba: The Hba for which this call is being executed.
294 * This routine is called when there is resource error in driver or firmware.
295 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
296 * posts at most 1 event each second. This routine wakes up worker thread of
297 * @phba to process WORKER_RAM_DOWN_EVENT event.
299 * This routine should be called with no lock held.
302 lpfc_rampdown_queue_depth(struct lpfc_hba
*phba
)
307 spin_lock_irqsave(&phba
->hbalock
, flags
);
308 atomic_inc(&phba
->num_rsrc_err
);
309 phba
->last_rsrc_error_time
= jiffies
;
311 if ((phba
->last_ramp_down_time
+ QUEUE_RAMP_DOWN_INTERVAL
) > jiffies
) {
312 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
316 phba
->last_ramp_down_time
= jiffies
;
318 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
320 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
321 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_DOWN_QUEUE
;
323 phba
->pport
->work_port_events
|= WORKER_RAMP_DOWN_QUEUE
;
324 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
327 lpfc_worker_wake_up(phba
);
332 * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread
333 * @phba: The Hba for which this call is being executed.
335 * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine
336 * post at most 1 event every 5 minute after last_ramp_up_time or
337 * last_rsrc_error_time. This routine wakes up worker thread of @phba
338 * to process WORKER_RAM_DOWN_EVENT event.
340 * This routine should be called with no lock held.
343 lpfc_rampup_queue_depth(struct lpfc_vport
*vport
,
344 uint32_t queue_depth
)
347 struct lpfc_hba
*phba
= vport
->phba
;
349 atomic_inc(&phba
->num_cmd_success
);
351 if (vport
->cfg_lun_queue_depth
<= queue_depth
)
353 spin_lock_irqsave(&phba
->hbalock
, flags
);
354 if (time_before(jiffies
,
355 phba
->last_ramp_up_time
+ QUEUE_RAMP_UP_INTERVAL
) ||
357 phba
->last_rsrc_error_time
+ QUEUE_RAMP_UP_INTERVAL
)) {
358 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
361 phba
->last_ramp_up_time
= jiffies
;
362 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
364 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
365 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_UP_QUEUE
;
367 phba
->pport
->work_port_events
|= WORKER_RAMP_UP_QUEUE
;
368 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
371 lpfc_worker_wake_up(phba
);
376 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
377 * @phba: The Hba for which this call is being executed.
379 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
380 * thread.This routine reduces queue depth for all scsi device on each vport
381 * associated with @phba.
384 lpfc_ramp_down_queue_handler(struct lpfc_hba
*phba
)
386 struct lpfc_vport
**vports
;
387 struct Scsi_Host
*shost
;
388 struct scsi_device
*sdev
;
389 unsigned long new_queue_depth
;
390 unsigned long num_rsrc_err
, num_cmd_success
;
393 num_rsrc_err
= atomic_read(&phba
->num_rsrc_err
);
394 num_cmd_success
= atomic_read(&phba
->num_cmd_success
);
397 * The error and success command counters are global per
398 * driver instance. If another handler has already
399 * operated on this error event, just exit.
401 if (num_rsrc_err
== 0)
404 vports
= lpfc_create_vport_work_array(phba
);
406 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
407 shost
= lpfc_shost_from_vport(vports
[i
]);
408 shost_for_each_device(sdev
, shost
) {
410 sdev
->queue_depth
* num_rsrc_err
/
411 (num_rsrc_err
+ num_cmd_success
);
412 if (!new_queue_depth
)
413 new_queue_depth
= sdev
->queue_depth
- 1;
415 new_queue_depth
= sdev
->queue_depth
-
417 lpfc_change_queue_depth(sdev
, new_queue_depth
,
418 SCSI_QDEPTH_DEFAULT
);
421 lpfc_destroy_vport_work_array(phba
, vports
);
422 atomic_set(&phba
->num_rsrc_err
, 0);
423 atomic_set(&phba
->num_cmd_success
, 0);
427 * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler
428 * @phba: The Hba for which this call is being executed.
430 * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker
431 * thread.This routine increases queue depth for all scsi device on each vport
432 * associated with @phba by 1. This routine also sets @phba num_rsrc_err and
433 * num_cmd_success to zero.
436 lpfc_ramp_up_queue_handler(struct lpfc_hba
*phba
)
438 struct lpfc_vport
**vports
;
439 struct Scsi_Host
*shost
;
440 struct scsi_device
*sdev
;
443 vports
= lpfc_create_vport_work_array(phba
);
445 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
446 shost
= lpfc_shost_from_vport(vports
[i
]);
447 shost_for_each_device(sdev
, shost
) {
448 if (vports
[i
]->cfg_lun_queue_depth
<=
451 lpfc_change_queue_depth(sdev
,
453 SCSI_QDEPTH_RAMP_UP
);
456 lpfc_destroy_vport_work_array(phba
, vports
);
457 atomic_set(&phba
->num_rsrc_err
, 0);
458 atomic_set(&phba
->num_cmd_success
, 0);
462 * lpfc_scsi_dev_block - set all scsi hosts to block state
463 * @phba: Pointer to HBA context object.
465 * This function walks vport list and set each SCSI host to block state
466 * by invoking fc_remote_port_delete() routine. This function is invoked
467 * with EEH when device's PCI slot has been permanently disabled.
470 lpfc_scsi_dev_block(struct lpfc_hba
*phba
)
472 struct lpfc_vport
**vports
;
473 struct Scsi_Host
*shost
;
474 struct scsi_device
*sdev
;
475 struct fc_rport
*rport
;
478 vports
= lpfc_create_vport_work_array(phba
);
480 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
481 shost
= lpfc_shost_from_vport(vports
[i
]);
482 shost_for_each_device(sdev
, shost
) {
483 rport
= starget_to_rport(scsi_target(sdev
));
484 fc_remote_port_delete(rport
);
487 lpfc_destroy_vport_work_array(phba
, vports
);
491 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
492 * @vport: The virtual port for which this call being executed.
493 * @num_to_allocate: The requested number of buffers to allocate.
495 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
496 * the scsi buffer contains all the necessary information needed to initiate
497 * a SCSI I/O. The non-DMAable buffer region contains information to build
498 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
499 * and the initial BPL. In addition to allocating memory, the FCP CMND and
500 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
503 * int - number of scsi buffers that were allocated.
504 * 0 = failure, less than num_to_alloc is a partial failure.
507 lpfc_new_scsi_buf_s3(struct lpfc_vport
*vport
, int num_to_alloc
)
509 struct lpfc_hba
*phba
= vport
->phba
;
510 struct lpfc_scsi_buf
*psb
;
511 struct ulp_bde64
*bpl
;
513 dma_addr_t pdma_phys_fcp_cmd
;
514 dma_addr_t pdma_phys_fcp_rsp
;
515 dma_addr_t pdma_phys_bpl
;
519 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
520 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
525 * Get memory from the pci pool to map the virt space to pci
526 * bus space for an I/O. The DMA buffer includes space for the
527 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
528 * necessary to support the sg_tablesize.
530 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
531 GFP_KERNEL
, &psb
->dma_handle
);
537 /* Initialize virtual ptrs to dma_buf region. */
538 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
540 /* Allocate iotag for psb->cur_iocbq. */
541 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
543 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
544 psb
->data
, psb
->dma_handle
);
548 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
550 psb
->fcp_cmnd
= psb
->data
;
551 psb
->fcp_rsp
= psb
->data
+ sizeof(struct fcp_cmnd
);
552 psb
->fcp_bpl
= psb
->data
+ sizeof(struct fcp_cmnd
) +
553 sizeof(struct fcp_rsp
);
555 /* Initialize local short-hand pointers. */
557 pdma_phys_fcp_cmd
= psb
->dma_handle
;
558 pdma_phys_fcp_rsp
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
);
559 pdma_phys_bpl
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
) +
560 sizeof(struct fcp_rsp
);
563 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
564 * are sg list bdes. Initialize the first two and leave the
565 * rest for queuecommand.
567 bpl
[0].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd
));
568 bpl
[0].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd
));
569 bpl
[0].tus
.f
.bdeSize
= sizeof(struct fcp_cmnd
);
570 bpl
[0].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
571 bpl
[0].tus
.w
= le32_to_cpu(bpl
[0].tus
.w
);
573 /* Setup the physical region for the FCP RSP */
574 bpl
[1].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp
));
575 bpl
[1].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp
));
576 bpl
[1].tus
.f
.bdeSize
= sizeof(struct fcp_rsp
);
577 bpl
[1].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
578 bpl
[1].tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
581 * Since the IOCB for the FCP I/O is built into this
582 * lpfc_scsi_buf, initialize it with all known data now.
584 iocb
= &psb
->cur_iocbq
.iocb
;
585 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
586 if ((phba
->sli_rev
== 3) &&
587 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)) {
588 /* fill in immediate fcp command BDE */
589 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_IMMED
;
590 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
591 iocb
->un
.fcpi64
.bdl
.addrLow
= offsetof(IOCB_t
,
593 iocb
->un
.fcpi64
.bdl
.addrHigh
= 0;
594 iocb
->ulpBdeCount
= 0;
596 /* fill in response BDE */
597 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeFlags
=
599 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeSize
=
600 sizeof(struct fcp_rsp
);
601 iocb
->unsli3
.fcp_ext
.rbde
.addrLow
=
602 putPaddrLow(pdma_phys_fcp_rsp
);
603 iocb
->unsli3
.fcp_ext
.rbde
.addrHigh
=
604 putPaddrHigh(pdma_phys_fcp_rsp
);
606 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
607 iocb
->un
.fcpi64
.bdl
.bdeSize
=
608 (2 * sizeof(struct ulp_bde64
));
609 iocb
->un
.fcpi64
.bdl
.addrLow
=
610 putPaddrLow(pdma_phys_bpl
);
611 iocb
->un
.fcpi64
.bdl
.addrHigh
=
612 putPaddrHigh(pdma_phys_bpl
);
613 iocb
->ulpBdeCount
= 1;
616 iocb
->ulpClass
= CLASS3
;
617 psb
->status
= IOSTAT_SUCCESS
;
618 /* Put it back into the SCSI buffer list */
619 psb
->cur_iocbq
.context1
= psb
;
620 lpfc_release_scsi_buf_s3(phba
, psb
);
628 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
629 * @vport: pointer to lpfc vport data structure.
631 * This routine is invoked by the vport cleanup for deletions and the cleanup
632 * for an ndlp on removal.
635 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport
*vport
)
637 struct lpfc_hba
*phba
= vport
->phba
;
638 struct lpfc_scsi_buf
*psb
, *next_psb
;
639 unsigned long iflag
= 0;
641 spin_lock_irqsave(&phba
->hbalock
, iflag
);
642 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
643 list_for_each_entry_safe(psb
, next_psb
,
644 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
645 if (psb
->rdata
&& psb
->rdata
->pnode
646 && psb
->rdata
->pnode
->vport
== vport
)
649 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
650 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
654 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
655 * @phba: pointer to lpfc hba data structure.
656 * @axri: pointer to the fcp xri abort wcqe structure.
658 * This routine is invoked by the worker thread to process a SLI4 fast-path
662 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba
*phba
,
663 struct sli4_wcqe_xri_aborted
*axri
)
665 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
666 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
667 struct lpfc_scsi_buf
*psb
, *next_psb
;
668 unsigned long iflag
= 0;
669 struct lpfc_iocbq
*iocbq
;
671 struct lpfc_nodelist
*ndlp
;
673 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
675 spin_lock_irqsave(&phba
->hbalock
, iflag
);
676 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
677 list_for_each_entry_safe(psb
, next_psb
,
678 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
679 if (psb
->cur_iocbq
.sli4_xritag
== xri
) {
680 list_del(&psb
->list
);
682 psb
->status
= IOSTAT_SUCCESS
;
684 &phba
->sli4_hba
.abts_scsi_buf_list_lock
);
685 if (psb
->rdata
&& psb
->rdata
->pnode
)
686 ndlp
= psb
->rdata
->pnode
;
690 rrq_empty
= list_empty(&phba
->active_rrq_list
);
691 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
693 lpfc_set_rrq_active(phba
, ndlp
,
694 psb
->cur_iocbq
.sli4_lxritag
, rxid
, 1);
695 lpfc_sli4_abts_err_handler(phba
, ndlp
, axri
);
697 lpfc_release_scsi_buf_s4(phba
, psb
);
699 lpfc_worker_wake_up(phba
);
703 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
704 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
705 iocbq
= phba
->sli
.iocbq_lookup
[i
];
707 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
) ||
708 (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
710 if (iocbq
->sli4_xritag
!= xri
)
712 psb
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
714 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
716 lpfc_worker_wake_up(phba
);
720 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
724 * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list
725 * @phba: pointer to lpfc hba data structure.
726 * @post_sblist: pointer to the scsi buffer list.
728 * This routine walks a list of scsi buffers that was passed in. It attempts
729 * to construct blocks of scsi buffer sgls which contains contiguous xris and
730 * uses the non-embedded SGL block post mailbox commands to post to the port.
731 * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use
732 * embedded SGL post mailbox command for posting. The @post_sblist passed in
733 * must be local list, thus no lock is needed when manipulate the list.
735 * Returns: 0 = failure, non-zero number of successfully posted buffers.
738 lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba
*phba
,
739 struct list_head
*post_sblist
, int sb_count
)
741 struct lpfc_scsi_buf
*psb
, *psb_next
;
743 int post_cnt
= 0, block_cnt
= 0, num_posting
= 0, num_posted
= 0;
744 dma_addr_t pdma_phys_bpl1
;
745 int last_xritag
= NO_XRI
;
746 LIST_HEAD(prep_sblist
);
747 LIST_HEAD(blck_sblist
);
748 LIST_HEAD(scsi_sblist
);
754 list_for_each_entry_safe(psb
, psb_next
, post_sblist
, list
) {
755 list_del_init(&psb
->list
);
757 if ((last_xritag
!= NO_XRI
) &&
758 (psb
->cur_iocbq
.sli4_xritag
!= last_xritag
+ 1)) {
759 /* a hole in xri block, form a sgl posting block */
760 list_splice_init(&prep_sblist
, &blck_sblist
);
761 post_cnt
= block_cnt
- 1;
762 /* prepare list for next posting block */
763 list_add_tail(&psb
->list
, &prep_sblist
);
766 /* prepare list for next posting block */
767 list_add_tail(&psb
->list
, &prep_sblist
);
768 /* enough sgls for non-embed sgl mbox command */
769 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
770 list_splice_init(&prep_sblist
, &blck_sblist
);
771 post_cnt
= block_cnt
;
776 last_xritag
= psb
->cur_iocbq
.sli4_xritag
;
778 /* end of repost sgl list condition for SCSI buffers */
779 if (num_posting
== sb_count
) {
781 /* last sgl posting block */
782 list_splice_init(&prep_sblist
, &blck_sblist
);
783 post_cnt
= block_cnt
;
784 } else if (block_cnt
== 1) {
785 /* last single sgl with non-contiguous xri */
786 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
787 pdma_phys_bpl1
= psb
->dma_phys_bpl
+
791 status
= lpfc_sli4_post_sgl(phba
,
794 psb
->cur_iocbq
.sli4_xritag
);
796 /* failure, put on abort scsi list */
799 /* success, put on SCSI buffer list */
801 psb
->status
= IOSTAT_SUCCESS
;
804 /* success, put on SCSI buffer sgl list */
805 list_add_tail(&psb
->list
, &scsi_sblist
);
809 /* continue until a nembed page worth of sgls */
813 /* post block of SCSI buffer list sgls */
814 status
= lpfc_sli4_post_scsi_sgl_block(phba
, &blck_sblist
,
817 /* don't reset xirtag due to hole in xri block */
819 last_xritag
= NO_XRI
;
821 /* reset SCSI buffer post count for next round of posting */
824 /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */
825 while (!list_empty(&blck_sblist
)) {
826 list_remove_head(&blck_sblist
, psb
,
827 struct lpfc_scsi_buf
, list
);
829 /* failure, put on abort scsi list */
832 /* success, put on SCSI buffer list */
834 psb
->status
= IOSTAT_SUCCESS
;
837 list_add_tail(&psb
->list
, &scsi_sblist
);
840 /* Push SCSI buffers with sgl posted to the availble list */
841 while (!list_empty(&scsi_sblist
)) {
842 list_remove_head(&scsi_sblist
, psb
,
843 struct lpfc_scsi_buf
, list
);
844 lpfc_release_scsi_buf_s4(phba
, psb
);
850 * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls
851 * @phba: pointer to lpfc hba data structure.
853 * This routine walks the list of scsi buffers that have been allocated and
854 * repost them to the port by using SGL block post. This is needed after a
855 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
856 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
857 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
859 * Returns: 0 = success, non-zero failure.
862 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba
*phba
)
864 LIST_HEAD(post_sblist
);
865 int num_posted
, rc
= 0;
867 /* get all SCSI buffers need to repost to a local list */
868 spin_lock(&phba
->scsi_buf_list_lock
);
869 list_splice_init(&phba
->lpfc_scsi_buf_list
, &post_sblist
);
870 spin_unlock(&phba
->scsi_buf_list_lock
);
872 /* post the list of scsi buffer sgls to port if available */
873 if (!list_empty(&post_sblist
)) {
874 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
, &post_sblist
,
875 phba
->sli4_hba
.scsi_xri_cnt
);
876 /* failed to post any scsi buffer, return error */
884 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
885 * @vport: The virtual port for which this call being executed.
886 * @num_to_allocate: The requested number of buffers to allocate.
888 * This routine allocates scsi buffers for device with SLI-4 interface spec,
889 * the scsi buffer contains all the necessary information needed to initiate
890 * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put
891 * them on a list, it post them to the port by using SGL block post.
894 * int - number of scsi buffers that were allocated and posted.
895 * 0 = failure, less than num_to_alloc is a partial failure.
898 lpfc_new_scsi_buf_s4(struct lpfc_vport
*vport
, int num_to_alloc
)
900 struct lpfc_hba
*phba
= vport
->phba
;
901 struct lpfc_scsi_buf
*psb
;
902 struct sli4_sge
*sgl
;
904 dma_addr_t pdma_phys_fcp_cmd
;
905 dma_addr_t pdma_phys_fcp_rsp
;
906 dma_addr_t pdma_phys_bpl
, pdma_phys_bpl1
;
907 uint16_t iotag
, lxri
= 0;
908 int bcnt
, num_posted
;
909 LIST_HEAD(prep_sblist
);
910 LIST_HEAD(post_sblist
);
911 LIST_HEAD(scsi_sblist
);
913 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
914 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
918 * Get memory from the pci pool to map the virt space to
919 * pci bus space for an I/O. The DMA buffer includes space
920 * for the struct fcp_cmnd, struct fcp_rsp and the number
921 * of bde's necessary to support the sg_tablesize.
923 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
924 GFP_KERNEL
, &psb
->dma_handle
);
929 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
931 /* Allocate iotag for psb->cur_iocbq. */
932 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
934 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
935 psb
->data
, psb
->dma_handle
);
940 lxri
= lpfc_sli4_next_xritag(phba
);
941 if (lxri
== NO_XRI
) {
942 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
943 psb
->data
, psb
->dma_handle
);
947 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
948 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
949 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
950 psb
->fcp_bpl
= psb
->data
;
951 psb
->fcp_cmnd
= (psb
->data
+ phba
->cfg_sg_dma_buf_size
)
952 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
953 psb
->fcp_rsp
= (struct fcp_rsp
*)((uint8_t *)psb
->fcp_cmnd
+
954 sizeof(struct fcp_cmnd
));
956 /* Initialize local short-hand pointers. */
957 sgl
= (struct sli4_sge
*)psb
->fcp_bpl
;
958 pdma_phys_bpl
= psb
->dma_handle
;
960 (psb
->dma_handle
+ phba
->cfg_sg_dma_buf_size
)
961 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
962 pdma_phys_fcp_rsp
= pdma_phys_fcp_cmd
+ sizeof(struct fcp_cmnd
);
965 * The first two bdes are the FCP_CMD and FCP_RSP.
966 * The balance are sg list bdes. Initialize the
967 * first two and leave the rest for queuecommand.
969 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd
));
970 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd
));
971 sgl
->word2
= le32_to_cpu(sgl
->word2
);
972 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
973 sgl
->word2
= cpu_to_le32(sgl
->word2
);
974 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_cmnd
));
977 /* Setup the physical region for the FCP RSP */
978 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp
));
979 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp
));
980 sgl
->word2
= le32_to_cpu(sgl
->word2
);
981 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
982 sgl
->word2
= cpu_to_le32(sgl
->word2
);
983 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_rsp
));
986 * Since the IOCB for the FCP I/O is built into this
987 * lpfc_scsi_buf, initialize it with all known data now.
989 iocb
= &psb
->cur_iocbq
.iocb
;
990 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
991 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
992 /* setting the BLP size to 2 * sizeof BDE may not be correct.
993 * We are setting the bpl to point to out sgl. An sgl's
994 * entries are 16 bytes, a bpl entries are 12 bytes.
996 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
997 iocb
->un
.fcpi64
.bdl
.addrLow
= putPaddrLow(pdma_phys_fcp_cmd
);
998 iocb
->un
.fcpi64
.bdl
.addrHigh
= putPaddrHigh(pdma_phys_fcp_cmd
);
999 iocb
->ulpBdeCount
= 1;
1001 iocb
->ulpClass
= CLASS3
;
1002 psb
->cur_iocbq
.context1
= psb
;
1003 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
1004 pdma_phys_bpl1
= pdma_phys_bpl
+ SGL_PAGE_SIZE
;
1007 psb
->dma_phys_bpl
= pdma_phys_bpl
;
1009 /* add the scsi buffer to a post list */
1010 list_add_tail(&psb
->list
, &post_sblist
);
1011 spin_lock_irq(&phba
->scsi_buf_list_lock
);
1012 phba
->sli4_hba
.scsi_xri_cnt
++;
1013 spin_unlock_irq(&phba
->scsi_buf_list_lock
);
1015 lpfc_printf_log(phba
, KERN_INFO
, LOG_BG
,
1016 "3021 Allocate %d out of %d requested new SCSI "
1017 "buffers\n", bcnt
, num_to_alloc
);
1019 /* post the list of scsi buffer sgls to port if available */
1020 if (!list_empty(&post_sblist
))
1021 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
,
1022 &post_sblist
, bcnt
);
1030 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
1031 * @vport: The virtual port for which this call being executed.
1032 * @num_to_allocate: The requested number of buffers to allocate.
1034 * This routine wraps the actual SCSI buffer allocator function pointer from
1035 * the lpfc_hba struct.
1038 * int - number of scsi buffers that were allocated.
1039 * 0 = failure, less than num_to_alloc is a partial failure.
1042 lpfc_new_scsi_buf(struct lpfc_vport
*vport
, int num_to_alloc
)
1044 return vport
->phba
->lpfc_new_scsi_buf(vport
, num_to_alloc
);
1048 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1049 * @phba: The HBA for which this call is being executed.
1051 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1052 * and returns to caller.
1056 * Pointer to lpfc_scsi_buf - Success
1058 static struct lpfc_scsi_buf
*
1059 lpfc_get_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1061 struct lpfc_scsi_buf
* lpfc_cmd
= NULL
;
1062 struct list_head
*scsi_buf_list
= &phba
->lpfc_scsi_buf_list
;
1063 unsigned long iflag
= 0;
1065 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1066 list_remove_head(scsi_buf_list
, lpfc_cmd
, struct lpfc_scsi_buf
, list
);
1068 lpfc_cmd
->seg_cnt
= 0;
1069 lpfc_cmd
->nonsg_phys
= 0;
1070 lpfc_cmd
->prot_seg_cnt
= 0;
1072 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1076 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1077 * @phba: The HBA for which this call is being executed.
1079 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1080 * and returns to caller.
1084 * Pointer to lpfc_scsi_buf - Success
1086 static struct lpfc_scsi_buf
*
1087 lpfc_get_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1089 struct lpfc_scsi_buf
*lpfc_cmd
;
1090 unsigned long iflag
= 0;
1093 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1094 list_for_each_entry(lpfc_cmd
, &phba
->lpfc_scsi_buf_list
,
1096 if (lpfc_test_rrq_active(phba
, ndlp
,
1097 lpfc_cmd
->cur_iocbq
.sli4_lxritag
))
1099 list_del(&lpfc_cmd
->list
);
1101 lpfc_cmd
->seg_cnt
= 0;
1102 lpfc_cmd
->nonsg_phys
= 0;
1103 lpfc_cmd
->prot_seg_cnt
= 0;
1106 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
,
1114 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1115 * @phba: The HBA for which this call is being executed.
1117 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1118 * and returns to caller.
1122 * Pointer to lpfc_scsi_buf - Success
1124 static struct lpfc_scsi_buf
*
1125 lpfc_get_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1127 return phba
->lpfc_get_scsi_buf(phba
, ndlp
);
1131 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
1132 * @phba: The Hba for which this call is being executed.
1133 * @psb: The scsi buffer which is being released.
1135 * This routine releases @psb scsi buffer by adding it to tail of @phba
1136 * lpfc_scsi_buf_list list.
1139 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1141 unsigned long iflag
= 0;
1143 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1145 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
1146 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1150 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
1151 * @phba: The Hba for which this call is being executed.
1152 * @psb: The scsi buffer which is being released.
1154 * This routine releases @psb scsi buffer by adding it to tail of @phba
1155 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
1156 * and cannot be reused for at least RA_TOV amount of time if it was
1160 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1162 unsigned long iflag
= 0;
1164 if (psb
->exch_busy
) {
1165 spin_lock_irqsave(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1168 list_add_tail(&psb
->list
,
1169 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
1170 spin_unlock_irqrestore(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1174 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
1176 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
1177 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
1182 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
1183 * @phba: The Hba for which this call is being executed.
1184 * @psb: The scsi buffer which is being released.
1186 * This routine releases @psb scsi buffer by adding it to tail of @phba
1187 * lpfc_scsi_buf_list list.
1190 lpfc_release_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1193 phba
->lpfc_release_scsi_buf(phba
, psb
);
1197 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
1198 * @phba: The Hba for which this call is being executed.
1199 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1201 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1202 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1203 * through sg elements and format the bdea. This routine also initializes all
1204 * IOCB fields which are dependent on scsi command request buffer.
1211 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
1213 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
1214 struct scatterlist
*sgel
= NULL
;
1215 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
1216 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
1217 struct lpfc_iocbq
*iocbq
= &lpfc_cmd
->cur_iocbq
;
1218 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
1219 struct ulp_bde64
*data_bde
= iocb_cmd
->unsli3
.fcp_ext
.dbde
;
1220 dma_addr_t physaddr
;
1221 uint32_t num_bde
= 0;
1222 int nseg
, datadir
= scsi_cmnd
->sc_data_direction
;
1225 * There are three possibilities here - use scatter-gather segment, use
1226 * the single mapping, or neither. Start the lpfc command prep by
1227 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1231 if (scsi_sg_count(scsi_cmnd
)) {
1233 * The driver stores the segment count returned from pci_map_sg
1234 * because this a count of dma-mappings used to map the use_sg
1235 * pages. They are not guaranteed to be the same for those
1236 * architectures that implement an IOMMU.
1239 nseg
= dma_map_sg(&phba
->pcidev
->dev
, scsi_sglist(scsi_cmnd
),
1240 scsi_sg_count(scsi_cmnd
), datadir
);
1241 if (unlikely(!nseg
))
1244 lpfc_cmd
->seg_cnt
= nseg
;
1245 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
1246 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1247 "9064 BLKGRD: %s: Too many sg segments from "
1248 "dma_map_sg. Config %d, seg_cnt %d\n",
1249 __func__
, phba
->cfg_sg_seg_cnt
,
1251 scsi_dma_unmap(scsi_cmnd
);
1256 * The driver established a maximum scatter-gather segment count
1257 * during probe that limits the number of sg elements in any
1258 * single scsi command. Just run through the seg_cnt and format
1260 * When using SLI-3 the driver will try to fit all the BDEs into
1261 * the IOCB. If it can't then the BDEs get added to a BPL as it
1262 * does for SLI-2 mode.
1264 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
1265 physaddr
= sg_dma_address(sgel
);
1266 if (phba
->sli_rev
== 3 &&
1267 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1268 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
) &&
1269 nseg
<= LPFC_EXT_DATA_BDE_COUNT
) {
1270 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1271 data_bde
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1272 data_bde
->addrLow
= putPaddrLow(physaddr
);
1273 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1276 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1277 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1278 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1280 le32_to_cpu(putPaddrLow(physaddr
));
1282 le32_to_cpu(putPaddrHigh(physaddr
));
1289 * Finish initializing those IOCB fields that are dependent on the
1290 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1291 * explicitly reinitialized and for SLI-3 the extended bde count is
1292 * explicitly reinitialized since all iocb memory resources are reused.
1294 if (phba
->sli_rev
== 3 &&
1295 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1296 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
)) {
1297 if (num_bde
> LPFC_EXT_DATA_BDE_COUNT
) {
1299 * The extended IOCB format can only fit 3 BDE or a BPL.
1300 * This I/O has more than 3 BDE so the 1st data bde will
1301 * be a BPL that is filled in here.
1303 physaddr
= lpfc_cmd
->dma_handle
;
1304 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BLP_64
;
1305 data_bde
->tus
.f
.bdeSize
= (num_bde
*
1306 sizeof(struct ulp_bde64
));
1307 physaddr
+= (sizeof(struct fcp_cmnd
) +
1308 sizeof(struct fcp_rsp
) +
1309 (2 * sizeof(struct ulp_bde64
)));
1310 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1311 data_bde
->addrLow
= putPaddrLow(physaddr
);
1312 /* ebde count includes the response bde and data bpl */
1313 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= 2;
1315 /* ebde count includes the response bde and data bdes */
1316 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1319 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
=
1320 ((num_bde
+ 2) * sizeof(struct ulp_bde64
));
1321 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1323 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
1326 * Due to difference in data length between DIF/non-DIF paths,
1327 * we need to set word 4 of IOCB here
1329 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
1333 static inline unsigned
1334 lpfc_cmd_blksize(struct scsi_cmnd
*sc
)
1336 return sc
->device
->sector_size
;
1339 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1341 /* Return if if error injection is detected by Initiator */
1342 #define BG_ERR_INIT 0x1
1343 /* Return if if error injection is detected by Target */
1344 #define BG_ERR_TGT 0x2
1345 /* Return if if swapping CSUM<-->CRC is required for error injection */
1346 #define BG_ERR_SWAP 0x10
1347 /* Return if disabling Guard/Ref/App checking is required for error injection */
1348 #define BG_ERR_CHECK 0x20
1351 * lpfc_bg_err_inject - Determine if we should inject an error
1352 * @phba: The Hba for which this call is being executed.
1353 * @sc: The SCSI command to examine
1354 * @reftag: (out) BlockGuard reference tag for transmitted data
1355 * @apptag: (out) BlockGuard application tag for transmitted data
1356 * @new_guard (in) Value to replace CRC with if needed
1358 * Returns BG_ERR_* bit mask or 0 if request ignored
1361 lpfc_bg_err_inject(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1362 uint32_t *reftag
, uint16_t *apptag
, uint32_t new_guard
)
1364 struct scatterlist
*sgpe
; /* s/g prot entry */
1365 struct scatterlist
*sgde
; /* s/g data entry */
1366 struct lpfc_scsi_buf
*lpfc_cmd
= NULL
;
1367 struct scsi_dif_tuple
*src
= NULL
;
1368 struct lpfc_nodelist
*ndlp
;
1369 struct lpfc_rport_data
*rdata
;
1370 uint32_t op
= scsi_get_prot_op(sc
);
1377 if (op
== SCSI_PROT_NORMAL
)
1380 sgpe
= scsi_prot_sglist(sc
);
1381 sgde
= scsi_sglist(sc
);
1382 lba
= scsi_get_lba(sc
);
1384 /* First check if we need to match the LBA */
1385 if (phba
->lpfc_injerr_lba
!= LPFC_INJERR_LBA_OFF
) {
1386 blksize
= lpfc_cmd_blksize(sc
);
1387 numblks
= (scsi_bufflen(sc
) + blksize
- 1) / blksize
;
1389 /* Make sure we have the right LBA if one is specified */
1390 if ((phba
->lpfc_injerr_lba
< lba
) ||
1391 (phba
->lpfc_injerr_lba
>= (lba
+ numblks
)))
1394 blockoff
= phba
->lpfc_injerr_lba
- lba
;
1395 numblks
= sg_dma_len(sgpe
) /
1396 sizeof(struct scsi_dif_tuple
);
1397 if (numblks
< blockoff
)
1402 /* Next check if we need to match the remote NPortID or WWPN */
1403 rdata
= sc
->device
->hostdata
;
1404 if (rdata
&& rdata
->pnode
) {
1405 ndlp
= rdata
->pnode
;
1407 /* Make sure we have the right NPortID if one is specified */
1408 if (phba
->lpfc_injerr_nportid
&&
1409 (phba
->lpfc_injerr_nportid
!= ndlp
->nlp_DID
))
1413 * Make sure we have the right WWPN if one is specified.
1414 * wwn[0] should be a non-zero NAA in a good WWPN.
1416 if (phba
->lpfc_injerr_wwpn
.u
.wwn
[0] &&
1417 (memcmp(&ndlp
->nlp_portname
, &phba
->lpfc_injerr_wwpn
,
1418 sizeof(struct lpfc_name
)) != 0))
1422 /* Setup a ptr to the protection data if the SCSI host provides it */
1424 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
1426 lpfc_cmd
= (struct lpfc_scsi_buf
*)sc
->host_scribble
;
1429 /* Should we change the Reference Tag */
1431 if (phba
->lpfc_injerr_wref_cnt
) {
1433 case SCSI_PROT_WRITE_PASS
:
1436 * For WRITE_PASS, force the error
1437 * to be sent on the wire. It should
1438 * be detected by the Target.
1439 * If blockoff != 0 error will be
1440 * inserted in middle of the IO.
1443 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1444 "9076 BLKGRD: Injecting reftag error: "
1445 "write lba x%lx + x%x oldrefTag x%x\n",
1446 (unsigned long)lba
, blockoff
,
1447 be32_to_cpu(src
->ref_tag
));
1450 * Save the old ref_tag so we can
1451 * restore it on completion.
1454 lpfc_cmd
->prot_data_type
=
1456 lpfc_cmd
->prot_data_segment
=
1458 lpfc_cmd
->prot_data
=
1461 src
->ref_tag
= cpu_to_be32(0xDEADBEEF);
1462 phba
->lpfc_injerr_wref_cnt
--;
1463 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1464 phba
->lpfc_injerr_nportid
= 0;
1465 phba
->lpfc_injerr_lba
=
1466 LPFC_INJERR_LBA_OFF
;
1467 memset(&phba
->lpfc_injerr_wwpn
,
1468 0, sizeof(struct lpfc_name
));
1470 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1475 case SCSI_PROT_WRITE_INSERT
:
1477 * For WRITE_INSERT, force the error
1478 * to be sent on the wire. It should be
1479 * detected by the Target.
1481 /* DEADBEEF will be the reftag on the wire */
1482 *reftag
= 0xDEADBEEF;
1483 phba
->lpfc_injerr_wref_cnt
--;
1484 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1485 phba
->lpfc_injerr_nportid
= 0;
1486 phba
->lpfc_injerr_lba
=
1487 LPFC_INJERR_LBA_OFF
;
1488 memset(&phba
->lpfc_injerr_wwpn
,
1489 0, sizeof(struct lpfc_name
));
1491 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1493 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1494 "9078 BLKGRD: Injecting reftag error: "
1495 "write lba x%lx\n", (unsigned long)lba
);
1497 case SCSI_PROT_WRITE_STRIP
:
1499 * For WRITE_STRIP and WRITE_PASS,
1500 * force the error on data
1501 * being copied from SLI-Host to SLI-Port.
1503 *reftag
= 0xDEADBEEF;
1504 phba
->lpfc_injerr_wref_cnt
--;
1505 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1506 phba
->lpfc_injerr_nportid
= 0;
1507 phba
->lpfc_injerr_lba
=
1508 LPFC_INJERR_LBA_OFF
;
1509 memset(&phba
->lpfc_injerr_wwpn
,
1510 0, sizeof(struct lpfc_name
));
1514 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1515 "9077 BLKGRD: Injecting reftag error: "
1516 "write lba x%lx\n", (unsigned long)lba
);
1520 if (phba
->lpfc_injerr_rref_cnt
) {
1522 case SCSI_PROT_READ_INSERT
:
1523 case SCSI_PROT_READ_STRIP
:
1524 case SCSI_PROT_READ_PASS
:
1526 * For READ_STRIP and READ_PASS, force the
1527 * error on data being read off the wire. It
1528 * should force an IO error to the driver.
1530 *reftag
= 0xDEADBEEF;
1531 phba
->lpfc_injerr_rref_cnt
--;
1532 if (phba
->lpfc_injerr_rref_cnt
== 0) {
1533 phba
->lpfc_injerr_nportid
= 0;
1534 phba
->lpfc_injerr_lba
=
1535 LPFC_INJERR_LBA_OFF
;
1536 memset(&phba
->lpfc_injerr_wwpn
,
1537 0, sizeof(struct lpfc_name
));
1541 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1542 "9079 BLKGRD: Injecting reftag error: "
1543 "read lba x%lx\n", (unsigned long)lba
);
1549 /* Should we change the Application Tag */
1551 if (phba
->lpfc_injerr_wapp_cnt
) {
1553 case SCSI_PROT_WRITE_PASS
:
1556 * For WRITE_PASS, force the error
1557 * to be sent on the wire. It should
1558 * be detected by the Target.
1559 * If blockoff != 0 error will be
1560 * inserted in middle of the IO.
1563 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1564 "9080 BLKGRD: Injecting apptag error: "
1565 "write lba x%lx + x%x oldappTag x%x\n",
1566 (unsigned long)lba
, blockoff
,
1567 be16_to_cpu(src
->app_tag
));
1570 * Save the old app_tag so we can
1571 * restore it on completion.
1574 lpfc_cmd
->prot_data_type
=
1576 lpfc_cmd
->prot_data_segment
=
1578 lpfc_cmd
->prot_data
=
1581 src
->app_tag
= cpu_to_be16(0xDEAD);
1582 phba
->lpfc_injerr_wapp_cnt
--;
1583 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1584 phba
->lpfc_injerr_nportid
= 0;
1585 phba
->lpfc_injerr_lba
=
1586 LPFC_INJERR_LBA_OFF
;
1587 memset(&phba
->lpfc_injerr_wwpn
,
1588 0, sizeof(struct lpfc_name
));
1590 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1594 case SCSI_PROT_WRITE_INSERT
:
1596 * For WRITE_INSERT, force the
1597 * error to be sent on the wire. It should be
1598 * detected by the Target.
1600 /* DEAD will be the apptag on the wire */
1602 phba
->lpfc_injerr_wapp_cnt
--;
1603 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1604 phba
->lpfc_injerr_nportid
= 0;
1605 phba
->lpfc_injerr_lba
=
1606 LPFC_INJERR_LBA_OFF
;
1607 memset(&phba
->lpfc_injerr_wwpn
,
1608 0, sizeof(struct lpfc_name
));
1610 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1612 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1613 "0813 BLKGRD: Injecting apptag error: "
1614 "write lba x%lx\n", (unsigned long)lba
);
1616 case SCSI_PROT_WRITE_STRIP
:
1618 * For WRITE_STRIP and WRITE_PASS,
1619 * force the error on data
1620 * being copied from SLI-Host to SLI-Port.
1623 phba
->lpfc_injerr_wapp_cnt
--;
1624 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1625 phba
->lpfc_injerr_nportid
= 0;
1626 phba
->lpfc_injerr_lba
=
1627 LPFC_INJERR_LBA_OFF
;
1628 memset(&phba
->lpfc_injerr_wwpn
,
1629 0, sizeof(struct lpfc_name
));
1633 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1634 "0812 BLKGRD: Injecting apptag error: "
1635 "write lba x%lx\n", (unsigned long)lba
);
1639 if (phba
->lpfc_injerr_rapp_cnt
) {
1641 case SCSI_PROT_READ_INSERT
:
1642 case SCSI_PROT_READ_STRIP
:
1643 case SCSI_PROT_READ_PASS
:
1645 * For READ_STRIP and READ_PASS, force the
1646 * error on data being read off the wire. It
1647 * should force an IO error to the driver.
1650 phba
->lpfc_injerr_rapp_cnt
--;
1651 if (phba
->lpfc_injerr_rapp_cnt
== 0) {
1652 phba
->lpfc_injerr_nportid
= 0;
1653 phba
->lpfc_injerr_lba
=
1654 LPFC_INJERR_LBA_OFF
;
1655 memset(&phba
->lpfc_injerr_wwpn
,
1656 0, sizeof(struct lpfc_name
));
1660 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1661 "0814 BLKGRD: Injecting apptag error: "
1662 "read lba x%lx\n", (unsigned long)lba
);
1669 /* Should we change the Guard Tag */
1671 if (phba
->lpfc_injerr_wgrd_cnt
) {
1673 case SCSI_PROT_WRITE_PASS
:
1677 case SCSI_PROT_WRITE_INSERT
:
1679 * For WRITE_INSERT, force the
1680 * error to be sent on the wire. It should be
1681 * detected by the Target.
1683 phba
->lpfc_injerr_wgrd_cnt
--;
1684 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1685 phba
->lpfc_injerr_nportid
= 0;
1686 phba
->lpfc_injerr_lba
=
1687 LPFC_INJERR_LBA_OFF
;
1688 memset(&phba
->lpfc_injerr_wwpn
,
1689 0, sizeof(struct lpfc_name
));
1692 rc
|= BG_ERR_TGT
| BG_ERR_SWAP
;
1693 /* Signals the caller to swap CRC->CSUM */
1695 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1696 "0817 BLKGRD: Injecting guard error: "
1697 "write lba x%lx\n", (unsigned long)lba
);
1699 case SCSI_PROT_WRITE_STRIP
:
1701 * For WRITE_STRIP and WRITE_PASS,
1702 * force the error on data
1703 * being copied from SLI-Host to SLI-Port.
1705 phba
->lpfc_injerr_wgrd_cnt
--;
1706 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1707 phba
->lpfc_injerr_nportid
= 0;
1708 phba
->lpfc_injerr_lba
=
1709 LPFC_INJERR_LBA_OFF
;
1710 memset(&phba
->lpfc_injerr_wwpn
,
1711 0, sizeof(struct lpfc_name
));
1714 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1715 /* Signals the caller to swap CRC->CSUM */
1717 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1718 "0816 BLKGRD: Injecting guard error: "
1719 "write lba x%lx\n", (unsigned long)lba
);
1723 if (phba
->lpfc_injerr_rgrd_cnt
) {
1725 case SCSI_PROT_READ_INSERT
:
1726 case SCSI_PROT_READ_STRIP
:
1727 case SCSI_PROT_READ_PASS
:
1729 * For READ_STRIP and READ_PASS, force the
1730 * error on data being read off the wire. It
1731 * should force an IO error to the driver.
1733 phba
->lpfc_injerr_rgrd_cnt
--;
1734 if (phba
->lpfc_injerr_rgrd_cnt
== 0) {
1735 phba
->lpfc_injerr_nportid
= 0;
1736 phba
->lpfc_injerr_lba
=
1737 LPFC_INJERR_LBA_OFF
;
1738 memset(&phba
->lpfc_injerr_wwpn
,
1739 0, sizeof(struct lpfc_name
));
1742 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1743 /* Signals the caller to swap CRC->CSUM */
1745 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1746 "0818 BLKGRD: Injecting guard error: "
1747 "read lba x%lx\n", (unsigned long)lba
);
1757 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1758 * the specified SCSI command.
1759 * @phba: The Hba for which this call is being executed.
1760 * @sc: The SCSI command to examine
1761 * @txopt: (out) BlockGuard operation for transmitted data
1762 * @rxopt: (out) BlockGuard operation for received data
1764 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1768 lpfc_sc_to_bg_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1769 uint8_t *txop
, uint8_t *rxop
)
1771 uint8_t guard_type
= scsi_host_get_guard(sc
->device
->host
);
1774 if (guard_type
== SHOST_DIX_GUARD_IP
) {
1775 switch (scsi_get_prot_op(sc
)) {
1776 case SCSI_PROT_READ_INSERT
:
1777 case SCSI_PROT_WRITE_STRIP
:
1778 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1779 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1782 case SCSI_PROT_READ_STRIP
:
1783 case SCSI_PROT_WRITE_INSERT
:
1784 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1785 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1788 case SCSI_PROT_READ_PASS
:
1789 case SCSI_PROT_WRITE_PASS
:
1790 *rxop
= BG_OP_IN_CRC_OUT_CSUM
;
1791 *txop
= BG_OP_IN_CSUM_OUT_CRC
;
1794 case SCSI_PROT_NORMAL
:
1796 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1797 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1798 scsi_get_prot_op(sc
));
1804 switch (scsi_get_prot_op(sc
)) {
1805 case SCSI_PROT_READ_STRIP
:
1806 case SCSI_PROT_WRITE_INSERT
:
1807 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1808 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1811 case SCSI_PROT_READ_PASS
:
1812 case SCSI_PROT_WRITE_PASS
:
1813 *rxop
= BG_OP_IN_CRC_OUT_CRC
;
1814 *txop
= BG_OP_IN_CRC_OUT_CRC
;
1817 case SCSI_PROT_READ_INSERT
:
1818 case SCSI_PROT_WRITE_STRIP
:
1819 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1820 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1823 case SCSI_PROT_NORMAL
:
1825 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1826 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1827 scsi_get_prot_op(sc
));
1836 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1838 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1839 * the specified SCSI command in order to force a guard tag error.
1840 * @phba: The Hba for which this call is being executed.
1841 * @sc: The SCSI command to examine
1842 * @txopt: (out) BlockGuard operation for transmitted data
1843 * @rxopt: (out) BlockGuard operation for received data
1845 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1849 lpfc_bg_err_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1850 uint8_t *txop
, uint8_t *rxop
)
1852 uint8_t guard_type
= scsi_host_get_guard(sc
->device
->host
);
1855 if (guard_type
== SHOST_DIX_GUARD_IP
) {
1856 switch (scsi_get_prot_op(sc
)) {
1857 case SCSI_PROT_READ_INSERT
:
1858 case SCSI_PROT_WRITE_STRIP
:
1859 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1860 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1863 case SCSI_PROT_READ_STRIP
:
1864 case SCSI_PROT_WRITE_INSERT
:
1865 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1866 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1869 case SCSI_PROT_READ_PASS
:
1870 case SCSI_PROT_WRITE_PASS
:
1871 *rxop
= BG_OP_IN_CSUM_OUT_CRC
;
1872 *txop
= BG_OP_IN_CRC_OUT_CSUM
;
1875 case SCSI_PROT_NORMAL
:
1881 switch (scsi_get_prot_op(sc
)) {
1882 case SCSI_PROT_READ_STRIP
:
1883 case SCSI_PROT_WRITE_INSERT
:
1884 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1885 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1888 case SCSI_PROT_READ_PASS
:
1889 case SCSI_PROT_WRITE_PASS
:
1890 *rxop
= BG_OP_IN_CSUM_OUT_CSUM
;
1891 *txop
= BG_OP_IN_CSUM_OUT_CSUM
;
1894 case SCSI_PROT_READ_INSERT
:
1895 case SCSI_PROT_WRITE_STRIP
:
1896 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1897 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1900 case SCSI_PROT_NORMAL
:
1911 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1912 * @phba: The Hba for which this call is being executed.
1913 * @sc: pointer to scsi command we're working on
1914 * @bpl: pointer to buffer list for protection groups
1915 * @datacnt: number of segments of data that have been dma mapped
1917 * This function sets up BPL buffer list for protection groups of
1918 * type LPFC_PG_TYPE_NO_DIF
1920 * This is usually used when the HBA is instructed to generate
1921 * DIFs and insert them into data stream (or strip DIF from
1922 * incoming data stream)
1924 * The buffer list consists of just one protection group described
1926 * +-------------------------+
1927 * start of prot group --> | PDE_5 |
1928 * +-------------------------+
1930 * +-------------------------+
1932 * +-------------------------+
1933 * |more Data BDE's ... (opt)|
1934 * +-------------------------+
1937 * Note: Data s/g buffers have been dma mapped
1939 * Returns the number of BDEs added to the BPL.
1942 lpfc_bg_setup_bpl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1943 struct ulp_bde64
*bpl
, int datasegcnt
)
1945 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1946 struct lpfc_pde5
*pde5
= NULL
;
1947 struct lpfc_pde6
*pde6
= NULL
;
1948 dma_addr_t physaddr
;
1949 int i
= 0, num_bde
= 0, status
;
1950 int datadir
= sc
->sc_data_direction
;
1951 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1954 uint32_t checking
= 1;
1959 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
1963 /* extract some info from the scsi command for pde*/
1964 blksize
= lpfc_cmd_blksize(sc
);
1965 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
1967 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1968 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
1970 if (rc
& BG_ERR_SWAP
)
1971 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
1972 if (rc
& BG_ERR_CHECK
)
1977 /* setup PDE5 with what we have */
1978 pde5
= (struct lpfc_pde5
*) bpl
;
1979 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
1980 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
1982 /* Endianness conversion if necessary for PDE5 */
1983 pde5
->word0
= cpu_to_le32(pde5
->word0
);
1984 pde5
->reftag
= cpu_to_le32(reftag
);
1986 /* advance bpl and increment bde count */
1989 pde6
= (struct lpfc_pde6
*) bpl
;
1991 /* setup PDE6 with the rest of the info */
1992 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
1993 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
1994 bf_set(pde6_optx
, pde6
, txop
);
1995 bf_set(pde6_oprx
, pde6
, rxop
);
1996 if (datadir
== DMA_FROM_DEVICE
) {
1997 bf_set(pde6_ce
, pde6
, checking
);
1998 bf_set(pde6_re
, pde6
, checking
);
2000 bf_set(pde6_ai
, pde6
, 1);
2001 bf_set(pde6_ae
, pde6
, 0);
2002 bf_set(pde6_apptagval
, pde6
, 0);
2004 /* Endianness conversion if necessary for PDE6 */
2005 pde6
->word0
= cpu_to_le32(pde6
->word0
);
2006 pde6
->word1
= cpu_to_le32(pde6
->word1
);
2007 pde6
->word2
= cpu_to_le32(pde6
->word2
);
2009 /* advance bpl and increment bde count */
2013 /* assumption: caller has already run dma_map_sg on command data */
2014 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
2015 physaddr
= sg_dma_address(sgde
);
2016 bpl
->addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
2017 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
2018 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgde
);
2019 if (datadir
== DMA_TO_DEVICE
)
2020 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2022 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2023 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2033 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
2034 * @phba: The Hba for which this call is being executed.
2035 * @sc: pointer to scsi command we're working on
2036 * @bpl: pointer to buffer list for protection groups
2037 * @datacnt: number of segments of data that have been dma mapped
2038 * @protcnt: number of segment of protection data that have been dma mapped
2040 * This function sets up BPL buffer list for protection groups of
2041 * type LPFC_PG_TYPE_DIF
2043 * This is usually used when DIFs are in their own buffers,
2044 * separate from the data. The HBA can then by instructed
2045 * to place the DIFs in the outgoing stream. For read operations,
2046 * The HBA could extract the DIFs and place it in DIF buffers.
2048 * The buffer list for this type consists of one or more of the
2049 * protection groups described below:
2050 * +-------------------------+
2051 * start of first prot group --> | PDE_5 |
2052 * +-------------------------+
2054 * +-------------------------+
2055 * | PDE_7 (Prot BDE) |
2056 * +-------------------------+
2058 * +-------------------------+
2059 * |more Data BDE's ... (opt)|
2060 * +-------------------------+
2061 * start of new prot group --> | PDE_5 |
2062 * +-------------------------+
2064 * +-------------------------+
2066 * Note: It is assumed that both data and protection s/g buffers have been
2069 * Returns the number of BDEs added to the BPL.
2072 lpfc_bg_setup_bpl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2073 struct ulp_bde64
*bpl
, int datacnt
, int protcnt
)
2075 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2076 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2077 struct lpfc_pde5
*pde5
= NULL
;
2078 struct lpfc_pde6
*pde6
= NULL
;
2079 struct lpfc_pde7
*pde7
= NULL
;
2080 dma_addr_t dataphysaddr
, protphysaddr
;
2081 unsigned short curr_data
= 0, curr_prot
= 0;
2082 unsigned int split_offset
;
2083 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2084 unsigned int protgrp_blks
, protgrp_bytes
;
2085 unsigned int remainder
, subtotal
;
2087 int datadir
= sc
->sc_data_direction
;
2088 unsigned char pgdone
= 0, alldone
= 0;
2090 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2093 uint32_t checking
= 1;
2098 sgpe
= scsi_prot_sglist(sc
);
2099 sgde
= scsi_sglist(sc
);
2101 if (!sgpe
|| !sgde
) {
2102 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2103 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
2108 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2112 /* extract some info from the scsi command */
2113 blksize
= lpfc_cmd_blksize(sc
);
2114 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2116 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2117 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2119 if (rc
& BG_ERR_SWAP
)
2120 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2121 if (rc
& BG_ERR_CHECK
)
2128 /* setup PDE5 with what we have */
2129 pde5
= (struct lpfc_pde5
*) bpl
;
2130 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
2131 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
2133 /* Endianness conversion if necessary for PDE5 */
2134 pde5
->word0
= cpu_to_le32(pde5
->word0
);
2135 pde5
->reftag
= cpu_to_le32(reftag
);
2137 /* advance bpl and increment bde count */
2140 pde6
= (struct lpfc_pde6
*) bpl
;
2142 /* setup PDE6 with the rest of the info */
2143 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
2144 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
2145 bf_set(pde6_optx
, pde6
, txop
);
2146 bf_set(pde6_oprx
, pde6
, rxop
);
2147 bf_set(pde6_ce
, pde6
, checking
);
2148 bf_set(pde6_re
, pde6
, checking
);
2149 bf_set(pde6_ai
, pde6
, 1);
2150 bf_set(pde6_ae
, pde6
, 0);
2151 bf_set(pde6_apptagval
, pde6
, 0);
2153 /* Endianness conversion if necessary for PDE6 */
2154 pde6
->word0
= cpu_to_le32(pde6
->word0
);
2155 pde6
->word1
= cpu_to_le32(pde6
->word1
);
2156 pde6
->word2
= cpu_to_le32(pde6
->word2
);
2158 /* advance bpl and increment bde count */
2162 /* setup the first BDE that points to protection buffer */
2163 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2164 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2166 /* must be integer multiple of the DIF block length */
2167 BUG_ON(protgroup_len
% 8);
2169 pde7
= (struct lpfc_pde7
*) bpl
;
2170 memset(pde7
, 0, sizeof(struct lpfc_pde7
));
2171 bf_set(pde7_type
, pde7
, LPFC_PDE7_DESCRIPTOR
);
2173 pde7
->addrHigh
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2174 pde7
->addrLow
= le32_to_cpu(putPaddrLow(protphysaddr
));
2176 protgrp_blks
= protgroup_len
/ 8;
2177 protgrp_bytes
= protgrp_blks
* blksize
;
2179 /* check if this pde is crossing the 4K boundary; if so split */
2180 if ((pde7
->addrLow
& 0xfff) + protgroup_len
> 0x1000) {
2181 protgroup_remainder
= 0x1000 - (pde7
->addrLow
& 0xfff);
2182 protgroup_offset
+= protgroup_remainder
;
2183 protgrp_blks
= protgroup_remainder
/ 8;
2184 protgrp_bytes
= protgrp_blks
* blksize
;
2186 protgroup_offset
= 0;
2192 /* setup BDE's for data blocks associated with DIF data */
2194 subtotal
= 0; /* total bytes processed for current prot grp */
2197 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2198 "9065 BLKGRD:%s Invalid data segment\n",
2203 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2204 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dataphysaddr
));
2205 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dataphysaddr
));
2207 remainder
= sg_dma_len(sgde
) - split_offset
;
2209 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2210 /* we can use this whole buffer */
2211 bpl
->tus
.f
.bdeSize
= remainder
;
2214 if ((subtotal
+ remainder
) == protgrp_bytes
)
2217 /* must split this buffer with next prot grp */
2218 bpl
->tus
.f
.bdeSize
= protgrp_bytes
- subtotal
;
2219 split_offset
+= bpl
->tus
.f
.bdeSize
;
2222 subtotal
+= bpl
->tus
.f
.bdeSize
;
2224 if (datadir
== DMA_TO_DEVICE
)
2225 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2227 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2228 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2236 /* Move to the next s/g segment if possible */
2237 sgde
= sg_next(sgde
);
2241 if (protgroup_offset
) {
2242 /* update the reference tag */
2243 reftag
+= protgrp_blks
;
2249 if (curr_prot
== protcnt
) {
2251 } else if (curr_prot
< protcnt
) {
2252 /* advance to next prot buffer */
2253 sgpe
= sg_next(sgpe
);
2256 /* update the reference tag */
2257 reftag
+= protgrp_blks
;
2259 /* if we're here, we have a bug */
2260 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2261 "9054 BLKGRD: bug in %s\n", __func__
);
2271 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
2272 * @phba: The Hba for which this call is being executed.
2273 * @sc: pointer to scsi command we're working on
2274 * @sgl: pointer to buffer list for protection groups
2275 * @datacnt: number of segments of data that have been dma mapped
2277 * This function sets up SGL buffer list for protection groups of
2278 * type LPFC_PG_TYPE_NO_DIF
2280 * This is usually used when the HBA is instructed to generate
2281 * DIFs and insert them into data stream (or strip DIF from
2282 * incoming data stream)
2284 * The buffer list consists of just one protection group described
2286 * +-------------------------+
2287 * start of prot group --> | DI_SEED |
2288 * +-------------------------+
2290 * +-------------------------+
2291 * |more Data SGE's ... (opt)|
2292 * +-------------------------+
2295 * Note: Data s/g buffers have been dma mapped
2297 * Returns the number of SGEs added to the SGL.
2300 lpfc_bg_setup_sgl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2301 struct sli4_sge
*sgl
, int datasegcnt
)
2303 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2304 struct sli4_sge_diseed
*diseed
= NULL
;
2305 dma_addr_t physaddr
;
2306 int i
= 0, num_sge
= 0, status
;
2307 int datadir
= sc
->sc_data_direction
;
2311 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2314 uint32_t checking
= 1;
2316 uint32_t dma_offset
= 0;
2318 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2322 /* extract some info from the scsi command for pde*/
2323 blksize
= lpfc_cmd_blksize(sc
);
2324 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2326 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2327 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2329 if (rc
& BG_ERR_SWAP
)
2330 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2331 if (rc
& BG_ERR_CHECK
)
2336 /* setup DISEED with what we have */
2337 diseed
= (struct sli4_sge_diseed
*) sgl
;
2338 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2339 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2341 /* Endianness conversion if necessary */
2342 diseed
->ref_tag
= cpu_to_le32(reftag
);
2343 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2345 /* setup DISEED with the rest of the info */
2346 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2347 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2348 if (datadir
== DMA_FROM_DEVICE
) {
2349 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2350 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2352 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2353 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2355 /* Endianness conversion if necessary for DISEED */
2356 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2357 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2359 /* advance bpl and increment sge count */
2363 /* assumption: caller has already run dma_map_sg on command data */
2364 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
2365 physaddr
= sg_dma_address(sgde
);
2366 dma_len
= sg_dma_len(sgde
);
2367 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
2368 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
2369 if ((i
+ 1) == datasegcnt
)
2370 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2372 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2373 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2374 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2376 sgl
->sge_len
= cpu_to_le32(dma_len
);
2377 dma_offset
+= dma_len
;
2388 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2389 * @phba: The Hba for which this call is being executed.
2390 * @sc: pointer to scsi command we're working on
2391 * @sgl: pointer to buffer list for protection groups
2392 * @datacnt: number of segments of data that have been dma mapped
2393 * @protcnt: number of segment of protection data that have been dma mapped
2395 * This function sets up SGL buffer list for protection groups of
2396 * type LPFC_PG_TYPE_DIF
2398 * This is usually used when DIFs are in their own buffers,
2399 * separate from the data. The HBA can then by instructed
2400 * to place the DIFs in the outgoing stream. For read operations,
2401 * The HBA could extract the DIFs and place it in DIF buffers.
2403 * The buffer list for this type consists of one or more of the
2404 * protection groups described below:
2405 * +-------------------------+
2406 * start of first prot group --> | DISEED |
2407 * +-------------------------+
2408 * | DIF (Prot SGE) |
2409 * +-------------------------+
2411 * +-------------------------+
2412 * |more Data SGE's ... (opt)|
2413 * +-------------------------+
2414 * start of new prot group --> | DISEED |
2415 * +-------------------------+
2417 * +-------------------------+
2419 * Note: It is assumed that both data and protection s/g buffers have been
2422 * Returns the number of SGEs added to the SGL.
2425 lpfc_bg_setup_sgl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2426 struct sli4_sge
*sgl
, int datacnt
, int protcnt
)
2428 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2429 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2430 struct sli4_sge_diseed
*diseed
= NULL
;
2431 dma_addr_t dataphysaddr
, protphysaddr
;
2432 unsigned short curr_data
= 0, curr_prot
= 0;
2433 unsigned int split_offset
;
2434 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2435 unsigned int protgrp_blks
, protgrp_bytes
;
2436 unsigned int remainder
, subtotal
;
2438 unsigned char pgdone
= 0, alldone
= 0;
2443 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2446 uint32_t checking
= 1;
2447 uint32_t dma_offset
= 0;
2450 sgpe
= scsi_prot_sglist(sc
);
2451 sgde
= scsi_sglist(sc
);
2453 if (!sgpe
|| !sgde
) {
2454 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2455 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2460 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2464 /* extract some info from the scsi command */
2465 blksize
= lpfc_cmd_blksize(sc
);
2466 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2468 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2469 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2471 if (rc
& BG_ERR_SWAP
)
2472 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2473 if (rc
& BG_ERR_CHECK
)
2480 /* setup DISEED with what we have */
2481 diseed
= (struct sli4_sge_diseed
*) sgl
;
2482 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2483 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2485 /* Endianness conversion if necessary */
2486 diseed
->ref_tag
= cpu_to_le32(reftag
);
2487 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2489 /* setup DISEED with the rest of the info */
2490 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2491 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2492 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2493 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2494 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2495 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2497 /* Endianness conversion if necessary for DISEED */
2498 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2499 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2501 /* advance sgl and increment bde count */
2505 /* setup the first BDE that points to protection buffer */
2506 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2507 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2509 /* must be integer multiple of the DIF block length */
2510 BUG_ON(protgroup_len
% 8);
2512 /* Now setup DIF SGE */
2514 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DIF
);
2515 sgl
->addr_hi
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2516 sgl
->addr_lo
= le32_to_cpu(putPaddrLow(protphysaddr
));
2517 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2519 protgrp_blks
= protgroup_len
/ 8;
2520 protgrp_bytes
= protgrp_blks
* blksize
;
2522 /* check if DIF SGE is crossing the 4K boundary; if so split */
2523 if ((sgl
->addr_lo
& 0xfff) + protgroup_len
> 0x1000) {
2524 protgroup_remainder
= 0x1000 - (sgl
->addr_lo
& 0xfff);
2525 protgroup_offset
+= protgroup_remainder
;
2526 protgrp_blks
= protgroup_remainder
/ 8;
2527 protgrp_bytes
= protgrp_blks
* blksize
;
2529 protgroup_offset
= 0;
2535 /* setup SGE's for data blocks associated with DIF data */
2537 subtotal
= 0; /* total bytes processed for current prot grp */
2540 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2541 "9086 BLKGRD:%s Invalid data segment\n",
2546 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2548 remainder
= sg_dma_len(sgde
) - split_offset
;
2550 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2551 /* we can use this whole buffer */
2552 dma_len
= remainder
;
2555 if ((subtotal
+ remainder
) == protgrp_bytes
)
2558 /* must split this buffer with next prot grp */
2559 dma_len
= protgrp_bytes
- subtotal
;
2560 split_offset
+= dma_len
;
2563 subtotal
+= dma_len
;
2565 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(dataphysaddr
));
2566 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(dataphysaddr
));
2567 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2568 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2569 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2571 sgl
->sge_len
= cpu_to_le32(dma_len
);
2572 dma_offset
+= dma_len
;
2580 /* Move to the next s/g segment if possible */
2581 sgde
= sg_next(sgde
);
2584 if (protgroup_offset
) {
2585 /* update the reference tag */
2586 reftag
+= protgrp_blks
;
2592 if (curr_prot
== protcnt
) {
2593 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2595 } else if (curr_prot
< protcnt
) {
2596 /* advance to next prot buffer */
2597 sgpe
= sg_next(sgpe
);
2600 /* update the reference tag */
2601 reftag
+= protgrp_blks
;
2603 /* if we're here, we have a bug */
2604 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2605 "9085 BLKGRD: bug in %s\n", __func__
);
2616 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2617 * @phba: The Hba for which this call is being executed.
2618 * @sc: pointer to scsi command we're working on
2620 * Given a SCSI command that supports DIF, determine composition of protection
2621 * groups involved in setting up buffer lists
2623 * Returns: Protection group type (with or without DIF)
2627 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
)
2629 int ret
= LPFC_PG_TYPE_INVALID
;
2630 unsigned char op
= scsi_get_prot_op(sc
);
2633 case SCSI_PROT_READ_STRIP
:
2634 case SCSI_PROT_WRITE_INSERT
:
2635 ret
= LPFC_PG_TYPE_NO_DIF
;
2637 case SCSI_PROT_READ_INSERT
:
2638 case SCSI_PROT_WRITE_STRIP
:
2639 case SCSI_PROT_READ_PASS
:
2640 case SCSI_PROT_WRITE_PASS
:
2641 ret
= LPFC_PG_TYPE_DIF_BUF
;
2644 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2645 "9021 Unsupported protection op:%d\n", op
);
2653 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2654 * @phba: The Hba for which this call is being executed.
2655 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2657 * This is the protection/DIF aware version of
2658 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2659 * two functions eventually, but for now, it's here
2662 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
,
2663 struct lpfc_scsi_buf
*lpfc_cmd
)
2665 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2666 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2667 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
2668 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2669 uint32_t num_bde
= 0;
2670 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
2671 int prot_group_type
= 0;
2676 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2677 * fcp_rsp regions to the first data bde entry
2680 if (scsi_sg_count(scsi_cmnd
)) {
2682 * The driver stores the segment count returned from pci_map_sg
2683 * because this a count of dma-mappings used to map the use_sg
2684 * pages. They are not guaranteed to be the same for those
2685 * architectures that implement an IOMMU.
2687 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2688 scsi_sglist(scsi_cmnd
),
2689 scsi_sg_count(scsi_cmnd
), datadir
);
2690 if (unlikely(!datasegcnt
))
2693 lpfc_cmd
->seg_cnt
= datasegcnt
;
2694 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
2695 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2696 "9067 BLKGRD: %s: Too many sg segments"
2697 " from dma_map_sg. Config %d, seg_cnt"
2699 __func__
, phba
->cfg_sg_seg_cnt
,
2701 scsi_dma_unmap(scsi_cmnd
);
2705 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
2707 switch (prot_group_type
) {
2708 case LPFC_PG_TYPE_NO_DIF
:
2709 num_bde
= lpfc_bg_setup_bpl(phba
, scsi_cmnd
, bpl
,
2711 /* we should have 2 or more entries in buffer list */
2715 case LPFC_PG_TYPE_DIF_BUF
:{
2717 * This type indicates that protection buffers are
2718 * passed to the driver, so that needs to be prepared
2721 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2722 scsi_prot_sglist(scsi_cmnd
),
2723 scsi_prot_sg_count(scsi_cmnd
), datadir
);
2724 if (unlikely(!protsegcnt
)) {
2725 scsi_dma_unmap(scsi_cmnd
);
2729 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
2730 if (lpfc_cmd
->prot_seg_cnt
2731 > phba
->cfg_prot_sg_seg_cnt
) {
2732 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2733 "9068 BLKGRD: %s: Too many prot sg "
2734 "segments from dma_map_sg. Config %d,"
2735 "prot_seg_cnt %d\n", __func__
,
2736 phba
->cfg_prot_sg_seg_cnt
,
2737 lpfc_cmd
->prot_seg_cnt
);
2738 dma_unmap_sg(&phba
->pcidev
->dev
,
2739 scsi_prot_sglist(scsi_cmnd
),
2740 scsi_prot_sg_count(scsi_cmnd
),
2742 scsi_dma_unmap(scsi_cmnd
);
2746 num_bde
= lpfc_bg_setup_bpl_prot(phba
, scsi_cmnd
, bpl
,
2747 datasegcnt
, protsegcnt
);
2748 /* we should have 3 or more entries in buffer list */
2753 case LPFC_PG_TYPE_INVALID
:
2755 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2756 "9022 Unexpected protection group %i\n",
2763 * Finish initializing those IOCB fields that are dependent on the
2764 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2765 * reinitialized since all iocb memory resources are used many times
2766 * for transmit, receive, and continuation bpl's.
2768 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
2769 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
+= (num_bde
* sizeof(struct ulp_bde64
));
2770 iocb_cmd
->ulpBdeCount
= 1;
2771 iocb_cmd
->ulpLe
= 1;
2773 fcpdl
= scsi_bufflen(scsi_cmnd
);
2775 if (scsi_get_prot_type(scsi_cmnd
) == SCSI_PROT_DIF_TYPE1
) {
2777 * We are in DIF Type 1 mode
2778 * Every data block has a 8 byte DIF (trailer)
2779 * attached to it. Must ajust FCP data length
2781 blksize
= lpfc_cmd_blksize(scsi_cmnd
);
2782 diflen
= (fcpdl
/ blksize
) * 8;
2785 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
2788 * Due to difference in data length between DIF/non-DIF paths,
2789 * we need to set word 4 of IOCB here
2791 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
2795 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2796 "9023 Could not setup all needed BDE's"
2797 "prot_group_type=%d, num_bde=%d\n",
2798 prot_group_type
, num_bde
);
2803 * This function checks for BlockGuard errors detected by
2804 * the HBA. In case of errors, the ASC/ASCQ fields in the
2805 * sense buffer will be set accordingly, paired with
2806 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2807 * detected corruption.
2810 * 0 - No error found
2811 * 1 - BlockGuard error found
2812 * -1 - Internal error (bad profile, ...etc)
2815 lpfc_parse_bg_err(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
,
2816 struct lpfc_iocbq
*pIocbOut
)
2818 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
2819 struct sli3_bg_fields
*bgf
= &pIocbOut
->iocb
.unsli3
.sli3_bg
;
2821 uint32_t bghm
= bgf
->bghm
;
2822 uint32_t bgstat
= bgf
->bgstat
;
2823 uint64_t failing_sector
= 0;
2825 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9069 BLKGRD: BG ERROR in cmd"
2826 " 0x%x lba 0x%llx blk cnt 0x%x "
2827 "bgstat=0x%x bghm=0x%x\n",
2828 cmd
->cmnd
[0], (unsigned long long)scsi_get_lba(cmd
),
2829 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
2831 spin_lock(&_dump_buf_lock
);
2832 if (!_dump_buf_done
) {
2833 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9070 BLKGRD: Saving"
2834 " Data for %u blocks to debugfs\n",
2835 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
2836 lpfc_debug_save_data(phba
, cmd
);
2838 /* If we have a prot sgl, save the DIF buffer */
2839 if (lpfc_prot_group_type(phba
, cmd
) ==
2840 LPFC_PG_TYPE_DIF_BUF
) {
2841 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9071 BLKGRD: "
2842 "Saving DIF for %u blocks to debugfs\n",
2843 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
2844 lpfc_debug_save_dif(phba
, cmd
);
2849 spin_unlock(&_dump_buf_lock
);
2851 if (lpfc_bgs_get_invalid_prof(bgstat
)) {
2852 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2853 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9072 BLKGRD: Invalid"
2854 " BlockGuard profile. bgstat:0x%x\n",
2860 if (lpfc_bgs_get_uninit_dif_block(bgstat
)) {
2861 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2862 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9073 BLKGRD: "
2863 "Invalid BlockGuard DIF Block. bgstat:0x%x\n",
2869 if (lpfc_bgs_get_guard_err(bgstat
)) {
2872 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2874 cmd
->result
= DRIVER_SENSE
<< 24
2875 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2876 phba
->bg_guard_err_cnt
++;
2877 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2878 "9055 BLKGRD: guard_tag error\n");
2881 if (lpfc_bgs_get_reftag_err(bgstat
)) {
2884 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2886 cmd
->result
= DRIVER_SENSE
<< 24
2887 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2889 phba
->bg_reftag_err_cnt
++;
2890 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2891 "9056 BLKGRD: ref_tag error\n");
2894 if (lpfc_bgs_get_apptag_err(bgstat
)) {
2897 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
2899 cmd
->result
= DRIVER_SENSE
<< 24
2900 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
2902 phba
->bg_apptag_err_cnt
++;
2903 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2904 "9061 BLKGRD: app_tag error\n");
2907 if (lpfc_bgs_get_hi_water_mark_present(bgstat
)) {
2909 * setup sense data descriptor 0 per SPC-4 as an information
2910 * field, and put the failing LBA in it.
2911 * This code assumes there was also a guard/app/ref tag error
2914 cmd
->sense_buffer
[7] = 0xc; /* Additional sense length */
2915 cmd
->sense_buffer
[8] = 0; /* Information descriptor type */
2916 cmd
->sense_buffer
[9] = 0xa; /* Additional descriptor length */
2917 cmd
->sense_buffer
[10] = 0x80; /* Validity bit */
2919 /* bghm is a "on the wire" FC frame based count */
2920 switch (scsi_get_prot_op(cmd
)) {
2921 case SCSI_PROT_READ_INSERT
:
2922 case SCSI_PROT_WRITE_STRIP
:
2923 bghm
/= cmd
->device
->sector_size
;
2925 case SCSI_PROT_READ_STRIP
:
2926 case SCSI_PROT_WRITE_INSERT
:
2927 case SCSI_PROT_READ_PASS
:
2928 case SCSI_PROT_WRITE_PASS
:
2929 bghm
/= (cmd
->device
->sector_size
+
2930 sizeof(struct scsi_dif_tuple
));
2934 failing_sector
= scsi_get_lba(cmd
);
2935 failing_sector
+= bghm
;
2937 /* Descriptor Information */
2938 put_unaligned_be64(failing_sector
, &cmd
->sense_buffer
[12]);
2942 /* No error was reported - problem in FW? */
2943 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2944 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2945 "9057 BLKGRD: Unknown error reported!\n");
2953 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
2954 * @phba: The Hba for which this call is being executed.
2955 * @lpfc_cmd: The scsi buffer which is going to be mapped.
2957 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
2958 * field of @lpfc_cmd for device with SLI-4 interface spec.
2965 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
2967 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2968 struct scatterlist
*sgel
= NULL
;
2969 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2970 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
2971 struct sli4_sge
*first_data_sgl
;
2972 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2973 dma_addr_t physaddr
;
2974 uint32_t num_bde
= 0;
2976 uint32_t dma_offset
= 0;
2978 struct ulp_bde64
*bde
;
2981 * There are three possibilities here - use scatter-gather segment, use
2982 * the single mapping, or neither. Start the lpfc command prep by
2983 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
2986 if (scsi_sg_count(scsi_cmnd
)) {
2988 * The driver stores the segment count returned from pci_map_sg
2989 * because this a count of dma-mappings used to map the use_sg
2990 * pages. They are not guaranteed to be the same for those
2991 * architectures that implement an IOMMU.
2994 nseg
= scsi_dma_map(scsi_cmnd
);
2995 if (unlikely(!nseg
))
2998 /* clear the last flag in the fcp_rsp map entry */
2999 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3000 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3001 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3003 first_data_sgl
= sgl
;
3004 lpfc_cmd
->seg_cnt
= nseg
;
3005 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
3006 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9074 BLKGRD:"
3007 " %s: Too many sg segments from "
3008 "dma_map_sg. Config %d, seg_cnt %d\n",
3009 __func__
, phba
->cfg_sg_seg_cnt
,
3011 scsi_dma_unmap(scsi_cmnd
);
3016 * The driver established a maximum scatter-gather segment count
3017 * during probe that limits the number of sg elements in any
3018 * single scsi command. Just run through the seg_cnt and format
3020 * When using SLI-3 the driver will try to fit all the BDEs into
3021 * the IOCB. If it can't then the BDEs get added to a BPL as it
3022 * does for SLI-2 mode.
3024 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
3025 physaddr
= sg_dma_address(sgel
);
3026 dma_len
= sg_dma_len(sgel
);
3027 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
3028 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
3029 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3030 if ((num_bde
+ 1) == nseg
)
3031 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3033 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3034 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
3035 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
3036 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3037 sgl
->sge_len
= cpu_to_le32(dma_len
);
3038 dma_offset
+= dma_len
;
3041 /* setup the performance hint (first data BDE) if enabled */
3042 if (phba
->sli3_options
& LPFC_SLI4_PERFH_ENABLED
) {
3043 bde
= (struct ulp_bde64
*)
3044 &(iocb_cmd
->unsli3
.sli3Words
[5]);
3045 bde
->addrLow
= first_data_sgl
->addr_lo
;
3046 bde
->addrHigh
= first_data_sgl
->addr_hi
;
3047 bde
->tus
.f
.bdeSize
=
3048 le32_to_cpu(first_data_sgl
->sge_len
);
3049 bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
3050 bde
->tus
.w
= cpu_to_le32(bde
->tus
.w
);
3054 /* clear the last flag in the fcp_rsp map entry */
3055 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3056 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3057 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3061 * Finish initializing those IOCB fields that are dependent on the
3062 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3063 * explicitly reinitialized.
3064 * all iocb memory resources are reused.
3066 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
3069 * Due to difference in data length between DIF/non-DIF paths,
3070 * we need to set word 4 of IOCB here
3072 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
3077 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
3078 * @phba: The Hba for which this call is being executed.
3079 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
3081 * Adjust the data length to account for how much data
3082 * is actually on the wire.
3084 * returns the adjusted data length
3087 lpfc_bg_scsi_adjust_dl(struct lpfc_hba
*phba
,
3088 struct lpfc_scsi_buf
*lpfc_cmd
)
3090 struct scsi_cmnd
*sc
= lpfc_cmd
->pCmd
;
3094 fcpdl
= scsi_bufflen(sc
);
3096 /* Check if there is protection data on the wire */
3097 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
3099 if (scsi_get_prot_op(sc
) == SCSI_PROT_READ_INSERT
)
3104 if (scsi_get_prot_op(sc
) == SCSI_PROT_WRITE_STRIP
)
3108 /* If protection data on the wire, adjust the count accordingly */
3109 blksize
= lpfc_cmd_blksize(sc
);
3110 diflen
= (fcpdl
/ blksize
) * 8;
3116 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3117 * @phba: The Hba for which this call is being executed.
3118 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3120 * This is the protection/DIF aware version of
3121 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3122 * two functions eventually, but for now, it's here
3125 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
,
3126 struct lpfc_scsi_buf
*lpfc_cmd
)
3128 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3129 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3130 struct sli4_sge
*sgl
= (struct sli4_sge
*)(lpfc_cmd
->fcp_bpl
);
3131 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3132 uint32_t num_bde
= 0;
3133 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
3134 int prot_group_type
= 0;
3138 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3139 * fcp_rsp regions to the first data bde entry
3141 if (scsi_sg_count(scsi_cmnd
)) {
3143 * The driver stores the segment count returned from pci_map_sg
3144 * because this a count of dma-mappings used to map the use_sg
3145 * pages. They are not guaranteed to be the same for those
3146 * architectures that implement an IOMMU.
3148 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3149 scsi_sglist(scsi_cmnd
),
3150 scsi_sg_count(scsi_cmnd
), datadir
);
3151 if (unlikely(!datasegcnt
))
3155 /* clear the last flag in the fcp_rsp map entry */
3156 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3157 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3158 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3161 lpfc_cmd
->seg_cnt
= datasegcnt
;
3162 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
3163 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
3164 "9087 BLKGRD: %s: Too many sg segments"
3165 " from dma_map_sg. Config %d, seg_cnt"
3167 __func__
, phba
->cfg_sg_seg_cnt
,
3169 scsi_dma_unmap(scsi_cmnd
);
3173 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
3175 switch (prot_group_type
) {
3176 case LPFC_PG_TYPE_NO_DIF
:
3177 num_bde
= lpfc_bg_setup_sgl(phba
, scsi_cmnd
, sgl
,
3179 /* we should have 2 or more entries in buffer list */
3183 case LPFC_PG_TYPE_DIF_BUF
:{
3185 * This type indicates that protection buffers are
3186 * passed to the driver, so that needs to be prepared
3189 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3190 scsi_prot_sglist(scsi_cmnd
),
3191 scsi_prot_sg_count(scsi_cmnd
), datadir
);
3192 if (unlikely(!protsegcnt
)) {
3193 scsi_dma_unmap(scsi_cmnd
);
3197 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
3198 if (lpfc_cmd
->prot_seg_cnt
3199 > phba
->cfg_prot_sg_seg_cnt
) {
3200 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
3201 "9088 BLKGRD: %s: Too many prot sg "
3202 "segments from dma_map_sg. Config %d,"
3203 "prot_seg_cnt %d\n", __func__
,
3204 phba
->cfg_prot_sg_seg_cnt
,
3205 lpfc_cmd
->prot_seg_cnt
);
3206 dma_unmap_sg(&phba
->pcidev
->dev
,
3207 scsi_prot_sglist(scsi_cmnd
),
3208 scsi_prot_sg_count(scsi_cmnd
),
3210 scsi_dma_unmap(scsi_cmnd
);
3214 num_bde
= lpfc_bg_setup_sgl_prot(phba
, scsi_cmnd
, sgl
,
3215 datasegcnt
, protsegcnt
);
3216 /* we should have 3 or more entries in buffer list */
3221 case LPFC_PG_TYPE_INVALID
:
3223 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3224 "9083 Unexpected protection group %i\n",
3230 fcpdl
= lpfc_bg_scsi_adjust_dl(phba
, lpfc_cmd
);
3232 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
3235 * Due to difference in data length between DIF/non-DIF paths,
3236 * we need to set word 4 of IOCB here
3238 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
3239 lpfc_cmd
->cur_iocbq
.iocb_flag
|= LPFC_IO_DIF
;
3243 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3244 "9084 Could not setup all needed BDE's"
3245 "prot_group_type=%d, num_bde=%d\n",
3246 prot_group_type
, num_bde
);
3251 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3252 * @phba: The Hba for which this call is being executed.
3253 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3255 * This routine wraps the actual DMA mapping function pointer from the
3263 lpfc_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3265 return phba
->lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3269 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3271 * @phba: The Hba for which this call is being executed.
3272 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3274 * This routine wraps the actual DMA mapping function pointer from the
3282 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3284 return phba
->lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3288 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3289 * @phba: Pointer to hba context object.
3290 * @vport: Pointer to vport object.
3291 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3292 * @rsp_iocb: Pointer to response iocb object which reported error.
3294 * This function posts an event when there is a SCSI command reporting
3295 * error from the scsi device.
3298 lpfc_send_scsi_error_event(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
3299 struct lpfc_scsi_buf
*lpfc_cmd
, struct lpfc_iocbq
*rsp_iocb
) {
3300 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3301 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3302 uint32_t resp_info
= fcprsp
->rspStatus2
;
3303 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3304 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3305 struct lpfc_fast_path_event
*fast_path_evt
= NULL
;
3306 struct lpfc_nodelist
*pnode
= lpfc_cmd
->rdata
->pnode
;
3307 unsigned long flags
;
3309 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3312 /* If there is queuefull or busy condition send a scsi event */
3313 if ((cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ||
3314 (cmnd
->result
== SAM_STAT_BUSY
)) {
3315 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3318 fast_path_evt
->un
.scsi_evt
.event_type
=
3320 fast_path_evt
->un
.scsi_evt
.subcategory
=
3321 (cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ?
3322 LPFC_EVENT_QFULL
: LPFC_EVENT_DEVBSY
;
3323 fast_path_evt
->un
.scsi_evt
.lun
= cmnd
->device
->lun
;
3324 memcpy(&fast_path_evt
->un
.scsi_evt
.wwpn
,
3325 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3326 memcpy(&fast_path_evt
->un
.scsi_evt
.wwnn
,
3327 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3328 } else if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
&&
3329 ((cmnd
->cmnd
[0] == READ_10
) || (cmnd
->cmnd
[0] == WRITE_10
))) {
3330 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3333 fast_path_evt
->un
.check_cond_evt
.scsi_event
.event_type
=
3335 fast_path_evt
->un
.check_cond_evt
.scsi_event
.subcategory
=
3336 LPFC_EVENT_CHECK_COND
;
3337 fast_path_evt
->un
.check_cond_evt
.scsi_event
.lun
=
3339 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwpn
,
3340 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3341 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwnn
,
3342 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3343 fast_path_evt
->un
.check_cond_evt
.sense_key
=
3344 cmnd
->sense_buffer
[2] & 0xf;
3345 fast_path_evt
->un
.check_cond_evt
.asc
= cmnd
->sense_buffer
[12];
3346 fast_path_evt
->un
.check_cond_evt
.ascq
= cmnd
->sense_buffer
[13];
3347 } else if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3349 ((be32_to_cpu(fcprsp
->rspResId
) != fcpi_parm
) ||
3350 ((scsi_status
== SAM_STAT_GOOD
) &&
3351 !(resp_info
& (RESID_UNDER
| RESID_OVER
))))) {
3353 * If status is good or resid does not match with fcp_param and
3354 * there is valid fcpi_parm, then there is a read_check error
3356 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3359 fast_path_evt
->un
.read_check_error
.header
.event_type
=
3360 FC_REG_FABRIC_EVENT
;
3361 fast_path_evt
->un
.read_check_error
.header
.subcategory
=
3362 LPFC_EVENT_FCPRDCHKERR
;
3363 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwpn
,
3364 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3365 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwnn
,
3366 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3367 fast_path_evt
->un
.read_check_error
.lun
= cmnd
->device
->lun
;
3368 fast_path_evt
->un
.read_check_error
.opcode
= cmnd
->cmnd
[0];
3369 fast_path_evt
->un
.read_check_error
.fcpiparam
=
3374 fast_path_evt
->vport
= vport
;
3375 spin_lock_irqsave(&phba
->hbalock
, flags
);
3376 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
3377 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3378 lpfc_worker_wake_up(phba
);
3383 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3384 * @phba: The HBA for which this call is being executed.
3385 * @psb: The scsi buffer which is going to be un-mapped.
3387 * This routine does DMA un-mapping of scatter gather list of scsi command
3388 * field of @lpfc_cmd for device with SLI-3 interface spec.
3391 lpfc_scsi_unprep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
3394 * There are only two special cases to consider. (1) the scsi command
3395 * requested scatter-gather usage or (2) the scsi command allocated
3396 * a request buffer, but did not request use_sg. There is a third
3397 * case, but it does not require resource deallocation.
3399 if (psb
->seg_cnt
> 0)
3400 scsi_dma_unmap(psb
->pCmd
);
3401 if (psb
->prot_seg_cnt
> 0)
3402 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(psb
->pCmd
),
3403 scsi_prot_sg_count(psb
->pCmd
),
3404 psb
->pCmd
->sc_data_direction
);
3408 * lpfc_handler_fcp_err - FCP response handler
3409 * @vport: The virtual port for which this call is being executed.
3410 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3411 * @rsp_iocb: The response IOCB which contains FCP error.
3413 * This routine is called to process response IOCB with status field
3414 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3415 * based upon SCSI and FCP error.
3418 lpfc_handle_fcp_err(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
3419 struct lpfc_iocbq
*rsp_iocb
)
3421 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3422 struct fcp_cmnd
*fcpcmd
= lpfc_cmd
->fcp_cmnd
;
3423 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3424 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3425 uint32_t resp_info
= fcprsp
->rspStatus2
;
3426 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3428 uint32_t host_status
= DID_OK
;
3429 uint32_t rsplen
= 0;
3430 uint32_t logit
= LOG_FCP
| LOG_FCP_ERROR
;
3434 * If this is a task management command, there is no
3435 * scsi packet associated with this lpfc_cmd. The driver
3438 if (fcpcmd
->fcpCntl2
) {
3443 if (resp_info
& RSP_LEN_VALID
) {
3444 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3445 if (rsplen
!= 0 && rsplen
!= 4 && rsplen
!= 8) {
3446 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3447 "2719 Invalid response length: "
3448 "tgt x%x lun x%x cmnd x%x rsplen x%x\n",
3450 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3452 host_status
= DID_ERROR
;
3455 if (fcprsp
->rspInfo3
!= RSP_NO_FAILURE
) {
3456 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3457 "2757 Protocol failure detected during "
3458 "processing of FCP I/O op: "
3459 "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n",
3461 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3463 host_status
= DID_ERROR
;
3468 if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
) {
3469 uint32_t snslen
= be32_to_cpu(fcprsp
->rspSnsLen
);
3470 if (snslen
> SCSI_SENSE_BUFFERSIZE
)
3471 snslen
= SCSI_SENSE_BUFFERSIZE
;
3473 if (resp_info
& RSP_LEN_VALID
)
3474 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3475 memcpy(cmnd
->sense_buffer
, &fcprsp
->rspInfo0
+ rsplen
, snslen
);
3477 lp
= (uint32_t *)cmnd
->sense_buffer
;
3479 /* special handling for under run conditions */
3480 if (!scsi_status
&& (resp_info
& RESID_UNDER
)) {
3481 /* don't log under runs if fcp set... */
3482 if (vport
->cfg_log_verbose
& LOG_FCP
)
3483 logit
= LOG_FCP_ERROR
;
3484 /* unless operator says so */
3485 if (vport
->cfg_log_verbose
& LOG_FCP_UNDER
)
3486 logit
= LOG_FCP_UNDER
;
3489 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3490 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3491 "Data: x%x x%x x%x x%x x%x\n",
3492 cmnd
->cmnd
[0], scsi_status
,
3493 be32_to_cpu(*lp
), be32_to_cpu(*(lp
+ 3)), resp_info
,
3494 be32_to_cpu(fcprsp
->rspResId
),
3495 be32_to_cpu(fcprsp
->rspSnsLen
),
3496 be32_to_cpu(fcprsp
->rspRspLen
),
3499 scsi_set_resid(cmnd
, 0);
3500 if (resp_info
& RESID_UNDER
) {
3501 scsi_set_resid(cmnd
, be32_to_cpu(fcprsp
->rspResId
));
3503 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_UNDER
,
3504 "9025 FCP Read Underrun, expected %d, "
3505 "residual %d Data: x%x x%x x%x\n",
3506 be32_to_cpu(fcpcmd
->fcpDl
),
3507 scsi_get_resid(cmnd
), fcpi_parm
, cmnd
->cmnd
[0],
3511 * If there is an under run check if under run reported by
3512 * storage array is same as the under run reported by HBA.
3513 * If this is not same, there is a dropped frame.
3515 if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3517 (scsi_get_resid(cmnd
) != fcpi_parm
)) {
3518 lpfc_printf_vlog(vport
, KERN_WARNING
,
3519 LOG_FCP
| LOG_FCP_ERROR
,
3520 "9026 FCP Read Check Error "
3521 "and Underrun Data: x%x x%x x%x x%x\n",
3522 be32_to_cpu(fcpcmd
->fcpDl
),
3523 scsi_get_resid(cmnd
), fcpi_parm
,
3525 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3526 host_status
= DID_ERROR
;
3529 * The cmnd->underflow is the minimum number of bytes that must
3530 * be transferred for this command. Provided a sense condition
3531 * is not present, make sure the actual amount transferred is at
3532 * least the underflow value or fail.
3534 if (!(resp_info
& SNS_LEN_VALID
) &&
3535 (scsi_status
== SAM_STAT_GOOD
) &&
3536 (scsi_bufflen(cmnd
) - scsi_get_resid(cmnd
)
3537 < cmnd
->underflow
)) {
3538 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3539 "9027 FCP command x%x residual "
3540 "underrun converted to error "
3541 "Data: x%x x%x x%x\n",
3542 cmnd
->cmnd
[0], scsi_bufflen(cmnd
),
3543 scsi_get_resid(cmnd
), cmnd
->underflow
);
3544 host_status
= DID_ERROR
;
3546 } else if (resp_info
& RESID_OVER
) {
3547 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3548 "9028 FCP command x%x residual overrun error. "
3549 "Data: x%x x%x\n", cmnd
->cmnd
[0],
3550 scsi_bufflen(cmnd
), scsi_get_resid(cmnd
));
3551 host_status
= DID_ERROR
;
3554 * Check SLI validation that all the transfer was actually done
3555 * (fcpi_parm should be zero).
3557 } else if (fcpi_parm
) {
3558 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
| LOG_FCP_ERROR
,
3559 "9029 FCP Data Transfer Check Error: "
3560 "x%x x%x x%x x%x x%x\n",
3561 be32_to_cpu(fcpcmd
->fcpDl
),
3562 be32_to_cpu(fcprsp
->rspResId
),
3563 fcpi_parm
, cmnd
->cmnd
[0], scsi_status
);
3564 switch (scsi_status
) {
3566 case SAM_STAT_CHECK_CONDITION
:
3567 /* Fabric dropped a data frame. Fail any successful
3568 * command in which we detected dropped frames.
3569 * A status of good or some check conditions could
3570 * be considered a successful command.
3572 host_status
= DID_ERROR
;
3575 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3579 cmnd
->result
= ScsiResult(host_status
, scsi_status
);
3580 lpfc_send_scsi_error_event(vport
->phba
, vport
, lpfc_cmd
, rsp_iocb
);
3584 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3585 * @phba: The Hba for which this call is being executed.
3586 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3587 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3589 * This routine assigns scsi command result by looking into response IOCB
3590 * status field appropriately. This routine handles QUEUE FULL condition as
3591 * well by ramping down device queue depth.
3594 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pIocbIn
,
3595 struct lpfc_iocbq
*pIocbOut
)
3597 struct lpfc_scsi_buf
*lpfc_cmd
=
3598 (struct lpfc_scsi_buf
*) pIocbIn
->context1
;
3599 struct lpfc_vport
*vport
= pIocbIn
->vport
;
3600 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
3601 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
3602 struct scsi_cmnd
*cmd
;
3604 struct scsi_device
*tmp_sdev
;
3606 unsigned long flags
;
3607 struct lpfc_fast_path_event
*fast_path_evt
;
3608 struct Scsi_Host
*shost
;
3609 uint32_t queue_depth
, scsi_id
;
3610 uint32_t logit
= LOG_FCP
;
3612 /* Sanity check on return of outstanding command */
3613 if (!(lpfc_cmd
->pCmd
))
3615 cmd
= lpfc_cmd
->pCmd
;
3616 shost
= cmd
->device
->host
;
3618 lpfc_cmd
->result
= (pIocbOut
->iocb
.un
.ulpWord
[4] & IOERR_PARAM_MASK
);
3619 lpfc_cmd
->status
= pIocbOut
->iocb
.ulpStatus
;
3620 /* pick up SLI4 exhange busy status from HBA */
3621 lpfc_cmd
->exch_busy
= pIocbOut
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
3623 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3624 if (lpfc_cmd
->prot_data_type
) {
3625 struct scsi_dif_tuple
*src
= NULL
;
3627 src
= (struct scsi_dif_tuple
*)lpfc_cmd
->prot_data_segment
;
3629 * Used to restore any changes to protection
3630 * data for error injection.
3632 switch (lpfc_cmd
->prot_data_type
) {
3633 case LPFC_INJERR_REFTAG
:
3635 lpfc_cmd
->prot_data
;
3637 case LPFC_INJERR_APPTAG
:
3639 (uint16_t)lpfc_cmd
->prot_data
;
3641 case LPFC_INJERR_GUARD
:
3643 (uint16_t)lpfc_cmd
->prot_data
;
3649 lpfc_cmd
->prot_data
= 0;
3650 lpfc_cmd
->prot_data_type
= 0;
3651 lpfc_cmd
->prot_data_segment
= NULL
;
3654 if (pnode
&& NLP_CHK_NODE_ACT(pnode
))
3655 atomic_dec(&pnode
->cmd_pending
);
3657 if (lpfc_cmd
->status
) {
3658 if (lpfc_cmd
->status
== IOSTAT_LOCAL_REJECT
&&
3659 (lpfc_cmd
->result
& IOERR_DRVR_MASK
))
3660 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
3661 else if (lpfc_cmd
->status
>= IOSTAT_CNT
)
3662 lpfc_cmd
->status
= IOSTAT_DEFAULT
;
3663 if (lpfc_cmd
->status
== IOSTAT_FCP_RSP_ERROR
&&
3664 !lpfc_cmd
->fcp_rsp
->rspStatus3
&&
3665 (lpfc_cmd
->fcp_rsp
->rspStatus2
& RESID_UNDER
) &&
3666 !(vport
->cfg_log_verbose
& LOG_FCP_UNDER
))
3669 logit
= LOG_FCP
| LOG_FCP_UNDER
;
3670 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3671 "9030 FCP cmd x%x failed <%d/%d> "
3672 "status: x%x result: x%x "
3673 "sid: x%x did: x%x oxid: x%x "
3676 cmd
->device
? cmd
->device
->id
: 0xffff,
3677 cmd
->device
? cmd
->device
->lun
: 0xffff,
3678 lpfc_cmd
->status
, lpfc_cmd
->result
,
3679 vport
->fc_myDID
, pnode
->nlp_DID
,
3680 phba
->sli_rev
== LPFC_SLI_REV4
?
3681 lpfc_cmd
->cur_iocbq
.sli4_xritag
: 0xffff,
3682 pIocbOut
->iocb
.ulpContext
,
3683 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
3685 switch (lpfc_cmd
->status
) {
3686 case IOSTAT_FCP_RSP_ERROR
:
3687 /* Call FCP RSP handler to determine result */
3688 lpfc_handle_fcp_err(vport
, lpfc_cmd
, pIocbOut
);
3690 case IOSTAT_NPORT_BSY
:
3691 case IOSTAT_FABRIC_BSY
:
3692 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
, 0);
3693 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3696 fast_path_evt
->un
.fabric_evt
.event_type
=
3697 FC_REG_FABRIC_EVENT
;
3698 fast_path_evt
->un
.fabric_evt
.subcategory
=
3699 (lpfc_cmd
->status
== IOSTAT_NPORT_BSY
) ?
3700 LPFC_EVENT_PORT_BUSY
: LPFC_EVENT_FABRIC_BUSY
;
3701 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3702 memcpy(&fast_path_evt
->un
.fabric_evt
.wwpn
,
3703 &pnode
->nlp_portname
,
3704 sizeof(struct lpfc_name
));
3705 memcpy(&fast_path_evt
->un
.fabric_evt
.wwnn
,
3706 &pnode
->nlp_nodename
,
3707 sizeof(struct lpfc_name
));
3709 fast_path_evt
->vport
= vport
;
3710 fast_path_evt
->work_evt
.evt
=
3711 LPFC_EVT_FASTPATH_MGMT_EVT
;
3712 spin_lock_irqsave(&phba
->hbalock
, flags
);
3713 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
,
3715 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3716 lpfc_worker_wake_up(phba
);
3718 case IOSTAT_LOCAL_REJECT
:
3719 case IOSTAT_REMOTE_STOP
:
3720 if (lpfc_cmd
->result
== IOERR_ELXSEC_KEY_UNWRAP_ERROR
||
3722 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR
||
3723 lpfc_cmd
->result
== IOERR_ELXSEC_CRYPTO_ERROR
||
3725 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR
) {
3726 cmd
->result
= ScsiResult(DID_NO_CONNECT
, 0);
3729 if (lpfc_cmd
->result
== IOERR_INVALID_RPI
||
3730 lpfc_cmd
->result
== IOERR_NO_RESOURCES
||
3731 lpfc_cmd
->result
== IOERR_ABORT_REQUESTED
||
3732 lpfc_cmd
->result
== IOERR_SLER_CMD_RCV_FAILURE
) {
3733 cmd
->result
= ScsiResult(DID_REQUEUE
, 0);
3736 if ((lpfc_cmd
->result
== IOERR_RX_DMA_FAILED
||
3737 lpfc_cmd
->result
== IOERR_TX_DMA_FAILED
) &&
3738 pIocbOut
->iocb
.unsli3
.sli3_bg
.bgstat
) {
3739 if (scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
3741 * This is a response for a BG enabled
3742 * cmd. Parse BG error
3744 lpfc_parse_bg_err(phba
, lpfc_cmd
,
3748 lpfc_printf_vlog(vport
, KERN_WARNING
,
3750 "9031 non-zero BGSTAT "
3751 "on unprotected cmd\n");
3754 if ((lpfc_cmd
->status
== IOSTAT_REMOTE_STOP
)
3755 && (phba
->sli_rev
== LPFC_SLI_REV4
)
3756 && (pnode
&& NLP_CHK_NODE_ACT(pnode
))) {
3757 /* This IO was aborted by the target, we don't
3758 * know the rxid and because we did not send the
3759 * ABTS we cannot generate and RRQ.
3761 lpfc_set_rrq_active(phba
, pnode
,
3762 lpfc_cmd
->cur_iocbq
.sli4_lxritag
,
3765 /* else: fall through */
3767 cmd
->result
= ScsiResult(DID_ERROR
, 0);
3771 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
)
3772 || (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
3773 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
,
3776 cmd
->result
= ScsiResult(DID_OK
, 0);
3778 if (cmd
->result
|| lpfc_cmd
->fcp_rsp
->rspSnsLen
) {
3779 uint32_t *lp
= (uint32_t *)cmd
->sense_buffer
;
3781 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3782 "0710 Iodone <%d/%d> cmd %p, error "
3783 "x%x SNS x%x x%x Data: x%x x%x\n",
3784 cmd
->device
->id
, cmd
->device
->lun
, cmd
,
3785 cmd
->result
, *lp
, *(lp
+ 3), cmd
->retries
,
3786 scsi_get_resid(cmd
));
3789 lpfc_update_stats(phba
, lpfc_cmd
);
3790 result
= cmd
->result
;
3791 if (vport
->cfg_max_scsicmpl_time
&&
3792 time_after(jiffies
, lpfc_cmd
->start_time
+
3793 msecs_to_jiffies(vport
->cfg_max_scsicmpl_time
))) {
3794 spin_lock_irqsave(shost
->host_lock
, flags
);
3795 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3796 if (pnode
->cmd_qdepth
>
3797 atomic_read(&pnode
->cmd_pending
) &&
3798 (atomic_read(&pnode
->cmd_pending
) >
3799 LPFC_MIN_TGT_QDEPTH
) &&
3800 ((cmd
->cmnd
[0] == READ_10
) ||
3801 (cmd
->cmnd
[0] == WRITE_10
)))
3803 atomic_read(&pnode
->cmd_pending
);
3805 pnode
->last_change_time
= jiffies
;
3807 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3808 } else if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
3809 if ((pnode
->cmd_qdepth
< vport
->cfg_tgt_queue_depth
) &&
3810 time_after(jiffies
, pnode
->last_change_time
+
3811 msecs_to_jiffies(LPFC_TGTQ_INTERVAL
))) {
3812 spin_lock_irqsave(shost
->host_lock
, flags
);
3813 depth
= pnode
->cmd_qdepth
* LPFC_TGTQ_RAMPUP_PCENT
3815 depth
= depth
? depth
: 1;
3816 pnode
->cmd_qdepth
+= depth
;
3817 if (pnode
->cmd_qdepth
> vport
->cfg_tgt_queue_depth
)
3818 pnode
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
3819 pnode
->last_change_time
= jiffies
;
3820 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3824 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
3826 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
3827 queue_depth
= cmd
->device
->queue_depth
;
3828 scsi_id
= cmd
->device
->id
;
3829 cmd
->scsi_done(cmd
);
3831 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
3832 spin_lock_irqsave(&phba
->hbalock
, flags
);
3833 lpfc_cmd
->pCmd
= NULL
;
3834 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3837 * If there is a thread waiting for command completion
3838 * wake up the thread.
3840 spin_lock_irqsave(shost
->host_lock
, flags
);
3841 if (lpfc_cmd
->waitq
)
3842 wake_up(lpfc_cmd
->waitq
);
3843 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3844 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3849 lpfc_rampup_queue_depth(vport
, queue_depth
);
3852 * Check for queue full. If the lun is reporting queue full, then
3853 * back off the lun queue depth to prevent target overloads.
3855 if (result
== SAM_STAT_TASK_SET_FULL
&& pnode
&&
3856 NLP_CHK_NODE_ACT(pnode
)) {
3857 shost_for_each_device(tmp_sdev
, shost
) {
3858 if (tmp_sdev
->id
!= scsi_id
)
3860 depth
= scsi_track_queue_full(tmp_sdev
,
3861 tmp_sdev
->queue_depth
-1);
3864 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3865 "0711 detected queue full - lun queue "
3866 "depth adjusted to %d.\n", depth
);
3867 lpfc_send_sdev_queuedepth_change_event(phba
, vport
,
3874 spin_lock_irqsave(&phba
->hbalock
, flags
);
3875 lpfc_cmd
->pCmd
= NULL
;
3876 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3879 * If there is a thread waiting for command completion
3880 * wake up the thread.
3882 spin_lock_irqsave(shost
->host_lock
, flags
);
3883 if (lpfc_cmd
->waitq
)
3884 wake_up(lpfc_cmd
->waitq
);
3885 spin_unlock_irqrestore(shost
->host_lock
, flags
);
3887 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3891 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
3892 * @data: A pointer to the immediate command data portion of the IOCB.
3893 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
3895 * The routine copies the entire FCP command from @fcp_cmnd to @data while
3896 * byte swapping the data to big endian format for transmission on the wire.
3899 lpfc_fcpcmd_to_iocb(uint8_t *data
, struct fcp_cmnd
*fcp_cmnd
)
3902 for (i
= 0, j
= 0; i
< sizeof(struct fcp_cmnd
);
3903 i
+= sizeof(uint32_t), j
++) {
3904 ((uint32_t *)data
)[j
] = cpu_to_be32(((uint32_t *)fcp_cmnd
)[j
]);
3909 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
3910 * @vport: The virtual port for which this call is being executed.
3911 * @lpfc_cmd: The scsi command which needs to send.
3912 * @pnode: Pointer to lpfc_nodelist.
3914 * This routine initializes fcp_cmnd and iocb data structure from scsi command
3915 * to transfer for device with SLI3 interface spec.
3918 lpfc_scsi_prep_cmnd(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
3919 struct lpfc_nodelist
*pnode
)
3921 struct lpfc_hba
*phba
= vport
->phba
;
3922 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3923 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3924 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3925 struct lpfc_iocbq
*piocbq
= &(lpfc_cmd
->cur_iocbq
);
3926 int datadir
= scsi_cmnd
->sc_data_direction
;
3931 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3934 lpfc_cmd
->fcp_rsp
->rspSnsLen
= 0;
3935 /* clear task management bits */
3936 lpfc_cmd
->fcp_cmnd
->fcpCntl2
= 0;
3938 int_to_scsilun(lpfc_cmd
->pCmd
->device
->lun
,
3939 &lpfc_cmd
->fcp_cmnd
->fcp_lun
);
3941 ptr
= &fcp_cmnd
->fcpCdb
[0];
3942 memcpy(ptr
, scsi_cmnd
->cmnd
, scsi_cmnd
->cmd_len
);
3943 if (scsi_cmnd
->cmd_len
< LPFC_FCP_CDB_LEN
) {
3944 ptr
+= scsi_cmnd
->cmd_len
;
3945 memset(ptr
, 0, (LPFC_FCP_CDB_LEN
- scsi_cmnd
->cmd_len
));
3948 if (scsi_populate_tag_msg(scsi_cmnd
, tag
)) {
3950 case HEAD_OF_QUEUE_TAG
:
3951 fcp_cmnd
->fcpCntl1
= HEAD_OF_Q
;
3953 case ORDERED_QUEUE_TAG
:
3954 fcp_cmnd
->fcpCntl1
= ORDERED_Q
;
3957 fcp_cmnd
->fcpCntl1
= SIMPLE_Q
;
3961 fcp_cmnd
->fcpCntl1
= 0;
3963 sli4
= (phba
->sli_rev
== LPFC_SLI_REV4
);
3966 * There are three possibilities here - use scatter-gather segment, use
3967 * the single mapping, or neither. Start the lpfc command prep by
3968 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3971 if (scsi_sg_count(scsi_cmnd
)) {
3972 if (datadir
== DMA_TO_DEVICE
) {
3973 iocb_cmd
->ulpCommand
= CMD_FCP_IWRITE64_CR
;
3975 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
3977 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
3978 iocb_cmd
->ulpPU
= 0;
3980 fcp_cmnd
->fcpCntl3
= WRITE_DATA
;
3981 phba
->fc4OutputRequests
++;
3983 iocb_cmd
->ulpCommand
= CMD_FCP_IREAD64_CR
;
3984 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
3985 fcp_cmnd
->fcpCntl3
= READ_DATA
;
3986 phba
->fc4InputRequests
++;
3989 iocb_cmd
->ulpCommand
= CMD_FCP_ICMND64_CR
;
3990 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
3991 iocb_cmd
->ulpPU
= 0;
3992 fcp_cmnd
->fcpCntl3
= 0;
3993 phba
->fc4ControlRequests
++;
3995 if (phba
->sli_rev
== 3 &&
3996 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
3997 lpfc_fcpcmd_to_iocb(iocb_cmd
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
3999 * Finish initializing those IOCB fields that are independent
4000 * of the scsi_cmnd request_buffer
4002 piocbq
->iocb
.ulpContext
= pnode
->nlp_rpi
;
4004 piocbq
->iocb
.ulpContext
=
4005 phba
->sli4_hba
.rpi_ids
[pnode
->nlp_rpi
];
4006 if (pnode
->nlp_fcp_info
& NLP_FCP_2_DEVICE
)
4007 piocbq
->iocb
.ulpFCP2Rcvy
= 1;
4009 piocbq
->iocb
.ulpFCP2Rcvy
= 0;
4011 piocbq
->iocb
.ulpClass
= (pnode
->nlp_fcp_info
& 0x0f);
4012 piocbq
->context1
= lpfc_cmd
;
4013 piocbq
->iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
4014 piocbq
->iocb
.ulpTimeout
= lpfc_cmd
->timeout
;
4015 piocbq
->vport
= vport
;
4019 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
4020 * @vport: The virtual port for which this call is being executed.
4021 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4022 * @lun: Logical unit number.
4023 * @task_mgmt_cmd: SCSI task management command.
4025 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4026 * for device with SLI-3 interface spec.
4033 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport
*vport
,
4034 struct lpfc_scsi_buf
*lpfc_cmd
,
4036 uint8_t task_mgmt_cmd
)
4038 struct lpfc_iocbq
*piocbq
;
4040 struct fcp_cmnd
*fcp_cmnd
;
4041 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
4042 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
4044 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) ||
4045 ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
4048 piocbq
= &(lpfc_cmd
->cur_iocbq
);
4049 piocbq
->vport
= vport
;
4051 piocb
= &piocbq
->iocb
;
4053 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4054 /* Clear out any old data in the FCP command area */
4055 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
4056 int_to_scsilun(lun
, &fcp_cmnd
->fcp_lun
);
4057 fcp_cmnd
->fcpCntl2
= task_mgmt_cmd
;
4058 if (vport
->phba
->sli_rev
== 3 &&
4059 !(vport
->phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
4060 lpfc_fcpcmd_to_iocb(piocb
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
4061 piocb
->ulpCommand
= CMD_FCP_ICMND64_CR
;
4062 piocb
->ulpContext
= ndlp
->nlp_rpi
;
4063 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4065 vport
->phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
4067 if (ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) {
4068 piocb
->ulpFCP2Rcvy
= 1;
4070 piocb
->ulpClass
= (ndlp
->nlp_fcp_info
& 0x0f);
4072 /* ulpTimeout is only one byte */
4073 if (lpfc_cmd
->timeout
> 0xff) {
4075 * Do not timeout the command at the firmware level.
4076 * The driver will provide the timeout mechanism.
4078 piocb
->ulpTimeout
= 0;
4080 piocb
->ulpTimeout
= lpfc_cmd
->timeout
;
4082 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
4083 lpfc_sli4_set_rsp_sgl_last(vport
->phba
, lpfc_cmd
);
4089 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4090 * @phba: The hba struct for which this call is being executed.
4091 * @dev_grp: The HBA PCI-Device group number.
4093 * This routine sets up the SCSI interface API function jump table in @phba
4095 * Returns: 0 - success, -ENODEV - failure.
4098 lpfc_scsi_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4101 phba
->lpfc_scsi_unprep_dma_buf
= lpfc_scsi_unprep_dma_buf
;
4102 phba
->lpfc_scsi_prep_cmnd
= lpfc_scsi_prep_cmnd
;
4105 case LPFC_PCI_DEV_LP
:
4106 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s3
;
4107 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s3
;
4108 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s3
;
4109 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s3
;
4110 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s3
;
4112 case LPFC_PCI_DEV_OC
:
4113 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s4
;
4114 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s4
;
4115 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s4
;
4116 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s4
;
4117 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s4
;
4120 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4121 "1418 Invalid HBA PCI-device group: 0x%x\n",
4126 phba
->lpfc_rampdown_queue_depth
= lpfc_rampdown_queue_depth
;
4127 phba
->lpfc_scsi_cmd_iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
4132 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4133 * @phba: The Hba for which this call is being executed.
4134 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4135 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4137 * This routine is IOCB completion routine for device reset and target reset
4138 * routine. This routine release scsi buffer associated with lpfc_cmd.
4141 lpfc_tskmgmt_def_cmpl(struct lpfc_hba
*phba
,
4142 struct lpfc_iocbq
*cmdiocbq
,
4143 struct lpfc_iocbq
*rspiocbq
)
4145 struct lpfc_scsi_buf
*lpfc_cmd
=
4146 (struct lpfc_scsi_buf
*) cmdiocbq
->context1
;
4148 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4153 * lpfc_info - Info entry point of scsi_host_template data structure
4154 * @host: The scsi host for which this call is being executed.
4156 * This routine provides module information about hba.
4159 * Pointer to char - Success.
4162 lpfc_info(struct Scsi_Host
*host
)
4164 struct lpfc_vport
*vport
= (struct lpfc_vport
*) host
->hostdata
;
4165 struct lpfc_hba
*phba
= vport
->phba
;
4166 int len
, link_speed
= 0;
4167 static char lpfcinfobuf
[384];
4169 memset(lpfcinfobuf
,0,384);
4170 if (phba
&& phba
->pcidev
){
4171 strncpy(lpfcinfobuf
, phba
->ModelDesc
, 256);
4172 len
= strlen(lpfcinfobuf
);
4173 snprintf(lpfcinfobuf
+ len
,
4175 " on PCI bus %02x device %02x irq %d",
4176 phba
->pcidev
->bus
->number
,
4177 phba
->pcidev
->devfn
,
4179 len
= strlen(lpfcinfobuf
);
4180 if (phba
->Port
[0]) {
4181 snprintf(lpfcinfobuf
+ len
,
4186 len
= strlen(lpfcinfobuf
);
4187 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
4188 link_speed
= lpfc_sli_port_speed_get(phba
);
4190 if (phba
->sli4_hba
.link_state
.logical_speed
)
4192 phba
->sli4_hba
.link_state
.logical_speed
;
4194 link_speed
= phba
->sli4_hba
.link_state
.speed
;
4196 if (link_speed
!= 0)
4197 snprintf(lpfcinfobuf
+ len
, 384-len
,
4198 " Logical Link Speed: %d Mbps", link_speed
);
4204 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4205 * @phba: The Hba for which this call is being executed.
4207 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4208 * The default value of cfg_poll_tmo is 10 milliseconds.
4210 static __inline__
void lpfc_poll_rearm_timer(struct lpfc_hba
* phba
)
4212 unsigned long poll_tmo_expires
=
4213 (jiffies
+ msecs_to_jiffies(phba
->cfg_poll_tmo
));
4215 if (phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
)
4216 mod_timer(&phba
->fcp_poll_timer
,
4221 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4222 * @phba: The Hba for which this call is being executed.
4224 * This routine starts the fcp_poll_timer of @phba.
4226 void lpfc_poll_start_timer(struct lpfc_hba
* phba
)
4228 lpfc_poll_rearm_timer(phba
);
4232 * lpfc_poll_timeout - Restart polling timer
4233 * @ptr: Map to lpfc_hba data structure pointer.
4235 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4236 * and FCP Ring interrupt is disable.
4239 void lpfc_poll_timeout(unsigned long ptr
)
4241 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4243 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4244 lpfc_sli_handle_fast_ring_event(phba
,
4245 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4247 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4248 lpfc_poll_rearm_timer(phba
);
4253 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4254 * @cmnd: Pointer to scsi_cmnd data structure.
4255 * @done: Pointer to done routine.
4257 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4258 * This routine prepares an IOCB from scsi command and provides to firmware.
4259 * The @done callback is invoked after driver finished processing the command.
4263 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4266 lpfc_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*cmnd
)
4268 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4269 struct lpfc_hba
*phba
= vport
->phba
;
4270 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4271 struct lpfc_nodelist
*ndlp
;
4272 struct lpfc_scsi_buf
*lpfc_cmd
;
4273 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
4276 err
= fc_remote_port_chkready(rport
);
4279 goto out_fail_command
;
4281 ndlp
= rdata
->pnode
;
4283 if ((scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) &&
4284 (!(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))) {
4286 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4287 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4288 " op:%02x str=%s without registering for"
4289 " BlockGuard - Rejecting command\n",
4290 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
4291 dif_op_str
[scsi_get_prot_op(cmnd
)]);
4292 goto out_fail_command
;
4296 * Catch race where our node has transitioned, but the
4297 * transport is still transitioning.
4299 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
4301 if (atomic_read(&ndlp
->cmd_pending
) >= ndlp
->cmd_qdepth
)
4304 lpfc_cmd
= lpfc_get_scsi_buf(phba
, ndlp
);
4305 if (lpfc_cmd
== NULL
) {
4306 lpfc_rampdown_queue_depth(phba
);
4308 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4309 "0707 driver's buffer pool is empty, "
4315 * Store the midlayer's command structure for the completion phase
4316 * and complete the command initialization.
4318 lpfc_cmd
->pCmd
= cmnd
;
4319 lpfc_cmd
->rdata
= rdata
;
4320 lpfc_cmd
->timeout
= 0;
4321 lpfc_cmd
->start_time
= jiffies
;
4322 cmnd
->host_scribble
= (unsigned char *)lpfc_cmd
;
4324 if (scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) {
4325 if (vport
->phba
->cfg_enable_bg
) {
4326 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_BG
,
4327 "9033 BLKGRD: rcvd %s cmd:x%x "
4328 "sector x%llx cnt %u pt %x\n",
4329 dif_op_str
[scsi_get_prot_op(cmnd
)],
4331 (unsigned long long)scsi_get_lba(cmnd
),
4332 blk_rq_sectors(cmnd
->request
),
4333 (cmnd
->cmnd
[1]>>5));
4335 err
= lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4337 if (vport
->phba
->cfg_enable_bg
) {
4338 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_BG
,
4339 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
4340 "x%x sector x%llx cnt %u pt %x\n",
4342 (unsigned long long)scsi_get_lba(cmnd
),
4343 blk_rq_sectors(cmnd
->request
),
4344 (cmnd
->cmnd
[1]>>5));
4346 err
= lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4350 goto out_host_busy_free_buf
;
4352 lpfc_scsi_prep_cmnd(vport
, lpfc_cmd
, ndlp
);
4354 atomic_inc(&ndlp
->cmd_pending
);
4355 err
= lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
,
4356 &lpfc_cmd
->cur_iocbq
, SLI_IOCB_RET_IOCB
);
4358 atomic_dec(&ndlp
->cmd_pending
);
4359 goto out_host_busy_free_buf
;
4361 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4362 lpfc_sli_handle_fast_ring_event(phba
,
4363 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4365 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4366 lpfc_poll_rearm_timer(phba
);
4371 out_host_busy_free_buf
:
4372 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
4373 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4375 return SCSI_MLQUEUE_HOST_BUSY
;
4378 return SCSI_MLQUEUE_TARGET_BUSY
;
4381 cmnd
->scsi_done(cmnd
);
4387 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4388 * @cmnd: Pointer to scsi_cmnd data structure.
4390 * This routine aborts @cmnd pending in base driver.
4397 lpfc_abort_handler(struct scsi_cmnd
*cmnd
)
4399 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4400 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4401 struct lpfc_hba
*phba
= vport
->phba
;
4402 struct lpfc_iocbq
*iocb
;
4403 struct lpfc_iocbq
*abtsiocb
;
4404 struct lpfc_scsi_buf
*lpfc_cmd
;
4406 int ret
= SUCCESS
, status
= 0;
4407 unsigned long flags
;
4408 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq
);
4410 status
= fc_block_scsi_eh(cmnd
);
4411 if (status
!= 0 && status
!= SUCCESS
)
4414 spin_lock_irqsave(&phba
->hbalock
, flags
);
4415 /* driver queued commands are in process of being flushed */
4416 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
4417 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4418 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4419 "3168 SCSI Layer abort requested I/O has been "
4420 "flushed by LLD.\n");
4424 lpfc_cmd
= (struct lpfc_scsi_buf
*)cmnd
->host_scribble
;
4425 if (!lpfc_cmd
|| !lpfc_cmd
->pCmd
) {
4426 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4427 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4428 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4429 "x%x ID %d LUN %d\n",
4430 SUCCESS
, cmnd
->device
->id
, cmnd
->device
->lun
);
4434 iocb
= &lpfc_cmd
->cur_iocbq
;
4435 /* the command is in process of being cancelled */
4436 if (!(iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
)) {
4437 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4438 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4439 "3169 SCSI Layer abort requested I/O has been "
4440 "cancelled by LLD.\n");
4444 * If pCmd field of the corresponding lpfc_scsi_buf structure
4445 * points to a different SCSI command, then the driver has
4446 * already completed this command, but the midlayer did not
4447 * see the completion before the eh fired. Just return SUCCESS.
4449 if (lpfc_cmd
->pCmd
!= cmnd
) {
4450 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4451 "3170 SCSI Layer abort requested I/O has been "
4452 "completed by LLD.\n");
4456 BUG_ON(iocb
->context1
!= lpfc_cmd
);
4458 abtsiocb
= __lpfc_sli_get_iocbq(phba
);
4459 if (abtsiocb
== NULL
) {
4465 * The scsi command can not be in txq and it is in flight because the
4466 * pCmd is still pointig at the SCSI command we have to abort. There
4467 * is no need to search the txcmplq. Just send an abort to the FW.
4471 icmd
= &abtsiocb
->iocb
;
4472 icmd
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
4473 icmd
->un
.acxri
.abortContextTag
= cmd
->ulpContext
;
4474 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4475 icmd
->un
.acxri
.abortIoTag
= iocb
->sli4_xritag
;
4477 icmd
->un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
4480 icmd
->ulpClass
= cmd
->ulpClass
;
4482 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4483 abtsiocb
->fcp_wqidx
= iocb
->fcp_wqidx
;
4484 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
4486 if (lpfc_is_link_up(phba
))
4487 icmd
->ulpCommand
= CMD_ABORT_XRI_CN
;
4489 icmd
->ulpCommand
= CMD_CLOSE_XRI_CN
;
4491 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
4492 abtsiocb
->vport
= vport
;
4493 /* no longer need the lock after this point */
4494 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4496 if (lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
, abtsiocb
, 0) ==
4498 lpfc_sli_release_iocbq(phba
, abtsiocb
);
4503 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4504 lpfc_sli_handle_fast_ring_event(phba
,
4505 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4507 lpfc_cmd
->waitq
= &waitq
;
4508 /* Wait for abort to complete */
4509 wait_event_timeout(waitq
,
4510 (lpfc_cmd
->pCmd
!= cmnd
),
4511 (2*vport
->cfg_devloss_tmo
*HZ
));
4512 lpfc_cmd
->waitq
= NULL
;
4514 if (lpfc_cmd
->pCmd
== cmnd
) {
4516 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4517 "0748 abort handler timed out waiting "
4518 "for abortng I/O (xri:x%x) to complete: "
4519 "ret %#x, ID %d, LUN %d\n",
4520 iocb
->sli4_xritag
, ret
,
4521 cmnd
->device
->id
, cmnd
->device
->lun
);
4526 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4528 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4529 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4530 "LUN %d\n", ret
, cmnd
->device
->id
,
4536 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd
)
4538 switch (task_mgmt_cmd
) {
4539 case FCP_ABORT_TASK_SET
:
4540 return "ABORT_TASK_SET";
4541 case FCP_CLEAR_TASK_SET
:
4542 return "FCP_CLEAR_TASK_SET";
4544 return "FCP_BUS_RESET";
4546 return "FCP_LUN_RESET";
4547 case FCP_TARGET_RESET
:
4548 return "FCP_TARGET_RESET";
4550 return "FCP_CLEAR_ACA";
4551 case FCP_TERMINATE_TASK
:
4552 return "FCP_TERMINATE_TASK";
4559 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4560 * @vport: The virtual port for which this call is being executed.
4561 * @rdata: Pointer to remote port local data
4562 * @tgt_id: Target ID of remote device.
4563 * @lun_id: Lun number for the TMF
4564 * @task_mgmt_cmd: type of TMF to send
4566 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4574 lpfc_send_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_rport_data
*rdata
,
4575 unsigned tgt_id
, unsigned int lun_id
,
4576 uint8_t task_mgmt_cmd
)
4578 struct lpfc_hba
*phba
= vport
->phba
;
4579 struct lpfc_scsi_buf
*lpfc_cmd
;
4580 struct lpfc_iocbq
*iocbq
;
4581 struct lpfc_iocbq
*iocbqrsp
;
4582 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
4586 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
4589 lpfc_cmd
= lpfc_get_scsi_buf(phba
, rdata
->pnode
);
4590 if (lpfc_cmd
== NULL
)
4592 lpfc_cmd
->timeout
= 60;
4593 lpfc_cmd
->rdata
= rdata
;
4595 status
= lpfc_scsi_prep_task_mgmt_cmd(vport
, lpfc_cmd
, lun_id
,
4598 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4602 iocbq
= &lpfc_cmd
->cur_iocbq
;
4603 iocbqrsp
= lpfc_sli_get_iocbq(phba
);
4604 if (iocbqrsp
== NULL
) {
4605 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4609 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4610 "0702 Issue %s to TGT %d LUN %d "
4611 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
4612 lpfc_taskmgmt_name(task_mgmt_cmd
), tgt_id
, lun_id
,
4613 pnode
->nlp_rpi
, pnode
->nlp_flag
, iocbq
->sli4_xritag
,
4616 status
= lpfc_sli_issue_iocb_wait(phba
, LPFC_FCP_RING
,
4617 iocbq
, iocbqrsp
, lpfc_cmd
->timeout
);
4618 if (status
!= IOCB_SUCCESS
) {
4619 if (status
== IOCB_TIMEDOUT
) {
4620 iocbq
->iocb_cmpl
= lpfc_tskmgmt_def_cmpl
;
4621 ret
= TIMEOUT_ERROR
;
4624 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
4625 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4626 "0727 TMF %s to TGT %d LUN %d failed (%d, %d) "
4628 lpfc_taskmgmt_name(task_mgmt_cmd
),
4629 tgt_id
, lun_id
, iocbqrsp
->iocb
.ulpStatus
,
4630 iocbqrsp
->iocb
.un
.ulpWord
[4],
4632 } else if (status
== IOCB_BUSY
)
4637 lpfc_sli_release_iocbq(phba
, iocbqrsp
);
4639 if (ret
!= TIMEOUT_ERROR
)
4640 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4646 * lpfc_chk_tgt_mapped -
4647 * @vport: The virtual port to check on
4648 * @cmnd: Pointer to scsi_cmnd data structure.
4650 * This routine delays until the scsi target (aka rport) for the
4651 * command exists (is present and logged in) or we declare it non-existent.
4658 lpfc_chk_tgt_mapped(struct lpfc_vport
*vport
, struct scsi_cmnd
*cmnd
)
4660 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4661 struct lpfc_nodelist
*pnode
;
4662 unsigned long later
;
4665 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4666 "0797 Tgt Map rport failure: rdata x%p\n", rdata
);
4669 pnode
= rdata
->pnode
;
4671 * If target is not in a MAPPED state, delay until
4672 * target is rediscovered or devloss timeout expires.
4674 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
4675 while (time_after(later
, jiffies
)) {
4676 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
4678 if (pnode
->nlp_state
== NLP_STE_MAPPED_NODE
)
4680 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
4681 rdata
= cmnd
->device
->hostdata
;
4684 pnode
= rdata
->pnode
;
4686 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
) ||
4687 (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4693 * lpfc_reset_flush_io_context -
4694 * @vport: The virtual port (scsi_host) for the flush context
4695 * @tgt_id: If aborting by Target contect - specifies the target id
4696 * @lun_id: If aborting by Lun context - specifies the lun id
4697 * @context: specifies the context level to flush at.
4699 * After a reset condition via TMF, we need to flush orphaned i/o
4700 * contexts from the adapter. This routine aborts any contexts
4701 * outstanding, then waits for their completions. The wait is
4702 * bounded by devloss_tmo though.
4709 lpfc_reset_flush_io_context(struct lpfc_vport
*vport
, uint16_t tgt_id
,
4710 uint64_t lun_id
, lpfc_ctx_cmd context
)
4712 struct lpfc_hba
*phba
= vport
->phba
;
4713 unsigned long later
;
4716 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
4718 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
4719 tgt_id
, lun_id
, context
);
4720 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
4721 while (time_after(later
, jiffies
) && cnt
) {
4722 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
4723 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
4726 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4727 "0724 I/O flush failure for context %s : cnt x%x\n",
4728 ((context
== LPFC_CTX_LUN
) ? "LUN" :
4729 ((context
== LPFC_CTX_TGT
) ? "TGT" :
4730 ((context
== LPFC_CTX_HOST
) ? "HOST" : "Unknown"))),
4738 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
4739 * @cmnd: Pointer to scsi_cmnd data structure.
4741 * This routine does a device reset by sending a LUN_RESET task management
4749 lpfc_device_reset_handler(struct scsi_cmnd
*cmnd
)
4751 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4752 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4753 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4754 struct lpfc_nodelist
*pnode
;
4755 unsigned tgt_id
= cmnd
->device
->id
;
4756 unsigned int lun_id
= cmnd
->device
->lun
;
4757 struct lpfc_scsi_event_header scsi_event
;
4758 int status
, ret
= SUCCESS
;
4761 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4762 "0798 Device Reset rport failure: rdata x%p\n", rdata
);
4765 pnode
= rdata
->pnode
;
4766 status
= fc_block_scsi_eh(cmnd
);
4767 if (status
!= 0 && status
!= SUCCESS
)
4770 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
4771 if (status
== FAILED
) {
4772 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4773 "0721 Device Reset rport failure: rdata x%p\n", rdata
);
4777 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4778 scsi_event
.subcategory
= LPFC_EVENT_LUNRESET
;
4779 scsi_event
.lun
= lun_id
;
4780 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
4781 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
4783 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4784 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4786 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
4789 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4790 "0713 SCSI layer issued Device Reset (%d, %d) "
4791 "return x%x\n", tgt_id
, lun_id
, status
);
4794 * We have to clean up i/o as : they may be orphaned by the TMF;
4795 * or if the TMF failed, they may be in an indeterminate state.
4797 * We will report success if all the i/o aborts successfully.
4799 ret
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
4805 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
4806 * @cmnd: Pointer to scsi_cmnd data structure.
4808 * This routine does a target reset by sending a TARGET_RESET task management
4816 lpfc_target_reset_handler(struct scsi_cmnd
*cmnd
)
4818 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4819 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4820 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
4821 struct lpfc_nodelist
*pnode
;
4822 unsigned tgt_id
= cmnd
->device
->id
;
4823 unsigned int lun_id
= cmnd
->device
->lun
;
4824 struct lpfc_scsi_event_header scsi_event
;
4825 int status
, ret
= SUCCESS
;
4828 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4829 "0799 Target Reset rport failure: rdata x%p\n", rdata
);
4832 pnode
= rdata
->pnode
;
4833 status
= fc_block_scsi_eh(cmnd
);
4834 if (status
!= 0 && status
!= SUCCESS
)
4837 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
4838 if (status
== FAILED
) {
4839 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4840 "0722 Target Reset rport failure: rdata x%p\n", rdata
);
4844 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4845 scsi_event
.subcategory
= LPFC_EVENT_TGTRESET
;
4847 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
4848 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
4850 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4851 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4853 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
4856 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4857 "0723 SCSI layer issued Target Reset (%d, %d) "
4858 "return x%x\n", tgt_id
, lun_id
, status
);
4861 * We have to clean up i/o as : they may be orphaned by the TMF;
4862 * or if the TMF failed, they may be in an indeterminate state.
4864 * We will report success if all the i/o aborts successfully.
4866 ret
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
4872 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
4873 * @cmnd: Pointer to scsi_cmnd data structure.
4875 * This routine does target reset to all targets on @cmnd->device->host.
4876 * This emulates Parallel SCSI Bus Reset Semantics.
4883 lpfc_bus_reset_handler(struct scsi_cmnd
*cmnd
)
4885 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4886 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4887 struct lpfc_nodelist
*ndlp
= NULL
;
4888 struct lpfc_scsi_event_header scsi_event
;
4890 int ret
= SUCCESS
, status
, i
;
4892 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
4893 scsi_event
.subcategory
= LPFC_EVENT_BUSRESET
;
4895 memcpy(scsi_event
.wwpn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4896 memcpy(scsi_event
.wwnn
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4898 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4899 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
4901 status
= fc_block_scsi_eh(cmnd
);
4902 if (status
!= 0 && status
!= SUCCESS
)
4906 * Since the driver manages a single bus device, reset all
4907 * targets known to the driver. Should any target reset
4908 * fail, this routine returns failure to the midlayer.
4910 for (i
= 0; i
< LPFC_MAX_TARGET
; i
++) {
4911 /* Search for mapped node by target ID */
4913 spin_lock_irq(shost
->host_lock
);
4914 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4915 if (!NLP_CHK_NODE_ACT(ndlp
))
4917 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
4918 ndlp
->nlp_sid
== i
&&
4924 spin_unlock_irq(shost
->host_lock
);
4928 status
= lpfc_send_taskmgmt(vport
, ndlp
->rport
->dd_data
,
4929 i
, 0, FCP_TARGET_RESET
);
4931 if (status
!= SUCCESS
) {
4932 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4933 "0700 Bus Reset on target %d failed\n",
4939 * We have to clean up i/o as : they may be orphaned by the TMFs
4940 * above; or if any of the TMFs failed, they may be in an
4941 * indeterminate state.
4942 * We will report success if all the i/o aborts successfully.
4945 status
= lpfc_reset_flush_io_context(vport
, 0, 0, LPFC_CTX_HOST
);
4946 if (status
!= SUCCESS
)
4949 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4950 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret
);
4955 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
4956 * @cmnd: Pointer to scsi_cmnd data structure.
4958 * This routine does host reset to the adaptor port. It brings the HBA
4959 * offline, performs a board restart, and then brings the board back online.
4960 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
4961 * reject all outstanding SCSI commands to the host and error returned
4962 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
4963 * of error handling, it will only return error if resetting of the adapter
4964 * is not successful; in all other cases, will return success.
4971 lpfc_host_reset_handler(struct scsi_cmnd
*cmnd
)
4973 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4974 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4975 struct lpfc_hba
*phba
= vport
->phba
;
4976 int rc
, ret
= SUCCESS
;
4978 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
4980 rc
= lpfc_sli_brdrestart(phba
);
4984 lpfc_unblock_mgmt_io(phba
);
4986 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
4987 "3172 SCSI layer issued Host Reset Data: x%x\n", ret
);
4992 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
4993 * @sdev: Pointer to scsi_device.
4995 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
4996 * globally available list of scsi buffers. This routine also makes sure scsi
4997 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
4998 * of scsi buffer exists for the lifetime of the driver.
5005 lpfc_slave_alloc(struct scsi_device
*sdev
)
5007 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5008 struct lpfc_hba
*phba
= vport
->phba
;
5009 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
5011 uint32_t num_to_alloc
= 0;
5012 int num_allocated
= 0;
5015 if (!rport
|| fc_remote_port_chkready(rport
))
5018 sdev
->hostdata
= rport
->dd_data
;
5019 sdev_cnt
= atomic_inc_return(&phba
->sdev_cnt
);
5022 * Populate the cmds_per_lun count scsi_bufs into this host's globally
5023 * available list of scsi buffers. Don't allocate more than the
5024 * HBA limit conveyed to the midlayer via the host structure. The
5025 * formula accounts for the lun_queue_depth + error handlers + 1
5026 * extra. This list of scsi bufs exists for the lifetime of the driver.
5028 total
= phba
->total_scsi_bufs
;
5029 num_to_alloc
= vport
->cfg_lun_queue_depth
+ 2;
5031 /* If allocated buffers are enough do nothing */
5032 if ((sdev_cnt
* (vport
->cfg_lun_queue_depth
+ 2)) < total
)
5035 /* Allow some exchanges to be available always to complete discovery */
5036 if (total
>= phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
5037 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5038 "0704 At limitation of %d preallocated "
5039 "command buffers\n", total
);
5041 /* Allow some exchanges to be available always to complete discovery */
5042 } else if (total
+ num_to_alloc
>
5043 phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
5044 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5045 "0705 Allocation request of %d "
5046 "command buffers will exceed max of %d. "
5047 "Reducing allocation request to %d.\n",
5048 num_to_alloc
, phba
->cfg_hba_queue_depth
,
5049 (phba
->cfg_hba_queue_depth
- total
));
5050 num_to_alloc
= phba
->cfg_hba_queue_depth
- total
;
5052 num_allocated
= lpfc_new_scsi_buf(vport
, num_to_alloc
);
5053 if (num_to_alloc
!= num_allocated
) {
5054 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5055 "0708 Allocation request of %d "
5056 "command buffers did not succeed. "
5057 "Allocated %d buffers.\n",
5058 num_to_alloc
, num_allocated
);
5060 if (num_allocated
> 0)
5061 phba
->total_scsi_bufs
+= num_allocated
;
5066 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5067 * @sdev: Pointer to scsi_device.
5069 * This routine configures following items
5070 * - Tag command queuing support for @sdev if supported.
5071 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5077 lpfc_slave_configure(struct scsi_device
*sdev
)
5079 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5080 struct lpfc_hba
*phba
= vport
->phba
;
5082 if (sdev
->tagged_supported
)
5083 scsi_activate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
5085 scsi_deactivate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
5087 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
5088 lpfc_sli_handle_fast_ring_event(phba
,
5089 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
5090 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
5091 lpfc_poll_rearm_timer(phba
);
5098 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5099 * @sdev: Pointer to scsi_device.
5101 * This routine sets @sdev hostatdata filed to null.
5104 lpfc_slave_destroy(struct scsi_device
*sdev
)
5106 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5107 struct lpfc_hba
*phba
= vport
->phba
;
5108 atomic_dec(&phba
->sdev_cnt
);
5109 sdev
->hostdata
= NULL
;
5114 struct scsi_host_template lpfc_template
= {
5115 .module
= THIS_MODULE
,
5116 .name
= LPFC_DRIVER_NAME
,
5118 .queuecommand
= lpfc_queuecommand
,
5119 .eh_abort_handler
= lpfc_abort_handler
,
5120 .eh_device_reset_handler
= lpfc_device_reset_handler
,
5121 .eh_target_reset_handler
= lpfc_target_reset_handler
,
5122 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
5123 .eh_host_reset_handler
= lpfc_host_reset_handler
,
5124 .slave_alloc
= lpfc_slave_alloc
,
5125 .slave_configure
= lpfc_slave_configure
,
5126 .slave_destroy
= lpfc_slave_destroy
,
5127 .scan_finished
= lpfc_scan_finished
,
5129 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
5130 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
5131 .use_clustering
= ENABLE_CLUSTERING
,
5132 .shost_attrs
= lpfc_hba_attrs
,
5133 .max_sectors
= 0xFFFF,
5134 .vendor_id
= LPFC_NL_VENDOR_ID
,
5135 .change_queue_depth
= lpfc_change_queue_depth
,
5138 struct scsi_host_template lpfc_vport_template
= {
5139 .module
= THIS_MODULE
,
5140 .name
= LPFC_DRIVER_NAME
,
5142 .queuecommand
= lpfc_queuecommand
,
5143 .eh_abort_handler
= lpfc_abort_handler
,
5144 .eh_device_reset_handler
= lpfc_device_reset_handler
,
5145 .eh_target_reset_handler
= lpfc_target_reset_handler
,
5146 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
5147 .slave_alloc
= lpfc_slave_alloc
,
5148 .slave_configure
= lpfc_slave_configure
,
5149 .slave_destroy
= lpfc_slave_destroy
,
5150 .scan_finished
= lpfc_scan_finished
,
5152 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
5153 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
5154 .use_clustering
= ENABLE_CLUSTERING
,
5155 .shost_attrs
= lpfc_vport_attrs
,
5156 .max_sectors
= 0xFFFF,
5157 .change_queue_depth
= lpfc_change_queue_depth
,