Commit Graph

103 Commits

Author SHA1 Message Date
Kristof Provost
6d011946c5 arswitch: Ensure the lock is always held when calling arswitch_modifyreg()
arswitch_setled() and a number of _global_setup functions did not acquire the
lock before calling arswitch_modifyreg(). With WITNESS enabled this would
instantly panic.

Discovered on a TPLink-3600:
("panic: mutex arswitch not owned at sys/dev/etherswitch/arswitch/arswitch_reg.c:236")

Reviewed by:	adrian, kan
Differential Revision:	https://reviews.freebsd.org/D9187
2017-01-15 10:21:25 +00:00
Michael Zhilin
d3bafe1d16 [etherswitch] Support Micrel KSZ8995MA switch chip
This is Micrel KSZ8995MA driver code. KSZ8995MA uses SPI bus to control.
This code is written & tested on @SRCHACK's ksz8995ma board and FON2100
with gpiospi.
etherswitchcfg support commands: addtag, ingress, striptag, dropuntagged.

Submitted by:	Hiroki Mori <yamori813@yahoo.co.jp>
Reviewed by:	mizhka, adrian
Approved by:	adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D8790
2017-01-14 23:24:50 +00:00
Luiz Otavio O Souza
bca353cacb Convert etherswitch to use the make_dev_s(9) KPI. This fix a possible race
where si_drv1 can be accessed before it gets set.

MFC after:	3 days
Suggested by:	kib
Sponsored by:	Rubicon Communications, LLC (Netgate)
2017-01-08 20:37:41 +00:00
Zbigniew Bodek
f7c13d78db Improve ports handling in e6000sw driver
- recognize ports and vlangroups based on DTS file
- support multi-chip addresing mode (required in upcoming
  Armada-388-Clearfog support)
- refactor attachment function

Each port in 'dsa' node should have 'vlangroup' property. Otherwise,
e6000sw will fail to attach.

Submitted by:	Bartosz Szczepanek <bsz@semihalf.com>
		Konrad Adamczyk <ka@semihalf.com>
Obtained from:	Semihalf
Sponsored by:	Stormshield
Differential revision: https://reviews.freebsd.org/D7328
2017-01-05 17:08:10 +00:00
Luiz Otavio O Souza
3c27ea76f0 Allow simultaneous access to switch device, there is no reason to prevent
it.

Remove bogus wrappers and use the kernel defaults.

While here, use DEVMETHOD_END.

Obtained from:	pfSense
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC (Netgate)
2016-12-03 01:55:38 +00:00
Michael Zhilin
b15317c431 [etherswitch] add ukswitch hint that is phy offset at mdio register
This patch allows to specify PHY register offset for ukswitch. For instance,
switch MAICREL KS8995XA connected via MDIO to SoC, but PHY register starts
at 1. So hint for this case is: hint.ukswitch.0.phyoffset=1

No change/effect if hint is not set.

Submitted by:	Hiroki Mori <yamori813@yahoo.co.jp>
Reviewed by:	adrian, mizhka
Approved by:	adrian(mentor)
Differential Revision:	https://reviews.freebsd.org/D8584
2016-11-21 19:26:22 +00:00
Michael Zhilin
c702a80e27 [etherswitch] add infineon adm6996fc support on etherswitch
This is Infineon ADM6996FC/M/MX driver code on etherswitch framework.
Support PORT and DOT1Q VLAN.
This code suppose ADM6996FC SDC/SDIO connect to SOC network interface
MDC/MDIO.
This code tested on Netgear WGR614Cv7.

Submitted by:	Hiroki Mori <yamori813@yahoo.co.jp>
Reviewed by:	adrian, mizhka
Approved by:	adrian(mentor)
Differential Revision:	https://reviews.freebsd.org/D8495
2016-11-17 07:33:37 +00:00
Michael Zhilin
2567d71370 [etherswitch] enable phy4/mac4 of ip175c
If MII1 interface is disabled, then enable phy4/mac4.

Submitted by:	Hiroki Mori <yamori813@yahoo.co.jp>
Reviewed by:	mizhka, adrian
Approved by:	adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D6832
2016-11-15 22:30:25 +00:00
Michael Zhilin
477e3eff7e [etherswitch] add RTL8366SR support
Add RTL8366SR support at etherswitch driver. Tested on RTL8366RB and
RTL8366SR.

Submitted by:	Hiroki Mori <yamori813@yahoo.co.jp>
Reviewed by:	adrian, mizhka
Approved by:	adrian(mentor)
Differential Revision:	https://reviews.freebsd.org/D6796
2016-11-15 21:58:04 +00:00
Michael Zhilin
4677ca5bf1 [etherswitch] add Marvell 88e6060 switch support
Add 88e6060 basic support: only port-based VLAN is supported.
No vlan(4) support.

Submitted by:	Hiroki Mori <yamori813@yahoo.co.jp>
Reviewed by:	mizhka, adrian
Approved by:	adrian(mentor)
Differential Revision:	https://reviews.freebsd.org/D8344
2016-11-15 21:49:01 +00:00
Pedro F. Giffuni
f0be707d74 sys/dev: replace comma with semicolon when pertinent.
Uses of commas instead of a semicolons can easily go undetected. The comma
can serve as a statement separator but this shouldn't be abused when
statements are meant to be standalone.

Detected with devel/coccinelle following a hint from DragonFlyBSD.

MFC after:	1 month
2016-08-09 19:41:46 +00:00
Sepherosa Ziehau
e6aeff0c0a etherswitch: Unbreak LINT build
Sponsored by:	Microsoft
2016-08-08 05:57:04 +00:00
Adrian Chadd
1b334c8bc1 [arswitch] extend the debug support to be configurable at runtime.
* remove the DEBUG ifdef; defining it is too far reaching throughout
  the whole system;
* add a bitmask in the softc for controlling debugging;
* .. enable said debugging as a sysctl;
* add bitmaps for register access, reset and vlans.

TODO:

* Now that the debug statements are configurable, we definitely could
  do with more debugging
* Move the debugging into the top-level etherswitch driver and have
  sub-drivers obey.
2016-08-07 01:32:37 +00:00
Adrian Chadd
c94dc8089f [etherswitch] add in an initial API for controlling per-port LED behaviour.
This is just implemented for the AR8327 for now.

Submitted by:	Dan Nelson <dnelson_1901@yahoo.com>
2016-08-04 17:45:35 +00:00
Adrian Chadd
a68401914f Update my TODO items. 2016-07-26 16:40:03 +00:00
Stanislav Galabov
86845464f0 Remove erroneous lock assertions
In mediatek etherswitch support, functions mtkswitch_reg_write32_mt7621
and mtkswitch_reg_read32_mt7621 are called without locks held, so
lock assertions fail. Remove the lock assertions.

Sponsored by:	Smartcom - Bulgaria AD
2016-06-06 10:07:57 +00:00
Stanislav Galabov
1027d6d672 Fix issues with mt762x etherswitch driver
Fix issues that crept in with initial import.

Approved by:	adrian (mentor)
Sponsored by:	Smartcom - Bulgaria AD
Differential Revision:	https://reviews.freebsd.org/D6393
2016-05-17 06:30:46 +00:00
Stanislav Galabov
dfb5178f9b Introduce basic etherswitch support for Ralink SoCs
This revision introduces basic support for the internal ESW switch found
Ralink/Mediatek SoCs such as RT3050, RT3352, RT5350, MT7628; and GSW
found in MT7620 and MT7621.

It only supports 802.1q VLANs and doesn't support external PHYs at the
moment (only the ones that are built into the switch itself).

Approved by:	adrian (mentor)
Sponsored by:	Smartcom - Bulgaria AD
Differential Revision:	https://reviews.freebsd.org/D6348
2016-05-16 07:00:49 +00:00
Pedro F. Giffuni
453130d9bf sys/dev: minor spelling fixes.
Most affect comments, very few have user-visible effects.
2016-05-03 03:41:25 +00:00
Pedro F. Giffuni
74b8d63dcc Cleanup unnecessary semicolons from the kernel.
Found with devel/coccinelle.
2016-04-10 23:07:00 +00:00
Adrian Chadd
71e8eac4fd [mdio] migrate mdiobus out of etherswitch and into a top-level device of its own.
The mdio driver interface is generally useful for devices that require
MDIO without the full MII bus interface. This lifts the driver/interface
out of etherswitch(4), and adds a mdio(4) man page.

Submitted by:	Landon Fuller <landon@landonf.org>
Differential Revision:	https://reviews.freebsd.org/D4606
2015-12-26 02:31:39 +00:00
Adrian Chadd
fd81a3291a [arswitch] bump the number of ports on the ar934x internal switch.
It indeed has more ports by default.
2015-12-15 04:46:48 +00:00
Zbigniew Bodek
5420071d39 Introduce e6000sw etherswitch support
Add e6000sw driver supporting Marvell 88E6352, 88E6172, 88E6176 switches.
It needs to be attached to mdio interface, exporting SMI access
functionality. e6000sw supports port-based VLAN configuration, per-port
media changing, accessing PHY and switch registers.

e6000sw attaches miibuses and PHY drivers as children. Instead of typical
tick as callout, kthread-based tick is used. This combined with SX locks
allows MDIO read/write calls to sleep. It is expected, because this
hardware requires long delays in SMI read/write procedures, which can not
be handled by busy-waiting.

Reviewed by:    adrian
Obtained from:  Semihalf
Submitted by:   Bartosz Szczepanek <bsz@semihalf.com>
Differential revision: https://reviews.freebsd.org/D3902
2015-10-25 22:14:04 +00:00
Adrian Chadd
8f1cf028d3 AR8327: Fix up the ability to configure the vlangroup configuration for the CPU port
I messed up when doing the reset_vlans method - setting vid[0] = 1 here
was making it 'hidden' from configuration (as it needed ETHERSWITCH_VID_VALID
as well) and so there was no way to configure vlangroup0.

In per-port VLAN mode, vlangroup0 is for the CPU port (port0).
Now, it normally wouldn't really matter - the CPU port thus sees
all other ports. However there are two CPU ports on the AR8327 and
so port0 (arge0) was seeing all traffic on port6 (arge1).
If you thus tried to use arge1/port6 for anything (eg a WAN port)
in a bridge group then things would very upset very quickly.

Whilst here, add a comment to remind myself that yes, it'd be nice
if we could specify a boot-time switch config.

Tested:

* AP135 reference platform w/ AR8327N switch
2015-10-20 21:18:02 +00:00
Rui Paulo
52f243678d Fix French typos in etherswitch. 2015-04-18 07:34:39 +00:00
Adrian Chadd
012bc22a86 Turns out the AR933x looks like the AR7240/AR7241 switch as far as VLAN
configuration is concerned.

So, remove the now-erroneous comment.

Tested:

* AR9331 - Carambola2, with transmitting dot1q tagged packets around.
2015-03-28 23:20:46 +00:00
Adrian Chadd
036e1c7646 Commit 802.1q configuration support for the AR8327.
This is slightly different to the other switches - the VLAN table
(VTU) programs in the vlan port mapping /and/ the port config
(tagged, untagged, passthrough, any.)

So:

* Add VTU operations to program the VTU (vlan table)
* abstract out the mirror-disable function so it's .. well, a function.
* setup the port to have a dot1q configuration for dot1q - the
  port security is VLAN (not per-port VLAN) and requires an entry
  in the VLAN table;
* add set_dot1q / get_dot1q to program the VLAN table;
* since the tagged/untagged ports are now programmed into the VTU,
  rather than global - plumb the ports /and/ untagged ports bitmaps
  through the arswitch API.

Tested:

* AP135 - QCA9558 SoC + AR8327N switch
2015-03-13 02:16:39 +00:00
Adrian Chadd
f35f94f4fd Methodise a couple more of the VLAN methods. 2015-03-08 23:02:15 +00:00
Adrian Chadd
749cac133f Add per-port vlan support for the AR8327.
All the per-port support is really doing is applying a port visibility
mask to each of the switchports.  Everything still look like a single
portgroup (vlan id 1), but the per-port visibility mask is modified.

Whilst I'm here, also add some initial dot1q support - the pvid stuff
is doing the right thing, but it's not useful without the rest of
the VLAN table programming.

It's enough for me to be able to use the LAN/WAN port distinction
on the AP135, where there isn't (for now!) a dedicated PHY for the
"WAN" port.

Tested:

* AP135, QCA9558 SoC + AR8327 switch
2015-03-08 21:59:03 +00:00
Adrian Chadd
78549b94cd Fix up support for the AR8327.
* Even though I got the registers around "right", it seems
  I'm not tickling the MDIO access correctly for the internal PHY
  bus.  Some of the switches are fine poking at the external PHY
  registers; others aren't.  So, enable direct PHY bus access
  for the AR8327, and leave the existing code in place for the
  others.

* Go and shuffle the register access around.  Whilst here,
  restore the 2ms delay if changing page.

* Comment out some of the stub printf()s; there's some upcoming
  work to add port VLAN support.

Tested:

* AP135 development board
* Carambola2 - AR9331 SoC
2015-03-08 03:53:36 +00:00
Adrian Chadd
db37238f70 AR8327: Disable energy-efficient ethernet support in the PHYs.
I noticed that openwrt/linux does this, citing "instability", so
until they figure out why I'm going to disable it here as well.

Tested:

* QCA AP135 - QCA955x SoC + AR8327 switch.
2015-03-01 20:32:35 +00:00
Adrian Chadd
7190a55c3e Bump the port mask on the AR8327 ethernet switch from 0x3f to 0x7f.
So, it turns out that the AR8327 has 7 ports internally:

* GMAC0 / external (CPU) MAC0
* GMAC1 / port1 -> GMAC5 / port5: external switch port PHYs
* GMAC6 / external (CPU) MAC1

Now, depending upon how things are wired up, the second CPU port (MAC1)
can be wired to either the switch (port6), or through port5's PHY, bypassing
the GMAC+switch entirely.  Ie, it can pretend to be a boring PHY, saving
system designers from having to include a separate PHY for a "WAN" port.

Here's the rub - the AP135 board (QCA955x SoC) hooks up arge0 to
the second CPU port on the AR8327, but it's hooked up as RGMII.
So, in order to hook it up to the rest of the switch, it isn't configured
as a separate PHY - OpenWRT has it setup as connected via RGMII to
GMAC6 and (I'm guessing) it's set to be a WAN port by configuring up
port-based VLANs or something.

Thus, with a port mask of 0x3f, GMAC6 was never allowed to receive traffic
from any other port.  It could transmit fine, but not receive anything.

So, now it works enough for me to continue doing board bootstrapping.
Note, this isn't enough to make the QCA955x + AR8327 work - there's
a bunch of uncommitted work to both the platform SoC (interrupt handling,
ethernet, etc) and the ethernet switch (register access space, setup, etc)
that needs to happen.  However, this particular change is also relevant to
other SoCs, like the AR934x and AR7161, both of which can be glued to
this switch.

Tested:

* AP135 development board

TODO:

* Figure out whether I can somehow abuse another port mode to have this
  be a pass-through PHY, or whether I should just create some more boot
  time hints to explicitly set up port-based isolation so this works
  in a more useful way by default.
2015-03-01 20:22:28 +00:00
Adrian Chadd
0f3ec57676 Add another register definition for the AR8327.
Obtained from:	OpenWRT
2015-02-28 23:59:29 +00:00
Adrian Chadd
9682e34719 Add another revision of the AR8327. 2014-07-26 21:33:17 +00:00
Rui Paulo
efce3748f3 Revert r268543.
We should probably fix sys/gpio.h instead.
2014-07-12 06:23:42 +00:00
Rui Paulo
bd08cbb81a Move iic.h to sys/ so that it's automatically installed in /usr/include/sys.
This lets us call iic(4) ioctls without needing the kernel source code
and follows the same model of GPIO.

MFC after:	3 weeks
2014-07-12 01:04:10 +00:00
Luiz Otavio O Souza
28b07d23a9 Allow the PVID setting on CPU port.
Return our static list of supported media for the CPU port.

Tested on TP-Link 1043ND.
2014-07-05 19:31:22 +00:00
Luiz Otavio O Souza
bfae93299c Initialize the switch vlan table at attachment.
Update some comments on code, specifying the correct vlans used on switch
setup.

Advertise the proper switch operation mode (the rtl8366rb only support
dot1q vlans).

This fixes the breakage that i introduced on r249752 and make the rtl8366rb
switch works again with etherswitchcfg(8).

Tested on TP-Link 1043ND.

Tested by:	me, Harm Weites (harm at weites.com)
2014-07-03 19:50:50 +00:00
Luiz Otavio O Souza
b0bb5bfaec Fix the reported status for the switch CPU port which was (wrongly)
reporting half-duplex link.

Tested on TP-Link WR1043ND.
2014-07-01 14:49:46 +00:00
Luiz Otavio O Souza
dddab08921 Add the CPU port flag to the CPU port on rtl8366 (port 5).
Do not allow any media change on the switch CPU port.

Tested on TP-Link WR1043ND.
2014-07-01 14:33:48 +00:00
Luiz Otavio O Souza
8237ba8ab3 Fix the build with debug enabled and remove a variable used only at switch
initialization, it is nonsense keep it around without futher use.
2014-05-09 13:21:34 +00:00
Luiz Otavio O Souza
6a7a25af3f Fix a bug on ip17x switch initialization which will fail as soon as you
disable the debug and diagnosis options from current.  We must wait 2ms
after the switch reset and not 2us.

Tested on RB433UAH.
2014-05-09 13:07:39 +00:00
Adrian Chadd
0d2041a08b Add a description here. 2014-03-02 07:39:37 +00:00
Adrian Chadd
dd846bddbf Set all of the ports into the same vlangroup; there's only one vlangroup
(pvid=1) and we already configure them to send to other ports.

Setting pvid=portnum would mean that there were separate vlangroups
for each ports, but 'leaking' into other ports.  The result? All port
traffic flooded to all other port traffic.

Tested:

* DB120, AR9344 + AR8327 switch
2014-03-02 07:10:43 +00:00
Adrian Chadd
4ff2f60db6 Add ATU flush support.
The OpenWRT AR8xxx switch support flushes the ATU (address translation
unit) after each port link 'up' status change.  I've modified this to
just flush on any port transition.

Whilst here, bump the number of ports on the AR8327 to 6, rather than
the default of 5.  It's DB120 specific; I'll go and make this configurable
later.

There's some debugging code in here still; I am still debugging whether
this is or isn't working fully.

Tested:

* DB120, AR9344 + AR8327 switch

Obtained from:	OpenWRT
2014-03-02 05:48:56 +00:00
Adrian Chadd
93f5e67e02 Add AR8216 era ATU management/configuration register definitions.
Obtained from:	OpenWRT
2014-03-02 05:47:05 +00:00
Adrian Chadd
03b5d8277b (I think!) make the AR8327 switch correctly handle traffic.
This patch does four things:

* it globally disables mirroring;
* it globally sets the mirroring on each port to be disabled;
* the initial port setup now programs a portmask for the port to allow
  transmission (forwarding) to all other ports bar itself;
* the vlan setup path now programs the portmask for the port to
  allow transmission (forwarding) to all other ports bar itself.

Before this, I hard-coded the portmask to 0x3f which would mean all
ports (bar port 6, which currently isn't hooked up to anything.)
This means that traffic would be duplicated back out the port it
received it.  I bet this wasn't .. optimal.

In any case, this _seems_ to make DHCP from my macosx laptop
work through this access point.  I'll do some further testing
to ensure it's actually working correctly on all my devices.

Tested:

* DB120, AR8327 switch
2014-03-01 10:04:31 +00:00
Adrian Chadd
ddea319180 Be paranoid about bit operations here. 2014-03-01 00:11:45 +00:00
Adrian Chadd
093c756e0e Remove now dead code. 2014-03-01 00:02:09 +00:00
Christian Brueffer
4170452de3 Add missing includes and remove two unused ones.
Reviewed by:	loos
MFC after:	1 week
2014-02-27 21:01:10 +00:00