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
25 #include "bna_types.h"
27 extern const u32 bna_napi_dim_vector[][BNA_BIAS_T_MAX];
29 /* Macros and constants */
31 #define BNA_IOC_TIMER_FREQ 200
34 #define BNA_MESSAGE_SIZE 256
36 #define bna_is_small_rxq(_id) ((_id) & 0x1)
38 #define BNA_MAC_IS_EQUAL(_mac1, _mac2) \
39 (!memcmp((_mac1), (_mac2), sizeof(mac_t)))
41 #define BNA_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
43 #define BNA_TO_POWER_OF_2(x) \
46 while ((x) && (x) != 1) { \
53 #define BNA_TO_POWER_OF_2_HIGH(x) \
62 * input : _addr-> os dma addr in host endian format,
63 * output : _bna_dma_addr-> pointer to hw dma addr
65 #define BNA_SET_DMA_ADDR(_addr, _bna_dma_addr) \
68 cpu_to_be64((u64)(_addr)); \
69 (_bna_dma_addr)->msb = ((struct bna_dma_addr *)&tmp_addr)->msb; \
70 (_bna_dma_addr)->lsb = ((struct bna_dma_addr *)&tmp_addr)->lsb; \
74 * input : _bna_dma_addr-> pointer to hw dma addr
75 * output : _addr-> os dma addr in host endian format
77 #define BNA_GET_DMA_ADDR(_bna_dma_addr, _addr) \
79 (_addr) = ((((u64)ntohl((_bna_dma_addr)->msb))) << 32) \
80 | ((ntohl((_bna_dma_addr)->lsb) & 0xffffffff)); \
83 #define containing_rec(addr, type, field) \
84 ((type *)((unsigned char *)(addr) - \
85 (unsigned char *)(&((type *)0)->field)))
87 #define BNA_TXQ_WI_NEEDED(_vectors) (((_vectors) + 3) >> 2)
89 /* TxQ element is 64 bytes */
90 #define BNA_TXQ_PAGE_INDEX_MAX (PAGE_SIZE >> 6)
91 #define BNA_TXQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 6)
93 #define BNA_TXQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
95 unsigned int page_index; /* index within a page */ \
97 page_index = (_qe_idx) & (BNA_TXQ_PAGE_INDEX_MAX - 1); \
98 (_qe_ptr_range) = (BNA_TXQ_PAGE_INDEX_MAX - page_index); \
99 page_addr = (_qpt_ptr)[((_qe_idx) >> BNA_TXQ_PAGE_INDEX_MAX_SHIFT)];\
100 (_qe_ptr) = &((struct bna_txq_entry *)(page_addr))[page_index]; \
103 /* RxQ element is 8 bytes */
104 #define BNA_RXQ_PAGE_INDEX_MAX (PAGE_SIZE >> 3)
105 #define BNA_RXQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 3)
107 #define BNA_RXQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
109 unsigned int page_index; /* index within a page */ \
111 page_index = (_qe_idx) & (BNA_RXQ_PAGE_INDEX_MAX - 1); \
112 (_qe_ptr_range) = (BNA_RXQ_PAGE_INDEX_MAX - page_index); \
113 page_addr = (_qpt_ptr)[((_qe_idx) >> \
114 BNA_RXQ_PAGE_INDEX_MAX_SHIFT)]; \
115 (_qe_ptr) = &((struct bna_rxq_entry *)(page_addr))[page_index]; \
118 /* CQ element is 16 bytes */
119 #define BNA_CQ_PAGE_INDEX_MAX (PAGE_SIZE >> 4)
120 #define BNA_CQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 4)
122 #define BNA_CQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
124 unsigned int page_index; /* index within a page */ \
127 page_index = (_qe_idx) & (BNA_CQ_PAGE_INDEX_MAX - 1); \
128 (_qe_ptr_range) = (BNA_CQ_PAGE_INDEX_MAX - page_index); \
129 page_addr = (_qpt_ptr)[((_qe_idx) >> \
130 BNA_CQ_PAGE_INDEX_MAX_SHIFT)]; \
131 (_qe_ptr) = &((struct bna_cq_entry *)(page_addr))[page_index];\
134 #define BNA_QE_INDX_2_PTR(_cast, _qe_idx, _q_base) \
135 (&((_cast *)(_q_base))[(_qe_idx)])
137 #define BNA_QE_INDX_RANGE(_qe_idx, _q_depth) ((_q_depth) - (_qe_idx))
139 #define BNA_QE_INDX_ADD(_qe_idx, _qe_num, _q_depth) \
140 ((_qe_idx) = ((_qe_idx) + (_qe_num)) & ((_q_depth) - 1))
142 #define BNA_QE_INDX_INC(_idx, _q_depth) BNA_QE_INDX_ADD(_idx, 1, _q_depth)
144 #define BNA_Q_INDEX_CHANGE(_old_idx, _updated_idx, _q_depth) \
145 (((_updated_idx) - (_old_idx)) & ((_q_depth) - 1))
147 #define BNA_QE_FREE_CNT(_q_ptr, _q_depth) \
148 (((_q_ptr)->consumer_index - (_q_ptr)->producer_index - 1) & \
151 #define BNA_QE_IN_USE_CNT(_q_ptr, _q_depth) \
152 ((((_q_ptr)->producer_index - (_q_ptr)->consumer_index)) & \
155 #define BNA_Q_GET_CI(_q_ptr) ((_q_ptr)->q.consumer_index)
157 #define BNA_Q_GET_PI(_q_ptr) ((_q_ptr)->q.producer_index)
159 #define BNA_Q_PI_ADD(_q_ptr, _num) \
160 (_q_ptr)->q.producer_index = \
161 (((_q_ptr)->q.producer_index + (_num)) & \
162 ((_q_ptr)->q.q_depth - 1))
164 #define BNA_Q_CI_ADD(_q_ptr, _num) \
165 (_q_ptr)->q.consumer_index = \
166 (((_q_ptr)->q.consumer_index + (_num)) \
167 & ((_q_ptr)->q.q_depth - 1))
169 #define BNA_Q_FREE_COUNT(_q_ptr) \
170 (BNA_QE_FREE_CNT(&((_q_ptr)->q), (_q_ptr)->q.q_depth))
172 #define BNA_Q_IN_USE_COUNT(_q_ptr) \
173 (BNA_QE_IN_USE_CNT(&(_q_ptr)->q, (_q_ptr)->q.q_depth))
175 #define BNA_LARGE_PKT_SIZE 1000
177 #define BNA_UPDATE_PKT_CNT(_pkt, _len) \
179 if ((_len) > BNA_LARGE_PKT_SIZE) { \
180 (_pkt)->large_pkt_cnt++; \
182 (_pkt)->small_pkt_cnt++; \
186 #define call_rxf_stop_cbfn(rxf) \
188 if ((rxf)->stop_cbfn) { \
189 void (*cbfn)(struct bna_rx *); \
190 struct bna_rx *cbarg; \
191 cbfn = (rxf)->stop_cbfn; \
192 cbarg = (rxf)->stop_cbarg; \
193 (rxf)->stop_cbfn = NULL; \
194 (rxf)->stop_cbarg = NULL; \
199 #define call_rxf_start_cbfn(rxf) \
201 if ((rxf)->start_cbfn) { \
202 void (*cbfn)(struct bna_rx *); \
203 struct bna_rx *cbarg; \
204 cbfn = (rxf)->start_cbfn; \
205 cbarg = (rxf)->start_cbarg; \
206 (rxf)->start_cbfn = NULL; \
207 (rxf)->start_cbarg = NULL; \
212 #define call_rxf_cam_fltr_cbfn(rxf) \
214 if ((rxf)->cam_fltr_cbfn) { \
215 void (*cbfn)(struct bnad *, struct bna_rx *); \
216 struct bnad *cbarg; \
217 cbfn = (rxf)->cam_fltr_cbfn; \
218 cbarg = (rxf)->cam_fltr_cbarg; \
219 (rxf)->cam_fltr_cbfn = NULL; \
220 (rxf)->cam_fltr_cbarg = NULL; \
221 cbfn(cbarg, rxf->rx); \
225 #define call_rxf_pause_cbfn(rxf) \
227 if ((rxf)->oper_state_cbfn) { \
228 void (*cbfn)(struct bnad *, struct bna_rx *); \
229 struct bnad *cbarg; \
230 cbfn = (rxf)->oper_state_cbfn; \
231 cbarg = (rxf)->oper_state_cbarg; \
232 (rxf)->oper_state_cbfn = NULL; \
233 (rxf)->oper_state_cbarg = NULL; \
234 cbfn(cbarg, rxf->rx); \
238 #define call_rxf_resume_cbfn(rxf) call_rxf_pause_cbfn(rxf)
240 #define is_xxx_enable(mode, bitmask, xxx) ((bitmask & xxx) && (mode & xxx))
242 #define is_xxx_disable(mode, bitmask, xxx) ((bitmask & xxx) && !(mode & xxx))
244 #define xxx_enable(mode, bitmask, xxx) \
250 #define xxx_disable(mode, bitmask, xxx) \
256 #define xxx_inactive(mode, bitmask, xxx) \
262 #define is_promisc_enable(mode, bitmask) \
263 is_xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
265 #define is_promisc_disable(mode, bitmask) \
266 is_xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
268 #define promisc_enable(mode, bitmask) \
269 xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
271 #define promisc_disable(mode, bitmask) \
272 xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
274 #define promisc_inactive(mode, bitmask) \
275 xxx_inactive(mode, bitmask, BNA_RXMODE_PROMISC)
277 #define is_default_enable(mode, bitmask) \
278 is_xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
280 #define is_default_disable(mode, bitmask) \
281 is_xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
283 #define default_enable(mode, bitmask) \
284 xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
286 #define default_disable(mode, bitmask) \
287 xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
289 #define default_inactive(mode, bitmask) \
290 xxx_inactive(mode, bitmask, BNA_RXMODE_DEFAULT)
292 #define is_allmulti_enable(mode, bitmask) \
293 is_xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
295 #define is_allmulti_disable(mode, bitmask) \
296 is_xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
298 #define allmulti_enable(mode, bitmask) \
299 xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
301 #define allmulti_disable(mode, bitmask) \
302 xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
304 #define allmulti_inactive(mode, bitmask) \
305 xxx_inactive(mode, bitmask, BNA_RXMODE_ALLMULTI)
307 #define GET_RXQS(rxp, q0, q1) do { \
308 switch ((rxp)->type) { \
309 case BNA_RXP_SINGLE: \
310 (q0) = rxp->rxq.single.only; \
314 (q0) = rxp->rxq.slr.large; \
315 (q1) = rxp->rxq.slr.small; \
318 (q0) = rxp->rxq.hds.data; \
319 (q1) = rxp->rxq.hds.hdr; \
324 #define bna_tx_rid_mask(_bna) ((_bna)->tx_mod.rid_mask)
326 #define bna_rx_rid_mask(_bna) ((_bna)->rx_mod.rid_mask)
328 #define bna_tx_from_rid(_bna, _rid, _tx) \
330 struct bna_tx_mod *__tx_mod = &(_bna)->tx_mod; \
331 struct bna_tx *__tx; \
332 struct list_head *qe; \
334 list_for_each(qe, &__tx_mod->tx_active_q) { \
335 __tx = (struct bna_tx *)qe; \
336 if (__tx->rid == (_rid)) { \
343 #define bna_rx_from_rid(_bna, _rid, _rx) \
345 struct bna_rx_mod *__rx_mod = &(_bna)->rx_mod; \
346 struct bna_rx *__rx; \
347 struct list_head *qe; \
349 list_for_each(qe, &__rx_mod->rx_active_q) { \
350 __rx = (struct bna_rx *)qe; \
351 if (__rx->rid == (_rid)) { \
358 #define bna_mcam_mod_free_q(_bna) (&(_bna)->mcam_mod.free_q)
360 #define bna_mcam_mod_del_q(_bna) (&(_bna)->mcam_mod.del_q)
362 #define bna_ucam_mod_free_q(_bna) (&(_bna)->ucam_mod.free_q)
364 #define bna_ucam_mod_del_q(_bna) (&(_bna)->ucam_mod.del_q)
366 /* Inline functions */
368 static inline struct bna_mac *bna_mac_find(struct list_head *q, u8 *addr)
370 struct bna_mac *mac = NULL;
371 struct list_head *qe;
372 list_for_each(qe, q) {
373 if (BNA_MAC_IS_EQUAL(((struct bna_mac *)qe)->addr, addr)) {
374 mac = (struct bna_mac *)qe;
381 #define bna_attr(_bna) (&(_bna)->ioceth.attr)
383 /* Function prototypes */
387 /* FW response handlers */
388 void bna_bfi_stats_clr_rsp(struct bna *bna, struct bfi_msgq_mhdr *msghdr);
391 void bna_res_req(struct bna_res_info *res_info);
392 void bna_mod_res_req(struct bna *bna, struct bna_res_info *res_info);
393 void bna_init(struct bna *bna, struct bnad *bnad,
394 struct bfa_pcidev *pcidev,
395 struct bna_res_info *res_info);
396 void bna_mod_init(struct bna *bna, struct bna_res_info *res_info);
397 void bna_uninit(struct bna *bna);
398 int bna_num_txq_set(struct bna *bna, int num_txq);
399 int bna_num_rxp_set(struct bna *bna, int num_rxp);
400 void bna_hw_stats_get(struct bna *bna);
403 struct bna_mac *bna_cam_mod_mac_get(struct list_head *head);
404 void bna_cam_mod_mac_put(struct list_head *tail, struct bna_mac *mac);
405 struct bna_mcam_handle *bna_mcam_mod_handle_get(struct bna_mcam_mod *mod);
406 void bna_mcam_mod_handle_put(struct bna_mcam_mod *mcam_mod,
407 struct bna_mcam_handle *handle);
412 void bna_mbox_handler(struct bna *bna, u32 intr_status);
416 /* Callbacks for RX */
417 void bna_ethport_cb_rx_started(struct bna_ethport *ethport);
418 void bna_ethport_cb_rx_stopped(struct bna_ethport *ethport);
420 /* TX MODULE AND TX */
422 /* FW response handelrs */
423 void bna_bfi_tx_enet_start_rsp(struct bna_tx *tx,
424 struct bfi_msgq_mhdr *msghdr);
425 void bna_bfi_tx_enet_stop_rsp(struct bna_tx *tx,
426 struct bfi_msgq_mhdr *msghdr);
427 void bna_bfi_bw_update_aen(struct bna_tx_mod *tx_mod);
430 void bna_tx_mod_init(struct bna_tx_mod *tx_mod, struct bna *bna,
431 struct bna_res_info *res_info);
432 void bna_tx_mod_uninit(struct bna_tx_mod *tx_mod);
435 void bna_tx_mod_start(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
436 void bna_tx_mod_stop(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
437 void bna_tx_mod_fail(struct bna_tx_mod *tx_mod);
440 void bna_tx_res_req(int num_txq, int txq_depth,
441 struct bna_res_info *res_info);
442 struct bna_tx *bna_tx_create(struct bna *bna, struct bnad *bnad,
443 struct bna_tx_config *tx_cfg,
444 const struct bna_tx_event_cbfn *tx_cbfn,
445 struct bna_res_info *res_info, void *priv);
446 void bna_tx_destroy(struct bna_tx *tx);
447 void bna_tx_enable(struct bna_tx *tx);
448 void bna_tx_disable(struct bna_tx *tx, enum bna_cleanup_type type,
449 void (*cbfn)(void *, struct bna_tx *));
450 void bna_tx_cleanup_complete(struct bna_tx *tx);
451 void bna_tx_coalescing_timeo_set(struct bna_tx *tx, int coalescing_timeo);
453 /* RX MODULE, RX, RXF */
455 /* FW response handlers */
456 void bna_bfi_rx_enet_start_rsp(struct bna_rx *rx,
457 struct bfi_msgq_mhdr *msghdr);
458 void bna_bfi_rx_enet_stop_rsp(struct bna_rx *rx,
459 struct bfi_msgq_mhdr *msghdr);
460 void bna_bfi_rxf_cfg_rsp(struct bna_rxf *rxf, struct bfi_msgq_mhdr *msghdr);
461 void bna_bfi_rxf_mcast_add_rsp(struct bna_rxf *rxf,
462 struct bfi_msgq_mhdr *msghdr);
463 void bna_bfi_rxf_ucast_set_rsp(struct bna_rxf *rxf,
464 struct bfi_msgq_mhdr *msghdr);
467 void bna_rx_mod_init(struct bna_rx_mod *rx_mod, struct bna *bna,
468 struct bna_res_info *res_info);
469 void bna_rx_mod_uninit(struct bna_rx_mod *rx_mod);
472 void bna_rx_mod_start(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
473 void bna_rx_mod_stop(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
474 void bna_rx_mod_fail(struct bna_rx_mod *rx_mod);
477 void bna_rx_res_req(struct bna_rx_config *rx_config,
478 struct bna_res_info *res_info);
479 struct bna_rx *bna_rx_create(struct bna *bna, struct bnad *bnad,
480 struct bna_rx_config *rx_cfg,
481 const struct bna_rx_event_cbfn *rx_cbfn,
482 struct bna_res_info *res_info, void *priv);
483 void bna_rx_destroy(struct bna_rx *rx);
484 void bna_rx_enable(struct bna_rx *rx);
485 void bna_rx_disable(struct bna_rx *rx, enum bna_cleanup_type type,
486 void (*cbfn)(void *, struct bna_rx *));
487 void bna_rx_cleanup_complete(struct bna_rx *rx);
488 void bna_rx_coalescing_timeo_set(struct bna_rx *rx, int coalescing_timeo);
489 void bna_rx_dim_reconfig(struct bna *bna, const u32 vector[][BNA_BIAS_T_MAX]);
490 void bna_rx_dim_update(struct bna_ccb *ccb);
492 bna_rx_ucast_set(struct bna_rx *rx, u8 *ucmac,
493 void (*cbfn)(struct bnad *, struct bna_rx *));
495 bna_rx_ucast_add(struct bna_rx *rx, u8* ucmac,
496 void (*cbfn)(struct bnad *, struct bna_rx *));
498 bna_rx_ucast_del(struct bna_rx *rx, u8 *ucmac,
499 void (*cbfn)(struct bnad *, struct bna_rx *));
501 bna_rx_ucast_listset(struct bna_rx *rx, int count, u8 *uclist,
502 void (*cbfn)(struct bnad *, struct bna_rx *));
504 bna_rx_mcast_add(struct bna_rx *rx, u8 *mcmac,
505 void (*cbfn)(struct bnad *, struct bna_rx *));
507 bna_rx_mcast_listset(struct bna_rx *rx, int count, u8 *mcmac,
508 void (*cbfn)(struct bnad *, struct bna_rx *));
510 bna_rx_mcast_delall(struct bna_rx *rx,
511 void (*cbfn)(struct bnad *, struct bna_rx *));
513 bna_rx_mode_set(struct bna_rx *rx, enum bna_rxmode rxmode,
514 enum bna_rxmode bitmask,
515 void (*cbfn)(struct bnad *, struct bna_rx *));
516 void bna_rx_vlan_add(struct bna_rx *rx, int vlan_id);
517 void bna_rx_vlan_del(struct bna_rx *rx, int vlan_id);
518 void bna_rx_vlanfilter_enable(struct bna_rx *rx);
519 void bna_rx_vlan_strip_enable(struct bna_rx *rx);
520 void bna_rx_vlan_strip_disable(struct bna_rx *rx);
524 int bna_enet_mtu_get(struct bna_enet *enet);
526 /* Callbacks for TX, RX */
527 void bna_enet_cb_tx_stopped(struct bna_enet *enet);
528 void bna_enet_cb_rx_stopped(struct bna_enet *enet);
531 void bna_enet_enable(struct bna_enet *enet);
532 void bna_enet_disable(struct bna_enet *enet, enum bna_cleanup_type type,
533 void (*cbfn)(void *));
534 void bna_enet_pause_config(struct bna_enet *enet,
535 struct bna_pause_config *pause_config,
536 void (*cbfn)(struct bnad *));
537 void bna_enet_mtu_set(struct bna_enet *enet, int mtu,
538 void (*cbfn)(struct bnad *));
539 void bna_enet_perm_mac_get(struct bna_enet *enet, mac_t *mac);
544 void bna_ioceth_enable(struct bna_ioceth *ioceth);
545 void bna_ioceth_disable(struct bna_ioceth *ioceth,
546 enum bna_cleanup_type type);
550 /* Callbacks for ENET */
551 void bnad_cb_ethport_link_status(struct bnad *bnad,
552 enum bna_link_status status);
554 /* Callbacks for IOCETH */
555 void bnad_cb_ioceth_ready(struct bnad *bnad);
556 void bnad_cb_ioceth_failed(struct bnad *bnad);
557 void bnad_cb_ioceth_disabled(struct bnad *bnad);
558 void bnad_cb_mbox_intr_enable(struct bnad *bnad);
559 void bnad_cb_mbox_intr_disable(struct bnad *bnad);
561 /* Callbacks for BNA */
562 void bnad_cb_stats_get(struct bnad *bnad, enum bna_cb_status status,
563 struct bna_stats *stats);
565 #endif /* __BNA_H__ */