1 /* bnx2fc_tgt.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * Handles operations such as session offload/upload etc, and manages
3 * session resources such as connection id and qp resources.
5 * Copyright (c) 2008 - 2011 Broadcom 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)
15 static void bnx2fc_upld_timer(unsigned long data
);
16 static void bnx2fc_ofld_timer(unsigned long data
);
17 static int bnx2fc_init_tgt(struct bnx2fc_rport
*tgt
,
18 struct fcoe_port
*port
,
19 struct fc_rport_priv
*rdata
);
20 static u32
bnx2fc_alloc_conn_id(struct bnx2fc_hba
*hba
,
21 struct bnx2fc_rport
*tgt
);
22 static int bnx2fc_alloc_session_resc(struct bnx2fc_hba
*hba
,
23 struct bnx2fc_rport
*tgt
);
24 static void bnx2fc_free_session_resc(struct bnx2fc_hba
*hba
,
25 struct bnx2fc_rport
*tgt
);
26 static void bnx2fc_free_conn_id(struct bnx2fc_hba
*hba
, u32 conn_id
);
28 static void bnx2fc_upld_timer(unsigned long data
)
31 struct bnx2fc_rport
*tgt
= (struct bnx2fc_rport
*)data
;
33 BNX2FC_TGT_DBG(tgt
, "upld_timer - Upload compl not received!!\n");
34 /* fake upload completion */
35 clear_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
);
36 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
37 wake_up_interruptible(&tgt
->upld_wait
);
40 static void bnx2fc_ofld_timer(unsigned long data
)
43 struct bnx2fc_rport
*tgt
= (struct bnx2fc_rport
*)data
;
45 BNX2FC_TGT_DBG(tgt
, "entered bnx2fc_ofld_timer\n");
46 /* NOTE: This function should never be called, as
47 * offload should never timeout
50 * If the timer has expired, this session is dead
51 * Clear offloaded flag and logout of this device.
52 * Since OFFLOADED flag is cleared, this case
53 * will be considered as offload error and the
54 * port will be logged off, and conn_id, session
55 * resources are freed up in bnx2fc_offload_session
57 clear_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
);
58 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL
, &tgt
->flags
);
59 wake_up_interruptible(&tgt
->ofld_wait
);
62 static void bnx2fc_offload_session(struct fcoe_port
*port
,
63 struct bnx2fc_rport
*tgt
,
64 struct fc_rport_priv
*rdata
)
66 struct fc_lport
*lport
= rdata
->local_port
;
67 struct fc_rport
*rport
= rdata
->rport
;
68 struct bnx2fc_interface
*interface
= port
->priv
;
69 struct bnx2fc_hba
*hba
= interface
->hba
;
73 /* Initialize bnx2fc_rport */
74 /* NOTE: tgt is already bzero'd */
75 rval
= bnx2fc_init_tgt(tgt
, port
, rdata
);
77 printk(KERN_ERR PFX
"Failed to allocate conn id for "
78 "port_id (%6x)\n", rport
->port_id
);
82 /* Allocate session resources */
83 rval
= bnx2fc_alloc_session_resc(hba
, tgt
);
85 printk(KERN_ERR PFX
"Failed to allocate resources\n");
90 * Initialize FCoE session offload process.
91 * Upon completion of offload process add
92 * rport to list of rports
95 clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL
, &tgt
->flags
);
96 rval
= bnx2fc_send_session_ofld_req(port
, tgt
);
98 printk(KERN_ERR PFX
"ofld_req failed\n");
103 * wait for the session is offloaded and enabled. 3 Secs
104 * should be ample time for this process to complete.
106 setup_timer(&tgt
->ofld_timer
, bnx2fc_ofld_timer
, (unsigned long)tgt
);
107 mod_timer(&tgt
->ofld_timer
, jiffies
+ BNX2FC_FW_TIMEOUT
);
109 wait_event_interruptible(tgt
->ofld_wait
,
111 BNX2FC_FLAG_OFLD_REQ_CMPL
,
113 if (signal_pending(current
))
114 flush_signals(current
);
116 del_timer_sync(&tgt
->ofld_timer
);
118 if (!(test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
))) {
119 if (test_and_clear_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE
,
121 BNX2FC_TGT_DBG(tgt
, "ctx_alloc_failure, "
122 "retry ofld..%d\n", i
++);
123 msleep_interruptible(1000);
132 if (bnx2fc_map_doorbell(tgt
)) {
133 printk(KERN_ERR PFX
"map doorbell failed - no mem\n");
134 /* upload will take care of cleaning up sess resc */
135 lport
->tt
.rport_logoff(rdata
);
142 /* couldn't offload the session. log off from this rport */
143 BNX2FC_TGT_DBG(tgt
, "bnx2fc_offload_session - offload error\n");
144 /* Free session resources */
145 bnx2fc_free_session_resc(hba
, tgt
);
147 if (tgt
->fcoe_conn_id
!= -1)
148 bnx2fc_free_conn_id(hba
, tgt
->fcoe_conn_id
);
149 lport
->tt
.rport_logoff(rdata
);
152 void bnx2fc_flush_active_ios(struct bnx2fc_rport
*tgt
)
154 struct bnx2fc_cmd
*io_req
;
155 struct list_head
*list
;
156 struct list_head
*tmp
;
159 BNX2FC_TGT_DBG(tgt
, "Entered flush_active_ios - %d\n",
160 tgt
->num_active_ios
.counter
);
162 spin_lock_bh(&tgt
->tgt_lock
);
163 tgt
->flush_in_prog
= 1;
165 list_for_each_safe(list
, tmp
, &tgt
->active_cmd_queue
) {
167 io_req
= (struct bnx2fc_cmd
*)list
;
168 list_del_init(&io_req
->link
);
169 io_req
->on_active_queue
= 0;
170 BNX2FC_IO_DBG(io_req
, "cmd_queue cleanup\n");
172 if (cancel_delayed_work(&io_req
->timeout_work
)) {
173 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
174 &io_req
->req_flags
)) {
175 /* Handle eh_abort timeout */
176 BNX2FC_IO_DBG(io_req
, "eh_abort for IO "
178 complete(&io_req
->tm_done
);
180 kref_put(&io_req
->refcount
,
181 bnx2fc_cmd_release
); /* drop timer hold */
184 set_bit(BNX2FC_FLAG_IO_COMPL
, &io_req
->req_flags
);
185 set_bit(BNX2FC_FLAG_IO_CLEANUP
, &io_req
->req_flags
);
186 rc
= bnx2fc_initiate_cleanup(io_req
);
190 list_for_each_safe(list
, tmp
, &tgt
->els_queue
) {
192 io_req
= (struct bnx2fc_cmd
*)list
;
193 list_del_init(&io_req
->link
);
194 io_req
->on_active_queue
= 0;
196 BNX2FC_IO_DBG(io_req
, "els_queue cleanup\n");
198 if (cancel_delayed_work(&io_req
->timeout_work
))
199 kref_put(&io_req
->refcount
,
200 bnx2fc_cmd_release
); /* drop timer hold */
202 if ((io_req
->cb_func
) && (io_req
->cb_arg
)) {
203 io_req
->cb_func(io_req
->cb_arg
);
204 io_req
->cb_arg
= NULL
;
207 rc
= bnx2fc_initiate_cleanup(io_req
);
211 list_for_each_safe(list
, tmp
, &tgt
->io_retire_queue
) {
213 io_req
= (struct bnx2fc_cmd
*)list
;
214 list_del_init(&io_req
->link
);
216 BNX2FC_IO_DBG(io_req
, "retire_queue flush\n");
218 if (cancel_delayed_work(&io_req
->timeout_work
))
219 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
221 clear_bit(BNX2FC_FLAG_ISSUE_RRQ
, &io_req
->req_flags
);
224 BNX2FC_TGT_DBG(tgt
, "IOs flushed = %d\n", i
);
226 spin_unlock_bh(&tgt
->tgt_lock
);
227 /* wait for active_ios to go to 0 */
228 while ((tgt
->num_active_ios
.counter
!= 0) && (i
++ < BNX2FC_WAIT_CNT
))
230 if (tgt
->num_active_ios
.counter
!= 0)
231 printk(KERN_ERR PFX
"CLEANUP on port 0x%x:"
232 " active_ios = %d\n",
233 tgt
->rdata
->ids
.port_id
, tgt
->num_active_ios
.counter
);
234 spin_lock_bh(&tgt
->tgt_lock
);
235 tgt
->flush_in_prog
= 0;
236 spin_unlock_bh(&tgt
->tgt_lock
);
239 static void bnx2fc_upload_session(struct fcoe_port
*port
,
240 struct bnx2fc_rport
*tgt
)
242 struct bnx2fc_interface
*interface
= port
->priv
;
243 struct bnx2fc_hba
*hba
= interface
->hba
;
245 BNX2FC_TGT_DBG(tgt
, "upload_session: active_ios = %d\n",
246 tgt
->num_active_ios
.counter
);
249 * Called with hba->hba_mutex held.
250 * This is a blocking call
252 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
253 bnx2fc_send_session_disable_req(port
, tgt
);
256 * wait for upload to complete. 3 Secs
257 * should be sufficient time for this process to complete.
259 setup_timer(&tgt
->upld_timer
, bnx2fc_upld_timer
, (unsigned long)tgt
);
260 mod_timer(&tgt
->upld_timer
, jiffies
+ BNX2FC_FW_TIMEOUT
);
262 BNX2FC_TGT_DBG(tgt
, "waiting for disable compl\n");
263 wait_event_interruptible(tgt
->upld_wait
,
265 BNX2FC_FLAG_UPLD_REQ_COMPL
,
268 if (signal_pending(current
))
269 flush_signals(current
);
271 del_timer_sync(&tgt
->upld_timer
);
274 * traverse thru the active_q and tmf_q and cleanup
277 BNX2FC_TGT_DBG(tgt
, "flush/upload - disable wait flags = 0x%lx\n",
279 bnx2fc_flush_active_ios(tgt
);
281 /* Issue destroy KWQE */
282 if (test_bit(BNX2FC_FLAG_DISABLED
, &tgt
->flags
)) {
283 BNX2FC_TGT_DBG(tgt
, "send destroy req\n");
284 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
285 bnx2fc_send_session_destroy_req(hba
, tgt
);
287 /* wait for destroy to complete */
288 setup_timer(&tgt
->upld_timer
,
289 bnx2fc_upld_timer
, (unsigned long)tgt
);
290 mod_timer(&tgt
->upld_timer
, jiffies
+ BNX2FC_FW_TIMEOUT
);
292 wait_event_interruptible(tgt
->upld_wait
,
294 BNX2FC_FLAG_UPLD_REQ_COMPL
,
297 if (!(test_bit(BNX2FC_FLAG_DESTROYED
, &tgt
->flags
)))
298 printk(KERN_ERR PFX
"ERROR!! destroy timed out\n");
300 BNX2FC_TGT_DBG(tgt
, "destroy wait complete flags = 0x%lx\n",
302 if (signal_pending(current
))
303 flush_signals(current
);
305 del_timer_sync(&tgt
->upld_timer
);
308 printk(KERN_ERR PFX
"ERROR!! DISABLE req timed out, destroy"
309 " not sent to FW\n");
311 /* Free session resources */
312 bnx2fc_free_session_resc(hba
, tgt
);
313 bnx2fc_free_conn_id(hba
, tgt
->fcoe_conn_id
);
316 static int bnx2fc_init_tgt(struct bnx2fc_rport
*tgt
,
317 struct fcoe_port
*port
,
318 struct fc_rport_priv
*rdata
)
321 struct fc_rport
*rport
= rdata
->rport
;
322 struct bnx2fc_interface
*interface
= port
->priv
;
323 struct bnx2fc_hba
*hba
= interface
->hba
;
324 struct b577xx_doorbell_set_prod
*sq_db
= &tgt
->sq_db
;
325 struct b577xx_fcoe_rx_doorbell
*rx_db
= &tgt
->rx_db
;
331 if (hba
->num_ofld_sess
>= BNX2FC_NUM_MAX_SESS
) {
332 BNX2FC_TGT_DBG(tgt
, "exceeded max sessions. logoff this tgt\n");
333 tgt
->fcoe_conn_id
= -1;
337 tgt
->fcoe_conn_id
= bnx2fc_alloc_conn_id(hba
, tgt
);
338 if (tgt
->fcoe_conn_id
== -1)
341 BNX2FC_TGT_DBG(tgt
, "init_tgt - conn_id = 0x%x\n", tgt
->fcoe_conn_id
);
343 tgt
->max_sqes
= BNX2FC_SQ_WQES_MAX
;
344 tgt
->max_rqes
= BNX2FC_RQ_WQES_MAX
;
345 tgt
->max_cqes
= BNX2FC_CQ_WQES_MAX
;
346 atomic_set(&tgt
->free_sqes
, BNX2FC_SQ_WQES_MAX
);
348 /* Initialize the toggle bit */
349 tgt
->sq_curr_toggle_bit
= 1;
350 tgt
->cq_curr_toggle_bit
= 1;
351 tgt
->sq_prod_idx
= 0;
352 tgt
->cq_cons_idx
= 0;
353 tgt
->rq_prod_idx
= 0x8000;
354 tgt
->rq_cons_idx
= 0;
355 atomic_set(&tgt
->num_active_ios
, 0);
357 if (rdata
->flags
& FC_RP_FLAGS_RETRY
) {
358 tgt
->dev_type
= TYPE_TAPE
;
359 tgt
->io_timeout
= 0; /* use default ULP timeout */
361 tgt
->dev_type
= TYPE_DISK
;
362 tgt
->io_timeout
= BNX2FC_IO_TIMEOUT
;
365 /* initialize sq doorbell */
366 sq_db
->header
.header
= B577XX_DOORBELL_HDR_DB_TYPE
;
367 sq_db
->header
.header
|= B577XX_FCOE_CONNECTION_TYPE
<<
368 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT
;
369 /* initialize rx doorbell */
370 rx_db
->hdr
.header
= ((0x1 << B577XX_DOORBELL_HDR_RX_SHIFT
) |
371 (0x1 << B577XX_DOORBELL_HDR_DB_TYPE_SHIFT
) |
372 (B577XX_FCOE_CONNECTION_TYPE
<<
373 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT
));
374 rx_db
->params
= (0x2 << B577XX_FCOE_RX_DOORBELL_NEGATIVE_ARM_SHIFT
) |
375 (0x3 << B577XX_FCOE_RX_DOORBELL_OPCODE_SHIFT
);
377 spin_lock_init(&tgt
->tgt_lock
);
378 spin_lock_init(&tgt
->cq_lock
);
380 /* Initialize active_cmd_queue list */
381 INIT_LIST_HEAD(&tgt
->active_cmd_queue
);
383 /* Initialize IO retire queue */
384 INIT_LIST_HEAD(&tgt
->io_retire_queue
);
386 INIT_LIST_HEAD(&tgt
->els_queue
);
388 /* Initialize active_tm_queue list */
389 INIT_LIST_HEAD(&tgt
->active_tm_queue
);
391 init_waitqueue_head(&tgt
->ofld_wait
);
392 init_waitqueue_head(&tgt
->upld_wait
);
398 * This event_callback is called after successful completion of libfc
399 * initiated target login. bnx2fc can proceed with initiating the session
402 void bnx2fc_rport_event_handler(struct fc_lport
*lport
,
403 struct fc_rport_priv
*rdata
,
404 enum fc_rport_event event
)
406 struct fcoe_port
*port
= lport_priv(lport
);
407 struct bnx2fc_interface
*interface
= port
->priv
;
408 struct bnx2fc_hba
*hba
= interface
->hba
;
409 struct fc_rport
*rport
= rdata
->rport
;
410 struct fc_rport_libfc_priv
*rp
;
411 struct bnx2fc_rport
*tgt
;
414 BNX2FC_HBA_DBG(lport
, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
415 event
, rdata
->ids
.port_id
);
419 printk(KERN_ERR PFX
"rport is NULL: ERROR!\n");
424 if (rport
->port_id
== FC_FID_DIR_SERV
) {
426 * bnx2fc_rport structure doesn't exist for
428 * We should not come here, as lport will
429 * take care of fabric login
431 printk(KERN_ERR PFX
"%x - rport_event_handler ERROR\n",
436 if (rdata
->spp_type
!= FC_TYPE_FCP
) {
437 BNX2FC_HBA_DBG(lport
, "not FCP type target."
438 " not offloading\n");
441 if (!(rdata
->ids
.roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
442 BNX2FC_HBA_DBG(lport
, "not FCP_TARGET"
443 " not offloading\n");
448 * Offlaod process is protected with hba mutex.
449 * Use the same mutex_lock for upload process too
451 mutex_lock(&hba
->hba_mutex
);
452 tgt
= (struct bnx2fc_rport
*)&rp
[1];
454 /* This can happen when ADISC finds the same target */
455 if (test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
)) {
456 BNX2FC_TGT_DBG(tgt
, "already offloaded\n");
457 mutex_unlock(&hba
->hba_mutex
);
462 * Offload the session. This is a blocking call, and will
463 * wait until the session is offloaded.
465 bnx2fc_offload_session(port
, tgt
, rdata
);
467 BNX2FC_TGT_DBG(tgt
, "OFFLOAD num_ofld_sess = %d\n",
470 if (test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
)) {
472 * Session is offloaded and enabled. Map
473 * doorbell register for this target
475 BNX2FC_TGT_DBG(tgt
, "sess offloaded\n");
476 /* This counter is protected with hba mutex */
477 hba
->num_ofld_sess
++;
479 set_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
);
482 * Offload or enable would have failed.
483 * In offload/enable completion path, the
484 * rport would have already been removed
486 BNX2FC_TGT_DBG(tgt
, "Port is being logged off as "
487 "offloaded flag not set\n");
489 mutex_unlock(&hba
->hba_mutex
);
492 case RPORT_EV_FAILED
:
494 port_id
= rdata
->ids
.port_id
;
495 if (port_id
== FC_FID_DIR_SERV
)
499 printk(KERN_INFO PFX
"%x - rport not created Yet!!\n",
504 mutex_lock(&hba
->hba_mutex
);
506 * Perform session upload. Note that rdata->peers is already
507 * removed from disc->rports list before we get this event.
509 tgt
= (struct bnx2fc_rport
*)&rp
[1];
511 if (!(test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
))) {
512 mutex_unlock(&hba
->hba_mutex
);
515 clear_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
);
517 bnx2fc_upload_session(port
, tgt
);
518 hba
->num_ofld_sess
--;
519 BNX2FC_TGT_DBG(tgt
, "UPLOAD num_ofld_sess = %d\n",
522 * Try to wake up the linkdown wait thread. If num_ofld_sess
523 * is 0, the waiting therad wakes up
525 if ((hba
->wait_for_link_down
) &&
526 (hba
->num_ofld_sess
== 0)) {
527 wake_up_interruptible(&hba
->shutdown_wait
);
529 if (test_bit(BNX2FC_FLAG_EXPL_LOGO
, &tgt
->flags
)) {
530 printk(KERN_ERR PFX
"Relogin to the tgt\n");
531 mutex_lock(&lport
->disc
.disc_mutex
);
532 lport
->tt
.rport_login(rdata
);
533 mutex_unlock(&lport
->disc
.disc_mutex
);
535 mutex_unlock(&hba
->hba_mutex
);
545 * bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
547 * @port: fcoe_port struct to lookup the target port on
548 * @port_id: The remote port ID to look up
550 struct bnx2fc_rport
*bnx2fc_tgt_lookup(struct fcoe_port
*port
,
553 struct bnx2fc_interface
*interface
= port
->priv
;
554 struct bnx2fc_hba
*hba
= interface
->hba
;
555 struct bnx2fc_rport
*tgt
;
556 struct fc_rport_priv
*rdata
;
559 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
560 tgt
= hba
->tgt_ofld_list
[i
];
561 if ((tgt
) && (tgt
->port
== port
)) {
563 if (rdata
->ids
.port_id
== port_id
) {
564 if (rdata
->rp_state
!= RPORT_ST_DELETE
) {
565 BNX2FC_TGT_DBG(tgt
, "rport "
569 BNX2FC_TGT_DBG(tgt
, "rport 0x%x "
570 "is in DELETED state\n",
582 * bnx2fc_alloc_conn_id - allocates FCOE Connection id
584 * @hba: pointer to adapter structure
585 * @tgt: pointer to bnx2fc_rport structure
587 static u32
bnx2fc_alloc_conn_id(struct bnx2fc_hba
*hba
,
588 struct bnx2fc_rport
*tgt
)
592 /* called with hba mutex held */
595 * tgt_ofld_list access is synchronized using
596 * both hba mutex and hba lock. Atleast hba mutex or
597 * hba lock needs to be held for read access.
600 spin_lock_bh(&hba
->hba_lock
);
601 next
= hba
->next_conn_id
;
602 conn_id
= hba
->next_conn_id
++;
603 if (hba
->next_conn_id
== BNX2FC_NUM_MAX_SESS
)
604 hba
->next_conn_id
= 0;
606 while (hba
->tgt_ofld_list
[conn_id
] != NULL
) {
608 if (conn_id
== BNX2FC_NUM_MAX_SESS
)
611 if (conn_id
== next
) {
612 /* No free conn_ids are available */
613 spin_unlock_bh(&hba
->hba_lock
);
617 hba
->tgt_ofld_list
[conn_id
] = tgt
;
618 tgt
->fcoe_conn_id
= conn_id
;
619 spin_unlock_bh(&hba
->hba_lock
);
623 static void bnx2fc_free_conn_id(struct bnx2fc_hba
*hba
, u32 conn_id
)
625 /* called with hba mutex held */
626 spin_lock_bh(&hba
->hba_lock
);
627 hba
->tgt_ofld_list
[conn_id
] = NULL
;
628 spin_unlock_bh(&hba
->hba_lock
);
632 *bnx2fc_alloc_session_resc - Allocate qp resources for the session
635 static int bnx2fc_alloc_session_resc(struct bnx2fc_hba
*hba
,
636 struct bnx2fc_rport
*tgt
)
642 /* Allocate and map SQ */
643 tgt
->sq_mem_size
= tgt
->max_sqes
* BNX2FC_SQ_WQE_SIZE
;
644 tgt
->sq_mem_size
= (tgt
->sq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
646 tgt
->sq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->sq_mem_size
,
647 &tgt
->sq_dma
, GFP_KERNEL
);
649 printk(KERN_ERR PFX
"unable to allocate SQ memory %d\n",
651 goto mem_alloc_failure
;
653 memset(tgt
->sq
, 0, tgt
->sq_mem_size
);
655 /* Allocate and map CQ */
656 tgt
->cq_mem_size
= tgt
->max_cqes
* BNX2FC_CQ_WQE_SIZE
;
657 tgt
->cq_mem_size
= (tgt
->cq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
659 tgt
->cq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->cq_mem_size
,
660 &tgt
->cq_dma
, GFP_KERNEL
);
662 printk(KERN_ERR PFX
"unable to allocate CQ memory %d\n",
664 goto mem_alloc_failure
;
666 memset(tgt
->cq
, 0, tgt
->cq_mem_size
);
668 /* Allocate and map RQ and RQ PBL */
669 tgt
->rq_mem_size
= tgt
->max_rqes
* BNX2FC_RQ_WQE_SIZE
;
670 tgt
->rq_mem_size
= (tgt
->rq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
672 tgt
->rq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->rq_mem_size
,
673 &tgt
->rq_dma
, GFP_KERNEL
);
675 printk(KERN_ERR PFX
"unable to allocate RQ memory %d\n",
677 goto mem_alloc_failure
;
679 memset(tgt
->rq
, 0, tgt
->rq_mem_size
);
681 tgt
->rq_pbl_size
= (tgt
->rq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
682 tgt
->rq_pbl_size
= (tgt
->rq_pbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
684 tgt
->rq_pbl
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->rq_pbl_size
,
685 &tgt
->rq_pbl_dma
, GFP_KERNEL
);
687 printk(KERN_ERR PFX
"unable to allocate RQ PBL %d\n",
689 goto mem_alloc_failure
;
692 memset(tgt
->rq_pbl
, 0, tgt
->rq_pbl_size
);
693 num_pages
= tgt
->rq_mem_size
/ PAGE_SIZE
;
695 pbl
= (u32
*)tgt
->rq_pbl
;
697 while (num_pages
--) {
700 *pbl
= (u32
)((u64
)page
>> 32);
705 /* Allocate and map XFERQ */
706 tgt
->xferq_mem_size
= tgt
->max_sqes
* BNX2FC_XFERQ_WQE_SIZE
;
707 tgt
->xferq_mem_size
= (tgt
->xferq_mem_size
+ (PAGE_SIZE
- 1)) &
710 tgt
->xferq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->xferq_mem_size
,
711 &tgt
->xferq_dma
, GFP_KERNEL
);
713 printk(KERN_ERR PFX
"unable to allocate XFERQ %d\n",
714 tgt
->xferq_mem_size
);
715 goto mem_alloc_failure
;
717 memset(tgt
->xferq
, 0, tgt
->xferq_mem_size
);
719 /* Allocate and map CONFQ & CONFQ PBL */
720 tgt
->confq_mem_size
= tgt
->max_sqes
* BNX2FC_CONFQ_WQE_SIZE
;
721 tgt
->confq_mem_size
= (tgt
->confq_mem_size
+ (PAGE_SIZE
- 1)) &
724 tgt
->confq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->confq_mem_size
,
725 &tgt
->confq_dma
, GFP_KERNEL
);
727 printk(KERN_ERR PFX
"unable to allocate CONFQ %d\n",
728 tgt
->confq_mem_size
);
729 goto mem_alloc_failure
;
731 memset(tgt
->confq
, 0, tgt
->confq_mem_size
);
733 tgt
->confq_pbl_size
=
734 (tgt
->confq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
735 tgt
->confq_pbl_size
=
736 (tgt
->confq_pbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
738 tgt
->confq_pbl
= dma_alloc_coherent(&hba
->pcidev
->dev
,
740 &tgt
->confq_pbl_dma
, GFP_KERNEL
);
741 if (!tgt
->confq_pbl
) {
742 printk(KERN_ERR PFX
"unable to allocate CONFQ PBL %d\n",
743 tgt
->confq_pbl_size
);
744 goto mem_alloc_failure
;
747 memset(tgt
->confq_pbl
, 0, tgt
->confq_pbl_size
);
748 num_pages
= tgt
->confq_mem_size
/ PAGE_SIZE
;
749 page
= tgt
->confq_dma
;
750 pbl
= (u32
*)tgt
->confq_pbl
;
752 while (num_pages
--) {
755 *pbl
= (u32
)((u64
)page
>> 32);
760 /* Allocate and map ConnDB */
761 tgt
->conn_db_mem_size
= sizeof(struct fcoe_conn_db
);
763 tgt
->conn_db
= dma_alloc_coherent(&hba
->pcidev
->dev
,
764 tgt
->conn_db_mem_size
,
765 &tgt
->conn_db_dma
, GFP_KERNEL
);
767 printk(KERN_ERR PFX
"unable to allocate conn_db %d\n",
768 tgt
->conn_db_mem_size
);
769 goto mem_alloc_failure
;
771 memset(tgt
->conn_db
, 0, tgt
->conn_db_mem_size
);
774 /* Allocate and map LCQ */
775 tgt
->lcq_mem_size
= (tgt
->max_sqes
+ 8) * BNX2FC_SQ_WQE_SIZE
;
776 tgt
->lcq_mem_size
= (tgt
->lcq_mem_size
+ (PAGE_SIZE
- 1)) &
779 tgt
->lcq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->lcq_mem_size
,
780 &tgt
->lcq_dma
, GFP_KERNEL
);
783 printk(KERN_ERR PFX
"unable to allocate lcq %d\n",
785 goto mem_alloc_failure
;
787 memset(tgt
->lcq
, 0, tgt
->lcq_mem_size
);
789 tgt
->conn_db
->rq_prod
= 0x8000;
798 * bnx2i_free_session_resc - free qp resources for the session
800 * @hba: adapter structure pointer
801 * @tgt: bnx2fc_rport structure pointer
803 * Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
805 static void bnx2fc_free_session_resc(struct bnx2fc_hba
*hba
,
806 struct bnx2fc_rport
*tgt
)
808 void __iomem
*ctx_base_ptr
;
810 BNX2FC_TGT_DBG(tgt
, "Freeing up session resources\n");
812 spin_lock_bh(&tgt
->cq_lock
);
813 ctx_base_ptr
= tgt
->ctx_base
;
814 tgt
->ctx_base
= NULL
;
818 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->lcq_mem_size
,
819 tgt
->lcq
, tgt
->lcq_dma
);
824 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->conn_db_mem_size
,
825 tgt
->conn_db
, tgt
->conn_db_dma
);
828 /* Free confq and confq pbl */
829 if (tgt
->confq_pbl
) {
830 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->confq_pbl_size
,
831 tgt
->confq_pbl
, tgt
->confq_pbl_dma
);
832 tgt
->confq_pbl
= NULL
;
835 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->confq_mem_size
,
836 tgt
->confq
, tgt
->confq_dma
);
841 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->xferq_mem_size
,
842 tgt
->xferq
, tgt
->xferq_dma
);
845 /* Free RQ PBL and RQ */
847 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->rq_pbl_size
,
848 tgt
->rq_pbl
, tgt
->rq_pbl_dma
);
852 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->rq_mem_size
,
853 tgt
->rq
, tgt
->rq_dma
);
858 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->cq_mem_size
,
859 tgt
->cq
, tgt
->cq_dma
);
864 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->sq_mem_size
,
865 tgt
->sq
, tgt
->sq_dma
);
868 spin_unlock_bh(&tgt
->cq_lock
);
871 iounmap(ctx_base_ptr
);