linux/include/linux/mdio.h
<<
>>
Prefs
   1/*
   2 * linux/mdio.h: definitions for MDIO (clause 45) transceivers
   3 * Copyright 2006-2009 Solarflare Communications Inc.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms of the GNU General Public License version 2 as published
   7 * by the Free Software Foundation, incorporated herein by reference.
   8 */
   9#ifndef __LINUX_MDIO_H__
  10#define __LINUX_MDIO_H__
  11
  12#include <uapi/linux/mdio.h>
  13
  14struct mii_bus;
  15
  16static inline bool mdio_phy_id_is_c45(int phy_id)
  17{
  18        return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
  19}
  20
  21static inline __u16 mdio_phy_id_prtad(int phy_id)
  22{
  23        return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
  24}
  25
  26static inline __u16 mdio_phy_id_devad(int phy_id)
  27{
  28        return phy_id & MDIO_PHY_ID_DEVAD;
  29}
  30
  31/**
  32 * struct mdio_if_info - Ethernet controller MDIO interface
  33 * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
  34 * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
  35 *      non-zero unless @prtad = %MDIO_PRTAD_NONE.
  36 * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
  37 *      MII register access will be passed through with @devad =
  38 *      %MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
  39 *      commonly used clause 22 registers will be translated into
  40 *      clause 45 registers.
  41 * @dev: Net device structure
  42 * @mdio_read: Register read function; returns value or negative error code
  43 * @mdio_write: Register write function; returns 0 or negative error code
  44 */
  45struct mdio_if_info {
  46        int prtad;
  47        u32 mmds;
  48        unsigned mode_support;
  49
  50        struct net_device *dev;
  51        int (*mdio_read)(struct net_device *dev, int prtad, int devad,
  52                         u16 addr);
  53        int (*mdio_write)(struct net_device *dev, int prtad, int devad,
  54                          u16 addr, u16 val);
  55};
  56
  57#define MDIO_PRTAD_NONE                 (-1)
  58#define MDIO_DEVAD_NONE                 (-1)
  59#define MDIO_SUPPORTS_C22               1
  60#define MDIO_SUPPORTS_C45               2
  61#define MDIO_EMULATE_C22                4
  62
  63struct ethtool_cmd;
  64struct ethtool_pauseparam;
  65extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
  66extern int mdio_set_flag(const struct mdio_if_info *mdio,
  67                         int prtad, int devad, u16 addr, int mask,
  68                         bool sense);
  69extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
  70extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
  71extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
  72                                      struct ethtool_cmd *ecmd,
  73                                      u32 npage_adv, u32 npage_lpa);
  74extern void
  75mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
  76                                   struct ethtool_link_ksettings *cmd,
  77                                   u32 npage_adv, u32 npage_lpa);
  78extern void
  79mdio45_ethtool_spauseparam_an(const struct mdio_if_info *mdio,
  80                              const struct ethtool_pauseparam *ecmd);
  81
  82/**
  83 * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
  84 * @mdio: MDIO interface
  85 * @ecmd: Ethtool request structure
  86 *
  87 * Since the CSRs for auto-negotiation using next pages are not fully
  88 * standardised, this function does not attempt to decode them.  Use
  89 * mdio45_ethtool_gset_npage() to specify advertisement bits from next
  90 * pages.
  91 */
  92static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
  93                                       struct ethtool_cmd *ecmd)
  94{
  95        mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
  96}
  97
  98/**
  99 * mdio45_ethtool_ksettings_get - get settings for ETHTOOL_GLINKSETTINGS
 100 * @mdio: MDIO interface
 101 * @cmd: Ethtool request structure
 102 *
 103 * Since the CSRs for auto-negotiation using next pages are not fully
 104 * standardised, this function does not attempt to decode them.  Use
 105 * mdio45_ethtool_ksettings_get_npage() to specify advertisement bits
 106 * from next pages.
 107 */
 108static inline void
 109mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio,
 110                             struct ethtool_link_ksettings *cmd)
 111{
 112        mdio45_ethtool_ksettings_get_npage(mdio, cmd, 0, 0);
 113}
 114
 115extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
 116                          struct mii_ioctl_data *mii_data, int cmd);
 117
 118/**
 119 * mmd_eee_cap_to_ethtool_sup_t
 120 * @eee_cap: value of the MMD EEE Capability register
 121 *
 122 * A small helper function that translates MMD EEE Capability (3.20) bits
 123 * to ethtool supported settings.
 124 */
 125static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
 126{
 127        u32 supported = 0;
 128
 129        if (eee_cap & MDIO_EEE_100TX)
 130                supported |= SUPPORTED_100baseT_Full;
 131        if (eee_cap & MDIO_EEE_1000T)
 132                supported |= SUPPORTED_1000baseT_Full;
 133        if (eee_cap & MDIO_EEE_10GT)
 134                supported |= SUPPORTED_10000baseT_Full;
 135        if (eee_cap & MDIO_EEE_1000KX)
 136                supported |= SUPPORTED_1000baseKX_Full;
 137        if (eee_cap & MDIO_EEE_10GKX4)
 138                supported |= SUPPORTED_10000baseKX4_Full;
 139        if (eee_cap & MDIO_EEE_10GKR)
 140                supported |= SUPPORTED_10000baseKR_Full;
 141
 142        return supported;
 143}
 144
 145/**
 146 * mmd_eee_adv_to_ethtool_adv_t
 147 * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
 148 *
 149 * A small helper function that translates the MMD EEE Advertisment (7.60)
 150 * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
 151 * settings.
 152 */
 153static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
 154{
 155        u32 adv = 0;
 156
 157        if (eee_adv & MDIO_EEE_100TX)
 158                adv |= ADVERTISED_100baseT_Full;
 159        if (eee_adv & MDIO_EEE_1000T)
 160                adv |= ADVERTISED_1000baseT_Full;
 161        if (eee_adv & MDIO_EEE_10GT)
 162                adv |= ADVERTISED_10000baseT_Full;
 163        if (eee_adv & MDIO_EEE_1000KX)
 164                adv |= ADVERTISED_1000baseKX_Full;
 165        if (eee_adv & MDIO_EEE_10GKX4)
 166                adv |= ADVERTISED_10000baseKX4_Full;
 167        if (eee_adv & MDIO_EEE_10GKR)
 168                adv |= ADVERTISED_10000baseKR_Full;
 169
 170        return adv;
 171}
 172
 173/**
 174 * ethtool_adv_to_mmd_eee_adv_t
 175 * @adv: the ethtool advertisement settings
 176 *
 177 * A small helper function that translates ethtool advertisement settings
 178 * to EEE advertisements for the MMD EEE Advertisement (7.60) and
 179 * MMD EEE Link Partner Ability (7.61) registers.
 180 */
 181static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
 182{
 183        u16 reg = 0;
 184
 185        if (adv & ADVERTISED_100baseT_Full)
 186                reg |= MDIO_EEE_100TX;
 187        if (adv & ADVERTISED_1000baseT_Full)
 188                reg |= MDIO_EEE_1000T;
 189        if (adv & ADVERTISED_10000baseT_Full)
 190                reg |= MDIO_EEE_10GT;
 191        if (adv & ADVERTISED_1000baseKX_Full)
 192                reg |= MDIO_EEE_1000KX;
 193        if (adv & ADVERTISED_10000baseKX4_Full)
 194                reg |= MDIO_EEE_10GKX4;
 195        if (adv & ADVERTISED_10000baseKR_Full)
 196                reg |= MDIO_EEE_10GKR;
 197
 198        return reg;
 199}
 200
 201int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
 202int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
 203int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
 204int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
 205
 206#endif /* __LINUX_MDIO_H__ */
 207