2 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15 * Copyright (c) 2014-2015 QLogic Corporation
24 bna_ib_coalescing_timeo_set(struct bna_ib
*ib
, u8 coalescing_timeo
)
26 ib
->coalescing_timeo
= coalescing_timeo
;
27 ib
->door_bell
.doorbell_ack
= BNA_DOORBELL_IB_INT_ACK(
28 (u32
)ib
->coalescing_timeo
, 0);
33 #define bna_rxf_vlan_cfg_soft_reset(rxf) \
35 (rxf)->vlan_pending_bitmask = (u8)BFI_VLAN_BMASK_ALL; \
36 (rxf)->vlan_strip_pending = true; \
39 #define bna_rxf_rss_cfg_soft_reset(rxf) \
41 if ((rxf)->rss_status == BNA_STATUS_T_ENABLED) \
42 (rxf)->rss_pending = (BNA_RSS_F_RIT_PENDING | \
43 BNA_RSS_F_CFG_PENDING | \
44 BNA_RSS_F_STATUS_PENDING); \
47 static int bna_rxf_cfg_apply(struct bna_rxf
*rxf
);
48 static void bna_rxf_cfg_reset(struct bna_rxf
*rxf
);
49 static int bna_rxf_ucast_cfg_apply(struct bna_rxf
*rxf
);
50 static int bna_rxf_promisc_cfg_apply(struct bna_rxf
*rxf
);
51 static int bna_rxf_allmulti_cfg_apply(struct bna_rxf
*rxf
);
52 static int bna_rxf_vlan_strip_cfg_apply(struct bna_rxf
*rxf
);
53 static int bna_rxf_ucast_cfg_reset(struct bna_rxf
*rxf
,
54 enum bna_cleanup_type cleanup
);
55 static int bna_rxf_promisc_cfg_reset(struct bna_rxf
*rxf
,
56 enum bna_cleanup_type cleanup
);
57 static int bna_rxf_allmulti_cfg_reset(struct bna_rxf
*rxf
,
58 enum bna_cleanup_type cleanup
);
60 bfa_fsm_state_decl(bna_rxf
, stopped
, struct bna_rxf
,
62 bfa_fsm_state_decl(bna_rxf
, cfg_wait
, struct bna_rxf
,
64 bfa_fsm_state_decl(bna_rxf
, started
, struct bna_rxf
,
66 bfa_fsm_state_decl(bna_rxf
, last_resp_wait
, struct bna_rxf
,
70 bna_rxf_sm_stopped_entry(struct bna_rxf
*rxf
)
72 call_rxf_stop_cbfn(rxf
);
76 bna_rxf_sm_stopped(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
80 bfa_fsm_set_state(rxf
, bna_rxf_sm_cfg_wait
);
84 call_rxf_stop_cbfn(rxf
);
92 call_rxf_cam_fltr_cbfn(rxf
);
101 bna_rxf_sm_cfg_wait_entry(struct bna_rxf
*rxf
)
103 if (!bna_rxf_cfg_apply(rxf
)) {
104 /* No more pending config updates */
105 bfa_fsm_set_state(rxf
, bna_rxf_sm_started
);
110 bna_rxf_sm_cfg_wait(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
114 bfa_fsm_set_state(rxf
, bna_rxf_sm_last_resp_wait
);
118 bna_rxf_cfg_reset(rxf
);
119 call_rxf_start_cbfn(rxf
);
120 call_rxf_cam_fltr_cbfn(rxf
);
121 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
129 if (!bna_rxf_cfg_apply(rxf
)) {
130 /* No more pending config updates */
131 bfa_fsm_set_state(rxf
, bna_rxf_sm_started
);
141 bna_rxf_sm_started_entry(struct bna_rxf
*rxf
)
143 call_rxf_start_cbfn(rxf
);
144 call_rxf_cam_fltr_cbfn(rxf
);
148 bna_rxf_sm_started(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
153 bna_rxf_cfg_reset(rxf
);
154 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
158 bfa_fsm_set_state(rxf
, bna_rxf_sm_cfg_wait
);
167 bna_rxf_sm_last_resp_wait_entry(struct bna_rxf
*rxf
)
172 bna_rxf_sm_last_resp_wait(struct bna_rxf
*rxf
, enum bna_rxf_event event
)
177 bna_rxf_cfg_reset(rxf
);
178 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
187 bna_bfi_ucast_req(struct bna_rxf
*rxf
, struct bna_mac
*mac
,
188 enum bfi_enet_h2i_msgs req_type
)
190 struct bfi_enet_ucast_req
*req
= &rxf
->bfi_enet_cmd
.ucast_req
;
192 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
, req_type
, 0, rxf
->rx
->rid
);
193 req
->mh
.num_entries
= htons(
194 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_ucast_req
)));
195 ether_addr_copy(req
->mac_addr
, mac
->addr
);
196 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
197 sizeof(struct bfi_enet_ucast_req
), &req
->mh
);
198 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
202 bna_bfi_mcast_add_req(struct bna_rxf
*rxf
, struct bna_mac
*mac
)
204 struct bfi_enet_mcast_add_req
*req
=
205 &rxf
->bfi_enet_cmd
.mcast_add_req
;
207 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
, BFI_ENET_H2I_MAC_MCAST_ADD_REQ
,
209 req
->mh
.num_entries
= htons(
210 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_mcast_add_req
)));
211 ether_addr_copy(req
->mac_addr
, mac
->addr
);
212 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
213 sizeof(struct bfi_enet_mcast_add_req
), &req
->mh
);
214 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
218 bna_bfi_mcast_del_req(struct bna_rxf
*rxf
, u16 handle
)
220 struct bfi_enet_mcast_del_req
*req
=
221 &rxf
->bfi_enet_cmd
.mcast_del_req
;
223 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
, BFI_ENET_H2I_MAC_MCAST_DEL_REQ
,
225 req
->mh
.num_entries
= htons(
226 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_mcast_del_req
)));
227 req
->handle
= htons(handle
);
228 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
229 sizeof(struct bfi_enet_mcast_del_req
), &req
->mh
);
230 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
234 bna_bfi_mcast_filter_req(struct bna_rxf
*rxf
, enum bna_status status
)
236 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
238 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
239 BFI_ENET_H2I_MAC_MCAST_FILTER_REQ
, 0, rxf
->rx
->rid
);
240 req
->mh
.num_entries
= htons(
241 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
242 req
->enable
= status
;
243 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
244 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
245 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
249 bna_bfi_rx_promisc_req(struct bna_rxf
*rxf
, enum bna_status status
)
251 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
253 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
254 BFI_ENET_H2I_RX_PROMISCUOUS_REQ
, 0, rxf
->rx
->rid
);
255 req
->mh
.num_entries
= htons(
256 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
257 req
->enable
= status
;
258 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
259 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
260 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
264 bna_bfi_rx_vlan_filter_set(struct bna_rxf
*rxf
, u8 block_idx
)
266 struct bfi_enet_rx_vlan_req
*req
= &rxf
->bfi_enet_cmd
.vlan_req
;
270 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
271 BFI_ENET_H2I_RX_VLAN_SET_REQ
, 0, rxf
->rx
->rid
);
272 req
->mh
.num_entries
= htons(
273 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rx_vlan_req
)));
274 req
->block_idx
= block_idx
;
275 for (i
= 0; i
< (BFI_ENET_VLAN_BLOCK_SIZE
/ 32); i
++) {
276 j
= (block_idx
* (BFI_ENET_VLAN_BLOCK_SIZE
/ 32)) + i
;
277 if (rxf
->vlan_filter_status
== BNA_STATUS_T_ENABLED
)
279 htonl(rxf
->vlan_filter_table
[j
]);
281 req
->bit_mask
[i
] = 0xFFFFFFFF;
283 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
284 sizeof(struct bfi_enet_rx_vlan_req
), &req
->mh
);
285 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
289 bna_bfi_vlan_strip_enable(struct bna_rxf
*rxf
)
291 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
293 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
294 BFI_ENET_H2I_RX_VLAN_STRIP_ENABLE_REQ
, 0, rxf
->rx
->rid
);
295 req
->mh
.num_entries
= htons(
296 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
297 req
->enable
= rxf
->vlan_strip_status
;
298 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
299 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
300 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
304 bna_bfi_rit_cfg(struct bna_rxf
*rxf
)
306 struct bfi_enet_rit_req
*req
= &rxf
->bfi_enet_cmd
.rit_req
;
308 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
309 BFI_ENET_H2I_RIT_CFG_REQ
, 0, rxf
->rx
->rid
);
310 req
->mh
.num_entries
= htons(
311 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rit_req
)));
312 req
->size
= htons(rxf
->rit_size
);
313 memcpy(&req
->table
[0], rxf
->rit
, rxf
->rit_size
);
314 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
315 sizeof(struct bfi_enet_rit_req
), &req
->mh
);
316 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
320 bna_bfi_rss_cfg(struct bna_rxf
*rxf
)
322 struct bfi_enet_rss_cfg_req
*req
= &rxf
->bfi_enet_cmd
.rss_req
;
325 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
326 BFI_ENET_H2I_RSS_CFG_REQ
, 0, rxf
->rx
->rid
);
327 req
->mh
.num_entries
= htons(
328 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rss_cfg_req
)));
329 req
->cfg
.type
= rxf
->rss_cfg
.hash_type
;
330 req
->cfg
.mask
= rxf
->rss_cfg
.hash_mask
;
331 for (i
= 0; i
< BFI_ENET_RSS_KEY_LEN
; i
++)
333 htonl(rxf
->rss_cfg
.toeplitz_hash_key
[i
]);
334 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
335 sizeof(struct bfi_enet_rss_cfg_req
), &req
->mh
);
336 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
340 bna_bfi_rss_enable(struct bna_rxf
*rxf
)
342 struct bfi_enet_enable_req
*req
= &rxf
->bfi_enet_cmd
.req
;
344 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
345 BFI_ENET_H2I_RSS_ENABLE_REQ
, 0, rxf
->rx
->rid
);
346 req
->mh
.num_entries
= htons(
347 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req
)));
348 req
->enable
= rxf
->rss_status
;
349 bfa_msgq_cmd_set(&rxf
->msgq_cmd
, NULL
, NULL
,
350 sizeof(struct bfi_enet_enable_req
), &req
->mh
);
351 bfa_msgq_cmd_post(&rxf
->rx
->bna
->msgq
, &rxf
->msgq_cmd
);
354 /* This function gets the multicast MAC that has already been added to CAM */
355 static struct bna_mac
*
356 bna_rxf_mcmac_get(struct bna_rxf
*rxf
, const u8
*mac_addr
)
360 list_for_each_entry(mac
, &rxf
->mcast_active_q
, qe
)
361 if (ether_addr_equal(mac
->addr
, mac_addr
))
364 list_for_each_entry(mac
, &rxf
->mcast_pending_del_q
, qe
)
365 if (ether_addr_equal(mac
->addr
, mac_addr
))
371 static struct bna_mcam_handle
*
372 bna_rxf_mchandle_get(struct bna_rxf
*rxf
, int handle
)
374 struct bna_mcam_handle
*mchandle
;
376 list_for_each_entry(mchandle
, &rxf
->mcast_handle_q
, qe
)
377 if (mchandle
->handle
== handle
)
384 bna_rxf_mchandle_attach(struct bna_rxf
*rxf
, u8
*mac_addr
, int handle
)
386 struct bna_mac
*mcmac
;
387 struct bna_mcam_handle
*mchandle
;
389 mcmac
= bna_rxf_mcmac_get(rxf
, mac_addr
);
390 mchandle
= bna_rxf_mchandle_get(rxf
, handle
);
391 if (mchandle
== NULL
) {
392 mchandle
= bna_mcam_mod_handle_get(&rxf
->rx
->bna
->mcam_mod
);
393 mchandle
->handle
= handle
;
394 mchandle
->refcnt
= 0;
395 list_add_tail(&mchandle
->qe
, &rxf
->mcast_handle_q
);
398 mcmac
->handle
= mchandle
;
402 bna_rxf_mcast_del(struct bna_rxf
*rxf
, struct bna_mac
*mac
,
403 enum bna_cleanup_type cleanup
)
405 struct bna_mcam_handle
*mchandle
;
408 mchandle
= mac
->handle
;
409 if (mchandle
== NULL
)
413 if (mchandle
->refcnt
== 0) {
414 if (cleanup
== BNA_HARD_CLEANUP
) {
415 bna_bfi_mcast_del_req(rxf
, mchandle
->handle
);
418 list_del(&mchandle
->qe
);
419 bna_mcam_mod_handle_put(&rxf
->rx
->bna
->mcam_mod
, mchandle
);
427 bna_rxf_mcast_cfg_apply(struct bna_rxf
*rxf
)
429 struct bna_mac
*mac
= NULL
;
432 /* First delete multicast entries to maintain the count */
433 while (!list_empty(&rxf
->mcast_pending_del_q
)) {
434 mac
= list_first_entry(&rxf
->mcast_pending_del_q
,
436 ret
= bna_rxf_mcast_del(rxf
, mac
, BNA_HARD_CLEANUP
);
437 list_move_tail(&mac
->qe
, bna_mcam_mod_del_q(rxf
->rx
->bna
));
442 /* Add multicast entries */
443 if (!list_empty(&rxf
->mcast_pending_add_q
)) {
444 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
446 list_move_tail(&mac
->qe
, &rxf
->mcast_active_q
);
447 bna_bfi_mcast_add_req(rxf
, mac
);
455 bna_rxf_vlan_cfg_apply(struct bna_rxf
*rxf
)
457 u8 vlan_pending_bitmask
;
460 if (rxf
->vlan_pending_bitmask
) {
461 vlan_pending_bitmask
= rxf
->vlan_pending_bitmask
;
462 while (!(vlan_pending_bitmask
& 0x1)) {
464 vlan_pending_bitmask
>>= 1;
466 rxf
->vlan_pending_bitmask
&= ~BIT(block_idx
);
467 bna_bfi_rx_vlan_filter_set(rxf
, block_idx
);
475 bna_rxf_mcast_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
480 /* Throw away delete pending mcast entries */
481 while (!list_empty(&rxf
->mcast_pending_del_q
)) {
482 mac
= list_first_entry(&rxf
->mcast_pending_del_q
,
484 ret
= bna_rxf_mcast_del(rxf
, mac
, cleanup
);
485 list_move_tail(&mac
->qe
, bna_mcam_mod_del_q(rxf
->rx
->bna
));
490 /* Move active mcast entries to pending_add_q */
491 while (!list_empty(&rxf
->mcast_active_q
)) {
492 mac
= list_first_entry(&rxf
->mcast_active_q
,
494 list_move_tail(&mac
->qe
, &rxf
->mcast_pending_add_q
);
495 if (bna_rxf_mcast_del(rxf
, mac
, cleanup
))
503 bna_rxf_rss_cfg_apply(struct bna_rxf
*rxf
)
505 if (rxf
->rss_pending
) {
506 if (rxf
->rss_pending
& BNA_RSS_F_RIT_PENDING
) {
507 rxf
->rss_pending
&= ~BNA_RSS_F_RIT_PENDING
;
508 bna_bfi_rit_cfg(rxf
);
512 if (rxf
->rss_pending
& BNA_RSS_F_CFG_PENDING
) {
513 rxf
->rss_pending
&= ~BNA_RSS_F_CFG_PENDING
;
514 bna_bfi_rss_cfg(rxf
);
518 if (rxf
->rss_pending
& BNA_RSS_F_STATUS_PENDING
) {
519 rxf
->rss_pending
&= ~BNA_RSS_F_STATUS_PENDING
;
520 bna_bfi_rss_enable(rxf
);
529 bna_rxf_cfg_apply(struct bna_rxf
*rxf
)
531 if (bna_rxf_ucast_cfg_apply(rxf
))
534 if (bna_rxf_mcast_cfg_apply(rxf
))
537 if (bna_rxf_promisc_cfg_apply(rxf
))
540 if (bna_rxf_allmulti_cfg_apply(rxf
))
543 if (bna_rxf_vlan_cfg_apply(rxf
))
546 if (bna_rxf_vlan_strip_cfg_apply(rxf
))
549 if (bna_rxf_rss_cfg_apply(rxf
))
556 bna_rxf_cfg_reset(struct bna_rxf
*rxf
)
558 bna_rxf_ucast_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
559 bna_rxf_mcast_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
560 bna_rxf_promisc_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
561 bna_rxf_allmulti_cfg_reset(rxf
, BNA_SOFT_CLEANUP
);
562 bna_rxf_vlan_cfg_soft_reset(rxf
);
563 bna_rxf_rss_cfg_soft_reset(rxf
);
567 bna_rit_init(struct bna_rxf
*rxf
, int rit_size
)
569 struct bna_rx
*rx
= rxf
->rx
;
573 rxf
->rit_size
= rit_size
;
574 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
) {
575 rxf
->rit
[offset
] = rxp
->cq
.ccb
->id
;
581 bna_bfi_rxf_cfg_rsp(struct bna_rxf
*rxf
, struct bfi_msgq_mhdr
*msghdr
)
583 bfa_fsm_send_event(rxf
, RXF_E_FW_RESP
);
587 bna_bfi_rxf_ucast_set_rsp(struct bna_rxf
*rxf
,
588 struct bfi_msgq_mhdr
*msghdr
)
590 struct bfi_enet_rsp
*rsp
=
591 container_of(msghdr
, struct bfi_enet_rsp
, mh
);
594 /* Clear ucast from cache */
595 rxf
->ucast_active_set
= 0;
598 bfa_fsm_send_event(rxf
, RXF_E_FW_RESP
);
602 bna_bfi_rxf_mcast_add_rsp(struct bna_rxf
*rxf
,
603 struct bfi_msgq_mhdr
*msghdr
)
605 struct bfi_enet_mcast_add_req
*req
=
606 &rxf
->bfi_enet_cmd
.mcast_add_req
;
607 struct bfi_enet_mcast_add_rsp
*rsp
=
608 container_of(msghdr
, struct bfi_enet_mcast_add_rsp
, mh
);
610 bna_rxf_mchandle_attach(rxf
, (u8
*)&req
->mac_addr
,
612 bfa_fsm_send_event(rxf
, RXF_E_FW_RESP
);
616 bna_rxf_init(struct bna_rxf
*rxf
,
618 struct bna_rx_config
*q_config
,
619 struct bna_res_info
*res_info
)
623 INIT_LIST_HEAD(&rxf
->ucast_pending_add_q
);
624 INIT_LIST_HEAD(&rxf
->ucast_pending_del_q
);
625 rxf
->ucast_pending_set
= 0;
626 rxf
->ucast_active_set
= 0;
627 INIT_LIST_HEAD(&rxf
->ucast_active_q
);
628 rxf
->ucast_pending_mac
= NULL
;
630 INIT_LIST_HEAD(&rxf
->mcast_pending_add_q
);
631 INIT_LIST_HEAD(&rxf
->mcast_pending_del_q
);
632 INIT_LIST_HEAD(&rxf
->mcast_active_q
);
633 INIT_LIST_HEAD(&rxf
->mcast_handle_q
);
636 res_info
[BNA_RX_RES_MEM_T_RIT
].res_u
.mem_info
.mdl
[0].kva
;
637 bna_rit_init(rxf
, q_config
->num_paths
);
639 rxf
->rss_status
= q_config
->rss_status
;
640 if (rxf
->rss_status
== BNA_STATUS_T_ENABLED
) {
641 rxf
->rss_cfg
= q_config
->rss_config
;
642 rxf
->rss_pending
|= BNA_RSS_F_CFG_PENDING
;
643 rxf
->rss_pending
|= BNA_RSS_F_RIT_PENDING
;
644 rxf
->rss_pending
|= BNA_RSS_F_STATUS_PENDING
;
647 rxf
->vlan_filter_status
= BNA_STATUS_T_DISABLED
;
648 memset(rxf
->vlan_filter_table
, 0,
649 (sizeof(u32
) * (BFI_ENET_VLAN_ID_MAX
/ 32)));
650 rxf
->vlan_filter_table
[0] |= 1; /* for pure priority tagged frames */
651 rxf
->vlan_pending_bitmask
= (u8
)BFI_VLAN_BMASK_ALL
;
653 rxf
->vlan_strip_status
= q_config
->vlan_strip_status
;
655 bfa_fsm_set_state(rxf
, bna_rxf_sm_stopped
);
659 bna_rxf_uninit(struct bna_rxf
*rxf
)
663 rxf
->ucast_pending_set
= 0;
664 rxf
->ucast_active_set
= 0;
666 while (!list_empty(&rxf
->ucast_pending_add_q
)) {
667 mac
= list_first_entry(&rxf
->ucast_pending_add_q
,
669 list_move_tail(&mac
->qe
, bna_ucam_mod_free_q(rxf
->rx
->bna
));
672 if (rxf
->ucast_pending_mac
) {
673 list_add_tail(&rxf
->ucast_pending_mac
->qe
,
674 bna_ucam_mod_free_q(rxf
->rx
->bna
));
675 rxf
->ucast_pending_mac
= NULL
;
678 while (!list_empty(&rxf
->mcast_pending_add_q
)) {
679 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
681 list_move_tail(&mac
->qe
, bna_mcam_mod_free_q(rxf
->rx
->bna
));
684 rxf
->rxmode_pending
= 0;
685 rxf
->rxmode_pending_bitmask
= 0;
686 if (rxf
->rx
->bna
->promisc_rid
== rxf
->rx
->rid
)
687 rxf
->rx
->bna
->promisc_rid
= BFI_INVALID_RID
;
688 if (rxf
->rx
->bna
->default_mode_rid
== rxf
->rx
->rid
)
689 rxf
->rx
->bna
->default_mode_rid
= BFI_INVALID_RID
;
691 rxf
->rss_pending
= 0;
692 rxf
->vlan_strip_pending
= false;
698 bna_rx_cb_rxf_started(struct bna_rx
*rx
)
700 bfa_fsm_send_event(rx
, RX_E_RXF_STARTED
);
704 bna_rxf_start(struct bna_rxf
*rxf
)
706 rxf
->start_cbfn
= bna_rx_cb_rxf_started
;
707 rxf
->start_cbarg
= rxf
->rx
;
708 bfa_fsm_send_event(rxf
, RXF_E_START
);
712 bna_rx_cb_rxf_stopped(struct bna_rx
*rx
)
714 bfa_fsm_send_event(rx
, RX_E_RXF_STOPPED
);
718 bna_rxf_stop(struct bna_rxf
*rxf
)
720 rxf
->stop_cbfn
= bna_rx_cb_rxf_stopped
;
721 rxf
->stop_cbarg
= rxf
->rx
;
722 bfa_fsm_send_event(rxf
, RXF_E_STOP
);
726 bna_rxf_fail(struct bna_rxf
*rxf
)
728 bfa_fsm_send_event(rxf
, RXF_E_FAIL
);
732 bna_rx_ucast_set(struct bna_rx
*rx
, const u8
*ucmac
)
734 struct bna_rxf
*rxf
= &rx
->rxf
;
736 if (rxf
->ucast_pending_mac
== NULL
) {
737 rxf
->ucast_pending_mac
=
738 bna_cam_mod_mac_get(bna_ucam_mod_free_q(rxf
->rx
->bna
));
739 if (rxf
->ucast_pending_mac
== NULL
)
740 return BNA_CB_UCAST_CAM_FULL
;
743 ether_addr_copy(rxf
->ucast_pending_mac
->addr
, ucmac
);
744 rxf
->ucast_pending_set
= 1;
745 rxf
->cam_fltr_cbfn
= NULL
;
746 rxf
->cam_fltr_cbarg
= rx
->bna
->bnad
;
748 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
750 return BNA_CB_SUCCESS
;
754 bna_rx_mcast_add(struct bna_rx
*rx
, const u8
*addr
,
755 void (*cbfn
)(struct bnad
*, struct bna_rx
*))
757 struct bna_rxf
*rxf
= &rx
->rxf
;
760 /* Check if already added or pending addition */
761 if (bna_mac_find(&rxf
->mcast_active_q
, addr
) ||
762 bna_mac_find(&rxf
->mcast_pending_add_q
, addr
)) {
764 cbfn(rx
->bna
->bnad
, rx
);
765 return BNA_CB_SUCCESS
;
768 mac
= bna_cam_mod_mac_get(bna_mcam_mod_free_q(rxf
->rx
->bna
));
770 return BNA_CB_MCAST_LIST_FULL
;
771 ether_addr_copy(mac
->addr
, addr
);
772 list_add_tail(&mac
->qe
, &rxf
->mcast_pending_add_q
);
774 rxf
->cam_fltr_cbfn
= cbfn
;
775 rxf
->cam_fltr_cbarg
= rx
->bna
->bnad
;
777 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
779 return BNA_CB_SUCCESS
;
783 bna_rx_ucast_listset(struct bna_rx
*rx
, int count
, const u8
*uclist
)
785 struct bna_ucam_mod
*ucam_mod
= &rx
->bna
->ucam_mod
;
786 struct bna_rxf
*rxf
= &rx
->rxf
;
787 struct list_head list_head
;
789 struct bna_mac
*mac
, *del_mac
;
792 /* Purge the pending_add_q */
793 while (!list_empty(&rxf
->ucast_pending_add_q
)) {
794 mac
= list_first_entry(&rxf
->ucast_pending_add_q
,
796 list_move_tail(&mac
->qe
, &ucam_mod
->free_q
);
799 /* Schedule active_q entries for deletion */
800 while (!list_empty(&rxf
->ucast_active_q
)) {
801 mac
= list_first_entry(&rxf
->ucast_active_q
,
803 del_mac
= bna_cam_mod_mac_get(&ucam_mod
->del_q
);
804 ether_addr_copy(del_mac
->addr
, mac
->addr
);
805 del_mac
->handle
= mac
->handle
;
806 list_add_tail(&del_mac
->qe
, &rxf
->ucast_pending_del_q
);
807 list_move_tail(&mac
->qe
, &ucam_mod
->free_q
);
811 INIT_LIST_HEAD(&list_head
);
812 for (i
= 0, mcaddr
= uclist
; i
< count
; i
++) {
813 mac
= bna_cam_mod_mac_get(&ucam_mod
->free_q
);
816 ether_addr_copy(mac
->addr
, mcaddr
);
817 list_add_tail(&mac
->qe
, &list_head
);
821 /* Add the new entries */
822 while (!list_empty(&list_head
)) {
823 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
824 list_move_tail(&mac
->qe
, &rxf
->ucast_pending_add_q
);
827 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
829 return BNA_CB_SUCCESS
;
832 while (!list_empty(&list_head
)) {
833 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
834 list_move_tail(&mac
->qe
, &ucam_mod
->free_q
);
837 return BNA_CB_UCAST_CAM_FULL
;
841 bna_rx_mcast_listset(struct bna_rx
*rx
, int count
, const u8
*mclist
)
843 struct bna_mcam_mod
*mcam_mod
= &rx
->bna
->mcam_mod
;
844 struct bna_rxf
*rxf
= &rx
->rxf
;
845 struct list_head list_head
;
847 struct bna_mac
*mac
, *del_mac
;
850 /* Purge the pending_add_q */
851 while (!list_empty(&rxf
->mcast_pending_add_q
)) {
852 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
854 list_move_tail(&mac
->qe
, &mcam_mod
->free_q
);
857 /* Schedule active_q entries for deletion */
858 while (!list_empty(&rxf
->mcast_active_q
)) {
859 mac
= list_first_entry(&rxf
->mcast_active_q
,
861 del_mac
= bna_cam_mod_mac_get(&mcam_mod
->del_q
);
862 ether_addr_copy(del_mac
->addr
, mac
->addr
);
863 del_mac
->handle
= mac
->handle
;
864 list_add_tail(&del_mac
->qe
, &rxf
->mcast_pending_del_q
);
866 list_move_tail(&mac
->qe
, &mcam_mod
->free_q
);
870 INIT_LIST_HEAD(&list_head
);
871 for (i
= 0, mcaddr
= mclist
; i
< count
; i
++) {
872 mac
= bna_cam_mod_mac_get(&mcam_mod
->free_q
);
875 ether_addr_copy(mac
->addr
, mcaddr
);
876 list_add_tail(&mac
->qe
, &list_head
);
881 /* Add the new entries */
882 while (!list_empty(&list_head
)) {
883 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
884 list_move_tail(&mac
->qe
, &rxf
->mcast_pending_add_q
);
887 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
889 return BNA_CB_SUCCESS
;
892 while (!list_empty(&list_head
)) {
893 mac
= list_first_entry(&list_head
, struct bna_mac
, qe
);
894 list_move_tail(&mac
->qe
, &mcam_mod
->free_q
);
897 return BNA_CB_MCAST_LIST_FULL
;
901 bna_rx_mcast_delall(struct bna_rx
*rx
)
903 struct bna_rxf
*rxf
= &rx
->rxf
;
904 struct bna_mac
*mac
, *del_mac
;
905 int need_hw_config
= 0;
907 /* Purge all entries from pending_add_q */
908 while (!list_empty(&rxf
->mcast_pending_add_q
)) {
909 mac
= list_first_entry(&rxf
->mcast_pending_add_q
,
911 list_move_tail(&mac
->qe
, bna_mcam_mod_free_q(rxf
->rx
->bna
));
914 /* Schedule all entries in active_q for deletion */
915 while (!list_empty(&rxf
->mcast_active_q
)) {
916 mac
= list_first_entry(&rxf
->mcast_active_q
,
919 del_mac
= bna_cam_mod_mac_get(bna_mcam_mod_del_q(rxf
->rx
->bna
));
920 memcpy(del_mac
, mac
, sizeof(*del_mac
));
921 list_add_tail(&del_mac
->qe
, &rxf
->mcast_pending_del_q
);
923 list_add_tail(&mac
->qe
, bna_mcam_mod_free_q(rxf
->rx
->bna
));
928 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
932 bna_rx_vlan_add(struct bna_rx
*rx
, int vlan_id
)
934 struct bna_rxf
*rxf
= &rx
->rxf
;
935 int index
= (vlan_id
>> BFI_VLAN_WORD_SHIFT
);
936 int bit
= BIT(vlan_id
& BFI_VLAN_WORD_MASK
);
937 int group_id
= (vlan_id
>> BFI_VLAN_BLOCK_SHIFT
);
939 rxf
->vlan_filter_table
[index
] |= bit
;
940 if (rxf
->vlan_filter_status
== BNA_STATUS_T_ENABLED
) {
941 rxf
->vlan_pending_bitmask
|= BIT(group_id
);
942 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
947 bna_rx_vlan_del(struct bna_rx
*rx
, int vlan_id
)
949 struct bna_rxf
*rxf
= &rx
->rxf
;
950 int index
= (vlan_id
>> BFI_VLAN_WORD_SHIFT
);
951 int bit
= BIT(vlan_id
& BFI_VLAN_WORD_MASK
);
952 int group_id
= (vlan_id
>> BFI_VLAN_BLOCK_SHIFT
);
954 rxf
->vlan_filter_table
[index
] &= ~bit
;
955 if (rxf
->vlan_filter_status
== BNA_STATUS_T_ENABLED
) {
956 rxf
->vlan_pending_bitmask
|= BIT(group_id
);
957 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
962 bna_rxf_ucast_cfg_apply(struct bna_rxf
*rxf
)
964 struct bna_mac
*mac
= NULL
;
966 /* Delete MAC addresses previousely added */
967 if (!list_empty(&rxf
->ucast_pending_del_q
)) {
968 mac
= list_first_entry(&rxf
->ucast_pending_del_q
,
970 bna_bfi_ucast_req(rxf
, mac
, BFI_ENET_H2I_MAC_UCAST_DEL_REQ
);
971 list_move_tail(&mac
->qe
, bna_ucam_mod_del_q(rxf
->rx
->bna
));
975 /* Set default unicast MAC */
976 if (rxf
->ucast_pending_set
) {
977 rxf
->ucast_pending_set
= 0;
978 ether_addr_copy(rxf
->ucast_active_mac
.addr
,
979 rxf
->ucast_pending_mac
->addr
);
980 rxf
->ucast_active_set
= 1;
981 bna_bfi_ucast_req(rxf
, &rxf
->ucast_active_mac
,
982 BFI_ENET_H2I_MAC_UCAST_SET_REQ
);
986 /* Add additional MAC entries */
987 if (!list_empty(&rxf
->ucast_pending_add_q
)) {
988 mac
= list_first_entry(&rxf
->ucast_pending_add_q
,
990 list_move_tail(&mac
->qe
, &rxf
->ucast_active_q
);
991 bna_bfi_ucast_req(rxf
, mac
, BFI_ENET_H2I_MAC_UCAST_ADD_REQ
);
999 bna_rxf_ucast_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
1001 struct bna_mac
*mac
;
1003 /* Throw away delete pending ucast entries */
1004 while (!list_empty(&rxf
->ucast_pending_del_q
)) {
1005 mac
= list_first_entry(&rxf
->ucast_pending_del_q
,
1006 struct bna_mac
, qe
);
1007 if (cleanup
== BNA_SOFT_CLEANUP
)
1008 list_move_tail(&mac
->qe
,
1009 bna_ucam_mod_del_q(rxf
->rx
->bna
));
1011 bna_bfi_ucast_req(rxf
, mac
,
1012 BFI_ENET_H2I_MAC_UCAST_DEL_REQ
);
1013 list_move_tail(&mac
->qe
,
1014 bna_ucam_mod_del_q(rxf
->rx
->bna
));
1019 /* Move active ucast entries to pending_add_q */
1020 while (!list_empty(&rxf
->ucast_active_q
)) {
1021 mac
= list_first_entry(&rxf
->ucast_active_q
,
1022 struct bna_mac
, qe
);
1023 list_move_tail(&mac
->qe
, &rxf
->ucast_pending_add_q
);
1024 if (cleanup
== BNA_HARD_CLEANUP
) {
1025 bna_bfi_ucast_req(rxf
, mac
,
1026 BFI_ENET_H2I_MAC_UCAST_DEL_REQ
);
1031 if (rxf
->ucast_active_set
) {
1032 rxf
->ucast_pending_set
= 1;
1033 rxf
->ucast_active_set
= 0;
1034 if (cleanup
== BNA_HARD_CLEANUP
) {
1035 bna_bfi_ucast_req(rxf
, &rxf
->ucast_active_mac
,
1036 BFI_ENET_H2I_MAC_UCAST_CLR_REQ
);
1045 bna_rxf_promisc_cfg_apply(struct bna_rxf
*rxf
)
1047 struct bna
*bna
= rxf
->rx
->bna
;
1049 /* Enable/disable promiscuous mode */
1050 if (is_promisc_enable(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_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_ENABLED
);
1058 } else if (is_promisc_disable(rxf
->rxmode_pending
,
1059 rxf
->rxmode_pending_bitmask
)) {
1060 /* move promisc configuration from pending -> active */
1061 promisc_inactive(rxf
->rxmode_pending
,
1062 rxf
->rxmode_pending_bitmask
);
1063 rxf
->rxmode_active
&= ~BNA_RXMODE_PROMISC
;
1064 bna
->promisc_rid
= BFI_INVALID_RID
;
1065 bna_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_DISABLED
);
1073 bna_rxf_promisc_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
1075 struct bna
*bna
= rxf
->rx
->bna
;
1077 /* Clear pending promisc mode disable */
1078 if (is_promisc_disable(rxf
->rxmode_pending
,
1079 rxf
->rxmode_pending_bitmask
)) {
1080 promisc_inactive(rxf
->rxmode_pending
,
1081 rxf
->rxmode_pending_bitmask
);
1082 rxf
->rxmode_active
&= ~BNA_RXMODE_PROMISC
;
1083 bna
->promisc_rid
= BFI_INVALID_RID
;
1084 if (cleanup
== BNA_HARD_CLEANUP
) {
1085 bna_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_DISABLED
);
1090 /* Move promisc mode config from active -> pending */
1091 if (rxf
->rxmode_active
& BNA_RXMODE_PROMISC
) {
1092 promisc_enable(rxf
->rxmode_pending
,
1093 rxf
->rxmode_pending_bitmask
);
1094 rxf
->rxmode_active
&= ~BNA_RXMODE_PROMISC
;
1095 if (cleanup
== BNA_HARD_CLEANUP
) {
1096 bna_bfi_rx_promisc_req(rxf
, BNA_STATUS_T_DISABLED
);
1105 bna_rxf_allmulti_cfg_apply(struct bna_rxf
*rxf
)
1107 /* Enable/disable allmulti mode */
1108 if (is_allmulti_enable(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_DISABLED
);
1116 } else if (is_allmulti_disable(rxf
->rxmode_pending
,
1117 rxf
->rxmode_pending_bitmask
)) {
1118 /* move allmulti configuration from pending -> active */
1119 allmulti_inactive(rxf
->rxmode_pending
,
1120 rxf
->rxmode_pending_bitmask
);
1121 rxf
->rxmode_active
&= ~BNA_RXMODE_ALLMULTI
;
1122 bna_bfi_mcast_filter_req(rxf
, BNA_STATUS_T_ENABLED
);
1130 bna_rxf_allmulti_cfg_reset(struct bna_rxf
*rxf
, enum bna_cleanup_type cleanup
)
1132 /* Clear pending allmulti mode disable */
1133 if (is_allmulti_disable(rxf
->rxmode_pending
,
1134 rxf
->rxmode_pending_bitmask
)) {
1135 allmulti_inactive(rxf
->rxmode_pending
,
1136 rxf
->rxmode_pending_bitmask
);
1137 rxf
->rxmode_active
&= ~BNA_RXMODE_ALLMULTI
;
1138 if (cleanup
== BNA_HARD_CLEANUP
) {
1139 bna_bfi_mcast_filter_req(rxf
, BNA_STATUS_T_ENABLED
);
1144 /* Move allmulti mode config from active -> pending */
1145 if (rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
) {
1146 allmulti_enable(rxf
->rxmode_pending
,
1147 rxf
->rxmode_pending_bitmask
);
1148 rxf
->rxmode_active
&= ~BNA_RXMODE_ALLMULTI
;
1149 if (cleanup
== BNA_HARD_CLEANUP
) {
1150 bna_bfi_mcast_filter_req(rxf
, BNA_STATUS_T_ENABLED
);
1159 bna_rxf_promisc_enable(struct bna_rxf
*rxf
)
1161 struct bna
*bna
= rxf
->rx
->bna
;
1164 if (is_promisc_enable(rxf
->rxmode_pending
,
1165 rxf
->rxmode_pending_bitmask
) ||
1166 (rxf
->rxmode_active
& BNA_RXMODE_PROMISC
)) {
1167 /* Do nothing if pending enable or already enabled */
1168 } else if (is_promisc_disable(rxf
->rxmode_pending
,
1169 rxf
->rxmode_pending_bitmask
)) {
1170 /* Turn off pending disable command */
1171 promisc_inactive(rxf
->rxmode_pending
,
1172 rxf
->rxmode_pending_bitmask
);
1174 /* Schedule enable */
1175 promisc_enable(rxf
->rxmode_pending
,
1176 rxf
->rxmode_pending_bitmask
);
1177 bna
->promisc_rid
= rxf
->rx
->rid
;
1185 bna_rxf_promisc_disable(struct bna_rxf
*rxf
)
1187 struct bna
*bna
= rxf
->rx
->bna
;
1190 if (is_promisc_disable(rxf
->rxmode_pending
,
1191 rxf
->rxmode_pending_bitmask
) ||
1192 (!(rxf
->rxmode_active
& BNA_RXMODE_PROMISC
))) {
1193 /* Do nothing if pending disable or already disabled */
1194 } else if (is_promisc_enable(rxf
->rxmode_pending
,
1195 rxf
->rxmode_pending_bitmask
)) {
1196 /* Turn off pending enable command */
1197 promisc_inactive(rxf
->rxmode_pending
,
1198 rxf
->rxmode_pending_bitmask
);
1199 bna
->promisc_rid
= BFI_INVALID_RID
;
1200 } else if (rxf
->rxmode_active
& BNA_RXMODE_PROMISC
) {
1201 /* Schedule disable */
1202 promisc_disable(rxf
->rxmode_pending
,
1203 rxf
->rxmode_pending_bitmask
);
1211 bna_rxf_allmulti_enable(struct bna_rxf
*rxf
)
1215 if (is_allmulti_enable(rxf
->rxmode_pending
,
1216 rxf
->rxmode_pending_bitmask
) ||
1217 (rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
)) {
1218 /* Do nothing if pending enable or already enabled */
1219 } else if (is_allmulti_disable(rxf
->rxmode_pending
,
1220 rxf
->rxmode_pending_bitmask
)) {
1221 /* Turn off pending disable command */
1222 allmulti_inactive(rxf
->rxmode_pending
,
1223 rxf
->rxmode_pending_bitmask
);
1225 /* Schedule enable */
1226 allmulti_enable(rxf
->rxmode_pending
,
1227 rxf
->rxmode_pending_bitmask
);
1235 bna_rxf_allmulti_disable(struct bna_rxf
*rxf
)
1239 if (is_allmulti_disable(rxf
->rxmode_pending
,
1240 rxf
->rxmode_pending_bitmask
) ||
1241 (!(rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
))) {
1242 /* Do nothing if pending disable or already disabled */
1243 } else if (is_allmulti_enable(rxf
->rxmode_pending
,
1244 rxf
->rxmode_pending_bitmask
)) {
1245 /* Turn off pending enable command */
1246 allmulti_inactive(rxf
->rxmode_pending
,
1247 rxf
->rxmode_pending_bitmask
);
1248 } else if (rxf
->rxmode_active
& BNA_RXMODE_ALLMULTI
) {
1249 /* Schedule disable */
1250 allmulti_disable(rxf
->rxmode_pending
,
1251 rxf
->rxmode_pending_bitmask
);
1259 bna_rxf_vlan_strip_cfg_apply(struct bna_rxf
*rxf
)
1261 if (rxf
->vlan_strip_pending
) {
1262 rxf
->vlan_strip_pending
= false;
1263 bna_bfi_vlan_strip_enable(rxf
);
1272 #define BNA_GET_RXQS(qcfg) (((qcfg)->rxp_type == BNA_RXP_SINGLE) ? \
1273 (qcfg)->num_paths : ((qcfg)->num_paths * 2))
1275 #define SIZE_TO_PAGES(size) (((size) >> PAGE_SHIFT) + ((((size) &\
1276 (PAGE_SIZE - 1)) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
1278 #define call_rx_stop_cbfn(rx) \
1280 if ((rx)->stop_cbfn) { \
1281 void (*cbfn)(void *, struct bna_rx *); \
1283 cbfn = (rx)->stop_cbfn; \
1284 cbarg = (rx)->stop_cbarg; \
1285 (rx)->stop_cbfn = NULL; \
1286 (rx)->stop_cbarg = NULL; \
1291 #define call_rx_stall_cbfn(rx) \
1293 if ((rx)->rx_stall_cbfn) \
1294 (rx)->rx_stall_cbfn((rx)->bna->bnad, (rx)); \
1297 #define bfi_enet_datapath_q_init(bfi_q, bna_qpt) \
1299 struct bna_dma_addr cur_q_addr = \
1300 *((struct bna_dma_addr *)((bna_qpt)->kv_qpt_ptr)); \
1301 (bfi_q)->pg_tbl.a32.addr_lo = (bna_qpt)->hw_qpt_ptr.lsb; \
1302 (bfi_q)->pg_tbl.a32.addr_hi = (bna_qpt)->hw_qpt_ptr.msb; \
1303 (bfi_q)->first_entry.a32.addr_lo = cur_q_addr.lsb; \
1304 (bfi_q)->first_entry.a32.addr_hi = cur_q_addr.msb; \
1305 (bfi_q)->pages = htons((u16)(bna_qpt)->page_count); \
1306 (bfi_q)->page_sz = htons((u16)(bna_qpt)->page_size);\
1309 static void bna_bfi_rx_enet_start(struct bna_rx
*rx
);
1310 static void bna_rx_enet_stop(struct bna_rx
*rx
);
1311 static void bna_rx_mod_cb_rx_stopped(void *arg
, struct bna_rx
*rx
);
1313 bfa_fsm_state_decl(bna_rx
, stopped
,
1314 struct bna_rx
, enum bna_rx_event
);
1315 bfa_fsm_state_decl(bna_rx
, start_wait
,
1316 struct bna_rx
, enum bna_rx_event
);
1317 bfa_fsm_state_decl(bna_rx
, start_stop_wait
,
1318 struct bna_rx
, enum bna_rx_event
);
1319 bfa_fsm_state_decl(bna_rx
, rxf_start_wait
,
1320 struct bna_rx
, enum bna_rx_event
);
1321 bfa_fsm_state_decl(bna_rx
, started
,
1322 struct bna_rx
, enum bna_rx_event
);
1323 bfa_fsm_state_decl(bna_rx
, rxf_stop_wait
,
1324 struct bna_rx
, enum bna_rx_event
);
1325 bfa_fsm_state_decl(bna_rx
, stop_wait
,
1326 struct bna_rx
, enum bna_rx_event
);
1327 bfa_fsm_state_decl(bna_rx
, cleanup_wait
,
1328 struct bna_rx
, enum bna_rx_event
);
1329 bfa_fsm_state_decl(bna_rx
, failed
,
1330 struct bna_rx
, enum bna_rx_event
);
1331 bfa_fsm_state_decl(bna_rx
, quiesce_wait
,
1332 struct bna_rx
, enum bna_rx_event
);
1334 static void bna_rx_sm_stopped_entry(struct bna_rx
*rx
)
1336 call_rx_stop_cbfn(rx
);
1339 static void bna_rx_sm_stopped(struct bna_rx
*rx
,
1340 enum bna_rx_event event
)
1344 bfa_fsm_set_state(rx
, bna_rx_sm_start_wait
);
1348 call_rx_stop_cbfn(rx
);
1356 bfa_sm_fault(event
);
1361 static void bna_rx_sm_start_wait_entry(struct bna_rx
*rx
)
1363 bna_bfi_rx_enet_start(rx
);
1367 bna_rx_sm_stop_wait_entry(struct bna_rx
*rx
)
1372 bna_rx_sm_stop_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1377 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1378 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1382 bna_rx_enet_stop(rx
);
1386 bfa_sm_fault(event
);
1391 static void bna_rx_sm_start_wait(struct bna_rx
*rx
,
1392 enum bna_rx_event event
)
1396 bfa_fsm_set_state(rx
, bna_rx_sm_start_stop_wait
);
1400 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1404 bfa_fsm_set_state(rx
, bna_rx_sm_rxf_start_wait
);
1408 bfa_sm_fault(event
);
1413 static void bna_rx_sm_rxf_start_wait_entry(struct bna_rx
*rx
)
1415 rx
->rx_post_cbfn(rx
->bna
->bnad
, rx
);
1416 bna_rxf_start(&rx
->rxf
);
1420 bna_rx_sm_rxf_stop_wait_entry(struct bna_rx
*rx
)
1425 bna_rx_sm_rxf_stop_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1429 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1430 bna_rxf_fail(&rx
->rxf
);
1431 call_rx_stall_cbfn(rx
);
1432 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1435 case RX_E_RXF_STARTED
:
1436 bna_rxf_stop(&rx
->rxf
);
1439 case RX_E_RXF_STOPPED
:
1440 bfa_fsm_set_state(rx
, bna_rx_sm_stop_wait
);
1441 call_rx_stall_cbfn(rx
);
1442 bna_rx_enet_stop(rx
);
1446 bfa_sm_fault(event
);
1453 bna_rx_sm_start_stop_wait_entry(struct bna_rx
*rx
)
1458 bna_rx_sm_start_stop_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1463 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1467 bna_rx_enet_stop(rx
);
1471 bfa_sm_fault(event
);
1476 bna_rx_sm_started_entry(struct bna_rx
*rx
)
1478 struct bna_rxp
*rxp
;
1479 int is_regular
= (rx
->type
== BNA_RX_T_REGULAR
);
1482 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
)
1483 bna_ib_start(rx
->bna
, &rxp
->cq
.ib
, is_regular
);
1485 bna_ethport_cb_rx_started(&rx
->bna
->ethport
);
1489 bna_rx_sm_started(struct bna_rx
*rx
, enum bna_rx_event event
)
1493 bfa_fsm_set_state(rx
, bna_rx_sm_rxf_stop_wait
);
1494 bna_ethport_cb_rx_stopped(&rx
->bna
->ethport
);
1495 bna_rxf_stop(&rx
->rxf
);
1499 bfa_fsm_set_state(rx
, bna_rx_sm_failed
);
1500 bna_ethport_cb_rx_stopped(&rx
->bna
->ethport
);
1501 bna_rxf_fail(&rx
->rxf
);
1502 call_rx_stall_cbfn(rx
);
1503 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1507 bfa_sm_fault(event
);
1512 static void bna_rx_sm_rxf_start_wait(struct bna_rx
*rx
,
1513 enum bna_rx_event event
)
1517 bfa_fsm_set_state(rx
, bna_rx_sm_rxf_stop_wait
);
1521 bfa_fsm_set_state(rx
, bna_rx_sm_failed
);
1522 bna_rxf_fail(&rx
->rxf
);
1523 call_rx_stall_cbfn(rx
);
1524 rx
->rx_cleanup_cbfn(rx
->bna
->bnad
, rx
);
1527 case RX_E_RXF_STARTED
:
1528 bfa_fsm_set_state(rx
, bna_rx_sm_started
);
1532 bfa_sm_fault(event
);
1538 bna_rx_sm_cleanup_wait_entry(struct bna_rx
*rx
)
1543 bna_rx_sm_cleanup_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1547 case RX_E_RXF_STOPPED
:
1551 case RX_E_CLEANUP_DONE
:
1552 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1556 bfa_sm_fault(event
);
1562 bna_rx_sm_failed_entry(struct bna_rx
*rx
)
1567 bna_rx_sm_failed(struct bna_rx
*rx
, enum bna_rx_event event
)
1571 bfa_fsm_set_state(rx
, bna_rx_sm_quiesce_wait
);
1575 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1579 case RX_E_RXF_STARTED
:
1580 case RX_E_RXF_STOPPED
:
1584 case RX_E_CLEANUP_DONE
:
1585 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
1589 bfa_sm_fault(event
);
1594 bna_rx_sm_quiesce_wait_entry(struct bna_rx
*rx
)
1599 bna_rx_sm_quiesce_wait(struct bna_rx
*rx
, enum bna_rx_event event
)
1603 bfa_fsm_set_state(rx
, bna_rx_sm_cleanup_wait
);
1607 bfa_fsm_set_state(rx
, bna_rx_sm_failed
);
1610 case RX_E_CLEANUP_DONE
:
1611 bfa_fsm_set_state(rx
, bna_rx_sm_start_wait
);
1615 bfa_sm_fault(event
);
1621 bna_bfi_rx_enet_start(struct bna_rx
*rx
)
1623 struct bfi_enet_rx_cfg_req
*cfg_req
= &rx
->bfi_enet_cmd
.cfg_req
;
1624 struct bna_rxp
*rxp
= NULL
;
1625 struct bna_rxq
*q0
= NULL
, *q1
= NULL
;
1628 bfi_msgq_mhdr_set(cfg_req
->mh
, BFI_MC_ENET
,
1629 BFI_ENET_H2I_RX_CFG_SET_REQ
, 0, rx
->rid
);
1630 cfg_req
->mh
.num_entries
= htons(
1631 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_rx_cfg_req
)));
1633 cfg_req
->rx_cfg
.frame_size
= bna_enet_mtu_get(&rx
->bna
->enet
);
1634 cfg_req
->num_queue_sets
= rx
->num_paths
;
1635 for (i
= 0; i
< rx
->num_paths
; i
++) {
1636 rxp
= rxp
? list_next_entry(rxp
, qe
)
1637 : list_first_entry(&rx
->rxp_q
, struct bna_rxp
, qe
);
1638 GET_RXQS(rxp
, q0
, q1
);
1639 switch (rxp
->type
) {
1643 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].qs
.q
,
1645 cfg_req
->q_cfg
[i
].qs
.rx_buffer_size
=
1646 htons((u16
)q1
->buffer_size
);
1649 case BNA_RXP_SINGLE
:
1650 /* Large/Single RxQ */
1651 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].ql
.q
,
1653 if (q0
->multi_buffer
)
1654 /* multi-buffer is enabled by allocating
1655 * a new rx with new set of resources.
1656 * q0->buffer_size should be initialized to
1659 cfg_req
->rx_cfg
.multi_buffer
=
1660 BNA_STATUS_T_ENABLED
;
1663 bna_enet_mtu_get(&rx
->bna
->enet
);
1664 cfg_req
->q_cfg
[i
].ql
.rx_buffer_size
=
1665 htons((u16
)q0
->buffer_size
);
1672 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].cq
.q
,
1675 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_lo
=
1676 rxp
->cq
.ib
.ib_seg_host_addr
.lsb
;
1677 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_hi
=
1678 rxp
->cq
.ib
.ib_seg_host_addr
.msb
;
1679 cfg_req
->q_cfg
[i
].ib
.intr
.msix_index
=
1680 htons((u16
)rxp
->cq
.ib
.intr_vector
);
1683 cfg_req
->ib_cfg
.int_pkt_dma
= BNA_STATUS_T_DISABLED
;
1684 cfg_req
->ib_cfg
.int_enabled
= BNA_STATUS_T_ENABLED
;
1685 cfg_req
->ib_cfg
.int_pkt_enabled
= BNA_STATUS_T_DISABLED
;
1686 cfg_req
->ib_cfg
.continuous_coalescing
= BNA_STATUS_T_DISABLED
;
1687 cfg_req
->ib_cfg
.msix
= (rxp
->cq
.ib
.intr_type
== BNA_INTR_T_MSIX
)
1688 ? BNA_STATUS_T_ENABLED
:
1689 BNA_STATUS_T_DISABLED
;
1690 cfg_req
->ib_cfg
.coalescing_timeout
=
1691 htonl((u32
)rxp
->cq
.ib
.coalescing_timeo
);
1692 cfg_req
->ib_cfg
.inter_pkt_timeout
=
1693 htonl((u32
)rxp
->cq
.ib
.interpkt_timeo
);
1694 cfg_req
->ib_cfg
.inter_pkt_count
= (u8
)rxp
->cq
.ib
.interpkt_count
;
1696 switch (rxp
->type
) {
1698 cfg_req
->rx_cfg
.rxq_type
= BFI_ENET_RXQ_LARGE_SMALL
;
1702 cfg_req
->rx_cfg
.rxq_type
= BFI_ENET_RXQ_HDS
;
1703 cfg_req
->rx_cfg
.hds
.type
= rx
->hds_cfg
.hdr_type
;
1704 cfg_req
->rx_cfg
.hds
.force_offset
= rx
->hds_cfg
.forced_offset
;
1705 cfg_req
->rx_cfg
.hds
.max_header_size
= rx
->hds_cfg
.forced_offset
;
1708 case BNA_RXP_SINGLE
:
1709 cfg_req
->rx_cfg
.rxq_type
= BFI_ENET_RXQ_SINGLE
;
1715 cfg_req
->rx_cfg
.strip_vlan
= rx
->rxf
.vlan_strip_status
;
1717 bfa_msgq_cmd_set(&rx
->msgq_cmd
, NULL
, NULL
,
1718 sizeof(struct bfi_enet_rx_cfg_req
), &cfg_req
->mh
);
1719 bfa_msgq_cmd_post(&rx
->bna
->msgq
, &rx
->msgq_cmd
);
1723 bna_bfi_rx_enet_stop(struct bna_rx
*rx
)
1725 struct bfi_enet_req
*req
= &rx
->bfi_enet_cmd
.req
;
1727 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
1728 BFI_ENET_H2I_RX_CFG_CLR_REQ
, 0, rx
->rid
);
1729 req
->mh
.num_entries
= htons(
1730 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_req
)));
1731 bfa_msgq_cmd_set(&rx
->msgq_cmd
, NULL
, NULL
, sizeof(struct bfi_enet_req
),
1733 bfa_msgq_cmd_post(&rx
->bna
->msgq
, &rx
->msgq_cmd
);
1737 bna_rx_enet_stop(struct bna_rx
*rx
)
1739 struct bna_rxp
*rxp
;
1742 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
)
1743 bna_ib_stop(rx
->bna
, &rxp
->cq
.ib
);
1745 bna_bfi_rx_enet_stop(rx
);
1749 bna_rx_res_check(struct bna_rx_mod
*rx_mod
, struct bna_rx_config
*rx_cfg
)
1751 if ((rx_mod
->rx_free_count
== 0) ||
1752 (rx_mod
->rxp_free_count
== 0) ||
1753 (rx_mod
->rxq_free_count
== 0))
1756 if (rx_cfg
->rxp_type
== BNA_RXP_SINGLE
) {
1757 if ((rx_mod
->rxp_free_count
< rx_cfg
->num_paths
) ||
1758 (rx_mod
->rxq_free_count
< rx_cfg
->num_paths
))
1761 if ((rx_mod
->rxp_free_count
< rx_cfg
->num_paths
) ||
1762 (rx_mod
->rxq_free_count
< (2 * rx_cfg
->num_paths
)))
1769 static struct bna_rxq
*
1770 bna_rxq_get(struct bna_rx_mod
*rx_mod
)
1772 struct bna_rxq
*rxq
= NULL
;
1774 rxq
= list_first_entry(&rx_mod
->rxq_free_q
, struct bna_rxq
, qe
);
1776 rx_mod
->rxq_free_count
--;
1782 bna_rxq_put(struct bna_rx_mod
*rx_mod
, struct bna_rxq
*rxq
)
1784 list_add_tail(&rxq
->qe
, &rx_mod
->rxq_free_q
);
1785 rx_mod
->rxq_free_count
++;
1788 static struct bna_rxp
*
1789 bna_rxp_get(struct bna_rx_mod
*rx_mod
)
1791 struct bna_rxp
*rxp
= NULL
;
1793 rxp
= list_first_entry(&rx_mod
->rxp_free_q
, struct bna_rxp
, qe
);
1795 rx_mod
->rxp_free_count
--;
1801 bna_rxp_put(struct bna_rx_mod
*rx_mod
, struct bna_rxp
*rxp
)
1803 list_add_tail(&rxp
->qe
, &rx_mod
->rxp_free_q
);
1804 rx_mod
->rxp_free_count
++;
1807 static struct bna_rx
*
1808 bna_rx_get(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
)
1810 struct bna_rx
*rx
= NULL
;
1812 BUG_ON(list_empty(&rx_mod
->rx_free_q
));
1813 if (type
== BNA_RX_T_REGULAR
)
1814 rx
= list_first_entry(&rx_mod
->rx_free_q
, struct bna_rx
, qe
);
1816 rx
= list_last_entry(&rx_mod
->rx_free_q
, struct bna_rx
, qe
);
1818 rx_mod
->rx_free_count
--;
1819 list_move_tail(&rx
->qe
, &rx_mod
->rx_active_q
);
1826 bna_rx_put(struct bna_rx_mod
*rx_mod
, struct bna_rx
*rx
)
1828 struct list_head
*qe
;
1830 list_for_each_prev(qe
, &rx_mod
->rx_free_q
)
1831 if (((struct bna_rx
*)qe
)->rid
< rx
->rid
)
1834 list_add(&rx
->qe
, qe
);
1835 rx_mod
->rx_free_count
++;
1839 bna_rxp_add_rxqs(struct bna_rxp
*rxp
, struct bna_rxq
*q0
,
1842 switch (rxp
->type
) {
1843 case BNA_RXP_SINGLE
:
1844 rxp
->rxq
.single
.only
= q0
;
1845 rxp
->rxq
.single
.reserved
= NULL
;
1848 rxp
->rxq
.slr
.large
= q0
;
1849 rxp
->rxq
.slr
.small
= q1
;
1852 rxp
->rxq
.hds
.data
= q0
;
1853 rxp
->rxq
.hds
.hdr
= q1
;
1861 bna_rxq_qpt_setup(struct bna_rxq
*rxq
,
1862 struct bna_rxp
*rxp
,
1865 struct bna_mem_descr
*qpt_mem
,
1866 struct bna_mem_descr
*swqpt_mem
,
1867 struct bna_mem_descr
*page_mem
)
1871 struct bna_dma_addr bna_dma
;
1874 rxq
->qpt
.hw_qpt_ptr
.lsb
= qpt_mem
->dma
.lsb
;
1875 rxq
->qpt
.hw_qpt_ptr
.msb
= qpt_mem
->dma
.msb
;
1876 rxq
->qpt
.kv_qpt_ptr
= qpt_mem
->kva
;
1877 rxq
->qpt
.page_count
= page_count
;
1878 rxq
->qpt
.page_size
= page_size
;
1880 rxq
->rcb
->sw_qpt
= (void **) swqpt_mem
->kva
;
1881 rxq
->rcb
->sw_q
= page_mem
->kva
;
1883 kva
= page_mem
->kva
;
1884 BNA_GET_DMA_ADDR(&page_mem
->dma
, dma
);
1886 for (i
= 0; i
< rxq
->qpt
.page_count
; i
++) {
1887 rxq
->rcb
->sw_qpt
[i
] = kva
;
1890 BNA_SET_DMA_ADDR(dma
, &bna_dma
);
1891 ((struct bna_dma_addr
*)rxq
->qpt
.kv_qpt_ptr
)[i
].lsb
=
1893 ((struct bna_dma_addr
*)rxq
->qpt
.kv_qpt_ptr
)[i
].msb
=
1900 bna_rxp_cqpt_setup(struct bna_rxp
*rxp
,
1903 struct bna_mem_descr
*qpt_mem
,
1904 struct bna_mem_descr
*swqpt_mem
,
1905 struct bna_mem_descr
*page_mem
)
1909 struct bna_dma_addr bna_dma
;
1912 rxp
->cq
.qpt
.hw_qpt_ptr
.lsb
= qpt_mem
->dma
.lsb
;
1913 rxp
->cq
.qpt
.hw_qpt_ptr
.msb
= qpt_mem
->dma
.msb
;
1914 rxp
->cq
.qpt
.kv_qpt_ptr
= qpt_mem
->kva
;
1915 rxp
->cq
.qpt
.page_count
= page_count
;
1916 rxp
->cq
.qpt
.page_size
= page_size
;
1918 rxp
->cq
.ccb
->sw_qpt
= (void **) swqpt_mem
->kva
;
1919 rxp
->cq
.ccb
->sw_q
= page_mem
->kva
;
1921 kva
= page_mem
->kva
;
1922 BNA_GET_DMA_ADDR(&page_mem
->dma
, dma
);
1924 for (i
= 0; i
< rxp
->cq
.qpt
.page_count
; i
++) {
1925 rxp
->cq
.ccb
->sw_qpt
[i
] = kva
;
1928 BNA_SET_DMA_ADDR(dma
, &bna_dma
);
1929 ((struct bna_dma_addr
*)rxp
->cq
.qpt
.kv_qpt_ptr
)[i
].lsb
=
1931 ((struct bna_dma_addr
*)rxp
->cq
.qpt
.kv_qpt_ptr
)[i
].msb
=
1938 bna_rx_mod_cb_rx_stopped(void *arg
, struct bna_rx
*rx
)
1940 struct bna_rx_mod
*rx_mod
= (struct bna_rx_mod
*)arg
;
1942 bfa_wc_down(&rx_mod
->rx_stop_wc
);
1946 bna_rx_mod_cb_rx_stopped_all(void *arg
)
1948 struct bna_rx_mod
*rx_mod
= (struct bna_rx_mod
*)arg
;
1950 if (rx_mod
->stop_cbfn
)
1951 rx_mod
->stop_cbfn(&rx_mod
->bna
->enet
);
1952 rx_mod
->stop_cbfn
= NULL
;
1956 bna_rx_start(struct bna_rx
*rx
)
1958 rx
->rx_flags
|= BNA_RX_F_ENET_STARTED
;
1959 if (rx
->rx_flags
& BNA_RX_F_ENABLED
)
1960 bfa_fsm_send_event(rx
, RX_E_START
);
1964 bna_rx_stop(struct bna_rx
*rx
)
1966 rx
->rx_flags
&= ~BNA_RX_F_ENET_STARTED
;
1967 if (rx
->fsm
== (bfa_fsm_t
) bna_rx_sm_stopped
)
1968 bna_rx_mod_cb_rx_stopped(&rx
->bna
->rx_mod
, rx
);
1970 rx
->stop_cbfn
= bna_rx_mod_cb_rx_stopped
;
1971 rx
->stop_cbarg
= &rx
->bna
->rx_mod
;
1972 bfa_fsm_send_event(rx
, RX_E_STOP
);
1977 bna_rx_fail(struct bna_rx
*rx
)
1979 /* Indicate Enet is not enabled, and failed */
1980 rx
->rx_flags
&= ~BNA_RX_F_ENET_STARTED
;
1981 bfa_fsm_send_event(rx
, RX_E_FAIL
);
1985 bna_rx_mod_start(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
)
1989 rx_mod
->flags
|= BNA_RX_MOD_F_ENET_STARTED
;
1990 if (type
== BNA_RX_T_LOOPBACK
)
1991 rx_mod
->flags
|= BNA_RX_MOD_F_ENET_LOOPBACK
;
1993 list_for_each_entry(rx
, &rx_mod
->rx_active_q
, qe
)
1994 if (rx
->type
== type
)
1999 bna_rx_mod_stop(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
)
2003 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_STARTED
;
2004 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_LOOPBACK
;
2006 rx_mod
->stop_cbfn
= bna_enet_cb_rx_stopped
;
2008 bfa_wc_init(&rx_mod
->rx_stop_wc
, bna_rx_mod_cb_rx_stopped_all
, rx_mod
);
2010 list_for_each_entry(rx
, &rx_mod
->rx_active_q
, qe
)
2011 if (rx
->type
== type
) {
2012 bfa_wc_up(&rx_mod
->rx_stop_wc
);
2016 bfa_wc_wait(&rx_mod
->rx_stop_wc
);
2020 bna_rx_mod_fail(struct bna_rx_mod
*rx_mod
)
2024 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_STARTED
;
2025 rx_mod
->flags
&= ~BNA_RX_MOD_F_ENET_LOOPBACK
;
2027 list_for_each_entry(rx
, &rx_mod
->rx_active_q
, qe
)
2031 void bna_rx_mod_init(struct bna_rx_mod
*rx_mod
, struct bna
*bna
,
2032 struct bna_res_info
*res_info
)
2035 struct bna_rx
*rx_ptr
;
2036 struct bna_rxp
*rxp_ptr
;
2037 struct bna_rxq
*rxq_ptr
;
2042 rx_mod
->rx
= (struct bna_rx
*)
2043 res_info
[BNA_MOD_RES_MEM_T_RX_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
2044 rx_mod
->rxp
= (struct bna_rxp
*)
2045 res_info
[BNA_MOD_RES_MEM_T_RXP_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
2046 rx_mod
->rxq
= (struct bna_rxq
*)
2047 res_info
[BNA_MOD_RES_MEM_T_RXQ_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
2049 /* Initialize the queues */
2050 INIT_LIST_HEAD(&rx_mod
->rx_free_q
);
2051 rx_mod
->rx_free_count
= 0;
2052 INIT_LIST_HEAD(&rx_mod
->rxq_free_q
);
2053 rx_mod
->rxq_free_count
= 0;
2054 INIT_LIST_HEAD(&rx_mod
->rxp_free_q
);
2055 rx_mod
->rxp_free_count
= 0;
2056 INIT_LIST_HEAD(&rx_mod
->rx_active_q
);
2058 /* Build RX queues */
2059 for (index
= 0; index
< bna
->ioceth
.attr
.num_rxp
; index
++) {
2060 rx_ptr
= &rx_mod
->rx
[index
];
2062 INIT_LIST_HEAD(&rx_ptr
->rxp_q
);
2064 rx_ptr
->rid
= index
;
2065 rx_ptr
->stop_cbfn
= NULL
;
2066 rx_ptr
->stop_cbarg
= NULL
;
2068 list_add_tail(&rx_ptr
->qe
, &rx_mod
->rx_free_q
);
2069 rx_mod
->rx_free_count
++;
2072 /* build RX-path queue */
2073 for (index
= 0; index
< bna
->ioceth
.attr
.num_rxp
; index
++) {
2074 rxp_ptr
= &rx_mod
->rxp
[index
];
2075 list_add_tail(&rxp_ptr
->qe
, &rx_mod
->rxp_free_q
);
2076 rx_mod
->rxp_free_count
++;
2079 /* build RXQ queue */
2080 for (index
= 0; index
< (bna
->ioceth
.attr
.num_rxp
* 2); index
++) {
2081 rxq_ptr
= &rx_mod
->rxq
[index
];
2082 list_add_tail(&rxq_ptr
->qe
, &rx_mod
->rxq_free_q
);
2083 rx_mod
->rxq_free_count
++;
2088 bna_rx_mod_uninit(struct bna_rx_mod
*rx_mod
)
2094 bna_bfi_rx_enet_start_rsp(struct bna_rx
*rx
, struct bfi_msgq_mhdr
*msghdr
)
2096 struct bfi_enet_rx_cfg_rsp
*cfg_rsp
= &rx
->bfi_enet_cmd
.cfg_rsp
;
2097 struct bna_rxp
*rxp
= NULL
;
2098 struct bna_rxq
*q0
= NULL
, *q1
= NULL
;
2101 bfa_msgq_rsp_copy(&rx
->bna
->msgq
, (u8
*)cfg_rsp
,
2102 sizeof(struct bfi_enet_rx_cfg_rsp
));
2104 rx
->hw_id
= cfg_rsp
->hw_id
;
2106 for (i
= 0, rxp
= list_first_entry(&rx
->rxp_q
, struct bna_rxp
, qe
);
2107 i
< rx
->num_paths
; i
++, rxp
= list_next_entry(rxp
, qe
)) {
2108 GET_RXQS(rxp
, q0
, q1
);
2110 /* Setup doorbells */
2111 rxp
->cq
.ccb
->i_dbell
->doorbell_addr
=
2112 rx
->bna
->pcidev
.pci_bar_kva
2113 + ntohl(cfg_rsp
->q_handles
[i
].i_dbell
);
2114 rxp
->hw_id
= cfg_rsp
->q_handles
[i
].hw_cqid
;
2116 rx
->bna
->pcidev
.pci_bar_kva
2117 + ntohl(cfg_rsp
->q_handles
[i
].ql_dbell
);
2118 q0
->hw_id
= cfg_rsp
->q_handles
[i
].hw_lqid
;
2121 rx
->bna
->pcidev
.pci_bar_kva
2122 + ntohl(cfg_rsp
->q_handles
[i
].qs_dbell
);
2123 q1
->hw_id
= cfg_rsp
->q_handles
[i
].hw_sqid
;
2126 /* Initialize producer/consumer indexes */
2127 (*rxp
->cq
.ccb
->hw_producer_index
) = 0;
2128 rxp
->cq
.ccb
->producer_index
= 0;
2129 q0
->rcb
->producer_index
= q0
->rcb
->consumer_index
= 0;
2131 q1
->rcb
->producer_index
= q1
->rcb
->consumer_index
= 0;
2134 bfa_fsm_send_event(rx
, RX_E_STARTED
);
2138 bna_bfi_rx_enet_stop_rsp(struct bna_rx
*rx
, struct bfi_msgq_mhdr
*msghdr
)
2140 bfa_fsm_send_event(rx
, RX_E_STOPPED
);
2144 bna_rx_res_req(struct bna_rx_config
*q_cfg
, struct bna_res_info
*res_info
)
2146 u32 cq_size
, hq_size
, dq_size
;
2147 u32 cpage_count
, hpage_count
, dpage_count
;
2148 struct bna_mem_info
*mem_info
;
2153 dq_depth
= q_cfg
->q0_depth
;
2154 hq_depth
= ((q_cfg
->rxp_type
== BNA_RXP_SINGLE
) ? 0 : q_cfg
->q1_depth
);
2155 cq_depth
= roundup_pow_of_two(dq_depth
+ hq_depth
);
2157 cq_size
= cq_depth
* BFI_CQ_WI_SIZE
;
2158 cq_size
= ALIGN(cq_size
, PAGE_SIZE
);
2159 cpage_count
= SIZE_TO_PAGES(cq_size
);
2161 dq_depth
= roundup_pow_of_two(dq_depth
);
2162 dq_size
= dq_depth
* BFI_RXQ_WI_SIZE
;
2163 dq_size
= ALIGN(dq_size
, PAGE_SIZE
);
2164 dpage_count
= SIZE_TO_PAGES(dq_size
);
2166 if (BNA_RXP_SINGLE
!= q_cfg
->rxp_type
) {
2167 hq_depth
= roundup_pow_of_two(hq_depth
);
2168 hq_size
= hq_depth
* BFI_RXQ_WI_SIZE
;
2169 hq_size
= ALIGN(hq_size
, PAGE_SIZE
);
2170 hpage_count
= SIZE_TO_PAGES(hq_size
);
2174 res_info
[BNA_RX_RES_MEM_T_CCB
].res_type
= BNA_RES_T_MEM
;
2175 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CCB
].res_u
.mem_info
;
2176 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2177 mem_info
->len
= sizeof(struct bna_ccb
);
2178 mem_info
->num
= q_cfg
->num_paths
;
2180 res_info
[BNA_RX_RES_MEM_T_RCB
].res_type
= BNA_RES_T_MEM
;
2181 mem_info
= &res_info
[BNA_RX_RES_MEM_T_RCB
].res_u
.mem_info
;
2182 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2183 mem_info
->len
= sizeof(struct bna_rcb
);
2184 mem_info
->num
= BNA_GET_RXQS(q_cfg
);
2186 res_info
[BNA_RX_RES_MEM_T_CQPT
].res_type
= BNA_RES_T_MEM
;
2187 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CQPT
].res_u
.mem_info
;
2188 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2189 mem_info
->len
= cpage_count
* sizeof(struct bna_dma_addr
);
2190 mem_info
->num
= q_cfg
->num_paths
;
2192 res_info
[BNA_RX_RES_MEM_T_CSWQPT
].res_type
= BNA_RES_T_MEM
;
2193 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CSWQPT
].res_u
.mem_info
;
2194 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2195 mem_info
->len
= cpage_count
* sizeof(void *);
2196 mem_info
->num
= q_cfg
->num_paths
;
2198 res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_type
= BNA_RES_T_MEM
;
2199 mem_info
= &res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_u
.mem_info
;
2200 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2201 mem_info
->len
= PAGE_SIZE
* cpage_count
;
2202 mem_info
->num
= q_cfg
->num_paths
;
2204 res_info
[BNA_RX_RES_MEM_T_DQPT
].res_type
= BNA_RES_T_MEM
;
2205 mem_info
= &res_info
[BNA_RX_RES_MEM_T_DQPT
].res_u
.mem_info
;
2206 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2207 mem_info
->len
= dpage_count
* sizeof(struct bna_dma_addr
);
2208 mem_info
->num
= q_cfg
->num_paths
;
2210 res_info
[BNA_RX_RES_MEM_T_DSWQPT
].res_type
= BNA_RES_T_MEM
;
2211 mem_info
= &res_info
[BNA_RX_RES_MEM_T_DSWQPT
].res_u
.mem_info
;
2212 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2213 mem_info
->len
= dpage_count
* sizeof(void *);
2214 mem_info
->num
= q_cfg
->num_paths
;
2216 res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_type
= BNA_RES_T_MEM
;
2217 mem_info
= &res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_u
.mem_info
;
2218 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2219 mem_info
->len
= PAGE_SIZE
* dpage_count
;
2220 mem_info
->num
= q_cfg
->num_paths
;
2222 res_info
[BNA_RX_RES_MEM_T_HQPT
].res_type
= BNA_RES_T_MEM
;
2223 mem_info
= &res_info
[BNA_RX_RES_MEM_T_HQPT
].res_u
.mem_info
;
2224 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2225 mem_info
->len
= hpage_count
* sizeof(struct bna_dma_addr
);
2226 mem_info
->num
= (hpage_count
? q_cfg
->num_paths
: 0);
2228 res_info
[BNA_RX_RES_MEM_T_HSWQPT
].res_type
= BNA_RES_T_MEM
;
2229 mem_info
= &res_info
[BNA_RX_RES_MEM_T_HSWQPT
].res_u
.mem_info
;
2230 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2231 mem_info
->len
= hpage_count
* sizeof(void *);
2232 mem_info
->num
= (hpage_count
? q_cfg
->num_paths
: 0);
2234 res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_type
= BNA_RES_T_MEM
;
2235 mem_info
= &res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_u
.mem_info
;
2236 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2237 mem_info
->len
= PAGE_SIZE
* hpage_count
;
2238 mem_info
->num
= (hpage_count
? q_cfg
->num_paths
: 0);
2240 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_type
= BNA_RES_T_MEM
;
2241 mem_info
= &res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
;
2242 mem_info
->mem_type
= BNA_MEM_T_DMA
;
2243 mem_info
->len
= BFI_IBIDX_SIZE
;
2244 mem_info
->num
= q_cfg
->num_paths
;
2246 res_info
[BNA_RX_RES_MEM_T_RIT
].res_type
= BNA_RES_T_MEM
;
2247 mem_info
= &res_info
[BNA_RX_RES_MEM_T_RIT
].res_u
.mem_info
;
2248 mem_info
->mem_type
= BNA_MEM_T_KVA
;
2249 mem_info
->len
= BFI_ENET_RSS_RIT_MAX
;
2252 res_info
[BNA_RX_RES_T_INTR
].res_type
= BNA_RES_T_INTR
;
2253 res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
.intr_type
= BNA_INTR_T_MSIX
;
2254 res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
.num
= q_cfg
->num_paths
;
2258 bna_rx_create(struct bna
*bna
, struct bnad
*bnad
,
2259 struct bna_rx_config
*rx_cfg
,
2260 const struct bna_rx_event_cbfn
*rx_cbfn
,
2261 struct bna_res_info
*res_info
,
2264 struct bna_rx_mod
*rx_mod
= &bna
->rx_mod
;
2266 struct bna_rxp
*rxp
;
2269 struct bna_intr_info
*intr_info
;
2270 struct bna_mem_descr
*hqunmap_mem
;
2271 struct bna_mem_descr
*dqunmap_mem
;
2272 struct bna_mem_descr
*ccb_mem
;
2273 struct bna_mem_descr
*rcb_mem
;
2274 struct bna_mem_descr
*cqpt_mem
;
2275 struct bna_mem_descr
*cswqpt_mem
;
2276 struct bna_mem_descr
*cpage_mem
;
2277 struct bna_mem_descr
*hqpt_mem
;
2278 struct bna_mem_descr
*dqpt_mem
;
2279 struct bna_mem_descr
*hsqpt_mem
;
2280 struct bna_mem_descr
*dsqpt_mem
;
2281 struct bna_mem_descr
*hpage_mem
;
2282 struct bna_mem_descr
*dpage_mem
;
2283 u32 dpage_count
, hpage_count
;
2284 u32 hq_idx
, dq_idx
, rcb_idx
;
2288 if (!bna_rx_res_check(rx_mod
, rx_cfg
))
2291 intr_info
= &res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
;
2292 ccb_mem
= &res_info
[BNA_RX_RES_MEM_T_CCB
].res_u
.mem_info
.mdl
[0];
2293 rcb_mem
= &res_info
[BNA_RX_RES_MEM_T_RCB
].res_u
.mem_info
.mdl
[0];
2294 dqunmap_mem
= &res_info
[BNA_RX_RES_MEM_T_UNMAPDQ
].res_u
.mem_info
.mdl
[0];
2295 hqunmap_mem
= &res_info
[BNA_RX_RES_MEM_T_UNMAPHQ
].res_u
.mem_info
.mdl
[0];
2296 cqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_CQPT
].res_u
.mem_info
.mdl
[0];
2297 cswqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_CSWQPT
].res_u
.mem_info
.mdl
[0];
2298 cpage_mem
= &res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_u
.mem_info
.mdl
[0];
2299 hqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_HQPT
].res_u
.mem_info
.mdl
[0];
2300 dqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_DQPT
].res_u
.mem_info
.mdl
[0];
2301 hsqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_HSWQPT
].res_u
.mem_info
.mdl
[0];
2302 dsqpt_mem
= &res_info
[BNA_RX_RES_MEM_T_DSWQPT
].res_u
.mem_info
.mdl
[0];
2303 hpage_mem
= &res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_u
.mem_info
.mdl
[0];
2304 dpage_mem
= &res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_u
.mem_info
.mdl
[0];
2306 page_count
= res_info
[BNA_RX_RES_MEM_T_CQPT_PAGE
].res_u
.mem_info
.len
/
2309 dpage_count
= res_info
[BNA_RX_RES_MEM_T_DPAGE
].res_u
.mem_info
.len
/
2312 hpage_count
= res_info
[BNA_RX_RES_MEM_T_HPAGE
].res_u
.mem_info
.len
/
2315 rx
= bna_rx_get(rx_mod
, rx_cfg
->rx_type
);
2318 INIT_LIST_HEAD(&rx
->rxp_q
);
2319 rx
->stop_cbfn
= NULL
;
2320 rx
->stop_cbarg
= NULL
;
2323 rx
->rcb_setup_cbfn
= rx_cbfn
->rcb_setup_cbfn
;
2324 rx
->rcb_destroy_cbfn
= rx_cbfn
->rcb_destroy_cbfn
;
2325 rx
->ccb_setup_cbfn
= rx_cbfn
->ccb_setup_cbfn
;
2326 rx
->ccb_destroy_cbfn
= rx_cbfn
->ccb_destroy_cbfn
;
2327 rx
->rx_stall_cbfn
= rx_cbfn
->rx_stall_cbfn
;
2328 /* Following callbacks are mandatory */
2329 rx
->rx_cleanup_cbfn
= rx_cbfn
->rx_cleanup_cbfn
;
2330 rx
->rx_post_cbfn
= rx_cbfn
->rx_post_cbfn
;
2332 if (rx
->bna
->rx_mod
.flags
& BNA_RX_MOD_F_ENET_STARTED
) {
2334 case BNA_RX_T_REGULAR
:
2335 if (!(rx
->bna
->rx_mod
.flags
&
2336 BNA_RX_MOD_F_ENET_LOOPBACK
))
2337 rx
->rx_flags
|= BNA_RX_F_ENET_STARTED
;
2339 case BNA_RX_T_LOOPBACK
:
2340 if (rx
->bna
->rx_mod
.flags
& BNA_RX_MOD_F_ENET_LOOPBACK
)
2341 rx
->rx_flags
|= BNA_RX_F_ENET_STARTED
;
2346 rx
->num_paths
= rx_cfg
->num_paths
;
2347 for (i
= 0, hq_idx
= 0, dq_idx
= 0, rcb_idx
= 0;
2348 i
< rx
->num_paths
; i
++) {
2349 rxp
= bna_rxp_get(rx_mod
);
2350 list_add_tail(&rxp
->qe
, &rx
->rxp_q
);
2351 rxp
->type
= rx_cfg
->rxp_type
;
2355 q0
= bna_rxq_get(rx_mod
);
2356 if (BNA_RXP_SINGLE
== rx_cfg
->rxp_type
)
2359 q1
= bna_rxq_get(rx_mod
);
2361 if (1 == intr_info
->num
)
2362 rxp
->vector
= intr_info
->idl
[0].vector
;
2364 rxp
->vector
= intr_info
->idl
[i
].vector
;
2368 rxp
->cq
.ib
.ib_seg_host_addr
.lsb
=
2369 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.lsb
;
2370 rxp
->cq
.ib
.ib_seg_host_addr
.msb
=
2371 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.msb
;
2372 rxp
->cq
.ib
.ib_seg_host_addr_kva
=
2373 res_info
[BNA_RX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].kva
;
2374 rxp
->cq
.ib
.intr_type
= intr_info
->intr_type
;
2375 if (intr_info
->intr_type
== BNA_INTR_T_MSIX
)
2376 rxp
->cq
.ib
.intr_vector
= rxp
->vector
;
2378 rxp
->cq
.ib
.intr_vector
= BIT(rxp
->vector
);
2379 rxp
->cq
.ib
.coalescing_timeo
= rx_cfg
->coalescing_timeo
;
2380 rxp
->cq
.ib
.interpkt_count
= BFI_RX_INTERPKT_COUNT
;
2381 rxp
->cq
.ib
.interpkt_timeo
= BFI_RX_INTERPKT_TIMEO
;
2383 bna_rxp_add_rxqs(rxp
, q0
, q1
);
2390 q0
->rcb
= (struct bna_rcb
*) rcb_mem
[rcb_idx
].kva
;
2391 q0
->rcb
->unmap_q
= (void *)dqunmap_mem
[dq_idx
].kva
;
2392 rcb_idx
++; dq_idx
++;
2393 q0
->rcb
->q_depth
= rx_cfg
->q0_depth
;
2394 q0
->q_depth
= rx_cfg
->q0_depth
;
2395 q0
->multi_buffer
= rx_cfg
->q0_multi_buf
;
2396 q0
->buffer_size
= rx_cfg
->q0_buf_size
;
2397 q0
->num_vecs
= rx_cfg
->q0_num_vecs
;
2399 q0
->rcb
->bnad
= bna
->bnad
;
2401 q0
->rx_packets
= q0
->rx_bytes
= 0;
2402 q0
->rx_packets_with_error
= q0
->rxbuf_alloc_failed
= 0;
2403 q0
->rxbuf_map_failed
= 0;
2405 bna_rxq_qpt_setup(q0
, rxp
, dpage_count
, PAGE_SIZE
,
2406 &dqpt_mem
[i
], &dsqpt_mem
[i
], &dpage_mem
[i
]);
2408 if (rx
->rcb_setup_cbfn
)
2409 rx
->rcb_setup_cbfn(bnad
, q0
->rcb
);
2417 q1
->rcb
= (struct bna_rcb
*) rcb_mem
[rcb_idx
].kva
;
2418 q1
->rcb
->unmap_q
= (void *)hqunmap_mem
[hq_idx
].kva
;
2419 rcb_idx
++; hq_idx
++;
2420 q1
->rcb
->q_depth
= rx_cfg
->q1_depth
;
2421 q1
->q_depth
= rx_cfg
->q1_depth
;
2422 q1
->multi_buffer
= BNA_STATUS_T_DISABLED
;
2425 q1
->rcb
->bnad
= bna
->bnad
;
2427 q1
->buffer_size
= (rx_cfg
->rxp_type
== BNA_RXP_HDS
) ?
2428 rx_cfg
->hds_config
.forced_offset
2429 : rx_cfg
->q1_buf_size
;
2430 q1
->rx_packets
= q1
->rx_bytes
= 0;
2431 q1
->rx_packets_with_error
= q1
->rxbuf_alloc_failed
= 0;
2432 q1
->rxbuf_map_failed
= 0;
2434 bna_rxq_qpt_setup(q1
, rxp
, hpage_count
, PAGE_SIZE
,
2435 &hqpt_mem
[i
], &hsqpt_mem
[i
],
2438 if (rx
->rcb_setup_cbfn
)
2439 rx
->rcb_setup_cbfn(bnad
, q1
->rcb
);
2444 rxp
->cq
.ccb
= (struct bna_ccb
*) ccb_mem
[i
].kva
;
2445 cq_depth
= rx_cfg
->q0_depth
+
2446 ((rx_cfg
->rxp_type
== BNA_RXP_SINGLE
) ?
2447 0 : rx_cfg
->q1_depth
);
2448 /* if multi-buffer is enabled sum of q0_depth
2449 * and q1_depth need not be a power of 2
2451 cq_depth
= roundup_pow_of_two(cq_depth
);
2452 rxp
->cq
.ccb
->q_depth
= cq_depth
;
2453 rxp
->cq
.ccb
->cq
= &rxp
->cq
;
2454 rxp
->cq
.ccb
->rcb
[0] = q0
->rcb
;
2455 q0
->rcb
->ccb
= rxp
->cq
.ccb
;
2457 rxp
->cq
.ccb
->rcb
[1] = q1
->rcb
;
2458 q1
->rcb
->ccb
= rxp
->cq
.ccb
;
2460 rxp
->cq
.ccb
->hw_producer_index
=
2461 (u32
*)rxp
->cq
.ib
.ib_seg_host_addr_kva
;
2462 rxp
->cq
.ccb
->i_dbell
= &rxp
->cq
.ib
.door_bell
;
2463 rxp
->cq
.ccb
->intr_type
= rxp
->cq
.ib
.intr_type
;
2464 rxp
->cq
.ccb
->intr_vector
= rxp
->cq
.ib
.intr_vector
;
2465 rxp
->cq
.ccb
->rx_coalescing_timeo
=
2466 rxp
->cq
.ib
.coalescing_timeo
;
2467 rxp
->cq
.ccb
->pkt_rate
.small_pkt_cnt
= 0;
2468 rxp
->cq
.ccb
->pkt_rate
.large_pkt_cnt
= 0;
2469 rxp
->cq
.ccb
->bnad
= bna
->bnad
;
2470 rxp
->cq
.ccb
->id
= i
;
2472 bna_rxp_cqpt_setup(rxp
, page_count
, PAGE_SIZE
,
2473 &cqpt_mem
[i
], &cswqpt_mem
[i
], &cpage_mem
[i
]);
2475 if (rx
->ccb_setup_cbfn
)
2476 rx
->ccb_setup_cbfn(bnad
, rxp
->cq
.ccb
);
2479 rx
->hds_cfg
= rx_cfg
->hds_config
;
2481 bna_rxf_init(&rx
->rxf
, rx
, rx_cfg
, res_info
);
2483 bfa_fsm_set_state(rx
, bna_rx_sm_stopped
);
2485 rx_mod
->rid_mask
|= BIT(rx
->rid
);
2491 bna_rx_destroy(struct bna_rx
*rx
)
2493 struct bna_rx_mod
*rx_mod
= &rx
->bna
->rx_mod
;
2494 struct bna_rxq
*q0
= NULL
;
2495 struct bna_rxq
*q1
= NULL
;
2496 struct bna_rxp
*rxp
;
2497 struct list_head
*qe
;
2499 bna_rxf_uninit(&rx
->rxf
);
2501 while (!list_empty(&rx
->rxp_q
)) {
2502 rxp
= list_first_entry(&rx
->rxp_q
, struct bna_rxp
, qe
);
2504 GET_RXQS(rxp
, q0
, q1
);
2505 if (rx
->rcb_destroy_cbfn
)
2506 rx
->rcb_destroy_cbfn(rx
->bna
->bnad
, q0
->rcb
);
2510 bna_rxq_put(rx_mod
, q0
);
2513 if (rx
->rcb_destroy_cbfn
)
2514 rx
->rcb_destroy_cbfn(rx
->bna
->bnad
, q1
->rcb
);
2518 bna_rxq_put(rx_mod
, q1
);
2520 rxp
->rxq
.slr
.large
= NULL
;
2521 rxp
->rxq
.slr
.small
= NULL
;
2523 if (rx
->ccb_destroy_cbfn
)
2524 rx
->ccb_destroy_cbfn(rx
->bna
->bnad
, rxp
->cq
.ccb
);
2527 bna_rxp_put(rx_mod
, rxp
);
2530 list_for_each(qe
, &rx_mod
->rx_active_q
)
2531 if (qe
== &rx
->qe
) {
2536 rx_mod
->rid_mask
&= ~BIT(rx
->rid
);
2540 bna_rx_put(rx_mod
, rx
);
2544 bna_rx_enable(struct bna_rx
*rx
)
2546 if (rx
->fsm
!= (bfa_sm_t
)bna_rx_sm_stopped
)
2549 rx
->rx_flags
|= BNA_RX_F_ENABLED
;
2550 if (rx
->rx_flags
& BNA_RX_F_ENET_STARTED
)
2551 bfa_fsm_send_event(rx
, RX_E_START
);
2555 bna_rx_disable(struct bna_rx
*rx
, enum bna_cleanup_type type
,
2556 void (*cbfn
)(void *, struct bna_rx
*))
2558 if (type
== BNA_SOFT_CLEANUP
) {
2559 /* h/w should not be accessed. Treat we're stopped */
2560 (*cbfn
)(rx
->bna
->bnad
, rx
);
2562 rx
->stop_cbfn
= cbfn
;
2563 rx
->stop_cbarg
= rx
->bna
->bnad
;
2565 rx
->rx_flags
&= ~BNA_RX_F_ENABLED
;
2567 bfa_fsm_send_event(rx
, RX_E_STOP
);
2572 bna_rx_cleanup_complete(struct bna_rx
*rx
)
2574 bfa_fsm_send_event(rx
, RX_E_CLEANUP_DONE
);
2578 bna_rx_vlan_strip_enable(struct bna_rx
*rx
)
2580 struct bna_rxf
*rxf
= &rx
->rxf
;
2582 if (rxf
->vlan_strip_status
== BNA_STATUS_T_DISABLED
) {
2583 rxf
->vlan_strip_status
= BNA_STATUS_T_ENABLED
;
2584 rxf
->vlan_strip_pending
= true;
2585 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2590 bna_rx_vlan_strip_disable(struct bna_rx
*rx
)
2592 struct bna_rxf
*rxf
= &rx
->rxf
;
2594 if (rxf
->vlan_strip_status
!= BNA_STATUS_T_DISABLED
) {
2595 rxf
->vlan_strip_status
= BNA_STATUS_T_DISABLED
;
2596 rxf
->vlan_strip_pending
= true;
2597 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2602 bna_rx_mode_set(struct bna_rx
*rx
, enum bna_rxmode new_mode
,
2603 enum bna_rxmode bitmask
)
2605 struct bna_rxf
*rxf
= &rx
->rxf
;
2606 int need_hw_config
= 0;
2610 if (is_promisc_enable(new_mode
, bitmask
)) {
2611 /* If promisc mode is already enabled elsewhere in the system */
2612 if ((rx
->bna
->promisc_rid
!= BFI_INVALID_RID
) &&
2613 (rx
->bna
->promisc_rid
!= rxf
->rx
->rid
))
2616 /* If default mode is already enabled in the system */
2617 if (rx
->bna
->default_mode_rid
!= BFI_INVALID_RID
)
2620 /* Trying to enable promiscuous and default mode together */
2621 if (is_default_enable(new_mode
, bitmask
))
2625 if (is_default_enable(new_mode
, bitmask
)) {
2626 /* If default mode is already enabled elsewhere in the system */
2627 if ((rx
->bna
->default_mode_rid
!= BFI_INVALID_RID
) &&
2628 (rx
->bna
->default_mode_rid
!= rxf
->rx
->rid
)) {
2632 /* If promiscuous mode is already enabled in the system */
2633 if (rx
->bna
->promisc_rid
!= BFI_INVALID_RID
)
2637 /* Process the commands */
2639 if (is_promisc_enable(new_mode
, bitmask
)) {
2640 if (bna_rxf_promisc_enable(rxf
))
2642 } else if (is_promisc_disable(new_mode
, bitmask
)) {
2643 if (bna_rxf_promisc_disable(rxf
))
2647 if (is_allmulti_enable(new_mode
, bitmask
)) {
2648 if (bna_rxf_allmulti_enable(rxf
))
2650 } else if (is_allmulti_disable(new_mode
, bitmask
)) {
2651 if (bna_rxf_allmulti_disable(rxf
))
2655 /* Trigger h/w if needed */
2657 if (need_hw_config
) {
2658 rxf
->cam_fltr_cbfn
= NULL
;
2659 rxf
->cam_fltr_cbarg
= rx
->bna
->bnad
;
2660 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2663 return BNA_CB_SUCCESS
;
2670 bna_rx_vlanfilter_enable(struct bna_rx
*rx
)
2672 struct bna_rxf
*rxf
= &rx
->rxf
;
2674 if (rxf
->vlan_filter_status
== BNA_STATUS_T_DISABLED
) {
2675 rxf
->vlan_filter_status
= BNA_STATUS_T_ENABLED
;
2676 rxf
->vlan_pending_bitmask
= (u8
)BFI_VLAN_BMASK_ALL
;
2677 bfa_fsm_send_event(rxf
, RXF_E_CONFIG
);
2682 bna_rx_coalescing_timeo_set(struct bna_rx
*rx
, int coalescing_timeo
)
2684 struct bna_rxp
*rxp
;
2686 list_for_each_entry(rxp
, &rx
->rxp_q
, qe
) {
2687 rxp
->cq
.ccb
->rx_coalescing_timeo
= coalescing_timeo
;
2688 bna_ib_coalescing_timeo_set(&rxp
->cq
.ib
, coalescing_timeo
);
2693 bna_rx_dim_reconfig(struct bna
*bna
, const u32 vector
[][BNA_BIAS_T_MAX
])
2697 for (i
= 0; i
< BNA_LOAD_T_MAX
; i
++)
2698 for (j
= 0; j
< BNA_BIAS_T_MAX
; j
++)
2699 bna
->rx_mod
.dim_vector
[i
][j
] = vector
[i
][j
];
2703 bna_rx_dim_update(struct bna_ccb
*ccb
)
2705 struct bna
*bna
= ccb
->cq
->rx
->bna
;
2707 u32 pkt_rt
, small_rt
, large_rt
;
2708 u8 coalescing_timeo
;
2710 if ((ccb
->pkt_rate
.small_pkt_cnt
== 0) &&
2711 (ccb
->pkt_rate
.large_pkt_cnt
== 0))
2714 /* Arrive at preconfigured coalescing timeo value based on pkt rate */
2716 small_rt
= ccb
->pkt_rate
.small_pkt_cnt
;
2717 large_rt
= ccb
->pkt_rate
.large_pkt_cnt
;
2719 pkt_rt
= small_rt
+ large_rt
;
2721 if (pkt_rt
< BNA_PKT_RATE_10K
)
2722 load
= BNA_LOAD_T_LOW_4
;
2723 else if (pkt_rt
< BNA_PKT_RATE_20K
)
2724 load
= BNA_LOAD_T_LOW_3
;
2725 else if (pkt_rt
< BNA_PKT_RATE_30K
)
2726 load
= BNA_LOAD_T_LOW_2
;
2727 else if (pkt_rt
< BNA_PKT_RATE_40K
)
2728 load
= BNA_LOAD_T_LOW_1
;
2729 else if (pkt_rt
< BNA_PKT_RATE_50K
)
2730 load
= BNA_LOAD_T_HIGH_1
;
2731 else if (pkt_rt
< BNA_PKT_RATE_60K
)
2732 load
= BNA_LOAD_T_HIGH_2
;
2733 else if (pkt_rt
< BNA_PKT_RATE_80K
)
2734 load
= BNA_LOAD_T_HIGH_3
;
2736 load
= BNA_LOAD_T_HIGH_4
;
2738 if (small_rt
> (large_rt
<< 1))
2743 ccb
->pkt_rate
.small_pkt_cnt
= 0;
2744 ccb
->pkt_rate
.large_pkt_cnt
= 0;
2746 coalescing_timeo
= bna
->rx_mod
.dim_vector
[load
][bias
];
2747 ccb
->rx_coalescing_timeo
= coalescing_timeo
;
2750 bna_ib_coalescing_timeo_set(&ccb
->cq
->ib
, coalescing_timeo
);
2753 const u32 bna_napi_dim_vector
[BNA_LOAD_T_MAX
][BNA_BIAS_T_MAX
] = {
2766 #define call_tx_stop_cbfn(tx) \
2768 if ((tx)->stop_cbfn) { \
2769 void (*cbfn)(void *, struct bna_tx *); \
2771 cbfn = (tx)->stop_cbfn; \
2772 cbarg = (tx)->stop_cbarg; \
2773 (tx)->stop_cbfn = NULL; \
2774 (tx)->stop_cbarg = NULL; \
2775 cbfn(cbarg, (tx)); \
2779 static void bna_tx_mod_cb_tx_stopped(void *tx_mod
, struct bna_tx
*tx
);
2780 static void bna_bfi_tx_enet_start(struct bna_tx
*tx
);
2781 static void bna_tx_enet_stop(struct bna_tx
*tx
);
2789 TX_E_CLEANUP_DONE
= 7,
2793 bfa_fsm_state_decl(bna_tx
, stopped
, struct bna_tx
, enum bna_tx_event
);
2794 bfa_fsm_state_decl(bna_tx
, start_wait
, struct bna_tx
, enum bna_tx_event
);
2795 bfa_fsm_state_decl(bna_tx
, started
, struct bna_tx
, enum bna_tx_event
);
2796 bfa_fsm_state_decl(bna_tx
, stop_wait
, struct bna_tx
, enum bna_tx_event
);
2797 bfa_fsm_state_decl(bna_tx
, cleanup_wait
, struct bna_tx
,
2799 bfa_fsm_state_decl(bna_tx
, prio_stop_wait
, struct bna_tx
,
2801 bfa_fsm_state_decl(bna_tx
, prio_cleanup_wait
, struct bna_tx
,
2803 bfa_fsm_state_decl(bna_tx
, failed
, struct bna_tx
, enum bna_tx_event
);
2804 bfa_fsm_state_decl(bna_tx
, quiesce_wait
, struct bna_tx
,
2808 bna_tx_sm_stopped_entry(struct bna_tx
*tx
)
2810 call_tx_stop_cbfn(tx
);
2814 bna_tx_sm_stopped(struct bna_tx
*tx
, enum bna_tx_event event
)
2818 bfa_fsm_set_state(tx
, bna_tx_sm_start_wait
);
2822 call_tx_stop_cbfn(tx
);
2829 case TX_E_BW_UPDATE
:
2834 bfa_sm_fault(event
);
2839 bna_tx_sm_start_wait_entry(struct bna_tx
*tx
)
2841 bna_bfi_tx_enet_start(tx
);
2845 bna_tx_sm_start_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2849 tx
->flags
&= ~BNA_TX_F_BW_UPDATED
;
2850 bfa_fsm_set_state(tx
, bna_tx_sm_stop_wait
);
2854 tx
->flags
&= ~BNA_TX_F_BW_UPDATED
;
2855 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
2859 if (tx
->flags
& BNA_TX_F_BW_UPDATED
) {
2860 tx
->flags
&= ~BNA_TX_F_BW_UPDATED
;
2861 bfa_fsm_set_state(tx
, bna_tx_sm_prio_stop_wait
);
2863 bfa_fsm_set_state(tx
, bna_tx_sm_started
);
2866 case TX_E_BW_UPDATE
:
2867 tx
->flags
|= BNA_TX_F_BW_UPDATED
;
2871 bfa_sm_fault(event
);
2876 bna_tx_sm_started_entry(struct bna_tx
*tx
)
2878 struct bna_txq
*txq
;
2879 int is_regular
= (tx
->type
== BNA_TX_T_REGULAR
);
2881 list_for_each_entry(txq
, &tx
->txq_q
, qe
) {
2882 txq
->tcb
->priority
= txq
->priority
;
2884 bna_ib_start(tx
->bna
, &txq
->ib
, is_regular
);
2886 tx
->tx_resume_cbfn(tx
->bna
->bnad
, tx
);
2890 bna_tx_sm_started(struct bna_tx
*tx
, enum bna_tx_event event
)
2894 bfa_fsm_set_state(tx
, bna_tx_sm_stop_wait
);
2895 tx
->tx_stall_cbfn(tx
->bna
->bnad
, tx
);
2896 bna_tx_enet_stop(tx
);
2900 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
2901 tx
->tx_stall_cbfn(tx
->bna
->bnad
, tx
);
2902 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
2905 case TX_E_BW_UPDATE
:
2906 bfa_fsm_set_state(tx
, bna_tx_sm_prio_stop_wait
);
2910 bfa_sm_fault(event
);
2915 bna_tx_sm_stop_wait_entry(struct bna_tx
*tx
)
2920 bna_tx_sm_stop_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2925 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
2926 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
2931 * We are here due to start_wait -> stop_wait transition on
2934 bna_tx_enet_stop(tx
);
2937 case TX_E_BW_UPDATE
:
2942 bfa_sm_fault(event
);
2947 bna_tx_sm_cleanup_wait_entry(struct bna_tx
*tx
)
2952 bna_tx_sm_cleanup_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2956 case TX_E_BW_UPDATE
:
2960 case TX_E_CLEANUP_DONE
:
2961 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
2965 bfa_sm_fault(event
);
2970 bna_tx_sm_prio_stop_wait_entry(struct bna_tx
*tx
)
2972 tx
->tx_stall_cbfn(tx
->bna
->bnad
, tx
);
2973 bna_tx_enet_stop(tx
);
2977 bna_tx_sm_prio_stop_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
2981 bfa_fsm_set_state(tx
, bna_tx_sm_stop_wait
);
2985 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
2986 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
2990 bfa_fsm_set_state(tx
, bna_tx_sm_prio_cleanup_wait
);
2993 case TX_E_BW_UPDATE
:
2998 bfa_sm_fault(event
);
3003 bna_tx_sm_prio_cleanup_wait_entry(struct bna_tx
*tx
)
3005 tx
->tx_cleanup_cbfn(tx
->bna
->bnad
, tx
);
3009 bna_tx_sm_prio_cleanup_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
3013 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
3017 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
3020 case TX_E_BW_UPDATE
:
3024 case TX_E_CLEANUP_DONE
:
3025 bfa_fsm_set_state(tx
, bna_tx_sm_start_wait
);
3029 bfa_sm_fault(event
);
3034 bna_tx_sm_failed_entry(struct bna_tx
*tx
)
3039 bna_tx_sm_failed(struct bna_tx
*tx
, enum bna_tx_event event
)
3043 bfa_fsm_set_state(tx
, bna_tx_sm_quiesce_wait
);
3047 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
3054 case TX_E_CLEANUP_DONE
:
3055 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
3059 bfa_sm_fault(event
);
3064 bna_tx_sm_quiesce_wait_entry(struct bna_tx
*tx
)
3069 bna_tx_sm_quiesce_wait(struct bna_tx
*tx
, enum bna_tx_event event
)
3073 bfa_fsm_set_state(tx
, bna_tx_sm_cleanup_wait
);
3077 bfa_fsm_set_state(tx
, bna_tx_sm_failed
);
3080 case TX_E_CLEANUP_DONE
:
3081 bfa_fsm_set_state(tx
, bna_tx_sm_start_wait
);
3084 case TX_E_BW_UPDATE
:
3089 bfa_sm_fault(event
);
3094 bna_bfi_tx_enet_start(struct bna_tx
*tx
)
3096 struct bfi_enet_tx_cfg_req
*cfg_req
= &tx
->bfi_enet_cmd
.cfg_req
;
3097 struct bna_txq
*txq
= NULL
;
3100 bfi_msgq_mhdr_set(cfg_req
->mh
, BFI_MC_ENET
,
3101 BFI_ENET_H2I_TX_CFG_SET_REQ
, 0, tx
->rid
);
3102 cfg_req
->mh
.num_entries
= htons(
3103 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_tx_cfg_req
)));
3105 cfg_req
->num_queues
= tx
->num_txq
;
3106 for (i
= 0; i
< tx
->num_txq
; i
++) {
3107 txq
= txq
? list_next_entry(txq
, qe
)
3108 : list_first_entry(&tx
->txq_q
, struct bna_txq
, qe
);
3109 bfi_enet_datapath_q_init(&cfg_req
->q_cfg
[i
].q
.q
, &txq
->qpt
);
3110 cfg_req
->q_cfg
[i
].q
.priority
= txq
->priority
;
3112 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_lo
=
3113 txq
->ib
.ib_seg_host_addr
.lsb
;
3114 cfg_req
->q_cfg
[i
].ib
.index_addr
.a32
.addr_hi
=
3115 txq
->ib
.ib_seg_host_addr
.msb
;
3116 cfg_req
->q_cfg
[i
].ib
.intr
.msix_index
=
3117 htons((u16
)txq
->ib
.intr_vector
);
3120 cfg_req
->ib_cfg
.int_pkt_dma
= BNA_STATUS_T_ENABLED
;
3121 cfg_req
->ib_cfg
.int_enabled
= BNA_STATUS_T_ENABLED
;
3122 cfg_req
->ib_cfg
.int_pkt_enabled
= BNA_STATUS_T_DISABLED
;
3123 cfg_req
->ib_cfg
.continuous_coalescing
= BNA_STATUS_T_ENABLED
;
3124 cfg_req
->ib_cfg
.msix
= (txq
->ib
.intr_type
== BNA_INTR_T_MSIX
)
3125 ? BNA_STATUS_T_ENABLED
: BNA_STATUS_T_DISABLED
;
3126 cfg_req
->ib_cfg
.coalescing_timeout
=
3127 htonl((u32
)txq
->ib
.coalescing_timeo
);
3128 cfg_req
->ib_cfg
.inter_pkt_timeout
=
3129 htonl((u32
)txq
->ib
.interpkt_timeo
);
3130 cfg_req
->ib_cfg
.inter_pkt_count
= (u8
)txq
->ib
.interpkt_count
;
3132 cfg_req
->tx_cfg
.vlan_mode
= BFI_ENET_TX_VLAN_WI
;
3133 cfg_req
->tx_cfg
.vlan_id
= htons((u16
)tx
->txf_vlan_id
);
3134 cfg_req
->tx_cfg
.admit_tagged_frame
= BNA_STATUS_T_ENABLED
;
3135 cfg_req
->tx_cfg
.apply_vlan_filter
= BNA_STATUS_T_DISABLED
;
3137 bfa_msgq_cmd_set(&tx
->msgq_cmd
, NULL
, NULL
,
3138 sizeof(struct bfi_enet_tx_cfg_req
), &cfg_req
->mh
);
3139 bfa_msgq_cmd_post(&tx
->bna
->msgq
, &tx
->msgq_cmd
);
3143 bna_bfi_tx_enet_stop(struct bna_tx
*tx
)
3145 struct bfi_enet_req
*req
= &tx
->bfi_enet_cmd
.req
;
3147 bfi_msgq_mhdr_set(req
->mh
, BFI_MC_ENET
,
3148 BFI_ENET_H2I_TX_CFG_CLR_REQ
, 0, tx
->rid
);
3149 req
->mh
.num_entries
= htons(
3150 bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_req
)));
3151 bfa_msgq_cmd_set(&tx
->msgq_cmd
, NULL
, NULL
, sizeof(struct bfi_enet_req
),
3153 bfa_msgq_cmd_post(&tx
->bna
->msgq
, &tx
->msgq_cmd
);
3157 bna_tx_enet_stop(struct bna_tx
*tx
)
3159 struct bna_txq
*txq
;
3162 list_for_each_entry(txq
, &tx
->txq_q
, qe
)
3163 bna_ib_stop(tx
->bna
, &txq
->ib
);
3165 bna_bfi_tx_enet_stop(tx
);
3169 bna_txq_qpt_setup(struct bna_txq
*txq
, int page_count
, int page_size
,
3170 struct bna_mem_descr
*qpt_mem
,
3171 struct bna_mem_descr
*swqpt_mem
,
3172 struct bna_mem_descr
*page_mem
)
3176 struct bna_dma_addr bna_dma
;
3179 txq
->qpt
.hw_qpt_ptr
.lsb
= qpt_mem
->dma
.lsb
;
3180 txq
->qpt
.hw_qpt_ptr
.msb
= qpt_mem
->dma
.msb
;
3181 txq
->qpt
.kv_qpt_ptr
= qpt_mem
->kva
;
3182 txq
->qpt
.page_count
= page_count
;
3183 txq
->qpt
.page_size
= page_size
;
3185 txq
->tcb
->sw_qpt
= (void **) swqpt_mem
->kva
;
3186 txq
->tcb
->sw_q
= page_mem
->kva
;
3188 kva
= page_mem
->kva
;
3189 BNA_GET_DMA_ADDR(&page_mem
->dma
, dma
);
3191 for (i
= 0; i
< page_count
; i
++) {
3192 txq
->tcb
->sw_qpt
[i
] = kva
;
3195 BNA_SET_DMA_ADDR(dma
, &bna_dma
);
3196 ((struct bna_dma_addr
*)txq
->qpt
.kv_qpt_ptr
)[i
].lsb
=
3198 ((struct bna_dma_addr
*)txq
->qpt
.kv_qpt_ptr
)[i
].msb
=
3204 static struct bna_tx
*
3205 bna_tx_get(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
)
3207 struct bna_tx
*tx
= NULL
;
3209 if (list_empty(&tx_mod
->tx_free_q
))
3211 if (type
== BNA_TX_T_REGULAR
)
3212 tx
= list_first_entry(&tx_mod
->tx_free_q
, struct bna_tx
, qe
);
3214 tx
= list_last_entry(&tx_mod
->tx_free_q
, struct bna_tx
, qe
);
3222 bna_tx_free(struct bna_tx
*tx
)
3224 struct bna_tx_mod
*tx_mod
= &tx
->bna
->tx_mod
;
3225 struct bna_txq
*txq
;
3226 struct list_head
*qe
;
3228 while (!list_empty(&tx
->txq_q
)) {
3229 txq
= list_first_entry(&tx
->txq_q
, struct bna_txq
, qe
);
3232 list_move_tail(&txq
->qe
, &tx_mod
->txq_free_q
);
3235 list_for_each(qe
, &tx_mod
->tx_active_q
) {
3236 if (qe
== &tx
->qe
) {
3245 list_for_each_prev(qe
, &tx_mod
->tx_free_q
)
3246 if (((struct bna_tx
*)qe
)->rid
< tx
->rid
)
3249 list_add(&tx
->qe
, qe
);
3253 bna_tx_start(struct bna_tx
*tx
)
3255 tx
->flags
|= BNA_TX_F_ENET_STARTED
;
3256 if (tx
->flags
& BNA_TX_F_ENABLED
)
3257 bfa_fsm_send_event(tx
, TX_E_START
);
3261 bna_tx_stop(struct bna_tx
*tx
)
3263 tx
->stop_cbfn
= bna_tx_mod_cb_tx_stopped
;
3264 tx
->stop_cbarg
= &tx
->bna
->tx_mod
;
3266 tx
->flags
&= ~BNA_TX_F_ENET_STARTED
;
3267 bfa_fsm_send_event(tx
, TX_E_STOP
);
3271 bna_tx_fail(struct bna_tx
*tx
)
3273 tx
->flags
&= ~BNA_TX_F_ENET_STARTED
;
3274 bfa_fsm_send_event(tx
, TX_E_FAIL
);
3278 bna_bfi_tx_enet_start_rsp(struct bna_tx
*tx
, struct bfi_msgq_mhdr
*msghdr
)
3280 struct bfi_enet_tx_cfg_rsp
*cfg_rsp
= &tx
->bfi_enet_cmd
.cfg_rsp
;
3281 struct bna_txq
*txq
= NULL
;
3284 bfa_msgq_rsp_copy(&tx
->bna
->msgq
, (u8
*)cfg_rsp
,
3285 sizeof(struct bfi_enet_tx_cfg_rsp
));
3287 tx
->hw_id
= cfg_rsp
->hw_id
;
3289 for (i
= 0, txq
= list_first_entry(&tx
->txq_q
, struct bna_txq
, qe
);
3290 i
< tx
->num_txq
; i
++, txq
= list_next_entry(txq
, qe
)) {
3291 /* Setup doorbells */
3292 txq
->tcb
->i_dbell
->doorbell_addr
=
3293 tx
->bna
->pcidev
.pci_bar_kva
3294 + ntohl(cfg_rsp
->q_handles
[i
].i_dbell
);
3296 tx
->bna
->pcidev
.pci_bar_kva
3297 + ntohl(cfg_rsp
->q_handles
[i
].q_dbell
);
3298 txq
->hw_id
= cfg_rsp
->q_handles
[i
].hw_qid
;
3300 /* Initialize producer/consumer indexes */
3301 (*txq
->tcb
->hw_consumer_index
) = 0;
3302 txq
->tcb
->producer_index
= txq
->tcb
->consumer_index
= 0;
3305 bfa_fsm_send_event(tx
, TX_E_STARTED
);
3309 bna_bfi_tx_enet_stop_rsp(struct bna_tx
*tx
, struct bfi_msgq_mhdr
*msghdr
)
3311 bfa_fsm_send_event(tx
, TX_E_STOPPED
);
3315 bna_bfi_bw_update_aen(struct bna_tx_mod
*tx_mod
)
3319 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3320 bfa_fsm_send_event(tx
, TX_E_BW_UPDATE
);
3324 bna_tx_res_req(int num_txq
, int txq_depth
, struct bna_res_info
*res_info
)
3328 struct bna_mem_info
*mem_info
;
3330 res_info
[BNA_TX_RES_MEM_T_TCB
].res_type
= BNA_RES_T_MEM
;
3331 mem_info
= &res_info
[BNA_TX_RES_MEM_T_TCB
].res_u
.mem_info
;
3332 mem_info
->mem_type
= BNA_MEM_T_KVA
;
3333 mem_info
->len
= sizeof(struct bna_tcb
);
3334 mem_info
->num
= num_txq
;
3336 q_size
= txq_depth
* BFI_TXQ_WI_SIZE
;
3337 q_size
= ALIGN(q_size
, PAGE_SIZE
);
3338 page_count
= q_size
>> PAGE_SHIFT
;
3340 res_info
[BNA_TX_RES_MEM_T_QPT
].res_type
= BNA_RES_T_MEM
;
3341 mem_info
= &res_info
[BNA_TX_RES_MEM_T_QPT
].res_u
.mem_info
;
3342 mem_info
->mem_type
= BNA_MEM_T_DMA
;
3343 mem_info
->len
= page_count
* sizeof(struct bna_dma_addr
);
3344 mem_info
->num
= num_txq
;
3346 res_info
[BNA_TX_RES_MEM_T_SWQPT
].res_type
= BNA_RES_T_MEM
;
3347 mem_info
= &res_info
[BNA_TX_RES_MEM_T_SWQPT
].res_u
.mem_info
;
3348 mem_info
->mem_type
= BNA_MEM_T_KVA
;
3349 mem_info
->len
= page_count
* sizeof(void *);
3350 mem_info
->num
= num_txq
;
3352 res_info
[BNA_TX_RES_MEM_T_PAGE
].res_type
= BNA_RES_T_MEM
;
3353 mem_info
= &res_info
[BNA_TX_RES_MEM_T_PAGE
].res_u
.mem_info
;
3354 mem_info
->mem_type
= BNA_MEM_T_DMA
;
3355 mem_info
->len
= PAGE_SIZE
* page_count
;
3356 mem_info
->num
= num_txq
;
3358 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_type
= BNA_RES_T_MEM
;
3359 mem_info
= &res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
;
3360 mem_info
->mem_type
= BNA_MEM_T_DMA
;
3361 mem_info
->len
= BFI_IBIDX_SIZE
;
3362 mem_info
->num
= num_txq
;
3364 res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_type
= BNA_RES_T_INTR
;
3365 res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
.intr_type
=
3367 res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
.num
= num_txq
;
3371 bna_tx_create(struct bna
*bna
, struct bnad
*bnad
,
3372 struct bna_tx_config
*tx_cfg
,
3373 const struct bna_tx_event_cbfn
*tx_cbfn
,
3374 struct bna_res_info
*res_info
, void *priv
)
3376 struct bna_intr_info
*intr_info
;
3377 struct bna_tx_mod
*tx_mod
= &bna
->tx_mod
;
3379 struct bna_txq
*txq
;
3383 intr_info
= &res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
;
3384 page_count
= (res_info
[BNA_TX_RES_MEM_T_PAGE
].res_u
.mem_info
.len
) /
3391 if ((intr_info
->num
!= 1) && (intr_info
->num
!= tx_cfg
->num_txq
))
3396 tx
= bna_tx_get(tx_mod
, tx_cfg
->tx_type
);
3404 INIT_LIST_HEAD(&tx
->txq_q
);
3405 for (i
= 0; i
< tx_cfg
->num_txq
; i
++) {
3406 if (list_empty(&tx_mod
->txq_free_q
))
3409 txq
= list_first_entry(&tx_mod
->txq_free_q
, struct bna_txq
, qe
);
3410 list_move_tail(&txq
->qe
, &tx
->txq_q
);
3420 tx
->tcb_setup_cbfn
= tx_cbfn
->tcb_setup_cbfn
;
3421 tx
->tcb_destroy_cbfn
= tx_cbfn
->tcb_destroy_cbfn
;
3422 /* Following callbacks are mandatory */
3423 tx
->tx_stall_cbfn
= tx_cbfn
->tx_stall_cbfn
;
3424 tx
->tx_resume_cbfn
= tx_cbfn
->tx_resume_cbfn
;
3425 tx
->tx_cleanup_cbfn
= tx_cbfn
->tx_cleanup_cbfn
;
3427 list_add_tail(&tx
->qe
, &tx_mod
->tx_active_q
);
3429 tx
->num_txq
= tx_cfg
->num_txq
;
3432 if (tx
->bna
->tx_mod
.flags
& BNA_TX_MOD_F_ENET_STARTED
) {
3434 case BNA_TX_T_REGULAR
:
3435 if (!(tx
->bna
->tx_mod
.flags
&
3436 BNA_TX_MOD_F_ENET_LOOPBACK
))
3437 tx
->flags
|= BNA_TX_F_ENET_STARTED
;
3439 case BNA_TX_T_LOOPBACK
:
3440 if (tx
->bna
->tx_mod
.flags
& BNA_TX_MOD_F_ENET_LOOPBACK
)
3441 tx
->flags
|= BNA_TX_F_ENET_STARTED
;
3449 list_for_each_entry(txq
, &tx
->txq_q
, qe
) {
3450 txq
->tcb
= (struct bna_tcb
*)
3451 res_info
[BNA_TX_RES_MEM_T_TCB
].res_u
.mem_info
.mdl
[i
].kva
;
3452 txq
->tx_packets
= 0;
3456 txq
->ib
.ib_seg_host_addr
.lsb
=
3457 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.lsb
;
3458 txq
->ib
.ib_seg_host_addr
.msb
=
3459 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].dma
.msb
;
3460 txq
->ib
.ib_seg_host_addr_kva
=
3461 res_info
[BNA_TX_RES_MEM_T_IBIDX
].res_u
.mem_info
.mdl
[i
].kva
;
3462 txq
->ib
.intr_type
= intr_info
->intr_type
;
3463 txq
->ib
.intr_vector
= (intr_info
->num
== 1) ?
3464 intr_info
->idl
[0].vector
:
3465 intr_info
->idl
[i
].vector
;
3466 if (intr_info
->intr_type
== BNA_INTR_T_INTX
)
3467 txq
->ib
.intr_vector
= BIT(txq
->ib
.intr_vector
);
3468 txq
->ib
.coalescing_timeo
= tx_cfg
->coalescing_timeo
;
3469 txq
->ib
.interpkt_timeo
= BFI_TX_INTERPKT_TIMEO
;
3470 txq
->ib
.interpkt_count
= BFI_TX_INTERPKT_COUNT
;
3474 txq
->tcb
->q_depth
= tx_cfg
->txq_depth
;
3475 txq
->tcb
->unmap_q
= (void *)
3476 res_info
[BNA_TX_RES_MEM_T_UNMAPQ
].res_u
.mem_info
.mdl
[i
].kva
;
3477 txq
->tcb
->hw_consumer_index
=
3478 (u32
*)txq
->ib
.ib_seg_host_addr_kva
;
3479 txq
->tcb
->i_dbell
= &txq
->ib
.door_bell
;
3480 txq
->tcb
->intr_type
= txq
->ib
.intr_type
;
3481 txq
->tcb
->intr_vector
= txq
->ib
.intr_vector
;
3482 txq
->tcb
->txq
= txq
;
3483 txq
->tcb
->bnad
= bnad
;
3486 /* QPT, SWQPT, Pages */
3487 bna_txq_qpt_setup(txq
, page_count
, PAGE_SIZE
,
3488 &res_info
[BNA_TX_RES_MEM_T_QPT
].res_u
.mem_info
.mdl
[i
],
3489 &res_info
[BNA_TX_RES_MEM_T_SWQPT
].res_u
.mem_info
.mdl
[i
],
3490 &res_info
[BNA_TX_RES_MEM_T_PAGE
].
3491 res_u
.mem_info
.mdl
[i
]);
3493 /* Callback to bnad for setting up TCB */
3494 if (tx
->tcb_setup_cbfn
)
3495 (tx
->tcb_setup_cbfn
)(bna
->bnad
, txq
->tcb
);
3497 if (tx_cfg
->num_txq
== BFI_TX_MAX_PRIO
)
3498 txq
->priority
= txq
->tcb
->id
;
3500 txq
->priority
= tx_mod
->default_prio
;
3505 tx
->txf_vlan_id
= 0;
3507 bfa_fsm_set_state(tx
, bna_tx_sm_stopped
);
3509 tx_mod
->rid_mask
|= BIT(tx
->rid
);
3519 bna_tx_destroy(struct bna_tx
*tx
)
3521 struct bna_txq
*txq
;
3523 list_for_each_entry(txq
, &tx
->txq_q
, qe
)
3524 if (tx
->tcb_destroy_cbfn
)
3525 (tx
->tcb_destroy_cbfn
)(tx
->bna
->bnad
, txq
->tcb
);
3527 tx
->bna
->tx_mod
.rid_mask
&= ~BIT(tx
->rid
);
3532 bna_tx_enable(struct bna_tx
*tx
)
3534 if (tx
->fsm
!= (bfa_sm_t
)bna_tx_sm_stopped
)
3537 tx
->flags
|= BNA_TX_F_ENABLED
;
3539 if (tx
->flags
& BNA_TX_F_ENET_STARTED
)
3540 bfa_fsm_send_event(tx
, TX_E_START
);
3544 bna_tx_disable(struct bna_tx
*tx
, enum bna_cleanup_type type
,
3545 void (*cbfn
)(void *, struct bna_tx
*))
3547 if (type
== BNA_SOFT_CLEANUP
) {
3548 (*cbfn
)(tx
->bna
->bnad
, tx
);
3552 tx
->stop_cbfn
= cbfn
;
3553 tx
->stop_cbarg
= tx
->bna
->bnad
;
3555 tx
->flags
&= ~BNA_TX_F_ENABLED
;
3557 bfa_fsm_send_event(tx
, TX_E_STOP
);
3561 bna_tx_cleanup_complete(struct bna_tx
*tx
)
3563 bfa_fsm_send_event(tx
, TX_E_CLEANUP_DONE
);
3567 bna_tx_mod_cb_tx_stopped(void *arg
, struct bna_tx
*tx
)
3569 struct bna_tx_mod
*tx_mod
= (struct bna_tx_mod
*)arg
;
3571 bfa_wc_down(&tx_mod
->tx_stop_wc
);
3575 bna_tx_mod_cb_tx_stopped_all(void *arg
)
3577 struct bna_tx_mod
*tx_mod
= (struct bna_tx_mod
*)arg
;
3579 if (tx_mod
->stop_cbfn
)
3580 tx_mod
->stop_cbfn(&tx_mod
->bna
->enet
);
3581 tx_mod
->stop_cbfn
= NULL
;
3585 bna_tx_mod_init(struct bna_tx_mod
*tx_mod
, struct bna
*bna
,
3586 struct bna_res_info
*res_info
)
3593 tx_mod
->tx
= (struct bna_tx
*)
3594 res_info
[BNA_MOD_RES_MEM_T_TX_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
3595 tx_mod
->txq
= (struct bna_txq
*)
3596 res_info
[BNA_MOD_RES_MEM_T_TXQ_ARRAY
].res_u
.mem_info
.mdl
[0].kva
;
3598 INIT_LIST_HEAD(&tx_mod
->tx_free_q
);
3599 INIT_LIST_HEAD(&tx_mod
->tx_active_q
);
3601 INIT_LIST_HEAD(&tx_mod
->txq_free_q
);
3603 for (i
= 0; i
< bna
->ioceth
.attr
.num_txq
; i
++) {
3604 tx_mod
->tx
[i
].rid
= i
;
3605 list_add_tail(&tx_mod
->tx
[i
].qe
, &tx_mod
->tx_free_q
);
3606 list_add_tail(&tx_mod
->txq
[i
].qe
, &tx_mod
->txq_free_q
);
3609 tx_mod
->prio_map
= BFI_TX_PRIO_MAP_ALL
;
3610 tx_mod
->default_prio
= 0;
3611 tx_mod
->iscsi_over_cee
= BNA_STATUS_T_DISABLED
;
3612 tx_mod
->iscsi_prio
= -1;
3616 bna_tx_mod_uninit(struct bna_tx_mod
*tx_mod
)
3622 bna_tx_mod_start(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
)
3626 tx_mod
->flags
|= BNA_TX_MOD_F_ENET_STARTED
;
3627 if (type
== BNA_TX_T_LOOPBACK
)
3628 tx_mod
->flags
|= BNA_TX_MOD_F_ENET_LOOPBACK
;
3630 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3631 if (tx
->type
== type
)
3636 bna_tx_mod_stop(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
)
3640 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_STARTED
;
3641 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_LOOPBACK
;
3643 tx_mod
->stop_cbfn
= bna_enet_cb_tx_stopped
;
3645 bfa_wc_init(&tx_mod
->tx_stop_wc
, bna_tx_mod_cb_tx_stopped_all
, tx_mod
);
3647 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3648 if (tx
->type
== type
) {
3649 bfa_wc_up(&tx_mod
->tx_stop_wc
);
3653 bfa_wc_wait(&tx_mod
->tx_stop_wc
);
3657 bna_tx_mod_fail(struct bna_tx_mod
*tx_mod
)
3661 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_STARTED
;
3662 tx_mod
->flags
&= ~BNA_TX_MOD_F_ENET_LOOPBACK
;
3664 list_for_each_entry(tx
, &tx_mod
->tx_active_q
, qe
)
3669 bna_tx_coalescing_timeo_set(struct bna_tx
*tx
, int coalescing_timeo
)
3671 struct bna_txq
*txq
;
3673 list_for_each_entry(txq
, &tx
->txq_q
, qe
)
3674 bna_ib_coalescing_timeo_set(&txq
->ib
, coalescing_timeo
);