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