Skip to content

Commit 0a6fcd3

Browse files
Russell Kingdavem330
authored andcommitted
sfp: add documentation for kernel APIs
Add kernel-doc documentation for sfp kernel APIs, and link it into the networking kapi documentation under "Network device support". Signed-off-by: Russell King <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8796c89 commit 0a6fcd3

File tree

3 files changed

+152
-14
lines changed

3 files changed

+152
-14
lines changed

Documentation/networking/kapi.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,15 @@ PHYLINK
157157
:internal:
158158

159159
.. kernel-doc:: drivers/net/phy/phylink.c
160+
161+
SFP support
162+
-----------
163+
164+
.. kernel-doc:: drivers/net/phy/sfp-bus.c
165+
:internal:
166+
167+
.. kernel-doc:: include/linux/sfp.h
168+
:internal:
169+
170+
.. kernel-doc:: drivers/net/phy/sfp-bus.c
171+
:export:

drivers/net/phy/sfp-bus.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
#include "sfp.h"
1010

11+
/**
12+
* struct sfp_bus - internal representation of a sfp bus
13+
*/
1114
struct sfp_bus {
15+
/* private: */
1216
struct kref kref;
1317
struct list_head node;
1418
struct device_node *device_node;
@@ -26,6 +30,20 @@ struct sfp_bus {
2630
bool started;
2731
};
2832

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+
*/
2947
int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
3048
unsigned long *support)
3149
{
@@ -78,6 +96,24 @@ int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
7896
}
7997
EXPORT_SYMBOL_GPL(sfp_parse_port);
8098

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+
*/
81117
phy_interface_t sfp_parse_interface(struct sfp_bus *bus,
82118
const struct sfp_eeprom_id *id)
83119
{
@@ -117,6 +153,15 @@ phy_interface_t sfp_parse_interface(struct sfp_bus *bus,
117153
}
118154
EXPORT_SYMBOL_GPL(sfp_parse_interface);
119155

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+
*/
120165
void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
121166
unsigned long *support)
122167
{
@@ -293,6 +338,16 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
293338
bus->registered = false;
294339
}
295340

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+
*/
296351
int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
297352
{
298353
if (!bus->registered)
@@ -301,6 +356,17 @@ int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
301356
}
302357
EXPORT_SYMBOL_GPL(sfp_get_module_info);
303358

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+
*/
304370
int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
305371
u8 *data)
306372
{
@@ -310,6 +376,15 @@ int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
310376
}
311377
EXPORT_SYMBOL_GPL(sfp_get_module_eeprom);
312378

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+
*/
313388
void sfp_upstream_start(struct sfp_bus *bus)
314389
{
315390
if (bus->registered)
@@ -318,6 +393,15 @@ void sfp_upstream_start(struct sfp_bus *bus)
318393
}
319394
EXPORT_SYMBOL_GPL(sfp_upstream_start);
320395

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+
*/
321405
void sfp_upstream_stop(struct sfp_bus *bus)
322406
{
323407
if (bus->registered)
@@ -326,6 +410,19 @@ void sfp_upstream_stop(struct sfp_bus *bus)
326410
}
327411
EXPORT_SYMBOL_GPL(sfp_upstream_stop);
328412

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+
*/
329426
struct sfp_bus *sfp_register_upstream(struct device_node *np,
330427
struct net_device *ndev, void *upstream,
331428
const struct sfp_upstream_ops *ops)
@@ -353,6 +450,13 @@ struct sfp_bus *sfp_register_upstream(struct device_node *np,
353450
}
354451
EXPORT_SYMBOL_GPL(sfp_register_upstream);
355452

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+
*/
356460
void sfp_unregister_upstream(struct sfp_bus *bus)
357461
{
358462
rtnl_lock();

include/linux/sfp.h

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <linux/phy.h>
55

6-
struct __packed sfp_eeprom_base {
6+
struct sfp_eeprom_base {
77
u8 phys_id;
88
u8 phys_ext_id;
99
u8 connector;
@@ -166,12 +166,12 @@ struct __packed sfp_eeprom_base {
166166
union {
167167
__be16 optical_wavelength;
168168
u8 cable_spec;
169-
};
169+
} __packed;
170170
u8 reserved62;
171171
u8 cc_base;
172-
};
172+
} __packed;
173173

174-
struct __packed sfp_eeprom_ext {
174+
struct sfp_eeprom_ext {
175175
__be16 options;
176176
u8 br_max;
177177
u8 br_min;
@@ -181,12 +181,21 @@ struct __packed sfp_eeprom_ext {
181181
u8 enhopts;
182182
u8 sff8472_compliance;
183183
u8 cc_ext;
184-
};
185-
186-
struct __packed sfp_eeprom_id {
184+
} __packed;
185+
186+
/**
187+
* struct sfp_eeprom_id - raw SFP module identification information
188+
* @base: base SFP module identification structure
189+
* @ext: extended SFP module identification structure
190+
*
191+
* See the SFF-8472 specification and related documents for the definition
192+
* of these structure members. This can be obtained from
193+
* ftp://ftp.seagate.com/sff
194+
*/
195+
struct sfp_eeprom_id {
187196
struct sfp_eeprom_base base;
188197
struct sfp_eeprom_ext ext;
189-
};
198+
} __packed;
190199

191200
/* SFP EEPROM registers */
192201
enum {
@@ -353,13 +362,26 @@ struct ethtool_modinfo;
353362
struct net_device;
354363
struct sfp_bus;
355364

365+
/**
366+
* struct sfp_upstream_ops - upstream operations structure
367+
* @module_insert: called after a module has been detected to determine
368+
* whether the module is supported for the upstream device.
369+
* @module_remove: called after the module has been removed.
370+
* @link_down: called when the link is non-operational for whatever
371+
* reason.
372+
* @link_up: called when the link is operational.
373+
* @connect_phy: called when an I2C accessible PHY has been detected
374+
* on the module.
375+
* @disconnect_phy: called when a module with an I2C accessible PHY has
376+
* been removed.
377+
*/
356378
struct sfp_upstream_ops {
357-
int (*module_insert)(void *, const struct sfp_eeprom_id *id);
358-
void (*module_remove)(void *);
359-
void (*link_down)(void *);
360-
void (*link_up)(void *);
361-
int (*connect_phy)(void *, struct phy_device *);
362-
void (*disconnect_phy)(void *);
379+
int (*module_insert)(void *priv, const struct sfp_eeprom_id *id);
380+
void (*module_remove)(void *priv);
381+
void (*link_down)(void *priv);
382+
void (*link_up)(void *priv);
383+
int (*connect_phy)(void *priv, struct phy_device *);
384+
void (*disconnect_phy)(void *priv);
363385
};
364386

365387
#if IS_ENABLED(CONFIG_SFP)

0 commit comments

Comments
 (0)