1 // SPDX-License-Identifier: GPL-2.0-only
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
16 bna_ib_coalescing_timeo_set(struct bna_ib
*ib
, u8 coalescing_timeo
)
18 ib
->coalescing_timeo
= coalescing_timeo
;
19 ib
->door_bell
.doorbell_ack
= BNA_DOORBELL_IB_INT_ACK(
20 (u32
)ib
->coalescing_timeo
, 0);
25 #define bna_rxf_vlan_cfg_soft_reset(rxf) \
27 (rxf)->vlan_pending_bitmask = (u8)BFI_VLAN_BMASK_ALL; \
28 (rxf)->vlan_strip_pending = true; \
31 #define bna_rxf_rss_cfg_soft_reset(rxf) \
33 if ((rxf)->rss_status == BNA_STATUS_T_ENABLED) \
34 (rxf)->rss_pending = (BNA_RSS_F_RIT_PENDING | \
35 BNA_RSS_F_CFG_PENDING | \
36 BNA_RSS_F_STATUS_PENDING); \
39 static int bna_rxf_cfg_apply(struct bna_rxf
*rxf
);
40 static void bna_rxf_cfg_reset(struct bna_rxf
*rxf
);
41 static int bna_rxf_ucast_cfg_apply(struct bna_rxf
*rxf
);
42 static int bna_rxf_promisc_cfg_apply(struct bna_rxf
*rxf
);
43 static int bna_rxf_allmulti_cfg_apply(struct bna_rxf
*rxf
);
44 static int bna_rxf_vlan_strip_cfg_apply(struct bna_rxf
*rxf
);
45 static int bna_rxf_ucast_cfg_reset(struct bna_rxf
*rxf
,
46 enum bna_cleanup_type cleanup
);
47 static int bna_rxf_promisc_cfg_reset(struct bna_rxf
*rxf
,
48 enum bna_cleanup_type cleanup
);
49 static int bna_rxf_allmulti_cfg_reset(struct bna_rxf
*rxf
,
50 enum bna_cleanup_type cleanup
);
52 bfa_fsm_state_decl(bna_rxf
, stopped
, struct bna_rxf
,
54 bfa_fsm_state_decl(bna_rxf
, cfg_wait
, struct bna_rxf
,
56 bfa_fsm_state_decl(bna_rxf
, started
, struct bna_rxf
,
58 bfa_fsm_state_decl(bna_rxf
, last_resp_wait
, struct bna_rxf
,
62 bna_rxf_sm_stopped_entry(struct bna_rxf
*rxf
)
64 call_rxf_stop_cbfn(rxf
);
68 bna_rxf_sm_stopped(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
72 bfa_fsm_set_state(rxf
, bna_rxf_sm_cfg_wait
);
76 call_rxf_stop_cbfn(rxf
);
84 call_rxf_cam_fltr_cbfn(rxf
);
93 bna_rxf_sm_cfg_wait_entry(struct bna_rxf
*rxf
)
95 if (!bna_rxf_cfg_apply(rxf
)) {
96 /* No more pending config updates */
97 bfa_fsm_set_state(rxf
, bna_rxf_sm_started
);
102 bna_rxf_sm_cfg_wait(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
106 bfa_fsm_set_state(rxf
, bna_rxf_sm_last_resp_wait
);
110 bna_rxf_cfg_reset(rxf
);
111 call_rxf_start_cbfn(rxf
);
112 call_rxf_cam_fltr_cbfn(rxf
);
113 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
121 if (!bna_rxf_cfg_apply(rxf
)) {
122 /* No more pending config updates */
123 bfa_fsm_set_state(rxf
, bna_rxf_sm_started
);
133 bna_rxf_sm_started_entry(struct bna_rxf
*rxf
)
135 call_rxf_start_cbfn(rxf
);
136 call_rxf_cam_fltr_cbfn(rxf
);
140 bna_rxf_sm_started(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
145 bna_rxf_cfg_reset(rxf
);
146 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
150 bfa_fsm_set_state(rxf
, bna_rxf_sm_cfg_wait
);
159 bna_rxf_sm_last_resp_wait_entry(struct bna_rxf
*rxf
)
164 bna_rxf_sm_last_resp_wait(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
169 bna_rxf_cfg_reset(rxf
);
170 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
179 bna_bfi_ucast_req(struct bna_rxf
*rxf
, struct bna_mac
*mac
,
180 enum bfi_enet_h2i_msgs req_type
)
182 struct bfi_enet_ucast_req
*req
= &rxf
->bfi_enet_cmd
.ucast_req
;
184 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
, req_type
, 0, rxf
->rx
->rid
);
185 req
->mh
.num_entries
= htons(
186 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_ucast_req
)));
187 ether_addr_copy(req
->mac_addr
, mac
->addr
);
188 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
189 sizeof(struct bfi_enet_ucast_req
), &req
->mh
);
190 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
194 bna_bfi_mcast_add_req(struct bna_rxf
*rxf
, struct bna_mac
*mac
)
196 struct bfi_enet_mcast_add_req
*req
=
197 &rxf
->bfi_enet_cmd
.mcast_add_req
;
199 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
, BFI_ENET_H2I_MAC_MCAST_ADD_REQ
,
201 req
->mh
.num_entries
= htons(
202 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_mcast_add_req
)));
203 ether_addr_copy(req
->mac_addr
, mac
->addr
);
204 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
205 sizeof(struct bfi_enet_mcast_add_req
), &req
->mh
);
206 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
210 bna_bfi_mcast_del_req(struct bna_rxf
*rxf
, u16 handle
)
212 struct bfi_enet_mcast_del_req
*req
=
213 &rxf
->bfi_enet_cmd
.mcast_del_req
;
215 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
, BFI_ENET_H2I_MAC_MCAST_DEL_REQ
,
217 req
->mh
.num_entries
= htons(
218 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_mcast_del_req
)));
219 req
->handle
= htons(handle
);
220 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
221 sizeof(struct bfi_enet_mcast_del_req
), &req
->mh
);
222 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
226 bna_bfi_mcast_filter_req(struct bna_rxf
*rxf
, enum bna_status status
)
228 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
230 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
231 BFI_ENET_H2I_MAC_MCAST_FILTER_REQ
, 0, rxf
->rx
->rid
);
232 req
->mh
.num_entries
= htons(
233 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
234 req
->enable
= status
;
235 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
236 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
237 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
241 bna_bfi_rx_promisc_req(struct bna_rxf
*rxf
, enum bna_status status
)
243 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
245 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
246 BFI_ENET_H2I_RX_PROMISCUOUS_REQ
, 0, rxf
->rx
->rid
);
247 req
->mh
.num_entries
= htons(
248 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
249 req
->enable
= status
;
250 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
251 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
252 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
256 bna_bfi_rx_vlan_filter_set(struct bna_rxf
*rxf
, u8 block_idx
)
258 struct bfi_enet_rx_vlan_req
*req
= &rxf
->bfi_enet_cmd
.vlan_req
;
262 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
263 BFI_ENET_H2I_RX_VLAN_SET_REQ
, 0, rxf
->rx
->rid
);
264 req
->mh
.num_entries
= htons(
265 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rx_vlan_req
)));
266 req
->block_idx
= block_idx
;
267 for (i
= 0; i
< (BFI_ENET_VLAN_BLOCK_SIZE
/ 32); i
++) {
268 j
= (block_idx
* (BFI_ENET_VLAN_BLOCK_SIZE
/ 32)) + i
;
269 if (rxf
->vlan_filter_status
== BNA_STATUS_T_ENABLED
)
271 htonl(rxf
->vlan_filter_table
[j
]);
273 req
->bit_mask
[i
] = 0xFFFFFFFF;
275 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
276 sizeof(struct bfi_enet_rx_vlan_req
), &req
->mh
);
277 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
281 bna_bfi_vlan_strip_enable(struct bna_rxf
*rxf
)
283 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
285 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
286 BFI_ENET_H2I_RX_VLAN_STRIP_ENABLE_REQ
, 0, rxf
->rx
->rid
);
287 req
->mh
.num_entries
= htons(
288 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
289 req
->enable
= rxf
->vlan_strip_status
;
290 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
291 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
292 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
296 bna_bfi_rit_cfg(struct bna_rxf
*rxf
)
298 struct bfi_enet_rit_req
*req
= &rxf
->bfi_enet_cmd
.rit_req
;
300 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
301 BFI_ENET_H2I_RIT_CFG_REQ
, 0, rxf
->rx
->rid
);
302 req
->mh
.num_entries
= htons(
303 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rit_req
)));
304 req
->size
= htons(rxf
->rit_size
);
305 memcpy(&req
->table
[0], rxf
->rit
, rxf
->rit_size
);
306 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
307 sizeof(struct bfi_enet_rit_req
), &req
->mh
);
308 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
312 bna_bfi_rss_cfg(struct bna_rxf
*rxf
)
314 struct bfi_enet_rss_cfg_req
*req
= &rxf
->bfi_enet_cmd
.rss_req
;
317 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
318 BFI_ENET_H2I_RSS_CFG_REQ
, 0, rxf
->rx
->rid
);
319 req
->mh
.num_entries
= htons(
320 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rss_cfg_req
)));
321 req
->cfg
.type
= rxf
->rss_cfg
.hash_type
;
322 req
->cfg
.mask
= rxf
->rss_cfg
.hash_mask
;
323 for (i
= 0; i
< BFI_ENET_RSS_KEY_LEN
; i
++)
325 htonl(rxf
->rss_cfg
.toeplitz_hash_key
[i
]);
326 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
327 sizeof(struct bfi_enet_rss_cfg_req
), &req
->mh
);
328 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
332 bna_bfi_rss_enable(struct bna_rxf
*rxf
)
334 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
336 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
337 BFI_ENET_H2I_RSS_ENABLE_REQ
, 0, rxf
->rx
->rid
);
338 req
->mh
.num_entries
= htons(
339 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
340 req
->enable
= rxf
->rss_status
;
341 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
342 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
343 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
346 /* This function gets the multicast MAC that has already been added to CAM */
347 static struct bna_mac
*
348 bna_rxf_mcmac_get(struct bna_rxf
*rxf
, const u8
*mac_addr
)
352 list_for_each_entry(mac
, &rxf
->mcast_active_q
, qe
)
353 if (ether_addr_equal(mac
->addr
, mac_addr
))
356 list_for_each_entry(mac
, &rxf
->mcast_pending_del_q
, qe
)
357 if (ether_addr_equal(mac
->addr
, mac_addr
))
363 static struct bna_mcam_handle
*
364 bna_rxf_mchandle_get(struct bna_rxf
*rxf
, int handle
)
366 struct bna_mcam_handle
*mchandle
;
368 list_for_each_entry(mchandle
, &rxf
->mcast_handle_q
, qe
)
369 if (mchandle
->handle
== handle
)
376 bna_rxf_mchandle_attach(struct bna_rxf
*rxf
, u8
*mac_addr
, int handle
)
378 struct bna_mac
*mcmac
;
379 struct bna_mcam_handle
*mchandle
;
381 mcmac
= bna_rxf_mcmac_get(rxf
, mac_addr
);
382 mchandle
= bna_rxf_mchandle_get(rxf
, handle
);
383 if (mchandle
== NULL
) {
384 mchandle
= bna_mcam_mod_handle_get(&rxf
->rx
->bna
->mcam_mod
);
385 mchandle
->handle
= handle
;
386 mchandle
->refcnt
= 0;
387 list_add_tail(&mchandle
->qe
, &rxf
->mcast_handle_q
);
390 mcmac
->handle
= mchandle
;
394 bna_rxf_mcast_del(struct bna_rxf
*rxf
, struct bna_mac
*mac
,
395 enum bna_cleanup_type cleanup
)
397 struct bna_mcam_handle
*mchandle
;
400 mchandle
= mac
->handle
;
401 if (mchandle
== NULL
)
405 if (mchandle
->refcnt
== 0) {
406 if (cleanup
== BNA_HARD_CLEANUP
) {
407 bna_bfi_mcast_del_req(rxf
, mchandle
->handle
);
410 list_del(&mchandle
->qe
);
411 bna_mcam_mod_handle_put(&rxf
->rx
->bna
->mcam_mod
, mchandle
);
419 bna_rxf_mcast_cfg_apply(struct bna_rxf
*rxf
)
421 struct bna_mac
*mac
= NULL
;
424 /* First delete multicast entries to maintain the count */
425 while (!list_empty(&rxf
->mcast_pending_del_q
)) {
426 mac
= list_first_entry(&rxf
->mcast_pending_del_q
,
428 ret
= bna_rxf_mcast_del(rxf
, mac
, BNA_HARD_CLEANUP
);
429 list_move_tail(&mac
->qe
, bna_mcam_mod_del_q(rxf
->rx
->bna
));
434 /* Add multicast entries */
435 if (!list_empty(&rxf
->mcast_pending_add_q
)) {
436 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
438 list_move_tail(&mac
->qe
, &rxf
->mcast_active_q
);
439 bna_bfi_mcast_add_req(rxf
, mac
);
447 bna_rxf_vlan_cfg_apply(struct bna_rxf
*rxf
)
449 u8 vlan_pending_bitmask
;
452 if (rxf
->vlan_pending_bitmask
) {
453 vlan_pending_bitmask
= rxf
->vlan_pending_bitmask
;
454 while (!(vlan_pending_bitmask
& 0x1)) {
456 vlan_pending_bitmask
>>= 1;
458 rxf
->vlan_pending_bitmask
&= ~BIT(block_idx
);
459 bna_bfi_rx_vlan_filter_set(rxf
, block_idx
);
467 bna_rxf_mcast_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
472 /* Throw away delete pending mcast entries */
473 while (!list_empty(&rxf
->mcast_pending_del_q
)) {
474 mac
= list_first_entry(&rxf
->mcast_pending_del_q
,
476 ret
= bna_rxf_mcast_del(rxf
, mac
, cleanup
);
477 list_move_tail(&mac
->qe
, bna_mcam_mod_del_q(rxf
->rx
->bna
));
482 /* Move active mcast entries to pending_add_q */
483 while (!list_empty(&rxf
->mcast_active_q
)) {
484 mac
= list_first_entry(&rxf
->mcast_active_q
,
486 list_move_tail(&mac
->qe
, &rxf
->mcast_pending_add_q
);
487 if (bna_rxf_mcast_del(rxf
, mac
, cleanup
))
495 bna_rxf_rss_cfg_apply(struct bna_rxf
*rxf
)
497 if (rxf
->rss_pending
) {
498 if (rxf
->rss_pending
& BNA_RSS_F_RIT_PENDING
) {
499 rxf
->rss_pending
&= ~BNA_RSS_F_RIT_PENDING
;
500 bna_bfi_rit_cfg(rxf
);
504 if (rxf
->rss_pending
& BNA_RSS_F_CFG_PENDING
) {
505 rxf
->rss_pending
&= ~BNA_RSS_F_CFG_PENDING
;
506 bna_bfi_rss_cfg(rxf
);
510 if (rxf
->rss_pending
& BNA_RSS_F_STATUS_PENDING
) {
511 rxf
->rss_pending
&= ~BNA_RSS_F_STATUS_PENDING
;
512 bna_bfi_rss_enable(rxf
);
521 bna_rxf_cfg_apply(struct bna_rxf
*rxf
)
523 if (bna_rxf_ucast_cfg_apply(rxf
))
526 if (bna_rxf_mcast_cfg_apply(rxf
))
529 if (bna_rxf_promisc_cfg_apply(rxf
))
532 if (bna_rxf_allmulti_cfg_apply(rxf
))
535 if (bna_rxf_vlan_cfg_apply(rxf
))
538 if (bna_rxf_vlan_strip_cfg_apply(rxf
))
541 if (bna_rxf_rss_cfg_apply(rxf
))
548 bna_rxf_cfg_reset(struct bna_rxf
*rxf
)
550 bna_rxf_ucast_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
551 bna_rxf_mcast_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
552 bna_rxf_promisc_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
553 bna_rxf_allmulti_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
554 bna_rxf_vlan_cfg_soft_reset(rxf
);
555 bna_rxf_rss_cfg_soft_reset(rxf
);
559 bna_rit_init(struct bna_rxf
*rxf
, int rit_size
)
561 struct bna_rx
*rx
= rxf
->rx
;
565 rxf
->rit_size
= rit_size
;
566 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
) {
567 rxf
->rit
[offset
] = rxp
->cq
.ccb
->id
;
573 bna_bfi_rxf_cfg_rsp(struct bna_rxf
*rxf
, struct bfi_msgq_mhdr
*msghdr
)
575 bfa_fsm_send_event(rxf
, RXF_E_FW_RESP
);
579 bna_bfi_rxf_ucast_set_rsp(struct bna_rxf
*rxf
,
580 struct bfi_msgq_mhdr
*msghdr
)
582 struct bfi_enet_rsp
*rsp
=
583 container_of(msghdr
, struct bfi_enet_rsp
, mh
);
586 /* Clear ucast from cache */
587 rxf
->ucast_active_set
= 0;
590 bfa_fsm_send_event(rxf
, RXF_E_FW_RESP
);
594 bna_bfi_rxf_mcast_add_rsp(struct bna_rxf
*rxf
,
595 struct bfi_msgq_mhdr
*msghdr
)
597 struct bfi_enet_mcast_add_req
*req
=
598 &rxf
->bfi_enet_cmd
.mcast_add_req
;
599 struct bfi_enet_mcast_add_rsp
*rsp
=
600 container_of(msghdr
, struct bfi_enet_mcast_add_rsp
, mh
);
602 bna_rxf_mchandle_attach(rxf
, (u8
*)&req
->mac_addr
,
604 bfa_fsm_send_event(rxf
, RXF_E_FW_RESP
);
608 bna_rxf_init(struct bna_rxf
*rxf
,
610 struct bna_rx_config
*q_config
,
611 struct bna_res_info
*res_info
)
615 INIT_LIST_HEAD(&rxf
->ucast_pending_add_q
);
616 INIT_LIST_HEAD(&rxf
->ucast_pending_del_q
);
617 rxf
->ucast_pending_set
= 0;
618 rxf
->ucast_active_set
= 0;
619 INIT_LIST_HEAD(&rxf
->ucast_active_q
);
620 rxf
->ucast_pending_mac
= NULL
;
622 INIT_LIST_HEAD(&rxf
->mcast_pending_add_q
);
623 INIT_LIST_HEAD(&rxf
->mcast_pending_del_q
);
624 INIT_LIST_HEAD(&rxf
->mcast_active_q
);
625 INIT_LIST_HEAD(&rxf
->mcast_handle_q
);
628 res_info
[BNA_RX_RES_MEM_T_RIT
].res_u
.mem_info
.mdl
[0].kva
;
629 bna_rit_init(rxf
, q_config
->num_paths
);
631 rxf
->rss_status
= q_config
->rss_status
;
632 if (rxf
->rss_status
== BNA_STATUS_T_ENABLED
) {
633 rxf
->rss_cfg
= q_config
->rss_config
;
634 rxf
->rss_pending
|= BNA_RSS_F_CFG_PENDING
;
635 rxf
->rss_pending
|= BNA_RSS_F_RIT_PENDING
;
636 rxf
->rss_pending
|= BNA_RSS_F_STATUS_PENDING
;
639 rxf
->vlan_filter_status
= BNA_STATUS_T_DISABLED
;
640 memset(rxf
->vlan_filter_table
, 0,
641 (sizeof(u32
) * (BFI_ENET_VLAN_ID_MAX
/ 32)));
642 rxf
->vlan_filter_table
[0] |= 1; /* for pure priority tagged frames */
643 rxf
->vlan_pending_bitmask
= (u8
)BFI_VLAN_BMASK_ALL
;
645 rxf
->vlan_strip_status
= q_config
->vlan_strip_status
;
647 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
651 bna_rxf_uninit(struct bna_rxf
*rxf
)
655 rxf
->ucast_pending_set
= 0;
656 rxf
->ucast_active_set
= 0;
658 while (!list_empty(&rxf
->ucast_pending_add_q
)) {
659 mac
= list_first_entry(&rxf
->ucast_pending_add_q
,
661 list_move_tail(&mac
->qe
, bna_ucam_mod_free_q(rxf
->rx
->bna
));
664 if (rxf
->ucast_pending_mac
) {
665 list_add_tail(&rxf
->ucast_pending_mac
->qe
,
666 bna_ucam_mod_free_q(rxf
->rx
->bna
));
667 rxf
->ucast_pending_mac
= NULL
;
670 while (!list_empty(&rxf
->mcast_pending_add_q
)) {
671 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
673 list_move_tail(&mac
->qe
, bna_mcam_mod_free_q(rxf
->rx
->bna
));
676 rxf
->rxmode_pending
= 0;
677 rxf
->rxmode_pending_bitmask
= 0;
678 if (rxf
->rx
->bna
->promisc_rid
== rxf
->rx
->rid
)
679 rxf
->rx
->bna
->promisc_rid
= BFI_INVALID_RID
;
680 if (rxf
->rx
->bna
->default_mode_rid
== rxf
->rx
->rid
)
681 rxf
->rx
->bna
->default_mode_rid
= BFI_INVALID_RID
;
683 rxf
->rss_pending
= 0;
684 rxf
->vlan_strip_pending
= false;
690 bna_rx_cb_rxf_started(struct bna_rx
*rx
)
692 bfa_fsm_send_event(rx
, RX_E_RXF_STARTED
);
696 bna_rxf_start(struct bna_rxf
*rxf
)
698 rxf
->start_cbfn
= bna_rx_cb_rxf_started
;
699 rxf
->start_cbarg
= rxf
->rx
;
700 bfa_fsm_send_event(rxf
, RXF_E_START
);
704 bna_rx_cb_rxf_stopped(struct bna_rx
*rx
)
706 bfa_fsm_send_event(rx
, RX_E_RXF_STOPPED
);
710 bna_rxf_stop(struct bna_rxf
*rxf
)
712 rxf
->stop_cbfn
= bna_rx_cb_rxf_stopped
;
713 rxf
->stop_cbarg
= rxf
->rx
;
714 bfa_fsm_send_event(rxf
, RXF_E_STOP
);
718 bna_rxf_fail(struct bna_rxf
*rxf
)
720 bfa_fsm_send_event(rxf
, RXF_E_FAIL
);
724 bna_rx_ucast_set(struct bna_rx
*rx
, const u8
*ucmac
)
726 struct bna_rxf
*rxf
= &rx
->rxf
;
728 if (rxf
->ucast_pending_mac
== NULL
) {
729 rxf
->ucast_pending_mac
=
730 bna_cam_mod_mac_get(bna_ucam_mod_free_q(rxf
->rx
->bna
));
731 if (rxf
->ucast_pending_mac
== NULL
)
732 return BNA_CB_UCAST_CAM_FULL
;
735 ether_addr_copy(rxf
->ucast_pending_mac
->addr
, ucmac
);
736 rxf
->ucast_pending_set
= 1;
737 rxf
->cam_fltr_cbfn
= NULL
;
738 rxf
->cam_fltr_cbarg
= rx
->bna
->bnad
;
740 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
742 return BNA_CB_SUCCESS
;
746 bna_rx_mcast_add(struct bna_rx
*rx
, const u8
*addr
,
747 void (*cbfn
)(struct bnad
*, struct bna_rx
*))
749 struct bna_rxf
*rxf
= &rx
->rxf
;
752 /* Check if already added or pending addition */
753 if (bna_mac_find(&rxf
->mcast_active_q
, addr
) ||
754 bna_mac_find(&rxf
->mcast_pending_add_q
, addr
)) {
756 cbfn(rx
->bna
->bnad
, rx
);
757 return BNA_CB_SUCCESS
;
760 mac
= bna_cam_mod_mac_get(bna_mcam_mod_free_q(rxf
->rx
->bna
));
762 return BNA_CB_MCAST_LIST_FULL
;
763 ether_addr_copy(mac
->addr
, addr
);
764 list_add_tail(&mac
->qe
, &rxf
->mcast_pending_add_q
);
766 rxf
->cam_fltr_cbfn
= cbfn
;
767 rxf
->cam_fltr_cbarg
= rx
->bna
->bnad
;
769 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
771 return BNA_CB_SUCCESS
;
775 bna_rx_ucast_listset(struct bna_rx
*rx
, int count
, const u8
*uclist
)
777 struct bna_ucam_mod
*ucam_mod
= &rx
->bna
->ucam_mod
;
778 struct bna_rxf
*rxf
= &rx
->rxf
;
779 struct list_head list_head
;
781 struct bna_mac
*mac
, *del_mac
;
784 /* Purge the pending_add_q */
785 while (!list_empty(&rxf
->ucast_pending_add_q
)) {
786 mac
= list_first_entry(&rxf
->ucast_pending_add_q
,
788 list_move_tail(&mac
->qe
, &ucam_mod
->free_q
);
791 /* Schedule active_q entries for deletion */
792 while (!list_empty(&rxf
->ucast_active_q
)) {
793 mac
= list_first_entry(&rxf
->ucast_active_q
,
795 del_mac
= bna_cam_mod_mac_get(&ucam_mod
->del_q
);
796 ether_addr_copy(del_mac
->addr
, mac
->addr
);
797 del_mac
->handle
= mac
->handle
;
798 list_add_tail(&del_mac
->qe
, &rxf
->ucast_pending_del_q
);
799 list_move_tail(&mac
->qe
, &ucam_mod
->free_q
);
803 INIT_LIST_HEAD(&list_head
);
804 for (i
= 0, mcaddr
= uclist
; i
< count
; i
++) {
805 mac
= bna_cam_mod_mac_get(&ucam_mod
->free_q
);
808 ether_addr_copy(mac
->addr
, mcaddr
);
809 list_add_tail(&mac
->qe
, &list_head
);
813 /* Add the new entries */
814 while (!list_empty(&list_head
)) {
815 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
816 list_move_tail(&mac
->qe
, &rxf
->ucast_pending_add_q
);
819 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
821 return BNA_CB_SUCCESS
;
824 while (!list_empty(&list_head
)) {
825 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
826 list_move_tail(&mac
->qe
, &ucam_mod
->free_q
);
829 return BNA_CB_UCAST_CAM_FULL
;
833 bna_rx_mcast_listset(struct bna_rx
*rx
, int count
, const u8
*mclist
)
835 struct bna_mcam_mod
*mcam_mod
= &rx
->bna
->mcam_mod
;
836 struct bna_rxf
*rxf
= &rx
->rxf
;
837 struct list_head list_head
;
839 struct bna_mac
*mac
, *del_mac
;
842 /* Purge the pending_add_q */
843 while (!list_empty(&rxf
->mcast_pending_add_q
)) {
844 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
846 list_move_tail(&mac
->qe
, &mcam_mod
->free_q
);
849 /* Schedule active_q entries for deletion */
850 while (!list_empty(&rxf
->mcast_active_q
)) {
851 mac
= list_first_entry(&rxf
->mcast_active_q
,
853 del_mac
= bna_cam_mod_mac_get(&mcam_mod
->del_q
);
854 ether_addr_copy(del_mac
->addr
, mac
->addr
);
855 del_mac
->handle
= mac
->handle
;
856 list_add_tail(&del_mac
->qe
, &rxf
->mcast_pending_del_q
);
858 list_move_tail(&mac
->qe
, &mcam_mod
->free_q
);
862 INIT_LIST_HEAD(&list_head
);
863 for (i
= 0, mcaddr
= mclist
; i
< count
; i
++) {
864 mac
= bna_cam_mod_mac_get(&mcam_mod
->free_q
);
867 ether_addr_copy(mac
->addr
, mcaddr
);
868 list_add_tail(&mac
->qe
, &list_head
);
873 /* Add the new entries */
874 while (!list_empty(&list_head
)) {
875 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
876 list_move_tail(&mac
->qe
, &rxf
->mcast_pending_add_q
);
879 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
881 return BNA_CB_SUCCESS
;
884 while (!list_empty(&list_head
)) {
885 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
886 list_move_tail(&mac
->qe
, &mcam_mod
->free_q
);
889 return BNA_CB_MCAST_LIST_FULL
;
893 bna_rx_mcast_delall(struct bna_rx
*rx
)
895 struct bna_rxf
*rxf
= &rx
->rxf
;
896 struct bna_mac
*mac
, *del_mac
;
897 int need_hw_config
= 0;
899 /* Purge all entries from pending_add_q */
900 while (!list_empty(&rxf
->mcast_pending_add_q
)) {
901 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
903 list_move_tail(&mac
->qe
, bna_mcam_mod_free_q(rxf
->rx
->bna
));
906 /* Schedule all entries in active_q for deletion */
907 while (!list_empty(&rxf
->mcast_active_q
)) {
908 mac
= list_first_entry(&rxf
->mcast_active_q
,
911 del_mac
= bna_cam_mod_mac_get(bna_mcam_mod_del_q(rxf
->rx
->bna
));
912 memcpy(del_mac
, mac
, sizeof(*del_mac
));
913 list_add_tail(&del_mac
->qe
, &rxf
->mcast_pending_del_q
);
915 list_add_tail(&mac
->qe
, bna_mcam_mod_free_q(rxf
->rx
->bna
));
920 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
924 bna_rx_vlan_add(struct bna_rx
*rx
, int vlan_id
)
926 struct bna_rxf
*rxf
= &rx
->rxf
;
927 int index
= (vlan_id
>> BFI_VLAN_WORD_SHIFT
);
928 int bit
= BIT(vlan_id
& BFI_VLAN_WORD_MASK
);
929 int group_id
= (vlan_id
>> BFI_VLAN_BLOCK_SHIFT
);
931 rxf
->vlan_filter_table
[index
] |= bit
;
932 if (rxf
->vlan_filter_status
== BNA_STATUS_T_ENABLED
) {
933 rxf
->vlan_pending_bitmask
|= BIT(group_id
);
934 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
939 bna_rx_vlan_del(struct bna_rx
*rx
, int vlan_id
)
941 struct bna_rxf
*rxf
= &rx
->rxf
;
942 int index
= (vlan_id
>> BFI_VLAN_WORD_SHIFT
);
943 int bit
= BIT(vlan_id
& BFI_VLAN_WORD_MASK
);
944 int group_id
= (vlan_id
>> BFI_VLAN_BLOCK_SHIFT
);
946 rxf
->vlan_filter_table
[index
] &= ~bit
;
947 if (rxf
->vlan_filter_status
== BNA_STATUS_T_ENABLED
) {
948 rxf
->vlan_pending_bitmask
|= BIT(group_id
);
949 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
954 bna_rxf_ucast_cfg_apply(struct bna_rxf
*rxf
)
956 struct bna_mac
*mac
= NULL
;
958 /* Delete MAC addresses previousely added */
959 if (!list_empty(&rxf
->ucast_pending_del_q
)) {
960 mac
= list_first_entry(&rxf
->ucast_pending_del_q
,
962 bna_bfi_ucast_req(rxf
, mac
, BFI_ENET_H2I_MAC_UCAST_DEL_REQ
);
963 list_move_tail(&mac
->qe
, bna_ucam_mod_del_q(rxf
->rx
->bna
));
967 /* Set default unicast MAC */
968 if (rxf
->ucast_pending_set
) {
969 rxf
->ucast_pending_set
= 0;
970 ether_addr_copy(rxf
->ucast_active_mac
.addr
,
971 rxf
->ucast_pending_mac
->addr
);
972 rxf
->ucast_active_set
= 1;
973 bna_bfi_ucast_req(rxf
, &rxf
->ucast_active_mac
,
974 BFI_ENET_H2I_MAC_UCAST_SET_REQ
);
978 /* Add additional MAC entries */
979 if (!list_empty(&rxf
->ucast_pending_add_q
)) {
980 mac
= list_first_entry(&rxf
->ucast_pending_add_q
,
982 list_move_tail(&mac
->qe
, &rxf
->ucast_active_q
);
983 bna_bfi_ucast_req(rxf
, mac
, BFI_ENET_H2I_MAC_UCAST_ADD_REQ
);
991 bna_rxf_ucast_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
995 /* Throw away delete pending ucast entries */
996 while (!list_empty(&rxf
->ucast_pending_del_q
)) {
997 mac
= list_first_entry(&rxf
->ucast_pending_del_q
,
999 if (cleanup
== BNA_SOFT_CLEANUP
)
1000 list_move_tail(&mac
->qe
,
1001 bna_ucam_mod_del_q(rxf
->rx
->bna
));
1003 bna_bfi_ucast_req(rxf
, mac
,
1004 BFI_ENET_H2I_MAC_UCAST_DEL_REQ
);
1005 list_move_tail(&mac
->qe
,
1006 bna_ucam_mod_del_q(rxf
->rx
->bna
));
1011 /* Move active ucast entries to pending_add_q */
1012 while (!list_empty(&rxf
->ucast_active_q
)) {
1013 mac
= list_first_entry(&rxf
->ucast_active_q
,
1014 struct bna_mac
, qe
);
1015 list_move_tail(&mac
->qe
, &rxf
->ucast_pending_add_q
);
1016 if (cleanup
== BNA_HARD_CLEANUP
) {
1017 bna_bfi_ucast_req(rxf
, mac
,
1018 BFI_ENET_H2I_MAC_UCAST_DEL_REQ
);
1023 if (rxf
->ucast_active_set
) {
1024 rxf
->ucast_pending_set
= 1;
1025 rxf
->ucast_active_set
= 0;
1026 if (cleanup
== BNA_HARD_CLEANUP
) {
1027 bna_bfi_ucast_req(rxf
, &rxf
->ucast_active_mac
,
1028 BFI_ENET_H2I_MAC_UCAST_CLR_REQ
);
1037 bna_rxf_promisc_cfg_apply(struct bna_rxf
*rxf
)
1039 struct bna
*bna
= rxf
->rx
->bna
;
1041 /* Enable/disable promiscuous mode */
1042 if (is_promisc_enable(rxf
->rxmode_pending
,
1043 rxf
->rxmode_pending_bitmask
)) {
1044 /* move promisc configuration from pending -> active */
1045 promisc_inactive(rxf
->rxmode_pending
,
1046 rxf
->rxmode_pending_bitmask
);
1047 rxf
->rxmode_active
|= BNA_RXMODE_PROMISC
;
1048 bna_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_ENABLED
);
1050 } else if (is_promisc_disable(rxf
->rxmode_pending
,
1051 rxf
->rxmode_pending_bitmask
)) {
1052 /* move promisc configuration from pending -> active */
1053 promisc_inactive(rxf
->rxmode_pending
,
1054 rxf
->rxmode_pending_bitmask
);
1055 rxf
->rxmode_active
&= ~BNA_RXMODE_PROMISC
;
1056 bna
->promisc_rid
= BFI_INVALID_RID
;
1057 bna_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_DISABLED
);
1065 bna_rxf_promisc_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
1067 struct bna
*bna
= rxf
->rx
->bna
;
1069 /* Clear pending promisc mode disable */
1070 if (is_promisc_disable(rxf
->rxmode_pending
,
1071 rxf
->rxmode_pending_bitmask
)) {
1072 promisc_inactive(rxf
->rxmode_pending
,
1073 rxf
->rxmode_pending_bitmask
);
1074 rxf
->rxmode_active
&= ~BNA_RXMODE_PROMISC
;
1075 bna
->promisc_rid
= BFI_INVALID_RID
;
1076 if (cleanup
== BNA_HARD_CLEANUP
) {
1077 bna_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_DISABLED
);
1082 /* Move promisc mode config from active -> pending */
1083 if (rxf
->rxmode_active
& BNA_RXMODE_PROMISC
) {
1084 promisc_enable(rxf
->rxmode_pending
,
1085 rxf
->rxmode_pending_bitmask
);
1086 rxf
->rxmode_active
&= ~BNA_RXMODE_PROMISC
;
1087 if (cleanup
== BNA_HARD_CLEANUP
) {
1088 bna_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_DISABLED
);
1097 bna_rxf_allmulti_cfg_apply(struct bna_rxf
*rxf
)
1099 /* Enable/disable allmulti mode */
1100 if (is_allmulti_enable(rxf
->rxmode_pending
,
1101 rxf
->rxmode_pending_bitmask
)) {
1102 /* move allmulti configuration from pending -> active */
1103 allmulti_inactive(rxf
->rxmode_pending
,
1104 rxf
->rxmode_pending_bitmask
);
1105 rxf
->rxmode_active
|= BNA_RXMODE_ALLMULTI
;
1106 bna_bfi_mcast_filter_req(rxf
, BNA_STATUS_T_DISABLED
);
1108 } else if (is_allmulti_disable(rxf
->rxmode_pending
,
1109 rxf
->rxmode_pending_bitmask
)) {
1110 /* move allmulti configuration from pending -> active */
1111 allmulti_inactive(rxf
->rxmode_pending
,
1112 rxf
->rxmode_pending_bitmask
);
1113 rxf
->rxmode_active
&= ~BNA_RXMODE_ALLMULTI
;
1114 bna_bfi_mcast_filter_req(rxf
, BNA_STATUS_T_ENABLED
);
1122 bna_rxf_allmulti_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
1124 /* Clear pending allmulti mode disable */
1125 if (is_allmulti_disable(rxf
->rxmode_pending
,
1126 rxf
->rxmode_pending_bitmask
)) {
1127 allmulti_inactive(rxf
->rxmode_pending
,
1128 rxf
->rxmode_pending_bitmask
);
1129 rxf
->rxmode_active
&= ~BNA_RXMODE_ALLMULTI
;
1130 if (cleanup
== BNA_HARD_CLEANUP
) {
1131 bna_bfi_mcast_filter_req(rxf
, BNA_STATUS_T_ENABLED
);
1136 /* Move allmulti mode config from active -> pending */
1137 if (rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
) {
1138 allmulti_enable(rxf
->rxmode_pending
,
1139 rxf
->rxmode_pending_bitmask
);
1140 rxf
->rxmode_active
&= ~BNA_RXMODE_ALLMULTI
;
1141 if (cleanup
== BNA_HARD_CLEANUP
) {
1142 bna_bfi_mcast_filter_req(rxf
, BNA_STATUS_T_ENABLED
);
1151 bna_rxf_promisc_enable(struct bna_rxf
*rxf
)
1153 struct bna
*bna
= rxf
->rx
->bna
;
1156 if (is_promisc_enable(rxf
->rxmode_pending
,
1157 rxf
->rxmode_pending_bitmask
) ||
1158 (rxf
->rxmode_active
& BNA_RXMODE_PROMISC
)) {
1159 /* Do nothing if pending enable or already enabled */
1160 } else if (is_promisc_disable(rxf
->rxmode_pending
,
1161 rxf
->rxmode_pending_bitmask
)) {
1162 /* Turn off pending disable command */
1163 promisc_inactive(rxf
->rxmode_pending
,
1164 rxf
->rxmode_pending_bitmask
);
1166 /* Schedule enable */
1167 promisc_enable(rxf
->rxmode_pending
,
1168 rxf
->rxmode_pending_bitmask
);
1169 bna
->promisc_rid
= rxf
->rx
->rid
;
1177 bna_rxf_promisc_disable(struct bna_rxf
*rxf
)
1179 struct bna
*bna
= rxf
->rx
->bna
;
1182 if (is_promisc_disable(rxf
->rxmode_pending
,
1183 rxf
->rxmode_pending_bitmask
) ||
1184 (!(rxf
->rxmode_active
& BNA_RXMODE_PROMISC
))) {
1185 /* Do nothing if pending disable or already disabled */
1186 } else if (is_promisc_enable(rxf
->rxmode_pending
,
1187 rxf
->rxmode_pending_bitmask
)) {
1188 /* Turn off pending enable command */
1189 promisc_inactive(rxf
->rxmode_pending
,
1190 rxf
->rxmode_pending_bitmask
);
1191 bna
->promisc_rid
= BFI_INVALID_RID
;
1192 } else if (rxf
->rxmode_active
& BNA_RXMODE_PROMISC
) {
1193 /* Schedule disable */
1194 promisc_disable(rxf
->rxmode_pending
,
1195 rxf
->rxmode_pending_bitmask
);
1203 bna_rxf_allmulti_enable(struct bna_rxf
*rxf
)
1207 if (is_allmulti_enable(rxf
->rxmode_pending
,
1208 rxf
->rxmode_pending_bitmask
) ||
1209 (rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
)) {
1210 /* Do nothing if pending enable or already enabled */
1211 } else if (is_allmulti_disable(rxf
->rxmode_pending
,
1212 rxf
->rxmode_pending_bitmask
)) {
1213 /* Turn off pending disable command */
1214 allmulti_inactive(rxf
->rxmode_pending
,
1215 rxf
->rxmode_pending_bitmask
);
1217 /* Schedule enable */
1218 allmulti_enable(rxf
->rxmode_pending
,
1219 rxf
->rxmode_pending_bitmask
);
1227 bna_rxf_allmulti_disable(struct bna_rxf
*rxf
)
1231 if (is_allmulti_disable(rxf
->rxmode_pending
,
1232 rxf
->rxmode_pending_bitmask
) ||
1233 (!(rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
))) {
1234 /* Do nothing if pending disable or already disabled */
1235 } else if (is_allmulti_enable(rxf
->rxmode_pending
,
1236 rxf
->rxmode_pending_bitmask
)) {
1237 /* Turn off pending enable command */
1238 allmulti_inactive(rxf
->rxmode_pending
,
1239 rxf
->rxmode_pending_bitmask
);
1240 } else if (rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
) {
1241 /* Schedule disable */
1242 allmulti_disable(rxf
->rxmode_pending
,
1243 rxf
->rxmode_pending_bitmask
);
1251 bna_rxf_vlan_strip_cfg_apply(struct bna_rxf
*rxf
)
1253 if (rxf
->vlan_strip_pending
) {
1254 rxf
->vlan_strip_pending
= false;
1255 bna_bfi_vlan_strip_enable(rxf
);
1264 #define BNA_GET_RXQS(qcfg) (((qcfg)->rxp_type == BNA_RXP_SINGLE) ? \
1265 (qcfg)->num_paths : ((qcfg)->num_paths * 2))
1267 #define SIZE_TO_PAGES(size) (((size) >> PAGE_SHIFT) + ((((size) &\
1268 (PAGE_SIZE - 1)) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
1270 #define call_rx_stop_cbfn(rx) \
1272 if ((rx)->stop_cbfn) { \
1273 void (*cbfn)(void *, struct bna_rx *); \
1275 cbfn = (rx)->stop_cbfn; \
1276 cbarg = (rx)->stop_cbarg; \
1277 (rx)->stop_cbfn = NULL; \
1278 (rx)->stop_cbarg = NULL; \
1283 #define call_rx_stall_cbfn(rx) \
1285 if ((rx)->rx_stall_cbfn) \
1286 (rx)->rx_stall_cbfn((rx)->bna->bnad, (rx)); \
1289 #define bfi_enet_datapath_q_init(bfi_q, bna_qpt) \
1291 struct bna_dma_addr cur_q_addr = \
1292 *((struct bna_dma_addr *)((bna_qpt)->kv_qpt_ptr)); \
1293 (bfi_q)->pg_tbl.a32.addr_lo = (bna_qpt)->hw_qpt_ptr.lsb; \
1294 (bfi_q)->pg_tbl.a32.addr_hi = (bna_qpt)->hw_qpt_ptr.msb; \
1295 (bfi_q)->first_entry.a32.addr_lo = cur_q_addr.lsb; \
1296 (bfi_q)->first_entry.a32.addr_hi = cur_q_addr.msb; \
1297 (bfi_q)->pages = htons((u16)(bna_qpt)->page_count); \
1298 (bfi_q)->page_sz = htons((u16)(bna_qpt)->page_size);\
1301 static void bna_bfi_rx_enet_start(struct bna_rx
*rx
);
1302 static void bna_rx_enet_stop(struct bna_rx
*rx
);
1303 static void bna_rx_mod_cb_rx_stopped(void *arg
, struct bna_rx
*rx
);
1305 bfa_fsm_state_decl(bna_rx
, stopped
,
1306 struct bna_rx
, enum bna_rx_event
);
1307 bfa_fsm_state_decl(bna_rx
, start_wait
,
1308 struct bna_rx
, enum bna_rx_event
);
1309 bfa_fsm_state_decl(bna_rx
, start_stop_wait
,
1310 struct bna_rx
, enum bna_rx_event
);
1311 bfa_fsm_state_decl(bna_rx
, rxf_start_wait
,
1312 struct bna_rx
, enum bna_rx_event
);
1313 bfa_fsm_state_decl(bna_rx
, started
,
1314 struct bna_rx
, enum bna_rx_event
);
1315 bfa_fsm_state_decl(bna_rx
, rxf_stop_wait
,
1316 struct bna_rx
, enum bna_rx_event
);
1317 bfa_fsm_state_decl(bna_rx
, stop_wait
,
1318 struct bna_rx
, enum bna_rx_event
);
1319 bfa_fsm_state_decl(bna_rx
, cleanup_wait
,
1320 struct bna_rx
, enum bna_rx_event
);
1321 bfa_fsm_state_decl(bna_rx
, failed
,
1322 struct bna_rx
, enum bna_rx_event
);
1323 bfa_fsm_state_decl(bna_rx
, quiesce_wait
,
1324 struct bna_rx
, enum bna_rx_event
);
1326 static void bna_rx_sm_stopped_entry(struct bna_rx
*rx
)
1328 call_rx_stop_cbfn(rx
);
1331 static void bna_rx_sm_stopped(struct bna_rx
*rx
,
1332 enum bna_rx_event event
)
1336 bfa_fsm_set_state(rx
, bna_rx_sm_start_wait
);
1340 call_rx_stop_cbfn(rx
);
1348 bfa_sm_fault(event
);
1353 static void bna_rx_sm_start_wait_entry(struct bna_rx
*rx
)
1355 bna_bfi_rx_enet_start(rx
);
1359 bna_rx_sm_stop_wait_entry(struct bna_rx
*rx
)
1364 bna_rx_sm_stop_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1369 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1370 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1374 bna_rx_enet_stop(rx
);
1378 bfa_sm_fault(event
);
1383 static void bna_rx_sm_start_wait(struct bna_rx
*rx
,
1384 enum bna_rx_event event
)
1388 bfa_fsm_set_state(rx
, bna_rx_sm_start_stop_wait
);
1392 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1396 bfa_fsm_set_state(rx
, bna_rx_sm_rxf_start_wait
);
1400 bfa_sm_fault(event
);
1405 static void bna_rx_sm_rxf_start_wait_entry(struct bna_rx
*rx
)
1407 rx
->rx_post_cbfn(rx
->bna
->bnad
, rx
);
1408 bna_rxf_start(&rx
->rxf
);
1412 bna_rx_sm_rxf_stop_wait_entry(struct bna_rx
*rx
)
1417 bna_rx_sm_rxf_stop_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1421 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1422 bna_rxf_fail(&rx
->rxf
);
1423 call_rx_stall_cbfn(rx
);
1424 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1427 case RX_E_RXF_STARTED
:
1428 bna_rxf_stop(&rx
->rxf
);
1431 case RX_E_RXF_STOPPED
:
1432 bfa_fsm_set_state(rx
, bna_rx_sm_stop_wait
);
1433 call_rx_stall_cbfn(rx
);
1434 bna_rx_enet_stop(rx
);
1438 bfa_sm_fault(event
);
1445 bna_rx_sm_start_stop_wait_entry(struct bna_rx
*rx
)
1450 bna_rx_sm_start_stop_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1455 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1459 bna_rx_enet_stop(rx
);
1463 bfa_sm_fault(event
);
1468 bna_rx_sm_started_entry(struct bna_rx
*rx
)
1470 struct bna_rxp
*rxp
;
1471 int is_regular
= (rx
->type
== BNA_RX_T_REGULAR
);
1474 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
)
1475 bna_ib_start(rx
->bna
, &rxp
->cq
.ib
, is_regular
);
1477 bna_ethport_cb_rx_started(&rx
->bna
->ethport
);
1481 bna_rx_sm_started(struct bna_rx
*rx
, enum bna_rx_event event
)
1485 bfa_fsm_set_state(rx
, bna_rx_sm_rxf_stop_wait
);
1486 bna_ethport_cb_rx_stopped(&rx
->bna
->ethport
);
1487 bna_rxf_stop(&rx
->rxf
);
1491 bfa_fsm_set_state(rx
, bna_rx_sm_failed
);
1492 bna_ethport_cb_rx_stopped(&rx
->bna
->ethport
);
1493 bna_rxf_fail(&rx
->rxf
);
1494 call_rx_stall_cbfn(rx
);
1495 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1499 bfa_sm_fault(event
);
1504 static void bna_rx_sm_rxf_start_wait(struct bna_rx
*rx
,
1505 enum bna_rx_event event
)
1509 bfa_fsm_set_state(rx
, bna_rx_sm_rxf_stop_wait
);
1513 bfa_fsm_set_state(rx
, bna_rx_sm_failed
);
1514 bna_rxf_fail(&rx
->rxf
);
1515 call_rx_stall_cbfn(rx
);
1516 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1519 case RX_E_RXF_STARTED
:
1520 bfa_fsm_set_state(rx
, bna_rx_sm_started
);
1524 bfa_sm_fault(event
);
1530 bna_rx_sm_cleanup_wait_entry(struct bna_rx
*rx
)
1535 bna_rx_sm_cleanup_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1539 case RX_E_RXF_STOPPED
:
1543 case RX_E_CLEANUP_DONE
:
1544 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1548 bfa_sm_fault(event
);
1554 bna_rx_sm_failed_entry(struct bna_rx
*rx
)
1559 bna_rx_sm_failed(struct bna_rx
*rx
, enum bna_rx_event event
)
1563 bfa_fsm_set_state(rx
, bna_rx_sm_quiesce_wait
);
1567 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1571 case RX_E_RXF_STARTED
:
1572 case RX_E_RXF_STOPPED
:
1576 case RX_E_CLEANUP_DONE
:
1577 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1581 bfa_sm_fault(event
);
1586 bna_rx_sm_quiesce_wait_entry(struct bna_rx
*rx
)
1591 bna_rx_sm_quiesce_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1595 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1599 bfa_fsm_set_state(rx
, bna_rx_sm_failed
);
1602 case RX_E_CLEANUP_DONE
:
1603 bfa_fsm_set_state(rx
, bna_rx_sm_start_wait
);
1607 bfa_sm_fault(event
);
1613 bna_bfi_rx_enet_start(struct bna_rx
*rx
)
1615 struct bfi_enet_rx_cfg_req
*cfg_req
= &rx
->bfi_enet_cmd
.cfg_req
;
1616 struct bna_rxp
*rxp
= NULL
;
1617 struct bna_rxq
*q0
= NULL
, *q1
= NULL
;
1620 bfi_msgq_mhdr_set(cfg_req
->mh
, BFI_MC_ENET
,
1621 BFI_ENET_H2I_RX_CFG_SET_REQ
, 0, rx
->rid
);
1622 cfg_req
->mh
.num_entries
= htons(
1623 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rx_cfg_req
)));
1625 cfg_req
->rx_cfg
.frame_size
= bna_enet_mtu_get(&rx
->bna
->enet
);
1626 cfg_req
->num_queue_sets
= rx
->num_paths
;
1627 for (i
= 0; i
< rx
->num_paths
; i
++) {
1628 rxp
= rxp
? list_next_entry(rxp
, qe
)
1629 : list_first_entry(&rx
->rxp_q
, struct bna_rxp
, qe
);
1630 GET_RXQS(rxp
, q0
, q1
);
1631 switch (rxp
->type
) {
1635 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].qs
.q
,
1637 cfg_req
->q_cfg
[i
].qs
.rx_buffer_size
=
1638 htons((u16
)q1
->buffer_size
);
1641 case BNA_RXP_SINGLE
:
1642 /* Large/Single RxQ */
1643 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].ql
.q
,
1645 if (q0
->multi_buffer
)
1646 /* multi-buffer is enabled by allocating
1647 * a new rx with new set of resources.
1648 * q0->buffer_size should be initialized to
1651 cfg_req
->rx_cfg
.multi_buffer
=
1652 BNA_STATUS_T_ENABLED
;
1655 bna_enet_mtu_get(&rx
->bna
->enet
);
1656 cfg_req
->q_cfg
[i
].ql
.rx_buffer_size
=
1657 htons((u16
)q0
->buffer_size
);
1664 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].cq
.q
,
1667 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_lo
=
1668 rxp
->cq
.ib
.ib_seg_host_addr
.lsb
;
1669 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_hi
=
1670 rxp
->cq
.ib
.ib_seg_host_addr
.msb
;
1671 cfg_req
->q_cfg
[i
].ib
.intr
.msix_index
=
1672 htons((u16
)rxp
->cq
.ib
.intr_vector
);
1675 cfg_req
->ib_cfg
.int_pkt_dma
= BNA_STATUS_T_DISABLED
;
1676 cfg_req
->ib_cfg
.int_enabled
= BNA_STATUS_T_ENABLED
;
1677 cfg_req
->ib_cfg
.int_pkt_enabled
= BNA_STATUS_T_DISABLED
;
1678 cfg_req
->ib_cfg
.continuous_coalescing
= BNA_STATUS_T_DISABLED
;
1679 cfg_req
->ib_cfg
.msix
= (rxp
->cq
.ib
.intr_type
== BNA_INTR_T_MSIX
)
1680 ? BNA_STATUS_T_ENABLED
:
1681 BNA_STATUS_T_DISABLED
;
1682 cfg_req
->ib_cfg
.coalescing_timeout
=
1683 htonl((u32
)rxp
->cq
.ib
.coalescing_timeo
);
1684 cfg_req
->ib_cfg
.inter_pkt_timeout
=
1685 htonl((u32
)rxp
->cq
.ib
.interpkt_timeo
);
1686 cfg_req
->ib_cfg
.inter_pkt_count
= (u8
)rxp
->cq
.ib
.interpkt_count
;
1688 switch (rxp
->type
) {
1690 cfg_req
->rx_cfg
.rxq_type
= BFI_ENET_RXQ_LARGE_SMALL
;
1694 cfg_req
->rx_cfg
.rxq_type
= BFI_ENET_RXQ_HDS
;
1695 cfg_req
->rx_cfg
.hds
.type
= rx
->hds_cfg
.hdr_type
;
1696 cfg_req
->rx_cfg
.hds
.force_offset
= rx
->hds_cfg
.forced_offset
;
1697 cfg_req
->rx_cfg
.hds
.max_header_size
= rx
->hds_cfg
.forced_offset
;
1700 case BNA_RXP_SINGLE
:
1701 cfg_req
->rx_cfg
.rxq_type
= BFI_ENET_RXQ_SINGLE
;
1707 cfg_req
->rx_cfg
.strip_vlan
= rx
->rxf
.vlan_strip_status
;
1709 bfa_msgq_cmd_set(&rx
->msgq_cmd
, NULL
, NULL
,
1710 sizeof(struct bfi_enet_rx_cfg_req
), &cfg_req
->mh
);
1711 bfa_msgq_cmd_post(&rx
->bna
->msgq
, &rx
->msgq_cmd
);
1715 bna_bfi_rx_enet_stop(struct bna_rx
*rx
)
1717 struct bfi_enet_req
*req
= &rx
->bfi_enet_cmd
.req
;
1719 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
1720 BFI_ENET_H2I_RX_CFG_CLR_REQ
, 0, rx
->rid
);
1721 req
->mh
.num_entries
= htons(
1722 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_req
)));
1723 bfa_msgq_cmd_set(&rx
->msgq_cmd
, NULL
, NULL
, sizeof(struct bfi_enet_req
),
1725 bfa_msgq_cmd_post(&rx
->bna
->msgq
, &rx
->msgq_cmd
);
1729 bna_rx_enet_stop(struct bna_rx
*rx
)
1731 struct bna_rxp
*rxp
;
1734 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
)
1735 bna_ib_stop(rx
->bna
, &rxp
->cq
.ib
);
1737 bna_bfi_rx_enet_stop(rx
);
1741 bna_rx_res_check(struct bna_rx_mod
*rx_mod
, struct bna_rx_config
*rx_cfg
)
1743 if ((rx_mod
->rx_free_count
== 0) ||
1744 (rx_mod
->rxp_free_count
== 0) ||
1745 (rx_mod
->rxq_free_count
== 0))
1748 if (rx_cfg
->rxp_type
== BNA_RXP_SINGLE
) {
1749 if ((rx_mod
->rxp_free_count
< rx_cfg
->num_paths
) ||
1750 (rx_mod
->rxq_free_count
< rx_cfg
->num_paths
))
1753 if ((rx_mod
->rxp_free_count
< rx_cfg
->num_paths
) ||
1754 (rx_mod
->rxq_free_count
< (2 * rx_cfg
->num_paths
)))
1761 static struct bna_rxq
*
1762 bna_rxq_get(struct bna_rx_mod
*rx_mod
)
1764 struct bna_rxq
*rxq
= NULL
;
1766 rxq
= list_first_entry(&rx_mod
->rxq_free_q
, struct bna_rxq
, qe
);
1768 rx_mod
->rxq_free_count
--;
1774 bna_rxq_put(struct bna_rx_mod
*rx_mod
, struct bna_rxq
*rxq
)
1776 list_add_tail(&rxq
->qe
, &rx_mod
->rxq_free_q
);
1777 rx_mod
->rxq_free_count
++;
1780 static struct bna_rxp
*
1781 bna_rxp_get(struct bna_rx_mod
*rx_mod
)
1783 struct bna_rxp
*rxp
= NULL
;
1785 rxp
= list_first_entry(&rx_mod
->rxp_free_q
, struct bna_rxp
, qe
);
1787 rx_mod
->rxp_free_count
--;
1793 bna_rxp_put(struct bna_rx_mod
*rx_mod
, struct bna_rxp
*rxp
)
1795 list_add_tail(&rxp
->qe
, &rx_mod
->rxp_free_q
);
1796 rx_mod
->rxp_free_count
++;
1799 static struct bna_rx
*
1800 bna_rx_get(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
)
1802 struct bna_rx
*rx
= NULL
;
1804 BUG_ON(list_empty(&rx_mod
->rx_free_q
));
1805 if (type
== BNA_RX_T_REGULAR
)
1806 rx
= list_first_entry(&rx_mod
->rx_free_q
, struct bna_rx
, qe
);
1808 rx
= list_last_entry(&rx_mod
->rx_free_q
, struct bna_rx
, qe
);
1810 rx_mod
->rx_free_count
--;
1811 list_move_tail(&rx
->qe
, &rx_mod
->rx_active_q
);
1818 bna_rx_put(struct bna_rx_mod
*rx_mod
, struct bna_rx
*rx
)
1820 struct list_head
*qe
;
1822 list_for_each_prev(qe
, &rx_mod
->rx_free_q
)
1823 if (((struct bna_rx
*)qe
)->rid
< rx
->rid
)
1826 list_add(&rx
->qe
, qe
);
1827 rx_mod
->rx_free_count
++;
1831 bna_rxp_add_rxqs(struct bna_rxp
*rxp
, struct bna_rxq
*q0
,
1834 switch (rxp
->type
) {
1835 case BNA_RXP_SINGLE
:
1836 rxp
->rxq
.single
.only
= q0
;
1837 rxp
->rxq
.single
.reserved
= NULL
;
1840 rxp
->rxq
.slr
.large
= q0
;
1841 rxp
->rxq
.slr
.small
= q1
;
1844 rxp
->rxq
.hds
.data
= q0
;
1845 rxp
->rxq
.hds
.hdr
= q1
;
1853 bna_rxq_qpt_setup(struct bna_rxq
*rxq
,
1854 struct bna_rxp
*rxp
,
1857 struct bna_mem_descr
*qpt_mem
,
1858 struct bna_mem_descr
*swqpt_mem
,
1859 struct bna_mem_descr
*page_mem
)
1863 struct bna_dma_addr bna_dma
;
1866 rxq
->qpt
.hw_qpt_ptr
.lsb
= qpt_mem
->dma
.lsb
;
1867 rxq
->qpt
.hw_qpt_ptr
.msb
= qpt_mem
->dma
.msb
;
1868 rxq
->qpt
.kv_qpt_ptr
= qpt_mem
->kva
;
1869 rxq
->qpt
.page_count
= page_count
;
1870 rxq
->qpt
.page_size
= page_size
;
1872 rxq
->rcb
->sw_qpt
= (void **) swqpt_mem
->kva
;
1873 rxq
->rcb
->sw_q
= page_mem
->kva
;
1875 kva
= page_mem
->kva
;
1876 BNA_GET_DMA_ADDR(&page_mem
->dma
, dma
);
1878 for (i
= 0; i
< rxq
->qpt
.page_count
; i
++) {
1879 rxq
->rcb
->sw_qpt
[i
] = kva
;
1882 BNA_SET_DMA_ADDR(dma
, &bna_dma
);
1883 ((struct bna_dma_addr
*)rxq
->qpt
.kv_qpt_ptr
)[i
].lsb
=
1885 ((struct bna_dma_addr
*)rxq
->qpt
.kv_qpt_ptr
)[i
].msb
=
1892 bna_rxp_cqpt_setup(struct bna_rxp
*rxp
,
1895 struct bna_mem_descr
*qpt_mem
,
1896 struct bna_mem_descr
*swqpt_mem
,
1897 struct bna_mem_descr
*page_mem
)
1901 struct bna_dma_addr bna_dma
;
1904 rxp
->cq
.qpt
.hw_qpt_ptr
.lsb
= qpt_mem
->dma
.lsb
;
1905 rxp
->cq
.qpt
.hw_qpt_ptr
.msb
= qpt_mem
->dma
.msb
;
1906 rxp
->cq
.qpt
.kv_qpt_ptr
= qpt_mem
->kva
;
1907 rxp
->cq
.qpt
.page_count
= page_count
;
1908 rxp
->cq
.qpt
.page_size
= page_size
;
1910 rxp
->cq
.ccb
->sw_qpt
= (void **) swqpt_mem
->kva
;
1911 rxp
->cq
.ccb
->sw_q
= page_mem
->kva
;
1913 kva
= page_mem
->kva
;
1914 BNA_GET_DMA_ADDR(&page_mem
->dma
, dma
);
1916 for (i
= 0; i
< rxp
->cq
.qpt
.page_count
; i
++) {
1917 rxp
->cq
.ccb
->sw_qpt
[i
] = kva
;
1920 BNA_SET_DMA_ADDR(dma
, &bna_dma
);
1921 ((struct bna_dma_addr
*)rxp
->cq
.qpt
.kv_qpt_ptr
)[i
].lsb
=
1923 ((struct bna_dma_addr
*)rxp
->cq
.qpt
.kv_qpt_ptr
)[i
].msb
=
1930 bna_rx_mod_cb_rx_stopped(void *arg
, struct bna_rx
*rx
)
1932 struct bna_rx_mod
*rx_mod
= (struct bna_rx_mod
*)arg
;
1934 bfa_wc_down(&rx_mod
->rx_stop_wc
);
1938 bna_rx_mod_cb_rx_stopped_all(void *arg
)
1940 struct bna_rx_mod
*rx_mod
= (struct bna_rx_mod
*)arg
;
1942 if (rx_mod
->stop_cbfn
)
1943 rx_mod
->stop_cbfn(&rx_mod
->bna
->enet
);
1944 rx_mod
->stop_cbfn
= NULL
;
1948 bna_rx_start(struct bna_rx
*rx
)
1950 rx
->rx_flags
|= BNA_RX_F_ENET_STARTED
;
1951 if (rx
->rx_flags
& BNA_RX_F_ENABLED
)
1952 bfa_fsm_send_event(rx
, RX_E_START
);
1956 bna_rx_stop(struct bna_rx
*rx
)
1958 rx
->rx_flags
&= ~BNA_RX_F_ENET_STARTED
;
1959 if (rx
->fsm
== (bfa_fsm_t
) bna_rx_sm_stopped
)
1960 bna_rx_mod_cb_rx_stopped(&rx
->bna
->rx_mod
, rx
);
1962 rx
->stop_cbfn
= bna_rx_mod_cb_rx_stopped
;
1963 rx
->stop_cbarg
= &rx
->bna
->rx_mod
;
1964 bfa_fsm_send_event(rx
, RX_E_STOP
);
1969 bna_rx_fail(struct bna_rx
*rx
)
1971 /* Indicate Enet is not enabled, and failed */
1972 rx
->rx_flags
&= ~BNA_RX_F_ENET_STARTED
;
1973 bfa_fsm_send_event(rx
, RX_E_FAIL
);
1977 bna_rx_mod_start(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
)
1981 rx_mod
->flags
|= BNA_RX_MOD_F_ENET_STARTED
;
1982 if (type
== BNA_RX_T_LOOPBACK
)
1983 rx_mod
->flags
|= BNA_RX_MOD_F_ENET_LOOPBACK
;
1985 list_for_each_entry(rx
, &rx_mod
->rx_active_q
, qe
)
1986 if (rx
->type
== type
)
1991 bna_rx_mod_stop(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
)
1995 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_STARTED
;
1996 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_LOOPBACK
;
1998 rx_mod
->stop_cbfn
= bna_enet_cb_rx_stopped
;
2000 bfa_wc_init(&rx_mod
->rx_stop_wc
, bna_rx_mod_cb_rx_stopped_all
, rx_mod
);
2002 list_for_each_entry(rx
, &rx_mod
->rx_active_q
, qe
)
2003 if (rx
->type
== type
) {
2004 bfa_wc_up(&rx_mod
->rx_stop_wc
);
2008 bfa_wc_wait(&rx_mod
->rx_stop_wc
);
2012 bna_rx_mod_fail(struct bna_rx_mod
*rx_mod
)
2016 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_STARTED
;
2017 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_LOOPBACK
;
2019 list_for_each_entry(rx
, &rx_mod
->rx_active_q
, qe
)
2023 void bna_rx_mod_init(struct bna_rx_mod
*rx_mod
, struct bna
*bna
,
2024 struct bna_res_info
*res_info
)
2027 struct bna_rx
*rx_ptr
;
2028 struct bna_rxp
*rxp_ptr
;
2029 struct bna_rxq
*rxq_ptr
;
2034 rx_mod
->rx
= (struct bna_rx
*)
2035 res_info
[BNA_MOD_RES_MEM_T_RX_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
2036 rx_mod
->rxp
= (struct bna_rxp
*)
2037 res_info
[BNA_MOD_RES_MEM_T_RXP_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
2038 rx_mod
->rxq
= (struct bna_rxq
*)
2039 res_info
[BNA_MOD_RES_MEM_T_RXQ_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
2041 /* Initialize the queues */
2042 INIT_LIST_HEAD(&rx_mod
->rx_free_q
);
2043 rx_mod
->rx_free_count
= 0;
2044 INIT_LIST_HEAD(&rx_mod
->rxq_free_q
);
2045 rx_mod
->rxq_free_count
= 0;
2046 INIT_LIST_HEAD(&rx_mod
->rxp_free_q
);
2047 rx_mod
->rxp_free_count
= 0;
2048 INIT_LIST_HEAD(&rx_mod
->rx_active_q
);
2050 /* Build RX queues */
2051 for (index
= 0; index
< bna
->ioceth
.attr
.num_rxp
; index
++) {
2052 rx_ptr
= &rx_mod
->rx
[index
];
2054 INIT_LIST_HEAD(&rx_ptr
->rxp_q
);
2056 rx_ptr
->rid
= index
;
2057 rx_ptr
->stop_cbfn
= NULL
;
2058 rx_ptr
->stop_cbarg
= NULL
;
2060 list_add_tail(&rx_ptr
->qe
, &rx_mod
->rx_free_q
);
2061 rx_mod
->rx_free_count
++;
2064 /* build RX-path queue */
2065 for (index
= 0; index
< bna
->ioceth
.attr
.num_rxp
; index
++) {
2066 rxp_ptr
= &rx_mod
->rxp
[index
];
2067 list_add_tail(&rxp_ptr
->qe
, &rx_mod
->rxp_free_q
);
2068 rx_mod
->rxp_free_count
++;
2071 /* build RXQ queue */
2072 for (index
= 0; index
< (bna
->ioceth
.attr
.num_rxp
* 2); index
++) {
2073 rxq_ptr
= &rx_mod
->rxq
[index
];
2074 list_add_tail(&rxq_ptr
->qe
, &rx_mod
->rxq_free_q
);
2075 rx_mod
->rxq_free_count
++;
2080 bna_rx_mod_uninit(struct bna_rx_mod
*rx_mod
)
2086 bna_bfi_rx_enet_start_rsp(struct bna_rx
*rx
, struct bfi_msgq_mhdr
*msghdr
)
2088 struct bfi_enet_rx_cfg_rsp
*cfg_rsp
= &rx
->bfi_enet_cmd
.cfg_rsp
;
2089 struct bna_rxp
*rxp
= NULL
;
2090 struct bna_rxq
*q0
= NULL
, *q1
= NULL
;
2093 bfa_msgq_rsp_copy(&rx
->bna
->msgq
, (u8
*)cfg_rsp
,
2094 sizeof(struct bfi_enet_rx_cfg_rsp
));
2096 rx
->hw_id
= cfg_rsp
->hw_id
;
2098 for (i
= 0, rxp
= list_first_entry(&rx
->rxp_q
, struct bna_rxp
, qe
);
2099 i
< rx
->num_paths
; i
++, rxp
= list_next_entry(rxp
, qe
)) {
2100 GET_RXQS(rxp
, q0
, q1
);
2102 /* Setup doorbells */
2103 rxp
->cq
.ccb
->i_dbell
->doorbell_addr
=
2104 rx
->bna
->pcidev
.pci_bar_kva
2105 + ntohl(cfg_rsp
->q_handles
[i
].i_dbell
);
2106 rxp
->hw_id
= cfg_rsp
->q_handles
[i
].hw_cqid
;
2108 rx
->bna
->pcidev
.pci_bar_kva
2109 + ntohl(cfg_rsp
->q_handles
[i
].ql_dbell
);
2110 q0
->hw_id
= cfg_rsp
->q_handles
[i
].hw_lqid
;
2113 rx
->bna
->pcidev
.pci_bar_kva
2114 + ntohl(cfg_rsp
->q_handles
[i
].qs_dbell
);
2115 q1
->hw_id
= cfg_rsp
->q_handles
[i
].hw_sqid
;
2118 /* Initialize producer/consumer indexes */
2119 (*rxp
->cq
.ccb
->hw_producer_index
) = 0;
2120 rxp
->cq
.ccb
->producer_index
= 0;
2121 q0
->rcb
->producer_index
= q0
->rcb
->consumer_index
= 0;
2123 q1
->rcb
->producer_index
= q1
->rcb
->consumer_index
= 0;
2126 bfa_fsm_send_event(rx
, RX_E_STARTED
);
2130 bna_bfi_rx_enet_stop_rsp(struct bna_rx
*rx
, struct bfi_msgq_mhdr
*msghdr
)
2132 bfa_fsm_send_event(rx
, RX_E_STOPPED
);
2136 bna_rx_res_req(struct bna_rx_config
*q_cfg
, struct bna_res_info
*res_info
)
2138 u32 cq_size
, hq_size
, dq_size
;
2139 u32 cpage_count
, hpage_count
, dpage_count
;
2140 struct bna_mem_info
*mem_info
;
2145 dq_depth
= q_cfg
->q0_depth
;
2146 hq_depth
= ((q_cfg
->rxp_type
== BNA_RXP_SINGLE
) ? 0 : q_cfg
->q1_depth
);
2147 cq_depth
= roundup_pow_of_two(dq_depth
+ hq_depth
);
2149 cq_size
= cq_depth
* BFI_CQ_WI_SIZE
;
2150 cq_size
= ALIGN(cq_size
, PAGE_SIZE
);
2151 cpage_count
= SIZE_TO_PAGES(cq_size
);
2153 dq_depth
= roundup_pow_of_two(dq_depth
);
2154 dq_size
= dq_depth
* BFI_RXQ_WI_SIZE
;
2155 dq_size
= ALIGN(dq_size
, PAGE_SIZE
);
2156 dpage_count
= SIZE_TO_PAGES(dq_size
);
2158 if (BNA_RXP_SINGLE
!= q_cfg
->rxp_type
) {
2159 hq_depth
= roundup_pow_of_two(hq_depth
);
2160 hq_size
= hq_depth
* BFI_RXQ_WI_SIZE
;
2161 hq_size
= ALIGN(hq_size
, PAGE_SIZE
);
2162 hpage_count
= SIZE_TO_PAGES(hq_size
);
2166 res_info
[BNA_RX_RES_MEM_T_CCB
].res_type
= BNA_RES_T_MEM
;
2167 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CCB
].res_u
.mem_info
;
2168 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2169 mem_info
->len
= sizeof(struct bna_ccb
);
2170 mem_info
->num
= q_cfg
->num_paths
;
2172 res_info
[BNA_RX_RES_MEM_T_RCB
].res_type
= BNA_RES_T_MEM
;
2173 mem_info
= &res_info
[BNA_RX_RES_MEM_T_RCB
].res_u
.mem_info
;
2174 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2175 mem_info
->len
= sizeof(struct bna_rcb
);
2176 mem_info
->num
= BNA_GET_RXQS(q_cfg
);
2178 res_info
[BNA_RX_RES_MEM_T_CQPT
].res_type
= BNA_RES_T_MEM
;
2179 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CQPT
].res_u
.mem_info
;
2180 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2181 mem_info
->len
= cpage_count
* sizeof(struct bna_dma_addr
);
2182 mem_info
->num
= q_cfg
->num_paths
;
2184 res_info
[BNA_RX_RES_MEM_T_CSWQPT
].res_type
= BNA_RES_T_MEM
;
2185 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CSWQPT
].res_u
.mem_info
;
2186 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2187 mem_info
->len
= cpage_count
* sizeof(void *);
2188 mem_info
->num
= q_cfg
->num_paths
;
2190 res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_type
= BNA_RES_T_MEM
;
2191 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_u
.mem_info
;
2192 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2193 mem_info
->len
= PAGE_SIZE
* cpage_count
;
2194 mem_info
->num
= q_cfg
->num_paths
;
2196 res_info
[BNA_RX_RES_MEM_T_DQPT
].res_type
= BNA_RES_T_MEM
;
2197 mem_info
= &res_info
[BNA_RX_RES_MEM_T_DQPT
].res_u
.mem_info
;
2198 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2199 mem_info
->len
= dpage_count
* sizeof(struct bna_dma_addr
);
2200 mem_info
->num
= q_cfg
->num_paths
;
2202 res_info
[BNA_RX_RES_MEM_T_DSWQPT
].res_type
= BNA_RES_T_MEM
;
2203 mem_info
= &res_info
[BNA_RX_RES_MEM_T_DSWQPT
].res_u
.mem_info
;
2204 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2205 mem_info
->len
= dpage_count
* sizeof(void *);
2206 mem_info
->num
= q_cfg
->num_paths
;
2208 res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_type
= BNA_RES_T_MEM
;
2209 mem_info
= &res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_u
.mem_info
;
2210 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2211 mem_info
->len
= PAGE_SIZE
* dpage_count
;
2212 mem_info
->num
= q_cfg
->num_paths
;
2214 res_info
[BNA_RX_RES_MEM_T_HQPT
].res_type
= BNA_RES_T_MEM
;
2215 mem_info
= &res_info
[BNA_RX_RES_MEM_T_HQPT
].res_u
.mem_info
;
2216 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2217 mem_info
->len
= hpage_count
* sizeof(struct bna_dma_addr
);
2218 mem_info
->num
= (hpage_count
? q_cfg
->num_paths
: 0);
2220 res_info
[BNA_RX_RES_MEM_T_HSWQPT
].res_type
= BNA_RES_T_MEM
;
2221 mem_info
= &res_info
[BNA_RX_RES_MEM_T_HSWQPT
].res_u
.mem_info
;
2222 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2223 mem_info
->len
= hpage_count
* sizeof(void *);
2224 mem_info
->num
= (hpage_count
? q_cfg
->num_paths
: 0);
2226 res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_type
= BNA_RES_T_MEM
;
2227 mem_info
= &res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_u
.mem_info
;
2228 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2229 mem_info
->len
= PAGE_SIZE
* hpage_count
;
2230 mem_info
->num
= (hpage_count
? q_cfg
->num_paths
: 0);
2232 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_type
= BNA_RES_T_MEM
;
2233 mem_info
= &res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
;
2234 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2235 mem_info
->len
= BFI_IBIDX_SIZE
;
2236 mem_info
->num
= q_cfg
->num_paths
;
2238 res_info
[BNA_RX_RES_MEM_T_RIT
].res_type
= BNA_RES_T_MEM
;
2239 mem_info
= &res_info
[BNA_RX_RES_MEM_T_RIT
].res_u
.mem_info
;
2240 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2241 mem_info
->len
= BFI_ENET_RSS_RIT_MAX
;
2244 res_info
[BNA_RX_RES_T_INTR
].res_type
= BNA_RES_T_INTR
;
2245 res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
.intr_type
= BNA_INTR_T_MSIX
;
2246 res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
.num
= q_cfg
->num_paths
;
2250 bna_rx_create(struct bna
*bna
, struct bnad
*bnad
,
2251 struct bna_rx_config
*rx_cfg
,
2252 const struct bna_rx_event_cbfn
*rx_cbfn
,
2253 struct bna_res_info
*res_info
,
2256 struct bna_rx_mod
*rx_mod
= &bna
->rx_mod
;
2258 struct bna_rxp
*rxp
;
2261 struct bna_intr_info
*intr_info
;
2262 struct bna_mem_descr
*hqunmap_mem
;
2263 struct bna_mem_descr
*dqunmap_mem
;
2264 struct bna_mem_descr
*ccb_mem
;
2265 struct bna_mem_descr
*rcb_mem
;
2266 struct bna_mem_descr
*cqpt_mem
;
2267 struct bna_mem_descr
*cswqpt_mem
;
2268 struct bna_mem_descr
*cpage_mem
;
2269 struct bna_mem_descr
*hqpt_mem
;
2270 struct bna_mem_descr
*dqpt_mem
;
2271 struct bna_mem_descr
*hsqpt_mem
;
2272 struct bna_mem_descr
*dsqpt_mem
;
2273 struct bna_mem_descr
*hpage_mem
;
2274 struct bna_mem_descr
*dpage_mem
;
2275 u32 dpage_count
, hpage_count
;
2276 u32 hq_idx
, dq_idx
, rcb_idx
;
2280 if (!bna_rx_res_check(rx_mod
, rx_cfg
))
2283 intr_info
= &res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
;
2284 ccb_mem
= &res_info
[BNA_RX_RES_MEM_T_CCB
].res_u
.mem_info
.mdl
[0];
2285 rcb_mem
= &res_info
[BNA_RX_RES_MEM_T_RCB
].res_u
.mem_info
.mdl
[0];
2286 dqunmap_mem
= &res_info
[BNA_RX_RES_MEM_T_UNMAPDQ
].res_u
.mem_info
.mdl
[0];
2287 hqunmap_mem
= &res_info
[BNA_RX_RES_MEM_T_UNMAPHQ
].res_u
.mem_info
.mdl
[0];
2288 cqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_CQPT
].res_u
.mem_info
.mdl
[0];
2289 cswqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_CSWQPT
].res_u
.mem_info
.mdl
[0];
2290 cpage_mem
= &res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_u
.mem_info
.mdl
[0];
2291 hqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_HQPT
].res_u
.mem_info
.mdl
[0];
2292 dqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_DQPT
].res_u
.mem_info
.mdl
[0];
2293 hsqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_HSWQPT
].res_u
.mem_info
.mdl
[0];
2294 dsqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_DSWQPT
].res_u
.mem_info
.mdl
[0];
2295 hpage_mem
= &res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_u
.mem_info
.mdl
[0];
2296 dpage_mem
= &res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_u
.mem_info
.mdl
[0];
2298 page_count
= res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_u
.mem_info
.len
/
2301 dpage_count
= res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_u
.mem_info
.len
/
2304 hpage_count
= res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_u
.mem_info
.len
/
2307 rx
= bna_rx_get(rx_mod
, rx_cfg
->rx_type
);
2310 INIT_LIST_HEAD(&rx
->rxp_q
);
2311 rx
->stop_cbfn
= NULL
;
2312 rx
->stop_cbarg
= NULL
;
2315 rx
->rcb_setup_cbfn
= rx_cbfn
->rcb_setup_cbfn
;
2316 rx
->rcb_destroy_cbfn
= rx_cbfn
->rcb_destroy_cbfn
;
2317 rx
->ccb_setup_cbfn
= rx_cbfn
->ccb_setup_cbfn
;
2318 rx
->ccb_destroy_cbfn
= rx_cbfn
->ccb_destroy_cbfn
;
2319 rx
->rx_stall_cbfn
= rx_cbfn
->rx_stall_cbfn
;
2320 /* Following callbacks are mandatory */
2321 rx
->rx_cleanup_cbfn
= rx_cbfn
->rx_cleanup_cbfn
;
2322 rx
->rx_post_cbfn
= rx_cbfn
->rx_post_cbfn
;
2324 if (rx
->bna
->rx_mod
.flags
& BNA_RX_MOD_F_ENET_STARTED
) {
2326 case BNA_RX_T_REGULAR
:
2327 if (!(rx
->bna
->rx_mod
.flags
&
2328 BNA_RX_MOD_F_ENET_LOOPBACK
))
2329 rx
->rx_flags
|= BNA_RX_F_ENET_STARTED
;
2331 case BNA_RX_T_LOOPBACK
:
2332 if (rx
->bna
->rx_mod
.flags
& BNA_RX_MOD_F_ENET_LOOPBACK
)
2333 rx
->rx_flags
|= BNA_RX_F_ENET_STARTED
;
2338 rx
->num_paths
= rx_cfg
->num_paths
;
2339 for (i
= 0, hq_idx
= 0, dq_idx
= 0, rcb_idx
= 0;
2340 i
< rx
->num_paths
; i
++) {
2341 rxp
= bna_rxp_get(rx_mod
);
2342 list_add_tail(&rxp
->qe
, &rx
->rxp_q
);
2343 rxp
->type
= rx_cfg
->rxp_type
;
2347 q0
= bna_rxq_get(rx_mod
);
2348 if (BNA_RXP_SINGLE
== rx_cfg
->rxp_type
)
2351 q1
= bna_rxq_get(rx_mod
);
2353 if (1 == intr_info
->num
)
2354 rxp
->vector
= intr_info
->idl
[0].vector
;
2356 rxp
->vector
= intr_info
->idl
[i
].vector
;
2360 rxp
->cq
.ib
.ib_seg_host_addr
.lsb
=
2361 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.lsb
;
2362 rxp
->cq
.ib
.ib_seg_host_addr
.msb
=
2363 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.msb
;
2364 rxp
->cq
.ib
.ib_seg_host_addr_kva
=
2365 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].kva
;
2366 rxp
->cq
.ib
.intr_type
= intr_info
->intr_type
;
2367 if (intr_info
->intr_type
== BNA_INTR_T_MSIX
)
2368 rxp
->cq
.ib
.intr_vector
= rxp
->vector
;
2370 rxp
->cq
.ib
.intr_vector
= BIT(rxp
->vector
);
2371 rxp
->cq
.ib
.coalescing_timeo
= rx_cfg
->coalescing_timeo
;
2372 rxp
->cq
.ib
.interpkt_count
= BFI_RX_INTERPKT_COUNT
;
2373 rxp
->cq
.ib
.interpkt_timeo
= BFI_RX_INTERPKT_TIMEO
;
2375 bna_rxp_add_rxqs(rxp
, q0
, q1
);
2382 q0
->rcb
= (struct bna_rcb
*) rcb_mem
[rcb_idx
].kva
;
2383 q0
->rcb
->unmap_q
= (void *)dqunmap_mem
[dq_idx
].kva
;
2384 rcb_idx
++; dq_idx
++;
2385 q0
->rcb
->q_depth
= rx_cfg
->q0_depth
;
2386 q0
->q_depth
= rx_cfg
->q0_depth
;
2387 q0
->multi_buffer
= rx_cfg
->q0_multi_buf
;
2388 q0
->buffer_size
= rx_cfg
->q0_buf_size
;
2389 q0
->num_vecs
= rx_cfg
->q0_num_vecs
;
2391 q0
->rcb
->bnad
= bna
->bnad
;
2393 q0
->rx_packets
= q0
->rx_bytes
= 0;
2394 q0
->rx_packets_with_error
= q0
->rxbuf_alloc_failed
= 0;
2395 q0
->rxbuf_map_failed
= 0;
2397 bna_rxq_qpt_setup(q0
, rxp
, dpage_count
, PAGE_SIZE
,
2398 &dqpt_mem
[i
], &dsqpt_mem
[i
], &dpage_mem
[i
]);
2400 if (rx
->rcb_setup_cbfn
)
2401 rx
->rcb_setup_cbfn(bnad
, q0
->rcb
);
2409 q1
->rcb
= (struct bna_rcb
*) rcb_mem
[rcb_idx
].kva
;
2410 q1
->rcb
->unmap_q
= (void *)hqunmap_mem
[hq_idx
].kva
;
2411 rcb_idx
++; hq_idx
++;
2412 q1
->rcb
->q_depth
= rx_cfg
->q1_depth
;
2413 q1
->q_depth
= rx_cfg
->q1_depth
;
2414 q1
->multi_buffer
= BNA_STATUS_T_DISABLED
;
2417 q1
->rcb
->bnad
= bna
->bnad
;
2419 q1
->buffer_size
= (rx_cfg
->rxp_type
== BNA_RXP_HDS
) ?
2420 rx_cfg
->hds_config
.forced_offset
2421 : rx_cfg
->q1_buf_size
;
2422 q1
->rx_packets
= q1
->rx_bytes
= 0;
2423 q1
->rx_packets_with_error
= q1
->rxbuf_alloc_failed
= 0;
2424 q1
->rxbuf_map_failed
= 0;
2426 bna_rxq_qpt_setup(q1
, rxp
, hpage_count
, PAGE_SIZE
,
2427 &hqpt_mem
[i
], &hsqpt_mem
[i
],
2430 if (rx
->rcb_setup_cbfn
)
2431 rx
->rcb_setup_cbfn(bnad
, q1
->rcb
);
2436 rxp
->cq
.ccb
= (struct bna_ccb
*) ccb_mem
[i
].kva
;
2437 cq_depth
= rx_cfg
->q0_depth
+
2438 ((rx_cfg
->rxp_type
== BNA_RXP_SINGLE
) ?
2439 0 : rx_cfg
->q1_depth
);
2440 /* if multi-buffer is enabled sum of q0_depth
2441 * and q1_depth need not be a power of 2
2443 cq_depth
= roundup_pow_of_two(cq_depth
);
2444 rxp
->cq
.ccb
->q_depth
= cq_depth
;
2445 rxp
->cq
.ccb
->cq
= &rxp
->cq
;
2446 rxp
->cq
.ccb
->rcb
[0] = q0
->rcb
;
2447 q0
->rcb
->ccb
= rxp
->cq
.ccb
;
2449 rxp
->cq
.ccb
->rcb
[1] = q1
->rcb
;
2450 q1
->rcb
->ccb
= rxp
->cq
.ccb
;
2452 rxp
->cq
.ccb
->hw_producer_index
=
2453 (u32
*)rxp
->cq
.ib
.ib_seg_host_addr_kva
;
2454 rxp
->cq
.ccb
->i_dbell
= &rxp
->cq
.ib
.door_bell
;
2455 rxp
->cq
.ccb
->intr_type
= rxp
->cq
.ib
.intr_type
;
2456 rxp
->cq
.ccb
->intr_vector
= rxp
->cq
.ib
.intr_vector
;
2457 rxp
->cq
.ccb
->rx_coalescing_timeo
=
2458 rxp
->cq
.ib
.coalescing_timeo
;
2459 rxp
->cq
.ccb
->pkt_rate
.small_pkt_cnt
= 0;
2460 rxp
->cq
.ccb
->pkt_rate
.large_pkt_cnt
= 0;
2461 rxp
->cq
.ccb
->bnad
= bna
->bnad
;
2462 rxp
->cq
.ccb
->id
= i
;
2464 bna_rxp_cqpt_setup(rxp
, page_count
, PAGE_SIZE
,
2465 &cqpt_mem
[i
], &cswqpt_mem
[i
], &cpage_mem
[i
]);
2467 if (rx
->ccb_setup_cbfn
)
2468 rx
->ccb_setup_cbfn(bnad
, rxp
->cq
.ccb
);
2471 rx
->hds_cfg
= rx_cfg
->hds_config
;
2473 bna_rxf_init(&rx
->rxf
, rx
, rx_cfg
, res_info
);
2475 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
2477 rx_mod
->rid_mask
|= BIT(rx
->rid
);
2483 bna_rx_destroy(struct bna_rx
*rx
)
2485 struct bna_rx_mod
*rx_mod
= &rx
->bna
->rx_mod
;
2486 struct bna_rxq
*q0
= NULL
;
2487 struct bna_rxq
*q1
= NULL
;
2488 struct bna_rxp
*rxp
;
2489 struct list_head
*qe
;
2491 bna_rxf_uninit(&rx
->rxf
);
2493 while (!list_empty(&rx
->rxp_q
)) {
2494 rxp
= list_first_entry(&rx
->rxp_q
, struct bna_rxp
, qe
);
2496 GET_RXQS(rxp
, q0
, q1
);
2497 if (rx
->rcb_destroy_cbfn
)
2498 rx
->rcb_destroy_cbfn(rx
->bna
->bnad
, q0
->rcb
);
2502 bna_rxq_put(rx_mod
, q0
);
2505 if (rx
->rcb_destroy_cbfn
)
2506 rx
->rcb_destroy_cbfn(rx
->bna
->bnad
, q1
->rcb
);
2510 bna_rxq_put(rx_mod
, q1
);
2512 rxp
->rxq
.slr
.large
= NULL
;
2513 rxp
->rxq
.slr
.small
= NULL
;
2515 if (rx
->ccb_destroy_cbfn
)
2516 rx
->ccb_destroy_cbfn(rx
->bna
->bnad
, rxp
->cq
.ccb
);
2519 bna_rxp_put(rx_mod
, rxp
);
2522 list_for_each(qe
, &rx_mod
->rx_active_q
)
2523 if (qe
== &rx
->qe
) {
2528 rx_mod
->rid_mask
&= ~BIT(rx
->rid
);
2532 bna_rx_put(rx_mod
, rx
);
2536 bna_rx_enable(struct bna_rx
*rx
)
2538 if (rx
->fsm
!= (bfa_sm_t
)bna_rx_sm_stopped
)
2541 rx
->rx_flags
|= BNA_RX_F_ENABLED
;
2542 if (rx
->rx_flags
& BNA_RX_F_ENET_STARTED
)
2543 bfa_fsm_send_event(rx
, RX_E_START
);
2547 bna_rx_disable(struct bna_rx
*rx
, enum bna_cleanup_type type
,
2548 void (*cbfn
)(void *, struct bna_rx
*))
2550 if (type
== BNA_SOFT_CLEANUP
) {
2551 /* h/w should not be accessed. Treat we're stopped */
2552 (*cbfn
)(rx
->bna
->bnad
, rx
);
2554 rx
->stop_cbfn
= cbfn
;
2555 rx
->stop_cbarg
= rx
->bna
->bnad
;
2557 rx
->rx_flags
&= ~BNA_RX_F_ENABLED
;
2559 bfa_fsm_send_event(rx
, RX_E_STOP
);
2564 bna_rx_cleanup_complete(struct bna_rx
*rx
)
2566 bfa_fsm_send_event(rx
, RX_E_CLEANUP_DONE
);
2570 bna_rx_vlan_strip_enable(struct bna_rx
*rx
)
2572 struct bna_rxf
*rxf
= &rx
->rxf
;
2574 if (rxf
->vlan_strip_status
== BNA_STATUS_T_DISABLED
) {
2575 rxf
->vlan_strip_status
= BNA_STATUS_T_ENABLED
;
2576 rxf
->vlan_strip_pending
= true;
2577 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2582 bna_rx_vlan_strip_disable(struct bna_rx
*rx
)
2584 struct bna_rxf
*rxf
= &rx
->rxf
;
2586 if (rxf
->vlan_strip_status
!= BNA_STATUS_T_DISABLED
) {
2587 rxf
->vlan_strip_status
= BNA_STATUS_T_DISABLED
;
2588 rxf
->vlan_strip_pending
= true;
2589 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2594 bna_rx_mode_set(struct bna_rx
*rx
, enum bna_rxmode new_mode
,
2595 enum bna_rxmode bitmask
)
2597 struct bna_rxf
*rxf
= &rx
->rxf
;
2598 int need_hw_config
= 0;
2602 if (is_promisc_enable(new_mode
, bitmask
)) {
2603 /* If promisc mode is already enabled elsewhere in the system */
2604 if ((rx
->bna
->promisc_rid
!= BFI_INVALID_RID
) &&
2605 (rx
->bna
->promisc_rid
!= rxf
->rx
->rid
))
2608 /* If default mode is already enabled in the system */
2609 if (rx
->bna
->default_mode_rid
!= BFI_INVALID_RID
)
2612 /* Trying to enable promiscuous and default mode together */
2613 if (is_default_enable(new_mode
, bitmask
))
2617 if (is_default_enable(new_mode
, bitmask
)) {
2618 /* If default mode is already enabled elsewhere in the system */
2619 if ((rx
->bna
->default_mode_rid
!= BFI_INVALID_RID
) &&
2620 (rx
->bna
->default_mode_rid
!= rxf
->rx
->rid
)) {
2624 /* If promiscuous mode is already enabled in the system */
2625 if (rx
->bna
->promisc_rid
!= BFI_INVALID_RID
)
2629 /* Process the commands */
2631 if (is_promisc_enable(new_mode
, bitmask
)) {
2632 if (bna_rxf_promisc_enable(rxf
))
2634 } else if (is_promisc_disable(new_mode
, bitmask
)) {
2635 if (bna_rxf_promisc_disable(rxf
))
2639 if (is_allmulti_enable(new_mode
, bitmask
)) {
2640 if (bna_rxf_allmulti_enable(rxf
))
2642 } else if (is_allmulti_disable(new_mode
, bitmask
)) {
2643 if (bna_rxf_allmulti_disable(rxf
))
2647 /* Trigger h/w if needed */
2649 if (need_hw_config
) {
2650 rxf
->cam_fltr_cbfn
= NULL
;
2651 rxf
->cam_fltr_cbarg
= rx
->bna
->bnad
;
2652 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2655 return BNA_CB_SUCCESS
;
2662 bna_rx_vlanfilter_enable(struct bna_rx
*rx
)
2664 struct bna_rxf
*rxf
= &rx
->rxf
;
2666 if (rxf
->vlan_filter_status
== BNA_STATUS_T_DISABLED
) {
2667 rxf
->vlan_filter_status
= BNA_STATUS_T_ENABLED
;
2668 rxf
->vlan_pending_bitmask
= (u8
)BFI_VLAN_BMASK_ALL
;
2669 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2674 bna_rx_coalescing_timeo_set(struct bna_rx
*rx
, int coalescing_timeo
)
2676 struct bna_rxp
*rxp
;
2678 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
) {
2679 rxp
->cq
.ccb
->rx_coalescing_timeo
= coalescing_timeo
;
2680 bna_ib_coalescing_timeo_set(&rxp
->cq
.ib
, coalescing_timeo
);
2685 bna_rx_dim_reconfig(struct bna
*bna
, const u32 vector
[][BNA_BIAS_T_MAX
])
2689 for (i
= 0; i
< BNA_LOAD_T_MAX
; i
++)
2690 for (j
= 0; j
< BNA_BIAS_T_MAX
; j
++)
2691 bna
->rx_mod
.dim_vector
[i
][j
] = vector
[i
][j
];
2695 bna_rx_dim_update(struct bna_ccb
*ccb
)
2697 struct bna
*bna
= ccb
->cq
->rx
->bna
;
2699 u32 pkt_rt
, small_rt
, large_rt
;
2700 u8 coalescing_timeo
;
2702 if ((ccb
->pkt_rate
.small_pkt_cnt
== 0) &&
2703 (ccb
->pkt_rate
.large_pkt_cnt
== 0))
2706 /* Arrive at preconfigured coalescing timeo value based on pkt rate */
2708 small_rt
= ccb
->pkt_rate
.small_pkt_cnt
;
2709 large_rt
= ccb
->pkt_rate
.large_pkt_cnt
;
2711 pkt_rt
= small_rt
+ large_rt
;
2713 if (pkt_rt
< BNA_PKT_RATE_10K
)
2714 load
= BNA_LOAD_T_LOW_4
;
2715 else if (pkt_rt
< BNA_PKT_RATE_20K
)
2716 load
= BNA_LOAD_T_LOW_3
;
2717 else if (pkt_rt
< BNA_PKT_RATE_30K
)
2718 load
= BNA_LOAD_T_LOW_2
;
2719 else if (pkt_rt
< BNA_PKT_RATE_40K
)
2720 load
= BNA_LOAD_T_LOW_1
;
2721 else if (pkt_rt
< BNA_PKT_RATE_50K
)
2722 load
= BNA_LOAD_T_HIGH_1
;
2723 else if (pkt_rt
< BNA_PKT_RATE_60K
)
2724 load
= BNA_LOAD_T_HIGH_2
;
2725 else if (pkt_rt
< BNA_PKT_RATE_80K
)
2726 load
= BNA_LOAD_T_HIGH_3
;
2728 load
= BNA_LOAD_T_HIGH_4
;
2730 if (small_rt
> (large_rt
<< 1))
2735 ccb
->pkt_rate
.small_pkt_cnt
= 0;
2736 ccb
->pkt_rate
.large_pkt_cnt
= 0;
2738 coalescing_timeo
= bna
->rx_mod
.dim_vector
[load
][bias
];
2739 ccb
->rx_coalescing_timeo
= coalescing_timeo
;
2742 bna_ib_coalescing_timeo_set(&ccb
->cq
->ib
, coalescing_timeo
);
2745 const u32 bna_napi_dim_vector
[BNA_LOAD_T_MAX
][BNA_BIAS_T_MAX
] = {
2758 #define call_tx_stop_cbfn(tx) \
2760 if ((tx)->stop_cbfn) { \
2761 void (*cbfn)(void *, struct bna_tx *); \
2763 cbfn = (tx)->stop_cbfn; \
2764 cbarg = (tx)->stop_cbarg; \
2765 (tx)->stop_cbfn = NULL; \
2766 (tx)->stop_cbarg = NULL; \
2767 cbfn(cbarg, (tx)); \
2771 static void bna_tx_mod_cb_tx_stopped(void *tx_mod
, struct bna_tx
*tx
);
2772 static void bna_bfi_tx_enet_start(struct bna_tx
*tx
);
2773 static void bna_tx_enet_stop(struct bna_tx
*tx
);
2781 TX_E_CLEANUP_DONE
= 7,
2785 bfa_fsm_state_decl(bna_tx
, stopped
, struct bna_tx
, enum bna_tx_event
);
2786 bfa_fsm_state_decl(bna_tx
, start_wait
, struct bna_tx
, enum bna_tx_event
);
2787 bfa_fsm_state_decl(bna_tx
, started
, struct bna_tx
, enum bna_tx_event
);
2788 bfa_fsm_state_decl(bna_tx
, stop_wait
, struct bna_tx
, enum bna_tx_event
);
2789 bfa_fsm_state_decl(bna_tx
, cleanup_wait
, struct bna_tx
,
2791 bfa_fsm_state_decl(bna_tx
, prio_stop_wait
, struct bna_tx
,
2793 bfa_fsm_state_decl(bna_tx
, prio_cleanup_wait
, struct bna_tx
,
2795 bfa_fsm_state_decl(bna_tx
, failed
, struct bna_tx
, enum bna_tx_event
);
2796 bfa_fsm_state_decl(bna_tx
, quiesce_wait
, struct bna_tx
,
2800 bna_tx_sm_stopped_entry(struct bna_tx
*tx
)
2802 call_tx_stop_cbfn(tx
);
2806 bna_tx_sm_stopped(struct bna_tx
*tx
, enum bna_tx_event event
)
2810 bfa_fsm_set_state(tx
, bna_tx_sm_start_wait
);
2814 call_tx_stop_cbfn(tx
);
2821 case TX_E_BW_UPDATE
:
2826 bfa_sm_fault(event
);
2831 bna_tx_sm_start_wait_entry(struct bna_tx
*tx
)
2833 bna_bfi_tx_enet_start(tx
);
2837 bna_tx_sm_start_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2841 tx
->flags
&= ~BNA_TX_F_BW_UPDATED
;
2842 bfa_fsm_set_state(tx
, bna_tx_sm_stop_wait
);
2846 tx
->flags
&= ~BNA_TX_F_BW_UPDATED
;
2847 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
2851 if (tx
->flags
& BNA_TX_F_BW_UPDATED
) {
2852 tx
->flags
&= ~BNA_TX_F_BW_UPDATED
;
2853 bfa_fsm_set_state(tx
, bna_tx_sm_prio_stop_wait
);
2855 bfa_fsm_set_state(tx
, bna_tx_sm_started
);
2858 case TX_E_BW_UPDATE
:
2859 tx
->flags
|= BNA_TX_F_BW_UPDATED
;
2863 bfa_sm_fault(event
);
2868 bna_tx_sm_started_entry(struct bna_tx
*tx
)
2870 struct bna_txq
*txq
;
2871 int is_regular
= (tx
->type
== BNA_TX_T_REGULAR
);
2873 list_for_each_entry(txq
, &tx
->txq_q
, qe
) {
2874 txq
->tcb
->priority
= txq
->priority
;
2876 bna_ib_start(tx
->bna
, &txq
->ib
, is_regular
);
2878 tx
->tx_resume_cbfn(tx
->bna
->bnad
, tx
);
2882 bna_tx_sm_started(struct bna_tx
*tx
, enum bna_tx_event event
)
2886 bfa_fsm_set_state(tx
, bna_tx_sm_stop_wait
);
2887 tx
->tx_stall_cbfn(tx
->bna
->bnad
, tx
);
2888 bna_tx_enet_stop(tx
);
2892 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
2893 tx
->tx_stall_cbfn(tx
->bna
->bnad
, tx
);
2894 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
2897 case TX_E_BW_UPDATE
:
2898 bfa_fsm_set_state(tx
, bna_tx_sm_prio_stop_wait
);
2902 bfa_sm_fault(event
);
2907 bna_tx_sm_stop_wait_entry(struct bna_tx
*tx
)
2912 bna_tx_sm_stop_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2917 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
2918 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
2923 * We are here due to start_wait -> stop_wait transition on
2926 bna_tx_enet_stop(tx
);
2929 case TX_E_BW_UPDATE
:
2934 bfa_sm_fault(event
);
2939 bna_tx_sm_cleanup_wait_entry(struct bna_tx
*tx
)
2944 bna_tx_sm_cleanup_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2948 case TX_E_BW_UPDATE
:
2952 case TX_E_CLEANUP_DONE
:
2953 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
2957 bfa_sm_fault(event
);
2962 bna_tx_sm_prio_stop_wait_entry(struct bna_tx
*tx
)
2964 tx
->tx_stall_cbfn(tx
->bna
->bnad
, tx
);
2965 bna_tx_enet_stop(tx
);
2969 bna_tx_sm_prio_stop_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2973 bfa_fsm_set_state(tx
, bna_tx_sm_stop_wait
);
2977 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
2978 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
2982 bfa_fsm_set_state(tx
, bna_tx_sm_prio_cleanup_wait
);
2985 case TX_E_BW_UPDATE
:
2990 bfa_sm_fault(event
);
2995 bna_tx_sm_prio_cleanup_wait_entry(struct bna_tx
*tx
)
2997 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
3001 bna_tx_sm_prio_cleanup_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
3005 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
3009 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
3012 case TX_E_BW_UPDATE
:
3016 case TX_E_CLEANUP_DONE
:
3017 bfa_fsm_set_state(tx
, bna_tx_sm_start_wait
);
3021 bfa_sm_fault(event
);
3026 bna_tx_sm_failed_entry(struct bna_tx
*tx
)
3031 bna_tx_sm_failed(struct bna_tx
*tx
, enum bna_tx_event event
)
3035 bfa_fsm_set_state(tx
, bna_tx_sm_quiesce_wait
);
3039 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
3046 case TX_E_CLEANUP_DONE
:
3047 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
3051 bfa_sm_fault(event
);
3056 bna_tx_sm_quiesce_wait_entry(struct bna_tx
*tx
)
3061 bna_tx_sm_quiesce_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
3065 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
3069 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
3072 case TX_E_CLEANUP_DONE
:
3073 bfa_fsm_set_state(tx
, bna_tx_sm_start_wait
);
3076 case TX_E_BW_UPDATE
:
3081 bfa_sm_fault(event
);
3086 bna_bfi_tx_enet_start(struct bna_tx
*tx
)
3088 struct bfi_enet_tx_cfg_req
*cfg_req
= &tx
->bfi_enet_cmd
.cfg_req
;
3089 struct bna_txq
*txq
= NULL
;
3092 bfi_msgq_mhdr_set(cfg_req
->mh
, BFI_MC_ENET
,
3093 BFI_ENET_H2I_TX_CFG_SET_REQ
, 0, tx
->rid
);
3094 cfg_req
->mh
.num_entries
= htons(
3095 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_tx_cfg_req
)));
3097 cfg_req
->num_queues
= tx
->num_txq
;
3098 for (i
= 0; i
< tx
->num_txq
; i
++) {
3099 txq
= txq
? list_next_entry(txq
, qe
)
3100 : list_first_entry(&tx
->txq_q
, struct bna_txq
, qe
);
3101 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].q
.q
, &txq
->qpt
);
3102 cfg_req
->q_cfg
[i
].q
.priority
= txq
->priority
;
3104 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_lo
=
3105 txq
->ib
.ib_seg_host_addr
.lsb
;
3106 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_hi
=
3107 txq
->ib
.ib_seg_host_addr
.msb
;
3108 cfg_req
->q_cfg
[i
].ib
.intr
.msix_index
=
3109 htons((u16
)txq
->ib
.intr_vector
);
3112 cfg_req
->ib_cfg
.int_pkt_dma
= BNA_STATUS_T_ENABLED
;
3113 cfg_req
->ib_cfg
.int_enabled
= BNA_STATUS_T_ENABLED
;
3114 cfg_req
->ib_cfg
.int_pkt_enabled
= BNA_STATUS_T_DISABLED
;
3115 cfg_req
->ib_cfg
.continuous_coalescing
= BNA_STATUS_T_ENABLED
;
3116 cfg_req
->ib_cfg
.msix
= (txq
->ib
.intr_type
== BNA_INTR_T_MSIX
)
3117 ? BNA_STATUS_T_ENABLED
: BNA_STATUS_T_DISABLED
;
3118 cfg_req
->ib_cfg
.coalescing_timeout
=
3119 htonl((u32
)txq
->ib
.coalescing_timeo
);
3120 cfg_req
->ib_cfg
.inter_pkt_timeout
=
3121 htonl((u32
)txq
->ib
.interpkt_timeo
);
3122 cfg_req
->ib_cfg
.inter_pkt_count
= (u8
)txq
->ib
.interpkt_count
;
3124 cfg_req
->tx_cfg
.vlan_mode
= BFI_ENET_TX_VLAN_WI
;
3125 cfg_req
->tx_cfg
.vlan_id
= htons((u16
)tx
->txf_vlan_id
);
3126 cfg_req
->tx_cfg
.admit_tagged_frame
= BNA_STATUS_T_ENABLED
;
3127 cfg_req
->tx_cfg
.apply_vlan_filter
= BNA_STATUS_T_DISABLED
;
3129 bfa_msgq_cmd_set(&tx
->msgq_cmd
, NULL
, NULL
,
3130 sizeof(struct bfi_enet_tx_cfg_req
), &cfg_req
->mh
);
3131 bfa_msgq_cmd_post(&tx
->bna
->msgq
, &tx
->msgq_cmd
);
3135 bna_bfi_tx_enet_stop(struct bna_tx
*tx
)
3137 struct bfi_enet_req
*req
= &tx
->bfi_enet_cmd
.req
;
3139 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
3140 BFI_ENET_H2I_TX_CFG_CLR_REQ
, 0, tx
->rid
);
3141 req
->mh
.num_entries
= htons(
3142 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_req
)));
3143 bfa_msgq_cmd_set(&tx
->msgq_cmd
, NULL
, NULL
, sizeof(struct bfi_enet_req
),
3145 bfa_msgq_cmd_post(&tx
->bna
->msgq
, &tx
->msgq_cmd
);
3149 bna_tx_enet_stop(struct bna_tx
*tx
)
3151 struct bna_txq
*txq
;
3154 list_for_each_entry(txq
, &tx
->txq_q
, qe
)
3155 bna_ib_stop(tx
->bna
, &txq
->ib
);
3157 bna_bfi_tx_enet_stop(tx
);
3161 bna_txq_qpt_setup(struct bna_txq
*txq
, int page_count
, int page_size
,
3162 struct bna_mem_descr
*qpt_mem
,
3163 struct bna_mem_descr
*swqpt_mem
,
3164 struct bna_mem_descr
*page_mem
)
3168 struct bna_dma_addr bna_dma
;
3171 txq
->qpt
.hw_qpt_ptr
.lsb
= qpt_mem
->dma
.lsb
;
3172 txq
->qpt
.hw_qpt_ptr
.msb
= qpt_mem
->dma
.msb
;
3173 txq
->qpt
.kv_qpt_ptr
= qpt_mem
->kva
;
3174 txq
->qpt
.page_count
= page_count
;
3175 txq
->qpt
.page_size
= page_size
;
3177 txq
->tcb
->sw_qpt
= (void **) swqpt_mem
->kva
;
3178 txq
->tcb
->sw_q
= page_mem
->kva
;
3180 kva
= page_mem
->kva
;
3181 BNA_GET_DMA_ADDR(&page_mem
->dma
, dma
);
3183 for (i
= 0; i
< page_count
; i
++) {
3184 txq
->tcb
->sw_qpt
[i
] = kva
;
3187 BNA_SET_DMA_ADDR(dma
, &bna_dma
);
3188 ((struct bna_dma_addr
*)txq
->qpt
.kv_qpt_ptr
)[i
].lsb
=
3190 ((struct bna_dma_addr
*)txq
->qpt
.kv_qpt_ptr
)[i
].msb
=
3196 static struct bna_tx
*
3197 bna_tx_get(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
)
3199 struct bna_tx
*tx
= NULL
;
3201 if (list_empty(&tx_mod
->tx_free_q
))
3203 if (type
== BNA_TX_T_REGULAR
)
3204 tx
= list_first_entry(&tx_mod
->tx_free_q
, struct bna_tx
, qe
);
3206 tx
= list_last_entry(&tx_mod
->tx_free_q
, struct bna_tx
, qe
);
3214 bna_tx_free(struct bna_tx
*tx
)
3216 struct bna_tx_mod
*tx_mod
= &tx
->bna
->tx_mod
;
3217 struct bna_txq
*txq
;
3218 struct list_head
*qe
;
3220 while (!list_empty(&tx
->txq_q
)) {
3221 txq
= list_first_entry(&tx
->txq_q
, struct bna_txq
, qe
);
3224 list_move_tail(&txq
->qe
, &tx_mod
->txq_free_q
);
3227 list_for_each(qe
, &tx_mod
->tx_active_q
) {
3228 if (qe
== &tx
->qe
) {
3237 list_for_each_prev(qe
, &tx_mod
->tx_free_q
)
3238 if (((struct bna_tx
*)qe
)->rid
< tx
->rid
)
3241 list_add(&tx
->qe
, qe
);
3245 bna_tx_start(struct bna_tx
*tx
)
3247 tx
->flags
|= BNA_TX_F_ENET_STARTED
;
3248 if (tx
->flags
& BNA_TX_F_ENABLED
)
3249 bfa_fsm_send_event(tx
, TX_E_START
);
3253 bna_tx_stop(struct bna_tx
*tx
)
3255 tx
->stop_cbfn
= bna_tx_mod_cb_tx_stopped
;
3256 tx
->stop_cbarg
= &tx
->bna
->tx_mod
;
3258 tx
->flags
&= ~BNA_TX_F_ENET_STARTED
;
3259 bfa_fsm_send_event(tx
, TX_E_STOP
);
3263 bna_tx_fail(struct bna_tx
*tx
)
3265 tx
->flags
&= ~BNA_TX_F_ENET_STARTED
;
3266 bfa_fsm_send_event(tx
, TX_E_FAIL
);
3270 bna_bfi_tx_enet_start_rsp(struct bna_tx
*tx
, struct bfi_msgq_mhdr
*msghdr
)
3272 struct bfi_enet_tx_cfg_rsp
*cfg_rsp
= &tx
->bfi_enet_cmd
.cfg_rsp
;
3273 struct bna_txq
*txq
= NULL
;
3276 bfa_msgq_rsp_copy(&tx
->bna
->msgq
, (u8
*)cfg_rsp
,
3277 sizeof(struct bfi_enet_tx_cfg_rsp
));
3279 tx
->hw_id
= cfg_rsp
->hw_id
;
3281 for (i
= 0, txq
= list_first_entry(&tx
->txq_q
, struct bna_txq
, qe
);
3282 i
< tx
->num_txq
; i
++, txq
= list_next_entry(txq
, qe
)) {
3283 /* Setup doorbells */
3284 txq
->tcb
->i_dbell
->doorbell_addr
=
3285 tx
->bna
->pcidev
.pci_bar_kva
3286 + ntohl(cfg_rsp
->q_handles
[i
].i_dbell
);
3288 tx
->bna
->pcidev
.pci_bar_kva
3289 + ntohl(cfg_rsp
->q_handles
[i
].q_dbell
);
3290 txq
->hw_id
= cfg_rsp
->q_handles
[i
].hw_qid
;
3292 /* Initialize producer/consumer indexes */
3293 (*txq
->tcb
->hw_consumer_index
) = 0;
3294 txq
->tcb
->producer_index
= txq
->tcb
->consumer_index
= 0;
3297 bfa_fsm_send_event(tx
, TX_E_STARTED
);
3301 bna_bfi_tx_enet_stop_rsp(struct bna_tx
*tx
, struct bfi_msgq_mhdr
*msghdr
)
3303 bfa_fsm_send_event(tx
, TX_E_STOPPED
);
3307 bna_bfi_bw_update_aen(struct bna_tx_mod
*tx_mod
)
3311 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3312 bfa_fsm_send_event(tx
, TX_E_BW_UPDATE
);
3316 bna_tx_res_req(int num_txq
, int txq_depth
, struct bna_res_info
*res_info
)
3320 struct bna_mem_info
*mem_info
;
3322 res_info
[BNA_TX_RES_MEM_T_TCB
].res_type
= BNA_RES_T_MEM
;
3323 mem_info
= &res_info
[BNA_TX_RES_MEM_T_TCB
].res_u
.mem_info
;
3324 mem_info
->mem_type
= BNA_MEM_T_KVA
;
3325 mem_info
->len
= sizeof(struct bna_tcb
);
3326 mem_info
->num
= num_txq
;
3328 q_size
= txq_depth
* BFI_TXQ_WI_SIZE
;
3329 q_size
= ALIGN(q_size
, PAGE_SIZE
);
3330 page_count
= q_size
>> PAGE_SHIFT
;
3332 res_info
[BNA_TX_RES_MEM_T_QPT
].res_type
= BNA_RES_T_MEM
;
3333 mem_info
= &res_info
[BNA_TX_RES_MEM_T_QPT
].res_u
.mem_info
;
3334 mem_info
->mem_type
= BNA_MEM_T_DMA
;
3335 mem_info
->len
= page_count
* sizeof(struct bna_dma_addr
);
3336 mem_info
->num
= num_txq
;
3338 res_info
[BNA_TX_RES_MEM_T_SWQPT
].res_type
= BNA_RES_T_MEM
;
3339 mem_info
= &res_info
[BNA_TX_RES_MEM_T_SWQPT
].res_u
.mem_info
;
3340 mem_info
->mem_type
= BNA_MEM_T_KVA
;
3341 mem_info
->len
= page_count
* sizeof(void *);
3342 mem_info
->num
= num_txq
;
3344 res_info
[BNA_TX_RES_MEM_T_PAGE
].res_type
= BNA_RES_T_MEM
;
3345 mem_info
= &res_info
[BNA_TX_RES_MEM_T_PAGE
].res_u
.mem_info
;
3346 mem_info
->mem_type
= BNA_MEM_T_DMA
;
3347 mem_info
->len
= PAGE_SIZE
* page_count
;
3348 mem_info
->num
= num_txq
;
3350 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_type
= BNA_RES_T_MEM
;
3351 mem_info
= &res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
;
3352 mem_info
->mem_type
= BNA_MEM_T_DMA
;
3353 mem_info
->len
= BFI_IBIDX_SIZE
;
3354 mem_info
->num
= num_txq
;
3356 res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_type
= BNA_RES_T_INTR
;
3357 res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
.intr_type
=
3359 res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
.num
= num_txq
;
3363 bna_tx_create(struct bna
*bna
, struct bnad
*bnad
,
3364 struct bna_tx_config
*tx_cfg
,
3365 const struct bna_tx_event_cbfn
*tx_cbfn
,
3366 struct bna_res_info
*res_info
, void *priv
)
3368 struct bna_intr_info
*intr_info
;
3369 struct bna_tx_mod
*tx_mod
= &bna
->tx_mod
;
3371 struct bna_txq
*txq
;
3375 intr_info
= &res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
;
3376 page_count
= (res_info
[BNA_TX_RES_MEM_T_PAGE
].res_u
.mem_info
.len
) /
3383 if ((intr_info
->num
!= 1) && (intr_info
->num
!= tx_cfg
->num_txq
))
3388 tx
= bna_tx_get(tx_mod
, tx_cfg
->tx_type
);
3396 INIT_LIST_HEAD(&tx
->txq_q
);
3397 for (i
= 0; i
< tx_cfg
->num_txq
; i
++) {
3398 if (list_empty(&tx_mod
->txq_free_q
))
3401 txq
= list_first_entry(&tx_mod
->txq_free_q
, struct bna_txq
, qe
);
3402 list_move_tail(&txq
->qe
, &tx
->txq_q
);
3412 tx
->tcb_setup_cbfn
= tx_cbfn
->tcb_setup_cbfn
;
3413 tx
->tcb_destroy_cbfn
= tx_cbfn
->tcb_destroy_cbfn
;
3414 /* Following callbacks are mandatory */
3415 tx
->tx_stall_cbfn
= tx_cbfn
->tx_stall_cbfn
;
3416 tx
->tx_resume_cbfn
= tx_cbfn
->tx_resume_cbfn
;
3417 tx
->tx_cleanup_cbfn
= tx_cbfn
->tx_cleanup_cbfn
;
3419 list_add_tail(&tx
->qe
, &tx_mod
->tx_active_q
);
3421 tx
->num_txq
= tx_cfg
->num_txq
;
3424 if (tx
->bna
->tx_mod
.flags
& BNA_TX_MOD_F_ENET_STARTED
) {
3426 case BNA_TX_T_REGULAR
:
3427 if (!(tx
->bna
->tx_mod
.flags
&
3428 BNA_TX_MOD_F_ENET_LOOPBACK
))
3429 tx
->flags
|= BNA_TX_F_ENET_STARTED
;
3431 case BNA_TX_T_LOOPBACK
:
3432 if (tx
->bna
->tx_mod
.flags
& BNA_TX_MOD_F_ENET_LOOPBACK
)
3433 tx
->flags
|= BNA_TX_F_ENET_STARTED
;
3441 list_for_each_entry(txq
, &tx
->txq_q
, qe
) {
3442 txq
->tcb
= (struct bna_tcb
*)
3443 res_info
[BNA_TX_RES_MEM_T_TCB
].res_u
.mem_info
.mdl
[i
].kva
;
3444 txq
->tx_packets
= 0;
3448 txq
->ib
.ib_seg_host_addr
.lsb
=
3449 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.lsb
;
3450 txq
->ib
.ib_seg_host_addr
.msb
=
3451 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.msb
;
3452 txq
->ib
.ib_seg_host_addr_kva
=
3453 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].kva
;
3454 txq
->ib
.intr_type
= intr_info
->intr_type
;
3455 txq
->ib
.intr_vector
= (intr_info
->num
== 1) ?
3456 intr_info
->idl
[0].vector
:
3457 intr_info
->idl
[i
].vector
;
3458 if (intr_info
->intr_type
== BNA_INTR_T_INTX
)
3459 txq
->ib
.intr_vector
= BIT(txq
->ib
.intr_vector
);
3460 txq
->ib
.coalescing_timeo
= tx_cfg
->coalescing_timeo
;
3461 txq
->ib
.interpkt_timeo
= BFI_TX_INTERPKT_TIMEO
;
3462 txq
->ib
.interpkt_count
= BFI_TX_INTERPKT_COUNT
;
3466 txq
->tcb
->q_depth
= tx_cfg
->txq_depth
;
3467 txq
->tcb
->unmap_q
= (void *)
3468 res_info
[BNA_TX_RES_MEM_T_UNMAPQ
].res_u
.mem_info
.mdl
[i
].kva
;
3469 txq
->tcb
->hw_consumer_index
=
3470 (u32
*)txq
->ib
.ib_seg_host_addr_kva
;
3471 txq
->tcb
->i_dbell
= &txq
->ib
.door_bell
;
3472 txq
->tcb
->intr_type
= txq
->ib
.intr_type
;
3473 txq
->tcb
->intr_vector
= txq
->ib
.intr_vector
;
3474 txq
->tcb
->txq
= txq
;
3475 txq
->tcb
->bnad
= bnad
;
3478 /* QPT, SWQPT, Pages */
3479 bna_txq_qpt_setup(txq
, page_count
, PAGE_SIZE
,
3480 &res_info
[BNA_TX_RES_MEM_T_QPT
].res_u
.mem_info
.mdl
[i
],
3481 &res_info
[BNA_TX_RES_MEM_T_SWQPT
].res_u
.mem_info
.mdl
[i
],
3482 &res_info
[BNA_TX_RES_MEM_T_PAGE
].
3483 res_u
.mem_info
.mdl
[i
]);
3485 /* Callback to bnad for setting up TCB */
3486 if (tx
->tcb_setup_cbfn
)
3487 (tx
->tcb_setup_cbfn
)(bna
->bnad
, txq
->tcb
);
3489 if (tx_cfg
->num_txq
== BFI_TX_MAX_PRIO
)
3490 txq
->priority
= txq
->tcb
->id
;
3492 txq
->priority
= tx_mod
->default_prio
;
3497 tx
->txf_vlan_id
= 0;
3499 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
3501 tx_mod
->rid_mask
|= BIT(tx
->rid
);
3511 bna_tx_destroy(struct bna_tx
*tx
)
3513 struct bna_txq
*txq
;
3515 list_for_each_entry(txq
, &tx
->txq_q
, qe
)
3516 if (tx
->tcb_destroy_cbfn
)
3517 (tx
->tcb_destroy_cbfn
)(tx
->bna
->bnad
, txq
->tcb
);
3519 tx
->bna
->tx_mod
.rid_mask
&= ~BIT(tx
->rid
);
3524 bna_tx_enable(struct bna_tx
*tx
)
3526 if (tx
->fsm
!= (bfa_sm_t
)bna_tx_sm_stopped
)
3529 tx
->flags
|= BNA_TX_F_ENABLED
;
3531 if (tx
->flags
& BNA_TX_F_ENET_STARTED
)
3532 bfa_fsm_send_event(tx
, TX_E_START
);
3536 bna_tx_disable(struct bna_tx
*tx
, enum bna_cleanup_type type
,
3537 void (*cbfn
)(void *, struct bna_tx
*))
3539 if (type
== BNA_SOFT_CLEANUP
) {
3540 (*cbfn
)(tx
->bna
->bnad
, tx
);
3544 tx
->stop_cbfn
= cbfn
;
3545 tx
->stop_cbarg
= tx
->bna
->bnad
;
3547 tx
->flags
&= ~BNA_TX_F_ENABLED
;
3549 bfa_fsm_send_event(tx
, TX_E_STOP
);
3553 bna_tx_cleanup_complete(struct bna_tx
*tx
)
3555 bfa_fsm_send_event(tx
, TX_E_CLEANUP_DONE
);
3559 bna_tx_mod_cb_tx_stopped(void *arg
, struct bna_tx
*tx
)
3561 struct bna_tx_mod
*tx_mod
= (struct bna_tx_mod
*)arg
;
3563 bfa_wc_down(&tx_mod
->tx_stop_wc
);
3567 bna_tx_mod_cb_tx_stopped_all(void *arg
)
3569 struct bna_tx_mod
*tx_mod
= (struct bna_tx_mod
*)arg
;
3571 if (tx_mod
->stop_cbfn
)
3572 tx_mod
->stop_cbfn(&tx_mod
->bna
->enet
);
3573 tx_mod
->stop_cbfn
= NULL
;
3577 bna_tx_mod_init(struct bna_tx_mod
*tx_mod
, struct bna
*bna
,
3578 struct bna_res_info
*res_info
)
3585 tx_mod
->tx
= (struct bna_tx
*)
3586 res_info
[BNA_MOD_RES_MEM_T_TX_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
3587 tx_mod
->txq
= (struct bna_txq
*)
3588 res_info
[BNA_MOD_RES_MEM_T_TXQ_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
3590 INIT_LIST_HEAD(&tx_mod
->tx_free_q
);
3591 INIT_LIST_HEAD(&tx_mod
->tx_active_q
);
3593 INIT_LIST_HEAD(&tx_mod
->txq_free_q
);
3595 for (i
= 0; i
< bna
->ioceth
.attr
.num_txq
; i
++) {
3596 tx_mod
->tx
[i
].rid
= i
;
3597 list_add_tail(&tx_mod
->tx
[i
].qe
, &tx_mod
->tx_free_q
);
3598 list_add_tail(&tx_mod
->txq
[i
].qe
, &tx_mod
->txq_free_q
);
3601 tx_mod
->prio_map
= BFI_TX_PRIO_MAP_ALL
;
3602 tx_mod
->default_prio
= 0;
3603 tx_mod
->iscsi_over_cee
= BNA_STATUS_T_DISABLED
;
3604 tx_mod
->iscsi_prio
= -1;
3608 bna_tx_mod_uninit(struct bna_tx_mod
*tx_mod
)
3614 bna_tx_mod_start(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
)
3618 tx_mod
->flags
|= BNA_TX_MOD_F_ENET_STARTED
;
3619 if (type
== BNA_TX_T_LOOPBACK
)
3620 tx_mod
->flags
|= BNA_TX_MOD_F_ENET_LOOPBACK
;
3622 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3623 if (tx
->type
== type
)
3628 bna_tx_mod_stop(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
)
3632 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_STARTED
;
3633 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_LOOPBACK
;
3635 tx_mod
->stop_cbfn
= bna_enet_cb_tx_stopped
;
3637 bfa_wc_init(&tx_mod
->tx_stop_wc
, bna_tx_mod_cb_tx_stopped_all
, tx_mod
);
3639 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3640 if (tx
->type
== type
) {
3641 bfa_wc_up(&tx_mod
->tx_stop_wc
);
3645 bfa_wc_wait(&tx_mod
->tx_stop_wc
);
3649 bna_tx_mod_fail(struct bna_tx_mod
*tx_mod
)
3653 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_STARTED
;
3654 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_LOOPBACK
;
3656 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3661 bna_tx_coalescing_timeo_set(struct bna_tx
*tx
, int coalescing_timeo
)
3663 struct bna_txq
*txq
;
3665 list_for_each_entry(txq
, &tx
->txq_q
, qe
)
3666 bna_ib_coalescing_timeo_set(&txq
->ib
, coalescing_timeo
);