xref: /openbmc/linux/drivers/scsi/bnx2fc/bnx2fc_hwi.c (revision fdbcbcab0eae6773430546697ace0b3fe48e7fbc)
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  *
5cf122191SBhanu Prakash Gollapudi  * Copyright (c) 2008 - 2013 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,
26aea71a02SBhanu Prakash Gollapudi 					struct fcoe_kcqe *destroy_kcqe);
27853e2bd2SBhanu Gollapudi 
28853e2bd2SBhanu Gollapudi int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
29853e2bd2SBhanu Gollapudi {
30853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_stat stat_req;
31853e2bd2SBhanu Gollapudi 	struct kwqe *kwqe_arr[2];
32853e2bd2SBhanu Gollapudi 	int num_kwqes = 1;
33853e2bd2SBhanu Gollapudi 	int rc = 0;
34853e2bd2SBhanu Gollapudi 
35853e2bd2SBhanu Gollapudi 	memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat));
36853e2bd2SBhanu Gollapudi 	stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT;
37853e2bd2SBhanu Gollapudi 	stat_req.hdr.flags =
38853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
39853e2bd2SBhanu Gollapudi 
40853e2bd2SBhanu Gollapudi 	stat_req.stat_params_addr_lo = (u32) hba->stats_buf_dma;
41853e2bd2SBhanu Gollapudi 	stat_req.stat_params_addr_hi = (u32) ((u64)hba->stats_buf_dma >> 32);
42853e2bd2SBhanu Gollapudi 
43853e2bd2SBhanu Gollapudi 	kwqe_arr[0] = (struct kwqe *) &stat_req;
44853e2bd2SBhanu Gollapudi 
45853e2bd2SBhanu Gollapudi 	if (hba->cnic && hba->cnic->submit_kwqes)
46853e2bd2SBhanu Gollapudi 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
47853e2bd2SBhanu Gollapudi 
48853e2bd2SBhanu Gollapudi 	return rc;
49853e2bd2SBhanu Gollapudi }
50853e2bd2SBhanu Gollapudi 
51853e2bd2SBhanu Gollapudi /**
52853e2bd2SBhanu Gollapudi  * bnx2fc_send_fw_fcoe_init_msg - initiates initial handshake with FCoE f/w
53853e2bd2SBhanu Gollapudi  *
54853e2bd2SBhanu Gollapudi  * @hba:	adapter structure pointer
55853e2bd2SBhanu Gollapudi  *
56853e2bd2SBhanu Gollapudi  * Send down FCoE firmware init KWQEs which initiates the initial handshake
57853e2bd2SBhanu Gollapudi  *	with the f/w.
58853e2bd2SBhanu Gollapudi  *
59853e2bd2SBhanu Gollapudi  */
60853e2bd2SBhanu Gollapudi int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
61853e2bd2SBhanu Gollapudi {
62853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_init1 fcoe_init1;
63853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_init2 fcoe_init2;
64853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_init3 fcoe_init3;
65853e2bd2SBhanu Gollapudi 	struct kwqe *kwqe_arr[3];
66853e2bd2SBhanu Gollapudi 	int num_kwqes = 3;
67853e2bd2SBhanu Gollapudi 	int rc = 0;
68853e2bd2SBhanu Gollapudi 
69853e2bd2SBhanu Gollapudi 	if (!hba->cnic) {
70aea71a02SBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "hba->cnic NULL during fcoe fw init\n");
71853e2bd2SBhanu Gollapudi 		return -ENODEV;
72853e2bd2SBhanu Gollapudi 	}
73853e2bd2SBhanu Gollapudi 
74853e2bd2SBhanu Gollapudi 	/* fill init1 KWQE */
75853e2bd2SBhanu Gollapudi 	memset(&fcoe_init1, 0x00, sizeof(struct fcoe_kwqe_init1));
76853e2bd2SBhanu Gollapudi 	fcoe_init1.hdr.op_code = FCOE_KWQE_OPCODE_INIT1;
77853e2bd2SBhanu Gollapudi 	fcoe_init1.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
78853e2bd2SBhanu Gollapudi 					FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
79853e2bd2SBhanu Gollapudi 
800eb43b4bSBhanu Prakash Gollapudi 	fcoe_init1.num_tasks = hba->max_tasks;
81853e2bd2SBhanu Gollapudi 	fcoe_init1.sq_num_wqes = BNX2FC_SQ_WQES_MAX;
82853e2bd2SBhanu Gollapudi 	fcoe_init1.rq_num_wqes = BNX2FC_RQ_WQES_MAX;
83853e2bd2SBhanu Gollapudi 	fcoe_init1.rq_buffer_log_size = BNX2FC_RQ_BUF_LOG_SZ;
84853e2bd2SBhanu Gollapudi 	fcoe_init1.cq_num_wqes = BNX2FC_CQ_WQES_MAX;
85853e2bd2SBhanu Gollapudi 	fcoe_init1.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
86853e2bd2SBhanu Gollapudi 	fcoe_init1.dummy_buffer_addr_hi = (u32) ((u64)hba->dummy_buf_dma >> 32);
87853e2bd2SBhanu Gollapudi 	fcoe_init1.task_list_pbl_addr_lo = (u32) hba->task_ctx_bd_dma;
88853e2bd2SBhanu Gollapudi 	fcoe_init1.task_list_pbl_addr_hi =
89853e2bd2SBhanu Gollapudi 				(u32) ((u64) hba->task_ctx_bd_dma >> 32);
901294bfe6SBhanu Gollapudi 	fcoe_init1.mtu = BNX2FC_MINI_JUMBO_MTU;
91853e2bd2SBhanu Gollapudi 
92853e2bd2SBhanu Gollapudi 	fcoe_init1.flags = (PAGE_SHIFT <<
93853e2bd2SBhanu Gollapudi 				FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT);
94853e2bd2SBhanu Gollapudi 
95853e2bd2SBhanu Gollapudi 	fcoe_init1.num_sessions_log = BNX2FC_NUM_MAX_SESS_LOG;
96853e2bd2SBhanu Gollapudi 
97853e2bd2SBhanu Gollapudi 	/* fill init2 KWQE */
98853e2bd2SBhanu Gollapudi 	memset(&fcoe_init2, 0x00, sizeof(struct fcoe_kwqe_init2));
99853e2bd2SBhanu Gollapudi 	fcoe_init2.hdr.op_code = FCOE_KWQE_OPCODE_INIT2;
100853e2bd2SBhanu Gollapudi 	fcoe_init2.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
101853e2bd2SBhanu Gollapudi 					FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
102853e2bd2SBhanu Gollapudi 
103619c5cb6SVlad Zolotarov 	fcoe_init2.hsi_major_version = FCOE_HSI_MAJOR_VERSION;
104619c5cb6SVlad Zolotarov 	fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION;
105619c5cb6SVlad Zolotarov 
106aea71a02SBhanu Prakash Gollapudi 
107853e2bd2SBhanu Gollapudi 	fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
108853e2bd2SBhanu Gollapudi 	fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
109853e2bd2SBhanu Gollapudi 					   ((u64) hba->hash_tbl_pbl_dma >> 32);
110853e2bd2SBhanu Gollapudi 
111853e2bd2SBhanu Gollapudi 	fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma;
112853e2bd2SBhanu Gollapudi 	fcoe_init2.t2_hash_tbl_addr_hi = (u32)
113853e2bd2SBhanu Gollapudi 					  ((u64) hba->t2_hash_tbl_dma >> 32);
114853e2bd2SBhanu Gollapudi 
115853e2bd2SBhanu Gollapudi 	fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma;
116853e2bd2SBhanu Gollapudi 	fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32)
117853e2bd2SBhanu Gollapudi 					((u64) hba->t2_hash_tbl_ptr_dma >> 32);
118853e2bd2SBhanu Gollapudi 
119853e2bd2SBhanu Gollapudi 	fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS;
120853e2bd2SBhanu Gollapudi 
121853e2bd2SBhanu Gollapudi 	/* fill init3 KWQE */
122853e2bd2SBhanu Gollapudi 	memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3));
123853e2bd2SBhanu Gollapudi 	fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3;
124853e2bd2SBhanu Gollapudi 	fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
125853e2bd2SBhanu Gollapudi 					FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
126853e2bd2SBhanu Gollapudi 	fcoe_init3.error_bit_map_lo = 0xffffffff;
127853e2bd2SBhanu Gollapudi 	fcoe_init3.error_bit_map_hi = 0xffffffff;
128853e2bd2SBhanu Gollapudi 
129353c2adeSBhanu Prakash Gollapudi 	/*
130353c2adeSBhanu Prakash Gollapudi 	 * enable both cached connection and cached tasks
131353c2adeSBhanu Prakash Gollapudi 	 * 0 = none, 1 = cached connection, 2 = cached tasks, 3 = both
132353c2adeSBhanu Prakash Gollapudi 	 */
133353c2adeSBhanu Prakash Gollapudi 	fcoe_init3.perf_config = 3;
134853e2bd2SBhanu Gollapudi 
135853e2bd2SBhanu Gollapudi 	kwqe_arr[0] = (struct kwqe *) &fcoe_init1;
136853e2bd2SBhanu Gollapudi 	kwqe_arr[1] = (struct kwqe *) &fcoe_init2;
137853e2bd2SBhanu Gollapudi 	kwqe_arr[2] = (struct kwqe *) &fcoe_init3;
138853e2bd2SBhanu Gollapudi 
139853e2bd2SBhanu Gollapudi 	if (hba->cnic && hba->cnic->submit_kwqes)
140853e2bd2SBhanu Gollapudi 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
141853e2bd2SBhanu Gollapudi 
142853e2bd2SBhanu Gollapudi 	return rc;
143853e2bd2SBhanu Gollapudi }
144853e2bd2SBhanu Gollapudi int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba)
145853e2bd2SBhanu Gollapudi {
146853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_destroy fcoe_destroy;
147853e2bd2SBhanu Gollapudi 	struct kwqe *kwqe_arr[2];
148853e2bd2SBhanu Gollapudi 	int num_kwqes = 1;
149853e2bd2SBhanu Gollapudi 	int rc = -1;
150853e2bd2SBhanu Gollapudi 
151853e2bd2SBhanu Gollapudi 	/* fill destroy KWQE */
152853e2bd2SBhanu Gollapudi 	memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy));
153853e2bd2SBhanu Gollapudi 	fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY;
154853e2bd2SBhanu Gollapudi 	fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
155853e2bd2SBhanu Gollapudi 					FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
156853e2bd2SBhanu Gollapudi 	kwqe_arr[0] = (struct kwqe *) &fcoe_destroy;
157853e2bd2SBhanu Gollapudi 
158853e2bd2SBhanu Gollapudi 	if (hba->cnic && hba->cnic->submit_kwqes)
159853e2bd2SBhanu Gollapudi 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
160853e2bd2SBhanu Gollapudi 	return rc;
161853e2bd2SBhanu Gollapudi }
162853e2bd2SBhanu Gollapudi 
163853e2bd2SBhanu Gollapudi /**
164853e2bd2SBhanu Gollapudi  * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process
165853e2bd2SBhanu Gollapudi  *
166853e2bd2SBhanu Gollapudi  * @port:		port structure pointer
167853e2bd2SBhanu Gollapudi  * @tgt:		bnx2fc_rport structure pointer
168853e2bd2SBhanu Gollapudi  */
169853e2bd2SBhanu Gollapudi int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
170853e2bd2SBhanu Gollapudi 					struct bnx2fc_rport *tgt)
171853e2bd2SBhanu Gollapudi {
172853e2bd2SBhanu Gollapudi 	struct fc_lport *lport = port->lport;
173aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = port->priv;
174fd8f8902SRobert Love 	struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
175aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_hba *hba = interface->hba;
176853e2bd2SBhanu Gollapudi 	struct kwqe *kwqe_arr[4];
177853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_conn_offload1 ofld_req1;
178853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_conn_offload2 ofld_req2;
179853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_conn_offload3 ofld_req3;
180853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_conn_offload4 ofld_req4;
181853e2bd2SBhanu Gollapudi 	struct fc_rport_priv *rdata = tgt->rdata;
182853e2bd2SBhanu Gollapudi 	struct fc_rport *rport = tgt->rport;
183853e2bd2SBhanu Gollapudi 	int num_kwqes = 4;
184853e2bd2SBhanu Gollapudi 	u32 port_id;
185853e2bd2SBhanu Gollapudi 	int rc = 0;
186853e2bd2SBhanu Gollapudi 	u16 conn_id;
187853e2bd2SBhanu Gollapudi 
188853e2bd2SBhanu Gollapudi 	/* Initialize offload request 1 structure */
189853e2bd2SBhanu Gollapudi 	memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
190853e2bd2SBhanu Gollapudi 
191853e2bd2SBhanu Gollapudi 	ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
192853e2bd2SBhanu Gollapudi 	ofld_req1.hdr.flags =
193853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
194853e2bd2SBhanu Gollapudi 
195853e2bd2SBhanu Gollapudi 
196853e2bd2SBhanu Gollapudi 	conn_id = (u16)tgt->fcoe_conn_id;
197853e2bd2SBhanu Gollapudi 	ofld_req1.fcoe_conn_id = conn_id;
198853e2bd2SBhanu Gollapudi 
199853e2bd2SBhanu Gollapudi 
200853e2bd2SBhanu Gollapudi 	ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
201853e2bd2SBhanu Gollapudi 	ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
202853e2bd2SBhanu Gollapudi 
203853e2bd2SBhanu Gollapudi 	ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
204853e2bd2SBhanu Gollapudi 	ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
205853e2bd2SBhanu Gollapudi 
206853e2bd2SBhanu Gollapudi 	ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
207853e2bd2SBhanu Gollapudi 	ofld_req1.rq_first_pbe_addr_hi =
208853e2bd2SBhanu Gollapudi 				(u32)((u64) tgt->rq_dma >> 32);
209853e2bd2SBhanu Gollapudi 
210853e2bd2SBhanu Gollapudi 	ofld_req1.rq_prod = 0x8000;
211853e2bd2SBhanu Gollapudi 
212853e2bd2SBhanu Gollapudi 	/* Initialize offload request 2 structure */
213853e2bd2SBhanu Gollapudi 	memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
214853e2bd2SBhanu Gollapudi 
215853e2bd2SBhanu Gollapudi 	ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
216853e2bd2SBhanu Gollapudi 	ofld_req2.hdr.flags =
217853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
218853e2bd2SBhanu Gollapudi 
219853e2bd2SBhanu Gollapudi 	ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
220853e2bd2SBhanu Gollapudi 
221853e2bd2SBhanu Gollapudi 	ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
222853e2bd2SBhanu Gollapudi 	ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
223853e2bd2SBhanu Gollapudi 
224853e2bd2SBhanu Gollapudi 	ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
225853e2bd2SBhanu Gollapudi 	ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
226853e2bd2SBhanu Gollapudi 
227853e2bd2SBhanu Gollapudi 	ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
228853e2bd2SBhanu Gollapudi 	ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
229853e2bd2SBhanu Gollapudi 
230853e2bd2SBhanu Gollapudi 	/* Initialize offload request 3 structure */
231853e2bd2SBhanu Gollapudi 	memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
232853e2bd2SBhanu Gollapudi 
233853e2bd2SBhanu Gollapudi 	ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
234853e2bd2SBhanu Gollapudi 	ofld_req3.hdr.flags =
235853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
236853e2bd2SBhanu Gollapudi 
237aea71a02SBhanu Prakash Gollapudi 	ofld_req3.vlan_tag = interface->vlan_id <<
238853e2bd2SBhanu Gollapudi 				FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
239853e2bd2SBhanu Gollapudi 	ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
240853e2bd2SBhanu Gollapudi 
241853e2bd2SBhanu Gollapudi 	port_id = fc_host_port_id(lport->host);
242853e2bd2SBhanu Gollapudi 	if (port_id == 0) {
243853e2bd2SBhanu Gollapudi 		BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
244853e2bd2SBhanu Gollapudi 		return -EINVAL;
245853e2bd2SBhanu Gollapudi 	}
246853e2bd2SBhanu Gollapudi 
247853e2bd2SBhanu Gollapudi 	/*
248853e2bd2SBhanu Gollapudi 	 * Store s_id of the initiator for further reference. This will
249853e2bd2SBhanu Gollapudi 	 * be used during disable/destroy during linkdown processing as
250853e2bd2SBhanu Gollapudi 	 * when the lport is reset, the port_id also is reset to 0
251853e2bd2SBhanu Gollapudi 	 */
252853e2bd2SBhanu Gollapudi 	tgt->sid = port_id;
253853e2bd2SBhanu Gollapudi 	ofld_req3.s_id[0] = (port_id & 0x000000FF);
254853e2bd2SBhanu Gollapudi 	ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
255853e2bd2SBhanu Gollapudi 	ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
256853e2bd2SBhanu Gollapudi 
257853e2bd2SBhanu Gollapudi 	port_id = rport->port_id;
258853e2bd2SBhanu Gollapudi 	ofld_req3.d_id[0] = (port_id & 0x000000FF);
259853e2bd2SBhanu Gollapudi 	ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
260853e2bd2SBhanu Gollapudi 	ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
261853e2bd2SBhanu Gollapudi 
262853e2bd2SBhanu Gollapudi 	ofld_req3.tx_total_conc_seqs = rdata->max_seq;
263853e2bd2SBhanu Gollapudi 
264853e2bd2SBhanu Gollapudi 	ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
265853e2bd2SBhanu Gollapudi 	ofld_req3.rx_max_fc_pay_len  = lport->mfs;
266853e2bd2SBhanu Gollapudi 
267853e2bd2SBhanu Gollapudi 	ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
268853e2bd2SBhanu Gollapudi 	ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
269853e2bd2SBhanu Gollapudi 	ofld_req3.rx_open_seqs_exch_c3 = 1;
270853e2bd2SBhanu Gollapudi 
271853e2bd2SBhanu Gollapudi 	ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
272853e2bd2SBhanu Gollapudi 	ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
273853e2bd2SBhanu Gollapudi 
274853e2bd2SBhanu Gollapudi 	/* set mul_n_port_ids supported flag to 0, until it is supported */
275853e2bd2SBhanu Gollapudi 	ofld_req3.flags = 0;
276853e2bd2SBhanu Gollapudi 	/*
277853e2bd2SBhanu Gollapudi 	ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
278853e2bd2SBhanu Gollapudi 			    FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
279853e2bd2SBhanu Gollapudi 	*/
280853e2bd2SBhanu Gollapudi 	/* Info from PLOGI response */
281853e2bd2SBhanu Gollapudi 	ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
282853e2bd2SBhanu Gollapudi 			     FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
283853e2bd2SBhanu Gollapudi 
284853e2bd2SBhanu Gollapudi 	ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
285853e2bd2SBhanu Gollapudi 			     FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
286853e2bd2SBhanu Gollapudi 
287b252f4c7SBhanu Prakash Gollapudi 	/*
288b252f4c7SBhanu Prakash Gollapudi 	 * Info from PRLI response, this info is used for sequence level error
289b252f4c7SBhanu Prakash Gollapudi 	 * recovery support
290b252f4c7SBhanu Prakash Gollapudi 	 */
291b252f4c7SBhanu Prakash Gollapudi 	if (tgt->dev_type == TYPE_TAPE) {
292b252f4c7SBhanu Prakash Gollapudi 		ofld_req3.flags |= 1 <<
293b252f4c7SBhanu Prakash Gollapudi 				    FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT;
294b252f4c7SBhanu Prakash Gollapudi 		ofld_req3.flags |= (((rdata->flags & FC_RP_FLAGS_REC_SUPPORTED)
295b252f4c7SBhanu Prakash Gollapudi 				    ? 1 : 0) <<
296b252f4c7SBhanu Prakash Gollapudi 				    FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT);
297b252f4c7SBhanu Prakash Gollapudi 	}
298b252f4c7SBhanu Prakash Gollapudi 
299853e2bd2SBhanu Gollapudi 	/* vlan flag */
300aea71a02SBhanu Prakash Gollapudi 	ofld_req3.flags |= (interface->vlan_enabled <<
301853e2bd2SBhanu Gollapudi 			    FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
302853e2bd2SBhanu Gollapudi 
303d7558148SMasanari Iida 	/* C2_VALID and ACK flags are not set as they are not supported */
304853e2bd2SBhanu Gollapudi 
305853e2bd2SBhanu Gollapudi 
306853e2bd2SBhanu Gollapudi 	/* Initialize offload request 4 structure */
307853e2bd2SBhanu Gollapudi 	memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
308853e2bd2SBhanu Gollapudi 	ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
309853e2bd2SBhanu Gollapudi 	ofld_req4.hdr.flags =
310853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
311853e2bd2SBhanu Gollapudi 
312853e2bd2SBhanu Gollapudi 	ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
313853e2bd2SBhanu Gollapudi 
314853e2bd2SBhanu Gollapudi 
315619c5cb6SVlad Zolotarov 	ofld_req4.src_mac_addr_lo[0] =  port->data_src_addr[5];
316853e2bd2SBhanu Gollapudi 							/* local mac */
317619c5cb6SVlad Zolotarov 	ofld_req4.src_mac_addr_lo[1] =  port->data_src_addr[4];
318619c5cb6SVlad Zolotarov 	ofld_req4.src_mac_addr_mid[0] =  port->data_src_addr[3];
319619c5cb6SVlad Zolotarov 	ofld_req4.src_mac_addr_mid[1] =  port->data_src_addr[2];
320619c5cb6SVlad Zolotarov 	ofld_req4.src_mac_addr_hi[0] =  port->data_src_addr[1];
321619c5cb6SVlad Zolotarov 	ofld_req4.src_mac_addr_hi[1] =  port->data_src_addr[0];
322fd8f8902SRobert Love 	ofld_req4.dst_mac_addr_lo[0] =  ctlr->dest_addr[5];
323aea71a02SBhanu Prakash Gollapudi 							/* fcf mac */
324fd8f8902SRobert Love 	ofld_req4.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
325fd8f8902SRobert Love 	ofld_req4.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
326fd8f8902SRobert Love 	ofld_req4.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
327fd8f8902SRobert Love 	ofld_req4.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
328fd8f8902SRobert Love 	ofld_req4.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
329853e2bd2SBhanu Gollapudi 
330853e2bd2SBhanu Gollapudi 	ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
331853e2bd2SBhanu Gollapudi 	ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
332853e2bd2SBhanu Gollapudi 
333853e2bd2SBhanu Gollapudi 	ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
334853e2bd2SBhanu Gollapudi 	ofld_req4.confq_pbl_base_addr_hi =
335853e2bd2SBhanu Gollapudi 					(u32)((u64) tgt->confq_pbl_dma >> 32);
336853e2bd2SBhanu Gollapudi 
337853e2bd2SBhanu Gollapudi 	kwqe_arr[0] = (struct kwqe *) &ofld_req1;
338853e2bd2SBhanu Gollapudi 	kwqe_arr[1] = (struct kwqe *) &ofld_req2;
339853e2bd2SBhanu Gollapudi 	kwqe_arr[2] = (struct kwqe *) &ofld_req3;
340853e2bd2SBhanu Gollapudi 	kwqe_arr[3] = (struct kwqe *) &ofld_req4;
341853e2bd2SBhanu Gollapudi 
342853e2bd2SBhanu Gollapudi 	if (hba->cnic && hba->cnic->submit_kwqes)
343853e2bd2SBhanu Gollapudi 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
344853e2bd2SBhanu Gollapudi 
345853e2bd2SBhanu Gollapudi 	return rc;
346853e2bd2SBhanu Gollapudi }
347853e2bd2SBhanu Gollapudi 
348853e2bd2SBhanu Gollapudi /**
349853e2bd2SBhanu Gollapudi  * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
350853e2bd2SBhanu Gollapudi  *
351853e2bd2SBhanu Gollapudi  * @port:		port structure pointer
352853e2bd2SBhanu Gollapudi  * @tgt:		bnx2fc_rport structure pointer
353853e2bd2SBhanu Gollapudi  */
354e7f4fed5SBhanu Prakash Gollapudi int bnx2fc_send_session_enable_req(struct fcoe_port *port,
355853e2bd2SBhanu Gollapudi 					struct bnx2fc_rport *tgt)
356853e2bd2SBhanu Gollapudi {
357853e2bd2SBhanu Gollapudi 	struct kwqe *kwqe_arr[2];
358aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = port->priv;
359fd8f8902SRobert Love 	struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
360aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_hba *hba = interface->hba;
361853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_conn_enable_disable enbl_req;
362853e2bd2SBhanu Gollapudi 	struct fc_lport *lport = port->lport;
363853e2bd2SBhanu Gollapudi 	struct fc_rport *rport = tgt->rport;
364853e2bd2SBhanu Gollapudi 	int num_kwqes = 1;
365853e2bd2SBhanu Gollapudi 	int rc = 0;
366853e2bd2SBhanu Gollapudi 	u32 port_id;
367853e2bd2SBhanu Gollapudi 
368853e2bd2SBhanu Gollapudi 	memset(&enbl_req, 0x00,
369853e2bd2SBhanu Gollapudi 	       sizeof(struct fcoe_kwqe_conn_enable_disable));
370853e2bd2SBhanu Gollapudi 	enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
371853e2bd2SBhanu Gollapudi 	enbl_req.hdr.flags =
372853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
373853e2bd2SBhanu Gollapudi 
374619c5cb6SVlad Zolotarov 	enbl_req.src_mac_addr_lo[0] =  port->data_src_addr[5];
375853e2bd2SBhanu Gollapudi 							/* local mac */
376619c5cb6SVlad Zolotarov 	enbl_req.src_mac_addr_lo[1] =  port->data_src_addr[4];
377619c5cb6SVlad Zolotarov 	enbl_req.src_mac_addr_mid[0] =  port->data_src_addr[3];
378619c5cb6SVlad Zolotarov 	enbl_req.src_mac_addr_mid[1] =  port->data_src_addr[2];
379619c5cb6SVlad Zolotarov 	enbl_req.src_mac_addr_hi[0] =  port->data_src_addr[1];
380619c5cb6SVlad Zolotarov 	enbl_req.src_mac_addr_hi[1] =  port->data_src_addr[0];
381619c5cb6SVlad Zolotarov 	memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
382853e2bd2SBhanu Gollapudi 
383fd8f8902SRobert Love 	enbl_req.dst_mac_addr_lo[0] =  ctlr->dest_addr[5];
384fd8f8902SRobert Love 	enbl_req.dst_mac_addr_lo[1] =  ctlr->dest_addr[4];
385fd8f8902SRobert Love 	enbl_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
386fd8f8902SRobert Love 	enbl_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
387fd8f8902SRobert Love 	enbl_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
388fd8f8902SRobert Love 	enbl_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
389853e2bd2SBhanu Gollapudi 
390853e2bd2SBhanu Gollapudi 	port_id = fc_host_port_id(lport->host);
391853e2bd2SBhanu Gollapudi 	if (port_id != tgt->sid) {
392853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
393853e2bd2SBhanu Gollapudi 				"sid = 0x%x\n", port_id, tgt->sid);
394853e2bd2SBhanu Gollapudi 		port_id = tgt->sid;
395853e2bd2SBhanu Gollapudi 	}
396853e2bd2SBhanu Gollapudi 	enbl_req.s_id[0] = (port_id & 0x000000FF);
397853e2bd2SBhanu Gollapudi 	enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
398853e2bd2SBhanu Gollapudi 	enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
399853e2bd2SBhanu Gollapudi 
400853e2bd2SBhanu Gollapudi 	port_id = rport->port_id;
401853e2bd2SBhanu Gollapudi 	enbl_req.d_id[0] = (port_id & 0x000000FF);
402853e2bd2SBhanu Gollapudi 	enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
403853e2bd2SBhanu Gollapudi 	enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
404aea71a02SBhanu Prakash Gollapudi 	enbl_req.vlan_tag = interface->vlan_id <<
405853e2bd2SBhanu Gollapudi 				FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
406853e2bd2SBhanu Gollapudi 	enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
407aea71a02SBhanu Prakash Gollapudi 	enbl_req.vlan_flag = interface->vlan_enabled;
408853e2bd2SBhanu Gollapudi 	enbl_req.context_id = tgt->context_id;
409853e2bd2SBhanu Gollapudi 	enbl_req.conn_id = tgt->fcoe_conn_id;
410853e2bd2SBhanu Gollapudi 
411853e2bd2SBhanu Gollapudi 	kwqe_arr[0] = (struct kwqe *) &enbl_req;
412853e2bd2SBhanu Gollapudi 
413853e2bd2SBhanu Gollapudi 	if (hba->cnic && hba->cnic->submit_kwqes)
414853e2bd2SBhanu Gollapudi 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
415853e2bd2SBhanu Gollapudi 	return rc;
416853e2bd2SBhanu Gollapudi }
417853e2bd2SBhanu Gollapudi 
418853e2bd2SBhanu Gollapudi /**
419853e2bd2SBhanu Gollapudi  * bnx2fc_send_session_disable_req - initiates FCoE Session disable
420853e2bd2SBhanu Gollapudi  *
421853e2bd2SBhanu Gollapudi  * @port:		port structure pointer
422853e2bd2SBhanu Gollapudi  * @tgt:		bnx2fc_rport structure pointer
423853e2bd2SBhanu Gollapudi  */
424853e2bd2SBhanu Gollapudi int bnx2fc_send_session_disable_req(struct fcoe_port *port,
425853e2bd2SBhanu Gollapudi 				    struct bnx2fc_rport *tgt)
426853e2bd2SBhanu Gollapudi {
427aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = port->priv;
428fd8f8902SRobert Love 	struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
429aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_hba *hba = interface->hba;
430853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_conn_enable_disable disable_req;
431853e2bd2SBhanu Gollapudi 	struct kwqe *kwqe_arr[2];
432853e2bd2SBhanu Gollapudi 	struct fc_rport *rport = tgt->rport;
433853e2bd2SBhanu Gollapudi 	int num_kwqes = 1;
434853e2bd2SBhanu Gollapudi 	int rc = 0;
435853e2bd2SBhanu Gollapudi 	u32 port_id;
436853e2bd2SBhanu Gollapudi 
437853e2bd2SBhanu Gollapudi 	memset(&disable_req, 0x00,
438853e2bd2SBhanu Gollapudi 	       sizeof(struct fcoe_kwqe_conn_enable_disable));
439853e2bd2SBhanu Gollapudi 	disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
440853e2bd2SBhanu Gollapudi 	disable_req.hdr.flags =
441853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
442853e2bd2SBhanu Gollapudi 
443619c5cb6SVlad Zolotarov 	disable_req.src_mac_addr_lo[0] =  tgt->src_addr[5];
444619c5cb6SVlad Zolotarov 	disable_req.src_mac_addr_lo[1] =  tgt->src_addr[4];
445619c5cb6SVlad Zolotarov 	disable_req.src_mac_addr_mid[0] =  tgt->src_addr[3];
446619c5cb6SVlad Zolotarov 	disable_req.src_mac_addr_mid[1] =  tgt->src_addr[2];
447619c5cb6SVlad Zolotarov 	disable_req.src_mac_addr_hi[0] =  tgt->src_addr[1];
448619c5cb6SVlad Zolotarov 	disable_req.src_mac_addr_hi[1] =  tgt->src_addr[0];
449853e2bd2SBhanu Gollapudi 
450fd8f8902SRobert Love 	disable_req.dst_mac_addr_lo[0] =  ctlr->dest_addr[5];
451fd8f8902SRobert Love 	disable_req.dst_mac_addr_lo[1] =  ctlr->dest_addr[4];
452fd8f8902SRobert Love 	disable_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
453fd8f8902SRobert Love 	disable_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
454fd8f8902SRobert Love 	disable_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
455fd8f8902SRobert Love 	disable_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
456853e2bd2SBhanu Gollapudi 
457853e2bd2SBhanu Gollapudi 	port_id = tgt->sid;
458853e2bd2SBhanu Gollapudi 	disable_req.s_id[0] = (port_id & 0x000000FF);
459853e2bd2SBhanu Gollapudi 	disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
460853e2bd2SBhanu Gollapudi 	disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
461853e2bd2SBhanu Gollapudi 
462853e2bd2SBhanu Gollapudi 
463853e2bd2SBhanu Gollapudi 	port_id = rport->port_id;
464853e2bd2SBhanu Gollapudi 	disable_req.d_id[0] = (port_id & 0x000000FF);
465853e2bd2SBhanu Gollapudi 	disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
466853e2bd2SBhanu Gollapudi 	disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
467853e2bd2SBhanu Gollapudi 	disable_req.context_id = tgt->context_id;
468853e2bd2SBhanu Gollapudi 	disable_req.conn_id = tgt->fcoe_conn_id;
469aea71a02SBhanu Prakash Gollapudi 	disable_req.vlan_tag = interface->vlan_id <<
470853e2bd2SBhanu Gollapudi 				FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
471853e2bd2SBhanu Gollapudi 	disable_req.vlan_tag |=
472853e2bd2SBhanu Gollapudi 			3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
473aea71a02SBhanu Prakash Gollapudi 	disable_req.vlan_flag = interface->vlan_enabled;
474853e2bd2SBhanu Gollapudi 
475853e2bd2SBhanu Gollapudi 	kwqe_arr[0] = (struct kwqe *) &disable_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 /**
484853e2bd2SBhanu Gollapudi  * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
485853e2bd2SBhanu Gollapudi  *
486853e2bd2SBhanu Gollapudi  * @port:		port structure pointer
487853e2bd2SBhanu Gollapudi  * @tgt:		bnx2fc_rport structure pointer
488853e2bd2SBhanu Gollapudi  */
489853e2bd2SBhanu Gollapudi int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
490853e2bd2SBhanu Gollapudi 					struct bnx2fc_rport *tgt)
491853e2bd2SBhanu Gollapudi {
492853e2bd2SBhanu Gollapudi 	struct fcoe_kwqe_conn_destroy destroy_req;
493853e2bd2SBhanu Gollapudi 	struct kwqe *kwqe_arr[2];
494853e2bd2SBhanu Gollapudi 	int num_kwqes = 1;
495853e2bd2SBhanu Gollapudi 	int rc = 0;
496853e2bd2SBhanu Gollapudi 
497853e2bd2SBhanu Gollapudi 	memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
498853e2bd2SBhanu Gollapudi 	destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
499853e2bd2SBhanu Gollapudi 	destroy_req.hdr.flags =
500853e2bd2SBhanu Gollapudi 		(FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
501853e2bd2SBhanu Gollapudi 
502853e2bd2SBhanu Gollapudi 	destroy_req.context_id = tgt->context_id;
503853e2bd2SBhanu Gollapudi 	destroy_req.conn_id = tgt->fcoe_conn_id;
504853e2bd2SBhanu Gollapudi 
505853e2bd2SBhanu Gollapudi 	kwqe_arr[0] = (struct kwqe *) &destroy_req;
506853e2bd2SBhanu Gollapudi 
507853e2bd2SBhanu Gollapudi 	if (hba->cnic && hba->cnic->submit_kwqes)
508853e2bd2SBhanu Gollapudi 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
509853e2bd2SBhanu Gollapudi 
510853e2bd2SBhanu Gollapudi 	return rc;
511853e2bd2SBhanu Gollapudi }
512853e2bd2SBhanu Gollapudi 
513d36b3279SBhanu Prakash Gollapudi static bool is_valid_lport(struct bnx2fc_hba *hba, struct fc_lport *lport)
514d36b3279SBhanu Prakash Gollapudi {
515d36b3279SBhanu Prakash Gollapudi 	struct bnx2fc_lport *blport;
516d36b3279SBhanu Prakash Gollapudi 
517d36b3279SBhanu Prakash Gollapudi 	spin_lock_bh(&hba->hba_lock);
518d36b3279SBhanu Prakash Gollapudi 	list_for_each_entry(blport, &hba->vports, list) {
519d36b3279SBhanu Prakash Gollapudi 		if (blport->lport == lport) {
520d36b3279SBhanu Prakash Gollapudi 			spin_unlock_bh(&hba->hba_lock);
521d36b3279SBhanu Prakash Gollapudi 			return true;
522d36b3279SBhanu Prakash Gollapudi 		}
523d36b3279SBhanu Prakash Gollapudi 	}
524d36b3279SBhanu Prakash Gollapudi 	spin_unlock_bh(&hba->hba_lock);
525d36b3279SBhanu Prakash Gollapudi 	return false;
526d36b3279SBhanu Prakash Gollapudi 
527d36b3279SBhanu Prakash Gollapudi }
528d36b3279SBhanu Prakash Gollapudi 
529d36b3279SBhanu Prakash Gollapudi 
530853e2bd2SBhanu Gollapudi static void bnx2fc_unsol_els_work(struct work_struct *work)
531853e2bd2SBhanu Gollapudi {
532853e2bd2SBhanu Gollapudi 	struct bnx2fc_unsol_els *unsol_els;
533853e2bd2SBhanu Gollapudi 	struct fc_lport *lport;
534d36b3279SBhanu Prakash Gollapudi 	struct bnx2fc_hba *hba;
535853e2bd2SBhanu Gollapudi 	struct fc_frame *fp;
536853e2bd2SBhanu Gollapudi 
537853e2bd2SBhanu Gollapudi 	unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
538853e2bd2SBhanu Gollapudi 	lport = unsol_els->lport;
539853e2bd2SBhanu Gollapudi 	fp = unsol_els->fp;
540d36b3279SBhanu Prakash Gollapudi 	hba = unsol_els->hba;
541d36b3279SBhanu Prakash Gollapudi 	if (is_valid_lport(hba, lport))
542853e2bd2SBhanu Gollapudi 		fc_exch_recv(lport, fp);
543853e2bd2SBhanu Gollapudi 	kfree(unsol_els);
544853e2bd2SBhanu Gollapudi }
545853e2bd2SBhanu Gollapudi 
546853e2bd2SBhanu Gollapudi void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
547853e2bd2SBhanu Gollapudi 				   unsigned char *buf,
548853e2bd2SBhanu Gollapudi 				   u32 frame_len, u16 l2_oxid)
549853e2bd2SBhanu Gollapudi {
550853e2bd2SBhanu Gollapudi 	struct fcoe_port *port = tgt->port;
551853e2bd2SBhanu Gollapudi 	struct fc_lport *lport = port->lport;
552aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = port->priv;
553853e2bd2SBhanu Gollapudi 	struct bnx2fc_unsol_els *unsol_els;
554853e2bd2SBhanu Gollapudi 	struct fc_frame_header *fh;
555853e2bd2SBhanu Gollapudi 	struct fc_frame *fp;
556853e2bd2SBhanu Gollapudi 	struct sk_buff *skb;
557853e2bd2SBhanu Gollapudi 	u32 payload_len;
558853e2bd2SBhanu Gollapudi 	u32 crc;
559853e2bd2SBhanu Gollapudi 	u8 op;
560853e2bd2SBhanu Gollapudi 
561853e2bd2SBhanu Gollapudi 
562853e2bd2SBhanu Gollapudi 	unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
563853e2bd2SBhanu Gollapudi 	if (!unsol_els) {
564853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
565853e2bd2SBhanu Gollapudi 		return;
566853e2bd2SBhanu Gollapudi 	}
567853e2bd2SBhanu Gollapudi 
568853e2bd2SBhanu Gollapudi 	BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
569853e2bd2SBhanu Gollapudi 		l2_oxid, frame_len);
570853e2bd2SBhanu Gollapudi 
571853e2bd2SBhanu Gollapudi 	payload_len = frame_len - sizeof(struct fc_frame_header);
572853e2bd2SBhanu Gollapudi 
573853e2bd2SBhanu Gollapudi 	fp = fc_frame_alloc(lport, payload_len);
574853e2bd2SBhanu Gollapudi 	if (!fp) {
575853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "fc_frame_alloc failure\n");
5765c2dce26SJulia Lawall 		kfree(unsol_els);
577853e2bd2SBhanu Gollapudi 		return;
578853e2bd2SBhanu Gollapudi 	}
579853e2bd2SBhanu Gollapudi 
580853e2bd2SBhanu Gollapudi 	fh = (struct fc_frame_header *) fc_frame_header_get(fp);
581853e2bd2SBhanu Gollapudi 	/* Copy FC Frame header and payload into the frame */
582853e2bd2SBhanu Gollapudi 	memcpy(fh, buf, frame_len);
583853e2bd2SBhanu Gollapudi 
584853e2bd2SBhanu Gollapudi 	if (l2_oxid != FC_XID_UNKNOWN)
585853e2bd2SBhanu Gollapudi 		fh->fh_ox_id = htons(l2_oxid);
586853e2bd2SBhanu Gollapudi 
587853e2bd2SBhanu Gollapudi 	skb = fp_skb(fp);
588853e2bd2SBhanu Gollapudi 
589853e2bd2SBhanu Gollapudi 	if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
590853e2bd2SBhanu Gollapudi 	    (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
591853e2bd2SBhanu Gollapudi 
592853e2bd2SBhanu Gollapudi 		if (fh->fh_type == FC_TYPE_ELS) {
593853e2bd2SBhanu Gollapudi 			op = fc_frame_payload_op(fp);
594853e2bd2SBhanu Gollapudi 			if ((op == ELS_TEST) ||	(op == ELS_ESTC) ||
595853e2bd2SBhanu Gollapudi 			    (op == ELS_FAN) || (op == ELS_CSU)) {
596853e2bd2SBhanu Gollapudi 				/*
597853e2bd2SBhanu Gollapudi 				 * No need to reply for these
598853e2bd2SBhanu Gollapudi 				 * ELS requests
599853e2bd2SBhanu Gollapudi 				 */
600853e2bd2SBhanu Gollapudi 				printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
601853e2bd2SBhanu Gollapudi 				kfree_skb(skb);
6025c2dce26SJulia Lawall 				kfree(unsol_els);
603853e2bd2SBhanu Gollapudi 				return;
604853e2bd2SBhanu Gollapudi 			}
605853e2bd2SBhanu Gollapudi 		}
606853e2bd2SBhanu Gollapudi 		crc = fcoe_fc_crc(fp);
607853e2bd2SBhanu Gollapudi 		fc_frame_init(fp);
608853e2bd2SBhanu Gollapudi 		fr_dev(fp) = lport;
609853e2bd2SBhanu Gollapudi 		fr_sof(fp) = FC_SOF_I3;
610853e2bd2SBhanu Gollapudi 		fr_eof(fp) = FC_EOF_T;
611853e2bd2SBhanu Gollapudi 		fr_crc(fp) = cpu_to_le32(~crc);
612853e2bd2SBhanu Gollapudi 		unsol_els->lport = lport;
613aea71a02SBhanu Prakash Gollapudi 		unsol_els->hba = interface->hba;
614853e2bd2SBhanu Gollapudi 		unsol_els->fp = fp;
615853e2bd2SBhanu Gollapudi 		INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
616853e2bd2SBhanu Gollapudi 		queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
617853e2bd2SBhanu Gollapudi 	} else {
618853e2bd2SBhanu Gollapudi 		BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
619853e2bd2SBhanu Gollapudi 		kfree_skb(skb);
6205c2dce26SJulia Lawall 		kfree(unsol_els);
621853e2bd2SBhanu Gollapudi 	}
622853e2bd2SBhanu Gollapudi }
623853e2bd2SBhanu Gollapudi 
624853e2bd2SBhanu Gollapudi static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
625853e2bd2SBhanu Gollapudi {
626853e2bd2SBhanu Gollapudi 	u8 num_rq;
627853e2bd2SBhanu Gollapudi 	struct fcoe_err_report_entry *err_entry;
628853e2bd2SBhanu Gollapudi 	unsigned char *rq_data;
629853e2bd2SBhanu Gollapudi 	unsigned char *buf = NULL, *buf1;
630853e2bd2SBhanu Gollapudi 	int i;
631853e2bd2SBhanu Gollapudi 	u16 xid;
632853e2bd2SBhanu Gollapudi 	u32 frame_len, len;
633853e2bd2SBhanu Gollapudi 	struct bnx2fc_cmd *io_req = NULL;
634853e2bd2SBhanu Gollapudi 	struct fcoe_task_ctx_entry *task, *task_page;
635aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = tgt->port->priv;
636aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_hba *hba = interface->hba;
637853e2bd2SBhanu Gollapudi 	int task_idx, index;
638853e2bd2SBhanu Gollapudi 	int rc = 0;
6397b594769SBhanu Prakash Gollapudi 	u64 err_warn_bit_map;
6407b594769SBhanu Prakash Gollapudi 	u8 err_warn = 0xff;
641853e2bd2SBhanu Gollapudi 
642853e2bd2SBhanu Gollapudi 
643853e2bd2SBhanu Gollapudi 	BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe);
644853e2bd2SBhanu Gollapudi 	switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) {
645853e2bd2SBhanu Gollapudi 	case FCOE_UNSOLICITED_FRAME_CQE_TYPE:
646853e2bd2SBhanu Gollapudi 		frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >>
647853e2bd2SBhanu Gollapudi 			     FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT;
648853e2bd2SBhanu Gollapudi 
649853e2bd2SBhanu Gollapudi 		num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ;
650853e2bd2SBhanu Gollapudi 
65168695973SNithin Sujir 		spin_lock_bh(&tgt->tgt_lock);
652853e2bd2SBhanu Gollapudi 		rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq);
65368695973SNithin Sujir 		spin_unlock_bh(&tgt->tgt_lock);
65468695973SNithin Sujir 
655853e2bd2SBhanu Gollapudi 		if (rq_data) {
656853e2bd2SBhanu Gollapudi 			buf = rq_data;
657853e2bd2SBhanu Gollapudi 		} else {
658853e2bd2SBhanu Gollapudi 			buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
659853e2bd2SBhanu Gollapudi 					      GFP_ATOMIC);
660853e2bd2SBhanu Gollapudi 
661853e2bd2SBhanu Gollapudi 			if (!buf1) {
662853e2bd2SBhanu Gollapudi 				BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
663853e2bd2SBhanu Gollapudi 				break;
664853e2bd2SBhanu Gollapudi 			}
665853e2bd2SBhanu Gollapudi 
666853e2bd2SBhanu Gollapudi 			for (i = 0; i < num_rq; i++) {
66768695973SNithin Sujir 				spin_lock_bh(&tgt->tgt_lock);
668853e2bd2SBhanu Gollapudi 				rq_data = (unsigned char *)
669853e2bd2SBhanu Gollapudi 					   bnx2fc_get_next_rqe(tgt, 1);
67068695973SNithin Sujir 				spin_unlock_bh(&tgt->tgt_lock);
671853e2bd2SBhanu Gollapudi 				len = BNX2FC_RQ_BUF_SZ;
672853e2bd2SBhanu Gollapudi 				memcpy(buf1, rq_data, len);
673853e2bd2SBhanu Gollapudi 				buf1 += len;
674853e2bd2SBhanu Gollapudi 			}
675853e2bd2SBhanu Gollapudi 		}
676853e2bd2SBhanu Gollapudi 		bnx2fc_process_l2_frame_compl(tgt, buf, frame_len,
677853e2bd2SBhanu Gollapudi 					      FC_XID_UNKNOWN);
678853e2bd2SBhanu Gollapudi 
679853e2bd2SBhanu Gollapudi 		if (buf != rq_data)
680853e2bd2SBhanu Gollapudi 			kfree(buf);
68168695973SNithin Sujir 		spin_lock_bh(&tgt->tgt_lock);
682853e2bd2SBhanu Gollapudi 		bnx2fc_return_rqe(tgt, num_rq);
68368695973SNithin Sujir 		spin_unlock_bh(&tgt->tgt_lock);
684853e2bd2SBhanu Gollapudi 		break;
685853e2bd2SBhanu Gollapudi 
686853e2bd2SBhanu Gollapudi 	case FCOE_ERROR_DETECTION_CQE_TYPE:
687853e2bd2SBhanu Gollapudi 		/*
688853e2bd2SBhanu Gollapudi 		 * In case of error reporting CQE a single RQ entry
68968695973SNithin Sujir 		 * is consumed.
690853e2bd2SBhanu Gollapudi 		 */
691853e2bd2SBhanu Gollapudi 		spin_lock_bh(&tgt->tgt_lock);
692853e2bd2SBhanu Gollapudi 		num_rq = 1;
693853e2bd2SBhanu Gollapudi 		err_entry = (struct fcoe_err_report_entry *)
694853e2bd2SBhanu Gollapudi 			     bnx2fc_get_next_rqe(tgt, 1);
695853e2bd2SBhanu Gollapudi 		xid = err_entry->fc_hdr.ox_id;
696853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid);
697853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n",
698619c5cb6SVlad Zolotarov 			err_entry->data.err_warn_bitmap_hi,
699619c5cb6SVlad Zolotarov 			err_entry->data.err_warn_bitmap_lo);
700853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n",
701619c5cb6SVlad Zolotarov 			err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
702853e2bd2SBhanu Gollapudi 
703853e2bd2SBhanu Gollapudi 
7040eb43b4bSBhanu Prakash Gollapudi 		if (xid > hba->max_xid) {
705853e2bd2SBhanu Gollapudi 			BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
706853e2bd2SBhanu Gollapudi 				   xid);
7077b594769SBhanu Prakash Gollapudi 			goto ret_err_rqe;
708853e2bd2SBhanu Gollapudi 		}
709853e2bd2SBhanu Gollapudi 
710853e2bd2SBhanu Gollapudi 		task_idx = xid / BNX2FC_TASKS_PER_PAGE;
711853e2bd2SBhanu Gollapudi 		index = xid % BNX2FC_TASKS_PER_PAGE;
712853e2bd2SBhanu Gollapudi 		task_page = (struct fcoe_task_ctx_entry *)
713853e2bd2SBhanu Gollapudi 					hba->task_ctx[task_idx];
714853e2bd2SBhanu Gollapudi 		task = &(task_page[index]);
715853e2bd2SBhanu Gollapudi 
716853e2bd2SBhanu Gollapudi 		io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
7177b594769SBhanu Prakash Gollapudi 		if (!io_req)
7187b594769SBhanu Prakash Gollapudi 			goto ret_err_rqe;
719853e2bd2SBhanu Gollapudi 
720853e2bd2SBhanu Gollapudi 		if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
721853e2bd2SBhanu Gollapudi 			printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
7227b594769SBhanu Prakash Gollapudi 			goto ret_err_rqe;
723853e2bd2SBhanu Gollapudi 		}
724853e2bd2SBhanu Gollapudi 
725853e2bd2SBhanu Gollapudi 		if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
726853e2bd2SBhanu Gollapudi 				       &io_req->req_flags)) {
727853e2bd2SBhanu Gollapudi 			BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
728853e2bd2SBhanu Gollapudi 					    "progress.. ignore unsol err\n");
7297b594769SBhanu Prakash Gollapudi 			goto ret_err_rqe;
7307b594769SBhanu Prakash Gollapudi 		}
7317b594769SBhanu Prakash Gollapudi 
7327b594769SBhanu Prakash Gollapudi 		err_warn_bit_map = (u64)
7337b594769SBhanu Prakash Gollapudi 			((u64)err_entry->data.err_warn_bitmap_hi << 32) |
7347b594769SBhanu Prakash Gollapudi 			(u64)err_entry->data.err_warn_bitmap_lo;
7357b594769SBhanu Prakash Gollapudi 		for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
7367b594769SBhanu Prakash Gollapudi 			if (err_warn_bit_map & (u64)((u64)1 << i)) {
7377b594769SBhanu Prakash Gollapudi 				err_warn = i;
738853e2bd2SBhanu Gollapudi 				break;
739853e2bd2SBhanu Gollapudi 			}
7407b594769SBhanu Prakash Gollapudi 		}
741853e2bd2SBhanu Gollapudi 
742853e2bd2SBhanu Gollapudi 		/*
743853e2bd2SBhanu Gollapudi 		 * If ABTS is already in progress, and FW error is
744853e2bd2SBhanu Gollapudi 		 * received after that, do not cancel the timeout_work
745853e2bd2SBhanu Gollapudi 		 * and let the error recovery continue by explicitly
746853e2bd2SBhanu Gollapudi 		 * logging out the target, when the ABTS eventually
747853e2bd2SBhanu Gollapudi 		 * times out.
748853e2bd2SBhanu Gollapudi 		 */
7497b594769SBhanu Prakash Gollapudi 		if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
7507b594769SBhanu Prakash Gollapudi 			printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
7517b594769SBhanu Prakash Gollapudi 					    "in ABTS processing\n", xid);
7527b594769SBhanu Prakash Gollapudi 			goto ret_err_rqe;
7537b594769SBhanu Prakash Gollapudi 		}
7547b594769SBhanu Prakash Gollapudi 		BNX2FC_TGT_DBG(tgt, "err = 0x%x\n", err_warn);
7557b594769SBhanu Prakash Gollapudi 		if (tgt->dev_type != TYPE_TAPE)
7567b594769SBhanu Prakash Gollapudi 			goto skip_rec;
7577b594769SBhanu Prakash Gollapudi 		switch (err_warn) {
7587b594769SBhanu Prakash Gollapudi 		case FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION:
7597b594769SBhanu Prakash Gollapudi 		case FCOE_ERROR_CODE_DATA_OOO_RO:
7607b594769SBhanu Prakash Gollapudi 		case FCOE_ERROR_CODE_COMMON_INCORRECT_SEQ_CNT:
7617b594769SBhanu Prakash Gollapudi 		case FCOE_ERROR_CODE_DATA_SOFI3_SEQ_ACTIVE_SET:
7627b594769SBhanu Prakash Gollapudi 		case FCOE_ERROR_CODE_FCP_RSP_OPENED_SEQ:
7637b594769SBhanu Prakash Gollapudi 		case FCOE_ERROR_CODE_DATA_SOFN_SEQ_ACTIVE_RESET:
7647b594769SBhanu Prakash Gollapudi 			BNX2FC_TGT_DBG(tgt, "REC TOV popped for xid - 0x%x\n",
7657b594769SBhanu Prakash Gollapudi 				   xid);
7667b594769SBhanu Prakash Gollapudi 			memcpy(&io_req->err_entry, err_entry,
7677b594769SBhanu Prakash Gollapudi 			       sizeof(struct fcoe_err_report_entry));
7687b594769SBhanu Prakash Gollapudi 			if (!test_bit(BNX2FC_FLAG_SRR_SENT,
769853e2bd2SBhanu Gollapudi 				      &io_req->req_flags)) {
7707b594769SBhanu Prakash Gollapudi 				spin_unlock_bh(&tgt->tgt_lock);
7717b594769SBhanu Prakash Gollapudi 				rc = bnx2fc_send_rec(io_req);
7727b594769SBhanu Prakash Gollapudi 				spin_lock_bh(&tgt->tgt_lock);
7737b594769SBhanu Prakash Gollapudi 
7747b594769SBhanu Prakash Gollapudi 				if (rc)
7757b594769SBhanu Prakash Gollapudi 					goto skip_rec;
7767b594769SBhanu Prakash Gollapudi 			} else
7777b594769SBhanu Prakash Gollapudi 				printk(KERN_ERR PFX "SRR in progress\n");
7787b594769SBhanu Prakash Gollapudi 			goto ret_err_rqe;
7797b594769SBhanu Prakash Gollapudi 			break;
7807b594769SBhanu Prakash Gollapudi 		default:
7817b594769SBhanu Prakash Gollapudi 			break;
7827b594769SBhanu Prakash Gollapudi 		}
7837b594769SBhanu Prakash Gollapudi 
7847b594769SBhanu Prakash Gollapudi skip_rec:
7857b594769SBhanu Prakash Gollapudi 		set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags);
786853e2bd2SBhanu Gollapudi 		/*
787853e2bd2SBhanu Gollapudi 		 * Cancel the timeout_work, as we received IO
788853e2bd2SBhanu Gollapudi 		 * completion with FW error.
789853e2bd2SBhanu Gollapudi 		 */
790853e2bd2SBhanu Gollapudi 		if (cancel_delayed_work(&io_req->timeout_work))
7917b594769SBhanu Prakash Gollapudi 			kref_put(&io_req->refcount, bnx2fc_cmd_release);
792853e2bd2SBhanu Gollapudi 
793853e2bd2SBhanu Gollapudi 		rc = bnx2fc_initiate_abts(io_req);
794853e2bd2SBhanu Gollapudi 		if (rc != SUCCESS) {
7957b594769SBhanu Prakash Gollapudi 			printk(KERN_ERR PFX "err_warn: initiate_abts "
7967b594769SBhanu Prakash Gollapudi 				"failed xid = 0x%x. issue cleanup\n",
7977b594769SBhanu Prakash Gollapudi 				io_req->xid);
7987b594769SBhanu Prakash Gollapudi 			bnx2fc_initiate_cleanup(io_req);
799853e2bd2SBhanu Gollapudi 		}
8007b594769SBhanu Prakash Gollapudi ret_err_rqe:
8017b594769SBhanu Prakash Gollapudi 		bnx2fc_return_rqe(tgt, 1);
802853e2bd2SBhanu Gollapudi 		spin_unlock_bh(&tgt->tgt_lock);
803853e2bd2SBhanu Gollapudi 		break;
804853e2bd2SBhanu Gollapudi 
805853e2bd2SBhanu Gollapudi 	case FCOE_WARNING_DETECTION_CQE_TYPE:
806853e2bd2SBhanu Gollapudi 		/*
807853e2bd2SBhanu Gollapudi 		 *In case of warning reporting CQE a single RQ entry
808853e2bd2SBhanu Gollapudi 		 * is consumes.
809853e2bd2SBhanu Gollapudi 		 */
81068695973SNithin Sujir 		spin_lock_bh(&tgt->tgt_lock);
811853e2bd2SBhanu Gollapudi 		num_rq = 1;
812853e2bd2SBhanu Gollapudi 		err_entry = (struct fcoe_err_report_entry *)
813853e2bd2SBhanu Gollapudi 			     bnx2fc_get_next_rqe(tgt, 1);
814853e2bd2SBhanu Gollapudi 		xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
815853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
816853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
817619c5cb6SVlad Zolotarov 			err_entry->data.err_warn_bitmap_hi,
818619c5cb6SVlad Zolotarov 			err_entry->data.err_warn_bitmap_lo);
819853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
820619c5cb6SVlad Zolotarov 			err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
821853e2bd2SBhanu Gollapudi 
8220eb43b4bSBhanu Prakash Gollapudi 		if (xid > hba->max_xid) {
8237b594769SBhanu Prakash Gollapudi 			BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", xid);
8247b594769SBhanu Prakash Gollapudi 			goto ret_warn_rqe;
8257b594769SBhanu Prakash Gollapudi 		}
8267b594769SBhanu Prakash Gollapudi 
8277b594769SBhanu Prakash Gollapudi 		err_warn_bit_map = (u64)
8287b594769SBhanu Prakash Gollapudi 			((u64)err_entry->data.err_warn_bitmap_hi << 32) |
8297b594769SBhanu Prakash Gollapudi 			(u64)err_entry->data.err_warn_bitmap_lo;
8307b594769SBhanu Prakash Gollapudi 		for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
8317b594769SBhanu Prakash Gollapudi 			if (err_warn_bit_map & (u64) (1 << i)) {
8327b594769SBhanu Prakash Gollapudi 				err_warn = i;
8337b594769SBhanu Prakash Gollapudi 				break;
8347b594769SBhanu Prakash Gollapudi 			}
8357b594769SBhanu Prakash Gollapudi 		}
8367b594769SBhanu Prakash Gollapudi 		BNX2FC_TGT_DBG(tgt, "warn = 0x%x\n", err_warn);
8377b594769SBhanu Prakash Gollapudi 
8387b594769SBhanu Prakash Gollapudi 		task_idx = xid / BNX2FC_TASKS_PER_PAGE;
8397b594769SBhanu Prakash Gollapudi 		index = xid % BNX2FC_TASKS_PER_PAGE;
8407b594769SBhanu Prakash Gollapudi 		task_page = (struct fcoe_task_ctx_entry *)
8417b594769SBhanu Prakash Gollapudi 			     interface->hba->task_ctx[task_idx];
8427b594769SBhanu Prakash Gollapudi 		task = &(task_page[index]);
8437b594769SBhanu Prakash Gollapudi 		io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
8447b594769SBhanu Prakash Gollapudi 		if (!io_req)
8457b594769SBhanu Prakash Gollapudi 			goto ret_warn_rqe;
8467b594769SBhanu Prakash Gollapudi 
8477b594769SBhanu Prakash Gollapudi 		if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
8487b594769SBhanu Prakash Gollapudi 			printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
8497b594769SBhanu Prakash Gollapudi 			goto ret_warn_rqe;
8507b594769SBhanu Prakash Gollapudi 		}
8517b594769SBhanu Prakash Gollapudi 
8527b594769SBhanu Prakash Gollapudi 		memcpy(&io_req->err_entry, err_entry,
8537b594769SBhanu Prakash Gollapudi 		       sizeof(struct fcoe_err_report_entry));
8547b594769SBhanu Prakash Gollapudi 
8557b594769SBhanu Prakash Gollapudi 		if (err_warn == FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION)
8567b594769SBhanu Prakash Gollapudi 			/* REC_TOV is not a warning code */
8577b594769SBhanu Prakash Gollapudi 			BUG_ON(1);
8587b594769SBhanu Prakash Gollapudi 		else
8597b594769SBhanu Prakash Gollapudi 			BNX2FC_TGT_DBG(tgt, "Unsolicited warning\n");
8607b594769SBhanu Prakash Gollapudi ret_warn_rqe:
861853e2bd2SBhanu Gollapudi 		bnx2fc_return_rqe(tgt, 1);
86268695973SNithin Sujir 		spin_unlock_bh(&tgt->tgt_lock);
863853e2bd2SBhanu Gollapudi 		break;
864853e2bd2SBhanu Gollapudi 
865853e2bd2SBhanu Gollapudi 	default:
866853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
867853e2bd2SBhanu Gollapudi 		break;
868853e2bd2SBhanu Gollapudi 	}
869853e2bd2SBhanu Gollapudi }
870853e2bd2SBhanu Gollapudi 
871853e2bd2SBhanu Gollapudi void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
872853e2bd2SBhanu Gollapudi {
873853e2bd2SBhanu Gollapudi 	struct fcoe_task_ctx_entry *task;
874853e2bd2SBhanu Gollapudi 	struct fcoe_task_ctx_entry *task_page;
875853e2bd2SBhanu Gollapudi 	struct fcoe_port *port = tgt->port;
876aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = port->priv;
877aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_hba *hba = interface->hba;
878853e2bd2SBhanu Gollapudi 	struct bnx2fc_cmd *io_req;
879853e2bd2SBhanu Gollapudi 	int task_idx, index;
880853e2bd2SBhanu Gollapudi 	u16 xid;
881853e2bd2SBhanu Gollapudi 	u8  cmd_type;
882853e2bd2SBhanu Gollapudi 	u8 rx_state = 0;
883853e2bd2SBhanu Gollapudi 	u8 num_rq;
884853e2bd2SBhanu Gollapudi 
885853e2bd2SBhanu Gollapudi 	spin_lock_bh(&tgt->tgt_lock);
886853e2bd2SBhanu Gollapudi 	xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
8870eb43b4bSBhanu Prakash Gollapudi 	if (xid >= hba->max_tasks) {
888b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "ERROR:xid out of range\n");
889853e2bd2SBhanu Gollapudi 		spin_unlock_bh(&tgt->tgt_lock);
890853e2bd2SBhanu Gollapudi 		return;
891853e2bd2SBhanu Gollapudi 	}
892853e2bd2SBhanu Gollapudi 	task_idx = xid / BNX2FC_TASKS_PER_PAGE;
893853e2bd2SBhanu Gollapudi 	index = xid % BNX2FC_TASKS_PER_PAGE;
894853e2bd2SBhanu Gollapudi 	task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
895853e2bd2SBhanu Gollapudi 	task = &(task_page[index]);
896853e2bd2SBhanu Gollapudi 
897619c5cb6SVlad Zolotarov 	num_rq = ((task->rxwr_txrd.var_ctx.rx_flags &
898619c5cb6SVlad Zolotarov 		   FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE) >>
899619c5cb6SVlad Zolotarov 		   FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE_SHIFT);
900853e2bd2SBhanu Gollapudi 
901853e2bd2SBhanu Gollapudi 	io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
902853e2bd2SBhanu Gollapudi 
903853e2bd2SBhanu Gollapudi 	if (io_req == NULL) {
904853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
905853e2bd2SBhanu Gollapudi 		spin_unlock_bh(&tgt->tgt_lock);
906853e2bd2SBhanu Gollapudi 		return;
907853e2bd2SBhanu Gollapudi 	}
908853e2bd2SBhanu Gollapudi 
909853e2bd2SBhanu Gollapudi 	/* Timestamp IO completion time */
910853e2bd2SBhanu Gollapudi 	cmd_type = io_req->cmd_type;
911853e2bd2SBhanu Gollapudi 
912619c5cb6SVlad Zolotarov 	rx_state = ((task->rxwr_txrd.var_ctx.rx_flags &
913619c5cb6SVlad Zolotarov 		    FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE) >>
914619c5cb6SVlad Zolotarov 		    FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE_SHIFT);
915853e2bd2SBhanu Gollapudi 
916619c5cb6SVlad Zolotarov 	/* Process other IO completion types */
917619c5cb6SVlad Zolotarov 	switch (cmd_type) {
918619c5cb6SVlad Zolotarov 	case BNX2FC_SCSI_CMD:
919853e2bd2SBhanu Gollapudi 		if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
920853e2bd2SBhanu Gollapudi 			bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq);
921853e2bd2SBhanu Gollapudi 			spin_unlock_bh(&tgt->tgt_lock);
922853e2bd2SBhanu Gollapudi 			return;
923853e2bd2SBhanu Gollapudi 		}
924853e2bd2SBhanu Gollapudi 
925853e2bd2SBhanu Gollapudi 		if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
926853e2bd2SBhanu Gollapudi 			bnx2fc_process_abts_compl(io_req, task, num_rq);
927853e2bd2SBhanu Gollapudi 		else if (rx_state ==
928853e2bd2SBhanu Gollapudi 			 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
929853e2bd2SBhanu Gollapudi 			bnx2fc_process_cleanup_compl(io_req, task, num_rq);
930853e2bd2SBhanu Gollapudi 		else
931853e2bd2SBhanu Gollapudi 			printk(KERN_ERR PFX "Invalid rx state - %d\n",
932853e2bd2SBhanu Gollapudi 				rx_state);
933853e2bd2SBhanu Gollapudi 		break;
934853e2bd2SBhanu Gollapudi 
935853e2bd2SBhanu Gollapudi 	case BNX2FC_TASK_MGMT_CMD:
936853e2bd2SBhanu Gollapudi 		BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
937853e2bd2SBhanu Gollapudi 		bnx2fc_process_tm_compl(io_req, task, num_rq);
938853e2bd2SBhanu Gollapudi 		break;
939853e2bd2SBhanu Gollapudi 
940853e2bd2SBhanu Gollapudi 	case BNX2FC_ABTS:
941853e2bd2SBhanu Gollapudi 		/*
942853e2bd2SBhanu Gollapudi 		 * ABTS request received by firmware. ABTS response
943853e2bd2SBhanu Gollapudi 		 * will be delivered to the task belonging to the IO
944853e2bd2SBhanu Gollapudi 		 * that was aborted
945853e2bd2SBhanu Gollapudi 		 */
946853e2bd2SBhanu Gollapudi 		BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
947853e2bd2SBhanu Gollapudi 		kref_put(&io_req->refcount, bnx2fc_cmd_release);
948853e2bd2SBhanu Gollapudi 		break;
949853e2bd2SBhanu Gollapudi 
950853e2bd2SBhanu Gollapudi 	case BNX2FC_ELS:
951619c5cb6SVlad Zolotarov 		if (rx_state == FCOE_TASK_RX_STATE_COMPLETED)
952853e2bd2SBhanu Gollapudi 			bnx2fc_process_els_compl(io_req, task, num_rq);
953619c5cb6SVlad Zolotarov 		else if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
954619c5cb6SVlad Zolotarov 			bnx2fc_process_abts_compl(io_req, task, num_rq);
955619c5cb6SVlad Zolotarov 		else if (rx_state ==
956619c5cb6SVlad Zolotarov 			 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
957619c5cb6SVlad Zolotarov 			bnx2fc_process_cleanup_compl(io_req, task, num_rq);
958619c5cb6SVlad Zolotarov 		else
959619c5cb6SVlad Zolotarov 			printk(KERN_ERR PFX "Invalid rx state =  %d\n",
960619c5cb6SVlad Zolotarov 				rx_state);
961853e2bd2SBhanu Gollapudi 		break;
962853e2bd2SBhanu Gollapudi 
963853e2bd2SBhanu Gollapudi 	case BNX2FC_CLEANUP:
964853e2bd2SBhanu Gollapudi 		BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
965853e2bd2SBhanu Gollapudi 		kref_put(&io_req->refcount, bnx2fc_cmd_release);
966853e2bd2SBhanu Gollapudi 		break;
967853e2bd2SBhanu Gollapudi 
9686c5a7ce4SBhanu Prakash Gollapudi 	case BNX2FC_SEQ_CLEANUP:
9696c5a7ce4SBhanu Prakash Gollapudi 		BNX2FC_IO_DBG(io_req, "cq_compl(0x%x) - seq cleanup resp\n",
9706c5a7ce4SBhanu Prakash Gollapudi 			      io_req->xid);
9716c5a7ce4SBhanu Prakash Gollapudi 		bnx2fc_process_seq_cleanup_compl(io_req, task, rx_state);
9726c5a7ce4SBhanu Prakash Gollapudi 		kref_put(&io_req->refcount, bnx2fc_cmd_release);
9736c5a7ce4SBhanu Prakash Gollapudi 		break;
9746c5a7ce4SBhanu Prakash Gollapudi 
975853e2bd2SBhanu Gollapudi 	default:
976853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
977853e2bd2SBhanu Gollapudi 		break;
978853e2bd2SBhanu Gollapudi 	}
979853e2bd2SBhanu Gollapudi 	spin_unlock_bh(&tgt->tgt_lock);
980853e2bd2SBhanu Gollapudi }
981853e2bd2SBhanu Gollapudi 
982619c5cb6SVlad Zolotarov void bnx2fc_arm_cq(struct bnx2fc_rport *tgt)
983619c5cb6SVlad Zolotarov {
984619c5cb6SVlad Zolotarov 	struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
985619c5cb6SVlad Zolotarov 	u32 msg;
986619c5cb6SVlad Zolotarov 
987619c5cb6SVlad Zolotarov 	wmb();
988619c5cb6SVlad Zolotarov 	rx_db->doorbell_cq_cons = tgt->cq_cons_idx | (tgt->cq_curr_toggle_bit <<
989619c5cb6SVlad Zolotarov 			FCOE_CQE_TOGGLE_BIT_SHIFT);
990619c5cb6SVlad Zolotarov 	msg = *((u32 *)rx_db);
991619c5cb6SVlad Zolotarov 	writel(cpu_to_le32(msg), tgt->ctx_base);
992619c5cb6SVlad Zolotarov 	mmiowb();
993619c5cb6SVlad Zolotarov 
994619c5cb6SVlad Zolotarov }
995619c5cb6SVlad Zolotarov 
996853e2bd2SBhanu Gollapudi struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe)
997853e2bd2SBhanu Gollapudi {
998853e2bd2SBhanu Gollapudi 	struct bnx2fc_work *work;
999853e2bd2SBhanu Gollapudi 	work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
1000853e2bd2SBhanu Gollapudi 	if (!work)
1001853e2bd2SBhanu Gollapudi 		return NULL;
1002853e2bd2SBhanu Gollapudi 
1003853e2bd2SBhanu Gollapudi 	INIT_LIST_HEAD(&work->list);
1004853e2bd2SBhanu Gollapudi 	work->tgt = tgt;
1005853e2bd2SBhanu Gollapudi 	work->wqe = wqe;
1006853e2bd2SBhanu Gollapudi 	return work;
1007853e2bd2SBhanu Gollapudi }
1008853e2bd2SBhanu Gollapudi 
1009853e2bd2SBhanu Gollapudi int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
1010853e2bd2SBhanu Gollapudi {
1011853e2bd2SBhanu Gollapudi 	struct fcoe_cqe *cq;
1012853e2bd2SBhanu Gollapudi 	u32 cq_cons;
1013853e2bd2SBhanu Gollapudi 	struct fcoe_cqe *cqe;
1014619c5cb6SVlad Zolotarov 	u32 num_free_sqes = 0;
1015b338c785SBhanu Prakash Gollapudi 	u32 num_cqes = 0;
1016853e2bd2SBhanu Gollapudi 	u16 wqe;
1017853e2bd2SBhanu Gollapudi 
1018853e2bd2SBhanu Gollapudi 	/*
1019853e2bd2SBhanu Gollapudi 	 * cq_lock is a low contention lock used to protect
1020853e2bd2SBhanu Gollapudi 	 * the CQ data structure from being freed up during
1021853e2bd2SBhanu Gollapudi 	 * the upload operation
1022853e2bd2SBhanu Gollapudi 	 */
1023853e2bd2SBhanu Gollapudi 	spin_lock_bh(&tgt->cq_lock);
1024853e2bd2SBhanu Gollapudi 
1025853e2bd2SBhanu Gollapudi 	if (!tgt->cq) {
1026853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
1027853e2bd2SBhanu Gollapudi 		spin_unlock_bh(&tgt->cq_lock);
1028853e2bd2SBhanu Gollapudi 		return 0;
1029853e2bd2SBhanu Gollapudi 	}
1030853e2bd2SBhanu Gollapudi 	cq = tgt->cq;
1031853e2bd2SBhanu Gollapudi 	cq_cons = tgt->cq_cons_idx;
1032853e2bd2SBhanu Gollapudi 	cqe = &cq[cq_cons];
1033853e2bd2SBhanu Gollapudi 
1034853e2bd2SBhanu Gollapudi 	while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
1035853e2bd2SBhanu Gollapudi 	       (tgt->cq_curr_toggle_bit <<
1036853e2bd2SBhanu Gollapudi 	       FCOE_CQE_TOGGLE_BIT_SHIFT)) {
1037853e2bd2SBhanu Gollapudi 
1038853e2bd2SBhanu Gollapudi 		/* new entry on the cq */
1039853e2bd2SBhanu Gollapudi 		if (wqe & FCOE_CQE_CQE_TYPE) {
1040853e2bd2SBhanu Gollapudi 			/* Unsolicited event notification */
1041853e2bd2SBhanu Gollapudi 			bnx2fc_process_unsol_compl(tgt, wqe);
1042853e2bd2SBhanu Gollapudi 		} else {
1043619c5cb6SVlad Zolotarov 			/* Pending work request completion */
1044853e2bd2SBhanu Gollapudi 			struct bnx2fc_work *work = NULL;
1045853e2bd2SBhanu Gollapudi 			struct bnx2fc_percpu_s *fps = NULL;
1046853e2bd2SBhanu Gollapudi 			unsigned int cpu = wqe % num_possible_cpus();
1047853e2bd2SBhanu Gollapudi 
1048853e2bd2SBhanu Gollapudi 			fps = &per_cpu(bnx2fc_percpu, cpu);
1049853e2bd2SBhanu Gollapudi 			spin_lock_bh(&fps->fp_work_lock);
1050853e2bd2SBhanu Gollapudi 			if (unlikely(!fps->iothread))
1051853e2bd2SBhanu Gollapudi 				goto unlock;
1052853e2bd2SBhanu Gollapudi 
1053853e2bd2SBhanu Gollapudi 			work = bnx2fc_alloc_work(tgt, wqe);
1054853e2bd2SBhanu Gollapudi 			if (work)
1055853e2bd2SBhanu Gollapudi 				list_add_tail(&work->list,
1056853e2bd2SBhanu Gollapudi 					      &fps->work_list);
1057853e2bd2SBhanu Gollapudi unlock:
1058853e2bd2SBhanu Gollapudi 			spin_unlock_bh(&fps->fp_work_lock);
1059853e2bd2SBhanu Gollapudi 
1060853e2bd2SBhanu Gollapudi 			/* Pending work request completion */
1061853e2bd2SBhanu Gollapudi 			if (fps->iothread && work)
1062853e2bd2SBhanu Gollapudi 				wake_up_process(fps->iothread);
1063853e2bd2SBhanu Gollapudi 			else
1064853e2bd2SBhanu Gollapudi 				bnx2fc_process_cq_compl(tgt, wqe);
1065b338c785SBhanu Prakash Gollapudi 			num_free_sqes++;
1066853e2bd2SBhanu Gollapudi 		}
1067853e2bd2SBhanu Gollapudi 		cqe++;
1068853e2bd2SBhanu Gollapudi 		tgt->cq_cons_idx++;
1069b338c785SBhanu Prakash Gollapudi 		num_cqes++;
1070853e2bd2SBhanu Gollapudi 
1071853e2bd2SBhanu Gollapudi 		if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
1072853e2bd2SBhanu Gollapudi 			tgt->cq_cons_idx = 0;
1073853e2bd2SBhanu Gollapudi 			cqe = cq;
1074853e2bd2SBhanu Gollapudi 			tgt->cq_curr_toggle_bit =
1075853e2bd2SBhanu Gollapudi 				1 - tgt->cq_curr_toggle_bit;
1076853e2bd2SBhanu Gollapudi 		}
1077853e2bd2SBhanu Gollapudi 	}
1078b338c785SBhanu Prakash Gollapudi 	if (num_cqes) {
1079b338c785SBhanu Prakash Gollapudi 		/* Arm CQ only if doorbell is mapped */
1080b338c785SBhanu Prakash Gollapudi 		if (tgt->ctx_base)
1081619c5cb6SVlad Zolotarov 			bnx2fc_arm_cq(tgt);
1082619c5cb6SVlad Zolotarov 		atomic_add(num_free_sqes, &tgt->free_sqes);
1083fd08bd62SBhanu Prakash Gollapudi 	}
1084853e2bd2SBhanu Gollapudi 	spin_unlock_bh(&tgt->cq_lock);
1085853e2bd2SBhanu Gollapudi 	return 0;
1086853e2bd2SBhanu Gollapudi }
1087853e2bd2SBhanu Gollapudi 
1088853e2bd2SBhanu Gollapudi /**
1089853e2bd2SBhanu Gollapudi  * bnx2fc_fastpath_notification - process global event queue (KCQ)
1090853e2bd2SBhanu Gollapudi  *
1091853e2bd2SBhanu Gollapudi  * @hba:		adapter structure pointer
1092853e2bd2SBhanu Gollapudi  * @new_cqe_kcqe:	pointer to newly DMA'd KCQ entry
1093853e2bd2SBhanu Gollapudi  *
1094853e2bd2SBhanu Gollapudi  * Fast path event notification handler
1095853e2bd2SBhanu Gollapudi  */
1096853e2bd2SBhanu Gollapudi static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
1097853e2bd2SBhanu Gollapudi 					struct fcoe_kcqe *new_cqe_kcqe)
1098853e2bd2SBhanu Gollapudi {
1099853e2bd2SBhanu Gollapudi 	u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
1100853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
1101853e2bd2SBhanu Gollapudi 
1102853e2bd2SBhanu Gollapudi 	if (!tgt) {
1103b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "conn_id 0x%x not valid\n", conn_id);
1104853e2bd2SBhanu Gollapudi 		return;
1105853e2bd2SBhanu Gollapudi 	}
1106853e2bd2SBhanu Gollapudi 
1107853e2bd2SBhanu Gollapudi 	bnx2fc_process_new_cqes(tgt);
1108853e2bd2SBhanu Gollapudi }
1109853e2bd2SBhanu Gollapudi 
1110853e2bd2SBhanu Gollapudi /**
1111853e2bd2SBhanu Gollapudi  * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
1112853e2bd2SBhanu Gollapudi  *
1113853e2bd2SBhanu Gollapudi  * @hba:	adapter structure pointer
1114853e2bd2SBhanu Gollapudi  * @ofld_kcqe:	connection offload kcqe pointer
1115853e2bd2SBhanu Gollapudi  *
1116853e2bd2SBhanu Gollapudi  * handle session offload completion, enable the session if offload is
1117853e2bd2SBhanu Gollapudi  * successful.
1118853e2bd2SBhanu Gollapudi  */
1119853e2bd2SBhanu Gollapudi static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
1120853e2bd2SBhanu Gollapudi 					struct fcoe_kcqe *ofld_kcqe)
1121853e2bd2SBhanu Gollapudi {
1122853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport		*tgt;
1123853e2bd2SBhanu Gollapudi 	struct fcoe_port		*port;
1124aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface		*interface;
1125853e2bd2SBhanu Gollapudi 	u32				conn_id;
1126853e2bd2SBhanu Gollapudi 	u32				context_id;
1127853e2bd2SBhanu Gollapudi 
1128853e2bd2SBhanu Gollapudi 	conn_id = ofld_kcqe->fcoe_conn_id;
1129853e2bd2SBhanu Gollapudi 	context_id = ofld_kcqe->fcoe_conn_context_id;
1130853e2bd2SBhanu Gollapudi 	tgt = hba->tgt_ofld_list[conn_id];
1131853e2bd2SBhanu Gollapudi 	if (!tgt) {
1132aea71a02SBhanu Prakash Gollapudi 		printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
1133853e2bd2SBhanu Gollapudi 		return;
1134853e2bd2SBhanu Gollapudi 	}
1135853e2bd2SBhanu Gollapudi 	BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
1136853e2bd2SBhanu Gollapudi 		ofld_kcqe->fcoe_conn_context_id);
1137853e2bd2SBhanu Gollapudi 	port = tgt->port;
1138aea71a02SBhanu Prakash Gollapudi 	interface = tgt->port->priv;
1139aea71a02SBhanu Prakash Gollapudi 	if (hba != interface->hba) {
1140aea71a02SBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mis-match\n");
1141853e2bd2SBhanu Gollapudi 		goto ofld_cmpl_err;
1142853e2bd2SBhanu Gollapudi 	}
1143853e2bd2SBhanu Gollapudi 	/*
1144853e2bd2SBhanu Gollapudi 	 * cnic has allocated a context_id for this session; use this
1145853e2bd2SBhanu Gollapudi 	 * while enabling the session.
1146853e2bd2SBhanu Gollapudi 	 */
1147853e2bd2SBhanu Gollapudi 	tgt->context_id = context_id;
1148853e2bd2SBhanu Gollapudi 	if (ofld_kcqe->completion_status) {
1149853e2bd2SBhanu Gollapudi 		if (ofld_kcqe->completion_status ==
1150853e2bd2SBhanu Gollapudi 				FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
1151853e2bd2SBhanu Gollapudi 			printk(KERN_ERR PFX "unable to allocate FCoE context "
1152853e2bd2SBhanu Gollapudi 				"resources\n");
1153853e2bd2SBhanu Gollapudi 			set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
1154853e2bd2SBhanu Gollapudi 		}
1155853e2bd2SBhanu Gollapudi 	} else {
1156e7f4fed5SBhanu Prakash Gollapudi 		/* FW offload request successfully completed */
1157e7f4fed5SBhanu Prakash Gollapudi 		set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1158853e2bd2SBhanu Gollapudi 	}
1159853e2bd2SBhanu Gollapudi ofld_cmpl_err:
1160853e2bd2SBhanu Gollapudi 	set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1161853e2bd2SBhanu Gollapudi 	wake_up_interruptible(&tgt->ofld_wait);
1162853e2bd2SBhanu Gollapudi }
1163853e2bd2SBhanu Gollapudi 
1164853e2bd2SBhanu Gollapudi /**
1165853e2bd2SBhanu Gollapudi  * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
1166853e2bd2SBhanu Gollapudi  *
1167853e2bd2SBhanu Gollapudi  * @hba:	adapter structure pointer
1168853e2bd2SBhanu Gollapudi  * @ofld_kcqe:	connection offload kcqe pointer
1169853e2bd2SBhanu Gollapudi  *
1170853e2bd2SBhanu Gollapudi  * handle session enable completion, mark the rport as ready
1171853e2bd2SBhanu Gollapudi  */
1172853e2bd2SBhanu Gollapudi 
1173853e2bd2SBhanu Gollapudi static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1174853e2bd2SBhanu Gollapudi 						struct fcoe_kcqe *ofld_kcqe)
1175853e2bd2SBhanu Gollapudi {
1176853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport		*tgt;
1177aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface		*interface;
1178853e2bd2SBhanu Gollapudi 	u32				conn_id;
1179853e2bd2SBhanu Gollapudi 	u32				context_id;
1180853e2bd2SBhanu Gollapudi 
1181853e2bd2SBhanu Gollapudi 	context_id = ofld_kcqe->fcoe_conn_context_id;
1182853e2bd2SBhanu Gollapudi 	conn_id = ofld_kcqe->fcoe_conn_id;
1183853e2bd2SBhanu Gollapudi 	tgt = hba->tgt_ofld_list[conn_id];
1184853e2bd2SBhanu Gollapudi 	if (!tgt) {
1185b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "ERROR:enbl_cmpl: No pending ofld req\n");
1186853e2bd2SBhanu Gollapudi 		return;
1187853e2bd2SBhanu Gollapudi 	}
1188853e2bd2SBhanu Gollapudi 
1189853e2bd2SBhanu Gollapudi 	BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
1190853e2bd2SBhanu Gollapudi 		ofld_kcqe->fcoe_conn_context_id);
1191853e2bd2SBhanu Gollapudi 
1192853e2bd2SBhanu Gollapudi 	/*
1193853e2bd2SBhanu Gollapudi 	 * context_id should be the same for this target during offload
1194853e2bd2SBhanu Gollapudi 	 * and enable
1195853e2bd2SBhanu Gollapudi 	 */
1196853e2bd2SBhanu Gollapudi 	if (tgt->context_id != context_id) {
1197b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "context id mis-match\n");
1198853e2bd2SBhanu Gollapudi 		return;
1199853e2bd2SBhanu Gollapudi 	}
1200aea71a02SBhanu Prakash Gollapudi 	interface = tgt->port->priv;
1201aea71a02SBhanu Prakash Gollapudi 	if (hba != interface->hba) {
1202aea71a02SBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
1203853e2bd2SBhanu Gollapudi 		goto enbl_cmpl_err;
1204853e2bd2SBhanu Gollapudi 	}
1205e7f4fed5SBhanu Prakash Gollapudi 	if (!ofld_kcqe->completion_status)
1206853e2bd2SBhanu Gollapudi 		/* enable successful - rport ready for issuing IOs */
1207e7f4fed5SBhanu Prakash Gollapudi 		set_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
1208853e2bd2SBhanu Gollapudi 
1209853e2bd2SBhanu Gollapudi enbl_cmpl_err:
1210853e2bd2SBhanu Gollapudi 	set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1211853e2bd2SBhanu Gollapudi 	wake_up_interruptible(&tgt->ofld_wait);
1212853e2bd2SBhanu Gollapudi }
1213853e2bd2SBhanu Gollapudi 
1214853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
1215853e2bd2SBhanu Gollapudi 					struct fcoe_kcqe *disable_kcqe)
1216853e2bd2SBhanu Gollapudi {
1217853e2bd2SBhanu Gollapudi 
1218853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport		*tgt;
1219853e2bd2SBhanu Gollapudi 	u32				conn_id;
1220853e2bd2SBhanu Gollapudi 
1221853e2bd2SBhanu Gollapudi 	conn_id = disable_kcqe->fcoe_conn_id;
1222853e2bd2SBhanu Gollapudi 	tgt = hba->tgt_ofld_list[conn_id];
1223853e2bd2SBhanu Gollapudi 	if (!tgt) {
1224b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "ERROR: disable_cmpl: No disable req\n");
1225853e2bd2SBhanu Gollapudi 		return;
1226853e2bd2SBhanu Gollapudi 	}
1227853e2bd2SBhanu Gollapudi 
1228853e2bd2SBhanu Gollapudi 	BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
1229853e2bd2SBhanu Gollapudi 
1230853e2bd2SBhanu Gollapudi 	if (disable_kcqe->completion_status) {
1231b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "Disable failed with cmpl status %d\n",
1232853e2bd2SBhanu Gollapudi 			disable_kcqe->completion_status);
12335c17ae21SBhanu Prakash Gollapudi 		set_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags);
12345c17ae21SBhanu Prakash Gollapudi 		set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
12355c17ae21SBhanu Prakash Gollapudi 		wake_up_interruptible(&tgt->upld_wait);
1236853e2bd2SBhanu Gollapudi 	} else {
1237853e2bd2SBhanu Gollapudi 		/* disable successful */
1238853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "disable successful\n");
1239853e2bd2SBhanu Gollapudi 		clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1240e7f4fed5SBhanu Prakash Gollapudi 		clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
1241853e2bd2SBhanu Gollapudi 		set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1242853e2bd2SBhanu Gollapudi 		set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1243853e2bd2SBhanu Gollapudi 		wake_up_interruptible(&tgt->upld_wait);
1244853e2bd2SBhanu Gollapudi 	}
1245853e2bd2SBhanu Gollapudi }
1246853e2bd2SBhanu Gollapudi 
1247853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
1248853e2bd2SBhanu Gollapudi 					struct fcoe_kcqe *destroy_kcqe)
1249853e2bd2SBhanu Gollapudi {
1250853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport		*tgt;
1251853e2bd2SBhanu Gollapudi 	u32				conn_id;
1252853e2bd2SBhanu Gollapudi 
1253853e2bd2SBhanu Gollapudi 	conn_id = destroy_kcqe->fcoe_conn_id;
1254853e2bd2SBhanu Gollapudi 	tgt = hba->tgt_ofld_list[conn_id];
1255853e2bd2SBhanu Gollapudi 	if (!tgt) {
1256b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "destroy_cmpl: No destroy req\n");
1257853e2bd2SBhanu Gollapudi 		return;
1258853e2bd2SBhanu Gollapudi 	}
1259853e2bd2SBhanu Gollapudi 
1260853e2bd2SBhanu Gollapudi 	BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
1261853e2bd2SBhanu Gollapudi 
1262853e2bd2SBhanu Gollapudi 	if (destroy_kcqe->completion_status) {
1263b2a554ffSBhanu Prakash Gollapudi 		printk(KERN_ERR PFX "Destroy conn failed, cmpl status %d\n",
1264853e2bd2SBhanu Gollapudi 			destroy_kcqe->completion_status);
1265853e2bd2SBhanu Gollapudi 		return;
1266853e2bd2SBhanu Gollapudi 	} else {
1267853e2bd2SBhanu Gollapudi 		/* destroy successful */
1268853e2bd2SBhanu Gollapudi 		BNX2FC_TGT_DBG(tgt, "upload successful\n");
1269853e2bd2SBhanu Gollapudi 		clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1270853e2bd2SBhanu Gollapudi 		set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
1271853e2bd2SBhanu Gollapudi 		set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1272853e2bd2SBhanu Gollapudi 		wake_up_interruptible(&tgt->upld_wait);
1273853e2bd2SBhanu Gollapudi 	}
1274853e2bd2SBhanu Gollapudi }
1275853e2bd2SBhanu Gollapudi 
1276853e2bd2SBhanu Gollapudi static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
1277853e2bd2SBhanu Gollapudi {
1278853e2bd2SBhanu Gollapudi 	switch (err_code) {
1279853e2bd2SBhanu Gollapudi 	case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
1280853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
1281853e2bd2SBhanu Gollapudi 		break;
1282853e2bd2SBhanu Gollapudi 
1283853e2bd2SBhanu Gollapudi 	case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
1284853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
1285853e2bd2SBhanu Gollapudi 		break;
1286853e2bd2SBhanu Gollapudi 
1287853e2bd2SBhanu Gollapudi 	case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
1288853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "init_failure due to NIC error\n");
1289853e2bd2SBhanu Gollapudi 		break;
1290619c5cb6SVlad Zolotarov 	case FCOE_KCQE_COMPLETION_STATUS_ERROR:
1291619c5cb6SVlad Zolotarov 		printk(KERN_ERR PFX "init failure due to compl status err\n");
1292619c5cb6SVlad Zolotarov 		break;
1293619c5cb6SVlad Zolotarov 	case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION:
1294619c5cb6SVlad Zolotarov 		printk(KERN_ERR PFX "init failure due to HSI mismatch\n");
1295b2a554ffSBhanu Prakash Gollapudi 		break;
1296853e2bd2SBhanu Gollapudi 	default:
1297853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
1298853e2bd2SBhanu Gollapudi 	}
1299853e2bd2SBhanu Gollapudi }
1300853e2bd2SBhanu Gollapudi 
1301853e2bd2SBhanu Gollapudi /**
1302853e2bd2SBhanu Gollapudi  * bnx2fc_indicae_kcqe - process KCQE
1303853e2bd2SBhanu Gollapudi  *
1304853e2bd2SBhanu Gollapudi  * @hba:	adapter structure pointer
1305853e2bd2SBhanu Gollapudi  * @kcqe:	kcqe pointer
1306853e2bd2SBhanu Gollapudi  * @num_cqe:	Number of completion queue elements
1307853e2bd2SBhanu Gollapudi  *
1308853e2bd2SBhanu Gollapudi  * Generic KCQ event handler
1309853e2bd2SBhanu Gollapudi  */
1310853e2bd2SBhanu Gollapudi void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
1311853e2bd2SBhanu Gollapudi 					u32 num_cqe)
1312853e2bd2SBhanu Gollapudi {
1313853e2bd2SBhanu Gollapudi 	struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
1314853e2bd2SBhanu Gollapudi 	int i = 0;
1315853e2bd2SBhanu Gollapudi 	struct fcoe_kcqe *kcqe = NULL;
1316853e2bd2SBhanu Gollapudi 
1317853e2bd2SBhanu Gollapudi 	while (i < num_cqe) {
1318853e2bd2SBhanu Gollapudi 		kcqe = (struct fcoe_kcqe *) kcq[i++];
1319853e2bd2SBhanu Gollapudi 
1320853e2bd2SBhanu Gollapudi 		switch (kcqe->op_code) {
1321853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
1322853e2bd2SBhanu Gollapudi 			bnx2fc_fastpath_notification(hba, kcqe);
1323853e2bd2SBhanu Gollapudi 			break;
1324853e2bd2SBhanu Gollapudi 
1325853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
1326853e2bd2SBhanu Gollapudi 			bnx2fc_process_ofld_cmpl(hba, kcqe);
1327853e2bd2SBhanu Gollapudi 			break;
1328853e2bd2SBhanu Gollapudi 
1329853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_ENABLE_CONN:
1330853e2bd2SBhanu Gollapudi 			bnx2fc_process_enable_conn_cmpl(hba, kcqe);
1331853e2bd2SBhanu Gollapudi 			break;
1332853e2bd2SBhanu Gollapudi 
1333853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_INIT_FUNC:
1334853e2bd2SBhanu Gollapudi 			if (kcqe->completion_status !=
1335853e2bd2SBhanu Gollapudi 					FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1336853e2bd2SBhanu Gollapudi 				bnx2fc_init_failure(hba,
1337853e2bd2SBhanu Gollapudi 						kcqe->completion_status);
1338853e2bd2SBhanu Gollapudi 			} else {
1339853e2bd2SBhanu Gollapudi 				set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1340853e2bd2SBhanu Gollapudi 				bnx2fc_get_link_state(hba);
1341853e2bd2SBhanu Gollapudi 				printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
1342853e2bd2SBhanu Gollapudi 					(u8)hba->pcidev->bus->number);
1343853e2bd2SBhanu Gollapudi 			}
1344853e2bd2SBhanu Gollapudi 			break;
1345853e2bd2SBhanu Gollapudi 
1346853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_DESTROY_FUNC:
1347853e2bd2SBhanu Gollapudi 			if (kcqe->completion_status !=
1348853e2bd2SBhanu Gollapudi 					FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1349853e2bd2SBhanu Gollapudi 
1350853e2bd2SBhanu Gollapudi 				printk(KERN_ERR PFX "DESTROY failed\n");
1351853e2bd2SBhanu Gollapudi 			} else {
1352853e2bd2SBhanu Gollapudi 				printk(KERN_ERR PFX "DESTROY success\n");
1353853e2bd2SBhanu Gollapudi 			}
1354aea71a02SBhanu Prakash Gollapudi 			set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1355853e2bd2SBhanu Gollapudi 			wake_up_interruptible(&hba->destroy_wait);
1356853e2bd2SBhanu Gollapudi 			break;
1357853e2bd2SBhanu Gollapudi 
1358853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_DISABLE_CONN:
1359853e2bd2SBhanu Gollapudi 			bnx2fc_process_conn_disable_cmpl(hba, kcqe);
1360853e2bd2SBhanu Gollapudi 			break;
1361853e2bd2SBhanu Gollapudi 
1362853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_DESTROY_CONN:
1363853e2bd2SBhanu Gollapudi 			bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
1364853e2bd2SBhanu Gollapudi 			break;
1365853e2bd2SBhanu Gollapudi 
1366853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_STAT_FUNC:
1367853e2bd2SBhanu Gollapudi 			if (kcqe->completion_status !=
1368853e2bd2SBhanu Gollapudi 			    FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
1369853e2bd2SBhanu Gollapudi 				printk(KERN_ERR PFX "STAT failed\n");
1370853e2bd2SBhanu Gollapudi 			complete(&hba->stat_req_done);
1371853e2bd2SBhanu Gollapudi 			break;
1372853e2bd2SBhanu Gollapudi 
1373853e2bd2SBhanu Gollapudi 		case FCOE_KCQE_OPCODE_FCOE_ERROR:
1374853e2bd2SBhanu Gollapudi 			/* fall thru */
1375853e2bd2SBhanu Gollapudi 		default:
1376b2a554ffSBhanu Prakash Gollapudi 			printk(KERN_ERR PFX "unknown opcode 0x%x\n",
1377853e2bd2SBhanu Gollapudi 								kcqe->op_code);
1378853e2bd2SBhanu Gollapudi 		}
1379853e2bd2SBhanu Gollapudi 	}
1380853e2bd2SBhanu Gollapudi }
1381853e2bd2SBhanu Gollapudi 
1382853e2bd2SBhanu Gollapudi void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
1383853e2bd2SBhanu Gollapudi {
1384853e2bd2SBhanu Gollapudi 	struct fcoe_sqe *sqe;
1385853e2bd2SBhanu Gollapudi 
1386853e2bd2SBhanu Gollapudi 	sqe = &tgt->sq[tgt->sq_prod_idx];
1387853e2bd2SBhanu Gollapudi 
1388853e2bd2SBhanu Gollapudi 	/* Fill SQ WQE */
1389853e2bd2SBhanu Gollapudi 	sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
1390853e2bd2SBhanu Gollapudi 	sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
1391853e2bd2SBhanu Gollapudi 
1392853e2bd2SBhanu Gollapudi 	/* Advance SQ Prod Idx */
1393853e2bd2SBhanu Gollapudi 	if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
1394853e2bd2SBhanu Gollapudi 		tgt->sq_prod_idx = 0;
1395853e2bd2SBhanu Gollapudi 		tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
1396853e2bd2SBhanu Gollapudi 	}
1397853e2bd2SBhanu Gollapudi }
1398853e2bd2SBhanu Gollapudi 
1399853e2bd2SBhanu Gollapudi void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
1400853e2bd2SBhanu Gollapudi {
1401619c5cb6SVlad Zolotarov 	struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
1402853e2bd2SBhanu Gollapudi 	u32 msg;
1403853e2bd2SBhanu Gollapudi 
1404853e2bd2SBhanu Gollapudi 	wmb();
1405619c5cb6SVlad Zolotarov 	sq_db->prod = tgt->sq_prod_idx |
1406853e2bd2SBhanu Gollapudi 				(tgt->sq_curr_toggle_bit << 15);
1407619c5cb6SVlad Zolotarov 	msg = *((u32 *)sq_db);
1408853e2bd2SBhanu Gollapudi 	writel(cpu_to_le32(msg), tgt->ctx_base);
1409853e2bd2SBhanu Gollapudi 	mmiowb();
1410853e2bd2SBhanu Gollapudi 
1411853e2bd2SBhanu Gollapudi }
1412853e2bd2SBhanu Gollapudi 
1413853e2bd2SBhanu Gollapudi int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
1414853e2bd2SBhanu Gollapudi {
1415853e2bd2SBhanu Gollapudi 	u32 context_id = tgt->context_id;
1416853e2bd2SBhanu Gollapudi 	struct fcoe_port *port = tgt->port;
1417853e2bd2SBhanu Gollapudi 	u32 reg_off;
1418853e2bd2SBhanu Gollapudi 	resource_size_t reg_base;
1419aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = port->priv;
1420aea71a02SBhanu Prakash Gollapudi 	struct bnx2fc_hba *hba = interface->hba;
1421853e2bd2SBhanu Gollapudi 
1422853e2bd2SBhanu Gollapudi 	reg_base = pci_resource_start(hba->pcidev,
1423853e2bd2SBhanu Gollapudi 					BNX2X_DOORBELL_PCI_BAR);
1424f78afb35SMichael Chan 	reg_off = (1 << BNX2X_DB_SHIFT) * (context_id & 0x1FFFF);
1425853e2bd2SBhanu Gollapudi 	tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4);
1426853e2bd2SBhanu Gollapudi 	if (!tgt->ctx_base)
1427853e2bd2SBhanu Gollapudi 		return -ENOMEM;
1428853e2bd2SBhanu Gollapudi 	return 0;
1429853e2bd2SBhanu Gollapudi }
1430853e2bd2SBhanu Gollapudi 
1431853e2bd2SBhanu Gollapudi char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1432853e2bd2SBhanu Gollapudi {
1433853e2bd2SBhanu Gollapudi 	char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
1434853e2bd2SBhanu Gollapudi 
1435853e2bd2SBhanu Gollapudi 	if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
1436853e2bd2SBhanu Gollapudi 		return NULL;
1437853e2bd2SBhanu Gollapudi 
1438853e2bd2SBhanu Gollapudi 	tgt->rq_cons_idx += num_items;
1439853e2bd2SBhanu Gollapudi 
1440853e2bd2SBhanu Gollapudi 	if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
1441853e2bd2SBhanu Gollapudi 		tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
1442853e2bd2SBhanu Gollapudi 
1443853e2bd2SBhanu Gollapudi 	return buf;
1444853e2bd2SBhanu Gollapudi }
1445853e2bd2SBhanu Gollapudi 
1446853e2bd2SBhanu Gollapudi void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1447853e2bd2SBhanu Gollapudi {
1448853e2bd2SBhanu Gollapudi 	/* return the rq buffer */
1449853e2bd2SBhanu Gollapudi 	u32 next_prod_idx = tgt->rq_prod_idx + num_items;
1450853e2bd2SBhanu Gollapudi 	if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
1451853e2bd2SBhanu Gollapudi 		/* Wrap around RQ */
1452853e2bd2SBhanu Gollapudi 		next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
1453853e2bd2SBhanu Gollapudi 	}
1454853e2bd2SBhanu Gollapudi 	tgt->rq_prod_idx = next_prod_idx;
1455853e2bd2SBhanu Gollapudi 	tgt->conn_db->rq_prod = tgt->rq_prod_idx;
1456853e2bd2SBhanu Gollapudi }
1457853e2bd2SBhanu Gollapudi 
14586c5a7ce4SBhanu Prakash Gollapudi void bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd *seq_clnp_req,
14596c5a7ce4SBhanu Prakash Gollapudi 				  struct fcoe_task_ctx_entry *task,
14606c5a7ce4SBhanu Prakash Gollapudi 				  struct bnx2fc_cmd *orig_io_req,
14616c5a7ce4SBhanu Prakash Gollapudi 				  u32 offset)
14626c5a7ce4SBhanu Prakash Gollapudi {
14636c5a7ce4SBhanu Prakash Gollapudi 	struct scsi_cmnd *sc_cmd = orig_io_req->sc_cmd;
14646c5a7ce4SBhanu Prakash Gollapudi 	struct bnx2fc_rport *tgt = seq_clnp_req->tgt;
14656c5a7ce4SBhanu Prakash Gollapudi 	struct bnx2fc_interface *interface = tgt->port->priv;
14666c5a7ce4SBhanu Prakash Gollapudi 	struct fcoe_bd_ctx *bd = orig_io_req->bd_tbl->bd_tbl;
14676c5a7ce4SBhanu Prakash Gollapudi 	struct fcoe_task_ctx_entry *orig_task;
14686c5a7ce4SBhanu Prakash Gollapudi 	struct fcoe_task_ctx_entry *task_page;
14696c5a7ce4SBhanu Prakash Gollapudi 	struct fcoe_ext_mul_sges_ctx *sgl;
14706c5a7ce4SBhanu Prakash Gollapudi 	u8 task_type = FCOE_TASK_TYPE_SEQUENCE_CLEANUP;
14716c5a7ce4SBhanu Prakash Gollapudi 	u8 orig_task_type;
14726c5a7ce4SBhanu Prakash Gollapudi 	u16 orig_xid = orig_io_req->xid;
14736c5a7ce4SBhanu Prakash Gollapudi 	u32 context_id = tgt->context_id;
14746c5a7ce4SBhanu Prakash Gollapudi 	u64 phys_addr = (u64)orig_io_req->bd_tbl->bd_tbl_dma;
14756c5a7ce4SBhanu Prakash Gollapudi 	u32 orig_offset = offset;
14766c5a7ce4SBhanu Prakash Gollapudi 	int bd_count;
14776c5a7ce4SBhanu Prakash Gollapudi 	int orig_task_idx, index;
14786c5a7ce4SBhanu Prakash Gollapudi 	int i;
14796c5a7ce4SBhanu Prakash Gollapudi 
14806c5a7ce4SBhanu Prakash Gollapudi 	memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
14816c5a7ce4SBhanu Prakash Gollapudi 
14826c5a7ce4SBhanu Prakash Gollapudi 	if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
14836c5a7ce4SBhanu Prakash Gollapudi 		orig_task_type = FCOE_TASK_TYPE_WRITE;
14846c5a7ce4SBhanu Prakash Gollapudi 	else
14856c5a7ce4SBhanu Prakash Gollapudi 		orig_task_type = FCOE_TASK_TYPE_READ;
14866c5a7ce4SBhanu Prakash Gollapudi 
14876c5a7ce4SBhanu Prakash Gollapudi 	/* Tx flags */
14886c5a7ce4SBhanu Prakash Gollapudi 	task->txwr_rxrd.const_ctx.tx_flags =
14896c5a7ce4SBhanu Prakash Gollapudi 				FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP <<
14906c5a7ce4SBhanu Prakash Gollapudi 				FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
14916c5a7ce4SBhanu Prakash Gollapudi 	/* init flags */
14926c5a7ce4SBhanu Prakash Gollapudi 	task->txwr_rxrd.const_ctx.init_flags = task_type <<
14936c5a7ce4SBhanu Prakash Gollapudi 				FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
14946c5a7ce4SBhanu Prakash Gollapudi 	task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
14956c5a7ce4SBhanu Prakash Gollapudi 				FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
14966c5a7ce4SBhanu Prakash Gollapudi 	task->rxwr_txrd.const_ctx.init_flags = context_id <<
14976c5a7ce4SBhanu Prakash Gollapudi 				FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
14986c5a7ce4SBhanu Prakash Gollapudi 	task->rxwr_txrd.const_ctx.init_flags = context_id <<
14996c5a7ce4SBhanu Prakash Gollapudi 				FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
15006c5a7ce4SBhanu Prakash Gollapudi 
15016c5a7ce4SBhanu Prakash Gollapudi 	task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
15026c5a7ce4SBhanu Prakash Gollapudi 
15036c5a7ce4SBhanu Prakash Gollapudi 	task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_seq_cnt = 0;
15046c5a7ce4SBhanu Prakash Gollapudi 	task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_data_offset = offset;
15056c5a7ce4SBhanu Prakash Gollapudi 
15066c5a7ce4SBhanu Prakash Gollapudi 	bd_count = orig_io_req->bd_tbl->bd_valid;
15076c5a7ce4SBhanu Prakash Gollapudi 
15086c5a7ce4SBhanu Prakash Gollapudi 	/* obtain the appropriate bd entry from relative offset */
15096c5a7ce4SBhanu Prakash Gollapudi 	for (i = 0; i < bd_count; i++) {
15106c5a7ce4SBhanu Prakash Gollapudi 		if (offset < bd[i].buf_len)
15116c5a7ce4SBhanu Prakash Gollapudi 			break;
15126c5a7ce4SBhanu Prakash Gollapudi 		offset -= bd[i].buf_len;
15136c5a7ce4SBhanu Prakash Gollapudi 	}
15146c5a7ce4SBhanu Prakash Gollapudi 	phys_addr += (i * sizeof(struct fcoe_bd_ctx));
15156c5a7ce4SBhanu Prakash Gollapudi 
15166c5a7ce4SBhanu Prakash Gollapudi 	if (orig_task_type == FCOE_TASK_TYPE_WRITE) {
15176c5a7ce4SBhanu Prakash Gollapudi 		task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
15186c5a7ce4SBhanu Prakash Gollapudi 				(u32)phys_addr;
15196c5a7ce4SBhanu Prakash Gollapudi 		task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
15206c5a7ce4SBhanu Prakash Gollapudi 				(u32)((u64)phys_addr >> 32);
15216c5a7ce4SBhanu Prakash Gollapudi 		task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
15226c5a7ce4SBhanu Prakash Gollapudi 				bd_count;
15236c5a7ce4SBhanu Prakash Gollapudi 		task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_off =
15246c5a7ce4SBhanu Prakash Gollapudi 				offset; /* adjusted offset */
15256c5a7ce4SBhanu Prakash Gollapudi 		task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_idx = i;
15266c5a7ce4SBhanu Prakash Gollapudi 	} else {
15276c5a7ce4SBhanu Prakash Gollapudi 		orig_task_idx = orig_xid / BNX2FC_TASKS_PER_PAGE;
15286c5a7ce4SBhanu Prakash Gollapudi 		index = orig_xid % BNX2FC_TASKS_PER_PAGE;
15296c5a7ce4SBhanu Prakash Gollapudi 
15306c5a7ce4SBhanu Prakash Gollapudi 		task_page = (struct fcoe_task_ctx_entry *)
15316c5a7ce4SBhanu Prakash Gollapudi 			     interface->hba->task_ctx[orig_task_idx];
15326c5a7ce4SBhanu Prakash Gollapudi 		orig_task = &(task_page[index]);
15336c5a7ce4SBhanu Prakash Gollapudi 
15346c5a7ce4SBhanu Prakash Gollapudi 		/* Multiple SGEs were used for this IO */
15356c5a7ce4SBhanu Prakash Gollapudi 		sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
15366c5a7ce4SBhanu Prakash Gollapudi 		sgl->mul_sgl.cur_sge_addr.lo = (u32)phys_addr;
15376c5a7ce4SBhanu Prakash Gollapudi 		sgl->mul_sgl.cur_sge_addr.hi = (u32)((u64)phys_addr >> 32);
15386c5a7ce4SBhanu Prakash Gollapudi 		sgl->mul_sgl.sgl_size = bd_count;
15396c5a7ce4SBhanu Prakash Gollapudi 		sgl->mul_sgl.cur_sge_off = offset; /*adjusted offset */
15406c5a7ce4SBhanu Prakash Gollapudi 		sgl->mul_sgl.cur_sge_idx = i;
15416c5a7ce4SBhanu Prakash Gollapudi 
15426c5a7ce4SBhanu Prakash Gollapudi 		memset(&task->rxwr_only.rx_seq_ctx, 0,
15436c5a7ce4SBhanu Prakash Gollapudi 		       sizeof(struct fcoe_rx_seq_ctx));
15446c5a7ce4SBhanu Prakash Gollapudi 		task->rxwr_only.rx_seq_ctx.low_exp_ro = orig_offset;
15456c5a7ce4SBhanu Prakash Gollapudi 		task->rxwr_only.rx_seq_ctx.high_exp_ro = orig_offset;
15466c5a7ce4SBhanu Prakash Gollapudi 	}
15476c5a7ce4SBhanu Prakash Gollapudi }
1548853e2bd2SBhanu Gollapudi void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
1549853e2bd2SBhanu Gollapudi 			      struct fcoe_task_ctx_entry *task,
1550853e2bd2SBhanu Gollapudi 			      u16 orig_xid)
1551853e2bd2SBhanu Gollapudi {
1552853e2bd2SBhanu Gollapudi 	u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
1553853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport *tgt = io_req->tgt;
1554853e2bd2SBhanu Gollapudi 	u32 context_id = tgt->context_id;
1555853e2bd2SBhanu Gollapudi 
1556853e2bd2SBhanu Gollapudi 	memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1557853e2bd2SBhanu Gollapudi 
1558853e2bd2SBhanu Gollapudi 	/* Tx Write Rx Read */
1559619c5cb6SVlad Zolotarov 	/* init flags */
1560619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.init_flags = task_type <<
1561619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1562619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1563619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1564f3820b71SBhanu Prakash Gollapudi 	if (tgt->dev_type == TYPE_TAPE)
1565f3820b71SBhanu Prakash Gollapudi 		task->txwr_rxrd.const_ctx.init_flags |=
1566f3820b71SBhanu Prakash Gollapudi 				FCOE_TASK_DEV_TYPE_TAPE <<
1567f3820b71SBhanu Prakash Gollapudi 				FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1568f3820b71SBhanu Prakash Gollapudi 	else
1569619c5cb6SVlad Zolotarov 		task->txwr_rxrd.const_ctx.init_flags |=
1570619c5cb6SVlad Zolotarov 				FCOE_TASK_DEV_TYPE_DISK <<
1571619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1572619c5cb6SVlad Zolotarov 	task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
1573853e2bd2SBhanu Gollapudi 
1574619c5cb6SVlad Zolotarov 	/* Tx flags */
1575619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.tx_flags =
1576619c5cb6SVlad Zolotarov 				FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
1577619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1578853e2bd2SBhanu Gollapudi 
1579619c5cb6SVlad Zolotarov 	/* Rx Read Tx Write */
1580619c5cb6SVlad Zolotarov 	task->rxwr_txrd.const_ctx.init_flags = context_id <<
1581619c5cb6SVlad Zolotarov 				FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1582619c5cb6SVlad Zolotarov 	task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1583619c5cb6SVlad Zolotarov 				FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1584853e2bd2SBhanu Gollapudi }
1585853e2bd2SBhanu Gollapudi 
1586853e2bd2SBhanu Gollapudi void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
1587853e2bd2SBhanu Gollapudi 				struct fcoe_task_ctx_entry *task)
1588853e2bd2SBhanu Gollapudi {
1589853e2bd2SBhanu Gollapudi 	struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
1590853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport *tgt = io_req->tgt;
1591853e2bd2SBhanu Gollapudi 	struct fc_frame_header *fc_hdr;
1592619c5cb6SVlad Zolotarov 	struct fcoe_ext_mul_sges_ctx *sgl;
1593853e2bd2SBhanu Gollapudi 	u8 task_type = 0;
1594853e2bd2SBhanu Gollapudi 	u64 *hdr;
1595853e2bd2SBhanu Gollapudi 	u64 temp_hdr[3];
1596853e2bd2SBhanu Gollapudi 	u32 context_id;
1597853e2bd2SBhanu Gollapudi 
1598853e2bd2SBhanu Gollapudi 
1599853e2bd2SBhanu Gollapudi 	/* Obtain task_type */
1600853e2bd2SBhanu Gollapudi 	if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
1601853e2bd2SBhanu Gollapudi 	    (io_req->cmd_type == BNX2FC_ELS)) {
1602853e2bd2SBhanu Gollapudi 		task_type = FCOE_TASK_TYPE_MIDPATH;
1603853e2bd2SBhanu Gollapudi 	} else if (io_req->cmd_type == BNX2FC_ABTS) {
1604853e2bd2SBhanu Gollapudi 		task_type = FCOE_TASK_TYPE_ABTS;
1605853e2bd2SBhanu Gollapudi 	}
1606853e2bd2SBhanu Gollapudi 
1607853e2bd2SBhanu Gollapudi 	memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1608853e2bd2SBhanu Gollapudi 
1609853e2bd2SBhanu Gollapudi 	/* Setup the task from io_req for easy reference */
1610853e2bd2SBhanu Gollapudi 	io_req->task = task;
1611853e2bd2SBhanu Gollapudi 
1612853e2bd2SBhanu Gollapudi 	BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
1613853e2bd2SBhanu Gollapudi 		io_req->cmd_type, task_type);
1614853e2bd2SBhanu Gollapudi 
1615853e2bd2SBhanu Gollapudi 	/* Tx only */
1616853e2bd2SBhanu Gollapudi 	if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
1617853e2bd2SBhanu Gollapudi 	    (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
1618619c5cb6SVlad Zolotarov 		task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1619853e2bd2SBhanu Gollapudi 				(u32)mp_req->mp_req_bd_dma;
1620619c5cb6SVlad Zolotarov 		task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1621853e2bd2SBhanu Gollapudi 				(u32)((u64)mp_req->mp_req_bd_dma >> 32);
1622619c5cb6SVlad Zolotarov 		task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1;
1623853e2bd2SBhanu Gollapudi 	}
1624853e2bd2SBhanu Gollapudi 
1625853e2bd2SBhanu Gollapudi 	/* Tx Write Rx Read */
1626619c5cb6SVlad Zolotarov 	/* init flags */
1627619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.init_flags = task_type <<
1628619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1629f3820b71SBhanu Prakash Gollapudi 	if (tgt->dev_type == TYPE_TAPE)
1630f3820b71SBhanu Prakash Gollapudi 		task->txwr_rxrd.const_ctx.init_flags |=
1631f3820b71SBhanu Prakash Gollapudi 				FCOE_TASK_DEV_TYPE_TAPE <<
1632f3820b71SBhanu Prakash Gollapudi 				FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1633f3820b71SBhanu Prakash Gollapudi 	else
1634619c5cb6SVlad Zolotarov 		task->txwr_rxrd.const_ctx.init_flags |=
1635619c5cb6SVlad Zolotarov 				FCOE_TASK_DEV_TYPE_DISK <<
1636619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1637619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1638619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1639853e2bd2SBhanu Gollapudi 
1640619c5cb6SVlad Zolotarov 	/* tx flags */
1641619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_INIT <<
1642619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1643853e2bd2SBhanu Gollapudi 
1644853e2bd2SBhanu Gollapudi 	/* Rx Write Tx Read */
1645619c5cb6SVlad Zolotarov 	task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1646619c5cb6SVlad Zolotarov 
1647619c5cb6SVlad Zolotarov 	/* rx flags */
1648619c5cb6SVlad Zolotarov 	task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1649619c5cb6SVlad Zolotarov 				FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1650619c5cb6SVlad Zolotarov 
1651619c5cb6SVlad Zolotarov 	context_id = tgt->context_id;
1652619c5cb6SVlad Zolotarov 	task->rxwr_txrd.const_ctx.init_flags = context_id <<
1653619c5cb6SVlad Zolotarov 				FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1654619c5cb6SVlad Zolotarov 
1655853e2bd2SBhanu Gollapudi 	fc_hdr = &(mp_req->req_fc_hdr);
1656853e2bd2SBhanu Gollapudi 	if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1657853e2bd2SBhanu Gollapudi 		fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
1658853e2bd2SBhanu Gollapudi 		fc_hdr->fh_rx_id = htons(0xffff);
1659619c5cb6SVlad Zolotarov 		task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1660853e2bd2SBhanu Gollapudi 	} else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
1661853e2bd2SBhanu Gollapudi 		fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
1662853e2bd2SBhanu Gollapudi 	}
1663853e2bd2SBhanu Gollapudi 
1664853e2bd2SBhanu Gollapudi 	/* Fill FC Header into middle path buffer */
1665619c5cb6SVlad Zolotarov 	hdr = (u64 *) &task->txwr_rxrd.union_ctx.tx_frame.fc_hdr;
1666853e2bd2SBhanu Gollapudi 	memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
1667853e2bd2SBhanu Gollapudi 	hdr[0] = cpu_to_be64(temp_hdr[0]);
1668853e2bd2SBhanu Gollapudi 	hdr[1] = cpu_to_be64(temp_hdr[1]);
1669853e2bd2SBhanu Gollapudi 	hdr[2] = cpu_to_be64(temp_hdr[2]);
1670853e2bd2SBhanu Gollapudi 
1671853e2bd2SBhanu Gollapudi 	/* Rx Only */
1672853e2bd2SBhanu Gollapudi 	if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1673619c5cb6SVlad Zolotarov 		sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1674853e2bd2SBhanu Gollapudi 
1675619c5cb6SVlad Zolotarov 		sgl->mul_sgl.cur_sge_addr.lo = (u32)mp_req->mp_resp_bd_dma;
1676619c5cb6SVlad Zolotarov 		sgl->mul_sgl.cur_sge_addr.hi =
1677853e2bd2SBhanu Gollapudi 				(u32)((u64)mp_req->mp_resp_bd_dma >> 32);
1678619c5cb6SVlad Zolotarov 		sgl->mul_sgl.sgl_size = 1;
1679853e2bd2SBhanu Gollapudi 	}
1680853e2bd2SBhanu Gollapudi }
1681853e2bd2SBhanu Gollapudi 
1682853e2bd2SBhanu Gollapudi void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
1683853e2bd2SBhanu Gollapudi 			     struct fcoe_task_ctx_entry *task)
1684853e2bd2SBhanu Gollapudi {
1685853e2bd2SBhanu Gollapudi 	u8 task_type;
1686853e2bd2SBhanu Gollapudi 	struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1687853e2bd2SBhanu Gollapudi 	struct io_bdt *bd_tbl = io_req->bd_tbl;
1688853e2bd2SBhanu Gollapudi 	struct bnx2fc_rport *tgt = io_req->tgt;
1689619c5cb6SVlad Zolotarov 	struct fcoe_cached_sge_ctx *cached_sge;
1690619c5cb6SVlad Zolotarov 	struct fcoe_ext_mul_sges_ctx *sgl;
1691f3820b71SBhanu Prakash Gollapudi 	int dev_type = tgt->dev_type;
1692853e2bd2SBhanu Gollapudi 	u64 *fcp_cmnd;
1693853e2bd2SBhanu Gollapudi 	u64 tmp_fcp_cmnd[4];
1694853e2bd2SBhanu Gollapudi 	u32 context_id;
1695853e2bd2SBhanu Gollapudi 	int cnt, i;
1696853e2bd2SBhanu Gollapudi 	int bd_count;
1697853e2bd2SBhanu Gollapudi 
1698853e2bd2SBhanu Gollapudi 	memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1699853e2bd2SBhanu Gollapudi 
1700853e2bd2SBhanu Gollapudi 	/* Setup the task from io_req for easy reference */
1701853e2bd2SBhanu Gollapudi 	io_req->task = task;
1702853e2bd2SBhanu Gollapudi 
1703853e2bd2SBhanu Gollapudi 	if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1704853e2bd2SBhanu Gollapudi 		task_type = FCOE_TASK_TYPE_WRITE;
1705853e2bd2SBhanu Gollapudi 	else
1706853e2bd2SBhanu Gollapudi 		task_type = FCOE_TASK_TYPE_READ;
1707853e2bd2SBhanu Gollapudi 
1708853e2bd2SBhanu Gollapudi 	/* Tx only */
17093c75108fSBhanu Prakash Gollapudi 	bd_count = bd_tbl->bd_valid;
17101101a0d8SBhanu Prakash Gollapudi 	cached_sge = &task->rxwr_only.union_ctx.read_info.sgl_ctx.cached_sge;
1711853e2bd2SBhanu Gollapudi 	if (task_type == FCOE_TASK_TYPE_WRITE) {
17123c75108fSBhanu Prakash Gollapudi 		if ((dev_type == TYPE_DISK) && (bd_count == 1)) {
17133c75108fSBhanu Prakash Gollapudi 			struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
17143c75108fSBhanu Prakash Gollapudi 
17153c75108fSBhanu Prakash Gollapudi 			task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.lo =
17161101a0d8SBhanu Prakash Gollapudi 			cached_sge->cur_buf_addr.lo =
17173c75108fSBhanu Prakash Gollapudi 					fcoe_bd_tbl->buf_addr_lo;
17183c75108fSBhanu Prakash Gollapudi 			task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.hi =
17191101a0d8SBhanu Prakash Gollapudi 			cached_sge->cur_buf_addr.hi =
17203c75108fSBhanu Prakash Gollapudi 					fcoe_bd_tbl->buf_addr_hi;
17213c75108fSBhanu Prakash Gollapudi 			task->txwr_only.sgl_ctx.cached_sge.cur_buf_rem =
17221101a0d8SBhanu Prakash Gollapudi 			cached_sge->cur_buf_rem =
17233c75108fSBhanu Prakash Gollapudi 					fcoe_bd_tbl->buf_len;
17243c75108fSBhanu Prakash Gollapudi 
17253c75108fSBhanu Prakash Gollapudi 			task->txwr_rxrd.const_ctx.init_flags |= 1 <<
17263c75108fSBhanu Prakash Gollapudi 				FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
17273c75108fSBhanu Prakash Gollapudi 		} else {
1728619c5cb6SVlad Zolotarov 			task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1729853e2bd2SBhanu Gollapudi 					(u32)bd_tbl->bd_tbl_dma;
1730619c5cb6SVlad Zolotarov 			task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1731853e2bd2SBhanu Gollapudi 					(u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1732619c5cb6SVlad Zolotarov 			task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
1733853e2bd2SBhanu Gollapudi 					bd_tbl->bd_valid;
1734853e2bd2SBhanu Gollapudi 		}
17353c75108fSBhanu Prakash Gollapudi 	}
1736853e2bd2SBhanu Gollapudi 
1737853e2bd2SBhanu Gollapudi 	/*Tx Write Rx Read */
1738853e2bd2SBhanu Gollapudi 	/* Init state to NORMAL */
17393c75108fSBhanu Prakash Gollapudi 	task->txwr_rxrd.const_ctx.init_flags |= task_type <<
1740619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1741c1c16bd5SBhanu Prakash Gollapudi 	if (dev_type == TYPE_TAPE) {
1742f3820b71SBhanu Prakash Gollapudi 		task->txwr_rxrd.const_ctx.init_flags |=
1743f3820b71SBhanu Prakash Gollapudi 				FCOE_TASK_DEV_TYPE_TAPE <<
1744f3820b71SBhanu Prakash Gollapudi 				FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1745c1c16bd5SBhanu Prakash Gollapudi 		io_req->rec_retry = 0;
1746c1c16bd5SBhanu Prakash Gollapudi 		io_req->rec_retry = 0;
1747c1c16bd5SBhanu Prakash Gollapudi 	} else
1748619c5cb6SVlad Zolotarov 		task->txwr_rxrd.const_ctx.init_flags |=
1749619c5cb6SVlad Zolotarov 				FCOE_TASK_DEV_TYPE_DISK <<
1750619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1751619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1752619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1753619c5cb6SVlad Zolotarov 	/* tx flags */
1754619c5cb6SVlad Zolotarov 	task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
1755619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1756853e2bd2SBhanu Gollapudi 
1757853e2bd2SBhanu Gollapudi 	/* Set initial seq counter */
1758619c5cb6SVlad Zolotarov 	task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1;
1759853e2bd2SBhanu Gollapudi 
1760853e2bd2SBhanu Gollapudi 	/* Fill FCP_CMND IU */
1761853e2bd2SBhanu Gollapudi 	fcp_cmnd = (u64 *)
1762619c5cb6SVlad Zolotarov 		    task->txwr_rxrd.union_ctx.fcp_cmd.opaque;
1763853e2bd2SBhanu Gollapudi 	bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
1764853e2bd2SBhanu Gollapudi 
1765853e2bd2SBhanu Gollapudi 	/* swap fcp_cmnd */
1766853e2bd2SBhanu Gollapudi 	cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
1767853e2bd2SBhanu Gollapudi 
1768853e2bd2SBhanu Gollapudi 	for (i = 0; i < cnt; i++) {
1769853e2bd2SBhanu Gollapudi 		*fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
1770853e2bd2SBhanu Gollapudi 		fcp_cmnd++;
1771853e2bd2SBhanu Gollapudi 	}
1772853e2bd2SBhanu Gollapudi 
1773853e2bd2SBhanu Gollapudi 	/* Rx Write Tx Read */
1774619c5cb6SVlad Zolotarov 	task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1775619c5cb6SVlad Zolotarov 
1776619c5cb6SVlad Zolotarov 	context_id = tgt->context_id;
1777619c5cb6SVlad Zolotarov 	task->rxwr_txrd.const_ctx.init_flags = context_id <<
1778619c5cb6SVlad Zolotarov 				FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1779619c5cb6SVlad Zolotarov 
1780619c5cb6SVlad Zolotarov 	/* rx flags */
1781619c5cb6SVlad Zolotarov 	/* Set state to "waiting for the first packet" */
1782619c5cb6SVlad Zolotarov 	task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1783619c5cb6SVlad Zolotarov 				FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1784619c5cb6SVlad Zolotarov 
1785619c5cb6SVlad Zolotarov 	task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1786853e2bd2SBhanu Gollapudi 
1787853e2bd2SBhanu Gollapudi 	/* Rx Only */
17881101a0d8SBhanu Prakash Gollapudi 	if (task_type != FCOE_TASK_TYPE_READ)
17891101a0d8SBhanu Prakash Gollapudi 		return;
17901101a0d8SBhanu Prakash Gollapudi 
1791619c5cb6SVlad Zolotarov 	sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1792853e2bd2SBhanu Gollapudi 	bd_count = bd_tbl->bd_valid;
17931101a0d8SBhanu Prakash Gollapudi 
17941101a0d8SBhanu Prakash Gollapudi 	if (dev_type == TYPE_DISK) {
1795853e2bd2SBhanu Gollapudi 		if (bd_count == 1) {
1796853e2bd2SBhanu Gollapudi 
1797853e2bd2SBhanu Gollapudi 			struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1798853e2bd2SBhanu Gollapudi 
1799619c5cb6SVlad Zolotarov 			cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1800619c5cb6SVlad Zolotarov 			cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1801619c5cb6SVlad Zolotarov 			cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1802619c5cb6SVlad Zolotarov 			task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1803619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1804619c5cb6SVlad Zolotarov 		} else if (bd_count == 2) {
1805619c5cb6SVlad Zolotarov 			struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1806619c5cb6SVlad Zolotarov 
1807619c5cb6SVlad Zolotarov 			cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1808619c5cb6SVlad Zolotarov 			cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1809619c5cb6SVlad Zolotarov 			cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1810619c5cb6SVlad Zolotarov 
1811619c5cb6SVlad Zolotarov 			fcoe_bd_tbl++;
1812619c5cb6SVlad Zolotarov 			cached_sge->second_buf_addr.lo =
1813853e2bd2SBhanu Gollapudi 						 fcoe_bd_tbl->buf_addr_lo;
1814619c5cb6SVlad Zolotarov 			cached_sge->second_buf_addr.hi =
1815853e2bd2SBhanu Gollapudi 						fcoe_bd_tbl->buf_addr_hi;
1816619c5cb6SVlad Zolotarov 			cached_sge->second_buf_rem = fcoe_bd_tbl->buf_len;
1817619c5cb6SVlad Zolotarov 			task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1818619c5cb6SVlad Zolotarov 				FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1819853e2bd2SBhanu Gollapudi 		} else {
1820853e2bd2SBhanu Gollapudi 
1821619c5cb6SVlad Zolotarov 			sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
1822619c5cb6SVlad Zolotarov 			sgl->mul_sgl.cur_sge_addr.hi =
1823853e2bd2SBhanu Gollapudi 					(u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1824619c5cb6SVlad Zolotarov 			sgl->mul_sgl.sgl_size = bd_count;
1825853e2bd2SBhanu Gollapudi 		}
1826f3820b71SBhanu Prakash Gollapudi 	} else {
1827f3820b71SBhanu Prakash Gollapudi 		sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
1828f3820b71SBhanu Prakash Gollapudi 		sgl->mul_sgl.cur_sge_addr.hi =
1829f3820b71SBhanu Prakash Gollapudi 				(u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1830f3820b71SBhanu Prakash Gollapudi 		sgl->mul_sgl.sgl_size = bd_count;
1831853e2bd2SBhanu Gollapudi 	}
1832853e2bd2SBhanu Gollapudi }
1833853e2bd2SBhanu Gollapudi 
1834853e2bd2SBhanu Gollapudi /**
1835853e2bd2SBhanu Gollapudi  * bnx2fc_setup_task_ctx - allocate and map task context
1836853e2bd2SBhanu Gollapudi  *
1837853e2bd2SBhanu Gollapudi  * @hba:	pointer to adapter structure
1838853e2bd2SBhanu Gollapudi  *
1839853e2bd2SBhanu Gollapudi  * allocate memory for task context, and associated BD table to be used
1840853e2bd2SBhanu Gollapudi  * by firmware
1841853e2bd2SBhanu Gollapudi  *
1842853e2bd2SBhanu Gollapudi  */
1843853e2bd2SBhanu Gollapudi int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
1844853e2bd2SBhanu Gollapudi {
1845853e2bd2SBhanu Gollapudi 	int rc = 0;
1846853e2bd2SBhanu Gollapudi 	struct regpair *task_ctx_bdt;
1847853e2bd2SBhanu Gollapudi 	dma_addr_t addr;
18480eb43b4bSBhanu Prakash Gollapudi 	int task_ctx_arr_sz;
1849853e2bd2SBhanu Gollapudi 	int i;
1850853e2bd2SBhanu Gollapudi 
1851853e2bd2SBhanu Gollapudi 	/*
1852853e2bd2SBhanu Gollapudi 	 * Allocate task context bd table. A page size of bd table
1853853e2bd2SBhanu Gollapudi 	 * can map 256 buffers. Each buffer contains 32 task context
1854853e2bd2SBhanu Gollapudi 	 * entries. Hence the limit with one page is 8192 task context
1855853e2bd2SBhanu Gollapudi 	 * entries.
1856853e2bd2SBhanu Gollapudi 	 */
1857853e2bd2SBhanu Gollapudi 	hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
1858853e2bd2SBhanu Gollapudi 						  PAGE_SIZE,
1859853e2bd2SBhanu Gollapudi 						  &hba->task_ctx_bd_dma,
1860853e2bd2SBhanu Gollapudi 						  GFP_KERNEL);
1861853e2bd2SBhanu Gollapudi 	if (!hba->task_ctx_bd_tbl) {
1862853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "unable to allocate task context BDT\n");
1863853e2bd2SBhanu Gollapudi 		rc = -1;
1864853e2bd2SBhanu Gollapudi 		goto out;
1865853e2bd2SBhanu Gollapudi 	}
1866853e2bd2SBhanu Gollapudi 	memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
1867853e2bd2SBhanu Gollapudi 
1868853e2bd2SBhanu Gollapudi 	/*
1869853e2bd2SBhanu Gollapudi 	 * Allocate task_ctx which is an array of pointers pointing to
1870853e2bd2SBhanu Gollapudi 	 * a page containing 32 task contexts
1871853e2bd2SBhanu Gollapudi 	 */
18720eb43b4bSBhanu Prakash Gollapudi 	task_ctx_arr_sz = (hba->max_tasks / BNX2FC_TASKS_PER_PAGE);
18730eb43b4bSBhanu Prakash Gollapudi 	hba->task_ctx = kzalloc((task_ctx_arr_sz * sizeof(void *)),
1874853e2bd2SBhanu Gollapudi 				 GFP_KERNEL);
1875853e2bd2SBhanu Gollapudi 	if (!hba->task_ctx) {
1876853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "unable to allocate task context array\n");
1877853e2bd2SBhanu Gollapudi 		rc = -1;
1878853e2bd2SBhanu Gollapudi 		goto out1;
1879853e2bd2SBhanu Gollapudi 	}
1880853e2bd2SBhanu Gollapudi 
1881853e2bd2SBhanu Gollapudi 	/*
1882853e2bd2SBhanu Gollapudi 	 * Allocate task_ctx_dma which is an array of dma addresses
1883853e2bd2SBhanu Gollapudi 	 */
18840eb43b4bSBhanu Prakash Gollapudi 	hba->task_ctx_dma = kmalloc((task_ctx_arr_sz *
1885853e2bd2SBhanu Gollapudi 					sizeof(dma_addr_t)), GFP_KERNEL);
1886853e2bd2SBhanu Gollapudi 	if (!hba->task_ctx_dma) {
1887853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "unable to alloc context mapping array\n");
1888853e2bd2SBhanu Gollapudi 		rc = -1;
1889853e2bd2SBhanu Gollapudi 		goto out2;
1890853e2bd2SBhanu Gollapudi 	}
1891853e2bd2SBhanu Gollapudi 
1892853e2bd2SBhanu Gollapudi 	task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
18930eb43b4bSBhanu Prakash Gollapudi 	for (i = 0; i < task_ctx_arr_sz; i++) {
1894853e2bd2SBhanu Gollapudi 
1895853e2bd2SBhanu Gollapudi 		hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
1896853e2bd2SBhanu Gollapudi 						      PAGE_SIZE,
1897853e2bd2SBhanu Gollapudi 						      &hba->task_ctx_dma[i],
1898853e2bd2SBhanu Gollapudi 						      GFP_KERNEL);
1899853e2bd2SBhanu Gollapudi 		if (!hba->task_ctx[i]) {
1900853e2bd2SBhanu Gollapudi 			printk(KERN_ERR PFX "unable to alloc task context\n");
1901853e2bd2SBhanu Gollapudi 			rc = -1;
1902853e2bd2SBhanu Gollapudi 			goto out3;
1903853e2bd2SBhanu Gollapudi 		}
1904853e2bd2SBhanu Gollapudi 		memset(hba->task_ctx[i], 0, PAGE_SIZE);
1905853e2bd2SBhanu Gollapudi 		addr = (u64)hba->task_ctx_dma[i];
1906853e2bd2SBhanu Gollapudi 		task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
1907853e2bd2SBhanu Gollapudi 		task_ctx_bdt->lo = cpu_to_le32((u32)addr);
1908853e2bd2SBhanu Gollapudi 		task_ctx_bdt++;
1909853e2bd2SBhanu Gollapudi 	}
1910853e2bd2SBhanu Gollapudi 	return 0;
1911853e2bd2SBhanu Gollapudi 
1912853e2bd2SBhanu Gollapudi out3:
19130eb43b4bSBhanu Prakash Gollapudi 	for (i = 0; i < task_ctx_arr_sz; i++) {
1914853e2bd2SBhanu Gollapudi 		if (hba->task_ctx[i]) {
1915853e2bd2SBhanu Gollapudi 
1916853e2bd2SBhanu Gollapudi 			dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1917853e2bd2SBhanu Gollapudi 				hba->task_ctx[i], hba->task_ctx_dma[i]);
1918853e2bd2SBhanu Gollapudi 			hba->task_ctx[i] = NULL;
1919853e2bd2SBhanu Gollapudi 		}
1920853e2bd2SBhanu Gollapudi 	}
1921853e2bd2SBhanu Gollapudi 
1922853e2bd2SBhanu Gollapudi 	kfree(hba->task_ctx_dma);
1923853e2bd2SBhanu Gollapudi 	hba->task_ctx_dma = NULL;
1924853e2bd2SBhanu Gollapudi out2:
1925853e2bd2SBhanu Gollapudi 	kfree(hba->task_ctx);
1926853e2bd2SBhanu Gollapudi 	hba->task_ctx = NULL;
1927853e2bd2SBhanu Gollapudi out1:
1928853e2bd2SBhanu Gollapudi 	dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1929853e2bd2SBhanu Gollapudi 			hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
1930853e2bd2SBhanu Gollapudi 	hba->task_ctx_bd_tbl = NULL;
1931853e2bd2SBhanu Gollapudi out:
1932853e2bd2SBhanu Gollapudi 	return rc;
1933853e2bd2SBhanu Gollapudi }
1934853e2bd2SBhanu Gollapudi 
1935853e2bd2SBhanu Gollapudi void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
1936853e2bd2SBhanu Gollapudi {
19370eb43b4bSBhanu Prakash Gollapudi 	int task_ctx_arr_sz;
1938853e2bd2SBhanu Gollapudi 	int i;
1939853e2bd2SBhanu Gollapudi 
1940853e2bd2SBhanu Gollapudi 	if (hba->task_ctx_bd_tbl) {
1941853e2bd2SBhanu Gollapudi 		dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1942853e2bd2SBhanu Gollapudi 				    hba->task_ctx_bd_tbl,
1943853e2bd2SBhanu Gollapudi 				    hba->task_ctx_bd_dma);
1944853e2bd2SBhanu Gollapudi 		hba->task_ctx_bd_tbl = NULL;
1945853e2bd2SBhanu Gollapudi 	}
1946853e2bd2SBhanu Gollapudi 
19470eb43b4bSBhanu Prakash Gollapudi 	task_ctx_arr_sz = (hba->max_tasks / BNX2FC_TASKS_PER_PAGE);
1948853e2bd2SBhanu Gollapudi 	if (hba->task_ctx) {
19490eb43b4bSBhanu Prakash Gollapudi 		for (i = 0; i < task_ctx_arr_sz; i++) {
1950853e2bd2SBhanu Gollapudi 			if (hba->task_ctx[i]) {
1951853e2bd2SBhanu Gollapudi 				dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1952853e2bd2SBhanu Gollapudi 						    hba->task_ctx[i],
1953853e2bd2SBhanu Gollapudi 						    hba->task_ctx_dma[i]);
1954853e2bd2SBhanu Gollapudi 				hba->task_ctx[i] = NULL;
1955853e2bd2SBhanu Gollapudi 			}
1956853e2bd2SBhanu Gollapudi 		}
1957853e2bd2SBhanu Gollapudi 		kfree(hba->task_ctx);
1958853e2bd2SBhanu Gollapudi 		hba->task_ctx = NULL;
1959853e2bd2SBhanu Gollapudi 	}
1960853e2bd2SBhanu Gollapudi 
1961853e2bd2SBhanu Gollapudi 	kfree(hba->task_ctx_dma);
1962853e2bd2SBhanu Gollapudi 	hba->task_ctx_dma = NULL;
1963853e2bd2SBhanu Gollapudi }
1964853e2bd2SBhanu Gollapudi 
1965853e2bd2SBhanu Gollapudi static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
1966853e2bd2SBhanu Gollapudi {
1967853e2bd2SBhanu Gollapudi 	int i;
1968853e2bd2SBhanu Gollapudi 	int segment_count;
1969853e2bd2SBhanu Gollapudi 	u32 *pbl;
1970853e2bd2SBhanu Gollapudi 
197191d9f809SMaurizio Lombardi 	if (hba->hash_tbl_segments) {
1972853e2bd2SBhanu Gollapudi 
1973853e2bd2SBhanu Gollapudi 		pbl = hba->hash_tbl_pbl;
197491d9f809SMaurizio Lombardi 		if (pbl) {
197591d9f809SMaurizio Lombardi 			segment_count = hba->hash_tbl_segment_count;
1976853e2bd2SBhanu Gollapudi 			for (i = 0; i < segment_count; ++i) {
1977853e2bd2SBhanu Gollapudi 				dma_addr_t dma_address;
1978853e2bd2SBhanu Gollapudi 
1979853e2bd2SBhanu Gollapudi 				dma_address = le32_to_cpu(*pbl);
1980853e2bd2SBhanu Gollapudi 				++pbl;
1981853e2bd2SBhanu Gollapudi 				dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
1982853e2bd2SBhanu Gollapudi 				++pbl;
1983853e2bd2SBhanu Gollapudi 				dma_free_coherent(&hba->pcidev->dev,
1984853e2bd2SBhanu Gollapudi 						  BNX2FC_HASH_TBL_CHUNK_SIZE,
1985853e2bd2SBhanu Gollapudi 						  hba->hash_tbl_segments[i],
1986853e2bd2SBhanu Gollapudi 						  dma_address);
198791d9f809SMaurizio Lombardi 			}
198891d9f809SMaurizio Lombardi 		}
1989853e2bd2SBhanu Gollapudi 
199091d9f809SMaurizio Lombardi 		kfree(hba->hash_tbl_segments);
199191d9f809SMaurizio Lombardi 		hba->hash_tbl_segments = NULL;
1992853e2bd2SBhanu Gollapudi 	}
1993853e2bd2SBhanu Gollapudi 
1994853e2bd2SBhanu Gollapudi 	if (hba->hash_tbl_pbl) {
1995853e2bd2SBhanu Gollapudi 		dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1996853e2bd2SBhanu Gollapudi 				    hba->hash_tbl_pbl,
1997853e2bd2SBhanu Gollapudi 				    hba->hash_tbl_pbl_dma);
1998853e2bd2SBhanu Gollapudi 		hba->hash_tbl_pbl = NULL;
1999853e2bd2SBhanu Gollapudi 	}
2000853e2bd2SBhanu Gollapudi }
2001853e2bd2SBhanu Gollapudi 
2002853e2bd2SBhanu Gollapudi static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
2003853e2bd2SBhanu Gollapudi {
2004853e2bd2SBhanu Gollapudi 	int i;
2005853e2bd2SBhanu Gollapudi 	int hash_table_size;
2006853e2bd2SBhanu Gollapudi 	int segment_count;
2007853e2bd2SBhanu Gollapudi 	int segment_array_size;
2008853e2bd2SBhanu Gollapudi 	int dma_segment_array_size;
2009853e2bd2SBhanu Gollapudi 	dma_addr_t *dma_segment_array;
2010853e2bd2SBhanu Gollapudi 	u32 *pbl;
2011853e2bd2SBhanu Gollapudi 
2012853e2bd2SBhanu Gollapudi 	hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
2013853e2bd2SBhanu Gollapudi 		sizeof(struct fcoe_hash_table_entry);
2014853e2bd2SBhanu Gollapudi 
2015853e2bd2SBhanu Gollapudi 	segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
2016853e2bd2SBhanu Gollapudi 	segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
2017853e2bd2SBhanu Gollapudi 	hba->hash_tbl_segment_count = segment_count;
2018853e2bd2SBhanu Gollapudi 
2019853e2bd2SBhanu Gollapudi 	segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
2020853e2bd2SBhanu Gollapudi 	hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
2021853e2bd2SBhanu Gollapudi 	if (!hba->hash_tbl_segments) {
2022853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "hash table pointers alloc failed\n");
2023853e2bd2SBhanu Gollapudi 		return -ENOMEM;
2024853e2bd2SBhanu Gollapudi 	}
2025853e2bd2SBhanu Gollapudi 	dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
2026853e2bd2SBhanu Gollapudi 	dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
2027853e2bd2SBhanu Gollapudi 	if (!dma_segment_array) {
2028853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
2029*fdbcbcabSMaurizio Lombardi 		goto cleanup_ht;
2030853e2bd2SBhanu Gollapudi 	}
2031853e2bd2SBhanu Gollapudi 
2032853e2bd2SBhanu Gollapudi 	for (i = 0; i < segment_count; ++i) {
2033853e2bd2SBhanu Gollapudi 		hba->hash_tbl_segments[i] =
2034853e2bd2SBhanu Gollapudi 			dma_alloc_coherent(&hba->pcidev->dev,
2035853e2bd2SBhanu Gollapudi 					   BNX2FC_HASH_TBL_CHUNK_SIZE,
2036853e2bd2SBhanu Gollapudi 					   &dma_segment_array[i],
2037853e2bd2SBhanu Gollapudi 					   GFP_KERNEL);
2038853e2bd2SBhanu Gollapudi 		if (!hba->hash_tbl_segments[i]) {
2039853e2bd2SBhanu Gollapudi 			printk(KERN_ERR PFX "hash segment alloc failed\n");
2040*fdbcbcabSMaurizio Lombardi 			goto cleanup_dma;
2041853e2bd2SBhanu Gollapudi 		}
2042853e2bd2SBhanu Gollapudi 		memset(hba->hash_tbl_segments[i], 0,
2043853e2bd2SBhanu Gollapudi 		       BNX2FC_HASH_TBL_CHUNK_SIZE);
2044853e2bd2SBhanu Gollapudi 	}
2045853e2bd2SBhanu Gollapudi 
2046853e2bd2SBhanu Gollapudi 	hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev,
2047853e2bd2SBhanu Gollapudi 					       PAGE_SIZE,
2048853e2bd2SBhanu Gollapudi 					       &hba->hash_tbl_pbl_dma,
2049853e2bd2SBhanu Gollapudi 					       GFP_KERNEL);
2050853e2bd2SBhanu Gollapudi 	if (!hba->hash_tbl_pbl) {
2051853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "hash table pbl alloc failed\n");
2052*fdbcbcabSMaurizio Lombardi 		goto cleanup_dma;
2053853e2bd2SBhanu Gollapudi 	}
2054853e2bd2SBhanu Gollapudi 	memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
2055853e2bd2SBhanu Gollapudi 
2056853e2bd2SBhanu Gollapudi 	pbl = hba->hash_tbl_pbl;
2057853e2bd2SBhanu Gollapudi 	for (i = 0; i < segment_count; ++i) {
2058853e2bd2SBhanu Gollapudi 		u64 paddr = dma_segment_array[i];
2059853e2bd2SBhanu Gollapudi 		*pbl = cpu_to_le32((u32) paddr);
2060853e2bd2SBhanu Gollapudi 		++pbl;
2061853e2bd2SBhanu Gollapudi 		*pbl = cpu_to_le32((u32) (paddr >> 32));
2062853e2bd2SBhanu Gollapudi 		++pbl;
2063853e2bd2SBhanu Gollapudi 	}
2064853e2bd2SBhanu Gollapudi 	pbl = hba->hash_tbl_pbl;
2065853e2bd2SBhanu Gollapudi 	i = 0;
2066853e2bd2SBhanu Gollapudi 	while (*pbl && *(pbl + 1)) {
2067853e2bd2SBhanu Gollapudi 		u32 lo;
2068853e2bd2SBhanu Gollapudi 		u32 hi;
2069853e2bd2SBhanu Gollapudi 		lo = *pbl;
2070853e2bd2SBhanu Gollapudi 		++pbl;
2071853e2bd2SBhanu Gollapudi 		hi = *pbl;
2072853e2bd2SBhanu Gollapudi 		++pbl;
2073853e2bd2SBhanu Gollapudi 		++i;
2074853e2bd2SBhanu Gollapudi 	}
2075853e2bd2SBhanu Gollapudi 	kfree(dma_segment_array);
2076853e2bd2SBhanu Gollapudi 	return 0;
2077*fdbcbcabSMaurizio Lombardi 
2078*fdbcbcabSMaurizio Lombardi cleanup_dma:
2079*fdbcbcabSMaurizio Lombardi 	for (i = 0; i < segment_count; ++i) {
2080*fdbcbcabSMaurizio Lombardi 		if (hba->hash_tbl_segments[i])
2081*fdbcbcabSMaurizio Lombardi 			dma_free_coherent(&hba->pcidev->dev,
2082*fdbcbcabSMaurizio Lombardi 					    BNX2FC_HASH_TBL_CHUNK_SIZE,
2083*fdbcbcabSMaurizio Lombardi 					    hba->hash_tbl_segments[i],
2084*fdbcbcabSMaurizio Lombardi 					    dma_segment_array[i]);
2085*fdbcbcabSMaurizio Lombardi 	}
2086*fdbcbcabSMaurizio Lombardi 
2087*fdbcbcabSMaurizio Lombardi 	kfree(dma_segment_array);
2088*fdbcbcabSMaurizio Lombardi 
2089*fdbcbcabSMaurizio Lombardi cleanup_ht:
2090*fdbcbcabSMaurizio Lombardi 	kfree(hba->hash_tbl_segments);
2091*fdbcbcabSMaurizio Lombardi 	hba->hash_tbl_segments = NULL;
2092*fdbcbcabSMaurizio Lombardi 	return -ENOMEM;
2093853e2bd2SBhanu Gollapudi }
2094853e2bd2SBhanu Gollapudi 
2095853e2bd2SBhanu Gollapudi /**
2096853e2bd2SBhanu Gollapudi  * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
2097853e2bd2SBhanu Gollapudi  *
2098853e2bd2SBhanu Gollapudi  * @hba:	Pointer to adapter structure
2099853e2bd2SBhanu Gollapudi  *
2100853e2bd2SBhanu Gollapudi  */
2101853e2bd2SBhanu Gollapudi int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
2102853e2bd2SBhanu Gollapudi {
2103853e2bd2SBhanu Gollapudi 	u64 addr;
2104853e2bd2SBhanu Gollapudi 	u32 mem_size;
2105853e2bd2SBhanu Gollapudi 	int i;
2106853e2bd2SBhanu Gollapudi 
2107853e2bd2SBhanu Gollapudi 	if (bnx2fc_allocate_hash_table(hba))
2108853e2bd2SBhanu Gollapudi 		return -ENOMEM;
2109853e2bd2SBhanu Gollapudi 
2110853e2bd2SBhanu Gollapudi 	mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2111853e2bd2SBhanu Gollapudi 	hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2112853e2bd2SBhanu Gollapudi 						  &hba->t2_hash_tbl_ptr_dma,
2113853e2bd2SBhanu Gollapudi 						  GFP_KERNEL);
2114853e2bd2SBhanu Gollapudi 	if (!hba->t2_hash_tbl_ptr) {
2115853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
2116853e2bd2SBhanu Gollapudi 		bnx2fc_free_fw_resc(hba);
2117853e2bd2SBhanu Gollapudi 		return -ENOMEM;
2118853e2bd2SBhanu Gollapudi 	}
2119853e2bd2SBhanu Gollapudi 	memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
2120853e2bd2SBhanu Gollapudi 
2121853e2bd2SBhanu Gollapudi 	mem_size = BNX2FC_NUM_MAX_SESS *
2122853e2bd2SBhanu Gollapudi 				sizeof(struct fcoe_t2_hash_table_entry);
2123853e2bd2SBhanu Gollapudi 	hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2124853e2bd2SBhanu Gollapudi 					      &hba->t2_hash_tbl_dma,
2125853e2bd2SBhanu Gollapudi 					      GFP_KERNEL);
2126853e2bd2SBhanu Gollapudi 	if (!hba->t2_hash_tbl) {
2127853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
2128853e2bd2SBhanu Gollapudi 		bnx2fc_free_fw_resc(hba);
2129853e2bd2SBhanu Gollapudi 		return -ENOMEM;
2130853e2bd2SBhanu Gollapudi 	}
2131853e2bd2SBhanu Gollapudi 	memset(hba->t2_hash_tbl, 0x00, mem_size);
2132853e2bd2SBhanu Gollapudi 	for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
2133853e2bd2SBhanu Gollapudi 		addr = (unsigned long) hba->t2_hash_tbl_dma +
2134853e2bd2SBhanu Gollapudi 			 ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
2135853e2bd2SBhanu Gollapudi 		hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
2136853e2bd2SBhanu Gollapudi 		hba->t2_hash_tbl[i].next.hi = addr >> 32;
2137853e2bd2SBhanu Gollapudi 	}
2138853e2bd2SBhanu Gollapudi 
2139853e2bd2SBhanu Gollapudi 	hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
2140853e2bd2SBhanu Gollapudi 					       PAGE_SIZE, &hba->dummy_buf_dma,
2141853e2bd2SBhanu Gollapudi 					       GFP_KERNEL);
2142853e2bd2SBhanu Gollapudi 	if (!hba->dummy_buffer) {
2143853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
2144853e2bd2SBhanu Gollapudi 		bnx2fc_free_fw_resc(hba);
2145853e2bd2SBhanu Gollapudi 		return -ENOMEM;
2146853e2bd2SBhanu Gollapudi 	}
2147853e2bd2SBhanu Gollapudi 
2148853e2bd2SBhanu Gollapudi 	hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
2149853e2bd2SBhanu Gollapudi 					       PAGE_SIZE,
2150853e2bd2SBhanu Gollapudi 					       &hba->stats_buf_dma,
2151853e2bd2SBhanu Gollapudi 					       GFP_KERNEL);
2152853e2bd2SBhanu Gollapudi 	if (!hba->stats_buffer) {
2153853e2bd2SBhanu Gollapudi 		printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
2154853e2bd2SBhanu Gollapudi 		bnx2fc_free_fw_resc(hba);
2155853e2bd2SBhanu Gollapudi 		return -ENOMEM;
2156853e2bd2SBhanu Gollapudi 	}
2157853e2bd2SBhanu Gollapudi 	memset(hba->stats_buffer, 0x00, PAGE_SIZE);
2158853e2bd2SBhanu Gollapudi 
2159853e2bd2SBhanu Gollapudi 	return 0;
2160853e2bd2SBhanu Gollapudi }
2161853e2bd2SBhanu Gollapudi 
2162853e2bd2SBhanu Gollapudi void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
2163853e2bd2SBhanu Gollapudi {
2164853e2bd2SBhanu Gollapudi 	u32 mem_size;
2165853e2bd2SBhanu Gollapudi 
2166853e2bd2SBhanu Gollapudi 	if (hba->stats_buffer) {
2167853e2bd2SBhanu Gollapudi 		dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2168853e2bd2SBhanu Gollapudi 				  hba->stats_buffer, hba->stats_buf_dma);
2169853e2bd2SBhanu Gollapudi 		hba->stats_buffer = NULL;
2170853e2bd2SBhanu Gollapudi 	}
2171853e2bd2SBhanu Gollapudi 
2172853e2bd2SBhanu Gollapudi 	if (hba->dummy_buffer) {
2173853e2bd2SBhanu Gollapudi 		dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2174853e2bd2SBhanu Gollapudi 				  hba->dummy_buffer, hba->dummy_buf_dma);
2175853e2bd2SBhanu Gollapudi 		hba->dummy_buffer = NULL;
2176853e2bd2SBhanu Gollapudi 	}
2177853e2bd2SBhanu Gollapudi 
2178853e2bd2SBhanu Gollapudi 	if (hba->t2_hash_tbl_ptr) {
2179853e2bd2SBhanu Gollapudi 		mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2180853e2bd2SBhanu Gollapudi 		dma_free_coherent(&hba->pcidev->dev, mem_size,
2181853e2bd2SBhanu Gollapudi 				    hba->t2_hash_tbl_ptr,
2182853e2bd2SBhanu Gollapudi 				    hba->t2_hash_tbl_ptr_dma);
2183853e2bd2SBhanu Gollapudi 		hba->t2_hash_tbl_ptr = NULL;
2184853e2bd2SBhanu Gollapudi 	}
2185853e2bd2SBhanu Gollapudi 
2186853e2bd2SBhanu Gollapudi 	if (hba->t2_hash_tbl) {
2187853e2bd2SBhanu Gollapudi 		mem_size = BNX2FC_NUM_MAX_SESS *
2188853e2bd2SBhanu Gollapudi 			    sizeof(struct fcoe_t2_hash_table_entry);
2189853e2bd2SBhanu Gollapudi 		dma_free_coherent(&hba->pcidev->dev, mem_size,
2190853e2bd2SBhanu Gollapudi 				    hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
2191853e2bd2SBhanu Gollapudi 		hba->t2_hash_tbl = NULL;
2192853e2bd2SBhanu Gollapudi 	}
2193853e2bd2SBhanu Gollapudi 	bnx2fc_free_hash_table(hba);
2194853e2bd2SBhanu Gollapudi }
2195