diff options
author | Matt Carlson <mcarlson@broadcom.com> | 2011-11-16 18:36:59 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-11-16 18:36:59 -0500 |
commit | 28011cf19b75df9d3f35489a7599a97ec0b3f1a0 (patch) | |
tree | cc058e15191db60adb45e426fc3d328e9d246b41 /include/linux/mii.h | |
parent | f85fa279138489543206381883c8f67ef94aa912 (diff) |
net: Add ethtool to mii advertisment conversion helpers
Translating between ethtool advertisement settings and MII
advertisements are common operations for ethernet drivers. This patch
adds a set of helper functions that implements the conversion. The
patch then modifies a couple of the drivers to use the new functions.
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/mii.h')
-rw-r--r-- | include/linux/mii.h | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/include/linux/mii.h b/include/linux/mii.h index 27748230aa69..6697b9112014 100644 --- a/include/linux/mii.h +++ b/include/linux/mii.h | |||
@@ -9,6 +9,7 @@ | |||
9 | #define __LINUX_MII_H__ | 9 | #define __LINUX_MII_H__ |
10 | 10 | ||
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <linux/ethtool.h> | ||
12 | 13 | ||
13 | /* Generic MII registers. */ | 14 | /* Generic MII registers. */ |
14 | #define MII_BMCR 0x00 /* Basic mode control register */ | 15 | #define MII_BMCR 0x00 /* Basic mode control register */ |
@@ -240,6 +241,171 @@ static inline unsigned int mii_duplex (unsigned int duplex_lock, | |||
240 | } | 241 | } |
241 | 242 | ||
242 | /** | 243 | /** |
244 | * ethtool_adv_to_mii_100bt | ||
245 | * @ethadv: the ethtool advertisement settings | ||
246 | * | ||
247 | * A small helper function that translates ethtool advertisement | ||
248 | * settings to phy autonegotiation advertisements for the | ||
249 | * MII_ADVERTISE register. | ||
250 | */ | ||
251 | static inline u32 ethtool_adv_to_mii_100bt(u32 ethadv) | ||
252 | { | ||
253 | u32 result = 0; | ||
254 | |||
255 | if (ethadv & ADVERTISED_10baseT_Half) | ||
256 | result |= ADVERTISE_10HALF; | ||
257 | if (ethadv & ADVERTISED_10baseT_Full) | ||
258 | result |= ADVERTISE_10FULL; | ||
259 | if (ethadv & ADVERTISED_100baseT_Half) | ||
260 | result |= ADVERTISE_100HALF; | ||
261 | if (ethadv & ADVERTISED_100baseT_Full) | ||
262 | result |= ADVERTISE_100FULL; | ||
263 | if (ethadv & ADVERTISED_Pause) | ||
264 | result |= ADVERTISE_PAUSE_CAP; | ||
265 | if (ethadv & ADVERTISED_Asym_Pause) | ||
266 | result |= ADVERTISE_PAUSE_ASYM; | ||
267 | |||
268 | return result; | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * mii_adv_to_ethtool_100bt | ||
273 | * @adv: value of the MII_ADVERTISE register | ||
274 | * | ||
275 | * A small helper function that translates MII_ADVERTISE bits | ||
276 | * to ethtool advertisement settings. | ||
277 | */ | ||
278 | static inline u32 mii_adv_to_ethtool_100bt(u32 adv) | ||
279 | { | ||
280 | u32 result = 0; | ||
281 | |||
282 | if (adv & ADVERTISE_10HALF) | ||
283 | result |= ADVERTISED_10baseT_Half; | ||
284 | if (adv & ADVERTISE_10FULL) | ||
285 | result |= ADVERTISED_10baseT_Full; | ||
286 | if (adv & ADVERTISE_100HALF) | ||
287 | result |= ADVERTISED_100baseT_Half; | ||
288 | if (adv & ADVERTISE_100FULL) | ||
289 | result |= ADVERTISED_100baseT_Full; | ||
290 | if (adv & ADVERTISE_PAUSE_CAP) | ||
291 | result |= ADVERTISED_Pause; | ||
292 | if (adv & ADVERTISE_PAUSE_ASYM) | ||
293 | result |= ADVERTISED_Asym_Pause; | ||
294 | |||
295 | return result; | ||
296 | } | ||
297 | |||
298 | /** | ||
299 | * ethtool_adv_to_mii_1000T | ||
300 | * @ethadv: the ethtool advertisement settings | ||
301 | * | ||
302 | * A small helper function that translates ethtool advertisement | ||
303 | * settings to phy autonegotiation advertisements for the | ||
304 | * MII_CTRL1000 register when in 1000T mode. | ||
305 | */ | ||
306 | static inline u32 ethtool_adv_to_mii_1000T(u32 ethadv) | ||
307 | { | ||
308 | u32 result = 0; | ||
309 | |||
310 | if (ethadv & ADVERTISED_1000baseT_Half) | ||
311 | result |= ADVERTISE_1000HALF; | ||
312 | if (ethadv & ADVERTISED_1000baseT_Full) | ||
313 | result |= ADVERTISE_1000FULL; | ||
314 | |||
315 | return result; | ||
316 | } | ||
317 | |||
318 | /** | ||
319 | * mii_adv_to_ethtool_1000T | ||
320 | * @adv: value of the MII_CTRL1000 register | ||
321 | * | ||
322 | * A small helper function that translates MII_CTRL1000 | ||
323 | * bits, when in 1000Base-T mode, to ethtool | ||
324 | * advertisement settings. | ||
325 | */ | ||
326 | static inline u32 mii_adv_to_ethtool_1000T(u32 adv) | ||
327 | { | ||
328 | u32 result = 0; | ||
329 | |||
330 | if (adv & ADVERTISE_1000HALF) | ||
331 | result |= ADVERTISED_1000baseT_Half; | ||
332 | if (adv & ADVERTISE_1000FULL) | ||
333 | result |= ADVERTISED_1000baseT_Full; | ||
334 | |||
335 | return result; | ||
336 | } | ||
337 | |||
338 | #define mii_lpa_to_ethtool_100bt(lpa) mii_adv_to_ethtool_100bt(lpa) | ||
339 | |||
340 | /** | ||
341 | * mii_lpa_to_ethtool_1000T | ||
342 | * @adv: value of the MII_STAT1000 register | ||
343 | * | ||
344 | * A small helper function that translates MII_STAT1000 | ||
345 | * bits, when in 1000Base-T mode, to ethtool | ||
346 | * advertisement settings. | ||
347 | */ | ||
348 | static inline u32 mii_lpa_to_ethtool_1000T(u32 lpa) | ||
349 | { | ||
350 | u32 result = 0; | ||
351 | |||
352 | if (lpa & LPA_1000HALF) | ||
353 | result |= ADVERTISED_1000baseT_Half; | ||
354 | if (lpa & LPA_1000FULL) | ||
355 | result |= ADVERTISED_1000baseT_Full; | ||
356 | |||
357 | return result; | ||
358 | } | ||
359 | |||
360 | /** | ||
361 | * ethtool_adv_to_mii_1000X | ||
362 | * @ethadv: the ethtool advertisement settings | ||
363 | * | ||
364 | * A small helper function that translates ethtool advertisement | ||
365 | * settings to phy autonegotiation advertisements for the | ||
366 | * MII_CTRL1000 register when in 1000Base-X mode. | ||
367 | */ | ||
368 | static inline u32 ethtool_adv_to_mii_1000X(u32 ethadv) | ||
369 | { | ||
370 | u32 result = 0; | ||
371 | |||
372 | if (ethadv & ADVERTISED_1000baseT_Half) | ||
373 | result |= ADVERTISE_1000XHALF; | ||
374 | if (ethadv & ADVERTISED_1000baseT_Full) | ||
375 | result |= ADVERTISE_1000XFULL; | ||
376 | if (ethadv & ADVERTISED_Pause) | ||
377 | result |= ADVERTISE_1000XPAUSE; | ||
378 | if (ethadv & ADVERTISED_Asym_Pause) | ||
379 | result |= ADVERTISE_1000XPSE_ASYM; | ||
380 | |||
381 | return result; | ||
382 | } | ||
383 | |||
384 | /** | ||
385 | * mii_adv_to_ethtool_1000X | ||
386 | * @adv: value of the MII_CTRL1000 register | ||
387 | * | ||
388 | * A small helper function that translates MII_CTRL1000 | ||
389 | * bits, when in 1000Base-X mode, to ethtool | ||
390 | * advertisement settings. | ||
391 | */ | ||
392 | static inline u32 mii_adv_to_ethtool_1000X(u32 adv) | ||
393 | { | ||
394 | u32 result = 0; | ||
395 | |||
396 | if (adv & ADVERTISE_1000XHALF) | ||
397 | result |= ADVERTISED_1000baseT_Half; | ||
398 | if (adv & ADVERTISE_1000XFULL) | ||
399 | result |= ADVERTISED_1000baseT_Full; | ||
400 | if (adv & ADVERTISE_1000XPAUSE) | ||
401 | result |= ADVERTISED_Pause; | ||
402 | if (adv & ADVERTISE_1000XPSE_ASYM) | ||
403 | result |= ADVERTISED_Asym_Pause; | ||
404 | |||
405 | return result; | ||
406 | } | ||
407 | |||
408 | /** | ||
243 | * mii_advertise_flowctrl - get flow control advertisement flags | 409 | * mii_advertise_flowctrl - get flow control advertisement flags |
244 | * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both) | 410 | * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both) |
245 | */ | 411 | */ |