xref: /freebsd/sys/dev/aq/aq_device.h (revision 493d26c58e732dcfcdd87993ef71880adfe9d0cb)
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 "aq_hw.h"
39 
40 enum aq_media_type {
41 	AQ_MEDIA_TYPE_UNKNOWN = 0,
42 	AQ_MEDIA_TYPE_FIBRE,
43 	AQ_MEDIA_TYPE_TP,
44 };
45 
46 #define	AQ_LINK_UNKNOWN	0x00000000
47 #define	AQ_LINK_100M	0x00000001
48 #define	AQ_LINK_1G		0x00000002
49 #define	AQ_LINK_2G5		0x00000004
50 #define	AQ_LINK_5G		0x00000008
51 #define	AQ_LINK_10G		0x00000010
52 
53 #define	AQ_LINK_ALL	(AQ_LINK_100M | AQ_LINK_1G | AQ_LINK_2G5 | AQ_LINK_5G | \
54 					 AQ_LINK_10G )
55 
56 struct aq_stats_s {
57     u64 prc;
58     u64 uprc;
59     u64 mprc;
60     u64 bprc;
61     u64 cprc;
62     u64 erpr;
63     u64 dpc;
64     u64 brc;
65     u64 ubrc;
66     u64 mbrc;
67     u64 bbrc;
68 
69     u64 ptc;
70     u64 uptc;
71     u64 mptc;
72     u64 bptc;
73     u64 erpt;
74     u64 btc;
75     u64 ubtc;
76     u64 mbtc;
77     u64 bbtc;
78 };
79 
80 enum aq_dev_state_e {
81     AQ_DEV_STATE_UNLOAD,
82     AQ_DEV_STATE_PCI_STOP,
83     AQ_DEV_STATE_DOWN,
84     AQ_DEV_STATE_UP,
85 };
86 
87 struct aq_rx_filters {
88     unsigned int rule_cnt;
89     struct aq_rx_filter_vlan vlan_filters[AQ_HW_VLAN_MAX_FILTERS];
90     struct aq_rx_filter_l2 etype_filters[AQ_HW_ETYPE_MAX_FILTERS];
91 };
92 
93 struct aq_vlan_tag {
94 	SLIST_ENTRY(aq_vlan_tag) next;
95 	uint16_t	tag;
96 };
97 
98 struct aq_dev {
99 	device_t		dev;
100 	if_ctx_t		ctx;
101 	if_softc_ctx_t		scctx;
102 	if_shared_ctx_t		sctx;
103 	struct ifmedia *	media;
104 
105     struct aq_hw          hw;
106 
107 	enum aq_media_type	media_type;
108 	uint32_t		link_speeds;
109 	uint32_t		chip_features;
110 	uint32_t		mbox_addr;
111 	uint8_t			mac_addr[ETHER_ADDR_LEN];
112 	uint64_t		admin_ticks;
113 	struct if_irq	irq;
114 	int				msix;
115 
116 	int			mmio_rid;
117 	struct resource *	mmio_res;
118 	bus_space_tag_t		mmio_tag;
119 	bus_space_handle_t	mmio_handle;
120 	bus_size_t		mmio_size;
121 
122 	struct aq_ring    *tx_rings[HW_ATL_B0_RINGS_MAX];
123 	struct aq_ring    *rx_rings[HW_ATL_B0_RINGS_MAX];
124 	uint32_t          tx_rings_count;
125 	uint32_t          rx_rings_count;
126 	bool              linkup;
127 	int               media_active;
128 
129 	struct aq_hw_stats_s  last_stats;
130 	struct aq_stats_s     curr_stats;
131 
132 	bitstr_t               *vlan_tags;
133 	int                     mcnt;
134 
135 	uint8_t			rss_key[HW_ATL_RSS_HASHKEY_SIZE];
136 	uint8_t			rss_table[HW_ATL_RSS_INDIRECTION_TABLE_MAX];
137 };
138 
139 typedef struct aq_dev aq_dev_t;
140 
141 int aq_update_hw_stats(aq_dev_t *aq_dev);
142 void aq_initmedia(aq_dev_t *aq_dev);
143 int aq_linkstat_isr(void *arg);
144 int aq_isr_rx(void *arg);
145 void aq_mediastatus_update(aq_dev_t *aq_dev, u32 link_speed, const struct aq_hw_fc_info *fc_neg);
146 void aq_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr);
147 int aq_mediachange(struct ifnet *ifp);
148 void aq_if_update_admin_status(if_ctx_t ctx);
149 
150 #endif
151