Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

Signed-off-by: Joe Hershberger <joe.hershber...@ni.com>
Cc: Joe Hershberger <joe.hershber...@gmail.com>
Cc: Simon Glass <s...@chromium.org>
Cc: Mike Frysinger <vap...@gentoo.org>
---
Changes for v2:
   - Split apart from "Un-typedef variables in net"
   - Created a new E802_hdr struct and removed 802 members from Ethernet_hdr
   - Renamed structs from *_t to *_hdr since they are nolonger types
   - Replaced offsetof(Ethernet_t, et_dsap) with ETHER_HDR_SIZE in 
arch/powerpc/cpu/mpc8260/ether_fcc.c

 arch/powerpc/cpu/mpc8260/ether_fcc.c |   17 ++++++++---------
 include/net.h                        |   18 ++++++++++++++----
 net/arp.c                            |    4 ++--
 net/arp.h                            |    2 +-
 net/bootp.c                          |    2 +-
 net/cdp.c                            |    4 ++--
 net/net.c                            |   11 ++++++-----
 net/ping.c                           |    2 +-
 net/ping.h                           |    2 +-
 9 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/cpu/mpc8260/ether_fcc.c 
b/arch/powerpc/cpu/mpc8260/ether_fcc.c
index 879ec0e..22e0730 100644
--- a/arch/powerpc/cpu/mpc8260/ether_fcc.c
+++ b/arch/powerpc/cpu/mpc8260/ether_fcc.c
@@ -1049,11 +1049,11 @@ eth_loopback_test (void)
                                        }
                                        else {
                                                ushort datlen = bdp->cbd_datlen;
-                                               Ethernet_t *ehp;
+                                               struct Ethernet_hdr *ehp;
                                                ushort prot;
                                                int ours, tb, n, nbytes;
 
-                                               ehp = (Ethernet_t *) \
+                                               ehp = (struct Ethernet_hdr *) \
                                                        &ecp->rxbufs[i][0];
 
                                                ours = memcmp (ehp->et_src, \
@@ -1063,9 +1063,8 @@ eth_loopback_test (void)
                                                tb = prot & 0x8000;
                                                n = prot & 0x7fff;
 
-                                               nbytes = ELBT_BUFSZ - \
-                                                       offsetof (Ethernet_t, \
-                                                               et_dsap) - \
+                                               nbytes = ELBT_BUFSZ -
+                                                       ETHER_HDR_SIZE -
                                                        ELBT_CRCSZ;
 
                                                /* check the frame is correct */
@@ -1080,10 +1079,10 @@ eth_loopback_test (void)
                                                                patwords[n];
                                                        uint nbb;
 
-                                                       nbb = badbits ( \
-                                                               &ehp->et_dsap, \
-                                                               nbytes, \
-                                                               patword);
+                                                       nbb = badbits(
+                                                           ((uchar *)&ehp) +
+                                                           ETHER_HDR_SIZE,
+                                                           nbytes, patword);
 
                                                        ecp->rxeacc.badbit += \
                                                                nbb;
diff --git a/include/net.h b/include/net.h
index e9b398a..328dc2c 100644
--- a/include/net.h
+++ b/include/net.h
@@ -155,7 +155,17 @@ u32 ether_crc(size_t len, unsigned char const *p);
 /*
  *     Ethernet header
  */
-typedef struct {
+
+struct Ethernet_hdr {
+       uchar           et_dest[6];     /* Destination node             */
+       uchar           et_src[6];      /* Source node                  */
+       ushort          et_protlen;     /* Protocol or length           */
+};
+
+/* Ethernet header size */
+#define ETHER_HDR_SIZE (sizeof(struct Ethernet_hdr))
+
+struct E802_hdr {
        uchar           et_dest[6];     /* Destination node             */
        uchar           et_src[6];      /* Source node                  */
        ushort          et_protlen;     /* Protocol or length           */
@@ -166,10 +176,10 @@ typedef struct {
        uchar           et_snap2;
        uchar           et_snap3;
        ushort          et_prot;        /* 802 protocol                 */
-} Ethernet_t;
+};
 
-#define ETHER_HDR_SIZE 14              /* Ethernet header size         */
-#define E802_HDR_SIZE  22              /* 802 ethernet header size     */
+/* 802 ethernet header size */
+#define E802_HDR_SIZE  (sizeof(struct E802_hdr))
 
 /*
  *     Ethernet header
diff --git a/net/arp.c b/net/arp.c
index d918810..8b30a73 100644
--- a/net/arp.c
+++ b/net/arp.c
@@ -113,7 +113,7 @@ void ArpTimeoutCheck(void)
        }
 }
 
-void ArpReceive(Ethernet_t *et, struct IP_UDP_hdr *ip, int len)
+void ArpReceive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len)
 {
        ARP_t *arp;
        IPaddr_t tmp;
@@ -193,7 +193,7 @@ void ArpReceive(Ethernet_t *et, struct IP_UDP_hdr *ip, int 
len)
                        NetGetHandler()(0, 0, 0, 0, 0);
 #endif
                        /* modify header, and transmit it */
-                       memcpy(((Ethernet_t *)NetArpWaitTxPacket)->
+                       memcpy(((struct Ethernet_hdr *)NetArpWaitTxPacket)->
                                et_dest, NetArpWaitPacketMAC, 6);
                        (void) eth_send(NetArpWaitTxPacket,
                                        NetArpWaitTxPacketSize);
diff --git a/net/arp.h b/net/arp.h
index 3c27348..61a7a21 100644
--- a/net/arp.h
+++ b/net/arp.h
@@ -25,6 +25,6 @@ extern int NetArpWaitTry;
 void ArpInit(void);
 void ArpRequest(void);
 void ArpTimeoutCheck(void);
-void ArpReceive(Ethernet_t *et, struct IP_UDP_hdr *ip, int len);
+void ArpReceive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len);
 
 #endif /* __ARP_H__ */
diff --git a/net/bootp.c b/net/bootp.c
index f5f9119..44c0b5c 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -105,7 +105,7 @@ static void BootpCopyNetParams(struct Bootp_t *bp)
        NetCopyIP(&tmp_ip, &bp->bp_siaddr);
        if (tmp_ip != 0)
                NetCopyIP(&NetServerIP, &bp->bp_siaddr);
-       memcpy(NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
+       memcpy(NetServerEther, ((struct Ethernet_hdr *)NetRxPacket)->et_src, 6);
 #endif
        if (strlen(bp->bp_file) > 0)
                copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
diff --git a/net/cdp.c b/net/cdp.c
index 028be82..6be6665 100644
--- a/net/cdp.c
+++ b/net/cdp.c
@@ -108,7 +108,7 @@ CDPSendTrigger(void)
        uchar *pkt;
        ushort *s;
        ushort *cp;
-       Ethernet_t *et;
+       struct Ethernet_hdr *et;
        int len;
        ushort chksum;
 #if    defined(CONFIG_CDP_DEVICE_ID) || defined(CONFIG_CDP_PORT_ID)   || \
@@ -117,7 +117,7 @@ CDPSendTrigger(void)
 #endif
 
        pkt = NetTxPacket;
-       et = (Ethernet_t *)pkt;
+       et = (struct Ethernet_hdr *)pkt;
 
        /* NOTE: trigger sent not on any VLAN */
 
diff --git a/net/net.c b/net/net.c
index 35ead0e..9c386ae 100644
--- a/net/net.c
+++ b/net/net.c
@@ -825,7 +825,7 @@ static inline struct IP_UDP_hdr *NetDefragment(struct 
IP_UDP_hdr *ip, int *lenp)
  * @parma ip   IP packet containing the ICMP
  */
 static void receive_icmp(struct IP_UDP_hdr *ip, int len,
-                       IPaddr_t src_ip, Ethernet_t *et)
+                       IPaddr_t src_ip, struct Ethernet_hdr *et)
 {
        ICMP_t *icmph = (ICMP_t *)&ip->udp_src;
 
@@ -853,7 +853,7 @@ static void receive_icmp(struct IP_UDP_hdr *ip, int len,
 void
 NetReceive(uchar *inpkt, int len)
 {
-       Ethernet_t *et;
+       struct Ethernet_hdr *et;
        struct IP_UDP_hdr *ip;
        IPaddr_t tmp;
        IPaddr_t src_ip;
@@ -867,7 +867,7 @@ NetReceive(uchar *inpkt, int len)
 
        NetRxPacket = inpkt;
        NetRxPacketLen = len;
-       et = (Ethernet_t *)inpkt;
+       et = (struct Ethernet_hdr *)inpkt;
 
        /* too small packet? */
        if (len < ETHER_HDR_SIZE)
@@ -897,10 +897,11 @@ NetReceive(uchar *inpkt, int len)
        debug("packet received\n");
 
        if (x < 1514) {
+               struct E802_hdr *et802 = (struct E802_hdr *)et;
                /*
                 *      Got a 802 packet.  Check the other protocol field.
                 */
-               x = ntohs(et->et_prot);
+               x = ntohs(et802->et_prot);
 
                ip = (struct IP_UDP_hdr *)(inpkt + E802_HDR_SIZE);
                len -= E802_HDR_SIZE;
@@ -1220,7 +1221,7 @@ NetEthHdrSize(void)
 int
 NetSetEther(uchar *xet, uchar * addr, uint prot)
 {
-       Ethernet_t *et = (Ethernet_t *)xet;
+       struct Ethernet_hdr *et = (struct Ethernet_hdr *)xet;
        ushort myvlanid;
 
        myvlanid = ntohs(NetOurVLAN);
diff --git a/net/ping.c b/net/ping.c
index fe4cead..e7fa64e 100644
--- a/net/ping.c
+++ b/net/ping.c
@@ -98,7 +98,7 @@ void ping_start(void)
        ping_send();
 }
 
-void ping_receive(Ethernet_t *et, struct IP_UDP_hdr *ip, int len)
+void ping_receive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len)
 {
        ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
        IPaddr_t src_ip;
diff --git a/net/ping.h b/net/ping.h
index dd97b58..2560f66 100644
--- a/net/ping.h
+++ b/net/ping.h
@@ -17,7 +17,7 @@
 #include <net.h>
 
 void ping_start(void);
-void ping_receive(Ethernet_t *et, struct IP_UDP_hdr *ip, int len);
+void ping_receive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len);
 
 #endif /* __PING_H__ */
 #endif
-- 
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to