Browse Source

Updated to new device API.

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
27a55b514c
1 changed files with 50 additions and 57 deletions
  1. 50
    57
      src/drivers/net/pnic.c

+ 50
- 57
src/drivers/net/pnic.c View File

22
 /* PNIC API */
22
 /* PNIC API */
23
 #include "pnic_api.h"
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
 /* Function prototypes */
25
 /* Function prototypes */
31
 static int pnic_api_check ( uint16_t api_version );
26
 static int pnic_api_check ( uint16_t api_version );
32
 
27
 
96
 			       void *input, uint16_t input_length,
91
 			       void *input, uint16_t input_length,
97
 			       void *output, uint16_t output_max_length,
92
 			       void *output, uint16_t output_max_length,
98
 			       uint16_t *output_length ) {
93
 			       uint16_t *output_length ) {
99
-	pnic_priv_data_t *priv = (pnic_priv_data_t*)nic->priv_data;
100
 	uint16_t status = pnic_command_quiet ( nic, command,
94
 	uint16_t status = pnic_command_quiet ( nic, command,
101
 					       input, input_length,
95
 					       input, input_length,
102
 					       output, output_max_length,
96
 					       output, output_max_length,
104
 	if ( status == PNIC_STATUS_OK ) return status;
98
 	if ( status == PNIC_STATUS_OK ) return status;
105
 	printf ( "PNIC command %#hx (len %#hx) failed with status %#hx\n",
99
 	printf ( "PNIC command %#hx (len %#hx) failed with status %#hx\n",
106
 		 command, input_length, status );
100
 		 command, input_length, status );
107
-	if ( priv->api_version ) pnic_api_check(priv->api_version);
108
 	return status;
101
 	return status;
109
 }
102
 }
110
 
103
 
122
 	return ( api_version == PNIC_API_VERSION );
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
 POLL - Wait for a frame
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
 	uint16_t length;
130
 	uint16_t length;
131
 	uint16_t qlen;
131
 	uint16_t qlen;
132
 
132
 
153
 /**************************************************************************
153
 /**************************************************************************
154
 TRANSMIT - Transmit a frame
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
 	unsigned int nstype = htons ( type );
159
 	unsigned int nstype = htons ( type );
164
 
160
 
165
 	if ( ( ETH_HLEN + size ) >= ETH_FRAME_LEN ) {
161
 	if ( ( ETH_HLEN + size ) >= ETH_FRAME_LEN ) {
180
 /**************************************************************************
176
 /**************************************************************************
181
 DISABLE - Turn off ethernet interface
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
 	pnic_command ( nic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
180
 	pnic_command ( nic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
187
 }
181
 }
188
 
182
 
189
 /**************************************************************************
183
 /**************************************************************************
190
 IRQ - Handle card interrupt status
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
 	uint8_t enabled;
187
 	uint8_t enabled;
195
 
188
 
196
 	switch ( action ) {
189
 	switch ( 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
 PROBE - Look for an adapter, this routine's visible to the outside
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
 	uint16_t status;
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
 	nic->irqno = pci->irq;
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
 	status = pnic_command_quiet( nic, PNIC_CMD_API_VER, NULL, 0,
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
 	if ( status != PNIC_STATUS_OK ) {
244
 	if ( status != PNIC_STATUS_OK ) {
236
 		printf ( "PNIC failed installation check, code %#hx\n",
245
 		printf ( "PNIC failed installation check, code %#hx\n",
237
 			 status );
246
 			 status );
238
 		return 0;
247
 		return 0;
239
 	}
248
 	}
240
-	pnic_api_check(priv.api_version);
249
+	pnic_api_check(api_version);
250
+
251
+	/* Get MAC address */
241
 	status = pnic_command ( nic, PNIC_CMD_READ_MAC, NULL, 0,
252
 	status = pnic_command ( nic, PNIC_CMD_READ_MAC, NULL, 0,
242
 				nic->node_addr, ETH_ALEN, NULL );
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
 	/* point to NIC specific routines */
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
 	return 1;
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 );

Loading…
Cancel
Save