2 * Linux network driver for Brocade 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-2011 Brocade Communications Systems, Inc.
24 #include "bna_types.h"
26 extern const u32 bna_napi_dim_vector
[][BNA_BIAS_T_MAX
];
28 /* Macros and constants */
30 #define BNA_IOC_TIMER_FREQ 200
33 #define BNA_MESSAGE_SIZE 256
35 #define bna_is_small_rxq(_id) ((_id) & 0x1)
37 #define BNA_MAC_IS_EQUAL(_mac1, _mac2) \
38 (!memcmp((_mac1), (_mac2), sizeof(mac_t)))
40 #define BNA_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
42 #define BNA_TO_POWER_OF_2(x) \
45 while ((x) && (x) != 1) { \
52 #define BNA_TO_POWER_OF_2_HIGH(x) \
61 * input : _addr-> os dma addr in host endian format,
62 * output : _bna_dma_addr-> pointer to hw dma addr
64 #define BNA_SET_DMA_ADDR(_addr, _bna_dma_addr) \
67 cpu_to_be64((u64)(_addr)); \
68 (_bna_dma_addr)->msb = ((struct bna_dma_addr *)&tmp_addr)->msb; \
69 (_bna_dma_addr)->lsb = ((struct bna_dma_addr *)&tmp_addr)->lsb; \
73 * input : _bna_dma_addr-> pointer to hw dma addr
74 * output : _addr-> os dma addr in host endian format
76 #define BNA_GET_DMA_ADDR(_bna_dma_addr, _addr) \
78 (_addr) = ((((u64)ntohl((_bna_dma_addr)->msb))) << 32) \
79 | ((ntohl((_bna_dma_addr)->lsb) & 0xffffffff)); \
82 #define containing_rec(addr, type, field) \
83 ((type *)((unsigned char *)(addr) - \
84 (unsigned char *)(&((type *)0)->field)))
86 #define BNA_TXQ_WI_NEEDED(_vectors) (((_vectors) + 3) >> 2)
88 /* TxQ element is 64 bytes */
89 #define BNA_TXQ_PAGE_INDEX_MAX (PAGE_SIZE >> 6)
90 #define BNA_TXQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 6)
92 #define BNA_TXQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
94 unsigned int page_index; /* index within a page */ \
96 page_index = (_qe_idx) & (BNA_TXQ_PAGE_INDEX_MAX - 1); \
97 (_qe_ptr_range) = (BNA_TXQ_PAGE_INDEX_MAX - page_index); \
98 page_addr = (_qpt_ptr)[((_qe_idx) >> BNA_TXQ_PAGE_INDEX_MAX_SHIFT)];\
99 (_qe_ptr) = &((struct bna_txq_entry *)(page_addr))[page_index]; \
102 /* RxQ element is 8 bytes */
103 #define BNA_RXQ_PAGE_INDEX_MAX (PAGE_SIZE >> 3)
104 #define BNA_RXQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 3)
106 #define BNA_RXQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
108 unsigned int page_index; /* index within a page */ \
110 page_index = (_qe_idx) & (BNA_RXQ_PAGE_INDEX_MAX - 1); \
111 (_qe_ptr_range) = (BNA_RXQ_PAGE_INDEX_MAX - page_index); \
112 page_addr = (_qpt_ptr)[((_qe_idx) >> \
113 BNA_RXQ_PAGE_INDEX_MAX_SHIFT)]; \
114 (_qe_ptr) = &((struct bna_rxq_entry *)(page_addr))[page_index]; \
117 /* CQ element is 16 bytes */
118 #define BNA_CQ_PAGE_INDEX_MAX (PAGE_SIZE >> 4)
119 #define BNA_CQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 4)
121 #define BNA_CQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
123 unsigned int page_index; /* index within a page */ \
126 page_index = (_qe_idx) & (BNA_CQ_PAGE_INDEX_MAX - 1); \
127 (_qe_ptr_range) = (BNA_CQ_PAGE_INDEX_MAX - page_index); \
128 page_addr = (_qpt_ptr)[((_qe_idx) >> \
129 BNA_CQ_PAGE_INDEX_MAX_SHIFT)]; \
130 (_qe_ptr) = &((struct bna_cq_entry *)(page_addr))[page_index];\
133 #define BNA_QE_INDX_2_PTR(_cast, _qe_idx, _q_base) \
134 (&((_cast *)(_q_base))[(_qe_idx)])
136 #define BNA_QE_INDX_RANGE(_qe_idx, _q_depth) ((_q_depth) - (_qe_idx))
138 #define BNA_QE_INDX_ADD(_qe_idx, _qe_num, _q_depth) \
139 ((_qe_idx) = ((_qe_idx) + (_qe_num)) & ((_q_depth) - 1))
141 #define BNA_QE_INDX_INC(_idx, _q_depth) BNA_QE_INDX_ADD(_idx, 1, _q_depth)
143 #define BNA_Q_INDEX_CHANGE(_old_idx, _updated_idx, _q_depth) \
144 (((_updated_idx) - (_old_idx)) & ((_q_depth) - 1))
146 #define BNA_QE_FREE_CNT(_q_ptr, _q_depth) \
147 (((_q_ptr)->consumer_index - (_q_ptr)->producer_index - 1) & \
150 #define BNA_QE_IN_USE_CNT(_q_ptr, _q_depth) \
151 ((((_q_ptr)->producer_index - (_q_ptr)->consumer_index)) & \
154 #define BNA_Q_GET_CI(_q_ptr) ((_q_ptr)->q.consumer_index)
156 #define BNA_Q_GET_PI(_q_ptr) ((_q_ptr)->q.producer_index)
158 #define BNA_Q_PI_ADD(_q_ptr, _num) \
159 (_q_ptr)->q.producer_index = \
160 (((_q_ptr)->q.producer_index + (_num)) & \
161 ((_q_ptr)->q.q_depth - 1))
163 #define BNA_Q_CI_ADD(_q_ptr, _num) \
164 (_q_ptr)->q.consumer_index = \
165 (((_q_ptr)->q.consumer_index + (_num)) \
166 & ((_q_ptr)->q.q_depth - 1))
168 #define BNA_Q_FREE_COUNT(_q_ptr) \
169 (BNA_QE_FREE_CNT(&((_q_ptr)->q), (_q_ptr)->q.q_depth))
171 #define BNA_Q_IN_USE_COUNT(_q_ptr) \
172 (BNA_QE_IN_USE_CNT(&(_q_ptr)->q, (_q_ptr)->q.q_depth))
174 #define BNA_LARGE_PKT_SIZE 1000
176 #define BNA_UPDATE_PKT_CNT(_pkt, _len) \
178 if ((_len) > BNA_LARGE_PKT_SIZE) { \
179 (_pkt)->large_pkt_cnt++; \
181 (_pkt)->small_pkt_cnt++; \
185 #define call_rxf_stop_cbfn(rxf) \
187 if ((rxf)->stop_cbfn) { \
188 void (*cbfn)(struct bna_rx *); \
189 struct bna_rx *cbarg; \
190 cbfn = (rxf)->stop_cbfn; \
191 cbarg = (rxf)->stop_cbarg; \
192 (rxf)->stop_cbfn = NULL; \
193 (rxf)->stop_cbarg = NULL; \
198 #define call_rxf_start_cbfn(rxf) \
200 if ((rxf)->start_cbfn) { \
201 void (*cbfn)(struct bna_rx *); \
202 struct bna_rx *cbarg; \
203 cbfn = (rxf)->start_cbfn; \
204 cbarg = (rxf)->start_cbarg; \
205 (rxf)->start_cbfn = NULL; \
206 (rxf)->start_cbarg = NULL; \
211 #define call_rxf_cam_fltr_cbfn(rxf) \
213 if ((rxf)->cam_fltr_cbfn) { \
214 void (*cbfn)(struct bnad *, struct bna_rx *); \
215 struct bnad *cbarg; \
216 cbfn = (rxf)->cam_fltr_cbfn; \
217 cbarg = (rxf)->cam_fltr_cbarg; \
218 (rxf)->cam_fltr_cbfn = NULL; \
219 (rxf)->cam_fltr_cbarg = NULL; \
220 cbfn(cbarg, rxf->rx); \
224 #define call_rxf_pause_cbfn(rxf) \
226 if ((rxf)->oper_state_cbfn) { \
227 void (*cbfn)(struct bnad *, struct bna_rx *); \
228 struct bnad *cbarg; \
229 cbfn = (rxf)->oper_state_cbfn; \
230 cbarg = (rxf)->oper_state_cbarg; \
231 (rxf)->oper_state_cbfn = NULL; \
232 (rxf)->oper_state_cbarg = NULL; \
233 cbfn(cbarg, rxf->rx); \
237 #define call_rxf_resume_cbfn(rxf) call_rxf_pause_cbfn(rxf)
239 #define is_xxx_enable(mode, bitmask, xxx) ((bitmask & xxx) && (mode & xxx))
241 #define is_xxx_disable(mode, bitmask, xxx) ((bitmask & xxx) && !(mode & xxx))
243 #define xxx_enable(mode, bitmask, xxx) \
249 #define xxx_disable(mode, bitmask, xxx) \
255 #define xxx_inactive(mode, bitmask, xxx) \
261 #define is_promisc_enable(mode, bitmask) \
262 is_xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
264 #define is_promisc_disable(mode, bitmask) \
265 is_xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
267 #define promisc_enable(mode, bitmask) \
268 xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
270 #define promisc_disable(mode, bitmask) \
271 xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
273 #define promisc_inactive(mode, bitmask) \
274 xxx_inactive(mode, bitmask, BNA_RXMODE_PROMISC)
276 #define is_default_enable(mode, bitmask) \
277 is_xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
279 #define is_default_disable(mode, bitmask) \
280 is_xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
282 #define default_enable(mode, bitmask) \
283 xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
285 #define default_disable(mode, bitmask) \
286 xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
288 #define default_inactive(mode, bitmask) \
289 xxx_inactive(mode, bitmask, BNA_RXMODE_DEFAULT)
291 #define is_allmulti_enable(mode, bitmask) \
292 is_xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
294 #define is_allmulti_disable(mode, bitmask) \
295 is_xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
297 #define allmulti_enable(mode, bitmask) \
298 xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
300 #define allmulti_disable(mode, bitmask) \
301 xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
303 #define allmulti_inactive(mode, bitmask) \
304 xxx_inactive(mode, bitmask, BNA_RXMODE_ALLMULTI)
306 #define GET_RXQS(rxp, q0, q1) do { \
307 switch ((rxp)->type) { \
308 case BNA_RXP_SINGLE: \
309 (q0) = rxp->rxq.single.only; \
313 (q0) = rxp->rxq.slr.large; \
314 (q1) = rxp->rxq.slr.small; \
317 (q0) = rxp->rxq.hds.data; \
318 (q1) = rxp->rxq.hds.hdr; \
323 #define bna_tx_rid_mask(_bna) ((_bna)->tx_mod.rid_mask)
325 #define bna_rx_rid_mask(_bna) ((_bna)->rx_mod.rid_mask)
327 #define bna_tx_from_rid(_bna, _rid, _tx) \
329 struct bna_tx_mod *__tx_mod = &(_bna)->tx_mod; \
330 struct bna_tx *__tx; \
331 struct list_head *qe; \
333 list_for_each(qe, &__tx_mod->tx_active_q) { \
334 __tx = (struct bna_tx *)qe; \
335 if (__tx->rid == (_rid)) { \
342 #define bna_rx_from_rid(_bna, _rid, _rx) \
344 struct bna_rx_mod *__rx_mod = &(_bna)->rx_mod; \
345 struct bna_rx *__rx; \
346 struct list_head *qe; \
348 list_for_each(qe, &__rx_mod->rx_active_q) { \
349 __rx = (struct bna_rx *)qe; \
350 if (__rx->rid == (_rid)) { \
357 #define bna_mcam_mod_free_q(_bna) (&(_bna)->mcam_mod.free_q)
359 #define bna_mcam_mod_del_q(_bna) (&(_bna)->mcam_mod.del_q)
361 #define bna_ucam_mod_free_q(_bna) (&(_bna)->ucam_mod.free_q)
363 #define bna_ucam_mod_del_q(_bna) (&(_bna)->ucam_mod.del_q)
365 /* Inline functions */
367 static inline struct bna_mac
*bna_mac_find(struct list_head
*q
, u8
*addr
)
369 struct bna_mac
*mac
= NULL
;
370 struct list_head
*qe
;
371 list_for_each(qe
, q
) {
372 if (BNA_MAC_IS_EQUAL(((struct bna_mac
*)qe
)->addr
, addr
)) {
373 mac
= (struct bna_mac
*)qe
;
380 #define bna_attr(_bna) (&(_bna)->ioceth.attr)
382 /* Function prototypes */
386 /* FW response handlers */
387 void bna_bfi_stats_clr_rsp(struct bna
*bna
, struct bfi_msgq_mhdr
*msghdr
);
390 void bna_res_req(struct bna_res_info
*res_info
);
391 void bna_mod_res_req(struct bna
*bna
, struct bna_res_info
*res_info
);
392 void bna_init(struct bna
*bna
, struct bnad
*bnad
,
393 struct bfa_pcidev
*pcidev
,
394 struct bna_res_info
*res_info
);
395 void bna_mod_init(struct bna
*bna
, struct bna_res_info
*res_info
);
396 void bna_uninit(struct bna
*bna
);
397 int bna_num_txq_set(struct bna
*bna
, int num_txq
);
398 int bna_num_rxp_set(struct bna
*bna
, int num_rxp
);
399 void bna_hw_stats_get(struct bna
*bna
);
402 struct bna_mac
*bna_cam_mod_mac_get(struct list_head
*head
);
403 void bna_cam_mod_mac_put(struct list_head
*tail
, struct bna_mac
*mac
);
404 struct bna_mcam_handle
*bna_mcam_mod_handle_get(struct bna_mcam_mod
*mod
);
405 void bna_mcam_mod_handle_put(struct bna_mcam_mod
*mcam_mod
,
406 struct bna_mcam_handle
*handle
);
411 void bna_mbox_handler(struct bna
*bna
, u32 intr_status
);
415 /* Callbacks for RX */
416 void bna_ethport_cb_rx_started(struct bna_ethport
*ethport
);
417 void bna_ethport_cb_rx_stopped(struct bna_ethport
*ethport
);
419 /* TX MODULE AND TX */
421 /* FW response handelrs */
422 void bna_bfi_tx_enet_start_rsp(struct bna_tx
*tx
,
423 struct bfi_msgq_mhdr
*msghdr
);
424 void bna_bfi_tx_enet_stop_rsp(struct bna_tx
*tx
,
425 struct bfi_msgq_mhdr
*msghdr
);
426 void bna_bfi_bw_update_aen(struct bna_tx_mod
*tx_mod
);
429 void bna_tx_mod_init(struct bna_tx_mod
*tx_mod
, struct bna
*bna
,
430 struct bna_res_info
*res_info
);
431 void bna_tx_mod_uninit(struct bna_tx_mod
*tx_mod
);
434 void bna_tx_mod_start(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
);
435 void bna_tx_mod_stop(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
);
436 void bna_tx_mod_fail(struct bna_tx_mod
*tx_mod
);
439 void bna_tx_res_req(int num_txq
, int txq_depth
,
440 struct bna_res_info
*res_info
);
441 struct bna_tx
*bna_tx_create(struct bna
*bna
, struct bnad
*bnad
,
442 struct bna_tx_config
*tx_cfg
,
443 const struct bna_tx_event_cbfn
*tx_cbfn
,
444 struct bna_res_info
*res_info
, void *priv
);
445 void bna_tx_destroy(struct bna_tx
*tx
);
446 void bna_tx_enable(struct bna_tx
*tx
);
447 void bna_tx_disable(struct bna_tx
*tx
, enum bna_cleanup_type type
,
448 void (*cbfn
)(void *, struct bna_tx
*));
449 void bna_tx_cleanup_complete(struct bna_tx
*tx
);
450 void bna_tx_coalescing_timeo_set(struct bna_tx
*tx
, int coalescing_timeo
);
452 /* RX MODULE, RX, RXF */
454 /* FW response handlers */
455 void bna_bfi_rx_enet_start_rsp(struct bna_rx
*rx
,
456 struct bfi_msgq_mhdr
*msghdr
);
457 void bna_bfi_rx_enet_stop_rsp(struct bna_rx
*rx
,
458 struct bfi_msgq_mhdr
*msghdr
);
459 void bna_bfi_rxf_cfg_rsp(struct bna_rxf
*rxf
, struct bfi_msgq_mhdr
*msghdr
);
460 void bna_bfi_rxf_mcast_add_rsp(struct bna_rxf
*rxf
,
461 struct bfi_msgq_mhdr
*msghdr
);
462 void bna_bfi_rxf_ucast_set_rsp(struct bna_rxf
*rxf
,
463 struct bfi_msgq_mhdr
*msghdr
);
466 void bna_rx_mod_init(struct bna_rx_mod
*rx_mod
, struct bna
*bna
,
467 struct bna_res_info
*res_info
);
468 void bna_rx_mod_uninit(struct bna_rx_mod
*rx_mod
);
471 void bna_rx_mod_start(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
);
472 void bna_rx_mod_stop(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
);
473 void bna_rx_mod_fail(struct bna_rx_mod
*rx_mod
);
476 void bna_rx_res_req(struct bna_rx_config
*rx_config
,
477 struct bna_res_info
*res_info
);
478 struct bna_rx
*bna_rx_create(struct bna
*bna
, struct bnad
*bnad
,
479 struct bna_rx_config
*rx_cfg
,
480 const struct bna_rx_event_cbfn
*rx_cbfn
,
481 struct bna_res_info
*res_info
, void *priv
);
482 void bna_rx_destroy(struct bna_rx
*rx
);
483 void bna_rx_enable(struct bna_rx
*rx
);
484 void bna_rx_disable(struct bna_rx
*rx
, enum bna_cleanup_type type
,
485 void (*cbfn
)(void *, struct bna_rx
*));
486 void bna_rx_cleanup_complete(struct bna_rx
*rx
);
487 void bna_rx_coalescing_timeo_set(struct bna_rx
*rx
, int coalescing_timeo
);
488 void bna_rx_dim_reconfig(struct bna
*bna
, const u32 vector
[][BNA_BIAS_T_MAX
]);
489 void bna_rx_dim_update(struct bna_ccb
*ccb
);
491 bna_rx_ucast_set(struct bna_rx
*rx
, u8
*ucmac
,
492 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
494 bna_rx_ucast_add(struct bna_rx
*rx
, u8
* ucmac
,
495 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
497 bna_rx_ucast_del(struct bna_rx
*rx
, u8
*ucmac
,
498 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
500 bna_rx_ucast_listset(struct bna_rx
*rx
, int count
, u8
*uclist
,
501 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
503 bna_rx_mcast_add(struct bna_rx
*rx
, u8
*mcmac
,
504 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
506 bna_rx_mcast_listset(struct bna_rx
*rx
, int count
, u8
*mcmac
,
507 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
509 bna_rx_mcast_delall(struct bna_rx
*rx
,
510 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
512 bna_rx_mode_set(struct bna_rx
*rx
, enum bna_rxmode rxmode
,
513 enum bna_rxmode bitmask
,
514 void (*cbfn
)(struct bnad
*, struct bna_rx
*));
515 void bna_rx_vlan_add(struct bna_rx
*rx
, int vlan_id
);
516 void bna_rx_vlan_del(struct bna_rx
*rx
, int vlan_id
);
517 void bna_rx_vlanfilter_enable(struct bna_rx
*rx
);
518 void bna_rx_vlan_strip_enable(struct bna_rx
*rx
);
519 void bna_rx_vlan_strip_disable(struct bna_rx
*rx
);
523 int bna_enet_mtu_get(struct bna_enet
*enet
);
525 /* Callbacks for TX, RX */
526 void bna_enet_cb_tx_stopped(struct bna_enet
*enet
);
527 void bna_enet_cb_rx_stopped(struct bna_enet
*enet
);
530 void bna_enet_enable(struct bna_enet
*enet
);
531 void bna_enet_disable(struct bna_enet
*enet
, enum bna_cleanup_type type
,
532 void (*cbfn
)(void *));
533 void bna_enet_pause_config(struct bna_enet
*enet
,
534 struct bna_pause_config
*pause_config
,
535 void (*cbfn
)(struct bnad
*));
536 void bna_enet_mtu_set(struct bna_enet
*enet
, int mtu
,
537 void (*cbfn
)(struct bnad
*));
538 void bna_enet_perm_mac_get(struct bna_enet
*enet
, mac_t
*mac
);
543 void bna_ioceth_enable(struct bna_ioceth
*ioceth
);
544 void bna_ioceth_disable(struct bna_ioceth
*ioceth
,
545 enum bna_cleanup_type type
);
549 /* Callbacks for ENET */
550 void bnad_cb_ethport_link_status(struct bnad
*bnad
,
551 enum bna_link_status status
);
553 /* Callbacks for IOCETH */
554 void bnad_cb_ioceth_ready(struct bnad
*bnad
);
555 void bnad_cb_ioceth_failed(struct bnad
*bnad
);
556 void bnad_cb_ioceth_disabled(struct bnad
*bnad
);
557 void bnad_cb_mbox_intr_enable(struct bnad
*bnad
);
558 void bnad_cb_mbox_intr_disable(struct bnad
*bnad
);
560 /* Callbacks for BNA */
561 void bnad_cb_stats_get(struct bnad
*bnad
, enum bna_cb_status status
,
562 struct bna_stats
*stats
);
564 #endif /* __BNA_H__ */