aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/mii/mii_physubr.c
Commit message (Collapse)AuthorAgeFilesLines
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* mii_physubr: Add support for limiting PHY max speedKornel Duleba2021-11-241-0/+36
| | | | | | | | | | | | | | | In some cases we might want to limit the max speed advertised below of what the PHY is capable of. This is usually the case when we connect 1G capable PHY to 100M MAC, or when some exotic physical connection is used. Add a new mii_maxspeed field to mii_softc and parse it in mii_phy_dev_attach. Speed limit is normally located in DT. The property is already parsed in mii_fdt.c, but its value still has to be passed by the PHY driver. Obtained from: Semihalf Sponsored by: Alstom Group Differential revision: https://reviews.freebsd.org/D32727
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* Cleanup unnecessary semicolons from the kernel.Pedro F. Giffuni2016-04-101-1/+1
| | | | | | | Found with devel/coccinelle. Notes: svn path=/head/; revision=297793
* Instead of storing mii_media_table array index in ifm_data, determineGleb Smirnoff2015-04-211-46/+114
| | | | | | | | | it in mii_phy_setmedia() functionally. Sponsored by: Nginx, Inc. Notes: svn path=/head/; revision=281821
* Clean some dead code.Gleb Smirnoff2015-01-141-7/+0
| | | | Notes: svn path=/head/; revision=277176
* The MII layer shouldn't care about administrative status of anGleb Smirnoff2013-10-261-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | interface. Make MII drivers forget about 'struct ifnet'. Later plan is to provide an administrative downcall from ifnet layer into drivers, to inform them about administrative status change. If someone thinks that processing MII events for an administratively down interface is a big problem, then drivers would turn MII processing off. The following MII drivers do evil things, like strcmp() on driver name, so they still need knowledge of ifnet and thus include if_var.h. They all need to be fixed: sys/dev/mii/brgphy.c sys/dev/mii/e1000phy.c sys/dev/mii/ip1000phy.c sys/dev/mii/jmphy.c sys/dev/mii/nsphy.c sys/dev/mii/rgephy.c sys/dev/mii/truephy.c Sponsored by: Netflix Sponsored by: Nginx, Inc. Notes: svn path=/head/; revision=257184
* r221812 reveals that at least some Broadcom PHYs default to being not onlyMarius Strobl2011-08-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | isolated but also powered down after a reset and while they just work fine [sic] when both is the case they don't if they are only deisolate but still powered down. So in order to put PHYs in an overall normal operation mode for the common case, ensure in mii_phy_reset() that they are not powered down after a reset. Unfortunately, this only helps in case of BCM5421, while BCM5709S apparently only work when they remain isolated and powered down after a reset. So don't call mii_phy_reset() in brgphy_reset() and implement the reset locally leaving the problematic bits alone. Effectively this bypasses r221812 for brgphy(4). Thanks to Justin Hibbits for doing a binary search in order to identify the problematic commit. PR: 157405, 158156 Reviewed by: yongari (mii_phy_reset() part) Approved by: re (kib) MFC after: 3 days Notes: svn path=/head/; revision=225014
* Some PHYs like the Level One LXT970 optionally can default to isolationMarius Strobl2011-05-121-6/+9
| | | | | | | | | | after rest, in which case we may need to deisolate it. Tested by: nwhitehorn MFC after 1 week Notes: svn path=/head/; revision=221812
* - Remove attempts to implement setting of BMCR_LOOP/MIIF_NOLOOPMarius Strobl2011-05-031-5/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (reporting IFM_LOOP based on BMCR_LOOP is left in place though as it might provide useful for debugging). For most mii(4) drivers it was unclear whether the PHYs driven by them actually support loopback or not. Moreover, typically loopback mode also needs to be activated on the MAC, which none of the Ethernet drivers using mii(4) implements. Given that loopback media has no real use (and obviously hardly had a chance to actually work) besides for driver development (which just loopback mode should be sufficient for though, i.e one doesn't necessary need support for loopback media) support for it is just dropped as both NetBSD and OpenBSD already did quite some time ago. - Let mii_phy_add_media() also announce the support of IFM_NONE. - Restructure the PHY entry points to use a structure of entry points instead of discrete function pointers, and extend this to include a "reset" entry point. Make sure any PHY-specific reset routine is always used, and provide one for lxtphy(4) which disables MII interrupts (as is done for a few other PHYs we have drivers for). This includes changing NIC drivers which previously just called the generic mii_phy_reset() to now actually call the PHY-specific reset routine, which might be crucial in some cases. While at it, the redundant checks in these NIC drivers for mii->mii_instance not being zero before calling the reset routines were removed because as soon as one PHY driver attaches mii->mii_instance is incremented and we hardly can end up in their media change callbacks etc if no PHY driver has attached as mii_attach() would have failed in that case and not attach a miibus(4) instance. Consequently, NIC drivers now no longer should call mii_phy_reset() directly, so it was removed from EXPORT_SYMS. - Add a mii_phy_dev_attach() as a companion helper to mii_phy_dev_probe(). The purpose of that function is to perform the common steps to attach a PHY driver instance and to hook it up to the miibus(4) instance and to optionally also handle the probing, addition and initialization of the supported media. So all a PHY driver without any special requirements has to do in its bus attach method is to call mii_phy_dev_attach() along with PHY-specific MIIF_* flags, a pointer to its PHY functions and the add_media set to one. All PHY drivers were updated to take advantage of mii_phy_dev_attach() as appropriate. Along with these changes the capability mask was added to the mii_softc structure so PHY drivers taking advantage of mii_phy_dev_attach() but still handling media on their own do not need to fiddle with the MII attach arguments anyway. - Keep track of the PHY offset in the mii_softc structure. This is done for compatibility with NetBSD/OpenBSD. - Keep track of the PHY's OUI, model and revision in the mii_softc structure. Several PHY drivers require this information also after attaching and previously had to wrap their own softc around mii_softc. NetBSD/OpenBSD also keep track of the model and revision on their mii_softc structure. All PHY drivers were updated to take advantage as appropriate. - Convert the mebers of the MII data structure to unsigned where appropriate. This is partly inspired by NetBSD/OpenBSD. - According to IEEE 802.3-2002 the bits actually have to be reversed when mapping an OUI to the MII ID registers. All PHY drivers and miidevs where changed as necessary. Actually this now again allows to largely share miidevs with NetBSD, which fixed this problem already 9 years ago. Consequently miidevs was synced as far as possible. - Add MIIF_NOMANPAUSE and mii_phy_flowstatus() calls to drivers that weren't explicitly converted to support flow control before. It's unclear whether flow control actually works with these but typically it should and their net behavior should be more correct with these changes in place than without if the MAC driver sets MIIF_DOPAUSE. Obtained from: NetBSD (partially) Reviewed by: yongari (earlier version), silence on arch@ and net@ Notes: svn path=/head/; revision=221407
* Correct spelling in comments.Marius Strobl2011-04-221-1/+1
| | | | | | | Submitted by: brucec Notes: svn path=/head/; revision=220938
* - Don't announce PAUSE support for half-duplex when MIIF_FORCEPAUSE isMarius Strobl2011-01-141-3/+5
| | | | | | | | | | set. - Let mii_phy_auto() also announce PAUSE support for 10baseT-FDX. MFC after: 1 week Notes: svn path=/head/; revision=217414
* o Flesh out the generic IEEE 802.3 annex 31B full duplex flow controlMarius Strobl2010-11-141-21/+141
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | support in mii(4): - Merge generic flow control advertisement (which can be enabled by passing by MIIF_DOPAUSE to mii_attach(9)) and parsing support from NetBSD into mii_physubr.c and ukphy_subr.c. Unlike as in NetBSD, IFM_FLOW isn't implemented as a global option via the "don't care mask" but instead as a media specific option this. This has the following advantages: o allows flow control advertisement with autonegotiation to be turned on and off via ifconfig(8) with the default typically being off (though MIIF_FORCEPAUSE has been added causing flow control to be always advertised, allowing to easily MFC this changes for drivers that previously used home-grown support for flow control that behaved that way without breaking POLA) o allows to deal with PHY drivers where flow control advertisement with manual selection doesn't work or at least isn't implemented, like it's the case with brgphy(4), e1000phy(4) and ip1000phy(4), by setting MIIF_NOMANPAUSE o the available combinations of media options are readily available from the `ifconfig -m` output - Add IFM_FLOW to IFM_SHARED_OPTION_DESCRIPTIONS and IFM_ETH_RXPAUSE and IFM_ETH_TXPAUSE to IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS so these are understood by ifconfig(8). o Make the master/slave support in mii(4) actually usable: - Change IFM_ETH_MASTER from being implemented as a global option via the "don't care mask" to a media specific one as it actually is only applicable to IFM_1000_T to date. - Let mii_phy_setmedia() set GTCR_MAN_MS in IFM_1000_T slave mode to actually configure manually selected slave mode (like we also do in the PHY specific implementations). - Add IFM_ETH_MASTER to IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS so it is understood by ifconfig(8). o Switch bge(4), bce(4), msk(4), nfe(4) and stge(4) along with brgphy(4), e1000phy(4) and ip1000phy(4) to use the generic flow control support instead of home-grown solutions via IFM_FLAGs. This includes changing these PHY drivers and smcphy(4) to no longer unconditionally advertise support for flow control but only if the selected media has IFM_FLOW set (or MIIF_FORCEPAUSE is set) and implemented for these media variants, i.e. typically only for copper. o Switch brgphy(4), ciphy(4), e1000phy(4) and ip1000phy(4) to report and set IFM_1000_T master mode via IFM_ETH_MASTER instead of via IFF_LINK0 and some IFM_FLAGn. o Switch brgphy(4) to add at least the the supported copper media based on the contents of the BMSR via mii_phy_add_media() instead of hardcoding them. The latter approach seems to have developed historically, besides causing unnecessary code duplication it was also undesirable because brgphy_mii_phy_auto() already based the capability advertisement on the contents of the BMSR though. o Let brgphy(4) set IFM_1000_T master mode on all supported PHY and not just BCM5701. Apparently this was a misinterpretation of a workaround in the Linux tg3 driver; BCM5701 seem to require RGPHY_1000CTL_MSE and BRGPHY_1000CTL_MSC to be set when configuring autonegotiation but this doesn't mean we can't set these as well on other PHYs for manual media selection. o Let ukphy_status() report IFM_1000_T master mode via IFM_ETH_MASTER so IFM_1000_T master mode support now is generally available with all PHY drivers. o Don't let e1000phy(4) set master/slave bits for IFM_1000_SX as it's not applicable there. Reviewed by: yongari (plus additional testing) Obtained from: NetBSD (partially), OpenBSD (partially) MFC after: 2 weeks Notes: svn path=/head/; revision=215297
* Turn a panic into a printf so IFM_ETH_MASTER on !IFM_1000_T is complainedMarius Strobl2010-10-311-1/+1
| | | | | | | | | | about but otherwise ignored. When allowing the master to be set manually via ifconfig(8) by adding the former to IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS (as it should be) it seems to be unfavorable that a machine can be made to panic with a simple ifconfig(8) invocation. Notes: svn path=/head/; revision=214608
* Try to make the style consistent (including regarding NetBSD bits not yetMarius Strobl2010-10-311-44/+39
| | | | | | | merged) and adhere style(9). Notes: svn path=/head/; revision=214606
* - Given that as of r214264 all PHY drivers using mii(4) finally have beenMarius Strobl2010-10-241-94/+1
| | | | | | | | | | | | converted to use the mii_phy_add_media()/mii_phy_setmedia() pair instead of mii_add_media()/mii_anar() remove the latter. - Declare mii_media mii_media_table static as it shouldn't be used outside of mii_physubr.c. MFC after: never Notes: svn path=/head/; revision=214265
* Use the mii_data provided via mii_attach_args and mii_pdata respectivelyMarius Strobl2010-09-271-2/+1
| | | | | | | instead of reaching out for the softc of the parent. Notes: svn path=/head/; revision=213229
* The NetBSD Foundation has granted permission to remove clause 3 and 4 fromJoel Dahl2010-03-031-7/+0
| | | | | | | | | the software. Obtained from: NetBSD Notes: svn path=/head/; revision=204646
* Remove mii_media_from_bmcr(); all previous users have been converted toMarius Strobl2007-01-131-18/+0
| | | | | | | use mii_phy_add_media()/mii_phy_setmedia(). Notes: svn path=/head/; revision=165990
* Add a helper function mii_phy_dev_probe(), which wraps around theMarius Strobl2006-12-021-1/+13
| | | | | | | | | | | | | | mii_phy_match() API and takes care of the PHY device probe based on the struct mii_phydesc array and the match return value provided. Convert PHY drivers to take advantage of mii_phy_dev_probe(), converting drivers to provide a mii_phydesc table in the first place where necessary. Reviewed by: yongari MFC after: 2 weeks Notes: svn path=/head/; revision=164827
* Analogous to mii_add_media(), factor out the code for checking whetherMarius Strobl2006-11-271-0/+6
| | | | | | | | | | | the BMSR contains any media at all to mii_phy_add_media(). The majority of the drivers currently using mii_phy_add_media() were missing such a check anyway though. MFC after: 2 weeks Notes: svn path=/head/; revision=164703
* - Add a MIIF_FORCEANEG flag which forces an auto-negotiation to alwaysMarius Strobl2006-11-271-4/+10
| | | | | | | | | | | | | | | | | | take place if IFM_AUTO is selected. This allows drivers like nsphy(4), which need to force writing the ANAR according to the BMSR, to take advantage of mii_phy_setmedia(). [1] - In mii_phy_reset() once the current media is set don't isolate the PHY corresponding to the instance of the currently selected media rather than unconditionally not isolating the PHY corresponding to instance 0. This saves a isolation-unisolation-cycle of the PHY corresponding to the currently selected media for the case were it isn't instance 0. - Fix some whitespace nits. [1] Obtained from: NetBSD [1] MFC after: 2 weeks Notes: svn path=/head/; revision=164702
* Reset autonegotiation timer if current media is not 'auto'.Oleg Bulyzhin2006-07-031-1/+3
| | | | | | | | Approved by: glebius (mentor) MFC after: 2 weeks Notes: svn path=/head/; revision=160082
* 1) Fix mii_phy_tick():Oleg Bulyzhin2006-05-161-18/+18
| | | | | | | | | | | | | | | | | Current code does not report link loss correctly - when link goes down, mii_phy_tick() will notice that with up to mii_anegticks delay. If link goes up during this delay then link flapping will be unnoticed by driver. 2) mii_phy_add_media(): initialize sc->mii_anegticks for 10/100 media 3) Use MII_ANEGTICKS/MII_ANEGTICKS_GIGE defines instead of hardcoded values. Approved by: glebius (mentor) MFC after: 1 month Notes: svn path=/head/; revision=158649
* Add a more generic version of the mii_phy_match routine (mii_phy_match_gen)Warner Losh2005-09-301-2/+10
| | | | | | | | which can be used for phy that want to piggy back other data with their table. Notes: svn path=/head/; revision=150756
* Use ANSI function definitions, in preference to the K&R definitions.Warner Losh2005-02-151-4/+2
| | | | Notes: svn path=/head/; revision=141937
* Remove double __FBSDID and move the remaining one into a common place afterMarius Strobl2004-05-291-3/+0
| | | | | | | | the license(s) and before the driver comment (the latter only in drivers not having __FBSDID at that location). Notes: svn path=/head/; revision=129844
* Correct the phy_service() routine case MII_TICK to correctly trackAndre Oppermann2004-05-031-2/+4
| | | | | | | | | | | | | the falling edge of a media state change. This is in preparation for media state change notification to the routing socket. No objections by: sam, wpaul, ru, bms Brucification by: bde Notes: svn path=/head/; revision=128870
* Use __FBSDID().David E. O'Brien2003-08-241-0/+3
| | | | | | | Also some minor style cleanups. Notes: svn path=/head/; revision=119418
* Remove unnecessary breaks.Poul-Henning Kamp2003-05-311-2/+0
| | | | | | | | | | Remove unused variables. Add XXX comment where a break may be missing. [lxtphy.c] Found by: FlexeLint Notes: svn path=/head/; revision=115520
* Use __FBSDID rather than rcsid[].David E. O'Brien2003-04-031-5/+3
| | | | Notes: svn path=/head/; revision=113038
* Increase gigE negotiation timeout to 17 seconds.Poul-Henning Kamp2002-05-041-5/+5
| | | | | | | | 10 seconds is not enough to negotiate a gigE link with a cisco switch which holds carrier off for several seconds between tries. Notes: svn path=/head/; revision=96027
* Clean up mii/phy drivers: Remove the MIIF_DOINGAUTO which doesn't reallyPoul-Henning Kamp2002-05-041-97/+36
| | | | | | | | do anything at the end of the day except bloat the drivers which has copy&pasted it. Notes: svn path=/head/; revision=96026
* Introduce NetBSD's mii_phy_match() API and use it in the nsgphy toPoul-Henning Kamp2002-04-291-0/+12
| | | | | | | get a description printed. Notes: svn path=/head/; revision=95724
* Make one generic mii_phy_detach() to replace 19 slightly different ones.Poul-Henning Kamp2002-04-291-14/+27
| | | | | | | | | | Rename mii_phy_auto_stop() mii_phy_down(). Introduce mii_down(), use it from nge. Do not indirect it to 19 identical case's in 19 switchstatements like NetBSD did. Notes: svn path=/head/; revision=95722
* Move a lot closer to NetBSDs MII support for GigE.Poul-Henning Kamp2002-04-291-50/+194
| | | | | | | Move fxp and nge drivers over to use the new stuff. Notes: svn path=/head/; revision=95718
* Moving closer to being able to use NetBSD's generic mii_set_media()Poul-Henning Kamp2002-04-291-16/+104
| | | | | | | function. Notes: svn path=/head/; revision=95707
* Edging ever closer to NetBSD...Poul-Henning Kamp2002-04-291-4/+4
| | | | Notes: svn path=/head/; revision=95705
* Don't pass three args when one will do just fine, and even preventPoul-Henning Kamp2002-04-281-3/+9
| | | | | | | mistakes like the one brgphy.c (now corrected). Notes: svn path=/head/; revision=95667
* Improve an API by about 4 lines per driver.Poul-Henning Kamp2002-04-281-0/+5
| | | | Notes: svn path=/head/; revision=95665
* Remove __P.Alfred Perlstein2002-03-201-1/+1
| | | | Notes: svn path=/head/; revision=92739
* Add new device method miibus_linkchg, along with a service routine.Jonathan Lemon2001-09-291-0/+66
| | | | Notes: svn path=/head/; revision=84140
* Grrrrr. That last commit was supposed to be to the head, not to -stableBill Paul2000-12-121-1/+11
| | | | | | | | | (even though I want the fixes in -stable anyway). I'm sure I'm going to get flamed now for committing to -stable and -current too quickly. *sigh* Notes: svn path=/head/; revision=69925
* Remove unneeded #include <machine/clock.h>Poul-Henning Kamp2000-10-151-1/+0
| | | | Notes: svn path=/head/; revision=67164
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50477
* This commit adds support for the NetBSD MII abstraction layer andBill Paul1999-08-211-0/+264
MII-compliant PHY drivers. Many 10/100 ethernet NICs available today either use an MII transceiver or have built-in transceivers that can be programmed using an MII interface. It makes sense then to separate this support out into common code instead of duplicating it in all of the NIC drivers. The mii code also handles all of the media detection, selection and reporting via the ifmedia interface. This is basically the same code from NetBSD's /sys/dev/mii, except it's been adapted to FreeBSD's bus architecture. The advantage to this is that it automatically allows everything to be turned into a loadable module. There are some common functions for use in drivers once an miibus has been attached (mii_mediachg(), mii_pollstat(), mii_tick()) as well as individual PHY drivers. There is also a generic driver for all PHYs that aren't handled by a specific driver. It's possible to do this because all 10/100 PHYs implement the same general register set in addition to their vendor-specific register sets, so for the most part you can use one driver for pretty much any PHY. There are a couple of oddball exceptions though, hence the need to have specific drivers. There are two layers: the generic "miibus" layer and the PHY driver layer. The drivers are child devices of "miibus" and the "miibus" is a child of a given NIC driver. The "miibus" code and the PHY drivers can actually be compiled and kldoaded as completely separate modules or compiled together into one module. For the moment I'm using the latter approach since the code is relatively small. Currently there are only three PHY drivers here: the generic driver, the built-in 3Com XL driver and the NS DP83840 driver. I'll be adding others later as I convert various NIC drivers to use this code. I realize that I'm cvs adding this stuff instead of importing it onto a separate vendor branch, but in my opinion the import approach doesn't really offer any significant advantage: I'm going to be maintaining this stuff and writing my own PHY drivers one way or the other. Notes: svn path=/head/; revision=50120