1*a6013785SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2f7917c00SJeff Kirsher /*****************************************************************************
3f7917c00SJeff Kirsher * *
4f7917c00SJeff Kirsher * File: cphy.h *
5f7917c00SJeff Kirsher * $Revision: 1.7 $ *
6f7917c00SJeff Kirsher * $Date: 2005/06/21 18:29:47 $ *
7f7917c00SJeff Kirsher * Description: *
8f7917c00SJeff Kirsher * part of the Chelsio 10Gb Ethernet Driver. *
9f7917c00SJeff Kirsher * *
10f7917c00SJeff Kirsher * *
11f7917c00SJeff Kirsher * http://www.chelsio.com *
12f7917c00SJeff Kirsher * *
13f7917c00SJeff Kirsher * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
14f7917c00SJeff Kirsher * All rights reserved. *
15f7917c00SJeff Kirsher * *
16f7917c00SJeff Kirsher * Maintainers: maintainers@chelsio.com *
17f7917c00SJeff Kirsher * *
18f7917c00SJeff Kirsher * Authors: Dimitrios Michailidis <dm@chelsio.com> *
19f7917c00SJeff Kirsher * Tina Yang <tainay@chelsio.com> *
20f7917c00SJeff Kirsher * Felix Marti <felix@chelsio.com> *
21f7917c00SJeff Kirsher * Scott Bardone <sbardone@chelsio.com> *
22f7917c00SJeff Kirsher * Kurt Ottaway <kottaway@chelsio.com> *
23f7917c00SJeff Kirsher * Frank DiMambro <frank@chelsio.com> *
24f7917c00SJeff Kirsher * *
25f7917c00SJeff Kirsher * History: *
26f7917c00SJeff Kirsher * *
27f7917c00SJeff Kirsher ****************************************************************************/
28f7917c00SJeff Kirsher
29f7917c00SJeff Kirsher #ifndef _CXGB_CPHY_H_
30f7917c00SJeff Kirsher #define _CXGB_CPHY_H_
31f7917c00SJeff Kirsher
32f7917c00SJeff Kirsher #include "common.h"
33f7917c00SJeff Kirsher
34f7917c00SJeff Kirsher struct mdio_ops {
35f7917c00SJeff Kirsher void (*init)(adapter_t *adapter, const struct board_info *bi);
36f7917c00SJeff Kirsher int (*read)(struct net_device *dev, int phy_addr, int mmd_addr,
37f7917c00SJeff Kirsher u16 reg_addr);
38f7917c00SJeff Kirsher int (*write)(struct net_device *dev, int phy_addr, int mmd_addr,
39f7917c00SJeff Kirsher u16 reg_addr, u16 val);
40f7917c00SJeff Kirsher unsigned mode_support;
41f7917c00SJeff Kirsher };
42f7917c00SJeff Kirsher
43f7917c00SJeff Kirsher /* PHY interrupt types */
44f7917c00SJeff Kirsher enum {
45f7917c00SJeff Kirsher cphy_cause_link_change = 0x1,
46f7917c00SJeff Kirsher cphy_cause_error = 0x2,
47f7917c00SJeff Kirsher cphy_cause_fifo_error = 0x3
48f7917c00SJeff Kirsher };
49f7917c00SJeff Kirsher
50f7917c00SJeff Kirsher enum {
51f7917c00SJeff Kirsher PHY_LINK_UP = 0x1,
52f7917c00SJeff Kirsher PHY_AUTONEG_RDY = 0x2,
53f7917c00SJeff Kirsher PHY_AUTONEG_EN = 0x4
54f7917c00SJeff Kirsher };
55f7917c00SJeff Kirsher
56f7917c00SJeff Kirsher struct cphy;
57f7917c00SJeff Kirsher
58f7917c00SJeff Kirsher /* PHY operations */
59f7917c00SJeff Kirsher struct cphy_ops {
60f7917c00SJeff Kirsher void (*destroy)(struct cphy *);
61f7917c00SJeff Kirsher int (*reset)(struct cphy *, int wait);
62f7917c00SJeff Kirsher
63f7917c00SJeff Kirsher int (*interrupt_enable)(struct cphy *);
64f7917c00SJeff Kirsher int (*interrupt_disable)(struct cphy *);
65f7917c00SJeff Kirsher int (*interrupt_clear)(struct cphy *);
66f7917c00SJeff Kirsher int (*interrupt_handler)(struct cphy *);
67f7917c00SJeff Kirsher
68f7917c00SJeff Kirsher int (*autoneg_enable)(struct cphy *);
69f7917c00SJeff Kirsher int (*autoneg_disable)(struct cphy *);
70f7917c00SJeff Kirsher int (*autoneg_restart)(struct cphy *);
71f7917c00SJeff Kirsher
72f7917c00SJeff Kirsher int (*advertise)(struct cphy *phy, unsigned int advertise_map);
73f7917c00SJeff Kirsher int (*set_loopback)(struct cphy *, int on);
74f7917c00SJeff Kirsher int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex);
75f7917c00SJeff Kirsher int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed,
76f7917c00SJeff Kirsher int *duplex, int *fc);
77f7917c00SJeff Kirsher
78f7917c00SJeff Kirsher u32 mmds;
79f7917c00SJeff Kirsher };
80f7917c00SJeff Kirsher
81f7917c00SJeff Kirsher /* A PHY instance */
82f7917c00SJeff Kirsher struct cphy {
83f7917c00SJeff Kirsher int state; /* Link status state machine */
84f7917c00SJeff Kirsher adapter_t *adapter; /* associated adapter */
85f7917c00SJeff Kirsher
86f7917c00SJeff Kirsher struct delayed_work phy_update;
87f7917c00SJeff Kirsher
88f7917c00SJeff Kirsher u16 bmsr;
89f7917c00SJeff Kirsher int count;
90f7917c00SJeff Kirsher int act_count;
91f7917c00SJeff Kirsher int act_on;
92f7917c00SJeff Kirsher
93f7917c00SJeff Kirsher u32 elmer_gpo;
94f7917c00SJeff Kirsher
95f7917c00SJeff Kirsher const struct cphy_ops *ops; /* PHY operations */
96f7917c00SJeff Kirsher struct mdio_if_info mdio;
97f7917c00SJeff Kirsher struct cphy_instance *instance;
98f7917c00SJeff Kirsher };
99f7917c00SJeff Kirsher
100f7917c00SJeff Kirsher /* Convenience MDIO read/write wrappers */
cphy_mdio_read(struct cphy * cphy,int mmd,int reg,unsigned int * valp)101f7917c00SJeff Kirsher static inline int cphy_mdio_read(struct cphy *cphy, int mmd, int reg,
102f7917c00SJeff Kirsher unsigned int *valp)
103f7917c00SJeff Kirsher {
104f7917c00SJeff Kirsher int rc = cphy->mdio.mdio_read(cphy->mdio.dev, cphy->mdio.prtad, mmd,
105f7917c00SJeff Kirsher reg);
106f7917c00SJeff Kirsher *valp = (rc >= 0) ? rc : -1;
107f7917c00SJeff Kirsher return (rc >= 0) ? 0 : rc;
108f7917c00SJeff Kirsher }
109f7917c00SJeff Kirsher
cphy_mdio_write(struct cphy * cphy,int mmd,int reg,unsigned int val)110f7917c00SJeff Kirsher static inline int cphy_mdio_write(struct cphy *cphy, int mmd, int reg,
111f7917c00SJeff Kirsher unsigned int val)
112f7917c00SJeff Kirsher {
113f7917c00SJeff Kirsher return cphy->mdio.mdio_write(cphy->mdio.dev, cphy->mdio.prtad, mmd,
114f7917c00SJeff Kirsher reg, val);
115f7917c00SJeff Kirsher }
116f7917c00SJeff Kirsher
simple_mdio_read(struct cphy * cphy,int reg,unsigned int * valp)117f7917c00SJeff Kirsher static inline int simple_mdio_read(struct cphy *cphy, int reg,
118f7917c00SJeff Kirsher unsigned int *valp)
119f7917c00SJeff Kirsher {
120f7917c00SJeff Kirsher return cphy_mdio_read(cphy, MDIO_DEVAD_NONE, reg, valp);
121f7917c00SJeff Kirsher }
122f7917c00SJeff Kirsher
simple_mdio_write(struct cphy * cphy,int reg,unsigned int val)123f7917c00SJeff Kirsher static inline int simple_mdio_write(struct cphy *cphy, int reg,
124f7917c00SJeff Kirsher unsigned int val)
125f7917c00SJeff Kirsher {
126f7917c00SJeff Kirsher return cphy_mdio_write(cphy, MDIO_DEVAD_NONE, reg, val);
127f7917c00SJeff Kirsher }
128f7917c00SJeff Kirsher
129f7917c00SJeff Kirsher /* Convenience initializer */
cphy_init(struct cphy * phy,struct net_device * dev,int phy_addr,const struct cphy_ops * phy_ops,const struct mdio_ops * mdio_ops)130f7917c00SJeff Kirsher static inline void cphy_init(struct cphy *phy, struct net_device *dev,
13146f85a92SJulia Lawall int phy_addr, const struct cphy_ops *phy_ops,
132f7917c00SJeff Kirsher const struct mdio_ops *mdio_ops)
133f7917c00SJeff Kirsher {
134f7917c00SJeff Kirsher struct adapter *adapter = netdev_priv(dev);
135f7917c00SJeff Kirsher phy->adapter = adapter;
136f7917c00SJeff Kirsher phy->ops = phy_ops;
137f7917c00SJeff Kirsher if (mdio_ops) {
138f7917c00SJeff Kirsher phy->mdio.prtad = phy_addr;
139f7917c00SJeff Kirsher phy->mdio.mmds = phy_ops->mmds;
140f7917c00SJeff Kirsher phy->mdio.mode_support = mdio_ops->mode_support;
141f7917c00SJeff Kirsher phy->mdio.mdio_read = mdio_ops->read;
142f7917c00SJeff Kirsher phy->mdio.mdio_write = mdio_ops->write;
143f7917c00SJeff Kirsher }
144f7917c00SJeff Kirsher phy->mdio.dev = dev;
145f7917c00SJeff Kirsher }
146f7917c00SJeff Kirsher
147f7917c00SJeff Kirsher /* Operations of the PHY-instance factory */
148f7917c00SJeff Kirsher struct gphy {
149f7917c00SJeff Kirsher /* Construct a PHY instance with the given PHY address */
150f7917c00SJeff Kirsher struct cphy *(*create)(struct net_device *dev, int phy_addr,
151f7917c00SJeff Kirsher const struct mdio_ops *mdio_ops);
152f7917c00SJeff Kirsher
153f7917c00SJeff Kirsher /*
154f7917c00SJeff Kirsher * Reset the PHY chip. This resets the whole PHY chip, not individual
155f7917c00SJeff Kirsher * ports.
156f7917c00SJeff Kirsher */
157f7917c00SJeff Kirsher int (*reset)(adapter_t *adapter);
158f7917c00SJeff Kirsher };
159f7917c00SJeff Kirsher
160f7917c00SJeff Kirsher extern const struct gphy t1_my3126_ops;
161f7917c00SJeff Kirsher extern const struct gphy t1_mv88e1xxx_ops;
162f7917c00SJeff Kirsher extern const struct gphy t1_vsc8244_ops;
163f7917c00SJeff Kirsher extern const struct gphy t1_mv88x201x_ops;
164f7917c00SJeff Kirsher
165f7917c00SJeff Kirsher #endif /* _CXGB_CPHY_H_ */
166