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