blob: d9bae5672273762dba7d183b4bedcc5206c1f9fe [file] [log] [blame]
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001/* 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 *
Bhanu Prakash Gollapudicf122192013-03-08 13:28:53 -08005 * Copyright (c) 2008 - 2013 Broadcom Corporation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08006 *
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);
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -080036 clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080037 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
38 wake_up_interruptible(&tgt->upld_wait);
39}
40
41static void bnx2fc_ofld_timer(unsigned long data)
42{
43
44 struct bnx2fc_rport *tgt = (struct bnx2fc_rport *)data;
45
46 BNX2FC_TGT_DBG(tgt, "entered bnx2fc_ofld_timer\n");
47 /* NOTE: This function should never be called, as
48 * offload should never timeout
49 */
50 /*
51 * If the timer has expired, this session is dead
52 * Clear offloaded flag and logout of this device.
53 * Since OFFLOADED flag is cleared, this case
54 * will be considered as offload error and the
55 * port will be logged off, and conn_id, session
56 * resources are freed up in bnx2fc_offload_session
57 */
58 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -080059 clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080060 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
61 wake_up_interruptible(&tgt->ofld_wait);
62}
63
Bhanu Prakash Gollapudi26bf62a2012-12-21 19:40:30 -080064static void bnx2fc_ofld_wait(struct bnx2fc_rport *tgt)
65{
66 setup_timer(&tgt->ofld_timer, bnx2fc_ofld_timer, (unsigned long)tgt);
67 mod_timer(&tgt->ofld_timer, jiffies + BNX2FC_FW_TIMEOUT);
68
69 wait_event_interruptible(tgt->ofld_wait,
70 (test_bit(
71 BNX2FC_FLAG_OFLD_REQ_CMPL,
72 &tgt->flags)));
73 if (signal_pending(current))
74 flush_signals(current);
75 del_timer_sync(&tgt->ofld_timer);
76}
77
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080078static void bnx2fc_offload_session(struct fcoe_port *port,
79 struct bnx2fc_rport *tgt,
80 struct fc_rport_priv *rdata)
81{
82 struct fc_lport *lport = rdata->local_port;
83 struct fc_rport *rport = rdata->rport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070084 struct bnx2fc_interface *interface = port->priv;
85 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080086 int rval;
87 int i = 0;
88
89 /* Initialize bnx2fc_rport */
90 /* NOTE: tgt is already bzero'd */
91 rval = bnx2fc_init_tgt(tgt, port, rdata);
92 if (rval) {
93 printk(KERN_ERR PFX "Failed to allocate conn id for "
94 "port_id (%6x)\n", rport->port_id);
Bhanu Prakash Gollapudi5fb8fd02011-08-04 17:38:47 -070095 goto tgt_init_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080096 }
97
98 /* Allocate session resources */
99 rval = bnx2fc_alloc_session_resc(hba, tgt);
100 if (rval) {
101 printk(KERN_ERR PFX "Failed to allocate resources\n");
102 goto ofld_err;
103 }
104
105 /*
106 * Initialize FCoE session offload process.
107 * Upon completion of offload process add
108 * rport to list of rports
109 */
110retry_ofld:
111 clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
112 rval = bnx2fc_send_session_ofld_req(port, tgt);
113 if (rval) {
114 printk(KERN_ERR PFX "ofld_req failed\n");
115 goto ofld_err;
116 }
117
118 /*
119 * wait for the session is offloaded and enabled. 3 Secs
120 * should be ample time for this process to complete.
121 */
Bhanu Prakash Gollapudi26bf62a2012-12-21 19:40:30 -0800122 bnx2fc_ofld_wait(tgt);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800123
124 if (!(test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags))) {
125 if (test_and_clear_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE,
126 &tgt->flags)) {
127 BNX2FC_TGT_DBG(tgt, "ctx_alloc_failure, "
128 "retry ofld..%d\n", i++);
129 msleep_interruptible(1000);
130 if (i > 3) {
131 i = 0;
132 goto ofld_err;
133 }
134 goto retry_ofld;
135 }
136 goto ofld_err;
137 }
138 if (bnx2fc_map_doorbell(tgt)) {
139 printk(KERN_ERR PFX "map doorbell failed - no mem\n");
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -0800140 goto ofld_err;
Bhanu Prakash Gollapudia96e8e12011-08-30 15:54:53 -0700141 }
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -0800142 clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
143 rval = bnx2fc_send_session_enable_req(port, tgt);
144 if (rval) {
145 pr_err(PFX "enable session failed\n");
146 goto ofld_err;
147 }
148 bnx2fc_ofld_wait(tgt);
149 if (!(test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)))
150 goto ofld_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800151 return;
152
153ofld_err:
154 /* couldn't offload the session. log off from this rport */
155 BNX2FC_TGT_DBG(tgt, "bnx2fc_offload_session - offload error\n");
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -0800156 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800157 /* Free session resources */
158 bnx2fc_free_session_resc(hba, tgt);
Bhanu Prakash Gollapudi5fb8fd02011-08-04 17:38:47 -0700159tgt_init_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800160 if (tgt->fcoe_conn_id != -1)
161 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
Bhanu Prakash Gollapudi5fb8fd02011-08-04 17:38:47 -0700162 lport->tt.rport_logoff(rdata);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800163}
164
165void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
166{
167 struct bnx2fc_cmd *io_req;
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -0700168 struct bnx2fc_cmd *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800169 int rc;
170 int i = 0;
171 BNX2FC_TGT_DBG(tgt, "Entered flush_active_ios - %d\n",
172 tgt->num_active_ios.counter);
173
174 spin_lock_bh(&tgt->tgt_lock);
175 tgt->flush_in_prog = 1;
176
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -0700177 list_for_each_entry_safe(io_req, tmp, &tgt->active_cmd_queue, link) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800178 i++;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800179 list_del_init(&io_req->link);
180 io_req->on_active_queue = 0;
181 BNX2FC_IO_DBG(io_req, "cmd_queue cleanup\n");
182
183 if (cancel_delayed_work(&io_req->timeout_work)) {
184 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
185 &io_req->req_flags)) {
186 /* Handle eh_abort timeout */
187 BNX2FC_IO_DBG(io_req, "eh_abort for IO "
188 "cleaned up\n");
189 complete(&io_req->tm_done);
190 }
191 kref_put(&io_req->refcount,
192 bnx2fc_cmd_release); /* drop timer hold */
193 }
194
195 set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags);
196 set_bit(BNX2FC_FLAG_IO_CLEANUP, &io_req->req_flags);
Bhanu Prakash Gollapudi5c17ae22012-06-07 02:19:35 -0700197
198 /* Do not issue cleanup when disable request failed */
199 if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
200 bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
201 else {
202 rc = bnx2fc_initiate_cleanup(io_req);
203 BUG_ON(rc);
204 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800205 }
206
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -0700207 list_for_each_entry_safe(io_req, tmp, &tgt->active_tm_queue, link) {
Bhanu Prakash Gollapudi92886c92012-04-24 15:26:03 -0700208 i++;
Bhanu Prakash Gollapudi92886c92012-04-24 15:26:03 -0700209 list_del_init(&io_req->link);
210 io_req->on_tmf_queue = 0;
211 BNX2FC_IO_DBG(io_req, "tm_queue cleanup\n");
212 if (io_req->wait_for_comp)
213 complete(&io_req->tm_done);
214 }
215
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -0700216 list_for_each_entry_safe(io_req, tmp, &tgt->els_queue, link) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800217 i++;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800218 list_del_init(&io_req->link);
219 io_req->on_active_queue = 0;
220
221 BNX2FC_IO_DBG(io_req, "els_queue cleanup\n");
222
223 if (cancel_delayed_work(&io_req->timeout_work))
224 kref_put(&io_req->refcount,
225 bnx2fc_cmd_release); /* drop timer hold */
226
227 if ((io_req->cb_func) && (io_req->cb_arg)) {
228 io_req->cb_func(io_req->cb_arg);
229 io_req->cb_arg = NULL;
230 }
231
Bhanu Prakash Gollapudi5c17ae22012-06-07 02:19:35 -0700232 /* Do not issue cleanup when disable request failed */
233 if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
234 bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
235 else {
236 rc = bnx2fc_initiate_cleanup(io_req);
237 BUG_ON(rc);
238 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800239 }
240
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -0700241 list_for_each_entry_safe(io_req, tmp, &tgt->io_retire_queue, link) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800242 i++;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800243 list_del_init(&io_req->link);
244
245 BNX2FC_IO_DBG(io_req, "retire_queue flush\n");
246
Bhanu Prakash Gollapudic1bb4f32012-04-24 15:26:02 -0700247 if (cancel_delayed_work(&io_req->timeout_work)) {
248 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
249 &io_req->req_flags)) {
250 /* Handle eh_abort timeout */
251 BNX2FC_IO_DBG(io_req, "eh_abort for IO "
252 "in retire_q\n");
253 if (io_req->wait_for_comp)
254 complete(&io_req->tm_done);
255 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800256 kref_put(&io_req->refcount, bnx2fc_cmd_release);
Bhanu Prakash Gollapudic1bb4f32012-04-24 15:26:02 -0700257 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800258
259 clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
260 }
261
262 BNX2FC_TGT_DBG(tgt, "IOs flushed = %d\n", i);
263 i = 0;
264 spin_unlock_bh(&tgt->tgt_lock);
265 /* wait for active_ios to go to 0 */
266 while ((tgt->num_active_ios.counter != 0) && (i++ < BNX2FC_WAIT_CNT))
267 msleep(25);
268 if (tgt->num_active_ios.counter != 0)
269 printk(KERN_ERR PFX "CLEANUP on port 0x%x:"
270 " active_ios = %d\n",
271 tgt->rdata->ids.port_id, tgt->num_active_ios.counter);
272 spin_lock_bh(&tgt->tgt_lock);
273 tgt->flush_in_prog = 0;
274 spin_unlock_bh(&tgt->tgt_lock);
275}
276
Bhanu Prakash Gollapudi26bf62a2012-12-21 19:40:30 -0800277static void bnx2fc_upld_wait(struct bnx2fc_rport *tgt)
278{
279 setup_timer(&tgt->upld_timer, bnx2fc_upld_timer, (unsigned long)tgt);
280 mod_timer(&tgt->upld_timer, jiffies + BNX2FC_FW_TIMEOUT);
281 wait_event_interruptible(tgt->upld_wait,
282 (test_bit(
283 BNX2FC_FLAG_UPLD_REQ_COMPL,
284 &tgt->flags)));
285 if (signal_pending(current))
286 flush_signals(current);
287 del_timer_sync(&tgt->upld_timer);
288}
289
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800290static void bnx2fc_upload_session(struct fcoe_port *port,
291 struct bnx2fc_rport *tgt)
292{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700293 struct bnx2fc_interface *interface = port->priv;
294 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800295
296 BNX2FC_TGT_DBG(tgt, "upload_session: active_ios = %d\n",
297 tgt->num_active_ios.counter);
298
299 /*
300 * Called with hba->hba_mutex held.
301 * This is a blocking call
302 */
303 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
304 bnx2fc_send_session_disable_req(port, tgt);
305
306 /*
307 * wait for upload to complete. 3 Secs
308 * should be sufficient time for this process to complete.
309 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800310 BNX2FC_TGT_DBG(tgt, "waiting for disable compl\n");
Bhanu Prakash Gollapudi26bf62a2012-12-21 19:40:30 -0800311 bnx2fc_upld_wait(tgt);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800312
313 /*
314 * traverse thru the active_q and tmf_q and cleanup
315 * IOs in these lists
316 */
317 BNX2FC_TGT_DBG(tgt, "flush/upload - disable wait flags = 0x%lx\n",
318 tgt->flags);
319 bnx2fc_flush_active_ios(tgt);
320
321 /* Issue destroy KWQE */
322 if (test_bit(BNX2FC_FLAG_DISABLED, &tgt->flags)) {
323 BNX2FC_TGT_DBG(tgt, "send destroy req\n");
324 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
325 bnx2fc_send_session_destroy_req(hba, tgt);
326
327 /* wait for destroy to complete */
Bhanu Prakash Gollapudi26bf62a2012-12-21 19:40:30 -0800328 bnx2fc_upld_wait(tgt);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800329
330 if (!(test_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags)))
331 printk(KERN_ERR PFX "ERROR!! destroy timed out\n");
332
333 BNX2FC_TGT_DBG(tgt, "destroy wait complete flags = 0x%lx\n",
334 tgt->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800335
Bhanu Prakash Gollapudi5c17ae22012-06-07 02:19:35 -0700336 } else if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags)) {
337 printk(KERN_ERR PFX "ERROR!! DISABLE req failed, destroy"
338 " not sent to FW\n");
339 } else {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800340 printk(KERN_ERR PFX "ERROR!! DISABLE req timed out, destroy"
341 " not sent to FW\n");
Bhanu Prakash Gollapudi5c17ae22012-06-07 02:19:35 -0700342 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800343
344 /* Free session resources */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800345 bnx2fc_free_session_resc(hba, tgt);
346 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800347}
348
349static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
350 struct fcoe_port *port,
351 struct fc_rport_priv *rdata)
352{
353
354 struct fc_rport *rport = rdata->rport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700355 struct bnx2fc_interface *interface = port->priv;
356 struct bnx2fc_hba *hba = interface->hba;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300357 struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
358 struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800359
360 tgt->rport = rport;
361 tgt->rdata = rdata;
362 tgt->port = port;
363
364 if (hba->num_ofld_sess >= BNX2FC_NUM_MAX_SESS) {
365 BNX2FC_TGT_DBG(tgt, "exceeded max sessions. logoff this tgt\n");
366 tgt->fcoe_conn_id = -1;
367 return -1;
368 }
369
370 tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
371 if (tgt->fcoe_conn_id == -1)
372 return -1;
373
374 BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n", tgt->fcoe_conn_id);
375
376 tgt->max_sqes = BNX2FC_SQ_WQES_MAX;
377 tgt->max_rqes = BNX2FC_RQ_WQES_MAX;
378 tgt->max_cqes = BNX2FC_CQ_WQES_MAX;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300379 atomic_set(&tgt->free_sqes, BNX2FC_SQ_WQES_MAX);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800380
381 /* Initialize the toggle bit */
382 tgt->sq_curr_toggle_bit = 1;
383 tgt->cq_curr_toggle_bit = 1;
384 tgt->sq_prod_idx = 0;
385 tgt->cq_cons_idx = 0;
386 tgt->rq_prod_idx = 0x8000;
387 tgt->rq_cons_idx = 0;
388 atomic_set(&tgt->num_active_ios, 0);
389
Bhanu Prakash Gollapudi50b71862013-01-10 23:59:38 -0800390 if (rdata->flags & FC_RP_FLAGS_RETRY &&
391 rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET &&
392 !(rdata->ids.roles & FC_RPORT_ROLE_FCP_INITIATOR)) {
Bhanu Prakash Gollapudib252f4c2011-07-26 14:51:40 -0700393 tgt->dev_type = TYPE_TAPE;
394 tgt->io_timeout = 0; /* use default ULP timeout */
395 } else {
396 tgt->dev_type = TYPE_DISK;
397 tgt->io_timeout = BNX2FC_IO_TIMEOUT;
398 }
399
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300400 /* initialize sq doorbell */
401 sq_db->header.header = B577XX_DOORBELL_HDR_DB_TYPE;
402 sq_db->header.header |= B577XX_FCOE_CONNECTION_TYPE <<
403 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT;
404 /* initialize rx doorbell */
405 rx_db->hdr.header = ((0x1 << B577XX_DOORBELL_HDR_RX_SHIFT) |
406 (0x1 << B577XX_DOORBELL_HDR_DB_TYPE_SHIFT) |
407 (B577XX_FCOE_CONNECTION_TYPE <<
408 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT));
409 rx_db->params = (0x2 << B577XX_FCOE_RX_DOORBELL_NEGATIVE_ARM_SHIFT) |
410 (0x3 << B577XX_FCOE_RX_DOORBELL_OPCODE_SHIFT);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800411
412 spin_lock_init(&tgt->tgt_lock);
413 spin_lock_init(&tgt->cq_lock);
414
415 /* Initialize active_cmd_queue list */
416 INIT_LIST_HEAD(&tgt->active_cmd_queue);
417
418 /* Initialize IO retire queue */
419 INIT_LIST_HEAD(&tgt->io_retire_queue);
420
421 INIT_LIST_HEAD(&tgt->els_queue);
422
423 /* Initialize active_tm_queue list */
424 INIT_LIST_HEAD(&tgt->active_tm_queue);
425
426 init_waitqueue_head(&tgt->ofld_wait);
427 init_waitqueue_head(&tgt->upld_wait);
428
429 return 0;
430}
431
432/**
433 * This event_callback is called after successful completion of libfc
434 * initiated target login. bnx2fc can proceed with initiating the session
435 * establishment.
436 */
437void bnx2fc_rport_event_handler(struct fc_lport *lport,
438 struct fc_rport_priv *rdata,
439 enum fc_rport_event event)
440{
441 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700442 struct bnx2fc_interface *interface = port->priv;
443 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800444 struct fc_rport *rport = rdata->rport;
445 struct fc_rport_libfc_priv *rp;
446 struct bnx2fc_rport *tgt;
447 u32 port_id;
448
449 BNX2FC_HBA_DBG(lport, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
450 event, rdata->ids.port_id);
451 switch (event) {
452 case RPORT_EV_READY:
453 if (!rport) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700454 printk(KERN_ERR PFX "rport is NULL: ERROR!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800455 break;
456 }
457
458 rp = rport->dd_data;
459 if (rport->port_id == FC_FID_DIR_SERV) {
460 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300461 * bnx2fc_rport structure doesn't exist for
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800462 * directory server.
463 * We should not come here, as lport will
464 * take care of fabric login
465 */
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700466 printk(KERN_ERR PFX "%x - rport_event_handler ERROR\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800467 rdata->ids.port_id);
468 break;
469 }
470
471 if (rdata->spp_type != FC_TYPE_FCP) {
472 BNX2FC_HBA_DBG(lport, "not FCP type target."
473 " not offloading\n");
474 break;
475 }
476 if (!(rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET)) {
477 BNX2FC_HBA_DBG(lport, "not FCP_TARGET"
478 " not offloading\n");
479 break;
480 }
481
482 /*
483 * Offlaod process is protected with hba mutex.
484 * Use the same mutex_lock for upload process too
485 */
486 mutex_lock(&hba->hba_mutex);
487 tgt = (struct bnx2fc_rport *)&rp[1];
488
489 /* This can happen when ADISC finds the same target */
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -0800490 if (test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800491 BNX2FC_TGT_DBG(tgt, "already offloaded\n");
492 mutex_unlock(&hba->hba_mutex);
493 return;
494 }
495
496 /*
497 * Offload the session. This is a blocking call, and will
498 * wait until the session is offloaded.
499 */
500 bnx2fc_offload_session(port, tgt, rdata);
501
502 BNX2FC_TGT_DBG(tgt, "OFFLOAD num_ofld_sess = %d\n",
503 hba->num_ofld_sess);
504
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -0800505 if (test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)) {
506 /* Session is offloaded and enabled. */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800507 BNX2FC_TGT_DBG(tgt, "sess offloaded\n");
508 /* This counter is protected with hba mutex */
509 hba->num_ofld_sess++;
510
511 set_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
512 } else {
513 /*
514 * Offload or enable would have failed.
515 * In offload/enable completion path, the
516 * rport would have already been removed
517 */
518 BNX2FC_TGT_DBG(tgt, "Port is being logged off as "
519 "offloaded flag not set\n");
520 }
521 mutex_unlock(&hba->hba_mutex);
522 break;
523 case RPORT_EV_LOGO:
524 case RPORT_EV_FAILED:
525 case RPORT_EV_STOP:
526 port_id = rdata->ids.port_id;
527 if (port_id == FC_FID_DIR_SERV)
528 break;
529
530 if (!rport) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700531 printk(KERN_INFO PFX "%x - rport not created Yet!!\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800532 port_id);
533 break;
534 }
535 rp = rport->dd_data;
536 mutex_lock(&hba->hba_mutex);
537 /*
538 * Perform session upload. Note that rdata->peers is already
539 * removed from disc->rports list before we get this event.
540 */
541 tgt = (struct bnx2fc_rport *)&rp[1];
542
Bhanu Prakash Gollapudie7f4fed2012-12-21 19:40:31 -0800543 if (!(test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800544 mutex_unlock(&hba->hba_mutex);
545 break;
546 }
547 clear_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
548
549 bnx2fc_upload_session(port, tgt);
550 hba->num_ofld_sess--;
551 BNX2FC_TGT_DBG(tgt, "UPLOAD num_ofld_sess = %d\n",
552 hba->num_ofld_sess);
553 /*
554 * Try to wake up the linkdown wait thread. If num_ofld_sess
555 * is 0, the waiting therad wakes up
556 */
557 if ((hba->wait_for_link_down) &&
558 (hba->num_ofld_sess == 0)) {
559 wake_up_interruptible(&hba->shutdown_wait);
560 }
561 if (test_bit(BNX2FC_FLAG_EXPL_LOGO, &tgt->flags)) {
562 printk(KERN_ERR PFX "Relogin to the tgt\n");
563 mutex_lock(&lport->disc.disc_mutex);
564 lport->tt.rport_login(rdata);
565 mutex_unlock(&lport->disc.disc_mutex);
566 }
567 mutex_unlock(&hba->hba_mutex);
568
569 break;
570
571 case RPORT_EV_NONE:
572 break;
573 }
574}
575
576/**
577 * bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
578 *
579 * @port: fcoe_port struct to lookup the target port on
580 * @port_id: The remote port ID to look up
581 */
582struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
583 u32 port_id)
584{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700585 struct bnx2fc_interface *interface = port->priv;
586 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800587 struct bnx2fc_rport *tgt;
588 struct fc_rport_priv *rdata;
589 int i;
590
591 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
592 tgt = hba->tgt_ofld_list[i];
593 if ((tgt) && (tgt->port == port)) {
594 rdata = tgt->rdata;
595 if (rdata->ids.port_id == port_id) {
596 if (rdata->rp_state != RPORT_ST_DELETE) {
597 BNX2FC_TGT_DBG(tgt, "rport "
598 "obtained\n");
599 return tgt;
600 } else {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700601 BNX2FC_TGT_DBG(tgt, "rport 0x%x "
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800602 "is in DELETED state\n",
603 rdata->ids.port_id);
604 return NULL;
605 }
606 }
607 }
608 }
609 return NULL;
610}
611
612
613/**
614 * bnx2fc_alloc_conn_id - allocates FCOE Connection id
615 *
616 * @hba: pointer to adapter structure
617 * @tgt: pointer to bnx2fc_rport structure
618 */
619static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
620 struct bnx2fc_rport *tgt)
621{
622 u32 conn_id, next;
623
624 /* called with hba mutex held */
625
626 /*
627 * tgt_ofld_list access is synchronized using
628 * both hba mutex and hba lock. Atleast hba mutex or
629 * hba lock needs to be held for read access.
630 */
631
632 spin_lock_bh(&hba->hba_lock);
633 next = hba->next_conn_id;
634 conn_id = hba->next_conn_id++;
635 if (hba->next_conn_id == BNX2FC_NUM_MAX_SESS)
636 hba->next_conn_id = 0;
637
638 while (hba->tgt_ofld_list[conn_id] != NULL) {
639 conn_id++;
640 if (conn_id == BNX2FC_NUM_MAX_SESS)
641 conn_id = 0;
642
643 if (conn_id == next) {
644 /* No free conn_ids are available */
645 spin_unlock_bh(&hba->hba_lock);
646 return -1;
647 }
648 }
649 hba->tgt_ofld_list[conn_id] = tgt;
650 tgt->fcoe_conn_id = conn_id;
651 spin_unlock_bh(&hba->hba_lock);
652 return conn_id;
653}
654
655static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id)
656{
657 /* called with hba mutex held */
658 spin_lock_bh(&hba->hba_lock);
659 hba->tgt_ofld_list[conn_id] = NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800660 spin_unlock_bh(&hba->hba_lock);
661}
662
663/**
664 *bnx2fc_alloc_session_resc - Allocate qp resources for the session
665 *
666 */
667static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
668 struct bnx2fc_rport *tgt)
669{
670 dma_addr_t page;
671 int num_pages;
672 u32 *pbl;
673
674 /* Allocate and map SQ */
675 tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800676 tgt->sq_mem_size = (tgt->sq_mem_size + (CNIC_PAGE_SIZE - 1)) &
677 CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800678
679 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
680 &tgt->sq_dma, GFP_KERNEL);
681 if (!tgt->sq) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700682 printk(KERN_ERR PFX "unable to allocate SQ memory %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800683 tgt->sq_mem_size);
684 goto mem_alloc_failure;
685 }
686 memset(tgt->sq, 0, tgt->sq_mem_size);
687
688 /* Allocate and map CQ */
689 tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800690 tgt->cq_mem_size = (tgt->cq_mem_size + (CNIC_PAGE_SIZE - 1)) &
691 CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800692
693 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
694 &tgt->cq_dma, GFP_KERNEL);
695 if (!tgt->cq) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700696 printk(KERN_ERR PFX "unable to allocate CQ memory %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800697 tgt->cq_mem_size);
698 goto mem_alloc_failure;
699 }
700 memset(tgt->cq, 0, tgt->cq_mem_size);
701
702 /* Allocate and map RQ and RQ PBL */
703 tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800704 tgt->rq_mem_size = (tgt->rq_mem_size + (CNIC_PAGE_SIZE - 1)) &
705 CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800706
707 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
708 &tgt->rq_dma, GFP_KERNEL);
709 if (!tgt->rq) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700710 printk(KERN_ERR PFX "unable to allocate RQ memory %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800711 tgt->rq_mem_size);
712 goto mem_alloc_failure;
713 }
714 memset(tgt->rq, 0, tgt->rq_mem_size);
715
Michael Chanbe1fefc2014-03-17 19:19:07 -0800716 tgt->rq_pbl_size = (tgt->rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
717 tgt->rq_pbl_size = (tgt->rq_pbl_size + (CNIC_PAGE_SIZE - 1)) &
718 CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800719
720 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
721 &tgt->rq_pbl_dma, GFP_KERNEL);
722 if (!tgt->rq_pbl) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700723 printk(KERN_ERR PFX "unable to allocate RQ PBL %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800724 tgt->rq_pbl_size);
725 goto mem_alloc_failure;
726 }
727
728 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
Michael Chanbe1fefc2014-03-17 19:19:07 -0800729 num_pages = tgt->rq_mem_size / CNIC_PAGE_SIZE;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800730 page = tgt->rq_dma;
731 pbl = (u32 *)tgt->rq_pbl;
732
733 while (num_pages--) {
734 *pbl = (u32)page;
735 pbl++;
736 *pbl = (u32)((u64)page >> 32);
737 pbl++;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800738 page += CNIC_PAGE_SIZE;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800739 }
740
741 /* Allocate and map XFERQ */
742 tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800743 tgt->xferq_mem_size = (tgt->xferq_mem_size + (CNIC_PAGE_SIZE - 1)) &
744 CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800745
746 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
747 &tgt->xferq_dma, GFP_KERNEL);
748 if (!tgt->xferq) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700749 printk(KERN_ERR PFX "unable to allocate XFERQ %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800750 tgt->xferq_mem_size);
751 goto mem_alloc_failure;
752 }
753 memset(tgt->xferq, 0, tgt->xferq_mem_size);
754
755 /* Allocate and map CONFQ & CONFQ PBL */
756 tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800757 tgt->confq_mem_size = (tgt->confq_mem_size + (CNIC_PAGE_SIZE - 1)) &
758 CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800759
760 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
761 &tgt->confq_dma, GFP_KERNEL);
762 if (!tgt->confq) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700763 printk(KERN_ERR PFX "unable to allocate CONFQ %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800764 tgt->confq_mem_size);
765 goto mem_alloc_failure;
766 }
767 memset(tgt->confq, 0, tgt->confq_mem_size);
768
769 tgt->confq_pbl_size =
Michael Chanbe1fefc2014-03-17 19:19:07 -0800770 (tgt->confq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800771 tgt->confq_pbl_size =
Michael Chanbe1fefc2014-03-17 19:19:07 -0800772 (tgt->confq_pbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800773
774 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
775 tgt->confq_pbl_size,
776 &tgt->confq_pbl_dma, GFP_KERNEL);
777 if (!tgt->confq_pbl) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700778 printk(KERN_ERR PFX "unable to allocate CONFQ PBL %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800779 tgt->confq_pbl_size);
780 goto mem_alloc_failure;
781 }
782
783 memset(tgt->confq_pbl, 0, tgt->confq_pbl_size);
Michael Chanbe1fefc2014-03-17 19:19:07 -0800784 num_pages = tgt->confq_mem_size / CNIC_PAGE_SIZE;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800785 page = tgt->confq_dma;
786 pbl = (u32 *)tgt->confq_pbl;
787
788 while (num_pages--) {
789 *pbl = (u32)page;
790 pbl++;
791 *pbl = (u32)((u64)page >> 32);
792 pbl++;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800793 page += CNIC_PAGE_SIZE;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800794 }
795
796 /* Allocate and map ConnDB */
797 tgt->conn_db_mem_size = sizeof(struct fcoe_conn_db);
798
799 tgt->conn_db = dma_alloc_coherent(&hba->pcidev->dev,
800 tgt->conn_db_mem_size,
801 &tgt->conn_db_dma, GFP_KERNEL);
802 if (!tgt->conn_db) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700803 printk(KERN_ERR PFX "unable to allocate conn_db %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800804 tgt->conn_db_mem_size);
805 goto mem_alloc_failure;
806 }
807 memset(tgt->conn_db, 0, tgt->conn_db_mem_size);
808
809
810 /* Allocate and map LCQ */
811 tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE;
Michael Chanbe1fefc2014-03-17 19:19:07 -0800812 tgt->lcq_mem_size = (tgt->lcq_mem_size + (CNIC_PAGE_SIZE - 1)) &
813 CNIC_PAGE_MASK;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800814
815 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
816 &tgt->lcq_dma, GFP_KERNEL);
817
818 if (!tgt->lcq) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700819 printk(KERN_ERR PFX "unable to allocate lcq %d\n",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800820 tgt->lcq_mem_size);
821 goto mem_alloc_failure;
822 }
823 memset(tgt->lcq, 0, tgt->lcq_mem_size);
824
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800825 tgt->conn_db->rq_prod = 0x8000;
826
827 return 0;
828
829mem_alloc_failure:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800830 return -ENOMEM;
831}
832
833/**
834 * bnx2i_free_session_resc - free qp resources for the session
835 *
836 * @hba: adapter structure pointer
837 * @tgt: bnx2fc_rport structure pointer
838 *
839 * Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
840 */
841static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
842 struct bnx2fc_rport *tgt)
843{
Bhanu Prakash Gollapudib338c782011-08-04 17:38:46 -0700844 void __iomem *ctx_base_ptr;
845
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800846 BNX2FC_TGT_DBG(tgt, "Freeing up session resources\n");
847
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300848 spin_lock_bh(&tgt->cq_lock);
Bhanu Prakash Gollapudib338c782011-08-04 17:38:46 -0700849 ctx_base_ptr = tgt->ctx_base;
850 tgt->ctx_base = NULL;
851
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800852 /* Free LCQ */
853 if (tgt->lcq) {
854 dma_free_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
855 tgt->lcq, tgt->lcq_dma);
856 tgt->lcq = NULL;
857 }
858 /* Free connDB */
859 if (tgt->conn_db) {
860 dma_free_coherent(&hba->pcidev->dev, tgt->conn_db_mem_size,
861 tgt->conn_db, tgt->conn_db_dma);
862 tgt->conn_db = NULL;
863 }
864 /* Free confq and confq pbl */
865 if (tgt->confq_pbl) {
866 dma_free_coherent(&hba->pcidev->dev, tgt->confq_pbl_size,
867 tgt->confq_pbl, tgt->confq_pbl_dma);
868 tgt->confq_pbl = NULL;
869 }
870 if (tgt->confq) {
871 dma_free_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
872 tgt->confq, tgt->confq_dma);
873 tgt->confq = NULL;
874 }
875 /* Free XFERQ */
876 if (tgt->xferq) {
877 dma_free_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
878 tgt->xferq, tgt->xferq_dma);
879 tgt->xferq = NULL;
880 }
881 /* Free RQ PBL and RQ */
882 if (tgt->rq_pbl) {
883 dma_free_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
884 tgt->rq_pbl, tgt->rq_pbl_dma);
885 tgt->rq_pbl = NULL;
886 }
887 if (tgt->rq) {
888 dma_free_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
889 tgt->rq, tgt->rq_dma);
890 tgt->rq = NULL;
891 }
892 /* Free CQ */
893 if (tgt->cq) {
894 dma_free_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
895 tgt->cq, tgt->cq_dma);
896 tgt->cq = NULL;
897 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800898 /* Free SQ */
899 if (tgt->sq) {
900 dma_free_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
901 tgt->sq, tgt->sq_dma);
902 tgt->sq = NULL;
903 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300904 spin_unlock_bh(&tgt->cq_lock);
Bhanu Prakash Gollapudib338c782011-08-04 17:38:46 -0700905
906 if (ctx_base_ptr)
907 iounmap(ctx_base_ptr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800908}