1de909d87SChad Dupuis /* bnx2fc_hwi.c: QLogic 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
621144b80SChad Dupuis * Copyright (c) 2014-2016 QLogic Corporation
721144b80SChad Dupuis * Copyright (c) 2016-2017 Cavium Inc.
8853e2bd2SBhanu Gollapudi *
9853e2bd2SBhanu Gollapudi * This program is free software; you can redistribute it and/or modify
10853e2bd2SBhanu Gollapudi * it under the terms of the GNU General Public License as published by
11853e2bd2SBhanu Gollapudi * the Free Software Foundation.
12853e2bd2SBhanu Gollapudi *
13853e2bd2SBhanu Gollapudi * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
14853e2bd2SBhanu Gollapudi */
15853e2bd2SBhanu Gollapudi
16853e2bd2SBhanu Gollapudi #include "bnx2fc.h"
17853e2bd2SBhanu Gollapudi
18853e2bd2SBhanu Gollapudi DECLARE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
19853e2bd2SBhanu Gollapudi
20853e2bd2SBhanu Gollapudi static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
21853e2bd2SBhanu Gollapudi struct fcoe_kcqe *new_cqe_kcqe);
22853e2bd2SBhanu Gollapudi static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
23853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe);
24853e2bd2SBhanu Gollapudi static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
25853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe);
26853e2bd2SBhanu Gollapudi static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code);
27853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
28aea71a02SBhanu Prakash Gollapudi struct fcoe_kcqe *destroy_kcqe);
29853e2bd2SBhanu Gollapudi
bnx2fc_send_stat_req(struct bnx2fc_hba * hba)30853e2bd2SBhanu Gollapudi int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
31853e2bd2SBhanu Gollapudi {
32853e2bd2SBhanu Gollapudi struct fcoe_kwqe_stat stat_req;
33853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2];
34853e2bd2SBhanu Gollapudi int num_kwqes = 1;
35853e2bd2SBhanu Gollapudi int rc = 0;
36853e2bd2SBhanu Gollapudi
37853e2bd2SBhanu Gollapudi memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat));
38853e2bd2SBhanu Gollapudi stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT;
39853e2bd2SBhanu Gollapudi stat_req.hdr.flags =
40853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
41853e2bd2SBhanu Gollapudi
42853e2bd2SBhanu Gollapudi stat_req.stat_params_addr_lo = (u32) hba->stats_buf_dma;
43853e2bd2SBhanu Gollapudi stat_req.stat_params_addr_hi = (u32) ((u64)hba->stats_buf_dma >> 32);
44853e2bd2SBhanu Gollapudi
45853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &stat_req;
46853e2bd2SBhanu Gollapudi
47853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes)
48853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
49853e2bd2SBhanu Gollapudi
50853e2bd2SBhanu Gollapudi return rc;
51853e2bd2SBhanu Gollapudi }
52853e2bd2SBhanu Gollapudi
53853e2bd2SBhanu Gollapudi /**
54853e2bd2SBhanu Gollapudi * bnx2fc_send_fw_fcoe_init_msg - initiates initial handshake with FCoE f/w
55853e2bd2SBhanu Gollapudi *
56853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer
57853e2bd2SBhanu Gollapudi *
58853e2bd2SBhanu Gollapudi * Send down FCoE firmware init KWQEs which initiates the initial handshake
59853e2bd2SBhanu Gollapudi * with the f/w.
60853e2bd2SBhanu Gollapudi *
61853e2bd2SBhanu Gollapudi */
bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba * hba)62853e2bd2SBhanu Gollapudi int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
63853e2bd2SBhanu Gollapudi {
64853e2bd2SBhanu Gollapudi struct fcoe_kwqe_init1 fcoe_init1;
65853e2bd2SBhanu Gollapudi struct fcoe_kwqe_init2 fcoe_init2;
66853e2bd2SBhanu Gollapudi struct fcoe_kwqe_init3 fcoe_init3;
67853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[3];
68853e2bd2SBhanu Gollapudi int num_kwqes = 3;
69853e2bd2SBhanu Gollapudi int rc = 0;
70853e2bd2SBhanu Gollapudi
71853e2bd2SBhanu Gollapudi if (!hba->cnic) {
72aea71a02SBhanu Prakash Gollapudi printk(KERN_ERR PFX "hba->cnic NULL during fcoe fw init\n");
73853e2bd2SBhanu Gollapudi return -ENODEV;
74853e2bd2SBhanu Gollapudi }
75853e2bd2SBhanu Gollapudi
76853e2bd2SBhanu Gollapudi /* fill init1 KWQE */
77853e2bd2SBhanu Gollapudi memset(&fcoe_init1, 0x00, sizeof(struct fcoe_kwqe_init1));
78853e2bd2SBhanu Gollapudi fcoe_init1.hdr.op_code = FCOE_KWQE_OPCODE_INIT1;
79853e2bd2SBhanu Gollapudi fcoe_init1.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
80853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
81853e2bd2SBhanu Gollapudi
820eb43b4bSBhanu Prakash Gollapudi fcoe_init1.num_tasks = hba->max_tasks;
83853e2bd2SBhanu Gollapudi fcoe_init1.sq_num_wqes = BNX2FC_SQ_WQES_MAX;
84853e2bd2SBhanu Gollapudi fcoe_init1.rq_num_wqes = BNX2FC_RQ_WQES_MAX;
85853e2bd2SBhanu Gollapudi fcoe_init1.rq_buffer_log_size = BNX2FC_RQ_BUF_LOG_SZ;
86853e2bd2SBhanu Gollapudi fcoe_init1.cq_num_wqes = BNX2FC_CQ_WQES_MAX;
87853e2bd2SBhanu Gollapudi fcoe_init1.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
88853e2bd2SBhanu Gollapudi fcoe_init1.dummy_buffer_addr_hi = (u32) ((u64)hba->dummy_buf_dma >> 32);
89853e2bd2SBhanu Gollapudi fcoe_init1.task_list_pbl_addr_lo = (u32) hba->task_ctx_bd_dma;
90853e2bd2SBhanu Gollapudi fcoe_init1.task_list_pbl_addr_hi =
91853e2bd2SBhanu Gollapudi (u32) ((u64) hba->task_ctx_bd_dma >> 32);
921294bfe6SBhanu Gollapudi fcoe_init1.mtu = BNX2FC_MINI_JUMBO_MTU;
93853e2bd2SBhanu Gollapudi
94853e2bd2SBhanu Gollapudi fcoe_init1.flags = (PAGE_SHIFT <<
95853e2bd2SBhanu Gollapudi FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT);
96853e2bd2SBhanu Gollapudi
97853e2bd2SBhanu Gollapudi fcoe_init1.num_sessions_log = BNX2FC_NUM_MAX_SESS_LOG;
98853e2bd2SBhanu Gollapudi
99853e2bd2SBhanu Gollapudi /* fill init2 KWQE */
100853e2bd2SBhanu Gollapudi memset(&fcoe_init2, 0x00, sizeof(struct fcoe_kwqe_init2));
101853e2bd2SBhanu Gollapudi fcoe_init2.hdr.op_code = FCOE_KWQE_OPCODE_INIT2;
102853e2bd2SBhanu Gollapudi fcoe_init2.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
103853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
104853e2bd2SBhanu Gollapudi
105619c5cb6SVlad Zolotarov fcoe_init2.hsi_major_version = FCOE_HSI_MAJOR_VERSION;
106619c5cb6SVlad Zolotarov fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION;
107619c5cb6SVlad Zolotarov
108aea71a02SBhanu Prakash Gollapudi
109853e2bd2SBhanu Gollapudi fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
110853e2bd2SBhanu Gollapudi fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
111853e2bd2SBhanu Gollapudi ((u64) hba->hash_tbl_pbl_dma >> 32);
112853e2bd2SBhanu Gollapudi
113853e2bd2SBhanu Gollapudi fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma;
114853e2bd2SBhanu Gollapudi fcoe_init2.t2_hash_tbl_addr_hi = (u32)
115853e2bd2SBhanu Gollapudi ((u64) hba->t2_hash_tbl_dma >> 32);
116853e2bd2SBhanu Gollapudi
117853e2bd2SBhanu Gollapudi fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma;
118853e2bd2SBhanu Gollapudi fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32)
119853e2bd2SBhanu Gollapudi ((u64) hba->t2_hash_tbl_ptr_dma >> 32);
120853e2bd2SBhanu Gollapudi
121853e2bd2SBhanu Gollapudi fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS;
122853e2bd2SBhanu Gollapudi
123853e2bd2SBhanu Gollapudi /* fill init3 KWQE */
124853e2bd2SBhanu Gollapudi memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3));
125853e2bd2SBhanu Gollapudi fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3;
126853e2bd2SBhanu Gollapudi fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
127853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
128853e2bd2SBhanu Gollapudi fcoe_init3.error_bit_map_lo = 0xffffffff;
129853e2bd2SBhanu Gollapudi fcoe_init3.error_bit_map_hi = 0xffffffff;
130853e2bd2SBhanu Gollapudi
131353c2adeSBhanu Prakash Gollapudi /*
132353c2adeSBhanu Prakash Gollapudi * enable both cached connection and cached tasks
133353c2adeSBhanu Prakash Gollapudi * 0 = none, 1 = cached connection, 2 = cached tasks, 3 = both
134353c2adeSBhanu Prakash Gollapudi */
135353c2adeSBhanu Prakash Gollapudi fcoe_init3.perf_config = 3;
136853e2bd2SBhanu Gollapudi
137853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &fcoe_init1;
138853e2bd2SBhanu Gollapudi kwqe_arr[1] = (struct kwqe *) &fcoe_init2;
139853e2bd2SBhanu Gollapudi kwqe_arr[2] = (struct kwqe *) &fcoe_init3;
140853e2bd2SBhanu Gollapudi
141853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes)
142853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
143853e2bd2SBhanu Gollapudi
144853e2bd2SBhanu Gollapudi return rc;
145853e2bd2SBhanu Gollapudi }
bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba * hba)146853e2bd2SBhanu Gollapudi int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba)
147853e2bd2SBhanu Gollapudi {
148853e2bd2SBhanu Gollapudi struct fcoe_kwqe_destroy fcoe_destroy;
149853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2];
150853e2bd2SBhanu Gollapudi int num_kwqes = 1;
151853e2bd2SBhanu Gollapudi int rc = -1;
152853e2bd2SBhanu Gollapudi
153853e2bd2SBhanu Gollapudi /* fill destroy KWQE */
154853e2bd2SBhanu Gollapudi memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy));
155853e2bd2SBhanu Gollapudi fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY;
156853e2bd2SBhanu Gollapudi fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
157853e2bd2SBhanu Gollapudi FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
158853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &fcoe_destroy;
159853e2bd2SBhanu Gollapudi
160853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes)
161853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
162853e2bd2SBhanu Gollapudi return rc;
163853e2bd2SBhanu Gollapudi }
164853e2bd2SBhanu Gollapudi
165853e2bd2SBhanu Gollapudi /**
166853e2bd2SBhanu Gollapudi * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process
167853e2bd2SBhanu Gollapudi *
168853e2bd2SBhanu Gollapudi * @port: port structure pointer
169853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer
170853e2bd2SBhanu Gollapudi */
bnx2fc_send_session_ofld_req(struct fcoe_port * port,struct bnx2fc_rport * tgt)171853e2bd2SBhanu Gollapudi int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
172853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt)
173853e2bd2SBhanu Gollapudi {
174853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport;
175aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv;
176fd8f8902SRobert Love struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
177aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba;
178853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[4];
179853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload1 ofld_req1;
180853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload2 ofld_req2;
181853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload3 ofld_req3;
182853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_offload4 ofld_req4;
183853e2bd2SBhanu Gollapudi struct fc_rport_priv *rdata = tgt->rdata;
184853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport;
185853e2bd2SBhanu Gollapudi int num_kwqes = 4;
186853e2bd2SBhanu Gollapudi u32 port_id;
187853e2bd2SBhanu Gollapudi int rc = 0;
188853e2bd2SBhanu Gollapudi u16 conn_id;
189853e2bd2SBhanu Gollapudi
190853e2bd2SBhanu Gollapudi /* Initialize offload request 1 structure */
191853e2bd2SBhanu Gollapudi memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
192853e2bd2SBhanu Gollapudi
193853e2bd2SBhanu Gollapudi ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
194853e2bd2SBhanu Gollapudi ofld_req1.hdr.flags =
195853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
196853e2bd2SBhanu Gollapudi
197853e2bd2SBhanu Gollapudi
198853e2bd2SBhanu Gollapudi conn_id = (u16)tgt->fcoe_conn_id;
199853e2bd2SBhanu Gollapudi ofld_req1.fcoe_conn_id = conn_id;
200853e2bd2SBhanu Gollapudi
201853e2bd2SBhanu Gollapudi
202853e2bd2SBhanu Gollapudi ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
203853e2bd2SBhanu Gollapudi ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
204853e2bd2SBhanu Gollapudi
205853e2bd2SBhanu Gollapudi ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
206853e2bd2SBhanu Gollapudi ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
207853e2bd2SBhanu Gollapudi
208853e2bd2SBhanu Gollapudi ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
209853e2bd2SBhanu Gollapudi ofld_req1.rq_first_pbe_addr_hi =
210853e2bd2SBhanu Gollapudi (u32)((u64) tgt->rq_dma >> 32);
211853e2bd2SBhanu Gollapudi
212853e2bd2SBhanu Gollapudi ofld_req1.rq_prod = 0x8000;
213853e2bd2SBhanu Gollapudi
214853e2bd2SBhanu Gollapudi /* Initialize offload request 2 structure */
215853e2bd2SBhanu Gollapudi memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
216853e2bd2SBhanu Gollapudi
217853e2bd2SBhanu Gollapudi ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
218853e2bd2SBhanu Gollapudi ofld_req2.hdr.flags =
219853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
220853e2bd2SBhanu Gollapudi
221853e2bd2SBhanu Gollapudi ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
222853e2bd2SBhanu Gollapudi
223853e2bd2SBhanu Gollapudi ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
224853e2bd2SBhanu Gollapudi ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
225853e2bd2SBhanu Gollapudi
226853e2bd2SBhanu Gollapudi ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
227853e2bd2SBhanu Gollapudi ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
228853e2bd2SBhanu Gollapudi
229853e2bd2SBhanu Gollapudi ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
230853e2bd2SBhanu Gollapudi ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
231853e2bd2SBhanu Gollapudi
232853e2bd2SBhanu Gollapudi /* Initialize offload request 3 structure */
233853e2bd2SBhanu Gollapudi memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
234853e2bd2SBhanu Gollapudi
235853e2bd2SBhanu Gollapudi ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
236853e2bd2SBhanu Gollapudi ofld_req3.hdr.flags =
237853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
238853e2bd2SBhanu Gollapudi
239aea71a02SBhanu Prakash Gollapudi ofld_req3.vlan_tag = interface->vlan_id <<
240853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
241853e2bd2SBhanu Gollapudi ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
242853e2bd2SBhanu Gollapudi
243853e2bd2SBhanu Gollapudi port_id = fc_host_port_id(lport->host);
244853e2bd2SBhanu Gollapudi if (port_id == 0) {
245853e2bd2SBhanu Gollapudi BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
246853e2bd2SBhanu Gollapudi return -EINVAL;
247853e2bd2SBhanu Gollapudi }
248853e2bd2SBhanu Gollapudi
249853e2bd2SBhanu Gollapudi /*
250853e2bd2SBhanu Gollapudi * Store s_id of the initiator for further reference. This will
251853e2bd2SBhanu Gollapudi * be used during disable/destroy during linkdown processing as
252853e2bd2SBhanu Gollapudi * when the lport is reset, the port_id also is reset to 0
253853e2bd2SBhanu Gollapudi */
254853e2bd2SBhanu Gollapudi tgt->sid = port_id;
255853e2bd2SBhanu Gollapudi ofld_req3.s_id[0] = (port_id & 0x000000FF);
256853e2bd2SBhanu Gollapudi ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
257853e2bd2SBhanu Gollapudi ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
258853e2bd2SBhanu Gollapudi
259853e2bd2SBhanu Gollapudi port_id = rport->port_id;
260853e2bd2SBhanu Gollapudi ofld_req3.d_id[0] = (port_id & 0x000000FF);
261853e2bd2SBhanu Gollapudi ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
262853e2bd2SBhanu Gollapudi ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
263853e2bd2SBhanu Gollapudi
264853e2bd2SBhanu Gollapudi ofld_req3.tx_total_conc_seqs = rdata->max_seq;
265853e2bd2SBhanu Gollapudi
266853e2bd2SBhanu Gollapudi ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
267853e2bd2SBhanu Gollapudi ofld_req3.rx_max_fc_pay_len = lport->mfs;
268853e2bd2SBhanu Gollapudi
269853e2bd2SBhanu Gollapudi ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
270853e2bd2SBhanu Gollapudi ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
271853e2bd2SBhanu Gollapudi ofld_req3.rx_open_seqs_exch_c3 = 1;
272853e2bd2SBhanu Gollapudi
273853e2bd2SBhanu Gollapudi ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
274853e2bd2SBhanu Gollapudi ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
275853e2bd2SBhanu Gollapudi
276853e2bd2SBhanu Gollapudi /* set mul_n_port_ids supported flag to 0, until it is supported */
277853e2bd2SBhanu Gollapudi ofld_req3.flags = 0;
278853e2bd2SBhanu Gollapudi /*
279853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
280853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
281853e2bd2SBhanu Gollapudi */
282853e2bd2SBhanu Gollapudi /* Info from PLOGI response */
283853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
284853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
285853e2bd2SBhanu Gollapudi
286853e2bd2SBhanu Gollapudi ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
287853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
288853e2bd2SBhanu Gollapudi
289b252f4c7SBhanu Prakash Gollapudi /*
290b252f4c7SBhanu Prakash Gollapudi * Info from PRLI response, this info is used for sequence level error
291b252f4c7SBhanu Prakash Gollapudi * recovery support
292b252f4c7SBhanu Prakash Gollapudi */
293b252f4c7SBhanu Prakash Gollapudi if (tgt->dev_type == TYPE_TAPE) {
294b252f4c7SBhanu Prakash Gollapudi ofld_req3.flags |= 1 <<
295b252f4c7SBhanu Prakash Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT;
296b252f4c7SBhanu Prakash Gollapudi ofld_req3.flags |= (((rdata->flags & FC_RP_FLAGS_REC_SUPPORTED)
297b252f4c7SBhanu Prakash Gollapudi ? 1 : 0) <<
298b252f4c7SBhanu Prakash Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT);
299b252f4c7SBhanu Prakash Gollapudi }
300b252f4c7SBhanu Prakash Gollapudi
301853e2bd2SBhanu Gollapudi /* vlan flag */
302aea71a02SBhanu Prakash Gollapudi ofld_req3.flags |= (interface->vlan_enabled <<
303853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
304853e2bd2SBhanu Gollapudi
305d7558148SMasanari Iida /* C2_VALID and ACK flags are not set as they are not supported */
306853e2bd2SBhanu Gollapudi
307853e2bd2SBhanu Gollapudi
308853e2bd2SBhanu Gollapudi /* Initialize offload request 4 structure */
309853e2bd2SBhanu Gollapudi memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
310853e2bd2SBhanu Gollapudi ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
311853e2bd2SBhanu Gollapudi ofld_req4.hdr.flags =
312853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
313853e2bd2SBhanu Gollapudi
314853e2bd2SBhanu Gollapudi ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
315853e2bd2SBhanu Gollapudi
316853e2bd2SBhanu Gollapudi
317619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_lo[0] = port->data_src_addr[5];
318853e2bd2SBhanu Gollapudi /* local mac */
319619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_lo[1] = port->data_src_addr[4];
320619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_mid[0] = port->data_src_addr[3];
321619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2];
322619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1];
323619c5cb6SVlad Zolotarov ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0];
324fd8f8902SRobert Love ofld_req4.dst_mac_addr_lo[0] = ctlr->dest_addr[5];
325aea71a02SBhanu Prakash Gollapudi /* fcf mac */
326fd8f8902SRobert Love ofld_req4.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
327fd8f8902SRobert Love ofld_req4.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
328fd8f8902SRobert Love ofld_req4.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
329fd8f8902SRobert Love ofld_req4.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
330fd8f8902SRobert Love ofld_req4.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
331853e2bd2SBhanu Gollapudi
332853e2bd2SBhanu Gollapudi ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
333853e2bd2SBhanu Gollapudi ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
334853e2bd2SBhanu Gollapudi
335853e2bd2SBhanu Gollapudi ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
336853e2bd2SBhanu Gollapudi ofld_req4.confq_pbl_base_addr_hi =
337853e2bd2SBhanu Gollapudi (u32)((u64) tgt->confq_pbl_dma >> 32);
338853e2bd2SBhanu Gollapudi
339853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &ofld_req1;
340853e2bd2SBhanu Gollapudi kwqe_arr[1] = (struct kwqe *) &ofld_req2;
341853e2bd2SBhanu Gollapudi kwqe_arr[2] = (struct kwqe *) &ofld_req3;
342853e2bd2SBhanu Gollapudi kwqe_arr[3] = (struct kwqe *) &ofld_req4;
343853e2bd2SBhanu Gollapudi
344853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes)
345853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
346853e2bd2SBhanu Gollapudi
347853e2bd2SBhanu Gollapudi return rc;
348853e2bd2SBhanu Gollapudi }
349853e2bd2SBhanu Gollapudi
350853e2bd2SBhanu Gollapudi /**
351853e2bd2SBhanu Gollapudi * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
352853e2bd2SBhanu Gollapudi *
353853e2bd2SBhanu Gollapudi * @port: port structure pointer
354853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer
355853e2bd2SBhanu Gollapudi */
bnx2fc_send_session_enable_req(struct fcoe_port * port,struct bnx2fc_rport * tgt)356e7f4fed5SBhanu Prakash Gollapudi int bnx2fc_send_session_enable_req(struct fcoe_port *port,
357853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt)
358853e2bd2SBhanu Gollapudi {
359853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2];
360aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv;
361fd8f8902SRobert Love struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
362aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba;
363853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_enable_disable enbl_req;
364853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport;
365853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport;
366853e2bd2SBhanu Gollapudi int num_kwqes = 1;
367853e2bd2SBhanu Gollapudi int rc = 0;
368853e2bd2SBhanu Gollapudi u32 port_id;
369853e2bd2SBhanu Gollapudi
370853e2bd2SBhanu Gollapudi memset(&enbl_req, 0x00,
371853e2bd2SBhanu Gollapudi sizeof(struct fcoe_kwqe_conn_enable_disable));
372853e2bd2SBhanu Gollapudi enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
373853e2bd2SBhanu Gollapudi enbl_req.hdr.flags =
374853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
375853e2bd2SBhanu Gollapudi
376619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_lo[0] = port->data_src_addr[5];
377853e2bd2SBhanu Gollapudi /* local mac */
378619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_lo[1] = port->data_src_addr[4];
379619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_mid[0] = port->data_src_addr[3];
380619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_mid[1] = port->data_src_addr[2];
381619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_hi[0] = port->data_src_addr[1];
382619c5cb6SVlad Zolotarov enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0];
383619c5cb6SVlad Zolotarov memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
384853e2bd2SBhanu Gollapudi
385fd8f8902SRobert Love enbl_req.dst_mac_addr_lo[0] = ctlr->dest_addr[5];
386fd8f8902SRobert Love enbl_req.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
387fd8f8902SRobert Love enbl_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
388fd8f8902SRobert Love enbl_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
389fd8f8902SRobert Love enbl_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
390fd8f8902SRobert Love enbl_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
391853e2bd2SBhanu Gollapudi
392853e2bd2SBhanu Gollapudi port_id = fc_host_port_id(lport->host);
393853e2bd2SBhanu Gollapudi if (port_id != tgt->sid) {
394853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
395853e2bd2SBhanu Gollapudi "sid = 0x%x\n", port_id, tgt->sid);
396853e2bd2SBhanu Gollapudi port_id = tgt->sid;
397853e2bd2SBhanu Gollapudi }
398853e2bd2SBhanu Gollapudi enbl_req.s_id[0] = (port_id & 0x000000FF);
399853e2bd2SBhanu Gollapudi enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
400853e2bd2SBhanu Gollapudi enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
401853e2bd2SBhanu Gollapudi
402853e2bd2SBhanu Gollapudi port_id = rport->port_id;
403853e2bd2SBhanu Gollapudi enbl_req.d_id[0] = (port_id & 0x000000FF);
404853e2bd2SBhanu Gollapudi enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
405853e2bd2SBhanu Gollapudi enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
406aea71a02SBhanu Prakash Gollapudi enbl_req.vlan_tag = interface->vlan_id <<
407853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
408853e2bd2SBhanu Gollapudi enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
409aea71a02SBhanu Prakash Gollapudi enbl_req.vlan_flag = interface->vlan_enabled;
410853e2bd2SBhanu Gollapudi enbl_req.context_id = tgt->context_id;
411853e2bd2SBhanu Gollapudi enbl_req.conn_id = tgt->fcoe_conn_id;
412853e2bd2SBhanu Gollapudi
413853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &enbl_req;
414853e2bd2SBhanu Gollapudi
415853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes)
416853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
417853e2bd2SBhanu Gollapudi return rc;
418853e2bd2SBhanu Gollapudi }
419853e2bd2SBhanu Gollapudi
420853e2bd2SBhanu Gollapudi /**
421853e2bd2SBhanu Gollapudi * bnx2fc_send_session_disable_req - initiates FCoE Session disable
422853e2bd2SBhanu Gollapudi *
423853e2bd2SBhanu Gollapudi * @port: port structure pointer
424853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer
425853e2bd2SBhanu Gollapudi */
bnx2fc_send_session_disable_req(struct fcoe_port * port,struct bnx2fc_rport * tgt)426853e2bd2SBhanu Gollapudi int bnx2fc_send_session_disable_req(struct fcoe_port *port,
427853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt)
428853e2bd2SBhanu Gollapudi {
429aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv;
430fd8f8902SRobert Love struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
431aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba;
432853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_enable_disable disable_req;
433853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2];
434853e2bd2SBhanu Gollapudi struct fc_rport *rport = tgt->rport;
435853e2bd2SBhanu Gollapudi int num_kwqes = 1;
436853e2bd2SBhanu Gollapudi int rc = 0;
437853e2bd2SBhanu Gollapudi u32 port_id;
438853e2bd2SBhanu Gollapudi
439853e2bd2SBhanu Gollapudi memset(&disable_req, 0x00,
440853e2bd2SBhanu Gollapudi sizeof(struct fcoe_kwqe_conn_enable_disable));
441853e2bd2SBhanu Gollapudi disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
442853e2bd2SBhanu Gollapudi disable_req.hdr.flags =
443853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
444853e2bd2SBhanu Gollapudi
445619c5cb6SVlad Zolotarov disable_req.src_mac_addr_lo[0] = tgt->src_addr[5];
446619c5cb6SVlad Zolotarov disable_req.src_mac_addr_lo[1] = tgt->src_addr[4];
447619c5cb6SVlad Zolotarov disable_req.src_mac_addr_mid[0] = tgt->src_addr[3];
448619c5cb6SVlad Zolotarov disable_req.src_mac_addr_mid[1] = tgt->src_addr[2];
449619c5cb6SVlad Zolotarov disable_req.src_mac_addr_hi[0] = tgt->src_addr[1];
450619c5cb6SVlad Zolotarov disable_req.src_mac_addr_hi[1] = tgt->src_addr[0];
451853e2bd2SBhanu Gollapudi
452fd8f8902SRobert Love disable_req.dst_mac_addr_lo[0] = ctlr->dest_addr[5];
453fd8f8902SRobert Love disable_req.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
454fd8f8902SRobert Love disable_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
455fd8f8902SRobert Love disable_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
456fd8f8902SRobert Love disable_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
457fd8f8902SRobert Love disable_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
458853e2bd2SBhanu Gollapudi
459853e2bd2SBhanu Gollapudi port_id = tgt->sid;
460853e2bd2SBhanu Gollapudi disable_req.s_id[0] = (port_id & 0x000000FF);
461853e2bd2SBhanu Gollapudi disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
462853e2bd2SBhanu Gollapudi disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
463853e2bd2SBhanu Gollapudi
464853e2bd2SBhanu Gollapudi
465853e2bd2SBhanu Gollapudi port_id = rport->port_id;
466853e2bd2SBhanu Gollapudi disable_req.d_id[0] = (port_id & 0x000000FF);
467853e2bd2SBhanu Gollapudi disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
468853e2bd2SBhanu Gollapudi disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
469853e2bd2SBhanu Gollapudi disable_req.context_id = tgt->context_id;
470853e2bd2SBhanu Gollapudi disable_req.conn_id = tgt->fcoe_conn_id;
471aea71a02SBhanu Prakash Gollapudi disable_req.vlan_tag = interface->vlan_id <<
472853e2bd2SBhanu Gollapudi FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
473853e2bd2SBhanu Gollapudi disable_req.vlan_tag |=
474853e2bd2SBhanu Gollapudi 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
475aea71a02SBhanu Prakash Gollapudi disable_req.vlan_flag = interface->vlan_enabled;
476853e2bd2SBhanu Gollapudi
477853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &disable_req;
478853e2bd2SBhanu Gollapudi
479853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes)
480853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
481853e2bd2SBhanu Gollapudi
482853e2bd2SBhanu Gollapudi return rc;
483853e2bd2SBhanu Gollapudi }
484853e2bd2SBhanu Gollapudi
485853e2bd2SBhanu Gollapudi /**
486853e2bd2SBhanu Gollapudi * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
487853e2bd2SBhanu Gollapudi *
4884db2ac3eSLee Jones * @hba: adapter structure pointer
489853e2bd2SBhanu Gollapudi * @tgt: bnx2fc_rport structure pointer
490853e2bd2SBhanu Gollapudi */
bnx2fc_send_session_destroy_req(struct bnx2fc_hba * hba,struct bnx2fc_rport * tgt)491853e2bd2SBhanu Gollapudi int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
492853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt)
493853e2bd2SBhanu Gollapudi {
494853e2bd2SBhanu Gollapudi struct fcoe_kwqe_conn_destroy destroy_req;
495853e2bd2SBhanu Gollapudi struct kwqe *kwqe_arr[2];
496853e2bd2SBhanu Gollapudi int num_kwqes = 1;
497853e2bd2SBhanu Gollapudi int rc = 0;
498853e2bd2SBhanu Gollapudi
499853e2bd2SBhanu Gollapudi memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
500853e2bd2SBhanu Gollapudi destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
501853e2bd2SBhanu Gollapudi destroy_req.hdr.flags =
502853e2bd2SBhanu Gollapudi (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
503853e2bd2SBhanu Gollapudi
504853e2bd2SBhanu Gollapudi destroy_req.context_id = tgt->context_id;
505853e2bd2SBhanu Gollapudi destroy_req.conn_id = tgt->fcoe_conn_id;
506853e2bd2SBhanu Gollapudi
507853e2bd2SBhanu Gollapudi kwqe_arr[0] = (struct kwqe *) &destroy_req;
508853e2bd2SBhanu Gollapudi
509853e2bd2SBhanu Gollapudi if (hba->cnic && hba->cnic->submit_kwqes)
510853e2bd2SBhanu Gollapudi rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
511853e2bd2SBhanu Gollapudi
512853e2bd2SBhanu Gollapudi return rc;
513853e2bd2SBhanu Gollapudi }
514853e2bd2SBhanu Gollapudi
is_valid_lport(struct bnx2fc_hba * hba,struct fc_lport * lport)515d36b3279SBhanu Prakash Gollapudi static bool is_valid_lport(struct bnx2fc_hba *hba, struct fc_lport *lport)
516d36b3279SBhanu Prakash Gollapudi {
517d36b3279SBhanu Prakash Gollapudi struct bnx2fc_lport *blport;
518d36b3279SBhanu Prakash Gollapudi
519d36b3279SBhanu Prakash Gollapudi spin_lock_bh(&hba->hba_lock);
520d36b3279SBhanu Prakash Gollapudi list_for_each_entry(blport, &hba->vports, list) {
521d36b3279SBhanu Prakash Gollapudi if (blport->lport == lport) {
522d36b3279SBhanu Prakash Gollapudi spin_unlock_bh(&hba->hba_lock);
523d36b3279SBhanu Prakash Gollapudi return true;
524d36b3279SBhanu Prakash Gollapudi }
525d36b3279SBhanu Prakash Gollapudi }
526d36b3279SBhanu Prakash Gollapudi spin_unlock_bh(&hba->hba_lock);
527d36b3279SBhanu Prakash Gollapudi return false;
528d36b3279SBhanu Prakash Gollapudi
529d36b3279SBhanu Prakash Gollapudi }
530d36b3279SBhanu Prakash Gollapudi
531d36b3279SBhanu Prakash Gollapudi
bnx2fc_unsol_els_work(struct work_struct * work)532853e2bd2SBhanu Gollapudi static void bnx2fc_unsol_els_work(struct work_struct *work)
533853e2bd2SBhanu Gollapudi {
534853e2bd2SBhanu Gollapudi struct bnx2fc_unsol_els *unsol_els;
535853e2bd2SBhanu Gollapudi struct fc_lport *lport;
536d36b3279SBhanu Prakash Gollapudi struct bnx2fc_hba *hba;
537853e2bd2SBhanu Gollapudi struct fc_frame *fp;
538853e2bd2SBhanu Gollapudi
539853e2bd2SBhanu Gollapudi unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
540853e2bd2SBhanu Gollapudi lport = unsol_els->lport;
541853e2bd2SBhanu Gollapudi fp = unsol_els->fp;
542d36b3279SBhanu Prakash Gollapudi hba = unsol_els->hba;
543d36b3279SBhanu Prakash Gollapudi if (is_valid_lport(hba, lport))
544853e2bd2SBhanu Gollapudi fc_exch_recv(lport, fp);
545853e2bd2SBhanu Gollapudi kfree(unsol_els);
546853e2bd2SBhanu Gollapudi }
547853e2bd2SBhanu Gollapudi
bnx2fc_process_l2_frame_compl(struct bnx2fc_rport * tgt,unsigned char * buf,u32 frame_len,u16 l2_oxid)548853e2bd2SBhanu Gollapudi void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
549853e2bd2SBhanu Gollapudi unsigned char *buf,
550853e2bd2SBhanu Gollapudi u32 frame_len, u16 l2_oxid)
551853e2bd2SBhanu Gollapudi {
552853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port;
553853e2bd2SBhanu Gollapudi struct fc_lport *lport = port->lport;
554aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv;
555853e2bd2SBhanu Gollapudi struct bnx2fc_unsol_els *unsol_els;
556853e2bd2SBhanu Gollapudi struct fc_frame_header *fh;
557853e2bd2SBhanu Gollapudi struct fc_frame *fp;
558853e2bd2SBhanu Gollapudi struct sk_buff *skb;
559853e2bd2SBhanu Gollapudi u32 payload_len;
560853e2bd2SBhanu Gollapudi u32 crc;
561853e2bd2SBhanu Gollapudi u8 op;
562853e2bd2SBhanu Gollapudi
563853e2bd2SBhanu Gollapudi
564853e2bd2SBhanu Gollapudi unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
565853e2bd2SBhanu Gollapudi if (!unsol_els) {
566853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
567853e2bd2SBhanu Gollapudi return;
568853e2bd2SBhanu Gollapudi }
569853e2bd2SBhanu Gollapudi
570853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
571853e2bd2SBhanu Gollapudi l2_oxid, frame_len);
572853e2bd2SBhanu Gollapudi
573853e2bd2SBhanu Gollapudi payload_len = frame_len - sizeof(struct fc_frame_header);
574853e2bd2SBhanu Gollapudi
575853e2bd2SBhanu Gollapudi fp = fc_frame_alloc(lport, payload_len);
576853e2bd2SBhanu Gollapudi if (!fp) {
577853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "fc_frame_alloc failure\n");
5785c2dce26SJulia Lawall kfree(unsol_els);
579853e2bd2SBhanu Gollapudi return;
580853e2bd2SBhanu Gollapudi }
581853e2bd2SBhanu Gollapudi
582853e2bd2SBhanu Gollapudi fh = (struct fc_frame_header *) fc_frame_header_get(fp);
583853e2bd2SBhanu Gollapudi /* Copy FC Frame header and payload into the frame */
584853e2bd2SBhanu Gollapudi memcpy(fh, buf, frame_len);
585853e2bd2SBhanu Gollapudi
586853e2bd2SBhanu Gollapudi if (l2_oxid != FC_XID_UNKNOWN)
587853e2bd2SBhanu Gollapudi fh->fh_ox_id = htons(l2_oxid);
588853e2bd2SBhanu Gollapudi
589853e2bd2SBhanu Gollapudi skb = fp_skb(fp);
590853e2bd2SBhanu Gollapudi
591853e2bd2SBhanu Gollapudi if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
592853e2bd2SBhanu Gollapudi (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
593853e2bd2SBhanu Gollapudi
594853e2bd2SBhanu Gollapudi if (fh->fh_type == FC_TYPE_ELS) {
595853e2bd2SBhanu Gollapudi op = fc_frame_payload_op(fp);
596853e2bd2SBhanu Gollapudi if ((op == ELS_TEST) || (op == ELS_ESTC) ||
597853e2bd2SBhanu Gollapudi (op == ELS_FAN) || (op == ELS_CSU)) {
598853e2bd2SBhanu Gollapudi /*
599853e2bd2SBhanu Gollapudi * No need to reply for these
600853e2bd2SBhanu Gollapudi * ELS requests
601853e2bd2SBhanu Gollapudi */
602853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
603853e2bd2SBhanu Gollapudi kfree_skb(skb);
6045c2dce26SJulia Lawall kfree(unsol_els);
605853e2bd2SBhanu Gollapudi return;
606853e2bd2SBhanu Gollapudi }
607853e2bd2SBhanu Gollapudi }
608853e2bd2SBhanu Gollapudi crc = fcoe_fc_crc(fp);
609853e2bd2SBhanu Gollapudi fc_frame_init(fp);
610853e2bd2SBhanu Gollapudi fr_dev(fp) = lport;
611853e2bd2SBhanu Gollapudi fr_sof(fp) = FC_SOF_I3;
612853e2bd2SBhanu Gollapudi fr_eof(fp) = FC_EOF_T;
613853e2bd2SBhanu Gollapudi fr_crc(fp) = cpu_to_le32(~crc);
614853e2bd2SBhanu Gollapudi unsol_els->lport = lport;
615aea71a02SBhanu Prakash Gollapudi unsol_els->hba = interface->hba;
616853e2bd2SBhanu Gollapudi unsol_els->fp = fp;
617853e2bd2SBhanu Gollapudi INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
618853e2bd2SBhanu Gollapudi queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
619853e2bd2SBhanu Gollapudi } else {
620853e2bd2SBhanu Gollapudi BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
621853e2bd2SBhanu Gollapudi kfree_skb(skb);
6225c2dce26SJulia Lawall kfree(unsol_els);
623853e2bd2SBhanu Gollapudi }
624853e2bd2SBhanu Gollapudi }
625853e2bd2SBhanu Gollapudi
bnx2fc_process_unsol_compl(struct bnx2fc_rport * tgt,u16 wqe)626853e2bd2SBhanu Gollapudi static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
627853e2bd2SBhanu Gollapudi {
628853e2bd2SBhanu Gollapudi u8 num_rq;
629853e2bd2SBhanu Gollapudi struct fcoe_err_report_entry *err_entry;
630853e2bd2SBhanu Gollapudi unsigned char *rq_data;
631853e2bd2SBhanu Gollapudi unsigned char *buf = NULL, *buf1;
632853e2bd2SBhanu Gollapudi int i;
633853e2bd2SBhanu Gollapudi u16 xid;
634853e2bd2SBhanu Gollapudi u32 frame_len, len;
635853e2bd2SBhanu Gollapudi struct bnx2fc_cmd *io_req = NULL;
636aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = tgt->port->priv;
637aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba;
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
7030eb43b4bSBhanu Prakash Gollapudi if (xid > hba->max_xid) {
704853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
705853e2bd2SBhanu Gollapudi xid);
7067b594769SBhanu Prakash Gollapudi goto ret_err_rqe;
707853e2bd2SBhanu Gollapudi }
708853e2bd2SBhanu Gollapudi
709853e2bd2SBhanu Gollapudi
710853e2bd2SBhanu Gollapudi io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
7117b594769SBhanu Prakash Gollapudi if (!io_req)
7127b594769SBhanu Prakash Gollapudi goto ret_err_rqe;
713853e2bd2SBhanu Gollapudi
714853e2bd2SBhanu Gollapudi if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
715853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
7167b594769SBhanu Prakash Gollapudi goto ret_err_rqe;
717853e2bd2SBhanu Gollapudi }
718853e2bd2SBhanu Gollapudi
719853e2bd2SBhanu Gollapudi if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
720853e2bd2SBhanu Gollapudi &io_req->req_flags)) {
721853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
722853e2bd2SBhanu Gollapudi "progress.. ignore unsol err\n");
7237b594769SBhanu Prakash Gollapudi goto ret_err_rqe;
7247b594769SBhanu Prakash Gollapudi }
7257b594769SBhanu Prakash Gollapudi
7267b594769SBhanu Prakash Gollapudi err_warn_bit_map = (u64)
7277b594769SBhanu Prakash Gollapudi ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
7287b594769SBhanu Prakash Gollapudi (u64)err_entry->data.err_warn_bitmap_lo;
7297b594769SBhanu Prakash Gollapudi for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
7307b594769SBhanu Prakash Gollapudi if (err_warn_bit_map & (u64)((u64)1 << i)) {
7317b594769SBhanu Prakash Gollapudi err_warn = i;
732853e2bd2SBhanu Gollapudi break;
733853e2bd2SBhanu Gollapudi }
7347b594769SBhanu Prakash Gollapudi }
735853e2bd2SBhanu Gollapudi
736853e2bd2SBhanu Gollapudi /*
737853e2bd2SBhanu Gollapudi * If ABTS is already in progress, and FW error is
738853e2bd2SBhanu Gollapudi * received after that, do not cancel the timeout_work
739853e2bd2SBhanu Gollapudi * and let the error recovery continue by explicitly
740853e2bd2SBhanu Gollapudi * logging out the target, when the ABTS eventually
741853e2bd2SBhanu Gollapudi * times out.
742853e2bd2SBhanu Gollapudi */
7437b594769SBhanu Prakash Gollapudi if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
7447b594769SBhanu Prakash Gollapudi printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
7457b594769SBhanu Prakash Gollapudi "in ABTS processing\n", xid);
7467b594769SBhanu Prakash Gollapudi goto ret_err_rqe;
7477b594769SBhanu Prakash Gollapudi }
7487b594769SBhanu Prakash Gollapudi BNX2FC_TGT_DBG(tgt, "err = 0x%x\n", err_warn);
7497b594769SBhanu Prakash Gollapudi if (tgt->dev_type != TYPE_TAPE)
7507b594769SBhanu Prakash Gollapudi goto skip_rec;
7517b594769SBhanu Prakash Gollapudi switch (err_warn) {
7527b594769SBhanu Prakash Gollapudi case FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION:
7537b594769SBhanu Prakash Gollapudi case FCOE_ERROR_CODE_DATA_OOO_RO:
7547b594769SBhanu Prakash Gollapudi case FCOE_ERROR_CODE_COMMON_INCORRECT_SEQ_CNT:
7557b594769SBhanu Prakash Gollapudi case FCOE_ERROR_CODE_DATA_SOFI3_SEQ_ACTIVE_SET:
7567b594769SBhanu Prakash Gollapudi case FCOE_ERROR_CODE_FCP_RSP_OPENED_SEQ:
7577b594769SBhanu Prakash Gollapudi case FCOE_ERROR_CODE_DATA_SOFN_SEQ_ACTIVE_RESET:
7587b594769SBhanu Prakash Gollapudi BNX2FC_TGT_DBG(tgt, "REC TOV popped for xid - 0x%x\n",
7597b594769SBhanu Prakash Gollapudi xid);
7607b594769SBhanu Prakash Gollapudi memcpy(&io_req->err_entry, err_entry,
7617b594769SBhanu Prakash Gollapudi sizeof(struct fcoe_err_report_entry));
7627b594769SBhanu Prakash Gollapudi if (!test_bit(BNX2FC_FLAG_SRR_SENT,
763853e2bd2SBhanu Gollapudi &io_req->req_flags)) {
7647b594769SBhanu Prakash Gollapudi spin_unlock_bh(&tgt->tgt_lock);
7657b594769SBhanu Prakash Gollapudi rc = bnx2fc_send_rec(io_req);
7667b594769SBhanu Prakash Gollapudi spin_lock_bh(&tgt->tgt_lock);
7677b594769SBhanu Prakash Gollapudi
7687b594769SBhanu Prakash Gollapudi if (rc)
7697b594769SBhanu Prakash Gollapudi goto skip_rec;
7707b594769SBhanu Prakash Gollapudi } else
7717b594769SBhanu Prakash Gollapudi printk(KERN_ERR PFX "SRR in progress\n");
7727b594769SBhanu Prakash Gollapudi goto ret_err_rqe;
7737b594769SBhanu Prakash Gollapudi default:
7747b594769SBhanu Prakash Gollapudi break;
7757b594769SBhanu Prakash Gollapudi }
7767b594769SBhanu Prakash Gollapudi
7777b594769SBhanu Prakash Gollapudi skip_rec:
7787b594769SBhanu Prakash Gollapudi set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags);
779853e2bd2SBhanu Gollapudi /*
780853e2bd2SBhanu Gollapudi * Cancel the timeout_work, as we received IO
781853e2bd2SBhanu Gollapudi * completion with FW error.
782853e2bd2SBhanu Gollapudi */
783853e2bd2SBhanu Gollapudi if (cancel_delayed_work(&io_req->timeout_work))
7847b594769SBhanu Prakash Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release);
785853e2bd2SBhanu Gollapudi
786853e2bd2SBhanu Gollapudi rc = bnx2fc_initiate_abts(io_req);
787853e2bd2SBhanu Gollapudi if (rc != SUCCESS) {
7887b594769SBhanu Prakash Gollapudi printk(KERN_ERR PFX "err_warn: initiate_abts "
7897b594769SBhanu Prakash Gollapudi "failed xid = 0x%x. issue cleanup\n",
7907b594769SBhanu Prakash Gollapudi io_req->xid);
7917b594769SBhanu Prakash Gollapudi bnx2fc_initiate_cleanup(io_req);
792853e2bd2SBhanu Gollapudi }
7937b594769SBhanu Prakash Gollapudi ret_err_rqe:
7947b594769SBhanu Prakash Gollapudi bnx2fc_return_rqe(tgt, 1);
795853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock);
796853e2bd2SBhanu Gollapudi break;
797853e2bd2SBhanu Gollapudi
798853e2bd2SBhanu Gollapudi case FCOE_WARNING_DETECTION_CQE_TYPE:
799853e2bd2SBhanu Gollapudi /*
800853e2bd2SBhanu Gollapudi *In case of warning reporting CQE a single RQ entry
801853e2bd2SBhanu Gollapudi * is consumes.
802853e2bd2SBhanu Gollapudi */
80368695973SNithin Sujir spin_lock_bh(&tgt->tgt_lock);
804853e2bd2SBhanu Gollapudi num_rq = 1;
805853e2bd2SBhanu Gollapudi err_entry = (struct fcoe_err_report_entry *)
806853e2bd2SBhanu Gollapudi bnx2fc_get_next_rqe(tgt, 1);
807853e2bd2SBhanu Gollapudi xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
808853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
809853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
810619c5cb6SVlad Zolotarov err_entry->data.err_warn_bitmap_hi,
811619c5cb6SVlad Zolotarov err_entry->data.err_warn_bitmap_lo);
812853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
813619c5cb6SVlad Zolotarov err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
814853e2bd2SBhanu Gollapudi
8150eb43b4bSBhanu Prakash Gollapudi if (xid > hba->max_xid) {
8167b594769SBhanu Prakash Gollapudi BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", xid);
8177b594769SBhanu Prakash Gollapudi goto ret_warn_rqe;
8187b594769SBhanu Prakash Gollapudi }
8197b594769SBhanu Prakash Gollapudi
8207b594769SBhanu Prakash Gollapudi err_warn_bit_map = (u64)
8217b594769SBhanu Prakash Gollapudi ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
8227b594769SBhanu Prakash Gollapudi (u64)err_entry->data.err_warn_bitmap_lo;
8237b594769SBhanu Prakash Gollapudi for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
824d0c0d902SColin Ian King if (err_warn_bit_map & ((u64)1 << i)) {
8257b594769SBhanu Prakash Gollapudi err_warn = i;
8267b594769SBhanu Prakash Gollapudi break;
8277b594769SBhanu Prakash Gollapudi }
8287b594769SBhanu Prakash Gollapudi }
8297b594769SBhanu Prakash Gollapudi BNX2FC_TGT_DBG(tgt, "warn = 0x%x\n", err_warn);
8307b594769SBhanu Prakash Gollapudi
8317b594769SBhanu Prakash Gollapudi io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
8327b594769SBhanu Prakash Gollapudi if (!io_req)
8337b594769SBhanu Prakash Gollapudi goto ret_warn_rqe;
8347b594769SBhanu Prakash Gollapudi
8357b594769SBhanu Prakash Gollapudi if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
8367b594769SBhanu Prakash Gollapudi printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
8377b594769SBhanu Prakash Gollapudi goto ret_warn_rqe;
8387b594769SBhanu Prakash Gollapudi }
8397b594769SBhanu Prakash Gollapudi
8407b594769SBhanu Prakash Gollapudi memcpy(&io_req->err_entry, err_entry,
8417b594769SBhanu Prakash Gollapudi sizeof(struct fcoe_err_report_entry));
8427b594769SBhanu Prakash Gollapudi
8437b594769SBhanu Prakash Gollapudi if (err_warn == FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION)
8447b594769SBhanu Prakash Gollapudi /* REC_TOV is not a warning code */
8457b594769SBhanu Prakash Gollapudi BUG_ON(1);
8467b594769SBhanu Prakash Gollapudi else
8477b594769SBhanu Prakash Gollapudi BNX2FC_TGT_DBG(tgt, "Unsolicited warning\n");
8487b594769SBhanu Prakash Gollapudi ret_warn_rqe:
849853e2bd2SBhanu Gollapudi bnx2fc_return_rqe(tgt, 1);
85068695973SNithin Sujir spin_unlock_bh(&tgt->tgt_lock);
851853e2bd2SBhanu Gollapudi break;
852853e2bd2SBhanu Gollapudi
853853e2bd2SBhanu Gollapudi default:
854853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
855853e2bd2SBhanu Gollapudi break;
856853e2bd2SBhanu Gollapudi }
857853e2bd2SBhanu Gollapudi }
858853e2bd2SBhanu Gollapudi
bnx2fc_process_cq_compl(struct bnx2fc_rport * tgt,u16 wqe,unsigned char * rq_data,u8 num_rq,struct fcoe_task_ctx_entry * task)85977331115SJaved Hasan void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe,
86077331115SJaved Hasan unsigned char *rq_data, u8 num_rq,
86177331115SJaved Hasan struct fcoe_task_ctx_entry *task)
862853e2bd2SBhanu Gollapudi {
863853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port;
864aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv;
865aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba;
866853e2bd2SBhanu Gollapudi struct bnx2fc_cmd *io_req;
86777331115SJaved Hasan
868853e2bd2SBhanu Gollapudi u16 xid;
869853e2bd2SBhanu Gollapudi u8 cmd_type;
870853e2bd2SBhanu Gollapudi u8 rx_state = 0;
871853e2bd2SBhanu Gollapudi
872853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->tgt_lock);
87377331115SJaved Hasan
874853e2bd2SBhanu Gollapudi xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
875853e2bd2SBhanu Gollapudi io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
876853e2bd2SBhanu Gollapudi
877853e2bd2SBhanu Gollapudi if (io_req == NULL) {
878853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
879853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock);
880853e2bd2SBhanu Gollapudi return;
881853e2bd2SBhanu Gollapudi }
882853e2bd2SBhanu Gollapudi
883853e2bd2SBhanu Gollapudi /* Timestamp IO completion time */
884853e2bd2SBhanu Gollapudi cmd_type = io_req->cmd_type;
885853e2bd2SBhanu Gollapudi
886619c5cb6SVlad Zolotarov rx_state = ((task->rxwr_txrd.var_ctx.rx_flags &
887619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE) >>
888619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE_SHIFT);
889853e2bd2SBhanu Gollapudi
890619c5cb6SVlad Zolotarov /* Process other IO completion types */
891619c5cb6SVlad Zolotarov switch (cmd_type) {
892619c5cb6SVlad Zolotarov case BNX2FC_SCSI_CMD:
893853e2bd2SBhanu Gollapudi if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
89477331115SJaved Hasan bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq,
89577331115SJaved Hasan rq_data);
896853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock);
897853e2bd2SBhanu Gollapudi return;
898853e2bd2SBhanu Gollapudi }
899853e2bd2SBhanu Gollapudi
900853e2bd2SBhanu Gollapudi if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
901853e2bd2SBhanu Gollapudi bnx2fc_process_abts_compl(io_req, task, num_rq);
902853e2bd2SBhanu Gollapudi else if (rx_state ==
903853e2bd2SBhanu Gollapudi FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
904853e2bd2SBhanu Gollapudi bnx2fc_process_cleanup_compl(io_req, task, num_rq);
905853e2bd2SBhanu Gollapudi else
906853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Invalid rx state - %d\n",
907853e2bd2SBhanu Gollapudi rx_state);
908853e2bd2SBhanu Gollapudi break;
909853e2bd2SBhanu Gollapudi
910853e2bd2SBhanu Gollapudi case BNX2FC_TASK_MGMT_CMD:
911853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
91277331115SJaved Hasan bnx2fc_process_tm_compl(io_req, task, num_rq, rq_data);
913853e2bd2SBhanu Gollapudi break;
914853e2bd2SBhanu Gollapudi
915853e2bd2SBhanu Gollapudi case BNX2FC_ABTS:
916853e2bd2SBhanu Gollapudi /*
917853e2bd2SBhanu Gollapudi * ABTS request received by firmware. ABTS response
918853e2bd2SBhanu Gollapudi * will be delivered to the task belonging to the IO
919853e2bd2SBhanu Gollapudi * that was aborted
920853e2bd2SBhanu Gollapudi */
921853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
922853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release);
923853e2bd2SBhanu Gollapudi break;
924853e2bd2SBhanu Gollapudi
925853e2bd2SBhanu Gollapudi case BNX2FC_ELS:
926619c5cb6SVlad Zolotarov if (rx_state == FCOE_TASK_RX_STATE_COMPLETED)
927853e2bd2SBhanu Gollapudi bnx2fc_process_els_compl(io_req, task, num_rq);
928619c5cb6SVlad Zolotarov else if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
929619c5cb6SVlad Zolotarov bnx2fc_process_abts_compl(io_req, task, num_rq);
930619c5cb6SVlad Zolotarov else if (rx_state ==
931619c5cb6SVlad Zolotarov FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
932619c5cb6SVlad Zolotarov bnx2fc_process_cleanup_compl(io_req, task, num_rq);
933619c5cb6SVlad Zolotarov else
934619c5cb6SVlad Zolotarov printk(KERN_ERR PFX "Invalid rx state = %d\n",
935619c5cb6SVlad Zolotarov rx_state);
936853e2bd2SBhanu Gollapudi break;
937853e2bd2SBhanu Gollapudi
938853e2bd2SBhanu Gollapudi case BNX2FC_CLEANUP:
939853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
940853e2bd2SBhanu Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release);
941853e2bd2SBhanu Gollapudi break;
942853e2bd2SBhanu Gollapudi
9436c5a7ce4SBhanu Prakash Gollapudi case BNX2FC_SEQ_CLEANUP:
9446c5a7ce4SBhanu Prakash Gollapudi BNX2FC_IO_DBG(io_req, "cq_compl(0x%x) - seq cleanup resp\n",
9456c5a7ce4SBhanu Prakash Gollapudi io_req->xid);
9466c5a7ce4SBhanu Prakash Gollapudi bnx2fc_process_seq_cleanup_compl(io_req, task, rx_state);
9476c5a7ce4SBhanu Prakash Gollapudi kref_put(&io_req->refcount, bnx2fc_cmd_release);
9486c5a7ce4SBhanu Prakash Gollapudi break;
9496c5a7ce4SBhanu Prakash Gollapudi
950853e2bd2SBhanu Gollapudi default:
951853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
952853e2bd2SBhanu Gollapudi break;
953853e2bd2SBhanu Gollapudi }
954853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->tgt_lock);
955853e2bd2SBhanu Gollapudi }
956853e2bd2SBhanu Gollapudi
bnx2fc_arm_cq(struct bnx2fc_rport * tgt)957619c5cb6SVlad Zolotarov void bnx2fc_arm_cq(struct bnx2fc_rport *tgt)
958619c5cb6SVlad Zolotarov {
959619c5cb6SVlad Zolotarov struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
960619c5cb6SVlad Zolotarov u32 msg;
961619c5cb6SVlad Zolotarov
962619c5cb6SVlad Zolotarov wmb();
963619c5cb6SVlad Zolotarov rx_db->doorbell_cq_cons = tgt->cq_cons_idx | (tgt->cq_curr_toggle_bit <<
964619c5cb6SVlad Zolotarov FCOE_CQE_TOGGLE_BIT_SHIFT);
965619c5cb6SVlad Zolotarov msg = *((u32 *)rx_db);
966619c5cb6SVlad Zolotarov writel(cpu_to_le32(msg), tgt->ctx_base);
967619c5cb6SVlad Zolotarov
968619c5cb6SVlad Zolotarov }
969619c5cb6SVlad Zolotarov
bnx2fc_alloc_work(struct bnx2fc_rport * tgt,u16 wqe,unsigned char * rq_data,u8 num_rq,struct fcoe_task_ctx_entry * task)97077331115SJaved Hasan static struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe,
97177331115SJaved Hasan unsigned char *rq_data, u8 num_rq,
97277331115SJaved Hasan struct fcoe_task_ctx_entry *task)
973853e2bd2SBhanu Gollapudi {
974853e2bd2SBhanu Gollapudi struct bnx2fc_work *work;
975853e2bd2SBhanu Gollapudi work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
976853e2bd2SBhanu Gollapudi if (!work)
977853e2bd2SBhanu Gollapudi return NULL;
978853e2bd2SBhanu Gollapudi
979853e2bd2SBhanu Gollapudi INIT_LIST_HEAD(&work->list);
980853e2bd2SBhanu Gollapudi work->tgt = tgt;
981853e2bd2SBhanu Gollapudi work->wqe = wqe;
98277331115SJaved Hasan work->num_rq = num_rq;
98377331115SJaved Hasan work->task = task;
98477331115SJaved Hasan if (rq_data)
98577331115SJaved Hasan memcpy(work->rq_data, rq_data, BNX2FC_RQ_BUF_SZ);
98677331115SJaved Hasan
987853e2bd2SBhanu Gollapudi return work;
988853e2bd2SBhanu Gollapudi }
989853e2bd2SBhanu Gollapudi
9908addebc1SThomas Gleixner /* Pending work request completion */
bnx2fc_pending_work(struct bnx2fc_rport * tgt,unsigned int wqe)99177331115SJaved Hasan static bool bnx2fc_pending_work(struct bnx2fc_rport *tgt, unsigned int wqe)
9928addebc1SThomas Gleixner {
9938addebc1SThomas Gleixner unsigned int cpu = wqe % num_possible_cpus();
9948addebc1SThomas Gleixner struct bnx2fc_percpu_s *fps;
9958addebc1SThomas Gleixner struct bnx2fc_work *work;
99677331115SJaved Hasan struct fcoe_task_ctx_entry *task;
99777331115SJaved Hasan struct fcoe_task_ctx_entry *task_page;
99877331115SJaved Hasan struct fcoe_port *port = tgt->port;
99977331115SJaved Hasan struct bnx2fc_interface *interface = port->priv;
100077331115SJaved Hasan struct bnx2fc_hba *hba = interface->hba;
100177331115SJaved Hasan unsigned char *rq_data = NULL;
100277331115SJaved Hasan unsigned char rq_data_buff[BNX2FC_RQ_BUF_SZ];
100377331115SJaved Hasan int task_idx, index;
100477331115SJaved Hasan u16 xid;
100577331115SJaved Hasan u8 num_rq;
100677331115SJaved Hasan int i;
100777331115SJaved Hasan
100877331115SJaved Hasan xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
100977331115SJaved Hasan if (xid >= hba->max_tasks) {
101077331115SJaved Hasan pr_err(PFX "ERROR:xid out of range\n");
101160f537d5Skbuild test robot return false;
101277331115SJaved Hasan }
101377331115SJaved Hasan
101477331115SJaved Hasan task_idx = xid / BNX2FC_TASKS_PER_PAGE;
101577331115SJaved Hasan index = xid % BNX2FC_TASKS_PER_PAGE;
101677331115SJaved Hasan task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
101777331115SJaved Hasan task = &task_page[index];
101877331115SJaved Hasan
101977331115SJaved Hasan num_rq = ((task->rxwr_txrd.var_ctx.rx_flags &
102077331115SJaved Hasan FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE) >>
102177331115SJaved Hasan FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE_SHIFT);
102277331115SJaved Hasan
102377331115SJaved Hasan memset(rq_data_buff, 0, BNX2FC_RQ_BUF_SZ);
102477331115SJaved Hasan
102577331115SJaved Hasan if (!num_rq)
102677331115SJaved Hasan goto num_rq_zero;
102777331115SJaved Hasan
102877331115SJaved Hasan rq_data = bnx2fc_get_next_rqe(tgt, 1);
102977331115SJaved Hasan
103077331115SJaved Hasan if (num_rq > 1) {
103177331115SJaved Hasan /* We do not need extra sense data */
103277331115SJaved Hasan for (i = 1; i < num_rq; i++)
103337d09067SJaved Hasan bnx2fc_get_next_rqe(tgt, 1);
103477331115SJaved Hasan }
103577331115SJaved Hasan
103677331115SJaved Hasan if (rq_data)
103777331115SJaved Hasan memcpy(rq_data_buff, rq_data, BNX2FC_RQ_BUF_SZ);
103877331115SJaved Hasan
103977331115SJaved Hasan /* return RQ entries */
104077331115SJaved Hasan for (i = 0; i < num_rq; i++)
104177331115SJaved Hasan bnx2fc_return_rqe(tgt, 1);
104277331115SJaved Hasan
104377331115SJaved Hasan num_rq_zero:
10448addebc1SThomas Gleixner
10458addebc1SThomas Gleixner fps = &per_cpu(bnx2fc_percpu, cpu);
10468addebc1SThomas Gleixner spin_lock_bh(&fps->fp_work_lock);
10478addebc1SThomas Gleixner if (fps->iothread) {
104877331115SJaved Hasan work = bnx2fc_alloc_work(tgt, wqe, rq_data_buff,
104977331115SJaved Hasan num_rq, task);
10508addebc1SThomas Gleixner if (work) {
10518addebc1SThomas Gleixner list_add_tail(&work->list, &fps->work_list);
10528addebc1SThomas Gleixner wake_up_process(fps->iothread);
10538addebc1SThomas Gleixner spin_unlock_bh(&fps->fp_work_lock);
105460f537d5Skbuild test robot return true;
10558addebc1SThomas Gleixner }
10568addebc1SThomas Gleixner }
10578addebc1SThomas Gleixner spin_unlock_bh(&fps->fp_work_lock);
105877331115SJaved Hasan bnx2fc_process_cq_compl(tgt, wqe,
105977331115SJaved Hasan rq_data_buff, num_rq, task);
106077331115SJaved Hasan
106160f537d5Skbuild test robot return true;
10628addebc1SThomas Gleixner }
10638addebc1SThomas Gleixner
bnx2fc_process_new_cqes(struct bnx2fc_rport * tgt)1064853e2bd2SBhanu Gollapudi int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
1065853e2bd2SBhanu Gollapudi {
1066853e2bd2SBhanu Gollapudi struct fcoe_cqe *cq;
1067853e2bd2SBhanu Gollapudi u32 cq_cons;
1068853e2bd2SBhanu Gollapudi struct fcoe_cqe *cqe;
1069619c5cb6SVlad Zolotarov u32 num_free_sqes = 0;
1070b338c785SBhanu Prakash Gollapudi u32 num_cqes = 0;
1071853e2bd2SBhanu Gollapudi u16 wqe;
1072853e2bd2SBhanu Gollapudi
1073853e2bd2SBhanu Gollapudi /*
1074853e2bd2SBhanu Gollapudi * cq_lock is a low contention lock used to protect
1075853e2bd2SBhanu Gollapudi * the CQ data structure from being freed up during
1076853e2bd2SBhanu Gollapudi * the upload operation
1077853e2bd2SBhanu Gollapudi */
1078853e2bd2SBhanu Gollapudi spin_lock_bh(&tgt->cq_lock);
1079853e2bd2SBhanu Gollapudi
1080853e2bd2SBhanu Gollapudi if (!tgt->cq) {
1081853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
1082853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->cq_lock);
1083853e2bd2SBhanu Gollapudi return 0;
1084853e2bd2SBhanu Gollapudi }
1085853e2bd2SBhanu Gollapudi cq = tgt->cq;
1086853e2bd2SBhanu Gollapudi cq_cons = tgt->cq_cons_idx;
1087853e2bd2SBhanu Gollapudi cqe = &cq[cq_cons];
1088853e2bd2SBhanu Gollapudi
1089853e2bd2SBhanu Gollapudi while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
1090853e2bd2SBhanu Gollapudi (tgt->cq_curr_toggle_bit <<
1091853e2bd2SBhanu Gollapudi FCOE_CQE_TOGGLE_BIT_SHIFT)) {
1092853e2bd2SBhanu Gollapudi
1093853e2bd2SBhanu Gollapudi /* new entry on the cq */
1094853e2bd2SBhanu Gollapudi if (wqe & FCOE_CQE_CQE_TYPE) {
1095853e2bd2SBhanu Gollapudi /* Unsolicited event notification */
1096853e2bd2SBhanu Gollapudi bnx2fc_process_unsol_compl(tgt, wqe);
1097853e2bd2SBhanu Gollapudi } else {
109877331115SJaved Hasan if (bnx2fc_pending_work(tgt, wqe))
1099b338c785SBhanu Prakash Gollapudi num_free_sqes++;
1100853e2bd2SBhanu Gollapudi }
1101853e2bd2SBhanu Gollapudi cqe++;
1102853e2bd2SBhanu Gollapudi tgt->cq_cons_idx++;
1103b338c785SBhanu Prakash Gollapudi num_cqes++;
1104853e2bd2SBhanu Gollapudi
1105853e2bd2SBhanu Gollapudi if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
1106853e2bd2SBhanu Gollapudi tgt->cq_cons_idx = 0;
1107853e2bd2SBhanu Gollapudi cqe = cq;
1108853e2bd2SBhanu Gollapudi tgt->cq_curr_toggle_bit =
1109853e2bd2SBhanu Gollapudi 1 - tgt->cq_curr_toggle_bit;
1110853e2bd2SBhanu Gollapudi }
1111853e2bd2SBhanu Gollapudi }
1112b338c785SBhanu Prakash Gollapudi if (num_cqes) {
1113b338c785SBhanu Prakash Gollapudi /* Arm CQ only if doorbell is mapped */
1114b338c785SBhanu Prakash Gollapudi if (tgt->ctx_base)
1115619c5cb6SVlad Zolotarov bnx2fc_arm_cq(tgt);
1116619c5cb6SVlad Zolotarov atomic_add(num_free_sqes, &tgt->free_sqes);
1117fd08bd62SBhanu Prakash Gollapudi }
1118853e2bd2SBhanu Gollapudi spin_unlock_bh(&tgt->cq_lock);
1119853e2bd2SBhanu Gollapudi return 0;
1120853e2bd2SBhanu Gollapudi }
1121853e2bd2SBhanu Gollapudi
1122853e2bd2SBhanu Gollapudi /**
1123853e2bd2SBhanu Gollapudi * bnx2fc_fastpath_notification - process global event queue (KCQ)
1124853e2bd2SBhanu Gollapudi *
1125853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer
1126853e2bd2SBhanu Gollapudi * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry
1127853e2bd2SBhanu Gollapudi *
1128853e2bd2SBhanu Gollapudi * Fast path event notification handler
1129853e2bd2SBhanu Gollapudi */
bnx2fc_fastpath_notification(struct bnx2fc_hba * hba,struct fcoe_kcqe * new_cqe_kcqe)1130853e2bd2SBhanu Gollapudi static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
1131853e2bd2SBhanu Gollapudi struct fcoe_kcqe *new_cqe_kcqe)
1132853e2bd2SBhanu Gollapudi {
1133853e2bd2SBhanu Gollapudi u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
1134853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
1135853e2bd2SBhanu Gollapudi
1136853e2bd2SBhanu Gollapudi if (!tgt) {
1137b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "conn_id 0x%x not valid\n", conn_id);
1138853e2bd2SBhanu Gollapudi return;
1139853e2bd2SBhanu Gollapudi }
1140853e2bd2SBhanu Gollapudi
1141853e2bd2SBhanu Gollapudi bnx2fc_process_new_cqes(tgt);
1142853e2bd2SBhanu Gollapudi }
1143853e2bd2SBhanu Gollapudi
1144853e2bd2SBhanu Gollapudi /**
1145853e2bd2SBhanu Gollapudi * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
1146853e2bd2SBhanu Gollapudi *
1147853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer
1148853e2bd2SBhanu Gollapudi * @ofld_kcqe: connection offload kcqe pointer
1149853e2bd2SBhanu Gollapudi *
1150853e2bd2SBhanu Gollapudi * handle session offload completion, enable the session if offload is
1151853e2bd2SBhanu Gollapudi * successful.
1152853e2bd2SBhanu Gollapudi */
bnx2fc_process_ofld_cmpl(struct bnx2fc_hba * hba,struct fcoe_kcqe * ofld_kcqe)1153853e2bd2SBhanu Gollapudi static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
1154853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe)
1155853e2bd2SBhanu Gollapudi {
1156853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt;
1157aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface;
1158853e2bd2SBhanu Gollapudi u32 conn_id;
1159853e2bd2SBhanu Gollapudi u32 context_id;
1160853e2bd2SBhanu Gollapudi
1161853e2bd2SBhanu Gollapudi conn_id = ofld_kcqe->fcoe_conn_id;
1162853e2bd2SBhanu Gollapudi context_id = ofld_kcqe->fcoe_conn_context_id;
1163853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id];
1164853e2bd2SBhanu Gollapudi if (!tgt) {
1165aea71a02SBhanu Prakash Gollapudi printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
1166853e2bd2SBhanu Gollapudi return;
1167853e2bd2SBhanu Gollapudi }
1168853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
1169853e2bd2SBhanu Gollapudi ofld_kcqe->fcoe_conn_context_id);
1170aea71a02SBhanu Prakash Gollapudi interface = tgt->port->priv;
1171aea71a02SBhanu Prakash Gollapudi if (hba != interface->hba) {
1172*7ff897b2SColin Ian King printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mismatch\n");
1173853e2bd2SBhanu Gollapudi goto ofld_cmpl_err;
1174853e2bd2SBhanu Gollapudi }
1175853e2bd2SBhanu Gollapudi /*
1176853e2bd2SBhanu Gollapudi * cnic has allocated a context_id for this session; use this
1177853e2bd2SBhanu Gollapudi * while enabling the session.
1178853e2bd2SBhanu Gollapudi */
1179853e2bd2SBhanu Gollapudi tgt->context_id = context_id;
1180853e2bd2SBhanu Gollapudi if (ofld_kcqe->completion_status) {
1181853e2bd2SBhanu Gollapudi if (ofld_kcqe->completion_status ==
1182853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
1183853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate FCoE context "
1184853e2bd2SBhanu Gollapudi "resources\n");
1185853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
1186853e2bd2SBhanu Gollapudi }
1187853e2bd2SBhanu Gollapudi } else {
1188e7f4fed5SBhanu Prakash Gollapudi /* FW offload request successfully completed */
1189e7f4fed5SBhanu Prakash Gollapudi set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1190853e2bd2SBhanu Gollapudi }
1191853e2bd2SBhanu Gollapudi ofld_cmpl_err:
1192853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1193853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait);
1194853e2bd2SBhanu Gollapudi }
1195853e2bd2SBhanu Gollapudi
1196853e2bd2SBhanu Gollapudi /**
1197853e2bd2SBhanu Gollapudi * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
1198853e2bd2SBhanu Gollapudi *
1199853e2bd2SBhanu Gollapudi * @hba: adapter structure pointer
1200853e2bd2SBhanu Gollapudi * @ofld_kcqe: connection offload kcqe pointer
1201853e2bd2SBhanu Gollapudi *
1202853e2bd2SBhanu Gollapudi * handle session enable completion, mark the rport as ready
1203853e2bd2SBhanu Gollapudi */
1204853e2bd2SBhanu Gollapudi
bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba * hba,struct fcoe_kcqe * ofld_kcqe)1205853e2bd2SBhanu Gollapudi static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1206853e2bd2SBhanu Gollapudi struct fcoe_kcqe *ofld_kcqe)
1207853e2bd2SBhanu Gollapudi {
1208853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt;
1209aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface;
1210853e2bd2SBhanu Gollapudi u32 conn_id;
1211853e2bd2SBhanu Gollapudi u32 context_id;
1212853e2bd2SBhanu Gollapudi
1213853e2bd2SBhanu Gollapudi context_id = ofld_kcqe->fcoe_conn_context_id;
1214853e2bd2SBhanu Gollapudi conn_id = ofld_kcqe->fcoe_conn_id;
1215853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id];
1216853e2bd2SBhanu Gollapudi if (!tgt) {
1217b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "ERROR:enbl_cmpl: No pending ofld req\n");
1218853e2bd2SBhanu Gollapudi return;
1219853e2bd2SBhanu Gollapudi }
1220853e2bd2SBhanu Gollapudi
1221853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
1222853e2bd2SBhanu Gollapudi ofld_kcqe->fcoe_conn_context_id);
1223853e2bd2SBhanu Gollapudi
1224853e2bd2SBhanu Gollapudi /*
1225853e2bd2SBhanu Gollapudi * context_id should be the same for this target during offload
1226853e2bd2SBhanu Gollapudi * and enable
1227853e2bd2SBhanu Gollapudi */
1228853e2bd2SBhanu Gollapudi if (tgt->context_id != context_id) {
1229*7ff897b2SColin Ian King printk(KERN_ERR PFX "context id mismatch\n");
1230853e2bd2SBhanu Gollapudi return;
1231853e2bd2SBhanu Gollapudi }
1232aea71a02SBhanu Prakash Gollapudi interface = tgt->port->priv;
1233aea71a02SBhanu Prakash Gollapudi if (hba != interface->hba) {
1234*7ff897b2SColin Ian King printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mismatch\n");
1235853e2bd2SBhanu Gollapudi goto enbl_cmpl_err;
1236853e2bd2SBhanu Gollapudi }
1237e7f4fed5SBhanu Prakash Gollapudi if (!ofld_kcqe->completion_status)
1238853e2bd2SBhanu Gollapudi /* enable successful - rport ready for issuing IOs */
1239e7f4fed5SBhanu Prakash Gollapudi set_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
1240853e2bd2SBhanu Gollapudi
1241853e2bd2SBhanu Gollapudi enbl_cmpl_err:
1242853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1243853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->ofld_wait);
1244853e2bd2SBhanu Gollapudi }
1245853e2bd2SBhanu Gollapudi
bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba * hba,struct fcoe_kcqe * disable_kcqe)1246853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
1247853e2bd2SBhanu Gollapudi struct fcoe_kcqe *disable_kcqe)
1248853e2bd2SBhanu Gollapudi {
1249853e2bd2SBhanu Gollapudi
1250853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt;
1251853e2bd2SBhanu Gollapudi u32 conn_id;
1252853e2bd2SBhanu Gollapudi
1253853e2bd2SBhanu Gollapudi conn_id = disable_kcqe->fcoe_conn_id;
1254853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id];
1255853e2bd2SBhanu Gollapudi if (!tgt) {
1256b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "ERROR: disable_cmpl: No disable req\n");
1257853e2bd2SBhanu Gollapudi return;
1258853e2bd2SBhanu Gollapudi }
1259853e2bd2SBhanu Gollapudi
1260853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
1261853e2bd2SBhanu Gollapudi
1262853e2bd2SBhanu Gollapudi if (disable_kcqe->completion_status) {
1263b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "Disable failed with cmpl status %d\n",
1264853e2bd2SBhanu Gollapudi disable_kcqe->completion_status);
12655c17ae21SBhanu Prakash Gollapudi set_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags);
12665c17ae21SBhanu Prakash Gollapudi set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
12675c17ae21SBhanu Prakash Gollapudi wake_up_interruptible(&tgt->upld_wait);
1268853e2bd2SBhanu Gollapudi } else {
1269853e2bd2SBhanu Gollapudi /* disable successful */
1270853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "disable successful\n");
1271853e2bd2SBhanu Gollapudi clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1272e7f4fed5SBhanu Prakash Gollapudi clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
1273853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1274853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1275853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->upld_wait);
1276853e2bd2SBhanu Gollapudi }
1277853e2bd2SBhanu Gollapudi }
1278853e2bd2SBhanu Gollapudi
bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba * hba,struct fcoe_kcqe * destroy_kcqe)1279853e2bd2SBhanu Gollapudi static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
1280853e2bd2SBhanu Gollapudi struct fcoe_kcqe *destroy_kcqe)
1281853e2bd2SBhanu Gollapudi {
1282853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt;
1283853e2bd2SBhanu Gollapudi u32 conn_id;
1284853e2bd2SBhanu Gollapudi
1285853e2bd2SBhanu Gollapudi conn_id = destroy_kcqe->fcoe_conn_id;
1286853e2bd2SBhanu Gollapudi tgt = hba->tgt_ofld_list[conn_id];
1287853e2bd2SBhanu Gollapudi if (!tgt) {
1288b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "destroy_cmpl: No destroy req\n");
1289853e2bd2SBhanu Gollapudi return;
1290853e2bd2SBhanu Gollapudi }
1291853e2bd2SBhanu Gollapudi
1292853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
1293853e2bd2SBhanu Gollapudi
1294853e2bd2SBhanu Gollapudi if (destroy_kcqe->completion_status) {
1295b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "Destroy conn failed, cmpl status %d\n",
1296853e2bd2SBhanu Gollapudi destroy_kcqe->completion_status);
1297853e2bd2SBhanu Gollapudi return;
1298853e2bd2SBhanu Gollapudi } else {
1299853e2bd2SBhanu Gollapudi /* destroy successful */
1300853e2bd2SBhanu Gollapudi BNX2FC_TGT_DBG(tgt, "upload successful\n");
1301853e2bd2SBhanu Gollapudi clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1302853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
1303853e2bd2SBhanu Gollapudi set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1304853e2bd2SBhanu Gollapudi wake_up_interruptible(&tgt->upld_wait);
1305853e2bd2SBhanu Gollapudi }
1306853e2bd2SBhanu Gollapudi }
1307853e2bd2SBhanu Gollapudi
bnx2fc_init_failure(struct bnx2fc_hba * hba,u32 err_code)1308853e2bd2SBhanu Gollapudi static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
1309853e2bd2SBhanu Gollapudi {
1310853e2bd2SBhanu Gollapudi switch (err_code) {
1311853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
1312853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
1313853e2bd2SBhanu Gollapudi break;
1314853e2bd2SBhanu Gollapudi
1315853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
1316853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
1317853e2bd2SBhanu Gollapudi break;
1318853e2bd2SBhanu Gollapudi
1319853e2bd2SBhanu Gollapudi case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
1320853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "init_failure due to NIC error\n");
1321853e2bd2SBhanu Gollapudi break;
1322619c5cb6SVlad Zolotarov case FCOE_KCQE_COMPLETION_STATUS_ERROR:
1323619c5cb6SVlad Zolotarov printk(KERN_ERR PFX "init failure due to compl status err\n");
1324619c5cb6SVlad Zolotarov break;
1325619c5cb6SVlad Zolotarov case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION:
1326619c5cb6SVlad Zolotarov printk(KERN_ERR PFX "init failure due to HSI mismatch\n");
1327b2a554ffSBhanu Prakash Gollapudi break;
1328853e2bd2SBhanu Gollapudi default:
1329853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
1330853e2bd2SBhanu Gollapudi }
1331853e2bd2SBhanu Gollapudi }
1332853e2bd2SBhanu Gollapudi
1333853e2bd2SBhanu Gollapudi /**
133452ffc08dSLee Jones * bnx2fc_indicate_kcqe() - process KCQE
1335853e2bd2SBhanu Gollapudi *
13364db2ac3eSLee Jones * @context: adapter structure pointer
13374db2ac3eSLee Jones * @kcq: kcqe pointer
1338853e2bd2SBhanu Gollapudi * @num_cqe: Number of completion queue elements
1339853e2bd2SBhanu Gollapudi *
1340853e2bd2SBhanu Gollapudi * Generic KCQ event handler
1341853e2bd2SBhanu Gollapudi */
bnx2fc_indicate_kcqe(void * context,struct kcqe * kcq[],u32 num_cqe)1342853e2bd2SBhanu Gollapudi void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
1343853e2bd2SBhanu Gollapudi u32 num_cqe)
1344853e2bd2SBhanu Gollapudi {
1345853e2bd2SBhanu Gollapudi struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
1346853e2bd2SBhanu Gollapudi int i = 0;
1347853e2bd2SBhanu Gollapudi struct fcoe_kcqe *kcqe = NULL;
1348853e2bd2SBhanu Gollapudi
1349853e2bd2SBhanu Gollapudi while (i < num_cqe) {
1350853e2bd2SBhanu Gollapudi kcqe = (struct fcoe_kcqe *) kcq[i++];
1351853e2bd2SBhanu Gollapudi
1352853e2bd2SBhanu Gollapudi switch (kcqe->op_code) {
1353853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
1354853e2bd2SBhanu Gollapudi bnx2fc_fastpath_notification(hba, kcqe);
1355853e2bd2SBhanu Gollapudi break;
1356853e2bd2SBhanu Gollapudi
1357853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
1358853e2bd2SBhanu Gollapudi bnx2fc_process_ofld_cmpl(hba, kcqe);
1359853e2bd2SBhanu Gollapudi break;
1360853e2bd2SBhanu Gollapudi
1361853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_ENABLE_CONN:
1362853e2bd2SBhanu Gollapudi bnx2fc_process_enable_conn_cmpl(hba, kcqe);
1363853e2bd2SBhanu Gollapudi break;
1364853e2bd2SBhanu Gollapudi
1365853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_INIT_FUNC:
1366853e2bd2SBhanu Gollapudi if (kcqe->completion_status !=
1367853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1368853e2bd2SBhanu Gollapudi bnx2fc_init_failure(hba,
1369853e2bd2SBhanu Gollapudi kcqe->completion_status);
1370853e2bd2SBhanu Gollapudi } else {
1371853e2bd2SBhanu Gollapudi set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1372853e2bd2SBhanu Gollapudi bnx2fc_get_link_state(hba);
1373853e2bd2SBhanu Gollapudi printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
1374853e2bd2SBhanu Gollapudi (u8)hba->pcidev->bus->number);
1375853e2bd2SBhanu Gollapudi }
1376853e2bd2SBhanu Gollapudi break;
1377853e2bd2SBhanu Gollapudi
1378853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DESTROY_FUNC:
1379853e2bd2SBhanu Gollapudi if (kcqe->completion_status !=
1380853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1381853e2bd2SBhanu Gollapudi
1382853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "DESTROY failed\n");
1383853e2bd2SBhanu Gollapudi } else {
1384853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "DESTROY success\n");
1385853e2bd2SBhanu Gollapudi }
1386aea71a02SBhanu Prakash Gollapudi set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1387853e2bd2SBhanu Gollapudi wake_up_interruptible(&hba->destroy_wait);
1388853e2bd2SBhanu Gollapudi break;
1389853e2bd2SBhanu Gollapudi
1390853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DISABLE_CONN:
1391853e2bd2SBhanu Gollapudi bnx2fc_process_conn_disable_cmpl(hba, kcqe);
1392853e2bd2SBhanu Gollapudi break;
1393853e2bd2SBhanu Gollapudi
1394853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_DESTROY_CONN:
1395853e2bd2SBhanu Gollapudi bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
1396853e2bd2SBhanu Gollapudi break;
1397853e2bd2SBhanu Gollapudi
1398853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_STAT_FUNC:
1399853e2bd2SBhanu Gollapudi if (kcqe->completion_status !=
1400853e2bd2SBhanu Gollapudi FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
1401853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "STAT failed\n");
1402853e2bd2SBhanu Gollapudi complete(&hba->stat_req_done);
1403853e2bd2SBhanu Gollapudi break;
1404853e2bd2SBhanu Gollapudi
1405853e2bd2SBhanu Gollapudi case FCOE_KCQE_OPCODE_FCOE_ERROR:
1406853e2bd2SBhanu Gollapudi default:
1407b2a554ffSBhanu Prakash Gollapudi printk(KERN_ERR PFX "unknown opcode 0x%x\n",
1408853e2bd2SBhanu Gollapudi kcqe->op_code);
1409853e2bd2SBhanu Gollapudi }
1410853e2bd2SBhanu Gollapudi }
1411853e2bd2SBhanu Gollapudi }
1412853e2bd2SBhanu Gollapudi
bnx2fc_add_2_sq(struct bnx2fc_rport * tgt,u16 xid)1413853e2bd2SBhanu Gollapudi void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
1414853e2bd2SBhanu Gollapudi {
1415853e2bd2SBhanu Gollapudi struct fcoe_sqe *sqe;
1416853e2bd2SBhanu Gollapudi
1417853e2bd2SBhanu Gollapudi sqe = &tgt->sq[tgt->sq_prod_idx];
1418853e2bd2SBhanu Gollapudi
1419853e2bd2SBhanu Gollapudi /* Fill SQ WQE */
1420853e2bd2SBhanu Gollapudi sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
1421853e2bd2SBhanu Gollapudi sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
1422853e2bd2SBhanu Gollapudi
1423853e2bd2SBhanu Gollapudi /* Advance SQ Prod Idx */
1424853e2bd2SBhanu Gollapudi if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
1425853e2bd2SBhanu Gollapudi tgt->sq_prod_idx = 0;
1426853e2bd2SBhanu Gollapudi tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
1427853e2bd2SBhanu Gollapudi }
1428853e2bd2SBhanu Gollapudi }
1429853e2bd2SBhanu Gollapudi
bnx2fc_ring_doorbell(struct bnx2fc_rport * tgt)1430853e2bd2SBhanu Gollapudi void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
1431853e2bd2SBhanu Gollapudi {
1432619c5cb6SVlad Zolotarov struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
1433853e2bd2SBhanu Gollapudi u32 msg;
1434853e2bd2SBhanu Gollapudi
1435853e2bd2SBhanu Gollapudi wmb();
1436619c5cb6SVlad Zolotarov sq_db->prod = tgt->sq_prod_idx |
1437853e2bd2SBhanu Gollapudi (tgt->sq_curr_toggle_bit << 15);
1438619c5cb6SVlad Zolotarov msg = *((u32 *)sq_db);
1439853e2bd2SBhanu Gollapudi writel(cpu_to_le32(msg), tgt->ctx_base);
1440853e2bd2SBhanu Gollapudi
1441853e2bd2SBhanu Gollapudi }
1442853e2bd2SBhanu Gollapudi
bnx2fc_map_doorbell(struct bnx2fc_rport * tgt)1443853e2bd2SBhanu Gollapudi int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
1444853e2bd2SBhanu Gollapudi {
1445853e2bd2SBhanu Gollapudi u32 context_id = tgt->context_id;
1446853e2bd2SBhanu Gollapudi struct fcoe_port *port = tgt->port;
1447853e2bd2SBhanu Gollapudi u32 reg_off;
1448853e2bd2SBhanu Gollapudi resource_size_t reg_base;
1449aea71a02SBhanu Prakash Gollapudi struct bnx2fc_interface *interface = port->priv;
1450aea71a02SBhanu Prakash Gollapudi struct bnx2fc_hba *hba = interface->hba;
1451853e2bd2SBhanu Gollapudi
1452853e2bd2SBhanu Gollapudi reg_base = pci_resource_start(hba->pcidev,
1453853e2bd2SBhanu Gollapudi BNX2X_DOORBELL_PCI_BAR);
1454f78afb35SMichael Chan reg_off = (1 << BNX2X_DB_SHIFT) * (context_id & 0x1FFFF);
14554bdc0d67SChristoph Hellwig tgt->ctx_base = ioremap(reg_base + reg_off, 4);
1456853e2bd2SBhanu Gollapudi if (!tgt->ctx_base)
1457853e2bd2SBhanu Gollapudi return -ENOMEM;
1458853e2bd2SBhanu Gollapudi return 0;
1459853e2bd2SBhanu Gollapudi }
1460853e2bd2SBhanu Gollapudi
bnx2fc_get_next_rqe(struct bnx2fc_rport * tgt,u8 num_items)1461853e2bd2SBhanu Gollapudi char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1462853e2bd2SBhanu Gollapudi {
1463853e2bd2SBhanu Gollapudi char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
1464853e2bd2SBhanu Gollapudi
1465853e2bd2SBhanu Gollapudi if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
1466853e2bd2SBhanu Gollapudi return NULL;
1467853e2bd2SBhanu Gollapudi
1468853e2bd2SBhanu Gollapudi tgt->rq_cons_idx += num_items;
1469853e2bd2SBhanu Gollapudi
1470853e2bd2SBhanu Gollapudi if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
1471853e2bd2SBhanu Gollapudi tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
1472853e2bd2SBhanu Gollapudi
1473853e2bd2SBhanu Gollapudi return buf;
1474853e2bd2SBhanu Gollapudi }
1475853e2bd2SBhanu Gollapudi
bnx2fc_return_rqe(struct bnx2fc_rport * tgt,u8 num_items)1476853e2bd2SBhanu Gollapudi void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1477853e2bd2SBhanu Gollapudi {
1478853e2bd2SBhanu Gollapudi /* return the rq buffer */
1479853e2bd2SBhanu Gollapudi u32 next_prod_idx = tgt->rq_prod_idx + num_items;
1480853e2bd2SBhanu Gollapudi if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
1481853e2bd2SBhanu Gollapudi /* Wrap around RQ */
1482853e2bd2SBhanu Gollapudi next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
1483853e2bd2SBhanu Gollapudi }
1484853e2bd2SBhanu Gollapudi tgt->rq_prod_idx = next_prod_idx;
1485853e2bd2SBhanu Gollapudi tgt->conn_db->rq_prod = tgt->rq_prod_idx;
1486853e2bd2SBhanu Gollapudi }
1487853e2bd2SBhanu Gollapudi
bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd * seq_clnp_req,struct fcoe_task_ctx_entry * task,struct bnx2fc_cmd * orig_io_req,u32 offset)14886c5a7ce4SBhanu Prakash Gollapudi void bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd *seq_clnp_req,
14896c5a7ce4SBhanu Prakash Gollapudi struct fcoe_task_ctx_entry *task,
14906c5a7ce4SBhanu Prakash Gollapudi struct bnx2fc_cmd *orig_io_req,
14916c5a7ce4SBhanu Prakash Gollapudi u32 offset)
14926c5a7ce4SBhanu Prakash Gollapudi {
14936c5a7ce4SBhanu Prakash Gollapudi struct scsi_cmnd *sc_cmd = orig_io_req->sc_cmd;
14946c5a7ce4SBhanu Prakash Gollapudi struct bnx2fc_rport *tgt = seq_clnp_req->tgt;
14956c5a7ce4SBhanu Prakash Gollapudi struct fcoe_bd_ctx *bd = orig_io_req->bd_tbl->bd_tbl;
14966c5a7ce4SBhanu Prakash Gollapudi struct fcoe_ext_mul_sges_ctx *sgl;
14976c5a7ce4SBhanu Prakash Gollapudi u8 task_type = FCOE_TASK_TYPE_SEQUENCE_CLEANUP;
14986c5a7ce4SBhanu Prakash Gollapudi u8 orig_task_type;
14996c5a7ce4SBhanu Prakash Gollapudi u16 orig_xid = orig_io_req->xid;
15006c5a7ce4SBhanu Prakash Gollapudi u32 context_id = tgt->context_id;
15016c5a7ce4SBhanu Prakash Gollapudi u64 phys_addr = (u64)orig_io_req->bd_tbl->bd_tbl_dma;
15026c5a7ce4SBhanu Prakash Gollapudi u32 orig_offset = offset;
15036c5a7ce4SBhanu Prakash Gollapudi int bd_count;
15046c5a7ce4SBhanu Prakash Gollapudi int i;
15056c5a7ce4SBhanu Prakash Gollapudi
15066c5a7ce4SBhanu Prakash Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
15076c5a7ce4SBhanu Prakash Gollapudi
15086c5a7ce4SBhanu Prakash Gollapudi if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
15096c5a7ce4SBhanu Prakash Gollapudi orig_task_type = FCOE_TASK_TYPE_WRITE;
15106c5a7ce4SBhanu Prakash Gollapudi else
15116c5a7ce4SBhanu Prakash Gollapudi orig_task_type = FCOE_TASK_TYPE_READ;
15126c5a7ce4SBhanu Prakash Gollapudi
15136c5a7ce4SBhanu Prakash Gollapudi /* Tx flags */
15146c5a7ce4SBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.tx_flags =
15156c5a7ce4SBhanu Prakash Gollapudi FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP <<
15166c5a7ce4SBhanu Prakash Gollapudi FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
15176c5a7ce4SBhanu Prakash Gollapudi /* init flags */
15186c5a7ce4SBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.init_flags = task_type <<
15196c5a7ce4SBhanu Prakash Gollapudi FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
15206c5a7ce4SBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
15216c5a7ce4SBhanu Prakash Gollapudi FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
15226c5a7ce4SBhanu Prakash Gollapudi task->rxwr_txrd.const_ctx.init_flags = context_id <<
15236c5a7ce4SBhanu Prakash Gollapudi FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
15246c5a7ce4SBhanu Prakash Gollapudi task->rxwr_txrd.const_ctx.init_flags = context_id <<
15256c5a7ce4SBhanu Prakash Gollapudi FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
15266c5a7ce4SBhanu Prakash Gollapudi
15276c5a7ce4SBhanu Prakash Gollapudi task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
15286c5a7ce4SBhanu Prakash Gollapudi
15296c5a7ce4SBhanu Prakash Gollapudi task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_seq_cnt = 0;
15306c5a7ce4SBhanu Prakash Gollapudi task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_data_offset = offset;
15316c5a7ce4SBhanu Prakash Gollapudi
15326c5a7ce4SBhanu Prakash Gollapudi bd_count = orig_io_req->bd_tbl->bd_valid;
15336c5a7ce4SBhanu Prakash Gollapudi
15346c5a7ce4SBhanu Prakash Gollapudi /* obtain the appropriate bd entry from relative offset */
15356c5a7ce4SBhanu Prakash Gollapudi for (i = 0; i < bd_count; i++) {
15366c5a7ce4SBhanu Prakash Gollapudi if (offset < bd[i].buf_len)
15376c5a7ce4SBhanu Prakash Gollapudi break;
15386c5a7ce4SBhanu Prakash Gollapudi offset -= bd[i].buf_len;
15396c5a7ce4SBhanu Prakash Gollapudi }
15406c5a7ce4SBhanu Prakash Gollapudi phys_addr += (i * sizeof(struct fcoe_bd_ctx));
15416c5a7ce4SBhanu Prakash Gollapudi
15426c5a7ce4SBhanu Prakash Gollapudi if (orig_task_type == FCOE_TASK_TYPE_WRITE) {
15436c5a7ce4SBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
15446c5a7ce4SBhanu Prakash Gollapudi (u32)phys_addr;
15456c5a7ce4SBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
15466c5a7ce4SBhanu Prakash Gollapudi (u32)((u64)phys_addr >> 32);
15476c5a7ce4SBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
15486c5a7ce4SBhanu Prakash Gollapudi bd_count;
15496c5a7ce4SBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_off =
15506c5a7ce4SBhanu Prakash Gollapudi offset; /* adjusted offset */
15516c5a7ce4SBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_idx = i;
15526c5a7ce4SBhanu Prakash Gollapudi } else {
15536c5a7ce4SBhanu Prakash Gollapudi
15546c5a7ce4SBhanu Prakash Gollapudi /* Multiple SGEs were used for this IO */
15556c5a7ce4SBhanu Prakash Gollapudi sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
15566c5a7ce4SBhanu Prakash Gollapudi sgl->mul_sgl.cur_sge_addr.lo = (u32)phys_addr;
15576c5a7ce4SBhanu Prakash Gollapudi sgl->mul_sgl.cur_sge_addr.hi = (u32)((u64)phys_addr >> 32);
15586c5a7ce4SBhanu Prakash Gollapudi sgl->mul_sgl.sgl_size = bd_count;
15596c5a7ce4SBhanu Prakash Gollapudi sgl->mul_sgl.cur_sge_off = offset; /*adjusted offset */
15606c5a7ce4SBhanu Prakash Gollapudi sgl->mul_sgl.cur_sge_idx = i;
15616c5a7ce4SBhanu Prakash Gollapudi
15626c5a7ce4SBhanu Prakash Gollapudi memset(&task->rxwr_only.rx_seq_ctx, 0,
15636c5a7ce4SBhanu Prakash Gollapudi sizeof(struct fcoe_rx_seq_ctx));
15646c5a7ce4SBhanu Prakash Gollapudi task->rxwr_only.rx_seq_ctx.low_exp_ro = orig_offset;
15656c5a7ce4SBhanu Prakash Gollapudi task->rxwr_only.rx_seq_ctx.high_exp_ro = orig_offset;
15666c5a7ce4SBhanu Prakash Gollapudi }
15676c5a7ce4SBhanu Prakash Gollapudi }
bnx2fc_init_cleanup_task(struct bnx2fc_cmd * io_req,struct fcoe_task_ctx_entry * task,u16 orig_xid)1568853e2bd2SBhanu Gollapudi void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
1569853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task,
1570853e2bd2SBhanu Gollapudi u16 orig_xid)
1571853e2bd2SBhanu Gollapudi {
1572853e2bd2SBhanu Gollapudi u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
1573853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt;
1574853e2bd2SBhanu Gollapudi u32 context_id = tgt->context_id;
1575853e2bd2SBhanu Gollapudi
1576853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1577853e2bd2SBhanu Gollapudi
1578853e2bd2SBhanu Gollapudi /* Tx Write Rx Read */
1579619c5cb6SVlad Zolotarov /* init flags */
1580619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags = task_type <<
1581619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1582619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1583619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1584f3820b71SBhanu Prakash Gollapudi if (tgt->dev_type == TYPE_TAPE)
1585f3820b71SBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.init_flags |=
1586f3820b71SBhanu Prakash Gollapudi FCOE_TASK_DEV_TYPE_TAPE <<
1587f3820b71SBhanu Prakash Gollapudi FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1588f3820b71SBhanu Prakash Gollapudi else
1589619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |=
1590619c5cb6SVlad Zolotarov FCOE_TASK_DEV_TYPE_DISK <<
1591619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1592619c5cb6SVlad Zolotarov task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
1593853e2bd2SBhanu Gollapudi
1594619c5cb6SVlad Zolotarov /* Tx flags */
1595619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.tx_flags =
1596619c5cb6SVlad Zolotarov FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
1597619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1598853e2bd2SBhanu Gollapudi
1599619c5cb6SVlad Zolotarov /* Rx Read Tx Write */
1600619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.init_flags = context_id <<
1601619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1602619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1603619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1604853e2bd2SBhanu Gollapudi }
1605853e2bd2SBhanu Gollapudi
bnx2fc_init_mp_task(struct bnx2fc_cmd * io_req,struct fcoe_task_ctx_entry * task)1606853e2bd2SBhanu Gollapudi void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
1607853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task)
1608853e2bd2SBhanu Gollapudi {
1609853e2bd2SBhanu Gollapudi struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
1610853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt;
1611853e2bd2SBhanu Gollapudi struct fc_frame_header *fc_hdr;
1612619c5cb6SVlad Zolotarov struct fcoe_ext_mul_sges_ctx *sgl;
1613853e2bd2SBhanu Gollapudi u8 task_type = 0;
1614853e2bd2SBhanu Gollapudi u64 *hdr;
1615853e2bd2SBhanu Gollapudi u64 temp_hdr[3];
1616853e2bd2SBhanu Gollapudi u32 context_id;
1617853e2bd2SBhanu Gollapudi
1618853e2bd2SBhanu Gollapudi
1619853e2bd2SBhanu Gollapudi /* Obtain task_type */
1620853e2bd2SBhanu Gollapudi if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
1621853e2bd2SBhanu Gollapudi (io_req->cmd_type == BNX2FC_ELS)) {
1622853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_MIDPATH;
1623853e2bd2SBhanu Gollapudi } else if (io_req->cmd_type == BNX2FC_ABTS) {
1624853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_ABTS;
1625853e2bd2SBhanu Gollapudi }
1626853e2bd2SBhanu Gollapudi
1627853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1628853e2bd2SBhanu Gollapudi
1629853e2bd2SBhanu Gollapudi /* Setup the task from io_req for easy reference */
1630853e2bd2SBhanu Gollapudi io_req->task = task;
1631853e2bd2SBhanu Gollapudi
1632853e2bd2SBhanu Gollapudi BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
1633853e2bd2SBhanu Gollapudi io_req->cmd_type, task_type);
1634853e2bd2SBhanu Gollapudi
1635853e2bd2SBhanu Gollapudi /* Tx only */
1636853e2bd2SBhanu Gollapudi if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
1637853e2bd2SBhanu Gollapudi (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
1638619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1639853e2bd2SBhanu Gollapudi (u32)mp_req->mp_req_bd_dma;
1640619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1641853e2bd2SBhanu Gollapudi (u32)((u64)mp_req->mp_req_bd_dma >> 32);
1642619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1;
1643853e2bd2SBhanu Gollapudi }
1644853e2bd2SBhanu Gollapudi
1645853e2bd2SBhanu Gollapudi /* Tx Write Rx Read */
1646619c5cb6SVlad Zolotarov /* init flags */
1647619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags = task_type <<
1648619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1649f3820b71SBhanu Prakash Gollapudi if (tgt->dev_type == TYPE_TAPE)
1650f3820b71SBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.init_flags |=
1651f3820b71SBhanu Prakash Gollapudi FCOE_TASK_DEV_TYPE_TAPE <<
1652f3820b71SBhanu Prakash Gollapudi FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1653f3820b71SBhanu Prakash Gollapudi else
1654619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |=
1655619c5cb6SVlad Zolotarov FCOE_TASK_DEV_TYPE_DISK <<
1656619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1657619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1658619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1659853e2bd2SBhanu Gollapudi
1660619c5cb6SVlad Zolotarov /* tx flags */
1661619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_INIT <<
1662619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1663853e2bd2SBhanu Gollapudi
1664853e2bd2SBhanu Gollapudi /* Rx Write Tx Read */
1665619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1666619c5cb6SVlad Zolotarov
1667619c5cb6SVlad Zolotarov /* rx flags */
1668619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1669619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1670619c5cb6SVlad Zolotarov
1671619c5cb6SVlad Zolotarov context_id = tgt->context_id;
1672619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.init_flags = context_id <<
1673619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1674619c5cb6SVlad Zolotarov
1675853e2bd2SBhanu Gollapudi fc_hdr = &(mp_req->req_fc_hdr);
1676853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1677853e2bd2SBhanu Gollapudi fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
1678853e2bd2SBhanu Gollapudi fc_hdr->fh_rx_id = htons(0xffff);
1679619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1680853e2bd2SBhanu Gollapudi } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
1681853e2bd2SBhanu Gollapudi fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
1682853e2bd2SBhanu Gollapudi }
1683853e2bd2SBhanu Gollapudi
1684853e2bd2SBhanu Gollapudi /* Fill FC Header into middle path buffer */
1685619c5cb6SVlad Zolotarov hdr = (u64 *) &task->txwr_rxrd.union_ctx.tx_frame.fc_hdr;
1686853e2bd2SBhanu Gollapudi memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
1687853e2bd2SBhanu Gollapudi hdr[0] = cpu_to_be64(temp_hdr[0]);
1688853e2bd2SBhanu Gollapudi hdr[1] = cpu_to_be64(temp_hdr[1]);
1689853e2bd2SBhanu Gollapudi hdr[2] = cpu_to_be64(temp_hdr[2]);
1690853e2bd2SBhanu Gollapudi
1691853e2bd2SBhanu Gollapudi /* Rx Only */
1692853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1693619c5cb6SVlad Zolotarov sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1694853e2bd2SBhanu Gollapudi
1695619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.lo = (u32)mp_req->mp_resp_bd_dma;
1696619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.hi =
1697853e2bd2SBhanu Gollapudi (u32)((u64)mp_req->mp_resp_bd_dma >> 32);
1698619c5cb6SVlad Zolotarov sgl->mul_sgl.sgl_size = 1;
1699853e2bd2SBhanu Gollapudi }
1700853e2bd2SBhanu Gollapudi }
1701853e2bd2SBhanu Gollapudi
bnx2fc_init_task(struct bnx2fc_cmd * io_req,struct fcoe_task_ctx_entry * task)1702853e2bd2SBhanu Gollapudi void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
1703853e2bd2SBhanu Gollapudi struct fcoe_task_ctx_entry *task)
1704853e2bd2SBhanu Gollapudi {
1705853e2bd2SBhanu Gollapudi u8 task_type;
1706853e2bd2SBhanu Gollapudi struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1707853e2bd2SBhanu Gollapudi struct io_bdt *bd_tbl = io_req->bd_tbl;
1708853e2bd2SBhanu Gollapudi struct bnx2fc_rport *tgt = io_req->tgt;
1709619c5cb6SVlad Zolotarov struct fcoe_cached_sge_ctx *cached_sge;
1710619c5cb6SVlad Zolotarov struct fcoe_ext_mul_sges_ctx *sgl;
1711f3820b71SBhanu Prakash Gollapudi int dev_type = tgt->dev_type;
1712853e2bd2SBhanu Gollapudi u64 *fcp_cmnd;
1713853e2bd2SBhanu Gollapudi u64 tmp_fcp_cmnd[4];
1714853e2bd2SBhanu Gollapudi u32 context_id;
1715853e2bd2SBhanu Gollapudi int cnt, i;
1716853e2bd2SBhanu Gollapudi int bd_count;
1717853e2bd2SBhanu Gollapudi
1718853e2bd2SBhanu Gollapudi memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1719853e2bd2SBhanu Gollapudi
1720853e2bd2SBhanu Gollapudi /* Setup the task from io_req for easy reference */
1721853e2bd2SBhanu Gollapudi io_req->task = task;
1722853e2bd2SBhanu Gollapudi
1723853e2bd2SBhanu Gollapudi if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1724853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_WRITE;
1725853e2bd2SBhanu Gollapudi else
1726853e2bd2SBhanu Gollapudi task_type = FCOE_TASK_TYPE_READ;
1727853e2bd2SBhanu Gollapudi
1728853e2bd2SBhanu Gollapudi /* Tx only */
17293c75108fSBhanu Prakash Gollapudi bd_count = bd_tbl->bd_valid;
17301101a0d8SBhanu Prakash Gollapudi cached_sge = &task->rxwr_only.union_ctx.read_info.sgl_ctx.cached_sge;
1731853e2bd2SBhanu Gollapudi if (task_type == FCOE_TASK_TYPE_WRITE) {
17323c75108fSBhanu Prakash Gollapudi if ((dev_type == TYPE_DISK) && (bd_count == 1)) {
17333c75108fSBhanu Prakash Gollapudi struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
17343c75108fSBhanu Prakash Gollapudi
17353c75108fSBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.lo =
17361101a0d8SBhanu Prakash Gollapudi cached_sge->cur_buf_addr.lo =
17373c75108fSBhanu Prakash Gollapudi fcoe_bd_tbl->buf_addr_lo;
17383c75108fSBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.hi =
17391101a0d8SBhanu Prakash Gollapudi cached_sge->cur_buf_addr.hi =
17403c75108fSBhanu Prakash Gollapudi fcoe_bd_tbl->buf_addr_hi;
17413c75108fSBhanu Prakash Gollapudi task->txwr_only.sgl_ctx.cached_sge.cur_buf_rem =
17421101a0d8SBhanu Prakash Gollapudi cached_sge->cur_buf_rem =
17433c75108fSBhanu Prakash Gollapudi fcoe_bd_tbl->buf_len;
17443c75108fSBhanu Prakash Gollapudi
17453c75108fSBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.init_flags |= 1 <<
17463c75108fSBhanu Prakash Gollapudi FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
17473c75108fSBhanu Prakash Gollapudi } else {
1748619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1749853e2bd2SBhanu Gollapudi (u32)bd_tbl->bd_tbl_dma;
1750619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1751853e2bd2SBhanu Gollapudi (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1752619c5cb6SVlad Zolotarov task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
1753853e2bd2SBhanu Gollapudi bd_tbl->bd_valid;
1754853e2bd2SBhanu Gollapudi }
17553c75108fSBhanu Prakash Gollapudi }
1756853e2bd2SBhanu Gollapudi
1757853e2bd2SBhanu Gollapudi /*Tx Write Rx Read */
1758853e2bd2SBhanu Gollapudi /* Init state to NORMAL */
17593c75108fSBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.init_flags |= task_type <<
1760619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1761c1c16bd5SBhanu Prakash Gollapudi if (dev_type == TYPE_TAPE) {
1762f3820b71SBhanu Prakash Gollapudi task->txwr_rxrd.const_ctx.init_flags |=
1763f3820b71SBhanu Prakash Gollapudi FCOE_TASK_DEV_TYPE_TAPE <<
1764f3820b71SBhanu Prakash Gollapudi FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1765c1c16bd5SBhanu Prakash Gollapudi io_req->rec_retry = 0;
1766c1c16bd5SBhanu Prakash Gollapudi io_req->rec_retry = 0;
1767c1c16bd5SBhanu Prakash Gollapudi } else
1768619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |=
1769619c5cb6SVlad Zolotarov FCOE_TASK_DEV_TYPE_DISK <<
1770619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1771619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1772619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1773619c5cb6SVlad Zolotarov /* tx flags */
1774619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
1775619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1776853e2bd2SBhanu Gollapudi
1777853e2bd2SBhanu Gollapudi /* Set initial seq counter */
1778619c5cb6SVlad Zolotarov task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1;
1779853e2bd2SBhanu Gollapudi
1780853e2bd2SBhanu Gollapudi /* Fill FCP_CMND IU */
1781853e2bd2SBhanu Gollapudi fcp_cmnd = (u64 *)
1782619c5cb6SVlad Zolotarov task->txwr_rxrd.union_ctx.fcp_cmd.opaque;
1783853e2bd2SBhanu Gollapudi bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
1784853e2bd2SBhanu Gollapudi
1785853e2bd2SBhanu Gollapudi /* swap fcp_cmnd */
1786853e2bd2SBhanu Gollapudi cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
1787853e2bd2SBhanu Gollapudi
1788853e2bd2SBhanu Gollapudi for (i = 0; i < cnt; i++) {
1789853e2bd2SBhanu Gollapudi *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
1790853e2bd2SBhanu Gollapudi fcp_cmnd++;
1791853e2bd2SBhanu Gollapudi }
1792853e2bd2SBhanu Gollapudi
1793853e2bd2SBhanu Gollapudi /* Rx Write Tx Read */
1794619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1795619c5cb6SVlad Zolotarov
1796619c5cb6SVlad Zolotarov context_id = tgt->context_id;
1797619c5cb6SVlad Zolotarov task->rxwr_txrd.const_ctx.init_flags = context_id <<
1798619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1799619c5cb6SVlad Zolotarov
1800619c5cb6SVlad Zolotarov /* rx flags */
1801619c5cb6SVlad Zolotarov /* Set state to "waiting for the first packet" */
1802619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1803619c5cb6SVlad Zolotarov FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1804619c5cb6SVlad Zolotarov
1805619c5cb6SVlad Zolotarov task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1806853e2bd2SBhanu Gollapudi
1807853e2bd2SBhanu Gollapudi /* Rx Only */
18081101a0d8SBhanu Prakash Gollapudi if (task_type != FCOE_TASK_TYPE_READ)
18091101a0d8SBhanu Prakash Gollapudi return;
18101101a0d8SBhanu Prakash Gollapudi
1811619c5cb6SVlad Zolotarov sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1812853e2bd2SBhanu Gollapudi bd_count = bd_tbl->bd_valid;
18131101a0d8SBhanu Prakash Gollapudi
18141101a0d8SBhanu Prakash Gollapudi if (dev_type == TYPE_DISK) {
1815853e2bd2SBhanu Gollapudi if (bd_count == 1) {
1816853e2bd2SBhanu Gollapudi
1817853e2bd2SBhanu Gollapudi struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1818853e2bd2SBhanu Gollapudi
1819619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1820619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1821619c5cb6SVlad Zolotarov cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1822619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1823619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1824619c5cb6SVlad Zolotarov } else if (bd_count == 2) {
1825619c5cb6SVlad Zolotarov struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1826619c5cb6SVlad Zolotarov
1827619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1828619c5cb6SVlad Zolotarov cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1829619c5cb6SVlad Zolotarov cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1830619c5cb6SVlad Zolotarov
1831619c5cb6SVlad Zolotarov fcoe_bd_tbl++;
1832619c5cb6SVlad Zolotarov cached_sge->second_buf_addr.lo =
1833853e2bd2SBhanu Gollapudi fcoe_bd_tbl->buf_addr_lo;
1834619c5cb6SVlad Zolotarov cached_sge->second_buf_addr.hi =
1835853e2bd2SBhanu Gollapudi fcoe_bd_tbl->buf_addr_hi;
1836619c5cb6SVlad Zolotarov cached_sge->second_buf_rem = fcoe_bd_tbl->buf_len;
1837619c5cb6SVlad Zolotarov task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1838619c5cb6SVlad Zolotarov FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1839853e2bd2SBhanu Gollapudi } else {
1840853e2bd2SBhanu Gollapudi
1841619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
1842619c5cb6SVlad Zolotarov sgl->mul_sgl.cur_sge_addr.hi =
1843853e2bd2SBhanu Gollapudi (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1844619c5cb6SVlad Zolotarov sgl->mul_sgl.sgl_size = bd_count;
1845853e2bd2SBhanu Gollapudi }
1846f3820b71SBhanu Prakash Gollapudi } else {
1847f3820b71SBhanu Prakash Gollapudi sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
1848f3820b71SBhanu Prakash Gollapudi sgl->mul_sgl.cur_sge_addr.hi =
1849f3820b71SBhanu Prakash Gollapudi (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1850f3820b71SBhanu Prakash Gollapudi sgl->mul_sgl.sgl_size = bd_count;
1851853e2bd2SBhanu Gollapudi }
1852853e2bd2SBhanu Gollapudi }
1853853e2bd2SBhanu Gollapudi
1854853e2bd2SBhanu Gollapudi /**
1855853e2bd2SBhanu Gollapudi * bnx2fc_setup_task_ctx - allocate and map task context
1856853e2bd2SBhanu Gollapudi *
1857853e2bd2SBhanu Gollapudi * @hba: pointer to adapter structure
1858853e2bd2SBhanu Gollapudi *
1859853e2bd2SBhanu Gollapudi * allocate memory for task context, and associated BD table to be used
1860853e2bd2SBhanu Gollapudi * by firmware
1861853e2bd2SBhanu Gollapudi *
1862853e2bd2SBhanu Gollapudi */
bnx2fc_setup_task_ctx(struct bnx2fc_hba * hba)1863853e2bd2SBhanu Gollapudi int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
1864853e2bd2SBhanu Gollapudi {
1865853e2bd2SBhanu Gollapudi int rc = 0;
1866853e2bd2SBhanu Gollapudi struct regpair *task_ctx_bdt;
1867853e2bd2SBhanu Gollapudi dma_addr_t addr;
18680eb43b4bSBhanu Prakash Gollapudi int task_ctx_arr_sz;
1869853e2bd2SBhanu Gollapudi int i;
1870853e2bd2SBhanu Gollapudi
1871853e2bd2SBhanu Gollapudi /*
1872853e2bd2SBhanu Gollapudi * Allocate task context bd table. A page size of bd table
1873853e2bd2SBhanu Gollapudi * can map 256 buffers. Each buffer contains 32 task context
1874853e2bd2SBhanu Gollapudi * entries. Hence the limit with one page is 8192 task context
1875853e2bd2SBhanu Gollapudi * entries.
1876853e2bd2SBhanu Gollapudi */
1877750afb08SLuis Chamberlain hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
1878853e2bd2SBhanu Gollapudi PAGE_SIZE,
1879853e2bd2SBhanu Gollapudi &hba->task_ctx_bd_dma,
1880853e2bd2SBhanu Gollapudi GFP_KERNEL);
1881853e2bd2SBhanu Gollapudi if (!hba->task_ctx_bd_tbl) {
1882853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate task context BDT\n");
1883853e2bd2SBhanu Gollapudi rc = -1;
1884853e2bd2SBhanu Gollapudi goto out;
1885853e2bd2SBhanu Gollapudi }
1886853e2bd2SBhanu Gollapudi
1887853e2bd2SBhanu Gollapudi /*
1888853e2bd2SBhanu Gollapudi * Allocate task_ctx which is an array of pointers pointing to
1889853e2bd2SBhanu Gollapudi * a page containing 32 task contexts
1890853e2bd2SBhanu Gollapudi */
18910eb43b4bSBhanu Prakash Gollapudi task_ctx_arr_sz = (hba->max_tasks / BNX2FC_TASKS_PER_PAGE);
18920eb43b4bSBhanu Prakash Gollapudi hba->task_ctx = kzalloc((task_ctx_arr_sz * sizeof(void *)),
1893853e2bd2SBhanu Gollapudi GFP_KERNEL);
1894853e2bd2SBhanu Gollapudi if (!hba->task_ctx) {
1895853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate task context array\n");
1896853e2bd2SBhanu Gollapudi rc = -1;
1897853e2bd2SBhanu Gollapudi goto out1;
1898853e2bd2SBhanu Gollapudi }
1899853e2bd2SBhanu Gollapudi
1900853e2bd2SBhanu Gollapudi /*
1901853e2bd2SBhanu Gollapudi * Allocate task_ctx_dma which is an array of dma addresses
1902853e2bd2SBhanu Gollapudi */
19030eb43b4bSBhanu Prakash Gollapudi hba->task_ctx_dma = kmalloc((task_ctx_arr_sz *
1904853e2bd2SBhanu Gollapudi sizeof(dma_addr_t)), GFP_KERNEL);
1905853e2bd2SBhanu Gollapudi if (!hba->task_ctx_dma) {
1906853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc context mapping array\n");
1907853e2bd2SBhanu Gollapudi rc = -1;
1908853e2bd2SBhanu Gollapudi goto out2;
1909853e2bd2SBhanu Gollapudi }
1910853e2bd2SBhanu Gollapudi
1911853e2bd2SBhanu Gollapudi task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
19120eb43b4bSBhanu Prakash Gollapudi for (i = 0; i < task_ctx_arr_sz; i++) {
1913853e2bd2SBhanu Gollapudi
1914750afb08SLuis Chamberlain hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
1915853e2bd2SBhanu Gollapudi PAGE_SIZE,
1916853e2bd2SBhanu Gollapudi &hba->task_ctx_dma[i],
1917853e2bd2SBhanu Gollapudi GFP_KERNEL);
1918853e2bd2SBhanu Gollapudi if (!hba->task_ctx[i]) {
1919853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc task context\n");
1920853e2bd2SBhanu Gollapudi rc = -1;
1921853e2bd2SBhanu Gollapudi goto out3;
1922853e2bd2SBhanu Gollapudi }
1923853e2bd2SBhanu Gollapudi addr = (u64)hba->task_ctx_dma[i];
1924853e2bd2SBhanu Gollapudi task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
1925853e2bd2SBhanu Gollapudi task_ctx_bdt->lo = cpu_to_le32((u32)addr);
1926853e2bd2SBhanu Gollapudi task_ctx_bdt++;
1927853e2bd2SBhanu Gollapudi }
1928853e2bd2SBhanu Gollapudi return 0;
1929853e2bd2SBhanu Gollapudi
1930853e2bd2SBhanu Gollapudi out3:
19310eb43b4bSBhanu Prakash Gollapudi for (i = 0; i < task_ctx_arr_sz; i++) {
1932853e2bd2SBhanu Gollapudi if (hba->task_ctx[i]) {
1933853e2bd2SBhanu Gollapudi
1934853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1935853e2bd2SBhanu Gollapudi hba->task_ctx[i], hba->task_ctx_dma[i]);
1936853e2bd2SBhanu Gollapudi hba->task_ctx[i] = NULL;
1937853e2bd2SBhanu Gollapudi }
1938853e2bd2SBhanu Gollapudi }
1939853e2bd2SBhanu Gollapudi
1940853e2bd2SBhanu Gollapudi kfree(hba->task_ctx_dma);
1941853e2bd2SBhanu Gollapudi hba->task_ctx_dma = NULL;
1942853e2bd2SBhanu Gollapudi out2:
1943853e2bd2SBhanu Gollapudi kfree(hba->task_ctx);
1944853e2bd2SBhanu Gollapudi hba->task_ctx = NULL;
1945853e2bd2SBhanu Gollapudi out1:
1946853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1947853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
1948853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = NULL;
1949853e2bd2SBhanu Gollapudi out:
1950853e2bd2SBhanu Gollapudi return rc;
1951853e2bd2SBhanu Gollapudi }
1952853e2bd2SBhanu Gollapudi
bnx2fc_free_task_ctx(struct bnx2fc_hba * hba)1953853e2bd2SBhanu Gollapudi void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
1954853e2bd2SBhanu Gollapudi {
19550eb43b4bSBhanu Prakash Gollapudi int task_ctx_arr_sz;
1956853e2bd2SBhanu Gollapudi int i;
1957853e2bd2SBhanu Gollapudi
1958853e2bd2SBhanu Gollapudi if (hba->task_ctx_bd_tbl) {
1959853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1960853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl,
1961853e2bd2SBhanu Gollapudi hba->task_ctx_bd_dma);
1962853e2bd2SBhanu Gollapudi hba->task_ctx_bd_tbl = NULL;
1963853e2bd2SBhanu Gollapudi }
1964853e2bd2SBhanu Gollapudi
19650eb43b4bSBhanu Prakash Gollapudi task_ctx_arr_sz = (hba->max_tasks / BNX2FC_TASKS_PER_PAGE);
1966853e2bd2SBhanu Gollapudi if (hba->task_ctx) {
19670eb43b4bSBhanu Prakash Gollapudi for (i = 0; i < task_ctx_arr_sz; i++) {
1968853e2bd2SBhanu Gollapudi if (hba->task_ctx[i]) {
1969853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1970853e2bd2SBhanu Gollapudi hba->task_ctx[i],
1971853e2bd2SBhanu Gollapudi hba->task_ctx_dma[i]);
1972853e2bd2SBhanu Gollapudi hba->task_ctx[i] = NULL;
1973853e2bd2SBhanu Gollapudi }
1974853e2bd2SBhanu Gollapudi }
1975853e2bd2SBhanu Gollapudi kfree(hba->task_ctx);
1976853e2bd2SBhanu Gollapudi hba->task_ctx = NULL;
1977853e2bd2SBhanu Gollapudi }
1978853e2bd2SBhanu Gollapudi
1979853e2bd2SBhanu Gollapudi kfree(hba->task_ctx_dma);
1980853e2bd2SBhanu Gollapudi hba->task_ctx_dma = NULL;
1981853e2bd2SBhanu Gollapudi }
1982853e2bd2SBhanu Gollapudi
bnx2fc_free_hash_table(struct bnx2fc_hba * hba)1983853e2bd2SBhanu Gollapudi static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
1984853e2bd2SBhanu Gollapudi {
1985853e2bd2SBhanu Gollapudi int i;
1986853e2bd2SBhanu Gollapudi int segment_count;
1987853e2bd2SBhanu Gollapudi u32 *pbl;
1988853e2bd2SBhanu Gollapudi
198991d9f809SMaurizio Lombardi if (hba->hash_tbl_segments) {
1990853e2bd2SBhanu Gollapudi
1991853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl;
199291d9f809SMaurizio Lombardi if (pbl) {
199391d9f809SMaurizio Lombardi segment_count = hba->hash_tbl_segment_count;
1994853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) {
1995853e2bd2SBhanu Gollapudi dma_addr_t dma_address;
1996853e2bd2SBhanu Gollapudi
1997853e2bd2SBhanu Gollapudi dma_address = le32_to_cpu(*pbl);
1998853e2bd2SBhanu Gollapudi ++pbl;
1999853e2bd2SBhanu Gollapudi dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
2000853e2bd2SBhanu Gollapudi ++pbl;
2001853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev,
2002853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE,
2003853e2bd2SBhanu Gollapudi hba->hash_tbl_segments[i],
2004853e2bd2SBhanu Gollapudi dma_address);
200591d9f809SMaurizio Lombardi }
200691d9f809SMaurizio Lombardi }
2007853e2bd2SBhanu Gollapudi
200891d9f809SMaurizio Lombardi kfree(hba->hash_tbl_segments);
200991d9f809SMaurizio Lombardi hba->hash_tbl_segments = NULL;
2010853e2bd2SBhanu Gollapudi }
2011853e2bd2SBhanu Gollapudi
2012853e2bd2SBhanu Gollapudi if (hba->hash_tbl_pbl) {
2013853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2014853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl,
2015853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl_dma);
2016853e2bd2SBhanu Gollapudi hba->hash_tbl_pbl = NULL;
2017853e2bd2SBhanu Gollapudi }
2018853e2bd2SBhanu Gollapudi }
2019853e2bd2SBhanu Gollapudi
bnx2fc_allocate_hash_table(struct bnx2fc_hba * hba)2020853e2bd2SBhanu Gollapudi static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
2021853e2bd2SBhanu Gollapudi {
2022853e2bd2SBhanu Gollapudi int i;
2023853e2bd2SBhanu Gollapudi int hash_table_size;
2024853e2bd2SBhanu Gollapudi int segment_count;
2025853e2bd2SBhanu Gollapudi int segment_array_size;
2026853e2bd2SBhanu Gollapudi int dma_segment_array_size;
2027853e2bd2SBhanu Gollapudi dma_addr_t *dma_segment_array;
2028853e2bd2SBhanu Gollapudi u32 *pbl;
2029853e2bd2SBhanu Gollapudi
2030853e2bd2SBhanu Gollapudi hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
2031853e2bd2SBhanu Gollapudi sizeof(struct fcoe_hash_table_entry);
2032853e2bd2SBhanu Gollapudi
2033853e2bd2SBhanu Gollapudi segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
2034853e2bd2SBhanu Gollapudi segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
2035853e2bd2SBhanu Gollapudi hba->hash_tbl_segment_count = segment_count;
2036853e2bd2SBhanu Gollapudi
2037853e2bd2SBhanu Gollapudi segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
2038853e2bd2SBhanu Gollapudi hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
2039853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_segments) {
2040853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pointers alloc failed\n");
2041853e2bd2SBhanu Gollapudi return -ENOMEM;
2042853e2bd2SBhanu Gollapudi }
2043853e2bd2SBhanu Gollapudi dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
2044853e2bd2SBhanu Gollapudi dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
2045853e2bd2SBhanu Gollapudi if (!dma_segment_array) {
2046853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
2047fdbcbcabSMaurizio Lombardi goto cleanup_ht;
2048853e2bd2SBhanu Gollapudi }
2049853e2bd2SBhanu Gollapudi
2050853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) {
2051750afb08SLuis Chamberlain hba->hash_tbl_segments[i] = dma_alloc_coherent(&hba->pcidev->dev,
2052853e2bd2SBhanu Gollapudi BNX2FC_HASH_TBL_CHUNK_SIZE,
2053853e2bd2SBhanu Gollapudi &dma_segment_array[i],
2054853e2bd2SBhanu Gollapudi GFP_KERNEL);
2055853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_segments[i]) {
2056853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash segment alloc failed\n");
2057fdbcbcabSMaurizio Lombardi goto cleanup_dma;
2058853e2bd2SBhanu Gollapudi }
2059853e2bd2SBhanu Gollapudi }
2060853e2bd2SBhanu Gollapudi
2061750afb08SLuis Chamberlain hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
2062853e2bd2SBhanu Gollapudi &hba->hash_tbl_pbl_dma,
2063853e2bd2SBhanu Gollapudi GFP_KERNEL);
2064853e2bd2SBhanu Gollapudi if (!hba->hash_tbl_pbl) {
2065853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "hash table pbl alloc failed\n");
2066fdbcbcabSMaurizio Lombardi goto cleanup_dma;
2067853e2bd2SBhanu Gollapudi }
2068853e2bd2SBhanu Gollapudi
2069853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl;
2070853e2bd2SBhanu Gollapudi for (i = 0; i < segment_count; ++i) {
2071853e2bd2SBhanu Gollapudi u64 paddr = dma_segment_array[i];
2072853e2bd2SBhanu Gollapudi *pbl = cpu_to_le32((u32) paddr);
2073853e2bd2SBhanu Gollapudi ++pbl;
2074853e2bd2SBhanu Gollapudi *pbl = cpu_to_le32((u32) (paddr >> 32));
2075853e2bd2SBhanu Gollapudi ++pbl;
2076853e2bd2SBhanu Gollapudi }
2077853e2bd2SBhanu Gollapudi pbl = hba->hash_tbl_pbl;
2078853e2bd2SBhanu Gollapudi i = 0;
2079853e2bd2SBhanu Gollapudi while (*pbl && *(pbl + 1)) {
2080853e2bd2SBhanu Gollapudi ++pbl;
2081853e2bd2SBhanu Gollapudi ++pbl;
2082853e2bd2SBhanu Gollapudi ++i;
2083853e2bd2SBhanu Gollapudi }
2084853e2bd2SBhanu Gollapudi kfree(dma_segment_array);
2085853e2bd2SBhanu Gollapudi return 0;
2086fdbcbcabSMaurizio Lombardi
2087fdbcbcabSMaurizio Lombardi cleanup_dma:
2088fdbcbcabSMaurizio Lombardi for (i = 0; i < segment_count; ++i) {
2089fdbcbcabSMaurizio Lombardi if (hba->hash_tbl_segments[i])
2090fdbcbcabSMaurizio Lombardi dma_free_coherent(&hba->pcidev->dev,
2091fdbcbcabSMaurizio Lombardi BNX2FC_HASH_TBL_CHUNK_SIZE,
2092fdbcbcabSMaurizio Lombardi hba->hash_tbl_segments[i],
2093fdbcbcabSMaurizio Lombardi dma_segment_array[i]);
2094fdbcbcabSMaurizio Lombardi }
2095fdbcbcabSMaurizio Lombardi
2096fdbcbcabSMaurizio Lombardi kfree(dma_segment_array);
2097fdbcbcabSMaurizio Lombardi
2098fdbcbcabSMaurizio Lombardi cleanup_ht:
2099fdbcbcabSMaurizio Lombardi kfree(hba->hash_tbl_segments);
2100fdbcbcabSMaurizio Lombardi hba->hash_tbl_segments = NULL;
2101fdbcbcabSMaurizio Lombardi return -ENOMEM;
2102853e2bd2SBhanu Gollapudi }
2103853e2bd2SBhanu Gollapudi
2104853e2bd2SBhanu Gollapudi /**
2105853e2bd2SBhanu Gollapudi * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
2106853e2bd2SBhanu Gollapudi *
2107853e2bd2SBhanu Gollapudi * @hba: Pointer to adapter structure
2108853e2bd2SBhanu Gollapudi *
2109853e2bd2SBhanu Gollapudi */
bnx2fc_setup_fw_resc(struct bnx2fc_hba * hba)2110853e2bd2SBhanu Gollapudi int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
2111853e2bd2SBhanu Gollapudi {
2112853e2bd2SBhanu Gollapudi u64 addr;
2113853e2bd2SBhanu Gollapudi u32 mem_size;
2114853e2bd2SBhanu Gollapudi int i;
2115853e2bd2SBhanu Gollapudi
2116853e2bd2SBhanu Gollapudi if (bnx2fc_allocate_hash_table(hba))
2117853e2bd2SBhanu Gollapudi return -ENOMEM;
2118853e2bd2SBhanu Gollapudi
2119853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2120750afb08SLuis Chamberlain hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2121853e2bd2SBhanu Gollapudi &hba->t2_hash_tbl_ptr_dma,
2122853e2bd2SBhanu Gollapudi GFP_KERNEL);
2123853e2bd2SBhanu Gollapudi if (!hba->t2_hash_tbl_ptr) {
2124853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
2125853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba);
2126853e2bd2SBhanu Gollapudi return -ENOMEM;
2127853e2bd2SBhanu Gollapudi }
2128853e2bd2SBhanu Gollapudi
2129853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS *
2130853e2bd2SBhanu Gollapudi sizeof(struct fcoe_t2_hash_table_entry);
2131750afb08SLuis Chamberlain hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2132853e2bd2SBhanu Gollapudi &hba->t2_hash_tbl_dma,
2133853e2bd2SBhanu Gollapudi GFP_KERNEL);
2134853e2bd2SBhanu Gollapudi if (!hba->t2_hash_tbl) {
2135853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
2136853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba);
2137853e2bd2SBhanu Gollapudi return -ENOMEM;
2138853e2bd2SBhanu Gollapudi }
2139853e2bd2SBhanu Gollapudi for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
2140853e2bd2SBhanu Gollapudi addr = (unsigned long) hba->t2_hash_tbl_dma +
2141853e2bd2SBhanu Gollapudi ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
2142853e2bd2SBhanu Gollapudi hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
2143853e2bd2SBhanu Gollapudi hba->t2_hash_tbl[i].next.hi = addr >> 32;
2144853e2bd2SBhanu Gollapudi }
2145853e2bd2SBhanu Gollapudi
2146853e2bd2SBhanu Gollapudi hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
2147853e2bd2SBhanu Gollapudi PAGE_SIZE, &hba->dummy_buf_dma,
2148853e2bd2SBhanu Gollapudi GFP_KERNEL);
2149853e2bd2SBhanu Gollapudi if (!hba->dummy_buffer) {
2150853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
2151853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba);
2152853e2bd2SBhanu Gollapudi return -ENOMEM;
2153853e2bd2SBhanu Gollapudi }
2154853e2bd2SBhanu Gollapudi
2155750afb08SLuis Chamberlain hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
2156853e2bd2SBhanu Gollapudi &hba->stats_buf_dma,
2157853e2bd2SBhanu Gollapudi GFP_KERNEL);
2158853e2bd2SBhanu Gollapudi if (!hba->stats_buffer) {
2159853e2bd2SBhanu Gollapudi printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
2160853e2bd2SBhanu Gollapudi bnx2fc_free_fw_resc(hba);
2161853e2bd2SBhanu Gollapudi return -ENOMEM;
2162853e2bd2SBhanu Gollapudi }
2163853e2bd2SBhanu Gollapudi
2164853e2bd2SBhanu Gollapudi return 0;
2165853e2bd2SBhanu Gollapudi }
2166853e2bd2SBhanu Gollapudi
bnx2fc_free_fw_resc(struct bnx2fc_hba * hba)2167853e2bd2SBhanu Gollapudi void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
2168853e2bd2SBhanu Gollapudi {
2169853e2bd2SBhanu Gollapudi u32 mem_size;
2170853e2bd2SBhanu Gollapudi
2171853e2bd2SBhanu Gollapudi if (hba->stats_buffer) {
2172853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2173853e2bd2SBhanu Gollapudi hba->stats_buffer, hba->stats_buf_dma);
2174853e2bd2SBhanu Gollapudi hba->stats_buffer = NULL;
2175853e2bd2SBhanu Gollapudi }
2176853e2bd2SBhanu Gollapudi
2177853e2bd2SBhanu Gollapudi if (hba->dummy_buffer) {
2178853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2179853e2bd2SBhanu Gollapudi hba->dummy_buffer, hba->dummy_buf_dma);
2180853e2bd2SBhanu Gollapudi hba->dummy_buffer = NULL;
2181853e2bd2SBhanu Gollapudi }
2182853e2bd2SBhanu Gollapudi
2183853e2bd2SBhanu Gollapudi if (hba->t2_hash_tbl_ptr) {
2184853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2185853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, mem_size,
2186853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr,
2187853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr_dma);
2188853e2bd2SBhanu Gollapudi hba->t2_hash_tbl_ptr = NULL;
2189853e2bd2SBhanu Gollapudi }
2190853e2bd2SBhanu Gollapudi
2191853e2bd2SBhanu Gollapudi if (hba->t2_hash_tbl) {
2192853e2bd2SBhanu Gollapudi mem_size = BNX2FC_NUM_MAX_SESS *
2193853e2bd2SBhanu Gollapudi sizeof(struct fcoe_t2_hash_table_entry);
2194853e2bd2SBhanu Gollapudi dma_free_coherent(&hba->pcidev->dev, mem_size,
2195853e2bd2SBhanu Gollapudi hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
2196853e2bd2SBhanu Gollapudi hba->t2_hash_tbl = NULL;
2197853e2bd2SBhanu Gollapudi }
2198853e2bd2SBhanu Gollapudi bnx2fc_free_hash_table(hba);
2199853e2bd2SBhanu Gollapudi }
2200