blob: 24997c679f3ca8526a329e213bcb01b6dd7a4865 [file] [log] [blame]
Michael Chancf4e6362009-06-08 18:14:44 -07001/*
2 * bnx2i_iscsi.c: Broadcom NetXtreme II iSCSI driver.
3 *
4 * Copyright (c) 2006 - 2009 Broadcom Corporation
5 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
6 * Copyright (c) 2007, 2008 Mike Christie
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: Anil Veerabhadrappa (anilgv@broadcom.com)
13 */
14
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Michael Chancf4e6362009-06-08 18:14:44 -070016#include <scsi/scsi_tcq.h>
17#include <scsi/libiscsi.h>
18#include "bnx2i.h"
19
20struct scsi_transport_template *bnx2i_scsi_xport_template;
21struct iscsi_transport bnx2i_iscsi_transport;
22static struct scsi_host_template bnx2i_host_template;
23
24/*
25 * Global endpoint resource info
26 */
27static DEFINE_SPINLOCK(bnx2i_resc_lock); /* protects global resources */
28
29
30static int bnx2i_adapter_ready(struct bnx2i_hba *hba)
31{
32 int retval = 0;
33
34 if (!hba || !test_bit(ADAPTER_STATE_UP, &hba->adapter_state) ||
35 test_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state) ||
36 test_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state))
37 retval = -EPERM;
38 return retval;
39}
40
41/**
42 * bnx2i_get_write_cmd_bd_idx - identifies various BD bookmarks
43 * @cmd: iscsi cmd struct pointer
44 * @buf_off: absolute buffer offset
45 * @start_bd_off: u32 pointer to return the offset within the BD
46 * indicated by 'start_bd_idx' on which 'buf_off' falls
47 * @start_bd_idx: index of the BD on which 'buf_off' falls
48 *
49 * identifies & marks various bd info for scsi command's imm data,
50 * unsolicited data and the first solicited data seq.
51 */
52static void bnx2i_get_write_cmd_bd_idx(struct bnx2i_cmd *cmd, u32 buf_off,
53 u32 *start_bd_off, u32 *start_bd_idx)
54{
55 struct iscsi_bd *bd_tbl = cmd->io_tbl.bd_tbl;
56 u32 cur_offset = 0;
57 u32 cur_bd_idx = 0;
58
59 if (buf_off) {
60 while (buf_off >= (cur_offset + bd_tbl->buffer_length)) {
61 cur_offset += bd_tbl->buffer_length;
62 cur_bd_idx++;
63 bd_tbl++;
64 }
65 }
66
67 *start_bd_off = buf_off - cur_offset;
68 *start_bd_idx = cur_bd_idx;
69}
70
71/**
72 * bnx2i_setup_write_cmd_bd_info - sets up BD various information
73 * @task: transport layer's cmd struct pointer
74 *
75 * identifies & marks various bd info for scsi command's immediate data,
76 * unsolicited data and first solicited data seq which includes BD start
77 * index & BD buf off. his function takes into account iscsi parameter such
78 * as immediate data and unsolicited data is support on this connection.
79 */
80static void bnx2i_setup_write_cmd_bd_info(struct iscsi_task *task)
81{
82 struct bnx2i_cmd *cmd = task->dd_data;
83 u32 start_bd_offset;
84 u32 start_bd_idx;
85 u32 buffer_offset = 0;
86 u32 cmd_len = cmd->req.total_data_transfer_length;
87
88 /* if ImmediateData is turned off & IntialR2T is turned on,
89 * there will be no immediate or unsolicited data, just return.
90 */
91 if (!iscsi_task_has_unsol_data(task) && !task->imm_count)
92 return;
93
94 /* Immediate data */
95 buffer_offset += task->imm_count;
96 if (task->imm_count == cmd_len)
97 return;
98
99 if (iscsi_task_has_unsol_data(task)) {
100 bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset,
101 &start_bd_offset, &start_bd_idx);
102 cmd->req.ud_buffer_offset = start_bd_offset;
103 cmd->req.ud_start_bd_index = start_bd_idx;
104 buffer_offset += task->unsol_r2t.data_length;
105 }
106
107 if (buffer_offset != cmd_len) {
108 bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset,
109 &start_bd_offset, &start_bd_idx);
110 if ((start_bd_offset > task->conn->session->first_burst) ||
111 (start_bd_idx > scsi_sg_count(cmd->scsi_cmd))) {
112 int i = 0;
113
114 iscsi_conn_printk(KERN_ALERT, task->conn,
115 "bnx2i- error, buf offset 0x%x "
116 "bd_valid %d use_sg %d\n",
117 buffer_offset, cmd->io_tbl.bd_valid,
118 scsi_sg_count(cmd->scsi_cmd));
119 for (i = 0; i < cmd->io_tbl.bd_valid; i++)
120 iscsi_conn_printk(KERN_ALERT, task->conn,
121 "bnx2i err, bd[%d]: len %x\n",
122 i, cmd->io_tbl.bd_tbl[i].\
123 buffer_length);
124 }
125 cmd->req.sd_buffer_offset = start_bd_offset;
126 cmd->req.sd_start_bd_index = start_bd_idx;
127 }
128}
129
130
131
132/**
133 * bnx2i_map_scsi_sg - maps IO buffer and prepares the BD table
134 * @hba: adapter instance
135 * @cmd: iscsi cmd struct pointer
136 *
137 * map SG list
138 */
139static int bnx2i_map_scsi_sg(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
140{
141 struct scsi_cmnd *sc = cmd->scsi_cmd;
142 struct iscsi_bd *bd = cmd->io_tbl.bd_tbl;
143 struct scatterlist *sg;
144 int byte_count = 0;
145 int bd_count = 0;
146 int sg_count;
147 int sg_len;
148 u64 addr;
149 int i;
150
151 BUG_ON(scsi_sg_count(sc) > ISCSI_MAX_BDS_PER_CMD);
152
153 sg_count = scsi_dma_map(sc);
154
155 scsi_for_each_sg(sc, sg, sg_count, i) {
156 sg_len = sg_dma_len(sg);
157 addr = (u64) sg_dma_address(sg);
158 bd[bd_count].buffer_addr_lo = addr & 0xffffffff;
159 bd[bd_count].buffer_addr_hi = addr >> 32;
160 bd[bd_count].buffer_length = sg_len;
161 bd[bd_count].flags = 0;
162 if (bd_count == 0)
163 bd[bd_count].flags = ISCSI_BD_FIRST_IN_BD_CHAIN;
164
165 byte_count += sg_len;
166 bd_count++;
167 }
168
169 if (bd_count)
170 bd[bd_count - 1].flags |= ISCSI_BD_LAST_IN_BD_CHAIN;
171
172 BUG_ON(byte_count != scsi_bufflen(sc));
173 return bd_count;
174}
175
176/**
177 * bnx2i_iscsi_map_sg_list - maps SG list
178 * @cmd: iscsi cmd struct pointer
179 *
180 * creates BD list table for the command
181 */
182static void bnx2i_iscsi_map_sg_list(struct bnx2i_cmd *cmd)
183{
184 int bd_count;
185
186 bd_count = bnx2i_map_scsi_sg(cmd->conn->hba, cmd);
187 if (!bd_count) {
188 struct iscsi_bd *bd = cmd->io_tbl.bd_tbl;
189
190 bd[0].buffer_addr_lo = bd[0].buffer_addr_hi = 0;
191 bd[0].buffer_length = bd[0].flags = 0;
192 }
193 cmd->io_tbl.bd_valid = bd_count;
194}
195
196
197/**
198 * bnx2i_iscsi_unmap_sg_list - unmaps SG list
199 * @cmd: iscsi cmd struct pointer
200 *
201 * unmap IO buffers and invalidate the BD table
202 */
203void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd)
204{
205 struct scsi_cmnd *sc = cmd->scsi_cmd;
206
207 if (cmd->io_tbl.bd_valid && sc) {
208 scsi_dma_unmap(sc);
209 cmd->io_tbl.bd_valid = 0;
210 }
211}
212
213static void bnx2i_setup_cmd_wqe_template(struct bnx2i_cmd *cmd)
214{
215 memset(&cmd->req, 0x00, sizeof(cmd->req));
216 cmd->req.op_code = 0xFF;
217 cmd->req.bd_list_addr_lo = (u32) cmd->io_tbl.bd_tbl_dma;
218 cmd->req.bd_list_addr_hi =
219 (u32) ((u64) cmd->io_tbl.bd_tbl_dma >> 32);
220
221}
222
223
224/**
225 * bnx2i_bind_conn_to_iscsi_cid - bind conn structure to 'iscsi_cid'
226 * @hba: pointer to adapter instance
227 * @conn: pointer to iscsi connection
228 * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
229 *
230 * update iscsi cid table entry with connection pointer. This enables
231 * driver to quickly get hold of connection structure pointer in
232 * completion/interrupt thread using iscsi context ID
233 */
234static int bnx2i_bind_conn_to_iscsi_cid(struct bnx2i_hba *hba,
235 struct bnx2i_conn *bnx2i_conn,
236 u32 iscsi_cid)
237{
238 if (hba && hba->cid_que.conn_cid_tbl[iscsi_cid]) {
239 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
240 "conn bind - entry #%d not free\n", iscsi_cid);
241 return -EBUSY;
242 }
243
244 hba->cid_que.conn_cid_tbl[iscsi_cid] = bnx2i_conn;
245 return 0;
246}
247
248
249/**
250 * bnx2i_get_conn_from_id - maps an iscsi cid to corresponding conn ptr
251 * @hba: pointer to adapter instance
252 * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
253 */
254struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba,
255 u16 iscsi_cid)
256{
257 if (!hba->cid_que.conn_cid_tbl) {
258 printk(KERN_ERR "bnx2i: ERROR - missing conn<->cid table\n");
259 return NULL;
260
261 } else if (iscsi_cid >= hba->max_active_conns) {
262 printk(KERN_ERR "bnx2i: wrong cid #%d\n", iscsi_cid);
263 return NULL;
264 }
265 return hba->cid_que.conn_cid_tbl[iscsi_cid];
266}
267
268
269/**
270 * bnx2i_alloc_iscsi_cid - allocates a iscsi_cid from free pool
271 * @hba: pointer to adapter instance
272 */
273static u32 bnx2i_alloc_iscsi_cid(struct bnx2i_hba *hba)
274{
275 int idx;
276
277 if (!hba->cid_que.cid_free_cnt)
278 return -1;
279
280 idx = hba->cid_que.cid_q_cons_idx;
281 hba->cid_que.cid_q_cons_idx++;
282 if (hba->cid_que.cid_q_cons_idx == hba->cid_que.cid_q_max_idx)
283 hba->cid_que.cid_q_cons_idx = 0;
284
285 hba->cid_que.cid_free_cnt--;
286 return hba->cid_que.cid_que[idx];
287}
288
289
290/**
291 * bnx2i_free_iscsi_cid - returns tcp port to free list
292 * @hba: pointer to adapter instance
293 * @iscsi_cid: iscsi context ID to free
294 */
295static void bnx2i_free_iscsi_cid(struct bnx2i_hba *hba, u16 iscsi_cid)
296{
297 int idx;
298
299 if (iscsi_cid == (u16) -1)
300 return;
301
302 hba->cid_que.cid_free_cnt++;
303
304 idx = hba->cid_que.cid_q_prod_idx;
305 hba->cid_que.cid_que[idx] = iscsi_cid;
306 hba->cid_que.conn_cid_tbl[iscsi_cid] = NULL;
307 hba->cid_que.cid_q_prod_idx++;
308 if (hba->cid_que.cid_q_prod_idx == hba->cid_que.cid_q_max_idx)
309 hba->cid_que.cid_q_prod_idx = 0;
310}
311
312
313/**
314 * bnx2i_setup_free_cid_que - sets up free iscsi cid queue
315 * @hba: pointer to adapter instance
316 *
317 * allocates memory for iscsi cid queue & 'cid - conn ptr' mapping table,
318 * and initialize table attributes
319 */
320static int bnx2i_setup_free_cid_que(struct bnx2i_hba *hba)
321{
322 int mem_size;
323 int i;
324
325 mem_size = hba->max_active_conns * sizeof(u32);
326 mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
327
328 hba->cid_que.cid_que_base = kmalloc(mem_size, GFP_KERNEL);
329 if (!hba->cid_que.cid_que_base)
330 return -ENOMEM;
331
332 mem_size = hba->max_active_conns * sizeof(struct bnx2i_conn *);
333 mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
334 hba->cid_que.conn_cid_tbl = kmalloc(mem_size, GFP_KERNEL);
335 if (!hba->cid_que.conn_cid_tbl) {
336 kfree(hba->cid_que.cid_que_base);
337 hba->cid_que.cid_que_base = NULL;
338 return -ENOMEM;
339 }
340
341 hba->cid_que.cid_que = (u32 *)hba->cid_que.cid_que_base;
342 hba->cid_que.cid_q_prod_idx = 0;
343 hba->cid_que.cid_q_cons_idx = 0;
344 hba->cid_que.cid_q_max_idx = hba->max_active_conns;
345 hba->cid_que.cid_free_cnt = hba->max_active_conns;
346
347 for (i = 0; i < hba->max_active_conns; i++) {
348 hba->cid_que.cid_que[i] = i;
349 hba->cid_que.conn_cid_tbl[i] = NULL;
350 }
351 return 0;
352}
353
354
355/**
356 * bnx2i_release_free_cid_que - releases 'iscsi_cid' queue resources
357 * @hba: pointer to adapter instance
358 */
359static void bnx2i_release_free_cid_que(struct bnx2i_hba *hba)
360{
361 kfree(hba->cid_que.cid_que_base);
362 hba->cid_que.cid_que_base = NULL;
363
364 kfree(hba->cid_que.conn_cid_tbl);
365 hba->cid_que.conn_cid_tbl = NULL;
366}
367
368
369/**
370 * bnx2i_alloc_ep - allocates ep structure from global pool
371 * @hba: pointer to adapter instance
372 *
373 * routine allocates a free endpoint structure from global pool and
374 * a tcp port to be used for this connection. Global resource lock,
375 * 'bnx2i_resc_lock' is held while accessing shared global data structures
376 */
377static struct iscsi_endpoint *bnx2i_alloc_ep(struct bnx2i_hba *hba)
378{
379 struct iscsi_endpoint *ep;
380 struct bnx2i_endpoint *bnx2i_ep;
381
382 ep = iscsi_create_endpoint(sizeof(*bnx2i_ep));
383 if (!ep) {
384 printk(KERN_ERR "bnx2i: Could not allocate ep\n");
385 return NULL;
386 }
387
388 bnx2i_ep = ep->dd_data;
Eddie Wai46012e82010-07-01 15:34:51 -0700389 bnx2i_ep->cls_ep = ep;
Michael Chancf4e6362009-06-08 18:14:44 -0700390 INIT_LIST_HEAD(&bnx2i_ep->link);
391 bnx2i_ep->state = EP_STATE_IDLE;
Anil Veerabhadrappac19dcd02009-07-29 21:50:11 -0700392 bnx2i_ep->ep_iscsi_cid = (u16) -1;
Michael Chancf4e6362009-06-08 18:14:44 -0700393 bnx2i_ep->hba = hba;
394 bnx2i_ep->hba_age = hba->age;
395 hba->ofld_conns_active++;
396 init_waitqueue_head(&bnx2i_ep->ofld_wait);
397 return ep;
398}
399
400
401/**
402 * bnx2i_free_ep - free endpoint
403 * @ep: pointer to iscsi endpoint structure
404 */
405static void bnx2i_free_ep(struct iscsi_endpoint *ep)
406{
407 struct bnx2i_endpoint *bnx2i_ep = ep->dd_data;
408 unsigned long flags;
409
410 spin_lock_irqsave(&bnx2i_resc_lock, flags);
411 bnx2i_ep->state = EP_STATE_IDLE;
412 bnx2i_ep->hba->ofld_conns_active--;
413
Eddie Waia91031a2010-11-23 15:29:30 -0800414 if (bnx2i_ep->ep_iscsi_cid != (u16) -1)
415 bnx2i_free_iscsi_cid(bnx2i_ep->hba, bnx2i_ep->ep_iscsi_cid);
416
Michael Chancf4e6362009-06-08 18:14:44 -0700417 if (bnx2i_ep->conn) {
418 bnx2i_ep->conn->ep = NULL;
419 bnx2i_ep->conn = NULL;
420 }
421
422 bnx2i_ep->hba = NULL;
423 spin_unlock_irqrestore(&bnx2i_resc_lock, flags);
424 iscsi_destroy_endpoint(ep);
425}
426
427
428/**
429 * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command
430 * @hba: adapter instance pointer
431 * @session: iscsi session pointer
432 * @cmd: iscsi command structure
433 */
434static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct iscsi_session *session,
435 struct bnx2i_cmd *cmd)
436{
437 struct io_bdt *io = &cmd->io_tbl;
438 struct iscsi_bd *bd;
439
440 io->bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
441 ISCSI_MAX_BDS_PER_CMD * sizeof(*bd),
442 &io->bd_tbl_dma, GFP_KERNEL);
443 if (!io->bd_tbl) {
444 iscsi_session_printk(KERN_ERR, session, "Could not "
445 "allocate bdt.\n");
446 return -ENOMEM;
447 }
448 io->bd_valid = 0;
449 return 0;
450}
451
452/**
453 * bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table
454 * @hba: adapter instance pointer
455 * @session: iscsi session pointer
456 * @cmd: iscsi command structure
457 */
458static void bnx2i_destroy_cmd_pool(struct bnx2i_hba *hba,
459 struct iscsi_session *session)
460{
461 int i;
462
463 for (i = 0; i < session->cmds_max; i++) {
464 struct iscsi_task *task = session->cmds[i];
465 struct bnx2i_cmd *cmd = task->dd_data;
466
467 if (cmd->io_tbl.bd_tbl)
468 dma_free_coherent(&hba->pcidev->dev,
469 ISCSI_MAX_BDS_PER_CMD *
470 sizeof(struct iscsi_bd),
471 cmd->io_tbl.bd_tbl,
472 cmd->io_tbl.bd_tbl_dma);
473 }
474
475}
476
477
478/**
479 * bnx2i_setup_cmd_pool - sets up iscsi command pool for the session
480 * @hba: adapter instance pointer
481 * @session: iscsi session pointer
482 */
483static int bnx2i_setup_cmd_pool(struct bnx2i_hba *hba,
484 struct iscsi_session *session)
485{
486 int i;
487
488 for (i = 0; i < session->cmds_max; i++) {
489 struct iscsi_task *task = session->cmds[i];
490 struct bnx2i_cmd *cmd = task->dd_data;
491
Michael Chancf4e6362009-06-08 18:14:44 -0700492 task->hdr = &cmd->hdr;
493 task->hdr_max = sizeof(struct iscsi_hdr);
494
495 if (bnx2i_alloc_bdt(hba, session, cmd))
496 goto free_bdts;
497 }
498
499 return 0;
500
501free_bdts:
502 bnx2i_destroy_cmd_pool(hba, session);
503 return -ENOMEM;
504}
505
506
507/**
508 * bnx2i_setup_mp_bdt - allocate BD table resources
509 * @hba: pointer to adapter structure
510 *
511 * Allocate memory for dummy buffer and associated BD
512 * table to be used by middle path (MP) requests
513 */
514static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
515{
516 int rc = 0;
517 struct iscsi_bd *mp_bdt;
518 u64 addr;
519
520 hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
521 &hba->mp_bd_dma, GFP_KERNEL);
522 if (!hba->mp_bd_tbl) {
523 printk(KERN_ERR "unable to allocate Middle Path BDT\n");
524 rc = -1;
525 goto out;
526 }
527
528 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
529 &hba->dummy_buf_dma, GFP_KERNEL);
530 if (!hba->dummy_buffer) {
531 printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n");
532 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
533 hba->mp_bd_tbl, hba->mp_bd_dma);
534 hba->mp_bd_tbl = NULL;
535 rc = -1;
536 goto out;
537 }
538
539 mp_bdt = (struct iscsi_bd *) hba->mp_bd_tbl;
540 addr = (unsigned long) hba->dummy_buf_dma;
541 mp_bdt->buffer_addr_lo = addr & 0xffffffff;
542 mp_bdt->buffer_addr_hi = addr >> 32;
543 mp_bdt->buffer_length = PAGE_SIZE;
544 mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
545 ISCSI_BD_FIRST_IN_BD_CHAIN;
546out:
547 return rc;
548}
549
550
551/**
552 * bnx2i_free_mp_bdt - releases ITT back to free pool
553 * @hba: pointer to adapter instance
554 *
555 * free MP dummy buffer and associated BD table
556 */
557static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba)
558{
559 if (hba->mp_bd_tbl) {
560 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
561 hba->mp_bd_tbl, hba->mp_bd_dma);
562 hba->mp_bd_tbl = NULL;
563 }
564 if (hba->dummy_buffer) {
565 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
566 hba->dummy_buffer, hba->dummy_buf_dma);
567 hba->dummy_buffer = NULL;
568 }
569 return;
570}
571
572/**
573 * bnx2i_drop_session - notifies iscsid of connection error.
574 * @hba: adapter instance pointer
575 * @session: iscsi session pointer
576 *
577 * This notifies iscsid that there is a error, so it can initiate
578 * recovery.
579 *
580 * This relies on caller using the iscsi class iterator so the object
581 * is refcounted and does not disapper from under us.
582 */
583void bnx2i_drop_session(struct iscsi_cls_session *cls_session)
584{
585 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
586}
587
588/**
589 * bnx2i_ep_destroy_list_add - add an entry to EP destroy list
590 * @hba: pointer to adapter instance
591 * @ep: pointer to endpoint (transport indentifier) structure
592 *
593 * EP destroy queue manager
594 */
595static int bnx2i_ep_destroy_list_add(struct bnx2i_hba *hba,
596 struct bnx2i_endpoint *ep)
597{
598 write_lock_bh(&hba->ep_rdwr_lock);
599 list_add_tail(&ep->link, &hba->ep_destroy_list);
600 write_unlock_bh(&hba->ep_rdwr_lock);
601 return 0;
602}
603
604/**
605 * bnx2i_ep_destroy_list_del - add an entry to EP destroy list
606 *
607 * @hba: pointer to adapter instance
608 * @ep: pointer to endpoint (transport indentifier) structure
609 *
610 * EP destroy queue manager
611 */
612static int bnx2i_ep_destroy_list_del(struct bnx2i_hba *hba,
613 struct bnx2i_endpoint *ep)
614{
615 write_lock_bh(&hba->ep_rdwr_lock);
616 list_del_init(&ep->link);
617 write_unlock_bh(&hba->ep_rdwr_lock);
618
619 return 0;
620}
621
622/**
623 * bnx2i_ep_ofld_list_add - add an entry to ep offload pending list
624 * @hba: pointer to adapter instance
625 * @ep: pointer to endpoint (transport indentifier) structure
626 *
627 * pending conn offload completion queue manager
628 */
629static int bnx2i_ep_ofld_list_add(struct bnx2i_hba *hba,
630 struct bnx2i_endpoint *ep)
631{
632 write_lock_bh(&hba->ep_rdwr_lock);
633 list_add_tail(&ep->link, &hba->ep_ofld_list);
634 write_unlock_bh(&hba->ep_rdwr_lock);
635 return 0;
636}
637
638/**
639 * bnx2i_ep_ofld_list_del - add an entry to ep offload pending list
640 * @hba: pointer to adapter instance
641 * @ep: pointer to endpoint (transport indentifier) structure
642 *
643 * pending conn offload completion queue manager
644 */
645static int bnx2i_ep_ofld_list_del(struct bnx2i_hba *hba,
646 struct bnx2i_endpoint *ep)
647{
648 write_lock_bh(&hba->ep_rdwr_lock);
649 list_del_init(&ep->link);
650 write_unlock_bh(&hba->ep_rdwr_lock);
651 return 0;
652}
653
654
655/**
656 * bnx2i_find_ep_in_ofld_list - find iscsi_cid in pending list of endpoints
657 *
658 * @hba: pointer to adapter instance
659 * @iscsi_cid: iscsi context ID to find
660 *
661 */
662struct bnx2i_endpoint *
663bnx2i_find_ep_in_ofld_list(struct bnx2i_hba *hba, u32 iscsi_cid)
664{
665 struct list_head *list;
666 struct list_head *tmp;
667 struct bnx2i_endpoint *ep;
668
669 read_lock_bh(&hba->ep_rdwr_lock);
670 list_for_each_safe(list, tmp, &hba->ep_ofld_list) {
671 ep = (struct bnx2i_endpoint *)list;
672
673 if (ep->ep_iscsi_cid == iscsi_cid)
674 break;
675 ep = NULL;
676 }
677 read_unlock_bh(&hba->ep_rdwr_lock);
678
679 if (!ep)
680 printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid);
681 return ep;
682}
683
Michael Chancf4e6362009-06-08 18:14:44 -0700684/**
685 * bnx2i_find_ep_in_destroy_list - find iscsi_cid in destroy list
686 * @hba: pointer to adapter instance
687 * @iscsi_cid: iscsi context ID to find
688 *
689 */
690struct bnx2i_endpoint *
691bnx2i_find_ep_in_destroy_list(struct bnx2i_hba *hba, u32 iscsi_cid)
692{
693 struct list_head *list;
694 struct list_head *tmp;
695 struct bnx2i_endpoint *ep;
696
697 read_lock_bh(&hba->ep_rdwr_lock);
698 list_for_each_safe(list, tmp, &hba->ep_destroy_list) {
699 ep = (struct bnx2i_endpoint *)list;
700
701 if (ep->ep_iscsi_cid == iscsi_cid)
702 break;
703 ep = NULL;
704 }
705 read_unlock_bh(&hba->ep_rdwr_lock);
706
707 if (!ep)
708 printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid);
709
710 return ep;
711}
712
Eddie Wai46012e82010-07-01 15:34:51 -0700713/**
714 * bnx2i_ep_active_list_add - add an entry to ep active list
715 * @hba: pointer to adapter instance
716 * @ep: pointer to endpoint (transport indentifier) structure
717 *
718 * current active conn queue manager
719 */
720static void bnx2i_ep_active_list_add(struct bnx2i_hba *hba,
721 struct bnx2i_endpoint *ep)
722{
723 write_lock_bh(&hba->ep_rdwr_lock);
724 list_add_tail(&ep->link, &hba->ep_active_list);
725 write_unlock_bh(&hba->ep_rdwr_lock);
726}
727
728
729/**
730 * bnx2i_ep_active_list_del - deletes an entry to ep active list
731 * @hba: pointer to adapter instance
732 * @ep: pointer to endpoint (transport indentifier) structure
733 *
734 * current active conn queue manager
735 */
736static void bnx2i_ep_active_list_del(struct bnx2i_hba *hba,
737 struct bnx2i_endpoint *ep)
738{
739 write_lock_bh(&hba->ep_rdwr_lock);
740 list_del_init(&ep->link);
741 write_unlock_bh(&hba->ep_rdwr_lock);
742}
743
744
Michael Chancf4e6362009-06-08 18:14:44 -0700745/**
746 * bnx2i_setup_host_queue_size - assigns shost->can_queue param
747 * @hba: pointer to adapter instance
748 * @shost: scsi host pointer
749 *
750 * Initializes 'can_queue' parameter based on how many outstanding commands
751 * the device can handle. Each device 5708/5709/57710 has different
752 * capabilities
753 */
754static void bnx2i_setup_host_queue_size(struct bnx2i_hba *hba,
755 struct Scsi_Host *shost)
756{
757 if (test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type))
758 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708;
759 else if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type))
760 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5709;
761 else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
762 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_57710;
763 else
764 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708;
765}
766
767
768/**
769 * bnx2i_alloc_hba - allocate and init adapter instance
770 * @cnic: cnic device pointer
771 *
772 * allocate & initialize adapter structure and call other
773 * support routines to do per adapter initialization
774 */
775struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic)
776{
777 struct Scsi_Host *shost;
778 struct bnx2i_hba *hba;
779
780 shost = iscsi_host_alloc(&bnx2i_host_template, sizeof(*hba), 0);
781 if (!shost)
782 return NULL;
783 shost->dma_boundary = cnic->pcidev->dma_mask;
784 shost->transportt = bnx2i_scsi_xport_template;
785 shost->max_id = ISCSI_MAX_CONNS_PER_HBA;
786 shost->max_channel = 0;
787 shost->max_lun = 512;
788 shost->max_cmd_len = 16;
789
790 hba = iscsi_host_priv(shost);
791 hba->shost = shost;
792 hba->netdev = cnic->netdev;
793 /* Get PCI related information and update hba struct members */
794 hba->pcidev = cnic->pcidev;
795 pci_dev_get(hba->pcidev);
796 hba->pci_did = hba->pcidev->device;
797 hba->pci_vid = hba->pcidev->vendor;
798 hba->pci_sdid = hba->pcidev->subsystem_device;
799 hba->pci_svid = hba->pcidev->subsystem_vendor;
800 hba->pci_func = PCI_FUNC(hba->pcidev->devfn);
801 hba->pci_devno = PCI_SLOT(hba->pcidev->devfn);
Michael Chancf4e6362009-06-08 18:14:44 -0700802
803 bnx2i_identify_device(hba);
804 bnx2i_setup_host_queue_size(hba, shost);
805
806 if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
807 hba->regview = ioremap_nocache(hba->netdev->base_addr,
808 BNX2_MQ_CONFIG2);
809 if (!hba->regview)
810 goto ioreg_map_err;
811 } else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
812 hba->regview = ioremap_nocache(hba->netdev->base_addr, 4096);
813 if (!hba->regview)
814 goto ioreg_map_err;
815 }
816
817 if (bnx2i_setup_mp_bdt(hba))
818 goto mp_bdt_mem_err;
819
820 INIT_LIST_HEAD(&hba->ep_ofld_list);
Eddie Wai46012e82010-07-01 15:34:51 -0700821 INIT_LIST_HEAD(&hba->ep_active_list);
Michael Chancf4e6362009-06-08 18:14:44 -0700822 INIT_LIST_HEAD(&hba->ep_destroy_list);
823 rwlock_init(&hba->ep_rdwr_lock);
824
825 hba->mtu_supported = BNX2I_MAX_MTU_SUPPORTED;
826
827 /* different values for 5708/5709/57710 */
828 hba->max_active_conns = ISCSI_MAX_CONNS_PER_HBA;
829
830 if (bnx2i_setup_free_cid_que(hba))
831 goto cid_que_err;
832
833 /* SQ/RQ/CQ size can be changed via sysfx interface */
834 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
835 if (sq_size && sq_size <= BNX2I_5770X_SQ_WQES_MAX)
836 hba->max_sqes = sq_size;
837 else
838 hba->max_sqes = BNX2I_5770X_SQ_WQES_DEFAULT;
839 } else { /* 5706/5708/5709 */
840 if (sq_size && sq_size <= BNX2I_570X_SQ_WQES_MAX)
841 hba->max_sqes = sq_size;
842 else
843 hba->max_sqes = BNX2I_570X_SQ_WQES_DEFAULT;
844 }
845
846 hba->max_rqes = rq_size;
847 hba->max_cqes = hba->max_sqes + rq_size;
848 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
849 if (hba->max_cqes > BNX2I_5770X_CQ_WQES_MAX)
850 hba->max_cqes = BNX2I_5770X_CQ_WQES_MAX;
851 } else if (hba->max_cqes > BNX2I_570X_CQ_WQES_MAX)
852 hba->max_cqes = BNX2I_570X_CQ_WQES_MAX;
853
854 hba->num_ccell = hba->max_sqes / 2;
855
856 spin_lock_init(&hba->lock);
857 mutex_init(&hba->net_dev_lock);
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700858 init_waitqueue_head(&hba->eh_wait);
Eddie Waie37d2c42010-07-01 15:34:53 -0700859 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
Eddie Wai55e15c92010-07-01 15:34:52 -0700860 hba->hba_shutdown_tmo = 20 * HZ;
Eddie Waie37d2c42010-07-01 15:34:53 -0700861 hba->conn_teardown_tmo = 20 * HZ;
862 hba->conn_ctx_destroy_tmo = 6 * HZ;
863 } else { /* 5706/5708/5709 */
Eddie Wai55e15c92010-07-01 15:34:52 -0700864 hba->hba_shutdown_tmo = 20 * HZ;
Eddie Waie37d2c42010-07-01 15:34:53 -0700865 hba->conn_teardown_tmo = 10 * HZ;
866 hba->conn_ctx_destroy_tmo = 2 * HZ;
867 }
Michael Chancf4e6362009-06-08 18:14:44 -0700868
869 if (iscsi_host_add(shost, &hba->pcidev->dev))
870 goto free_dump_mem;
871 return hba;
872
873free_dump_mem:
874 bnx2i_release_free_cid_que(hba);
875cid_que_err:
876 bnx2i_free_mp_bdt(hba);
877mp_bdt_mem_err:
878 if (hba->regview) {
879 iounmap(hba->regview);
880 hba->regview = NULL;
881 }
882ioreg_map_err:
883 pci_dev_put(hba->pcidev);
884 scsi_host_put(shost);
885 return NULL;
886}
887
888/**
889 * bnx2i_free_hba- releases hba structure and resources held by the adapter
890 * @hba: pointer to adapter instance
891 *
892 * free adapter structure and call various cleanup routines.
893 */
894void bnx2i_free_hba(struct bnx2i_hba *hba)
895{
896 struct Scsi_Host *shost = hba->shost;
897
898 iscsi_host_remove(shost);
899 INIT_LIST_HEAD(&hba->ep_ofld_list);
Eddie Wai46012e82010-07-01 15:34:51 -0700900 INIT_LIST_HEAD(&hba->ep_active_list);
Michael Chancf4e6362009-06-08 18:14:44 -0700901 INIT_LIST_HEAD(&hba->ep_destroy_list);
902 pci_dev_put(hba->pcidev);
903
904 if (hba->regview) {
905 iounmap(hba->regview);
906 hba->regview = NULL;
907 }
908 bnx2i_free_mp_bdt(hba);
909 bnx2i_release_free_cid_que(hba);
910 iscsi_host_free(shost);
911}
912
913/**
914 * bnx2i_conn_free_login_resources - free DMA resources used for login process
915 * @hba: pointer to adapter instance
916 * @bnx2i_conn: iscsi connection pointer
917 *
918 * Login related resources, mostly BDT & payload DMA memory is freed
919 */
920static void bnx2i_conn_free_login_resources(struct bnx2i_hba *hba,
921 struct bnx2i_conn *bnx2i_conn)
922{
923 if (bnx2i_conn->gen_pdu.resp_bd_tbl) {
924 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
925 bnx2i_conn->gen_pdu.resp_bd_tbl,
926 bnx2i_conn->gen_pdu.resp_bd_dma);
927 bnx2i_conn->gen_pdu.resp_bd_tbl = NULL;
928 }
929
930 if (bnx2i_conn->gen_pdu.req_bd_tbl) {
931 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
932 bnx2i_conn->gen_pdu.req_bd_tbl,
933 bnx2i_conn->gen_pdu.req_bd_dma);
934 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
935 }
936
937 if (bnx2i_conn->gen_pdu.resp_buf) {
938 dma_free_coherent(&hba->pcidev->dev,
939 ISCSI_DEF_MAX_RECV_SEG_LEN,
940 bnx2i_conn->gen_pdu.resp_buf,
941 bnx2i_conn->gen_pdu.resp_dma_addr);
942 bnx2i_conn->gen_pdu.resp_buf = NULL;
943 }
944
945 if (bnx2i_conn->gen_pdu.req_buf) {
946 dma_free_coherent(&hba->pcidev->dev,
947 ISCSI_DEF_MAX_RECV_SEG_LEN,
948 bnx2i_conn->gen_pdu.req_buf,
949 bnx2i_conn->gen_pdu.req_dma_addr);
950 bnx2i_conn->gen_pdu.req_buf = NULL;
951 }
952}
953
954/**
955 * bnx2i_conn_alloc_login_resources - alloc DMA resources for login/nop.
956 * @hba: pointer to adapter instance
957 * @bnx2i_conn: iscsi connection pointer
958 *
959 * Mgmt task DNA resources are allocated in this routine.
960 */
961static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
962 struct bnx2i_conn *bnx2i_conn)
963{
964 /* Allocate memory for login request/response buffers */
965 bnx2i_conn->gen_pdu.req_buf =
966 dma_alloc_coherent(&hba->pcidev->dev,
967 ISCSI_DEF_MAX_RECV_SEG_LEN,
968 &bnx2i_conn->gen_pdu.req_dma_addr,
969 GFP_KERNEL);
970 if (bnx2i_conn->gen_pdu.req_buf == NULL)
971 goto login_req_buf_failure;
972
973 bnx2i_conn->gen_pdu.req_buf_size = 0;
974 bnx2i_conn->gen_pdu.req_wr_ptr = bnx2i_conn->gen_pdu.req_buf;
975
976 bnx2i_conn->gen_pdu.resp_buf =
977 dma_alloc_coherent(&hba->pcidev->dev,
978 ISCSI_DEF_MAX_RECV_SEG_LEN,
979 &bnx2i_conn->gen_pdu.resp_dma_addr,
980 GFP_KERNEL);
981 if (bnx2i_conn->gen_pdu.resp_buf == NULL)
982 goto login_resp_buf_failure;
983
984 bnx2i_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
985 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf;
986
987 bnx2i_conn->gen_pdu.req_bd_tbl =
988 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
989 &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
990 if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL)
991 goto login_req_bd_tbl_failure;
992
993 bnx2i_conn->gen_pdu.resp_bd_tbl =
994 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
995 &bnx2i_conn->gen_pdu.resp_bd_dma,
996 GFP_KERNEL);
997 if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL)
998 goto login_resp_bd_tbl_failure;
999
1000 return 0;
1001
1002login_resp_bd_tbl_failure:
1003 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1004 bnx2i_conn->gen_pdu.req_bd_tbl,
1005 bnx2i_conn->gen_pdu.req_bd_dma);
1006 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
1007
1008login_req_bd_tbl_failure:
1009 dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
1010 bnx2i_conn->gen_pdu.resp_buf,
1011 bnx2i_conn->gen_pdu.resp_dma_addr);
1012 bnx2i_conn->gen_pdu.resp_buf = NULL;
1013login_resp_buf_failure:
1014 dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
1015 bnx2i_conn->gen_pdu.req_buf,
1016 bnx2i_conn->gen_pdu.req_dma_addr);
1017 bnx2i_conn->gen_pdu.req_buf = NULL;
1018login_req_buf_failure:
1019 iscsi_conn_printk(KERN_ERR, bnx2i_conn->cls_conn->dd_data,
1020 "login resource alloc failed!!\n");
1021 return -ENOMEM;
1022
1023}
1024
1025
1026/**
1027 * bnx2i_iscsi_prep_generic_pdu_bd - prepares BD table.
1028 * @bnx2i_conn: iscsi connection pointer
1029 *
1030 * Allocates buffers and BD tables before shipping requests to cnic
1031 * for PDUs prepared by 'iscsid' daemon
1032 */
1033static void bnx2i_iscsi_prep_generic_pdu_bd(struct bnx2i_conn *bnx2i_conn)
1034{
1035 struct iscsi_bd *bd_tbl;
1036
1037 bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.req_bd_tbl;
1038
1039 bd_tbl->buffer_addr_hi =
1040 (u32) ((u64) bnx2i_conn->gen_pdu.req_dma_addr >> 32);
1041 bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.req_dma_addr;
1042 bd_tbl->buffer_length = bnx2i_conn->gen_pdu.req_wr_ptr -
1043 bnx2i_conn->gen_pdu.req_buf;
1044 bd_tbl->reserved0 = 0;
1045 bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
1046 ISCSI_BD_FIRST_IN_BD_CHAIN;
1047
1048 bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.resp_bd_tbl;
1049 bd_tbl->buffer_addr_hi = (u64) bnx2i_conn->gen_pdu.resp_dma_addr >> 32;
1050 bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_dma_addr;
1051 bd_tbl->buffer_length = ISCSI_DEF_MAX_RECV_SEG_LEN;
1052 bd_tbl->reserved0 = 0;
1053 bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
1054 ISCSI_BD_FIRST_IN_BD_CHAIN;
1055}
1056
1057
1058/**
1059 * bnx2i_iscsi_send_generic_request - called to send mgmt tasks.
1060 * @task: transport layer task pointer
1061 *
1062 * called to transmit PDUs prepared by the 'iscsid' daemon. iSCSI login,
1063 * Nop-out and Logout requests flow through this path.
1064 */
1065static int bnx2i_iscsi_send_generic_request(struct iscsi_task *task)
1066{
1067 struct bnx2i_cmd *cmd = task->dd_data;
1068 struct bnx2i_conn *bnx2i_conn = cmd->conn;
1069 int rc = 0;
1070 char *buf;
1071 int data_len;
1072
1073 bnx2i_iscsi_prep_generic_pdu_bd(bnx2i_conn);
1074 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
1075 case ISCSI_OP_LOGIN:
1076 bnx2i_send_iscsi_login(bnx2i_conn, task);
1077 break;
1078 case ISCSI_OP_NOOP_OUT:
1079 data_len = bnx2i_conn->gen_pdu.req_buf_size;
1080 buf = bnx2i_conn->gen_pdu.req_buf;
1081 if (data_len)
1082 rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
Michael Chancf4e6362009-06-08 18:14:44 -07001083 buf, data_len, 1);
1084 else
1085 rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
Michael Chancf4e6362009-06-08 18:14:44 -07001086 NULL, 0, 1);
1087 break;
1088 case ISCSI_OP_LOGOUT:
1089 rc = bnx2i_send_iscsi_logout(bnx2i_conn, task);
1090 break;
1091 case ISCSI_OP_SCSI_TMFUNC:
1092 rc = bnx2i_send_iscsi_tmf(bnx2i_conn, task);
1093 break;
1094 default:
1095 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1096 "send_gen: unsupported op 0x%x\n",
1097 task->hdr->opcode);
1098 }
1099 return rc;
1100}
1101
1102
1103/**********************************************************************
1104 * SCSI-ML Interface
1105 **********************************************************************/
1106
1107/**
1108 * bnx2i_cpy_scsi_cdb - copies LUN & CDB fields in required format to sq wqe
1109 * @sc: SCSI-ML command pointer
1110 * @cmd: iscsi cmd pointer
1111 */
1112static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd *sc, struct bnx2i_cmd *cmd)
1113{
1114 u32 dword;
1115 int lpcnt;
1116 u8 *srcp;
1117 u32 *dstp;
1118 u32 scsi_lun[2];
1119
1120 int_to_scsilun(sc->device->lun, (struct scsi_lun *) scsi_lun);
1121 cmd->req.lun[0] = be32_to_cpu(scsi_lun[0]);
1122 cmd->req.lun[1] = be32_to_cpu(scsi_lun[1]);
1123
1124 lpcnt = cmd->scsi_cmd->cmd_len / sizeof(dword);
1125 srcp = (u8 *) sc->cmnd;
1126 dstp = (u32 *) cmd->req.cdb;
1127 while (lpcnt--) {
1128 memcpy(&dword, (const void *) srcp, 4);
1129 *dstp = cpu_to_be32(dword);
1130 srcp += 4;
1131 dstp++;
1132 }
1133 if (sc->cmd_len & 0x3) {
1134 dword = (u32) srcp[0] | ((u32) srcp[1] << 8);
1135 *dstp = cpu_to_be32(dword);
1136 }
1137}
1138
1139static void bnx2i_cleanup_task(struct iscsi_task *task)
1140{
1141 struct iscsi_conn *conn = task->conn;
1142 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1143 struct bnx2i_hba *hba = bnx2i_conn->hba;
1144
1145 /*
1146 * mgmt task or cmd was never sent to us to transmit.
1147 */
1148 if (!task->sc || task->state == ISCSI_TASK_PENDING)
1149 return;
1150 /*
1151 * need to clean-up task context to claim dma buffers
1152 */
1153 if (task->state == ISCSI_TASK_ABRT_TMF) {
1154 bnx2i_send_cmd_cleanup_req(hba, task->dd_data);
1155
1156 spin_unlock_bh(&conn->session->lock);
1157 wait_for_completion_timeout(&bnx2i_conn->cmd_cleanup_cmpl,
1158 msecs_to_jiffies(ISCSI_CMD_CLEANUP_TIMEOUT));
1159 spin_lock_bh(&conn->session->lock);
1160 }
1161 bnx2i_iscsi_unmap_sg_list(task->dd_data);
1162}
1163
1164/**
1165 * bnx2i_mtask_xmit - transmit mtask to chip for further processing
1166 * @conn: transport layer conn structure pointer
1167 * @task: transport layer command structure pointer
1168 */
1169static int
1170bnx2i_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
1171{
1172 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1173 struct bnx2i_cmd *cmd = task->dd_data;
1174
1175 memset(bnx2i_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
1176
1177 bnx2i_setup_cmd_wqe_template(cmd);
1178 bnx2i_conn->gen_pdu.req_buf_size = task->data_count;
1179 if (task->data_count) {
1180 memcpy(bnx2i_conn->gen_pdu.req_buf, task->data,
1181 task->data_count);
1182 bnx2i_conn->gen_pdu.req_wr_ptr =
1183 bnx2i_conn->gen_pdu.req_buf + task->data_count;
1184 }
1185 cmd->conn = conn->dd_data;
1186 cmd->scsi_cmd = NULL;
1187 return bnx2i_iscsi_send_generic_request(task);
1188}
1189
1190/**
1191 * bnx2i_task_xmit - transmit iscsi command to chip for further processing
1192 * @task: transport layer command structure pointer
1193 *
1194 * maps SG buffers and send request to chip/firmware in the form of SQ WQE
1195 */
1196static int bnx2i_task_xmit(struct iscsi_task *task)
1197{
1198 struct iscsi_conn *conn = task->conn;
1199 struct iscsi_session *session = conn->session;
1200 struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session);
1201 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1202 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1203 struct scsi_cmnd *sc = task->sc;
1204 struct bnx2i_cmd *cmd = task->dd_data;
1205 struct iscsi_cmd *hdr = (struct iscsi_cmd *) task->hdr;
1206
Michael Chancf4e6362009-06-08 18:14:44 -07001207 /*
1208 * If there is no scsi_cmnd this must be a mgmt task
1209 */
1210 if (!sc)
1211 return bnx2i_mtask_xmit(conn, task);
1212
1213 bnx2i_setup_cmd_wqe_template(cmd);
1214 cmd->req.op_code = ISCSI_OP_SCSI_CMD;
1215 cmd->conn = bnx2i_conn;
1216 cmd->scsi_cmd = sc;
1217 cmd->req.total_data_transfer_length = scsi_bufflen(sc);
1218 cmd->req.cmd_sn = be32_to_cpu(hdr->cmdsn);
1219
1220 bnx2i_iscsi_map_sg_list(cmd);
1221 bnx2i_cpy_scsi_cdb(sc, cmd);
1222
1223 cmd->req.op_attr = ISCSI_ATTR_SIMPLE;
1224 if (sc->sc_data_direction == DMA_TO_DEVICE) {
1225 cmd->req.op_attr |= ISCSI_CMD_REQUEST_WRITE;
1226 cmd->req.itt = task->itt |
1227 (ISCSI_TASK_TYPE_WRITE << ISCSI_CMD_REQUEST_TYPE_SHIFT);
1228 bnx2i_setup_write_cmd_bd_info(task);
1229 } else {
1230 if (scsi_bufflen(sc))
1231 cmd->req.op_attr |= ISCSI_CMD_REQUEST_READ;
1232 cmd->req.itt = task->itt |
1233 (ISCSI_TASK_TYPE_READ << ISCSI_CMD_REQUEST_TYPE_SHIFT);
1234 }
1235
1236 cmd->req.num_bds = cmd->io_tbl.bd_valid;
1237 if (!cmd->io_tbl.bd_valid) {
1238 cmd->req.bd_list_addr_lo = (u32) hba->mp_bd_dma;
1239 cmd->req.bd_list_addr_hi = (u32) ((u64) hba->mp_bd_dma >> 32);
1240 cmd->req.num_bds = 1;
1241 }
1242
1243 bnx2i_send_iscsi_scsicmd(bnx2i_conn, cmd);
1244 return 0;
1245}
1246
1247/**
1248 * bnx2i_session_create - create a new iscsi session
1249 * @cmds_max: max commands supported
1250 * @qdepth: scsi queue depth to support
1251 * @initial_cmdsn: initial iscsi CMDSN to be used for this session
1252 *
1253 * Creates a new iSCSI session instance on given device.
1254 */
1255static struct iscsi_cls_session *
1256bnx2i_session_create(struct iscsi_endpoint *ep,
1257 uint16_t cmds_max, uint16_t qdepth,
1258 uint32_t initial_cmdsn)
1259{
1260 struct Scsi_Host *shost;
1261 struct iscsi_cls_session *cls_session;
1262 struct bnx2i_hba *hba;
1263 struct bnx2i_endpoint *bnx2i_ep;
1264
1265 if (!ep) {
1266 printk(KERN_ERR "bnx2i: missing ep.\n");
1267 return NULL;
1268 }
1269
1270 bnx2i_ep = ep->dd_data;
1271 shost = bnx2i_ep->hba->shost;
1272 hba = iscsi_host_priv(shost);
1273 if (bnx2i_adapter_ready(hba))
1274 return NULL;
1275
1276 /*
1277 * user can override hw limit as long as it is within
1278 * the min/max.
1279 */
1280 if (cmds_max > hba->max_sqes)
1281 cmds_max = hba->max_sqes;
1282 else if (cmds_max < BNX2I_SQ_WQES_MIN)
1283 cmds_max = BNX2I_SQ_WQES_MIN;
1284
1285 cls_session = iscsi_session_setup(&bnx2i_iscsi_transport, shost,
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +05301286 cmds_max, 0, sizeof(struct bnx2i_cmd),
Michael Chancf4e6362009-06-08 18:14:44 -07001287 initial_cmdsn, ISCSI_MAX_TARGET);
1288 if (!cls_session)
1289 return NULL;
1290
1291 if (bnx2i_setup_cmd_pool(hba, cls_session->dd_data))
1292 goto session_teardown;
1293 return cls_session;
1294
1295session_teardown:
1296 iscsi_session_teardown(cls_session);
1297 return NULL;
1298}
1299
1300
1301/**
1302 * bnx2i_session_destroy - destroys iscsi session
1303 * @cls_session: pointer to iscsi cls session
1304 *
1305 * Destroys previously created iSCSI session instance and releases
1306 * all resources held by it
1307 */
1308static void bnx2i_session_destroy(struct iscsi_cls_session *cls_session)
1309{
1310 struct iscsi_session *session = cls_session->dd_data;
1311 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1312 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1313
1314 bnx2i_destroy_cmd_pool(hba, session);
1315 iscsi_session_teardown(cls_session);
1316}
1317
1318
1319/**
1320 * bnx2i_conn_create - create iscsi connection instance
1321 * @cls_session: pointer to iscsi cls session
1322 * @cid: iscsi cid as per rfc (not NX2's CID terminology)
1323 *
1324 * Creates a new iSCSI connection instance for a given session
1325 */
1326static struct iscsi_cls_conn *
1327bnx2i_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
1328{
1329 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1330 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1331 struct bnx2i_conn *bnx2i_conn;
1332 struct iscsi_cls_conn *cls_conn;
1333 struct iscsi_conn *conn;
1334
1335 cls_conn = iscsi_conn_setup(cls_session, sizeof(*bnx2i_conn),
1336 cid);
1337 if (!cls_conn)
1338 return NULL;
1339 conn = cls_conn->dd_data;
1340
1341 bnx2i_conn = conn->dd_data;
1342 bnx2i_conn->cls_conn = cls_conn;
1343 bnx2i_conn->hba = hba;
1344 /* 'ep' ptr will be assigned in bind() call */
1345 bnx2i_conn->ep = NULL;
1346 init_completion(&bnx2i_conn->cmd_cleanup_cmpl);
1347
1348 if (bnx2i_conn_alloc_login_resources(hba, bnx2i_conn)) {
1349 iscsi_conn_printk(KERN_ALERT, conn,
1350 "conn_new: login resc alloc failed!!\n");
1351 goto free_conn;
1352 }
1353
1354 return cls_conn;
1355
1356free_conn:
1357 iscsi_conn_teardown(cls_conn);
1358 return NULL;
1359}
1360
1361/**
1362 * bnx2i_conn_bind - binds iscsi sess, conn and ep objects together
1363 * @cls_session: pointer to iscsi cls session
1364 * @cls_conn: pointer to iscsi cls conn
1365 * @transport_fd: 64-bit EP handle
1366 * @is_leading: leading connection on this session?
1367 *
1368 * Binds together iSCSI session instance, iSCSI connection instance
1369 * and the TCP connection. This routine returns error code if
1370 * TCP connection does not belong on the device iSCSI sess/conn
1371 * is bound
1372 */
1373static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session,
1374 struct iscsi_cls_conn *cls_conn,
1375 uint64_t transport_fd, int is_leading)
1376{
1377 struct iscsi_conn *conn = cls_conn->dd_data;
1378 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1379 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1380 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1381 struct bnx2i_endpoint *bnx2i_ep;
1382 struct iscsi_endpoint *ep;
1383 int ret_code;
1384
1385 ep = iscsi_lookup_endpoint(transport_fd);
1386 if (!ep)
1387 return -EINVAL;
Eddie Wai842158d2010-11-23 15:29:28 -08001388 /*
1389 * Forcefully terminate all in progress connection recovery at the
1390 * earliest, either in bind(), send_pdu(LOGIN), or conn_start()
1391 */
1392 if (bnx2i_adapter_ready(hba))
1393 return -EIO;
Michael Chancf4e6362009-06-08 18:14:44 -07001394
1395 bnx2i_ep = ep->dd_data;
1396 if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) ||
1397 (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD))
1398 /* Peer disconnect via' FIN or RST */
1399 return -EINVAL;
1400
1401 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1402 return -EINVAL;
1403
1404 if (bnx2i_ep->hba != hba) {
1405 /* Error - TCP connection does not belong to this device
1406 */
1407 iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
1408 "conn bind, ep=0x%p (%s) does not",
1409 bnx2i_ep, bnx2i_ep->hba->netdev->name);
1410 iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
1411 "belong to hba (%s)\n",
1412 hba->netdev->name);
1413 return -EEXIST;
1414 }
Michael Chancf4e6362009-06-08 18:14:44 -07001415 bnx2i_ep->conn = bnx2i_conn;
1416 bnx2i_conn->ep = bnx2i_ep;
1417 bnx2i_conn->iscsi_conn_cid = bnx2i_ep->ep_iscsi_cid;
1418 bnx2i_conn->fw_cid = bnx2i_ep->ep_cid;
Michael Chancf4e6362009-06-08 18:14:44 -07001419
1420 ret_code = bnx2i_bind_conn_to_iscsi_cid(hba, bnx2i_conn,
1421 bnx2i_ep->ep_iscsi_cid);
1422
1423 /* 5706/5708/5709 FW takes RQ as full when initiated, but for 57710
1424 * driver needs to explicitly replenish RQ index during setup.
1425 */
1426 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
1427 bnx2i_put_rq_buf(bnx2i_conn, 0);
1428
1429 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1430 return ret_code;
1431}
1432
1433
1434/**
1435 * bnx2i_conn_destroy - destroy iscsi connection instance & release resources
1436 * @cls_conn: pointer to iscsi cls conn
1437 *
1438 * Destroy an iSCSI connection instance and release memory resources held by
1439 * this connection
1440 */
1441static void bnx2i_conn_destroy(struct iscsi_cls_conn *cls_conn)
1442{
1443 struct iscsi_conn *conn = cls_conn->dd_data;
1444 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1445 struct Scsi_Host *shost;
1446 struct bnx2i_hba *hba;
1447
1448 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
1449 hba = iscsi_host_priv(shost);
1450
1451 bnx2i_conn_free_login_resources(hba, bnx2i_conn);
1452 iscsi_conn_teardown(cls_conn);
1453}
1454
1455
1456/**
1457 * bnx2i_conn_get_param - return iscsi connection parameter to caller
1458 * @cls_conn: pointer to iscsi cls conn
1459 * @param: parameter type identifier
1460 * @buf: buffer pointer
1461 *
1462 * returns iSCSI connection parameters
1463 */
1464static int bnx2i_conn_get_param(struct iscsi_cls_conn *cls_conn,
1465 enum iscsi_param param, char *buf)
1466{
1467 struct iscsi_conn *conn = cls_conn->dd_data;
1468 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1469 int len = 0;
1470
Eddie Wai7a2962c2010-11-23 15:29:26 -08001471 if (!(bnx2i_conn && bnx2i_conn->ep && bnx2i_conn->ep->hba))
1472 goto out;
1473
Michael Chancf4e6362009-06-08 18:14:44 -07001474 switch (param) {
1475 case ISCSI_PARAM_CONN_PORT:
Eddie Wai7a2962c2010-11-23 15:29:26 -08001476 mutex_lock(&bnx2i_conn->ep->hba->net_dev_lock);
1477 if (bnx2i_conn->ep->cm_sk)
Michael Chancf4e6362009-06-08 18:14:44 -07001478 len = sprintf(buf, "%hu\n",
1479 bnx2i_conn->ep->cm_sk->dst_port);
Eddie Wai7a2962c2010-11-23 15:29:26 -08001480 mutex_unlock(&bnx2i_conn->ep->hba->net_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -07001481 break;
1482 case ISCSI_PARAM_CONN_ADDRESS:
Eddie Wai7a2962c2010-11-23 15:29:26 -08001483 mutex_lock(&bnx2i_conn->ep->hba->net_dev_lock);
1484 if (bnx2i_conn->ep->cm_sk)
Joe Perchesd9573e72010-02-10 16:51:43 -06001485 len = sprintf(buf, "%pI4\n",
1486 &bnx2i_conn->ep->cm_sk->dst_ip);
Eddie Wai7a2962c2010-11-23 15:29:26 -08001487 mutex_unlock(&bnx2i_conn->ep->hba->net_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -07001488 break;
1489 default:
1490 return iscsi_conn_get_param(cls_conn, param, buf);
1491 }
Eddie Wai7a2962c2010-11-23 15:29:26 -08001492out:
Michael Chancf4e6362009-06-08 18:14:44 -07001493 return len;
1494}
1495
1496/**
1497 * bnx2i_host_get_param - returns host (adapter) related parameters
1498 * @shost: scsi host pointer
1499 * @param: parameter type identifier
1500 * @buf: buffer pointer
1501 */
1502static int bnx2i_host_get_param(struct Scsi_Host *shost,
1503 enum iscsi_host_param param, char *buf)
1504{
1505 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1506 int len = 0;
1507
1508 switch (param) {
1509 case ISCSI_HOST_PARAM_HWADDRESS:
1510 len = sysfs_format_mac(buf, hba->cnic->mac_addr, 6);
1511 break;
1512 case ISCSI_HOST_PARAM_NETDEV_NAME:
1513 len = sprintf(buf, "%s\n", hba->netdev->name);
1514 break;
Michael Chan625986c2010-07-01 15:34:55 -07001515 case ISCSI_HOST_PARAM_IPADDRESS: {
1516 struct list_head *active_list = &hba->ep_active_list;
1517
1518 read_lock_bh(&hba->ep_rdwr_lock);
1519 if (!list_empty(&hba->ep_active_list)) {
1520 struct bnx2i_endpoint *bnx2i_ep;
1521 struct cnic_sock *csk;
1522
1523 bnx2i_ep = list_first_entry(active_list,
1524 struct bnx2i_endpoint,
1525 link);
1526 csk = bnx2i_ep->cm_sk;
1527 if (test_bit(SK_F_IPV6, &csk->flags))
1528 len = sprintf(buf, "%pI6\n", csk->src_ip);
1529 else
1530 len = sprintf(buf, "%pI4\n", csk->src_ip);
1531 }
1532 read_unlock_bh(&hba->ep_rdwr_lock);
1533 break;
1534 }
Michael Chancf4e6362009-06-08 18:14:44 -07001535 default:
1536 return iscsi_host_get_param(shost, param, buf);
1537 }
1538 return len;
1539}
1540
1541/**
1542 * bnx2i_conn_start - completes iscsi connection migration to FFP
1543 * @cls_conn: pointer to iscsi cls conn
1544 *
1545 * last call in FFP migration to handover iscsi conn to the driver
1546 */
1547static int bnx2i_conn_start(struct iscsi_cls_conn *cls_conn)
1548{
1549 struct iscsi_conn *conn = cls_conn->dd_data;
1550 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1551
1552 bnx2i_conn->ep->state = EP_STATE_ULP_UPDATE_START;
1553 bnx2i_update_iscsi_conn(conn);
1554
1555 /*
1556 * this should normally not sleep for a long time so it should
1557 * not disrupt the caller.
1558 */
1559 bnx2i_conn->ep->ofld_timer.expires = 1 * HZ + jiffies;
1560 bnx2i_conn->ep->ofld_timer.function = bnx2i_ep_ofld_timer;
1561 bnx2i_conn->ep->ofld_timer.data = (unsigned long) bnx2i_conn->ep;
1562 add_timer(&bnx2i_conn->ep->ofld_timer);
1563 /* update iSCSI context for this conn, wait for CNIC to complete */
1564 wait_event_interruptible(bnx2i_conn->ep->ofld_wait,
1565 bnx2i_conn->ep->state != EP_STATE_ULP_UPDATE_START);
1566
1567 if (signal_pending(current))
1568 flush_signals(current);
1569 del_timer_sync(&bnx2i_conn->ep->ofld_timer);
1570
1571 iscsi_conn_start(cls_conn);
1572 return 0;
1573}
1574
1575
1576/**
1577 * bnx2i_conn_get_stats - returns iSCSI stats
1578 * @cls_conn: pointer to iscsi cls conn
1579 * @stats: pointer to iscsi statistic struct
1580 */
1581static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1582 struct iscsi_stats *stats)
1583{
1584 struct iscsi_conn *conn = cls_conn->dd_data;
1585
1586 stats->txdata_octets = conn->txdata_octets;
1587 stats->rxdata_octets = conn->rxdata_octets;
1588 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
1589 stats->dataout_pdus = conn->dataout_pdus_cnt;
1590 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
1591 stats->datain_pdus = conn->datain_pdus_cnt;
1592 stats->r2t_pdus = conn->r2t_pdus_cnt;
1593 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
1594 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
1595 stats->custom_length = 3;
1596 strcpy(stats->custom[2].desc, "eh_abort_cnt");
1597 stats->custom[2].value = conn->eh_abort_cnt;
1598 stats->digest_err = 0;
1599 stats->timeout_err = 0;
1600 stats->custom_length = 0;
1601}
1602
1603
1604/**
1605 * bnx2i_check_route - checks if target IP route belongs to one of NX2 devices
1606 * @dst_addr: target IP address
1607 *
1608 * check if route resolves to BNX2 device
1609 */
1610static struct bnx2i_hba *bnx2i_check_route(struct sockaddr *dst_addr)
1611{
1612 struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
1613 struct bnx2i_hba *hba;
1614 struct cnic_dev *cnic = NULL;
1615
Michael Chancf4e6362009-06-08 18:14:44 -07001616 hba = get_adapter_list_head();
1617 if (hba && hba->cnic)
1618 cnic = hba->cnic->cm_select_dev(desti, CNIC_ULP_ISCSI);
1619 if (!cnic) {
1620 printk(KERN_ALERT "bnx2i: no route,"
1621 "can't connect using cnic\n");
1622 goto no_nx2_route;
1623 }
1624 hba = bnx2i_find_hba_for_cnic(cnic);
1625 if (!hba)
1626 goto no_nx2_route;
1627
1628 if (bnx2i_adapter_ready(hba)) {
1629 printk(KERN_ALERT "bnx2i: check route, hba not found\n");
1630 goto no_nx2_route;
1631 }
1632 if (hba->netdev->mtu > hba->mtu_supported) {
1633 printk(KERN_ALERT "bnx2i: %s network i/f mtu is set to %d\n",
1634 hba->netdev->name, hba->netdev->mtu);
1635 printk(KERN_ALERT "bnx2i: iSCSI HBA can support mtu of %d\n",
1636 hba->mtu_supported);
1637 goto no_nx2_route;
1638 }
1639 return hba;
1640no_nx2_route:
1641 return NULL;
1642}
1643
1644
1645/**
1646 * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources
1647 * @hba: pointer to adapter instance
1648 * @ep: endpoint (transport indentifier) structure
1649 *
1650 * destroys cm_sock structure and on chip iscsi context
1651 */
1652static int bnx2i_tear_down_conn(struct bnx2i_hba *hba,
1653 struct bnx2i_endpoint *ep)
1654{
Eddie Wai5bf3f392010-11-23 15:29:23 -08001655 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic) && ep->cm_sk)
Michael Chancf4e6362009-06-08 18:14:44 -07001656 hba->cnic->cm_destroy(ep->cm_sk);
1657
Michael Chancf4e6362009-06-08 18:14:44 -07001658 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type) &&
1659 ep->state == EP_STATE_DISCONN_TIMEDOUT) {
Eddie Wai5bf3f392010-11-23 15:29:23 -08001660 if (ep->conn && ep->conn->cls_conn &&
1661 ep->conn->cls_conn->dd_data) {
1662 struct iscsi_conn *conn = ep->conn->cls_conn->dd_data;
1663
1664 /* Must suspend all rx queue activity for this ep */
1665 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
1666 }
1667 /* CONN_DISCONNECT timeout may or may not be an issue depending
1668 * on what transcribed in TCP layer, different targets behave
1669 * differently
1670 */
1671 printk(KERN_ALERT "bnx2i (%s): - WARN - CONN_DISCON timed out, "
1672 "please submit GRC Dump, NW/PCIe trace, "
1673 "driver msgs to developers for analysis\n",
1674 hba->netdev->name);
Michael Chancf4e6362009-06-08 18:14:44 -07001675 }
1676
1677 ep->state = EP_STATE_CLEANUP_START;
1678 init_timer(&ep->ofld_timer);
Eddie Waie37d2c42010-07-01 15:34:53 -07001679 ep->ofld_timer.expires = hba->conn_ctx_destroy_tmo + jiffies;
Michael Chancf4e6362009-06-08 18:14:44 -07001680 ep->ofld_timer.function = bnx2i_ep_ofld_timer;
1681 ep->ofld_timer.data = (unsigned long) ep;
1682 add_timer(&ep->ofld_timer);
1683
1684 bnx2i_ep_destroy_list_add(hba, ep);
1685
1686 /* destroy iSCSI context, wait for it to complete */
Eddie Waibee34872010-11-23 15:29:29 -08001687 if (bnx2i_send_conn_destroy(hba, ep))
1688 ep->state = EP_STATE_CLEANUP_CMPL;
1689
Michael Chancf4e6362009-06-08 18:14:44 -07001690 wait_event_interruptible(ep->ofld_wait,
1691 (ep->state != EP_STATE_CLEANUP_START));
1692
1693 if (signal_pending(current))
1694 flush_signals(current);
1695 del_timer_sync(&ep->ofld_timer);
1696
1697 bnx2i_ep_destroy_list_del(hba, ep);
1698
1699 if (ep->state != EP_STATE_CLEANUP_CMPL)
1700 /* should never happen */
1701 printk(KERN_ALERT "bnx2i - conn destroy failed\n");
1702
1703 return 0;
1704}
1705
1706
1707/**
1708 * bnx2i_ep_connect - establish TCP connection to target portal
1709 * @shost: scsi host
1710 * @dst_addr: target IP address
1711 * @non_blocking: blocking or non-blocking call
1712 *
1713 * this routine initiates the TCP/IP connection by invoking Option-2 i/f
1714 * with l5_core and the CNIC. This is a multi-step process of resolving
1715 * route to target, create a iscsi connection context, handshaking with
1716 * CNIC module to create/initialize the socket struct and finally
1717 * sending down option-2 request to complete TCP 3-way handshake
1718 */
1719static struct iscsi_endpoint *bnx2i_ep_connect(struct Scsi_Host *shost,
1720 struct sockaddr *dst_addr,
1721 int non_blocking)
1722{
1723 u32 iscsi_cid = BNX2I_CID_RESERVED;
1724 struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
1725 struct sockaddr_in6 *desti6;
1726 struct bnx2i_endpoint *bnx2i_ep;
1727 struct bnx2i_hba *hba;
1728 struct cnic_dev *cnic;
1729 struct cnic_sockaddr saddr;
1730 struct iscsi_endpoint *ep;
1731 int rc = 0;
1732
Anil Veerabhadrappafac3cc42009-07-08 18:21:01 -07001733 if (shost) {
Michael Chancf4e6362009-06-08 18:14:44 -07001734 /* driver is given scsi host to work with */
1735 hba = iscsi_host_priv(shost);
Anil Veerabhadrappafac3cc42009-07-08 18:21:01 -07001736 } else
Michael Chancf4e6362009-06-08 18:14:44 -07001737 /*
1738 * check if the given destination can be reached through
1739 * a iscsi capable NetXtreme2 device
1740 */
1741 hba = bnx2i_check_route(dst_addr);
Anil Veerabhadrappafac3cc42009-07-08 18:21:01 -07001742
Eddie Waia91031a2010-11-23 15:29:30 -08001743 if (!hba) {
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -07001744 rc = -EINVAL;
Eddie Wai55e15c92010-07-01 15:34:52 -07001745 goto nohba;
Michael Chancf4e6362009-06-08 18:14:44 -07001746 }
Eddie Wai55e15c92010-07-01 15:34:52 -07001747 mutex_lock(&hba->net_dev_lock);
Eddie Waia91031a2010-11-23 15:29:30 -08001748
1749 if (bnx2i_adapter_ready(hba) || !hba->cid_que.cid_free_cnt) {
1750 rc = -EPERM;
1751 goto check_busy;
1752 }
1753 cnic = hba->cnic;
Michael Chancf4e6362009-06-08 18:14:44 -07001754 ep = bnx2i_alloc_ep(hba);
1755 if (!ep) {
1756 rc = -ENOMEM;
1757 goto check_busy;
1758 }
1759 bnx2i_ep = ep->dd_data;
1760
Michael Chancf4e6362009-06-08 18:14:44 -07001761 bnx2i_ep->num_active_cmds = 0;
1762 iscsi_cid = bnx2i_alloc_iscsi_cid(hba);
1763 if (iscsi_cid == -1) {
Eddie Waia91031a2010-11-23 15:29:30 -08001764 printk(KERN_ALERT "bnx2i (%s): alloc_ep - unable to allocate "
1765 "iscsi cid\n", hba->netdev->name);
Michael Chancf4e6362009-06-08 18:14:44 -07001766 rc = -ENOMEM;
Eddie Waia91031a2010-11-23 15:29:30 -08001767 bnx2i_free_ep(ep);
1768 goto check_busy;
Michael Chancf4e6362009-06-08 18:14:44 -07001769 }
1770 bnx2i_ep->hba_age = hba->age;
1771
1772 rc = bnx2i_alloc_qp_resc(hba, bnx2i_ep);
1773 if (rc != 0) {
Eddie Waia91031a2010-11-23 15:29:30 -08001774 printk(KERN_ALERT "bnx2i (%s): ep_conn - alloc QP resc error"
1775 "\n", hba->netdev->name);
Michael Chancf4e6362009-06-08 18:14:44 -07001776 rc = -ENOMEM;
1777 goto qp_resc_err;
1778 }
1779
1780 bnx2i_ep->ep_iscsi_cid = (u16)iscsi_cid;
1781 bnx2i_ep->state = EP_STATE_OFLD_START;
1782 bnx2i_ep_ofld_list_add(hba, bnx2i_ep);
1783
1784 init_timer(&bnx2i_ep->ofld_timer);
1785 bnx2i_ep->ofld_timer.expires = 2 * HZ + jiffies;
1786 bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
1787 bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
1788 add_timer(&bnx2i_ep->ofld_timer);
1789
Eddie Waibee34872010-11-23 15:29:29 -08001790 if (bnx2i_send_conn_ofld_req(hba, bnx2i_ep)) {
1791 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) {
1792 printk(KERN_ALERT "bnx2i (%s): iscsi cid %d is busy\n",
1793 hba->netdev->name, bnx2i_ep->ep_iscsi_cid);
1794 rc = -EBUSY;
1795 } else
1796 rc = -ENOSPC;
1797 printk(KERN_ALERT "bnx2i (%s): unable to send conn offld kwqe"
1798 "\n", hba->netdev->name);
1799 bnx2i_ep_ofld_list_del(hba, bnx2i_ep);
1800 goto conn_failed;
1801 }
Michael Chancf4e6362009-06-08 18:14:44 -07001802
1803 /* Wait for CNIC hardware to setup conn context and return 'cid' */
1804 wait_event_interruptible(bnx2i_ep->ofld_wait,
1805 bnx2i_ep->state != EP_STATE_OFLD_START);
1806
1807 if (signal_pending(current))
1808 flush_signals(current);
1809 del_timer_sync(&bnx2i_ep->ofld_timer);
1810
1811 bnx2i_ep_ofld_list_del(hba, bnx2i_ep);
1812
1813 if (bnx2i_ep->state != EP_STATE_OFLD_COMPL) {
Eddie Waia91031a2010-11-23 15:29:30 -08001814 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) {
1815 printk(KERN_ALERT "bnx2i (%s): iscsi cid %d is busy\n",
1816 hba->netdev->name, bnx2i_ep->ep_iscsi_cid);
1817 rc = -EBUSY;
1818 } else
1819 rc = -ENOSPC;
Michael Chancf4e6362009-06-08 18:14:44 -07001820 goto conn_failed;
1821 }
1822
1823 rc = cnic->cm_create(cnic, CNIC_ULP_ISCSI, bnx2i_ep->ep_cid,
1824 iscsi_cid, &bnx2i_ep->cm_sk, bnx2i_ep);
1825 if (rc) {
1826 rc = -EINVAL;
Eddie Waia91031a2010-11-23 15:29:30 -08001827 /* Need to terminate and cleanup the connection */
1828 goto release_ep;
Michael Chancf4e6362009-06-08 18:14:44 -07001829 }
1830
1831 bnx2i_ep->cm_sk->rcv_buf = 256 * 1024;
1832 bnx2i_ep->cm_sk->snd_buf = 256 * 1024;
1833 clear_bit(SK_TCP_TIMESTAMP, &bnx2i_ep->cm_sk->tcp_flags);
1834
1835 memset(&saddr, 0, sizeof(saddr));
1836 if (dst_addr->sa_family == AF_INET) {
1837 desti = (struct sockaddr_in *) dst_addr;
1838 saddr.remote.v4 = *desti;
1839 saddr.local.v4.sin_family = desti->sin_family;
1840 } else if (dst_addr->sa_family == AF_INET6) {
1841 desti6 = (struct sockaddr_in6 *) dst_addr;
1842 saddr.remote.v6 = *desti6;
1843 saddr.local.v6.sin6_family = desti6->sin6_family;
1844 }
1845
1846 bnx2i_ep->timestamp = jiffies;
1847 bnx2i_ep->state = EP_STATE_CONNECT_START;
1848 if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
1849 rc = -EINVAL;
1850 goto conn_failed;
1851 } else
1852 rc = cnic->cm_connect(bnx2i_ep->cm_sk, &saddr);
Michael Chancf4e6362009-06-08 18:14:44 -07001853 if (rc)
1854 goto release_ep;
1855
Eddie Wai46012e82010-07-01 15:34:51 -07001856 bnx2i_ep_active_list_add(hba, bnx2i_ep);
1857
Michael Chancf4e6362009-06-08 18:14:44 -07001858 if (bnx2i_map_ep_dbell_regs(bnx2i_ep))
Eddie Wai46012e82010-07-01 15:34:51 -07001859 goto del_active_ep;
1860
Michael Chancf4e6362009-06-08 18:14:44 -07001861 mutex_unlock(&hba->net_dev_lock);
1862 return ep;
1863
Eddie Wai46012e82010-07-01 15:34:51 -07001864del_active_ep:
1865 bnx2i_ep_active_list_del(hba, bnx2i_ep);
Michael Chancf4e6362009-06-08 18:14:44 -07001866release_ep:
1867 if (bnx2i_tear_down_conn(hba, bnx2i_ep)) {
1868 mutex_unlock(&hba->net_dev_lock);
1869 return ERR_PTR(rc);
1870 }
1871conn_failed:
Michael Chancf4e6362009-06-08 18:14:44 -07001872 bnx2i_free_qp_resc(hba, bnx2i_ep);
1873qp_resc_err:
1874 bnx2i_free_ep(ep);
Michael Chancf4e6362009-06-08 18:14:44 -07001875check_busy:
Eddie Wai55e15c92010-07-01 15:34:52 -07001876 mutex_unlock(&hba->net_dev_lock);
1877nohba:
Michael Chancf4e6362009-06-08 18:14:44 -07001878 return ERR_PTR(rc);
1879}
1880
1881
1882/**
1883 * bnx2i_ep_poll - polls for TCP connection establishement
1884 * @ep: TCP connection (endpoint) handle
1885 * @timeout_ms: timeout value in milli secs
1886 *
1887 * polls for TCP connect request to complete
1888 */
1889static int bnx2i_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1890{
1891 struct bnx2i_endpoint *bnx2i_ep;
1892 int rc = 0;
1893
1894 bnx2i_ep = ep->dd_data;
1895 if ((bnx2i_ep->state == EP_STATE_IDLE) ||
1896 (bnx2i_ep->state == EP_STATE_CONNECT_FAILED) ||
1897 (bnx2i_ep->state == EP_STATE_OFLD_FAILED))
1898 return -1;
1899 if (bnx2i_ep->state == EP_STATE_CONNECT_COMPL)
1900 return 1;
1901
1902 rc = wait_event_interruptible_timeout(bnx2i_ep->ofld_wait,
1903 ((bnx2i_ep->state ==
1904 EP_STATE_OFLD_FAILED) ||
1905 (bnx2i_ep->state ==
1906 EP_STATE_CONNECT_FAILED) ||
1907 (bnx2i_ep->state ==
1908 EP_STATE_CONNECT_COMPL)),
1909 msecs_to_jiffies(timeout_ms));
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -07001910 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED)
Michael Chancf4e6362009-06-08 18:14:44 -07001911 rc = -1;
1912
1913 if (rc > 0)
1914 return 1;
1915 else if (!rc)
1916 return 0; /* timeout */
1917 else
1918 return rc;
1919}
1920
1921
1922/**
1923 * bnx2i_ep_tcp_conn_active - check EP state transition
1924 * @ep: endpoint pointer
1925 *
1926 * check if underlying TCP connection is active
1927 */
1928static int bnx2i_ep_tcp_conn_active(struct bnx2i_endpoint *bnx2i_ep)
1929{
1930 int ret;
1931 int cnic_dev_10g = 0;
1932
1933 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
1934 cnic_dev_10g = 1;
1935
1936 switch (bnx2i_ep->state) {
Eddie Wai94810e82010-11-23 15:29:24 -08001937 case EP_STATE_CONNECT_FAILED:
Michael Chancf4e6362009-06-08 18:14:44 -07001938 case EP_STATE_CLEANUP_FAILED:
1939 case EP_STATE_OFLD_FAILED:
1940 case EP_STATE_DISCONN_TIMEDOUT:
1941 ret = 0;
1942 break;
Eddie Wai252e44802010-11-23 15:29:25 -08001943 case EP_STATE_CONNECT_START:
Michael Chancf4e6362009-06-08 18:14:44 -07001944 case EP_STATE_CONNECT_COMPL:
1945 case EP_STATE_ULP_UPDATE_START:
1946 case EP_STATE_ULP_UPDATE_COMPL:
1947 case EP_STATE_TCP_FIN_RCVD:
Eddie Wai2eefb202010-07-01 15:34:54 -07001948 case EP_STATE_LOGOUT_SENT:
1949 case EP_STATE_LOGOUT_RESP_RCVD:
Michael Chancf4e6362009-06-08 18:14:44 -07001950 case EP_STATE_ULP_UPDATE_FAILED:
1951 ret = 1;
1952 break;
1953 case EP_STATE_TCP_RST_RCVD:
Michael Chancf4e6362009-06-08 18:14:44 -07001954 if (cnic_dev_10g)
Michael Chancf4e6362009-06-08 18:14:44 -07001955 ret = 0;
Eddie Wai94810e82010-11-23 15:29:24 -08001956 else
1957 ret = 1;
Michael Chancf4e6362009-06-08 18:14:44 -07001958 break;
1959 default:
1960 ret = 0;
1961 }
1962
1963 return ret;
1964}
1965
1966
Eddie Wai6447f282010-07-01 15:34:50 -07001967/*
1968 * bnx2i_hw_ep_disconnect - executes TCP connection teardown process in the hw
1969 * @ep: TCP connection (bnx2i endpoint) handle
1970 *
1971 * executes TCP connection teardown process
1972 */
1973int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep)
1974{
1975 struct bnx2i_hba *hba = bnx2i_ep->hba;
1976 struct cnic_dev *cnic;
1977 struct iscsi_session *session = NULL;
1978 struct iscsi_conn *conn = NULL;
1979 int ret = 0;
Eddie Wai2eefb202010-07-01 15:34:54 -07001980 int close = 0;
1981 int close_ret = 0;
Eddie Wai6447f282010-07-01 15:34:50 -07001982
1983 if (!hba)
1984 return 0;
1985
1986 cnic = hba->cnic;
1987 if (!cnic)
1988 return 0;
1989
Eddie Waia91031a2010-11-23 15:29:30 -08001990 if (bnx2i_ep->state == EP_STATE_IDLE ||
1991 bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT)
Eddie Wai250ae982010-08-12 16:44:30 -07001992 return 0;
1993
Eddie Wai6447f282010-07-01 15:34:50 -07001994 if (!bnx2i_ep_tcp_conn_active(bnx2i_ep))
1995 goto destroy_conn;
1996
1997 if (bnx2i_ep->conn) {
1998 conn = bnx2i_ep->conn->cls_conn->dd_data;
1999 session = conn->session;
2000 }
2001
Eddie Wai6447f282010-07-01 15:34:50 -07002002 init_timer(&bnx2i_ep->ofld_timer);
Eddie Waie37d2c42010-07-01 15:34:53 -07002003 bnx2i_ep->ofld_timer.expires = hba->conn_teardown_tmo + jiffies;
Eddie Wai6447f282010-07-01 15:34:50 -07002004 bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
2005 bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
2006 add_timer(&bnx2i_ep->ofld_timer);
2007
Eddie Wai2eefb202010-07-01 15:34:54 -07002008 if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic))
Eddie Wai6447f282010-07-01 15:34:50 -07002009 goto out;
2010
Eddie Wai2eefb202010-07-01 15:34:54 -07002011 if (session) {
2012 spin_lock_bh(&session->lock);
2013 if (bnx2i_ep->state != EP_STATE_TCP_FIN_RCVD) {
2014 if (session->state == ISCSI_STATE_LOGGING_OUT) {
2015 if (bnx2i_ep->state == EP_STATE_LOGOUT_SENT) {
2016 /* Logout sent, but no resp */
Eddie Waia91031a2010-11-23 15:29:30 -08002017 printk(KERN_ALERT "bnx2i (%s): WARNING"
2018 " logout response was not "
2019 "received!\n",
2020 bnx2i_ep->hba->netdev->name);
Eddie Wai2eefb202010-07-01 15:34:54 -07002021 } else if (bnx2i_ep->state ==
2022 EP_STATE_LOGOUT_RESP_RCVD)
2023 close = 1;
2024 }
2025 } else
2026 close = 1;
2027
2028 spin_unlock_bh(&session->lock);
2029 }
2030
2031 bnx2i_ep->state = EP_STATE_DISCONN_START;
2032
2033 if (close)
2034 close_ret = cnic->cm_close(bnx2i_ep->cm_sk);
2035 else
2036 close_ret = cnic->cm_abort(bnx2i_ep->cm_sk);
2037
2038 if (close_ret)
Eddie Waia91031a2010-11-23 15:29:30 -08002039 printk(KERN_ALERT "bnx2i (%s): close/abort(%d) returned %d\n",
Eddie Wai2c2255e2010-08-12 16:44:29 -07002040 bnx2i_ep->hba->netdev->name, close, close_ret);
2041 else
2042 /* wait for option-2 conn teardown */
2043 wait_event_interruptible(bnx2i_ep->ofld_wait,
Eddie Wai6447f282010-07-01 15:34:50 -07002044 bnx2i_ep->state != EP_STATE_DISCONN_START);
2045
2046 if (signal_pending(current))
2047 flush_signals(current);
2048 del_timer_sync(&bnx2i_ep->ofld_timer);
2049
2050destroy_conn:
Eddie Wai46012e82010-07-01 15:34:51 -07002051 bnx2i_ep_active_list_del(hba, bnx2i_ep);
Eddie Wai6447f282010-07-01 15:34:50 -07002052 if (bnx2i_tear_down_conn(hba, bnx2i_ep))
Eddie Waia91031a2010-11-23 15:29:30 -08002053 return -EINVAL;
Eddie Wai6447f282010-07-01 15:34:50 -07002054out:
2055 bnx2i_ep->state = EP_STATE_IDLE;
2056 return ret;
2057}
2058
2059
Michael Chancf4e6362009-06-08 18:14:44 -07002060/**
2061 * bnx2i_ep_disconnect - executes TCP connection teardown process
Eddie Wai6447f282010-07-01 15:34:50 -07002062 * @ep: TCP connection (iscsi endpoint) handle
Michael Chancf4e6362009-06-08 18:14:44 -07002063 *
2064 * executes TCP connection teardown process
2065 */
2066static void bnx2i_ep_disconnect(struct iscsi_endpoint *ep)
2067{
2068 struct bnx2i_endpoint *bnx2i_ep;
2069 struct bnx2i_conn *bnx2i_conn = NULL;
Eddie Wai6447f282010-07-01 15:34:50 -07002070 struct iscsi_conn *conn = NULL;
Michael Chancf4e6362009-06-08 18:14:44 -07002071 struct bnx2i_hba *hba;
2072
2073 bnx2i_ep = ep->dd_data;
2074
Thadeu Lima de Souza Cascardo94e2bd62009-10-16 15:20:49 +02002075 /* driver should not attempt connection cleanup until TCP_CONNECT
Michael Chancf4e6362009-06-08 18:14:44 -07002076 * completes either successfully or fails. Timeout is 9-secs, so
2077 * wait for it to complete
2078 */
2079 while ((bnx2i_ep->state == EP_STATE_CONNECT_START) &&
2080 !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ)))
2081 msleep(250);
2082
2083 if (bnx2i_ep->conn) {
2084 bnx2i_conn = bnx2i_ep->conn;
2085 conn = bnx2i_conn->cls_conn->dd_data;
Mike Christie24246de2009-11-11 16:34:30 -06002086 iscsi_suspend_queue(conn);
Michael Chancf4e6362009-06-08 18:14:44 -07002087 }
Michael Chancf4e6362009-06-08 18:14:44 -07002088 hba = bnx2i_ep->hba;
Michael Chancf4e6362009-06-08 18:14:44 -07002089
2090 mutex_lock(&hba->net_dev_lock);
2091
Eddie Waia91031a2010-11-23 15:29:30 -08002092 if (bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT)
2093 goto out;
2094
Eddie Wai6447f282010-07-01 15:34:50 -07002095 if (bnx2i_ep->state == EP_STATE_IDLE)
Michael Chancf4e6362009-06-08 18:14:44 -07002096 goto free_resc;
Eddie Wai6447f282010-07-01 15:34:50 -07002097
Eddie Waia91031a2010-11-23 15:29:30 -08002098 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) ||
2099 (bnx2i_ep->hba_age != hba->age)) {
2100 bnx2i_ep_active_list_del(hba, bnx2i_ep);
Michael Chancf4e6362009-06-08 18:14:44 -07002101 goto free_resc;
Eddie Waia91031a2010-11-23 15:29:30 -08002102 }
Michael Chancf4e6362009-06-08 18:14:44 -07002103
Eddie Wai6447f282010-07-01 15:34:50 -07002104 /* Do all chip cleanup here */
2105 if (bnx2i_hw_ep_disconnect(bnx2i_ep)) {
Michael Chancf4e6362009-06-08 18:14:44 -07002106 mutex_unlock(&hba->net_dev_lock);
2107 return;
2108 }
2109free_resc:
Michael Chancf4e6362009-06-08 18:14:44 -07002110 bnx2i_free_qp_resc(hba, bnx2i_ep);
Eddie Waia91031a2010-11-23 15:29:30 -08002111
Michael Chancf4e6362009-06-08 18:14:44 -07002112 if (bnx2i_conn)
2113 bnx2i_conn->ep = NULL;
2114
2115 bnx2i_free_ep(ep);
Eddie Waia91031a2010-11-23 15:29:30 -08002116out:
Eddie Wai6447f282010-07-01 15:34:50 -07002117 mutex_unlock(&hba->net_dev_lock);
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -07002118
2119 wake_up_interruptible(&hba->eh_wait);
Michael Chancf4e6362009-06-08 18:14:44 -07002120}
2121
2122
2123/**
2124 * bnx2i_nl_set_path - ISCSI_UEVENT_PATH_UPDATE user message handler
2125 * @buf: pointer to buffer containing iscsi path message
2126 *
2127 */
2128static int bnx2i_nl_set_path(struct Scsi_Host *shost, struct iscsi_path *params)
2129{
2130 struct bnx2i_hba *hba = iscsi_host_priv(shost);
2131 char *buf = (char *) params;
2132 u16 len = sizeof(*params);
2133
2134 /* handled by cnic driver */
2135 hba->cnic->iscsi_nl_msg_recv(hba->cnic, ISCSI_UEVENT_PATH_UPDATE, buf,
2136 len);
2137
2138 return 0;
2139}
2140
2141
2142/*
2143 * 'Scsi_Host_Template' structure and 'iscsi_tranport' structure template
2144 * used while registering with the scsi host and iSCSI transport module.
2145 */
2146static struct scsi_host_template bnx2i_host_template = {
2147 .module = THIS_MODULE,
2148 .name = "Broadcom Offload iSCSI Initiator",
2149 .proc_name = "bnx2i",
2150 .queuecommand = iscsi_queuecommand,
2151 .eh_abort_handler = iscsi_eh_abort,
2152 .eh_device_reset_handler = iscsi_eh_device_reset,
Jayamohan Kallickal309ce152010-02-20 08:02:10 +05302153 .eh_target_reset_handler = iscsi_eh_recover_target,
Mike Christie9f9127f2010-02-10 16:51:46 -06002154 .change_queue_depth = iscsi_change_queue_depth,
Michael Chancf4e6362009-06-08 18:14:44 -07002155 .can_queue = 1024,
2156 .max_sectors = 127,
2157 .cmd_per_lun = 32,
2158 .this_id = -1,
2159 .use_clustering = ENABLE_CLUSTERING,
2160 .sg_tablesize = ISCSI_MAX_BDS_PER_CMD,
2161 .shost_attrs = bnx2i_dev_attributes,
2162};
2163
2164struct iscsi_transport bnx2i_iscsi_transport = {
2165 .owner = THIS_MODULE,
2166 .name = "bnx2i",
2167 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST |
2168 CAP_MULTI_R2T | CAP_DATADGST |
2169 CAP_DATA_PATH_OFFLOAD,
2170 .param_mask = ISCSI_MAX_RECV_DLENGTH |
2171 ISCSI_MAX_XMIT_DLENGTH |
2172 ISCSI_HDRDGST_EN |
2173 ISCSI_DATADGST_EN |
2174 ISCSI_INITIAL_R2T_EN |
2175 ISCSI_MAX_R2T |
2176 ISCSI_IMM_DATA_EN |
2177 ISCSI_FIRST_BURST |
2178 ISCSI_MAX_BURST |
2179 ISCSI_PDU_INORDER_EN |
2180 ISCSI_DATASEQ_INORDER_EN |
2181 ISCSI_ERL |
2182 ISCSI_CONN_PORT |
2183 ISCSI_CONN_ADDRESS |
2184 ISCSI_EXP_STATSN |
2185 ISCSI_PERSISTENT_PORT |
2186 ISCSI_PERSISTENT_ADDRESS |
2187 ISCSI_TARGET_NAME | ISCSI_TPGT |
2188 ISCSI_USERNAME | ISCSI_PASSWORD |
2189 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
2190 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
Mike Christie3fe5ae82009-11-11 16:34:33 -06002191 ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
Michael Chancf4e6362009-06-08 18:14:44 -07002192 ISCSI_PING_TMO | ISCSI_RECV_TMO |
2193 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
Michael Chan625986c2010-07-01 15:34:55 -07002194 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
2195 ISCSI_HOST_NETDEV_NAME,
Michael Chancf4e6362009-06-08 18:14:44 -07002196 .create_session = bnx2i_session_create,
2197 .destroy_session = bnx2i_session_destroy,
2198 .create_conn = bnx2i_conn_create,
2199 .bind_conn = bnx2i_conn_bind,
2200 .destroy_conn = bnx2i_conn_destroy,
2201 .set_param = iscsi_set_param,
2202 .get_conn_param = bnx2i_conn_get_param,
2203 .get_session_param = iscsi_session_get_param,
2204 .get_host_param = bnx2i_host_get_param,
2205 .start_conn = bnx2i_conn_start,
2206 .stop_conn = iscsi_conn_stop,
2207 .send_pdu = iscsi_conn_send_pdu,
2208 .xmit_task = bnx2i_task_xmit,
2209 .get_stats = bnx2i_conn_get_stats,
2210 /* TCP connect - disconnect - option-2 interface calls */
2211 .ep_connect = bnx2i_ep_connect,
2212 .ep_poll = bnx2i_ep_poll,
2213 .ep_disconnect = bnx2i_ep_disconnect,
2214 .set_path = bnx2i_nl_set_path,
2215 /* Error recovery timeout call */
2216 .session_recovery_timedout = iscsi_session_recovery_timedout,
2217 .cleanup_task = bnx2i_cleanup_task,
2218};