3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright * 2005 Agere Systems Inc.
9 *------------------------------------------------------------------------------
11 * et1310_phy.c - Routines for configuring and accessing the PHY
13 *------------------------------------------------------------------------------
17 * This software is provided subject to the following terms and conditions,
18 * which you should read carefully before using the software. Using this
19 * software indicates your acceptance of these terms and conditions. If you do
20 * not agree with these terms and conditions, do not use the software.
22 * Copyright * 2005 Agere Systems Inc.
23 * All rights reserved.
25 * Redistribution and use in source or binary forms, with or without
26 * modifications, are permitted provided that the following conditions are met:
28 * . Redistributions of source code must retain the above copyright notice, this
29 * list of conditions and the following Disclaimer as comments in the code as
30 * well as in the documentation and/or other materials provided with the
33 * . Redistributions in binary form must reproduce the above copyright notice,
34 * this list of conditions and the following Disclaimer in the documentation
35 * and/or other materials provided with the distribution.
37 * . Neither the name of Agere Systems Inc. nor the names of the contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
45 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
46 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
47 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
48 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
58 #include "et131x_version.h"
59 #include "et131x_defs.h"
61 #include <linux/pci.h>
62 #include <linux/init.h>
63 #include <linux/module.h>
64 #include <linux/types.h>
65 #include <linux/kernel.h>
67 #include <linux/sched.h>
68 #include <linux/ptrace.h>
69 #include <linux/slab.h>
70 #include <linux/ctype.h>
71 #include <linux/string.h>
72 #include <linux/timer.h>
73 #include <linux/interrupt.h>
75 #include <linux/delay.h>
77 #include <linux/bitops.h>
78 #include <asm/system.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
83 #include <linux/if_arp.h>
84 #include <linux/ioport.h>
85 #include <linux/random.h>
87 #include "et1310_phy.h"
88 #include "et1310_pm.h"
89 #include "et1310_jagcore.h"
91 #include "et131x_adapter.h"
92 #include "et131x_netdev.h"
93 #include "et131x_initpci.h"
95 #include "et1310_address_map.h"
96 #include "et1310_tx.h"
97 #include "et1310_rx.h"
98 #include "et1310_mac.h"
100 /* Prototypes for functions with local scope */
101 static int et131x_xcvr_init(struct et131x_adapter
*adapter
);
104 * PhyMiRead - Read from the PHY through the MII Interface on the MAC
105 * @adapter: pointer to our private adapter structure
106 * @xcvrAddr: the address of the transciever
107 * @xcvrReg: the register to read
108 * @value: pointer to a 16-bit value in which the value will be stored
110 * Returns 0 on success, errno on failure (as defined in errno.h)
112 int PhyMiRead(struct et131x_adapter
*adapter
, uint8_t xcvrAddr
,
113 uint8_t xcvrReg
, uint16_t *value
)
115 struct _MAC_t __iomem
*mac
= &adapter
->regs
->mac
;
118 MII_MGMT_ADDR_t miiAddr
;
119 MII_MGMT_CMD_t miiCmd
;
120 MII_MGMT_INDICATOR_t miiIndicator
;
122 /* Save a local copy of the registers we are dealing with so we can
125 miiAddr
.value
= readl(&mac
->mii_mgmt_addr
.value
);
126 miiCmd
.value
= readl(&mac
->mii_mgmt_cmd
.value
);
128 /* Stop the current operation */
129 writel(0, &mac
->mii_mgmt_cmd
.value
);
131 /* Set up the register we need to read from on the correct PHY */
133 MII_MGMT_ADDR_t mii_mgmt_addr
= { 0 };
135 mii_mgmt_addr
.bits
.phy_addr
= xcvrAddr
;
136 mii_mgmt_addr
.bits
.reg_addr
= xcvrReg
;
137 writel(mii_mgmt_addr
.value
, &mac
->mii_mgmt_addr
.value
);
140 /* Kick the read cycle off */
143 writel(0x1, &mac
->mii_mgmt_cmd
.value
);
148 miiIndicator
.value
= readl(&mac
->mii_mgmt_indicator
.value
);
149 } while ((miiIndicator
.bits
.not_valid
|| miiIndicator
.bits
.busy
) &&
152 /* If we hit the max delay, we could not read the register */
154 dev_warn(&adapter
->pdev
->dev
,
155 "xcvrReg 0x%08x could not be read\n", xcvrReg
);
156 dev_warn(&adapter
->pdev
->dev
, "status is 0x%08x\n",
162 /* If we hit here we were able to read the register and we need to
163 * return the value to the caller
165 /* TODO: make this stuff a simple readw()?! */
167 MII_MGMT_STAT_t mii_mgmt_stat
;
169 mii_mgmt_stat
.value
= readl(&mac
->mii_mgmt_stat
.value
);
170 *value
= (uint16_t) mii_mgmt_stat
.bits
.phy_stat
;
173 /* Stop the read operation */
174 writel(0, &mac
->mii_mgmt_cmd
.value
);
176 /* set the registers we touched back to the state at which we entered
179 writel(miiAddr
.value
, &mac
->mii_mgmt_addr
.value
);
180 writel(miiCmd
.value
, &mac
->mii_mgmt_cmd
.value
);
186 * MiWrite - Write to a PHY register through the MII interface of the MAC
187 * @adapter: pointer to our private adapter structure
188 * @xcvrReg: the register to read
189 * @value: 16-bit value to write
191 * Return 0 on success, errno on failure (as defined in errno.h)
193 int MiWrite(struct et131x_adapter
*adapter
, uint8_t xcvrReg
, uint16_t value
)
195 struct _MAC_t __iomem
*mac
= &adapter
->regs
->mac
;
197 uint8_t xcvrAddr
= adapter
->Stats
.xcvr_addr
;
199 MII_MGMT_ADDR_t miiAddr
;
200 MII_MGMT_CMD_t miiCmd
;
201 MII_MGMT_INDICATOR_t miiIndicator
;
203 /* Save a local copy of the registers we are dealing with so we can
206 miiAddr
.value
= readl(&mac
->mii_mgmt_addr
.value
);
207 miiCmd
.value
= readl(&mac
->mii_mgmt_cmd
.value
);
209 /* Stop the current operation */
210 writel(0, &mac
->mii_mgmt_cmd
.value
);
212 /* Set up the register we need to write to on the correct PHY */
214 MII_MGMT_ADDR_t mii_mgmt_addr
;
216 mii_mgmt_addr
.bits
.phy_addr
= xcvrAddr
;
217 mii_mgmt_addr
.bits
.reg_addr
= xcvrReg
;
218 writel(mii_mgmt_addr
.value
, &mac
->mii_mgmt_addr
.value
);
221 /* Add the value to write to the registers to the mac */
222 writel(value
, &mac
->mii_mgmt_ctrl
.value
);
228 miiIndicator
.value
= readl(&mac
->mii_mgmt_indicator
.value
);
229 } while (miiIndicator
.bits
.busy
&& delay
< 100);
231 /* If we hit the max delay, we could not write the register */
235 dev_warn(&adapter
->pdev
->dev
,
236 "xcvrReg 0x%08x could not be written", xcvrReg
);
237 dev_warn(&adapter
->pdev
->dev
, "status is 0x%08x\n",
239 dev_warn(&adapter
->pdev
->dev
, "command is 0x%08x\n",
240 readl(&mac
->mii_mgmt_cmd
.value
));
242 MiRead(adapter
, xcvrReg
, &TempValue
);
247 /* Stop the write operation */
248 writel(0, &mac
->mii_mgmt_cmd
.value
);
250 /* set the registers we touched back to the state at which we entered
253 writel(miiAddr
.value
, &mac
->mii_mgmt_addr
.value
);
254 writel(miiCmd
.value
, &mac
->mii_mgmt_cmd
.value
);
260 * et131x_xcvr_find - Find the PHY ID
261 * @adapter: pointer to our private adapter structure
263 * Returns 0 on success, errno on failure (as defined in errno.h)
265 int et131x_xcvr_find(struct et131x_adapter
*adapter
)
267 int status
= -ENODEV
;
273 /* We need to get xcvr id and address we just get the first one */
274 for (xcvr_addr
= 0; xcvr_addr
< 32; xcvr_addr
++) {
275 /* Read the ID from the PHY */
276 PhyMiRead(adapter
, xcvr_addr
,
277 (uint8_t) offsetof(MI_REGS_t
, idr1
),
279 PhyMiRead(adapter
, xcvr_addr
,
280 (uint8_t) offsetof(MI_REGS_t
, idr2
),
283 xcvr_id
= (uint32_t) ((idr1
.value
<< 16) | idr2
.value
);
285 if ((idr1
.value
!= 0) && (idr1
.value
!= 0xffff)) {
286 adapter
->Stats
.xcvr_id
= xcvr_id
;
287 adapter
->Stats
.xcvr_addr
= xcvr_addr
;
297 * et131x_setphy_normal - Set PHY for normal operation.
298 * @adapter: pointer to our private adapter structure
300 * Used by Power Management to force the PHY into 10 Base T half-duplex mode,
301 * when going to D3 in WOL mode. Also used during initialization to set the
302 * PHY for normal operation.
304 int et131x_setphy_normal(struct et131x_adapter
*adapter
)
308 /* Make sure the PHY is powered up */
309 ET1310_PhyPowerDown(adapter
, 0);
310 status
= et131x_xcvr_init(adapter
);
315 * et131x_xcvr_init - Init the phy if we are setting it into force mode
316 * @adapter: pointer to our private adapter structure
318 * Returns 0 on success, errno on failure (as defined in errno.h)
320 static int et131x_xcvr_init(struct et131x_adapter
*adapter
)
327 /* Zero out the adapter structure variable representing BMSR */
328 adapter
->Bmsr
.value
= 0;
330 MiRead(adapter
, (uint8_t) offsetof(MI_REGS_t
, isr
), &isr
.value
);
332 MiRead(adapter
, (uint8_t) offsetof(MI_REGS_t
, imr
), &imr
.value
);
334 /* Set the link status interrupt only. Bad behavior when link status
335 * and auto neg are set, we run into a nested interrupt problem
337 imr
.bits
.int_en
= 0x1;
338 imr
.bits
.link_status
= 0x1;
339 imr
.bits
.autoneg_status
= 0x1;
341 MiWrite(adapter
, (uint8_t) offsetof(MI_REGS_t
, imr
), imr
.value
);
343 /* Set the LED behavior such that LED 1 indicates speed (off =
344 * 10Mbits, blink = 100Mbits, on = 1000Mbits) and LED 2 indicates
345 * link and activity (on for link, blink off for activity).
347 * NOTE: Some customizations have been added here for specific
348 * vendors; The LED behavior is now determined by vendor data in the
349 * EEPROM. However, the above description is the default.
351 if ((adapter
->eepromData
[1] & 0x4) == 0) {
352 MiRead(adapter
, (uint8_t) offsetof(MI_REGS_t
, lcr2
),
354 if ((adapter
->eepromData
[1] & 0x8) == 0)
355 lcr2
.bits
.led_tx_rx
= 0x3;
357 lcr2
.bits
.led_tx_rx
= 0x4;
358 lcr2
.bits
.led_link
= 0xa;
359 MiWrite(adapter
, (uint8_t) offsetof(MI_REGS_t
, lcr2
),
363 /* Determine if we need to go into a force mode and set it */
364 if (adapter
->AiForceSpeed
== 0 && adapter
->AiForceDpx
== 0) {
365 if ((adapter
->RegistryFlowControl
== TxOnly
) ||
366 (adapter
->RegistryFlowControl
== Both
)) {
367 ET1310_PhyAccessMiBit(adapter
,
368 TRUEPHY_BIT_SET
, 4, 11, NULL
);
370 ET1310_PhyAccessMiBit(adapter
,
371 TRUEPHY_BIT_CLEAR
, 4, 11, NULL
);
374 if (adapter
->RegistryFlowControl
== Both
) {
375 ET1310_PhyAccessMiBit(adapter
,
376 TRUEPHY_BIT_SET
, 4, 10, NULL
);
378 ET1310_PhyAccessMiBit(adapter
,
379 TRUEPHY_BIT_CLEAR
, 4, 10, NULL
);
382 /* Set the phy to autonegotiation */
383 ET1310_PhyAutoNeg(adapter
, true);
385 /* NOTE - Do we need this? */
386 ET1310_PhyAccessMiBit(adapter
, TRUEPHY_BIT_SET
, 0, 9, NULL
);
389 ET1310_PhyAutoNeg(adapter
, false);
391 /* Set to the correct force mode. */
392 if (adapter
->AiForceDpx
!= 1) {
393 if ((adapter
->RegistryFlowControl
== TxOnly
) ||
394 (adapter
->RegistryFlowControl
== Both
)) {
395 ET1310_PhyAccessMiBit(adapter
,
396 TRUEPHY_BIT_SET
, 4, 11,
399 ET1310_PhyAccessMiBit(adapter
,
400 TRUEPHY_BIT_CLEAR
, 4, 11,
404 if (adapter
->RegistryFlowControl
== Both
) {
405 ET1310_PhyAccessMiBit(adapter
,
406 TRUEPHY_BIT_SET
, 4, 10,
409 ET1310_PhyAccessMiBit(adapter
,
410 TRUEPHY_BIT_CLEAR
, 4, 10,
414 ET1310_PhyAccessMiBit(adapter
,
415 TRUEPHY_BIT_CLEAR
, 4, 10, NULL
);
416 ET1310_PhyAccessMiBit(adapter
,
417 TRUEPHY_BIT_CLEAR
, 4, 11, NULL
);
420 switch (adapter
->AiForceSpeed
) {
422 if (adapter
->AiForceDpx
== 1)
423 TPAL_SetPhy10HalfDuplex(adapter
);
424 else if (adapter
->AiForceDpx
== 2)
425 TPAL_SetPhy10FullDuplex(adapter
);
427 TPAL_SetPhy10Force(adapter
);
430 if (adapter
->AiForceDpx
== 1)
431 TPAL_SetPhy100HalfDuplex(adapter
);
432 else if (adapter
->AiForceDpx
== 2)
433 TPAL_SetPhy100FullDuplex(adapter
);
435 TPAL_SetPhy100Force(adapter
);
438 TPAL_SetPhy1000FullDuplex(adapter
);
446 void et131x_Mii_check(struct et131x_adapter
*etdev
,
447 MI_BMSR_t bmsr
, MI_BMSR_t bmsr_ints
)
450 uint32_t autoneg_status
;
454 uint32_t masterslave
;
458 if (bmsr_ints
.bits
.link_status
) {
459 if (bmsr
.bits
.link_status
) {
460 etdev
->PoMgmt
.TransPhyComaModeOnBoot
= 20;
462 /* Update our state variables and indicate the
465 spin_lock_irqsave(&etdev
->Lock
, flags
);
467 etdev
->MediaState
= NETIF_STATUS_MEDIA_CONNECT
;
468 etdev
->Flags
&= ~fMP_ADAPTER_LINK_DETECTION
;
470 spin_unlock_irqrestore(&etdev
->Lock
, flags
);
472 /* Don't indicate state if we're in loopback mode */
473 if (etdev
->RegistryPhyLoopbk
== false)
474 netif_carrier_on(etdev
->netdev
);
476 dev_warn(&etdev
->pdev
->dev
,
477 "Link down - cable problem ?\n");
479 if (etdev
->linkspeed
== TRUEPHY_SPEED_10MBPS
) {
480 /* NOTE - Is there a way to query this without
482 * && TRU_QueryCoreType(etdev->hTruePhy, 0) == EMI_TRUEPHY_A13O) {
486 MiRead(etdev
, 0x12, &Register18
);
487 MiWrite(etdev
, 0x12, Register18
| 0x4);
488 MiWrite(etdev
, 0x10, Register18
| 0x8402);
489 MiWrite(etdev
, 0x11, Register18
| 511);
490 MiWrite(etdev
, 0x12, Register18
);
493 /* For the first N seconds of life, we are in "link
494 * detection" When we are in this state, we should
495 * only report "connected". When the LinkDetection
496 * Timer expires, we can report disconnected (handled
497 * in the LinkDetectionDPC).
499 if (!(etdev
->Flags
& fMP_ADAPTER_LINK_DETECTION
) ||
500 (etdev
->MediaState
== NETIF_STATUS_MEDIA_DISCONNECT
)) {
501 spin_lock_irqsave(&etdev
->Lock
, flags
);
503 NETIF_STATUS_MEDIA_DISCONNECT
;
504 spin_unlock_irqrestore(&etdev
->Lock
,
507 /* Only indicate state if we're in loopback
510 if (etdev
->RegistryPhyLoopbk
== false)
511 netif_carrier_off(etdev
->netdev
);
514 etdev
->linkspeed
= 0;
515 etdev
->duplex_mode
= 0;
517 /* Free the packets being actively sent & stopped */
518 et131x_free_busy_send_packets(etdev
);
520 /* Re-initialize the send structures */
521 et131x_init_send(etdev
);
523 /* Reset the RFD list and re-start RU */
524 et131x_reset_recv(etdev
);
527 * Bring the device back to the state it was during
528 * init prior to autonegotiation being complete. This
529 * way, when we get the auto-neg complete interrupt,
530 * we can complete init by calling ConfigMacREGS2.
532 et131x_soft_reset(etdev
);
534 /* Setup ET1310 as per the documentation */
535 et131x_adapter_setup(etdev
);
537 /* Setup the PHY into coma mode until the cable is
540 if (etdev
->RegistryPhyComa
== 1)
541 EnablePhyComa(etdev
);
545 if (bmsr_ints
.bits
.auto_neg_complete
||
546 (etdev
->AiForceDpx
== 3 && bmsr_ints
.bits
.link_status
)) {
547 if (bmsr
.bits
.auto_neg_complete
|| etdev
->AiForceDpx
== 3) {
548 ET1310_PhyLinkStatus(etdev
,
549 &link_status
, &autoneg_status
,
550 &speed
, &duplex
, &mdi_mdix
,
551 &masterslave
, &polarity
);
553 etdev
->linkspeed
= speed
;
554 etdev
->duplex_mode
= duplex
;
556 etdev
->PoMgmt
.TransPhyComaModeOnBoot
= 20;
558 if (etdev
->linkspeed
== TRUEPHY_SPEED_10MBPS
) {
560 * NOTE - Is there a way to query this without
562 * && TRU_QueryCoreType(etdev->hTruePhy, 0)== EMI_TRUEPHY_A13O) {
566 MiRead(etdev
, 0x12, &Register18
);
567 MiWrite(etdev
, 0x12, Register18
| 0x4);
568 MiWrite(etdev
, 0x10, Register18
| 0x8402);
569 MiWrite(etdev
, 0x11, Register18
| 511);
570 MiWrite(etdev
, 0x12, Register18
);
573 ConfigFlowControl(etdev
);
575 if (etdev
->linkspeed
== TRUEPHY_SPEED_1000MBPS
&&
576 etdev
->RegistryJumboPacket
> 2048)
577 ET1310_PhyAndOrReg(etdev
, 0x16, 0xcfff,
580 SetRxDmaTimer(etdev
);
581 ConfigMACRegs2(etdev
);
587 * TPAL_SetPhy10HalfDuplex - Force the phy into 10 Base T Half Duplex mode.
588 * @etdev: pointer to the adapter structure
590 * Also sets the MAC so it is syncd up properly
592 void TPAL_SetPhy10HalfDuplex(struct et131x_adapter
*etdev
)
595 ET1310_PhyPowerDown(etdev
, 1);
597 /* First we need to turn off all other advertisement */
598 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
600 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
602 /* Set our advertise values accordingly */
603 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_HALF
);
606 ET1310_PhyPowerDown(etdev
, 0);
610 * TPAL_SetPhy10FullDuplex - Force the phy into 10 Base T Full Duplex mode.
611 * @etdev: pointer to the adapter structure
613 * Also sets the MAC so it is syncd up properly
615 void TPAL_SetPhy10FullDuplex(struct et131x_adapter
*etdev
)
618 ET1310_PhyPowerDown(etdev
, 1);
620 /* First we need to turn off all other advertisement */
621 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
623 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
625 /* Set our advertise values accordingly */
626 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_FULL
);
629 ET1310_PhyPowerDown(etdev
, 0);
633 * TPAL_SetPhy10Force - Force Base-T FD mode WITHOUT using autonegotiation
634 * @etdev: pointer to the adapter structure
636 void TPAL_SetPhy10Force(struct et131x_adapter
*etdev
)
639 ET1310_PhyPowerDown(etdev
, 1);
641 /* Disable autoneg */
642 ET1310_PhyAutoNeg(etdev
, false);
644 /* Disable all advertisement */
645 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
646 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
647 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
650 ET1310_PhySpeedSelect(etdev
, TRUEPHY_SPEED_10MBPS
);
652 /* Force Full duplex */
653 ET1310_PhyDuplexMode(etdev
, TRUEPHY_DUPLEX_FULL
);
656 ET1310_PhyPowerDown(etdev
, 0);
660 * TPAL_SetPhy100HalfDuplex - Force 100 Base T Half Duplex mode.
661 * @etdev: pointer to the adapter structure
663 * Also sets the MAC so it is syncd up properly.
665 void TPAL_SetPhy100HalfDuplex(struct et131x_adapter
*etdev
)
668 ET1310_PhyPowerDown(etdev
, 1);
670 /* first we need to turn off all other advertisement */
671 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
673 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
675 /* Set our advertise values accordingly */
676 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_HALF
);
679 ET1310_PhySpeedSelect(etdev
, TRUEPHY_SPEED_100MBPS
);
682 ET1310_PhyPowerDown(etdev
, 0);
686 * TPAL_SetPhy100FullDuplex - Force 100 Base T Full Duplex mode.
687 * @etdev: pointer to the adapter structure
689 * Also sets the MAC so it is syncd up properly
691 void TPAL_SetPhy100FullDuplex(struct et131x_adapter
*etdev
)
694 ET1310_PhyPowerDown(etdev
, 1);
696 /* First we need to turn off all other advertisement */
697 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
699 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
701 /* Set our advertise values accordingly */
702 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_FULL
);
705 ET1310_PhyPowerDown(etdev
, 0);
709 * TPAL_SetPhy100Force - Force 100 BaseT FD mode WITHOUT using autonegotiation
710 * @etdev: pointer to the adapter structure
712 void TPAL_SetPhy100Force(struct et131x_adapter
*etdev
)
715 ET1310_PhyPowerDown(etdev
, 1);
717 /* Disable autoneg */
718 ET1310_PhyAutoNeg(etdev
, false);
720 /* Disable all advertisement */
721 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
722 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
723 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
726 ET1310_PhySpeedSelect(etdev
, TRUEPHY_SPEED_100MBPS
);
728 /* Force Full duplex */
729 ET1310_PhyDuplexMode(etdev
, TRUEPHY_DUPLEX_FULL
);
732 ET1310_PhyPowerDown(etdev
, 0);
736 * TPAL_SetPhy1000FullDuplex - Force 1000 Base T Full Duplex mode
737 * @etdev: pointer to the adapter structure
739 * Also sets the MAC so it is syncd up properly.
741 void TPAL_SetPhy1000FullDuplex(struct et131x_adapter
*etdev
)
744 ET1310_PhyPowerDown(etdev
, 1);
746 /* first we need to turn off all other advertisement */
747 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
749 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
751 /* set our advertise values accordingly */
752 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_FULL
);
755 ET1310_PhyPowerDown(etdev
, 0);
759 * TPAL_SetPhyAutoNeg - Set phy to autonegotiation mode.
760 * @etdev: pointer to the adapter structure
762 void TPAL_SetPhyAutoNeg(struct et131x_adapter
*etdev
)
765 ET1310_PhyPowerDown(etdev
, 1);
767 /* Turn on advertisement of all capabilities */
768 ET1310_PhyAdvertise10BaseT(etdev
, TRUEPHY_ADV_DUPLEX_BOTH
);
770 ET1310_PhyAdvertise100BaseT(etdev
, TRUEPHY_ADV_DUPLEX_BOTH
);
772 if (etdev
->pdev
->device
!= ET131X_PCI_DEVICE_ID_FAST
)
773 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_FULL
);
775 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
777 /* Make sure auto-neg is ON (it is disabled in FORCE modes) */
778 ET1310_PhyAutoNeg(etdev
, true);
781 ET1310_PhyPowerDown(etdev
, 0);
786 * The routines which follow provide low-level access to the PHY, and are used
787 * primarily by the routines above (although there are a few places elsewhere
788 * in the driver where this level of access is required).
791 static const uint16_t ConfigPhy
[25][2] = {
792 /* Reg Value Register */
794 {0x880B, 0x0926}, /* AfeIfCreg4B1000Msbs */
795 {0x880C, 0x0926}, /* AfeIfCreg4B100Msbs */
796 {0x880D, 0x0926}, /* AfeIfCreg4B10Msbs */
798 {0x880E, 0xB4D3}, /* AfeIfCreg4B1000Lsbs */
799 {0x880F, 0xB4D3}, /* AfeIfCreg4B100Lsbs */
800 {0x8810, 0xB4D3}, /* AfeIfCreg4B10Lsbs */
802 {0x8805, 0xB03E}, /* AfeIfCreg3B1000Msbs */
803 {0x8806, 0xB03E}, /* AfeIfCreg3B100Msbs */
804 {0x8807, 0xFF00}, /* AfeIfCreg3B10Msbs */
806 {0x8808, 0xE090}, /* AfeIfCreg3B1000Lsbs */
807 {0x8809, 0xE110}, /* AfeIfCreg3B100Lsbs */
808 {0x880A, 0x0000}, /* AfeIfCreg3B10Lsbs */
810 {0x300D, 1}, /* DisableNorm */
812 {0x280C, 0x0180}, /* LinkHoldEnd */
814 {0x1C21, 0x0002}, /* AlphaM */
816 {0x3821, 6}, /* FfeLkgTx0 */
817 {0x381D, 1}, /* FfeLkg1g4 */
818 {0x381E, 1}, /* FfeLkg1g5 */
819 {0x381F, 1}, /* FfeLkg1g6 */
820 {0x3820, 1}, /* FfeLkg1g7 */
822 {0x8402, 0x01F0}, /* Btinact */
823 {0x800E, 20}, /* LftrainTime */
824 {0x800F, 24}, /* DvguardTime */
825 {0x8010, 46}, /* IdlguardTime */
831 /* condensed version of the phy initialization routine */
832 void ET1310_PhyInit(struct et131x_adapter
*etdev
)
834 uint16_t data
, index
;
839 /* get the identity (again ?) */
840 MiRead(etdev
, PHY_ID_1
, &data
);
841 MiRead(etdev
, PHY_ID_2
, &data
);
843 /* what does this do/achieve ? */
844 MiRead(etdev
, PHY_MPHY_CONTROL_REG
, &data
); /* should read 0002 */
845 MiWrite(etdev
, PHY_MPHY_CONTROL_REG
, 0x0006);
847 /* read modem register 0402, should I do something with the return
849 MiWrite(etdev
, PHY_INDEX_REG
, 0x0402);
850 MiRead(etdev
, PHY_DATA_REG
, &data
);
852 /* what does this do/achieve ? */
853 MiWrite(etdev
, PHY_MPHY_CONTROL_REG
, 0x0002);
855 /* get the identity (again ?) */
856 MiRead(etdev
, PHY_ID_1
, &data
);
857 MiRead(etdev
, PHY_ID_2
, &data
);
859 /* what does this achieve ? */
860 MiRead(etdev
, PHY_MPHY_CONTROL_REG
, &data
); /* should read 0002 */
861 MiWrite(etdev
, PHY_MPHY_CONTROL_REG
, 0x0006);
863 /* read modem register 0402, should I do something with
865 MiWrite(etdev
, PHY_INDEX_REG
, 0x0402);
866 MiRead(etdev
, PHY_DATA_REG
, &data
);
868 MiWrite(etdev
, PHY_MPHY_CONTROL_REG
, 0x0002);
870 /* what does this achieve (should return 0x1040) */
871 MiRead(etdev
, PHY_CONTROL
, &data
);
872 MiRead(etdev
, PHY_MPHY_CONTROL_REG
, &data
); /* should read 0002 */
873 MiWrite(etdev
, PHY_CONTROL
, 0x1840);
875 MiWrite(etdev
, PHY_MPHY_CONTROL_REG
, 0x0007);
877 /* here the writing of the array starts.... */
879 while (ConfigPhy
[index
][0] != 0x0000) {
881 MiWrite(etdev
, PHY_INDEX_REG
, ConfigPhy
[index
][0]);
882 MiWrite(etdev
, PHY_DATA_REG
, ConfigPhy
[index
][1]);
885 MiWrite(etdev
, PHY_INDEX_REG
, ConfigPhy
[index
][0]);
886 MiRead(etdev
, PHY_DATA_REG
, &data
);
888 /* do a check on the value read back ? */
891 /* here the writing of the array ends... */
893 MiRead(etdev
, PHY_CONTROL
, &data
); /* 0x1840 */
894 MiRead(etdev
, PHY_MPHY_CONTROL_REG
, &data
);/* should read 0007 */
895 MiWrite(etdev
, PHY_CONTROL
, 0x1040);
896 MiWrite(etdev
, PHY_MPHY_CONTROL_REG
, 0x0002);
899 void ET1310_PhyReset(struct et131x_adapter
*etdev
)
901 MiWrite(etdev
, PHY_CONTROL
, 0x8000);
904 void ET1310_PhyPowerDown(struct et131x_adapter
*etdev
, bool down
)
908 MiRead(etdev
, PHY_CONTROL
, &data
);
913 MiWrite(etdev
, PHY_CONTROL
, data
);
917 MiWrite(etdev
, PHY_CONTROL
, data
);
921 void ET1310_PhyAutoNeg(struct et131x_adapter
*etdev
, bool enable
)
925 MiRead(etdev
, PHY_CONTROL
, &data
);
927 if (enable
== true) {
928 /* Autonegotiation ON */
930 MiWrite(etdev
, PHY_CONTROL
, data
);
932 /* Autonegotiation OFF */
934 MiWrite(etdev
, PHY_CONTROL
, data
);
938 void ET1310_PhyDuplexMode(struct et131x_adapter
*etdev
, uint16_t duplex
)
942 MiRead(etdev
, PHY_CONTROL
, &data
);
944 if (duplex
== TRUEPHY_DUPLEX_FULL
) {
945 /* Set Full Duplex */
947 MiWrite(etdev
, PHY_CONTROL
, data
);
949 /* Set Half Duplex */
951 MiWrite(etdev
, PHY_CONTROL
, data
);
955 void ET1310_PhySpeedSelect(struct et131x_adapter
*etdev
, uint16_t speed
)
959 /* Read the PHY control register */
960 MiRead(etdev
, PHY_CONTROL
, &data
);
962 /* Clear all Speed settings (Bits 6, 13) */
965 /* Reset the speed bits based on user selection */
967 case TRUEPHY_SPEED_10MBPS
:
968 /* Bits already cleared above, do nothing */
971 case TRUEPHY_SPEED_100MBPS
:
972 /* 100M == Set bit 13 */
976 case TRUEPHY_SPEED_1000MBPS
:
982 /* Write back the new speed */
983 MiWrite(etdev
, PHY_CONTROL
, data
);
986 void ET1310_PhyAdvertise1000BaseT(struct et131x_adapter
*etdev
,
991 /* Read the PHY 1000 Base-T Control Register */
992 MiRead(etdev
, PHY_1000_CONTROL
, &data
);
998 case TRUEPHY_ADV_DUPLEX_NONE
:
999 /* Duplex already cleared, do nothing */
1002 case TRUEPHY_ADV_DUPLEX_FULL
:
1007 case TRUEPHY_ADV_DUPLEX_HALF
:
1012 case TRUEPHY_ADV_DUPLEX_BOTH
:
1018 /* Write back advertisement */
1019 MiWrite(etdev
, PHY_1000_CONTROL
, data
);
1022 void ET1310_PhyAdvertise100BaseT(struct et131x_adapter
*etdev
,
1027 /* Read the Autonegotiation Register (10/100) */
1028 MiRead(etdev
, PHY_AUTO_ADVERTISEMENT
, &data
);
1030 /* Clear bits 7,8 */
1034 case TRUEPHY_ADV_DUPLEX_NONE
:
1035 /* Duplex already cleared, do nothing */
1038 case TRUEPHY_ADV_DUPLEX_FULL
:
1043 case TRUEPHY_ADV_DUPLEX_HALF
:
1048 case TRUEPHY_ADV_DUPLEX_BOTH
:
1055 /* Write back advertisement */
1056 MiWrite(etdev
, PHY_AUTO_ADVERTISEMENT
, data
);
1059 void ET1310_PhyAdvertise10BaseT(struct et131x_adapter
*etdev
,
1064 /* Read the Autonegotiation Register (10/100) */
1065 MiRead(etdev
, PHY_AUTO_ADVERTISEMENT
, &data
);
1067 /* Clear bits 5,6 */
1071 case TRUEPHY_ADV_DUPLEX_NONE
:
1072 /* Duplex already cleared, do nothing */
1075 case TRUEPHY_ADV_DUPLEX_FULL
:
1080 case TRUEPHY_ADV_DUPLEX_HALF
:
1085 case TRUEPHY_ADV_DUPLEX_BOTH
:
1092 /* Write back advertisement */
1093 MiWrite(etdev
, PHY_AUTO_ADVERTISEMENT
, data
);
1096 void ET1310_PhyLinkStatus(struct et131x_adapter
*etdev
,
1097 uint8_t *link_status
,
1099 uint32_t *linkspeed
,
1100 uint32_t *duplex_mode
,
1102 uint32_t *masterslave
, uint32_t *polarity
)
1104 uint16_t mistatus
= 0;
1105 uint16_t is1000BaseT
= 0;
1106 uint16_t vmi_phystatus
= 0;
1107 uint16_t control
= 0;
1109 MiRead(etdev
, PHY_STATUS
, &mistatus
);
1110 MiRead(etdev
, PHY_1000_STATUS
, &is1000BaseT
);
1111 MiRead(etdev
, PHY_PHY_STATUS
, &vmi_phystatus
);
1112 MiRead(etdev
, PHY_CONTROL
, &control
);
1116 (unsigned char)((vmi_phystatus
& 0x0040) ? 1 : 0);
1121 (control
& 0x1000) ? ((vmi_phystatus
& 0x0020) ?
1122 TRUEPHY_ANEG_COMPLETE
:
1123 TRUEPHY_ANEG_NOT_COMPLETE
) :
1124 TRUEPHY_ANEG_DISABLED
;
1128 *linkspeed
= (vmi_phystatus
& 0x0300) >> 8;
1131 *duplex_mode
= (vmi_phystatus
& 0x0080) >> 7;
1134 /* NOTE: Need to complete this */
1139 (is1000BaseT
& 0x4000) ? TRUEPHY_CFG_MASTER
:
1145 (vmi_phystatus
& 0x0400) ? TRUEPHY_POLARITY_INVERTED
:
1146 TRUEPHY_POLARITY_NORMAL
;
1150 void ET1310_PhyAndOrReg(struct et131x_adapter
*etdev
,
1151 uint16_t regnum
, uint16_t andMask
, uint16_t orMask
)
1155 /* Read the requested register */
1156 MiRead(etdev
, regnum
, ®
);
1158 /* Apply the AND mask */
1161 /* Apply the OR mask */
1164 /* Write the value back to the register */
1165 MiWrite(etdev
, regnum
, reg
);
1168 void ET1310_PhyAccessMiBit(struct et131x_adapter
*etdev
, uint16_t action
,
1169 uint16_t regnum
, uint16_t bitnum
, uint8_t *value
)
1174 /* Create a mask to isolate the requested bit */
1175 mask
= 0x0001 << bitnum
;
1177 /* Read the requested register */
1178 MiRead(etdev
, regnum
, ®
);
1181 case TRUEPHY_BIT_READ
:
1183 *value
= (reg
& mask
) >> bitnum
;
1186 case TRUEPHY_BIT_SET
:
1188 MiWrite(etdev
, regnum
, reg
);
1191 case TRUEPHY_BIT_CLEAR
:
1193 MiWrite(etdev
, regnum
, reg
);