8
8
9
9
#include "sfp.h"
10
10
11
+ /**
12
+ * struct sfp_bus - internal representation of a sfp bus
13
+ */
11
14
struct sfp_bus {
15
+ /* private: */
12
16
struct kref kref ;
13
17
struct list_head node ;
14
18
struct device_node * device_node ;
@@ -26,6 +30,20 @@ struct sfp_bus {
26
30
bool started ;
27
31
};
28
32
33
+ /**
34
+ * sfp_parse_port() - Parse the EEPROM base ID, setting the port type
35
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
36
+ * @id: a pointer to the module's &struct sfp_eeprom_id
37
+ * @support: optional pointer to an array of unsigned long for the
38
+ * ethtool support mask
39
+ *
40
+ * Parse the EEPROM identification given in @id, and return one of
41
+ * %PORT_TP, %PORT_FIBRE or %PORT_OTHER. If @support is non-%NULL,
42
+ * also set the ethtool %ETHTOOL_LINK_MODE_xxx_BIT corresponding with
43
+ * the connector type.
44
+ *
45
+ * If the port type is not known, returns %PORT_OTHER.
46
+ */
29
47
int sfp_parse_port (struct sfp_bus * bus , const struct sfp_eeprom_id * id ,
30
48
unsigned long * support )
31
49
{
@@ -78,6 +96,24 @@ int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
78
96
}
79
97
EXPORT_SYMBOL_GPL (sfp_parse_port );
80
98
99
+ /**
100
+ * sfp_parse_interface() - Parse the phy_interface_t
101
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
102
+ * @id: a pointer to the module's &struct sfp_eeprom_id
103
+ *
104
+ * Derive the phy_interface_t mode for the information found in the
105
+ * module's identifying EEPROM. There is no standard or defined way
106
+ * to derive this information, so we use some heuristics.
107
+ *
108
+ * If the encoding is 64b66b, then the module must be >= 10G, so
109
+ * return %PHY_INTERFACE_MODE_10GKR.
110
+ *
111
+ * If it's 8b10b, then it's 1G or slower. If it's definitely a fibre
112
+ * module, return %PHY_INTERFACE_MODE_1000BASEX mode, otherwise return
113
+ * %PHY_INTERFACE_MODE_SGMII mode.
114
+ *
115
+ * If the encoding is not known, return %PHY_INTERFACE_MODE_NA.
116
+ */
81
117
phy_interface_t sfp_parse_interface (struct sfp_bus * bus ,
82
118
const struct sfp_eeprom_id * id )
83
119
{
@@ -117,6 +153,15 @@ phy_interface_t sfp_parse_interface(struct sfp_bus *bus,
117
153
}
118
154
EXPORT_SYMBOL_GPL (sfp_parse_interface );
119
155
156
+ /**
157
+ * sfp_parse_support() - Parse the eeprom id for supported link modes
158
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
159
+ * @id: a pointer to the module's &struct sfp_eeprom_id
160
+ * @support: pointer to an array of unsigned long for the ethtool support mask
161
+ *
162
+ * Parse the EEPROM identification information and derive the supported
163
+ * ethtool link modes for the module.
164
+ */
120
165
void sfp_parse_support (struct sfp_bus * bus , const struct sfp_eeprom_id * id ,
121
166
unsigned long * support )
122
167
{
@@ -293,6 +338,16 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
293
338
bus -> registered = false;
294
339
}
295
340
341
+ /**
342
+ * sfp_get_module_info() - Get the ethtool_modinfo for a SFP module
343
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
344
+ * @modinfo: a &struct ethtool_modinfo
345
+ *
346
+ * Fill in the type and eeprom_len parameters in @modinfo for a module on
347
+ * the sfp bus specified by @bus.
348
+ *
349
+ * Returns 0 on success or a negative errno number.
350
+ */
296
351
int sfp_get_module_info (struct sfp_bus * bus , struct ethtool_modinfo * modinfo )
297
352
{
298
353
if (!bus -> registered )
@@ -301,6 +356,17 @@ int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
301
356
}
302
357
EXPORT_SYMBOL_GPL (sfp_get_module_info );
303
358
359
+ /**
360
+ * sfp_get_module_eeprom() - Read the SFP module EEPROM
361
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
362
+ * @ee: a &struct ethtool_eeprom
363
+ * @data: buffer to contain the EEPROM data (must be at least @ee->len bytes)
364
+ *
365
+ * Read the EEPROM as specified by the supplied @ee. See the documentation
366
+ * for &struct ethtool_eeprom for the region to be read.
367
+ *
368
+ * Returns 0 on success or a negative errno number.
369
+ */
304
370
int sfp_get_module_eeprom (struct sfp_bus * bus , struct ethtool_eeprom * ee ,
305
371
u8 * data )
306
372
{
@@ -310,6 +376,15 @@ int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
310
376
}
311
377
EXPORT_SYMBOL_GPL (sfp_get_module_eeprom );
312
378
379
+ /**
380
+ * sfp_upstream_start() - Inform the SFP that the network device is up
381
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
382
+ *
383
+ * Inform the SFP socket that the network device is now up, so that the
384
+ * module can be enabled by allowing TX_DISABLE to be deasserted. This
385
+ * should be called from the network device driver's &struct net_device_ops
386
+ * ndo_open() method.
387
+ */
313
388
void sfp_upstream_start (struct sfp_bus * bus )
314
389
{
315
390
if (bus -> registered )
@@ -318,6 +393,15 @@ void sfp_upstream_start(struct sfp_bus *bus)
318
393
}
319
394
EXPORT_SYMBOL_GPL (sfp_upstream_start );
320
395
396
+ /**
397
+ * sfp_upstream_stop() - Inform the SFP that the network device is down
398
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
399
+ *
400
+ * Inform the SFP socket that the network device is now up, so that the
401
+ * module can be disabled by asserting TX_DISABLE, disabling the laser
402
+ * in optical modules. This should be called from the network device
403
+ * driver's &struct net_device_ops ndo_stop() method.
404
+ */
321
405
void sfp_upstream_stop (struct sfp_bus * bus )
322
406
{
323
407
if (bus -> registered )
@@ -326,6 +410,19 @@ void sfp_upstream_stop(struct sfp_bus *bus)
326
410
}
327
411
EXPORT_SYMBOL_GPL (sfp_upstream_stop );
328
412
413
+ /**
414
+ * sfp_register_upstream() - Register the neighbouring device
415
+ * @np: device node for the SFP bus
416
+ * @ndev: network device associated with the interface
417
+ * @upstream: the upstream private data
418
+ * @ops: the upstream's &struct sfp_upstream_ops
419
+ *
420
+ * Register the upstream device (eg, PHY) with the SFP bus. MAC drivers
421
+ * should use phylink, which will call this function for them. Returns
422
+ * a pointer to the allocated &struct sfp_bus.
423
+ *
424
+ * On error, returns %NULL.
425
+ */
329
426
struct sfp_bus * sfp_register_upstream (struct device_node * np ,
330
427
struct net_device * ndev , void * upstream ,
331
428
const struct sfp_upstream_ops * ops )
@@ -353,6 +450,13 @@ struct sfp_bus *sfp_register_upstream(struct device_node *np,
353
450
}
354
451
EXPORT_SYMBOL_GPL (sfp_register_upstream );
355
452
453
+ /**
454
+ * sfp_unregister_upstream() - Unregister sfp bus
455
+ * @bus: a pointer to the &struct sfp_bus structure for the sfp module
456
+ *
457
+ * Unregister a previously registered upstream connection for the SFP
458
+ * module. @bus is returned from sfp_register_upstream().
459
+ */
356
460
void sfp_unregister_upstream (struct sfp_bus * bus )
357
461
{
358
462
rtnl_lock ();
0 commit comments