1853e2bd2SBhanu Gollapudi /* bnx2fc_hwi.c: Broadcom NetXtreme II Linux FCoE offload driver. 2853e2bd2SBhanu Gollapudi * This file contains the code that low level functions that interact 3853e2bd2SBhanu Gollapudi * with 57712 FCoE firmware. 4853e2bd2SBhanu Gollapudi * 5853e2bd2SBhanu Gollapudi * Copyright (c) 2008 - 2010 Broadcom Corporation 6853e2bd2SBhanu Gollapudi * 7853e2bd2SBhanu Gollapudi * This program is free software; you can redistribute it and/or modify 8853e2bd2SBhanu Gollapudi * it under the terms of the GNU General Public License as published by 9853e2bd2SBhanu Gollapudi * the Free Software Foundation. 10853e2bd2SBhanu Gollapudi * 11853e2bd2SBhanu Gollapudi * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com) 12853e2bd2SBhanu Gollapudi */ 13853e2bd2SBhanu Gollapudi 14853e2bd2SBhanu Gollapudi #include "bnx2fc.h" 15853e2bd2SBhanu Gollapudi 16853e2bd2SBhanu Gollapudi DECLARE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu); 17853e2bd2SBhanu Gollapudi 18853e2bd2SBhanu Gollapudi static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba, 19853e2bd2SBhanu Gollapudi struct fcoe_kcqe *new_cqe_kcqe); 20853e2bd2SBhanu Gollapudi static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba, 21853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe); 22853e2bd2SBhanu Gollapudi static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba, 23853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe); 24853e2bd2SBhanu Gollapudi static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code); 25853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba, 26*aea71a02SBhanu Prakash Gollapudi struct fcoe_kcqe *destroy_kcqe); 27853e2bd2SBhanu Gollapudi 28853e2bd2SBhanu Gollapudi int bnx2fc_send_stat_req(struct bnx2fc_hba *hba) 29853e2bd2SBhanu Gollapudi { 30853e2bd2SBhanu Gollapudi struct fcoe_kwqe_stat stat_req; 31853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 32853e2bd2SBhanu Gollapudi int num_kwqes = 1; 33853e2bd2SBhanu Gollapudi int rc = 0; 34853e2bd2SBhanu Gollapudi 35853e2bd2SBhanu Gollapudi memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat)); 36853e2bd2SBhanu Gollapudi stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT; 37853e2bd2SBhanu Gollapudi stat_req.hdr.flags = 38853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 39853e2bd2SBhanu Gollapudi 40853e2bd2SBhanu Gollapudi stat_req.stat_params_addr_lo = (u32) hba->stats_buf_dma; 41853e2bd2SBhanu Gollapudi stat_req.stat_params_addr_hi = (u32) ((u64)hba->stats_buf_dma >> 32); 42853e2bd2SBhanu Gollapudi 43853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &stat_req; 44853e2bd2SBhanu Gollapudi 45853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 46853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 47853e2bd2SBhanu Gollapudi 48853e2bd2SBhanu Gollapudi return rc; 49853e2bd2SBhanu Gollapudi } 50853e2bd2SBhanu Gollapudi 51853e2bd2SBhanu Gollapudi /** 52853e2bd2SBhanu Gollapudi * bnx2fc_send_fw_fcoe_init_msg - initiates initial handshake with FCoE f/w 53853e2bd2SBhanu Gollapudi * 54853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 55853e2bd2SBhanu Gollapudi * 56853e2bd2SBhanu Gollapudi * Send down FCoE firmware init KWQEs which initiates the initial handshake 57853e2bd2SBhanu Gollapudi * with the f/w. 58853e2bd2SBhanu Gollapudi * 59853e2bd2SBhanu Gollapudi */ 60853e2bd2SBhanu Gollapudi int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba) 61853e2bd2SBhanu Gollapudi { 62853e2bd2SBhanu Gollapudi struct fcoe_kwqe_init1 fcoe_init1; 63853e2bd2SBhanu Gollapudi struct fcoe_kwqe_init2 fcoe_init2; 64853e2bd2SBhanu Gollapudi struct fcoe_kwqe_init3 fcoe_init3; 65853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[3]; 66853e2bd2SBhanu Gollapudi int num_kwqes = 3; 67853e2bd2SBhanu Gollapudi int rc = 0; 68853e2bd2SBhanu Gollapudi 69853e2bd2SBhanu Gollapudi if (!hba->cnic) { 70*aea71a02SBhanu Prakash Gollapudi printk(KERN_ERR PFX "hba->cnic NULL during fcoe fw init\n"); 71853e2bd2SBhanu Gollapudi return -ENODEV; 72853e2bd2SBhanu Gollapudi } 73853e2bd2SBhanu Gollapudi 74853e2bd2SBhanu Gollapudi /* fill init1 KWQE */ 75853e2bd2SBhanu Gollapudi memset(&fcoe_init1, 0x00, sizeof(struct fcoe_kwqe_init1)); 76853e2bd2SBhanu Gollapudi fcoe_init1.hdr.op_code = FCOE_KWQE_OPCODE_INIT1; 77853e2bd2SBhanu Gollapudi fcoe_init1.hdr.flags = (FCOE_KWQE_LAYER_CODE << 78853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 79853e2bd2SBhanu Gollapudi 80853e2bd2SBhanu Gollapudi fcoe_init1.num_tasks = BNX2FC_MAX_TASKS; 81853e2bd2SBhanu Gollapudi fcoe_init1.sq_num_wqes = BNX2FC_SQ_WQES_MAX; 82853e2bd2SBhanu Gollapudi fcoe_init1.rq_num_wqes = BNX2FC_RQ_WQES_MAX; 83853e2bd2SBhanu Gollapudi fcoe_init1.rq_buffer_log_size = BNX2FC_RQ_BUF_LOG_SZ; 84853e2bd2SBhanu Gollapudi fcoe_init1.cq_num_wqes = BNX2FC_CQ_WQES_MAX; 85853e2bd2SBhanu Gollapudi fcoe_init1.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma; 86853e2bd2SBhanu Gollapudi fcoe_init1.dummy_buffer_addr_hi = (u32) ((u64)hba->dummy_buf_dma >> 32); 87853e2bd2SBhanu Gollapudi fcoe_init1.task_list_pbl_addr_lo = (u32) hba->task_ctx_bd_dma; 88853e2bd2SBhanu Gollapudi fcoe_init1.task_list_pbl_addr_hi = 89853e2bd2SBhanu Gollapudi (u32) ((u64) hba->task_ctx_bd_dma >> 32); 901294bfe6SBhanu Gollapudi fcoe_init1.mtu = BNX2FC_MINI_JUMBO_MTU; 91853e2bd2SBhanu Gollapudi 92853e2bd2SBhanu Gollapudi fcoe_init1.flags = (PAGE_SHIFT << 93853e2bd2SBhanu Gollapudi FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT); 94853e2bd2SBhanu Gollapudi 95853e2bd2SBhanu Gollapudi fcoe_init1.num_sessions_log = BNX2FC_NUM_MAX_SESS_LOG; 96853e2bd2SBhanu Gollapudi 97853e2bd2SBhanu Gollapudi /* fill init2 KWQE */ 98853e2bd2SBhanu Gollapudi memset(&fcoe_init2, 0x00, sizeof(struct fcoe_kwqe_init2)); 99853e2bd2SBhanu Gollapudi fcoe_init2.hdr.op_code = FCOE_KWQE_OPCODE_INIT2; 100853e2bd2SBhanu Gollapudi fcoe_init2.hdr.flags = (FCOE_KWQE_LAYER_CODE << 101853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 102853e2bd2SBhanu Gollapudi 103619c5cb6SVlad Zolotarov fcoe_init2.hsi_major_version = FCOE_HSI_MAJOR_VERSION; 104619c5cb6SVlad Zolotarov fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION; 105619c5cb6SVlad Zolotarov 106*aea71a02SBhanu Prakash Gollapudi 107853e2bd2SBhanu Gollapudi fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma; 108853e2bd2SBhanu Gollapudi fcoe_init2.hash_tbl_pbl_addr_hi = (u32) 109853e2bd2SBhanu Gollapudi ((u64) hba->hash_tbl_pbl_dma >> 32); 110853e2bd2SBhanu Gollapudi 111853e2bd2SBhanu Gollapudi fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma; 112853e2bd2SBhanu Gollapudi fcoe_init2.t2_hash_tbl_addr_hi = (u32) 113853e2bd2SBhanu Gollapudi ((u64) hba->t2_hash_tbl_dma >> 32); 114853e2bd2SBhanu Gollapudi 115853e2bd2SBhanu Gollapudi fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma; 116853e2bd2SBhanu Gollapudi fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32) 117853e2bd2SBhanu Gollapudi ((u64) hba->t2_hash_tbl_ptr_dma >> 32); 118853e2bd2SBhanu Gollapudi 119853e2bd2SBhanu Gollapudi fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS; 120853e2bd2SBhanu Gollapudi 121853e2bd2SBhanu Gollapudi /* fill init3 KWQE */ 122853e2bd2SBhanu Gollapudi memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3)); 123853e2bd2SBhanu Gollapudi fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3; 124853e2bd2SBhanu Gollapudi fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE << 125853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 126853e2bd2SBhanu Gollapudi fcoe_init3.error_bit_map_lo = 0xffffffff; 127853e2bd2SBhanu Gollapudi fcoe_init3.error_bit_map_hi = 0xffffffff; 128853e2bd2SBhanu Gollapudi 129619c5cb6SVlad Zolotarov fcoe_init3.perf_config = 1; 130853e2bd2SBhanu Gollapudi 131853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &fcoe_init1; 132853e2bd2SBhanu Gollapudi kwqe_arr[1] = (struct kwqe *) &fcoe_init2; 133853e2bd2SBhanu Gollapudi kwqe_arr[2] = (struct kwqe *) &fcoe_init3; 134853e2bd2SBhanu Gollapudi 135853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 136853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 137853e2bd2SBhanu Gollapudi 138853e2bd2SBhanu Gollapudi return rc; 139853e2bd2SBhanu Gollapudi } 140853e2bd2SBhanu Gollapudi int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba) 141853e2bd2SBhanu Gollapudi { 142853e2bd2SBhanu Gollapudi struct fcoe_kwqe_destroy fcoe_destroy; 143853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 144853e2bd2SBhanu Gollapudi int num_kwqes = 1; 145853e2bd2SBhanu Gollapudi int rc = -1; 146853e2bd2SBhanu Gollapudi 147853e2bd2SBhanu Gollapudi /* fill destroy KWQE */ 148853e2bd2SBhanu Gollapudi memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy)); 149853e2bd2SBhanu Gollapudi fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY; 150853e2bd2SBhanu Gollapudi fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE << 151853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 152853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &fcoe_destroy; 153853e2bd2SBhanu Gollapudi 154853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 155853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 156853e2bd2SBhanu Gollapudi return rc; 157853e2bd2SBhanu Gollapudi } 158853e2bd2SBhanu Gollapudi 159853e2bd2SBhanu Gollapudi /** 160853e2bd2SBhanu Gollapudi * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process 161853e2bd2SBhanu Gollapudi * 162853e2bd2SBhanu Gollapudi * @port: port structure pointer 163853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 164853e2bd2SBhanu Gollapudi */ 165853e2bd2SBhanu Gollapudi int bnx2fc_send_session_ofld_req(struct fcoe_port *port, 166853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 167853e2bd2SBhanu Gollapudi { 168853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport; 169*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv; 170*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba; 171853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[4]; 172853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload1 ofld_req1; 173853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload2 ofld_req2; 174853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload3 ofld_req3; 175853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload4 ofld_req4; 176853e2bd2SBhanu Gollapudi struct fc_rport_priv *rdata = tgt->rdata; 177853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport; 178853e2bd2SBhanu Gollapudi int num_kwqes = 4; 179853e2bd2SBhanu Gollapudi u32 port_id; 180853e2bd2SBhanu Gollapudi int rc = 0; 181853e2bd2SBhanu Gollapudi u16 conn_id; 182853e2bd2SBhanu Gollapudi 183853e2bd2SBhanu Gollapudi /* Initialize offload request 1 structure */ 184853e2bd2SBhanu Gollapudi memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1)); 185853e2bd2SBhanu Gollapudi 186853e2bd2SBhanu Gollapudi ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1; 187853e2bd2SBhanu Gollapudi ofld_req1.hdr.flags = 188853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 189853e2bd2SBhanu Gollapudi 190853e2bd2SBhanu Gollapudi 191853e2bd2SBhanu Gollapudi conn_id = (u16)tgt->fcoe_conn_id; 192853e2bd2SBhanu Gollapudi ofld_req1.fcoe_conn_id = conn_id; 193853e2bd2SBhanu Gollapudi 194853e2bd2SBhanu Gollapudi 195853e2bd2SBhanu Gollapudi ofld_req1.sq_addr_lo = (u32) tgt->sq_dma; 196853e2bd2SBhanu Gollapudi ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32); 197853e2bd2SBhanu Gollapudi 198853e2bd2SBhanu Gollapudi ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma; 199853e2bd2SBhanu Gollapudi ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32); 200853e2bd2SBhanu Gollapudi 201853e2bd2SBhanu Gollapudi ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma; 202853e2bd2SBhanu Gollapudi ofld_req1.rq_first_pbe_addr_hi = 203853e2bd2SBhanu Gollapudi (u32)((u64) tgt->rq_dma >> 32); 204853e2bd2SBhanu Gollapudi 205853e2bd2SBhanu Gollapudi ofld_req1.rq_prod = 0x8000; 206853e2bd2SBhanu Gollapudi 207853e2bd2SBhanu Gollapudi /* Initialize offload request 2 structure */ 208853e2bd2SBhanu Gollapudi memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2)); 209853e2bd2SBhanu Gollapudi 210853e2bd2SBhanu Gollapudi ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2; 211853e2bd2SBhanu Gollapudi ofld_req2.hdr.flags = 212853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 213853e2bd2SBhanu Gollapudi 214853e2bd2SBhanu Gollapudi ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size; 215853e2bd2SBhanu Gollapudi 216853e2bd2SBhanu Gollapudi ofld_req2.cq_addr_lo = (u32) tgt->cq_dma; 217853e2bd2SBhanu Gollapudi ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32); 218853e2bd2SBhanu Gollapudi 219853e2bd2SBhanu Gollapudi ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma; 220853e2bd2SBhanu Gollapudi ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32); 221853e2bd2SBhanu Gollapudi 222853e2bd2SBhanu Gollapudi ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma; 223853e2bd2SBhanu Gollapudi ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32); 224853e2bd2SBhanu Gollapudi 225853e2bd2SBhanu Gollapudi /* Initialize offload request 3 structure */ 226853e2bd2SBhanu Gollapudi memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3)); 227853e2bd2SBhanu Gollapudi 228853e2bd2SBhanu Gollapudi ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3; 229853e2bd2SBhanu Gollapudi ofld_req3.hdr.flags = 230853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 231853e2bd2SBhanu Gollapudi 232*aea71a02SBhanu Prakash Gollapudi ofld_req3.vlan_tag = interface->vlan_id << 233853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT; 234853e2bd2SBhanu Gollapudi ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT; 235853e2bd2SBhanu Gollapudi 236853e2bd2SBhanu Gollapudi port_id = fc_host_port_id(lport->host); 237853e2bd2SBhanu Gollapudi if (port_id == 0) { 238853e2bd2SBhanu Gollapudi BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n"); 239853e2bd2SBhanu Gollapudi return -EINVAL; 240853e2bd2SBhanu Gollapudi } 241853e2bd2SBhanu Gollapudi 242853e2bd2SBhanu Gollapudi /* 243853e2bd2SBhanu Gollapudi * Store s_id of the initiator for further reference. This will 244853e2bd2SBhanu Gollapudi * be used during disable/destroy during linkdown processing as 245853e2bd2SBhanu Gollapudi * when the lport is reset, the port_id also is reset to 0 246853e2bd2SBhanu Gollapudi */ 247853e2bd2SBhanu Gollapudi tgt->sid = port_id; 248853e2bd2SBhanu Gollapudi ofld_req3.s_id[0] = (port_id & 0x000000FF); 249853e2bd2SBhanu Gollapudi ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8; 250853e2bd2SBhanu Gollapudi ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16; 251853e2bd2SBhanu Gollapudi 252853e2bd2SBhanu Gollapudi port_id = rport->port_id; 253853e2bd2SBhanu Gollapudi ofld_req3.d_id[0] = (port_id & 0x000000FF); 254853e2bd2SBhanu Gollapudi ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8; 255853e2bd2SBhanu Gollapudi ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16; 256853e2bd2SBhanu Gollapudi 257853e2bd2SBhanu Gollapudi ofld_req3.tx_total_conc_seqs = rdata->max_seq; 258853e2bd2SBhanu Gollapudi 259853e2bd2SBhanu Gollapudi ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq; 260853e2bd2SBhanu Gollapudi ofld_req3.rx_max_fc_pay_len = lport->mfs; 261853e2bd2SBhanu Gollapudi 262853e2bd2SBhanu Gollapudi ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS; 263853e2bd2SBhanu Gollapudi ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS; 264853e2bd2SBhanu Gollapudi ofld_req3.rx_open_seqs_exch_c3 = 1; 265853e2bd2SBhanu Gollapudi 266853e2bd2SBhanu Gollapudi ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma; 267853e2bd2SBhanu Gollapudi ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32); 268853e2bd2SBhanu Gollapudi 269853e2bd2SBhanu Gollapudi /* set mul_n_port_ids supported flag to 0, until it is supported */ 270853e2bd2SBhanu Gollapudi ofld_req3.flags = 0; 271853e2bd2SBhanu Gollapudi /* 272853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) << 273853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT); 274853e2bd2SBhanu Gollapudi */ 275853e2bd2SBhanu Gollapudi /* Info from PLOGI response */ 276853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) << 277853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT); 278853e2bd2SBhanu Gollapudi 279853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) << 280853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT); 281853e2bd2SBhanu Gollapudi 282853e2bd2SBhanu Gollapudi /* vlan flag */ 283*aea71a02SBhanu Prakash Gollapudi ofld_req3.flags |= (interface->vlan_enabled << 284853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT); 285853e2bd2SBhanu Gollapudi 286853e2bd2SBhanu Gollapudi /* C2_VALID and ACK flags are not set as they are not suppported */ 287853e2bd2SBhanu Gollapudi 288853e2bd2SBhanu Gollapudi 289853e2bd2SBhanu Gollapudi /* Initialize offload request 4 structure */ 290853e2bd2SBhanu Gollapudi memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4)); 291853e2bd2SBhanu Gollapudi ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4; 292853e2bd2SBhanu Gollapudi ofld_req4.hdr.flags = 293853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 294853e2bd2SBhanu Gollapudi 295853e2bd2SBhanu Gollapudi ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20; 296853e2bd2SBhanu Gollapudi 297853e2bd2SBhanu Gollapudi 298619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_lo[0] = port->data_src_addr[5]; 299853e2bd2SBhanu Gollapudi /* local mac */ 300619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_lo[1] = port->data_src_addr[4]; 301619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_mid[0] = port->data_src_addr[3]; 302619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2]; 303619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1]; 304619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0]; 305*aea71a02SBhanu Prakash Gollapudi ofld_req4.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5]; 306*aea71a02SBhanu Prakash Gollapudi /* fcf mac */ 307*aea71a02SBhanu Prakash Gollapudi ofld_req4.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4]; 308*aea71a02SBhanu Prakash Gollapudi ofld_req4.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3]; 309*aea71a02SBhanu Prakash Gollapudi ofld_req4.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2]; 310*aea71a02SBhanu Prakash Gollapudi ofld_req4.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1]; 311*aea71a02SBhanu Prakash Gollapudi ofld_req4.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0]; 312853e2bd2SBhanu Gollapudi 313853e2bd2SBhanu Gollapudi ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma; 314853e2bd2SBhanu Gollapudi ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32); 315853e2bd2SBhanu Gollapudi 316853e2bd2SBhanu Gollapudi ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma; 317853e2bd2SBhanu Gollapudi ofld_req4.confq_pbl_base_addr_hi = 318853e2bd2SBhanu Gollapudi (u32)((u64) tgt->confq_pbl_dma >> 32); 319853e2bd2SBhanu Gollapudi 320853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &ofld_req1; 321853e2bd2SBhanu Gollapudi kwqe_arr[1] = (struct kwqe *) &ofld_req2; 322853e2bd2SBhanu Gollapudi kwqe_arr[2] = (struct kwqe *) &ofld_req3; 323853e2bd2SBhanu Gollapudi kwqe_arr[3] = (struct kwqe *) &ofld_req4; 324853e2bd2SBhanu Gollapudi 325853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 326853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 327853e2bd2SBhanu Gollapudi 328853e2bd2SBhanu Gollapudi return rc; 329853e2bd2SBhanu Gollapudi } 330853e2bd2SBhanu Gollapudi 331853e2bd2SBhanu Gollapudi /** 332853e2bd2SBhanu Gollapudi * bnx2fc_send_session_enable_req - initiates FCoE Session enablement 333853e2bd2SBhanu Gollapudi * 334853e2bd2SBhanu Gollapudi * @port: port structure pointer 335853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 336853e2bd2SBhanu Gollapudi */ 337853e2bd2SBhanu Gollapudi static int bnx2fc_send_session_enable_req(struct fcoe_port *port, 338853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 339853e2bd2SBhanu Gollapudi { 340853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 341*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv; 342*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba; 343853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_enable_disable enbl_req; 344853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport; 345853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport; 346853e2bd2SBhanu Gollapudi int num_kwqes = 1; 347853e2bd2SBhanu Gollapudi int rc = 0; 348853e2bd2SBhanu Gollapudi u32 port_id; 349853e2bd2SBhanu Gollapudi 350853e2bd2SBhanu Gollapudi memset(&enbl_req, 0x00, 351853e2bd2SBhanu Gollapudi sizeof(struct fcoe_kwqe_conn_enable_disable)); 352853e2bd2SBhanu Gollapudi enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN; 353853e2bd2SBhanu Gollapudi enbl_req.hdr.flags = 354853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 355853e2bd2SBhanu Gollapudi 356619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_lo[0] = port->data_src_addr[5]; 357853e2bd2SBhanu Gollapudi /* local mac */ 358619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_lo[1] = port->data_src_addr[4]; 359619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_mid[0] = port->data_src_addr[3]; 360619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_mid[1] = port->data_src_addr[2]; 361619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_hi[0] = port->data_src_addr[1]; 362619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0]; 363619c5cb6SVlad Zolotarov memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN); 364853e2bd2SBhanu Gollapudi 365*aea71a02SBhanu Prakash Gollapudi enbl_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5]; 366*aea71a02SBhanu Prakash Gollapudi enbl_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4]; 367*aea71a02SBhanu Prakash Gollapudi enbl_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3]; 368*aea71a02SBhanu Prakash Gollapudi enbl_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2]; 369*aea71a02SBhanu Prakash Gollapudi enbl_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1]; 370*aea71a02SBhanu Prakash Gollapudi enbl_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0]; 371853e2bd2SBhanu Gollapudi 372853e2bd2SBhanu Gollapudi port_id = fc_host_port_id(lport->host); 373853e2bd2SBhanu Gollapudi if (port_id != tgt->sid) { 374853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x," 375853e2bd2SBhanu Gollapudi "sid = 0x%x\n", port_id, tgt->sid); 376853e2bd2SBhanu Gollapudi port_id = tgt->sid; 377853e2bd2SBhanu Gollapudi } 378853e2bd2SBhanu Gollapudi enbl_req.s_id[0] = (port_id & 0x000000FF); 379853e2bd2SBhanu Gollapudi enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8; 380853e2bd2SBhanu Gollapudi enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16; 381853e2bd2SBhanu Gollapudi 382853e2bd2SBhanu Gollapudi port_id = rport->port_id; 383853e2bd2SBhanu Gollapudi enbl_req.d_id[0] = (port_id & 0x000000FF); 384853e2bd2SBhanu Gollapudi enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8; 385853e2bd2SBhanu Gollapudi enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16; 386*aea71a02SBhanu Prakash Gollapudi enbl_req.vlan_tag = interface->vlan_id << 387853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT; 388853e2bd2SBhanu Gollapudi enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT; 389*aea71a02SBhanu Prakash Gollapudi enbl_req.vlan_flag = interface->vlan_enabled; 390853e2bd2SBhanu Gollapudi enbl_req.context_id = tgt->context_id; 391853e2bd2SBhanu Gollapudi enbl_req.conn_id = tgt->fcoe_conn_id; 392853e2bd2SBhanu Gollapudi 393853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &enbl_req; 394853e2bd2SBhanu Gollapudi 395853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 396853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 397853e2bd2SBhanu Gollapudi return rc; 398853e2bd2SBhanu Gollapudi } 399853e2bd2SBhanu Gollapudi 400853e2bd2SBhanu Gollapudi /** 401853e2bd2SBhanu Gollapudi * bnx2fc_send_session_disable_req - initiates FCoE Session disable 402853e2bd2SBhanu Gollapudi * 403853e2bd2SBhanu Gollapudi * @port: port structure pointer 404853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 405853e2bd2SBhanu Gollapudi */ 406853e2bd2SBhanu Gollapudi int bnx2fc_send_session_disable_req(struct fcoe_port *port, 407853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 408853e2bd2SBhanu Gollapudi { 409*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv; 410*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba; 411853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_enable_disable disable_req; 412853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 413853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport; 414853e2bd2SBhanu Gollapudi int num_kwqes = 1; 415853e2bd2SBhanu Gollapudi int rc = 0; 416853e2bd2SBhanu Gollapudi u32 port_id; 417853e2bd2SBhanu Gollapudi 418853e2bd2SBhanu Gollapudi memset(&disable_req, 0x00, 419853e2bd2SBhanu Gollapudi sizeof(struct fcoe_kwqe_conn_enable_disable)); 420853e2bd2SBhanu Gollapudi disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN; 421853e2bd2SBhanu Gollapudi disable_req.hdr.flags = 422853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 423853e2bd2SBhanu Gollapudi 424619c5cb6SVlad Zolotarov disable_req.src_mac_addr_lo[0] = tgt->src_addr[5]; 425619c5cb6SVlad Zolotarov disable_req.src_mac_addr_lo[1] = tgt->src_addr[4]; 426619c5cb6SVlad Zolotarov disable_req.src_mac_addr_mid[0] = tgt->src_addr[3]; 427619c5cb6SVlad Zolotarov disable_req.src_mac_addr_mid[1] = tgt->src_addr[2]; 428619c5cb6SVlad Zolotarov disable_req.src_mac_addr_hi[0] = tgt->src_addr[1]; 429619c5cb6SVlad Zolotarov disable_req.src_mac_addr_hi[1] = tgt->src_addr[0]; 430853e2bd2SBhanu Gollapudi 431*aea71a02SBhanu Prakash Gollapudi disable_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5]; 432*aea71a02SBhanu Prakash Gollapudi disable_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4]; 433*aea71a02SBhanu Prakash Gollapudi disable_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3]; 434*aea71a02SBhanu Prakash Gollapudi disable_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2]; 435*aea71a02SBhanu Prakash Gollapudi disable_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1]; 436*aea71a02SBhanu Prakash Gollapudi disable_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0]; 437853e2bd2SBhanu Gollapudi 438853e2bd2SBhanu Gollapudi port_id = tgt->sid; 439853e2bd2SBhanu Gollapudi disable_req.s_id[0] = (port_id & 0x000000FF); 440853e2bd2SBhanu Gollapudi disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8; 441853e2bd2SBhanu Gollapudi disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16; 442853e2bd2SBhanu Gollapudi 443853e2bd2SBhanu Gollapudi 444853e2bd2SBhanu Gollapudi port_id = rport->port_id; 445853e2bd2SBhanu Gollapudi disable_req.d_id[0] = (port_id & 0x000000FF); 446853e2bd2SBhanu Gollapudi disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8; 447853e2bd2SBhanu Gollapudi disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16; 448853e2bd2SBhanu Gollapudi disable_req.context_id = tgt->context_id; 449853e2bd2SBhanu Gollapudi disable_req.conn_id = tgt->fcoe_conn_id; 450*aea71a02SBhanu Prakash Gollapudi disable_req.vlan_tag = interface->vlan_id << 451853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT; 452853e2bd2SBhanu Gollapudi disable_req.vlan_tag |= 453853e2bd2SBhanu Gollapudi 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT; 454*aea71a02SBhanu Prakash Gollapudi disable_req.vlan_flag = interface->vlan_enabled; 455853e2bd2SBhanu Gollapudi 456853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &disable_req; 457853e2bd2SBhanu Gollapudi 458853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 459853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 460853e2bd2SBhanu Gollapudi 461853e2bd2SBhanu Gollapudi return rc; 462853e2bd2SBhanu Gollapudi } 463853e2bd2SBhanu Gollapudi 464853e2bd2SBhanu Gollapudi /** 465853e2bd2SBhanu Gollapudi * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy 466853e2bd2SBhanu Gollapudi * 467853e2bd2SBhanu Gollapudi * @port: port structure pointer 468853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 469853e2bd2SBhanu Gollapudi */ 470853e2bd2SBhanu Gollapudi int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba, 471853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 472853e2bd2SBhanu Gollapudi { 473853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_destroy destroy_req; 474853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 475853e2bd2SBhanu Gollapudi int num_kwqes = 1; 476853e2bd2SBhanu Gollapudi int rc = 0; 477853e2bd2SBhanu Gollapudi 478853e2bd2SBhanu Gollapudi memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy)); 479853e2bd2SBhanu Gollapudi destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN; 480853e2bd2SBhanu Gollapudi destroy_req.hdr.flags = 481853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 482853e2bd2SBhanu Gollapudi 483853e2bd2SBhanu Gollapudi destroy_req.context_id = tgt->context_id; 484853e2bd2SBhanu Gollapudi destroy_req.conn_id = tgt->fcoe_conn_id; 485853e2bd2SBhanu Gollapudi 486853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &destroy_req; 487853e2bd2SBhanu Gollapudi 488853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 489853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 490853e2bd2SBhanu Gollapudi 491853e2bd2SBhanu Gollapudi return rc; 492853e2bd2SBhanu Gollapudi } 493853e2bd2SBhanu Gollapudi 494d36b3279SBhanu Prakash Gollapudi static bool is_valid_lport(struct bnx2fc_hba *hba, struct fc_lport *lport) 495d36b3279SBhanu Prakash Gollapudi { 496d36b3279SBhanu Prakash Gollapudi struct bnx2fc_lport *blport; 497d36b3279SBhanu Prakash Gollapudi 498d36b3279SBhanu Prakash Gollapudi spin_lock_bh(&hba->hba_lock); 499d36b3279SBhanu Prakash Gollapudi list_for_each_entry(blport, &hba->vports, list) { 500d36b3279SBhanu Prakash Gollapudi if (blport->lport == lport) { 501d36b3279SBhanu Prakash Gollapudi spin_unlock_bh(&hba->hba_lock); 502d36b3279SBhanu Prakash Gollapudi return true; 503d36b3279SBhanu Prakash Gollapudi } 504d36b3279SBhanu Prakash Gollapudi } 505d36b3279SBhanu Prakash Gollapudi spin_unlock_bh(&hba->hba_lock); 506d36b3279SBhanu Prakash Gollapudi return false; 507d36b3279SBhanu Prakash Gollapudi 508d36b3279SBhanu Prakash Gollapudi } 509d36b3279SBhanu Prakash Gollapudi 510d36b3279SBhanu Prakash Gollapudi 511853e2bd2SBhanu Gollapudi static void bnx2fc_unsol_els_work(struct work_struct *work) 512853e2bd2SBhanu Gollapudi { 513853e2bd2SBhanu Gollapudi struct bnx2fc_unsol_els *unsol_els; 514853e2bd2SBhanu Gollapudi struct fc_lport *lport; 515d36b3279SBhanu Prakash Gollapudi struct bnx2fc_hba *hba; 516853e2bd2SBhanu Gollapudi struct fc_frame *fp; 517853e2bd2SBhanu Gollapudi 518853e2bd2SBhanu Gollapudi unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work); 519853e2bd2SBhanu Gollapudi lport = unsol_els->lport; 520853e2bd2SBhanu Gollapudi fp = unsol_els->fp; 521d36b3279SBhanu Prakash Gollapudi hba = unsol_els->hba; 522d36b3279SBhanu Prakash Gollapudi if (is_valid_lport(hba, lport)) 523853e2bd2SBhanu Gollapudi fc_exch_recv(lport, fp); 524853e2bd2SBhanu Gollapudi kfree(unsol_els); 525853e2bd2SBhanu Gollapudi } 526853e2bd2SBhanu Gollapudi 527853e2bd2SBhanu Gollapudi void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt, 528853e2bd2SBhanu Gollapudi unsigned char *buf, 529853e2bd2SBhanu Gollapudi u32 frame_len, u16 l2_oxid) 530853e2bd2SBhanu Gollapudi { 531853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port; 532853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport; 533*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv; 534853e2bd2SBhanu Gollapudi struct bnx2fc_unsol_els *unsol_els; 535853e2bd2SBhanu Gollapudi struct fc_frame_header *fh; 536853e2bd2SBhanu Gollapudi struct fc_frame *fp; 537853e2bd2SBhanu Gollapudi struct sk_buff *skb; 538853e2bd2SBhanu Gollapudi u32 payload_len; 539853e2bd2SBhanu Gollapudi u32 crc; 540853e2bd2SBhanu Gollapudi u8 op; 541853e2bd2SBhanu Gollapudi 542853e2bd2SBhanu Gollapudi 543853e2bd2SBhanu Gollapudi unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC); 544853e2bd2SBhanu Gollapudi if (!unsol_els) { 545853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n"); 546853e2bd2SBhanu Gollapudi return; 547853e2bd2SBhanu Gollapudi } 548853e2bd2SBhanu Gollapudi 549853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n", 550853e2bd2SBhanu Gollapudi l2_oxid, frame_len); 551853e2bd2SBhanu Gollapudi 552853e2bd2SBhanu Gollapudi payload_len = frame_len - sizeof(struct fc_frame_header); 553853e2bd2SBhanu Gollapudi 554853e2bd2SBhanu Gollapudi fp = fc_frame_alloc(lport, payload_len); 555853e2bd2SBhanu Gollapudi if (!fp) { 556853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "fc_frame_alloc failure\n"); 5575c2dce26SJulia Lawall kfree(unsol_els); 558853e2bd2SBhanu Gollapudi return; 559853e2bd2SBhanu Gollapudi } 560853e2bd2SBhanu Gollapudi 561853e2bd2SBhanu Gollapudi fh = (struct fc_frame_header *) fc_frame_header_get(fp); 562853e2bd2SBhanu Gollapudi /* Copy FC Frame header and payload into the frame */ 563853e2bd2SBhanu Gollapudi memcpy(fh, buf, frame_len); 564853e2bd2SBhanu Gollapudi 565853e2bd2SBhanu Gollapudi if (l2_oxid != FC_XID_UNKNOWN) 566853e2bd2SBhanu Gollapudi fh->fh_ox_id = htons(l2_oxid); 567853e2bd2SBhanu Gollapudi 568853e2bd2SBhanu Gollapudi skb = fp_skb(fp); 569853e2bd2SBhanu Gollapudi 570853e2bd2SBhanu Gollapudi if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) || 571853e2bd2SBhanu Gollapudi (fh->fh_r_ctl == FC_RCTL_ELS_REP)) { 572853e2bd2SBhanu Gollapudi 573853e2bd2SBhanu Gollapudi if (fh->fh_type == FC_TYPE_ELS) { 574853e2bd2SBhanu Gollapudi op = fc_frame_payload_op(fp); 575853e2bd2SBhanu Gollapudi if ((op == ELS_TEST) || (op == ELS_ESTC) || 576853e2bd2SBhanu Gollapudi (op == ELS_FAN) || (op == ELS_CSU)) { 577853e2bd2SBhanu Gollapudi /* 578853e2bd2SBhanu Gollapudi * No need to reply for these 579853e2bd2SBhanu Gollapudi * ELS requests 580853e2bd2SBhanu Gollapudi */ 581853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "dropping ELS 0x%x\n", op); 582853e2bd2SBhanu Gollapudi kfree_skb(skb); 5835c2dce26SJulia Lawall kfree(unsol_els); 584853e2bd2SBhanu Gollapudi return; 585853e2bd2SBhanu Gollapudi } 586853e2bd2SBhanu Gollapudi } 587853e2bd2SBhanu Gollapudi crc = fcoe_fc_crc(fp); 588853e2bd2SBhanu Gollapudi fc_frame_init(fp); 589853e2bd2SBhanu Gollapudi fr_dev(fp) = lport; 590853e2bd2SBhanu Gollapudi fr_sof(fp) = FC_SOF_I3; 591853e2bd2SBhanu Gollapudi fr_eof(fp) = FC_EOF_T; 592853e2bd2SBhanu Gollapudi fr_crc(fp) = cpu_to_le32(~crc); 593853e2bd2SBhanu Gollapudi unsol_els->lport = lport; 594*aea71a02SBhanu Prakash Gollapudi unsol_els->hba = interface->hba; 595853e2bd2SBhanu Gollapudi unsol_els->fp = fp; 596853e2bd2SBhanu Gollapudi INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work); 597853e2bd2SBhanu Gollapudi queue_work(bnx2fc_wq, &unsol_els->unsol_els_work); 598853e2bd2SBhanu Gollapudi } else { 599853e2bd2SBhanu Gollapudi BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl); 600853e2bd2SBhanu Gollapudi kfree_skb(skb); 6015c2dce26SJulia Lawall kfree(unsol_els); 602853e2bd2SBhanu Gollapudi } 603853e2bd2SBhanu Gollapudi } 604853e2bd2SBhanu Gollapudi 605853e2bd2SBhanu Gollapudi static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe) 606853e2bd2SBhanu Gollapudi { 607853e2bd2SBhanu Gollapudi u8 num_rq; 608853e2bd2SBhanu Gollapudi struct fcoe_err_report_entry *err_entry; 609853e2bd2SBhanu Gollapudi unsigned char *rq_data; 610853e2bd2SBhanu Gollapudi unsigned char *buf = NULL, *buf1; 611853e2bd2SBhanu Gollapudi int i; 612853e2bd2SBhanu Gollapudi u16 xid; 613853e2bd2SBhanu Gollapudi u32 frame_len, len; 614853e2bd2SBhanu Gollapudi struct bnx2fc_cmd *io_req = NULL; 615853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task, *task_page; 616*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = tgt->port->priv; 617*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba; 618853e2bd2SBhanu Gollapudi int task_idx, index; 619853e2bd2SBhanu Gollapudi int rc = 0; 620853e2bd2SBhanu Gollapudi 621853e2bd2SBhanu Gollapudi 622853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe); 623853e2bd2SBhanu Gollapudi switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) { 624853e2bd2SBhanu Gollapudi case FCOE_UNSOLICITED_FRAME_CQE_TYPE: 625853e2bd2SBhanu Gollapudi frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >> 626853e2bd2SBhanu Gollapudi FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT; 627853e2bd2SBhanu Gollapudi 628853e2bd2SBhanu Gollapudi num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ; 629853e2bd2SBhanu Gollapudi 63068695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 631853e2bd2SBhanu Gollapudi rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq); 63268695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 63368695973SNithin Sujir 634853e2bd2SBhanu Gollapudi if (rq_data) { 635853e2bd2SBhanu Gollapudi buf = rq_data; 636853e2bd2SBhanu Gollapudi } else { 637853e2bd2SBhanu Gollapudi buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ), 638853e2bd2SBhanu Gollapudi GFP_ATOMIC); 639853e2bd2SBhanu Gollapudi 640853e2bd2SBhanu Gollapudi if (!buf1) { 641853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n"); 642853e2bd2SBhanu Gollapudi break; 643853e2bd2SBhanu Gollapudi } 644853e2bd2SBhanu Gollapudi 645853e2bd2SBhanu Gollapudi for (i = 0; i < num_rq; i++) { 64668695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 647853e2bd2SBhanu Gollapudi rq_data = (unsigned char *) 648853e2bd2SBhanu Gollapudi bnx2fc_get_next_rqe(tgt, 1); 64968695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 650853e2bd2SBhanu Gollapudi len = BNX2FC_RQ_BUF_SZ; 651853e2bd2SBhanu Gollapudi memcpy(buf1, rq_data, len); 652853e2bd2SBhanu Gollapudi buf1 += len; 653853e2bd2SBhanu Gollapudi } 654853e2bd2SBhanu Gollapudi } 655853e2bd2SBhanu Gollapudi bnx2fc_process_l2_frame_compl(tgt, buf, frame_len, 656853e2bd2SBhanu Gollapudi FC_XID_UNKNOWN); 657853e2bd2SBhanu Gollapudi 658853e2bd2SBhanu Gollapudi if (buf != rq_data) 659853e2bd2SBhanu Gollapudi kfree(buf); 66068695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 661853e2bd2SBhanu Gollapudi bnx2fc_return_rqe(tgt, num_rq); 66268695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 663853e2bd2SBhanu Gollapudi break; 664853e2bd2SBhanu Gollapudi 665853e2bd2SBhanu Gollapudi case FCOE_ERROR_DETECTION_CQE_TYPE: 666853e2bd2SBhanu Gollapudi /* 667853e2bd2SBhanu Gollapudi * In case of error reporting CQE a single RQ entry 66868695973SNithin Sujir * is consumed. 669853e2bd2SBhanu Gollapudi */ 670853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->tgt_lock); 671853e2bd2SBhanu Gollapudi num_rq = 1; 672853e2bd2SBhanu Gollapudi err_entry = (struct fcoe_err_report_entry *) 673853e2bd2SBhanu Gollapudi bnx2fc_get_next_rqe(tgt, 1); 674853e2bd2SBhanu Gollapudi xid = err_entry->fc_hdr.ox_id; 675853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid); 676853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n", 677619c5cb6SVlad Zolotarov err_entry->data.err_warn_bitmap_hi, 678619c5cb6SVlad Zolotarov err_entry->data.err_warn_bitmap_lo); 679853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n", 680619c5cb6SVlad Zolotarov err_entry->data.tx_buf_off, err_entry->data.rx_buf_off); 681853e2bd2SBhanu Gollapudi 682853e2bd2SBhanu Gollapudi bnx2fc_return_rqe(tgt, 1); 683853e2bd2SBhanu Gollapudi 684853e2bd2SBhanu Gollapudi if (xid > BNX2FC_MAX_XID) { 685853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", 686853e2bd2SBhanu Gollapudi xid); 687853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 688853e2bd2SBhanu Gollapudi break; 689853e2bd2SBhanu Gollapudi } 690853e2bd2SBhanu Gollapudi 691853e2bd2SBhanu Gollapudi task_idx = xid / BNX2FC_TASKS_PER_PAGE; 692853e2bd2SBhanu Gollapudi index = xid % BNX2FC_TASKS_PER_PAGE; 693853e2bd2SBhanu Gollapudi task_page = (struct fcoe_task_ctx_entry *) 694853e2bd2SBhanu Gollapudi hba->task_ctx[task_idx]; 695853e2bd2SBhanu Gollapudi task = &(task_page[index]); 696853e2bd2SBhanu Gollapudi 697853e2bd2SBhanu Gollapudi io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid]; 698853e2bd2SBhanu Gollapudi if (!io_req) { 699853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 700853e2bd2SBhanu Gollapudi break; 701853e2bd2SBhanu Gollapudi } 702853e2bd2SBhanu Gollapudi 703853e2bd2SBhanu Gollapudi if (io_req->cmd_type != BNX2FC_SCSI_CMD) { 704853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n"); 705853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 706853e2bd2SBhanu Gollapudi break; 707853e2bd2SBhanu Gollapudi } 708853e2bd2SBhanu Gollapudi 709853e2bd2SBhanu Gollapudi if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP, 710853e2bd2SBhanu Gollapudi &io_req->req_flags)) { 711853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in " 712853e2bd2SBhanu Gollapudi "progress.. ignore unsol err\n"); 713853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 714853e2bd2SBhanu Gollapudi break; 715853e2bd2SBhanu Gollapudi } 716853e2bd2SBhanu Gollapudi 717853e2bd2SBhanu Gollapudi /* 718853e2bd2SBhanu Gollapudi * If ABTS is already in progress, and FW error is 719853e2bd2SBhanu Gollapudi * received after that, do not cancel the timeout_work 720853e2bd2SBhanu Gollapudi * and let the error recovery continue by explicitly 721853e2bd2SBhanu Gollapudi * logging out the target, when the ABTS eventually 722853e2bd2SBhanu Gollapudi * times out. 723853e2bd2SBhanu Gollapudi */ 724853e2bd2SBhanu Gollapudi if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS, 725853e2bd2SBhanu Gollapudi &io_req->req_flags)) { 726853e2bd2SBhanu Gollapudi /* 727853e2bd2SBhanu Gollapudi * Cancel the timeout_work, as we received IO 728853e2bd2SBhanu Gollapudi * completion with FW error. 729853e2bd2SBhanu Gollapudi */ 730853e2bd2SBhanu Gollapudi if (cancel_delayed_work(&io_req->timeout_work)) 731853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, 732853e2bd2SBhanu Gollapudi bnx2fc_cmd_release); /* timer hold */ 733853e2bd2SBhanu Gollapudi 734853e2bd2SBhanu Gollapudi rc = bnx2fc_initiate_abts(io_req); 735853e2bd2SBhanu Gollapudi if (rc != SUCCESS) { 736853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "err_warn: initiate_abts " 737853e2bd2SBhanu Gollapudi "failed. issue cleanup\n"); 738853e2bd2SBhanu Gollapudi rc = bnx2fc_initiate_cleanup(io_req); 739853e2bd2SBhanu Gollapudi BUG_ON(rc); 740853e2bd2SBhanu Gollapudi } 741853e2bd2SBhanu Gollapudi } else 742853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "err_warn: io_req (0x%x) already " 743853e2bd2SBhanu Gollapudi "in ABTS processing\n", xid); 744853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 745853e2bd2SBhanu Gollapudi break; 746853e2bd2SBhanu Gollapudi 747853e2bd2SBhanu Gollapudi case FCOE_WARNING_DETECTION_CQE_TYPE: 748853e2bd2SBhanu Gollapudi /* 749853e2bd2SBhanu Gollapudi *In case of warning reporting CQE a single RQ entry 750853e2bd2SBhanu Gollapudi * is consumes. 751853e2bd2SBhanu Gollapudi */ 75268695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 753853e2bd2SBhanu Gollapudi num_rq = 1; 754853e2bd2SBhanu Gollapudi err_entry = (struct fcoe_err_report_entry *) 755853e2bd2SBhanu Gollapudi bnx2fc_get_next_rqe(tgt, 1); 756853e2bd2SBhanu Gollapudi xid = cpu_to_be16(err_entry->fc_hdr.ox_id); 757853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid); 758853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x", 759619c5cb6SVlad Zolotarov err_entry->data.err_warn_bitmap_hi, 760619c5cb6SVlad Zolotarov err_entry->data.err_warn_bitmap_lo); 761853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x", 762619c5cb6SVlad Zolotarov err_entry->data.tx_buf_off, err_entry->data.rx_buf_off); 763853e2bd2SBhanu Gollapudi 764853e2bd2SBhanu Gollapudi bnx2fc_return_rqe(tgt, 1); 76568695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 766853e2bd2SBhanu Gollapudi break; 767853e2bd2SBhanu Gollapudi 768853e2bd2SBhanu Gollapudi default: 769853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n"); 770853e2bd2SBhanu Gollapudi break; 771853e2bd2SBhanu Gollapudi } 772853e2bd2SBhanu Gollapudi } 773853e2bd2SBhanu Gollapudi 774853e2bd2SBhanu Gollapudi void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe) 775853e2bd2SBhanu Gollapudi { 776853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task; 777853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task_page; 778853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port; 779*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv; 780*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba; 781853e2bd2SBhanu Gollapudi struct bnx2fc_cmd *io_req; 782853e2bd2SBhanu Gollapudi int task_idx, index; 783853e2bd2SBhanu Gollapudi u16 xid; 784853e2bd2SBhanu Gollapudi u8 cmd_type; 785853e2bd2SBhanu Gollapudi u8 rx_state = 0; 786853e2bd2SBhanu Gollapudi u8 num_rq; 787853e2bd2SBhanu Gollapudi 788853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->tgt_lock); 789853e2bd2SBhanu Gollapudi xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID; 790853e2bd2SBhanu Gollapudi if (xid >= BNX2FC_MAX_TASKS) { 791b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "ERROR:xid out of range\n"); 792853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 793853e2bd2SBhanu Gollapudi return; 794853e2bd2SBhanu Gollapudi } 795853e2bd2SBhanu Gollapudi task_idx = xid / BNX2FC_TASKS_PER_PAGE; 796853e2bd2SBhanu Gollapudi index = xid % BNX2FC_TASKS_PER_PAGE; 797853e2bd2SBhanu Gollapudi task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx]; 798853e2bd2SBhanu Gollapudi task = &(task_page[index]); 799853e2bd2SBhanu Gollapudi 800619c5cb6SVlad Zolotarov num_rq = ((task->rxwr_txrd.var_ctx.rx_flags & 801619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE) >> 802619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE_SHIFT); 803853e2bd2SBhanu Gollapudi 804853e2bd2SBhanu Gollapudi io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid]; 805853e2bd2SBhanu Gollapudi 806853e2bd2SBhanu Gollapudi if (io_req == NULL) { 807853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n"); 808853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 809853e2bd2SBhanu Gollapudi return; 810853e2bd2SBhanu Gollapudi } 811853e2bd2SBhanu Gollapudi 812853e2bd2SBhanu Gollapudi /* Timestamp IO completion time */ 813853e2bd2SBhanu Gollapudi cmd_type = io_req->cmd_type; 814853e2bd2SBhanu Gollapudi 815619c5cb6SVlad Zolotarov rx_state = ((task->rxwr_txrd.var_ctx.rx_flags & 816619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE) >> 817619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE_SHIFT); 818853e2bd2SBhanu Gollapudi 819619c5cb6SVlad Zolotarov /* Process other IO completion types */ 820619c5cb6SVlad Zolotarov switch (cmd_type) { 821619c5cb6SVlad Zolotarov case BNX2FC_SCSI_CMD: 822853e2bd2SBhanu Gollapudi if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) { 823853e2bd2SBhanu Gollapudi bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq); 824853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 825853e2bd2SBhanu Gollapudi return; 826853e2bd2SBhanu Gollapudi } 827853e2bd2SBhanu Gollapudi 828853e2bd2SBhanu Gollapudi if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED) 829853e2bd2SBhanu Gollapudi bnx2fc_process_abts_compl(io_req, task, num_rq); 830853e2bd2SBhanu Gollapudi else if (rx_state == 831853e2bd2SBhanu Gollapudi FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED) 832853e2bd2SBhanu Gollapudi bnx2fc_process_cleanup_compl(io_req, task, num_rq); 833853e2bd2SBhanu Gollapudi else 834853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Invalid rx state - %d\n", 835853e2bd2SBhanu Gollapudi rx_state); 836853e2bd2SBhanu Gollapudi break; 837853e2bd2SBhanu Gollapudi 838853e2bd2SBhanu Gollapudi case BNX2FC_TASK_MGMT_CMD: 839853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "Processing TM complete\n"); 840853e2bd2SBhanu Gollapudi bnx2fc_process_tm_compl(io_req, task, num_rq); 841853e2bd2SBhanu Gollapudi break; 842853e2bd2SBhanu Gollapudi 843853e2bd2SBhanu Gollapudi case BNX2FC_ABTS: 844853e2bd2SBhanu Gollapudi /* 845853e2bd2SBhanu Gollapudi * ABTS request received by firmware. ABTS response 846853e2bd2SBhanu Gollapudi * will be delivered to the task belonging to the IO 847853e2bd2SBhanu Gollapudi * that was aborted 848853e2bd2SBhanu Gollapudi */ 849853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n"); 850853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release); 851853e2bd2SBhanu Gollapudi break; 852853e2bd2SBhanu Gollapudi 853853e2bd2SBhanu Gollapudi case BNX2FC_ELS: 854619c5cb6SVlad Zolotarov if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) 855853e2bd2SBhanu Gollapudi bnx2fc_process_els_compl(io_req, task, num_rq); 856619c5cb6SVlad Zolotarov else if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED) 857619c5cb6SVlad Zolotarov bnx2fc_process_abts_compl(io_req, task, num_rq); 858619c5cb6SVlad Zolotarov else if (rx_state == 859619c5cb6SVlad Zolotarov FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED) 860619c5cb6SVlad Zolotarov bnx2fc_process_cleanup_compl(io_req, task, num_rq); 861619c5cb6SVlad Zolotarov else 862619c5cb6SVlad Zolotarov printk(KERN_ERR PFX "Invalid rx state = %d\n", 863619c5cb6SVlad Zolotarov rx_state); 864853e2bd2SBhanu Gollapudi break; 865853e2bd2SBhanu Gollapudi 866853e2bd2SBhanu Gollapudi case BNX2FC_CLEANUP: 867853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n"); 868853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release); 869853e2bd2SBhanu Gollapudi break; 870853e2bd2SBhanu Gollapudi 871853e2bd2SBhanu Gollapudi default: 872853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type); 873853e2bd2SBhanu Gollapudi break; 874853e2bd2SBhanu Gollapudi } 875853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 876853e2bd2SBhanu Gollapudi } 877853e2bd2SBhanu Gollapudi 878619c5cb6SVlad Zolotarov void bnx2fc_arm_cq(struct bnx2fc_rport *tgt) 879619c5cb6SVlad Zolotarov { 880619c5cb6SVlad Zolotarov struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db; 881619c5cb6SVlad Zolotarov u32 msg; 882619c5cb6SVlad Zolotarov 883619c5cb6SVlad Zolotarov wmb(); 884619c5cb6SVlad Zolotarov rx_db->doorbell_cq_cons = tgt->cq_cons_idx | (tgt->cq_curr_toggle_bit << 885619c5cb6SVlad Zolotarov FCOE_CQE_TOGGLE_BIT_SHIFT); 886619c5cb6SVlad Zolotarov msg = *((u32 *)rx_db); 887619c5cb6SVlad Zolotarov writel(cpu_to_le32(msg), tgt->ctx_base); 888619c5cb6SVlad Zolotarov mmiowb(); 889619c5cb6SVlad Zolotarov 890619c5cb6SVlad Zolotarov } 891619c5cb6SVlad Zolotarov 892853e2bd2SBhanu Gollapudi struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe) 893853e2bd2SBhanu Gollapudi { 894853e2bd2SBhanu Gollapudi struct bnx2fc_work *work; 895853e2bd2SBhanu Gollapudi work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC); 896853e2bd2SBhanu Gollapudi if (!work) 897853e2bd2SBhanu Gollapudi return NULL; 898853e2bd2SBhanu Gollapudi 899853e2bd2SBhanu Gollapudi INIT_LIST_HEAD(&work->list); 900853e2bd2SBhanu Gollapudi work->tgt = tgt; 901853e2bd2SBhanu Gollapudi work->wqe = wqe; 902853e2bd2SBhanu Gollapudi return work; 903853e2bd2SBhanu Gollapudi } 904853e2bd2SBhanu Gollapudi 905853e2bd2SBhanu Gollapudi int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt) 906853e2bd2SBhanu Gollapudi { 907853e2bd2SBhanu Gollapudi struct fcoe_cqe *cq; 908853e2bd2SBhanu Gollapudi u32 cq_cons; 909853e2bd2SBhanu Gollapudi struct fcoe_cqe *cqe; 910619c5cb6SVlad Zolotarov u32 num_free_sqes = 0; 911853e2bd2SBhanu Gollapudi u16 wqe; 912853e2bd2SBhanu Gollapudi 913853e2bd2SBhanu Gollapudi /* 914853e2bd2SBhanu Gollapudi * cq_lock is a low contention lock used to protect 915853e2bd2SBhanu Gollapudi * the CQ data structure from being freed up during 916853e2bd2SBhanu Gollapudi * the upload operation 917853e2bd2SBhanu Gollapudi */ 918853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->cq_lock); 919853e2bd2SBhanu Gollapudi 920853e2bd2SBhanu Gollapudi if (!tgt->cq) { 921853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n"); 922853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->cq_lock); 923853e2bd2SBhanu Gollapudi return 0; 924853e2bd2SBhanu Gollapudi } 925853e2bd2SBhanu Gollapudi cq = tgt->cq; 926853e2bd2SBhanu Gollapudi cq_cons = tgt->cq_cons_idx; 927853e2bd2SBhanu Gollapudi cqe = &cq[cq_cons]; 928853e2bd2SBhanu Gollapudi 929853e2bd2SBhanu Gollapudi while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) == 930853e2bd2SBhanu Gollapudi (tgt->cq_curr_toggle_bit << 931853e2bd2SBhanu Gollapudi FCOE_CQE_TOGGLE_BIT_SHIFT)) { 932853e2bd2SBhanu Gollapudi 933853e2bd2SBhanu Gollapudi /* new entry on the cq */ 934853e2bd2SBhanu Gollapudi if (wqe & FCOE_CQE_CQE_TYPE) { 935853e2bd2SBhanu Gollapudi /* Unsolicited event notification */ 936853e2bd2SBhanu Gollapudi bnx2fc_process_unsol_compl(tgt, wqe); 937853e2bd2SBhanu Gollapudi } else { 938619c5cb6SVlad Zolotarov /* Pending work request completion */ 939853e2bd2SBhanu Gollapudi struct bnx2fc_work *work = NULL; 940853e2bd2SBhanu Gollapudi struct bnx2fc_percpu_s *fps = NULL; 941853e2bd2SBhanu Gollapudi unsigned int cpu = wqe % num_possible_cpus(); 942853e2bd2SBhanu Gollapudi 943853e2bd2SBhanu Gollapudi fps = &per_cpu(bnx2fc_percpu, cpu); 944853e2bd2SBhanu Gollapudi spin_lock_bh(&fps->fp_work_lock); 945853e2bd2SBhanu Gollapudi if (unlikely(!fps->iothread)) 946853e2bd2SBhanu Gollapudi goto unlock; 947853e2bd2SBhanu Gollapudi 948853e2bd2SBhanu Gollapudi work = bnx2fc_alloc_work(tgt, wqe); 949853e2bd2SBhanu Gollapudi if (work) 950853e2bd2SBhanu Gollapudi list_add_tail(&work->list, 951853e2bd2SBhanu Gollapudi &fps->work_list); 952853e2bd2SBhanu Gollapudi unlock: 953853e2bd2SBhanu Gollapudi spin_unlock_bh(&fps->fp_work_lock); 954853e2bd2SBhanu Gollapudi 955853e2bd2SBhanu Gollapudi /* Pending work request completion */ 956853e2bd2SBhanu Gollapudi if (fps->iothread && work) 957853e2bd2SBhanu Gollapudi wake_up_process(fps->iothread); 958853e2bd2SBhanu Gollapudi else 959853e2bd2SBhanu Gollapudi bnx2fc_process_cq_compl(tgt, wqe); 960853e2bd2SBhanu Gollapudi } 961853e2bd2SBhanu Gollapudi cqe++; 962853e2bd2SBhanu Gollapudi tgt->cq_cons_idx++; 963619c5cb6SVlad Zolotarov num_free_sqes++; 964853e2bd2SBhanu Gollapudi 965853e2bd2SBhanu Gollapudi if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) { 966853e2bd2SBhanu Gollapudi tgt->cq_cons_idx = 0; 967853e2bd2SBhanu Gollapudi cqe = cq; 968853e2bd2SBhanu Gollapudi tgt->cq_curr_toggle_bit = 969853e2bd2SBhanu Gollapudi 1 - tgt->cq_curr_toggle_bit; 970853e2bd2SBhanu Gollapudi } 971853e2bd2SBhanu Gollapudi } 972619c5cb6SVlad Zolotarov bnx2fc_arm_cq(tgt); 973619c5cb6SVlad Zolotarov atomic_add(num_free_sqes, &tgt->free_sqes); 974853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->cq_lock); 975853e2bd2SBhanu Gollapudi return 0; 976853e2bd2SBhanu Gollapudi } 977853e2bd2SBhanu Gollapudi 978853e2bd2SBhanu Gollapudi /** 979853e2bd2SBhanu Gollapudi * bnx2fc_fastpath_notification - process global event queue (KCQ) 980853e2bd2SBhanu Gollapudi * 981853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 982853e2bd2SBhanu Gollapudi * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry 983853e2bd2SBhanu Gollapudi * 984853e2bd2SBhanu Gollapudi * Fast path event notification handler 985853e2bd2SBhanu Gollapudi */ 986853e2bd2SBhanu Gollapudi static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba, 987853e2bd2SBhanu Gollapudi struct fcoe_kcqe *new_cqe_kcqe) 988853e2bd2SBhanu Gollapudi { 989853e2bd2SBhanu Gollapudi u32 conn_id = new_cqe_kcqe->fcoe_conn_id; 990853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id]; 991853e2bd2SBhanu Gollapudi 992853e2bd2SBhanu Gollapudi if (!tgt) { 993b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "conn_id 0x%x not valid\n", conn_id); 994853e2bd2SBhanu Gollapudi return; 995853e2bd2SBhanu Gollapudi } 996853e2bd2SBhanu Gollapudi 997853e2bd2SBhanu Gollapudi bnx2fc_process_new_cqes(tgt); 998853e2bd2SBhanu Gollapudi } 999853e2bd2SBhanu Gollapudi 1000853e2bd2SBhanu Gollapudi /** 1001853e2bd2SBhanu Gollapudi * bnx2fc_process_ofld_cmpl - process FCoE session offload completion 1002853e2bd2SBhanu Gollapudi * 1003853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 1004853e2bd2SBhanu Gollapudi * @ofld_kcqe: connection offload kcqe pointer 1005853e2bd2SBhanu Gollapudi * 1006853e2bd2SBhanu Gollapudi * handle session offload completion, enable the session if offload is 1007853e2bd2SBhanu Gollapudi * successful. 1008853e2bd2SBhanu Gollapudi */ 1009853e2bd2SBhanu Gollapudi static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba, 1010853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe) 1011853e2bd2SBhanu Gollapudi { 1012853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 1013853e2bd2SBhanu Gollapudi struct fcoe_port *port; 1014*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface; 1015853e2bd2SBhanu Gollapudi u32 conn_id; 1016853e2bd2SBhanu Gollapudi u32 context_id; 1017853e2bd2SBhanu Gollapudi int rc; 1018853e2bd2SBhanu Gollapudi 1019853e2bd2SBhanu Gollapudi conn_id = ofld_kcqe->fcoe_conn_id; 1020853e2bd2SBhanu Gollapudi context_id = ofld_kcqe->fcoe_conn_context_id; 1021853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 1022853e2bd2SBhanu Gollapudi if (!tgt) { 1023*aea71a02SBhanu Prakash Gollapudi printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n"); 1024853e2bd2SBhanu Gollapudi return; 1025853e2bd2SBhanu Gollapudi } 1026853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n", 1027853e2bd2SBhanu Gollapudi ofld_kcqe->fcoe_conn_context_id); 1028853e2bd2SBhanu Gollapudi port = tgt->port; 1029*aea71a02SBhanu Prakash Gollapudi interface = tgt->port->priv; 1030*aea71a02SBhanu Prakash Gollapudi if (hba != interface->hba) { 1031*aea71a02SBhanu Prakash Gollapudi printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mis-match\n"); 1032853e2bd2SBhanu Gollapudi goto ofld_cmpl_err; 1033853e2bd2SBhanu Gollapudi } 1034853e2bd2SBhanu Gollapudi /* 1035853e2bd2SBhanu Gollapudi * cnic has allocated a context_id for this session; use this 1036853e2bd2SBhanu Gollapudi * while enabling the session. 1037853e2bd2SBhanu Gollapudi */ 1038853e2bd2SBhanu Gollapudi tgt->context_id = context_id; 1039853e2bd2SBhanu Gollapudi if (ofld_kcqe->completion_status) { 1040853e2bd2SBhanu Gollapudi if (ofld_kcqe->completion_status == 1041853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) { 1042853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate FCoE context " 1043853e2bd2SBhanu Gollapudi "resources\n"); 1044853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags); 1045853e2bd2SBhanu Gollapudi } 1046853e2bd2SBhanu Gollapudi goto ofld_cmpl_err; 1047853e2bd2SBhanu Gollapudi } else { 1048853e2bd2SBhanu Gollapudi 1049853e2bd2SBhanu Gollapudi /* now enable the session */ 1050853e2bd2SBhanu Gollapudi rc = bnx2fc_send_session_enable_req(port, tgt); 1051853e2bd2SBhanu Gollapudi if (rc) { 1052b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "enable session failed\n"); 1053853e2bd2SBhanu Gollapudi goto ofld_cmpl_err; 1054853e2bd2SBhanu Gollapudi } 1055853e2bd2SBhanu Gollapudi } 1056853e2bd2SBhanu Gollapudi return; 1057853e2bd2SBhanu Gollapudi ofld_cmpl_err: 1058853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags); 1059853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait); 1060853e2bd2SBhanu Gollapudi } 1061853e2bd2SBhanu Gollapudi 1062853e2bd2SBhanu Gollapudi /** 1063853e2bd2SBhanu Gollapudi * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion 1064853e2bd2SBhanu Gollapudi * 1065853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 1066853e2bd2SBhanu Gollapudi * @ofld_kcqe: connection offload kcqe pointer 1067853e2bd2SBhanu Gollapudi * 1068853e2bd2SBhanu Gollapudi * handle session enable completion, mark the rport as ready 1069853e2bd2SBhanu Gollapudi */ 1070853e2bd2SBhanu Gollapudi 1071853e2bd2SBhanu Gollapudi static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba, 1072853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe) 1073853e2bd2SBhanu Gollapudi { 1074853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 1075*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface; 1076853e2bd2SBhanu Gollapudi u32 conn_id; 1077853e2bd2SBhanu Gollapudi u32 context_id; 1078853e2bd2SBhanu Gollapudi 1079853e2bd2SBhanu Gollapudi context_id = ofld_kcqe->fcoe_conn_context_id; 1080853e2bd2SBhanu Gollapudi conn_id = ofld_kcqe->fcoe_conn_id; 1081853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 1082853e2bd2SBhanu Gollapudi if (!tgt) { 1083b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "ERROR:enbl_cmpl: No pending ofld req\n"); 1084853e2bd2SBhanu Gollapudi return; 1085853e2bd2SBhanu Gollapudi } 1086853e2bd2SBhanu Gollapudi 1087853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n", 1088853e2bd2SBhanu Gollapudi ofld_kcqe->fcoe_conn_context_id); 1089853e2bd2SBhanu Gollapudi 1090853e2bd2SBhanu Gollapudi /* 1091853e2bd2SBhanu Gollapudi * context_id should be the same for this target during offload 1092853e2bd2SBhanu Gollapudi * and enable 1093853e2bd2SBhanu Gollapudi */ 1094853e2bd2SBhanu Gollapudi if (tgt->context_id != context_id) { 1095b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "context id mis-match\n"); 1096853e2bd2SBhanu Gollapudi return; 1097853e2bd2SBhanu Gollapudi } 1098*aea71a02SBhanu Prakash Gollapudi interface = tgt->port->priv; 1099*aea71a02SBhanu Prakash Gollapudi if (hba != interface->hba) { 1100*aea71a02SBhanu Prakash Gollapudi printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mis-match\n"); 1101853e2bd2SBhanu Gollapudi goto enbl_cmpl_err; 1102853e2bd2SBhanu Gollapudi } 1103*aea71a02SBhanu Prakash Gollapudi if (ofld_kcqe->completion_status) 1104853e2bd2SBhanu Gollapudi goto enbl_cmpl_err; 1105*aea71a02SBhanu Prakash Gollapudi else { 1106853e2bd2SBhanu Gollapudi /* enable successful - rport ready for issuing IOs */ 1107853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags); 1108853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags); 1109853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait); 1110853e2bd2SBhanu Gollapudi } 1111853e2bd2SBhanu Gollapudi return; 1112853e2bd2SBhanu Gollapudi 1113853e2bd2SBhanu Gollapudi enbl_cmpl_err: 1114853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags); 1115853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait); 1116853e2bd2SBhanu Gollapudi } 1117853e2bd2SBhanu Gollapudi 1118853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba, 1119853e2bd2SBhanu Gollapudi struct fcoe_kcqe *disable_kcqe) 1120853e2bd2SBhanu Gollapudi { 1121853e2bd2SBhanu Gollapudi 1122853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 1123853e2bd2SBhanu Gollapudi u32 conn_id; 1124853e2bd2SBhanu Gollapudi 1125853e2bd2SBhanu Gollapudi conn_id = disable_kcqe->fcoe_conn_id; 1126853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 1127853e2bd2SBhanu Gollapudi if (!tgt) { 1128b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "ERROR: disable_cmpl: No disable req\n"); 1129853e2bd2SBhanu Gollapudi return; 1130853e2bd2SBhanu Gollapudi } 1131853e2bd2SBhanu Gollapudi 1132853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id); 1133853e2bd2SBhanu Gollapudi 1134853e2bd2SBhanu Gollapudi if (disable_kcqe->completion_status) { 1135b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "Disable failed with cmpl status %d\n", 1136853e2bd2SBhanu Gollapudi disable_kcqe->completion_status); 1137853e2bd2SBhanu Gollapudi return; 1138853e2bd2SBhanu Gollapudi } else { 1139853e2bd2SBhanu Gollapudi /* disable successful */ 1140853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "disable successful\n"); 1141853e2bd2SBhanu Gollapudi clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags); 1142853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags); 1143853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags); 1144853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->upld_wait); 1145853e2bd2SBhanu Gollapudi } 1146853e2bd2SBhanu Gollapudi } 1147853e2bd2SBhanu Gollapudi 1148853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba, 1149853e2bd2SBhanu Gollapudi struct fcoe_kcqe *destroy_kcqe) 1150853e2bd2SBhanu Gollapudi { 1151853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 1152853e2bd2SBhanu Gollapudi u32 conn_id; 1153853e2bd2SBhanu Gollapudi 1154853e2bd2SBhanu Gollapudi conn_id = destroy_kcqe->fcoe_conn_id; 1155853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 1156853e2bd2SBhanu Gollapudi if (!tgt) { 1157b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "destroy_cmpl: No destroy req\n"); 1158853e2bd2SBhanu Gollapudi return; 1159853e2bd2SBhanu Gollapudi } 1160853e2bd2SBhanu Gollapudi 1161853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id); 1162853e2bd2SBhanu Gollapudi 1163853e2bd2SBhanu Gollapudi if (destroy_kcqe->completion_status) { 1164b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "Destroy conn failed, cmpl status %d\n", 1165853e2bd2SBhanu Gollapudi destroy_kcqe->completion_status); 1166853e2bd2SBhanu Gollapudi return; 1167853e2bd2SBhanu Gollapudi } else { 1168853e2bd2SBhanu Gollapudi /* destroy successful */ 1169853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "upload successful\n"); 1170853e2bd2SBhanu Gollapudi clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags); 1171853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags); 1172853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags); 1173853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->upld_wait); 1174853e2bd2SBhanu Gollapudi } 1175853e2bd2SBhanu Gollapudi } 1176853e2bd2SBhanu Gollapudi 1177853e2bd2SBhanu Gollapudi static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code) 1178853e2bd2SBhanu Gollapudi { 1179853e2bd2SBhanu Gollapudi switch (err_code) { 1180853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE: 1181853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init_failure due to invalid opcode\n"); 1182853e2bd2SBhanu Gollapudi break; 1183853e2bd2SBhanu Gollapudi 1184853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE: 1185853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init failed due to ctx alloc failure\n"); 1186853e2bd2SBhanu Gollapudi break; 1187853e2bd2SBhanu Gollapudi 1188853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR: 1189853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init_failure due to NIC error\n"); 1190853e2bd2SBhanu Gollapudi break; 1191619c5cb6SVlad Zolotarov case FCOE_KCQE_COMPLETION_STATUS_ERROR: 1192619c5cb6SVlad Zolotarov printk(KERN_ERR PFX "init failure due to compl status err\n"); 1193619c5cb6SVlad Zolotarov break; 1194619c5cb6SVlad Zolotarov case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION: 1195619c5cb6SVlad Zolotarov printk(KERN_ERR PFX "init failure due to HSI mismatch\n"); 1196b2a554ffSBhanu Prakash Gollapudi break; 1197853e2bd2SBhanu Gollapudi default: 1198853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Unknown Error code %d\n", err_code); 1199853e2bd2SBhanu Gollapudi } 1200853e2bd2SBhanu Gollapudi } 1201853e2bd2SBhanu Gollapudi 1202853e2bd2SBhanu Gollapudi /** 1203853e2bd2SBhanu Gollapudi * bnx2fc_indicae_kcqe - process KCQE 1204853e2bd2SBhanu Gollapudi * 1205853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 1206853e2bd2SBhanu Gollapudi * @kcqe: kcqe pointer 1207853e2bd2SBhanu Gollapudi * @num_cqe: Number of completion queue elements 1208853e2bd2SBhanu Gollapudi * 1209853e2bd2SBhanu Gollapudi * Generic KCQ event handler 1210853e2bd2SBhanu Gollapudi */ 1211853e2bd2SBhanu Gollapudi void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[], 1212853e2bd2SBhanu Gollapudi u32 num_cqe) 1213853e2bd2SBhanu Gollapudi { 1214853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context; 1215853e2bd2SBhanu Gollapudi int i = 0; 1216853e2bd2SBhanu Gollapudi struct fcoe_kcqe *kcqe = NULL; 1217853e2bd2SBhanu Gollapudi 1218853e2bd2SBhanu Gollapudi while (i < num_cqe) { 1219853e2bd2SBhanu Gollapudi kcqe = (struct fcoe_kcqe *) kcq[i++]; 1220853e2bd2SBhanu Gollapudi 1221853e2bd2SBhanu Gollapudi switch (kcqe->op_code) { 1222853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION: 1223853e2bd2SBhanu Gollapudi bnx2fc_fastpath_notification(hba, kcqe); 1224853e2bd2SBhanu Gollapudi break; 1225853e2bd2SBhanu Gollapudi 1226853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_OFFLOAD_CONN: 1227853e2bd2SBhanu Gollapudi bnx2fc_process_ofld_cmpl(hba, kcqe); 1228853e2bd2SBhanu Gollapudi break; 1229853e2bd2SBhanu Gollapudi 1230853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_ENABLE_CONN: 1231853e2bd2SBhanu Gollapudi bnx2fc_process_enable_conn_cmpl(hba, kcqe); 1232853e2bd2SBhanu Gollapudi break; 1233853e2bd2SBhanu Gollapudi 1234853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_INIT_FUNC: 1235853e2bd2SBhanu Gollapudi if (kcqe->completion_status != 1236853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) { 1237853e2bd2SBhanu Gollapudi bnx2fc_init_failure(hba, 1238853e2bd2SBhanu Gollapudi kcqe->completion_status); 1239853e2bd2SBhanu Gollapudi } else { 1240853e2bd2SBhanu Gollapudi set_bit(ADAPTER_STATE_UP, &hba->adapter_state); 1241853e2bd2SBhanu Gollapudi bnx2fc_get_link_state(hba); 1242853e2bd2SBhanu Gollapudi printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n", 1243853e2bd2SBhanu Gollapudi (u8)hba->pcidev->bus->number); 1244853e2bd2SBhanu Gollapudi } 1245853e2bd2SBhanu Gollapudi break; 1246853e2bd2SBhanu Gollapudi 1247853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DESTROY_FUNC: 1248853e2bd2SBhanu Gollapudi if (kcqe->completion_status != 1249853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) { 1250853e2bd2SBhanu Gollapudi 1251853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "DESTROY failed\n"); 1252853e2bd2SBhanu Gollapudi } else { 1253853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "DESTROY success\n"); 1254853e2bd2SBhanu Gollapudi } 1255*aea71a02SBhanu Prakash Gollapudi set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags); 1256853e2bd2SBhanu Gollapudi wake_up_interruptible(&hba->destroy_wait); 1257853e2bd2SBhanu Gollapudi break; 1258853e2bd2SBhanu Gollapudi 1259853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DISABLE_CONN: 1260853e2bd2SBhanu Gollapudi bnx2fc_process_conn_disable_cmpl(hba, kcqe); 1261853e2bd2SBhanu Gollapudi break; 1262853e2bd2SBhanu Gollapudi 1263853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DESTROY_CONN: 1264853e2bd2SBhanu Gollapudi bnx2fc_process_conn_destroy_cmpl(hba, kcqe); 1265853e2bd2SBhanu Gollapudi break; 1266853e2bd2SBhanu Gollapudi 1267853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_STAT_FUNC: 1268853e2bd2SBhanu Gollapudi if (kcqe->completion_status != 1269853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) 1270853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "STAT failed\n"); 1271853e2bd2SBhanu Gollapudi complete(&hba->stat_req_done); 1272853e2bd2SBhanu Gollapudi break; 1273853e2bd2SBhanu Gollapudi 1274853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_FCOE_ERROR: 1275853e2bd2SBhanu Gollapudi /* fall thru */ 1276853e2bd2SBhanu Gollapudi default: 1277b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "unknown opcode 0x%x\n", 1278853e2bd2SBhanu Gollapudi kcqe->op_code); 1279853e2bd2SBhanu Gollapudi } 1280853e2bd2SBhanu Gollapudi } 1281853e2bd2SBhanu Gollapudi } 1282853e2bd2SBhanu Gollapudi 1283853e2bd2SBhanu Gollapudi void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid) 1284853e2bd2SBhanu Gollapudi { 1285853e2bd2SBhanu Gollapudi struct fcoe_sqe *sqe; 1286853e2bd2SBhanu Gollapudi 1287853e2bd2SBhanu Gollapudi sqe = &tgt->sq[tgt->sq_prod_idx]; 1288853e2bd2SBhanu Gollapudi 1289853e2bd2SBhanu Gollapudi /* Fill SQ WQE */ 1290853e2bd2SBhanu Gollapudi sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT; 1291853e2bd2SBhanu Gollapudi sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT; 1292853e2bd2SBhanu Gollapudi 1293853e2bd2SBhanu Gollapudi /* Advance SQ Prod Idx */ 1294853e2bd2SBhanu Gollapudi if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) { 1295853e2bd2SBhanu Gollapudi tgt->sq_prod_idx = 0; 1296853e2bd2SBhanu Gollapudi tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit; 1297853e2bd2SBhanu Gollapudi } 1298853e2bd2SBhanu Gollapudi } 1299853e2bd2SBhanu Gollapudi 1300853e2bd2SBhanu Gollapudi void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt) 1301853e2bd2SBhanu Gollapudi { 1302619c5cb6SVlad Zolotarov struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db; 1303853e2bd2SBhanu Gollapudi u32 msg; 1304853e2bd2SBhanu Gollapudi 1305853e2bd2SBhanu Gollapudi wmb(); 1306619c5cb6SVlad Zolotarov sq_db->prod = tgt->sq_prod_idx | 1307853e2bd2SBhanu Gollapudi (tgt->sq_curr_toggle_bit << 15); 1308619c5cb6SVlad Zolotarov msg = *((u32 *)sq_db); 1309853e2bd2SBhanu Gollapudi writel(cpu_to_le32(msg), tgt->ctx_base); 1310853e2bd2SBhanu Gollapudi mmiowb(); 1311853e2bd2SBhanu Gollapudi 1312853e2bd2SBhanu Gollapudi } 1313853e2bd2SBhanu Gollapudi 1314853e2bd2SBhanu Gollapudi int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt) 1315853e2bd2SBhanu Gollapudi { 1316853e2bd2SBhanu Gollapudi u32 context_id = tgt->context_id; 1317853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port; 1318853e2bd2SBhanu Gollapudi u32 reg_off; 1319853e2bd2SBhanu Gollapudi resource_size_t reg_base; 1320*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv; 1321*aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba; 1322853e2bd2SBhanu Gollapudi 1323853e2bd2SBhanu Gollapudi reg_base = pci_resource_start(hba->pcidev, 1324853e2bd2SBhanu Gollapudi BNX2X_DOORBELL_PCI_BAR); 1325853e2bd2SBhanu Gollapudi reg_off = BNX2FC_5771X_DB_PAGE_SIZE * 1326853e2bd2SBhanu Gollapudi (context_id & 0x1FFFF) + DPM_TRIGER_TYPE; 1327853e2bd2SBhanu Gollapudi tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4); 1328853e2bd2SBhanu Gollapudi if (!tgt->ctx_base) 1329853e2bd2SBhanu Gollapudi return -ENOMEM; 1330853e2bd2SBhanu Gollapudi return 0; 1331853e2bd2SBhanu Gollapudi } 1332853e2bd2SBhanu Gollapudi 1333853e2bd2SBhanu Gollapudi char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items) 1334853e2bd2SBhanu Gollapudi { 1335853e2bd2SBhanu Gollapudi char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ); 1336853e2bd2SBhanu Gollapudi 1337853e2bd2SBhanu Gollapudi if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX) 1338853e2bd2SBhanu Gollapudi return NULL; 1339853e2bd2SBhanu Gollapudi 1340853e2bd2SBhanu Gollapudi tgt->rq_cons_idx += num_items; 1341853e2bd2SBhanu Gollapudi 1342853e2bd2SBhanu Gollapudi if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX) 1343853e2bd2SBhanu Gollapudi tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX; 1344853e2bd2SBhanu Gollapudi 1345853e2bd2SBhanu Gollapudi return buf; 1346853e2bd2SBhanu Gollapudi } 1347853e2bd2SBhanu Gollapudi 1348853e2bd2SBhanu Gollapudi void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items) 1349853e2bd2SBhanu Gollapudi { 1350853e2bd2SBhanu Gollapudi /* return the rq buffer */ 1351853e2bd2SBhanu Gollapudi u32 next_prod_idx = tgt->rq_prod_idx + num_items; 1352853e2bd2SBhanu Gollapudi if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) { 1353853e2bd2SBhanu Gollapudi /* Wrap around RQ */ 1354853e2bd2SBhanu Gollapudi next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX; 1355853e2bd2SBhanu Gollapudi } 1356853e2bd2SBhanu Gollapudi tgt->rq_prod_idx = next_prod_idx; 1357853e2bd2SBhanu Gollapudi tgt->conn_db->rq_prod = tgt->rq_prod_idx; 1358853e2bd2SBhanu Gollapudi } 1359853e2bd2SBhanu Gollapudi 1360853e2bd2SBhanu Gollapudi void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req, 1361853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task, 1362853e2bd2SBhanu Gollapudi u16 orig_xid) 1363853e2bd2SBhanu Gollapudi { 1364853e2bd2SBhanu Gollapudi u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP; 1365853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt; 1366853e2bd2SBhanu Gollapudi u32 context_id = tgt->context_id; 1367853e2bd2SBhanu Gollapudi 1368853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry)); 1369853e2bd2SBhanu Gollapudi 1370853e2bd2SBhanu Gollapudi /* Tx Write Rx Read */ 1371619c5cb6SVlad Zolotarov /* init flags */ 1372619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags = task_type << 1373619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT; 1374619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 << 1375619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT; 1376619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= 1377619c5cb6SVlad Zolotarov FCOE_TASK_DEV_TYPE_DISK << 1378619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT; 1379619c5cb6SVlad Zolotarov task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid; 1380853e2bd2SBhanu Gollapudi 1381619c5cb6SVlad Zolotarov /* Tx flags */ 1382619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.tx_flags = 1383619c5cb6SVlad Zolotarov FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP << 1384619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT; 1385853e2bd2SBhanu Gollapudi 1386619c5cb6SVlad Zolotarov /* Rx Read Tx Write */ 1387619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.init_flags = context_id << 1388619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT; 1389619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_flags |= 1 << 1390619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT; 1391853e2bd2SBhanu Gollapudi } 1392853e2bd2SBhanu Gollapudi 1393853e2bd2SBhanu Gollapudi void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req, 1394853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task) 1395853e2bd2SBhanu Gollapudi { 1396853e2bd2SBhanu Gollapudi struct bnx2fc_mp_req *mp_req = &(io_req->mp_req); 1397853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt; 1398853e2bd2SBhanu Gollapudi struct fc_frame_header *fc_hdr; 1399619c5cb6SVlad Zolotarov struct fcoe_ext_mul_sges_ctx *sgl; 1400853e2bd2SBhanu Gollapudi u8 task_type = 0; 1401853e2bd2SBhanu Gollapudi u64 *hdr; 1402853e2bd2SBhanu Gollapudi u64 temp_hdr[3]; 1403853e2bd2SBhanu Gollapudi u32 context_id; 1404853e2bd2SBhanu Gollapudi 1405853e2bd2SBhanu Gollapudi 1406853e2bd2SBhanu Gollapudi /* Obtain task_type */ 1407853e2bd2SBhanu Gollapudi if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) || 1408853e2bd2SBhanu Gollapudi (io_req->cmd_type == BNX2FC_ELS)) { 1409853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_MIDPATH; 1410853e2bd2SBhanu Gollapudi } else if (io_req->cmd_type == BNX2FC_ABTS) { 1411853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_ABTS; 1412853e2bd2SBhanu Gollapudi } 1413853e2bd2SBhanu Gollapudi 1414853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry)); 1415853e2bd2SBhanu Gollapudi 1416853e2bd2SBhanu Gollapudi /* Setup the task from io_req for easy reference */ 1417853e2bd2SBhanu Gollapudi io_req->task = task; 1418853e2bd2SBhanu Gollapudi 1419853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n", 1420853e2bd2SBhanu Gollapudi io_req->cmd_type, task_type); 1421853e2bd2SBhanu Gollapudi 1422853e2bd2SBhanu Gollapudi /* Tx only */ 1423853e2bd2SBhanu Gollapudi if ((task_type == FCOE_TASK_TYPE_MIDPATH) || 1424853e2bd2SBhanu Gollapudi (task_type == FCOE_TASK_TYPE_UNSOLICITED)) { 1425619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo = 1426853e2bd2SBhanu Gollapudi (u32)mp_req->mp_req_bd_dma; 1427619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi = 1428853e2bd2SBhanu Gollapudi (u32)((u64)mp_req->mp_req_bd_dma >> 32); 1429619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1; 1430853e2bd2SBhanu Gollapudi } 1431853e2bd2SBhanu Gollapudi 1432853e2bd2SBhanu Gollapudi /* Tx Write Rx Read */ 1433619c5cb6SVlad Zolotarov /* init flags */ 1434619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags = task_type << 1435619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT; 1436619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= 1437619c5cb6SVlad Zolotarov FCOE_TASK_DEV_TYPE_DISK << 1438619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT; 1439619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 << 1440619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT; 1441853e2bd2SBhanu Gollapudi 1442619c5cb6SVlad Zolotarov /* tx flags */ 1443619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_INIT << 1444619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT; 1445853e2bd2SBhanu Gollapudi 1446853e2bd2SBhanu Gollapudi /* Rx Write Tx Read */ 1447619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len; 1448619c5cb6SVlad Zolotarov 1449619c5cb6SVlad Zolotarov /* rx flags */ 1450619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_flags |= 1 << 1451619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT; 1452619c5cb6SVlad Zolotarov 1453619c5cb6SVlad Zolotarov context_id = tgt->context_id; 1454619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.init_flags = context_id << 1455619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT; 1456619c5cb6SVlad Zolotarov 1457853e2bd2SBhanu Gollapudi fc_hdr = &(mp_req->req_fc_hdr); 1458853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_MIDPATH) { 1459853e2bd2SBhanu Gollapudi fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid); 1460853e2bd2SBhanu Gollapudi fc_hdr->fh_rx_id = htons(0xffff); 1461619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_id = 0xffff; 1462853e2bd2SBhanu Gollapudi } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) { 1463853e2bd2SBhanu Gollapudi fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid); 1464853e2bd2SBhanu Gollapudi } 1465853e2bd2SBhanu Gollapudi 1466853e2bd2SBhanu Gollapudi /* Fill FC Header into middle path buffer */ 1467619c5cb6SVlad Zolotarov hdr = (u64 *) &task->txwr_rxrd.union_ctx.tx_frame.fc_hdr; 1468853e2bd2SBhanu Gollapudi memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr)); 1469853e2bd2SBhanu Gollapudi hdr[0] = cpu_to_be64(temp_hdr[0]); 1470853e2bd2SBhanu Gollapudi hdr[1] = cpu_to_be64(temp_hdr[1]); 1471853e2bd2SBhanu Gollapudi hdr[2] = cpu_to_be64(temp_hdr[2]); 1472853e2bd2SBhanu Gollapudi 1473853e2bd2SBhanu Gollapudi /* Rx Only */ 1474853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_MIDPATH) { 1475619c5cb6SVlad Zolotarov sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl; 1476853e2bd2SBhanu Gollapudi 1477619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.lo = (u32)mp_req->mp_resp_bd_dma; 1478619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.hi = 1479853e2bd2SBhanu Gollapudi (u32)((u64)mp_req->mp_resp_bd_dma >> 32); 1480619c5cb6SVlad Zolotarov sgl->mul_sgl.sgl_size = 1; 1481853e2bd2SBhanu Gollapudi } 1482853e2bd2SBhanu Gollapudi } 1483853e2bd2SBhanu Gollapudi 1484853e2bd2SBhanu Gollapudi void bnx2fc_init_task(struct bnx2fc_cmd *io_req, 1485853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task) 1486853e2bd2SBhanu Gollapudi { 1487853e2bd2SBhanu Gollapudi u8 task_type; 1488853e2bd2SBhanu Gollapudi struct scsi_cmnd *sc_cmd = io_req->sc_cmd; 1489853e2bd2SBhanu Gollapudi struct io_bdt *bd_tbl = io_req->bd_tbl; 1490853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt; 1491619c5cb6SVlad Zolotarov struct fcoe_cached_sge_ctx *cached_sge; 1492619c5cb6SVlad Zolotarov struct fcoe_ext_mul_sges_ctx *sgl; 1493853e2bd2SBhanu Gollapudi u64 *fcp_cmnd; 1494853e2bd2SBhanu Gollapudi u64 tmp_fcp_cmnd[4]; 1495853e2bd2SBhanu Gollapudi u32 context_id; 1496853e2bd2SBhanu Gollapudi int cnt, i; 1497853e2bd2SBhanu Gollapudi int bd_count; 1498853e2bd2SBhanu Gollapudi 1499853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry)); 1500853e2bd2SBhanu Gollapudi 1501853e2bd2SBhanu Gollapudi /* Setup the task from io_req for easy reference */ 1502853e2bd2SBhanu Gollapudi io_req->task = task; 1503853e2bd2SBhanu Gollapudi 1504853e2bd2SBhanu Gollapudi if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) 1505853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_WRITE; 1506853e2bd2SBhanu Gollapudi else 1507853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_READ; 1508853e2bd2SBhanu Gollapudi 1509853e2bd2SBhanu Gollapudi /* Tx only */ 1510853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_WRITE) { 1511619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo = 1512853e2bd2SBhanu Gollapudi (u32)bd_tbl->bd_tbl_dma; 1513619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi = 1514853e2bd2SBhanu Gollapudi (u32)((u64)bd_tbl->bd_tbl_dma >> 32); 1515619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1516853e2bd2SBhanu Gollapudi bd_tbl->bd_valid; 1517853e2bd2SBhanu Gollapudi } 1518853e2bd2SBhanu Gollapudi 1519853e2bd2SBhanu Gollapudi /*Tx Write Rx Read */ 1520853e2bd2SBhanu Gollapudi /* Init state to NORMAL */ 1521619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags = task_type << 1522619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT; 1523619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= 1524619c5cb6SVlad Zolotarov FCOE_TASK_DEV_TYPE_DISK << 1525619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT; 1526619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 << 1527619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT; 1528619c5cb6SVlad Zolotarov /* tx flags */ 1529619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_NORMAL << 1530619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT; 1531853e2bd2SBhanu Gollapudi 1532853e2bd2SBhanu Gollapudi /* Set initial seq counter */ 1533619c5cb6SVlad Zolotarov task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1; 1534853e2bd2SBhanu Gollapudi 1535853e2bd2SBhanu Gollapudi /* Fill FCP_CMND IU */ 1536853e2bd2SBhanu Gollapudi fcp_cmnd = (u64 *) 1537619c5cb6SVlad Zolotarov task->txwr_rxrd.union_ctx.fcp_cmd.opaque; 1538853e2bd2SBhanu Gollapudi bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd); 1539853e2bd2SBhanu Gollapudi 1540853e2bd2SBhanu Gollapudi /* swap fcp_cmnd */ 1541853e2bd2SBhanu Gollapudi cnt = sizeof(struct fcp_cmnd) / sizeof(u64); 1542853e2bd2SBhanu Gollapudi 1543853e2bd2SBhanu Gollapudi for (i = 0; i < cnt; i++) { 1544853e2bd2SBhanu Gollapudi *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]); 1545853e2bd2SBhanu Gollapudi fcp_cmnd++; 1546853e2bd2SBhanu Gollapudi } 1547853e2bd2SBhanu Gollapudi 1548853e2bd2SBhanu Gollapudi /* Rx Write Tx Read */ 1549619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len; 1550619c5cb6SVlad Zolotarov 1551619c5cb6SVlad Zolotarov context_id = tgt->context_id; 1552619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.init_flags = context_id << 1553619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT; 1554619c5cb6SVlad Zolotarov 1555619c5cb6SVlad Zolotarov /* rx flags */ 1556619c5cb6SVlad Zolotarov /* Set state to "waiting for the first packet" */ 1557619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_flags |= 1 << 1558619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT; 1559619c5cb6SVlad Zolotarov 1560619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_id = 0xffff; 1561853e2bd2SBhanu Gollapudi 1562853e2bd2SBhanu Gollapudi /* Rx Only */ 1563619c5cb6SVlad Zolotarov cached_sge = &task->rxwr_only.union_ctx.read_info.sgl_ctx.cached_sge; 1564619c5cb6SVlad Zolotarov sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl; 1565853e2bd2SBhanu Gollapudi bd_count = bd_tbl->bd_valid; 1566619c5cb6SVlad Zolotarov if (task_type == FCOE_TASK_TYPE_READ) { 1567853e2bd2SBhanu Gollapudi if (bd_count == 1) { 1568853e2bd2SBhanu Gollapudi 1569853e2bd2SBhanu Gollapudi struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl; 1570853e2bd2SBhanu Gollapudi 1571619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo; 1572619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi; 1573619c5cb6SVlad Zolotarov cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len; 1574619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= 1 << 1575619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT; 1576619c5cb6SVlad Zolotarov } else if (bd_count == 2) { 1577619c5cb6SVlad Zolotarov struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl; 1578619c5cb6SVlad Zolotarov 1579619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo; 1580619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi; 1581619c5cb6SVlad Zolotarov cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len; 1582619c5cb6SVlad Zolotarov 1583619c5cb6SVlad Zolotarov fcoe_bd_tbl++; 1584619c5cb6SVlad Zolotarov cached_sge->second_buf_addr.lo = 1585853e2bd2SBhanu Gollapudi fcoe_bd_tbl->buf_addr_lo; 1586619c5cb6SVlad Zolotarov cached_sge->second_buf_addr.hi = 1587853e2bd2SBhanu Gollapudi fcoe_bd_tbl->buf_addr_hi; 1588619c5cb6SVlad Zolotarov cached_sge->second_buf_rem = fcoe_bd_tbl->buf_len; 1589619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= 1 << 1590619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT; 1591853e2bd2SBhanu Gollapudi } else { 1592853e2bd2SBhanu Gollapudi 1593619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma; 1594619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.hi = 1595853e2bd2SBhanu Gollapudi (u32)((u64)bd_tbl->bd_tbl_dma >> 32); 1596619c5cb6SVlad Zolotarov sgl->mul_sgl.sgl_size = bd_count; 1597853e2bd2SBhanu Gollapudi } 1598853e2bd2SBhanu Gollapudi } 1599853e2bd2SBhanu Gollapudi } 1600853e2bd2SBhanu Gollapudi 1601853e2bd2SBhanu Gollapudi /** 1602853e2bd2SBhanu Gollapudi * bnx2fc_setup_task_ctx - allocate and map task context 1603853e2bd2SBhanu Gollapudi * 1604853e2bd2SBhanu Gollapudi * @hba: pointer to adapter structure 1605853e2bd2SBhanu Gollapudi * 1606853e2bd2SBhanu Gollapudi * allocate memory for task context, and associated BD table to be used 1607853e2bd2SBhanu Gollapudi * by firmware 1608853e2bd2SBhanu Gollapudi * 1609853e2bd2SBhanu Gollapudi */ 1610853e2bd2SBhanu Gollapudi int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba) 1611853e2bd2SBhanu Gollapudi { 1612853e2bd2SBhanu Gollapudi int rc = 0; 1613853e2bd2SBhanu Gollapudi struct regpair *task_ctx_bdt; 1614853e2bd2SBhanu Gollapudi dma_addr_t addr; 1615853e2bd2SBhanu Gollapudi int i; 1616853e2bd2SBhanu Gollapudi 1617853e2bd2SBhanu Gollapudi /* 1618853e2bd2SBhanu Gollapudi * Allocate task context bd table. A page size of bd table 1619853e2bd2SBhanu Gollapudi * can map 256 buffers. Each buffer contains 32 task context 1620853e2bd2SBhanu Gollapudi * entries. Hence the limit with one page is 8192 task context 1621853e2bd2SBhanu Gollapudi * entries. 1622853e2bd2SBhanu Gollapudi */ 1623853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, 1624853e2bd2SBhanu Gollapudi PAGE_SIZE, 1625853e2bd2SBhanu Gollapudi &hba->task_ctx_bd_dma, 1626853e2bd2SBhanu Gollapudi GFP_KERNEL); 1627853e2bd2SBhanu Gollapudi if (!hba->task_ctx_bd_tbl) { 1628853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate task context BDT\n"); 1629853e2bd2SBhanu Gollapudi rc = -1; 1630853e2bd2SBhanu Gollapudi goto out; 1631853e2bd2SBhanu Gollapudi } 1632853e2bd2SBhanu Gollapudi memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE); 1633853e2bd2SBhanu Gollapudi 1634853e2bd2SBhanu Gollapudi /* 1635853e2bd2SBhanu Gollapudi * Allocate task_ctx which is an array of pointers pointing to 1636853e2bd2SBhanu Gollapudi * a page containing 32 task contexts 1637853e2bd2SBhanu Gollapudi */ 1638853e2bd2SBhanu Gollapudi hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)), 1639853e2bd2SBhanu Gollapudi GFP_KERNEL); 1640853e2bd2SBhanu Gollapudi if (!hba->task_ctx) { 1641853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate task context array\n"); 1642853e2bd2SBhanu Gollapudi rc = -1; 1643853e2bd2SBhanu Gollapudi goto out1; 1644853e2bd2SBhanu Gollapudi } 1645853e2bd2SBhanu Gollapudi 1646853e2bd2SBhanu Gollapudi /* 1647853e2bd2SBhanu Gollapudi * Allocate task_ctx_dma which is an array of dma addresses 1648853e2bd2SBhanu Gollapudi */ 1649853e2bd2SBhanu Gollapudi hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ * 1650853e2bd2SBhanu Gollapudi sizeof(dma_addr_t)), GFP_KERNEL); 1651853e2bd2SBhanu Gollapudi if (!hba->task_ctx_dma) { 1652853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc context mapping array\n"); 1653853e2bd2SBhanu Gollapudi rc = -1; 1654853e2bd2SBhanu Gollapudi goto out2; 1655853e2bd2SBhanu Gollapudi } 1656853e2bd2SBhanu Gollapudi 1657853e2bd2SBhanu Gollapudi task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl; 1658853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) { 1659853e2bd2SBhanu Gollapudi 1660853e2bd2SBhanu Gollapudi hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev, 1661853e2bd2SBhanu Gollapudi PAGE_SIZE, 1662853e2bd2SBhanu Gollapudi &hba->task_ctx_dma[i], 1663853e2bd2SBhanu Gollapudi GFP_KERNEL); 1664853e2bd2SBhanu Gollapudi if (!hba->task_ctx[i]) { 1665853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc task context\n"); 1666853e2bd2SBhanu Gollapudi rc = -1; 1667853e2bd2SBhanu Gollapudi goto out3; 1668853e2bd2SBhanu Gollapudi } 1669853e2bd2SBhanu Gollapudi memset(hba->task_ctx[i], 0, PAGE_SIZE); 1670853e2bd2SBhanu Gollapudi addr = (u64)hba->task_ctx_dma[i]; 1671853e2bd2SBhanu Gollapudi task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32); 1672853e2bd2SBhanu Gollapudi task_ctx_bdt->lo = cpu_to_le32((u32)addr); 1673853e2bd2SBhanu Gollapudi task_ctx_bdt++; 1674853e2bd2SBhanu Gollapudi } 1675853e2bd2SBhanu Gollapudi return 0; 1676853e2bd2SBhanu Gollapudi 1677853e2bd2SBhanu Gollapudi out3: 1678853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) { 1679853e2bd2SBhanu Gollapudi if (hba->task_ctx[i]) { 1680853e2bd2SBhanu Gollapudi 1681853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1682853e2bd2SBhanu Gollapudi hba->task_ctx[i], hba->task_ctx_dma[i]); 1683853e2bd2SBhanu Gollapudi hba->task_ctx[i] = NULL; 1684853e2bd2SBhanu Gollapudi } 1685853e2bd2SBhanu Gollapudi } 1686853e2bd2SBhanu Gollapudi 1687853e2bd2SBhanu Gollapudi kfree(hba->task_ctx_dma); 1688853e2bd2SBhanu Gollapudi hba->task_ctx_dma = NULL; 1689853e2bd2SBhanu Gollapudi out2: 1690853e2bd2SBhanu Gollapudi kfree(hba->task_ctx); 1691853e2bd2SBhanu Gollapudi hba->task_ctx = NULL; 1692853e2bd2SBhanu Gollapudi out1: 1693853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1694853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma); 1695853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = NULL; 1696853e2bd2SBhanu Gollapudi out: 1697853e2bd2SBhanu Gollapudi return rc; 1698853e2bd2SBhanu Gollapudi } 1699853e2bd2SBhanu Gollapudi 1700853e2bd2SBhanu Gollapudi void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba) 1701853e2bd2SBhanu Gollapudi { 1702853e2bd2SBhanu Gollapudi int i; 1703853e2bd2SBhanu Gollapudi 1704853e2bd2SBhanu Gollapudi if (hba->task_ctx_bd_tbl) { 1705853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1706853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl, 1707853e2bd2SBhanu Gollapudi hba->task_ctx_bd_dma); 1708853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = NULL; 1709853e2bd2SBhanu Gollapudi } 1710853e2bd2SBhanu Gollapudi 1711853e2bd2SBhanu Gollapudi if (hba->task_ctx) { 1712853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) { 1713853e2bd2SBhanu Gollapudi if (hba->task_ctx[i]) { 1714853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1715853e2bd2SBhanu Gollapudi hba->task_ctx[i], 1716853e2bd2SBhanu Gollapudi hba->task_ctx_dma[i]); 1717853e2bd2SBhanu Gollapudi hba->task_ctx[i] = NULL; 1718853e2bd2SBhanu Gollapudi } 1719853e2bd2SBhanu Gollapudi } 1720853e2bd2SBhanu Gollapudi kfree(hba->task_ctx); 1721853e2bd2SBhanu Gollapudi hba->task_ctx = NULL; 1722853e2bd2SBhanu Gollapudi } 1723853e2bd2SBhanu Gollapudi 1724853e2bd2SBhanu Gollapudi kfree(hba->task_ctx_dma); 1725853e2bd2SBhanu Gollapudi hba->task_ctx_dma = NULL; 1726853e2bd2SBhanu Gollapudi } 1727853e2bd2SBhanu Gollapudi 1728853e2bd2SBhanu Gollapudi static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba) 1729853e2bd2SBhanu Gollapudi { 1730853e2bd2SBhanu Gollapudi int i; 1731853e2bd2SBhanu Gollapudi int segment_count; 1732853e2bd2SBhanu Gollapudi int hash_table_size; 1733853e2bd2SBhanu Gollapudi u32 *pbl; 1734853e2bd2SBhanu Gollapudi 1735853e2bd2SBhanu Gollapudi segment_count = hba->hash_tbl_segment_count; 1736853e2bd2SBhanu Gollapudi hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL * 1737853e2bd2SBhanu Gollapudi sizeof(struct fcoe_hash_table_entry); 1738853e2bd2SBhanu Gollapudi 1739853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl; 1740853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) { 1741853e2bd2SBhanu Gollapudi dma_addr_t dma_address; 1742853e2bd2SBhanu Gollapudi 1743853e2bd2SBhanu Gollapudi dma_address = le32_to_cpu(*pbl); 1744853e2bd2SBhanu Gollapudi ++pbl; 1745853e2bd2SBhanu Gollapudi dma_address += ((u64)le32_to_cpu(*pbl)) << 32; 1746853e2bd2SBhanu Gollapudi ++pbl; 1747853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, 1748853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE, 1749853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i], 1750853e2bd2SBhanu Gollapudi dma_address); 1751853e2bd2SBhanu Gollapudi 1752853e2bd2SBhanu Gollapudi } 1753853e2bd2SBhanu Gollapudi 1754853e2bd2SBhanu Gollapudi if (hba->hash_tbl_pbl) { 1755853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1756853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl, 1757853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl_dma); 1758853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl = NULL; 1759853e2bd2SBhanu Gollapudi } 1760853e2bd2SBhanu Gollapudi } 1761853e2bd2SBhanu Gollapudi 1762853e2bd2SBhanu Gollapudi static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba) 1763853e2bd2SBhanu Gollapudi { 1764853e2bd2SBhanu Gollapudi int i; 1765853e2bd2SBhanu Gollapudi int hash_table_size; 1766853e2bd2SBhanu Gollapudi int segment_count; 1767853e2bd2SBhanu Gollapudi int segment_array_size; 1768853e2bd2SBhanu Gollapudi int dma_segment_array_size; 1769853e2bd2SBhanu Gollapudi dma_addr_t *dma_segment_array; 1770853e2bd2SBhanu Gollapudi u32 *pbl; 1771853e2bd2SBhanu Gollapudi 1772853e2bd2SBhanu Gollapudi hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL * 1773853e2bd2SBhanu Gollapudi sizeof(struct fcoe_hash_table_entry); 1774853e2bd2SBhanu Gollapudi 1775853e2bd2SBhanu Gollapudi segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1; 1776853e2bd2SBhanu Gollapudi segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE; 1777853e2bd2SBhanu Gollapudi hba->hash_tbl_segment_count = segment_count; 1778853e2bd2SBhanu Gollapudi 1779853e2bd2SBhanu Gollapudi segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments); 1780853e2bd2SBhanu Gollapudi hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL); 1781853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_segments) { 1782853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pointers alloc failed\n"); 1783853e2bd2SBhanu Gollapudi return -ENOMEM; 1784853e2bd2SBhanu Gollapudi } 1785853e2bd2SBhanu Gollapudi dma_segment_array_size = segment_count * sizeof(*dma_segment_array); 1786853e2bd2SBhanu Gollapudi dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL); 1787853e2bd2SBhanu Gollapudi if (!dma_segment_array) { 1788853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n"); 1789853e2bd2SBhanu Gollapudi return -ENOMEM; 1790853e2bd2SBhanu Gollapudi } 1791853e2bd2SBhanu Gollapudi 1792853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) { 1793853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i] = 1794853e2bd2SBhanu Gollapudi dma_alloc_coherent(&hba->pcidev->dev, 1795853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE, 1796853e2bd2SBhanu Gollapudi &dma_segment_array[i], 1797853e2bd2SBhanu Gollapudi GFP_KERNEL); 1798853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_segments[i]) { 1799853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash segment alloc failed\n"); 1800853e2bd2SBhanu Gollapudi while (--i >= 0) { 1801853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, 1802853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE, 1803853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i], 1804853e2bd2SBhanu Gollapudi dma_segment_array[i]); 1805853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i] = NULL; 1806853e2bd2SBhanu Gollapudi } 1807853e2bd2SBhanu Gollapudi kfree(dma_segment_array); 1808853e2bd2SBhanu Gollapudi return -ENOMEM; 1809853e2bd2SBhanu Gollapudi } 1810853e2bd2SBhanu Gollapudi memset(hba->hash_tbl_segments[i], 0, 1811853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE); 1812853e2bd2SBhanu Gollapudi } 1813853e2bd2SBhanu Gollapudi 1814853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev, 1815853e2bd2SBhanu Gollapudi PAGE_SIZE, 1816853e2bd2SBhanu Gollapudi &hba->hash_tbl_pbl_dma, 1817853e2bd2SBhanu Gollapudi GFP_KERNEL); 1818853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_pbl) { 1819853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pbl alloc failed\n"); 1820853e2bd2SBhanu Gollapudi kfree(dma_segment_array); 1821853e2bd2SBhanu Gollapudi return -ENOMEM; 1822853e2bd2SBhanu Gollapudi } 1823853e2bd2SBhanu Gollapudi memset(hba->hash_tbl_pbl, 0, PAGE_SIZE); 1824853e2bd2SBhanu Gollapudi 1825853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl; 1826853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) { 1827853e2bd2SBhanu Gollapudi u64 paddr = dma_segment_array[i]; 1828853e2bd2SBhanu Gollapudi *pbl = cpu_to_le32((u32) paddr); 1829853e2bd2SBhanu Gollapudi ++pbl; 1830853e2bd2SBhanu Gollapudi *pbl = cpu_to_le32((u32) (paddr >> 32)); 1831853e2bd2SBhanu Gollapudi ++pbl; 1832853e2bd2SBhanu Gollapudi } 1833853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl; 1834853e2bd2SBhanu Gollapudi i = 0; 1835853e2bd2SBhanu Gollapudi while (*pbl && *(pbl + 1)) { 1836853e2bd2SBhanu Gollapudi u32 lo; 1837853e2bd2SBhanu Gollapudi u32 hi; 1838853e2bd2SBhanu Gollapudi lo = *pbl; 1839853e2bd2SBhanu Gollapudi ++pbl; 1840853e2bd2SBhanu Gollapudi hi = *pbl; 1841853e2bd2SBhanu Gollapudi ++pbl; 1842853e2bd2SBhanu Gollapudi ++i; 1843853e2bd2SBhanu Gollapudi } 1844853e2bd2SBhanu Gollapudi kfree(dma_segment_array); 1845853e2bd2SBhanu Gollapudi return 0; 1846853e2bd2SBhanu Gollapudi } 1847853e2bd2SBhanu Gollapudi 1848853e2bd2SBhanu Gollapudi /** 1849853e2bd2SBhanu Gollapudi * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer 1850853e2bd2SBhanu Gollapudi * 1851853e2bd2SBhanu Gollapudi * @hba: Pointer to adapter structure 1852853e2bd2SBhanu Gollapudi * 1853853e2bd2SBhanu Gollapudi */ 1854853e2bd2SBhanu Gollapudi int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba) 1855853e2bd2SBhanu Gollapudi { 1856853e2bd2SBhanu Gollapudi u64 addr; 1857853e2bd2SBhanu Gollapudi u32 mem_size; 1858853e2bd2SBhanu Gollapudi int i; 1859853e2bd2SBhanu Gollapudi 1860853e2bd2SBhanu Gollapudi if (bnx2fc_allocate_hash_table(hba)) 1861853e2bd2SBhanu Gollapudi return -ENOMEM; 1862853e2bd2SBhanu Gollapudi 1863853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair); 1864853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size, 1865853e2bd2SBhanu Gollapudi &hba->t2_hash_tbl_ptr_dma, 1866853e2bd2SBhanu Gollapudi GFP_KERNEL); 1867853e2bd2SBhanu Gollapudi if (!hba->t2_hash_tbl_ptr) { 1868853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n"); 1869853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1870853e2bd2SBhanu Gollapudi return -ENOMEM; 1871853e2bd2SBhanu Gollapudi } 1872853e2bd2SBhanu Gollapudi memset(hba->t2_hash_tbl_ptr, 0x00, mem_size); 1873853e2bd2SBhanu Gollapudi 1874853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * 1875853e2bd2SBhanu Gollapudi sizeof(struct fcoe_t2_hash_table_entry); 1876853e2bd2SBhanu Gollapudi hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size, 1877853e2bd2SBhanu Gollapudi &hba->t2_hash_tbl_dma, 1878853e2bd2SBhanu Gollapudi GFP_KERNEL); 1879853e2bd2SBhanu Gollapudi if (!hba->t2_hash_tbl) { 1880853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate t2 hash table\n"); 1881853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1882853e2bd2SBhanu Gollapudi return -ENOMEM; 1883853e2bd2SBhanu Gollapudi } 1884853e2bd2SBhanu Gollapudi memset(hba->t2_hash_tbl, 0x00, mem_size); 1885853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) { 1886853e2bd2SBhanu Gollapudi addr = (unsigned long) hba->t2_hash_tbl_dma + 1887853e2bd2SBhanu Gollapudi ((i+1) * sizeof(struct fcoe_t2_hash_table_entry)); 1888853e2bd2SBhanu Gollapudi hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff; 1889853e2bd2SBhanu Gollapudi hba->t2_hash_tbl[i].next.hi = addr >> 32; 1890853e2bd2SBhanu Gollapudi } 1891853e2bd2SBhanu Gollapudi 1892853e2bd2SBhanu Gollapudi hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, 1893853e2bd2SBhanu Gollapudi PAGE_SIZE, &hba->dummy_buf_dma, 1894853e2bd2SBhanu Gollapudi GFP_KERNEL); 1895853e2bd2SBhanu Gollapudi if (!hba->dummy_buffer) { 1896853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n"); 1897853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1898853e2bd2SBhanu Gollapudi return -ENOMEM; 1899853e2bd2SBhanu Gollapudi } 1900853e2bd2SBhanu Gollapudi 1901853e2bd2SBhanu Gollapudi hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev, 1902853e2bd2SBhanu Gollapudi PAGE_SIZE, 1903853e2bd2SBhanu Gollapudi &hba->stats_buf_dma, 1904853e2bd2SBhanu Gollapudi GFP_KERNEL); 1905853e2bd2SBhanu Gollapudi if (!hba->stats_buffer) { 1906853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc Stats Buffer\n"); 1907853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1908853e2bd2SBhanu Gollapudi return -ENOMEM; 1909853e2bd2SBhanu Gollapudi } 1910853e2bd2SBhanu Gollapudi memset(hba->stats_buffer, 0x00, PAGE_SIZE); 1911853e2bd2SBhanu Gollapudi 1912853e2bd2SBhanu Gollapudi return 0; 1913853e2bd2SBhanu Gollapudi } 1914853e2bd2SBhanu Gollapudi 1915853e2bd2SBhanu Gollapudi void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba) 1916853e2bd2SBhanu Gollapudi { 1917853e2bd2SBhanu Gollapudi u32 mem_size; 1918853e2bd2SBhanu Gollapudi 1919853e2bd2SBhanu Gollapudi if (hba->stats_buffer) { 1920853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1921853e2bd2SBhanu Gollapudi hba->stats_buffer, hba->stats_buf_dma); 1922853e2bd2SBhanu Gollapudi hba->stats_buffer = NULL; 1923853e2bd2SBhanu Gollapudi } 1924853e2bd2SBhanu Gollapudi 1925853e2bd2SBhanu Gollapudi if (hba->dummy_buffer) { 1926853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1927853e2bd2SBhanu Gollapudi hba->dummy_buffer, hba->dummy_buf_dma); 1928853e2bd2SBhanu Gollapudi hba->dummy_buffer = NULL; 1929853e2bd2SBhanu Gollapudi } 1930853e2bd2SBhanu Gollapudi 1931853e2bd2SBhanu Gollapudi if (hba->t2_hash_tbl_ptr) { 1932853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair); 1933853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, mem_size, 1934853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr, 1935853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr_dma); 1936853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr = NULL; 1937853e2bd2SBhanu Gollapudi } 1938853e2bd2SBhanu Gollapudi 1939853e2bd2SBhanu Gollapudi if (hba->t2_hash_tbl) { 1940853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * 1941853e2bd2SBhanu Gollapudi sizeof(struct fcoe_t2_hash_table_entry); 1942853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, mem_size, 1943853e2bd2SBhanu Gollapudi hba->t2_hash_tbl, hba->t2_hash_tbl_dma); 1944853e2bd2SBhanu Gollapudi hba->t2_hash_tbl = NULL; 1945853e2bd2SBhanu Gollapudi } 1946853e2bd2SBhanu Gollapudi bnx2fc_free_hash_table(hba); 1947853e2bd2SBhanu Gollapudi } 1948