2 * bnx2i_iscsi.c: Broadcom NetXtreme II iSCSI driver.
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
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.
12 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
15 #include <linux/slab.h>
16 #include <scsi/scsi_tcq.h>
17 #include <scsi/libiscsi.h>
20 struct scsi_transport_template
*bnx2i_scsi_xport_template
;
21 struct iscsi_transport bnx2i_iscsi_transport
;
22 static struct scsi_host_template bnx2i_host_template
;
25 * Global endpoint resource info
27 static DEFINE_SPINLOCK(bnx2i_resc_lock
); /* protects global resources */
30 static int bnx2i_adapter_ready(struct bnx2i_hba
*hba
)
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
))
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
49 * identifies & marks various bd info for scsi command's imm data,
50 * unsolicited data and the first solicited data seq.
52 static void bnx2i_get_write_cmd_bd_idx(struct bnx2i_cmd
*cmd
, u32 buf_off
,
53 u32
*start_bd_off
, u32
*start_bd_idx
)
55 struct iscsi_bd
*bd_tbl
= cmd
->io_tbl
.bd_tbl
;
60 while (buf_off
>= (cur_offset
+ bd_tbl
->buffer_length
)) {
61 cur_offset
+= bd_tbl
->buffer_length
;
67 *start_bd_off
= buf_off
- cur_offset
;
68 *start_bd_idx
= cur_bd_idx
;
72 * bnx2i_setup_write_cmd_bd_info - sets up BD various information
73 * @task: transport layer's cmd struct pointer
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.
80 static void bnx2i_setup_write_cmd_bd_info(struct iscsi_task
*task
)
82 struct bnx2i_cmd
*cmd
= task
->dd_data
;
85 u32 buffer_offset
= 0;
86 u32 cmd_len
= cmd
->req
.total_data_transfer_length
;
88 /* if ImmediateData is turned off & IntialR2T is turned on,
89 * there will be no immediate or unsolicited data, just return.
91 if (!iscsi_task_has_unsol_data(task
) && !task
->imm_count
)
95 buffer_offset
+= task
->imm_count
;
96 if (task
->imm_count
== cmd_len
)
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
;
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
))) {
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
].\
125 cmd
->req
.sd_buffer_offset
= start_bd_offset
;
126 cmd
->req
.sd_start_bd_index
= start_bd_idx
;
133 * bnx2i_map_scsi_sg - maps IO buffer and prepares the BD table
134 * @hba: adapter instance
135 * @cmd: iscsi cmd struct pointer
139 static int bnx2i_map_scsi_sg(struct bnx2i_hba
*hba
, struct bnx2i_cmd
*cmd
)
141 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
142 struct iscsi_bd
*bd
= cmd
->io_tbl
.bd_tbl
;
143 struct scatterlist
*sg
;
151 BUG_ON(scsi_sg_count(sc
) > ISCSI_MAX_BDS_PER_CMD
);
153 sg_count
= scsi_dma_map(sc
);
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;
163 bd
[bd_count
].flags
= ISCSI_BD_FIRST_IN_BD_CHAIN
;
165 byte_count
+= sg_len
;
170 bd
[bd_count
- 1].flags
|= ISCSI_BD_LAST_IN_BD_CHAIN
;
172 BUG_ON(byte_count
!= scsi_bufflen(sc
));
177 * bnx2i_iscsi_map_sg_list - maps SG list
178 * @cmd: iscsi cmd struct pointer
180 * creates BD list table for the command
182 static void bnx2i_iscsi_map_sg_list(struct bnx2i_cmd
*cmd
)
186 bd_count
= bnx2i_map_scsi_sg(cmd
->conn
->hba
, cmd
);
188 struct iscsi_bd
*bd
= cmd
->io_tbl
.bd_tbl
;
190 bd
[0].buffer_addr_lo
= bd
[0].buffer_addr_hi
= 0;
191 bd
[0].buffer_length
= bd
[0].flags
= 0;
193 cmd
->io_tbl
.bd_valid
= bd_count
;
198 * bnx2i_iscsi_unmap_sg_list - unmaps SG list
199 * @cmd: iscsi cmd struct pointer
201 * unmap IO buffers and invalidate the BD table
203 void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd
*cmd
)
205 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
207 if (cmd
->io_tbl
.bd_valid
&& sc
) {
209 cmd
->io_tbl
.bd_valid
= 0;
213 static void bnx2i_setup_cmd_wqe_template(struct bnx2i_cmd
*cmd
)
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);
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)
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
234 static int bnx2i_bind_conn_to_iscsi_cid(struct bnx2i_hba
*hba
,
235 struct bnx2i_conn
*bnx2i_conn
,
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
);
244 hba
->cid_que
.conn_cid_tbl
[iscsi_cid
] = bnx2i_conn
;
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)
254 struct bnx2i_conn
*bnx2i_get_conn_from_id(struct bnx2i_hba
*hba
,
257 if (!hba
->cid_que
.conn_cid_tbl
) {
258 printk(KERN_ERR
"bnx2i: ERROR - missing conn<->cid table\n");
261 } else if (iscsi_cid
>= hba
->max_active_conns
) {
262 printk(KERN_ERR
"bnx2i: wrong cid #%d\n", iscsi_cid
);
265 return hba
->cid_que
.conn_cid_tbl
[iscsi_cid
];
270 * bnx2i_alloc_iscsi_cid - allocates a iscsi_cid from free pool
271 * @hba: pointer to adapter instance
273 static u32
bnx2i_alloc_iscsi_cid(struct bnx2i_hba
*hba
)
277 if (!hba
->cid_que
.cid_free_cnt
)
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;
285 hba
->cid_que
.cid_free_cnt
--;
286 return hba
->cid_que
.cid_que
[idx
];
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
295 static void bnx2i_free_iscsi_cid(struct bnx2i_hba
*hba
, u16 iscsi_cid
)
299 if (iscsi_cid
== (u16
) -1)
302 hba
->cid_que
.cid_free_cnt
++;
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;
314 * bnx2i_setup_free_cid_que - sets up free iscsi cid queue
315 * @hba: pointer to adapter instance
317 * allocates memory for iscsi cid queue & 'cid - conn ptr' mapping table,
318 * and initialize table attributes
320 static int bnx2i_setup_free_cid_que(struct bnx2i_hba
*hba
)
325 mem_size
= hba
->max_active_conns
* sizeof(u32
);
326 mem_size
= (mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
328 hba
->cid_que
.cid_que_base
= kmalloc(mem_size
, GFP_KERNEL
);
329 if (!hba
->cid_que
.cid_que_base
)
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
;
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
;
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
;
356 * bnx2i_release_free_cid_que - releases 'iscsi_cid' queue resources
357 * @hba: pointer to adapter instance
359 static void bnx2i_release_free_cid_que(struct bnx2i_hba
*hba
)
361 kfree(hba
->cid_que
.cid_que_base
);
362 hba
->cid_que
.cid_que_base
= NULL
;
364 kfree(hba
->cid_que
.conn_cid_tbl
);
365 hba
->cid_que
.conn_cid_tbl
= NULL
;
370 * bnx2i_alloc_ep - allocates ep structure from global pool
371 * @hba: pointer to adapter instance
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
377 static struct iscsi_endpoint
*bnx2i_alloc_ep(struct bnx2i_hba
*hba
)
379 struct iscsi_endpoint
*ep
;
380 struct bnx2i_endpoint
*bnx2i_ep
;
382 ep
= iscsi_create_endpoint(sizeof(*bnx2i_ep
));
384 printk(KERN_ERR
"bnx2i: Could not allocate ep\n");
388 bnx2i_ep
= ep
->dd_data
;
389 INIT_LIST_HEAD(&bnx2i_ep
->link
);
390 bnx2i_ep
->state
= EP_STATE_IDLE
;
391 bnx2i_ep
->ep_iscsi_cid
= (u16
) -1;
393 bnx2i_ep
->hba_age
= hba
->age
;
394 hba
->ofld_conns_active
++;
395 init_waitqueue_head(&bnx2i_ep
->ofld_wait
);
401 * bnx2i_free_ep - free endpoint
402 * @ep: pointer to iscsi endpoint structure
404 static void bnx2i_free_ep(struct iscsi_endpoint
*ep
)
406 struct bnx2i_endpoint
*bnx2i_ep
= ep
->dd_data
;
409 spin_lock_irqsave(&bnx2i_resc_lock
, flags
);
410 bnx2i_ep
->state
= EP_STATE_IDLE
;
411 bnx2i_ep
->hba
->ofld_conns_active
--;
413 bnx2i_free_iscsi_cid(bnx2i_ep
->hba
, bnx2i_ep
->ep_iscsi_cid
);
414 if (bnx2i_ep
->conn
) {
415 bnx2i_ep
->conn
->ep
= NULL
;
416 bnx2i_ep
->conn
= NULL
;
419 bnx2i_ep
->hba
= NULL
;
420 spin_unlock_irqrestore(&bnx2i_resc_lock
, flags
);
421 iscsi_destroy_endpoint(ep
);
426 * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command
427 * @hba: adapter instance pointer
428 * @session: iscsi session pointer
429 * @cmd: iscsi command structure
431 static int bnx2i_alloc_bdt(struct bnx2i_hba
*hba
, struct iscsi_session
*session
,
432 struct bnx2i_cmd
*cmd
)
434 struct io_bdt
*io
= &cmd
->io_tbl
;
437 io
->bd_tbl
= dma_alloc_coherent(&hba
->pcidev
->dev
,
438 ISCSI_MAX_BDS_PER_CMD
* sizeof(*bd
),
439 &io
->bd_tbl_dma
, GFP_KERNEL
);
441 iscsi_session_printk(KERN_ERR
, session
, "Could not "
450 * bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table
451 * @hba: adapter instance pointer
452 * @session: iscsi session pointer
453 * @cmd: iscsi command structure
455 static void bnx2i_destroy_cmd_pool(struct bnx2i_hba
*hba
,
456 struct iscsi_session
*session
)
460 for (i
= 0; i
< session
->cmds_max
; i
++) {
461 struct iscsi_task
*task
= session
->cmds
[i
];
462 struct bnx2i_cmd
*cmd
= task
->dd_data
;
464 if (cmd
->io_tbl
.bd_tbl
)
465 dma_free_coherent(&hba
->pcidev
->dev
,
466 ISCSI_MAX_BDS_PER_CMD
*
467 sizeof(struct iscsi_bd
),
469 cmd
->io_tbl
.bd_tbl_dma
);
476 * bnx2i_setup_cmd_pool - sets up iscsi command pool for the session
477 * @hba: adapter instance pointer
478 * @session: iscsi session pointer
480 static int bnx2i_setup_cmd_pool(struct bnx2i_hba
*hba
,
481 struct iscsi_session
*session
)
485 for (i
= 0; i
< session
->cmds_max
; i
++) {
486 struct iscsi_task
*task
= session
->cmds
[i
];
487 struct bnx2i_cmd
*cmd
= task
->dd_data
;
489 task
->hdr
= &cmd
->hdr
;
490 task
->hdr_max
= sizeof(struct iscsi_hdr
);
492 if (bnx2i_alloc_bdt(hba
, session
, cmd
))
499 bnx2i_destroy_cmd_pool(hba
, session
);
505 * bnx2i_setup_mp_bdt - allocate BD table resources
506 * @hba: pointer to adapter structure
508 * Allocate memory for dummy buffer and associated BD
509 * table to be used by middle path (MP) requests
511 static int bnx2i_setup_mp_bdt(struct bnx2i_hba
*hba
)
514 struct iscsi_bd
*mp_bdt
;
517 hba
->mp_bd_tbl
= dma_alloc_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
518 &hba
->mp_bd_dma
, GFP_KERNEL
);
519 if (!hba
->mp_bd_tbl
) {
520 printk(KERN_ERR
"unable to allocate Middle Path BDT\n");
525 hba
->dummy_buffer
= dma_alloc_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
526 &hba
->dummy_buf_dma
, GFP_KERNEL
);
527 if (!hba
->dummy_buffer
) {
528 printk(KERN_ERR
"unable to alloc Middle Path Dummy Buffer\n");
529 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
530 hba
->mp_bd_tbl
, hba
->mp_bd_dma
);
531 hba
->mp_bd_tbl
= NULL
;
536 mp_bdt
= (struct iscsi_bd
*) hba
->mp_bd_tbl
;
537 addr
= (unsigned long) hba
->dummy_buf_dma
;
538 mp_bdt
->buffer_addr_lo
= addr
& 0xffffffff;
539 mp_bdt
->buffer_addr_hi
= addr
>> 32;
540 mp_bdt
->buffer_length
= PAGE_SIZE
;
541 mp_bdt
->flags
= ISCSI_BD_LAST_IN_BD_CHAIN
|
542 ISCSI_BD_FIRST_IN_BD_CHAIN
;
549 * bnx2i_free_mp_bdt - releases ITT back to free pool
550 * @hba: pointer to adapter instance
552 * free MP dummy buffer and associated BD table
554 static void bnx2i_free_mp_bdt(struct bnx2i_hba
*hba
)
556 if (hba
->mp_bd_tbl
) {
557 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
558 hba
->mp_bd_tbl
, hba
->mp_bd_dma
);
559 hba
->mp_bd_tbl
= NULL
;
561 if (hba
->dummy_buffer
) {
562 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
563 hba
->dummy_buffer
, hba
->dummy_buf_dma
);
564 hba
->dummy_buffer
= NULL
;
570 * bnx2i_drop_session - notifies iscsid of connection error.
571 * @hba: adapter instance pointer
572 * @session: iscsi session pointer
574 * This notifies iscsid that there is a error, so it can initiate
577 * This relies on caller using the iscsi class iterator so the object
578 * is refcounted and does not disapper from under us.
580 void bnx2i_drop_session(struct iscsi_cls_session
*cls_session
)
582 iscsi_session_failure(cls_session
->dd_data
, ISCSI_ERR_CONN_FAILED
);
586 * bnx2i_ep_destroy_list_add - add an entry to EP destroy list
587 * @hba: pointer to adapter instance
588 * @ep: pointer to endpoint (transport indentifier) structure
590 * EP destroy queue manager
592 static int bnx2i_ep_destroy_list_add(struct bnx2i_hba
*hba
,
593 struct bnx2i_endpoint
*ep
)
595 write_lock_bh(&hba
->ep_rdwr_lock
);
596 list_add_tail(&ep
->link
, &hba
->ep_destroy_list
);
597 write_unlock_bh(&hba
->ep_rdwr_lock
);
602 * bnx2i_ep_destroy_list_del - add an entry to EP destroy list
604 * @hba: pointer to adapter instance
605 * @ep: pointer to endpoint (transport indentifier) structure
607 * EP destroy queue manager
609 static int bnx2i_ep_destroy_list_del(struct bnx2i_hba
*hba
,
610 struct bnx2i_endpoint
*ep
)
612 write_lock_bh(&hba
->ep_rdwr_lock
);
613 list_del_init(&ep
->link
);
614 write_unlock_bh(&hba
->ep_rdwr_lock
);
620 * bnx2i_ep_ofld_list_add - add an entry to ep offload pending list
621 * @hba: pointer to adapter instance
622 * @ep: pointer to endpoint (transport indentifier) structure
624 * pending conn offload completion queue manager
626 static int bnx2i_ep_ofld_list_add(struct bnx2i_hba
*hba
,
627 struct bnx2i_endpoint
*ep
)
629 write_lock_bh(&hba
->ep_rdwr_lock
);
630 list_add_tail(&ep
->link
, &hba
->ep_ofld_list
);
631 write_unlock_bh(&hba
->ep_rdwr_lock
);
636 * bnx2i_ep_ofld_list_del - add an entry to ep offload pending list
637 * @hba: pointer to adapter instance
638 * @ep: pointer to endpoint (transport indentifier) structure
640 * pending conn offload completion queue manager
642 static int bnx2i_ep_ofld_list_del(struct bnx2i_hba
*hba
,
643 struct bnx2i_endpoint
*ep
)
645 write_lock_bh(&hba
->ep_rdwr_lock
);
646 list_del_init(&ep
->link
);
647 write_unlock_bh(&hba
->ep_rdwr_lock
);
653 * bnx2i_find_ep_in_ofld_list - find iscsi_cid in pending list of endpoints
655 * @hba: pointer to adapter instance
656 * @iscsi_cid: iscsi context ID to find
659 struct bnx2i_endpoint
*
660 bnx2i_find_ep_in_ofld_list(struct bnx2i_hba
*hba
, u32 iscsi_cid
)
662 struct list_head
*list
;
663 struct list_head
*tmp
;
664 struct bnx2i_endpoint
*ep
;
666 read_lock_bh(&hba
->ep_rdwr_lock
);
667 list_for_each_safe(list
, tmp
, &hba
->ep_ofld_list
) {
668 ep
= (struct bnx2i_endpoint
*)list
;
670 if (ep
->ep_iscsi_cid
== iscsi_cid
)
674 read_unlock_bh(&hba
->ep_rdwr_lock
);
677 printk(KERN_ERR
"l5 cid %d not found\n", iscsi_cid
);
683 * bnx2i_find_ep_in_destroy_list - find iscsi_cid in destroy list
684 * @hba: pointer to adapter instance
685 * @iscsi_cid: iscsi context ID to find
688 struct bnx2i_endpoint
*
689 bnx2i_find_ep_in_destroy_list(struct bnx2i_hba
*hba
, u32 iscsi_cid
)
691 struct list_head
*list
;
692 struct list_head
*tmp
;
693 struct bnx2i_endpoint
*ep
;
695 read_lock_bh(&hba
->ep_rdwr_lock
);
696 list_for_each_safe(list
, tmp
, &hba
->ep_destroy_list
) {
697 ep
= (struct bnx2i_endpoint
*)list
;
699 if (ep
->ep_iscsi_cid
== iscsi_cid
)
703 read_unlock_bh(&hba
->ep_rdwr_lock
);
706 printk(KERN_ERR
"l5 cid %d not found\n", iscsi_cid
);
712 * bnx2i_setup_host_queue_size - assigns shost->can_queue param
713 * @hba: pointer to adapter instance
714 * @shost: scsi host pointer
716 * Initializes 'can_queue' parameter based on how many outstanding commands
717 * the device can handle. Each device 5708/5709/57710 has different
720 static void bnx2i_setup_host_queue_size(struct bnx2i_hba
*hba
,
721 struct Scsi_Host
*shost
)
723 if (test_bit(BNX2I_NX2_DEV_5708
, &hba
->cnic_dev_type
))
724 shost
->can_queue
= ISCSI_MAX_CMDS_PER_HBA_5708
;
725 else if (test_bit(BNX2I_NX2_DEV_5709
, &hba
->cnic_dev_type
))
726 shost
->can_queue
= ISCSI_MAX_CMDS_PER_HBA_5709
;
727 else if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
))
728 shost
->can_queue
= ISCSI_MAX_CMDS_PER_HBA_57710
;
730 shost
->can_queue
= ISCSI_MAX_CMDS_PER_HBA_5708
;
735 * bnx2i_alloc_hba - allocate and init adapter instance
736 * @cnic: cnic device pointer
738 * allocate & initialize adapter structure and call other
739 * support routines to do per adapter initialization
741 struct bnx2i_hba
*bnx2i_alloc_hba(struct cnic_dev
*cnic
)
743 struct Scsi_Host
*shost
;
744 struct bnx2i_hba
*hba
;
746 shost
= iscsi_host_alloc(&bnx2i_host_template
, sizeof(*hba
), 0);
749 shost
->dma_boundary
= cnic
->pcidev
->dma_mask
;
750 shost
->transportt
= bnx2i_scsi_xport_template
;
751 shost
->max_id
= ISCSI_MAX_CONNS_PER_HBA
;
752 shost
->max_channel
= 0;
753 shost
->max_lun
= 512;
754 shost
->max_cmd_len
= 16;
756 hba
= iscsi_host_priv(shost
);
758 hba
->netdev
= cnic
->netdev
;
759 /* Get PCI related information and update hba struct members */
760 hba
->pcidev
= cnic
->pcidev
;
761 pci_dev_get(hba
->pcidev
);
762 hba
->pci_did
= hba
->pcidev
->device
;
763 hba
->pci_vid
= hba
->pcidev
->vendor
;
764 hba
->pci_sdid
= hba
->pcidev
->subsystem_device
;
765 hba
->pci_svid
= hba
->pcidev
->subsystem_vendor
;
766 hba
->pci_func
= PCI_FUNC(hba
->pcidev
->devfn
);
767 hba
->pci_devno
= PCI_SLOT(hba
->pcidev
->devfn
);
769 bnx2i_identify_device(hba
);
770 bnx2i_setup_host_queue_size(hba
, shost
);
772 if (test_bit(BNX2I_NX2_DEV_5709
, &hba
->cnic_dev_type
)) {
773 hba
->regview
= ioremap_nocache(hba
->netdev
->base_addr
,
777 } else if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
)) {
778 hba
->regview
= ioremap_nocache(hba
->netdev
->base_addr
, 4096);
783 if (bnx2i_setup_mp_bdt(hba
))
786 INIT_LIST_HEAD(&hba
->ep_ofld_list
);
787 INIT_LIST_HEAD(&hba
->ep_destroy_list
);
788 rwlock_init(&hba
->ep_rdwr_lock
);
790 hba
->mtu_supported
= BNX2I_MAX_MTU_SUPPORTED
;
792 /* different values for 5708/5709/57710 */
793 hba
->max_active_conns
= ISCSI_MAX_CONNS_PER_HBA
;
795 if (bnx2i_setup_free_cid_que(hba
))
798 /* SQ/RQ/CQ size can be changed via sysfx interface */
799 if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
)) {
800 if (sq_size
&& sq_size
<= BNX2I_5770X_SQ_WQES_MAX
)
801 hba
->max_sqes
= sq_size
;
803 hba
->max_sqes
= BNX2I_5770X_SQ_WQES_DEFAULT
;
804 } else { /* 5706/5708/5709 */
805 if (sq_size
&& sq_size
<= BNX2I_570X_SQ_WQES_MAX
)
806 hba
->max_sqes
= sq_size
;
808 hba
->max_sqes
= BNX2I_570X_SQ_WQES_DEFAULT
;
811 hba
->max_rqes
= rq_size
;
812 hba
->max_cqes
= hba
->max_sqes
+ rq_size
;
813 if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
)) {
814 if (hba
->max_cqes
> BNX2I_5770X_CQ_WQES_MAX
)
815 hba
->max_cqes
= BNX2I_5770X_CQ_WQES_MAX
;
816 } else if (hba
->max_cqes
> BNX2I_570X_CQ_WQES_MAX
)
817 hba
->max_cqes
= BNX2I_570X_CQ_WQES_MAX
;
819 hba
->num_ccell
= hba
->max_sqes
/ 2;
821 spin_lock_init(&hba
->lock
);
822 mutex_init(&hba
->net_dev_lock
);
823 init_waitqueue_head(&hba
->eh_wait
);
824 if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
))
825 hba
->hba_shutdown_tmo
= 240 * HZ
;
826 else /* 5706/5708/5709 */
827 hba
->hba_shutdown_tmo
= 30 * HZ
;
829 if (iscsi_host_add(shost
, &hba
->pcidev
->dev
))
834 bnx2i_release_free_cid_que(hba
);
836 bnx2i_free_mp_bdt(hba
);
839 iounmap(hba
->regview
);
843 pci_dev_put(hba
->pcidev
);
844 scsi_host_put(shost
);
849 * bnx2i_free_hba- releases hba structure and resources held by the adapter
850 * @hba: pointer to adapter instance
852 * free adapter structure and call various cleanup routines.
854 void bnx2i_free_hba(struct bnx2i_hba
*hba
)
856 struct Scsi_Host
*shost
= hba
->shost
;
858 iscsi_host_remove(shost
);
859 INIT_LIST_HEAD(&hba
->ep_ofld_list
);
860 INIT_LIST_HEAD(&hba
->ep_destroy_list
);
861 pci_dev_put(hba
->pcidev
);
864 iounmap(hba
->regview
);
867 bnx2i_free_mp_bdt(hba
);
868 bnx2i_release_free_cid_que(hba
);
869 iscsi_host_free(shost
);
873 * bnx2i_conn_free_login_resources - free DMA resources used for login process
874 * @hba: pointer to adapter instance
875 * @bnx2i_conn: iscsi connection pointer
877 * Login related resources, mostly BDT & payload DMA memory is freed
879 static void bnx2i_conn_free_login_resources(struct bnx2i_hba
*hba
,
880 struct bnx2i_conn
*bnx2i_conn
)
882 if (bnx2i_conn
->gen_pdu
.resp_bd_tbl
) {
883 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
884 bnx2i_conn
->gen_pdu
.resp_bd_tbl
,
885 bnx2i_conn
->gen_pdu
.resp_bd_dma
);
886 bnx2i_conn
->gen_pdu
.resp_bd_tbl
= NULL
;
889 if (bnx2i_conn
->gen_pdu
.req_bd_tbl
) {
890 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
891 bnx2i_conn
->gen_pdu
.req_bd_tbl
,
892 bnx2i_conn
->gen_pdu
.req_bd_dma
);
893 bnx2i_conn
->gen_pdu
.req_bd_tbl
= NULL
;
896 if (bnx2i_conn
->gen_pdu
.resp_buf
) {
897 dma_free_coherent(&hba
->pcidev
->dev
,
898 ISCSI_DEF_MAX_RECV_SEG_LEN
,
899 bnx2i_conn
->gen_pdu
.resp_buf
,
900 bnx2i_conn
->gen_pdu
.resp_dma_addr
);
901 bnx2i_conn
->gen_pdu
.resp_buf
= NULL
;
904 if (bnx2i_conn
->gen_pdu
.req_buf
) {
905 dma_free_coherent(&hba
->pcidev
->dev
,
906 ISCSI_DEF_MAX_RECV_SEG_LEN
,
907 bnx2i_conn
->gen_pdu
.req_buf
,
908 bnx2i_conn
->gen_pdu
.req_dma_addr
);
909 bnx2i_conn
->gen_pdu
.req_buf
= NULL
;
914 * bnx2i_conn_alloc_login_resources - alloc DMA resources for login/nop.
915 * @hba: pointer to adapter instance
916 * @bnx2i_conn: iscsi connection pointer
918 * Mgmt task DNA resources are allocated in this routine.
920 static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba
*hba
,
921 struct bnx2i_conn
*bnx2i_conn
)
923 /* Allocate memory for login request/response buffers */
924 bnx2i_conn
->gen_pdu
.req_buf
=
925 dma_alloc_coherent(&hba
->pcidev
->dev
,
926 ISCSI_DEF_MAX_RECV_SEG_LEN
,
927 &bnx2i_conn
->gen_pdu
.req_dma_addr
,
929 if (bnx2i_conn
->gen_pdu
.req_buf
== NULL
)
930 goto login_req_buf_failure
;
932 bnx2i_conn
->gen_pdu
.req_buf_size
= 0;
933 bnx2i_conn
->gen_pdu
.req_wr_ptr
= bnx2i_conn
->gen_pdu
.req_buf
;
935 bnx2i_conn
->gen_pdu
.resp_buf
=
936 dma_alloc_coherent(&hba
->pcidev
->dev
,
937 ISCSI_DEF_MAX_RECV_SEG_LEN
,
938 &bnx2i_conn
->gen_pdu
.resp_dma_addr
,
940 if (bnx2i_conn
->gen_pdu
.resp_buf
== NULL
)
941 goto login_resp_buf_failure
;
943 bnx2i_conn
->gen_pdu
.resp_buf_size
= ISCSI_DEF_MAX_RECV_SEG_LEN
;
944 bnx2i_conn
->gen_pdu
.resp_wr_ptr
= bnx2i_conn
->gen_pdu
.resp_buf
;
946 bnx2i_conn
->gen_pdu
.req_bd_tbl
=
947 dma_alloc_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
948 &bnx2i_conn
->gen_pdu
.req_bd_dma
, GFP_KERNEL
);
949 if (bnx2i_conn
->gen_pdu
.req_bd_tbl
== NULL
)
950 goto login_req_bd_tbl_failure
;
952 bnx2i_conn
->gen_pdu
.resp_bd_tbl
=
953 dma_alloc_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
954 &bnx2i_conn
->gen_pdu
.resp_bd_dma
,
956 if (bnx2i_conn
->gen_pdu
.resp_bd_tbl
== NULL
)
957 goto login_resp_bd_tbl_failure
;
961 login_resp_bd_tbl_failure
:
962 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
963 bnx2i_conn
->gen_pdu
.req_bd_tbl
,
964 bnx2i_conn
->gen_pdu
.req_bd_dma
);
965 bnx2i_conn
->gen_pdu
.req_bd_tbl
= NULL
;
967 login_req_bd_tbl_failure
:
968 dma_free_coherent(&hba
->pcidev
->dev
, ISCSI_DEF_MAX_RECV_SEG_LEN
,
969 bnx2i_conn
->gen_pdu
.resp_buf
,
970 bnx2i_conn
->gen_pdu
.resp_dma_addr
);
971 bnx2i_conn
->gen_pdu
.resp_buf
= NULL
;
972 login_resp_buf_failure
:
973 dma_free_coherent(&hba
->pcidev
->dev
, ISCSI_DEF_MAX_RECV_SEG_LEN
,
974 bnx2i_conn
->gen_pdu
.req_buf
,
975 bnx2i_conn
->gen_pdu
.req_dma_addr
);
976 bnx2i_conn
->gen_pdu
.req_buf
= NULL
;
977 login_req_buf_failure
:
978 iscsi_conn_printk(KERN_ERR
, bnx2i_conn
->cls_conn
->dd_data
,
979 "login resource alloc failed!!\n");
986 * bnx2i_iscsi_prep_generic_pdu_bd - prepares BD table.
987 * @bnx2i_conn: iscsi connection pointer
989 * Allocates buffers and BD tables before shipping requests to cnic
990 * for PDUs prepared by 'iscsid' daemon
992 static void bnx2i_iscsi_prep_generic_pdu_bd(struct bnx2i_conn
*bnx2i_conn
)
994 struct iscsi_bd
*bd_tbl
;
996 bd_tbl
= (struct iscsi_bd
*) bnx2i_conn
->gen_pdu
.req_bd_tbl
;
998 bd_tbl
->buffer_addr_hi
=
999 (u32
) ((u64
) bnx2i_conn
->gen_pdu
.req_dma_addr
>> 32);
1000 bd_tbl
->buffer_addr_lo
= (u32
) bnx2i_conn
->gen_pdu
.req_dma_addr
;
1001 bd_tbl
->buffer_length
= bnx2i_conn
->gen_pdu
.req_wr_ptr
-
1002 bnx2i_conn
->gen_pdu
.req_buf
;
1003 bd_tbl
->reserved0
= 0;
1004 bd_tbl
->flags
= ISCSI_BD_LAST_IN_BD_CHAIN
|
1005 ISCSI_BD_FIRST_IN_BD_CHAIN
;
1007 bd_tbl
= (struct iscsi_bd
*) bnx2i_conn
->gen_pdu
.resp_bd_tbl
;
1008 bd_tbl
->buffer_addr_hi
= (u64
) bnx2i_conn
->gen_pdu
.resp_dma_addr
>> 32;
1009 bd_tbl
->buffer_addr_lo
= (u32
) bnx2i_conn
->gen_pdu
.resp_dma_addr
;
1010 bd_tbl
->buffer_length
= ISCSI_DEF_MAX_RECV_SEG_LEN
;
1011 bd_tbl
->reserved0
= 0;
1012 bd_tbl
->flags
= ISCSI_BD_LAST_IN_BD_CHAIN
|
1013 ISCSI_BD_FIRST_IN_BD_CHAIN
;
1018 * bnx2i_iscsi_send_generic_request - called to send mgmt tasks.
1019 * @task: transport layer task pointer
1021 * called to transmit PDUs prepared by the 'iscsid' daemon. iSCSI login,
1022 * Nop-out and Logout requests flow through this path.
1024 static int bnx2i_iscsi_send_generic_request(struct iscsi_task
*task
)
1026 struct bnx2i_cmd
*cmd
= task
->dd_data
;
1027 struct bnx2i_conn
*bnx2i_conn
= cmd
->conn
;
1032 bnx2i_iscsi_prep_generic_pdu_bd(bnx2i_conn
);
1033 switch (task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) {
1034 case ISCSI_OP_LOGIN
:
1035 bnx2i_send_iscsi_login(bnx2i_conn
, task
);
1037 case ISCSI_OP_NOOP_OUT
:
1038 data_len
= bnx2i_conn
->gen_pdu
.req_buf_size
;
1039 buf
= bnx2i_conn
->gen_pdu
.req_buf
;
1041 rc
= bnx2i_send_iscsi_nopout(bnx2i_conn
, task
,
1045 rc
= bnx2i_send_iscsi_nopout(bnx2i_conn
, task
,
1049 case ISCSI_OP_LOGOUT
:
1050 rc
= bnx2i_send_iscsi_logout(bnx2i_conn
, task
);
1052 case ISCSI_OP_SCSI_TMFUNC
:
1053 rc
= bnx2i_send_iscsi_tmf(bnx2i_conn
, task
);
1056 iscsi_conn_printk(KERN_ALERT
, bnx2i_conn
->cls_conn
->dd_data
,
1057 "send_gen: unsupported op 0x%x\n",
1064 /**********************************************************************
1066 **********************************************************************/
1069 * bnx2i_cpy_scsi_cdb - copies LUN & CDB fields in required format to sq wqe
1070 * @sc: SCSI-ML command pointer
1071 * @cmd: iscsi cmd pointer
1073 static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd
*sc
, struct bnx2i_cmd
*cmd
)
1081 int_to_scsilun(sc
->device
->lun
, (struct scsi_lun
*) scsi_lun
);
1082 cmd
->req
.lun
[0] = be32_to_cpu(scsi_lun
[0]);
1083 cmd
->req
.lun
[1] = be32_to_cpu(scsi_lun
[1]);
1085 lpcnt
= cmd
->scsi_cmd
->cmd_len
/ sizeof(dword
);
1086 srcp
= (u8
*) sc
->cmnd
;
1087 dstp
= (u32
*) cmd
->req
.cdb
;
1089 memcpy(&dword
, (const void *) srcp
, 4);
1090 *dstp
= cpu_to_be32(dword
);
1094 if (sc
->cmd_len
& 0x3) {
1095 dword
= (u32
) srcp
[0] | ((u32
) srcp
[1] << 8);
1096 *dstp
= cpu_to_be32(dword
);
1100 static void bnx2i_cleanup_task(struct iscsi_task
*task
)
1102 struct iscsi_conn
*conn
= task
->conn
;
1103 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
1104 struct bnx2i_hba
*hba
= bnx2i_conn
->hba
;
1107 * mgmt task or cmd was never sent to us to transmit.
1109 if (!task
->sc
|| task
->state
== ISCSI_TASK_PENDING
)
1112 * need to clean-up task context to claim dma buffers
1114 if (task
->state
== ISCSI_TASK_ABRT_TMF
) {
1115 bnx2i_send_cmd_cleanup_req(hba
, task
->dd_data
);
1117 spin_unlock_bh(&conn
->session
->lock
);
1118 wait_for_completion_timeout(&bnx2i_conn
->cmd_cleanup_cmpl
,
1119 msecs_to_jiffies(ISCSI_CMD_CLEANUP_TIMEOUT
));
1120 spin_lock_bh(&conn
->session
->lock
);
1122 bnx2i_iscsi_unmap_sg_list(task
->dd_data
);
1126 * bnx2i_mtask_xmit - transmit mtask to chip for further processing
1127 * @conn: transport layer conn structure pointer
1128 * @task: transport layer command structure pointer
1131 bnx2i_mtask_xmit(struct iscsi_conn
*conn
, struct iscsi_task
*task
)
1133 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
1134 struct bnx2i_cmd
*cmd
= task
->dd_data
;
1136 memset(bnx2i_conn
->gen_pdu
.req_buf
, 0, ISCSI_DEF_MAX_RECV_SEG_LEN
);
1138 bnx2i_setup_cmd_wqe_template(cmd
);
1139 bnx2i_conn
->gen_pdu
.req_buf_size
= task
->data_count
;
1140 if (task
->data_count
) {
1141 memcpy(bnx2i_conn
->gen_pdu
.req_buf
, task
->data
,
1143 bnx2i_conn
->gen_pdu
.req_wr_ptr
=
1144 bnx2i_conn
->gen_pdu
.req_buf
+ task
->data_count
;
1146 cmd
->conn
= conn
->dd_data
;
1147 cmd
->scsi_cmd
= NULL
;
1148 return bnx2i_iscsi_send_generic_request(task
);
1152 * bnx2i_task_xmit - transmit iscsi command to chip for further processing
1153 * @task: transport layer command structure pointer
1155 * maps SG buffers and send request to chip/firmware in the form of SQ WQE
1157 static int bnx2i_task_xmit(struct iscsi_task
*task
)
1159 struct iscsi_conn
*conn
= task
->conn
;
1160 struct iscsi_session
*session
= conn
->session
;
1161 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
->cls_session
);
1162 struct bnx2i_hba
*hba
= iscsi_host_priv(shost
);
1163 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
1164 struct scsi_cmnd
*sc
= task
->sc
;
1165 struct bnx2i_cmd
*cmd
= task
->dd_data
;
1166 struct iscsi_cmd
*hdr
= (struct iscsi_cmd
*) task
->hdr
;
1169 * If there is no scsi_cmnd this must be a mgmt task
1172 return bnx2i_mtask_xmit(conn
, task
);
1174 bnx2i_setup_cmd_wqe_template(cmd
);
1175 cmd
->req
.op_code
= ISCSI_OP_SCSI_CMD
;
1176 cmd
->conn
= bnx2i_conn
;
1178 cmd
->req
.total_data_transfer_length
= scsi_bufflen(sc
);
1179 cmd
->req
.cmd_sn
= be32_to_cpu(hdr
->cmdsn
);
1181 bnx2i_iscsi_map_sg_list(cmd
);
1182 bnx2i_cpy_scsi_cdb(sc
, cmd
);
1184 cmd
->req
.op_attr
= ISCSI_ATTR_SIMPLE
;
1185 if (sc
->sc_data_direction
== DMA_TO_DEVICE
) {
1186 cmd
->req
.op_attr
|= ISCSI_CMD_REQUEST_WRITE
;
1187 cmd
->req
.itt
= task
->itt
|
1188 (ISCSI_TASK_TYPE_WRITE
<< ISCSI_CMD_REQUEST_TYPE_SHIFT
);
1189 bnx2i_setup_write_cmd_bd_info(task
);
1191 if (scsi_bufflen(sc
))
1192 cmd
->req
.op_attr
|= ISCSI_CMD_REQUEST_READ
;
1193 cmd
->req
.itt
= task
->itt
|
1194 (ISCSI_TASK_TYPE_READ
<< ISCSI_CMD_REQUEST_TYPE_SHIFT
);
1197 cmd
->req
.num_bds
= cmd
->io_tbl
.bd_valid
;
1198 if (!cmd
->io_tbl
.bd_valid
) {
1199 cmd
->req
.bd_list_addr_lo
= (u32
) hba
->mp_bd_dma
;
1200 cmd
->req
.bd_list_addr_hi
= (u32
) ((u64
) hba
->mp_bd_dma
>> 32);
1201 cmd
->req
.num_bds
= 1;
1204 bnx2i_send_iscsi_scsicmd(bnx2i_conn
, cmd
);
1209 * bnx2i_session_create - create a new iscsi session
1210 * @cmds_max: max commands supported
1211 * @qdepth: scsi queue depth to support
1212 * @initial_cmdsn: initial iscsi CMDSN to be used for this session
1214 * Creates a new iSCSI session instance on given device.
1216 static struct iscsi_cls_session
*
1217 bnx2i_session_create(struct iscsi_endpoint
*ep
,
1218 uint16_t cmds_max
, uint16_t qdepth
,
1219 uint32_t initial_cmdsn
)
1221 struct Scsi_Host
*shost
;
1222 struct iscsi_cls_session
*cls_session
;
1223 struct bnx2i_hba
*hba
;
1224 struct bnx2i_endpoint
*bnx2i_ep
;
1227 printk(KERN_ERR
"bnx2i: missing ep.\n");
1231 bnx2i_ep
= ep
->dd_data
;
1232 shost
= bnx2i_ep
->hba
->shost
;
1233 hba
= iscsi_host_priv(shost
);
1234 if (bnx2i_adapter_ready(hba
))
1238 * user can override hw limit as long as it is within
1241 if (cmds_max
> hba
->max_sqes
)
1242 cmds_max
= hba
->max_sqes
;
1243 else if (cmds_max
< BNX2I_SQ_WQES_MIN
)
1244 cmds_max
= BNX2I_SQ_WQES_MIN
;
1246 cls_session
= iscsi_session_setup(&bnx2i_iscsi_transport
, shost
,
1247 cmds_max
, 0, sizeof(struct bnx2i_cmd
),
1248 initial_cmdsn
, ISCSI_MAX_TARGET
);
1252 if (bnx2i_setup_cmd_pool(hba
, cls_session
->dd_data
))
1253 goto session_teardown
;
1257 iscsi_session_teardown(cls_session
);
1263 * bnx2i_session_destroy - destroys iscsi session
1264 * @cls_session: pointer to iscsi cls session
1266 * Destroys previously created iSCSI session instance and releases
1267 * all resources held by it
1269 static void bnx2i_session_destroy(struct iscsi_cls_session
*cls_session
)
1271 struct iscsi_session
*session
= cls_session
->dd_data
;
1272 struct Scsi_Host
*shost
= iscsi_session_to_shost(cls_session
);
1273 struct bnx2i_hba
*hba
= iscsi_host_priv(shost
);
1275 bnx2i_destroy_cmd_pool(hba
, session
);
1276 iscsi_session_teardown(cls_session
);
1281 * bnx2i_conn_create - create iscsi connection instance
1282 * @cls_session: pointer to iscsi cls session
1283 * @cid: iscsi cid as per rfc (not NX2's CID terminology)
1285 * Creates a new iSCSI connection instance for a given session
1287 static struct iscsi_cls_conn
*
1288 bnx2i_conn_create(struct iscsi_cls_session
*cls_session
, uint32_t cid
)
1290 struct Scsi_Host
*shost
= iscsi_session_to_shost(cls_session
);
1291 struct bnx2i_hba
*hba
= iscsi_host_priv(shost
);
1292 struct bnx2i_conn
*bnx2i_conn
;
1293 struct iscsi_cls_conn
*cls_conn
;
1294 struct iscsi_conn
*conn
;
1296 cls_conn
= iscsi_conn_setup(cls_session
, sizeof(*bnx2i_conn
),
1300 conn
= cls_conn
->dd_data
;
1302 bnx2i_conn
= conn
->dd_data
;
1303 bnx2i_conn
->cls_conn
= cls_conn
;
1304 bnx2i_conn
->hba
= hba
;
1305 /* 'ep' ptr will be assigned in bind() call */
1306 bnx2i_conn
->ep
= NULL
;
1307 init_completion(&bnx2i_conn
->cmd_cleanup_cmpl
);
1309 if (bnx2i_conn_alloc_login_resources(hba
, bnx2i_conn
)) {
1310 iscsi_conn_printk(KERN_ALERT
, conn
,
1311 "conn_new: login resc alloc failed!!\n");
1318 iscsi_conn_teardown(cls_conn
);
1323 * bnx2i_conn_bind - binds iscsi sess, conn and ep objects together
1324 * @cls_session: pointer to iscsi cls session
1325 * @cls_conn: pointer to iscsi cls conn
1326 * @transport_fd: 64-bit EP handle
1327 * @is_leading: leading connection on this session?
1329 * Binds together iSCSI session instance, iSCSI connection instance
1330 * and the TCP connection. This routine returns error code if
1331 * TCP connection does not belong on the device iSCSI sess/conn
1334 static int bnx2i_conn_bind(struct iscsi_cls_session
*cls_session
,
1335 struct iscsi_cls_conn
*cls_conn
,
1336 uint64_t transport_fd
, int is_leading
)
1338 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
1339 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
1340 struct Scsi_Host
*shost
= iscsi_session_to_shost(cls_session
);
1341 struct bnx2i_hba
*hba
= iscsi_host_priv(shost
);
1342 struct bnx2i_endpoint
*bnx2i_ep
;
1343 struct iscsi_endpoint
*ep
;
1346 ep
= iscsi_lookup_endpoint(transport_fd
);
1350 bnx2i_ep
= ep
->dd_data
;
1351 if ((bnx2i_ep
->state
== EP_STATE_TCP_FIN_RCVD
) ||
1352 (bnx2i_ep
->state
== EP_STATE_TCP_RST_RCVD
))
1353 /* Peer disconnect via' FIN or RST */
1356 if (iscsi_conn_bind(cls_session
, cls_conn
, is_leading
))
1359 if (bnx2i_ep
->hba
!= hba
) {
1360 /* Error - TCP connection does not belong to this device
1362 iscsi_conn_printk(KERN_ALERT
, cls_conn
->dd_data
,
1363 "conn bind, ep=0x%p (%s) does not",
1364 bnx2i_ep
, bnx2i_ep
->hba
->netdev
->name
);
1365 iscsi_conn_printk(KERN_ALERT
, cls_conn
->dd_data
,
1366 "belong to hba (%s)\n",
1371 bnx2i_ep
->conn
= bnx2i_conn
;
1372 bnx2i_conn
->ep
= bnx2i_ep
;
1373 bnx2i_conn
->iscsi_conn_cid
= bnx2i_ep
->ep_iscsi_cid
;
1374 bnx2i_conn
->fw_cid
= bnx2i_ep
->ep_cid
;
1376 ret_code
= bnx2i_bind_conn_to_iscsi_cid(hba
, bnx2i_conn
,
1377 bnx2i_ep
->ep_iscsi_cid
);
1379 /* 5706/5708/5709 FW takes RQ as full when initiated, but for 57710
1380 * driver needs to explicitly replenish RQ index during setup.
1382 if (test_bit(BNX2I_NX2_DEV_57710
, &bnx2i_ep
->hba
->cnic_dev_type
))
1383 bnx2i_put_rq_buf(bnx2i_conn
, 0);
1385 bnx2i_arm_cq_event_coalescing(bnx2i_conn
->ep
, CNIC_ARM_CQE
);
1391 * bnx2i_conn_destroy - destroy iscsi connection instance & release resources
1392 * @cls_conn: pointer to iscsi cls conn
1394 * Destroy an iSCSI connection instance and release memory resources held by
1397 static void bnx2i_conn_destroy(struct iscsi_cls_conn
*cls_conn
)
1399 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
1400 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
1401 struct Scsi_Host
*shost
;
1402 struct bnx2i_hba
*hba
;
1404 shost
= iscsi_session_to_shost(iscsi_conn_to_session(cls_conn
));
1405 hba
= iscsi_host_priv(shost
);
1407 bnx2i_conn_free_login_resources(hba
, bnx2i_conn
);
1408 iscsi_conn_teardown(cls_conn
);
1413 * bnx2i_conn_get_param - return iscsi connection parameter to caller
1414 * @cls_conn: pointer to iscsi cls conn
1415 * @param: parameter type identifier
1416 * @buf: buffer pointer
1418 * returns iSCSI connection parameters
1420 static int bnx2i_conn_get_param(struct iscsi_cls_conn
*cls_conn
,
1421 enum iscsi_param param
, char *buf
)
1423 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
1424 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
1428 case ISCSI_PARAM_CONN_PORT
:
1430 len
= sprintf(buf
, "%hu\n",
1431 bnx2i_conn
->ep
->cm_sk
->dst_port
);
1433 case ISCSI_PARAM_CONN_ADDRESS
:
1435 len
= sprintf(buf
, "%pI4\n",
1436 &bnx2i_conn
->ep
->cm_sk
->dst_ip
);
1439 return iscsi_conn_get_param(cls_conn
, param
, buf
);
1446 * bnx2i_host_get_param - returns host (adapter) related parameters
1447 * @shost: scsi host pointer
1448 * @param: parameter type identifier
1449 * @buf: buffer pointer
1451 static int bnx2i_host_get_param(struct Scsi_Host
*shost
,
1452 enum iscsi_host_param param
, char *buf
)
1454 struct bnx2i_hba
*hba
= iscsi_host_priv(shost
);
1458 case ISCSI_HOST_PARAM_HWADDRESS
:
1459 len
= sysfs_format_mac(buf
, hba
->cnic
->mac_addr
, 6);
1461 case ISCSI_HOST_PARAM_NETDEV_NAME
:
1462 len
= sprintf(buf
, "%s\n", hba
->netdev
->name
);
1465 return iscsi_host_get_param(shost
, param
, buf
);
1471 * bnx2i_conn_start - completes iscsi connection migration to FFP
1472 * @cls_conn: pointer to iscsi cls conn
1474 * last call in FFP migration to handover iscsi conn to the driver
1476 static int bnx2i_conn_start(struct iscsi_cls_conn
*cls_conn
)
1478 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
1479 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
1481 bnx2i_conn
->ep
->state
= EP_STATE_ULP_UPDATE_START
;
1482 bnx2i_update_iscsi_conn(conn
);
1485 * this should normally not sleep for a long time so it should
1486 * not disrupt the caller.
1488 bnx2i_conn
->ep
->ofld_timer
.expires
= 1 * HZ
+ jiffies
;
1489 bnx2i_conn
->ep
->ofld_timer
.function
= bnx2i_ep_ofld_timer
;
1490 bnx2i_conn
->ep
->ofld_timer
.data
= (unsigned long) bnx2i_conn
->ep
;
1491 add_timer(&bnx2i_conn
->ep
->ofld_timer
);
1492 /* update iSCSI context for this conn, wait for CNIC to complete */
1493 wait_event_interruptible(bnx2i_conn
->ep
->ofld_wait
,
1494 bnx2i_conn
->ep
->state
!= EP_STATE_ULP_UPDATE_START
);
1496 if (signal_pending(current
))
1497 flush_signals(current
);
1498 del_timer_sync(&bnx2i_conn
->ep
->ofld_timer
);
1500 iscsi_conn_start(cls_conn
);
1506 * bnx2i_conn_get_stats - returns iSCSI stats
1507 * @cls_conn: pointer to iscsi cls conn
1508 * @stats: pointer to iscsi statistic struct
1510 static void bnx2i_conn_get_stats(struct iscsi_cls_conn
*cls_conn
,
1511 struct iscsi_stats
*stats
)
1513 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
1515 stats
->txdata_octets
= conn
->txdata_octets
;
1516 stats
->rxdata_octets
= conn
->rxdata_octets
;
1517 stats
->scsicmd_pdus
= conn
->scsicmd_pdus_cnt
;
1518 stats
->dataout_pdus
= conn
->dataout_pdus_cnt
;
1519 stats
->scsirsp_pdus
= conn
->scsirsp_pdus_cnt
;
1520 stats
->datain_pdus
= conn
->datain_pdus_cnt
;
1521 stats
->r2t_pdus
= conn
->r2t_pdus_cnt
;
1522 stats
->tmfcmd_pdus
= conn
->tmfcmd_pdus_cnt
;
1523 stats
->tmfrsp_pdus
= conn
->tmfrsp_pdus_cnt
;
1524 stats
->custom_length
= 3;
1525 strcpy(stats
->custom
[2].desc
, "eh_abort_cnt");
1526 stats
->custom
[2].value
= conn
->eh_abort_cnt
;
1527 stats
->digest_err
= 0;
1528 stats
->timeout_err
= 0;
1529 stats
->custom_length
= 0;
1534 * bnx2i_check_route - checks if target IP route belongs to one of NX2 devices
1535 * @dst_addr: target IP address
1537 * check if route resolves to BNX2 device
1539 static struct bnx2i_hba
*bnx2i_check_route(struct sockaddr
*dst_addr
)
1541 struct sockaddr_in
*desti
= (struct sockaddr_in
*) dst_addr
;
1542 struct bnx2i_hba
*hba
;
1543 struct cnic_dev
*cnic
= NULL
;
1545 bnx2i_reg_dev_all();
1547 hba
= get_adapter_list_head();
1548 if (hba
&& hba
->cnic
)
1549 cnic
= hba
->cnic
->cm_select_dev(desti
, CNIC_ULP_ISCSI
);
1551 printk(KERN_ALERT
"bnx2i: no route,"
1552 "can't connect using cnic\n");
1555 hba
= bnx2i_find_hba_for_cnic(cnic
);
1559 if (bnx2i_adapter_ready(hba
)) {
1560 printk(KERN_ALERT
"bnx2i: check route, hba not found\n");
1563 if (hba
->netdev
->mtu
> hba
->mtu_supported
) {
1564 printk(KERN_ALERT
"bnx2i: %s network i/f mtu is set to %d\n",
1565 hba
->netdev
->name
, hba
->netdev
->mtu
);
1566 printk(KERN_ALERT
"bnx2i: iSCSI HBA can support mtu of %d\n",
1567 hba
->mtu_supported
);
1577 * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources
1578 * @hba: pointer to adapter instance
1579 * @ep: endpoint (transport indentifier) structure
1581 * destroys cm_sock structure and on chip iscsi context
1583 static int bnx2i_tear_down_conn(struct bnx2i_hba
*hba
,
1584 struct bnx2i_endpoint
*ep
)
1586 if (test_bit(BNX2I_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
1587 hba
->cnic
->cm_destroy(ep
->cm_sk
);
1589 if (test_bit(ADAPTER_STATE_GOING_DOWN
, &ep
->hba
->adapter_state
))
1590 ep
->state
= EP_STATE_DISCONN_COMPL
;
1592 if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
) &&
1593 ep
->state
== EP_STATE_DISCONN_TIMEDOUT
) {
1594 printk(KERN_ALERT
"bnx2i - ERROR - please submit GRC Dump,"
1595 " NW/PCIe trace, driver msgs to developers"
1600 ep
->state
= EP_STATE_CLEANUP_START
;
1601 init_timer(&ep
->ofld_timer
);
1602 ep
->ofld_timer
.expires
= 10*HZ
+ jiffies
;
1603 ep
->ofld_timer
.function
= bnx2i_ep_ofld_timer
;
1604 ep
->ofld_timer
.data
= (unsigned long) ep
;
1605 add_timer(&ep
->ofld_timer
);
1607 bnx2i_ep_destroy_list_add(hba
, ep
);
1609 /* destroy iSCSI context, wait for it to complete */
1610 bnx2i_send_conn_destroy(hba
, ep
);
1611 wait_event_interruptible(ep
->ofld_wait
,
1612 (ep
->state
!= EP_STATE_CLEANUP_START
));
1614 if (signal_pending(current
))
1615 flush_signals(current
);
1616 del_timer_sync(&ep
->ofld_timer
);
1618 bnx2i_ep_destroy_list_del(hba
, ep
);
1620 if (ep
->state
!= EP_STATE_CLEANUP_CMPL
)
1621 /* should never happen */
1622 printk(KERN_ALERT
"bnx2i - conn destroy failed\n");
1629 * bnx2i_ep_connect - establish TCP connection to target portal
1631 * @dst_addr: target IP address
1632 * @non_blocking: blocking or non-blocking call
1634 * this routine initiates the TCP/IP connection by invoking Option-2 i/f
1635 * with l5_core and the CNIC. This is a multi-step process of resolving
1636 * route to target, create a iscsi connection context, handshaking with
1637 * CNIC module to create/initialize the socket struct and finally
1638 * sending down option-2 request to complete TCP 3-way handshake
1640 static struct iscsi_endpoint
*bnx2i_ep_connect(struct Scsi_Host
*shost
,
1641 struct sockaddr
*dst_addr
,
1644 u32 iscsi_cid
= BNX2I_CID_RESERVED
;
1645 struct sockaddr_in
*desti
= (struct sockaddr_in
*) dst_addr
;
1646 struct sockaddr_in6
*desti6
;
1647 struct bnx2i_endpoint
*bnx2i_ep
;
1648 struct bnx2i_hba
*hba
;
1649 struct cnic_dev
*cnic
;
1650 struct cnic_sockaddr saddr
;
1651 struct iscsi_endpoint
*ep
;
1655 /* driver is given scsi host to work with */
1656 hba
= iscsi_host_priv(shost
);
1657 /* Register the device with cnic if not already done so */
1658 bnx2i_register_device(hba
);
1661 * check if the given destination can be reached through
1662 * a iscsi capable NetXtreme2 device
1664 hba
= bnx2i_check_route(dst_addr
);
1666 if (!hba
|| test_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
)) {
1672 ep
= bnx2i_alloc_ep(hba
);
1677 bnx2i_ep
= ep
->dd_data
;
1679 mutex_lock(&hba
->net_dev_lock
);
1680 if (bnx2i_adapter_ready(hba
)) {
1685 bnx2i_ep
->num_active_cmds
= 0;
1686 iscsi_cid
= bnx2i_alloc_iscsi_cid(hba
);
1687 if (iscsi_cid
== -1) {
1688 printk(KERN_ALERT
"alloc_ep: unable to allocate iscsi cid\n");
1692 bnx2i_ep
->hba_age
= hba
->age
;
1694 rc
= bnx2i_alloc_qp_resc(hba
, bnx2i_ep
);
1696 printk(KERN_ALERT
"bnx2i: ep_conn, alloc QP resc error\n");
1701 bnx2i_ep
->ep_iscsi_cid
= (u16
)iscsi_cid
;
1702 bnx2i_ep
->state
= EP_STATE_OFLD_START
;
1703 bnx2i_ep_ofld_list_add(hba
, bnx2i_ep
);
1705 init_timer(&bnx2i_ep
->ofld_timer
);
1706 bnx2i_ep
->ofld_timer
.expires
= 2 * HZ
+ jiffies
;
1707 bnx2i_ep
->ofld_timer
.function
= bnx2i_ep_ofld_timer
;
1708 bnx2i_ep
->ofld_timer
.data
= (unsigned long) bnx2i_ep
;
1709 add_timer(&bnx2i_ep
->ofld_timer
);
1711 bnx2i_send_conn_ofld_req(hba
, bnx2i_ep
);
1713 /* Wait for CNIC hardware to setup conn context and return 'cid' */
1714 wait_event_interruptible(bnx2i_ep
->ofld_wait
,
1715 bnx2i_ep
->state
!= EP_STATE_OFLD_START
);
1717 if (signal_pending(current
))
1718 flush_signals(current
);
1719 del_timer_sync(&bnx2i_ep
->ofld_timer
);
1721 bnx2i_ep_ofld_list_del(hba
, bnx2i_ep
);
1723 if (bnx2i_ep
->state
!= EP_STATE_OFLD_COMPL
) {
1728 rc
= cnic
->cm_create(cnic
, CNIC_ULP_ISCSI
, bnx2i_ep
->ep_cid
,
1729 iscsi_cid
, &bnx2i_ep
->cm_sk
, bnx2i_ep
);
1735 bnx2i_ep
->cm_sk
->rcv_buf
= 256 * 1024;
1736 bnx2i_ep
->cm_sk
->snd_buf
= 256 * 1024;
1737 clear_bit(SK_TCP_TIMESTAMP
, &bnx2i_ep
->cm_sk
->tcp_flags
);
1739 memset(&saddr
, 0, sizeof(saddr
));
1740 if (dst_addr
->sa_family
== AF_INET
) {
1741 desti
= (struct sockaddr_in
*) dst_addr
;
1742 saddr
.remote
.v4
= *desti
;
1743 saddr
.local
.v4
.sin_family
= desti
->sin_family
;
1744 } else if (dst_addr
->sa_family
== AF_INET6
) {
1745 desti6
= (struct sockaddr_in6
*) dst_addr
;
1746 saddr
.remote
.v6
= *desti6
;
1747 saddr
.local
.v6
.sin6_family
= desti6
->sin6_family
;
1750 bnx2i_ep
->timestamp
= jiffies
;
1751 bnx2i_ep
->state
= EP_STATE_CONNECT_START
;
1752 if (!test_bit(BNX2I_CNIC_REGISTERED
, &hba
->reg_with_cnic
)) {
1756 rc
= cnic
->cm_connect(bnx2i_ep
->cm_sk
, &saddr
);
1761 if (bnx2i_map_ep_dbell_regs(bnx2i_ep
))
1763 mutex_unlock(&hba
->net_dev_lock
);
1767 if (bnx2i_tear_down_conn(hba
, bnx2i_ep
)) {
1768 mutex_unlock(&hba
->net_dev_lock
);
1774 bnx2i_free_qp_resc(hba
, bnx2i_ep
);
1777 mutex_unlock(&hba
->net_dev_lock
);
1779 bnx2i_unreg_dev_all();
1785 * bnx2i_ep_poll - polls for TCP connection establishement
1786 * @ep: TCP connection (endpoint) handle
1787 * @timeout_ms: timeout value in milli secs
1789 * polls for TCP connect request to complete
1791 static int bnx2i_ep_poll(struct iscsi_endpoint
*ep
, int timeout_ms
)
1793 struct bnx2i_endpoint
*bnx2i_ep
;
1796 bnx2i_ep
= ep
->dd_data
;
1797 if ((bnx2i_ep
->state
== EP_STATE_IDLE
) ||
1798 (bnx2i_ep
->state
== EP_STATE_CONNECT_FAILED
) ||
1799 (bnx2i_ep
->state
== EP_STATE_OFLD_FAILED
))
1801 if (bnx2i_ep
->state
== EP_STATE_CONNECT_COMPL
)
1804 rc
= wait_event_interruptible_timeout(bnx2i_ep
->ofld_wait
,
1805 ((bnx2i_ep
->state
==
1806 EP_STATE_OFLD_FAILED
) ||
1808 EP_STATE_CONNECT_FAILED
) ||
1810 EP_STATE_CONNECT_COMPL
)),
1811 msecs_to_jiffies(timeout_ms
));
1812 if (bnx2i_ep
->state
== EP_STATE_OFLD_FAILED
)
1818 return 0; /* timeout */
1825 * bnx2i_ep_tcp_conn_active - check EP state transition
1826 * @ep: endpoint pointer
1828 * check if underlying TCP connection is active
1830 static int bnx2i_ep_tcp_conn_active(struct bnx2i_endpoint
*bnx2i_ep
)
1833 int cnic_dev_10g
= 0;
1835 if (test_bit(BNX2I_NX2_DEV_57710
, &bnx2i_ep
->hba
->cnic_dev_type
))
1838 switch (bnx2i_ep
->state
) {
1839 case EP_STATE_CONNECT_START
:
1840 case EP_STATE_CLEANUP_FAILED
:
1841 case EP_STATE_OFLD_FAILED
:
1842 case EP_STATE_DISCONN_TIMEDOUT
:
1845 case EP_STATE_CONNECT_COMPL
:
1846 case EP_STATE_ULP_UPDATE_START
:
1847 case EP_STATE_ULP_UPDATE_COMPL
:
1848 case EP_STATE_TCP_FIN_RCVD
:
1849 case EP_STATE_ULP_UPDATE_FAILED
:
1852 case EP_STATE_TCP_RST_RCVD
:
1855 case EP_STATE_CONNECT_FAILED
:
1870 * bnx2i_ep_disconnect - executes TCP connection teardown process
1871 * @ep: TCP connection (endpoint) handle
1873 * executes TCP connection teardown process
1875 static void bnx2i_ep_disconnect(struct iscsi_endpoint
*ep
)
1877 struct bnx2i_endpoint
*bnx2i_ep
;
1878 struct bnx2i_conn
*bnx2i_conn
= NULL
;
1879 struct iscsi_session
*session
= NULL
;
1880 struct iscsi_conn
*conn
;
1881 struct cnic_dev
*cnic
;
1882 struct bnx2i_hba
*hba
;
1884 bnx2i_ep
= ep
->dd_data
;
1886 /* driver should not attempt connection cleanup until TCP_CONNECT
1887 * completes either successfully or fails. Timeout is 9-secs, so
1888 * wait for it to complete
1890 while ((bnx2i_ep
->state
== EP_STATE_CONNECT_START
) &&
1891 !time_after(jiffies
, bnx2i_ep
->timestamp
+ (12 * HZ
)))
1894 if (bnx2i_ep
->conn
) {
1895 bnx2i_conn
= bnx2i_ep
->conn
;
1896 conn
= bnx2i_conn
->cls_conn
->dd_data
;
1897 session
= conn
->session
;
1899 iscsi_suspend_queue(conn
);
1902 hba
= bnx2i_ep
->hba
;
1903 if (bnx2i_ep
->state
== EP_STATE_IDLE
)
1904 goto return_bnx2i_ep
;
1907 mutex_lock(&hba
->net_dev_lock
);
1909 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
1911 if (bnx2i_ep
->hba_age
!= hba
->age
)
1914 if (!bnx2i_ep_tcp_conn_active(bnx2i_ep
))
1917 bnx2i_ep
->state
= EP_STATE_DISCONN_START
;
1919 init_timer(&bnx2i_ep
->ofld_timer
);
1920 bnx2i_ep
->ofld_timer
.expires
= 10*HZ
+ jiffies
;
1921 bnx2i_ep
->ofld_timer
.function
= bnx2i_ep_ofld_timer
;
1922 bnx2i_ep
->ofld_timer
.data
= (unsigned long) bnx2i_ep
;
1923 add_timer(&bnx2i_ep
->ofld_timer
);
1925 if (test_bit(BNX2I_CNIC_REGISTERED
, &hba
->reg_with_cnic
)) {
1929 spin_lock_bh(&session
->lock
);
1930 if (session
->state
== ISCSI_STATE_LOGGING_OUT
)
1932 spin_unlock_bh(&session
->lock
);
1935 cnic
->cm_close(bnx2i_ep
->cm_sk
);
1937 cnic
->cm_abort(bnx2i_ep
->cm_sk
);
1941 /* wait for option-2 conn teardown */
1942 wait_event_interruptible(bnx2i_ep
->ofld_wait
,
1943 bnx2i_ep
->state
!= EP_STATE_DISCONN_START
);
1945 if (signal_pending(current
))
1946 flush_signals(current
);
1947 del_timer_sync(&bnx2i_ep
->ofld_timer
);
1950 if (bnx2i_tear_down_conn(hba
, bnx2i_ep
)) {
1951 mutex_unlock(&hba
->net_dev_lock
);
1955 mutex_unlock(&hba
->net_dev_lock
);
1956 bnx2i_free_qp_resc(hba
, bnx2i_ep
);
1959 bnx2i_conn
->ep
= NULL
;
1963 if (!hba
->ofld_conns_active
)
1964 bnx2i_unreg_dev_all();
1966 wake_up_interruptible(&hba
->eh_wait
);
1971 * bnx2i_nl_set_path - ISCSI_UEVENT_PATH_UPDATE user message handler
1972 * @buf: pointer to buffer containing iscsi path message
1975 static int bnx2i_nl_set_path(struct Scsi_Host
*shost
, struct iscsi_path
*params
)
1977 struct bnx2i_hba
*hba
= iscsi_host_priv(shost
);
1978 char *buf
= (char *) params
;
1979 u16 len
= sizeof(*params
);
1981 /* handled by cnic driver */
1982 hba
->cnic
->iscsi_nl_msg_recv(hba
->cnic
, ISCSI_UEVENT_PATH_UPDATE
, buf
,
1990 * 'Scsi_Host_Template' structure and 'iscsi_tranport' structure template
1991 * used while registering with the scsi host and iSCSI transport module.
1993 static struct scsi_host_template bnx2i_host_template
= {
1994 .module
= THIS_MODULE
,
1995 .name
= "Broadcom Offload iSCSI Initiator",
1996 .proc_name
= "bnx2i",
1997 .queuecommand
= iscsi_queuecommand
,
1998 .eh_abort_handler
= iscsi_eh_abort
,
1999 .eh_device_reset_handler
= iscsi_eh_device_reset
,
2000 .eh_target_reset_handler
= iscsi_eh_recover_target
,
2001 .change_queue_depth
= iscsi_change_queue_depth
,
2006 .use_clustering
= ENABLE_CLUSTERING
,
2007 .sg_tablesize
= ISCSI_MAX_BDS_PER_CMD
,
2008 .shost_attrs
= bnx2i_dev_attributes
,
2011 struct iscsi_transport bnx2i_iscsi_transport
= {
2012 .owner
= THIS_MODULE
,
2014 .caps
= CAP_RECOVERY_L0
| CAP_HDRDGST
|
2015 CAP_MULTI_R2T
| CAP_DATADGST
|
2016 CAP_DATA_PATH_OFFLOAD
,
2017 .param_mask
= ISCSI_MAX_RECV_DLENGTH
|
2018 ISCSI_MAX_XMIT_DLENGTH
|
2021 ISCSI_INITIAL_R2T_EN
|
2026 ISCSI_PDU_INORDER_EN
|
2027 ISCSI_DATASEQ_INORDER_EN
|
2030 ISCSI_CONN_ADDRESS
|
2032 ISCSI_PERSISTENT_PORT
|
2033 ISCSI_PERSISTENT_ADDRESS
|
2034 ISCSI_TARGET_NAME
| ISCSI_TPGT
|
2035 ISCSI_USERNAME
| ISCSI_PASSWORD
|
2036 ISCSI_USERNAME_IN
| ISCSI_PASSWORD_IN
|
2037 ISCSI_FAST_ABORT
| ISCSI_ABORT_TMO
|
2038 ISCSI_LU_RESET_TMO
| ISCSI_TGT_RESET_TMO
|
2039 ISCSI_PING_TMO
| ISCSI_RECV_TMO
|
2040 ISCSI_IFACE_NAME
| ISCSI_INITIATOR_NAME
,
2041 .host_param_mask
= ISCSI_HOST_HWADDRESS
| ISCSI_HOST_NETDEV_NAME
,
2042 .create_session
= bnx2i_session_create
,
2043 .destroy_session
= bnx2i_session_destroy
,
2044 .create_conn
= bnx2i_conn_create
,
2045 .bind_conn
= bnx2i_conn_bind
,
2046 .destroy_conn
= bnx2i_conn_destroy
,
2047 .set_param
= iscsi_set_param
,
2048 .get_conn_param
= bnx2i_conn_get_param
,
2049 .get_session_param
= iscsi_session_get_param
,
2050 .get_host_param
= bnx2i_host_get_param
,
2051 .start_conn
= bnx2i_conn_start
,
2052 .stop_conn
= iscsi_conn_stop
,
2053 .send_pdu
= iscsi_conn_send_pdu
,
2054 .xmit_task
= bnx2i_task_xmit
,
2055 .get_stats
= bnx2i_conn_get_stats
,
2056 /* TCP connect - disconnect - option-2 interface calls */
2057 .ep_connect
= bnx2i_ep_connect
,
2058 .ep_poll
= bnx2i_ep_poll
,
2059 .ep_disconnect
= bnx2i_ep_disconnect
,
2060 .set_path
= bnx2i_nl_set_path
,
2061 /* Error recovery timeout call */
2062 .session_recovery_timedout
= iscsi_session_recovery_timedout
,
2063 .cleanup_task
= bnx2i_cleanup_task
,