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, 26853e2bd2SBhanu Gollapudi struct fcoe_kcqe *conn_destroy); 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) { 70853e2bd2SBhanu Gollapudi printk(KERN_ALERT 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); 90*1294bfe6SBhanu 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 103853e2bd2SBhanu Gollapudi fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma; 104853e2bd2SBhanu Gollapudi fcoe_init2.hash_tbl_pbl_addr_hi = (u32) 105853e2bd2SBhanu Gollapudi ((u64) hba->hash_tbl_pbl_dma >> 32); 106853e2bd2SBhanu Gollapudi 107853e2bd2SBhanu Gollapudi fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma; 108853e2bd2SBhanu Gollapudi fcoe_init2.t2_hash_tbl_addr_hi = (u32) 109853e2bd2SBhanu Gollapudi ((u64) hba->t2_hash_tbl_dma >> 32); 110853e2bd2SBhanu Gollapudi 111853e2bd2SBhanu Gollapudi fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma; 112853e2bd2SBhanu Gollapudi fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32) 113853e2bd2SBhanu Gollapudi ((u64) hba->t2_hash_tbl_ptr_dma >> 32); 114853e2bd2SBhanu Gollapudi 115853e2bd2SBhanu Gollapudi fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS; 116853e2bd2SBhanu Gollapudi 117853e2bd2SBhanu Gollapudi /* fill init3 KWQE */ 118853e2bd2SBhanu Gollapudi memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3)); 119853e2bd2SBhanu Gollapudi fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3; 120853e2bd2SBhanu Gollapudi fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE << 121853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 122853e2bd2SBhanu Gollapudi fcoe_init3.error_bit_map_lo = 0xffffffff; 123853e2bd2SBhanu Gollapudi fcoe_init3.error_bit_map_hi = 0xffffffff; 124853e2bd2SBhanu Gollapudi 125853e2bd2SBhanu Gollapudi 126853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &fcoe_init1; 127853e2bd2SBhanu Gollapudi kwqe_arr[1] = (struct kwqe *) &fcoe_init2; 128853e2bd2SBhanu Gollapudi kwqe_arr[2] = (struct kwqe *) &fcoe_init3; 129853e2bd2SBhanu Gollapudi 130853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 131853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 132853e2bd2SBhanu Gollapudi 133853e2bd2SBhanu Gollapudi return rc; 134853e2bd2SBhanu Gollapudi } 135853e2bd2SBhanu Gollapudi int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba) 136853e2bd2SBhanu Gollapudi { 137853e2bd2SBhanu Gollapudi struct fcoe_kwqe_destroy fcoe_destroy; 138853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 139853e2bd2SBhanu Gollapudi int num_kwqes = 1; 140853e2bd2SBhanu Gollapudi int rc = -1; 141853e2bd2SBhanu Gollapudi 142853e2bd2SBhanu Gollapudi /* fill destroy KWQE */ 143853e2bd2SBhanu Gollapudi memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy)); 144853e2bd2SBhanu Gollapudi fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY; 145853e2bd2SBhanu Gollapudi fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE << 146853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 147853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &fcoe_destroy; 148853e2bd2SBhanu Gollapudi 149853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 150853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 151853e2bd2SBhanu Gollapudi return rc; 152853e2bd2SBhanu Gollapudi } 153853e2bd2SBhanu Gollapudi 154853e2bd2SBhanu Gollapudi /** 155853e2bd2SBhanu Gollapudi * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process 156853e2bd2SBhanu Gollapudi * 157853e2bd2SBhanu Gollapudi * @port: port structure pointer 158853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 159853e2bd2SBhanu Gollapudi */ 160853e2bd2SBhanu Gollapudi int bnx2fc_send_session_ofld_req(struct fcoe_port *port, 161853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 162853e2bd2SBhanu Gollapudi { 163853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport; 164853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = port->priv; 165853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[4]; 166853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload1 ofld_req1; 167853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload2 ofld_req2; 168853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload3 ofld_req3; 169853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload4 ofld_req4; 170853e2bd2SBhanu Gollapudi struct fc_rport_priv *rdata = tgt->rdata; 171853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport; 172853e2bd2SBhanu Gollapudi int num_kwqes = 4; 173853e2bd2SBhanu Gollapudi u32 port_id; 174853e2bd2SBhanu Gollapudi int rc = 0; 175853e2bd2SBhanu Gollapudi u16 conn_id; 176853e2bd2SBhanu Gollapudi 177853e2bd2SBhanu Gollapudi /* Initialize offload request 1 structure */ 178853e2bd2SBhanu Gollapudi memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1)); 179853e2bd2SBhanu Gollapudi 180853e2bd2SBhanu Gollapudi ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1; 181853e2bd2SBhanu Gollapudi ofld_req1.hdr.flags = 182853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 183853e2bd2SBhanu Gollapudi 184853e2bd2SBhanu Gollapudi 185853e2bd2SBhanu Gollapudi conn_id = (u16)tgt->fcoe_conn_id; 186853e2bd2SBhanu Gollapudi ofld_req1.fcoe_conn_id = conn_id; 187853e2bd2SBhanu Gollapudi 188853e2bd2SBhanu Gollapudi 189853e2bd2SBhanu Gollapudi ofld_req1.sq_addr_lo = (u32) tgt->sq_dma; 190853e2bd2SBhanu Gollapudi ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32); 191853e2bd2SBhanu Gollapudi 192853e2bd2SBhanu Gollapudi ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma; 193853e2bd2SBhanu Gollapudi ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32); 194853e2bd2SBhanu Gollapudi 195853e2bd2SBhanu Gollapudi ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma; 196853e2bd2SBhanu Gollapudi ofld_req1.rq_first_pbe_addr_hi = 197853e2bd2SBhanu Gollapudi (u32)((u64) tgt->rq_dma >> 32); 198853e2bd2SBhanu Gollapudi 199853e2bd2SBhanu Gollapudi ofld_req1.rq_prod = 0x8000; 200853e2bd2SBhanu Gollapudi 201853e2bd2SBhanu Gollapudi /* Initialize offload request 2 structure */ 202853e2bd2SBhanu Gollapudi memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2)); 203853e2bd2SBhanu Gollapudi 204853e2bd2SBhanu Gollapudi ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2; 205853e2bd2SBhanu Gollapudi ofld_req2.hdr.flags = 206853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 207853e2bd2SBhanu Gollapudi 208853e2bd2SBhanu Gollapudi ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size; 209853e2bd2SBhanu Gollapudi 210853e2bd2SBhanu Gollapudi ofld_req2.cq_addr_lo = (u32) tgt->cq_dma; 211853e2bd2SBhanu Gollapudi ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32); 212853e2bd2SBhanu Gollapudi 213853e2bd2SBhanu Gollapudi ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma; 214853e2bd2SBhanu Gollapudi ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32); 215853e2bd2SBhanu Gollapudi 216853e2bd2SBhanu Gollapudi ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma; 217853e2bd2SBhanu Gollapudi ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32); 218853e2bd2SBhanu Gollapudi 219853e2bd2SBhanu Gollapudi /* Initialize offload request 3 structure */ 220853e2bd2SBhanu Gollapudi memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3)); 221853e2bd2SBhanu Gollapudi 222853e2bd2SBhanu Gollapudi ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3; 223853e2bd2SBhanu Gollapudi ofld_req3.hdr.flags = 224853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 225853e2bd2SBhanu Gollapudi 226853e2bd2SBhanu Gollapudi ofld_req3.vlan_tag = hba->vlan_id << 227853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT; 228853e2bd2SBhanu Gollapudi ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT; 229853e2bd2SBhanu Gollapudi 230853e2bd2SBhanu Gollapudi port_id = fc_host_port_id(lport->host); 231853e2bd2SBhanu Gollapudi if (port_id == 0) { 232853e2bd2SBhanu Gollapudi BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n"); 233853e2bd2SBhanu Gollapudi return -EINVAL; 234853e2bd2SBhanu Gollapudi } 235853e2bd2SBhanu Gollapudi 236853e2bd2SBhanu Gollapudi /* 237853e2bd2SBhanu Gollapudi * Store s_id of the initiator for further reference. This will 238853e2bd2SBhanu Gollapudi * be used during disable/destroy during linkdown processing as 239853e2bd2SBhanu Gollapudi * when the lport is reset, the port_id also is reset to 0 240853e2bd2SBhanu Gollapudi */ 241853e2bd2SBhanu Gollapudi tgt->sid = port_id; 242853e2bd2SBhanu Gollapudi ofld_req3.s_id[0] = (port_id & 0x000000FF); 243853e2bd2SBhanu Gollapudi ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8; 244853e2bd2SBhanu Gollapudi ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16; 245853e2bd2SBhanu Gollapudi 246853e2bd2SBhanu Gollapudi port_id = rport->port_id; 247853e2bd2SBhanu Gollapudi ofld_req3.d_id[0] = (port_id & 0x000000FF); 248853e2bd2SBhanu Gollapudi ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8; 249853e2bd2SBhanu Gollapudi ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16; 250853e2bd2SBhanu Gollapudi 251853e2bd2SBhanu Gollapudi ofld_req3.tx_total_conc_seqs = rdata->max_seq; 252853e2bd2SBhanu Gollapudi 253853e2bd2SBhanu Gollapudi ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq; 254853e2bd2SBhanu Gollapudi ofld_req3.rx_max_fc_pay_len = lport->mfs; 255853e2bd2SBhanu Gollapudi 256853e2bd2SBhanu Gollapudi ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS; 257853e2bd2SBhanu Gollapudi ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS; 258853e2bd2SBhanu Gollapudi ofld_req3.rx_open_seqs_exch_c3 = 1; 259853e2bd2SBhanu Gollapudi 260853e2bd2SBhanu Gollapudi ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma; 261853e2bd2SBhanu Gollapudi ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32); 262853e2bd2SBhanu Gollapudi 263853e2bd2SBhanu Gollapudi /* set mul_n_port_ids supported flag to 0, until it is supported */ 264853e2bd2SBhanu Gollapudi ofld_req3.flags = 0; 265853e2bd2SBhanu Gollapudi /* 266853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) << 267853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT); 268853e2bd2SBhanu Gollapudi */ 269853e2bd2SBhanu Gollapudi /* Info from PLOGI response */ 270853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) << 271853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT); 272853e2bd2SBhanu Gollapudi 273853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) << 274853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT); 275853e2bd2SBhanu Gollapudi 276853e2bd2SBhanu Gollapudi /* vlan flag */ 277853e2bd2SBhanu Gollapudi ofld_req3.flags |= (hba->vlan_enabled << 278853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT); 279853e2bd2SBhanu Gollapudi 280853e2bd2SBhanu Gollapudi /* C2_VALID and ACK flags are not set as they are not suppported */ 281853e2bd2SBhanu Gollapudi 282853e2bd2SBhanu Gollapudi 283853e2bd2SBhanu Gollapudi /* Initialize offload request 4 structure */ 284853e2bd2SBhanu Gollapudi memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4)); 285853e2bd2SBhanu Gollapudi ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4; 286853e2bd2SBhanu Gollapudi ofld_req4.hdr.flags = 287853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 288853e2bd2SBhanu Gollapudi 289853e2bd2SBhanu Gollapudi ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20; 290853e2bd2SBhanu Gollapudi 291853e2bd2SBhanu Gollapudi 292853e2bd2SBhanu Gollapudi ofld_req4.src_mac_addr_lo32[0] = port->data_src_addr[5]; 293853e2bd2SBhanu Gollapudi /* local mac */ 294853e2bd2SBhanu Gollapudi ofld_req4.src_mac_addr_lo32[1] = port->data_src_addr[4]; 295853e2bd2SBhanu Gollapudi ofld_req4.src_mac_addr_lo32[2] = port->data_src_addr[3]; 296853e2bd2SBhanu Gollapudi ofld_req4.src_mac_addr_lo32[3] = port->data_src_addr[2]; 297853e2bd2SBhanu Gollapudi ofld_req4.src_mac_addr_hi16[0] = port->data_src_addr[1]; 298853e2bd2SBhanu Gollapudi ofld_req4.src_mac_addr_hi16[1] = port->data_src_addr[0]; 299853e2bd2SBhanu Gollapudi ofld_req4.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */ 300853e2bd2SBhanu Gollapudi ofld_req4.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4]; 301853e2bd2SBhanu Gollapudi ofld_req4.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3]; 302853e2bd2SBhanu Gollapudi ofld_req4.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2]; 303853e2bd2SBhanu Gollapudi ofld_req4.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1]; 304853e2bd2SBhanu Gollapudi ofld_req4.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0]; 305853e2bd2SBhanu Gollapudi 306853e2bd2SBhanu Gollapudi ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma; 307853e2bd2SBhanu Gollapudi ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32); 308853e2bd2SBhanu Gollapudi 309853e2bd2SBhanu Gollapudi ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma; 310853e2bd2SBhanu Gollapudi ofld_req4.confq_pbl_base_addr_hi = 311853e2bd2SBhanu Gollapudi (u32)((u64) tgt->confq_pbl_dma >> 32); 312853e2bd2SBhanu Gollapudi 313853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &ofld_req1; 314853e2bd2SBhanu Gollapudi kwqe_arr[1] = (struct kwqe *) &ofld_req2; 315853e2bd2SBhanu Gollapudi kwqe_arr[2] = (struct kwqe *) &ofld_req3; 316853e2bd2SBhanu Gollapudi kwqe_arr[3] = (struct kwqe *) &ofld_req4; 317853e2bd2SBhanu Gollapudi 318853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 319853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 320853e2bd2SBhanu Gollapudi 321853e2bd2SBhanu Gollapudi return rc; 322853e2bd2SBhanu Gollapudi } 323853e2bd2SBhanu Gollapudi 324853e2bd2SBhanu Gollapudi /** 325853e2bd2SBhanu Gollapudi * bnx2fc_send_session_enable_req - initiates FCoE Session enablement 326853e2bd2SBhanu Gollapudi * 327853e2bd2SBhanu Gollapudi * @port: port structure pointer 328853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 329853e2bd2SBhanu Gollapudi */ 330853e2bd2SBhanu Gollapudi static int bnx2fc_send_session_enable_req(struct fcoe_port *port, 331853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 332853e2bd2SBhanu Gollapudi { 333853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 334853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = port->priv; 335853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_enable_disable enbl_req; 336853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport; 337853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport; 338853e2bd2SBhanu Gollapudi int num_kwqes = 1; 339853e2bd2SBhanu Gollapudi int rc = 0; 340853e2bd2SBhanu Gollapudi u32 port_id; 341853e2bd2SBhanu Gollapudi 342853e2bd2SBhanu Gollapudi memset(&enbl_req, 0x00, 343853e2bd2SBhanu Gollapudi sizeof(struct fcoe_kwqe_conn_enable_disable)); 344853e2bd2SBhanu Gollapudi enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN; 345853e2bd2SBhanu Gollapudi enbl_req.hdr.flags = 346853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 347853e2bd2SBhanu Gollapudi 348853e2bd2SBhanu Gollapudi enbl_req.src_mac_addr_lo32[0] = port->data_src_addr[5]; 349853e2bd2SBhanu Gollapudi /* local mac */ 350853e2bd2SBhanu Gollapudi enbl_req.src_mac_addr_lo32[1] = port->data_src_addr[4]; 351853e2bd2SBhanu Gollapudi enbl_req.src_mac_addr_lo32[2] = port->data_src_addr[3]; 352853e2bd2SBhanu Gollapudi enbl_req.src_mac_addr_lo32[3] = port->data_src_addr[2]; 353853e2bd2SBhanu Gollapudi enbl_req.src_mac_addr_hi16[0] = port->data_src_addr[1]; 354853e2bd2SBhanu Gollapudi enbl_req.src_mac_addr_hi16[1] = port->data_src_addr[0]; 355853e2bd2SBhanu Gollapudi 356853e2bd2SBhanu Gollapudi enbl_req.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */ 357853e2bd2SBhanu Gollapudi enbl_req.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4]; 358853e2bd2SBhanu Gollapudi enbl_req.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3]; 359853e2bd2SBhanu Gollapudi enbl_req.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2]; 360853e2bd2SBhanu Gollapudi enbl_req.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1]; 361853e2bd2SBhanu Gollapudi enbl_req.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0]; 362853e2bd2SBhanu Gollapudi 363853e2bd2SBhanu Gollapudi port_id = fc_host_port_id(lport->host); 364853e2bd2SBhanu Gollapudi if (port_id != tgt->sid) { 365853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x," 366853e2bd2SBhanu Gollapudi "sid = 0x%x\n", port_id, tgt->sid); 367853e2bd2SBhanu Gollapudi port_id = tgt->sid; 368853e2bd2SBhanu Gollapudi } 369853e2bd2SBhanu Gollapudi enbl_req.s_id[0] = (port_id & 0x000000FF); 370853e2bd2SBhanu Gollapudi enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8; 371853e2bd2SBhanu Gollapudi enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16; 372853e2bd2SBhanu Gollapudi 373853e2bd2SBhanu Gollapudi port_id = rport->port_id; 374853e2bd2SBhanu Gollapudi enbl_req.d_id[0] = (port_id & 0x000000FF); 375853e2bd2SBhanu Gollapudi enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8; 376853e2bd2SBhanu Gollapudi enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16; 377853e2bd2SBhanu Gollapudi enbl_req.vlan_tag = hba->vlan_id << 378853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT; 379853e2bd2SBhanu Gollapudi enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT; 380853e2bd2SBhanu Gollapudi enbl_req.vlan_flag = hba->vlan_enabled; 381853e2bd2SBhanu Gollapudi enbl_req.context_id = tgt->context_id; 382853e2bd2SBhanu Gollapudi enbl_req.conn_id = tgt->fcoe_conn_id; 383853e2bd2SBhanu Gollapudi 384853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &enbl_req; 385853e2bd2SBhanu Gollapudi 386853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 387853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 388853e2bd2SBhanu Gollapudi return rc; 389853e2bd2SBhanu Gollapudi } 390853e2bd2SBhanu Gollapudi 391853e2bd2SBhanu Gollapudi /** 392853e2bd2SBhanu Gollapudi * bnx2fc_send_session_disable_req - initiates FCoE Session disable 393853e2bd2SBhanu Gollapudi * 394853e2bd2SBhanu Gollapudi * @port: port structure pointer 395853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 396853e2bd2SBhanu Gollapudi */ 397853e2bd2SBhanu Gollapudi int bnx2fc_send_session_disable_req(struct fcoe_port *port, 398853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 399853e2bd2SBhanu Gollapudi { 400853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = port->priv; 401853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_enable_disable disable_req; 402853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 403853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport; 404853e2bd2SBhanu Gollapudi int num_kwqes = 1; 405853e2bd2SBhanu Gollapudi int rc = 0; 406853e2bd2SBhanu Gollapudi u32 port_id; 407853e2bd2SBhanu Gollapudi 408853e2bd2SBhanu Gollapudi memset(&disable_req, 0x00, 409853e2bd2SBhanu Gollapudi sizeof(struct fcoe_kwqe_conn_enable_disable)); 410853e2bd2SBhanu Gollapudi disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN; 411853e2bd2SBhanu Gollapudi disable_req.hdr.flags = 412853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 413853e2bd2SBhanu Gollapudi 414853e2bd2SBhanu Gollapudi disable_req.src_mac_addr_lo32[0] = port->data_src_addr[5]; 415853e2bd2SBhanu Gollapudi disable_req.src_mac_addr_lo32[2] = port->data_src_addr[3]; 416853e2bd2SBhanu Gollapudi disable_req.src_mac_addr_lo32[3] = port->data_src_addr[2]; 417853e2bd2SBhanu Gollapudi disable_req.src_mac_addr_hi16[0] = port->data_src_addr[1]; 418853e2bd2SBhanu Gollapudi disable_req.src_mac_addr_hi16[1] = port->data_src_addr[0]; 419853e2bd2SBhanu Gollapudi 420853e2bd2SBhanu Gollapudi disable_req.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */ 421853e2bd2SBhanu Gollapudi disable_req.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4]; 422853e2bd2SBhanu Gollapudi disable_req.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3]; 423853e2bd2SBhanu Gollapudi disable_req.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2]; 424853e2bd2SBhanu Gollapudi disable_req.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1]; 425853e2bd2SBhanu Gollapudi disable_req.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0]; 426853e2bd2SBhanu Gollapudi 427853e2bd2SBhanu Gollapudi port_id = tgt->sid; 428853e2bd2SBhanu Gollapudi disable_req.s_id[0] = (port_id & 0x000000FF); 429853e2bd2SBhanu Gollapudi disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8; 430853e2bd2SBhanu Gollapudi disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16; 431853e2bd2SBhanu Gollapudi 432853e2bd2SBhanu Gollapudi 433853e2bd2SBhanu Gollapudi port_id = rport->port_id; 434853e2bd2SBhanu Gollapudi disable_req.d_id[0] = (port_id & 0x000000FF); 435853e2bd2SBhanu Gollapudi disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8; 436853e2bd2SBhanu Gollapudi disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16; 437853e2bd2SBhanu Gollapudi disable_req.context_id = tgt->context_id; 438853e2bd2SBhanu Gollapudi disable_req.conn_id = tgt->fcoe_conn_id; 439853e2bd2SBhanu Gollapudi disable_req.vlan_tag = hba->vlan_id << 440853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT; 441853e2bd2SBhanu Gollapudi disable_req.vlan_tag |= 442853e2bd2SBhanu Gollapudi 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT; 443853e2bd2SBhanu Gollapudi disable_req.vlan_flag = hba->vlan_enabled; 444853e2bd2SBhanu Gollapudi 445853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &disable_req; 446853e2bd2SBhanu Gollapudi 447853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 448853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 449853e2bd2SBhanu Gollapudi 450853e2bd2SBhanu Gollapudi return rc; 451853e2bd2SBhanu Gollapudi } 452853e2bd2SBhanu Gollapudi 453853e2bd2SBhanu Gollapudi /** 454853e2bd2SBhanu Gollapudi * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy 455853e2bd2SBhanu Gollapudi * 456853e2bd2SBhanu Gollapudi * @port: port structure pointer 457853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer 458853e2bd2SBhanu Gollapudi */ 459853e2bd2SBhanu Gollapudi int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba, 460853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt) 461853e2bd2SBhanu Gollapudi { 462853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_destroy destroy_req; 463853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2]; 464853e2bd2SBhanu Gollapudi int num_kwqes = 1; 465853e2bd2SBhanu Gollapudi int rc = 0; 466853e2bd2SBhanu Gollapudi 467853e2bd2SBhanu Gollapudi memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy)); 468853e2bd2SBhanu Gollapudi destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN; 469853e2bd2SBhanu Gollapudi destroy_req.hdr.flags = 470853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 471853e2bd2SBhanu Gollapudi 472853e2bd2SBhanu Gollapudi destroy_req.context_id = tgt->context_id; 473853e2bd2SBhanu Gollapudi destroy_req.conn_id = tgt->fcoe_conn_id; 474853e2bd2SBhanu Gollapudi 475853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &destroy_req; 476853e2bd2SBhanu Gollapudi 477853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes) 478853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes); 479853e2bd2SBhanu Gollapudi 480853e2bd2SBhanu Gollapudi return rc; 481853e2bd2SBhanu Gollapudi } 482853e2bd2SBhanu Gollapudi 483853e2bd2SBhanu Gollapudi static void bnx2fc_unsol_els_work(struct work_struct *work) 484853e2bd2SBhanu Gollapudi { 485853e2bd2SBhanu Gollapudi struct bnx2fc_unsol_els *unsol_els; 486853e2bd2SBhanu Gollapudi struct fc_lport *lport; 487853e2bd2SBhanu Gollapudi struct fc_frame *fp; 488853e2bd2SBhanu Gollapudi 489853e2bd2SBhanu Gollapudi unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work); 490853e2bd2SBhanu Gollapudi lport = unsol_els->lport; 491853e2bd2SBhanu Gollapudi fp = unsol_els->fp; 492853e2bd2SBhanu Gollapudi fc_exch_recv(lport, fp); 493853e2bd2SBhanu Gollapudi kfree(unsol_els); 494853e2bd2SBhanu Gollapudi } 495853e2bd2SBhanu Gollapudi 496853e2bd2SBhanu Gollapudi void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt, 497853e2bd2SBhanu Gollapudi unsigned char *buf, 498853e2bd2SBhanu Gollapudi u32 frame_len, u16 l2_oxid) 499853e2bd2SBhanu Gollapudi { 500853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port; 501853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport; 502853e2bd2SBhanu Gollapudi struct bnx2fc_unsol_els *unsol_els; 503853e2bd2SBhanu Gollapudi struct fc_frame_header *fh; 504853e2bd2SBhanu Gollapudi struct fc_frame *fp; 505853e2bd2SBhanu Gollapudi struct sk_buff *skb; 506853e2bd2SBhanu Gollapudi u32 payload_len; 507853e2bd2SBhanu Gollapudi u32 crc; 508853e2bd2SBhanu Gollapudi u8 op; 509853e2bd2SBhanu Gollapudi 510853e2bd2SBhanu Gollapudi 511853e2bd2SBhanu Gollapudi unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC); 512853e2bd2SBhanu Gollapudi if (!unsol_els) { 513853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n"); 514853e2bd2SBhanu Gollapudi return; 515853e2bd2SBhanu Gollapudi } 516853e2bd2SBhanu Gollapudi 517853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n", 518853e2bd2SBhanu Gollapudi l2_oxid, frame_len); 519853e2bd2SBhanu Gollapudi 520853e2bd2SBhanu Gollapudi payload_len = frame_len - sizeof(struct fc_frame_header); 521853e2bd2SBhanu Gollapudi 522853e2bd2SBhanu Gollapudi fp = fc_frame_alloc(lport, payload_len); 523853e2bd2SBhanu Gollapudi if (!fp) { 524853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "fc_frame_alloc failure\n"); 525853e2bd2SBhanu Gollapudi return; 526853e2bd2SBhanu Gollapudi } 527853e2bd2SBhanu Gollapudi 528853e2bd2SBhanu Gollapudi fh = (struct fc_frame_header *) fc_frame_header_get(fp); 529853e2bd2SBhanu Gollapudi /* Copy FC Frame header and payload into the frame */ 530853e2bd2SBhanu Gollapudi memcpy(fh, buf, frame_len); 531853e2bd2SBhanu Gollapudi 532853e2bd2SBhanu Gollapudi if (l2_oxid != FC_XID_UNKNOWN) 533853e2bd2SBhanu Gollapudi fh->fh_ox_id = htons(l2_oxid); 534853e2bd2SBhanu Gollapudi 535853e2bd2SBhanu Gollapudi skb = fp_skb(fp); 536853e2bd2SBhanu Gollapudi 537853e2bd2SBhanu Gollapudi if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) || 538853e2bd2SBhanu Gollapudi (fh->fh_r_ctl == FC_RCTL_ELS_REP)) { 539853e2bd2SBhanu Gollapudi 540853e2bd2SBhanu Gollapudi if (fh->fh_type == FC_TYPE_ELS) { 541853e2bd2SBhanu Gollapudi op = fc_frame_payload_op(fp); 542853e2bd2SBhanu Gollapudi if ((op == ELS_TEST) || (op == ELS_ESTC) || 543853e2bd2SBhanu Gollapudi (op == ELS_FAN) || (op == ELS_CSU)) { 544853e2bd2SBhanu Gollapudi /* 545853e2bd2SBhanu Gollapudi * No need to reply for these 546853e2bd2SBhanu Gollapudi * ELS requests 547853e2bd2SBhanu Gollapudi */ 548853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "dropping ELS 0x%x\n", op); 549853e2bd2SBhanu Gollapudi kfree_skb(skb); 550853e2bd2SBhanu Gollapudi return; 551853e2bd2SBhanu Gollapudi } 552853e2bd2SBhanu Gollapudi } 553853e2bd2SBhanu Gollapudi crc = fcoe_fc_crc(fp); 554853e2bd2SBhanu Gollapudi fc_frame_init(fp); 555853e2bd2SBhanu Gollapudi fr_dev(fp) = lport; 556853e2bd2SBhanu Gollapudi fr_sof(fp) = FC_SOF_I3; 557853e2bd2SBhanu Gollapudi fr_eof(fp) = FC_EOF_T; 558853e2bd2SBhanu Gollapudi fr_crc(fp) = cpu_to_le32(~crc); 559853e2bd2SBhanu Gollapudi unsol_els->lport = lport; 560853e2bd2SBhanu Gollapudi unsol_els->fp = fp; 561853e2bd2SBhanu Gollapudi INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work); 562853e2bd2SBhanu Gollapudi queue_work(bnx2fc_wq, &unsol_els->unsol_els_work); 563853e2bd2SBhanu Gollapudi } else { 564853e2bd2SBhanu Gollapudi BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl); 565853e2bd2SBhanu Gollapudi kfree_skb(skb); 566853e2bd2SBhanu Gollapudi } 567853e2bd2SBhanu Gollapudi } 568853e2bd2SBhanu Gollapudi 569853e2bd2SBhanu Gollapudi static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe) 570853e2bd2SBhanu Gollapudi { 571853e2bd2SBhanu Gollapudi u8 num_rq; 572853e2bd2SBhanu Gollapudi struct fcoe_err_report_entry *err_entry; 573853e2bd2SBhanu Gollapudi unsigned char *rq_data; 574853e2bd2SBhanu Gollapudi unsigned char *buf = NULL, *buf1; 575853e2bd2SBhanu Gollapudi int i; 576853e2bd2SBhanu Gollapudi u16 xid; 577853e2bd2SBhanu Gollapudi u32 frame_len, len; 578853e2bd2SBhanu Gollapudi struct bnx2fc_cmd *io_req = NULL; 579853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task, *task_page; 580853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = tgt->port->priv; 581853e2bd2SBhanu Gollapudi int task_idx, index; 582853e2bd2SBhanu Gollapudi int rc = 0; 583853e2bd2SBhanu Gollapudi 584853e2bd2SBhanu Gollapudi 585853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe); 586853e2bd2SBhanu Gollapudi switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) { 587853e2bd2SBhanu Gollapudi case FCOE_UNSOLICITED_FRAME_CQE_TYPE: 588853e2bd2SBhanu Gollapudi frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >> 589853e2bd2SBhanu Gollapudi FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT; 590853e2bd2SBhanu Gollapudi 591853e2bd2SBhanu Gollapudi num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ; 592853e2bd2SBhanu Gollapudi 59368695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 594853e2bd2SBhanu Gollapudi rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq); 59568695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 59668695973SNithin Sujir 597853e2bd2SBhanu Gollapudi if (rq_data) { 598853e2bd2SBhanu Gollapudi buf = rq_data; 599853e2bd2SBhanu Gollapudi } else { 600853e2bd2SBhanu Gollapudi buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ), 601853e2bd2SBhanu Gollapudi GFP_ATOMIC); 602853e2bd2SBhanu Gollapudi 603853e2bd2SBhanu Gollapudi if (!buf1) { 604853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n"); 605853e2bd2SBhanu Gollapudi break; 606853e2bd2SBhanu Gollapudi } 607853e2bd2SBhanu Gollapudi 608853e2bd2SBhanu Gollapudi for (i = 0; i < num_rq; i++) { 60968695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 610853e2bd2SBhanu Gollapudi rq_data = (unsigned char *) 611853e2bd2SBhanu Gollapudi bnx2fc_get_next_rqe(tgt, 1); 61268695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 613853e2bd2SBhanu Gollapudi len = BNX2FC_RQ_BUF_SZ; 614853e2bd2SBhanu Gollapudi memcpy(buf1, rq_data, len); 615853e2bd2SBhanu Gollapudi buf1 += len; 616853e2bd2SBhanu Gollapudi } 617853e2bd2SBhanu Gollapudi } 618853e2bd2SBhanu Gollapudi bnx2fc_process_l2_frame_compl(tgt, buf, frame_len, 619853e2bd2SBhanu Gollapudi FC_XID_UNKNOWN); 620853e2bd2SBhanu Gollapudi 621853e2bd2SBhanu Gollapudi if (buf != rq_data) 622853e2bd2SBhanu Gollapudi kfree(buf); 62368695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 624853e2bd2SBhanu Gollapudi bnx2fc_return_rqe(tgt, num_rq); 62568695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 626853e2bd2SBhanu Gollapudi break; 627853e2bd2SBhanu Gollapudi 628853e2bd2SBhanu Gollapudi case FCOE_ERROR_DETECTION_CQE_TYPE: 629853e2bd2SBhanu Gollapudi /* 630853e2bd2SBhanu Gollapudi * In case of error reporting CQE a single RQ entry 63168695973SNithin Sujir * is consumed. 632853e2bd2SBhanu Gollapudi */ 633853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->tgt_lock); 634853e2bd2SBhanu Gollapudi num_rq = 1; 635853e2bd2SBhanu Gollapudi err_entry = (struct fcoe_err_report_entry *) 636853e2bd2SBhanu Gollapudi bnx2fc_get_next_rqe(tgt, 1); 637853e2bd2SBhanu Gollapudi xid = err_entry->fc_hdr.ox_id; 638853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid); 639853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n", 640853e2bd2SBhanu Gollapudi err_entry->err_warn_bitmap_hi, 641853e2bd2SBhanu Gollapudi err_entry->err_warn_bitmap_lo); 642853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n", 643853e2bd2SBhanu Gollapudi err_entry->tx_buf_off, err_entry->rx_buf_off); 644853e2bd2SBhanu Gollapudi 645853e2bd2SBhanu Gollapudi bnx2fc_return_rqe(tgt, 1); 646853e2bd2SBhanu Gollapudi 647853e2bd2SBhanu Gollapudi if (xid > BNX2FC_MAX_XID) { 648853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", 649853e2bd2SBhanu Gollapudi xid); 650853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 651853e2bd2SBhanu Gollapudi break; 652853e2bd2SBhanu Gollapudi } 653853e2bd2SBhanu Gollapudi 654853e2bd2SBhanu Gollapudi task_idx = xid / BNX2FC_TASKS_PER_PAGE; 655853e2bd2SBhanu Gollapudi index = xid % BNX2FC_TASKS_PER_PAGE; 656853e2bd2SBhanu Gollapudi task_page = (struct fcoe_task_ctx_entry *) 657853e2bd2SBhanu Gollapudi hba->task_ctx[task_idx]; 658853e2bd2SBhanu Gollapudi task = &(task_page[index]); 659853e2bd2SBhanu Gollapudi 660853e2bd2SBhanu Gollapudi io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid]; 661853e2bd2SBhanu Gollapudi if (!io_req) { 662853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 663853e2bd2SBhanu Gollapudi break; 664853e2bd2SBhanu Gollapudi } 665853e2bd2SBhanu Gollapudi 666853e2bd2SBhanu Gollapudi if (io_req->cmd_type != BNX2FC_SCSI_CMD) { 667853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n"); 668853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 669853e2bd2SBhanu Gollapudi break; 670853e2bd2SBhanu Gollapudi } 671853e2bd2SBhanu Gollapudi 672853e2bd2SBhanu Gollapudi if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP, 673853e2bd2SBhanu Gollapudi &io_req->req_flags)) { 674853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in " 675853e2bd2SBhanu Gollapudi "progress.. ignore unsol err\n"); 676853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 677853e2bd2SBhanu Gollapudi break; 678853e2bd2SBhanu Gollapudi } 679853e2bd2SBhanu Gollapudi 680853e2bd2SBhanu Gollapudi /* 681853e2bd2SBhanu Gollapudi * If ABTS is already in progress, and FW error is 682853e2bd2SBhanu Gollapudi * received after that, do not cancel the timeout_work 683853e2bd2SBhanu Gollapudi * and let the error recovery continue by explicitly 684853e2bd2SBhanu Gollapudi * logging out the target, when the ABTS eventually 685853e2bd2SBhanu Gollapudi * times out. 686853e2bd2SBhanu Gollapudi */ 687853e2bd2SBhanu Gollapudi if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS, 688853e2bd2SBhanu Gollapudi &io_req->req_flags)) { 689853e2bd2SBhanu Gollapudi /* 690853e2bd2SBhanu Gollapudi * Cancel the timeout_work, as we received IO 691853e2bd2SBhanu Gollapudi * completion with FW error. 692853e2bd2SBhanu Gollapudi */ 693853e2bd2SBhanu Gollapudi if (cancel_delayed_work(&io_req->timeout_work)) 694853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, 695853e2bd2SBhanu Gollapudi bnx2fc_cmd_release); /* timer hold */ 696853e2bd2SBhanu Gollapudi 697853e2bd2SBhanu Gollapudi rc = bnx2fc_initiate_abts(io_req); 698853e2bd2SBhanu Gollapudi if (rc != SUCCESS) { 699853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "err_warn: initiate_abts " 700853e2bd2SBhanu Gollapudi "failed. issue cleanup\n"); 701853e2bd2SBhanu Gollapudi rc = bnx2fc_initiate_cleanup(io_req); 702853e2bd2SBhanu Gollapudi BUG_ON(rc); 703853e2bd2SBhanu Gollapudi } 704853e2bd2SBhanu Gollapudi } else 705853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "err_warn: io_req (0x%x) already " 706853e2bd2SBhanu Gollapudi "in ABTS processing\n", xid); 707853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 708853e2bd2SBhanu Gollapudi break; 709853e2bd2SBhanu Gollapudi 710853e2bd2SBhanu Gollapudi case FCOE_WARNING_DETECTION_CQE_TYPE: 711853e2bd2SBhanu Gollapudi /* 712853e2bd2SBhanu Gollapudi *In case of warning reporting CQE a single RQ entry 713853e2bd2SBhanu Gollapudi * is consumes. 714853e2bd2SBhanu Gollapudi */ 71568695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock); 716853e2bd2SBhanu Gollapudi num_rq = 1; 717853e2bd2SBhanu Gollapudi err_entry = (struct fcoe_err_report_entry *) 718853e2bd2SBhanu Gollapudi bnx2fc_get_next_rqe(tgt, 1); 719853e2bd2SBhanu Gollapudi xid = cpu_to_be16(err_entry->fc_hdr.ox_id); 720853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid); 721853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x", 722853e2bd2SBhanu Gollapudi err_entry->err_warn_bitmap_hi, 723853e2bd2SBhanu Gollapudi err_entry->err_warn_bitmap_lo); 724853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x", 725853e2bd2SBhanu Gollapudi err_entry->tx_buf_off, err_entry->rx_buf_off); 726853e2bd2SBhanu Gollapudi 727853e2bd2SBhanu Gollapudi bnx2fc_return_rqe(tgt, 1); 72868695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock); 729853e2bd2SBhanu Gollapudi break; 730853e2bd2SBhanu Gollapudi 731853e2bd2SBhanu Gollapudi default: 732853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n"); 733853e2bd2SBhanu Gollapudi break; 734853e2bd2SBhanu Gollapudi } 735853e2bd2SBhanu Gollapudi } 736853e2bd2SBhanu Gollapudi 737853e2bd2SBhanu Gollapudi void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe) 738853e2bd2SBhanu Gollapudi { 739853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task; 740853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task_page; 741853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port; 742853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = port->priv; 743853e2bd2SBhanu Gollapudi struct bnx2fc_cmd *io_req; 744853e2bd2SBhanu Gollapudi int task_idx, index; 745853e2bd2SBhanu Gollapudi u16 xid; 746853e2bd2SBhanu Gollapudi u8 cmd_type; 747853e2bd2SBhanu Gollapudi u8 rx_state = 0; 748853e2bd2SBhanu Gollapudi u8 num_rq; 749853e2bd2SBhanu Gollapudi 750853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->tgt_lock); 751853e2bd2SBhanu Gollapudi xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID; 752853e2bd2SBhanu Gollapudi if (xid >= BNX2FC_MAX_TASKS) { 753853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "ERROR:xid out of range\n"); 754853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 755853e2bd2SBhanu Gollapudi return; 756853e2bd2SBhanu Gollapudi } 757853e2bd2SBhanu Gollapudi task_idx = xid / BNX2FC_TASKS_PER_PAGE; 758853e2bd2SBhanu Gollapudi index = xid % BNX2FC_TASKS_PER_PAGE; 759853e2bd2SBhanu Gollapudi task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx]; 760853e2bd2SBhanu Gollapudi task = &(task_page[index]); 761853e2bd2SBhanu Gollapudi 762853e2bd2SBhanu Gollapudi num_rq = ((task->rx_wr_tx_rd.rx_flags & 763853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE) >> 764853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE_SHIFT); 765853e2bd2SBhanu Gollapudi 766853e2bd2SBhanu Gollapudi io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid]; 767853e2bd2SBhanu Gollapudi 768853e2bd2SBhanu Gollapudi if (io_req == NULL) { 769853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n"); 770853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 771853e2bd2SBhanu Gollapudi return; 772853e2bd2SBhanu Gollapudi } 773853e2bd2SBhanu Gollapudi 774853e2bd2SBhanu Gollapudi /* Timestamp IO completion time */ 775853e2bd2SBhanu Gollapudi cmd_type = io_req->cmd_type; 776853e2bd2SBhanu Gollapudi 777853e2bd2SBhanu Gollapudi /* optimized completion path */ 778853e2bd2SBhanu Gollapudi if (cmd_type == BNX2FC_SCSI_CMD) { 779853e2bd2SBhanu Gollapudi rx_state = ((task->rx_wr_tx_rd.rx_flags & 780853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE) >> 781853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE_SHIFT); 782853e2bd2SBhanu Gollapudi 783853e2bd2SBhanu Gollapudi if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) { 784853e2bd2SBhanu Gollapudi bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq); 785853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 786853e2bd2SBhanu Gollapudi return; 787853e2bd2SBhanu Gollapudi } 788853e2bd2SBhanu Gollapudi } 789853e2bd2SBhanu Gollapudi 790853e2bd2SBhanu Gollapudi /* Process other IO completion types */ 791853e2bd2SBhanu Gollapudi switch (cmd_type) { 792853e2bd2SBhanu Gollapudi case BNX2FC_SCSI_CMD: 793853e2bd2SBhanu Gollapudi if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED) 794853e2bd2SBhanu Gollapudi bnx2fc_process_abts_compl(io_req, task, num_rq); 795853e2bd2SBhanu Gollapudi else if (rx_state == 796853e2bd2SBhanu Gollapudi FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED) 797853e2bd2SBhanu Gollapudi bnx2fc_process_cleanup_compl(io_req, task, num_rq); 798853e2bd2SBhanu Gollapudi else 799853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Invalid rx state - %d\n", 800853e2bd2SBhanu Gollapudi rx_state); 801853e2bd2SBhanu Gollapudi break; 802853e2bd2SBhanu Gollapudi 803853e2bd2SBhanu Gollapudi case BNX2FC_TASK_MGMT_CMD: 804853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "Processing TM complete\n"); 805853e2bd2SBhanu Gollapudi bnx2fc_process_tm_compl(io_req, task, num_rq); 806853e2bd2SBhanu Gollapudi break; 807853e2bd2SBhanu Gollapudi 808853e2bd2SBhanu Gollapudi case BNX2FC_ABTS: 809853e2bd2SBhanu Gollapudi /* 810853e2bd2SBhanu Gollapudi * ABTS request received by firmware. ABTS response 811853e2bd2SBhanu Gollapudi * will be delivered to the task belonging to the IO 812853e2bd2SBhanu Gollapudi * that was aborted 813853e2bd2SBhanu Gollapudi */ 814853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n"); 815853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release); 816853e2bd2SBhanu Gollapudi break; 817853e2bd2SBhanu Gollapudi 818853e2bd2SBhanu Gollapudi case BNX2FC_ELS: 819853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl - call process_els_compl\n"); 820853e2bd2SBhanu Gollapudi bnx2fc_process_els_compl(io_req, task, num_rq); 821853e2bd2SBhanu Gollapudi break; 822853e2bd2SBhanu Gollapudi 823853e2bd2SBhanu Gollapudi case BNX2FC_CLEANUP: 824853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n"); 825853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release); 826853e2bd2SBhanu Gollapudi break; 827853e2bd2SBhanu Gollapudi 828853e2bd2SBhanu Gollapudi default: 829853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type); 830853e2bd2SBhanu Gollapudi break; 831853e2bd2SBhanu Gollapudi } 832853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock); 833853e2bd2SBhanu Gollapudi } 834853e2bd2SBhanu Gollapudi 835853e2bd2SBhanu Gollapudi struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe) 836853e2bd2SBhanu Gollapudi { 837853e2bd2SBhanu Gollapudi struct bnx2fc_work *work; 838853e2bd2SBhanu Gollapudi work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC); 839853e2bd2SBhanu Gollapudi if (!work) 840853e2bd2SBhanu Gollapudi return NULL; 841853e2bd2SBhanu Gollapudi 842853e2bd2SBhanu Gollapudi INIT_LIST_HEAD(&work->list); 843853e2bd2SBhanu Gollapudi work->tgt = tgt; 844853e2bd2SBhanu Gollapudi work->wqe = wqe; 845853e2bd2SBhanu Gollapudi return work; 846853e2bd2SBhanu Gollapudi } 847853e2bd2SBhanu Gollapudi 848853e2bd2SBhanu Gollapudi int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt) 849853e2bd2SBhanu Gollapudi { 850853e2bd2SBhanu Gollapudi struct fcoe_cqe *cq; 851853e2bd2SBhanu Gollapudi u32 cq_cons; 852853e2bd2SBhanu Gollapudi struct fcoe_cqe *cqe; 853853e2bd2SBhanu Gollapudi u16 wqe; 854853e2bd2SBhanu Gollapudi bool more_cqes_found = false; 855853e2bd2SBhanu Gollapudi 856853e2bd2SBhanu Gollapudi /* 857853e2bd2SBhanu Gollapudi * cq_lock is a low contention lock used to protect 858853e2bd2SBhanu Gollapudi * the CQ data structure from being freed up during 859853e2bd2SBhanu Gollapudi * the upload operation 860853e2bd2SBhanu Gollapudi */ 861853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->cq_lock); 862853e2bd2SBhanu Gollapudi 863853e2bd2SBhanu Gollapudi if (!tgt->cq) { 864853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n"); 865853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->cq_lock); 866853e2bd2SBhanu Gollapudi return 0; 867853e2bd2SBhanu Gollapudi } 868853e2bd2SBhanu Gollapudi cq = tgt->cq; 869853e2bd2SBhanu Gollapudi cq_cons = tgt->cq_cons_idx; 870853e2bd2SBhanu Gollapudi cqe = &cq[cq_cons]; 871853e2bd2SBhanu Gollapudi 872853e2bd2SBhanu Gollapudi do { 873853e2bd2SBhanu Gollapudi more_cqes_found ^= true; 874853e2bd2SBhanu Gollapudi 875853e2bd2SBhanu Gollapudi while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) == 876853e2bd2SBhanu Gollapudi (tgt->cq_curr_toggle_bit << 877853e2bd2SBhanu Gollapudi FCOE_CQE_TOGGLE_BIT_SHIFT)) { 878853e2bd2SBhanu Gollapudi 879853e2bd2SBhanu Gollapudi /* new entry on the cq */ 880853e2bd2SBhanu Gollapudi if (wqe & FCOE_CQE_CQE_TYPE) { 881853e2bd2SBhanu Gollapudi /* Unsolicited event notification */ 882853e2bd2SBhanu Gollapudi bnx2fc_process_unsol_compl(tgt, wqe); 883853e2bd2SBhanu Gollapudi } else { 884853e2bd2SBhanu Gollapudi struct bnx2fc_work *work = NULL; 885853e2bd2SBhanu Gollapudi struct bnx2fc_percpu_s *fps = NULL; 886853e2bd2SBhanu Gollapudi unsigned int cpu = wqe % num_possible_cpus(); 887853e2bd2SBhanu Gollapudi 888853e2bd2SBhanu Gollapudi fps = &per_cpu(bnx2fc_percpu, cpu); 889853e2bd2SBhanu Gollapudi spin_lock_bh(&fps->fp_work_lock); 890853e2bd2SBhanu Gollapudi if (unlikely(!fps->iothread)) 891853e2bd2SBhanu Gollapudi goto unlock; 892853e2bd2SBhanu Gollapudi 893853e2bd2SBhanu Gollapudi work = bnx2fc_alloc_work(tgt, wqe); 894853e2bd2SBhanu Gollapudi if (work) 895853e2bd2SBhanu Gollapudi list_add_tail(&work->list, 896853e2bd2SBhanu Gollapudi &fps->work_list); 897853e2bd2SBhanu Gollapudi unlock: 898853e2bd2SBhanu Gollapudi spin_unlock_bh(&fps->fp_work_lock); 899853e2bd2SBhanu Gollapudi 900853e2bd2SBhanu Gollapudi /* Pending work request completion */ 901853e2bd2SBhanu Gollapudi if (fps->iothread && work) 902853e2bd2SBhanu Gollapudi wake_up_process(fps->iothread); 903853e2bd2SBhanu Gollapudi else 904853e2bd2SBhanu Gollapudi bnx2fc_process_cq_compl(tgt, wqe); 905853e2bd2SBhanu Gollapudi } 906853e2bd2SBhanu Gollapudi cqe++; 907853e2bd2SBhanu Gollapudi tgt->cq_cons_idx++; 908853e2bd2SBhanu Gollapudi 909853e2bd2SBhanu Gollapudi if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) { 910853e2bd2SBhanu Gollapudi tgt->cq_cons_idx = 0; 911853e2bd2SBhanu Gollapudi cqe = cq; 912853e2bd2SBhanu Gollapudi tgt->cq_curr_toggle_bit = 913853e2bd2SBhanu Gollapudi 1 - tgt->cq_curr_toggle_bit; 914853e2bd2SBhanu Gollapudi } 915853e2bd2SBhanu Gollapudi } 916853e2bd2SBhanu Gollapudi /* Re-arm CQ */ 917853e2bd2SBhanu Gollapudi if (more_cqes_found) { 918853e2bd2SBhanu Gollapudi tgt->conn_db->cq_arm.lo = -1; 919853e2bd2SBhanu Gollapudi wmb(); 920853e2bd2SBhanu Gollapudi } 921853e2bd2SBhanu Gollapudi } while (more_cqes_found); 922853e2bd2SBhanu Gollapudi 923853e2bd2SBhanu Gollapudi /* 924853e2bd2SBhanu Gollapudi * Commit tgt->cq_cons_idx change to the memory 925853e2bd2SBhanu Gollapudi * spin_lock implies full memory barrier, no need to smp_wmb 926853e2bd2SBhanu Gollapudi */ 927853e2bd2SBhanu Gollapudi 928853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->cq_lock); 929853e2bd2SBhanu Gollapudi return 0; 930853e2bd2SBhanu Gollapudi } 931853e2bd2SBhanu Gollapudi 932853e2bd2SBhanu Gollapudi /** 933853e2bd2SBhanu Gollapudi * bnx2fc_fastpath_notification - process global event queue (KCQ) 934853e2bd2SBhanu Gollapudi * 935853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 936853e2bd2SBhanu Gollapudi * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry 937853e2bd2SBhanu Gollapudi * 938853e2bd2SBhanu Gollapudi * Fast path event notification handler 939853e2bd2SBhanu Gollapudi */ 940853e2bd2SBhanu Gollapudi static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba, 941853e2bd2SBhanu Gollapudi struct fcoe_kcqe *new_cqe_kcqe) 942853e2bd2SBhanu Gollapudi { 943853e2bd2SBhanu Gollapudi u32 conn_id = new_cqe_kcqe->fcoe_conn_id; 944853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id]; 945853e2bd2SBhanu Gollapudi 946853e2bd2SBhanu Gollapudi if (!tgt) { 947853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "conn_id 0x%x not valid\n", conn_id); 948853e2bd2SBhanu Gollapudi return; 949853e2bd2SBhanu Gollapudi } 950853e2bd2SBhanu Gollapudi 951853e2bd2SBhanu Gollapudi bnx2fc_process_new_cqes(tgt); 952853e2bd2SBhanu Gollapudi } 953853e2bd2SBhanu Gollapudi 954853e2bd2SBhanu Gollapudi /** 955853e2bd2SBhanu Gollapudi * bnx2fc_process_ofld_cmpl - process FCoE session offload completion 956853e2bd2SBhanu Gollapudi * 957853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 958853e2bd2SBhanu Gollapudi * @ofld_kcqe: connection offload kcqe pointer 959853e2bd2SBhanu Gollapudi * 960853e2bd2SBhanu Gollapudi * handle session offload completion, enable the session if offload is 961853e2bd2SBhanu Gollapudi * successful. 962853e2bd2SBhanu Gollapudi */ 963853e2bd2SBhanu Gollapudi static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba, 964853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe) 965853e2bd2SBhanu Gollapudi { 966853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 967853e2bd2SBhanu Gollapudi struct fcoe_port *port; 968853e2bd2SBhanu Gollapudi u32 conn_id; 969853e2bd2SBhanu Gollapudi u32 context_id; 970853e2bd2SBhanu Gollapudi int rc; 971853e2bd2SBhanu Gollapudi 972853e2bd2SBhanu Gollapudi conn_id = ofld_kcqe->fcoe_conn_id; 973853e2bd2SBhanu Gollapudi context_id = ofld_kcqe->fcoe_conn_context_id; 974853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 975853e2bd2SBhanu Gollapudi if (!tgt) { 976853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n"); 977853e2bd2SBhanu Gollapudi return; 978853e2bd2SBhanu Gollapudi } 979853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n", 980853e2bd2SBhanu Gollapudi ofld_kcqe->fcoe_conn_context_id); 981853e2bd2SBhanu Gollapudi port = tgt->port; 982853e2bd2SBhanu Gollapudi if (hba != tgt->port->priv) { 983853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "ERROR:ofld_cmpl: HBA mis-match\n"); 984853e2bd2SBhanu Gollapudi goto ofld_cmpl_err; 985853e2bd2SBhanu Gollapudi } 986853e2bd2SBhanu Gollapudi /* 987853e2bd2SBhanu Gollapudi * cnic has allocated a context_id for this session; use this 988853e2bd2SBhanu Gollapudi * while enabling the session. 989853e2bd2SBhanu Gollapudi */ 990853e2bd2SBhanu Gollapudi tgt->context_id = context_id; 991853e2bd2SBhanu Gollapudi if (ofld_kcqe->completion_status) { 992853e2bd2SBhanu Gollapudi if (ofld_kcqe->completion_status == 993853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) { 994853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate FCoE context " 995853e2bd2SBhanu Gollapudi "resources\n"); 996853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags); 997853e2bd2SBhanu Gollapudi } 998853e2bd2SBhanu Gollapudi goto ofld_cmpl_err; 999853e2bd2SBhanu Gollapudi } else { 1000853e2bd2SBhanu Gollapudi 1001853e2bd2SBhanu Gollapudi /* now enable the session */ 1002853e2bd2SBhanu Gollapudi rc = bnx2fc_send_session_enable_req(port, tgt); 1003853e2bd2SBhanu Gollapudi if (rc) { 1004853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "enable session failed\n"); 1005853e2bd2SBhanu Gollapudi goto ofld_cmpl_err; 1006853e2bd2SBhanu Gollapudi } 1007853e2bd2SBhanu Gollapudi } 1008853e2bd2SBhanu Gollapudi return; 1009853e2bd2SBhanu Gollapudi ofld_cmpl_err: 1010853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags); 1011853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait); 1012853e2bd2SBhanu Gollapudi } 1013853e2bd2SBhanu Gollapudi 1014853e2bd2SBhanu Gollapudi /** 1015853e2bd2SBhanu Gollapudi * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion 1016853e2bd2SBhanu Gollapudi * 1017853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 1018853e2bd2SBhanu Gollapudi * @ofld_kcqe: connection offload kcqe pointer 1019853e2bd2SBhanu Gollapudi * 1020853e2bd2SBhanu Gollapudi * handle session enable completion, mark the rport as ready 1021853e2bd2SBhanu Gollapudi */ 1022853e2bd2SBhanu Gollapudi 1023853e2bd2SBhanu Gollapudi static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba, 1024853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe) 1025853e2bd2SBhanu Gollapudi { 1026853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 1027853e2bd2SBhanu Gollapudi u32 conn_id; 1028853e2bd2SBhanu Gollapudi u32 context_id; 1029853e2bd2SBhanu Gollapudi 1030853e2bd2SBhanu Gollapudi context_id = ofld_kcqe->fcoe_conn_context_id; 1031853e2bd2SBhanu Gollapudi conn_id = ofld_kcqe->fcoe_conn_id; 1032853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 1033853e2bd2SBhanu Gollapudi if (!tgt) { 1034853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "ERROR:enbl_cmpl: No pending ofld req\n"); 1035853e2bd2SBhanu Gollapudi return; 1036853e2bd2SBhanu Gollapudi } 1037853e2bd2SBhanu Gollapudi 1038853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n", 1039853e2bd2SBhanu Gollapudi ofld_kcqe->fcoe_conn_context_id); 1040853e2bd2SBhanu Gollapudi 1041853e2bd2SBhanu Gollapudi /* 1042853e2bd2SBhanu Gollapudi * context_id should be the same for this target during offload 1043853e2bd2SBhanu Gollapudi * and enable 1044853e2bd2SBhanu Gollapudi */ 1045853e2bd2SBhanu Gollapudi if (tgt->context_id != context_id) { 1046853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "context id mis-match\n"); 1047853e2bd2SBhanu Gollapudi return; 1048853e2bd2SBhanu Gollapudi } 1049853e2bd2SBhanu Gollapudi if (hba != tgt->port->priv) { 1050853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "bnx2fc-enbl_cmpl: HBA mis-match\n"); 1051853e2bd2SBhanu Gollapudi goto enbl_cmpl_err; 1052853e2bd2SBhanu Gollapudi } 1053853e2bd2SBhanu Gollapudi if (ofld_kcqe->completion_status) { 1054853e2bd2SBhanu Gollapudi goto enbl_cmpl_err; 1055853e2bd2SBhanu Gollapudi } else { 1056853e2bd2SBhanu Gollapudi /* enable successful - rport ready for issuing IOs */ 1057853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags); 1058853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags); 1059853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait); 1060853e2bd2SBhanu Gollapudi } 1061853e2bd2SBhanu Gollapudi return; 1062853e2bd2SBhanu Gollapudi 1063853e2bd2SBhanu Gollapudi enbl_cmpl_err: 1064853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags); 1065853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait); 1066853e2bd2SBhanu Gollapudi } 1067853e2bd2SBhanu Gollapudi 1068853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba, 1069853e2bd2SBhanu Gollapudi struct fcoe_kcqe *disable_kcqe) 1070853e2bd2SBhanu Gollapudi { 1071853e2bd2SBhanu Gollapudi 1072853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 1073853e2bd2SBhanu Gollapudi u32 conn_id; 1074853e2bd2SBhanu Gollapudi 1075853e2bd2SBhanu Gollapudi conn_id = disable_kcqe->fcoe_conn_id; 1076853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 1077853e2bd2SBhanu Gollapudi if (!tgt) { 1078853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "ERROR: disable_cmpl: No disable req\n"); 1079853e2bd2SBhanu Gollapudi return; 1080853e2bd2SBhanu Gollapudi } 1081853e2bd2SBhanu Gollapudi 1082853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id); 1083853e2bd2SBhanu Gollapudi 1084853e2bd2SBhanu Gollapudi if (disable_kcqe->completion_status) { 1085853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "ERROR: Disable failed with cmpl status %d\n", 1086853e2bd2SBhanu Gollapudi disable_kcqe->completion_status); 1087853e2bd2SBhanu Gollapudi return; 1088853e2bd2SBhanu Gollapudi } else { 1089853e2bd2SBhanu Gollapudi /* disable successful */ 1090853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "disable successful\n"); 1091853e2bd2SBhanu Gollapudi clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags); 1092853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags); 1093853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags); 1094853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->upld_wait); 1095853e2bd2SBhanu Gollapudi } 1096853e2bd2SBhanu Gollapudi } 1097853e2bd2SBhanu Gollapudi 1098853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba, 1099853e2bd2SBhanu Gollapudi struct fcoe_kcqe *destroy_kcqe) 1100853e2bd2SBhanu Gollapudi { 1101853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt; 1102853e2bd2SBhanu Gollapudi u32 conn_id; 1103853e2bd2SBhanu Gollapudi 1104853e2bd2SBhanu Gollapudi conn_id = destroy_kcqe->fcoe_conn_id; 1105853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id]; 1106853e2bd2SBhanu Gollapudi if (!tgt) { 1107853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "destroy_cmpl: No destroy req\n"); 1108853e2bd2SBhanu Gollapudi return; 1109853e2bd2SBhanu Gollapudi } 1110853e2bd2SBhanu Gollapudi 1111853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id); 1112853e2bd2SBhanu Gollapudi 1113853e2bd2SBhanu Gollapudi if (destroy_kcqe->completion_status) { 1114853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "Destroy conn failed, cmpl status %d\n", 1115853e2bd2SBhanu Gollapudi destroy_kcqe->completion_status); 1116853e2bd2SBhanu Gollapudi return; 1117853e2bd2SBhanu Gollapudi } else { 1118853e2bd2SBhanu Gollapudi /* destroy successful */ 1119853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "upload successful\n"); 1120853e2bd2SBhanu Gollapudi clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags); 1121853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags); 1122853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags); 1123853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->upld_wait); 1124853e2bd2SBhanu Gollapudi } 1125853e2bd2SBhanu Gollapudi } 1126853e2bd2SBhanu Gollapudi 1127853e2bd2SBhanu Gollapudi static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code) 1128853e2bd2SBhanu Gollapudi { 1129853e2bd2SBhanu Gollapudi switch (err_code) { 1130853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE: 1131853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init_failure due to invalid opcode\n"); 1132853e2bd2SBhanu Gollapudi break; 1133853e2bd2SBhanu Gollapudi 1134853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE: 1135853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init failed due to ctx alloc failure\n"); 1136853e2bd2SBhanu Gollapudi break; 1137853e2bd2SBhanu Gollapudi 1138853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR: 1139853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init_failure due to NIC error\n"); 1140853e2bd2SBhanu Gollapudi break; 1141853e2bd2SBhanu Gollapudi 1142853e2bd2SBhanu Gollapudi default: 1143853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Unknown Error code %d\n", err_code); 1144853e2bd2SBhanu Gollapudi } 1145853e2bd2SBhanu Gollapudi } 1146853e2bd2SBhanu Gollapudi 1147853e2bd2SBhanu Gollapudi /** 1148853e2bd2SBhanu Gollapudi * bnx2fc_indicae_kcqe - process KCQE 1149853e2bd2SBhanu Gollapudi * 1150853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer 1151853e2bd2SBhanu Gollapudi * @kcqe: kcqe pointer 1152853e2bd2SBhanu Gollapudi * @num_cqe: Number of completion queue elements 1153853e2bd2SBhanu Gollapudi * 1154853e2bd2SBhanu Gollapudi * Generic KCQ event handler 1155853e2bd2SBhanu Gollapudi */ 1156853e2bd2SBhanu Gollapudi void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[], 1157853e2bd2SBhanu Gollapudi u32 num_cqe) 1158853e2bd2SBhanu Gollapudi { 1159853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context; 1160853e2bd2SBhanu Gollapudi int i = 0; 1161853e2bd2SBhanu Gollapudi struct fcoe_kcqe *kcqe = NULL; 1162853e2bd2SBhanu Gollapudi 1163853e2bd2SBhanu Gollapudi while (i < num_cqe) { 1164853e2bd2SBhanu Gollapudi kcqe = (struct fcoe_kcqe *) kcq[i++]; 1165853e2bd2SBhanu Gollapudi 1166853e2bd2SBhanu Gollapudi switch (kcqe->op_code) { 1167853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION: 1168853e2bd2SBhanu Gollapudi bnx2fc_fastpath_notification(hba, kcqe); 1169853e2bd2SBhanu Gollapudi break; 1170853e2bd2SBhanu Gollapudi 1171853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_OFFLOAD_CONN: 1172853e2bd2SBhanu Gollapudi bnx2fc_process_ofld_cmpl(hba, kcqe); 1173853e2bd2SBhanu Gollapudi break; 1174853e2bd2SBhanu Gollapudi 1175853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_ENABLE_CONN: 1176853e2bd2SBhanu Gollapudi bnx2fc_process_enable_conn_cmpl(hba, kcqe); 1177853e2bd2SBhanu Gollapudi break; 1178853e2bd2SBhanu Gollapudi 1179853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_INIT_FUNC: 1180853e2bd2SBhanu Gollapudi if (kcqe->completion_status != 1181853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) { 1182853e2bd2SBhanu Gollapudi bnx2fc_init_failure(hba, 1183853e2bd2SBhanu Gollapudi kcqe->completion_status); 1184853e2bd2SBhanu Gollapudi } else { 1185853e2bd2SBhanu Gollapudi set_bit(ADAPTER_STATE_UP, &hba->adapter_state); 1186853e2bd2SBhanu Gollapudi bnx2fc_get_link_state(hba); 1187853e2bd2SBhanu Gollapudi printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n", 1188853e2bd2SBhanu Gollapudi (u8)hba->pcidev->bus->number); 1189853e2bd2SBhanu Gollapudi } 1190853e2bd2SBhanu Gollapudi break; 1191853e2bd2SBhanu Gollapudi 1192853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DESTROY_FUNC: 1193853e2bd2SBhanu Gollapudi if (kcqe->completion_status != 1194853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) { 1195853e2bd2SBhanu Gollapudi 1196853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "DESTROY failed\n"); 1197853e2bd2SBhanu Gollapudi } else { 1198853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "DESTROY success\n"); 1199853e2bd2SBhanu Gollapudi } 1200853e2bd2SBhanu Gollapudi hba->flags |= BNX2FC_FLAG_DESTROY_CMPL; 1201853e2bd2SBhanu Gollapudi wake_up_interruptible(&hba->destroy_wait); 1202853e2bd2SBhanu Gollapudi break; 1203853e2bd2SBhanu Gollapudi 1204853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DISABLE_CONN: 1205853e2bd2SBhanu Gollapudi bnx2fc_process_conn_disable_cmpl(hba, kcqe); 1206853e2bd2SBhanu Gollapudi break; 1207853e2bd2SBhanu Gollapudi 1208853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DESTROY_CONN: 1209853e2bd2SBhanu Gollapudi bnx2fc_process_conn_destroy_cmpl(hba, kcqe); 1210853e2bd2SBhanu Gollapudi break; 1211853e2bd2SBhanu Gollapudi 1212853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_STAT_FUNC: 1213853e2bd2SBhanu Gollapudi if (kcqe->completion_status != 1214853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) 1215853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "STAT failed\n"); 1216853e2bd2SBhanu Gollapudi complete(&hba->stat_req_done); 1217853e2bd2SBhanu Gollapudi break; 1218853e2bd2SBhanu Gollapudi 1219853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_FCOE_ERROR: 1220853e2bd2SBhanu Gollapudi /* fall thru */ 1221853e2bd2SBhanu Gollapudi default: 1222853e2bd2SBhanu Gollapudi printk(KERN_ALERT PFX "unknown opcode 0x%x\n", 1223853e2bd2SBhanu Gollapudi kcqe->op_code); 1224853e2bd2SBhanu Gollapudi } 1225853e2bd2SBhanu Gollapudi } 1226853e2bd2SBhanu Gollapudi } 1227853e2bd2SBhanu Gollapudi 1228853e2bd2SBhanu Gollapudi void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid) 1229853e2bd2SBhanu Gollapudi { 1230853e2bd2SBhanu Gollapudi struct fcoe_sqe *sqe; 1231853e2bd2SBhanu Gollapudi 1232853e2bd2SBhanu Gollapudi sqe = &tgt->sq[tgt->sq_prod_idx]; 1233853e2bd2SBhanu Gollapudi 1234853e2bd2SBhanu Gollapudi /* Fill SQ WQE */ 1235853e2bd2SBhanu Gollapudi sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT; 1236853e2bd2SBhanu Gollapudi sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT; 1237853e2bd2SBhanu Gollapudi 1238853e2bd2SBhanu Gollapudi /* Advance SQ Prod Idx */ 1239853e2bd2SBhanu Gollapudi if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) { 1240853e2bd2SBhanu Gollapudi tgt->sq_prod_idx = 0; 1241853e2bd2SBhanu Gollapudi tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit; 1242853e2bd2SBhanu Gollapudi } 1243853e2bd2SBhanu Gollapudi } 1244853e2bd2SBhanu Gollapudi 1245853e2bd2SBhanu Gollapudi void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt) 1246853e2bd2SBhanu Gollapudi { 1247853e2bd2SBhanu Gollapudi struct b577xx_doorbell_set_prod ev_doorbell; 1248853e2bd2SBhanu Gollapudi u32 msg; 1249853e2bd2SBhanu Gollapudi 1250853e2bd2SBhanu Gollapudi wmb(); 1251853e2bd2SBhanu Gollapudi 1252853e2bd2SBhanu Gollapudi memset(&ev_doorbell, 0, sizeof(struct b577xx_doorbell_set_prod)); 1253853e2bd2SBhanu Gollapudi ev_doorbell.header.header = B577XX_DOORBELL_HDR_DB_TYPE; 1254853e2bd2SBhanu Gollapudi 1255853e2bd2SBhanu Gollapudi ev_doorbell.prod = tgt->sq_prod_idx | 1256853e2bd2SBhanu Gollapudi (tgt->sq_curr_toggle_bit << 15); 1257853e2bd2SBhanu Gollapudi ev_doorbell.header.header |= B577XX_FCOE_CONNECTION_TYPE << 1258853e2bd2SBhanu Gollapudi B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT; 1259853e2bd2SBhanu Gollapudi msg = *((u32 *)&ev_doorbell); 1260853e2bd2SBhanu Gollapudi writel(cpu_to_le32(msg), tgt->ctx_base); 1261853e2bd2SBhanu Gollapudi 1262853e2bd2SBhanu Gollapudi mmiowb(); 1263853e2bd2SBhanu Gollapudi 1264853e2bd2SBhanu Gollapudi } 1265853e2bd2SBhanu Gollapudi 1266853e2bd2SBhanu Gollapudi int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt) 1267853e2bd2SBhanu Gollapudi { 1268853e2bd2SBhanu Gollapudi u32 context_id = tgt->context_id; 1269853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port; 1270853e2bd2SBhanu Gollapudi u32 reg_off; 1271853e2bd2SBhanu Gollapudi resource_size_t reg_base; 1272853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = port->priv; 1273853e2bd2SBhanu Gollapudi 1274853e2bd2SBhanu Gollapudi reg_base = pci_resource_start(hba->pcidev, 1275853e2bd2SBhanu Gollapudi BNX2X_DOORBELL_PCI_BAR); 1276853e2bd2SBhanu Gollapudi reg_off = BNX2FC_5771X_DB_PAGE_SIZE * 1277853e2bd2SBhanu Gollapudi (context_id & 0x1FFFF) + DPM_TRIGER_TYPE; 1278853e2bd2SBhanu Gollapudi tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4); 1279853e2bd2SBhanu Gollapudi if (!tgt->ctx_base) 1280853e2bd2SBhanu Gollapudi return -ENOMEM; 1281853e2bd2SBhanu Gollapudi return 0; 1282853e2bd2SBhanu Gollapudi } 1283853e2bd2SBhanu Gollapudi 1284853e2bd2SBhanu Gollapudi char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items) 1285853e2bd2SBhanu Gollapudi { 1286853e2bd2SBhanu Gollapudi char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ); 1287853e2bd2SBhanu Gollapudi 1288853e2bd2SBhanu Gollapudi if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX) 1289853e2bd2SBhanu Gollapudi return NULL; 1290853e2bd2SBhanu Gollapudi 1291853e2bd2SBhanu Gollapudi tgt->rq_cons_idx += num_items; 1292853e2bd2SBhanu Gollapudi 1293853e2bd2SBhanu Gollapudi if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX) 1294853e2bd2SBhanu Gollapudi tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX; 1295853e2bd2SBhanu Gollapudi 1296853e2bd2SBhanu Gollapudi return buf; 1297853e2bd2SBhanu Gollapudi } 1298853e2bd2SBhanu Gollapudi 1299853e2bd2SBhanu Gollapudi void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items) 1300853e2bd2SBhanu Gollapudi { 1301853e2bd2SBhanu Gollapudi /* return the rq buffer */ 1302853e2bd2SBhanu Gollapudi u32 next_prod_idx = tgt->rq_prod_idx + num_items; 1303853e2bd2SBhanu Gollapudi if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) { 1304853e2bd2SBhanu Gollapudi /* Wrap around RQ */ 1305853e2bd2SBhanu Gollapudi next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX; 1306853e2bd2SBhanu Gollapudi } 1307853e2bd2SBhanu Gollapudi tgt->rq_prod_idx = next_prod_idx; 1308853e2bd2SBhanu Gollapudi tgt->conn_db->rq_prod = tgt->rq_prod_idx; 1309853e2bd2SBhanu Gollapudi } 1310853e2bd2SBhanu Gollapudi 1311853e2bd2SBhanu Gollapudi void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req, 1312853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task, 1313853e2bd2SBhanu Gollapudi u16 orig_xid) 1314853e2bd2SBhanu Gollapudi { 1315853e2bd2SBhanu Gollapudi u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP; 1316853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt; 1317853e2bd2SBhanu Gollapudi u32 context_id = tgt->context_id; 1318853e2bd2SBhanu Gollapudi 1319853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry)); 1320853e2bd2SBhanu Gollapudi 1321853e2bd2SBhanu Gollapudi /* Tx Write Rx Read */ 1322853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP << 1323853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT; 1324853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags = task_type << 1325853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT; 1326853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 << 1327853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT; 1328853e2bd2SBhanu Gollapudi /* Common */ 1329853e2bd2SBhanu Gollapudi task->cmn.common_flags = context_id << 1330853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT; 1331853e2bd2SBhanu Gollapudi task->cmn.general.cleanup_info.task_id = orig_xid; 1332853e2bd2SBhanu Gollapudi 1333853e2bd2SBhanu Gollapudi 1334853e2bd2SBhanu Gollapudi } 1335853e2bd2SBhanu Gollapudi 1336853e2bd2SBhanu Gollapudi void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req, 1337853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task) 1338853e2bd2SBhanu Gollapudi { 1339853e2bd2SBhanu Gollapudi struct bnx2fc_mp_req *mp_req = &(io_req->mp_req); 1340853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt; 1341853e2bd2SBhanu Gollapudi struct fc_frame_header *fc_hdr; 1342853e2bd2SBhanu Gollapudi u8 task_type = 0; 1343853e2bd2SBhanu Gollapudi u64 *hdr; 1344853e2bd2SBhanu Gollapudi u64 temp_hdr[3]; 1345853e2bd2SBhanu Gollapudi u32 context_id; 1346853e2bd2SBhanu Gollapudi 1347853e2bd2SBhanu Gollapudi 1348853e2bd2SBhanu Gollapudi /* Obtain task_type */ 1349853e2bd2SBhanu Gollapudi if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) || 1350853e2bd2SBhanu Gollapudi (io_req->cmd_type == BNX2FC_ELS)) { 1351853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_MIDPATH; 1352853e2bd2SBhanu Gollapudi } else if (io_req->cmd_type == BNX2FC_ABTS) { 1353853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_ABTS; 1354853e2bd2SBhanu Gollapudi } 1355853e2bd2SBhanu Gollapudi 1356853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry)); 1357853e2bd2SBhanu Gollapudi 1358853e2bd2SBhanu Gollapudi /* Setup the task from io_req for easy reference */ 1359853e2bd2SBhanu Gollapudi io_req->task = task; 1360853e2bd2SBhanu Gollapudi 1361853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n", 1362853e2bd2SBhanu Gollapudi io_req->cmd_type, task_type); 1363853e2bd2SBhanu Gollapudi 1364853e2bd2SBhanu Gollapudi /* Tx only */ 1365853e2bd2SBhanu Gollapudi if ((task_type == FCOE_TASK_TYPE_MIDPATH) || 1366853e2bd2SBhanu Gollapudi (task_type == FCOE_TASK_TYPE_UNSOLICITED)) { 1367853e2bd2SBhanu Gollapudi task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo = 1368853e2bd2SBhanu Gollapudi (u32)mp_req->mp_req_bd_dma; 1369853e2bd2SBhanu Gollapudi task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi = 1370853e2bd2SBhanu Gollapudi (u32)((u64)mp_req->mp_req_bd_dma >> 32); 1371853e2bd2SBhanu Gollapudi task->tx_wr_only.sgl_ctx.mul_sges.sgl_size = 1; 1372853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "init_mp_task - bd_dma = 0x%llx\n", 1373853e2bd2SBhanu Gollapudi (unsigned long long)mp_req->mp_req_bd_dma); 1374853e2bd2SBhanu Gollapudi } 1375853e2bd2SBhanu Gollapudi 1376853e2bd2SBhanu Gollapudi /* Tx Write Rx Read */ 1377853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_INIT << 1378853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT; 1379853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags = task_type << 1380853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT; 1381853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags |= FCOE_TASK_DEV_TYPE_DISK << 1382853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT; 1383853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 << 1384853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT; 1385853e2bd2SBhanu Gollapudi 1386853e2bd2SBhanu Gollapudi /* Common */ 1387853e2bd2SBhanu Gollapudi task->cmn.data_2_trns = io_req->data_xfer_len; 1388853e2bd2SBhanu Gollapudi context_id = tgt->context_id; 1389853e2bd2SBhanu Gollapudi task->cmn.common_flags = context_id << 1390853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT; 1391853e2bd2SBhanu Gollapudi task->cmn.common_flags |= 1 << 1392853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID_SHIFT; 1393853e2bd2SBhanu Gollapudi task->cmn.common_flags |= 1 << 1394853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME_SHIFT; 1395853e2bd2SBhanu Gollapudi 1396853e2bd2SBhanu Gollapudi /* Rx Write Tx Read */ 1397853e2bd2SBhanu Gollapudi fc_hdr = &(mp_req->req_fc_hdr); 1398853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_MIDPATH) { 1399853e2bd2SBhanu Gollapudi fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid); 1400853e2bd2SBhanu Gollapudi fc_hdr->fh_rx_id = htons(0xffff); 1401853e2bd2SBhanu Gollapudi task->rx_wr_tx_rd.rx_id = 0xffff; 1402853e2bd2SBhanu Gollapudi } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) { 1403853e2bd2SBhanu Gollapudi fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid); 1404853e2bd2SBhanu Gollapudi } 1405853e2bd2SBhanu Gollapudi 1406853e2bd2SBhanu Gollapudi /* Fill FC Header into middle path buffer */ 1407853e2bd2SBhanu Gollapudi hdr = (u64 *) &task->cmn.general.cmd_info.mp_fc_frame.fc_hdr; 1408853e2bd2SBhanu Gollapudi memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr)); 1409853e2bd2SBhanu Gollapudi hdr[0] = cpu_to_be64(temp_hdr[0]); 1410853e2bd2SBhanu Gollapudi hdr[1] = cpu_to_be64(temp_hdr[1]); 1411853e2bd2SBhanu Gollapudi hdr[2] = cpu_to_be64(temp_hdr[2]); 1412853e2bd2SBhanu Gollapudi 1413853e2bd2SBhanu Gollapudi /* Rx Only */ 1414853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_MIDPATH) { 1415853e2bd2SBhanu Gollapudi 1416853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo = 1417853e2bd2SBhanu Gollapudi (u32)mp_req->mp_resp_bd_dma; 1418853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi = 1419853e2bd2SBhanu Gollapudi (u32)((u64)mp_req->mp_resp_bd_dma >> 32); 1420853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.mul_sges.sgl_size = 1; 1421853e2bd2SBhanu Gollapudi } 1422853e2bd2SBhanu Gollapudi } 1423853e2bd2SBhanu Gollapudi 1424853e2bd2SBhanu Gollapudi void bnx2fc_init_task(struct bnx2fc_cmd *io_req, 1425853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task) 1426853e2bd2SBhanu Gollapudi { 1427853e2bd2SBhanu Gollapudi u8 task_type; 1428853e2bd2SBhanu Gollapudi struct scsi_cmnd *sc_cmd = io_req->sc_cmd; 1429853e2bd2SBhanu Gollapudi struct io_bdt *bd_tbl = io_req->bd_tbl; 1430853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt; 1431853e2bd2SBhanu Gollapudi u64 *fcp_cmnd; 1432853e2bd2SBhanu Gollapudi u64 tmp_fcp_cmnd[4]; 1433853e2bd2SBhanu Gollapudi u32 context_id; 1434853e2bd2SBhanu Gollapudi int cnt, i; 1435853e2bd2SBhanu Gollapudi int bd_count; 1436853e2bd2SBhanu Gollapudi 1437853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry)); 1438853e2bd2SBhanu Gollapudi 1439853e2bd2SBhanu Gollapudi /* Setup the task from io_req for easy reference */ 1440853e2bd2SBhanu Gollapudi io_req->task = task; 1441853e2bd2SBhanu Gollapudi 1442853e2bd2SBhanu Gollapudi if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) 1443853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_WRITE; 1444853e2bd2SBhanu Gollapudi else 1445853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_READ; 1446853e2bd2SBhanu Gollapudi 1447853e2bd2SBhanu Gollapudi /* Tx only */ 1448853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_WRITE) { 1449853e2bd2SBhanu Gollapudi task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo = 1450853e2bd2SBhanu Gollapudi (u32)bd_tbl->bd_tbl_dma; 1451853e2bd2SBhanu Gollapudi task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi = 1452853e2bd2SBhanu Gollapudi (u32)((u64)bd_tbl->bd_tbl_dma >> 32); 1453853e2bd2SBhanu Gollapudi task->tx_wr_only.sgl_ctx.mul_sges.sgl_size = 1454853e2bd2SBhanu Gollapudi bd_tbl->bd_valid; 1455853e2bd2SBhanu Gollapudi } 1456853e2bd2SBhanu Gollapudi 1457853e2bd2SBhanu Gollapudi /*Tx Write Rx Read */ 1458853e2bd2SBhanu Gollapudi /* Init state to NORMAL */ 1459853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_NORMAL << 1460853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT; 1461853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags = task_type << 1462853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT; 1463853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags |= FCOE_TASK_DEV_TYPE_DISK << 1464853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT; 1465853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 << 1466853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT; 1467853e2bd2SBhanu Gollapudi 1468853e2bd2SBhanu Gollapudi /* Common */ 1469853e2bd2SBhanu Gollapudi task->cmn.data_2_trns = io_req->data_xfer_len; 1470853e2bd2SBhanu Gollapudi context_id = tgt->context_id; 1471853e2bd2SBhanu Gollapudi task->cmn.common_flags = context_id << 1472853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT; 1473853e2bd2SBhanu Gollapudi task->cmn.common_flags |= 1 << 1474853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID_SHIFT; 1475853e2bd2SBhanu Gollapudi task->cmn.common_flags |= 1 << 1476853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME_SHIFT; 1477853e2bd2SBhanu Gollapudi 1478853e2bd2SBhanu Gollapudi /* Set initiative ownership */ 1479853e2bd2SBhanu Gollapudi task->cmn.common_flags |= FCOE_TASK_CTX_ENTRY_TX_RX_CMN_SEQ_INIT; 1480853e2bd2SBhanu Gollapudi 1481853e2bd2SBhanu Gollapudi /* Set initial seq counter */ 1482853e2bd2SBhanu Gollapudi task->cmn.tx_low_seq_cnt = 1; 1483853e2bd2SBhanu Gollapudi 1484853e2bd2SBhanu Gollapudi /* Set state to "waiting for the first packet" */ 1485853e2bd2SBhanu Gollapudi task->cmn.common_flags |= FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME; 1486853e2bd2SBhanu Gollapudi 1487853e2bd2SBhanu Gollapudi /* Fill FCP_CMND IU */ 1488853e2bd2SBhanu Gollapudi fcp_cmnd = (u64 *) 1489853e2bd2SBhanu Gollapudi task->cmn.general.cmd_info.fcp_cmd_payload.opaque; 1490853e2bd2SBhanu Gollapudi bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd); 1491853e2bd2SBhanu Gollapudi 1492853e2bd2SBhanu Gollapudi /* swap fcp_cmnd */ 1493853e2bd2SBhanu Gollapudi cnt = sizeof(struct fcp_cmnd) / sizeof(u64); 1494853e2bd2SBhanu Gollapudi 1495853e2bd2SBhanu Gollapudi for (i = 0; i < cnt; i++) { 1496853e2bd2SBhanu Gollapudi *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]); 1497853e2bd2SBhanu Gollapudi fcp_cmnd++; 1498853e2bd2SBhanu Gollapudi } 1499853e2bd2SBhanu Gollapudi 1500853e2bd2SBhanu Gollapudi /* Rx Write Tx Read */ 1501853e2bd2SBhanu Gollapudi task->rx_wr_tx_rd.rx_id = 0xffff; 1502853e2bd2SBhanu Gollapudi 1503853e2bd2SBhanu Gollapudi /* Rx Only */ 1504853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_READ) { 1505853e2bd2SBhanu Gollapudi 1506853e2bd2SBhanu Gollapudi bd_count = bd_tbl->bd_valid; 1507853e2bd2SBhanu Gollapudi if (bd_count == 1) { 1508853e2bd2SBhanu Gollapudi 1509853e2bd2SBhanu Gollapudi struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl; 1510853e2bd2SBhanu Gollapudi 1511853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.single_sge.cur_buf_addr.lo = 1512853e2bd2SBhanu Gollapudi fcoe_bd_tbl->buf_addr_lo; 1513853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.single_sge.cur_buf_addr.hi = 1514853e2bd2SBhanu Gollapudi fcoe_bd_tbl->buf_addr_hi; 1515853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.single_sge.cur_buf_rem = 1516853e2bd2SBhanu Gollapudi fcoe_bd_tbl->buf_len; 1517853e2bd2SBhanu Gollapudi task->tx_wr_rx_rd.init_flags |= 1 << 1518853e2bd2SBhanu Gollapudi FCOE_TASK_CTX_ENTRY_TXWR_RXRD_SINGLE_SGE_SHIFT; 1519853e2bd2SBhanu Gollapudi } else { 1520853e2bd2SBhanu Gollapudi 1521853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo = 1522853e2bd2SBhanu Gollapudi (u32)bd_tbl->bd_tbl_dma; 1523853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi = 1524853e2bd2SBhanu Gollapudi (u32)((u64)bd_tbl->bd_tbl_dma >> 32); 1525853e2bd2SBhanu Gollapudi task->rx_wr_only.sgl_ctx.mul_sges.sgl_size = 1526853e2bd2SBhanu Gollapudi bd_tbl->bd_valid; 1527853e2bd2SBhanu Gollapudi } 1528853e2bd2SBhanu Gollapudi } 1529853e2bd2SBhanu Gollapudi } 1530853e2bd2SBhanu Gollapudi 1531853e2bd2SBhanu Gollapudi /** 1532853e2bd2SBhanu Gollapudi * bnx2fc_setup_task_ctx - allocate and map task context 1533853e2bd2SBhanu Gollapudi * 1534853e2bd2SBhanu Gollapudi * @hba: pointer to adapter structure 1535853e2bd2SBhanu Gollapudi * 1536853e2bd2SBhanu Gollapudi * allocate memory for task context, and associated BD table to be used 1537853e2bd2SBhanu Gollapudi * by firmware 1538853e2bd2SBhanu Gollapudi * 1539853e2bd2SBhanu Gollapudi */ 1540853e2bd2SBhanu Gollapudi int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba) 1541853e2bd2SBhanu Gollapudi { 1542853e2bd2SBhanu Gollapudi int rc = 0; 1543853e2bd2SBhanu Gollapudi struct regpair *task_ctx_bdt; 1544853e2bd2SBhanu Gollapudi dma_addr_t addr; 1545853e2bd2SBhanu Gollapudi int i; 1546853e2bd2SBhanu Gollapudi 1547853e2bd2SBhanu Gollapudi /* 1548853e2bd2SBhanu Gollapudi * Allocate task context bd table. A page size of bd table 1549853e2bd2SBhanu Gollapudi * can map 256 buffers. Each buffer contains 32 task context 1550853e2bd2SBhanu Gollapudi * entries. Hence the limit with one page is 8192 task context 1551853e2bd2SBhanu Gollapudi * entries. 1552853e2bd2SBhanu Gollapudi */ 1553853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, 1554853e2bd2SBhanu Gollapudi PAGE_SIZE, 1555853e2bd2SBhanu Gollapudi &hba->task_ctx_bd_dma, 1556853e2bd2SBhanu Gollapudi GFP_KERNEL); 1557853e2bd2SBhanu Gollapudi if (!hba->task_ctx_bd_tbl) { 1558853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate task context BDT\n"); 1559853e2bd2SBhanu Gollapudi rc = -1; 1560853e2bd2SBhanu Gollapudi goto out; 1561853e2bd2SBhanu Gollapudi } 1562853e2bd2SBhanu Gollapudi memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE); 1563853e2bd2SBhanu Gollapudi 1564853e2bd2SBhanu Gollapudi /* 1565853e2bd2SBhanu Gollapudi * Allocate task_ctx which is an array of pointers pointing to 1566853e2bd2SBhanu Gollapudi * a page containing 32 task contexts 1567853e2bd2SBhanu Gollapudi */ 1568853e2bd2SBhanu Gollapudi hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)), 1569853e2bd2SBhanu Gollapudi GFP_KERNEL); 1570853e2bd2SBhanu Gollapudi if (!hba->task_ctx) { 1571853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate task context array\n"); 1572853e2bd2SBhanu Gollapudi rc = -1; 1573853e2bd2SBhanu Gollapudi goto out1; 1574853e2bd2SBhanu Gollapudi } 1575853e2bd2SBhanu Gollapudi 1576853e2bd2SBhanu Gollapudi /* 1577853e2bd2SBhanu Gollapudi * Allocate task_ctx_dma which is an array of dma addresses 1578853e2bd2SBhanu Gollapudi */ 1579853e2bd2SBhanu Gollapudi hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ * 1580853e2bd2SBhanu Gollapudi sizeof(dma_addr_t)), GFP_KERNEL); 1581853e2bd2SBhanu Gollapudi if (!hba->task_ctx_dma) { 1582853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc context mapping array\n"); 1583853e2bd2SBhanu Gollapudi rc = -1; 1584853e2bd2SBhanu Gollapudi goto out2; 1585853e2bd2SBhanu Gollapudi } 1586853e2bd2SBhanu Gollapudi 1587853e2bd2SBhanu Gollapudi task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl; 1588853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) { 1589853e2bd2SBhanu Gollapudi 1590853e2bd2SBhanu Gollapudi hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev, 1591853e2bd2SBhanu Gollapudi PAGE_SIZE, 1592853e2bd2SBhanu Gollapudi &hba->task_ctx_dma[i], 1593853e2bd2SBhanu Gollapudi GFP_KERNEL); 1594853e2bd2SBhanu Gollapudi if (!hba->task_ctx[i]) { 1595853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc task context\n"); 1596853e2bd2SBhanu Gollapudi rc = -1; 1597853e2bd2SBhanu Gollapudi goto out3; 1598853e2bd2SBhanu Gollapudi } 1599853e2bd2SBhanu Gollapudi memset(hba->task_ctx[i], 0, PAGE_SIZE); 1600853e2bd2SBhanu Gollapudi addr = (u64)hba->task_ctx_dma[i]; 1601853e2bd2SBhanu Gollapudi task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32); 1602853e2bd2SBhanu Gollapudi task_ctx_bdt->lo = cpu_to_le32((u32)addr); 1603853e2bd2SBhanu Gollapudi task_ctx_bdt++; 1604853e2bd2SBhanu Gollapudi } 1605853e2bd2SBhanu Gollapudi return 0; 1606853e2bd2SBhanu Gollapudi 1607853e2bd2SBhanu Gollapudi out3: 1608853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) { 1609853e2bd2SBhanu Gollapudi if (hba->task_ctx[i]) { 1610853e2bd2SBhanu Gollapudi 1611853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1612853e2bd2SBhanu Gollapudi hba->task_ctx[i], hba->task_ctx_dma[i]); 1613853e2bd2SBhanu Gollapudi hba->task_ctx[i] = NULL; 1614853e2bd2SBhanu Gollapudi } 1615853e2bd2SBhanu Gollapudi } 1616853e2bd2SBhanu Gollapudi 1617853e2bd2SBhanu Gollapudi kfree(hba->task_ctx_dma); 1618853e2bd2SBhanu Gollapudi hba->task_ctx_dma = NULL; 1619853e2bd2SBhanu Gollapudi out2: 1620853e2bd2SBhanu Gollapudi kfree(hba->task_ctx); 1621853e2bd2SBhanu Gollapudi hba->task_ctx = NULL; 1622853e2bd2SBhanu Gollapudi out1: 1623853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1624853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma); 1625853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = NULL; 1626853e2bd2SBhanu Gollapudi out: 1627853e2bd2SBhanu Gollapudi return rc; 1628853e2bd2SBhanu Gollapudi } 1629853e2bd2SBhanu Gollapudi 1630853e2bd2SBhanu Gollapudi void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba) 1631853e2bd2SBhanu Gollapudi { 1632853e2bd2SBhanu Gollapudi int i; 1633853e2bd2SBhanu Gollapudi 1634853e2bd2SBhanu Gollapudi if (hba->task_ctx_bd_tbl) { 1635853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1636853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl, 1637853e2bd2SBhanu Gollapudi hba->task_ctx_bd_dma); 1638853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = NULL; 1639853e2bd2SBhanu Gollapudi } 1640853e2bd2SBhanu Gollapudi 1641853e2bd2SBhanu Gollapudi if (hba->task_ctx) { 1642853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) { 1643853e2bd2SBhanu Gollapudi if (hba->task_ctx[i]) { 1644853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1645853e2bd2SBhanu Gollapudi hba->task_ctx[i], 1646853e2bd2SBhanu Gollapudi hba->task_ctx_dma[i]); 1647853e2bd2SBhanu Gollapudi hba->task_ctx[i] = NULL; 1648853e2bd2SBhanu Gollapudi } 1649853e2bd2SBhanu Gollapudi } 1650853e2bd2SBhanu Gollapudi kfree(hba->task_ctx); 1651853e2bd2SBhanu Gollapudi hba->task_ctx = NULL; 1652853e2bd2SBhanu Gollapudi } 1653853e2bd2SBhanu Gollapudi 1654853e2bd2SBhanu Gollapudi kfree(hba->task_ctx_dma); 1655853e2bd2SBhanu Gollapudi hba->task_ctx_dma = NULL; 1656853e2bd2SBhanu Gollapudi } 1657853e2bd2SBhanu Gollapudi 1658853e2bd2SBhanu Gollapudi static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba) 1659853e2bd2SBhanu Gollapudi { 1660853e2bd2SBhanu Gollapudi int i; 1661853e2bd2SBhanu Gollapudi int segment_count; 1662853e2bd2SBhanu Gollapudi int hash_table_size; 1663853e2bd2SBhanu Gollapudi u32 *pbl; 1664853e2bd2SBhanu Gollapudi 1665853e2bd2SBhanu Gollapudi segment_count = hba->hash_tbl_segment_count; 1666853e2bd2SBhanu Gollapudi hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL * 1667853e2bd2SBhanu Gollapudi sizeof(struct fcoe_hash_table_entry); 1668853e2bd2SBhanu Gollapudi 1669853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl; 1670853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) { 1671853e2bd2SBhanu Gollapudi dma_addr_t dma_address; 1672853e2bd2SBhanu Gollapudi 1673853e2bd2SBhanu Gollapudi dma_address = le32_to_cpu(*pbl); 1674853e2bd2SBhanu Gollapudi ++pbl; 1675853e2bd2SBhanu Gollapudi dma_address += ((u64)le32_to_cpu(*pbl)) << 32; 1676853e2bd2SBhanu Gollapudi ++pbl; 1677853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, 1678853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE, 1679853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i], 1680853e2bd2SBhanu Gollapudi dma_address); 1681853e2bd2SBhanu Gollapudi 1682853e2bd2SBhanu Gollapudi } 1683853e2bd2SBhanu Gollapudi 1684853e2bd2SBhanu Gollapudi if (hba->hash_tbl_pbl) { 1685853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1686853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl, 1687853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl_dma); 1688853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl = NULL; 1689853e2bd2SBhanu Gollapudi } 1690853e2bd2SBhanu Gollapudi } 1691853e2bd2SBhanu Gollapudi 1692853e2bd2SBhanu Gollapudi static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba) 1693853e2bd2SBhanu Gollapudi { 1694853e2bd2SBhanu Gollapudi int i; 1695853e2bd2SBhanu Gollapudi int hash_table_size; 1696853e2bd2SBhanu Gollapudi int segment_count; 1697853e2bd2SBhanu Gollapudi int segment_array_size; 1698853e2bd2SBhanu Gollapudi int dma_segment_array_size; 1699853e2bd2SBhanu Gollapudi dma_addr_t *dma_segment_array; 1700853e2bd2SBhanu Gollapudi u32 *pbl; 1701853e2bd2SBhanu Gollapudi 1702853e2bd2SBhanu Gollapudi hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL * 1703853e2bd2SBhanu Gollapudi sizeof(struct fcoe_hash_table_entry); 1704853e2bd2SBhanu Gollapudi 1705853e2bd2SBhanu Gollapudi segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1; 1706853e2bd2SBhanu Gollapudi segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE; 1707853e2bd2SBhanu Gollapudi hba->hash_tbl_segment_count = segment_count; 1708853e2bd2SBhanu Gollapudi 1709853e2bd2SBhanu Gollapudi segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments); 1710853e2bd2SBhanu Gollapudi hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL); 1711853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_segments) { 1712853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pointers alloc failed\n"); 1713853e2bd2SBhanu Gollapudi return -ENOMEM; 1714853e2bd2SBhanu Gollapudi } 1715853e2bd2SBhanu Gollapudi dma_segment_array_size = segment_count * sizeof(*dma_segment_array); 1716853e2bd2SBhanu Gollapudi dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL); 1717853e2bd2SBhanu Gollapudi if (!dma_segment_array) { 1718853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n"); 1719853e2bd2SBhanu Gollapudi return -ENOMEM; 1720853e2bd2SBhanu Gollapudi } 1721853e2bd2SBhanu Gollapudi 1722853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) { 1723853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i] = 1724853e2bd2SBhanu Gollapudi dma_alloc_coherent(&hba->pcidev->dev, 1725853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE, 1726853e2bd2SBhanu Gollapudi &dma_segment_array[i], 1727853e2bd2SBhanu Gollapudi GFP_KERNEL); 1728853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_segments[i]) { 1729853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash segment alloc failed\n"); 1730853e2bd2SBhanu Gollapudi while (--i >= 0) { 1731853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, 1732853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE, 1733853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i], 1734853e2bd2SBhanu Gollapudi dma_segment_array[i]); 1735853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i] = NULL; 1736853e2bd2SBhanu Gollapudi } 1737853e2bd2SBhanu Gollapudi kfree(dma_segment_array); 1738853e2bd2SBhanu Gollapudi return -ENOMEM; 1739853e2bd2SBhanu Gollapudi } 1740853e2bd2SBhanu Gollapudi memset(hba->hash_tbl_segments[i], 0, 1741853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE); 1742853e2bd2SBhanu Gollapudi } 1743853e2bd2SBhanu Gollapudi 1744853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev, 1745853e2bd2SBhanu Gollapudi PAGE_SIZE, 1746853e2bd2SBhanu Gollapudi &hba->hash_tbl_pbl_dma, 1747853e2bd2SBhanu Gollapudi GFP_KERNEL); 1748853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_pbl) { 1749853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pbl alloc failed\n"); 1750853e2bd2SBhanu Gollapudi kfree(dma_segment_array); 1751853e2bd2SBhanu Gollapudi return -ENOMEM; 1752853e2bd2SBhanu Gollapudi } 1753853e2bd2SBhanu Gollapudi memset(hba->hash_tbl_pbl, 0, PAGE_SIZE); 1754853e2bd2SBhanu Gollapudi 1755853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl; 1756853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) { 1757853e2bd2SBhanu Gollapudi u64 paddr = dma_segment_array[i]; 1758853e2bd2SBhanu Gollapudi *pbl = cpu_to_le32((u32) paddr); 1759853e2bd2SBhanu Gollapudi ++pbl; 1760853e2bd2SBhanu Gollapudi *pbl = cpu_to_le32((u32) (paddr >> 32)); 1761853e2bd2SBhanu Gollapudi ++pbl; 1762853e2bd2SBhanu Gollapudi } 1763853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl; 1764853e2bd2SBhanu Gollapudi i = 0; 1765853e2bd2SBhanu Gollapudi while (*pbl && *(pbl + 1)) { 1766853e2bd2SBhanu Gollapudi u32 lo; 1767853e2bd2SBhanu Gollapudi u32 hi; 1768853e2bd2SBhanu Gollapudi lo = *pbl; 1769853e2bd2SBhanu Gollapudi ++pbl; 1770853e2bd2SBhanu Gollapudi hi = *pbl; 1771853e2bd2SBhanu Gollapudi ++pbl; 1772853e2bd2SBhanu Gollapudi ++i; 1773853e2bd2SBhanu Gollapudi } 1774853e2bd2SBhanu Gollapudi kfree(dma_segment_array); 1775853e2bd2SBhanu Gollapudi return 0; 1776853e2bd2SBhanu Gollapudi } 1777853e2bd2SBhanu Gollapudi 1778853e2bd2SBhanu Gollapudi /** 1779853e2bd2SBhanu Gollapudi * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer 1780853e2bd2SBhanu Gollapudi * 1781853e2bd2SBhanu Gollapudi * @hba: Pointer to adapter structure 1782853e2bd2SBhanu Gollapudi * 1783853e2bd2SBhanu Gollapudi */ 1784853e2bd2SBhanu Gollapudi int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba) 1785853e2bd2SBhanu Gollapudi { 1786853e2bd2SBhanu Gollapudi u64 addr; 1787853e2bd2SBhanu Gollapudi u32 mem_size; 1788853e2bd2SBhanu Gollapudi int i; 1789853e2bd2SBhanu Gollapudi 1790853e2bd2SBhanu Gollapudi if (bnx2fc_allocate_hash_table(hba)) 1791853e2bd2SBhanu Gollapudi return -ENOMEM; 1792853e2bd2SBhanu Gollapudi 1793853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair); 1794853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size, 1795853e2bd2SBhanu Gollapudi &hba->t2_hash_tbl_ptr_dma, 1796853e2bd2SBhanu Gollapudi GFP_KERNEL); 1797853e2bd2SBhanu Gollapudi if (!hba->t2_hash_tbl_ptr) { 1798853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n"); 1799853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1800853e2bd2SBhanu Gollapudi return -ENOMEM; 1801853e2bd2SBhanu Gollapudi } 1802853e2bd2SBhanu Gollapudi memset(hba->t2_hash_tbl_ptr, 0x00, mem_size); 1803853e2bd2SBhanu Gollapudi 1804853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * 1805853e2bd2SBhanu Gollapudi sizeof(struct fcoe_t2_hash_table_entry); 1806853e2bd2SBhanu Gollapudi hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size, 1807853e2bd2SBhanu Gollapudi &hba->t2_hash_tbl_dma, 1808853e2bd2SBhanu Gollapudi GFP_KERNEL); 1809853e2bd2SBhanu Gollapudi if (!hba->t2_hash_tbl) { 1810853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate t2 hash table\n"); 1811853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1812853e2bd2SBhanu Gollapudi return -ENOMEM; 1813853e2bd2SBhanu Gollapudi } 1814853e2bd2SBhanu Gollapudi memset(hba->t2_hash_tbl, 0x00, mem_size); 1815853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) { 1816853e2bd2SBhanu Gollapudi addr = (unsigned long) hba->t2_hash_tbl_dma + 1817853e2bd2SBhanu Gollapudi ((i+1) * sizeof(struct fcoe_t2_hash_table_entry)); 1818853e2bd2SBhanu Gollapudi hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff; 1819853e2bd2SBhanu Gollapudi hba->t2_hash_tbl[i].next.hi = addr >> 32; 1820853e2bd2SBhanu Gollapudi } 1821853e2bd2SBhanu Gollapudi 1822853e2bd2SBhanu Gollapudi hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, 1823853e2bd2SBhanu Gollapudi PAGE_SIZE, &hba->dummy_buf_dma, 1824853e2bd2SBhanu Gollapudi GFP_KERNEL); 1825853e2bd2SBhanu Gollapudi if (!hba->dummy_buffer) { 1826853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n"); 1827853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1828853e2bd2SBhanu Gollapudi return -ENOMEM; 1829853e2bd2SBhanu Gollapudi } 1830853e2bd2SBhanu Gollapudi 1831853e2bd2SBhanu Gollapudi hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev, 1832853e2bd2SBhanu Gollapudi PAGE_SIZE, 1833853e2bd2SBhanu Gollapudi &hba->stats_buf_dma, 1834853e2bd2SBhanu Gollapudi GFP_KERNEL); 1835853e2bd2SBhanu Gollapudi if (!hba->stats_buffer) { 1836853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc Stats Buffer\n"); 1837853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba); 1838853e2bd2SBhanu Gollapudi return -ENOMEM; 1839853e2bd2SBhanu Gollapudi } 1840853e2bd2SBhanu Gollapudi memset(hba->stats_buffer, 0x00, PAGE_SIZE); 1841853e2bd2SBhanu Gollapudi 1842853e2bd2SBhanu Gollapudi return 0; 1843853e2bd2SBhanu Gollapudi } 1844853e2bd2SBhanu Gollapudi 1845853e2bd2SBhanu Gollapudi void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba) 1846853e2bd2SBhanu Gollapudi { 1847853e2bd2SBhanu Gollapudi u32 mem_size; 1848853e2bd2SBhanu Gollapudi 1849853e2bd2SBhanu Gollapudi if (hba->stats_buffer) { 1850853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1851853e2bd2SBhanu Gollapudi hba->stats_buffer, hba->stats_buf_dma); 1852853e2bd2SBhanu Gollapudi hba->stats_buffer = NULL; 1853853e2bd2SBhanu Gollapudi } 1854853e2bd2SBhanu Gollapudi 1855853e2bd2SBhanu Gollapudi if (hba->dummy_buffer) { 1856853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1857853e2bd2SBhanu Gollapudi hba->dummy_buffer, hba->dummy_buf_dma); 1858853e2bd2SBhanu Gollapudi hba->dummy_buffer = NULL; 1859853e2bd2SBhanu Gollapudi } 1860853e2bd2SBhanu Gollapudi 1861853e2bd2SBhanu Gollapudi if (hba->t2_hash_tbl_ptr) { 1862853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair); 1863853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, mem_size, 1864853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr, 1865853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr_dma); 1866853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr = NULL; 1867853e2bd2SBhanu Gollapudi } 1868853e2bd2SBhanu Gollapudi 1869853e2bd2SBhanu Gollapudi if (hba->t2_hash_tbl) { 1870853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * 1871853e2bd2SBhanu Gollapudi sizeof(struct fcoe_t2_hash_table_entry); 1872853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, mem_size, 1873853e2bd2SBhanu Gollapudi hba->t2_hash_tbl, hba->t2_hash_tbl_dma); 1874853e2bd2SBhanu Gollapudi hba->t2_hash_tbl = NULL; 1875853e2bd2SBhanu Gollapudi } 1876853e2bd2SBhanu Gollapudi bnx2fc_free_hash_table(hba); 1877853e2bd2SBhanu Gollapudi } 1878