* MAC address setting
@ 2011-07-28 10:05 Sascha Hauer
2011-07-28 10:05 ` [PATCH 1/4] ARM i.MX IIM: Add a iim read function Sascha Hauer
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:05 UTC (permalink / raw)
To: barebox
The following series allows boards to associate MAC addresses with
ethernet devices. This makes it possible for boards to correctly
assign a MAC address without fiddling with each network driver.
The series also switches the current i.MX IIM based MAC address
setting to this new functionality.
Sascha Hauer (4):
ARM i.MX IIM: Add a iim read function
net: Add a possibility for boards to give network devices a MAC address
ARM i.MX: rework IIM MAC address setting
ARM i.MX51 babbage: set fec ethernet address from IIM
arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c | 2 +
arch/arm/boards/freescale-mx25-3-stack/3stack.c | 2 +
arch/arm/boards/freescale-mx51-pdk/board.c | 5 ++-
arch/arm/mach-imx/iim.c | 29 ++++++----
arch/arm/mach-imx/include/mach/iim.h | 34 +++++++++++-
drivers/net/fec_imx.c | 4 --
include/net.h | 6 ++
net/eth.c | 59 ++++++++++++++++++++-
8 files changed, 122 insertions(+), 19 deletions(-)
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] ARM i.MX IIM: Add a iim read function
2011-07-28 10:05 MAC address setting Sascha Hauer
@ 2011-07-28 10:05 ` Sascha Hauer
2011-07-28 14:10 ` Marc Kleine-Budde
2011-07-28 10:05 ` [PATCH 2/4] net: Add a possibility for boards to give network devices a MAC address Sascha Hauer
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:05 UTC (permalink / raw)
To: barebox
To allow reading the iim from code.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-imx/iim.c | 28 ++++++++++++++++++++++++----
arch/arm/mach-imx/include/mach/iim.h | 7 +++++++
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c
index 0774ebb..7a8712b 100644
--- a/arch/arm/mach-imx/iim.c
+++ b/arch/arm/mach-imx/iim.c
@@ -22,6 +22,8 @@
#include <xfuncs.h>
#include <errno.h>
#include <param.h>
+#include <fcntl.h>
+#include <malloc.h>
#include <asm/io.h>
@@ -73,7 +75,7 @@ static int do_fuse_sense(unsigned long reg_base, unsigned int bank,
return readb(reg_base + IIM_SDAT);
}
-static ssize_t imx_iim_read(struct cdev *cdev, void *buf, size_t count,
+static ssize_t imx_iim_cdev_read(struct cdev *cdev, void *buf, size_t count,
ulong offset, ulong flags)
{
ulong size, i;
@@ -168,7 +170,7 @@ out:
}
#endif /* CONFIG_IMX_IIM_FUSE_BLOW */
-static ssize_t imx_iim_write(struct cdev *cdev, const void *buf, size_t count,
+static ssize_t imx_iim_cdev_write(struct cdev *cdev, const void *buf, size_t count,
ulong offset, ulong flags)
{
ulong size, i;
@@ -204,8 +206,8 @@ static ssize_t imx_iim_write(struct cdev *cdev, const void *buf, size_t count,
}
static struct file_operations imx_iim_ops = {
- .read = imx_iim_read,
- .write = imx_iim_write,
+ .read = imx_iim_cdev_read,
+ .write = imx_iim_cdev_write,
.lseek = dev_lseek_default,
};
@@ -297,6 +299,24 @@ static int imx_iim_init(void)
}
coredevice_initcall(imx_iim_init);
+int imx_iim_read(unsigned int bank, int offset, int count, void *buf)
+{
+ struct cdev *cdev;
+ char *name = asprintf(DRIVERNAME "_bank%d", bank);
+ int ret;
+
+ cdev = cdev_open(name, O_RDONLY);
+ if (!cdev)
+ return -ENODEV;
+
+ ret = cdev_read(cdev, buf, count, offset, 0);
+
+ cdev_close(cdev);
+ free(name);
+
+ return ret;
+}
+
int imx_iim_get_mac(unsigned char *mac)
{
int i;
diff --git a/arch/arm/mach-imx/include/mach/iim.h b/arch/arm/mach-imx/include/mach/iim.h
index 03ff485..9ff44be 100644
--- a/arch/arm/mach-imx/include/mach/iim.h
+++ b/arch/arm/mach-imx/include/mach/iim.h
@@ -46,8 +46,15 @@ struct imx_iim_platform_data {
};
#ifdef CONFIG_IMX_IIM
+int imx_iim_read(unsigned int bank, int offset, int count, void *buf);
int imx_iim_get_mac(unsigned char *mac);
#else
+static inline int imx_iim_read(unsigned int bank, int offset, int count,
+ void *buf)
+{
+ return -EINVAL;
+}
+
static inline int imx_iim_get_mac(unsigned char *mac)
{
return -EINVAL;
--
1.7.5.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] net: Add a possibility for boards to give network devices a MAC address
2011-07-28 10:05 MAC address setting Sascha Hauer
2011-07-28 10:05 ` [PATCH 1/4] ARM i.MX IIM: Add a iim read function Sascha Hauer
@ 2011-07-28 10:05 ` Sascha Hauer
2011-07-28 10:05 ` [PATCH 3/4] ARM i.MX: rework IIM MAC address setting Sascha Hauer
2011-07-28 10:06 ` [PATCH 4/4] ARM i.MX51 babbage: set fec ethernet address from IIM Sascha Hauer
3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:05 UTC (permalink / raw)
To: barebox
MAC addresses are sometimes stored at unusual places. This
patch makes it possible to give a MAC address to a ethernet
device id. This is independent of the device actually being
present.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/net.h | 6 +++++
net/eth.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 1 deletions(-)
diff --git a/include/net.h b/include/net.h
index 31bf6a2..7fee6fe 100644
--- a/include/net.h
+++ b/include/net.h
@@ -57,6 +57,12 @@ int eth_send(void *packet, int length); /* Send a packet */
int eth_rx(void); /* Check for received packets */
void eth_halt(void); /* stop SCC */
+/* associate a MAC address to a ethernet device. Should be called by
+ * board code for boards which store their MAC address at some unusual
+ * place.
+ */
+void eth_register_ethaddr(int ethid, const char *ethaddr);
+
/*
* Ethernet header
*/
diff --git a/net/eth.c b/net/eth.c
index c5b346c..2a801f5 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -34,6 +34,52 @@ static struct eth_device *eth_current;
static LIST_HEAD(netdev_list);
+struct eth_ethaddr {
+ struct list_head list;
+ u8 ethaddr[6];
+ int ethid;
+};
+
+static LIST_HEAD(ethaddr_list);
+
+static int eth_get_registered_ethaddr(int ethid, void *buf)
+{
+ struct eth_ethaddr *addr;
+
+ list_for_each_entry(addr, ðaddr_list, list) {
+ if (addr->ethid == ethid) {
+ memcpy(buf, addr->ethaddr, 6);
+ return 0;
+ }
+ }
+ return -EINVAL;
+}
+
+static void eth_drop_ethaddr(int ethid)
+{
+ struct eth_ethaddr *addr, *tmp;
+
+ list_for_each_entry_safe(addr, tmp, ðaddr_list, list) {
+ if (addr->ethid == ethid) {
+ list_del(&addr->list);
+ free(addr);
+ return;
+ }
+ }
+}
+
+void eth_register_ethaddr(int ethid, const char *ethaddr)
+{
+ struct eth_ethaddr *addr;
+
+ eth_drop_ethaddr(ethid);
+
+ addr = xzalloc(sizeof(*addr));
+ addr->ethid = ethid;
+ memcpy(addr->ethaddr, ethaddr, 6);
+ list_add_tail(&addr->list, ðaddr_list);
+}
+
void eth_set_current(struct eth_device *eth)
{
if (eth_current && eth_current->active) {
@@ -144,6 +190,7 @@ int eth_register(struct eth_device *edev)
struct device_d *dev = &edev->dev;
unsigned char ethaddr_str[20];
unsigned char ethaddr[6];
+ int ret, found = 0;
if (!edev->get_ethaddr) {
dev_err(dev, "no get_mac_address found for current eth device\n");
@@ -165,7 +212,17 @@ int eth_register(struct eth_device *edev)
list_add_tail(&edev->list, &netdev_list);
- if (edev->get_ethaddr(edev, ethaddr) == 0) {
+ ret = eth_get_registered_ethaddr(dev->id, ethaddr);
+ if (!ret)
+ found = 1;
+
+ if (!found) {
+ ret = edev->get_ethaddr(edev, ethaddr);
+ if (!ret)
+ found = 1;
+ }
+
+ if (found) {
ethaddr_to_string(ethaddr, ethaddr_str);
if (is_valid_ether_addr(ethaddr)) {
dev_info(dev, "got MAC address from EEPROM: %s\n", ethaddr_str);
--
1.7.5.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] ARM i.MX: rework IIM MAC address setting
2011-07-28 10:05 MAC address setting Sascha Hauer
2011-07-28 10:05 ` [PATCH 1/4] ARM i.MX IIM: Add a iim read function Sascha Hauer
2011-07-28 10:05 ` [PATCH 2/4] net: Add a possibility for boards to give network devices a MAC address Sascha Hauer
@ 2011-07-28 10:05 ` Sascha Hauer
2011-07-28 10:06 ` [PATCH 4/4] ARM i.MX51 babbage: set fec ethernet address from IIM Sascha Hauer
3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:05 UTC (permalink / raw)
To: barebox
Switch to the generic way of setting a MAC address for a
device.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c | 2 +
arch/arm/boards/freescale-mx25-3-stack/3stack.c | 2 +
arch/arm/mach-imx/iim.c | 13 ---------
arch/arm/mach-imx/include/mach/iim.h | 31 ++++++++++++++++++---
drivers/net/fec_imx.c | 4 ---
5 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
index 6ea4a6e..d797846 100644
--- a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
+++ b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
@@ -37,6 +37,7 @@
#include <generated/mach-types.h>
#include <mach/imx-nand.h>
#include <mach/imxfb.h>
+#include <mach/iim.h>
#include <fec.h>
#include <nand.h>
#include <mach/imx-flash-header.h>
@@ -251,6 +252,7 @@ static int eukrea_cpuimx25_devices_init(void)
led_gpio_register(&led0);
+ imx25_iim_register_fec_ethaddr();
imx25_add_fec(&fec_info);
nand_info.width = 1;
diff --git a/arch/arm/boards/freescale-mx25-3-stack/3stack.c b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
index 6d4bde5..f71cb4b 100644
--- a/arch/arm/boards/freescale-mx25-3-stack/3stack.c
+++ b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
@@ -37,6 +37,7 @@
#include <mach/imx-flash-header.h>
#include <mach/iomux-mx25.h>
#include <mach/generic.h>
+#include <mach/iim.h>
#include <linux/err.h>
#include <i2c/i2c.h>
#include <mfd/mc34704.h>
@@ -210,6 +211,7 @@ static int imx25_devices_init(void)
register_device(&usbh2_dev);
#endif
+ imx25_iim_register_fec_ethaddr();
imx25_add_fec(&fec_info);
if (readl(IMX_CCM_BASE + CCM_RCSR) & (1 << 14))
diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c
index 7a8712b..d641bf5 100644
--- a/arch/arm/mach-imx/iim.c
+++ b/arch/arm/mach-imx/iim.c
@@ -316,16 +316,3 @@ int imx_iim_read(unsigned int bank, int offset, int count, void *buf)
return ret;
}
-
-int imx_iim_get_mac(unsigned char *mac)
-{
- int i;
-
- if (mac_addr_base == 0)
- return -EINVAL;
-
- for (i = 0; i < 6; i++)
- mac[i] = readb(mac_addr_base + i*4);
-
- return 0;
-}
diff --git a/arch/arm/mach-imx/include/mach/iim.h b/arch/arm/mach-imx/include/mach/iim.h
index 9ff44be..f74b415 100644
--- a/arch/arm/mach-imx/include/mach/iim.h
+++ b/arch/arm/mach-imx/include/mach/iim.h
@@ -24,6 +24,7 @@
#define __MACH_IMX_IIM_H
#include <errno.h>
+#include <net.h>
#define IIM_STAT 0x0000
#define IIM_STATM 0x0004
@@ -47,18 +48,40 @@ struct imx_iim_platform_data {
#ifdef CONFIG_IMX_IIM
int imx_iim_read(unsigned int bank, int offset, int count, void *buf);
-int imx_iim_get_mac(unsigned char *mac);
#else
static inline int imx_iim_read(unsigned int bank, int offset, int count,
void *buf)
{
return -EINVAL;
}
+#endif /* CONFIG_IMX_IIM */
-static inline int imx_iim_get_mac(unsigned char *mac)
+static inline int imx51_iim_register_fec_ethaddr(void)
{
- return -EINVAL;
+ int ret;
+ u8 buf[6];
+
+ ret = imx_iim_read(1, 9, 6, buf);
+ if (ret != 6)
+ return -EINVAL;
+
+ eth_register_ethaddr(0, buf);
+
+ return 0;
+}
+
+static inline int imx25_iim_register_fec_ethaddr(void)
+{
+ int ret;
+ u8 buf[6];
+
+ ret = imx_iim_read(0, 26, 6, buf);
+ if (ret != 6)
+ return -EINVAL;
+
+ eth_register_ethaddr(0, buf);
+
+ return 0;
}
-#endif /* CONFIG_IMX_IIM */
#endif /* __MACH_IMX_IIM_H */
diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index fcb8cc5..619504e 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -269,11 +269,7 @@ static void fec_rbd_clean(int last, struct buffer_descriptor __iomem *pRbd)
static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
{
-#ifdef CONFIG_ARCH_MXS
return -1;
-#else
- return imx_iim_get_mac(mac);
-#endif
}
static int fec_set_hwaddr(struct eth_device *dev, unsigned char *mac)
--
1.7.5.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] ARM i.MX51 babbage: set fec ethernet address from IIM
2011-07-28 10:05 MAC address setting Sascha Hauer
` (2 preceding siblings ...)
2011-07-28 10:05 ` [PATCH 3/4] ARM i.MX: rework IIM MAC address setting Sascha Hauer
@ 2011-07-28 10:06 ` Sascha Hauer
3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:06 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/freescale-mx51-pdk/board.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index d0b8b89..c763719 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -19,7 +19,6 @@
*/
#include <common.h>
-#include <net.h>
#include <init.h>
#include <environment.h>
#include <mach/imx-regs.h>
@@ -40,6 +39,7 @@
#include <mach/generic.h>
#include <mach/iomux-mx51.h>
#include <mach/devices-imx51.h>
+#include <mach/iim.h>
static struct fec_platform_data fec_info = {
.xcv_type = MII100,
@@ -230,11 +230,14 @@ static void babbage_power_init(void)
static int f3s_devices_init(void)
{
struct device_d *sdram_dev;
+
babbage_mmu_init();
sdram_dev = add_mem_device("ram0", 0x90000000, 512 * 1024 * 1024,
IORESOURCE_MEM_WRITEABLE);
armlinux_add_dram(sdram_dev);
+
+ imx51_iim_register_fec_ethaddr();
imx51_add_fec(&fec_info);
imx51_add_mmc0(NULL);
--
1.7.5.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] ARM i.MX IIM: Add a iim read function
2011-07-28 10:05 ` [PATCH 1/4] ARM i.MX IIM: Add a iim read function Sascha Hauer
@ 2011-07-28 14:10 ` Marc Kleine-Budde
0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2011-07-28 14:10 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
[-- Attachment #1.1: Type: text/plain, Size: 3288 bytes --]
On 07/28/2011 12:05 PM, Sascha Hauer wrote:
> To allow reading the iim from code.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> arch/arm/mach-imx/iim.c | 28 ++++++++++++++++++++++++----
> arch/arm/mach-imx/include/mach/iim.h | 7 +++++++
> 2 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c
> index 0774ebb..7a8712b 100644
> --- a/arch/arm/mach-imx/iim.c
> +++ b/arch/arm/mach-imx/iim.c
> @@ -22,6 +22,8 @@
> #include <xfuncs.h>
> #include <errno.h>
> #include <param.h>
> +#include <fcntl.h>
> +#include <malloc.h>
>
> #include <asm/io.h>
>
> @@ -73,7 +75,7 @@ static int do_fuse_sense(unsigned long reg_base, unsigned int bank,
> return readb(reg_base + IIM_SDAT);
> }
>
> -static ssize_t imx_iim_read(struct cdev *cdev, void *buf, size_t count,
> +static ssize_t imx_iim_cdev_read(struct cdev *cdev, void *buf, size_t count,
> ulong offset, ulong flags)
> {
> ulong size, i;
> @@ -168,7 +170,7 @@ out:
> }
> #endif /* CONFIG_IMX_IIM_FUSE_BLOW */
>
> -static ssize_t imx_iim_write(struct cdev *cdev, const void *buf, size_t count,
> +static ssize_t imx_iim_cdev_write(struct cdev *cdev, const void *buf, size_t count,
> ulong offset, ulong flags)
> {
> ulong size, i;
> @@ -204,8 +206,8 @@ static ssize_t imx_iim_write(struct cdev *cdev, const void *buf, size_t count,
> }
>
> static struct file_operations imx_iim_ops = {
> - .read = imx_iim_read,
> - .write = imx_iim_write,
> + .read = imx_iim_cdev_read,
> + .write = imx_iim_cdev_write,
> .lseek = dev_lseek_default,
> };
>
> @@ -297,6 +299,24 @@ static int imx_iim_init(void)
> }
> coredevice_initcall(imx_iim_init);
>
> +int imx_iim_read(unsigned int bank, int offset, int count, void *buf)
The order of count and buf is IMHO unintuitive:
ssize_t read(int fildes, void *buf, size_t nbyte);
Marc
> +{
> + struct cdev *cdev;
> + char *name = asprintf(DRIVERNAME "_bank%d", bank);
> + int ret;
> +
> + cdev = cdev_open(name, O_RDONLY);
> + if (!cdev)
> + return -ENODEV;
> +
> + ret = cdev_read(cdev, buf, count, offset, 0);
> +
> + cdev_close(cdev);
> + free(name);
> +
> + return ret;
> +}
> +
> int imx_iim_get_mac(unsigned char *mac)
> {
> int i;
> diff --git a/arch/arm/mach-imx/include/mach/iim.h b/arch/arm/mach-imx/include/mach/iim.h
> index 03ff485..9ff44be 100644
> --- a/arch/arm/mach-imx/include/mach/iim.h
> +++ b/arch/arm/mach-imx/include/mach/iim.h
> @@ -46,8 +46,15 @@ struct imx_iim_platform_data {
> };
>
> #ifdef CONFIG_IMX_IIM
> +int imx_iim_read(unsigned int bank, int offset, int count, void *buf);
> int imx_iim_get_mac(unsigned char *mac);
> #else
> +static inline int imx_iim_read(unsigned int bank, int offset, int count,
> + void *buf)
> +{
> + return -EINVAL;
> +}
> +
> static inline int imx_iim_get_mac(unsigned char *mac)
> {
> return -EINVAL;
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-07-28 14:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-28 10:05 MAC address setting Sascha Hauer
2011-07-28 10:05 ` [PATCH 1/4] ARM i.MX IIM: Add a iim read function Sascha Hauer
2011-07-28 14:10 ` Marc Kleine-Budde
2011-07-28 10:05 ` [PATCH 2/4] net: Add a possibility for boards to give network devices a MAC address Sascha Hauer
2011-07-28 10:05 ` [PATCH 3/4] ARM i.MX: rework IIM MAC address setting Sascha Hauer
2011-07-28 10:06 ` [PATCH 4/4] ARM i.MX51 babbage: set fec ethernet address from IIM Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox