Loading...
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.
4 *
5 * Copyright (c) 2008 - 2011 Broadcom Corporation
6 *
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.
10 *
11 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
12 */
13
14#include "bnx2fc.h"
15static void bnx2fc_upld_timer(unsigned long data);
16static void bnx2fc_ofld_timer(unsigned long data);
17static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
18 struct fcoe_port *port,
19 struct fc_rport_priv *rdata);
20static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
21 struct bnx2fc_rport *tgt);
22static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
23 struct bnx2fc_rport *tgt);
24static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
25 struct bnx2fc_rport *tgt);
26static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id);
27
28static void bnx2fc_upld_timer(unsigned long data)
29{
30
31 struct bnx2fc_rport *tgt = (struct bnx2fc_rport *)data;
32
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);
38}
39
40static void bnx2fc_ofld_timer(unsigned long data)
41{
42
43 struct bnx2fc_rport *tgt = (struct bnx2fc_rport *)data;
44
45 BNX2FC_TGT_DBG(tgt, "entered bnx2fc_ofld_timer\n");
46 /* NOTE: This function should never be called, as
47 * offload should never timeout
48 */
49 /*
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
56 */
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);
60}
61
62static void bnx2fc_offload_session(struct fcoe_port *port,
63 struct bnx2fc_rport *tgt,
64 struct fc_rport_priv *rdata)
65{
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;
70 int rval;
71 int i = 0;
72
73 /* Initialize bnx2fc_rport */
74 /* NOTE: tgt is already bzero'd */
75 rval = bnx2fc_init_tgt(tgt, port, rdata);
76 if (rval) {
77 printk(KERN_ERR PFX "Failed to allocate conn id for "
78 "port_id (%6x)\n", rport->port_id);
79 goto ofld_err;
80 }
81
82 /* Allocate session resources */
83 rval = bnx2fc_alloc_session_resc(hba, tgt);
84 if (rval) {
85 printk(KERN_ERR PFX "Failed to allocate resources\n");
86 goto ofld_err;
87 }
88
89 /*
90 * Initialize FCoE session offload process.
91 * Upon completion of offload process add
92 * rport to list of rports
93 */
94retry_ofld:
95 clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
96 rval = bnx2fc_send_session_ofld_req(port, tgt);
97 if (rval) {
98 printk(KERN_ERR PFX "ofld_req failed\n");
99 goto ofld_err;
100 }
101
102 /*
103 * wait for the session is offloaded and enabled. 3 Secs
104 * should be ample time for this process to complete.
105 */
106 setup_timer(&tgt->ofld_timer, bnx2fc_ofld_timer, (unsigned long)tgt);
107 mod_timer(&tgt->ofld_timer, jiffies + BNX2FC_FW_TIMEOUT);
108
109 wait_event_interruptible(tgt->ofld_wait,
110 (test_bit(
111 BNX2FC_FLAG_OFLD_REQ_CMPL,
112 &tgt->flags)));
113 if (signal_pending(current))
114 flush_signals(current);
115
116 del_timer_sync(&tgt->ofld_timer);
117
118 if (!(test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags))) {
119 if (test_and_clear_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE,
120 &tgt->flags)) {
121 BNX2FC_TGT_DBG(tgt, "ctx_alloc_failure, "
122 "retry ofld..%d\n", i++);
123 msleep_interruptible(1000);
124 if (i > 3) {
125 i = 0;
126 goto ofld_err;
127 }
128 goto retry_ofld;
129 }
130 goto ofld_err;
131 }
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);
136 }
137 /* Arm CQ */
138 bnx2fc_arm_cq(tgt);
139 return;
140
141ofld_err:
142 /* couldn't offload the session. log off from this rport */
143 BNX2FC_TGT_DBG(tgt, "bnx2fc_offload_session - offload error\n");
144 lport->tt.rport_logoff(rdata);
145 /* Free session resources */
146 bnx2fc_free_session_resc(hba, tgt);
147 if (tgt->fcoe_conn_id != -1)
148 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
149}
150
151void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
152{
153 struct bnx2fc_cmd *io_req;
154 struct list_head *list;
155 struct list_head *tmp;
156 int rc;
157 int i = 0;
158 BNX2FC_TGT_DBG(tgt, "Entered flush_active_ios - %d\n",
159 tgt->num_active_ios.counter);
160
161 spin_lock_bh(&tgt->tgt_lock);
162 tgt->flush_in_prog = 1;
163
164 list_for_each_safe(list, tmp, &tgt->active_cmd_queue) {
165 i++;
166 io_req = (struct bnx2fc_cmd *)list;
167 list_del_init(&io_req->link);
168 io_req->on_active_queue = 0;
169 BNX2FC_IO_DBG(io_req, "cmd_queue cleanup\n");
170
171 if (cancel_delayed_work(&io_req->timeout_work)) {
172 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
173 &io_req->req_flags)) {
174 /* Handle eh_abort timeout */
175 BNX2FC_IO_DBG(io_req, "eh_abort for IO "
176 "cleaned up\n");
177 complete(&io_req->tm_done);
178 }
179 kref_put(&io_req->refcount,
180 bnx2fc_cmd_release); /* drop timer hold */
181 }
182
183 set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags);
184 set_bit(BNX2FC_FLAG_IO_CLEANUP, &io_req->req_flags);
185 rc = bnx2fc_initiate_cleanup(io_req);
186 BUG_ON(rc);
187 }
188
189 list_for_each_safe(list, tmp, &tgt->els_queue) {
190 i++;
191 io_req = (struct bnx2fc_cmd *)list;
192 list_del_init(&io_req->link);
193 io_req->on_active_queue = 0;
194
195 BNX2FC_IO_DBG(io_req, "els_queue cleanup\n");
196
197 if (cancel_delayed_work(&io_req->timeout_work))
198 kref_put(&io_req->refcount,
199 bnx2fc_cmd_release); /* drop timer hold */
200
201 if ((io_req->cb_func) && (io_req->cb_arg)) {
202 io_req->cb_func(io_req->cb_arg);
203 io_req->cb_arg = NULL;
204 }
205
206 rc = bnx2fc_initiate_cleanup(io_req);
207 BUG_ON(rc);
208 }
209
210 list_for_each_safe(list, tmp, &tgt->io_retire_queue) {
211 i++;
212 io_req = (struct bnx2fc_cmd *)list;
213 list_del_init(&io_req->link);
214
215 BNX2FC_IO_DBG(io_req, "retire_queue flush\n");
216
217 if (cancel_delayed_work(&io_req->timeout_work))
218 kref_put(&io_req->refcount, bnx2fc_cmd_release);
219
220 clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
221 }
222
223 BNX2FC_TGT_DBG(tgt, "IOs flushed = %d\n", i);
224 i = 0;
225 spin_unlock_bh(&tgt->tgt_lock);
226 /* wait for active_ios to go to 0 */
227 while ((tgt->num_active_ios.counter != 0) && (i++ < BNX2FC_WAIT_CNT))
228 msleep(25);
229 if (tgt->num_active_ios.counter != 0)
230 printk(KERN_ERR PFX "CLEANUP on port 0x%x:"
231 " active_ios = %d\n",
232 tgt->rdata->ids.port_id, tgt->num_active_ios.counter);
233 spin_lock_bh(&tgt->tgt_lock);
234 tgt->flush_in_prog = 0;
235 spin_unlock_bh(&tgt->tgt_lock);
236}
237
238static void bnx2fc_upload_session(struct fcoe_port *port,
239 struct bnx2fc_rport *tgt)
240{
241 struct bnx2fc_interface *interface = port->priv;
242 struct bnx2fc_hba *hba = interface->hba;
243
244 BNX2FC_TGT_DBG(tgt, "upload_session: active_ios = %d\n",
245 tgt->num_active_ios.counter);
246
247 /*
248 * Called with hba->hba_mutex held.
249 * This is a blocking call
250 */
251 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
252 bnx2fc_send_session_disable_req(port, tgt);
253
254 /*
255 * wait for upload to complete. 3 Secs
256 * should be sufficient time for this process to complete.
257 */
258 setup_timer(&tgt->upld_timer, bnx2fc_upld_timer, (unsigned long)tgt);
259 mod_timer(&tgt->upld_timer, jiffies + BNX2FC_FW_TIMEOUT);
260
261 BNX2FC_TGT_DBG(tgt, "waiting for disable compl\n");
262 wait_event_interruptible(tgt->upld_wait,
263 (test_bit(
264 BNX2FC_FLAG_UPLD_REQ_COMPL,
265 &tgt->flags)));
266
267 if (signal_pending(current))
268 flush_signals(current);
269
270 del_timer_sync(&tgt->upld_timer);
271
272 /*
273 * traverse thru the active_q and tmf_q and cleanup
274 * IOs in these lists
275 */
276 BNX2FC_TGT_DBG(tgt, "flush/upload - disable wait flags = 0x%lx\n",
277 tgt->flags);
278 bnx2fc_flush_active_ios(tgt);
279
280 /* Issue destroy KWQE */
281 if (test_bit(BNX2FC_FLAG_DISABLED, &tgt->flags)) {
282 BNX2FC_TGT_DBG(tgt, "send destroy req\n");
283 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
284 bnx2fc_send_session_destroy_req(hba, tgt);
285
286 /* wait for destroy to complete */
287 setup_timer(&tgt->upld_timer,
288 bnx2fc_upld_timer, (unsigned long)tgt);
289 mod_timer(&tgt->upld_timer, jiffies + BNX2FC_FW_TIMEOUT);
290
291 wait_event_interruptible(tgt->upld_wait,
292 (test_bit(
293 BNX2FC_FLAG_UPLD_REQ_COMPL,
294 &tgt->flags)));
295
296 if (!(test_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags)))
297 printk(KERN_ERR PFX "ERROR!! destroy timed out\n");
298
299 BNX2FC_TGT_DBG(tgt, "destroy wait complete flags = 0x%lx\n",
300 tgt->flags);
301 if (signal_pending(current))
302 flush_signals(current);
303
304 del_timer_sync(&tgt->upld_timer);
305
306 } else
307 printk(KERN_ERR PFX "ERROR!! DISABLE req timed out, destroy"
308 " not sent to FW\n");
309
310 /* Free session resources */
311 bnx2fc_free_session_resc(hba, tgt);
312 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
313}
314
315static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
316 struct fcoe_port *port,
317 struct fc_rport_priv *rdata)
318{
319
320 struct fc_rport *rport = rdata->rport;
321 struct bnx2fc_interface *interface = port->priv;
322 struct bnx2fc_hba *hba = interface->hba;
323 struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
324 struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
325
326 tgt->rport = rport;
327 tgt->rdata = rdata;
328 tgt->port = port;
329
330 if (hba->num_ofld_sess >= BNX2FC_NUM_MAX_SESS) {
331 BNX2FC_TGT_DBG(tgt, "exceeded max sessions. logoff this tgt\n");
332 tgt->fcoe_conn_id = -1;
333 return -1;
334 }
335
336 tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
337 if (tgt->fcoe_conn_id == -1)
338 return -1;
339
340 BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n", tgt->fcoe_conn_id);
341
342 tgt->max_sqes = BNX2FC_SQ_WQES_MAX;
343 tgt->max_rqes = BNX2FC_RQ_WQES_MAX;
344 tgt->max_cqes = BNX2FC_CQ_WQES_MAX;
345 atomic_set(&tgt->free_sqes, BNX2FC_SQ_WQES_MAX);
346
347 /* Initialize the toggle bit */
348 tgt->sq_curr_toggle_bit = 1;
349 tgt->cq_curr_toggle_bit = 1;
350 tgt->sq_prod_idx = 0;
351 tgt->cq_cons_idx = 0;
352 tgt->rq_prod_idx = 0x8000;
353 tgt->rq_cons_idx = 0;
354 atomic_set(&tgt->num_active_ios, 0);
355
356 if (rdata->flags & FC_RP_FLAGS_RETRY) {
357 tgt->dev_type = TYPE_TAPE;
358 tgt->io_timeout = 0; /* use default ULP timeout */
359 } else {
360 tgt->dev_type = TYPE_DISK;
361 tgt->io_timeout = BNX2FC_IO_TIMEOUT;
362 }
363
364 /* initialize sq doorbell */
365 sq_db->header.header = B577XX_DOORBELL_HDR_DB_TYPE;
366 sq_db->header.header |= B577XX_FCOE_CONNECTION_TYPE <<
367 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT;
368 /* initialize rx doorbell */
369 rx_db->hdr.header = ((0x1 << B577XX_DOORBELL_HDR_RX_SHIFT) |
370 (0x1 << B577XX_DOORBELL_HDR_DB_TYPE_SHIFT) |
371 (B577XX_FCOE_CONNECTION_TYPE <<
372 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT));
373 rx_db->params = (0x2 << B577XX_FCOE_RX_DOORBELL_NEGATIVE_ARM_SHIFT) |
374 (0x3 << B577XX_FCOE_RX_DOORBELL_OPCODE_SHIFT);
375
376 spin_lock_init(&tgt->tgt_lock);
377 spin_lock_init(&tgt->cq_lock);
378
379 /* Initialize active_cmd_queue list */
380 INIT_LIST_HEAD(&tgt->active_cmd_queue);
381
382 /* Initialize IO retire queue */
383 INIT_LIST_HEAD(&tgt->io_retire_queue);
384
385 INIT_LIST_HEAD(&tgt->els_queue);
386
387 /* Initialize active_tm_queue list */
388 INIT_LIST_HEAD(&tgt->active_tm_queue);
389
390 init_waitqueue_head(&tgt->ofld_wait);
391 init_waitqueue_head(&tgt->upld_wait);
392
393 return 0;
394}
395
396/**
397 * This event_callback is called after successful completion of libfc
398 * initiated target login. bnx2fc can proceed with initiating the session
399 * establishment.
400 */
401void bnx2fc_rport_event_handler(struct fc_lport *lport,
402 struct fc_rport_priv *rdata,
403 enum fc_rport_event event)
404{
405 struct fcoe_port *port = lport_priv(lport);
406 struct bnx2fc_interface *interface = port->priv;
407 struct bnx2fc_hba *hba = interface->hba;
408 struct fc_rport *rport = rdata->rport;
409 struct fc_rport_libfc_priv *rp;
410 struct bnx2fc_rport *tgt;
411 u32 port_id;
412
413 BNX2FC_HBA_DBG(lport, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
414 event, rdata->ids.port_id);
415 switch (event) {
416 case RPORT_EV_READY:
417 if (!rport) {
418 printk(KERN_ERR PFX "rport is NULL: ERROR!\n");
419 break;
420 }
421
422 rp = rport->dd_data;
423 if (rport->port_id == FC_FID_DIR_SERV) {
424 /*
425 * bnx2fc_rport structure doesn't exist for
426 * directory server.
427 * We should not come here, as lport will
428 * take care of fabric login
429 */
430 printk(KERN_ERR PFX "%x - rport_event_handler ERROR\n",
431 rdata->ids.port_id);
432 break;
433 }
434
435 if (rdata->spp_type != FC_TYPE_FCP) {
436 BNX2FC_HBA_DBG(lport, "not FCP type target."
437 " not offloading\n");
438 break;
439 }
440 if (!(rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET)) {
441 BNX2FC_HBA_DBG(lport, "not FCP_TARGET"
442 " not offloading\n");
443 break;
444 }
445
446 /*
447 * Offlaod process is protected with hba mutex.
448 * Use the same mutex_lock for upload process too
449 */
450 mutex_lock(&hba->hba_mutex);
451 tgt = (struct bnx2fc_rport *)&rp[1];
452
453 /* This can happen when ADISC finds the same target */
454 if (test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags)) {
455 BNX2FC_TGT_DBG(tgt, "already offloaded\n");
456 mutex_unlock(&hba->hba_mutex);
457 return;
458 }
459
460 /*
461 * Offload the session. This is a blocking call, and will
462 * wait until the session is offloaded.
463 */
464 bnx2fc_offload_session(port, tgt, rdata);
465
466 BNX2FC_TGT_DBG(tgt, "OFFLOAD num_ofld_sess = %d\n",
467 hba->num_ofld_sess);
468
469 if (test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags)) {
470 /*
471 * Session is offloaded and enabled. Map
472 * doorbell register for this target
473 */
474 BNX2FC_TGT_DBG(tgt, "sess offloaded\n");
475 /* This counter is protected with hba mutex */
476 hba->num_ofld_sess++;
477
478 set_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
479 } else {
480 /*
481 * Offload or enable would have failed.
482 * In offload/enable completion path, the
483 * rport would have already been removed
484 */
485 BNX2FC_TGT_DBG(tgt, "Port is being logged off as "
486 "offloaded flag not set\n");
487 }
488 mutex_unlock(&hba->hba_mutex);
489 break;
490 case RPORT_EV_LOGO:
491 case RPORT_EV_FAILED:
492 case RPORT_EV_STOP:
493 port_id = rdata->ids.port_id;
494 if (port_id == FC_FID_DIR_SERV)
495 break;
496
497 if (!rport) {
498 printk(KERN_INFO PFX "%x - rport not created Yet!!\n",
499 port_id);
500 break;
501 }
502 rp = rport->dd_data;
503 mutex_lock(&hba->hba_mutex);
504 /*
505 * Perform session upload. Note that rdata->peers is already
506 * removed from disc->rports list before we get this event.
507 */
508 tgt = (struct bnx2fc_rport *)&rp[1];
509
510 if (!(test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags))) {
511 mutex_unlock(&hba->hba_mutex);
512 break;
513 }
514 clear_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
515
516 bnx2fc_upload_session(port, tgt);
517 hba->num_ofld_sess--;
518 BNX2FC_TGT_DBG(tgt, "UPLOAD num_ofld_sess = %d\n",
519 hba->num_ofld_sess);
520 /*
521 * Try to wake up the linkdown wait thread. If num_ofld_sess
522 * is 0, the waiting therad wakes up
523 */
524 if ((hba->wait_for_link_down) &&
525 (hba->num_ofld_sess == 0)) {
526 wake_up_interruptible(&hba->shutdown_wait);
527 }
528 if (test_bit(BNX2FC_FLAG_EXPL_LOGO, &tgt->flags)) {
529 printk(KERN_ERR PFX "Relogin to the tgt\n");
530 mutex_lock(&lport->disc.disc_mutex);
531 lport->tt.rport_login(rdata);
532 mutex_unlock(&lport->disc.disc_mutex);
533 }
534 mutex_unlock(&hba->hba_mutex);
535
536 break;
537
538 case RPORT_EV_NONE:
539 break;
540 }
541}
542
543/**
544 * bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
545 *
546 * @port: fcoe_port struct to lookup the target port on
547 * @port_id: The remote port ID to look up
548 */
549struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
550 u32 port_id)
551{
552 struct bnx2fc_interface *interface = port->priv;
553 struct bnx2fc_hba *hba = interface->hba;
554 struct bnx2fc_rport *tgt;
555 struct fc_rport_priv *rdata;
556 int i;
557
558 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
559 tgt = hba->tgt_ofld_list[i];
560 if ((tgt) && (tgt->port == port)) {
561 rdata = tgt->rdata;
562 if (rdata->ids.port_id == port_id) {
563 if (rdata->rp_state != RPORT_ST_DELETE) {
564 BNX2FC_TGT_DBG(tgt, "rport "
565 "obtained\n");
566 return tgt;
567 } else {
568 BNX2FC_TGT_DBG(tgt, "rport 0x%x "
569 "is in DELETED state\n",
570 rdata->ids.port_id);
571 return NULL;
572 }
573 }
574 }
575 }
576 return NULL;
577}
578
579
580/**
581 * bnx2fc_alloc_conn_id - allocates FCOE Connection id
582 *
583 * @hba: pointer to adapter structure
584 * @tgt: pointer to bnx2fc_rport structure
585 */
586static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
587 struct bnx2fc_rport *tgt)
588{
589 u32 conn_id, next;
590
591 /* called with hba mutex held */
592
593 /*
594 * tgt_ofld_list access is synchronized using
595 * both hba mutex and hba lock. Atleast hba mutex or
596 * hba lock needs to be held for read access.
597 */
598
599 spin_lock_bh(&hba->hba_lock);
600 next = hba->next_conn_id;
601 conn_id = hba->next_conn_id++;
602 if (hba->next_conn_id == BNX2FC_NUM_MAX_SESS)
603 hba->next_conn_id = 0;
604
605 while (hba->tgt_ofld_list[conn_id] != NULL) {
606 conn_id++;
607 if (conn_id == BNX2FC_NUM_MAX_SESS)
608 conn_id = 0;
609
610 if (conn_id == next) {
611 /* No free conn_ids are available */
612 spin_unlock_bh(&hba->hba_lock);
613 return -1;
614 }
615 }
616 hba->tgt_ofld_list[conn_id] = tgt;
617 tgt->fcoe_conn_id = conn_id;
618 spin_unlock_bh(&hba->hba_lock);
619 return conn_id;
620}
621
622static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id)
623{
624 /* called with hba mutex held */
625 spin_lock_bh(&hba->hba_lock);
626 hba->tgt_ofld_list[conn_id] = NULL;
627 hba->next_conn_id = conn_id;
628 spin_unlock_bh(&hba->hba_lock);
629}
630
631/**
632 *bnx2fc_alloc_session_resc - Allocate qp resources for the session
633 *
634 */
635static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
636 struct bnx2fc_rport *tgt)
637{
638 dma_addr_t page;
639 int num_pages;
640 u32 *pbl;
641
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;
645
646 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
647 &tgt->sq_dma, GFP_KERNEL);
648 if (!tgt->sq) {
649 printk(KERN_ERR PFX "unable to allocate SQ memory %d\n",
650 tgt->sq_mem_size);
651 goto mem_alloc_failure;
652 }
653 memset(tgt->sq, 0, tgt->sq_mem_size);
654
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;
658
659 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
660 &tgt->cq_dma, GFP_KERNEL);
661 if (!tgt->cq) {
662 printk(KERN_ERR PFX "unable to allocate CQ memory %d\n",
663 tgt->cq_mem_size);
664 goto mem_alloc_failure;
665 }
666 memset(tgt->cq, 0, tgt->cq_mem_size);
667
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;
671
672 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
673 &tgt->rq_dma, GFP_KERNEL);
674 if (!tgt->rq) {
675 printk(KERN_ERR PFX "unable to allocate RQ memory %d\n",
676 tgt->rq_mem_size);
677 goto mem_alloc_failure;
678 }
679 memset(tgt->rq, 0, tgt->rq_mem_size);
680
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;
683
684 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
685 &tgt->rq_pbl_dma, GFP_KERNEL);
686 if (!tgt->rq_pbl) {
687 printk(KERN_ERR PFX "unable to allocate RQ PBL %d\n",
688 tgt->rq_pbl_size);
689 goto mem_alloc_failure;
690 }
691
692 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
693 num_pages = tgt->rq_mem_size / PAGE_SIZE;
694 page = tgt->rq_dma;
695 pbl = (u32 *)tgt->rq_pbl;
696
697 while (num_pages--) {
698 *pbl = (u32)page;
699 pbl++;
700 *pbl = (u32)((u64)page >> 32);
701 pbl++;
702 page += PAGE_SIZE;
703 }
704
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)) &
708 PAGE_MASK;
709
710 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
711 &tgt->xferq_dma, GFP_KERNEL);
712 if (!tgt->xferq) {
713 printk(KERN_ERR PFX "unable to allocate XFERQ %d\n",
714 tgt->xferq_mem_size);
715 goto mem_alloc_failure;
716 }
717 memset(tgt->xferq, 0, tgt->xferq_mem_size);
718
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)) &
722 PAGE_MASK;
723
724 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
725 &tgt->confq_dma, GFP_KERNEL);
726 if (!tgt->confq) {
727 printk(KERN_ERR PFX "unable to allocate CONFQ %d\n",
728 tgt->confq_mem_size);
729 goto mem_alloc_failure;
730 }
731 memset(tgt->confq, 0, tgt->confq_mem_size);
732
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;
737
738 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
739 tgt->confq_pbl_size,
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;
745 }
746
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;
751
752 while (num_pages--) {
753 *pbl = (u32)page;
754 pbl++;
755 *pbl = (u32)((u64)page >> 32);
756 pbl++;
757 page += PAGE_SIZE;
758 }
759
760 /* Allocate and map ConnDB */
761 tgt->conn_db_mem_size = sizeof(struct fcoe_conn_db);
762
763 tgt->conn_db = dma_alloc_coherent(&hba->pcidev->dev,
764 tgt->conn_db_mem_size,
765 &tgt->conn_db_dma, GFP_KERNEL);
766 if (!tgt->conn_db) {
767 printk(KERN_ERR PFX "unable to allocate conn_db %d\n",
768 tgt->conn_db_mem_size);
769 goto mem_alloc_failure;
770 }
771 memset(tgt->conn_db, 0, tgt->conn_db_mem_size);
772
773
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)) &
777 PAGE_MASK;
778
779 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
780 &tgt->lcq_dma, GFP_KERNEL);
781
782 if (!tgt->lcq) {
783 printk(KERN_ERR PFX "unable to allocate lcq %d\n",
784 tgt->lcq_mem_size);
785 goto mem_alloc_failure;
786 }
787 memset(tgt->lcq, 0, tgt->lcq_mem_size);
788
789 tgt->conn_db->rq_prod = 0x8000;
790
791 return 0;
792
793mem_alloc_failure:
794 bnx2fc_free_session_resc(hba, tgt);
795 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
796 return -ENOMEM;
797}
798
799/**
800 * bnx2i_free_session_resc - free qp resources for the session
801 *
802 * @hba: adapter structure pointer
803 * @tgt: bnx2fc_rport structure pointer
804 *
805 * Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
806 */
807static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
808 struct bnx2fc_rport *tgt)
809{
810 BNX2FC_TGT_DBG(tgt, "Freeing up session resources\n");
811
812 if (tgt->ctx_base) {
813 iounmap(tgt->ctx_base);
814 tgt->ctx_base = NULL;
815 }
816
817 spin_lock_bh(&tgt->cq_lock);
818 /* Free LCQ */
819 if (tgt->lcq) {
820 dma_free_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
821 tgt->lcq, tgt->lcq_dma);
822 tgt->lcq = NULL;
823 }
824 /* Free connDB */
825 if (tgt->conn_db) {
826 dma_free_coherent(&hba->pcidev->dev, tgt->conn_db_mem_size,
827 tgt->conn_db, tgt->conn_db_dma);
828 tgt->conn_db = NULL;
829 }
830 /* Free confq and confq pbl */
831 if (tgt->confq_pbl) {
832 dma_free_coherent(&hba->pcidev->dev, tgt->confq_pbl_size,
833 tgt->confq_pbl, tgt->confq_pbl_dma);
834 tgt->confq_pbl = NULL;
835 }
836 if (tgt->confq) {
837 dma_free_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
838 tgt->confq, tgt->confq_dma);
839 tgt->confq = NULL;
840 }
841 /* Free XFERQ */
842 if (tgt->xferq) {
843 dma_free_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
844 tgt->xferq, tgt->xferq_dma);
845 tgt->xferq = NULL;
846 }
847 /* Free RQ PBL and RQ */
848 if (tgt->rq_pbl) {
849 dma_free_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
850 tgt->rq_pbl, tgt->rq_pbl_dma);
851 tgt->rq_pbl = NULL;
852 }
853 if (tgt->rq) {
854 dma_free_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
855 tgt->rq, tgt->rq_dma);
856 tgt->rq = NULL;
857 }
858 /* Free CQ */
859 if (tgt->cq) {
860 dma_free_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
861 tgt->cq, tgt->cq_dma);
862 tgt->cq = NULL;
863 }
864 /* Free SQ */
865 if (tgt->sq) {
866 dma_free_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
867 tgt->sq, tgt->sq_dma);
868 tgt->sq = NULL;
869 }
870 spin_unlock_bh(&tgt->cq_lock);
871}
1/* bnx2fc_tgt.c: QLogic 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.
4 *
5 * Copyright (c) 2008-2013 Broadcom Corporation
6 * Copyright (c) 2014-2015 QLogic Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
11 *
12 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
13 */
14
15#include "bnx2fc.h"
16static void bnx2fc_upld_timer(unsigned long data);
17static void bnx2fc_ofld_timer(unsigned long data);
18static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
19 struct fcoe_port *port,
20 struct fc_rport_priv *rdata);
21static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
22 struct bnx2fc_rport *tgt);
23static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
24 struct bnx2fc_rport *tgt);
25static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
26 struct bnx2fc_rport *tgt);
27static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id);
28
29static void bnx2fc_upld_timer(unsigned long data)
30{
31
32 struct bnx2fc_rport *tgt = (struct bnx2fc_rport *)data;
33
34 BNX2FC_TGT_DBG(tgt, "upld_timer - Upload compl not received!!\n");
35 /* fake upload completion */
36 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
37 clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
38 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
39 wake_up_interruptible(&tgt->upld_wait);
40}
41
42static void bnx2fc_ofld_timer(unsigned long data)
43{
44
45 struct bnx2fc_rport *tgt = (struct bnx2fc_rport *)data;
46
47 BNX2FC_TGT_DBG(tgt, "entered bnx2fc_ofld_timer\n");
48 /* NOTE: This function should never be called, as
49 * offload should never timeout
50 */
51 /*
52 * If the timer has expired, this session is dead
53 * Clear offloaded flag and logout of this device.
54 * Since OFFLOADED flag is cleared, this case
55 * will be considered as offload error and the
56 * port will be logged off, and conn_id, session
57 * resources are freed up in bnx2fc_offload_session
58 */
59 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
60 clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
61 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
62 wake_up_interruptible(&tgt->ofld_wait);
63}
64
65static void bnx2fc_ofld_wait(struct bnx2fc_rport *tgt)
66{
67 setup_timer(&tgt->ofld_timer, bnx2fc_ofld_timer, (unsigned long)tgt);
68 mod_timer(&tgt->ofld_timer, jiffies + BNX2FC_FW_TIMEOUT);
69
70 wait_event_interruptible(tgt->ofld_wait,
71 (test_bit(
72 BNX2FC_FLAG_OFLD_REQ_CMPL,
73 &tgt->flags)));
74 if (signal_pending(current))
75 flush_signals(current);
76 del_timer_sync(&tgt->ofld_timer);
77}
78
79static void bnx2fc_offload_session(struct fcoe_port *port,
80 struct bnx2fc_rport *tgt,
81 struct fc_rport_priv *rdata)
82{
83 struct fc_lport *lport = rdata->local_port;
84 struct fc_rport *rport = rdata->rport;
85 struct bnx2fc_interface *interface = port->priv;
86 struct bnx2fc_hba *hba = interface->hba;
87 int rval;
88 int i = 0;
89
90 /* Initialize bnx2fc_rport */
91 /* NOTE: tgt is already bzero'd */
92 rval = bnx2fc_init_tgt(tgt, port, rdata);
93 if (rval) {
94 printk(KERN_ERR PFX "Failed to allocate conn id for "
95 "port_id (%6x)\n", rport->port_id);
96 goto tgt_init_err;
97 }
98
99 /* Allocate session resources */
100 rval = bnx2fc_alloc_session_resc(hba, tgt);
101 if (rval) {
102 printk(KERN_ERR PFX "Failed to allocate resources\n");
103 goto ofld_err;
104 }
105
106 /*
107 * Initialize FCoE session offload process.
108 * Upon completion of offload process add
109 * rport to list of rports
110 */
111retry_ofld:
112 clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
113 rval = bnx2fc_send_session_ofld_req(port, tgt);
114 if (rval) {
115 printk(KERN_ERR PFX "ofld_req failed\n");
116 goto ofld_err;
117 }
118
119 /*
120 * wait for the session is offloaded and enabled. 3 Secs
121 * should be ample time for this process to complete.
122 */
123 bnx2fc_ofld_wait(tgt);
124
125 if (!(test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags))) {
126 if (test_and_clear_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE,
127 &tgt->flags)) {
128 BNX2FC_TGT_DBG(tgt, "ctx_alloc_failure, "
129 "retry ofld..%d\n", i++);
130 msleep_interruptible(1000);
131 if (i > 3) {
132 i = 0;
133 goto ofld_err;
134 }
135 goto retry_ofld;
136 }
137 goto ofld_err;
138 }
139 if (bnx2fc_map_doorbell(tgt)) {
140 printk(KERN_ERR PFX "map doorbell failed - no mem\n");
141 goto ofld_err;
142 }
143 clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
144 rval = bnx2fc_send_session_enable_req(port, tgt);
145 if (rval) {
146 pr_err(PFX "enable session failed\n");
147 goto ofld_err;
148 }
149 bnx2fc_ofld_wait(tgt);
150 if (!(test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)))
151 goto ofld_err;
152 return;
153
154ofld_err:
155 /* couldn't offload the session. log off from this rport */
156 BNX2FC_TGT_DBG(tgt, "bnx2fc_offload_session - offload error\n");
157 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
158 /* Free session resources */
159 bnx2fc_free_session_resc(hba, tgt);
160tgt_init_err:
161 if (tgt->fcoe_conn_id != -1)
162 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
163 lport->tt.rport_logoff(rdata);
164}
165
166void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
167{
168 struct bnx2fc_cmd *io_req;
169 struct bnx2fc_cmd *tmp;
170 int rc;
171 int i = 0;
172 BNX2FC_TGT_DBG(tgt, "Entered flush_active_ios - %d\n",
173 tgt->num_active_ios.counter);
174
175 spin_lock_bh(&tgt->tgt_lock);
176 tgt->flush_in_prog = 1;
177
178 list_for_each_entry_safe(io_req, tmp, &tgt->active_cmd_queue, link) {
179 i++;
180 list_del_init(&io_req->link);
181 io_req->on_active_queue = 0;
182 BNX2FC_IO_DBG(io_req, "cmd_queue cleanup\n");
183
184 if (cancel_delayed_work(&io_req->timeout_work)) {
185 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
186 &io_req->req_flags)) {
187 /* Handle eh_abort timeout */
188 BNX2FC_IO_DBG(io_req, "eh_abort for IO "
189 "cleaned up\n");
190 complete(&io_req->tm_done);
191 }
192 kref_put(&io_req->refcount,
193 bnx2fc_cmd_release); /* drop timer hold */
194 }
195
196 set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags);
197 set_bit(BNX2FC_FLAG_IO_CLEANUP, &io_req->req_flags);
198
199 /* Do not issue cleanup when disable request failed */
200 if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
201 bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
202 else {
203 rc = bnx2fc_initiate_cleanup(io_req);
204 BUG_ON(rc);
205 }
206 }
207
208 list_for_each_entry_safe(io_req, tmp, &tgt->active_tm_queue, link) {
209 i++;
210 list_del_init(&io_req->link);
211 io_req->on_tmf_queue = 0;
212 BNX2FC_IO_DBG(io_req, "tm_queue cleanup\n");
213 if (io_req->wait_for_comp)
214 complete(&io_req->tm_done);
215 }
216
217 list_for_each_entry_safe(io_req, tmp, &tgt->els_queue, link) {
218 i++;
219 list_del_init(&io_req->link);
220 io_req->on_active_queue = 0;
221
222 BNX2FC_IO_DBG(io_req, "els_queue cleanup\n");
223
224 if (cancel_delayed_work(&io_req->timeout_work))
225 kref_put(&io_req->refcount,
226 bnx2fc_cmd_release); /* drop timer hold */
227
228 if ((io_req->cb_func) && (io_req->cb_arg)) {
229 io_req->cb_func(io_req->cb_arg);
230 io_req->cb_arg = NULL;
231 }
232
233 /* Do not issue cleanup when disable request failed */
234 if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
235 bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
236 else {
237 rc = bnx2fc_initiate_cleanup(io_req);
238 BUG_ON(rc);
239 }
240 }
241
242 list_for_each_entry_safe(io_req, tmp, &tgt->io_retire_queue, link) {
243 i++;
244 list_del_init(&io_req->link);
245
246 BNX2FC_IO_DBG(io_req, "retire_queue flush\n");
247
248 if (cancel_delayed_work(&io_req->timeout_work)) {
249 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
250 &io_req->req_flags)) {
251 /* Handle eh_abort timeout */
252 BNX2FC_IO_DBG(io_req, "eh_abort for IO "
253 "in retire_q\n");
254 if (io_req->wait_for_comp)
255 complete(&io_req->tm_done);
256 }
257 kref_put(&io_req->refcount, bnx2fc_cmd_release);
258 }
259
260 clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
261 }
262
263 BNX2FC_TGT_DBG(tgt, "IOs flushed = %d\n", i);
264 i = 0;
265 spin_unlock_bh(&tgt->tgt_lock);
266 /* wait for active_ios to go to 0 */
267 while ((tgt->num_active_ios.counter != 0) && (i++ < BNX2FC_WAIT_CNT))
268 msleep(25);
269 if (tgt->num_active_ios.counter != 0)
270 printk(KERN_ERR PFX "CLEANUP on port 0x%x:"
271 " active_ios = %d\n",
272 tgt->rdata->ids.port_id, tgt->num_active_ios.counter);
273 spin_lock_bh(&tgt->tgt_lock);
274 tgt->flush_in_prog = 0;
275 spin_unlock_bh(&tgt->tgt_lock);
276}
277
278static void bnx2fc_upld_wait(struct bnx2fc_rport *tgt)
279{
280 setup_timer(&tgt->upld_timer, bnx2fc_upld_timer, (unsigned long)tgt);
281 mod_timer(&tgt->upld_timer, jiffies + BNX2FC_FW_TIMEOUT);
282 wait_event_interruptible(tgt->upld_wait,
283 (test_bit(
284 BNX2FC_FLAG_UPLD_REQ_COMPL,
285 &tgt->flags)));
286 if (signal_pending(current))
287 flush_signals(current);
288 del_timer_sync(&tgt->upld_timer);
289}
290
291static void bnx2fc_upload_session(struct fcoe_port *port,
292 struct bnx2fc_rport *tgt)
293{
294 struct bnx2fc_interface *interface = port->priv;
295 struct bnx2fc_hba *hba = interface->hba;
296
297 BNX2FC_TGT_DBG(tgt, "upload_session: active_ios = %d\n",
298 tgt->num_active_ios.counter);
299
300 /*
301 * Called with hba->hba_mutex held.
302 * This is a blocking call
303 */
304 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
305 bnx2fc_send_session_disable_req(port, tgt);
306
307 /*
308 * wait for upload to complete. 3 Secs
309 * should be sufficient time for this process to complete.
310 */
311 BNX2FC_TGT_DBG(tgt, "waiting for disable compl\n");
312 bnx2fc_upld_wait(tgt);
313
314 /*
315 * traverse thru the active_q and tmf_q and cleanup
316 * IOs in these lists
317 */
318 BNX2FC_TGT_DBG(tgt, "flush/upload - disable wait flags = 0x%lx\n",
319 tgt->flags);
320 bnx2fc_flush_active_ios(tgt);
321
322 /* Issue destroy KWQE */
323 if (test_bit(BNX2FC_FLAG_DISABLED, &tgt->flags)) {
324 BNX2FC_TGT_DBG(tgt, "send destroy req\n");
325 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
326 bnx2fc_send_session_destroy_req(hba, tgt);
327
328 /* wait for destroy to complete */
329 bnx2fc_upld_wait(tgt);
330
331 if (!(test_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags)))
332 printk(KERN_ERR PFX "ERROR!! destroy timed out\n");
333
334 BNX2FC_TGT_DBG(tgt, "destroy wait complete flags = 0x%lx\n",
335 tgt->flags);
336
337 } else if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags)) {
338 printk(KERN_ERR PFX "ERROR!! DISABLE req failed, destroy"
339 " not sent to FW\n");
340 } else {
341 printk(KERN_ERR PFX "ERROR!! DISABLE req timed out, destroy"
342 " not sent to FW\n");
343 }
344
345 /* Free session resources */
346 bnx2fc_free_session_resc(hba, tgt);
347 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
348}
349
350static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
351 struct fcoe_port *port,
352 struct fc_rport_priv *rdata)
353{
354
355 struct fc_rport *rport = rdata->rport;
356 struct bnx2fc_interface *interface = port->priv;
357 struct bnx2fc_hba *hba = interface->hba;
358 struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
359 struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
360
361 tgt->rport = rport;
362 tgt->rdata = rdata;
363 tgt->port = port;
364
365 if (hba->num_ofld_sess >= BNX2FC_NUM_MAX_SESS) {
366 BNX2FC_TGT_DBG(tgt, "exceeded max sessions. logoff this tgt\n");
367 tgt->fcoe_conn_id = -1;
368 return -1;
369 }
370
371 tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
372 if (tgt->fcoe_conn_id == -1)
373 return -1;
374
375 BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n", tgt->fcoe_conn_id);
376
377 tgt->max_sqes = BNX2FC_SQ_WQES_MAX;
378 tgt->max_rqes = BNX2FC_RQ_WQES_MAX;
379 tgt->max_cqes = BNX2FC_CQ_WQES_MAX;
380 atomic_set(&tgt->free_sqes, BNX2FC_SQ_WQES_MAX);
381
382 /* Initialize the toggle bit */
383 tgt->sq_curr_toggle_bit = 1;
384 tgt->cq_curr_toggle_bit = 1;
385 tgt->sq_prod_idx = 0;
386 tgt->cq_cons_idx = 0;
387 tgt->rq_prod_idx = 0x8000;
388 tgt->rq_cons_idx = 0;
389 atomic_set(&tgt->num_active_ios, 0);
390 tgt->retry_delay_timestamp = 0;
391
392 if (rdata->flags & FC_RP_FLAGS_RETRY &&
393 rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET &&
394 !(rdata->ids.roles & FC_RPORT_ROLE_FCP_INITIATOR)) {
395 tgt->dev_type = TYPE_TAPE;
396 tgt->io_timeout = 0; /* use default ULP timeout */
397 } else {
398 tgt->dev_type = TYPE_DISK;
399 tgt->io_timeout = BNX2FC_IO_TIMEOUT;
400 }
401
402 /* initialize sq doorbell */
403 sq_db->header.header = B577XX_DOORBELL_HDR_DB_TYPE;
404 sq_db->header.header |= B577XX_FCOE_CONNECTION_TYPE <<
405 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT;
406 /* initialize rx doorbell */
407 rx_db->hdr.header = ((0x1 << B577XX_DOORBELL_HDR_RX_SHIFT) |
408 (0x1 << B577XX_DOORBELL_HDR_DB_TYPE_SHIFT) |
409 (B577XX_FCOE_CONNECTION_TYPE <<
410 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT));
411 rx_db->params = (0x2 << B577XX_FCOE_RX_DOORBELL_NEGATIVE_ARM_SHIFT) |
412 (0x3 << B577XX_FCOE_RX_DOORBELL_OPCODE_SHIFT);
413
414 spin_lock_init(&tgt->tgt_lock);
415 spin_lock_init(&tgt->cq_lock);
416
417 /* Initialize active_cmd_queue list */
418 INIT_LIST_HEAD(&tgt->active_cmd_queue);
419
420 /* Initialize IO retire queue */
421 INIT_LIST_HEAD(&tgt->io_retire_queue);
422
423 INIT_LIST_HEAD(&tgt->els_queue);
424
425 /* Initialize active_tm_queue list */
426 INIT_LIST_HEAD(&tgt->active_tm_queue);
427
428 init_waitqueue_head(&tgt->ofld_wait);
429 init_waitqueue_head(&tgt->upld_wait);
430
431 return 0;
432}
433
434/**
435 * This event_callback is called after successful completion of libfc
436 * initiated target login. bnx2fc can proceed with initiating the session
437 * establishment.
438 */
439void bnx2fc_rport_event_handler(struct fc_lport *lport,
440 struct fc_rport_priv *rdata,
441 enum fc_rport_event event)
442{
443 struct fcoe_port *port = lport_priv(lport);
444 struct bnx2fc_interface *interface = port->priv;
445 struct bnx2fc_hba *hba = interface->hba;
446 struct fc_rport *rport = rdata->rport;
447 struct fc_rport_libfc_priv *rp;
448 struct bnx2fc_rport *tgt;
449 u32 port_id;
450
451 BNX2FC_HBA_DBG(lport, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
452 event, rdata->ids.port_id);
453 switch (event) {
454 case RPORT_EV_READY:
455 if (!rport) {
456 printk(KERN_ERR PFX "rport is NULL: ERROR!\n");
457 break;
458 }
459
460 rp = rport->dd_data;
461 if (rport->port_id == FC_FID_DIR_SERV) {
462 /*
463 * bnx2fc_rport structure doesn't exist for
464 * directory server.
465 * We should not come here, as lport will
466 * take care of fabric login
467 */
468 printk(KERN_ERR PFX "%x - rport_event_handler ERROR\n",
469 rdata->ids.port_id);
470 break;
471 }
472
473 if (rdata->spp_type != FC_TYPE_FCP) {
474 BNX2FC_HBA_DBG(lport, "not FCP type target."
475 " not offloading\n");
476 break;
477 }
478 if (!(rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET)) {
479 BNX2FC_HBA_DBG(lport, "not FCP_TARGET"
480 " not offloading\n");
481 break;
482 }
483
484 /*
485 * Offlaod process is protected with hba mutex.
486 * Use the same mutex_lock for upload process too
487 */
488 mutex_lock(&hba->hba_mutex);
489 tgt = (struct bnx2fc_rport *)&rp[1];
490
491 /* This can happen when ADISC finds the same target */
492 if (test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)) {
493 BNX2FC_TGT_DBG(tgt, "already offloaded\n");
494 mutex_unlock(&hba->hba_mutex);
495 return;
496 }
497
498 /*
499 * Offload the session. This is a blocking call, and will
500 * wait until the session is offloaded.
501 */
502 bnx2fc_offload_session(port, tgt, rdata);
503
504 BNX2FC_TGT_DBG(tgt, "OFFLOAD num_ofld_sess = %d\n",
505 hba->num_ofld_sess);
506
507 if (test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)) {
508 /* Session is offloaded and enabled. */
509 BNX2FC_TGT_DBG(tgt, "sess offloaded\n");
510 /* This counter is protected with hba mutex */
511 hba->num_ofld_sess++;
512
513 set_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
514 } else {
515 /*
516 * Offload or enable would have failed.
517 * In offload/enable completion path, the
518 * rport would have already been removed
519 */
520 BNX2FC_TGT_DBG(tgt, "Port is being logged off as "
521 "offloaded flag not set\n");
522 }
523 mutex_unlock(&hba->hba_mutex);
524 break;
525 case RPORT_EV_LOGO:
526 case RPORT_EV_FAILED:
527 case RPORT_EV_STOP:
528 port_id = rdata->ids.port_id;
529 if (port_id == FC_FID_DIR_SERV)
530 break;
531
532 if (!rport) {
533 printk(KERN_INFO PFX "%x - rport not created Yet!!\n",
534 port_id);
535 break;
536 }
537 rp = rport->dd_data;
538 mutex_lock(&hba->hba_mutex);
539 /*
540 * Perform session upload. Note that rdata->peers is already
541 * removed from disc->rports list before we get this event.
542 */
543 tgt = (struct bnx2fc_rport *)&rp[1];
544
545 if (!(test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags))) {
546 mutex_unlock(&hba->hba_mutex);
547 break;
548 }
549 clear_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
550
551 bnx2fc_upload_session(port, tgt);
552 hba->num_ofld_sess--;
553 BNX2FC_TGT_DBG(tgt, "UPLOAD num_ofld_sess = %d\n",
554 hba->num_ofld_sess);
555 /*
556 * Try to wake up the linkdown wait thread. If num_ofld_sess
557 * is 0, the waiting therad wakes up
558 */
559 if ((hba->wait_for_link_down) &&
560 (hba->num_ofld_sess == 0)) {
561 wake_up_interruptible(&hba->shutdown_wait);
562 }
563 mutex_unlock(&hba->hba_mutex);
564
565 break;
566
567 case RPORT_EV_NONE:
568 break;
569 }
570}
571
572/**
573 * bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
574 *
575 * @port: fcoe_port struct to lookup the target port on
576 * @port_id: The remote port ID to look up
577 */
578struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
579 u32 port_id)
580{
581 struct bnx2fc_interface *interface = port->priv;
582 struct bnx2fc_hba *hba = interface->hba;
583 struct bnx2fc_rport *tgt;
584 struct fc_rport_priv *rdata;
585 int i;
586
587 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
588 tgt = hba->tgt_ofld_list[i];
589 if ((tgt) && (tgt->port == port)) {
590 rdata = tgt->rdata;
591 if (rdata->ids.port_id == port_id) {
592 if (rdata->rp_state != RPORT_ST_DELETE) {
593 BNX2FC_TGT_DBG(tgt, "rport "
594 "obtained\n");
595 return tgt;
596 } else {
597 BNX2FC_TGT_DBG(tgt, "rport 0x%x "
598 "is in DELETED state\n",
599 rdata->ids.port_id);
600 return NULL;
601 }
602 }
603 }
604 }
605 return NULL;
606}
607
608
609/**
610 * bnx2fc_alloc_conn_id - allocates FCOE Connection id
611 *
612 * @hba: pointer to adapter structure
613 * @tgt: pointer to bnx2fc_rport structure
614 */
615static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
616 struct bnx2fc_rport *tgt)
617{
618 u32 conn_id, next;
619
620 /* called with hba mutex held */
621
622 /*
623 * tgt_ofld_list access is synchronized using
624 * both hba mutex and hba lock. Atleast hba mutex or
625 * hba lock needs to be held for read access.
626 */
627
628 spin_lock_bh(&hba->hba_lock);
629 next = hba->next_conn_id;
630 conn_id = hba->next_conn_id++;
631 if (hba->next_conn_id == BNX2FC_NUM_MAX_SESS)
632 hba->next_conn_id = 0;
633
634 while (hba->tgt_ofld_list[conn_id] != NULL) {
635 conn_id++;
636 if (conn_id == BNX2FC_NUM_MAX_SESS)
637 conn_id = 0;
638
639 if (conn_id == next) {
640 /* No free conn_ids are available */
641 spin_unlock_bh(&hba->hba_lock);
642 return -1;
643 }
644 }
645 hba->tgt_ofld_list[conn_id] = tgt;
646 tgt->fcoe_conn_id = conn_id;
647 spin_unlock_bh(&hba->hba_lock);
648 return conn_id;
649}
650
651static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id)
652{
653 /* called with hba mutex held */
654 spin_lock_bh(&hba->hba_lock);
655 hba->tgt_ofld_list[conn_id] = NULL;
656 spin_unlock_bh(&hba->hba_lock);
657}
658
659/**
660 *bnx2fc_alloc_session_resc - Allocate qp resources for the session
661 *
662 */
663static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
664 struct bnx2fc_rport *tgt)
665{
666 dma_addr_t page;
667 int num_pages;
668 u32 *pbl;
669
670 /* Allocate and map SQ */
671 tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE;
672 tgt->sq_mem_size = (tgt->sq_mem_size + (CNIC_PAGE_SIZE - 1)) &
673 CNIC_PAGE_MASK;
674
675 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
676 &tgt->sq_dma, GFP_KERNEL);
677 if (!tgt->sq) {
678 printk(KERN_ERR PFX "unable to allocate SQ memory %d\n",
679 tgt->sq_mem_size);
680 goto mem_alloc_failure;
681 }
682 memset(tgt->sq, 0, tgt->sq_mem_size);
683
684 /* Allocate and map CQ */
685 tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
686 tgt->cq_mem_size = (tgt->cq_mem_size + (CNIC_PAGE_SIZE - 1)) &
687 CNIC_PAGE_MASK;
688
689 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
690 &tgt->cq_dma, GFP_KERNEL);
691 if (!tgt->cq) {
692 printk(KERN_ERR PFX "unable to allocate CQ memory %d\n",
693 tgt->cq_mem_size);
694 goto mem_alloc_failure;
695 }
696 memset(tgt->cq, 0, tgt->cq_mem_size);
697
698 /* Allocate and map RQ and RQ PBL */
699 tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
700 tgt->rq_mem_size = (tgt->rq_mem_size + (CNIC_PAGE_SIZE - 1)) &
701 CNIC_PAGE_MASK;
702
703 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
704 &tgt->rq_dma, GFP_KERNEL);
705 if (!tgt->rq) {
706 printk(KERN_ERR PFX "unable to allocate RQ memory %d\n",
707 tgt->rq_mem_size);
708 goto mem_alloc_failure;
709 }
710 memset(tgt->rq, 0, tgt->rq_mem_size);
711
712 tgt->rq_pbl_size = (tgt->rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
713 tgt->rq_pbl_size = (tgt->rq_pbl_size + (CNIC_PAGE_SIZE - 1)) &
714 CNIC_PAGE_MASK;
715
716 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
717 &tgt->rq_pbl_dma, GFP_KERNEL);
718 if (!tgt->rq_pbl) {
719 printk(KERN_ERR PFX "unable to allocate RQ PBL %d\n",
720 tgt->rq_pbl_size);
721 goto mem_alloc_failure;
722 }
723
724 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
725 num_pages = tgt->rq_mem_size / CNIC_PAGE_SIZE;
726 page = tgt->rq_dma;
727 pbl = (u32 *)tgt->rq_pbl;
728
729 while (num_pages--) {
730 *pbl = (u32)page;
731 pbl++;
732 *pbl = (u32)((u64)page >> 32);
733 pbl++;
734 page += CNIC_PAGE_SIZE;
735 }
736
737 /* Allocate and map XFERQ */
738 tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE;
739 tgt->xferq_mem_size = (tgt->xferq_mem_size + (CNIC_PAGE_SIZE - 1)) &
740 CNIC_PAGE_MASK;
741
742 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
743 &tgt->xferq_dma, GFP_KERNEL);
744 if (!tgt->xferq) {
745 printk(KERN_ERR PFX "unable to allocate XFERQ %d\n",
746 tgt->xferq_mem_size);
747 goto mem_alloc_failure;
748 }
749 memset(tgt->xferq, 0, tgt->xferq_mem_size);
750
751 /* Allocate and map CONFQ & CONFQ PBL */
752 tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
753 tgt->confq_mem_size = (tgt->confq_mem_size + (CNIC_PAGE_SIZE - 1)) &
754 CNIC_PAGE_MASK;
755
756 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
757 &tgt->confq_dma, GFP_KERNEL);
758 if (!tgt->confq) {
759 printk(KERN_ERR PFX "unable to allocate CONFQ %d\n",
760 tgt->confq_mem_size);
761 goto mem_alloc_failure;
762 }
763 memset(tgt->confq, 0, tgt->confq_mem_size);
764
765 tgt->confq_pbl_size =
766 (tgt->confq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
767 tgt->confq_pbl_size =
768 (tgt->confq_pbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
769
770 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
771 tgt->confq_pbl_size,
772 &tgt->confq_pbl_dma, GFP_KERNEL);
773 if (!tgt->confq_pbl) {
774 printk(KERN_ERR PFX "unable to allocate CONFQ PBL %d\n",
775 tgt->confq_pbl_size);
776 goto mem_alloc_failure;
777 }
778
779 memset(tgt->confq_pbl, 0, tgt->confq_pbl_size);
780 num_pages = tgt->confq_mem_size / CNIC_PAGE_SIZE;
781 page = tgt->confq_dma;
782 pbl = (u32 *)tgt->confq_pbl;
783
784 while (num_pages--) {
785 *pbl = (u32)page;
786 pbl++;
787 *pbl = (u32)((u64)page >> 32);
788 pbl++;
789 page += CNIC_PAGE_SIZE;
790 }
791
792 /* Allocate and map ConnDB */
793 tgt->conn_db_mem_size = sizeof(struct fcoe_conn_db);
794
795 tgt->conn_db = dma_alloc_coherent(&hba->pcidev->dev,
796 tgt->conn_db_mem_size,
797 &tgt->conn_db_dma, GFP_KERNEL);
798 if (!tgt->conn_db) {
799 printk(KERN_ERR PFX "unable to allocate conn_db %d\n",
800 tgt->conn_db_mem_size);
801 goto mem_alloc_failure;
802 }
803 memset(tgt->conn_db, 0, tgt->conn_db_mem_size);
804
805
806 /* Allocate and map LCQ */
807 tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE;
808 tgt->lcq_mem_size = (tgt->lcq_mem_size + (CNIC_PAGE_SIZE - 1)) &
809 CNIC_PAGE_MASK;
810
811 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
812 &tgt->lcq_dma, GFP_KERNEL);
813
814 if (!tgt->lcq) {
815 printk(KERN_ERR PFX "unable to allocate lcq %d\n",
816 tgt->lcq_mem_size);
817 goto mem_alloc_failure;
818 }
819 memset(tgt->lcq, 0, tgt->lcq_mem_size);
820
821 tgt->conn_db->rq_prod = 0x8000;
822
823 return 0;
824
825mem_alloc_failure:
826 return -ENOMEM;
827}
828
829/**
830 * bnx2i_free_session_resc - free qp resources for the session
831 *
832 * @hba: adapter structure pointer
833 * @tgt: bnx2fc_rport structure pointer
834 *
835 * Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
836 */
837static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
838 struct bnx2fc_rport *tgt)
839{
840 void __iomem *ctx_base_ptr;
841
842 BNX2FC_TGT_DBG(tgt, "Freeing up session resources\n");
843
844 spin_lock_bh(&tgt->cq_lock);
845 ctx_base_ptr = tgt->ctx_base;
846 tgt->ctx_base = NULL;
847
848 /* Free LCQ */
849 if (tgt->lcq) {
850 dma_free_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
851 tgt->lcq, tgt->lcq_dma);
852 tgt->lcq = NULL;
853 }
854 /* Free connDB */
855 if (tgt->conn_db) {
856 dma_free_coherent(&hba->pcidev->dev, tgt->conn_db_mem_size,
857 tgt->conn_db, tgt->conn_db_dma);
858 tgt->conn_db = NULL;
859 }
860 /* Free confq and confq pbl */
861 if (tgt->confq_pbl) {
862 dma_free_coherent(&hba->pcidev->dev, tgt->confq_pbl_size,
863 tgt->confq_pbl, tgt->confq_pbl_dma);
864 tgt->confq_pbl = NULL;
865 }
866 if (tgt->confq) {
867 dma_free_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
868 tgt->confq, tgt->confq_dma);
869 tgt->confq = NULL;
870 }
871 /* Free XFERQ */
872 if (tgt->xferq) {
873 dma_free_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
874 tgt->xferq, tgt->xferq_dma);
875 tgt->xferq = NULL;
876 }
877 /* Free RQ PBL and RQ */
878 if (tgt->rq_pbl) {
879 dma_free_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
880 tgt->rq_pbl, tgt->rq_pbl_dma);
881 tgt->rq_pbl = NULL;
882 }
883 if (tgt->rq) {
884 dma_free_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
885 tgt->rq, tgt->rq_dma);
886 tgt->rq = NULL;
887 }
888 /* Free CQ */
889 if (tgt->cq) {
890 dma_free_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
891 tgt->cq, tgt->cq_dma);
892 tgt->cq = NULL;
893 }
894 /* Free SQ */
895 if (tgt->sq) {
896 dma_free_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
897 tgt->sq, tgt->sq_dma);
898 tgt->sq = NULL;
899 }
900 spin_unlock_bh(&tgt->cq_lock);
901
902 if (ctx_base_ptr)
903 iounmap(ctx_base_ptr);
904}