0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef _CXGB_CPHY_H_
0030 #define _CXGB_CPHY_H_
0031
0032 #include "common.h"
0033
0034 struct mdio_ops {
0035 void (*init)(adapter_t *adapter, const struct board_info *bi);
0036 int (*read)(struct net_device *dev, int phy_addr, int mmd_addr,
0037 u16 reg_addr);
0038 int (*write)(struct net_device *dev, int phy_addr, int mmd_addr,
0039 u16 reg_addr, u16 val);
0040 unsigned mode_support;
0041 };
0042
0043
0044 enum {
0045 cphy_cause_link_change = 0x1,
0046 cphy_cause_error = 0x2,
0047 cphy_cause_fifo_error = 0x3
0048 };
0049
0050 enum {
0051 PHY_LINK_UP = 0x1,
0052 PHY_AUTONEG_RDY = 0x2,
0053 PHY_AUTONEG_EN = 0x4
0054 };
0055
0056 struct cphy;
0057
0058
0059 struct cphy_ops {
0060 void (*destroy)(struct cphy *);
0061 int (*reset)(struct cphy *, int wait);
0062
0063 int (*interrupt_enable)(struct cphy *);
0064 int (*interrupt_disable)(struct cphy *);
0065 int (*interrupt_clear)(struct cphy *);
0066 int (*interrupt_handler)(struct cphy *);
0067
0068 int (*autoneg_enable)(struct cphy *);
0069 int (*autoneg_disable)(struct cphy *);
0070 int (*autoneg_restart)(struct cphy *);
0071
0072 int (*advertise)(struct cphy *phy, unsigned int advertise_map);
0073 int (*set_loopback)(struct cphy *, int on);
0074 int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex);
0075 int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed,
0076 int *duplex, int *fc);
0077
0078 u32 mmds;
0079 };
0080
0081
0082 struct cphy {
0083 int state;
0084 adapter_t *adapter;
0085
0086 struct delayed_work phy_update;
0087
0088 u16 bmsr;
0089 int count;
0090 int act_count;
0091 int act_on;
0092
0093 u32 elmer_gpo;
0094
0095 const struct cphy_ops *ops;
0096 struct mdio_if_info mdio;
0097 struct cphy_instance *instance;
0098 };
0099
0100
0101 static inline int cphy_mdio_read(struct cphy *cphy, int mmd, int reg,
0102 unsigned int *valp)
0103 {
0104 int rc = cphy->mdio.mdio_read(cphy->mdio.dev, cphy->mdio.prtad, mmd,
0105 reg);
0106 *valp = (rc >= 0) ? rc : -1;
0107 return (rc >= 0) ? 0 : rc;
0108 }
0109
0110 static inline int cphy_mdio_write(struct cphy *cphy, int mmd, int reg,
0111 unsigned int val)
0112 {
0113 return cphy->mdio.mdio_write(cphy->mdio.dev, cphy->mdio.prtad, mmd,
0114 reg, val);
0115 }
0116
0117 static inline int simple_mdio_read(struct cphy *cphy, int reg,
0118 unsigned int *valp)
0119 {
0120 return cphy_mdio_read(cphy, MDIO_DEVAD_NONE, reg, valp);
0121 }
0122
0123 static inline int simple_mdio_write(struct cphy *cphy, int reg,
0124 unsigned int val)
0125 {
0126 return cphy_mdio_write(cphy, MDIO_DEVAD_NONE, reg, val);
0127 }
0128
0129
0130 static inline void cphy_init(struct cphy *phy, struct net_device *dev,
0131 int phy_addr, const struct cphy_ops *phy_ops,
0132 const struct mdio_ops *mdio_ops)
0133 {
0134 struct adapter *adapter = netdev_priv(dev);
0135 phy->adapter = adapter;
0136 phy->ops = phy_ops;
0137 if (mdio_ops) {
0138 phy->mdio.prtad = phy_addr;
0139 phy->mdio.mmds = phy_ops->mmds;
0140 phy->mdio.mode_support = mdio_ops->mode_support;
0141 phy->mdio.mdio_read = mdio_ops->read;
0142 phy->mdio.mdio_write = mdio_ops->write;
0143 }
0144 phy->mdio.dev = dev;
0145 }
0146
0147
0148 struct gphy {
0149
0150 struct cphy *(*create)(struct net_device *dev, int phy_addr,
0151 const struct mdio_ops *mdio_ops);
0152
0153
0154
0155
0156
0157 int (*reset)(adapter_t *adapter);
0158 };
0159
0160 extern const struct gphy t1_my3126_ops;
0161 extern const struct gphy t1_mv88e1xxx_ops;
0162 extern const struct gphy t1_vsc8244_ops;
0163 extern const struct gphy t1_mv88x201x_ops;
0164
0165 #endif