b5ac84d78b6dcff0a459a5a361b1b4b4df490de0
[dpdk.git] / drivers / net / sfc / base / efx_impl.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2007-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  */
6
7 #ifndef _SYS_EFX_IMPL_H
8 #define _SYS_EFX_IMPL_H
9
10 #include "efx.h"
11 #include "efx_regs.h"
12 #include "efx_regs_ef10.h"
13 #if EFSYS_OPT_MCDI
14 #include "efx_mcdi.h"
15 #endif  /* EFSYS_OPT_MCDI */
16
17 /* FIXME: Add definition for driver generated software events */
18 #ifndef ESE_DZ_EV_CODE_DRV_GEN_EV
19 #define ESE_DZ_EV_CODE_DRV_GEN_EV FSE_AZ_EV_CODE_DRV_GEN_EV
20 #endif
21
22
23 #if EFSYS_OPT_SIENA
24 #include "siena_impl.h"
25 #endif  /* EFSYS_OPT_SIENA */
26
27 #if EFSYS_OPT_HUNTINGTON
28 #include "hunt_impl.h"
29 #endif  /* EFSYS_OPT_HUNTINGTON */
30
31 #if EFSYS_OPT_MEDFORD
32 #include "medford_impl.h"
33 #endif  /* EFSYS_OPT_MEDFORD */
34
35 #if EFSYS_OPT_MEDFORD2
36 #include "medford2_impl.h"
37 #endif  /* EFSYS_OPT_MEDFORD2 */
38
39 #if EFX_OPTS_EF10()
40 #include "ef10_impl.h"
41 #endif  /* EFX_OPTS_EF10() */
42
43 #ifdef  __cplusplus
44 extern "C" {
45 #endif
46
47 #define EFX_MOD_MCDI            0x00000001
48 #define EFX_MOD_PROBE           0x00000002
49 #define EFX_MOD_NVRAM           0x00000004
50 #define EFX_MOD_VPD             0x00000008
51 #define EFX_MOD_NIC             0x00000010
52 #define EFX_MOD_INTR            0x00000020
53 #define EFX_MOD_EV              0x00000040
54 #define EFX_MOD_RX              0x00000080
55 #define EFX_MOD_TX              0x00000100
56 #define EFX_MOD_PORT            0x00000200
57 #define EFX_MOD_MON             0x00000400
58 #define EFX_MOD_FILTER          0x00001000
59 #define EFX_MOD_LIC             0x00002000
60 #define EFX_MOD_TUNNEL          0x00004000
61
62 #define EFX_RESET_PHY           0x00000001
63 #define EFX_RESET_RXQ_ERR       0x00000002
64 #define EFX_RESET_TXQ_ERR       0x00000004
65 #define EFX_RESET_HW_UNAVAIL    0x00000008
66
67 typedef enum efx_mac_type_e {
68         EFX_MAC_INVALID = 0,
69         EFX_MAC_SIENA,
70         EFX_MAC_HUNTINGTON,
71         EFX_MAC_MEDFORD,
72         EFX_MAC_MEDFORD2,
73         EFX_MAC_NTYPES
74 } efx_mac_type_t;
75
76 typedef struct efx_ev_ops_s {
77         efx_rc_t        (*eevo_init)(efx_nic_t *);
78         void            (*eevo_fini)(efx_nic_t *);
79         efx_rc_t        (*eevo_qcreate)(efx_nic_t *, unsigned int,
80                                           efsys_mem_t *, size_t, uint32_t,
81                                           uint32_t, uint32_t, efx_evq_t *);
82         void            (*eevo_qdestroy)(efx_evq_t *);
83         efx_rc_t        (*eevo_qprime)(efx_evq_t *, unsigned int);
84         void            (*eevo_qpost)(efx_evq_t *, uint16_t);
85         efx_rc_t        (*eevo_qmoderate)(efx_evq_t *, unsigned int);
86 #if EFSYS_OPT_QSTATS
87         void            (*eevo_qstats_update)(efx_evq_t *, efsys_stat_t *);
88 #endif
89 } efx_ev_ops_t;
90
91 typedef struct efx_tx_ops_s {
92         efx_rc_t        (*etxo_init)(efx_nic_t *);
93         void            (*etxo_fini)(efx_nic_t *);
94         efx_rc_t        (*etxo_qcreate)(efx_nic_t *,
95                                         unsigned int, unsigned int,
96                                         efsys_mem_t *, size_t,
97                                         uint32_t, uint16_t,
98                                         efx_evq_t *, efx_txq_t *,
99                                         unsigned int *);
100         void            (*etxo_qdestroy)(efx_txq_t *);
101         efx_rc_t        (*etxo_qpost)(efx_txq_t *, efx_buffer_t *,
102                                       unsigned int, unsigned int,
103                                       unsigned int *);
104         void            (*etxo_qpush)(efx_txq_t *, unsigned int, unsigned int);
105         efx_rc_t        (*etxo_qpace)(efx_txq_t *, unsigned int);
106         efx_rc_t        (*etxo_qflush)(efx_txq_t *);
107         void            (*etxo_qenable)(efx_txq_t *);
108         efx_rc_t        (*etxo_qpio_enable)(efx_txq_t *);
109         void            (*etxo_qpio_disable)(efx_txq_t *);
110         efx_rc_t        (*etxo_qpio_write)(efx_txq_t *, uint8_t *, size_t,
111                                            size_t);
112         efx_rc_t        (*etxo_qpio_post)(efx_txq_t *, size_t, unsigned int,
113                                            unsigned int *);
114         efx_rc_t        (*etxo_qdesc_post)(efx_txq_t *, efx_desc_t *,
115                                       unsigned int, unsigned int,
116                                       unsigned int *);
117         void            (*etxo_qdesc_dma_create)(efx_txq_t *, efsys_dma_addr_t,
118                                                 size_t, boolean_t,
119                                                 efx_desc_t *);
120         void            (*etxo_qdesc_tso_create)(efx_txq_t *, uint16_t,
121                                                 uint32_t, uint8_t,
122                                                 efx_desc_t *);
123         void            (*etxo_qdesc_tso2_create)(efx_txq_t *, uint16_t,
124                                                 uint16_t, uint32_t, uint16_t,
125                                                 efx_desc_t *, int);
126         void            (*etxo_qdesc_vlantci_create)(efx_txq_t *, uint16_t,
127                                                 efx_desc_t *);
128         void            (*etxo_qdesc_checksum_create)(efx_txq_t *, uint16_t,
129                                                 efx_desc_t *);
130 #if EFSYS_OPT_QSTATS
131         void            (*etxo_qstats_update)(efx_txq_t *,
132                                               efsys_stat_t *);
133 #endif
134 } efx_tx_ops_t;
135
136 typedef union efx_rxq_type_data_u {
137         struct {
138                 size_t          ed_buf_size;
139         } ertd_default;
140 #if EFSYS_OPT_RX_PACKED_STREAM
141         struct {
142                 uint32_t        eps_buf_size;
143         } ertd_packed_stream;
144 #endif
145 #if EFSYS_OPT_RX_ES_SUPER_BUFFER
146         struct {
147                 uint32_t        eessb_bufs_per_desc;
148                 uint32_t        eessb_max_dma_len;
149                 uint32_t        eessb_buf_stride;
150                 uint32_t        eessb_hol_block_timeout;
151         } ertd_es_super_buffer;
152 #endif
153 } efx_rxq_type_data_t;
154
155 typedef struct efx_rx_ops_s {
156         efx_rc_t        (*erxo_init)(efx_nic_t *);
157         void            (*erxo_fini)(efx_nic_t *);
158 #if EFSYS_OPT_RX_SCATTER
159         efx_rc_t        (*erxo_scatter_enable)(efx_nic_t *, unsigned int);
160 #endif
161 #if EFSYS_OPT_RX_SCALE
162         efx_rc_t        (*erxo_scale_context_alloc)(efx_nic_t *,
163                                                     efx_rx_scale_context_type_t,
164                                                     uint32_t, uint32_t *);
165         efx_rc_t        (*erxo_scale_context_free)(efx_nic_t *, uint32_t);
166         efx_rc_t        (*erxo_scale_mode_set)(efx_nic_t *, uint32_t,
167                                                efx_rx_hash_alg_t,
168                                                efx_rx_hash_type_t, boolean_t);
169         efx_rc_t        (*erxo_scale_key_set)(efx_nic_t *, uint32_t,
170                                               uint8_t *, size_t);
171         efx_rc_t        (*erxo_scale_tbl_set)(efx_nic_t *, uint32_t,
172                                               unsigned int *, size_t);
173         uint32_t        (*erxo_prefix_hash)(efx_nic_t *, efx_rx_hash_alg_t,
174                                             uint8_t *);
175 #endif /* EFSYS_OPT_RX_SCALE */
176         efx_rc_t        (*erxo_prefix_pktlen)(efx_nic_t *, uint8_t *,
177                                               uint16_t *);
178         void            (*erxo_qpost)(efx_rxq_t *, efsys_dma_addr_t *, size_t,
179                                       unsigned int, unsigned int,
180                                       unsigned int);
181         void            (*erxo_qpush)(efx_rxq_t *, unsigned int, unsigned int *);
182 #if EFSYS_OPT_RX_PACKED_STREAM
183         void            (*erxo_qpush_ps_credits)(efx_rxq_t *);
184         uint8_t *       (*erxo_qps_packet_info)(efx_rxq_t *, uint8_t *,
185                                                 uint32_t, uint32_t,
186                                                 uint16_t *, uint32_t *, uint32_t *);
187 #endif
188         efx_rc_t        (*erxo_qflush)(efx_rxq_t *);
189         void            (*erxo_qenable)(efx_rxq_t *);
190         efx_rc_t        (*erxo_qcreate)(efx_nic_t *enp, unsigned int,
191                                         unsigned int, efx_rxq_type_t,
192                                         const efx_rxq_type_data_t *,
193                                         efsys_mem_t *, size_t, uint32_t,
194                                         unsigned int,
195                                         efx_evq_t *, efx_rxq_t *);
196         void            (*erxo_qdestroy)(efx_rxq_t *);
197 } efx_rx_ops_t;
198
199 typedef struct efx_mac_ops_s {
200         efx_rc_t        (*emo_poll)(efx_nic_t *, efx_link_mode_t *);
201         efx_rc_t        (*emo_up)(efx_nic_t *, boolean_t *);
202         efx_rc_t        (*emo_addr_set)(efx_nic_t *);
203         efx_rc_t        (*emo_pdu_set)(efx_nic_t *);
204         efx_rc_t        (*emo_pdu_get)(efx_nic_t *, size_t *);
205         efx_rc_t        (*emo_reconfigure)(efx_nic_t *);
206         efx_rc_t        (*emo_multicast_list_set)(efx_nic_t *);
207         efx_rc_t        (*emo_filter_default_rxq_set)(efx_nic_t *,
208                                                       efx_rxq_t *, boolean_t);
209         void            (*emo_filter_default_rxq_clear)(efx_nic_t *);
210 #if EFSYS_OPT_LOOPBACK
211         efx_rc_t        (*emo_loopback_set)(efx_nic_t *, efx_link_mode_t,
212                                             efx_loopback_type_t);
213 #endif  /* EFSYS_OPT_LOOPBACK */
214 #if EFSYS_OPT_MAC_STATS
215         efx_rc_t        (*emo_stats_get_mask)(efx_nic_t *, uint32_t *, size_t);
216         efx_rc_t        (*emo_stats_clear)(efx_nic_t *);
217         efx_rc_t        (*emo_stats_upload)(efx_nic_t *, efsys_mem_t *);
218         efx_rc_t        (*emo_stats_periodic)(efx_nic_t *, efsys_mem_t *,
219                                               uint16_t, boolean_t);
220         efx_rc_t        (*emo_stats_update)(efx_nic_t *, efsys_mem_t *,
221                                             efsys_stat_t *, uint32_t *);
222 #endif  /* EFSYS_OPT_MAC_STATS */
223 } efx_mac_ops_t;
224
225 typedef struct efx_phy_ops_s {
226         efx_rc_t        (*epo_power)(efx_nic_t *, boolean_t); /* optional */
227         efx_rc_t        (*epo_reset)(efx_nic_t *);
228         efx_rc_t        (*epo_reconfigure)(efx_nic_t *);
229         efx_rc_t        (*epo_verify)(efx_nic_t *);
230         efx_rc_t        (*epo_oui_get)(efx_nic_t *, uint32_t *);
231         efx_rc_t        (*epo_link_state_get)(efx_nic_t *, efx_phy_link_state_t *);
232 #if EFSYS_OPT_PHY_STATS
233         efx_rc_t        (*epo_stats_update)(efx_nic_t *, efsys_mem_t *,
234                                             uint32_t *);
235 #endif  /* EFSYS_OPT_PHY_STATS */
236 #if EFSYS_OPT_BIST
237         efx_rc_t        (*epo_bist_enable_offline)(efx_nic_t *);
238         efx_rc_t        (*epo_bist_start)(efx_nic_t *, efx_bist_type_t);
239         efx_rc_t        (*epo_bist_poll)(efx_nic_t *, efx_bist_type_t,
240                                          efx_bist_result_t *, uint32_t *,
241                                          unsigned long *, size_t);
242         void            (*epo_bist_stop)(efx_nic_t *, efx_bist_type_t);
243 #endif  /* EFSYS_OPT_BIST */
244 } efx_phy_ops_t;
245
246 #if EFSYS_OPT_FILTER
247 typedef struct efx_filter_ops_s {
248         efx_rc_t        (*efo_init)(efx_nic_t *);
249         void            (*efo_fini)(efx_nic_t *);
250         efx_rc_t        (*efo_restore)(efx_nic_t *);
251         efx_rc_t        (*efo_add)(efx_nic_t *, efx_filter_spec_t *,
252                                    boolean_t may_replace);
253         efx_rc_t        (*efo_delete)(efx_nic_t *, efx_filter_spec_t *);
254         efx_rc_t        (*efo_supported_filters)(efx_nic_t *, uint32_t *,
255                                    size_t, size_t *);
256         efx_rc_t        (*efo_reconfigure)(efx_nic_t *, uint8_t const *, boolean_t,
257                                    boolean_t, boolean_t, boolean_t,
258                                    uint8_t const *, uint32_t);
259 } efx_filter_ops_t;
260
261 extern  __checkReturn   efx_rc_t
262 efx_filter_reconfigure(
263         __in                            efx_nic_t *enp,
264         __in_ecount(6)                  uint8_t const *mac_addr,
265         __in                            boolean_t all_unicst,
266         __in                            boolean_t mulcst,
267         __in                            boolean_t all_mulcst,
268         __in                            boolean_t brdcst,
269         __in_ecount(6*count)            uint8_t const *addrs,
270         __in                            uint32_t count);
271
272 #endif /* EFSYS_OPT_FILTER */
273
274 #if EFSYS_OPT_TUNNEL
275 typedef struct efx_tunnel_ops_s {
276         boolean_t       (*eto_udp_encap_supported)(efx_nic_t *);
277         efx_rc_t        (*eto_reconfigure)(efx_nic_t *);
278 } efx_tunnel_ops_t;
279 #endif /* EFSYS_OPT_TUNNEL */
280
281 typedef struct efx_port_s {
282         efx_mac_type_t          ep_mac_type;
283         uint32_t                ep_phy_type;
284         uint8_t                 ep_port;
285         uint32_t                ep_mac_pdu;
286         uint8_t                 ep_mac_addr[6];
287         efx_link_mode_t         ep_link_mode;
288         boolean_t               ep_all_unicst;
289         boolean_t               ep_mulcst;
290         boolean_t               ep_all_mulcst;
291         boolean_t               ep_brdcst;
292         unsigned int            ep_fcntl;
293         boolean_t               ep_fcntl_autoneg;
294         efx_oword_t             ep_multicst_hash[2];
295         uint8_t                 ep_mulcst_addr_list[EFX_MAC_ADDR_LEN *
296                                                     EFX_MAC_MULTICAST_LIST_MAX];
297         uint32_t                ep_mulcst_addr_count;
298 #if EFSYS_OPT_LOOPBACK
299         efx_loopback_type_t     ep_loopback_type;
300         efx_link_mode_t         ep_loopback_link_mode;
301 #endif  /* EFSYS_OPT_LOOPBACK */
302 #if EFSYS_OPT_PHY_FLAGS
303         uint32_t                ep_phy_flags;
304 #endif  /* EFSYS_OPT_PHY_FLAGS */
305 #if EFSYS_OPT_PHY_LED_CONTROL
306         efx_phy_led_mode_t      ep_phy_led_mode;
307 #endif  /* EFSYS_OPT_PHY_LED_CONTROL */
308         efx_phy_media_type_t    ep_fixed_port_type;
309         efx_phy_media_type_t    ep_module_type;
310         uint32_t                ep_adv_cap_mask;
311         uint32_t                ep_lp_cap_mask;
312         uint32_t                ep_default_adv_cap_mask;
313         uint32_t                ep_phy_cap_mask;
314         boolean_t               ep_mac_drain;
315 #if EFSYS_OPT_BIST
316         efx_bist_type_t         ep_current_bist;
317 #endif
318         const efx_mac_ops_t     *ep_emop;
319         const efx_phy_ops_t     *ep_epop;
320 } efx_port_t;
321
322 typedef struct efx_mon_ops_s {
323 #if EFSYS_OPT_MON_STATS
324         efx_rc_t        (*emo_stats_update)(efx_nic_t *, efsys_mem_t *,
325                                             efx_mon_stat_value_t *);
326         efx_rc_t        (*emo_limits_update)(efx_nic_t *,
327                                              efx_mon_stat_limits_t *);
328 #endif  /* EFSYS_OPT_MON_STATS */
329 } efx_mon_ops_t;
330
331 typedef struct efx_mon_s {
332         efx_mon_type_t          em_type;
333         const efx_mon_ops_t     *em_emop;
334 } efx_mon_t;
335
336 typedef struct efx_intr_ops_s {
337         efx_rc_t        (*eio_init)(efx_nic_t *, efx_intr_type_t, efsys_mem_t *);
338         void            (*eio_enable)(efx_nic_t *);
339         void            (*eio_disable)(efx_nic_t *);
340         void            (*eio_disable_unlocked)(efx_nic_t *);
341         efx_rc_t        (*eio_trigger)(efx_nic_t *, unsigned int);
342         void            (*eio_status_line)(efx_nic_t *, boolean_t *, uint32_t *);
343         void            (*eio_status_message)(efx_nic_t *, unsigned int,
344                                  boolean_t *);
345         void            (*eio_fatal)(efx_nic_t *);
346         void            (*eio_fini)(efx_nic_t *);
347 } efx_intr_ops_t;
348
349 typedef struct efx_intr_s {
350         const efx_intr_ops_t    *ei_eiop;
351         efsys_mem_t             *ei_esmp;
352         efx_intr_type_t         ei_type;
353         unsigned int            ei_level;
354 } efx_intr_t;
355
356 typedef struct efx_nic_ops_s {
357         efx_rc_t        (*eno_probe)(efx_nic_t *);
358         efx_rc_t        (*eno_board_cfg)(efx_nic_t *);
359         efx_rc_t        (*eno_set_drv_limits)(efx_nic_t *, efx_drv_limits_t*);
360         efx_rc_t        (*eno_reset)(efx_nic_t *);
361         efx_rc_t        (*eno_init)(efx_nic_t *);
362         efx_rc_t        (*eno_get_vi_pool)(efx_nic_t *, uint32_t *);
363         efx_rc_t        (*eno_get_bar_region)(efx_nic_t *, efx_nic_region_t,
364                                         uint32_t *, size_t *);
365         boolean_t       (*eno_hw_unavailable)(efx_nic_t *);
366         void            (*eno_set_hw_unavailable)(efx_nic_t *);
367 #if EFSYS_OPT_DIAG
368         efx_rc_t        (*eno_register_test)(efx_nic_t *);
369 #endif  /* EFSYS_OPT_DIAG */
370         void            (*eno_fini)(efx_nic_t *);
371         void            (*eno_unprobe)(efx_nic_t *);
372 } efx_nic_ops_t;
373
374 #ifndef EFX_TXQ_LIMIT_TARGET
375 #define EFX_TXQ_LIMIT_TARGET 259
376 #endif
377 #ifndef EFX_RXQ_LIMIT_TARGET
378 #define EFX_RXQ_LIMIT_TARGET 512
379 #endif
380
381
382 #if EFSYS_OPT_FILTER
383
384 #if EFSYS_OPT_SIENA
385
386 typedef struct siena_filter_spec_s {
387         uint8_t         sfs_type;
388         uint32_t        sfs_flags;
389         uint32_t        sfs_dmaq_id;
390         uint32_t        sfs_dword[3];
391 } siena_filter_spec_t;
392
393 typedef enum siena_filter_type_e {
394         EFX_SIENA_FILTER_RX_TCP_FULL,   /* TCP/IPv4 {dIP,dTCP,sIP,sTCP} */
395         EFX_SIENA_FILTER_RX_TCP_WILD,   /* TCP/IPv4 {dIP,dTCP,  -,   -} */
396         EFX_SIENA_FILTER_RX_UDP_FULL,   /* UDP/IPv4 {dIP,dUDP,sIP,sUDP} */
397         EFX_SIENA_FILTER_RX_UDP_WILD,   /* UDP/IPv4 {dIP,dUDP,  -,   -} */
398         EFX_SIENA_FILTER_RX_MAC_FULL,   /* Ethernet {dMAC,VLAN} */
399         EFX_SIENA_FILTER_RX_MAC_WILD,   /* Ethernet {dMAC,   -} */
400
401         EFX_SIENA_FILTER_TX_TCP_FULL,   /* TCP/IPv4 {dIP,dTCP,sIP,sTCP} */
402         EFX_SIENA_FILTER_TX_TCP_WILD,   /* TCP/IPv4 {  -,   -,sIP,sTCP} */
403         EFX_SIENA_FILTER_TX_UDP_FULL,   /* UDP/IPv4 {dIP,dTCP,sIP,sTCP} */
404         EFX_SIENA_FILTER_TX_UDP_WILD,   /* UDP/IPv4 {  -,   -,sIP,sUDP} */
405         EFX_SIENA_FILTER_TX_MAC_FULL,   /* Ethernet {sMAC,VLAN} */
406         EFX_SIENA_FILTER_TX_MAC_WILD,   /* Ethernet {sMAC,   -} */
407
408         EFX_SIENA_FILTER_NTYPES
409 } siena_filter_type_t;
410
411 typedef enum siena_filter_tbl_id_e {
412         EFX_SIENA_FILTER_TBL_RX_IP = 0,
413         EFX_SIENA_FILTER_TBL_RX_MAC,
414         EFX_SIENA_FILTER_TBL_TX_IP,
415         EFX_SIENA_FILTER_TBL_TX_MAC,
416         EFX_SIENA_FILTER_NTBLS
417 } siena_filter_tbl_id_t;
418
419 typedef struct siena_filter_tbl_s {
420         int                     sft_size;       /* number of entries */
421         int                     sft_used;       /* active count */
422         uint32_t                *sft_bitmap;    /* active bitmap */
423         siena_filter_spec_t     *sft_spec;      /* array of saved specs */
424 } siena_filter_tbl_t;
425
426 typedef struct siena_filter_s {
427         siena_filter_tbl_t      sf_tbl[EFX_SIENA_FILTER_NTBLS];
428         unsigned int            sf_depth[EFX_SIENA_FILTER_NTYPES];
429 } siena_filter_t;
430
431 #endif  /* EFSYS_OPT_SIENA */
432
433 typedef struct efx_filter_s {
434 #if EFSYS_OPT_SIENA
435         siena_filter_t          *ef_siena_filter;
436 #endif /* EFSYS_OPT_SIENA */
437 #if EFX_OPTS_EF10()
438         ef10_filter_table_t     *ef_ef10_filter_table;
439 #endif /* EFX_OPTS_EF10() */
440 } efx_filter_t;
441
442 #if EFSYS_OPT_SIENA
443
444 extern                  void
445 siena_filter_tbl_clear(
446         __in            efx_nic_t *enp,
447         __in            siena_filter_tbl_id_t tbl);
448
449 #endif  /* EFSYS_OPT_SIENA */
450
451 #endif  /* EFSYS_OPT_FILTER */
452
453 #if EFSYS_OPT_MCDI
454
455 #define EFX_TUNNEL_MAXNENTRIES  (16)
456
457 #if EFSYS_OPT_TUNNEL
458
459 typedef struct efx_tunnel_udp_entry_s {
460         uint16_t                        etue_port; /* host/cpu-endian */
461         uint16_t                        etue_protocol;
462 } efx_tunnel_udp_entry_t;
463
464 typedef struct efx_tunnel_cfg_s {
465         efx_tunnel_udp_entry_t  etc_udp_entries[EFX_TUNNEL_MAXNENTRIES];
466         unsigned int            etc_udp_entries_num;
467 } efx_tunnel_cfg_t;
468
469 #endif /* EFSYS_OPT_TUNNEL */
470
471 typedef struct efx_mcdi_ops_s {
472         efx_rc_t        (*emco_init)(efx_nic_t *, const efx_mcdi_transport_t *);
473         void            (*emco_send_request)(efx_nic_t *, void *, size_t,
474                                         void *, size_t);
475         efx_rc_t        (*emco_poll_reboot)(efx_nic_t *);
476         boolean_t       (*emco_poll_response)(efx_nic_t *);
477         void            (*emco_read_response)(efx_nic_t *, void *, size_t, size_t);
478         void            (*emco_fini)(efx_nic_t *);
479         efx_rc_t        (*emco_feature_supported)(efx_nic_t *,
480                                             efx_mcdi_feature_id_t, boolean_t *);
481         void            (*emco_get_timeout)(efx_nic_t *, efx_mcdi_req_t *,
482                                             uint32_t *);
483 } efx_mcdi_ops_t;
484
485 typedef struct efx_mcdi_s {
486         const efx_mcdi_ops_t            *em_emcop;
487         const efx_mcdi_transport_t      *em_emtp;
488         efx_mcdi_iface_t                em_emip;
489 } efx_mcdi_t;
490
491 #endif /* EFSYS_OPT_MCDI */
492
493 #if EFSYS_OPT_NVRAM
494
495 /* Invalid partition ID for en_nvram_partn_locked field of efx_nc_t */
496 #define EFX_NVRAM_PARTN_INVALID         (0xffffffffu)
497
498 typedef struct efx_nvram_ops_s {
499 #if EFSYS_OPT_DIAG
500         efx_rc_t        (*envo_test)(efx_nic_t *);
501 #endif  /* EFSYS_OPT_DIAG */
502         efx_rc_t        (*envo_type_to_partn)(efx_nic_t *, efx_nvram_type_t,
503                                             uint32_t *);
504         efx_rc_t        (*envo_partn_size)(efx_nic_t *, uint32_t, size_t *);
505         efx_rc_t        (*envo_partn_rw_start)(efx_nic_t *, uint32_t, size_t *);
506         efx_rc_t        (*envo_partn_read)(efx_nic_t *, uint32_t,
507                                             unsigned int, caddr_t, size_t);
508         efx_rc_t        (*envo_partn_read_backup)(efx_nic_t *, uint32_t,
509                                             unsigned int, caddr_t, size_t);
510         efx_rc_t        (*envo_partn_erase)(efx_nic_t *, uint32_t,
511                                             unsigned int, size_t);
512         efx_rc_t        (*envo_partn_write)(efx_nic_t *, uint32_t,
513                                             unsigned int, caddr_t, size_t);
514         efx_rc_t        (*envo_partn_rw_finish)(efx_nic_t *, uint32_t,
515                                             uint32_t *);
516         efx_rc_t        (*envo_partn_get_version)(efx_nic_t *, uint32_t,
517                                             uint32_t *, uint16_t *);
518         efx_rc_t        (*envo_partn_set_version)(efx_nic_t *, uint32_t,
519                                             uint16_t *);
520         efx_rc_t        (*envo_buffer_validate)(uint32_t,
521                                             caddr_t, size_t);
522 } efx_nvram_ops_t;
523 #endif /* EFSYS_OPT_NVRAM */
524
525 #if EFSYS_OPT_VPD
526 typedef struct efx_vpd_ops_s {
527         efx_rc_t        (*evpdo_init)(efx_nic_t *);
528         efx_rc_t        (*evpdo_size)(efx_nic_t *, size_t *);
529         efx_rc_t        (*evpdo_read)(efx_nic_t *, caddr_t, size_t);
530         efx_rc_t        (*evpdo_verify)(efx_nic_t *, caddr_t, size_t);
531         efx_rc_t        (*evpdo_reinit)(efx_nic_t *, caddr_t, size_t);
532         efx_rc_t        (*evpdo_get)(efx_nic_t *, caddr_t, size_t,
533                                         efx_vpd_value_t *);
534         efx_rc_t        (*evpdo_set)(efx_nic_t *, caddr_t, size_t,
535                                         efx_vpd_value_t *);
536         efx_rc_t        (*evpdo_next)(efx_nic_t *, caddr_t, size_t,
537                                         efx_vpd_value_t *, unsigned int *);
538         efx_rc_t        (*evpdo_write)(efx_nic_t *, caddr_t, size_t);
539         void            (*evpdo_fini)(efx_nic_t *);
540 } efx_vpd_ops_t;
541 #endif  /* EFSYS_OPT_VPD */
542
543 #if EFSYS_OPT_VPD || EFSYS_OPT_NVRAM
544
545         __checkReturn           efx_rc_t
546 efx_mcdi_nvram_partitions(
547         __in                    efx_nic_t *enp,
548         __out_bcount(size)      caddr_t data,
549         __in                    size_t size,
550         __out                   unsigned int *npartnp);
551
552         __checkReturn           efx_rc_t
553 efx_mcdi_nvram_metadata(
554         __in                    efx_nic_t *enp,
555         __in                    uint32_t partn,
556         __out                   uint32_t *subtypep,
557         __out_ecount(4)         uint16_t version[4],
558         __out_bcount_opt(size)  char *descp,
559         __in                    size_t size);
560
561         __checkReturn           efx_rc_t
562 efx_mcdi_nvram_info(
563         __in                    efx_nic_t *enp,
564         __in                    uint32_t partn,
565         __out_opt               size_t *sizep,
566         __out_opt               uint32_t *addressp,
567         __out_opt               uint32_t *erase_sizep,
568         __out_opt               uint32_t *write_sizep);
569
570         __checkReturn           efx_rc_t
571 efx_mcdi_nvram_update_start(
572         __in                    efx_nic_t *enp,
573         __in                    uint32_t partn);
574
575         __checkReturn           efx_rc_t
576 efx_mcdi_nvram_read(
577         __in                    efx_nic_t *enp,
578         __in                    uint32_t partn,
579         __in                    uint32_t offset,
580         __out_bcount(size)      caddr_t data,
581         __in                    size_t size,
582         __in                    uint32_t mode);
583
584         __checkReturn           efx_rc_t
585 efx_mcdi_nvram_erase(
586         __in                    efx_nic_t *enp,
587         __in                    uint32_t partn,
588         __in                    uint32_t offset,
589         __in                    size_t size);
590
591         __checkReturn           efx_rc_t
592 efx_mcdi_nvram_write(
593         __in                    efx_nic_t *enp,
594         __in                    uint32_t partn,
595         __in                    uint32_t offset,
596         __in_bcount(size)       caddr_t data,
597         __in                    size_t size);
598
599         __checkReturn           efx_rc_t
600 efx_mcdi_nvram_update_finish(
601         __in                    efx_nic_t *enp,
602         __in                    uint32_t partn,
603         __in                    boolean_t reboot,
604         __out_opt               uint32_t *verify_resultp);
605
606 #if EFSYS_OPT_DIAG
607
608         __checkReturn           efx_rc_t
609 efx_mcdi_nvram_test(
610         __in                    efx_nic_t *enp,
611         __in                    uint32_t partn);
612
613 #endif  /* EFSYS_OPT_DIAG */
614
615 #endif /* EFSYS_OPT_VPD || EFSYS_OPT_NVRAM */
616
617 #if EFSYS_OPT_LICENSING
618
619 typedef struct efx_lic_ops_s {
620         efx_rc_t        (*elo_update_licenses)(efx_nic_t *);
621         efx_rc_t        (*elo_get_key_stats)(efx_nic_t *, efx_key_stats_t *);
622         efx_rc_t        (*elo_app_state)(efx_nic_t *, uint64_t, boolean_t *);
623         efx_rc_t        (*elo_get_id)(efx_nic_t *, size_t, uint32_t *,
624                                       size_t *, uint8_t *);
625         efx_rc_t        (*elo_find_start)
626                                 (efx_nic_t *, caddr_t, size_t, uint32_t *);
627         efx_rc_t        (*elo_find_end)(efx_nic_t *, caddr_t, size_t,
628                                 uint32_t, uint32_t *);
629         boolean_t       (*elo_find_key)(efx_nic_t *, caddr_t, size_t,
630                                 uint32_t, uint32_t *, uint32_t *);
631         boolean_t       (*elo_validate_key)(efx_nic_t *,
632                                 caddr_t, uint32_t);
633         efx_rc_t        (*elo_read_key)(efx_nic_t *,
634                                 caddr_t, size_t, uint32_t, uint32_t,
635                                 caddr_t, size_t, uint32_t *);
636         efx_rc_t        (*elo_write_key)(efx_nic_t *,
637                                 caddr_t, size_t, uint32_t,
638                                 caddr_t, uint32_t, uint32_t *);
639         efx_rc_t        (*elo_delete_key)(efx_nic_t *,
640                                 caddr_t, size_t, uint32_t,
641                                 uint32_t, uint32_t, uint32_t *);
642         efx_rc_t        (*elo_create_partition)(efx_nic_t *,
643                                 caddr_t, size_t);
644         efx_rc_t        (*elo_finish_partition)(efx_nic_t *,
645                                 caddr_t, size_t);
646 } efx_lic_ops_t;
647
648 #endif
649
650 #define EFX_DRV_VER_MAX         20
651
652 typedef struct efx_drv_cfg_s {
653         uint32_t                edc_min_vi_count;
654         uint32_t                edc_max_vi_count;
655
656         uint32_t                edc_max_piobuf_count;
657         uint32_t                edc_pio_alloc_size;
658 } efx_drv_cfg_t;
659
660 struct efx_nic_s {
661         uint32_t                en_magic;
662         efx_family_t            en_family;
663         uint32_t                en_features;
664         efsys_identifier_t      *en_esip;
665         efsys_lock_t            *en_eslp;
666         efsys_bar_t             *en_esbp;
667         unsigned int            en_mod_flags;
668         unsigned int            en_reset_flags;
669         efx_nic_cfg_t           en_nic_cfg;
670         efx_drv_cfg_t           en_drv_cfg;
671         efx_port_t              en_port;
672         efx_mon_t               en_mon;
673         efx_intr_t              en_intr;
674         uint32_t                en_ev_qcount;
675         uint32_t                en_rx_qcount;
676         uint32_t                en_tx_qcount;
677         const efx_nic_ops_t     *en_enop;
678         const efx_ev_ops_t      *en_eevop;
679         const efx_tx_ops_t      *en_etxop;
680         const efx_rx_ops_t      *en_erxop;
681         efx_fw_variant_t        efv;
682         char                    en_drv_version[EFX_DRV_VER_MAX];
683 #if EFSYS_OPT_FILTER
684         efx_filter_t            en_filter;
685         const efx_filter_ops_t  *en_efop;
686 #endif  /* EFSYS_OPT_FILTER */
687 #if EFSYS_OPT_TUNNEL
688         efx_tunnel_cfg_t        en_tunnel_cfg;
689         const efx_tunnel_ops_t  *en_etop;
690 #endif /* EFSYS_OPT_TUNNEL */
691 #if EFSYS_OPT_MCDI
692         efx_mcdi_t              en_mcdi;
693 #endif  /* EFSYS_OPT_MCDI */
694 #if EFSYS_OPT_NVRAM
695         uint32_t                en_nvram_partn_locked;
696         const efx_nvram_ops_t   *en_envop;
697 #endif  /* EFSYS_OPT_NVRAM */
698 #if EFSYS_OPT_VPD
699         const efx_vpd_ops_t     *en_evpdop;
700 #endif  /* EFSYS_OPT_VPD */
701 #if EFSYS_OPT_RX_SCALE
702         efx_rx_hash_support_t           en_hash_support;
703         efx_rx_scale_context_type_t     en_rss_context_type;
704         uint32_t                        en_rss_context;
705 #endif  /* EFSYS_OPT_RX_SCALE */
706         uint32_t                en_vport_id;
707 #if EFSYS_OPT_LICENSING
708         const efx_lic_ops_t     *en_elop;
709         boolean_t               en_licensing_supported;
710 #endif
711         union {
712 #if EFSYS_OPT_SIENA
713                 struct {
714 #if EFSYS_OPT_NVRAM || EFSYS_OPT_VPD
715                         unsigned int            enu_partn_mask;
716 #endif  /* EFSYS_OPT_NVRAM || EFSYS_OPT_VPD */
717 #if EFSYS_OPT_VPD
718                         caddr_t                 enu_svpd;
719                         size_t                  enu_svpd_length;
720 #endif  /* EFSYS_OPT_VPD */
721                         int                     enu_unused;
722                 } siena;
723 #endif  /* EFSYS_OPT_SIENA */
724                 int     enu_unused;
725         } en_u;
726 #if EFX_OPTS_EF10()
727         union en_arch {
728                 struct {
729                         int                     ena_vi_base;
730                         int                     ena_vi_count;
731                         int                     ena_vi_shift;
732 #if EFSYS_OPT_VPD
733                         caddr_t                 ena_svpd;
734                         size_t                  ena_svpd_length;
735 #endif  /* EFSYS_OPT_VPD */
736                         efx_piobuf_handle_t     ena_piobuf_handle[EF10_MAX_PIOBUF_NBUFS];
737                         uint32_t                ena_piobuf_count;
738                         uint32_t                ena_pio_alloc_map[EF10_MAX_PIOBUF_NBUFS];
739                         uint32_t                ena_pio_write_vi_base;
740                         /* Memory BAR mapping regions */
741                         uint32_t                ena_uc_mem_map_offset;
742                         size_t                  ena_uc_mem_map_size;
743                         uint32_t                ena_wc_mem_map_offset;
744                         size_t                  ena_wc_mem_map_size;
745                 } ef10;
746         } en_arch;
747 #endif  /* EFX_OPTS_EF10() */
748 };
749
750 #define EFX_FAMILY_IS_EF10(_enp) \
751         ((_enp)->en_family == EFX_FAMILY_MEDFORD2 || \
752          (_enp)->en_family == EFX_FAMILY_MEDFORD || \
753          (_enp)->en_family == EFX_FAMILY_HUNTINGTON)
754
755
756 #define EFX_NIC_MAGIC   0x02121996
757
758 typedef boolean_t (*efx_ev_handler_t)(efx_evq_t *, efx_qword_t *,
759     const efx_ev_callbacks_t *, void *);
760
761 typedef struct efx_evq_rxq_state_s {
762         unsigned int                    eers_rx_read_ptr;
763         unsigned int                    eers_rx_mask;
764 #if EFSYS_OPT_RX_PACKED_STREAM || EFSYS_OPT_RX_ES_SUPER_BUFFER
765         unsigned int                    eers_rx_stream_npackets;
766         boolean_t                       eers_rx_packed_stream;
767 #endif
768 #if EFSYS_OPT_RX_PACKED_STREAM
769         unsigned int                    eers_rx_packed_stream_credits;
770 #endif
771 } efx_evq_rxq_state_t;
772
773 struct efx_evq_s {
774         uint32_t                        ee_magic;
775         uint32_t                        ee_flags;
776         efx_nic_t                       *ee_enp;
777         unsigned int                    ee_index;
778         unsigned int                    ee_mask;
779         efsys_mem_t                     *ee_esmp;
780 #if EFSYS_OPT_QSTATS
781         uint32_t                        ee_stat[EV_NQSTATS];
782 #endif  /* EFSYS_OPT_QSTATS */
783
784         efx_ev_handler_t                ee_rx;
785         efx_ev_handler_t                ee_tx;
786         efx_ev_handler_t                ee_driver;
787         efx_ev_handler_t                ee_global;
788         efx_ev_handler_t                ee_drv_gen;
789 #if EFSYS_OPT_MCDI
790         efx_ev_handler_t                ee_mcdi;
791 #endif  /* EFSYS_OPT_MCDI */
792
793         efx_evq_rxq_state_t             ee_rxq_state[EFX_EV_RX_NLABELS];
794 };
795
796 #define EFX_EVQ_MAGIC   0x08081997
797
798 #define EFX_EVQ_SIENA_TIMER_QUANTUM_NS  6144 /* 768 cycles */
799
800 #if EFSYS_OPT_QSTATS
801 #define EFX_EV_QSTAT_INCR(_eep, _stat)                                  \
802         do {                                                            \
803                 (_eep)->ee_stat[_stat]++;                               \
804         _NOTE(CONSTANTCONDITION)                                        \
805         } while (B_FALSE)
806 #else
807 #define EFX_EV_QSTAT_INCR(_eep, _stat)
808 #endif
809
810 struct efx_rxq_s {
811         uint32_t                        er_magic;
812         efx_nic_t                       *er_enp;
813         efx_evq_t                       *er_eep;
814         unsigned int                    er_index;
815         unsigned int                    er_label;
816         unsigned int                    er_mask;
817         size_t                          er_buf_size;
818         efsys_mem_t                     *er_esmp;
819         efx_evq_rxq_state_t             *er_ev_qstate;
820 };
821
822 #define EFX_RXQ_MAGIC   0x15022005
823
824 struct efx_txq_s {
825         uint32_t                        et_magic;
826         efx_nic_t                       *et_enp;
827         unsigned int                    et_index;
828         unsigned int                    et_mask;
829         efsys_mem_t                     *et_esmp;
830 #if EFSYS_OPT_HUNTINGTON
831         uint32_t                        et_pio_bufnum;
832         uint32_t                        et_pio_blknum;
833         uint32_t                        et_pio_write_offset;
834         uint32_t                        et_pio_offset;
835         size_t                          et_pio_size;
836 #endif
837 #if EFSYS_OPT_QSTATS
838         uint32_t                        et_stat[TX_NQSTATS];
839 #endif  /* EFSYS_OPT_QSTATS */
840 };
841
842 #define EFX_TXQ_MAGIC   0x05092005
843
844 #define EFX_MAC_ADDR_COPY(_dst, _src)                                   \
845         do {                                                            \
846                 (_dst)[0] = (_src)[0];                                  \
847                 (_dst)[1] = (_src)[1];                                  \
848                 (_dst)[2] = (_src)[2];                                  \
849                 (_dst)[3] = (_src)[3];                                  \
850                 (_dst)[4] = (_src)[4];                                  \
851                 (_dst)[5] = (_src)[5];                                  \
852         _NOTE(CONSTANTCONDITION)                                        \
853         } while (B_FALSE)
854
855 #define EFX_MAC_BROADCAST_ADDR_SET(_dst)                                \
856         do {                                                            \
857                 uint16_t *_d = (uint16_t *)(_dst);                      \
858                 _d[0] = 0xffff;                                         \
859                 _d[1] = 0xffff;                                         \
860                 _d[2] = 0xffff;                                         \
861         _NOTE(CONSTANTCONDITION)                                        \
862         } while (B_FALSE)
863
864 #if EFSYS_OPT_CHECK_REG
865 #define EFX_CHECK_REG(_enp, _reg)                                       \
866         do {                                                            \
867                 const char *name = #_reg;                               \
868                 char min = name[4];                                     \
869                 char max = name[5];                                     \
870                 char rev;                                               \
871                                                                         \
872                 switch ((_enp)->en_family) {                            \
873                 case EFX_FAMILY_SIENA:                                  \
874                         rev = 'C';                                      \
875                         break;                                          \
876                                                                         \
877                 case EFX_FAMILY_HUNTINGTON:                             \
878                         rev = 'D';                                      \
879                         break;                                          \
880                                                                         \
881                 case EFX_FAMILY_MEDFORD:                                \
882                         rev = 'E';                                      \
883                         break;                                          \
884                                                                         \
885                 case EFX_FAMILY_MEDFORD2:                               \
886                         rev = 'F';                                      \
887                         break;                                          \
888                                                                         \
889                 default:                                                \
890                         rev = '?';                                      \
891                         break;                                          \
892                 }                                                       \
893                                                                         \
894                 EFSYS_ASSERT3S(rev, >=, min);                           \
895                 EFSYS_ASSERT3S(rev, <=, max);                           \
896                                                                         \
897         _NOTE(CONSTANTCONDITION)                                        \
898         } while (B_FALSE)
899 #else
900 #define EFX_CHECK_REG(_enp, _reg) do {                                  \
901         _NOTE(CONSTANTCONDITION)                                        \
902         } while (B_FALSE)
903 #endif
904
905 #define EFX_BAR_READD(_enp, _reg, _edp, _lock)                          \
906         do {                                                            \
907                 EFX_CHECK_REG((_enp), (_reg));                          \
908                 EFSYS_BAR_READD((_enp)->en_esbp, _reg ## _OFST,         \
909                     (_edp), (_lock));                                   \
910                 EFSYS_PROBE3(efx_bar_readd, const char *, #_reg,        \
911                     uint32_t, _reg ## _OFST,                            \
912                     uint32_t, (_edp)->ed_u32[0]);                       \
913         _NOTE(CONSTANTCONDITION)                                        \
914         } while (B_FALSE)
915
916 #define EFX_BAR_WRITED(_enp, _reg, _edp, _lock)                         \
917         do {                                                            \
918                 EFX_CHECK_REG((_enp), (_reg));                          \
919                 EFSYS_PROBE3(efx_bar_writed, const char *, #_reg,       \
920                     uint32_t, _reg ## _OFST,                            \
921                     uint32_t, (_edp)->ed_u32[0]);                       \
922                 EFSYS_BAR_WRITED((_enp)->en_esbp, _reg ## _OFST,        \
923                     (_edp), (_lock));                                   \
924         _NOTE(CONSTANTCONDITION)                                        \
925         } while (B_FALSE)
926
927 #define EFX_BAR_READQ(_enp, _reg, _eqp)                                 \
928         do {                                                            \
929                 EFX_CHECK_REG((_enp), (_reg));                          \
930                 EFSYS_BAR_READQ((_enp)->en_esbp, _reg ## _OFST,         \
931                     (_eqp));                                            \
932                 EFSYS_PROBE4(efx_bar_readq, const char *, #_reg,        \
933                     uint32_t, _reg ## _OFST,                            \
934                     uint32_t, (_eqp)->eq_u32[1],                        \
935                     uint32_t, (_eqp)->eq_u32[0]);                       \
936         _NOTE(CONSTANTCONDITION)                                        \
937         } while (B_FALSE)
938
939 #define EFX_BAR_WRITEQ(_enp, _reg, _eqp)                                \
940         do {                                                            \
941                 EFX_CHECK_REG((_enp), (_reg));                          \
942                 EFSYS_PROBE4(efx_bar_writeq, const char *, #_reg,       \
943                     uint32_t, _reg ## _OFST,                            \
944                     uint32_t, (_eqp)->eq_u32[1],                        \
945                     uint32_t, (_eqp)->eq_u32[0]);                       \
946                 EFSYS_BAR_WRITEQ((_enp)->en_esbp, _reg ## _OFST,        \
947                     (_eqp));                                            \
948         _NOTE(CONSTANTCONDITION)                                        \
949         } while (B_FALSE)
950
951 #define EFX_BAR_READO(_enp, _reg, _eop)                                 \
952         do {                                                            \
953                 EFX_CHECK_REG((_enp), (_reg));                          \
954                 EFSYS_BAR_READO((_enp)->en_esbp, _reg ## _OFST,         \
955                     (_eop), B_TRUE);                                    \
956                 EFSYS_PROBE6(efx_bar_reado, const char *, #_reg,        \
957                     uint32_t, _reg ## _OFST,                            \
958                     uint32_t, (_eop)->eo_u32[3],                        \
959                     uint32_t, (_eop)->eo_u32[2],                        \
960                     uint32_t, (_eop)->eo_u32[1],                        \
961                     uint32_t, (_eop)->eo_u32[0]);                       \
962         _NOTE(CONSTANTCONDITION)                                        \
963         } while (B_FALSE)
964
965 #define EFX_BAR_WRITEO(_enp, _reg, _eop)                                \
966         do {                                                            \
967                 EFX_CHECK_REG((_enp), (_reg));                          \
968                 EFSYS_PROBE6(efx_bar_writeo, const char *, #_reg,       \
969                     uint32_t, _reg ## _OFST,                            \
970                     uint32_t, (_eop)->eo_u32[3],                        \
971                     uint32_t, (_eop)->eo_u32[2],                        \
972                     uint32_t, (_eop)->eo_u32[1],                        \
973                     uint32_t, (_eop)->eo_u32[0]);                       \
974                 EFSYS_BAR_WRITEO((_enp)->en_esbp, _reg ## _OFST,        \
975                     (_eop), B_TRUE);                                    \
976         _NOTE(CONSTANTCONDITION)                                        \
977         } while (B_FALSE)
978
979 /*
980  * Accessors for memory BAR non-VI tables.
981  *
982  * Code used on EF10 *must* use EFX_BAR_VI_*() macros for per-VI registers,
983  * to ensure the correct runtime VI window size is used on Medford2.
984  *
985  * Siena-only code may continue using EFX_BAR_TBL_*() macros for VI registers.
986  */
987
988 #define EFX_BAR_TBL_READD(_enp, _reg, _index, _edp, _lock)              \
989         do {                                                            \
990                 EFX_CHECK_REG((_enp), (_reg));                          \
991                 EFSYS_BAR_READD((_enp)->en_esbp,                        \
992                     (_reg ## _OFST + ((_index) * _reg ## _STEP)),       \
993                     (_edp), (_lock));                                   \
994                 EFSYS_PROBE4(efx_bar_tbl_readd, const char *, #_reg,    \
995                     uint32_t, (_index),                                 \
996                     uint32_t, _reg ## _OFST,                            \
997                     uint32_t, (_edp)->ed_u32[0]);                       \
998         _NOTE(CONSTANTCONDITION)                                        \
999         } while (B_FALSE)
1000
1001 #define EFX_BAR_TBL_WRITED(_enp, _reg, _index, _edp, _lock)             \
1002         do {                                                            \
1003                 EFX_CHECK_REG((_enp), (_reg));                          \
1004                 EFSYS_PROBE4(efx_bar_tbl_writed, const char *, #_reg,   \
1005                     uint32_t, (_index),                                 \
1006                     uint32_t, _reg ## _OFST,                            \
1007                     uint32_t, (_edp)->ed_u32[0]);                       \
1008                 EFSYS_BAR_WRITED((_enp)->en_esbp,                       \
1009                     (_reg ## _OFST + ((_index) * _reg ## _STEP)),       \
1010                     (_edp), (_lock));                                   \
1011         _NOTE(CONSTANTCONDITION)                                        \
1012         } while (B_FALSE)
1013
1014 #define EFX_BAR_TBL_WRITED3(_enp, _reg, _index, _edp, _lock)            \
1015         do {                                                            \
1016                 EFX_CHECK_REG((_enp), (_reg));                          \
1017                 EFSYS_PROBE4(efx_bar_tbl_writed, const char *, #_reg,   \
1018                     uint32_t, (_index),                                 \
1019                     uint32_t, _reg ## _OFST,                            \
1020                     uint32_t, (_edp)->ed_u32[0]);                       \
1021                 EFSYS_BAR_WRITED((_enp)->en_esbp,                       \
1022                     (_reg ## _OFST +                                    \
1023                     (3 * sizeof (efx_dword_t)) +                        \
1024                     ((_index) * _reg ## _STEP)),                        \
1025                     (_edp), (_lock));                                   \
1026         _NOTE(CONSTANTCONDITION)                                        \
1027         } while (B_FALSE)
1028
1029 #define EFX_BAR_TBL_READQ(_enp, _reg, _index, _eqp)                     \
1030         do {                                                            \
1031                 EFX_CHECK_REG((_enp), (_reg));                          \
1032                 EFSYS_BAR_READQ((_enp)->en_esbp,                        \
1033                     (_reg ## _OFST + ((_index) * _reg ## _STEP)),       \
1034                     (_eqp));                                            \
1035                 EFSYS_PROBE5(efx_bar_tbl_readq, const char *, #_reg,    \
1036                     uint32_t, (_index),                                 \
1037                     uint32_t, _reg ## _OFST,                            \
1038                     uint32_t, (_eqp)->eq_u32[1],                        \
1039                     uint32_t, (_eqp)->eq_u32[0]);                       \
1040         _NOTE(CONSTANTCONDITION)                                        \
1041         } while (B_FALSE)
1042
1043 #define EFX_BAR_TBL_WRITEQ(_enp, _reg, _index, _eqp)                    \
1044         do {                                                            \
1045                 EFX_CHECK_REG((_enp), (_reg));                          \
1046                 EFSYS_PROBE5(efx_bar_tbl_writeq, const char *, #_reg,   \
1047                     uint32_t, (_index),                                 \
1048                     uint32_t, _reg ## _OFST,                            \
1049                     uint32_t, (_eqp)->eq_u32[1],                        \
1050                     uint32_t, (_eqp)->eq_u32[0]);                       \
1051                 EFSYS_BAR_WRITEQ((_enp)->en_esbp,                       \
1052                     (_reg ## _OFST + ((_index) * _reg ## _STEP)),       \
1053                     (_eqp));                                            \
1054         _NOTE(CONSTANTCONDITION)                                        \
1055         } while (B_FALSE)
1056
1057 #define EFX_BAR_TBL_READO(_enp, _reg, _index, _eop, _lock)              \
1058         do {                                                            \
1059                 EFX_CHECK_REG((_enp), (_reg));                          \
1060                 EFSYS_BAR_READO((_enp)->en_esbp,                        \
1061                     (_reg ## _OFST + ((_index) * _reg ## _STEP)),       \
1062                     (_eop), (_lock));                                   \
1063                 EFSYS_PROBE7(efx_bar_tbl_reado, const char *, #_reg,    \
1064                     uint32_t, (_index),                                 \
1065                     uint32_t, _reg ## _OFST,                            \
1066                     uint32_t, (_eop)->eo_u32[3],                        \
1067                     uint32_t, (_eop)->eo_u32[2],                        \
1068                     uint32_t, (_eop)->eo_u32[1],                        \
1069                     uint32_t, (_eop)->eo_u32[0]);                       \
1070         _NOTE(CONSTANTCONDITION)                                        \
1071         } while (B_FALSE)
1072
1073 #define EFX_BAR_TBL_WRITEO(_enp, _reg, _index, _eop, _lock)             \
1074         do {                                                            \
1075                 EFX_CHECK_REG((_enp), (_reg));                          \
1076                 EFSYS_PROBE7(efx_bar_tbl_writeo, const char *, #_reg,   \
1077                     uint32_t, (_index),                                 \
1078                     uint32_t, _reg ## _OFST,                            \
1079                     uint32_t, (_eop)->eo_u32[3],                        \
1080                     uint32_t, (_eop)->eo_u32[2],                        \
1081                     uint32_t, (_eop)->eo_u32[1],                        \
1082                     uint32_t, (_eop)->eo_u32[0]);                       \
1083                 EFSYS_BAR_WRITEO((_enp)->en_esbp,                       \
1084                     (_reg ## _OFST + ((_index) * _reg ## _STEP)),       \
1085                     (_eop), (_lock));                                   \
1086         _NOTE(CONSTANTCONDITION)                                        \
1087         } while (B_FALSE)
1088
1089 /*
1090  * Accessors for memory BAR per-VI registers.
1091  *
1092  * The VI window size is 8KB for Medford and all earlier controllers.
1093  * For Medford2, the VI window size can be 8KB, 16KB or 64KB.
1094  */
1095
1096 #define EFX_BAR_VI_READD(_enp, _reg, _index, _edp, _lock)               \
1097         do {                                                            \
1098                 EFX_CHECK_REG((_enp), (_reg));                          \
1099                 EFSYS_BAR_READD((_enp)->en_esbp,                        \
1100                     ((_reg ## _OFST) +                                  \
1101                     ((_index) << (_enp)->en_nic_cfg.enc_vi_window_shift)), \
1102                     (_edp), (_lock));                                   \
1103                 EFSYS_PROBE4(efx_bar_vi_readd, const char *, #_reg,     \
1104                     uint32_t, (_index),                                 \
1105                     uint32_t, _reg ## _OFST,                            \
1106                     uint32_t, (_edp)->ed_u32[0]);                       \
1107         _NOTE(CONSTANTCONDITION)                                        \
1108         } while (B_FALSE)
1109
1110 #define EFX_BAR_VI_WRITED(_enp, _reg, _index, _edp, _lock)              \
1111         do {                                                            \
1112                 EFX_CHECK_REG((_enp), (_reg));                          \
1113                 EFSYS_PROBE4(efx_bar_vi_writed, const char *, #_reg,    \
1114                     uint32_t, (_index),                                 \
1115                     uint32_t, _reg ## _OFST,                            \
1116                     uint32_t, (_edp)->ed_u32[0]);                       \
1117                 EFSYS_BAR_WRITED((_enp)->en_esbp,                       \
1118                     ((_reg ## _OFST) +                                  \
1119                     ((_index) << (_enp)->en_nic_cfg.enc_vi_window_shift)), \
1120                     (_edp), (_lock));                                   \
1121         _NOTE(CONSTANTCONDITION)                                        \
1122         } while (B_FALSE)
1123
1124 #define EFX_BAR_VI_WRITED2(_enp, _reg, _index, _edp, _lock)             \
1125         do {                                                            \
1126                 EFX_CHECK_REG((_enp), (_reg));                          \
1127                 EFSYS_PROBE4(efx_bar_vi_writed, const char *, #_reg,    \
1128                     uint32_t, (_index),                                 \
1129                     uint32_t, _reg ## _OFST,                            \
1130                     uint32_t, (_edp)->ed_u32[0]);                       \
1131                 EFSYS_BAR_WRITED((_enp)->en_esbp,                       \
1132                     ((_reg ## _OFST) +                                  \
1133                     (2 * sizeof (efx_dword_t)) +                        \
1134                     ((_index) << (_enp)->en_nic_cfg.enc_vi_window_shift)), \
1135                     (_edp), (_lock));                                   \
1136         _NOTE(CONSTANTCONDITION)                                        \
1137         } while (B_FALSE)
1138
1139 /*
1140  * Allow drivers to perform optimised 128-bit VI doorbell writes.
1141  * The DMA descriptor pointers (RX_DESC_UPD and TX_DESC_UPD) are
1142  * special-cased in the BIU on the Falcon/Siena and EF10 architectures to avoid
1143  * the need for locking in the host, and are the only ones known to be safe to
1144  * use 128-bites write with.
1145  */
1146 #define EFX_BAR_VI_DOORBELL_WRITEO(_enp, _reg, _index, _eop)            \
1147         do {                                                            \
1148                 EFX_CHECK_REG((_enp), (_reg));                          \
1149                 EFSYS_PROBE7(efx_bar_vi_doorbell_writeo,                \
1150                     const char *, #_reg,                                \
1151                     uint32_t, (_index),                                 \
1152                     uint32_t, _reg ## _OFST,                            \
1153                     uint32_t, (_eop)->eo_u32[3],                        \
1154                     uint32_t, (_eop)->eo_u32[2],                        \
1155                     uint32_t, (_eop)->eo_u32[1],                        \
1156                     uint32_t, (_eop)->eo_u32[0]);                       \
1157                 EFSYS_BAR_DOORBELL_WRITEO((_enp)->en_esbp,              \
1158                     (_reg ## _OFST +                                    \
1159                     ((_index) << (_enp)->en_nic_cfg.enc_vi_window_shift)), \
1160                     (_eop));                                            \
1161         _NOTE(CONSTANTCONDITION)                                        \
1162         } while (B_FALSE)
1163
1164 #define EFX_DMA_SYNC_QUEUE_FOR_DEVICE(_esmp, _entries, _wptr, _owptr)   \
1165         do {                                                            \
1166                 unsigned int _new = (_wptr);                            \
1167                 unsigned int _old = (_owptr);                           \
1168                                                                         \
1169                 if ((_new) >= (_old))                                   \
1170                         EFSYS_DMA_SYNC_FOR_DEVICE((_esmp),              \
1171                             (_old) * sizeof (efx_desc_t),               \
1172                             ((_new) - (_old)) * sizeof (efx_desc_t));   \
1173                 else                                                    \
1174                         /*                                              \
1175                          * It is cheaper to sync entire map than sync   \
1176                          * two parts especially when offset/size are    \
1177                          * ignored and entire map is synced in any case.\
1178                          */                                             \
1179                         EFSYS_DMA_SYNC_FOR_DEVICE((_esmp),              \
1180                             0,                                          \
1181                             (_entries) * sizeof (efx_desc_t));          \
1182         _NOTE(CONSTANTCONDITION)                                        \
1183         } while (B_FALSE)
1184
1185 extern  __checkReturn   efx_rc_t
1186 efx_mac_select(
1187         __in            efx_nic_t *enp);
1188
1189 extern  void
1190 efx_mac_multicast_hash_compute(
1191         __in_ecount(6*count)            uint8_t const *addrs,
1192         __in                            int count,
1193         __out                           efx_oword_t *hash_low,
1194         __out                           efx_oword_t *hash_high);
1195
1196 extern  __checkReturn   efx_rc_t
1197 efx_phy_probe(
1198         __in            efx_nic_t *enp);
1199
1200 extern                  void
1201 efx_phy_unprobe(
1202         __in            efx_nic_t *enp);
1203
1204 #if EFSYS_OPT_VPD
1205
1206 /* VPD utility functions */
1207
1208 extern  __checkReturn           efx_rc_t
1209 efx_vpd_hunk_length(
1210         __in_bcount(size)       caddr_t data,
1211         __in                    size_t size,
1212         __out                   size_t *lengthp);
1213
1214 extern  __checkReturn           efx_rc_t
1215 efx_vpd_hunk_verify(
1216         __in_bcount(size)       caddr_t data,
1217         __in                    size_t size,
1218         __out_opt               boolean_t *cksummedp);
1219
1220 extern  __checkReturn           efx_rc_t
1221 efx_vpd_hunk_reinit(
1222         __in_bcount(size)       caddr_t data,
1223         __in                    size_t size,
1224         __in                    boolean_t wantpid);
1225
1226 extern  __checkReturn           efx_rc_t
1227 efx_vpd_hunk_get(
1228         __in_bcount(size)       caddr_t data,
1229         __in                    size_t size,
1230         __in                    efx_vpd_tag_t tag,
1231         __in                    efx_vpd_keyword_t keyword,
1232         __out                   unsigned int *payloadp,
1233         __out                   uint8_t *paylenp);
1234
1235 extern  __checkReturn                   efx_rc_t
1236 efx_vpd_hunk_next(
1237         __in_bcount(size)               caddr_t data,
1238         __in                            size_t size,
1239         __out                           efx_vpd_tag_t *tagp,
1240         __out                           efx_vpd_keyword_t *keyword,
1241         __out_opt                       unsigned int *payloadp,
1242         __out_opt                       uint8_t *paylenp,
1243         __inout                         unsigned int *contp);
1244
1245 extern  __checkReturn           efx_rc_t
1246 efx_vpd_hunk_set(
1247         __in_bcount(size)       caddr_t data,
1248         __in                    size_t size,
1249         __in                    efx_vpd_value_t *evvp);
1250
1251 #endif  /* EFSYS_OPT_VPD */
1252
1253 #if EFSYS_OPT_MCDI
1254
1255 extern  __checkReturn           efx_rc_t
1256 efx_mcdi_set_workaround(
1257         __in                    efx_nic_t *enp,
1258         __in                    uint32_t type,
1259         __in                    boolean_t enabled,
1260         __out_opt               uint32_t *flagsp);
1261
1262 extern  __checkReturn           efx_rc_t
1263 efx_mcdi_get_workarounds(
1264         __in                    efx_nic_t *enp,
1265         __out_opt               uint32_t *implementedp,
1266         __out_opt               uint32_t *enabledp);
1267
1268 #endif /* EFSYS_OPT_MCDI */
1269
1270 #if EFSYS_OPT_MAC_STATS
1271
1272 /*
1273  * Closed range of stats (i.e. the first and the last are included).
1274  * The last must be greater or equal (if the range is one item only) to
1275  * the first.
1276  */
1277 struct efx_mac_stats_range {
1278         efx_mac_stat_t          first;
1279         efx_mac_stat_t          last;
1280 };
1281
1282 extern                                  efx_rc_t
1283 efx_mac_stats_mask_add_ranges(
1284         __inout_bcount(mask_size)       uint32_t *maskp,
1285         __in                            size_t mask_size,
1286         __in_ecount(rng_count)          const struct efx_mac_stats_range *rngp,
1287         __in                            unsigned int rng_count);
1288
1289 #endif  /* EFSYS_OPT_MAC_STATS */
1290
1291 #ifdef  __cplusplus
1292 }
1293 #endif
1294
1295 #endif  /* _SYS_EFX_IMPL_H */