Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 1 | /* |
Divy Le Ray | 1d68e93 | 2007-01-30 19:44:35 -0800 | [diff] [blame] | 2 | * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 3 | * |
Divy Le Ray | 1d68e93 | 2007-01-30 19:44:35 -0800 | [diff] [blame] | 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: |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 9 | * |
Divy Le Ray | 1d68e93 | 2007-01-30 19:44:35 -0800 | [diff] [blame] | 10 | * 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 Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 31 | */ |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 32 | #include "common.h" |
| 33 | #include "regs.h" |
| 34 | |
| 35 | enum { |
| 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 Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | static 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 | |
| 53 | static 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 | |
| 64 | static 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 | |
| 79 | static int ael1002_intr_noop(struct cphy *phy) |
| 80 | { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static 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 | |
| 109 | static 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 Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 119 | int t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter, |
| 120 | int phy_addr, const struct mdio_ops *mdio_ops) |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 121 | { |
Divy Le Ray | 0449798 | 2008-10-08 17:38:29 -0700 | [diff] [blame] | 122 | cphy_init(phy, adapter, phy_addr, &ael1002_ops, mdio_ops, |
| 123 | SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE, |
| 124 | "10GBASE-R"); |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 125 | ael100x_txon(phy); |
Divy Le Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 126 | return 0; |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static int ael1006_reset(struct cphy *phy, int wait) |
| 130 | { |
| 131 | return t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait); |
| 132 | } |
| 133 | |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 134 | static 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 | |
| 140 | static struct cphy_ops ael1006_ops = { |
| 141 | .reset = ael1006_reset, |
Divy Le Ray | 9b1e365 | 2008-10-08 17:39:31 -0700 | [diff] [blame^] | 142 | .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 Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 146 | .get_link_status = ael100x_get_link_status, |
| 147 | .power_down = ael1006_power_down, |
| 148 | }; |
| 149 | |
Divy Le Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 150 | int t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter, |
| 151 | int phy_addr, const struct mdio_ops *mdio_ops) |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 152 | { |
Divy Le Ray | 0449798 | 2008-10-08 17:38:29 -0700 | [diff] [blame] | 153 | cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops, |
| 154 | SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE, |
| 155 | "10GBASE-SR"); |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 156 | ael100x_txon(phy); |
Divy Le Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 157 | return 0; |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static struct cphy_ops qt2045_ops = { |
| 161 | .reset = ael1006_reset, |
Divy Le Ray | 9b1e365 | 2008-10-08 17:39:31 -0700 | [diff] [blame^] | 162 | .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 Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 166 | .get_link_status = ael100x_get_link_status, |
| 167 | .power_down = ael1006_power_down, |
| 168 | }; |
| 169 | |
Divy Le Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 170 | int t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter, |
| 171 | int phy_addr, const struct mdio_ops *mdio_ops) |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 172 | { |
| 173 | unsigned int stat; |
| 174 | |
Divy Le Ray | 0449798 | 2008-10-08 17:38:29 -0700 | [diff] [blame] | 175 | cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops, |
| 176 | SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP, |
| 177 | "10GBASE-CX4"); |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 178 | |
| 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 Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 186 | return 0; |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static int xaui_direct_reset(struct cphy *phy, int wait) |
| 190 | { |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static 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 Ray | c706bfb | 2007-05-30 10:01:39 -0700 | [diff] [blame] | 201 | 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 Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 208 | *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 | |
| 217 | static int xaui_direct_power_down(struct cphy *phy, int enable) |
| 218 | { |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static 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 Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 232 | int t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter, |
| 233 | int phy_addr, const struct mdio_ops *mdio_ops) |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 234 | { |
Divy Le Ray | 0449798 | 2008-10-08 17:38:29 -0700 | [diff] [blame] | 235 | cphy_init(phy, adapter, phy_addr, &xaui_direct_ops, mdio_ops, |
| 236 | SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP, |
| 237 | "10GBASE-CX4"); |
Divy Le Ray | 78e4689 | 2008-10-08 17:38:01 -0700 | [diff] [blame] | 238 | return 0; |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 239 | } |