blob: f4e046e32fc66dfc69c7c8b6a4c226376ebb8729 [file] [log] [blame]
Divy Le Ray4d22de32007-01-18 22:04:14 -05001/*
Divy Le Ray1d68e932007-01-30 19:44:35 -08002 * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
Divy Le Ray4d22de32007-01-18 22:04:14 -05003 *
Divy Le Ray1d68e932007-01-30 19:44:35 -08004 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
Divy Le Ray4d22de32007-01-18 22:04:14 -05009 *
Divy Le Ray1d68e932007-01-30 19:44:35 -080010 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
Divy Le Ray4d22de32007-01-18 22:04:14 -050031 */
Divy Le Ray4d22de32007-01-18 22:04:14 -050032#include "common.h"
33#include "regs.h"
34
35enum {
36 AEL100X_TX_DISABLE = 9,
37 AEL100X_TX_CONFIG1 = 0xc002,
38 AEL1002_PWR_DOWN_HI = 0xc011,
39 AEL1002_PWR_DOWN_LO = 0xc012,
40 AEL1002_XFI_EQL = 0xc015,
41 AEL1002_LB_EN = 0xc017,
42
43 LASI_CTRL = 0x9002,
44 LASI_STAT = 0x9005
45};
46
47static void ael100x_txon(struct cphy *phy)
48{
49 int tx_on_gpio = phy->addr == 0 ? F_GPIO7_OUT_VAL : F_GPIO2_OUT_VAL;
50
51 msleep(100);
52 t3_set_reg_field(phy->adapter, A_T3DBG_GPIO_EN, 0, tx_on_gpio);
53 msleep(30);
54}
55
56static int ael1002_power_down(struct cphy *phy, int enable)
57{
58 int err;
59
60 err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_DISABLE, !!enable);
61 if (!err)
62 err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
63 BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
64 return err;
65}
66
67static int ael1002_reset(struct cphy *phy, int wait)
68{
69 int err;
70
71 if ((err = ael1002_power_down(phy, 0)) ||
72 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_CONFIG1, 1)) ||
73 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_HI, 0)) ||
74 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_LO, 0)) ||
75 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_XFI_EQL, 0x18)) ||
76 (err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, AEL1002_LB_EN,
77 0, 1 << 5)))
78 return err;
79 return 0;
80}
81
82static int ael1002_intr_noop(struct cphy *phy)
83{
84 return 0;
85}
86
87static int ael100x_get_link_status(struct cphy *phy, int *link_ok,
88 int *speed, int *duplex, int *fc)
89{
90 if (link_ok) {
91 unsigned int status;
92 int err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &status);
93
94 /*
95 * BMSR_LSTATUS is latch-low, so if it is 0 we need to read it
96 * once more to get the current link state.
97 */
98 if (!err && !(status & BMSR_LSTATUS))
99 err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR,
100 &status);
101 if (err)
102 return err;
103 *link_ok = !!(status & BMSR_LSTATUS);
104 }
105 if (speed)
106 *speed = SPEED_10000;
107 if (duplex)
108 *duplex = DUPLEX_FULL;
109 return 0;
110}
111
112static struct cphy_ops ael1002_ops = {
113 .reset = ael1002_reset,
114 .intr_enable = ael1002_intr_noop,
115 .intr_disable = ael1002_intr_noop,
116 .intr_clear = ael1002_intr_noop,
117 .intr_handler = ael1002_intr_noop,
118 .get_link_status = ael100x_get_link_status,
119 .power_down = ael1002_power_down,
120};
121
Divy Le Ray78e46892008-10-08 17:38:01 -0700122int t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter,
123 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500124{
Divy Le Ray04497982008-10-08 17:38:29 -0700125 cphy_init(phy, adapter, phy_addr, &ael1002_ops, mdio_ops,
126 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
127 "10GBASE-R");
Divy Le Ray4d22de32007-01-18 22:04:14 -0500128 ael100x_txon(phy);
Divy Le Ray78e46892008-10-08 17:38:01 -0700129 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500130}
131
132static int ael1006_reset(struct cphy *phy, int wait)
133{
134 return t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait);
135}
136
137static int ael1006_intr_enable(struct cphy *phy)
138{
139 return mdio_write(phy, MDIO_DEV_PMA_PMD, LASI_CTRL, 1);
140}
141
142static int ael1006_intr_disable(struct cphy *phy)
143{
144 return mdio_write(phy, MDIO_DEV_PMA_PMD, LASI_CTRL, 0);
145}
146
147static int ael1006_intr_clear(struct cphy *phy)
148{
149 u32 val;
150
151 return mdio_read(phy, MDIO_DEV_PMA_PMD, LASI_STAT, &val);
152}
153
154static int ael1006_intr_handler(struct cphy *phy)
155{
156 unsigned int status;
157 int err = mdio_read(phy, MDIO_DEV_PMA_PMD, LASI_STAT, &status);
158
159 if (err)
160 return err;
161 return (status & 1) ? cphy_cause_link_change : 0;
162}
163
164static int ael1006_power_down(struct cphy *phy, int enable)
165{
166 return t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
167 BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
168}
169
170static struct cphy_ops ael1006_ops = {
171 .reset = ael1006_reset,
172 .intr_enable = ael1006_intr_enable,
173 .intr_disable = ael1006_intr_disable,
174 .intr_clear = ael1006_intr_clear,
175 .intr_handler = ael1006_intr_handler,
176 .get_link_status = ael100x_get_link_status,
177 .power_down = ael1006_power_down,
178};
179
Divy Le Ray78e46892008-10-08 17:38:01 -0700180int t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
181 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500182{
Divy Le Ray04497982008-10-08 17:38:29 -0700183 cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops,
184 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
185 "10GBASE-SR");
Divy Le Ray4d22de32007-01-18 22:04:14 -0500186 ael100x_txon(phy);
Divy Le Ray78e46892008-10-08 17:38:01 -0700187 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500188}
189
190static struct cphy_ops qt2045_ops = {
191 .reset = ael1006_reset,
192 .intr_enable = ael1006_intr_enable,
193 .intr_disable = ael1006_intr_disable,
194 .intr_clear = ael1006_intr_clear,
195 .intr_handler = ael1006_intr_handler,
196 .get_link_status = ael100x_get_link_status,
197 .power_down = ael1006_power_down,
198};
199
Divy Le Ray78e46892008-10-08 17:38:01 -0700200int t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter,
201 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500202{
203 unsigned int stat;
204
Divy Le Ray04497982008-10-08 17:38:29 -0700205 cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops,
206 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
207 "10GBASE-CX4");
Divy Le Ray4d22de32007-01-18 22:04:14 -0500208
209 /*
210 * Some cards where the PHY is supposed to be at address 0 actually
211 * have it at 1.
212 */
213 if (!phy_addr && !mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &stat) &&
214 stat == 0xffff)
215 phy->addr = 1;
Divy Le Ray78e46892008-10-08 17:38:01 -0700216 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500217}
218
219static int xaui_direct_reset(struct cphy *phy, int wait)
220{
221 return 0;
222}
223
224static int xaui_direct_get_link_status(struct cphy *phy, int *link_ok,
225 int *speed, int *duplex, int *fc)
226{
227 if (link_ok) {
228 unsigned int status;
229
230 status = t3_read_reg(phy->adapter,
Divy Le Rayc706bfb2007-05-30 10:01:39 -0700231 XGM_REG(A_XGM_SERDES_STAT0, phy->addr)) |
232 t3_read_reg(phy->adapter,
233 XGM_REG(A_XGM_SERDES_STAT1, phy->addr)) |
234 t3_read_reg(phy->adapter,
235 XGM_REG(A_XGM_SERDES_STAT2, phy->addr)) |
236 t3_read_reg(phy->adapter,
237 XGM_REG(A_XGM_SERDES_STAT3, phy->addr));
Divy Le Ray4d22de32007-01-18 22:04:14 -0500238 *link_ok = !(status & F_LOWSIG0);
239 }
240 if (speed)
241 *speed = SPEED_10000;
242 if (duplex)
243 *duplex = DUPLEX_FULL;
244 return 0;
245}
246
247static int xaui_direct_power_down(struct cphy *phy, int enable)
248{
249 return 0;
250}
251
252static struct cphy_ops xaui_direct_ops = {
253 .reset = xaui_direct_reset,
254 .intr_enable = ael1002_intr_noop,
255 .intr_disable = ael1002_intr_noop,
256 .intr_clear = ael1002_intr_noop,
257 .intr_handler = ael1002_intr_noop,
258 .get_link_status = xaui_direct_get_link_status,
259 .power_down = xaui_direct_power_down,
260};
261
Divy Le Ray78e46892008-10-08 17:38:01 -0700262int t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
263 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500264{
Divy Le Ray04497982008-10-08 17:38:29 -0700265 cphy_init(phy, adapter, phy_addr, &xaui_direct_ops, mdio_ops,
266 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
267 "10GBASE-CX4");
Divy Le Ray78e46892008-10-08 17:38:01 -0700268 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500269}