From owner-svn-src-head@freebsd.org Fri Feb 2 02:05:15 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 F3125EDCA59; Fri, 2 Feb 2018 02:05:14 +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 A2BE474091; Fri, 2 Feb 2018 02:05:14 +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 9989E156CF; Fri, 2 Feb 2018 02:05:14 +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 w1225EiM027170; Fri, 2 Feb 2018 02:05:14 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1225EWH027167; Fri, 2 Feb 2018 02:05:14 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201802020205.w1225EWH027167@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Fri, 2 Feb 2018 02:05:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328766 - head/sys/dev/etherswitch X-SVN-Group: head X-SVN-Commit-Author: adrian X-SVN-Commit-Paths: head/sys/dev/etherswitch X-SVN-Commit-Revision: 328766 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: Fri, 02 Feb 2018 02:05:15 -0000 Author: adrian Date: Fri Feb 2 02:05:14 2018 New Revision: 328766 URL: https://svnweb.freebsd.org/changeset/base/328766 Log: [etherswitch] add the first pass of a simple API to flush and fetch the L2 address table from the ethernet switch. This stuff may be a bit fluid during this -HEAD cycle as various other switch features are added, but the current stuff is enough to drive initial development and features on the atheros range of integrated and external switches. * add a method to flush the whole address table; * add a method to flush all addresses on a given port; * add a method to download the address table; * .. and then a method to fetch entries from the address table. The table fetch/read methods pass through to the drivers for now since the drivers may implement different ways of fetching/caching the address table data. The atheros devices for example fetch the table by iterating over the table through a set of registers and so you need to keep that locked whilst you iterate otherwise you may have the table flushed half way by a port status change. This is a no-op until the userland and arswitch code shows up. Modified: head/sys/dev/etherswitch/etherswitch.c head/sys/dev/etherswitch/etherswitch.h head/sys/dev/etherswitch/etherswitch_if.m Modified: head/sys/dev/etherswitch/etherswitch.c ============================================================================== --- head/sys/dev/etherswitch/etherswitch.c Fri Feb 2 01:28:14 2018 (r328765) +++ head/sys/dev/etherswitch/etherswitch.c Fri Feb 2 02:05:14 2018 (r328766) @@ -144,6 +144,7 @@ etherswitchioctl(struct cdev *cdev, u_long cmd, caddr_ etherswitch_info_t *info; etherswitch_reg_t *reg; etherswitch_phyreg_t *phyreg; + etherswitch_portid_t *portid; int error = 0; switch (cmd) { @@ -200,6 +201,23 @@ etherswitchioctl(struct cdev *cdev, u_long cmd, caddr_ case IOETHERSWITCHSETCONF: error = ETHERSWITCH_SETCONF(etherswitch, (etherswitch_conf_t *)data); + break; + + case IOETHERSWITCHFLUSHALL: + error = ETHERSWITCH_FLUSH_ALL(etherswitch); + break; + + case IOETHERSWITCHFLUSHPORT: + portid = (etherswitch_portid_t *)data; + error = ETHERSWITCH_FLUSH_PORT(etherswitch, portid->es_port); + break; + + case IOETHERSWITCHGETTABLE: + error = ETHERSWITCH_FETCH_TABLE(etherswitch, (void *) data); + break; + + case IOETHERSWITCHGETTABLEENTRY: + error = ETHERSWITCH_FETCH_TABLE_ENTRY(etherswitch, (void *) data); break; default: Modified: head/sys/dev/etherswitch/etherswitch.h ============================================================================== --- head/sys/dev/etherswitch/etherswitch.h Fri Feb 2 01:28:14 2018 (r328765) +++ head/sys/dev/etherswitch/etherswitch.h Fri Feb 2 02:05:14 2018 (r328766) @@ -6,6 +6,7 @@ #define __SYS_DEV_ETHERSWITCH_ETHERSWITCH_H #include +#include #ifdef _KERNEL extern devclass_t etherswitch_devclass; @@ -101,6 +102,28 @@ typedef struct etherswitch_vlangroup etherswitch_vlang #define ETHERSWITCH_PORTMASK(_port) (1 << (_port)) +struct etherswitch_portid { + int es_port; +}; +typedef struct etherswitch_portid etherswitch_portid_t; + +struct etherswitch_atu_entry { + int id; + int es_portmask; + uint8_t es_macaddr[ETHER_ADDR_LEN]; +}; +typedef struct etherswitch_atu_entry etherswitch_atu_entry_t; + +struct etherswitch_atu_table { + uint32_t es_nitems; +}; +typedef struct etherswitch_atu_table etherswitch_atu_table_t; + +struct etherswitch_atu_flush_macentry { + uint8_t es_macaddr[ETHER_ADDR_LEN]; +}; +typedef struct etherswitch_atu_flush_macentry etherswitch_atu_flush_macentry_t; + #define IOETHERSWITCHGETINFO _IOR('i', 1, etherswitch_info_t) #define IOETHERSWITCHGETREG _IOWR('i', 2, etherswitch_reg_t) #define IOETHERSWITCHSETREG _IOW('i', 3, etherswitch_reg_t) @@ -112,5 +135,10 @@ typedef struct etherswitch_vlangroup etherswitch_vlang #define IOETHERSWITCHSETPHYREG _IOW('i', 9, etherswitch_phyreg_t) #define IOETHERSWITCHGETCONF _IOR('i', 10, etherswitch_conf_t) #define IOETHERSWITCHSETCONF _IOW('i', 11, etherswitch_conf_t) +#define IOETHERSWITCHFLUSHALL _IOW('i', 12, etherswitch_portid_t) /* Dummy */ +#define IOETHERSWITCHFLUSHPORT _IOW('i', 13, etherswitch_portid_t) +#define IOETHERSWITCHFLUSHMAC _IOW('i', 14, etherswitch_atu_flush_macentry_t) +#define IOETHERSWITCHGETTABLE _IOWR('i', 15, etherswitch_atu_table_t) +#define IOETHERSWITCHGETTABLEENTRY _IOWR('i', 16, etherswitch_atu_entry_t) #endif Modified: head/sys/dev/etherswitch/etherswitch_if.m ============================================================================== --- head/sys/dev/etherswitch/etherswitch_if.m Fri Feb 2 01:28:14 2018 (r328765) +++ head/sys/dev/etherswitch/etherswitch_if.m Fri Feb 2 02:05:14 2018 (r328766) @@ -35,6 +35,45 @@ CODE { { return (0); } + + static int + null_etherswitch_flush_all(device_t dev) + { + + return (ENXIO); + } + + static int + null_etherswitch_flush_port(device_t dev, int port) + { + + return (ENXIO); + } + + static int + null_etherswitch_flush_mac(device_t dev, + etherswitch_atu_flush_macentry_t *e) + { + + return (ENXIO); + } + + static int + null_etherswitch_fetch_table(device_t dev, + etherswitch_atu_table_t *table) + { + + table->es_nitems = 0; + return (ENXIO); + } + + static int + null_etherswitch_fetch_entry(device_t dev, + etherswitch_atu_entry_t *e) + { + + return (ENXIO); + } }; # @@ -141,3 +180,42 @@ METHOD int setconf { device_t dev; etherswitch_conf_t *conf; } DEFAULT null_etherswitch_setconf; + +# +# Flush all of the programmed/learnt MAC addresses +# +METHOD int flush_all { + device_t dev; +} DEFAULT null_etherswitch_flush_all; + +# +# Flush a single MAC address entry +# +METHOD int flush_mac { + device_t dev; + etherswitch_atu_flush_macentry_t *entry; +} DEFAULT null_etherswitch_flush_mac; + +# +# Flush all of the dynamic MAC addresses on a given port +# +METHOD int flush_port { + device_t dev; + int port; +} DEFAULT null_etherswitch_flush_port; + +# +# Fetch the address table from the ethernet switch. +# +METHOD int fetch_table { + device_t dev; + etherswitch_atu_table_t *table; +} DEFAULT null_etherswitch_fetch_table; + +# +# Fetch a single entry from the ethernet switch table. +# +METHOD int fetch_table_entry { + device_t dev; + etherswitch_atu_entry_t *entry; +} DEFAULT null_etherswitch_fetch_entry;