xref: /freebsd/sys/dev/aq/aq_device.h (revision c4fde87a3236b500246d4fce76dbca2a3d64f73a)
1 /*
2  * aQuantia Corporation Network Driver
3  * Copyright (C) 2014-2017 aQuantia Corporation. 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
7  * are met:
8  *
9  *   (1) Redistributions of source code must retain the above
10  *   copyright notice, this list of conditions and the following
11  *   disclaimer.
12  *
13  *   (2) Redistributions in binary form must reproduce the above
14  *   copyright notice, this list of conditions and the following
15  *   disclaimer in the documentation and/or other materials provided
16  *   with the distribution.
17  *
18  *   (3)The name of the author may not be used to endorse or promote
19  *   products derived from this software without specific prior
20  *   written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef _AQ_DEVICE_H_
36 #define _AQ_DEVICE_H_
37 
38 #include <sys/bitstring.h>
39 #include <sys/queue.h>
40 #include <sys/socket.h>
41 #include <sys/sysctl.h>
42 
43 #include <net/ethernet.h>
44 #include <net/if.h>
45 #include <net/if_media.h>
46 #include <net/if_var.h>
47 #include <net/iflib.h>
48 
49 #include "aq_hw.h"
50 
51 enum aq_media_type {
52 	AQ_MEDIA_TYPE_UNKNOWN = 0,
53 	AQ_MEDIA_TYPE_FIBRE,
54 	AQ_MEDIA_TYPE_TP,
55 };
56 
57 #define	AQ_LINK_UNKNOWN	0x00000000
58 #define	AQ_LINK_10M	0x00000001
59 #define	AQ_LINK_100M	0x00000002
60 #define	AQ_LINK_1G	0x00000004
61 #define	AQ_LINK_2G5	0x00000008
62 #define	AQ_LINK_5G	0x00000010
63 #define	AQ_LINK_10G	0x00000020
64 
65 #define	AQ_LINK_ALL	(AQ_LINK_10M | AQ_LINK_100M | AQ_LINK_1G | \
66 			 AQ_LINK_2G5 | AQ_LINK_5G | AQ_LINK_10G)
67 
68 /* Atlantic 1 has no 10BASE-T PHY. */
69 #define	AQ_LINK_ALL_ATLANTIC1	(AQ_LINK_ALL & ~AQ_LINK_10M)
70 
71 struct aq_stats {
72 	uint64_t prc;
73 	uint64_t uprc;
74 	uint64_t mprc;
75 	uint64_t bprc;
76 	uint64_t cprc;
77 	uint64_t erpr;
78 	uint64_t dpc;
79 	uint64_t brc;
80 	uint64_t ubrc;
81 	uint64_t mbrc;
82 	uint64_t bbrc;
83 
84 	uint64_t ptc;
85 	uint64_t uptc;
86 	uint64_t mptc;
87 	uint64_t bptc;
88 	uint64_t erpt;
89 	uint64_t btc;
90 	uint64_t ubtc;
91 	uint64_t mbtc;
92 	uint64_t bbtc;
93 };
94 
95 struct aq_dev {
96 	device_t		dev;
97 	if_ctx_t		ctx;
98 	if_softc_ctx_t		scctx;
99 	if_shared_ctx_t		sctx;
100 	struct ifmedia *	media;
101 
102 	struct aq_hw          hw;
103 
104 	enum aq_media_type	media_type;
105 	uint32_t		link_speeds;
106 	uint32_t		chip_features;
107 	uint32_t		mbox_addr;
108 	uint8_t			mac_addr[ETHER_ADDR_LEN];
109 	uint64_t		admin_ticks;
110 	struct if_irq	irq;
111 	int				msix;
112 
113 	int			mmio_rid;
114 	struct resource *	mmio_res;
115 	bus_space_tag_t		mmio_tag;
116 	bus_space_handle_t	mmio_handle;
117 	bus_size_t		mmio_size;
118 
119 	struct aq_ring    *tx_rings[HW_ATL_B0_RINGS_MAX];
120 	struct aq_ring    *rx_rings[HW_ATL_B0_RINGS_MAX];
121 	uint32_t          tx_rings_count;
122 	uint32_t          rx_rings_count;
123 	bool              linkup;
124 	uint32_t          link_speed;	/* Mbit/s last announced to the stack */
125 	uint16_t          phy_fault_last;	/* last fault code reported */
126 	bool              phy_hot_last;		/* last over-temperature warning */
127 	bool              link_read_failed;	/* link state read is failing */
128 	enum aq_thermal_state {
129 		AQ_THERMAL_NORMAL = 0,	/* no thermal shutdown pending */
130 		AQ_THERMAL_COOLING,	/* shut down; waiting to cool */
131 		AQ_THERMAL_SETTLING,	/* PHY reset; waiting to re-init */
132 	}                 thermal_state;
133 	int               thermal_settle;
134 	int               thermal_retry_ticks;	/* earliest tick to retry at */
135 	int               thermal_temp_mc;	/* temp at the last shutdown/cool */
136 	int               thermal_recover_mc;	/* recover once cooled to here */
137 	bool              thermal_shutdown_enabled;	/* arm the shutdown */
138 	int               thermal_arm_err;	/* last result returned */
139 	bool              init_failed;		/* aq_hw_init() left the hw down */
140 	int               init_retries;
141 	bool              reset_pending;	/* a re-init is already queued */
142 	int               media_active;
143 
144 	struct aq_hw_stats  last_stats;
145 	struct aq_stats     curr_stats;
146 
147 	bitstr_t               *vlan_tags;
148 	int                     mcnt;
149 
150 	uint8_t			rss_key[HW_ATL_RSS_HASHKEY_SIZE];
151 	uint8_t			rss_table[HW_ATL_RSS_INDIRECTION_TABLE_MAX];
152 
153 	int			dbg_level;
154 	uint32_t		dbg_categories;
155 
156 	struct sysctl_ctx_list	aq_sysctl_ctx;
157 };
158 
159 int aq_update_hw_stats(struct aq_dev *aq_dev);
160 void aq_initmedia(struct aq_dev *aq_dev);
161 int aq_linkstat_isr(void *arg);
162 int aq_isr_rx(void *arg);
163 void aq_mediastatus_update(struct aq_dev *aq_dev, uint32_t link_speed, const struct aq_hw_fc_info *fc_neg);
164 void aq_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr);
165 int aq_mediachange(struct ifnet *ifp);
166 void aq_if_update_admin_status(if_ctx_t ctx);
167 
168 #endif // _AQ_DEVICE_H_
169