1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __PHY_H
19#define __PHY_H
20
21#include <linux/spinlock.h>
22#include <linux/ethtool.h>
23#include <linux/mii.h>
24#include <linux/timer.h>
25#include <linux/workqueue.h>
26#include <linux/mod_devicetable.h>
27
28#include <linux/atomic.h>
29
30#define PHY_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
31 SUPPORTED_10baseT_Full | \
32 SUPPORTED_100baseT_Half | \
33 SUPPORTED_100baseT_Full | \
34 SUPPORTED_Autoneg | \
35 SUPPORTED_TP | \
36 SUPPORTED_MII)
37
38#define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
39 SUPPORTED_1000baseT_Half | \
40 SUPPORTED_1000baseT_Full)
41
42
43
44
45
46
47#define PHY_POLL -1
48#define PHY_IGNORE_INTERRUPT -2
49
50#define PHY_HAS_INTERRUPT 0x00000001
51#define PHY_HAS_MAGICANEG 0x00000002
52
53
54typedef enum {
55 PHY_INTERFACE_MODE_NA,
56 PHY_INTERFACE_MODE_MII,
57 PHY_INTERFACE_MODE_GMII,
58 PHY_INTERFACE_MODE_SGMII,
59 PHY_INTERFACE_MODE_TBI,
60 PHY_INTERFACE_MODE_RMII,
61 PHY_INTERFACE_MODE_RGMII,
62 PHY_INTERFACE_MODE_RGMII_ID,
63 PHY_INTERFACE_MODE_RGMII_RXID,
64 PHY_INTERFACE_MODE_RGMII_TXID,
65 PHY_INTERFACE_MODE_RTBI,
66 PHY_INTERFACE_MODE_SMII,
67} phy_interface_t;
68
69
70#define PHY_INIT_TIMEOUT 100000
71#define PHY_STATE_TIME 1
72#define PHY_FORCE_TIMEOUT 10
73#define PHY_AN_TIMEOUT 10
74
75#define PHY_MAX_ADDR 32
76
77
78#define PHY_ID_FMT "%s:%02x"
79
80
81
82
83
84#define MII_BUS_ID_SIZE (20 - 3)
85
86
87
88#define MII_ADDR_C45 (1<<30)
89
90struct device;
91struct sk_buff;
92
93
94
95
96
97struct mii_bus {
98 const char *name;
99 char id[MII_BUS_ID_SIZE];
100 void *priv;
101 int (*read)(struct mii_bus *bus, int phy_id, int regnum);
102 int (*write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);
103 int (*reset)(struct mii_bus *bus);
104
105
106
107
108
109 struct mutex mdio_lock;
110
111 struct device *parent;
112 enum {
113 MDIOBUS_ALLOCATED = 1,
114 MDIOBUS_REGISTERED,
115 MDIOBUS_UNREGISTERED,
116 MDIOBUS_RELEASED,
117 } state;
118 struct device dev;
119
120
121 struct phy_device *phy_map[PHY_MAX_ADDR];
122
123
124 u32 phy_mask;
125
126
127
128
129
130 int *irq;
131};
132#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
133
134struct mii_bus *mdiobus_alloc_size(size_t);
135static inline struct mii_bus *mdiobus_alloc(void)
136{
137 return mdiobus_alloc_size(0);
138}
139
140int mdiobus_register(struct mii_bus *bus);
141void mdiobus_unregister(struct mii_bus *bus);
142void mdiobus_free(struct mii_bus *bus);
143struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
144int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
145int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
146
147
148#define PHY_INTERRUPT_DISABLED 0x0
149#define PHY_INTERRUPT_ENABLED 0x80000000
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231enum phy_state {
232 PHY_DOWN=0,
233 PHY_STARTING,
234 PHY_READY,
235 PHY_PENDING,
236 PHY_UP,
237 PHY_AN,
238 PHY_RUNNING,
239 PHY_NOLINK,
240 PHY_FORCING,
241 PHY_CHANGELINK,
242 PHY_HALTED,
243 PHY_RESUMING
244};
245
246
247
248
249
250
251struct phy_c45_device_ids {
252 u32 devices_in_package;
253 u32 device_ids[8];
254};
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288struct phy_device {
289
290
291 struct phy_driver *drv;
292
293 struct mii_bus *bus;
294
295 struct device dev;
296
297 u32 phy_id;
298
299 struct phy_c45_device_ids c45_ids;
300 bool is_c45;
301
302 enum phy_state state;
303
304 u32 dev_flags;
305
306 phy_interface_t interface;
307
308
309 int addr;
310
311
312
313
314
315 int speed;
316 int duplex;
317 int pause;
318 int asym_pause;
319
320
321 int link;
322
323
324 u32 interrupts;
325
326
327
328 u32 supported;
329 u32 advertising;
330
331 int autoneg;
332
333 int link_timeout;
334
335
336
337
338
339 int irq;
340
341
342
343 void *priv;
344
345
346 struct work_struct phy_queue;
347 struct delayed_work state_queue;
348 atomic_t irq_disable;
349
350 struct mutex lock;
351
352 struct net_device *attached_dev;
353
354 void (*adjust_link)(struct net_device *dev);
355
356 void (*adjust_state)(struct net_device *dev);
357};
358#define to_phy_device(d) container_of(d, struct phy_device, dev)
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380struct phy_driver {
381 u32 phy_id;
382 char *name;
383 unsigned int phy_id_mask;
384 u32 features;
385 u32 flags;
386
387
388
389
390
391 int (*config_init)(struct phy_device *phydev);
392
393
394
395
396
397 int (*probe)(struct phy_device *phydev);
398
399
400 int (*suspend)(struct phy_device *phydev);
401 int (*resume)(struct phy_device *phydev);
402
403
404
405
406
407
408
409 int (*config_aneg)(struct phy_device *phydev);
410
411
412 int (*read_status)(struct phy_device *phydev);
413
414
415 int (*ack_interrupt)(struct phy_device *phydev);
416
417
418 int (*config_intr)(struct phy_device *phydev);
419
420
421
422
423
424 int (*did_interrupt)(struct phy_device *phydev);
425
426
427 void (*remove)(struct phy_device *phydev);
428
429
430
431
432
433 int (*match_phy_device)(struct phy_device *phydev);
434
435
436 int (*ts_info)(struct phy_device *phydev, struct ethtool_ts_info *ti);
437
438
439 int (*hwtstamp)(struct phy_device *phydev, struct ifreq *ifr);
440
441
442
443
444
445
446
447
448 bool (*rxtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
449
450
451
452
453
454
455
456 void (*txtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
457
458 struct device_driver driver;
459};
460#define to_phy_driver(d) container_of(d, struct phy_driver, driver)
461
462#define PHY_ANY_ID "MATCH ANY PHY"
463#define PHY_ANY_UID 0xffffffff
464
465
466struct phy_fixup {
467 struct list_head list;
468 char bus_id[20];
469 u32 phy_uid;
470 u32 phy_uid_mask;
471 int (*run)(struct phy_device *phydev);
472};
473
474
475
476
477
478
479
480
481
482
483static inline int phy_read(struct phy_device *phydev, u32 regnum)
484{
485 return mdiobus_read(phydev->bus, phydev->addr, regnum);
486}
487
488
489
490
491
492
493
494
495
496
497
498static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
499{
500 return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
501}
502
503struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
504 bool is_c45, struct phy_c45_device_ids *c45_ids);
505struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
506int phy_device_register(struct phy_device *phy);
507int phy_init_hw(struct phy_device *phydev);
508struct phy_device * phy_attach(struct net_device *dev,
509 const char *bus_id, u32 flags, phy_interface_t interface);
510struct phy_device *phy_find_first(struct mii_bus *bus);
511int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
512 void (*handler)(struct net_device *), u32 flags,
513 phy_interface_t interface);
514struct phy_device * phy_connect(struct net_device *dev, const char *bus_id,
515 void (*handler)(struct net_device *), u32 flags,
516 phy_interface_t interface);
517void phy_disconnect(struct phy_device *phydev);
518void phy_detach(struct phy_device *phydev);
519void phy_start(struct phy_device *phydev);
520void phy_stop(struct phy_device *phydev);
521int phy_start_aneg(struct phy_device *phydev);
522
523int phy_stop_interrupts(struct phy_device *phydev);
524
525static inline int phy_read_status(struct phy_device *phydev) {
526 return phydev->drv->read_status(phydev);
527}
528
529int genphy_restart_aneg(struct phy_device *phydev);
530int genphy_config_aneg(struct phy_device *phydev);
531int genphy_update_link(struct phy_device *phydev);
532int genphy_read_status(struct phy_device *phydev);
533int genphy_suspend(struct phy_device *phydev);
534int genphy_resume(struct phy_device *phydev);
535void phy_driver_unregister(struct phy_driver *drv);
536void phy_drivers_unregister(struct phy_driver *drv, int n);
537int phy_driver_register(struct phy_driver *new_driver);
538int phy_drivers_register(struct phy_driver *new_driver, int n);
539void phy_state_machine(struct work_struct *work);
540void phy_start_machine(struct phy_device *phydev,
541 void (*handler)(struct net_device *));
542void phy_stop_machine(struct phy_device *phydev);
543int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
544int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
545int phy_mii_ioctl(struct phy_device *phydev,
546 struct ifreq *ifr, int cmd);
547int phy_start_interrupts(struct phy_device *phydev);
548void phy_print_status(struct phy_device *phydev);
549void phy_device_free(struct phy_device *phydev);
550
551int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
552 int (*run)(struct phy_device *));
553int phy_register_fixup_for_id(const char *bus_id,
554 int (*run)(struct phy_device *));
555int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
556 int (*run)(struct phy_device *));
557int phy_scan_fixups(struct phy_device *phydev);
558
559int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
560int phy_get_eee_err(struct phy_device *phydev);
561int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
562int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
563
564int __init mdio_bus_init(void);
565void mdio_bus_exit(void);
566
567extern struct bus_type mdio_bus_type;
568#endif
569