From owner-svn-src-head@freebsd.org Tue Feb 6 08:35:50 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1A83DEE355C; Tue, 6 Feb 2018 08:35:50 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C1B3D7D7B6; Tue, 6 Feb 2018 08:35:49 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BCBE31576B; Tue, 6 Feb 2018 08:35:49 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w168Zndw025775; Tue, 6 Feb 2018 08:35:49 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w168ZnBa025771; Tue, 6 Feb 2018 08:35:49 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201802060835.w168ZnBa025771@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Tue, 6 Feb 2018 08:35:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328924 - head/sys/dev/etherswitch/arswitch X-SVN-Group: head X-SVN-Commit-Author: adrian X-SVN-Commit-Paths: head/sys/dev/etherswitch/arswitch X-SVN-Commit-Revision: 328924 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Feb 2018 08:35:50 -0000 Author: adrian Date: Tue Feb 6 08:35:49 2018 New Revision: 328924 URL: https://svnweb.freebsd.org/changeset/base/328924 Log: [arswitch] Implement the switch MAC address fetch API. The placeholders are here for some future "set" MAC address API. Tested: * AR9340 switch * AR8327 switch Modified: head/sys/dev/etherswitch/arswitch/arswitch.c head/sys/dev/etherswitch/arswitch/arswitchreg.h head/sys/dev/etherswitch/arswitch/arswitchvar.h Modified: head/sys/dev/etherswitch/arswitch/arswitch.c ============================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch.c Tue Feb 6 08:35:09 2018 (r328923) +++ head/sys/dev/etherswitch/arswitch/arswitch.c Tue Feb 6 08:35:49 2018 (r328924) @@ -484,6 +484,41 @@ ar8xxx_atu_learn_default(struct arswitch_softc *sc) */ /* + * Fetch the configured switch MAC address. + */ +static int +ar8xxx_hw_get_switch_macaddr(struct arswitch_softc *sc, struct ether_addr *ea) +{ + uint32_t ret0, ret1; + char *s; + + s = (void *) ea; + + ret0 = arswitch_readreg(sc->sc_dev, AR8X16_REG_SW_MAC_ADDR0); + ret1 = arswitch_readreg(sc->sc_dev, AR8X16_REG_SW_MAC_ADDR1); + + s[5] = MS(ret0, AR8X16_REG_SW_MAC_ADDR0_BYTE5); + s[4] = MS(ret0, AR8X16_REG_SW_MAC_ADDR0_BYTE4); + s[3] = MS(ret1, AR8X16_REG_SW_MAC_ADDR1_BYTE3); + s[2] = MS(ret1, AR8X16_REG_SW_MAC_ADDR1_BYTE2); + s[1] = MS(ret1, AR8X16_REG_SW_MAC_ADDR1_BYTE1); + s[0] = MS(ret1, AR8X16_REG_SW_MAC_ADDR1_BYTE0); + + return (0); +} + +/* + * Set the switch mac address. + */ +static int +ar8xxx_hw_set_switch_macaddr(struct arswitch_softc *sc, + const struct ether_addr *ea) +{ + + return (ENXIO); +} + +/* * XXX TODO: this attach routine does NOT free all memory, resources * upon failure! */ @@ -527,6 +562,8 @@ arswitch_attach(device_t dev) sc->hal.arswitch_port_vlan_setup = ar8xxx_port_vlan_setup; sc->hal.arswitch_port_vlan_get = ar8xxx_port_vlan_get; sc->hal.arswitch_vlan_init_hw = ar8xxx_reset_vlans; + sc->hal.arswitch_hw_get_switch_macaddr = ar8xxx_hw_get_switch_macaddr; + sc->hal.arswitch_hw_set_switch_macaddr = ar8xxx_hw_set_switch_macaddr; sc->hal.arswitch_vlan_getvgroup = ar8xxx_getvgroup; sc->hal.arswitch_vlan_setvgroup = ar8xxx_setvgroup; @@ -1115,6 +1152,7 @@ static int arswitch_getconf(device_t dev, etherswitch_conf_t *conf) { struct arswitch_softc *sc; + int ret; sc = device_get_softc(dev); @@ -1122,6 +1160,13 @@ arswitch_getconf(device_t dev, etherswitch_conf_t *con conf->cmd = ETHERSWITCH_CONF_VLAN_MODE; conf->vlan_mode = sc->vlan_mode; + /* Return the switch ethernet address. */ + ret = sc->hal.arswitch_hw_get_switch_macaddr(sc, + &conf->switch_macaddr); + if (ret == 0) { + conf->cmd |= ETHERSWITCH_CONF_SWITCH_MACADDR; + } + return (0); } @@ -1139,6 +1184,8 @@ arswitch_setconf(device_t dev, etherswitch_conf_t *con if (err != 0) return (err); } + + /* TODO: Set the switch ethernet address. */ return (0); } Modified: head/sys/dev/etherswitch/arswitch/arswitchreg.h ============================================================================== --- head/sys/dev/etherswitch/arswitch/arswitchreg.h Tue Feb 6 08:35:09 2018 (r328923) +++ head/sys/dev/etherswitch/arswitch/arswitchreg.h Tue Feb 6 08:35:49 2018 (r328924) @@ -88,7 +88,20 @@ #define AR8X16_REG_IMR 0x0014 #define AR8X16_REG_SW_MAC_ADDR0 0x0020 +#define AR8X16_REG_SW_MAC_ADDR0_BYTE4 BITS(8, 8) +#define AR8X16_REG_SW_MAC_ADDR0_BYTE4_S 8 +#define AR8X16_REG_SW_MAC_ADDR0_BYTE5 BITS(0, 8) +#define AR8X16_REG_SW_MAC_ADDR0_BYTE5_S 0 + #define AR8X16_REG_SW_MAC_ADDR1 0x0024 +#define AR8X16_REG_SW_MAC_ADDR1_BYTE0 BITS(24, 8) +#define AR8X16_REG_SW_MAC_ADDR1_BYTE0_S 24 +#define AR8X16_REG_SW_MAC_ADDR1_BYTE1 BITS(16, 8) +#define AR8X16_REG_SW_MAC_ADDR1_BYTE1_S 16 +#define AR8X16_REG_SW_MAC_ADDR1_BYTE2 BITS(8, 8) +#define AR8X16_REG_SW_MAC_ADDR1_BYTE2_S 8 +#define AR8X16_REG_SW_MAC_ADDR1_BYTE3 BITS(0, 8) +#define AR8X16_REG_SW_MAC_ADDR1_BYTE3_S 0 #define AR8X16_REG_FLOOD_MASK 0x002c #define AR8X16_FLOOD_MASK_BCAST_TO_CPU (1 << 26) Modified: head/sys/dev/etherswitch/arswitch/arswitchvar.h ============================================================================== --- head/sys/dev/etherswitch/arswitch/arswitchvar.h Tue Feb 6 08:35:09 2018 (r328923) +++ head/sys/dev/etherswitch/arswitch/arswitchvar.h Tue Feb 6 08:35:49 2018 (r328924) @@ -99,6 +99,11 @@ struct arswitch_softc { int (* arswitch_hw_setup) (struct arswitch_softc *); int (* arswitch_hw_global_setup) (struct arswitch_softc *); + int (* arswitch_hw_get_switch_macaddr) (struct arswitch_softc *, + struct ether_addr *sa); + int (* arswitch_hw_set_switch_macaddr) (struct arswitch_softc *, + const struct ether_addr *sa); + /* Port functions */ void (* arswitch_port_init) (struct arswitch_softc *, int);