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