aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/atl1e/atl1e_hw.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/atl1e/atl1e_hw.c')
-rw-r--r--drivers/net/atl1e/atl1e_hw.c664
1 files changed, 664 insertions, 0 deletions
diff --git a/drivers/net/atl1e/atl1e_hw.c b/drivers/net/atl1e/atl1e_hw.c
new file mode 100644
index 000000000000..949e75358bf0
--- /dev/null
+++ b/drivers/net/atl1e/atl1e_hw.c
@@ -0,0 +1,664 @@
1/*
2 * Copyright(c) 2007 Atheros Corporation. All rights reserved.
3 *
4 * Derived from Intel e1000 driver
5 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#include <linux/pci.h>
22#include <linux/delay.h>
23#include <linux/mii.h>
24#include <linux/crc32.h>
25
26#include "atl1e.h"
27
28/*
29 * check_eeprom_exist
30 * return 0 if eeprom exist
31 */
32int atl1e_check_eeprom_exist(struct atl1e_hw *hw)
33{
34 u32 value;
35
36 value = AT_READ_REG(hw, REG_SPI_FLASH_CTRL);
37 if (value & SPI_FLASH_CTRL_EN_VPD) {
38 value &= ~SPI_FLASH_CTRL_EN_VPD;
39 AT_WRITE_REG(hw, REG_SPI_FLASH_CTRL, value);
40 }
41 value = AT_READ_REGW(hw, REG_PCIE_CAP_LIST);
42 return ((value & 0xFF00) == 0x6C00) ? 0 : 1;
43}
44
45void atl1e_hw_set_mac_addr(struct atl1e_hw *hw)
46{
47 u32 value;
48 /*
49 * 00-0B-6A-F6-00-DC
50 * 0: 6AF600DC 1: 000B
51 * low dword
52 */
53 value = (((u32)hw->mac_addr[2]) << 24) |
54 (((u32)hw->mac_addr[3]) << 16) |
55 (((u32)hw->mac_addr[4]) << 8) |
56 (((u32)hw->mac_addr[5])) ;
57 AT_WRITE_REG_ARRAY(hw, REG_MAC_STA_ADDR, 0, value);
58 /* hight dword */
59 value = (((u32)hw->mac_addr[0]) << 8) |
60 (((u32)hw->mac_addr[1])) ;
61 AT_WRITE_REG_ARRAY(hw, REG_MAC_STA_ADDR, 1, value);
62}
63
64/*
65 * atl1e_get_permanent_address
66 * return 0 if get valid mac address,
67 */
68static int atl1e_get_permanent_address(struct atl1e_hw *hw)
69{
70 u32 addr[2];
71 u32 i;
72 u32 twsi_ctrl_data;
73 u8 eth_addr[ETH_ALEN];
74
75 if (is_valid_ether_addr(hw->perm_mac_addr))
76 return 0;
77
78 /* init */
79 addr[0] = addr[1] = 0;
80
81 if (!atl1e_check_eeprom_exist(hw)) {
82 /* eeprom exist */
83 twsi_ctrl_data = AT_READ_REG(hw, REG_TWSI_CTRL);
84 twsi_ctrl_data |= TWSI_CTRL_SW_LDSTART;
85 AT_WRITE_REG(hw, REG_TWSI_CTRL, twsi_ctrl_data);
86 for (i = 0; i < AT_TWSI_EEPROM_TIMEOUT; i++) {
87 msleep(10);
88 twsi_ctrl_data = AT_READ_REG(hw, REG_TWSI_CTRL);
89 if ((twsi_ctrl_data & TWSI_CTRL_SW_LDSTART) == 0)
90 break;
91 }
92 if (i >= AT_TWSI_EEPROM_TIMEOUT)
93 return AT_ERR_TIMEOUT;
94 }
95
96 /* maybe MAC-address is from BIOS */
97 addr[0] = AT_READ_REG(hw, REG_MAC_STA_ADDR);
98 addr[1] = AT_READ_REG(hw, REG_MAC_STA_ADDR + 4);
99 *(u32 *) &eth_addr[2] = swab32(addr[0]);
100 *(u16 *) &eth_addr[0] = swab16(*(u16 *)&addr[1]);
101
102 if (is_valid_ether_addr(eth_addr)) {
103 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
104 return 0;
105 }
106
107 return AT_ERR_EEPROM;
108}
109
110bool atl1e_write_eeprom(struct atl1e_hw *hw, u32 offset, u32 value)
111{
112 return true;
113}
114
115bool atl1e_read_eeprom(struct atl1e_hw *hw, u32 offset, u32 *p_value)
116{
117 int i;
118 u32 control;
119
120 if (offset & 3)
121 return false; /* address do not align */
122
123 AT_WRITE_REG(hw, REG_VPD_DATA, 0);
124 control = (offset & VPD_CAP_VPD_ADDR_MASK) << VPD_CAP_VPD_ADDR_SHIFT;
125 AT_WRITE_REG(hw, REG_VPD_CAP, control);
126
127 for (i = 0; i < 10; i++) {
128 msleep(2);
129 control = AT_READ_REG(hw, REG_VPD_CAP);
130 if (control & VPD_CAP_VPD_FLAG)
131 break;
132 }
133 if (control & VPD_CAP_VPD_FLAG) {
134 *p_value = AT_READ_REG(hw, REG_VPD_DATA);
135 return true;
136 }
137 return false; /* timeout */
138}
139
140void atl1e_force_ps(struct atl1e_hw *hw)
141{
142 AT_WRITE_REGW(hw, REG_GPHY_CTRL,
143 GPHY_CTRL_PW_WOL_DIS | GPHY_CTRL_EXT_RESET);
144}
145
146/*
147 * Reads the adapter's MAC address from the EEPROM
148 *
149 * hw - Struct containing variables accessed by shared code
150 */
151int atl1e_read_mac_addr(struct atl1e_hw *hw)
152{
153 int err = 0;
154
155 err = atl1e_get_permanent_address(hw);
156 if (err)
157 return AT_ERR_EEPROM;
158 memcpy(hw->mac_addr, hw->perm_mac_addr, sizeof(hw->perm_mac_addr));
159 return 0;
160}
161
162/*
163 * atl1e_hash_mc_addr
164 * purpose
165 * set hash value for a multicast address
166 * hash calcu processing :
167 * 1. calcu 32bit CRC for multicast address
168 * 2. reverse crc with MSB to LSB
169 */
170u32 atl1e_hash_mc_addr(struct atl1e_hw *hw, u8 *mc_addr)
171{
172 u32 crc32;
173 u32 value = 0;
174 int i;
175
176 crc32 = ether_crc_le(6, mc_addr);
177 crc32 = ~crc32;
178 for (i = 0; i < 32; i++)
179 value |= (((crc32 >> i) & 1) << (31 - i));
180
181 return value;
182}
183
184/*
185 * Sets the bit in the multicast table corresponding to the hash value.
186 * hw - Struct containing variables accessed by shared code
187 * hash_value - Multicast address hash value
188 */
189void atl1e_hash_set(struct atl1e_hw *hw, u32 hash_value)
190{
191 u32 hash_bit, hash_reg;
192 u32 mta;
193
194 /*
195 * The HASH Table is a register array of 2 32-bit registers.
196 * It is treated like an array of 64 bits. We want to set
197 * bit BitArray[hash_value]. So we figure out what register
198 * the bit is in, read it, OR in the new bit, then write
199 * back the new value. The register is determined by the
200 * upper 7 bits of the hash value and the bit within that
201 * register are determined by the lower 5 bits of the value.
202 */
203 hash_reg = (hash_value >> 31) & 0x1;
204 hash_bit = (hash_value >> 26) & 0x1F;
205
206 mta = AT_READ_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg);
207
208 mta |= (1 << hash_bit);
209
210 AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg, mta);
211}
212/*
213 * Reads the value from a PHY register
214 * hw - Struct containing variables accessed by shared code
215 * reg_addr - address of the PHY register to read
216 */
217int atl1e_read_phy_reg(struct atl1e_hw *hw, u16 reg_addr, u16 *phy_data)
218{
219 u32 val;
220 int i;
221
222 val = ((u32)(reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT |
223 MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW |
224 MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
225
226 AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
227
228 wmb();
229
230 for (i = 0; i < MDIO_WAIT_TIMES; i++) {
231 udelay(2);
232 val = AT_READ_REG(hw, REG_MDIO_CTRL);
233 if (!(val & (MDIO_START | MDIO_BUSY)))
234 break;
235 wmb();
236 }
237 if (!(val & (MDIO_START | MDIO_BUSY))) {
238 *phy_data = (u16)val;
239 return 0;
240 }
241
242 return AT_ERR_PHY;
243}
244
245/*
246 * Writes a value to a PHY register
247 * hw - Struct containing variables accessed by shared code
248 * reg_addr - address of the PHY register to write
249 * data - data to write to the PHY
250 */
251int atl1e_write_phy_reg(struct atl1e_hw *hw, u32 reg_addr, u16 phy_data)
252{
253 int i;
254 u32 val;
255
256 val = ((u32)(phy_data & MDIO_DATA_MASK)) << MDIO_DATA_SHIFT |
257 (reg_addr&MDIO_REG_ADDR_MASK) << MDIO_REG_ADDR_SHIFT |
258 MDIO_SUP_PREAMBLE |
259 MDIO_START |
260 MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
261
262 AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
263 wmb();
264
265 for (i = 0; i < MDIO_WAIT_TIMES; i++) {
266 udelay(2);
267 val = AT_READ_REG(hw, REG_MDIO_CTRL);
268 if (!(val & (MDIO_START | MDIO_BUSY)))
269 break;
270 wmb();
271 }
272
273 if (!(val & (MDIO_START | MDIO_BUSY)))
274 return 0;
275
276 return AT_ERR_PHY;
277}
278
279/*
280 * atl1e_init_pcie - init PCIE module
281 */
282static void atl1e_init_pcie(struct atl1e_hw *hw)
283{
284 u32 value;
285 /* comment 2lines below to save more power when sususpend
286 value = LTSSM_TEST_MODE_DEF;
287 AT_WRITE_REG(hw, REG_LTSSM_TEST_MODE, value);
288 */
289
290 /* pcie flow control mode change */
291 value = AT_READ_REG(hw, 0x1008);
292 value |= 0x8000;
293 AT_WRITE_REG(hw, 0x1008, value);
294}
295/*
296 * Configures PHY autoneg and flow control advertisement settings
297 *
298 * hw - Struct containing variables accessed by shared code
299 */
300static int atl1e_phy_setup_autoneg_adv(struct atl1e_hw *hw)
301{
302 s32 ret_val;
303 u16 mii_autoneg_adv_reg;
304 u16 mii_1000t_ctrl_reg;
305
306 if (0 != hw->mii_autoneg_adv_reg)
307 return 0;
308 /* Read the MII Auto-Neg Advertisement Register (Address 4/9). */
309 mii_autoneg_adv_reg = MII_AR_DEFAULT_CAP_MASK;
310 mii_1000t_ctrl_reg = MII_AT001_CR_1000T_DEFAULT_CAP_MASK;
311
312 /*
313 * Need to parse autoneg_advertised and set up
314 * the appropriate PHY registers. First we will parse for
315 * autoneg_advertised software override. Since we can advertise
316 * a plethora of combinations, we need to check each bit
317 * individually.
318 */
319
320 /*
321 * First we clear all the 10/100 mb speed bits in the Auto-Neg
322 * Advertisement Register (Address 4) and the 1000 mb speed bits in
323 * the 1000Base-T control Register (Address 9).
324 */
325 mii_autoneg_adv_reg &= ~MII_AR_SPEED_MASK;
326 mii_1000t_ctrl_reg &= ~MII_AT001_CR_1000T_SPEED_MASK;
327
328 /*
329 * Need to parse MediaType and setup the
330 * appropriate PHY registers.
331 */
332 switch (hw->media_type) {
333 case MEDIA_TYPE_AUTO_SENSOR:
334 mii_autoneg_adv_reg |= (MII_AR_10T_HD_CAPS |
335 MII_AR_10T_FD_CAPS |
336 MII_AR_100TX_HD_CAPS |
337 MII_AR_100TX_FD_CAPS);
338 hw->autoneg_advertised = ADVERTISE_10_HALF |
339 ADVERTISE_10_FULL |
340 ADVERTISE_100_HALF |
341 ADVERTISE_100_FULL;
342 if (hw->nic_type == athr_l1e) {
343 mii_1000t_ctrl_reg |=
344 MII_AT001_CR_1000T_FD_CAPS;
345 hw->autoneg_advertised |= ADVERTISE_1000_FULL;
346 }
347 break;
348
349 case MEDIA_TYPE_100M_FULL:
350 mii_autoneg_adv_reg |= MII_AR_100TX_FD_CAPS;
351 hw->autoneg_advertised = ADVERTISE_100_FULL;
352 break;
353
354 case MEDIA_TYPE_100M_HALF:
355 mii_autoneg_adv_reg |= MII_AR_100TX_HD_CAPS;
356 hw->autoneg_advertised = ADVERTISE_100_HALF;
357 break;
358
359 case MEDIA_TYPE_10M_FULL:
360 mii_autoneg_adv_reg |= MII_AR_10T_FD_CAPS;
361 hw->autoneg_advertised = ADVERTISE_10_FULL;
362 break;
363
364 default:
365 mii_autoneg_adv_reg |= MII_AR_10T_HD_CAPS;
366 hw->autoneg_advertised = ADVERTISE_10_HALF;
367 break;
368 }
369
370 /* flow control fixed to enable all */
371 mii_autoneg_adv_reg |= (MII_AR_ASM_DIR | MII_AR_PAUSE);
372
373 hw->mii_autoneg_adv_reg = mii_autoneg_adv_reg;
374 hw->mii_1000t_ctrl_reg = mii_1000t_ctrl_reg;
375
376 ret_val = atl1e_write_phy_reg(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
377 if (ret_val)
378 return ret_val;
379
380 if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
381 ret_val = atl1e_write_phy_reg(hw, MII_AT001_CR,
382 mii_1000t_ctrl_reg);
383 if (ret_val)
384 return ret_val;
385 }
386
387 return 0;
388}
389
390
391/*
392 * Resets the PHY and make all config validate
393 *
394 * hw - Struct containing variables accessed by shared code
395 *
396 * Sets bit 15 and 12 of the MII control regiser (for F001 bug)
397 */
398int atl1e_phy_commit(struct atl1e_hw *hw)
399{
400 struct atl1e_adapter *adapter = (struct atl1e_adapter *)hw->adapter;
401 struct pci_dev *pdev = adapter->pdev;
402 int ret_val;
403 u16 phy_data;
404
405 phy_data = MII_CR_RESET | MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG;
406
407 ret_val = atl1e_write_phy_reg(hw, MII_BMCR, phy_data);
408 if (ret_val) {
409 u32 val;
410 int i;
411 /**************************************
412 * pcie serdes link may be down !
413 **************************************/
414 for (i = 0; i < 25; i++) {
415 msleep(1);
416 val = AT_READ_REG(hw, REG_MDIO_CTRL);
417 if (!(val & (MDIO_START | MDIO_BUSY)))
418 break;
419 }
420
421 if (0 != (val & (MDIO_START | MDIO_BUSY))) {
422 dev_err(&pdev->dev,
423 "pcie linkdown at least for 25ms\n");
424 return ret_val;
425 }
426
427 dev_err(&pdev->dev, "pcie linkup after %d ms\n", i);
428 }
429 return 0;
430}
431
432int atl1e_phy_init(struct atl1e_hw *hw)
433{
434 struct atl1e_adapter *adapter = (struct atl1e_adapter *)hw->adapter;
435 struct pci_dev *pdev = adapter->pdev;
436 s32 ret_val;
437 u16 phy_val;
438
439 if (hw->phy_configured) {
440 if (hw->re_autoneg) {
441 hw->re_autoneg = false;
442 return atl1e_restart_autoneg(hw);
443 }
444 return 0;
445 }
446
447 /* RESET GPHY Core */
448 AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT);
449 msleep(2);
450 AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT |
451 GPHY_CTRL_EXT_RESET);
452 msleep(2);
453
454 /* patches */
455 /* p1. eable hibernation mode */
456 ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0xB);
457 if (ret_val)
458 return ret_val;
459 ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0xBC00);
460 if (ret_val)
461 return ret_val;
462 /* p2. set Class A/B for all modes */
463 ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0);
464 if (ret_val)
465 return ret_val;
466 phy_val = 0x02ef;
467 /* remove Class AB */
468 /* phy_val = hw->emi_ca ? 0x02ef : 0x02df; */
469 ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, phy_val);
470 if (ret_val)
471 return ret_val;
472 /* p3. 10B ??? */
473 ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x12);
474 if (ret_val)
475 return ret_val;
476 ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x4C04);
477 if (ret_val)
478 return ret_val;
479 /* p4. 1000T power */
480 ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x4);
481 if (ret_val)
482 return ret_val;
483 ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x8BBB);
484 if (ret_val)
485 return ret_val;
486
487 ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x5);
488 if (ret_val)
489 return ret_val;
490 ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x2C46);
491 if (ret_val)
492 return ret_val;
493
494 msleep(1);
495
496 /*Enable PHY LinkChange Interrupt */
497 ret_val = atl1e_write_phy_reg(hw, MII_INT_CTRL, 0xC00);
498 if (ret_val) {
499 dev_err(&pdev->dev, "Error enable PHY linkChange Interrupt\n");
500 return ret_val;
501 }
502 /* setup AutoNeg parameters */
503 ret_val = atl1e_phy_setup_autoneg_adv(hw);
504 if (ret_val) {
505 dev_err(&pdev->dev, "Error Setting up Auto-Negotiation\n");
506 return ret_val;
507 }
508 /* SW.Reset & En-Auto-Neg to restart Auto-Neg*/
509 dev_dbg(&pdev->dev, "Restarting Auto-Neg");
510 ret_val = atl1e_phy_commit(hw);
511 if (ret_val) {
512 dev_err(&pdev->dev, "Error Resetting the phy");
513 return ret_val;
514 }
515
516 hw->phy_configured = true;
517
518 return 0;
519}
520
521/*
522 * Reset the transmit and receive units; mask and clear all interrupts.
523 * hw - Struct containing variables accessed by shared code
524 * return : 0 or idle status (if error)
525 */
526int atl1e_reset_hw(struct atl1e_hw *hw)
527{
528 struct atl1e_adapter *adapter = (struct atl1e_adapter *)hw->adapter;
529 struct pci_dev *pdev = adapter->pdev;
530
531 u32 idle_status_data = 0;
532 u16 pci_cfg_cmd_word = 0;
533 int timeout = 0;
534
535 /* Workaround for PCI problem when BIOS sets MMRBC incorrectly. */
536 pci_read_config_word(pdev, PCI_REG_COMMAND, &pci_cfg_cmd_word);
537 if ((pci_cfg_cmd_word & (CMD_IO_SPACE |
538 CMD_MEMORY_SPACE | CMD_BUS_MASTER))
539 != (CMD_IO_SPACE | CMD_MEMORY_SPACE | CMD_BUS_MASTER)) {
540 pci_cfg_cmd_word |= (CMD_IO_SPACE |
541 CMD_MEMORY_SPACE | CMD_BUS_MASTER);
542 pci_write_config_word(pdev, PCI_REG_COMMAND, pci_cfg_cmd_word);
543 }
544
545 /*
546 * Issue Soft Reset to the MAC. This will reset the chip's
547 * transmit, receive, DMA. It will not effect
548 * the current PCI configuration. The global reset bit is self-
549 * clearing, and should clear within a microsecond.
550 */
551 AT_WRITE_REG(hw, REG_MASTER_CTRL,
552 MASTER_CTRL_LED_MODE | MASTER_CTRL_SOFT_RST);
553 wmb();
554 msleep(1);
555
556 /* Wait at least 10ms for All module to be Idle */
557 for (timeout = 0; timeout < AT_HW_MAX_IDLE_DELAY; timeout++) {
558 idle_status_data = AT_READ_REG(hw, REG_IDLE_STATUS);
559 if (idle_status_data == 0)
560 break;
561 msleep(1);
562 cpu_relax();
563 }
564
565 if (timeout >= AT_HW_MAX_IDLE_DELAY) {
566 dev_err(&pdev->dev,
567 "MAC state machine cann't be idle since"
568 " disabled for 10ms second\n");
569 return AT_ERR_TIMEOUT;
570 }
571
572 return 0;
573}
574
575
576/*
577 * Performs basic configuration of the adapter.
578 *
579 * hw - Struct containing variables accessed by shared code
580 * Assumes that the controller has previously been reset and is in a
581 * post-reset uninitialized state. Initializes multicast table,
582 * and Calls routines to setup link
583 * Leaves the transmit and receive units disabled and uninitialized.
584 */
585int atl1e_init_hw(struct atl1e_hw *hw)
586{
587 s32 ret_val = 0;
588
589 atl1e_init_pcie(hw);
590
591 /* Zero out the Multicast HASH table */
592 /* clear the old settings from the multicast hash table */
593 AT_WRITE_REG(hw, REG_RX_HASH_TABLE, 0);
594 AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, 1, 0);
595
596 ret_val = atl1e_phy_init(hw);
597
598 return ret_val;
599}
600
601/*
602 * Detects the current speed and duplex settings of the hardware.
603 *
604 * hw - Struct containing variables accessed by shared code
605 * speed - Speed of the connection
606 * duplex - Duplex setting of the connection
607 */
608int atl1e_get_speed_and_duplex(struct atl1e_hw *hw, u16 *speed, u16 *duplex)
609{
610 int err;
611 u16 phy_data;
612
613 /* Read PHY Specific Status Register (17) */
614 err = atl1e_read_phy_reg(hw, MII_AT001_PSSR, &phy_data);
615 if (err)
616 return err;
617
618 if (!(phy_data & MII_AT001_PSSR_SPD_DPLX_RESOLVED))
619 return AT_ERR_PHY_RES;
620
621 switch (phy_data & MII_AT001_PSSR_SPEED) {
622 case MII_AT001_PSSR_1000MBS:
623 *speed = SPEED_1000;
624 break;
625 case MII_AT001_PSSR_100MBS:
626 *speed = SPEED_100;
627 break;
628 case MII_AT001_PSSR_10MBS:
629 *speed = SPEED_10;
630 break;
631 default:
632 return AT_ERR_PHY_SPEED;
633 break;
634 }
635
636 if (phy_data & MII_AT001_PSSR_DPLX)
637 *duplex = FULL_DUPLEX;
638 else
639 *duplex = HALF_DUPLEX;
640
641 return 0;
642}
643
644int atl1e_restart_autoneg(struct atl1e_hw *hw)
645{
646 int err = 0;
647
648 err = atl1e_write_phy_reg(hw, MII_ADVERTISE, hw->mii_autoneg_adv_reg);
649 if (err)
650 return err;
651
652 if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
653 err = atl1e_write_phy_reg(hw, MII_AT001_CR,
654 hw->mii_1000t_ctrl_reg);
655 if (err)
656 return err;
657 }
658
659 err = atl1e_write_phy_reg(hw, MII_BMCR,
660 MII_CR_RESET | MII_CR_AUTO_NEG_EN |
661 MII_CR_RESTART_AUTO_NEG);
662 return err;
663}
664