\hypertarget{arswitch__phy_8c_source}{}\doxysection{arswitch\+\_\+phy.\+c}
\label{arswitch__phy_8c_source}\index{dev/etherswitch/arswitch/arswitch\_phy.c@{dev/etherswitch/arswitch/arswitch\_phy.c}}
\mbox{\hyperlink{arswitch__phy_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 2011-\/2012 Stefan Bethke.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00005}00005 \textcolor{comment}{ * Copyright (c) 2012 Adrian Chadd.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00006}00006 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00007}00007 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00008}00008 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00009}00009 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00010}00010 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00011}00011 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00012}00012 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00013}00013 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00014}00014 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00015}00015 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00016}00016 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00017}00017 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00018}00018 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00019}00019 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00020}00020 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00021}00021 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00022}00022 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00023}00023 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00024}00024 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00025}00025 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00026}00026 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00027}00027 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00028}00028 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00029}00029 \textcolor{comment}{ * \$FreeBSD\$}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00030}00030 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00031}00031 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00033}00033 \textcolor{preprocessor}{\#include <sys/bus.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <sys/errno.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00035}00035 \textcolor{preprocessor}{\#include <sys/kernel.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00036}00036 \textcolor{preprocessor}{\#include <sys/lock.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00037}00037 \textcolor{preprocessor}{\#include <sys/module.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00038}00038 \textcolor{preprocessor}{\#include <sys/mutex.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00039}00039 \textcolor{preprocessor}{\#include <sys/socket.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00040}00040 \textcolor{preprocessor}{\#include <sys/sockio.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <sys/sysctl.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00043}00043 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00044}00044 \textcolor{preprocessor}{\#include <net/if.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00045}00045 \textcolor{preprocessor}{\#include <net/if\_media.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00046}00046 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00047}00047 \textcolor{preprocessor}{\#include <machine/bus.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00048}00048 \textcolor{preprocessor}{\#include <dev/iicbus/iic.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00049}00049 \textcolor{preprocessor}{\#include <dev/iicbus/iiconf.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00050}00050 \textcolor{preprocessor}{\#include <dev/iicbus/iicbus.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00051}00051 \textcolor{preprocessor}{\#include <dev/mii/mii.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00052}00052 \textcolor{preprocessor}{\#include <dev/mii/miivar.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00053}00053 \textcolor{preprocessor}{\#include <dev/mdio/mdio.h>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00054}00054 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00055}00055 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{etherswitch_8h}{dev/etherswitch/etherswitch.h}}>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00056}00056 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00057}00057 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{arswitchreg_8h}{dev/etherswitch/arswitch/arswitchreg.h}}>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00058}00058 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{arswitchvar_8h}{dev/etherswitch/arswitch/arswitchvar.h}}>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00059}00059 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00060}00060 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{arswitch__reg_8h}{dev/etherswitch/arswitch/arswitch\_reg.h}}>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00061}00061 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{arswitch__phy_8h}{dev/etherswitch/arswitch/arswitch\_phy.h}}>}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00062}00062 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00063}00063 \textcolor{preprocessor}{\#include "{}mdio\_if.h"{}}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00064}00064 \textcolor{preprocessor}{\#include "{}miibus\_if.h"{}}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00065}00065 \textcolor{preprocessor}{\#include "{}etherswitch\_if.h"{}}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00066}00066 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00067}00067 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00068}00068 \textcolor{comment}{ * Access PHYs integrated into the switch by going direct}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00069}00069 \textcolor{comment}{ * to the PHY space itself, rather than through the switch}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00070}00070 \textcolor{comment}{ * MDIO register.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00071}00071 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00072}00072 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00073}\mbox{\hyperlink{arswitch__phy_8c_a3492048794497b97d53fd27190f6da62}{00073}} \mbox{\hyperlink{arswitch__phy_8c_a3492048794497b97d53fd27190f6da62}{arswitch\_readphy\_external}}(device\_t dev, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}})}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00074}00074 \{}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00075}00075         \textcolor{keywordtype}{int} ret;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00076}00076         \textcolor{keyword}{struct }\mbox{\hyperlink{structarswitch__softc}{arswitch\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00077}00077 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00078}00078         sc = device\_get\_softc(dev);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00079}00079 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00080}00080         \mbox{\hyperlink{arswitchvar_8h_ac08400399758baa649e223dd369aa3cc}{ARSWITCH\_LOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00081}00081         ret = (MDIO\_READREG(device\_get\_parent(dev), \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}));}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00082}00082         \mbox{\hyperlink{arswitchvar_8h_abdc2f40de12a2aa619e6366e0039832d}{DPRINTF}}(sc, \mbox{\hyperlink{arswitchvar_8h_a9a3d89a943c30ba0ac07c5e738eb82fc}{ARSWITCH\_DBG\_PHYIO}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00083}00083             \textcolor{stringliteral}{"{}\%s: phy=0x\%08x, reg=0x\%08x, ret=0x\%08x\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00084}00084             \_\_func\_\_, \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, ret);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00085}00085         \mbox{\hyperlink{arswitchvar_8h_a946c613ba31a000a1e32396435b4f55b}{ARSWITCH\_UNLOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00086}00086 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00087}00087         \textcolor{keywordflow}{return} (ret);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00088}00088 \}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00089}00089 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00090}00090 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00091}\mbox{\hyperlink{arswitch__phy_8c_a3a1ff744ab0b2a5125e4c2b162961c93}{00091}} \mbox{\hyperlink{arswitch__phy_8c_a3a1ff744ab0b2a5125e4c2b162961c93}{arswitch\_writephy\_external}}(device\_t dev, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, \textcolor{keywordtype}{int} data)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00092}00092 \{}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00093}00093         \textcolor{keyword}{struct }\mbox{\hyperlink{structarswitch__softc}{arswitch\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00094}00094 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00095}00095         sc = device\_get\_softc(dev);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00096}00096 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00097}00097         \mbox{\hyperlink{arswitchvar_8h_ac08400399758baa649e223dd369aa3cc}{ARSWITCH\_LOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00098}00098         (void) MDIO\_WRITEREG(device\_get\_parent(dev), \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00099}00099             \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, data);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00100}00100         \mbox{\hyperlink{arswitchvar_8h_abdc2f40de12a2aa619e6366e0039832d}{DPRINTF}}(sc, \mbox{\hyperlink{arswitchvar_8h_a9a3d89a943c30ba0ac07c5e738eb82fc}{ARSWITCH\_DBG\_PHYIO}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00101}00101             \textcolor{stringliteral}{"{}\%s: phy=0x\%08x, reg=0x\%08x, data=0x\%08x\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00102}00102             \_\_func\_\_, \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, data);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00103}00103         \mbox{\hyperlink{arswitchvar_8h_a946c613ba31a000a1e32396435b4f55b}{ARSWITCH\_UNLOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00104}00104 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00105}00105         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00106}00106 \}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00107}00107 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00108}00108 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00109}00109 \textcolor{comment}{ * Access PHYs integrated into the switch chip through the switch's MDIO}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00110}00110 \textcolor{comment}{ * control register.}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00111}00111 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00112}00112 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00113}\mbox{\hyperlink{arswitch__phy_8c_aeb1d86dab14caef20569e1abb40b6278}{00113}} \mbox{\hyperlink{arswitch__phy_8c_aeb1d86dab14caef20569e1abb40b6278}{arswitch\_readphy\_internal}}(device\_t dev, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}})}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00114}00114 \{}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00115}00115         \textcolor{keyword}{struct }\mbox{\hyperlink{structarswitch__softc}{arswitch\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00116}00116         uint32\_t data = 0, ctrl;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00117}00117         \textcolor{keywordtype}{int} err, timeout;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00118}00118         uint32\_t a;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00119}00119 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00120}00120         sc = device\_get\_softc(dev);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00121}00121         \mbox{\hyperlink{arswitchvar_8h_a74ca3c42d23651042ca1eb048d52d6c2}{ARSWITCH\_LOCK\_ASSERT}}(sc, MA\_NOTOWNED);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00122}00122 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00123}00123         \textcolor{keywordflow}{if} (phy < 0 || phy >= 32)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00124}00124                 \textcolor{keywordflow}{return} (ENXIO);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00125}00125         \textcolor{keywordflow}{if} (reg < 0 || reg >= 32)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00126}00126                 \textcolor{keywordflow}{return} (ENXIO);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00127}00127 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00128}00128         \textcolor{keywordflow}{if} (\mbox{\hyperlink{arswitchvar_8h_af47a5f56a5ea9be1a450a2efa2e1a427}{AR8X16\_IS\_SWITCH}}(sc, AR8327))}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00129}00129                 a = \mbox{\hyperlink{arswitchreg_8h_aaa9f2022e07b31a599517c930c7fa6e6}{AR8327\_REG\_MDIO\_CTRL}};}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00130}00130         \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00131}00131                 a = \mbox{\hyperlink{arswitchreg_8h_a92e2db8e6597b4919dc2af6a7bc0d516}{AR8X16\_REG\_MDIO\_CTRL}};}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00132}00132 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00133}00133         \mbox{\hyperlink{arswitchvar_8h_ac08400399758baa649e223dd369aa3cc}{ARSWITCH\_LOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00134}00134         err = \mbox{\hyperlink{arswitch__reg_8c_a23c507aa0cc6995ebaebb1f533d5a54a}{arswitch\_writereg\_msb}}(dev, a,}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00135}00135             \mbox{\hyperlink{arswitchreg_8h_aa43a095034526d4617497c1c0cf7f73a}{AR8X16\_MDIO\_CTRL\_BUSY}} | \mbox{\hyperlink{arswitchreg_8h_a6b5234a2242e5f6746bc14be19a23c33}{AR8X16\_MDIO\_CTRL\_MASTER\_EN}} |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00136}00136             \mbox{\hyperlink{arswitchreg_8h_a5b67b6a12349296bc3296fecf8a936f3}{AR8X16\_MDIO\_CTRL\_CMD\_READ}} |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00137}00137             (\mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}} << \mbox{\hyperlink{arswitchreg_8h_a96541e5fcc2f7888d62479f27b0a1c41}{AR8X16\_MDIO\_CTRL\_PHY\_ADDR\_SHIFT}}) |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00138}00138             (\mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}} << \mbox{\hyperlink{arswitchreg_8h_a7877bf2177f4d292c86e091fd90dacd9}{AR8X16\_MDIO\_CTRL\_REG\_ADDR\_SHIFT}}));}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00139}00139         \mbox{\hyperlink{arswitchvar_8h_a4ede244673807da3e01bbecdafd9c3fc}{DEVERR}}(dev, err, \textcolor{stringliteral}{"{}arswitch\_readphy()=\%d: phy=\%d.\%02x\(\backslash\)n"{}}, \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}});}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00140}00140         \textcolor{keywordflow}{if} (err != 0)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00141}00141                 \textcolor{keywordflow}{goto} fail;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00142}00142         \textcolor{keywordflow}{for} (timeout = 100; timeout-\/-\/; ) \{}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00143}00143                 ctrl = \mbox{\hyperlink{arswitch__reg_8c_a8a5d0e2e41d815be6f2e6539de8aeb17}{arswitch\_readreg\_msb}}(dev, a);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00144}00144                 \textcolor{keywordflow}{if} ((ctrl \& \mbox{\hyperlink{arswitchreg_8h_aa43a095034526d4617497c1c0cf7f73a}{AR8X16\_MDIO\_CTRL\_BUSY}}) == 0)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00145}00145                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00146}00146         \}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00147}00147         \textcolor{keywordflow}{if} (timeout < 0) \{}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00148}00148                 \mbox{\hyperlink{arswitchvar_8h_abdc2f40de12a2aa619e6366e0039832d}{DPRINTF}}(sc, \mbox{\hyperlink{arswitchvar_8h_a879e5191e3d83dabd0bf9d2f6625b20d}{ARSWITCH\_DBG\_ANY}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00149}00149                     \textcolor{stringliteral}{"{}arswitch\_readphy(): phy=\%d.\%02x; timeout=\%d\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00150}00150                     \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, timeout);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00151}00151                 \textcolor{keywordflow}{goto} fail;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00152}00152         \}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00153}00153         data = \mbox{\hyperlink{arswitch__reg_8c_ae483680c77bcadab500a8a438937dfeb}{arswitch\_readreg\_lsb}}(dev, a) \&}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00154}00154             \mbox{\hyperlink{arswitchreg_8h_a145e3d867ab010eddce3909755cf1d45}{AR8X16\_MDIO\_CTRL\_DATA\_MASK}};}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00155}00155         \mbox{\hyperlink{arswitchvar_8h_a946c613ba31a000a1e32396435b4f55b}{ARSWITCH\_UNLOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00156}00156 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00157}00157         \mbox{\hyperlink{arswitchvar_8h_abdc2f40de12a2aa619e6366e0039832d}{DPRINTF}}(sc, \mbox{\hyperlink{arswitchvar_8h_a9a3d89a943c30ba0ac07c5e738eb82fc}{ARSWITCH\_DBG\_PHYIO}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00158}00158             \textcolor{stringliteral}{"{}\%s: phy=0x\%08x, reg=0x\%08x, ret=0x\%08x\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00159}00159             \_\_func\_\_, \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, data);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00160}00160 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00161}00161         \textcolor{keywordflow}{return} (data);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00162}00162 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00163}00163 fail:}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00164}00164         \mbox{\hyperlink{arswitchvar_8h_a946c613ba31a000a1e32396435b4f55b}{ARSWITCH\_UNLOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00165}00165 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00166}00166         \mbox{\hyperlink{arswitchvar_8h_abdc2f40de12a2aa619e6366e0039832d}{DPRINTF}}(sc, \mbox{\hyperlink{arswitchvar_8h_a9a3d89a943c30ba0ac07c5e738eb82fc}{ARSWITCH\_DBG\_PHYIO}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00167}00167             \textcolor{stringliteral}{"{}\%s: phy=0x\%08x, reg=0x\%08x, fail; err=\%d\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00168}00168             \_\_func\_\_, \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, err);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00169}00169 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00170}00170         \textcolor{keywordflow}{return} (-\/1);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00171}00171 \}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00172}00172 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00173}00173 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00174}\mbox{\hyperlink{arswitch__phy_8c_ad7cf871460bc39e6c425c98e6c05da9f}{00174}} \mbox{\hyperlink{arswitch__phy_8c_ad7cf871460bc39e6c425c98e6c05da9f}{arswitch\_writephy\_internal}}(device\_t dev, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \textcolor{keywordtype}{int} \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, \textcolor{keywordtype}{int} data)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00175}00175 \{}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00176}00176         \textcolor{keyword}{struct }\mbox{\hyperlink{structarswitch__softc}{arswitch\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00177}00177         uint32\_t ctrl;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00178}00178         \textcolor{keywordtype}{int} err, timeout;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00179}00179         uint32\_t a;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00180}00180 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00181}00181         sc = device\_get\_softc(dev);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00182}00182         \mbox{\hyperlink{arswitchvar_8h_a74ca3c42d23651042ca1eb048d52d6c2}{ARSWITCH\_LOCK\_ASSERT}}(sc, MA\_NOTOWNED);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00183}00183 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00184}00184         \textcolor{keywordflow}{if} (reg < 0 || reg >= 32)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00185}00185                 \textcolor{keywordflow}{return} (ENXIO);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00186}00186 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00187}00187         \textcolor{keywordflow}{if} (\mbox{\hyperlink{arswitchvar_8h_af47a5f56a5ea9be1a450a2efa2e1a427}{AR8X16\_IS\_SWITCH}}(sc, AR8327))}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00188}00188                 a = \mbox{\hyperlink{arswitchreg_8h_aaa9f2022e07b31a599517c930c7fa6e6}{AR8327\_REG\_MDIO\_CTRL}};}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00189}00189         \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00190}00190                 a = \mbox{\hyperlink{arswitchreg_8h_a92e2db8e6597b4919dc2af6a7bc0d516}{AR8X16\_REG\_MDIO\_CTRL}};}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00191}00191 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00192}00192         \mbox{\hyperlink{arswitchvar_8h_ac08400399758baa649e223dd369aa3cc}{ARSWITCH\_LOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00193}00193         err = \mbox{\hyperlink{arswitch__reg_8c_a9425ce0fc426ca95431a54cdf02b4921}{arswitch\_writereg}}(dev, a,}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00194}00194             \mbox{\hyperlink{arswitchreg_8h_aa43a095034526d4617497c1c0cf7f73a}{AR8X16\_MDIO\_CTRL\_BUSY}} |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00195}00195             \mbox{\hyperlink{arswitchreg_8h_a6b5234a2242e5f6746bc14be19a23c33}{AR8X16\_MDIO\_CTRL\_MASTER\_EN}} |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00196}00196             \mbox{\hyperlink{arswitchreg_8h_a9dd6802b2ff8702f3c798930c4789d92}{AR8X16\_MDIO\_CTRL\_CMD\_WRITE}} |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00197}00197             (\mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}} << \mbox{\hyperlink{arswitchreg_8h_a96541e5fcc2f7888d62479f27b0a1c41}{AR8X16\_MDIO\_CTRL\_PHY\_ADDR\_SHIFT}}) |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00198}00198             (\mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}} << \mbox{\hyperlink{arswitchreg_8h_a7877bf2177f4d292c86e091fd90dacd9}{AR8X16\_MDIO\_CTRL\_REG\_ADDR\_SHIFT}}) |}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00199}00199             (data \& \mbox{\hyperlink{arswitchreg_8h_a145e3d867ab010eddce3909755cf1d45}{AR8X16\_MDIO\_CTRL\_DATA\_MASK}}));}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00200}00200         \textcolor{keywordflow}{if} (err != 0)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00201}00201                 \textcolor{keywordflow}{goto} out;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00202}00202         \textcolor{keywordflow}{for} (timeout = 100; timeout-\/-\/; ) \{}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00203}00203                 ctrl = \mbox{\hyperlink{arswitch__reg_8c_a032a26bfd0728d9e080f65aedaf8b6a0}{arswitch\_readreg}}(dev, a);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00204}00204                 \textcolor{keywordflow}{if} ((ctrl \& \mbox{\hyperlink{arswitchreg_8h_aa43a095034526d4617497c1c0cf7f73a}{AR8X16\_MDIO\_CTRL\_BUSY}}) == 0)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00205}00205                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00206}00206         \}}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00207}00207         \textcolor{keywordflow}{if} (timeout < 0)}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00208}00208                 err = EIO;}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00209}00209 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00210}00210         \mbox{\hyperlink{arswitchvar_8h_abdc2f40de12a2aa619e6366e0039832d}{DPRINTF}}(sc, \mbox{\hyperlink{arswitchvar_8h_a9a3d89a943c30ba0ac07c5e738eb82fc}{ARSWITCH\_DBG\_PHYIO}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00211}00211             \textcolor{stringliteral}{"{}\%s: phy=0x\%08x, reg=0x\%08x, data=0x\%08x, err=\%d\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00212}00212             \_\_func\_\_, \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}}, data, err);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00213}00213 }
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00214}00214 out:}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00215}00215         \mbox{\hyperlink{arswitchvar_8h_a4ede244673807da3e01bbecdafd9c3fc}{DEVERR}}(dev, err, \textcolor{stringliteral}{"{}arswitch\_writephy()=\%d: phy=\%d.\%02x\(\backslash\)n"{}}, \mbox{\hyperlink{etherswitch__if_8m_a5a9bb95881c089e261771c35775eeaf9}{phy}}, \mbox{\hyperlink{etherswitch__if_8m_aa391927e06832c3d8d2f4e89a25cdd81}{reg}});}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00216}00216         \mbox{\hyperlink{arswitchvar_8h_a946c613ba31a000a1e32396435b4f55b}{ARSWITCH\_UNLOCK}}(sc);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00217}00217         \textcolor{keywordflow}{return} (err);}
\DoxyCodeLine{\Hypertarget{arswitch__phy_8c_source_l00218}00218 \}}

\end{DoxyCode}
