2 * bnx2i_iscsi.c: Broadcom NetXtreme II iSCSI driver.
4 * Copyright (c) 2006 - 2010 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)
13 * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
16 #include <linux/slab.h>
17 #include <scsi/scsi_tcq.h>
18 #include <scsi/libiscsi.h>
21 struct scsi_transport_template *bnx2i_scsi_xport_template;
22 struct iscsi_transport bnx2i_iscsi_transport;
23 static struct scsi_host_template bnx2i_host_template;
26 * Global endpoint resource info
28 static DEFINE_SPINLOCK(bnx2i_resc_lock); /* protects global resources */
31 static int bnx2i_adapter_ready(struct bnx2i_hba *hba)
35 if (!hba || !test_bit(ADAPTER_STATE_UP, &hba->adapter_state) ||
36 test_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state) ||
37 test_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state))
43 * bnx2i_get_write_cmd_bd_idx - identifies various BD bookmarks
44 * @cmd: iscsi cmd struct pointer
45 * @buf_off: absolute buffer offset
46 * @start_bd_off: u32 pointer to return the offset within the BD
47 * indicated by 'start_bd_idx' on which 'buf_off' falls
48 * @start_bd_idx: index of the BD on which 'buf_off' falls
50 * identifies & marks various bd info for scsi command's imm data,
51 * unsolicited data and the first solicited data seq.
53 static void bnx2i_get_write_cmd_bd_idx(struct bnx2i_cmd *cmd, u32 buf_off,
54 u32 *start_bd_off, u32 *start_bd_idx)
56 struct iscsi_bd *bd_tbl = cmd->io_tbl.bd_tbl;
61 while (buf_off >= (cur_offset + bd_tbl->buffer_length)) {
62 cur_offset += bd_tbl->buffer_length;
68 *start_bd_off = buf_off - cur_offset;
69 *start_bd_idx = cur_bd_idx;
73 * bnx2i_setup_write_cmd_bd_info - sets up BD various information
74 * @task: transport layer's cmd struct pointer
76 * identifies & marks various bd info for scsi command's immediate data,
77 * unsolicited data and first solicited data seq which includes BD start
78 * index & BD buf off. his function takes into account iscsi parameter such
79 * as immediate data and unsolicited data is support on this connection.
81 static void bnx2i_setup_write_cmd_bd_info(struct iscsi_task *task)
83 struct bnx2i_cmd *cmd = task->dd_data;
86 u32 buffer_offset = 0;
87 u32 cmd_len = cmd->req.total_data_transfer_length;
89 /* if ImmediateData is turned off & IntialR2T is turned on,
90 * there will be no immediate or unsolicited data, just return.
92 if (!iscsi_task_has_unsol_data(task) && !task->imm_count)
96 buffer_offset += task->imm_count;
97 if (task->imm_count == cmd_len)
100 if (iscsi_task_has_unsol_data(task)) {
101 bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset,
102 &start_bd_offset, &start_bd_idx);
103 cmd->req.ud_buffer_offset = start_bd_offset;
104 cmd->req.ud_start_bd_index = start_bd_idx;
105 buffer_offset += task->unsol_r2t.data_length;
108 if (buffer_offset != cmd_len) {
109 bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset,
110 &start_bd_offset, &start_bd_idx);
111 if ((start_bd_offset > task->conn->session->first_burst) ||
112 (start_bd_idx > scsi_sg_count(cmd->scsi_cmd))) {
115 iscsi_conn_printk(KERN_ALERT, task->conn,
116 "bnx2i- error, buf offset 0x%x "
117 "bd_valid %d use_sg %d\n",
118 buffer_offset, cmd->io_tbl.bd_valid,
119 scsi_sg_count(cmd->scsi_cmd));
120 for (i = 0; i < cmd->io_tbl.bd_valid; i++)
121 iscsi_conn_printk(KERN_ALERT, task->conn,
122 "bnx2i err, bd[%d]: len %x\n",
123 i, cmd->io_tbl.bd_tbl[i].\
126 cmd->req.sd_buffer_offset = start_bd_offset;
127 cmd->req.sd_start_bd_index = start_bd_idx;
134 * bnx2i_map_scsi_sg - maps IO buffer and prepares the BD table
135 * @hba: adapter instance
136 * @cmd: iscsi cmd struct pointer
140 static int bnx2i_map_scsi_sg(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
142 struct scsi_cmnd *sc = cmd->scsi_cmd;
143 struct iscsi_bd *bd = cmd->io_tbl.bd_tbl;
144 struct scatterlist *sg;
152 BUG_ON(scsi_sg_count(sc) > ISCSI_MAX_BDS_PER_CMD);
154 sg_count = scsi_dma_map(sc);
156 scsi_for_each_sg(sc, sg, sg_count, i) {
157 sg_len = sg_dma_len(sg);
158 addr = (u64) sg_dma_address(sg);
159 bd[bd_count].buffer_addr_lo = addr & 0xffffffff;
160 bd[bd_count].buffer_addr_hi = addr >> 32;
161 bd[bd_count].buffer_length = sg_len;
162 bd[bd_count].flags = 0;
164 bd[bd_count].flags = ISCSI_BD_FIRST_IN_BD_CHAIN;
166 byte_count += sg_len;
171 bd[bd_count - 1].flags |= ISCSI_BD_LAST_IN_BD_CHAIN;
173 BUG_ON(byte_count != scsi_bufflen(sc));
178 * bnx2i_iscsi_map_sg_list - maps SG list
179 * @cmd: iscsi cmd struct pointer
181 * creates BD list table for the command
183 static void bnx2i_iscsi_map_sg_list(struct bnx2i_cmd *cmd)
187 bd_count = bnx2i_map_scsi_sg(cmd->conn->hba, cmd);
189 struct iscsi_bd *bd = cmd->io_tbl.bd_tbl;
191 bd[0].buffer_addr_lo = bd[0].buffer_addr_hi = 0;
192 bd[0].buffer_length = bd[0].flags = 0;
194 cmd->io_tbl.bd_valid = bd_count;
199 * bnx2i_iscsi_unmap_sg_list - unmaps SG list
200 * @cmd: iscsi cmd struct pointer
202 * unmap IO buffers and invalidate the BD table
204 void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd)
206 struct scsi_cmnd *sc = cmd->scsi_cmd;
208 if (cmd->io_tbl.bd_valid && sc) {
210 cmd->io_tbl.bd_valid = 0;
214 static void bnx2i_setup_cmd_wqe_template(struct bnx2i_cmd *cmd)
216 memset(&cmd->req, 0x00, sizeof(cmd->req));
217 cmd->req.op_code = 0xFF;
218 cmd->req.bd_list_addr_lo = (u32) cmd->io_tbl.bd_tbl_dma;
219 cmd->req.bd_list_addr_hi =
220 (u32) ((u64) cmd->io_tbl.bd_tbl_dma >> 32);
226 * bnx2i_bind_conn_to_iscsi_cid - bind conn structure to 'iscsi_cid'
227 * @hba: pointer to adapter instance
228 * @conn: pointer to iscsi connection
229 * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
231 * update iscsi cid table entry with connection pointer. This enables
232 * driver to quickly get hold of connection structure pointer in
233 * completion/interrupt thread using iscsi context ID
235 static int bnx2i_bind_conn_to_iscsi_cid(struct bnx2i_hba *hba,
236 struct bnx2i_conn *bnx2i_conn,
239 if (hba && hba->cid_que.conn_cid_tbl[iscsi_cid]) {
240 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
241 "conn bind - entry #%d not free\n", iscsi_cid);
245 hba->cid_que.conn_cid_tbl[iscsi_cid] = bnx2i_conn;
251 * bnx2i_get_conn_from_id - maps an iscsi cid to corresponding conn ptr
252 * @hba: pointer to adapter instance
253 * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
255 struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba,
258 if (!hba->cid_que.conn_cid_tbl) {
259 printk(KERN_ERR "bnx2i: ERROR - missing conn<->cid table\n");
262 } else if (iscsi_cid >= hba->max_active_conns) {
263 printk(KERN_ERR "bnx2i: wrong cid #%d\n", iscsi_cid);
266 return hba->cid_que.conn_cid_tbl[iscsi_cid];
271 * bnx2i_alloc_iscsi_cid - allocates a iscsi_cid from free pool
272 * @hba: pointer to adapter instance
274 static u32 bnx2i_alloc_iscsi_cid(struct bnx2i_hba *hba)
278 if (!hba->cid_que.cid_free_cnt)
281 idx = hba->cid_que.cid_q_cons_idx;
282 hba->cid_que.cid_q_cons_idx++;
283 if (hba->cid_que.cid_q_cons_idx == hba->cid_que.cid_q_max_idx)
284 hba->cid_que.cid_q_cons_idx = 0;
286 hba->cid_que.cid_free_cnt--;
287 return hba->cid_que.cid_que[idx];
292 * bnx2i_free_iscsi_cid - returns tcp port to free list
293 * @hba: pointer to adapter instance
294 * @iscsi_cid: iscsi context ID to free
296 static void bnx2i_free_iscsi_cid(struct bnx2i_hba *hba, u16 iscsi_cid)
300 if (iscsi_cid == (u16) -1)
303 hba->cid_que.cid_free_cnt++;
305 idx = hba->cid_que.cid_q_prod_idx;
306 hba->cid_que.cid_que[idx] = iscsi_cid;
307 hba->cid_que.conn_cid_tbl[iscsi_cid] = NULL;
308 hba->cid_que.cid_q_prod_idx++;
309 if (hba->cid_que.cid_q_prod_idx == hba->cid_que.cid_q_max_idx)
310 hba->cid_que.cid_q_prod_idx = 0;
315 * bnx2i_setup_free_cid_que - sets up free iscsi cid queue
316 * @hba: pointer to adapter instance
318 * allocates memory for iscsi cid queue & 'cid - conn ptr' mapping table,
319 * and initialize table attributes
321 static int bnx2i_setup_free_cid_que(struct bnx2i_hba *hba)
326 mem_size = hba->max_active_conns * sizeof(u32);
327 mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
329 hba->cid_que.cid_que_base = kmalloc(mem_size, GFP_KERNEL);
330 if (!hba->cid_que.cid_que_base)
333 mem_size = hba->max_active_conns * sizeof(struct bnx2i_conn *);
334 mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
335 hba->cid_que.conn_cid_tbl = kmalloc(mem_size, GFP_KERNEL);
336 if (!hba->cid_que.conn_cid_tbl) {
337 kfree(hba->cid_que.cid_que_base);
338 hba->cid_que.cid_que_base = NULL;
342 hba->cid_que.cid_que = (u32 *)hba->cid_que.cid_que_base;
343 hba->cid_que.cid_q_prod_idx = 0;
344 hba->cid_que.cid_q_cons_idx = 0;
345 hba->cid_que.cid_q_max_idx = hba->max_active_conns;
346 hba->cid_que.cid_free_cnt = hba->max_active_conns;
348 for (i = 0; i < hba->max_active_conns; i++) {
349 hba->cid_que.cid_que[i] = i;
350 hba->cid_que.conn_cid_tbl[i] = NULL;
357 * bnx2i_release_free_cid_que - releases 'iscsi_cid' queue resources
358 * @hba: pointer to adapter instance
360 static void bnx2i_release_free_cid_que(struct bnx2i_hba *hba)
362 kfree(hba->cid_que.cid_que_base);
363 hba->cid_que.cid_que_base = NULL;
365 kfree(hba->cid_que.conn_cid_tbl);
366 hba->cid_que.conn_cid_tbl = NULL;
371 * bnx2i_alloc_ep - allocates ep structure from global pool
372 * @hba: pointer to adapter instance
374 * routine allocates a free endpoint structure from global pool and
375 * a tcp port to be used for this connection. Global resource lock,
376 * 'bnx2i_resc_lock' is held while accessing shared global data structures
378 static struct iscsi_endpoint *bnx2i_alloc_ep(struct bnx2i_hba *hba)
380 struct iscsi_endpoint *ep;
381 struct bnx2i_endpoint *bnx2i_ep;
383 ep = iscsi_create_endpoint(sizeof(*bnx2i_ep));
385 printk(KERN_ERR "bnx2i: Could not allocate ep\n");
389 bnx2i_ep = ep->dd_data;
390 bnx2i_ep->cls_ep = ep;
391 INIT_LIST_HEAD(&bnx2i_ep->link);
392 bnx2i_ep->state = EP_STATE_IDLE;
393 bnx2i_ep->ep_iscsi_cid = (u16) -1;
395 bnx2i_ep->hba_age = hba->age;
396 hba->ofld_conns_active++;
397 init_waitqueue_head(&bnx2i_ep->ofld_wait);
403 * bnx2i_free_ep - free endpoint
404 * @ep: pointer to iscsi endpoint structure
406 static void bnx2i_free_ep(struct iscsi_endpoint *ep)
408 struct bnx2i_endpoint *bnx2i_ep = ep->dd_data;
411 spin_lock_irqsave(&bnx2i_resc_lock, flags);
412 bnx2i_ep->state = EP_STATE_IDLE;
413 bnx2i_ep->hba->ofld_conns_active--;
415 if (bnx2i_ep->ep_iscsi_cid != (u16) -1)
416 bnx2i_free_iscsi_cid(bnx2i_ep->hba, bnx2i_ep->ep_iscsi_cid);
418 if (bnx2i_ep->conn) {
419 bnx2i_ep->conn->ep = NULL;
420 bnx2i_ep->conn = NULL;
423 bnx2i_ep->hba = NULL;
424 spin_unlock_irqrestore(&bnx2i_resc_lock, flags);
425 iscsi_destroy_endpoint(ep);
430 * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command
431 * @hba: adapter instance pointer
432 * @session: iscsi session pointer
433 * @cmd: iscsi command structure
435 static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct iscsi_session *session,
436 struct bnx2i_cmd *cmd)
438 struct io_bdt *io = &cmd->io_tbl;
441 io->bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
442 ISCSI_MAX_BDS_PER_CMD * sizeof(*bd),
443 &io->bd_tbl_dma, GFP_KERNEL);
445 iscsi_session_printk(KERN_ERR, session, "Could not "
454 * bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table
455 * @hba: adapter instance pointer
456 * @session: iscsi session pointer
457 * @cmd: iscsi command structure
459 static void bnx2i_destroy_cmd_pool(struct bnx2i_hba *hba,
460 struct iscsi_session *session)
464 for (i = 0; i < session->cmds_max; i++) {
465 struct iscsi_task *task = session->cmds[i];
466 struct bnx2i_cmd *cmd = task->dd_data;
468 if (cmd->io_tbl.bd_tbl)
469 dma_free_coherent(&hba->pcidev->dev,
470 ISCSI_MAX_BDS_PER_CMD *
471 sizeof(struct iscsi_bd),
473 cmd->io_tbl.bd_tbl_dma);
480 * bnx2i_setup_cmd_pool - sets up iscsi command pool for the session
481 * @hba: adapter instance pointer
482 * @session: iscsi session pointer
484 static int bnx2i_setup_cmd_pool(struct bnx2i_hba *hba,
485 struct iscsi_session *session)
489 for (i = 0; i < session->cmds_max; i++) {
490 struct iscsi_task *task = session->cmds[i];
491 struct bnx2i_cmd *cmd = task->dd_data;
493 task->hdr = &cmd->hdr;
494 task->hdr_max = sizeof(struct iscsi_hdr);
496 if (bnx2i_alloc_bdt(hba, session, cmd))
503 bnx2i_destroy_cmd_pool(hba, session);
509 * bnx2i_setup_mp_bdt - allocate BD table resources
510 * @hba: pointer to adapter structure
512 * Allocate memory for dummy buffer and associated BD
513 * table to be used by middle path (MP) requests
515 static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
518 struct iscsi_bd *mp_bdt;
521 hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
522 &hba->mp_bd_dma, GFP_KERNEL);
523 if (!hba->mp_bd_tbl) {
524 printk(KERN_ERR "unable to allocate Middle Path BDT\n");
529 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
530 &hba->dummy_buf_dma, GFP_KERNEL);
531 if (!hba->dummy_buffer) {
532 printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n");
533 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
534 hba->mp_bd_tbl, hba->mp_bd_dma);
535 hba->mp_bd_tbl = NULL;
540 mp_bdt = (struct iscsi_bd *) hba->mp_bd_tbl;
541 addr = (unsigned long) hba->dummy_buf_dma;
542 mp_bdt->buffer_addr_lo = addr & 0xffffffff;
543 mp_bdt->buffer_addr_hi = addr >> 32;
544 mp_bdt->buffer_length = PAGE_SIZE;
545 mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
546 ISCSI_BD_FIRST_IN_BD_CHAIN;
553 * bnx2i_free_mp_bdt - releases ITT back to free pool
554 * @hba: pointer to adapter instance
556 * free MP dummy buffer and associated BD table
558 static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba)
560 if (hba->mp_bd_tbl) {
561 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
562 hba->mp_bd_tbl, hba->mp_bd_dma);
563 hba->mp_bd_tbl = NULL;
565 if (hba->dummy_buffer) {
566 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
567 hba->dummy_buffer, hba->dummy_buf_dma);
568 hba->dummy_buffer = NULL;
574 * bnx2i_drop_session - notifies iscsid of connection error.
575 * @hba: adapter instance pointer
576 * @session: iscsi session pointer
578 * This notifies iscsid that there is a error, so it can initiate
581 * This relies on caller using the iscsi class iterator so the object
582 * is refcounted and does not disapper from under us.
584 void bnx2i_drop_session(struct iscsi_cls_session *cls_session)
586 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
590 * bnx2i_ep_destroy_list_add - add an entry to EP destroy list
591 * @hba: pointer to adapter instance
592 * @ep: pointer to endpoint (transport indentifier) structure
594 * EP destroy queue manager
596 static int bnx2i_ep_destroy_list_add(struct bnx2i_hba *hba,
597 struct bnx2i_endpoint *ep)
599 write_lock_bh(&hba->ep_rdwr_lock);
600 list_add_tail(&ep->link, &hba->ep_destroy_list);
601 write_unlock_bh(&hba->ep_rdwr_lock);
606 * bnx2i_ep_destroy_list_del - add an entry to EP destroy list
608 * @hba: pointer to adapter instance
609 * @ep: pointer to endpoint (transport indentifier) structure
611 * EP destroy queue manager
613 static int bnx2i_ep_destroy_list_del(struct bnx2i_hba *hba,
614 struct bnx2i_endpoint *ep)
616 write_lock_bh(&hba->ep_rdwr_lock);
617 list_del_init(&ep->link);
618 write_unlock_bh(&hba->ep_rdwr_lock);
624 * bnx2i_ep_ofld_list_add - add an entry to ep offload pending list
625 * @hba: pointer to adapter instance
626 * @ep: pointer to endpoint (transport indentifier) structure
628 * pending conn offload completion queue manager
630 static int bnx2i_ep_ofld_list_add(struct bnx2i_hba *hba,
631 struct bnx2i_endpoint *ep)
633 write_lock_bh(&hba->ep_rdwr_lock);
634 list_add_tail(&ep->link, &hba->ep_ofld_list);
635 write_unlock_bh(&hba->ep_rdwr_lock);
640 * bnx2i_ep_ofld_list_del - add an entry to ep offload pending list
641 * @hba: pointer to adapter instance
642 * @ep: pointer to endpoint (transport indentifier) structure
644 * pending conn offload completion queue manager
646 static int bnx2i_ep_ofld_list_del(struct bnx2i_hba *hba,
647 struct bnx2i_endpoint *ep)
649 write_lock_bh(&hba->ep_rdwr_lock);
650 list_del_init(&ep->link);
651 write_unlock_bh(&hba->ep_rdwr_lock);
657 * bnx2i_find_ep_in_ofld_list - find iscsi_cid in pending list of endpoints
659 * @hba: pointer to adapter instance
660 * @iscsi_cid: iscsi context ID to find
663 struct bnx2i_endpoint *
664 bnx2i_find_ep_in_ofld_list(struct bnx2i_hba *hba, u32 iscsi_cid)
666 struct list_head *list;
667 struct list_head *tmp;
668 struct bnx2i_endpoint *ep;
670 read_lock_bh(&hba->ep_rdwr_lock);
671 list_for_each_safe(list, tmp, &hba->ep_ofld_list) {
672 ep = (struct bnx2i_endpoint *)list;
674 if (ep->ep_iscsi_cid == iscsi_cid)
678 read_unlock_bh(&hba->ep_rdwr_lock);
681 printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid);
686 * bnx2i_find_ep_in_destroy_list - find iscsi_cid in destroy list
687 * @hba: pointer to adapter instance
688 * @iscsi_cid: iscsi context ID to find
691 struct bnx2i_endpoint *
692 bnx2i_find_ep_in_destroy_list(struct bnx2i_hba *hba, u32 iscsi_cid)
694 struct list_head *list;
695 struct list_head *tmp;
696 struct bnx2i_endpoint *ep;
698 read_lock_bh(&hba->ep_rdwr_lock);
699 list_for_each_safe(list, tmp, &hba->ep_destroy_list) {
700 ep = (struct bnx2i_endpoint *)list;
702 if (ep->ep_iscsi_cid == iscsi_cid)
706 read_unlock_bh(&hba->ep_rdwr_lock);
709 printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid);
715 * bnx2i_ep_active_list_add - add an entry to ep active list
716 * @hba: pointer to adapter instance
717 * @ep: pointer to endpoint (transport indentifier) structure
719 * current active conn queue manager
721 static void bnx2i_ep_active_list_add(struct bnx2i_hba *hba,
722 struct bnx2i_endpoint *ep)
724 write_lock_bh(&hba->ep_rdwr_lock);
725 list_add_tail(&ep->link, &hba->ep_active_list);
726 write_unlock_bh(&hba->ep_rdwr_lock);
731 * bnx2i_ep_active_list_del - deletes an entry to ep active list
732 * @hba: pointer to adapter instance
733 * @ep: pointer to endpoint (transport indentifier) structure
735 * current active conn queue manager
737 static void bnx2i_ep_active_list_del(struct bnx2i_hba *hba,
738 struct bnx2i_endpoint *ep)
740 write_lock_bh(&hba->ep_rdwr_lock);
741 list_del_init(&ep->link);
742 write_unlock_bh(&hba->ep_rdwr_lock);
747 * bnx2i_setup_host_queue_size - assigns shost->can_queue param
748 * @hba: pointer to adapter instance
749 * @shost: scsi host pointer
751 * Initializes 'can_queue' parameter based on how many outstanding commands
752 * the device can handle. Each device 5708/5709/57710 has different
755 static void bnx2i_setup_host_queue_size(struct bnx2i_hba *hba,
756 struct Scsi_Host *shost)
758 if (test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type))
759 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708;
760 else if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type))
761 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5709;
762 else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
763 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_57710;
765 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708;
770 * bnx2i_alloc_hba - allocate and init adapter instance
771 * @cnic: cnic device pointer
773 * allocate & initialize adapter structure and call other
774 * support routines to do per adapter initialization
776 struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic)
778 struct Scsi_Host *shost;
779 struct bnx2i_hba *hba;
781 shost = iscsi_host_alloc(&bnx2i_host_template, sizeof(*hba), 0);
784 shost->dma_boundary = cnic->pcidev->dma_mask;
785 shost->transportt = bnx2i_scsi_xport_template;
786 shost->max_id = ISCSI_MAX_CONNS_PER_HBA;
787 shost->max_channel = 0;
788 shost->max_lun = 512;
789 shost->max_cmd_len = 16;
791 hba = iscsi_host_priv(shost);
793 hba->netdev = cnic->netdev;
794 /* Get PCI related information and update hba struct members */
795 hba->pcidev = cnic->pcidev;
796 pci_dev_get(hba->pcidev);
797 hba->pci_did = hba->pcidev->device;
798 hba->pci_vid = hba->pcidev->vendor;
799 hba->pci_sdid = hba->pcidev->subsystem_device;
800 hba->pci_svid = hba->pcidev->subsystem_vendor;
801 hba->pci_func = PCI_FUNC(hba->pcidev->devfn);
802 hba->pci_devno = PCI_SLOT(hba->pcidev->devfn);
804 bnx2i_identify_device(hba);
805 bnx2i_setup_host_queue_size(hba, shost);
807 if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
808 hba->regview = ioremap_nocache(hba->netdev->base_addr,
812 } else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
813 hba->regview = ioremap_nocache(hba->netdev->base_addr, 4096);
818 if (bnx2i_setup_mp_bdt(hba))
821 INIT_LIST_HEAD(&hba->ep_ofld_list);
822 INIT_LIST_HEAD(&hba->ep_active_list);
823 INIT_LIST_HEAD(&hba->ep_destroy_list);
824 rwlock_init(&hba->ep_rdwr_lock);
826 hba->mtu_supported = BNX2I_MAX_MTU_SUPPORTED;
828 /* different values for 5708/5709/57710 */
829 hba->max_active_conns = ISCSI_MAX_CONNS_PER_HBA;
831 if (bnx2i_setup_free_cid_que(hba))
834 /* SQ/RQ/CQ size can be changed via sysfx interface */
835 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
836 if (sq_size && sq_size <= BNX2I_5770X_SQ_WQES_MAX)
837 hba->max_sqes = sq_size;
839 hba->max_sqes = BNX2I_5770X_SQ_WQES_DEFAULT;
840 } else { /* 5706/5708/5709 */
841 if (sq_size && sq_size <= BNX2I_570X_SQ_WQES_MAX)
842 hba->max_sqes = sq_size;
844 hba->max_sqes = BNX2I_570X_SQ_WQES_DEFAULT;
847 hba->max_rqes = rq_size;
848 hba->max_cqes = hba->max_sqes + rq_size;
849 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
850 if (hba->max_cqes > BNX2I_5770X_CQ_WQES_MAX)
851 hba->max_cqes = BNX2I_5770X_CQ_WQES_MAX;
852 } else if (hba->max_cqes > BNX2I_570X_CQ_WQES_MAX)
853 hba->max_cqes = BNX2I_570X_CQ_WQES_MAX;
855 hba->num_ccell = hba->max_sqes / 2;
857 spin_lock_init(&hba->lock);
858 mutex_init(&hba->net_dev_lock);
859 init_waitqueue_head(&hba->eh_wait);
860 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
861 hba->hba_shutdown_tmo = 20 * HZ;
862 hba->conn_teardown_tmo = 20 * HZ;
863 hba->conn_ctx_destroy_tmo = 6 * HZ;
864 } else { /* 5706/5708/5709 */
865 hba->hba_shutdown_tmo = 20 * HZ;
866 hba->conn_teardown_tmo = 10 * HZ;
867 hba->conn_ctx_destroy_tmo = 2 * HZ;
870 if (iscsi_host_add(shost, &hba->pcidev->dev))
875 bnx2i_release_free_cid_que(hba);
877 bnx2i_free_mp_bdt(hba);
880 iounmap(hba->regview);
884 pci_dev_put(hba->pcidev);
885 scsi_host_put(shost);
890 * bnx2i_free_hba- releases hba structure and resources held by the adapter
891 * @hba: pointer to adapter instance
893 * free adapter structure and call various cleanup routines.
895 void bnx2i_free_hba(struct bnx2i_hba *hba)
897 struct Scsi_Host *shost = hba->shost;
899 iscsi_host_remove(shost);
900 INIT_LIST_HEAD(&hba->ep_ofld_list);
901 INIT_LIST_HEAD(&hba->ep_active_list);
902 INIT_LIST_HEAD(&hba->ep_destroy_list);
903 pci_dev_put(hba->pcidev);
906 iounmap(hba->regview);
909 bnx2i_free_mp_bdt(hba);
910 bnx2i_release_free_cid_que(hba);
911 iscsi_host_free(shost);
915 * bnx2i_conn_free_login_resources - free DMA resources used for login process
916 * @hba: pointer to adapter instance
917 * @bnx2i_conn: iscsi connection pointer
919 * Login related resources, mostly BDT & payload DMA memory is freed
921 static void bnx2i_conn_free_login_resources(struct bnx2i_hba *hba,
922 struct bnx2i_conn *bnx2i_conn)
924 if (bnx2i_conn->gen_pdu.resp_bd_tbl) {
925 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
926 bnx2i_conn->gen_pdu.resp_bd_tbl,
927 bnx2i_conn->gen_pdu.resp_bd_dma);
928 bnx2i_conn->gen_pdu.resp_bd_tbl = NULL;
931 if (bnx2i_conn->gen_pdu.req_bd_tbl) {
932 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
933 bnx2i_conn->gen_pdu.req_bd_tbl,
934 bnx2i_conn->gen_pdu.req_bd_dma);
935 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
938 if (bnx2i_conn->gen_pdu.resp_buf) {
939 dma_free_coherent(&hba->pcidev->dev,
940 ISCSI_DEF_MAX_RECV_SEG_LEN,
941 bnx2i_conn->gen_pdu.resp_buf,
942 bnx2i_conn->gen_pdu.resp_dma_addr);
943 bnx2i_conn->gen_pdu.resp_buf = NULL;
946 if (bnx2i_conn->gen_pdu.req_buf) {
947 dma_free_coherent(&hba->pcidev->dev,
948 ISCSI_DEF_MAX_RECV_SEG_LEN,
949 bnx2i_conn->gen_pdu.req_buf,
950 bnx2i_conn->gen_pdu.req_dma_addr);
951 bnx2i_conn->gen_pdu.req_buf = NULL;
956 * bnx2i_conn_alloc_login_resources - alloc DMA resources for login/nop.
957 * @hba: pointer to adapter instance
958 * @bnx2i_conn: iscsi connection pointer
960 * Mgmt task DNA resources are allocated in this routine.
962 static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
963 struct bnx2i_conn *bnx2i_conn)
965 /* Allocate memory for login request/response buffers */
966 bnx2i_conn->gen_pdu.req_buf =
967 dma_alloc_coherent(&hba->pcidev->dev,
968 ISCSI_DEF_MAX_RECV_SEG_LEN,
969 &bnx2i_conn->gen_pdu.req_dma_addr,
971 if (bnx2i_conn->gen_pdu.req_buf == NULL)
972 goto login_req_buf_failure;
974 bnx2i_conn->gen_pdu.req_buf_size = 0;
975 bnx2i_conn->gen_pdu.req_wr_ptr = bnx2i_conn->gen_pdu.req_buf;
977 bnx2i_conn->gen_pdu.resp_buf =
978 dma_alloc_coherent(&hba->pcidev->dev,
979 ISCSI_DEF_MAX_RECV_SEG_LEN,
980 &bnx2i_conn->gen_pdu.resp_dma_addr,
982 if (bnx2i_conn->gen_pdu.resp_buf == NULL)
983 goto login_resp_buf_failure;
985 bnx2i_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
986 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf;
988 bnx2i_conn->gen_pdu.req_bd_tbl =
989 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
990 &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
991 if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL)
992 goto login_req_bd_tbl_failure;
994 bnx2i_conn->gen_pdu.resp_bd_tbl =
995 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
996 &bnx2i_conn->gen_pdu.resp_bd_dma,
998 if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL)
999 goto login_resp_bd_tbl_failure;
1003 login_resp_bd_tbl_failure:
1004 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1005 bnx2i_conn->gen_pdu.req_bd_tbl,
1006 bnx2i_conn->gen_pdu.req_bd_dma);
1007 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
1009 login_req_bd_tbl_failure:
1010 dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
1011 bnx2i_conn->gen_pdu.resp_buf,
1012 bnx2i_conn->gen_pdu.resp_dma_addr);
1013 bnx2i_conn->gen_pdu.resp_buf = NULL;
1014 login_resp_buf_failure:
1015 dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
1016 bnx2i_conn->gen_pdu.req_buf,
1017 bnx2i_conn->gen_pdu.req_dma_addr);
1018 bnx2i_conn->gen_pdu.req_buf = NULL;
1019 login_req_buf_failure:
1020 iscsi_conn_printk(KERN_ERR, bnx2i_conn->cls_conn->dd_data,
1021 "login resource alloc failed!!\n");
1028 * bnx2i_iscsi_prep_generic_pdu_bd - prepares BD table.
1029 * @bnx2i_conn: iscsi connection pointer
1031 * Allocates buffers and BD tables before shipping requests to cnic
1032 * for PDUs prepared by 'iscsid' daemon
1034 static void bnx2i_iscsi_prep_generic_pdu_bd(struct bnx2i_conn *bnx2i_conn)
1036 struct iscsi_bd *bd_tbl;
1038 bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.req_bd_tbl;
1040 bd_tbl->buffer_addr_hi =
1041 (u32) ((u64) bnx2i_conn->gen_pdu.req_dma_addr >> 32);
1042 bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.req_dma_addr;
1043 bd_tbl->buffer_length = bnx2i_conn->gen_pdu.req_wr_ptr -
1044 bnx2i_conn->gen_pdu.req_buf;
1045 bd_tbl->reserved0 = 0;
1046 bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
1047 ISCSI_BD_FIRST_IN_BD_CHAIN;
1049 bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.resp_bd_tbl;
1050 bd_tbl->buffer_addr_hi = (u64) bnx2i_conn->gen_pdu.resp_dma_addr >> 32;
1051 bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_dma_addr;
1052 bd_tbl->buffer_length = ISCSI_DEF_MAX_RECV_SEG_LEN;
1053 bd_tbl->reserved0 = 0;
1054 bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
1055 ISCSI_BD_FIRST_IN_BD_CHAIN;
1060 * bnx2i_iscsi_send_generic_request - called to send mgmt tasks.
1061 * @task: transport layer task pointer
1063 * called to transmit PDUs prepared by the 'iscsid' daemon. iSCSI login,
1064 * Nop-out and Logout requests flow through this path.
1066 static int bnx2i_iscsi_send_generic_request(struct iscsi_task *task)
1068 struct bnx2i_cmd *cmd = task->dd_data;
1069 struct bnx2i_conn *bnx2i_conn = cmd->conn;
1074 bnx2i_iscsi_prep_generic_pdu_bd(bnx2i_conn);
1075 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
1076 case ISCSI_OP_LOGIN:
1077 bnx2i_send_iscsi_login(bnx2i_conn, task);
1079 case ISCSI_OP_NOOP_OUT:
1080 data_len = bnx2i_conn->gen_pdu.req_buf_size;
1081 buf = bnx2i_conn->gen_pdu.req_buf;
1083 rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
1086 rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
1089 case ISCSI_OP_LOGOUT:
1090 rc = bnx2i_send_iscsi_logout(bnx2i_conn, task);
1092 case ISCSI_OP_SCSI_TMFUNC:
1093 rc = bnx2i_send_iscsi_tmf(bnx2i_conn, task);
1096 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1097 "send_gen: unsupported op 0x%x\n",
1104 /**********************************************************************
1106 **********************************************************************/
1109 * bnx2i_cpy_scsi_cdb - copies LUN & CDB fields in required format to sq wqe
1110 * @sc: SCSI-ML command pointer
1111 * @cmd: iscsi cmd pointer
1113 static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd *sc, struct bnx2i_cmd *cmd)
1121 int_to_scsilun(sc->device->lun, (struct scsi_lun *) scsi_lun);
1122 cmd->req.lun[0] = be32_to_cpu(scsi_lun[0]);
1123 cmd->req.lun[1] = be32_to_cpu(scsi_lun[1]);
1125 lpcnt = cmd->scsi_cmd->cmd_len / sizeof(dword);
1126 srcp = (u8 *) sc->cmnd;
1127 dstp = (u32 *) cmd->req.cdb;
1129 memcpy(&dword, (const void *) srcp, 4);
1130 *dstp = cpu_to_be32(dword);
1134 if (sc->cmd_len & 0x3) {
1135 dword = (u32) srcp[0] | ((u32) srcp[1] << 8);
1136 *dstp = cpu_to_be32(dword);
1140 static void bnx2i_cleanup_task(struct iscsi_task *task)
1142 struct iscsi_conn *conn = task->conn;
1143 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1144 struct bnx2i_hba *hba = bnx2i_conn->hba;
1147 * mgmt task or cmd was never sent to us to transmit.
1149 if (!task->sc || task->state == ISCSI_TASK_PENDING)
1152 * need to clean-up task context to claim dma buffers
1154 if (task->state == ISCSI_TASK_ABRT_TMF) {
1155 bnx2i_send_cmd_cleanup_req(hba, task->dd_data);
1157 spin_unlock_bh(&conn->session->lock);
1158 wait_for_completion_timeout(&bnx2i_conn->cmd_cleanup_cmpl,
1159 msecs_to_jiffies(ISCSI_CMD_CLEANUP_TIMEOUT));
1160 spin_lock_bh(&conn->session->lock);
1162 bnx2i_iscsi_unmap_sg_list(task->dd_data);
1166 * bnx2i_mtask_xmit - transmit mtask to chip for further processing
1167 * @conn: transport layer conn structure pointer
1168 * @task: transport layer command structure pointer
1171 bnx2i_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
1173 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1174 struct bnx2i_cmd *cmd = task->dd_data;
1176 memset(bnx2i_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
1178 bnx2i_setup_cmd_wqe_template(cmd);
1179 bnx2i_conn->gen_pdu.req_buf_size = task->data_count;
1180 if (task->data_count) {
1181 memcpy(bnx2i_conn->gen_pdu.req_buf, task->data,
1183 bnx2i_conn->gen_pdu.req_wr_ptr =
1184 bnx2i_conn->gen_pdu.req_buf + task->data_count;
1186 cmd->conn = conn->dd_data;
1187 cmd->scsi_cmd = NULL;
1188 return bnx2i_iscsi_send_generic_request(task);
1192 * bnx2i_task_xmit - transmit iscsi command to chip for further processing
1193 * @task: transport layer command structure pointer
1195 * maps SG buffers and send request to chip/firmware in the form of SQ WQE
1197 static int bnx2i_task_xmit(struct iscsi_task *task)
1199 struct iscsi_conn *conn = task->conn;
1200 struct iscsi_session *session = conn->session;
1201 struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session);
1202 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1203 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1204 struct scsi_cmnd *sc = task->sc;
1205 struct bnx2i_cmd *cmd = task->dd_data;
1206 struct iscsi_cmd *hdr = (struct iscsi_cmd *) task->hdr;
1209 * If there is no scsi_cmnd this must be a mgmt task
1212 return bnx2i_mtask_xmit(conn, task);
1214 bnx2i_setup_cmd_wqe_template(cmd);
1215 cmd->req.op_code = ISCSI_OP_SCSI_CMD;
1216 cmd->conn = bnx2i_conn;
1218 cmd->req.total_data_transfer_length = scsi_bufflen(sc);
1219 cmd->req.cmd_sn = be32_to_cpu(hdr->cmdsn);
1221 bnx2i_iscsi_map_sg_list(cmd);
1222 bnx2i_cpy_scsi_cdb(sc, cmd);
1224 cmd->req.op_attr = ISCSI_ATTR_SIMPLE;
1225 if (sc->sc_data_direction == DMA_TO_DEVICE) {
1226 cmd->req.op_attr |= ISCSI_CMD_REQUEST_WRITE;
1227 cmd->req.itt = task->itt |
1228 (ISCSI_TASK_TYPE_WRITE << ISCSI_CMD_REQUEST_TYPE_SHIFT);
1229 bnx2i_setup_write_cmd_bd_info(task);
1231 if (scsi_bufflen(sc))
1232 cmd->req.op_attr |= ISCSI_CMD_REQUEST_READ;
1233 cmd->req.itt = task->itt |
1234 (ISCSI_TASK_TYPE_READ << ISCSI_CMD_REQUEST_TYPE_SHIFT);
1237 cmd->req.num_bds = cmd->io_tbl.bd_valid;
1238 if (!cmd->io_tbl.bd_valid) {
1239 cmd->req.bd_list_addr_lo = (u32) hba->mp_bd_dma;
1240 cmd->req.bd_list_addr_hi = (u32) ((u64) hba->mp_bd_dma >> 32);
1241 cmd->req.num_bds = 1;
1244 bnx2i_send_iscsi_scsicmd(bnx2i_conn, cmd);
1249 * bnx2i_session_create - create a new iscsi session
1250 * @cmds_max: max commands supported
1251 * @qdepth: scsi queue depth to support
1252 * @initial_cmdsn: initial iscsi CMDSN to be used for this session
1254 * Creates a new iSCSI session instance on given device.
1256 static struct iscsi_cls_session *
1257 bnx2i_session_create(struct iscsi_endpoint *ep,
1258 uint16_t cmds_max, uint16_t qdepth,
1259 uint32_t initial_cmdsn)
1261 struct Scsi_Host *shost;
1262 struct iscsi_cls_session *cls_session;
1263 struct bnx2i_hba *hba;
1264 struct bnx2i_endpoint *bnx2i_ep;
1267 printk(KERN_ERR "bnx2i: missing ep.\n");
1271 bnx2i_ep = ep->dd_data;
1272 shost = bnx2i_ep->hba->shost;
1273 hba = iscsi_host_priv(shost);
1274 if (bnx2i_adapter_ready(hba))
1278 * user can override hw limit as long as it is within
1281 if (cmds_max > hba->max_sqes)
1282 cmds_max = hba->max_sqes;
1283 else if (cmds_max < BNX2I_SQ_WQES_MIN)
1284 cmds_max = BNX2I_SQ_WQES_MIN;
1286 cls_session = iscsi_session_setup(&bnx2i_iscsi_transport, shost,
1287 cmds_max, 0, sizeof(struct bnx2i_cmd),
1288 initial_cmdsn, ISCSI_MAX_TARGET);
1292 if (bnx2i_setup_cmd_pool(hba, cls_session->dd_data))
1293 goto session_teardown;
1297 iscsi_session_teardown(cls_session);
1303 * bnx2i_session_destroy - destroys iscsi session
1304 * @cls_session: pointer to iscsi cls session
1306 * Destroys previously created iSCSI session instance and releases
1307 * all resources held by it
1309 static void bnx2i_session_destroy(struct iscsi_cls_session *cls_session)
1311 struct iscsi_session *session = cls_session->dd_data;
1312 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1313 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1315 bnx2i_destroy_cmd_pool(hba, session);
1316 iscsi_session_teardown(cls_session);
1321 * bnx2i_conn_create - create iscsi connection instance
1322 * @cls_session: pointer to iscsi cls session
1323 * @cid: iscsi cid as per rfc (not NX2's CID terminology)
1325 * Creates a new iSCSI connection instance for a given session
1327 static struct iscsi_cls_conn *
1328 bnx2i_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
1330 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1331 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1332 struct bnx2i_conn *bnx2i_conn;
1333 struct iscsi_cls_conn *cls_conn;
1334 struct iscsi_conn *conn;
1336 cls_conn = iscsi_conn_setup(cls_session, sizeof(*bnx2i_conn),
1340 conn = cls_conn->dd_data;
1342 bnx2i_conn = conn->dd_data;
1343 bnx2i_conn->cls_conn = cls_conn;
1344 bnx2i_conn->hba = hba;
1345 /* 'ep' ptr will be assigned in bind() call */
1346 bnx2i_conn->ep = NULL;
1347 init_completion(&bnx2i_conn->cmd_cleanup_cmpl);
1349 if (bnx2i_conn_alloc_login_resources(hba, bnx2i_conn)) {
1350 iscsi_conn_printk(KERN_ALERT, conn,
1351 "conn_new: login resc alloc failed!!\n");
1358 iscsi_conn_teardown(cls_conn);
1363 * bnx2i_conn_bind - binds iscsi sess, conn and ep objects together
1364 * @cls_session: pointer to iscsi cls session
1365 * @cls_conn: pointer to iscsi cls conn
1366 * @transport_fd: 64-bit EP handle
1367 * @is_leading: leading connection on this session?
1369 * Binds together iSCSI session instance, iSCSI connection instance
1370 * and the TCP connection. This routine returns error code if
1371 * TCP connection does not belong on the device iSCSI sess/conn
1374 static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session,
1375 struct iscsi_cls_conn *cls_conn,
1376 uint64_t transport_fd, int is_leading)
1378 struct iscsi_conn *conn = cls_conn->dd_data;
1379 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1380 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1381 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1382 struct bnx2i_endpoint *bnx2i_ep;
1383 struct iscsi_endpoint *ep;
1386 ep = iscsi_lookup_endpoint(transport_fd);
1390 * Forcefully terminate all in progress connection recovery at the
1391 * earliest, either in bind(), send_pdu(LOGIN), or conn_start()
1393 if (bnx2i_adapter_ready(hba))
1396 bnx2i_ep = ep->dd_data;
1397 if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) ||
1398 (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD))
1399 /* Peer disconnect via' FIN or RST */
1402 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1405 if (bnx2i_ep->hba != hba) {
1406 /* Error - TCP connection does not belong to this device
1408 iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
1409 "conn bind, ep=0x%p (%s) does not",
1410 bnx2i_ep, bnx2i_ep->hba->netdev->name);
1411 iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
1412 "belong to hba (%s)\n",
1416 bnx2i_ep->conn = bnx2i_conn;
1417 bnx2i_conn->ep = bnx2i_ep;
1418 bnx2i_conn->iscsi_conn_cid = bnx2i_ep->ep_iscsi_cid;
1419 bnx2i_conn->fw_cid = bnx2i_ep->ep_cid;
1421 ret_code = bnx2i_bind_conn_to_iscsi_cid(hba, bnx2i_conn,
1422 bnx2i_ep->ep_iscsi_cid);
1424 /* 5706/5708/5709 FW takes RQ as full when initiated, but for 57710
1425 * driver needs to explicitly replenish RQ index during setup.
1427 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
1428 bnx2i_put_rq_buf(bnx2i_conn, 0);
1430 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1436 * bnx2i_conn_destroy - destroy iscsi connection instance & release resources
1437 * @cls_conn: pointer to iscsi cls conn
1439 * Destroy an iSCSI connection instance and release memory resources held by
1442 static void bnx2i_conn_destroy(struct iscsi_cls_conn *cls_conn)
1444 struct iscsi_conn *conn = cls_conn->dd_data;
1445 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1446 struct Scsi_Host *shost;
1447 struct bnx2i_hba *hba;
1449 shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
1450 hba = iscsi_host_priv(shost);
1452 bnx2i_conn_free_login_resources(hba, bnx2i_conn);
1453 iscsi_conn_teardown(cls_conn);
1458 * bnx2i_conn_get_param - return iscsi connection parameter to caller
1459 * @cls_conn: pointer to iscsi cls conn
1460 * @param: parameter type identifier
1461 * @buf: buffer pointer
1463 * returns iSCSI connection parameters
1465 static int bnx2i_conn_get_param(struct iscsi_cls_conn *cls_conn,
1466 enum iscsi_param param, char *buf)
1468 struct iscsi_conn *conn = cls_conn->dd_data;
1469 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1472 if (!(bnx2i_conn && bnx2i_conn->ep && bnx2i_conn->ep->hba))
1476 case ISCSI_PARAM_CONN_PORT:
1477 mutex_lock(&bnx2i_conn->ep->hba->net_dev_lock);
1478 if (bnx2i_conn->ep->cm_sk)
1479 len = sprintf(buf, "%hu\n",
1480 bnx2i_conn->ep->cm_sk->dst_port);
1481 mutex_unlock(&bnx2i_conn->ep->hba->net_dev_lock);
1483 case ISCSI_PARAM_CONN_ADDRESS:
1484 mutex_lock(&bnx2i_conn->ep->hba->net_dev_lock);
1485 if (bnx2i_conn->ep->cm_sk)
1486 len = sprintf(buf, "%pI4\n",
1487 &bnx2i_conn->ep->cm_sk->dst_ip);
1488 mutex_unlock(&bnx2i_conn->ep->hba->net_dev_lock);
1491 return iscsi_conn_get_param(cls_conn, param, buf);
1498 * bnx2i_host_get_param - returns host (adapter) related parameters
1499 * @shost: scsi host pointer
1500 * @param: parameter type identifier
1501 * @buf: buffer pointer
1503 static int bnx2i_host_get_param(struct Scsi_Host *shost,
1504 enum iscsi_host_param param, char *buf)
1506 struct bnx2i_hba *hba = iscsi_host_priv(shost);
1510 case ISCSI_HOST_PARAM_HWADDRESS:
1511 len = sysfs_format_mac(buf, hba->cnic->mac_addr, 6);
1513 case ISCSI_HOST_PARAM_NETDEV_NAME:
1514 len = sprintf(buf, "%s\n", hba->netdev->name);
1516 case ISCSI_HOST_PARAM_IPADDRESS: {
1517 struct list_head *active_list = &hba->ep_active_list;
1519 read_lock_bh(&hba->ep_rdwr_lock);
1520 if (!list_empty(&hba->ep_active_list)) {
1521 struct bnx2i_endpoint *bnx2i_ep;
1522 struct cnic_sock *csk;
1524 bnx2i_ep = list_first_entry(active_list,
1525 struct bnx2i_endpoint,
1527 csk = bnx2i_ep->cm_sk;
1528 if (test_bit(SK_F_IPV6, &csk->flags))
1529 len = sprintf(buf, "%pI6\n", csk->src_ip);
1531 len = sprintf(buf, "%pI4\n", csk->src_ip);
1533 read_unlock_bh(&hba->ep_rdwr_lock);
1537 return iscsi_host_get_param(shost, param, buf);
1543 * bnx2i_conn_start - completes iscsi connection migration to FFP
1544 * @cls_conn: pointer to iscsi cls conn
1546 * last call in FFP migration to handover iscsi conn to the driver
1548 static int bnx2i_conn_start(struct iscsi_cls_conn *cls_conn)
1550 struct iscsi_conn *conn = cls_conn->dd_data;
1551 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
1553 bnx2i_conn->ep->state = EP_STATE_ULP_UPDATE_START;
1554 bnx2i_update_iscsi_conn(conn);
1557 * this should normally not sleep for a long time so it should
1558 * not disrupt the caller.
1560 bnx2i_conn->ep->ofld_timer.expires = 1 * HZ + jiffies;
1561 bnx2i_conn->ep->ofld_timer.function = bnx2i_ep_ofld_timer;
1562 bnx2i_conn->ep->ofld_timer.data = (unsigned long) bnx2i_conn->ep;
1563 add_timer(&bnx2i_conn->ep->ofld_timer);
1564 /* update iSCSI context for this conn, wait for CNIC to complete */
1565 wait_event_interruptible(bnx2i_conn->ep->ofld_wait,
1566 bnx2i_conn->ep->state != EP_STATE_ULP_UPDATE_START);
1568 if (signal_pending(current))
1569 flush_signals(current);
1570 del_timer_sync(&bnx2i_conn->ep->ofld_timer);
1572 iscsi_conn_start(cls_conn);
1578 * bnx2i_conn_get_stats - returns iSCSI stats
1579 * @cls_conn: pointer to iscsi cls conn
1580 * @stats: pointer to iscsi statistic struct
1582 static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1583 struct iscsi_stats *stats)
1585 struct iscsi_conn *conn = cls_conn->dd_data;
1587 stats->txdata_octets = conn->txdata_octets;
1588 stats->rxdata_octets = conn->rxdata_octets;
1589 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
1590 stats->dataout_pdus = conn->dataout_pdus_cnt;
1591 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
1592 stats->datain_pdus = conn->datain_pdus_cnt;
1593 stats->r2t_pdus = conn->r2t_pdus_cnt;
1594 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
1595 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
1596 stats->custom_length = 3;
1597 strcpy(stats->custom[2].desc, "eh_abort_cnt");
1598 stats->custom[2].value = conn->eh_abort_cnt;
1599 stats->digest_err = 0;
1600 stats->timeout_err = 0;
1601 stats->custom_length = 0;
1606 * bnx2i_check_route - checks if target IP route belongs to one of NX2 devices
1607 * @dst_addr: target IP address
1609 * check if route resolves to BNX2 device
1611 static struct bnx2i_hba *bnx2i_check_route(struct sockaddr *dst_addr)
1613 struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
1614 struct bnx2i_hba *hba;
1615 struct cnic_dev *cnic = NULL;
1617 hba = get_adapter_list_head();
1618 if (hba && hba->cnic)
1619 cnic = hba->cnic->cm_select_dev(desti, CNIC_ULP_ISCSI);
1621 printk(KERN_ALERT "bnx2i: no route,"
1622 "can't connect using cnic\n");
1625 hba = bnx2i_find_hba_for_cnic(cnic);
1629 if (bnx2i_adapter_ready(hba)) {
1630 printk(KERN_ALERT "bnx2i: check route, hba not found\n");
1633 if (hba->netdev->mtu > hba->mtu_supported) {
1634 printk(KERN_ALERT "bnx2i: %s network i/f mtu is set to %d\n",
1635 hba->netdev->name, hba->netdev->mtu);
1636 printk(KERN_ALERT "bnx2i: iSCSI HBA can support mtu of %d\n",
1637 hba->mtu_supported);
1647 * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources
1648 * @hba: pointer to adapter instance
1649 * @ep: endpoint (transport indentifier) structure
1651 * destroys cm_sock structure and on chip iscsi context
1653 static int bnx2i_tear_down_conn(struct bnx2i_hba *hba,
1654 struct bnx2i_endpoint *ep)
1656 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic) && ep->cm_sk)
1657 hba->cnic->cm_destroy(ep->cm_sk);
1659 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type) &&
1660 ep->state == EP_STATE_DISCONN_TIMEDOUT) {
1661 if (ep->conn && ep->conn->cls_conn &&
1662 ep->conn->cls_conn->dd_data) {
1663 struct iscsi_conn *conn = ep->conn->cls_conn->dd_data;
1665 /* Must suspend all rx queue activity for this ep */
1666 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
1668 /* CONN_DISCONNECT timeout may or may not be an issue depending
1669 * on what transcribed in TCP layer, different targets behave
1672 printk(KERN_ALERT "bnx2i (%s): - WARN - CONN_DISCON timed out, "
1673 "please submit GRC Dump, NW/PCIe trace, "
1674 "driver msgs to developers for analysis\n",
1678 ep->state = EP_STATE_CLEANUP_START;
1679 init_timer(&ep->ofld_timer);
1680 ep->ofld_timer.expires = hba->conn_ctx_destroy_tmo + jiffies;
1681 ep->ofld_timer.function = bnx2i_ep_ofld_timer;
1682 ep->ofld_timer.data = (unsigned long) ep;
1683 add_timer(&ep->ofld_timer);
1685 bnx2i_ep_destroy_list_add(hba, ep);
1687 /* destroy iSCSI context, wait for it to complete */
1688 if (bnx2i_send_conn_destroy(hba, ep))
1689 ep->state = EP_STATE_CLEANUP_CMPL;
1691 wait_event_interruptible(ep->ofld_wait,
1692 (ep->state != EP_STATE_CLEANUP_START));
1694 if (signal_pending(current))
1695 flush_signals(current);
1696 del_timer_sync(&ep->ofld_timer);
1698 bnx2i_ep_destroy_list_del(hba, ep);
1700 if (ep->state != EP_STATE_CLEANUP_CMPL)
1701 /* should never happen */
1702 printk(KERN_ALERT "bnx2i - conn destroy failed\n");
1709 * bnx2i_ep_connect - establish TCP connection to target portal
1711 * @dst_addr: target IP address
1712 * @non_blocking: blocking or non-blocking call
1714 * this routine initiates the TCP/IP connection by invoking Option-2 i/f
1715 * with l5_core and the CNIC. This is a multi-step process of resolving
1716 * route to target, create a iscsi connection context, handshaking with
1717 * CNIC module to create/initialize the socket struct and finally
1718 * sending down option-2 request to complete TCP 3-way handshake
1720 static struct iscsi_endpoint *bnx2i_ep_connect(struct Scsi_Host *shost,
1721 struct sockaddr *dst_addr,
1724 u32 iscsi_cid = BNX2I_CID_RESERVED;
1725 struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
1726 struct sockaddr_in6 *desti6;
1727 struct bnx2i_endpoint *bnx2i_ep;
1728 struct bnx2i_hba *hba;
1729 struct cnic_dev *cnic;
1730 struct cnic_sockaddr saddr;
1731 struct iscsi_endpoint *ep;
1735 /* driver is given scsi host to work with */
1736 hba = iscsi_host_priv(shost);
1739 * check if the given destination can be reached through
1740 * a iscsi capable NetXtreme2 device
1742 hba = bnx2i_check_route(dst_addr);
1748 mutex_lock(&hba->net_dev_lock);
1750 if (bnx2i_adapter_ready(hba) || !hba->cid_que.cid_free_cnt) {
1755 ep = bnx2i_alloc_ep(hba);
1760 bnx2i_ep = ep->dd_data;
1762 bnx2i_ep->num_active_cmds = 0;
1763 iscsi_cid = bnx2i_alloc_iscsi_cid(hba);
1764 if (iscsi_cid == -1) {
1765 printk(KERN_ALERT "bnx2i (%s): alloc_ep - unable to allocate "
1766 "iscsi cid\n", hba->netdev->name);
1771 bnx2i_ep->hba_age = hba->age;
1773 rc = bnx2i_alloc_qp_resc(hba, bnx2i_ep);
1775 printk(KERN_ALERT "bnx2i (%s): ep_conn - alloc QP resc error"
1776 "\n", hba->netdev->name);
1781 bnx2i_ep->ep_iscsi_cid = (u16)iscsi_cid;
1782 bnx2i_ep->state = EP_STATE_OFLD_START;
1783 bnx2i_ep_ofld_list_add(hba, bnx2i_ep);
1785 init_timer(&bnx2i_ep->ofld_timer);
1786 bnx2i_ep->ofld_timer.expires = 2 * HZ + jiffies;
1787 bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
1788 bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
1789 add_timer(&bnx2i_ep->ofld_timer);
1791 if (bnx2i_send_conn_ofld_req(hba, bnx2i_ep)) {
1792 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) {
1793 printk(KERN_ALERT "bnx2i (%s): iscsi cid %d is busy\n",
1794 hba->netdev->name, bnx2i_ep->ep_iscsi_cid);
1798 printk(KERN_ALERT "bnx2i (%s): unable to send conn offld kwqe"
1799 "\n", hba->netdev->name);
1800 bnx2i_ep_ofld_list_del(hba, bnx2i_ep);
1804 /* Wait for CNIC hardware to setup conn context and return 'cid' */
1805 wait_event_interruptible(bnx2i_ep->ofld_wait,
1806 bnx2i_ep->state != EP_STATE_OFLD_START);
1808 if (signal_pending(current))
1809 flush_signals(current);
1810 del_timer_sync(&bnx2i_ep->ofld_timer);
1812 bnx2i_ep_ofld_list_del(hba, bnx2i_ep);
1814 if (bnx2i_ep->state != EP_STATE_OFLD_COMPL) {
1815 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) {
1816 printk(KERN_ALERT "bnx2i (%s): iscsi cid %d is busy\n",
1817 hba->netdev->name, bnx2i_ep->ep_iscsi_cid);
1824 rc = cnic->cm_create(cnic, CNIC_ULP_ISCSI, bnx2i_ep->ep_cid,
1825 iscsi_cid, &bnx2i_ep->cm_sk, bnx2i_ep);
1828 /* Need to terminate and cleanup the connection */
1832 bnx2i_ep->cm_sk->rcv_buf = 256 * 1024;
1833 bnx2i_ep->cm_sk->snd_buf = 256 * 1024;
1834 clear_bit(SK_TCP_TIMESTAMP, &bnx2i_ep->cm_sk->tcp_flags);
1836 memset(&saddr, 0, sizeof(saddr));
1837 if (dst_addr->sa_family == AF_INET) {
1838 desti = (struct sockaddr_in *) dst_addr;
1839 saddr.remote.v4 = *desti;
1840 saddr.local.v4.sin_family = desti->sin_family;
1841 } else if (dst_addr->sa_family == AF_INET6) {
1842 desti6 = (struct sockaddr_in6 *) dst_addr;
1843 saddr.remote.v6 = *desti6;
1844 saddr.local.v6.sin6_family = desti6->sin6_family;
1847 bnx2i_ep->timestamp = jiffies;
1848 bnx2i_ep->state = EP_STATE_CONNECT_START;
1849 if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
1853 rc = cnic->cm_connect(bnx2i_ep->cm_sk, &saddr);
1857 bnx2i_ep_active_list_add(hba, bnx2i_ep);
1859 if (bnx2i_map_ep_dbell_regs(bnx2i_ep))
1862 mutex_unlock(&hba->net_dev_lock);
1866 bnx2i_ep_active_list_del(hba, bnx2i_ep);
1868 if (bnx2i_tear_down_conn(hba, bnx2i_ep)) {
1869 mutex_unlock(&hba->net_dev_lock);
1873 bnx2i_free_qp_resc(hba, bnx2i_ep);
1877 mutex_unlock(&hba->net_dev_lock);
1884 * bnx2i_ep_poll - polls for TCP connection establishement
1885 * @ep: TCP connection (endpoint) handle
1886 * @timeout_ms: timeout value in milli secs
1888 * polls for TCP connect request to complete
1890 static int bnx2i_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1892 struct bnx2i_endpoint *bnx2i_ep;
1895 bnx2i_ep = ep->dd_data;
1896 if ((bnx2i_ep->state == EP_STATE_IDLE) ||
1897 (bnx2i_ep->state == EP_STATE_CONNECT_FAILED) ||
1898 (bnx2i_ep->state == EP_STATE_OFLD_FAILED))
1900 if (bnx2i_ep->state == EP_STATE_CONNECT_COMPL)
1903 rc = wait_event_interruptible_timeout(bnx2i_ep->ofld_wait,
1904 ((bnx2i_ep->state ==
1905 EP_STATE_OFLD_FAILED) ||
1907 EP_STATE_CONNECT_FAILED) ||
1909 EP_STATE_CONNECT_COMPL)),
1910 msecs_to_jiffies(timeout_ms));
1911 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED)
1917 return 0; /* timeout */
1924 * bnx2i_ep_tcp_conn_active - check EP state transition
1925 * @ep: endpoint pointer
1927 * check if underlying TCP connection is active
1929 static int bnx2i_ep_tcp_conn_active(struct bnx2i_endpoint *bnx2i_ep)
1932 int cnic_dev_10g = 0;
1934 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
1937 switch (bnx2i_ep->state) {
1938 case EP_STATE_CLEANUP_FAILED:
1939 case EP_STATE_OFLD_FAILED:
1940 case EP_STATE_DISCONN_TIMEDOUT:
1943 case EP_STATE_CONNECT_START:
1944 case EP_STATE_CONNECT_FAILED:
1945 case EP_STATE_CONNECT_COMPL:
1946 case EP_STATE_ULP_UPDATE_START:
1947 case EP_STATE_ULP_UPDATE_COMPL:
1948 case EP_STATE_TCP_FIN_RCVD:
1949 case EP_STATE_LOGOUT_SENT:
1950 case EP_STATE_LOGOUT_RESP_RCVD:
1951 case EP_STATE_ULP_UPDATE_FAILED:
1954 case EP_STATE_TCP_RST_RCVD:
1969 * bnx2i_hw_ep_disconnect - executes TCP connection teardown process in the hw
1970 * @ep: TCP connection (bnx2i endpoint) handle
1972 * executes TCP connection teardown process
1974 int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep)
1976 struct bnx2i_hba *hba = bnx2i_ep->hba;
1977 struct cnic_dev *cnic;
1978 struct iscsi_session *session = NULL;
1979 struct iscsi_conn *conn = NULL;
1991 if (bnx2i_ep->state == EP_STATE_IDLE ||
1992 bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT)
1995 if (!bnx2i_ep_tcp_conn_active(bnx2i_ep))
1998 if (bnx2i_ep->conn) {
1999 conn = bnx2i_ep->conn->cls_conn->dd_data;
2000 session = conn->session;
2003 init_timer(&bnx2i_ep->ofld_timer);
2004 bnx2i_ep->ofld_timer.expires = hba->conn_teardown_tmo + jiffies;
2005 bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
2006 bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
2007 add_timer(&bnx2i_ep->ofld_timer);
2009 if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic))
2013 spin_lock_bh(&session->lock);
2014 if (bnx2i_ep->state != EP_STATE_TCP_FIN_RCVD) {
2015 if (session->state == ISCSI_STATE_LOGGING_OUT) {
2016 if (bnx2i_ep->state == EP_STATE_LOGOUT_SENT) {
2017 /* Logout sent, but no resp */
2018 printk(KERN_ALERT "bnx2i (%s): WARNING"
2019 " logout response was not "
2021 bnx2i_ep->hba->netdev->name);
2022 } else if (bnx2i_ep->state ==
2023 EP_STATE_LOGOUT_RESP_RCVD)
2029 spin_unlock_bh(&session->lock);
2032 bnx2i_ep->state = EP_STATE_DISCONN_START;
2035 close_ret = cnic->cm_close(bnx2i_ep->cm_sk);
2037 close_ret = cnic->cm_abort(bnx2i_ep->cm_sk);
2040 printk(KERN_ALERT "bnx2i (%s): close/abort(%d) returned %d\n",
2041 bnx2i_ep->hba->netdev->name, close, close_ret);
2043 /* wait for option-2 conn teardown */
2044 wait_event_interruptible(bnx2i_ep->ofld_wait,
2045 bnx2i_ep->state != EP_STATE_DISCONN_START);
2047 if (signal_pending(current))
2048 flush_signals(current);
2049 del_timer_sync(&bnx2i_ep->ofld_timer);
2052 bnx2i_ep_active_list_del(hba, bnx2i_ep);
2053 if (bnx2i_tear_down_conn(hba, bnx2i_ep))
2056 bnx2i_ep->state = EP_STATE_IDLE;
2062 * bnx2i_ep_disconnect - executes TCP connection teardown process
2063 * @ep: TCP connection (iscsi endpoint) handle
2065 * executes TCP connection teardown process
2067 static void bnx2i_ep_disconnect(struct iscsi_endpoint *ep)
2069 struct bnx2i_endpoint *bnx2i_ep;
2070 struct bnx2i_conn *bnx2i_conn = NULL;
2071 struct iscsi_conn *conn = NULL;
2072 struct bnx2i_hba *hba;
2074 bnx2i_ep = ep->dd_data;
2076 /* driver should not attempt connection cleanup until TCP_CONNECT
2077 * completes either successfully or fails. Timeout is 9-secs, so
2078 * wait for it to complete
2080 while ((bnx2i_ep->state == EP_STATE_CONNECT_START) &&
2081 !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ)))
2084 if (bnx2i_ep->conn) {
2085 bnx2i_conn = bnx2i_ep->conn;
2086 conn = bnx2i_conn->cls_conn->dd_data;
2087 iscsi_suspend_queue(conn);
2089 hba = bnx2i_ep->hba;
2091 mutex_lock(&hba->net_dev_lock);
2093 if (bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT)
2096 if (bnx2i_ep->state == EP_STATE_IDLE)
2099 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) ||
2100 (bnx2i_ep->hba_age != hba->age)) {
2101 bnx2i_ep_active_list_del(hba, bnx2i_ep);
2105 /* Do all chip cleanup here */
2106 if (bnx2i_hw_ep_disconnect(bnx2i_ep)) {
2107 mutex_unlock(&hba->net_dev_lock);
2111 bnx2i_free_qp_resc(hba, bnx2i_ep);
2114 bnx2i_conn->ep = NULL;
2118 mutex_unlock(&hba->net_dev_lock);
2120 wake_up_interruptible(&hba->eh_wait);
2125 * bnx2i_nl_set_path - ISCSI_UEVENT_PATH_UPDATE user message handler
2126 * @buf: pointer to buffer containing iscsi path message
2129 static int bnx2i_nl_set_path(struct Scsi_Host *shost, struct iscsi_path *params)
2131 struct bnx2i_hba *hba = iscsi_host_priv(shost);
2132 char *buf = (char *) params;
2133 u16 len = sizeof(*params);
2135 /* handled by cnic driver */
2136 hba->cnic->iscsi_nl_msg_recv(hba->cnic, ISCSI_UEVENT_PATH_UPDATE, buf,
2144 * 'Scsi_Host_Template' structure and 'iscsi_tranport' structure template
2145 * used while registering with the scsi host and iSCSI transport module.
2147 static struct scsi_host_template bnx2i_host_template = {
2148 .module = THIS_MODULE,
2149 .name = "Broadcom Offload iSCSI Initiator",
2150 .proc_name = "bnx2i",
2151 .queuecommand = iscsi_queuecommand,
2152 .eh_abort_handler = iscsi_eh_abort,
2153 .eh_device_reset_handler = iscsi_eh_device_reset,
2154 .eh_target_reset_handler = iscsi_eh_recover_target,
2155 .change_queue_depth = iscsi_change_queue_depth,
2160 .use_clustering = ENABLE_CLUSTERING,
2161 .sg_tablesize = ISCSI_MAX_BDS_PER_CMD,
2162 .shost_attrs = bnx2i_dev_attributes,
2165 struct iscsi_transport bnx2i_iscsi_transport = {
2166 .owner = THIS_MODULE,
2168 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST |
2169 CAP_MULTI_R2T | CAP_DATADGST |
2170 CAP_DATA_PATH_OFFLOAD,
2171 .param_mask = ISCSI_MAX_RECV_DLENGTH |
2172 ISCSI_MAX_XMIT_DLENGTH |
2175 ISCSI_INITIAL_R2T_EN |
2180 ISCSI_PDU_INORDER_EN |
2181 ISCSI_DATASEQ_INORDER_EN |
2184 ISCSI_CONN_ADDRESS |
2186 ISCSI_PERSISTENT_PORT |
2187 ISCSI_PERSISTENT_ADDRESS |
2188 ISCSI_TARGET_NAME | ISCSI_TPGT |
2189 ISCSI_USERNAME | ISCSI_PASSWORD |
2190 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
2191 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
2192 ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
2193 ISCSI_PING_TMO | ISCSI_RECV_TMO |
2194 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
2195 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
2196 ISCSI_HOST_NETDEV_NAME,
2197 .create_session = bnx2i_session_create,
2198 .destroy_session = bnx2i_session_destroy,
2199 .create_conn = bnx2i_conn_create,
2200 .bind_conn = bnx2i_conn_bind,
2201 .destroy_conn = bnx2i_conn_destroy,
2202 .set_param = iscsi_set_param,
2203 .get_conn_param = bnx2i_conn_get_param,
2204 .get_session_param = iscsi_session_get_param,
2205 .get_host_param = bnx2i_host_get_param,
2206 .start_conn = bnx2i_conn_start,
2207 .stop_conn = iscsi_conn_stop,
2208 .send_pdu = iscsi_conn_send_pdu,
2209 .xmit_task = bnx2i_task_xmit,
2210 .get_stats = bnx2i_conn_get_stats,
2211 /* TCP connect - disconnect - option-2 interface calls */
2212 .ep_connect = bnx2i_ep_connect,
2213 .ep_poll = bnx2i_ep_poll,
2214 .ep_disconnect = bnx2i_ep_disconnect,
2215 .set_path = bnx2i_nl_set_path,
2216 /* Error recovery timeout call */
2217 .session_recovery_timedout = iscsi_session_recovery_timedout,
2218 .cleanup_task = bnx2i_cleanup_task,