Lines Matching +full:sc +full:- +full:resource

4  * Copyright (c) 2006 - 2013 Broadcom Corporation
15 * Maintained by: QLogic-Storage-Upstream@qlogic.com
28 * Global endpoint resource info
38 if (!hba || !test_bit(ADAPTER_STATE_UP, &hba->adapter_state) || in bnx2i_adapter_ready()
39 test_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state) || in bnx2i_adapter_ready()
40 test_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state)) in bnx2i_adapter_ready()
41 retval = -EPERM; in bnx2i_adapter_ready()
46 * bnx2i_get_write_cmd_bd_idx - identifies various BD bookmarks
59 struct iscsi_bd *bd_tbl = cmd->io_tbl.bd_tbl; in bnx2i_get_write_cmd_bd_idx()
64 while (buf_off >= (cur_offset + bd_tbl->buffer_length)) { in bnx2i_get_write_cmd_bd_idx()
65 cur_offset += bd_tbl->buffer_length; in bnx2i_get_write_cmd_bd_idx()
71 *start_bd_off = buf_off - cur_offset; in bnx2i_get_write_cmd_bd_idx()
76 * bnx2i_setup_write_cmd_bd_info - sets up BD various information
86 struct bnx2i_cmd *cmd = task->dd_data; in bnx2i_setup_write_cmd_bd_info()
90 u32 cmd_len = cmd->req.total_data_transfer_length; in bnx2i_setup_write_cmd_bd_info()
95 if (!iscsi_task_has_unsol_data(task) && !task->imm_count) in bnx2i_setup_write_cmd_bd_info()
99 buffer_offset += task->imm_count; in bnx2i_setup_write_cmd_bd_info()
100 if (task->imm_count == cmd_len) in bnx2i_setup_write_cmd_bd_info()
106 cmd->req.ud_buffer_offset = start_bd_offset; in bnx2i_setup_write_cmd_bd_info()
107 cmd->req.ud_start_bd_index = start_bd_idx; in bnx2i_setup_write_cmd_bd_info()
108 buffer_offset += task->unsol_r2t.data_length; in bnx2i_setup_write_cmd_bd_info()
114 if ((start_bd_offset > task->conn->session->first_burst) || in bnx2i_setup_write_cmd_bd_info()
115 (start_bd_idx > scsi_sg_count(cmd->scsi_cmd))) { in bnx2i_setup_write_cmd_bd_info()
118 iscsi_conn_printk(KERN_ALERT, task->conn, in bnx2i_setup_write_cmd_bd_info()
119 "bnx2i- error, buf offset 0x%x " in bnx2i_setup_write_cmd_bd_info()
121 buffer_offset, cmd->io_tbl.bd_valid, in bnx2i_setup_write_cmd_bd_info()
122 scsi_sg_count(cmd->scsi_cmd)); in bnx2i_setup_write_cmd_bd_info()
123 for (i = 0; i < cmd->io_tbl.bd_valid; i++) in bnx2i_setup_write_cmd_bd_info()
124 iscsi_conn_printk(KERN_ALERT, task->conn, in bnx2i_setup_write_cmd_bd_info()
126 i, cmd->io_tbl.bd_tbl[i].\ in bnx2i_setup_write_cmd_bd_info()
129 cmd->req.sd_buffer_offset = start_bd_offset; in bnx2i_setup_write_cmd_bd_info()
130 cmd->req.sd_start_bd_index = start_bd_idx; in bnx2i_setup_write_cmd_bd_info()
137 * bnx2i_map_scsi_sg - maps IO buffer and prepares the BD table
145 struct scsi_cmnd *sc = cmd->scsi_cmd; in bnx2i_map_scsi_sg() local
146 struct iscsi_bd *bd = cmd->io_tbl.bd_tbl; in bnx2i_map_scsi_sg()
155 BUG_ON(scsi_sg_count(sc) > ISCSI_MAX_BDS_PER_CMD); in bnx2i_map_scsi_sg()
157 sg_count = scsi_dma_map(sc); in bnx2i_map_scsi_sg()
159 scsi_for_each_sg(sc, sg, sg_count, i) { in bnx2i_map_scsi_sg()
174 bd[bd_count - 1].flags |= ISCSI_BD_LAST_IN_BD_CHAIN; in bnx2i_map_scsi_sg()
176 BUG_ON(byte_count != scsi_bufflen(sc)); in bnx2i_map_scsi_sg()
181 * bnx2i_iscsi_map_sg_list - maps SG list
190 bd_count = bnx2i_map_scsi_sg(cmd->conn->hba, cmd); in bnx2i_iscsi_map_sg_list()
192 struct iscsi_bd *bd = cmd->io_tbl.bd_tbl; in bnx2i_iscsi_map_sg_list()
197 cmd->io_tbl.bd_valid = bd_count; in bnx2i_iscsi_map_sg_list()
202 * bnx2i_iscsi_unmap_sg_list - unmaps SG list
209 struct scsi_cmnd *sc = cmd->scsi_cmd; in bnx2i_iscsi_unmap_sg_list() local
211 if (cmd->io_tbl.bd_valid && sc) { in bnx2i_iscsi_unmap_sg_list()
212 scsi_dma_unmap(sc); in bnx2i_iscsi_unmap_sg_list()
213 cmd->io_tbl.bd_valid = 0; in bnx2i_iscsi_unmap_sg_list()
219 memset(&cmd->req, 0x00, sizeof(cmd->req)); in bnx2i_setup_cmd_wqe_template()
220 cmd->req.op_code = 0xFF; in bnx2i_setup_cmd_wqe_template()
221 cmd->req.bd_list_addr_lo = (u32) cmd->io_tbl.bd_tbl_dma; in bnx2i_setup_cmd_wqe_template()
222 cmd->req.bd_list_addr_hi = in bnx2i_setup_cmd_wqe_template()
223 (u32) ((u64) cmd->io_tbl.bd_tbl_dma >> 32); in bnx2i_setup_cmd_wqe_template()
229 * bnx2i_bind_conn_to_iscsi_cid - bind conn structure to 'iscsi_cid'
232 * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
242 if (hba && hba->cid_que.conn_cid_tbl[iscsi_cid]) { in bnx2i_bind_conn_to_iscsi_cid()
243 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data, in bnx2i_bind_conn_to_iscsi_cid()
244 "conn bind - entry #%d not free\n", iscsi_cid); in bnx2i_bind_conn_to_iscsi_cid()
245 return -EBUSY; in bnx2i_bind_conn_to_iscsi_cid()
248 hba->cid_que.conn_cid_tbl[iscsi_cid] = bnx2i_conn; in bnx2i_bind_conn_to_iscsi_cid()
254 * bnx2i_get_conn_from_id - maps an iscsi cid to corresponding conn ptr
256 * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
261 if (!hba->cid_que.conn_cid_tbl) { in bnx2i_get_conn_from_id()
262 printk(KERN_ERR "bnx2i: ERROR - missing conn<->cid table\n"); in bnx2i_get_conn_from_id()
265 } else if (iscsi_cid >= hba->max_active_conns) { in bnx2i_get_conn_from_id()
269 return hba->cid_que.conn_cid_tbl[iscsi_cid]; in bnx2i_get_conn_from_id()
274 * bnx2i_alloc_iscsi_cid - allocates a iscsi_cid from free pool
281 if (!hba->cid_que.cid_free_cnt) in bnx2i_alloc_iscsi_cid()
282 return -1; in bnx2i_alloc_iscsi_cid()
284 idx = hba->cid_que.cid_q_cons_idx; in bnx2i_alloc_iscsi_cid()
285 hba->cid_que.cid_q_cons_idx++; in bnx2i_alloc_iscsi_cid()
286 if (hba->cid_que.cid_q_cons_idx == hba->cid_que.cid_q_max_idx) in bnx2i_alloc_iscsi_cid()
287 hba->cid_que.cid_q_cons_idx = 0; in bnx2i_alloc_iscsi_cid()
289 hba->cid_que.cid_free_cnt--; in bnx2i_alloc_iscsi_cid()
290 return hba->cid_que.cid_que[idx]; in bnx2i_alloc_iscsi_cid()
295 * bnx2i_free_iscsi_cid - returns tcp port to free list
303 if (iscsi_cid == (u16) -1) in bnx2i_free_iscsi_cid()
306 hba->cid_que.cid_free_cnt++; in bnx2i_free_iscsi_cid()
308 idx = hba->cid_que.cid_q_prod_idx; in bnx2i_free_iscsi_cid()
309 hba->cid_que.cid_que[idx] = iscsi_cid; in bnx2i_free_iscsi_cid()
310 hba->cid_que.conn_cid_tbl[iscsi_cid] = NULL; in bnx2i_free_iscsi_cid()
311 hba->cid_que.cid_q_prod_idx++; in bnx2i_free_iscsi_cid()
312 if (hba->cid_que.cid_q_prod_idx == hba->cid_que.cid_q_max_idx) in bnx2i_free_iscsi_cid()
313 hba->cid_que.cid_q_prod_idx = 0; in bnx2i_free_iscsi_cid()
318 * bnx2i_setup_free_cid_que - sets up free iscsi cid queue
321 * allocates memory for iscsi cid queue & 'cid - conn ptr' mapping table,
329 mem_size = hba->max_active_conns * sizeof(u32); in bnx2i_setup_free_cid_que()
330 mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; in bnx2i_setup_free_cid_que()
332 hba->cid_que.cid_que_base = kmalloc(mem_size, GFP_KERNEL); in bnx2i_setup_free_cid_que()
333 if (!hba->cid_que.cid_que_base) in bnx2i_setup_free_cid_que()
334 return -ENOMEM; in bnx2i_setup_free_cid_que()
336 mem_size = hba->max_active_conns * sizeof(struct bnx2i_conn *); in bnx2i_setup_free_cid_que()
337 mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; in bnx2i_setup_free_cid_que()
338 hba->cid_que.conn_cid_tbl = kmalloc(mem_size, GFP_KERNEL); in bnx2i_setup_free_cid_que()
339 if (!hba->cid_que.conn_cid_tbl) { in bnx2i_setup_free_cid_que()
340 kfree(hba->cid_que.cid_que_base); in bnx2i_setup_free_cid_que()
341 hba->cid_que.cid_que_base = NULL; in bnx2i_setup_free_cid_que()
342 return -ENOMEM; in bnx2i_setup_free_cid_que()
345 hba->cid_que.cid_que = (u32 *)hba->cid_que.cid_que_base; in bnx2i_setup_free_cid_que()
346 hba->cid_que.cid_q_prod_idx = 0; in bnx2i_setup_free_cid_que()
347 hba->cid_que.cid_q_cons_idx = 0; in bnx2i_setup_free_cid_que()
348 hba->cid_que.cid_q_max_idx = hba->max_active_conns; in bnx2i_setup_free_cid_que()
349 hba->cid_que.cid_free_cnt = hba->max_active_conns; in bnx2i_setup_free_cid_que()
351 for (i = 0; i < hba->max_active_conns; i++) { in bnx2i_setup_free_cid_que()
352 hba->cid_que.cid_que[i] = i; in bnx2i_setup_free_cid_que()
353 hba->cid_que.conn_cid_tbl[i] = NULL; in bnx2i_setup_free_cid_que()
360 * bnx2i_release_free_cid_que - releases 'iscsi_cid' queue resources
365 kfree(hba->cid_que.cid_que_base); in bnx2i_release_free_cid_que()
366 hba->cid_que.cid_que_base = NULL; in bnx2i_release_free_cid_que()
368 kfree(hba->cid_que.conn_cid_tbl); in bnx2i_release_free_cid_que()
369 hba->cid_que.conn_cid_tbl = NULL; in bnx2i_release_free_cid_que()
374 * bnx2i_alloc_ep - allocates ep structure from global pool
378 * a tcp port to be used for this connection. Global resource lock,
393 bnx2i_ep = ep->dd_data; in bnx2i_alloc_ep()
394 bnx2i_ep->cls_ep = ep; in bnx2i_alloc_ep()
395 INIT_LIST_HEAD(&bnx2i_ep->link); in bnx2i_alloc_ep()
396 bnx2i_ep->state = EP_STATE_IDLE; in bnx2i_alloc_ep()
397 bnx2i_ep->ep_iscsi_cid = (u16) -1; in bnx2i_alloc_ep()
398 bnx2i_ep->hba = hba; in bnx2i_alloc_ep()
399 bnx2i_ep->hba_age = hba->age; in bnx2i_alloc_ep()
403 bnx2i_ep->ec_shift += 1; in bnx2i_alloc_ep()
405 hba->ofld_conns_active++; in bnx2i_alloc_ep()
406 init_waitqueue_head(&bnx2i_ep->ofld_wait); in bnx2i_alloc_ep()
412 * bnx2i_free_ep - free endpoint
417 struct bnx2i_endpoint *bnx2i_ep = ep->dd_data; in bnx2i_free_ep()
421 bnx2i_ep->state = EP_STATE_IDLE; in bnx2i_free_ep()
422 bnx2i_ep->hba->ofld_conns_active--; in bnx2i_free_ep()
424 if (bnx2i_ep->ep_iscsi_cid != (u16) -1) in bnx2i_free_ep()
425 bnx2i_free_iscsi_cid(bnx2i_ep->hba, bnx2i_ep->ep_iscsi_cid); in bnx2i_free_ep()
427 if (bnx2i_ep->conn) { in bnx2i_free_ep()
428 bnx2i_ep->conn->ep = NULL; in bnx2i_free_ep()
429 bnx2i_ep->conn = NULL; in bnx2i_free_ep()
432 bnx2i_ep->hba = NULL; in bnx2i_free_ep()
439 * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command
447 struct io_bdt *io = &cmd->io_tbl; in bnx2i_alloc_bdt()
450 io->bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, in bnx2i_alloc_bdt()
452 &io->bd_tbl_dma, GFP_KERNEL); in bnx2i_alloc_bdt()
453 if (!io->bd_tbl) { in bnx2i_alloc_bdt()
456 return -ENOMEM; in bnx2i_alloc_bdt()
458 io->bd_valid = 0; in bnx2i_alloc_bdt()
463 * bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table
472 for (i = 0; i < session->cmds_max; i++) { in bnx2i_destroy_cmd_pool()
473 struct iscsi_task *task = session->cmds[i]; in bnx2i_destroy_cmd_pool()
474 struct bnx2i_cmd *cmd = task->dd_data; in bnx2i_destroy_cmd_pool()
476 if (cmd->io_tbl.bd_tbl) in bnx2i_destroy_cmd_pool()
477 dma_free_coherent(&hba->pcidev->dev, in bnx2i_destroy_cmd_pool()
480 cmd->io_tbl.bd_tbl, in bnx2i_destroy_cmd_pool()
481 cmd->io_tbl.bd_tbl_dma); in bnx2i_destroy_cmd_pool()
488 * bnx2i_setup_cmd_pool - sets up iscsi command pool for the session
497 for (i = 0; i < session->cmds_max; i++) { in bnx2i_setup_cmd_pool()
498 struct iscsi_task *task = session->cmds[i]; in bnx2i_setup_cmd_pool()
499 struct bnx2i_cmd *cmd = task->dd_data; in bnx2i_setup_cmd_pool()
501 task->hdr = &cmd->hdr; in bnx2i_setup_cmd_pool()
502 task->hdr_max = sizeof(struct iscsi_hdr); in bnx2i_setup_cmd_pool()
512 return -ENOMEM; in bnx2i_setup_cmd_pool()
517 * bnx2i_setup_mp_bdt - allocate BD table resources
529 hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_setup_mp_bdt()
530 &hba->mp_bd_dma, GFP_KERNEL); in bnx2i_setup_mp_bdt()
531 if (!hba->mp_bd_tbl) { in bnx2i_setup_mp_bdt()
533 rc = -1; in bnx2i_setup_mp_bdt()
537 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, in bnx2i_setup_mp_bdt()
539 &hba->dummy_buf_dma, GFP_KERNEL); in bnx2i_setup_mp_bdt()
540 if (!hba->dummy_buffer) { in bnx2i_setup_mp_bdt()
542 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_setup_mp_bdt()
543 hba->mp_bd_tbl, hba->mp_bd_dma); in bnx2i_setup_mp_bdt()
544 hba->mp_bd_tbl = NULL; in bnx2i_setup_mp_bdt()
545 rc = -1; in bnx2i_setup_mp_bdt()
549 mp_bdt = (struct iscsi_bd *) hba->mp_bd_tbl; in bnx2i_setup_mp_bdt()
550 addr = (unsigned long) hba->dummy_buf_dma; in bnx2i_setup_mp_bdt()
551 mp_bdt->buffer_addr_lo = addr & 0xffffffff; in bnx2i_setup_mp_bdt()
552 mp_bdt->buffer_addr_hi = addr >> 32; in bnx2i_setup_mp_bdt()
553 mp_bdt->buffer_length = CNIC_PAGE_SIZE; in bnx2i_setup_mp_bdt()
554 mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN | in bnx2i_setup_mp_bdt()
562 * bnx2i_free_mp_bdt - releases ITT back to free pool
569 if (hba->mp_bd_tbl) { in bnx2i_free_mp_bdt()
570 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_free_mp_bdt()
571 hba->mp_bd_tbl, hba->mp_bd_dma); in bnx2i_free_mp_bdt()
572 hba->mp_bd_tbl = NULL; in bnx2i_free_mp_bdt()
574 if (hba->dummy_buffer) { in bnx2i_free_mp_bdt()
575 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_free_mp_bdt()
576 hba->dummy_buffer, hba->dummy_buf_dma); in bnx2i_free_mp_bdt()
577 hba->dummy_buffer = NULL; in bnx2i_free_mp_bdt()
583 * bnx2i_drop_session - notifies iscsid of connection error.
594 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED); in bnx2i_drop_session()
598 * bnx2i_ep_destroy_list_add - add an entry to EP destroy list
607 write_lock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_destroy_list_add()
608 list_add_tail(&ep->link, &hba->ep_destroy_list); in bnx2i_ep_destroy_list_add()
609 write_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_destroy_list_add()
614 * bnx2i_ep_destroy_list_del - add an entry to EP destroy list
624 write_lock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_destroy_list_del()
625 list_del_init(&ep->link); in bnx2i_ep_destroy_list_del()
626 write_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_destroy_list_del()
632 * bnx2i_ep_ofld_list_add - add an entry to ep offload pending list
641 write_lock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_ofld_list_add()
642 list_add_tail(&ep->link, &hba->ep_ofld_list); in bnx2i_ep_ofld_list_add()
643 write_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_ofld_list_add()
648 * bnx2i_ep_ofld_list_del - add an entry to ep offload pending list
657 write_lock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_ofld_list_del()
658 list_del_init(&ep->link); in bnx2i_ep_ofld_list_del()
659 write_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_ofld_list_del()
665 * bnx2i_find_ep_in_ofld_list - find iscsi_cid in pending list of endpoints
678 read_lock_bh(&hba->ep_rdwr_lock); in bnx2i_find_ep_in_ofld_list()
679 list_for_each_safe(list, tmp, &hba->ep_ofld_list) { in bnx2i_find_ep_in_ofld_list()
682 if (ep->ep_iscsi_cid == iscsi_cid) in bnx2i_find_ep_in_ofld_list()
686 read_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_find_ep_in_ofld_list()
694 * bnx2i_find_ep_in_destroy_list - find iscsi_cid in destroy list
706 read_lock_bh(&hba->ep_rdwr_lock); in bnx2i_find_ep_in_destroy_list()
707 list_for_each_safe(list, tmp, &hba->ep_destroy_list) { in bnx2i_find_ep_in_destroy_list()
710 if (ep->ep_iscsi_cid == iscsi_cid) in bnx2i_find_ep_in_destroy_list()
714 read_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_find_ep_in_destroy_list()
723 * bnx2i_ep_active_list_add - add an entry to ep active list
732 write_lock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_active_list_add()
733 list_add_tail(&ep->link, &hba->ep_active_list); in bnx2i_ep_active_list_add()
734 write_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_active_list_add()
739 * bnx2i_ep_active_list_del - deletes an entry to ep active list
748 write_lock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_active_list_del()
749 list_del_init(&ep->link); in bnx2i_ep_active_list_del()
750 write_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_ep_active_list_del()
755 * bnx2i_setup_host_queue_size - assigns shost->can_queue param
766 if (test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type)) in bnx2i_setup_host_queue_size()
767 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708; in bnx2i_setup_host_queue_size()
768 else if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) in bnx2i_setup_host_queue_size()
769 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5709; in bnx2i_setup_host_queue_size()
770 else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) in bnx2i_setup_host_queue_size()
771 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_57710; in bnx2i_setup_host_queue_size()
773 shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708; in bnx2i_setup_host_queue_size()
778 * bnx2i_alloc_hba - allocate and init adapter instance
792 shost->dma_boundary = cnic->pcidev->dma_mask; in bnx2i_alloc_hba()
793 shost->transportt = bnx2i_scsi_xport_template; in bnx2i_alloc_hba()
794 shost->max_id = ISCSI_MAX_CONNS_PER_HBA - 1; in bnx2i_alloc_hba()
795 shost->max_channel = 0; in bnx2i_alloc_hba()
796 shost->max_lun = 512; in bnx2i_alloc_hba()
797 shost->max_cmd_len = 16; in bnx2i_alloc_hba()
800 hba->shost = shost; in bnx2i_alloc_hba()
801 hba->netdev = cnic->netdev; in bnx2i_alloc_hba()
803 hba->pcidev = cnic->pcidev; in bnx2i_alloc_hba()
804 pci_dev_get(hba->pcidev); in bnx2i_alloc_hba()
805 hba->pci_did = hba->pcidev->device; in bnx2i_alloc_hba()
806 hba->pci_vid = hba->pcidev->vendor; in bnx2i_alloc_hba()
807 hba->pci_sdid = hba->pcidev->subsystem_device; in bnx2i_alloc_hba()
808 hba->pci_svid = hba->pcidev->subsystem_vendor; in bnx2i_alloc_hba()
809 hba->pci_func = PCI_FUNC(hba->pcidev->devfn); in bnx2i_alloc_hba()
810 hba->pci_devno = PCI_SLOT(hba->pcidev->devfn); in bnx2i_alloc_hba()
815 hba->reg_base = pci_resource_start(hba->pcidev, 0); in bnx2i_alloc_hba()
816 if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) { in bnx2i_alloc_hba()
817 hba->regview = pci_iomap(hba->pcidev, 0, BNX2_MQ_CONFIG2); in bnx2i_alloc_hba()
818 if (!hba->regview) in bnx2i_alloc_hba()
820 } else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { in bnx2i_alloc_hba()
821 hba->regview = pci_iomap(hba->pcidev, 0, 4096); in bnx2i_alloc_hba()
822 if (!hba->regview) in bnx2i_alloc_hba()
829 INIT_LIST_HEAD(&hba->ep_ofld_list); in bnx2i_alloc_hba()
830 INIT_LIST_HEAD(&hba->ep_active_list); in bnx2i_alloc_hba()
831 INIT_LIST_HEAD(&hba->ep_destroy_list); in bnx2i_alloc_hba()
832 rwlock_init(&hba->ep_rdwr_lock); in bnx2i_alloc_hba()
834 hba->mtu_supported = BNX2I_MAX_MTU_SUPPORTED; in bnx2i_alloc_hba()
837 hba->max_active_conns = ISCSI_MAX_CONNS_PER_HBA; in bnx2i_alloc_hba()
843 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { in bnx2i_alloc_hba()
845 hba->max_sqes = sq_size; in bnx2i_alloc_hba()
847 hba->max_sqes = BNX2I_5770X_SQ_WQES_DEFAULT; in bnx2i_alloc_hba()
850 hba->max_sqes = sq_size; in bnx2i_alloc_hba()
852 hba->max_sqes = BNX2I_570X_SQ_WQES_DEFAULT; in bnx2i_alloc_hba()
855 hba->max_rqes = rq_size; in bnx2i_alloc_hba()
856 hba->max_cqes = hba->max_sqes + rq_size; in bnx2i_alloc_hba()
857 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { in bnx2i_alloc_hba()
858 if (hba->max_cqes > BNX2I_5770X_CQ_WQES_MAX) in bnx2i_alloc_hba()
859 hba->max_cqes = BNX2I_5770X_CQ_WQES_MAX; in bnx2i_alloc_hba()
860 } else if (hba->max_cqes > BNX2I_570X_CQ_WQES_MAX) in bnx2i_alloc_hba()
861 hba->max_cqes = BNX2I_570X_CQ_WQES_MAX; in bnx2i_alloc_hba()
863 hba->num_ccell = hba->max_sqes / 2; in bnx2i_alloc_hba()
865 spin_lock_init(&hba->lock); in bnx2i_alloc_hba()
866 mutex_init(&hba->net_dev_lock); in bnx2i_alloc_hba()
867 init_waitqueue_head(&hba->eh_wait); in bnx2i_alloc_hba()
868 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { in bnx2i_alloc_hba()
869 hba->hba_shutdown_tmo = 30 * HZ; in bnx2i_alloc_hba()
870 hba->conn_teardown_tmo = 20 * HZ; in bnx2i_alloc_hba()
871 hba->conn_ctx_destroy_tmo = 6 * HZ; in bnx2i_alloc_hba()
873 hba->hba_shutdown_tmo = 20 * HZ; in bnx2i_alloc_hba()
874 hba->conn_teardown_tmo = 10 * HZ; in bnx2i_alloc_hba()
875 hba->conn_ctx_destroy_tmo = 2 * HZ; in bnx2i_alloc_hba()
879 spin_lock_init(&hba->stat_lock); in bnx2i_alloc_hba()
881 memset(&hba->stats, 0, sizeof(struct iscsi_stats_info)); in bnx2i_alloc_hba()
883 if (iscsi_host_add(shost, &hba->pcidev->dev)) in bnx2i_alloc_hba()
892 if (hba->regview) { in bnx2i_alloc_hba()
893 pci_iounmap(hba->pcidev, hba->regview); in bnx2i_alloc_hba()
894 hba->regview = NULL; in bnx2i_alloc_hba()
897 pci_dev_put(hba->pcidev); in bnx2i_alloc_hba()
903 * bnx2i_free_hba- releases hba structure and resources held by the adapter
910 struct Scsi_Host *shost = hba->shost; in bnx2i_free_hba()
913 INIT_LIST_HEAD(&hba->ep_ofld_list); in bnx2i_free_hba()
914 INIT_LIST_HEAD(&hba->ep_active_list); in bnx2i_free_hba()
915 INIT_LIST_HEAD(&hba->ep_destroy_list); in bnx2i_free_hba()
917 if (hba->regview) { in bnx2i_free_hba()
918 pci_iounmap(hba->pcidev, hba->regview); in bnx2i_free_hba()
919 hba->regview = NULL; in bnx2i_free_hba()
921 pci_dev_put(hba->pcidev); in bnx2i_free_hba()
928 * bnx2i_conn_free_login_resources - free DMA resources used for login process
937 if (bnx2i_conn->gen_pdu.resp_bd_tbl) { in bnx2i_conn_free_login_resources()
938 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_conn_free_login_resources()
939 bnx2i_conn->gen_pdu.resp_bd_tbl, in bnx2i_conn_free_login_resources()
940 bnx2i_conn->gen_pdu.resp_bd_dma); in bnx2i_conn_free_login_resources()
941 bnx2i_conn->gen_pdu.resp_bd_tbl = NULL; in bnx2i_conn_free_login_resources()
944 if (bnx2i_conn->gen_pdu.req_bd_tbl) { in bnx2i_conn_free_login_resources()
945 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_conn_free_login_resources()
946 bnx2i_conn->gen_pdu.req_bd_tbl, in bnx2i_conn_free_login_resources()
947 bnx2i_conn->gen_pdu.req_bd_dma); in bnx2i_conn_free_login_resources()
948 bnx2i_conn->gen_pdu.req_bd_tbl = NULL; in bnx2i_conn_free_login_resources()
951 if (bnx2i_conn->gen_pdu.resp_buf) { in bnx2i_conn_free_login_resources()
952 dma_free_coherent(&hba->pcidev->dev, in bnx2i_conn_free_login_resources()
954 bnx2i_conn->gen_pdu.resp_buf, in bnx2i_conn_free_login_resources()
955 bnx2i_conn->gen_pdu.resp_dma_addr); in bnx2i_conn_free_login_resources()
956 bnx2i_conn->gen_pdu.resp_buf = NULL; in bnx2i_conn_free_login_resources()
959 if (bnx2i_conn->gen_pdu.req_buf) { in bnx2i_conn_free_login_resources()
960 dma_free_coherent(&hba->pcidev->dev, in bnx2i_conn_free_login_resources()
962 bnx2i_conn->gen_pdu.req_buf, in bnx2i_conn_free_login_resources()
963 bnx2i_conn->gen_pdu.req_dma_addr); in bnx2i_conn_free_login_resources()
964 bnx2i_conn->gen_pdu.req_buf = NULL; in bnx2i_conn_free_login_resources()
969 * bnx2i_conn_alloc_login_resources - alloc DMA resources for login/nop.
979 bnx2i_conn->gen_pdu.req_buf = in bnx2i_conn_alloc_login_resources()
980 dma_alloc_coherent(&hba->pcidev->dev, in bnx2i_conn_alloc_login_resources()
982 &bnx2i_conn->gen_pdu.req_dma_addr, in bnx2i_conn_alloc_login_resources()
984 if (bnx2i_conn->gen_pdu.req_buf == NULL) in bnx2i_conn_alloc_login_resources()
987 bnx2i_conn->gen_pdu.req_buf_size = 0; in bnx2i_conn_alloc_login_resources()
988 bnx2i_conn->gen_pdu.req_wr_ptr = bnx2i_conn->gen_pdu.req_buf; in bnx2i_conn_alloc_login_resources()
990 bnx2i_conn->gen_pdu.resp_buf = in bnx2i_conn_alloc_login_resources()
991 dma_alloc_coherent(&hba->pcidev->dev, in bnx2i_conn_alloc_login_resources()
993 &bnx2i_conn->gen_pdu.resp_dma_addr, in bnx2i_conn_alloc_login_resources()
995 if (bnx2i_conn->gen_pdu.resp_buf == NULL) in bnx2i_conn_alloc_login_resources()
998 bnx2i_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN; in bnx2i_conn_alloc_login_resources()
999 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf; in bnx2i_conn_alloc_login_resources()
1001 bnx2i_conn->gen_pdu.req_bd_tbl = in bnx2i_conn_alloc_login_resources()
1002 dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_conn_alloc_login_resources()
1003 &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL); in bnx2i_conn_alloc_login_resources()
1004 if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL) in bnx2i_conn_alloc_login_resources()
1007 bnx2i_conn->gen_pdu.resp_bd_tbl = in bnx2i_conn_alloc_login_resources()
1008 dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_conn_alloc_login_resources()
1009 &bnx2i_conn->gen_pdu.resp_bd_dma, in bnx2i_conn_alloc_login_resources()
1011 if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL) in bnx2i_conn_alloc_login_resources()
1017 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE, in bnx2i_conn_alloc_login_resources()
1018 bnx2i_conn->gen_pdu.req_bd_tbl, in bnx2i_conn_alloc_login_resources()
1019 bnx2i_conn->gen_pdu.req_bd_dma); in bnx2i_conn_alloc_login_resources()
1020 bnx2i_conn->gen_pdu.req_bd_tbl = NULL; in bnx2i_conn_alloc_login_resources()
1023 dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN, in bnx2i_conn_alloc_login_resources()
1024 bnx2i_conn->gen_pdu.resp_buf, in bnx2i_conn_alloc_login_resources()
1025 bnx2i_conn->gen_pdu.resp_dma_addr); in bnx2i_conn_alloc_login_resources()
1026 bnx2i_conn->gen_pdu.resp_buf = NULL; in bnx2i_conn_alloc_login_resources()
1028 dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN, in bnx2i_conn_alloc_login_resources()
1029 bnx2i_conn->gen_pdu.req_buf, in bnx2i_conn_alloc_login_resources()
1030 bnx2i_conn->gen_pdu.req_dma_addr); in bnx2i_conn_alloc_login_resources()
1031 bnx2i_conn->gen_pdu.req_buf = NULL; in bnx2i_conn_alloc_login_resources()
1033 iscsi_conn_printk(KERN_ERR, bnx2i_conn->cls_conn->dd_data, in bnx2i_conn_alloc_login_resources()
1034 "login resource alloc failed!!\n"); in bnx2i_conn_alloc_login_resources()
1035 return -ENOMEM; in bnx2i_conn_alloc_login_resources()
1041 * bnx2i_iscsi_prep_generic_pdu_bd - prepares BD table.
1051 bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.req_bd_tbl; in bnx2i_iscsi_prep_generic_pdu_bd()
1053 bd_tbl->buffer_addr_hi = in bnx2i_iscsi_prep_generic_pdu_bd()
1054 (u32) ((u64) bnx2i_conn->gen_pdu.req_dma_addr >> 32); in bnx2i_iscsi_prep_generic_pdu_bd()
1055 bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.req_dma_addr; in bnx2i_iscsi_prep_generic_pdu_bd()
1056 bd_tbl->buffer_length = bnx2i_conn->gen_pdu.req_wr_ptr - in bnx2i_iscsi_prep_generic_pdu_bd()
1057 bnx2i_conn->gen_pdu.req_buf; in bnx2i_iscsi_prep_generic_pdu_bd()
1058 bd_tbl->reserved0 = 0; in bnx2i_iscsi_prep_generic_pdu_bd()
1059 bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN | in bnx2i_iscsi_prep_generic_pdu_bd()
1062 bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.resp_bd_tbl; in bnx2i_iscsi_prep_generic_pdu_bd()
1063 bd_tbl->buffer_addr_hi = (u64) bnx2i_conn->gen_pdu.resp_dma_addr >> 32; in bnx2i_iscsi_prep_generic_pdu_bd()
1064 bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_dma_addr; in bnx2i_iscsi_prep_generic_pdu_bd()
1065 bd_tbl->buffer_length = ISCSI_DEF_MAX_RECV_SEG_LEN; in bnx2i_iscsi_prep_generic_pdu_bd()
1066 bd_tbl->reserved0 = 0; in bnx2i_iscsi_prep_generic_pdu_bd()
1067 bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN | in bnx2i_iscsi_prep_generic_pdu_bd()
1073 * bnx2i_iscsi_send_generic_request - called to send mgmt tasks.
1077 * Nop-out and Logout requests flow through this path.
1081 struct bnx2i_cmd *cmd = task->dd_data; in bnx2i_iscsi_send_generic_request()
1082 struct bnx2i_conn *bnx2i_conn = cmd->conn; in bnx2i_iscsi_send_generic_request()
1088 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { in bnx2i_iscsi_send_generic_request()
1093 data_len = bnx2i_conn->gen_pdu.req_buf_size; in bnx2i_iscsi_send_generic_request()
1094 buf = bnx2i_conn->gen_pdu.req_buf; in bnx2i_iscsi_send_generic_request()
1112 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data, in bnx2i_iscsi_send_generic_request()
1114 task->hdr->opcode); in bnx2i_iscsi_send_generic_request()
1121 * SCSI-ML Interface
1125 * bnx2i_cpy_scsi_cdb - copies LUN & CDB fields in required format to sq wqe
1126 * @sc: SCSI-ML command pointer
1129 static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd *sc, struct bnx2i_cmd *cmd) in bnx2i_cpy_scsi_cdb() argument
1137 int_to_scsilun(sc->device->lun, (struct scsi_lun *) scsi_lun); in bnx2i_cpy_scsi_cdb()
1138 cmd->req.lun[0] = be32_to_cpu(scsi_lun[0]); in bnx2i_cpy_scsi_cdb()
1139 cmd->req.lun[1] = be32_to_cpu(scsi_lun[1]); in bnx2i_cpy_scsi_cdb()
1141 lpcnt = cmd->scsi_cmd->cmd_len / sizeof(dword); in bnx2i_cpy_scsi_cdb()
1142 srcp = (u8 *) sc->cmnd; in bnx2i_cpy_scsi_cdb()
1143 dstp = (u32 *) cmd->req.cdb; in bnx2i_cpy_scsi_cdb()
1144 while (lpcnt--) { in bnx2i_cpy_scsi_cdb()
1150 if (sc->cmd_len & 0x3) { in bnx2i_cpy_scsi_cdb()
1158 struct iscsi_conn *conn = task->conn; in bnx2i_cleanup_task()
1159 struct bnx2i_conn *bnx2i_conn = conn->dd_data; in bnx2i_cleanup_task()
1160 struct bnx2i_hba *hba = bnx2i_conn->hba; in bnx2i_cleanup_task()
1165 if (!task->sc || task->state == ISCSI_TASK_PENDING) in bnx2i_cleanup_task()
1168 * need to clean-up task context to claim dma buffers in bnx2i_cleanup_task()
1170 if (task->state == ISCSI_TASK_ABRT_TMF) { in bnx2i_cleanup_task()
1171 bnx2i_send_cmd_cleanup_req(hba, task->dd_data); in bnx2i_cleanup_task()
1173 spin_unlock_bh(&conn->session->back_lock); in bnx2i_cleanup_task()
1174 wait_for_completion_timeout(&bnx2i_conn->cmd_cleanup_cmpl, in bnx2i_cleanup_task()
1176 spin_lock_bh(&conn->session->back_lock); in bnx2i_cleanup_task()
1178 bnx2i_iscsi_unmap_sg_list(task->dd_data); in bnx2i_cleanup_task()
1182 * bnx2i_mtask_xmit - transmit mtask to chip for further processing
1189 struct bnx2i_conn *bnx2i_conn = conn->dd_data; in bnx2i_mtask_xmit()
1190 struct bnx2i_hba *hba = bnx2i_conn->hba; in bnx2i_mtask_xmit()
1191 struct bnx2i_cmd *cmd = task->dd_data; in bnx2i_mtask_xmit()
1193 memset(bnx2i_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN); in bnx2i_mtask_xmit()
1196 bnx2i_conn->gen_pdu.req_buf_size = task->data_count; in bnx2i_mtask_xmit()
1200 ADD_STATS_64(hba, tx_bytes, task->data_count); in bnx2i_mtask_xmit()
1202 if (task->data_count) { in bnx2i_mtask_xmit()
1203 memcpy(bnx2i_conn->gen_pdu.req_buf, task->data, in bnx2i_mtask_xmit()
1204 task->data_count); in bnx2i_mtask_xmit()
1205 bnx2i_conn->gen_pdu.req_wr_ptr = in bnx2i_mtask_xmit()
1206 bnx2i_conn->gen_pdu.req_buf + task->data_count; in bnx2i_mtask_xmit()
1208 cmd->conn = conn->dd_data; in bnx2i_mtask_xmit()
1209 cmd->scsi_cmd = NULL; in bnx2i_mtask_xmit()
1214 * bnx2i_task_xmit - transmit iscsi command to chip for further processing
1221 struct iscsi_conn *conn = task->conn; in bnx2i_task_xmit()
1222 struct iscsi_session *session = conn->session; in bnx2i_task_xmit()
1223 struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session); in bnx2i_task_xmit()
1225 struct bnx2i_conn *bnx2i_conn = conn->dd_data; in bnx2i_task_xmit()
1226 struct scsi_cmnd *sc = task->sc; in bnx2i_task_xmit() local
1227 struct bnx2i_cmd *cmd = task->dd_data; in bnx2i_task_xmit()
1228 struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr; in bnx2i_task_xmit()
1230 if (atomic_read(&bnx2i_conn->ep->num_active_cmds) + 1 > in bnx2i_task_xmit()
1231 hba->max_sqes) in bnx2i_task_xmit()
1232 return -ENOMEM; in bnx2i_task_xmit()
1237 if (!sc) in bnx2i_task_xmit()
1241 cmd->req.op_code = ISCSI_OP_SCSI_CMD; in bnx2i_task_xmit()
1242 cmd->conn = bnx2i_conn; in bnx2i_task_xmit()
1243 cmd->scsi_cmd = sc; in bnx2i_task_xmit()
1244 cmd->req.total_data_transfer_length = scsi_bufflen(sc); in bnx2i_task_xmit()
1245 cmd->req.cmd_sn = be32_to_cpu(hdr->cmdsn); in bnx2i_task_xmit()
1248 bnx2i_cpy_scsi_cdb(sc, cmd); in bnx2i_task_xmit()
1250 cmd->req.op_attr = ISCSI_ATTR_SIMPLE; in bnx2i_task_xmit()
1251 if (sc->sc_data_direction == DMA_TO_DEVICE) { in bnx2i_task_xmit()
1252 cmd->req.op_attr |= ISCSI_CMD_REQUEST_WRITE; in bnx2i_task_xmit()
1253 cmd->req.itt = task->itt | in bnx2i_task_xmit()
1257 if (scsi_bufflen(sc)) in bnx2i_task_xmit()
1258 cmd->req.op_attr |= ISCSI_CMD_REQUEST_READ; in bnx2i_task_xmit()
1259 cmd->req.itt = task->itt | in bnx2i_task_xmit()
1263 cmd->req.num_bds = cmd->io_tbl.bd_valid; in bnx2i_task_xmit()
1264 if (!cmd->io_tbl.bd_valid) { in bnx2i_task_xmit()
1265 cmd->req.bd_list_addr_lo = (u32) hba->mp_bd_dma; in bnx2i_task_xmit()
1266 cmd->req.bd_list_addr_hi = (u32) ((u64) hba->mp_bd_dma >> 32); in bnx2i_task_xmit()
1267 cmd->req.num_bds = 1; in bnx2i_task_xmit()
1275 * bnx2i_session_create - create a new iscsi session
1298 bnx2i_ep = ep->dd_data; in bnx2i_session_create()
1299 shost = bnx2i_ep->hba->shost; in bnx2i_session_create()
1308 if (cmds_max > hba->max_sqes) in bnx2i_session_create()
1309 cmds_max = hba->max_sqes; in bnx2i_session_create()
1319 if (bnx2i_setup_cmd_pool(hba, cls_session->dd_data)) in bnx2i_session_create()
1330 * bnx2i_session_destroy - destroys iscsi session
1338 struct iscsi_session *session = cls_session->dd_data; in bnx2i_session_destroy()
1348 * bnx2i_conn_create - create iscsi connection instance
1367 conn = cls_conn->dd_data; in bnx2i_conn_create()
1369 bnx2i_conn = conn->dd_data; in bnx2i_conn_create()
1370 bnx2i_conn->cls_conn = cls_conn; in bnx2i_conn_create()
1371 bnx2i_conn->hba = hba; in bnx2i_conn_create()
1373 atomic_set(&bnx2i_conn->work_cnt, 0); in bnx2i_conn_create()
1376 bnx2i_conn->ep = NULL; in bnx2i_conn_create()
1377 init_completion(&bnx2i_conn->cmd_cleanup_cmpl); in bnx2i_conn_create()
1393 * bnx2i_conn_bind - binds iscsi sess, conn and ep objects together
1396 * @transport_fd: 64-bit EP handle
1408 struct iscsi_conn *conn = cls_conn->dd_data; in bnx2i_conn_bind()
1409 struct bnx2i_conn *bnx2i_conn = conn->dd_data; in bnx2i_conn_bind()
1418 return -EINVAL; in bnx2i_conn_bind()
1424 ret_code = -EIO; in bnx2i_conn_bind()
1428 bnx2i_ep = ep->dd_data; in bnx2i_conn_bind()
1429 if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) || in bnx2i_conn_bind()
1430 (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD)) { in bnx2i_conn_bind()
1432 ret_code = -EINVAL; in bnx2i_conn_bind()
1437 ret_code = -EINVAL; in bnx2i_conn_bind()
1441 if (bnx2i_ep->hba != hba) { in bnx2i_conn_bind()
1442 /* Error - TCP connection does not belong to this device in bnx2i_conn_bind()
1444 iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data, in bnx2i_conn_bind()
1446 bnx2i_ep, bnx2i_ep->hba->netdev->name); in bnx2i_conn_bind()
1447 iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data, in bnx2i_conn_bind()
1449 hba->netdev->name); in bnx2i_conn_bind()
1450 ret_code = -EEXIST; in bnx2i_conn_bind()
1453 bnx2i_ep->conn = bnx2i_conn; in bnx2i_conn_bind()
1454 bnx2i_conn->ep = bnx2i_ep; in bnx2i_conn_bind()
1455 bnx2i_conn->iscsi_conn_cid = bnx2i_ep->ep_iscsi_cid; in bnx2i_conn_bind()
1456 bnx2i_conn->fw_cid = bnx2i_ep->ep_cid; in bnx2i_conn_bind()
1459 bnx2i_ep->ep_iscsi_cid); in bnx2i_conn_bind()
1464 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type)) in bnx2i_conn_bind()
1467 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE); in bnx2i_conn_bind()
1475 * bnx2i_conn_destroy - destroy iscsi connection instance & release resources
1483 struct iscsi_conn *conn = cls_conn->dd_data; in bnx2i_conn_destroy()
1484 struct bnx2i_conn *bnx2i_conn = conn->dd_data; in bnx2i_conn_destroy()
1496 if (atomic_read(&bnx2i_conn->work_cnt)) { in bnx2i_conn_destroy()
1499 spin_lock_bh(&p->p_work_lock); in bnx2i_conn_destroy()
1501 &p->work_list, list) { in bnx2i_conn_destroy()
1502 if (work->session == conn->session && in bnx2i_conn_destroy()
1503 work->bnx2i_conn == bnx2i_conn) { in bnx2i_conn_destroy()
1504 list_del_init(&work->list); in bnx2i_conn_destroy()
1507 &bnx2i_conn->work_cnt)) in bnx2i_conn_destroy()
1511 spin_unlock_bh(&p->p_work_lock); in bnx2i_conn_destroy()
1520 * bnx2i_ep_get_param - return iscsi ep parameter to caller
1530 struct bnx2i_endpoint *bnx2i_ep = ep->dd_data; in bnx2i_ep_get_param()
1531 struct bnx2i_hba *hba = bnx2i_ep->hba; in bnx2i_ep_get_param()
1532 int len = -ENOTCONN; in bnx2i_ep_get_param()
1535 return -ENOTCONN; in bnx2i_ep_get_param()
1539 mutex_lock(&hba->net_dev_lock); in bnx2i_ep_get_param()
1540 if (bnx2i_ep->cm_sk) in bnx2i_ep_get_param()
1541 len = sprintf(buf, "%hu\n", bnx2i_ep->cm_sk->dst_port); in bnx2i_ep_get_param()
1542 mutex_unlock(&hba->net_dev_lock); in bnx2i_ep_get_param()
1545 mutex_lock(&hba->net_dev_lock); in bnx2i_ep_get_param()
1546 if (bnx2i_ep->cm_sk) in bnx2i_ep_get_param()
1547 len = sprintf(buf, "%pI4\n", &bnx2i_ep->cm_sk->dst_ip); in bnx2i_ep_get_param()
1548 mutex_unlock(&hba->net_dev_lock); in bnx2i_ep_get_param()
1551 return -ENOSYS; in bnx2i_ep_get_param()
1558 * bnx2i_host_get_param - returns host (adapter) related parameters
1571 len = sysfs_format_mac(buf, hba->cnic->mac_addr, 6); in bnx2i_host_get_param()
1574 len = sprintf(buf, "%s\n", hba->netdev->name); in bnx2i_host_get_param()
1577 struct list_head *active_list = &hba->ep_active_list; in bnx2i_host_get_param()
1579 read_lock_bh(&hba->ep_rdwr_lock); in bnx2i_host_get_param()
1580 if (!list_empty(&hba->ep_active_list)) { in bnx2i_host_get_param()
1587 csk = bnx2i_ep->cm_sk; in bnx2i_host_get_param()
1588 if (test_bit(SK_F_IPV6, &csk->flags)) in bnx2i_host_get_param()
1589 len = sprintf(buf, "%pI6\n", csk->src_ip); in bnx2i_host_get_param()
1591 len = sprintf(buf, "%pI4\n", csk->src_ip); in bnx2i_host_get_param()
1593 read_unlock_bh(&hba->ep_rdwr_lock); in bnx2i_host_get_param()
1603 * bnx2i_conn_start - completes iscsi connection migration to FFP
1610 struct iscsi_conn *conn = cls_conn->dd_data; in bnx2i_conn_start()
1611 struct bnx2i_conn *bnx2i_conn = conn->dd_data; in bnx2i_conn_start()
1613 bnx2i_conn->ep->state = EP_STATE_ULP_UPDATE_START; in bnx2i_conn_start()
1620 timer_setup(&bnx2i_conn->ep->ofld_timer, bnx2i_ep_ofld_timer, 0); in bnx2i_conn_start()
1621 bnx2i_conn->ep->ofld_timer.expires = 1 * HZ + jiffies; in bnx2i_conn_start()
1622 add_timer(&bnx2i_conn->ep->ofld_timer); in bnx2i_conn_start()
1624 wait_event_interruptible(bnx2i_conn->ep->ofld_wait, in bnx2i_conn_start()
1625 bnx2i_conn->ep->state != EP_STATE_ULP_UPDATE_START); in bnx2i_conn_start()
1629 del_timer_sync(&bnx2i_conn->ep->ofld_timer); in bnx2i_conn_start()
1637 * bnx2i_conn_get_stats - returns iSCSI stats
1644 struct iscsi_conn *conn = cls_conn->dd_data; in bnx2i_conn_get_stats()
1646 stats->txdata_octets = conn->txdata_octets; in bnx2i_conn_get_stats()
1647 stats->rxdata_octets = conn->rxdata_octets; in bnx2i_conn_get_stats()
1648 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; in bnx2i_conn_get_stats()
1649 stats->dataout_pdus = conn->dataout_pdus_cnt; in bnx2i_conn_get_stats()
1650 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; in bnx2i_conn_get_stats()
1651 stats->datain_pdus = conn->datain_pdus_cnt; in bnx2i_conn_get_stats()
1652 stats->r2t_pdus = conn->r2t_pdus_cnt; in bnx2i_conn_get_stats()
1653 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; in bnx2i_conn_get_stats()
1654 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; in bnx2i_conn_get_stats()
1655 stats->digest_err = 0; in bnx2i_conn_get_stats()
1656 stats->timeout_err = 0; in bnx2i_conn_get_stats()
1657 strcpy(stats->custom[0].desc, "eh_abort_cnt"); in bnx2i_conn_get_stats()
1658 stats->custom[0].value = conn->eh_abort_cnt; in bnx2i_conn_get_stats()
1659 stats->custom_length = 1; in bnx2i_conn_get_stats()
1664 * bnx2i_check_route - checks if target IP route belongs to one of NX2 devices
1676 if (hba && hba->cnic) in bnx2i_check_route()
1677 cnic = hba->cnic->cm_select_dev(desti, CNIC_ULP_ISCSI); in bnx2i_check_route()
1691 if (hba->netdev->mtu > hba->mtu_supported) { in bnx2i_check_route()
1693 hba->netdev->name, hba->netdev->mtu); in bnx2i_check_route()
1695 hba->mtu_supported); in bnx2i_check_route()
1705 * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources
1714 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic) && ep->cm_sk) in bnx2i_tear_down_conn()
1715 hba->cnic->cm_destroy(ep->cm_sk); in bnx2i_tear_down_conn()
1717 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type) && in bnx2i_tear_down_conn()
1718 ep->state == EP_STATE_DISCONN_TIMEDOUT) { in bnx2i_tear_down_conn()
1719 if (ep->conn && ep->conn->cls_conn && in bnx2i_tear_down_conn()
1720 ep->conn->cls_conn->dd_data) { in bnx2i_tear_down_conn()
1721 struct iscsi_conn *conn = ep->conn->cls_conn->dd_data; in bnx2i_tear_down_conn()
1724 set_bit(ISCSI_CONN_FLAG_SUSPEND_RX, &conn->flags); in bnx2i_tear_down_conn()
1730 printk(KERN_ALERT "bnx2i (%s): - WARN - CONN_DISCON timed out, " in bnx2i_tear_down_conn()
1733 hba->netdev->name); in bnx2i_tear_down_conn()
1736 ep->state = EP_STATE_CLEANUP_START; in bnx2i_tear_down_conn()
1737 timer_setup(&ep->ofld_timer, bnx2i_ep_ofld_timer, 0); in bnx2i_tear_down_conn()
1738 ep->ofld_timer.expires = hba->conn_ctx_destroy_tmo + jiffies; in bnx2i_tear_down_conn()
1739 add_timer(&ep->ofld_timer); in bnx2i_tear_down_conn()
1745 ep->state = EP_STATE_CLEANUP_CMPL; in bnx2i_tear_down_conn()
1747 wait_event_interruptible(ep->ofld_wait, in bnx2i_tear_down_conn()
1748 (ep->state != EP_STATE_CLEANUP_START)); in bnx2i_tear_down_conn()
1752 del_timer_sync(&ep->ofld_timer); in bnx2i_tear_down_conn()
1756 if (ep->state != EP_STATE_CLEANUP_CMPL) in bnx2i_tear_down_conn()
1758 printk(KERN_ALERT "bnx2i - conn destroy failed\n"); in bnx2i_tear_down_conn()
1765 * bnx2i_ep_connect - establish TCP connection to target portal
1768 * @non_blocking: blocking or non-blocking call
1770 * this routine initiates the TCP/IP connection by invoking Option-2 i/f
1771 * with l5_core and the CNIC. This is a multi-step process of resolving
1774 * sending down option-2 request to complete TCP 3-way handshake
1801 rc = -EINVAL; in bnx2i_ep_connect()
1804 mutex_lock(&hba->net_dev_lock); in bnx2i_ep_connect()
1806 if (bnx2i_adapter_ready(hba) || !hba->cid_que.cid_free_cnt) { in bnx2i_ep_connect()
1807 rc = -EPERM; in bnx2i_ep_connect()
1810 cnic = hba->cnic; in bnx2i_ep_connect()
1813 rc = -ENOMEM; in bnx2i_ep_connect()
1816 bnx2i_ep = ep->dd_data; in bnx2i_ep_connect()
1818 atomic_set(&bnx2i_ep->num_active_cmds, 0); in bnx2i_ep_connect()
1820 if (iscsi_cid == -1) { in bnx2i_ep_connect()
1821 printk(KERN_ALERT "bnx2i (%s): alloc_ep - unable to allocate " in bnx2i_ep_connect()
1822 "iscsi cid\n", hba->netdev->name); in bnx2i_ep_connect()
1823 rc = -ENOMEM; in bnx2i_ep_connect()
1827 bnx2i_ep->hba_age = hba->age; in bnx2i_ep_connect()
1831 printk(KERN_ALERT "bnx2i (%s): ep_conn - alloc QP resc error" in bnx2i_ep_connect()
1832 "\n", hba->netdev->name); in bnx2i_ep_connect()
1833 rc = -ENOMEM; in bnx2i_ep_connect()
1837 bnx2i_ep->ep_iscsi_cid = (u16)iscsi_cid; in bnx2i_ep_connect()
1838 bnx2i_ep->state = EP_STATE_OFLD_START; in bnx2i_ep_connect()
1841 timer_setup(&bnx2i_ep->ofld_timer, bnx2i_ep_ofld_timer, 0); in bnx2i_ep_connect()
1842 bnx2i_ep->ofld_timer.expires = 2 * HZ + jiffies; in bnx2i_ep_connect()
1843 add_timer(&bnx2i_ep->ofld_timer); in bnx2i_ep_connect()
1846 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) { in bnx2i_ep_connect()
1848 hba->netdev->name, bnx2i_ep->ep_iscsi_cid); in bnx2i_ep_connect()
1849 rc = -EBUSY; in bnx2i_ep_connect()
1851 rc = -ENOSPC; in bnx2i_ep_connect()
1853 "\n", hba->netdev->name); in bnx2i_ep_connect()
1859 wait_event_interruptible(bnx2i_ep->ofld_wait, in bnx2i_ep_connect()
1860 bnx2i_ep->state != EP_STATE_OFLD_START); in bnx2i_ep_connect()
1864 del_timer_sync(&bnx2i_ep->ofld_timer); in bnx2i_ep_connect()
1868 if (bnx2i_ep->state != EP_STATE_OFLD_COMPL) { in bnx2i_ep_connect()
1869 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) { in bnx2i_ep_connect()
1871 hba->netdev->name, bnx2i_ep->ep_iscsi_cid); in bnx2i_ep_connect()
1872 rc = -EBUSY; in bnx2i_ep_connect()
1874 rc = -ENOSPC; in bnx2i_ep_connect()
1878 rc = cnic->cm_create(cnic, CNIC_ULP_ISCSI, bnx2i_ep->ep_cid, in bnx2i_ep_connect()
1879 iscsi_cid, &bnx2i_ep->cm_sk, bnx2i_ep); in bnx2i_ep_connect()
1881 rc = -EINVAL; in bnx2i_ep_connect()
1886 bnx2i_ep->cm_sk->rcv_buf = 256 * 1024; in bnx2i_ep_connect()
1887 bnx2i_ep->cm_sk->snd_buf = 256 * 1024; in bnx2i_ep_connect()
1888 clear_bit(SK_TCP_TIMESTAMP, &bnx2i_ep->cm_sk->tcp_flags); in bnx2i_ep_connect()
1891 if (dst_addr->sa_family == AF_INET) { in bnx2i_ep_connect()
1894 saddr.local.v4.sin_family = desti->sin_family; in bnx2i_ep_connect()
1895 } else if (dst_addr->sa_family == AF_INET6) { in bnx2i_ep_connect()
1898 saddr.local.v6.sin6_family = desti6->sin6_family; in bnx2i_ep_connect()
1901 bnx2i_ep->timestamp = jiffies; in bnx2i_ep_connect()
1902 bnx2i_ep->state = EP_STATE_CONNECT_START; in bnx2i_ep_connect()
1903 if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) { in bnx2i_ep_connect()
1904 rc = -EINVAL; in bnx2i_ep_connect()
1907 rc = cnic->cm_connect(bnx2i_ep->cm_sk, &saddr); in bnx2i_ep_connect()
1917 mutex_unlock(&hba->net_dev_lock); in bnx2i_ep_connect()
1924 mutex_unlock(&hba->net_dev_lock); in bnx2i_ep_connect()
1932 mutex_unlock(&hba->net_dev_lock); in bnx2i_ep_connect()
1939 * bnx2i_ep_poll - polls for TCP connection establishement
1950 bnx2i_ep = ep->dd_data; in bnx2i_ep_poll()
1951 if ((bnx2i_ep->state == EP_STATE_IDLE) || in bnx2i_ep_poll()
1952 (bnx2i_ep->state == EP_STATE_CONNECT_FAILED) || in bnx2i_ep_poll()
1953 (bnx2i_ep->state == EP_STATE_OFLD_FAILED)) in bnx2i_ep_poll()
1954 return -1; in bnx2i_ep_poll()
1955 if (bnx2i_ep->state == EP_STATE_CONNECT_COMPL) in bnx2i_ep_poll()
1958 rc = wait_event_interruptible_timeout(bnx2i_ep->ofld_wait, in bnx2i_ep_poll()
1959 ((bnx2i_ep->state == in bnx2i_ep_poll()
1961 (bnx2i_ep->state == in bnx2i_ep_poll()
1963 (bnx2i_ep->state == in bnx2i_ep_poll()
1966 if (bnx2i_ep->state == EP_STATE_OFLD_FAILED) in bnx2i_ep_poll()
1967 rc = -1; in bnx2i_ep_poll()
1979 * bnx2i_ep_tcp_conn_active - check EP state transition
1989 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type)) in bnx2i_ep_tcp_conn_active()
1992 switch (bnx2i_ep->state) { in bnx2i_ep_tcp_conn_active()
2024 * bnx2i_hw_ep_disconnect - executes TCP connection teardown process in the hw
2031 struct bnx2i_hba *hba = bnx2i_ep->hba; in bnx2i_hw_ep_disconnect()
2042 cnic = hba->cnic; in bnx2i_hw_ep_disconnect()
2046 if (bnx2i_ep->state == EP_STATE_IDLE || in bnx2i_hw_ep_disconnect()
2047 bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT) in bnx2i_hw_ep_disconnect()
2053 if (bnx2i_ep->conn) { in bnx2i_hw_ep_disconnect()
2054 conn = bnx2i_ep->conn->cls_conn->dd_data; in bnx2i_hw_ep_disconnect()
2055 session = conn->session; in bnx2i_hw_ep_disconnect()
2058 timer_setup(&bnx2i_ep->ofld_timer, bnx2i_ep_ofld_timer, 0); in bnx2i_hw_ep_disconnect()
2059 bnx2i_ep->ofld_timer.expires = hba->conn_teardown_tmo + jiffies; in bnx2i_hw_ep_disconnect()
2060 add_timer(&bnx2i_ep->ofld_timer); in bnx2i_hw_ep_disconnect()
2062 if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) in bnx2i_hw_ep_disconnect()
2066 spin_lock_bh(&session->frwd_lock); in bnx2i_hw_ep_disconnect()
2067 if (bnx2i_ep->state != EP_STATE_TCP_FIN_RCVD) { in bnx2i_hw_ep_disconnect()
2068 if (session->state == ISCSI_STATE_LOGGING_OUT) { in bnx2i_hw_ep_disconnect()
2069 if (bnx2i_ep->state == EP_STATE_LOGOUT_SENT) { in bnx2i_hw_ep_disconnect()
2074 bnx2i_ep->hba->netdev->name); in bnx2i_hw_ep_disconnect()
2075 } else if (bnx2i_ep->state == in bnx2i_hw_ep_disconnect()
2082 spin_unlock_bh(&session->frwd_lock); in bnx2i_hw_ep_disconnect()
2085 bnx2i_ep->state = EP_STATE_DISCONN_START; in bnx2i_hw_ep_disconnect()
2088 close_ret = cnic->cm_close(bnx2i_ep->cm_sk); in bnx2i_hw_ep_disconnect()
2090 close_ret = cnic->cm_abort(bnx2i_ep->cm_sk); in bnx2i_hw_ep_disconnect()
2094 bnx2i_ep->hba->netdev->name, close, close_ret); in bnx2i_hw_ep_disconnect()
2096 /* wait for option-2 conn teardown */ in bnx2i_hw_ep_disconnect()
2097 wait_event_interruptible(bnx2i_ep->ofld_wait, in bnx2i_hw_ep_disconnect()
2098 ((bnx2i_ep->state != EP_STATE_DISCONN_START) in bnx2i_hw_ep_disconnect()
2099 && (bnx2i_ep->state != EP_STATE_TCP_FIN_RCVD))); in bnx2i_hw_ep_disconnect()
2103 del_timer_sync(&bnx2i_ep->ofld_timer); in bnx2i_hw_ep_disconnect()
2108 return -EINVAL; in bnx2i_hw_ep_disconnect()
2110 bnx2i_ep->state = EP_STATE_IDLE; in bnx2i_hw_ep_disconnect()
2116 * bnx2i_ep_disconnect - executes TCP connection teardown process
2127 bnx2i_ep = ep->dd_data; in bnx2i_ep_disconnect()
2130 * completes either successfully or fails. Timeout is 9-secs, so in bnx2i_ep_disconnect()
2133 while ((bnx2i_ep->state == EP_STATE_CONNECT_START) && in bnx2i_ep_disconnect()
2134 !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ))) in bnx2i_ep_disconnect()
2137 if (bnx2i_ep->conn) in bnx2i_ep_disconnect()
2138 bnx2i_conn = bnx2i_ep->conn; in bnx2i_ep_disconnect()
2139 hba = bnx2i_ep->hba; in bnx2i_ep_disconnect()
2141 mutex_lock(&hba->net_dev_lock); in bnx2i_ep_disconnect()
2143 if (bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT) in bnx2i_ep_disconnect()
2146 if (bnx2i_ep->state == EP_STATE_IDLE) in bnx2i_ep_disconnect()
2149 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) || in bnx2i_ep_disconnect()
2150 (bnx2i_ep->hba_age != hba->age)) { in bnx2i_ep_disconnect()
2157 mutex_unlock(&hba->net_dev_lock); in bnx2i_ep_disconnect()
2164 bnx2i_conn->ep = NULL; in bnx2i_ep_disconnect()
2168 mutex_unlock(&hba->net_dev_lock); in bnx2i_ep_disconnect()
2170 wake_up_interruptible(&hba->eh_wait); in bnx2i_ep_disconnect()
2175 * bnx2i_nl_set_path - ISCSI_UEVENT_PATH_UPDATE user message handler
2186 hba->cnic->iscsi_nl_msg_recv(hba->cnic, ISCSI_UEVENT_PATH_UPDATE, buf, in bnx2i_nl_set_path()
2267 .this_id = -1,
2297 /* TCP connect - disconnect - option-2 interface calls */