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)
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 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
;
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
);
239 BNX2FC_HBA_DBG(lport
, "ofld_req: port_id = 0, link down?\n");
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
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 */
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
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
)
292 FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT
);
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];
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];
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
);
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
;
364 memset(&enbl_req
, 0x00,
365 sizeof(struct fcoe_kwqe_conn_enable_disable
));
366 enbl_req
.hdr
.op_code
= FCOE_KWQE_OPCODE_ENABLE_CONN
;
368 (FCOE_KWQE_LAYER_CODE
<< FCOE_KWQE_HEADER_LAYER_CODE_SHIFT
);
370 enbl_req
.src_mac_addr_lo
[0] = port
->data_src_addr
[5];
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
);
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
);
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
;
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];
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
);
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];
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
);
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
);
520 spin_unlock_bh(&hba
->hba_lock
);
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
;
533 unsol_els
= container_of(work
, struct bnx2fc_unsol_els
, unsol_els_work
);
534 lport
= unsol_els
->lport
;
536 hba
= unsol_els
->hba
;
537 if (is_valid_lport(hba
, lport
))
538 fc_exch_recv(lport
, fp
);
542 void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport
*tgt
,
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
;
558 unsol_els
= kzalloc(sizeof(*unsol_els
), GFP_ATOMIC
);
560 BNX2FC_TGT_DBG(tgt
, "Unable to allocate unsol_work\n");
564 BNX2FC_TGT_DBG(tgt
, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
567 payload_len
= frame_len
- sizeof(struct fc_frame_header
);
569 fp
= fc_frame_alloc(lport
, payload_len
);
571 printk(KERN_ERR PFX
"fc_frame_alloc failure\n");
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
);
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
596 printk(KERN_ERR PFX
"dropping ELS 0x%x\n", op
);
602 crc
= fcoe_fc_crc(fp
);
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
;
611 INIT_WORK(&unsol_els
->unsol_els_work
, bnx2fc_unsol_els_work
);
612 queue_work(bnx2fc_wq
, &unsol_els
->unsol_els_work
);
614 BNX2FC_HBA_DBG(lport
, "fh_r_ctl = 0x%x\n", fh
->fh_r_ctl
);
620 static void bnx2fc_process_unsol_compl(struct bnx2fc_rport
*tgt
, u16 wqe
)
623 struct fcoe_err_report_entry
*err_entry
;
624 unsigned char *rq_data
;
625 unsigned char *buf
= NULL
, *buf1
;
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
;
635 u64 err_warn_bit_map
;
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
);
654 buf1
= buf
= kmalloc((num_rq
* BNX2FC_RQ_BUF_SZ
),
658 BNX2FC_TGT_DBG(tgt
, "Memory alloc failure\n");
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
);
672 bnx2fc_process_l2_frame_compl(tgt
, buf
, frame_len
,
677 spin_lock_bh(&tgt
->tgt_lock
);
678 bnx2fc_return_rqe(tgt
, num_rq
);
679 spin_unlock_bh(&tgt
->tgt_lock
);
682 case FCOE_ERROR_DETECTION_CQE_TYPE
:
684 * In case of error reporting CQE a single RQ entry
687 spin_lock_bh(&tgt
->tgt_lock
);
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",
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
];
716 if (io_req
->cmd_type
!= BNX2FC_SCSI_CMD
) {
717 printk(KERN_ERR PFX
"err_warn: Not a SCSI cmd\n");
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");
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
)) {
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
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
);
750 BNX2FC_TGT_DBG(tgt
, "err = 0x%x\n", err_warn
);
751 if (tgt
->dev_type
!= TYPE_TAPE
)
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",
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
);
775 printk(KERN_ERR PFX
"SRR in progress\n");
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
);
793 printk(KERN_ERR PFX
"err_warn: initiate_abts "
794 "failed xid = 0x%x. issue cleanup\n",
796 bnx2fc_initiate_cleanup(io_req
);
799 bnx2fc_return_rqe(tgt
, 1);
800 spin_unlock_bh(&tgt
->tgt_lock
);
803 case FCOE_WARNING_DETECTION_CQE_TYPE
:
805 *In case of warning reporting CQE a single RQ entry
808 spin_lock_bh(&tgt
->tgt_lock
);
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
);
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
)) {
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
];
845 if (io_req
->cmd_type
!= BNX2FC_SCSI_CMD
) {
846 printk(KERN_ERR PFX
"err_warn: Not a SCSI cmd\n");
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 */
859 BNX2FC_TGT_DBG(tgt
, "Unsolicited warning\n");
861 bnx2fc_return_rqe(tgt
, 1);
862 spin_unlock_bh(&tgt
->tgt_lock
);
866 printk(KERN_ERR PFX
"Unsol Compl: Invalid CQE Subtype\n");
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
;
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
);
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
);
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 */
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
);
925 if (rx_state
== FCOE_TASK_RX_STATE_ABTS_COMPLETED
)
926 bnx2fc_process_abts_compl(io_req
, task
, num_rq
);
928 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED
)
929 bnx2fc_process_cleanup_compl(io_req
, task
, num_rq
);
931 printk(KERN_ERR PFX
"Invalid rx state - %d\n",
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
);
942 * ABTS request received by firmware. ABTS response
943 * will be delivered to the task belonging to the IO
946 BNX2FC_IO_DBG(io_req
, "cq_compl- ABTS sent out by fw\n");
947 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
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
);
956 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED
)
957 bnx2fc_process_cleanup_compl(io_req
, task
, num_rq
);
959 printk(KERN_ERR PFX
"Invalid rx state = %d\n",
964 BNX2FC_IO_DBG(io_req
, "cq_compl- cleanup resp rcvd\n");
965 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
968 case BNX2FC_SEQ_CLEANUP
:
969 BNX2FC_IO_DBG(io_req
, "cq_compl(0x%x) - seq cleanup resp\n",
971 bnx2fc_process_seq_cleanup_compl(io_req
, task
, rx_state
);
972 kref_put(&io_req
->refcount
, bnx2fc_cmd_release
);
976 printk(KERN_ERR PFX
"Invalid cmd_type %d\n", cmd_type
);
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
;
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
);
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
);
1003 INIT_LIST_HEAD(&work
->list
);
1009 int bnx2fc_process_new_cqes(struct bnx2fc_rport
*tgt
)
1011 struct fcoe_cqe
*cq
;
1013 struct fcoe_cqe
*cqe
;
1014 u32 num_free_sqes
= 0;
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
);
1026 printk(KERN_ERR PFX
"process_new_cqes: cq is NULL\n");
1027 spin_unlock_bh(&tgt
->cq_lock
);
1031 cq_cons
= tgt
->cq_cons_idx
;
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
);
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
))
1053 work
= bnx2fc_alloc_work(tgt
, wqe
);
1055 list_add_tail(&work
->list
,
1058 spin_unlock_bh(&fps
->fp_work_lock
);
1060 /* Pending work request completion */
1061 if (fps
->iothread
&& work
)
1062 wake_up_process(fps
->iothread
);
1064 bnx2fc_process_cq_compl(tgt
, wqe
);
1071 if (tgt
->cq_cons_idx
== BNX2FC_CQ_WQES_MAX
) {
1072 tgt
->cq_cons_idx
= 0;
1074 tgt
->cq_curr_toggle_bit
=
1075 1 - tgt
->cq_curr_toggle_bit
;
1079 /* Arm CQ only if doorbell is mapped */
1082 atomic_add(num_free_sqes
, &tgt
->free_sqes
);
1084 spin_unlock_bh(&tgt
->cq_lock
);
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
];
1103 printk(KERN_ERR PFX
"conn_id 0x%x not valid\n", conn_id
);
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
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
;
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
];
1133 printk(KERN_ALERT PFX
"ERROR:ofld_cmpl: No pending ofld req\n");
1136 BNX2FC_TGT_DBG(tgt
, "Entered ofld compl - context_id = 0x%x\n",
1137 ofld_kcqe
->fcoe_conn_context_id
);
1139 interface
= tgt
->port
->priv
;
1140 if (hba
!= interface
->hba
) {
1141 printk(KERN_ERR PFX
"ERROR:ofld_cmpl: HBA mis-match\n");
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 "
1154 set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE
, &tgt
->flags
);
1159 /* now enable the session */
1160 rc
= bnx2fc_send_session_enable_req(port
, tgt
);
1162 printk(KERN_ERR PFX
"enable session failed\n");
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
;
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
];
1193 printk(KERN_ERR PFX
"ERROR:enbl_cmpl: No pending ofld req\n");
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
1204 if (tgt
->context_id
!= context_id
) {
1205 printk(KERN_ERR PFX
"context id mis-match\n");
1208 interface
= tgt
->port
->priv
;
1209 if (hba
!= interface
->hba
) {
1210 printk(KERN_ERR PFX
"bnx2fc-enbl_cmpl: HBA mis-match\n");
1213 if (ofld_kcqe
->completion_status
)
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
);
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
;
1235 conn_id
= disable_kcqe
->fcoe_conn_id
;
1236 tgt
= hba
->tgt_ofld_list
[conn_id
];
1238 printk(KERN_ERR PFX
"ERROR: disable_cmpl: No disable req\n");
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 set_bit(BNX2FC_FLAG_DISABLE_FAILED
, &tgt
->flags
);
1248 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
1249 wake_up_interruptible(&tgt
->upld_wait
);
1251 /* disable successful */
1252 BNX2FC_TGT_DBG(tgt
, "disable successful\n");
1253 clear_bit(BNX2FC_FLAG_OFFLOADED
, &tgt
->flags
);
1254 set_bit(BNX2FC_FLAG_DISABLED
, &tgt
->flags
);
1255 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
1256 wake_up_interruptible(&tgt
->upld_wait
);
1260 static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba
*hba
,
1261 struct fcoe_kcqe
*destroy_kcqe
)
1263 struct bnx2fc_rport
*tgt
;
1266 conn_id
= destroy_kcqe
->fcoe_conn_id
;
1267 tgt
= hba
->tgt_ofld_list
[conn_id
];
1269 printk(KERN_ERR PFX
"destroy_cmpl: No destroy req\n");
1273 BNX2FC_TGT_DBG(tgt
, "destroy_cmpl: conn_id %d\n", conn_id
);
1275 if (destroy_kcqe
->completion_status
) {
1276 printk(KERN_ERR PFX
"Destroy conn failed, cmpl status %d\n",
1277 destroy_kcqe
->completion_status
);
1280 /* destroy successful */
1281 BNX2FC_TGT_DBG(tgt
, "upload successful\n");
1282 clear_bit(BNX2FC_FLAG_DISABLED
, &tgt
->flags
);
1283 set_bit(BNX2FC_FLAG_DESTROYED
, &tgt
->flags
);
1284 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL
, &tgt
->flags
);
1285 wake_up_interruptible(&tgt
->upld_wait
);
1289 static void bnx2fc_init_failure(struct bnx2fc_hba
*hba
, u32 err_code
)
1292 case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE
:
1293 printk(KERN_ERR PFX
"init_failure due to invalid opcode\n");
1296 case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
:
1297 printk(KERN_ERR PFX
"init failed due to ctx alloc failure\n");
1300 case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR
:
1301 printk(KERN_ERR PFX
"init_failure due to NIC error\n");
1303 case FCOE_KCQE_COMPLETION_STATUS_ERROR
:
1304 printk(KERN_ERR PFX
"init failure due to compl status err\n");
1306 case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION
:
1307 printk(KERN_ERR PFX
"init failure due to HSI mismatch\n");
1310 printk(KERN_ERR PFX
"Unknown Error code %d\n", err_code
);
1315 * bnx2fc_indicae_kcqe - process KCQE
1317 * @hba: adapter structure pointer
1318 * @kcqe: kcqe pointer
1319 * @num_cqe: Number of completion queue elements
1321 * Generic KCQ event handler
1323 void bnx2fc_indicate_kcqe(void *context
, struct kcqe
*kcq
[],
1326 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
1328 struct fcoe_kcqe
*kcqe
= NULL
;
1330 while (i
< num_cqe
) {
1331 kcqe
= (struct fcoe_kcqe
*) kcq
[i
++];
1333 switch (kcqe
->op_code
) {
1334 case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION
:
1335 bnx2fc_fastpath_notification(hba
, kcqe
);
1338 case FCOE_KCQE_OPCODE_OFFLOAD_CONN
:
1339 bnx2fc_process_ofld_cmpl(hba
, kcqe
);
1342 case FCOE_KCQE_OPCODE_ENABLE_CONN
:
1343 bnx2fc_process_enable_conn_cmpl(hba
, kcqe
);
1346 case FCOE_KCQE_OPCODE_INIT_FUNC
:
1347 if (kcqe
->completion_status
!=
1348 FCOE_KCQE_COMPLETION_STATUS_SUCCESS
) {
1349 bnx2fc_init_failure(hba
,
1350 kcqe
->completion_status
);
1352 set_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1353 bnx2fc_get_link_state(hba
);
1354 printk(KERN_INFO PFX
"[%.2x]: FCOE_INIT passed\n",
1355 (u8
)hba
->pcidev
->bus
->number
);
1359 case FCOE_KCQE_OPCODE_DESTROY_FUNC
:
1360 if (kcqe
->completion_status
!=
1361 FCOE_KCQE_COMPLETION_STATUS_SUCCESS
) {
1363 printk(KERN_ERR PFX
"DESTROY failed\n");
1365 printk(KERN_ERR PFX
"DESTROY success\n");
1367 set_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
1368 wake_up_interruptible(&hba
->destroy_wait
);
1371 case FCOE_KCQE_OPCODE_DISABLE_CONN
:
1372 bnx2fc_process_conn_disable_cmpl(hba
, kcqe
);
1375 case FCOE_KCQE_OPCODE_DESTROY_CONN
:
1376 bnx2fc_process_conn_destroy_cmpl(hba
, kcqe
);
1379 case FCOE_KCQE_OPCODE_STAT_FUNC
:
1380 if (kcqe
->completion_status
!=
1381 FCOE_KCQE_COMPLETION_STATUS_SUCCESS
)
1382 printk(KERN_ERR PFX
"STAT failed\n");
1383 complete(&hba
->stat_req_done
);
1386 case FCOE_KCQE_OPCODE_FCOE_ERROR
:
1389 printk(KERN_ERR PFX
"unknown opcode 0x%x\n",
1395 void bnx2fc_add_2_sq(struct bnx2fc_rport
*tgt
, u16 xid
)
1397 struct fcoe_sqe
*sqe
;
1399 sqe
= &tgt
->sq
[tgt
->sq_prod_idx
];
1402 sqe
->wqe
= xid
<< FCOE_SQE_TASK_ID_SHIFT
;
1403 sqe
->wqe
|= tgt
->sq_curr_toggle_bit
<< FCOE_SQE_TOGGLE_BIT_SHIFT
;
1405 /* Advance SQ Prod Idx */
1406 if (++tgt
->sq_prod_idx
== BNX2FC_SQ_WQES_MAX
) {
1407 tgt
->sq_prod_idx
= 0;
1408 tgt
->sq_curr_toggle_bit
= 1 - tgt
->sq_curr_toggle_bit
;
1412 void bnx2fc_ring_doorbell(struct bnx2fc_rport
*tgt
)
1414 struct b577xx_doorbell_set_prod
*sq_db
= &tgt
->sq_db
;
1418 sq_db
->prod
= tgt
->sq_prod_idx
|
1419 (tgt
->sq_curr_toggle_bit
<< 15);
1420 msg
= *((u32
*)sq_db
);
1421 writel(cpu_to_le32(msg
), tgt
->ctx_base
);
1426 int bnx2fc_map_doorbell(struct bnx2fc_rport
*tgt
)
1428 u32 context_id
= tgt
->context_id
;
1429 struct fcoe_port
*port
= tgt
->port
;
1431 resource_size_t reg_base
;
1432 struct bnx2fc_interface
*interface
= port
->priv
;
1433 struct bnx2fc_hba
*hba
= interface
->hba
;
1435 reg_base
= pci_resource_start(hba
->pcidev
,
1436 BNX2X_DOORBELL_PCI_BAR
);
1437 reg_off
= BNX2FC_5771X_DB_PAGE_SIZE
*
1438 (context_id
& 0x1FFFF) + DPM_TRIGER_TYPE
;
1439 tgt
->ctx_base
= ioremap_nocache(reg_base
+ reg_off
, 4);
1445 char *bnx2fc_get_next_rqe(struct bnx2fc_rport
*tgt
, u8 num_items
)
1447 char *buf
= (char *)tgt
->rq
+ (tgt
->rq_cons_idx
* BNX2FC_RQ_BUF_SZ
);
1449 if (tgt
->rq_cons_idx
+ num_items
> BNX2FC_RQ_WQES_MAX
)
1452 tgt
->rq_cons_idx
+= num_items
;
1454 if (tgt
->rq_cons_idx
>= BNX2FC_RQ_WQES_MAX
)
1455 tgt
->rq_cons_idx
-= BNX2FC_RQ_WQES_MAX
;
1460 void bnx2fc_return_rqe(struct bnx2fc_rport
*tgt
, u8 num_items
)
1462 /* return the rq buffer */
1463 u32 next_prod_idx
= tgt
->rq_prod_idx
+ num_items
;
1464 if ((next_prod_idx
& 0x7fff) == BNX2FC_RQ_WQES_MAX
) {
1465 /* Wrap around RQ */
1466 next_prod_idx
+= 0x8000 - BNX2FC_RQ_WQES_MAX
;
1468 tgt
->rq_prod_idx
= next_prod_idx
;
1469 tgt
->conn_db
->rq_prod
= tgt
->rq_prod_idx
;
1472 void bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd
*seq_clnp_req
,
1473 struct fcoe_task_ctx_entry
*task
,
1474 struct bnx2fc_cmd
*orig_io_req
,
1477 struct scsi_cmnd
*sc_cmd
= orig_io_req
->sc_cmd
;
1478 struct bnx2fc_rport
*tgt
= seq_clnp_req
->tgt
;
1479 struct bnx2fc_interface
*interface
= tgt
->port
->priv
;
1480 struct fcoe_bd_ctx
*bd
= orig_io_req
->bd_tbl
->bd_tbl
;
1481 struct fcoe_task_ctx_entry
*orig_task
;
1482 struct fcoe_task_ctx_entry
*task_page
;
1483 struct fcoe_ext_mul_sges_ctx
*sgl
;
1484 u8 task_type
= FCOE_TASK_TYPE_SEQUENCE_CLEANUP
;
1486 u16 orig_xid
= orig_io_req
->xid
;
1487 u32 context_id
= tgt
->context_id
;
1488 u64 phys_addr
= (u64
)orig_io_req
->bd_tbl
->bd_tbl_dma
;
1489 u32 orig_offset
= offset
;
1491 int orig_task_idx
, index
;
1494 memset(task
, 0, sizeof(struct fcoe_task_ctx_entry
));
1496 if (sc_cmd
->sc_data_direction
== DMA_TO_DEVICE
)
1497 orig_task_type
= FCOE_TASK_TYPE_WRITE
;
1499 orig_task_type
= FCOE_TASK_TYPE_READ
;
1502 task
->txwr_rxrd
.const_ctx
.tx_flags
=
1503 FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP
<<
1504 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT
;
1506 task
->txwr_rxrd
.const_ctx
.init_flags
= task_type
<<
1507 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT
;
1508 task
->txwr_rxrd
.const_ctx
.init_flags
|= FCOE_TASK_CLASS_TYPE_3
<<
1509 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT
;
1510 task
->rxwr_txrd
.const_ctx
.init_flags
= context_id
<<
1511 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT
;
1512 task
->rxwr_txrd
.const_ctx
.init_flags
= context_id
<<
1513 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT
;
1515 task
->txwr_rxrd
.union_ctx
.cleanup
.ctx
.cleaned_task_id
= orig_xid
;
1517 task
->txwr_rxrd
.union_ctx
.cleanup
.ctx
.rolled_tx_seq_cnt
= 0;
1518 task
->txwr_rxrd
.union_ctx
.cleanup
.ctx
.rolled_tx_data_offset
= offset
;
1520 bd_count
= orig_io_req
->bd_tbl
->bd_valid
;
1522 /* obtain the appropriate bd entry from relative offset */
1523 for (i
= 0; i
< bd_count
; i
++) {
1524 if (offset
< bd
[i
].buf_len
)
1526 offset
-= bd
[i
].buf_len
;
1528 phys_addr
+= (i
* sizeof(struct fcoe_bd_ctx
));
1530 if (orig_task_type
== FCOE_TASK_TYPE_WRITE
) {
1531 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_addr
.lo
=
1533 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_addr
.hi
=
1534 (u32
)((u64
)phys_addr
>> 32);
1535 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.sgl_size
=
1537 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_off
=
1538 offset
; /* adjusted offset */
1539 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_idx
= i
;
1541 orig_task_idx
= orig_xid
/ BNX2FC_TASKS_PER_PAGE
;
1542 index
= orig_xid
% BNX2FC_TASKS_PER_PAGE
;
1544 task_page
= (struct fcoe_task_ctx_entry
*)
1545 interface
->hba
->task_ctx
[orig_task_idx
];
1546 orig_task
= &(task_page
[index
]);
1548 /* Multiple SGEs were used for this IO */
1549 sgl
= &task
->rxwr_only
.union_ctx
.read_info
.sgl_ctx
.sgl
;
1550 sgl
->mul_sgl
.cur_sge_addr
.lo
= (u32
)phys_addr
;
1551 sgl
->mul_sgl
.cur_sge_addr
.hi
= (u32
)((u64
)phys_addr
>> 32);
1552 sgl
->mul_sgl
.sgl_size
= bd_count
;
1553 sgl
->mul_sgl
.cur_sge_off
= offset
; /*adjusted offset */
1554 sgl
->mul_sgl
.cur_sge_idx
= i
;
1556 memset(&task
->rxwr_only
.rx_seq_ctx
, 0,
1557 sizeof(struct fcoe_rx_seq_ctx
));
1558 task
->rxwr_only
.rx_seq_ctx
.low_exp_ro
= orig_offset
;
1559 task
->rxwr_only
.rx_seq_ctx
.high_exp_ro
= orig_offset
;
1562 void bnx2fc_init_cleanup_task(struct bnx2fc_cmd
*io_req
,
1563 struct fcoe_task_ctx_entry
*task
,
1566 u8 task_type
= FCOE_TASK_TYPE_EXCHANGE_CLEANUP
;
1567 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1568 u32 context_id
= tgt
->context_id
;
1570 memset(task
, 0, sizeof(struct fcoe_task_ctx_entry
));
1572 /* Tx Write Rx Read */
1574 task
->txwr_rxrd
.const_ctx
.init_flags
= task_type
<<
1575 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT
;
1576 task
->txwr_rxrd
.const_ctx
.init_flags
|= FCOE_TASK_CLASS_TYPE_3
<<
1577 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT
;
1578 if (tgt
->dev_type
== TYPE_TAPE
)
1579 task
->txwr_rxrd
.const_ctx
.init_flags
|=
1580 FCOE_TASK_DEV_TYPE_TAPE
<<
1581 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT
;
1583 task
->txwr_rxrd
.const_ctx
.init_flags
|=
1584 FCOE_TASK_DEV_TYPE_DISK
<<
1585 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT
;
1586 task
->txwr_rxrd
.union_ctx
.cleanup
.ctx
.cleaned_task_id
= orig_xid
;
1589 task
->txwr_rxrd
.const_ctx
.tx_flags
=
1590 FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP
<<
1591 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT
;
1593 /* Rx Read Tx Write */
1594 task
->rxwr_txrd
.const_ctx
.init_flags
= context_id
<<
1595 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT
;
1596 task
->rxwr_txrd
.var_ctx
.rx_flags
|= 1 <<
1597 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT
;
1600 void bnx2fc_init_mp_task(struct bnx2fc_cmd
*io_req
,
1601 struct fcoe_task_ctx_entry
*task
)
1603 struct bnx2fc_mp_req
*mp_req
= &(io_req
->mp_req
);
1604 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1605 struct fc_frame_header
*fc_hdr
;
1606 struct fcoe_ext_mul_sges_ctx
*sgl
;
1613 /* Obtain task_type */
1614 if ((io_req
->cmd_type
== BNX2FC_TASK_MGMT_CMD
) ||
1615 (io_req
->cmd_type
== BNX2FC_ELS
)) {
1616 task_type
= FCOE_TASK_TYPE_MIDPATH
;
1617 } else if (io_req
->cmd_type
== BNX2FC_ABTS
) {
1618 task_type
= FCOE_TASK_TYPE_ABTS
;
1621 memset(task
, 0, sizeof(struct fcoe_task_ctx_entry
));
1623 /* Setup the task from io_req for easy reference */
1624 io_req
->task
= task
;
1626 BNX2FC_IO_DBG(io_req
, "Init MP task for cmd_type = %d task_type = %d\n",
1627 io_req
->cmd_type
, task_type
);
1630 if ((task_type
== FCOE_TASK_TYPE_MIDPATH
) ||
1631 (task_type
== FCOE_TASK_TYPE_UNSOLICITED
)) {
1632 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_addr
.lo
=
1633 (u32
)mp_req
->mp_req_bd_dma
;
1634 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_addr
.hi
=
1635 (u32
)((u64
)mp_req
->mp_req_bd_dma
>> 32);
1636 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.sgl_size
= 1;
1639 /* Tx Write Rx Read */
1641 task
->txwr_rxrd
.const_ctx
.init_flags
= task_type
<<
1642 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT
;
1643 if (tgt
->dev_type
== TYPE_TAPE
)
1644 task
->txwr_rxrd
.const_ctx
.init_flags
|=
1645 FCOE_TASK_DEV_TYPE_TAPE
<<
1646 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT
;
1648 task
->txwr_rxrd
.const_ctx
.init_flags
|=
1649 FCOE_TASK_DEV_TYPE_DISK
<<
1650 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT
;
1651 task
->txwr_rxrd
.const_ctx
.init_flags
|= FCOE_TASK_CLASS_TYPE_3
<<
1652 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT
;
1655 task
->txwr_rxrd
.const_ctx
.tx_flags
= FCOE_TASK_TX_STATE_INIT
<<
1656 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT
;
1658 /* Rx Write Tx Read */
1659 task
->rxwr_txrd
.const_ctx
.data_2_trns
= io_req
->data_xfer_len
;
1662 task
->rxwr_txrd
.var_ctx
.rx_flags
|= 1 <<
1663 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT
;
1665 context_id
= tgt
->context_id
;
1666 task
->rxwr_txrd
.const_ctx
.init_flags
= context_id
<<
1667 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT
;
1669 fc_hdr
= &(mp_req
->req_fc_hdr
);
1670 if (task_type
== FCOE_TASK_TYPE_MIDPATH
) {
1671 fc_hdr
->fh_ox_id
= cpu_to_be16(io_req
->xid
);
1672 fc_hdr
->fh_rx_id
= htons(0xffff);
1673 task
->rxwr_txrd
.var_ctx
.rx_id
= 0xffff;
1674 } else if (task_type
== FCOE_TASK_TYPE_UNSOLICITED
) {
1675 fc_hdr
->fh_rx_id
= cpu_to_be16(io_req
->xid
);
1678 /* Fill FC Header into middle path buffer */
1679 hdr
= (u64
*) &task
->txwr_rxrd
.union_ctx
.tx_frame
.fc_hdr
;
1680 memcpy(temp_hdr
, fc_hdr
, sizeof(temp_hdr
));
1681 hdr
[0] = cpu_to_be64(temp_hdr
[0]);
1682 hdr
[1] = cpu_to_be64(temp_hdr
[1]);
1683 hdr
[2] = cpu_to_be64(temp_hdr
[2]);
1686 if (task_type
== FCOE_TASK_TYPE_MIDPATH
) {
1687 sgl
= &task
->rxwr_only
.union_ctx
.read_info
.sgl_ctx
.sgl
;
1689 sgl
->mul_sgl
.cur_sge_addr
.lo
= (u32
)mp_req
->mp_resp_bd_dma
;
1690 sgl
->mul_sgl
.cur_sge_addr
.hi
=
1691 (u32
)((u64
)mp_req
->mp_resp_bd_dma
>> 32);
1692 sgl
->mul_sgl
.sgl_size
= 1;
1696 void bnx2fc_init_task(struct bnx2fc_cmd
*io_req
,
1697 struct fcoe_task_ctx_entry
*task
)
1700 struct scsi_cmnd
*sc_cmd
= io_req
->sc_cmd
;
1701 struct io_bdt
*bd_tbl
= io_req
->bd_tbl
;
1702 struct bnx2fc_rport
*tgt
= io_req
->tgt
;
1703 struct fcoe_cached_sge_ctx
*cached_sge
;
1704 struct fcoe_ext_mul_sges_ctx
*sgl
;
1705 int dev_type
= tgt
->dev_type
;
1707 u64 tmp_fcp_cmnd
[4];
1712 memset(task
, 0, sizeof(struct fcoe_task_ctx_entry
));
1714 /* Setup the task from io_req for easy reference */
1715 io_req
->task
= task
;
1717 if (sc_cmd
->sc_data_direction
== DMA_TO_DEVICE
)
1718 task_type
= FCOE_TASK_TYPE_WRITE
;
1720 task_type
= FCOE_TASK_TYPE_READ
;
1723 bd_count
= bd_tbl
->bd_valid
;
1724 cached_sge
= &task
->rxwr_only
.union_ctx
.read_info
.sgl_ctx
.cached_sge
;
1725 if (task_type
== FCOE_TASK_TYPE_WRITE
) {
1726 if ((dev_type
== TYPE_DISK
) && (bd_count
== 1)) {
1727 struct fcoe_bd_ctx
*fcoe_bd_tbl
= bd_tbl
->bd_tbl
;
1729 task
->txwr_only
.sgl_ctx
.cached_sge
.cur_buf_addr
.lo
=
1730 cached_sge
->cur_buf_addr
.lo
=
1731 fcoe_bd_tbl
->buf_addr_lo
;
1732 task
->txwr_only
.sgl_ctx
.cached_sge
.cur_buf_addr
.hi
=
1733 cached_sge
->cur_buf_addr
.hi
=
1734 fcoe_bd_tbl
->buf_addr_hi
;
1735 task
->txwr_only
.sgl_ctx
.cached_sge
.cur_buf_rem
=
1736 cached_sge
->cur_buf_rem
=
1737 fcoe_bd_tbl
->buf_len
;
1739 task
->txwr_rxrd
.const_ctx
.init_flags
|= 1 <<
1740 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT
;
1742 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_addr
.lo
=
1743 (u32
)bd_tbl
->bd_tbl_dma
;
1744 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.cur_sge_addr
.hi
=
1745 (u32
)((u64
)bd_tbl
->bd_tbl_dma
>> 32);
1746 task
->txwr_only
.sgl_ctx
.sgl
.mul_sgl
.sgl_size
=
1751 /*Tx Write Rx Read */
1752 /* Init state to NORMAL */
1753 task
->txwr_rxrd
.const_ctx
.init_flags
|= task_type
<<
1754 FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT
;
1755 if (dev_type
== TYPE_TAPE
) {
1756 task
->txwr_rxrd
.const_ctx
.init_flags
|=
1757 FCOE_TASK_DEV_TYPE_TAPE
<<
1758 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT
;
1759 io_req
->rec_retry
= 0;
1760 io_req
->rec_retry
= 0;
1762 task
->txwr_rxrd
.const_ctx
.init_flags
|=
1763 FCOE_TASK_DEV_TYPE_DISK
<<
1764 FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT
;
1765 task
->txwr_rxrd
.const_ctx
.init_flags
|= FCOE_TASK_CLASS_TYPE_3
<<
1766 FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT
;
1768 task
->txwr_rxrd
.const_ctx
.tx_flags
= FCOE_TASK_TX_STATE_NORMAL
<<
1769 FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT
;
1771 /* Set initial seq counter */
1772 task
->txwr_rxrd
.union_ctx
.tx_seq
.ctx
.seq_cnt
= 1;
1774 /* Fill FCP_CMND IU */
1776 task
->txwr_rxrd
.union_ctx
.fcp_cmd
.opaque
;
1777 bnx2fc_build_fcp_cmnd(io_req
, (struct fcp_cmnd
*)&tmp_fcp_cmnd
);
1780 cnt
= sizeof(struct fcp_cmnd
) / sizeof(u64
);
1782 for (i
= 0; i
< cnt
; i
++) {
1783 *fcp_cmnd
= cpu_to_be64(tmp_fcp_cmnd
[i
]);
1787 /* Rx Write Tx Read */
1788 task
->rxwr_txrd
.const_ctx
.data_2_trns
= io_req
->data_xfer_len
;
1790 context_id
= tgt
->context_id
;
1791 task
->rxwr_txrd
.const_ctx
.init_flags
= context_id
<<
1792 FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT
;
1795 /* Set state to "waiting for the first packet" */
1796 task
->rxwr_txrd
.var_ctx
.rx_flags
|= 1 <<
1797 FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT
;
1799 task
->rxwr_txrd
.var_ctx
.rx_id
= 0xffff;
1802 if (task_type
!= FCOE_TASK_TYPE_READ
)
1805 sgl
= &task
->rxwr_only
.union_ctx
.read_info
.sgl_ctx
.sgl
;
1806 bd_count
= bd_tbl
->bd_valid
;
1808 if (dev_type
== TYPE_DISK
) {
1809 if (bd_count
== 1) {
1811 struct fcoe_bd_ctx
*fcoe_bd_tbl
= bd_tbl
->bd_tbl
;
1813 cached_sge
->cur_buf_addr
.lo
= fcoe_bd_tbl
->buf_addr_lo
;
1814 cached_sge
->cur_buf_addr
.hi
= fcoe_bd_tbl
->buf_addr_hi
;
1815 cached_sge
->cur_buf_rem
= fcoe_bd_tbl
->buf_len
;
1816 task
->txwr_rxrd
.const_ctx
.init_flags
|= 1 <<
1817 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT
;
1818 } else if (bd_count
== 2) {
1819 struct fcoe_bd_ctx
*fcoe_bd_tbl
= bd_tbl
->bd_tbl
;
1821 cached_sge
->cur_buf_addr
.lo
= fcoe_bd_tbl
->buf_addr_lo
;
1822 cached_sge
->cur_buf_addr
.hi
= fcoe_bd_tbl
->buf_addr_hi
;
1823 cached_sge
->cur_buf_rem
= fcoe_bd_tbl
->buf_len
;
1826 cached_sge
->second_buf_addr
.lo
=
1827 fcoe_bd_tbl
->buf_addr_lo
;
1828 cached_sge
->second_buf_addr
.hi
=
1829 fcoe_bd_tbl
->buf_addr_hi
;
1830 cached_sge
->second_buf_rem
= fcoe_bd_tbl
->buf_len
;
1831 task
->txwr_rxrd
.const_ctx
.init_flags
|= 1 <<
1832 FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT
;
1835 sgl
->mul_sgl
.cur_sge_addr
.lo
= (u32
)bd_tbl
->bd_tbl_dma
;
1836 sgl
->mul_sgl
.cur_sge_addr
.hi
=
1837 (u32
)((u64
)bd_tbl
->bd_tbl_dma
>> 32);
1838 sgl
->mul_sgl
.sgl_size
= bd_count
;
1841 sgl
->mul_sgl
.cur_sge_addr
.lo
= (u32
)bd_tbl
->bd_tbl_dma
;
1842 sgl
->mul_sgl
.cur_sge_addr
.hi
=
1843 (u32
)((u64
)bd_tbl
->bd_tbl_dma
>> 32);
1844 sgl
->mul_sgl
.sgl_size
= bd_count
;
1849 * bnx2fc_setup_task_ctx - allocate and map task context
1851 * @hba: pointer to adapter structure
1853 * allocate memory for task context, and associated BD table to be used
1857 int bnx2fc_setup_task_ctx(struct bnx2fc_hba
*hba
)
1860 struct regpair
*task_ctx_bdt
;
1865 * Allocate task context bd table. A page size of bd table
1866 * can map 256 buffers. Each buffer contains 32 task context
1867 * entries. Hence the limit with one page is 8192 task context
1870 hba
->task_ctx_bd_tbl
= dma_alloc_coherent(&hba
->pcidev
->dev
,
1872 &hba
->task_ctx_bd_dma
,
1874 if (!hba
->task_ctx_bd_tbl
) {
1875 printk(KERN_ERR PFX
"unable to allocate task context BDT\n");
1879 memset(hba
->task_ctx_bd_tbl
, 0, PAGE_SIZE
);
1882 * Allocate task_ctx which is an array of pointers pointing to
1883 * a page containing 32 task contexts
1885 hba
->task_ctx
= kzalloc((BNX2FC_TASK_CTX_ARR_SZ
* sizeof(void *)),
1887 if (!hba
->task_ctx
) {
1888 printk(KERN_ERR PFX
"unable to allocate task context array\n");
1894 * Allocate task_ctx_dma which is an array of dma addresses
1896 hba
->task_ctx_dma
= kmalloc((BNX2FC_TASK_CTX_ARR_SZ
*
1897 sizeof(dma_addr_t
)), GFP_KERNEL
);
1898 if (!hba
->task_ctx_dma
) {
1899 printk(KERN_ERR PFX
"unable to alloc context mapping array\n");
1904 task_ctx_bdt
= (struct regpair
*)hba
->task_ctx_bd_tbl
;
1905 for (i
= 0; i
< BNX2FC_TASK_CTX_ARR_SZ
; i
++) {
1907 hba
->task_ctx
[i
] = dma_alloc_coherent(&hba
->pcidev
->dev
,
1909 &hba
->task_ctx_dma
[i
],
1911 if (!hba
->task_ctx
[i
]) {
1912 printk(KERN_ERR PFX
"unable to alloc task context\n");
1916 memset(hba
->task_ctx
[i
], 0, PAGE_SIZE
);
1917 addr
= (u64
)hba
->task_ctx_dma
[i
];
1918 task_ctx_bdt
->hi
= cpu_to_le32((u64
)addr
>> 32);
1919 task_ctx_bdt
->lo
= cpu_to_le32((u32
)addr
);
1925 for (i
= 0; i
< BNX2FC_TASK_CTX_ARR_SZ
; i
++) {
1926 if (hba
->task_ctx
[i
]) {
1928 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
1929 hba
->task_ctx
[i
], hba
->task_ctx_dma
[i
]);
1930 hba
->task_ctx
[i
] = NULL
;
1934 kfree(hba
->task_ctx_dma
);
1935 hba
->task_ctx_dma
= NULL
;
1937 kfree(hba
->task_ctx
);
1938 hba
->task_ctx
= NULL
;
1940 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
1941 hba
->task_ctx_bd_tbl
, hba
->task_ctx_bd_dma
);
1942 hba
->task_ctx_bd_tbl
= NULL
;
1947 void bnx2fc_free_task_ctx(struct bnx2fc_hba
*hba
)
1951 if (hba
->task_ctx_bd_tbl
) {
1952 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
1953 hba
->task_ctx_bd_tbl
,
1954 hba
->task_ctx_bd_dma
);
1955 hba
->task_ctx_bd_tbl
= NULL
;
1958 if (hba
->task_ctx
) {
1959 for (i
= 0; i
< BNX2FC_TASK_CTX_ARR_SZ
; i
++) {
1960 if (hba
->task_ctx
[i
]) {
1961 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
1963 hba
->task_ctx_dma
[i
]);
1964 hba
->task_ctx
[i
] = NULL
;
1967 kfree(hba
->task_ctx
);
1968 hba
->task_ctx
= NULL
;
1971 kfree(hba
->task_ctx_dma
);
1972 hba
->task_ctx_dma
= NULL
;
1975 static void bnx2fc_free_hash_table(struct bnx2fc_hba
*hba
)
1979 int hash_table_size
;
1982 segment_count
= hba
->hash_tbl_segment_count
;
1983 hash_table_size
= BNX2FC_NUM_MAX_SESS
* BNX2FC_MAX_ROWS_IN_HASH_TBL
*
1984 sizeof(struct fcoe_hash_table_entry
);
1986 pbl
= hba
->hash_tbl_pbl
;
1987 for (i
= 0; i
< segment_count
; ++i
) {
1988 dma_addr_t dma_address
;
1990 dma_address
= le32_to_cpu(*pbl
);
1992 dma_address
+= ((u64
)le32_to_cpu(*pbl
)) << 32;
1994 dma_free_coherent(&hba
->pcidev
->dev
,
1995 BNX2FC_HASH_TBL_CHUNK_SIZE
,
1996 hba
->hash_tbl_segments
[i
],
2001 if (hba
->hash_tbl_pbl
) {
2002 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
2004 hba
->hash_tbl_pbl_dma
);
2005 hba
->hash_tbl_pbl
= NULL
;
2009 static int bnx2fc_allocate_hash_table(struct bnx2fc_hba
*hba
)
2012 int hash_table_size
;
2014 int segment_array_size
;
2015 int dma_segment_array_size
;
2016 dma_addr_t
*dma_segment_array
;
2019 hash_table_size
= BNX2FC_NUM_MAX_SESS
* BNX2FC_MAX_ROWS_IN_HASH_TBL
*
2020 sizeof(struct fcoe_hash_table_entry
);
2022 segment_count
= hash_table_size
+ BNX2FC_HASH_TBL_CHUNK_SIZE
- 1;
2023 segment_count
/= BNX2FC_HASH_TBL_CHUNK_SIZE
;
2024 hba
->hash_tbl_segment_count
= segment_count
;
2026 segment_array_size
= segment_count
* sizeof(*hba
->hash_tbl_segments
);
2027 hba
->hash_tbl_segments
= kzalloc(segment_array_size
, GFP_KERNEL
);
2028 if (!hba
->hash_tbl_segments
) {
2029 printk(KERN_ERR PFX
"hash table pointers alloc failed\n");
2032 dma_segment_array_size
= segment_count
* sizeof(*dma_segment_array
);
2033 dma_segment_array
= kzalloc(dma_segment_array_size
, GFP_KERNEL
);
2034 if (!dma_segment_array
) {
2035 printk(KERN_ERR PFX
"hash table pointers (dma) alloc failed\n");
2039 for (i
= 0; i
< segment_count
; ++i
) {
2040 hba
->hash_tbl_segments
[i
] =
2041 dma_alloc_coherent(&hba
->pcidev
->dev
,
2042 BNX2FC_HASH_TBL_CHUNK_SIZE
,
2043 &dma_segment_array
[i
],
2045 if (!hba
->hash_tbl_segments
[i
]) {
2046 printk(KERN_ERR PFX
"hash segment alloc failed\n");
2048 dma_free_coherent(&hba
->pcidev
->dev
,
2049 BNX2FC_HASH_TBL_CHUNK_SIZE
,
2050 hba
->hash_tbl_segments
[i
],
2051 dma_segment_array
[i
]);
2052 hba
->hash_tbl_segments
[i
] = NULL
;
2054 kfree(dma_segment_array
);
2057 memset(hba
->hash_tbl_segments
[i
], 0,
2058 BNX2FC_HASH_TBL_CHUNK_SIZE
);
2061 hba
->hash_tbl_pbl
= dma_alloc_coherent(&hba
->pcidev
->dev
,
2063 &hba
->hash_tbl_pbl_dma
,
2065 if (!hba
->hash_tbl_pbl
) {
2066 printk(KERN_ERR PFX
"hash table pbl alloc failed\n");
2067 kfree(dma_segment_array
);
2070 memset(hba
->hash_tbl_pbl
, 0, PAGE_SIZE
);
2072 pbl
= hba
->hash_tbl_pbl
;
2073 for (i
= 0; i
< segment_count
; ++i
) {
2074 u64 paddr
= dma_segment_array
[i
];
2075 *pbl
= cpu_to_le32((u32
) paddr
);
2077 *pbl
= cpu_to_le32((u32
) (paddr
>> 32));
2080 pbl
= hba
->hash_tbl_pbl
;
2082 while (*pbl
&& *(pbl
+ 1)) {
2091 kfree(dma_segment_array
);
2096 * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
2098 * @hba: Pointer to adapter structure
2101 int bnx2fc_setup_fw_resc(struct bnx2fc_hba
*hba
)
2107 if (bnx2fc_allocate_hash_table(hba
))
2110 mem_size
= BNX2FC_NUM_MAX_SESS
* sizeof(struct regpair
);
2111 hba
->t2_hash_tbl_ptr
= dma_alloc_coherent(&hba
->pcidev
->dev
, mem_size
,
2112 &hba
->t2_hash_tbl_ptr_dma
,
2114 if (!hba
->t2_hash_tbl_ptr
) {
2115 printk(KERN_ERR PFX
"unable to allocate t2 hash table ptr\n");
2116 bnx2fc_free_fw_resc(hba
);
2119 memset(hba
->t2_hash_tbl_ptr
, 0x00, mem_size
);
2121 mem_size
= BNX2FC_NUM_MAX_SESS
*
2122 sizeof(struct fcoe_t2_hash_table_entry
);
2123 hba
->t2_hash_tbl
= dma_alloc_coherent(&hba
->pcidev
->dev
, mem_size
,
2124 &hba
->t2_hash_tbl_dma
,
2126 if (!hba
->t2_hash_tbl
) {
2127 printk(KERN_ERR PFX
"unable to allocate t2 hash table\n");
2128 bnx2fc_free_fw_resc(hba
);
2131 memset(hba
->t2_hash_tbl
, 0x00, mem_size
);
2132 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
2133 addr
= (unsigned long) hba
->t2_hash_tbl_dma
+
2134 ((i
+1) * sizeof(struct fcoe_t2_hash_table_entry
));
2135 hba
->t2_hash_tbl
[i
].next
.lo
= addr
& 0xffffffff;
2136 hba
->t2_hash_tbl
[i
].next
.hi
= addr
>> 32;
2139 hba
->dummy_buffer
= dma_alloc_coherent(&hba
->pcidev
->dev
,
2140 PAGE_SIZE
, &hba
->dummy_buf_dma
,
2142 if (!hba
->dummy_buffer
) {
2143 printk(KERN_ERR PFX
"unable to alloc MP Dummy Buffer\n");
2144 bnx2fc_free_fw_resc(hba
);
2148 hba
->stats_buffer
= dma_alloc_coherent(&hba
->pcidev
->dev
,
2150 &hba
->stats_buf_dma
,
2152 if (!hba
->stats_buffer
) {
2153 printk(KERN_ERR PFX
"unable to alloc Stats Buffer\n");
2154 bnx2fc_free_fw_resc(hba
);
2157 memset(hba
->stats_buffer
, 0x00, PAGE_SIZE
);
2162 void bnx2fc_free_fw_resc(struct bnx2fc_hba
*hba
)
2166 if (hba
->stats_buffer
) {
2167 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
2168 hba
->stats_buffer
, hba
->stats_buf_dma
);
2169 hba
->stats_buffer
= NULL
;
2172 if (hba
->dummy_buffer
) {
2173 dma_free_coherent(&hba
->pcidev
->dev
, PAGE_SIZE
,
2174 hba
->dummy_buffer
, hba
->dummy_buf_dma
);
2175 hba
->dummy_buffer
= NULL
;
2178 if (hba
->t2_hash_tbl_ptr
) {
2179 mem_size
= BNX2FC_NUM_MAX_SESS
* sizeof(struct regpair
);
2180 dma_free_coherent(&hba
->pcidev
->dev
, mem_size
,
2181 hba
->t2_hash_tbl_ptr
,
2182 hba
->t2_hash_tbl_ptr_dma
);
2183 hba
->t2_hash_tbl_ptr
= NULL
;
2186 if (hba
->t2_hash_tbl
) {
2187 mem_size
= BNX2FC_NUM_MAX_SESS
*
2188 sizeof(struct fcoe_t2_hash_table_entry
);
2189 dma_free_coherent(&hba
->pcidev
->dev
, mem_size
,
2190 hba
->t2_hash_tbl
, hba
->t2_hash_tbl_dma
);
2191 hba
->t2_hash_tbl
= NULL
;
2193 bnx2fc_free_hash_table(hba
);