blob: 2d8b62f066a8c36a8692901ed67f5ce33c23ad8d [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 * 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 Cox64f93032009-06-10 17:30:41 +010024 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070025 * 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 Cox64f93032009-06-10 17:30:41 +010045 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070046 * 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-Hartmancfb739b2008-04-03 17:30:53 -070061#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 Cox64f93032009-06-10 17:30:41 +010078#include <linux/io.h>
79#include <linux/bitops.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070080#include <asm/system.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070081
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-Hartmancfb739b2008-04-03 17:30:53 -070099#include "et1310_tx.h"
100#include "et1310_rx.h"
101#include "et1310_mac.h"
102#include "et1310_eeprom.h"
103
104
105int __devinit et131x_pci_setup(struct pci_dev *pdev,
106 const struct pci_device_id *ent);
107void __devexit et131x_pci_remove(struct pci_dev *pdev);
108
109
110/* Modinfo parameters (filled out using defines from et131x_version.h) */
111MODULE_AUTHOR(DRIVER_AUTHOR);
112MODULE_DESCRIPTION(DRIVER_INFO);
113MODULE_LICENSE(DRIVER_LICENSE);
114
Alan Cox8c5f20f2009-08-27 11:00:24 +0100115/* Defines for Parameter Default/Min/Max vaules */
116#define PARM_SPEED_DUPLEX_MIN 0
117#define PARM_SPEED_DUPLEX_MAX 5
118
119/* Module parameter for disabling NMI
120 * et131x_nmi_disable :
121 * Disable NMI (0-2) [0]
122 * 0 :
123 * 1 :
124 * 2 :
125 */
126static u32 et131x_nmi_disable; /* 0-2 */
127module_param(et131x_nmi_disable, uint, 0);
128MODULE_PARM_DESC(et131x_nmi_disable, "Disable NMI (0-2) [0]");
129
130/* Module parameter for manual speed setting
131 * Set Link speed and dublex manually (0-5) [0]
132 * 1 : 10Mb Half-Duplex
133 * 2 : 10Mb Full-Duplex
134 * 3 : 100Mb Half-Duplex
135 * 4 : 100Mb Full-Duplex
136 * 5 : 1000Mb Full-Duplex
137 * 0 : Auto Speed Auto Duplex // default
138 */
139static u32 et131x_speed_set;
140module_param(et131x_speed_set, uint, 0);
141MODULE_PARM_DESC(et131x_speed_set,
142 "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");
143
144
145
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700146static struct pci_device_id et131x_pci_table[] __devinitdata = {
147 {ET131X_PCI_VENDOR_ID, ET131X_PCI_DEVICE_ID_GIG, PCI_ANY_ID,
148 PCI_ANY_ID, 0, 0, 0UL},
149 {ET131X_PCI_VENDOR_ID, ET131X_PCI_DEVICE_ID_FAST, PCI_ANY_ID,
150 PCI_ANY_ID, 0, 0, 0UL},
151 {0,}
152};
153
154MODULE_DEVICE_TABLE(pci, et131x_pci_table);
155
156static struct pci_driver et131x_driver = {
157 .name = DRIVER_NAME,
158 .id_table = et131x_pci_table,
159 .probe = et131x_pci_setup,
160 .remove = __devexit_p(et131x_pci_remove),
Alan Cox64f93032009-06-10 17:30:41 +0100161 .suspend = NULL, /* et131x_pci_suspend */
162 .resume = NULL, /* et131x_pci_resume */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700163};
164
165
166/**
167 * et131x_init_module - The "main" entry point called on driver initialization
168 *
169 * Returns 0 on success, errno on failure (as defined in errno.h)
170 */
Alan Cox15700032009-08-27 11:03:09 +0100171static int et131x_init_module(void)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700172{
Alan Cox8c5f20f2009-08-27 11:00:24 +0100173 if (et131x_speed_set < PARM_SPEED_DUPLEX_MIN ||
174 et131x_speed_set > PARM_SPEED_DUPLEX_MAX) {
Alan Cox15700032009-08-27 11:03:09 +0100175 printk(KERN_WARNING "et131x: invalid speed setting ignored.\n");
Alan Cox8c5f20f2009-08-27 11:00:24 +0100176 et131x_speed_set = 0;
177 }
Alan Cox15700032009-08-27 11:03:09 +0100178 return pci_register_driver(&et131x_driver);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700179}
180
181/**
182 * et131x_cleanup_module - The entry point called on driver cleanup
183 */
Alan Cox15700032009-08-27 11:03:09 +0100184static void et131x_cleanup_module(void)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700185{
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700186 pci_unregister_driver(&et131x_driver);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700187}
188
189/*
190 * These macros map the driver-specific init_module() and cleanup_module()
191 * routines so they can be called by the kernel.
192 */
Alan Cox15700032009-08-27 11:03:09 +0100193
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700194module_init(et131x_init_module);
195module_exit(et131x_cleanup_module);
196
197
198/**
199 * et131x_find_adapter - Find the adapter and get all the assigned resources
200 * @adapter: pointer to our private adapter structure
201 *
202 * Returns 0 on success, errno on failure (as defined in errno.h)
203 */
204int et131x_find_adapter(struct et131x_adapter *adapter, struct pci_dev *pdev)
205{
206 int result;
207 uint8_t eepromStat;
208 uint8_t maxPayload = 0;
209 uint8_t read_size_reg;
Alan Cox5ec34872009-08-27 10:59:13 +0100210 u8 rev;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700211
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700212 /* Allow disabling of Non-Maskable Interrupts in I/O space, to
213 * support validation.
214 */
215 if (adapter->RegistryNMIDisable) {
216 uint8_t RegisterVal;
217
218 RegisterVal = inb(ET1310_NMI_DISABLE);
219 RegisterVal &= 0xf3;
220
Alan Cox64f93032009-06-10 17:30:41 +0100221 if (adapter->RegistryNMIDisable == 2)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700222 RegisterVal |= 0xc;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700223
224 outb(ET1310_NMI_DISABLE, RegisterVal);
225 }
226
227 /* We first need to check the EEPROM Status code located at offset
228 * 0xB2 of config space
229 */
230 result = pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS,
231 &eepromStat);
232
233 /* THIS IS A WORKAROUND:
Alan Cox64f93032009-06-10 17:30:41 +0100234 * I need to call this function twice to get my card in a
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700235 * LG M1 Express Dual running. I tried also a msleep before this
236 * function, because I thougth there could be some time condidions
237 * but it didn't work. Call the whole function twice also work.
238 */
239 result = pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS,
240 &eepromStat);
241 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100242 dev_err(&pdev->dev, "Could not read PCI config space for "
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700243 "EEPROM Status\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700244 return -EIO;
245 }
246
247 /* Determine if the error(s) we care about are present. If they are
248 * present, we need to fail.
249 */
250 if (eepromStat & 0x4C) {
Alan Cox5ec34872009-08-27 10:59:13 +0100251 result = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700252 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100253 dev_err(&pdev->dev,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700254 "Could not read PCI config space for "
255 "Revision ID\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700256 return -EIO;
Alan Cox5ec34872009-08-27 10:59:13 +0100257 } else if (rev == 0x01) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700258 int32_t nLoop;
Alan Cox9fa81092009-08-27 11:00:36 +0100259 uint8_t temp[4] = { 0xFE, 0x13, 0x10, 0xFF };
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700260
261 /* Re-write the first 4 bytes if we have an eeprom
262 * present and the revision id is 1, this fixes the
263 * corruption seen with 1310 B Silicon
264 */
265 for (nLoop = 0; nLoop < 3; nLoop++) {
Alan Cox13071fd2009-08-27 11:01:04 +0100266 EepromWriteByte(adapter, nLoop, temp[nLoop]);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700267 }
268 }
269
Alan Cox15700032009-08-27 11:03:09 +0100270 dev_err(&pdev->dev, "Fatal EEPROM Status Error - 0x%04x\n", eepromStat);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700271
272 /* This error could mean that there was an error reading the
273 * eeprom or that the eeprom doesn't exist. We will treat
274 * each case the same and not try to gather additional
275 * information that normally would come from the eeprom, like
276 * MAC Address
277 */
Alan Cox9fa81092009-08-27 11:00:36 +0100278 adapter->has_eeprom = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700279 return -EIO;
Alan Cox15700032009-08-27 11:03:09 +0100280 } else
Alan Cox9fa81092009-08-27 11:00:36 +0100281 adapter->has_eeprom = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700282
283 /* Read the EEPROM for information regarding LED behavior. Refer to
284 * ET1310_phy.c, et131x_xcvr_init(), for its use.
285 */
Alan Cox13071fd2009-08-27 11:01:04 +0100286 EepromReadByte(adapter, 0x70, &adapter->eepromData[0]);
287 EepromReadByte(adapter, 0x71, &adapter->eepromData[1]);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700288
Alan Cox64f93032009-06-10 17:30:41 +0100289 if (adapter->eepromData[0] != 0xcd)
290 /* Disable all optional features */
291 adapter->eepromData[1] = 0x00;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700292
293 /* Let's set up the PORT LOGIC Register. First we need to know what
294 * the max_payload_size is
295 */
296 result = pci_read_config_byte(pdev, ET1310_PCI_MAX_PYLD, &maxPayload);
297 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100298 dev_err(&pdev->dev,
299 "Could not read PCI config space for Max Payload Size\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700300 return -EIO;
301 }
302
303 /* Program the Ack/Nak latency and replay timers */
Alan Cox64f93032009-06-10 17:30:41 +0100304 maxPayload &= 0x07; /* Only the lower 3 bits are valid */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700305
306 if (maxPayload < 2) {
307 const uint16_t AckNak[2] = { 0x76, 0xD0 };
308 const uint16_t Replay[2] = { 0x1E0, 0x2ED };
309
310 result = pci_write_config_word(pdev, ET1310_PCI_ACK_NACK,
311 AckNak[maxPayload]);
312 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100313 dev_err(&pdev->dev,
314 "Could not write PCI config space for ACK/NAK\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700315 return -EIO;
316 }
317
318 result = pci_write_config_word(pdev, ET1310_PCI_REPLAY,
319 Replay[maxPayload]);
320 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100321 dev_err(&pdev->dev,
322 "Could not write PCI config space for Replay Timer\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700323 return -EIO;
324 }
325 }
326
327 /* l0s and l1 latency timers. We are using default values.
328 * Representing 001 for L0s and 010 for L1
329 */
330 result = pci_write_config_byte(pdev, ET1310_PCI_L0L1LATENCY, 0x11);
331 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100332 dev_err(&pdev->dev,
333 "Could not write PCI config space for Latency Timers\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700334 return -EIO;
335 }
336
337 /* Change the max read size to 2k */
338 result = pci_read_config_byte(pdev, 0x51, &read_size_reg);
339 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100340 dev_err(&pdev->dev,
Alan Cox64f93032009-06-10 17:30:41 +0100341 "Could not read PCI config space for Max read size\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700342 return -EIO;
343 }
344
345 read_size_reg &= 0x8f;
346 read_size_reg |= 0x40;
347
348 result = pci_write_config_byte(pdev, 0x51, read_size_reg);
349 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100350 dev_err(&pdev->dev,
Alan Cox64f93032009-06-10 17:30:41 +0100351 "Could not write PCI config space for Max read size\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700352 return -EIO;
353 }
354
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700355 /* Get MAC address from config space if an eeprom exists, otherwise
356 * the MAC address there will not be valid
357 */
Alan Cox9fa81092009-08-27 11:00:36 +0100358 if (adapter->has_eeprom) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700359 int i;
360
361 for (i = 0; i < ETH_ALEN; i++) {
362 result = pci_read_config_byte(
363 pdev, ET1310_PCI_MAC_ADDRESS + i,
364 adapter->PermanentAddress + i);
365 if (result != PCIBIOS_SUCCESSFUL) {
Alan Cox15700032009-08-27 11:03:09 +0100366 dev_err(&pdev->dev, ";Could not read PCI config space for MAC address\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700367 return -EIO;
368 }
369 }
370 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700371 return 0;
372}
373
374/**
375 * et131x_error_timer_handler
376 * @data: timer-specific variable; here a pointer to our adapter structure
377 *
378 * The routine called when the error timer expires, to track the number of
379 * recurring errors.
380 */
381void et131x_error_timer_handler(unsigned long data)
382{
Alan Cox25ad00b2009-08-19 18:21:44 +0100383 struct et131x_adapter *etdev = (struct et131x_adapter *) data;
Alan Coxf2c98d22009-08-27 11:01:49 +0100384 u32 pm_csr;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700385
Alan Coxf2c98d22009-08-27 11:01:49 +0100386 pm_csr = readl(&etdev->regs->global.pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700387
Alan Coxf2c98d22009-08-27 11:01:49 +0100388 if ((pm_csr & ET_PM_PHY_SW_COMA) == 0)
Alan Cox94831462009-08-27 11:00:06 +0100389 UpdateMacStatHostCounters(etdev);
390 else
Alan Cox15700032009-08-27 11:03:09 +0100391 dev_err(&etdev->pdev->dev,
392 "No interrupts, in PHY coma, pm_csr = 0x%x\n", pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700393
Alan Cox25ad00b2009-08-19 18:21:44 +0100394 if (!etdev->Bmsr.bits.link_status &&
395 etdev->RegistryPhyComa &&
396 etdev->PoMgmt.TransPhyComaModeOnBoot < 11) {
397 etdev->PoMgmt.TransPhyComaModeOnBoot++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700398 }
399
Alan Cox25ad00b2009-08-19 18:21:44 +0100400 if (etdev->PoMgmt.TransPhyComaModeOnBoot == 10) {
401 if (!etdev->Bmsr.bits.link_status
402 && etdev->RegistryPhyComa) {
Alan Coxf2c98d22009-08-27 11:01:49 +0100403 if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
Alan Cox64f93032009-06-10 17:30:41 +0100404 /* NOTE - This was originally a 'sync with
405 * interrupt'. How to do that under Linux?
406 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100407 et131x_enable_interrupts(etdev);
408 EnablePhyComa(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700409 }
410 }
411 }
412
413 /* This is a periodic timer, so reschedule */
Alan Cox25ad00b2009-08-19 18:21:44 +0100414 mod_timer(&etdev->ErrorTimer, jiffies +
Alan Cox64f93032009-06-10 17:30:41 +0100415 TX_ERROR_PERIOD * HZ / 1000);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700416}
417
418/**
419 * et131x_link_detection_handler
420 *
421 * Timer function for link up at driver load time
422 */
423void et131x_link_detection_handler(unsigned long data)
424{
Alan Cox25ad00b2009-08-19 18:21:44 +0100425 struct et131x_adapter *etdev = (struct et131x_adapter *) data;
Alan Cox37628602009-08-19 18:21:50 +0100426 unsigned long flags;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700427
Alan Cox25ad00b2009-08-19 18:21:44 +0100428 if (etdev->MediaState == 0) {
Alan Cox37628602009-08-19 18:21:50 +0100429 spin_lock_irqsave(&etdev->Lock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700430
Alan Cox25ad00b2009-08-19 18:21:44 +0100431 etdev->MediaState = NETIF_STATUS_MEDIA_DISCONNECT;
Alan Coxf6b35d62009-08-27 11:02:05 +0100432 etdev->Flags &= ~fMP_ADAPTER_LINK_DETECTION;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700433
Alan Cox37628602009-08-19 18:21:50 +0100434 spin_unlock_irqrestore(&etdev->Lock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700435
Alan Cox25ad00b2009-08-19 18:21:44 +0100436 netif_carrier_off(etdev->netdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700437 }
438}
439
440/**
Alan Coxb8c4cc42009-08-27 11:02:25 +0100441 * et131x_configure_global_regs - configure JAGCore global regs
442 * @etdev: pointer to our adapter structure
443 *
444 * Used to configure the global registers on the JAGCore
445 */
446void ConfigGlobalRegs(struct et131x_adapter *etdev)
447{
Alan Coxe266b202009-08-27 11:02:34 +0100448 struct _GLOBAL_t __iomem *regs = &etdev->regs->global;
Alan Coxb8c4cc42009-08-27 11:02:25 +0100449
Alan Coxb8c4cc42009-08-27 11:02:25 +0100450 if (etdev->RegistryPhyLoopbk == false) {
451 if (etdev->RegistryJumboPacket < 2048) {
452 /* Tx / RxDMA and Tx/Rx MAC interfaces have a 1k word
453 * block of RAM that the driver can split between Tx
454 * and Rx as it desires. Our default is to split it
455 * 50/50:
456 */
Alan Coxe266b202009-08-27 11:02:34 +0100457 writel(0, &regs->rxq_start_addr);
458 writel(PARM_RX_MEM_END_DEF, &regs->rxq_end_addr);
459 writel(PARM_RX_MEM_END_DEF + 1, &regs->txq_start_addr);
460 writel(INTERNAL_MEM_SIZE - 1, &regs->txq_end_addr);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100461 } else if (etdev->RegistryJumboPacket < 8192) {
462 /* For jumbo packets > 2k but < 8k, split 50-50. */
Alan Coxe266b202009-08-27 11:02:34 +0100463 writel(0, &regs->rxq_start_addr);
464 writel(INTERNAL_MEM_RX_OFFSET, &regs->rxq_end_addr);
465 writel(INTERNAL_MEM_RX_OFFSET + 1, &regs->txq_start_addr);
466 writel(INTERNAL_MEM_SIZE - 1, &regs->txq_end_addr);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100467 } else {
468 /* 9216 is the only packet size greater than 8k that
469 * is available. The Tx buffer has to be big enough
470 * for one whole packet on the Tx side. We'll make
471 * the Tx 9408, and give the rest to Rx
472 */
Alan Coxe266b202009-08-27 11:02:34 +0100473 writel(0x0000, &regs->rxq_start_addr);
474 writel(0x01b3, &regs->rxq_end_addr);
475 writel(0x01b4, &regs->txq_start_addr);
476 writel(INTERNAL_MEM_SIZE - 1,&regs->txq_end_addr);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100477 }
478
479 /* Initialize the loopback register. Disable all loopbacks. */
Alan Coxbc7f9c52009-08-27 11:02:43 +0100480 writel(0, &regs->loopback);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100481 } else {
482 /* For PHY Line loopback, the memory is configured as if Tx
483 * and Rx both have all the memory. This is because the
484 * RxMAC will write data into the space, and the TxMAC will
485 * read it out.
486 */
Alan Coxe266b202009-08-27 11:02:34 +0100487 writel(0, &regs->rxq_start_addr);
488 writel(INTERNAL_MEM_SIZE - 1, &regs->rxq_end_addr);
489 writel(0, &regs->txq_start_addr);
490 writel(INTERNAL_MEM_SIZE - 1, &regs->txq_end_addr);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100491
492 /* Initialize the loopback register (MAC loopback). */
Alan Coxbc7f9c52009-08-27 11:02:43 +0100493 writel(ET_LOOP_MAC, &regs->loopback);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100494 }
495
496 /* MSI Register */
Alan Coxe266b202009-08-27 11:02:34 +0100497 writel(0, &regs->msi_config);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100498
499 /* By default, disable the watchdog timer. It will be enabled when
500 * a packet is queued.
501 */
Alan Coxe266b202009-08-27 11:02:34 +0100502 writel(0, &regs->watchdog_timer);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100503}
504
505
506/**
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700507 * et131x_adapter_setup - Set the adapter up as per cassini+ documentation
508 * @adapter: pointer to our private adapter structure
509 *
510 * Returns 0 on success, errno on failure (as defined in errno.h)
511 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100512int et131x_adapter_setup(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700513{
514 int status = 0;
515
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700516 /* Configure the JAGCore */
Alan Cox25ad00b2009-08-19 18:21:44 +0100517 ConfigGlobalRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700518
Alan Cox25ad00b2009-08-19 18:21:44 +0100519 ConfigMACRegs1(etdev);
Alan Coxb8c4cc42009-08-27 11:02:25 +0100520
521 /* Configure the MMC registers */
522 /* All we need to do is initialize the Memory Control Register */
523 writel(ET_MMC_ENABLE, &etdev->regs->mmc.mmc_ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700524
Alan Cox25ad00b2009-08-19 18:21:44 +0100525 ConfigRxMacRegs(etdev);
526 ConfigTxMacRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700527
Alan Cox25ad00b2009-08-19 18:21:44 +0100528 ConfigRxDmaRegs(etdev);
529 ConfigTxDmaRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700530
Alan Cox25ad00b2009-08-19 18:21:44 +0100531 ConfigMacStatRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700532
533 /* Move the following code to Timer function?? */
Alan Cox25ad00b2009-08-19 18:21:44 +0100534 status = et131x_xcvr_find(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700535
Alan Cox64f93032009-06-10 17:30:41 +0100536 if (status != 0)
Alan Cox15700032009-08-27 11:03:09 +0100537 dev_warn(&etdev->pdev->dev, "Could not find the xcvr\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700538
539 /* Prepare the TRUEPHY library. */
Alan Cox25ad00b2009-08-19 18:21:44 +0100540 ET1310_PhyInit(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700541
542 /* Reset the phy now so changes take place */
Alan Cox25ad00b2009-08-19 18:21:44 +0100543 ET1310_PhyReset(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700544
545 /* Power down PHY */
Alan Cox25ad00b2009-08-19 18:21:44 +0100546 ET1310_PhyPowerDown(etdev, 1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700547
548 /*
549 * We need to turn off 1000 base half dulplex, the mac does not
550 * support it. For the 10/100 part, turn off all gig advertisement
551 */
Alan Cox5ec34872009-08-27 10:59:13 +0100552 if (etdev->pdev->device != ET131X_PCI_DEVICE_ID_FAST)
Alan Cox25ad00b2009-08-19 18:21:44 +0100553 ET1310_PhyAdvertise1000BaseT(etdev, TRUEPHY_ADV_DUPLEX_FULL);
Alan Cox64f93032009-06-10 17:30:41 +0100554 else
Alan Cox25ad00b2009-08-19 18:21:44 +0100555 ET1310_PhyAdvertise1000BaseT(etdev, TRUEPHY_ADV_DUPLEX_NONE);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700556
557 /* Power up PHY */
Alan Cox25ad00b2009-08-19 18:21:44 +0100558 ET1310_PhyPowerDown(etdev, 0);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700559
Alan Cox25ad00b2009-08-19 18:21:44 +0100560 et131x_setphy_normal(etdev);
Alan Cox15700032009-08-27 11:03:09 +0100561; return status;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700562}
563
564/**
565 * et131x_setup_hardware_properties - set up the MAC Address on the ET1310
566 * @adapter: pointer to our private adapter structure
567 */
568void et131x_setup_hardware_properties(struct et131x_adapter *adapter)
569{
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700570 /* If have our default mac from registry and no mac address from
571 * EEPROM then we need to generate the last octet and set it on the
572 * device
573 */
Alan Cox9fa81092009-08-27 11:00:36 +0100574 if (adapter->PermanentAddress[0] == 0x00 &&
575 adapter->PermanentAddress[1] == 0x00 &&
576 adapter->PermanentAddress[2] == 0x00 &&
577 adapter->PermanentAddress[3] == 0x00 &&
578 adapter->PermanentAddress[4] == 0x00 &&
579 adapter->PermanentAddress[5] == 0x00) {
580 /*
581 * We need to randomly generate the last octet so we
582 * decrease our chances of setting the mac address to
583 * same as another one of our cards in the system
584 */
585 get_random_bytes(&adapter->CurrentAddress[5], 1);
586 /*
587 * We have the default value in the register we are
588 * working with so we need to copy the current
589 * address into the permanent address
590 */
591 memcpy(adapter->PermanentAddress,
592 adapter->CurrentAddress, ETH_ALEN);
593 } else {
594 /* We do not have an override address, so set the
595 * current address to the permanent address and add
596 * it to the device
597 */
598 memcpy(adapter->CurrentAddress,
599 adapter->PermanentAddress, ETH_ALEN);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700600 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700601}
602
603/**
604 * et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310
605 * @adapter: pointer to our private adapter structure
606 */
607void et131x_soft_reset(struct et131x_adapter *adapter)
608{
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700609 /* Disable MAC Core */
Alan Coxf3f415a2009-08-27 10:59:30 +0100610 writel(0xc00f0000, &adapter->regs->mac.cfg1.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700611
612 /* Set everything to a reset value */
Alan Coxb8c4cc42009-08-27 11:02:25 +0100613 writel(0x7F, &adapter->regs->global.sw_reset);
Alan Coxf3f415a2009-08-27 10:59:30 +0100614 writel(0x000f0000, &adapter->regs->mac.cfg1.value);
615 writel(0x00000000, &adapter->regs->mac.cfg1.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700616}
617
618/**
619 * et131x_align_allocated_memory - Align allocated memory on a given boundary
620 * @adapter: pointer to our adapter structure
621 * @phys_addr: pointer to Physical address
622 * @offset: pointer to the offset variable
623 * @mask: correct mask
624 */
625void et131x_align_allocated_memory(struct et131x_adapter *adapter,
626 uint64_t *phys_addr,
627 uint64_t *offset, uint64_t mask)
628{
629 uint64_t new_addr;
630
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700631 *offset = 0;
632
633 new_addr = *phys_addr & ~mask;
634
635 if (new_addr != *phys_addr) {
636 /* Move to next aligned block */
637 new_addr += mask + 1;
638 /* Return offset for adjusting virt addr */
639 *offset = new_addr - *phys_addr;
640 /* Return new physical address */
641 *phys_addr = new_addr;
642 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700643}
644
645/**
646 * et131x_adapter_memory_alloc
647 * @adapter: pointer to our private adapter structure
648 *
649 * Returns 0 on success, errno on failure (as defined in errno.h).
650 *
651 * Allocate all the memory blocks for send, receive and others.
652 */
653int et131x_adapter_memory_alloc(struct et131x_adapter *adapter)
654{
655 int status = 0;
656
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700657 do {
658 /* Allocate memory for the Tx Ring */
659 status = et131x_tx_dma_memory_alloc(adapter);
660 if (status != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100661 dev_err(&adapter->pdev->dev,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700662 "et131x_tx_dma_memory_alloc FAILED\n");
663 break;
664 }
665
666 /* Receive buffer memory allocation */
667 status = et131x_rx_dma_memory_alloc(adapter);
668 if (status != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100669 dev_err(&adapter->pdev->dev,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700670 "et131x_rx_dma_memory_alloc FAILED\n");
671 et131x_tx_dma_memory_free(adapter);
672 break;
673 }
674
675 /* Init receive data structures */
676 status = et131x_init_recv(adapter);
677 if (status != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100678 dev_err(&adapter->pdev->dev,
679 "et131x_init_recv FAILED\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700680 et131x_tx_dma_memory_free(adapter);
681 et131x_rx_dma_memory_free(adapter);
682 break;
683 }
684 } while (0);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700685 return status;
686}
687
688/**
689 * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx
690 * @adapter: pointer to our private adapter structure
691 */
692void et131x_adapter_memory_free(struct et131x_adapter *adapter)
693{
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700694 /* Free DMA memory */
695 et131x_tx_dma_memory_free(adapter);
696 et131x_rx_dma_memory_free(adapter);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700697}
698
699/**
700 * et131x_pci_remove
701 * @pdev: a pointer to the device's pci_dev structure
702 *
703 * Registered in the pci_driver structure, this function is called when the
704 * PCI subsystem detects that a PCI device which matches the information
705 * contained in the pci_device_id table has been removed.
706 */
707void __devexit et131x_pci_remove(struct pci_dev *pdev)
708{
709 struct net_device *netdev;
710 struct et131x_adapter *adapter;
711
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700712 /* Retrieve the net_device pointer from the pci_dev struct, as well
713 * as the private adapter struct
714 */
715 netdev = (struct net_device *) pci_get_drvdata(pdev);
716 adapter = netdev_priv(netdev);
717
718 /* Perform device cleanup */
719 unregister_netdev(netdev);
720 et131x_adapter_memory_free(adapter);
Alan Coxf3f415a2009-08-27 10:59:30 +0100721 iounmap(adapter->regs);
Alan Cox6ae56042009-08-27 10:59:21 +0100722 pci_dev_put(adapter->pdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700723 free_netdev(netdev);
724 pci_release_regions(pdev);
725 pci_disable_device(pdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700726}
727
728/**
Alan Cox8c5f20f2009-08-27 11:00:24 +0100729 * et131x_config_parse
730 * @etdev: pointer to the private adapter struct
731 *
732 * Parses a configuration from some location (module parameters, for example)
733 * into the private adapter struct. This really has no sensible analogy in
734 * Linux as sysfs parameters are dynamic. Several things that were hee could
735 * go into sysfs, but other stuff like speed handling is part of the mii
736 * interfaces/ethtool.
737 */
738void et131x_config_parse(struct et131x_adapter *etdev)
739{
740 static const u8 default_mac[] = { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 };
741 static const u8 duplex[] = { 0, 1, 2, 1, 2, 2 };
742 static const u16 speed[] = { 0, 10, 10, 100, 100, 1000 };
743
Alan Cox8c5f20f2009-08-27 11:00:24 +0100744 if (et131x_speed_set)
Alan Cox15700032009-08-27 11:03:09 +0100745 dev_info(&etdev->pdev->dev,
746 "Speed set manually to : %d \n", et131x_speed_set);
Alan Cox8c5f20f2009-08-27 11:00:24 +0100747
748 etdev->SpeedDuplex = et131x_speed_set;
749 etdev->RegistryJumboPacket = 1514; /* 1514-9216 */
750
751 etdev->RegistryNMIDisable = et131x_nmi_disable;
752
753 /* Set the MAC address to a default */
754 memcpy(etdev->CurrentAddress, default_mac, ETH_ALEN);
755
756 /* Decode SpeedDuplex
757 *
758 * Set up as if we are auto negotiating always and then change if we
759 * go into force mode
760 *
761 * If we are the 10/100 device, and gigabit is somehow requested then
762 * knock it down to 100 full.
763 */
764 if (etdev->pdev->device == ET131X_PCI_DEVICE_ID_FAST &&
765 etdev->SpeedDuplex == 5)
766 etdev->SpeedDuplex = 4;
767
768 etdev->AiForceSpeed = speed[etdev->SpeedDuplex];
769 etdev->AiForceDpx = duplex[etdev->SpeedDuplex]; /* Auto FDX */
Alan Cox8c5f20f2009-08-27 11:00:24 +0100770}
771
772
773/**
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700774 * et131x_pci_setup - Perform device initialization
775 * @pdev: a pointer to the device's pci_dev structure
776 * @ent: this device's entry in the pci_device_id table
777 *
778 * Returns 0 on success, errno on failure (as defined in errno.h)
779 *
780 * Registered in the pci_driver structure, this function is called when the
781 * PCI subsystem finds a new PCI device which matches the information
782 * contained in the pci_device_id table. This routine is the equivalent to
783 * a device insertion routine.
784 */
785int __devinit et131x_pci_setup(struct pci_dev *pdev,
786 const struct pci_device_id *ent)
787{
788 int result = 0;
789 int pm_cap;
790 bool pci_using_dac;
791 struct net_device *netdev = NULL;
792 struct et131x_adapter *adapter = NULL;
793
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700794 /* Enable the device via the PCI subsystem */
795 result = pci_enable_device(pdev);
796 if (result != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100797 dev_err(&adapter->pdev->dev,
798 "pci_enable_device() failed\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700799 goto out;
800 }
801
802 /* Perform some basic PCI checks */
803 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Alan Cox15700032009-08-27 11:03:09 +0100804 dev_err(&adapter->pdev->dev,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700805 "Can't find PCI device's base address\n");
806 result = -ENODEV;
807 goto out;
808 }
809
810 result = pci_request_regions(pdev, DRIVER_NAME);
811 if (result != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100812 dev_err(&adapter->pdev->dev,
813 "Can't get PCI resources\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700814 goto err_disable;
815 }
816
817 /* Enable PCI bus mastering */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700818 pci_set_master(pdev);
819
820 /* Query PCI for Power Mgmt Capabilities
821 *
822 * NOTE: Now reading PowerMgmt in another location; is this still
823 * needed?
824 */
825 pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
826 if (pm_cap == 0) {
Alan Cox15700032009-08-27 11:03:09 +0100827 dev_err(&adapter->pdev->dev,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700828 "Cannot find Power Management capabilities\n");
829 result = -EIO;
830 goto err_release_res;
831 }
832
833 /* Check the DMA addressing support of this device */
834 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700835 pci_using_dac = true;
836
837 result =
838 pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL);
839 if (result != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100840 dev_err(&pdev->dev,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700841 "Unable to obtain 64 bit DMA for consistent allocations\n");
842 goto err_release_res;
843 }
844 } else if (!pci_set_dma_mask(pdev, 0xffffffffULL)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700845 pci_using_dac = false;
846 } else {
Alan Cox15700032009-08-27 11:03:09 +0100847 dev_err(&adapter->pdev->dev,
848 "No usable DMA addressing method\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700849 result = -EIO;
850 goto err_release_res;
851 }
852
853 /* Allocate netdev and private adapter structs */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700854 netdev = et131x_device_alloc();
855 if (netdev == NULL) {
Alan Cox15700032009-08-27 11:03:09 +0100856 dev_err(&adapter->pdev->dev,
857 "Couldn't alloc netdev struct\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700858 result = -ENOMEM;
859 goto err_release_res;
860 }
861
862 /* Setup the fundamental net_device and private adapter structure elements */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700863 SET_NETDEV_DEV(netdev, &pdev->dev);
Alan Cox64f93032009-06-10 17:30:41 +0100864 /*
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700865 if (pci_using_dac) {
Alan Cox64f93032009-06-10 17:30:41 +0100866 netdev->features |= NETIF_F_HIGHDMA;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700867 }
Alan Cox64f93032009-06-10 17:30:41 +0100868 */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700869
870 /*
871 * NOTE - Turn this on when we're ready to deal with SG-DMA
872 *
873 * NOTE: According to "Linux Device Drivers", 3rd ed, Rubini et al,
874 * if checksumming is not performed in HW, then the kernel will not
875 * use SG.
876 * From pp 510-511:
877 *
878 * "Note that the kernel does not perform scatter/gather I/O to your
879 * device if it does not also provide some form of checksumming as
880 * well. The reason is that, if the kernel has to make a pass over a
881 * fragmented ("nonlinear") packet to calculate the checksum, it
882 * might as well copy the data and coalesce the packet at the same
883 * time."
884 *
885 * This has been verified by setting the flags below and still not
886 * receiving a scattered buffer from the network stack, so leave it
887 * off until checksums are calculated in HW.
888 */
Alan Cox64f93032009-06-10 17:30:41 +0100889 /* netdev->features |= NETIF_F_SG; */
890 /* netdev->features |= NETIF_F_NO_CSUM; */
891 /* netdev->features |= NETIF_F_LLTX; */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700892
893 /* Allocate private adapter struct and copy in relevant information */
894 adapter = netdev_priv(netdev);
Alan Cox6ae56042009-08-27 10:59:21 +0100895 adapter->pdev = pci_dev_get(pdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700896 adapter->netdev = netdev;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700897
898 /* Do the same for the netdev struct */
899 netdev->irq = pdev->irq;
900 netdev->base_addr = pdev->resource[0].start;
901
902 /* Initialize spinlocks here */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700903 spin_lock_init(&adapter->Lock);
904 spin_lock_init(&adapter->TCBSendQLock);
905 spin_lock_init(&adapter->TCBReadyQLock);
906 spin_lock_init(&adapter->SendHWLock);
907 spin_lock_init(&adapter->SendWaitLock);
908 spin_lock_init(&adapter->RcvLock);
909 spin_lock_init(&adapter->RcvPendLock);
910 spin_lock_init(&adapter->FbrLock);
911 spin_lock_init(&adapter->PHYLock);
912
913 /* Parse configuration parameters into the private adapter struct */
914 et131x_config_parse(adapter);
915
916 /* Find the physical adapter
917 *
918 * NOTE: This is the equivalent of the MpFindAdapter() routine; can we
919 * lump it's init with the device specific init below into a
920 * single init function?
921 */
Alan Cox64f93032009-06-10 17:30:41 +0100922 /* while (et131x_find_adapter(adapter, pdev) != 0); */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700923 et131x_find_adapter(adapter, pdev);
924
925 /* Map the bus-relative registers to system virtual memory */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700926
Alan Coxf3f415a2009-08-27 10:59:30 +0100927 adapter->regs = ioremap_nocache(pci_resource_start(pdev, 0),
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700928 pci_resource_len(pdev, 0));
Alan Coxf3f415a2009-08-27 10:59:30 +0100929 if (adapter->regs == NULL) {
Alan Cox15700032009-08-27 11:03:09 +0100930 dev_err(&pdev->dev, "Cannot map device registers\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700931 result = -ENOMEM;
932 goto err_free_dev;
933 }
934
935 /* Perform device-specific initialization here (See code below) */
936
937 /* If Phy COMA mode was enabled when we went down, disable it here. */
Alan Coxf2c98d22009-08-27 11:01:49 +0100938 writel(ET_PMCSR_INIT, &adapter->regs->global.pm_csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700939
940 /* Issue a global reset to the et1310 */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700941 et131x_soft_reset(adapter);
942
943 /* Disable all interrupts (paranoid) */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700944 et131x_disable_interrupts(adapter);
945
946 /* Allocate DMA memory */
947 result = et131x_adapter_memory_alloc(adapter);
948 if (result != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100949 dev_err(&pdev->dev, "Could not alloc adapater memory (DMA)\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700950 goto err_iounmap;
951 }
952
953 /* Init send data structures */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700954 et131x_init_send(adapter);
955
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700956 /* Register the interrupt
957 *
958 * NOTE - This is being done in the open routine, where most other
959 * Linux drivers setup IRQ handlers. Make sure device
960 * interrupts are not turned on before the IRQ is registered!!
961 *
962 * What we will do here is setup the task structure for the
963 * ISR's deferred handler
964 */
965 INIT_WORK(&adapter->task, et131x_isr_handler);
966
967 /* Determine MAC Address, and copy into the net_device struct */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700968 et131x_setup_hardware_properties(adapter);
969
970 memcpy(netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN);
971
972 /* Setup et1310 as per the documentation */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700973 et131x_adapter_setup(adapter);
974
975 /* Create a timer to count errors received by the NIC */
976 init_timer(&adapter->ErrorTimer);
977
978 adapter->ErrorTimer.expires = jiffies + TX_ERROR_PERIOD * HZ / 1000;
979 adapter->ErrorTimer.function = et131x_error_timer_handler;
980 adapter->ErrorTimer.data = (unsigned long)adapter;
981
982 /* Initialize link state */
983 et131x_link_detection_handler((unsigned long)adapter);
984
Alan Cox64f93032009-06-10 17:30:41 +0100985 /* Intialize variable for counting how long we do not have
986 link status */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700987 adapter->PoMgmt.TransPhyComaModeOnBoot = 0;
988
989 /* We can enable interrupts now
990 *
991 * NOTE - Because registration of interrupt handler is done in the
992 * device's open(), defer enabling device interrupts to that
993 * point
994 */
995
996 /* Register the net_device struct with the Linux network layer */
Alan Cox64f93032009-06-10 17:30:41 +0100997 result = register_netdev(netdev);
998 if (result != 0) {
Alan Cox15700032009-08-27 11:03:09 +0100999 dev_err(&pdev->dev, "register_netdev() failed\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001000 goto err_mem_free;
1001 }
1002
1003 /* Register the net_device struct with the PCI subsystem. Save a copy
1004 * of the PCI config space for this device now that the device has
1005 * been initialized, just in case it needs to be quickly restored.
1006 */
1007 pci_set_drvdata(pdev, netdev);
1008
1009 pci_save_state(adapter->pdev);
1010
1011out:
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001012 return result;
1013
1014err_mem_free:
1015 et131x_adapter_memory_free(adapter);
1016err_iounmap:
Alan Coxf3f415a2009-08-27 10:59:30 +01001017 iounmap(adapter->regs);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001018err_free_dev:
Alan Cox6ae56042009-08-27 10:59:21 +01001019 pci_dev_put(pdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001020 free_netdev(netdev);
1021err_release_res:
1022 pci_release_regions(pdev);
1023err_disable:
1024 pci_disable_device(pdev);
1025 goto out;
1026}