1/* Intel PRO/1000 Family Driver
2 * Copyright (C) 2004 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
3 *
4 * Permission to use, copy, modify and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies, and that both the
7 * copyright notice and this permission notice appear in supporting documentation.
8 *
9 * Marcus Overhagen makes no representations about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
11 *
12 * MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
13 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
14 * OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
15 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19#ifndef __IF_COMPAT_H
20#define __IF_COMPAT_H
21
22#include <OS.h>
23#include <net/if.h>
24#include <net/if_dl.h>
25#include <net/if_media.h>
26
27#include "if_em_osdep.h" // for TAILQ_...
28
29#define __FreeBSD_version	500001
30
31#define IFF_RUNNING		0x10000
32#define IFF_OACTIVE		0x20000
33
34#define IFCAP_HWCSUM			0x0001
35#define IFCAP_VLAN_HWTAGGING	0x0002
36#define IFCAP_VLAN_MTU			0x0004
37#define IFCAP_TXCSUM			0x0010
38#define IFCAP_RXCSUM			0x0020
39
40#ifdef HAIKU_TARGET_PLATFORM_HAIKU
41#	define IFM_AVALID	0
42#	define IFM_FDX		IFM_FULL_DUPLEX
43#	define IFM_HDX		IFM_HALF_DUPLEX
44#	define IFM_1000_TX	IFM_1000_T
45#else
46#	define IFM_ACTIVE	0x0001
47#	define IFM_FDX		0x0002
48#	define IFM_HDX		0x0004
49#	define IFM_10_T		0x0008
50#	define IFM_100_TX	0x0010
51#	define IFM_1000_T	0x0020
52#	define IFM_1000_TX	0x0040
53#	define IFM_1000_SX	0x0080
54#	define IFM_ETHER	0x0100
55#	define IFM_AUTO		0x0200
56#	define IFM_AVALID	0x0400
57#	define IFM_GMASK	(IFM_FDX | IFM_HDX)
58#	define IFM_TYPE_MASK (IFM_ETHER)
59#	define IFM_SUBTYPE_MASK \
60		(IFM_AUTO | IFM_1000_SX | IFM_1000_TX | IFM_1000_T | IFM_100_TX | IFM_10_T)
61#	define IFM_TYPE(media)		((media) & IFM_TYPE_MASK)
62#	define IFM_SUBTYPE(media)	((media) & IFM_SUBTYPE_MASK)
63#endif
64
65#define CSUM_TCP			0x0001 // ifnet::if_hwassist
66#define CSUM_UDP			0x0002 // ifnet::if_hwassist
67#define CSUM_IP_CHECKED		0x0004
68#define CSUM_IP_VALID		0x0008
69#define CSUM_DATA_VALID		0x0010
70#define CSUM_PSEUDO_HDR		0x0020
71
72#define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
73#define ETHER_TYPE_LEN          2       /* length of the Ethernet type field */
74#define ETHER_CRC_LEN           4       /* length of the Ethernet CRC */
75#define ETHER_HDR_LEN           (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
76#define ETHER_MIN_LEN           64      /* minimum frame len, including CRC */
77#define ETHER_MAX_LEN           1518    /* maximum frame len, including CRC */
78#define ETHER_MAX_LEN_JUMBO     9018    /* max jumbo frame len, including CRC */
79#define ETHER_VLAN_ENCAP_LEN    4       /* len of 802.1Q VLAN encapsulation */
80#define	ETHERMTU				ETHER_MAX_LEN_JUMBO
81#define IP_HEADER_SIZE			20
82#define OFFSETOF_IPHDR_SUM		10
83#define OFFSETOF_TCPHDR_SUM		16
84#define OFFSETOF_UDPHDR_SUM		6
85
86
87// vlan stuff is not supported
88#define ETHERTYPE_VLAN					0x8100
89#define VLAN_INPUT_TAG(a, b, c, d)
90#define VLAN_TAG_VALUE(mtag)			0
91#define VLAN_OUTPUT_TAG(ifp, m_head)	0
92
93
94// BPF listener not supported
95#define BPF_MTAP(a, b)
96
97
98// sysctl stuff is not supported
99#define sysctl_ctx_init(a)
100#define sysctl_ctx_free(a)
101#define SYSCTL_HANDLER_ARGS void
102#define SYSCTL_ADD_NODE(a, b, c, d, e, f, g) \
103	(struct sysctl_oid *) 1
104#define SYSCTL_ADD_PROC(a, b, c, d, e, f, g, h, i, j)
105
106struct sysctl_ctx_list
107{
108};
109
110struct sysctl_oid
111{
112};
113
114
115struct adapter;
116struct ifnet;
117struct mbuf;
118
119
120struct ifmedia
121{
122	uint32 	ifm_media;
123};
124
125struct if_queue
126{
127	volatile struct mbuf *	ifq_head;
128	volatile struct mbuf *	ifq_tail;
129	int						ifq_maxlen; // ignored
130};
131
132typedef void	(*if_start)(struct ifnet *);
133typedef int		(*if_ioctl)(struct ifnet *, u_long, caddr_t);
134typedef void	(*if_watchdog)(struct ifnet *);
135typedef void	(*if_init)(void *);
136typedef void	(*if_input)(struct ifnet *, struct mbuf *);
137
138struct m_pkthdr
139{
140	int 			len;
141	int				csum_flags;
142	uint16			csum_data;
143	struct ifnet *	rcvif; // set by receive int
144};
145
146struct m_ext
147{
148	void *ext_buf;
149};
150
151struct mbuf
152{
153	struct mbuf *	m_next;		// next buffer in chain (e.g. for jumboframes)
154	struct mbuf *	m_nextq;	// next buffer in queue
155	int				m_len;
156	int 			m_flags;
157	void *			m_data;
158	struct m_pkthdr	m_pkthdr;
159	struct m_ext 	m_ext;
160};
161
162#define M_DONTWAIT	0x01
163#define M_EXT		0x02
164#define	M_PKTHDR	0x04
165#define MT_DATA		1
166#define MCLBYTES	2048
167
168struct mbuf *m_gethdr(int how, int type);
169
170// Allocate and return a single M_PKTHDR mbuf.  NULL is returned on failure.
171#define MGETHDR(mb, how, type) ((mb) = m_gethdr((how), (type)))
172
173void m_clget(struct mbuf * mb, int how);
174
175// Fetch a single mbuf cluster and attach it to an existing mbuf.  If
176// successfull, configures the provided mbuf to have mbuf->m_ext.ext_buf
177// pointing to the cluster, and sets the M_EXT bit in the mbuf's flags.
178// The M_EXT bit is not set on failure
179#define MCLGET(mb, how)  m_clget((mb), (how))
180
181struct mbuf *if_dequeue(struct if_queue *queue);
182
183void if_prepend(struct if_queue *queue, struct mbuf *mb);
184void if_append(struct if_queue *queue, struct mbuf *mb);
185
186#define IF_DEQUEUE(queue, mb) ((mb) = if_dequeue((queue)))
187#define IF_PREPEND(queue, mb) if_prepend((queue), (mb))
188#define IF_APPEND(queue, mb) if_append((queue), (mb))
189
190void m_adj(struct mbuf *mp, int bytes);
191void m_freem(struct mbuf *mp);
192
193#define mtod(m, t)	((t)((m)->m_data))
194
195void ether_ifattach(struct ifnet *ifp, const uint8 *etheraddr);
196void ether_ifdetach(struct ifnet *ifp);
197
198int ether_add_multi(struct ifnet *ifp, const struct sockaddr *address);
199int ether_rem_multi(struct ifnet *ifp, const struct sockaddr *address);
200
201TAILQ_HEAD(ifmultihead, ifmultiaddr);
202
203struct ifmultiaddr
204{
205	TAILQ_ENTRY(ifmultiaddr) ifma_link;
206	struct sockaddr *ifma_addr;
207	int ifma_refcount;
208
209	/* private */
210	struct sockaddr_dl ifma_addr_storage;
211};
212
213struct if_data
214{
215	int ifi_hdrlen;
216};
217
218struct ether_vlan_header
219{
220	uint8  evl_dhost[ETHER_ADDR_LEN];
221	uint8  evl_shost[ETHER_ADDR_LEN];
222	uint16 evl_encap_proto;
223	uint16 evl_tag;
224	uint16 evl_proto;
225};
226
227struct ifnet
228{
229	const char *if_name;
230
231	struct adapter *if_softc;
232
233	int		if_unit;
234	int		if_mtu;
235	volatile uint32	if_flags;
236	uint32	if_capabilities;
237	uint32	if_hwassist;
238	uint32	if_capenable;
239	uint64	if_baudrate;
240	int64	if_timer;
241
242	uint64	if_ibytes;
243	uint64	if_obytes;
244	uint64	if_imcasts;
245	uint64	if_collisions;
246	uint64	if_ierrors;
247	uint64	if_oerrors;
248	uint64	if_ipackets;
249	uint64	if_opackets;
250
251	struct if_queue if_snd; // send queue
252	struct if_queue if_rcv; // recveive queue
253
254	sem_id if_rcv_sem;
255
256	struct if_data if_data;
257	struct ifmultihead if_multiaddrs;
258
259	if_start	if_start;
260	if_ioctl	if_ioctl;
261	if_watchdog	if_watchdog;
262	if_init		if_init;
263	if_input	if_input;
264
265
266	void *if_output; // unused
267	#define ether_output 0
268};
269
270struct arpcom
271{
272	struct ifnet ac_if;
273	uint8 ac_enaddr[ETHER_ADDR_LEN];
274};
275
276#define device_get_softc(dev) \
277	(dev->adapter ? dev->adapter : (dev->adapter = (struct adapter *)malloc(sizeof(struct adapter), 0, 0)))
278
279#define device_get_unit(dev) \
280	dev->devId
281
282enum { // ioctl commands
283	SIOCSIFADDR = 0x7000,
284	SIOCGIFADDR,
285	SIOCSIFMTU,
286	SIOCSIFFLAGS,
287	SIOCADDMULTI,
288	SIOCDELMULTI,
289	SIOCSIFMEDIA,
290	SIOCGIFMEDIA,
291	SIOCSIFCAP,
292};
293
294// used for media properties
295#define ifmedia_init(a, b, c, d)
296#define ifmedia_add(a, b, c, d)
297#define ifmedia_set(a, b)
298#define ifmedia_ioctl(ifp, ifr, media, command) 0
299
300// called for SIOCxIFADDR (Get/Set Interface Addr)
301#define ether_ioctl(ifp, command, data)
302
303#endif // __IF_COMPAT_H
304