Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * * |
| 3 | * File: subr.c * |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 4 | * $Revision: 1.27 $ * |
| 5 | * $Date: 2005/06/22 01:08:36 $ * |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 6 | * Description: * |
| 7 | * Various subroutines (intr,pio,etc.) used by Chelsio 10G Ethernet driver. * |
| 8 | * part of the Chelsio 10Gb Ethernet Driver. * |
| 9 | * * |
| 10 | * This program is free software; you can redistribute it and/or modify * |
| 11 | * it under the terms of the GNU General Public License, version 2, as * |
| 12 | * published by the Free Software Foundation. * |
| 13 | * * |
| 14 | * You should have received a copy of the GNU General Public License along * |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., * |
| 16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 17 | * * |
| 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * |
| 19 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * |
| 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * |
| 21 | * * |
| 22 | * http://www.chelsio.com * |
| 23 | * * |
| 24 | * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. * |
| 25 | * All rights reserved. * |
| 26 | * * |
| 27 | * Maintainers: maintainers@chelsio.com * |
| 28 | * * |
| 29 | * Authors: Dimitrios Michailidis <dm@chelsio.com> * |
| 30 | * Tina Yang <tainay@chelsio.com> * |
| 31 | * Felix Marti <felix@chelsio.com> * |
| 32 | * Scott Bardone <sbardone@chelsio.com> * |
| 33 | * Kurt Ottaway <kottaway@chelsio.com> * |
| 34 | * Frank DiMambro <frank@chelsio.com> * |
| 35 | * * |
| 36 | * History: * |
| 37 | * * |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "common.h" |
| 41 | #include "elmer0.h" |
| 42 | #include "regs.h" |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 43 | #include "gmac.h" |
| 44 | #include "cphy.h" |
| 45 | #include "sge.h" |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 46 | #include "tp.h" |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 47 | #include "espi.h" |
| 48 | |
| 49 | /** |
| 50 | * t1_wait_op_done - wait until an operation is completed |
| 51 | * @adapter: the adapter performing the operation |
| 52 | * @reg: the register to check for completion |
| 53 | * @mask: a single-bit field within @reg that indicates completion |
| 54 | * @polarity: the value of the field when the operation is completed |
| 55 | * @attempts: number of check iterations |
| 56 | * @delay: delay in usecs between iterations |
| 57 | * |
| 58 | * Wait until an operation is completed by checking a bit in a register |
| 59 | * up to @attempts times. Returns %0 if the operation completes and %1 |
| 60 | * otherwise. |
| 61 | */ |
| 62 | static int t1_wait_op_done(adapter_t *adapter, int reg, u32 mask, int polarity, |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 63 | int attempts, int delay) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 64 | { |
| 65 | while (1) { |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 66 | u32 val = readl(adapter->regs + reg) & mask; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 67 | |
| 68 | if (!!val == polarity) |
| 69 | return 0; |
| 70 | if (--attempts == 0) |
| 71 | return 1; |
| 72 | if (delay) |
| 73 | udelay(delay); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | #define TPI_ATTEMPTS 50 |
| 78 | |
| 79 | /* |
| 80 | * Write a register over the TPI interface (unlocked and locked versions). |
| 81 | */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 82 | int __t1_tpi_write(adapter_t *adapter, u32 addr, u32 value) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 83 | { |
| 84 | int tpi_busy; |
| 85 | |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 86 | writel(addr, adapter->regs + A_TPI_ADDR); |
| 87 | writel(value, adapter->regs + A_TPI_WR_DATA); |
| 88 | writel(F_TPIWR, adapter->regs + A_TPI_CSR); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 89 | |
| 90 | tpi_busy = t1_wait_op_done(adapter, A_TPI_CSR, F_TPIRDY, 1, |
| 91 | TPI_ATTEMPTS, 3); |
| 92 | if (tpi_busy) |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 93 | pr_alert("%s: TPI write to 0x%x failed\n", |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 94 | adapter->name, addr); |
| 95 | return tpi_busy; |
| 96 | } |
| 97 | |
| 98 | int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value) |
| 99 | { |
| 100 | int ret; |
| 101 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 102 | spin_lock(&adapter->tpi_lock); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 103 | ret = __t1_tpi_write(adapter, addr, value); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 104 | spin_unlock(&adapter->tpi_lock); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * Read a register over the TPI interface (unlocked and locked versions). |
| 110 | */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 111 | int __t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 112 | { |
| 113 | int tpi_busy; |
| 114 | |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 115 | writel(addr, adapter->regs + A_TPI_ADDR); |
| 116 | writel(0, adapter->regs + A_TPI_CSR); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 117 | |
| 118 | tpi_busy = t1_wait_op_done(adapter, A_TPI_CSR, F_TPIRDY, 1, |
| 119 | TPI_ATTEMPTS, 3); |
| 120 | if (tpi_busy) |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 121 | pr_alert("%s: TPI read from 0x%x failed\n", |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 122 | adapter->name, addr); |
| 123 | else |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 124 | *valp = readl(adapter->regs + A_TPI_RD_DATA); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 125 | return tpi_busy; |
| 126 | } |
| 127 | |
| 128 | int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp) |
| 129 | { |
| 130 | int ret; |
| 131 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 132 | spin_lock(&adapter->tpi_lock); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 133 | ret = __t1_tpi_read(adapter, addr, valp); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 134 | spin_unlock(&adapter->tpi_lock); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | /* |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 139 | * Set a TPI parameter. |
| 140 | */ |
| 141 | static void t1_tpi_par(adapter_t *adapter, u32 value) |
| 142 | { |
| 143 | writel(V_TPIPAR(value), adapter->regs + A_TPI_PAR); |
| 144 | } |
| 145 | |
| 146 | /* |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 147 | * Called when a port's link settings change to propagate the new values to the |
| 148 | * associated PHY and MAC. After performing the common tasks it invokes an |
| 149 | * OS-specific handler. |
| 150 | */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 151 | void t1_link_changed(adapter_t *adapter, int port_id) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 152 | { |
| 153 | int link_ok, speed, duplex, fc; |
| 154 | struct cphy *phy = adapter->port[port_id].phy; |
| 155 | struct link_config *lc = &adapter->port[port_id].link_config; |
| 156 | |
| 157 | phy->ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc); |
| 158 | |
| 159 | lc->speed = speed < 0 ? SPEED_INVALID : speed; |
| 160 | lc->duplex = duplex < 0 ? DUPLEX_INVALID : duplex; |
| 161 | if (!(lc->requested_fc & PAUSE_AUTONEG)) |
| 162 | fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX); |
| 163 | |
| 164 | if (link_ok && speed >= 0 && lc->autoneg == AUTONEG_ENABLE) { |
| 165 | /* Set MAC speed, duplex, and flow control to match PHY. */ |
| 166 | struct cmac *mac = adapter->port[port_id].mac; |
| 167 | |
| 168 | mac->ops->set_speed_duplex_fc(mac, speed, duplex, fc); |
| 169 | lc->fc = (unsigned char)fc; |
| 170 | } |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 171 | t1_link_negotiated(adapter, port_id, link_ok, speed, duplex, fc); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static int t1_pci_intr_handler(adapter_t *adapter) |
| 175 | { |
| 176 | u32 pcix_cause; |
| 177 | |
Stephen Hemminger | 11e5a20 | 2006-12-01 16:36:13 -0800 | [diff] [blame] | 178 | pci_read_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, &pcix_cause); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 179 | |
| 180 | if (pcix_cause) { |
| 181 | pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, |
Stephen Hemminger | 11e5a20 | 2006-12-01 16:36:13 -0800 | [diff] [blame] | 182 | pcix_cause); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 183 | t1_fatal_err(adapter); /* PCI errors are fatal */ |
| 184 | } |
| 185 | return 0; |
| 186 | } |
| 187 | |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 188 | #ifdef CONFIG_CHELSIO_T1_COUGAR |
| 189 | #include "cspi.h" |
| 190 | #endif |
| 191 | #ifdef CONFIG_CHELSIO_T1_1G |
| 192 | #include "fpga_defs.h" |
| 193 | |
| 194 | /* |
| 195 | * PHY interrupt handler for FPGA boards. |
| 196 | */ |
| 197 | static int fpga_phy_intr_handler(adapter_t *adapter) |
| 198 | { |
| 199 | int p; |
| 200 | u32 cause = readl(adapter->regs + FPGA_GMAC_ADDR_INTERRUPT_CAUSE); |
| 201 | |
| 202 | for_each_port(adapter, p) |
| 203 | if (cause & (1 << p)) { |
| 204 | struct cphy *phy = adapter->port[p].phy; |
| 205 | int phy_cause = phy->ops->interrupt_handler(phy); |
| 206 | |
| 207 | if (phy_cause & cphy_cause_link_change) |
| 208 | t1_link_changed(adapter, p); |
| 209 | } |
| 210 | writel(cause, adapter->regs + FPGA_GMAC_ADDR_INTERRUPT_CAUSE); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Slow path interrupt handler for FPGAs. |
| 216 | */ |
| 217 | static int fpga_slow_intr(adapter_t *adapter) |
| 218 | { |
| 219 | u32 cause = readl(adapter->regs + A_PL_CAUSE); |
| 220 | |
| 221 | cause &= ~F_PL_INTR_SGE_DATA; |
| 222 | if (cause & F_PL_INTR_SGE_ERR) |
| 223 | t1_sge_intr_error_handler(adapter->sge); |
| 224 | |
| 225 | if (cause & FPGA_PCIX_INTERRUPT_GMAC) |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 226 | fpga_phy_intr_handler(adapter); |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 227 | |
| 228 | if (cause & FPGA_PCIX_INTERRUPT_TP) { |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 229 | /* |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 230 | * FPGA doesn't support MC4 interrupts and it requires |
| 231 | * this odd layer of indirection for MC5. |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 232 | */ |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 233 | u32 tp_cause = readl(adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE); |
| 234 | |
| 235 | /* Clear TP interrupt */ |
| 236 | writel(tp_cause, adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE); |
| 237 | } |
| 238 | if (cause & FPGA_PCIX_INTERRUPT_PCIX) |
| 239 | t1_pci_intr_handler(adapter); |
| 240 | |
| 241 | /* Clear the interrupts just processed. */ |
| 242 | if (cause) |
| 243 | writel(cause, adapter->regs + A_PL_CAUSE); |
| 244 | |
| 245 | return cause != 0; |
| 246 | } |
| 247 | #endif |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * Wait until Elmer's MI1 interface is ready for new operations. |
| 251 | */ |
| 252 | static int mi1_wait_until_ready(adapter_t *adapter, int mi1_reg) |
| 253 | { |
| 254 | int attempts = 100, busy; |
| 255 | |
| 256 | do { |
| 257 | u32 val; |
| 258 | |
| 259 | __t1_tpi_read(adapter, mi1_reg, &val); |
| 260 | busy = val & F_MI1_OP_BUSY; |
| 261 | if (busy) |
| 262 | udelay(10); |
| 263 | } while (busy && --attempts); |
| 264 | if (busy) |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 265 | pr_alert("%s: MDIO operation timed out\n", adapter->name); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 266 | return busy; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * MI1 MDIO initialization. |
| 271 | */ |
| 272 | static void mi1_mdio_init(adapter_t *adapter, const struct board_info *bi) |
| 273 | { |
| 274 | u32 clkdiv = bi->clock_elmer0 / (2 * bi->mdio_mdc) - 1; |
| 275 | u32 val = F_MI1_PREAMBLE_ENABLE | V_MI1_MDI_INVERT(bi->mdio_mdiinv) | |
| 276 | V_MI1_MDI_ENABLE(bi->mdio_mdien) | V_MI1_CLK_DIV(clkdiv); |
| 277 | |
| 278 | if (!(bi->caps & SUPPORTED_10000baseT_Full)) |
| 279 | val |= V_MI1_SOF(1); |
| 280 | t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_CFG, val); |
| 281 | } |
| 282 | |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 283 | #if defined(CONFIG_CHELSIO_T1_1G) || defined(CONFIG_CHELSIO_T1_COUGAR) |
| 284 | /* |
| 285 | * Elmer MI1 MDIO read/write operations. |
| 286 | */ |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 287 | static int mi1_mdio_read(struct net_device *dev, int phy_addr, int mmd_addr, |
| 288 | u16 reg_addr) |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 289 | { |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 290 | struct adapter *adapter = dev->ml_priv; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 291 | u32 addr = V_MI1_REG_ADDR(reg_addr) | V_MI1_PHY_ADDR(phy_addr); |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 292 | unsigned int val; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 293 | |
| 294 | spin_lock(&adapter->tpi_lock); |
| 295 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr); |
| 296 | __t1_tpi_write(adapter, |
| 297 | A_ELMER0_PORT0_MI1_OP, MI1_OP_DIRECT_READ); |
| 298 | mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP); |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 299 | __t1_tpi_read(adapter, A_ELMER0_PORT0_MI1_DATA, &val); |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 300 | spin_unlock(&adapter->tpi_lock); |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 301 | return val; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 304 | static int mi1_mdio_write(struct net_device *dev, int phy_addr, int mmd_addr, |
| 305 | u16 reg_addr, u16 val) |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 306 | { |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 307 | struct adapter *adapter = dev->ml_priv; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 308 | u32 addr = V_MI1_REG_ADDR(reg_addr) | V_MI1_PHY_ADDR(phy_addr); |
| 309 | |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 310 | spin_lock(&adapter->tpi_lock); |
| 311 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr); |
| 312 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, val); |
| 313 | __t1_tpi_write(adapter, |
| 314 | A_ELMER0_PORT0_MI1_OP, MI1_OP_DIRECT_WRITE); |
| 315 | mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP); |
| 316 | spin_unlock(&adapter->tpi_lock); |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | #if defined(CONFIG_CHELSIO_T1_1G) || defined(CONFIG_CHELSIO_T1_COUGAR) |
Stephen Hemminger | 459e536 | 2007-02-20 15:58:02 -0800 | [diff] [blame] | 321 | static const struct mdio_ops mi1_mdio_ops = { |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 322 | .init = mi1_mdio_init, |
| 323 | .read = mi1_mdio_read, |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 324 | .write = mi1_mdio_write, |
| 325 | .mode_support = MDIO_SUPPORTS_C22 |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 326 | }; |
| 327 | #endif |
| 328 | |
| 329 | #endif |
| 330 | |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 331 | static int mi1_mdio_ext_read(struct net_device *dev, int phy_addr, int mmd_addr, |
| 332 | u16 reg_addr) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 333 | { |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 334 | struct adapter *adapter = dev->ml_priv; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 335 | u32 addr = V_MI1_REG_ADDR(mmd_addr) | V_MI1_PHY_ADDR(phy_addr); |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 336 | unsigned int val; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 337 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 338 | spin_lock(&adapter->tpi_lock); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 339 | |
| 340 | /* Write the address we want. */ |
| 341 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr); |
| 342 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, reg_addr); |
| 343 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP, |
| 344 | MI1_OP_INDIRECT_ADDRESS); |
| 345 | mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP); |
| 346 | |
| 347 | /* Write the operation we want. */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 348 | __t1_tpi_write(adapter, |
| 349 | A_ELMER0_PORT0_MI1_OP, MI1_OP_INDIRECT_READ); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 350 | mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP); |
| 351 | |
| 352 | /* Read the data. */ |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 353 | __t1_tpi_read(adapter, A_ELMER0_PORT0_MI1_DATA, &val); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 354 | spin_unlock(&adapter->tpi_lock); |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 355 | return val; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 358 | static int mi1_mdio_ext_write(struct net_device *dev, int phy_addr, |
| 359 | int mmd_addr, u16 reg_addr, u16 val) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 360 | { |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 361 | struct adapter *adapter = dev->ml_priv; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 362 | u32 addr = V_MI1_REG_ADDR(mmd_addr) | V_MI1_PHY_ADDR(phy_addr); |
| 363 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 364 | spin_lock(&adapter->tpi_lock); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 365 | |
| 366 | /* Write the address we want. */ |
| 367 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr); |
| 368 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, reg_addr); |
| 369 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP, |
| 370 | MI1_OP_INDIRECT_ADDRESS); |
| 371 | mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP); |
| 372 | |
| 373 | /* Write the data. */ |
| 374 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, val); |
| 375 | __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP, MI1_OP_INDIRECT_WRITE); |
| 376 | mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 377 | spin_unlock(&adapter->tpi_lock); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
Stephen Hemminger | 459e536 | 2007-02-20 15:58:02 -0800 | [diff] [blame] | 381 | static const struct mdio_ops mi1_mdio_ext_ops = { |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 382 | .init = mi1_mdio_init, |
| 383 | .read = mi1_mdio_ext_read, |
Ben Hutchings | 23c3320 | 2009-04-29 08:06:34 +0000 | [diff] [blame] | 384 | .write = mi1_mdio_ext_write, |
| 385 | .mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22 |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | enum { |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 389 | CH_BRD_T110_1CU, |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 390 | CH_BRD_N110_1F, |
| 391 | CH_BRD_N210_1F, |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 392 | CH_BRD_T210_1F, |
| 393 | CH_BRD_T210_1CU, |
| 394 | CH_BRD_N204_4CU, |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 395 | }; |
| 396 | |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 397 | static const struct board_info t1_board[] = { |
| 398 | { |
| 399 | .board = CHBT_BOARD_CHT110, |
| 400 | .port_number = 1, |
| 401 | .caps = SUPPORTED_10000baseT_Full, |
| 402 | .chip_term = CHBT_TERM_T1, |
| 403 | .chip_mac = CHBT_MAC_PM3393, |
| 404 | .chip_phy = CHBT_PHY_MY3126, |
| 405 | .clock_core = 125000000, |
| 406 | .clock_mc3 = 150000000, |
| 407 | .clock_mc4 = 125000000, |
| 408 | .espi_nports = 1, |
| 409 | .clock_elmer0 = 44, |
| 410 | .mdio_mdien = 1, |
| 411 | .mdio_mdiinv = 1, |
| 412 | .mdio_mdc = 1, |
| 413 | .mdio_phybaseaddr = 1, |
| 414 | .gmac = &t1_pm3393_ops, |
| 415 | .gphy = &t1_my3126_ops, |
| 416 | .mdio_ops = &mi1_mdio_ext_ops, |
| 417 | .desc = "Chelsio T110 1x10GBase-CX4 TOE", |
| 418 | }, |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 419 | |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 420 | { |
| 421 | .board = CHBT_BOARD_N110, |
| 422 | .port_number = 1, |
| 423 | .caps = SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE, |
| 424 | .chip_term = CHBT_TERM_T1, |
| 425 | .chip_mac = CHBT_MAC_PM3393, |
| 426 | .chip_phy = CHBT_PHY_88X2010, |
| 427 | .clock_core = 125000000, |
| 428 | .espi_nports = 1, |
| 429 | .clock_elmer0 = 44, |
| 430 | .mdio_mdien = 0, |
| 431 | .mdio_mdiinv = 0, |
| 432 | .mdio_mdc = 1, |
| 433 | .mdio_phybaseaddr = 0, |
| 434 | .gmac = &t1_pm3393_ops, |
| 435 | .gphy = &t1_mv88x201x_ops, |
| 436 | .mdio_ops = &mi1_mdio_ext_ops, |
| 437 | .desc = "Chelsio N110 1x10GBaseX NIC", |
| 438 | }, |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 439 | |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 440 | { |
| 441 | .board = CHBT_BOARD_N210, |
| 442 | .port_number = 1, |
| 443 | .caps = SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE, |
| 444 | .chip_term = CHBT_TERM_T2, |
| 445 | .chip_mac = CHBT_MAC_PM3393, |
| 446 | .chip_phy = CHBT_PHY_88X2010, |
| 447 | .clock_core = 125000000, |
| 448 | .espi_nports = 1, |
| 449 | .clock_elmer0 = 44, |
| 450 | .mdio_mdien = 0, |
| 451 | .mdio_mdiinv = 0, |
| 452 | .mdio_mdc = 1, |
| 453 | .mdio_phybaseaddr = 0, |
| 454 | .gmac = &t1_pm3393_ops, |
| 455 | .gphy = &t1_mv88x201x_ops, |
| 456 | .mdio_ops = &mi1_mdio_ext_ops, |
| 457 | .desc = "Chelsio N210 1x10GBaseX NIC", |
| 458 | }, |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 459 | |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 460 | { |
| 461 | .board = CHBT_BOARD_CHT210, |
| 462 | .port_number = 1, |
| 463 | .caps = SUPPORTED_10000baseT_Full, |
| 464 | .chip_term = CHBT_TERM_T2, |
| 465 | .chip_mac = CHBT_MAC_PM3393, |
| 466 | .chip_phy = CHBT_PHY_88X2010, |
| 467 | .clock_core = 125000000, |
| 468 | .clock_mc3 = 133000000, |
| 469 | .clock_mc4 = 125000000, |
| 470 | .espi_nports = 1, |
| 471 | .clock_elmer0 = 44, |
| 472 | .mdio_mdien = 0, |
| 473 | .mdio_mdiinv = 0, |
| 474 | .mdio_mdc = 1, |
| 475 | .mdio_phybaseaddr = 0, |
| 476 | .gmac = &t1_pm3393_ops, |
| 477 | .gphy = &t1_mv88x201x_ops, |
| 478 | .mdio_ops = &mi1_mdio_ext_ops, |
| 479 | .desc = "Chelsio T210 1x10GBaseX TOE", |
| 480 | }, |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 481 | |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 482 | { |
| 483 | .board = CHBT_BOARD_CHT210, |
| 484 | .port_number = 1, |
| 485 | .caps = SUPPORTED_10000baseT_Full, |
| 486 | .chip_term = CHBT_TERM_T2, |
| 487 | .chip_mac = CHBT_MAC_PM3393, |
| 488 | .chip_phy = CHBT_PHY_MY3126, |
| 489 | .clock_core = 125000000, |
| 490 | .clock_mc3 = 133000000, |
| 491 | .clock_mc4 = 125000000, |
| 492 | .espi_nports = 1, |
| 493 | .clock_elmer0 = 44, |
| 494 | .mdio_mdien = 1, |
| 495 | .mdio_mdiinv = 1, |
| 496 | .mdio_mdc = 1, |
| 497 | .mdio_phybaseaddr = 1, |
| 498 | .gmac = &t1_pm3393_ops, |
| 499 | .gphy = &t1_my3126_ops, |
| 500 | .mdio_ops = &mi1_mdio_ext_ops, |
| 501 | .desc = "Chelsio T210 1x10GBase-CX4 TOE", |
| 502 | }, |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 503 | |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 504 | #ifdef CONFIG_CHELSIO_T1_1G |
Stephen Hemminger | 4c247db | 2007-02-20 15:58:01 -0800 | [diff] [blame] | 505 | { |
| 506 | .board = CHBT_BOARD_CHN204, |
| 507 | .port_number = 4, |
| 508 | .caps = SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
| 509 | | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
| 510 | | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | |
| 511 | SUPPORTED_PAUSE | SUPPORTED_TP, |
| 512 | .chip_term = CHBT_TERM_T2, |
| 513 | .chip_mac = CHBT_MAC_VSC7321, |
| 514 | .chip_phy = CHBT_PHY_88E1111, |
| 515 | .clock_core = 100000000, |
| 516 | .espi_nports = 4, |
| 517 | .clock_elmer0 = 44, |
| 518 | .mdio_mdien = 0, |
| 519 | .mdio_mdiinv = 0, |
| 520 | .mdio_mdc = 0, |
| 521 | .mdio_phybaseaddr = 4, |
| 522 | .gmac = &t1_vsc7326_ops, |
| 523 | .gphy = &t1_mv88e1xxx_ops, |
| 524 | .mdio_ops = &mi1_mdio_ops, |
| 525 | .desc = "Chelsio N204 4x100/1000BaseT NIC", |
| 526 | }, |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 527 | #endif |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 528 | |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 529 | }; |
| 530 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 531 | DEFINE_PCI_DEVICE_TABLE(t1_pci_tbl) = { |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 532 | CH_DEVICE(8, 0, CH_BRD_T110_1CU), |
| 533 | CH_DEVICE(8, 1, CH_BRD_T110_1CU), |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 534 | CH_DEVICE(7, 0, CH_BRD_N110_1F), |
| 535 | CH_DEVICE(10, 1, CH_BRD_N210_1F), |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 536 | CH_DEVICE(11, 1, CH_BRD_T210_1F), |
| 537 | CH_DEVICE(14, 1, CH_BRD_T210_1CU), |
| 538 | CH_DEVICE(16, 1, CH_BRD_N204_4CU), |
| 539 | { 0 } |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 540 | }; |
| 541 | |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 542 | MODULE_DEVICE_TABLE(pci, t1_pci_tbl); |
| 543 | |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 544 | /* |
| 545 | * Return the board_info structure with a given index. Out-of-range indices |
| 546 | * return NULL. |
| 547 | */ |
| 548 | const struct board_info *t1_get_board_info(unsigned int board_id) |
| 549 | { |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 550 | return board_id < ARRAY_SIZE(t1_board) ? &t1_board[board_id] : NULL; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | struct chelsio_vpd_t { |
| 554 | u32 format_version; |
| 555 | u8 serial_number[16]; |
| 556 | u8 mac_base_address[6]; |
| 557 | u8 pad[2]; /* make multiple-of-4 size requirement explicit */ |
| 558 | }; |
| 559 | |
| 560 | #define EEPROMSIZE (8 * 1024) |
| 561 | #define EEPROM_MAX_POLL 4 |
| 562 | |
| 563 | /* |
| 564 | * Read SEEPROM. A zero is written to the flag register when the addres is |
| 565 | * written to the Control register. The hardware device will set the flag to a |
| 566 | * one when 4B have been transferred to the Data register. |
| 567 | */ |
Al Viro | ac390c60 | 2007-12-22 18:56:33 +0000 | [diff] [blame] | 568 | int t1_seeprom_read(adapter_t *adapter, u32 addr, __le32 *data) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 569 | { |
| 570 | int i = EEPROM_MAX_POLL; |
| 571 | u16 val; |
Al Viro | ac390c60 | 2007-12-22 18:56:33 +0000 | [diff] [blame] | 572 | u32 v; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 573 | |
| 574 | if (addr >= EEPROMSIZE || (addr & 3)) |
| 575 | return -EINVAL; |
| 576 | |
| 577 | pci_write_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, (u16)addr); |
| 578 | do { |
| 579 | udelay(50); |
| 580 | pci_read_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, &val); |
| 581 | } while (!(val & F_VPD_OP_FLAG) && --i); |
| 582 | |
| 583 | if (!(val & F_VPD_OP_FLAG)) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 584 | pr_err("%s: reading EEPROM address 0x%x failed\n", |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 585 | adapter->name, addr); |
| 586 | return -EIO; |
| 587 | } |
Al Viro | ac390c60 | 2007-12-22 18:56:33 +0000 | [diff] [blame] | 588 | pci_read_config_dword(adapter->pdev, A_PCICFG_VPD_DATA, &v); |
| 589 | *data = cpu_to_le32(v); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int t1_eeprom_vpd_get(adapter_t *adapter, struct chelsio_vpd_t *vpd) |
| 594 | { |
| 595 | int addr, ret = 0; |
| 596 | |
| 597 | for (addr = 0; !ret && addr < sizeof(*vpd); addr += sizeof(u32)) |
| 598 | ret = t1_seeprom_read(adapter, addr, |
Al Viro | ac390c60 | 2007-12-22 18:56:33 +0000 | [diff] [blame] | 599 | (__le32 *)((u8 *)vpd + addr)); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 600 | |
| 601 | return ret; |
| 602 | } |
| 603 | |
| 604 | /* |
| 605 | * Read a port's MAC address from the VPD ROM. |
| 606 | */ |
| 607 | static int vpd_macaddress_get(adapter_t *adapter, int index, u8 mac_addr[]) |
| 608 | { |
| 609 | struct chelsio_vpd_t vpd; |
| 610 | |
| 611 | if (t1_eeprom_vpd_get(adapter, &vpd)) |
| 612 | return 1; |
| 613 | memcpy(mac_addr, vpd.mac_base_address, 5); |
| 614 | mac_addr[5] = vpd.mac_base_address[5] + index; |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Set up the MAC/PHY according to the requested link settings. |
| 620 | * |
| 621 | * If the PHY can auto-negotiate first decide what to advertise, then |
| 622 | * enable/disable auto-negotiation as desired and reset. |
| 623 | * |
| 624 | * If the PHY does not auto-negotiate we just reset it. |
| 625 | * |
| 626 | * If auto-negotiation is off set the MAC to the proper speed/duplex/FC, |
| 627 | * otherwise do it later based on the outcome of auto-negotiation. |
| 628 | */ |
| 629 | int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc) |
| 630 | { |
| 631 | unsigned int fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX); |
| 632 | |
| 633 | if (lc->supported & SUPPORTED_Autoneg) { |
| 634 | lc->advertising &= ~(ADVERTISED_ASYM_PAUSE | ADVERTISED_PAUSE); |
| 635 | if (fc) { |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 636 | if (fc == ((PAUSE_RX | PAUSE_TX) & |
| 637 | (mac->adapter->params.nports < 2))) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 638 | lc->advertising |= ADVERTISED_PAUSE; |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 639 | else { |
| 640 | lc->advertising |= ADVERTISED_ASYM_PAUSE; |
| 641 | if (fc == PAUSE_RX) |
| 642 | lc->advertising |= ADVERTISED_PAUSE; |
| 643 | } |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 644 | } |
| 645 | phy->ops->advertise(phy, lc->advertising); |
| 646 | |
| 647 | if (lc->autoneg == AUTONEG_DISABLE) { |
| 648 | lc->speed = lc->requested_speed; |
| 649 | lc->duplex = lc->requested_duplex; |
| 650 | lc->fc = (unsigned char)fc; |
| 651 | mac->ops->set_speed_duplex_fc(mac, lc->speed, |
| 652 | lc->duplex, fc); |
| 653 | /* Also disables autoneg */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 654 | phy->state = PHY_AUTONEG_RDY; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 655 | phy->ops->set_speed_duplex(phy, lc->speed, lc->duplex); |
| 656 | phy->ops->reset(phy, 0); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 657 | } else { |
| 658 | phy->state = PHY_AUTONEG_EN; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 659 | phy->ops->autoneg_enable(phy); /* also resets PHY */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 660 | } |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 661 | } else { |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 662 | phy->state = PHY_AUTONEG_RDY; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 663 | mac->ops->set_speed_duplex_fc(mac, -1, -1, fc); |
| 664 | lc->fc = (unsigned char)fc; |
| 665 | phy->ops->reset(phy, 0); |
| 666 | } |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * External interrupt handler for boards using elmer0. |
| 672 | */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 673 | int t1_elmer0_ext_intr_handler(adapter_t *adapter) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 674 | { |
Stephen Hemminger | 11e5a20 | 2006-12-01 16:36:13 -0800 | [diff] [blame] | 675 | struct cphy *phy; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 676 | int phy_cause; |
Stephen Hemminger | 11e5a20 | 2006-12-01 16:36:13 -0800 | [diff] [blame] | 677 | u32 cause; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 678 | |
| 679 | t1_tpi_read(adapter, A_ELMER0_INT_CAUSE, &cause); |
| 680 | |
| 681 | switch (board_info(adapter)->board) { |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 682 | #ifdef CONFIG_CHELSIO_T1_1G |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 683 | case CHBT_BOARD_CHT204: |
| 684 | case CHBT_BOARD_CHT204E: |
| 685 | case CHBT_BOARD_CHN204: |
| 686 | case CHBT_BOARD_CHT204V: { |
| 687 | int i, port_bit; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 688 | for_each_port(adapter, i) { |
| 689 | port_bit = i + 1; |
Francois Romieu | c697f83 | 2006-12-05 22:38:00 +0100 | [diff] [blame] | 690 | if (!(cause & (1 << port_bit))) |
| 691 | continue; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 692 | |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 693 | phy = adapter->port[i].phy; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 694 | phy_cause = phy->ops->interrupt_handler(phy); |
| 695 | if (phy_cause & cphy_cause_link_change) |
| 696 | t1_link_changed(adapter, i); |
| 697 | } |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 698 | break; |
| 699 | } |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 700 | case CHBT_BOARD_CHT101: |
| 701 | if (cause & ELMER0_GP_BIT1) { /* Marvell 88E1111 interrupt */ |
| 702 | phy = adapter->port[0].phy; |
| 703 | phy_cause = phy->ops->interrupt_handler(phy); |
| 704 | if (phy_cause & cphy_cause_link_change) |
| 705 | t1_link_changed(adapter, 0); |
| 706 | } |
| 707 | break; |
| 708 | case CHBT_BOARD_7500: { |
| 709 | int p; |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 710 | /* |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 711 | * Elmer0's interrupt cause isn't useful here because there is |
| 712 | * only one bit that can be set for all 4 ports. This means |
| 713 | * we are forced to check every PHY's interrupt status |
| 714 | * register to see who initiated the interrupt. |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 715 | */ |
| 716 | for_each_port(adapter, p) { |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 717 | phy = adapter->port[p].phy; |
| 718 | phy_cause = phy->ops->interrupt_handler(phy); |
| 719 | if (phy_cause & cphy_cause_link_change) |
| 720 | t1_link_changed(adapter, p); |
| 721 | } |
| 722 | break; |
| 723 | } |
| 724 | #endif |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 725 | case CHBT_BOARD_CHT210: |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 726 | case CHBT_BOARD_N210: |
| 727 | case CHBT_BOARD_N110: |
| 728 | if (cause & ELMER0_GP_BIT6) { /* Marvell 88x2010 interrupt */ |
| 729 | phy = adapter->port[0].phy; |
| 730 | phy_cause = phy->ops->interrupt_handler(phy); |
| 731 | if (phy_cause & cphy_cause_link_change) |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 732 | t1_link_changed(adapter, 0); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 733 | } |
| 734 | break; |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 735 | case CHBT_BOARD_8000: |
| 736 | case CHBT_BOARD_CHT110: |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 737 | if (netif_msg_intr(adapter)) |
| 738 | dev_dbg(&adapter->pdev->dev, |
| 739 | "External interrupt cause 0x%x\n", cause); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 740 | if (cause & ELMER0_GP_BIT1) { /* PMC3393 INTB */ |
| 741 | struct cmac *mac = adapter->port[0].mac; |
| 742 | |
| 743 | mac->ops->interrupt_handler(mac); |
| 744 | } |
| 745 | if (cause & ELMER0_GP_BIT5) { /* XPAK MOD_DETECT */ |
| 746 | u32 mod_detect; |
| 747 | |
| 748 | t1_tpi_read(adapter, |
| 749 | A_ELMER0_GPI_STAT, &mod_detect); |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 750 | if (netif_msg_link(adapter)) |
| 751 | dev_info(&adapter->pdev->dev, "XPAK %s\n", |
| 752 | mod_detect ? "removed" : "inserted"); |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 753 | } |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 754 | break; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 755 | #ifdef CONFIG_CHELSIO_T1_COUGAR |
| 756 | case CHBT_BOARD_COUGAR: |
| 757 | if (adapter->params.nports == 1) { |
| 758 | if (cause & ELMER0_GP_BIT1) { /* Vitesse MAC */ |
| 759 | struct cmac *mac = adapter->port[0].mac; |
| 760 | mac->ops->interrupt_handler(mac); |
| 761 | } |
| 762 | if (cause & ELMER0_GP_BIT5) { /* XPAK MOD_DETECT */ |
| 763 | } |
| 764 | } else { |
| 765 | int i, port_bit; |
| 766 | |
| 767 | for_each_port(adapter, i) { |
| 768 | port_bit = i ? i + 1 : 0; |
Francois Romieu | c697f83 | 2006-12-05 22:38:00 +0100 | [diff] [blame] | 769 | if (!(cause & (1 << port_bit))) |
| 770 | continue; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 771 | |
| 772 | phy = adapter->port[i].phy; |
| 773 | phy_cause = phy->ops->interrupt_handler(phy); |
| 774 | if (phy_cause & cphy_cause_link_change) |
| 775 | t1_link_changed(adapter, i); |
| 776 | } |
| 777 | } |
| 778 | break; |
| 779 | #endif |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 780 | } |
| 781 | t1_tpi_write(adapter, A_ELMER0_INT_CAUSE, cause); |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | /* Enables all interrupts. */ |
| 786 | void t1_interrupts_enable(adapter_t *adapter) |
| 787 | { |
| 788 | unsigned int i; |
| 789 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 790 | adapter->slow_intr_mask = F_PL_INTR_SGE_ERR | F_PL_INTR_TP; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 791 | |
| 792 | t1_sge_intr_enable(adapter->sge); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 793 | t1_tp_intr_enable(adapter->tp); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 794 | if (adapter->espi) { |
| 795 | adapter->slow_intr_mask |= F_PL_INTR_ESPI; |
| 796 | t1_espi_intr_enable(adapter->espi); |
| 797 | } |
| 798 | |
| 799 | /* Enable MAC/PHY interrupts for each port. */ |
| 800 | for_each_port(adapter, i) { |
| 801 | adapter->port[i].mac->ops->interrupt_enable(adapter->port[i].mac); |
| 802 | adapter->port[i].phy->ops->interrupt_enable(adapter->port[i].phy); |
| 803 | } |
| 804 | |
| 805 | /* Enable PCIX & external chip interrupts on ASIC boards. */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 806 | if (t1_is_asic(adapter)) { |
| 807 | u32 pl_intr = readl(adapter->regs + A_PL_ENABLE); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 808 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 809 | /* PCI-X interrupts */ |
| 810 | pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE, |
| 811 | 0xffffffff); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 812 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 813 | adapter->slow_intr_mask |= F_PL_INTR_EXT | F_PL_INTR_PCIX; |
| 814 | pl_intr |= F_PL_INTR_EXT | F_PL_INTR_PCIX; |
| 815 | writel(pl_intr, adapter->regs + A_PL_ENABLE); |
| 816 | } |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | /* Disables all interrupts. */ |
| 820 | void t1_interrupts_disable(adapter_t* adapter) |
| 821 | { |
| 822 | unsigned int i; |
| 823 | |
| 824 | t1_sge_intr_disable(adapter->sge); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 825 | t1_tp_intr_disable(adapter->tp); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 826 | if (adapter->espi) |
| 827 | t1_espi_intr_disable(adapter->espi); |
| 828 | |
| 829 | /* Disable MAC/PHY interrupts for each port. */ |
| 830 | for_each_port(adapter, i) { |
| 831 | adapter->port[i].mac->ops->interrupt_disable(adapter->port[i].mac); |
| 832 | adapter->port[i].phy->ops->interrupt_disable(adapter->port[i].phy); |
| 833 | } |
| 834 | |
| 835 | /* Disable PCIX & external chip interrupts. */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 836 | if (t1_is_asic(adapter)) |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 837 | writel(0, adapter->regs + A_PL_ENABLE); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 838 | |
| 839 | /* PCI-X interrupts */ |
| 840 | pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE, 0); |
| 841 | |
| 842 | adapter->slow_intr_mask = 0; |
| 843 | } |
| 844 | |
| 845 | /* Clears all interrupts */ |
| 846 | void t1_interrupts_clear(adapter_t* adapter) |
| 847 | { |
| 848 | unsigned int i; |
| 849 | |
| 850 | t1_sge_intr_clear(adapter->sge); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 851 | t1_tp_intr_clear(adapter->tp); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 852 | if (adapter->espi) |
| 853 | t1_espi_intr_clear(adapter->espi); |
| 854 | |
| 855 | /* Clear MAC/PHY interrupts for each port. */ |
| 856 | for_each_port(adapter, i) { |
| 857 | adapter->port[i].mac->ops->interrupt_clear(adapter->port[i].mac); |
| 858 | adapter->port[i].phy->ops->interrupt_clear(adapter->port[i].phy); |
| 859 | } |
| 860 | |
| 861 | /* Enable interrupts for external devices. */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 862 | if (t1_is_asic(adapter)) { |
| 863 | u32 pl_intr = readl(adapter->regs + A_PL_CAUSE); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 864 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 865 | writel(pl_intr | F_PL_INTR_EXT | F_PL_INTR_PCIX, |
| 866 | adapter->regs + A_PL_CAUSE); |
| 867 | } |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 868 | |
| 869 | /* PCI-X interrupts */ |
| 870 | pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, 0xffffffff); |
| 871 | } |
| 872 | |
| 873 | /* |
| 874 | * Slow path interrupt handler for ASICs. |
| 875 | */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 876 | static int asic_slow_intr(adapter_t *adapter) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 877 | { |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 878 | u32 cause = readl(adapter->regs + A_PL_CAUSE); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 879 | |
| 880 | cause &= adapter->slow_intr_mask; |
| 881 | if (!cause) |
| 882 | return 0; |
| 883 | if (cause & F_PL_INTR_SGE_ERR) |
| 884 | t1_sge_intr_error_handler(adapter->sge); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 885 | if (cause & F_PL_INTR_TP) |
| 886 | t1_tp_intr_handler(adapter->tp); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 887 | if (cause & F_PL_INTR_ESPI) |
| 888 | t1_espi_intr_handler(adapter->espi); |
| 889 | if (cause & F_PL_INTR_PCIX) |
| 890 | t1_pci_intr_handler(adapter); |
| 891 | if (cause & F_PL_INTR_EXT) |
Stephen Hemminger | 33a85aa | 2007-10-08 16:19:10 -0700 | [diff] [blame] | 892 | t1_elmer0_ext_intr(adapter); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 893 | |
| 894 | /* Clear the interrupts just processed. */ |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 895 | writel(cause, adapter->regs + A_PL_CAUSE); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 896 | readl(adapter->regs + A_PL_CAUSE); /* flush writes */ |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 897 | return 1; |
| 898 | } |
| 899 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 900 | int t1_slow_intr_handler(adapter_t *adapter) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 901 | { |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 902 | #ifdef CONFIG_CHELSIO_T1_1G |
| 903 | if (!t1_is_asic(adapter)) |
| 904 | return fpga_slow_intr(adapter); |
| 905 | #endif |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 906 | return asic_slow_intr(adapter); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 907 | } |
| 908 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 909 | /* Power sequencing is a work-around for Intel's XPAKs. */ |
| 910 | static void power_sequence_xpak(adapter_t* adapter) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 911 | { |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 912 | u32 mod_detect; |
| 913 | u32 gpo; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 914 | |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 915 | /* Check for XPAK */ |
| 916 | t1_tpi_read(adapter, A_ELMER0_GPI_STAT, &mod_detect); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 917 | if (!(ELMER0_GP_BIT5 & mod_detect)) { |
| 918 | /* XPAK is present */ |
| 919 | t1_tpi_read(adapter, A_ELMER0_GPO, &gpo); |
| 920 | gpo |= ELMER0_GP_BIT18; |
| 921 | t1_tpi_write(adapter, A_ELMER0_GPO, gpo); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | |
| 925 | int __devinit t1_get_board_rev(adapter_t *adapter, const struct board_info *bi, |
| 926 | struct adapter_params *p) |
| 927 | { |
| 928 | p->chip_version = bi->chip_term; |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 929 | p->is_asic = (p->chip_version != CHBT_TERM_FPGA); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 930 | if (p->chip_version == CHBT_TERM_T1 || |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 931 | p->chip_version == CHBT_TERM_T2 || |
| 932 | p->chip_version == CHBT_TERM_FPGA) { |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 933 | u32 val = readl(adapter->regs + A_TP_PC_CONFIG); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 934 | |
| 935 | val = G_TP_PC_REV(val); |
| 936 | if (val == 2) |
| 937 | p->chip_revision = TERM_T1B; |
| 938 | else if (val == 3) |
| 939 | p->chip_revision = TERM_T2; |
| 940 | else |
| 941 | return -1; |
| 942 | } else |
| 943 | return -1; |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | /* |
| 948 | * Enable board components other than the Chelsio chip, such as external MAC |
| 949 | * and PHY. |
| 950 | */ |
| 951 | static int board_init(adapter_t *adapter, const struct board_info *bi) |
| 952 | { |
| 953 | switch (bi->board) { |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 954 | case CHBT_BOARD_8000: |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 955 | case CHBT_BOARD_N110: |
| 956 | case CHBT_BOARD_N210: |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 957 | case CHBT_BOARD_CHT210: |
| 958 | case CHBT_BOARD_COUGAR: |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 959 | t1_tpi_par(adapter, 0xf); |
| 960 | t1_tpi_write(adapter, A_ELMER0_GPO, 0x800); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 961 | break; |
| 962 | case CHBT_BOARD_CHT110: |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 963 | t1_tpi_par(adapter, 0xf); |
| 964 | t1_tpi_write(adapter, A_ELMER0_GPO, 0x1800); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 965 | |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 966 | /* TBD XXX Might not need. This fixes a problem |
| 967 | * described in the Intel SR XPAK errata. |
| 968 | */ |
| 969 | power_sequence_xpak(adapter); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 970 | break; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 971 | #ifdef CONFIG_CHELSIO_T1_1G |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 972 | case CHBT_BOARD_CHT204E: |
| 973 | /* add config space write here */ |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 974 | case CHBT_BOARD_CHT204: |
| 975 | case CHBT_BOARD_CHT204V: |
| 976 | case CHBT_BOARD_CHN204: |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 977 | t1_tpi_par(adapter, 0xf); |
| 978 | t1_tpi_write(adapter, A_ELMER0_GPO, 0x804); |
| 979 | break; |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 980 | case CHBT_BOARD_CHT101: |
| 981 | case CHBT_BOARD_7500: |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 982 | t1_tpi_par(adapter, 0xf); |
| 983 | t1_tpi_write(adapter, A_ELMER0_GPO, 0x1804); |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 984 | break; |
| 985 | #endif |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 986 | } |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | /* |
| 991 | * Initialize and configure the Terminator HW modules. Note that external |
| 992 | * MAC and PHYs are initialized separately. |
| 993 | */ |
| 994 | int t1_init_hw_modules(adapter_t *adapter) |
| 995 | { |
| 996 | int err = -EIO; |
| 997 | const struct board_info *bi = board_info(adapter); |
| 998 | |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 999 | if (!bi->clock_mc4) { |
| 1000 | u32 val = readl(adapter->regs + A_MC4_CFG); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1001 | |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 1002 | writel(val | F_READY | F_MC4_SLOW, adapter->regs + A_MC4_CFG); |
| 1003 | writel(F_M_BUS_ENABLE | F_TCAM_RESET, |
| 1004 | adapter->regs + A_MC5_CONFIG); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 1007 | #ifdef CONFIG_CHELSIO_T1_COUGAR |
| 1008 | if (adapter->cspi && t1_cspi_init(adapter->cspi)) |
| 1009 | goto out_err; |
| 1010 | #endif |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1011 | if (adapter->espi && t1_espi_init(adapter->espi, bi->chip_mac, |
| 1012 | bi->espi_nports)) |
| 1013 | goto out_err; |
| 1014 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 1015 | if (t1_tp_reset(adapter->tp, &adapter->params.tp, bi->clock_core)) |
| 1016 | goto out_err; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1017 | |
| 1018 | err = t1_sge_configure(adapter->sge, &adapter->params.sge); |
| 1019 | if (err) |
| 1020 | goto out_err; |
| 1021 | |
| 1022 | err = 0; |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 1023 | out_err: |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1024 | return err; |
| 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | * Determine a card's PCI mode. |
| 1029 | */ |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 1030 | static void __devinit get_pci_mode(adapter_t *adapter, struct chelsio_pci_params *p) |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1031 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 1032 | static const unsigned short speed_map[] = { 33, 66, 100, 133 }; |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1033 | u32 pci_mode; |
| 1034 | |
| 1035 | pci_read_config_dword(adapter->pdev, A_PCICFG_MODE, &pci_mode); |
| 1036 | p->speed = speed_map[G_PCI_MODE_CLK(pci_mode)]; |
| 1037 | p->width = (pci_mode & F_PCI_MODE_64BIT) ? 64 : 32; |
| 1038 | p->is_pcix = (pci_mode & F_PCI_MODE_PCIX) != 0; |
| 1039 | } |
| 1040 | |
| 1041 | /* |
| 1042 | * Release the structures holding the SW per-Terminator-HW-module state. |
| 1043 | */ |
| 1044 | void t1_free_sw_modules(adapter_t *adapter) |
| 1045 | { |
| 1046 | unsigned int i; |
| 1047 | |
| 1048 | for_each_port(adapter, i) { |
| 1049 | struct cmac *mac = adapter->port[i].mac; |
| 1050 | struct cphy *phy = adapter->port[i].phy; |
| 1051 | |
| 1052 | if (mac) |
| 1053 | mac->ops->destroy(mac); |
| 1054 | if (phy) |
| 1055 | phy->ops->destroy(phy); |
| 1056 | } |
| 1057 | |
| 1058 | if (adapter->sge) |
| 1059 | t1_sge_destroy(adapter->sge); |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 1060 | if (adapter->tp) |
| 1061 | t1_tp_destroy(adapter->tp); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1062 | if (adapter->espi) |
| 1063 | t1_espi_destroy(adapter->espi); |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 1064 | #ifdef CONFIG_CHELSIO_T1_COUGAR |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 1065 | if (adapter->cspi) |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 1066 | t1_cspi_destroy(adapter->cspi); |
| 1067 | #endif |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | static void __devinit init_link_config(struct link_config *lc, |
| 1071 | const struct board_info *bi) |
| 1072 | { |
| 1073 | lc->supported = bi->caps; |
| 1074 | lc->requested_speed = lc->speed = SPEED_INVALID; |
| 1075 | lc->requested_duplex = lc->duplex = DUPLEX_INVALID; |
| 1076 | lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX; |
| 1077 | if (lc->supported & SUPPORTED_Autoneg) { |
| 1078 | lc->advertising = lc->supported; |
| 1079 | lc->autoneg = AUTONEG_ENABLE; |
| 1080 | lc->requested_fc |= PAUSE_AUTONEG; |
| 1081 | } else { |
| 1082 | lc->advertising = 0; |
| 1083 | lc->autoneg = AUTONEG_DISABLE; |
| 1084 | } |
| 1085 | } |
| 1086 | |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 1087 | #ifdef CONFIG_CHELSIO_T1_COUGAR |
| 1088 | if (bi->clock_cspi && !(adapter->cspi = t1_cspi_create(adapter))) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 1089 | pr_err("%s: CSPI initialization failed\n", |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 1090 | adapter->name); |
| 1091 | goto error; |
Francois Romieu | 356bd14 | 2006-12-11 23:47:00 +0100 | [diff] [blame] | 1092 | } |
Stephen Hemminger | 352c417 | 2006-12-01 16:36:17 -0800 | [diff] [blame] | 1093 | #endif |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1094 | |
| 1095 | /* |
| 1096 | * Allocate and initialize the data structures that hold the SW state of |
| 1097 | * the Terminator HW modules. |
| 1098 | */ |
| 1099 | int __devinit t1_init_sw_modules(adapter_t *adapter, |
| 1100 | const struct board_info *bi) |
| 1101 | { |
| 1102 | unsigned int i; |
| 1103 | |
| 1104 | adapter->params.brd_info = bi; |
| 1105 | adapter->params.nports = bi->port_number; |
| 1106 | adapter->params.stats_update_period = bi->gmac->stats_update_period; |
| 1107 | |
| 1108 | adapter->sge = t1_sge_create(adapter, &adapter->params.sge); |
| 1109 | if (!adapter->sge) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 1110 | pr_err("%s: SGE initialization failed\n", |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1111 | adapter->name); |
| 1112 | goto error; |
| 1113 | } |
| 1114 | |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1115 | if (bi->espi_nports && !(adapter->espi = t1_espi_create(adapter))) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 1116 | pr_err("%s: ESPI initialization failed\n", |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1117 | adapter->name); |
| 1118 | goto error; |
| 1119 | } |
| 1120 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 1121 | adapter->tp = t1_tp_create(adapter, &adapter->params.tp); |
| 1122 | if (!adapter->tp) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 1123 | pr_err("%s: TP initialization failed\n", |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 1124 | adapter->name); |
| 1125 | goto error; |
| 1126 | } |
| 1127 | |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1128 | board_init(adapter, bi); |
| 1129 | bi->mdio_ops->init(adapter, bi); |
| 1130 | if (bi->gphy->reset) |
| 1131 | bi->gphy->reset(adapter); |
| 1132 | if (bi->gmac->reset) |
| 1133 | bi->gmac->reset(adapter); |
| 1134 | |
| 1135 | for_each_port(adapter, i) { |
| 1136 | u8 hw_addr[6]; |
| 1137 | struct cmac *mac; |
| 1138 | int phy_addr = bi->mdio_phybaseaddr + i; |
| 1139 | |
Divy Le Ray | 703ceba | 2009-05-20 15:56:12 +0000 | [diff] [blame] | 1140 | adapter->port[i].phy = bi->gphy->create(adapter->port[i].dev, |
| 1141 | phy_addr, bi->mdio_ops); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1142 | if (!adapter->port[i].phy) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 1143 | pr_err("%s: PHY %d initialization failed\n", |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1144 | adapter->name, i); |
| 1145 | goto error; |
| 1146 | } |
| 1147 | |
| 1148 | adapter->port[i].mac = mac = bi->gmac->create(adapter, i); |
| 1149 | if (!mac) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 1150 | pr_err("%s: MAC %d initialization failed\n", |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1151 | adapter->name, i); |
| 1152 | goto error; |
| 1153 | } |
| 1154 | |
| 1155 | /* |
| 1156 | * Get the port's MAC addresses either from the EEPROM if one |
| 1157 | * exists or the one hardcoded in the MAC. |
| 1158 | */ |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 1159 | if (!t1_is_asic(adapter) || bi->chip_mac == CHBT_MAC_DUMMY) |
| 1160 | mac->ops->macaddress_get(mac, hw_addr); |
| 1161 | else if (vpd_macaddress_get(adapter, i, hw_addr)) { |
Joe Perches | c1f5121 | 2010-02-22 16:56:57 +0000 | [diff] [blame] | 1162 | pr_err("%s: could not read MAC address from VPD ROM\n", |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 1163 | adapter->port[i].dev->name); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1164 | goto error; |
| 1165 | } |
Scott Bardone | 559fb51 | 2005-06-23 01:40:19 -0400 | [diff] [blame] | 1166 | memcpy(adapter->port[i].dev->dev_addr, hw_addr, ETH_ALEN); |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1167 | init_link_config(&adapter->port[i].link_config, bi); |
| 1168 | } |
| 1169 | |
| 1170 | get_pci_mode(adapter, &adapter->params.pci); |
| 1171 | t1_interrupts_clear(adapter); |
| 1172 | return 0; |
| 1173 | |
Stephen Hemminger | f1d3d38 | 2006-12-01 16:36:16 -0800 | [diff] [blame] | 1174 | error: |
Christoph Lameter | 8199d3a | 2005-03-30 13:34:31 -0800 | [diff] [blame] | 1175 | t1_free_sw_modules(adapter); |
| 1176 | return -1; |
| 1177 | } |