1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-01 08:42:12 +02:00

drivers/net/vsc9953: Cleanup patch

This patch groups some macros defined for registers and
replaces some magic numbers from vsc9953 with macros. Also,
"port" and "port_nr" words are replaced with "port_no",
puts each variable declaration on a line and removes
unnecessary tabs.

Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: York Sun <yorksun@freescale.com>
This commit is contained in:
Codrin Ciubotariu
2015-07-24 16:52:45 +03:00
committed by York Sun
parent c4390486a6
commit 3cc8cfffb2
2 changed files with 154 additions and 125 deletions

View File

@@ -10,6 +10,8 @@
#include <asm/fsl_serdes.h>
#include <fm_eth.h>
#include <fsl_memac.h>
#include <errno.h>
#include <malloc.h>
#include <vsc9953.h>
static struct vsc9953_info vsc9953_l2sw = {
@@ -25,44 +27,44 @@ static struct vsc9953_info vsc9953_l2sw = {
.port[9] = VSC9953_PORT_INFO_INITIALIZER(9),
};
void vsc9953_port_info_set_mdio(int port, struct mii_dev *bus)
void vsc9953_port_info_set_mdio(int port_no, struct mii_dev *bus)
{
if (!VSC9953_PORT_CHECK(port))
if (!VSC9953_PORT_CHECK(port_no))
return;
vsc9953_l2sw.port[port].bus = bus;
vsc9953_l2sw.port[port_no].bus = bus;
}
void vsc9953_port_info_set_phy_address(int port, int address)
void vsc9953_port_info_set_phy_address(int port_no, int address)
{
if (!VSC9953_PORT_CHECK(port))
if (!VSC9953_PORT_CHECK(port_no))
return;
vsc9953_l2sw.port[port].phyaddr = address;
vsc9953_l2sw.port[port_no].phyaddr = address;
}
void vsc9953_port_info_set_phy_int(int port, phy_interface_t phy_int)
void vsc9953_port_info_set_phy_int(int port_no, phy_interface_t phy_int)
{
if (!VSC9953_PORT_CHECK(port))
if (!VSC9953_PORT_CHECK(port_no))
return;
vsc9953_l2sw.port[port].enet_if = phy_int;
vsc9953_l2sw.port[port_no].enet_if = phy_int;
}
void vsc9953_port_enable(int port)
void vsc9953_port_enable(int port_no)
{
if (!VSC9953_PORT_CHECK(port))
if (!VSC9953_PORT_CHECK(port_no))
return;
vsc9953_l2sw.port[port].enabled = 1;
vsc9953_l2sw.port[port_no].enabled = 1;
}
void vsc9953_port_disable(int port)
void vsc9953_port_disable(int port_no)
{
if (!VSC9953_PORT_CHECK(port))
if (!VSC9953_PORT_CHECK(port_no))
return;
vsc9953_l2sw.port[port].enabled = 0;
vsc9953_l2sw.port[port_no].enabled = 0;
}
static void vsc9953_mdio_write(struct vsc9953_mii_mng *phyregs, int port_addr,
@@ -148,21 +150,21 @@ static int init_phy(struct eth_device *dev)
return 0;
}
static int vsc9953_port_init(int port)
static int vsc9953_port_init(int port_no)
{
struct eth_device *dev;
/* Internal ports never have a PHY */
if (VSC9953_INTERNAL_PORT_CHECK(port))
if (VSC9953_INTERNAL_PORT_CHECK(port_no))
return 0;
/* alloc eth device */
dev = (struct eth_device *)calloc(1, sizeof(struct eth_device));
if (!dev)
return 1;
return -ENOMEM;
sprintf(dev->name, "SW@PORT%d", port);
dev->priv = &vsc9953_l2sw.port[port];
sprintf(dev->name, "SW@PORT%d", port_no);
dev->priv = &vsc9953_l2sw.port[port_no];
dev->init = NULL;
dev->halt = NULL;
dev->send = NULL;
@@ -170,7 +172,7 @@ static int vsc9953_port_init(int port)
if (init_phy(dev)) {
free(dev);
return 1;
return -ENODEV;
}
return 0;
@@ -178,7 +180,9 @@ static int vsc9953_port_init(int port)
void vsc9953_init(bd_t *bis)
{
u32 i, hdx_cfg = 0, phy_addr = 0;
u32 i;
u32 hdx_cfg = 0;
u32 phy_addr = 0;
int timeout;
struct vsc9953_system_reg *l2sys_reg;
struct vsc9953_qsys_reg *l2qsys_reg;
@@ -312,25 +316,23 @@ void vsc9953_init(bd_t *bis)
#ifdef CONFIG_VSC9953_CMD
/* Enable/disable status of a VSC9953 port */
static void vsc9953_port_status_set(int port_nr, u8 enabled)
static void vsc9953_port_status_set(int port_no, u8 enabled)
{
u32 val;
struct vsc9953_qsys_reg *l2qsys_reg;
/* Administrative down */
if (vsc9953_l2sw.port[port_nr].enabled == 0)
if (!vsc9953_l2sw.port[port_no].enabled)
return;
l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
VSC9953_QSYS_OFFSET);
val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_nr]);
if (enabled == 1)
val |= (1 << 13);
if (enabled)
setbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
VSC9953_PORT_ENA);
else
val &= ~(1 << 13);
out_le32(&l2qsys_reg->sys.switch_port_mode[port_nr], val);
clrbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
VSC9953_PORT_ENA);
}
/* Set all VSC9953 ports' status */
@@ -343,14 +345,14 @@ static void vsc9953_port_all_status_set(u8 enabled)
}
/* Start autonegotiation for a VSC9953 PHY */
static void vsc9953_phy_autoneg(int port_nr)
static void vsc9953_phy_autoneg(int port_no)
{
if (!vsc9953_l2sw.port[port_nr].phydev)
if (!vsc9953_l2sw.port[port_no].phydev)
return;
if (vsc9953_l2sw.port[port_nr].phydev->drv->startup(
vsc9953_l2sw.port[port_nr].phydev))
printf("Failed to start PHY for port %d\n", port_nr);
if (vsc9953_l2sw.port[port_no].phydev->drv->startup(
vsc9953_l2sw.port[port_no].phydev))
printf("Failed to start PHY for port %d\n", port_no);
}
/* Start autonegotiation for all VSC9953 PHYs */
@@ -363,7 +365,7 @@ static void vsc9953_phy_all_autoneg(void)
}
/* Print a VSC9953 port's configuration */
static void vsc9953_port_config_show(int port)
static void vsc9953_port_config_show(int port_no)
{
int speed;
int duplex;
@@ -375,20 +377,20 @@ static void vsc9953_port_config_show(int port)
l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
VSC9953_QSYS_OFFSET);
val = in_le32(&l2qsys_reg->sys.switch_port_mode[port]);
enabled = vsc9953_l2sw.port[port].enabled &
((val & 0x00002000) >> 13);
val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_no]);
enabled = vsc9953_l2sw.port[port_no].enabled &&
(val & VSC9953_PORT_ENA);
/* internal ports (8 and 9) are fixed */
if (VSC9953_INTERNAL_PORT_CHECK(port)) {
if (VSC9953_INTERNAL_PORT_CHECK(port_no)) {
link = 1;
speed = SPEED_2500;
duplex = DUPLEX_FULL;
} else {
if (vsc9953_l2sw.port[port].phydev) {
link = vsc9953_l2sw.port[port].phydev->link;
speed = vsc9953_l2sw.port[port].phydev->speed;
duplex = vsc9953_l2sw.port[port].phydev->duplex;
if (vsc9953_l2sw.port[port_no].phydev) {
link = vsc9953_l2sw.port[port_no].phydev->link;
speed = vsc9953_l2sw.port[port_no].phydev->speed;
duplex = vsc9953_l2sw.port[port_no].phydev->duplex;
} else {
link = -1;
speed = -1;
@@ -396,7 +398,7 @@ static void vsc9953_port_config_show(int port)
}
}
printf("%8d ", port);
printf("%8d ", port_no);
printf("%8s ", enabled == 1 ? "enabled" : "disabled");
printf("%8s ", link == 1 ? "up" : "down");
@@ -487,11 +489,11 @@ static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(ethsw, 5, 0, do_ethsw,
"vsc9953 l2 switch commands",
"port <port_nr> enable|disable\n"
"port <port_no> enable|disable\n"
" - enable/disable an l2 switch port\n"
" port_nr=0..9; use \"all\" for all ports\n"
"ethsw port <port_nr> show\n"
" port_no=0..9; use \"all\" for all ports\n"
"ethsw port <port_no> show\n"
" - show an l2 switch port's configuration\n"
" port_nr=0..9; use \"all\" for all ports\n"
" port_no=0..9; use \"all\" for all ports\n"
);
#endif /* CONFIG_VSC9953_CMD */

View File

@@ -17,7 +17,6 @@
#include <config.h>
#include <miiphy.h>
#include <asm/types.h>
#include <malloc.h>
#define VSC9953_OFFSET (CONFIG_SYS_CCSRBAR_DEFAULT + 0x800000)
@@ -33,29 +32,57 @@
#define T1040_SWITCH_GMII_DEV_OFFSET 0x010000
#define VSC9953_PHY_REGS_OFFST 0x0000AC
/* Macros for vsc9953_chip_regs.soft_rst register */
#define VSC9953_SOFT_SWC_RST_ENA 0x00000001
/* Macros for vsc9953_sys_sys.reset_cfg register */
#define VSC9953_CORE_ENABLE 0x80
#define VSC9953_MEM_ENABLE 0x40
#define VSC9953_MEM_INIT 0x20
#define VSC9953_PORT_ENA 0x00003a00
/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_ena_cfg register */
#define VSC9953_MAC_ENA_CFG 0x00000011
/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_mode_cfg register */
#define VSC9953_MAC_MODE_CFG 0x00000011
/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_ifg_cfg register */
#define VSC9953_MAC_IFG_CFG 0x00000515
/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_hdx_cfg register */
#define VSC9953_MAC_HDX_CFG 0x00001043
#define VSC9953_CLOCK_CFG 0x00000001
#define VSC9953_CLOCK_CFG_1000M 0x00000001
#define VSC9953_PFC_FC 0x00000001
#define VSC9953_PFC_FC_QSGMII 0x00000000
#define VSC9953_MAC_FC_CFG 0x04700000
#define VSC9953_MAC_FC_CFG_QSGMII 0x00700000
#define VSC9953_PAUSE_CFG 0x001ffffe
#define VSC9953_TOT_TAIL_DROP_LVL 0x000003ff
#define VSC9953_FRONT_PORT_MODE 0x00000000
/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_maxlen_cfg register */
#define VSC9953_MAC_MAX_LEN 0x000005ee
/* Macros for vsc9953_dev_gmii_port_mode.clock_cfg register */
#define VSC9953_CLOCK_CFG 0x00000001
#define VSC9953_CLOCK_CFG_1000M 0x00000001
/* Macros for vsc9953_sys_sys.front_port_mode register */
#define VSC9953_FRONT_PORT_MODE 0x00000000
/* Macros for vsc9953_ana_pfc.pfc_cfg register */
#define VSC9953_PFC_FC 0x00000001
#define VSC9953_PFC_FC_QSGMII 0x00000000
/* Macros for vsc9953_sys_pause_cfg.mac_fc_cfg register */
#define VSC9953_MAC_FC_CFG 0x04700000
#define VSC9953_MAC_FC_CFG_QSGMII 0x00700000
/* Macros for vsc9953_sys_pause_cfg.pause_cfg register */
#define VSC9953_PAUSE_CFG 0x001ffffe
/* Macros for vsc9953_sys_pause_cfgtot_tail_drop_lvl register */
#define VSC9953_TOT_TAIL_DROP_LVL 0x000003ff
/* Macros for vsc9953_vcap_core_cfg.vcap_mv_cfg register */
#define VSC9953_VCAP_MV_CFG 0x0000ffff
#define VSC9953_VCAP_UPDATE_CTRL 0x01000004
/* Macros for vsc9953_qsys_sys.switch_port_mode register */
#define VSC9953_PORT_ENA 0x00003a00
#define VSC9953_MAX_PORTS 10
#define VSC9953_PORT_CHECK(port) \
(((port) < 0 || (port) >= VSC9953_MAX_PORTS) ? 0 : 1)
@@ -74,7 +101,7 @@ struct vsc9953_mdio_info {
char *name;
};
/* VSC9953 ANA structure for T1040 U-boot*/
/* VSC9953 ANA structure */
struct vsc9953_ana_port {
u32 vlan_cfg;
@@ -176,9 +203,9 @@ struct vsc9953_analyzer {
u32 reserved5[196];
struct vsc9953_ana_common common;
};
/* END VSC9953 ANA structure for T1040 U-boot*/
/* END VSC9953 ANA structure t*/
/* VSC9953 DEV_GMII structure for T1040 U-boot*/
/* VSC9953 DEV_GMII structure */
struct vsc9953_dev_gmii_port_mode {
u32 clock_cfg;
@@ -205,9 +232,9 @@ struct vsc9953_dev_gmii {
struct vsc9953_dev_gmii_mac_cfg_status mac_cfg_status;
};
/* END VSC9953 DEV_GMII structure for T1040 U-boot*/
/* END VSC9953 DEV_GMII structure */
/* VSC9953 QSYS structure for T1040 U-boot*/
/* VSC9953 QSYS structure */
struct vsc9953_qsys_hsch {
u32 cir_cfg;
@@ -267,9 +294,9 @@ struct vsc9953_qsys_reg {
struct vsc9953_qsys_res_ctrl res_ctrl[1024];
};
/* END VSC9953 QSYS structure for T1040 U-boot*/
/* END VSC9953 QSYS structure */
/* VSC9953 SYS structure for T1040 U-boot*/
/* VSC9953 SYS structure */
struct vsc9953_sys_stat {
u32 rx_cntrs[64];
@@ -308,10 +335,10 @@ struct vsc9953_system_reg {
struct vsc9953_sys_mmgt mmgt;
};
/* END VSC9953 SYS structure for T1040 U-boot*/
/* END VSC9953 SYS structure */
/* VSC9953 DEVCPU_GCB structure for T1040 U-boot*/
/* VSC9953 DEVCPU_GCB structure */
struct vsc9953_chip_regs {
u32 chipd_id;
@@ -349,9 +376,9 @@ struct vsc9953_devcpu_gcb {
struct vsc9953_mii_read_scan mii_read_scan;
};
/* END VSC9953 DEVCPU_GCB structure for T1040 U-boot*/
/* END VSC9953 DEVCPU_GCB structure */
/* VSC9953 IS* structure for T1040 U-boot*/
/* VSC9953 IS* structure */
struct vsc9953_vcap_core_cfg {
u32 vcap_update_ctrl;
@@ -362,7 +389,7 @@ struct vsc9953_vcap {
struct vsc9953_vcap_core_cfg vcap_core_cfg;
};
/* END VSC9953 IS* structure for T1040 U-boot*/
/* END VSC9953 IS* structure */
#define VSC9953_PORT_INFO_INITIALIZER(idx) \
{ \
@@ -393,10 +420,10 @@ struct vsc9953_info {
void vsc9953_init(bd_t *bis);
void vsc9953_port_info_set_mdio(int port, struct mii_dev *bus);
void vsc9953_port_info_set_phy_address(int port, int address);
void vsc9953_port_enable(int port);
void vsc9953_port_disable(int port);
void vsc9953_port_info_set_phy_int(int port, phy_interface_t phy_int);
void vsc9953_port_info_set_mdio(int port_no, struct mii_dev *bus);
void vsc9953_port_info_set_phy_address(int port_no, int address);
void vsc9953_port_enable(int port_no);
void vsc9953_port_disable(int port_no);
void vsc9953_port_info_set_phy_int(int port_no, phy_interface_t phy_int);
#endif /* _VSC9953_H_ */