1
2
3
4
5
6
7
8
9
10
11#ifndef __PHY_H
12#define __PHY_H
13
14#include <linux/compiler.h>
15#include <linux/spinlock.h>
16#include <linux/ethtool.h>
17#include <linux/linkmode.h>
18#include <linux/netlink.h>
19#include <linux/mdio.h>
20#include <linux/mii.h>
21#include <linux/mii_timestamper.h>
22#include <linux/module.h>
23#include <linux/timer.h>
24#include <linux/workqueue.h>
25#include <linux/mod_devicetable.h>
26#include <linux/u64_stats_sync.h>
27#include <linux/irqreturn.h>
28#include <linux/iopoll.h>
29#include <linux/refcount.h>
30
31#include <linux/atomic.h>
32
33#define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
34 SUPPORTED_TP | \
35 SUPPORTED_MII)
36
37#define PHY_10BT_FEATURES (SUPPORTED_10baseT_Half | \
38 SUPPORTED_10baseT_Full)
39
40#define PHY_100BT_FEATURES (SUPPORTED_100baseT_Half | \
41 SUPPORTED_100baseT_Full)
42
43#define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \
44 SUPPORTED_1000baseT_Full)
45
46extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_features) __ro_after_init;
47extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1_features) __ro_after_init;
48extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_features) __ro_after_init;
49extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_fibre_features) __ro_after_init;
50extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_all_ports_features) __ro_after_init;
51extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_features) __ro_after_init;
52extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_fec_features) __ro_after_init;
53extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_full_features) __ro_after_init;
54
55#define PHY_BASIC_FEATURES ((unsigned long *)&phy_basic_features)
56#define PHY_BASIC_T1_FEATURES ((unsigned long *)&phy_basic_t1_features)
57#define PHY_GBIT_FEATURES ((unsigned long *)&phy_gbit_features)
58#define PHY_GBIT_FIBRE_FEATURES ((unsigned long *)&phy_gbit_fibre_features)
59#define PHY_GBIT_ALL_PORTS_FEATURES ((unsigned long *)&phy_gbit_all_ports_features)
60#define PHY_10GBIT_FEATURES ((unsigned long *)&phy_10gbit_features)
61#define PHY_10GBIT_FEC_FEATURES ((unsigned long *)&phy_10gbit_fec_features)
62#define PHY_10GBIT_FULL_FEATURES ((unsigned long *)&phy_10gbit_full_features)
63
64extern const int phy_basic_ports_array[3];
65extern const int phy_fibre_port_array[1];
66extern const int phy_all_ports_features_array[7];
67extern const int phy_10_100_features_array[4];
68extern const int phy_basic_t1_features_array[2];
69extern const int phy_gbit_features_array[2];
70extern const int phy_10gbit_features_array[1];
71
72
73
74
75
76
77#define PHY_POLL -1
78#define PHY_MAC_INTERRUPT -2
79
80#define PHY_IS_INTERNAL 0x00000001
81#define PHY_RST_AFTER_CLK_EN 0x00000002
82#define PHY_POLL_CABLE_TEST 0x00000004
83#define MDIO_DEVICE_IS_PHY 0x80000000
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122typedef enum {
123 PHY_INTERFACE_MODE_NA,
124 PHY_INTERFACE_MODE_INTERNAL,
125 PHY_INTERFACE_MODE_MII,
126 PHY_INTERFACE_MODE_GMII,
127 PHY_INTERFACE_MODE_SGMII,
128 PHY_INTERFACE_MODE_TBI,
129 PHY_INTERFACE_MODE_REVMII,
130 PHY_INTERFACE_MODE_RMII,
131 PHY_INTERFACE_MODE_REVRMII,
132 PHY_INTERFACE_MODE_RGMII,
133 PHY_INTERFACE_MODE_RGMII_ID,
134 PHY_INTERFACE_MODE_RGMII_RXID,
135 PHY_INTERFACE_MODE_RGMII_TXID,
136 PHY_INTERFACE_MODE_RTBI,
137 PHY_INTERFACE_MODE_SMII,
138 PHY_INTERFACE_MODE_XGMII,
139 PHY_INTERFACE_MODE_XLGMII,
140 PHY_INTERFACE_MODE_MOCA,
141 PHY_INTERFACE_MODE_QSGMII,
142 PHY_INTERFACE_MODE_TRGMII,
143 PHY_INTERFACE_MODE_100BASEX,
144 PHY_INTERFACE_MODE_1000BASEX,
145 PHY_INTERFACE_MODE_2500BASEX,
146 PHY_INTERFACE_MODE_5GBASER,
147 PHY_INTERFACE_MODE_RXAUI,
148 PHY_INTERFACE_MODE_XAUI,
149
150 PHY_INTERFACE_MODE_10GBASER,
151 PHY_INTERFACE_MODE_25GBASER,
152 PHY_INTERFACE_MODE_USXGMII,
153
154 PHY_INTERFACE_MODE_10GKR,
155 PHY_INTERFACE_MODE_MAX,
156} phy_interface_t;
157
158
159#define DECLARE_PHY_INTERFACE_MASK(name) \
160 DECLARE_BITMAP(name, PHY_INTERFACE_MODE_MAX)
161
162static inline void phy_interface_zero(unsigned long *intf)
163{
164 bitmap_zero(intf, PHY_INTERFACE_MODE_MAX);
165}
166
167static inline bool phy_interface_empty(const unsigned long *intf)
168{
169 return bitmap_empty(intf, PHY_INTERFACE_MODE_MAX);
170}
171
172static inline void phy_interface_and(unsigned long *dst, const unsigned long *a,
173 const unsigned long *b)
174{
175 bitmap_and(dst, a, b, PHY_INTERFACE_MODE_MAX);
176}
177
178static inline void phy_interface_or(unsigned long *dst, const unsigned long *a,
179 const unsigned long *b)
180{
181 bitmap_or(dst, a, b, PHY_INTERFACE_MODE_MAX);
182}
183
184static inline void phy_interface_set_rgmii(unsigned long *intf)
185{
186 __set_bit(PHY_INTERFACE_MODE_RGMII, intf);
187 __set_bit(PHY_INTERFACE_MODE_RGMII_ID, intf);
188 __set_bit(PHY_INTERFACE_MODE_RGMII_RXID, intf);
189 __set_bit(PHY_INTERFACE_MODE_RGMII_TXID, intf);
190}
191
192
193
194
195unsigned int phy_supported_speeds(struct phy_device *phy,
196 unsigned int *speeds,
197 unsigned int size);
198
199
200
201
202
203
204
205
206
207static inline const char *phy_modes(phy_interface_t interface)
208{
209 switch (interface) {
210 case PHY_INTERFACE_MODE_NA:
211 return "";
212 case PHY_INTERFACE_MODE_INTERNAL:
213 return "internal";
214 case PHY_INTERFACE_MODE_MII:
215 return "mii";
216 case PHY_INTERFACE_MODE_GMII:
217 return "gmii";
218 case PHY_INTERFACE_MODE_SGMII:
219 return "sgmii";
220 case PHY_INTERFACE_MODE_TBI:
221 return "tbi";
222 case PHY_INTERFACE_MODE_REVMII:
223 return "rev-mii";
224 case PHY_INTERFACE_MODE_RMII:
225 return "rmii";
226 case PHY_INTERFACE_MODE_REVRMII:
227 return "rev-rmii";
228 case PHY_INTERFACE_MODE_RGMII:
229 return "rgmii";
230 case PHY_INTERFACE_MODE_RGMII_ID:
231 return "rgmii-id";
232 case PHY_INTERFACE_MODE_RGMII_RXID:
233 return "rgmii-rxid";
234 case PHY_INTERFACE_MODE_RGMII_TXID:
235 return "rgmii-txid";
236 case PHY_INTERFACE_MODE_RTBI:
237 return "rtbi";
238 case PHY_INTERFACE_MODE_SMII:
239 return "smii";
240 case PHY_INTERFACE_MODE_XGMII:
241 return "xgmii";
242 case PHY_INTERFACE_MODE_XLGMII:
243 return "xlgmii";
244 case PHY_INTERFACE_MODE_MOCA:
245 return "moca";
246 case PHY_INTERFACE_MODE_QSGMII:
247 return "qsgmii";
248 case PHY_INTERFACE_MODE_TRGMII:
249 return "trgmii";
250 case PHY_INTERFACE_MODE_1000BASEX:
251 return "1000base-x";
252 case PHY_INTERFACE_MODE_2500BASEX:
253 return "2500base-x";
254 case PHY_INTERFACE_MODE_5GBASER:
255 return "5gbase-r";
256 case PHY_INTERFACE_MODE_RXAUI:
257 return "rxaui";
258 case PHY_INTERFACE_MODE_XAUI:
259 return "xaui";
260 case PHY_INTERFACE_MODE_10GBASER:
261 return "10gbase-r";
262 case PHY_INTERFACE_MODE_25GBASER:
263 return "25gbase-r";
264 case PHY_INTERFACE_MODE_USXGMII:
265 return "usxgmii";
266 case PHY_INTERFACE_MODE_10GKR:
267 return "10gbase-kr";
268 case PHY_INTERFACE_MODE_100BASEX:
269 return "100base-x";
270 default:
271 return "unknown";
272 }
273}
274
275
276#define PHY_INIT_TIMEOUT 100000
277#define PHY_FORCE_TIMEOUT 10
278
279#define PHY_MAX_ADDR 32
280
281
282#define PHY_ID_FMT "%s:%02x"
283
284#define MII_BUS_ID_SIZE 61
285
286struct device;
287struct phylink;
288struct sfp_bus;
289struct sfp_upstream_ops;
290struct sk_buff;
291
292
293
294
295
296
297
298
299
300struct mdio_bus_stats {
301 u64_stats_t transfers;
302 u64_stats_t errors;
303 u64_stats_t writes;
304 u64_stats_t reads;
305
306 struct u64_stats_sync syncp;
307};
308
309
310
311
312
313
314
315
316
317
318
319
320
321struct phy_package_shared {
322 int addr;
323 refcount_t refcnt;
324 unsigned long flags;
325 size_t priv_size;
326
327
328
329
330
331
332
333 void *priv;
334};
335
336
337#define PHY_SHARED_F_INIT_DONE 0
338#define PHY_SHARED_F_PROBE_DONE 1
339
340
341
342
343
344
345
346
347
348
349
350
351struct mii_bus {
352 struct module *owner;
353 const char *name;
354 char id[MII_BUS_ID_SIZE];
355 void *priv;
356
357 int (*read)(struct mii_bus *bus, int addr, int regnum);
358
359 int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val);
360
361 int (*reset)(struct mii_bus *bus);
362
363
364 struct mdio_bus_stats stats[PHY_MAX_ADDR];
365
366
367
368
369
370 struct mutex mdio_lock;
371
372
373 struct device *parent;
374
375 enum {
376 MDIOBUS_ALLOCATED = 1,
377 MDIOBUS_REGISTERED,
378 MDIOBUS_UNREGISTERED,
379 MDIOBUS_RELEASED,
380 } state;
381
382
383 struct device dev;
384
385
386 struct mdio_device *mdio_map[PHY_MAX_ADDR];
387
388
389 u32 phy_mask;
390
391
392 u32 phy_ignore_ta_mask;
393
394
395
396
397
398 int irq[PHY_MAX_ADDR];
399
400
401 int reset_delay_us;
402
403 int reset_post_delay_us;
404
405 struct gpio_desc *reset_gpiod;
406
407
408 enum {
409 MDIOBUS_NO_CAP = 0,
410 MDIOBUS_C22,
411 MDIOBUS_C45,
412 MDIOBUS_C22_C45,
413 } probe_capabilities;
414
415
416 struct mutex shared_lock;
417
418
419 struct phy_package_shared *shared[PHY_MAX_ADDR];
420};
421#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
422
423struct mii_bus *mdiobus_alloc_size(size_t size);
424
425
426
427
428
429
430
431static inline struct mii_bus *mdiobus_alloc(void)
432{
433 return mdiobus_alloc_size(0);
434}
435
436int __mdiobus_register(struct mii_bus *bus, struct module *owner);
437int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,
438 struct module *owner);
439#define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)
440#define devm_mdiobus_register(dev, bus) \
441 __devm_mdiobus_register(dev, bus, THIS_MODULE)
442
443void mdiobus_unregister(struct mii_bus *bus);
444void mdiobus_free(struct mii_bus *bus);
445struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv);
446static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
447{
448 return devm_mdiobus_alloc_size(dev, 0);
449}
450
451struct mii_bus *mdio_find_bus(const char *mdio_name);
452struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
453
454#define PHY_INTERRUPT_DISABLED false
455#define PHY_INTERRUPT_ENABLED true
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493enum phy_state {
494 PHY_DOWN = 0,
495 PHY_READY,
496 PHY_HALTED,
497 PHY_UP,
498 PHY_RUNNING,
499 PHY_NOLINK,
500 PHY_CABLETEST,
501};
502
503#define MDIO_MMD_NUM 32
504
505
506
507
508
509
510
511struct phy_c45_device_ids {
512 u32 devices_in_package;
513 u32 mmds_present;
514 u32 device_ids[MDIO_MMD_NUM];
515};
516
517struct macsec_context;
518struct macsec_ops;
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598struct phy_device {
599 struct mdio_device mdio;
600
601
602
603 struct phy_driver *drv;
604
605 u32 phy_id;
606
607 struct phy_c45_device_ids c45_ids;
608 unsigned is_c45:1;
609 unsigned is_internal:1;
610 unsigned is_pseudo_fixed_link:1;
611 unsigned is_gigabit_capable:1;
612 unsigned has_fixups:1;
613 unsigned suspended:1;
614 unsigned suspended_by_mdio_bus:1;
615 unsigned sysfs_links:1;
616 unsigned loopback_enabled:1;
617 unsigned downshifted_rate:1;
618 unsigned is_on_sfp_module:1;
619 unsigned mac_managed_pm:1;
620
621 unsigned autoneg:1;
622
623 unsigned link:1;
624 unsigned autoneg_complete:1;
625
626
627 unsigned interrupts:1;
628
629 enum phy_state state;
630
631 u32 dev_flags;
632
633 phy_interface_t interface;
634
635
636
637
638
639 int speed;
640 int duplex;
641 int port;
642 int pause;
643 int asym_pause;
644 u8 master_slave_get;
645 u8 master_slave_set;
646 u8 master_slave_state;
647
648
649
650 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
651 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
652 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
653
654 __ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
655
656
657 u32 eee_broken_modes;
658
659#ifdef CONFIG_LED_TRIGGER_PHY
660 struct phy_led_trigger *phy_led_triggers;
661 unsigned int phy_num_led_triggers;
662 struct phy_led_trigger *last_triggered;
663
664 struct phy_led_trigger *led_link_trigger;
665#endif
666
667
668
669
670
671 int irq;
672
673
674
675 void *priv;
676
677
678
679 struct phy_package_shared *shared;
680
681
682 struct sk_buff *skb;
683 void *ehdr;
684 struct nlattr *nest;
685
686
687 struct delayed_work state_queue;
688
689 struct mutex lock;
690
691
692 bool sfp_bus_attached;
693 struct sfp_bus *sfp_bus;
694 struct phylink *phylink;
695 struct net_device *attached_dev;
696 struct mii_timestamper *mii_ts;
697
698 u8 mdix;
699 u8 mdix_ctrl;
700
701 void (*phy_link_change)(struct phy_device *phydev, bool up);
702 void (*adjust_link)(struct net_device *dev);
703
704#if IS_ENABLED(CONFIG_MACSEC)
705
706 const struct macsec_ops *macsec_ops;
707#endif
708};
709
710static inline struct phy_device *to_phy_device(const struct device *dev)
711{
712 return container_of(to_mdio_device(dev), struct phy_device, mdio);
713}
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728struct phy_tdr_config {
729 u32 first;
730 u32 last;
731 u32 step;
732 s8 pair;
733};
734#define PHY_PAIR_ALL -1
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759struct phy_driver {
760 struct mdio_driver_common mdiodrv;
761 u32 phy_id;
762 char *name;
763 u32 phy_id_mask;
764 const unsigned long * const features;
765 u32 flags;
766 const void *driver_data;
767
768
769
770
771 int (*soft_reset)(struct phy_device *phydev);
772
773
774
775
776
777 int (*config_init)(struct phy_device *phydev);
778
779
780
781
782
783 int (*probe)(struct phy_device *phydev);
784
785
786
787
788
789 int (*get_features)(struct phy_device *phydev);
790
791
792
793 int (*suspend)(struct phy_device *phydev);
794
795 int (*resume)(struct phy_device *phydev);
796
797
798
799
800
801
802
803 int (*config_aneg)(struct phy_device *phydev);
804
805
806 int (*aneg_done)(struct phy_device *phydev);
807
808
809 int (*read_status)(struct phy_device *phydev);
810
811
812
813
814
815
816 int (*config_intr)(struct phy_device *phydev);
817
818
819 irqreturn_t (*handle_interrupt)(struct phy_device *phydev);
820
821
822 void (*remove)(struct phy_device *phydev);
823
824
825
826
827
828
829 int (*match_phy_device)(struct phy_device *phydev);
830
831
832
833
834
835
836
837 int (*set_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
838
839
840
841
842
843 void (*get_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
844
845
846
847
848
849
850
851
852
853 void (*link_change_notify)(struct phy_device *dev);
854
855
856
857
858
859
860
861
862
863
864
865 int (*read_mmd)(struct phy_device *dev, int devnum, u16 regnum);
866
867
868
869
870
871
872
873
874
875
876
877 int (*write_mmd)(struct phy_device *dev, int devnum, u16 regnum,
878 u16 val);
879
880
881 int (*read_page)(struct phy_device *dev);
882
883 int (*write_page)(struct phy_device *dev, int page);
884
885
886
887
888
889 int (*module_info)(struct phy_device *dev,
890 struct ethtool_modinfo *modinfo);
891
892
893
894
895
896 int (*module_eeprom)(struct phy_device *dev,
897 struct ethtool_eeprom *ee, u8 *data);
898
899
900 int (*cable_test_start)(struct phy_device *dev);
901
902
903 int (*cable_test_tdr_start)(struct phy_device *dev,
904 const struct phy_tdr_config *config);
905
906
907
908
909
910 int (*cable_test_get_status)(struct phy_device *dev, bool *finished);
911
912
913
914 int (*get_sset_count)(struct phy_device *dev);
915
916 void (*get_strings)(struct phy_device *dev, u8 *data);
917
918 void (*get_stats)(struct phy_device *dev,
919 struct ethtool_stats *stats, u64 *data);
920
921
922
923 int (*get_tunable)(struct phy_device *dev,
924 struct ethtool_tunable *tuna, void *data);
925
926 int (*set_tunable)(struct phy_device *dev,
927 struct ethtool_tunable *tuna,
928 const void *data);
929
930 int (*set_loopback)(struct phy_device *dev, bool enable);
931
932 int (*get_sqi)(struct phy_device *dev);
933
934 int (*get_sqi_max)(struct phy_device *dev);
935};
936#define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
937 struct phy_driver, mdiodrv)
938
939#define PHY_ANY_ID "MATCH ANY PHY"
940#define PHY_ANY_UID 0xffffffff
941
942#define PHY_ID_MATCH_EXACT(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 0)
943#define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 4)
944#define PHY_ID_MATCH_VENDOR(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 10)
945
946
947struct phy_fixup {
948 struct list_head list;
949 char bus_id[MII_BUS_ID_SIZE + 3];
950 u32 phy_uid;
951 u32 phy_uid_mask;
952 int (*run)(struct phy_device *phydev);
953};
954
955const char *phy_speed_to_str(int speed);
956const char *phy_duplex_to_str(unsigned int duplex);
957
958
959
960
961struct phy_setting {
962 u32 speed;
963 u8 duplex;
964 u8 bit;
965};
966
967const struct phy_setting *
968phy_lookup_setting(int speed, int duplex, const unsigned long *mask,
969 bool exact);
970size_t phy_speeds(unsigned int *speeds, size_t size,
971 unsigned long *mask);
972void of_set_phy_supported(struct phy_device *phydev);
973void of_set_phy_eee_broken(struct phy_device *phydev);
974int phy_speed_down_core(struct phy_device *phydev);
975
976
977
978
979
980static inline bool phy_is_started(struct phy_device *phydev)
981{
982 return phydev->state >= PHY_UP;
983}
984
985void phy_resolve_aneg_pause(struct phy_device *phydev);
986void phy_resolve_aneg_linkmode(struct phy_device *phydev);
987void phy_check_downshift(struct phy_device *phydev);
988
989
990
991
992
993
994
995
996
997
998static inline int phy_read(struct phy_device *phydev, u32 regnum)
999{
1000 return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
1001}
1002
1003#define phy_read_poll_timeout(phydev, regnum, val, cond, sleep_us, \
1004 timeout_us, sleep_before_read) \
1005({ \
1006 int __ret = read_poll_timeout(phy_read, val, (cond) || val < 0, \
1007 sleep_us, timeout_us, sleep_before_read, phydev, regnum); \
1008 if (val < 0) \
1009 __ret = val; \
1010 if (__ret) \
1011 phydev_err(phydev, "%s failed: %d\n", __func__, __ret); \
1012 __ret; \
1013})
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023static inline int __phy_read(struct phy_device *phydev, u32 regnum)
1024{
1025 return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
1026}
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
1039{
1040 return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
1041}
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
1052{
1053 return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum,
1054 val);
1055}
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069static inline int __phy_modify_changed(struct phy_device *phydev, u32 regnum,
1070 u16 mask, u16 set)
1071{
1072 return __mdiobus_modify_changed(phydev->mdio.bus, phydev->mdio.addr,
1073 regnum, mask, set);
1074}
1075
1076
1077
1078
1079
1080int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100#define phy_read_mmd_poll_timeout(phydev, devaddr, regnum, val, cond, \
1101 sleep_us, timeout_us, sleep_before_read) \
1102({ \
1103 int __ret = read_poll_timeout(phy_read_mmd, val, (cond) || val < 0, \
1104 sleep_us, timeout_us, sleep_before_read, \
1105 phydev, devaddr, regnum); \
1106 if (val < 0) \
1107 __ret = val; \
1108 if (__ret) \
1109 phydev_err(phydev, "%s failed: %d\n", __func__, __ret); \
1110 __ret; \
1111})
1112
1113
1114
1115
1116
1117int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
1118
1119
1120
1121
1122
1123int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
1124
1125
1126
1127
1128
1129int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
1130
1131int __phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
1132 u16 set);
1133int phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
1134 u16 set);
1135int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
1136int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
1137
1138int __phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
1139 u16 mask, u16 set);
1140int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
1141 u16 mask, u16 set);
1142int __phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
1143 u16 mask, u16 set);
1144int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
1145 u16 mask, u16 set);
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155static inline int __phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
1156{
1157 return __phy_modify(phydev, regnum, 0, val);
1158}
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168static inline int __phy_clear_bits(struct phy_device *phydev, u32 regnum,
1169 u16 val)
1170{
1171 return __phy_modify(phydev, regnum, val, 0);
1172}
1173
1174
1175
1176
1177
1178
1179
1180static inline int phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
1181{
1182 return phy_modify(phydev, regnum, 0, val);
1183}
1184
1185
1186
1187
1188
1189
1190
1191static inline int phy_clear_bits(struct phy_device *phydev, u32 regnum, u16 val)
1192{
1193 return phy_modify(phydev, regnum, val, 0);
1194}
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206static inline int __phy_set_bits_mmd(struct phy_device *phydev, int devad,
1207 u32 regnum, u16 val)
1208{
1209 return __phy_modify_mmd(phydev, devad, regnum, 0, val);
1210}
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222static inline int __phy_clear_bits_mmd(struct phy_device *phydev, int devad,
1223 u32 regnum, u16 val)
1224{
1225 return __phy_modify_mmd(phydev, devad, regnum, val, 0);
1226}
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad,
1237 u32 regnum, u16 val)
1238{
1239 return phy_modify_mmd(phydev, devad, regnum, 0, val);
1240}
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad,
1251 u32 regnum, u16 val)
1252{
1253 return phy_modify_mmd(phydev, devad, regnum, val, 0);
1254}
1255
1256
1257
1258
1259
1260
1261
1262
1263static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
1264{
1265 return phydev->irq != PHY_POLL && phydev->irq != PHY_MAC_INTERRUPT;
1266}
1267
1268
1269
1270
1271
1272
1273static inline bool phy_polling_mode(struct phy_device *phydev)
1274{
1275 if (phydev->state == PHY_CABLETEST)
1276 if (phydev->drv->flags & PHY_POLL_CABLE_TEST)
1277 return true;
1278
1279 return phydev->irq == PHY_POLL;
1280}
1281
1282
1283
1284
1285
1286static inline bool phy_has_hwtstamp(struct phy_device *phydev)
1287{
1288 return phydev && phydev->mii_ts && phydev->mii_ts->hwtstamp;
1289}
1290
1291
1292
1293
1294
1295static inline bool phy_has_rxtstamp(struct phy_device *phydev)
1296{
1297 return phydev && phydev->mii_ts && phydev->mii_ts->rxtstamp;
1298}
1299
1300
1301
1302
1303
1304
1305static inline bool phy_has_tsinfo(struct phy_device *phydev)
1306{
1307 return phydev && phydev->mii_ts && phydev->mii_ts->ts_info;
1308}
1309
1310
1311
1312
1313
1314static inline bool phy_has_txtstamp(struct phy_device *phydev)
1315{
1316 return phydev && phydev->mii_ts && phydev->mii_ts->txtstamp;
1317}
1318
1319static inline int phy_hwtstamp(struct phy_device *phydev, struct ifreq *ifr)
1320{
1321 return phydev->mii_ts->hwtstamp(phydev->mii_ts, ifr);
1322}
1323
1324static inline bool phy_rxtstamp(struct phy_device *phydev, struct sk_buff *skb,
1325 int type)
1326{
1327 return phydev->mii_ts->rxtstamp(phydev->mii_ts, skb, type);
1328}
1329
1330static inline int phy_ts_info(struct phy_device *phydev,
1331 struct ethtool_ts_info *tsinfo)
1332{
1333 return phydev->mii_ts->ts_info(phydev->mii_ts, tsinfo);
1334}
1335
1336static inline void phy_txtstamp(struct phy_device *phydev, struct sk_buff *skb,
1337 int type)
1338{
1339 phydev->mii_ts->txtstamp(phydev->mii_ts, skb, type);
1340}
1341
1342
1343
1344
1345
1346static inline bool phy_is_internal(struct phy_device *phydev)
1347{
1348 return phydev->is_internal;
1349}
1350
1351
1352
1353
1354
1355static inline bool phy_on_sfp(struct phy_device *phydev)
1356{
1357 return phydev->is_on_sfp_module;
1358}
1359
1360
1361
1362
1363
1364
1365static inline bool phy_interface_mode_is_rgmii(phy_interface_t mode)
1366{
1367 return mode >= PHY_INTERFACE_MODE_RGMII &&
1368 mode <= PHY_INTERFACE_MODE_RGMII_TXID;
1369};
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379static inline bool phy_interface_mode_is_8023z(phy_interface_t mode)
1380{
1381 return mode == PHY_INTERFACE_MODE_1000BASEX ||
1382 mode == PHY_INTERFACE_MODE_2500BASEX;
1383}
1384
1385
1386
1387
1388
1389
1390static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
1391{
1392 return phy_interface_mode_is_rgmii(phydev->interface);
1393};
1394
1395
1396
1397
1398
1399
1400static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)
1401{
1402 return phydev->is_pseudo_fixed_link;
1403}
1404
1405int phy_save_page(struct phy_device *phydev);
1406int phy_select_page(struct phy_device *phydev, int page);
1407int phy_restore_page(struct phy_device *phydev, int oldpage, int ret);
1408int phy_read_paged(struct phy_device *phydev, int page, u32 regnum);
1409int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val);
1410int phy_modify_paged_changed(struct phy_device *phydev, int page, u32 regnum,
1411 u16 mask, u16 set);
1412int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum,
1413 u16 mask, u16 set);
1414
1415struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
1416 bool is_c45,
1417 struct phy_c45_device_ids *c45_ids);
1418#if IS_ENABLED(CONFIG_PHYLIB)
1419int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id);
1420struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode);
1421struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode);
1422struct phy_device *device_phy_find_device(struct device *dev);
1423struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode);
1424struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
1425int phy_device_register(struct phy_device *phy);
1426void phy_device_free(struct phy_device *phydev);
1427#else
1428static inline int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id)
1429{
1430 return 0;
1431}
1432static inline
1433struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode)
1434{
1435 return 0;
1436}
1437
1438static inline
1439struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode)
1440{
1441 return NULL;
1442}
1443
1444static inline struct phy_device *device_phy_find_device(struct device *dev)
1445{
1446 return NULL;
1447}
1448
1449static inline
1450struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode)
1451{
1452 return NULL;
1453}
1454
1455static inline
1456struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
1457{
1458 return NULL;
1459}
1460
1461static inline int phy_device_register(struct phy_device *phy)
1462{
1463 return 0;
1464}
1465
1466static inline void phy_device_free(struct phy_device *phydev) { }
1467#endif
1468void phy_device_remove(struct phy_device *phydev);
1469int phy_get_c45_ids(struct phy_device *phydev);
1470int phy_init_hw(struct phy_device *phydev);
1471int phy_suspend(struct phy_device *phydev);
1472int phy_resume(struct phy_device *phydev);
1473int __phy_resume(struct phy_device *phydev);
1474int phy_loopback(struct phy_device *phydev, bool enable);
1475void phy_sfp_attach(void *upstream, struct sfp_bus *bus);
1476void phy_sfp_detach(void *upstream, struct sfp_bus *bus);
1477int phy_sfp_probe(struct phy_device *phydev,
1478 const struct sfp_upstream_ops *ops);
1479struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
1480 phy_interface_t interface);
1481struct phy_device *phy_find_first(struct mii_bus *bus);
1482int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
1483 u32 flags, phy_interface_t interface);
1484int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
1485 void (*handler)(struct net_device *),
1486 phy_interface_t interface);
1487struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
1488 void (*handler)(struct net_device *),
1489 phy_interface_t interface);
1490void phy_disconnect(struct phy_device *phydev);
1491void phy_detach(struct phy_device *phydev);
1492void phy_start(struct phy_device *phydev);
1493void phy_stop(struct phy_device *phydev);
1494int phy_config_aneg(struct phy_device *phydev);
1495int phy_start_aneg(struct phy_device *phydev);
1496int phy_aneg_done(struct phy_device *phydev);
1497int phy_speed_down(struct phy_device *phydev, bool sync);
1498int phy_speed_up(struct phy_device *phydev);
1499
1500int phy_restart_aneg(struct phy_device *phydev);
1501int phy_reset_after_clk_enable(struct phy_device *phydev);
1502
1503#if IS_ENABLED(CONFIG_PHYLIB)
1504int phy_start_cable_test(struct phy_device *phydev,
1505 struct netlink_ext_ack *extack);
1506int phy_start_cable_test_tdr(struct phy_device *phydev,
1507 struct netlink_ext_ack *extack,
1508 const struct phy_tdr_config *config);
1509#else
1510static inline
1511int phy_start_cable_test(struct phy_device *phydev,
1512 struct netlink_ext_ack *extack)
1513{
1514 NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
1515 return -EOPNOTSUPP;
1516}
1517static inline
1518int phy_start_cable_test_tdr(struct phy_device *phydev,
1519 struct netlink_ext_ack *extack,
1520 const struct phy_tdr_config *config)
1521{
1522 NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
1523 return -EOPNOTSUPP;
1524}
1525#endif
1526
1527int phy_cable_test_result(struct phy_device *phydev, u8 pair, u16 result);
1528int phy_cable_test_fault_length(struct phy_device *phydev, u8 pair,
1529 u16 cm);
1530
1531static inline void phy_device_reset(struct phy_device *phydev, int value)
1532{
1533 mdio_device_reset(&phydev->mdio, value);
1534}
1535
1536#define phydev_err(_phydev, format, args...) \
1537 dev_err(&_phydev->mdio.dev, format, ##args)
1538
1539#define phydev_info(_phydev, format, args...) \
1540 dev_info(&_phydev->mdio.dev, format, ##args)
1541
1542#define phydev_warn(_phydev, format, args...) \
1543 dev_warn(&_phydev->mdio.dev, format, ##args)
1544
1545#define phydev_dbg(_phydev, format, args...) \
1546 dev_dbg(&_phydev->mdio.dev, format, ##args)
1547
1548static inline const char *phydev_name(const struct phy_device *phydev)
1549{
1550 return dev_name(&phydev->mdio.dev);
1551}
1552
1553static inline void phy_lock_mdio_bus(struct phy_device *phydev)
1554{
1555 mutex_lock(&phydev->mdio.bus->mdio_lock);
1556}
1557
1558static inline void phy_unlock_mdio_bus(struct phy_device *phydev)
1559{
1560 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1561}
1562
1563void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
1564 __printf(2, 3);
1565char *phy_attached_info_irq(struct phy_device *phydev)
1566 __malloc;
1567void phy_attached_info(struct phy_device *phydev);
1568
1569
1570int genphy_read_abilities(struct phy_device *phydev);
1571int genphy_setup_forced(struct phy_device *phydev);
1572int genphy_restart_aneg(struct phy_device *phydev);
1573int genphy_check_and_restart_aneg(struct phy_device *phydev, bool restart);
1574int genphy_config_eee_advert(struct phy_device *phydev);
1575int __genphy_config_aneg(struct phy_device *phydev, bool changed);
1576int genphy_aneg_done(struct phy_device *phydev);
1577int genphy_update_link(struct phy_device *phydev);
1578int genphy_read_lpa(struct phy_device *phydev);
1579int genphy_read_status_fixed(struct phy_device *phydev);
1580int genphy_read_status(struct phy_device *phydev);
1581int genphy_read_master_slave(struct phy_device *phydev);
1582int genphy_suspend(struct phy_device *phydev);
1583int genphy_resume(struct phy_device *phydev);
1584int genphy_loopback(struct phy_device *phydev, bool enable);
1585int genphy_soft_reset(struct phy_device *phydev);
1586irqreturn_t genphy_handle_interrupt_no_ack(struct phy_device *phydev);
1587
1588static inline int genphy_config_aneg(struct phy_device *phydev)
1589{
1590 return __genphy_config_aneg(phydev, false);
1591}
1592
1593static inline int genphy_no_config_intr(struct phy_device *phydev)
1594{
1595 return 0;
1596}
1597int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad,
1598 u16 regnum);
1599int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,
1600 u16 regnum, u16 val);
1601
1602
1603int genphy_c37_config_aneg(struct phy_device *phydev);
1604int genphy_c37_read_status(struct phy_device *phydev);
1605
1606
1607int genphy_c45_restart_aneg(struct phy_device *phydev);
1608int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart);
1609int genphy_c45_aneg_done(struct phy_device *phydev);
1610int genphy_c45_read_link(struct phy_device *phydev);
1611int genphy_c45_read_lpa(struct phy_device *phydev);
1612int genphy_c45_read_pma(struct phy_device *phydev);
1613int genphy_c45_pma_setup_forced(struct phy_device *phydev);
1614int genphy_c45_an_config_aneg(struct phy_device *phydev);
1615int genphy_c45_an_disable_aneg(struct phy_device *phydev);
1616int genphy_c45_read_mdix(struct phy_device *phydev);
1617int genphy_c45_pma_read_abilities(struct phy_device *phydev);
1618int genphy_c45_read_status(struct phy_device *phydev);
1619int genphy_c45_config_aneg(struct phy_device *phydev);
1620int genphy_c45_loopback(struct phy_device *phydev, bool enable);
1621int genphy_c45_pma_resume(struct phy_device *phydev);
1622int genphy_c45_pma_suspend(struct phy_device *phydev);
1623int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable);
1624
1625
1626extern struct phy_driver genphy_c45_driver;
1627
1628
1629int gen10g_config_aneg(struct phy_device *phydev);
1630
1631static inline int phy_read_status(struct phy_device *phydev)
1632{
1633 if (!phydev->drv)
1634 return -EIO;
1635
1636 if (phydev->drv->read_status)
1637 return phydev->drv->read_status(phydev);
1638 else
1639 return genphy_read_status(phydev);
1640}
1641
1642void phy_driver_unregister(struct phy_driver *drv);
1643void phy_drivers_unregister(struct phy_driver *drv, int n);
1644int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
1645int phy_drivers_register(struct phy_driver *new_driver, int n,
1646 struct module *owner);
1647void phy_error(struct phy_device *phydev);
1648void phy_state_machine(struct work_struct *work);
1649void phy_queue_state_machine(struct phy_device *phydev, unsigned long jiffies);
1650void phy_trigger_machine(struct phy_device *phydev);
1651void phy_mac_interrupt(struct phy_device *phydev);
1652void phy_start_machine(struct phy_device *phydev);
1653void phy_stop_machine(struct phy_device *phydev);
1654void phy_ethtool_ksettings_get(struct phy_device *phydev,
1655 struct ethtool_link_ksettings *cmd);
1656int phy_ethtool_ksettings_set(struct phy_device *phydev,
1657 const struct ethtool_link_ksettings *cmd);
1658int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
1659int phy_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
1660int phy_do_ioctl_running(struct net_device *dev, struct ifreq *ifr, int cmd);
1661int phy_disable_interrupts(struct phy_device *phydev);
1662void phy_request_interrupt(struct phy_device *phydev);
1663void phy_free_interrupt(struct phy_device *phydev);
1664void phy_print_status(struct phy_device *phydev);
1665void phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
1666void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
1667void phy_advertise_supported(struct phy_device *phydev);
1668void phy_support_sym_pause(struct phy_device *phydev);
1669void phy_support_asym_pause(struct phy_device *phydev);
1670void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
1671 bool autoneg);
1672void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
1673bool phy_validate_pause(struct phy_device *phydev,
1674 struct ethtool_pauseparam *pp);
1675void phy_get_pause(struct phy_device *phydev, bool *tx_pause, bool *rx_pause);
1676
1677s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
1678 const int *delay_values, int size, bool is_rx);
1679
1680void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv,
1681 bool *tx_pause, bool *rx_pause);
1682
1683int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
1684 int (*run)(struct phy_device *));
1685int phy_register_fixup_for_id(const char *bus_id,
1686 int (*run)(struct phy_device *));
1687int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
1688 int (*run)(struct phy_device *));
1689
1690int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask);
1691int phy_unregister_fixup_for_id(const char *bus_id);
1692int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
1693
1694int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
1695int phy_get_eee_err(struct phy_device *phydev);
1696int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
1697int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
1698int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
1699void phy_ethtool_get_wol(struct phy_device *phydev,
1700 struct ethtool_wolinfo *wol);
1701int phy_ethtool_get_link_ksettings(struct net_device *ndev,
1702 struct ethtool_link_ksettings *cmd);
1703int phy_ethtool_set_link_ksettings(struct net_device *ndev,
1704 const struct ethtool_link_ksettings *cmd);
1705int phy_ethtool_nway_reset(struct net_device *ndev);
1706int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size);
1707void phy_package_leave(struct phy_device *phydev);
1708int devm_phy_package_join(struct device *dev, struct phy_device *phydev,
1709 int addr, size_t priv_size);
1710
1711#if IS_ENABLED(CONFIG_PHYLIB)
1712int __init mdio_bus_init(void);
1713void mdio_bus_exit(void);
1714#endif
1715
1716int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data);
1717int phy_ethtool_get_sset_count(struct phy_device *phydev);
1718int phy_ethtool_get_stats(struct phy_device *phydev,
1719 struct ethtool_stats *stats, u64 *data);
1720
1721static inline int phy_package_read(struct phy_device *phydev, u32 regnum)
1722{
1723 struct phy_package_shared *shared = phydev->shared;
1724
1725 if (!shared)
1726 return -EIO;
1727
1728 return mdiobus_read(phydev->mdio.bus, shared->addr, regnum);
1729}
1730
1731static inline int __phy_package_read(struct phy_device *phydev, u32 regnum)
1732{
1733 struct phy_package_shared *shared = phydev->shared;
1734
1735 if (!shared)
1736 return -EIO;
1737
1738 return __mdiobus_read(phydev->mdio.bus, shared->addr, regnum);
1739}
1740
1741static inline int phy_package_write(struct phy_device *phydev,
1742 u32 regnum, u16 val)
1743{
1744 struct phy_package_shared *shared = phydev->shared;
1745
1746 if (!shared)
1747 return -EIO;
1748
1749 return mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val);
1750}
1751
1752static inline int __phy_package_write(struct phy_device *phydev,
1753 u32 regnum, u16 val)
1754{
1755 struct phy_package_shared *shared = phydev->shared;
1756
1757 if (!shared)
1758 return -EIO;
1759
1760 return __mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val);
1761}
1762
1763static inline bool __phy_package_set_once(struct phy_device *phydev,
1764 unsigned int b)
1765{
1766 struct phy_package_shared *shared = phydev->shared;
1767
1768 if (!shared)
1769 return false;
1770
1771 return !test_and_set_bit(b, &shared->flags);
1772}
1773
1774static inline bool phy_package_init_once(struct phy_device *phydev)
1775{
1776 return __phy_package_set_once(phydev, PHY_SHARED_F_INIT_DONE);
1777}
1778
1779static inline bool phy_package_probe_once(struct phy_device *phydev)
1780{
1781 return __phy_package_set_once(phydev, PHY_SHARED_F_PROBE_DONE);
1782}
1783
1784extern struct bus_type mdio_bus_type;
1785
1786struct mdio_board_info {
1787 const char *bus_id;
1788 char modalias[MDIO_NAME_SIZE];
1789 int mdio_addr;
1790 const void *platform_data;
1791};
1792
1793#if IS_ENABLED(CONFIG_MDIO_DEVICE)
1794int mdiobus_register_board_info(const struct mdio_board_info *info,
1795 unsigned int n);
1796#else
1797static inline int mdiobus_register_board_info(const struct mdio_board_info *i,
1798 unsigned int n)
1799{
1800 return 0;
1801}
1802#endif
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814#define phy_module_driver(__phy_drivers, __count) \
1815static int __init phy_module_init(void) \
1816{ \
1817 return phy_drivers_register(__phy_drivers, __count, THIS_MODULE); \
1818} \
1819module_init(phy_module_init); \
1820static void __exit phy_module_exit(void) \
1821{ \
1822 phy_drivers_unregister(__phy_drivers, __count); \
1823} \
1824module_exit(phy_module_exit)
1825
1826#define module_phy_driver(__phy_drivers) \
1827 phy_module_driver(__phy_drivers, ARRAY_SIZE(__phy_drivers))
1828
1829bool phy_driver_is_genphy(struct phy_device *phydev);
1830bool phy_driver_is_genphy_10g(struct phy_device *phydev);
1831
1832#endif
1833