1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * linux/mii.h: definitions for MII-compatible 3 * linux/mii.h: definitions for MII-compatible transceivers 4 * Originally drivers/net/sunhme.h. 4 * Originally drivers/net/sunhme.h. 5 * 5 * 6 * Copyright (C) 1996, 1999, 2001 David S. Mil 6 * Copyright (C) 1996, 1999, 2001 David S. Miller (davem@redhat.com) 7 */ 7 */ 8 #ifndef __LINUX_MII_H__ 8 #ifndef __LINUX_MII_H__ 9 #define __LINUX_MII_H__ 9 #define __LINUX_MII_H__ 10 10 11 11 12 #include <linux/if.h> 12 #include <linux/if.h> 13 #include <linux/linkmode.h> << 14 #include <uapi/linux/mii.h> 13 #include <uapi/linux/mii.h> 15 14 16 struct ethtool_cmd; 15 struct ethtool_cmd; 17 16 18 struct mii_if_info { 17 struct mii_if_info { 19 int phy_id; 18 int phy_id; 20 int advertising; 19 int advertising; 21 int phy_id_mask; 20 int phy_id_mask; 22 int reg_num_mask; 21 int reg_num_mask; 23 22 24 unsigned int full_duplex : 1; /* is 23 unsigned int full_duplex : 1; /* is full duplex? */ 25 unsigned int force_media : 1; /* is 24 unsigned int force_media : 1; /* is autoneg. disabled? */ 26 unsigned int supports_gmii : 1; /* are 25 unsigned int supports_gmii : 1; /* are GMII registers supported? */ 27 26 28 struct net_device *dev; 27 struct net_device *dev; 29 int (*mdio_read) (struct net_device *d 28 int (*mdio_read) (struct net_device *dev, int phy_id, int location); 30 void (*mdio_write) (struct net_device 29 void (*mdio_write) (struct net_device *dev, int phy_id, int location, int val); 31 }; 30 }; 32 31 33 extern int mii_link_ok (struct mii_if_info *mi 32 extern int mii_link_ok (struct mii_if_info *mii); 34 extern int mii_nway_restart (struct mii_if_inf 33 extern int mii_nway_restart (struct mii_if_info *mii); 35 extern void mii_ethtool_gset(struct mii_if_inf !! 34 extern int mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd); 36 extern void mii_ethtool_get_link_ksettings( 35 extern void mii_ethtool_get_link_ksettings( 37 struct mii_if_info *mii, struct ethtoo 36 struct mii_if_info *mii, struct ethtool_link_ksettings *cmd); 38 extern int mii_ethtool_sset(struct mii_if_info 37 extern int mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd); 39 extern int mii_ethtool_set_link_ksettings( 38 extern int mii_ethtool_set_link_ksettings( 40 struct mii_if_info *mii, const struct 39 struct mii_if_info *mii, const struct ethtool_link_ksettings *cmd); 41 extern int mii_check_gmii_support(struct mii_i 40 extern int mii_check_gmii_support(struct mii_if_info *mii); 42 extern void mii_check_link (struct mii_if_info 41 extern void mii_check_link (struct mii_if_info *mii); 43 extern unsigned int mii_check_media (struct mi 42 extern unsigned int mii_check_media (struct mii_if_info *mii, 44 unsigned 43 unsigned int ok_to_print, 45 unsigned 44 unsigned int init_media); 46 extern int generic_mii_ioctl(struct mii_if_inf 45 extern int generic_mii_ioctl(struct mii_if_info *mii_if, 47 struct mii_ioctl_ 46 struct mii_ioctl_data *mii_data, int cmd, 48 unsigned int *dup 47 unsigned int *duplex_changed); 49 48 50 49 51 static inline struct mii_ioctl_data *if_mii(st 50 static inline struct mii_ioctl_data *if_mii(struct ifreq *rq) 52 { 51 { 53 return (struct mii_ioctl_data *) &rq-> 52 return (struct mii_ioctl_data *) &rq->ifr_ifru; 54 } 53 } 55 54 56 /** 55 /** 57 * mii_nway_result 56 * mii_nway_result 58 * @negotiated: value of MII ANAR and'd with A 57 * @negotiated: value of MII ANAR and'd with ANLPAR 59 * 58 * 60 * Given a set of MII abilities, check each bi 59 * Given a set of MII abilities, check each bit and returns the 61 * currently supported media, in the priority 60 * currently supported media, in the priority order defined by 62 * IEEE 802.3u. We use LPA_xxx constants but 61 * IEEE 802.3u. We use LPA_xxx constants but note this is not the 63 * value of LPA solely, as described above. 62 * value of LPA solely, as described above. 64 * 63 * 65 * The one exception to IEEE 802.3u is that 10 64 * The one exception to IEEE 802.3u is that 100baseT4 is placed 66 * between 100T-full and 100T-half. If your p 65 * between 100T-full and 100T-half. If your phy does not support 67 * 100T4 this is fine. If your phy places 100 66 * 100T4 this is fine. If your phy places 100T4 elsewhere in the 68 * priority order, you will need to roll your 67 * priority order, you will need to roll your own function. 69 */ 68 */ 70 static inline unsigned int mii_nway_result (un 69 static inline unsigned int mii_nway_result (unsigned int negotiated) 71 { 70 { 72 unsigned int ret; 71 unsigned int ret; 73 72 74 if (negotiated & LPA_100FULL) 73 if (negotiated & LPA_100FULL) 75 ret = LPA_100FULL; 74 ret = LPA_100FULL; 76 else if (negotiated & LPA_100BASE4) 75 else if (negotiated & LPA_100BASE4) 77 ret = LPA_100BASE4; 76 ret = LPA_100BASE4; 78 else if (negotiated & LPA_100HALF) 77 else if (negotiated & LPA_100HALF) 79 ret = LPA_100HALF; 78 ret = LPA_100HALF; 80 else if (negotiated & LPA_10FULL) 79 else if (negotiated & LPA_10FULL) 81 ret = LPA_10FULL; 80 ret = LPA_10FULL; 82 else 81 else 83 ret = LPA_10HALF; 82 ret = LPA_10HALF; 84 83 85 return ret; 84 return ret; 86 } 85 } 87 86 88 /** 87 /** 89 * mii_duplex 88 * mii_duplex 90 * @duplex_lock: Non-zero if duplex is locked 89 * @duplex_lock: Non-zero if duplex is locked at full 91 * @negotiated: value of MII ANAR and'd with A 90 * @negotiated: value of MII ANAR and'd with ANLPAR 92 * 91 * 93 * A small helper function for a common case. 92 * A small helper function for a common case. Returns one 94 * if the media is operating or locked at full 93 * if the media is operating or locked at full duplex, and 95 * returns zero otherwise. 94 * returns zero otherwise. 96 */ 95 */ 97 static inline unsigned int mii_duplex (unsigne 96 static inline unsigned int mii_duplex (unsigned int duplex_lock, 98 unsigne 97 unsigned int negotiated) 99 { 98 { 100 if (duplex_lock) 99 if (duplex_lock) 101 return 1; 100 return 1; 102 if (mii_nway_result(negotiated) & LPA_ 101 if (mii_nway_result(negotiated) & LPA_DUPLEX) 103 return 1; 102 return 1; 104 return 0; 103 return 0; 105 } 104 } 106 105 107 /** 106 /** 108 * ethtool_adv_to_mii_adv_t 107 * ethtool_adv_to_mii_adv_t 109 * @ethadv: the ethtool advertisement settings 108 * @ethadv: the ethtool advertisement settings 110 * 109 * 111 * A small helper function that translates eth 110 * A small helper function that translates ethtool advertisement 112 * settings to phy autonegotiation advertiseme 111 * settings to phy autonegotiation advertisements for the 113 * MII_ADVERTISE register. 112 * MII_ADVERTISE register. 114 */ 113 */ 115 static inline u32 ethtool_adv_to_mii_adv_t(u32 114 static inline u32 ethtool_adv_to_mii_adv_t(u32 ethadv) 116 { 115 { 117 u32 result = 0; 116 u32 result = 0; 118 117 119 if (ethadv & ADVERTISED_10baseT_Half) 118 if (ethadv & ADVERTISED_10baseT_Half) 120 result |= ADVERTISE_10HALF; 119 result |= ADVERTISE_10HALF; 121 if (ethadv & ADVERTISED_10baseT_Full) 120 if (ethadv & ADVERTISED_10baseT_Full) 122 result |= ADVERTISE_10FULL; 121 result |= ADVERTISE_10FULL; 123 if (ethadv & ADVERTISED_100baseT_Half) 122 if (ethadv & ADVERTISED_100baseT_Half) 124 result |= ADVERTISE_100HALF; 123 result |= ADVERTISE_100HALF; 125 if (ethadv & ADVERTISED_100baseT_Full) 124 if (ethadv & ADVERTISED_100baseT_Full) 126 result |= ADVERTISE_100FULL; 125 result |= ADVERTISE_100FULL; 127 if (ethadv & ADVERTISED_Pause) 126 if (ethadv & ADVERTISED_Pause) 128 result |= ADVERTISE_PAUSE_CAP; 127 result |= ADVERTISE_PAUSE_CAP; 129 if (ethadv & ADVERTISED_Asym_Pause) 128 if (ethadv & ADVERTISED_Asym_Pause) 130 result |= ADVERTISE_PAUSE_ASYM 129 result |= ADVERTISE_PAUSE_ASYM; 131 130 132 return result; 131 return result; 133 } 132 } 134 133 135 /** 134 /** 136 * linkmode_adv_to_mii_adv_t << 137 * @advertising: the linkmode advertisement se << 138 * << 139 * A small helper function that translates lin << 140 * settings to phy autonegotiation advertiseme << 141 * MII_ADVERTISE register. << 142 */ << 143 static inline u32 linkmode_adv_to_mii_adv_t(co << 144 { << 145 u32 result = 0; << 146 << 147 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 148 result |= ADVERTISE_10HALF; << 149 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 150 result |= ADVERTISE_10FULL; << 151 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 152 result |= ADVERTISE_100HALF; << 153 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 154 result |= ADVERTISE_100FULL; << 155 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 156 result |= ADVERTISE_PAUSE_CAP; << 157 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 158 result |= ADVERTISE_PAUSE_ASYM << 159 << 160 return result; << 161 } << 162 << 163 /** << 164 * mii_adv_to_ethtool_adv_t 135 * mii_adv_to_ethtool_adv_t 165 * @adv: value of the MII_ADVERTISE register 136 * @adv: value of the MII_ADVERTISE register 166 * 137 * 167 * A small helper function that translates MII 138 * A small helper function that translates MII_ADVERTISE bits 168 * to ethtool advertisement settings. 139 * to ethtool advertisement settings. 169 */ 140 */ 170 static inline u32 mii_adv_to_ethtool_adv_t(u32 141 static inline u32 mii_adv_to_ethtool_adv_t(u32 adv) 171 { 142 { 172 u32 result = 0; 143 u32 result = 0; 173 144 174 if (adv & ADVERTISE_10HALF) 145 if (adv & ADVERTISE_10HALF) 175 result |= ADVERTISED_10baseT_H 146 result |= ADVERTISED_10baseT_Half; 176 if (adv & ADVERTISE_10FULL) 147 if (adv & ADVERTISE_10FULL) 177 result |= ADVERTISED_10baseT_F 148 result |= ADVERTISED_10baseT_Full; 178 if (adv & ADVERTISE_100HALF) 149 if (adv & ADVERTISE_100HALF) 179 result |= ADVERTISED_100baseT_ 150 result |= ADVERTISED_100baseT_Half; 180 if (adv & ADVERTISE_100FULL) 151 if (adv & ADVERTISE_100FULL) 181 result |= ADVERTISED_100baseT_ 152 result |= ADVERTISED_100baseT_Full; 182 if (adv & ADVERTISE_PAUSE_CAP) 153 if (adv & ADVERTISE_PAUSE_CAP) 183 result |= ADVERTISED_Pause; 154 result |= ADVERTISED_Pause; 184 if (adv & ADVERTISE_PAUSE_ASYM) 155 if (adv & ADVERTISE_PAUSE_ASYM) 185 result |= ADVERTISED_Asym_Paus 156 result |= ADVERTISED_Asym_Pause; 186 157 187 return result; 158 return result; 188 } 159 } 189 160 190 /** 161 /** 191 * ethtool_adv_to_mii_ctrl1000_t 162 * ethtool_adv_to_mii_ctrl1000_t 192 * @ethadv: the ethtool advertisement settings 163 * @ethadv: the ethtool advertisement settings 193 * 164 * 194 * A small helper function that translates eth 165 * A small helper function that translates ethtool advertisement 195 * settings to phy autonegotiation advertiseme 166 * settings to phy autonegotiation advertisements for the 196 * MII_CTRL1000 register when in 1000T mode. 167 * MII_CTRL1000 register when in 1000T mode. 197 */ 168 */ 198 static inline u32 ethtool_adv_to_mii_ctrl1000_ 169 static inline u32 ethtool_adv_to_mii_ctrl1000_t(u32 ethadv) 199 { 170 { 200 u32 result = 0; 171 u32 result = 0; 201 172 202 if (ethadv & ADVERTISED_1000baseT_Half 173 if (ethadv & ADVERTISED_1000baseT_Half) 203 result |= ADVERTISE_1000HALF; 174 result |= ADVERTISE_1000HALF; 204 if (ethadv & ADVERTISED_1000baseT_Full 175 if (ethadv & ADVERTISED_1000baseT_Full) 205 result |= ADVERTISE_1000FULL; 176 result |= ADVERTISE_1000FULL; 206 177 207 return result; 178 return result; 208 } 179 } 209 180 210 /** 181 /** 211 * linkmode_adv_to_mii_ctrl1000_t << 212 * @advertising: the linkmode advertisement se << 213 * << 214 * A small helper function that translates lin << 215 * settings to phy autonegotiation advertiseme << 216 * MII_CTRL1000 register when in 1000T mode. << 217 */ << 218 static inline u32 << 219 linkmode_adv_to_mii_ctrl1000_t(const unsigned << 220 { << 221 u32 result = 0; << 222 << 223 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 224 advertising)) << 225 result |= ADVERTISE_1000HALF; << 226 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 227 advertising)) << 228 result |= ADVERTISE_1000FULL; << 229 << 230 return result; << 231 } << 232 << 233 /** << 234 * mii_ctrl1000_to_ethtool_adv_t 182 * mii_ctrl1000_to_ethtool_adv_t 235 * @adv: value of the MII_CTRL1000 register 183 * @adv: value of the MII_CTRL1000 register 236 * 184 * 237 * A small helper function that translates MII 185 * A small helper function that translates MII_CTRL1000 238 * bits, when in 1000Base-T mode, to ethtool 186 * bits, when in 1000Base-T mode, to ethtool 239 * advertisement settings. 187 * advertisement settings. 240 */ 188 */ 241 static inline u32 mii_ctrl1000_to_ethtool_adv_ 189 static inline u32 mii_ctrl1000_to_ethtool_adv_t(u32 adv) 242 { 190 { 243 u32 result = 0; 191 u32 result = 0; 244 192 245 if (adv & ADVERTISE_1000HALF) 193 if (adv & ADVERTISE_1000HALF) 246 result |= ADVERTISED_1000baseT 194 result |= ADVERTISED_1000baseT_Half; 247 if (adv & ADVERTISE_1000FULL) 195 if (adv & ADVERTISE_1000FULL) 248 result |= ADVERTISED_1000baseT 196 result |= ADVERTISED_1000baseT_Full; 249 197 250 return result; 198 return result; 251 } 199 } 252 200 253 /** 201 /** 254 * mii_lpa_to_ethtool_lpa_t 202 * mii_lpa_to_ethtool_lpa_t 255 * @adv: value of the MII_LPA register 203 * @adv: value of the MII_LPA register 256 * 204 * 257 * A small helper function that translates MII 205 * A small helper function that translates MII_LPA 258 * bits, when in 1000Base-T mode, to ethtool 206 * bits, when in 1000Base-T mode, to ethtool 259 * LP advertisement settings. 207 * LP advertisement settings. 260 */ 208 */ 261 static inline u32 mii_lpa_to_ethtool_lpa_t(u32 209 static inline u32 mii_lpa_to_ethtool_lpa_t(u32 lpa) 262 { 210 { 263 u32 result = 0; 211 u32 result = 0; 264 212 265 if (lpa & LPA_LPACK) 213 if (lpa & LPA_LPACK) 266 result |= ADVERTISED_Autoneg; 214 result |= ADVERTISED_Autoneg; 267 215 268 return result | mii_adv_to_ethtool_adv 216 return result | mii_adv_to_ethtool_adv_t(lpa); 269 } 217 } 270 218 271 /** 219 /** 272 * mii_stat1000_to_ethtool_lpa_t 220 * mii_stat1000_to_ethtool_lpa_t 273 * @adv: value of the MII_STAT1000 register 221 * @adv: value of the MII_STAT1000 register 274 * 222 * 275 * A small helper function that translates MII 223 * A small helper function that translates MII_STAT1000 276 * bits, when in 1000Base-T mode, to ethtool 224 * bits, when in 1000Base-T mode, to ethtool 277 * advertisement settings. 225 * advertisement settings. 278 */ 226 */ 279 static inline u32 mii_stat1000_to_ethtool_lpa_ 227 static inline u32 mii_stat1000_to_ethtool_lpa_t(u32 lpa) 280 { 228 { 281 u32 result = 0; 229 u32 result = 0; 282 230 283 if (lpa & LPA_1000HALF) 231 if (lpa & LPA_1000HALF) 284 result |= ADVERTISED_1000baseT 232 result |= ADVERTISED_1000baseT_Half; 285 if (lpa & LPA_1000FULL) 233 if (lpa & LPA_1000FULL) 286 result |= ADVERTISED_1000baseT 234 result |= ADVERTISED_1000baseT_Full; 287 235 288 return result; 236 return result; 289 } 237 } 290 238 291 /** 239 /** 292 * mii_stat1000_mod_linkmode_lpa_t << 293 * @advertising: target the linkmode advertise << 294 * @adv: value of the MII_STAT1000 register << 295 * << 296 * A small helper function that translates MII << 297 * 1000Base-T mode, to linkmode advertisement << 298 * advertising are not changes. << 299 */ << 300 static inline void mii_stat1000_mod_linkmode_l << 301 << 302 { << 303 linkmode_mod_bit(ETHTOOL_LINK_MODE_100 << 304 advertising, lpa & LP << 305 << 306 linkmode_mod_bit(ETHTOOL_LINK_MODE_100 << 307 advertising, lpa & LP << 308 } << 309 << 310 /** << 311 * ethtool_adv_to_mii_adv_x 240 * ethtool_adv_to_mii_adv_x 312 * @ethadv: the ethtool advertisement settings 241 * @ethadv: the ethtool advertisement settings 313 * 242 * 314 * A small helper function that translates eth 243 * A small helper function that translates ethtool advertisement 315 * settings to phy autonegotiation advertiseme 244 * settings to phy autonegotiation advertisements for the 316 * MII_CTRL1000 register when in 1000Base-X mo 245 * MII_CTRL1000 register when in 1000Base-X mode. 317 */ 246 */ 318 static inline u32 ethtool_adv_to_mii_adv_x(u32 247 static inline u32 ethtool_adv_to_mii_adv_x(u32 ethadv) 319 { 248 { 320 u32 result = 0; 249 u32 result = 0; 321 250 322 if (ethadv & ADVERTISED_1000baseT_Half 251 if (ethadv & ADVERTISED_1000baseT_Half) 323 result |= ADVERTISE_1000XHALF; 252 result |= ADVERTISE_1000XHALF; 324 if (ethadv & ADVERTISED_1000baseT_Full 253 if (ethadv & ADVERTISED_1000baseT_Full) 325 result |= ADVERTISE_1000XFULL; 254 result |= ADVERTISE_1000XFULL; 326 if (ethadv & ADVERTISED_Pause) 255 if (ethadv & ADVERTISED_Pause) 327 result |= ADVERTISE_1000XPAUSE 256 result |= ADVERTISE_1000XPAUSE; 328 if (ethadv & ADVERTISED_Asym_Pause) 257 if (ethadv & ADVERTISED_Asym_Pause) 329 result |= ADVERTISE_1000XPSE_A 258 result |= ADVERTISE_1000XPSE_ASYM; 330 259 331 return result; 260 return result; 332 } 261 } 333 262 334 /** 263 /** 335 * mii_adv_to_ethtool_adv_x 264 * mii_adv_to_ethtool_adv_x 336 * @adv: value of the MII_CTRL1000 register 265 * @adv: value of the MII_CTRL1000 register 337 * 266 * 338 * A small helper function that translates MII 267 * A small helper function that translates MII_CTRL1000 339 * bits, when in 1000Base-X mode, to ethtool 268 * bits, when in 1000Base-X mode, to ethtool 340 * advertisement settings. 269 * advertisement settings. 341 */ 270 */ 342 static inline u32 mii_adv_to_ethtool_adv_x(u32 271 static inline u32 mii_adv_to_ethtool_adv_x(u32 adv) 343 { 272 { 344 u32 result = 0; 273 u32 result = 0; 345 274 346 if (adv & ADVERTISE_1000XHALF) 275 if (adv & ADVERTISE_1000XHALF) 347 result |= ADVERTISED_1000baseT 276 result |= ADVERTISED_1000baseT_Half; 348 if (adv & ADVERTISE_1000XFULL) 277 if (adv & ADVERTISE_1000XFULL) 349 result |= ADVERTISED_1000baseT 278 result |= ADVERTISED_1000baseT_Full; 350 if (adv & ADVERTISE_1000XPAUSE) 279 if (adv & ADVERTISE_1000XPAUSE) 351 result |= ADVERTISED_Pause; 280 result |= ADVERTISED_Pause; 352 if (adv & ADVERTISE_1000XPSE_ASYM) 281 if (adv & ADVERTISE_1000XPSE_ASYM) 353 result |= ADVERTISED_Asym_Paus 282 result |= ADVERTISED_Asym_Pause; 354 283 355 return result; 284 return result; 356 } 285 } 357 286 358 /** 287 /** 359 * mii_adv_mod_linkmode_adv_t !! 288 * mii_lpa_to_ethtool_lpa_x 360 * @advertising:pointer to destination link mo << 361 * @adv: value of the MII_ADVERTISE register << 362 * << 363 * A small helper function that translates MII << 364 * linkmode advertisement settings. Leaves oth << 365 */ << 366 static inline void mii_adv_mod_linkmode_adv_t( << 367 << 368 { << 369 linkmode_mod_bit(ETHTOOL_LINK_MODE_10b << 370 advertising, adv & AD << 371 << 372 linkmode_mod_bit(ETHTOOL_LINK_MODE_10b << 373 advertising, adv & AD << 374 << 375 linkmode_mod_bit(ETHTOOL_LINK_MODE_100 << 376 advertising, adv & AD << 377 << 378 linkmode_mod_bit(ETHTOOL_LINK_MODE_100 << 379 advertising, adv & AD << 380 << 381 linkmode_mod_bit(ETHTOOL_LINK_MODE_Pau << 382 adv & ADVERTISE_PAUSE << 383 << 384 linkmode_mod_bit(ETHTOOL_LINK_MODE_Asy << 385 advertising, adv & AD << 386 } << 387 << 388 /** << 389 * mii_adv_to_linkmode_adv_t << 390 * @advertising:pointer to destination link mo << 391 * @adv: value of the MII_ADVERTISE register << 392 * << 393 * A small helper function that translates MII << 394 * to linkmode advertisement settings. Clears << 395 * of advertising. << 396 */ << 397 static inline void mii_adv_to_linkmode_adv_t(u << 398 u << 399 { << 400 linkmode_zero(advertising); << 401 << 402 mii_adv_mod_linkmode_adv_t(advertising << 403 } << 404 << 405 /** << 406 * mii_lpa_to_linkmode_lpa_t << 407 * @adv: value of the MII_LPA register 289 * @adv: value of the MII_LPA register 408 * 290 * 409 * A small helper function that translates MII !! 291 * A small helper function that translates MII_LPA 410 * 1000Base-T mode, to linkmode LP advertiseme !! 292 * bits, when in 1000Base-X mode, to ethtool 411 * old value of advertising !! 293 * LP advertisement settings. 412 */ 294 */ 413 static inline void mii_lpa_to_linkmode_lpa_t(u !! 295 static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa) 414 u << 415 { 296 { 416 mii_adv_to_linkmode_adv_t(lp_advertisi !! 297 u32 result = 0; 417 298 418 if (lpa & LPA_LPACK) 299 if (lpa & LPA_LPACK) 419 linkmode_set_bit(ETHTOOL_LINK_ !! 300 result |= ADVERTISED_Autoneg; 420 lp_advertisin << 421 << 422 } << 423 << 424 /** << 425 * mii_lpa_mod_linkmode_lpa_t << 426 * @adv: value of the MII_LPA register << 427 * << 428 * A small helper function that translates MII << 429 * 1000Base-T mode, to linkmode LP advertiseme << 430 * other bits unchanged. << 431 */ << 432 static inline void mii_lpa_mod_linkmode_lpa_t( << 433 << 434 { << 435 mii_adv_mod_linkmode_adv_t(lp_advertis << 436 << 437 linkmode_mod_bit(ETHTOOL_LINK_MODE_Aut << 438 lp_advertising, lpa & << 439 } << 440 << 441 static inline void mii_ctrl1000_mod_linkmode_a << 442 << 443 { << 444 linkmode_mod_bit(ETHTOOL_LINK_MODE_100 << 445 ctrl1000 & ADVERTISE_ << 446 linkmode_mod_bit(ETHTOOL_LINK_MODE_100 << 447 ctrl1000 & ADVERTISE_ << 448 } << 449 << 450 /** << 451 * linkmode_adv_to_lcl_adv_t << 452 * @advertising:pointer to linkmode advertisin << 453 * << 454 * A small helper function that translates lin << 455 * pause capabilities. << 456 */ << 457 static inline u32 linkmode_adv_to_lcl_adv_t(co << 458 { << 459 u32 lcl_adv = 0; << 460 << 461 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 462 advertising)) << 463 lcl_adv |= ADVERTISE_PAUSE_CAP << 464 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 465 advertising)) << 466 lcl_adv |= ADVERTISE_PAUSE_ASY << 467 << 468 return lcl_adv; << 469 } << 470 << 471 /** << 472 * mii_lpa_mod_linkmode_x - decode the link pa << 473 * @linkmodes: link modes array << 474 * @lpa: config_reg word from link partner << 475 * @fd_bit: link mode for 1000XFULL bit << 476 */ << 477 static inline void mii_lpa_mod_linkmode_x(unsi << 478 int f << 479 { << 480 linkmode_mod_bit(ETHTOOL_LINK_MODE_Aut << 481 lpa & LPA_LPACK); << 482 linkmode_mod_bit(ETHTOOL_LINK_MODE_Pau << 483 lpa & LPA_1000XPAUSE) << 484 linkmode_mod_bit(ETHTOOL_LINK_MODE_Asy << 485 lpa & LPA_1000XPAUSE_ << 486 linkmode_mod_bit(fd_bit, linkmodes, << 487 lpa & LPA_1000XFULL); << 488 } << 489 << 490 /** << 491 * linkmode_adv_to_mii_adv_x - encode a linkmo << 492 * @linkmodes: linkmodes << 493 * @fd_bit: full duplex bit << 494 */ << 495 static inline u16 linkmode_adv_to_mii_adv_x(co << 496 in << 497 { << 498 u16 adv = 0; << 499 << 500 if (linkmode_test_bit(fd_bit, linkmode << 501 adv |= ADVERTISE_1000XFULL; << 502 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 503 adv |= ADVERTISE_1000XPAUSE; << 504 if (linkmode_test_bit(ETHTOOL_LINK_MOD << 505 adv |= ADVERTISE_1000XPSE_ASYM << 506 301 507 return adv; !! 302 return result | mii_adv_to_ethtool_adv_x(lpa); 508 } 303 } 509 304 510 /** 305 /** 511 * mii_advertise_flowctrl - get flow control a 306 * mii_advertise_flowctrl - get flow control advertisement flags 512 * @cap: Flow control capabilities (FLOW_CTRL_ 307 * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both) 513 */ 308 */ 514 static inline u16 mii_advertise_flowctrl(int c 309 static inline u16 mii_advertise_flowctrl(int cap) 515 { 310 { 516 u16 adv = 0; 311 u16 adv = 0; 517 312 518 if (cap & FLOW_CTRL_RX) 313 if (cap & FLOW_CTRL_RX) 519 adv = ADVERTISE_PAUSE_CAP | AD 314 adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; 520 if (cap & FLOW_CTRL_TX) 315 if (cap & FLOW_CTRL_TX) 521 adv ^= ADVERTISE_PAUSE_ASYM; 316 adv ^= ADVERTISE_PAUSE_ASYM; 522 317 523 return adv; 318 return adv; 524 } 319 } 525 320 526 /** 321 /** 527 * mii_resolve_flowctrl_fdx 322 * mii_resolve_flowctrl_fdx 528 * @lcladv: value of MII ADVERTISE register 323 * @lcladv: value of MII ADVERTISE register 529 * @rmtadv: value of MII LPA register 324 * @rmtadv: value of MII LPA register 530 * 325 * 531 * Resolve full duplex flow control as per IEE 326 * Resolve full duplex flow control as per IEEE 802.3-2005 table 28B-3 532 */ 327 */ 533 static inline u8 mii_resolve_flowctrl_fdx(u16 328 static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv) 534 { 329 { 535 u8 cap = 0; 330 u8 cap = 0; 536 331 537 if (lcladv & rmtadv & ADVERTISE_PAUSE_ 332 if (lcladv & rmtadv & ADVERTISE_PAUSE_CAP) { 538 cap = FLOW_CTRL_TX | FLOW_CTRL 333 cap = FLOW_CTRL_TX | FLOW_CTRL_RX; 539 } else if (lcladv & rmtadv & ADVERTISE 334 } else if (lcladv & rmtadv & ADVERTISE_PAUSE_ASYM) { 540 if (lcladv & ADVERTISE_PAUSE_C 335 if (lcladv & ADVERTISE_PAUSE_CAP) 541 cap = FLOW_CTRL_RX; 336 cap = FLOW_CTRL_RX; 542 else if (rmtadv & ADVERTISE_PA 337 else if (rmtadv & ADVERTISE_PAUSE_CAP) 543 cap = FLOW_CTRL_TX; 338 cap = FLOW_CTRL_TX; 544 } 339 } 545 340 546 return cap; 341 return cap; 547 } << 548 << 549 /** << 550 * mii_bmcr_encode_fixed - encode fixed speed/ << 551 * @speed: a SPEED_* value << 552 * @duplex: a DUPLEX_* value << 553 * << 554 * Encode the speed and duplex to a BMCR value << 555 * supported. 2500Mbps is encoded to 1000Mbps. << 556 * Mbps. Unknown duplex values are encoded to << 557 */ << 558 static inline u16 mii_bmcr_encode_fixed(int sp << 559 { << 560 u16 bmcr; << 561 << 562 switch (speed) { << 563 case SPEED_2500: << 564 case SPEED_1000: << 565 bmcr = BMCR_SPEED1000; << 566 break; << 567 << 568 case SPEED_100: << 569 bmcr = BMCR_SPEED100; << 570 break; << 571 << 572 case SPEED_10: << 573 default: << 574 bmcr = BMCR_SPEED10; << 575 break; << 576 } << 577 << 578 if (duplex == DUPLEX_FULL) << 579 bmcr |= BMCR_FULLDPLX; << 580 << 581 return bmcr; << 582 } 342 } 583 343 584 #endif /* __LINUX_MII_H__ */ 344 #endif /* __LINUX_MII_H__ */ 585 345
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.