blob: 34737d1638085c9026aa7b5ef3369aa09efc593b [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"
61#include "et131x_debug.h"
62#include "et131x_defs.h"
63
64#include <linux/pci.h>
65#include <linux/init.h>
66#include <linux/module.h>
67#include <linux/types.h>
68#include <linux/kernel.h>
69
70#include <linux/sched.h>
71#include <linux/ptrace.h>
72#include <linux/slab.h>
73#include <linux/ctype.h>
74#include <linux/string.h>
75#include <linux/timer.h>
76#include <linux/interrupt.h>
77#include <linux/in.h>
78#include <linux/delay.h>
Alan Cox64f93032009-06-10 17:30:41 +010079#include <linux/io.h>
80#include <linux/bitops.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070081#include <asm/system.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070082
83#include <linux/netdevice.h>
84#include <linux/etherdevice.h>
85#include <linux/skbuff.h>
86#include <linux/if_arp.h>
87#include <linux/ioport.h>
88#include <linux/random.h>
89
90#include "et1310_phy.h"
91#include "et1310_pm.h"
92#include "et1310_jagcore.h"
93
94#include "et131x_adapter.h"
95#include "et131x_netdev.h"
96#include "et131x_config.h"
97#include "et131x_isr.h"
98
99#include "et1310_address_map.h"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700100#include "et1310_tx.h"
101#include "et1310_rx.h"
102#include "et1310_mac.h"
103#include "et1310_eeprom.h"
104
105
106int __devinit et131x_pci_setup(struct pci_dev *pdev,
107 const struct pci_device_id *ent);
108void __devexit et131x_pci_remove(struct pci_dev *pdev);
109
110
111/* Modinfo parameters (filled out using defines from et131x_version.h) */
112MODULE_AUTHOR(DRIVER_AUTHOR);
113MODULE_DESCRIPTION(DRIVER_INFO);
114MODULE_LICENSE(DRIVER_LICENSE);
115
116/* Module Parameters and related data for debugging facilities */
117#ifdef CONFIG_ET131X_DEBUG
118static u32 et131x_debug_level = DBG_LVL;
119static u32 et131x_debug_flags = DBG_DEFAULTS;
120
121/*
122et131x_debug_level :
123 Level of debugging desired (0-7)
124 7 : DBG_RX_ON | DBG_TX_ON
125 6 : DBG_PARAM_ON
126 5 : DBG_VERBOSE_ON
127 4 : DBG_TRACE_ON
128 3 : DBG_NOTICE_ON
129 2 : no debug info
130 1 : no debug info
131 0 : no debug info
132*/
133
134module_param(et131x_debug_level, uint, 0);
135module_param(et131x_debug_flags, uint, 0);
136
137MODULE_PARM_DESC(et131x_debug_level, "Level of debugging desired (0-7)");
138
139static dbg_info_t et131x_info = { DRIVER_NAME_EXT, 0, 0 };
140dbg_info_t *et131x_dbginfo = &et131x_info;
141#endif /* CONFIG_ET131X_DEBUG */
142
Alan Cox8c5f20f2009-08-27 11:00:24 +0100143/* Defines for Parameter Default/Min/Max vaules */
144#define PARM_SPEED_DUPLEX_MIN 0
145#define PARM_SPEED_DUPLEX_MAX 5
146
147/* Module parameter for disabling NMI
148 * et131x_nmi_disable :
149 * Disable NMI (0-2) [0]
150 * 0 :
151 * 1 :
152 * 2 :
153 */
154static u32 et131x_nmi_disable; /* 0-2 */
155module_param(et131x_nmi_disable, uint, 0);
156MODULE_PARM_DESC(et131x_nmi_disable, "Disable NMI (0-2) [0]");
157
158/* Module parameter for manual speed setting
159 * Set Link speed and dublex manually (0-5) [0]
160 * 1 : 10Mb Half-Duplex
161 * 2 : 10Mb Full-Duplex
162 * 3 : 100Mb Half-Duplex
163 * 4 : 100Mb Full-Duplex
164 * 5 : 1000Mb Full-Duplex
165 * 0 : Auto Speed Auto Duplex // default
166 */
167static u32 et131x_speed_set;
168module_param(et131x_speed_set, uint, 0);
169MODULE_PARM_DESC(et131x_speed_set,
170 "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");
171
172
173
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700174static struct pci_device_id et131x_pci_table[] __devinitdata = {
175 {ET131X_PCI_VENDOR_ID, ET131X_PCI_DEVICE_ID_GIG, PCI_ANY_ID,
176 PCI_ANY_ID, 0, 0, 0UL},
177 {ET131X_PCI_VENDOR_ID, ET131X_PCI_DEVICE_ID_FAST, PCI_ANY_ID,
178 PCI_ANY_ID, 0, 0, 0UL},
179 {0,}
180};
181
182MODULE_DEVICE_TABLE(pci, et131x_pci_table);
183
184static struct pci_driver et131x_driver = {
185 .name = DRIVER_NAME,
186 .id_table = et131x_pci_table,
187 .probe = et131x_pci_setup,
188 .remove = __devexit_p(et131x_pci_remove),
Alan Cox64f93032009-06-10 17:30:41 +0100189 .suspend = NULL, /* et131x_pci_suspend */
190 .resume = NULL, /* et131x_pci_resume */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700191};
192
193
194/**
195 * et131x_init_module - The "main" entry point called on driver initialization
196 *
197 * Returns 0 on success, errno on failure (as defined in errno.h)
198 */
199int et131x_init_module(void)
200{
201 int result;
202
203#ifdef CONFIG_ET131X_DEBUG
204 /* Set the level of debug messages displayed using the module
205 * parameter
206 */
207 et131x_dbginfo->dbgFlags = et131x_debug_flags;
208
209 switch (et131x_debug_level) {
210 case 7:
211 et131x_dbginfo->dbgFlags |= (DBG_RX_ON | DBG_TX_ON);
212
213 case 6:
214 et131x_dbginfo->dbgFlags |= DBG_PARAM_ON;
215
216 case 5:
217 et131x_dbginfo->dbgFlags |= DBG_VERBOSE_ON;
218
219 case 4:
220 et131x_dbginfo->dbgFlags |= DBG_TRACE_ON;
221
222 case 3:
223 et131x_dbginfo->dbgFlags |= DBG_NOTICE_ON;
224
225 case 2:
226 case 1:
227 case 0:
228 default:
229 break;
230 }
231#endif /* CONFIG_ET131X_DEBUG */
232
233 DBG_ENTER(et131x_dbginfo);
234 DBG_PRINT("%s\n", DRIVER_INFO);
235
Alan Cox8c5f20f2009-08-27 11:00:24 +0100236 if (et131x_speed_set < PARM_SPEED_DUPLEX_MIN ||
237 et131x_speed_set > PARM_SPEED_DUPLEX_MAX) {
238 printk(KERN_WARNING "et131x: invalid speed setting ignored.\n");
239 et131x_speed_set = 0;
240 }
241
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700242 result = pci_register_driver(&et131x_driver);
243
244 DBG_LEAVE(et131x_dbginfo);
245 return result;
246}
247
248/**
249 * et131x_cleanup_module - The entry point called on driver cleanup
250 */
251void et131x_cleanup_module(void)
252{
253 DBG_ENTER(et131x_dbginfo);
254
255 pci_unregister_driver(&et131x_driver);
256
257 DBG_LEAVE(et131x_dbginfo);
258}
259
260/*
261 * These macros map the driver-specific init_module() and cleanup_module()
262 * routines so they can be called by the kernel.
263 */
264module_init(et131x_init_module);
265module_exit(et131x_cleanup_module);
266
267
268/**
269 * et131x_find_adapter - Find the adapter and get all the assigned resources
270 * @adapter: pointer to our private adapter structure
271 *
272 * Returns 0 on success, errno on failure (as defined in errno.h)
273 */
274int et131x_find_adapter(struct et131x_adapter *adapter, struct pci_dev *pdev)
275{
276 int result;
277 uint8_t eepromStat;
278 uint8_t maxPayload = 0;
279 uint8_t read_size_reg;
Alan Cox5ec34872009-08-27 10:59:13 +0100280 u8 rev;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700281
282 DBG_ENTER(et131x_dbginfo);
283
284 /* Allow disabling of Non-Maskable Interrupts in I/O space, to
285 * support validation.
286 */
287 if (adapter->RegistryNMIDisable) {
288 uint8_t RegisterVal;
289
290 RegisterVal = inb(ET1310_NMI_DISABLE);
291 RegisterVal &= 0xf3;
292
Alan Cox64f93032009-06-10 17:30:41 +0100293 if (adapter->RegistryNMIDisable == 2)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700294 RegisterVal |= 0xc;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700295
296 outb(ET1310_NMI_DISABLE, RegisterVal);
297 }
298
299 /* We first need to check the EEPROM Status code located at offset
300 * 0xB2 of config space
301 */
302 result = pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS,
303 &eepromStat);
304
305 /* THIS IS A WORKAROUND:
Alan Cox64f93032009-06-10 17:30:41 +0100306 * I need to call this function twice to get my card in a
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700307 * LG M1 Express Dual running. I tried also a msleep before this
308 * function, because I thougth there could be some time condidions
309 * but it didn't work. Call the whole function twice also work.
310 */
311 result = pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS,
312 &eepromStat);
313 if (result != PCIBIOS_SUCCESSFUL) {
314 DBG_ERROR(et131x_dbginfo, "Could not read PCI config space for "
315 "EEPROM Status\n");
316 DBG_LEAVE(et131x_dbginfo);
317 return -EIO;
318 }
319
320 /* Determine if the error(s) we care about are present. If they are
321 * present, we need to fail.
322 */
323 if (eepromStat & 0x4C) {
Alan Cox5ec34872009-08-27 10:59:13 +0100324 result = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700325 if (result != PCIBIOS_SUCCESSFUL) {
326 DBG_ERROR(et131x_dbginfo,
327 "Could not read PCI config space for "
328 "Revision ID\n");
329 DBG_LEAVE(et131x_dbginfo);
330 return -EIO;
Alan Cox5ec34872009-08-27 10:59:13 +0100331 } else if (rev == 0x01) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700332 int32_t nLoop;
333 uint8_t ucTemp[4] = { 0xFE, 0x13, 0x10, 0xFF };
334
335 /* Re-write the first 4 bytes if we have an eeprom
336 * present and the revision id is 1, this fixes the
337 * corruption seen with 1310 B Silicon
338 */
339 for (nLoop = 0; nLoop < 3; nLoop++) {
340 EepromWriteByte(adapter, nLoop, ucTemp[nLoop],
341 0, SINGLE_BYTE);
342 }
343 }
344
345 DBG_ERROR(et131x_dbginfo,
346 "Fatal EEPROM Status Error - 0x%04x\n", eepromStat);
347
348 /* This error could mean that there was an error reading the
349 * eeprom or that the eeprom doesn't exist. We will treat
350 * each case the same and not try to gather additional
351 * information that normally would come from the eeprom, like
352 * MAC Address
353 */
354 adapter->bEepromPresent = false;
355
356 DBG_LEAVE(et131x_dbginfo);
357 return -EIO;
358 } else {
359 DBG_TRACE(et131x_dbginfo, "EEPROM Status Code - 0x%04x\n",
360 eepromStat);
361 adapter->bEepromPresent = true;
362 }
363
364 /* Read the EEPROM for information regarding LED behavior. Refer to
365 * ET1310_phy.c, et131x_xcvr_init(), for its use.
366 */
367 EepromReadByte(adapter, 0x70, &adapter->eepromData[0], 0, SINGLE_BYTE);
368 EepromReadByte(adapter, 0x71, &adapter->eepromData[1], 0, SINGLE_BYTE);
369
Alan Cox64f93032009-06-10 17:30:41 +0100370 if (adapter->eepromData[0] != 0xcd)
371 /* Disable all optional features */
372 adapter->eepromData[1] = 0x00;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700373
374 /* Let's set up the PORT LOGIC Register. First we need to know what
375 * the max_payload_size is
376 */
377 result = pci_read_config_byte(pdev, ET1310_PCI_MAX_PYLD, &maxPayload);
378 if (result != PCIBIOS_SUCCESSFUL) {
379 DBG_ERROR(et131x_dbginfo, "Could not read PCI config space for "
380 "Max Payload Size\n");
381 DBG_LEAVE(et131x_dbginfo);
382 return -EIO;
383 }
384
385 /* Program the Ack/Nak latency and replay timers */
Alan Cox64f93032009-06-10 17:30:41 +0100386 maxPayload &= 0x07; /* Only the lower 3 bits are valid */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700387
388 if (maxPayload < 2) {
389 const uint16_t AckNak[2] = { 0x76, 0xD0 };
390 const uint16_t Replay[2] = { 0x1E0, 0x2ED };
391
392 result = pci_write_config_word(pdev, ET1310_PCI_ACK_NACK,
393 AckNak[maxPayload]);
394 if (result != PCIBIOS_SUCCESSFUL) {
395 DBG_ERROR(et131x_dbginfo,
396 "Could not write PCI config space "
397 "for ACK/NAK\n");
398 DBG_LEAVE(et131x_dbginfo);
399 return -EIO;
400 }
401
402 result = pci_write_config_word(pdev, ET1310_PCI_REPLAY,
403 Replay[maxPayload]);
404 if (result != PCIBIOS_SUCCESSFUL) {
405 DBG_ERROR(et131x_dbginfo,
406 "Could not write PCI config space "
407 "for Replay Timer\n");
408 DBG_LEAVE(et131x_dbginfo);
409 return -EIO;
410 }
411 }
412
413 /* l0s and l1 latency timers. We are using default values.
414 * Representing 001 for L0s and 010 for L1
415 */
416 result = pci_write_config_byte(pdev, ET1310_PCI_L0L1LATENCY, 0x11);
417 if (result != PCIBIOS_SUCCESSFUL) {
418 DBG_ERROR(et131x_dbginfo,
419 "Could not write PCI config space for "
420 "Latency Timers\n");
421 DBG_LEAVE(et131x_dbginfo);
422 return -EIO;
423 }
424
425 /* Change the max read size to 2k */
426 result = pci_read_config_byte(pdev, 0x51, &read_size_reg);
427 if (result != PCIBIOS_SUCCESSFUL) {
428 DBG_ERROR(et131x_dbginfo,
Alan Cox64f93032009-06-10 17:30:41 +0100429 "Could not read PCI config space for Max read size\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700430 DBG_LEAVE(et131x_dbginfo);
431 return -EIO;
432 }
433
434 read_size_reg &= 0x8f;
435 read_size_reg |= 0x40;
436
437 result = pci_write_config_byte(pdev, 0x51, read_size_reg);
438 if (result != PCIBIOS_SUCCESSFUL) {
439 DBG_ERROR(et131x_dbginfo,
Alan Cox64f93032009-06-10 17:30:41 +0100440 "Could not write PCI config space for Max read size\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700441 DBG_LEAVE(et131x_dbginfo);
442 return -EIO;
443 }
444
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700445 /* Get MAC address from config space if an eeprom exists, otherwise
446 * the MAC address there will not be valid
447 */
448 if (adapter->bEepromPresent) {
449 int i;
450
451 for (i = 0; i < ETH_ALEN; i++) {
452 result = pci_read_config_byte(
453 pdev, ET1310_PCI_MAC_ADDRESS + i,
454 adapter->PermanentAddress + i);
455 if (result != PCIBIOS_SUCCESSFUL) {
456 DBG_ERROR(et131x_dbginfo,
Alan Cox64f93032009-06-10 17:30:41 +0100457 "Could not read PCI config space for MAC address\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700458 DBG_LEAVE(et131x_dbginfo);
459 return -EIO;
460 }
461 }
462 }
463
464 DBG_LEAVE(et131x_dbginfo);
465 return 0;
466}
467
468/**
469 * et131x_error_timer_handler
470 * @data: timer-specific variable; here a pointer to our adapter structure
471 *
472 * The routine called when the error timer expires, to track the number of
473 * recurring errors.
474 */
475void et131x_error_timer_handler(unsigned long data)
476{
Alan Cox25ad00b2009-08-19 18:21:44 +0100477 struct et131x_adapter *etdev = (struct et131x_adapter *) data;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700478 PM_CSR_t pm_csr;
479
Alan Coxf3f415a2009-08-27 10:59:30 +0100480 pm_csr.value = readl(&etdev->regs->global.pm_csr.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700481
Alan Cox94831462009-08-27 11:00:06 +0100482 if (pm_csr.bits.pm_phy_sw_coma == 0)
483 UpdateMacStatHostCounters(etdev);
484 else
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700485 DBG_VERBOSE(et131x_dbginfo,
486 "No interrupts, in PHY coma, pm_csr = 0x%x\n",
487 pm_csr.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700488
Alan Cox25ad00b2009-08-19 18:21:44 +0100489 if (!etdev->Bmsr.bits.link_status &&
490 etdev->RegistryPhyComa &&
491 etdev->PoMgmt.TransPhyComaModeOnBoot < 11) {
492 etdev->PoMgmt.TransPhyComaModeOnBoot++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700493 }
494
Alan Cox25ad00b2009-08-19 18:21:44 +0100495 if (etdev->PoMgmt.TransPhyComaModeOnBoot == 10) {
496 if (!etdev->Bmsr.bits.link_status
497 && etdev->RegistryPhyComa) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700498 if (pm_csr.bits.pm_phy_sw_coma == 0) {
Alan Cox64f93032009-06-10 17:30:41 +0100499 /* NOTE - This was originally a 'sync with
500 * interrupt'. How to do that under Linux?
501 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100502 et131x_enable_interrupts(etdev);
503 EnablePhyComa(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700504 }
505 }
506 }
507
508 /* This is a periodic timer, so reschedule */
Alan Cox25ad00b2009-08-19 18:21:44 +0100509 mod_timer(&etdev->ErrorTimer, jiffies +
Alan Cox64f93032009-06-10 17:30:41 +0100510 TX_ERROR_PERIOD * HZ / 1000);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700511}
512
513/**
514 * et131x_link_detection_handler
515 *
516 * Timer function for link up at driver load time
517 */
518void et131x_link_detection_handler(unsigned long data)
519{
Alan Cox25ad00b2009-08-19 18:21:44 +0100520 struct et131x_adapter *etdev = (struct et131x_adapter *) data;
Alan Cox37628602009-08-19 18:21:50 +0100521 unsigned long flags;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700522
523 /* Let everyone know that we have run */
Alan Cox25ad00b2009-08-19 18:21:44 +0100524 etdev->bLinkTimerActive = false;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700525
Alan Cox25ad00b2009-08-19 18:21:44 +0100526 if (etdev->MediaState == 0) {
Alan Cox37628602009-08-19 18:21:50 +0100527 spin_lock_irqsave(&etdev->Lock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700528
Alan Cox25ad00b2009-08-19 18:21:44 +0100529 etdev->MediaState = NETIF_STATUS_MEDIA_DISCONNECT;
530 MP_CLEAR_FLAG(etdev, fMP_ADAPTER_LINK_DETECTION);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700531
Alan Cox37628602009-08-19 18:21:50 +0100532 spin_unlock_irqrestore(&etdev->Lock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700533
Alan Cox25ad00b2009-08-19 18:21:44 +0100534 netif_carrier_off(etdev->netdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700535
Alan Cox25ad00b2009-08-19 18:21:44 +0100536 etdev->bSetPending = false;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700537 }
538}
539
540/**
541 * et131x_adapter_setup - Set the adapter up as per cassini+ documentation
542 * @adapter: pointer to our private adapter structure
543 *
544 * Returns 0 on success, errno on failure (as defined in errno.h)
545 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100546int et131x_adapter_setup(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700547{
548 int status = 0;
549
550 DBG_ENTER(et131x_dbginfo);
551
552 /* Configure the JAGCore */
Alan Cox25ad00b2009-08-19 18:21:44 +0100553 ConfigGlobalRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700554
Alan Cox25ad00b2009-08-19 18:21:44 +0100555 ConfigMACRegs1(etdev);
556 ConfigMMCRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700557
Alan Cox25ad00b2009-08-19 18:21:44 +0100558 ConfigRxMacRegs(etdev);
559 ConfigTxMacRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700560
Alan Cox25ad00b2009-08-19 18:21:44 +0100561 ConfigRxDmaRegs(etdev);
562 ConfigTxDmaRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700563
Alan Cox25ad00b2009-08-19 18:21:44 +0100564 ConfigMacStatRegs(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700565
566 /* Move the following code to Timer function?? */
Alan Cox25ad00b2009-08-19 18:21:44 +0100567 status = et131x_xcvr_find(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700568
Alan Cox64f93032009-06-10 17:30:41 +0100569 if (status != 0)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700570 DBG_WARNING(et131x_dbginfo, "Could not find the xcvr\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700571
572 /* Prepare the TRUEPHY library. */
Alan Cox25ad00b2009-08-19 18:21:44 +0100573 ET1310_PhyInit(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700574
575 /* Reset the phy now so changes take place */
Alan Cox25ad00b2009-08-19 18:21:44 +0100576 ET1310_PhyReset(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700577
578 /* Power down PHY */
Alan Cox25ad00b2009-08-19 18:21:44 +0100579 ET1310_PhyPowerDown(etdev, 1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700580
581 /*
582 * We need to turn off 1000 base half dulplex, the mac does not
583 * support it. For the 10/100 part, turn off all gig advertisement
584 */
Alan Cox5ec34872009-08-27 10:59:13 +0100585 if (etdev->pdev->device != ET131X_PCI_DEVICE_ID_FAST)
Alan Cox25ad00b2009-08-19 18:21:44 +0100586 ET1310_PhyAdvertise1000BaseT(etdev, TRUEPHY_ADV_DUPLEX_FULL);
Alan Cox64f93032009-06-10 17:30:41 +0100587 else
Alan Cox25ad00b2009-08-19 18:21:44 +0100588 ET1310_PhyAdvertise1000BaseT(etdev, TRUEPHY_ADV_DUPLEX_NONE);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700589
590 /* Power up PHY */
Alan Cox25ad00b2009-08-19 18:21:44 +0100591 ET1310_PhyPowerDown(etdev, 0);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700592
Alan Cox25ad00b2009-08-19 18:21:44 +0100593 et131x_setphy_normal(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700594
595 DBG_LEAVE(et131x_dbginfo);
596 return status;
597}
598
599/**
600 * et131x_setup_hardware_properties - set up the MAC Address on the ET1310
601 * @adapter: pointer to our private adapter structure
602 */
603void et131x_setup_hardware_properties(struct et131x_adapter *adapter)
604{
605 DBG_ENTER(et131x_dbginfo);
606
607 /* If have our default mac from registry and no mac address from
608 * EEPROM then we need to generate the last octet and set it on the
609 * device
610 */
611 if (!adapter->bOverrideAddress) {
612 if (adapter->PermanentAddress[0] == 0x00 &&
613 adapter->PermanentAddress[1] == 0x00 &&
614 adapter->PermanentAddress[2] == 0x00 &&
615 adapter->PermanentAddress[3] == 0x00 &&
616 adapter->PermanentAddress[4] == 0x00 &&
617 adapter->PermanentAddress[5] == 0x00) {
618 /*
619 * We need to randomly generate the last octet so we
620 * decrease our chances of setting the mac address to
621 * same as another one of our cards in the system
622 */
623 get_random_bytes(&adapter->CurrentAddress[5], 1);
624
625 /*
626 * We have the default value in the register we are
627 * working with so we need to copy the current
628 * address into the permanent address
629 */
630 memcpy(adapter->PermanentAddress,
631 adapter->CurrentAddress, ETH_ALEN);
632 } else {
633 /* We do not have an override address, so set the
634 * current address to the permanent address and add
635 * it to the device
636 */
637 memcpy(adapter->CurrentAddress,
638 adapter->PermanentAddress, ETH_ALEN);
639 }
640 }
641
642 DBG_LEAVE(et131x_dbginfo);
643}
644
645/**
646 * et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310
647 * @adapter: pointer to our private adapter structure
648 */
649void et131x_soft_reset(struct et131x_adapter *adapter)
650{
651 DBG_ENTER(et131x_dbginfo);
652
653 /* Disable MAC Core */
Alan Coxf3f415a2009-08-27 10:59:30 +0100654 writel(0xc00f0000, &adapter->regs->mac.cfg1.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700655
656 /* Set everything to a reset value */
Alan Coxf3f415a2009-08-27 10:59:30 +0100657 writel(0x7F, &adapter->regs->global.sw_reset.value);
658 writel(0x000f0000, &adapter->regs->mac.cfg1.value);
659 writel(0x00000000, &adapter->regs->mac.cfg1.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700660
661 DBG_LEAVE(et131x_dbginfo);
662}
663
664/**
665 * et131x_align_allocated_memory - Align allocated memory on a given boundary
666 * @adapter: pointer to our adapter structure
667 * @phys_addr: pointer to Physical address
668 * @offset: pointer to the offset variable
669 * @mask: correct mask
670 */
671void et131x_align_allocated_memory(struct et131x_adapter *adapter,
672 uint64_t *phys_addr,
673 uint64_t *offset, uint64_t mask)
674{
675 uint64_t new_addr;
676
677 DBG_ENTER(et131x_dbginfo);
678
679 *offset = 0;
680
681 new_addr = *phys_addr & ~mask;
682
683 if (new_addr != *phys_addr) {
684 /* Move to next aligned block */
685 new_addr += mask + 1;
686 /* Return offset for adjusting virt addr */
687 *offset = new_addr - *phys_addr;
688 /* Return new physical address */
689 *phys_addr = new_addr;
690 }
691
692 DBG_LEAVE(et131x_dbginfo);
693}
694
695/**
696 * et131x_adapter_memory_alloc
697 * @adapter: pointer to our private adapter structure
698 *
699 * Returns 0 on success, errno on failure (as defined in errno.h).
700 *
701 * Allocate all the memory blocks for send, receive and others.
702 */
703int et131x_adapter_memory_alloc(struct et131x_adapter *adapter)
704{
705 int status = 0;
706
707 DBG_ENTER(et131x_dbginfo);
708
709 do {
710 /* Allocate memory for the Tx Ring */
711 status = et131x_tx_dma_memory_alloc(adapter);
712 if (status != 0) {
713 DBG_ERROR(et131x_dbginfo,
714 "et131x_tx_dma_memory_alloc FAILED\n");
715 break;
716 }
717
718 /* Receive buffer memory allocation */
719 status = et131x_rx_dma_memory_alloc(adapter);
720 if (status != 0) {
721 DBG_ERROR(et131x_dbginfo,
722 "et131x_rx_dma_memory_alloc FAILED\n");
723 et131x_tx_dma_memory_free(adapter);
724 break;
725 }
726
727 /* Init receive data structures */
728 status = et131x_init_recv(adapter);
729 if (status != 0) {
730 DBG_ERROR(et131x_dbginfo, "et131x_init_recv FAILED\n");
731 et131x_tx_dma_memory_free(adapter);
732 et131x_rx_dma_memory_free(adapter);
733 break;
734 }
735 } while (0);
736
737 DBG_LEAVE(et131x_dbginfo);
738 return status;
739}
740
741/**
742 * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx
743 * @adapter: pointer to our private adapter structure
744 */
745void et131x_adapter_memory_free(struct et131x_adapter *adapter)
746{
747 DBG_ENTER(et131x_dbginfo);
748
749 /* Free DMA memory */
750 et131x_tx_dma_memory_free(adapter);
751 et131x_rx_dma_memory_free(adapter);
752
753 DBG_LEAVE(et131x_dbginfo);
754}
755
756/**
757 * et131x_pci_remove
758 * @pdev: a pointer to the device's pci_dev structure
759 *
760 * Registered in the pci_driver structure, this function is called when the
761 * PCI subsystem detects that a PCI device which matches the information
762 * contained in the pci_device_id table has been removed.
763 */
764void __devexit et131x_pci_remove(struct pci_dev *pdev)
765{
766 struct net_device *netdev;
767 struct et131x_adapter *adapter;
768
769 DBG_ENTER(et131x_dbginfo);
770
771 /* Retrieve the net_device pointer from the pci_dev struct, as well
772 * as the private adapter struct
773 */
774 netdev = (struct net_device *) pci_get_drvdata(pdev);
775 adapter = netdev_priv(netdev);
776
777 /* Perform device cleanup */
778 unregister_netdev(netdev);
779 et131x_adapter_memory_free(adapter);
Alan Coxf3f415a2009-08-27 10:59:30 +0100780 iounmap(adapter->regs);
Alan Cox6ae56042009-08-27 10:59:21 +0100781 pci_dev_put(adapter->pdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700782 free_netdev(netdev);
783 pci_release_regions(pdev);
784 pci_disable_device(pdev);
785
786 DBG_LEAVE(et131x_dbginfo);
787}
788
789/**
Alan Cox8c5f20f2009-08-27 11:00:24 +0100790 * et131x_config_parse
791 * @etdev: pointer to the private adapter struct
792 *
793 * Parses a configuration from some location (module parameters, for example)
794 * into the private adapter struct. This really has no sensible analogy in
795 * Linux as sysfs parameters are dynamic. Several things that were hee could
796 * go into sysfs, but other stuff like speed handling is part of the mii
797 * interfaces/ethtool.
798 */
799void et131x_config_parse(struct et131x_adapter *etdev)
800{
801 static const u8 default_mac[] = { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 };
802 static const u8 duplex[] = { 0, 1, 2, 1, 2, 2 };
803 static const u16 speed[] = { 0, 10, 10, 100, 100, 1000 };
804
805 DBG_ENTER(et131x_dbginfo);
806
807 if (et131x_speed_set)
808 DBG_VERBOSE(et131x_dbginfo, "Speed set manually to : %d \n",
809 et131x_speed_set);
810
811 etdev->SpeedDuplex = et131x_speed_set;
812 etdev->RegistryJumboPacket = 1514; /* 1514-9216 */
813
814 etdev->RegistryNMIDisable = et131x_nmi_disable;
815
816 /* Set the MAC address to a default */
817 memcpy(etdev->CurrentAddress, default_mac, ETH_ALEN);
818
819 /* Decode SpeedDuplex
820 *
821 * Set up as if we are auto negotiating always and then change if we
822 * go into force mode
823 *
824 * If we are the 10/100 device, and gigabit is somehow requested then
825 * knock it down to 100 full.
826 */
827 if (etdev->pdev->device == ET131X_PCI_DEVICE_ID_FAST &&
828 etdev->SpeedDuplex == 5)
829 etdev->SpeedDuplex = 4;
830
831 etdev->AiForceSpeed = speed[etdev->SpeedDuplex];
832 etdev->AiForceDpx = duplex[etdev->SpeedDuplex]; /* Auto FDX */
833
834 DBG_LEAVE(et131x_dbginfo);
835}
836
837
838/**
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700839 * et131x_pci_setup - Perform device initialization
840 * @pdev: a pointer to the device's pci_dev structure
841 * @ent: this device's entry in the pci_device_id table
842 *
843 * Returns 0 on success, errno on failure (as defined in errno.h)
844 *
845 * Registered in the pci_driver structure, this function is called when the
846 * PCI subsystem finds a new PCI device which matches the information
847 * contained in the pci_device_id table. This routine is the equivalent to
848 * a device insertion routine.
849 */
850int __devinit et131x_pci_setup(struct pci_dev *pdev,
851 const struct pci_device_id *ent)
852{
853 int result = 0;
854 int pm_cap;
855 bool pci_using_dac;
856 struct net_device *netdev = NULL;
857 struct et131x_adapter *adapter = NULL;
858
859 DBG_ENTER(et131x_dbginfo);
860
861 /* Enable the device via the PCI subsystem */
862 result = pci_enable_device(pdev);
863 if (result != 0) {
864 DBG_ERROR(et131x_dbginfo, "pci_enable_device() failed\n");
865 goto out;
866 }
867
868 /* Perform some basic PCI checks */
869 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
870 DBG_ERROR(et131x_dbginfo,
871 "Can't find PCI device's base address\n");
872 result = -ENODEV;
873 goto out;
874 }
875
876 result = pci_request_regions(pdev, DRIVER_NAME);
877 if (result != 0) {
878 DBG_ERROR(et131x_dbginfo, "Can't get PCI resources\n");
879 goto err_disable;
880 }
881
882 /* Enable PCI bus mastering */
883 DBG_TRACE(et131x_dbginfo, "Setting PCI Bus Mastering...\n");
884 pci_set_master(pdev);
885
886 /* Query PCI for Power Mgmt Capabilities
887 *
888 * NOTE: Now reading PowerMgmt in another location; is this still
889 * needed?
890 */
891 pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
892 if (pm_cap == 0) {
893 DBG_ERROR(et131x_dbginfo,
894 "Cannot find Power Management capabilities\n");
895 result = -EIO;
896 goto err_release_res;
897 }
898
899 /* Check the DMA addressing support of this device */
900 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
901 DBG_TRACE(et131x_dbginfo, "64-bit DMA addressing supported\n");
902 pci_using_dac = true;
903
904 result =
905 pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL);
906 if (result != 0) {
907 DBG_ERROR(et131x_dbginfo,
908 "Unable to obtain 64 bit DMA for consistent allocations\n");
909 goto err_release_res;
910 }
911 } else if (!pci_set_dma_mask(pdev, 0xffffffffULL)) {
912 DBG_TRACE(et131x_dbginfo,
913 "64-bit DMA addressing NOT supported\n");
914 DBG_TRACE(et131x_dbginfo,
915 "32-bit DMA addressing will be used\n");
916 pci_using_dac = false;
917 } else {
918 DBG_ERROR(et131x_dbginfo, "No usable DMA addressing method\n");
919 result = -EIO;
920 goto err_release_res;
921 }
922
923 /* Allocate netdev and private adapter structs */
924 DBG_TRACE(et131x_dbginfo,
925 "Allocate netdev and private adapter structs...\n");
926 netdev = et131x_device_alloc();
927 if (netdev == NULL) {
928 DBG_ERROR(et131x_dbginfo, "Couldn't alloc netdev struct\n");
929 result = -ENOMEM;
930 goto err_release_res;
931 }
932
933 /* Setup the fundamental net_device and private adapter structure elements */
934 DBG_TRACE(et131x_dbginfo, "Setting fundamental net_device info...\n");
935 SET_NETDEV_DEV(netdev, &pdev->dev);
Alan Cox64f93032009-06-10 17:30:41 +0100936 /*
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700937 if (pci_using_dac) {
Alan Cox64f93032009-06-10 17:30:41 +0100938 netdev->features |= NETIF_F_HIGHDMA;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700939 }
Alan Cox64f93032009-06-10 17:30:41 +0100940 */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700941
942 /*
943 * NOTE - Turn this on when we're ready to deal with SG-DMA
944 *
945 * NOTE: According to "Linux Device Drivers", 3rd ed, Rubini et al,
946 * if checksumming is not performed in HW, then the kernel will not
947 * use SG.
948 * From pp 510-511:
949 *
950 * "Note that the kernel does not perform scatter/gather I/O to your
951 * device if it does not also provide some form of checksumming as
952 * well. The reason is that, if the kernel has to make a pass over a
953 * fragmented ("nonlinear") packet to calculate the checksum, it
954 * might as well copy the data and coalesce the packet at the same
955 * time."
956 *
957 * This has been verified by setting the flags below and still not
958 * receiving a scattered buffer from the network stack, so leave it
959 * off until checksums are calculated in HW.
960 */
Alan Cox64f93032009-06-10 17:30:41 +0100961 /* netdev->features |= NETIF_F_SG; */
962 /* netdev->features |= NETIF_F_NO_CSUM; */
963 /* netdev->features |= NETIF_F_LLTX; */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700964
965 /* Allocate private adapter struct and copy in relevant information */
966 adapter = netdev_priv(netdev);
Alan Cox6ae56042009-08-27 10:59:21 +0100967 adapter->pdev = pci_dev_get(pdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700968 adapter->netdev = netdev;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700969
970 /* Do the same for the netdev struct */
971 netdev->irq = pdev->irq;
972 netdev->base_addr = pdev->resource[0].start;
973
974 /* Initialize spinlocks here */
975 DBG_TRACE(et131x_dbginfo, "Initialize spinlocks...\n");
976
977 spin_lock_init(&adapter->Lock);
978 spin_lock_init(&adapter->TCBSendQLock);
979 spin_lock_init(&adapter->TCBReadyQLock);
980 spin_lock_init(&adapter->SendHWLock);
981 spin_lock_init(&adapter->SendWaitLock);
982 spin_lock_init(&adapter->RcvLock);
983 spin_lock_init(&adapter->RcvPendLock);
984 spin_lock_init(&adapter->FbrLock);
985 spin_lock_init(&adapter->PHYLock);
986
987 /* Parse configuration parameters into the private adapter struct */
988 et131x_config_parse(adapter);
989
990 /* Find the physical adapter
991 *
992 * NOTE: This is the equivalent of the MpFindAdapter() routine; can we
993 * lump it's init with the device specific init below into a
994 * single init function?
995 */
Alan Cox64f93032009-06-10 17:30:41 +0100996 /* while (et131x_find_adapter(adapter, pdev) != 0); */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700997 et131x_find_adapter(adapter, pdev);
998
999 /* Map the bus-relative registers to system virtual memory */
1000 DBG_TRACE(et131x_dbginfo,
1001 "Mapping bus-relative registers to virtual memory...\n");
1002
Alan Coxf3f415a2009-08-27 10:59:30 +01001003 adapter->regs = ioremap_nocache(pci_resource_start(pdev, 0),
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001004 pci_resource_len(pdev, 0));
Alan Coxf3f415a2009-08-27 10:59:30 +01001005 if (adapter->regs == NULL) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001006 DBG_ERROR(et131x_dbginfo, "Cannot map device registers\n");
1007 result = -ENOMEM;
1008 goto err_free_dev;
1009 }
1010
1011 /* Perform device-specific initialization here (See code below) */
1012
1013 /* If Phy COMA mode was enabled when we went down, disable it here. */
1014 {
1015 PM_CSR_t GlobalPmCSR = { 0 };
1016
1017 GlobalPmCSR.bits.pm_sysclk_gate = 1;
1018 GlobalPmCSR.bits.pm_txclk_gate = 1;
1019 GlobalPmCSR.bits.pm_rxclk_gate = 1;
1020 writel(GlobalPmCSR.value,
Alan Coxf3f415a2009-08-27 10:59:30 +01001021 &adapter->regs->global.pm_csr.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001022 }
1023
1024 /* Issue a global reset to the et1310 */
1025 DBG_TRACE(et131x_dbginfo, "Issuing soft reset...\n");
1026 et131x_soft_reset(adapter);
1027
1028 /* Disable all interrupts (paranoid) */
1029 DBG_TRACE(et131x_dbginfo, "Disable device interrupts...\n");
1030 et131x_disable_interrupts(adapter);
1031
1032 /* Allocate DMA memory */
1033 result = et131x_adapter_memory_alloc(adapter);
1034 if (result != 0) {
1035 DBG_ERROR(et131x_dbginfo,
1036 "Could not alloc adapater memory (DMA)\n");
1037 goto err_iounmap;
1038 }
1039
1040 /* Init send data structures */
1041 DBG_TRACE(et131x_dbginfo, "Init send data structures...\n");
1042 et131x_init_send(adapter);
1043
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001044 /* Register the interrupt
1045 *
1046 * NOTE - This is being done in the open routine, where most other
1047 * Linux drivers setup IRQ handlers. Make sure device
1048 * interrupts are not turned on before the IRQ is registered!!
1049 *
1050 * What we will do here is setup the task structure for the
1051 * ISR's deferred handler
1052 */
1053 INIT_WORK(&adapter->task, et131x_isr_handler);
1054
1055 /* Determine MAC Address, and copy into the net_device struct */
1056 DBG_TRACE(et131x_dbginfo, "Retrieve MAC address...\n");
1057 et131x_setup_hardware_properties(adapter);
1058
1059 memcpy(netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN);
1060
1061 /* Setup et1310 as per the documentation */
1062 DBG_TRACE(et131x_dbginfo, "Setup the adapter...\n");
1063 et131x_adapter_setup(adapter);
1064
1065 /* Create a timer to count errors received by the NIC */
1066 init_timer(&adapter->ErrorTimer);
1067
1068 adapter->ErrorTimer.expires = jiffies + TX_ERROR_PERIOD * HZ / 1000;
1069 adapter->ErrorTimer.function = et131x_error_timer_handler;
1070 adapter->ErrorTimer.data = (unsigned long)adapter;
1071
1072 /* Initialize link state */
1073 et131x_link_detection_handler((unsigned long)adapter);
1074
Alan Cox64f93032009-06-10 17:30:41 +01001075 /* Intialize variable for counting how long we do not have
1076 link status */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001077 adapter->PoMgmt.TransPhyComaModeOnBoot = 0;
1078
1079 /* We can enable interrupts now
1080 *
1081 * NOTE - Because registration of interrupt handler is done in the
1082 * device's open(), defer enabling device interrupts to that
1083 * point
1084 */
1085
1086 /* Register the net_device struct with the Linux network layer */
1087 DBG_TRACE(et131x_dbginfo, "Registering net_device...\n");
Alan Cox64f93032009-06-10 17:30:41 +01001088 result = register_netdev(netdev);
1089 if (result != 0) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001090 DBG_ERROR(et131x_dbginfo, "register_netdev() failed\n");
1091 goto err_mem_free;
1092 }
1093
1094 /* Register the net_device struct with the PCI subsystem. Save a copy
1095 * of the PCI config space for this device now that the device has
1096 * been initialized, just in case it needs to be quickly restored.
1097 */
1098 pci_set_drvdata(pdev, netdev);
1099
1100 pci_save_state(adapter->pdev);
1101
1102out:
1103 DBG_LEAVE(et131x_dbginfo);
1104 return result;
1105
1106err_mem_free:
1107 et131x_adapter_memory_free(adapter);
1108err_iounmap:
Alan Coxf3f415a2009-08-27 10:59:30 +01001109 iounmap(adapter->regs);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001110err_free_dev:
Alan Cox6ae56042009-08-27 10:59:21 +01001111 pci_dev_put(pdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001112 free_netdev(netdev);
1113err_release_res:
1114 pci_release_regions(pdev);
1115err_disable:
1116 pci_disable_device(pdev);
1117 goto out;
1118}