net/sfc/base: import PHY flags control
[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 /* Return codes */
52
53 typedef __success(return == 0) int efx_rc_t;
54
55
56 /* Chip families */
57
58 typedef enum efx_family_e {
59         EFX_FAMILY_INVALID,
60         EFX_FAMILY_FALCON,      /* Obsolete and not supported */
61         EFX_FAMILY_SIENA,
62         EFX_FAMILY_HUNTINGTON,
63         EFX_FAMILY_MEDFORD,
64         EFX_FAMILY_NTYPES
65 } efx_family_t;
66
67 extern  __checkReturn   efx_rc_t
68 efx_family(
69         __in            uint16_t venid,
70         __in            uint16_t devid,
71         __out           efx_family_t *efp);
72
73
74 #define EFX_PCI_VENID_SFC                       0x1924
75
76 #define EFX_PCI_DEVID_FALCON                    0x0710  /* SFC4000 */
77
78 #define EFX_PCI_DEVID_BETHPAGE                  0x0803  /* SFC9020 */
79 #define EFX_PCI_DEVID_SIENA                     0x0813  /* SFL9021 */
80 #define EFX_PCI_DEVID_SIENA_F1_UNINIT           0x0810
81
82 #define EFX_PCI_DEVID_HUNTINGTON_PF_UNINIT      0x0901
83 #define EFX_PCI_DEVID_FARMINGDALE               0x0903  /* SFC9120 PF */
84 #define EFX_PCI_DEVID_GREENPORT                 0x0923  /* SFC9140 PF */
85
86 #define EFX_PCI_DEVID_FARMINGDALE_VF            0x1903  /* SFC9120 VF */
87 #define EFX_PCI_DEVID_GREENPORT_VF              0x1923  /* SFC9140 VF */
88
89 #define EFX_PCI_DEVID_MEDFORD_PF_UNINIT         0x0913
90 #define EFX_PCI_DEVID_MEDFORD                   0x0A03  /* SFC9240 PF */
91 #define EFX_PCI_DEVID_MEDFORD_VF                0x1A03  /* SFC9240 VF */
92
93 #define EFX_MEM_BAR     2
94
95 /* Error codes */
96
97 enum {
98         EFX_ERR_INVALID,
99         EFX_ERR_SRAM_OOB,
100         EFX_ERR_BUFID_DC_OOB,
101         EFX_ERR_MEM_PERR,
102         EFX_ERR_RBUF_OWN,
103         EFX_ERR_TBUF_OWN,
104         EFX_ERR_RDESQ_OWN,
105         EFX_ERR_TDESQ_OWN,
106         EFX_ERR_EVQ_OWN,
107         EFX_ERR_EVFF_OFLO,
108         EFX_ERR_ILL_ADDR,
109         EFX_ERR_SRAM_PERR,
110         EFX_ERR_NCODES
111 };
112
113 /* Calculate the IEEE 802.3 CRC32 of a MAC addr */
114 extern  __checkReturn           uint32_t
115 efx_crc32_calculate(
116         __in                    uint32_t crc_init,
117         __in_ecount(length)     uint8_t const *input,
118         __in                    int length);
119
120
121 /* Type prototypes */
122
123 typedef struct efx_rxq_s        efx_rxq_t;
124
125 /* NIC */
126
127 typedef struct efx_nic_s        efx_nic_t;
128
129 extern  __checkReturn   efx_rc_t
130 efx_nic_create(
131         __in            efx_family_t family,
132         __in            efsys_identifier_t *esip,
133         __in            efsys_bar_t *esbp,
134         __in            efsys_lock_t *eslp,
135         __deref_out     efx_nic_t **enpp);
136
137 extern  __checkReturn   efx_rc_t
138 efx_nic_probe(
139         __in            efx_nic_t *enp);
140
141 extern  __checkReturn   efx_rc_t
142 efx_nic_init(
143         __in            efx_nic_t *enp);
144
145 extern  __checkReturn   efx_rc_t
146 efx_nic_reset(
147         __in            efx_nic_t *enp);
148
149 #if EFSYS_OPT_DIAG
150
151 extern  __checkReturn   efx_rc_t
152 efx_nic_register_test(
153         __in            efx_nic_t *enp);
154
155 #endif  /* EFSYS_OPT_DIAG */
156
157 extern          void
158 efx_nic_fini(
159         __in            efx_nic_t *enp);
160
161 extern          void
162 efx_nic_unprobe(
163         __in            efx_nic_t *enp);
164
165 extern          void
166 efx_nic_destroy(
167         __in    efx_nic_t *enp);
168
169 #define EFX_PCIE_LINK_SPEED_GEN1                1
170 #define EFX_PCIE_LINK_SPEED_GEN2                2
171 #define EFX_PCIE_LINK_SPEED_GEN3                3
172
173 typedef enum efx_pcie_link_performance_e {
174         EFX_PCIE_LINK_PERFORMANCE_UNKNOWN_BANDWIDTH,
175         EFX_PCIE_LINK_PERFORMANCE_SUBOPTIMAL_BANDWIDTH,
176         EFX_PCIE_LINK_PERFORMANCE_SUBOPTIMAL_LATENCY,
177         EFX_PCIE_LINK_PERFORMANCE_OPTIMAL
178 } efx_pcie_link_performance_t;
179
180 extern  __checkReturn   efx_rc_t
181 efx_nic_calculate_pcie_link_bandwidth(
182         __in            uint32_t pcie_link_width,
183         __in            uint32_t pcie_link_gen,
184         __out           uint32_t *bandwidth_mbpsp);
185
186 extern  __checkReturn   efx_rc_t
187 efx_nic_check_pcie_link_speed(
188         __in            efx_nic_t *enp,
189         __in            uint32_t pcie_link_width,
190         __in            uint32_t pcie_link_gen,
191         __out           efx_pcie_link_performance_t *resultp);
192
193 #if EFSYS_OPT_MCDI
194
195 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
196 /* Huntington and Medford require MCDIv2 commands */
197 #define WITH_MCDI_V2 1
198 #endif
199
200 typedef struct efx_mcdi_req_s efx_mcdi_req_t;
201
202 typedef enum efx_mcdi_exception_e {
203         EFX_MCDI_EXCEPTION_MC_REBOOT,
204         EFX_MCDI_EXCEPTION_MC_BADASSERT,
205 } efx_mcdi_exception_t;
206
207 #if EFSYS_OPT_MCDI_LOGGING
208 typedef enum efx_log_msg_e {
209         EFX_LOG_INVALID,
210         EFX_LOG_MCDI_REQUEST,
211         EFX_LOG_MCDI_RESPONSE,
212 } efx_log_msg_t;
213 #endif /* EFSYS_OPT_MCDI_LOGGING */
214
215 typedef struct efx_mcdi_transport_s {
216         void            *emt_context;
217         efsys_mem_t     *emt_dma_mem;
218         void            (*emt_execute)(void *, efx_mcdi_req_t *);
219         void            (*emt_ev_cpl)(void *);
220         void            (*emt_exception)(void *, efx_mcdi_exception_t);
221 #if EFSYS_OPT_MCDI_LOGGING
222         void            (*emt_logger)(void *, efx_log_msg_t,
223                                         void *, size_t, void *, size_t);
224 #endif /* EFSYS_OPT_MCDI_LOGGING */
225 #if EFSYS_OPT_MCDI_PROXY_AUTH
226         void            (*emt_ev_proxy_response)(void *, uint32_t, efx_rc_t);
227 #endif /* EFSYS_OPT_MCDI_PROXY_AUTH */
228 } efx_mcdi_transport_t;
229
230 extern  __checkReturn   efx_rc_t
231 efx_mcdi_init(
232         __in            efx_nic_t *enp,
233         __in            const efx_mcdi_transport_t *mtp);
234
235 extern  __checkReturn   efx_rc_t
236 efx_mcdi_reboot(
237         __in            efx_nic_t *enp);
238
239                         void
240 efx_mcdi_new_epoch(
241         __in            efx_nic_t *enp);
242
243 extern                  void
244 efx_mcdi_get_timeout(
245         __in            efx_nic_t *enp,
246         __in            efx_mcdi_req_t *emrp,
247         __out           uint32_t *usec_timeoutp);
248
249 extern                  void
250 efx_mcdi_request_start(
251         __in            efx_nic_t *enp,
252         __in            efx_mcdi_req_t *emrp,
253         __in            boolean_t ev_cpl);
254
255 extern  __checkReturn   boolean_t
256 efx_mcdi_request_poll(
257         __in            efx_nic_t *enp);
258
259 extern  __checkReturn   boolean_t
260 efx_mcdi_request_abort(
261         __in            efx_nic_t *enp);
262
263 extern                  void
264 efx_mcdi_fini(
265         __in            efx_nic_t *enp);
266
267 #endif  /* EFSYS_OPT_MCDI */
268
269 /* INTR */
270
271 #define EFX_NINTR_SIENA 1024
272
273 typedef enum efx_intr_type_e {
274         EFX_INTR_INVALID = 0,
275         EFX_INTR_LINE,
276         EFX_INTR_MESSAGE,
277         EFX_INTR_NTYPES
278 } efx_intr_type_t;
279
280 #define EFX_INTR_SIZE   (sizeof (efx_oword_t))
281
282 extern  __checkReturn   efx_rc_t
283 efx_intr_init(
284         __in            efx_nic_t *enp,
285         __in            efx_intr_type_t type,
286         __in            efsys_mem_t *esmp);
287
288 extern                  void
289 efx_intr_enable(
290         __in            efx_nic_t *enp);
291
292 extern                  void
293 efx_intr_disable(
294         __in            efx_nic_t *enp);
295
296 extern                  void
297 efx_intr_disable_unlocked(
298         __in            efx_nic_t *enp);
299
300 #define EFX_INTR_NEVQS  32
301
302 extern  __checkReturn   efx_rc_t
303 efx_intr_trigger(
304         __in            efx_nic_t *enp,
305         __in            unsigned int level);
306
307 extern                  void
308 efx_intr_status_line(
309         __in            efx_nic_t *enp,
310         __out           boolean_t *fatalp,
311         __out           uint32_t *maskp);
312
313 extern                  void
314 efx_intr_status_message(
315         __in            efx_nic_t *enp,
316         __in            unsigned int message,
317         __out           boolean_t *fatalp);
318
319 extern                  void
320 efx_intr_fatal(
321         __in            efx_nic_t *enp);
322
323 extern                  void
324 efx_intr_fini(
325         __in            efx_nic_t *enp);
326
327 /* MAC */
328
329 typedef enum efx_link_mode_e {
330         EFX_LINK_UNKNOWN = 0,
331         EFX_LINK_DOWN,
332         EFX_LINK_10HDX,
333         EFX_LINK_10FDX,
334         EFX_LINK_100HDX,
335         EFX_LINK_100FDX,
336         EFX_LINK_1000HDX,
337         EFX_LINK_1000FDX,
338         EFX_LINK_10000FDX,
339         EFX_LINK_40000FDX,
340         EFX_LINK_NMODES
341 } efx_link_mode_t;
342
343 #define EFX_MAC_ADDR_LEN 6
344
345 #define EFX_MAC_ADDR_IS_MULTICAST(_address) (((uint8_t *)_address)[0] & 0x01)
346
347 #define EFX_MAC_MULTICAST_LIST_MAX      256
348
349 #define EFX_MAC_SDU_MAX 9202
350
351 #define EFX_MAC_PDU_ADJUSTMENT                                  \
352         (/* EtherII */ 14                                       \
353             + /* VLAN */ 4                                      \
354             + /* CRC */ 4                                       \
355             + /* bug16011 */ 16)                                \
356
357 #define EFX_MAC_PDU(_sdu)                                       \
358         P2ROUNDUP((_sdu) + EFX_MAC_PDU_ADJUSTMENT, 8)
359
360 /*
361  * Due to the P2ROUNDUP in EFX_MAC_PDU(), EFX_MAC_SDU_FROM_PDU() may give
362  * the SDU rounded up slightly.
363  */
364 #define EFX_MAC_SDU_FROM_PDU(_pdu)      ((_pdu) - EFX_MAC_PDU_ADJUSTMENT)
365
366 #define EFX_MAC_PDU_MIN 60
367 #define EFX_MAC_PDU_MAX EFX_MAC_PDU(EFX_MAC_SDU_MAX)
368
369 extern  __checkReturn   efx_rc_t
370 efx_mac_pdu_get(
371         __in            efx_nic_t *enp,
372         __out           size_t *pdu);
373
374 extern  __checkReturn   efx_rc_t
375 efx_mac_pdu_set(
376         __in            efx_nic_t *enp,
377         __in            size_t pdu);
378
379 extern  __checkReturn   efx_rc_t
380 efx_mac_addr_set(
381         __in            efx_nic_t *enp,
382         __in            uint8_t *addr);
383
384 extern  __checkReturn                   efx_rc_t
385 efx_mac_filter_set(
386         __in                            efx_nic_t *enp,
387         __in                            boolean_t all_unicst,
388         __in                            boolean_t mulcst,
389         __in                            boolean_t all_mulcst,
390         __in                            boolean_t brdcst);
391
392 extern  __checkReturn   efx_rc_t
393 efx_mac_multicast_list_set(
394         __in                            efx_nic_t *enp,
395         __in_ecount(6*count)            uint8_t const *addrs,
396         __in                            int count);
397
398 extern  __checkReturn   efx_rc_t
399 efx_mac_filter_default_rxq_set(
400         __in            efx_nic_t *enp,
401         __in            efx_rxq_t *erp,
402         __in            boolean_t using_rss);
403
404 extern                  void
405 efx_mac_filter_default_rxq_clear(
406         __in            efx_nic_t *enp);
407
408 extern  __checkReturn   efx_rc_t
409 efx_mac_drain(
410         __in            efx_nic_t *enp,
411         __in            boolean_t enabled);
412
413 extern  __checkReturn   efx_rc_t
414 efx_mac_up(
415         __in            efx_nic_t *enp,
416         __out           boolean_t *mac_upp);
417
418 #define EFX_FCNTL_RESPOND       0x00000001
419 #define EFX_FCNTL_GENERATE      0x00000002
420
421 extern  __checkReturn   efx_rc_t
422 efx_mac_fcntl_set(
423         __in            efx_nic_t *enp,
424         __in            unsigned int fcntl,
425         __in            boolean_t autoneg);
426
427 extern                  void
428 efx_mac_fcntl_get(
429         __in            efx_nic_t *enp,
430         __out           unsigned int *fcntl_wantedp,
431         __out           unsigned int *fcntl_linkp);
432
433
434 /* MON */
435
436 typedef enum efx_mon_type_e {
437         EFX_MON_INVALID = 0,
438         EFX_MON_SFC90X0,
439         EFX_MON_SFC91X0,
440         EFX_MON_SFC92X0,
441         EFX_MON_NTYPES
442 } efx_mon_type_t;
443
444 #if EFSYS_OPT_NAMES
445
446 extern          const char *
447 efx_mon_name(
448         __in    efx_nic_t *enp);
449
450 #endif  /* EFSYS_OPT_NAMES */
451
452 extern  __checkReturn   efx_rc_t
453 efx_mon_init(
454         __in            efx_nic_t *enp);
455
456 extern          void
457 efx_mon_fini(
458         __in    efx_nic_t *enp);
459
460 /* PHY */
461
462 extern  __checkReturn   efx_rc_t
463 efx_phy_verify(
464         __in            efx_nic_t *enp);
465
466 extern  __checkReturn   efx_rc_t
467 efx_port_init(
468         __in            efx_nic_t *enp);
469
470 extern  __checkReturn   efx_rc_t
471 efx_port_poll(
472         __in            efx_nic_t *enp,
473         __out_opt       efx_link_mode_t *link_modep);
474
475 extern          void
476 efx_port_fini(
477         __in    efx_nic_t *enp);
478
479 typedef enum efx_phy_cap_type_e {
480         EFX_PHY_CAP_INVALID = 0,
481         EFX_PHY_CAP_10HDX,
482         EFX_PHY_CAP_10FDX,
483         EFX_PHY_CAP_100HDX,
484         EFX_PHY_CAP_100FDX,
485         EFX_PHY_CAP_1000HDX,
486         EFX_PHY_CAP_1000FDX,
487         EFX_PHY_CAP_10000FDX,
488         EFX_PHY_CAP_PAUSE,
489         EFX_PHY_CAP_ASYM,
490         EFX_PHY_CAP_AN,
491         EFX_PHY_CAP_40000FDX,
492         EFX_PHY_CAP_NTYPES
493 } efx_phy_cap_type_t;
494
495
496 #define EFX_PHY_CAP_CURRENT     0x00000000
497 #define EFX_PHY_CAP_DEFAULT     0x00000001
498 #define EFX_PHY_CAP_PERM        0x00000002
499
500 extern          void
501 efx_phy_adv_cap_get(
502         __in            efx_nic_t *enp,
503         __in            uint32_t flag,
504         __out           uint32_t *maskp);
505
506 extern  __checkReturn   efx_rc_t
507 efx_phy_adv_cap_set(
508         __in            efx_nic_t *enp,
509         __in            uint32_t mask);
510
511 extern                  void
512 efx_phy_lp_cap_get(
513         __in            efx_nic_t *enp,
514         __out           uint32_t *maskp);
515
516 extern  __checkReturn   efx_rc_t
517 efx_phy_oui_get(
518         __in            efx_nic_t *enp,
519         __out           uint32_t *ouip);
520
521 typedef enum efx_phy_media_type_e {
522         EFX_PHY_MEDIA_INVALID = 0,
523         EFX_PHY_MEDIA_XAUI,
524         EFX_PHY_MEDIA_CX4,
525         EFX_PHY_MEDIA_KX4,
526         EFX_PHY_MEDIA_XFP,
527         EFX_PHY_MEDIA_SFP_PLUS,
528         EFX_PHY_MEDIA_BASE_T,
529         EFX_PHY_MEDIA_QSFP_PLUS,
530         EFX_PHY_MEDIA_NTYPES
531 } efx_phy_media_type_t;
532
533 /* Get the type of medium currently used.  If the board has ports for
534  * modules, a module is present, and we recognise the media type of
535  * the module, then this will be the media type of the module.
536  * Otherwise it will be the media type of the port.
537  */
538 extern                  void
539 efx_phy_media_type_get(
540         __in            efx_nic_t *enp,
541         __out           efx_phy_media_type_t *typep);
542
543 extern                                  efx_rc_t
544 efx_phy_module_get_info(
545         __in                            efx_nic_t *enp,
546         __in                            uint8_t dev_addr,
547         __in                            uint8_t offset,
548         __in                            uint8_t len,
549         __out_bcount(len)               uint8_t *data);
550
551
552 #if EFSYS_OPT_BIST
553
554 typedef enum efx_bist_type_e {
555         EFX_BIST_TYPE_UNKNOWN,
556         EFX_BIST_TYPE_PHY_NORMAL,
557         EFX_BIST_TYPE_PHY_CABLE_SHORT,
558         EFX_BIST_TYPE_PHY_CABLE_LONG,
559         EFX_BIST_TYPE_MC_MEM,   /* Test the MC DMEM and IMEM */
560         EFX_BIST_TYPE_SAT_MEM,  /* Test the DMEM and IMEM of satellite cpus*/
561         EFX_BIST_TYPE_REG,      /* Test the register memories */
562         EFX_BIST_TYPE_NTYPES,
563 } efx_bist_type_t;
564
565 typedef enum efx_bist_result_e {
566         EFX_BIST_RESULT_UNKNOWN,
567         EFX_BIST_RESULT_RUNNING,
568         EFX_BIST_RESULT_PASSED,
569         EFX_BIST_RESULT_FAILED,
570 } efx_bist_result_t;
571
572 typedef enum efx_phy_cable_status_e {
573         EFX_PHY_CABLE_STATUS_OK,
574         EFX_PHY_CABLE_STATUS_INVALID,
575         EFX_PHY_CABLE_STATUS_OPEN,
576         EFX_PHY_CABLE_STATUS_INTRAPAIRSHORT,
577         EFX_PHY_CABLE_STATUS_INTERPAIRSHORT,
578         EFX_PHY_CABLE_STATUS_BUSY,
579 } efx_phy_cable_status_t;
580
581 typedef enum efx_bist_value_e {
582         EFX_BIST_PHY_CABLE_LENGTH_A,
583         EFX_BIST_PHY_CABLE_LENGTH_B,
584         EFX_BIST_PHY_CABLE_LENGTH_C,
585         EFX_BIST_PHY_CABLE_LENGTH_D,
586         EFX_BIST_PHY_CABLE_STATUS_A,
587         EFX_BIST_PHY_CABLE_STATUS_B,
588         EFX_BIST_PHY_CABLE_STATUS_C,
589         EFX_BIST_PHY_CABLE_STATUS_D,
590         EFX_BIST_FAULT_CODE,
591         /* Memory BIST specific values. These match to the MC_CMD_BIST_POLL
592          * response. */
593         EFX_BIST_MEM_TEST,
594         EFX_BIST_MEM_ADDR,
595         EFX_BIST_MEM_BUS,
596         EFX_BIST_MEM_EXPECT,
597         EFX_BIST_MEM_ACTUAL,
598         EFX_BIST_MEM_ECC,
599         EFX_BIST_MEM_ECC_PARITY,
600         EFX_BIST_MEM_ECC_FATAL,
601         EFX_BIST_NVALUES,
602 } efx_bist_value_t;
603
604 extern  __checkReturn           efx_rc_t
605 efx_bist_enable_offline(
606         __in                    efx_nic_t *enp);
607
608 extern  __checkReturn           efx_rc_t
609 efx_bist_start(
610         __in                    efx_nic_t *enp,
611         __in                    efx_bist_type_t type);
612
613 extern  __checkReturn           efx_rc_t
614 efx_bist_poll(
615         __in                    efx_nic_t *enp,
616         __in                    efx_bist_type_t type,
617         __out                   efx_bist_result_t *resultp,
618         __out_opt               uint32_t *value_maskp,
619         __out_ecount_opt(count) unsigned long *valuesp,
620         __in                    size_t count);
621
622 extern                          void
623 efx_bist_stop(
624         __in                    efx_nic_t *enp,
625         __in                    efx_bist_type_t type);
626
627 #endif  /* EFSYS_OPT_BIST */
628
629 #define EFX_FEATURE_IPV6                0x00000001
630 #define EFX_FEATURE_LFSR_HASH_INSERT    0x00000002
631 #define EFX_FEATURE_LINK_EVENTS         0x00000004
632 #define EFX_FEATURE_PERIODIC_MAC_STATS  0x00000008
633 #define EFX_FEATURE_MCDI                0x00000020
634 #define EFX_FEATURE_LOOKAHEAD_SPLIT     0x00000040
635 #define EFX_FEATURE_MAC_HEADER_FILTERS  0x00000080
636 #define EFX_FEATURE_TURBO               0x00000100
637 #define EFX_FEATURE_MCDI_DMA            0x00000200
638 #define EFX_FEATURE_TX_SRC_FILTERS      0x00000400
639 #define EFX_FEATURE_PIO_BUFFERS         0x00000800
640 #define EFX_FEATURE_FW_ASSISTED_TSO     0x00001000
641 #define EFX_FEATURE_FW_ASSISTED_TSO_V2  0x00002000
642 #define EFX_FEATURE_PACKED_STREAM       0x00004000
643
644 typedef struct efx_nic_cfg_s {
645         uint32_t                enc_board_type;
646         uint32_t                enc_phy_type;
647 #if EFSYS_OPT_NAMES
648         char                    enc_phy_name[21];
649 #endif
650         char                    enc_phy_revision[21];
651         efx_mon_type_t          enc_mon_type;
652         unsigned int            enc_features;
653         uint8_t                 enc_mac_addr[6];
654         uint8_t                 enc_port;       /* PHY port number */
655         uint32_t                enc_intr_vec_base;
656         uint32_t                enc_intr_limit;
657         uint32_t                enc_evq_limit;
658         uint32_t                enc_txq_limit;
659         uint32_t                enc_rxq_limit;
660         uint32_t                enc_txq_max_ndescs;
661         uint32_t                enc_buftbl_limit;
662         uint32_t                enc_piobuf_limit;
663         uint32_t                enc_piobuf_size;
664         uint32_t                enc_piobuf_min_alloc_size;
665         uint32_t                enc_evq_timer_quantum_ns;
666         uint32_t                enc_evq_timer_max_us;
667         uint32_t                enc_clk_mult;
668         uint32_t                enc_rx_prefix_size;
669         uint32_t                enc_rx_buf_align_start;
670         uint32_t                enc_rx_buf_align_end;
671 #if EFSYS_OPT_PHY_FLAGS
672         uint32_t                enc_phy_flags_mask;
673 #endif  /* EFSYS_OPT_PHY_FLAGS */
674 #if EFSYS_OPT_MCDI
675         uint8_t                 enc_mcdi_mdio_channel;
676 #endif  /* EFSYS_OPT_MCDI */
677 #if EFSYS_OPT_BIST
678         uint32_t                enc_bist_mask;
679 #endif  /* EFSYS_OPT_BIST */
680 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
681         uint32_t                enc_pf;
682         uint32_t                enc_vf;
683         uint32_t                enc_privilege_mask;
684 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
685         boolean_t               enc_bug26807_workaround;
686         boolean_t               enc_bug35388_workaround;
687         boolean_t               enc_bug41750_workaround;
688         boolean_t               enc_bug61265_workaround;
689         boolean_t               enc_rx_batching_enabled;
690         /* Maximum number of descriptors completed in an rx event. */
691         uint32_t                enc_rx_batch_max;
692         /* Number of rx descriptors the hardware requires for a push. */
693         uint32_t                enc_rx_push_align;
694         /*
695          * Maximum number of bytes into the packet the TCP header can start for
696          * the hardware to apply TSO packet edits.
697          */
698         uint32_t                enc_tx_tso_tcp_header_offset_limit;
699         boolean_t               enc_fw_assisted_tso_enabled;
700         boolean_t               enc_fw_assisted_tso_v2_enabled;
701         /* Number of TSO contexts on the NIC (FATSOv2) */
702         uint32_t                enc_fw_assisted_tso_v2_n_contexts;
703         boolean_t               enc_hw_tx_insert_vlan_enabled;
704         /* Number of PFs on the NIC */
705         uint32_t                enc_hw_pf_count;
706         /* Datapath firmware vadapter/vport/vswitch support */
707         boolean_t               enc_datapath_cap_evb;
708         boolean_t               enc_rx_disable_scatter_supported;
709         boolean_t               enc_allow_set_mac_with_installed_filters;
710         boolean_t               enc_enhanced_set_mac_supported;
711         boolean_t               enc_init_evq_v2_supported;
712         boolean_t               enc_rx_packed_stream_supported;
713         boolean_t               enc_rx_var_packed_stream_supported;
714         boolean_t               enc_pm_and_rxdp_counters;
715         boolean_t               enc_mac_stats_40g_tx_size_bins;
716         /* External port identifier */
717         uint8_t                 enc_external_port;
718         uint32_t                enc_mcdi_max_payload_length;
719         /* VPD may be per-PF or global */
720         boolean_t               enc_vpd_is_global;
721         /* Minimum unidirectional bandwidth in Mb/s to max out all ports */
722         uint32_t                enc_required_pcie_bandwidth_mbps;
723         uint32_t                enc_max_pcie_link_gen;
724         /* Firmware verifies integrity of NVRAM updates */
725         uint32_t                enc_fw_verified_nvram_update_required;
726 } efx_nic_cfg_t;
727
728 #define EFX_PCI_FUNCTION_IS_PF(_encp)   ((_encp)->enc_vf == 0xffff)
729 #define EFX_PCI_FUNCTION_IS_VF(_encp)   ((_encp)->enc_vf != 0xffff)
730
731 #define EFX_PCI_FUNCTION(_encp) \
732         (EFX_PCI_FUNCTION_IS_PF(_encp) ? (_encp)->enc_pf : (_encp)->enc_vf)
733
734 #define EFX_PCI_VF_PARENT(_encp)        ((_encp)->enc_pf)
735
736 extern                  const efx_nic_cfg_t *
737 efx_nic_cfg_get(
738         __in            efx_nic_t *enp);
739
740 /* Driver resource limits (minimum required/maximum usable). */
741 typedef struct efx_drv_limits_s {
742         uint32_t        edl_min_evq_count;
743         uint32_t        edl_max_evq_count;
744
745         uint32_t        edl_min_rxq_count;
746         uint32_t        edl_max_rxq_count;
747
748         uint32_t        edl_min_txq_count;
749         uint32_t        edl_max_txq_count;
750
751         /* PIO blocks (sub-allocated from piobuf) */
752         uint32_t        edl_min_pio_alloc_size;
753         uint32_t        edl_max_pio_alloc_count;
754 } efx_drv_limits_t;
755
756 extern  __checkReturn   efx_rc_t
757 efx_nic_set_drv_limits(
758         __inout         efx_nic_t *enp,
759         __in            efx_drv_limits_t *edlp);
760
761 typedef enum efx_nic_region_e {
762         EFX_REGION_VI,                  /* Memory BAR UC mapping */
763         EFX_REGION_PIO_WRITE_VI,        /* Memory BAR WC mapping */
764 } efx_nic_region_t;
765
766 extern  __checkReturn   efx_rc_t
767 efx_nic_get_bar_region(
768         __in            efx_nic_t *enp,
769         __in            efx_nic_region_t region,
770         __out           uint32_t *offsetp,
771         __out           size_t *sizep);
772
773 extern  __checkReturn   efx_rc_t
774 efx_nic_get_vi_pool(
775         __in            efx_nic_t *enp,
776         __out           uint32_t *evq_countp,
777         __out           uint32_t *rxq_countp,
778         __out           uint32_t *txq_countp);
779
780
781 /* NVRAM */
782
783 #if EFSYS_OPT_DIAG
784
785 typedef enum efx_pattern_type_t {
786         EFX_PATTERN_BYTE_INCREMENT = 0,
787         EFX_PATTERN_ALL_THE_SAME,
788         EFX_PATTERN_BIT_ALTERNATE,
789         EFX_PATTERN_BYTE_ALTERNATE,
790         EFX_PATTERN_BYTE_CHANGING,
791         EFX_PATTERN_BIT_SWEEP,
792         EFX_PATTERN_NTYPES
793 } efx_pattern_type_t;
794
795 typedef                 void
796 (*efx_sram_pattern_fn_t)(
797         __in            size_t row,
798         __in            boolean_t negate,
799         __out           efx_qword_t *eqp);
800
801 extern  __checkReturn   efx_rc_t
802 efx_sram_test(
803         __in            efx_nic_t *enp,
804         __in            efx_pattern_type_t type);
805
806 #endif  /* EFSYS_OPT_DIAG */
807
808 extern  __checkReturn   efx_rc_t
809 efx_sram_buf_tbl_set(
810         __in            efx_nic_t *enp,
811         __in            uint32_t id,
812         __in            efsys_mem_t *esmp,
813         __in            size_t n);
814
815 extern          void
816 efx_sram_buf_tbl_clear(
817         __in    efx_nic_t *enp,
818         __in    uint32_t id,
819         __in    size_t n);
820
821 #define EFX_BUF_TBL_SIZE        0x20000
822
823 #define EFX_BUF_SIZE            4096
824
825 /* EV */
826
827 typedef struct efx_evq_s        efx_evq_t;
828
829 #if EFSYS_OPT_QSTATS
830
831 /* START MKCONFIG GENERATED EfxHeaderEventQueueBlock 6f3843f5fe7cc843 */
832 typedef enum efx_ev_qstat_e {
833         EV_ALL,
834         EV_RX,
835         EV_RX_OK,
836         EV_RX_FRM_TRUNC,
837         EV_RX_TOBE_DISC,
838         EV_RX_PAUSE_FRM_ERR,
839         EV_RX_BUF_OWNER_ID_ERR,
840         EV_RX_IPV4_HDR_CHKSUM_ERR,
841         EV_RX_TCP_UDP_CHKSUM_ERR,
842         EV_RX_ETH_CRC_ERR,
843         EV_RX_IP_FRAG_ERR,
844         EV_RX_MCAST_PKT,
845         EV_RX_MCAST_HASH_MATCH,
846         EV_RX_TCP_IPV4,
847         EV_RX_TCP_IPV6,
848         EV_RX_UDP_IPV4,
849         EV_RX_UDP_IPV6,
850         EV_RX_OTHER_IPV4,
851         EV_RX_OTHER_IPV6,
852         EV_RX_NON_IP,
853         EV_RX_BATCH,
854         EV_TX,
855         EV_TX_WQ_FF_FULL,
856         EV_TX_PKT_ERR,
857         EV_TX_PKT_TOO_BIG,
858         EV_TX_UNEXPECTED,
859         EV_GLOBAL,
860         EV_GLOBAL_MNT,
861         EV_DRIVER,
862         EV_DRIVER_SRM_UPD_DONE,
863         EV_DRIVER_TX_DESCQ_FLS_DONE,
864         EV_DRIVER_RX_DESCQ_FLS_DONE,
865         EV_DRIVER_RX_DESCQ_FLS_FAILED,
866         EV_DRIVER_RX_DSC_ERROR,
867         EV_DRIVER_TX_DSC_ERROR,
868         EV_DRV_GEN,
869         EV_MCDI_RESPONSE,
870         EV_NQSTATS
871 } efx_ev_qstat_t;
872
873 /* END MKCONFIG GENERATED EfxHeaderEventQueueBlock */
874
875 #endif  /* EFSYS_OPT_QSTATS */
876
877 extern  __checkReturn   efx_rc_t
878 efx_ev_init(
879         __in            efx_nic_t *enp);
880
881 extern          void
882 efx_ev_fini(
883         __in            efx_nic_t *enp);
884
885 #define EFX_EVQ_MAXNEVS         32768
886 #define EFX_EVQ_MINNEVS         512
887
888 #define EFX_EVQ_SIZE(_nevs)     ((_nevs) * sizeof (efx_qword_t))
889 #define EFX_EVQ_NBUFS(_nevs)    (EFX_EVQ_SIZE(_nevs) / EFX_BUF_SIZE)
890
891 #define EFX_EVQ_FLAGS_TYPE_MASK         (0x3)
892 #define EFX_EVQ_FLAGS_TYPE_AUTO         (0x0)
893 #define EFX_EVQ_FLAGS_TYPE_THROUGHPUT   (0x1)
894 #define EFX_EVQ_FLAGS_TYPE_LOW_LATENCY  (0x2)
895
896 #define EFX_EVQ_FLAGS_NOTIFY_MASK       (0xC)
897 #define EFX_EVQ_FLAGS_NOTIFY_INTERRUPT  (0x0)   /* Interrupting (default) */
898 #define EFX_EVQ_FLAGS_NOTIFY_DISABLED   (0x4)   /* Non-interrupting */
899
900 extern  __checkReturn   efx_rc_t
901 efx_ev_qcreate(
902         __in            efx_nic_t *enp,
903         __in            unsigned int index,
904         __in            efsys_mem_t *esmp,
905         __in            size_t n,
906         __in            uint32_t id,
907         __in            uint32_t us,
908         __in            uint32_t flags,
909         __deref_out     efx_evq_t **eepp);
910
911 extern          void
912 efx_ev_qpost(
913         __in            efx_evq_t *eep,
914         __in            uint16_t data);
915
916 typedef __checkReturn   boolean_t
917 (*efx_initialized_ev_t)(
918         __in_opt        void *arg);
919
920 #define EFX_PKT_UNICAST         0x0004
921 #define EFX_PKT_START           0x0008
922
923 #define EFX_PKT_VLAN_TAGGED     0x0010
924 #define EFX_CKSUM_TCPUDP        0x0020
925 #define EFX_CKSUM_IPV4          0x0040
926 #define EFX_PKT_CONT            0x0080
927
928 #define EFX_CHECK_VLAN          0x0100
929 #define EFX_PKT_TCP             0x0200
930 #define EFX_PKT_UDP             0x0400
931 #define EFX_PKT_IPV4            0x0800
932
933 #define EFX_PKT_IPV6            0x1000
934 #define EFX_PKT_PREFIX_LEN      0x2000
935 #define EFX_ADDR_MISMATCH       0x4000
936 #define EFX_DISCARD             0x8000
937
938 /*
939  * The following flags are used only for packed stream
940  * mode. The values for the flags are reused to fit into 16 bit,
941  * since EFX_PKT_START and EFX_PKT_CONT are never used in
942  * packed stream mode
943  */
944 #define EFX_PKT_PACKED_STREAM_NEW_BUFFER        EFX_PKT_START
945 #define EFX_PKT_PACKED_STREAM_PARSE_INCOMPLETE  EFX_PKT_CONT
946
947
948 #define EFX_EV_RX_NLABELS       32
949 #define EFX_EV_TX_NLABELS       32
950
951 typedef __checkReturn   boolean_t
952 (*efx_rx_ev_t)(
953         __in_opt        void *arg,
954         __in            uint32_t label,
955         __in            uint32_t id,
956         __in            uint32_t size,
957         __in            uint16_t flags);
958
959 typedef __checkReturn   boolean_t
960 (*efx_tx_ev_t)(
961         __in_opt        void *arg,
962         __in            uint32_t label,
963         __in            uint32_t id);
964
965 #define EFX_EXCEPTION_RX_RECOVERY       0x00000001
966 #define EFX_EXCEPTION_RX_DSC_ERROR      0x00000002
967 #define EFX_EXCEPTION_TX_DSC_ERROR      0x00000003
968 #define EFX_EXCEPTION_UNKNOWN_SENSOREVT 0x00000004
969 #define EFX_EXCEPTION_FWALERT_SRAM      0x00000005
970 #define EFX_EXCEPTION_UNKNOWN_FWALERT   0x00000006
971 #define EFX_EXCEPTION_RX_ERROR          0x00000007
972 #define EFX_EXCEPTION_TX_ERROR          0x00000008
973 #define EFX_EXCEPTION_EV_ERROR          0x00000009
974
975 typedef __checkReturn   boolean_t
976 (*efx_exception_ev_t)(
977         __in_opt        void *arg,
978         __in            uint32_t label,
979         __in            uint32_t data);
980
981 typedef __checkReturn   boolean_t
982 (*efx_rxq_flush_done_ev_t)(
983         __in_opt        void *arg,
984         __in            uint32_t rxq_index);
985
986 typedef __checkReturn   boolean_t
987 (*efx_rxq_flush_failed_ev_t)(
988         __in_opt        void *arg,
989         __in            uint32_t rxq_index);
990
991 typedef __checkReturn   boolean_t
992 (*efx_txq_flush_done_ev_t)(
993         __in_opt        void *arg,
994         __in            uint32_t txq_index);
995
996 typedef __checkReturn   boolean_t
997 (*efx_software_ev_t)(
998         __in_opt        void *arg,
999         __in            uint16_t magic);
1000
1001 typedef __checkReturn   boolean_t
1002 (*efx_sram_ev_t)(
1003         __in_opt        void *arg,
1004         __in            uint32_t code);
1005
1006 #define EFX_SRAM_CLEAR          0
1007 #define EFX_SRAM_UPDATE         1
1008 #define EFX_SRAM_ILLEGAL_CLEAR  2
1009
1010 typedef __checkReturn   boolean_t
1011 (*efx_wake_up_ev_t)(
1012         __in_opt        void *arg,
1013         __in            uint32_t label);
1014
1015 typedef __checkReturn   boolean_t
1016 (*efx_timer_ev_t)(
1017         __in_opt        void *arg,
1018         __in            uint32_t label);
1019
1020 typedef __checkReturn   boolean_t
1021 (*efx_link_change_ev_t)(
1022         __in_opt        void *arg,
1023         __in            efx_link_mode_t link_mode);
1024
1025 typedef struct efx_ev_callbacks_s {
1026         efx_initialized_ev_t            eec_initialized;
1027         efx_rx_ev_t                     eec_rx;
1028         efx_tx_ev_t                     eec_tx;
1029         efx_exception_ev_t              eec_exception;
1030         efx_rxq_flush_done_ev_t         eec_rxq_flush_done;
1031         efx_rxq_flush_failed_ev_t       eec_rxq_flush_failed;
1032         efx_txq_flush_done_ev_t         eec_txq_flush_done;
1033         efx_software_ev_t               eec_software;
1034         efx_sram_ev_t                   eec_sram;
1035         efx_wake_up_ev_t                eec_wake_up;
1036         efx_timer_ev_t                  eec_timer;
1037         efx_link_change_ev_t            eec_link_change;
1038 } efx_ev_callbacks_t;
1039
1040 extern  __checkReturn   boolean_t
1041 efx_ev_qpending(
1042         __in            efx_evq_t *eep,
1043         __in            unsigned int count);
1044
1045 extern                  void
1046 efx_ev_qpoll(
1047         __in            efx_evq_t *eep,
1048         __inout         unsigned int *countp,
1049         __in            const efx_ev_callbacks_t *eecp,
1050         __in_opt        void *arg);
1051
1052 extern  __checkReturn   efx_rc_t
1053 efx_ev_usecs_to_ticks(
1054         __in            efx_nic_t *enp,
1055         __in            unsigned int usecs,
1056         __out           unsigned int *ticksp);
1057
1058 extern  __checkReturn   efx_rc_t
1059 efx_ev_qmoderate(
1060         __in            efx_evq_t *eep,
1061         __in            unsigned int us);
1062
1063 extern  __checkReturn   efx_rc_t
1064 efx_ev_qprime(
1065         __in            efx_evq_t *eep,
1066         __in            unsigned int count);
1067
1068 #if EFSYS_OPT_QSTATS
1069
1070 #if EFSYS_OPT_NAMES
1071
1072 extern          const char *
1073 efx_ev_qstat_name(
1074         __in    efx_nic_t *enp,
1075         __in    unsigned int id);
1076
1077 #endif  /* EFSYS_OPT_NAMES */
1078
1079 extern                                  void
1080 efx_ev_qstats_update(
1081         __in                            efx_evq_t *eep,
1082         __inout_ecount(EV_NQSTATS)      efsys_stat_t *stat);
1083
1084 #endif  /* EFSYS_OPT_QSTATS */
1085
1086 extern          void
1087 efx_ev_qdestroy(
1088         __in    efx_evq_t *eep);
1089
1090 /* RX */
1091
1092 extern  __checkReturn   efx_rc_t
1093 efx_rx_init(
1094         __inout         efx_nic_t *enp);
1095
1096 extern          void
1097 efx_rx_fini(
1098         __in            efx_nic_t *enp);
1099
1100 extern  __checkReturn   efx_rc_t
1101 efx_pseudo_hdr_pkt_length_get(
1102         __in            efx_rxq_t *erp,
1103         __in            uint8_t *buffer,
1104         __out           uint16_t *pkt_lengthp);
1105
1106 #define EFX_RXQ_MAXNDESCS               4096
1107 #define EFX_RXQ_MINNDESCS               512
1108
1109 #define EFX_RXQ_SIZE(_ndescs)           ((_ndescs) * sizeof (efx_qword_t))
1110 #define EFX_RXQ_NBUFS(_ndescs)          (EFX_RXQ_SIZE(_ndescs) / EFX_BUF_SIZE)
1111 #define EFX_RXQ_LIMIT(_ndescs)          ((_ndescs) - 16)
1112 #define EFX_RXQ_DC_NDESCS(_dcsize)      (8 << _dcsize)
1113
1114 typedef enum efx_rxq_type_e {
1115         EFX_RXQ_TYPE_DEFAULT,
1116         EFX_RXQ_TYPE_SCATTER,
1117         EFX_RXQ_TYPE_PACKED_STREAM_1M,
1118         EFX_RXQ_TYPE_PACKED_STREAM_512K,
1119         EFX_RXQ_TYPE_PACKED_STREAM_256K,
1120         EFX_RXQ_TYPE_PACKED_STREAM_128K,
1121         EFX_RXQ_TYPE_PACKED_STREAM_64K,
1122         EFX_RXQ_NTYPES
1123 } efx_rxq_type_t;
1124
1125 extern  __checkReturn   efx_rc_t
1126 efx_rx_qcreate(
1127         __in            efx_nic_t *enp,
1128         __in            unsigned int index,
1129         __in            unsigned int label,
1130         __in            efx_rxq_type_t type,
1131         __in            efsys_mem_t *esmp,
1132         __in            size_t n,
1133         __in            uint32_t id,
1134         __in            efx_evq_t *eep,
1135         __deref_out     efx_rxq_t **erpp);
1136
1137 typedef struct efx_buffer_s {
1138         efsys_dma_addr_t        eb_addr;
1139         size_t                  eb_size;
1140         boolean_t               eb_eop;
1141 } efx_buffer_t;
1142
1143 typedef struct efx_desc_s {
1144         efx_qword_t ed_eq;
1145 } efx_desc_t;
1146
1147 extern                  void
1148 efx_rx_qpost(
1149         __in            efx_rxq_t *erp,
1150         __in_ecount(n)  efsys_dma_addr_t *addrp,
1151         __in            size_t size,
1152         __in            unsigned int n,
1153         __in            unsigned int completed,
1154         __in            unsigned int added);
1155
1156 extern          void
1157 efx_rx_qpush(
1158         __in    efx_rxq_t *erp,
1159         __in    unsigned int added,
1160         __inout unsigned int *pushedp);
1161
1162 extern  __checkReturn   efx_rc_t
1163 efx_rx_qflush(
1164         __in    efx_rxq_t *erp);
1165
1166 extern          void
1167 efx_rx_qenable(
1168         __in    efx_rxq_t *erp);
1169
1170 extern          void
1171 efx_rx_qdestroy(
1172         __in    efx_rxq_t *erp);
1173
1174 /* TX */
1175
1176 typedef struct efx_txq_s        efx_txq_t;
1177
1178 #if EFSYS_OPT_QSTATS
1179
1180 /* START MKCONFIG GENERATED EfxHeaderTransmitQueueBlock 12dff8778598b2db */
1181 typedef enum efx_tx_qstat_e {
1182         TX_POST,
1183         TX_POST_PIO,
1184         TX_NQSTATS
1185 } efx_tx_qstat_t;
1186
1187 /* END MKCONFIG GENERATED EfxHeaderTransmitQueueBlock */
1188
1189 #endif  /* EFSYS_OPT_QSTATS */
1190
1191 extern  __checkReturn   efx_rc_t
1192 efx_tx_init(
1193         __in            efx_nic_t *enp);
1194
1195 extern          void
1196 efx_tx_fini(
1197         __in    efx_nic_t *enp);
1198
1199 #define EFX_TXQ_MINNDESCS               512
1200
1201 #define EFX_TXQ_SIZE(_ndescs)           ((_ndescs) * sizeof (efx_qword_t))
1202 #define EFX_TXQ_NBUFS(_ndescs)          (EFX_TXQ_SIZE(_ndescs) / EFX_BUF_SIZE)
1203 #define EFX_TXQ_LIMIT(_ndescs)          ((_ndescs) - 16)
1204 #define EFX_TXQ_DC_NDESCS(_dcsize)      (8 << _dcsize)
1205
1206 #define EFX_TXQ_MAX_BUFS 8 /* Maximum independent of EFX_BUG35388_WORKAROUND. */
1207
1208 #define EFX_TXQ_CKSUM_IPV4      0x0001
1209 #define EFX_TXQ_CKSUM_TCPUDP    0x0002
1210 #define EFX_TXQ_FATSOV2         0x0004
1211
1212 extern  __checkReturn   efx_rc_t
1213 efx_tx_qcreate(
1214         __in            efx_nic_t *enp,
1215         __in            unsigned int index,
1216         __in            unsigned int label,
1217         __in            efsys_mem_t *esmp,
1218         __in            size_t n,
1219         __in            uint32_t id,
1220         __in            uint16_t flags,
1221         __in            efx_evq_t *eep,
1222         __deref_out     efx_txq_t **etpp,
1223         __out           unsigned int *addedp);
1224
1225 extern  __checkReturn   efx_rc_t
1226 efx_tx_qpost(
1227         __in            efx_txq_t *etp,
1228         __in_ecount(n)  efx_buffer_t *eb,
1229         __in            unsigned int n,
1230         __in            unsigned int completed,
1231         __inout         unsigned int *addedp);
1232
1233 extern  __checkReturn   efx_rc_t
1234 efx_tx_qpace(
1235         __in            efx_txq_t *etp,
1236         __in            unsigned int ns);
1237
1238 extern                  void
1239 efx_tx_qpush(
1240         __in            efx_txq_t *etp,
1241         __in            unsigned int added,
1242         __in            unsigned int pushed);
1243
1244 extern  __checkReturn   efx_rc_t
1245 efx_tx_qflush(
1246         __in            efx_txq_t *etp);
1247
1248 extern                  void
1249 efx_tx_qenable(
1250         __in            efx_txq_t *etp);
1251
1252 extern  __checkReturn   efx_rc_t
1253 efx_tx_qpio_enable(
1254         __in            efx_txq_t *etp);
1255
1256 extern                  void
1257 efx_tx_qpio_disable(
1258         __in            efx_txq_t *etp);
1259
1260 extern  __checkReturn   efx_rc_t
1261 efx_tx_qpio_write(
1262         __in                    efx_txq_t *etp,
1263         __in_ecount(buf_length) uint8_t *buffer,
1264         __in                    size_t buf_length,
1265         __in                    size_t pio_buf_offset);
1266
1267 extern  __checkReturn   efx_rc_t
1268 efx_tx_qpio_post(
1269         __in                    efx_txq_t *etp,
1270         __in                    size_t pkt_length,
1271         __in                    unsigned int completed,
1272         __inout                 unsigned int *addedp);
1273
1274 extern  __checkReturn   efx_rc_t
1275 efx_tx_qdesc_post(
1276         __in            efx_txq_t *etp,
1277         __in_ecount(n)  efx_desc_t *ed,
1278         __in            unsigned int n,
1279         __in            unsigned int completed,
1280         __inout         unsigned int *addedp);
1281
1282 extern  void
1283 efx_tx_qdesc_dma_create(
1284         __in    efx_txq_t *etp,
1285         __in    efsys_dma_addr_t addr,
1286         __in    size_t size,
1287         __in    boolean_t eop,
1288         __out   efx_desc_t *edp);
1289
1290 extern  void
1291 efx_tx_qdesc_tso_create(
1292         __in    efx_txq_t *etp,
1293         __in    uint16_t ipv4_id,
1294         __in    uint32_t tcp_seq,
1295         __in    uint8_t  tcp_flags,
1296         __out   efx_desc_t *edp);
1297
1298 /* Number of FATSOv2 option descriptors */
1299 #define EFX_TX_FATSOV2_OPT_NDESCS               2
1300
1301 /* Maximum number of DMA segments per TSO packet (not superframe) */
1302 #define EFX_TX_FATSOV2_DMA_SEGS_PER_PKT_MAX     24
1303
1304 extern  void
1305 efx_tx_qdesc_tso2_create(
1306         __in                    efx_txq_t *etp,
1307         __in                    uint16_t ipv4_id,
1308         __in                    uint32_t tcp_seq,
1309         __in                    uint16_t tcp_mss,
1310         __out_ecount(count)     efx_desc_t *edp,
1311         __in                    int count);
1312
1313 extern  void
1314 efx_tx_qdesc_vlantci_create(
1315         __in    efx_txq_t *etp,
1316         __in    uint16_t tci,
1317         __out   efx_desc_t *edp);
1318
1319 #if EFSYS_OPT_QSTATS
1320
1321 #if EFSYS_OPT_NAMES
1322
1323 extern          const char *
1324 efx_tx_qstat_name(
1325         __in    efx_nic_t *etp,
1326         __in    unsigned int id);
1327
1328 #endif  /* EFSYS_OPT_NAMES */
1329
1330 extern                                  void
1331 efx_tx_qstats_update(
1332         __in                            efx_txq_t *etp,
1333         __inout_ecount(TX_NQSTATS)      efsys_stat_t *stat);
1334
1335 #endif  /* EFSYS_OPT_QSTATS */
1336
1337 extern          void
1338 efx_tx_qdestroy(
1339         __in    efx_txq_t *etp);
1340
1341
1342 /* FILTER */
1343
1344 #if EFSYS_OPT_FILTER
1345
1346 #define EFX_ETHER_TYPE_IPV4 0x0800
1347 #define EFX_ETHER_TYPE_IPV6 0x86DD
1348
1349 #define EFX_IPPROTO_TCP 6
1350 #define EFX_IPPROTO_UDP 17
1351
1352 /* Use RSS to spread across multiple queues */
1353 #define EFX_FILTER_FLAG_RX_RSS          0x01
1354 /* Enable RX scatter */
1355 #define EFX_FILTER_FLAG_RX_SCATTER      0x02
1356 /*
1357  * Override an automatic filter (priority EFX_FILTER_PRI_AUTO).
1358  * May only be set by the filter implementation for each type.
1359  * A removal request will restore the automatic filter in its place.
1360  */
1361 #define EFX_FILTER_FLAG_RX_OVER_AUTO    0x04
1362 /* Filter is for RX */
1363 #define EFX_FILTER_FLAG_RX              0x08
1364 /* Filter is for TX */
1365 #define EFX_FILTER_FLAG_TX              0x10
1366
1367 typedef unsigned int efx_filter_flags_t;
1368
1369 typedef enum efx_filter_match_flags_e {
1370         EFX_FILTER_MATCH_REM_HOST = 0x0001,     /* Match by remote IP host
1371                                                  * address */
1372         EFX_FILTER_MATCH_LOC_HOST = 0x0002,     /* Match by local IP host
1373                                                  * address */
1374         EFX_FILTER_MATCH_REM_MAC = 0x0004,      /* Match by remote MAC address */
1375         EFX_FILTER_MATCH_REM_PORT = 0x0008,     /* Match by remote TCP/UDP port */
1376         EFX_FILTER_MATCH_LOC_MAC = 0x0010,      /* Match by remote TCP/UDP port */
1377         EFX_FILTER_MATCH_LOC_PORT = 0x0020,     /* Match by local TCP/UDP port */
1378         EFX_FILTER_MATCH_ETHER_TYPE = 0x0040,   /* Match by Ether-type */
1379         EFX_FILTER_MATCH_INNER_VID = 0x0080,    /* Match by inner VLAN ID */
1380         EFX_FILTER_MATCH_OUTER_VID = 0x0100,    /* Match by outer VLAN ID */
1381         EFX_FILTER_MATCH_IP_PROTO = 0x0200,     /* Match by IP transport
1382                                                  * protocol */
1383         EFX_FILTER_MATCH_LOC_MAC_IG = 0x0400,   /* Match by local MAC address
1384                                                  * I/G bit. Used for RX default
1385                                                  * unicast and multicast/
1386                                                  * broadcast filters. */
1387 } efx_filter_match_flags_t;
1388
1389 typedef enum efx_filter_priority_s {
1390         EFX_FILTER_PRI_HINT = 0,        /* Performance hint */
1391         EFX_FILTER_PRI_AUTO,            /* Automatic filter based on device
1392                                          * address list or hardware
1393                                          * requirements. This may only be used
1394                                          * by the filter implementation for
1395                                          * each NIC type. */
1396         EFX_FILTER_PRI_MANUAL,          /* Manually configured filter */
1397         EFX_FILTER_PRI_REQUIRED,        /* Required for correct behaviour of the
1398                                          * client (e.g. SR-IOV, HyperV VMQ etc.)
1399                                          */
1400 } efx_filter_priority_t;
1401
1402 /*
1403  * FIXME: All these fields are assumed to be in little-endian byte order.
1404  * It may be better for some to be big-endian. See bug42804.
1405  */
1406
1407 typedef struct efx_filter_spec_s {
1408         uint32_t        efs_match_flags:12;
1409         uint32_t        efs_priority:2;
1410         uint32_t        efs_flags:6;
1411         uint32_t        efs_dmaq_id:12;
1412         uint32_t        efs_rss_context;
1413         uint16_t        efs_outer_vid;
1414         uint16_t        efs_inner_vid;
1415         uint8_t         efs_loc_mac[EFX_MAC_ADDR_LEN];
1416         uint8_t         efs_rem_mac[EFX_MAC_ADDR_LEN];
1417         uint16_t        efs_ether_type;
1418         uint8_t         efs_ip_proto;
1419         uint16_t        efs_loc_port;
1420         uint16_t        efs_rem_port;
1421         efx_oword_t     efs_rem_host;
1422         efx_oword_t     efs_loc_host;
1423 } efx_filter_spec_t;
1424
1425
1426 /* Default values for use in filter specifications */
1427 #define EFX_FILTER_SPEC_RSS_CONTEXT_DEFAULT     0xffffffff
1428 #define EFX_FILTER_SPEC_RX_DMAQ_ID_DROP         0xfff
1429 #define EFX_FILTER_SPEC_VID_UNSPEC              0xffff
1430
1431 extern  __checkReturn   efx_rc_t
1432 efx_filter_init(
1433         __in            efx_nic_t *enp);
1434
1435 extern                  void
1436 efx_filter_fini(
1437         __in            efx_nic_t *enp);
1438
1439 extern  __checkReturn   efx_rc_t
1440 efx_filter_insert(
1441         __in            efx_nic_t *enp,
1442         __inout         efx_filter_spec_t *spec);
1443
1444 extern  __checkReturn   efx_rc_t
1445 efx_filter_remove(
1446         __in            efx_nic_t *enp,
1447         __inout         efx_filter_spec_t *spec);
1448
1449 extern  __checkReturn   efx_rc_t
1450 efx_filter_restore(
1451         __in            efx_nic_t *enp);
1452
1453 extern  __checkReturn   efx_rc_t
1454 efx_filter_supported_filters(
1455         __in            efx_nic_t *enp,
1456         __out           uint32_t *list,
1457         __out           size_t *length);
1458
1459 extern                  void
1460 efx_filter_spec_init_rx(
1461         __out           efx_filter_spec_t *spec,
1462         __in            efx_filter_priority_t priority,
1463         __in            efx_filter_flags_t flags,
1464         __in            efx_rxq_t *erp);
1465
1466 extern                  void
1467 efx_filter_spec_init_tx(
1468         __out           efx_filter_spec_t *spec,
1469         __in            efx_txq_t *etp);
1470
1471 extern  __checkReturn   efx_rc_t
1472 efx_filter_spec_set_ipv4_local(
1473         __inout         efx_filter_spec_t *spec,
1474         __in            uint8_t proto,
1475         __in            uint32_t host,
1476         __in            uint16_t port);
1477
1478 extern  __checkReturn   efx_rc_t
1479 efx_filter_spec_set_ipv4_full(
1480         __inout         efx_filter_spec_t *spec,
1481         __in            uint8_t proto,
1482         __in            uint32_t lhost,
1483         __in            uint16_t lport,
1484         __in            uint32_t rhost,
1485         __in            uint16_t rport);
1486
1487 extern  __checkReturn   efx_rc_t
1488 efx_filter_spec_set_eth_local(
1489         __inout         efx_filter_spec_t *spec,
1490         __in            uint16_t vid,
1491         __in            const uint8_t *addr);
1492
1493 extern  __checkReturn   efx_rc_t
1494 efx_filter_spec_set_uc_def(
1495         __inout         efx_filter_spec_t *spec);
1496
1497 extern  __checkReturn   efx_rc_t
1498 efx_filter_spec_set_mc_def(
1499         __inout         efx_filter_spec_t *spec);
1500
1501 #endif  /* EFSYS_OPT_FILTER */
1502
1503 /* HASH */
1504
1505 extern  __checkReturn           uint32_t
1506 efx_hash_dwords(
1507         __in_ecount(count)      uint32_t const *input,
1508         __in                    size_t count,
1509         __in                    uint32_t init);
1510
1511 extern  __checkReturn           uint32_t
1512 efx_hash_bytes(
1513         __in_ecount(length)     uint8_t const *input,
1514         __in                    size_t length,
1515         __in                    uint32_t init);
1516
1517
1518
1519 #ifdef  __cplusplus
1520 }
1521 #endif
1522
1523 #endif  /* _SYS_EFX_H */