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 | * et131x_initpci.c - Routines and data used to register the driver with the |
| 12 | * PCI (and PCI Express) subsystem, as well as basic driver |
| 13 | * init and startup. |
| 14 | * |
| 15 | *------------------------------------------------------------------------------ |
| 16 | * |
| 17 | * SOFTWARE LICENSE |
| 18 | * |
| 19 | * This software is provided subject to the following terms and conditions, |
| 20 | * which you should read carefully before using the software. Using this |
| 21 | * software indicates your acceptance of these terms and conditions. If you do |
| 22 | * not agree with these terms and conditions, do not use the software. |
| 23 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 24 | * Copyright © 2005 Agere Systems Inc. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 25 | * All rights reserved. |
| 26 | * |
| 27 | * Redistribution and use in source or binary forms, with or without |
| 28 | * modifications, are permitted provided that the following conditions are met: |
| 29 | * |
| 30 | * . Redistributions of source code must retain the above copyright notice, this |
| 31 | * list of conditions and the following Disclaimer as comments in the code as |
| 32 | * well as in the documentation and/or other materials provided with the |
| 33 | * distribution. |
| 34 | * |
| 35 | * . Redistributions in binary form must reproduce the above copyright notice, |
| 36 | * this list of conditions and the following Disclaimer in the documentation |
| 37 | * and/or other materials provided with the distribution. |
| 38 | * |
| 39 | * . Neither the name of Agere Systems Inc. nor the names of the contributors |
| 40 | * may be used to endorse or promote products derived from this software |
| 41 | * without specific prior written permission. |
| 42 | * |
| 43 | * Disclaimer |
| 44 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 45 | * 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] | 46 | * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF |
| 47 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY |
| 48 | * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN |
| 49 | * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY |
| 50 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 51 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 52 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 53 | * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT |
| 54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 55 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 56 | * DAMAGE. |
| 57 | * |
| 58 | */ |
| 59 | |
| 60 | #include "et131x_version.h" |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 61 | #include "et131x_defs.h" |
| 62 | |
| 63 | #include <linux/pci.h> |
| 64 | #include <linux/init.h> |
| 65 | #include <linux/module.h> |
| 66 | #include <linux/types.h> |
| 67 | #include <linux/kernel.h> |
| 68 | |
| 69 | #include <linux/sched.h> |
| 70 | #include <linux/ptrace.h> |
| 71 | #include <linux/slab.h> |
| 72 | #include <linux/ctype.h> |
| 73 | #include <linux/string.h> |
| 74 | #include <linux/timer.h> |
| 75 | #include <linux/interrupt.h> |
| 76 | #include <linux/in.h> |
| 77 | #include <linux/delay.h> |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 78 | #include <linux/io.h> |
| 79 | #include <linux/bitops.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 80 | #include <asm/system.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 81 | |
| 82 | #include <linux/netdevice.h> |
| 83 | #include <linux/etherdevice.h> |
| 84 | #include <linux/skbuff.h> |
| 85 | #include <linux/if_arp.h> |
| 86 | #include <linux/ioport.h> |
| 87 | #include <linux/random.h> |
| 88 | |
| 89 | #include "et1310_phy.h" |
| 90 | #include "et1310_pm.h" |
| 91 | #include "et1310_jagcore.h" |
| 92 | |
| 93 | #include "et131x_adapter.h" |
| 94 | #include "et131x_netdev.h" |
| 95 | #include "et131x_config.h" |
| 96 | #include "et131x_isr.h" |
| 97 | |
| 98 | #include "et1310_address_map.h" |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 99 | #include "et1310_tx.h" |
| 100 | #include "et1310_rx.h" |
| 101 | #include "et1310_mac.h" |
| 102 | #include "et1310_eeprom.h" |
| 103 | |
| 104 | |
Alan Cox | 8c5f20f | 2009-08-27 11:00:24 +0100 | [diff] [blame] | 105 | /* Defines for Parameter Default/Min/Max vaules */ |
| 106 | #define PARM_SPEED_DUPLEX_MIN 0 |
| 107 | #define PARM_SPEED_DUPLEX_MAX 5 |
| 108 | |
| 109 | /* Module parameter for disabling NMI |
| 110 | * et131x_nmi_disable : |
| 111 | * Disable NMI (0-2) [0] |
| 112 | * 0 : |
| 113 | * 1 : |
| 114 | * 2 : |
| 115 | */ |
| 116 | static u32 et131x_nmi_disable; /* 0-2 */ |
| 117 | module_param(et131x_nmi_disable, uint, 0); |
| 118 | MODULE_PARM_DESC(et131x_nmi_disable, "Disable NMI (0-2) [0]"); |
| 119 | |
| 120 | /* Module parameter for manual speed setting |
| 121 | * Set Link speed and dublex manually (0-5) [0] |
| 122 | * 1 : 10Mb Half-Duplex |
| 123 | * 2 : 10Mb Full-Duplex |
| 124 | * 3 : 100Mb Half-Duplex |
| 125 | * 4 : 100Mb Full-Duplex |
| 126 | * 5 : 1000Mb Full-Duplex |
| 127 | * 0 : Auto Speed Auto Duplex // default |
| 128 | */ |
| 129 | static u32 et131x_speed_set; |
| 130 | module_param(et131x_speed_set, uint, 0); |
| 131 | MODULE_PARM_DESC(et131x_speed_set, |
| 132 | "Set Link speed and dublex manually (0-5) [0] \n 1 : 10Mb Half-Duplex \n 2 : 10Mb Full-Duplex \n 3 : 100Mb Half-Duplex \n 4 : 100Mb Full-Duplex \n 5 : 1000Mb Full-Duplex \n 0 : Auto Speed Auto Dublex"); |
| 133 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 134 | /** |
| 135 | * et131x_find_adapter - Find the adapter and get all the assigned resources |
| 136 | * @adapter: pointer to our private adapter structure |
| 137 | * |
| 138 | * Returns 0 on success, errno on failure (as defined in errno.h) |
| 139 | */ |
| 140 | int et131x_find_adapter(struct et131x_adapter *adapter, struct pci_dev *pdev) |
| 141 | { |
| 142 | int result; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 143 | uint8_t maxPayload = 0; |
| 144 | uint8_t read_size_reg; |
| 145 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 146 | /* Allow disabling of Non-Maskable Interrupts in I/O space, to |
| 147 | * support validation. |
| 148 | */ |
| 149 | if (adapter->RegistryNMIDisable) { |
| 150 | uint8_t RegisterVal; |
| 151 | |
| 152 | RegisterVal = inb(ET1310_NMI_DISABLE); |
| 153 | RegisterVal &= 0xf3; |
| 154 | |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 155 | if (adapter->RegistryNMIDisable == 2) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 156 | RegisterVal |= 0xc; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 157 | |
| 158 | outb(ET1310_NMI_DISABLE, RegisterVal); |
| 159 | } |
| 160 | |
Alan Cox | 4e02b4b | 2009-10-06 15:47:22 +0100 | [diff] [blame^] | 161 | if (et131x_init_eeprom(adapter) < 0) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 162 | return -EIO; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 163 | |
| 164 | /* Let's set up the PORT LOGIC Register. First we need to know what |
| 165 | * the max_payload_size is |
| 166 | */ |
| 167 | result = pci_read_config_byte(pdev, ET1310_PCI_MAX_PYLD, &maxPayload); |
| 168 | if (result != PCIBIOS_SUCCESSFUL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 169 | dev_err(&pdev->dev, |
| 170 | "Could not read PCI config space for Max Payload Size\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 171 | return -EIO; |
| 172 | } |
| 173 | |
| 174 | /* Program the Ack/Nak latency and replay timers */ |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 175 | maxPayload &= 0x07; /* Only the lower 3 bits are valid */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 176 | |
| 177 | if (maxPayload < 2) { |
| 178 | const uint16_t AckNak[2] = { 0x76, 0xD0 }; |
| 179 | const uint16_t Replay[2] = { 0x1E0, 0x2ED }; |
| 180 | |
| 181 | result = pci_write_config_word(pdev, ET1310_PCI_ACK_NACK, |
| 182 | AckNak[maxPayload]); |
| 183 | if (result != PCIBIOS_SUCCESSFUL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 184 | dev_err(&pdev->dev, |
| 185 | "Could not write PCI config space for ACK/NAK\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 186 | return -EIO; |
| 187 | } |
| 188 | |
| 189 | result = pci_write_config_word(pdev, ET1310_PCI_REPLAY, |
| 190 | Replay[maxPayload]); |
| 191 | if (result != PCIBIOS_SUCCESSFUL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 192 | dev_err(&pdev->dev, |
| 193 | "Could not write PCI config space for Replay Timer\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 194 | return -EIO; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /* l0s and l1 latency timers. We are using default values. |
| 199 | * Representing 001 for L0s and 010 for L1 |
| 200 | */ |
| 201 | result = pci_write_config_byte(pdev, ET1310_PCI_L0L1LATENCY, 0x11); |
| 202 | if (result != PCIBIOS_SUCCESSFUL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 203 | dev_err(&pdev->dev, |
| 204 | "Could not write PCI config space for Latency Timers\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 205 | return -EIO; |
| 206 | } |
| 207 | |
| 208 | /* Change the max read size to 2k */ |
| 209 | result = pci_read_config_byte(pdev, 0x51, &read_size_reg); |
| 210 | if (result != PCIBIOS_SUCCESSFUL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 211 | dev_err(&pdev->dev, |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 212 | "Could not read PCI config space for Max read size\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 213 | return -EIO; |
| 214 | } |
| 215 | |
| 216 | read_size_reg &= 0x8f; |
| 217 | read_size_reg |= 0x40; |
| 218 | |
| 219 | result = pci_write_config_byte(pdev, 0x51, read_size_reg); |
| 220 | if (result != PCIBIOS_SUCCESSFUL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 221 | dev_err(&pdev->dev, |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 222 | "Could not write PCI config space for Max read size\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 223 | return -EIO; |
| 224 | } |
| 225 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 226 | /* Get MAC address from config space if an eeprom exists, otherwise |
| 227 | * the MAC address there will not be valid |
| 228 | */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 229 | if (adapter->has_eeprom) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 230 | int i; |
| 231 | |
| 232 | for (i = 0; i < ETH_ALEN; i++) { |
| 233 | result = pci_read_config_byte( |
| 234 | pdev, ET1310_PCI_MAC_ADDRESS + i, |
| 235 | adapter->PermanentAddress + i); |
| 236 | if (result != PCIBIOS_SUCCESSFUL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 237 | dev_err(&pdev->dev, ";Could not read PCI config space for MAC address\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 238 | return -EIO; |
| 239 | } |
| 240 | } |
| 241 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * et131x_error_timer_handler |
| 247 | * @data: timer-specific variable; here a pointer to our adapter structure |
| 248 | * |
| 249 | * The routine called when the error timer expires, to track the number of |
| 250 | * recurring errors. |
| 251 | */ |
| 252 | void et131x_error_timer_handler(unsigned long data) |
| 253 | { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 254 | struct et131x_adapter *etdev = (struct et131x_adapter *) data; |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame] | 255 | u32 pm_csr; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 256 | |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame] | 257 | pm_csr = readl(&etdev->regs->global.pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 258 | |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame] | 259 | if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) |
Alan Cox | 9483146 | 2009-08-27 11:00:06 +0100 | [diff] [blame] | 260 | UpdateMacStatHostCounters(etdev); |
| 261 | else |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 262 | dev_err(&etdev->pdev->dev, |
| 263 | "No interrupts, in PHY coma, pm_csr = 0x%x\n", pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 264 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 265 | if (!etdev->Bmsr.bits.link_status && |
| 266 | etdev->RegistryPhyComa && |
| 267 | etdev->PoMgmt.TransPhyComaModeOnBoot < 11) { |
| 268 | etdev->PoMgmt.TransPhyComaModeOnBoot++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 271 | if (etdev->PoMgmt.TransPhyComaModeOnBoot == 10) { |
| 272 | if (!etdev->Bmsr.bits.link_status |
| 273 | && etdev->RegistryPhyComa) { |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame] | 274 | if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) { |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 275 | /* NOTE - This was originally a 'sync with |
| 276 | * interrupt'. How to do that under Linux? |
| 277 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 278 | et131x_enable_interrupts(etdev); |
| 279 | EnablePhyComa(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /* This is a periodic timer, so reschedule */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 285 | mod_timer(&etdev->ErrorTimer, jiffies + |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 286 | TX_ERROR_PERIOD * HZ / 1000); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /** |
| 290 | * et131x_link_detection_handler |
| 291 | * |
| 292 | * Timer function for link up at driver load time |
| 293 | */ |
| 294 | void et131x_link_detection_handler(unsigned long data) |
| 295 | { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 296 | struct et131x_adapter *etdev = (struct et131x_adapter *) data; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 297 | unsigned long flags; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 298 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 299 | if (etdev->MediaState == 0) { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 300 | spin_lock_irqsave(&etdev->Lock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 301 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 302 | etdev->MediaState = NETIF_STATUS_MEDIA_DISCONNECT; |
Alan Cox | f6b35d6 | 2009-08-27 11:02:05 +0100 | [diff] [blame] | 303 | etdev->Flags &= ~fMP_ADAPTER_LINK_DETECTION; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 304 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 305 | spin_unlock_irqrestore(&etdev->Lock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 306 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 307 | netif_carrier_off(etdev->netdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
| 311 | /** |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 312 | * et131x_configure_global_regs - configure JAGCore global regs |
| 313 | * @etdev: pointer to our adapter structure |
| 314 | * |
| 315 | * Used to configure the global registers on the JAGCore |
| 316 | */ |
| 317 | void ConfigGlobalRegs(struct et131x_adapter *etdev) |
| 318 | { |
Alan Cox | e266b20 | 2009-08-27 11:02:34 +0100 | [diff] [blame] | 319 | struct _GLOBAL_t __iomem *regs = &etdev->regs->global; |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 320 | |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 321 | if (etdev->RegistryPhyLoopbk == false) { |
| 322 | if (etdev->RegistryJumboPacket < 2048) { |
| 323 | /* Tx / RxDMA and Tx/Rx MAC interfaces have a 1k word |
| 324 | * block of RAM that the driver can split between Tx |
| 325 | * and Rx as it desires. Our default is to split it |
| 326 | * 50/50: |
| 327 | */ |
Alan Cox | e266b20 | 2009-08-27 11:02:34 +0100 | [diff] [blame] | 328 | writel(0, ®s->rxq_start_addr); |
| 329 | writel(PARM_RX_MEM_END_DEF, ®s->rxq_end_addr); |
| 330 | writel(PARM_RX_MEM_END_DEF + 1, ®s->txq_start_addr); |
| 331 | writel(INTERNAL_MEM_SIZE - 1, ®s->txq_end_addr); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 332 | } else if (etdev->RegistryJumboPacket < 8192) { |
| 333 | /* For jumbo packets > 2k but < 8k, split 50-50. */ |
Alan Cox | e266b20 | 2009-08-27 11:02:34 +0100 | [diff] [blame] | 334 | writel(0, ®s->rxq_start_addr); |
| 335 | writel(INTERNAL_MEM_RX_OFFSET, ®s->rxq_end_addr); |
| 336 | writel(INTERNAL_MEM_RX_OFFSET + 1, ®s->txq_start_addr); |
| 337 | writel(INTERNAL_MEM_SIZE - 1, ®s->txq_end_addr); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 338 | } else { |
| 339 | /* 9216 is the only packet size greater than 8k that |
| 340 | * is available. The Tx buffer has to be big enough |
| 341 | * for one whole packet on the Tx side. We'll make |
| 342 | * the Tx 9408, and give the rest to Rx |
| 343 | */ |
Alan Cox | e266b20 | 2009-08-27 11:02:34 +0100 | [diff] [blame] | 344 | writel(0x0000, ®s->rxq_start_addr); |
| 345 | writel(0x01b3, ®s->rxq_end_addr); |
| 346 | writel(0x01b4, ®s->txq_start_addr); |
| 347 | writel(INTERNAL_MEM_SIZE - 1,®s->txq_end_addr); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* Initialize the loopback register. Disable all loopbacks. */ |
Alan Cox | bc7f9c5 | 2009-08-27 11:02:43 +0100 | [diff] [blame] | 351 | writel(0, ®s->loopback); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 352 | } else { |
| 353 | /* For PHY Line loopback, the memory is configured as if Tx |
| 354 | * and Rx both have all the memory. This is because the |
| 355 | * RxMAC will write data into the space, and the TxMAC will |
| 356 | * read it out. |
| 357 | */ |
Alan Cox | e266b20 | 2009-08-27 11:02:34 +0100 | [diff] [blame] | 358 | writel(0, ®s->rxq_start_addr); |
| 359 | writel(INTERNAL_MEM_SIZE - 1, ®s->rxq_end_addr); |
| 360 | writel(0, ®s->txq_start_addr); |
| 361 | writel(INTERNAL_MEM_SIZE - 1, ®s->txq_end_addr); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 362 | |
| 363 | /* Initialize the loopback register (MAC loopback). */ |
Alan Cox | bc7f9c5 | 2009-08-27 11:02:43 +0100 | [diff] [blame] | 364 | writel(ET_LOOP_MAC, ®s->loopback); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* MSI Register */ |
Alan Cox | e266b20 | 2009-08-27 11:02:34 +0100 | [diff] [blame] | 368 | writel(0, ®s->msi_config); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 369 | |
| 370 | /* By default, disable the watchdog timer. It will be enabled when |
| 371 | * a packet is queued. |
| 372 | */ |
Alan Cox | e266b20 | 2009-08-27 11:02:34 +0100 | [diff] [blame] | 373 | writel(0, ®s->watchdog_timer); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
| 377 | /** |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 378 | * et131x_adapter_setup - Set the adapter up as per cassini+ documentation |
| 379 | * @adapter: pointer to our private adapter structure |
| 380 | * |
| 381 | * Returns 0 on success, errno on failure (as defined in errno.h) |
| 382 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 383 | int et131x_adapter_setup(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 384 | { |
| 385 | int status = 0; |
| 386 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 387 | /* Configure the JAGCore */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 388 | ConfigGlobalRegs(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 389 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 390 | ConfigMACRegs1(etdev); |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 391 | |
| 392 | /* Configure the MMC registers */ |
| 393 | /* All we need to do is initialize the Memory Control Register */ |
| 394 | writel(ET_MMC_ENABLE, &etdev->regs->mmc.mmc_ctrl); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 395 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 396 | ConfigRxMacRegs(etdev); |
| 397 | ConfigTxMacRegs(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 398 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 399 | ConfigRxDmaRegs(etdev); |
| 400 | ConfigTxDmaRegs(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 401 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 402 | ConfigMacStatRegs(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 403 | |
| 404 | /* Move the following code to Timer function?? */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 405 | status = et131x_xcvr_find(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 406 | |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 407 | if (status != 0) |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 408 | dev_warn(&etdev->pdev->dev, "Could not find the xcvr\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 409 | |
| 410 | /* Prepare the TRUEPHY library. */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 411 | ET1310_PhyInit(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 412 | |
| 413 | /* Reset the phy now so changes take place */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 414 | ET1310_PhyReset(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 415 | |
| 416 | /* Power down PHY */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 417 | ET1310_PhyPowerDown(etdev, 1); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | * We need to turn off 1000 base half dulplex, the mac does not |
| 421 | * support it. For the 10/100 part, turn off all gig advertisement |
| 422 | */ |
Alan Cox | 5ec3487 | 2009-08-27 10:59:13 +0100 | [diff] [blame] | 423 | if (etdev->pdev->device != ET131X_PCI_DEVICE_ID_FAST) |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 424 | ET1310_PhyAdvertise1000BaseT(etdev, TRUEPHY_ADV_DUPLEX_FULL); |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 425 | else |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 426 | ET1310_PhyAdvertise1000BaseT(etdev, TRUEPHY_ADV_DUPLEX_NONE); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 427 | |
| 428 | /* Power up PHY */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 429 | ET1310_PhyPowerDown(etdev, 0); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 430 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 431 | et131x_setphy_normal(etdev); |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 432 | ; return status; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /** |
| 436 | * et131x_setup_hardware_properties - set up the MAC Address on the ET1310 |
| 437 | * @adapter: pointer to our private adapter structure |
| 438 | */ |
| 439 | void et131x_setup_hardware_properties(struct et131x_adapter *adapter) |
| 440 | { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 441 | /* If have our default mac from registry and no mac address from |
| 442 | * EEPROM then we need to generate the last octet and set it on the |
| 443 | * device |
| 444 | */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 445 | if (adapter->PermanentAddress[0] == 0x00 && |
| 446 | adapter->PermanentAddress[1] == 0x00 && |
| 447 | adapter->PermanentAddress[2] == 0x00 && |
| 448 | adapter->PermanentAddress[3] == 0x00 && |
| 449 | adapter->PermanentAddress[4] == 0x00 && |
| 450 | adapter->PermanentAddress[5] == 0x00) { |
| 451 | /* |
| 452 | * We need to randomly generate the last octet so we |
| 453 | * decrease our chances of setting the mac address to |
| 454 | * same as another one of our cards in the system |
| 455 | */ |
| 456 | get_random_bytes(&adapter->CurrentAddress[5], 1); |
| 457 | /* |
| 458 | * We have the default value in the register we are |
| 459 | * working with so we need to copy the current |
| 460 | * address into the permanent address |
| 461 | */ |
| 462 | memcpy(adapter->PermanentAddress, |
| 463 | adapter->CurrentAddress, ETH_ALEN); |
| 464 | } else { |
| 465 | /* We do not have an override address, so set the |
| 466 | * current address to the permanent address and add |
| 467 | * it to the device |
| 468 | */ |
| 469 | memcpy(adapter->CurrentAddress, |
| 470 | adapter->PermanentAddress, ETH_ALEN); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 471 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
| 475 | * et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310 |
| 476 | * @adapter: pointer to our private adapter structure |
| 477 | */ |
| 478 | void et131x_soft_reset(struct et131x_adapter *adapter) |
| 479 | { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 480 | /* Disable MAC Core */ |
Alan Cox | f3f415a | 2009-08-27 10:59:30 +0100 | [diff] [blame] | 481 | writel(0xc00f0000, &adapter->regs->mac.cfg1.value); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 482 | |
| 483 | /* Set everything to a reset value */ |
Alan Cox | b8c4cc4 | 2009-08-27 11:02:25 +0100 | [diff] [blame] | 484 | writel(0x7F, &adapter->regs->global.sw_reset); |
Alan Cox | f3f415a | 2009-08-27 10:59:30 +0100 | [diff] [blame] | 485 | writel(0x000f0000, &adapter->regs->mac.cfg1.value); |
| 486 | writel(0x00000000, &adapter->regs->mac.cfg1.value); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /** |
| 490 | * et131x_align_allocated_memory - Align allocated memory on a given boundary |
| 491 | * @adapter: pointer to our adapter structure |
| 492 | * @phys_addr: pointer to Physical address |
| 493 | * @offset: pointer to the offset variable |
| 494 | * @mask: correct mask |
| 495 | */ |
| 496 | void et131x_align_allocated_memory(struct et131x_adapter *adapter, |
| 497 | uint64_t *phys_addr, |
| 498 | uint64_t *offset, uint64_t mask) |
| 499 | { |
| 500 | uint64_t new_addr; |
| 501 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 502 | *offset = 0; |
| 503 | |
| 504 | new_addr = *phys_addr & ~mask; |
| 505 | |
| 506 | if (new_addr != *phys_addr) { |
| 507 | /* Move to next aligned block */ |
| 508 | new_addr += mask + 1; |
| 509 | /* Return offset for adjusting virt addr */ |
| 510 | *offset = new_addr - *phys_addr; |
| 511 | /* Return new physical address */ |
| 512 | *phys_addr = new_addr; |
| 513 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /** |
| 517 | * et131x_adapter_memory_alloc |
| 518 | * @adapter: pointer to our private adapter structure |
| 519 | * |
| 520 | * Returns 0 on success, errno on failure (as defined in errno.h). |
| 521 | * |
| 522 | * Allocate all the memory blocks for send, receive and others. |
| 523 | */ |
| 524 | int et131x_adapter_memory_alloc(struct et131x_adapter *adapter) |
| 525 | { |
| 526 | int status = 0; |
| 527 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 528 | do { |
| 529 | /* Allocate memory for the Tx Ring */ |
| 530 | status = et131x_tx_dma_memory_alloc(adapter); |
| 531 | if (status != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 532 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 533 | "et131x_tx_dma_memory_alloc FAILED\n"); |
| 534 | break; |
| 535 | } |
| 536 | |
| 537 | /* Receive buffer memory allocation */ |
| 538 | status = et131x_rx_dma_memory_alloc(adapter); |
| 539 | if (status != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 540 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 541 | "et131x_rx_dma_memory_alloc FAILED\n"); |
| 542 | et131x_tx_dma_memory_free(adapter); |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | /* Init receive data structures */ |
| 547 | status = et131x_init_recv(adapter); |
| 548 | if (status != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 549 | dev_err(&adapter->pdev->dev, |
| 550 | "et131x_init_recv FAILED\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 551 | et131x_tx_dma_memory_free(adapter); |
| 552 | et131x_rx_dma_memory_free(adapter); |
| 553 | break; |
| 554 | } |
| 555 | } while (0); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 556 | return status; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx |
| 561 | * @adapter: pointer to our private adapter structure |
| 562 | */ |
| 563 | void et131x_adapter_memory_free(struct et131x_adapter *adapter) |
| 564 | { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 565 | /* Free DMA memory */ |
| 566 | et131x_tx_dma_memory_free(adapter); |
| 567 | et131x_rx_dma_memory_free(adapter); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /** |
Alan Cox | 8c5f20f | 2009-08-27 11:00:24 +0100 | [diff] [blame] | 571 | * et131x_config_parse |
| 572 | * @etdev: pointer to the private adapter struct |
| 573 | * |
| 574 | * Parses a configuration from some location (module parameters, for example) |
| 575 | * into the private adapter struct. This really has no sensible analogy in |
| 576 | * Linux as sysfs parameters are dynamic. Several things that were hee could |
| 577 | * go into sysfs, but other stuff like speed handling is part of the mii |
| 578 | * interfaces/ethtool. |
| 579 | */ |
| 580 | void et131x_config_parse(struct et131x_adapter *etdev) |
| 581 | { |
| 582 | static const u8 default_mac[] = { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 }; |
| 583 | static const u8 duplex[] = { 0, 1, 2, 1, 2, 2 }; |
| 584 | static const u16 speed[] = { 0, 10, 10, 100, 100, 1000 }; |
| 585 | |
Alan Cox | 8c5f20f | 2009-08-27 11:00:24 +0100 | [diff] [blame] | 586 | if (et131x_speed_set) |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 587 | dev_info(&etdev->pdev->dev, |
| 588 | "Speed set manually to : %d \n", et131x_speed_set); |
Alan Cox | 8c5f20f | 2009-08-27 11:00:24 +0100 | [diff] [blame] | 589 | |
| 590 | etdev->SpeedDuplex = et131x_speed_set; |
| 591 | etdev->RegistryJumboPacket = 1514; /* 1514-9216 */ |
| 592 | |
| 593 | etdev->RegistryNMIDisable = et131x_nmi_disable; |
| 594 | |
| 595 | /* Set the MAC address to a default */ |
| 596 | memcpy(etdev->CurrentAddress, default_mac, ETH_ALEN); |
| 597 | |
| 598 | /* Decode SpeedDuplex |
| 599 | * |
| 600 | * Set up as if we are auto negotiating always and then change if we |
| 601 | * go into force mode |
| 602 | * |
| 603 | * If we are the 10/100 device, and gigabit is somehow requested then |
| 604 | * knock it down to 100 full. |
| 605 | */ |
| 606 | if (etdev->pdev->device == ET131X_PCI_DEVICE_ID_FAST && |
| 607 | etdev->SpeedDuplex == 5) |
| 608 | etdev->SpeedDuplex = 4; |
| 609 | |
| 610 | etdev->AiForceSpeed = speed[etdev->SpeedDuplex]; |
| 611 | etdev->AiForceDpx = duplex[etdev->SpeedDuplex]; /* Auto FDX */ |
Alan Cox | 8c5f20f | 2009-08-27 11:00:24 +0100 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | |
| 615 | /** |
Alan Cox | 7ca5d42 | 2009-08-27 11:03:21 +0100 | [diff] [blame] | 616 | * et131x_pci_remove |
| 617 | * @pdev: a pointer to the device's pci_dev structure |
| 618 | * |
| 619 | * Registered in the pci_driver structure, this function is called when the |
| 620 | * PCI subsystem detects that a PCI device which matches the information |
| 621 | * contained in the pci_device_id table has been removed. |
| 622 | */ |
| 623 | |
| 624 | void __devexit et131x_pci_remove(struct pci_dev *pdev) |
| 625 | { |
| 626 | struct net_device *netdev; |
| 627 | struct et131x_adapter *adapter; |
| 628 | |
| 629 | /* Retrieve the net_device pointer from the pci_dev struct, as well |
| 630 | * as the private adapter struct |
| 631 | */ |
| 632 | netdev = (struct net_device *) pci_get_drvdata(pdev); |
| 633 | adapter = netdev_priv(netdev); |
| 634 | |
| 635 | /* Perform device cleanup */ |
| 636 | unregister_netdev(netdev); |
| 637 | et131x_adapter_memory_free(adapter); |
| 638 | iounmap(adapter->regs); |
| 639 | pci_dev_put(adapter->pdev); |
| 640 | free_netdev(netdev); |
| 641 | pci_release_regions(pdev); |
| 642 | pci_disable_device(pdev); |
| 643 | } |
| 644 | |
| 645 | |
| 646 | /** |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 647 | * et131x_pci_setup - Perform device initialization |
| 648 | * @pdev: a pointer to the device's pci_dev structure |
| 649 | * @ent: this device's entry in the pci_device_id table |
| 650 | * |
| 651 | * Returns 0 on success, errno on failure (as defined in errno.h) |
| 652 | * |
| 653 | * Registered in the pci_driver structure, this function is called when the |
| 654 | * PCI subsystem finds a new PCI device which matches the information |
| 655 | * contained in the pci_device_id table. This routine is the equivalent to |
| 656 | * a device insertion routine. |
| 657 | */ |
Alan Cox | 7ca5d42 | 2009-08-27 11:03:21 +0100 | [diff] [blame] | 658 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 659 | int __devinit et131x_pci_setup(struct pci_dev *pdev, |
| 660 | const struct pci_device_id *ent) |
| 661 | { |
| 662 | int result = 0; |
| 663 | int pm_cap; |
| 664 | bool pci_using_dac; |
| 665 | struct net_device *netdev = NULL; |
| 666 | struct et131x_adapter *adapter = NULL; |
| 667 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 668 | /* Enable the device via the PCI subsystem */ |
| 669 | result = pci_enable_device(pdev); |
| 670 | if (result != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 671 | dev_err(&adapter->pdev->dev, |
| 672 | "pci_enable_device() failed\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 673 | goto out; |
| 674 | } |
| 675 | |
| 676 | /* Perform some basic PCI checks */ |
| 677 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 678 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 679 | "Can't find PCI device's base address\n"); |
| 680 | result = -ENODEV; |
| 681 | goto out; |
| 682 | } |
| 683 | |
| 684 | result = pci_request_regions(pdev, DRIVER_NAME); |
| 685 | if (result != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 686 | dev_err(&adapter->pdev->dev, |
| 687 | "Can't get PCI resources\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 688 | goto err_disable; |
| 689 | } |
| 690 | |
| 691 | /* Enable PCI bus mastering */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 692 | pci_set_master(pdev); |
| 693 | |
| 694 | /* Query PCI for Power Mgmt Capabilities |
| 695 | * |
| 696 | * NOTE: Now reading PowerMgmt in another location; is this still |
| 697 | * needed? |
| 698 | */ |
| 699 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 700 | if (pm_cap == 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 701 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 702 | "Cannot find Power Management capabilities\n"); |
| 703 | result = -EIO; |
| 704 | goto err_release_res; |
| 705 | } |
| 706 | |
| 707 | /* Check the DMA addressing support of this device */ |
| 708 | if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 709 | pci_using_dac = true; |
| 710 | |
| 711 | result = |
| 712 | pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL); |
| 713 | if (result != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 714 | dev_err(&pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 715 | "Unable to obtain 64 bit DMA for consistent allocations\n"); |
| 716 | goto err_release_res; |
| 717 | } |
| 718 | } else if (!pci_set_dma_mask(pdev, 0xffffffffULL)) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 719 | pci_using_dac = false; |
| 720 | } else { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 721 | dev_err(&adapter->pdev->dev, |
| 722 | "No usable DMA addressing method\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 723 | result = -EIO; |
| 724 | goto err_release_res; |
| 725 | } |
| 726 | |
| 727 | /* Allocate netdev and private adapter structs */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 728 | netdev = et131x_device_alloc(); |
| 729 | if (netdev == NULL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 730 | dev_err(&adapter->pdev->dev, |
| 731 | "Couldn't alloc netdev struct\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 732 | result = -ENOMEM; |
| 733 | goto err_release_res; |
| 734 | } |
| 735 | |
| 736 | /* Setup the fundamental net_device and private adapter structure elements */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 737 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 738 | /* |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 739 | if (pci_using_dac) { |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 740 | netdev->features |= NETIF_F_HIGHDMA; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 741 | } |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 742 | */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 743 | |
| 744 | /* |
| 745 | * NOTE - Turn this on when we're ready to deal with SG-DMA |
| 746 | * |
| 747 | * NOTE: According to "Linux Device Drivers", 3rd ed, Rubini et al, |
| 748 | * if checksumming is not performed in HW, then the kernel will not |
| 749 | * use SG. |
| 750 | * From pp 510-511: |
| 751 | * |
| 752 | * "Note that the kernel does not perform scatter/gather I/O to your |
| 753 | * device if it does not also provide some form of checksumming as |
| 754 | * well. The reason is that, if the kernel has to make a pass over a |
| 755 | * fragmented ("nonlinear") packet to calculate the checksum, it |
| 756 | * might as well copy the data and coalesce the packet at the same |
| 757 | * time." |
| 758 | * |
| 759 | * This has been verified by setting the flags below and still not |
| 760 | * receiving a scattered buffer from the network stack, so leave it |
| 761 | * off until checksums are calculated in HW. |
| 762 | */ |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 763 | /* netdev->features |= NETIF_F_SG; */ |
| 764 | /* netdev->features |= NETIF_F_NO_CSUM; */ |
| 765 | /* netdev->features |= NETIF_F_LLTX; */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 766 | |
| 767 | /* Allocate private adapter struct and copy in relevant information */ |
| 768 | adapter = netdev_priv(netdev); |
Alan Cox | 6ae5604 | 2009-08-27 10:59:21 +0100 | [diff] [blame] | 769 | adapter->pdev = pci_dev_get(pdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 770 | adapter->netdev = netdev; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 771 | |
| 772 | /* Do the same for the netdev struct */ |
| 773 | netdev->irq = pdev->irq; |
| 774 | netdev->base_addr = pdev->resource[0].start; |
| 775 | |
| 776 | /* Initialize spinlocks here */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 777 | spin_lock_init(&adapter->Lock); |
| 778 | spin_lock_init(&adapter->TCBSendQLock); |
| 779 | spin_lock_init(&adapter->TCBReadyQLock); |
| 780 | spin_lock_init(&adapter->SendHWLock); |
| 781 | spin_lock_init(&adapter->SendWaitLock); |
| 782 | spin_lock_init(&adapter->RcvLock); |
| 783 | spin_lock_init(&adapter->RcvPendLock); |
| 784 | spin_lock_init(&adapter->FbrLock); |
| 785 | spin_lock_init(&adapter->PHYLock); |
| 786 | |
| 787 | /* Parse configuration parameters into the private adapter struct */ |
| 788 | et131x_config_parse(adapter); |
| 789 | |
| 790 | /* Find the physical adapter |
| 791 | * |
| 792 | * NOTE: This is the equivalent of the MpFindAdapter() routine; can we |
| 793 | * lump it's init with the device specific init below into a |
| 794 | * single init function? |
| 795 | */ |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 796 | /* while (et131x_find_adapter(adapter, pdev) != 0); */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 797 | et131x_find_adapter(adapter, pdev); |
| 798 | |
| 799 | /* Map the bus-relative registers to system virtual memory */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 800 | |
Alan Cox | f3f415a | 2009-08-27 10:59:30 +0100 | [diff] [blame] | 801 | adapter->regs = ioremap_nocache(pci_resource_start(pdev, 0), |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 802 | pci_resource_len(pdev, 0)); |
Alan Cox | f3f415a | 2009-08-27 10:59:30 +0100 | [diff] [blame] | 803 | if (adapter->regs == NULL) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 804 | dev_err(&pdev->dev, "Cannot map device registers\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 805 | result = -ENOMEM; |
| 806 | goto err_free_dev; |
| 807 | } |
| 808 | |
| 809 | /* Perform device-specific initialization here (See code below) */ |
| 810 | |
| 811 | /* If Phy COMA mode was enabled when we went down, disable it here. */ |
Alan Cox | f2c98d2 | 2009-08-27 11:01:49 +0100 | [diff] [blame] | 812 | writel(ET_PMCSR_INIT, &adapter->regs->global.pm_csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 813 | |
| 814 | /* Issue a global reset to the et1310 */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 815 | et131x_soft_reset(adapter); |
| 816 | |
| 817 | /* Disable all interrupts (paranoid) */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 818 | et131x_disable_interrupts(adapter); |
| 819 | |
| 820 | /* Allocate DMA memory */ |
| 821 | result = et131x_adapter_memory_alloc(adapter); |
| 822 | if (result != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 823 | dev_err(&pdev->dev, "Could not alloc adapater memory (DMA)\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 824 | goto err_iounmap; |
| 825 | } |
| 826 | |
| 827 | /* Init send data structures */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 828 | et131x_init_send(adapter); |
| 829 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 830 | /* Register the interrupt |
| 831 | * |
| 832 | * NOTE - This is being done in the open routine, where most other |
| 833 | * Linux drivers setup IRQ handlers. Make sure device |
| 834 | * interrupts are not turned on before the IRQ is registered!! |
| 835 | * |
| 836 | * What we will do here is setup the task structure for the |
| 837 | * ISR's deferred handler |
| 838 | */ |
| 839 | INIT_WORK(&adapter->task, et131x_isr_handler); |
| 840 | |
| 841 | /* Determine MAC Address, and copy into the net_device struct */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 842 | et131x_setup_hardware_properties(adapter); |
| 843 | |
| 844 | memcpy(netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN); |
| 845 | |
| 846 | /* Setup et1310 as per the documentation */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 847 | et131x_adapter_setup(adapter); |
| 848 | |
| 849 | /* Create a timer to count errors received by the NIC */ |
| 850 | init_timer(&adapter->ErrorTimer); |
| 851 | |
| 852 | adapter->ErrorTimer.expires = jiffies + TX_ERROR_PERIOD * HZ / 1000; |
| 853 | adapter->ErrorTimer.function = et131x_error_timer_handler; |
| 854 | adapter->ErrorTimer.data = (unsigned long)adapter; |
| 855 | |
| 856 | /* Initialize link state */ |
| 857 | et131x_link_detection_handler((unsigned long)adapter); |
| 858 | |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 859 | /* Intialize variable for counting how long we do not have |
| 860 | link status */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 861 | adapter->PoMgmt.TransPhyComaModeOnBoot = 0; |
| 862 | |
| 863 | /* We can enable interrupts now |
| 864 | * |
| 865 | * NOTE - Because registration of interrupt handler is done in the |
| 866 | * device's open(), defer enabling device interrupts to that |
| 867 | * point |
| 868 | */ |
| 869 | |
| 870 | /* Register the net_device struct with the Linux network layer */ |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 871 | result = register_netdev(netdev); |
| 872 | if (result != 0) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 873 | dev_err(&pdev->dev, "register_netdev() failed\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 874 | goto err_mem_free; |
| 875 | } |
| 876 | |
| 877 | /* Register the net_device struct with the PCI subsystem. Save a copy |
| 878 | * of the PCI config space for this device now that the device has |
| 879 | * been initialized, just in case it needs to be quickly restored. |
| 880 | */ |
| 881 | pci_set_drvdata(pdev, netdev); |
| 882 | |
| 883 | pci_save_state(adapter->pdev); |
| 884 | |
| 885 | out: |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 886 | return result; |
| 887 | |
| 888 | err_mem_free: |
| 889 | et131x_adapter_memory_free(adapter); |
| 890 | err_iounmap: |
Alan Cox | f3f415a | 2009-08-27 10:59:30 +0100 | [diff] [blame] | 891 | iounmap(adapter->regs); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 892 | err_free_dev: |
Alan Cox | 6ae5604 | 2009-08-27 10:59:21 +0100 | [diff] [blame] | 893 | pci_dev_put(pdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 894 | free_netdev(netdev); |
| 895 | err_release_res: |
| 896 | pci_release_regions(pdev); |
| 897 | err_disable: |
| 898 | pci_disable_device(pdev); |
| 899 | goto out; |
| 900 | } |
Alan Cox | 7ca5d42 | 2009-08-27 11:03:21 +0100 | [diff] [blame] | 901 | |
| 902 | static struct pci_device_id et131x_pci_table[] __devinitdata = { |
| 903 | {ET131X_PCI_VENDOR_ID, ET131X_PCI_DEVICE_ID_GIG, PCI_ANY_ID, |
| 904 | PCI_ANY_ID, 0, 0, 0UL}, |
| 905 | {ET131X_PCI_VENDOR_ID, ET131X_PCI_DEVICE_ID_FAST, PCI_ANY_ID, |
| 906 | PCI_ANY_ID, 0, 0, 0UL}, |
| 907 | {0,} |
| 908 | }; |
| 909 | |
| 910 | MODULE_DEVICE_TABLE(pci, et131x_pci_table); |
| 911 | |
| 912 | static struct pci_driver et131x_driver = { |
| 913 | .name = DRIVER_NAME, |
| 914 | .id_table = et131x_pci_table, |
| 915 | .probe = et131x_pci_setup, |
| 916 | .remove = __devexit_p(et131x_pci_remove), |
| 917 | .suspend = NULL, /* et131x_pci_suspend */ |
| 918 | .resume = NULL, /* et131x_pci_resume */ |
| 919 | }; |
| 920 | |
| 921 | |
| 922 | /** |
| 923 | * et131x_init_module - The "main" entry point called on driver initialization |
| 924 | * |
| 925 | * Returns 0 on success, errno on failure (as defined in errno.h) |
| 926 | */ |
Peter Huewe | 3c0d446 | 2009-09-29 01:34:14 +0200 | [diff] [blame] | 927 | static int __init et131x_init_module(void) |
Alan Cox | 7ca5d42 | 2009-08-27 11:03:21 +0100 | [diff] [blame] | 928 | { |
| 929 | if (et131x_speed_set < PARM_SPEED_DUPLEX_MIN || |
| 930 | et131x_speed_set > PARM_SPEED_DUPLEX_MAX) { |
| 931 | printk(KERN_WARNING "et131x: invalid speed setting ignored.\n"); |
| 932 | et131x_speed_set = 0; |
| 933 | } |
| 934 | return pci_register_driver(&et131x_driver); |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * et131x_cleanup_module - The entry point called on driver cleanup |
| 939 | */ |
Peter Huewe | 3c0d446 | 2009-09-29 01:34:14 +0200 | [diff] [blame] | 940 | static void __exit et131x_cleanup_module(void) |
Alan Cox | 7ca5d42 | 2009-08-27 11:03:21 +0100 | [diff] [blame] | 941 | { |
| 942 | pci_unregister_driver(&et131x_driver); |
| 943 | } |
| 944 | |
| 945 | module_init(et131x_init_module); |
| 946 | module_exit(et131x_cleanup_module); |
| 947 | |
| 948 | |
| 949 | /* Modinfo parameters (filled out using defines from et131x_version.h) */ |
| 950 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 951 | MODULE_DESCRIPTION(DRIVER_INFO); |
| 952 | MODULE_LICENSE(DRIVER_LICENSE); |