1 /* bnx2fc_io.c: QLogic Linux FCoE offload driver.
2 * IO manager and SCSI IO processing.
4 * Copyright (c) 2008-2013 Broadcom Corporation
5 * Copyright (c) 2014-2015 QLogic Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
11 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
16 #define RESERVE_FREE_LIST_INDEX num_possible_cpus()
18 static int bnx2fc_split_bd(struct bnx2fc_cmd
*io_req
, u64 addr
, int sg_len
,
20 static int bnx2fc_map_sg(struct bnx2fc_cmd
*io_req
);
21 static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd
*io_req
);
22 static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd
*io_req
);
23 static void bnx2fc_free_mp_resc(struct bnx2fc_cmd
*io_req
);
24 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd
*io_req
,
25 struct fcoe_fcp_rsp_payload
*fcp_rsp
,
28 void bnx2fc_cmd_timer_set(struct bnx2fc_cmd
*io_req
,
29 unsigned int timer_msec
)
31 struct bnx2fc_interface
*interface
= io_req
->port
->priv
;
33 if (queue_delayed_work(interface
->timer_work_queue
,
34 &io_req
->timeout_work
,
35 msecs_to_jiffies(timer_msec
)))
36 kref_get(&io_req
->refcount
);
39 static void bnx2fc_cmd_timeout(struct work_struct
*work
)
41 struct bnx2fc_cmd
*io_req
= container_of(work
, struct bnx2fc_cmd
,
43 u8 cmd_type
= io_req
->cmd_type
;
44 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
47 BNX2FC_IO_DBG(io_req
, "cmd_timeout, cmd_type = %d,"
48 "req_flags = %lx\n", cmd_type
, io_req
->req_flags
);
50 spin_lock_bh(&tgt
->tgt_lock
);
51 if (test_and_clear_bit(BNX2FC_FLAG_ISSUE_RRQ
, &io_req
->req_flags
)) {
52 clear_bit(BNX2FC_FLAG_RETIRE_OXID
, &io_req
->req_flags
);
54 * ideally we should hold the io_req until RRQ complets,
55 * and release io_req from timeout hold.
57 spin_unlock_bh(&tgt
->tgt_lock
);
58 bnx2fc_send_rrq(io_req
);
61 if (test_and_clear_bit(BNX2FC_FLAG_RETIRE_OXID
, &io_req
->req_flags
)) {
62 BNX2FC_IO_DBG(io_req
, "IO ready for reuse now\n");
68 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
69 &io_req
->req_flags
)) {
70 /* Handle eh_abort timeout */
71 BNX2FC_IO_DBG(io_req
, "eh_abort timed out\n");
72 complete(&io_req
->tm_done
);
73 } else if (test_bit(BNX2FC_FLAG_ISSUE_ABTS
,
74 &io_req
->req_flags
)) {
75 /* Handle internally generated ABTS timeout */
76 BNX2FC_IO_DBG(io_req
, "ABTS timed out refcnt = %d\n",
77 io_req
->refcount
.refcount
.counter
);
78 if (!(test_and_set_bit(BNX2FC_FLAG_ABTS_DONE
,
79 &io_req
->req_flags
))) {
81 * Cleanup and return original command to
84 bnx2fc_initiate_cleanup(io_req
);
85 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
86 spin_unlock_bh(&tgt
->tgt_lock
);
91 /* Hanlde IO timeout */
92 BNX2FC_IO_DBG(io_req
, "IO timed out. issue ABTS\n");
93 if (test_and_set_bit(BNX2FC_FLAG_IO_COMPL
,
94 &io_req
->req_flags
)) {
95 BNX2FC_IO_DBG(io_req
, "IO completed before "
100 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS
,
101 &io_req
->req_flags
)) {
102 rc
= bnx2fc_initiate_abts(io_req
);
106 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
107 spin_unlock_bh(&tgt
->tgt_lock
);
111 BNX2FC_IO_DBG(io_req
, "IO already in "
112 "ABTS processing\n");
118 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS
, &io_req
->req_flags
)) {
119 BNX2FC_IO_DBG(io_req
, "ABTS for ELS timed out\n");
121 if (!test_and_set_bit(BNX2FC_FLAG_ABTS_DONE
,
122 &io_req
->req_flags
)) {
123 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
124 spin_unlock_bh(&tgt
->tgt_lock
);
130 * Handle ELS timeout.
131 * tgt_lock is used to sync compl path and timeout
132 * path. If els compl path is processing this IO, we
133 * have nothing to do here, just release the timer hold
135 BNX2FC_IO_DBG(io_req
, "ELS timed out\n");
136 if (test_and_set_bit(BNX2FC_FLAG_ELS_DONE
,
140 /* Indicate the cb_func that this ELS is timed out */
141 set_bit(BNX2FC_FLAG_ELS_TIMEOUT
, &io_req
->req_flags
);
143 if ((io_req
->cb_func
) && (io_req
->cb_arg
)) {
144 io_req
->cb_func(io_req
->cb_arg
);
145 io_req
->cb_arg
= NULL
;
150 printk(KERN_ERR PFX
"cmd_timeout: invalid cmd_type %d\n",
156 /* release the cmd that was held when timer was set */
157 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
158 spin_unlock_bh(&tgt
->tgt_lock
);
161 static void bnx2fc_scsi_done(struct bnx2fc_cmd
*io_req
, int err_code
)
163 /* Called with host lock held */
164 struct scsi_cmnd
*sc_cmd
= io_req
->sc_cmd
;
167 * active_cmd_queue may have other command types as well,
168 * and during flush operation, we want to error back only
171 if (io_req
->cmd_type
!= BNX2FC_SCSI_CMD
)
174 BNX2FC_IO_DBG(io_req
, "scsi_done. err_code = 0x%x\n", err_code
);
175 if (test_bit(BNX2FC_FLAG_CMD_LOST
, &io_req
->req_flags
)) {
176 /* Do not call scsi done for this IO */
180 bnx2fc_unmap_sg_list(io_req
);
181 io_req
->sc_cmd
= NULL
;
183 printk(KERN_ERR PFX
"scsi_done - sc_cmd NULL. "
184 "IO(0x%x) already cleaned up\n",
188 sc_cmd
->result
= err_code
<< 16;
190 BNX2FC_IO_DBG(io_req
, "sc=%p, result=0x%x, retries=%d, allowed=%d\n",
191 sc_cmd
, host_byte(sc_cmd
->result
), sc_cmd
->retries
,
193 scsi_set_resid(sc_cmd
, scsi_bufflen(sc_cmd
));
194 sc_cmd
->SCp
.ptr
= NULL
;
195 sc_cmd
->scsi_done(sc_cmd
);
198 struct bnx2fc_cmd_mgr
*bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba
*hba
)
200 struct bnx2fc_cmd_mgr
*cmgr
;
201 struct io_bdt
*bdt_info
;
202 struct bnx2fc_cmd
*io_req
;
207 int num_ios
, num_pri_ios
;
209 int arr_sz
= num_possible_cpus() + 1;
210 u16 min_xid
= BNX2FC_MIN_XID
;
211 u16 max_xid
= hba
->max_xid
;
213 if (max_xid
<= min_xid
|| max_xid
== FC_XID_UNKNOWN
) {
214 printk(KERN_ERR PFX
"cmd_mgr_alloc: Invalid min_xid 0x%x \
215 and max_xid 0x%x\n", min_xid
, max_xid
);
218 BNX2FC_MISC_DBG("min xid 0x%x, max xid 0x%x\n", min_xid
, max_xid
);
220 num_ios
= max_xid
- min_xid
+ 1;
221 len
= (num_ios
* (sizeof(struct bnx2fc_cmd
*)));
222 len
+= sizeof(struct bnx2fc_cmd_mgr
);
224 cmgr
= kzalloc(len
, GFP_KERNEL
);
226 printk(KERN_ERR PFX
"failed to alloc cmgr\n");
230 cmgr
->free_list
= kzalloc(sizeof(*cmgr
->free_list
) *
232 if (!cmgr
->free_list
) {
233 printk(KERN_ERR PFX
"failed to alloc free_list\n");
237 cmgr
->free_list_lock
= kzalloc(sizeof(*cmgr
->free_list_lock
) *
239 if (!cmgr
->free_list_lock
) {
240 printk(KERN_ERR PFX
"failed to alloc free_list_lock\n");
241 kfree(cmgr
->free_list
);
242 cmgr
->free_list
= NULL
;
247 cmgr
->cmds
= (struct bnx2fc_cmd
**)(cmgr
+ 1);
249 for (i
= 0; i
< arr_sz
; i
++) {
250 INIT_LIST_HEAD(&cmgr
->free_list
[i
]);
251 spin_lock_init(&cmgr
->free_list_lock
[i
]);
255 * Pre-allocated pool of bnx2fc_cmds.
256 * Last entry in the free list array is the free list
257 * of slow path requests.
259 xid
= BNX2FC_MIN_XID
;
260 num_pri_ios
= num_ios
- hba
->elstm_xids
;
261 for (i
= 0; i
< num_ios
; i
++) {
262 io_req
= kzalloc(sizeof(*io_req
), GFP_KERNEL
);
265 printk(KERN_ERR PFX
"failed to alloc io_req\n");
269 INIT_LIST_HEAD(&io_req
->link
);
270 INIT_DELAYED_WORK(&io_req
->timeout_work
, bnx2fc_cmd_timeout
);
274 list_add_tail(&io_req
->link
,
275 &cmgr
->free_list
[io_req
->xid
%
276 num_possible_cpus()]);
278 list_add_tail(&io_req
->link
,
279 &cmgr
->free_list
[num_possible_cpus()]);
283 /* Allocate pool of io_bdts - one for each bnx2fc_cmd */
284 mem_size
= num_ios
* sizeof(struct io_bdt
*);
285 cmgr
->io_bdt_pool
= kmalloc(mem_size
, GFP_KERNEL
);
286 if (!cmgr
->io_bdt_pool
) {
287 printk(KERN_ERR PFX
"failed to alloc io_bdt_pool\n");
291 mem_size
= sizeof(struct io_bdt
);
292 for (i
= 0; i
< num_ios
; i
++) {
293 cmgr
->io_bdt_pool
[i
] = kmalloc(mem_size
, GFP_KERNEL
);
294 if (!cmgr
->io_bdt_pool
[i
]) {
295 printk(KERN_ERR PFX
"failed to alloc "
296 "io_bdt_pool[%d]\n", i
);
301 /* Allocate an map fcoe_bdt_ctx structures */
302 bd_tbl_sz
= BNX2FC_MAX_BDS_PER_CMD
* sizeof(struct fcoe_bd_ctx
);
303 for (i
= 0; i
< num_ios
; i
++) {
304 bdt_info
= cmgr
->io_bdt_pool
[i
];
305 bdt_info
->bd_tbl
= dma_alloc_coherent(&hba
->pcidev
->dev
,
307 &bdt_info
->bd_tbl_dma
,
309 if (!bdt_info
->bd_tbl
) {
310 printk(KERN_ERR PFX
"failed to alloc "
319 bnx2fc_cmd_mgr_free(cmgr
);
323 void bnx2fc_cmd_mgr_free(struct bnx2fc_cmd_mgr
*cmgr
)
325 struct io_bdt
*bdt_info
;
326 struct bnx2fc_hba
*hba
= cmgr
->hba
;
328 u16 min_xid
= BNX2FC_MIN_XID
;
329 u16 max_xid
= hba
->max_xid
;
333 num_ios
= max_xid
- min_xid
+ 1;
335 /* Free fcoe_bdt_ctx structures */
336 if (!cmgr
->io_bdt_pool
)
339 bd_tbl_sz
= BNX2FC_MAX_BDS_PER_CMD
* sizeof(struct fcoe_bd_ctx
);
340 for (i
= 0; i
< num_ios
; i
++) {
341 bdt_info
= cmgr
->io_bdt_pool
[i
];
342 if (bdt_info
->bd_tbl
) {
343 dma_free_coherent(&hba
->pcidev
->dev
, bd_tbl_sz
,
345 bdt_info
->bd_tbl_dma
);
346 bdt_info
->bd_tbl
= NULL
;
350 /* Destroy io_bdt pool */
351 for (i
= 0; i
< num_ios
; i
++) {
352 kfree(cmgr
->io_bdt_pool
[i
]);
353 cmgr
->io_bdt_pool
[i
] = NULL
;
356 kfree(cmgr
->io_bdt_pool
);
357 cmgr
->io_bdt_pool
= NULL
;
360 kfree(cmgr
->free_list_lock
);
362 /* Destroy cmd pool */
363 if (!cmgr
->free_list
)
366 for (i
= 0; i
< num_possible_cpus() + 1; i
++) {
367 struct bnx2fc_cmd
*tmp
, *io_req
;
369 list_for_each_entry_safe(io_req
, tmp
,
370 &cmgr
->free_list
[i
], link
) {
371 list_del(&io_req
->link
);
375 kfree(cmgr
->free_list
);
377 /* Free command manager itself */
381 struct bnx2fc_cmd
*bnx2fc_elstm_alloc(struct bnx2fc_rport
*tgt
, int type
)
383 struct fcoe_port
*port
= tgt
->port
;
384 struct bnx2fc_interface
*interface
= port
->priv
;
385 struct bnx2fc_cmd_mgr
*cmd_mgr
= interface
->hba
->cmd_mgr
;
386 struct bnx2fc_cmd
*io_req
;
387 struct list_head
*listp
;
388 struct io_bdt
*bd_tbl
;
389 int index
= RESERVE_FREE_LIST_INDEX
;
394 max_sqes
= tgt
->max_sqes
;
396 case BNX2FC_TASK_MGMT_CMD
:
397 max_sqes
= BNX2FC_TM_MAX_SQES
;
400 max_sqes
= BNX2FC_ELS_MAX_SQES
;
407 * NOTE: Free list insertions and deletions are protected with
410 spin_lock_bh(&cmd_mgr
->free_list_lock
[index
]);
411 free_sqes
= atomic_read(&tgt
->free_sqes
);
412 if ((list_empty(&(cmd_mgr
->free_list
[index
]))) ||
413 (tgt
->num_active_ios
.counter
>= max_sqes
) ||
414 (free_sqes
+ max_sqes
<= BNX2FC_SQ_WQES_MAX
)) {
415 BNX2FC_TGT_DBG(tgt
, "No free els_tm cmds available "
416 "ios(%d):sqes(%d)\n",
417 tgt
->num_active_ios
.counter
, tgt
->max_sqes
);
418 if (list_empty(&(cmd_mgr
->free_list
[index
])))
419 printk(KERN_ERR PFX
"elstm_alloc: list_empty\n");
420 spin_unlock_bh(&cmd_mgr
->free_list_lock
[index
]);
424 listp
= (struct list_head
*)
425 cmd_mgr
->free_list
[index
].next
;
426 list_del_init(listp
);
427 io_req
= (struct bnx2fc_cmd
*) listp
;
429 cmd_mgr
->cmds
[xid
] = io_req
;
430 atomic_inc(&tgt
->num_active_ios
);
431 atomic_dec(&tgt
->free_sqes
);
432 spin_unlock_bh(&cmd_mgr
->free_list_lock
[index
]);
434 INIT_LIST_HEAD(&io_req
->link
);
437 io_req
->cmd_mgr
= cmd_mgr
;
438 io_req
->req_flags
= 0;
439 io_req
->cmd_type
= type
;
441 /* Bind io_bdt for this io_req */
442 /* Have a static link between io_req and io_bdt_pool */
443 bd_tbl
= io_req
->bd_tbl
= cmd_mgr
->io_bdt_pool
[xid
];
444 bd_tbl
->io_req
= io_req
;
446 /* Hold the io_req against deletion */
447 kref_init(&io_req
->refcount
);
451 struct bnx2fc_cmd
*bnx2fc_cmd_alloc(struct bnx2fc_rport
*tgt
)
453 struct fcoe_port
*port
= tgt
->port
;
454 struct bnx2fc_interface
*interface
= port
->priv
;
455 struct bnx2fc_cmd_mgr
*cmd_mgr
= interface
->hba
->cmd_mgr
;
456 struct bnx2fc_cmd
*io_req
;
457 struct list_head
*listp
;
458 struct io_bdt
*bd_tbl
;
462 int index
= get_cpu();
464 max_sqes
= BNX2FC_SCSI_MAX_SQES
;
466 * NOTE: Free list insertions and deletions are protected with
469 spin_lock_bh(&cmd_mgr
->free_list_lock
[index
]);
470 free_sqes
= atomic_read(&tgt
->free_sqes
);
471 if ((list_empty(&cmd_mgr
->free_list
[index
])) ||
472 (tgt
->num_active_ios
.counter
>= max_sqes
) ||
473 (free_sqes
+ max_sqes
<= BNX2FC_SQ_WQES_MAX
)) {
474 spin_unlock_bh(&cmd_mgr
->free_list_lock
[index
]);
479 listp
= (struct list_head
*)
480 cmd_mgr
->free_list
[index
].next
;
481 list_del_init(listp
);
482 io_req
= (struct bnx2fc_cmd
*) listp
;
484 cmd_mgr
->cmds
[xid
] = io_req
;
485 atomic_inc(&tgt
->num_active_ios
);
486 atomic_dec(&tgt
->free_sqes
);
487 spin_unlock_bh(&cmd_mgr
->free_list_lock
[index
]);
490 INIT_LIST_HEAD(&io_req
->link
);
493 io_req
->cmd_mgr
= cmd_mgr
;
494 io_req
->req_flags
= 0;
496 /* Bind io_bdt for this io_req */
497 /* Have a static link between io_req and io_bdt_pool */
498 bd_tbl
= io_req
->bd_tbl
= cmd_mgr
->io_bdt_pool
[xid
];
499 bd_tbl
->io_req
= io_req
;
501 /* Hold the io_req against deletion */
502 kref_init(&io_req
->refcount
);
506 void bnx2fc_cmd_release(struct kref
*ref
)
508 struct bnx2fc_cmd
*io_req
= container_of(ref
,
509 struct bnx2fc_cmd
, refcount
);
510 struct bnx2fc_cmd_mgr
*cmd_mgr
= io_req
->cmd_mgr
;
513 if (io_req
->cmd_type
== BNX2FC_SCSI_CMD
)
514 index
= io_req
->xid
% num_possible_cpus();
516 index
= RESERVE_FREE_LIST_INDEX
;
519 spin_lock_bh(&cmd_mgr
->free_list_lock
[index
]);
520 if (io_req
->cmd_type
!= BNX2FC_SCSI_CMD
)
521 bnx2fc_free_mp_resc(io_req
);
522 cmd_mgr
->cmds
[io_req
->xid
] = NULL
;
523 /* Delete IO from retire queue */
524 list_del_init(&io_req
->link
);
525 /* Add it to the free list */
526 list_add(&io_req
->link
,
527 &cmd_mgr
->free_list
[index
]);
528 atomic_dec(&io_req
->tgt
->num_active_ios
);
529 spin_unlock_bh(&cmd_mgr
->free_list_lock
[index
]);
533 static void bnx2fc_free_mp_resc(struct bnx2fc_cmd
*io_req
)
535 struct bnx2fc_mp_req
*mp_req
= &(io_req
->mp_req
);
536 struct bnx2fc_interface
*interface
= io_req
->port
->priv
;
537 struct bnx2fc_hba
*hba
= interface
->hba
;
538 size_t sz
= sizeof(struct fcoe_bd_ctx
);
541 mp_req
->tm_flags
= 0;
542 if (mp_req
->mp_req_bd
) {
543 dma_free_coherent(&hba
->pcidev
->dev
, sz
,
545 mp_req
->mp_req_bd_dma
);
546 mp_req
->mp_req_bd
= NULL
;
548 if (mp_req
->mp_resp_bd
) {
549 dma_free_coherent(&hba
->pcidev
->dev
, sz
,
551 mp_req
->mp_resp_bd_dma
);
552 mp_req
->mp_resp_bd
= NULL
;
554 if (mp_req
->req_buf
) {
555 dma_free_coherent(&hba
->pcidev
->dev
, CNIC_PAGE_SIZE
,
557 mp_req
->req_buf_dma
);
558 mp_req
->req_buf
= NULL
;
560 if (mp_req
->resp_buf
) {
561 dma_free_coherent(&hba
->pcidev
->dev
, CNIC_PAGE_SIZE
,
563 mp_req
->resp_buf_dma
);
564 mp_req
->resp_buf
= NULL
;
568 int bnx2fc_init_mp_req(struct bnx2fc_cmd
*io_req
)
570 struct bnx2fc_mp_req
*mp_req
;
571 struct fcoe_bd_ctx
*mp_req_bd
;
572 struct fcoe_bd_ctx
*mp_resp_bd
;
573 struct bnx2fc_interface
*interface
= io_req
->port
->priv
;
574 struct bnx2fc_hba
*hba
= interface
->hba
;
578 mp_req
= (struct bnx2fc_mp_req
*)&(io_req
->mp_req
);
579 memset(mp_req
, 0, sizeof(struct bnx2fc_mp_req
));
581 if (io_req
->cmd_type
!= BNX2FC_ELS
) {
582 mp_req
->req_len
= sizeof(struct fcp_cmnd
);
583 io_req
->data_xfer_len
= mp_req
->req_len
;
585 mp_req
->req_len
= io_req
->data_xfer_len
;
587 mp_req
->req_buf
= dma_alloc_coherent(&hba
->pcidev
->dev
, CNIC_PAGE_SIZE
,
588 &mp_req
->req_buf_dma
,
590 if (!mp_req
->req_buf
) {
591 printk(KERN_ERR PFX
"unable to alloc MP req buffer\n");
592 bnx2fc_free_mp_resc(io_req
);
596 mp_req
->resp_buf
= dma_alloc_coherent(&hba
->pcidev
->dev
, CNIC_PAGE_SIZE
,
597 &mp_req
->resp_buf_dma
,
599 if (!mp_req
->resp_buf
) {
600 printk(KERN_ERR PFX
"unable to alloc TM resp buffer\n");
601 bnx2fc_free_mp_resc(io_req
);
604 memset(mp_req
->req_buf
, 0, CNIC_PAGE_SIZE
);
605 memset(mp_req
->resp_buf
, 0, CNIC_PAGE_SIZE
);
607 /* Allocate and map mp_req_bd and mp_resp_bd */
608 sz
= sizeof(struct fcoe_bd_ctx
);
609 mp_req
->mp_req_bd
= dma_alloc_coherent(&hba
->pcidev
->dev
, sz
,
610 &mp_req
->mp_req_bd_dma
,
612 if (!mp_req
->mp_req_bd
) {
613 printk(KERN_ERR PFX
"unable to alloc MP req bd\n");
614 bnx2fc_free_mp_resc(io_req
);
617 mp_req
->mp_resp_bd
= dma_alloc_coherent(&hba
->pcidev
->dev
, sz
,
618 &mp_req
->mp_resp_bd_dma
,
620 if (!mp_req
->mp_resp_bd
) {
621 printk(KERN_ERR PFX
"unable to alloc MP resp bd\n");
622 bnx2fc_free_mp_resc(io_req
);
626 addr
= mp_req
->req_buf_dma
;
627 mp_req_bd
= mp_req
->mp_req_bd
;
628 mp_req_bd
->buf_addr_lo
= (u32
)addr
& 0xffffffff;
629 mp_req_bd
->buf_addr_hi
= (u32
)((u64
)addr
>> 32);
630 mp_req_bd
->buf_len
= CNIC_PAGE_SIZE
;
631 mp_req_bd
->flags
= 0;
634 * MP buffer is either a task mgmt command or an ELS.
635 * So the assumption is that it consumes a single bd
636 * entry in the bd table
638 mp_resp_bd
= mp_req
->mp_resp_bd
;
639 addr
= mp_req
->resp_buf_dma
;
640 mp_resp_bd
->buf_addr_lo
= (u32
)addr
& 0xffffffff;
641 mp_resp_bd
->buf_addr_hi
= (u32
)((u64
)addr
>> 32);
642 mp_resp_bd
->buf_len
= CNIC_PAGE_SIZE
;
643 mp_resp_bd
->flags
= 0;
648 static int bnx2fc_initiate_tmf(struct scsi_cmnd
*sc_cmd
, u8 tm_flags
)
650 struct fc_lport
*lport
;
651 struct fc_rport
*rport
;
652 struct fc_rport_libfc_priv
*rp
;
653 struct fcoe_port
*port
;
654 struct bnx2fc_interface
*interface
;
655 struct bnx2fc_rport
*tgt
;
656 struct bnx2fc_cmd
*io_req
;
657 struct bnx2fc_mp_req
*tm_req
;
658 struct fcoe_task_ctx_entry
*task
;
659 struct fcoe_task_ctx_entry
*task_page
;
660 struct Scsi_Host
*host
= sc_cmd
->device
->host
;
661 struct fc_frame_header
*fc_hdr
;
662 struct fcp_cmnd
*fcp_cmnd
;
667 unsigned long start
= jiffies
;
669 lport
= shost_priv(host
);
670 rport
= starget_to_rport(scsi_target(sc_cmd
->device
));
671 port
= lport_priv(lport
);
672 interface
= port
->priv
;
675 printk(KERN_ERR PFX
"device_reset: rport is NULL\n");
681 rc
= fc_block_scsi_eh(sc_cmd
);
685 if (lport
->state
!= LPORT_ST_READY
|| !(lport
->link_up
)) {
686 printk(KERN_ERR PFX
"device_reset: link is not ready\n");
690 /* rport and tgt are allocated together, so tgt should be non-NULL */
691 tgt
= (struct bnx2fc_rport
*)&rp
[1];
693 if (!(test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
))) {
694 printk(KERN_ERR PFX
"device_reset: tgt not offloaded\n");
699 io_req
= bnx2fc_elstm_alloc(tgt
, BNX2FC_TASK_MGMT_CMD
);
701 if (time_after(jiffies
, start
+ HZ
)) {
702 printk(KERN_ERR PFX
"tmf: Failed TMF");
709 /* Initialize rest of io_req fields */
710 io_req
->sc_cmd
= sc_cmd
;
714 tm_req
= (struct bnx2fc_mp_req
*)&(io_req
->mp_req
);
716 rc
= bnx2fc_init_mp_req(io_req
);
718 printk(KERN_ERR PFX
"Task mgmt MP request init failed\n");
719 spin_lock_bh(&tgt
->tgt_lock
);
720 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
721 spin_unlock_bh(&tgt
->tgt_lock
);
726 io_req
->io_req_flags
= 0;
727 tm_req
->tm_flags
= tm_flags
;
730 bnx2fc_build_fcp_cmnd(io_req
, (struct fcp_cmnd
*)tm_req
->req_buf
);
731 fcp_cmnd
= (struct fcp_cmnd
*)tm_req
->req_buf
;
732 memset(fcp_cmnd
->fc_cdb
, 0, sc_cmd
->cmd_len
);
736 fc_hdr
= &(tm_req
->req_fc_hdr
);
738 did
= rport
->port_id
;
739 __fc_fill_fc_hdr(fc_hdr
, FC_RCTL_DD_UNSOL_CMD
, did
, sid
,
740 FC_TYPE_FCP
, FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
|
742 /* Obtain exchange id */
745 BNX2FC_TGT_DBG(tgt
, "Initiate TMF - xid = 0x%x\n", xid
);
746 task_idx
= xid
/BNX2FC_TASKS_PER_PAGE
;
747 index
= xid
% BNX2FC_TASKS_PER_PAGE
;
749 /* Initialize task context for this IO request */
750 task_page
= (struct fcoe_task_ctx_entry
*)
751 interface
->hba
->task_ctx
[task_idx
];
752 task
= &(task_page
[index
]);
753 bnx2fc_init_mp_task(io_req
, task
);
755 sc_cmd
->SCp
.ptr
= (char *)io_req
;
757 /* Obtain free SQ entry */
758 spin_lock_bh(&tgt
->tgt_lock
);
759 bnx2fc_add_2_sq(tgt
, xid
);
761 /* Enqueue the io_req to active_tm_queue */
762 io_req
->on_tmf_queue
= 1;
763 list_add_tail(&io_req
->link
, &tgt
->active_tm_queue
);
765 init_completion(&io_req
->tm_done
);
766 io_req
->wait_for_comp
= 1;
769 bnx2fc_ring_doorbell(tgt
);
770 spin_unlock_bh(&tgt
->tgt_lock
);
772 rc
= wait_for_completion_timeout(&io_req
->tm_done
,
773 BNX2FC_TM_TIMEOUT
* HZ
);
774 spin_lock_bh(&tgt
->tgt_lock
);
776 io_req
->wait_for_comp
= 0;
777 if (!(test_bit(BNX2FC_FLAG_TM_COMPL
, &io_req
->req_flags
))) {
778 set_bit(BNX2FC_FLAG_TM_TIMEOUT
, &io_req
->req_flags
);
779 if (io_req
->on_tmf_queue
) {
780 list_del_init(&io_req
->link
);
781 io_req
->on_tmf_queue
= 0;
783 io_req
->wait_for_comp
= 1;
784 bnx2fc_initiate_cleanup(io_req
);
785 spin_unlock_bh(&tgt
->tgt_lock
);
786 rc
= wait_for_completion_timeout(&io_req
->tm_done
,
788 spin_lock_bh(&tgt
->tgt_lock
);
789 io_req
->wait_for_comp
= 0;
791 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
794 spin_unlock_bh(&tgt
->tgt_lock
);
797 BNX2FC_TGT_DBG(tgt
, "task mgmt command failed...\n");
800 BNX2FC_TGT_DBG(tgt
, "task mgmt command success...\n");
807 int bnx2fc_initiate_abts(struct bnx2fc_cmd
*io_req
)
809 struct fc_lport
*lport
;
810 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
811 struct fc_rport
*rport
= tgt
->rport
;
812 struct fc_rport_priv
*rdata
= tgt
->rdata
;
813 struct bnx2fc_interface
*interface
;
814 struct fcoe_port
*port
;
815 struct bnx2fc_cmd
*abts_io_req
;
816 struct fcoe_task_ctx_entry
*task
;
817 struct fcoe_task_ctx_entry
*task_page
;
818 struct fc_frame_header
*fc_hdr
;
819 struct bnx2fc_mp_req
*abts_req
;
824 u32 r_a_tov
= rdata
->r_a_tov
;
826 /* called with tgt_lock held */
827 BNX2FC_IO_DBG(io_req
, "Entered bnx2fc_initiate_abts\n");
830 interface
= port
->priv
;
833 if (!test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
)) {
834 printk(KERN_ERR PFX
"initiate_abts: tgt not offloaded\n");
840 printk(KERN_ERR PFX
"initiate_abts: rport is NULL\n");
845 if (lport
->state
!= LPORT_ST_READY
|| !(lport
->link_up
)) {
846 printk(KERN_ERR PFX
"initiate_abts: link is not ready\n");
851 abts_io_req
= bnx2fc_elstm_alloc(tgt
, BNX2FC_ABTS
);
853 printk(KERN_ERR PFX
"abts: couldnt allocate cmd\n");
858 /* Initialize rest of io_req fields */
859 abts_io_req
->sc_cmd
= NULL
;
860 abts_io_req
->port
= port
;
861 abts_io_req
->tgt
= tgt
;
862 abts_io_req
->data_xfer_len
= 0; /* No data transfer for ABTS */
864 abts_req
= (struct bnx2fc_mp_req
*)&(abts_io_req
->mp_req
);
865 memset(abts_req
, 0, sizeof(struct bnx2fc_mp_req
));
868 fc_hdr
= &(abts_req
->req_fc_hdr
);
870 /* Obtain oxid and rxid for the original exchange to be aborted */
871 fc_hdr
->fh_ox_id
= htons(io_req
->xid
);
872 fc_hdr
->fh_rx_id
= htons(io_req
->task
->rxwr_txrd
.var_ctx
.rx_id
);
875 did
= rport
->port_id
;
877 __fc_fill_fc_hdr(fc_hdr
, FC_RCTL_BA_ABTS
, did
, sid
,
878 FC_TYPE_BLS
, FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
|
881 xid
= abts_io_req
->xid
;
882 BNX2FC_IO_DBG(abts_io_req
, "ABTS io_req\n");
883 task_idx
= xid
/BNX2FC_TASKS_PER_PAGE
;
884 index
= xid
% BNX2FC_TASKS_PER_PAGE
;
886 /* Initialize task context for this IO request */
887 task_page
= (struct fcoe_task_ctx_entry
*)
888 interface
->hba
->task_ctx
[task_idx
];
889 task
= &(task_page
[index
]);
890 bnx2fc_init_mp_task(abts_io_req
, task
);
893 * ABTS task is a temporary task that will be cleaned up
894 * irrespective of ABTS response. We need to start the timer
895 * for the original exchange, as the CQE is posted for the original
898 * Timer for ABTS is started only when it is originated by a
899 * TM request. For the ABTS issued as part of ULP timeout,
900 * scsi-ml maintains the timers.
903 /* if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags))*/
904 bnx2fc_cmd_timer_set(io_req
, 2 * r_a_tov
);
906 /* Obtain free SQ entry */
907 bnx2fc_add_2_sq(tgt
, xid
);
910 bnx2fc_ring_doorbell(tgt
);
916 int bnx2fc_initiate_seq_cleanup(struct bnx2fc_cmd
*orig_io_req
, u32 offset
,
919 struct fc_lport
*lport
;
920 struct bnx2fc_rport
*tgt
= orig_io_req
->tgt
;
921 struct bnx2fc_interface
*interface
;
922 struct fcoe_port
*port
;
923 struct bnx2fc_cmd
*seq_clnp_req
;
924 struct fcoe_task_ctx_entry
*task
;
925 struct fcoe_task_ctx_entry
*task_page
;
926 struct bnx2fc_els_cb_arg
*cb_arg
= NULL
;
931 BNX2FC_IO_DBG(orig_io_req
, "bnx2fc_initiate_seq_cleanup xid = 0x%x\n",
933 kref_get(&orig_io_req
->refcount
);
935 port
= orig_io_req
->port
;
936 interface
= port
->priv
;
939 cb_arg
= kzalloc(sizeof(struct bnx2fc_els_cb_arg
), GFP_ATOMIC
);
941 printk(KERN_ERR PFX
"Unable to alloc cb_arg for seq clnup\n");
946 seq_clnp_req
= bnx2fc_elstm_alloc(tgt
, BNX2FC_SEQ_CLEANUP
);
948 printk(KERN_ERR PFX
"cleanup: couldnt allocate cmd\n");
953 /* Initialize rest of io_req fields */
954 seq_clnp_req
->sc_cmd
= NULL
;
955 seq_clnp_req
->port
= port
;
956 seq_clnp_req
->tgt
= tgt
;
957 seq_clnp_req
->data_xfer_len
= 0; /* No data transfer for cleanup */
959 xid
= seq_clnp_req
->xid
;
961 task_idx
= xid
/BNX2FC_TASKS_PER_PAGE
;
962 index
= xid
% BNX2FC_TASKS_PER_PAGE
;
964 /* Initialize task context for this IO request */
965 task_page
= (struct fcoe_task_ctx_entry
*)
966 interface
->hba
->task_ctx
[task_idx
];
967 task
= &(task_page
[index
]);
968 cb_arg
->aborted_io_req
= orig_io_req
;
969 cb_arg
->io_req
= seq_clnp_req
;
970 cb_arg
->r_ctl
= r_ctl
;
971 cb_arg
->offset
= offset
;
972 seq_clnp_req
->cb_arg
= cb_arg
;
974 printk(KERN_ERR PFX
"call init_seq_cleanup_task\n");
975 bnx2fc_init_seq_cleanup_task(seq_clnp_req
, task
, orig_io_req
, offset
);
977 /* Obtain free SQ entry */
978 bnx2fc_add_2_sq(tgt
, xid
);
981 bnx2fc_ring_doorbell(tgt
);
986 int bnx2fc_initiate_cleanup(struct bnx2fc_cmd
*io_req
)
988 struct fc_lport
*lport
;
989 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
990 struct bnx2fc_interface
*interface
;
991 struct fcoe_port
*port
;
992 struct bnx2fc_cmd
*cleanup_io_req
;
993 struct fcoe_task_ctx_entry
*task
;
994 struct fcoe_task_ctx_entry
*task_page
;
999 /* ASSUMPTION: called with tgt_lock held */
1000 BNX2FC_IO_DBG(io_req
, "Entered bnx2fc_initiate_cleanup\n");
1002 port
= io_req
->port
;
1003 interface
= port
->priv
;
1004 lport
= port
->lport
;
1006 cleanup_io_req
= bnx2fc_elstm_alloc(tgt
, BNX2FC_CLEANUP
);
1007 if (!cleanup_io_req
) {
1008 printk(KERN_ERR PFX
"cleanup: couldnt allocate cmd\n");
1013 /* Initialize rest of io_req fields */
1014 cleanup_io_req
->sc_cmd
= NULL
;
1015 cleanup_io_req
->port
= port
;
1016 cleanup_io_req
->tgt
= tgt
;
1017 cleanup_io_req
->data_xfer_len
= 0; /* No data transfer for cleanup */
1019 xid
= cleanup_io_req
->xid
;
1021 task_idx
= xid
/BNX2FC_TASKS_PER_PAGE
;
1022 index
= xid
% BNX2FC_TASKS_PER_PAGE
;
1024 /* Initialize task context for this IO request */
1025 task_page
= (struct fcoe_task_ctx_entry
*)
1026 interface
->hba
->task_ctx
[task_idx
];
1027 task
= &(task_page
[index
]);
1028 orig_xid
= io_req
->xid
;
1030 BNX2FC_IO_DBG(io_req
, "CLEANUP io_req xid = 0x%x\n", xid
);
1032 bnx2fc_init_cleanup_task(cleanup_io_req
, task
, orig_xid
);
1034 /* Obtain free SQ entry */
1035 bnx2fc_add_2_sq(tgt
, xid
);
1038 bnx2fc_ring_doorbell(tgt
);
1045 * bnx2fc_eh_target_reset: Reset a target
1047 * @sc_cmd: SCSI command
1049 * Set from SCSI host template to send task mgmt command to the target
1050 * and wait for the response
1052 int bnx2fc_eh_target_reset(struct scsi_cmnd
*sc_cmd
)
1054 return bnx2fc_initiate_tmf(sc_cmd
, FCP_TMF_TGT_RESET
);
1058 * bnx2fc_eh_device_reset - Reset a single LUN
1060 * @sc_cmd: SCSI command
1062 * Set from SCSI host template to send task mgmt command to the target
1063 * and wait for the response
1065 int bnx2fc_eh_device_reset(struct scsi_cmnd
*sc_cmd
)
1067 return bnx2fc_initiate_tmf(sc_cmd
, FCP_TMF_LUN_RESET
);
1070 int bnx2fc_abts_cleanup(struct bnx2fc_cmd
*io_req
)
1072 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1075 io_req
->wait_for_comp
= 1;
1076 bnx2fc_initiate_cleanup(io_req
);
1078 spin_unlock_bh(&tgt
->tgt_lock
);
1080 wait_for_completion(&io_req
->tm_done
);
1082 io_req
->wait_for_comp
= 0;
1084 * release the reference taken in eh_abort to allow the
1085 * target to re-login after flushing IOs
1087 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1089 spin_lock_bh(&tgt
->tgt_lock
);
1093 * bnx2fc_eh_abort - eh_abort_handler api to abort an outstanding
1096 * @sc_cmd: SCSI_ML command pointer
1098 * SCSI abort request handler
1100 int bnx2fc_eh_abort(struct scsi_cmnd
*sc_cmd
)
1102 struct fc_rport
*rport
= starget_to_rport(scsi_target(sc_cmd
->device
));
1103 struct fc_rport_libfc_priv
*rp
= rport
->dd_data
;
1104 struct bnx2fc_cmd
*io_req
;
1105 struct fc_lport
*lport
;
1106 struct bnx2fc_rport
*tgt
;
1110 rc
= fc_block_scsi_eh(sc_cmd
);
1114 lport
= shost_priv(sc_cmd
->device
->host
);
1115 if ((lport
->state
!= LPORT_ST_READY
) || !(lport
->link_up
)) {
1116 printk(KERN_ERR PFX
"eh_abort: link not ready\n");
1120 tgt
= (struct bnx2fc_rport
*)&rp
[1];
1122 BNX2FC_TGT_DBG(tgt
, "Entered bnx2fc_eh_abort\n");
1124 spin_lock_bh(&tgt
->tgt_lock
);
1125 io_req
= (struct bnx2fc_cmd
*)sc_cmd
->SCp
.ptr
;
1127 /* Command might have just completed */
1128 printk(KERN_ERR PFX
"eh_abort: io_req is NULL\n");
1129 spin_unlock_bh(&tgt
->tgt_lock
);
1132 BNX2FC_IO_DBG(io_req
, "eh_abort - refcnt = %d\n",
1133 io_req
->refcount
.refcount
.counter
);
1135 /* Hold IO request across abort processing */
1136 kref_get(&io_req
->refcount
);
1138 BUG_ON(tgt
!= io_req
->tgt
);
1140 /* Remove the io_req from the active_q. */
1142 * Task Mgmt functions (LUN RESET & TGT RESET) will not
1143 * issue an ABTS on this particular IO req, as the
1144 * io_req is no longer in the active_q.
1146 if (tgt
->flush_in_prog
) {
1147 printk(KERN_ERR PFX
"eh_abort: io_req (xid = 0x%x) "
1148 "flush in progress\n", io_req
->xid
);
1149 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1150 spin_unlock_bh(&tgt
->tgt_lock
);
1154 if (io_req
->on_active_queue
== 0) {
1155 printk(KERN_ERR PFX
"eh_abort: io_req (xid = 0x%x) "
1156 "not on active_q\n", io_req
->xid
);
1158 * This condition can happen only due to the FW bug,
1159 * where we do not receive cleanup response from
1160 * the FW. Handle this case gracefully by erroring
1161 * back the IO request to SCSI-ml
1163 bnx2fc_scsi_done(io_req
, DID_ABORT
);
1165 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1166 spin_unlock_bh(&tgt
->tgt_lock
);
1171 * Only eh_abort processing will remove the IO from
1172 * active_cmd_q before processing the request. this is
1173 * done to avoid race conditions between IOs aborted
1174 * as part of task management completion and eh_abort
1177 list_del_init(&io_req
->link
);
1178 io_req
->on_active_queue
= 0;
1179 /* Move IO req to retire queue */
1180 list_add_tail(&io_req
->link
, &tgt
->io_retire_queue
);
1182 init_completion(&io_req
->tm_done
);
1184 if (test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS
, &io_req
->req_flags
)) {
1185 printk(KERN_ERR PFX
"eh_abort: io_req (xid = 0x%x) "
1186 "already in abts processing\n", io_req
->xid
);
1187 if (cancel_delayed_work(&io_req
->timeout_work
))
1188 kref_put(&io_req
->refcount
,
1189 bnx2fc_cmd_release
); /* drop timer hold */
1190 rc
= bnx2fc_abts_cleanup(io_req
);
1191 /* This only occurs when an task abort was requested while ABTS
1192 is in progress. Setting the IO_CLEANUP flag will skip the
1193 RRQ process in the case when the fw generated SCSI_CMD cmpl
1194 was a result from the ABTS request rather than the CLEANUP
1196 set_bit(BNX2FC_FLAG_IO_CLEANUP
, &io_req
->req_flags
);
1200 /* Cancel the current timer running on this io_req */
1201 if (cancel_delayed_work(&io_req
->timeout_work
))
1202 kref_put(&io_req
->refcount
,
1203 bnx2fc_cmd_release
); /* drop timer hold */
1204 set_bit(BNX2FC_FLAG_EH_ABORT
, &io_req
->req_flags
);
1205 io_req
->wait_for_comp
= 1;
1206 rc
= bnx2fc_initiate_abts(io_req
);
1208 bnx2fc_initiate_cleanup(io_req
);
1209 spin_unlock_bh(&tgt
->tgt_lock
);
1210 wait_for_completion(&io_req
->tm_done
);
1211 spin_lock_bh(&tgt
->tgt_lock
);
1212 io_req
->wait_for_comp
= 0;
1215 spin_unlock_bh(&tgt
->tgt_lock
);
1217 wait_for_completion(&io_req
->tm_done
);
1219 spin_lock_bh(&tgt
->tgt_lock
);
1220 io_req
->wait_for_comp
= 0;
1221 if (test_bit(BNX2FC_FLAG_IO_COMPL
, &io_req
->req_flags
)) {
1222 BNX2FC_IO_DBG(io_req
, "IO completed in a different context\n");
1224 } else if (!(test_and_set_bit(BNX2FC_FLAG_ABTS_DONE
,
1225 &io_req
->req_flags
))) {
1226 /* Let the scsi-ml try to recover this command */
1227 printk(KERN_ERR PFX
"abort failed, xid = 0x%x\n",
1229 rc
= bnx2fc_abts_cleanup(io_req
);
1233 * We come here even when there was a race condition
1234 * between timeout and abts completion, and abts
1235 * completion happens just in time.
1237 BNX2FC_IO_DBG(io_req
, "abort succeeded\n");
1239 bnx2fc_scsi_done(io_req
, DID_ABORT
);
1240 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1243 /* release the reference taken in eh_abort */
1244 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1246 spin_unlock_bh(&tgt
->tgt_lock
);
1250 void bnx2fc_process_seq_cleanup_compl(struct bnx2fc_cmd
*seq_clnp_req
,
1251 struct fcoe_task_ctx_entry
*task
,
1254 struct bnx2fc_els_cb_arg
*cb_arg
= seq_clnp_req
->cb_arg
;
1255 struct bnx2fc_cmd
*orig_io_req
= cb_arg
->aborted_io_req
;
1256 u32 offset
= cb_arg
->offset
;
1257 enum fc_rctl r_ctl
= cb_arg
->r_ctl
;
1259 struct bnx2fc_rport
*tgt
= orig_io_req
->tgt
;
1261 BNX2FC_IO_DBG(orig_io_req
, "Entered process_cleanup_compl xid = 0x%x"
1263 seq_clnp_req
->xid
, seq_clnp_req
->cmd_type
);
1265 if (rx_state
== FCOE_TASK_RX_STATE_IGNORED_SEQUENCE_CLEANUP
) {
1266 printk(KERN_ERR PFX
"seq cleanup ignored - xid = 0x%x\n",
1271 spin_unlock_bh(&tgt
->tgt_lock
);
1272 rc
= bnx2fc_send_srr(orig_io_req
, offset
, r_ctl
);
1273 spin_lock_bh(&tgt
->tgt_lock
);
1276 printk(KERN_ERR PFX
"clnup_compl: Unable to send SRR"
1277 " IO will abort\n");
1278 seq_clnp_req
->cb_arg
= NULL
;
1279 kref_put(&orig_io_req
->refcount
, bnx2fc_cmd_release
);
1285 void bnx2fc_process_cleanup_compl(struct bnx2fc_cmd
*io_req
,
1286 struct fcoe_task_ctx_entry
*task
,
1289 BNX2FC_IO_DBG(io_req
, "Entered process_cleanup_compl "
1290 "refcnt = %d, cmd_type = %d\n",
1291 io_req
->refcount
.refcount
.counter
, io_req
->cmd_type
);
1292 bnx2fc_scsi_done(io_req
, DID_ERROR
);
1293 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1294 if (io_req
->wait_for_comp
)
1295 complete(&io_req
->tm_done
);
1298 void bnx2fc_process_abts_compl(struct bnx2fc_cmd
*io_req
,
1299 struct fcoe_task_ctx_entry
*task
,
1303 u32 r_a_tov
= FC_DEF_R_A_TOV
;
1305 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1307 BNX2FC_IO_DBG(io_req
, "Entered process_abts_compl xid = 0x%x"
1308 "refcnt = %d, cmd_type = %d\n",
1310 io_req
->refcount
.refcount
.counter
, io_req
->cmd_type
);
1312 if (test_and_set_bit(BNX2FC_FLAG_ABTS_DONE
,
1313 &io_req
->req_flags
)) {
1314 BNX2FC_IO_DBG(io_req
, "Timer context finished processing"
1319 /* Do not issue RRQ as this IO is already cleanedup */
1320 if (test_and_set_bit(BNX2FC_FLAG_IO_CLEANUP
,
1321 &io_req
->req_flags
))
1325 * For ABTS issued due to SCSI eh_abort_handler, timeout
1326 * values are maintained by scsi-ml itself. Cancel timeout
1327 * in case ABTS issued as part of task management function
1328 * or due to FW error.
1330 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS
, &io_req
->req_flags
))
1331 if (cancel_delayed_work(&io_req
->timeout_work
))
1332 kref_put(&io_req
->refcount
,
1333 bnx2fc_cmd_release
); /* drop timer hold */
1335 r_ctl
= (u8
)task
->rxwr_only
.union_ctx
.comp_info
.abts_rsp
.r_ctl
;
1338 case FC_RCTL_BA_ACC
:
1340 * Dont release this cmd yet. It will be relesed
1341 * after we get RRQ response
1343 BNX2FC_IO_DBG(io_req
, "ABTS response - ACC Send RRQ\n");
1347 case FC_RCTL_BA_RJT
:
1348 BNX2FC_IO_DBG(io_req
, "ABTS response - RJT\n");
1351 printk(KERN_ERR PFX
"Unknown ABTS response\n");
1356 BNX2FC_IO_DBG(io_req
, "Issue RRQ after R_A_TOV\n");
1357 set_bit(BNX2FC_FLAG_ISSUE_RRQ
, &io_req
->req_flags
);
1359 set_bit(BNX2FC_FLAG_RETIRE_OXID
, &io_req
->req_flags
);
1360 bnx2fc_cmd_timer_set(io_req
, r_a_tov
);
1363 if (io_req
->wait_for_comp
) {
1364 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
1365 &io_req
->req_flags
))
1366 complete(&io_req
->tm_done
);
1369 * We end up here when ABTS is issued as
1370 * in asynchronous context, i.e., as part
1371 * of task management completion, or
1372 * when FW error is received or when the
1373 * ABTS is issued when the IO is timed
1377 if (io_req
->on_active_queue
) {
1378 list_del_init(&io_req
->link
);
1379 io_req
->on_active_queue
= 0;
1380 /* Move IO req to retire queue */
1381 list_add_tail(&io_req
->link
, &tgt
->io_retire_queue
);
1383 bnx2fc_scsi_done(io_req
, DID_ERROR
);
1384 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1388 static void bnx2fc_lun_reset_cmpl(struct bnx2fc_cmd
*io_req
)
1390 struct scsi_cmnd
*sc_cmd
= io_req
->sc_cmd
;
1391 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1392 struct bnx2fc_cmd
*cmd
, *tmp
;
1393 u64 tm_lun
= sc_cmd
->device
->lun
;
1397 /* called with tgt_lock held */
1398 BNX2FC_IO_DBG(io_req
, "Entered bnx2fc_lun_reset_cmpl\n");
1400 * Walk thru the active_ios queue and ABORT the IO
1401 * that matches with the LUN that was reset
1403 list_for_each_entry_safe(cmd
, tmp
, &tgt
->active_cmd_queue
, link
) {
1404 BNX2FC_TGT_DBG(tgt
, "LUN RST cmpl: scan for pending IOs\n");
1405 lun
= cmd
->sc_cmd
->device
->lun
;
1406 if (lun
== tm_lun
) {
1407 /* Initiate ABTS on this cmd */
1408 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS
,
1410 /* cancel the IO timeout */
1411 if (cancel_delayed_work(&io_req
->timeout_work
))
1412 kref_put(&io_req
->refcount
,
1413 bnx2fc_cmd_release
);
1415 rc
= bnx2fc_initiate_abts(cmd
);
1416 /* abts shouldn't fail in this context */
1417 WARN_ON(rc
!= SUCCESS
);
1419 printk(KERN_ERR PFX
"lun_rst: abts already in"
1420 " progress for this IO 0x%x\n",
1426 static void bnx2fc_tgt_reset_cmpl(struct bnx2fc_cmd
*io_req
)
1428 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1429 struct bnx2fc_cmd
*cmd
, *tmp
;
1432 /* called with tgt_lock held */
1433 BNX2FC_IO_DBG(io_req
, "Entered bnx2fc_tgt_reset_cmpl\n");
1435 * Walk thru the active_ios queue and ABORT the IO
1436 * that matches with the LUN that was reset
1438 list_for_each_entry_safe(cmd
, tmp
, &tgt
->active_cmd_queue
, link
) {
1439 BNX2FC_TGT_DBG(tgt
, "TGT RST cmpl: scan for pending IOs\n");
1441 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS
,
1443 /* cancel the IO timeout */
1444 if (cancel_delayed_work(&io_req
->timeout_work
))
1445 kref_put(&io_req
->refcount
,
1446 bnx2fc_cmd_release
); /* timer hold */
1447 rc
= bnx2fc_initiate_abts(cmd
);
1448 /* abts shouldn't fail in this context */
1449 WARN_ON(rc
!= SUCCESS
);
1452 printk(KERN_ERR PFX
"tgt_rst: abts already in progress"
1453 " for this IO 0x%x\n", cmd
->xid
);
1457 void bnx2fc_process_tm_compl(struct bnx2fc_cmd
*io_req
,
1458 struct fcoe_task_ctx_entry
*task
, u8 num_rq
)
1460 struct bnx2fc_mp_req
*tm_req
;
1461 struct fc_frame_header
*fc_hdr
;
1462 struct scsi_cmnd
*sc_cmd
= io_req
->sc_cmd
;
1467 /* Called with tgt_lock held */
1468 BNX2FC_IO_DBG(io_req
, "Entered process_tm_compl\n");
1470 if (!(test_bit(BNX2FC_FLAG_TM_TIMEOUT
, &io_req
->req_flags
)))
1471 set_bit(BNX2FC_FLAG_TM_COMPL
, &io_req
->req_flags
);
1473 /* TM has already timed out and we got
1474 * delayed completion. Ignore completion
1480 tm_req
= &(io_req
->mp_req
);
1481 fc_hdr
= &(tm_req
->resp_fc_hdr
);
1482 hdr
= (u64
*)fc_hdr
;
1484 &task
->rxwr_only
.union_ctx
.comp_info
.mp_rsp
.fc_hdr
;
1485 hdr
[0] = cpu_to_be64(temp_hdr
[0]);
1486 hdr
[1] = cpu_to_be64(temp_hdr
[1]);
1487 hdr
[2] = cpu_to_be64(temp_hdr
[2]);
1490 task
->rxwr_only
.union_ctx
.comp_info
.mp_rsp
.mp_payload_len
;
1492 rsp_buf
= tm_req
->resp_buf
;
1494 if (fc_hdr
->fh_r_ctl
== FC_RCTL_DD_CMD_STATUS
) {
1495 bnx2fc_parse_fcp_rsp(io_req
,
1496 (struct fcoe_fcp_rsp_payload
*)
1498 if (io_req
->fcp_rsp_code
== 0) {
1500 if (tm_req
->tm_flags
& FCP_TMF_LUN_RESET
)
1501 bnx2fc_lun_reset_cmpl(io_req
);
1502 else if (tm_req
->tm_flags
& FCP_TMF_TGT_RESET
)
1503 bnx2fc_tgt_reset_cmpl(io_req
);
1506 printk(KERN_ERR PFX
"tmf's fc_hdr r_ctl = 0x%x\n",
1509 if (!sc_cmd
->SCp
.ptr
) {
1510 printk(KERN_ERR PFX
"tm_compl: SCp.ptr is NULL\n");
1513 switch (io_req
->fcp_status
) {
1515 if (io_req
->cdb_status
== 0) {
1516 /* Good IO completion */
1517 sc_cmd
->result
= DID_OK
<< 16;
1519 /* Transport status is good, SCSI status not good */
1520 sc_cmd
->result
= (DID_OK
<< 16) | io_req
->cdb_status
;
1522 if (io_req
->fcp_resid
)
1523 scsi_set_resid(sc_cmd
, io_req
->fcp_resid
);
1527 BNX2FC_IO_DBG(io_req
, "process_tm_compl: fcp_status = %d\n",
1528 io_req
->fcp_status
);
1532 sc_cmd
= io_req
->sc_cmd
;
1533 io_req
->sc_cmd
= NULL
;
1535 /* check if the io_req exists in tgt's tmf_q */
1536 if (io_req
->on_tmf_queue
) {
1538 list_del_init(&io_req
->link
);
1539 io_req
->on_tmf_queue
= 0;
1542 printk(KERN_ERR PFX
"Command not on active_cmd_queue!\n");
1546 sc_cmd
->SCp
.ptr
= NULL
;
1547 sc_cmd
->scsi_done(sc_cmd
);
1549 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1550 if (io_req
->wait_for_comp
) {
1551 BNX2FC_IO_DBG(io_req
, "tm_compl - wake up the waiter\n");
1552 complete(&io_req
->tm_done
);
1556 static int bnx2fc_split_bd(struct bnx2fc_cmd
*io_req
, u64 addr
, int sg_len
,
1559 struct fcoe_bd_ctx
*bd
= io_req
->bd_tbl
->bd_tbl
;
1560 int frag_size
, sg_frags
;
1564 if (sg_len
>= BNX2FC_BD_SPLIT_SZ
)
1565 frag_size
= BNX2FC_BD_SPLIT_SZ
;
1568 bd
[bd_index
+ sg_frags
].buf_addr_lo
= addr
& 0xffffffff;
1569 bd
[bd_index
+ sg_frags
].buf_addr_hi
= addr
>> 32;
1570 bd
[bd_index
+ sg_frags
].buf_len
= (u16
)frag_size
;
1571 bd
[bd_index
+ sg_frags
].flags
= 0;
1573 addr
+= (u64
) frag_size
;
1575 sg_len
-= frag_size
;
1581 static int bnx2fc_map_sg(struct bnx2fc_cmd
*io_req
)
1583 struct bnx2fc_interface
*interface
= io_req
->port
->priv
;
1584 struct bnx2fc_hba
*hba
= interface
->hba
;
1585 struct scsi_cmnd
*sc
= io_req
->sc_cmd
;
1586 struct fcoe_bd_ctx
*bd
= io_req
->bd_tbl
->bd_tbl
;
1587 struct scatterlist
*sg
;
1592 unsigned int sg_len
;
1597 * Use dma_map_sg directly to ensure we're using the correct
1598 * dev struct off of pcidev.
1600 sg_count
= dma_map_sg(&hba
->pcidev
->dev
, scsi_sglist(sc
),
1601 scsi_sg_count(sc
), sc
->sc_data_direction
);
1602 scsi_for_each_sg(sc
, sg
, sg_count
, i
) {
1603 sg_len
= sg_dma_len(sg
);
1604 addr
= sg_dma_address(sg
);
1605 if (sg_len
> BNX2FC_MAX_BD_LEN
) {
1606 sg_frags
= bnx2fc_split_bd(io_req
, addr
, sg_len
,
1611 bd
[bd_count
].buf_addr_lo
= addr
& 0xffffffff;
1612 bd
[bd_count
].buf_addr_hi
= addr
>> 32;
1613 bd
[bd_count
].buf_len
= (u16
)sg_len
;
1614 bd
[bd_count
].flags
= 0;
1616 bd_count
+= sg_frags
;
1617 byte_count
+= sg_len
;
1619 if (byte_count
!= scsi_bufflen(sc
))
1620 printk(KERN_ERR PFX
"byte_count = %d != scsi_bufflen = %d, "
1621 "task_id = 0x%x\n", byte_count
, scsi_bufflen(sc
),
1626 static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd
*io_req
)
1628 struct scsi_cmnd
*sc
= io_req
->sc_cmd
;
1629 struct fcoe_bd_ctx
*bd
= io_req
->bd_tbl
->bd_tbl
;
1632 if (scsi_sg_count(sc
)) {
1633 bd_count
= bnx2fc_map_sg(io_req
);
1638 bd
[0].buf_addr_lo
= bd
[0].buf_addr_hi
= 0;
1639 bd
[0].buf_len
= bd
[0].flags
= 0;
1641 io_req
->bd_tbl
->bd_valid
= bd_count
;
1646 static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd
*io_req
)
1648 struct scsi_cmnd
*sc
= io_req
->sc_cmd
;
1649 struct bnx2fc_interface
*interface
= io_req
->port
->priv
;
1650 struct bnx2fc_hba
*hba
= interface
->hba
;
1653 * Use dma_unmap_sg directly to ensure we're using the correct
1654 * dev struct off of pcidev.
1656 if (io_req
->bd_tbl
->bd_valid
&& sc
&& scsi_sg_count(sc
)) {
1657 dma_unmap_sg(&hba
->pcidev
->dev
, scsi_sglist(sc
),
1658 scsi_sg_count(sc
), sc
->sc_data_direction
);
1659 io_req
->bd_tbl
->bd_valid
= 0;
1663 void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd
*io_req
,
1664 struct fcp_cmnd
*fcp_cmnd
)
1666 struct scsi_cmnd
*sc_cmd
= io_req
->sc_cmd
;
1668 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
1670 int_to_scsilun(sc_cmd
->device
->lun
, &fcp_cmnd
->fc_lun
);
1672 fcp_cmnd
->fc_dl
= htonl(io_req
->data_xfer_len
);
1673 memcpy(fcp_cmnd
->fc_cdb
, sc_cmd
->cmnd
, sc_cmd
->cmd_len
);
1675 fcp_cmnd
->fc_cmdref
= 0;
1676 fcp_cmnd
->fc_pri_ta
= 0;
1677 fcp_cmnd
->fc_tm_flags
= io_req
->mp_req
.tm_flags
;
1678 fcp_cmnd
->fc_flags
= io_req
->io_req_flags
;
1679 fcp_cmnd
->fc_pri_ta
= FCP_PTA_SIMPLE
;
1682 static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd
*io_req
,
1683 struct fcoe_fcp_rsp_payload
*fcp_rsp
,
1686 struct scsi_cmnd
*sc_cmd
= io_req
->sc_cmd
;
1687 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1688 u8 rsp_flags
= fcp_rsp
->fcp_flags
.flags
;
1689 u32 rq_buff_len
= 0;
1691 unsigned char *rq_data
;
1692 unsigned char *dummy
;
1693 int fcp_sns_len
= 0;
1694 int fcp_rsp_len
= 0;
1696 io_req
->fcp_status
= FC_GOOD
;
1697 io_req
->fcp_resid
= 0;
1698 if (rsp_flags
& (FCOE_FCP_RSP_FLAGS_FCP_RESID_OVER
|
1699 FCOE_FCP_RSP_FLAGS_FCP_RESID_UNDER
))
1700 io_req
->fcp_resid
= fcp_rsp
->fcp_resid
;
1702 io_req
->scsi_comp_flags
= rsp_flags
;
1703 CMD_SCSI_STATUS(sc_cmd
) = io_req
->cdb_status
=
1704 fcp_rsp
->scsi_status_code
;
1706 /* Fetch fcp_rsp_info and fcp_sns_info if available */
1710 * We do not anticipate num_rq >1, as the linux defined
1711 * SCSI_SENSE_BUFFERSIZE is 96 bytes + 8 bytes of FCP_RSP_INFO
1712 * 256 bytes of single rq buffer is good enough to hold this.
1716 FCOE_FCP_RSP_FLAGS_FCP_RSP_LEN_VALID
) {
1717 fcp_rsp_len
= rq_buff_len
1718 = fcp_rsp
->fcp_rsp_len
;
1722 FCOE_FCP_RSP_FLAGS_FCP_SNS_LEN_VALID
) {
1723 fcp_sns_len
= fcp_rsp
->fcp_sns_len
;
1724 rq_buff_len
+= fcp_rsp
->fcp_sns_len
;
1727 io_req
->fcp_rsp_len
= fcp_rsp_len
;
1728 io_req
->fcp_sns_len
= fcp_sns_len
;
1730 if (rq_buff_len
> num_rq
* BNX2FC_RQ_BUF_SZ
) {
1731 /* Invalid sense sense length. */
1732 printk(KERN_ERR PFX
"invalid sns length %d\n",
1734 /* reset rq_buff_len */
1735 rq_buff_len
= num_rq
* BNX2FC_RQ_BUF_SZ
;
1738 rq_data
= bnx2fc_get_next_rqe(tgt
, 1);
1741 /* We do not need extra sense data */
1742 for (i
= 1; i
< num_rq
; i
++)
1743 dummy
= bnx2fc_get_next_rqe(tgt
, 1);
1746 /* fetch fcp_rsp_code */
1747 if ((fcp_rsp_len
== 4) || (fcp_rsp_len
== 8)) {
1748 /* Only for task management function */
1749 io_req
->fcp_rsp_code
= rq_data
[3];
1750 printk(KERN_ERR PFX
"fcp_rsp_code = %d\n",
1751 io_req
->fcp_rsp_code
);
1754 /* fetch sense data */
1755 rq_data
+= fcp_rsp_len
;
1757 if (fcp_sns_len
> SCSI_SENSE_BUFFERSIZE
) {
1758 printk(KERN_ERR PFX
"Truncating sense buffer\n");
1759 fcp_sns_len
= SCSI_SENSE_BUFFERSIZE
;
1762 memset(sc_cmd
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
1764 memcpy(sc_cmd
->sense_buffer
, rq_data
, fcp_sns_len
);
1766 /* return RQ entries */
1767 for (i
= 0; i
< num_rq
; i
++)
1768 bnx2fc_return_rqe(tgt
, 1);
1773 * bnx2fc_queuecommand - Queuecommand function of the scsi template
1775 * @host: The Scsi_Host the command was issued to
1776 * @sc_cmd: struct scsi_cmnd to be executed
1778 * This is the IO strategy routine, called by SCSI-ML
1780 int bnx2fc_queuecommand(struct Scsi_Host
*host
,
1781 struct scsi_cmnd
*sc_cmd
)
1783 struct fc_lport
*lport
= shost_priv(host
);
1784 struct fc_rport
*rport
= starget_to_rport(scsi_target(sc_cmd
->device
));
1785 struct fc_rport_libfc_priv
*rp
= rport
->dd_data
;
1786 struct bnx2fc_rport
*tgt
;
1787 struct bnx2fc_cmd
*io_req
;
1791 rval
= fc_remote_port_chkready(rport
);
1793 sc_cmd
->result
= rval
;
1794 sc_cmd
->scsi_done(sc_cmd
);
1798 if ((lport
->state
!= LPORT_ST_READY
) || !(lport
->link_up
)) {
1799 rc
= SCSI_MLQUEUE_HOST_BUSY
;
1803 /* rport and tgt are allocated together, so tgt should be non-NULL */
1804 tgt
= (struct bnx2fc_rport
*)&rp
[1];
1806 if (!test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
)) {
1808 * Session is not offloaded yet. Let SCSI-ml retry
1811 rc
= SCSI_MLQUEUE_TARGET_BUSY
;
1814 if (tgt
->retry_delay_timestamp
) {
1815 if (time_after(jiffies
, tgt
->retry_delay_timestamp
)) {
1816 tgt
->retry_delay_timestamp
= 0;
1818 /* If retry_delay timer is active, flow off the ML */
1819 rc
= SCSI_MLQUEUE_TARGET_BUSY
;
1824 spin_lock_bh(&tgt
->tgt_lock
);
1826 io_req
= bnx2fc_cmd_alloc(tgt
);
1828 rc
= SCSI_MLQUEUE_HOST_BUSY
;
1829 goto exit_qcmd_tgtlock
;
1831 io_req
->sc_cmd
= sc_cmd
;
1833 if (bnx2fc_post_io_req(tgt
, io_req
)) {
1834 printk(KERN_ERR PFX
"Unable to post io_req\n");
1835 rc
= SCSI_MLQUEUE_HOST_BUSY
;
1836 goto exit_qcmd_tgtlock
;
1840 spin_unlock_bh(&tgt
->tgt_lock
);
1845 void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd
*io_req
,
1846 struct fcoe_task_ctx_entry
*task
,
1849 struct fcoe_fcp_rsp_payload
*fcp_rsp
;
1850 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1851 struct scsi_cmnd
*sc_cmd
;
1852 struct Scsi_Host
*host
;
1855 /* scsi_cmd_cmpl is called with tgt lock held */
1857 if (test_and_set_bit(BNX2FC_FLAG_IO_COMPL
, &io_req
->req_flags
)) {
1858 /* we will not receive ABTS response for this IO */
1859 BNX2FC_IO_DBG(io_req
, "Timer context finished processing "
1863 /* Cancel the timeout_work, as we received IO completion */
1864 if (cancel_delayed_work(&io_req
->timeout_work
))
1865 kref_put(&io_req
->refcount
,
1866 bnx2fc_cmd_release
); /* drop timer hold */
1868 sc_cmd
= io_req
->sc_cmd
;
1869 if (sc_cmd
== NULL
) {
1870 printk(KERN_ERR PFX
"scsi_cmd_compl - sc_cmd is NULL\n");
1874 /* Fetch fcp_rsp from task context and perform cmd completion */
1875 fcp_rsp
= (struct fcoe_fcp_rsp_payload
*)
1876 &(task
->rxwr_only
.union_ctx
.comp_info
.fcp_rsp
.payload
);
1878 /* parse fcp_rsp and obtain sense data from RQ if available */
1879 bnx2fc_parse_fcp_rsp(io_req
, fcp_rsp
, num_rq
);
1881 host
= sc_cmd
->device
->host
;
1882 if (!sc_cmd
->SCp
.ptr
) {
1883 printk(KERN_ERR PFX
"SCp.ptr is NULL\n");
1887 if (io_req
->on_active_queue
) {
1888 list_del_init(&io_req
->link
);
1889 io_req
->on_active_queue
= 0;
1890 /* Move IO req to retire queue */
1891 list_add_tail(&io_req
->link
, &tgt
->io_retire_queue
);
1893 /* This should not happen, but could have been pulled
1894 * by bnx2fc_flush_active_ios(), or during a race
1895 * between command abort and (late) completion.
1897 BNX2FC_IO_DBG(io_req
, "xid not on active_cmd_queue\n");
1898 if (io_req
->wait_for_comp
)
1899 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
1900 &io_req
->req_flags
))
1901 complete(&io_req
->tm_done
);
1904 bnx2fc_unmap_sg_list(io_req
);
1905 io_req
->sc_cmd
= NULL
;
1907 switch (io_req
->fcp_status
) {
1909 if (io_req
->cdb_status
== 0) {
1910 /* Good IO completion */
1911 sc_cmd
->result
= DID_OK
<< 16;
1913 /* Transport status is good, SCSI status not good */
1914 BNX2FC_IO_DBG(io_req
, "scsi_cmpl: cdb_status = %d"
1915 " fcp_resid = 0x%x\n",
1916 io_req
->cdb_status
, io_req
->fcp_resid
);
1917 sc_cmd
->result
= (DID_OK
<< 16) | io_req
->cdb_status
;
1919 if (io_req
->cdb_status
== SAM_STAT_TASK_SET_FULL
||
1920 io_req
->cdb_status
== SAM_STAT_BUSY
) {
1921 /* Set the jiffies + retry_delay_timer * 100ms
1922 for the rport/tgt */
1923 tgt
->retry_delay_timestamp
= jiffies
+
1924 fcp_rsp
->retry_delay_timer
* HZ
/ 10;
1928 if (io_req
->fcp_resid
)
1929 scsi_set_resid(sc_cmd
, io_req
->fcp_resid
);
1932 printk(KERN_ERR PFX
"scsi_cmd_compl: fcp_status = %d\n",
1933 io_req
->fcp_status
);
1936 sc_cmd
->SCp
.ptr
= NULL
;
1937 sc_cmd
->scsi_done(sc_cmd
);
1938 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1941 int bnx2fc_post_io_req(struct bnx2fc_rport
*tgt
,
1942 struct bnx2fc_cmd
*io_req
)
1944 struct fcoe_task_ctx_entry
*task
;
1945 struct fcoe_task_ctx_entry
*task_page
;
1946 struct scsi_cmnd
*sc_cmd
= io_req
->sc_cmd
;
1947 struct fcoe_port
*port
= tgt
->port
;
1948 struct bnx2fc_interface
*interface
= port
->priv
;
1949 struct bnx2fc_hba
*hba
= interface
->hba
;
1950 struct fc_lport
*lport
= port
->lport
;
1951 struct fc_stats
*stats
;
1952 int task_idx
, index
;
1955 /* bnx2fc_post_io_req() is called with the tgt_lock held */
1957 /* Initialize rest of io_req fields */
1958 io_req
->cmd_type
= BNX2FC_SCSI_CMD
;
1959 io_req
->port
= port
;
1961 io_req
->data_xfer_len
= scsi_bufflen(sc_cmd
);
1962 sc_cmd
->SCp
.ptr
= (char *)io_req
;
1964 stats
= per_cpu_ptr(lport
->stats
, get_cpu());
1965 if (sc_cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
1966 io_req
->io_req_flags
= BNX2FC_READ
;
1967 stats
->InputRequests
++;
1968 stats
->InputBytes
+= io_req
->data_xfer_len
;
1969 } else if (sc_cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
1970 io_req
->io_req_flags
= BNX2FC_WRITE
;
1971 stats
->OutputRequests
++;
1972 stats
->OutputBytes
+= io_req
->data_xfer_len
;
1974 io_req
->io_req_flags
= 0;
1975 stats
->ControlRequests
++;
1981 /* Build buffer descriptor list for firmware from sg list */
1982 if (bnx2fc_build_bd_list_from_sg(io_req
)) {
1983 printk(KERN_ERR PFX
"BD list creation failed\n");
1984 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
1988 task_idx
= xid
/ BNX2FC_TASKS_PER_PAGE
;
1989 index
= xid
% BNX2FC_TASKS_PER_PAGE
;
1991 /* Initialize task context for this IO request */
1992 task_page
= (struct fcoe_task_ctx_entry
*) hba
->task_ctx
[task_idx
];
1993 task
= &(task_page
[index
]);
1994 bnx2fc_init_task(io_req
, task
);
1996 if (tgt
->flush_in_prog
) {
1997 printk(KERN_ERR PFX
"Flush in progress..Host Busy\n");
1998 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
2002 if (!test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
)) {
2003 printk(KERN_ERR PFX
"Session not ready...post_io\n");
2004 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
2009 if (tgt
->io_timeout
)
2010 bnx2fc_cmd_timer_set(io_req
, BNX2FC_IO_TIMEOUT
);
2011 /* Obtain free SQ entry */
2012 bnx2fc_add_2_sq(tgt
, xid
);
2014 /* Enqueue the io_req to active_cmd_queue */
2016 io_req
->on_active_queue
= 1;
2017 /* move io_req from pending_queue to active_queue */
2018 list_add_tail(&io_req
->link
, &tgt
->active_cmd_queue
);
2021 bnx2fc_ring_doorbell(tgt
);