On Sat, Sep 14, 2013 at 08:34:42PM +1000, Jonathan Matthew wrote:
> The network interfaces on the ubiquiti edgerouter lite don't work yet.
> Here's the first step towards fixing that:
>
> Mapping port numbers to phy addresses in the mii read/write functions
> hides the phy addresses unnecessarily. Instead, we should figure out
> the phy address when setting up the port and pass it to mii_attach.
>
> I don't have an octeon system that works with the existing code, so all
> I can say is this doesn't make any difference on the edgerouter lite.
> It uses different phy addresses, which I'll add a mapping for later.
>
> ok?
Reads good to me, and given the fact it doesn't break the cam-0100; Ok with me.
> Index: arch/octeon/dev/cn30xxgmx.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/octeon/dev/cn30xxgmx.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 cn30xxgmx.c
> --- arch/octeon/dev/cn30xxgmx.c 5 Dec 2012 23:20:14 -0000 1.5
> +++ arch/octeon/dev/cn30xxgmx.c 14 Sep 2013 09:35:40 -0000
> @@ -146,6 +146,11 @@ struct cn30xxgmx_port_ops *cn30xxgmx_por
> [GMX_SPI42_PORT] = &cn30xxgmx_port_ops_spi42
> };
>
> +/* this apparently works for the portwell cam-0100 */
> +int octeon_eth_phy_table[] = {
> + 0x02, 0x03, 0x22
> +};
> +
> #ifdef OCTEON_ETH_DEBUG
> static void *cn30xxgmx_intr_drop_ih;
> struct evcnt cn30xxgmx_intr_drop_evcnt =
> @@ -178,6 +183,14 @@ cn30xxgmx_match(struct device *parent, v
> return 1;
> }
>
> +static int
> +cn30xxgmx_port_phy_addr(int port)
> +{
> + if (port >= nitems(octeon_eth_phy_table))
> + return -1;
> + return octeon_eth_phy_table[port];
> +}
> +
> static void
> cn30xxgmx_attach(struct device *parent, struct device *self, void *aux)
> {
> @@ -223,6 +236,9 @@ cn30xxgmx_attach(struct device *parent,
> gmx_aa.ga_port_type = sc->sc_port_types[i];
> gmx_aa.ga_gmx = sc;
> gmx_aa.ga_gmx_port = port_sc;
> + gmx_aa.ga_phy_addr = cn30xxgmx_port_phy_addr(i);
> + if (gmx_aa.ga_phy_addr == -1)
> + panic(": don't know phy address for port %d", i);
>
> config_found_sm(self, &gmx_aa,
> cn30xxgmx_print, cn30xxgmx_submatch);
> Index: arch/octeon/dev/cn30xxgmxvar.h
> ===================================================================
> RCS file: /cvs/src/sys/arch/octeon/dev/cn30xxgmxvar.h,v
> retrieving revision 1.1
> diff -u -p -r1.1 cn30xxgmxvar.h
> --- arch/octeon/dev/cn30xxgmxvar.h 16 Jun 2011 11:22:30 -0000 1.1
> +++ arch/octeon/dev/cn30xxgmxvar.h 14 Sep 2013 09:35:40 -0000
> @@ -136,6 +136,7 @@ struct cn30xxgmx_attach_args {
> const char *ga_name;
> int ga_portno;
> int ga_port_type;
> + int ga_phy_addr;
>
> struct cn30xxgmx_softc *ga_gmx;
> struct cn30xxgmx_port_softc
> Index: arch/octeon/dev/if_cnmac.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/octeon/dev/if_cnmac.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 if_cnmac.c
> --- arch/octeon/dev/if_cnmac.c 17 Aug 2013 10:00:09 -0000 1.11
> +++ arch/octeon/dev/if_cnmac.c 14 Sep 2013 09:35:40 -0000
> @@ -259,15 +259,6 @@ static const struct octeon_evcnt_entry o
> };
> #endif
>
> -/* XXX board-specific */
> -static const int octeon_eth_phy_table[] = {
> -#if defined __seil5__
> - 0x04, 0x01, 0x02
> -#else
> - 0x02, 0x03, 0x22
> -#endif
> -};
> -
> /* ---- buffer management */
>
> static const struct octeon_eth_pool_param {
> @@ -338,6 +329,7 @@ octeon_eth_attach(struct device *parent,
> sc->sc_port_type = ga->ga_port_type;
> sc->sc_gmx = ga->ga_gmx;
> sc->sc_gmx_port = ga->ga_gmx_port;
> + sc->sc_phy_addr = ga->ga_phy_addr;
>
> sc->sc_init_flag = 0;
>
> @@ -549,30 +541,14 @@ static int
> octeon_eth_mii_readreg(struct device *self, int phy_no, int reg)
> {
> struct octeon_eth_softc *sc = (struct octeon_eth_softc *)self;
> - int phy_addr = octeon_eth_phy_table[phy_no];
> -
> - if (sc->sc_port >= (int)nitems(octeon_eth_phy_table) ||
> - phy_no != sc->sc_port) {
> - log(LOG_ERR,
> - "mii read address mismatch, phy number %d.\n", phy_no);
> - return -1;
> - }
> - return cn30xxsmi_read(sc->sc_smi, phy_addr, reg);
> + return cn30xxsmi_read(sc->sc_smi, phy_no, reg);
> }
>
> static void
> octeon_eth_mii_writereg(struct device *self, int phy_no, int reg, int value)
> {
> struct octeon_eth_softc *sc = (struct octeon_eth_softc *)self;
> - int phy_addr = octeon_eth_phy_table[phy_no];
> -
> - if (sc->sc_port >= (int)nitems(octeon_eth_phy_table) ||
> - phy_no != sc->sc_port) {
> - log(LOG_ERR,
> - "mii write address mismatch, phy number %d.\n", phy_no);
> - return;
> - }
> - cn30xxsmi_write(sc->sc_smi, phy_addr, reg, value);
> + cn30xxsmi_write(sc->sc_smi, phy_no, reg, value);
> }
>
> static void
> @@ -606,7 +582,7 @@ octeon_eth_mediainit(struct octeon_eth_s
> octeon_eth_mediastatus);
>
> mii_attach(&sc->sc_dev, &sc->sc_mii,
> - 0xffffffff, sc->sc_port, MII_OFFSET_ANY, MIIF_DOPAUSE);
> + 0xffffffff, sc->sc_phy_addr, MII_OFFSET_ANY, MIIF_DOPAUSE);
>
> /* XXX */
> if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL) {
> Index: arch/octeon/dev/if_cnmacvar.h
> ===================================================================
> RCS file: /cvs/src/sys/arch/octeon/dev/if_cnmacvar.h,v
> retrieving revision 1.2
> diff -u -p -r1.2 if_cnmacvar.h
> --- arch/octeon/dev/if_cnmacvar.h 17 Jun 2011 03:36:25 -0000 1.2
> +++ arch/octeon/dev/if_cnmacvar.h 14 Sep 2013 09:35:40 -0000
> @@ -90,6 +90,7 @@ struct octeon_eth_softc {
> uint32_t sc_port;
> uint32_t sc_port_type;
> uint32_t sc_init_flag;
> + int sc_phy_addr;
>
> /*
> * Redirection - received (input) packets are redirected (directly sent)
--
Cheers,
Jasper
"Stay Hungry. Stay Foolish"