From owner-p4-projects@FreeBSD.ORG Tue Aug 8 23:00:50 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2852416A4E1; Tue, 8 Aug 2006 23:00:50 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C547F16A4DA for ; Tue, 8 Aug 2006 23:00:49 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7FF5F43D46 for ; Tue, 8 Aug 2006 23:00:49 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k78N0ndm062466 for ; Tue, 8 Aug 2006 23:00:49 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k78N0nfg062461 for perforce@freebsd.org; Tue, 8 Aug 2006 23:00:49 GMT (envelope-from imp@freebsd.org) Date: Tue, 8 Aug 2006 23:00:49 GMT Message-Id: <200608082300.k78N0nfg062461@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh To: Perforce Change Reviews Cc: Subject: PERFORCE change 103477 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Aug 2006 23:00:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=103477 Change 103477 by imp@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 // 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 // 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) ====