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