blob: f6e575fa7468377673e9f5f0b4006d0fda4c3a07 [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,
Divy Le Ray4d22de32007-01-18 22:04:14 -050042};
43
44static void ael100x_txon(struct cphy *phy)
45{
46 int tx_on_gpio = phy->addr == 0 ? F_GPIO7_OUT_VAL : F_GPIO2_OUT_VAL;
47
48 msleep(100);
49 t3_set_reg_field(phy->adapter, A_T3DBG_GPIO_EN, 0, tx_on_gpio);
50 msleep(30);
51}
52
53static int ael1002_power_down(struct cphy *phy, int enable)
54{
55 int err;
56
57 err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_DISABLE, !!enable);
58 if (!err)
59 err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
60 BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
61 return err;
62}
63
64static int ael1002_reset(struct cphy *phy, int wait)
65{
66 int err;
67
68 if ((err = ael1002_power_down(phy, 0)) ||
69 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_CONFIG1, 1)) ||
70 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_HI, 0)) ||
71 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_LO, 0)) ||
72 (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_XFI_EQL, 0x18)) ||
73 (err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, AEL1002_LB_EN,
74 0, 1 << 5)))
75 return err;
76 return 0;
77}
78
79static int ael1002_intr_noop(struct cphy *phy)
80{
81 return 0;
82}
83
84static int ael100x_get_link_status(struct cphy *phy, int *link_ok,
85 int *speed, int *duplex, int *fc)
86{
87 if (link_ok) {
88 unsigned int status;
89 int err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &status);
90
91 /*
92 * BMSR_LSTATUS is latch-low, so if it is 0 we need to read it
93 * once more to get the current link state.
94 */
95 if (!err && !(status & BMSR_LSTATUS))
96 err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR,
97 &status);
98 if (err)
99 return err;
100 *link_ok = !!(status & BMSR_LSTATUS);
101 }
102 if (speed)
103 *speed = SPEED_10000;
104 if (duplex)
105 *duplex = DUPLEX_FULL;
106 return 0;
107}
108
109static struct cphy_ops ael1002_ops = {
110 .reset = ael1002_reset,
111 .intr_enable = ael1002_intr_noop,
112 .intr_disable = ael1002_intr_noop,
113 .intr_clear = ael1002_intr_noop,
114 .intr_handler = ael1002_intr_noop,
115 .get_link_status = ael100x_get_link_status,
116 .power_down = ael1002_power_down,
117};
118
Divy Le Ray78e46892008-10-08 17:38:01 -0700119int t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter,
120 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500121{
Divy Le Ray04497982008-10-08 17:38:29 -0700122 cphy_init(phy, adapter, phy_addr, &ael1002_ops, mdio_ops,
123 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
124 "10GBASE-R");
Divy Le Ray4d22de32007-01-18 22:04:14 -0500125 ael100x_txon(phy);
Divy Le Ray78e46892008-10-08 17:38:01 -0700126 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500127}
128
129static int ael1006_reset(struct cphy *phy, int wait)
130{
131 return t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait);
132}
133
Divy Le Ray4d22de32007-01-18 22:04:14 -0500134static int ael1006_power_down(struct cphy *phy, int enable)
135{
136 return t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
137 BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
138}
139
140static struct cphy_ops ael1006_ops = {
141 .reset = ael1006_reset,
Divy Le Ray9b1e3652008-10-08 17:39:31 -0700142 .intr_enable = t3_phy_lasi_intr_enable,
143 .intr_disable = t3_phy_lasi_intr_disable,
144 .intr_clear = t3_phy_lasi_intr_clear,
145 .intr_handler = t3_phy_lasi_intr_handler,
Divy Le Ray4d22de32007-01-18 22:04:14 -0500146 .get_link_status = ael100x_get_link_status,
147 .power_down = ael1006_power_down,
148};
149
Divy Le Ray78e46892008-10-08 17:38:01 -0700150int t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
151 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500152{
Divy Le Ray04497982008-10-08 17:38:29 -0700153 cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops,
154 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
155 "10GBASE-SR");
Divy Le Ray4d22de32007-01-18 22:04:14 -0500156 ael100x_txon(phy);
Divy Le Ray78e46892008-10-08 17:38:01 -0700157 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500158}
159
160static struct cphy_ops qt2045_ops = {
161 .reset = ael1006_reset,
Divy Le Ray9b1e3652008-10-08 17:39:31 -0700162 .intr_enable = t3_phy_lasi_intr_enable,
163 .intr_disable = t3_phy_lasi_intr_disable,
164 .intr_clear = t3_phy_lasi_intr_clear,
165 .intr_handler = t3_phy_lasi_intr_handler,
Divy Le Ray4d22de32007-01-18 22:04:14 -0500166 .get_link_status = ael100x_get_link_status,
167 .power_down = ael1006_power_down,
168};
169
Divy Le Ray78e46892008-10-08 17:38:01 -0700170int t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter,
171 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500172{
173 unsigned int stat;
174
Divy Le Ray04497982008-10-08 17:38:29 -0700175 cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops,
176 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
177 "10GBASE-CX4");
Divy Le Ray4d22de32007-01-18 22:04:14 -0500178
179 /*
180 * Some cards where the PHY is supposed to be at address 0 actually
181 * have it at 1.
182 */
183 if (!phy_addr && !mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &stat) &&
184 stat == 0xffff)
185 phy->addr = 1;
Divy Le Ray78e46892008-10-08 17:38:01 -0700186 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500187}
188
189static int xaui_direct_reset(struct cphy *phy, int wait)
190{
191 return 0;
192}
193
194static int xaui_direct_get_link_status(struct cphy *phy, int *link_ok,
195 int *speed, int *duplex, int *fc)
196{
197 if (link_ok) {
198 unsigned int status;
199
200 status = t3_read_reg(phy->adapter,
Divy Le Rayc706bfb2007-05-30 10:01:39 -0700201 XGM_REG(A_XGM_SERDES_STAT0, phy->addr)) |
202 t3_read_reg(phy->adapter,
203 XGM_REG(A_XGM_SERDES_STAT1, phy->addr)) |
204 t3_read_reg(phy->adapter,
205 XGM_REG(A_XGM_SERDES_STAT2, phy->addr)) |
206 t3_read_reg(phy->adapter,
207 XGM_REG(A_XGM_SERDES_STAT3, phy->addr));
Divy Le Ray4d22de32007-01-18 22:04:14 -0500208 *link_ok = !(status & F_LOWSIG0);
209 }
210 if (speed)
211 *speed = SPEED_10000;
212 if (duplex)
213 *duplex = DUPLEX_FULL;
214 return 0;
215}
216
217static int xaui_direct_power_down(struct cphy *phy, int enable)
218{
219 return 0;
220}
221
222static struct cphy_ops xaui_direct_ops = {
223 .reset = xaui_direct_reset,
224 .intr_enable = ael1002_intr_noop,
225 .intr_disable = ael1002_intr_noop,
226 .intr_clear = ael1002_intr_noop,
227 .intr_handler = ael1002_intr_noop,
228 .get_link_status = xaui_direct_get_link_status,
229 .power_down = xaui_direct_power_down,
230};
231
Divy Le Ray78e46892008-10-08 17:38:01 -0700232int t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
233 int phy_addr, const struct mdio_ops *mdio_ops)
Divy Le Ray4d22de32007-01-18 22:04:14 -0500234{
Divy Le Ray04497982008-10-08 17:38:29 -0700235 cphy_init(phy, adapter, phy_addr, &xaui_direct_ops, mdio_ops,
236 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
237 "10GBASE-CX4");
Divy Le Ray78e46892008-10-08 17:38:01 -0700238 return 0;
Divy Le Ray4d22de32007-01-18 22:04:14 -0500239}