Skip to content

Commit d740513

Browse files
lunndavem330
authored andcommitted
phy: sfp: add netlink SFP support to generic SFP code
The new netlink API for reading SFP data requires a new op to be implemented. The idea of the new netlink SFP code is that userspace is responsible to parsing the EEPROM data and requesting pages, rather than have the kernel decide what pages are interesting and returning them. This allows greater flexibility for newer formats. Currently the generic SFP code only supports simple SFPs. Allow i2c address 0x50 and 0x51 to be accessed with page and bank must always be 0. This interface will later be extended when for example QSFP support is added. Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: Vladyslav Tarasiuk <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 96d971e commit d740513

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

drivers/net/phy/sfp-bus.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,26 @@ int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
555555
}
556556
EXPORT_SYMBOL_GPL(sfp_get_module_eeprom);
557557

558+
/**
559+
* sfp_get_module_eeprom_by_page() - Read a page from the SFP module EEPROM
560+
* @bus: a pointer to the &struct sfp_bus structure for the sfp module
561+
* @page: a &struct ethtool_module_eeprom
562+
* @extack: extack for reporting problems
563+
*
564+
* Read an EEPROM page as specified by the supplied @page. See the
565+
* documentation for &struct ethtool_module_eeprom for the page to be read.
566+
*
567+
* Returns 0 on success or a negative errno number. More error
568+
* information might be provided via extack
569+
*/
570+
int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
571+
const struct ethtool_module_eeprom *page,
572+
struct netlink_ext_ack *extack)
573+
{
574+
return bus->socket_ops->module_eeprom_by_page(bus->sfp, page, extack);
575+
}
576+
EXPORT_SYMBOL_GPL(sfp_get_module_eeprom_by_page);
577+
558578
/**
559579
* sfp_upstream_start() - Inform the SFP that the network device is up
560580
* @bus: a pointer to the &struct sfp_bus structure for the sfp module

drivers/net/phy/sfp.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,13 +2330,38 @@ static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee,
23302330
return 0;
23312331
}
23322332

2333+
static int sfp_module_eeprom_by_page(struct sfp *sfp,
2334+
const struct ethtool_module_eeprom *page,
2335+
struct netlink_ext_ack *extack)
2336+
{
2337+
if (page->bank) {
2338+
NL_SET_ERR_MSG(extack, "Banks not supported");
2339+
return -EOPNOTSUPP;
2340+
}
2341+
2342+
if (page->page) {
2343+
NL_SET_ERR_MSG(extack, "Only page 0 supported");
2344+
return -EOPNOTSUPP;
2345+
}
2346+
2347+
if (page->i2c_address != 0x50 &&
2348+
page->i2c_address != 0x51) {
2349+
NL_SET_ERR_MSG(extack, "Only address 0x50 and 0x51 supported");
2350+
return -EOPNOTSUPP;
2351+
}
2352+
2353+
return sfp_read(sfp, page->i2c_address == 0x51, page->offset,
2354+
page->data, page->length);
2355+
};
2356+
23332357
static const struct sfp_socket_ops sfp_module_ops = {
23342358
.attach = sfp_attach,
23352359
.detach = sfp_detach,
23362360
.start = sfp_start,
23372361
.stop = sfp_stop,
23382362
.module_info = sfp_module_info,
23392363
.module_eeprom = sfp_module_eeprom,
2364+
.module_eeprom_by_page = sfp_module_eeprom_by_page,
23402365
};
23412366

23422367
static void sfp_timeout(struct work_struct *work)

drivers/net/phy/sfp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ struct sfp_socket_ops {
1414
int (*module_info)(struct sfp *sfp, struct ethtool_modinfo *modinfo);
1515
int (*module_eeprom)(struct sfp *sfp, struct ethtool_eeprom *ee,
1616
u8 *data);
17+
int (*module_eeprom_by_page)(struct sfp *sfp,
18+
const struct ethtool_module_eeprom *page,
19+
struct netlink_ext_ack *extack);
1720
};
1821

1922
int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev);

include/linux/sfp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ phy_interface_t sfp_select_interface(struct sfp_bus *bus,
542542
int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo);
543543
int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
544544
u8 *data);
545+
int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
546+
const struct ethtool_module_eeprom *page,
547+
struct netlink_ext_ack *extack);
545548
void sfp_upstream_start(struct sfp_bus *bus);
546549
void sfp_upstream_stop(struct sfp_bus *bus);
547550
void sfp_bus_put(struct sfp_bus *bus);
@@ -587,6 +590,13 @@ static inline int sfp_get_module_eeprom(struct sfp_bus *bus,
587590
return -EOPNOTSUPP;
588591
}
589592

593+
static inline int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
594+
const struct ethtool_module_eeprom *page,
595+
struct netlink_ext_ack *extack)
596+
{
597+
return -EOPNOTSUPP;
598+
}
599+
590600
static inline void sfp_upstream_start(struct sfp_bus *bus)
591601
{
592602
}

0 commit comments

Comments
 (0)