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 *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];
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_ERR 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 = 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;
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);
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];
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);
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 bnx2fc_hba *hba = interface->hba;
171 struct kwqe *kwqe_arr[4];
172 struct fcoe_kwqe_conn_offload1 ofld_req1;
173 struct fcoe_kwqe_conn_offload2 ofld_req2;
174 struct fcoe_kwqe_conn_offload3 ofld_req3;
175 struct fcoe_kwqe_conn_offload4 ofld_req4;
176 struct fc_rport_priv *rdata = tgt->rdata;
177 struct fc_rport *rport = tgt->rport;
183 /* Initialize offload request 1 structure */
184 memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
186 ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
187 ofld_req1.hdr.flags =
188 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
191 conn_id = (u16)tgt->fcoe_conn_id;
192 ofld_req1.fcoe_conn_id = conn_id;
195 ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
196 ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
198 ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
199 ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
201 ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
202 ofld_req1.rq_first_pbe_addr_hi =
203 (u32)((u64) tgt->rq_dma >> 32);
205 ofld_req1.rq_prod = 0x8000;
207 /* Initialize offload request 2 structure */
208 memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
210 ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
211 ofld_req2.hdr.flags =
212 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
214 ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
216 ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
217 ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
219 ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
220 ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
222 ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
223 ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
225 /* Initialize offload request 3 structure */
226 memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
228 ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
229 ofld_req3.hdr.flags =
230 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
232 ofld_req3.vlan_tag = interface->vlan_id <<
233 FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
234 ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
236 port_id = fc_host_port_id(lport->host);
238 BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
243 * Store s_id of the initiator for further reference. This will
244 * be used during disable/destroy during linkdown processing as
245 * when the lport is reset, the port_id also is reset to 0
248 ofld_req3.s_id[0] = (port_id & 0x000000FF);
249 ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
250 ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
252 port_id = rport->port_id;
253 ofld_req3.d_id[0] = (port_id & 0x000000FF);
254 ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
255 ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
257 ofld_req3.tx_total_conc_seqs = rdata->max_seq;
259 ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
260 ofld_req3.rx_max_fc_pay_len = lport->mfs;
262 ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
263 ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
264 ofld_req3.rx_open_seqs_exch_c3 = 1;
266 ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
267 ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
269 /* set mul_n_port_ids supported flag to 0, until it is supported */
272 ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
273 FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
275 /* Info from PLOGI response */
276 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
277 FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
279 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
280 FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
283 * Info from PRLI response, this info is used for sequence level error
286 if (tgt->dev_type == TYPE_TAPE) {
287 ofld_req3.flags |= 1 <<
288 FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT;
289 ofld_req3.flags |= (((rdata->flags & FC_RP_FLAGS_REC_SUPPORTED)
291 FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT);
295 ofld_req3.flags |= (interface->vlan_enabled <<
296 FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
298 /* C2_VALID and ACK flags are not set as they are not suppported */
301 /* Initialize offload request 4 structure */
302 memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
303 ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
304 ofld_req4.hdr.flags =
305 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
307 ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
310 ofld_req4.src_mac_addr_lo[0] = port->data_src_addr[5];
312 ofld_req4.src_mac_addr_lo[1] = port->data_src_addr[4];
313 ofld_req4.src_mac_addr_mid[0] = port->data_src_addr[3];
314 ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2];
315 ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1];
316 ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0];
317 ofld_req4.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
319 ofld_req4.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
320 ofld_req4.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
321 ofld_req4.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
322 ofld_req4.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
323 ofld_req4.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
325 ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
326 ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
328 ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
329 ofld_req4.confq_pbl_base_addr_hi =
330 (u32)((u64) tgt->confq_pbl_dma >> 32);
332 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
333 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
334 kwqe_arr[2] = (struct kwqe *) &ofld_req3;
335 kwqe_arr[3] = (struct kwqe *) &ofld_req4;
337 if (hba->cnic && hba->cnic->submit_kwqes)
338 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
344 * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
346 * @port: port structure pointer
347 * @tgt: bnx2fc_rport structure pointer
349 static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
350 struct bnx2fc_rport *tgt)
352 struct kwqe *kwqe_arr[2];
353 struct bnx2fc_interface *interface = port->priv;
354 struct bnx2fc_hba *hba = interface->hba;
355 struct fcoe_kwqe_conn_enable_disable enbl_req;
356 struct fc_lport *lport = port->lport;
357 struct fc_rport *rport = tgt->rport;
362 memset(&enbl_req, 0x00,
363 sizeof(struct fcoe_kwqe_conn_enable_disable));
364 enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
366 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
368 enbl_req.src_mac_addr_lo[0] = port->data_src_addr[5];
370 enbl_req.src_mac_addr_lo[1] = port->data_src_addr[4];
371 enbl_req.src_mac_addr_mid[0] = port->data_src_addr[3];
372 enbl_req.src_mac_addr_mid[1] = port->data_src_addr[2];
373 enbl_req.src_mac_addr_hi[0] = port->data_src_addr[1];
374 enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0];
375 memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
377 enbl_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
378 enbl_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
379 enbl_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
380 enbl_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
381 enbl_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
382 enbl_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
384 port_id = fc_host_port_id(lport->host);
385 if (port_id != tgt->sid) {
386 printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
387 "sid = 0x%x\n", port_id, tgt->sid);
390 enbl_req.s_id[0] = (port_id & 0x000000FF);
391 enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
392 enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
394 port_id = rport->port_id;
395 enbl_req.d_id[0] = (port_id & 0x000000FF);
396 enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
397 enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
398 enbl_req.vlan_tag = interface->vlan_id <<
399 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
400 enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
401 enbl_req.vlan_flag = interface->vlan_enabled;
402 enbl_req.context_id = tgt->context_id;
403 enbl_req.conn_id = tgt->fcoe_conn_id;
405 kwqe_arr[0] = (struct kwqe *) &enbl_req;
407 if (hba->cnic && hba->cnic->submit_kwqes)
408 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
413 * bnx2fc_send_session_disable_req - initiates FCoE Session disable
415 * @port: port structure pointer
416 * @tgt: bnx2fc_rport structure pointer
418 int bnx2fc_send_session_disable_req(struct fcoe_port *port,
419 struct bnx2fc_rport *tgt)
421 struct bnx2fc_interface *interface = port->priv;
422 struct bnx2fc_hba *hba = interface->hba;
423 struct fcoe_kwqe_conn_enable_disable disable_req;
424 struct kwqe *kwqe_arr[2];
425 struct fc_rport *rport = tgt->rport;
430 memset(&disable_req, 0x00,
431 sizeof(struct fcoe_kwqe_conn_enable_disable));
432 disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
433 disable_req.hdr.flags =
434 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
436 disable_req.src_mac_addr_lo[0] = tgt->src_addr[5];
437 disable_req.src_mac_addr_lo[1] = tgt->src_addr[4];
438 disable_req.src_mac_addr_mid[0] = tgt->src_addr[3];
439 disable_req.src_mac_addr_mid[1] = tgt->src_addr[2];
440 disable_req.src_mac_addr_hi[0] = tgt->src_addr[1];
441 disable_req.src_mac_addr_hi[1] = tgt->src_addr[0];
443 disable_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
444 disable_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
445 disable_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
446 disable_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
447 disable_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
448 disable_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
451 disable_req.s_id[0] = (port_id & 0x000000FF);
452 disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
453 disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
456 port_id = rport->port_id;
457 disable_req.d_id[0] = (port_id & 0x000000FF);
458 disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
459 disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
460 disable_req.context_id = tgt->context_id;
461 disable_req.conn_id = tgt->fcoe_conn_id;
462 disable_req.vlan_tag = interface->vlan_id <<
463 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
464 disable_req.vlan_tag |=
465 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
466 disable_req.vlan_flag = interface->vlan_enabled;
468 kwqe_arr[0] = (struct kwqe *) &disable_req;
470 if (hba->cnic && hba->cnic->submit_kwqes)
471 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
477 * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
479 * @port: port structure pointer
480 * @tgt: bnx2fc_rport structure pointer
482 int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
483 struct bnx2fc_rport *tgt)
485 struct fcoe_kwqe_conn_destroy destroy_req;
486 struct kwqe *kwqe_arr[2];
490 memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
491 destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
492 destroy_req.hdr.flags =
493 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
495 destroy_req.context_id = tgt->context_id;
496 destroy_req.conn_id = tgt->fcoe_conn_id;
498 kwqe_arr[0] = (struct kwqe *) &destroy_req;
500 if (hba->cnic && hba->cnic->submit_kwqes)
501 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
506 static bool is_valid_lport(struct bnx2fc_hba *hba, struct fc_lport *lport)
508 struct bnx2fc_lport *blport;
510 spin_lock_bh(&hba->hba_lock);
511 list_for_each_entry(blport, &hba->vports, list) {
512 if (blport->lport == lport) {
513 spin_unlock_bh(&hba->hba_lock);
517 spin_unlock_bh(&hba->hba_lock);
523 static void bnx2fc_unsol_els_work(struct work_struct *work)
525 struct bnx2fc_unsol_els *unsol_els;
526 struct fc_lport *lport;
527 struct bnx2fc_hba *hba;
530 unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
531 lport = unsol_els->lport;
533 hba = unsol_els->hba;
534 if (is_valid_lport(hba, lport))
535 fc_exch_recv(lport, fp);
539 void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
541 u32 frame_len, u16 l2_oxid)
543 struct fcoe_port *port = tgt->port;
544 struct fc_lport *lport = port->lport;
545 struct bnx2fc_interface *interface = port->priv;
546 struct bnx2fc_unsol_els *unsol_els;
547 struct fc_frame_header *fh;
555 unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
557 BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
561 BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
564 payload_len = frame_len - sizeof(struct fc_frame_header);
566 fp = fc_frame_alloc(lport, payload_len);
568 printk(KERN_ERR PFX "fc_frame_alloc failure\n");
573 fh = (struct fc_frame_header *) fc_frame_header_get(fp);
574 /* Copy FC Frame header and payload into the frame */
575 memcpy(fh, buf, frame_len);
577 if (l2_oxid != FC_XID_UNKNOWN)
578 fh->fh_ox_id = htons(l2_oxid);
582 if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
583 (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
585 if (fh->fh_type == FC_TYPE_ELS) {
586 op = fc_frame_payload_op(fp);
587 if ((op == ELS_TEST) || (op == ELS_ESTC) ||
588 (op == ELS_FAN) || (op == ELS_CSU)) {
590 * No need to reply for these
593 printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
599 crc = fcoe_fc_crc(fp);
602 fr_sof(fp) = FC_SOF_I3;
603 fr_eof(fp) = FC_EOF_T;
604 fr_crc(fp) = cpu_to_le32(~crc);
605 unsol_els->lport = lport;
606 unsol_els->hba = interface->hba;
608 INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
609 queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
611 BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
617 static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
620 struct fcoe_err_report_entry *err_entry;
621 unsigned char *rq_data;
622 unsigned char *buf = NULL, *buf1;
626 struct bnx2fc_cmd *io_req = NULL;
627 struct fcoe_task_ctx_entry *task, *task_page;
628 struct bnx2fc_interface *interface = tgt->port->priv;
629 struct bnx2fc_hba *hba = interface->hba;
632 u64 err_warn_bit_map;
636 BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe);
637 switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) {
638 case FCOE_UNSOLICITED_FRAME_CQE_TYPE:
639 frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >>
640 FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT;
642 num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ;
644 spin_lock_bh(&tgt->tgt_lock);
645 rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq);
646 spin_unlock_bh(&tgt->tgt_lock);
651 buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
655 BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
659 for (i = 0; i < num_rq; i++) {
660 spin_lock_bh(&tgt->tgt_lock);
661 rq_data = (unsigned char *)
662 bnx2fc_get_next_rqe(tgt, 1);
663 spin_unlock_bh(&tgt->tgt_lock);
664 len = BNX2FC_RQ_BUF_SZ;
665 memcpy(buf1, rq_data, len);
669 bnx2fc_process_l2_frame_compl(tgt, buf, frame_len,
674 spin_lock_bh(&tgt->tgt_lock);
675 bnx2fc_return_rqe(tgt, num_rq);
676 spin_unlock_bh(&tgt->tgt_lock);
679 case FCOE_ERROR_DETECTION_CQE_TYPE:
681 * In case of error reporting CQE a single RQ entry
684 spin_lock_bh(&tgt->tgt_lock);
686 err_entry = (struct fcoe_err_report_entry *)
687 bnx2fc_get_next_rqe(tgt, 1);
688 xid = err_entry->fc_hdr.ox_id;
689 BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid);
690 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n",
691 err_entry->data.err_warn_bitmap_hi,
692 err_entry->data.err_warn_bitmap_lo);
693 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n",
694 err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
697 if (xid > BNX2FC_MAX_XID) {
698 BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
703 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
704 index = xid % BNX2FC_TASKS_PER_PAGE;
705 task_page = (struct fcoe_task_ctx_entry *)
706 hba->task_ctx[task_idx];
707 task = &(task_page[index]);
709 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
713 if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
714 printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
718 if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
719 &io_req->req_flags)) {
720 BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
721 "progress.. ignore unsol err\n");
725 err_warn_bit_map = (u64)
726 ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
727 (u64)err_entry->data.err_warn_bitmap_lo;
728 for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
729 if (err_warn_bit_map & (u64)((u64)1 << i)) {
736 * If ABTS is already in progress, and FW error is
737 * received after that, do not cancel the timeout_work
738 * and let the error recovery continue by explicitly
739 * logging out the target, when the ABTS eventually
742 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
743 printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
744 "in ABTS processing\n", xid);
747 BNX2FC_TGT_DBG(tgt, "err = 0x%x\n", err_warn);
748 if (tgt->dev_type != TYPE_TAPE)
751 case FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION:
752 case FCOE_ERROR_CODE_DATA_OOO_RO:
753 case FCOE_ERROR_CODE_COMMON_INCORRECT_SEQ_CNT:
754 case FCOE_ERROR_CODE_DATA_SOFI3_SEQ_ACTIVE_SET:
755 case FCOE_ERROR_CODE_FCP_RSP_OPENED_SEQ:
756 case FCOE_ERROR_CODE_DATA_SOFN_SEQ_ACTIVE_RESET:
757 BNX2FC_TGT_DBG(tgt, "REC TOV popped for xid - 0x%x\n",
759 memset(&io_req->err_entry, 0,
760 sizeof(struct fcoe_err_report_entry));
761 memcpy(&io_req->err_entry, err_entry,
762 sizeof(struct fcoe_err_report_entry));
763 if (!test_bit(BNX2FC_FLAG_SRR_SENT,
764 &io_req->req_flags)) {
765 spin_unlock_bh(&tgt->tgt_lock);
766 rc = bnx2fc_send_rec(io_req);
767 spin_lock_bh(&tgt->tgt_lock);
772 printk(KERN_ERR PFX "SRR in progress\n");
780 set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags);
782 * Cancel the timeout_work, as we received IO
783 * completion with FW error.
785 if (cancel_delayed_work(&io_req->timeout_work))
786 kref_put(&io_req->refcount, bnx2fc_cmd_release);
788 rc = bnx2fc_initiate_abts(io_req);
790 printk(KERN_ERR PFX "err_warn: initiate_abts "
791 "failed xid = 0x%x. issue cleanup\n",
793 bnx2fc_initiate_cleanup(io_req);
796 bnx2fc_return_rqe(tgt, 1);
797 spin_unlock_bh(&tgt->tgt_lock);
800 case FCOE_WARNING_DETECTION_CQE_TYPE:
802 *In case of warning reporting CQE a single RQ entry
805 spin_lock_bh(&tgt->tgt_lock);
807 err_entry = (struct fcoe_err_report_entry *)
808 bnx2fc_get_next_rqe(tgt, 1);
809 xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
810 BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
811 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
812 err_entry->data.err_warn_bitmap_hi,
813 err_entry->data.err_warn_bitmap_lo);
814 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
815 err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
817 if (xid > BNX2FC_MAX_XID) {
818 BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", xid);
822 err_warn_bit_map = (u64)
823 ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
824 (u64)err_entry->data.err_warn_bitmap_lo;
825 for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
826 if (err_warn_bit_map & (u64) (1 << i)) {
831 BNX2FC_TGT_DBG(tgt, "warn = 0x%x\n", err_warn);
833 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
834 index = xid % BNX2FC_TASKS_PER_PAGE;
835 task_page = (struct fcoe_task_ctx_entry *)
836 interface->hba->task_ctx[task_idx];
837 task = &(task_page[index]);
838 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
842 if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
843 printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
847 memset(&io_req->err_entry, 0,
848 sizeof(struct fcoe_err_report_entry));
849 memcpy(&io_req->err_entry, err_entry,
850 sizeof(struct fcoe_err_report_entry));
852 if (err_warn == FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION)
853 /* REC_TOV is not a warning code */
856 BNX2FC_TGT_DBG(tgt, "Unsolicited warning\n");
858 bnx2fc_return_rqe(tgt, 1);
859 spin_unlock_bh(&tgt->tgt_lock);
863 printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
868 void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
870 struct fcoe_task_ctx_entry *task;
871 struct fcoe_task_ctx_entry *task_page;
872 struct fcoe_port *port = tgt->port;
873 struct bnx2fc_interface *interface = port->priv;
874 struct bnx2fc_hba *hba = interface->hba;
875 struct bnx2fc_cmd *io_req;
882 spin_lock_bh(&tgt->tgt_lock);
883 xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
884 if (xid >= BNX2FC_MAX_TASKS) {
885 printk(KERN_ERR PFX "ERROR:xid out of range\n");
886 spin_unlock_bh(&tgt->tgt_lock);
889 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
890 index = xid % BNX2FC_TASKS_PER_PAGE;
891 task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
892 task = &(task_page[index]);
894 num_rq = ((task->rxwr_txrd.var_ctx.rx_flags &
895 FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE) >>
896 FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE_SHIFT);
898 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
900 if (io_req == NULL) {
901 printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
902 spin_unlock_bh(&tgt->tgt_lock);
906 /* Timestamp IO completion time */
907 cmd_type = io_req->cmd_type;
909 rx_state = ((task->rxwr_txrd.var_ctx.rx_flags &
910 FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE) >>
911 FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE_SHIFT);
913 /* Process other IO completion types */
915 case BNX2FC_SCSI_CMD:
916 if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
917 bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq);
918 spin_unlock_bh(&tgt->tgt_lock);
922 if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
923 bnx2fc_process_abts_compl(io_req, task, num_rq);
925 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
926 bnx2fc_process_cleanup_compl(io_req, task, num_rq);
928 printk(KERN_ERR PFX "Invalid rx state - %d\n",
932 case BNX2FC_TASK_MGMT_CMD:
933 BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
934 bnx2fc_process_tm_compl(io_req, task, num_rq);
939 * ABTS request received by firmware. ABTS response
940 * will be delivered to the task belonging to the IO
943 BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
944 kref_put(&io_req->refcount, bnx2fc_cmd_release);
948 if (rx_state == FCOE_TASK_RX_STATE_COMPLETED)
949 bnx2fc_process_els_compl(io_req, task, num_rq);
950 else if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
951 bnx2fc_process_abts_compl(io_req, task, num_rq);
953 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
954 bnx2fc_process_cleanup_compl(io_req, task, num_rq);
956 printk(KERN_ERR PFX "Invalid rx state = %d\n",
961 BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
962 kref_put(&io_req->refcount, bnx2fc_cmd_release);
965 case BNX2FC_SEQ_CLEANUP:
966 BNX2FC_IO_DBG(io_req, "cq_compl(0x%x) - seq cleanup resp\n",
968 bnx2fc_process_seq_cleanup_compl(io_req, task, rx_state);
969 kref_put(&io_req->refcount, bnx2fc_cmd_release);
973 printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
976 spin_unlock_bh(&tgt->tgt_lock);
979 void bnx2fc_arm_cq(struct bnx2fc_rport *tgt)
981 struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
985 rx_db->doorbell_cq_cons = tgt->cq_cons_idx | (tgt->cq_curr_toggle_bit <<
986 FCOE_CQE_TOGGLE_BIT_SHIFT);
987 msg = *((u32 *)rx_db);
988 writel(cpu_to_le32(msg), tgt->ctx_base);
993 struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe)
995 struct bnx2fc_work *work;
996 work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
1000 INIT_LIST_HEAD(&work->list);
1006 int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
1008 struct fcoe_cqe *cq;
1010 struct fcoe_cqe *cqe;
1011 u32 num_free_sqes = 0;
1015 * cq_lock is a low contention lock used to protect
1016 * the CQ data structure from being freed up during
1017 * the upload operation
1019 spin_lock_bh(&tgt->cq_lock);
1022 printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
1023 spin_unlock_bh(&tgt->cq_lock);
1027 cq_cons = tgt->cq_cons_idx;
1030 while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
1031 (tgt->cq_curr_toggle_bit <<
1032 FCOE_CQE_TOGGLE_BIT_SHIFT)) {
1034 /* new entry on the cq */
1035 if (wqe & FCOE_CQE_CQE_TYPE) {
1036 /* Unsolicited event notification */
1037 bnx2fc_process_unsol_compl(tgt, wqe);
1039 /* Pending work request completion */
1040 struct bnx2fc_work *work = NULL;
1041 struct bnx2fc_percpu_s *fps = NULL;
1042 unsigned int cpu = wqe % num_possible_cpus();
1044 fps = &per_cpu(bnx2fc_percpu, cpu);
1045 spin_lock_bh(&fps->fp_work_lock);
1046 if (unlikely(!fps->iothread))
1049 work = bnx2fc_alloc_work(tgt, wqe);
1051 list_add_tail(&work->list,
1054 spin_unlock_bh(&fps->fp_work_lock);
1056 /* Pending work request completion */
1057 if (fps->iothread && work)
1058 wake_up_process(fps->iothread);
1060 bnx2fc_process_cq_compl(tgt, wqe);
1066 if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
1067 tgt->cq_cons_idx = 0;
1069 tgt->cq_curr_toggle_bit =
1070 1 - tgt->cq_curr_toggle_bit;
1074 atomic_add(num_free_sqes, &tgt->free_sqes);
1075 spin_unlock_bh(&tgt->cq_lock);
1080 * bnx2fc_fastpath_notification - process global event queue (KCQ)
1082 * @hba: adapter structure pointer
1083 * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry
1085 * Fast path event notification handler
1087 static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
1088 struct fcoe_kcqe *new_cqe_kcqe)
1090 u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
1091 struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
1094 printk(KERN_ERR PFX "conn_id 0x%x not valid\n", conn_id);
1098 bnx2fc_process_new_cqes(tgt);
1102 * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
1104 * @hba: adapter structure pointer
1105 * @ofld_kcqe: connection offload kcqe pointer
1107 * handle session offload completion, enable the session if offload is
1110 static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
1111 struct fcoe_kcqe *ofld_kcqe)
1113 struct bnx2fc_rport *tgt;
1114 struct fcoe_port *port;
1115 struct bnx2fc_interface *interface;
1120 conn_id = ofld_kcqe->fcoe_conn_id;
1121 context_id = ofld_kcqe->fcoe_conn_context_id;
1122 tgt = hba->tgt_ofld_list[conn_id];
1124 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
1127 BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
1128 ofld_kcqe->fcoe_conn_context_id);
1130 interface = tgt->port->priv;
1131 if (hba != interface->hba) {
1132 printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mis-match\n");
1136 * cnic has allocated a context_id for this session; use this
1137 * while enabling the session.
1139 tgt->context_id = context_id;
1140 if (ofld_kcqe->completion_status) {
1141 if (ofld_kcqe->completion_status ==
1142 FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
1143 printk(KERN_ERR PFX "unable to allocate FCoE context "
1145 set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
1150 /* now enable the session */
1151 rc = bnx2fc_send_session_enable_req(port, tgt);
1153 printk(KERN_ERR PFX "enable session failed\n");
1159 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1160 wake_up_interruptible(&tgt->ofld_wait);
1164 * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
1166 * @hba: adapter structure pointer
1167 * @ofld_kcqe: connection offload kcqe pointer
1169 * handle session enable completion, mark the rport as ready
1172 static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1173 struct fcoe_kcqe *ofld_kcqe)
1175 struct bnx2fc_rport *tgt;
1176 struct bnx2fc_interface *interface;
1180 context_id = ofld_kcqe->fcoe_conn_context_id;
1181 conn_id = ofld_kcqe->fcoe_conn_id;
1182 tgt = hba->tgt_ofld_list[conn_id];
1184 printk(KERN_ERR PFX "ERROR:enbl_cmpl: No pending ofld req\n");
1188 BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
1189 ofld_kcqe->fcoe_conn_context_id);
1192 * context_id should be the same for this target during offload
1195 if (tgt->context_id != context_id) {
1196 printk(KERN_ERR PFX "context id mis-match\n");
1199 interface = tgt->port->priv;
1200 if (hba != interface->hba) {
1201 printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
1204 if (ofld_kcqe->completion_status)
1207 /* enable successful - rport ready for issuing IOs */
1208 set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1209 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1210 wake_up_interruptible(&tgt->ofld_wait);
1215 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1216 wake_up_interruptible(&tgt->ofld_wait);
1219 static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
1220 struct fcoe_kcqe *disable_kcqe)
1223 struct bnx2fc_rport *tgt;
1226 conn_id = disable_kcqe->fcoe_conn_id;
1227 tgt = hba->tgt_ofld_list[conn_id];
1229 printk(KERN_ERR PFX "ERROR: disable_cmpl: No disable req\n");
1233 BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
1235 if (disable_kcqe->completion_status) {
1236 printk(KERN_ERR PFX "Disable failed with cmpl status %d\n",
1237 disable_kcqe->completion_status);
1240 /* disable successful */
1241 BNX2FC_TGT_DBG(tgt, "disable successful\n");
1242 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1243 set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1244 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1245 wake_up_interruptible(&tgt->upld_wait);
1249 static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
1250 struct fcoe_kcqe *destroy_kcqe)
1252 struct bnx2fc_rport *tgt;
1255 conn_id = destroy_kcqe->fcoe_conn_id;
1256 tgt = hba->tgt_ofld_list[conn_id];
1258 printk(KERN_ERR PFX "destroy_cmpl: No destroy req\n");
1262 BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
1264 if (destroy_kcqe->completion_status) {
1265 printk(KERN_ERR PFX "Destroy conn failed, cmpl status %d\n",
1266 destroy_kcqe->completion_status);
1269 /* destroy successful */
1270 BNX2FC_TGT_DBG(tgt, "upload successful\n");
1271 clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1272 set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
1273 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1274 wake_up_interruptible(&tgt->upld_wait);
1278 static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
1281 case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
1282 printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
1285 case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
1286 printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
1289 case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
1290 printk(KERN_ERR PFX "init_failure due to NIC error\n");
1292 case FCOE_KCQE_COMPLETION_STATUS_ERROR:
1293 printk(KERN_ERR PFX "init failure due to compl status err\n");
1295 case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION:
1296 printk(KERN_ERR PFX "init failure due to HSI mismatch\n");
1299 printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
1304 * bnx2fc_indicae_kcqe - process KCQE
1306 * @hba: adapter structure pointer
1307 * @kcqe: kcqe pointer
1308 * @num_cqe: Number of completion queue elements
1310 * Generic KCQ event handler
1312 void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
1315 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
1317 struct fcoe_kcqe *kcqe = NULL;
1319 while (i < num_cqe) {
1320 kcqe = (struct fcoe_kcqe *) kcq[i++];
1322 switch (kcqe->op_code) {
1323 case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
1324 bnx2fc_fastpath_notification(hba, kcqe);
1327 case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
1328 bnx2fc_process_ofld_cmpl(hba, kcqe);
1331 case FCOE_KCQE_OPCODE_ENABLE_CONN:
1332 bnx2fc_process_enable_conn_cmpl(hba, kcqe);
1335 case FCOE_KCQE_OPCODE_INIT_FUNC:
1336 if (kcqe->completion_status !=
1337 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1338 bnx2fc_init_failure(hba,
1339 kcqe->completion_status);
1341 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1342 bnx2fc_get_link_state(hba);
1343 printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
1344 (u8)hba->pcidev->bus->number);
1348 case FCOE_KCQE_OPCODE_DESTROY_FUNC:
1349 if (kcqe->completion_status !=
1350 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1352 printk(KERN_ERR PFX "DESTROY failed\n");
1354 printk(KERN_ERR PFX "DESTROY success\n");
1356 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1357 wake_up_interruptible(&hba->destroy_wait);
1360 case FCOE_KCQE_OPCODE_DISABLE_CONN:
1361 bnx2fc_process_conn_disable_cmpl(hba, kcqe);
1364 case FCOE_KCQE_OPCODE_DESTROY_CONN:
1365 bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
1368 case FCOE_KCQE_OPCODE_STAT_FUNC:
1369 if (kcqe->completion_status !=
1370 FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
1371 printk(KERN_ERR PFX "STAT failed\n");
1372 complete(&hba->stat_req_done);
1375 case FCOE_KCQE_OPCODE_FCOE_ERROR:
1378 printk(KERN_ERR PFX "unknown opcode 0x%x\n",
1384 void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
1386 struct fcoe_sqe *sqe;
1388 sqe = &tgt->sq[tgt->sq_prod_idx];
1391 sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
1392 sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
1394 /* Advance SQ Prod Idx */
1395 if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
1396 tgt->sq_prod_idx = 0;
1397 tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
1401 void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
1403 struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
1407 sq_db->prod = tgt->sq_prod_idx |
1408 (tgt->sq_curr_toggle_bit << 15);
1409 msg = *((u32 *)sq_db);
1410 writel(cpu_to_le32(msg), tgt->ctx_base);
1415 int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
1417 u32 context_id = tgt->context_id;
1418 struct fcoe_port *port = tgt->port;
1420 resource_size_t reg_base;
1421 struct bnx2fc_interface *interface = port->priv;
1422 struct bnx2fc_hba *hba = interface->hba;
1424 reg_base = pci_resource_start(hba->pcidev,
1425 BNX2X_DOORBELL_PCI_BAR);
1426 reg_off = BNX2FC_5771X_DB_PAGE_SIZE *
1427 (context_id & 0x1FFFF) + DPM_TRIGER_TYPE;
1428 tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4);
1434 char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1436 char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
1438 if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
1441 tgt->rq_cons_idx += num_items;
1443 if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
1444 tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
1449 void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1451 /* return the rq buffer */
1452 u32 next_prod_idx = tgt->rq_prod_idx + num_items;
1453 if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
1454 /* Wrap around RQ */
1455 next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
1457 tgt->rq_prod_idx = next_prod_idx;
1458 tgt->conn_db->rq_prod = tgt->rq_prod_idx;
1461 void bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd *seq_clnp_req,
1462 struct fcoe_task_ctx_entry *task,
1463 struct bnx2fc_cmd *orig_io_req,
1466 struct scsi_cmnd *sc_cmd = orig_io_req->sc_cmd;
1467 struct bnx2fc_rport *tgt = seq_clnp_req->tgt;
1468 struct bnx2fc_interface *interface = tgt->port->priv;
1469 struct fcoe_bd_ctx *bd = orig_io_req->bd_tbl->bd_tbl;
1470 struct fcoe_task_ctx_entry *orig_task;
1471 struct fcoe_task_ctx_entry *task_page;
1472 struct fcoe_ext_mul_sges_ctx *sgl;
1473 u8 task_type = FCOE_TASK_TYPE_SEQUENCE_CLEANUP;
1475 u16 orig_xid = orig_io_req->xid;
1476 u32 context_id = tgt->context_id;
1477 u64 phys_addr = (u64)orig_io_req->bd_tbl->bd_tbl_dma;
1478 u32 orig_offset = offset;
1480 int orig_task_idx, index;
1483 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1485 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1486 orig_task_type = FCOE_TASK_TYPE_WRITE;
1488 orig_task_type = FCOE_TASK_TYPE_READ;
1491 task->txwr_rxrd.const_ctx.tx_flags =
1492 FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP <<
1493 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1495 task->txwr_rxrd.const_ctx.init_flags = task_type <<
1496 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1497 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1498 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1499 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1500 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1501 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1502 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1504 task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
1506 task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_seq_cnt = 0;
1507 task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_data_offset = offset;
1509 bd_count = orig_io_req->bd_tbl->bd_valid;
1511 /* obtain the appropriate bd entry from relative offset */
1512 for (i = 0; i < bd_count; i++) {
1513 if (offset < bd[i].buf_len)
1515 offset -= bd[i].buf_len;
1517 phys_addr += (i * sizeof(struct fcoe_bd_ctx));
1519 if (orig_task_type == FCOE_TASK_TYPE_WRITE) {
1520 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1522 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1523 (u32)((u64)phys_addr >> 32);
1524 task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
1526 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_off =
1527 offset; /* adjusted offset */
1528 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_idx = i;
1530 orig_task_idx = orig_xid / BNX2FC_TASKS_PER_PAGE;
1531 index = orig_xid % BNX2FC_TASKS_PER_PAGE;
1533 task_page = (struct fcoe_task_ctx_entry *)
1534 interface->hba->task_ctx[orig_task_idx];
1535 orig_task = &(task_page[index]);
1537 /* Multiple SGEs were used for this IO */
1538 sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1539 sgl->mul_sgl.cur_sge_addr.lo = (u32)phys_addr;
1540 sgl->mul_sgl.cur_sge_addr.hi = (u32)((u64)phys_addr >> 32);
1541 sgl->mul_sgl.sgl_size = bd_count;
1542 sgl->mul_sgl.cur_sge_off = offset; /*adjusted offset */
1543 sgl->mul_sgl.cur_sge_idx = i;
1545 memset(&task->rxwr_only.rx_seq_ctx, 0,
1546 sizeof(struct fcoe_rx_seq_ctx));
1547 task->rxwr_only.rx_seq_ctx.low_exp_ro = orig_offset;
1548 task->rxwr_only.rx_seq_ctx.high_exp_ro = orig_offset;
1551 void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
1552 struct fcoe_task_ctx_entry *task,
1555 u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
1556 struct bnx2fc_rport *tgt = io_req->tgt;
1557 u32 context_id = tgt->context_id;
1559 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1561 /* Tx Write Rx Read */
1563 task->txwr_rxrd.const_ctx.init_flags = task_type <<
1564 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1565 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1566 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1567 task->txwr_rxrd.const_ctx.init_flags |=
1568 FCOE_TASK_DEV_TYPE_DISK <<
1569 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1570 task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
1573 task->txwr_rxrd.const_ctx.tx_flags =
1574 FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
1575 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1577 /* Rx Read Tx Write */
1578 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1579 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1580 task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1581 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1584 void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
1585 struct fcoe_task_ctx_entry *task)
1587 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
1588 struct bnx2fc_rport *tgt = io_req->tgt;
1589 struct fc_frame_header *fc_hdr;
1590 struct fcoe_ext_mul_sges_ctx *sgl;
1597 /* Obtain task_type */
1598 if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
1599 (io_req->cmd_type == BNX2FC_ELS)) {
1600 task_type = FCOE_TASK_TYPE_MIDPATH;
1601 } else if (io_req->cmd_type == BNX2FC_ABTS) {
1602 task_type = FCOE_TASK_TYPE_ABTS;
1605 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1607 /* Setup the task from io_req for easy reference */
1608 io_req->task = task;
1610 BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
1611 io_req->cmd_type, task_type);
1614 if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
1615 (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
1616 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1617 (u32)mp_req->mp_req_bd_dma;
1618 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1619 (u32)((u64)mp_req->mp_req_bd_dma >> 32);
1620 task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1;
1623 /* Tx Write Rx Read */
1625 task->txwr_rxrd.const_ctx.init_flags = task_type <<
1626 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1627 task->txwr_rxrd.const_ctx.init_flags |=
1628 FCOE_TASK_DEV_TYPE_DISK <<
1629 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1630 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1631 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1634 task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_INIT <<
1635 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1637 /* Rx Write Tx Read */
1638 task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1641 task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1642 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1644 context_id = tgt->context_id;
1645 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1646 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1648 fc_hdr = &(mp_req->req_fc_hdr);
1649 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1650 fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
1651 fc_hdr->fh_rx_id = htons(0xffff);
1652 task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1653 } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
1654 fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
1657 /* Fill FC Header into middle path buffer */
1658 hdr = (u64 *) &task->txwr_rxrd.union_ctx.tx_frame.fc_hdr;
1659 memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
1660 hdr[0] = cpu_to_be64(temp_hdr[0]);
1661 hdr[1] = cpu_to_be64(temp_hdr[1]);
1662 hdr[2] = cpu_to_be64(temp_hdr[2]);
1665 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1666 sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1668 sgl->mul_sgl.cur_sge_addr.lo = (u32)mp_req->mp_resp_bd_dma;
1669 sgl->mul_sgl.cur_sge_addr.hi =
1670 (u32)((u64)mp_req->mp_resp_bd_dma >> 32);
1671 sgl->mul_sgl.sgl_size = 1;
1675 void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
1676 struct fcoe_task_ctx_entry *task)
1679 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1680 struct io_bdt *bd_tbl = io_req->bd_tbl;
1681 struct bnx2fc_rport *tgt = io_req->tgt;
1682 struct fcoe_cached_sge_ctx *cached_sge;
1683 struct fcoe_ext_mul_sges_ctx *sgl;
1685 u64 tmp_fcp_cmnd[4];
1690 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1692 /* Setup the task from io_req for easy reference */
1693 io_req->task = task;
1695 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1696 task_type = FCOE_TASK_TYPE_WRITE;
1698 task_type = FCOE_TASK_TYPE_READ;
1701 if (task_type == FCOE_TASK_TYPE_WRITE) {
1702 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
1703 (u32)bd_tbl->bd_tbl_dma;
1704 task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
1705 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1706 task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
1710 /*Tx Write Rx Read */
1711 /* Init state to NORMAL */
1712 task->txwr_rxrd.const_ctx.init_flags = task_type <<
1713 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
1714 task->txwr_rxrd.const_ctx.init_flags |=
1715 FCOE_TASK_DEV_TYPE_DISK <<
1716 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
1717 task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1718 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
1720 task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
1721 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
1723 /* Set initial seq counter */
1724 task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1;
1726 /* Fill FCP_CMND IU */
1728 task->txwr_rxrd.union_ctx.fcp_cmd.opaque;
1729 bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
1732 cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
1734 for (i = 0; i < cnt; i++) {
1735 *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
1739 /* Rx Write Tx Read */
1740 task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
1742 context_id = tgt->context_id;
1743 task->rxwr_txrd.const_ctx.init_flags = context_id <<
1744 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
1747 /* Set state to "waiting for the first packet" */
1748 task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
1749 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
1751 task->rxwr_txrd.var_ctx.rx_id = 0xffff;
1754 cached_sge = &task->rxwr_only.union_ctx.read_info.sgl_ctx.cached_sge;
1755 sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
1756 bd_count = bd_tbl->bd_valid;
1757 if (task_type == FCOE_TASK_TYPE_READ) {
1758 if (bd_count == 1) {
1760 struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1762 cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1763 cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1764 cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1765 task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1766 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1767 } else if (bd_count == 2) {
1768 struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1770 cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
1771 cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
1772 cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
1775 cached_sge->second_buf_addr.lo =
1776 fcoe_bd_tbl->buf_addr_lo;
1777 cached_sge->second_buf_addr.hi =
1778 fcoe_bd_tbl->buf_addr_hi;
1779 cached_sge->second_buf_rem = fcoe_bd_tbl->buf_len;
1780 task->txwr_rxrd.const_ctx.init_flags |= 1 <<
1781 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
1784 sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
1785 sgl->mul_sgl.cur_sge_addr.hi =
1786 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1787 sgl->mul_sgl.sgl_size = bd_count;
1793 * bnx2fc_setup_task_ctx - allocate and map task context
1795 * @hba: pointer to adapter structure
1797 * allocate memory for task context, and associated BD table to be used
1801 int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
1804 struct regpair *task_ctx_bdt;
1809 * Allocate task context bd table. A page size of bd table
1810 * can map 256 buffers. Each buffer contains 32 task context
1811 * entries. Hence the limit with one page is 8192 task context
1814 hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
1816 &hba->task_ctx_bd_dma,
1818 if (!hba->task_ctx_bd_tbl) {
1819 printk(KERN_ERR PFX "unable to allocate task context BDT\n");
1823 memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
1826 * Allocate task_ctx which is an array of pointers pointing to
1827 * a page containing 32 task contexts
1829 hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)),
1831 if (!hba->task_ctx) {
1832 printk(KERN_ERR PFX "unable to allocate task context array\n");
1838 * Allocate task_ctx_dma which is an array of dma addresses
1840 hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ *
1841 sizeof(dma_addr_t)), GFP_KERNEL);
1842 if (!hba->task_ctx_dma) {
1843 printk(KERN_ERR PFX "unable to alloc context mapping array\n");
1848 task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
1849 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1851 hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
1853 &hba->task_ctx_dma[i],
1855 if (!hba->task_ctx[i]) {
1856 printk(KERN_ERR PFX "unable to alloc task context\n");
1860 memset(hba->task_ctx[i], 0, PAGE_SIZE);
1861 addr = (u64)hba->task_ctx_dma[i];
1862 task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
1863 task_ctx_bdt->lo = cpu_to_le32((u32)addr);
1869 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1870 if (hba->task_ctx[i]) {
1872 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1873 hba->task_ctx[i], hba->task_ctx_dma[i]);
1874 hba->task_ctx[i] = NULL;
1878 kfree(hba->task_ctx_dma);
1879 hba->task_ctx_dma = NULL;
1881 kfree(hba->task_ctx);
1882 hba->task_ctx = NULL;
1884 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1885 hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
1886 hba->task_ctx_bd_tbl = NULL;
1891 void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
1895 if (hba->task_ctx_bd_tbl) {
1896 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1897 hba->task_ctx_bd_tbl,
1898 hba->task_ctx_bd_dma);
1899 hba->task_ctx_bd_tbl = NULL;
1902 if (hba->task_ctx) {
1903 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1904 if (hba->task_ctx[i]) {
1905 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1907 hba->task_ctx_dma[i]);
1908 hba->task_ctx[i] = NULL;
1911 kfree(hba->task_ctx);
1912 hba->task_ctx = NULL;
1915 kfree(hba->task_ctx_dma);
1916 hba->task_ctx_dma = NULL;
1919 static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
1923 int hash_table_size;
1926 segment_count = hba->hash_tbl_segment_count;
1927 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
1928 sizeof(struct fcoe_hash_table_entry);
1930 pbl = hba->hash_tbl_pbl;
1931 for (i = 0; i < segment_count; ++i) {
1932 dma_addr_t dma_address;
1934 dma_address = le32_to_cpu(*pbl);
1936 dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
1938 dma_free_coherent(&hba->pcidev->dev,
1939 BNX2FC_HASH_TBL_CHUNK_SIZE,
1940 hba->hash_tbl_segments[i],
1945 if (hba->hash_tbl_pbl) {
1946 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1948 hba->hash_tbl_pbl_dma);
1949 hba->hash_tbl_pbl = NULL;
1953 static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
1956 int hash_table_size;
1958 int segment_array_size;
1959 int dma_segment_array_size;
1960 dma_addr_t *dma_segment_array;
1963 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
1964 sizeof(struct fcoe_hash_table_entry);
1966 segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
1967 segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
1968 hba->hash_tbl_segment_count = segment_count;
1970 segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
1971 hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
1972 if (!hba->hash_tbl_segments) {
1973 printk(KERN_ERR PFX "hash table pointers alloc failed\n");
1976 dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
1977 dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
1978 if (!dma_segment_array) {
1979 printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
1983 for (i = 0; i < segment_count; ++i) {
1984 hba->hash_tbl_segments[i] =
1985 dma_alloc_coherent(&hba->pcidev->dev,
1986 BNX2FC_HASH_TBL_CHUNK_SIZE,
1987 &dma_segment_array[i],
1989 if (!hba->hash_tbl_segments[i]) {
1990 printk(KERN_ERR PFX "hash segment alloc failed\n");
1992 dma_free_coherent(&hba->pcidev->dev,
1993 BNX2FC_HASH_TBL_CHUNK_SIZE,
1994 hba->hash_tbl_segments[i],
1995 dma_segment_array[i]);
1996 hba->hash_tbl_segments[i] = NULL;
1998 kfree(dma_segment_array);
2001 memset(hba->hash_tbl_segments[i], 0,
2002 BNX2FC_HASH_TBL_CHUNK_SIZE);
2005 hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev,
2007 &hba->hash_tbl_pbl_dma,
2009 if (!hba->hash_tbl_pbl) {
2010 printk(KERN_ERR PFX "hash table pbl alloc failed\n");
2011 kfree(dma_segment_array);
2014 memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
2016 pbl = hba->hash_tbl_pbl;
2017 for (i = 0; i < segment_count; ++i) {
2018 u64 paddr = dma_segment_array[i];
2019 *pbl = cpu_to_le32((u32) paddr);
2021 *pbl = cpu_to_le32((u32) (paddr >> 32));
2024 pbl = hba->hash_tbl_pbl;
2026 while (*pbl && *(pbl + 1)) {
2035 kfree(dma_segment_array);
2040 * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
2042 * @hba: Pointer to adapter structure
2045 int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
2051 if (bnx2fc_allocate_hash_table(hba))
2054 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2055 hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2056 &hba->t2_hash_tbl_ptr_dma,
2058 if (!hba->t2_hash_tbl_ptr) {
2059 printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
2060 bnx2fc_free_fw_resc(hba);
2063 memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
2065 mem_size = BNX2FC_NUM_MAX_SESS *
2066 sizeof(struct fcoe_t2_hash_table_entry);
2067 hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
2068 &hba->t2_hash_tbl_dma,
2070 if (!hba->t2_hash_tbl) {
2071 printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
2072 bnx2fc_free_fw_resc(hba);
2075 memset(hba->t2_hash_tbl, 0x00, mem_size);
2076 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
2077 addr = (unsigned long) hba->t2_hash_tbl_dma +
2078 ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
2079 hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
2080 hba->t2_hash_tbl[i].next.hi = addr >> 32;
2083 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
2084 PAGE_SIZE, &hba->dummy_buf_dma,
2086 if (!hba->dummy_buffer) {
2087 printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
2088 bnx2fc_free_fw_resc(hba);
2092 hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
2094 &hba->stats_buf_dma,
2096 if (!hba->stats_buffer) {
2097 printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
2098 bnx2fc_free_fw_resc(hba);
2101 memset(hba->stats_buffer, 0x00, PAGE_SIZE);
2106 void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
2110 if (hba->stats_buffer) {
2111 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2112 hba->stats_buffer, hba->stats_buf_dma);
2113 hba->stats_buffer = NULL;
2116 if (hba->dummy_buffer) {
2117 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
2118 hba->dummy_buffer, hba->dummy_buf_dma);
2119 hba->dummy_buffer = NULL;
2122 if (hba->t2_hash_tbl_ptr) {
2123 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
2124 dma_free_coherent(&hba->pcidev->dev, mem_size,
2125 hba->t2_hash_tbl_ptr,
2126 hba->t2_hash_tbl_ptr_dma);
2127 hba->t2_hash_tbl_ptr = NULL;
2130 if (hba->t2_hash_tbl) {
2131 mem_size = BNX2FC_NUM_MAX_SESS *
2132 sizeof(struct fcoe_t2_hash_table_entry);
2133 dma_free_coherent(&hba->pcidev->dev, mem_size,
2134 hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
2135 hba->t2_hash_tbl = NULL;
2137 bnx2fc_free_hash_table(hba);