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