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

Christian Mauderer christian.mauderer at embedded-brains.de
Fri Aug 22 06:53:10 UTC 2014


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/lib/libbsp/arm/altera-cyclone-v/README | 21 +++++++++++++++++++
 c/src/libchip/network/dwmac-common.h         |  1 +
 c/src/libchip/network/dwmac.c                | 31 +++++++++++++++++-----------
 c/src/libchip/network/dwmac.h                | 10 +++++++++
 4 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/c/src/lib/libbsp/arm/altera-cyclone-v/README b/c/src/lib/libbsp/arm/altera-cyclone-v/README
index 0a5bc05..82b2ffb 100644
--- a/c/src/lib/libbsp/arm/altera-cyclone-v/README
+++ b/c/src/lib/libbsp/arm/altera-cyclone-v/README
@@ -14,3 +14,24 @@ have to set the following options:
 
 Additional there has to be one free file descriptor to access the i2c. Set the
 CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS accordingly.
+
+Network
+-------
+The default PHY address can be overwritten by the application. To do this, the
+drv_ctrl pointer of the rtems_bsdnet_ifconfig structure should point to a
+dwmac_ifconfig_drv_ctrl object with the appropriate settings before the
+rtems_bsdnet_initialize_network is called. E.g.:
+
+  static dwmac_ifconfig_drv_ctrl drv_ctrl = {
+    .phy_addr = 1,
+  };
+
+  ...
+
+  rtems_bsdnet_ifconfig.ifconfig->drv_ctrl = &drv_ctrl;
+
+  ...
+
+  rtems_bsdnet_initialize_network();
+
+If drv_ctrl is the NULL-pointer, default values will be used instead.
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..ddcf365 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_ifconfig_drv_ctrl *drv_ctrl =
+    (const dwmac_ifconfig_drv_ctrl *) 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 ( drv_ctrl == NULL ) {
+      self->MDIO_BUS_ADDR = driver_config->MDIO_BUS_ADDR;
+    } else {
+      self->MDIO_BUS_ADDR = drv_ctrl->phy_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..8270988 100644
--- a/c/src/libchip/network/dwmac.h
+++ b/c/src/libchip/network/dwmac.h
@@ -31,6 +31,16 @@
 extern "C" {
 #endif /* __cplusplus */
 
+/** @brief DWMAC user configuration structure.
+ *
+ * Gives the user the possibility to overwrite some configuration data by
+ * setting the drv_ctrl pointer of the @ref rtems_bsdnet_ifconfig structure to a
+ * object with this type.
+ */
+typedef struct {
+  int phy_addr;
+} dwmac_ifconfig_drv_ctrl;
+
 /** @brief PHY event.
  *
  * Data type to be used for PHY events and event sets.
-- 
1.8.4.5



More information about the devel mailing list