2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-04-29 16:04:14 +08:00
|
|
|
/*
|
|
|
|
* linux/mdio.h: definitions for MDIO (clause 45) transceivers
|
|
|
|
* Copyright 2006-2009 Solarflare Communications Inc.
|
|
|
|
*/
|
|
|
|
#ifndef __LINUX_MDIO_H__
|
|
|
|
#define __LINUX_MDIO_H__
|
|
|
|
|
2012-10-13 17:46:48 +08:00
|
|
|
#include <uapi/linux/mdio.h>
|
2022-01-04 20:07:00 +08:00
|
|
|
#include <linux/bitfield.h>
|
2017-02-05 05:02:44 +08:00
|
|
|
#include <linux/mod_devicetable.h>
|
2009-04-29 16:04:14 +08:00
|
|
|
|
2020-05-26 23:29:36 +08:00
|
|
|
/* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit
|
|
|
|
* IEEE 802.3ae clause 45 addressing mode used by 10GIGE phy chips.
|
|
|
|
*/
|
|
|
|
#define MII_ADDR_C45 (1<<30)
|
|
|
|
#define MII_DEVADDR_C45_SHIFT 16
|
2022-01-04 20:07:00 +08:00
|
|
|
#define MII_DEVADDR_C45_MASK GENMASK(20, 16)
|
2020-05-26 23:29:36 +08:00
|
|
|
#define MII_REGADDR_C45_MASK GENMASK(15, 0)
|
|
|
|
|
2017-12-04 20:35:05 +08:00
|
|
|
struct gpio_desc;
|
2016-01-07 03:11:07 +08:00
|
|
|
struct mii_bus;
|
2020-06-26 23:53:23 +08:00
|
|
|
struct reset_control;
|
2012-02-29 22:23:27 +08:00
|
|
|
|
2016-04-12 03:40:05 +08:00
|
|
|
/* Multiple levels of nesting are possible. However typically this is
|
|
|
|
* limited to nested DSA like layer, a MUX layer, and the normal
|
|
|
|
* user. Instead of trying to handle the general case, just define
|
|
|
|
* these cases.
|
|
|
|
*/
|
|
|
|
enum mdio_mutex_lock_class {
|
|
|
|
MDIO_MUTEX_NORMAL,
|
|
|
|
MDIO_MUTEX_MUX,
|
|
|
|
MDIO_MUTEX_NESTED,
|
|
|
|
};
|
|
|
|
|
2016-01-07 03:11:16 +08:00
|
|
|
struct mdio_device {
|
|
|
|
struct device dev;
|
2016-01-07 03:11:26 +08:00
|
|
|
|
2016-01-07 03:11:16 +08:00
|
|
|
struct mii_bus *bus;
|
2017-02-05 05:02:44 +08:00
|
|
|
char modalias[MDIO_NAME_SIZE];
|
2016-01-07 03:11:27 +08:00
|
|
|
|
2016-01-07 03:11:23 +08:00
|
|
|
int (*bus_match)(struct device *dev, struct device_driver *drv);
|
2016-01-07 03:11:27 +08:00
|
|
|
void (*device_free)(struct mdio_device *mdiodev);
|
|
|
|
void (*device_remove)(struct mdio_device *mdiodev);
|
|
|
|
|
2016-01-07 03:11:16 +08:00
|
|
|
/* Bus address of the MDIO device (0-31) */
|
|
|
|
int addr;
|
2016-01-07 03:11:18 +08:00
|
|
|
int flags;
|
2019-04-18 05:59:22 +08:00
|
|
|
struct gpio_desc *reset_gpio;
|
2019-04-18 05:59:21 +08:00
|
|
|
struct reset_control *reset_ctrl;
|
2017-12-22 18:08:09 +08:00
|
|
|
unsigned int reset_assert_delay;
|
|
|
|
unsigned int reset_deassert_delay;
|
2016-01-07 03:11:16 +08:00
|
|
|
};
|
mdio, phy: fix -Wshadow warnings triggered by nested container_of()
container_of() macro hides a local variable '__mptr' inside. This
becomes a problem when several container_of() are nested in each
other within single line or plain macros.
As C preprocessor doesn't support generating random variable names,
the sole solution is to avoid defining macros that consist only of
container_of() calls, or they will self-shadow '__mptr' each time:
In file included from ./include/linux/bitmap.h:10,
from drivers/net/phy/phy_device.c:12:
drivers/net/phy/phy_device.c: In function ‘phy_device_release’:
./include/linux/kernel.h:693:8: warning: declaration of ‘__mptr’ shadows a previous local [-Wshadow]
693 | void *__mptr = (void *)(ptr); \
| ^~~~~~
./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~
./include/linux/mdio.h:52:27: note: in expansion of macro ‘container_of’
52 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
| ^~~~~~~~~~~~
./include/linux/phy.h:647:39: note: in expansion of macro ‘to_mdio_device’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~~~
drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
217 | kfree(to_phy_device(dev));
| ^~~~~~~~~~~~~
./include/linux/kernel.h:693:8: note: shadowed declaration is here
693 | void *__mptr = (void *)(ptr); \
| ^~~~~~
./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~
drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
217 | kfree(to_phy_device(dev));
| ^~~~~~~~~~~~~
As they are declared in header files, these warnings are highly
repetitive and very annoying (along with the one from linux/pci.h).
Convert the related macros from linux/{mdio,phy}.h to static inlines
to avoid self-shadowing and potentially improve bug-catching.
No functional changes implied.
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20210116161246.67075-1-alobakin@pm.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-17 00:13:22 +08:00
|
|
|
|
|
|
|
static inline struct mdio_device *to_mdio_device(const struct device *dev)
|
|
|
|
{
|
|
|
|
return container_of(dev, struct mdio_device, dev);
|
|
|
|
}
|
2016-01-07 03:11:16 +08:00
|
|
|
|
2016-01-07 03:11:26 +08:00
|
|
|
/* struct mdio_driver_common: Common to all MDIO drivers */
|
|
|
|
struct mdio_driver_common {
|
|
|
|
struct device_driver driver;
|
|
|
|
int flags;
|
|
|
|
};
|
2016-01-07 03:11:18 +08:00
|
|
|
#define MDIO_DEVICE_FLAG_PHY 1
|
mdio, phy: fix -Wshadow warnings triggered by nested container_of()
container_of() macro hides a local variable '__mptr' inside. This
becomes a problem when several container_of() are nested in each
other within single line or plain macros.
As C preprocessor doesn't support generating random variable names,
the sole solution is to avoid defining macros that consist only of
container_of() calls, or they will self-shadow '__mptr' each time:
In file included from ./include/linux/bitmap.h:10,
from drivers/net/phy/phy_device.c:12:
drivers/net/phy/phy_device.c: In function ‘phy_device_release’:
./include/linux/kernel.h:693:8: warning: declaration of ‘__mptr’ shadows a previous local [-Wshadow]
693 | void *__mptr = (void *)(ptr); \
| ^~~~~~
./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~
./include/linux/mdio.h:52:27: note: in expansion of macro ‘container_of’
52 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
| ^~~~~~~~~~~~
./include/linux/phy.h:647:39: note: in expansion of macro ‘to_mdio_device’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~~~
drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
217 | kfree(to_phy_device(dev));
| ^~~~~~~~~~~~~
./include/linux/kernel.h:693:8: note: shadowed declaration is here
693 | void *__mptr = (void *)(ptr); \
| ^~~~~~
./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~
drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
217 | kfree(to_phy_device(dev));
| ^~~~~~~~~~~~~
As they are declared in header files, these warnings are highly
repetitive and very annoying (along with the one from linux/pci.h).
Convert the related macros from linux/{mdio,phy}.h to static inlines
to avoid self-shadowing and potentially improve bug-catching.
No functional changes implied.
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20210116161246.67075-1-alobakin@pm.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-17 00:13:22 +08:00
|
|
|
|
|
|
|
static inline struct mdio_driver_common *
|
|
|
|
to_mdio_common_driver(const struct device_driver *driver)
|
|
|
|
{
|
|
|
|
return container_of(driver, struct mdio_driver_common, driver);
|
|
|
|
}
|
2016-01-07 03:11:26 +08:00
|
|
|
|
|
|
|
/* struct mdio_driver: Generic MDIO driver */
|
|
|
|
struct mdio_driver {
|
|
|
|
struct mdio_driver_common mdiodrv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called during discovery. Used to set
|
|
|
|
* up device-specific structures, if any
|
|
|
|
*/
|
|
|
|
int (*probe)(struct mdio_device *mdiodev);
|
|
|
|
|
|
|
|
/* Clears up any memory if needed */
|
|
|
|
void (*remove)(struct mdio_device *mdiodev);
|
2021-09-17 21:34:32 +08:00
|
|
|
|
|
|
|
/* Quiesces the device on system shutdown, turns off interrupts etc */
|
|
|
|
void (*shutdown)(struct mdio_device *mdiodev);
|
2016-01-07 03:11:26 +08:00
|
|
|
};
|
mdio, phy: fix -Wshadow warnings triggered by nested container_of()
container_of() macro hides a local variable '__mptr' inside. This
becomes a problem when several container_of() are nested in each
other within single line or plain macros.
As C preprocessor doesn't support generating random variable names,
the sole solution is to avoid defining macros that consist only of
container_of() calls, or they will self-shadow '__mptr' each time:
In file included from ./include/linux/bitmap.h:10,
from drivers/net/phy/phy_device.c:12:
drivers/net/phy/phy_device.c: In function ‘phy_device_release’:
./include/linux/kernel.h:693:8: warning: declaration of ‘__mptr’ shadows a previous local [-Wshadow]
693 | void *__mptr = (void *)(ptr); \
| ^~~~~~
./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~
./include/linux/mdio.h:52:27: note: in expansion of macro ‘container_of’
52 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
| ^~~~~~~~~~~~
./include/linux/phy.h:647:39: note: in expansion of macro ‘to_mdio_device’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~~~
drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
217 | kfree(to_phy_device(dev));
| ^~~~~~~~~~~~~
./include/linux/kernel.h:693:8: note: shadowed declaration is here
693 | void *__mptr = (void *)(ptr); \
| ^~~~~~
./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
| ^~~~~~~~~~~~
drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
217 | kfree(to_phy_device(dev));
| ^~~~~~~~~~~~~
As they are declared in header files, these warnings are highly
repetitive and very annoying (along with the one from linux/pci.h).
Convert the related macros from linux/{mdio,phy}.h to static inlines
to avoid self-shadowing and potentially improve bug-catching.
No functional changes implied.
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20210116161246.67075-1-alobakin@pm.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-17 00:13:22 +08:00
|
|
|
|
|
|
|
static inline struct mdio_driver *
|
|
|
|
to_mdio_driver(const struct device_driver *driver)
|
|
|
|
{
|
|
|
|
return container_of(to_mdio_common_driver(driver), struct mdio_driver,
|
|
|
|
mdiodrv);
|
|
|
|
}
|
2016-01-07 03:11:26 +08:00
|
|
|
|
2019-09-04 22:00:20 +08:00
|
|
|
/* device driver data */
|
|
|
|
static inline void mdiodev_set_drvdata(struct mdio_device *mdio, void *data)
|
|
|
|
{
|
|
|
|
dev_set_drvdata(&mdio->dev, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *mdiodev_get_drvdata(struct mdio_device *mdio)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(&mdio->dev);
|
|
|
|
}
|
|
|
|
|
2016-01-07 03:11:26 +08:00
|
|
|
void mdio_device_free(struct mdio_device *mdiodev);
|
|
|
|
struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
|
|
|
|
int mdio_device_register(struct mdio_device *mdiodev);
|
|
|
|
void mdio_device_remove(struct mdio_device *mdiodev);
|
2017-12-04 20:35:05 +08:00
|
|
|
void mdio_device_reset(struct mdio_device *mdiodev, int value);
|
2016-01-07 03:11:26 +08:00
|
|
|
int mdio_driver_register(struct mdio_driver *drv);
|
|
|
|
void mdio_driver_unregister(struct mdio_driver *drv);
|
2017-02-05 05:02:44 +08:00
|
|
|
int mdio_device_bus_match(struct device *dev, struct device_driver *drv);
|
2016-01-07 03:11:18 +08:00
|
|
|
|
2009-04-29 16:04:14 +08:00
|
|
|
static inline bool mdio_phy_id_is_c45(int phy_id)
|
|
|
|
{
|
|
|
|
return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline __u16 mdio_phy_id_prtad(int phy_id)
|
|
|
|
{
|
|
|
|
return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline __u16 mdio_phy_id_devad(int phy_id)
|
|
|
|
{
|
|
|
|
return phy_id & MDIO_PHY_ID_DEVAD;
|
|
|
|
}
|
|
|
|
|
2009-04-29 16:04:46 +08:00
|
|
|
/**
|
|
|
|
* struct mdio_if_info - Ethernet controller MDIO interface
|
|
|
|
* @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
|
|
|
|
* @mmds: Mask of MMDs expected to be present in the PHY. This must be
|
|
|
|
* non-zero unless @prtad = %MDIO_PRTAD_NONE.
|
|
|
|
* @mode_support: MDIO modes supported. If %MDIO_SUPPORTS_C22 is set then
|
|
|
|
* MII register access will be passed through with @devad =
|
|
|
|
* %MDIO_DEVAD_NONE. If %MDIO_EMULATE_C22 is set then access to
|
|
|
|
* commonly used clause 22 registers will be translated into
|
|
|
|
* clause 45 registers.
|
|
|
|
* @dev: Net device structure
|
|
|
|
* @mdio_read: Register read function; returns value or negative error code
|
|
|
|
* @mdio_write: Register write function; returns 0 or negative error code
|
|
|
|
*/
|
|
|
|
struct mdio_if_info {
|
|
|
|
int prtad;
|
2009-08-19 11:13:03 +08:00
|
|
|
u32 mmds;
|
2009-04-29 16:04:46 +08:00
|
|
|
unsigned mode_support;
|
|
|
|
|
|
|
|
struct net_device *dev;
|
|
|
|
int (*mdio_read)(struct net_device *dev, int prtad, int devad,
|
|
|
|
u16 addr);
|
|
|
|
int (*mdio_write)(struct net_device *dev, int prtad, int devad,
|
|
|
|
u16 addr, u16 val);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MDIO_PRTAD_NONE (-1)
|
|
|
|
#define MDIO_DEVAD_NONE (-1)
|
2012-02-29 22:23:27 +08:00
|
|
|
#define MDIO_SUPPORTS_C22 1
|
|
|
|
#define MDIO_SUPPORTS_C45 2
|
2009-04-29 16:04:46 +08:00
|
|
|
#define MDIO_EMULATE_C22 4
|
|
|
|
|
|
|
|
struct ethtool_cmd;
|
|
|
|
struct ethtool_pauseparam;
|
|
|
|
extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
|
|
|
|
extern int mdio_set_flag(const struct mdio_if_info *mdio,
|
|
|
|
int prtad, int devad, u16 addr, int mask,
|
|
|
|
bool sense);
|
|
|
|
extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
|
|
|
|
extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
|
|
|
|
extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
|
|
|
|
struct ethtool_cmd *ecmd,
|
|
|
|
u32 npage_adv, u32 npage_lpa);
|
2017-01-02 02:02:45 +08:00
|
|
|
extern void
|
|
|
|
mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
|
|
|
|
struct ethtool_link_ksettings *cmd,
|
|
|
|
u32 npage_adv, u32 npage_lpa);
|
2009-04-29 16:04:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* mdio45_ethtool_gset - get settings for ETHTOOL_GSET
|
|
|
|
* @mdio: MDIO interface
|
|
|
|
* @ecmd: Ethtool request structure
|
|
|
|
*
|
|
|
|
* Since the CSRs for auto-negotiation using next pages are not fully
|
|
|
|
* standardised, this function does not attempt to decode them. Use
|
|
|
|
* mdio45_ethtool_gset_npage() to specify advertisement bits from next
|
|
|
|
* pages.
|
|
|
|
*/
|
|
|
|
static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
|
|
|
|
struct ethtool_cmd *ecmd)
|
|
|
|
{
|
|
|
|
mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
|
|
|
|
}
|
|
|
|
|
2017-01-02 02:02:45 +08:00
|
|
|
/**
|
|
|
|
* mdio45_ethtool_ksettings_get - get settings for ETHTOOL_GLINKSETTINGS
|
|
|
|
* @mdio: MDIO interface
|
|
|
|
* @cmd: Ethtool request structure
|
|
|
|
*
|
|
|
|
* Since the CSRs for auto-negotiation using next pages are not fully
|
|
|
|
* standardised, this function does not attempt to decode them. Use
|
|
|
|
* mdio45_ethtool_ksettings_get_npage() to specify advertisement bits
|
|
|
|
* from next pages.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio,
|
|
|
|
struct ethtool_link_ksettings *cmd)
|
|
|
|
{
|
|
|
|
mdio45_ethtool_ksettings_get_npage(mdio, cmd, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-04-29 16:04:46 +08:00
|
|
|
extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
|
|
|
|
struct mii_ioctl_data *mii_data, int cmd);
|
|
|
|
|
2012-08-20 12:55:29 +08:00
|
|
|
/**
|
|
|
|
* mmd_eee_cap_to_ethtool_sup_t
|
|
|
|
* @eee_cap: value of the MMD EEE Capability register
|
|
|
|
*
|
|
|
|
* A small helper function that translates MMD EEE Capability (3.20) bits
|
|
|
|
* to ethtool supported settings.
|
|
|
|
*/
|
|
|
|
static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
|
|
|
|
{
|
|
|
|
u32 supported = 0;
|
|
|
|
|
|
|
|
if (eee_cap & MDIO_EEE_100TX)
|
|
|
|
supported |= SUPPORTED_100baseT_Full;
|
|
|
|
if (eee_cap & MDIO_EEE_1000T)
|
|
|
|
supported |= SUPPORTED_1000baseT_Full;
|
|
|
|
if (eee_cap & MDIO_EEE_10GT)
|
|
|
|
supported |= SUPPORTED_10000baseT_Full;
|
|
|
|
if (eee_cap & MDIO_EEE_1000KX)
|
|
|
|
supported |= SUPPORTED_1000baseKX_Full;
|
|
|
|
if (eee_cap & MDIO_EEE_10GKX4)
|
|
|
|
supported |= SUPPORTED_10000baseKX4_Full;
|
|
|
|
if (eee_cap & MDIO_EEE_10GKR)
|
|
|
|
supported |= SUPPORTED_10000baseKR_Full;
|
|
|
|
|
|
|
|
return supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmd_eee_adv_to_ethtool_adv_t
|
|
|
|
* @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
|
|
|
|
*
|
|
|
|
* A small helper function that translates the MMD EEE Advertisment (7.60)
|
|
|
|
* and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
|
|
|
|
* settings.
|
|
|
|
*/
|
|
|
|
static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
|
|
|
|
{
|
|
|
|
u32 adv = 0;
|
|
|
|
|
|
|
|
if (eee_adv & MDIO_EEE_100TX)
|
|
|
|
adv |= ADVERTISED_100baseT_Full;
|
|
|
|
if (eee_adv & MDIO_EEE_1000T)
|
|
|
|
adv |= ADVERTISED_1000baseT_Full;
|
|
|
|
if (eee_adv & MDIO_EEE_10GT)
|
|
|
|
adv |= ADVERTISED_10000baseT_Full;
|
|
|
|
if (eee_adv & MDIO_EEE_1000KX)
|
|
|
|
adv |= ADVERTISED_1000baseKX_Full;
|
|
|
|
if (eee_adv & MDIO_EEE_10GKX4)
|
|
|
|
adv |= ADVERTISED_10000baseKX4_Full;
|
|
|
|
if (eee_adv & MDIO_EEE_10GKR)
|
|
|
|
adv |= ADVERTISED_10000baseKR_Full;
|
|
|
|
|
|
|
|
return adv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ethtool_adv_to_mmd_eee_adv_t
|
|
|
|
* @adv: the ethtool advertisement settings
|
|
|
|
*
|
|
|
|
* A small helper function that translates ethtool advertisement settings
|
|
|
|
* to EEE advertisements for the MMD EEE Advertisement (7.60) and
|
|
|
|
* MMD EEE Link Partner Ability (7.61) registers.
|
|
|
|
*/
|
|
|
|
static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
|
|
|
|
{
|
|
|
|
u16 reg = 0;
|
|
|
|
|
|
|
|
if (adv & ADVERTISED_100baseT_Full)
|
|
|
|
reg |= MDIO_EEE_100TX;
|
|
|
|
if (adv & ADVERTISED_1000baseT_Full)
|
|
|
|
reg |= MDIO_EEE_1000T;
|
|
|
|
if (adv & ADVERTISED_10000baseT_Full)
|
|
|
|
reg |= MDIO_EEE_10GT;
|
|
|
|
if (adv & ADVERTISED_1000baseKX_Full)
|
|
|
|
reg |= MDIO_EEE_1000KX;
|
|
|
|
if (adv & ADVERTISED_10000baseKX4_Full)
|
|
|
|
reg |= MDIO_EEE_10GKX4;
|
|
|
|
if (adv & ADVERTISED_10000baseKR_Full)
|
|
|
|
reg |= MDIO_EEE_10GKR;
|
|
|
|
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2019-02-17 17:28:33 +08:00
|
|
|
/**
|
|
|
|
* linkmode_adv_to_mii_10gbt_adv_t
|
|
|
|
* @advertising: the linkmode advertisement settings
|
|
|
|
*
|
|
|
|
* A small helper function that translates linkmode advertisement
|
|
|
|
* settings to phy autonegotiation advertisements for the C45
|
|
|
|
* 10GBASE-T AN CONTROL (7.32) register.
|
|
|
|
*/
|
|
|
|
static inline u32 linkmode_adv_to_mii_10gbt_adv_t(unsigned long *advertising)
|
|
|
|
{
|
|
|
|
u32 result = 0;
|
|
|
|
|
|
|
|
if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
|
|
|
|
advertising))
|
|
|
|
result |= MDIO_AN_10GBT_CTRL_ADV2_5G;
|
|
|
|
if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
|
|
|
|
advertising))
|
|
|
|
result |= MDIO_AN_10GBT_CTRL_ADV5G;
|
|
|
|
if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
|
|
|
|
advertising))
|
|
|
|
result |= MDIO_AN_10GBT_CTRL_ADV10G;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-17 00:26:05 +08:00
|
|
|
/**
|
|
|
|
* mii_10gbt_stat_mod_linkmode_lpa_t
|
|
|
|
* @advertising: target the linkmode advertisement settings
|
2020-09-23 06:29:02 +08:00
|
|
|
* @lpa: value of the C45 10GBASE-T AN STATUS register
|
2019-02-17 00:26:05 +08:00
|
|
|
*
|
|
|
|
* A small helper function that translates C45 10GBASE-T AN STATUS register bits
|
|
|
|
* to linkmode advertisement settings. Other bits in advertising aren't changed.
|
|
|
|
*/
|
|
|
|
static inline void mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long *advertising,
|
|
|
|
u32 lpa)
|
|
|
|
{
|
|
|
|
linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
|
|
|
|
advertising, lpa & MDIO_AN_10GBT_STAT_LP2_5G);
|
|
|
|
linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
|
|
|
|
advertising, lpa & MDIO_AN_10GBT_STAT_LP5G);
|
|
|
|
linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
|
|
|
|
advertising, lpa & MDIO_AN_10GBT_STAT_LP10G);
|
|
|
|
}
|
|
|
|
|
2022-04-29 23:34:34 +08:00
|
|
|
/**
|
|
|
|
* mii_t1_adv_l_mod_linkmode_t
|
|
|
|
* @advertising: target the linkmode advertisement settings
|
|
|
|
* @lpa: value of the BASE-T1 Autonegotiation Advertisement [15:0] Register
|
|
|
|
*
|
|
|
|
* A small helper function that translates BASE-T1 Autonegotiation
|
|
|
|
* Advertisement [15:0] Register bits to linkmode advertisement settings.
|
|
|
|
* Other bits in advertising aren't changed.
|
|
|
|
*/
|
|
|
|
static inline void mii_t1_adv_l_mod_linkmode_t(unsigned long *advertising, u32 lpa)
|
|
|
|
{
|
|
|
|
linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising,
|
|
|
|
lpa & MDIO_AN_T1_ADV_L_PAUSE_CAP);
|
|
|
|
linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising,
|
|
|
|
lpa & MDIO_AN_T1_ADV_L_PAUSE_ASYM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mii_t1_adv_m_mod_linkmode_t
|
|
|
|
* @advertising: target the linkmode advertisement settings
|
|
|
|
* @lpa: value of the BASE-T1 Autonegotiation Advertisement [31:16] Register
|
|
|
|
*
|
|
|
|
* A small helper function that translates BASE-T1 Autonegotiation
|
|
|
|
* Advertisement [31:16] Register bits to linkmode advertisement settings.
|
|
|
|
* Other bits in advertising aren't changed.
|
|
|
|
*/
|
|
|
|
static inline void mii_t1_adv_m_mod_linkmode_t(unsigned long *advertising, u32 lpa)
|
|
|
|
{
|
|
|
|
linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
|
|
|
|
advertising, lpa & MDIO_AN_T1_ADV_M_B10L);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* linkmode_adv_to_mii_t1_adv_l_t
|
|
|
|
* @advertising: the linkmode advertisement settings
|
|
|
|
*
|
|
|
|
* A small helper function that translates linkmode advertisement
|
|
|
|
* settings to phy autonegotiation advertisements for the
|
|
|
|
* BASE-T1 Autonegotiation Advertisement [15:0] Register.
|
|
|
|
*/
|
|
|
|
static inline u32 linkmode_adv_to_mii_t1_adv_l_t(unsigned long *advertising)
|
|
|
|
{
|
|
|
|
u32 result = 0;
|
|
|
|
|
|
|
|
if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising))
|
|
|
|
result |= MDIO_AN_T1_ADV_L_PAUSE_CAP;
|
|
|
|
if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising))
|
|
|
|
result |= MDIO_AN_T1_ADV_L_PAUSE_ASYM;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* linkmode_adv_to_mii_t1_adv_m_t
|
|
|
|
* @advertising: the linkmode advertisement settings
|
|
|
|
*
|
|
|
|
* A small helper function that translates linkmode advertisement
|
|
|
|
* settings to phy autonegotiation advertisements for the
|
|
|
|
* BASE-T1 Autonegotiation Advertisement [31:16] Register.
|
|
|
|
*/
|
|
|
|
static inline u32 linkmode_adv_to_mii_t1_adv_m_t(unsigned long *advertising)
|
|
|
|
{
|
|
|
|
u32 result = 0;
|
|
|
|
|
|
|
|
if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, advertising))
|
|
|
|
result |= MDIO_AN_T1_ADV_M_B10L;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-02 18:58:27 +08:00
|
|
|
int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
|
|
|
|
int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
|
2020-03-17 22:52:31 +08:00
|
|
|
int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
|
|
|
|
u16 mask, u16 set);
|
2018-01-02 18:58:27 +08:00
|
|
|
|
2016-01-07 03:11:07 +08:00
|
|
|
int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
|
|
|
|
int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
|
|
|
|
int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
|
|
|
|
int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
|
2020-03-17 22:52:31 +08:00
|
|
|
int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask,
|
|
|
|
u16 set);
|
2021-10-06 20:19:20 +08:00
|
|
|
int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
|
|
|
|
u16 mask, u16 set);
|
2016-01-07 03:11:07 +08:00
|
|
|
|
2021-10-22 23:59:12 +08:00
|
|
|
static inline int mdiodev_read(struct mdio_device *mdiodev, u32 regnum)
|
|
|
|
{
|
|
|
|
return mdiobus_read(mdiodev->bus, mdiodev->addr, regnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mdiodev_write(struct mdio_device *mdiodev, u32 regnum,
|
|
|
|
u16 val)
|
|
|
|
{
|
|
|
|
return mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mdiodev_modify(struct mdio_device *mdiodev, u32 regnum,
|
|
|
|
u16 mask, u16 set)
|
|
|
|
{
|
|
|
|
return mdiobus_modify(mdiodev->bus, mdiodev->addr, regnum, mask, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mdiodev_modify_changed(struct mdio_device *mdiodev,
|
|
|
|
u32 regnum, u16 mask, u16 set)
|
|
|
|
{
|
|
|
|
return mdiobus_modify_changed(mdiodev->bus, mdiodev->addr, regnum,
|
|
|
|
mask, set);
|
|
|
|
}
|
|
|
|
|
2020-05-26 23:29:36 +08:00
|
|
|
static inline u32 mdiobus_c45_addr(int devad, u16 regnum)
|
|
|
|
{
|
|
|
|
return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum;
|
|
|
|
}
|
|
|
|
|
2022-01-04 20:07:00 +08:00
|
|
|
static inline u16 mdiobus_c45_regad(u32 regnum)
|
|
|
|
{
|
|
|
|
return FIELD_GET(MII_REGADDR_C45_MASK, regnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u16 mdiobus_c45_devad(u32 regnum)
|
|
|
|
{
|
|
|
|
return FIELD_GET(MII_DEVADDR_C45_MASK, regnum);
|
|
|
|
}
|
|
|
|
|
2020-05-26 23:29:36 +08:00
|
|
|
static inline int __mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
|
|
|
|
u16 regnum)
|
|
|
|
{
|
|
|
|
return __mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __mdiobus_c45_write(struct mii_bus *bus, int prtad, int devad,
|
|
|
|
u16 regnum, u16 val)
|
|
|
|
{
|
|
|
|
return __mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum),
|
|
|
|
val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
|
|
|
|
u16 regnum)
|
|
|
|
{
|
|
|
|
return mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
|
|
|
|
}
|
|
|
|
|
2020-08-30 16:34:00 +08:00
|
|
|
static inline int mdiobus_c45_write(struct mii_bus *bus, int prtad, int devad,
|
|
|
|
u16 regnum, u16 val)
|
|
|
|
{
|
|
|
|
return mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum), val);
|
|
|
|
}
|
|
|
|
|
2016-01-07 03:11:18 +08:00
|
|
|
int mdiobus_register_device(struct mdio_device *mdiodev);
|
|
|
|
int mdiobus_unregister_device(struct mdio_device *mdiodev);
|
|
|
|
bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
|
|
|
|
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
|
|
|
|
|
2016-01-07 03:11:26 +08:00
|
|
|
/**
|
2017-01-23 13:17:32 +08:00
|
|
|
* mdio_module_driver() - Helper macro for registering mdio drivers
|
2020-09-23 06:29:02 +08:00
|
|
|
* @_mdio_driver: driver to register
|
2016-01-07 03:11:26 +08:00
|
|
|
*
|
|
|
|
* Helper macro for MDIO drivers which do not do anything special in module
|
|
|
|
* init/exit. Each module may only use this macro once, and calling it
|
|
|
|
* replaces module_init() and module_exit().
|
|
|
|
*/
|
|
|
|
#define mdio_module_driver(_mdio_driver) \
|
|
|
|
static int __init mdio_module_init(void) \
|
|
|
|
{ \
|
|
|
|
return mdio_driver_register(&_mdio_driver); \
|
|
|
|
} \
|
|
|
|
module_init(mdio_module_init); \
|
|
|
|
static void __exit mdio_module_exit(void) \
|
|
|
|
{ \
|
|
|
|
mdio_driver_unregister(&_mdio_driver); \
|
|
|
|
} \
|
|
|
|
module_exit(mdio_module_exit)
|
|
|
|
|
2009-04-29 16:04:14 +08:00
|
|
|
#endif /* __LINUX_MDIO_H__ */
|