PERFORCE change 103477 for review
Warner Losh
imp at FreeBSD.org
Tue Aug 8 23:00:50 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=103477
Change 103477 by imp at imp_lighthouse on 2006/08/08 22:59:54
Reorder the way we initialize the NIC. Initialize more of the
nic when we set the MAC address. For that matter, set the mac
address only once correctly in the tftp case, rather than twice,
the first time incorrectly. In the non-ftp case we were setting
it once incorrectly :-(.
This has the nice side effect of +100 bytes free.
Affected files ...
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/loader_prompt.c#12 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/loader_prompt.c#16 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.c#22 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.h#6 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/lib.h#15 edit
Differences ...
==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/loader_prompt.c#12 (text+ko) ====
@@ -171,7 +171,7 @@
static void
ParseCommand(char *buffer)
{
- int argc;
+ int argc, i;
if ((argc = BreakCommand(buffer)) < 1)
return;
@@ -261,17 +261,12 @@
{
// "m <mac address 12 34 56 78 9a bc>
// set mac address using 6 byte values
- unsigned low_addr, high_addr;
+ unsigned char mac[6];
if (argc > 6) {
- low_addr = (p_ASCIIToHex(argv[4]) << 24) |
- (p_ASCIIToHex(argv[3]) << 16) |
- (p_ASCIIToHex(argv[2]) << 8) |
- p_ASCIIToHex(argv[1]);
- high_addr =
- (p_ASCIIToHex(argv[6]) << 8) |
- p_ASCIIToHex(argv[5]);
- SetMACAddress(low_addr, high_addr);
+ for (i = 0; i < 6; i++)
+ mac[i] = p_ASCIIToHex(argv[i + 1]);
+ SetMACAddress(mac);
}
break;
}
==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/loader_prompt.c#16 (text+ko) ====
@@ -222,7 +222,7 @@
static void
ParseCommand(char *buffer)
{
- int argc;
+ int argc, i;
if ((argc = BreakCommand(buffer)) < 1)
return;
@@ -278,17 +278,12 @@
{
// "m <mac address 12 34 56 78 9a bc>
// set mac address using 6 byte values
- unsigned low_addr, high_addr;
+ unsigned char mac[6];
if (argc > 6) {
- low_addr = (p_ASCIIToHex(argv[4]) << 24) |
- (p_ASCIIToHex(argv[3]) << 16) |
- (p_ASCIIToHex(argv[2]) << 8) |
- p_ASCIIToHex(argv[1]);
- high_addr =
- (p_ASCIIToHex(argv[6]) << 8) |
- p_ASCIIToHex(argv[5]);
- SetMACAddress(low_addr, high_addr);
+ for (i = 0; i < 6; i++)
+ mac[i] = p_ASCIIToHex(argv[i + 1]);
+ SetMACAddress(mac);
}
break;
}
==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.c#22 (text+ko) ====
@@ -29,8 +29,9 @@
/* ********************** PRIVATE FUNCTIONS/DATA ******************************/
-static unsigned localMACSet, serverMACSet, MAC_init;
+static unsigned localMACSet, serverMACSet;
static unsigned char localMACAddr[6], serverMACAddr[6];
+static unsigned localMAClow, localMAChigh;
static unsigned localIPSet, serverIPSet;
static unsigned char localIPAddr[4], serverIPAddr[4];
static unsigned short serverPort, localPort;
@@ -458,20 +459,9 @@
// Set the WRAP bit at the end of the list descriptor
p_rxBD[MAX_RX_PACKETS-1].address |= 0x02;
- pEmac->EMAC_CTL = 0;
-
- pEmac->EMAC_CFG = (pEmac->EMAC_CFG & ~(AT91C_EMAC_CLK)) |
-#ifdef BOOT_TSC
- AT91C_EMAC_RMII |
-#endif
- AT91C_EMAC_CLK_HCLK_32 | AT91C_EMAC_CAF;
if (!(pEmac->EMAC_SR & AT91C_EMAC_LINK))
MII_GetLinkSpeed(pEmac);
- // the sequence write EMAC_SA1L and write EMAC_SA1H must be respected
- pEmac->EMAC_SA1L = ((unsigned)localMACAddr[2] << 24) | ((unsigned)localMACAddr[3] << 16) | ((int)localMACAddr[4] << 8) | localMACAddr[5];
- pEmac->EMAC_SA1H = ((unsigned)localMACAddr[0] << 8) | localMACAddr[1];
-
pEmac->EMAC_RBQP = (unsigned) p_rxBD;
pEmac->EMAC_RSR |= (AT91C_EMAC_OVR | AT91C_EMAC_REC | AT91C_EMAC_BNA);
pEmac->EMAC_CTL = AT91C_EMAC_TE | AT91C_EMAC_RE;
@@ -491,58 +481,50 @@
* .KB_C_FN_DEFINITION_END
*/
void
-SetMACAddress(unsigned low_address, unsigned high_address)
+SetMACAddress(unsigned char mac[6])
{
+ AT91PS_PMC pPMC = AT91C_BASE_PMC;
AT91PS_EMAC pEmac = AT91C_BASE_EMAC;
- AT91PS_PMC pPMC = AT91C_BASE_PMC;
/* enable the peripheral clock before using EMAC */
pPMC->PMC_PCER = ((unsigned) 1 << AT91C_ID_EMAC);
- pEmac->EMAC_SA1L = low_address;
- pEmac->EMAC_SA1H = (high_address & 0x0000ffff);
-
- localMACAddr[0] = (low_address >> 0) & 0xFF;
- localMACAddr[1] = (low_address >> 8) & 0xFF;
- localMACAddr[2] = (low_address >> 16) & 0xFF;
- localMACAddr[3] = (low_address >> 24) & 0xFF;
- localMACAddr[4] = (high_address >> 0) & 0xFF;
- localMACAddr[5] = (high_address >> 8) & 0xFF;
-
+ p_memcpy(localMACAddr, mac, 6);
+ localMAClow = (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5];
+ localMAChigh = (mac[0] << 8) | mac[1];
localMACSet = 1;
- // low_address & 0x000000ff = first byte in address
- // low_address & 0x0000ff00 = next
- // low_address & 0x00ff0000 = next
- // low_address & 0xff000000 = next
- // high_address & 0x000000ff = next
- // high_address & 0x0000ff00 = last byte in address
-
- if (!MAC_init) {
- AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_EMAC;
- AT91C_BASE_PIOA->PIO_ASR =
- AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 |
- AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 |
- AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC |
- AT91C_PA7_ETXCK_EREFCK;
- AT91C_BASE_PIOA->PIO_PDR =
- AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 |
- AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 |
- AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC |
- AT91C_PA7_ETXCK_EREFCK;
+ AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_EMAC;
+ AT91C_BASE_PIOA->PIO_ASR =
+ AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 |
+ AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 |
+ AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC |
+ AT91C_PA7_ETXCK_EREFCK;
+ AT91C_BASE_PIOA->PIO_PDR =
+ AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 |
+ AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 |
+ AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC |
+ AT91C_PA7_ETXCK_EREFCK;
#ifdef BOOT_KB9202 /* Really !RMII */
- AT91C_BASE_PIOB->PIO_BSR =
- AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER |
- AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV |
- AT91C_PB18_ECOL | AT91C_PB19_ERXCK;
- AT91C_BASE_PIOB->PIO_PDR =
- AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER |
- AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV |
- AT91C_PB18_ECOL | AT91C_PB19_ERXCK;
+ AT91C_BASE_PIOB->PIO_BSR =
+ AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER |
+ AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV |
+ AT91C_PB18_ECOL | AT91C_PB19_ERXCK;
+ AT91C_BASE_PIOB->PIO_PDR =
+ AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER |
+ AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV |
+ AT91C_PB18_ECOL | AT91C_PB19_ERXCK;
#endif
- MAC_init = 1;
- }
+ pEmac->EMAC_CTL = 0;
+ pEmac->EMAC_CFG = (pEmac->EMAC_CFG & ~(AT91C_EMAC_CLK)) |
+#ifdef BOOT_TSC
+ AT91C_EMAC_RMII |
+#endif
+ AT91C_EMAC_CLK_HCLK_32 | AT91C_EMAC_CAF;
+ // the sequence write EMAC_SA1L and write EMAC_SA1H must be respected
+ pEmac->EMAC_SA1L = localMAClow;
+ pEmac->EMAC_SA1H = localMAChigh;
}
@@ -607,7 +589,6 @@
return ;
AT91F_EmacEntry();
-
GetServerAddress();
dlAddress = (char*)address;
lastSize = 0;
@@ -659,5 +640,4 @@
serverIPSet = 0;
localPort = SWAP16(0x8002);
lastSize = 0;
- MAC_init = 0;
}
==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.h#6 (text+ko) ====
@@ -24,7 +24,7 @@
#ifndef _EMAC_H_
#define _EMAC_H_
-extern void SetMACAddress(unsigned low_address, unsigned high_address);
+extern void SetMACAddress(unsigned char addr[6]);
extern void SetServerIPAddress(unsigned address);
extern void SetLocalIPAddress(unsigned address);
extern void EMAC_Init(void);
==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/lib.h#15 (text) ====
More information about the p4-projects
mailing list