1 /* bnx2fc_hwi.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * This file contains the code that low level functions that interact
3 * with 57712 FCoE firmware.
5 * Copyright (c) 2008 - 2010 Broadcom Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
11 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
16 DECLARE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
18 static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
19 struct fcoe_kcqe *new_cqe_kcqe);
20 static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
21 struct fcoe_kcqe *ofld_kcqe);
22 static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
23 struct fcoe_kcqe *ofld_kcqe);
24 static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code);
25 static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
26 struct fcoe_kcqe *conn_destroy);
28 int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
30 struct fcoe_kwqe_stat stat_req;
31 struct kwqe *kwqe_arr[2];
35 memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat));
36 stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT;
38 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
40 stat_req.stat_params_addr_lo = (u32) hba->stats_buf_dma;
41 stat_req.stat_params_addr_hi = (u32) ((u64)hba->stats_buf_dma >> 32);
43 kwqe_arr[0] = (struct kwqe *) &stat_req;
45 if (hba->cnic && hba->cnic->submit_kwqes)
46 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
52 * bnx2fc_send_fw_fcoe_init_msg - initiates initial handshake with FCoE f/w
54 * @hba: adapter structure pointer
56 * Send down FCoE firmware init KWQEs which initiates the initial handshake
60 int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
62 struct fcoe_kwqe_init1 fcoe_init1;
63 struct fcoe_kwqe_init2 fcoe_init2;
64 struct fcoe_kwqe_init3 fcoe_init3;
65 struct kwqe *kwqe_arr[3];
70 printk(KERN_ALERT PFX "hba->cnic NULL during fcoe fw init\n");
75 memset(&fcoe_init1, 0x00, sizeof(struct fcoe_kwqe_init1));
76 fcoe_init1.hdr.op_code = FCOE_KWQE_OPCODE_INIT1;
77 fcoe_init1.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
78 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
80 fcoe_init1.num_tasks = BNX2FC_MAX_TASKS;
81 fcoe_init1.sq_num_wqes = BNX2FC_SQ_WQES_MAX;
82 fcoe_init1.rq_num_wqes = BNX2FC_RQ_WQES_MAX;
83 fcoe_init1.rq_buffer_log_size = BNX2FC_RQ_BUF_LOG_SZ;
84 fcoe_init1.cq_num_wqes = BNX2FC_CQ_WQES_MAX;
85 fcoe_init1.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
86 fcoe_init1.dummy_buffer_addr_hi = (u32) ((u64)hba->dummy_buf_dma >> 32);
87 fcoe_init1.task_list_pbl_addr_lo = (u32) hba->task_ctx_bd_dma;
88 fcoe_init1.task_list_pbl_addr_hi =
89 (u32) ((u64) hba->task_ctx_bd_dma >> 32);
90 fcoe_init1.mtu = hba->netdev->mtu;
92 fcoe_init1.flags = (PAGE_SHIFT <<
93 FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT);
95 fcoe_init1.num_sessions_log = BNX2FC_NUM_MAX_SESS_LOG;
98 memset(&fcoe_init2, 0x00, sizeof(struct fcoe_kwqe_init2));
99 fcoe_init2.hdr.op_code = FCOE_KWQE_OPCODE_INIT2;
100 fcoe_init2.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
101 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
103 fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
104 fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
105 ((u64) hba->hash_tbl_pbl_dma >> 32);
107 fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma;
108 fcoe_init2.t2_hash_tbl_addr_hi = (u32)
109 ((u64) hba->t2_hash_tbl_dma >> 32);
111 fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma;
112 fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32)
113 ((u64) hba->t2_hash_tbl_ptr_dma >> 32);
115 fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS;
117 /* fill init3 KWQE */
118 memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3));
119 fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3;
120 fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
121 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
122 fcoe_init3.error_bit_map_lo = 0xffffffff;
123 fcoe_init3.error_bit_map_hi = 0xffffffff;
126 kwqe_arr[0] = (struct kwqe *) &fcoe_init1;
127 kwqe_arr[1] = (struct kwqe *) &fcoe_init2;
128 kwqe_arr[2] = (struct kwqe *) &fcoe_init3;
130 if (hba->cnic && hba->cnic->submit_kwqes)
131 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
135 int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba)
137 struct fcoe_kwqe_destroy fcoe_destroy;
138 struct kwqe *kwqe_arr[2];
142 /* fill destroy KWQE */
143 memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy));
144 fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY;
145 fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
146 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
147 kwqe_arr[0] = (struct kwqe *) &fcoe_destroy;
149 if (hba->cnic && hba->cnic->submit_kwqes)
150 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
155 * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process
157 * @port: port structure pointer
158 * @tgt: bnx2fc_rport structure pointer
160 int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
161 struct bnx2fc_rport *tgt)
163 struct fc_lport *lport = port->lport;
164 struct bnx2fc_hba *hba = port->priv;
165 struct kwqe *kwqe_arr[4];
166 struct fcoe_kwqe_conn_offload1 ofld_req1;
167 struct fcoe_kwqe_conn_offload2 ofld_req2;
168 struct fcoe_kwqe_conn_offload3 ofld_req3;
169 struct fcoe_kwqe_conn_offload4 ofld_req4;
170 struct fc_rport_priv *rdata = tgt->rdata;
171 struct fc_rport *rport = tgt->rport;
177 /* Initialize offload request 1 structure */
178 memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
180 ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
181 ofld_req1.hdr.flags =
182 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
185 conn_id = (u16)tgt->fcoe_conn_id;
186 ofld_req1.fcoe_conn_id = conn_id;
189 ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
190 ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
192 ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
193 ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
195 ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
196 ofld_req1.rq_first_pbe_addr_hi =
197 (u32)((u64) tgt->rq_dma >> 32);
199 ofld_req1.rq_prod = 0x8000;
201 /* Initialize offload request 2 structure */
202 memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
204 ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
205 ofld_req2.hdr.flags =
206 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
208 ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
210 ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
211 ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
213 ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
214 ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
216 ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
217 ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
219 /* Initialize offload request 3 structure */
220 memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
222 ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
223 ofld_req3.hdr.flags =
224 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
226 ofld_req3.vlan_tag = hba->vlan_id <<
227 FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
228 ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
230 port_id = fc_host_port_id(lport->host);
232 BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
237 * Store s_id of the initiator for further reference. This will
238 * be used during disable/destroy during linkdown processing as
239 * when the lport is reset, the port_id also is reset to 0
242 ofld_req3.s_id[0] = (port_id & 0x000000FF);
243 ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
244 ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
246 port_id = rport->port_id;
247 ofld_req3.d_id[0] = (port_id & 0x000000FF);
248 ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
249 ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
251 ofld_req3.tx_total_conc_seqs = rdata->max_seq;
253 ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
254 ofld_req3.rx_max_fc_pay_len = lport->mfs;
256 ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
257 ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
258 ofld_req3.rx_open_seqs_exch_c3 = 1;
260 ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
261 ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
263 /* set mul_n_port_ids supported flag to 0, until it is supported */
266 ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
267 FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
269 /* Info from PLOGI response */
270 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
271 FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
273 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
274 FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
277 ofld_req3.flags |= (hba->vlan_enabled <<
278 FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
280 /* C2_VALID and ACK flags are not set as they are not suppported */
283 /* Initialize offload request 4 structure */
284 memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
285 ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
286 ofld_req4.hdr.flags =
287 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
289 ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
292 ofld_req4.src_mac_addr_lo32[0] = port->data_src_addr[5];
294 ofld_req4.src_mac_addr_lo32[1] = port->data_src_addr[4];
295 ofld_req4.src_mac_addr_lo32[2] = port->data_src_addr[3];
296 ofld_req4.src_mac_addr_lo32[3] = port->data_src_addr[2];
297 ofld_req4.src_mac_addr_hi16[0] = port->data_src_addr[1];
298 ofld_req4.src_mac_addr_hi16[1] = port->data_src_addr[0];
299 ofld_req4.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */
300 ofld_req4.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4];
301 ofld_req4.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3];
302 ofld_req4.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2];
303 ofld_req4.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1];
304 ofld_req4.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0];
306 ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
307 ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
309 ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
310 ofld_req4.confq_pbl_base_addr_hi =
311 (u32)((u64) tgt->confq_pbl_dma >> 32);
313 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
314 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
315 kwqe_arr[2] = (struct kwqe *) &ofld_req3;
316 kwqe_arr[3] = (struct kwqe *) &ofld_req4;
318 if (hba->cnic && hba->cnic->submit_kwqes)
319 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
325 * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
327 * @port: port structure pointer
328 * @tgt: bnx2fc_rport structure pointer
330 static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
331 struct bnx2fc_rport *tgt)
333 struct kwqe *kwqe_arr[2];
334 struct bnx2fc_hba *hba = port->priv;
335 struct fcoe_kwqe_conn_enable_disable enbl_req;
336 struct fc_lport *lport = port->lport;
337 struct fc_rport *rport = tgt->rport;
342 memset(&enbl_req, 0x00,
343 sizeof(struct fcoe_kwqe_conn_enable_disable));
344 enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
346 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
348 enbl_req.src_mac_addr_lo32[0] = port->data_src_addr[5];
350 enbl_req.src_mac_addr_lo32[1] = port->data_src_addr[4];
351 enbl_req.src_mac_addr_lo32[2] = port->data_src_addr[3];
352 enbl_req.src_mac_addr_lo32[3] = port->data_src_addr[2];
353 enbl_req.src_mac_addr_hi16[0] = port->data_src_addr[1];
354 enbl_req.src_mac_addr_hi16[1] = port->data_src_addr[0];
356 enbl_req.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */
357 enbl_req.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4];
358 enbl_req.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3];
359 enbl_req.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2];
360 enbl_req.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1];
361 enbl_req.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0];
363 port_id = fc_host_port_id(lport->host);
364 if (port_id != tgt->sid) {
365 printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
366 "sid = 0x%x\n", port_id, tgt->sid);
369 enbl_req.s_id[0] = (port_id & 0x000000FF);
370 enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
371 enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
373 port_id = rport->port_id;
374 enbl_req.d_id[0] = (port_id & 0x000000FF);
375 enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
376 enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
377 enbl_req.vlan_tag = hba->vlan_id <<
378 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
379 enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
380 enbl_req.vlan_flag = hba->vlan_enabled;
381 enbl_req.context_id = tgt->context_id;
382 enbl_req.conn_id = tgt->fcoe_conn_id;
384 kwqe_arr[0] = (struct kwqe *) &enbl_req;
386 if (hba->cnic && hba->cnic->submit_kwqes)
387 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
392 * bnx2fc_send_session_disable_req - initiates FCoE Session disable
394 * @port: port structure pointer
395 * @tgt: bnx2fc_rport structure pointer
397 int bnx2fc_send_session_disable_req(struct fcoe_port *port,
398 struct bnx2fc_rport *tgt)
400 struct bnx2fc_hba *hba = port->priv;
401 struct fcoe_kwqe_conn_enable_disable disable_req;
402 struct kwqe *kwqe_arr[2];
403 struct fc_rport *rport = tgt->rport;
408 memset(&disable_req, 0x00,
409 sizeof(struct fcoe_kwqe_conn_enable_disable));
410 disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
411 disable_req.hdr.flags =
412 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
414 disable_req.src_mac_addr_lo32[0] = port->data_src_addr[5];
415 disable_req.src_mac_addr_lo32[2] = port->data_src_addr[3];
416 disable_req.src_mac_addr_lo32[3] = port->data_src_addr[2];
417 disable_req.src_mac_addr_hi16[0] = port->data_src_addr[1];
418 disable_req.src_mac_addr_hi16[1] = port->data_src_addr[0];
420 disable_req.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */
421 disable_req.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4];
422 disable_req.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3];
423 disable_req.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2];
424 disable_req.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1];
425 disable_req.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0];
428 disable_req.s_id[0] = (port_id & 0x000000FF);
429 disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
430 disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
433 port_id = rport->port_id;
434 disable_req.d_id[0] = (port_id & 0x000000FF);
435 disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
436 disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
437 disable_req.context_id = tgt->context_id;
438 disable_req.conn_id = tgt->fcoe_conn_id;
439 disable_req.vlan_tag = hba->vlan_id <<
440 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
441 disable_req.vlan_tag |=
442 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
443 disable_req.vlan_flag = hba->vlan_enabled;
445 kwqe_arr[0] = (struct kwqe *) &disable_req;
447 if (hba->cnic && hba->cnic->submit_kwqes)
448 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
454 * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
456 * @port: port structure pointer
457 * @tgt: bnx2fc_rport structure pointer
459 int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
460 struct bnx2fc_rport *tgt)
462 struct fcoe_kwqe_conn_destroy destroy_req;
463 struct kwqe *kwqe_arr[2];
467 memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
468 destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
469 destroy_req.hdr.flags =
470 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
472 destroy_req.context_id = tgt->context_id;
473 destroy_req.conn_id = tgt->fcoe_conn_id;
475 kwqe_arr[0] = (struct kwqe *) &destroy_req;
477 if (hba->cnic && hba->cnic->submit_kwqes)
478 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
483 static void bnx2fc_unsol_els_work(struct work_struct *work)
485 struct bnx2fc_unsol_els *unsol_els;
486 struct fc_lport *lport;
489 unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
490 lport = unsol_els->lport;
492 fc_exch_recv(lport, fp);
496 void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
498 u32 frame_len, u16 l2_oxid)
500 struct fcoe_port *port = tgt->port;
501 struct fc_lport *lport = port->lport;
502 struct bnx2fc_unsol_els *unsol_els;
503 struct fc_frame_header *fh;
511 unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
513 BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
517 BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
520 payload_len = frame_len - sizeof(struct fc_frame_header);
522 fp = fc_frame_alloc(lport, payload_len);
524 printk(KERN_ERR PFX "fc_frame_alloc failure\n");
528 fh = (struct fc_frame_header *) fc_frame_header_get(fp);
529 /* Copy FC Frame header and payload into the frame */
530 memcpy(fh, buf, frame_len);
532 if (l2_oxid != FC_XID_UNKNOWN)
533 fh->fh_ox_id = htons(l2_oxid);
537 if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
538 (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
540 if (fh->fh_type == FC_TYPE_ELS) {
541 op = fc_frame_payload_op(fp);
542 if ((op == ELS_TEST) || (op == ELS_ESTC) ||
543 (op == ELS_FAN) || (op == ELS_CSU)) {
545 * No need to reply for these
548 printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
553 crc = fcoe_fc_crc(fp);
556 fr_sof(fp) = FC_SOF_I3;
557 fr_eof(fp) = FC_EOF_T;
558 fr_crc(fp) = cpu_to_le32(~crc);
559 unsol_els->lport = lport;
561 INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
562 queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
564 BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
569 static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
572 struct fcoe_err_report_entry *err_entry;
573 unsigned char *rq_data;
574 unsigned char *buf = NULL, *buf1;
578 struct bnx2fc_cmd *io_req = NULL;
579 struct fcoe_task_ctx_entry *task, *task_page;
580 struct bnx2fc_hba *hba = tgt->port->priv;
585 BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe);
586 switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) {
587 case FCOE_UNSOLICITED_FRAME_CQE_TYPE:
588 frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >>
589 FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT;
591 num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ;
593 rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq);
597 buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
601 BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
605 for (i = 0; i < num_rq; i++) {
606 rq_data = (unsigned char *)
607 bnx2fc_get_next_rqe(tgt, 1);
608 len = BNX2FC_RQ_BUF_SZ;
609 memcpy(buf1, rq_data, len);
613 bnx2fc_process_l2_frame_compl(tgt, buf, frame_len,
618 bnx2fc_return_rqe(tgt, num_rq);
621 case FCOE_ERROR_DETECTION_CQE_TYPE:
623 *In case of error reporting CQE a single RQ entry
626 spin_lock_bh(&tgt->tgt_lock);
628 err_entry = (struct fcoe_err_report_entry *)
629 bnx2fc_get_next_rqe(tgt, 1);
630 xid = err_entry->fc_hdr.ox_id;
631 BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid);
632 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n",
633 err_entry->err_warn_bitmap_hi,
634 err_entry->err_warn_bitmap_lo);
635 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n",
636 err_entry->tx_buf_off, err_entry->rx_buf_off);
638 bnx2fc_return_rqe(tgt, 1);
640 if (xid > BNX2FC_MAX_XID) {
641 BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
643 spin_unlock_bh(&tgt->tgt_lock);
647 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
648 index = xid % BNX2FC_TASKS_PER_PAGE;
649 task_page = (struct fcoe_task_ctx_entry *)
650 hba->task_ctx[task_idx];
651 task = &(task_page[index]);
653 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
655 spin_unlock_bh(&tgt->tgt_lock);
659 if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
660 printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
661 spin_unlock_bh(&tgt->tgt_lock);
665 if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
666 &io_req->req_flags)) {
667 BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
668 "progress.. ignore unsol err\n");
669 spin_unlock_bh(&tgt->tgt_lock);
674 * If ABTS is already in progress, and FW error is
675 * received after that, do not cancel the timeout_work
676 * and let the error recovery continue by explicitly
677 * logging out the target, when the ABTS eventually
680 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
681 &io_req->req_flags)) {
683 * Cancel the timeout_work, as we received IO
684 * completion with FW error.
686 if (cancel_delayed_work(&io_req->timeout_work))
687 kref_put(&io_req->refcount,
688 bnx2fc_cmd_release); /* timer hold */
690 rc = bnx2fc_initiate_abts(io_req);
692 BNX2FC_IO_DBG(io_req, "err_warn: initiate_abts "
693 "failed. issue cleanup\n");
694 rc = bnx2fc_initiate_cleanup(io_req);
698 printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
699 "in ABTS processing\n", xid);
700 spin_unlock_bh(&tgt->tgt_lock);
703 case FCOE_WARNING_DETECTION_CQE_TYPE:
705 *In case of warning reporting CQE a single RQ entry
709 err_entry = (struct fcoe_err_report_entry *)
710 bnx2fc_get_next_rqe(tgt, 1);
711 xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
712 BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
713 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
714 err_entry->err_warn_bitmap_hi,
715 err_entry->err_warn_bitmap_lo);
716 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
717 err_entry->tx_buf_off, err_entry->rx_buf_off);
719 bnx2fc_return_rqe(tgt, 1);
723 printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
728 void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
730 struct fcoe_task_ctx_entry *task;
731 struct fcoe_task_ctx_entry *task_page;
732 struct fcoe_port *port = tgt->port;
733 struct bnx2fc_hba *hba = port->priv;
734 struct bnx2fc_cmd *io_req;
741 spin_lock_bh(&tgt->tgt_lock);
742 xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
743 if (xid >= BNX2FC_MAX_TASKS) {
744 printk(KERN_ALERT PFX "ERROR:xid out of range\n");
745 spin_unlock_bh(&tgt->tgt_lock);
748 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
749 index = xid % BNX2FC_TASKS_PER_PAGE;
750 task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
751 task = &(task_page[index]);
753 num_rq = ((task->rx_wr_tx_rd.rx_flags &
754 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE) >>
755 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE_SHIFT);
757 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
759 if (io_req == NULL) {
760 printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
761 spin_unlock_bh(&tgt->tgt_lock);
765 /* Timestamp IO completion time */
766 cmd_type = io_req->cmd_type;
768 /* optimized completion path */
769 if (cmd_type == BNX2FC_SCSI_CMD) {
770 rx_state = ((task->rx_wr_tx_rd.rx_flags &
771 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE) >>
772 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE_SHIFT);
774 if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
775 bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq);
776 spin_unlock_bh(&tgt->tgt_lock);
781 /* Process other IO completion types */
783 case BNX2FC_SCSI_CMD:
784 if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
785 bnx2fc_process_abts_compl(io_req, task, num_rq);
787 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
788 bnx2fc_process_cleanup_compl(io_req, task, num_rq);
790 printk(KERN_ERR PFX "Invalid rx state - %d\n",
794 case BNX2FC_TASK_MGMT_CMD:
795 BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
796 bnx2fc_process_tm_compl(io_req, task, num_rq);
801 * ABTS request received by firmware. ABTS response
802 * will be delivered to the task belonging to the IO
805 BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
806 kref_put(&io_req->refcount, bnx2fc_cmd_release);
810 BNX2FC_IO_DBG(io_req, "cq_compl - call process_els_compl\n");
811 bnx2fc_process_els_compl(io_req, task, num_rq);
815 BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
816 kref_put(&io_req->refcount, bnx2fc_cmd_release);
820 printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
823 spin_unlock_bh(&tgt->tgt_lock);
826 struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe)
828 struct bnx2fc_work *work;
829 work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
833 INIT_LIST_HEAD(&work->list);
839 int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
843 struct fcoe_cqe *cqe;
845 bool more_cqes_found = false;
848 * cq_lock is a low contention lock used to protect
849 * the CQ data structure from being freed up during
850 * the upload operation
852 spin_lock_bh(&tgt->cq_lock);
855 printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
856 spin_unlock_bh(&tgt->cq_lock);
860 cq_cons = tgt->cq_cons_idx;
864 more_cqes_found ^= true;
866 while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
867 (tgt->cq_curr_toggle_bit <<
868 FCOE_CQE_TOGGLE_BIT_SHIFT)) {
870 /* new entry on the cq */
871 if (wqe & FCOE_CQE_CQE_TYPE) {
872 /* Unsolicited event notification */
873 bnx2fc_process_unsol_compl(tgt, wqe);
875 struct bnx2fc_work *work = NULL;
876 struct bnx2fc_percpu_s *fps = NULL;
877 unsigned int cpu = wqe % num_possible_cpus();
879 fps = &per_cpu(bnx2fc_percpu, cpu);
880 spin_lock_bh(&fps->fp_work_lock);
881 if (unlikely(!fps->iothread))
884 work = bnx2fc_alloc_work(tgt, wqe);
886 list_add_tail(&work->list,
889 spin_unlock_bh(&fps->fp_work_lock);
891 /* Pending work request completion */
892 if (fps->iothread && work)
893 wake_up_process(fps->iothread);
895 bnx2fc_process_cq_compl(tgt, wqe);
900 if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
901 tgt->cq_cons_idx = 0;
903 tgt->cq_curr_toggle_bit =
904 1 - tgt->cq_curr_toggle_bit;
908 if (more_cqes_found) {
909 tgt->conn_db->cq_arm.lo = -1;
912 } while (more_cqes_found);
915 * Commit tgt->cq_cons_idx change to the memory
916 * spin_lock implies full memory barrier, no need to smp_wmb
919 spin_unlock_bh(&tgt->cq_lock);
924 * bnx2fc_fastpath_notification - process global event queue (KCQ)
926 * @hba: adapter structure pointer
927 * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry
929 * Fast path event notification handler
931 static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
932 struct fcoe_kcqe *new_cqe_kcqe)
934 u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
935 struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
938 printk(KERN_ALERT PFX "conn_id 0x%x not valid\n", conn_id);
942 bnx2fc_process_new_cqes(tgt);
946 * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
948 * @hba: adapter structure pointer
949 * @ofld_kcqe: connection offload kcqe pointer
951 * handle session offload completion, enable the session if offload is
954 static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
955 struct fcoe_kcqe *ofld_kcqe)
957 struct bnx2fc_rport *tgt;
958 struct fcoe_port *port;
963 conn_id = ofld_kcqe->fcoe_conn_id;
964 context_id = ofld_kcqe->fcoe_conn_context_id;
965 tgt = hba->tgt_ofld_list[conn_id];
967 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
970 BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
971 ofld_kcqe->fcoe_conn_context_id);
973 if (hba != tgt->port->priv) {
974 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: HBA mis-match\n");
978 * cnic has allocated a context_id for this session; use this
979 * while enabling the session.
981 tgt->context_id = context_id;
982 if (ofld_kcqe->completion_status) {
983 if (ofld_kcqe->completion_status ==
984 FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
985 printk(KERN_ERR PFX "unable to allocate FCoE context "
987 set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
992 /* now enable the session */
993 rc = bnx2fc_send_session_enable_req(port, tgt);
995 printk(KERN_ALERT PFX "enable session failed\n");
1001 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1002 wake_up_interruptible(&tgt->ofld_wait);
1006 * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
1008 * @hba: adapter structure pointer
1009 * @ofld_kcqe: connection offload kcqe pointer
1011 * handle session enable completion, mark the rport as ready
1014 static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1015 struct fcoe_kcqe *ofld_kcqe)
1017 struct bnx2fc_rport *tgt;
1021 context_id = ofld_kcqe->fcoe_conn_context_id;
1022 conn_id = ofld_kcqe->fcoe_conn_id;
1023 tgt = hba->tgt_ofld_list[conn_id];
1025 printk(KERN_ALERT PFX "ERROR:enbl_cmpl: No pending ofld req\n");
1029 BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
1030 ofld_kcqe->fcoe_conn_context_id);
1033 * context_id should be the same for this target during offload
1036 if (tgt->context_id != context_id) {
1037 printk(KERN_ALERT PFX "context id mis-match\n");
1040 if (hba != tgt->port->priv) {
1041 printk(KERN_ALERT PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
1044 if (ofld_kcqe->completion_status) {
1047 /* enable successful - rport ready for issuing IOs */
1048 set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1049 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1050 wake_up_interruptible(&tgt->ofld_wait);
1055 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1056 wake_up_interruptible(&tgt->ofld_wait);
1059 static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
1060 struct fcoe_kcqe *disable_kcqe)
1063 struct bnx2fc_rport *tgt;
1066 conn_id = disable_kcqe->fcoe_conn_id;
1067 tgt = hba->tgt_ofld_list[conn_id];
1069 printk(KERN_ALERT PFX "ERROR: disable_cmpl: No disable req\n");
1073 BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
1075 if (disable_kcqe->completion_status) {
1076 printk(KERN_ALERT PFX "ERROR: Disable failed with cmpl status %d\n",
1077 disable_kcqe->completion_status);
1080 /* disable successful */
1081 BNX2FC_TGT_DBG(tgt, "disable successful\n");
1082 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1083 set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1084 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1085 wake_up_interruptible(&tgt->upld_wait);
1089 static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
1090 struct fcoe_kcqe *destroy_kcqe)
1092 struct bnx2fc_rport *tgt;
1095 conn_id = destroy_kcqe->fcoe_conn_id;
1096 tgt = hba->tgt_ofld_list[conn_id];
1098 printk(KERN_ALERT PFX "destroy_cmpl: No destroy req\n");
1102 BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
1104 if (destroy_kcqe->completion_status) {
1105 printk(KERN_ALERT PFX "Destroy conn failed, cmpl status %d\n",
1106 destroy_kcqe->completion_status);
1109 /* destroy successful */
1110 BNX2FC_TGT_DBG(tgt, "upload successful\n");
1111 clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1112 set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
1113 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1114 wake_up_interruptible(&tgt->upld_wait);
1118 static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
1121 case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
1122 printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
1125 case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
1126 printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
1129 case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
1130 printk(KERN_ERR PFX "init_failure due to NIC error\n");
1134 printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
1139 * bnx2fc_indicae_kcqe - process KCQE
1141 * @hba: adapter structure pointer
1142 * @kcqe: kcqe pointer
1143 * @num_cqe: Number of completion queue elements
1145 * Generic KCQ event handler
1147 void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
1150 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
1152 struct fcoe_kcqe *kcqe = NULL;
1154 while (i < num_cqe) {
1155 kcqe = (struct fcoe_kcqe *) kcq[i++];
1157 switch (kcqe->op_code) {
1158 case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
1159 bnx2fc_fastpath_notification(hba, kcqe);
1162 case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
1163 bnx2fc_process_ofld_cmpl(hba, kcqe);
1166 case FCOE_KCQE_OPCODE_ENABLE_CONN:
1167 bnx2fc_process_enable_conn_cmpl(hba, kcqe);
1170 case FCOE_KCQE_OPCODE_INIT_FUNC:
1171 if (kcqe->completion_status !=
1172 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1173 bnx2fc_init_failure(hba,
1174 kcqe->completion_status);
1176 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1177 bnx2fc_get_link_state(hba);
1178 printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
1179 (u8)hba->pcidev->bus->number);
1183 case FCOE_KCQE_OPCODE_DESTROY_FUNC:
1184 if (kcqe->completion_status !=
1185 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1187 printk(KERN_ERR PFX "DESTROY failed\n");
1189 printk(KERN_ERR PFX "DESTROY success\n");
1191 hba->flags |= BNX2FC_FLAG_DESTROY_CMPL;
1192 wake_up_interruptible(&hba->destroy_wait);
1195 case FCOE_KCQE_OPCODE_DISABLE_CONN:
1196 bnx2fc_process_conn_disable_cmpl(hba, kcqe);
1199 case FCOE_KCQE_OPCODE_DESTROY_CONN:
1200 bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
1203 case FCOE_KCQE_OPCODE_STAT_FUNC:
1204 if (kcqe->completion_status !=
1205 FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
1206 printk(KERN_ERR PFX "STAT failed\n");
1207 complete(&hba->stat_req_done);
1210 case FCOE_KCQE_OPCODE_FCOE_ERROR:
1213 printk(KERN_ALERT PFX "unknown opcode 0x%x\n",
1219 void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
1221 struct fcoe_sqe *sqe;
1223 sqe = &tgt->sq[tgt->sq_prod_idx];
1226 sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
1227 sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
1229 /* Advance SQ Prod Idx */
1230 if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
1231 tgt->sq_prod_idx = 0;
1232 tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
1236 void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
1238 struct b577xx_doorbell_set_prod ev_doorbell;
1243 memset(&ev_doorbell, 0, sizeof(struct b577xx_doorbell_set_prod));
1244 ev_doorbell.header.header = B577XX_DOORBELL_HDR_DB_TYPE;
1246 ev_doorbell.prod = tgt->sq_prod_idx |
1247 (tgt->sq_curr_toggle_bit << 15);
1248 ev_doorbell.header.header |= B577XX_FCOE_CONNECTION_TYPE <<
1249 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT;
1250 msg = *((u32 *)&ev_doorbell);
1251 writel(cpu_to_le32(msg), tgt->ctx_base);
1257 int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
1259 u32 context_id = tgt->context_id;
1260 struct fcoe_port *port = tgt->port;
1262 resource_size_t reg_base;
1263 struct bnx2fc_hba *hba = port->priv;
1265 reg_base = pci_resource_start(hba->pcidev,
1266 BNX2X_DOORBELL_PCI_BAR);
1267 reg_off = BNX2FC_5771X_DB_PAGE_SIZE *
1268 (context_id & 0x1FFFF) + DPM_TRIGER_TYPE;
1269 tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4);
1275 char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1277 char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
1279 if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
1282 tgt->rq_cons_idx += num_items;
1284 if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
1285 tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
1290 void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1292 /* return the rq buffer */
1293 u32 next_prod_idx = tgt->rq_prod_idx + num_items;
1294 if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
1295 /* Wrap around RQ */
1296 next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
1298 tgt->rq_prod_idx = next_prod_idx;
1299 tgt->conn_db->rq_prod = tgt->rq_prod_idx;
1302 void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
1303 struct fcoe_task_ctx_entry *task,
1306 u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
1307 struct bnx2fc_rport *tgt = io_req->tgt;
1308 u32 context_id = tgt->context_id;
1310 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1312 /* Tx Write Rx Read */
1313 task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
1314 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT;
1315 task->tx_wr_rx_rd.init_flags = task_type <<
1316 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT;
1317 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1318 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT;
1320 task->cmn.common_flags = context_id <<
1321 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT;
1322 task->cmn.general.cleanup_info.task_id = orig_xid;
1327 void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
1328 struct fcoe_task_ctx_entry *task)
1330 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
1331 struct bnx2fc_rport *tgt = io_req->tgt;
1332 struct fc_frame_header *fc_hdr;
1339 /* Obtain task_type */
1340 if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
1341 (io_req->cmd_type == BNX2FC_ELS)) {
1342 task_type = FCOE_TASK_TYPE_MIDPATH;
1343 } else if (io_req->cmd_type == BNX2FC_ABTS) {
1344 task_type = FCOE_TASK_TYPE_ABTS;
1347 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1349 /* Setup the task from io_req for easy reference */
1350 io_req->task = task;
1352 BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
1353 io_req->cmd_type, task_type);
1356 if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
1357 (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
1358 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1359 (u32)mp_req->mp_req_bd_dma;
1360 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1361 (u32)((u64)mp_req->mp_req_bd_dma >> 32);
1362 task->tx_wr_only.sgl_ctx.mul_sges.sgl_size = 1;
1363 BNX2FC_IO_DBG(io_req, "init_mp_task - bd_dma = 0x%llx\n",
1364 (unsigned long long)mp_req->mp_req_bd_dma);
1367 /* Tx Write Rx Read */
1368 task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_INIT <<
1369 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT;
1370 task->tx_wr_rx_rd.init_flags = task_type <<
1371 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT;
1372 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_DEV_TYPE_DISK <<
1373 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT;
1374 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1375 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT;
1378 task->cmn.data_2_trns = io_req->data_xfer_len;
1379 context_id = tgt->context_id;
1380 task->cmn.common_flags = context_id <<
1381 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT;
1382 task->cmn.common_flags |= 1 <<
1383 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID_SHIFT;
1384 task->cmn.common_flags |= 1 <<
1385 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME_SHIFT;
1387 /* Rx Write Tx Read */
1388 fc_hdr = &(mp_req->req_fc_hdr);
1389 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1390 fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
1391 fc_hdr->fh_rx_id = htons(0xffff);
1392 task->rx_wr_tx_rd.rx_id = 0xffff;
1393 } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
1394 fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
1397 /* Fill FC Header into middle path buffer */
1398 hdr = (u64 *) &task->cmn.general.cmd_info.mp_fc_frame.fc_hdr;
1399 memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
1400 hdr[0] = cpu_to_be64(temp_hdr[0]);
1401 hdr[1] = cpu_to_be64(temp_hdr[1]);
1402 hdr[2] = cpu_to_be64(temp_hdr[2]);
1405 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1407 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1408 (u32)mp_req->mp_resp_bd_dma;
1409 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1410 (u32)((u64)mp_req->mp_resp_bd_dma >> 32);
1411 task->rx_wr_only.sgl_ctx.mul_sges.sgl_size = 1;
1415 void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
1416 struct fcoe_task_ctx_entry *task)
1419 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1420 struct io_bdt *bd_tbl = io_req->bd_tbl;
1421 struct bnx2fc_rport *tgt = io_req->tgt;
1423 u64 tmp_fcp_cmnd[4];
1428 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1430 /* Setup the task from io_req for easy reference */
1431 io_req->task = task;
1433 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1434 task_type = FCOE_TASK_TYPE_WRITE;
1436 task_type = FCOE_TASK_TYPE_READ;
1439 if (task_type == FCOE_TASK_TYPE_WRITE) {
1440 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1441 (u32)bd_tbl->bd_tbl_dma;
1442 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1443 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1444 task->tx_wr_only.sgl_ctx.mul_sges.sgl_size =
1448 /*Tx Write Rx Read */
1449 /* Init state to NORMAL */
1450 task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
1451 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT;
1452 task->tx_wr_rx_rd.init_flags = task_type <<
1453 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT;
1454 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_DEV_TYPE_DISK <<
1455 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT;
1456 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1457 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT;
1460 task->cmn.data_2_trns = io_req->data_xfer_len;
1461 context_id = tgt->context_id;
1462 task->cmn.common_flags = context_id <<
1463 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT;
1464 task->cmn.common_flags |= 1 <<
1465 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID_SHIFT;
1466 task->cmn.common_flags |= 1 <<
1467 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME_SHIFT;
1469 /* Set initiative ownership */
1470 task->cmn.common_flags |= FCOE_TASK_CTX_ENTRY_TX_RX_CMN_SEQ_INIT;
1472 /* Set initial seq counter */
1473 task->cmn.tx_low_seq_cnt = 1;
1475 /* Set state to "waiting for the first packet" */
1476 task->cmn.common_flags |= FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME;
1478 /* Fill FCP_CMND IU */
1480 task->cmn.general.cmd_info.fcp_cmd_payload.opaque;
1481 bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
1484 cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
1486 for (i = 0; i < cnt; i++) {
1487 *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
1491 /* Rx Write Tx Read */
1492 task->rx_wr_tx_rd.rx_id = 0xffff;
1495 if (task_type == FCOE_TASK_TYPE_READ) {
1497 bd_count = bd_tbl->bd_valid;
1498 if (bd_count == 1) {
1500 struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1502 task->rx_wr_only.sgl_ctx.single_sge.cur_buf_addr.lo =
1503 fcoe_bd_tbl->buf_addr_lo;
1504 task->rx_wr_only.sgl_ctx.single_sge.cur_buf_addr.hi =
1505 fcoe_bd_tbl->buf_addr_hi;
1506 task->rx_wr_only.sgl_ctx.single_sge.cur_buf_rem =
1507 fcoe_bd_tbl->buf_len;
1508 task->tx_wr_rx_rd.init_flags |= 1 <<
1509 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_SINGLE_SGE_SHIFT;
1512 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1513 (u32)bd_tbl->bd_tbl_dma;
1514 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1515 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1516 task->rx_wr_only.sgl_ctx.mul_sges.sgl_size =
1523 * bnx2fc_setup_task_ctx - allocate and map task context
1525 * @hba: pointer to adapter structure
1527 * allocate memory for task context, and associated BD table to be used
1531 int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
1534 struct regpair *task_ctx_bdt;
1539 * Allocate task context bd table. A page size of bd table
1540 * can map 256 buffers. Each buffer contains 32 task context
1541 * entries. Hence the limit with one page is 8192 task context
1544 hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
1546 &hba->task_ctx_bd_dma,
1548 if (!hba->task_ctx_bd_tbl) {
1549 printk(KERN_ERR PFX "unable to allocate task context BDT\n");
1553 memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
1556 * Allocate task_ctx which is an array of pointers pointing to
1557 * a page containing 32 task contexts
1559 hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)),
1561 if (!hba->task_ctx) {
1562 printk(KERN_ERR PFX "unable to allocate task context array\n");
1568 * Allocate task_ctx_dma which is an array of dma addresses
1570 hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ *
1571 sizeof(dma_addr_t)), GFP_KERNEL);
1572 if (!hba->task_ctx_dma) {
1573 printk(KERN_ERR PFX "unable to alloc context mapping array\n");
1578 task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
1579 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1581 hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
1583 &hba->task_ctx_dma[i],
1585 if (!hba->task_ctx[i]) {
1586 printk(KERN_ERR PFX "unable to alloc task context\n");
1590 memset(hba->task_ctx[i], 0, PAGE_SIZE);
1591 addr = (u64)hba->task_ctx_dma[i];
1592 task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
1593 task_ctx_bdt->lo = cpu_to_le32((u32)addr);
1599 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1600 if (hba->task_ctx[i]) {
1602 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1603 hba->task_ctx[i], hba->task_ctx_dma[i]);
1604 hba->task_ctx[i] = NULL;
1608 kfree(hba->task_ctx_dma);
1609 hba->task_ctx_dma = NULL;
1611 kfree(hba->task_ctx);
1612 hba->task_ctx = NULL;
1614 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1615 hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
1616 hba->task_ctx_bd_tbl = NULL;
1621 void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
1625 if (hba->task_ctx_bd_tbl) {
1626 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1627 hba->task_ctx_bd_tbl,
1628 hba->task_ctx_bd_dma);
1629 hba->task_ctx_bd_tbl = NULL;
1632 if (hba->task_ctx) {
1633 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1634 if (hba->task_ctx[i]) {
1635 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1637 hba->task_ctx_dma[i]);
1638 hba->task_ctx[i] = NULL;
1641 kfree(hba->task_ctx);
1642 hba->task_ctx = NULL;
1645 kfree(hba->task_ctx_dma);
1646 hba->task_ctx_dma = NULL;
1649 static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
1653 int hash_table_size;
1656 segment_count = hba->hash_tbl_segment_count;
1657 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
1658 sizeof(struct fcoe_hash_table_entry);
1660 pbl = hba->hash_tbl_pbl;
1661 for (i = 0; i < segment_count; ++i) {
1662 dma_addr_t dma_address;
1664 dma_address = le32_to_cpu(*pbl);
1666 dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
1668 dma_free_coherent(&hba->pcidev->dev,
1669 BNX2FC_HASH_TBL_CHUNK_SIZE,
1670 hba->hash_tbl_segments[i],
1675 if (hba->hash_tbl_pbl) {
1676 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1678 hba->hash_tbl_pbl_dma);
1679 hba->hash_tbl_pbl = NULL;
1683 static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
1686 int hash_table_size;
1688 int segment_array_size;
1689 int dma_segment_array_size;
1690 dma_addr_t *dma_segment_array;
1693 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
1694 sizeof(struct fcoe_hash_table_entry);
1696 segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
1697 segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
1698 hba->hash_tbl_segment_count = segment_count;
1700 segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
1701 hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
1702 if (!hba->hash_tbl_segments) {
1703 printk(KERN_ERR PFX "hash table pointers alloc failed\n");
1706 dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
1707 dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
1708 if (!dma_segment_array) {
1709 printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
1713 for (i = 0; i < segment_count; ++i) {
1714 hba->hash_tbl_segments[i] =
1715 dma_alloc_coherent(&hba->pcidev->dev,
1716 BNX2FC_HASH_TBL_CHUNK_SIZE,
1717 &dma_segment_array[i],
1719 if (!hba->hash_tbl_segments[i]) {
1720 printk(KERN_ERR PFX "hash segment alloc failed\n");
1722 dma_free_coherent(&hba->pcidev->dev,
1723 BNX2FC_HASH_TBL_CHUNK_SIZE,
1724 hba->hash_tbl_segments[i],
1725 dma_segment_array[i]);
1726 hba->hash_tbl_segments[i] = NULL;
1728 kfree(dma_segment_array);
1731 memset(hba->hash_tbl_segments[i], 0,
1732 BNX2FC_HASH_TBL_CHUNK_SIZE);
1735 hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev,
1737 &hba->hash_tbl_pbl_dma,
1739 if (!hba->hash_tbl_pbl) {
1740 printk(KERN_ERR PFX "hash table pbl alloc failed\n");
1741 kfree(dma_segment_array);
1744 memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
1746 pbl = hba->hash_tbl_pbl;
1747 for (i = 0; i < segment_count; ++i) {
1748 u64 paddr = dma_segment_array[i];
1749 *pbl = cpu_to_le32((u32) paddr);
1751 *pbl = cpu_to_le32((u32) (paddr >> 32));
1754 pbl = hba->hash_tbl_pbl;
1756 while (*pbl && *(pbl + 1)) {
1765 kfree(dma_segment_array);
1770 * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
1772 * @hba: Pointer to adapter structure
1775 int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
1781 if (bnx2fc_allocate_hash_table(hba))
1784 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
1785 hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
1786 &hba->t2_hash_tbl_ptr_dma,
1788 if (!hba->t2_hash_tbl_ptr) {
1789 printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
1790 bnx2fc_free_fw_resc(hba);
1793 memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
1795 mem_size = BNX2FC_NUM_MAX_SESS *
1796 sizeof(struct fcoe_t2_hash_table_entry);
1797 hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
1798 &hba->t2_hash_tbl_dma,
1800 if (!hba->t2_hash_tbl) {
1801 printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
1802 bnx2fc_free_fw_resc(hba);
1805 memset(hba->t2_hash_tbl, 0x00, mem_size);
1806 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
1807 addr = (unsigned long) hba->t2_hash_tbl_dma +
1808 ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
1809 hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
1810 hba->t2_hash_tbl[i].next.hi = addr >> 32;
1813 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
1814 PAGE_SIZE, &hba->dummy_buf_dma,
1816 if (!hba->dummy_buffer) {
1817 printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
1818 bnx2fc_free_fw_resc(hba);
1822 hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
1824 &hba->stats_buf_dma,
1826 if (!hba->stats_buffer) {
1827 printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
1828 bnx2fc_free_fw_resc(hba);
1831 memset(hba->stats_buffer, 0x00, PAGE_SIZE);
1836 void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
1840 if (hba->stats_buffer) {
1841 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1842 hba->stats_buffer, hba->stats_buf_dma);
1843 hba->stats_buffer = NULL;
1846 if (hba->dummy_buffer) {
1847 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1848 hba->dummy_buffer, hba->dummy_buf_dma);
1849 hba->dummy_buffer = NULL;
1852 if (hba->t2_hash_tbl_ptr) {
1853 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
1854 dma_free_coherent(&hba->pcidev->dev, mem_size,
1855 hba->t2_hash_tbl_ptr,
1856 hba->t2_hash_tbl_ptr_dma);
1857 hba->t2_hash_tbl_ptr = NULL;
1860 if (hba->t2_hash_tbl) {
1861 mem_size = BNX2FC_NUM_MAX_SESS *
1862 sizeof(struct fcoe_t2_hash_table_entry);
1863 dma_free_coherent(&hba->pcidev->dev, mem_size,
1864 hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
1865 hba->t2_hash_tbl = NULL;
1867 bnx2fc_free_hash_table(hba);