summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mauderer <Christian.Mauderer@embedded-brains.de>2014-08-22 08:53:10 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-08-22 11:48:27 +0200
commitd5f543296737df9b9410fccca4b7105679d0e17a (patch)
tree40e3583a4fcbff95c17e94ad5d7fb9680e374577
parentbsp/tms570: disable huge memory demanding tests for internal RAM build variant. (diff)
downloadrtems-d5f543296737df9b9410fccca4b7105679d0e17a.tar.bz2
libchip/dwmac: Make PHY address user configurable
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 stack via rtems_bsdnet_ifconfig::drv_ctrl.
-rw-r--r--c/src/lib/libbsp/arm/altera-cyclone-v/README28
-rw-r--r--c/src/libchip/network/dwmac-common.h1
-rw-r--r--c/src/libchip/network/dwmac.c31
-rw-r--r--c/src/libchip/network/dwmac.h10
4 files changed, 58 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 0a5bc05505..658fe77255 100644
--- a/c/src/lib/libbsp/arm/altera-cyclone-v/README
+++ b/c/src/lib/libbsp/arm/altera-cyclone-v/README
@@ -14,3 +14,31 @@ 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.:
+
+ #include <libchip/dwmac.h>
+ #include <bsp.h>
+
+ static dwmac_ifconfig_drv_ctrl drv_ctrl = {
+ .phy_addr = 1
+ };
+
+ ...
+
+ static struct rtems_bsdnet_ifconfig some_ifconfig = {
+ .name = RTEMS_BSP_NETWORK_DRIVER_NAME,
+ .attach = RTEMS_BSP_NETWORK_DRIVER_ATTACH,
+ .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 b61b833078..05bf941604 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 20d87dc83b..ddcf36530c 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 9ccf75af44..8270988b1e 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.