xref: /haiku/src/add-ons/kernel/drivers/network/ether/pegasus/driver.h (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2  * Pegasus BeOS Driver
3  *
4  * Copyright 2006, Haiku, Inc. All Rights Reserved.
5  * Distributed under the terms of the MIT License.
6  *
7  * Authors:
8  *		Jérôme Duval
9  */
10 #ifndef _DEV_PEGASUS_H_
11 #define _DEV_PEGASUS_H_
12 
13 #include <Drivers.h>
14 #include <OS.h>
15 #include <SupportDefs.h>
16 #include <USB3.h>
17 
18 #include "ether_driver.h"
19 
20 #include "ByteOrder.h"
21 
22 // compat
23 #define u_uint8_t 	uint8
24 #define u_uint16_t 	uint16
25 #define u_int8_t 	int8
26 #define u_int16_t	int16
27 #define DELAY 		snooze
28 
29 #include "if_auereg.h"
30 
31 #define VERSION "Version 0, Copyright (c) 2006 Jérôme Duval, compiled on " ## __DATE__ ## " " ## __TIME__
32 #define DRIVER_NAME "pegasus"
33 
34 #define	MY_ID	"\033[34m" DRIVER_NAME ":\033[m "
35 #define	MY_ERR	"\033[31merror:\033[m "
36 #define	MY_WARN	"\033[31mwarning:\033[m "
37 
38 //#define DEBUG 1
39 #if DEBUG
40 	#define	DPRINTF_INFO(x...)	dprintf(MY_ID x)
41 	#define	DPRINTF_ERR(x...)	dprintf(MY_ID x)
42 #else
43 	#define DPRINTF_INFO(x...)
44 	#define DPRINTF_ERR(x...)	dprintf(MY_ID x)
45 #endif
46 
47 #define	ASSERT(x) \
48 	((x) ? 0 : dprintf (MY_ID "assertion failed at " __FILE__ ", line %d\n", __LINE__))
49 
50 #define NUM_CARDS 3
51 #define DEVNAME 32
52 
53 #define	DEFAULT_CONFIGURATION	0
54 
55 #define ENET_HEADER_SIZE	14
56 #define ETHER_ADDRESS_LENGTH		6
57 #define MAX_FRAME_SIZE	1536
58 #define ETHER_TRANSMIT_TIMEOUT ((bigtime_t)5000000)
59 	/* five seconds */
60 
61 /*
62  * Various supported device vendors/products.
63  */
64 struct aue_type {
65 	struct usb_devno {
66 		uint16 vendor;
67 		uint16 product;
68 	} aue_dev;
69 	uint16		aue_flags;
70 #define LSYS	0x0001		/* use Linksys reset */
71 #define PNA	0x0002		/* has Home PNA */
72 #define PII	0x0004		/* Pegasus II chip */
73 };
74 
75 
76 /*
77  * Devices
78  */
79 
80 typedef struct _pegasus_dev {
81 	/* list structure */
82 	struct _pegasus_dev *next;
83 
84 	uint32			cookieMagic;
85 
86 	/* maintain device */
87 	sem_id 		sem_lock;
88 
89 	char		name[DEVNAME];	/* used for resources */
90 	int 		type;
91 	usb_device 	dev;
92 	uint16 		aue_vendor;
93 	uint16 		aue_product;
94 
95 	uint16 		ifno;
96 
97 	int open;
98 	struct driver_cookie *open_fds;
99 	volatile bool aue_dying;
100 	int number;
101 	uint flags;
102 
103 	int			aue_unit;
104 	uint16		aue_flags;
105 
106 	volatile bool		nonblocking;
107 
108 	uint32				maxframesize;	// 14 bytes header + MTU
109 	uint8				macaddr[6];
110 
111 	usb_pipe pipe_in;			/**/
112 	usb_pipe pipe_out;			/**/
113 	usb_pipe pipe_intr;			/**/
114 
115 	uint16			phy;
116 	bool			link;
117 
118 	// receive data
119 
120 	sem_id			rx_sem;
121 	sem_id			rx_sem_cb;
122 	char			rx_buffer[MAX_FRAME_SIZE];
123 	status_t		rx_status;
124 	size_t			rx_actual_length;
125 
126 	// transmit data
127 
128 	sem_id			tx_sem;
129 	sem_id			tx_sem_cb;
130 	char			tx_buffer[MAX_FRAME_SIZE];
131 	status_t		tx_status;
132 	size_t			tx_actual_length;
133 
134 } pegasus_dev;
135 
136 #define PEGASUS_COOKIE_MAGIC 'pega'
137 
138 
139 /* driver.c */
140 
141 extern usb_module_info *usb;
142 
143 pegasus_dev *create_device(const usb_device dev, const usb_interface_info *ii, uint16 ifno);
144 void remove_device(pegasus_dev *device);
145 
146 /* devlist.c */
147 
148 extern sem_id gDeviceListLock;
149 extern bool gDeviceListChanged;
150 
151 void add_device_info(pegasus_dev *device);
152 void remove_device_info(pegasus_dev *device);
153 pegasus_dev *search_device_info(const char *name);
154 
155 extern char **gDeviceNames;
156 
157 void alloc_device_names(void);
158 void free_device_names(void);
159 void rebuild_device_names(void);
160 
161 /* if_aue.c */
162 void aue_attach(pegasus_dev *sc);
163 void aue_init(pegasus_dev *sc);
164 void aue_uninit(pegasus_dev *sc);
165 
166 #endif /* _DEV_PEGASUS_H_ */
167