PERFORCE change 95456 for review
Warner Losh
imp at FreeBSD.org
Mon Apr 17 22:19:44 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=95456
Change 95456 by imp at imp_hammer on 2006/04/17 22:19:35
Hopefully fix all the compile warnings w/o introducing new bugs.
# This code makes some, ummmm, interesting assumptions
Affected files ...
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/emac.c#5 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/emac.h#3 edit
Differences ...
==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/emac.c#5 (text+ko) ====
@@ -24,6 +24,7 @@
#include "emac.h"
#include "p_string.h"
#include "at91rm9200_lowlevel.h"
+#include "debug_io.h"
/* ****************************** GLOBALS *************************************/
@@ -51,17 +52,17 @@
* This private function calculates the IP checksum for various headers.
* .KB_C_FN_DEFINITION_END
*/
-static unsigned short IP_checksum(unsigned short *p, int len)
+static unsigned short
+IP_checksum(void *cp, int len)
{
unsigned i, t;
+ unsigned short *p = (unsigned short *)cp;
len &= ~1;
-
for (i=0,t=0; i<len; i+=2, ++p)
t += SWAP16(*p);
-
t = (t & 0xffff) + (t >> 16);
- return (~t);
+ return (~t);
}
@@ -71,14 +72,13 @@
* This private function sends an ARP request to determine the server MAC.
* .KB_C_FN_DEFINITION_END
*/
-static void GetServerAddress(void) {
-
+static void
+GetServerAddress(void)
+{
arp_header_t *p_ARP;
p_ARP = (arp_header_t*)transmitBuffer;
-
p_memset((char*)p_ARP->dest_mac, 0xFF, 6);
-
p_memcpy((char*)p_ARP->src_mac, (char*)localMACAddr, 6);
p_ARP->frame_type = SWAP16(PROTOCOL_ARP);
@@ -111,7 +111,8 @@
* This private function initializes and send a TFTP packet.
* .KB_C_FN_DEFINITION_END
*/
-static void Send_TFTP_Packet(char *tftpData, unsigned tftpLength)
+static void
+Send_TFTP_Packet(char *tftpData, unsigned tftpLength)
{
transmit_header_t *macHdr = (transmit_header_t*)tftpSendPacket;
ip_header_t *ipHdr;
@@ -122,9 +123,9 @@
p_memcpy((char*)macHdr->src_mac, (char*)localMACAddr, 6);
- *(unsigned short*)&(macHdr->ip_tos) = SWAP16(PROTOCOL_IP);
+ macHdr->proto_mac = SWAP16(PROTOCOL_IP);
- ipHdr = (ip_header_t*)&macHdr->packet_length;
+ ipHdr = &macHdr->iphdr;
ipHdr->ip_v_hl = 0x45;
ipHdr->ip_tos = 0;
@@ -139,7 +140,7 @@
p_memcpy((char*)ipHdr->ip_dst, (char*)serverIPAddr, 4);
- ipHdr->ip_sum = SWAP16(IP_checksum((unsigned short*)ipHdr, 20));
+ ipHdr->ip_sum = SWAP16(IP_checksum(ipHdr, 20));
udpHdr = (udp_header_t*)(ipHdr + 1);
@@ -150,7 +151,7 @@
p_memcpy((char*)udpHdr+8, tftpData, tftpLength);
- t_checksum = IP_checksum((unsigned short*)ipHdr + 6, (16 + tftpLength));
+ t_checksum = IP_checksum((char *)ipHdr + 12, (16 + tftpLength));
t_checksum = (~t_checksum) & 0xFFFF;
t_checksum += 25 + tftpLength;
@@ -174,8 +175,9 @@
* This private function sends a RRQ packet to the server.
* .KB_C_FN_DEFINITION_END
*/
-static void TFTP_RequestFile(char *filename) {
-
+static void
+TFTP_RequestFile(char *filename)
+{
tftp_header_t tftpHeader;
char *cPtr, *ePtr, *mPtr;
unsigned length;
@@ -200,8 +202,9 @@
* This private function sends an ACK packet to the server.
* .KB_C_FN_DEFINITION_END
*/
-static void TFTP_ACK_Data(char *data, unsigned short block_num, unsigned short len) {
-
+static void
+TFTP_ACK_Data(char *data, unsigned short block_num, unsigned short len)
+{
tftp_header_t tftpHeader;
if (block_num == (ackBlock + 1)) {
@@ -227,9 +230,10 @@
* any here.
* .KB_C_FN_DEFINITION_END
*/
-static void CheckForNewPacket(ip_header_t *pHeader) {
-
- unsigned short *pFrameType, *pArpOp;
+static void
+CheckForNewPacket(ip_header_t *pHeader)
+{
+ unsigned short *pFrameType;
unsigned i;
char *pData;
ip_header_t *pIpHeader;
@@ -256,11 +260,9 @@
switch (SWAP16(*pFrameType)) {
case PROTOCOL_ARP:
-
- pArpOp = (unsigned short *) (pData + 20);
p_ARP = (arp_header_t*)pData;
- if (SWAP16(*pArpOp) == ARP_REPLY) {
+ if (SWAP16(p_ARP->operation) == ARP_REPLY) {
// check if new server info is available
if ((!serverMACSet) &&
@@ -274,10 +276,10 @@
}
}
- if (SWAP16(*pArpOp) == ARP_REQUEST) {
+ if (SWAP16(p_ARP->operation) == ARP_REQUEST) {
// ARP REPLY operation
- *pArpOp = SWAP16(ARP_REPLY);
+ p_ARP->operation = SWAP16(ARP_REPLY);
// Fill the dest address and src address
for (i = 0; i <6; i++) {
@@ -304,7 +306,7 @@
break;
case PROTOCOL_IP:
- pIpHeader = (ip_header_t*)(pData + 14);
+ pIpHeader = (ip_header_t*)(pData + 14);
p_memcpy((char*)pHeader, (char*)pIpHeader,sizeof(ip_header_t));
switch(pIpHeader->ip_p) {
@@ -357,8 +359,9 @@
* This private function reads the PHY device.
* .KB_C_FN_DEFINITION_END
*/
-static unsigned short AT91F_MII_ReadPhy (AT91PS_EMAC pEmac, unsigned char addr) {
-
+static unsigned short
+AT91F_MII_ReadPhy (AT91PS_EMAC pEmac, unsigned char addr)
+{
unsigned value = 0x60020000 | (addr << 18);
pEmac->EMAC_CTL |= AT91C_EMAC_MPE;
@@ -375,11 +378,12 @@
* This private function determines the link speed set by the PHY.
* .KB_C_FN_DEFINITION_END
*/
-static void MII_GetLinkSpeed(AT91PS_EMAC pEmac) {
+static void
+MII_GetLinkSpeed(AT91PS_EMAC pEmac)
+{
+ unsigned short stat2;
+ unsigned update = 0;
- unsigned short stat2;
- unsigned update = 0;
-
stat2 = AT91F_MII_ReadPhy(pEmac, MII_STS2_REG);
if (!(stat2 & 0x400)) {
@@ -408,14 +412,14 @@
* This private function initializes the EMAC on the chip.
* .KB_C_FN_DEFINITION_END
*/
-void AT91F_EmacEntry(void) {
-
+static void
+AT91F_EmacEntry(void)
+{
unsigned i;
char *pRxPacket = (char*)RX_DATA_START;
AT91PS_EMAC pEmac = AT91C_BASE_EMAC;
for (i = 0; i < MAX_RX_PACKETS; ++i) {
-
p_rxBD[i].address = (unsigned)pRxPacket;
p_rxBD[i].size = 0;
pRxPacket += RX_PACKET_SIZE;
@@ -430,7 +434,9 @@
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_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;
@@ -454,7 +460,9 @@
* four bytes while high_address is the last 2 bytes of the 48-bit value.
* .KB_C_FN_DEFINITION_END
*/
-void SetMACAddress(unsigned low_address, unsigned high_address) {
+void
+SetMACAddress(unsigned low_address, unsigned high_address)
+{
AT91PS_EMAC pEmac = AT91C_BASE_EMAC;
AT91PS_PMC pPMC = AT91C_BASE_PMC;
@@ -489,8 +497,9 @@
* This global function sets the IP of the TFTP download server.
* .KB_C_FN_DEFINITION_END
*/
-void SetServerIPAddress(unsigned address) {
-
+void
+SetServerIPAddress(unsigned address)
+{
// force update in case the IP has changed
serverMACSet = 0;
@@ -509,8 +518,9 @@
* This global function sets the IP of this module.
* .KB_C_FN_DEFINITION_END
*/
-void SetLocalIPAddress(unsigned address) {
-
+void
+SetLocalIPAddress(unsigned address)
+{
// force update in case the IP has changed
serverMACSet = 0;
@@ -531,10 +541,10 @@
* executed.
* .KB_C_FN_DEFINITION_END
*/
-void TFTP_Download(unsigned address, char *filename)
+void
+TFTP_Download(unsigned address, char *filename)
{
ip_header_t IpHeader;
- AT91PS_EMAC pEmac = (AT91PS_EMAC)AT91C_BASE_EMAC;
unsigned thisSeconds, running, state;
int timeout, tickUpdate;
@@ -553,53 +563,50 @@
return ;
if (!MAC_init) {
- AT91C_BASE_PMC->PMC_PCER =
- ((unsigned) 1 << AT91C_ID_EMAC);
+ AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_EMAC;
- AT91C_BASE_PIOA->PIO_ASR =
- ((unsigned) AT91C_PA14_ERXER ) |
- ((unsigned) AT91C_PA12_ERX0 ) |
- ((unsigned) AT91C_PA13_ERX1 ) |
- ((unsigned) AT91C_PA8_ETXEN ) |
- ((unsigned) AT91C_PA16_EMDIO ) |
- ((unsigned) AT91C_PA9_ETX0 ) |
- ((unsigned) AT91C_PA10_ETX1 ) |
- ((unsigned) AT91C_PA11_ECRS_ECRSDV) |
- ((unsigned) AT91C_PA15_EMDC ) |
- ((unsigned) AT91C_PA7_ETXCK_EREFCK);
+ 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_BSR = 0;
- AT91C_BASE_PIOA->PIO_PDR =
- ((unsigned) AT91C_PA14_ERXER ) |
- ((unsigned) AT91C_PA12_ERX0 ) |
- ((unsigned) AT91C_PA13_ERX1 ) |
- ((unsigned) AT91C_PA8_ETXEN ) |
- ((unsigned) AT91C_PA16_EMDIO ) |
- ((unsigned) AT91C_PA9_ETX0 ) |
- ((unsigned) AT91C_PA10_ETX1 ) |
- ((unsigned) AT91C_PA11_ECRS_ECRSDV) |
- ((unsigned) AT91C_PA15_EMDC ) |
- ((unsigned) 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_PIOB->PIO_ASR = 0;
AT91C_BASE_PIOB->PIO_BSR =
- ((unsigned) AT91C_PB12_ETX2) |
- ((unsigned) AT91C_PB13_ETX3) |
- ((unsigned) AT91C_PB14_ETXER) |
- ((unsigned) AT91C_PB15_ERX2) |
- ((unsigned) AT91C_PB16_ERX3) |
- ((unsigned) AT91C_PB17_ERXDV) |
- ((unsigned) AT91C_PB18_ECOL) |
- ((unsigned) AT91C_PB19_ERXCK);
+ 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 =
- ((unsigned) AT91C_PB12_ETX2) |
- ((unsigned) AT91C_PB13_ETX3) |
- ((unsigned) AT91C_PB14_ETXER) |
- ((unsigned) AT91C_PB15_ERX2) |
- ((unsigned) AT91C_PB16_ERX3) |
- ((unsigned) AT91C_PB17_ERXDV) |
- ((unsigned) AT91C_PB18_ECOL) |
- ((unsigned) AT91C_PB19_ERXCK);
-
+ AT91C_PB12_ETX2 |
+ AT91C_PB13_ETX3 |
+ AT91C_PB14_ETXER |
+ AT91C_PB15_ERX2 |
+ AT91C_PB16_ERX3 |
+ AT91C_PB17_ERXDV |
+ AT91C_PB18_ECOL |
+ AT91C_PB19_ERXCK;
MAC_init = 1;
}
@@ -675,8 +682,9 @@
* This global function initializes variables used in tftp transfers.
* .KB_C_FN_DEFINITION_END
*/
-void EMAC_Init(void) {
-
+void
+EMAC_Init(void)
+{
p_rxBD = (receive_descriptor_t*)RX_BUFFER_START;
localMACSet = 0;
serverMACSet = 0;
==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/emac.h#3 (text+ko) ====
@@ -39,7 +39,7 @@
#define PROTOCOL_IP 0x0800
#define PROTOCOL_UDP 0x11
-#define SWAP16(x) (((x & 0xff) << 8) | (x >> 8))
+#define SWAP16(x) ((((x) & 0xff) << 8) | ((x) >> 8))
typedef struct {
unsigned address;
@@ -66,7 +66,7 @@
unsigned char target_mac[6];
unsigned char target_ip[4];
-} arp_header_t;
+} __attribute__((__packed__)) arp_header_t;
typedef struct {
unsigned char ip_v_hl;
@@ -79,36 +79,28 @@
unsigned short ip_sum;
unsigned char ip_src[4];
unsigned char ip_dst[4];
-} ip_header_t;
+} __attribute__((__packed__)) ip_header_t;
typedef struct {
unsigned char dest_mac[6];
unsigned char src_mac[6];
- unsigned char ip_tos;
- unsigned char ip_hl_v;
+ unsigned short proto_mac;
unsigned short packet_length;
- unsigned short ip_id;
- unsigned short ip_len;
- unsigned char ip_p;
- unsigned char ip_ttl;
- unsigned short ip_off;
- unsigned short ip_sum;
- unsigned char ip_src[4];
- unsigned char ip_dst[4];
-} transmit_header_t;
+ ip_header_t iphdr;
+} __attribute__((__packed__)) transmit_header_t;
typedef struct {
unsigned short src_port;
unsigned short dst_port;
unsigned short udp_len;
unsigned short udp_cksum;
-} udp_header_t;
+} __attribute__((__packed__)) udp_header_t;
typedef struct {
unsigned short opcode;
unsigned short block_num;
unsigned char data[512];
-} tftp_header_t;
+} __attribute__((__packed__)) tftp_header_t;
#define TFTP_RRQ_OPCODE 1
#define TFTP_WRQ_OPCODE 2
More information about the p4-projects
mailing list