xref: /onnv-gate/usr/src/uts/common/io/chxge/com/cphy.h (revision 3833:45d8d0ee8613)
1*3833Sxw161283 /*
2*3833Sxw161283  * CDDL HEADER START
3*3833Sxw161283  *
4*3833Sxw161283  * The contents of this file are subject to the terms of the
5*3833Sxw161283  * Common Development and Distribution License (the "License").
6*3833Sxw161283  * You may not use this file except in compliance with the License.
7*3833Sxw161283  *
8*3833Sxw161283  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3833Sxw161283  * or http://www.opensolaris.org/os/licensing.
10*3833Sxw161283  * See the License for the specific language governing permissions
11*3833Sxw161283  * and limitations under the License.
12*3833Sxw161283  *
13*3833Sxw161283  * When distributing Covered Code, include this CDDL HEADER in each
14*3833Sxw161283  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3833Sxw161283  * If applicable, add the following below this CDDL HEADER, with the
16*3833Sxw161283  * fields enclosed by brackets "[]" replaced with your own identifying
17*3833Sxw161283  * information: Portions Copyright [yyyy] [name of copyright owner]
18*3833Sxw161283  *
19*3833Sxw161283  * CDDL HEADER END
20*3833Sxw161283  */
21*3833Sxw161283 
22*3833Sxw161283 /*
23*3833Sxw161283  * Copyright (C) 2003-2005 Chelsio Communications.  All rights reserved.
24*3833Sxw161283  */
25*3833Sxw161283 
26*3833Sxw161283 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* cphy.h */
27*3833Sxw161283 
28*3833Sxw161283 #ifndef CHELSIO_CPHY_H
29*3833Sxw161283 #define CHELSIO_CPHY_H
30*3833Sxw161283 
31*3833Sxw161283 #include "common.h"
32*3833Sxw161283 
33*3833Sxw161283 struct mdio_ops {
34*3833Sxw161283 	void (*init)(adapter_t *adapter, const struct board_info *bi);
35*3833Sxw161283 	int  (*read)(adapter_t *adapter, int phy_addr, int mmd_addr,
36*3833Sxw161283 		     int reg_addr, unsigned int *val);
37*3833Sxw161283         int  (*write)(adapter_t *adapter, int phy_addr, int mmd_addr,
38*3833Sxw161283 		      int reg_addr, unsigned int val);
39*3833Sxw161283 };
40*3833Sxw161283 
41*3833Sxw161283 /* PHY interrupt types */
42*3833Sxw161283 enum {
43*3833Sxw161283 	cphy_cause_link_change = 0x1,
44*3833Sxw161283 	cphy_cause_error = 0x2
45*3833Sxw161283 };
46*3833Sxw161283 
47*3833Sxw161283 enum {
48*3833Sxw161283 	PHY_LINK_UP = 0x1,
49*3833Sxw161283 	PHY_AUTONEG_RDY = 0x2,
50*3833Sxw161283 	PHY_AUTONEG_EN = 0x4
51*3833Sxw161283 };
52*3833Sxw161283 
53*3833Sxw161283 struct cphy;
54*3833Sxw161283 
55*3833Sxw161283 /* PHY operations */
56*3833Sxw161283 struct cphy_ops {
57*3833Sxw161283 	void (*destroy)(struct cphy *);
58*3833Sxw161283 	int (*reset)(struct cphy *, int wait);
59*3833Sxw161283 
60*3833Sxw161283 	int (*interrupt_enable)(struct cphy *);
61*3833Sxw161283 	int (*interrupt_disable)(struct cphy *);
62*3833Sxw161283 	int (*interrupt_clear)(struct cphy *);
63*3833Sxw161283 	int (*interrupt_handler)(struct cphy *);
64*3833Sxw161283 
65*3833Sxw161283 	int (*autoneg_enable)(struct cphy *);
66*3833Sxw161283 	int (*autoneg_disable)(struct cphy *);
67*3833Sxw161283 	int (*autoneg_restart)(struct cphy *);
68*3833Sxw161283 
69*3833Sxw161283 	int (*advertise)(struct cphy *phy, unsigned int advertise_map);
70*3833Sxw161283 	int (*set_loopback)(struct cphy *, int on);
71*3833Sxw161283 	int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex);
72*3833Sxw161283 	int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed,
73*3833Sxw161283 			       int *duplex, int *fc);
74*3833Sxw161283 };
75*3833Sxw161283 
76*3833Sxw161283 /* A PHY instance */
77*3833Sxw161283 struct cphy {
78*3833Sxw161283 	int addr;                            /* PHY address */
79*3833Sxw161283 	int state;	/* Link status state machine */
80*3833Sxw161283 	adapter_t *adapter;                  /* associated adapter */
81*3833Sxw161283 
82*3833Sxw161283 	ch_cyclic_t phy_update_cyclic;
83*3833Sxw161283 
84*3833Sxw161283 	u16 bmsr;
85*3833Sxw161283 	int count;
86*3833Sxw161283 	int act_count;
87*3833Sxw161283 	int act_on;
88*3833Sxw161283 
89*3833Sxw161283 	u32 elmer_gpo;
90*3833Sxw161283 
91*3833Sxw161283 	struct cphy_ops *ops;                /* PHY operations */
92*3833Sxw161283 	int (*mdio_read)(adapter_t *adapter, int phy_addr, int mmd_addr,
93*3833Sxw161283 			 int reg_addr, unsigned int *val);
94*3833Sxw161283         int (*mdio_write)(adapter_t *adapter, int phy_addr, int mmd_addr,
95*3833Sxw161283 			  int reg_addr, unsigned int val);
96*3833Sxw161283 	struct cphy_instance *instance;
97*3833Sxw161283 };
98*3833Sxw161283 
99*3833Sxw161283 /* Convenience MDIO read/write wrappers */
mdio_read(struct cphy * cphy,int mmd,int reg,unsigned int * valp)100*3833Sxw161283 static inline int mdio_read(struct cphy *cphy, int mmd, int reg,
101*3833Sxw161283 			    unsigned int *valp)
102*3833Sxw161283 {
103*3833Sxw161283         return cphy->mdio_read(cphy->adapter, cphy->addr, mmd, reg, valp);
104*3833Sxw161283 }
105*3833Sxw161283 
mdio_write(struct cphy * cphy,int mmd,int reg,unsigned int val)106*3833Sxw161283 static inline int mdio_write(struct cphy *cphy, int mmd, int reg,
107*3833Sxw161283 			     unsigned int val)
108*3833Sxw161283 {
109*3833Sxw161283         return cphy->mdio_write(cphy->adapter, cphy->addr, mmd, reg, val);
110*3833Sxw161283 }
111*3833Sxw161283 
simple_mdio_read(struct cphy * cphy,int reg,unsigned int * valp)112*3833Sxw161283 static inline int simple_mdio_read(struct cphy *cphy, int reg,
113*3833Sxw161283 				   unsigned int *valp)
114*3833Sxw161283 {
115*3833Sxw161283 	return mdio_read(cphy, 0, reg, valp);
116*3833Sxw161283 }
117*3833Sxw161283 
simple_mdio_write(struct cphy * cphy,int reg,unsigned int val)118*3833Sxw161283 static inline int simple_mdio_write(struct cphy *cphy, int reg,
119*3833Sxw161283 				    unsigned int val)
120*3833Sxw161283 {
121*3833Sxw161283 	return mdio_write(cphy, 0, reg, val);
122*3833Sxw161283 }
123*3833Sxw161283 
124*3833Sxw161283 /* Convenience initializer */
cphy_init(struct cphy * phy,adapter_t * adapter,int phy_addr,struct cphy_ops * phy_ops,struct mdio_ops * mdio_ops)125*3833Sxw161283 static inline void cphy_init(struct cphy *phy, adapter_t *adapter,
126*3833Sxw161283 			     int phy_addr, struct cphy_ops *phy_ops,
127*3833Sxw161283 			     struct mdio_ops *mdio_ops)
128*3833Sxw161283 {
129*3833Sxw161283 	phy->adapter = adapter;
130*3833Sxw161283 	phy->addr    = phy_addr;
131*3833Sxw161283 	phy->ops     = phy_ops;
132*3833Sxw161283 	if (mdio_ops) {
133*3833Sxw161283 		phy->mdio_read  = mdio_ops->read;
134*3833Sxw161283 		phy->mdio_write = mdio_ops->write;
135*3833Sxw161283 	}
136*3833Sxw161283 }
137*3833Sxw161283 
138*3833Sxw161283 /* Operations of the PHY-instance factory */
139*3833Sxw161283 struct gphy {
140*3833Sxw161283 	/* Construct a PHY instance with the given PHY address */
141*3833Sxw161283 	struct cphy *(*create)(adapter_t *adapter, int phy_addr,
142*3833Sxw161283 			       struct mdio_ops *mdio_ops);
143*3833Sxw161283 
144*3833Sxw161283 	/*
145*3833Sxw161283 	 * Reset the PHY chip.  This resets the whole PHY chip, not individual
146*3833Sxw161283 	 * ports.
147*3833Sxw161283 	 */
148*3833Sxw161283 	int (*reset)(adapter_t *adapter);
149*3833Sxw161283 };
150*3833Sxw161283 
151*3833Sxw161283 extern struct gphy t1_my3126_ops;
152*3833Sxw161283 extern struct gphy t1_mv88e1xxx_ops;
153*3833Sxw161283 extern struct gphy t1_xpak_ops;
154*3833Sxw161283 extern struct gphy t1_mv88x201x_ops;
155*3833Sxw161283 extern struct gphy t1_dummy_phy_ops;
156*3833Sxw161283 #endif
157