[PATCH] libchip/dwmac: Make PHY address user configurable.

Joel Sherrill joel.sherrill at oarcorp.com
Thu Aug 21 15:15:34 UTC 2014


How does the user configure the address?

Other than that, I don't see anything.

--joel
On 8/21/2014 10:07 AM, Christian Mauderer wrote:
> From: Christian Mauderer <Christian.Mauderer at embedded-brains.de>
>
> This patch allows the user to configure the PHY address for the DWMAC driver by
> giving a pointer to a dwmac_user_cfg structure to network stak via
> rtems_bsdnet_config.ifconfig->drv_ctrl.
> ---
>  c/src/libchip/network/dwmac-common.h |  1 +
>  c/src/libchip/network/dwmac.c        | 31 +++++++++++++++++++------------
>  c/src/libchip/network/dwmac.h        |  8 ++++++++
>  3 files changed, 28 insertions(+), 12 deletions(-)
>
> diff --git a/c/src/libchip/network/dwmac-common.h b/c/src/libchip/network/dwmac-common.h
> index b61b833..05bf941 100644
> --- a/c/src/libchip/network/dwmac-common.h
> +++ b/c/src/libchip/network/dwmac-common.h
> @@ -227,6 +227,7 @@ typedef struct {
>    struct mbuf **mbuf_addr_rx;
>    struct mbuf **mbuf_addr_tx;
>    const dwmac_cfg *CFG;
> +  int MDIO_BUS_ADDR;
>  } dwmac_common_context;
>  
>  struct dwmac_common_core_ops {
> diff --git a/c/src/libchip/network/dwmac.c b/c/src/libchip/network/dwmac.c
> index 20d87dc..499e02b 100644
> --- a/c/src/libchip/network/dwmac.c
> +++ b/c/src/libchip/network/dwmac.c
> @@ -131,7 +131,7 @@ static int dwmac_if_mdio_read(
>    if ( phy == -1 ) {
>      reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET(
>        reg_value,
> -      self->CFG->MDIO_BUS_ADDR
> +      self->MDIO_BUS_ADDR
>        );
>    } else {
>      reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET(
> @@ -187,7 +187,7 @@ static int dwmac_if_mdio_write(
>    if ( phy == -1 ) {
>      reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET(
>        reg_value,
> -      self->CFG->MDIO_BUS_ADDR
> +      self->MDIO_BUS_ADDR
>        );
>    } else {
>      reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET(
> @@ -347,7 +347,7 @@ static int dwmac_if_interface_stats( void *arg )
>    volatile macgrp      *macgrp   = self->macgrp;
>    int                   media    = 0;
>    bool                  media_ok = dwmac_if_media_status(
> -    self, &media, self->CFG->MDIO_BUS_ADDR );
> +    self, &media, self->MDIO_BUS_ADDR );
>    uint32_t              oui;
>    uint8_t               model;
>    uint8_t               revision;
> @@ -364,7 +364,7 @@ static int dwmac_if_interface_stats( void *arg )
>      printf( "\n" );
>      eno = dwmac_get_phy_info(
>        self,
> -      self->CFG->MDIO_BUS_ADDR,
> +      self->MDIO_BUS_ADDR,
>        &oui,
>        &model,
>        &revision );
> @@ -372,7 +372,7 @@ static int dwmac_if_interface_stats( void *arg )
>      if ( eno == 0 ) {
>        printf( "PHY 0x%02x: OUI = 0x%04" PRIX32 ", Model = 0x%02" PRIX8 ", Rev = "
>                "0x%02" PRIX8 "\n",
> -              self->CFG->MDIO_BUS_ADDR,
> +              self->MDIO_BUS_ADDR,
>                oui,
>                model,
>                revision );
> @@ -387,7 +387,7 @@ static int dwmac_if_interface_stats( void *arg )
>          );
>      }
>    } else {
> -    printf( "PHY %d communication error\n", self->CFG->MDIO_BUS_ADDR );
> +    printf( "PHY %d communication error\n", self->MDIO_BUS_ADDR );
>    }
>  
>    printf( "\nHardware counters:\n" );
> @@ -1250,7 +1250,7 @@ static int dwmac_update_autonegotiation_params( dwmac_common_context *self )
>    uint32_t value    = self->macgrp->mac_configuration;
>    int      media    = 0;
>    bool     media_ok = dwmac_if_media_status(
> -    self, &media, self->CFG->MDIO_BUS_ADDR );
> +    self, &media, self->MDIO_BUS_ADDR );
>  
>  
>    if ( media_ok ) {
> @@ -2065,7 +2065,8 @@ static int dwmac_if_attach(
>    const dwmac_callback_cfg    *CALLBACK = &driver_config->CALLBACK;
>    const dwmac_common_desc_ops *DESC_OPS =
>      (const dwmac_common_desc_ops *) driver_config->DESC_OPS->ops;
> -
> +  const dwmac_user_cfg        *user_cfg =
> +    (const dwmac_user_cfg *) bsd_config->drv_ctrl;
>  
>    assert( self != NULL );
>    assert( bsd_config != NULL );
> @@ -2135,9 +2136,15 @@ static int dwmac_if_attach(
>    }
>  
>    if ( eno == 0 ) {
> -    assert( 32 >= driver_config->MDIO_BUS_ADDR );
> +    if ( user_cfg == NULL ) {
> +      self->MDIO_BUS_ADDR = driver_config->MDIO_BUS_ADDR;
> +    } else {
> +      self->MDIO_BUS_ADDR = user_cfg->MDIO_BUS_ADDR;
> +    }
> +
> +    assert( 32 >= self->MDIO_BUS_ADDR );
>  
> -    if ( 32 < driver_config->MDIO_BUS_ADDR ) {
> +    if ( 32 < self->MDIO_BUS_ADDR ) {
>        eno = EINVAL;
>      }
>    }
> @@ -2317,7 +2324,7 @@ int dwmac_if_read_from_phy(
>  
>    if ( arg != NULL ) {
>      eno = dwmac_if_mdio_read(
> -      self->CFG->MDIO_BUS_ADDR,
> +      self->MDIO_BUS_ADDR,
>        self,
>        phy_reg,
>        &value );
> @@ -2341,7 +2348,7 @@ int dwmac_if_write_to_phy(
>  
>    if ( arg != NULL ) {
>      eno = dwmac_if_mdio_write(
> -      self->CFG->MDIO_BUS_ADDR,
> +      self->MDIO_BUS_ADDR,
>        self,
>        phy_reg,
>        val );
> diff --git a/c/src/libchip/network/dwmac.h b/c/src/libchip/network/dwmac.h
> index 9ccf75a..2220aa7 100644
> --- a/c/src/libchip/network/dwmac.h
> +++ b/c/src/libchip/network/dwmac.h
> @@ -31,6 +31,14 @@
>  extern "C" {
>  #endif /* __cplusplus */
>  
> +/** @brief DWMAC user configuration structure.
> + *
> + * Gives the user the possibility to overwrite some configuration data.
> + */
> +typedef struct {
> +  int MDIO_BUS_ADDR;
> +} dwmac_user_cfg;
> +
>  /** @brief PHY event.
>   *
>   * Data type to be used for PHY events and event sets.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the devel mailing list