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