[U-Boot] [PATCH] driver: net: ldpaa_eth: Get MAC address from env variable
Joe Hershberger
joe.hershberger at gmail.com
Tue Aug 11 19:30:46 CEST 2015
Hi Prabhakar,
On Mon, Aug 10, 2015 at 7:30 AM, Prabhakar Kushwaha
<prabhakar at freescale.com> wrote:
> Currently ldpaa ethernet driver rely on DPL file to statically configure
> mac address for the DPNIs. It is not a correct approach.
>
> Add support of reading MAC address for env variable and configure same
> in DPAA driver.
>
> Signed-off-by: Prabhakar Kushwaha <prabhakar at freescale.com>
> ---
> drivers/net/ldpaa_eth/ldpaa_eth.c | 48 +++++++++++++++++++++++++++------------
> 1 file changed, 34 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index 4ed1805..1b4094a 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -23,6 +23,38 @@ static int init_phy(struct eth_device *dev)
> return 0;
> }
>
> +static int ldpaa_set_mac_from_env(struct eth_device *net_dev)
> +{
> + struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
> + uint8_t mac_addr[6];
> + char ethaddr[15] = "eth";
> + int err;
> +
> + if (priv->dpni_id == 1)
> + strcat(ethaddr, "addr");
> + else
> + sprintf(ethaddr, "eth%daddr", priv->dpni_id - 1);
> +
> + err = eth_getenv_enetaddr(ethaddr, mac_addr);
Instead of re-implementing this logic, you should just implement a
write_hwaddr() ops function for this driver. The network stack will
assign the MAC address either from the env, the ROM (as set by the
driver in init if available), or random if configured.
> + if (err) {
> + err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
> + priv->dpni_handle, mac_addr);
> + if (err) {
> + printf("dpni_add_mac_addr() failed\n");
> + return err;
> + }
> +
> + memcpy(net_dev->enetaddr, mac_addr, 0x6);
> + err = 0;
> + } else {
> + printf("%s: MAC address is not set\n", ethaddr);
> + err = 1;
> + }
> +
> + return err;
> +}
> +
> static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
> const struct dpaa_fd *fd)
> {
> @@ -216,7 +248,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
> {
> struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
> struct dpni_queue_attr rx_queue_attr;
> - uint8_t mac_addr[6];
> int err;
>
> if (net_dev->state == ETH_STATE_ACTIVE)
> @@ -236,20 +267,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
> if (err)
> goto err_bind;
>
> - err = dpni_get_primary_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
> - priv->dpni_handle, mac_addr);
> - if (err) {
> - printf("dpni_get_primary_mac_addr() failed\n");
> + err = ldpaa_set_mac_from_env(net_dev);
> + if (err)
> return err;
> - }
> -
> - memcpy(net_dev->enetaddr, mac_addr, 0x6);
> -
> - /* setup the MAC address */
> - if (net_dev->enetaddr[0] & 0x01) {
> - printf("%s: MacAddress is multcast address\n", __func__);
> - return 1;
> - }
>
> #ifdef CONFIG_PHYLIB
> /* TODO Check this path */
> --
> 1.9.1
>
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
More information about the U-Boot
mailing list