Commit 5cfa3039 authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller

net: fec: make driver endian-safe

The driver treats the device descriptors as CPU-endian, which appears
to be correct with the default endianness on both ARM (typically LE)
and PowerPC (typically BE) SoCs, indicating that the hardware block
is generated differently. Add endianness annotations and byteswaps as
necessary.

It's not clear that the ifdef there really is correct and shouldn't
just be #ifdef CONFIG_ARM, but I also can't test on anything but the
i.MX6 HummingBoard where this gets it working with a BE kernel.
Signed-off-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent db0e51af
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
obj-$(CONFIG_FEC) += fec.o obj-$(CONFIG_FEC) += fec.o
fec-objs :=fec_main.o fec_ptp.o fec-objs :=fec_main.o fec_ptp.o
CFLAGS_fec_main.o := -D__CHECK_ENDIAN__
CFLAGS_fec_ptp.o := -D__CHECK_ENDIAN__
obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o
ifeq ($(CONFIG_FEC_MPC52xx_MDIO),y) ifeq ($(CONFIG_FEC_MPC52xx_MDIO),y)
obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx_phy.o obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx_phy.o
......
...@@ -190,28 +190,46 @@ ...@@ -190,28 +190,46 @@
/* /*
* Define the buffer descriptor structure. * Define the buffer descriptor structure.
*
* Evidently, ARM SoCs have the FEC block generated in a
* little endian mode; or at least ARCH_MXC/SOC_IMX28 do,
* so adjust endianness accordingly.
*/ */
#if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28) #if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
#define fec32_to_cpu le32_to_cpu
#define fec16_to_cpu le16_to_cpu
#define cpu_to_fec32 cpu_to_le32
#define cpu_to_fec16 cpu_to_le16
#define __fec32 __le32
#define __fec16 __le16
struct bufdesc { struct bufdesc {
unsigned short cbd_datlen; /* Data length */ __fec16 cbd_datlen; /* Data length */
unsigned short cbd_sc; /* Control and status info */ __fec16 cbd_sc; /* Control and status info */
unsigned long cbd_bufaddr; /* Buffer address */ __fec32 cbd_bufaddr; /* Buffer address */
}; };
#else #else
#define fec32_to_cpu be32_to_cpu
#define fec16_to_cpu be16_to_cpu
#define cpu_to_fec32 cpu_to_be32
#define cpu_to_fec16 cpu_to_be16
#define __fec32 __be32
#define __fec16 __be16
struct bufdesc { struct bufdesc {
unsigned short cbd_sc; /* Control and status info */ __fec16 cbd_sc; /* Control and status info */
unsigned short cbd_datlen; /* Data length */ __fec16 cbd_datlen; /* Data length */
unsigned long cbd_bufaddr; /* Buffer address */ __fec32 cbd_bufaddr; /* Buffer address */
}; };
#endif #endif
struct bufdesc_ex { struct bufdesc_ex {
struct bufdesc desc; struct bufdesc desc;
unsigned long cbd_esc; __fec32 cbd_esc;
unsigned long cbd_prot; __fec32 cbd_prot;
unsigned long cbd_bdu; __fec32 cbd_bdu;
unsigned long ts; __fec32 ts;
unsigned short res0[4]; __fec16 res0[4];
}; };
/* /*
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment