瀏覽代碼

natsemi.c is workin

tags/v0.9.3
Udayan Kumar 18 年之前
父節點
當前提交
4f2fab2e14
共有 1 個文件被更改,包括 102 次插入155 次删除
  1. 102
    155
      src/drivers/net/natsemi.c

+ 102
- 155
src/drivers/net/natsemi.c 查看文件

107
 	struct natsemi_rx rx[NUM_RX_DESC];
107
 	struct natsemi_rx rx[NUM_RX_DESC];
108
 	/* need to add iobuf as we cannot free iobuf->data in close without this 
108
 	/* need to add iobuf as we cannot free iobuf->data in close without this 
109
 	 * alternatively substracting sizeof(head) and sizeof(list_head) can also 
109
 	 * alternatively substracting sizeof(head) and sizeof(list_head) can also 
110
-	 * give the same.*/
110
+	 * give the same.
111
+	 */
111
 	struct io_buffer *iobuf[NUM_RX_DESC];
112
 	struct io_buffer *iobuf[NUM_RX_DESC];
112
-	/*netdev_tx_complete needs pointer to the iobuf of the data so as to free 
113
-	  it from the memory.*/
113
+	/* netdev_tx_complete needs pointer to the iobuf of the data so as to free 
114
+	 * it from the memory.
115
+	 */
114
 	struct io_buffer *tx_iobuf[TX_RING_SIZE];
116
 	struct io_buffer *tx_iobuf[TX_RING_SIZE];
115
 	struct spi_bit_basher spibit;
117
 	struct spi_bit_basher spibit;
116
 	struct spi_device eeprom;
118
 	struct spi_device eeprom;
119
 
121
 
120
 
122
 
121
 /* NATSEMI: Offsets to the device registers.
123
 /* NATSEMI: Offsets to the device registers.
122
-   Unlike software-only systems, device drivers interact with complex hardware.
123
-   It's not useful to define symbolic names for every register bit in the
124
-   device.
125
-*/
124
+ * Unlike software-only systems, device drivers interact with complex hardware.
125
+ * It's not useful to define symbolic names for every register bit in the
126
+ * device.
127
+ */
126
 enum register_offsets {
128
 enum register_offsets {
127
     ChipCmd      = 0x00, 
129
     ChipCmd      = 0x00, 
128
     ChipConfig   = 0x04, 
130
     ChipConfig   = 0x04, 
258
 	.read = nat_spi_read_bit,
260
 	.read = nat_spi_read_bit,
259
 	.write = nat_spi_write_bit,
261
 	.write = nat_spi_write_bit,
260
 };
262
 };
261
-/** Portion of EEPROM available for non-volatile stored options
262
- *
263
- * We use offset 0x40 (i.e. address 0x20), length 0x40.  This block is
264
- * marked as VPD in the rtl8139 datasheets, so we use it only if we
265
- * detect that the card is not supporting VPD.
263
+
264
+/* It looks that this portion of EEPROM can be used for 
265
+ * non-volatile stored options. Data sheet does not talk about this region.
266
+ * Currently it is not working. But with some efforts it can.
266
  */
267
  */
267
 static struct nvo_fragment nat_nvo_fragments[] = {
268
 static struct nvo_fragment nat_nvo_fragments[] = {
268
-	{ 0x0c, 0x40 },
269
+	{ 0x0c, 0x68 },
269
 	{ 0, 0 }
270
 	{ 0, 0 }
270
 };
271
 };
271
 
272
 
272
-/**
273
+/*
273
  * Set up for EEPROM access
274
  * Set up for EEPROM access
274
  *
275
  *
275
  * @v NAT		NATSEMI NIC
276
  * @v NAT		NATSEMI NIC
276
  */
277
  */
277
  void nat_init_eeprom ( struct natsemi_nic *nat ) {
278
  void nat_init_eeprom ( struct natsemi_nic *nat ) {
278
 
279
 
279
-	// Initialise three-wire bus 
280
+	/* Initialise three-wire bus  */
280
 	nat->spibit.basher.op = &nat_basher_ops;
281
 	nat->spibit.basher.op = &nat_basher_ops;
281
 	nat->spibit.bus.mode = SPI_MODE_THREEWIRE;
282
 	nat->spibit.bus.mode = SPI_MODE_THREEWIRE;
282
 	nat->spibit.endianness = SPI_BIT_LITTLE_ENDIAN;
283
 	nat->spibit.endianness = SPI_BIT_LITTLE_ENDIAN;
286
 	init_at93c46 ( &nat->eeprom, 16 );
287
 	init_at93c46 ( &nat->eeprom, 16 );
287
 	nat->eeprom.bus = &nat->spibit.bus;
288
 	nat->eeprom.bus = &nat->spibit.bus;
288
 
289
 
289
-		nat->nvo.nvs = &nat->eeprom.nvs;
290
-		nat->nvo.fragments = nat_nvo_fragments;
290
+	nat->nvo.nvs = &nat->eeprom.nvs;
291
+	nat->nvo.fragments = nat_nvo_fragments;
291
 }
292
 }
292
 
293
 
293
-/**
294
+/*
294
  * Reset NIC
295
  * Reset NIC
295
  *
296
  *
296
  * @v		NATSEMI NIC
297
  * @v		NATSEMI NIC
305
 	mdelay ( 10 );
306
 	mdelay ( 10 );
306
 	nat->tx_dirty=0;
307
 	nat->tx_dirty=0;
307
 	nat->tx_cur=0;
308
 	nat->tx_cur=0;
308
-	for(i=0;i<TX_RING_SIZE;i++)
309
-	{
309
+	for(i=0;i<TX_RING_SIZE;i++) {
310
 		nat->tx[i].link=0;
310
 		nat->tx[i].link=0;
311
 		nat->tx[i].cmdsts=0;
311
 		nat->tx[i].cmdsts=0;
312
 		nat->tx[i].bufptr=0;
312
 		nat->tx[i].bufptr=0;
321
 	outl(SavedClkRun, nat->ioaddr + ClkRun);
321
 	outl(SavedClkRun, nat->ioaddr + ClkRun);
322
 }
322
 }
323
 
323
 
324
-/**
324
+/*
325
  * Open NIC
325
  * Open NIC
326
  *
326
  *
327
  * @v netdev		Net device
327
  * @v netdev		Net device
333
 	uint32_t tx_config,rx_config;
333
 	uint32_t tx_config,rx_config;
334
 	
334
 	
335
 	/* Disable PME:
335
 	/* Disable PME:
336
-        * The PME bit is initialized from the EEPROM contents.
337
-        * PCI cards probably have PME disabled, but motherboard
338
-        * implementations may have PME set to enable WakeOnLan. 
339
-        * With PME set the chip will scan incoming packets but
340
-        * nothing will be written to memory. */
336
+         * The PME bit is initialized from the EEPROM contents.
337
+         * PCI cards probably have PME disabled, but motherboard
338
+         * implementations may have PME set to enable WakeOnLan. 
339
+         * With PME set the chip will scan incoming packets but
340
+         * nothing will be written to memory. 
341
+         */
341
         SavedClkRun = inl(nat->ioaddr + ClkRun);
342
         SavedClkRun = inl(nat->ioaddr + ClkRun);
342
         outl(SavedClkRun & ~0x100, nat->ioaddr + ClkRun);
343
         outl(SavedClkRun & ~0x100, nat->ioaddr + ClkRun);
343
 
344
 
344
-		
345
-
346
-
347
-	 uint8_t last=0;
348
-	 uint8_t last1=0;
349
-	 for ( i = 0 ; i < ETH_ALEN ; i+=2 )
350
-	 {
345
+	/* Setting up Mac address in the NIC */
346
+	for ( i = 0 ; i < ETH_ALEN ; i+=2 ) {
351
 		outl(i,nat->ioaddr+RxFilterAddr);
347
 		outl(i,nat->ioaddr+RxFilterAddr);
352
-		last1=netdev->ll_addr[i]>>7;
353
-	 	netdev->ll_addr[i]=netdev->ll_addr[i]<<1|last;
354
-		last=(netdev->ll_addr[i+1]>>7);
355
-		netdev->ll_addr[i+1]=(netdev->ll_addr[i+1]<<1)+last1;
356
-
357
 		outw ( netdev->ll_addr[i] + (netdev->ll_addr[i+1]<<8), nat->ioaddr +RxFilterData);
348
 		outw ( netdev->ll_addr[i] + (netdev->ll_addr[i+1]<<8), nat->ioaddr +RxFilterData);
358
 	}
349
 	}
359
-       
360
-
361
 
350
 
362
 	/*Set up the Tx Ring */
351
 	/*Set up the Tx Ring */
363
 	nat->tx_cur=0;
352
 	nat->tx_cur=0;
364
 	nat->tx_dirty=0;
353
 	nat->tx_dirty=0;
365
-	for (i=0;i<TX_RING_SIZE;i++)
366
-	{
354
+	for (i=0;i<TX_RING_SIZE;i++) {
367
 		nat->tx[i].link   = virt_to_bus((i+1 < TX_RING_SIZE) ? &nat->tx[i+1] : &nat->tx[0]);
355
 		nat->tx[i].link   = virt_to_bus((i+1 < TX_RING_SIZE) ? &nat->tx[i+1] : &nat->tx[0]);
368
 		nat->tx[i].cmdsts = 0;
356
 		nat->tx[i].cmdsts = 0;
369
 		nat->tx[i].bufptr = 0;
357
 		nat->tx[i].bufptr = 0;
370
 	}
358
 	}
371
 
359
 
372
-
373
-
374
-
375
-
376
 	/* Set up RX ring */
360
 	/* Set up RX ring */
377
 	nat->rx_cur=0;
361
 	nat->rx_cur=0;
378
-	for (i=0;i<NUM_RX_DESC;i++)
379
-	{
362
+	for (i=0;i<NUM_RX_DESC;i++) {
380
 
363
 
381
 		nat->iobuf[i] = alloc_iob ( RX_BUF_SIZE );
364
 		nat->iobuf[i] = alloc_iob ( RX_BUF_SIZE );
382
 		if (!nat->iobuf[i])
365
 		if (!nat->iobuf[i])
386
 		nat->rx[i].bufptr = virt_to_bus(nat->iobuf[i]->data);
369
 		nat->rx[i].bufptr = virt_to_bus(nat->iobuf[i]->data);
387
 	}
370
 	}
388
 
371
 
389
-
390
-	 /* load Receive Descriptor Register */
372
+	/* load Receive Descriptor Register */
391
 	outl(virt_to_bus(&nat->rx[0]), nat->ioaddr + RxRingPtr);
373
 	outl(virt_to_bus(&nat->rx[0]), nat->ioaddr + RxRingPtr);
392
 	DBG("Natsemi Rx descriptor loaded with: %X\n",(unsigned int)inl(nat->ioaddr+RxRingPtr));		
374
 	DBG("Natsemi Rx descriptor loaded with: %X\n",(unsigned int)inl(nat->ioaddr+RxRingPtr));		
393
 
375
 
398
 	/* Enables RX */
380
 	/* Enables RX */
399
 	outl(RxFilterEnable|AcceptBroadcast|AcceptAllMulticast|AcceptMyPhys, nat->ioaddr+RxFilterAddr);
381
 	outl(RxFilterEnable|AcceptBroadcast|AcceptAllMulticast|AcceptMyPhys, nat->ioaddr+RxFilterAddr);
400
 
382
 
401
-	/* Initialize other registers. */
402
-	/* Configure the PCI bus bursts and FIFO thresholds. */
403
-	/* Configure for standard, in-spec Ethernet. */
383
+	/* Initialize other registers. 
384
+	 * Configure the PCI bus bursts and FIFO thresholds. 
385
+	 * Configure for standard, in-spec Ethernet. 
386
+	 */
404
 	if (inl(nat->ioaddr + ChipConfig) & 0x20000000) {	/* Full duplex */
387
 	if (inl(nat->ioaddr + ChipConfig) & 0x20000000) {	/* Full duplex */
405
 		tx_config = 0xD0801002;
388
 		tx_config = 0xD0801002;
406
 		rx_config = 0x10000020;
389
 		rx_config = 0x10000020;
411
 	outl(tx_config, nat->ioaddr + TxConfig);
394
 	outl(tx_config, nat->ioaddr + TxConfig);
412
 	outl(rx_config, nat->ioaddr + RxConfig);
395
 	outl(rx_config, nat->ioaddr + RxConfig);
413
 
396
 
414
-
415
-
416
 	/*start the receiver  */
397
 	/*start the receiver  */
417
         outl(RxOn, nat->ioaddr + ChipCmd);
398
         outl(RxOn, nat->ioaddr + ChipCmd);
418
 
399
 
419
 	/*enable interrupts*/
400
 	/*enable interrupts*/
420
 	outl((RxOk|RxErr|TxOk|TxErr),nat->ioaddr + IntrMask); 
401
 	outl((RxOk|RxErr|TxOk|TxErr),nat->ioaddr + IntrMask); 
421
-	outl(1,nat->ioaddr +IntrEnable);
422
-
423
-
424
-
402
+	//outl(1,nat->ioaddr +IntrEnable);
425
 
403
 
426
 	return 0;
404
 	return 0;
427
 }
405
 }
440
 	nat_reset ( nat );
418
 	nat_reset ( nat );
441
 
419
 
442
 	/* Free RX ring */
420
 	/* Free RX ring */
443
-	for (i=0;i<NUM_RX_DESC;i++)
444
-	{
421
+	for (i=0;i<NUM_RX_DESC;i++) {
445
 		
422
 		
446
 		free_iob( nat->iobuf[i] );
423
 		free_iob( nat->iobuf[i] );
447
 	}
424
 	}
448
 	/* disable interrupts */
425
 	/* disable interrupts */
449
-	outl(0,nat->ioaddr + IntrMask) ;
426
+	//outl(0,nat->ioaddr + IntrMask) ;
450
 }
427
 }
451
 
428
 
452
 /** 
429
 /** 
459
 static int nat_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
436
 static int nat_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
460
 	struct natsemi_nic *nat = netdev->priv;
437
 	struct natsemi_nic *nat = netdev->priv;
461
 
438
 
462
-       /* check for space in TX ring */
463
-
464
-	if (nat->tx[nat->tx_cur].cmdsts !=0)
465
-	{
466
-		printf ( "TX overflow\n" );
439
+        /* check for space in TX ring */
440
+	if (nat->tx[nat->tx_cur].cmdsts !=0) {
441
+		DBG( "TX overflow\n" );
467
 		return -ENOBUFS;
442
 		return -ENOBUFS;
468
 	}
443
 	}
469
 
444
 
478
 	      virt_to_bus ( &iobuf->data ), iob_len ( iobuf ) );
453
 	      virt_to_bus ( &iobuf->data ), iob_len ( iobuf ) );
479
 
454
 
480
 	nat->tx[nat->tx_cur].bufptr = virt_to_bus(iobuf->data);
455
 	nat->tx[nat->tx_cur].bufptr = virt_to_bus(iobuf->data);
481
-	nat->tx[nat->tx_cur].cmdsts= (uint32_t) iob_len(iobuf)|OWN;
482
-
483
-
456
+	nat->tx[nat->tx_cur].cmdsts= iob_len(iobuf)|OWN;
457
+	/* increment the circular buffer pointer to the next buffer location */
484
 	nat->tx_cur=(nat->tx_cur+1) % TX_RING_SIZE;
458
 	nat->tx_cur=(nat->tx_cur+1) % TX_RING_SIZE;
485
 
459
 
486
 	/*start the transmitter  */
460
 	/*start the transmitter  */
513
 	/* check the status of packets given to card for transmission */	
487
 	/* check the status of packets given to card for transmission */	
514
 	DBG("Intr status %X\n",intr_status);
488
 	DBG("Intr status %X\n",intr_status);
515
 
489
 
516
-
517
 	i=nat->tx_dirty;
490
 	i=nat->tx_dirty;
518
-	while(i!=nat->tx_cur)
519
-	{
491
+	while(i!=nat->tx_cur) {
520
 		status=nat->tx[nat->tx_dirty].cmdsts;
492
 		status=nat->tx[nat->tx_dirty].cmdsts;
521
 		DBG("value of tx_dirty = %d tx_cur=%d status=%X\n",
493
 		DBG("value of tx_dirty = %d tx_cur=%d status=%X\n",
522
 			nat->tx_dirty,nat->tx_cur,status);
494
 			nat->tx_dirty,nat->tx_cur,status);
525
 		if(status & OWN) 
497
 		if(status & OWN) 
526
 			break;
498
 			break;
527
 		/* Check if any errors in transmission */
499
 		/* Check if any errors in transmission */
528
-		if (! (status & DescPktOK))
529
-		{
530
-			printf("Error in sending Packet status:%X\n",
500
+		if (! (status & DescPktOK)) {
501
+			DBG("Error in sending Packet status:%X\n",
531
 					(unsigned int)status);
502
 					(unsigned int)status);
503
+			netdev_tx_complete_err(netdev,nat->tx_iobuf[nat->tx_dirty],-EINVAL);
504
+		} else {
505
+			DBG("Success in transmitting Packet\n");
506
+			netdev_tx_complete(netdev,nat->tx_iobuf[nat->tx_dirty]);
532
 		}
507
 		}
533
-		else
534
-		{
535
-			DBG("Success in transmitting Packet with data\n");
536
-		//	DBG_HD(&nat->tx[nat->tx_dirty].bufptr,130);
537
-		}
538
-		netdev_tx_complete(netdev,nat->tx_iobuf[nat->tx_dirty]);
539
 		/* setting cmdsts zero, indicating that it can be reused */
508
 		/* setting cmdsts zero, indicating that it can be reused */
540
 		nat->tx[nat->tx_dirty].cmdsts=0;
509
 		nat->tx[nat->tx_dirty].cmdsts=0;
541
 		nat->tx_dirty=(nat->tx_dirty +1) % TX_RING_SIZE;
510
 		nat->tx_dirty=(nat->tx_dirty +1) % TX_RING_SIZE;
542
 		i=(i+1) % TX_RING_SIZE;
511
 		i=(i+1) % TX_RING_SIZE;
543
-
544
 	}
512
 	}
545
-			
546
 	
513
 	
547
-	rx_status=(unsigned int)nat->rx[nat->rx_cur].cmdsts; 
548
 	/* Handle received packets */
514
 	/* Handle received packets */
549
-	while (rx_quota && (rx_status & OWN))
550
-	{
515
+	rx_status=(unsigned int)nat->rx[nat->rx_cur].cmdsts; 
516
+	while (rx_quota && (rx_status & OWN)) {
551
 		rx_len= (rx_status & DSIZE) - CRC_SIZE;
517
 		rx_len= (rx_status & DSIZE) - CRC_SIZE;
552
-
553
 		/*check for the corrupt packet */
518
 		/*check for the corrupt packet */
554
-		if((rx_status & (DescMore|DescPktOK|RxTooLong)) != DescPktOK)
555
-		{
556
-			 printf("natsemi_poll: Corrupted packet received, "
519
+		if((rx_status & (DescMore|DescPktOK|RxTooLong)) != DescPktOK) {
520
+			 DBG("natsemi_poll: Corrupted packet received, "
557
 					"buffer status = %X ^ %X \n",rx_status,
521
 					"buffer status = %X ^ %X \n",rx_status,
558
 					(unsigned int) nat->rx[nat->rx_cur].cmdsts);
522
 					(unsigned int) nat->rx[nat->rx_cur].cmdsts);
559
-		}
560
-		else
561
-		{
523
+			 netdev_rx_err(netdev,NULL,-EINVAL);
524
+		} else 	{
562
 			rx_iob = alloc_iob(rx_len);
525
 			rx_iob = alloc_iob(rx_len);
563
 			if(!rx_iob) 
526
 			if(!rx_iob) 
564
 				/* leave packet for next call to poll*/
527
 				/* leave packet for next call to poll*/
565
 				goto end;
528
 				goto end;
566
 			memcpy(iob_put(rx_iob,rx_len),
529
 			memcpy(iob_put(rx_iob,rx_len),
567
-					bus_to_virt(nat->rx[nat->rx_cur].bufptr),rx_len);
568
-
530
+					nat->iobuf[nat->rx_cur]->data,rx_len);
569
 			DBG("received packet\n");
531
 			DBG("received packet\n");
570
 			/* add to the receive queue. */
532
 			/* add to the receive queue. */
571
 			netdev_rx(netdev,rx_iob);
533
 			netdev_rx(netdev,rx_iob);
573
 		}
535
 		}
574
 		nat->rx[nat->rx_cur].cmdsts = RX_BUF_SIZE;
536
 		nat->rx[nat->rx_cur].cmdsts = RX_BUF_SIZE;
575
 		nat->rx_cur=(nat->rx_cur+1) % NUM_RX_DESC;
537
 		nat->rx_cur=(nat->rx_cur+1) % NUM_RX_DESC;
576
-		rx_status=(unsigned int)nat->rx[nat->rx_cur].cmdsts; 
538
+		rx_status=nat->rx[nat->rx_cur].cmdsts; 
577
 	}
539
 	}
578
 
540
 
579
 end:
541
 end:
580
 
542
 
581
-	 /* re-enable the potentially idle receive state machine */
543
+	/* re-enable the potentially idle receive state machine */
582
 	outl(RxOn, nat->ioaddr + ChipCmd);	
544
 	outl(RxOn, nat->ioaddr + ChipCmd);	
583
 //	outl(1,nat->ioaddr +IntrEnable);
545
 //	outl(1,nat->ioaddr +IntrEnable);
584
 }				
546
 }				
585
 
547
 
548
+/** RTL8139 net device operations */
549
+static struct net_device_operations nat_operations = {
550
+        .open           = nat_open,
551
+        .close          = nat_close,
552
+        .transmit       = nat_transmit,
553
+        .poll           = nat_poll,
554
+};
586
 
555
 
587
-
588
-
589
-
590
-
591
-/**
556
+/*
592
  * Probe PCI device
557
  * Probe PCI device
593
  *
558
  *
594
  * @v pci	PCI device
559
  * @v pci	PCI device
599
 		       const struct pci_device_id *id __unused ) {
564
 		       const struct pci_device_id *id __unused ) {
600
 	struct net_device *netdev;
565
 	struct net_device *netdev;
601
 	struct natsemi_nic *nat = NULL;
566
 	struct natsemi_nic *nat = NULL;
602
-	int registered_netdev = 0;
603
 	int rc;
567
 	int rc;
604
-	uint32_t advertising;
605
-
606
-	/* Fix up PCI device */
607
-	adjust_pci_device ( pci );
568
+	int i;
569
+	uint8_t ll_addr_encoded[MAX_LL_ADDR_LEN];
570
+	uint8_t last=0;
571
+	uint8_t last1=0;
608
 
572
 
609
 	/* Allocate net device */
573
 	/* Allocate net device */
610
 	netdev = alloc_etherdev ( sizeof ( *nat ) );
574
 	netdev = alloc_etherdev ( sizeof ( *nat ) );
611
-	if ( ! netdev ) {
612
-		rc = -ENOMEM;
613
-		goto err;
614
-	}
575
+	if ( ! netdev ) 
576
+		return -ENOMEM;
577
+	netdev_init(netdev,&nat_operations);
615
 	nat = netdev->priv;
578
 	nat = netdev->priv;
616
 	pci_set_drvdata ( pci, netdev );
579
 	pci_set_drvdata ( pci, netdev );
617
 	netdev->dev = &pci->dev;
580
 	netdev->dev = &pci->dev;
618
 	memset ( nat, 0, sizeof ( *nat ) );
581
 	memset ( nat, 0, sizeof ( *nat ) );
619
 	nat->ioaddr = pci->ioaddr;
582
 	nat->ioaddr = pci->ioaddr;
620
 
583
 
621
-	/* getting the IRQ vector */
622
-	unsigned long vector_phys = IRQ_INT ( pci->irq ) * 4;
623
-	DBG_HDA ( vector_phys, phys_to_virt ( vector_phys ), 4 );
624
-	DBG_HD ( phys_to_virt ( 0xfaea5 ), 64 );
625
-	DBG (" PIC state %X\n", irq_enabled(pci->irq));
626
-	DBG (" IRQ Number %X\n",pci->irq);
627
-
628
-
584
+	/* Fix up PCI device */
585
+	adjust_pci_device ( pci );
629
 
586
 
630
 	/* Reset the NIC, set up EEPROM access and read MAC address */
587
 	/* Reset the NIC, set up EEPROM access and read MAC address */
631
 	nat_reset ( nat );
588
 	nat_reset ( nat );
632
 	nat_init_eeprom ( nat );
589
 	nat_init_eeprom ( nat );
633
-	nvs_read ( &nat->eeprom.nvs, EE_MAC, netdev->ll_addr, ETH_ALEN );
634
-	uint8_t  eetest[128];	
635
-	nvs_read ( &nat->eeprom.nvs, 0, eetest,128 );
590
+	nvs_read ( &nat->eeprom.nvs, EE_MAC, ll_addr_encoded, ETH_ALEN );
636
 	
591
 	
637
-
638
-	/* mdio routine of etherboot-5.4.0 natsemi driver has been removed and 
639
-	 * statement to read from MII transceiver control section is used directly
640
-	 */
641
-
642
-        advertising = inl(nat->ioaddr + 0x80 + (4<<2)) & 0xffff; 
643
-        {
644
-	   	uint32_t chip_config = inl(nat->ioaddr + ChipConfig);
645
-		DBG("%s: Transceiver default autoneg. %s 10 %s %s duplex.\n",
646
-	      	pci->driver_name,
647
-	        chip_config & 0x2000 ? "enabled, advertise" : "disabled, force",
648
-	        chip_config & 0x4000 ? "0" : "",
649
-	        chip_config & 0x8000 ? "full" : "half");
650
-    	}
651
-	DBG("%s: Transceiver status %hX advertising %hX\n",pci->driver_name, (int)inl(nat->ioaddr + 0x84),(unsigned int) advertising);
652
-
653
-
654
-
655
-
592
+	/* decoding the MAC address read from NVS 
593
+	 * and save it in netdev->ll_addr
594
+         */
595
+	for ( i = 0 ; i < ETH_ALEN ; i+=2 ) {
596
+		last1=ll_addr_encoded[i]>>7;
597
+	 	netdev->ll_addr[i]=ll_addr_encoded[i]<<1|last;
598
+		last=(ll_addr_encoded[i+1]>>7);
599
+		netdev->ll_addr[i+1]=(ll_addr_encoded[i+1]<<1)+last1;
600
+	}
601
+	/* TODO remove the block below */
602
+	DBG("Contents of the EEPROM\n");
603
+	uint8_t eetest[108];
604
+	nvs_read(&nat->eeprom.nvs,0,eetest,108);
605
+	DBG_HD(&eetest,108);
656
 
606
 
657
 	/* Point to NIC specific routines */
607
 	/* Point to NIC specific routines */
608
+	/*
658
 	netdev->open	 = nat_open;
609
 	netdev->open	 = nat_open;
659
 	netdev->close	 = nat_close;
610
 	netdev->close	 = nat_close;
660
 	netdev->transmit = nat_transmit;
611
 	netdev->transmit = nat_transmit;
661
 	netdev->poll	 = nat_poll;
612
 	netdev->poll	 = nat_poll;
662
-
613
+	*/
663
 	/* Register network device */
614
 	/* Register network device */
664
 	if ( ( rc = register_netdev ( netdev ) ) != 0 )
615
 	if ( ( rc = register_netdev ( netdev ) ) != 0 )
665
-		goto err;
666
-	registered_netdev = 1;
616
+		goto err_register_netdev;
667
 
617
 
668
-	/* Register non-volatile storagei
669
-	 * uncomment lines below in final version*/
670
-	
671
-	 if ( nat->nvo.nvs ) {
618
+	/* Register non-volatile storage */
619
+	if ( nat->nvo.nvs ) {
672
 		if ( ( rc = nvo_register ( &nat->nvo ) ) != 0 )
620
 		if ( ( rc = nvo_register ( &nat->nvo ) ) != 0 )
673
-			goto err;
621
+			goto err_register_nvo;
674
 	}
622
 	}
675
 	
623
 	
676
 
624
 
677
 	return 0;
625
 	return 0;
678
 
626
 
679
- err:
627
+err_register_nvo:
628
+	unregister_netdev ( netdev );
629
+err_register_netdev:
680
 	/* Disable NIC */
630
 	/* Disable NIC */
681
-	if ( nat )
682
-		nat_reset ( nat );
683
-	if ( registered_netdev )
684
-		unregister_netdev ( netdev );
631
+	nat_reset ( nat );
685
 	/* Free net device */
632
 	/* Free net device */
686
 	netdev_put ( netdev );
633
 	netdev_put ( netdev );
687
 	return rc;
634
 	return rc;

Loading…
取消
儲存