Browse Source

Hand-finished

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
28590d718b
1 changed files with 27 additions and 30 deletions
  1. 27
    30
      src/drivers/net/rtl8139.c

+ 27
- 30
src/drivers/net/rtl8139.c View File

180
 static int rtl_poll(struct nic *nic, int retrieve);
180
 static int rtl_poll(struct nic *nic, int retrieve);
181
 static void rtl_disable(struct nic *nic);
181
 static void rtl_disable(struct nic *nic);
182
 static void rtl_irq(struct nic *nic, irq_action_t action);
182
 static void rtl_irq(struct nic *nic, irq_action_t action);
183
-
183
+static struct nic_operations rtl_operations;
184
+static struct pci_driver rtl8139_driver;
184
 
185
 
185
 static int rtl8139_probe ( struct dev *dev ) {
186
 static int rtl8139_probe ( struct dev *dev ) {
186
-
187
 	struct nic *nic = nic_device ( dev );
187
 	struct nic *nic = nic_device ( dev );
188
-
189
 	struct pci_device *pci = pci_device ( dev );
188
 	struct pci_device *pci = pci_device ( dev );
190
 	int i;
189
 	int i;
191
 	int speed10, fullduplex;
190
 	int speed10, fullduplex;
192
 	int addr_len;
191
 	int addr_len;
193
 	unsigned short *ap = (unsigned short*)nic->node_addr;
192
 	unsigned short *ap = (unsigned short*)nic->node_addr;
194
 
193
 
195
-	/* There are enough "RTL8139" strings on the console already, so
196
-	 * be brief and concentrate on the interesting pieces of info... */
197
-	printf(" - ");
198
-
199
-	/* Mask the bit that says "this is an io addr" */
200
-	nic->ioaddr = pci->ioaddr & ~3;
194
+	/* Look for PCI device */
195
+	if ( ! find_pci_device ( pci, &rtl8139_driver ) )
196
+		return 0;
201
 
197
 
202
-	/* Copy IRQ from PCI information */
198
+	/* Copy ioaddr and IRQ from PCI information */
199
+	nic->ioaddr = pci->ioaddr;
203
 	nic->irqno = pci->irq;
200
 	nic->irqno = pci->irq;
204
 
201
 
205
-	adjust_pci_device(pci);
206
-
207
 	/* Bring the chip out of low-power mode. */
202
 	/* Bring the chip out of low-power mode. */
208
 	outb(0x00, nic->ioaddr + Config1);
203
 	outb(0x00, nic->ioaddr + Config1);
209
 
204
 
211
 	for (i = 0; i < 3; i++)
206
 	for (i = 0; i < 3; i++)
212
 	  *ap++ = read_eeprom(nic,i + 7,addr_len);
207
 	  *ap++ = read_eeprom(nic,i + 7,addr_len);
213
 
208
 
209
+	rtl_reset(nic);
210
+
214
 	speed10 = inb(nic->ioaddr + MediaStatus) & MSRSpeed10;
211
 	speed10 = inb(nic->ioaddr + MediaStatus) & MSRSpeed10;
212
+	nic->mbps = speed10 ? 10 : 100;
215
 	fullduplex = inw(nic->ioaddr + MII_BMCR) & BMCRDuplex;
213
 	fullduplex = inw(nic->ioaddr + MII_BMCR) & BMCRDuplex;
216
-	printf("ioaddr %#hX, irq %d, addr %! %sMbps %s-duplex\n", nic->ioaddr,
217
-	       nic->irqno, nic->node_addr,  speed10 ? "10" : "100",
218
-	       fullduplex ? "full" : "half");
214
+	nic->duplex = fullduplex ? FULL_DUPLEX : HALF_DUPLEX;
219
 
215
 
220
-	rtl_reset(nic);
221
-
222
-	if (inb(nic->ioaddr + MediaStatus) & MSRLinkFail) {
223
-		printf("Cable not connected or other link failure\n");
224
-		return(0);
225
-	}
226
-static struct nic_operations rtl_operations;
227
-static struct nic_operations rtl_operations = {
228
-	.connect	= dummy_connect,
229
-	.poll		= rtl_poll,
230
-	.transmit	= rtl_transmit,
231
-	.irq		= rtl_irq,
232
-	.disable	= rtl_disable,
233
-};
234
 	nic->nic_op	= &rtl_operations;
216
 	nic->nic_op	= &rtl_operations;
235
-
236
 	return 1;
217
 	return 1;
237
 }
218
 }
238
 
219
 
312
 	outl(mc_filter[0], nic->ioaddr + MAR0 + 0);
293
 	outl(mc_filter[0], nic->ioaddr + MAR0 + 0);
313
 	outl(mc_filter[1], nic->ioaddr + MAR0 + 4);
294
 	outl(mc_filter[1], nic->ioaddr + MAR0 + 4);
314
 }
295
 }
296
+
297
+static int rtl_connect ( struct nic *nic ) {
298
+	if (inb(nic->ioaddr + MediaStatus) & MSRLinkFail) {
299
+		printf("Cable not connected or other link failure\n");
300
+		return 0;
301
+	}
302
+	return 1;
303
+}
315
 	
304
 	
316
 static void rtl_reset(struct nic* nic)
305
 static void rtl_reset(struct nic* nic)
317
 {
306
 {
528
 		/* wait */;
517
 		/* wait */;
529
 }
518
 }
530
 
519
 
520
+static struct nic_operations rtl_operations = {
521
+	.connect	= rtl_connect,
522
+	.poll		= rtl_poll,
523
+	.transmit	= rtl_transmit,
524
+	.irq		= rtl_irq,
525
+	.disable	= rtl_disable,
526
+};
527
+
531
 static struct pci_id rtl8139_nics[] = {
528
 static struct pci_id rtl8139_nics[] = {
532
 PCI_ROM(0x10ec, 0x8129, "rtl8129",       "Realtek 8129"),
529
 PCI_ROM(0x10ec, 0x8129, "rtl8129",       "Realtek 8129"),
533
 PCI_ROM(0x10ec, 0x8139, "rtl8139",       "Realtek 8139"),
530
 PCI_ROM(0x10ec, 0x8139, "rtl8139",       "Realtek 8139"),

Loading…
Cancel
Save