2 * JMicron JMC2x0 series PCIe Ethernet Linux Device Driver
4 * Copyright 2008 JMicron Technology Corporation
5 * http://www.jmicron.com/
6 * Copyright (c) 2009 - 2010 Guo-Fu Tseng <cooldavid@cooldavid.org>
8 * Author: Guo-Fu Tseng <cooldavid@cooldavid.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/pci.h>
30 #include <linux/pci-aspm.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/ethtool.h>
34 #include <linux/mii.h>
35 #include <linux/crc32.h>
36 #include <linux/delay.h>
37 #include <linux/spinlock.h>
40 #include <linux/ipv6.h>
41 #include <linux/tcp.h>
42 #include <linux/udp.h>
43 #include <linux/if_vlan.h>
44 #include <linux/slab.h>
45 #include <net/ip6_checksum.h>
48 static int force_pseudohp
= -1;
49 static int no_pseudohp
= -1;
50 static int no_extplug
= -1;
51 module_param(force_pseudohp
, int, 0);
52 MODULE_PARM_DESC(force_pseudohp
,
53 "Enable pseudo hot-plug feature manually by driver instead of BIOS.");
54 module_param(no_pseudohp
, int, 0);
55 MODULE_PARM_DESC(no_pseudohp
, "Disable pseudo hot-plug feature.");
56 module_param(no_extplug
, int, 0);
57 MODULE_PARM_DESC(no_extplug
,
58 "Do not use external plug signal for pseudo hot-plug.");
61 jme_mdio_read(struct net_device
*netdev
, int phy
, int reg
)
63 struct jme_adapter
*jme
= netdev_priv(netdev
);
64 int i
, val
, again
= (reg
== MII_BMSR
) ? 1 : 0;
67 jwrite32(jme
, JME_SMI
, SMI_OP_REQ
|
72 for (i
= JME_PHY_TIMEOUT
* 50 ; i
> 0 ; --i
) {
74 val
= jread32(jme
, JME_SMI
);
75 if ((val
& SMI_OP_REQ
) == 0)
80 pr_err("phy(%d) read timeout : %d\n", phy
, reg
);
87 return (val
& SMI_DATA_MASK
) >> SMI_DATA_SHIFT
;
91 jme_mdio_write(struct net_device
*netdev
,
92 int phy
, int reg
, int val
)
94 struct jme_adapter
*jme
= netdev_priv(netdev
);
97 jwrite32(jme
, JME_SMI
, SMI_OP_WRITE
| SMI_OP_REQ
|
98 ((val
<< SMI_DATA_SHIFT
) & SMI_DATA_MASK
) |
99 smi_phy_addr(phy
) | smi_reg_addr(reg
));
102 for (i
= JME_PHY_TIMEOUT
* 50 ; i
> 0 ; --i
) {
104 if ((jread32(jme
, JME_SMI
) & SMI_OP_REQ
) == 0)
109 pr_err("phy(%d) write timeout : %d\n", phy
, reg
);
113 jme_reset_phy_processor(struct jme_adapter
*jme
)
117 jme_mdio_write(jme
->dev
,
119 MII_ADVERTISE
, ADVERTISE_ALL
|
120 ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
122 if (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
123 jme_mdio_write(jme
->dev
,
126 ADVERTISE_1000FULL
| ADVERTISE_1000HALF
);
128 val
= jme_mdio_read(jme
->dev
,
132 jme_mdio_write(jme
->dev
,
134 MII_BMCR
, val
| BMCR_RESET
);
138 jme_setup_wakeup_frame(struct jme_adapter
*jme
,
139 const 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_mac_rxclk_off(struct jme_adapter
*jme
)
167 jme
->reg_gpreg1
|= GPREG1_RXCLKOFF
;
168 jwrite32f(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
172 jme_mac_rxclk_on(struct jme_adapter
*jme
)
174 jme
->reg_gpreg1
&= ~GPREG1_RXCLKOFF
;
175 jwrite32f(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
179 jme_mac_txclk_off(struct jme_adapter
*jme
)
181 jme
->reg_ghc
&= ~(GHC_TO_CLK_SRC
| GHC_TXMAC_CLK_SRC
);
182 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
186 jme_mac_txclk_on(struct jme_adapter
*jme
)
188 u32 speed
= jme
->reg_ghc
& GHC_SPEED
;
189 if (speed
== GHC_SPEED_1000M
)
190 jme
->reg_ghc
|= GHC_TO_CLK_GPHY
| GHC_TXMAC_CLK_GPHY
;
192 jme
->reg_ghc
|= GHC_TO_CLK_PCIE
| GHC_TXMAC_CLK_PCIE
;
193 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
197 jme_reset_ghc_speed(struct jme_adapter
*jme
)
199 jme
->reg_ghc
&= ~(GHC_SPEED
| GHC_DPX
);
200 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
204 jme_reset_250A2_workaround(struct jme_adapter
*jme
)
206 jme
->reg_gpreg1
&= ~(GPREG1_HALFMODEPATCH
|
208 jwrite32(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
212 jme_assert_ghc_reset(struct jme_adapter
*jme
)
214 jme
->reg_ghc
|= GHC_SWRST
;
215 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
219 jme_clear_ghc_reset(struct jme_adapter
*jme
)
221 jme
->reg_ghc
&= ~GHC_SWRST
;
222 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
226 jme_reset_mac_processor(struct jme_adapter
*jme
)
228 static const u32 mask
[WAKEUP_FRAME_MASK_DWNR
] = {0, 0, 0, 0};
229 u32 crc
= 0xCDCDCDCD;
233 jme_reset_ghc_speed(jme
);
234 jme_reset_250A2_workaround(jme
);
236 jme_mac_rxclk_on(jme
);
237 jme_mac_txclk_on(jme
);
239 jme_assert_ghc_reset(jme
);
241 jme_mac_rxclk_off(jme
);
242 jme_mac_txclk_off(jme
);
244 jme_clear_ghc_reset(jme
);
246 jme_mac_rxclk_on(jme
);
247 jme_mac_txclk_on(jme
);
249 jme_mac_rxclk_off(jme
);
250 jme_mac_txclk_off(jme
);
252 jwrite32(jme
, JME_RXDBA_LO
, 0x00000000);
253 jwrite32(jme
, JME_RXDBA_HI
, 0x00000000);
254 jwrite32(jme
, JME_RXQDC
, 0x00000000);
255 jwrite32(jme
, JME_RXNDA
, 0x00000000);
256 jwrite32(jme
, JME_TXDBA_LO
, 0x00000000);
257 jwrite32(jme
, JME_TXDBA_HI
, 0x00000000);
258 jwrite32(jme
, JME_TXQDC
, 0x00000000);
259 jwrite32(jme
, JME_TXNDA
, 0x00000000);
261 jwrite32(jme
, JME_RXMCHT_LO
, 0x00000000);
262 jwrite32(jme
, JME_RXMCHT_HI
, 0x00000000);
263 for (i
= 0 ; i
< WAKEUP_FRAME_NR
; ++i
)
264 jme_setup_wakeup_frame(jme
, mask
, crc
, i
);
266 gpreg0
= GPREG0_DEFAULT
| GPREG0_LNKINTPOLL
;
268 gpreg0
= GPREG0_DEFAULT
;
269 jwrite32(jme
, JME_GPREG0
, gpreg0
);
273 jme_clear_pm_enable_wol(struct jme_adapter
*jme
)
275 jwrite32(jme
, JME_PMCS
, PMCS_STMASK
| jme
->reg_pmcs
);
279 jme_clear_pm_disable_wol(struct jme_adapter
*jme
)
281 jwrite32(jme
, JME_PMCS
, PMCS_STMASK
);
285 jme_reload_eeprom(struct jme_adapter
*jme
)
290 val
= jread32(jme
, JME_SMBCSR
);
292 if (val
& SMBCSR_EEPROMD
) {
294 jwrite32(jme
, JME_SMBCSR
, val
);
295 val
|= SMBCSR_RELOAD
;
296 jwrite32(jme
, JME_SMBCSR
, val
);
299 for (i
= JME_EEPROM_RELOAD_TIMEOUT
; i
> 0; --i
) {
301 if ((jread32(jme
, JME_SMBCSR
) & SMBCSR_RELOAD
) == 0)
306 pr_err("eeprom reload timeout\n");
315 jme_load_macaddr(struct net_device
*netdev
)
317 struct jme_adapter
*jme
= netdev_priv(netdev
);
318 unsigned char macaddr
[ETH_ALEN
];
321 spin_lock_bh(&jme
->macaddr_lock
);
322 val
= jread32(jme
, JME_RXUMA_LO
);
323 macaddr
[0] = (val
>> 0) & 0xFF;
324 macaddr
[1] = (val
>> 8) & 0xFF;
325 macaddr
[2] = (val
>> 16) & 0xFF;
326 macaddr
[3] = (val
>> 24) & 0xFF;
327 val
= jread32(jme
, JME_RXUMA_HI
);
328 macaddr
[4] = (val
>> 0) & 0xFF;
329 macaddr
[5] = (val
>> 8) & 0xFF;
330 memcpy(netdev
->dev_addr
, macaddr
, ETH_ALEN
);
331 spin_unlock_bh(&jme
->macaddr_lock
);
335 jme_set_rx_pcc(struct jme_adapter
*jme
, int p
)
339 jwrite32(jme
, JME_PCCRX0
,
340 ((PCC_OFF_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
341 ((PCC_OFF_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
344 jwrite32(jme
, JME_PCCRX0
,
345 ((PCC_P1_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
346 ((PCC_P1_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
349 jwrite32(jme
, JME_PCCRX0
,
350 ((PCC_P2_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
351 ((PCC_P2_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
354 jwrite32(jme
, JME_PCCRX0
,
355 ((PCC_P3_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
356 ((PCC_P3_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
363 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
364 netif_info(jme
, rx_status
, jme
->dev
, "Switched to PCC_P%d\n", p
);
368 jme_start_irq(struct jme_adapter
*jme
)
370 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
372 jme_set_rx_pcc(jme
, PCC_P1
);
374 dpi
->attempt
= PCC_P1
;
377 jwrite32(jme
, JME_PCCTX
,
378 ((PCC_TX_TO
<< PCCTXTO_SHIFT
) & PCCTXTO_MASK
) |
379 ((PCC_TX_CNT
<< PCCTX_SHIFT
) & PCCTX_MASK
) |
386 jwrite32(jme
, JME_IENS
, INTR_ENABLE
);
390 jme_stop_irq(struct jme_adapter
*jme
)
395 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
399 jme_linkstat_from_phy(struct jme_adapter
*jme
)
403 phylink
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 17);
404 bmsr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMSR
);
405 if (bmsr
& BMSR_ANCOMP
)
406 phylink
|= PHY_LINK_AUTONEG_COMPLETE
;
412 jme_set_phyfifo_5level(struct jme_adapter
*jme
)
414 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0004);
418 jme_set_phyfifo_8level(struct jme_adapter
*jme
)
420 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0000);
424 jme_check_link(struct net_device
*netdev
, int testonly
)
426 struct jme_adapter
*jme
= netdev_priv(netdev
);
427 u32 phylink
, cnt
= JME_SPDRSV_TIMEOUT
, bmcr
;
434 phylink
= jme_linkstat_from_phy(jme
);
436 phylink
= jread32(jme
, JME_PHY_LINK
);
438 if (phylink
& PHY_LINK_UP
) {
439 if (!(phylink
& PHY_LINK_AUTONEG_COMPLETE
)) {
441 * If we did not enable AN
442 * Speed/Duplex Info should be obtained from SMI
444 phylink
= PHY_LINK_UP
;
446 bmcr
= jme_mdio_read(jme
->dev
,
450 phylink
|= ((bmcr
& BMCR_SPEED1000
) &&
451 (bmcr
& BMCR_SPEED100
) == 0) ?
452 PHY_LINK_SPEED_1000M
:
453 (bmcr
& BMCR_SPEED100
) ?
454 PHY_LINK_SPEED_100M
:
457 phylink
|= (bmcr
& BMCR_FULLDPLX
) ?
460 strcat(linkmsg
, "Forced: ");
463 * Keep polling for speed/duplex resolve complete
465 while (!(phylink
& PHY_LINK_SPEEDDPU_RESOLVED
) &&
471 phylink
= jme_linkstat_from_phy(jme
);
473 phylink
= jread32(jme
, JME_PHY_LINK
);
476 pr_err("Waiting speed resolve timeout\n");
478 strcat(linkmsg
, "ANed: ");
481 if (jme
->phylink
== phylink
) {
488 jme
->phylink
= phylink
;
491 * The speed/duplex setting of jme->reg_ghc already cleared
492 * by jme_reset_mac_processor()
494 switch (phylink
& PHY_LINK_SPEED_MASK
) {
495 case PHY_LINK_SPEED_10M
:
496 jme
->reg_ghc
|= GHC_SPEED_10M
;
497 strcat(linkmsg
, "10 Mbps, ");
499 case PHY_LINK_SPEED_100M
:
500 jme
->reg_ghc
|= GHC_SPEED_100M
;
501 strcat(linkmsg
, "100 Mbps, ");
503 case PHY_LINK_SPEED_1000M
:
504 jme
->reg_ghc
|= GHC_SPEED_1000M
;
505 strcat(linkmsg
, "1000 Mbps, ");
511 if (phylink
& PHY_LINK_DUPLEX
) {
512 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
);
513 jwrite32(jme
, JME_TXTRHD
, TXTRHD_FULLDUPLEX
);
514 jme
->reg_ghc
|= GHC_DPX
;
516 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
|
520 jwrite32(jme
, JME_TXTRHD
, TXTRHD_HALFDUPLEX
);
523 jwrite32(jme
, JME_GHC
, jme
->reg_ghc
);
525 if (is_buggy250(jme
->pdev
->device
, jme
->chiprev
)) {
526 jme
->reg_gpreg1
&= ~(GPREG1_HALFMODEPATCH
|
528 if (!(phylink
& PHY_LINK_DUPLEX
))
529 jme
->reg_gpreg1
|= GPREG1_HALFMODEPATCH
;
530 switch (phylink
& PHY_LINK_SPEED_MASK
) {
531 case PHY_LINK_SPEED_10M
:
532 jme_set_phyfifo_8level(jme
);
533 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
535 case PHY_LINK_SPEED_100M
:
536 jme_set_phyfifo_5level(jme
);
537 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
539 case PHY_LINK_SPEED_1000M
:
540 jme_set_phyfifo_8level(jme
);
546 jwrite32(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
548 strcat(linkmsg
, (phylink
& PHY_LINK_DUPLEX
) ?
551 strcat(linkmsg
, (phylink
& PHY_LINK_MDI_STAT
) ?
554 netif_info(jme
, link
, jme
->dev
, "Link is up at %s\n", linkmsg
);
555 netif_carrier_on(netdev
);
560 netif_info(jme
, link
, jme
->dev
, "Link is down\n");
562 netif_carrier_off(netdev
);
570 jme_setup_tx_resources(struct jme_adapter
*jme
)
572 struct jme_ring
*txring
= &(jme
->txring
[0]);
574 txring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
575 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
585 txring
->desc
= (void *)ALIGN((unsigned long)(txring
->alloc
),
587 txring
->dma
= ALIGN(txring
->dmaalloc
, RING_DESC_ALIGN
);
588 txring
->next_to_use
= 0;
589 atomic_set(&txring
->next_to_clean
, 0);
590 atomic_set(&txring
->nr_free
, jme
->tx_ring_size
);
592 txring
->bufinf
= kzalloc(sizeof(struct jme_buffer_info
) *
593 jme
->tx_ring_size
, GFP_ATOMIC
);
594 if (unlikely(!(txring
->bufinf
)))
595 goto err_free_txring
;
598 * Initialize Transmit Descriptors
600 memset(txring
->alloc
, 0, TX_RING_ALLOC_SIZE(jme
->tx_ring_size
));
605 dma_free_coherent(&(jme
->pdev
->dev
),
606 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
612 txring
->dmaalloc
= 0;
614 txring
->bufinf
= NULL
;
620 jme_free_tx_resources(struct jme_adapter
*jme
)
623 struct jme_ring
*txring
= &(jme
->txring
[0]);
624 struct jme_buffer_info
*txbi
;
627 if (txring
->bufinf
) {
628 for (i
= 0 ; i
< jme
->tx_ring_size
; ++i
) {
629 txbi
= txring
->bufinf
+ i
;
631 dev_kfree_skb(txbi
->skb
);
637 txbi
->start_xmit
= 0;
639 kfree(txring
->bufinf
);
642 dma_free_coherent(&(jme
->pdev
->dev
),
643 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
647 txring
->alloc
= NULL
;
649 txring
->dmaalloc
= 0;
651 txring
->bufinf
= NULL
;
653 txring
->next_to_use
= 0;
654 atomic_set(&txring
->next_to_clean
, 0);
655 atomic_set(&txring
->nr_free
, 0);
659 jme_enable_tx_engine(struct jme_adapter
*jme
)
664 jwrite32(jme
, JME_TXCS
, TXCS_DEFAULT
| TXCS_SELECT_QUEUE0
);
668 * Setup TX Queue 0 DMA Bass Address
670 jwrite32(jme
, JME_TXDBA_LO
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
671 jwrite32(jme
, JME_TXDBA_HI
, (__u64
)(jme
->txring
[0].dma
) >> 32);
672 jwrite32(jme
, JME_TXNDA
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
675 * Setup TX Descptor Count
677 jwrite32(jme
, JME_TXQDC
, jme
->tx_ring_size
);
683 jwrite32f(jme
, JME_TXCS
, jme
->reg_txcs
|
688 * Start clock for TX MAC Processor
690 jme_mac_txclk_on(jme
);
694 jme_restart_tx_engine(struct jme_adapter
*jme
)
699 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
705 jme_disable_tx_engine(struct jme_adapter
*jme
)
713 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
| TXCS_SELECT_QUEUE0
);
716 val
= jread32(jme
, JME_TXCS
);
717 for (i
= JME_TX_DISABLE_TIMEOUT
; (val
& TXCS_ENABLE
) && i
> 0 ; --i
) {
719 val
= jread32(jme
, JME_TXCS
);
724 pr_err("Disable TX engine timeout\n");
727 * Stop clock for TX MAC Processor
729 jme_mac_txclk_off(jme
);
733 jme_set_clean_rxdesc(struct jme_adapter
*jme
, int i
)
735 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
736 register struct rxdesc
*rxdesc
= rxring
->desc
;
737 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
743 rxdesc
->desc1
.bufaddrh
= cpu_to_le32((__u64
)rxbi
->mapping
>> 32);
744 rxdesc
->desc1
.bufaddrl
= cpu_to_le32(
745 (__u64
)rxbi
->mapping
& 0xFFFFFFFFUL
);
746 rxdesc
->desc1
.datalen
= cpu_to_le16(rxbi
->len
);
747 if (jme
->dev
->features
& NETIF_F_HIGHDMA
)
748 rxdesc
->desc1
.flags
= RXFLAG_64BIT
;
750 rxdesc
->desc1
.flags
|= RXFLAG_OWN
| RXFLAG_INT
;
754 jme_make_new_rx_buf(struct jme_adapter
*jme
, int i
)
756 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
757 struct jme_buffer_info
*rxbi
= rxring
->bufinf
+ i
;
761 skb
= netdev_alloc_skb(jme
->dev
,
762 jme
->dev
->mtu
+ RX_EXTRA_LEN
);
766 mapping
= pci_map_page(jme
->pdev
, virt_to_page(skb
->data
),
767 offset_in_page(skb
->data
), skb_tailroom(skb
),
769 if (unlikely(pci_dma_mapping_error(jme
->pdev
, mapping
))) {
774 if (likely(rxbi
->mapping
))
775 pci_unmap_page(jme
->pdev
, rxbi
->mapping
,
776 rxbi
->len
, PCI_DMA_FROMDEVICE
);
779 rxbi
->len
= skb_tailroom(skb
);
780 rxbi
->mapping
= mapping
;
785 jme_free_rx_buf(struct jme_adapter
*jme
, int i
)
787 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
788 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
792 pci_unmap_page(jme
->pdev
,
796 dev_kfree_skb(rxbi
->skb
);
804 jme_free_rx_resources(struct jme_adapter
*jme
)
807 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
810 if (rxring
->bufinf
) {
811 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
)
812 jme_free_rx_buf(jme
, i
);
813 kfree(rxring
->bufinf
);
816 dma_free_coherent(&(jme
->pdev
->dev
),
817 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
820 rxring
->alloc
= NULL
;
822 rxring
->dmaalloc
= 0;
824 rxring
->bufinf
= NULL
;
826 rxring
->next_to_use
= 0;
827 atomic_set(&rxring
->next_to_clean
, 0);
831 jme_setup_rx_resources(struct jme_adapter
*jme
)
834 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
836 rxring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
837 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
846 rxring
->desc
= (void *)ALIGN((unsigned long)(rxring
->alloc
),
848 rxring
->dma
= ALIGN(rxring
->dmaalloc
, RING_DESC_ALIGN
);
849 rxring
->next_to_use
= 0;
850 atomic_set(&rxring
->next_to_clean
, 0);
852 rxring
->bufinf
= kzalloc(sizeof(struct jme_buffer_info
) *
853 jme
->rx_ring_size
, GFP_ATOMIC
);
854 if (unlikely(!(rxring
->bufinf
)))
855 goto err_free_rxring
;
858 * Initiallize Receive Descriptors
860 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
) {
861 if (unlikely(jme_make_new_rx_buf(jme
, i
))) {
862 jme_free_rx_resources(jme
);
866 jme_set_clean_rxdesc(jme
, i
);
872 dma_free_coherent(&(jme
->pdev
->dev
),
873 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
878 rxring
->dmaalloc
= 0;
880 rxring
->bufinf
= NULL
;
886 jme_enable_rx_engine(struct jme_adapter
*jme
)
891 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
896 * Setup RX DMA Bass Address
898 jwrite32(jme
, JME_RXDBA_LO
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
899 jwrite32(jme
, JME_RXDBA_HI
, (__u64
)(jme
->rxring
[0].dma
) >> 32);
900 jwrite32(jme
, JME_RXNDA
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
903 * Setup RX Descriptor Count
905 jwrite32(jme
, JME_RXQDC
, jme
->rx_ring_size
);
908 * Setup Unicast Filter
910 jme_set_unicastaddr(jme
->dev
);
911 jme_set_multi(jme
->dev
);
917 jwrite32f(jme
, JME_RXCS
, jme
->reg_rxcs
|
923 * Start clock for RX MAC Processor
925 jme_mac_rxclk_on(jme
);
929 jme_restart_rx_engine(struct jme_adapter
*jme
)
934 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
941 jme_disable_rx_engine(struct jme_adapter
*jme
)
949 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
);
952 val
= jread32(jme
, JME_RXCS
);
953 for (i
= JME_RX_DISABLE_TIMEOUT
; (val
& RXCS_ENABLE
) && i
> 0 ; --i
) {
955 val
= jread32(jme
, JME_RXCS
);
960 pr_err("Disable RX engine timeout\n");
963 * Stop clock for RX MAC Processor
965 jme_mac_rxclk_off(jme
);
969 jme_udpsum(struct sk_buff
*skb
)
973 if (skb
->len
< (ETH_HLEN
+ sizeof(struct iphdr
)))
975 if (skb
->protocol
!= htons(ETH_P_IP
))
977 skb_set_network_header(skb
, ETH_HLEN
);
978 if ((ip_hdr(skb
)->protocol
!= IPPROTO_UDP
) ||
979 (skb
->len
< (ETH_HLEN
+
980 (ip_hdr(skb
)->ihl
<< 2) +
981 sizeof(struct udphdr
)))) {
982 skb_reset_network_header(skb
);
985 skb_set_transport_header(skb
,
986 ETH_HLEN
+ (ip_hdr(skb
)->ihl
<< 2));
987 csum
= udp_hdr(skb
)->check
;
988 skb_reset_transport_header(skb
);
989 skb_reset_network_header(skb
);
995 jme_rxsum_ok(struct jme_adapter
*jme
, u16 flags
, struct sk_buff
*skb
)
997 if (!(flags
& (RXWBFLAG_TCPON
| RXWBFLAG_UDPON
| RXWBFLAG_IPV4
)))
1000 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_TCPON
| RXWBFLAG_TCPCS
))
1001 == RXWBFLAG_TCPON
)) {
1002 if (flags
& RXWBFLAG_IPV4
)
1003 netif_err(jme
, rx_err
, jme
->dev
, "TCP Checksum error\n");
1007 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_UDPON
| RXWBFLAG_UDPCS
))
1008 == RXWBFLAG_UDPON
) && jme_udpsum(skb
)) {
1009 if (flags
& RXWBFLAG_IPV4
)
1010 netif_err(jme
, rx_err
, jme
->dev
, "UDP Checksum error\n");
1014 if (unlikely((flags
& (RXWBFLAG_IPV4
| RXWBFLAG_IPCS
))
1015 == RXWBFLAG_IPV4
)) {
1016 netif_err(jme
, rx_err
, jme
->dev
, "IPv4 Checksum error\n");
1024 jme_alloc_and_feed_skb(struct jme_adapter
*jme
, int idx
)
1026 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1027 struct rxdesc
*rxdesc
= rxring
->desc
;
1028 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
1029 struct sk_buff
*skb
;
1036 pci_dma_sync_single_for_cpu(jme
->pdev
,
1039 PCI_DMA_FROMDEVICE
);
1041 if (unlikely(jme_make_new_rx_buf(jme
, idx
))) {
1042 pci_dma_sync_single_for_device(jme
->pdev
,
1045 PCI_DMA_FROMDEVICE
);
1047 ++(NET_STAT(jme
).rx_dropped
);
1049 framesize
= le16_to_cpu(rxdesc
->descwb
.framesize
)
1052 skb_reserve(skb
, RX_PREPAD_SIZE
);
1053 skb_put(skb
, framesize
);
1054 skb
->protocol
= eth_type_trans(skb
, jme
->dev
);
1056 if (jme_rxsum_ok(jme
, le16_to_cpu(rxdesc
->descwb
.flags
), skb
))
1057 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1059 skb_checksum_none_assert(skb
);
1061 if (rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_TAGON
)) {
1062 u16 vid
= le16_to_cpu(rxdesc
->descwb
.vlan
);
1064 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
1065 NET_STAT(jme
).rx_bytes
+= 4;
1069 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_DEST
)) ==
1070 cpu_to_le16(RXWBFLAG_DEST_MUL
))
1071 ++(NET_STAT(jme
).multicast
);
1073 NET_STAT(jme
).rx_bytes
+= framesize
;
1074 ++(NET_STAT(jme
).rx_packets
);
1077 jme_set_clean_rxdesc(jme
, idx
);
1082 jme_process_receive(struct jme_adapter
*jme
, int limit
)
1084 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1085 struct rxdesc
*rxdesc
= rxring
->desc
;
1086 int i
, j
, ccnt
, desccnt
, mask
= jme
->rx_ring_mask
;
1088 if (unlikely(!atomic_dec_and_test(&jme
->rx_cleaning
)))
1091 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1094 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1097 i
= atomic_read(&rxring
->next_to_clean
);
1099 rxdesc
= rxring
->desc
;
1102 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_OWN
)) ||
1103 !(rxdesc
->descwb
.desccnt
& RXWBDCNT_WBCPL
))
1108 desccnt
= rxdesc
->descwb
.desccnt
& RXWBDCNT_DCNT
;
1110 if (unlikely(desccnt
> 1 ||
1111 rxdesc
->descwb
.errstat
& RXWBERR_ALLERR
)) {
1113 if (rxdesc
->descwb
.errstat
& RXWBERR_CRCERR
)
1114 ++(NET_STAT(jme
).rx_crc_errors
);
1115 else if (rxdesc
->descwb
.errstat
& RXWBERR_OVERUN
)
1116 ++(NET_STAT(jme
).rx_fifo_errors
);
1118 ++(NET_STAT(jme
).rx_errors
);
1121 limit
-= desccnt
- 1;
1123 for (j
= i
, ccnt
= desccnt
; ccnt
-- ; ) {
1124 jme_set_clean_rxdesc(jme
, j
);
1125 j
= (j
+ 1) & (mask
);
1129 jme_alloc_and_feed_skb(jme
, i
);
1132 i
= (i
+ desccnt
) & (mask
);
1136 atomic_set(&rxring
->next_to_clean
, i
);
1139 atomic_inc(&jme
->rx_cleaning
);
1141 return limit
> 0 ? limit
: 0;
1146 jme_attempt_pcc(struct dynpcc_info
*dpi
, int atmp
)
1148 if (likely(atmp
== dpi
->cur
)) {
1153 if (dpi
->attempt
== atmp
) {
1156 dpi
->attempt
= atmp
;
1163 jme_dynamic_pcc(struct jme_adapter
*jme
)
1165 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
1167 if ((NET_STAT(jme
).rx_bytes
- dpi
->last_bytes
) > PCC_P3_THRESHOLD
)
1168 jme_attempt_pcc(dpi
, PCC_P3
);
1169 else if ((NET_STAT(jme
).rx_packets
- dpi
->last_pkts
) > PCC_P2_THRESHOLD
||
1170 dpi
->intr_cnt
> PCC_INTR_THRESHOLD
)
1171 jme_attempt_pcc(dpi
, PCC_P2
);
1173 jme_attempt_pcc(dpi
, PCC_P1
);
1175 if (unlikely(dpi
->attempt
!= dpi
->cur
&& dpi
->cnt
> 5)) {
1176 if (dpi
->attempt
< dpi
->cur
)
1177 tasklet_schedule(&jme
->rxclean_task
);
1178 jme_set_rx_pcc(jme
, dpi
->attempt
);
1179 dpi
->cur
= dpi
->attempt
;
1185 jme_start_pcc_timer(struct jme_adapter
*jme
)
1187 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1188 dpi
->last_bytes
= NET_STAT(jme
).rx_bytes
;
1189 dpi
->last_pkts
= NET_STAT(jme
).rx_packets
;
1191 jwrite32(jme
, JME_TMCSR
,
1192 TMCSR_EN
| ((0xFFFFFF - PCC_INTERVAL_US
) & TMCSR_CNT
));
1196 jme_stop_pcc_timer(struct jme_adapter
*jme
)
1198 jwrite32(jme
, JME_TMCSR
, 0);
1202 jme_shutdown_nic(struct jme_adapter
*jme
)
1206 phylink
= jme_linkstat_from_phy(jme
);
1208 if (!(phylink
& PHY_LINK_UP
)) {
1210 * Disable all interrupt before issue timer
1213 jwrite32(jme
, JME_TIMER2
, TMCSR_EN
| 0xFFFFFE);
1218 jme_pcc_tasklet(unsigned long arg
)
1220 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1221 struct net_device
*netdev
= jme
->dev
;
1223 if (unlikely(test_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
))) {
1224 jme_shutdown_nic(jme
);
1228 if (unlikely(!netif_carrier_ok(netdev
) ||
1229 (atomic_read(&jme
->link_changing
) != 1)
1231 jme_stop_pcc_timer(jme
);
1235 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
1236 jme_dynamic_pcc(jme
);
1238 jme_start_pcc_timer(jme
);
1242 jme_polling_mode(struct jme_adapter
*jme
)
1244 jme_set_rx_pcc(jme
, PCC_OFF
);
1248 jme_interrupt_mode(struct jme_adapter
*jme
)
1250 jme_set_rx_pcc(jme
, PCC_P1
);
1254 jme_pseudo_hotplug_enabled(struct jme_adapter
*jme
)
1257 apmc
= jread32(jme
, JME_APMC
);
1258 return apmc
& JME_APMC_PSEUDO_HP_EN
;
1262 jme_start_shutdown_timer(struct jme_adapter
*jme
)
1266 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PCIE_SD_EN
;
1267 apmc
&= ~JME_APMC_EPIEN_CTRL
;
1269 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_EN
);
1272 jwrite32f(jme
, JME_APMC
, apmc
);
1274 jwrite32f(jme
, JME_TIMER2
, 0);
1275 set_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1276 jwrite32(jme
, JME_TMCSR
,
1277 TMCSR_EN
| ((0xFFFFFF - APMC_PHP_SHUTDOWN_DELAY
) & TMCSR_CNT
));
1281 jme_stop_shutdown_timer(struct jme_adapter
*jme
)
1285 jwrite32f(jme
, JME_TMCSR
, 0);
1286 jwrite32f(jme
, JME_TIMER2
, 0);
1287 clear_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1289 apmc
= jread32(jme
, JME_APMC
);
1290 apmc
&= ~(JME_APMC_PCIE_SD_EN
| JME_APMC_EPIEN_CTRL
);
1291 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_DIS
);
1293 jwrite32f(jme
, JME_APMC
, apmc
);
1297 jme_link_change_tasklet(unsigned long arg
)
1299 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1300 struct net_device
*netdev
= jme
->dev
;
1303 while (!atomic_dec_and_test(&jme
->link_changing
)) {
1304 atomic_inc(&jme
->link_changing
);
1305 netif_info(jme
, intr
, jme
->dev
, "Get link change lock failed\n");
1306 while (atomic_read(&jme
->link_changing
) != 1)
1307 netif_info(jme
, intr
, jme
->dev
, "Waiting link change lock\n");
1310 if (jme_check_link(netdev
, 1) && jme
->old_mtu
== netdev
->mtu
)
1313 jme
->old_mtu
= netdev
->mtu
;
1314 netif_stop_queue(netdev
);
1315 if (jme_pseudo_hotplug_enabled(jme
))
1316 jme_stop_shutdown_timer(jme
);
1318 jme_stop_pcc_timer(jme
);
1319 tasklet_disable(&jme
->txclean_task
);
1320 tasklet_disable(&jme
->rxclean_task
);
1321 tasklet_disable(&jme
->rxempty_task
);
1323 if (netif_carrier_ok(netdev
)) {
1324 jme_disable_rx_engine(jme
);
1325 jme_disable_tx_engine(jme
);
1326 jme_reset_mac_processor(jme
);
1327 jme_free_rx_resources(jme
);
1328 jme_free_tx_resources(jme
);
1330 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1331 jme_polling_mode(jme
);
1333 netif_carrier_off(netdev
);
1336 jme_check_link(netdev
, 0);
1337 if (netif_carrier_ok(netdev
)) {
1338 rc
= jme_setup_rx_resources(jme
);
1340 pr_err("Allocating resources for RX error, Device STOPPED!\n");
1341 goto out_enable_tasklet
;
1344 rc
= jme_setup_tx_resources(jme
);
1346 pr_err("Allocating resources for TX error, Device STOPPED!\n");
1347 goto err_out_free_rx_resources
;
1350 jme_enable_rx_engine(jme
);
1351 jme_enable_tx_engine(jme
);
1353 netif_start_queue(netdev
);
1355 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1356 jme_interrupt_mode(jme
);
1358 jme_start_pcc_timer(jme
);
1359 } else if (jme_pseudo_hotplug_enabled(jme
)) {
1360 jme_start_shutdown_timer(jme
);
1363 goto out_enable_tasklet
;
1365 err_out_free_rx_resources
:
1366 jme_free_rx_resources(jme
);
1368 tasklet_enable(&jme
->txclean_task
);
1369 tasklet_enable(&jme
->rxclean_task
);
1370 tasklet_enable(&jme
->rxempty_task
);
1372 atomic_inc(&jme
->link_changing
);
1376 jme_rx_clean_tasklet(unsigned long arg
)
1378 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1379 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1381 jme_process_receive(jme
, jme
->rx_ring_size
);
1387 jme_poll(JME_NAPI_HOLDER(holder
), JME_NAPI_WEIGHT(budget
))
1389 struct jme_adapter
*jme
= jme_napi_priv(holder
);
1392 rest
= jme_process_receive(jme
, JME_NAPI_WEIGHT_VAL(budget
));
1394 while (atomic_read(&jme
->rx_empty
) > 0) {
1395 atomic_dec(&jme
->rx_empty
);
1396 ++(NET_STAT(jme
).rx_dropped
);
1397 jme_restart_rx_engine(jme
);
1399 atomic_inc(&jme
->rx_empty
);
1402 JME_RX_COMPLETE(netdev
, holder
);
1403 jme_interrupt_mode(jme
);
1406 JME_NAPI_WEIGHT_SET(budget
, rest
);
1407 return JME_NAPI_WEIGHT_VAL(budget
) - rest
;
1411 jme_rx_empty_tasklet(unsigned long arg
)
1413 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1415 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1418 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1421 netif_info(jme
, rx_status
, jme
->dev
, "RX Queue Full!\n");
1423 jme_rx_clean_tasklet(arg
);
1425 while (atomic_read(&jme
->rx_empty
) > 0) {
1426 atomic_dec(&jme
->rx_empty
);
1427 ++(NET_STAT(jme
).rx_dropped
);
1428 jme_restart_rx_engine(jme
);
1430 atomic_inc(&jme
->rx_empty
);
1434 jme_wake_queue_if_stopped(struct jme_adapter
*jme
)
1436 struct jme_ring
*txring
= &(jme
->txring
[0]);
1439 if (unlikely(netif_queue_stopped(jme
->dev
) &&
1440 atomic_read(&txring
->nr_free
) >= (jme
->tx_wake_threshold
))) {
1441 netif_info(jme
, tx_done
, jme
->dev
, "TX Queue Waked\n");
1442 netif_wake_queue(jme
->dev
);
1448 jme_tx_clean_tasklet(unsigned long arg
)
1450 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1451 struct jme_ring
*txring
= &(jme
->txring
[0]);
1452 struct txdesc
*txdesc
= txring
->desc
;
1453 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
, *ttxbi
;
1454 int i
, j
, cnt
= 0, max
, err
, mask
;
1456 tx_dbg(jme
, "Into txclean\n");
1458 if (unlikely(!atomic_dec_and_test(&jme
->tx_cleaning
)))
1461 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1464 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1467 max
= jme
->tx_ring_size
- atomic_read(&txring
->nr_free
);
1468 mask
= jme
->tx_ring_mask
;
1470 for (i
= atomic_read(&txring
->next_to_clean
) ; cnt
< max
; ) {
1474 if (likely(ctxbi
->skb
&&
1475 !(txdesc
[i
].descwb
.flags
& TXWBFLAG_OWN
))) {
1477 tx_dbg(jme
, "txclean: %d+%d@%lu\n",
1478 i
, ctxbi
->nr_desc
, jiffies
);
1480 err
= txdesc
[i
].descwb
.flags
& TXWBFLAG_ALLERR
;
1482 for (j
= 1 ; j
< ctxbi
->nr_desc
; ++j
) {
1483 ttxbi
= txbi
+ ((i
+ j
) & (mask
));
1484 txdesc
[(i
+ j
) & (mask
)].dw
[0] = 0;
1486 pci_unmap_page(jme
->pdev
,
1495 dev_kfree_skb(ctxbi
->skb
);
1497 cnt
+= ctxbi
->nr_desc
;
1499 if (unlikely(err
)) {
1500 ++(NET_STAT(jme
).tx_carrier_errors
);
1502 ++(NET_STAT(jme
).tx_packets
);
1503 NET_STAT(jme
).tx_bytes
+= ctxbi
->len
;
1508 ctxbi
->start_xmit
= 0;
1514 i
= (i
+ ctxbi
->nr_desc
) & mask
;
1519 tx_dbg(jme
, "txclean: done %d@%lu\n", i
, jiffies
);
1520 atomic_set(&txring
->next_to_clean
, i
);
1521 atomic_add(cnt
, &txring
->nr_free
);
1523 jme_wake_queue_if_stopped(jme
);
1526 atomic_inc(&jme
->tx_cleaning
);
1530 jme_intr_msi(struct jme_adapter
*jme
, u32 intrstat
)
1535 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
1537 if (intrstat
& (INTR_LINKCH
| INTR_SWINTR
)) {
1539 * Link change event is critical
1540 * all other events are ignored
1542 jwrite32(jme
, JME_IEVE
, intrstat
);
1543 tasklet_schedule(&jme
->linkch_task
);
1547 if (intrstat
& INTR_TMINTR
) {
1548 jwrite32(jme
, JME_IEVE
, INTR_TMINTR
);
1549 tasklet_schedule(&jme
->pcc_task
);
1552 if (intrstat
& (INTR_PCCTXTO
| INTR_PCCTX
)) {
1553 jwrite32(jme
, JME_IEVE
, INTR_PCCTXTO
| INTR_PCCTX
| INTR_TX0
);
1554 tasklet_schedule(&jme
->txclean_task
);
1557 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1558 jwrite32(jme
, JME_IEVE
, (intrstat
& (INTR_PCCRX0TO
|
1564 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
1565 if (intrstat
& INTR_RX0EMP
)
1566 atomic_inc(&jme
->rx_empty
);
1568 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1569 if (likely(JME_RX_SCHEDULE_PREP(jme
))) {
1570 jme_polling_mode(jme
);
1571 JME_RX_SCHEDULE(jme
);
1575 if (intrstat
& INTR_RX0EMP
) {
1576 atomic_inc(&jme
->rx_empty
);
1577 tasklet_hi_schedule(&jme
->rxempty_task
);
1578 } else if (intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
)) {
1579 tasklet_hi_schedule(&jme
->rxclean_task
);
1585 * Re-enable interrupt
1587 jwrite32f(jme
, JME_IENS
, INTR_ENABLE
);
1591 jme_intr(int irq
, void *dev_id
)
1593 struct net_device
*netdev
= dev_id
;
1594 struct jme_adapter
*jme
= netdev_priv(netdev
);
1597 intrstat
= jread32(jme
, JME_IEVE
);
1600 * Check if it's really an interrupt for us
1602 if (unlikely((intrstat
& INTR_ENABLE
) == 0))
1606 * Check if the device still exist
1608 if (unlikely(intrstat
== ~((typeof(intrstat
))0)))
1611 jme_intr_msi(jme
, intrstat
);
1617 jme_msi(int irq
, void *dev_id
)
1619 struct net_device
*netdev
= dev_id
;
1620 struct jme_adapter
*jme
= netdev_priv(netdev
);
1623 intrstat
= jread32(jme
, JME_IEVE
);
1625 jme_intr_msi(jme
, intrstat
);
1631 jme_reset_link(struct jme_adapter
*jme
)
1633 jwrite32(jme
, JME_TMCSR
, TMCSR_SWIT
);
1637 jme_restart_an(struct jme_adapter
*jme
)
1641 spin_lock_bh(&jme
->phy_lock
);
1642 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1643 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1644 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1645 spin_unlock_bh(&jme
->phy_lock
);
1649 jme_request_irq(struct jme_adapter
*jme
)
1652 struct net_device
*netdev
= jme
->dev
;
1653 irq_handler_t handler
= jme_intr
;
1654 int irq_flags
= IRQF_SHARED
;
1656 if (!pci_enable_msi(jme
->pdev
)) {
1657 set_bit(JME_FLAG_MSI
, &jme
->flags
);
1662 rc
= request_irq(jme
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
1666 "Unable to request %s interrupt (return: %d)\n",
1667 test_bit(JME_FLAG_MSI
, &jme
->flags
) ? "MSI" : "INTx",
1670 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1671 pci_disable_msi(jme
->pdev
);
1672 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1675 netdev
->irq
= jme
->pdev
->irq
;
1682 jme_free_irq(struct jme_adapter
*jme
)
1684 free_irq(jme
->pdev
->irq
, jme
->dev
);
1685 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1686 pci_disable_msi(jme
->pdev
);
1687 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1688 jme
->dev
->irq
= jme
->pdev
->irq
;
1693 jme_new_phy_on(struct jme_adapter
*jme
)
1697 reg
= jread32(jme
, JME_PHY_PWR
);
1698 reg
&= ~(PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1699 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
);
1700 jwrite32(jme
, JME_PHY_PWR
, reg
);
1702 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1703 reg
&= ~PE1_GPREG0_PBG
;
1704 reg
|= PE1_GPREG0_ENBG
;
1705 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1709 jme_new_phy_off(struct jme_adapter
*jme
)
1713 reg
= jread32(jme
, JME_PHY_PWR
);
1714 reg
|= PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1715 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
;
1716 jwrite32(jme
, JME_PHY_PWR
, reg
);
1718 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1719 reg
&= ~PE1_GPREG0_PBG
;
1720 reg
|= PE1_GPREG0_PDD3COLD
;
1721 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1725 jme_phy_on(struct jme_adapter
*jme
)
1729 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1730 bmcr
&= ~BMCR_PDOWN
;
1731 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1733 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1734 jme_new_phy_on(jme
);
1738 jme_phy_off(struct jme_adapter
*jme
)
1742 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1744 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1746 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1747 jme_new_phy_off(jme
);
1751 jme_phy_specreg_read(struct jme_adapter
*jme
, u32 specreg
)
1755 phy_addr
= JM_PHY_SPEC_REG_READ
| specreg
;
1756 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_ADDR_REG
,
1758 return jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
,
1759 JM_PHY_SPEC_DATA_REG
);
1763 jme_phy_specreg_write(struct jme_adapter
*jme
, u32 ext_reg
, u32 phy_data
)
1767 phy_addr
= JM_PHY_SPEC_REG_WRITE
| ext_reg
;
1768 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_DATA_REG
,
1770 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_ADDR_REG
,
1775 jme_phy_calibration(struct jme_adapter
*jme
)
1777 u32 ctrl1000
, phy_data
;
1781 /* Enabel PHY test mode 1 */
1782 ctrl1000
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
);
1783 ctrl1000
&= ~PHY_GAD_TEST_MODE_MSK
;
1784 ctrl1000
|= PHY_GAD_TEST_MODE_1
;
1785 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
, ctrl1000
);
1787 phy_data
= jme_phy_specreg_read(jme
, JM_PHY_EXT_COMM_2_REG
);
1788 phy_data
&= ~JM_PHY_EXT_COMM_2_CALI_MODE_0
;
1789 phy_data
|= JM_PHY_EXT_COMM_2_CALI_LATCH
|
1790 JM_PHY_EXT_COMM_2_CALI_ENABLE
;
1791 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_2_REG
, phy_data
);
1793 phy_data
= jme_phy_specreg_read(jme
, JM_PHY_EXT_COMM_2_REG
);
1794 phy_data
&= ~(JM_PHY_EXT_COMM_2_CALI_ENABLE
|
1795 JM_PHY_EXT_COMM_2_CALI_MODE_0
|
1796 JM_PHY_EXT_COMM_2_CALI_LATCH
);
1797 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_2_REG
, phy_data
);
1799 /* Disable PHY test mode */
1800 ctrl1000
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
);
1801 ctrl1000
&= ~PHY_GAD_TEST_MODE_MSK
;
1802 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
, ctrl1000
);
1807 jme_phy_setEA(struct jme_adapter
*jme
)
1809 u32 phy_comm0
= 0, phy_comm1
= 0;
1812 pci_read_config_byte(jme
->pdev
, PCI_PRIV_SHARE_NICCTRL
, &nic_ctrl
);
1813 if ((nic_ctrl
& 0x3) == JME_FLAG_PHYEA_ENABLE
)
1816 switch (jme
->pdev
->device
) {
1817 case PCI_DEVICE_ID_JMICRON_JMC250
:
1818 if (((jme
->chip_main_rev
== 5) &&
1819 ((jme
->chip_sub_rev
== 0) || (jme
->chip_sub_rev
== 1) ||
1820 (jme
->chip_sub_rev
== 3))) ||
1821 (jme
->chip_main_rev
>= 6)) {
1825 if ((jme
->chip_main_rev
== 3) &&
1826 ((jme
->chip_sub_rev
== 1) || (jme
->chip_sub_rev
== 2)))
1829 case PCI_DEVICE_ID_JMICRON_JMC260
:
1830 if (((jme
->chip_main_rev
== 5) &&
1831 ((jme
->chip_sub_rev
== 0) || (jme
->chip_sub_rev
== 1) ||
1832 (jme
->chip_sub_rev
== 3))) ||
1833 (jme
->chip_main_rev
>= 6)) {
1837 if ((jme
->chip_main_rev
== 3) &&
1838 ((jme
->chip_sub_rev
== 1) || (jme
->chip_sub_rev
== 2)))
1840 if ((jme
->chip_main_rev
== 2) && (jme
->chip_sub_rev
== 0))
1842 if ((jme
->chip_main_rev
== 2) && (jme
->chip_sub_rev
== 2))
1849 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_0_REG
, phy_comm0
);
1851 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_1_REG
, phy_comm1
);
1857 jme_open(struct net_device
*netdev
)
1859 struct jme_adapter
*jme
= netdev_priv(netdev
);
1862 jme_clear_pm_disable_wol(jme
);
1863 JME_NAPI_ENABLE(jme
);
1865 tasklet_init(&jme
->linkch_task
, jme_link_change_tasklet
,
1866 (unsigned long) jme
);
1867 tasklet_init(&jme
->txclean_task
, jme_tx_clean_tasklet
,
1868 (unsigned long) jme
);
1869 tasklet_init(&jme
->rxclean_task
, jme_rx_clean_tasklet
,
1870 (unsigned long) jme
);
1871 tasklet_init(&jme
->rxempty_task
, jme_rx_empty_tasklet
,
1872 (unsigned long) jme
);
1874 rc
= jme_request_irq(jme
);
1881 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
1882 jme_set_settings(netdev
, &jme
->old_ecmd
);
1884 jme_reset_phy_processor(jme
);
1885 jme_phy_calibration(jme
);
1887 jme_reset_link(jme
);
1892 netif_stop_queue(netdev
);
1893 netif_carrier_off(netdev
);
1898 jme_set_100m_half(struct jme_adapter
*jme
)
1903 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1904 tmp
= bmcr
& ~(BMCR_ANENABLE
| BMCR_SPEED100
|
1905 BMCR_SPEED1000
| BMCR_FULLDPLX
);
1906 tmp
|= BMCR_SPEED100
;
1909 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, tmp
);
1912 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
| GHC_LINK_POLL
);
1914 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
);
1917 #define JME_WAIT_LINK_TIME 2000 /* 2000ms */
1919 jme_wait_link(struct jme_adapter
*jme
)
1921 u32 phylink
, to
= JME_WAIT_LINK_TIME
;
1924 phylink
= jme_linkstat_from_phy(jme
);
1925 while (!(phylink
& PHY_LINK_UP
) && (to
-= 10) > 0) {
1927 phylink
= jme_linkstat_from_phy(jme
);
1932 jme_powersave_phy(struct jme_adapter
*jme
)
1934 if (jme
->reg_pmcs
&& device_may_wakeup(&jme
->pdev
->dev
)) {
1935 jme_set_100m_half(jme
);
1936 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
1938 jme_clear_pm_enable_wol(jme
);
1945 jme_close(struct net_device
*netdev
)
1947 struct jme_adapter
*jme
= netdev_priv(netdev
);
1949 netif_stop_queue(netdev
);
1950 netif_carrier_off(netdev
);
1955 JME_NAPI_DISABLE(jme
);
1957 tasklet_kill(&jme
->linkch_task
);
1958 tasklet_kill(&jme
->txclean_task
);
1959 tasklet_kill(&jme
->rxclean_task
);
1960 tasklet_kill(&jme
->rxempty_task
);
1962 jme_disable_rx_engine(jme
);
1963 jme_disable_tx_engine(jme
);
1964 jme_reset_mac_processor(jme
);
1965 jme_free_rx_resources(jme
);
1966 jme_free_tx_resources(jme
);
1974 jme_alloc_txdesc(struct jme_adapter
*jme
,
1975 struct sk_buff
*skb
)
1977 struct jme_ring
*txring
= &(jme
->txring
[0]);
1978 int idx
, nr_alloc
, mask
= jme
->tx_ring_mask
;
1980 idx
= txring
->next_to_use
;
1981 nr_alloc
= skb_shinfo(skb
)->nr_frags
+ 2;
1983 if (unlikely(atomic_read(&txring
->nr_free
) < nr_alloc
))
1986 atomic_sub(nr_alloc
, &txring
->nr_free
);
1988 txring
->next_to_use
= (txring
->next_to_use
+ nr_alloc
) & mask
;
1994 jme_fill_tx_map(struct pci_dev
*pdev
,
1995 struct txdesc
*txdesc
,
1996 struct jme_buffer_info
*txbi
,
2004 dmaaddr
= pci_map_page(pdev
,
2010 if (unlikely(pci_dma_mapping_error(pdev
, dmaaddr
)))
2013 pci_dma_sync_single_for_device(pdev
,
2020 txdesc
->desc2
.flags
= TXFLAG_OWN
;
2021 txdesc
->desc2
.flags
|= (hidma
) ? TXFLAG_64BIT
: 0;
2022 txdesc
->desc2
.datalen
= cpu_to_le16(len
);
2023 txdesc
->desc2
.bufaddrh
= cpu_to_le32((__u64
)dmaaddr
>> 32);
2024 txdesc
->desc2
.bufaddrl
= cpu_to_le32(
2025 (__u64
)dmaaddr
& 0xFFFFFFFFUL
);
2027 txbi
->mapping
= dmaaddr
;
2032 static void jme_drop_tx_map(struct jme_adapter
*jme
, int startidx
, int count
)
2034 struct jme_ring
*txring
= &(jme
->txring
[0]);
2035 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
;
2036 int mask
= jme
->tx_ring_mask
;
2039 for (j
= 0 ; j
< count
; j
++) {
2040 ctxbi
= txbi
+ ((startidx
+ j
+ 2) & (mask
));
2041 pci_unmap_page(jme
->pdev
,
2053 jme_map_tx_skb(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
2055 struct jme_ring
*txring
= &(jme
->txring
[0]);
2056 struct txdesc
*txdesc
= txring
->desc
, *ctxdesc
;
2057 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
;
2058 bool hidma
= jme
->dev
->features
& NETIF_F_HIGHDMA
;
2059 int i
, nr_frags
= skb_shinfo(skb
)->nr_frags
;
2060 int mask
= jme
->tx_ring_mask
;
2061 const struct skb_frag_struct
*frag
;
2065 for (i
= 0 ; i
< nr_frags
; ++i
) {
2066 frag
= &skb_shinfo(skb
)->frags
[i
];
2067 ctxdesc
= txdesc
+ ((idx
+ i
+ 2) & (mask
));
2068 ctxbi
= txbi
+ ((idx
+ i
+ 2) & (mask
));
2070 ret
= jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
,
2071 skb_frag_page(frag
),
2072 frag
->page_offset
, skb_frag_size(frag
), hidma
);
2074 jme_drop_tx_map(jme
, idx
, i
);
2080 len
= skb_is_nonlinear(skb
) ? skb_headlen(skb
) : skb
->len
;
2081 ctxdesc
= txdesc
+ ((idx
+ 1) & (mask
));
2082 ctxbi
= txbi
+ ((idx
+ 1) & (mask
));
2083 ret
= jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
, virt_to_page(skb
->data
),
2084 offset_in_page(skb
->data
), len
, hidma
);
2086 jme_drop_tx_map(jme
, idx
, i
);
2095 jme_tx_tso(struct sk_buff
*skb
, __le16
*mss
, u8
*flags
)
2097 *mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
<< TXDESC_MSS_SHIFT
);
2099 *flags
|= TXFLAG_LSEN
;
2101 if (skb
->protocol
== htons(ETH_P_IP
)) {
2102 struct iphdr
*iph
= ip_hdr(skb
);
2105 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2110 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2112 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ip6h
->saddr
,
2125 jme_tx_csum(struct jme_adapter
*jme
, struct sk_buff
*skb
, u8
*flags
)
2127 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2130 switch (skb
->protocol
) {
2131 case htons(ETH_P_IP
):
2132 ip_proto
= ip_hdr(skb
)->protocol
;
2134 case htons(ETH_P_IPV6
):
2135 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
2144 *flags
|= TXFLAG_TCPCS
;
2147 *flags
|= TXFLAG_UDPCS
;
2150 netif_err(jme
, tx_err
, jme
->dev
, "Error upper layer protocol\n");
2157 jme_tx_vlan(struct sk_buff
*skb
, __le16
*vlan
, u8
*flags
)
2159 if (skb_vlan_tag_present(skb
)) {
2160 *flags
|= TXFLAG_TAGON
;
2161 *vlan
= cpu_to_le16(skb_vlan_tag_get(skb
));
2166 jme_fill_tx_desc(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
2168 struct jme_ring
*txring
= &(jme
->txring
[0]);
2169 struct txdesc
*txdesc
;
2170 struct jme_buffer_info
*txbi
;
2174 txdesc
= (struct txdesc
*)txring
->desc
+ idx
;
2175 txbi
= txring
->bufinf
+ idx
;
2181 txdesc
->desc1
.pktsize
= cpu_to_le16(skb
->len
);
2183 * Set OWN bit at final.
2184 * When kernel transmit faster than NIC.
2185 * And NIC trying to send this descriptor before we tell
2186 * it to start sending this TX queue.
2187 * Other fields are already filled correctly.
2190 flags
= TXFLAG_OWN
| TXFLAG_INT
;
2192 * Set checksum flags while not tso
2194 if (jme_tx_tso(skb
, &txdesc
->desc1
.mss
, &flags
))
2195 jme_tx_csum(jme
, skb
, &flags
);
2196 jme_tx_vlan(skb
, &txdesc
->desc1
.vlan
, &flags
);
2197 ret
= jme_map_tx_skb(jme
, skb
, idx
);
2201 txdesc
->desc1
.flags
= flags
;
2203 * Set tx buffer info after telling NIC to send
2204 * For better tx_clean timing
2207 txbi
->nr_desc
= skb_shinfo(skb
)->nr_frags
+ 2;
2209 txbi
->len
= skb
->len
;
2210 txbi
->start_xmit
= jiffies
;
2211 if (!txbi
->start_xmit
)
2212 txbi
->start_xmit
= (0UL-1);
2218 jme_stop_queue_if_full(struct jme_adapter
*jme
)
2220 struct jme_ring
*txring
= &(jme
->txring
[0]);
2221 struct jme_buffer_info
*txbi
= txring
->bufinf
;
2222 int idx
= atomic_read(&txring
->next_to_clean
);
2227 if (unlikely(atomic_read(&txring
->nr_free
) < (MAX_SKB_FRAGS
+2))) {
2228 netif_stop_queue(jme
->dev
);
2229 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Paused\n");
2231 if (atomic_read(&txring
->nr_free
)
2232 >= (jme
->tx_wake_threshold
)) {
2233 netif_wake_queue(jme
->dev
);
2234 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Fast Waked\n");
2238 if (unlikely(txbi
->start_xmit
&&
2239 (jiffies
- txbi
->start_xmit
) >= TX_TIMEOUT
&&
2241 netif_stop_queue(jme
->dev
);
2242 netif_info(jme
, tx_queued
, jme
->dev
,
2243 "TX Queue Stopped %d@%lu\n", idx
, jiffies
);
2248 * This function is already protected by netif_tx_lock()
2252 jme_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
2254 struct jme_adapter
*jme
= netdev_priv(netdev
);
2257 if (unlikely(skb_is_gso(skb
) && skb_cow_head(skb
, 0))) {
2258 dev_kfree_skb_any(skb
);
2259 ++(NET_STAT(jme
).tx_dropped
);
2260 return NETDEV_TX_OK
;
2263 idx
= jme_alloc_txdesc(jme
, skb
);
2265 if (unlikely(idx
< 0)) {
2266 netif_stop_queue(netdev
);
2267 netif_err(jme
, tx_err
, jme
->dev
,
2268 "BUG! Tx ring full when queue awake!\n");
2270 return NETDEV_TX_BUSY
;
2273 if (jme_fill_tx_desc(jme
, skb
, idx
))
2274 return NETDEV_TX_OK
;
2276 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
2277 TXCS_SELECT_QUEUE0
|
2281 tx_dbg(jme
, "xmit: %d+%d@%lu\n",
2282 idx
, skb_shinfo(skb
)->nr_frags
+ 2, jiffies
);
2283 jme_stop_queue_if_full(jme
);
2285 return NETDEV_TX_OK
;
2289 jme_set_unicastaddr(struct net_device
*netdev
)
2291 struct jme_adapter
*jme
= netdev_priv(netdev
);
2294 val
= (netdev
->dev_addr
[3] & 0xff) << 24 |
2295 (netdev
->dev_addr
[2] & 0xff) << 16 |
2296 (netdev
->dev_addr
[1] & 0xff) << 8 |
2297 (netdev
->dev_addr
[0] & 0xff);
2298 jwrite32(jme
, JME_RXUMA_LO
, val
);
2299 val
= (netdev
->dev_addr
[5] & 0xff) << 8 |
2300 (netdev
->dev_addr
[4] & 0xff);
2301 jwrite32(jme
, JME_RXUMA_HI
, val
);
2305 jme_set_macaddr(struct net_device
*netdev
, void *p
)
2307 struct jme_adapter
*jme
= netdev_priv(netdev
);
2308 struct sockaddr
*addr
= p
;
2310 if (netif_running(netdev
))
2313 spin_lock_bh(&jme
->macaddr_lock
);
2314 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2315 jme_set_unicastaddr(netdev
);
2316 spin_unlock_bh(&jme
->macaddr_lock
);
2322 jme_set_multi(struct net_device
*netdev
)
2324 struct jme_adapter
*jme
= netdev_priv(netdev
);
2325 u32 mc_hash
[2] = {};
2327 spin_lock_bh(&jme
->rxmcs_lock
);
2329 jme
->reg_rxmcs
|= RXMCS_BRDFRAME
| RXMCS_UNIFRAME
;
2331 if (netdev
->flags
& IFF_PROMISC
) {
2332 jme
->reg_rxmcs
|= RXMCS_ALLFRAME
;
2333 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2334 jme
->reg_rxmcs
|= RXMCS_ALLMULFRAME
;
2335 } else if (netdev
->flags
& IFF_MULTICAST
) {
2336 struct netdev_hw_addr
*ha
;
2339 jme
->reg_rxmcs
|= RXMCS_MULFRAME
| RXMCS_MULFILTERED
;
2340 netdev_for_each_mc_addr(ha
, netdev
) {
2341 bit_nr
= ether_crc(ETH_ALEN
, ha
->addr
) & 0x3F;
2342 mc_hash
[bit_nr
>> 5] |= 1 << (bit_nr
& 0x1F);
2345 jwrite32(jme
, JME_RXMCHT_LO
, mc_hash
[0]);
2346 jwrite32(jme
, JME_RXMCHT_HI
, mc_hash
[1]);
2350 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2352 spin_unlock_bh(&jme
->rxmcs_lock
);
2356 jme_change_mtu(struct net_device
*netdev
, int new_mtu
)
2358 struct jme_adapter
*jme
= netdev_priv(netdev
);
2360 if (new_mtu
== jme
->old_mtu
)
2363 if (((new_mtu
+ ETH_HLEN
) > MAX_ETHERNET_JUMBO_PACKET_SIZE
) ||
2364 ((new_mtu
) < IPV6_MIN_MTU
))
2368 netdev
->mtu
= new_mtu
;
2369 netdev_update_features(netdev
);
2371 jme_restart_rx_engine(jme
);
2372 jme_reset_link(jme
);
2378 jme_tx_timeout(struct net_device
*netdev
)
2380 struct jme_adapter
*jme
= netdev_priv(netdev
);
2383 jme_reset_phy_processor(jme
);
2384 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
2385 jme_set_settings(netdev
, &jme
->old_ecmd
);
2388 * Force to Reset the link again
2390 jme_reset_link(jme
);
2393 static inline void jme_pause_rx(struct jme_adapter
*jme
)
2395 atomic_dec(&jme
->link_changing
);
2397 jme_set_rx_pcc(jme
, PCC_OFF
);
2398 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2399 JME_NAPI_DISABLE(jme
);
2401 tasklet_disable(&jme
->rxclean_task
);
2402 tasklet_disable(&jme
->rxempty_task
);
2406 static inline void jme_resume_rx(struct jme_adapter
*jme
)
2408 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2410 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2411 JME_NAPI_ENABLE(jme
);
2413 tasklet_enable(&jme
->rxclean_task
);
2414 tasklet_enable(&jme
->rxempty_task
);
2417 dpi
->attempt
= PCC_P1
;
2419 jme_set_rx_pcc(jme
, PCC_P1
);
2421 atomic_inc(&jme
->link_changing
);
2425 jme_get_drvinfo(struct net_device
*netdev
,
2426 struct ethtool_drvinfo
*info
)
2428 struct jme_adapter
*jme
= netdev_priv(netdev
);
2430 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
2431 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
2432 strlcpy(info
->bus_info
, pci_name(jme
->pdev
), sizeof(info
->bus_info
));
2436 jme_get_regs_len(struct net_device
*netdev
)
2442 mmapio_memcpy(struct jme_adapter
*jme
, u32
*p
, u32 reg
, int len
)
2446 for (i
= 0 ; i
< len
; i
+= 4)
2447 p
[i
>> 2] = jread32(jme
, reg
+ i
);
2451 mdio_memcpy(struct jme_adapter
*jme
, u32
*p
, int reg_nr
)
2454 u16
*p16
= (u16
*)p
;
2456 for (i
= 0 ; i
< reg_nr
; ++i
)
2457 p16
[i
] = jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, i
);
2461 jme_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
2463 struct jme_adapter
*jme
= netdev_priv(netdev
);
2464 u32
*p32
= (u32
*)p
;
2466 memset(p
, 0xFF, JME_REG_LEN
);
2469 mmapio_memcpy(jme
, p32
, JME_MAC
, JME_MAC_LEN
);
2472 mmapio_memcpy(jme
, p32
, JME_PHY
, JME_PHY_LEN
);
2475 mmapio_memcpy(jme
, p32
, JME_MISC
, JME_MISC_LEN
);
2478 mmapio_memcpy(jme
, p32
, JME_RSS
, JME_RSS_LEN
);
2481 mdio_memcpy(jme
, p32
, JME_PHY_REG_NR
);
2485 jme_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2487 struct jme_adapter
*jme
= netdev_priv(netdev
);
2489 ecmd
->tx_coalesce_usecs
= PCC_TX_TO
;
2490 ecmd
->tx_max_coalesced_frames
= PCC_TX_CNT
;
2492 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2493 ecmd
->use_adaptive_rx_coalesce
= false;
2494 ecmd
->rx_coalesce_usecs
= 0;
2495 ecmd
->rx_max_coalesced_frames
= 0;
2499 ecmd
->use_adaptive_rx_coalesce
= true;
2501 switch (jme
->dpi
.cur
) {
2503 ecmd
->rx_coalesce_usecs
= PCC_P1_TO
;
2504 ecmd
->rx_max_coalesced_frames
= PCC_P1_CNT
;
2507 ecmd
->rx_coalesce_usecs
= PCC_P2_TO
;
2508 ecmd
->rx_max_coalesced_frames
= PCC_P2_CNT
;
2511 ecmd
->rx_coalesce_usecs
= PCC_P3_TO
;
2512 ecmd
->rx_max_coalesced_frames
= PCC_P3_CNT
;
2522 jme_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2524 struct jme_adapter
*jme
= netdev_priv(netdev
);
2525 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2527 if (netif_running(netdev
))
2530 if (ecmd
->use_adaptive_rx_coalesce
&&
2531 test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2532 clear_bit(JME_FLAG_POLL
, &jme
->flags
);
2533 jme
->jme_rx
= netif_rx
;
2535 dpi
->attempt
= PCC_P1
;
2537 jme_set_rx_pcc(jme
, PCC_P1
);
2538 jme_interrupt_mode(jme
);
2539 } else if (!(ecmd
->use_adaptive_rx_coalesce
) &&
2540 !(test_bit(JME_FLAG_POLL
, &jme
->flags
))) {
2541 set_bit(JME_FLAG_POLL
, &jme
->flags
);
2542 jme
->jme_rx
= netif_receive_skb
;
2543 jme_interrupt_mode(jme
);
2550 jme_get_pauseparam(struct net_device
*netdev
,
2551 struct ethtool_pauseparam
*ecmd
)
2553 struct jme_adapter
*jme
= netdev_priv(netdev
);
2556 ecmd
->tx_pause
= (jme
->reg_txpfc
& TXPFC_PF_EN
) != 0;
2557 ecmd
->rx_pause
= (jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0;
2559 spin_lock_bh(&jme
->phy_lock
);
2560 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2561 spin_unlock_bh(&jme
->phy_lock
);
2564 (val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0;
2568 jme_set_pauseparam(struct net_device
*netdev
,
2569 struct ethtool_pauseparam
*ecmd
)
2571 struct jme_adapter
*jme
= netdev_priv(netdev
);
2574 if (((jme
->reg_txpfc
& TXPFC_PF_EN
) != 0) ^
2575 (ecmd
->tx_pause
!= 0)) {
2578 jme
->reg_txpfc
|= TXPFC_PF_EN
;
2580 jme
->reg_txpfc
&= ~TXPFC_PF_EN
;
2582 jwrite32(jme
, JME_TXPFC
, jme
->reg_txpfc
);
2585 spin_lock_bh(&jme
->rxmcs_lock
);
2586 if (((jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0) ^
2587 (ecmd
->rx_pause
!= 0)) {
2590 jme
->reg_rxmcs
|= RXMCS_FLOWCTRL
;
2592 jme
->reg_rxmcs
&= ~RXMCS_FLOWCTRL
;
2594 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2596 spin_unlock_bh(&jme
->rxmcs_lock
);
2598 spin_lock_bh(&jme
->phy_lock
);
2599 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2600 if (((val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0) ^
2601 (ecmd
->autoneg
!= 0)) {
2604 val
|= (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2606 val
&= ~(ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2608 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
,
2609 MII_ADVERTISE
, val
);
2611 spin_unlock_bh(&jme
->phy_lock
);
2617 jme_get_wol(struct net_device
*netdev
,
2618 struct ethtool_wolinfo
*wol
)
2620 struct jme_adapter
*jme
= netdev_priv(netdev
);
2622 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
2626 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
2627 wol
->wolopts
|= WAKE_PHY
;
2629 if (jme
->reg_pmcs
& PMCS_MFEN
)
2630 wol
->wolopts
|= WAKE_MAGIC
;
2635 jme_set_wol(struct net_device
*netdev
,
2636 struct ethtool_wolinfo
*wol
)
2638 struct jme_adapter
*jme
= netdev_priv(netdev
);
2640 if (wol
->wolopts
& (WAKE_MAGICSECURE
|
2649 if (wol
->wolopts
& WAKE_PHY
)
2650 jme
->reg_pmcs
|= PMCS_LFEN
| PMCS_LREN
;
2652 if (wol
->wolopts
& WAKE_MAGIC
)
2653 jme
->reg_pmcs
|= PMCS_MFEN
;
2659 jme_get_settings(struct net_device
*netdev
,
2660 struct ethtool_cmd
*ecmd
)
2662 struct jme_adapter
*jme
= netdev_priv(netdev
);
2665 spin_lock_bh(&jme
->phy_lock
);
2666 rc
= mii_ethtool_gset(&(jme
->mii_if
), ecmd
);
2667 spin_unlock_bh(&jme
->phy_lock
);
2672 jme_set_settings(struct net_device
*netdev
,
2673 struct ethtool_cmd
*ecmd
)
2675 struct jme_adapter
*jme
= netdev_priv(netdev
);
2678 if (ethtool_cmd_speed(ecmd
) == SPEED_1000
2679 && ecmd
->autoneg
!= AUTONEG_ENABLE
)
2683 * Check If user changed duplex only while force_media.
2684 * Hardware would not generate link change interrupt.
2686 if (jme
->mii_if
.force_media
&&
2687 ecmd
->autoneg
!= AUTONEG_ENABLE
&&
2688 (jme
->mii_if
.full_duplex
!= ecmd
->duplex
))
2691 spin_lock_bh(&jme
->phy_lock
);
2692 rc
= mii_ethtool_sset(&(jme
->mii_if
), ecmd
);
2693 spin_unlock_bh(&jme
->phy_lock
);
2697 jme_reset_link(jme
);
2698 jme
->old_ecmd
= *ecmd
;
2699 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2706 jme_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
2709 struct jme_adapter
*jme
= netdev_priv(netdev
);
2710 struct mii_ioctl_data
*mii_data
= if_mii(rq
);
2711 unsigned int duplex_chg
;
2713 if (cmd
== SIOCSMIIREG
) {
2714 u16 val
= mii_data
->val_in
;
2715 if (!(val
& (BMCR_RESET
|BMCR_ANENABLE
)) &&
2716 (val
& BMCR_SPEED1000
))
2720 spin_lock_bh(&jme
->phy_lock
);
2721 rc
= generic_mii_ioctl(&jme
->mii_if
, mii_data
, cmd
, &duplex_chg
);
2722 spin_unlock_bh(&jme
->phy_lock
);
2724 if (!rc
&& (cmd
== SIOCSMIIREG
)) {
2726 jme_reset_link(jme
);
2727 jme_get_settings(netdev
, &jme
->old_ecmd
);
2728 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2735 jme_get_link(struct net_device
*netdev
)
2737 struct jme_adapter
*jme
= netdev_priv(netdev
);
2738 return jread32(jme
, JME_PHY_LINK
) & PHY_LINK_UP
;
2742 jme_get_msglevel(struct net_device
*netdev
)
2744 struct jme_adapter
*jme
= netdev_priv(netdev
);
2745 return jme
->msg_enable
;
2749 jme_set_msglevel(struct net_device
*netdev
, u32 value
)
2751 struct jme_adapter
*jme
= netdev_priv(netdev
);
2752 jme
->msg_enable
= value
;
2755 static netdev_features_t
2756 jme_fix_features(struct net_device
*netdev
, netdev_features_t features
)
2758 if (netdev
->mtu
> 1900)
2759 features
&= ~(NETIF_F_ALL_TSO
| NETIF_F_CSUM_MASK
);
2764 jme_set_features(struct net_device
*netdev
, netdev_features_t features
)
2766 struct jme_adapter
*jme
= netdev_priv(netdev
);
2768 spin_lock_bh(&jme
->rxmcs_lock
);
2769 if (features
& NETIF_F_RXCSUM
)
2770 jme
->reg_rxmcs
|= RXMCS_CHECKSUM
;
2772 jme
->reg_rxmcs
&= ~RXMCS_CHECKSUM
;
2773 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2774 spin_unlock_bh(&jme
->rxmcs_lock
);
2779 #ifdef CONFIG_NET_POLL_CONTROLLER
2780 static void jme_netpoll(struct net_device
*dev
)
2782 unsigned long flags
;
2784 local_irq_save(flags
);
2785 jme_intr(dev
->irq
, dev
);
2786 local_irq_restore(flags
);
2791 jme_nway_reset(struct net_device
*netdev
)
2793 struct jme_adapter
*jme
= netdev_priv(netdev
);
2794 jme_restart_an(jme
);
2799 jme_smb_read(struct jme_adapter
*jme
, unsigned int addr
)
2804 val
= jread32(jme
, JME_SMBCSR
);
2805 to
= JME_SMB_BUSY_TIMEOUT
;
2806 while ((val
& SMBCSR_BUSY
) && --to
) {
2808 val
= jread32(jme
, JME_SMBCSR
);
2811 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2815 jwrite32(jme
, JME_SMBINTF
,
2816 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2817 SMBINTF_HWRWN_READ
|
2820 val
= jread32(jme
, JME_SMBINTF
);
2821 to
= JME_SMB_BUSY_TIMEOUT
;
2822 while ((val
& SMBINTF_HWCMD
) && --to
) {
2824 val
= jread32(jme
, JME_SMBINTF
);
2827 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2831 return (val
& SMBINTF_HWDATR
) >> SMBINTF_HWDATR_SHIFT
;
2835 jme_smb_write(struct jme_adapter
*jme
, unsigned int addr
, u8 data
)
2840 val
= jread32(jme
, JME_SMBCSR
);
2841 to
= JME_SMB_BUSY_TIMEOUT
;
2842 while ((val
& SMBCSR_BUSY
) && --to
) {
2844 val
= jread32(jme
, JME_SMBCSR
);
2847 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2851 jwrite32(jme
, JME_SMBINTF
,
2852 ((data
<< SMBINTF_HWDATW_SHIFT
) & SMBINTF_HWDATW
) |
2853 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2854 SMBINTF_HWRWN_WRITE
|
2857 val
= jread32(jme
, JME_SMBINTF
);
2858 to
= JME_SMB_BUSY_TIMEOUT
;
2859 while ((val
& SMBINTF_HWCMD
) && --to
) {
2861 val
= jread32(jme
, JME_SMBINTF
);
2864 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2872 jme_get_eeprom_len(struct net_device
*netdev
)
2874 struct jme_adapter
*jme
= netdev_priv(netdev
);
2876 val
= jread32(jme
, JME_SMBCSR
);
2877 return (val
& SMBCSR_EEPROMD
) ? JME_SMB_LEN
: 0;
2881 jme_get_eeprom(struct net_device
*netdev
,
2882 struct ethtool_eeprom
*eeprom
, u8
*data
)
2884 struct jme_adapter
*jme
= netdev_priv(netdev
);
2885 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2888 * ethtool will check the boundary for us
2890 eeprom
->magic
= JME_EEPROM_MAGIC
;
2891 for (i
= 0 ; i
< len
; ++i
)
2892 data
[i
] = jme_smb_read(jme
, i
+ offset
);
2898 jme_set_eeprom(struct net_device
*netdev
,
2899 struct ethtool_eeprom
*eeprom
, u8
*data
)
2901 struct jme_adapter
*jme
= netdev_priv(netdev
);
2902 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2904 if (eeprom
->magic
!= JME_EEPROM_MAGIC
)
2908 * ethtool will check the boundary for us
2910 for (i
= 0 ; i
< len
; ++i
)
2911 jme_smb_write(jme
, i
+ offset
, data
[i
]);
2916 static const struct ethtool_ops jme_ethtool_ops
= {
2917 .get_drvinfo
= jme_get_drvinfo
,
2918 .get_regs_len
= jme_get_regs_len
,
2919 .get_regs
= jme_get_regs
,
2920 .get_coalesce
= jme_get_coalesce
,
2921 .set_coalesce
= jme_set_coalesce
,
2922 .get_pauseparam
= jme_get_pauseparam
,
2923 .set_pauseparam
= jme_set_pauseparam
,
2924 .get_wol
= jme_get_wol
,
2925 .set_wol
= jme_set_wol
,
2926 .get_settings
= jme_get_settings
,
2927 .set_settings
= jme_set_settings
,
2928 .get_link
= jme_get_link
,
2929 .get_msglevel
= jme_get_msglevel
,
2930 .set_msglevel
= jme_set_msglevel
,
2931 .nway_reset
= jme_nway_reset
,
2932 .get_eeprom_len
= jme_get_eeprom_len
,
2933 .get_eeprom
= jme_get_eeprom
,
2934 .set_eeprom
= jme_set_eeprom
,
2938 jme_pci_dma64(struct pci_dev
*pdev
)
2940 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2941 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
2942 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
2945 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2946 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(40)))
2947 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(40)))
2950 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)))
2951 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
2958 jme_phy_init(struct jme_adapter
*jme
)
2962 reg26
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 26);
2963 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 26, reg26
| 0x1000);
2967 jme_check_hw_ver(struct jme_adapter
*jme
)
2971 chipmode
= jread32(jme
, JME_CHIPMODE
);
2973 jme
->fpgaver
= (chipmode
& CM_FPGAVER_MASK
) >> CM_FPGAVER_SHIFT
;
2974 jme
->chiprev
= (chipmode
& CM_CHIPREV_MASK
) >> CM_CHIPREV_SHIFT
;
2975 jme
->chip_main_rev
= jme
->chiprev
& 0xF;
2976 jme
->chip_sub_rev
= (jme
->chiprev
>> 4) & 0xF;
2979 static const struct net_device_ops jme_netdev_ops
= {
2980 .ndo_open
= jme_open
,
2981 .ndo_stop
= jme_close
,
2982 .ndo_validate_addr
= eth_validate_addr
,
2983 .ndo_do_ioctl
= jme_ioctl
,
2984 .ndo_start_xmit
= jme_start_xmit
,
2985 .ndo_set_mac_address
= jme_set_macaddr
,
2986 .ndo_set_rx_mode
= jme_set_multi
,
2987 .ndo_change_mtu
= jme_change_mtu
,
2988 .ndo_tx_timeout
= jme_tx_timeout
,
2989 .ndo_fix_features
= jme_fix_features
,
2990 .ndo_set_features
= jme_set_features
,
2991 #ifdef CONFIG_NET_POLL_CONTROLLER
2992 .ndo_poll_controller
= jme_netpoll
,
2997 jme_init_one(struct pci_dev
*pdev
,
2998 const struct pci_device_id
*ent
)
3000 int rc
= 0, using_dac
, i
;
3001 struct net_device
*netdev
;
3002 struct jme_adapter
*jme
;
3007 * set up PCI device basics
3009 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
| PCIE_LINK_STATE_L1
|
3010 PCIE_LINK_STATE_CLKPM
);
3012 rc
= pci_enable_device(pdev
);
3014 pr_err("Cannot enable PCI device\n");
3018 using_dac
= jme_pci_dma64(pdev
);
3019 if (using_dac
< 0) {
3020 pr_err("Cannot set PCI DMA Mask\n");
3022 goto err_out_disable_pdev
;
3025 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
3026 pr_err("No PCI resource region found\n");
3028 goto err_out_disable_pdev
;
3031 rc
= pci_request_regions(pdev
, DRV_NAME
);
3033 pr_err("Cannot obtain PCI resource region\n");
3034 goto err_out_disable_pdev
;
3037 pci_set_master(pdev
);
3040 * alloc and init net device
3042 netdev
= alloc_etherdev(sizeof(*jme
));
3045 goto err_out_release_regions
;
3047 netdev
->netdev_ops
= &jme_netdev_ops
;
3048 netdev
->ethtool_ops
= &jme_ethtool_ops
;
3049 netdev
->watchdog_timeo
= TX_TIMEOUT
;
3050 netdev
->hw_features
= NETIF_F_IP_CSUM
|
3056 netdev
->features
= NETIF_F_IP_CSUM
|
3061 NETIF_F_HW_VLAN_CTAG_TX
|
3062 NETIF_F_HW_VLAN_CTAG_RX
;
3064 netdev
->features
|= NETIF_F_HIGHDMA
;
3066 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3067 pci_set_drvdata(pdev
, netdev
);
3072 jme
= netdev_priv(netdev
);
3075 jme
->jme_rx
= netif_rx
;
3076 jme
->old_mtu
= netdev
->mtu
= 1500;
3078 jme
->tx_ring_size
= 1 << 10;
3079 jme
->tx_ring_mask
= jme
->tx_ring_size
- 1;
3080 jme
->tx_wake_threshold
= 1 << 9;
3081 jme
->rx_ring_size
= 1 << 9;
3082 jme
->rx_ring_mask
= jme
->rx_ring_size
- 1;
3083 jme
->msg_enable
= JME_DEF_MSG_ENABLE
;
3084 jme
->regs
= ioremap(pci_resource_start(pdev
, 0),
3085 pci_resource_len(pdev
, 0));
3087 pr_err("Mapping PCI resource region error\n");
3089 goto err_out_free_netdev
;
3093 apmc
= jread32(jme
, JME_APMC
) & ~JME_APMC_PSEUDO_HP_EN
;
3094 jwrite32(jme
, JME_APMC
, apmc
);
3095 } else if (force_pseudohp
) {
3096 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PSEUDO_HP_EN
;
3097 jwrite32(jme
, JME_APMC
, apmc
);
3100 NETIF_NAPI_SET(netdev
, &jme
->napi
, jme_poll
, NAPI_POLL_WEIGHT
)
3102 spin_lock_init(&jme
->phy_lock
);
3103 spin_lock_init(&jme
->macaddr_lock
);
3104 spin_lock_init(&jme
->rxmcs_lock
);
3106 atomic_set(&jme
->link_changing
, 1);
3107 atomic_set(&jme
->rx_cleaning
, 1);
3108 atomic_set(&jme
->tx_cleaning
, 1);
3109 atomic_set(&jme
->rx_empty
, 1);
3111 tasklet_init(&jme
->pcc_task
,
3113 (unsigned long) jme
);
3114 jme
->dpi
.cur
= PCC_P1
;
3117 jme
->reg_rxcs
= RXCS_DEFAULT
;
3118 jme
->reg_rxmcs
= RXMCS_DEFAULT
;
3120 jme
->reg_pmcs
= PMCS_MFEN
;
3121 jme
->reg_gpreg1
= GPREG1_DEFAULT
;
3123 if (jme
->reg_rxmcs
& RXMCS_CHECKSUM
)
3124 netdev
->features
|= NETIF_F_RXCSUM
;
3127 * Get Max Read Req Size from PCI Config Space
3129 pci_read_config_byte(pdev
, PCI_DCSR_MRRS
, &jme
->mrrs
);
3130 jme
->mrrs
&= PCI_DCSR_MRRS_MASK
;
3131 switch (jme
->mrrs
) {
3133 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_128B
;
3136 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_256B
;
3139 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_512B
;
3144 * Must check before reset_mac_processor
3146 jme_check_hw_ver(jme
);
3147 jme
->mii_if
.dev
= netdev
;
3149 jme
->mii_if
.phy_id
= 0;
3150 for (i
= 1 ; i
< 32 ; ++i
) {
3151 bmcr
= jme_mdio_read(netdev
, i
, MII_BMCR
);
3152 bmsr
= jme_mdio_read(netdev
, i
, MII_BMSR
);
3153 if (bmcr
!= 0xFFFFU
&& (bmcr
!= 0 || bmsr
!= 0)) {
3154 jme
->mii_if
.phy_id
= i
;
3159 if (!jme
->mii_if
.phy_id
) {
3161 pr_err("Can not find phy_id\n");
3165 jme
->reg_ghc
|= GHC_LINK_POLL
;
3167 jme
->mii_if
.phy_id
= 1;
3169 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
3170 jme
->mii_if
.supports_gmii
= true;
3172 jme
->mii_if
.supports_gmii
= false;
3173 jme
->mii_if
.phy_id_mask
= 0x1F;
3174 jme
->mii_if
.reg_num_mask
= 0x1F;
3175 jme
->mii_if
.mdio_read
= jme_mdio_read
;
3176 jme
->mii_if
.mdio_write
= jme_mdio_write
;
3178 jme_clear_pm_disable_wol(jme
);
3179 device_init_wakeup(&pdev
->dev
, true);
3181 jme_set_phyfifo_5level(jme
);
3182 jme
->pcirev
= pdev
->revision
;
3188 * Reset MAC processor and reload EEPROM for MAC Address
3190 jme_reset_mac_processor(jme
);
3191 rc
= jme_reload_eeprom(jme
);
3193 pr_err("Reload eeprom for reading MAC Address error\n");
3196 jme_load_macaddr(netdev
);
3199 * Tell stack that we are not ready to work until open()
3201 netif_carrier_off(netdev
);
3203 rc
= register_netdev(netdev
);
3205 pr_err("Cannot register net device\n");
3209 netif_info(jme
, probe
, jme
->dev
, "%s%s chiprev:%x pcirev:%x macaddr:%pM\n",
3210 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
) ?
3211 "JMC250 Gigabit Ethernet" :
3212 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC260
) ?
3213 "JMC260 Fast Ethernet" : "Unknown",
3214 (jme
->fpgaver
!= 0) ? " (FPGA)" : "",
3215 (jme
->fpgaver
!= 0) ? jme
->fpgaver
: jme
->chiprev
,
3216 jme
->pcirev
, netdev
->dev_addr
);
3222 err_out_free_netdev
:
3223 free_netdev(netdev
);
3224 err_out_release_regions
:
3225 pci_release_regions(pdev
);
3226 err_out_disable_pdev
:
3227 pci_disable_device(pdev
);
3233 jme_remove_one(struct pci_dev
*pdev
)
3235 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3236 struct jme_adapter
*jme
= netdev_priv(netdev
);
3238 unregister_netdev(netdev
);
3240 free_netdev(netdev
);
3241 pci_release_regions(pdev
);
3242 pci_disable_device(pdev
);
3247 jme_shutdown(struct pci_dev
*pdev
)
3249 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3250 struct jme_adapter
*jme
= netdev_priv(netdev
);
3252 jme_powersave_phy(jme
);
3253 pci_pme_active(pdev
, true);
3256 #ifdef CONFIG_PM_SLEEP
3258 jme_suspend(struct device
*dev
)
3260 struct pci_dev
*pdev
= to_pci_dev(dev
);
3261 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3262 struct jme_adapter
*jme
= netdev_priv(netdev
);
3264 if (!netif_running(netdev
))
3267 atomic_dec(&jme
->link_changing
);
3269 netif_device_detach(netdev
);
3270 netif_stop_queue(netdev
);
3273 tasklet_disable(&jme
->txclean_task
);
3274 tasklet_disable(&jme
->rxclean_task
);
3275 tasklet_disable(&jme
->rxempty_task
);
3277 if (netif_carrier_ok(netdev
)) {
3278 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
3279 jme_polling_mode(jme
);
3281 jme_stop_pcc_timer(jme
);
3282 jme_disable_rx_engine(jme
);
3283 jme_disable_tx_engine(jme
);
3284 jme_reset_mac_processor(jme
);
3285 jme_free_rx_resources(jme
);
3286 jme_free_tx_resources(jme
);
3287 netif_carrier_off(netdev
);
3291 tasklet_enable(&jme
->txclean_task
);
3292 tasklet_enable(&jme
->rxclean_task
);
3293 tasklet_enable(&jme
->rxempty_task
);
3295 jme_powersave_phy(jme
);
3301 jme_resume(struct device
*dev
)
3303 struct pci_dev
*pdev
= to_pci_dev(dev
);
3304 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3305 struct jme_adapter
*jme
= netdev_priv(netdev
);
3307 if (!netif_running(netdev
))
3310 jme_clear_pm_disable_wol(jme
);
3312 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
3313 jme_set_settings(netdev
, &jme
->old_ecmd
);
3315 jme_reset_phy_processor(jme
);
3316 jme_phy_calibration(jme
);
3318 netif_device_attach(netdev
);
3320 atomic_inc(&jme
->link_changing
);
3322 jme_reset_link(jme
);
3329 static SIMPLE_DEV_PM_OPS(jme_pm_ops
, jme_suspend
, jme_resume
);
3330 #define JME_PM_OPS (&jme_pm_ops)
3334 #define JME_PM_OPS NULL
3337 static const struct pci_device_id jme_pci_tbl
[] = {
3338 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC250
) },
3339 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC260
) },
3343 static struct pci_driver jme_driver
= {
3345 .id_table
= jme_pci_tbl
,
3346 .probe
= jme_init_one
,
3347 .remove
= jme_remove_one
,
3348 .shutdown
= jme_shutdown
,
3349 .driver
.pm
= JME_PM_OPS
,
3353 jme_init_module(void)
3355 pr_info("JMicron JMC2XX ethernet driver version %s\n", DRV_VERSION
);
3356 return pci_register_driver(&jme_driver
);
3360 jme_cleanup_module(void)
3362 pci_unregister_driver(&jme_driver
);
3365 module_init(jme_init_module
);
3366 module_exit(jme_cleanup_module
);
3368 MODULE_AUTHOR("Guo-Fu Tseng <cooldavid@cooldavid.org>");
3369 MODULE_DESCRIPTION("JMicron JMC2x0 PCI Express Ethernet driver");
3370 MODULE_LICENSE("GPL");
3371 MODULE_VERSION(DRV_VERSION
);
3372 MODULE_DEVICE_TABLE(pci
, jme_pci_tbl
);