2 * JMicron JMC2x0 series PCIe Ethernet Linux Device Driver
4 * Copyright 2008 JMicron Technology Corporation
5 * http://www.jmicron.com/
7 * Author: Guo-Fu Tseng <cooldavid@cooldavid.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/pci.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/ethtool.h>
30 #include <linux/mii.h>
31 #include <linux/crc32.h>
32 #include <linux/delay.h>
33 #include <linux/spinlock.h>
36 #include <linux/ipv6.h>
37 #include <linux/tcp.h>
38 #include <linux/udp.h>
39 #include <linux/if_vlan.h>
40 #include <linux/slab.h>
41 #include <net/ip6_checksum.h>
44 static int force_pseudohp
= -1;
45 static int no_pseudohp
= -1;
46 static int no_extplug
= -1;
47 module_param(force_pseudohp
, int, 0);
48 MODULE_PARM_DESC(force_pseudohp
,
49 "Enable pseudo hot-plug feature manually by driver instead of BIOS.");
50 module_param(no_pseudohp
, int, 0);
51 MODULE_PARM_DESC(no_pseudohp
, "Disable pseudo hot-plug feature.");
52 module_param(no_extplug
, int, 0);
53 MODULE_PARM_DESC(no_extplug
,
54 "Do not use external plug signal for pseudo hot-plug.");
57 jme_mdio_read(struct net_device
*netdev
, int phy
, int reg
)
59 struct jme_adapter
*jme
= netdev_priv(netdev
);
60 int i
, val
, again
= (reg
== MII_BMSR
) ? 1 : 0;
63 jwrite32(jme
, JME_SMI
, SMI_OP_REQ
|
68 for (i
= JME_PHY_TIMEOUT
* 50 ; i
> 0 ; --i
) {
70 val
= jread32(jme
, JME_SMI
);
71 if ((val
& SMI_OP_REQ
) == 0)
76 jeprintk(jme
->pdev
, "phy(%d) read timeout : %d\n", phy
, reg
);
83 return (val
& SMI_DATA_MASK
) >> SMI_DATA_SHIFT
;
87 jme_mdio_write(struct net_device
*netdev
,
88 int phy
, int reg
, int val
)
90 struct jme_adapter
*jme
= netdev_priv(netdev
);
93 jwrite32(jme
, JME_SMI
, SMI_OP_WRITE
| SMI_OP_REQ
|
94 ((val
<< SMI_DATA_SHIFT
) & SMI_DATA_MASK
) |
95 smi_phy_addr(phy
) | smi_reg_addr(reg
));
98 for (i
= JME_PHY_TIMEOUT
* 50 ; i
> 0 ; --i
) {
100 if ((jread32(jme
, JME_SMI
) & SMI_OP_REQ
) == 0)
105 jeprintk(jme
->pdev
, "phy(%d) write timeout : %d\n", phy
, reg
);
111 jme_reset_phy_processor(struct jme_adapter
*jme
)
115 jme_mdio_write(jme
->dev
,
117 MII_ADVERTISE
, ADVERTISE_ALL
|
118 ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
120 if (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
121 jme_mdio_write(jme
->dev
,
124 ADVERTISE_1000FULL
| ADVERTISE_1000HALF
);
126 val
= jme_mdio_read(jme
->dev
,
130 jme_mdio_write(jme
->dev
,
132 MII_BMCR
, val
| BMCR_RESET
);
138 jme_setup_wakeup_frame(struct jme_adapter
*jme
,
139 u32
*mask
, u32 crc
, int fnr
)
146 jwrite32(jme
, JME_WFOI
, WFOI_CRC_SEL
| (fnr
& WFOI_FRAME_SEL
));
148 jwrite32(jme
, JME_WFODP
, crc
);
154 for (i
= 0 ; i
< WAKEUP_FRAME_MASK_DWNR
; ++i
) {
155 jwrite32(jme
, JME_WFOI
,
156 ((i
<< WFOI_MASK_SHIFT
) & WFOI_MASK_SEL
) |
157 (fnr
& WFOI_FRAME_SEL
));
159 jwrite32(jme
, JME_WFODP
, mask
[i
]);
165 jme_reset_mac_processor(struct jme_adapter
*jme
)
167 u32 mask
[WAKEUP_FRAME_MASK_DWNR
] = {0, 0, 0, 0};
168 u32 crc
= 0xCDCDCDCD;
172 jwrite32(jme
, JME_GHC
, jme
->reg_ghc
| GHC_SWRST
);
174 jwrite32(jme
, JME_GHC
, jme
->reg_ghc
);
176 jwrite32(jme
, JME_RXDBA_LO
, 0x00000000);
177 jwrite32(jme
, JME_RXDBA_HI
, 0x00000000);
178 jwrite32(jme
, JME_RXQDC
, 0x00000000);
179 jwrite32(jme
, JME_RXNDA
, 0x00000000);
180 jwrite32(jme
, JME_TXDBA_LO
, 0x00000000);
181 jwrite32(jme
, JME_TXDBA_HI
, 0x00000000);
182 jwrite32(jme
, JME_TXQDC
, 0x00000000);
183 jwrite32(jme
, JME_TXNDA
, 0x00000000);
185 jwrite32(jme
, JME_RXMCHT_LO
, 0x00000000);
186 jwrite32(jme
, JME_RXMCHT_HI
, 0x00000000);
187 for (i
= 0 ; i
< WAKEUP_FRAME_NR
; ++i
)
188 jme_setup_wakeup_frame(jme
, mask
, crc
, i
);
190 gpreg0
= GPREG0_DEFAULT
| GPREG0_LNKINTPOLL
;
192 gpreg0
= GPREG0_DEFAULT
;
193 jwrite32(jme
, JME_GPREG0
, gpreg0
);
194 jwrite32(jme
, JME_GPREG1
, GPREG1_DEFAULT
);
198 jme_reset_ghc_speed(struct jme_adapter
*jme
)
200 jme
->reg_ghc
&= ~(GHC_SPEED_1000M
| GHC_DPX
);
201 jwrite32(jme
, JME_GHC
, jme
->reg_ghc
);
205 jme_clear_pm(struct jme_adapter
*jme
)
207 jwrite32(jme
, JME_PMCS
, 0xFFFF0000 | jme
->reg_pmcs
);
208 pci_set_power_state(jme
->pdev
, PCI_D0
);
209 pci_enable_wake(jme
->pdev
, PCI_D0
, false);
213 jme_reload_eeprom(struct jme_adapter
*jme
)
218 val
= jread32(jme
, JME_SMBCSR
);
220 if (val
& SMBCSR_EEPROMD
) {
222 jwrite32(jme
, JME_SMBCSR
, val
);
223 val
|= SMBCSR_RELOAD
;
224 jwrite32(jme
, JME_SMBCSR
, val
);
227 for (i
= JME_EEPROM_RELOAD_TIMEOUT
; i
> 0; --i
) {
229 if ((jread32(jme
, JME_SMBCSR
) & SMBCSR_RELOAD
) == 0)
234 jeprintk(jme
->pdev
, "eeprom reload timeout\n");
243 jme_load_macaddr(struct net_device
*netdev
)
245 struct jme_adapter
*jme
= netdev_priv(netdev
);
246 unsigned char macaddr
[6];
249 spin_lock_bh(&jme
->macaddr_lock
);
250 val
= jread32(jme
, JME_RXUMA_LO
);
251 macaddr
[0] = (val
>> 0) & 0xFF;
252 macaddr
[1] = (val
>> 8) & 0xFF;
253 macaddr
[2] = (val
>> 16) & 0xFF;
254 macaddr
[3] = (val
>> 24) & 0xFF;
255 val
= jread32(jme
, JME_RXUMA_HI
);
256 macaddr
[4] = (val
>> 0) & 0xFF;
257 macaddr
[5] = (val
>> 8) & 0xFF;
258 memcpy(netdev
->dev_addr
, macaddr
, 6);
259 spin_unlock_bh(&jme
->macaddr_lock
);
263 jme_set_rx_pcc(struct jme_adapter
*jme
, int p
)
267 jwrite32(jme
, JME_PCCRX0
,
268 ((PCC_OFF_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
269 ((PCC_OFF_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
272 jwrite32(jme
, JME_PCCRX0
,
273 ((PCC_P1_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
274 ((PCC_P1_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
277 jwrite32(jme
, JME_PCCRX0
,
278 ((PCC_P2_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
279 ((PCC_P2_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
282 jwrite32(jme
, JME_PCCRX0
,
283 ((PCC_P3_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
284 ((PCC_P3_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
291 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
292 netif_info(jme
, rx_status
, jme
->dev
, "Switched to PCC_P%d\n", p
);
296 jme_start_irq(struct jme_adapter
*jme
)
298 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
300 jme_set_rx_pcc(jme
, PCC_P1
);
302 dpi
->attempt
= PCC_P1
;
305 jwrite32(jme
, JME_PCCTX
,
306 ((PCC_TX_TO
<< PCCTXTO_SHIFT
) & PCCTXTO_MASK
) |
307 ((PCC_TX_CNT
<< PCCTX_SHIFT
) & PCCTX_MASK
) |
314 jwrite32(jme
, JME_IENS
, INTR_ENABLE
);
318 jme_stop_irq(struct jme_adapter
*jme
)
323 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
327 jme_linkstat_from_phy(struct jme_adapter
*jme
)
331 phylink
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 17);
332 bmsr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMSR
);
333 if (bmsr
& BMSR_ANCOMP
)
334 phylink
|= PHY_LINK_AUTONEG_COMPLETE
;
340 jme_set_phyfifoa(struct jme_adapter
*jme
)
342 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0004);
346 jme_set_phyfifob(struct jme_adapter
*jme
)
348 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0000);
352 jme_check_link(struct net_device
*netdev
, int testonly
)
354 struct jme_adapter
*jme
= netdev_priv(netdev
);
355 u32 phylink
, ghc
, cnt
= JME_SPDRSV_TIMEOUT
, bmcr
, gpreg1
;
362 phylink
= jme_linkstat_from_phy(jme
);
364 phylink
= jread32(jme
, JME_PHY_LINK
);
366 if (phylink
& PHY_LINK_UP
) {
367 if (!(phylink
& PHY_LINK_AUTONEG_COMPLETE
)) {
369 * If we did not enable AN
370 * Speed/Duplex Info should be obtained from SMI
372 phylink
= PHY_LINK_UP
;
374 bmcr
= jme_mdio_read(jme
->dev
,
378 phylink
|= ((bmcr
& BMCR_SPEED1000
) &&
379 (bmcr
& BMCR_SPEED100
) == 0) ?
380 PHY_LINK_SPEED_1000M
:
381 (bmcr
& BMCR_SPEED100
) ?
382 PHY_LINK_SPEED_100M
:
385 phylink
|= (bmcr
& BMCR_FULLDPLX
) ?
388 strcat(linkmsg
, "Forced: ");
391 * Keep polling for speed/duplex resolve complete
393 while (!(phylink
& PHY_LINK_SPEEDDPU_RESOLVED
) &&
399 phylink
= jme_linkstat_from_phy(jme
);
401 phylink
= jread32(jme
, JME_PHY_LINK
);
405 "Waiting speed resolve timeout.\n");
407 strcat(linkmsg
, "ANed: ");
410 if (jme
->phylink
== phylink
) {
417 jme
->phylink
= phylink
;
419 ghc
= jme
->reg_ghc
& ~(GHC_SPEED
| GHC_DPX
|
420 GHC_TO_CLK_PCIE
| GHC_TXMAC_CLK_PCIE
|
421 GHC_TO_CLK_GPHY
| GHC_TXMAC_CLK_GPHY
);
422 switch (phylink
& PHY_LINK_SPEED_MASK
) {
423 case PHY_LINK_SPEED_10M
:
424 ghc
|= GHC_SPEED_10M
|
425 GHC_TO_CLK_PCIE
| GHC_TXMAC_CLK_PCIE
;
426 strcat(linkmsg
, "10 Mbps, ");
428 case PHY_LINK_SPEED_100M
:
429 ghc
|= GHC_SPEED_100M
|
430 GHC_TO_CLK_PCIE
| GHC_TXMAC_CLK_PCIE
;
431 strcat(linkmsg
, "100 Mbps, ");
433 case PHY_LINK_SPEED_1000M
:
434 ghc
|= GHC_SPEED_1000M
|
435 GHC_TO_CLK_GPHY
| GHC_TXMAC_CLK_GPHY
;
436 strcat(linkmsg
, "1000 Mbps, ");
442 if (phylink
& PHY_LINK_DUPLEX
) {
443 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
);
446 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
|
450 jwrite32(jme
, JME_TXTRHD
, TXTRHD_TXPEN
|
451 ((0x2000 << TXTRHD_TXP_SHIFT
) & TXTRHD_TXP
) |
453 ((8 << TXTRHD_TXRL_SHIFT
) & TXTRHD_TXRL
));
456 gpreg1
= GPREG1_DEFAULT
;
457 if (is_buggy250(jme
->pdev
->device
, jme
->chiprev
)) {
458 if (!(phylink
& PHY_LINK_DUPLEX
))
459 gpreg1
|= GPREG1_HALFMODEPATCH
;
460 switch (phylink
& PHY_LINK_SPEED_MASK
) {
461 case PHY_LINK_SPEED_10M
:
462 jme_set_phyfifoa(jme
);
463 gpreg1
|= GPREG1_RSSPATCH
;
465 case PHY_LINK_SPEED_100M
:
466 jme_set_phyfifob(jme
);
467 gpreg1
|= GPREG1_RSSPATCH
;
469 case PHY_LINK_SPEED_1000M
:
470 jme_set_phyfifoa(jme
);
477 jwrite32(jme
, JME_GPREG1
, gpreg1
);
478 jwrite32(jme
, JME_GHC
, ghc
);
481 strcat(linkmsg
, (phylink
& PHY_LINK_DUPLEX
) ?
484 strcat(linkmsg
, (phylink
& PHY_LINK_MDI_STAT
) ?
487 netif_info(jme
, link
, jme
->dev
, "Link is up at %s.\n", linkmsg
);
488 netif_carrier_on(netdev
);
493 netif_info(jme
, link
, jme
->dev
, "Link is down.\n");
495 netif_carrier_off(netdev
);
503 jme_setup_tx_resources(struct jme_adapter
*jme
)
505 struct jme_ring
*txring
= &(jme
->txring
[0]);
507 txring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
508 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
518 txring
->desc
= (void *)ALIGN((unsigned long)(txring
->alloc
),
520 txring
->dma
= ALIGN(txring
->dmaalloc
, RING_DESC_ALIGN
);
521 txring
->next_to_use
= 0;
522 atomic_set(&txring
->next_to_clean
, 0);
523 atomic_set(&txring
->nr_free
, jme
->tx_ring_size
);
525 txring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
526 jme
->tx_ring_size
, GFP_ATOMIC
);
527 if (unlikely(!(txring
->bufinf
)))
528 goto err_free_txring
;
531 * Initialize Transmit Descriptors
533 memset(txring
->alloc
, 0, TX_RING_ALLOC_SIZE(jme
->tx_ring_size
));
534 memset(txring
->bufinf
, 0,
535 sizeof(struct jme_buffer_info
) * jme
->tx_ring_size
);
540 dma_free_coherent(&(jme
->pdev
->dev
),
541 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
547 txring
->dmaalloc
= 0;
549 txring
->bufinf
= NULL
;
555 jme_free_tx_resources(struct jme_adapter
*jme
)
558 struct jme_ring
*txring
= &(jme
->txring
[0]);
559 struct jme_buffer_info
*txbi
;
562 if (txring
->bufinf
) {
563 for (i
= 0 ; i
< jme
->tx_ring_size
; ++i
) {
564 txbi
= txring
->bufinf
+ i
;
566 dev_kfree_skb(txbi
->skb
);
572 txbi
->start_xmit
= 0;
574 kfree(txring
->bufinf
);
577 dma_free_coherent(&(jme
->pdev
->dev
),
578 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
582 txring
->alloc
= NULL
;
584 txring
->dmaalloc
= 0;
586 txring
->bufinf
= NULL
;
588 txring
->next_to_use
= 0;
589 atomic_set(&txring
->next_to_clean
, 0);
590 atomic_set(&txring
->nr_free
, 0);
594 jme_enable_tx_engine(struct jme_adapter
*jme
)
599 jwrite32(jme
, JME_TXCS
, TXCS_DEFAULT
| TXCS_SELECT_QUEUE0
);
603 * Setup TX Queue 0 DMA Bass Address
605 jwrite32(jme
, JME_TXDBA_LO
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
606 jwrite32(jme
, JME_TXDBA_HI
, (__u64
)(jme
->txring
[0].dma
) >> 32);
607 jwrite32(jme
, JME_TXNDA
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
610 * Setup TX Descptor Count
612 jwrite32(jme
, JME_TXQDC
, jme
->tx_ring_size
);
618 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
625 jme_restart_tx_engine(struct jme_adapter
*jme
)
630 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
636 jme_disable_tx_engine(struct jme_adapter
*jme
)
644 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
| TXCS_SELECT_QUEUE0
);
647 val
= jread32(jme
, JME_TXCS
);
648 for (i
= JME_TX_DISABLE_TIMEOUT
; (val
& TXCS_ENABLE
) && i
> 0 ; --i
) {
650 val
= jread32(jme
, JME_TXCS
);
655 jeprintk(jme
->pdev
, "Disable TX engine timeout.\n");
659 jme_set_clean_rxdesc(struct jme_adapter
*jme
, int i
)
661 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
662 register struct rxdesc
*rxdesc
= rxring
->desc
;
663 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
669 rxdesc
->desc1
.bufaddrh
= cpu_to_le32((__u64
)rxbi
->mapping
>> 32);
670 rxdesc
->desc1
.bufaddrl
= cpu_to_le32(
671 (__u64
)rxbi
->mapping
& 0xFFFFFFFFUL
);
672 rxdesc
->desc1
.datalen
= cpu_to_le16(rxbi
->len
);
673 if (jme
->dev
->features
& NETIF_F_HIGHDMA
)
674 rxdesc
->desc1
.flags
= RXFLAG_64BIT
;
676 rxdesc
->desc1
.flags
|= RXFLAG_OWN
| RXFLAG_INT
;
680 jme_make_new_rx_buf(struct jme_adapter
*jme
, int i
)
682 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
683 struct jme_buffer_info
*rxbi
= rxring
->bufinf
+ i
;
686 skb
= netdev_alloc_skb(jme
->dev
,
687 jme
->dev
->mtu
+ RX_EXTRA_LEN
);
692 rxbi
->len
= skb_tailroom(skb
);
693 rxbi
->mapping
= pci_map_page(jme
->pdev
,
694 virt_to_page(skb
->data
),
695 offset_in_page(skb
->data
),
703 jme_free_rx_buf(struct jme_adapter
*jme
, int i
)
705 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
706 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
710 pci_unmap_page(jme
->pdev
,
714 dev_kfree_skb(rxbi
->skb
);
722 jme_free_rx_resources(struct jme_adapter
*jme
)
725 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
728 if (rxring
->bufinf
) {
729 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
)
730 jme_free_rx_buf(jme
, i
);
731 kfree(rxring
->bufinf
);
734 dma_free_coherent(&(jme
->pdev
->dev
),
735 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
738 rxring
->alloc
= NULL
;
740 rxring
->dmaalloc
= 0;
742 rxring
->bufinf
= NULL
;
744 rxring
->next_to_use
= 0;
745 atomic_set(&rxring
->next_to_clean
, 0);
749 jme_setup_rx_resources(struct jme_adapter
*jme
)
752 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
754 rxring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
755 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
764 rxring
->desc
= (void *)ALIGN((unsigned long)(rxring
->alloc
),
766 rxring
->dma
= ALIGN(rxring
->dmaalloc
, RING_DESC_ALIGN
);
767 rxring
->next_to_use
= 0;
768 atomic_set(&rxring
->next_to_clean
, 0);
770 rxring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
771 jme
->rx_ring_size
, GFP_ATOMIC
);
772 if (unlikely(!(rxring
->bufinf
)))
773 goto err_free_rxring
;
776 * Initiallize Receive Descriptors
778 memset(rxring
->bufinf
, 0,
779 sizeof(struct jme_buffer_info
) * jme
->rx_ring_size
);
780 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
) {
781 if (unlikely(jme_make_new_rx_buf(jme
, i
))) {
782 jme_free_rx_resources(jme
);
786 jme_set_clean_rxdesc(jme
, i
);
792 dma_free_coherent(&(jme
->pdev
->dev
),
793 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
798 rxring
->dmaalloc
= 0;
800 rxring
->bufinf
= NULL
;
806 jme_enable_rx_engine(struct jme_adapter
*jme
)
811 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
816 * Setup RX DMA Bass Address
818 jwrite32(jme
, JME_RXDBA_LO
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
819 jwrite32(jme
, JME_RXDBA_HI
, (__u64
)(jme
->rxring
[0].dma
) >> 32);
820 jwrite32(jme
, JME_RXNDA
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
823 * Setup RX Descriptor Count
825 jwrite32(jme
, JME_RXQDC
, jme
->rx_ring_size
);
828 * Setup Unicast Filter
830 jme_set_multi(jme
->dev
);
836 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
843 jme_restart_rx_engine(struct jme_adapter
*jme
)
848 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
855 jme_disable_rx_engine(struct jme_adapter
*jme
)
863 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
);
866 val
= jread32(jme
, JME_RXCS
);
867 for (i
= JME_RX_DISABLE_TIMEOUT
; (val
& RXCS_ENABLE
) && i
> 0 ; --i
) {
869 val
= jread32(jme
, JME_RXCS
);
874 jeprintk(jme
->pdev
, "Disable RX engine timeout.\n");
879 jme_rxsum_ok(struct jme_adapter
*jme
, u16 flags
)
881 if (!(flags
& (RXWBFLAG_TCPON
| RXWBFLAG_UDPON
| RXWBFLAG_IPV4
)))
884 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_TCPON
| RXWBFLAG_TCPCS
))
885 == RXWBFLAG_TCPON
)) {
886 if (flags
& RXWBFLAG_IPV4
)
887 netif_err(jme
, rx_err
, jme
->dev
, "TCP Checksum error\n");
891 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_UDPON
| RXWBFLAG_UDPCS
))
892 == RXWBFLAG_UDPON
)) {
893 if (flags
& RXWBFLAG_IPV4
)
894 netif_err(jme
, rx_err
, jme
->dev
, "UDP Checksum error.\n");
898 if (unlikely((flags
& (RXWBFLAG_IPV4
| RXWBFLAG_IPCS
))
900 netif_err(jme
, rx_err
, jme
->dev
, "IPv4 Checksum error.\n");
908 jme_alloc_and_feed_skb(struct jme_adapter
*jme
, int idx
)
910 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
911 struct rxdesc
*rxdesc
= rxring
->desc
;
912 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
920 pci_dma_sync_single_for_cpu(jme
->pdev
,
925 if (unlikely(jme_make_new_rx_buf(jme
, idx
))) {
926 pci_dma_sync_single_for_device(jme
->pdev
,
931 ++(NET_STAT(jme
).rx_dropped
);
933 framesize
= le16_to_cpu(rxdesc
->descwb
.framesize
)
936 skb_reserve(skb
, RX_PREPAD_SIZE
);
937 skb_put(skb
, framesize
);
938 skb
->protocol
= eth_type_trans(skb
, jme
->dev
);
940 if (jme_rxsum_ok(jme
, le16_to_cpu(rxdesc
->descwb
.flags
)))
941 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
943 skb
->ip_summed
= CHECKSUM_NONE
;
945 if (rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_TAGON
)) {
947 jme
->jme_vlan_rx(skb
, jme
->vlgrp
,
948 le16_to_cpu(rxdesc
->descwb
.vlan
));
949 NET_STAT(jme
).rx_bytes
+= 4;
957 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_DEST
)) ==
958 cpu_to_le16(RXWBFLAG_DEST_MUL
))
959 ++(NET_STAT(jme
).multicast
);
961 NET_STAT(jme
).rx_bytes
+= framesize
;
962 ++(NET_STAT(jme
).rx_packets
);
965 jme_set_clean_rxdesc(jme
, idx
);
970 jme_process_receive(struct jme_adapter
*jme
, int limit
)
972 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
973 struct rxdesc
*rxdesc
= rxring
->desc
;
974 int i
, j
, ccnt
, desccnt
, mask
= jme
->rx_ring_mask
;
976 if (unlikely(!atomic_dec_and_test(&jme
->rx_cleaning
)))
979 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
982 if (unlikely(!netif_carrier_ok(jme
->dev
)))
985 i
= atomic_read(&rxring
->next_to_clean
);
987 rxdesc
= rxring
->desc
;
990 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_OWN
)) ||
991 !(rxdesc
->descwb
.desccnt
& RXWBDCNT_WBCPL
))
995 desccnt
= rxdesc
->descwb
.desccnt
& RXWBDCNT_DCNT
;
997 if (unlikely(desccnt
> 1 ||
998 rxdesc
->descwb
.errstat
& RXWBERR_ALLERR
)) {
1000 if (rxdesc
->descwb
.errstat
& RXWBERR_CRCERR
)
1001 ++(NET_STAT(jme
).rx_crc_errors
);
1002 else if (rxdesc
->descwb
.errstat
& RXWBERR_OVERUN
)
1003 ++(NET_STAT(jme
).rx_fifo_errors
);
1005 ++(NET_STAT(jme
).rx_errors
);
1008 limit
-= desccnt
- 1;
1010 for (j
= i
, ccnt
= desccnt
; ccnt
-- ; ) {
1011 jme_set_clean_rxdesc(jme
, j
);
1012 j
= (j
+ 1) & (mask
);
1016 jme_alloc_and_feed_skb(jme
, i
);
1019 i
= (i
+ desccnt
) & (mask
);
1023 atomic_set(&rxring
->next_to_clean
, i
);
1026 atomic_inc(&jme
->rx_cleaning
);
1028 return limit
> 0 ? limit
: 0;
1033 jme_attempt_pcc(struct dynpcc_info
*dpi
, int atmp
)
1035 if (likely(atmp
== dpi
->cur
)) {
1040 if (dpi
->attempt
== atmp
) {
1043 dpi
->attempt
= atmp
;
1050 jme_dynamic_pcc(struct jme_adapter
*jme
)
1052 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
1054 if ((NET_STAT(jme
).rx_bytes
- dpi
->last_bytes
) > PCC_P3_THRESHOLD
)
1055 jme_attempt_pcc(dpi
, PCC_P3
);
1056 else if ((NET_STAT(jme
).rx_packets
- dpi
->last_pkts
) > PCC_P2_THRESHOLD
||
1057 dpi
->intr_cnt
> PCC_INTR_THRESHOLD
)
1058 jme_attempt_pcc(dpi
, PCC_P2
);
1060 jme_attempt_pcc(dpi
, PCC_P1
);
1062 if (unlikely(dpi
->attempt
!= dpi
->cur
&& dpi
->cnt
> 5)) {
1063 if (dpi
->attempt
< dpi
->cur
)
1064 tasklet_schedule(&jme
->rxclean_task
);
1065 jme_set_rx_pcc(jme
, dpi
->attempt
);
1066 dpi
->cur
= dpi
->attempt
;
1072 jme_start_pcc_timer(struct jme_adapter
*jme
)
1074 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1075 dpi
->last_bytes
= NET_STAT(jme
).rx_bytes
;
1076 dpi
->last_pkts
= NET_STAT(jme
).rx_packets
;
1078 jwrite32(jme
, JME_TMCSR
,
1079 TMCSR_EN
| ((0xFFFFFF - PCC_INTERVAL_US
) & TMCSR_CNT
));
1083 jme_stop_pcc_timer(struct jme_adapter
*jme
)
1085 jwrite32(jme
, JME_TMCSR
, 0);
1089 jme_shutdown_nic(struct jme_adapter
*jme
)
1093 phylink
= jme_linkstat_from_phy(jme
);
1095 if (!(phylink
& PHY_LINK_UP
)) {
1097 * Disable all interrupt before issue timer
1100 jwrite32(jme
, JME_TIMER2
, TMCSR_EN
| 0xFFFFFE);
1105 jme_pcc_tasklet(unsigned long arg
)
1107 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1108 struct net_device
*netdev
= jme
->dev
;
1110 if (unlikely(test_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
))) {
1111 jme_shutdown_nic(jme
);
1115 if (unlikely(!netif_carrier_ok(netdev
) ||
1116 (atomic_read(&jme
->link_changing
) != 1)
1118 jme_stop_pcc_timer(jme
);
1122 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
1123 jme_dynamic_pcc(jme
);
1125 jme_start_pcc_timer(jme
);
1129 jme_polling_mode(struct jme_adapter
*jme
)
1131 jme_set_rx_pcc(jme
, PCC_OFF
);
1135 jme_interrupt_mode(struct jme_adapter
*jme
)
1137 jme_set_rx_pcc(jme
, PCC_P1
);
1141 jme_pseudo_hotplug_enabled(struct jme_adapter
*jme
)
1144 apmc
= jread32(jme
, JME_APMC
);
1145 return apmc
& JME_APMC_PSEUDO_HP_EN
;
1149 jme_start_shutdown_timer(struct jme_adapter
*jme
)
1153 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PCIE_SD_EN
;
1154 apmc
&= ~JME_APMC_EPIEN_CTRL
;
1156 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_EN
);
1159 jwrite32f(jme
, JME_APMC
, apmc
);
1161 jwrite32f(jme
, JME_TIMER2
, 0);
1162 set_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1163 jwrite32(jme
, JME_TMCSR
,
1164 TMCSR_EN
| ((0xFFFFFF - APMC_PHP_SHUTDOWN_DELAY
) & TMCSR_CNT
));
1168 jme_stop_shutdown_timer(struct jme_adapter
*jme
)
1172 jwrite32f(jme
, JME_TMCSR
, 0);
1173 jwrite32f(jme
, JME_TIMER2
, 0);
1174 clear_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1176 apmc
= jread32(jme
, JME_APMC
);
1177 apmc
&= ~(JME_APMC_PCIE_SD_EN
| JME_APMC_EPIEN_CTRL
);
1178 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_DIS
);
1180 jwrite32f(jme
, JME_APMC
, apmc
);
1184 jme_link_change_tasklet(unsigned long arg
)
1186 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1187 struct net_device
*netdev
= jme
->dev
;
1190 while (!atomic_dec_and_test(&jme
->link_changing
)) {
1191 atomic_inc(&jme
->link_changing
);
1192 netif_info(jme
, intr
, jme
->dev
, "Get link change lock failed.\n");
1193 while (atomic_read(&jme
->link_changing
) != 1)
1194 netif_info(jme
, intr
, jme
->dev
, "Waiting link change lock.\n");
1197 if (jme_check_link(netdev
, 1) && jme
->old_mtu
== netdev
->mtu
)
1200 jme
->old_mtu
= netdev
->mtu
;
1201 netif_stop_queue(netdev
);
1202 if (jme_pseudo_hotplug_enabled(jme
))
1203 jme_stop_shutdown_timer(jme
);
1205 jme_stop_pcc_timer(jme
);
1206 tasklet_disable(&jme
->txclean_task
);
1207 tasklet_disable(&jme
->rxclean_task
);
1208 tasklet_disable(&jme
->rxempty_task
);
1210 if (netif_carrier_ok(netdev
)) {
1211 jme_reset_ghc_speed(jme
);
1212 jme_disable_rx_engine(jme
);
1213 jme_disable_tx_engine(jme
);
1214 jme_reset_mac_processor(jme
);
1215 jme_free_rx_resources(jme
);
1216 jme_free_tx_resources(jme
);
1218 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1219 jme_polling_mode(jme
);
1221 netif_carrier_off(netdev
);
1224 jme_check_link(netdev
, 0);
1225 if (netif_carrier_ok(netdev
)) {
1226 rc
= jme_setup_rx_resources(jme
);
1228 jeprintk(jme
->pdev
, "Allocating resources for RX error"
1229 ", Device STOPPED!\n");
1230 goto out_enable_tasklet
;
1233 rc
= jme_setup_tx_resources(jme
);
1235 jeprintk(jme
->pdev
, "Allocating resources for TX error"
1236 ", Device STOPPED!\n");
1237 goto err_out_free_rx_resources
;
1240 jme_enable_rx_engine(jme
);
1241 jme_enable_tx_engine(jme
);
1243 netif_start_queue(netdev
);
1245 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1246 jme_interrupt_mode(jme
);
1248 jme_start_pcc_timer(jme
);
1249 } else if (jme_pseudo_hotplug_enabled(jme
)) {
1250 jme_start_shutdown_timer(jme
);
1253 goto out_enable_tasklet
;
1255 err_out_free_rx_resources
:
1256 jme_free_rx_resources(jme
);
1258 tasklet_enable(&jme
->txclean_task
);
1259 tasklet_hi_enable(&jme
->rxclean_task
);
1260 tasklet_hi_enable(&jme
->rxempty_task
);
1262 atomic_inc(&jme
->link_changing
);
1266 jme_rx_clean_tasklet(unsigned long arg
)
1268 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1269 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1271 jme_process_receive(jme
, jme
->rx_ring_size
);
1277 jme_poll(JME_NAPI_HOLDER(holder
), JME_NAPI_WEIGHT(budget
))
1279 struct jme_adapter
*jme
= jme_napi_priv(holder
);
1282 rest
= jme_process_receive(jme
, JME_NAPI_WEIGHT_VAL(budget
));
1284 while (atomic_read(&jme
->rx_empty
) > 0) {
1285 atomic_dec(&jme
->rx_empty
);
1286 ++(NET_STAT(jme
).rx_dropped
);
1287 jme_restart_rx_engine(jme
);
1289 atomic_inc(&jme
->rx_empty
);
1292 JME_RX_COMPLETE(netdev
, holder
);
1293 jme_interrupt_mode(jme
);
1296 JME_NAPI_WEIGHT_SET(budget
, rest
);
1297 return JME_NAPI_WEIGHT_VAL(budget
) - rest
;
1301 jme_rx_empty_tasklet(unsigned long arg
)
1303 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1305 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1308 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1311 netif_info(jme
, rx_status
, jme
->dev
, "RX Queue Full!\n");
1313 jme_rx_clean_tasklet(arg
);
1315 while (atomic_read(&jme
->rx_empty
) > 0) {
1316 atomic_dec(&jme
->rx_empty
);
1317 ++(NET_STAT(jme
).rx_dropped
);
1318 jme_restart_rx_engine(jme
);
1320 atomic_inc(&jme
->rx_empty
);
1324 jme_wake_queue_if_stopped(struct jme_adapter
*jme
)
1326 struct jme_ring
*txring
= &(jme
->txring
[0]);
1329 if (unlikely(netif_queue_stopped(jme
->dev
) &&
1330 atomic_read(&txring
->nr_free
) >= (jme
->tx_wake_threshold
))) {
1331 netif_info(jme
, tx_done
, jme
->dev
, "TX Queue Waked.\n");
1332 netif_wake_queue(jme
->dev
);
1338 jme_tx_clean_tasklet(unsigned long arg
)
1340 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1341 struct jme_ring
*txring
= &(jme
->txring
[0]);
1342 struct txdesc
*txdesc
= txring
->desc
;
1343 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
, *ttxbi
;
1344 int i
, j
, cnt
= 0, max
, err
, mask
;
1346 tx_dbg(jme
, "Into txclean.\n");
1348 if (unlikely(!atomic_dec_and_test(&jme
->tx_cleaning
)))
1351 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1354 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1357 max
= jme
->tx_ring_size
- atomic_read(&txring
->nr_free
);
1358 mask
= jme
->tx_ring_mask
;
1360 for (i
= atomic_read(&txring
->next_to_clean
) ; cnt
< max
; ) {
1364 if (likely(ctxbi
->skb
&&
1365 !(txdesc
[i
].descwb
.flags
& TXWBFLAG_OWN
))) {
1367 tx_dbg(jme
, "txclean: %d+%d@%lu\n",
1368 i
, ctxbi
->nr_desc
, jiffies
);
1370 err
= txdesc
[i
].descwb
.flags
& TXWBFLAG_ALLERR
;
1372 for (j
= 1 ; j
< ctxbi
->nr_desc
; ++j
) {
1373 ttxbi
= txbi
+ ((i
+ j
) & (mask
));
1374 txdesc
[(i
+ j
) & (mask
)].dw
[0] = 0;
1376 pci_unmap_page(jme
->pdev
,
1385 dev_kfree_skb(ctxbi
->skb
);
1387 cnt
+= ctxbi
->nr_desc
;
1389 if (unlikely(err
)) {
1390 ++(NET_STAT(jme
).tx_carrier_errors
);
1392 ++(NET_STAT(jme
).tx_packets
);
1393 NET_STAT(jme
).tx_bytes
+= ctxbi
->len
;
1398 ctxbi
->start_xmit
= 0;
1404 i
= (i
+ ctxbi
->nr_desc
) & mask
;
1409 tx_dbg(jme
, "txclean: done %d@%lu.\n", i
, jiffies
);
1410 atomic_set(&txring
->next_to_clean
, i
);
1411 atomic_add(cnt
, &txring
->nr_free
);
1413 jme_wake_queue_if_stopped(jme
);
1416 atomic_inc(&jme
->tx_cleaning
);
1420 jme_intr_msi(struct jme_adapter
*jme
, u32 intrstat
)
1425 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
1427 if (intrstat
& (INTR_LINKCH
| INTR_SWINTR
)) {
1429 * Link change event is critical
1430 * all other events are ignored
1432 jwrite32(jme
, JME_IEVE
, intrstat
);
1433 tasklet_schedule(&jme
->linkch_task
);
1437 if (intrstat
& INTR_TMINTR
) {
1438 jwrite32(jme
, JME_IEVE
, INTR_TMINTR
);
1439 tasklet_schedule(&jme
->pcc_task
);
1442 if (intrstat
& (INTR_PCCTXTO
| INTR_PCCTX
)) {
1443 jwrite32(jme
, JME_IEVE
, INTR_PCCTXTO
| INTR_PCCTX
| INTR_TX0
);
1444 tasklet_schedule(&jme
->txclean_task
);
1447 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1448 jwrite32(jme
, JME_IEVE
, (intrstat
& (INTR_PCCRX0TO
|
1454 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
1455 if (intrstat
& INTR_RX0EMP
)
1456 atomic_inc(&jme
->rx_empty
);
1458 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1459 if (likely(JME_RX_SCHEDULE_PREP(jme
))) {
1460 jme_polling_mode(jme
);
1461 JME_RX_SCHEDULE(jme
);
1465 if (intrstat
& INTR_RX0EMP
) {
1466 atomic_inc(&jme
->rx_empty
);
1467 tasklet_hi_schedule(&jme
->rxempty_task
);
1468 } else if (intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
)) {
1469 tasklet_hi_schedule(&jme
->rxclean_task
);
1475 * Re-enable interrupt
1477 jwrite32f(jme
, JME_IENS
, INTR_ENABLE
);
1481 jme_intr(int irq
, void *dev_id
)
1483 struct net_device
*netdev
= dev_id
;
1484 struct jme_adapter
*jme
= netdev_priv(netdev
);
1487 intrstat
= jread32(jme
, JME_IEVE
);
1490 * Check if it's really an interrupt for us
1492 if (unlikely((intrstat
& INTR_ENABLE
) == 0))
1496 * Check if the device still exist
1498 if (unlikely(intrstat
== ~((typeof(intrstat
))0)))
1501 jme_intr_msi(jme
, intrstat
);
1507 jme_msi(int irq
, void *dev_id
)
1509 struct net_device
*netdev
= dev_id
;
1510 struct jme_adapter
*jme
= netdev_priv(netdev
);
1513 intrstat
= jread32(jme
, JME_IEVE
);
1515 jme_intr_msi(jme
, intrstat
);
1521 jme_reset_link(struct jme_adapter
*jme
)
1523 jwrite32(jme
, JME_TMCSR
, TMCSR_SWIT
);
1527 jme_restart_an(struct jme_adapter
*jme
)
1531 spin_lock_bh(&jme
->phy_lock
);
1532 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1533 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1534 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1535 spin_unlock_bh(&jme
->phy_lock
);
1539 jme_request_irq(struct jme_adapter
*jme
)
1542 struct net_device
*netdev
= jme
->dev
;
1543 irq_handler_t handler
= jme_intr
;
1544 int irq_flags
= IRQF_SHARED
;
1546 if (!pci_enable_msi(jme
->pdev
)) {
1547 set_bit(JME_FLAG_MSI
, &jme
->flags
);
1552 rc
= request_irq(jme
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
1556 "Unable to request %s interrupt (return: %d)\n",
1557 test_bit(JME_FLAG_MSI
, &jme
->flags
) ? "MSI" : "INTx",
1560 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1561 pci_disable_msi(jme
->pdev
);
1562 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1565 netdev
->irq
= jme
->pdev
->irq
;
1572 jme_free_irq(struct jme_adapter
*jme
)
1574 free_irq(jme
->pdev
->irq
, jme
->dev
);
1575 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1576 pci_disable_msi(jme
->pdev
);
1577 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1578 jme
->dev
->irq
= jme
->pdev
->irq
;
1583 jme_open(struct net_device
*netdev
)
1585 struct jme_adapter
*jme
= netdev_priv(netdev
);
1589 JME_NAPI_ENABLE(jme
);
1591 tasklet_enable(&jme
->linkch_task
);
1592 tasklet_enable(&jme
->txclean_task
);
1593 tasklet_hi_enable(&jme
->rxclean_task
);
1594 tasklet_hi_enable(&jme
->rxempty_task
);
1596 rc
= jme_request_irq(jme
);
1602 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
1603 jme_set_settings(netdev
, &jme
->old_ecmd
);
1605 jme_reset_phy_processor(jme
);
1607 jme_reset_link(jme
);
1612 netif_stop_queue(netdev
);
1613 netif_carrier_off(netdev
);
1619 jme_set_100m_half(struct jme_adapter
*jme
)
1623 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1624 tmp
= bmcr
& ~(BMCR_ANENABLE
| BMCR_SPEED100
|
1625 BMCR_SPEED1000
| BMCR_FULLDPLX
);
1626 tmp
|= BMCR_SPEED100
;
1629 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, tmp
);
1632 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
| GHC_LINK_POLL
);
1634 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
);
1637 #define JME_WAIT_LINK_TIME 2000 /* 2000ms */
1639 jme_wait_link(struct jme_adapter
*jme
)
1641 u32 phylink
, to
= JME_WAIT_LINK_TIME
;
1644 phylink
= jme_linkstat_from_phy(jme
);
1645 while (!(phylink
& PHY_LINK_UP
) && (to
-= 10) > 0) {
1647 phylink
= jme_linkstat_from_phy(jme
);
1653 jme_phy_off(struct jme_adapter
*jme
)
1655 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, BMCR_PDOWN
);
1659 jme_close(struct net_device
*netdev
)
1661 struct jme_adapter
*jme
= netdev_priv(netdev
);
1663 netif_stop_queue(netdev
);
1664 netif_carrier_off(netdev
);
1669 JME_NAPI_DISABLE(jme
);
1671 tasklet_disable(&jme
->linkch_task
);
1672 tasklet_disable(&jme
->txclean_task
);
1673 tasklet_disable(&jme
->rxclean_task
);
1674 tasklet_disable(&jme
->rxempty_task
);
1676 jme_reset_ghc_speed(jme
);
1677 jme_disable_rx_engine(jme
);
1678 jme_disable_tx_engine(jme
);
1679 jme_reset_mac_processor(jme
);
1680 jme_free_rx_resources(jme
);
1681 jme_free_tx_resources(jme
);
1689 jme_alloc_txdesc(struct jme_adapter
*jme
,
1690 struct sk_buff
*skb
)
1692 struct jme_ring
*txring
= &(jme
->txring
[0]);
1693 int idx
, nr_alloc
, mask
= jme
->tx_ring_mask
;
1695 idx
= txring
->next_to_use
;
1696 nr_alloc
= skb_shinfo(skb
)->nr_frags
+ 2;
1698 if (unlikely(atomic_read(&txring
->nr_free
) < nr_alloc
))
1701 atomic_sub(nr_alloc
, &txring
->nr_free
);
1703 txring
->next_to_use
= (txring
->next_to_use
+ nr_alloc
) & mask
;
1709 jme_fill_tx_map(struct pci_dev
*pdev
,
1710 struct txdesc
*txdesc
,
1711 struct jme_buffer_info
*txbi
,
1719 dmaaddr
= pci_map_page(pdev
,
1725 pci_dma_sync_single_for_device(pdev
,
1732 txdesc
->desc2
.flags
= TXFLAG_OWN
;
1733 txdesc
->desc2
.flags
|= (hidma
) ? TXFLAG_64BIT
: 0;
1734 txdesc
->desc2
.datalen
= cpu_to_le16(len
);
1735 txdesc
->desc2
.bufaddrh
= cpu_to_le32((__u64
)dmaaddr
>> 32);
1736 txdesc
->desc2
.bufaddrl
= cpu_to_le32(
1737 (__u64
)dmaaddr
& 0xFFFFFFFFUL
);
1739 txbi
->mapping
= dmaaddr
;
1744 jme_map_tx_skb(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
1746 struct jme_ring
*txring
= &(jme
->txring
[0]);
1747 struct txdesc
*txdesc
= txring
->desc
, *ctxdesc
;
1748 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
;
1749 u8 hidma
= jme
->dev
->features
& NETIF_F_HIGHDMA
;
1750 int i
, nr_frags
= skb_shinfo(skb
)->nr_frags
;
1751 int mask
= jme
->tx_ring_mask
;
1752 struct skb_frag_struct
*frag
;
1755 for (i
= 0 ; i
< nr_frags
; ++i
) {
1756 frag
= &skb_shinfo(skb
)->frags
[i
];
1757 ctxdesc
= txdesc
+ ((idx
+ i
+ 2) & (mask
));
1758 ctxbi
= txbi
+ ((idx
+ i
+ 2) & (mask
));
1760 jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
, frag
->page
,
1761 frag
->page_offset
, frag
->size
, hidma
);
1764 len
= skb_is_nonlinear(skb
) ? skb_headlen(skb
) : skb
->len
;
1765 ctxdesc
= txdesc
+ ((idx
+ 1) & (mask
));
1766 ctxbi
= txbi
+ ((idx
+ 1) & (mask
));
1767 jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
, virt_to_page(skb
->data
),
1768 offset_in_page(skb
->data
), len
, hidma
);
1773 jme_expand_header(struct jme_adapter
*jme
, struct sk_buff
*skb
)
1775 if (unlikely(skb_shinfo(skb
)->gso_size
&&
1776 skb_header_cloned(skb
) &&
1777 pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
))) {
1786 jme_tx_tso(struct sk_buff
*skb
, __le16
*mss
, u8
*flags
)
1788 *mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
<< TXDESC_MSS_SHIFT
);
1790 *flags
|= TXFLAG_LSEN
;
1792 if (skb
->protocol
== htons(ETH_P_IP
)) {
1793 struct iphdr
*iph
= ip_hdr(skb
);
1796 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
1801 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
1803 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ip6h
->saddr
,
1816 jme_tx_csum(struct jme_adapter
*jme
, struct sk_buff
*skb
, u8
*flags
)
1818 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1821 switch (skb
->protocol
) {
1822 case htons(ETH_P_IP
):
1823 ip_proto
= ip_hdr(skb
)->protocol
;
1825 case htons(ETH_P_IPV6
):
1826 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
1835 *flags
|= TXFLAG_TCPCS
;
1838 *flags
|= TXFLAG_UDPCS
;
1841 netif_err(jme
, tx_err
, jme
->dev
, "Error upper layer protocol.\n");
1848 jme_tx_vlan(struct sk_buff
*skb
, __le16
*vlan
, u8
*flags
)
1850 if (vlan_tx_tag_present(skb
)) {
1851 *flags
|= TXFLAG_TAGON
;
1852 *vlan
= cpu_to_le16(vlan_tx_tag_get(skb
));
1857 jme_fill_tx_desc(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
1859 struct jme_ring
*txring
= &(jme
->txring
[0]);
1860 struct txdesc
*txdesc
;
1861 struct jme_buffer_info
*txbi
;
1864 txdesc
= (struct txdesc
*)txring
->desc
+ idx
;
1865 txbi
= txring
->bufinf
+ idx
;
1871 txdesc
->desc1
.pktsize
= cpu_to_le16(skb
->len
);
1873 * Set OWN bit at final.
1874 * When kernel transmit faster than NIC.
1875 * And NIC trying to send this descriptor before we tell
1876 * it to start sending this TX queue.
1877 * Other fields are already filled correctly.
1880 flags
= TXFLAG_OWN
| TXFLAG_INT
;
1882 * Set checksum flags while not tso
1884 if (jme_tx_tso(skb
, &txdesc
->desc1
.mss
, &flags
))
1885 jme_tx_csum(jme
, skb
, &flags
);
1886 jme_tx_vlan(skb
, &txdesc
->desc1
.vlan
, &flags
);
1887 jme_map_tx_skb(jme
, skb
, idx
);
1888 txdesc
->desc1
.flags
= flags
;
1890 * Set tx buffer info after telling NIC to send
1891 * For better tx_clean timing
1894 txbi
->nr_desc
= skb_shinfo(skb
)->nr_frags
+ 2;
1896 txbi
->len
= skb
->len
;
1897 txbi
->start_xmit
= jiffies
;
1898 if (!txbi
->start_xmit
)
1899 txbi
->start_xmit
= (0UL-1);
1905 jme_stop_queue_if_full(struct jme_adapter
*jme
)
1907 struct jme_ring
*txring
= &(jme
->txring
[0]);
1908 struct jme_buffer_info
*txbi
= txring
->bufinf
;
1909 int idx
= atomic_read(&txring
->next_to_clean
);
1914 if (unlikely(atomic_read(&txring
->nr_free
) < (MAX_SKB_FRAGS
+2))) {
1915 netif_stop_queue(jme
->dev
);
1916 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Paused.\n");
1918 if (atomic_read(&txring
->nr_free
)
1919 >= (jme
->tx_wake_threshold
)) {
1920 netif_wake_queue(jme
->dev
);
1921 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Fast Waked.\n");
1925 if (unlikely(txbi
->start_xmit
&&
1926 (jiffies
- txbi
->start_xmit
) >= TX_TIMEOUT
&&
1928 netif_stop_queue(jme
->dev
);
1929 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Stopped %d@%lu.\n", idx
, jiffies
);
1934 * This function is already protected by netif_tx_lock()
1938 jme_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
1940 struct jme_adapter
*jme
= netdev_priv(netdev
);
1943 if (unlikely(jme_expand_header(jme
, skb
))) {
1944 ++(NET_STAT(jme
).tx_dropped
);
1945 return NETDEV_TX_OK
;
1948 idx
= jme_alloc_txdesc(jme
, skb
);
1950 if (unlikely(idx
< 0)) {
1951 netif_stop_queue(netdev
);
1952 netif_err(jme
, tx_err
, jme
->dev
, "BUG! Tx ring full when queue awake!\n");
1954 return NETDEV_TX_BUSY
;
1957 jme_fill_tx_desc(jme
, skb
, idx
);
1959 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
1960 TXCS_SELECT_QUEUE0
|
1964 tx_dbg(jme
, "xmit: %d+%d@%lu\n", idx
,
1965 skb_shinfo(skb
)->nr_frags
+ 2,
1967 jme_stop_queue_if_full(jme
);
1969 return NETDEV_TX_OK
;
1973 jme_set_macaddr(struct net_device
*netdev
, void *p
)
1975 struct jme_adapter
*jme
= netdev_priv(netdev
);
1976 struct sockaddr
*addr
= p
;
1979 if (netif_running(netdev
))
1982 spin_lock_bh(&jme
->macaddr_lock
);
1983 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
1985 val
= (addr
->sa_data
[3] & 0xff) << 24 |
1986 (addr
->sa_data
[2] & 0xff) << 16 |
1987 (addr
->sa_data
[1] & 0xff) << 8 |
1988 (addr
->sa_data
[0] & 0xff);
1989 jwrite32(jme
, JME_RXUMA_LO
, val
);
1990 val
= (addr
->sa_data
[5] & 0xff) << 8 |
1991 (addr
->sa_data
[4] & 0xff);
1992 jwrite32(jme
, JME_RXUMA_HI
, val
);
1993 spin_unlock_bh(&jme
->macaddr_lock
);
1999 jme_set_multi(struct net_device
*netdev
)
2001 struct jme_adapter
*jme
= netdev_priv(netdev
);
2002 u32 mc_hash
[2] = {};
2004 spin_lock_bh(&jme
->rxmcs_lock
);
2006 jme
->reg_rxmcs
|= RXMCS_BRDFRAME
| RXMCS_UNIFRAME
;
2008 if (netdev
->flags
& IFF_PROMISC
) {
2009 jme
->reg_rxmcs
|= RXMCS_ALLFRAME
;
2010 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2011 jme
->reg_rxmcs
|= RXMCS_ALLMULFRAME
;
2012 } else if (netdev
->flags
& IFF_MULTICAST
) {
2013 struct dev_mc_list
*mclist
;
2016 jme
->reg_rxmcs
|= RXMCS_MULFRAME
| RXMCS_MULFILTERED
;
2017 netdev_for_each_mc_addr(mclist
, netdev
) {
2018 bit_nr
= ether_crc(ETH_ALEN
, mclist
->dmi_addr
) & 0x3F;
2019 mc_hash
[bit_nr
>> 5] |= 1 << (bit_nr
& 0x1F);
2022 jwrite32(jme
, JME_RXMCHT_LO
, mc_hash
[0]);
2023 jwrite32(jme
, JME_RXMCHT_HI
, mc_hash
[1]);
2027 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2029 spin_unlock_bh(&jme
->rxmcs_lock
);
2033 jme_change_mtu(struct net_device
*netdev
, int new_mtu
)
2035 struct jme_adapter
*jme
= netdev_priv(netdev
);
2037 if (new_mtu
== jme
->old_mtu
)
2040 if (((new_mtu
+ ETH_HLEN
) > MAX_ETHERNET_JUMBO_PACKET_SIZE
) ||
2041 ((new_mtu
) < IPV6_MIN_MTU
))
2044 if (new_mtu
> 4000) {
2045 jme
->reg_rxcs
&= ~RXCS_FIFOTHNP
;
2046 jme
->reg_rxcs
|= RXCS_FIFOTHNP_64QW
;
2047 jme_restart_rx_engine(jme
);
2049 jme
->reg_rxcs
&= ~RXCS_FIFOTHNP
;
2050 jme
->reg_rxcs
|= RXCS_FIFOTHNP_128QW
;
2051 jme_restart_rx_engine(jme
);
2054 if (new_mtu
> 1900) {
2055 netdev
->features
&= ~(NETIF_F_HW_CSUM
|
2059 if (test_bit(JME_FLAG_TXCSUM
, &jme
->flags
))
2060 netdev
->features
|= NETIF_F_HW_CSUM
;
2061 if (test_bit(JME_FLAG_TSO
, &jme
->flags
))
2062 netdev
->features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
2065 netdev
->mtu
= new_mtu
;
2066 jme_reset_link(jme
);
2072 jme_tx_timeout(struct net_device
*netdev
)
2074 struct jme_adapter
*jme
= netdev_priv(netdev
);
2077 jme_reset_phy_processor(jme
);
2078 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
2079 jme_set_settings(netdev
, &jme
->old_ecmd
);
2082 * Force to Reset the link again
2084 jme_reset_link(jme
);
2087 static inline void jme_pause_rx(struct jme_adapter
*jme
)
2089 atomic_dec(&jme
->link_changing
);
2091 jme_set_rx_pcc(jme
, PCC_OFF
);
2092 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2093 JME_NAPI_DISABLE(jme
);
2095 tasklet_disable(&jme
->rxclean_task
);
2096 tasklet_disable(&jme
->rxempty_task
);
2100 static inline void jme_resume_rx(struct jme_adapter
*jme
)
2102 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2104 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2105 JME_NAPI_ENABLE(jme
);
2107 tasklet_hi_enable(&jme
->rxclean_task
);
2108 tasklet_hi_enable(&jme
->rxempty_task
);
2111 dpi
->attempt
= PCC_P1
;
2113 jme_set_rx_pcc(jme
, PCC_P1
);
2115 atomic_inc(&jme
->link_changing
);
2119 jme_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
2121 struct jme_adapter
*jme
= netdev_priv(netdev
);
2129 jme_get_drvinfo(struct net_device
*netdev
,
2130 struct ethtool_drvinfo
*info
)
2132 struct jme_adapter
*jme
= netdev_priv(netdev
);
2134 strcpy(info
->driver
, DRV_NAME
);
2135 strcpy(info
->version
, DRV_VERSION
);
2136 strcpy(info
->bus_info
, pci_name(jme
->pdev
));
2140 jme_get_regs_len(struct net_device
*netdev
)
2146 mmapio_memcpy(struct jme_adapter
*jme
, u32
*p
, u32 reg
, int len
)
2150 for (i
= 0 ; i
< len
; i
+= 4)
2151 p
[i
>> 2] = jread32(jme
, reg
+ i
);
2155 mdio_memcpy(struct jme_adapter
*jme
, u32
*p
, int reg_nr
)
2158 u16
*p16
= (u16
*)p
;
2160 for (i
= 0 ; i
< reg_nr
; ++i
)
2161 p16
[i
] = jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, i
);
2165 jme_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
2167 struct jme_adapter
*jme
= netdev_priv(netdev
);
2168 u32
*p32
= (u32
*)p
;
2170 memset(p
, 0xFF, JME_REG_LEN
);
2173 mmapio_memcpy(jme
, p32
, JME_MAC
, JME_MAC_LEN
);
2176 mmapio_memcpy(jme
, p32
, JME_PHY
, JME_PHY_LEN
);
2179 mmapio_memcpy(jme
, p32
, JME_MISC
, JME_MISC_LEN
);
2182 mmapio_memcpy(jme
, p32
, JME_RSS
, JME_RSS_LEN
);
2185 mdio_memcpy(jme
, p32
, JME_PHY_REG_NR
);
2189 jme_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2191 struct jme_adapter
*jme
= netdev_priv(netdev
);
2193 ecmd
->tx_coalesce_usecs
= PCC_TX_TO
;
2194 ecmd
->tx_max_coalesced_frames
= PCC_TX_CNT
;
2196 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2197 ecmd
->use_adaptive_rx_coalesce
= false;
2198 ecmd
->rx_coalesce_usecs
= 0;
2199 ecmd
->rx_max_coalesced_frames
= 0;
2203 ecmd
->use_adaptive_rx_coalesce
= true;
2205 switch (jme
->dpi
.cur
) {
2207 ecmd
->rx_coalesce_usecs
= PCC_P1_TO
;
2208 ecmd
->rx_max_coalesced_frames
= PCC_P1_CNT
;
2211 ecmd
->rx_coalesce_usecs
= PCC_P2_TO
;
2212 ecmd
->rx_max_coalesced_frames
= PCC_P2_CNT
;
2215 ecmd
->rx_coalesce_usecs
= PCC_P3_TO
;
2216 ecmd
->rx_max_coalesced_frames
= PCC_P3_CNT
;
2226 jme_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2228 struct jme_adapter
*jme
= netdev_priv(netdev
);
2229 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2231 if (netif_running(netdev
))
2234 if (ecmd
->use_adaptive_rx_coalesce
&&
2235 test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2236 clear_bit(JME_FLAG_POLL
, &jme
->flags
);
2237 jme
->jme_rx
= netif_rx
;
2238 jme
->jme_vlan_rx
= vlan_hwaccel_rx
;
2240 dpi
->attempt
= PCC_P1
;
2242 jme_set_rx_pcc(jme
, PCC_P1
);
2243 jme_interrupt_mode(jme
);
2244 } else if (!(ecmd
->use_adaptive_rx_coalesce
) &&
2245 !(test_bit(JME_FLAG_POLL
, &jme
->flags
))) {
2246 set_bit(JME_FLAG_POLL
, &jme
->flags
);
2247 jme
->jme_rx
= netif_receive_skb
;
2248 jme
->jme_vlan_rx
= vlan_hwaccel_receive_skb
;
2249 jme_interrupt_mode(jme
);
2256 jme_get_pauseparam(struct net_device
*netdev
,
2257 struct ethtool_pauseparam
*ecmd
)
2259 struct jme_adapter
*jme
= netdev_priv(netdev
);
2262 ecmd
->tx_pause
= (jme
->reg_txpfc
& TXPFC_PF_EN
) != 0;
2263 ecmd
->rx_pause
= (jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0;
2265 spin_lock_bh(&jme
->phy_lock
);
2266 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2267 spin_unlock_bh(&jme
->phy_lock
);
2270 (val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0;
2274 jme_set_pauseparam(struct net_device
*netdev
,
2275 struct ethtool_pauseparam
*ecmd
)
2277 struct jme_adapter
*jme
= netdev_priv(netdev
);
2280 if (((jme
->reg_txpfc
& TXPFC_PF_EN
) != 0) ^
2281 (ecmd
->tx_pause
!= 0)) {
2284 jme
->reg_txpfc
|= TXPFC_PF_EN
;
2286 jme
->reg_txpfc
&= ~TXPFC_PF_EN
;
2288 jwrite32(jme
, JME_TXPFC
, jme
->reg_txpfc
);
2291 spin_lock_bh(&jme
->rxmcs_lock
);
2292 if (((jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0) ^
2293 (ecmd
->rx_pause
!= 0)) {
2296 jme
->reg_rxmcs
|= RXMCS_FLOWCTRL
;
2298 jme
->reg_rxmcs
&= ~RXMCS_FLOWCTRL
;
2300 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2302 spin_unlock_bh(&jme
->rxmcs_lock
);
2304 spin_lock_bh(&jme
->phy_lock
);
2305 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2306 if (((val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0) ^
2307 (ecmd
->autoneg
!= 0)) {
2310 val
|= (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2312 val
&= ~(ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2314 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
,
2315 MII_ADVERTISE
, val
);
2317 spin_unlock_bh(&jme
->phy_lock
);
2323 jme_get_wol(struct net_device
*netdev
,
2324 struct ethtool_wolinfo
*wol
)
2326 struct jme_adapter
*jme
= netdev_priv(netdev
);
2328 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
2332 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
2333 wol
->wolopts
|= WAKE_PHY
;
2335 if (jme
->reg_pmcs
& PMCS_MFEN
)
2336 wol
->wolopts
|= WAKE_MAGIC
;
2341 jme_set_wol(struct net_device
*netdev
,
2342 struct ethtool_wolinfo
*wol
)
2344 struct jme_adapter
*jme
= netdev_priv(netdev
);
2346 if (wol
->wolopts
& (WAKE_MAGICSECURE
|
2355 if (wol
->wolopts
& WAKE_PHY
)
2356 jme
->reg_pmcs
|= PMCS_LFEN
| PMCS_LREN
;
2358 if (wol
->wolopts
& WAKE_MAGIC
)
2359 jme
->reg_pmcs
|= PMCS_MFEN
;
2361 jwrite32(jme
, JME_PMCS
, jme
->reg_pmcs
);
2367 jme_get_settings(struct net_device
*netdev
,
2368 struct ethtool_cmd
*ecmd
)
2370 struct jme_adapter
*jme
= netdev_priv(netdev
);
2373 spin_lock_bh(&jme
->phy_lock
);
2374 rc
= mii_ethtool_gset(&(jme
->mii_if
), ecmd
);
2375 spin_unlock_bh(&jme
->phy_lock
);
2380 jme_set_settings(struct net_device
*netdev
,
2381 struct ethtool_cmd
*ecmd
)
2383 struct jme_adapter
*jme
= netdev_priv(netdev
);
2386 if (ecmd
->speed
== SPEED_1000
&& ecmd
->autoneg
!= AUTONEG_ENABLE
)
2389 if (jme
->mii_if
.force_media
&&
2390 ecmd
->autoneg
!= AUTONEG_ENABLE
&&
2391 (jme
->mii_if
.full_duplex
!= ecmd
->duplex
))
2394 spin_lock_bh(&jme
->phy_lock
);
2395 rc
= mii_ethtool_sset(&(jme
->mii_if
), ecmd
);
2396 spin_unlock_bh(&jme
->phy_lock
);
2399 jme_reset_link(jme
);
2402 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2403 jme
->old_ecmd
= *ecmd
;
2410 jme_get_link(struct net_device
*netdev
)
2412 struct jme_adapter
*jme
= netdev_priv(netdev
);
2413 return jread32(jme
, JME_PHY_LINK
) & PHY_LINK_UP
;
2417 jme_get_msglevel(struct net_device
*netdev
)
2419 struct jme_adapter
*jme
= netdev_priv(netdev
);
2420 return jme
->msg_enable
;
2424 jme_set_msglevel(struct net_device
*netdev
, u32 value
)
2426 struct jme_adapter
*jme
= netdev_priv(netdev
);
2427 jme
->msg_enable
= value
;
2431 jme_get_rx_csum(struct net_device
*netdev
)
2433 struct jme_adapter
*jme
= netdev_priv(netdev
);
2434 return jme
->reg_rxmcs
& RXMCS_CHECKSUM
;
2438 jme_set_rx_csum(struct net_device
*netdev
, u32 on
)
2440 struct jme_adapter
*jme
= netdev_priv(netdev
);
2442 spin_lock_bh(&jme
->rxmcs_lock
);
2444 jme
->reg_rxmcs
|= RXMCS_CHECKSUM
;
2446 jme
->reg_rxmcs
&= ~RXMCS_CHECKSUM
;
2447 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2448 spin_unlock_bh(&jme
->rxmcs_lock
);
2454 jme_set_tx_csum(struct net_device
*netdev
, u32 on
)
2456 struct jme_adapter
*jme
= netdev_priv(netdev
);
2459 set_bit(JME_FLAG_TXCSUM
, &jme
->flags
);
2460 if (netdev
->mtu
<= 1900)
2461 netdev
->features
|= NETIF_F_HW_CSUM
;
2463 clear_bit(JME_FLAG_TXCSUM
, &jme
->flags
);
2464 netdev
->features
&= ~NETIF_F_HW_CSUM
;
2471 jme_set_tso(struct net_device
*netdev
, u32 on
)
2473 struct jme_adapter
*jme
= netdev_priv(netdev
);
2476 set_bit(JME_FLAG_TSO
, &jme
->flags
);
2477 if (netdev
->mtu
<= 1900)
2478 netdev
->features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
2480 clear_bit(JME_FLAG_TSO
, &jme
->flags
);
2481 netdev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO6
);
2488 jme_nway_reset(struct net_device
*netdev
)
2490 struct jme_adapter
*jme
= netdev_priv(netdev
);
2491 jme_restart_an(jme
);
2496 jme_smb_read(struct jme_adapter
*jme
, unsigned int addr
)
2501 val
= jread32(jme
, JME_SMBCSR
);
2502 to
= JME_SMB_BUSY_TIMEOUT
;
2503 while ((val
& SMBCSR_BUSY
) && --to
) {
2505 val
= jread32(jme
, JME_SMBCSR
);
2508 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy.\n");
2512 jwrite32(jme
, JME_SMBINTF
,
2513 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2514 SMBINTF_HWRWN_READ
|
2517 val
= jread32(jme
, JME_SMBINTF
);
2518 to
= JME_SMB_BUSY_TIMEOUT
;
2519 while ((val
& SMBINTF_HWCMD
) && --to
) {
2521 val
= jread32(jme
, JME_SMBINTF
);
2524 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy.\n");
2528 return (val
& SMBINTF_HWDATR
) >> SMBINTF_HWDATR_SHIFT
;
2532 jme_smb_write(struct jme_adapter
*jme
, unsigned int addr
, u8 data
)
2537 val
= jread32(jme
, JME_SMBCSR
);
2538 to
= JME_SMB_BUSY_TIMEOUT
;
2539 while ((val
& SMBCSR_BUSY
) && --to
) {
2541 val
= jread32(jme
, JME_SMBCSR
);
2544 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy.\n");
2548 jwrite32(jme
, JME_SMBINTF
,
2549 ((data
<< SMBINTF_HWDATW_SHIFT
) & SMBINTF_HWDATW
) |
2550 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2551 SMBINTF_HWRWN_WRITE
|
2554 val
= jread32(jme
, JME_SMBINTF
);
2555 to
= JME_SMB_BUSY_TIMEOUT
;
2556 while ((val
& SMBINTF_HWCMD
) && --to
) {
2558 val
= jread32(jme
, JME_SMBINTF
);
2561 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy.\n");
2569 jme_get_eeprom_len(struct net_device
*netdev
)
2571 struct jme_adapter
*jme
= netdev_priv(netdev
);
2573 val
= jread32(jme
, JME_SMBCSR
);
2574 return (val
& SMBCSR_EEPROMD
) ? JME_SMB_LEN
: 0;
2578 jme_get_eeprom(struct net_device
*netdev
,
2579 struct ethtool_eeprom
*eeprom
, u8
*data
)
2581 struct jme_adapter
*jme
= netdev_priv(netdev
);
2582 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2585 * ethtool will check the boundary for us
2587 eeprom
->magic
= JME_EEPROM_MAGIC
;
2588 for (i
= 0 ; i
< len
; ++i
)
2589 data
[i
] = jme_smb_read(jme
, i
+ offset
);
2595 jme_set_eeprom(struct net_device
*netdev
,
2596 struct ethtool_eeprom
*eeprom
, u8
*data
)
2598 struct jme_adapter
*jme
= netdev_priv(netdev
);
2599 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2601 if (eeprom
->magic
!= JME_EEPROM_MAGIC
)
2605 * ethtool will check the boundary for us
2607 for (i
= 0 ; i
< len
; ++i
)
2608 jme_smb_write(jme
, i
+ offset
, data
[i
]);
2613 static const struct ethtool_ops jme_ethtool_ops
= {
2614 .get_drvinfo
= jme_get_drvinfo
,
2615 .get_regs_len
= jme_get_regs_len
,
2616 .get_regs
= jme_get_regs
,
2617 .get_coalesce
= jme_get_coalesce
,
2618 .set_coalesce
= jme_set_coalesce
,
2619 .get_pauseparam
= jme_get_pauseparam
,
2620 .set_pauseparam
= jme_set_pauseparam
,
2621 .get_wol
= jme_get_wol
,
2622 .set_wol
= jme_set_wol
,
2623 .get_settings
= jme_get_settings
,
2624 .set_settings
= jme_set_settings
,
2625 .get_link
= jme_get_link
,
2626 .get_msglevel
= jme_get_msglevel
,
2627 .set_msglevel
= jme_set_msglevel
,
2628 .get_rx_csum
= jme_get_rx_csum
,
2629 .set_rx_csum
= jme_set_rx_csum
,
2630 .set_tx_csum
= jme_set_tx_csum
,
2631 .set_tso
= jme_set_tso
,
2632 .set_sg
= ethtool_op_set_sg
,
2633 .nway_reset
= jme_nway_reset
,
2634 .get_eeprom_len
= jme_get_eeprom_len
,
2635 .get_eeprom
= jme_get_eeprom
,
2636 .set_eeprom
= jme_set_eeprom
,
2640 jme_pci_dma64(struct pci_dev
*pdev
)
2642 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2643 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
2644 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
2647 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2648 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(40)))
2649 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(40)))
2652 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)))
2653 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
2660 jme_phy_init(struct jme_adapter
*jme
)
2664 reg26
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 26);
2665 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 26, reg26
| 0x1000);
2669 jme_check_hw_ver(struct jme_adapter
*jme
)
2673 chipmode
= jread32(jme
, JME_CHIPMODE
);
2675 jme
->fpgaver
= (chipmode
& CM_FPGAVER_MASK
) >> CM_FPGAVER_SHIFT
;
2676 jme
->chiprev
= (chipmode
& CM_CHIPREV_MASK
) >> CM_CHIPREV_SHIFT
;
2679 static const struct net_device_ops jme_netdev_ops
= {
2680 .ndo_open
= jme_open
,
2681 .ndo_stop
= jme_close
,
2682 .ndo_validate_addr
= eth_validate_addr
,
2683 .ndo_start_xmit
= jme_start_xmit
,
2684 .ndo_set_mac_address
= jme_set_macaddr
,
2685 .ndo_set_multicast_list
= jme_set_multi
,
2686 .ndo_change_mtu
= jme_change_mtu
,
2687 .ndo_tx_timeout
= jme_tx_timeout
,
2688 .ndo_vlan_rx_register
= jme_vlan_rx_register
,
2691 static int __devinit
2692 jme_init_one(struct pci_dev
*pdev
,
2693 const struct pci_device_id
*ent
)
2695 int rc
= 0, using_dac
, i
;
2696 struct net_device
*netdev
;
2697 struct jme_adapter
*jme
;
2702 * set up PCI device basics
2704 rc
= pci_enable_device(pdev
);
2706 jeprintk(pdev
, "Cannot enable PCI device.\n");
2710 using_dac
= jme_pci_dma64(pdev
);
2711 if (using_dac
< 0) {
2712 jeprintk(pdev
, "Cannot set PCI DMA Mask.\n");
2714 goto err_out_disable_pdev
;
2717 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
2718 jeprintk(pdev
, "No PCI resource region found.\n");
2720 goto err_out_disable_pdev
;
2723 rc
= pci_request_regions(pdev
, DRV_NAME
);
2725 jeprintk(pdev
, "Cannot obtain PCI resource region.\n");
2726 goto err_out_disable_pdev
;
2729 pci_set_master(pdev
);
2732 * alloc and init net device
2734 netdev
= alloc_etherdev(sizeof(*jme
));
2736 jeprintk(pdev
, "Cannot allocate netdev structure.\n");
2738 goto err_out_release_regions
;
2740 netdev
->netdev_ops
= &jme_netdev_ops
;
2741 netdev
->ethtool_ops
= &jme_ethtool_ops
;
2742 netdev
->watchdog_timeo
= TX_TIMEOUT
;
2743 netdev
->features
= NETIF_F_HW_CSUM
|
2747 NETIF_F_HW_VLAN_TX
|
2750 netdev
->features
|= NETIF_F_HIGHDMA
;
2752 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2753 pci_set_drvdata(pdev
, netdev
);
2758 jme
= netdev_priv(netdev
);
2761 jme
->jme_rx
= netif_rx
;
2762 jme
->jme_vlan_rx
= vlan_hwaccel_rx
;
2763 jme
->old_mtu
= netdev
->mtu
= 1500;
2765 jme
->tx_ring_size
= 1 << 10;
2766 jme
->tx_ring_mask
= jme
->tx_ring_size
- 1;
2767 jme
->tx_wake_threshold
= 1 << 9;
2768 jme
->rx_ring_size
= 1 << 9;
2769 jme
->rx_ring_mask
= jme
->rx_ring_size
- 1;
2770 jme
->msg_enable
= JME_DEF_MSG_ENABLE
;
2771 jme
->regs
= ioremap(pci_resource_start(pdev
, 0),
2772 pci_resource_len(pdev
, 0));
2774 jeprintk(pdev
, "Mapping PCI resource region error.\n");
2776 goto err_out_free_netdev
;
2780 apmc
= jread32(jme
, JME_APMC
) & ~JME_APMC_PSEUDO_HP_EN
;
2781 jwrite32(jme
, JME_APMC
, apmc
);
2782 } else if (force_pseudohp
) {
2783 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PSEUDO_HP_EN
;
2784 jwrite32(jme
, JME_APMC
, apmc
);
2787 NETIF_NAPI_SET(netdev
, &jme
->napi
, jme_poll
, jme
->rx_ring_size
>> 2)
2789 spin_lock_init(&jme
->phy_lock
);
2790 spin_lock_init(&jme
->macaddr_lock
);
2791 spin_lock_init(&jme
->rxmcs_lock
);
2793 atomic_set(&jme
->link_changing
, 1);
2794 atomic_set(&jme
->rx_cleaning
, 1);
2795 atomic_set(&jme
->tx_cleaning
, 1);
2796 atomic_set(&jme
->rx_empty
, 1);
2798 tasklet_init(&jme
->pcc_task
,
2800 (unsigned long) jme
);
2801 tasklet_init(&jme
->linkch_task
,
2802 jme_link_change_tasklet
,
2803 (unsigned long) jme
);
2804 tasklet_init(&jme
->txclean_task
,
2805 jme_tx_clean_tasklet
,
2806 (unsigned long) jme
);
2807 tasklet_init(&jme
->rxclean_task
,
2808 jme_rx_clean_tasklet
,
2809 (unsigned long) jme
);
2810 tasklet_init(&jme
->rxempty_task
,
2811 jme_rx_empty_tasklet
,
2812 (unsigned long) jme
);
2813 tasklet_disable_nosync(&jme
->linkch_task
);
2814 tasklet_disable_nosync(&jme
->txclean_task
);
2815 tasklet_disable_nosync(&jme
->rxclean_task
);
2816 tasklet_disable_nosync(&jme
->rxempty_task
);
2817 jme
->dpi
.cur
= PCC_P1
;
2820 jme
->reg_rxcs
= RXCS_DEFAULT
;
2821 jme
->reg_rxmcs
= RXMCS_DEFAULT
;
2823 jme
->reg_pmcs
= PMCS_MFEN
;
2824 set_bit(JME_FLAG_TXCSUM
, &jme
->flags
);
2825 set_bit(JME_FLAG_TSO
, &jme
->flags
);
2828 * Get Max Read Req Size from PCI Config Space
2830 pci_read_config_byte(pdev
, PCI_DCSR_MRRS
, &jme
->mrrs
);
2831 jme
->mrrs
&= PCI_DCSR_MRRS_MASK
;
2832 switch (jme
->mrrs
) {
2834 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_128B
;
2837 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_256B
;
2840 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_512B
;
2845 * Must check before reset_mac_processor
2847 jme_check_hw_ver(jme
);
2848 jme
->mii_if
.dev
= netdev
;
2850 jme
->mii_if
.phy_id
= 0;
2851 for (i
= 1 ; i
< 32 ; ++i
) {
2852 bmcr
= jme_mdio_read(netdev
, i
, MII_BMCR
);
2853 bmsr
= jme_mdio_read(netdev
, i
, MII_BMSR
);
2854 if (bmcr
!= 0xFFFFU
&& (bmcr
!= 0 || bmsr
!= 0)) {
2855 jme
->mii_if
.phy_id
= i
;
2860 if (!jme
->mii_if
.phy_id
) {
2862 jeprintk(pdev
, "Can not find phy_id.\n");
2866 jme
->reg_ghc
|= GHC_LINK_POLL
;
2868 jme
->mii_if
.phy_id
= 1;
2870 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
2871 jme
->mii_if
.supports_gmii
= true;
2873 jme
->mii_if
.supports_gmii
= false;
2874 jme
->mii_if
.mdio_read
= jme_mdio_read
;
2875 jme
->mii_if
.mdio_write
= jme_mdio_write
;
2878 jme_set_phyfifoa(jme
);
2879 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &jme
->rev
);
2885 * Reset MAC processor and reload EEPROM for MAC Address
2887 jme_reset_mac_processor(jme
);
2888 rc
= jme_reload_eeprom(jme
);
2891 "Reload eeprom for reading MAC Address error.\n");
2894 jme_load_macaddr(netdev
);
2897 * Tell stack that we are not ready to work until open()
2899 netif_carrier_off(netdev
);
2900 netif_stop_queue(netdev
);
2905 rc
= register_netdev(netdev
);
2907 jeprintk(pdev
, "Cannot register net device.\n");
2911 netif_info(jme
, probe
, jme
->dev
, "%s%s ver:%x rev:%x macaddr:%pM\n",
2912 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
) ?
2913 "JMC250 Gigabit Ethernet" :
2914 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC260
) ?
2915 "JMC260 Fast Ethernet" : "Unknown",
2916 (jme
->fpgaver
!= 0) ? " (FPGA)" : "",
2917 (jme
->fpgaver
!= 0) ? jme
->fpgaver
: jme
->chiprev
,
2918 jme
->rev
, netdev
->dev_addr
);
2924 err_out_free_netdev
:
2925 pci_set_drvdata(pdev
, NULL
);
2926 free_netdev(netdev
);
2927 err_out_release_regions
:
2928 pci_release_regions(pdev
);
2929 err_out_disable_pdev
:
2930 pci_disable_device(pdev
);
2935 static void __devexit
2936 jme_remove_one(struct pci_dev
*pdev
)
2938 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2939 struct jme_adapter
*jme
= netdev_priv(netdev
);
2941 unregister_netdev(netdev
);
2943 pci_set_drvdata(pdev
, NULL
);
2944 free_netdev(netdev
);
2945 pci_release_regions(pdev
);
2946 pci_disable_device(pdev
);
2952 jme_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2954 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2955 struct jme_adapter
*jme
= netdev_priv(netdev
);
2957 atomic_dec(&jme
->link_changing
);
2959 netif_device_detach(netdev
);
2960 netif_stop_queue(netdev
);
2963 tasklet_disable(&jme
->txclean_task
);
2964 tasklet_disable(&jme
->rxclean_task
);
2965 tasklet_disable(&jme
->rxempty_task
);
2967 if (netif_carrier_ok(netdev
)) {
2968 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
2969 jme_polling_mode(jme
);
2971 jme_stop_pcc_timer(jme
);
2972 jme_reset_ghc_speed(jme
);
2973 jme_disable_rx_engine(jme
);
2974 jme_disable_tx_engine(jme
);
2975 jme_reset_mac_processor(jme
);
2976 jme_free_rx_resources(jme
);
2977 jme_free_tx_resources(jme
);
2978 netif_carrier_off(netdev
);
2982 tasklet_enable(&jme
->txclean_task
);
2983 tasklet_hi_enable(&jme
->rxclean_task
);
2984 tasklet_hi_enable(&jme
->rxempty_task
);
2986 pci_save_state(pdev
);
2987 if (jme
->reg_pmcs
) {
2988 jme_set_100m_half(jme
);
2990 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
2993 jwrite32(jme
, JME_PMCS
, jme
->reg_pmcs
);
2995 pci_enable_wake(pdev
, PCI_D3cold
, true);
2999 pci_set_power_state(pdev
, PCI_D3cold
);
3005 jme_resume(struct pci_dev
*pdev
)
3007 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3008 struct jme_adapter
*jme
= netdev_priv(netdev
);
3011 pci_restore_state(pdev
);
3013 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
3014 jme_set_settings(netdev
, &jme
->old_ecmd
);
3016 jme_reset_phy_processor(jme
);
3019 netif_device_attach(netdev
);
3021 atomic_inc(&jme
->link_changing
);
3023 jme_reset_link(jme
);
3029 static DEFINE_PCI_DEVICE_TABLE(jme_pci_tbl
) = {
3030 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC250
) },
3031 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC260
) },
3035 static struct pci_driver jme_driver
= {
3037 .id_table
= jme_pci_tbl
,
3038 .probe
= jme_init_one
,
3039 .remove
= __devexit_p(jme_remove_one
),
3041 .suspend
= jme_suspend
,
3042 .resume
= jme_resume
,
3043 #endif /* CONFIG_PM */
3047 jme_init_module(void)
3049 printk(KERN_INFO PFX
"JMicron JMC2XX ethernet "
3050 "driver version %s\n", DRV_VERSION
);
3051 return pci_register_driver(&jme_driver
);
3055 jme_cleanup_module(void)
3057 pci_unregister_driver(&jme_driver
);
3060 module_init(jme_init_module
);
3061 module_exit(jme_cleanup_module
);
3063 MODULE_AUTHOR("Guo-Fu Tseng <cooldavid@cooldavid.org>");
3064 MODULE_DESCRIPTION("JMicron JMC2x0 PCI Express Ethernet driver");
3065 MODULE_LICENSE("GPL");
3066 MODULE_VERSION(DRV_VERSION
);
3067 MODULE_DEVICE_TABLE(pci
, jme_pci_tbl
);