1 /**  <at> file
2 *  Media Independent Interface configuration definitions. Ported from FreeBSD.
3 *
4 *  Copyright (c) 2011-2016, ARM Limited. All rights reserved.
5 *
6 *  This program and the accompanying materials
7 *  are licensed and made available under the terms and conditions of the BSD License
8 *  which accompanies this distribution.  The full text of the license may be found at
9 *  http://opensource.org/licenses/bsd-license.php
10 *
11 *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 *
14 **/
15 /*-
16  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
17  * All rights reserved.
18  *
19  * This code is derived from software contributed to The NetBSD Foundation
20  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
21  * NASA Ames Research Center.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the above copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. All advertising materials mentioning features or use of this software
32  *    must display the following acknowledgement:
33  *  This product includes software developed by the NetBSD
34  *  Foundation, Inc. and its contributors.
35  * 4. Neither the name of The NetBSD Foundation nor the names of its
36  *    contributors may be used to endorse or promote products derived
37  *    from this software without specific prior written permission.
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
40  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
43  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  * $FreeBSD: src/sys/dev/mii/miivar.h,v 1.21.10.1.4.1 2010/06/14 02:09:06 kensmith Exp $
52  */
53 
54 #ifndef _DEV_MII_MIIVAR_H_
55 #define  _DEV_MII_MIIVAR_H_
56 
57 /*
58  * A network interface driver has one of these structures in its softc.
59  * It is the interface from the network interface driver to the MII
60  * layer.
61  */
62 struct mii_data {
63   /*
64    * PHY driver fills this in with active media status.
65    */
66   INTN mii_media_status;
67   INTN mii_media_active;
68 };
69 
70 /*
71  * Requests that can be made to the downcall.
72  */
73 #define  MII_TICK                    1  /* once-per-second tick */
74 #define  MII_MEDIACHG                2  /* user changed media; perform the switch */
75 #define  MII_POLLSTAT                3  /* user requested media status; fill it in */
76 
77 /*
78  * Each PHY driver's softc has one of these as the first member.
79  * XXX This would be better named "phy_softc", but this is the name
80  * XXX BSDI used, and we would like to have the same interface.
81  */
82 struct mii_softc {
83   struct mii_data *mii_pdata;  /* pointer to parent's mii_data */
84 
85   INTN mii_flags;           /* misc. flags; see below */
86   INTN mii_capabilities;    /* capabilities from BMSR */
87   INTN mii_extcapabilities; /* extended capabilities */
88   INTN mii_ticks;           /* MII_TICK counter */
89   INTN mii_anegticks;       /* ticks before retrying aneg */
90   INTN mii_media_active;    /* last active media */
91   INTN mii_media_status;    /* last active status */
92 };
93 
94 /* mii_flags */
95 #define  MIIF_INITDONE              0x0001    /* has been initialized (mii_data) */
96 #define  MIIF_NOISOLATE             0x0002    /* do not isolate the PHY */
97 #define  MIIF_NOLOOP                0x0004    /* no loopback capability */
98 #define MIIF_AUTOTSLEEP             0x0010    /* use tsleep(), not callout() */
99 #define MIIF_HAVEFIBER              0x0020    /* from parent: has fiber interface */
100 #define  MIIF_HAVE_GTCR             0x0040    /* has 100base-T2/1000base-T CR */
101 #define  MIIF_IS_1000X              0x0080    /* is a 1000BASE-X device */
102 #define  MIIF_DOPAUSE               0x0100    /* advertise PAUSE capability */
103 #define  MIIF_IS_HPNA               0x0200    /* is a HomePNA device */
104 #define  MIIF_FORCEANEG             0x0400    /* force auto-negotiation */
105 
106 /* Default mii_anegticks values */
107 #define  MII_ANEGTICKS              5
108 #define  MII_ANEGTICKS_GIGE         17
109 
110 #define  MIIF_INHERIT_MASK          (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP)
111 
112 #define MII_OUI_MARVELL             0x005043
113 #define MII_OUI_xxMARVELL           0x000ac2
114 
115 #define MII_MODEL_MARVELL_E1000     0x0000
116 #define MII_MODEL_MARVELL_E1011     0x0002
117 #define MII_MODEL_MARVELL_E1000_3   0x0003
118 #define MII_MODEL_MARVELL_E1000S    0x0004
119 #define MII_MODEL_MARVELL_E1000_5   0x0005
120 #define MII_MODEL_MARVELL_E1000_6   0x0006
121 #define MII_MODEL_MARVELL_E3082     0x0008
122 #define MII_MODEL_MARVELL_E1112     0x0009
123 #define MII_MODEL_MARVELL_E1149     0x000b
124 #define MII_MODEL_MARVELL_E1111     0x000c
125 #define MII_MODEL_MARVELL_E1116     0x0021
126 #define MII_MODEL_MARVELL_E1116R    0x0024
127 #define MII_MODEL_MARVELL_E1118     0x0022
128 #define MII_MODEL_MARVELL_E3016     0x0026
129 #define MII_MODEL_MARVELL_PHYG65G   0x0027
130 #define MII_MODEL_xxMARVELL_E1000   0x0000
131 #define MII_MODEL_xxMARVELL_E1011   0x0002
132 #define MII_MODEL_xxMARVELL_E1000_3 0x0003
133 #define MII_MODEL_xxMARVELL_E1000_5 0x0005
134 #define MII_MODEL_xxMARVELL_E1111   0x000c
135 
136 #define MII_STR_MARVELL_E1000       "Marvell 88E1000 Gigabit PHY"
137 #define MII_STR_MARVELL_E1011       "Marvell 88E1011 Gigabit PHY"
138 #define MII_STR_MARVELL_E1000_3     "Marvell 88E1000_3 Gigabit PHY"
139 #define MII_STR_MARVELL_E1000S      "Marvell 88E1000S Gigabit PHY"
140 #define MII_STR_MARVELL_E1000_5     "Marvell 88E1000_5 Gigabit PHY"
141 #define MII_STR_MARVELL_E1000_6     "Marvell 88E1000_6 Gigabit PHY"
142 #define MII_STR_MARVELL_E3082       "Marvell 88E3082 10/100 Fast Ethernet PHY"
143 #define MII_STR_MARVELL_E1112       "Marvell 88E1112 Gigabit PHY"
144 #define MII_STR_MARVELL_E1149       "Marvell 88E1149 Gigabit PHY"
145 #define MII_STR_MARVELL_E1111       "Marvell 88E1111 Gigabit PHY"
146 #define MII_STR_MARVELL_E1116       "Marvell 88E1116 Gigabit PHY"
147 #define MII_STR_MARVELL_E1116R      "Marvell 88E1116R Gigabit PHY"
148 #define MII_STR_MARVELL_E1118       "Marvell 88E1118 Gigabit PHY"
149 #define MII_STR_MARVELL_E3016       "Marvell 88E3016 10/100 Fast Ethernet PHY"
150 #define MII_STR_MARVELL_PHYG65G     "Marvell PHYG65G Gigabit PHY"
151 #define MII_STR_xxMARVELL_E1000     "Marvell 88E1000 Gigabit PHY"
152 #define MII_STR_xxMARVELL_E1011     "Marvell 88E1011 Gigabit PHY"
153 #define MII_STR_xxMARVELL_E1000_3   "Marvell 88E1000_3 Gigabit PHY"
154 #define MII_STR_xxMARVELL_E1000_5   "Marvell 88E1000_5 Gigabit PHY"
155 #define MII_STR_xxMARVELL_E1111     "Marvell 88E1111 Gigabit PHY"
156 
157 /*
158  * Used to attach a PHY to a parent.
159  */
160 struct mii_attach_args {
161   struct mii_data *mii_data;  /* pointer to parent data */
162   INTN mii_id1;      /* PHY ID register 1 */
163   INTN mii_id2;      /* PHY ID register 2 */
164 };
165 
166 /*
167  * Used to match a PHY.
168  */
169 struct mii_phydesc {
170   UINT32      mpd_oui;    /* the PHY's OUI */
171   UINT32      mpd_model;  /* the PHY's model */
172   const CHAR8 *mpd_name;  /* the PHY's name */
173 };
174 #define MII_PHY_DESC(a, b)          { MII_OUI_ ## a, MII_MODEL_ ## a ## _ ## b, MII_STR_ ## a ## _ ## b }
175 #define MII_PHY_END                 { 0, 0, NULL }
176 
177 #define PHY_READ(p, r)           msk_phy_readreg ((p)->sc_if, (r))
178 
179 #define PHY_WRITE(p, r, v)       msk_phy_writereg ((p)->sc_if, (r), (v))
180 
181 struct msk_mii_data {
182   INTN    port;
183   UINT32  pmd;
184   INTN    mii_flags;
185 };
186 
187 #endif /* _DEV_MII_MIIVAR_H_ */
188