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.
This commit is contained in:
Christian Mauderer
2014-08-22 08:53:10 +02:00
committed by Sebastian Huber
parent 66f1ca64c8
commit d5f5432967
4 changed files with 58 additions and 12 deletions

View File

@@ -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 Additional there has to be one free file descriptor to access the i2c. Set the
CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS accordingly. 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.

View File

@@ -227,6 +227,7 @@ typedef struct {
struct mbuf **mbuf_addr_rx; struct mbuf **mbuf_addr_rx;
struct mbuf **mbuf_addr_tx; struct mbuf **mbuf_addr_tx;
const dwmac_cfg *CFG; const dwmac_cfg *CFG;
int MDIO_BUS_ADDR;
} dwmac_common_context; } dwmac_common_context;
struct dwmac_common_core_ops { struct dwmac_common_core_ops {

View File

@@ -131,7 +131,7 @@ static int dwmac_if_mdio_read(
if ( phy == -1 ) { if ( phy == -1 ) {
reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET( reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET(
reg_value, reg_value,
self->CFG->MDIO_BUS_ADDR self->MDIO_BUS_ADDR
); );
} else { } else {
reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET( reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET(
@@ -187,7 +187,7 @@ static int dwmac_if_mdio_write(
if ( phy == -1 ) { if ( phy == -1 ) {
reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET( reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET(
reg_value, reg_value,
self->CFG->MDIO_BUS_ADDR self->MDIO_BUS_ADDR
); );
} else { } else {
reg_value = MACGRP_GMII_ADDRESS_PHYSICAL_LAYER_ADDRESS_SET( 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; volatile macgrp *macgrp = self->macgrp;
int media = 0; int media = 0;
bool media_ok = dwmac_if_media_status( bool media_ok = dwmac_if_media_status(
self, &media, self->CFG->MDIO_BUS_ADDR ); self, &media, self->MDIO_BUS_ADDR );
uint32_t oui; uint32_t oui;
uint8_t model; uint8_t model;
uint8_t revision; uint8_t revision;
@@ -364,7 +364,7 @@ static int dwmac_if_interface_stats( void *arg )
printf( "\n" ); printf( "\n" );
eno = dwmac_get_phy_info( eno = dwmac_get_phy_info(
self, self,
self->CFG->MDIO_BUS_ADDR, self->MDIO_BUS_ADDR,
&oui, &oui,
&model, &model,
&revision ); &revision );
@@ -372,7 +372,7 @@ static int dwmac_if_interface_stats( void *arg )
if ( eno == 0 ) { if ( eno == 0 ) {
printf( "PHY 0x%02x: OUI = 0x%04" PRIX32 ", Model = 0x%02" PRIX8 ", Rev = " printf( "PHY 0x%02x: OUI = 0x%04" PRIX32 ", Model = 0x%02" PRIX8 ", Rev = "
"0x%02" PRIX8 "\n", "0x%02" PRIX8 "\n",
self->CFG->MDIO_BUS_ADDR, self->MDIO_BUS_ADDR,
oui, oui,
model, model,
revision ); revision );
@@ -387,7 +387,7 @@ static int dwmac_if_interface_stats( void *arg )
); );
} }
} else { } 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" ); 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; uint32_t value = self->macgrp->mac_configuration;
int media = 0; int media = 0;
bool media_ok = dwmac_if_media_status( bool media_ok = dwmac_if_media_status(
self, &media, self->CFG->MDIO_BUS_ADDR ); self, &media, self->MDIO_BUS_ADDR );
if ( media_ok ) { if ( media_ok ) {
@@ -2065,7 +2065,8 @@ static int dwmac_if_attach(
const dwmac_callback_cfg *CALLBACK = &driver_config->CALLBACK; const dwmac_callback_cfg *CALLBACK = &driver_config->CALLBACK;
const dwmac_common_desc_ops *DESC_OPS = const dwmac_common_desc_ops *DESC_OPS =
(const dwmac_common_desc_ops *) driver_config->DESC_OPS->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( self != NULL );
assert( bsd_config != NULL ); assert( bsd_config != NULL );
@@ -2135,9 +2136,15 @@ static int dwmac_if_attach(
} }
if ( eno == 0 ) { 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;
}
if ( 32 < driver_config->MDIO_BUS_ADDR ) { assert( 32 >= self->MDIO_BUS_ADDR );
if ( 32 < self->MDIO_BUS_ADDR ) {
eno = EINVAL; eno = EINVAL;
} }
} }
@@ -2317,7 +2324,7 @@ int dwmac_if_read_from_phy(
if ( arg != NULL ) { if ( arg != NULL ) {
eno = dwmac_if_mdio_read( eno = dwmac_if_mdio_read(
self->CFG->MDIO_BUS_ADDR, self->MDIO_BUS_ADDR,
self, self,
phy_reg, phy_reg,
&value ); &value );
@@ -2341,7 +2348,7 @@ int dwmac_if_write_to_phy(
if ( arg != NULL ) { if ( arg != NULL ) {
eno = dwmac_if_mdio_write( eno = dwmac_if_mdio_write(
self->CFG->MDIO_BUS_ADDR, self->MDIO_BUS_ADDR,
self, self,
phy_reg, phy_reg,
val ); val );

View File

@@ -31,6 +31,16 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #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. /** @brief PHY event.
* *
* Data type to be used for PHY events and event sets. * Data type to be used for PHY events and event sets.