1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
17 #include "bna_types.h"
19 extern const u32 bna_napi_dim_vector
[][BNA_BIAS_T_MAX
];
21 /* Macros and constants */
23 #define bna_is_small_rxq(_id) ((_id) & 0x1)
26 * input : _addr-> os dma addr in host endian format,
27 * output : _bna_dma_addr-> pointer to hw dma addr
29 #define BNA_SET_DMA_ADDR(_addr, _bna_dma_addr) \
32 cpu_to_be64((u64)(_addr)); \
33 (_bna_dma_addr)->msb = ((struct bna_dma_addr *)&tmp_addr)->msb; \
34 (_bna_dma_addr)->lsb = ((struct bna_dma_addr *)&tmp_addr)->lsb; \
38 * input : _bna_dma_addr-> pointer to hw dma addr
39 * output : _addr-> os dma addr in host endian format
41 #define BNA_GET_DMA_ADDR(_bna_dma_addr, _addr) \
43 (_addr) = ((((u64)ntohl((_bna_dma_addr)->msb))) << 32) \
44 | ((ntohl((_bna_dma_addr)->lsb) & 0xffffffff)); \
47 #define BNA_TXQ_WI_NEEDED(_vectors) (((_vectors) + 3) >> 2)
49 #define BNA_QE_INDX_ADD(_qe_idx, _qe_num, _q_depth) \
50 ((_qe_idx) = ((_qe_idx) + (_qe_num)) & ((_q_depth) - 1))
52 #define BNA_QE_INDX_INC(_idx, _q_depth) BNA_QE_INDX_ADD(_idx, 1, _q_depth)
54 #define BNA_Q_INDEX_CHANGE(_old_idx, _updated_idx, _q_depth) \
55 (((_updated_idx) - (_old_idx)) & ((_q_depth) - 1))
57 #define BNA_QE_FREE_CNT(_q_ptr, _q_depth) \
58 (((_q_ptr)->consumer_index - (_q_ptr)->producer_index - 1) & \
60 #define BNA_QE_IN_USE_CNT(_q_ptr, _q_depth) \
61 ((((_q_ptr)->producer_index - (_q_ptr)->consumer_index)) & \
64 #define BNA_LARGE_PKT_SIZE 1000
66 #define BNA_UPDATE_PKT_CNT(_pkt, _len) \
68 if ((_len) > BNA_LARGE_PKT_SIZE) { \
69 (_pkt)->large_pkt_cnt++; \
71 (_pkt)->small_pkt_cnt++; \
75 #define call_rxf_stop_cbfn(rxf) \
77 if ((rxf)->stop_cbfn) { \
78 void (*cbfn)(struct bna_rx *); \
79 struct bna_rx *cbarg; \
80 cbfn = (rxf)->stop_cbfn; \
81 cbarg = (rxf)->stop_cbarg; \
82 (rxf)->stop_cbfn = NULL; \
83 (rxf)->stop_cbarg = NULL; \
88 #define call_rxf_start_cbfn(rxf) \
90 if ((rxf)->start_cbfn) { \
91 void (*cbfn)(struct bna_rx *); \
92 struct bna_rx *cbarg; \
93 cbfn = (rxf)->start_cbfn; \
94 cbarg = (rxf)->start_cbarg; \
95 (rxf)->start_cbfn = NULL; \
96 (rxf)->start_cbarg = NULL; \
101 #define call_rxf_cam_fltr_cbfn(rxf) \
103 if ((rxf)->cam_fltr_cbfn) { \
104 void (*cbfn)(struct bnad *, struct bna_rx *); \
105 struct bnad *cbarg; \
106 cbfn = (rxf)->cam_fltr_cbfn; \
107 cbarg = (rxf)->cam_fltr_cbarg; \
108 (rxf)->cam_fltr_cbfn = NULL; \
109 (rxf)->cam_fltr_cbarg = NULL; \
110 cbfn(cbarg, rxf->rx); \
114 #define is_xxx_enable(mode, bitmask, xxx) ((bitmask & xxx) && (mode & xxx))
116 #define is_xxx_disable(mode, bitmask, xxx) ((bitmask & xxx) && !(mode & xxx))
118 #define xxx_enable(mode, bitmask, xxx) \
124 #define xxx_disable(mode, bitmask, xxx) \
130 #define xxx_inactive(mode, bitmask, xxx) \
136 #define is_promisc_enable(mode, bitmask) \
137 is_xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
139 #define is_promisc_disable(mode, bitmask) \
140 is_xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
142 #define promisc_enable(mode, bitmask) \
143 xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
145 #define promisc_disable(mode, bitmask) \
146 xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
148 #define promisc_inactive(mode, bitmask) \
149 xxx_inactive(mode, bitmask, BNA_RXMODE_PROMISC)
151 #define is_default_enable(mode, bitmask) \
152 is_xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
154 #define is_default_disable(mode, bitmask) \
155 is_xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
157 #define default_enable(mode, bitmask) \
158 xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
160 #define default_disable(mode, bitmask) \
161 xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
163 #define default_inactive(mode, bitmask) \
164 xxx_inactive(mode, bitmask, BNA_RXMODE_DEFAULT)
166 #define is_allmulti_enable(mode, bitmask) \
167 is_xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
169 #define is_allmulti_disable(mode, bitmask) \
170 is_xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
172 #define allmulti_enable(mode, bitmask) \
173 xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
175 #define allmulti_disable(mode, bitmask) \
176 xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
178 #define allmulti_inactive(mode, bitmask) \
179 xxx_inactive(mode, bitmask, BNA_RXMODE_ALLMULTI)
181 #define GET_RXQS(rxp, q0, q1) do { \
182 switch ((rxp)->type) { \
183 case BNA_RXP_SINGLE: \
184 (q0) = rxp->rxq.single.only; \
188 (q0) = rxp->rxq.slr.large; \
189 (q1) = rxp->rxq.slr.small; \
192 (q0) = rxp->rxq.hds.data; \
193 (q1) = rxp->rxq.hds.hdr; \
198 #define bna_tx_rid_mask(_bna) ((_bna)->tx_mod.rid_mask)
200 #define bna_rx_rid_mask(_bna) ((_bna)->rx_mod.rid_mask)
202 #define bna_tx_from_rid(_bna, _rid, _tx) \
204 struct bna_tx_mod *__tx_mod = &(_bna)->tx_mod; \
205 struct bna_tx *__tx; \
207 list_for_each_entry(__tx, &__tx_mod->tx_active_q, qe) { \
208 if (__tx->rid == (_rid)) { \
215 #define bna_rx_from_rid(_bna, _rid, _rx) \
217 struct bna_rx_mod *__rx_mod = &(_bna)->rx_mod; \
218 struct bna_rx *__rx; \
220 list_for_each_entry(__rx, &__rx_mod->rx_active_q, qe) { \
221 if (__rx->rid == (_rid)) { \
228 #define bna_mcam_mod_free_q(_bna) (&(_bna)->mcam_mod.free_q)
230 #define bna_mcam_mod_del_q(_bna) (&(_bna)->mcam_mod.del_q)
232 #define bna_ucam_mod_free_q(_bna) (&(_bna)->ucam_mod.free_q)
234 #define bna_ucam_mod_del_q(_bna) (&(_bna)->ucam_mod.del_q)
236 /* Inline functions */
238 static inline struct bna_mac
*bna_mac_find(struct list_head
*q
, const u8
*addr
)
242 list_for_each_entry(mac
, q
, qe
)
243 if (ether_addr_equal(mac
->addr
, addr
))
248 #define bna_attr(_bna) (&(_bna)->ioceth.attr)
250 /* Function prototypes */
254 /* FW response handlers */
255 void bna_bfi_stats_clr_rsp(struct bna
*bna
, struct bfi_msgq_mhdr
*msghdr
);
258 void bna_res_req(struct bna_res_info
*res_info
);
259 void bna_mod_res_req(struct bna
*bna
, struct bna_res_info
*res_info
);
260 void bna_init(struct bna
*bna
, struct bnad
*bnad
,
261 struct bfa_pcidev
*pcidev
,
262 struct bna_res_info
*res_info
);
263 void bna_mod_init(struct bna
*bna
, struct bna_res_info
*res_info
);
264 void bna_uninit(struct bna
*bna
);
265 int bna_num_txq_set(struct bna
*bna
, int num_txq
);
266 int bna_num_rxp_set(struct bna
*bna
, int num_rxp
);
267 void bna_hw_stats_get(struct bna
*bna
);
270 struct bna_mac
*bna_cam_mod_mac_get(struct list_head
*head
);
271 struct bna_mcam_handle
*bna_mcam_mod_handle_get(struct bna_mcam_mod
*mod
);
272 void bna_mcam_mod_handle_put(struct bna_mcam_mod
*mcam_mod
,
273 struct bna_mcam_handle
*handle
);
278 void bna_mbox_handler(struct bna
*bna
, u32 intr_status
);
282 /* Callbacks for RX */
283 void bna_ethport_cb_rx_started(struct bna_ethport
*ethport
);
284 void bna_ethport_cb_rx_stopped(struct bna_ethport
*ethport
);
286 /* TX MODULE AND TX */
288 /* FW response handelrs */
289 void bna_bfi_tx_enet_start_rsp(struct bna_tx
*tx
,
290 struct bfi_msgq_mhdr
*msghdr
);
291 void bna_bfi_tx_enet_stop_rsp(struct bna_tx
*tx
,
292 struct bfi_msgq_mhdr
*msghdr
);
293 void bna_bfi_bw_update_aen(struct bna_tx_mod
*tx_mod
);
296 void bna_tx_mod_init(struct bna_tx_mod
*tx_mod
, struct bna
*bna
,
297 struct bna_res_info
*res_info
);
298 void bna_tx_mod_uninit(struct bna_tx_mod
*tx_mod
);
301 void bna_tx_mod_start(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
);
302 void bna_tx_mod_stop(struct bna_tx_mod
*tx_mod
, enum bna_tx_type type
);
303 void bna_tx_mod_fail(struct bna_tx_mod
*tx_mod
);
306 void bna_tx_res_req(int num_txq
, int txq_depth
,
307 struct bna_res_info
*res_info
);
308 struct bna_tx
*bna_tx_create(struct bna
*bna
, struct bnad
*bnad
,
309 struct bna_tx_config
*tx_cfg
,
310 const struct bna_tx_event_cbfn
*tx_cbfn
,
311 struct bna_res_info
*res_info
, void *priv
);
312 void bna_tx_destroy(struct bna_tx
*tx
);
313 void bna_tx_enable(struct bna_tx
*tx
);
314 void bna_tx_disable(struct bna_tx
*tx
, enum bna_cleanup_type type
,
315 void (*cbfn
)(void *, struct bna_tx
*));
316 void bna_tx_cleanup_complete(struct bna_tx
*tx
);
317 void bna_tx_coalescing_timeo_set(struct bna_tx
*tx
, int coalescing_timeo
);
319 /* RX MODULE, RX, RXF */
321 /* FW response handlers */
322 void bna_bfi_rx_enet_start_rsp(struct bna_rx
*rx
,
323 struct bfi_msgq_mhdr
*msghdr
);
324 void bna_bfi_rx_enet_stop_rsp(struct bna_rx
*rx
,
325 struct bfi_msgq_mhdr
*msghdr
);
326 void bna_bfi_rxf_cfg_rsp(struct bna_rxf
*rxf
, struct bfi_msgq_mhdr
*msghdr
);
327 void bna_bfi_rxf_mcast_add_rsp(struct bna_rxf
*rxf
,
328 struct bfi_msgq_mhdr
*msghdr
);
329 void bna_bfi_rxf_ucast_set_rsp(struct bna_rxf
*rxf
,
330 struct bfi_msgq_mhdr
*msghdr
);
333 void bna_rx_mod_init(struct bna_rx_mod
*rx_mod
, struct bna
*bna
,
334 struct bna_res_info
*res_info
);
335 void bna_rx_mod_uninit(struct bna_rx_mod
*rx_mod
);
338 void bna_rx_mod_start(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
);
339 void bna_rx_mod_stop(struct bna_rx_mod
*rx_mod
, enum bna_rx_type type
);
340 void bna_rx_mod_fail(struct bna_rx_mod
*rx_mod
);
343 void bna_rx_res_req(struct bna_rx_config
*rx_config
,
344 struct bna_res_info
*res_info
);
345 struct bna_rx
*bna_rx_create(struct bna
*bna
, struct bnad
*bnad
,
346 struct bna_rx_config
*rx_cfg
,
347 const struct bna_rx_event_cbfn
*rx_cbfn
,
348 struct bna_res_info
*res_info
, void *priv
);
349 void bna_rx_destroy(struct bna_rx
*rx
);
350 void bna_rx_enable(struct bna_rx
*rx
);
351 void bna_rx_disable(struct bna_rx
*rx
, enum bna_cleanup_type type
,
352 void (*cbfn
)(void *, struct bna_rx
*));
353 void bna_rx_cleanup_complete(struct bna_rx
*rx
);
354 void bna_rx_coalescing_timeo_set(struct bna_rx
*rx
, int coalescing_timeo
);
355 void bna_rx_dim_reconfig(struct bna
*bna
, const u32 vector
[][BNA_BIAS_T_MAX
]);
356 void bna_rx_dim_update(struct bna_ccb
*ccb
);
357 enum bna_cb_status
bna_rx_ucast_set(struct bna_rx
*rx
, const u8
*ucmac
);
358 enum bna_cb_status
bna_rx_ucast_listset(struct bna_rx
*rx
, int count
,
360 enum bna_cb_status
bna_rx_mcast_add(struct bna_rx
*rx
, const u8
*mcmac
,
361 void (*cbfn
)(struct bnad
*,
363 enum bna_cb_status
bna_rx_mcast_listset(struct bna_rx
*rx
, int count
,
366 bna_rx_mcast_delall(struct bna_rx
*rx
);
368 bna_rx_mode_set(struct bna_rx
*rx
, enum bna_rxmode rxmode
,
369 enum bna_rxmode bitmask
);
370 void bna_rx_vlan_add(struct bna_rx
*rx
, int vlan_id
);
371 void bna_rx_vlan_del(struct bna_rx
*rx
, int vlan_id
);
372 void bna_rx_vlanfilter_enable(struct bna_rx
*rx
);
373 void bna_rx_vlan_strip_enable(struct bna_rx
*rx
);
374 void bna_rx_vlan_strip_disable(struct bna_rx
*rx
);
378 int bna_enet_mtu_get(struct bna_enet
*enet
);
380 /* Callbacks for TX, RX */
381 void bna_enet_cb_tx_stopped(struct bna_enet
*enet
);
382 void bna_enet_cb_rx_stopped(struct bna_enet
*enet
);
385 void bna_enet_enable(struct bna_enet
*enet
);
386 void bna_enet_disable(struct bna_enet
*enet
, enum bna_cleanup_type type
,
387 void (*cbfn
)(void *));
388 void bna_enet_pause_config(struct bna_enet
*enet
,
389 struct bna_pause_config
*pause_config
);
390 void bna_enet_mtu_set(struct bna_enet
*enet
, int mtu
,
391 void (*cbfn
)(struct bnad
*));
392 void bna_enet_perm_mac_get(struct bna_enet
*enet
, u8
*mac
);
397 void bna_ioceth_enable(struct bna_ioceth
*ioceth
);
398 void bna_ioceth_disable(struct bna_ioceth
*ioceth
,
399 enum bna_cleanup_type type
);
403 /* Callbacks for ENET */
404 void bnad_cb_ethport_link_status(struct bnad
*bnad
,
405 enum bna_link_status status
);
407 /* Callbacks for IOCETH */
408 void bnad_cb_ioceth_ready(struct bnad
*bnad
);
409 void bnad_cb_ioceth_failed(struct bnad
*bnad
);
410 void bnad_cb_ioceth_disabled(struct bnad
*bnad
);
411 void bnad_cb_mbox_intr_enable(struct bnad
*bnad
);
412 void bnad_cb_mbox_intr_disable(struct bnad
*bnad
);
414 /* Callbacks for BNA */
415 void bnad_cb_stats_get(struct bnad
*bnad
, enum bna_cb_status status
,
416 struct bna_stats
*stats
);
418 #endif /* __BNA_H__ */