bna: get rid of duplicate and unused macros
[cascardo/linux.git] / drivers / net / ethernet / brocade / bna / bna.h
1 /*
2  * Linux network driver for QLogic BR-series Converged Network Adapter.
3  *
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
7  *
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.
12  */
13 /*
14  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15  * Copyright (c) 2014-2015 QLogic Corporation
16  * All rights reserved
17  * www.qlogic.com
18  */
19 #ifndef __BNA_H__
20 #define __BNA_H__
21
22 #include "bfa_defs.h"
23 #include "bfa_ioc.h"
24 #include "bfi_enet.h"
25 #include "bna_types.h"
26
27 extern const u32 bna_napi_dim_vector[][BNA_BIAS_T_MAX];
28
29 /*  Macros and constants  */
30
31 #define bna_is_small_rxq(_id) ((_id) & 0x1)
32
33 /*
34  * input : _addr-> os dma addr in host endian format,
35  * output : _bna_dma_addr-> pointer to hw dma addr
36  */
37 #define BNA_SET_DMA_ADDR(_addr, _bna_dma_addr)                          \
38 do {                                                                    \
39         u64 tmp_addr =                                          \
40         cpu_to_be64((u64)(_addr));                              \
41         (_bna_dma_addr)->msb = ((struct bna_dma_addr *)&tmp_addr)->msb; \
42         (_bna_dma_addr)->lsb = ((struct bna_dma_addr *)&tmp_addr)->lsb; \
43 } while (0)
44
45 /*
46  * input : _bna_dma_addr-> pointer to hw dma addr
47  * output : _addr-> os dma addr in host endian format
48  */
49 #define BNA_GET_DMA_ADDR(_bna_dma_addr, _addr)                  \
50 do {                                                            \
51         (_addr) = ((((u64)ntohl((_bna_dma_addr)->msb))) << 32)          \
52         | ((ntohl((_bna_dma_addr)->lsb) & 0xffffffff)); \
53 } while (0)
54
55 #define BNA_TXQ_WI_NEEDED(_vectors)     (((_vectors) + 3) >> 2)
56
57 #define BNA_QE_INDX_ADD(_qe_idx, _qe_num, _q_depth)                     \
58         ((_qe_idx) = ((_qe_idx) + (_qe_num)) & ((_q_depth) - 1))
59
60 #define BNA_QE_INDX_INC(_idx, _q_depth) BNA_QE_INDX_ADD(_idx, 1, _q_depth)
61
62 #define BNA_Q_INDEX_CHANGE(_old_idx, _updated_idx, _q_depth)            \
63         (((_updated_idx) - (_old_idx)) & ((_q_depth) - 1))
64
65 #define BNA_QE_FREE_CNT(_q_ptr, _q_depth)                               \
66         (((_q_ptr)->consumer_index - (_q_ptr)->producer_index - 1) &    \
67          ((_q_depth) - 1))
68 #define BNA_QE_IN_USE_CNT(_q_ptr, _q_depth)                             \
69         ((((_q_ptr)->producer_index - (_q_ptr)->consumer_index)) &      \
70          (_q_depth - 1))
71
72 #define BNA_LARGE_PKT_SIZE              1000
73
74 #define BNA_UPDATE_PKT_CNT(_pkt, _len)                                  \
75 do {                                                                    \
76         if ((_len) > BNA_LARGE_PKT_SIZE) {                              \
77                 (_pkt)->large_pkt_cnt++;                                \
78         } else {                                                        \
79                 (_pkt)->small_pkt_cnt++;                                \
80         }                                                               \
81 } while (0)
82
83 #define call_rxf_stop_cbfn(rxf)                                         \
84 do {                                                                    \
85         if ((rxf)->stop_cbfn) {                                         \
86                 void (*cbfn)(struct bna_rx *);                  \
87                 struct bna_rx *cbarg;                                   \
88                 cbfn = (rxf)->stop_cbfn;                                \
89                 cbarg = (rxf)->stop_cbarg;                              \
90                 (rxf)->stop_cbfn = NULL;                                \
91                 (rxf)->stop_cbarg = NULL;                               \
92                 cbfn(cbarg);                                            \
93         }                                                               \
94 } while (0)
95
96 #define call_rxf_start_cbfn(rxf)                                        \
97 do {                                                                    \
98         if ((rxf)->start_cbfn) {                                        \
99                 void (*cbfn)(struct bna_rx *);                  \
100                 struct bna_rx *cbarg;                                   \
101                 cbfn = (rxf)->start_cbfn;                               \
102                 cbarg = (rxf)->start_cbarg;                             \
103                 (rxf)->start_cbfn = NULL;                               \
104                 (rxf)->start_cbarg = NULL;                              \
105                 cbfn(cbarg);                                            \
106         }                                                               \
107 } while (0)
108
109 #define call_rxf_cam_fltr_cbfn(rxf)                                     \
110 do {                                                                    \
111         if ((rxf)->cam_fltr_cbfn) {                                     \
112                 void (*cbfn)(struct bnad *, struct bna_rx *);   \
113                 struct bnad *cbarg;                                     \
114                 cbfn = (rxf)->cam_fltr_cbfn;                            \
115                 cbarg = (rxf)->cam_fltr_cbarg;                          \
116                 (rxf)->cam_fltr_cbfn = NULL;                            \
117                 (rxf)->cam_fltr_cbarg = NULL;                           \
118                 cbfn(cbarg, rxf->rx);                                   \
119         }                                                               \
120 } while (0)
121
122 #define call_rxf_pause_cbfn(rxf)                                        \
123 do {                                                                    \
124         if ((rxf)->oper_state_cbfn) {                                   \
125                 void (*cbfn)(struct bnad *, struct bna_rx *);   \
126                 struct bnad *cbarg;                                     \
127                 cbfn = (rxf)->oper_state_cbfn;                          \
128                 cbarg = (rxf)->oper_state_cbarg;                        \
129                 (rxf)->oper_state_cbfn = NULL;                          \
130                 (rxf)->oper_state_cbarg = NULL;                         \
131                 cbfn(cbarg, rxf->rx);                                   \
132         }                                                               \
133 } while (0)
134
135 #define call_rxf_resume_cbfn(rxf) call_rxf_pause_cbfn(rxf)
136
137 #define is_xxx_enable(mode, bitmask, xxx) ((bitmask & xxx) && (mode & xxx))
138
139 #define is_xxx_disable(mode, bitmask, xxx) ((bitmask & xxx) && !(mode & xxx))
140
141 #define xxx_enable(mode, bitmask, xxx)                                  \
142 do {                                                                    \
143         bitmask |= xxx;                                                 \
144         mode |= xxx;                                                    \
145 } while (0)
146
147 #define xxx_disable(mode, bitmask, xxx)                                 \
148 do {                                                                    \
149         bitmask |= xxx;                                                 \
150         mode &= ~xxx;                                                   \
151 } while (0)
152
153 #define xxx_inactive(mode, bitmask, xxx)                                \
154 do {                                                                    \
155         bitmask &= ~xxx;                                                \
156         mode &= ~xxx;                                                   \
157 } while (0)
158
159 #define is_promisc_enable(mode, bitmask)                                \
160         is_xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
161
162 #define is_promisc_disable(mode, bitmask)                               \
163         is_xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
164
165 #define promisc_enable(mode, bitmask)                                   \
166         xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
167
168 #define promisc_disable(mode, bitmask)                                  \
169         xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
170
171 #define promisc_inactive(mode, bitmask)                                 \
172         xxx_inactive(mode, bitmask, BNA_RXMODE_PROMISC)
173
174 #define is_default_enable(mode, bitmask)                                \
175         is_xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
176
177 #define is_default_disable(mode, bitmask)                               \
178         is_xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
179
180 #define default_enable(mode, bitmask)                                   \
181         xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
182
183 #define default_disable(mode, bitmask)                                  \
184         xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
185
186 #define default_inactive(mode, bitmask)                                 \
187         xxx_inactive(mode, bitmask, BNA_RXMODE_DEFAULT)
188
189 #define is_allmulti_enable(mode, bitmask)                               \
190         is_xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
191
192 #define is_allmulti_disable(mode, bitmask)                              \
193         is_xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
194
195 #define allmulti_enable(mode, bitmask)                                  \
196         xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
197
198 #define allmulti_disable(mode, bitmask)                                 \
199         xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
200
201 #define allmulti_inactive(mode, bitmask)                                \
202         xxx_inactive(mode, bitmask, BNA_RXMODE_ALLMULTI)
203
204 #define GET_RXQS(rxp, q0, q1)   do {                                    \
205         switch ((rxp)->type) {                                          \
206         case BNA_RXP_SINGLE:                                            \
207                 (q0) = rxp->rxq.single.only;                            \
208                 (q1) = NULL;                                            \
209                 break;                                                  \
210         case BNA_RXP_SLR:                                               \
211                 (q0) = rxp->rxq.slr.large;                              \
212                 (q1) = rxp->rxq.slr.small;                              \
213                 break;                                                  \
214         case BNA_RXP_HDS:                                               \
215                 (q0) = rxp->rxq.hds.data;                               \
216                 (q1) = rxp->rxq.hds.hdr;                                \
217                 break;                                                  \
218         }                                                               \
219 } while (0)
220
221 #define bna_tx_rid_mask(_bna) ((_bna)->tx_mod.rid_mask)
222
223 #define bna_rx_rid_mask(_bna) ((_bna)->rx_mod.rid_mask)
224
225 #define bna_tx_from_rid(_bna, _rid, _tx)                                \
226 do {                                                                \
227         struct bna_tx_mod *__tx_mod = &(_bna)->tx_mod;    \
228         struct bna_tx *__tx;                                        \
229         struct list_head *qe;                                      \
230         _tx = NULL;                                                  \
231         list_for_each(qe, &__tx_mod->tx_active_q) {                  \
232                 __tx = (struct bna_tx *)qe;                          \
233                 if (__tx->rid == (_rid)) {                            \
234                         (_tx) = __tx;                              \
235                         break;                                    \
236                 }                                                      \
237         }                                                              \
238 } while (0)
239
240 #define bna_rx_from_rid(_bna, _rid, _rx)                                \
241 do {                                                                    \
242         struct bna_rx_mod *__rx_mod = &(_bna)->rx_mod;                  \
243         struct bna_rx *__rx;                                            \
244         struct list_head *qe;                                           \
245         _rx = NULL;                                                     \
246         list_for_each(qe, &__rx_mod->rx_active_q) {                     \
247                 __rx = (struct bna_rx *)qe;                             \
248                 if (__rx->rid == (_rid)) {                              \
249                         (_rx) = __rx;                                   \
250                         break;                                          \
251                 }                                                       \
252         }                                                               \
253 } while (0)
254
255 #define bna_mcam_mod_free_q(_bna) (&(_bna)->mcam_mod.free_q)
256
257 #define bna_mcam_mod_del_q(_bna) (&(_bna)->mcam_mod.del_q)
258
259 #define bna_ucam_mod_free_q(_bna) (&(_bna)->ucam_mod.free_q)
260
261 #define bna_ucam_mod_del_q(_bna) (&(_bna)->ucam_mod.del_q)
262
263 /*  Inline functions  */
264
265 static inline struct bna_mac *bna_mac_find(struct list_head *q, u8 *addr)
266 {
267         struct bna_mac *mac = NULL;
268         struct list_head *qe;
269         list_for_each(qe, q) {
270                 if (ether_addr_equal(((struct bna_mac *)qe)->addr, addr)) {
271                         mac = (struct bna_mac *)qe;
272                         break;
273                 }
274         }
275         return mac;
276 }
277
278 #define bna_attr(_bna) (&(_bna)->ioceth.attr)
279
280 /* Function prototypes */
281
282 /* BNA */
283
284 /* FW response handlers */
285 void bna_bfi_stats_clr_rsp(struct bna *bna, struct bfi_msgq_mhdr *msghdr);
286
287 /* APIs for BNAD */
288 void bna_res_req(struct bna_res_info *res_info);
289 void bna_mod_res_req(struct bna *bna, struct bna_res_info *res_info);
290 void bna_init(struct bna *bna, struct bnad *bnad,
291                         struct bfa_pcidev *pcidev,
292                         struct bna_res_info *res_info);
293 void bna_mod_init(struct bna *bna, struct bna_res_info *res_info);
294 void bna_uninit(struct bna *bna);
295 int bna_num_txq_set(struct bna *bna, int num_txq);
296 int bna_num_rxp_set(struct bna *bna, int num_rxp);
297 void bna_hw_stats_get(struct bna *bna);
298
299 /* APIs for RxF */
300 struct bna_mac *bna_cam_mod_mac_get(struct list_head *head);
301 void bna_cam_mod_mac_put(struct list_head *tail, struct bna_mac *mac);
302 struct bna_mcam_handle *bna_mcam_mod_handle_get(struct bna_mcam_mod *mod);
303 void bna_mcam_mod_handle_put(struct bna_mcam_mod *mcam_mod,
304                           struct bna_mcam_handle *handle);
305
306 /* MBOX */
307
308 /* API for BNAD */
309 void bna_mbox_handler(struct bna *bna, u32 intr_status);
310
311 /* ETHPORT */
312
313 /* Callbacks for RX */
314 void bna_ethport_cb_rx_started(struct bna_ethport *ethport);
315 void bna_ethport_cb_rx_stopped(struct bna_ethport *ethport);
316
317 /* TX MODULE AND TX */
318
319 /* FW response handelrs */
320 void bna_bfi_tx_enet_start_rsp(struct bna_tx *tx,
321                                struct bfi_msgq_mhdr *msghdr);
322 void bna_bfi_tx_enet_stop_rsp(struct bna_tx *tx,
323                               struct bfi_msgq_mhdr *msghdr);
324 void bna_bfi_bw_update_aen(struct bna_tx_mod *tx_mod);
325
326 /* APIs for BNA */
327 void bna_tx_mod_init(struct bna_tx_mod *tx_mod, struct bna *bna,
328                      struct bna_res_info *res_info);
329 void bna_tx_mod_uninit(struct bna_tx_mod *tx_mod);
330
331 /* APIs for ENET */
332 void bna_tx_mod_start(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
333 void bna_tx_mod_stop(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
334 void bna_tx_mod_fail(struct bna_tx_mod *tx_mod);
335
336 /* APIs for BNAD */
337 void bna_tx_res_req(int num_txq, int txq_depth,
338                     struct bna_res_info *res_info);
339 struct bna_tx *bna_tx_create(struct bna *bna, struct bnad *bnad,
340                                struct bna_tx_config *tx_cfg,
341                                const struct bna_tx_event_cbfn *tx_cbfn,
342                                struct bna_res_info *res_info, void *priv);
343 void bna_tx_destroy(struct bna_tx *tx);
344 void bna_tx_enable(struct bna_tx *tx);
345 void bna_tx_disable(struct bna_tx *tx, enum bna_cleanup_type type,
346                     void (*cbfn)(void *, struct bna_tx *));
347 void bna_tx_cleanup_complete(struct bna_tx *tx);
348 void bna_tx_coalescing_timeo_set(struct bna_tx *tx, int coalescing_timeo);
349
350 /* RX MODULE, RX, RXF */
351
352 /* FW response handlers */
353 void bna_bfi_rx_enet_start_rsp(struct bna_rx *rx,
354                                struct bfi_msgq_mhdr *msghdr);
355 void bna_bfi_rx_enet_stop_rsp(struct bna_rx *rx,
356                               struct bfi_msgq_mhdr *msghdr);
357 void bna_bfi_rxf_cfg_rsp(struct bna_rxf *rxf, struct bfi_msgq_mhdr *msghdr);
358 void bna_bfi_rxf_mcast_add_rsp(struct bna_rxf *rxf,
359                                struct bfi_msgq_mhdr *msghdr);
360 void bna_bfi_rxf_ucast_set_rsp(struct bna_rxf *rxf,
361                                struct bfi_msgq_mhdr *msghdr);
362
363 /* APIs for BNA */
364 void bna_rx_mod_init(struct bna_rx_mod *rx_mod, struct bna *bna,
365                      struct bna_res_info *res_info);
366 void bna_rx_mod_uninit(struct bna_rx_mod *rx_mod);
367
368 /* APIs for ENET */
369 void bna_rx_mod_start(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
370 void bna_rx_mod_stop(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
371 void bna_rx_mod_fail(struct bna_rx_mod *rx_mod);
372
373 /* APIs for BNAD */
374 void bna_rx_res_req(struct bna_rx_config *rx_config,
375                     struct bna_res_info *res_info);
376 struct bna_rx *bna_rx_create(struct bna *bna, struct bnad *bnad,
377                                struct bna_rx_config *rx_cfg,
378                                const struct bna_rx_event_cbfn *rx_cbfn,
379                                struct bna_res_info *res_info, void *priv);
380 void bna_rx_destroy(struct bna_rx *rx);
381 void bna_rx_enable(struct bna_rx *rx);
382 void bna_rx_disable(struct bna_rx *rx, enum bna_cleanup_type type,
383                     void (*cbfn)(void *, struct bna_rx *));
384 void bna_rx_cleanup_complete(struct bna_rx *rx);
385 void bna_rx_coalescing_timeo_set(struct bna_rx *rx, int coalescing_timeo);
386 void bna_rx_dim_reconfig(struct bna *bna, const u32 vector[][BNA_BIAS_T_MAX]);
387 void bna_rx_dim_update(struct bna_ccb *ccb);
388 enum bna_cb_status
389 bna_rx_ucast_set(struct bna_rx *rx, u8 *ucmac,
390                  void (*cbfn)(struct bnad *, struct bna_rx *));
391 enum bna_cb_status
392 bna_rx_ucast_add(struct bna_rx *rx, u8* ucmac,
393                  void (*cbfn)(struct bnad *, struct bna_rx *));
394 enum bna_cb_status
395 bna_rx_ucast_del(struct bna_rx *rx, u8 *ucmac,
396                  void (*cbfn)(struct bnad *, struct bna_rx *));
397 enum bna_cb_status
398 bna_rx_ucast_listset(struct bna_rx *rx, int count, u8 *uclist,
399                      void (*cbfn)(struct bnad *, struct bna_rx *));
400 enum bna_cb_status
401 bna_rx_mcast_add(struct bna_rx *rx, u8 *mcmac,
402                  void (*cbfn)(struct bnad *, struct bna_rx *));
403 enum bna_cb_status
404 bna_rx_mcast_listset(struct bna_rx *rx, int count, u8 *mcmac,
405                      void (*cbfn)(struct bnad *, struct bna_rx *));
406 void
407 bna_rx_mcast_delall(struct bna_rx *rx,
408                     void (*cbfn)(struct bnad *, struct bna_rx *));
409 enum bna_cb_status
410 bna_rx_mode_set(struct bna_rx *rx, enum bna_rxmode rxmode,
411                 enum bna_rxmode bitmask,
412                 void (*cbfn)(struct bnad *, struct bna_rx *));
413 void bna_rx_vlan_add(struct bna_rx *rx, int vlan_id);
414 void bna_rx_vlan_del(struct bna_rx *rx, int vlan_id);
415 void bna_rx_vlanfilter_enable(struct bna_rx *rx);
416 void bna_rx_vlan_strip_enable(struct bna_rx *rx);
417 void bna_rx_vlan_strip_disable(struct bna_rx *rx);
418 /* ENET */
419
420 /* API for RX */
421 int bna_enet_mtu_get(struct bna_enet *enet);
422
423 /* Callbacks for TX, RX */
424 void bna_enet_cb_tx_stopped(struct bna_enet *enet);
425 void bna_enet_cb_rx_stopped(struct bna_enet *enet);
426
427 /* API for BNAD */
428 void bna_enet_enable(struct bna_enet *enet);
429 void bna_enet_disable(struct bna_enet *enet, enum bna_cleanup_type type,
430                       void (*cbfn)(void *));
431 void bna_enet_pause_config(struct bna_enet *enet,
432                            struct bna_pause_config *pause_config,
433                            void (*cbfn)(struct bnad *));
434 void bna_enet_mtu_set(struct bna_enet *enet, int mtu,
435                       void (*cbfn)(struct bnad *));
436 void bna_enet_perm_mac_get(struct bna_enet *enet, u8 *mac);
437
438 /* IOCETH */
439
440 /* APIs for BNAD */
441 void bna_ioceth_enable(struct bna_ioceth *ioceth);
442 void bna_ioceth_disable(struct bna_ioceth *ioceth,
443                         enum bna_cleanup_type type);
444
445 /* BNAD */
446
447 /* Callbacks for ENET */
448 void bnad_cb_ethport_link_status(struct bnad *bnad,
449                               enum bna_link_status status);
450
451 /* Callbacks for IOCETH */
452 void bnad_cb_ioceth_ready(struct bnad *bnad);
453 void bnad_cb_ioceth_failed(struct bnad *bnad);
454 void bnad_cb_ioceth_disabled(struct bnad *bnad);
455 void bnad_cb_mbox_intr_enable(struct bnad *bnad);
456 void bnad_cb_mbox_intr_disable(struct bnad *bnad);
457
458 /* Callbacks for BNA */
459 void bnad_cb_stats_get(struct bnad *bnad, enum bna_cb_status status,
460                        struct bna_stats *stats);
461
462 #endif  /* __BNA_H__ */