2 * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
4 * 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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
37 /* MDIO_DEV_PMA_PMD registers */
38 AQ_LINK_STAT
= 0xe800,
39 AQ_IMASK_PMA
= 0xf000,
41 /* MDIO_DEV_XGXS registers */
42 AQ_XAUI_RX_CFG
= 0xc400,
43 AQ_XAUI_TX_CFG
= 0xe400,
45 /* MDIO_DEV_ANEG registers */
46 AQ_100M_CTRL
= 0x0010,
49 AQ_ANEG_STAT
= 0xc800,
51 /* MDIO_DEV_VEND1 registers */
52 AQ_FW_VERSION
= 0x0020,
53 AQ_IFLAG_GLOBAL
= 0xfc00,
54 AQ_IMASK_GLOBAL
= 0xff00,
57 #define AQBIT(x) (1 << (x))
58 #define IMASK_PMA AQBIT(0x2)
59 #define IMASK_GLOBAL AQBIT(0xf)
60 #define ADV_1G_FULL AQBIT(0xf)
61 #define ADV_1G_HALF AQBIT(0xe)
62 #define ADV_10G_FULL AQBIT(0xc)
63 #define AQ_RESET (AQBIT(0xe) | AQBIT(0xf))
64 #define AQ_LOWPOWER AQBIT(0xb)
66 static int aq100x_reset(struct cphy
*phy
, int wait
)
69 * Ignore the caller specified wait time; always wait for the reset to
70 * complete. Can take up to 3s.
72 int err
= t3_phy_reset(phy
, MDIO_MMD_VEND1
, 3000);
75 CH_WARN(phy
->adapter
, "PHY%d: reset failed (0x%x).\n",
76 phy
->mdio
.prtad
, err
);
81 static int aq100x_intr_enable(struct cphy
*phy
)
83 int err
= t3_mdio_write(phy
, MDIO_MMD_PMAPMD
, AQ_IMASK_PMA
, IMASK_PMA
);
87 err
= t3_mdio_write(phy
, MDIO_MMD_VEND1
, AQ_IMASK_GLOBAL
, IMASK_GLOBAL
);
91 static int aq100x_intr_disable(struct cphy
*phy
)
93 return t3_mdio_write(phy
, MDIO_MMD_VEND1
, AQ_IMASK_GLOBAL
, 0);
96 static int aq100x_intr_clear(struct cphy
*phy
)
100 t3_mdio_read(phy
, MDIO_MMD_VEND1
, AQ_IFLAG_GLOBAL
, &v
);
101 t3_mdio_read(phy
, MDIO_MMD_PMAPMD
, MDIO_STAT1
, &v
);
106 static int aq100x_intr_handler(struct cphy
*phy
)
109 unsigned int cause
, v
;
111 err
= t3_mdio_read(phy
, MDIO_MMD_VEND1
, AQ_IFLAG_GLOBAL
, &cause
);
115 /* Read (and reset) the latching version of the status */
116 t3_mdio_read(phy
, MDIO_MMD_PMAPMD
, MDIO_STAT1
, &v
);
118 return cphy_cause_link_change
;
121 static int aq100x_power_down(struct cphy
*phy
, int off
)
123 return mdio_set_flag(&phy
->mdio
, phy
->mdio
.prtad
,
124 MDIO_MMD_PMAPMD
, MDIO_CTRL1
,
125 MDIO_CTRL1_LPOWER
, off
);
128 static int aq100x_autoneg_enable(struct cphy
*phy
)
132 err
= aq100x_power_down(phy
, 0);
134 err
= mdio_set_flag(&phy
->mdio
, phy
->mdio
.prtad
,
135 MDIO_MMD_AN
, MDIO_CTRL1
,
136 BMCR_ANENABLE
| BMCR_ANRESTART
, 1);
141 static int aq100x_autoneg_restart(struct cphy
*phy
)
145 err
= aq100x_power_down(phy
, 0);
147 err
= mdio_set_flag(&phy
->mdio
, phy
->mdio
.prtad
,
148 MDIO_MMD_AN
, MDIO_CTRL1
,
149 BMCR_ANENABLE
| BMCR_ANRESTART
, 1);
154 static int aq100x_advertise(struct cphy
*phy
, unsigned int advertise_map
)
159 /* 10G advertisement */
161 if (advertise_map
& ADVERTISED_10000baseT_Full
)
163 err
= t3_mdio_change_bits(phy
, MDIO_MMD_AN
, AQ_10G_CTRL
,
168 /* 1G advertisement */
170 if (advertise_map
& ADVERTISED_1000baseT_Full
)
172 if (advertise_map
& ADVERTISED_1000baseT_Half
)
174 err
= t3_mdio_change_bits(phy
, MDIO_MMD_AN
, AQ_1G_CTRL
,
175 ADV_1G_FULL
| ADV_1G_HALF
, adv
);
179 /* 100M, pause advertisement */
181 if (advertise_map
& ADVERTISED_100baseT_Half
)
182 adv
|= ADVERTISE_100HALF
;
183 if (advertise_map
& ADVERTISED_100baseT_Full
)
184 adv
|= ADVERTISE_100FULL
;
185 if (advertise_map
& ADVERTISED_Pause
)
186 adv
|= ADVERTISE_PAUSE_CAP
;
187 if (advertise_map
& ADVERTISED_Asym_Pause
)
188 adv
|= ADVERTISE_PAUSE_ASYM
;
189 err
= t3_mdio_change_bits(phy
, MDIO_MMD_AN
, AQ_100M_CTRL
, 0xfe0, adv
);
194 static int aq100x_set_loopback(struct cphy
*phy
, int mmd
, int dir
, int enable
)
196 return mdio_set_flag(&phy
->mdio
, phy
->mdio
.prtad
,
197 MDIO_MMD_PMAPMD
, MDIO_CTRL1
,
198 BMCR_LOOPBACK
, enable
);
201 static int aq100x_set_speed_duplex(struct cphy
*phy
, int speed
, int duplex
)
207 static int aq100x_get_link_status(struct cphy
*phy
, int *link_ok
,
208 int *speed
, int *duplex
, int *fc
)
214 err
= t3_mdio_read(phy
, MDIO_MMD_PMAPMD
, AQ_LINK_STAT
, &v
);
223 err
= t3_mdio_read(phy
, MDIO_MMD_AN
, AQ_ANEG_STAT
, &v
);
230 *speed
= SPEED_10000
;
245 *duplex
= v
& 1 ? DUPLEX_FULL
: DUPLEX_HALF
;
250 static struct cphy_ops aq100x_ops
= {
251 .reset
= aq100x_reset
,
252 .intr_enable
= aq100x_intr_enable
,
253 .intr_disable
= aq100x_intr_disable
,
254 .intr_clear
= aq100x_intr_clear
,
255 .intr_handler
= aq100x_intr_handler
,
256 .autoneg_enable
= aq100x_autoneg_enable
,
257 .autoneg_restart
= aq100x_autoneg_restart
,
258 .advertise
= aq100x_advertise
,
259 .set_loopback
= aq100x_set_loopback
,
260 .set_speed_duplex
= aq100x_set_speed_duplex
,
261 .get_link_status
= aq100x_get_link_status
,
262 .power_down
= aq100x_power_down
,
263 .mmds
= MDIO_DEVS_PMAPMD
| MDIO_DEVS_PCS
| MDIO_DEVS_PHYXS
,
266 int t3_aq100x_phy_prep(struct cphy
*phy
, struct adapter
*adapter
, int phy_addr
,
267 const struct mdio_ops
*mdio_ops
)
269 unsigned int v
, v2
, gpio
, wait
;
272 cphy_init(phy
, adapter
, phy_addr
, &aq100x_ops
, mdio_ops
,
273 SUPPORTED_1000baseT_Full
| SUPPORTED_10000baseT_Full
|
274 SUPPORTED_Autoneg
| SUPPORTED_AUI
, "1000/10GBASE-T");
277 * The PHY has been out of reset ever since the system powered up. So
278 * we do a hard reset over here.
280 gpio
= phy_addr
? F_GPIO10_OUT_VAL
: F_GPIO6_OUT_VAL
;
281 t3_set_reg_field(adapter
, A_T3DBG_GPIO_EN
, gpio
, 0);
283 t3_set_reg_field(adapter
, A_T3DBG_GPIO_EN
, gpio
, gpio
);
286 * Give it enough time to load the firmware and get ready for mdio.
289 wait
= 500; /* in 10ms increments */
291 err
= t3_mdio_read(phy
, MDIO_MMD_VEND1
, MDIO_CTRL1
, &v
);
292 if (err
|| v
== 0xffff) {
294 /* Allow prep_adapter to succeed when ffff is read */
296 CH_WARN(adapter
, "PHY%d: reset failed (0x%x, 0x%x).\n",
304 } while (v
&& --wait
);
306 CH_WARN(adapter
, "PHY%d: reset timed out (0x%x).\n",
309 goto done
; /* let prep_adapter succeed */
312 /* Datasheet says 3s max but this has been observed */
313 wait
= (500 - wait
) * 10 + 1000;
315 CH_WARN(adapter
, "PHY%d: reset took %ums\n", phy_addr
, wait
);
317 /* Firmware version check. */
318 t3_mdio_read(phy
, MDIO_MMD_VEND1
, AQ_FW_VERSION
, &v
);
320 CH_WARN(adapter
, "PHY%d: unsupported firmware %d\n",
322 return 0; /* allow t3_prep_adapter to succeed */
326 * The PHY should start in really-low-power mode. Prepare it for normal
329 err
= t3_mdio_read(phy
, MDIO_MMD_VEND1
, MDIO_CTRL1
, &v
);
332 if (v
& AQ_LOWPOWER
) {
333 err
= t3_mdio_change_bits(phy
, MDIO_MMD_VEND1
, MDIO_CTRL1
,
339 CH_WARN(adapter
, "PHY%d does not start in low power mode.\n",
343 * Verify XAUI settings, but let prep succeed no matter what.
346 t3_mdio_read(phy
, MDIO_MMD_PHYXS
, AQ_XAUI_RX_CFG
, &v
);
347 t3_mdio_read(phy
, MDIO_MMD_PHYXS
, AQ_XAUI_TX_CFG
, &v2
);
348 if (v
!= 0x1b || v2
!= 0x1b)
350 "PHY%d: incorrect XAUI settings (0x%x, 0x%x).\n",