ethtool/mdio: Support backplane mode negotiation
[pandora-kernel.git] / include / linux / mdio.h
1 /*
2  * linux/mdio.h: definitions for MDIO (clause 45) transceivers
3  * Copyright 2006-2009 Solarflare Communications Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, incorporated herein by reference.
8  */
9
10 #ifndef __LINUX_MDIO_H__
11 #define __LINUX_MDIO_H__
12
13 #include <linux/mii.h>
14
15 /* MDIO Manageable Devices (MMDs). */
16 #define MDIO_MMD_PMAPMD         1       /* Physical Medium Attachment/
17                                          * Physical Medium Dependent */
18 #define MDIO_MMD_WIS            2       /* WAN Interface Sublayer */
19 #define MDIO_MMD_PCS            3       /* Physical Coding Sublayer */
20 #define MDIO_MMD_PHYXS          4       /* PHY Extender Sublayer */
21 #define MDIO_MMD_DTEXS          5       /* DTE Extender Sublayer */
22 #define MDIO_MMD_TC             6       /* Transmission Convergence */
23 #define MDIO_MMD_AN             7       /* Auto-Negotiation */
24 #define MDIO_MMD_C22EXT         29      /* Clause 22 extension */
25 #define MDIO_MMD_VEND1          30      /* Vendor specific 1 */
26 #define MDIO_MMD_VEND2          31      /* Vendor specific 2 */
27
28 /* Generic MDIO registers. */
29 #define MDIO_CTRL1              MII_BMCR
30 #define MDIO_STAT1              MII_BMSR
31 #define MDIO_DEVID1             MII_PHYSID1
32 #define MDIO_DEVID2             MII_PHYSID2
33 #define MDIO_SPEED              4       /* Speed ability */
34 #define MDIO_DEVS1              5       /* Devices in package */
35 #define MDIO_DEVS2              6
36 #define MDIO_CTRL2              7       /* 10G control 2 */
37 #define MDIO_STAT2              8       /* 10G status 2 */
38 #define MDIO_PMA_TXDIS          9       /* 10G PMA/PMD transmit disable */
39 #define MDIO_PMA_RXDET          10      /* 10G PMA/PMD receive signal detect */
40 #define MDIO_PMA_EXTABLE        11      /* 10G PMA/PMD extended ability */
41 #define MDIO_PKGID1             14      /* Package identifier */
42 #define MDIO_PKGID2             15
43 #define MDIO_AN_ADVERTISE       16      /* AN advertising (base page) */
44 #define MDIO_AN_LPA             19      /* AN LP abilities (base page) */
45 #define MDIO_PHYXS_LNSTAT       24      /* PHY XGXS lane state */
46
47 /* Media-dependent registers. */
48 #define MDIO_PMA_10GBT_TXPWR    131     /* 10GBASE-T TX power control */
49 #define MDIO_PMA_10GBR_FECABLE  170     /* 10GBASE-R FEC ability */
50 #define MDIO_PCS_10GBX_STAT1    24      /* 10GBASE-X PCS status 1 */
51 #define MDIO_PCS_10GBRT_STAT1   32      /* 10GBASE-R/-T PCS status 1 */
52 #define MDIO_PCS_10GBRT_STAT2   33      /* 10GBASE-R/-T PCS status 2 */
53 #define MDIO_AN_10GBT_CTRL      32      /* 10GBASE-T auto-negotiation control */
54 #define MDIO_AN_10GBT_STAT      33      /* 10GBASE-T auto-negotiation status */
55
56 /* Control register 1. */
57 /* Enable extended speed selection */
58 #define MDIO_CTRL1_SPEEDSELEXT          (BMCR_SPEED1000 | BMCR_SPEED100)
59 /* All speed selection bits */
60 #define MDIO_CTRL1_SPEEDSEL             (MDIO_CTRL1_SPEEDSELEXT | 0x003c)
61 #define MDIO_CTRL1_FULLDPLX             BMCR_FULLDPLX
62 #define MDIO_CTRL1_LPOWER               BMCR_PDOWN
63 #define MDIO_CTRL1_RESET                BMCR_RESET
64 #define MDIO_PMA_CTRL1_LOOPBACK         0x0001
65 #define MDIO_PMA_CTRL1_SPEED1000        BMCR_SPEED1000
66 #define MDIO_PMA_CTRL1_SPEED100         BMCR_SPEED100
67 #define MDIO_PCS_CTRL1_LOOPBACK         BMCR_LOOPBACK
68 #define MDIO_PHYXS_CTRL1_LOOPBACK       BMCR_LOOPBACK
69 #define MDIO_AN_CTRL1_RESTART           BMCR_ANRESTART
70 #define MDIO_AN_CTRL1_ENABLE            BMCR_ANENABLE
71 #define MDIO_AN_CTRL1_XNP               0x2000  /* Enable extended next page */
72
73 /* 10 Gb/s */
74 #define MDIO_CTRL1_SPEED10G             (MDIO_CTRL1_SPEEDSELEXT | 0x00)
75 /* 10PASS-TS/2BASE-TL */
76 #define MDIO_CTRL1_SPEED10P2B           (MDIO_CTRL1_SPEEDSELEXT | 0x04)
77
78 /* Status register 1. */
79 #define MDIO_STAT1_LPOWERABLE           0x0002  /* Low-power ability */
80 #define MDIO_STAT1_LSTATUS              BMSR_LSTATUS
81 #define MDIO_STAT1_FAULT                0x0080  /* Fault */
82 #define MDIO_AN_STAT1_LPABLE            0x0001  /* Link partner AN ability */
83 #define MDIO_AN_STAT1_ABLE              BMSR_ANEGCAPABLE
84 #define MDIO_AN_STAT1_RFAULT            BMSR_RFAULT
85 #define MDIO_AN_STAT1_COMPLETE          BMSR_ANEGCOMPLETE
86 #define MDIO_AN_STAT1_PAGE              0x0040  /* Page received */
87 #define MDIO_AN_STAT1_XNP               0x0080  /* Extended next page status */
88
89 /* Speed register. */
90 #define MDIO_SPEED_10G                  0x0001  /* 10G capable */
91 #define MDIO_PMA_SPEED_2B               0x0002  /* 2BASE-TL capable */
92 #define MDIO_PMA_SPEED_10P              0x0004  /* 10PASS-TS capable */
93 #define MDIO_PMA_SPEED_1000             0x0010  /* 1000M capable */
94 #define MDIO_PMA_SPEED_100              0x0020  /* 100M capable */
95 #define MDIO_PMA_SPEED_10               0x0040  /* 10M capable */
96 #define MDIO_PCS_SPEED_10P2B            0x0002  /* 10PASS-TS/2BASE-TL capable */
97
98 /* Device present registers. */
99 #define MDIO_DEVS_PRESENT(devad)        (1 << (devad))
100 #define MDIO_DEVS_PMAPMD                MDIO_DEVS_PRESENT(MDIO_MMD_PMAPMD)
101 #define MDIO_DEVS_WIS                   MDIO_DEVS_PRESENT(MDIO_MMD_WIS)
102 #define MDIO_DEVS_PCS                   MDIO_DEVS_PRESENT(MDIO_MMD_PCS)
103 #define MDIO_DEVS_PHYXS                 MDIO_DEVS_PRESENT(MDIO_MMD_PHYXS)
104 #define MDIO_DEVS_DTEXS                 MDIO_DEVS_PRESENT(MDIO_MMD_DTEXS)
105 #define MDIO_DEVS_TC                    MDIO_DEVS_PRESENT(MDIO_MMD_TC)
106 #define MDIO_DEVS_AN                    MDIO_DEVS_PRESENT(MDIO_MMD_AN)
107 #define MDIO_DEVS_C22EXT                MDIO_DEVS_PRESENT(MDIO_MMD_C22EXT)
108
109 /* Control register 2. */
110 #define MDIO_PMA_CTRL2_TYPE             0x000f  /* PMA/PMD type selection */
111 #define MDIO_PMA_CTRL2_10GBCX4          0x0000  /* 10GBASE-CX4 type */
112 #define MDIO_PMA_CTRL2_10GBEW           0x0001  /* 10GBASE-EW type */
113 #define MDIO_PMA_CTRL2_10GBLW           0x0002  /* 10GBASE-LW type */
114 #define MDIO_PMA_CTRL2_10GBSW           0x0003  /* 10GBASE-SW type */
115 #define MDIO_PMA_CTRL2_10GBLX4          0x0004  /* 10GBASE-LX4 type */
116 #define MDIO_PMA_CTRL2_10GBER           0x0005  /* 10GBASE-ER type */
117 #define MDIO_PMA_CTRL2_10GBLR           0x0006  /* 10GBASE-LR type */
118 #define MDIO_PMA_CTRL2_10GBSR           0x0007  /* 10GBASE-SR type */
119 #define MDIO_PMA_CTRL2_10GBLRM          0x0008  /* 10GBASE-LRM type */
120 #define MDIO_PMA_CTRL2_10GBT            0x0009  /* 10GBASE-T type */
121 #define MDIO_PMA_CTRL2_10GBKX4          0x000a  /* 10GBASE-KX4 type */
122 #define MDIO_PMA_CTRL2_10GBKR           0x000b  /* 10GBASE-KR type */
123 #define MDIO_PMA_CTRL2_1000BT           0x000c  /* 1000BASE-T type */
124 #define MDIO_PMA_CTRL2_1000BKX          0x000d  /* 1000BASE-KX type */
125 #define MDIO_PMA_CTRL2_100BTX           0x000e  /* 100BASE-TX type */
126 #define MDIO_PMA_CTRL2_10BT             0x000f  /* 10BASE-T type */
127 #define MDIO_PCS_CTRL2_TYPE             0x0003  /* PCS type selection */
128 #define MDIO_PCS_CTRL2_10GBR            0x0000  /* 10GBASE-R type */
129 #define MDIO_PCS_CTRL2_10GBX            0x0001  /* 10GBASE-X type */
130 #define MDIO_PCS_CTRL2_10GBW            0x0002  /* 10GBASE-W type */
131 #define MDIO_PCS_CTRL2_10GBT            0x0003  /* 10GBASE-T type */
132
133 /* Status register 2. */
134 #define MDIO_STAT2_RXFAULT              0x0400  /* Receive fault */
135 #define MDIO_STAT2_TXFAULT              0x0800  /* Transmit fault */
136 #define MDIO_STAT2_DEVPRST              0xc000  /* Device present */
137 #define MDIO_STAT2_DEVPRST_VAL          0x8000  /* Device present value */
138 #define MDIO_PMA_STAT2_LBABLE           0x0001  /* PMA loopback ability */
139 #define MDIO_PMA_STAT2_10GBEW           0x0002  /* 10GBASE-EW ability */
140 #define MDIO_PMA_STAT2_10GBLW           0x0004  /* 10GBASE-LW ability */
141 #define MDIO_PMA_STAT2_10GBSW           0x0008  /* 10GBASE-SW ability */
142 #define MDIO_PMA_STAT2_10GBLX4          0x0010  /* 10GBASE-LX4 ability */
143 #define MDIO_PMA_STAT2_10GBER           0x0020  /* 10GBASE-ER ability */
144 #define MDIO_PMA_STAT2_10GBLR           0x0040  /* 10GBASE-LR ability */
145 #define MDIO_PMA_STAT2_10GBSR           0x0080  /* 10GBASE-SR ability */
146 #define MDIO_PMD_STAT2_TXDISAB          0x0100  /* PMD TX disable ability */
147 #define MDIO_PMA_STAT2_EXTABLE          0x0200  /* Extended abilities */
148 #define MDIO_PMA_STAT2_RXFLTABLE        0x1000  /* Receive fault ability */
149 #define MDIO_PMA_STAT2_TXFLTABLE        0x2000  /* Transmit fault ability */
150 #define MDIO_PCS_STAT2_10GBR            0x0001  /* 10GBASE-R capable */
151 #define MDIO_PCS_STAT2_10GBX            0x0002  /* 10GBASE-X capable */
152 #define MDIO_PCS_STAT2_10GBW            0x0004  /* 10GBASE-W capable */
153 #define MDIO_PCS_STAT2_RXFLTABLE        0x1000  /* Receive fault ability */
154 #define MDIO_PCS_STAT2_TXFLTABLE        0x2000  /* Transmit fault ability */
155
156 /* Transmit disable register. */
157 #define MDIO_PMD_TXDIS_GLOBAL           0x0001  /* Global PMD TX disable */
158 #define MDIO_PMD_TXDIS_0                0x0002  /* PMD TX disable 0 */
159 #define MDIO_PMD_TXDIS_1                0x0004  /* PMD TX disable 1 */
160 #define MDIO_PMD_TXDIS_2                0x0008  /* PMD TX disable 2 */
161 #define MDIO_PMD_TXDIS_3                0x0010  /* PMD TX disable 3 */
162
163 /* Receive signal detect register. */
164 #define MDIO_PMD_RXDET_GLOBAL           0x0001  /* Global PMD RX signal detect */
165 #define MDIO_PMD_RXDET_0                0x0002  /* PMD RX signal detect 0 */
166 #define MDIO_PMD_RXDET_1                0x0004  /* PMD RX signal detect 1 */
167 #define MDIO_PMD_RXDET_2                0x0008  /* PMD RX signal detect 2 */
168 #define MDIO_PMD_RXDET_3                0x0010  /* PMD RX signal detect 3 */
169
170 /* Extended abilities register. */
171 #define MDIO_PMA_EXTABLE_10GCX4         0x0001  /* 10GBASE-CX4 ability */
172 #define MDIO_PMA_EXTABLE_10GBLRM        0x0002  /* 10GBASE-LRM ability */
173 #define MDIO_PMA_EXTABLE_10GBT          0x0004  /* 10GBASE-T ability */
174 #define MDIO_PMA_EXTABLE_10GBKX4        0x0008  /* 10GBASE-KX4 ability */
175 #define MDIO_PMA_EXTABLE_10GBKR         0x0010  /* 10GBASE-KR ability */
176 #define MDIO_PMA_EXTABLE_1000BT         0x0020  /* 1000BASE-T ability */
177 #define MDIO_PMA_EXTABLE_1000BKX        0x0040  /* 1000BASE-KX ability */
178 #define MDIO_PMA_EXTABLE_100BTX         0x0080  /* 100BASE-TX ability */
179 #define MDIO_PMA_EXTABLE_10BT           0x0100  /* 10BASE-T ability */
180
181 /* PHY XGXS lane state register. */
182 #define MDIO_PHYXS_LNSTAT_SYNC0         0x0001
183 #define MDIO_PHYXS_LNSTAT_SYNC1         0x0002
184 #define MDIO_PHYXS_LNSTAT_SYNC2         0x0004
185 #define MDIO_PHYXS_LNSTAT_SYNC3         0x0008
186 #define MDIO_PHYXS_LNSTAT_ALIGN         0x1000
187
188 /* PMA 10GBASE-T TX power register. */
189 #define MDIO_PMA_10GBT_TXPWR_SHORT      0x0001  /* Short-reach mode */
190
191 /* PMA 10GBASE-R FEC ability register. */
192 #define MDIO_PMA_10GBR_FECABLE_ABLE     0x0001  /* FEC ability */
193 #define MDIO_PMA_10GBR_FECABLE_ERRABLE  0x0002  /* FEC error indic. ability */
194
195 /* PCS 10GBASE-R/-T status register 1. */
196 #define MDIO_PCS_10GBRT_STAT1_BLKLK     0x0001  /* Block lock attained */
197
198 /* PCS 10GBASE-R/-T status register 2. */
199 #define MDIO_PCS_10GBRT_STAT2_ERR       0x00ff
200 #define MDIO_PCS_10GBRT_STAT2_BER       0x3f00
201
202 /* AN 10GBASE-T control register. */
203 #define MDIO_AN_10GBT_CTRL_ADV10G       0x1000  /* Advertise 10GBASE-T */
204
205 /* AN 10GBASE-T status register. */
206 #define MDIO_AN_10GBT_STAT_LPTRR        0x0200  /* LP training reset req. */
207 #define MDIO_AN_10GBT_STAT_LPLTABLE     0x0400  /* LP loop timing ability */
208 #define MDIO_AN_10GBT_STAT_LP10G        0x0800  /* LP is 10GBT capable */
209 #define MDIO_AN_10GBT_STAT_REMOK        0x1000  /* Remote OK */
210 #define MDIO_AN_10GBT_STAT_LOCOK        0x2000  /* Local OK */
211 #define MDIO_AN_10GBT_STAT_MS           0x4000  /* Master/slave config */
212 #define MDIO_AN_10GBT_STAT_MSFLT        0x8000  /* Master/slave config fault */
213
214 /* Mapping between MDIO PRTAD/DEVAD and mii_ioctl_data::phy_id */
215
216 #define MDIO_PHY_ID_C45                 0x8000
217 #define MDIO_PHY_ID_PRTAD               0x03e0
218 #define MDIO_PHY_ID_DEVAD               0x001f
219 #define MDIO_PHY_ID_C45_MASK                                            \
220         (MDIO_PHY_ID_C45 | MDIO_PHY_ID_PRTAD | MDIO_PHY_ID_DEVAD)
221
222 static inline __u16 mdio_phy_id_c45(int prtad, int devad)
223 {
224         return MDIO_PHY_ID_C45 | (prtad << 5) | devad;
225 }
226
227 static inline bool mdio_phy_id_is_c45(int phy_id)
228 {
229         return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
230 }
231
232 static inline __u16 mdio_phy_id_prtad(int phy_id)
233 {
234         return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
235 }
236
237 static inline __u16 mdio_phy_id_devad(int phy_id)
238 {
239         return phy_id & MDIO_PHY_ID_DEVAD;
240 }
241
242 #define MDIO_SUPPORTS_C22               1
243 #define MDIO_SUPPORTS_C45               2
244
245 #ifdef __KERNEL__ 
246
247 /**
248  * struct mdio_if_info - Ethernet controller MDIO interface
249  * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
250  * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
251  *      non-zero unless @prtad = %MDIO_PRTAD_NONE.
252  * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
253  *      MII register access will be passed through with @devad =
254  *      %MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
255  *      commonly used clause 22 registers will be translated into
256  *      clause 45 registers.
257  * @dev: Net device structure
258  * @mdio_read: Register read function; returns value or negative error code
259  * @mdio_write: Register write function; returns 0 or negative error code
260  */
261 struct mdio_if_info {
262         int prtad;
263         u32 __bitwise mmds;
264         unsigned mode_support;
265
266         struct net_device *dev;
267         int (*mdio_read)(struct net_device *dev, int prtad, int devad,
268                          u16 addr);
269         int (*mdio_write)(struct net_device *dev, int prtad, int devad,
270                           u16 addr, u16 val);
271 };
272
273 #define MDIO_PRTAD_NONE                 (-1)
274 #define MDIO_DEVAD_NONE                 (-1)
275 #define MDIO_EMULATE_C22                4
276
277 struct ethtool_cmd;
278 struct ethtool_pauseparam;
279 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
280 extern int mdio_set_flag(const struct mdio_if_info *mdio,
281                          int prtad, int devad, u16 addr, int mask,
282                          bool sense);
283 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
284 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
285 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
286                                       struct ethtool_cmd *ecmd,
287                                       u32 npage_adv, u32 npage_lpa);
288 extern void
289 mdio45_ethtool_spauseparam_an(const struct mdio_if_info *mdio,
290                               const struct ethtool_pauseparam *ecmd);
291
292 /**
293  * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
294  * @mdio: MDIO interface
295  * @ecmd: Ethtool request structure
296  *
297  * Since the CSRs for auto-negotiation using next pages are not fully
298  * standardised, this function does not attempt to decode them.  Use
299  * mdio45_ethtool_gset_npage() to specify advertisement bits from next
300  * pages.
301  */
302 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
303                                        struct ethtool_cmd *ecmd)
304 {
305         mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
306 }
307
308 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
309                           struct mii_ioctl_data *mii_data, int cmd);
310
311 #endif /* __KERNEL__ */
312 #endif /* __LINUX_MDIO_H__ */