ieee802154: verify packet size before trying to allocate it
[linux/fpc-iii.git] / drivers / scsi / bnx2fc / bnx2fc_hwi.c
blob2ca6bfe4ce5e38fe3a7be6b75cd39191c4a6ca2d
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 - 2011 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)
14 #include "bnx2fc.h"
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 *destroy_kcqe);
28 int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
30 struct fcoe_kwqe_stat stat_req;
31 struct kwqe *kwqe_arr[2];
32 int num_kwqes = 1;
33 int rc = 0;
35 memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat));
36 stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT;
37 stat_req.hdr.flags =
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);
48 return rc;
51 /**
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
57 * with the f/w.
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];
66 int num_kwqes = 3;
67 int rc = 0;
69 if (!hba->cnic) {
70 printk(KERN_ERR PFX "hba->cnic NULL during fcoe fw init\n");
71 return -ENODEV;
74 /* fill init1 KWQE */
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 = BNX2FC_MINI_JUMBO_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;
97 /* fill init2 KWQE */
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.hsi_major_version = FCOE_HSI_MAJOR_VERSION;
104 fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION;
107 fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
108 fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
109 ((u64) hba->hash_tbl_pbl_dma >> 32);
111 fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma;
112 fcoe_init2.t2_hash_tbl_addr_hi = (u32)
113 ((u64) hba->t2_hash_tbl_dma >> 32);
115 fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma;
116 fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32)
117 ((u64) hba->t2_hash_tbl_ptr_dma >> 32);
119 fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS;
121 /* fill init3 KWQE */
122 memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3));
123 fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3;
124 fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
125 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
126 fcoe_init3.error_bit_map_lo = 0xffffffff;
127 fcoe_init3.error_bit_map_hi = 0xffffffff;
129 fcoe_init3.perf_config = 1;
131 kwqe_arr[0] = (struct kwqe *) &fcoe_init1;
132 kwqe_arr[1] = (struct kwqe *) &fcoe_init2;
133 kwqe_arr[2] = (struct kwqe *) &fcoe_init3;
135 if (hba->cnic && hba->cnic->submit_kwqes)
136 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
138 return rc;
140 int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba)
142 struct fcoe_kwqe_destroy fcoe_destroy;
143 struct kwqe *kwqe_arr[2];
144 int num_kwqes = 1;
145 int rc = -1;
147 /* fill destroy KWQE */
148 memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy));
149 fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY;
150 fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
151 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
152 kwqe_arr[0] = (struct kwqe *) &fcoe_destroy;
154 if (hba->cnic && hba->cnic->submit_kwqes)
155 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
156 return rc;
160 * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process
162 * @port: port structure pointer
163 * @tgt: bnx2fc_rport structure pointer
165 int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
166 struct bnx2fc_rport *tgt)
168 struct fc_lport *lport = port->lport;
169 struct bnx2fc_interface *interface = port->priv;
170 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
171 struct bnx2fc_hba *hba = interface->hba;
172 struct kwqe *kwqe_arr[4];
173 struct fcoe_kwqe_conn_offload1 ofld_req1;
174 struct fcoe_kwqe_conn_offload2 ofld_req2;
175 struct fcoe_kwqe_conn_offload3 ofld_req3;
176 struct fcoe_kwqe_conn_offload4 ofld_req4;
177 struct fc_rport_priv *rdata = tgt->rdata;
178 struct fc_rport *rport = tgt->rport;
179 int num_kwqes = 4;
180 u32 port_id;
181 int rc = 0;
182 u16 conn_id;
184 /* Initialize offload request 1 structure */
185 memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
187 ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
188 ofld_req1.hdr.flags =
189 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
192 conn_id = (u16)tgt->fcoe_conn_id;
193 ofld_req1.fcoe_conn_id = conn_id;
196 ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
197 ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
199 ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
200 ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
202 ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
203 ofld_req1.rq_first_pbe_addr_hi =
204 (u32)((u64) tgt->rq_dma >> 32);
206 ofld_req1.rq_prod = 0x8000;
208 /* Initialize offload request 2 structure */
209 memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
211 ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
212 ofld_req2.hdr.flags =
213 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
215 ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
217 ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
218 ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
220 ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
221 ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
223 ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
224 ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
226 /* Initialize offload request 3 structure */
227 memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
229 ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
230 ofld_req3.hdr.flags =
231 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
233 ofld_req3.vlan_tag = interface->vlan_id <<
234 FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
235 ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
237 port_id = fc_host_port_id(lport->host);
238 if (port_id == 0) {
239 BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
240 return -EINVAL;
244 * Store s_id of the initiator for further reference. This will
245 * be used during disable/destroy during linkdown processing as
246 * when the lport is reset, the port_id also is reset to 0
248 tgt->sid = port_id;
249 ofld_req3.s_id[0] = (port_id & 0x000000FF);
250 ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
251 ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
253 port_id = rport->port_id;
254 ofld_req3.d_id[0] = (port_id & 0x000000FF);
255 ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
256 ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
258 ofld_req3.tx_total_conc_seqs = rdata->max_seq;
260 ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
261 ofld_req3.rx_max_fc_pay_len = lport->mfs;
263 ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
264 ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
265 ofld_req3.rx_open_seqs_exch_c3 = 1;
267 ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
268 ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
270 /* set mul_n_port_ids supported flag to 0, until it is supported */
271 ofld_req3.flags = 0;
273 ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
274 FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
276 /* Info from PLOGI response */
277 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
278 FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
280 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
281 FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
284 * Info from PRLI response, this info is used for sequence level error
285 * recovery support
287 if (tgt->dev_type == TYPE_TAPE) {
288 ofld_req3.flags |= 1 <<
289 FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT;
290 ofld_req3.flags |= (((rdata->flags & FC_RP_FLAGS_REC_SUPPORTED)
291 ? 1 : 0) <<
292 FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT);
295 /* vlan flag */
296 ofld_req3.flags |= (interface->vlan_enabled <<
297 FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
299 /* C2_VALID and ACK flags are not set as they are not suppported */
302 /* Initialize offload request 4 structure */
303 memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
304 ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
305 ofld_req4.hdr.flags =
306 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
308 ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
311 ofld_req4.src_mac_addr_lo[0] = port->data_src_addr[5];
312 /* local mac */
313 ofld_req4.src_mac_addr_lo[1] = port->data_src_addr[4];
314 ofld_req4.src_mac_addr_mid[0] = port->data_src_addr[3];
315 ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2];
316 ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1];
317 ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0];
318 ofld_req4.dst_mac_addr_lo[0] = ctlr->dest_addr[5];
319 /* fcf mac */
320 ofld_req4.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
321 ofld_req4.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
322 ofld_req4.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
323 ofld_req4.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
324 ofld_req4.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
326 ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
327 ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
329 ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
330 ofld_req4.confq_pbl_base_addr_hi =
331 (u32)((u64) tgt->confq_pbl_dma >> 32);
333 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
334 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
335 kwqe_arr[2] = (struct kwqe *) &ofld_req3;
336 kwqe_arr[3] = (struct kwqe *) &ofld_req4;
338 if (hba->cnic && hba->cnic->submit_kwqes)
339 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
341 return rc;
345 * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
347 * @port: port structure pointer
348 * @tgt: bnx2fc_rport structure pointer
350 static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
351 struct bnx2fc_rport *tgt)
353 struct kwqe *kwqe_arr[2];
354 struct bnx2fc_interface *interface = port->priv;
355 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
356 struct bnx2fc_hba *hba = interface->hba;
357 struct fcoe_kwqe_conn_enable_disable enbl_req;
358 struct fc_lport *lport = port->lport;
359 struct fc_rport *rport = tgt->rport;
360 int num_kwqes = 1;
361 int rc = 0;
362 u32 port_id;
364 memset(&enbl_req, 0x00,
365 sizeof(struct fcoe_kwqe_conn_enable_disable));
366 enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
367 enbl_req.hdr.flags =
368 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
370 enbl_req.src_mac_addr_lo[0] = port->data_src_addr[5];
371 /* local mac */
372 enbl_req.src_mac_addr_lo[1] = port->data_src_addr[4];
373 enbl_req.src_mac_addr_mid[0] = port->data_src_addr[3];
374 enbl_req.src_mac_addr_mid[1] = port->data_src_addr[2];
375 enbl_req.src_mac_addr_hi[0] = port->data_src_addr[1];
376 enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0];
377 memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
379 enbl_req.dst_mac_addr_lo[0] = ctlr->dest_addr[5];
380 enbl_req.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
381 enbl_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
382 enbl_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
383 enbl_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
384 enbl_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
386 port_id = fc_host_port_id(lport->host);
387 if (port_id != tgt->sid) {
388 printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
389 "sid = 0x%x\n", port_id, tgt->sid);
390 port_id = tgt->sid;
392 enbl_req.s_id[0] = (port_id & 0x000000FF);
393 enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
394 enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
396 port_id = rport->port_id;
397 enbl_req.d_id[0] = (port_id & 0x000000FF);
398 enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
399 enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
400 enbl_req.vlan_tag = interface->vlan_id <<
401 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
402 enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
403 enbl_req.vlan_flag = interface->vlan_enabled;
404 enbl_req.context_id = tgt->context_id;
405 enbl_req.conn_id = tgt->fcoe_conn_id;
407 kwqe_arr[0] = (struct kwqe *) &enbl_req;
409 if (hba->cnic && hba->cnic->submit_kwqes)
410 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
411 return rc;
415 * bnx2fc_send_session_disable_req - initiates FCoE Session disable
417 * @port: port structure pointer
418 * @tgt: bnx2fc_rport structure pointer
420 int bnx2fc_send_session_disable_req(struct fcoe_port *port,
421 struct bnx2fc_rport *tgt)
423 struct bnx2fc_interface *interface = port->priv;
424 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
425 struct bnx2fc_hba *hba = interface->hba;
426 struct fcoe_kwqe_conn_enable_disable disable_req;
427 struct kwqe *kwqe_arr[2];
428 struct fc_rport *rport = tgt->rport;
429 int num_kwqes = 1;
430 int rc = 0;
431 u32 port_id;
433 memset(&disable_req, 0x00,
434 sizeof(struct fcoe_kwqe_conn_enable_disable));
435 disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
436 disable_req.hdr.flags =
437 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
439 disable_req.src_mac_addr_lo[0] = tgt->src_addr[5];
440 disable_req.src_mac_addr_lo[1] = tgt->src_addr[4];
441 disable_req.src_mac_addr_mid[0] = tgt->src_addr[3];
442 disable_req.src_mac_addr_mid[1] = tgt->src_addr[2];
443 disable_req.src_mac_addr_hi[0] = tgt->src_addr[1];
444 disable_req.src_mac_addr_hi[1] = tgt->src_addr[0];
446 disable_req.dst_mac_addr_lo[0] = ctlr->dest_addr[5];
447 disable_req.dst_mac_addr_lo[1] = ctlr->dest_addr[4];
448 disable_req.dst_mac_addr_mid[0] = ctlr->dest_addr[3];
449 disable_req.dst_mac_addr_mid[1] = ctlr->dest_addr[2];
450 disable_req.dst_mac_addr_hi[0] = ctlr->dest_addr[1];
451 disable_req.dst_mac_addr_hi[1] = ctlr->dest_addr[0];
453 port_id = tgt->sid;
454 disable_req.s_id[0] = (port_id & 0x000000FF);
455 disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
456 disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
459 port_id = rport->port_id;
460 disable_req.d_id[0] = (port_id & 0x000000FF);
461 disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
462 disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
463 disable_req.context_id = tgt->context_id;
464 disable_req.conn_id = tgt->fcoe_conn_id;
465 disable_req.vlan_tag = interface->vlan_id <<
466 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
467 disable_req.vlan_tag |=
468 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
469 disable_req.vlan_flag = interface->vlan_enabled;
471 kwqe_arr[0] = (struct kwqe *) &disable_req;
473 if (hba->cnic && hba->cnic->submit_kwqes)
474 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
476 return rc;
480 * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
482 * @port: port structure pointer
483 * @tgt: bnx2fc_rport structure pointer
485 int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
486 struct bnx2fc_rport *tgt)
488 struct fcoe_kwqe_conn_destroy destroy_req;
489 struct kwqe *kwqe_arr[2];
490 int num_kwqes = 1;
491 int rc = 0;
493 memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
494 destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
495 destroy_req.hdr.flags =
496 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
498 destroy_req.context_id = tgt->context_id;
499 destroy_req.conn_id = tgt->fcoe_conn_id;
501 kwqe_arr[0] = (struct kwqe *) &destroy_req;
503 if (hba->cnic && hba->cnic->submit_kwqes)
504 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
506 return rc;
509 static bool is_valid_lport(struct bnx2fc_hba *hba, struct fc_lport *lport)
511 struct bnx2fc_lport *blport;
513 spin_lock_bh(&hba->hba_lock);
514 list_for_each_entry(blport, &hba->vports, list) {
515 if (blport->lport == lport) {
516 spin_unlock_bh(&hba->hba_lock);
517 return true;
520 spin_unlock_bh(&hba->hba_lock);
521 return false;
526 static void bnx2fc_unsol_els_work(struct work_struct *work)
528 struct bnx2fc_unsol_els *unsol_els;
529 struct fc_lport *lport;
530 struct bnx2fc_hba *hba;
531 struct fc_frame *fp;
533 unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
534 lport = unsol_els->lport;
535 fp = unsol_els->fp;
536 hba = unsol_els->hba;
537 if (is_valid_lport(hba, lport))
538 fc_exch_recv(lport, fp);
539 kfree(unsol_els);
542 void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
543 unsigned char *buf,
544 u32 frame_len, u16 l2_oxid)
546 struct fcoe_port *port = tgt->port;
547 struct fc_lport *lport = port->lport;
548 struct bnx2fc_interface *interface = port->priv;
549 struct bnx2fc_unsol_els *unsol_els;
550 struct fc_frame_header *fh;
551 struct fc_frame *fp;
552 struct sk_buff *skb;
553 u32 payload_len;
554 u32 crc;
555 u8 op;
558 unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
559 if (!unsol_els) {
560 BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
561 return;
564 BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
565 l2_oxid, frame_len);
567 payload_len = frame_len - sizeof(struct fc_frame_header);
569 fp = fc_frame_alloc(lport, payload_len);
570 if (!fp) {
571 printk(KERN_ERR PFX "fc_frame_alloc failure\n");
572 kfree(unsol_els);
573 return;
576 fh = (struct fc_frame_header *) fc_frame_header_get(fp);
577 /* Copy FC Frame header and payload into the frame */
578 memcpy(fh, buf, frame_len);
580 if (l2_oxid != FC_XID_UNKNOWN)
581 fh->fh_ox_id = htons(l2_oxid);
583 skb = fp_skb(fp);
585 if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
586 (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
588 if (fh->fh_type == FC_TYPE_ELS) {
589 op = fc_frame_payload_op(fp);
590 if ((op == ELS_TEST) || (op == ELS_ESTC) ||
591 (op == ELS_FAN) || (op == ELS_CSU)) {
593 * No need to reply for these
594 * ELS requests
596 printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
597 kfree_skb(skb);
598 kfree(unsol_els);
599 return;
602 crc = fcoe_fc_crc(fp);
603 fc_frame_init(fp);
604 fr_dev(fp) = lport;
605 fr_sof(fp) = FC_SOF_I3;
606 fr_eof(fp) = FC_EOF_T;
607 fr_crc(fp) = cpu_to_le32(~crc);
608 unsol_els->lport = lport;
609 unsol_els->hba = interface->hba;
610 unsol_els->fp = fp;
611 INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
612 queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
613 } else {
614 BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
615 kfree_skb(skb);
616 kfree(unsol_els);
620 static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
622 u8 num_rq;
623 struct fcoe_err_report_entry *err_entry;
624 unsigned char *rq_data;
625 unsigned char *buf = NULL, *buf1;
626 int i;
627 u16 xid;
628 u32 frame_len, len;
629 struct bnx2fc_cmd *io_req = NULL;
630 struct fcoe_task_ctx_entry *task, *task_page;
631 struct bnx2fc_interface *interface = tgt->port->priv;
632 struct bnx2fc_hba *hba = interface->hba;
633 int task_idx, index;
634 int rc = 0;
635 u64 err_warn_bit_map;
636 u8 err_warn = 0xff;
639 BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe);
640 switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) {
641 case FCOE_UNSOLICITED_FRAME_CQE_TYPE:
642 frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >>
643 FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT;
645 num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ;
647 spin_lock_bh(&tgt->tgt_lock);
648 rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq);
649 spin_unlock_bh(&tgt->tgt_lock);
651 if (rq_data) {
652 buf = rq_data;
653 } else {
654 buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
655 GFP_ATOMIC);
657 if (!buf1) {
658 BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
659 break;
662 for (i = 0; i < num_rq; i++) {
663 spin_lock_bh(&tgt->tgt_lock);
664 rq_data = (unsigned char *)
665 bnx2fc_get_next_rqe(tgt, 1);
666 spin_unlock_bh(&tgt->tgt_lock);
667 len = BNX2FC_RQ_BUF_SZ;
668 memcpy(buf1, rq_data, len);
669 buf1 += len;
672 bnx2fc_process_l2_frame_compl(tgt, buf, frame_len,
673 FC_XID_UNKNOWN);
675 if (buf != rq_data)
676 kfree(buf);
677 spin_lock_bh(&tgt->tgt_lock);
678 bnx2fc_return_rqe(tgt, num_rq);
679 spin_unlock_bh(&tgt->tgt_lock);
680 break;
682 case FCOE_ERROR_DETECTION_CQE_TYPE:
684 * In case of error reporting CQE a single RQ entry
685 * is consumed.
687 spin_lock_bh(&tgt->tgt_lock);
688 num_rq = 1;
689 err_entry = (struct fcoe_err_report_entry *)
690 bnx2fc_get_next_rqe(tgt, 1);
691 xid = err_entry->fc_hdr.ox_id;
692 BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid);
693 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n",
694 err_entry->data.err_warn_bitmap_hi,
695 err_entry->data.err_warn_bitmap_lo);
696 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n",
697 err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
700 if (xid > BNX2FC_MAX_XID) {
701 BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
702 xid);
703 goto ret_err_rqe;
706 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
707 index = xid % BNX2FC_TASKS_PER_PAGE;
708 task_page = (struct fcoe_task_ctx_entry *)
709 hba->task_ctx[task_idx];
710 task = &(task_page[index]);
712 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
713 if (!io_req)
714 goto ret_err_rqe;
716 if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
717 printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
718 goto ret_err_rqe;
721 if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
722 &io_req->req_flags)) {
723 BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
724 "progress.. ignore unsol err\n");
725 goto ret_err_rqe;
728 err_warn_bit_map = (u64)
729 ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
730 (u64)err_entry->data.err_warn_bitmap_lo;
731 for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
732 if (err_warn_bit_map & (u64)((u64)1 << i)) {
733 err_warn = i;
734 break;
739 * If ABTS is already in progress, and FW error is
740 * received after that, do not cancel the timeout_work
741 * and let the error recovery continue by explicitly
742 * logging out the target, when the ABTS eventually
743 * times out.
745 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
746 printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
747 "in ABTS processing\n", xid);
748 goto ret_err_rqe;
750 BNX2FC_TGT_DBG(tgt, "err = 0x%x\n", err_warn);
751 if (tgt->dev_type != TYPE_TAPE)
752 goto skip_rec;
753 switch (err_warn) {
754 case FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION:
755 case FCOE_ERROR_CODE_DATA_OOO_RO:
756 case FCOE_ERROR_CODE_COMMON_INCORRECT_SEQ_CNT:
757 case FCOE_ERROR_CODE_DATA_SOFI3_SEQ_ACTIVE_SET:
758 case FCOE_ERROR_CODE_FCP_RSP_OPENED_SEQ:
759 case FCOE_ERROR_CODE_DATA_SOFN_SEQ_ACTIVE_RESET:
760 BNX2FC_TGT_DBG(tgt, "REC TOV popped for xid - 0x%x\n",
761 xid);
762 memset(&io_req->err_entry, 0,
763 sizeof(struct fcoe_err_report_entry));
764 memcpy(&io_req->err_entry, err_entry,
765 sizeof(struct fcoe_err_report_entry));
766 if (!test_bit(BNX2FC_FLAG_SRR_SENT,
767 &io_req->req_flags)) {
768 spin_unlock_bh(&tgt->tgt_lock);
769 rc = bnx2fc_send_rec(io_req);
770 spin_lock_bh(&tgt->tgt_lock);
772 if (rc)
773 goto skip_rec;
774 } else
775 printk(KERN_ERR PFX "SRR in progress\n");
776 goto ret_err_rqe;
777 break;
778 default:
779 break;
782 skip_rec:
783 set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags);
785 * Cancel the timeout_work, as we received IO
786 * completion with FW error.
788 if (cancel_delayed_work(&io_req->timeout_work))
789 kref_put(&io_req->refcount, bnx2fc_cmd_release);
791 rc = bnx2fc_initiate_abts(io_req);
792 if (rc != SUCCESS) {
793 printk(KERN_ERR PFX "err_warn: initiate_abts "
794 "failed xid = 0x%x. issue cleanup\n",
795 io_req->xid);
796 bnx2fc_initiate_cleanup(io_req);
798 ret_err_rqe:
799 bnx2fc_return_rqe(tgt, 1);
800 spin_unlock_bh(&tgt->tgt_lock);
801 break;
803 case FCOE_WARNING_DETECTION_CQE_TYPE:
805 *In case of warning reporting CQE a single RQ entry
806 * is consumes.
808 spin_lock_bh(&tgt->tgt_lock);
809 num_rq = 1;
810 err_entry = (struct fcoe_err_report_entry *)
811 bnx2fc_get_next_rqe(tgt, 1);
812 xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
813 BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
814 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
815 err_entry->data.err_warn_bitmap_hi,
816 err_entry->data.err_warn_bitmap_lo);
817 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
818 err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
820 if (xid > BNX2FC_MAX_XID) {
821 BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", xid);
822 goto ret_warn_rqe;
825 err_warn_bit_map = (u64)
826 ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
827 (u64)err_entry->data.err_warn_bitmap_lo;
828 for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
829 if (err_warn_bit_map & (u64) (1 << i)) {
830 err_warn = i;
831 break;
834 BNX2FC_TGT_DBG(tgt, "warn = 0x%x\n", err_warn);
836 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
837 index = xid % BNX2FC_TASKS_PER_PAGE;
838 task_page = (struct fcoe_task_ctx_entry *)
839 interface->hba->task_ctx[task_idx];
840 task = &(task_page[index]);
841 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
842 if (!io_req)
843 goto ret_warn_rqe;
845 if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
846 printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
847 goto ret_warn_rqe;
850 memset(&io_req->err_entry, 0,
851 sizeof(struct fcoe_err_report_entry));
852 memcpy(&io_req->err_entry, err_entry,
853 sizeof(struct fcoe_err_report_entry));
855 if (err_warn == FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION)
856 /* REC_TOV is not a warning code */
857 BUG_ON(1);
858 else
859 BNX2FC_TGT_DBG(tgt, "Unsolicited warning\n");
860 ret_warn_rqe:
861 bnx2fc_return_rqe(tgt, 1);
862 spin_unlock_bh(&tgt->tgt_lock);
863 break;
865 default:
866 printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
867 break;
871 void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
873 struct fcoe_task_ctx_entry *task;
874 struct fcoe_task_ctx_entry *task_page;
875 struct fcoe_port *port = tgt->port;
876 struct bnx2fc_interface *interface = port->priv;
877 struct bnx2fc_hba *hba = interface->hba;
878 struct bnx2fc_cmd *io_req;
879 int task_idx, index;
880 u16 xid;
881 u8 cmd_type;
882 u8 rx_state = 0;
883 u8 num_rq;
885 spin_lock_bh(&tgt->tgt_lock);
886 xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
887 if (xid >= BNX2FC_MAX_TASKS) {
888 printk(KERN_ERR PFX "ERROR:xid out of range\n");
889 spin_unlock_bh(&tgt->tgt_lock);
890 return;
892 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
893 index = xid % BNX2FC_TASKS_PER_PAGE;
894 task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
895 task = &(task_page[index]);
897 num_rq = ((task->rxwr_txrd.var_ctx.rx_flags &
898 FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE) >>
899 FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE_SHIFT);
901 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
903 if (io_req == NULL) {
904 printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
905 spin_unlock_bh(&tgt->tgt_lock);
906 return;
909 /* Timestamp IO completion time */
910 cmd_type = io_req->cmd_type;
912 rx_state = ((task->rxwr_txrd.var_ctx.rx_flags &
913 FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE) >>
914 FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE_SHIFT);
916 /* Process other IO completion types */
917 switch (cmd_type) {
918 case BNX2FC_SCSI_CMD:
919 if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
920 bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq);
921 spin_unlock_bh(&tgt->tgt_lock);
922 return;
925 if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
926 bnx2fc_process_abts_compl(io_req, task, num_rq);
927 else if (rx_state ==
928 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
929 bnx2fc_process_cleanup_compl(io_req, task, num_rq);
930 else
931 printk(KERN_ERR PFX "Invalid rx state - %d\n",
932 rx_state);
933 break;
935 case BNX2FC_TASK_MGMT_CMD:
936 BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
937 bnx2fc_process_tm_compl(io_req, task, num_rq);
938 break;
940 case BNX2FC_ABTS:
942 * ABTS request received by firmware. ABTS response
943 * will be delivered to the task belonging to the IO
944 * that was aborted
946 BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
947 kref_put(&io_req->refcount, bnx2fc_cmd_release);
948 break;
950 case BNX2FC_ELS:
951 if (rx_state == FCOE_TASK_RX_STATE_COMPLETED)
952 bnx2fc_process_els_compl(io_req, task, num_rq);
953 else if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
954 bnx2fc_process_abts_compl(io_req, task, num_rq);
955 else if (rx_state ==
956 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
957 bnx2fc_process_cleanup_compl(io_req, task, num_rq);
958 else
959 printk(KERN_ERR PFX "Invalid rx state = %d\n",
960 rx_state);
961 break;
963 case BNX2FC_CLEANUP:
964 BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
965 kref_put(&io_req->refcount, bnx2fc_cmd_release);
966 break;
968 case BNX2FC_SEQ_CLEANUP:
969 BNX2FC_IO_DBG(io_req, "cq_compl(0x%x) - seq cleanup resp\n",
970 io_req->xid);
971 bnx2fc_process_seq_cleanup_compl(io_req, task, rx_state);
972 kref_put(&io_req->refcount, bnx2fc_cmd_release);
973 break;
975 default:
976 printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
977 break;
979 spin_unlock_bh(&tgt->tgt_lock);
982 void bnx2fc_arm_cq(struct bnx2fc_rport *tgt)
984 struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
985 u32 msg;
987 wmb();
988 rx_db->doorbell_cq_cons = tgt->cq_cons_idx | (tgt->cq_curr_toggle_bit <<
989 FCOE_CQE_TOGGLE_BIT_SHIFT);
990 msg = *((u32 *)rx_db);
991 writel(cpu_to_le32(msg), tgt->ctx_base);
992 mmiowb();
996 struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe)
998 struct bnx2fc_work *work;
999 work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
1000 if (!work)
1001 return NULL;
1003 INIT_LIST_HEAD(&work->list);
1004 work->tgt = tgt;
1005 work->wqe = wqe;
1006 return work;
1009 int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
1011 struct fcoe_cqe *cq;
1012 u32 cq_cons;
1013 struct fcoe_cqe *cqe;
1014 u32 num_free_sqes = 0;
1015 u32 num_cqes = 0;
1016 u16 wqe;
1019 * cq_lock is a low contention lock used to protect
1020 * the CQ data structure from being freed up during
1021 * the upload operation
1023 spin_lock_bh(&tgt->cq_lock);
1025 if (!tgt->cq) {
1026 printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
1027 spin_unlock_bh(&tgt->cq_lock);
1028 return 0;
1030 cq = tgt->cq;
1031 cq_cons = tgt->cq_cons_idx;
1032 cqe = &cq[cq_cons];
1034 while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
1035 (tgt->cq_curr_toggle_bit <<
1036 FCOE_CQE_TOGGLE_BIT_SHIFT)) {
1038 /* new entry on the cq */
1039 if (wqe & FCOE_CQE_CQE_TYPE) {
1040 /* Unsolicited event notification */
1041 bnx2fc_process_unsol_compl(tgt, wqe);
1042 } else {
1043 /* Pending work request completion */
1044 struct bnx2fc_work *work = NULL;
1045 struct bnx2fc_percpu_s *fps = NULL;
1046 unsigned int cpu = wqe % num_possible_cpus();
1048 fps = &per_cpu(bnx2fc_percpu, cpu);
1049 spin_lock_bh(&fps->fp_work_lock);
1050 if (unlikely(!fps->iothread))
1051 goto unlock;
1053 work = bnx2fc_alloc_work(tgt, wqe);
1054 if (work)
1055 list_add_tail(&work->list,
1056 &fps->work_list);
1057 unlock:
1058 spin_unlock_bh(&fps->fp_work_lock);
1060 /* Pending work request completion */
1061 if (fps->iothread && work)
1062 wake_up_process(fps->iothread);
1063 else
1064 bnx2fc_process_cq_compl(tgt, wqe);
1065 num_free_sqes++;
1067 cqe++;
1068 tgt->cq_cons_idx++;
1069 num_cqes++;
1071 if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
1072 tgt->cq_cons_idx = 0;
1073 cqe = cq;
1074 tgt->cq_curr_toggle_bit =
1075 1 - tgt->cq_curr_toggle_bit;
1078 if (num_cqes) {
1079 /* Arm CQ only if doorbell is mapped */
1080 if (tgt->ctx_base)
1081 bnx2fc_arm_cq(tgt);
1082 atomic_add(num_free_sqes, &tgt->free_sqes);
1084 spin_unlock_bh(&tgt->cq_lock);
1085 return 0;
1089 * bnx2fc_fastpath_notification - process global event queue (KCQ)
1091 * @hba: adapter structure pointer
1092 * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry
1094 * Fast path event notification handler
1096 static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
1097 struct fcoe_kcqe *new_cqe_kcqe)
1099 u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
1100 struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
1102 if (!tgt) {
1103 printk(KERN_ERR PFX "conn_id 0x%x not valid\n", conn_id);
1104 return;
1107 bnx2fc_process_new_cqes(tgt);
1111 * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
1113 * @hba: adapter structure pointer
1114 * @ofld_kcqe: connection offload kcqe pointer
1116 * handle session offload completion, enable the session if offload is
1117 * successful.
1119 static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
1120 struct fcoe_kcqe *ofld_kcqe)
1122 struct bnx2fc_rport *tgt;
1123 struct fcoe_port *port;
1124 struct bnx2fc_interface *interface;
1125 u32 conn_id;
1126 u32 context_id;
1127 int rc;
1129 conn_id = ofld_kcqe->fcoe_conn_id;
1130 context_id = ofld_kcqe->fcoe_conn_context_id;
1131 tgt = hba->tgt_ofld_list[conn_id];
1132 if (!tgt) {
1133 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
1134 return;
1136 BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
1137 ofld_kcqe->fcoe_conn_context_id);
1138 port = tgt->port;
1139 interface = tgt->port->priv;
1140 if (hba != interface->hba) {
1141 printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mis-match\n");
1142 goto ofld_cmpl_err;
1145 * cnic has allocated a context_id for this session; use this
1146 * while enabling the session.
1148 tgt->context_id = context_id;
1149 if (ofld_kcqe->completion_status) {
1150 if (ofld_kcqe->completion_status ==
1151 FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
1152 printk(KERN_ERR PFX "unable to allocate FCoE context "
1153 "resources\n");
1154 set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
1156 goto ofld_cmpl_err;
1157 } else {
1159 /* now enable the session */
1160 rc = bnx2fc_send_session_enable_req(port, tgt);
1161 if (rc) {
1162 printk(KERN_ERR PFX "enable session failed\n");
1163 goto ofld_cmpl_err;
1166 return;
1167 ofld_cmpl_err:
1168 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1169 wake_up_interruptible(&tgt->ofld_wait);
1173 * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
1175 * @hba: adapter structure pointer
1176 * @ofld_kcqe: connection offload kcqe pointer
1178 * handle session enable completion, mark the rport as ready
1181 static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1182 struct fcoe_kcqe *ofld_kcqe)
1184 struct bnx2fc_rport *tgt;
1185 struct bnx2fc_interface *interface;
1186 u32 conn_id;
1187 u32 context_id;
1189 context_id = ofld_kcqe->fcoe_conn_context_id;
1190 conn_id = ofld_kcqe->fcoe_conn_id;
1191 tgt = hba->tgt_ofld_list[conn_id];
1192 if (!tgt) {
1193 printk(KERN_ERR PFX "ERROR:enbl_cmpl: No pending ofld req\n");
1194 return;
1197 BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
1198 ofld_kcqe->fcoe_conn_context_id);
1201 * context_id should be the same for this target during offload
1202 * and enable
1204 if (tgt->context_id != context_id) {
1205 printk(KERN_ERR PFX "context id mis-match\n");
1206 return;
1208 interface = tgt->port->priv;
1209 if (hba != interface->hba) {
1210 printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
1211 goto enbl_cmpl_err;
1213 if (ofld_kcqe->completion_status)
1214 goto enbl_cmpl_err;
1215 else {
1216 /* enable successful - rport ready for issuing IOs */
1217 set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1218 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1219 wake_up_interruptible(&tgt->ofld_wait);
1221 return;
1223 enbl_cmpl_err:
1224 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1225 wake_up_interruptible(&tgt->ofld_wait);
1228 static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
1229 struct fcoe_kcqe *disable_kcqe)
1232 struct bnx2fc_rport *tgt;
1233 u32 conn_id;
1235 conn_id = disable_kcqe->fcoe_conn_id;
1236 tgt = hba->tgt_ofld_list[conn_id];
1237 if (!tgt) {
1238 printk(KERN_ERR PFX "ERROR: disable_cmpl: No disable req\n");
1239 return;
1242 BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
1244 if (disable_kcqe->completion_status) {
1245 printk(KERN_ERR PFX "Disable failed with cmpl status %d\n",
1246 disable_kcqe->completion_status);
1247 return;
1248 } else {
1249 /* disable successful */
1250 BNX2FC_TGT_DBG(tgt, "disable successful\n");
1251 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1252 set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1253 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1254 wake_up_interruptible(&tgt->upld_wait);
1258 static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
1259 struct fcoe_kcqe *destroy_kcqe)
1261 struct bnx2fc_rport *tgt;
1262 u32 conn_id;
1264 conn_id = destroy_kcqe->fcoe_conn_id;
1265 tgt = hba->tgt_ofld_list[conn_id];
1266 if (!tgt) {
1267 printk(KERN_ERR PFX "destroy_cmpl: No destroy req\n");
1268 return;
1271 BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
1273 if (destroy_kcqe->completion_status) {
1274 printk(KERN_ERR PFX "Destroy conn failed, cmpl status %d\n",
1275 destroy_kcqe->completion_status);
1276 return;
1277 } else {
1278 /* destroy successful */
1279 BNX2FC_TGT_DBG(tgt, "upload successful\n");
1280 clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1281 set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
1282 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1283 wake_up_interruptible(&tgt->upld_wait);
1287 static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
1289 switch (err_code) {
1290 case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
1291 printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
1292 break;
1294 case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
1295 printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
1296 break;
1298 case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
1299 printk(KERN_ERR PFX "init_failure due to NIC error\n");
1300 break;
1301 case FCOE_KCQE_COMPLETION_STATUS_ERROR:
1302 printk(KERN_ERR PFX "init failure due to compl status err\n");
1303 break;
1304 case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION:
1305 printk(KERN_ERR PFX "init failure due to HSI mismatch\n");
1306 break;
1307 default:
1308 printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
1313 * bnx2fc_indicae_kcqe - process KCQE
1315 * @hba: adapter structure pointer
1316 * @kcqe: kcqe pointer
1317 * @num_cqe: Number of completion queue elements
1319 * Generic KCQ event handler
1321 void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
1322 u32 num_cqe)
1324 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
1325 int i = 0;
1326 struct fcoe_kcqe *kcqe = NULL;
1328 while (i < num_cqe) {
1329 kcqe = (struct fcoe_kcqe *) kcq[i++];
1331 switch (kcqe->op_code) {
1332 case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
1333 bnx2fc_fastpath_notification(hba, kcqe);
1334 break;
1336 case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
1337 bnx2fc_process_ofld_cmpl(hba, kcqe);
1338 break;
1340 case FCOE_KCQE_OPCODE_ENABLE_CONN:
1341 bnx2fc_process_enable_conn_cmpl(hba, kcqe);
1342 break;
1344 case FCOE_KCQE_OPCODE_INIT_FUNC:
1345 if (kcqe->completion_status !=
1346 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1347 bnx2fc_init_failure(hba,
1348 kcqe->completion_status);
1349 } else {
1350 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1351 bnx2fc_get_link_state(hba);
1352 printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
1353 (u8)hba->pcidev->bus->number);
1355 break;
1357 case FCOE_KCQE_OPCODE_DESTROY_FUNC:
1358 if (kcqe->completion_status !=
1359 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1361 printk(KERN_ERR PFX "DESTROY failed\n");
1362 } else {
1363 printk(KERN_ERR PFX "DESTROY success\n");
1365 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1366 wake_up_interruptible(&hba->destroy_wait);
1367 break;
1369 case FCOE_KCQE_OPCODE_DISABLE_CONN:
1370 bnx2fc_process_conn_disable_cmpl(hba, kcqe);
1371 break;
1373 case FCOE_KCQE_OPCODE_DESTROY_CONN:
1374 bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
1375 break;
1377 case FCOE_KCQE_OPCODE_STAT_FUNC:
1378 if (kcqe->completion_status !=
1379 FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
1380 printk(KERN_ERR PFX "STAT failed\n");
1381 complete(&hba->stat_req_done);
1382 break;
1384 case FCOE_KCQE_OPCODE_FCOE_ERROR:
1385 /* fall thru */
1386 default:
1387 printk(KERN_ERR PFX "unknown opcode 0x%x\n",
1388 kcqe->op_code);
1393 void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
1395 struct fcoe_sqe *sqe;
1397 sqe = &tgt->sq[tgt->sq_prod_idx];
1399 /* Fill SQ WQE */
1400 sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
1401 sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
1403 /* Advance SQ Prod Idx */
1404 if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
1405 tgt->sq_prod_idx = 0;
1406 tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
1410 void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
1412 struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
1413 u32 msg;
1415 wmb();
1416 sq_db->prod = tgt->sq_prod_idx |
1417 (tgt->sq_curr_toggle_bit << 15);
1418 msg = *((u32 *)sq_db);
1419 writel(cpu_to_le32(msg), tgt->ctx_base);
1420 mmiowb();
1424 int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
1426 u32 context_id = tgt->context_id;
1427 struct fcoe_port *port = tgt->port;
1428 u32 reg_off;
1429 resource_size_t reg_base;
1430 struct bnx2fc_interface *interface = port->priv;
1431 struct bnx2fc_hba *hba = interface->hba;
1433 reg_base = pci_resource_start(hba->pcidev,
1434 BNX2X_DOORBELL_PCI_BAR);
1435 reg_off = BNX2FC_5771X_DB_PAGE_SIZE *
1436 (context_id & 0x1FFFF) + DPM_TRIGER_TYPE;
1437 tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4);
1438 if (!tgt->ctx_base)
1439 return -ENOMEM;
1440 return 0;
1443 char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1445 char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
1447 if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
1448 return NULL;
1450 tgt->rq_cons_idx += num_items;
1452 if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
1453 tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
1455 return buf;
1458 void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1460 /* return the rq buffer */
1461 u32 next_prod_idx = tgt->rq_prod_idx + num_items;
1462 if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
1463 /* Wrap around RQ */
1464 next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
1466 tgt->rq_prod_idx = next_prod_idx;
1467 tgt->conn_db->rq_prod = tgt->rq_prod_idx;
1470 void bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd *seq_clnp_req,
1471 struct fcoe_task_ctx_entry *task,
1472 struct bnx2fc_cmd *orig_io_req,
1473 u32 offset)
1475 struct scsi_cmnd *sc_cmd = orig_io_req->sc_cmd;
1476 struct bnx2fc_rport *tgt = seq_clnp_req->tgt;
1477 struct bnx2fc_interface *interface = tgt->port->priv;
1478 struct fcoe_bd_ctx *bd = orig_io_req->bd_tbl->bd_tbl;
1479 struct fcoe_task_ctx_entry *orig_task;
1480 struct fcoe_task_ctx_entry *task_page;
1481 struct fcoe_ext_mul_sges_ctx *sgl;
1482 u8 task_type = FCOE_TASK_TYPE_SEQUENCE_CLEANUP;
1483 u8 orig_task_type;
1484 u16 orig_xid = orig_io_req->xid;
1485 u32 context_id = tgt->context_id;
1486 u64 phys_addr = (u64)orig_io_req->bd_tbl->bd_tbl_dma;
1487 u32 orig_offset = offset;
1488 int bd_count;
1489 int orig_task_idx, index;
1490 int i;
1492 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1494 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1495 orig_task_type = FCOE_TASK_TYPE_WRITE;
1496 else
1497 orig_task_type = FCOE_TASK_TYPE_READ;
1499 /* Tx flags */
1500 task->txwr_rxrd.const_ctx.tx_flags =
1501 FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP <<
1502 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1503 /* init flags */
1504 task->txwr_rxrd.const_ctx.init_flags = task_type <<
1505 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1506 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1507 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1508 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1509 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1510 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1511 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1513 task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
1515 task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_seq_cnt = 0;
1516 task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_data_offset = offset;
1518 bd_count = orig_io_req->bd_tbl->bd_valid;
1520 /* obtain the appropriate bd entry from relative offset */
1521 for (i = 0; i < bd_count; i++) {
1522 if (offset < bd[i].buf_len)
1523 break;
1524 offset -= bd[i].buf_len;
1526 phys_addr += (i * sizeof(struct fcoe_bd_ctx));
1528 if (orig_task_type == FCOE_TASK_TYPE_WRITE) {
1529 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1530 (u32)phys_addr;
1531 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1532 (u32)((u64)phys_addr >> 32);
1533 task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
1534 bd_count;
1535 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_off =
1536 offset; /* adjusted offset */
1537 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_idx = i;
1538 } else {
1539 orig_task_idx = orig_xid / BNX2FC_TASKS_PER_PAGE;
1540 index = orig_xid % BNX2FC_TASKS_PER_PAGE;
1542 task_page = (struct fcoe_task_ctx_entry *)
1543 interface->hba->task_ctx[orig_task_idx];
1544 orig_task = &(task_page[index]);
1546 /* Multiple SGEs were used for this IO */
1547 sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1548 sgl->mul_sgl.cur_sge_addr.lo = (u32)phys_addr;
1549 sgl->mul_sgl.cur_sge_addr.hi = (u32)((u64)phys_addr >> 32);
1550 sgl->mul_sgl.sgl_size = bd_count;
1551 sgl->mul_sgl.cur_sge_off = offset; /*adjusted offset */
1552 sgl->mul_sgl.cur_sge_idx = i;
1554 memset(&task->rxwr_only.rx_seq_ctx, 0,
1555 sizeof(struct fcoe_rx_seq_ctx));
1556 task->rxwr_only.rx_seq_ctx.low_exp_ro = orig_offset;
1557 task->rxwr_only.rx_seq_ctx.high_exp_ro = orig_offset;
1560 void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
1561 struct fcoe_task_ctx_entry *task,
1562 u16 orig_xid)
1564 u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
1565 struct bnx2fc_rport *tgt = io_req->tgt;
1566 u32 context_id = tgt->context_id;
1568 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1570 /* Tx Write Rx Read */
1571 /* init flags */
1572 task->txwr_rxrd.const_ctx.init_flags = task_type <<
1573 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1574 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1575 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1576 if (tgt->dev_type == TYPE_TAPE)
1577 task->txwr_rxrd.const_ctx.init_flags |=
1578 FCOE_TASK_DEV_TYPE_TAPE <<
1579 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1580 else
1581 task->txwr_rxrd.const_ctx.init_flags |=
1582 FCOE_TASK_DEV_TYPE_DISK <<
1583 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1584 task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
1586 /* Tx flags */
1587 task->txwr_rxrd.const_ctx.tx_flags =
1588 FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
1589 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1591 /* Rx Read Tx Write */
1592 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1593 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1594 task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1595 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1598 void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
1599 struct fcoe_task_ctx_entry *task)
1601 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
1602 struct bnx2fc_rport *tgt = io_req->tgt;
1603 struct fc_frame_header *fc_hdr;
1604 struct fcoe_ext_mul_sges_ctx *sgl;
1605 u8 task_type = 0;
1606 u64 *hdr;
1607 u64 temp_hdr[3];
1608 u32 context_id;
1611 /* Obtain task_type */
1612 if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
1613 (io_req->cmd_type == BNX2FC_ELS)) {
1614 task_type = FCOE_TASK_TYPE_MIDPATH;
1615 } else if (io_req->cmd_type == BNX2FC_ABTS) {
1616 task_type = FCOE_TASK_TYPE_ABTS;
1619 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1621 /* Setup the task from io_req for easy reference */
1622 io_req->task = task;
1624 BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
1625 io_req->cmd_type, task_type);
1627 /* Tx only */
1628 if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
1629 (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
1630 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1631 (u32)mp_req->mp_req_bd_dma;
1632 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1633 (u32)((u64)mp_req->mp_req_bd_dma >> 32);
1634 task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1;
1637 /* Tx Write Rx Read */
1638 /* init flags */
1639 task->txwr_rxrd.const_ctx.init_flags = task_type <<
1640 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1641 if (tgt->dev_type == TYPE_TAPE)
1642 task->txwr_rxrd.const_ctx.init_flags |=
1643 FCOE_TASK_DEV_TYPE_TAPE <<
1644 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1645 else
1646 task->txwr_rxrd.const_ctx.init_flags |=
1647 FCOE_TASK_DEV_TYPE_DISK <<
1648 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1649 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1650 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1652 /* tx flags */
1653 task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_INIT <<
1654 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1656 /* Rx Write Tx Read */
1657 task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1659 /* rx flags */
1660 task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1661 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1663 context_id = tgt->context_id;
1664 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1665 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1667 fc_hdr = &(mp_req->req_fc_hdr);
1668 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1669 fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
1670 fc_hdr->fh_rx_id = htons(0xffff);
1671 task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1672 } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
1673 fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
1676 /* Fill FC Header into middle path buffer */
1677 hdr = (u64 *) &task->txwr_rxrd.union_ctx.tx_frame.fc_hdr;
1678 memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
1679 hdr[0] = cpu_to_be64(temp_hdr[0]);
1680 hdr[1] = cpu_to_be64(temp_hdr[1]);
1681 hdr[2] = cpu_to_be64(temp_hdr[2]);
1683 /* Rx Only */
1684 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1685 sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1687 sgl->mul_sgl.cur_sge_addr.lo = (u32)mp_req->mp_resp_bd_dma;
1688 sgl->mul_sgl.cur_sge_addr.hi =
1689 (u32)((u64)mp_req->mp_resp_bd_dma >> 32);
1690 sgl->mul_sgl.sgl_size = 1;
1694 void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
1695 struct fcoe_task_ctx_entry *task)
1697 u8 task_type;
1698 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1699 struct io_bdt *bd_tbl = io_req->bd_tbl;
1700 struct bnx2fc_rport *tgt = io_req->tgt;
1701 struct fcoe_cached_sge_ctx *cached_sge;
1702 struct fcoe_ext_mul_sges_ctx *sgl;
1703 int dev_type = tgt->dev_type;
1704 u64 *fcp_cmnd;
1705 u64 tmp_fcp_cmnd[4];
1706 u32 context_id;
1707 int cnt, i;
1708 int bd_count;
1710 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1712 /* Setup the task from io_req for easy reference */
1713 io_req->task = task;
1715 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1716 task_type = FCOE_TASK_TYPE_WRITE;
1717 else
1718 task_type = FCOE_TASK_TYPE_READ;
1720 /* Tx only */
1721 bd_count = bd_tbl->bd_valid;
1722 cached_sge = &task->rxwr_only.union_ctx.read_info.sgl_ctx.cached_sge;
1723 if (task_type == FCOE_TASK_TYPE_WRITE) {
1724 if ((dev_type == TYPE_DISK) && (bd_count == 1)) {
1725 struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1727 task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.lo =
1728 cached_sge->cur_buf_addr.lo =
1729 fcoe_bd_tbl->buf_addr_lo;
1730 task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.hi =
1731 cached_sge->cur_buf_addr.hi =
1732 fcoe_bd_tbl->buf_addr_hi;
1733 task->txwr_only.sgl_ctx.cached_sge.cur_buf_rem =
1734 cached_sge->cur_buf_rem =
1735 fcoe_bd_tbl->buf_len;
1737 task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1738 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1739 } else {
1740 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1741 (u32)bd_tbl->bd_tbl_dma;
1742 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1743 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1744 task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
1745 bd_tbl->bd_valid;
1749 /*Tx Write Rx Read */
1750 /* Init state to NORMAL */
1751 task->txwr_rxrd.const_ctx.init_flags |= task_type <<
1752 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1753 if (dev_type == TYPE_TAPE) {
1754 task->txwr_rxrd.const_ctx.init_flags |=
1755 FCOE_TASK_DEV_TYPE_TAPE <<
1756 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1757 io_req->rec_retry = 0;
1758 io_req->rec_retry = 0;
1759 } else
1760 task->txwr_rxrd.const_ctx.init_flags |=
1761 FCOE_TASK_DEV_TYPE_DISK <<
1762 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1763 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1764 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1765 /* tx flags */
1766 task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
1767 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1769 /* Set initial seq counter */
1770 task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1;
1772 /* Fill FCP_CMND IU */
1773 fcp_cmnd = (u64 *)
1774 task->txwr_rxrd.union_ctx.fcp_cmd.opaque;
1775 bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
1777 /* swap fcp_cmnd */
1778 cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
1780 for (i = 0; i < cnt; i++) {
1781 *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
1782 fcp_cmnd++;
1785 /* Rx Write Tx Read */
1786 task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1788 context_id = tgt->context_id;
1789 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1790 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1792 /* rx flags */
1793 /* Set state to "waiting for the first packet" */
1794 task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1795 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1797 task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1799 /* Rx Only */
1800 if (task_type != FCOE_TASK_TYPE_READ)
1801 return;
1803 sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1804 bd_count = bd_tbl->bd_valid;
1806 if (dev_type == TYPE_DISK) {
1807 if (bd_count == 1) {
1809 struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1811 cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1812 cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1813 cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1814 task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1815 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1816 } else if (bd_count == 2) {
1817 struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1819 cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1820 cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1821 cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1823 fcoe_bd_tbl++;
1824 cached_sge->second_buf_addr.lo =
1825 fcoe_bd_tbl->buf_addr_lo;
1826 cached_sge->second_buf_addr.hi =
1827 fcoe_bd_tbl->buf_addr_hi;
1828 cached_sge->second_buf_rem = fcoe_bd_tbl->buf_len;
1829 task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1830 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1831 } else {
1833 sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
1834 sgl->mul_sgl.cur_sge_addr.hi =
1835 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1836 sgl->mul_sgl.sgl_size = bd_count;
1838 } else {
1839 sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
1840 sgl->mul_sgl.cur_sge_addr.hi =
1841 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1842 sgl->mul_sgl.sgl_size = bd_count;
1847 * bnx2fc_setup_task_ctx - allocate and map task context
1849 * @hba: pointer to adapter structure
1851 * allocate memory for task context, and associated BD table to be used
1852 * by firmware
1855 int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
1857 int rc = 0;
1858 struct regpair *task_ctx_bdt;
1859 dma_addr_t addr;
1860 int i;
1863 * Allocate task context bd table. A page size of bd table
1864 * can map 256 buffers. Each buffer contains 32 task context
1865 * entries. Hence the limit with one page is 8192 task context
1866 * entries.
1868 hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
1869 PAGE_SIZE,
1870 &hba->task_ctx_bd_dma,
1871 GFP_KERNEL);
1872 if (!hba->task_ctx_bd_tbl) {
1873 printk(KERN_ERR PFX "unable to allocate task context BDT\n");
1874 rc = -1;
1875 goto out;
1877 memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
1880 * Allocate task_ctx which is an array of pointers pointing to
1881 * a page containing 32 task contexts
1883 hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)),
1884 GFP_KERNEL);
1885 if (!hba->task_ctx) {
1886 printk(KERN_ERR PFX "unable to allocate task context array\n");
1887 rc = -1;
1888 goto out1;
1892 * Allocate task_ctx_dma which is an array of dma addresses
1894 hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ *
1895 sizeof(dma_addr_t)), GFP_KERNEL);
1896 if (!hba->task_ctx_dma) {
1897 printk(KERN_ERR PFX "unable to alloc context mapping array\n");
1898 rc = -1;
1899 goto out2;
1902 task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
1903 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1905 hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
1906 PAGE_SIZE,
1907 &hba->task_ctx_dma[i],
1908 GFP_KERNEL);
1909 if (!hba->task_ctx[i]) {
1910 printk(KERN_ERR PFX "unable to alloc task context\n");
1911 rc = -1;
1912 goto out3;
1914 memset(hba->task_ctx[i], 0, PAGE_SIZE);
1915 addr = (u64)hba->task_ctx_dma[i];
1916 task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
1917 task_ctx_bdt->lo = cpu_to_le32((u32)addr);
1918 task_ctx_bdt++;
1920 return 0;
1922 out3:
1923 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1924 if (hba->task_ctx[i]) {
1926 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1927 hba->task_ctx[i], hba->task_ctx_dma[i]);
1928 hba->task_ctx[i] = NULL;
1932 kfree(hba->task_ctx_dma);
1933 hba->task_ctx_dma = NULL;
1934 out2:
1935 kfree(hba->task_ctx);
1936 hba->task_ctx = NULL;
1937 out1:
1938 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1939 hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
1940 hba->task_ctx_bd_tbl = NULL;
1941 out:
1942 return rc;
1945 void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
1947 int i;
1949 if (hba->task_ctx_bd_tbl) {
1950 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1951 hba->task_ctx_bd_tbl,
1952 hba->task_ctx_bd_dma);
1953 hba->task_ctx_bd_tbl = NULL;
1956 if (hba->task_ctx) {
1957 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1958 if (hba->task_ctx[i]) {
1959 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1960 hba->task_ctx[i],
1961 hba->task_ctx_dma[i]);
1962 hba->task_ctx[i] = NULL;
1965 kfree(hba->task_ctx);
1966 hba->task_ctx = NULL;
1969 kfree(hba->task_ctx_dma);
1970 hba->task_ctx_dma = NULL;
1973 static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
1975 int i;
1976 int segment_count;
1977 int hash_table_size;
1978 u32 *pbl;
1980 segment_count = hba->hash_tbl_segment_count;
1981 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
1982 sizeof(struct fcoe_hash_table_entry);
1984 pbl = hba->hash_tbl_pbl;
1985 for (i = 0; i < segment_count; ++i) {
1986 dma_addr_t dma_address;
1988 dma_address = le32_to_cpu(*pbl);
1989 ++pbl;
1990 dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
1991 ++pbl;
1992 dma_free_coherent(&hba->pcidev->dev,
1993 BNX2FC_HASH_TBL_CHUNK_SIZE,
1994 hba->hash_tbl_segments[i],
1995 dma_address);
1999 if (hba->hash_tbl_pbl) {
2000 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2001 hba->hash_tbl_pbl,
2002 hba->hash_tbl_pbl_dma);
2003 hba->hash_tbl_pbl = NULL;
2007 static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
2009 int i;
2010 int hash_table_size;
2011 int segment_count;
2012 int segment_array_size;
2013 int dma_segment_array_size;
2014 dma_addr_t *dma_segment_array;
2015 u32 *pbl;
2017 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
2018 sizeof(struct fcoe_hash_table_entry);
2020 segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
2021 segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
2022 hba->hash_tbl_segment_count = segment_count;
2024 segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
2025 hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
2026 if (!hba->hash_tbl_segments) {
2027 printk(KERN_ERR PFX "hash table pointers alloc failed\n");
2028 return -ENOMEM;
2030 dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
2031 dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
2032 if (!dma_segment_array) {
2033 printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
2034 return -ENOMEM;
2037 for (i = 0; i < segment_count; ++i) {
2038 hba->hash_tbl_segments[i] =
2039 dma_alloc_coherent(&hba->pcidev->dev,
2040 BNX2FC_HASH_TBL_CHUNK_SIZE,
2041 &dma_segment_array[i],
2042 GFP_KERNEL);
2043 if (!hba->hash_tbl_segments[i]) {
2044 printk(KERN_ERR PFX "hash segment alloc failed\n");
2045 while (--i >= 0) {
2046 dma_free_coherent(&hba->pcidev->dev,
2047 BNX2FC_HASH_TBL_CHUNK_SIZE,
2048 hba->hash_tbl_segments[i],
2049 dma_segment_array[i]);
2050 hba->hash_tbl_segments[i] = NULL;
2052 kfree(dma_segment_array);
2053 return -ENOMEM;
2055 memset(hba->hash_tbl_segments[i], 0,
2056 BNX2FC_HASH_TBL_CHUNK_SIZE);
2059 hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev,
2060 PAGE_SIZE,
2061 &hba->hash_tbl_pbl_dma,
2062 GFP_KERNEL);
2063 if (!hba->hash_tbl_pbl) {
2064 printk(KERN_ERR PFX "hash table pbl alloc failed\n");
2065 kfree(dma_segment_array);
2066 return -ENOMEM;
2068 memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
2070 pbl = hba->hash_tbl_pbl;
2071 for (i = 0; i < segment_count; ++i) {
2072 u64 paddr = dma_segment_array[i];
2073 *pbl = cpu_to_le32((u32) paddr);
2074 ++pbl;
2075 *pbl = cpu_to_le32((u32) (paddr >> 32));
2076 ++pbl;
2078 pbl = hba->hash_tbl_pbl;
2079 i = 0;
2080 while (*pbl && *(pbl + 1)) {
2081 u32 lo;
2082 u32 hi;
2083 lo = *pbl;
2084 ++pbl;
2085 hi = *pbl;
2086 ++pbl;
2087 ++i;
2089 kfree(dma_segment_array);
2090 return 0;
2094 * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
2096 * @hba: Pointer to adapter structure
2099 int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
2101 u64 addr;
2102 u32 mem_size;
2103 int i;
2105 if (bnx2fc_allocate_hash_table(hba))
2106 return -ENOMEM;
2108 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2109 hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2110 &hba->t2_hash_tbl_ptr_dma,
2111 GFP_KERNEL);
2112 if (!hba->t2_hash_tbl_ptr) {
2113 printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
2114 bnx2fc_free_fw_resc(hba);
2115 return -ENOMEM;
2117 memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
2119 mem_size = BNX2FC_NUM_MAX_SESS *
2120 sizeof(struct fcoe_t2_hash_table_entry);
2121 hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2122 &hba->t2_hash_tbl_dma,
2123 GFP_KERNEL);
2124 if (!hba->t2_hash_tbl) {
2125 printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
2126 bnx2fc_free_fw_resc(hba);
2127 return -ENOMEM;
2129 memset(hba->t2_hash_tbl, 0x00, mem_size);
2130 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
2131 addr = (unsigned long) hba->t2_hash_tbl_dma +
2132 ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
2133 hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
2134 hba->t2_hash_tbl[i].next.hi = addr >> 32;
2137 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
2138 PAGE_SIZE, &hba->dummy_buf_dma,
2139 GFP_KERNEL);
2140 if (!hba->dummy_buffer) {
2141 printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
2142 bnx2fc_free_fw_resc(hba);
2143 return -ENOMEM;
2146 hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
2147 PAGE_SIZE,
2148 &hba->stats_buf_dma,
2149 GFP_KERNEL);
2150 if (!hba->stats_buffer) {
2151 printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
2152 bnx2fc_free_fw_resc(hba);
2153 return -ENOMEM;
2155 memset(hba->stats_buffer, 0x00, PAGE_SIZE);
2157 return 0;
2160 void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
2162 u32 mem_size;
2164 if (hba->stats_buffer) {
2165 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2166 hba->stats_buffer, hba->stats_buf_dma);
2167 hba->stats_buffer = NULL;
2170 if (hba->dummy_buffer) {
2171 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2172 hba->dummy_buffer, hba->dummy_buf_dma);
2173 hba->dummy_buffer = NULL;
2176 if (hba->t2_hash_tbl_ptr) {
2177 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2178 dma_free_coherent(&hba->pcidev->dev, mem_size,
2179 hba->t2_hash_tbl_ptr,
2180 hba->t2_hash_tbl_ptr_dma);
2181 hba->t2_hash_tbl_ptr = NULL;
2184 if (hba->t2_hash_tbl) {
2185 mem_size = BNX2FC_NUM_MAX_SESS *
2186 sizeof(struct fcoe_t2_hash_table_entry);
2187 dma_free_coherent(&hba->pcidev->dev, mem_size,
2188 hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
2189 hba->t2_hash_tbl = NULL;
2191 bnx2fc_free_hash_table(hba);