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.
20 #include "bna_types.h"
22 extern const u32 bna_napi_dim_vector[][BNA_BIAS_T_MAX];
26 * Macros and constants
30 #define BNA_IOC_TIMER_FREQ 200
33 #define BNA_MESSAGE_SIZE 256
35 #define bna_device_timer(_dev) bfa_timer_beat(&((_dev)->timer_mod))
37 /* MBOX API for PORT, TX, RX */
38 #define bna_mbox_qe_fill(_qe, _cmd, _cmd_len, _cbfn, _cbarg) \
40 memcpy(&((_qe)->cmd.msg[0]), (_cmd), (_cmd_len)); \
41 (_qe)->cbfn = (_cbfn); \
42 (_qe)->cbarg = (_cbarg); \
45 #define bna_is_small_rxq(rcb) ((rcb)->id == 1)
47 #define BNA_MAC_IS_EQUAL(_mac1, _mac2) \
48 (!memcmp((_mac1), (_mac2), sizeof(mac_t)))
50 #define BNA_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
52 #define BNA_TO_POWER_OF_2(x) \
55 while ((x) && (x) != 1) { \
62 #define BNA_TO_POWER_OF_2_HIGH(x) \
71 * input : _addr-> os dma addr in host endian format,
72 * output : _bna_dma_addr-> pointer to hw dma addr
74 #define BNA_SET_DMA_ADDR(_addr, _bna_dma_addr) \
77 cpu_to_be64((u64)(_addr)); \
78 (_bna_dma_addr)->msb = ((struct bna_dma_addr *)&tmp_addr)->msb; \
79 (_bna_dma_addr)->lsb = ((struct bna_dma_addr *)&tmp_addr)->lsb; \
83 * input : _bna_dma_addr-> pointer to hw dma addr
84 * output : _addr-> os dma addr in host endian format
86 #define BNA_GET_DMA_ADDR(_bna_dma_addr, _addr) \
88 (_addr) = ((((u64)ntohl((_bna_dma_addr)->msb))) << 32) \
89 | ((ntohl((_bna_dma_addr)->lsb) & 0xffffffff)); \
92 #define containing_rec(addr, type, field) \
93 ((type *)((unsigned char *)(addr) - \
94 (unsigned char *)(&((type *)0)->field)))
96 #define BNA_TXQ_WI_NEEDED(_vectors) (((_vectors) + 3) >> 2)
98 /* TxQ element is 64 bytes */
99 #define BNA_TXQ_PAGE_INDEX_MAX (PAGE_SIZE >> 6)
100 #define BNA_TXQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 6)
102 #define BNA_TXQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
104 unsigned int page_index; /* index within a page */ \
106 page_index = (_qe_idx) & (BNA_TXQ_PAGE_INDEX_MAX - 1); \
107 (_qe_ptr_range) = (BNA_TXQ_PAGE_INDEX_MAX - page_index); \
108 page_addr = (_qpt_ptr)[((_qe_idx) >> BNA_TXQ_PAGE_INDEX_MAX_SHIFT)];\
109 (_qe_ptr) = &((struct bna_txq_entry *)(page_addr))[page_index]; \
112 /* RxQ element is 8 bytes */
113 #define BNA_RXQ_PAGE_INDEX_MAX (PAGE_SIZE >> 3)
114 #define BNA_RXQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 3)
116 #define BNA_RXQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
118 unsigned int page_index; /* index within a page */ \
120 page_index = (_qe_idx) & (BNA_RXQ_PAGE_INDEX_MAX - 1); \
121 (_qe_ptr_range) = (BNA_RXQ_PAGE_INDEX_MAX - page_index); \
122 page_addr = (_qpt_ptr)[((_qe_idx) >> \
123 BNA_RXQ_PAGE_INDEX_MAX_SHIFT)]; \
124 (_qe_ptr) = &((struct bna_rxq_entry *)(page_addr))[page_index]; \
127 /* CQ element is 16 bytes */
128 #define BNA_CQ_PAGE_INDEX_MAX (PAGE_SIZE >> 4)
129 #define BNA_CQ_PAGE_INDEX_MAX_SHIFT (PAGE_SHIFT - 4)
131 #define BNA_CQ_QPGE_PTR_GET(_qe_idx, _qpt_ptr, _qe_ptr, _qe_ptr_range) \
133 unsigned int page_index; /* index within a page */ \
136 page_index = (_qe_idx) & (BNA_CQ_PAGE_INDEX_MAX - 1); \
137 (_qe_ptr_range) = (BNA_CQ_PAGE_INDEX_MAX - page_index); \
138 page_addr = (_qpt_ptr)[((_qe_idx) >> \
139 BNA_CQ_PAGE_INDEX_MAX_SHIFT)]; \
140 (_qe_ptr) = &((struct bna_cq_entry *)(page_addr))[page_index];\
143 #define BNA_QE_INDX_2_PTR(_cast, _qe_idx, _q_base) \
144 (&((_cast *)(_q_base))[(_qe_idx)])
146 #define BNA_QE_INDX_RANGE(_qe_idx, _q_depth) ((_q_depth) - (_qe_idx))
148 #define BNA_QE_INDX_ADD(_qe_idx, _qe_num, _q_depth) \
149 ((_qe_idx) = ((_qe_idx) + (_qe_num)) & ((_q_depth) - 1))
151 #define BNA_Q_INDEX_CHANGE(_old_idx, _updated_idx, _q_depth) \
152 (((_updated_idx) - (_old_idx)) & ((_q_depth) - 1))
154 #define BNA_QE_FREE_CNT(_q_ptr, _q_depth) \
155 (((_q_ptr)->consumer_index - (_q_ptr)->producer_index - 1) & \
158 #define BNA_QE_IN_USE_CNT(_q_ptr, _q_depth) \
159 ((((_q_ptr)->producer_index - (_q_ptr)->consumer_index)) & \
162 #define BNA_Q_GET_CI(_q_ptr) ((_q_ptr)->q.consumer_index)
164 #define BNA_Q_GET_PI(_q_ptr) ((_q_ptr)->q.producer_index)
166 #define BNA_Q_PI_ADD(_q_ptr, _num) \
167 (_q_ptr)->q.producer_index = \
168 (((_q_ptr)->q.producer_index + (_num)) & \
169 ((_q_ptr)->q.q_depth - 1))
171 #define BNA_Q_CI_ADD(_q_ptr, _num) \
172 (_q_ptr)->q.consumer_index = \
173 (((_q_ptr)->q.consumer_index + (_num)) \
174 & ((_q_ptr)->q.q_depth - 1))
176 #define BNA_Q_FREE_COUNT(_q_ptr) \
177 (BNA_QE_FREE_CNT(&((_q_ptr)->q), (_q_ptr)->q.q_depth))
179 #define BNA_Q_IN_USE_COUNT(_q_ptr) \
180 (BNA_QE_IN_USE_CNT(&(_q_ptr)->q, (_q_ptr)->q.q_depth))
182 /* These macros build the data portion of the TxQ/RxQ doorbell */
183 #define BNA_DOORBELL_Q_PRD_IDX(_pi) (0x80000000 | (_pi))
184 #define BNA_DOORBELL_Q_STOP (0x40000000)
186 /* These macros build the data portion of the IB doorbell */
187 #define BNA_DOORBELL_IB_INT_ACK(_timeout, _events) \
188 (0x80000000 | ((_timeout) << 16) | (_events))
189 #define BNA_DOORBELL_IB_INT_DISABLE (0x40000000)
191 /* Set the coalescing timer for the given ib */
192 #define bna_ib_coalescing_timer_set(_i_dbell, _cls_timer) \
193 ((_i_dbell)->doorbell_ack = BNA_DOORBELL_IB_INT_ACK((_cls_timer), 0));
195 /* Acks 'events' # of events for a given ib */
196 #define bna_ib_ack(_i_dbell, _events) \
197 (writel(((_i_dbell)->doorbell_ack | (_events)), \
198 (_i_dbell)->doorbell_addr));
200 #define bna_txq_prod_indx_doorbell(_tcb) \
201 (writel(BNA_DOORBELL_Q_PRD_IDX((_tcb)->producer_index), \
204 #define bna_rxq_prod_indx_doorbell(_rcb) \
205 (writel(BNA_DOORBELL_Q_PRD_IDX((_rcb)->producer_index), \
208 #define BNA_LARGE_PKT_SIZE 1000
210 #define BNA_UPDATE_PKT_CNT(_pkt, _len) \
212 if ((_len) > BNA_LARGE_PKT_SIZE) { \
213 (_pkt)->large_pkt_cnt++; \
215 (_pkt)->small_pkt_cnt++; \
219 #define call_rxf_stop_cbfn(rxf, status) \
220 if ((rxf)->stop_cbfn) { \
221 (*(rxf)->stop_cbfn)((rxf)->stop_cbarg, (status)); \
222 (rxf)->stop_cbfn = NULL; \
223 (rxf)->stop_cbarg = NULL; \
226 #define call_rxf_start_cbfn(rxf, status) \
227 if ((rxf)->start_cbfn) { \
228 (*(rxf)->start_cbfn)((rxf)->start_cbarg, (status)); \
229 (rxf)->start_cbfn = NULL; \
230 (rxf)->start_cbarg = NULL; \
233 #define call_rxf_cam_fltr_cbfn(rxf, status) \
234 if ((rxf)->cam_fltr_cbfn) { \
235 (*(rxf)->cam_fltr_cbfn)((rxf)->cam_fltr_cbarg, rxf->rx, \
237 (rxf)->cam_fltr_cbfn = NULL; \
238 (rxf)->cam_fltr_cbarg = NULL; \
241 #define call_rxf_pause_cbfn(rxf, status) \
242 if ((rxf)->oper_state_cbfn) { \
243 (*(rxf)->oper_state_cbfn)((rxf)->oper_state_cbarg, rxf->rx,\
245 (rxf)->rxf_flags &= ~BNA_RXF_FL_OPERSTATE_CHANGED; \
246 (rxf)->oper_state_cbfn = NULL; \
247 (rxf)->oper_state_cbarg = NULL; \
250 #define call_rxf_resume_cbfn(rxf, status) call_rxf_pause_cbfn(rxf, status)
252 #define is_xxx_enable(mode, bitmask, xxx) ((bitmask & xxx) && (mode & xxx))
254 #define is_xxx_disable(mode, bitmask, xxx) ((bitmask & xxx) && !(mode & xxx))
256 #define xxx_enable(mode, bitmask, xxx) \
262 #define xxx_disable(mode, bitmask, xxx) \
268 #define xxx_inactive(mode, bitmask, xxx) \
274 #define is_promisc_enable(mode, bitmask) \
275 is_xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
277 #define is_promisc_disable(mode, bitmask) \
278 is_xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
280 #define promisc_enable(mode, bitmask) \
281 xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
283 #define promisc_disable(mode, bitmask) \
284 xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
286 #define promisc_inactive(mode, bitmask) \
287 xxx_inactive(mode, bitmask, BNA_RXMODE_PROMISC)
289 #define is_default_enable(mode, bitmask) \
290 is_xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
292 #define is_default_disable(mode, bitmask) \
293 is_xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
295 #define default_enable(mode, bitmask) \
296 xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
298 #define default_disable(mode, bitmask) \
299 xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
301 #define default_inactive(mode, bitmask) \
302 xxx_inactive(mode, bitmask, BNA_RXMODE_DEFAULT)
304 #define is_allmulti_enable(mode, bitmask) \
305 is_xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
307 #define is_allmulti_disable(mode, bitmask) \
308 is_xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
310 #define allmulti_enable(mode, bitmask) \
311 xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
313 #define allmulti_disable(mode, bitmask) \
314 xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
316 #define allmulti_inactive(mode, bitmask) \
317 xxx_inactive(mode, bitmask, BNA_RXMODE_ALLMULTI)
319 #define GET_RXQS(rxp, q0, q1) do { \
320 switch ((rxp)->type) { \
321 case BNA_RXP_SINGLE: \
322 (q0) = rxp->rxq.single.only; \
326 (q0) = rxp->rxq.slr.large; \
327 (q1) = rxp->rxq.slr.small; \
330 (q0) = rxp->rxq.hds.data; \
331 (q1) = rxp->rxq.hds.hdr; \
338 * Function prototypes
347 void bna_res_req(struct bna_res_info *res_info);
348 void bna_init(struct bna *bna, struct bnad *bnad,
349 struct bfa_pcidev *pcidev,
350 struct bna_res_info *res_info);
351 void bna_uninit(struct bna *bna);
352 void bna_stats_get(struct bna *bna);
353 void bna_get_perm_mac(struct bna *bna, u8 *mac);
356 int bna_rit_mod_can_satisfy(struct bna_rit_mod *rit_mod, int seg_size);
359 struct bna_mac *bna_ucam_mod_mac_get(struct bna_ucam_mod *ucam_mod);
360 void bna_ucam_mod_mac_put(struct bna_ucam_mod *ucam_mod,
361 struct bna_mac *mac);
362 struct bna_mac *bna_mcam_mod_mac_get(struct bna_mcam_mod *mcam_mod);
363 void bna_mcam_mod_mac_put(struct bna_mcam_mod *mcam_mod,
364 struct bna_mac *mac);
365 struct bna_rit_segment *
366 bna_rit_mod_seg_get(struct bna_rit_mod *rit_mod, int seg_size);
367 void bna_rit_mod_seg_put(struct bna_rit_mod *rit_mod,
368 struct bna_rit_segment *seg);
375 void bna_device_enable(struct bna_device *device);
376 void bna_device_disable(struct bna_device *device,
377 enum bna_cleanup_type type);
383 /* APIs for PORT, TX, RX */
384 void bna_mbox_handler(struct bna *bna, u32 intr_status);
385 void bna_mbox_send(struct bna *bna, struct bna_mbox_qe *mbox_qe);
392 int bna_port_mtu_get(struct bna_port *port);
393 void bna_llport_admin_up(struct bna_llport *llport);
394 void bna_llport_admin_down(struct bna_llport *llport);
397 void bna_port_enable(struct bna_port *port);
398 void bna_port_disable(struct bna_port *port, enum bna_cleanup_type type,
399 void (*cbfn)(void *, enum bna_cb_status));
400 void bna_port_pause_config(struct bna_port *port,
401 struct bna_pause_config *pause_config,
402 void (*cbfn)(struct bnad *, enum bna_cb_status));
403 void bna_port_mtu_set(struct bna_port *port, int mtu,
404 void (*cbfn)(struct bnad *, enum bna_cb_status));
405 void bna_port_mac_get(struct bna_port *port, mac_t *mac);
407 /* Callbacks for TX, RX */
408 void bna_port_cb_tx_stopped(struct bna_port *port,
409 enum bna_cb_status status);
410 void bna_port_cb_rx_stopped(struct bna_port *port,
411 enum bna_cb_status status);
418 void bna_ib_mod_init(struct bna_ib_mod *ib_mod, struct bna *bna,
419 struct bna_res_info *res_info);
420 void bna_ib_mod_uninit(struct bna_ib_mod *ib_mod);
427 void bna_tx_mod_init(struct bna_tx_mod *tx_mod, struct bna *bna,
428 struct bna_res_info *res_info);
429 void bna_tx_mod_uninit(struct bna_tx_mod *tx_mod);
430 int bna_tx_state_get(struct bna_tx *tx);
433 void bna_tx_mod_start(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
434 void bna_tx_mod_stop(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
435 void bna_tx_mod_fail(struct bna_tx_mod *tx_mod);
436 void bna_tx_mod_prio_changed(struct bna_tx_mod *tx_mod, int prio);
437 void bna_tx_mod_cee_link_status(struct bna_tx_mod *tx_mod, int cee_link);
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 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 enum bna_cb_status));
451 void bna_tx_coalescing_timeo_set(struct bna_tx *tx, int coalescing_timeo);
458 void rxf_cb_cam_fltr_mbox_cmd(void *arg, int status);
459 void rxf_cam_mbox_cmd(struct bna_rxf *rxf, u8 cmd,
460 const struct bna_mac *mac_addr);
461 void __rxf_vlan_filter_set(struct bna_rxf *rxf, enum bna_status status);
462 void bna_rxf_adv_init(struct bna_rxf *rxf,
464 struct bna_rx_config *q_config);
465 int rxf_process_packet_filter_ucast(struct bna_rxf *rxf);
466 int rxf_process_packet_filter_promisc(struct bna_rxf *rxf);
467 int rxf_process_packet_filter_default(struct bna_rxf *rxf);
468 int rxf_process_packet_filter_allmulti(struct bna_rxf *rxf);
469 int rxf_clear_packet_filter_ucast(struct bna_rxf *rxf);
470 int rxf_clear_packet_filter_promisc(struct bna_rxf *rxf);
471 int rxf_clear_packet_filter_default(struct bna_rxf *rxf);
472 int rxf_clear_packet_filter_allmulti(struct bna_rxf *rxf);
473 void rxf_reset_packet_filter_ucast(struct bna_rxf *rxf);
474 void rxf_reset_packet_filter_promisc(struct bna_rxf *rxf);
475 void rxf_reset_packet_filter_default(struct bna_rxf *rxf);
476 void rxf_reset_packet_filter_allmulti(struct bna_rxf *rxf);
479 void bna_rx_mod_init(struct bna_rx_mod *rx_mod, struct bna *bna,
480 struct bna_res_info *res_info);
481 void bna_rx_mod_uninit(struct bna_rx_mod *rx_mod);
482 int bna_rx_state_get(struct bna_rx *rx);
483 int bna_rxf_state_get(struct bna_rxf *rxf);
486 void bna_rx_mod_start(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
487 void bna_rx_mod_stop(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
488 void bna_rx_mod_fail(struct bna_rx_mod *rx_mod);
491 void bna_rx_res_req(struct bna_rx_config *rx_config,
492 struct bna_res_info *res_info);
493 struct bna_rx *bna_rx_create(struct bna *bna, struct bnad *bnad,
494 struct bna_rx_config *rx_cfg,
495 struct bna_rx_event_cbfn *rx_cbfn,
496 struct bna_res_info *res_info, void *priv);
497 void bna_rx_destroy(struct bna_rx *rx);
498 void bna_rx_enable(struct bna_rx *rx);
499 void bna_rx_disable(struct bna_rx *rx, enum bna_cleanup_type type,
500 void (*cbfn)(void *, struct bna_rx *,
501 enum bna_cb_status));
502 void bna_rx_coalescing_timeo_set(struct bna_rx *rx, int coalescing_timeo);
503 void bna_rx_dim_reconfig(struct bna *bna, const u32 vector[][BNA_BIAS_T_MAX]);
504 void bna_rx_dim_update(struct bna_ccb *ccb);
506 bna_rx_ucast_set(struct bna_rx *rx, u8 *ucmac,
507 void (*cbfn)(struct bnad *, struct bna_rx *,
508 enum bna_cb_status));
510 bna_rx_mcast_add(struct bna_rx *rx, u8 *mcmac,
511 void (*cbfn)(struct bnad *, struct bna_rx *,
512 enum bna_cb_status));
514 bna_rx_mcast_listset(struct bna_rx *rx, int count, u8 *mcmac,
515 void (*cbfn)(struct bnad *, struct bna_rx *,
516 enum bna_cb_status));
518 bna_rx_mode_set(struct bna_rx *rx, enum bna_rxmode rxmode,
519 enum bna_rxmode bitmask,
520 void (*cbfn)(struct bnad *, struct bna_rx *,
521 enum bna_cb_status));
522 void bna_rx_vlan_add(struct bna_rx *rx, int vlan_id);
523 void bna_rx_vlan_del(struct bna_rx *rx, int vlan_id);
524 void bna_rx_vlanfilter_enable(struct bna_rx *rx);
525 void bna_rx_hds_enable(struct bna_rx *rx, struct bna_rxf_hds *hds_config,
526 void (*cbfn)(struct bnad *, struct bna_rx *,
527 enum bna_cb_status));
528 void bna_rx_hds_disable(struct bna_rx *rx,
529 void (*cbfn)(struct bnad *, struct bna_rx *,
530 enum bna_cb_status));
536 /* Callbacks for BNA */
537 void bnad_cb_stats_get(struct bnad *bnad, enum bna_cb_status status,
538 struct bna_stats *stats);
540 /* Callbacks for DEVICE */
541 void bnad_cb_device_enabled(struct bnad *bnad, enum bna_cb_status status);
542 void bnad_cb_device_disabled(struct bnad *bnad, enum bna_cb_status status);
543 void bnad_cb_device_enable_mbox_intr(struct bnad *bnad);
544 void bnad_cb_device_disable_mbox_intr(struct bnad *bnad);
546 /* Callbacks for port */
547 void bnad_cb_port_link_status(struct bnad *bnad,
548 enum bna_link_status status);
550 #endif /* __BNA_H__ */