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