Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Agere Systems Inc. |
| 3 | * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs |
| 4 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 5 | * Copyright © 2005 Agere Systems Inc. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * http://www.agere.com |
| 8 | * |
| 9 | *------------------------------------------------------------------------------ |
| 10 | * |
| 11 | * et1310_pm.c - All power management related code (not completely implemented) |
| 12 | * |
| 13 | *------------------------------------------------------------------------------ |
| 14 | * |
| 15 | * SOFTWARE LICENSE |
| 16 | * |
| 17 | * This software is provided subject to the following terms and conditions, |
| 18 | * which you should read carefully before using the software. Using this |
| 19 | * software indicates your acceptance of these terms and conditions. If you do |
| 20 | * not agree with these terms and conditions, do not use the software. |
| 21 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 22 | * Copyright © 2005 Agere Systems Inc. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 23 | * All rights reserved. |
| 24 | * |
| 25 | * Redistribution and use in source or binary forms, with or without |
| 26 | * modifications, are permitted provided that the following conditions are met: |
| 27 | * |
| 28 | * . Redistributions of source code must retain the above copyright notice, this |
| 29 | * list of conditions and the following Disclaimer as comments in the code as |
| 30 | * well as in the documentation and/or other materials provided with the |
| 31 | * distribution. |
| 32 | * |
| 33 | * . Redistributions in binary form must reproduce the above copyright notice, |
| 34 | * this list of conditions and the following Disclaimer in the documentation |
| 35 | * and/or other materials provided with the distribution. |
| 36 | * |
| 37 | * . Neither the name of Agere Systems Inc. nor the names of the contributors |
| 38 | * may be used to endorse or promote products derived from this software |
| 39 | * without specific prior written permission. |
| 40 | * |
| 41 | * Disclaimer |
| 42 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 43 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 44 | * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF |
| 45 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY |
| 46 | * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN |
| 47 | * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY |
| 48 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 49 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 50 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 51 | * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT |
| 52 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 53 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 54 | * DAMAGE. |
| 55 | * |
| 56 | */ |
| 57 | |
| 58 | #include "et131x_version.h" |
| 59 | #include "et131x_debug.h" |
| 60 | #include "et131x_defs.h" |
| 61 | |
| 62 | #include <linux/init.h> |
| 63 | #include <linux/module.h> |
| 64 | #include <linux/types.h> |
| 65 | #include <linux/kernel.h> |
| 66 | |
| 67 | #include <linux/sched.h> |
| 68 | #include <linux/ptrace.h> |
| 69 | #include <linux/slab.h> |
| 70 | #include <linux/ctype.h> |
| 71 | #include <linux/string.h> |
| 72 | #include <linux/timer.h> |
| 73 | #include <linux/interrupt.h> |
| 74 | #include <linux/in.h> |
| 75 | #include <linux/delay.h> |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 76 | #include <linux/io.h> |
| 77 | #include <linux/bitops.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 78 | #include <asm/system.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 79 | |
| 80 | #include <linux/netdevice.h> |
| 81 | #include <linux/etherdevice.h> |
| 82 | #include <linux/skbuff.h> |
| 83 | #include <linux/if_arp.h> |
| 84 | #include <linux/ioport.h> |
| 85 | |
| 86 | #include "et1310_phy.h" |
| 87 | #include "et1310_pm.h" |
| 88 | #include "et1310_jagcore.h" |
| 89 | #include "et1310_mac.h" |
| 90 | #include "et1310_rx.h" |
| 91 | |
| 92 | #include "et131x_adapter.h" |
| 93 | #include "et131x_initpci.h" |
| 94 | |
| 95 | /* Data for debugging facilities */ |
| 96 | #ifdef CONFIG_ET131X_DEBUG |
| 97 | extern dbg_info_t *et131x_dbginfo; |
| 98 | #endif /* CONFIG_ET131X_DEBUG */ |
| 99 | |
| 100 | /** |
| 101 | * EnablePhyComa - called when network cable is unplugged |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 102 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 103 | * |
| 104 | * driver receive an phy status change interrupt while in D0 and check that |
| 105 | * phy_status is down. |
| 106 | * |
| 107 | * -- gate off JAGCore; |
| 108 | * -- set gigE PHY in Coma mode |
| 109 | * -- wake on phy_interrupt; Perform software reset JAGCore, |
| 110 | * re-initialize jagcore and gigE PHY |
| 111 | * |
| 112 | * Add D0-ASPM-PhyLinkDown Support: |
| 113 | * -- while in D0, when there is a phy_interrupt indicating phy link |
| 114 | * down status, call the MPSetPhyComa routine to enter this active |
| 115 | * state power saving mode |
| 116 | * -- while in D0-ASPM-PhyLinkDown mode, when there is a phy_interrupt |
| 117 | * indicating linkup status, call the MPDisablePhyComa routine to |
| 118 | * restore JAGCore and gigE PHY |
| 119 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 120 | void EnablePhyComa(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 121 | { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 122 | unsigned long flags; |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame^] | 123 | u32 GlobalPmCSR; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 124 | |
| 125 | DBG_ENTER(et131x_dbginfo); |
| 126 | |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame^] | 127 | GlobalPmCSR = readl(&etdev->regs->global.pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 128 | |
| 129 | /* Save the GbE PHY speed and duplex modes. Need to restore this |
| 130 | * when cable is plugged back in |
| 131 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 132 | etdev->PoMgmt.PowerDownSpeed = etdev->AiForceSpeed; |
| 133 | etdev->PoMgmt.PowerDownDuplex = etdev->AiForceDpx; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 134 | |
| 135 | /* Stop sending packets. */ |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 136 | spin_lock_irqsave(&etdev->SendHWLock, flags); |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 137 | MP_SET_FLAG(etdev, fMP_ADAPTER_LOWER_POWER); |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 138 | spin_unlock_irqrestore(&etdev->SendHWLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 139 | |
| 140 | /* Wait for outstanding Receive packets */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 141 | |
| 142 | /* Gate off JAGCore 3 clock domains */ |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame^] | 143 | GlobalPmCSR &= ~ET_PMCSR_INIT; |
| 144 | writel(GlobalPmCSR, &etdev->regs->global.pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 145 | |
| 146 | /* Program gigE PHY in to Coma mode */ |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame^] | 147 | GlobalPmCSR |= ET_PM_PHY_SW_COMA; |
| 148 | writel(GlobalPmCSR, &etdev->regs->global.pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 149 | |
| 150 | DBG_LEAVE(et131x_dbginfo); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * DisablePhyComa - Disable the Phy Coma Mode |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 155 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 156 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 157 | void DisablePhyComa(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 158 | { |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame^] | 159 | u32 GlobalPmCSR; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 160 | |
| 161 | DBG_ENTER(et131x_dbginfo); |
| 162 | |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame^] | 163 | GlobalPmCSR = readl(&etdev->regs->global.pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 164 | |
| 165 | /* Disable phy_sw_coma register and re-enable JAGCore clocks */ |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame^] | 166 | GlobalPmCSR |= ET_PMCSR_INIT; |
| 167 | GlobalPmCSR &= ~ET_PM_PHY_SW_COMA; |
| 168 | writel(GlobalPmCSR, &etdev->regs->global.pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 169 | |
| 170 | /* Restore the GbE PHY speed and duplex modes; |
| 171 | * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY |
| 172 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 173 | etdev->AiForceSpeed = etdev->PoMgmt.PowerDownSpeed; |
| 174 | etdev->AiForceDpx = etdev->PoMgmt.PowerDownDuplex; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 175 | |
| 176 | /* Re-initialize the send structures */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 177 | et131x_init_send(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 178 | |
| 179 | /* Reset the RFD list and re-start RU */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 180 | et131x_reset_recv(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 181 | |
| 182 | /* Bring the device back to the state it was during init prior to |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 183 | * autonegotiation being complete. This way, when we get the auto-neg |
| 184 | * complete interrupt, we can complete init by calling ConfigMacREGS2. |
| 185 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 186 | et131x_soft_reset(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 187 | |
| 188 | /* setup et1310 as per the documentation ?? */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 189 | et131x_adapter_setup(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 190 | |
| 191 | /* Allow Tx to restart */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 192 | MP_CLEAR_FLAG(etdev, fMP_ADAPTER_LOWER_POWER); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 193 | |
| 194 | /* Need to re-enable Rx. */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 195 | et131x_rx_dma_enable(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 196 | |
| 197 | DBG_LEAVE(et131x_dbginfo); |
| 198 | } |
| 199 | |