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 list_head
*list
;
154 struct list_head
*tmp
;
157 BNX2FC_TGT_DBG(tgt
, "Entered flush_active_ios - %d\n",
158 tgt
->num_active_ios
.counter
);
160 spin_lock_bh(&tgt
->tgt_lock
);
161 tgt
->flush_in_prog
= 1;
163 list_for_each_safe(list
, tmp
, &tgt
->active_cmd_queue
) {
165 io_req
= (struct bnx2fc_cmd
*)list
;
166 list_del_init(&io_req
->link
);
167 io_req
->on_active_queue
= 0;
168 BNX2FC_IO_DBG(io_req
, "cmd_queue cleanup\n");
170 if (cancel_delayed_work(&io_req
->timeout_work
)) {
171 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
172 &io_req
->req_flags
)) {
173 /* Handle eh_abort timeout */
174 BNX2FC_IO_DBG(io_req
, "eh_abort for IO "
176 complete(&io_req
->tm_done
);
178 kref_put(&io_req
->refcount
,
179 bnx2fc_cmd_release
); /* drop timer hold */
182 set_bit(BNX2FC_FLAG_IO_COMPL
, &io_req
->req_flags
);
183 set_bit(BNX2FC_FLAG_IO_CLEANUP
, &io_req
->req_flags
);
184 rc
= bnx2fc_initiate_cleanup(io_req
);
188 list_for_each_safe(list
, tmp
, &tgt
->active_tm_queue
) {
190 io_req
= (struct bnx2fc_cmd
*)list
;
191 list_del_init(&io_req
->link
);
192 io_req
->on_tmf_queue
= 0;
193 BNX2FC_IO_DBG(io_req
, "tm_queue cleanup\n");
194 if (io_req
->wait_for_comp
)
195 complete(&io_req
->tm_done
);
198 list_for_each_safe(list
, tmp
, &tgt
->els_queue
) {
200 io_req
= (struct bnx2fc_cmd
*)list
;
201 list_del_init(&io_req
->link
);
202 io_req
->on_active_queue
= 0;
204 BNX2FC_IO_DBG(io_req
, "els_queue cleanup\n");
206 if (cancel_delayed_work(&io_req
->timeout_work
))
207 kref_put(&io_req
->refcount
,
208 bnx2fc_cmd_release
); /* drop timer hold */
210 if ((io_req
->cb_func
) && (io_req
->cb_arg
)) {
211 io_req
->cb_func(io_req
->cb_arg
);
212 io_req
->cb_arg
= NULL
;
215 rc
= bnx2fc_initiate_cleanup(io_req
);
219 list_for_each_safe(list
, tmp
, &tgt
->io_retire_queue
) {
221 io_req
= (struct bnx2fc_cmd
*)list
;
222 list_del_init(&io_req
->link
);
224 BNX2FC_IO_DBG(io_req
, "retire_queue flush\n");
226 if (cancel_delayed_work(&io_req
->timeout_work
)) {
227 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT
,
228 &io_req
->req_flags
)) {
229 /* Handle eh_abort timeout */
230 BNX2FC_IO_DBG(io_req
, "eh_abort for IO "
232 if (io_req
->wait_for_comp
)
233 complete(&io_req
->tm_done
);
235 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
238 clear_bit(BNX2FC_FLAG_ISSUE_RRQ
, &io_req
->req_flags
);
241 BNX2FC_TGT_DBG(tgt
, "IOs flushed = %d\n", i
);
243 spin_unlock_bh(&tgt
->tgt_lock
);
244 /* wait for active_ios to go to 0 */
245 while ((tgt
->num_active_ios
.counter
!= 0) && (i
++ < BNX2FC_WAIT_CNT
))
247 if (tgt
->num_active_ios
.counter
!= 0)
248 printk(KERN_ERR PFX
"CLEANUP on port 0x%x:"
249 " active_ios = %d\n",
250 tgt
->rdata
->ids
.port_id
, tgt
->num_active_ios
.counter
);
251 spin_lock_bh(&tgt
->tgt_lock
);
252 tgt
->flush_in_prog
= 0;
253 spin_unlock_bh(&tgt
->tgt_lock
);
256 static void bnx2fc_upload_session(struct fcoe_port
*port
,
257 struct bnx2fc_rport
*tgt
)
259 struct bnx2fc_interface
*interface
= port
->priv
;
260 struct bnx2fc_hba
*hba
= interface
->hba
;
262 BNX2FC_TGT_DBG(tgt
, "upload_session: active_ios = %d\n",
263 tgt
->num_active_ios
.counter
);
266 * Called with hba->hba_mutex held.
267 * This is a blocking call
269 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
270 bnx2fc_send_session_disable_req(port
, tgt
);
273 * wait for upload to complete. 3 Secs
274 * should be sufficient time for this process to complete.
276 setup_timer(&tgt
->upld_timer
, bnx2fc_upld_timer
, (unsigned long)tgt
);
277 mod_timer(&tgt
->upld_timer
, jiffies
+ BNX2FC_FW_TIMEOUT
);
279 BNX2FC_TGT_DBG(tgt
, "waiting for disable compl\n");
280 wait_event_interruptible(tgt
->upld_wait
,
282 BNX2FC_FLAG_UPLD_REQ_COMPL
,
285 if (signal_pending(current
))
286 flush_signals(current
);
288 del_timer_sync(&tgt
->upld_timer
);
291 * traverse thru the active_q and tmf_q and cleanup
294 BNX2FC_TGT_DBG(tgt
, "flush/upload - disable wait flags = 0x%lx\n",
296 bnx2fc_flush_active_ios(tgt
);
298 /* Issue destroy KWQE */
299 if (test_bit(BNX2FC_FLAG_DISABLED
, &tgt
->flags
)) {
300 BNX2FC_TGT_DBG(tgt
, "send destroy req\n");
301 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
302 bnx2fc_send_session_destroy_req(hba
, tgt
);
304 /* wait for destroy to complete */
305 setup_timer(&tgt
->upld_timer
,
306 bnx2fc_upld_timer
, (unsigned long)tgt
);
307 mod_timer(&tgt
->upld_timer
, jiffies
+ BNX2FC_FW_TIMEOUT
);
309 wait_event_interruptible(tgt
->upld_wait
,
311 BNX2FC_FLAG_UPLD_REQ_COMPL
,
314 if (!(test_bit(BNX2FC_FLAG_DESTROYED
, &tgt
->flags
)))
315 printk(KERN_ERR PFX
"ERROR!! destroy timed out\n");
317 BNX2FC_TGT_DBG(tgt
, "destroy wait complete flags = 0x%lx\n",
319 if (signal_pending(current
))
320 flush_signals(current
);
322 del_timer_sync(&tgt
->upld_timer
);
325 printk(KERN_ERR PFX
"ERROR!! DISABLE req timed out, destroy"
326 " not sent to FW\n");
328 /* Free session resources */
329 bnx2fc_free_session_resc(hba
, tgt
);
330 bnx2fc_free_conn_id(hba
, tgt
->fcoe_conn_id
);
333 static int bnx2fc_init_tgt(struct bnx2fc_rport
*tgt
,
334 struct fcoe_port
*port
,
335 struct fc_rport_priv
*rdata
)
338 struct fc_rport
*rport
= rdata
->rport
;
339 struct bnx2fc_interface
*interface
= port
->priv
;
340 struct bnx2fc_hba
*hba
= interface
->hba
;
341 struct b577xx_doorbell_set_prod
*sq_db
= &tgt
->sq_db
;
342 struct b577xx_fcoe_rx_doorbell
*rx_db
= &tgt
->rx_db
;
348 if (hba
->num_ofld_sess
>= BNX2FC_NUM_MAX_SESS
) {
349 BNX2FC_TGT_DBG(tgt
, "exceeded max sessions. logoff this tgt\n");
350 tgt
->fcoe_conn_id
= -1;
354 tgt
->fcoe_conn_id
= bnx2fc_alloc_conn_id(hba
, tgt
);
355 if (tgt
->fcoe_conn_id
== -1)
358 BNX2FC_TGT_DBG(tgt
, "init_tgt - conn_id = 0x%x\n", tgt
->fcoe_conn_id
);
360 tgt
->max_sqes
= BNX2FC_SQ_WQES_MAX
;
361 tgt
->max_rqes
= BNX2FC_RQ_WQES_MAX
;
362 tgt
->max_cqes
= BNX2FC_CQ_WQES_MAX
;
363 atomic_set(&tgt
->free_sqes
, BNX2FC_SQ_WQES_MAX
);
365 /* Initialize the toggle bit */
366 tgt
->sq_curr_toggle_bit
= 1;
367 tgt
->cq_curr_toggle_bit
= 1;
368 tgt
->sq_prod_idx
= 0;
369 tgt
->cq_cons_idx
= 0;
370 tgt
->rq_prod_idx
= 0x8000;
371 tgt
->rq_cons_idx
= 0;
372 atomic_set(&tgt
->num_active_ios
, 0);
374 if (rdata
->flags
& FC_RP_FLAGS_RETRY
) {
375 tgt
->dev_type
= TYPE_TAPE
;
376 tgt
->io_timeout
= 0; /* use default ULP timeout */
378 tgt
->dev_type
= TYPE_DISK
;
379 tgt
->io_timeout
= BNX2FC_IO_TIMEOUT
;
382 /* initialize sq doorbell */
383 sq_db
->header
.header
= B577XX_DOORBELL_HDR_DB_TYPE
;
384 sq_db
->header
.header
|= B577XX_FCOE_CONNECTION_TYPE
<<
385 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT
;
386 /* initialize rx doorbell */
387 rx_db
->hdr
.header
= ((0x1 << B577XX_DOORBELL_HDR_RX_SHIFT
) |
388 (0x1 << B577XX_DOORBELL_HDR_DB_TYPE_SHIFT
) |
389 (B577XX_FCOE_CONNECTION_TYPE
<<
390 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT
));
391 rx_db
->params
= (0x2 << B577XX_FCOE_RX_DOORBELL_NEGATIVE_ARM_SHIFT
) |
392 (0x3 << B577XX_FCOE_RX_DOORBELL_OPCODE_SHIFT
);
394 spin_lock_init(&tgt
->tgt_lock
);
395 spin_lock_init(&tgt
->cq_lock
);
397 /* Initialize active_cmd_queue list */
398 INIT_LIST_HEAD(&tgt
->active_cmd_queue
);
400 /* Initialize IO retire queue */
401 INIT_LIST_HEAD(&tgt
->io_retire_queue
);
403 INIT_LIST_HEAD(&tgt
->els_queue
);
405 /* Initialize active_tm_queue list */
406 INIT_LIST_HEAD(&tgt
->active_tm_queue
);
408 init_waitqueue_head(&tgt
->ofld_wait
);
409 init_waitqueue_head(&tgt
->upld_wait
);
415 * This event_callback is called after successful completion of libfc
416 * initiated target login. bnx2fc can proceed with initiating the session
419 void bnx2fc_rport_event_handler(struct fc_lport
*lport
,
420 struct fc_rport_priv
*rdata
,
421 enum fc_rport_event event
)
423 struct fcoe_port
*port
= lport_priv(lport
);
424 struct bnx2fc_interface
*interface
= port
->priv
;
425 struct bnx2fc_hba
*hba
= interface
->hba
;
426 struct fc_rport
*rport
= rdata
->rport
;
427 struct fc_rport_libfc_priv
*rp
;
428 struct bnx2fc_rport
*tgt
;
431 BNX2FC_HBA_DBG(lport
, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
432 event
, rdata
->ids
.port_id
);
436 printk(KERN_ERR PFX
"rport is NULL: ERROR!\n");
441 if (rport
->port_id
== FC_FID_DIR_SERV
) {
443 * bnx2fc_rport structure doesn't exist for
445 * We should not come here, as lport will
446 * take care of fabric login
448 printk(KERN_ERR PFX
"%x - rport_event_handler ERROR\n",
453 if (rdata
->spp_type
!= FC_TYPE_FCP
) {
454 BNX2FC_HBA_DBG(lport
, "not FCP type target."
455 " not offloading\n");
458 if (!(rdata
->ids
.roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
459 BNX2FC_HBA_DBG(lport
, "not FCP_TARGET"
460 " not offloading\n");
465 * Offlaod process is protected with hba mutex.
466 * Use the same mutex_lock for upload process too
468 mutex_lock(&hba
->hba_mutex
);
469 tgt
= (struct bnx2fc_rport
*)&rp
[1];
471 /* This can happen when ADISC finds the same target */
472 if (test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
)) {
473 BNX2FC_TGT_DBG(tgt
, "already offloaded\n");
474 mutex_unlock(&hba
->hba_mutex
);
479 * Offload the session. This is a blocking call, and will
480 * wait until the session is offloaded.
482 bnx2fc_offload_session(port
, tgt
, rdata
);
484 BNX2FC_TGT_DBG(tgt
, "OFFLOAD num_ofld_sess = %d\n",
487 if (test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
)) {
489 * Session is offloaded and enabled. Map
490 * doorbell register for this target
492 BNX2FC_TGT_DBG(tgt
, "sess offloaded\n");
493 /* This counter is protected with hba mutex */
494 hba
->num_ofld_sess
++;
496 set_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
);
499 * Offload or enable would have failed.
500 * In offload/enable completion path, the
501 * rport would have already been removed
503 BNX2FC_TGT_DBG(tgt
, "Port is being logged off as "
504 "offloaded flag not set\n");
506 mutex_unlock(&hba
->hba_mutex
);
509 case RPORT_EV_FAILED
:
511 port_id
= rdata
->ids
.port_id
;
512 if (port_id
== FC_FID_DIR_SERV
)
516 printk(KERN_INFO PFX
"%x - rport not created Yet!!\n",
521 mutex_lock(&hba
->hba_mutex
);
523 * Perform session upload. Note that rdata->peers is already
524 * removed from disc->rports list before we get this event.
526 tgt
= (struct bnx2fc_rport
*)&rp
[1];
528 if (!(test_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
))) {
529 mutex_unlock(&hba
->hba_mutex
);
532 clear_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
);
534 bnx2fc_upload_session(port
, tgt
);
535 hba
->num_ofld_sess
--;
536 BNX2FC_TGT_DBG(tgt
, "UPLOAD num_ofld_sess = %d\n",
539 * Try to wake up the linkdown wait thread. If num_ofld_sess
540 * is 0, the waiting therad wakes up
542 if ((hba
->wait_for_link_down
) &&
543 (hba
->num_ofld_sess
== 0)) {
544 wake_up_interruptible(&hba
->shutdown_wait
);
546 if (test_bit(BNX2FC_FLAG_EXPL_LOGO
, &tgt
->flags
)) {
547 printk(KERN_ERR PFX
"Relogin to the tgt\n");
548 mutex_lock(&lport
->disc
.disc_mutex
);
549 lport
->tt
.rport_login(rdata
);
550 mutex_unlock(&lport
->disc
.disc_mutex
);
552 mutex_unlock(&hba
->hba_mutex
);
562 * bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
564 * @port: fcoe_port struct to lookup the target port on
565 * @port_id: The remote port ID to look up
567 struct bnx2fc_rport
*bnx2fc_tgt_lookup(struct fcoe_port
*port
,
570 struct bnx2fc_interface
*interface
= port
->priv
;
571 struct bnx2fc_hba
*hba
= interface
->hba
;
572 struct bnx2fc_rport
*tgt
;
573 struct fc_rport_priv
*rdata
;
576 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
577 tgt
= hba
->tgt_ofld_list
[i
];
578 if ((tgt
) && (tgt
->port
== port
)) {
580 if (rdata
->ids
.port_id
== port_id
) {
581 if (rdata
->rp_state
!= RPORT_ST_DELETE
) {
582 BNX2FC_TGT_DBG(tgt
, "rport "
586 BNX2FC_TGT_DBG(tgt
, "rport 0x%x "
587 "is in DELETED state\n",
599 * bnx2fc_alloc_conn_id - allocates FCOE Connection id
601 * @hba: pointer to adapter structure
602 * @tgt: pointer to bnx2fc_rport structure
604 static u32
bnx2fc_alloc_conn_id(struct bnx2fc_hba
*hba
,
605 struct bnx2fc_rport
*tgt
)
609 /* called with hba mutex held */
612 * tgt_ofld_list access is synchronized using
613 * both hba mutex and hba lock. Atleast hba mutex or
614 * hba lock needs to be held for read access.
617 spin_lock_bh(&hba
->hba_lock
);
618 next
= hba
->next_conn_id
;
619 conn_id
= hba
->next_conn_id
++;
620 if (hba
->next_conn_id
== BNX2FC_NUM_MAX_SESS
)
621 hba
->next_conn_id
= 0;
623 while (hba
->tgt_ofld_list
[conn_id
] != NULL
) {
625 if (conn_id
== BNX2FC_NUM_MAX_SESS
)
628 if (conn_id
== next
) {
629 /* No free conn_ids are available */
630 spin_unlock_bh(&hba
->hba_lock
);
634 hba
->tgt_ofld_list
[conn_id
] = tgt
;
635 tgt
->fcoe_conn_id
= conn_id
;
636 spin_unlock_bh(&hba
->hba_lock
);
640 static void bnx2fc_free_conn_id(struct bnx2fc_hba
*hba
, u32 conn_id
)
642 /* called with hba mutex held */
643 spin_lock_bh(&hba
->hba_lock
);
644 hba
->tgt_ofld_list
[conn_id
] = NULL
;
645 spin_unlock_bh(&hba
->hba_lock
);
649 *bnx2fc_alloc_session_resc - Allocate qp resources for the session
652 static int bnx2fc_alloc_session_resc(struct bnx2fc_hba
*hba
,
653 struct bnx2fc_rport
*tgt
)
659 /* Allocate and map SQ */
660 tgt
->sq_mem_size
= tgt
->max_sqes
* BNX2FC_SQ_WQE_SIZE
;
661 tgt
->sq_mem_size
= (tgt
->sq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
663 tgt
->sq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->sq_mem_size
,
664 &tgt
->sq_dma
, GFP_KERNEL
);
666 printk(KERN_ERR PFX
"unable to allocate SQ memory %d\n",
668 goto mem_alloc_failure
;
670 memset(tgt
->sq
, 0, tgt
->sq_mem_size
);
672 /* Allocate and map CQ */
673 tgt
->cq_mem_size
= tgt
->max_cqes
* BNX2FC_CQ_WQE_SIZE
;
674 tgt
->cq_mem_size
= (tgt
->cq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
676 tgt
->cq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->cq_mem_size
,
677 &tgt
->cq_dma
, GFP_KERNEL
);
679 printk(KERN_ERR PFX
"unable to allocate CQ memory %d\n",
681 goto mem_alloc_failure
;
683 memset(tgt
->cq
, 0, tgt
->cq_mem_size
);
685 /* Allocate and map RQ and RQ PBL */
686 tgt
->rq_mem_size
= tgt
->max_rqes
* BNX2FC_RQ_WQE_SIZE
;
687 tgt
->rq_mem_size
= (tgt
->rq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
689 tgt
->rq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->rq_mem_size
,
690 &tgt
->rq_dma
, GFP_KERNEL
);
692 printk(KERN_ERR PFX
"unable to allocate RQ memory %d\n",
694 goto mem_alloc_failure
;
696 memset(tgt
->rq
, 0, tgt
->rq_mem_size
);
698 tgt
->rq_pbl_size
= (tgt
->rq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
699 tgt
->rq_pbl_size
= (tgt
->rq_pbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
701 tgt
->rq_pbl
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->rq_pbl_size
,
702 &tgt
->rq_pbl_dma
, GFP_KERNEL
);
704 printk(KERN_ERR PFX
"unable to allocate RQ PBL %d\n",
706 goto mem_alloc_failure
;
709 memset(tgt
->rq_pbl
, 0, tgt
->rq_pbl_size
);
710 num_pages
= tgt
->rq_mem_size
/ PAGE_SIZE
;
712 pbl
= (u32
*)tgt
->rq_pbl
;
714 while (num_pages
--) {
717 *pbl
= (u32
)((u64
)page
>> 32);
722 /* Allocate and map XFERQ */
723 tgt
->xferq_mem_size
= tgt
->max_sqes
* BNX2FC_XFERQ_WQE_SIZE
;
724 tgt
->xferq_mem_size
= (tgt
->xferq_mem_size
+ (PAGE_SIZE
- 1)) &
727 tgt
->xferq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->xferq_mem_size
,
728 &tgt
->xferq_dma
, GFP_KERNEL
);
730 printk(KERN_ERR PFX
"unable to allocate XFERQ %d\n",
731 tgt
->xferq_mem_size
);
732 goto mem_alloc_failure
;
734 memset(tgt
->xferq
, 0, tgt
->xferq_mem_size
);
736 /* Allocate and map CONFQ & CONFQ PBL */
737 tgt
->confq_mem_size
= tgt
->max_sqes
* BNX2FC_CONFQ_WQE_SIZE
;
738 tgt
->confq_mem_size
= (tgt
->confq_mem_size
+ (PAGE_SIZE
- 1)) &
741 tgt
->confq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->confq_mem_size
,
742 &tgt
->confq_dma
, GFP_KERNEL
);
744 printk(KERN_ERR PFX
"unable to allocate CONFQ %d\n",
745 tgt
->confq_mem_size
);
746 goto mem_alloc_failure
;
748 memset(tgt
->confq
, 0, tgt
->confq_mem_size
);
750 tgt
->confq_pbl_size
=
751 (tgt
->confq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
752 tgt
->confq_pbl_size
=
753 (tgt
->confq_pbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
755 tgt
->confq_pbl
= dma_alloc_coherent(&hba
->pcidev
->dev
,
757 &tgt
->confq_pbl_dma
, GFP_KERNEL
);
758 if (!tgt
->confq_pbl
) {
759 printk(KERN_ERR PFX
"unable to allocate CONFQ PBL %d\n",
760 tgt
->confq_pbl_size
);
761 goto mem_alloc_failure
;
764 memset(tgt
->confq_pbl
, 0, tgt
->confq_pbl_size
);
765 num_pages
= tgt
->confq_mem_size
/ PAGE_SIZE
;
766 page
= tgt
->confq_dma
;
767 pbl
= (u32
*)tgt
->confq_pbl
;
769 while (num_pages
--) {
772 *pbl
= (u32
)((u64
)page
>> 32);
777 /* Allocate and map ConnDB */
778 tgt
->conn_db_mem_size
= sizeof(struct fcoe_conn_db
);
780 tgt
->conn_db
= dma_alloc_coherent(&hba
->pcidev
->dev
,
781 tgt
->conn_db_mem_size
,
782 &tgt
->conn_db_dma
, GFP_KERNEL
);
784 printk(KERN_ERR PFX
"unable to allocate conn_db %d\n",
785 tgt
->conn_db_mem_size
);
786 goto mem_alloc_failure
;
788 memset(tgt
->conn_db
, 0, tgt
->conn_db_mem_size
);
791 /* Allocate and map LCQ */
792 tgt
->lcq_mem_size
= (tgt
->max_sqes
+ 8) * BNX2FC_SQ_WQE_SIZE
;
793 tgt
->lcq_mem_size
= (tgt
->lcq_mem_size
+ (PAGE_SIZE
- 1)) &
796 tgt
->lcq
= dma_alloc_coherent(&hba
->pcidev
->dev
, tgt
->lcq_mem_size
,
797 &tgt
->lcq_dma
, GFP_KERNEL
);
800 printk(KERN_ERR PFX
"unable to allocate lcq %d\n",
802 goto mem_alloc_failure
;
804 memset(tgt
->lcq
, 0, tgt
->lcq_mem_size
);
806 tgt
->conn_db
->rq_prod
= 0x8000;
815 * bnx2i_free_session_resc - free qp resources for the session
817 * @hba: adapter structure pointer
818 * @tgt: bnx2fc_rport structure pointer
820 * Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
822 static void bnx2fc_free_session_resc(struct bnx2fc_hba
*hba
,
823 struct bnx2fc_rport
*tgt
)
825 void __iomem
*ctx_base_ptr
;
827 BNX2FC_TGT_DBG(tgt
, "Freeing up session resources\n");
829 spin_lock_bh(&tgt
->cq_lock
);
830 ctx_base_ptr
= tgt
->ctx_base
;
831 tgt
->ctx_base
= NULL
;
835 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->lcq_mem_size
,
836 tgt
->lcq
, tgt
->lcq_dma
);
841 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->conn_db_mem_size
,
842 tgt
->conn_db
, tgt
->conn_db_dma
);
845 /* Free confq and confq pbl */
846 if (tgt
->confq_pbl
) {
847 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->confq_pbl_size
,
848 tgt
->confq_pbl
, tgt
->confq_pbl_dma
);
849 tgt
->confq_pbl
= NULL
;
852 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->confq_mem_size
,
853 tgt
->confq
, tgt
->confq_dma
);
858 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->xferq_mem_size
,
859 tgt
->xferq
, tgt
->xferq_dma
);
862 /* Free RQ PBL and RQ */
864 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->rq_pbl_size
,
865 tgt
->rq_pbl
, tgt
->rq_pbl_dma
);
869 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->rq_mem_size
,
870 tgt
->rq
, tgt
->rq_dma
);
875 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->cq_mem_size
,
876 tgt
->cq
, tgt
->cq_dma
);
881 dma_free_coherent(&hba
->pcidev
->dev
, tgt
->sq_mem_size
,
882 tgt
->sq
, tgt
->sq_dma
);
885 spin_unlock_bh(&tgt
->cq_lock
);
888 iounmap(ctx_base_ptr
);