blob: c64bb2c6d0d69d6c9f6ed605d6e80b9aa0518a61 [file] [log] [blame]
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001/*
2 * Agere Systems Inc.
3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4 *
Alan Cox64f93032009-06-10 17:30:41 +01005 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07006 * 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 Cox64f93032009-06-10 17:30:41 +010022 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070023 * 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 Cox64f93032009-06-10 17:30:41 +010043 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070044 * 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"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070059#include "et131x_defs.h"
60
61#include <linux/init.h>
62#include <linux/module.h>
63#include <linux/types.h>
64#include <linux/kernel.h>
65
66#include <linux/sched.h>
67#include <linux/ptrace.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070068#include <linux/ctype.h>
69#include <linux/string.h>
70#include <linux/timer.h>
71#include <linux/interrupt.h>
72#include <linux/in.h>
73#include <linux/delay.h>
Alan Cox64f93032009-06-10 17:30:41 +010074#include <linux/io.h>
75#include <linux/bitops.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070076#include <asm/system.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070077
78#include <linux/netdevice.h>
79#include <linux/etherdevice.h>
80#include <linux/skbuff.h>
81#include <linux/if_arp.h>
82#include <linux/ioport.h>
83
84#include "et1310_phy.h"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070085#include "et1310_rx.h"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070086#include "et131x_adapter.h"
Alan Cox69ea5fc2010-01-18 15:34:24 +000087#include "et131x.h"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070088
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070089/**
90 * EnablePhyComa - called when network cable is unplugged
Alan Cox25ad00b2009-08-19 18:21:44 +010091 * @etdev: pointer to our adapter structure
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070092 *
93 * driver receive an phy status change interrupt while in D0 and check that
94 * phy_status is down.
95 *
96 * -- gate off JAGCore;
97 * -- set gigE PHY in Coma mode
98 * -- wake on phy_interrupt; Perform software reset JAGCore,
99 * re-initialize jagcore and gigE PHY
100 *
101 * Add D0-ASPM-PhyLinkDown Support:
102 * -- while in D0, when there is a phy_interrupt indicating phy link
103 * down status, call the MPSetPhyComa routine to enter this active
104 * state power saving mode
105 * -- while in D0-ASPM-PhyLinkDown mode, when there is a phy_interrupt
106 * indicating linkup status, call the MPDisablePhyComa routine to
107 * restore JAGCore and gigE PHY
108 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100109void EnablePhyComa(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700110{
Alan Cox37628602009-08-19 18:21:50 +0100111 unsigned long flags;
Alan Coxf2c98d22009-08-27 11:01:49 +0100112 u32 GlobalPmCSR;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700113
Alan Coxf2c98d22009-08-27 11:01:49 +0100114 GlobalPmCSR = readl(&etdev->regs->global.pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700115
116 /* Save the GbE PHY speed and duplex modes. Need to restore this
117 * when cable is plugged back in
118 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100119 etdev->PoMgmt.PowerDownSpeed = etdev->AiForceSpeed;
120 etdev->PoMgmt.PowerDownDuplex = etdev->AiForceDpx;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700121
122 /* Stop sending packets. */
Alan Cox37628602009-08-19 18:21:50 +0100123 spin_lock_irqsave(&etdev->SendHWLock, flags);
Alan Coxf6b35d62009-08-27 11:02:05 +0100124 etdev->Flags |= fMP_ADAPTER_LOWER_POWER;
Alan Cox37628602009-08-19 18:21:50 +0100125 spin_unlock_irqrestore(&etdev->SendHWLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700126
127 /* Wait for outstanding Receive packets */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700128
129 /* Gate off JAGCore 3 clock domains */
Alan Coxf2c98d22009-08-27 11:01:49 +0100130 GlobalPmCSR &= ~ET_PMCSR_INIT;
131 writel(GlobalPmCSR, &etdev->regs->global.pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700132
133 /* Program gigE PHY in to Coma mode */
Alan Coxf2c98d22009-08-27 11:01:49 +0100134 GlobalPmCSR |= ET_PM_PHY_SW_COMA;
135 writel(GlobalPmCSR, &etdev->regs->global.pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700136}
137
138/**
139 * DisablePhyComa - Disable the Phy Coma Mode
Alan Cox25ad00b2009-08-19 18:21:44 +0100140 * @etdev: pointer to our adapter structure
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700141 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100142void DisablePhyComa(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700143{
Alan Coxf2c98d22009-08-27 11:01:49 +0100144 u32 GlobalPmCSR;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700145
Alan Coxf2c98d22009-08-27 11:01:49 +0100146 GlobalPmCSR = readl(&etdev->regs->global.pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700147
148 /* Disable phy_sw_coma register and re-enable JAGCore clocks */
Alan Coxf2c98d22009-08-27 11:01:49 +0100149 GlobalPmCSR |= ET_PMCSR_INIT;
150 GlobalPmCSR &= ~ET_PM_PHY_SW_COMA;
151 writel(GlobalPmCSR, &etdev->regs->global.pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700152
153 /* Restore the GbE PHY speed and duplex modes;
154 * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY
155 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100156 etdev->AiForceSpeed = etdev->PoMgmt.PowerDownSpeed;
157 etdev->AiForceDpx = etdev->PoMgmt.PowerDownDuplex;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700158
159 /* Re-initialize the send structures */
Alan Cox25ad00b2009-08-19 18:21:44 +0100160 et131x_init_send(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700161
162 /* Reset the RFD list and re-start RU */
Alan Cox25ad00b2009-08-19 18:21:44 +0100163 et131x_reset_recv(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700164
165 /* Bring the device back to the state it was during init prior to
Alan Cox64f93032009-06-10 17:30:41 +0100166 * autonegotiation being complete. This way, when we get the auto-neg
167 * complete interrupt, we can complete init by calling ConfigMacREGS2.
168 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100169 et131x_soft_reset(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700170
171 /* setup et1310 as per the documentation ?? */
Alan Cox25ad00b2009-08-19 18:21:44 +0100172 et131x_adapter_setup(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700173
174 /* Allow Tx to restart */
Alan Coxf6b35d62009-08-27 11:02:05 +0100175 etdev->Flags &= ~fMP_ADAPTER_LOWER_POWER;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700176
177 /* Need to re-enable Rx. */
Alan Cox25ad00b2009-08-19 18:21:44 +0100178 et131x_rx_dma_enable(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700179}
180