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
);
140 /* couldn't offload the session. log off from this rport */
141 BNX2FC_TGT_DBG(tgt
, "bnx2fc_offload_session - offload error\n");
142 /* Free session resources */
143 bnx2fc_free_session_resc(hba
, tgt
);
145 if (tgt
->fcoe_conn_id
!= -1)
146 bnx2fc_free_conn_id(hba
, tgt
->fcoe_conn_id
);
147 lport
->tt
.rport_logoff(rdata
);
150 void bnx2fc_flush_active_ios(struct bnx2fc_rport
*tgt
)
152 struct bnx2fc_cmd
*io_req
;
153 struct bnx2fc_cmd
*tmp
;
156 BNX2FC_TGT_DBG(tgt
, "Entered flush_active_ios - %d\n",
157 tgt
->num_active_ios
.counter
);
159 spin_lock_bh(&tgt
->tgt_lock
);
160 tgt
->flush_in_prog
= 1;
162 list_for_each_entry_safe(io_req
, tmp
, &tgt
->active_cmd_queue
, link
) {
164 list_del_init(&io_req
->link
);
165 io_req
->on_active_queue
= 0;
166 BNX2FC_IO_DBG(io_req
, "cmd_queue cleanup\n");
168 if (cancel_delayed_work(&io_req
->timeout_work
)) {
169 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
170 &io_req
->req_flags
)) {
171 /* Handle eh_abort timeout */
172 BNX2FC_IO_DBG(io_req
, "eh_abort for IO "
174 complete(&io_req
->tm_done
);
176 kref_put(&io_req
->refcount
,
177 bnx2fc_cmd_release
); /* drop timer hold */
180 set_bit(BNX2FC_FLAG_IO_COMPL
, &io_req
->req_flags
);
181 set_bit(BNX2FC_FLAG_IO_CLEANUP
, &io_req
->req_flags
);
183 /* Do not issue cleanup when disable request failed */
184 if (test_bit(BNX2FC_FLAG_DISABLE_FAILED
, &tgt
->flags
))
185 bnx2fc_process_cleanup_compl(io_req
, io_req
->task
, 0);
187 rc
= bnx2fc_initiate_cleanup(io_req
);
192 list_for_each_entry_safe(io_req
, tmp
, &tgt
->active_tm_queue
, link
) {
194 list_del_init(&io_req
->link
);
195 io_req
->on_tmf_queue
= 0;
196 BNX2FC_IO_DBG(io_req
, "tm_queue cleanup\n");
197 if (io_req
->wait_for_comp
)
198 complete(&io_req
->tm_done
);
201 list_for_each_entry_safe(io_req
, tmp
, &tgt
->els_queue
, link
) {
203 list_del_init(&io_req
->link
);
204 io_req
->on_active_queue
= 0;
206 BNX2FC_IO_DBG(io_req
, "els_queue cleanup\n");
208 if (cancel_delayed_work(&io_req
->timeout_work
))
209 kref_put(&io_req
->refcount
,
210 bnx2fc_cmd_release
); /* drop timer hold */
212 if ((io_req
->cb_func
) && (io_req
->cb_arg
)) {
213 io_req
->cb_func(io_req
->cb_arg
);
214 io_req
->cb_arg
= NULL
;
217 /* Do not issue cleanup when disable request failed */
218 if (test_bit(BNX2FC_FLAG_DISABLE_FAILED
, &tgt
->flags
))
219 bnx2fc_process_cleanup_compl(io_req
, io_req
->task
, 0);
221 rc
= bnx2fc_initiate_cleanup(io_req
);
226 list_for_each_entry_safe(io_req
, tmp
, &tgt
->io_retire_queue
, link
) {
228 list_del_init(&io_req
->link
);
230 BNX2FC_IO_DBG(io_req
, "retire_queue flush\n");
232 if (cancel_delayed_work(&io_req
->timeout_work
)) {
233 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
234 &io_req
->req_flags
)) {
235 /* Handle eh_abort timeout */
236 BNX2FC_IO_DBG(io_req
, "eh_abort for IO "
238 if (io_req
->wait_for_comp
)
239 complete(&io_req
->tm_done
);
241 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
244 clear_bit(BNX2FC_FLAG_ISSUE_RRQ
, &io_req
->req_flags
);
247 BNX2FC_TGT_DBG(tgt
, "IOs flushed = %d\n", i
);
249 spin_unlock_bh(&tgt
->tgt_lock
);
250 /* wait for active_ios to go to 0 */
251 while ((tgt
->num_active_ios
.counter
!= 0) && (i
++ < BNX2FC_WAIT_CNT
))
253 if (tgt
->num_active_ios
.counter
!= 0)
254 printk(KERN_ERR PFX
"CLEANUP on port 0x%x:"
255 " active_ios = %d\n",
256 tgt
->rdata
->ids
.port_id
, tgt
->num_active_ios
.counter
);
257 spin_lock_bh(&tgt
->tgt_lock
);
258 tgt
->flush_in_prog
= 0;
259 spin_unlock_bh(&tgt
->tgt_lock
);
262 static void bnx2fc_upload_session(struct fcoe_port
*port
,
263 struct bnx2fc_rport
*tgt
)
265 struct bnx2fc_interface
*interface
= port
->priv
;
266 struct bnx2fc_hba
*hba
= interface
->hba
;
268 BNX2FC_TGT_DBG(tgt
, "upload_session: active_ios = %d\n",
269 tgt
->num_active_ios
.counter
);
272 * Called with hba->hba_mutex held.
273 * This is a blocking call
275 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
276 bnx2fc_send_session_disable_req(port
, tgt
);
279 * wait for upload to complete. 3 Secs
280 * should be sufficient time for this process to complete.
282 setup_timer(&tgt
->upld_timer
, bnx2fc_upld_timer
, (unsigned long)tgt
);
283 mod_timer(&tgt
->upld_timer
, jiffies
+ BNX2FC_FW_TIMEOUT
);
285 BNX2FC_TGT_DBG(tgt
, "waiting for disable compl\n");
286 wait_event_interruptible(tgt
->upld_wait
,
288 BNX2FC_FLAG_UPLD_REQ_COMPL
,
291 if (signal_pending(current
))
292 flush_signals(current
);
294 del_timer_sync(&tgt
->upld_timer
);
297 * traverse thru the active_q and tmf_q and cleanup
300 BNX2FC_TGT_DBG(tgt
, "flush/upload - disable wait flags = 0x%lx\n",
302 bnx2fc_flush_active_ios(tgt
);
304 /* Issue destroy KWQE */
305 if (test_bit(BNX2FC_FLAG_DISABLED
, &tgt
->flags
)) {
306 BNX2FC_TGT_DBG(tgt
, "send destroy req\n");
307 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
308 bnx2fc_send_session_destroy_req(hba
, tgt
);
310 /* wait for destroy to complete */
311 setup_timer(&tgt
->upld_timer
,
312 bnx2fc_upld_timer
, (unsigned long)tgt
);
313 mod_timer(&tgt
->upld_timer
, jiffies
+ BNX2FC_FW_TIMEOUT
);
315 wait_event_interruptible(tgt
->upld_wait
,
317 BNX2FC_FLAG_UPLD_REQ_COMPL
,
320 if (!(test_bit(BNX2FC_FLAG_DESTROYED
, &tgt
->flags
)))
321 printk(KERN_ERR PFX
"ERROR!! destroy timed out\n");
323 BNX2FC_TGT_DBG(tgt
, "destroy wait complete flags = 0x%lx\n",
325 if (signal_pending(current
))
326 flush_signals(current
);
328 del_timer_sync(&tgt
->upld_timer
);
330 } else if (test_bit(BNX2FC_FLAG_DISABLE_FAILED
, &tgt
->flags
)) {
331 printk(KERN_ERR PFX
"ERROR!! DISABLE req failed, destroy"
332 " not sent to FW\n");
334 printk(KERN_ERR PFX
"ERROR!! DISABLE req timed out, destroy"
335 " not sent to FW\n");
338 /* Free session resources */
339 bnx2fc_free_session_resc(hba
, tgt
);
340 bnx2fc_free_conn_id(hba
, tgt
->fcoe_conn_id
);
343 static int bnx2fc_init_tgt(struct bnx2fc_rport
*tgt
,
344 struct fcoe_port
*port
,
345 struct fc_rport_priv
*rdata
)
348 struct fc_rport
*rport
= rdata
->rport
;
349 struct bnx2fc_interface
*interface
= port
->priv
;
350 struct bnx2fc_hba
*hba
= interface
->hba
;
351 struct b577xx_doorbell_set_prod
*sq_db
= &tgt
->sq_db
;
352 struct b577xx_fcoe_rx_doorbell
*rx_db
= &tgt
->rx_db
;
358 if (hba
->num_ofld_sess
>= BNX2FC_NUM_MAX_SESS
) {
359 BNX2FC_TGT_DBG(tgt
, "exceeded max sessions. logoff this tgt\n");
360 tgt
->fcoe_conn_id
= -1;
364 tgt
->fcoe_conn_id
= bnx2fc_alloc_conn_id(hba
, tgt
);
365 if (tgt
->fcoe_conn_id
== -1)
368 BNX2FC_TGT_DBG(tgt
, "init_tgt - conn_id = 0x%x\n", tgt
->fcoe_conn_id
);
370 tgt
->max_sqes
= BNX2FC_SQ_WQES_MAX
;
371 tgt
->max_rqes
= BNX2FC_RQ_WQES_MAX
;
372 tgt
->max_cqes
= BNX2FC_CQ_WQES_MAX
;
373 atomic_set(&tgt
->free_sqes
, BNX2FC_SQ_WQES_MAX
);
375 /* Initialize the toggle bit */
376 tgt
->sq_curr_toggle_bit
= 1;
377 tgt
->cq_curr_toggle_bit
= 1;
378 tgt
->sq_prod_idx
= 0;
379 tgt
->cq_cons_idx
= 0;
380 tgt
->rq_prod_idx
= 0x8000;
381 tgt
->rq_cons_idx
= 0;
382 atomic_set(&tgt
->num_active_ios
, 0);
384 if (rdata
->flags
& FC_RP_FLAGS_RETRY
) {
385 tgt
->dev_type
= TYPE_TAPE
;
386 tgt
->io_timeout
= 0; /* use default ULP timeout */
388 tgt
->dev_type
= TYPE_DISK
;
389 tgt
->io_timeout
= BNX2FC_IO_TIMEOUT
;
392 /* initialize sq doorbell */
393 sq_db
->header
.header
= B577XX_DOORBELL_HDR_DB_TYPE
;
394 sq_db
->header
.header
|= B577XX_FCOE_CONNECTION_TYPE
<<
395 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT
;
396 /* initialize rx doorbell */
397 rx_db
->hdr
.header
= ((0x1 << B577XX_DOORBELL_HDR_RX_SHIFT
) |
398 (0x1 << B577XX_DOORBELL_HDR_DB_TYPE_SHIFT
) |
399 (B577XX_FCOE_CONNECTION_TYPE
<<
400 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT
));
401 rx_db
->params
= (0x2 << B577XX_FCOE_RX_DOORBELL_NEGATIVE_ARM_SHIFT
) |
402 (0x3 << B577XX_FCOE_RX_DOORBELL_OPCODE_SHIFT
);
404 spin_lock_init(&tgt
->tgt_lock
);
405 spin_lock_init(&tgt
->cq_lock
);
407 /* Initialize active_cmd_queue list */
408 INIT_LIST_HEAD(&tgt
->active_cmd_queue
);
410 /* Initialize IO retire queue */
411 INIT_LIST_HEAD(&tgt
->io_retire_queue
);
413 INIT_LIST_HEAD(&tgt
->els_queue
);
415 /* Initialize active_tm_queue list */
416 INIT_LIST_HEAD(&tgt
->active_tm_queue
);
418 init_waitqueue_head(&tgt
->ofld_wait
);
419 init_waitqueue_head(&tgt
->upld_wait
);
425 * This event_callback is called after successful completion of libfc
426 * initiated target login. bnx2fc can proceed with initiating the session
429 void bnx2fc_rport_event_handler(struct fc_lport
*lport
,
430 struct fc_rport_priv
*rdata
,
431 enum fc_rport_event event
)
433 struct fcoe_port
*port
= lport_priv(lport
);
434 struct bnx2fc_interface
*interface
= port
->priv
;
435 struct bnx2fc_hba
*hba
= interface
->hba
;
436 struct fc_rport
*rport
= rdata
->rport
;
437 struct fc_rport_libfc_priv
*rp
;
438 struct bnx2fc_rport
*tgt
;
441 BNX2FC_HBA_DBG(lport
, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
442 event
, rdata
->ids
.port_id
);
446 printk(KERN_ERR PFX
"rport is NULL: ERROR!\n");
451 if (rport
->port_id
== FC_FID_DIR_SERV
) {
453 * bnx2fc_rport structure doesn't exist for
455 * We should not come here, as lport will
456 * take care of fabric login
458 printk(KERN_ERR PFX
"%x - rport_event_handler ERROR\n",
463 if (rdata
->spp_type
!= FC_TYPE_FCP
) {
464 BNX2FC_HBA_DBG(lport
, "not FCP type target."
465 " not offloading\n");
468 if (!(rdata
->ids
.roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
469 BNX2FC_HBA_DBG(lport
, "not FCP_TARGET"
470 " not offloading\n");
475 * Offlaod process is protected with hba mutex.
476 * Use the same mutex_lock for upload process too
478 mutex_lock(&hba
->hba_mutex
);
479 tgt
= (struct bnx2fc_rport
*)&rp
[1];
481 /* This can happen when ADISC finds the same target */
482 if (test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
)) {
483 BNX2FC_TGT_DBG(tgt
, "already offloaded\n");
484 mutex_unlock(&hba
->hba_mutex
);
489 * Offload the session. This is a blocking call, and will
490 * wait until the session is offloaded.
492 bnx2fc_offload_session(port
, tgt
, rdata
);
494 BNX2FC_TGT_DBG(tgt
, "OFFLOAD num_ofld_sess = %d\n",
497 if (test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
)) {
499 * Session is offloaded and enabled. Map
500 * doorbell register for this target
502 BNX2FC_TGT_DBG(tgt
, "sess offloaded\n");
503 /* This counter is protected with hba mutex */
504 hba
->num_ofld_sess
++;
506 set_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
);
509 * Offload or enable would have failed.
510 * In offload/enable completion path, the
511 * rport would have already been removed
513 BNX2FC_TGT_DBG(tgt
, "Port is being logged off as "
514 "offloaded flag not set\n");
516 mutex_unlock(&hba
->hba_mutex
);
519 case RPORT_EV_FAILED
:
521 port_id
= rdata
->ids
.port_id
;
522 if (port_id
== FC_FID_DIR_SERV
)
526 printk(KERN_INFO PFX
"%x - rport not created Yet!!\n",
531 mutex_lock(&hba
->hba_mutex
);
533 * Perform session upload. Note that rdata->peers is already
534 * removed from disc->rports list before we get this event.
536 tgt
= (struct bnx2fc_rport
*)&rp
[1];
538 if (!(test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
))) {
539 mutex_unlock(&hba
->hba_mutex
);
542 clear_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
);
544 bnx2fc_upload_session(port
, tgt
);
545 hba
->num_ofld_sess
--;
546 BNX2FC_TGT_DBG(tgt
, "UPLOAD num_ofld_sess = %d\n",
549 * Try to wake up the linkdown wait thread. If num_ofld_sess
550 * is 0, the waiting therad wakes up
552 if ((hba
->wait_for_link_down
) &&
553 (hba
->num_ofld_sess
== 0)) {
554 wake_up_interruptible(&hba
->shutdown_wait
);
556 if (test_bit(BNX2FC_FLAG_EXPL_LOGO
, &tgt
->flags
)) {
557 printk(KERN_ERR PFX
"Relogin to the tgt\n");
558 mutex_lock(&lport
->disc
.disc_mutex
);
559 lport
->tt
.rport_login(rdata
);
560 mutex_unlock(&lport
->disc
.disc_mutex
);
562 mutex_unlock(&hba
->hba_mutex
);
572 * bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
574 * @port: fcoe_port struct to lookup the target port on
575 * @port_id: The remote port ID to look up
577 struct bnx2fc_rport
*bnx2fc_tgt_lookup(struct fcoe_port
*port
,
580 struct bnx2fc_interface
*interface
= port
->priv
;
581 struct bnx2fc_hba
*hba
= interface
->hba
;
582 struct bnx2fc_rport
*tgt
;
583 struct fc_rport_priv
*rdata
;
586 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
587 tgt
= hba
->tgt_ofld_list
[i
];
588 if ((tgt
) && (tgt
->port
== port
)) {
590 if (rdata
->ids
.port_id
== port_id
) {
591 if (rdata
->rp_state
!= RPORT_ST_DELETE
) {
592 BNX2FC_TGT_DBG(tgt
, "rport "
596 BNX2FC_TGT_DBG(tgt
, "rport 0x%x "
597 "is in DELETED state\n",
609 * bnx2fc_alloc_conn_id - allocates FCOE Connection id
611 * @hba: pointer to adapter structure
612 * @tgt: pointer to bnx2fc_rport structure
614 static u32
bnx2fc_alloc_conn_id(struct bnx2fc_hba
*hba
,
615 struct bnx2fc_rport
*tgt
)
619 /* called with hba mutex held */
622 * tgt_ofld_list access is synchronized using
623 * both hba mutex and hba lock. Atleast hba mutex or
624 * hba lock needs to be held for read access.
627 spin_lock_bh(&hba
->hba_lock
);
628 next
= hba
->next_conn_id
;
629 conn_id
= hba
->next_conn_id
++;
630 if (hba
->next_conn_id
== BNX2FC_NUM_MAX_SESS
)
631 hba
->next_conn_id
= 0;
633 while (hba
->tgt_ofld_list
[conn_id
] != NULL
) {
635 if (conn_id
== BNX2FC_NUM_MAX_SESS
)
638 if (conn_id
== next
) {
639 /* No free conn_ids are available */
640 spin_unlock_bh(&hba
->hba_lock
);
644 hba
->tgt_ofld_list
[conn_id
] = tgt
;
645 tgt
->fcoe_conn_id
= conn_id
;
646 spin_unlock_bh(&hba
->hba_lock
);
650 static void bnx2fc_free_conn_id(struct bnx2fc_hba
*hba
, u32 conn_id
)
652 /* called with hba mutex held */
653 spin_lock_bh(&hba
->hba_lock
);
654 hba
->tgt_ofld_list
[conn_id
] = NULL
;
655 spin_unlock_bh(&hba
->hba_lock
);
659 *bnx2fc_alloc_session_resc - Allocate qp resources for the session
662 static int bnx2fc_alloc_session_resc(struct bnx2fc_hba
*hba
,
663 struct bnx2fc_rport
*tgt
)
669 /* Allocate and map SQ */
670 tgt
->sq_mem_size
= tgt
->max_sqes
* BNX2FC_SQ_WQE_SIZE
;
671 tgt
->sq_mem_size
= (tgt
->sq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
673 tgt
->sq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->sq_mem_size
,
674 &tgt
->sq_dma
, GFP_KERNEL
);
676 printk(KERN_ERR PFX
"unable to allocate SQ memory %d\n",
678 goto mem_alloc_failure
;
680 memset(tgt
->sq
, 0, tgt
->sq_mem_size
);
682 /* Allocate and map CQ */
683 tgt
->cq_mem_size
= tgt
->max_cqes
* BNX2FC_CQ_WQE_SIZE
;
684 tgt
->cq_mem_size
= (tgt
->cq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
686 tgt
->cq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->cq_mem_size
,
687 &tgt
->cq_dma
, GFP_KERNEL
);
689 printk(KERN_ERR PFX
"unable to allocate CQ memory %d\n",
691 goto mem_alloc_failure
;
693 memset(tgt
->cq
, 0, tgt
->cq_mem_size
);
695 /* Allocate and map RQ and RQ PBL */
696 tgt
->rq_mem_size
= tgt
->max_rqes
* BNX2FC_RQ_WQE_SIZE
;
697 tgt
->rq_mem_size
= (tgt
->rq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
699 tgt
->rq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->rq_mem_size
,
700 &tgt
->rq_dma
, GFP_KERNEL
);
702 printk(KERN_ERR PFX
"unable to allocate RQ memory %d\n",
704 goto mem_alloc_failure
;
706 memset(tgt
->rq
, 0, tgt
->rq_mem_size
);
708 tgt
->rq_pbl_size
= (tgt
->rq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
709 tgt
->rq_pbl_size
= (tgt
->rq_pbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
711 tgt
->rq_pbl
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->rq_pbl_size
,
712 &tgt
->rq_pbl_dma
, GFP_KERNEL
);
714 printk(KERN_ERR PFX
"unable to allocate RQ PBL %d\n",
716 goto mem_alloc_failure
;
719 memset(tgt
->rq_pbl
, 0, tgt
->rq_pbl_size
);
720 num_pages
= tgt
->rq_mem_size
/ PAGE_SIZE
;
722 pbl
= (u32
*)tgt
->rq_pbl
;
724 while (num_pages
--) {
727 *pbl
= (u32
)((u64
)page
>> 32);
732 /* Allocate and map XFERQ */
733 tgt
->xferq_mem_size
= tgt
->max_sqes
* BNX2FC_XFERQ_WQE_SIZE
;
734 tgt
->xferq_mem_size
= (tgt
->xferq_mem_size
+ (PAGE_SIZE
- 1)) &
737 tgt
->xferq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->xferq_mem_size
,
738 &tgt
->xferq_dma
, GFP_KERNEL
);
740 printk(KERN_ERR PFX
"unable to allocate XFERQ %d\n",
741 tgt
->xferq_mem_size
);
742 goto mem_alloc_failure
;
744 memset(tgt
->xferq
, 0, tgt
->xferq_mem_size
);
746 /* Allocate and map CONFQ & CONFQ PBL */
747 tgt
->confq_mem_size
= tgt
->max_sqes
* BNX2FC_CONFQ_WQE_SIZE
;
748 tgt
->confq_mem_size
= (tgt
->confq_mem_size
+ (PAGE_SIZE
- 1)) &
751 tgt
->confq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->confq_mem_size
,
752 &tgt
->confq_dma
, GFP_KERNEL
);
754 printk(KERN_ERR PFX
"unable to allocate CONFQ %d\n",
755 tgt
->confq_mem_size
);
756 goto mem_alloc_failure
;
758 memset(tgt
->confq
, 0, tgt
->confq_mem_size
);
760 tgt
->confq_pbl_size
=
761 (tgt
->confq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
762 tgt
->confq_pbl_size
=
763 (tgt
->confq_pbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
765 tgt
->confq_pbl
= dma_alloc_coherent(&hba
->pcidev
->dev
,
767 &tgt
->confq_pbl_dma
, GFP_KERNEL
);
768 if (!tgt
->confq_pbl
) {
769 printk(KERN_ERR PFX
"unable to allocate CONFQ PBL %d\n",
770 tgt
->confq_pbl_size
);
771 goto mem_alloc_failure
;
774 memset(tgt
->confq_pbl
, 0, tgt
->confq_pbl_size
);
775 num_pages
= tgt
->confq_mem_size
/ PAGE_SIZE
;
776 page
= tgt
->confq_dma
;
777 pbl
= (u32
*)tgt
->confq_pbl
;
779 while (num_pages
--) {
782 *pbl
= (u32
)((u64
)page
>> 32);
787 /* Allocate and map ConnDB */
788 tgt
->conn_db_mem_size
= sizeof(struct fcoe_conn_db
);
790 tgt
->conn_db
= dma_alloc_coherent(&hba
->pcidev
->dev
,
791 tgt
->conn_db_mem_size
,
792 &tgt
->conn_db_dma
, GFP_KERNEL
);
794 printk(KERN_ERR PFX
"unable to allocate conn_db %d\n",
795 tgt
->conn_db_mem_size
);
796 goto mem_alloc_failure
;
798 memset(tgt
->conn_db
, 0, tgt
->conn_db_mem_size
);
801 /* Allocate and map LCQ */
802 tgt
->lcq_mem_size
= (tgt
->max_sqes
+ 8) * BNX2FC_SQ_WQE_SIZE
;
803 tgt
->lcq_mem_size
= (tgt
->lcq_mem_size
+ (PAGE_SIZE
- 1)) &
806 tgt
->lcq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->lcq_mem_size
,
807 &tgt
->lcq_dma
, GFP_KERNEL
);
810 printk(KERN_ERR PFX
"unable to allocate lcq %d\n",
812 goto mem_alloc_failure
;
814 memset(tgt
->lcq
, 0, tgt
->lcq_mem_size
);
816 tgt
->conn_db
->rq_prod
= 0x8000;
825 * bnx2i_free_session_resc - free qp resources for the session
827 * @hba: adapter structure pointer
828 * @tgt: bnx2fc_rport structure pointer
830 * Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
832 static void bnx2fc_free_session_resc(struct bnx2fc_hba
*hba
,
833 struct bnx2fc_rport
*tgt
)
835 void __iomem
*ctx_base_ptr
;
837 BNX2FC_TGT_DBG(tgt
, "Freeing up session resources\n");
839 spin_lock_bh(&tgt
->cq_lock
);
840 ctx_base_ptr
= tgt
->ctx_base
;
841 tgt
->ctx_base
= NULL
;
845 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->lcq_mem_size
,
846 tgt
->lcq
, tgt
->lcq_dma
);
851 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->conn_db_mem_size
,
852 tgt
->conn_db
, tgt
->conn_db_dma
);
855 /* Free confq and confq pbl */
856 if (tgt
->confq_pbl
) {
857 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->confq_pbl_size
,
858 tgt
->confq_pbl
, tgt
->confq_pbl_dma
);
859 tgt
->confq_pbl
= NULL
;
862 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->confq_mem_size
,
863 tgt
->confq
, tgt
->confq_dma
);
868 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->xferq_mem_size
,
869 tgt
->xferq
, tgt
->xferq_dma
);
872 /* Free RQ PBL and RQ */
874 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->rq_pbl_size
,
875 tgt
->rq_pbl
, tgt
->rq_pbl_dma
);
879 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->rq_mem_size
,
880 tgt
->rq
, tgt
->rq_dma
);
885 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->cq_mem_size
,
886 tgt
->cq
, tgt
->cq_dma
);
891 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->sq_mem_size
,
892 tgt
->sq
, tgt
->sq_dma
);
895 spin_unlock_bh(&tgt
->cq_lock
);
898 iounmap(ctx_base_ptr
);