088a8968917b5f9697aa60ca3bc164c267b837f2
[dpdk.git] / drivers / net / sfc / base / efx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2006-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  */
6
7 #ifndef _SYS_EFX_H
8 #define _SYS_EFX_H
9
10 #include "efsys.h"
11 #include "efx_check.h"
12 #include "efx_phy_ids.h"
13
14 #ifdef  __cplusplus
15 extern "C" {
16 #endif
17
18 #define EFX_STATIC_ASSERT(_cond)                \
19         ((void)sizeof (char[(_cond) ? 1 : -1]))
20
21 #define EFX_ARRAY_SIZE(_array)                  \
22         (sizeof (_array) / sizeof ((_array)[0]))
23
24 #define EFX_FIELD_OFFSET(_type, _field)         \
25         ((size_t)&(((_type *)0)->_field))
26
27 /* The macro expands divider twice */
28 #define EFX_DIV_ROUND_UP(_n, _d)                (((_n) + (_d) - 1) / (_d))
29
30 /* Return codes */
31
32 typedef __success(return == 0) int efx_rc_t;
33
34
35 /* Chip families */
36
37 typedef enum efx_family_e {
38         EFX_FAMILY_INVALID,
39         EFX_FAMILY_FALCON,      /* Obsolete and not supported */
40         EFX_FAMILY_SIENA,
41         EFX_FAMILY_HUNTINGTON,
42         EFX_FAMILY_MEDFORD,
43         EFX_FAMILY_MEDFORD2,
44         EFX_FAMILY_NTYPES
45 } efx_family_t;
46
47 extern  __checkReturn   efx_rc_t
48 efx_family(
49         __in            uint16_t venid,
50         __in            uint16_t devid,
51         __out           efx_family_t *efp,
52         __out           unsigned int *membarp);
53
54
55 #define EFX_PCI_VENID_SFC                       0x1924
56
57 #define EFX_PCI_DEVID_FALCON                    0x0710  /* SFC4000 */
58
59 #define EFX_PCI_DEVID_BETHPAGE                  0x0803  /* SFC9020 */
60 #define EFX_PCI_DEVID_SIENA                     0x0813  /* SFL9021 */
61 #define EFX_PCI_DEVID_SIENA_F1_UNINIT           0x0810
62
63 #define EFX_PCI_DEVID_HUNTINGTON_PF_UNINIT      0x0901
64 #define EFX_PCI_DEVID_FARMINGDALE               0x0903  /* SFC9120 PF */
65 #define EFX_PCI_DEVID_GREENPORT                 0x0923  /* SFC9140 PF */
66
67 #define EFX_PCI_DEVID_FARMINGDALE_VF            0x1903  /* SFC9120 VF */
68 #define EFX_PCI_DEVID_GREENPORT_VF              0x1923  /* SFC9140 VF */
69
70 #define EFX_PCI_DEVID_MEDFORD_PF_UNINIT         0x0913
71 #define EFX_PCI_DEVID_MEDFORD                   0x0A03  /* SFC9240 PF */
72 #define EFX_PCI_DEVID_MEDFORD_VF                0x1A03  /* SFC9240 VF */
73
74 #define EFX_PCI_DEVID_MEDFORD2_PF_UNINIT        0x0B13
75 #define EFX_PCI_DEVID_MEDFORD2                  0x0B03  /* SFC9250 PF */
76 #define EFX_PCI_DEVID_MEDFORD2_VF               0x1B03  /* SFC9250 VF */
77
78
79 #define EFX_MEM_BAR_SIENA                       2
80
81 #define EFX_MEM_BAR_HUNTINGTON_PF               2
82 #define EFX_MEM_BAR_HUNTINGTON_VF               0
83
84 #define EFX_MEM_BAR_MEDFORD_PF                  2
85 #define EFX_MEM_BAR_MEDFORD_VF                  0
86
87 #define EFX_MEM_BAR_MEDFORD2                    0
88
89
90 /* Error codes */
91
92 enum {
93         EFX_ERR_INVALID,
94         EFX_ERR_SRAM_OOB,
95         EFX_ERR_BUFID_DC_OOB,
96         EFX_ERR_MEM_PERR,
97         EFX_ERR_RBUF_OWN,
98         EFX_ERR_TBUF_OWN,
99         EFX_ERR_RDESQ_OWN,
100         EFX_ERR_TDESQ_OWN,
101         EFX_ERR_EVQ_OWN,
102         EFX_ERR_EVFF_OFLO,
103         EFX_ERR_ILL_ADDR,
104         EFX_ERR_SRAM_PERR,
105         EFX_ERR_NCODES
106 };
107
108 /* Calculate the IEEE 802.3 CRC32 of a MAC addr */
109 extern  __checkReturn           uint32_t
110 efx_crc32_calculate(
111         __in                    uint32_t crc_init,
112         __in_ecount(length)     uint8_t const *input,
113         __in                    int length);
114
115
116 /* Type prototypes */
117
118 typedef struct efx_rxq_s        efx_rxq_t;
119
120 /* NIC */
121
122 typedef struct efx_nic_s        efx_nic_t;
123
124 extern  __checkReturn   efx_rc_t
125 efx_nic_create(
126         __in            efx_family_t family,
127         __in            efsys_identifier_t *esip,
128         __in            efsys_bar_t *esbp,
129         __in            efsys_lock_t *eslp,
130         __deref_out     efx_nic_t **enpp);
131
132 extern  __checkReturn   efx_rc_t
133 efx_nic_probe(
134         __in            efx_nic_t *enp);
135
136 extern  __checkReturn   efx_rc_t
137 efx_nic_init(
138         __in            efx_nic_t *enp);
139
140 extern  __checkReturn   efx_rc_t
141 efx_nic_reset(
142         __in            efx_nic_t *enp);
143
144 #if EFSYS_OPT_DIAG
145
146 extern  __checkReturn   efx_rc_t
147 efx_nic_register_test(
148         __in            efx_nic_t *enp);
149
150 #endif  /* EFSYS_OPT_DIAG */
151
152 extern          void
153 efx_nic_fini(
154         __in            efx_nic_t *enp);
155
156 extern          void
157 efx_nic_unprobe(
158         __in            efx_nic_t *enp);
159
160 extern          void
161 efx_nic_destroy(
162         __in    efx_nic_t *enp);
163
164 #define EFX_PCIE_LINK_SPEED_GEN1                1
165 #define EFX_PCIE_LINK_SPEED_GEN2                2
166 #define EFX_PCIE_LINK_SPEED_GEN3                3
167
168 typedef enum efx_pcie_link_performance_e {
169         EFX_PCIE_LINK_PERFORMANCE_UNKNOWN_BANDWIDTH,
170         EFX_PCIE_LINK_PERFORMANCE_SUBOPTIMAL_BANDWIDTH,
171         EFX_PCIE_LINK_PERFORMANCE_SUBOPTIMAL_LATENCY,
172         EFX_PCIE_LINK_PERFORMANCE_OPTIMAL
173 } efx_pcie_link_performance_t;
174
175 extern  __checkReturn   efx_rc_t
176 efx_nic_calculate_pcie_link_bandwidth(
177         __in            uint32_t pcie_link_width,
178         __in            uint32_t pcie_link_gen,
179         __out           uint32_t *bandwidth_mbpsp);
180
181 extern  __checkReturn   efx_rc_t
182 efx_nic_check_pcie_link_speed(
183         __in            efx_nic_t *enp,
184         __in            uint32_t pcie_link_width,
185         __in            uint32_t pcie_link_gen,
186         __out           efx_pcie_link_performance_t *resultp);
187
188 #if EFSYS_OPT_MCDI
189
190 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
191 /* Huntington and Medford require MCDIv2 commands */
192 #define WITH_MCDI_V2 1
193 #endif
194
195 typedef struct efx_mcdi_req_s efx_mcdi_req_t;
196
197 typedef enum efx_mcdi_exception_e {
198         EFX_MCDI_EXCEPTION_MC_REBOOT,
199         EFX_MCDI_EXCEPTION_MC_BADASSERT,
200 } efx_mcdi_exception_t;
201
202 #if EFSYS_OPT_MCDI_LOGGING
203 typedef enum efx_log_msg_e {
204         EFX_LOG_INVALID,
205         EFX_LOG_MCDI_REQUEST,
206         EFX_LOG_MCDI_RESPONSE,
207 } efx_log_msg_t;
208 #endif /* EFSYS_OPT_MCDI_LOGGING */
209
210 typedef struct efx_mcdi_transport_s {
211         void            *emt_context;
212         efsys_mem_t     *emt_dma_mem;
213         void            (*emt_execute)(void *, efx_mcdi_req_t *);
214         void            (*emt_ev_cpl)(void *);
215         void            (*emt_exception)(void *, efx_mcdi_exception_t);
216 #if EFSYS_OPT_MCDI_LOGGING
217         void            (*emt_logger)(void *, efx_log_msg_t,
218                                         void *, size_t, void *, size_t);
219 #endif /* EFSYS_OPT_MCDI_LOGGING */
220 #if EFSYS_OPT_MCDI_PROXY_AUTH
221         void            (*emt_ev_proxy_response)(void *, uint32_t, efx_rc_t);
222 #endif /* EFSYS_OPT_MCDI_PROXY_AUTH */
223 } efx_mcdi_transport_t;
224
225 extern  __checkReturn   efx_rc_t
226 efx_mcdi_init(
227         __in            efx_nic_t *enp,
228         __in            const efx_mcdi_transport_t *mtp);
229
230 extern  __checkReturn   efx_rc_t
231 efx_mcdi_reboot(
232         __in            efx_nic_t *enp);
233
234                         void
235 efx_mcdi_new_epoch(
236         __in            efx_nic_t *enp);
237
238 extern                  void
239 efx_mcdi_get_timeout(
240         __in            efx_nic_t *enp,
241         __in            efx_mcdi_req_t *emrp,
242         __out           uint32_t *usec_timeoutp);
243
244 extern                  void
245 efx_mcdi_request_start(
246         __in            efx_nic_t *enp,
247         __in            efx_mcdi_req_t *emrp,
248         __in            boolean_t ev_cpl);
249
250 extern  __checkReturn   boolean_t
251 efx_mcdi_request_poll(
252         __in            efx_nic_t *enp);
253
254 extern  __checkReturn   boolean_t
255 efx_mcdi_request_abort(
256         __in            efx_nic_t *enp);
257
258 extern                  void
259 efx_mcdi_fini(
260         __in            efx_nic_t *enp);
261
262 #endif  /* EFSYS_OPT_MCDI */
263
264 /* INTR */
265
266 #define EFX_NINTR_SIENA 1024
267
268 typedef enum efx_intr_type_e {
269         EFX_INTR_INVALID = 0,
270         EFX_INTR_LINE,
271         EFX_INTR_MESSAGE,
272         EFX_INTR_NTYPES
273 } efx_intr_type_t;
274
275 #define EFX_INTR_SIZE   (sizeof (efx_oword_t))
276
277 extern  __checkReturn   efx_rc_t
278 efx_intr_init(
279         __in            efx_nic_t *enp,
280         __in            efx_intr_type_t type,
281         __in            efsys_mem_t *esmp);
282
283 extern                  void
284 efx_intr_enable(
285         __in            efx_nic_t *enp);
286
287 extern                  void
288 efx_intr_disable(
289         __in            efx_nic_t *enp);
290
291 extern                  void
292 efx_intr_disable_unlocked(
293         __in            efx_nic_t *enp);
294
295 #define EFX_INTR_NEVQS  32
296
297 extern  __checkReturn   efx_rc_t
298 efx_intr_trigger(
299         __in            efx_nic_t *enp,
300         __in            unsigned int level);
301
302 extern                  void
303 efx_intr_status_line(
304         __in            efx_nic_t *enp,
305         __out           boolean_t *fatalp,
306         __out           uint32_t *maskp);
307
308 extern                  void
309 efx_intr_status_message(
310         __in            efx_nic_t *enp,
311         __in            unsigned int message,
312         __out           boolean_t *fatalp);
313
314 extern                  void
315 efx_intr_fatal(
316         __in            efx_nic_t *enp);
317
318 extern                  void
319 efx_intr_fini(
320         __in            efx_nic_t *enp);
321
322 /* MAC */
323
324 #if EFSYS_OPT_MAC_STATS
325
326 /* START MKCONFIG GENERATED EfxHeaderMacBlock 7d59c0d68431a5d1 */
327 typedef enum efx_mac_stat_e {
328         EFX_MAC_RX_OCTETS,
329         EFX_MAC_RX_PKTS,
330         EFX_MAC_RX_UNICST_PKTS,
331         EFX_MAC_RX_MULTICST_PKTS,
332         EFX_MAC_RX_BRDCST_PKTS,
333         EFX_MAC_RX_PAUSE_PKTS,
334         EFX_MAC_RX_LE_64_PKTS,
335         EFX_MAC_RX_65_TO_127_PKTS,
336         EFX_MAC_RX_128_TO_255_PKTS,
337         EFX_MAC_RX_256_TO_511_PKTS,
338         EFX_MAC_RX_512_TO_1023_PKTS,
339         EFX_MAC_RX_1024_TO_15XX_PKTS,
340         EFX_MAC_RX_GE_15XX_PKTS,
341         EFX_MAC_RX_ERRORS,
342         EFX_MAC_RX_FCS_ERRORS,
343         EFX_MAC_RX_DROP_EVENTS,
344         EFX_MAC_RX_FALSE_CARRIER_ERRORS,
345         EFX_MAC_RX_SYMBOL_ERRORS,
346         EFX_MAC_RX_ALIGN_ERRORS,
347         EFX_MAC_RX_INTERNAL_ERRORS,
348         EFX_MAC_RX_JABBER_PKTS,
349         EFX_MAC_RX_LANE0_CHAR_ERR,
350         EFX_MAC_RX_LANE1_CHAR_ERR,
351         EFX_MAC_RX_LANE2_CHAR_ERR,
352         EFX_MAC_RX_LANE3_CHAR_ERR,
353         EFX_MAC_RX_LANE0_DISP_ERR,
354         EFX_MAC_RX_LANE1_DISP_ERR,
355         EFX_MAC_RX_LANE2_DISP_ERR,
356         EFX_MAC_RX_LANE3_DISP_ERR,
357         EFX_MAC_RX_MATCH_FAULT,
358         EFX_MAC_RX_NODESC_DROP_CNT,
359         EFX_MAC_TX_OCTETS,
360         EFX_MAC_TX_PKTS,
361         EFX_MAC_TX_UNICST_PKTS,
362         EFX_MAC_TX_MULTICST_PKTS,
363         EFX_MAC_TX_BRDCST_PKTS,
364         EFX_MAC_TX_PAUSE_PKTS,
365         EFX_MAC_TX_LE_64_PKTS,
366         EFX_MAC_TX_65_TO_127_PKTS,
367         EFX_MAC_TX_128_TO_255_PKTS,
368         EFX_MAC_TX_256_TO_511_PKTS,
369         EFX_MAC_TX_512_TO_1023_PKTS,
370         EFX_MAC_TX_1024_TO_15XX_PKTS,
371         EFX_MAC_TX_GE_15XX_PKTS,
372         EFX_MAC_TX_ERRORS,
373         EFX_MAC_TX_SGL_COL_PKTS,
374         EFX_MAC_TX_MULT_COL_PKTS,
375         EFX_MAC_TX_EX_COL_PKTS,
376         EFX_MAC_TX_LATE_COL_PKTS,
377         EFX_MAC_TX_DEF_PKTS,
378         EFX_MAC_TX_EX_DEF_PKTS,
379         EFX_MAC_PM_TRUNC_BB_OVERFLOW,
380         EFX_MAC_PM_DISCARD_BB_OVERFLOW,
381         EFX_MAC_PM_TRUNC_VFIFO_FULL,
382         EFX_MAC_PM_DISCARD_VFIFO_FULL,
383         EFX_MAC_PM_TRUNC_QBB,
384         EFX_MAC_PM_DISCARD_QBB,
385         EFX_MAC_PM_DISCARD_MAPPING,
386         EFX_MAC_RXDP_Q_DISABLED_PKTS,
387         EFX_MAC_RXDP_DI_DROPPED_PKTS,
388         EFX_MAC_RXDP_STREAMING_PKTS,
389         EFX_MAC_RXDP_HLB_FETCH,
390         EFX_MAC_RXDP_HLB_WAIT,
391         EFX_MAC_VADAPTER_RX_UNICAST_PACKETS,
392         EFX_MAC_VADAPTER_RX_UNICAST_BYTES,
393         EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS,
394         EFX_MAC_VADAPTER_RX_MULTICAST_BYTES,
395         EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS,
396         EFX_MAC_VADAPTER_RX_BROADCAST_BYTES,
397         EFX_MAC_VADAPTER_RX_BAD_PACKETS,
398         EFX_MAC_VADAPTER_RX_BAD_BYTES,
399         EFX_MAC_VADAPTER_RX_OVERFLOW,
400         EFX_MAC_VADAPTER_TX_UNICAST_PACKETS,
401         EFX_MAC_VADAPTER_TX_UNICAST_BYTES,
402         EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS,
403         EFX_MAC_VADAPTER_TX_MULTICAST_BYTES,
404         EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS,
405         EFX_MAC_VADAPTER_TX_BROADCAST_BYTES,
406         EFX_MAC_VADAPTER_TX_BAD_PACKETS,
407         EFX_MAC_VADAPTER_TX_BAD_BYTES,
408         EFX_MAC_VADAPTER_TX_OVERFLOW,
409         EFX_MAC_FEC_UNCORRECTED_ERRORS,
410         EFX_MAC_FEC_CORRECTED_ERRORS,
411         EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE0,
412         EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE1,
413         EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE2,
414         EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE3,
415         EFX_MAC_CTPIO_VI_BUSY_FALLBACK,
416         EFX_MAC_CTPIO_LONG_WRITE_SUCCESS,
417         EFX_MAC_CTPIO_MISSING_DBELL_FAIL,
418         EFX_MAC_CTPIO_OVERFLOW_FAIL,
419         EFX_MAC_CTPIO_UNDERFLOW_FAIL,
420         EFX_MAC_CTPIO_TIMEOUT_FAIL,
421         EFX_MAC_CTPIO_NONCONTIG_WR_FAIL,
422         EFX_MAC_CTPIO_FRM_CLOBBER_FAIL,
423         EFX_MAC_CTPIO_INVALID_WR_FAIL,
424         EFX_MAC_CTPIO_VI_CLOBBER_FALLBACK,
425         EFX_MAC_CTPIO_UNQUALIFIED_FALLBACK,
426         EFX_MAC_CTPIO_RUNT_FALLBACK,
427         EFX_MAC_CTPIO_SUCCESS,
428         EFX_MAC_CTPIO_FALLBACK,
429         EFX_MAC_CTPIO_POISON,
430         EFX_MAC_CTPIO_ERASE,
431         EFX_MAC_NSTATS
432 } efx_mac_stat_t;
433
434 /* END MKCONFIG GENERATED EfxHeaderMacBlock */
435
436 #endif  /* EFSYS_OPT_MAC_STATS */
437
438 typedef enum efx_link_mode_e {
439         EFX_LINK_UNKNOWN = 0,
440         EFX_LINK_DOWN,
441         EFX_LINK_10HDX,
442         EFX_LINK_10FDX,
443         EFX_LINK_100HDX,
444         EFX_LINK_100FDX,
445         EFX_LINK_1000HDX,
446         EFX_LINK_1000FDX,
447         EFX_LINK_10000FDX,
448         EFX_LINK_40000FDX,
449         EFX_LINK_25000FDX,
450         EFX_LINK_50000FDX,
451         EFX_LINK_100000FDX,
452         EFX_LINK_NMODES
453 } efx_link_mode_t;
454
455 #define EFX_MAC_ADDR_LEN 6
456
457 #define EFX_MAC_ADDR_IS_MULTICAST(_address) (((uint8_t *)_address)[0] & 0x01)
458
459 #define EFX_MAC_MULTICAST_LIST_MAX      256
460
461 #define EFX_MAC_SDU_MAX 9202
462
463 #define EFX_MAC_PDU_ADJUSTMENT                                  \
464         (/* EtherII */ 14                                       \
465             + /* VLAN */ 4                                      \
466             + /* CRC */ 4                                       \
467             + /* bug16011 */ 16)                                \
468
469 #define EFX_MAC_PDU(_sdu)                                       \
470         P2ROUNDUP((_sdu) + EFX_MAC_PDU_ADJUSTMENT, 8)
471
472 /*
473  * Due to the P2ROUNDUP in EFX_MAC_PDU(), EFX_MAC_SDU_FROM_PDU() may give
474  * the SDU rounded up slightly.
475  */
476 #define EFX_MAC_SDU_FROM_PDU(_pdu)      ((_pdu) - EFX_MAC_PDU_ADJUSTMENT)
477
478 #define EFX_MAC_PDU_MIN 60
479 #define EFX_MAC_PDU_MAX EFX_MAC_PDU(EFX_MAC_SDU_MAX)
480
481 extern  __checkReturn   efx_rc_t
482 efx_mac_pdu_get(
483         __in            efx_nic_t *enp,
484         __out           size_t *pdu);
485
486 extern  __checkReturn   efx_rc_t
487 efx_mac_pdu_set(
488         __in            efx_nic_t *enp,
489         __in            size_t pdu);
490
491 extern  __checkReturn   efx_rc_t
492 efx_mac_addr_set(
493         __in            efx_nic_t *enp,
494         __in            uint8_t *addr);
495
496 extern  __checkReturn                   efx_rc_t
497 efx_mac_filter_set(
498         __in                            efx_nic_t *enp,
499         __in                            boolean_t all_unicst,
500         __in                            boolean_t mulcst,
501         __in                            boolean_t all_mulcst,
502         __in                            boolean_t brdcst);
503
504 extern  __checkReturn   efx_rc_t
505 efx_mac_multicast_list_set(
506         __in                            efx_nic_t *enp,
507         __in_ecount(6*count)            uint8_t const *addrs,
508         __in                            int count);
509
510 extern  __checkReturn   efx_rc_t
511 efx_mac_filter_default_rxq_set(
512         __in            efx_nic_t *enp,
513         __in            efx_rxq_t *erp,
514         __in            boolean_t using_rss);
515
516 extern                  void
517 efx_mac_filter_default_rxq_clear(
518         __in            efx_nic_t *enp);
519
520 extern  __checkReturn   efx_rc_t
521 efx_mac_drain(
522         __in            efx_nic_t *enp,
523         __in            boolean_t enabled);
524
525 extern  __checkReturn   efx_rc_t
526 efx_mac_up(
527         __in            efx_nic_t *enp,
528         __out           boolean_t *mac_upp);
529
530 #define EFX_FCNTL_RESPOND       0x00000001
531 #define EFX_FCNTL_GENERATE      0x00000002
532
533 extern  __checkReturn   efx_rc_t
534 efx_mac_fcntl_set(
535         __in            efx_nic_t *enp,
536         __in            unsigned int fcntl,
537         __in            boolean_t autoneg);
538
539 extern                  void
540 efx_mac_fcntl_get(
541         __in            efx_nic_t *enp,
542         __out           unsigned int *fcntl_wantedp,
543         __out           unsigned int *fcntl_linkp);
544
545
546 #if EFSYS_OPT_MAC_STATS
547
548 #if EFSYS_OPT_NAMES
549
550 extern  __checkReturn                   const char *
551 efx_mac_stat_name(
552         __in                            efx_nic_t *enp,
553         __in                            unsigned int id);
554
555 #endif  /* EFSYS_OPT_NAMES */
556
557 #define EFX_MAC_STATS_MASK_BITS_PER_PAGE        (8 * sizeof (uint32_t))
558
559 #define EFX_MAC_STATS_MASK_NPAGES       \
560         (P2ROUNDUP(EFX_MAC_NSTATS, EFX_MAC_STATS_MASK_BITS_PER_PAGE) / \
561             EFX_MAC_STATS_MASK_BITS_PER_PAGE)
562
563 /*
564  * Get mask of MAC statistics supported by the hardware.
565  *
566  * If mask_size is insufficient to return the mask, EINVAL error is
567  * returned. EFX_MAC_STATS_MASK_NPAGES multiplied by size of the page
568  * (which is sizeof (uint32_t)) is sufficient.
569  */
570 extern  __checkReturn                   efx_rc_t
571 efx_mac_stats_get_mask(
572         __in                            efx_nic_t *enp,
573         __out_bcount(mask_size)         uint32_t *maskp,
574         __in                            size_t mask_size);
575
576 #define EFX_MAC_STAT_SUPPORTED(_mask, _stat)    \
577         ((_mask)[(_stat) / EFX_MAC_STATS_MASK_BITS_PER_PAGE] &  \
578             (1ULL << ((_stat) & (EFX_MAC_STATS_MASK_BITS_PER_PAGE - 1))))
579
580
581 extern  __checkReturn                   efx_rc_t
582 efx_mac_stats_clear(
583         __in                            efx_nic_t *enp);
584
585 /*
586  * Upload mac statistics supported by the hardware into the given buffer.
587  *
588  * The DMA buffer must be 4Kbyte aligned and sized to hold at least
589  * efx_nic_cfg_t::enc_mac_stats_nstats 64bit counters.
590  *
591  * The hardware will only DMA statistics that it understands (of course).
592  * Drivers should not make any assumptions about which statistics are
593  * supported, especially when the statistics are generated by firmware.
594  *
595  * Thus, drivers should zero this buffer before use, so that not-understood
596  * statistics read back as zero.
597  */
598 extern  __checkReturn                   efx_rc_t
599 efx_mac_stats_upload(
600         __in                            efx_nic_t *enp,
601         __in                            efsys_mem_t *esmp);
602
603 extern  __checkReturn                   efx_rc_t
604 efx_mac_stats_periodic(
605         __in                            efx_nic_t *enp,
606         __in                            efsys_mem_t *esmp,
607         __in                            uint16_t period_ms,
608         __in                            boolean_t events);
609
610 extern  __checkReturn                   efx_rc_t
611 efx_mac_stats_update(
612         __in                            efx_nic_t *enp,
613         __in                            efsys_mem_t *esmp,
614         __inout_ecount(EFX_MAC_NSTATS)  efsys_stat_t *stat,
615         __inout_opt                     uint32_t *generationp);
616
617 #endif  /* EFSYS_OPT_MAC_STATS */
618
619 /* MON */
620
621 typedef enum efx_mon_type_e {
622         EFX_MON_INVALID = 0,
623         EFX_MON_SFC90X0,
624         EFX_MON_SFC91X0,
625         EFX_MON_SFC92X0,
626         EFX_MON_NTYPES
627 } efx_mon_type_t;
628
629 #if EFSYS_OPT_NAMES
630
631 extern          const char *
632 efx_mon_name(
633         __in    efx_nic_t *enp);
634
635 #endif  /* EFSYS_OPT_NAMES */
636
637 extern  __checkReturn   efx_rc_t
638 efx_mon_init(
639         __in            efx_nic_t *enp);
640
641 #if EFSYS_OPT_MON_STATS
642
643 #define EFX_MON_STATS_PAGE_SIZE 0x100
644 #define EFX_MON_MASK_ELEMENT_SIZE 32
645
646 /* START MKCONFIG GENERATED MonitorHeaderStatsBlock 400fdb0517af1fca */
647 typedef enum efx_mon_stat_e {
648         EFX_MON_STAT_2_5V,
649         EFX_MON_STAT_VCCP1,
650         EFX_MON_STAT_VCC,
651         EFX_MON_STAT_5V,
652         EFX_MON_STAT_12V,
653         EFX_MON_STAT_VCCP2,
654         EFX_MON_STAT_EXT_TEMP,
655         EFX_MON_STAT_INT_TEMP,
656         EFX_MON_STAT_AIN1,
657         EFX_MON_STAT_AIN2,
658         EFX_MON_STAT_INT_COOLING,
659         EFX_MON_STAT_EXT_COOLING,
660         EFX_MON_STAT_1V,
661         EFX_MON_STAT_1_2V,
662         EFX_MON_STAT_1_8V,
663         EFX_MON_STAT_3_3V,
664         EFX_MON_STAT_1_2VA,
665         EFX_MON_STAT_VREF,
666         EFX_MON_STAT_VAOE,
667         EFX_MON_STAT_AOE_TEMP,
668         EFX_MON_STAT_PSU_AOE_TEMP,
669         EFX_MON_STAT_PSU_TEMP,
670         EFX_MON_STAT_FAN0,
671         EFX_MON_STAT_FAN1,
672         EFX_MON_STAT_FAN2,
673         EFX_MON_STAT_FAN3,
674         EFX_MON_STAT_FAN4,
675         EFX_MON_STAT_VAOE_IN,
676         EFX_MON_STAT_IAOE,
677         EFX_MON_STAT_IAOE_IN,
678         EFX_MON_STAT_NIC_POWER,
679         EFX_MON_STAT_0_9V,
680         EFX_MON_STAT_I0_9V,
681         EFX_MON_STAT_I1_2V,
682         EFX_MON_STAT_0_9V_ADC,
683         EFX_MON_STAT_INT_TEMP2,
684         EFX_MON_STAT_VREG_TEMP,
685         EFX_MON_STAT_VREG_0_9V_TEMP,
686         EFX_MON_STAT_VREG_1_2V_TEMP,
687         EFX_MON_STAT_INT_VPTAT,
688         EFX_MON_STAT_INT_ADC_TEMP,
689         EFX_MON_STAT_EXT_VPTAT,
690         EFX_MON_STAT_EXT_ADC_TEMP,
691         EFX_MON_STAT_AMBIENT_TEMP,
692         EFX_MON_STAT_AIRFLOW,
693         EFX_MON_STAT_VDD08D_VSS08D_CSR,
694         EFX_MON_STAT_VDD08D_VSS08D_CSR_EXTADC,
695         EFX_MON_STAT_HOTPOINT_TEMP,
696         EFX_MON_STAT_PHY_POWER_SWITCH_PORT0,
697         EFX_MON_STAT_PHY_POWER_SWITCH_PORT1,
698         EFX_MON_STAT_MUM_VCC,
699         EFX_MON_STAT_0V9_A,
700         EFX_MON_STAT_I0V9_A,
701         EFX_MON_STAT_0V9_A_TEMP,
702         EFX_MON_STAT_0V9_B,
703         EFX_MON_STAT_I0V9_B,
704         EFX_MON_STAT_0V9_B_TEMP,
705         EFX_MON_STAT_CCOM_AVREG_1V2_SUPPLY,
706         EFX_MON_STAT_CCOM_AVREG_1V2_SUPPLY_EXT_ADC,
707         EFX_MON_STAT_CCOM_AVREG_1V8_SUPPLY,
708         EFX_MON_STAT_CCOM_AVREG_1V8_SUPPLY_EXT_ADC,
709         EFX_MON_STAT_CONTROLLER_MASTER_VPTAT,
710         EFX_MON_STAT_CONTROLLER_MASTER_INTERNAL_TEMP,
711         EFX_MON_STAT_CONTROLLER_MASTER_VPTAT_EXT_ADC,
712         EFX_MON_STAT_CONTROLLER_MASTER_INTERNAL_TEMP_EXT_ADC,
713         EFX_MON_STAT_CONTROLLER_SLAVE_VPTAT,
714         EFX_MON_STAT_CONTROLLER_SLAVE_INTERNAL_TEMP,
715         EFX_MON_STAT_CONTROLLER_SLAVE_VPTAT_EXT_ADC,
716         EFX_MON_STAT_CONTROLLER_SLAVE_INTERNAL_TEMP_EXT_ADC,
717         EFX_MON_STAT_SODIMM_VOUT,
718         EFX_MON_STAT_SODIMM_0_TEMP,
719         EFX_MON_STAT_SODIMM_1_TEMP,
720         EFX_MON_STAT_PHY0_VCC,
721         EFX_MON_STAT_PHY1_VCC,
722         EFX_MON_STAT_CONTROLLER_TDIODE_TEMP,
723         EFX_MON_STAT_BOARD_FRONT_TEMP,
724         EFX_MON_STAT_BOARD_BACK_TEMP,
725         EFX_MON_STAT_I1V8,
726         EFX_MON_STAT_I2V5,
727         EFX_MON_STAT_I3V3,
728         EFX_MON_STAT_I12V0,
729         EFX_MON_STAT_1_3V,
730         EFX_MON_STAT_I1V3,
731         EFX_MON_NSTATS
732 } efx_mon_stat_t;
733
734 /* END MKCONFIG GENERATED MonitorHeaderStatsBlock */
735
736 typedef enum efx_mon_stat_state_e {
737         EFX_MON_STAT_STATE_OK = 0,
738         EFX_MON_STAT_STATE_WARNING = 1,
739         EFX_MON_STAT_STATE_FATAL = 2,
740         EFX_MON_STAT_STATE_BROKEN = 3,
741         EFX_MON_STAT_STATE_NO_READING = 4,
742 } efx_mon_stat_state_t;
743
744 typedef struct efx_mon_stat_value_s {
745         uint16_t        emsv_value;
746         uint16_t        emsv_state;
747 } efx_mon_stat_value_t;
748
749 #if EFSYS_OPT_NAMES
750
751 extern                                  const char *
752 efx_mon_stat_name(
753         __in                            efx_nic_t *enp,
754         __in                            efx_mon_stat_t id);
755
756 #endif  /* EFSYS_OPT_NAMES */
757
758 extern  __checkReturn                   efx_rc_t
759 efx_mon_stats_update(
760         __in                            efx_nic_t *enp,
761         __in                            efsys_mem_t *esmp,
762         __inout_ecount(EFX_MON_NSTATS)  efx_mon_stat_value_t *values);
763
764 #endif  /* EFSYS_OPT_MON_STATS */
765
766 extern          void
767 efx_mon_fini(
768         __in    efx_nic_t *enp);
769
770 /* PHY */
771
772 extern  __checkReturn   efx_rc_t
773 efx_phy_verify(
774         __in            efx_nic_t *enp);
775
776 #if EFSYS_OPT_PHY_LED_CONTROL
777
778 typedef enum efx_phy_led_mode_e {
779         EFX_PHY_LED_DEFAULT = 0,
780         EFX_PHY_LED_OFF,
781         EFX_PHY_LED_ON,
782         EFX_PHY_LED_FLASH,
783         EFX_PHY_LED_NMODES
784 } efx_phy_led_mode_t;
785
786 extern  __checkReturn   efx_rc_t
787 efx_phy_led_set(
788         __in    efx_nic_t *enp,
789         __in    efx_phy_led_mode_t mode);
790
791 #endif  /* EFSYS_OPT_PHY_LED_CONTROL */
792
793 extern  __checkReturn   efx_rc_t
794 efx_port_init(
795         __in            efx_nic_t *enp);
796
797 #if EFSYS_OPT_LOOPBACK
798
799 typedef enum efx_loopback_type_e {
800         EFX_LOOPBACK_OFF = 0,
801         EFX_LOOPBACK_DATA = 1,
802         EFX_LOOPBACK_GMAC = 2,
803         EFX_LOOPBACK_XGMII = 3,
804         EFX_LOOPBACK_XGXS = 4,
805         EFX_LOOPBACK_XAUI = 5,
806         EFX_LOOPBACK_GMII = 6,
807         EFX_LOOPBACK_SGMII = 7,
808         EFX_LOOPBACK_XGBR = 8,
809         EFX_LOOPBACK_XFI = 9,
810         EFX_LOOPBACK_XAUI_FAR = 10,
811         EFX_LOOPBACK_GMII_FAR = 11,
812         EFX_LOOPBACK_SGMII_FAR = 12,
813         EFX_LOOPBACK_XFI_FAR = 13,
814         EFX_LOOPBACK_GPHY = 14,
815         EFX_LOOPBACK_PHY_XS = 15,
816         EFX_LOOPBACK_PCS = 16,
817         EFX_LOOPBACK_PMA_PMD = 17,
818         EFX_LOOPBACK_XPORT = 18,
819         EFX_LOOPBACK_XGMII_WS = 19,
820         EFX_LOOPBACK_XAUI_WS = 20,
821         EFX_LOOPBACK_XAUI_WS_FAR = 21,
822         EFX_LOOPBACK_XAUI_WS_NEAR = 22,
823         EFX_LOOPBACK_GMII_WS = 23,
824         EFX_LOOPBACK_XFI_WS = 24,
825         EFX_LOOPBACK_XFI_WS_FAR = 25,
826         EFX_LOOPBACK_PHYXS_WS = 26,
827         EFX_LOOPBACK_PMA_INT = 27,
828         EFX_LOOPBACK_SD_NEAR = 28,
829         EFX_LOOPBACK_SD_FAR = 29,
830         EFX_LOOPBACK_PMA_INT_WS = 30,
831         EFX_LOOPBACK_SD_FEP2_WS = 31,
832         EFX_LOOPBACK_SD_FEP1_5_WS = 32,
833         EFX_LOOPBACK_SD_FEP_WS = 33,
834         EFX_LOOPBACK_SD_FES_WS = 34,
835         EFX_LOOPBACK_AOE_INT_NEAR = 35,
836         EFX_LOOPBACK_DATA_WS = 36,
837         EFX_LOOPBACK_FORCE_EXT_LINK = 37,
838         EFX_LOOPBACK_NTYPES
839 } efx_loopback_type_t;
840
841 typedef enum efx_loopback_kind_e {
842         EFX_LOOPBACK_KIND_OFF = 0,
843         EFX_LOOPBACK_KIND_ALL,
844         EFX_LOOPBACK_KIND_MAC,
845         EFX_LOOPBACK_KIND_PHY,
846         EFX_LOOPBACK_NKINDS
847 } efx_loopback_kind_t;
848
849 extern                  void
850 efx_loopback_mask(
851         __in    efx_loopback_kind_t loopback_kind,
852         __out   efx_qword_t *maskp);
853
854 extern  __checkReturn   efx_rc_t
855 efx_port_loopback_set(
856         __in    efx_nic_t *enp,
857         __in    efx_link_mode_t link_mode,
858         __in    efx_loopback_type_t type);
859
860 #if EFSYS_OPT_NAMES
861
862 extern  __checkReturn   const char *
863 efx_loopback_type_name(
864         __in            efx_nic_t *enp,
865         __in            efx_loopback_type_t type);
866
867 #endif  /* EFSYS_OPT_NAMES */
868
869 #endif  /* EFSYS_OPT_LOOPBACK */
870
871 extern  __checkReturn   efx_rc_t
872 efx_port_poll(
873         __in            efx_nic_t *enp,
874         __out_opt       efx_link_mode_t *link_modep);
875
876 extern          void
877 efx_port_fini(
878         __in    efx_nic_t *enp);
879
880 typedef enum efx_phy_cap_type_e {
881         EFX_PHY_CAP_INVALID = 0,
882         EFX_PHY_CAP_10HDX,
883         EFX_PHY_CAP_10FDX,
884         EFX_PHY_CAP_100HDX,
885         EFX_PHY_CAP_100FDX,
886         EFX_PHY_CAP_1000HDX,
887         EFX_PHY_CAP_1000FDX,
888         EFX_PHY_CAP_10000FDX,
889         EFX_PHY_CAP_PAUSE,
890         EFX_PHY_CAP_ASYM,
891         EFX_PHY_CAP_AN,
892         EFX_PHY_CAP_40000FDX,
893         EFX_PHY_CAP_DDM,
894         EFX_PHY_CAP_100000FDX,
895         EFX_PHY_CAP_25000FDX,
896         EFX_PHY_CAP_50000FDX,
897         EFX_PHY_CAP_BASER_FEC,
898         EFX_PHY_CAP_BASER_FEC_REQUESTED,
899         EFX_PHY_CAP_RS_FEC,
900         EFX_PHY_CAP_RS_FEC_REQUESTED,
901         EFX_PHY_CAP_25G_BASER_FEC,
902         EFX_PHY_CAP_25G_BASER_FEC_REQUESTED,
903         EFX_PHY_CAP_NTYPES
904 } efx_phy_cap_type_t;
905
906
907 #define EFX_PHY_CAP_CURRENT     0x00000000
908 #define EFX_PHY_CAP_DEFAULT     0x00000001
909 #define EFX_PHY_CAP_PERM        0x00000002
910
911 extern          void
912 efx_phy_adv_cap_get(
913         __in            efx_nic_t *enp,
914         __in            uint32_t flag,
915         __out           uint32_t *maskp);
916
917 extern  __checkReturn   efx_rc_t
918 efx_phy_adv_cap_set(
919         __in            efx_nic_t *enp,
920         __in            uint32_t mask);
921
922 extern                  void
923 efx_phy_lp_cap_get(
924         __in            efx_nic_t *enp,
925         __out           uint32_t *maskp);
926
927 extern  __checkReturn   efx_rc_t
928 efx_phy_oui_get(
929         __in            efx_nic_t *enp,
930         __out           uint32_t *ouip);
931
932 typedef enum efx_phy_media_type_e {
933         EFX_PHY_MEDIA_INVALID = 0,
934         EFX_PHY_MEDIA_XAUI,
935         EFX_PHY_MEDIA_CX4,
936         EFX_PHY_MEDIA_KX4,
937         EFX_PHY_MEDIA_XFP,
938         EFX_PHY_MEDIA_SFP_PLUS,
939         EFX_PHY_MEDIA_BASE_T,
940         EFX_PHY_MEDIA_QSFP_PLUS,
941         EFX_PHY_MEDIA_NTYPES
942 } efx_phy_media_type_t;
943
944 /*
945  * Get the type of medium currently used.  If the board has ports for
946  * modules, a module is present, and we recognise the media type of
947  * the module, then this will be the media type of the module.
948  * Otherwise it will be the media type of the port.
949  */
950 extern                  void
951 efx_phy_media_type_get(
952         __in            efx_nic_t *enp,
953         __out           efx_phy_media_type_t *typep);
954
955 extern  __checkReturn           efx_rc_t
956 efx_phy_module_get_info(
957         __in                    efx_nic_t *enp,
958         __in                    uint8_t dev_addr,
959         __in                    uint8_t offset,
960         __in                    uint8_t len,
961         __out_bcount(len)       uint8_t *data);
962
963 #if EFSYS_OPT_PHY_STATS
964
965 /* START MKCONFIG GENERATED PhyHeaderStatsBlock 30ed56ad501f8e36 */
966 typedef enum efx_phy_stat_e {
967         EFX_PHY_STAT_OUI,
968         EFX_PHY_STAT_PMA_PMD_LINK_UP,
969         EFX_PHY_STAT_PMA_PMD_RX_FAULT,
970         EFX_PHY_STAT_PMA_PMD_TX_FAULT,
971         EFX_PHY_STAT_PMA_PMD_REV_A,
972         EFX_PHY_STAT_PMA_PMD_REV_B,
973         EFX_PHY_STAT_PMA_PMD_REV_C,
974         EFX_PHY_STAT_PMA_PMD_REV_D,
975         EFX_PHY_STAT_PCS_LINK_UP,
976         EFX_PHY_STAT_PCS_RX_FAULT,
977         EFX_PHY_STAT_PCS_TX_FAULT,
978         EFX_PHY_STAT_PCS_BER,
979         EFX_PHY_STAT_PCS_BLOCK_ERRORS,
980         EFX_PHY_STAT_PHY_XS_LINK_UP,
981         EFX_PHY_STAT_PHY_XS_RX_FAULT,
982         EFX_PHY_STAT_PHY_XS_TX_FAULT,
983         EFX_PHY_STAT_PHY_XS_ALIGN,
984         EFX_PHY_STAT_PHY_XS_SYNC_A,
985         EFX_PHY_STAT_PHY_XS_SYNC_B,
986         EFX_PHY_STAT_PHY_XS_SYNC_C,
987         EFX_PHY_STAT_PHY_XS_SYNC_D,
988         EFX_PHY_STAT_AN_LINK_UP,
989         EFX_PHY_STAT_AN_MASTER,
990         EFX_PHY_STAT_AN_LOCAL_RX_OK,
991         EFX_PHY_STAT_AN_REMOTE_RX_OK,
992         EFX_PHY_STAT_CL22EXT_LINK_UP,
993         EFX_PHY_STAT_SNR_A,
994         EFX_PHY_STAT_SNR_B,
995         EFX_PHY_STAT_SNR_C,
996         EFX_PHY_STAT_SNR_D,
997         EFX_PHY_STAT_PMA_PMD_SIGNAL_A,
998         EFX_PHY_STAT_PMA_PMD_SIGNAL_B,
999         EFX_PHY_STAT_PMA_PMD_SIGNAL_C,
1000         EFX_PHY_STAT_PMA_PMD_SIGNAL_D,
1001         EFX_PHY_STAT_AN_COMPLETE,
1002         EFX_PHY_STAT_PMA_PMD_REV_MAJOR,
1003         EFX_PHY_STAT_PMA_PMD_REV_MINOR,
1004         EFX_PHY_STAT_PMA_PMD_REV_MICRO,
1005         EFX_PHY_STAT_PCS_FW_VERSION_0,
1006         EFX_PHY_STAT_PCS_FW_VERSION_1,
1007         EFX_PHY_STAT_PCS_FW_VERSION_2,
1008         EFX_PHY_STAT_PCS_FW_VERSION_3,
1009         EFX_PHY_STAT_PCS_FW_BUILD_YY,
1010         EFX_PHY_STAT_PCS_FW_BUILD_MM,
1011         EFX_PHY_STAT_PCS_FW_BUILD_DD,
1012         EFX_PHY_STAT_PCS_OP_MODE,
1013         EFX_PHY_NSTATS
1014 } efx_phy_stat_t;
1015
1016 /* END MKCONFIG GENERATED PhyHeaderStatsBlock */
1017
1018 #if EFSYS_OPT_NAMES
1019
1020 extern                                  const char *
1021 efx_phy_stat_name(
1022         __in                            efx_nic_t *enp,
1023         __in                            efx_phy_stat_t stat);
1024
1025 #endif  /* EFSYS_OPT_NAMES */
1026
1027 #define EFX_PHY_STATS_SIZE 0x100
1028
1029 extern  __checkReturn                   efx_rc_t
1030 efx_phy_stats_update(
1031         __in                            efx_nic_t *enp,
1032         __in                            efsys_mem_t *esmp,
1033         __inout_ecount(EFX_PHY_NSTATS)  uint32_t *stat);
1034
1035 #endif  /* EFSYS_OPT_PHY_STATS */
1036
1037
1038 #if EFSYS_OPT_BIST
1039
1040 typedef enum efx_bist_type_e {
1041         EFX_BIST_TYPE_UNKNOWN,
1042         EFX_BIST_TYPE_PHY_NORMAL,
1043         EFX_BIST_TYPE_PHY_CABLE_SHORT,
1044         EFX_BIST_TYPE_PHY_CABLE_LONG,
1045         EFX_BIST_TYPE_MC_MEM,   /* Test the MC DMEM and IMEM */
1046         EFX_BIST_TYPE_SAT_MEM,  /* Test the DMEM and IMEM of satellite cpus */
1047         EFX_BIST_TYPE_REG,      /* Test the register memories */
1048         EFX_BIST_TYPE_NTYPES,
1049 } efx_bist_type_t;
1050
1051 typedef enum efx_bist_result_e {
1052         EFX_BIST_RESULT_UNKNOWN,
1053         EFX_BIST_RESULT_RUNNING,
1054         EFX_BIST_RESULT_PASSED,
1055         EFX_BIST_RESULT_FAILED,
1056 } efx_bist_result_t;
1057
1058 typedef enum efx_phy_cable_status_e {
1059         EFX_PHY_CABLE_STATUS_OK,
1060         EFX_PHY_CABLE_STATUS_INVALID,
1061         EFX_PHY_CABLE_STATUS_OPEN,
1062         EFX_PHY_CABLE_STATUS_INTRAPAIRSHORT,
1063         EFX_PHY_CABLE_STATUS_INTERPAIRSHORT,
1064         EFX_PHY_CABLE_STATUS_BUSY,
1065 } efx_phy_cable_status_t;
1066
1067 typedef enum efx_bist_value_e {
1068         EFX_BIST_PHY_CABLE_LENGTH_A,
1069         EFX_BIST_PHY_CABLE_LENGTH_B,
1070         EFX_BIST_PHY_CABLE_LENGTH_C,
1071         EFX_BIST_PHY_CABLE_LENGTH_D,
1072         EFX_BIST_PHY_CABLE_STATUS_A,
1073         EFX_BIST_PHY_CABLE_STATUS_B,
1074         EFX_BIST_PHY_CABLE_STATUS_C,
1075         EFX_BIST_PHY_CABLE_STATUS_D,
1076         EFX_BIST_FAULT_CODE,
1077         /*
1078          * Memory BIST specific values. These match to the MC_CMD_BIST_POLL
1079          * response.
1080          */
1081         EFX_BIST_MEM_TEST,
1082         EFX_BIST_MEM_ADDR,
1083         EFX_BIST_MEM_BUS,
1084         EFX_BIST_MEM_EXPECT,
1085         EFX_BIST_MEM_ACTUAL,
1086         EFX_BIST_MEM_ECC,
1087         EFX_BIST_MEM_ECC_PARITY,
1088         EFX_BIST_MEM_ECC_FATAL,
1089         EFX_BIST_NVALUES,
1090 } efx_bist_value_t;
1091
1092 extern  __checkReturn           efx_rc_t
1093 efx_bist_enable_offline(
1094         __in                    efx_nic_t *enp);
1095
1096 extern  __checkReturn           efx_rc_t
1097 efx_bist_start(
1098         __in                    efx_nic_t *enp,
1099         __in                    efx_bist_type_t type);
1100
1101 extern  __checkReturn           efx_rc_t
1102 efx_bist_poll(
1103         __in                    efx_nic_t *enp,
1104         __in                    efx_bist_type_t type,
1105         __out                   efx_bist_result_t *resultp,
1106         __out_opt               uint32_t *value_maskp,
1107         __out_ecount_opt(count) unsigned long *valuesp,
1108         __in                    size_t count);
1109
1110 extern                          void
1111 efx_bist_stop(
1112         __in                    efx_nic_t *enp,
1113         __in                    efx_bist_type_t type);
1114
1115 #endif  /* EFSYS_OPT_BIST */
1116
1117 #define EFX_FEATURE_IPV6                0x00000001
1118 #define EFX_FEATURE_LFSR_HASH_INSERT    0x00000002
1119 #define EFX_FEATURE_LINK_EVENTS         0x00000004
1120 #define EFX_FEATURE_PERIODIC_MAC_STATS  0x00000008
1121 #define EFX_FEATURE_MCDI                0x00000020
1122 #define EFX_FEATURE_LOOKAHEAD_SPLIT     0x00000040
1123 #define EFX_FEATURE_MAC_HEADER_FILTERS  0x00000080
1124 #define EFX_FEATURE_TURBO               0x00000100
1125 #define EFX_FEATURE_MCDI_DMA            0x00000200
1126 #define EFX_FEATURE_TX_SRC_FILTERS      0x00000400
1127 #define EFX_FEATURE_PIO_BUFFERS         0x00000800
1128 #define EFX_FEATURE_FW_ASSISTED_TSO     0x00001000
1129 #define EFX_FEATURE_FW_ASSISTED_TSO_V2  0x00002000
1130 #define EFX_FEATURE_PACKED_STREAM       0x00004000
1131
1132 typedef enum efx_tunnel_protocol_e {
1133         EFX_TUNNEL_PROTOCOL_NONE = 0,
1134         EFX_TUNNEL_PROTOCOL_VXLAN,
1135         EFX_TUNNEL_PROTOCOL_GENEVE,
1136         EFX_TUNNEL_PROTOCOL_NVGRE,
1137         EFX_TUNNEL_NPROTOS
1138 } efx_tunnel_protocol_t;
1139
1140 typedef enum efx_vi_window_shift_e {
1141         EFX_VI_WINDOW_SHIFT_INVALID = 0,
1142         EFX_VI_WINDOW_SHIFT_8K = 13,
1143         EFX_VI_WINDOW_SHIFT_16K = 14,
1144         EFX_VI_WINDOW_SHIFT_64K = 16,
1145 } efx_vi_window_shift_t;
1146
1147 typedef struct efx_nic_cfg_s {
1148         uint32_t                enc_board_type;
1149         uint32_t                enc_phy_type;
1150 #if EFSYS_OPT_NAMES
1151         char                    enc_phy_name[21];
1152 #endif
1153         char                    enc_phy_revision[21];
1154         efx_mon_type_t          enc_mon_type;
1155 #if EFSYS_OPT_MON_STATS
1156         uint32_t                enc_mon_stat_dma_buf_size;
1157         uint32_t                enc_mon_stat_mask[(EFX_MON_NSTATS + 31) / 32];
1158 #endif
1159         unsigned int            enc_features;
1160         efx_vi_window_shift_t   enc_vi_window_shift;
1161         uint8_t                 enc_mac_addr[6];
1162         uint8_t                 enc_port;       /* PHY port number */
1163         uint32_t                enc_intr_vec_base;
1164         uint32_t                enc_intr_limit;
1165         uint32_t                enc_evq_limit;
1166         uint32_t                enc_txq_limit;
1167         uint32_t                enc_rxq_limit;
1168         uint32_t                enc_txq_max_ndescs;
1169         uint32_t                enc_buftbl_limit;
1170         uint32_t                enc_piobuf_limit;
1171         uint32_t                enc_piobuf_size;
1172         uint32_t                enc_piobuf_min_alloc_size;
1173         uint32_t                enc_evq_timer_quantum_ns;
1174         uint32_t                enc_evq_timer_max_us;
1175         uint32_t                enc_clk_mult;
1176         uint32_t                enc_rx_prefix_size;
1177         uint32_t                enc_rx_buf_align_start;
1178         uint32_t                enc_rx_buf_align_end;
1179         uint32_t                enc_rx_scale_max_exclusive_contexts;
1180 #if EFSYS_OPT_LOOPBACK
1181         efx_qword_t             enc_loopback_types[EFX_LINK_NMODES];
1182 #endif  /* EFSYS_OPT_LOOPBACK */
1183 #if EFSYS_OPT_PHY_FLAGS
1184         uint32_t                enc_phy_flags_mask;
1185 #endif  /* EFSYS_OPT_PHY_FLAGS */
1186 #if EFSYS_OPT_PHY_LED_CONTROL
1187         uint32_t                enc_led_mask;
1188 #endif  /* EFSYS_OPT_PHY_LED_CONTROL */
1189 #if EFSYS_OPT_PHY_STATS
1190         uint64_t                enc_phy_stat_mask;
1191 #endif  /* EFSYS_OPT_PHY_STATS */
1192 #if EFSYS_OPT_MCDI
1193         uint8_t                 enc_mcdi_mdio_channel;
1194 #if EFSYS_OPT_PHY_STATS
1195         uint32_t                enc_mcdi_phy_stat_mask;
1196 #endif  /* EFSYS_OPT_PHY_STATS */
1197 #if EFSYS_OPT_MON_STATS
1198         uint32_t                *enc_mcdi_sensor_maskp;
1199         uint32_t                enc_mcdi_sensor_mask_size;
1200 #endif  /* EFSYS_OPT_MON_STATS */
1201 #endif  /* EFSYS_OPT_MCDI */
1202 #if EFSYS_OPT_BIST
1203         uint32_t                enc_bist_mask;
1204 #endif  /* EFSYS_OPT_BIST */
1205 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
1206         uint32_t                enc_pf;
1207         uint32_t                enc_vf;
1208         uint32_t                enc_privilege_mask;
1209 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */
1210         boolean_t               enc_bug26807_workaround;
1211         boolean_t               enc_bug35388_workaround;
1212         boolean_t               enc_bug41750_workaround;
1213         boolean_t               enc_bug61265_workaround;
1214         boolean_t               enc_rx_batching_enabled;
1215         /* Maximum number of descriptors completed in an rx event. */
1216         uint32_t                enc_rx_batch_max;
1217         /* Number of rx descriptors the hardware requires for a push. */
1218         uint32_t                enc_rx_push_align;
1219         /* Maximum amount of data in DMA descriptor */
1220         uint32_t                enc_tx_dma_desc_size_max;
1221         /*
1222          * Boundary which DMA descriptor data must not cross or 0 if no
1223          * limitation.
1224          */
1225         uint32_t                enc_tx_dma_desc_boundary;
1226         /*
1227          * Maximum number of bytes into the packet the TCP header can start for
1228          * the hardware to apply TSO packet edits.
1229          */
1230         uint32_t                enc_tx_tso_tcp_header_offset_limit;
1231         boolean_t               enc_fw_assisted_tso_enabled;
1232         boolean_t               enc_fw_assisted_tso_v2_enabled;
1233         boolean_t               enc_fw_assisted_tso_v2_encap_enabled;
1234         /* Number of TSO contexts on the NIC (FATSOv2) */
1235         uint32_t                enc_fw_assisted_tso_v2_n_contexts;
1236         boolean_t               enc_hw_tx_insert_vlan_enabled;
1237         /* Number of PFs on the NIC */
1238         uint32_t                enc_hw_pf_count;
1239         /* Datapath firmware vadapter/vport/vswitch support */
1240         boolean_t               enc_datapath_cap_evb;
1241         boolean_t               enc_rx_disable_scatter_supported;
1242         boolean_t               enc_allow_set_mac_with_installed_filters;
1243         boolean_t               enc_enhanced_set_mac_supported;
1244         boolean_t               enc_init_evq_v2_supported;
1245         boolean_t               enc_rx_packed_stream_supported;
1246         boolean_t               enc_rx_var_packed_stream_supported;
1247         boolean_t               enc_pm_and_rxdp_counters;
1248         boolean_t               enc_mac_stats_40g_tx_size_bins;
1249         uint32_t                enc_tunnel_encapsulations_supported;
1250         /*
1251          * NIC global maximum for unique UDP tunnel ports shared by all
1252          * functions.
1253          */
1254         uint32_t                enc_tunnel_config_udp_entries_max;
1255         /* External port identifier */
1256         uint8_t                 enc_external_port;
1257         uint32_t                enc_mcdi_max_payload_length;
1258         /* VPD may be per-PF or global */
1259         boolean_t               enc_vpd_is_global;
1260         /* Minimum unidirectional bandwidth in Mb/s to max out all ports */
1261         uint32_t                enc_required_pcie_bandwidth_mbps;
1262         uint32_t                enc_max_pcie_link_gen;
1263         /* Firmware verifies integrity of NVRAM updates */
1264         uint32_t                enc_nvram_update_verify_result_supported;
1265         /* Firmware support for extended MAC_STATS buffer */
1266         uint32_t                enc_mac_stats_nstats;
1267         boolean_t               enc_fec_counters;
1268 } efx_nic_cfg_t;
1269
1270 #define EFX_PCI_FUNCTION_IS_PF(_encp)   ((_encp)->enc_vf == 0xffff)
1271 #define EFX_PCI_FUNCTION_IS_VF(_encp)   ((_encp)->enc_vf != 0xffff)
1272
1273 #define EFX_PCI_FUNCTION(_encp) \
1274         (EFX_PCI_FUNCTION_IS_PF(_encp) ? (_encp)->enc_pf : (_encp)->enc_vf)
1275
1276 #define EFX_PCI_VF_PARENT(_encp)        ((_encp)->enc_pf)
1277
1278 extern                  const efx_nic_cfg_t *
1279 efx_nic_cfg_get(
1280         __in            efx_nic_t *enp);
1281
1282 typedef struct efx_nic_fw_info_s {
1283         /* Basic FW version information */
1284         uint16_t        enfi_mc_fw_version[4];
1285         /*
1286          * If datapath capabilities can be detected,
1287          * additional FW information is to be shown
1288          */
1289         boolean_t       enfi_dpcpu_fw_ids_valid;
1290         /* Rx and Tx datapath CPU FW IDs */
1291         uint16_t        enfi_rx_dpcpu_fw_id;
1292         uint16_t        enfi_tx_dpcpu_fw_id;
1293 } efx_nic_fw_info_t;
1294
1295 extern  __checkReturn           efx_rc_t
1296 efx_nic_get_fw_version(
1297         __in                    efx_nic_t *enp,
1298         __out                   efx_nic_fw_info_t *enfip);
1299
1300 /* Driver resource limits (minimum required/maximum usable). */
1301 typedef struct efx_drv_limits_s {
1302         uint32_t        edl_min_evq_count;
1303         uint32_t        edl_max_evq_count;
1304
1305         uint32_t        edl_min_rxq_count;
1306         uint32_t        edl_max_rxq_count;
1307
1308         uint32_t        edl_min_txq_count;
1309         uint32_t        edl_max_txq_count;
1310
1311         /* PIO blocks (sub-allocated from piobuf) */
1312         uint32_t        edl_min_pio_alloc_size;
1313         uint32_t        edl_max_pio_alloc_count;
1314 } efx_drv_limits_t;
1315
1316 extern  __checkReturn   efx_rc_t
1317 efx_nic_set_drv_limits(
1318         __inout         efx_nic_t *enp,
1319         __in            efx_drv_limits_t *edlp);
1320
1321 typedef enum efx_nic_region_e {
1322         EFX_REGION_VI,                  /* Memory BAR UC mapping */
1323         EFX_REGION_PIO_WRITE_VI,        /* Memory BAR WC mapping */
1324 } efx_nic_region_t;
1325
1326 extern  __checkReturn   efx_rc_t
1327 efx_nic_get_bar_region(
1328         __in            efx_nic_t *enp,
1329         __in            efx_nic_region_t region,
1330         __out           uint32_t *offsetp,
1331         __out           size_t *sizep);
1332
1333 extern  __checkReturn   efx_rc_t
1334 efx_nic_get_vi_pool(
1335         __in            efx_nic_t *enp,
1336         __out           uint32_t *evq_countp,
1337         __out           uint32_t *rxq_countp,
1338         __out           uint32_t *txq_countp);
1339
1340
1341 #if EFSYS_OPT_VPD
1342
1343 typedef enum efx_vpd_tag_e {
1344         EFX_VPD_ID = 0x02,
1345         EFX_VPD_END = 0x0f,
1346         EFX_VPD_RO = 0x10,
1347         EFX_VPD_RW = 0x11,
1348 } efx_vpd_tag_t;
1349
1350 typedef uint16_t efx_vpd_keyword_t;
1351
1352 typedef struct efx_vpd_value_s {
1353         efx_vpd_tag_t           evv_tag;
1354         efx_vpd_keyword_t       evv_keyword;
1355         uint8_t                 evv_length;
1356         uint8_t                 evv_value[0x100];
1357 } efx_vpd_value_t;
1358
1359
1360 #define EFX_VPD_KEYWORD(x, y) ((x) | ((y) << 8))
1361
1362 extern  __checkReturn           efx_rc_t
1363 efx_vpd_init(
1364         __in                    efx_nic_t *enp);
1365
1366 extern  __checkReturn           efx_rc_t
1367 efx_vpd_size(
1368         __in                    efx_nic_t *enp,
1369         __out                   size_t *sizep);
1370
1371 extern  __checkReturn           efx_rc_t
1372 efx_vpd_read(
1373         __in                    efx_nic_t *enp,
1374         __out_bcount(size)      caddr_t data,
1375         __in                    size_t size);
1376
1377 extern  __checkReturn           efx_rc_t
1378 efx_vpd_verify(
1379         __in                    efx_nic_t *enp,
1380         __in_bcount(size)       caddr_t data,
1381         __in                    size_t size);
1382
1383 extern  __checkReturn           efx_rc_t
1384 efx_vpd_reinit(
1385         __in                    efx_nic_t *enp,
1386         __in_bcount(size)       caddr_t data,
1387         __in                    size_t size);
1388
1389 extern  __checkReturn           efx_rc_t
1390 efx_vpd_get(
1391         __in                    efx_nic_t *enp,
1392         __in_bcount(size)       caddr_t data,
1393         __in                    size_t size,
1394         __inout                 efx_vpd_value_t *evvp);
1395
1396 extern  __checkReturn           efx_rc_t
1397 efx_vpd_set(
1398         __in                    efx_nic_t *enp,
1399         __inout_bcount(size)    caddr_t data,
1400         __in                    size_t size,
1401         __in                    efx_vpd_value_t *evvp);
1402
1403 extern  __checkReturn           efx_rc_t
1404 efx_vpd_next(
1405         __in                    efx_nic_t *enp,
1406         __inout_bcount(size)    caddr_t data,
1407         __in                    size_t size,
1408         __out                   efx_vpd_value_t *evvp,
1409         __inout                 unsigned int *contp);
1410
1411 extern  __checkReturn           efx_rc_t
1412 efx_vpd_write(
1413         __in                    efx_nic_t *enp,
1414         __in_bcount(size)       caddr_t data,
1415         __in                    size_t size);
1416
1417 extern                          void
1418 efx_vpd_fini(
1419         __in                    efx_nic_t *enp);
1420
1421 #endif  /* EFSYS_OPT_VPD */
1422
1423 /* NVRAM */
1424
1425 #if EFSYS_OPT_NVRAM
1426
1427 typedef enum efx_nvram_type_e {
1428         EFX_NVRAM_INVALID = 0,
1429         EFX_NVRAM_BOOTROM,
1430         EFX_NVRAM_BOOTROM_CFG,
1431         EFX_NVRAM_MC_FIRMWARE,
1432         EFX_NVRAM_MC_GOLDEN,
1433         EFX_NVRAM_PHY,
1434         EFX_NVRAM_NULLPHY,
1435         EFX_NVRAM_FPGA,
1436         EFX_NVRAM_FCFW,
1437         EFX_NVRAM_CPLD,
1438         EFX_NVRAM_FPGA_BACKUP,
1439         EFX_NVRAM_DYNAMIC_CFG,
1440         EFX_NVRAM_LICENSE,
1441         EFX_NVRAM_UEFIROM,
1442         EFX_NVRAM_MUM_FIRMWARE,
1443         EFX_NVRAM_NTYPES,
1444 } efx_nvram_type_t;
1445
1446 extern  __checkReturn           efx_rc_t
1447 efx_nvram_init(
1448         __in                    efx_nic_t *enp);
1449
1450 #if EFSYS_OPT_DIAG
1451
1452 extern  __checkReturn           efx_rc_t
1453 efx_nvram_test(
1454         __in                    efx_nic_t *enp);
1455
1456 #endif  /* EFSYS_OPT_DIAG */
1457
1458 extern  __checkReturn           efx_rc_t
1459 efx_nvram_size(
1460         __in                    efx_nic_t *enp,
1461         __in                    efx_nvram_type_t type,
1462         __out                   size_t *sizep);
1463
1464 extern  __checkReturn           efx_rc_t
1465 efx_nvram_rw_start(
1466         __in                    efx_nic_t *enp,
1467         __in                    efx_nvram_type_t type,
1468         __out_opt               size_t *pref_chunkp);
1469
1470 extern  __checkReturn           efx_rc_t
1471 efx_nvram_rw_finish(
1472         __in                    efx_nic_t *enp,
1473         __in                    efx_nvram_type_t type,
1474         __out_opt               uint32_t *verify_resultp);
1475
1476 extern  __checkReturn           efx_rc_t
1477 efx_nvram_get_version(
1478         __in                    efx_nic_t *enp,
1479         __in                    efx_nvram_type_t type,
1480         __out                   uint32_t *subtypep,
1481         __out_ecount(4)         uint16_t version[4]);
1482
1483 extern  __checkReturn           efx_rc_t
1484 efx_nvram_read_chunk(
1485         __in                    efx_nic_t *enp,
1486         __in                    efx_nvram_type_t type,
1487         __in                    unsigned int offset,
1488         __out_bcount(size)      caddr_t data,
1489         __in                    size_t size);
1490
1491 extern  __checkReturn           efx_rc_t
1492 efx_nvram_read_backup(
1493         __in                    efx_nic_t *enp,
1494         __in                    efx_nvram_type_t type,
1495         __in                    unsigned int offset,
1496         __out_bcount(size)      caddr_t data,
1497         __in                    size_t size);
1498
1499 extern  __checkReturn           efx_rc_t
1500 efx_nvram_set_version(
1501         __in                    efx_nic_t *enp,
1502         __in                    efx_nvram_type_t type,
1503         __in_ecount(4)          uint16_t version[4]);
1504
1505 extern  __checkReturn           efx_rc_t
1506 efx_nvram_validate(
1507         __in                    efx_nic_t *enp,
1508         __in                    efx_nvram_type_t type,
1509         __in_bcount(partn_size) caddr_t partn_data,
1510         __in                    size_t partn_size);
1511
1512 extern   __checkReturn          efx_rc_t
1513 efx_nvram_erase(
1514         __in                    efx_nic_t *enp,
1515         __in                    efx_nvram_type_t type);
1516
1517 extern  __checkReturn           efx_rc_t
1518 efx_nvram_write_chunk(
1519         __in                    efx_nic_t *enp,
1520         __in                    efx_nvram_type_t type,
1521         __in                    unsigned int offset,
1522         __in_bcount(size)       caddr_t data,
1523         __in                    size_t size);
1524
1525 extern                          void
1526 efx_nvram_fini(
1527         __in                    efx_nic_t *enp);
1528
1529 #endif  /* EFSYS_OPT_NVRAM */
1530
1531 #if EFSYS_OPT_BOOTCFG
1532
1533 /* Report size and offset of bootcfg sector in NVRAM partition. */
1534 extern  __checkReturn           efx_rc_t
1535 efx_bootcfg_sector_info(
1536         __in                    efx_nic_t *enp,
1537         __in                    uint32_t pf,
1538         __out_opt               uint32_t *sector_countp,
1539         __out                   size_t *offsetp,
1540         __out                   size_t *max_sizep);
1541
1542 /*
1543  * Copy bootcfg sector data to a target buffer which may differ in size.
1544  * Optionally corrects format errors in source buffer.
1545  */
1546 extern                          efx_rc_t
1547 efx_bootcfg_copy_sector(
1548         __in                    efx_nic_t *enp,
1549         __inout_bcount(sector_length)
1550                                 uint8_t *sector,
1551         __in                    size_t sector_length,
1552         __out_bcount(data_size) uint8_t *data,
1553         __in                    size_t data_size,
1554         __in                    boolean_t handle_format_errors);
1555
1556 extern                          efx_rc_t
1557 efx_bootcfg_read(
1558         __in                    efx_nic_t *enp,
1559         __out_bcount(size)      uint8_t *data,
1560         __in                    size_t size);
1561
1562 extern                          efx_rc_t
1563 efx_bootcfg_write(
1564         __in                    efx_nic_t *enp,
1565         __in_bcount(size)       uint8_t *data,
1566         __in                    size_t size);
1567
1568 #endif  /* EFSYS_OPT_BOOTCFG */
1569
1570 #if EFSYS_OPT_IMAGE_LAYOUT
1571
1572 #include "ef10_signed_image_layout.h"
1573
1574 /*
1575  * Image header used in unsigned and signed image layouts (see SF-102785-PS).
1576  *
1577  * NOTE:
1578  * The image header format is extensible. However, older drivers require an
1579  * exact match of image header version and header length when validating and
1580  * writing firmware images.
1581  *
1582  * To avoid breaking backward compatibility, we use the upper bits of the
1583  * controller version fields to contain an extra version number used for
1584  * combined bootROM and UEFI ROM images on EF10 and later (to hold the UEFI ROM
1585  * version). See bug39254 and SF-102785-PS for details.
1586  */
1587 typedef struct efx_image_header_s {
1588         uint32_t        eih_magic;
1589         uint32_t        eih_version;
1590         uint32_t        eih_type;
1591         uint32_t        eih_subtype;
1592         uint32_t        eih_code_size;
1593         uint32_t        eih_size;
1594         union {
1595                 uint32_t        eih_controller_version_min;
1596                 struct {
1597                         uint16_t        eih_controller_version_min_short;
1598                         uint8_t         eih_extra_version_a;
1599                         uint8_t         eih_extra_version_b;
1600                 };
1601         };
1602         union {
1603                 uint32_t        eih_controller_version_max;
1604                 struct {
1605                         uint16_t        eih_controller_version_max_short;
1606                         uint8_t         eih_extra_version_c;
1607                         uint8_t         eih_extra_version_d;
1608                 };
1609         };
1610         uint16_t        eih_code_version_a;
1611         uint16_t        eih_code_version_b;
1612         uint16_t        eih_code_version_c;
1613         uint16_t        eih_code_version_d;
1614 } efx_image_header_t;
1615
1616 #define EFX_IMAGE_HEADER_SIZE           (40)
1617 #define EFX_IMAGE_HEADER_VERSION        (4)
1618 #define EFX_IMAGE_HEADER_MAGIC          (0x106F1A5)
1619
1620
1621 typedef struct efx_image_trailer_s {
1622         uint32_t        eit_crc;
1623 } efx_image_trailer_t;
1624
1625 #define EFX_IMAGE_TRAILER_SIZE          (4)
1626
1627 typedef enum efx_image_format_e {
1628         EFX_IMAGE_FORMAT_NO_IMAGE,
1629         EFX_IMAGE_FORMAT_INVALID,
1630         EFX_IMAGE_FORMAT_UNSIGNED,
1631         EFX_IMAGE_FORMAT_SIGNED,
1632 } efx_image_format_t;
1633
1634 typedef struct efx_image_info_s {
1635         efx_image_format_t      eii_format;
1636         uint8_t *               eii_imagep;
1637         size_t                  eii_image_size;
1638         efx_image_header_t *    eii_headerp;
1639 } efx_image_info_t;
1640
1641 extern  __checkReturn   efx_rc_t
1642 efx_check_reflash_image(
1643         __in            void                    *bufferp,
1644         __in            uint32_t                buffer_size,
1645         __out           efx_image_info_t        *infop);
1646
1647 extern  __checkReturn   efx_rc_t
1648 efx_build_signed_image_write_buffer(
1649         __out           uint8_t                 *bufferp,
1650         __in            uint32_t                buffer_size,
1651         __in            efx_image_info_t        *infop,
1652         __out           efx_image_header_t      **headerpp);
1653
1654 #endif  /* EFSYS_OPT_IMAGE_LAYOUT */
1655
1656 #if EFSYS_OPT_DIAG
1657
1658 typedef enum efx_pattern_type_t {
1659         EFX_PATTERN_BYTE_INCREMENT = 0,
1660         EFX_PATTERN_ALL_THE_SAME,
1661         EFX_PATTERN_BIT_ALTERNATE,
1662         EFX_PATTERN_BYTE_ALTERNATE,
1663         EFX_PATTERN_BYTE_CHANGING,
1664         EFX_PATTERN_BIT_SWEEP,
1665         EFX_PATTERN_NTYPES
1666 } efx_pattern_type_t;
1667
1668 typedef                 void
1669 (*efx_sram_pattern_fn_t)(
1670         __in            size_t row,
1671         __in            boolean_t negate,
1672         __out           efx_qword_t *eqp);
1673
1674 extern  __checkReturn   efx_rc_t
1675 efx_sram_test(
1676         __in            efx_nic_t *enp,
1677         __in            efx_pattern_type_t type);
1678
1679 #endif  /* EFSYS_OPT_DIAG */
1680
1681 extern  __checkReturn   efx_rc_t
1682 efx_sram_buf_tbl_set(
1683         __in            efx_nic_t *enp,
1684         __in            uint32_t id,
1685         __in            efsys_mem_t *esmp,
1686         __in            size_t n);
1687
1688 extern          void
1689 efx_sram_buf_tbl_clear(
1690         __in    efx_nic_t *enp,
1691         __in    uint32_t id,
1692         __in    size_t n);
1693
1694 #define EFX_BUF_TBL_SIZE        0x20000
1695
1696 #define EFX_BUF_SIZE            4096
1697
1698 /* EV */
1699
1700 typedef struct efx_evq_s        efx_evq_t;
1701
1702 #if EFSYS_OPT_QSTATS
1703
1704 /* START MKCONFIG GENERATED EfxHeaderEventQueueBlock 6f3843f5fe7cc843 */
1705 typedef enum efx_ev_qstat_e {
1706         EV_ALL,
1707         EV_RX,
1708         EV_RX_OK,
1709         EV_RX_FRM_TRUNC,
1710         EV_RX_TOBE_DISC,
1711         EV_RX_PAUSE_FRM_ERR,
1712         EV_RX_BUF_OWNER_ID_ERR,
1713         EV_RX_IPV4_HDR_CHKSUM_ERR,
1714         EV_RX_TCP_UDP_CHKSUM_ERR,
1715         EV_RX_ETH_CRC_ERR,
1716         EV_RX_IP_FRAG_ERR,
1717         EV_RX_MCAST_PKT,
1718         EV_RX_MCAST_HASH_MATCH,
1719         EV_RX_TCP_IPV4,
1720         EV_RX_TCP_IPV6,
1721         EV_RX_UDP_IPV4,
1722         EV_RX_UDP_IPV6,
1723         EV_RX_OTHER_IPV4,
1724         EV_RX_OTHER_IPV6,
1725         EV_RX_NON_IP,
1726         EV_RX_BATCH,
1727         EV_TX,
1728         EV_TX_WQ_FF_FULL,
1729         EV_TX_PKT_ERR,
1730         EV_TX_PKT_TOO_BIG,
1731         EV_TX_UNEXPECTED,
1732         EV_GLOBAL,
1733         EV_GLOBAL_MNT,
1734         EV_DRIVER,
1735         EV_DRIVER_SRM_UPD_DONE,
1736         EV_DRIVER_TX_DESCQ_FLS_DONE,
1737         EV_DRIVER_RX_DESCQ_FLS_DONE,
1738         EV_DRIVER_RX_DESCQ_FLS_FAILED,
1739         EV_DRIVER_RX_DSC_ERROR,
1740         EV_DRIVER_TX_DSC_ERROR,
1741         EV_DRV_GEN,
1742         EV_MCDI_RESPONSE,
1743         EV_NQSTATS
1744 } efx_ev_qstat_t;
1745
1746 /* END MKCONFIG GENERATED EfxHeaderEventQueueBlock */
1747
1748 #endif  /* EFSYS_OPT_QSTATS */
1749
1750 extern  __checkReturn   efx_rc_t
1751 efx_ev_init(
1752         __in            efx_nic_t *enp);
1753
1754 extern          void
1755 efx_ev_fini(
1756         __in            efx_nic_t *enp);
1757
1758 #define EFX_EVQ_MAXNEVS         32768
1759 #define EFX_EVQ_MINNEVS         512
1760
1761 #define EFX_EVQ_SIZE(_nevs)     ((_nevs) * sizeof (efx_qword_t))
1762 #define EFX_EVQ_NBUFS(_nevs)    (EFX_EVQ_SIZE(_nevs) / EFX_BUF_SIZE)
1763
1764 #define EFX_EVQ_FLAGS_TYPE_MASK         (0x3)
1765 #define EFX_EVQ_FLAGS_TYPE_AUTO         (0x0)
1766 #define EFX_EVQ_FLAGS_TYPE_THROUGHPUT   (0x1)
1767 #define EFX_EVQ_FLAGS_TYPE_LOW_LATENCY  (0x2)
1768
1769 #define EFX_EVQ_FLAGS_NOTIFY_MASK       (0xC)
1770 #define EFX_EVQ_FLAGS_NOTIFY_INTERRUPT  (0x0)   /* Interrupting (default) */
1771 #define EFX_EVQ_FLAGS_NOTIFY_DISABLED   (0x4)   /* Non-interrupting */
1772
1773 extern  __checkReturn   efx_rc_t
1774 efx_ev_qcreate(
1775         __in            efx_nic_t *enp,
1776         __in            unsigned int index,
1777         __in            efsys_mem_t *esmp,
1778         __in            size_t ndescs,
1779         __in            uint32_t id,
1780         __in            uint32_t us,
1781         __in            uint32_t flags,
1782         __deref_out     efx_evq_t **eepp);
1783
1784 extern          void
1785 efx_ev_qpost(
1786         __in            efx_evq_t *eep,
1787         __in            uint16_t data);
1788
1789 typedef __checkReturn   boolean_t
1790 (*efx_initialized_ev_t)(
1791         __in_opt        void *arg);
1792
1793 #define EFX_PKT_UNICAST         0x0004
1794 #define EFX_PKT_START           0x0008
1795
1796 #define EFX_PKT_VLAN_TAGGED     0x0010
1797 #define EFX_CKSUM_TCPUDP        0x0020
1798 #define EFX_CKSUM_IPV4          0x0040
1799 #define EFX_PKT_CONT            0x0080
1800
1801 #define EFX_CHECK_VLAN          0x0100
1802 #define EFX_PKT_TCP             0x0200
1803 #define EFX_PKT_UDP             0x0400
1804 #define EFX_PKT_IPV4            0x0800
1805
1806 #define EFX_PKT_IPV6            0x1000
1807 #define EFX_PKT_PREFIX_LEN      0x2000
1808 #define EFX_ADDR_MISMATCH       0x4000
1809 #define EFX_DISCARD             0x8000
1810
1811 /*
1812  * The following flags are used only for packed stream
1813  * mode. The values for the flags are reused to fit into 16 bit,
1814  * since EFX_PKT_START and EFX_PKT_CONT are never used in
1815  * packed stream mode
1816  */
1817 #define EFX_PKT_PACKED_STREAM_NEW_BUFFER        EFX_PKT_START
1818 #define EFX_PKT_PACKED_STREAM_PARSE_INCOMPLETE  EFX_PKT_CONT
1819
1820
1821 #define EFX_EV_RX_NLABELS       32
1822 #define EFX_EV_TX_NLABELS       32
1823
1824 typedef __checkReturn   boolean_t
1825 (*efx_rx_ev_t)(
1826         __in_opt        void *arg,
1827         __in            uint32_t label,
1828         __in            uint32_t id,
1829         __in            uint32_t size,
1830         __in            uint16_t flags);
1831
1832 #if EFSYS_OPT_RX_PACKED_STREAM
1833
1834 /*
1835  * Packed stream mode is documented in SF-112241-TC.
1836  * The general idea is that, instead of putting each incoming
1837  * packet into a separate buffer which is specified in a RX
1838  * descriptor, a large buffer is provided to the hardware and
1839  * packets are put there in a continuous stream.
1840  * The main advantage of such an approach is that RX queue refilling
1841  * happens much less frequently.
1842  */
1843
1844 typedef __checkReturn   boolean_t
1845 (*efx_rx_ps_ev_t)(
1846         __in_opt        void *arg,
1847         __in            uint32_t label,
1848         __in            uint32_t id,
1849         __in            uint32_t pkt_count,
1850         __in            uint16_t flags);
1851
1852 #endif
1853
1854 typedef __checkReturn   boolean_t
1855 (*efx_tx_ev_t)(
1856         __in_opt        void *arg,
1857         __in            uint32_t label,
1858         __in            uint32_t id);
1859
1860 #define EFX_EXCEPTION_RX_RECOVERY       0x00000001
1861 #define EFX_EXCEPTION_RX_DSC_ERROR      0x00000002
1862 #define EFX_EXCEPTION_TX_DSC_ERROR      0x00000003
1863 #define EFX_EXCEPTION_UNKNOWN_SENSOREVT 0x00000004
1864 #define EFX_EXCEPTION_FWALERT_SRAM      0x00000005
1865 #define EFX_EXCEPTION_UNKNOWN_FWALERT   0x00000006
1866 #define EFX_EXCEPTION_RX_ERROR          0x00000007
1867 #define EFX_EXCEPTION_TX_ERROR          0x00000008
1868 #define EFX_EXCEPTION_EV_ERROR          0x00000009
1869
1870 typedef __checkReturn   boolean_t
1871 (*efx_exception_ev_t)(
1872         __in_opt        void *arg,
1873         __in            uint32_t label,
1874         __in            uint32_t data);
1875
1876 typedef __checkReturn   boolean_t
1877 (*efx_rxq_flush_done_ev_t)(
1878         __in_opt        void *arg,
1879         __in            uint32_t rxq_index);
1880
1881 typedef __checkReturn   boolean_t
1882 (*efx_rxq_flush_failed_ev_t)(
1883         __in_opt        void *arg,
1884         __in            uint32_t rxq_index);
1885
1886 typedef __checkReturn   boolean_t
1887 (*efx_txq_flush_done_ev_t)(
1888         __in_opt        void *arg,
1889         __in            uint32_t txq_index);
1890
1891 typedef __checkReturn   boolean_t
1892 (*efx_software_ev_t)(
1893         __in_opt        void *arg,
1894         __in            uint16_t magic);
1895
1896 typedef __checkReturn   boolean_t
1897 (*efx_sram_ev_t)(
1898         __in_opt        void *arg,
1899         __in            uint32_t code);
1900
1901 #define EFX_SRAM_CLEAR          0
1902 #define EFX_SRAM_UPDATE         1
1903 #define EFX_SRAM_ILLEGAL_CLEAR  2
1904
1905 typedef __checkReturn   boolean_t
1906 (*efx_wake_up_ev_t)(
1907         __in_opt        void *arg,
1908         __in            uint32_t label);
1909
1910 typedef __checkReturn   boolean_t
1911 (*efx_timer_ev_t)(
1912         __in_opt        void *arg,
1913         __in            uint32_t label);
1914
1915 typedef __checkReturn   boolean_t
1916 (*efx_link_change_ev_t)(
1917         __in_opt        void *arg,
1918         __in            efx_link_mode_t link_mode);
1919
1920 #if EFSYS_OPT_MON_STATS
1921
1922 typedef __checkReturn   boolean_t
1923 (*efx_monitor_ev_t)(
1924         __in_opt        void *arg,
1925         __in            efx_mon_stat_t id,
1926         __in            efx_mon_stat_value_t value);
1927
1928 #endif  /* EFSYS_OPT_MON_STATS */
1929
1930 #if EFSYS_OPT_MAC_STATS
1931
1932 typedef __checkReturn   boolean_t
1933 (*efx_mac_stats_ev_t)(
1934         __in_opt        void *arg,
1935         __in            uint32_t generation);
1936
1937 #endif  /* EFSYS_OPT_MAC_STATS */
1938
1939 typedef struct efx_ev_callbacks_s {
1940         efx_initialized_ev_t            eec_initialized;
1941         efx_rx_ev_t                     eec_rx;
1942 #if EFSYS_OPT_RX_PACKED_STREAM
1943         efx_rx_ps_ev_t                  eec_rx_ps;
1944 #endif
1945         efx_tx_ev_t                     eec_tx;
1946         efx_exception_ev_t              eec_exception;
1947         efx_rxq_flush_done_ev_t         eec_rxq_flush_done;
1948         efx_rxq_flush_failed_ev_t       eec_rxq_flush_failed;
1949         efx_txq_flush_done_ev_t         eec_txq_flush_done;
1950         efx_software_ev_t               eec_software;
1951         efx_sram_ev_t                   eec_sram;
1952         efx_wake_up_ev_t                eec_wake_up;
1953         efx_timer_ev_t                  eec_timer;
1954         efx_link_change_ev_t            eec_link_change;
1955 #if EFSYS_OPT_MON_STATS
1956         efx_monitor_ev_t                eec_monitor;
1957 #endif  /* EFSYS_OPT_MON_STATS */
1958 #if EFSYS_OPT_MAC_STATS
1959         efx_mac_stats_ev_t              eec_mac_stats;
1960 #endif  /* EFSYS_OPT_MAC_STATS */
1961 } efx_ev_callbacks_t;
1962
1963 extern  __checkReturn   boolean_t
1964 efx_ev_qpending(
1965         __in            efx_evq_t *eep,
1966         __in            unsigned int count);
1967
1968 #if EFSYS_OPT_EV_PREFETCH
1969
1970 extern                  void
1971 efx_ev_qprefetch(
1972         __in            efx_evq_t *eep,
1973         __in            unsigned int count);
1974
1975 #endif  /* EFSYS_OPT_EV_PREFETCH */
1976
1977 extern                  void
1978 efx_ev_qpoll(
1979         __in            efx_evq_t *eep,
1980         __inout         unsigned int *countp,
1981         __in            const efx_ev_callbacks_t *eecp,
1982         __in_opt        void *arg);
1983
1984 extern  __checkReturn   efx_rc_t
1985 efx_ev_usecs_to_ticks(
1986         __in            efx_nic_t *enp,
1987         __in            unsigned int usecs,
1988         __out           unsigned int *ticksp);
1989
1990 extern  __checkReturn   efx_rc_t
1991 efx_ev_qmoderate(
1992         __in            efx_evq_t *eep,
1993         __in            unsigned int us);
1994
1995 extern  __checkReturn   efx_rc_t
1996 efx_ev_qprime(
1997         __in            efx_evq_t *eep,
1998         __in            unsigned int count);
1999
2000 #if EFSYS_OPT_QSTATS
2001
2002 #if EFSYS_OPT_NAMES
2003
2004 extern          const char *
2005 efx_ev_qstat_name(
2006         __in    efx_nic_t *enp,
2007         __in    unsigned int id);
2008
2009 #endif  /* EFSYS_OPT_NAMES */
2010
2011 extern                                  void
2012 efx_ev_qstats_update(
2013         __in                            efx_evq_t *eep,
2014         __inout_ecount(EV_NQSTATS)      efsys_stat_t *stat);
2015
2016 #endif  /* EFSYS_OPT_QSTATS */
2017
2018 extern          void
2019 efx_ev_qdestroy(
2020         __in    efx_evq_t *eep);
2021
2022 /* RX */
2023
2024 extern  __checkReturn   efx_rc_t
2025 efx_rx_init(
2026         __inout         efx_nic_t *enp);
2027
2028 extern          void
2029 efx_rx_fini(
2030         __in            efx_nic_t *enp);
2031
2032 #if EFSYS_OPT_RX_SCATTER
2033         __checkReturn   efx_rc_t
2034 efx_rx_scatter_enable(
2035         __in            efx_nic_t *enp,
2036         __in            unsigned int buf_size);
2037 #endif  /* EFSYS_OPT_RX_SCATTER */
2038
2039 /* Handle to represent use of the default RSS context. */
2040 #define EFX_RSS_CONTEXT_DEFAULT 0xffffffff
2041
2042 #if EFSYS_OPT_RX_SCALE
2043
2044 typedef enum efx_rx_hash_alg_e {
2045         EFX_RX_HASHALG_LFSR = 0,
2046         EFX_RX_HASHALG_TOEPLITZ
2047 } efx_rx_hash_alg_t;
2048
2049 #define EFX_RX_HASH_IPV4        (1U << 0)
2050 #define EFX_RX_HASH_TCPIPV4     (1U << 1)
2051 #define EFX_RX_HASH_IPV6        (1U << 2)
2052 #define EFX_RX_HASH_TCPIPV6     (1U << 3)
2053
2054 typedef unsigned int efx_rx_hash_type_t;
2055
2056 typedef enum efx_rx_hash_support_e {
2057         EFX_RX_HASH_UNAVAILABLE = 0,    /* Hardware hash not inserted */
2058         EFX_RX_HASH_AVAILABLE           /* Insert hash with/without RSS */
2059 } efx_rx_hash_support_t;
2060
2061 #define EFX_RSS_KEY_SIZE        40      /* RSS key size (bytes) */
2062 #define EFX_RSS_TBL_SIZE        128     /* Rows in RX indirection table */
2063 #define EFX_MAXRSS              64      /* RX indirection entry range */
2064 #define EFX_MAXRSS_LEGACY       16      /* See bug16611 and bug17213 */
2065
2066 typedef enum efx_rx_scale_context_type_e {
2067         EFX_RX_SCALE_UNAVAILABLE = 0,   /* No RX scale context */
2068         EFX_RX_SCALE_EXCLUSIVE,         /* Writable key/indirection table */
2069         EFX_RX_SCALE_SHARED             /* Read-only key/indirection table */
2070 } efx_rx_scale_context_type_t;
2071
2072 extern  __checkReturn   efx_rc_t
2073 efx_rx_hash_default_support_get(
2074         __in            efx_nic_t *enp,
2075         __out           efx_rx_hash_support_t *supportp);
2076
2077
2078 extern  __checkReturn   efx_rc_t
2079 efx_rx_scale_default_support_get(
2080         __in            efx_nic_t *enp,
2081         __out           efx_rx_scale_context_type_t *typep);
2082
2083 extern  __checkReturn   efx_rc_t
2084 efx_rx_scale_context_alloc(
2085         __in            efx_nic_t *enp,
2086         __in            efx_rx_scale_context_type_t type,
2087         __in            uint32_t num_queues,
2088         __out           uint32_t *rss_contextp);
2089
2090 extern  __checkReturn   efx_rc_t
2091 efx_rx_scale_context_free(
2092         __in            efx_nic_t *enp,
2093         __in            uint32_t rss_context);
2094
2095 extern  __checkReturn   efx_rc_t
2096 efx_rx_scale_mode_set(
2097         __in    efx_nic_t *enp,
2098         __in    uint32_t rss_context,
2099         __in    efx_rx_hash_alg_t alg,
2100         __in    efx_rx_hash_type_t type,
2101         __in    boolean_t insert);
2102
2103 extern  __checkReturn   efx_rc_t
2104 efx_rx_scale_tbl_set(
2105         __in            efx_nic_t *enp,
2106         __in            uint32_t rss_context,
2107         __in_ecount(n)  unsigned int *table,
2108         __in            size_t n);
2109
2110 extern  __checkReturn   efx_rc_t
2111 efx_rx_scale_key_set(
2112         __in            efx_nic_t *enp,
2113         __in            uint32_t rss_context,
2114         __in_ecount(n)  uint8_t *key,
2115         __in            size_t n);
2116
2117 extern  __checkReturn   uint32_t
2118 efx_pseudo_hdr_hash_get(
2119         __in            efx_rxq_t *erp,
2120         __in            efx_rx_hash_alg_t func,
2121         __in            uint8_t *buffer);
2122
2123 #endif  /* EFSYS_OPT_RX_SCALE */
2124
2125 extern  __checkReturn   efx_rc_t
2126 efx_pseudo_hdr_pkt_length_get(
2127         __in            efx_rxq_t *erp,
2128         __in            uint8_t *buffer,
2129         __out           uint16_t *pkt_lengthp);
2130
2131 #define EFX_RXQ_MAXNDESCS               4096
2132 #define EFX_RXQ_MINNDESCS               512
2133
2134 #define EFX_RXQ_SIZE(_ndescs)           ((_ndescs) * sizeof (efx_qword_t))
2135 #define EFX_RXQ_NBUFS(_ndescs)          (EFX_RXQ_SIZE(_ndescs) / EFX_BUF_SIZE)
2136 #define EFX_RXQ_LIMIT(_ndescs)          ((_ndescs) - 16)
2137 #define EFX_RXQ_DC_NDESCS(_dcsize)      (8 << _dcsize)
2138
2139 typedef enum efx_rxq_type_e {
2140         EFX_RXQ_TYPE_DEFAULT,
2141         EFX_RXQ_TYPE_PACKED_STREAM,
2142         EFX_RXQ_NTYPES
2143 } efx_rxq_type_t;
2144
2145 /*
2146  * Dummy flag to be used instead of 0 to make it clear that the argument
2147  * is receive queue flags.
2148  */
2149 #define EFX_RXQ_FLAG_NONE               0x0
2150 #define EFX_RXQ_FLAG_SCATTER            0x1
2151 /*
2152  * If tunnels are supported and Rx event can provide information about
2153  * either outer or inner packet classes (e.g. SFN8xxx adapters with
2154  * full-feature firmware variant running), outer classes are requested by
2155  * default. However, if the driver supports tunnels, the flag allows to
2156  * request inner classes which are required to be able to interpret inner
2157  * Rx checksum offload results.
2158  */
2159 #define EFX_RXQ_FLAG_INNER_CLASSES      0x2
2160
2161 extern  __checkReturn   efx_rc_t
2162 efx_rx_qcreate(
2163         __in            efx_nic_t *enp,
2164         __in            unsigned int index,
2165         __in            unsigned int label,
2166         __in            efx_rxq_type_t type,
2167         __in            efsys_mem_t *esmp,
2168         __in            size_t ndescs,
2169         __in            uint32_t id,
2170         __in            unsigned int flags,
2171         __in            efx_evq_t *eep,
2172         __deref_out     efx_rxq_t **erpp);
2173
2174 #if EFSYS_OPT_RX_PACKED_STREAM
2175
2176 #define EFX_RXQ_PACKED_STREAM_BUF_SIZE_1M       (1U * 1024 * 1024)
2177 #define EFX_RXQ_PACKED_STREAM_BUF_SIZE_512K     (512U * 1024)
2178 #define EFX_RXQ_PACKED_STREAM_BUF_SIZE_256K     (256U * 1024)
2179 #define EFX_RXQ_PACKED_STREAM_BUF_SIZE_128K     (128U * 1024)
2180 #define EFX_RXQ_PACKED_STREAM_BUF_SIZE_64K      (64U * 1024)
2181
2182 extern  __checkReturn   efx_rc_t
2183 efx_rx_qcreate_packed_stream(
2184         __in            efx_nic_t *enp,
2185         __in            unsigned int index,
2186         __in            unsigned int label,
2187         __in            uint32_t ps_buf_size,
2188         __in            efsys_mem_t *esmp,
2189         __in            size_t ndescs,
2190         __in            efx_evq_t *eep,
2191         __deref_out     efx_rxq_t **erpp);
2192
2193 #endif
2194
2195 typedef struct efx_buffer_s {
2196         efsys_dma_addr_t        eb_addr;
2197         size_t                  eb_size;
2198         boolean_t               eb_eop;
2199 } efx_buffer_t;
2200
2201 typedef struct efx_desc_s {
2202         efx_qword_t ed_eq;
2203 } efx_desc_t;
2204
2205 extern                          void
2206 efx_rx_qpost(
2207         __in                    efx_rxq_t *erp,
2208         __in_ecount(ndescs)     efsys_dma_addr_t *addrp,
2209         __in                    size_t size,
2210         __in                    unsigned int ndescs,
2211         __in                    unsigned int completed,
2212         __in                    unsigned int added);
2213
2214 extern          void
2215 efx_rx_qpush(
2216         __in    efx_rxq_t *erp,
2217         __in    unsigned int added,
2218         __inout unsigned int *pushedp);
2219
2220 #if EFSYS_OPT_RX_PACKED_STREAM
2221
2222 extern                  void
2223 efx_rx_qpush_ps_credits(
2224         __in            efx_rxq_t *erp);
2225
2226 extern  __checkReturn   uint8_t *
2227 efx_rx_qps_packet_info(
2228         __in            efx_rxq_t *erp,
2229         __in            uint8_t *buffer,
2230         __in            uint32_t buffer_length,
2231         __in            uint32_t current_offset,
2232         __out           uint16_t *lengthp,
2233         __out           uint32_t *next_offsetp,
2234         __out           uint32_t *timestamp);
2235 #endif
2236
2237 extern  __checkReturn   efx_rc_t
2238 efx_rx_qflush(
2239         __in    efx_rxq_t *erp);
2240
2241 extern          void
2242 efx_rx_qenable(
2243         __in    efx_rxq_t *erp);
2244
2245 extern          void
2246 efx_rx_qdestroy(
2247         __in    efx_rxq_t *erp);
2248
2249 /* TX */
2250
2251 typedef struct efx_txq_s        efx_txq_t;
2252
2253 #if EFSYS_OPT_QSTATS
2254
2255 /* START MKCONFIG GENERATED EfxHeaderTransmitQueueBlock 12dff8778598b2db */
2256 typedef enum efx_tx_qstat_e {
2257         TX_POST,
2258         TX_POST_PIO,
2259         TX_NQSTATS
2260 } efx_tx_qstat_t;
2261
2262 /* END MKCONFIG GENERATED EfxHeaderTransmitQueueBlock */
2263
2264 #endif  /* EFSYS_OPT_QSTATS */
2265
2266 extern  __checkReturn   efx_rc_t
2267 efx_tx_init(
2268         __in            efx_nic_t *enp);
2269
2270 extern          void
2271 efx_tx_fini(
2272         __in    efx_nic_t *enp);
2273
2274 #define EFX_TXQ_MINNDESCS               512
2275
2276 #define EFX_TXQ_SIZE(_ndescs)           ((_ndescs) * sizeof (efx_qword_t))
2277 #define EFX_TXQ_NBUFS(_ndescs)          (EFX_TXQ_SIZE(_ndescs) / EFX_BUF_SIZE)
2278 #define EFX_TXQ_LIMIT(_ndescs)          ((_ndescs) - 16)
2279
2280 #define EFX_TXQ_MAX_BUFS 8 /* Maximum independent of EFX_BUG35388_WORKAROUND. */
2281
2282 #define EFX_TXQ_CKSUM_IPV4              0x0001
2283 #define EFX_TXQ_CKSUM_TCPUDP            0x0002
2284 #define EFX_TXQ_FATSOV2                 0x0004
2285 #define EFX_TXQ_CKSUM_INNER_IPV4        0x0008
2286 #define EFX_TXQ_CKSUM_INNER_TCPUDP      0x0010
2287
2288 extern  __checkReturn   efx_rc_t
2289 efx_tx_qcreate(
2290         __in            efx_nic_t *enp,
2291         __in            unsigned int index,
2292         __in            unsigned int label,
2293         __in            efsys_mem_t *esmp,
2294         __in            size_t n,
2295         __in            uint32_t id,
2296         __in            uint16_t flags,
2297         __in            efx_evq_t *eep,
2298         __deref_out     efx_txq_t **etpp,
2299         __out           unsigned int *addedp);
2300
2301 extern  __checkReturn           efx_rc_t
2302 efx_tx_qpost(
2303         __in                    efx_txq_t *etp,
2304         __in_ecount(ndescs)     efx_buffer_t *eb,
2305         __in                    unsigned int ndescs,
2306         __in                    unsigned int completed,
2307         __inout                 unsigned int *addedp);
2308
2309 extern  __checkReturn   efx_rc_t
2310 efx_tx_qpace(
2311         __in            efx_txq_t *etp,
2312         __in            unsigned int ns);
2313
2314 extern                  void
2315 efx_tx_qpush(
2316         __in            efx_txq_t *etp,
2317         __in            unsigned int added,
2318         __in            unsigned int pushed);
2319
2320 extern  __checkReturn   efx_rc_t
2321 efx_tx_qflush(
2322         __in            efx_txq_t *etp);
2323
2324 extern                  void
2325 efx_tx_qenable(
2326         __in            efx_txq_t *etp);
2327
2328 extern  __checkReturn   efx_rc_t
2329 efx_tx_qpio_enable(
2330         __in            efx_txq_t *etp);
2331
2332 extern                  void
2333 efx_tx_qpio_disable(
2334         __in            efx_txq_t *etp);
2335
2336 extern  __checkReturn   efx_rc_t
2337 efx_tx_qpio_write(
2338         __in                    efx_txq_t *etp,
2339         __in_ecount(buf_length) uint8_t *buffer,
2340         __in                    size_t buf_length,
2341         __in                    size_t pio_buf_offset);
2342
2343 extern  __checkReturn   efx_rc_t
2344 efx_tx_qpio_post(
2345         __in                    efx_txq_t *etp,
2346         __in                    size_t pkt_length,
2347         __in                    unsigned int completed,
2348         __inout                 unsigned int *addedp);
2349
2350 extern  __checkReturn   efx_rc_t
2351 efx_tx_qdesc_post(
2352         __in            efx_txq_t *etp,
2353         __in_ecount(n)  efx_desc_t *ed,
2354         __in            unsigned int n,
2355         __in            unsigned int completed,
2356         __inout         unsigned int *addedp);
2357
2358 extern  void
2359 efx_tx_qdesc_dma_create(
2360         __in    efx_txq_t *etp,
2361         __in    efsys_dma_addr_t addr,
2362         __in    size_t size,
2363         __in    boolean_t eop,
2364         __out   efx_desc_t *edp);
2365
2366 extern  void
2367 efx_tx_qdesc_tso_create(
2368         __in    efx_txq_t *etp,
2369         __in    uint16_t ipv4_id,
2370         __in    uint32_t tcp_seq,
2371         __in    uint8_t  tcp_flags,
2372         __out   efx_desc_t *edp);
2373
2374 /* Number of FATSOv2 option descriptors */
2375 #define EFX_TX_FATSOV2_OPT_NDESCS               2
2376
2377 /* Maximum number of DMA segments per TSO packet (not superframe) */
2378 #define EFX_TX_FATSOV2_DMA_SEGS_PER_PKT_MAX     24
2379
2380 extern  void
2381 efx_tx_qdesc_tso2_create(
2382         __in                    efx_txq_t *etp,
2383         __in                    uint16_t ipv4_id,
2384         __in                    uint16_t outer_ipv4_id,
2385         __in                    uint32_t tcp_seq,
2386         __in                    uint16_t tcp_mss,
2387         __out_ecount(count)     efx_desc_t *edp,
2388         __in                    int count);
2389
2390 extern  void
2391 efx_tx_qdesc_vlantci_create(
2392         __in    efx_txq_t *etp,
2393         __in    uint16_t tci,
2394         __out   efx_desc_t *edp);
2395
2396 extern  void
2397 efx_tx_qdesc_checksum_create(
2398         __in    efx_txq_t *etp,
2399         __in    uint16_t flags,
2400         __out   efx_desc_t *edp);
2401
2402 #if EFSYS_OPT_QSTATS
2403
2404 #if EFSYS_OPT_NAMES
2405
2406 extern          const char *
2407 efx_tx_qstat_name(
2408         __in    efx_nic_t *etp,
2409         __in    unsigned int id);
2410
2411 #endif  /* EFSYS_OPT_NAMES */
2412
2413 extern                                  void
2414 efx_tx_qstats_update(
2415         __in                            efx_txq_t *etp,
2416         __inout_ecount(TX_NQSTATS)      efsys_stat_t *stat);
2417
2418 #endif  /* EFSYS_OPT_QSTATS */
2419
2420 extern          void
2421 efx_tx_qdestroy(
2422         __in    efx_txq_t *etp);
2423
2424
2425 /* FILTER */
2426
2427 #if EFSYS_OPT_FILTER
2428
2429 #define EFX_ETHER_TYPE_IPV4 0x0800
2430 #define EFX_ETHER_TYPE_IPV6 0x86DD
2431
2432 #define EFX_IPPROTO_TCP 6
2433 #define EFX_IPPROTO_UDP 17
2434 #define EFX_IPPROTO_GRE 47
2435
2436 /* Use RSS to spread across multiple queues */
2437 #define EFX_FILTER_FLAG_RX_RSS          0x01
2438 /* Enable RX scatter */
2439 #define EFX_FILTER_FLAG_RX_SCATTER      0x02
2440 /*
2441  * Override an automatic filter (priority EFX_FILTER_PRI_AUTO).
2442  * May only be set by the filter implementation for each type.
2443  * A removal request will restore the automatic filter in its place.
2444  */
2445 #define EFX_FILTER_FLAG_RX_OVER_AUTO    0x04
2446 /* Filter is for RX */
2447 #define EFX_FILTER_FLAG_RX              0x08
2448 /* Filter is for TX */
2449 #define EFX_FILTER_FLAG_TX              0x10
2450
2451 typedef uint8_t efx_filter_flags_t;
2452
2453 /*
2454  * Flags which specify the fields to match on. The values are the same as in the
2455  * MC_CMD_FILTER_OP/MC_CMD_FILTER_OP_EXT commands.
2456  */
2457
2458 /* Match by remote IP host address */
2459 #define EFX_FILTER_MATCH_REM_HOST               0x00000001
2460 /* Match by local IP host address */
2461 #define EFX_FILTER_MATCH_LOC_HOST               0x00000002
2462 /* Match by remote MAC address */
2463 #define EFX_FILTER_MATCH_REM_MAC                0x00000004
2464 /* Match by remote TCP/UDP port */
2465 #define EFX_FILTER_MATCH_REM_PORT               0x00000008
2466 /* Match by remote TCP/UDP port */
2467 #define EFX_FILTER_MATCH_LOC_MAC                0x00000010
2468 /* Match by local TCP/UDP port */
2469 #define EFX_FILTER_MATCH_LOC_PORT               0x00000020
2470 /* Match by Ether-type */
2471 #define EFX_FILTER_MATCH_ETHER_TYPE             0x00000040
2472 /* Match by inner VLAN ID */
2473 #define EFX_FILTER_MATCH_INNER_VID              0x00000080
2474 /* Match by outer VLAN ID */
2475 #define EFX_FILTER_MATCH_OUTER_VID              0x00000100
2476 /* Match by IP transport protocol */
2477 #define EFX_FILTER_MATCH_IP_PROTO               0x00000200
2478 /* For encapsulated packets, match all multicast inner frames */
2479 #define EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST 0x01000000
2480 /* For encapsulated packets, match all unicast inner frames */
2481 #define EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST 0x02000000
2482 /* Match otherwise-unmatched multicast and broadcast packets */
2483 #define EFX_FILTER_MATCH_UNKNOWN_MCAST_DST      0x40000000
2484 /* Match otherwise-unmatched unicast packets */
2485 #define EFX_FILTER_MATCH_UNKNOWN_UCAST_DST      0x80000000
2486
2487 typedef uint32_t efx_filter_match_flags_t;
2488
2489 typedef enum efx_filter_priority_s {
2490         EFX_FILTER_PRI_HINT = 0,        /* Performance hint */
2491         EFX_FILTER_PRI_AUTO,            /* Automatic filter based on device
2492                                          * address list or hardware
2493                                          * requirements. This may only be used
2494                                          * by the filter implementation for
2495                                          * each NIC type. */
2496         EFX_FILTER_PRI_MANUAL,          /* Manually configured filter */
2497         EFX_FILTER_PRI_REQUIRED,        /* Required for correct behaviour of the
2498                                          * client (e.g. SR-IOV, HyperV VMQ etc.)
2499                                          */
2500 } efx_filter_priority_t;
2501
2502 /*
2503  * FIXME: All these fields are assumed to be in little-endian byte order.
2504  * It may be better for some to be big-endian. See bug42804.
2505  */
2506
2507 typedef struct efx_filter_spec_s {
2508         efx_filter_match_flags_t        efs_match_flags;
2509         uint8_t                         efs_priority;
2510         efx_filter_flags_t              efs_flags;
2511         uint16_t                        efs_dmaq_id;
2512         uint32_t                        efs_rss_context;
2513         uint16_t                        efs_outer_vid;
2514         uint16_t                        efs_inner_vid;
2515         uint8_t                         efs_loc_mac[EFX_MAC_ADDR_LEN];
2516         uint8_t                         efs_rem_mac[EFX_MAC_ADDR_LEN];
2517         uint16_t                        efs_ether_type;
2518         uint8_t                         efs_ip_proto;
2519         efx_tunnel_protocol_t           efs_encap_type;
2520         uint16_t                        efs_loc_port;
2521         uint16_t                        efs_rem_port;
2522         efx_oword_t                     efs_rem_host;
2523         efx_oword_t                     efs_loc_host;
2524 } efx_filter_spec_t;
2525
2526
2527 /* Default values for use in filter specifications */
2528 #define EFX_FILTER_SPEC_RX_DMAQ_ID_DROP         0xfff
2529 #define EFX_FILTER_SPEC_VID_UNSPEC              0xffff
2530
2531 extern  __checkReturn   efx_rc_t
2532 efx_filter_init(
2533         __in            efx_nic_t *enp);
2534
2535 extern                  void
2536 efx_filter_fini(
2537         __in            efx_nic_t *enp);
2538
2539 extern  __checkReturn   efx_rc_t
2540 efx_filter_insert(
2541         __in            efx_nic_t *enp,
2542         __inout         efx_filter_spec_t *spec);
2543
2544 extern  __checkReturn   efx_rc_t
2545 efx_filter_remove(
2546         __in            efx_nic_t *enp,
2547         __inout         efx_filter_spec_t *spec);
2548
2549 extern  __checkReturn   efx_rc_t
2550 efx_filter_restore(
2551         __in            efx_nic_t *enp);
2552
2553 extern  __checkReturn   efx_rc_t
2554 efx_filter_supported_filters(
2555         __in                            efx_nic_t *enp,
2556         __out_ecount(buffer_length)     uint32_t *buffer,
2557         __in                            size_t buffer_length,
2558         __out                           size_t *list_lengthp);
2559
2560 extern                  void
2561 efx_filter_spec_init_rx(
2562         __out           efx_filter_spec_t *spec,
2563         __in            efx_filter_priority_t priority,
2564         __in            efx_filter_flags_t flags,
2565         __in            efx_rxq_t *erp);
2566
2567 extern                  void
2568 efx_filter_spec_init_tx(
2569         __out           efx_filter_spec_t *spec,
2570         __in            efx_txq_t *etp);
2571
2572 extern  __checkReturn   efx_rc_t
2573 efx_filter_spec_set_ipv4_local(
2574         __inout         efx_filter_spec_t *spec,
2575         __in            uint8_t proto,
2576         __in            uint32_t host,
2577         __in            uint16_t port);
2578
2579 extern  __checkReturn   efx_rc_t
2580 efx_filter_spec_set_ipv4_full(
2581         __inout         efx_filter_spec_t *spec,
2582         __in            uint8_t proto,
2583         __in            uint32_t lhost,
2584         __in            uint16_t lport,
2585         __in            uint32_t rhost,
2586         __in            uint16_t rport);
2587
2588 extern  __checkReturn   efx_rc_t
2589 efx_filter_spec_set_eth_local(
2590         __inout         efx_filter_spec_t *spec,
2591         __in            uint16_t vid,
2592         __in            const uint8_t *addr);
2593
2594 extern                  void
2595 efx_filter_spec_set_ether_type(
2596         __inout         efx_filter_spec_t *spec,
2597         __in            uint16_t ether_type);
2598
2599 extern  __checkReturn   efx_rc_t
2600 efx_filter_spec_set_uc_def(
2601         __inout         efx_filter_spec_t *spec);
2602
2603 extern  __checkReturn   efx_rc_t
2604 efx_filter_spec_set_mc_def(
2605         __inout         efx_filter_spec_t *spec);
2606
2607 typedef enum efx_filter_inner_frame_match_e {
2608         EFX_FILTER_INNER_FRAME_MATCH_OTHER = 0,
2609         EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST,
2610         EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_UCAST_DST
2611 } efx_filter_inner_frame_match_t;
2612
2613 extern  __checkReturn   efx_rc_t
2614 efx_filter_spec_set_encap_type(
2615         __inout         efx_filter_spec_t *spec,
2616         __in            efx_tunnel_protocol_t encap_type,
2617         __in            efx_filter_inner_frame_match_t inner_frame_match);
2618
2619 #if EFSYS_OPT_RX_SCALE
2620 extern  __checkReturn   efx_rc_t
2621 efx_filter_spec_set_rss_context(
2622         __inout         efx_filter_spec_t *spec,
2623         __in            uint32_t rss_context);
2624 #endif
2625 #endif  /* EFSYS_OPT_FILTER */
2626
2627 /* HASH */
2628
2629 extern  __checkReturn           uint32_t
2630 efx_hash_dwords(
2631         __in_ecount(count)      uint32_t const *input,
2632         __in                    size_t count,
2633         __in                    uint32_t init);
2634
2635 extern  __checkReturn           uint32_t
2636 efx_hash_bytes(
2637         __in_ecount(length)     uint8_t const *input,
2638         __in                    size_t length,
2639         __in                    uint32_t init);
2640
2641 #if EFSYS_OPT_LICENSING
2642
2643 /* LICENSING */
2644
2645 typedef struct efx_key_stats_s {
2646         uint32_t        eks_valid;
2647         uint32_t        eks_invalid;
2648         uint32_t        eks_blacklisted;
2649         uint32_t        eks_unverifiable;
2650         uint32_t        eks_wrong_node;
2651         uint32_t        eks_licensed_apps_lo;
2652         uint32_t        eks_licensed_apps_hi;
2653         uint32_t        eks_licensed_features_lo;
2654         uint32_t        eks_licensed_features_hi;
2655 } efx_key_stats_t;
2656
2657 extern  __checkReturn           efx_rc_t
2658 efx_lic_init(
2659         __in                    efx_nic_t *enp);
2660
2661 extern                          void
2662 efx_lic_fini(
2663         __in                    efx_nic_t *enp);
2664
2665 extern  __checkReturn   boolean_t
2666 efx_lic_check_support(
2667         __in                    efx_nic_t *enp);
2668
2669 extern  __checkReturn   efx_rc_t
2670 efx_lic_update_licenses(
2671         __in            efx_nic_t *enp);
2672
2673 extern  __checkReturn   efx_rc_t
2674 efx_lic_get_key_stats(
2675         __in            efx_nic_t *enp,
2676         __out           efx_key_stats_t *ksp);
2677
2678 extern  __checkReturn   efx_rc_t
2679 efx_lic_app_state(
2680         __in            efx_nic_t *enp,
2681         __in            uint64_t app_id,
2682         __out           boolean_t *licensedp);
2683
2684 extern  __checkReturn   efx_rc_t
2685 efx_lic_get_id(
2686         __in            efx_nic_t *enp,
2687         __in            size_t buffer_size,
2688         __out           uint32_t *typep,
2689         __out           size_t *lengthp,
2690         __out_opt       uint8_t *bufferp);
2691
2692
2693 extern  __checkReturn           efx_rc_t
2694 efx_lic_find_start(
2695         __in                    efx_nic_t *enp,
2696         __in_bcount(buffer_size)
2697                                 caddr_t bufferp,
2698         __in                    size_t buffer_size,
2699         __out                   uint32_t *startp);
2700
2701 extern  __checkReturn           efx_rc_t
2702 efx_lic_find_end(
2703         __in                    efx_nic_t *enp,
2704         __in_bcount(buffer_size)
2705                                 caddr_t bufferp,
2706         __in                    size_t buffer_size,
2707         __in                    uint32_t offset,
2708         __out                   uint32_t *endp);
2709
2710 extern  __checkReturn   __success(return != B_FALSE)    boolean_t
2711 efx_lic_find_key(
2712         __in                    efx_nic_t *enp,
2713         __in_bcount(buffer_size)
2714                                 caddr_t bufferp,
2715         __in                    size_t buffer_size,
2716         __in                    uint32_t offset,
2717         __out                   uint32_t *startp,
2718         __out                   uint32_t *lengthp);
2719
2720 extern  __checkReturn   __success(return != B_FALSE)    boolean_t
2721 efx_lic_validate_key(
2722         __in                    efx_nic_t *enp,
2723         __in_bcount(length)     caddr_t keyp,
2724         __in                    uint32_t length);
2725
2726 extern  __checkReturn           efx_rc_t
2727 efx_lic_read_key(
2728         __in                    efx_nic_t *enp,
2729         __in_bcount(buffer_size)
2730                                 caddr_t bufferp,
2731         __in                    size_t buffer_size,
2732         __in                    uint32_t offset,
2733         __in                    uint32_t length,
2734         __out_bcount_part(key_max_size, *lengthp)
2735                                 caddr_t keyp,
2736         __in                    size_t key_max_size,
2737         __out                   uint32_t *lengthp);
2738
2739 extern  __checkReturn           efx_rc_t
2740 efx_lic_write_key(
2741         __in                    efx_nic_t *enp,
2742         __in_bcount(buffer_size)
2743                                 caddr_t bufferp,
2744         __in                    size_t buffer_size,
2745         __in                    uint32_t offset,
2746         __in_bcount(length)     caddr_t keyp,
2747         __in                    uint32_t length,
2748         __out                   uint32_t *lengthp);
2749
2750         __checkReturn           efx_rc_t
2751 efx_lic_delete_key(
2752         __in                    efx_nic_t *enp,
2753         __in_bcount(buffer_size)
2754                                 caddr_t bufferp,
2755         __in                    size_t buffer_size,
2756         __in                    uint32_t offset,
2757         __in                    uint32_t length,
2758         __in                    uint32_t end,
2759         __out                   uint32_t *deltap);
2760
2761 extern  __checkReturn           efx_rc_t
2762 efx_lic_create_partition(
2763         __in                    efx_nic_t *enp,
2764         __in_bcount(buffer_size)
2765                                 caddr_t bufferp,
2766         __in                    size_t buffer_size);
2767
2768 extern  __checkReturn           efx_rc_t
2769 efx_lic_finish_partition(
2770         __in                    efx_nic_t *enp,
2771         __in_bcount(buffer_size)
2772                                 caddr_t bufferp,
2773         __in                    size_t buffer_size);
2774
2775 #endif  /* EFSYS_OPT_LICENSING */
2776
2777 /* TUNNEL */
2778
2779 #if EFSYS_OPT_TUNNEL
2780
2781 extern  __checkReturn   efx_rc_t
2782 efx_tunnel_init(
2783         __in            efx_nic_t *enp);
2784
2785 extern                  void
2786 efx_tunnel_fini(
2787         __in            efx_nic_t *enp);
2788
2789 /*
2790  * For overlay network encapsulation using UDP, the firmware needs to know
2791  * the configured UDP port for the overlay so it can decode encapsulated
2792  * frames correctly.
2793  * The UDP port/protocol list is global.
2794  */
2795
2796 extern  __checkReturn   efx_rc_t
2797 efx_tunnel_config_udp_add(
2798         __in            efx_nic_t *enp,
2799         __in            uint16_t port /* host/cpu-endian */,
2800         __in            efx_tunnel_protocol_t protocol);
2801
2802 extern  __checkReturn   efx_rc_t
2803 efx_tunnel_config_udp_remove(
2804         __in            efx_nic_t *enp,
2805         __in            uint16_t port /* host/cpu-endian */,
2806         __in            efx_tunnel_protocol_t protocol);
2807
2808 extern                  void
2809 efx_tunnel_config_clear(
2810         __in            efx_nic_t *enp);
2811
2812 /**
2813  * Apply tunnel UDP ports configuration to hardware.
2814  *
2815  * EAGAIN is returned if hardware will be reset (datapath and managment CPU
2816  * reboot).
2817  */
2818 extern  __checkReturn   efx_rc_t
2819 efx_tunnel_reconfigure(
2820         __in            efx_nic_t *enp);
2821
2822 #endif /* EFSYS_OPT_TUNNEL */
2823
2824
2825 #ifdef  __cplusplus
2826 }
2827 #endif
2828
2829 #endif  /* _SYS_EFX_H */