Parcourir la source

Updated to new device API.

tags/v0.9.3
Michael Brown il y a 19 ans
Parent
révision
27a55b514c
1 fichiers modifiés avec 50 ajouts et 57 suppressions
  1. 50
    57
      src/drivers/net/pnic.c

+ 50
- 57
src/drivers/net/pnic.c Voir le fichier

@@ -22,11 +22,6 @@ Bochs Pseudo NIC driver for Etherboot
22 22
 /* PNIC API */
23 23
 #include "pnic_api.h"
24 24
 
25
-/* Private data structure */
26
-typedef struct {
27
-	uint16_t api_version;
28
-} pnic_priv_data_t;
29
-
30 25
 /* Function prototypes */
31 26
 static int pnic_api_check ( uint16_t api_version );
32 27
 
@@ -96,7 +91,6 @@ static uint16_t pnic_command ( struct nic *nic, uint16_t command,
96 91
 			       void *input, uint16_t input_length,
97 92
 			       void *output, uint16_t output_max_length,
98 93
 			       uint16_t *output_length ) {
99
-	pnic_priv_data_t *priv = (pnic_priv_data_t*)nic->priv_data;
100 94
 	uint16_t status = pnic_command_quiet ( nic, command,
101 95
 					       input, input_length,
102 96
 					       output, output_max_length,
@@ -104,7 +98,6 @@ static uint16_t pnic_command ( struct nic *nic, uint16_t command,
104 98
 	if ( status == PNIC_STATUS_OK ) return status;
105 99
 	printf ( "PNIC command %#hx (len %#hx) failed with status %#hx\n",
106 100
 		 command, input_length, status );
107
-	if ( priv->api_version ) pnic_api_check(priv->api_version);
108 101
 	return status;
109 102
 }
110 103
 
@@ -122,11 +115,18 @@ static int pnic_api_check ( uint16_t api_version ) {
122 115
 	return ( api_version == PNIC_API_VERSION );
123 116
 }
124 117
 
118
+/**************************************************************************
119
+CONNECT - connect adapter to the network
120
+***************************************************************************/
121
+static int pnic_connect ( struct nic *nic __unused ) {
122
+	/* Nothing to do */
123
+	return 1;
124
+}
125
+
125 126
 /**************************************************************************
126 127
 POLL - Wait for a frame
127 128
 ***************************************************************************/
128
-static int pnic_poll(struct nic *nic, int retrieve)
129
-{
129
+static int pnic_poll ( struct nic *nic, int retrieve ) {
130 130
 	uint16_t length;
131 131
 	uint16_t qlen;
132 132
 
@@ -153,13 +153,9 @@ static int pnic_poll(struct nic *nic, int retrieve)
153 153
 /**************************************************************************
154 154
 TRANSMIT - Transmit a frame
155 155
 ***************************************************************************/
156
-static void pnic_transmit(
157
-	struct nic *nic,
158
-	const char *dest,		/* Destination */
159
-	unsigned int type,		/* Type */
160
-	unsigned int size,		/* size */
161
-	const char *data)		/* Packet */
162
-{
156
+static void pnic_transmit ( struct nic *nic, const char *dest,
157
+			    unsigned int type, unsigned int size,
158
+			    const char *data ) {
163 159
 	unsigned int nstype = htons ( type );
164 160
 
165 161
 	if ( ( ETH_HLEN + size ) >= ETH_FRAME_LEN ) {
@@ -180,17 +176,14 @@ static void pnic_transmit(
180 176
 /**************************************************************************
181 177
 DISABLE - Turn off ethernet interface
182 178
 ***************************************************************************/
183
-static void pnic_disable(struct dev *dev)
184
-{
185
-	struct nic *nic = (struct nic *)dev;
179
+static void pnic_disable ( struct nic *nic ) {
186 180
 	pnic_command ( nic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
187 181
 }
188 182
 
189 183
 /**************************************************************************
190 184
 IRQ - Handle card interrupt status
191 185
 ***************************************************************************/
192
-static void pnic_irq ( struct nic *nic, irq_action_t action )
193
-{
186
+static void pnic_irq ( struct nic *nic, irq_action_t action ) {
194 187
 	uint8_t enabled;
195 188
 
196 189
 	switch ( action ) {
@@ -207,61 +200,61 @@ static void pnic_irq ( struct nic *nic, irq_action_t action )
207 200
 	}
208 201
 }
209 202
 
203
+/**************************************************************************
204
+NIC operations table
205
+***************************************************************************/
206
+static struct nic_operations pnic_operations = {
207
+	.connect	= pnic_connect,
208
+	.poll		= pnic_poll,
209
+	.transmit	= pnic_transmit,
210
+	.irq		= pnic_irq,
211
+	.disable        = pnic_disable,
212
+};
213
+
214
+static struct pci_id pnic_nics[] = {
215
+/* genrules.pl doesn't let us use macros for PCI IDs...*/
216
+PCI_ROM ( 0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor" ),
217
+};
218
+
219
+static struct pci_driver pnic_driver =
220
+	PCI_DRIVER ( "PNIC", pnic_nics, PCI_NO_CLASS );
221
+
210 222
 /**************************************************************************
211 223
 PROBE - Look for an adapter, this routine's visible to the outside
212 224
 ***************************************************************************/
213 225
 
214
-static int pnic_probe(struct dev *dev, struct pci_device *pci)
215
-{
216
-	struct nic *nic = (struct nic *)dev;
217
-	static pnic_priv_data_t priv;
226
+static int pnic_probe ( struct dev *dev ) {
227
+	struct nic *nic = nic_device ( dev );
228
+	struct pci_device *pci = pci_device ( dev );
229
+	uint16_t api_version;
218 230
 	uint16_t status;
219 231
 
220
-	printf(" - ");
221
-
222
-	/* Clear private data structure and chain it in */
223
-	memset ( &priv, 0, sizeof(priv) );
224
-	nic->priv_data = &priv;
232
+	/* Scan PCI bus for a PNIC device */
233
+	if ( ! find_pci_device ( pci, &pnic_driver ) )
234
+		return 0;
225 235
 
226
-	/* Mask the bit that says "this is an io addr" */
227
-	nic->ioaddr = pci->ioaddr & ~3;
236
+	/* Retrieve relevant information about PCI device */
237
+	nic->ioaddr = pci->ioaddr;
228 238
 	nic->irqno = pci->irq;
229
-	/* Not sure what this does, but the rtl8139 driver does it */
230
-	adjust_pci_device(pci);
231 239
 
240
+	/* API version check */
232 241
 	status = pnic_command_quiet( nic, PNIC_CMD_API_VER, NULL, 0,
233
-				     &priv.api_version,
234
-				     sizeof(priv.api_version), NULL );
242
+				     &api_version,
243
+				     sizeof(api_version), NULL );
235 244
 	if ( status != PNIC_STATUS_OK ) {
236 245
 		printf ( "PNIC failed installation check, code %#hx\n",
237 246
 			 status );
238 247
 		return 0;
239 248
 	}
240
-	pnic_api_check(priv.api_version);
249
+	pnic_api_check(api_version);
250
+
251
+	/* Get MAC address */
241 252
 	status = pnic_command ( nic, PNIC_CMD_READ_MAC, NULL, 0,
242 253
 				nic->node_addr, ETH_ALEN, NULL );
243
-	printf ( "Detected Bochs Pseudo NIC MAC %! (API v%d.%d) at %#hx\n",
244
-		 nic->node_addr, priv.api_version>>8, priv.api_version&0xff,
245
-		 nic->ioaddr );
246 254
 
247 255
 	/* point to NIC specific routines */
248
-	dev->disable  = pnic_disable;
249
-	nic->poll     = pnic_poll;
250
-	nic->transmit = pnic_transmit;
251
-	nic->irq      = pnic_irq;
256
+	nic->nic_op	= &pnic_operations;
252 257
 	return 1;
253 258
 }
254 259
 
255
-static struct pci_id pnic_nics[] = {
256
-/* genrules.pl doesn't let us use macros for PCI IDs...*/
257
-PCI_ROM(0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor"),
258
-};
259
-
260
-static struct pci_driver pnic_driver __pci_driver = {
261
-	.type     = NIC_DRIVER,
262
-	.name     = "PNIC",
263
-	.probe    = pnic_probe,
264
-	.ids      = pnic_nics,
265
-	.id_count = sizeof(pnic_nics)/sizeof(pnic_nics[0]),
266
-	.class    = 0,
267
-};
260
+BOOT_DRIVER ( "PNIC", pnic_probe );

Chargement…
Annuler
Enregistrer