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(struct jme_adapter
*jme
)
275 jwrite32(jme
, JME_PMCS
, PMCS_STMASK
| jme
->reg_pmcs
);
279 jme_reload_eeprom(struct jme_adapter
*jme
)
284 val
= jread32(jme
, JME_SMBCSR
);
286 if (val
& SMBCSR_EEPROMD
) {
288 jwrite32(jme
, JME_SMBCSR
, val
);
289 val
|= SMBCSR_RELOAD
;
290 jwrite32(jme
, JME_SMBCSR
, val
);
293 for (i
= JME_EEPROM_RELOAD_TIMEOUT
; i
> 0; --i
) {
295 if ((jread32(jme
, JME_SMBCSR
) & SMBCSR_RELOAD
) == 0)
300 pr_err("eeprom reload timeout\n");
309 jme_load_macaddr(struct net_device
*netdev
)
311 struct jme_adapter
*jme
= netdev_priv(netdev
);
312 unsigned char macaddr
[ETH_ALEN
];
315 spin_lock_bh(&jme
->macaddr_lock
);
316 val
= jread32(jme
, JME_RXUMA_LO
);
317 macaddr
[0] = (val
>> 0) & 0xFF;
318 macaddr
[1] = (val
>> 8) & 0xFF;
319 macaddr
[2] = (val
>> 16) & 0xFF;
320 macaddr
[3] = (val
>> 24) & 0xFF;
321 val
= jread32(jme
, JME_RXUMA_HI
);
322 macaddr
[4] = (val
>> 0) & 0xFF;
323 macaddr
[5] = (val
>> 8) & 0xFF;
324 memcpy(netdev
->dev_addr
, macaddr
, ETH_ALEN
);
325 spin_unlock_bh(&jme
->macaddr_lock
);
329 jme_set_rx_pcc(struct jme_adapter
*jme
, int p
)
333 jwrite32(jme
, JME_PCCRX0
,
334 ((PCC_OFF_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
335 ((PCC_OFF_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
338 jwrite32(jme
, JME_PCCRX0
,
339 ((PCC_P1_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
340 ((PCC_P1_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
343 jwrite32(jme
, JME_PCCRX0
,
344 ((PCC_P2_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
345 ((PCC_P2_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
348 jwrite32(jme
, JME_PCCRX0
,
349 ((PCC_P3_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
350 ((PCC_P3_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
357 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
358 netif_info(jme
, rx_status
, jme
->dev
, "Switched to PCC_P%d\n", p
);
362 jme_start_irq(struct jme_adapter
*jme
)
364 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
366 jme_set_rx_pcc(jme
, PCC_P1
);
368 dpi
->attempt
= PCC_P1
;
371 jwrite32(jme
, JME_PCCTX
,
372 ((PCC_TX_TO
<< PCCTXTO_SHIFT
) & PCCTXTO_MASK
) |
373 ((PCC_TX_CNT
<< PCCTX_SHIFT
) & PCCTX_MASK
) |
380 jwrite32(jme
, JME_IENS
, INTR_ENABLE
);
384 jme_stop_irq(struct jme_adapter
*jme
)
389 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
393 jme_linkstat_from_phy(struct jme_adapter
*jme
)
397 phylink
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 17);
398 bmsr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMSR
);
399 if (bmsr
& BMSR_ANCOMP
)
400 phylink
|= PHY_LINK_AUTONEG_COMPLETE
;
406 jme_set_phyfifo_5level(struct jme_adapter
*jme
)
408 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0004);
412 jme_set_phyfifo_8level(struct jme_adapter
*jme
)
414 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0000);
418 jme_check_link(struct net_device
*netdev
, int testonly
)
420 struct jme_adapter
*jme
= netdev_priv(netdev
);
421 u32 phylink
, cnt
= JME_SPDRSV_TIMEOUT
, bmcr
;
428 phylink
= jme_linkstat_from_phy(jme
);
430 phylink
= jread32(jme
, JME_PHY_LINK
);
432 if (phylink
& PHY_LINK_UP
) {
433 if (!(phylink
& PHY_LINK_AUTONEG_COMPLETE
)) {
435 * If we did not enable AN
436 * Speed/Duplex Info should be obtained from SMI
438 phylink
= PHY_LINK_UP
;
440 bmcr
= jme_mdio_read(jme
->dev
,
444 phylink
|= ((bmcr
& BMCR_SPEED1000
) &&
445 (bmcr
& BMCR_SPEED100
) == 0) ?
446 PHY_LINK_SPEED_1000M
:
447 (bmcr
& BMCR_SPEED100
) ?
448 PHY_LINK_SPEED_100M
:
451 phylink
|= (bmcr
& BMCR_FULLDPLX
) ?
454 strcat(linkmsg
, "Forced: ");
457 * Keep polling for speed/duplex resolve complete
459 while (!(phylink
& PHY_LINK_SPEEDDPU_RESOLVED
) &&
465 phylink
= jme_linkstat_from_phy(jme
);
467 phylink
= jread32(jme
, JME_PHY_LINK
);
470 pr_err("Waiting speed resolve timeout\n");
472 strcat(linkmsg
, "ANed: ");
475 if (jme
->phylink
== phylink
) {
482 jme
->phylink
= phylink
;
485 * The speed/duplex setting of jme->reg_ghc already cleared
486 * by jme_reset_mac_processor()
488 switch (phylink
& PHY_LINK_SPEED_MASK
) {
489 case PHY_LINK_SPEED_10M
:
490 jme
->reg_ghc
|= GHC_SPEED_10M
;
491 strcat(linkmsg
, "10 Mbps, ");
493 case PHY_LINK_SPEED_100M
:
494 jme
->reg_ghc
|= GHC_SPEED_100M
;
495 strcat(linkmsg
, "100 Mbps, ");
497 case PHY_LINK_SPEED_1000M
:
498 jme
->reg_ghc
|= GHC_SPEED_1000M
;
499 strcat(linkmsg
, "1000 Mbps, ");
505 if (phylink
& PHY_LINK_DUPLEX
) {
506 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
);
507 jwrite32(jme
, JME_TXTRHD
, TXTRHD_FULLDUPLEX
);
508 jme
->reg_ghc
|= GHC_DPX
;
510 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
|
514 jwrite32(jme
, JME_TXTRHD
, TXTRHD_HALFDUPLEX
);
517 jwrite32(jme
, JME_GHC
, jme
->reg_ghc
);
519 if (is_buggy250(jme
->pdev
->device
, jme
->chiprev
)) {
520 jme
->reg_gpreg1
&= ~(GPREG1_HALFMODEPATCH
|
522 if (!(phylink
& PHY_LINK_DUPLEX
))
523 jme
->reg_gpreg1
|= GPREG1_HALFMODEPATCH
;
524 switch (phylink
& PHY_LINK_SPEED_MASK
) {
525 case PHY_LINK_SPEED_10M
:
526 jme_set_phyfifo_8level(jme
);
527 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
529 case PHY_LINK_SPEED_100M
:
530 jme_set_phyfifo_5level(jme
);
531 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
533 case PHY_LINK_SPEED_1000M
:
534 jme_set_phyfifo_8level(jme
);
540 jwrite32(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
542 strcat(linkmsg
, (phylink
& PHY_LINK_DUPLEX
) ?
545 strcat(linkmsg
, (phylink
& PHY_LINK_MDI_STAT
) ?
548 netif_info(jme
, link
, jme
->dev
, "Link is up at %s\n", linkmsg
);
549 netif_carrier_on(netdev
);
554 netif_info(jme
, link
, jme
->dev
, "Link is down\n");
556 netif_carrier_off(netdev
);
564 jme_setup_tx_resources(struct jme_adapter
*jme
)
566 struct jme_ring
*txring
= &(jme
->txring
[0]);
568 txring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
569 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
579 txring
->desc
= (void *)ALIGN((unsigned long)(txring
->alloc
),
581 txring
->dma
= ALIGN(txring
->dmaalloc
, RING_DESC_ALIGN
);
582 txring
->next_to_use
= 0;
583 atomic_set(&txring
->next_to_clean
, 0);
584 atomic_set(&txring
->nr_free
, jme
->tx_ring_size
);
586 txring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
587 jme
->tx_ring_size
, GFP_ATOMIC
);
588 if (unlikely(!(txring
->bufinf
)))
589 goto err_free_txring
;
592 * Initialize Transmit Descriptors
594 memset(txring
->alloc
, 0, TX_RING_ALLOC_SIZE(jme
->tx_ring_size
));
595 memset(txring
->bufinf
, 0,
596 sizeof(struct jme_buffer_info
) * jme
->tx_ring_size
);
601 dma_free_coherent(&(jme
->pdev
->dev
),
602 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
608 txring
->dmaalloc
= 0;
610 txring
->bufinf
= NULL
;
616 jme_free_tx_resources(struct jme_adapter
*jme
)
619 struct jme_ring
*txring
= &(jme
->txring
[0]);
620 struct jme_buffer_info
*txbi
;
623 if (txring
->bufinf
) {
624 for (i
= 0 ; i
< jme
->tx_ring_size
; ++i
) {
625 txbi
= txring
->bufinf
+ i
;
627 dev_kfree_skb(txbi
->skb
);
633 txbi
->start_xmit
= 0;
635 kfree(txring
->bufinf
);
638 dma_free_coherent(&(jme
->pdev
->dev
),
639 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
643 txring
->alloc
= NULL
;
645 txring
->dmaalloc
= 0;
647 txring
->bufinf
= NULL
;
649 txring
->next_to_use
= 0;
650 atomic_set(&txring
->next_to_clean
, 0);
651 atomic_set(&txring
->nr_free
, 0);
655 jme_enable_tx_engine(struct jme_adapter
*jme
)
660 jwrite32(jme
, JME_TXCS
, TXCS_DEFAULT
| TXCS_SELECT_QUEUE0
);
664 * Setup TX Queue 0 DMA Bass Address
666 jwrite32(jme
, JME_TXDBA_LO
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
667 jwrite32(jme
, JME_TXDBA_HI
, (__u64
)(jme
->txring
[0].dma
) >> 32);
668 jwrite32(jme
, JME_TXNDA
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
671 * Setup TX Descptor Count
673 jwrite32(jme
, JME_TXQDC
, jme
->tx_ring_size
);
679 jwrite32f(jme
, JME_TXCS
, jme
->reg_txcs
|
684 * Start clock for TX MAC Processor
686 jme_mac_txclk_on(jme
);
690 jme_restart_tx_engine(struct jme_adapter
*jme
)
695 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
701 jme_disable_tx_engine(struct jme_adapter
*jme
)
709 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
| TXCS_SELECT_QUEUE0
);
712 val
= jread32(jme
, JME_TXCS
);
713 for (i
= JME_TX_DISABLE_TIMEOUT
; (val
& TXCS_ENABLE
) && i
> 0 ; --i
) {
715 val
= jread32(jme
, JME_TXCS
);
720 pr_err("Disable TX engine timeout\n");
723 * Stop clock for TX MAC Processor
725 jme_mac_txclk_off(jme
);
729 jme_set_clean_rxdesc(struct jme_adapter
*jme
, int i
)
731 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
732 register struct rxdesc
*rxdesc
= rxring
->desc
;
733 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
739 rxdesc
->desc1
.bufaddrh
= cpu_to_le32((__u64
)rxbi
->mapping
>> 32);
740 rxdesc
->desc1
.bufaddrl
= cpu_to_le32(
741 (__u64
)rxbi
->mapping
& 0xFFFFFFFFUL
);
742 rxdesc
->desc1
.datalen
= cpu_to_le16(rxbi
->len
);
743 if (jme
->dev
->features
& NETIF_F_HIGHDMA
)
744 rxdesc
->desc1
.flags
= RXFLAG_64BIT
;
746 rxdesc
->desc1
.flags
|= RXFLAG_OWN
| RXFLAG_INT
;
750 jme_make_new_rx_buf(struct jme_adapter
*jme
, int i
)
752 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
753 struct jme_buffer_info
*rxbi
= rxring
->bufinf
+ i
;
757 skb
= netdev_alloc_skb(jme
->dev
,
758 jme
->dev
->mtu
+ RX_EXTRA_LEN
);
762 mapping
= pci_map_page(jme
->pdev
, virt_to_page(skb
->data
),
763 offset_in_page(skb
->data
), skb_tailroom(skb
),
765 if (unlikely(pci_dma_mapping_error(jme
->pdev
, mapping
))) {
770 if (likely(rxbi
->mapping
))
771 pci_unmap_page(jme
->pdev
, rxbi
->mapping
,
772 rxbi
->len
, PCI_DMA_FROMDEVICE
);
775 rxbi
->len
= skb_tailroom(skb
);
776 rxbi
->mapping
= mapping
;
781 jme_free_rx_buf(struct jme_adapter
*jme
, int i
)
783 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
784 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
788 pci_unmap_page(jme
->pdev
,
792 dev_kfree_skb(rxbi
->skb
);
800 jme_free_rx_resources(struct jme_adapter
*jme
)
803 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
806 if (rxring
->bufinf
) {
807 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
)
808 jme_free_rx_buf(jme
, i
);
809 kfree(rxring
->bufinf
);
812 dma_free_coherent(&(jme
->pdev
->dev
),
813 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
816 rxring
->alloc
= NULL
;
818 rxring
->dmaalloc
= 0;
820 rxring
->bufinf
= NULL
;
822 rxring
->next_to_use
= 0;
823 atomic_set(&rxring
->next_to_clean
, 0);
827 jme_setup_rx_resources(struct jme_adapter
*jme
)
830 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
832 rxring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
833 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
842 rxring
->desc
= (void *)ALIGN((unsigned long)(rxring
->alloc
),
844 rxring
->dma
= ALIGN(rxring
->dmaalloc
, RING_DESC_ALIGN
);
845 rxring
->next_to_use
= 0;
846 atomic_set(&rxring
->next_to_clean
, 0);
848 rxring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
849 jme
->rx_ring_size
, GFP_ATOMIC
);
850 if (unlikely(!(rxring
->bufinf
)))
851 goto err_free_rxring
;
854 * Initiallize Receive Descriptors
856 memset(rxring
->bufinf
, 0,
857 sizeof(struct jme_buffer_info
) * jme
->rx_ring_size
);
858 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
) {
859 if (unlikely(jme_make_new_rx_buf(jme
, i
))) {
860 jme_free_rx_resources(jme
);
864 jme_set_clean_rxdesc(jme
, i
);
870 dma_free_coherent(&(jme
->pdev
->dev
),
871 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
876 rxring
->dmaalloc
= 0;
878 rxring
->bufinf
= NULL
;
884 jme_enable_rx_engine(struct jme_adapter
*jme
)
889 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
894 * Setup RX DMA Bass Address
896 jwrite32(jme
, JME_RXDBA_LO
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
897 jwrite32(jme
, JME_RXDBA_HI
, (__u64
)(jme
->rxring
[0].dma
) >> 32);
898 jwrite32(jme
, JME_RXNDA
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
901 * Setup RX Descriptor Count
903 jwrite32(jme
, JME_RXQDC
, jme
->rx_ring_size
);
906 * Setup Unicast Filter
908 jme_set_unicastaddr(jme
->dev
);
909 jme_set_multi(jme
->dev
);
915 jwrite32f(jme
, JME_RXCS
, jme
->reg_rxcs
|
921 * Start clock for RX MAC Processor
923 jme_mac_rxclk_on(jme
);
927 jme_restart_rx_engine(struct jme_adapter
*jme
)
932 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
939 jme_disable_rx_engine(struct jme_adapter
*jme
)
947 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
);
950 val
= jread32(jme
, JME_RXCS
);
951 for (i
= JME_RX_DISABLE_TIMEOUT
; (val
& RXCS_ENABLE
) && i
> 0 ; --i
) {
953 val
= jread32(jme
, JME_RXCS
);
958 pr_err("Disable RX engine timeout\n");
961 * Stop clock for RX MAC Processor
963 jme_mac_rxclk_off(jme
);
967 jme_udpsum(struct sk_buff
*skb
)
971 if (skb
->len
< (ETH_HLEN
+ sizeof(struct iphdr
)))
973 if (skb
->protocol
!= htons(ETH_P_IP
))
975 skb_set_network_header(skb
, ETH_HLEN
);
976 if ((ip_hdr(skb
)->protocol
!= IPPROTO_UDP
) ||
977 (skb
->len
< (ETH_HLEN
+
978 (ip_hdr(skb
)->ihl
<< 2) +
979 sizeof(struct udphdr
)))) {
980 skb_reset_network_header(skb
);
983 skb_set_transport_header(skb
,
984 ETH_HLEN
+ (ip_hdr(skb
)->ihl
<< 2));
985 csum
= udp_hdr(skb
)->check
;
986 skb_reset_transport_header(skb
);
987 skb_reset_network_header(skb
);
993 jme_rxsum_ok(struct jme_adapter
*jme
, u16 flags
, struct sk_buff
*skb
)
995 if (!(flags
& (RXWBFLAG_TCPON
| RXWBFLAG_UDPON
| RXWBFLAG_IPV4
)))
998 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_TCPON
| RXWBFLAG_TCPCS
))
999 == RXWBFLAG_TCPON
)) {
1000 if (flags
& RXWBFLAG_IPV4
)
1001 netif_err(jme
, rx_err
, jme
->dev
, "TCP Checksum error\n");
1005 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_UDPON
| RXWBFLAG_UDPCS
))
1006 == RXWBFLAG_UDPON
) && jme_udpsum(skb
)) {
1007 if (flags
& RXWBFLAG_IPV4
)
1008 netif_err(jme
, rx_err
, jme
->dev
, "UDP Checksum error\n");
1012 if (unlikely((flags
& (RXWBFLAG_IPV4
| RXWBFLAG_IPCS
))
1013 == RXWBFLAG_IPV4
)) {
1014 netif_err(jme
, rx_err
, jme
->dev
, "IPv4 Checksum error\n");
1022 jme_alloc_and_feed_skb(struct jme_adapter
*jme
, int idx
)
1024 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1025 struct rxdesc
*rxdesc
= rxring
->desc
;
1026 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
1027 struct sk_buff
*skb
;
1034 pci_dma_sync_single_for_cpu(jme
->pdev
,
1037 PCI_DMA_FROMDEVICE
);
1039 if (unlikely(jme_make_new_rx_buf(jme
, idx
))) {
1040 pci_dma_sync_single_for_device(jme
->pdev
,
1043 PCI_DMA_FROMDEVICE
);
1045 ++(NET_STAT(jme
).rx_dropped
);
1047 framesize
= le16_to_cpu(rxdesc
->descwb
.framesize
)
1050 skb_reserve(skb
, RX_PREPAD_SIZE
);
1051 skb_put(skb
, framesize
);
1052 skb
->protocol
= eth_type_trans(skb
, jme
->dev
);
1054 if (jme_rxsum_ok(jme
, le16_to_cpu(rxdesc
->descwb
.flags
), skb
))
1055 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1057 skb_checksum_none_assert(skb
);
1059 if (rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_TAGON
)) {
1060 u16 vid
= le16_to_cpu(rxdesc
->descwb
.vlan
);
1062 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
1063 NET_STAT(jme
).rx_bytes
+= 4;
1067 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_DEST
)) ==
1068 cpu_to_le16(RXWBFLAG_DEST_MUL
))
1069 ++(NET_STAT(jme
).multicast
);
1071 NET_STAT(jme
).rx_bytes
+= framesize
;
1072 ++(NET_STAT(jme
).rx_packets
);
1075 jme_set_clean_rxdesc(jme
, idx
);
1080 jme_process_receive(struct jme_adapter
*jme
, int limit
)
1082 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1083 struct rxdesc
*rxdesc
= rxring
->desc
;
1084 int i
, j
, ccnt
, desccnt
, mask
= jme
->rx_ring_mask
;
1086 if (unlikely(!atomic_dec_and_test(&jme
->rx_cleaning
)))
1089 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1092 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1095 i
= atomic_read(&rxring
->next_to_clean
);
1097 rxdesc
= rxring
->desc
;
1100 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_OWN
)) ||
1101 !(rxdesc
->descwb
.desccnt
& RXWBDCNT_WBCPL
))
1106 desccnt
= rxdesc
->descwb
.desccnt
& RXWBDCNT_DCNT
;
1108 if (unlikely(desccnt
> 1 ||
1109 rxdesc
->descwb
.errstat
& RXWBERR_ALLERR
)) {
1111 if (rxdesc
->descwb
.errstat
& RXWBERR_CRCERR
)
1112 ++(NET_STAT(jme
).rx_crc_errors
);
1113 else if (rxdesc
->descwb
.errstat
& RXWBERR_OVERUN
)
1114 ++(NET_STAT(jme
).rx_fifo_errors
);
1116 ++(NET_STAT(jme
).rx_errors
);
1119 limit
-= desccnt
- 1;
1121 for (j
= i
, ccnt
= desccnt
; ccnt
-- ; ) {
1122 jme_set_clean_rxdesc(jme
, j
);
1123 j
= (j
+ 1) & (mask
);
1127 jme_alloc_and_feed_skb(jme
, i
);
1130 i
= (i
+ desccnt
) & (mask
);
1134 atomic_set(&rxring
->next_to_clean
, i
);
1137 atomic_inc(&jme
->rx_cleaning
);
1139 return limit
> 0 ? limit
: 0;
1144 jme_attempt_pcc(struct dynpcc_info
*dpi
, int atmp
)
1146 if (likely(atmp
== dpi
->cur
)) {
1151 if (dpi
->attempt
== atmp
) {
1154 dpi
->attempt
= atmp
;
1161 jme_dynamic_pcc(struct jme_adapter
*jme
)
1163 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
1165 if ((NET_STAT(jme
).rx_bytes
- dpi
->last_bytes
) > PCC_P3_THRESHOLD
)
1166 jme_attempt_pcc(dpi
, PCC_P3
);
1167 else if ((NET_STAT(jme
).rx_packets
- dpi
->last_pkts
) > PCC_P2_THRESHOLD
||
1168 dpi
->intr_cnt
> PCC_INTR_THRESHOLD
)
1169 jme_attempt_pcc(dpi
, PCC_P2
);
1171 jme_attempt_pcc(dpi
, PCC_P1
);
1173 if (unlikely(dpi
->attempt
!= dpi
->cur
&& dpi
->cnt
> 5)) {
1174 if (dpi
->attempt
< dpi
->cur
)
1175 tasklet_schedule(&jme
->rxclean_task
);
1176 jme_set_rx_pcc(jme
, dpi
->attempt
);
1177 dpi
->cur
= dpi
->attempt
;
1183 jme_start_pcc_timer(struct jme_adapter
*jme
)
1185 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1186 dpi
->last_bytes
= NET_STAT(jme
).rx_bytes
;
1187 dpi
->last_pkts
= NET_STAT(jme
).rx_packets
;
1189 jwrite32(jme
, JME_TMCSR
,
1190 TMCSR_EN
| ((0xFFFFFF - PCC_INTERVAL_US
) & TMCSR_CNT
));
1194 jme_stop_pcc_timer(struct jme_adapter
*jme
)
1196 jwrite32(jme
, JME_TMCSR
, 0);
1200 jme_shutdown_nic(struct jme_adapter
*jme
)
1204 phylink
= jme_linkstat_from_phy(jme
);
1206 if (!(phylink
& PHY_LINK_UP
)) {
1208 * Disable all interrupt before issue timer
1211 jwrite32(jme
, JME_TIMER2
, TMCSR_EN
| 0xFFFFFE);
1216 jme_pcc_tasklet(unsigned long arg
)
1218 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1219 struct net_device
*netdev
= jme
->dev
;
1221 if (unlikely(test_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
))) {
1222 jme_shutdown_nic(jme
);
1226 if (unlikely(!netif_carrier_ok(netdev
) ||
1227 (atomic_read(&jme
->link_changing
) != 1)
1229 jme_stop_pcc_timer(jme
);
1233 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
1234 jme_dynamic_pcc(jme
);
1236 jme_start_pcc_timer(jme
);
1240 jme_polling_mode(struct jme_adapter
*jme
)
1242 jme_set_rx_pcc(jme
, PCC_OFF
);
1246 jme_interrupt_mode(struct jme_adapter
*jme
)
1248 jme_set_rx_pcc(jme
, PCC_P1
);
1252 jme_pseudo_hotplug_enabled(struct jme_adapter
*jme
)
1255 apmc
= jread32(jme
, JME_APMC
);
1256 return apmc
& JME_APMC_PSEUDO_HP_EN
;
1260 jme_start_shutdown_timer(struct jme_adapter
*jme
)
1264 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PCIE_SD_EN
;
1265 apmc
&= ~JME_APMC_EPIEN_CTRL
;
1267 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_EN
);
1270 jwrite32f(jme
, JME_APMC
, apmc
);
1272 jwrite32f(jme
, JME_TIMER2
, 0);
1273 set_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1274 jwrite32(jme
, JME_TMCSR
,
1275 TMCSR_EN
| ((0xFFFFFF - APMC_PHP_SHUTDOWN_DELAY
) & TMCSR_CNT
));
1279 jme_stop_shutdown_timer(struct jme_adapter
*jme
)
1283 jwrite32f(jme
, JME_TMCSR
, 0);
1284 jwrite32f(jme
, JME_TIMER2
, 0);
1285 clear_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1287 apmc
= jread32(jme
, JME_APMC
);
1288 apmc
&= ~(JME_APMC_PCIE_SD_EN
| JME_APMC_EPIEN_CTRL
);
1289 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_DIS
);
1291 jwrite32f(jme
, JME_APMC
, apmc
);
1295 jme_link_change_tasklet(unsigned long arg
)
1297 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1298 struct net_device
*netdev
= jme
->dev
;
1301 while (!atomic_dec_and_test(&jme
->link_changing
)) {
1302 atomic_inc(&jme
->link_changing
);
1303 netif_info(jme
, intr
, jme
->dev
, "Get link change lock failed\n");
1304 while (atomic_read(&jme
->link_changing
) != 1)
1305 netif_info(jme
, intr
, jme
->dev
, "Waiting link change lock\n");
1308 if (jme_check_link(netdev
, 1) && jme
->old_mtu
== netdev
->mtu
)
1311 jme
->old_mtu
= netdev
->mtu
;
1312 netif_stop_queue(netdev
);
1313 if (jme_pseudo_hotplug_enabled(jme
))
1314 jme_stop_shutdown_timer(jme
);
1316 jme_stop_pcc_timer(jme
);
1317 tasklet_disable(&jme
->txclean_task
);
1318 tasklet_disable(&jme
->rxclean_task
);
1319 tasklet_disable(&jme
->rxempty_task
);
1321 if (netif_carrier_ok(netdev
)) {
1322 jme_disable_rx_engine(jme
);
1323 jme_disable_tx_engine(jme
);
1324 jme_reset_mac_processor(jme
);
1325 jme_free_rx_resources(jme
);
1326 jme_free_tx_resources(jme
);
1328 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1329 jme_polling_mode(jme
);
1331 netif_carrier_off(netdev
);
1334 jme_check_link(netdev
, 0);
1335 if (netif_carrier_ok(netdev
)) {
1336 rc
= jme_setup_rx_resources(jme
);
1338 pr_err("Allocating resources for RX error, Device STOPPED!\n");
1339 goto out_enable_tasklet
;
1342 rc
= jme_setup_tx_resources(jme
);
1344 pr_err("Allocating resources for TX error, Device STOPPED!\n");
1345 goto err_out_free_rx_resources
;
1348 jme_enable_rx_engine(jme
);
1349 jme_enable_tx_engine(jme
);
1351 netif_start_queue(netdev
);
1353 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1354 jme_interrupt_mode(jme
);
1356 jme_start_pcc_timer(jme
);
1357 } else if (jme_pseudo_hotplug_enabled(jme
)) {
1358 jme_start_shutdown_timer(jme
);
1361 goto out_enable_tasklet
;
1363 err_out_free_rx_resources
:
1364 jme_free_rx_resources(jme
);
1366 tasklet_enable(&jme
->txclean_task
);
1367 tasklet_enable(&jme
->rxclean_task
);
1368 tasklet_enable(&jme
->rxempty_task
);
1370 atomic_inc(&jme
->link_changing
);
1374 jme_rx_clean_tasklet(unsigned long arg
)
1376 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1377 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1379 jme_process_receive(jme
, jme
->rx_ring_size
);
1385 jme_poll(JME_NAPI_HOLDER(holder
), JME_NAPI_WEIGHT(budget
))
1387 struct jme_adapter
*jme
= jme_napi_priv(holder
);
1390 rest
= jme_process_receive(jme
, JME_NAPI_WEIGHT_VAL(budget
));
1392 while (atomic_read(&jme
->rx_empty
) > 0) {
1393 atomic_dec(&jme
->rx_empty
);
1394 ++(NET_STAT(jme
).rx_dropped
);
1395 jme_restart_rx_engine(jme
);
1397 atomic_inc(&jme
->rx_empty
);
1400 JME_RX_COMPLETE(netdev
, holder
);
1401 jme_interrupt_mode(jme
);
1404 JME_NAPI_WEIGHT_SET(budget
, rest
);
1405 return JME_NAPI_WEIGHT_VAL(budget
) - rest
;
1409 jme_rx_empty_tasklet(unsigned long arg
)
1411 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1413 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1416 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1419 netif_info(jme
, rx_status
, jme
->dev
, "RX Queue Full!\n");
1421 jme_rx_clean_tasklet(arg
);
1423 while (atomic_read(&jme
->rx_empty
) > 0) {
1424 atomic_dec(&jme
->rx_empty
);
1425 ++(NET_STAT(jme
).rx_dropped
);
1426 jme_restart_rx_engine(jme
);
1428 atomic_inc(&jme
->rx_empty
);
1432 jme_wake_queue_if_stopped(struct jme_adapter
*jme
)
1434 struct jme_ring
*txring
= &(jme
->txring
[0]);
1437 if (unlikely(netif_queue_stopped(jme
->dev
) &&
1438 atomic_read(&txring
->nr_free
) >= (jme
->tx_wake_threshold
))) {
1439 netif_info(jme
, tx_done
, jme
->dev
, "TX Queue Waked\n");
1440 netif_wake_queue(jme
->dev
);
1446 jme_tx_clean_tasklet(unsigned long arg
)
1448 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1449 struct jme_ring
*txring
= &(jme
->txring
[0]);
1450 struct txdesc
*txdesc
= txring
->desc
;
1451 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
, *ttxbi
;
1452 int i
, j
, cnt
= 0, max
, err
, mask
;
1454 tx_dbg(jme
, "Into txclean\n");
1456 if (unlikely(!atomic_dec_and_test(&jme
->tx_cleaning
)))
1459 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1462 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1465 max
= jme
->tx_ring_size
- atomic_read(&txring
->nr_free
);
1466 mask
= jme
->tx_ring_mask
;
1468 for (i
= atomic_read(&txring
->next_to_clean
) ; cnt
< max
; ) {
1472 if (likely(ctxbi
->skb
&&
1473 !(txdesc
[i
].descwb
.flags
& TXWBFLAG_OWN
))) {
1475 tx_dbg(jme
, "txclean: %d+%d@%lu\n",
1476 i
, ctxbi
->nr_desc
, jiffies
);
1478 err
= txdesc
[i
].descwb
.flags
& TXWBFLAG_ALLERR
;
1480 for (j
= 1 ; j
< ctxbi
->nr_desc
; ++j
) {
1481 ttxbi
= txbi
+ ((i
+ j
) & (mask
));
1482 txdesc
[(i
+ j
) & (mask
)].dw
[0] = 0;
1484 pci_unmap_page(jme
->pdev
,
1493 dev_kfree_skb(ctxbi
->skb
);
1495 cnt
+= ctxbi
->nr_desc
;
1497 if (unlikely(err
)) {
1498 ++(NET_STAT(jme
).tx_carrier_errors
);
1500 ++(NET_STAT(jme
).tx_packets
);
1501 NET_STAT(jme
).tx_bytes
+= ctxbi
->len
;
1506 ctxbi
->start_xmit
= 0;
1512 i
= (i
+ ctxbi
->nr_desc
) & mask
;
1517 tx_dbg(jme
, "txclean: done %d@%lu\n", i
, jiffies
);
1518 atomic_set(&txring
->next_to_clean
, i
);
1519 atomic_add(cnt
, &txring
->nr_free
);
1521 jme_wake_queue_if_stopped(jme
);
1524 atomic_inc(&jme
->tx_cleaning
);
1528 jme_intr_msi(struct jme_adapter
*jme
, u32 intrstat
)
1533 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
1535 if (intrstat
& (INTR_LINKCH
| INTR_SWINTR
)) {
1537 * Link change event is critical
1538 * all other events are ignored
1540 jwrite32(jme
, JME_IEVE
, intrstat
);
1541 tasklet_schedule(&jme
->linkch_task
);
1545 if (intrstat
& INTR_TMINTR
) {
1546 jwrite32(jme
, JME_IEVE
, INTR_TMINTR
);
1547 tasklet_schedule(&jme
->pcc_task
);
1550 if (intrstat
& (INTR_PCCTXTO
| INTR_PCCTX
)) {
1551 jwrite32(jme
, JME_IEVE
, INTR_PCCTXTO
| INTR_PCCTX
| INTR_TX0
);
1552 tasklet_schedule(&jme
->txclean_task
);
1555 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1556 jwrite32(jme
, JME_IEVE
, (intrstat
& (INTR_PCCRX0TO
|
1562 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
1563 if (intrstat
& INTR_RX0EMP
)
1564 atomic_inc(&jme
->rx_empty
);
1566 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1567 if (likely(JME_RX_SCHEDULE_PREP(jme
))) {
1568 jme_polling_mode(jme
);
1569 JME_RX_SCHEDULE(jme
);
1573 if (intrstat
& INTR_RX0EMP
) {
1574 atomic_inc(&jme
->rx_empty
);
1575 tasklet_hi_schedule(&jme
->rxempty_task
);
1576 } else if (intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
)) {
1577 tasklet_hi_schedule(&jme
->rxclean_task
);
1583 * Re-enable interrupt
1585 jwrite32f(jme
, JME_IENS
, INTR_ENABLE
);
1589 jme_intr(int irq
, void *dev_id
)
1591 struct net_device
*netdev
= dev_id
;
1592 struct jme_adapter
*jme
= netdev_priv(netdev
);
1595 intrstat
= jread32(jme
, JME_IEVE
);
1598 * Check if it's really an interrupt for us
1600 if (unlikely((intrstat
& INTR_ENABLE
) == 0))
1604 * Check if the device still exist
1606 if (unlikely(intrstat
== ~((typeof(intrstat
))0)))
1609 jme_intr_msi(jme
, intrstat
);
1615 jme_msi(int irq
, void *dev_id
)
1617 struct net_device
*netdev
= dev_id
;
1618 struct jme_adapter
*jme
= netdev_priv(netdev
);
1621 intrstat
= jread32(jme
, JME_IEVE
);
1623 jme_intr_msi(jme
, intrstat
);
1629 jme_reset_link(struct jme_adapter
*jme
)
1631 jwrite32(jme
, JME_TMCSR
, TMCSR_SWIT
);
1635 jme_restart_an(struct jme_adapter
*jme
)
1639 spin_lock_bh(&jme
->phy_lock
);
1640 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1641 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1642 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1643 spin_unlock_bh(&jme
->phy_lock
);
1647 jme_request_irq(struct jme_adapter
*jme
)
1650 struct net_device
*netdev
= jme
->dev
;
1651 irq_handler_t handler
= jme_intr
;
1652 int irq_flags
= IRQF_SHARED
;
1654 if (!pci_enable_msi(jme
->pdev
)) {
1655 set_bit(JME_FLAG_MSI
, &jme
->flags
);
1660 rc
= request_irq(jme
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
1664 "Unable to request %s interrupt (return: %d)\n",
1665 test_bit(JME_FLAG_MSI
, &jme
->flags
) ? "MSI" : "INTx",
1668 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1669 pci_disable_msi(jme
->pdev
);
1670 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1673 netdev
->irq
= jme
->pdev
->irq
;
1680 jme_free_irq(struct jme_adapter
*jme
)
1682 free_irq(jme
->pdev
->irq
, jme
->dev
);
1683 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1684 pci_disable_msi(jme
->pdev
);
1685 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1686 jme
->dev
->irq
= jme
->pdev
->irq
;
1691 jme_new_phy_on(struct jme_adapter
*jme
)
1695 reg
= jread32(jme
, JME_PHY_PWR
);
1696 reg
&= ~(PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1697 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
);
1698 jwrite32(jme
, JME_PHY_PWR
, reg
);
1700 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1701 reg
&= ~PE1_GPREG0_PBG
;
1702 reg
|= PE1_GPREG0_ENBG
;
1703 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1707 jme_new_phy_off(struct jme_adapter
*jme
)
1711 reg
= jread32(jme
, JME_PHY_PWR
);
1712 reg
|= PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1713 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
;
1714 jwrite32(jme
, JME_PHY_PWR
, reg
);
1716 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1717 reg
&= ~PE1_GPREG0_PBG
;
1718 reg
|= PE1_GPREG0_PDD3COLD
;
1719 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1723 jme_phy_on(struct jme_adapter
*jme
)
1727 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1728 bmcr
&= ~BMCR_PDOWN
;
1729 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1731 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1732 jme_new_phy_on(jme
);
1736 jme_phy_off(struct jme_adapter
*jme
)
1740 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1742 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1744 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1745 jme_new_phy_off(jme
);
1749 jme_phy_specreg_read(struct jme_adapter
*jme
, u32 specreg
)
1753 phy_addr
= JM_PHY_SPEC_REG_READ
| specreg
;
1754 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_ADDR_REG
,
1756 return jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
,
1757 JM_PHY_SPEC_DATA_REG
);
1761 jme_phy_specreg_write(struct jme_adapter
*jme
, u32 ext_reg
, u32 phy_data
)
1765 phy_addr
= JM_PHY_SPEC_REG_WRITE
| ext_reg
;
1766 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_DATA_REG
,
1768 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_ADDR_REG
,
1773 jme_phy_calibration(struct jme_adapter
*jme
)
1775 u32 ctrl1000
, phy_data
;
1779 /* Enabel PHY test mode 1 */
1780 ctrl1000
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
);
1781 ctrl1000
&= ~PHY_GAD_TEST_MODE_MSK
;
1782 ctrl1000
|= PHY_GAD_TEST_MODE_1
;
1783 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
, ctrl1000
);
1785 phy_data
= jme_phy_specreg_read(jme
, JM_PHY_EXT_COMM_2_REG
);
1786 phy_data
&= ~JM_PHY_EXT_COMM_2_CALI_MODE_0
;
1787 phy_data
|= JM_PHY_EXT_COMM_2_CALI_LATCH
|
1788 JM_PHY_EXT_COMM_2_CALI_ENABLE
;
1789 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_2_REG
, phy_data
);
1791 phy_data
= jme_phy_specreg_read(jme
, JM_PHY_EXT_COMM_2_REG
);
1792 phy_data
&= ~(JM_PHY_EXT_COMM_2_CALI_ENABLE
|
1793 JM_PHY_EXT_COMM_2_CALI_MODE_0
|
1794 JM_PHY_EXT_COMM_2_CALI_LATCH
);
1795 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_2_REG
, phy_data
);
1797 /* Disable PHY test mode */
1798 ctrl1000
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
);
1799 ctrl1000
&= ~PHY_GAD_TEST_MODE_MSK
;
1800 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
, ctrl1000
);
1805 jme_phy_setEA(struct jme_adapter
*jme
)
1807 u32 phy_comm0
= 0, phy_comm1
= 0;
1810 pci_read_config_byte(jme
->pdev
, PCI_PRIV_SHARE_NICCTRL
, &nic_ctrl
);
1811 if ((nic_ctrl
& 0x3) == JME_FLAG_PHYEA_ENABLE
)
1814 switch (jme
->pdev
->device
) {
1815 case PCI_DEVICE_ID_JMICRON_JMC250
:
1816 if (((jme
->chip_main_rev
== 5) &&
1817 ((jme
->chip_sub_rev
== 0) || (jme
->chip_sub_rev
== 1) ||
1818 (jme
->chip_sub_rev
== 3))) ||
1819 (jme
->chip_main_rev
>= 6)) {
1823 if ((jme
->chip_main_rev
== 3) &&
1824 ((jme
->chip_sub_rev
== 1) || (jme
->chip_sub_rev
== 2)))
1827 case PCI_DEVICE_ID_JMICRON_JMC260
:
1828 if (((jme
->chip_main_rev
== 5) &&
1829 ((jme
->chip_sub_rev
== 0) || (jme
->chip_sub_rev
== 1) ||
1830 (jme
->chip_sub_rev
== 3))) ||
1831 (jme
->chip_main_rev
>= 6)) {
1835 if ((jme
->chip_main_rev
== 3) &&
1836 ((jme
->chip_sub_rev
== 1) || (jme
->chip_sub_rev
== 2)))
1838 if ((jme
->chip_main_rev
== 2) && (jme
->chip_sub_rev
== 0))
1840 if ((jme
->chip_main_rev
== 2) && (jme
->chip_sub_rev
== 2))
1847 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_0_REG
, phy_comm0
);
1849 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_1_REG
, phy_comm1
);
1855 jme_open(struct net_device
*netdev
)
1857 struct jme_adapter
*jme
= netdev_priv(netdev
);
1861 JME_NAPI_ENABLE(jme
);
1863 tasklet_init(&jme
->linkch_task
, jme_link_change_tasklet
,
1864 (unsigned long) jme
);
1865 tasklet_init(&jme
->txclean_task
, jme_tx_clean_tasklet
,
1866 (unsigned long) jme
);
1867 tasklet_init(&jme
->rxclean_task
, jme_rx_clean_tasklet
,
1868 (unsigned long) jme
);
1869 tasklet_init(&jme
->rxempty_task
, jme_rx_empty_tasklet
,
1870 (unsigned long) jme
);
1872 rc
= jme_request_irq(jme
);
1879 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
1880 jme_set_settings(netdev
, &jme
->old_ecmd
);
1882 jme_reset_phy_processor(jme
);
1883 jme_phy_calibration(jme
);
1885 jme_reset_link(jme
);
1890 netif_stop_queue(netdev
);
1891 netif_carrier_off(netdev
);
1896 jme_set_100m_half(struct jme_adapter
*jme
)
1901 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1902 tmp
= bmcr
& ~(BMCR_ANENABLE
| BMCR_SPEED100
|
1903 BMCR_SPEED1000
| BMCR_FULLDPLX
);
1904 tmp
|= BMCR_SPEED100
;
1907 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, tmp
);
1910 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
| GHC_LINK_POLL
);
1912 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
);
1915 #define JME_WAIT_LINK_TIME 2000 /* 2000ms */
1917 jme_wait_link(struct jme_adapter
*jme
)
1919 u32 phylink
, to
= JME_WAIT_LINK_TIME
;
1922 phylink
= jme_linkstat_from_phy(jme
);
1923 while (!(phylink
& PHY_LINK_UP
) && (to
-= 10) > 0) {
1925 phylink
= jme_linkstat_from_phy(jme
);
1930 jme_powersave_phy(struct jme_adapter
*jme
)
1932 if (jme
->reg_pmcs
) {
1933 jme_set_100m_half(jme
);
1934 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
1943 jme_close(struct net_device
*netdev
)
1945 struct jme_adapter
*jme
= netdev_priv(netdev
);
1947 netif_stop_queue(netdev
);
1948 netif_carrier_off(netdev
);
1953 JME_NAPI_DISABLE(jme
);
1955 tasklet_kill(&jme
->linkch_task
);
1956 tasklet_kill(&jme
->txclean_task
);
1957 tasklet_kill(&jme
->rxclean_task
);
1958 tasklet_kill(&jme
->rxempty_task
);
1960 jme_disable_rx_engine(jme
);
1961 jme_disable_tx_engine(jme
);
1962 jme_reset_mac_processor(jme
);
1963 jme_free_rx_resources(jme
);
1964 jme_free_tx_resources(jme
);
1972 jme_alloc_txdesc(struct jme_adapter
*jme
,
1973 struct sk_buff
*skb
)
1975 struct jme_ring
*txring
= &(jme
->txring
[0]);
1976 int idx
, nr_alloc
, mask
= jme
->tx_ring_mask
;
1978 idx
= txring
->next_to_use
;
1979 nr_alloc
= skb_shinfo(skb
)->nr_frags
+ 2;
1981 if (unlikely(atomic_read(&txring
->nr_free
) < nr_alloc
))
1984 atomic_sub(nr_alloc
, &txring
->nr_free
);
1986 txring
->next_to_use
= (txring
->next_to_use
+ nr_alloc
) & mask
;
1992 jme_fill_tx_map(struct pci_dev
*pdev
,
1993 struct txdesc
*txdesc
,
1994 struct jme_buffer_info
*txbi
,
2002 dmaaddr
= pci_map_page(pdev
,
2008 if (unlikely(pci_dma_mapping_error(pdev
, dmaaddr
)))
2011 pci_dma_sync_single_for_device(pdev
,
2018 txdesc
->desc2
.flags
= TXFLAG_OWN
;
2019 txdesc
->desc2
.flags
|= (hidma
) ? TXFLAG_64BIT
: 0;
2020 txdesc
->desc2
.datalen
= cpu_to_le16(len
);
2021 txdesc
->desc2
.bufaddrh
= cpu_to_le32((__u64
)dmaaddr
>> 32);
2022 txdesc
->desc2
.bufaddrl
= cpu_to_le32(
2023 (__u64
)dmaaddr
& 0xFFFFFFFFUL
);
2025 txbi
->mapping
= dmaaddr
;
2030 static void jme_drop_tx_map(struct jme_adapter
*jme
, int startidx
, int count
)
2032 struct jme_ring
*txring
= &(jme
->txring
[0]);
2033 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
;
2034 int mask
= jme
->tx_ring_mask
;
2037 for (j
= 0 ; j
< count
; j
++) {
2038 ctxbi
= txbi
+ ((startidx
+ j
+ 2) & (mask
));
2039 pci_unmap_page(jme
->pdev
,
2051 jme_map_tx_skb(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
2053 struct jme_ring
*txring
= &(jme
->txring
[0]);
2054 struct txdesc
*txdesc
= txring
->desc
, *ctxdesc
;
2055 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
;
2056 bool hidma
= jme
->dev
->features
& NETIF_F_HIGHDMA
;
2057 int i
, nr_frags
= skb_shinfo(skb
)->nr_frags
;
2058 int mask
= jme
->tx_ring_mask
;
2059 const struct skb_frag_struct
*frag
;
2063 for (i
= 0 ; i
< nr_frags
; ++i
) {
2064 frag
= &skb_shinfo(skb
)->frags
[i
];
2065 ctxdesc
= txdesc
+ ((idx
+ i
+ 2) & (mask
));
2066 ctxbi
= txbi
+ ((idx
+ i
+ 2) & (mask
));
2068 ret
= jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
,
2069 skb_frag_page(frag
),
2070 frag
->page_offset
, skb_frag_size(frag
), hidma
);
2072 jme_drop_tx_map(jme
, idx
, i
);
2078 len
= skb_is_nonlinear(skb
) ? skb_headlen(skb
) : skb
->len
;
2079 ctxdesc
= txdesc
+ ((idx
+ 1) & (mask
));
2080 ctxbi
= txbi
+ ((idx
+ 1) & (mask
));
2081 ret
= jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
, virt_to_page(skb
->data
),
2082 offset_in_page(skb
->data
), len
, hidma
);
2084 jme_drop_tx_map(jme
, idx
, i
);
2093 jme_tx_tso(struct sk_buff
*skb
, __le16
*mss
, u8
*flags
)
2095 *mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
<< TXDESC_MSS_SHIFT
);
2097 *flags
|= TXFLAG_LSEN
;
2099 if (skb
->protocol
== htons(ETH_P_IP
)) {
2100 struct iphdr
*iph
= ip_hdr(skb
);
2103 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2108 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2110 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ip6h
->saddr
,
2123 jme_tx_csum(struct jme_adapter
*jme
, struct sk_buff
*skb
, u8
*flags
)
2125 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2128 switch (skb
->protocol
) {
2129 case htons(ETH_P_IP
):
2130 ip_proto
= ip_hdr(skb
)->protocol
;
2132 case htons(ETH_P_IPV6
):
2133 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
2142 *flags
|= TXFLAG_TCPCS
;
2145 *flags
|= TXFLAG_UDPCS
;
2148 netif_err(jme
, tx_err
, jme
->dev
, "Error upper layer protocol\n");
2155 jme_tx_vlan(struct sk_buff
*skb
, __le16
*vlan
, u8
*flags
)
2157 if (skb_vlan_tag_present(skb
)) {
2158 *flags
|= TXFLAG_TAGON
;
2159 *vlan
= cpu_to_le16(skb_vlan_tag_get(skb
));
2164 jme_fill_tx_desc(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
2166 struct jme_ring
*txring
= &(jme
->txring
[0]);
2167 struct txdesc
*txdesc
;
2168 struct jme_buffer_info
*txbi
;
2172 txdesc
= (struct txdesc
*)txring
->desc
+ idx
;
2173 txbi
= txring
->bufinf
+ idx
;
2179 txdesc
->desc1
.pktsize
= cpu_to_le16(skb
->len
);
2181 * Set OWN bit at final.
2182 * When kernel transmit faster than NIC.
2183 * And NIC trying to send this descriptor before we tell
2184 * it to start sending this TX queue.
2185 * Other fields are already filled correctly.
2188 flags
= TXFLAG_OWN
| TXFLAG_INT
;
2190 * Set checksum flags while not tso
2192 if (jme_tx_tso(skb
, &txdesc
->desc1
.mss
, &flags
))
2193 jme_tx_csum(jme
, skb
, &flags
);
2194 jme_tx_vlan(skb
, &txdesc
->desc1
.vlan
, &flags
);
2195 ret
= jme_map_tx_skb(jme
, skb
, idx
);
2199 txdesc
->desc1
.flags
= flags
;
2201 * Set tx buffer info after telling NIC to send
2202 * For better tx_clean timing
2205 txbi
->nr_desc
= skb_shinfo(skb
)->nr_frags
+ 2;
2207 txbi
->len
= skb
->len
;
2208 txbi
->start_xmit
= jiffies
;
2209 if (!txbi
->start_xmit
)
2210 txbi
->start_xmit
= (0UL-1);
2216 jme_stop_queue_if_full(struct jme_adapter
*jme
)
2218 struct jme_ring
*txring
= &(jme
->txring
[0]);
2219 struct jme_buffer_info
*txbi
= txring
->bufinf
;
2220 int idx
= atomic_read(&txring
->next_to_clean
);
2225 if (unlikely(atomic_read(&txring
->nr_free
) < (MAX_SKB_FRAGS
+2))) {
2226 netif_stop_queue(jme
->dev
);
2227 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Paused\n");
2229 if (atomic_read(&txring
->nr_free
)
2230 >= (jme
->tx_wake_threshold
)) {
2231 netif_wake_queue(jme
->dev
);
2232 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Fast Waked\n");
2236 if (unlikely(txbi
->start_xmit
&&
2237 (jiffies
- txbi
->start_xmit
) >= TX_TIMEOUT
&&
2239 netif_stop_queue(jme
->dev
);
2240 netif_info(jme
, tx_queued
, jme
->dev
,
2241 "TX Queue Stopped %d@%lu\n", idx
, jiffies
);
2246 * This function is already protected by netif_tx_lock()
2250 jme_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
2252 struct jme_adapter
*jme
= netdev_priv(netdev
);
2255 if (unlikely(skb_is_gso(skb
) && skb_cow_head(skb
, 0))) {
2256 dev_kfree_skb_any(skb
);
2257 ++(NET_STAT(jme
).tx_dropped
);
2258 return NETDEV_TX_OK
;
2261 idx
= jme_alloc_txdesc(jme
, skb
);
2263 if (unlikely(idx
< 0)) {
2264 netif_stop_queue(netdev
);
2265 netif_err(jme
, tx_err
, jme
->dev
,
2266 "BUG! Tx ring full when queue awake!\n");
2268 return NETDEV_TX_BUSY
;
2271 if (jme_fill_tx_desc(jme
, skb
, idx
))
2272 return NETDEV_TX_OK
;
2274 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
2275 TXCS_SELECT_QUEUE0
|
2279 tx_dbg(jme
, "xmit: %d+%d@%lu\n",
2280 idx
, skb_shinfo(skb
)->nr_frags
+ 2, jiffies
);
2281 jme_stop_queue_if_full(jme
);
2283 return NETDEV_TX_OK
;
2287 jme_set_unicastaddr(struct net_device
*netdev
)
2289 struct jme_adapter
*jme
= netdev_priv(netdev
);
2292 val
= (netdev
->dev_addr
[3] & 0xff) << 24 |
2293 (netdev
->dev_addr
[2] & 0xff) << 16 |
2294 (netdev
->dev_addr
[1] & 0xff) << 8 |
2295 (netdev
->dev_addr
[0] & 0xff);
2296 jwrite32(jme
, JME_RXUMA_LO
, val
);
2297 val
= (netdev
->dev_addr
[5] & 0xff) << 8 |
2298 (netdev
->dev_addr
[4] & 0xff);
2299 jwrite32(jme
, JME_RXUMA_HI
, val
);
2303 jme_set_macaddr(struct net_device
*netdev
, void *p
)
2305 struct jme_adapter
*jme
= netdev_priv(netdev
);
2306 struct sockaddr
*addr
= p
;
2308 if (netif_running(netdev
))
2311 spin_lock_bh(&jme
->macaddr_lock
);
2312 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2313 jme_set_unicastaddr(netdev
);
2314 spin_unlock_bh(&jme
->macaddr_lock
);
2320 jme_set_multi(struct net_device
*netdev
)
2322 struct jme_adapter
*jme
= netdev_priv(netdev
);
2323 u32 mc_hash
[2] = {};
2325 spin_lock_bh(&jme
->rxmcs_lock
);
2327 jme
->reg_rxmcs
|= RXMCS_BRDFRAME
| RXMCS_UNIFRAME
;
2329 if (netdev
->flags
& IFF_PROMISC
) {
2330 jme
->reg_rxmcs
|= RXMCS_ALLFRAME
;
2331 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2332 jme
->reg_rxmcs
|= RXMCS_ALLMULFRAME
;
2333 } else if (netdev
->flags
& IFF_MULTICAST
) {
2334 struct netdev_hw_addr
*ha
;
2337 jme
->reg_rxmcs
|= RXMCS_MULFRAME
| RXMCS_MULFILTERED
;
2338 netdev_for_each_mc_addr(ha
, netdev
) {
2339 bit_nr
= ether_crc(ETH_ALEN
, ha
->addr
) & 0x3F;
2340 mc_hash
[bit_nr
>> 5] |= 1 << (bit_nr
& 0x1F);
2343 jwrite32(jme
, JME_RXMCHT_LO
, mc_hash
[0]);
2344 jwrite32(jme
, JME_RXMCHT_HI
, mc_hash
[1]);
2348 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2350 spin_unlock_bh(&jme
->rxmcs_lock
);
2354 jme_change_mtu(struct net_device
*netdev
, int new_mtu
)
2356 struct jme_adapter
*jme
= netdev_priv(netdev
);
2358 if (new_mtu
== jme
->old_mtu
)
2361 if (((new_mtu
+ ETH_HLEN
) > MAX_ETHERNET_JUMBO_PACKET_SIZE
) ||
2362 ((new_mtu
) < IPV6_MIN_MTU
))
2366 netdev
->mtu
= new_mtu
;
2367 netdev_update_features(netdev
);
2369 jme_restart_rx_engine(jme
);
2370 jme_reset_link(jme
);
2376 jme_tx_timeout(struct net_device
*netdev
)
2378 struct jme_adapter
*jme
= netdev_priv(netdev
);
2381 jme_reset_phy_processor(jme
);
2382 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
2383 jme_set_settings(netdev
, &jme
->old_ecmd
);
2386 * Force to Reset the link again
2388 jme_reset_link(jme
);
2391 static inline void jme_pause_rx(struct jme_adapter
*jme
)
2393 atomic_dec(&jme
->link_changing
);
2395 jme_set_rx_pcc(jme
, PCC_OFF
);
2396 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2397 JME_NAPI_DISABLE(jme
);
2399 tasklet_disable(&jme
->rxclean_task
);
2400 tasklet_disable(&jme
->rxempty_task
);
2404 static inline void jme_resume_rx(struct jme_adapter
*jme
)
2406 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2408 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2409 JME_NAPI_ENABLE(jme
);
2411 tasklet_enable(&jme
->rxclean_task
);
2412 tasklet_enable(&jme
->rxempty_task
);
2415 dpi
->attempt
= PCC_P1
;
2417 jme_set_rx_pcc(jme
, PCC_P1
);
2419 atomic_inc(&jme
->link_changing
);
2423 jme_get_drvinfo(struct net_device
*netdev
,
2424 struct ethtool_drvinfo
*info
)
2426 struct jme_adapter
*jme
= netdev_priv(netdev
);
2428 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
2429 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
2430 strlcpy(info
->bus_info
, pci_name(jme
->pdev
), sizeof(info
->bus_info
));
2434 jme_get_regs_len(struct net_device
*netdev
)
2440 mmapio_memcpy(struct jme_adapter
*jme
, u32
*p
, u32 reg
, int len
)
2444 for (i
= 0 ; i
< len
; i
+= 4)
2445 p
[i
>> 2] = jread32(jme
, reg
+ i
);
2449 mdio_memcpy(struct jme_adapter
*jme
, u32
*p
, int reg_nr
)
2452 u16
*p16
= (u16
*)p
;
2454 for (i
= 0 ; i
< reg_nr
; ++i
)
2455 p16
[i
] = jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, i
);
2459 jme_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
2461 struct jme_adapter
*jme
= netdev_priv(netdev
);
2462 u32
*p32
= (u32
*)p
;
2464 memset(p
, 0xFF, JME_REG_LEN
);
2467 mmapio_memcpy(jme
, p32
, JME_MAC
, JME_MAC_LEN
);
2470 mmapio_memcpy(jme
, p32
, JME_PHY
, JME_PHY_LEN
);
2473 mmapio_memcpy(jme
, p32
, JME_MISC
, JME_MISC_LEN
);
2476 mmapio_memcpy(jme
, p32
, JME_RSS
, JME_RSS_LEN
);
2479 mdio_memcpy(jme
, p32
, JME_PHY_REG_NR
);
2483 jme_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2485 struct jme_adapter
*jme
= netdev_priv(netdev
);
2487 ecmd
->tx_coalesce_usecs
= PCC_TX_TO
;
2488 ecmd
->tx_max_coalesced_frames
= PCC_TX_CNT
;
2490 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2491 ecmd
->use_adaptive_rx_coalesce
= false;
2492 ecmd
->rx_coalesce_usecs
= 0;
2493 ecmd
->rx_max_coalesced_frames
= 0;
2497 ecmd
->use_adaptive_rx_coalesce
= true;
2499 switch (jme
->dpi
.cur
) {
2501 ecmd
->rx_coalesce_usecs
= PCC_P1_TO
;
2502 ecmd
->rx_max_coalesced_frames
= PCC_P1_CNT
;
2505 ecmd
->rx_coalesce_usecs
= PCC_P2_TO
;
2506 ecmd
->rx_max_coalesced_frames
= PCC_P2_CNT
;
2509 ecmd
->rx_coalesce_usecs
= PCC_P3_TO
;
2510 ecmd
->rx_max_coalesced_frames
= PCC_P3_CNT
;
2520 jme_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2522 struct jme_adapter
*jme
= netdev_priv(netdev
);
2523 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2525 if (netif_running(netdev
))
2528 if (ecmd
->use_adaptive_rx_coalesce
&&
2529 test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2530 clear_bit(JME_FLAG_POLL
, &jme
->flags
);
2531 jme
->jme_rx
= netif_rx
;
2533 dpi
->attempt
= PCC_P1
;
2535 jme_set_rx_pcc(jme
, PCC_P1
);
2536 jme_interrupt_mode(jme
);
2537 } else if (!(ecmd
->use_adaptive_rx_coalesce
) &&
2538 !(test_bit(JME_FLAG_POLL
, &jme
->flags
))) {
2539 set_bit(JME_FLAG_POLL
, &jme
->flags
);
2540 jme
->jme_rx
= netif_receive_skb
;
2541 jme_interrupt_mode(jme
);
2548 jme_get_pauseparam(struct net_device
*netdev
,
2549 struct ethtool_pauseparam
*ecmd
)
2551 struct jme_adapter
*jme
= netdev_priv(netdev
);
2554 ecmd
->tx_pause
= (jme
->reg_txpfc
& TXPFC_PF_EN
) != 0;
2555 ecmd
->rx_pause
= (jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0;
2557 spin_lock_bh(&jme
->phy_lock
);
2558 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2559 spin_unlock_bh(&jme
->phy_lock
);
2562 (val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0;
2566 jme_set_pauseparam(struct net_device
*netdev
,
2567 struct ethtool_pauseparam
*ecmd
)
2569 struct jme_adapter
*jme
= netdev_priv(netdev
);
2572 if (((jme
->reg_txpfc
& TXPFC_PF_EN
) != 0) ^
2573 (ecmd
->tx_pause
!= 0)) {
2576 jme
->reg_txpfc
|= TXPFC_PF_EN
;
2578 jme
->reg_txpfc
&= ~TXPFC_PF_EN
;
2580 jwrite32(jme
, JME_TXPFC
, jme
->reg_txpfc
);
2583 spin_lock_bh(&jme
->rxmcs_lock
);
2584 if (((jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0) ^
2585 (ecmd
->rx_pause
!= 0)) {
2588 jme
->reg_rxmcs
|= RXMCS_FLOWCTRL
;
2590 jme
->reg_rxmcs
&= ~RXMCS_FLOWCTRL
;
2592 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2594 spin_unlock_bh(&jme
->rxmcs_lock
);
2596 spin_lock_bh(&jme
->phy_lock
);
2597 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2598 if (((val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0) ^
2599 (ecmd
->autoneg
!= 0)) {
2602 val
|= (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2604 val
&= ~(ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2606 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
,
2607 MII_ADVERTISE
, val
);
2609 spin_unlock_bh(&jme
->phy_lock
);
2615 jme_get_wol(struct net_device
*netdev
,
2616 struct ethtool_wolinfo
*wol
)
2618 struct jme_adapter
*jme
= netdev_priv(netdev
);
2620 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
2624 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
2625 wol
->wolopts
|= WAKE_PHY
;
2627 if (jme
->reg_pmcs
& PMCS_MFEN
)
2628 wol
->wolopts
|= WAKE_MAGIC
;
2633 jme_set_wol(struct net_device
*netdev
,
2634 struct ethtool_wolinfo
*wol
)
2636 struct jme_adapter
*jme
= netdev_priv(netdev
);
2638 if (wol
->wolopts
& (WAKE_MAGICSECURE
|
2647 if (wol
->wolopts
& WAKE_PHY
)
2648 jme
->reg_pmcs
|= PMCS_LFEN
| PMCS_LREN
;
2650 if (wol
->wolopts
& WAKE_MAGIC
)
2651 jme
->reg_pmcs
|= PMCS_MFEN
;
2653 jwrite32(jme
, JME_PMCS
, jme
->reg_pmcs
);
2654 device_set_wakeup_enable(&jme
->pdev
->dev
, !!(jme
->reg_pmcs
));
2660 jme_get_settings(struct net_device
*netdev
,
2661 struct ethtool_cmd
*ecmd
)
2663 struct jme_adapter
*jme
= netdev_priv(netdev
);
2666 spin_lock_bh(&jme
->phy_lock
);
2667 rc
= mii_ethtool_gset(&(jme
->mii_if
), ecmd
);
2668 spin_unlock_bh(&jme
->phy_lock
);
2673 jme_set_settings(struct net_device
*netdev
,
2674 struct ethtool_cmd
*ecmd
)
2676 struct jme_adapter
*jme
= netdev_priv(netdev
);
2679 if (ethtool_cmd_speed(ecmd
) == SPEED_1000
2680 && ecmd
->autoneg
!= AUTONEG_ENABLE
)
2684 * Check If user changed duplex only while force_media.
2685 * Hardware would not generate link change interrupt.
2687 if (jme
->mii_if
.force_media
&&
2688 ecmd
->autoneg
!= AUTONEG_ENABLE
&&
2689 (jme
->mii_if
.full_duplex
!= ecmd
->duplex
))
2692 spin_lock_bh(&jme
->phy_lock
);
2693 rc
= mii_ethtool_sset(&(jme
->mii_if
), ecmd
);
2694 spin_unlock_bh(&jme
->phy_lock
);
2698 jme_reset_link(jme
);
2699 jme
->old_ecmd
= *ecmd
;
2700 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2707 jme_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
2710 struct jme_adapter
*jme
= netdev_priv(netdev
);
2711 struct mii_ioctl_data
*mii_data
= if_mii(rq
);
2712 unsigned int duplex_chg
;
2714 if (cmd
== SIOCSMIIREG
) {
2715 u16 val
= mii_data
->val_in
;
2716 if (!(val
& (BMCR_RESET
|BMCR_ANENABLE
)) &&
2717 (val
& BMCR_SPEED1000
))
2721 spin_lock_bh(&jme
->phy_lock
);
2722 rc
= generic_mii_ioctl(&jme
->mii_if
, mii_data
, cmd
, &duplex_chg
);
2723 spin_unlock_bh(&jme
->phy_lock
);
2725 if (!rc
&& (cmd
== SIOCSMIIREG
)) {
2727 jme_reset_link(jme
);
2728 jme_get_settings(netdev
, &jme
->old_ecmd
);
2729 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2736 jme_get_link(struct net_device
*netdev
)
2738 struct jme_adapter
*jme
= netdev_priv(netdev
);
2739 return jread32(jme
, JME_PHY_LINK
) & PHY_LINK_UP
;
2743 jme_get_msglevel(struct net_device
*netdev
)
2745 struct jme_adapter
*jme
= netdev_priv(netdev
);
2746 return jme
->msg_enable
;
2750 jme_set_msglevel(struct net_device
*netdev
, u32 value
)
2752 struct jme_adapter
*jme
= netdev_priv(netdev
);
2753 jme
->msg_enable
= value
;
2756 static netdev_features_t
2757 jme_fix_features(struct net_device
*netdev
, netdev_features_t features
)
2759 if (netdev
->mtu
> 1900)
2760 features
&= ~(NETIF_F_ALL_TSO
| NETIF_F_ALL_CSUM
);
2765 jme_set_features(struct net_device
*netdev
, netdev_features_t features
)
2767 struct jme_adapter
*jme
= netdev_priv(netdev
);
2769 spin_lock_bh(&jme
->rxmcs_lock
);
2770 if (features
& NETIF_F_RXCSUM
)
2771 jme
->reg_rxmcs
|= RXMCS_CHECKSUM
;
2773 jme
->reg_rxmcs
&= ~RXMCS_CHECKSUM
;
2774 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2775 spin_unlock_bh(&jme
->rxmcs_lock
);
2780 #ifdef CONFIG_NET_POLL_CONTROLLER
2781 static void jme_netpoll(struct net_device
*dev
)
2783 unsigned long flags
;
2785 local_irq_save(flags
);
2786 jme_intr(dev
->irq
, dev
);
2787 local_irq_restore(flags
);
2792 jme_nway_reset(struct net_device
*netdev
)
2794 struct jme_adapter
*jme
= netdev_priv(netdev
);
2795 jme_restart_an(jme
);
2800 jme_smb_read(struct jme_adapter
*jme
, unsigned int addr
)
2805 val
= jread32(jme
, JME_SMBCSR
);
2806 to
= JME_SMB_BUSY_TIMEOUT
;
2807 while ((val
& SMBCSR_BUSY
) && --to
) {
2809 val
= jread32(jme
, JME_SMBCSR
);
2812 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2816 jwrite32(jme
, JME_SMBINTF
,
2817 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2818 SMBINTF_HWRWN_READ
|
2821 val
= jread32(jme
, JME_SMBINTF
);
2822 to
= JME_SMB_BUSY_TIMEOUT
;
2823 while ((val
& SMBINTF_HWCMD
) && --to
) {
2825 val
= jread32(jme
, JME_SMBINTF
);
2828 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2832 return (val
& SMBINTF_HWDATR
) >> SMBINTF_HWDATR_SHIFT
;
2836 jme_smb_write(struct jme_adapter
*jme
, unsigned int addr
, u8 data
)
2841 val
= jread32(jme
, JME_SMBCSR
);
2842 to
= JME_SMB_BUSY_TIMEOUT
;
2843 while ((val
& SMBCSR_BUSY
) && --to
) {
2845 val
= jread32(jme
, JME_SMBCSR
);
2848 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2852 jwrite32(jme
, JME_SMBINTF
,
2853 ((data
<< SMBINTF_HWDATW_SHIFT
) & SMBINTF_HWDATW
) |
2854 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2855 SMBINTF_HWRWN_WRITE
|
2858 val
= jread32(jme
, JME_SMBINTF
);
2859 to
= JME_SMB_BUSY_TIMEOUT
;
2860 while ((val
& SMBINTF_HWCMD
) && --to
) {
2862 val
= jread32(jme
, JME_SMBINTF
);
2865 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2873 jme_get_eeprom_len(struct net_device
*netdev
)
2875 struct jme_adapter
*jme
= netdev_priv(netdev
);
2877 val
= jread32(jme
, JME_SMBCSR
);
2878 return (val
& SMBCSR_EEPROMD
) ? JME_SMB_LEN
: 0;
2882 jme_get_eeprom(struct net_device
*netdev
,
2883 struct ethtool_eeprom
*eeprom
, u8
*data
)
2885 struct jme_adapter
*jme
= netdev_priv(netdev
);
2886 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2889 * ethtool will check the boundary for us
2891 eeprom
->magic
= JME_EEPROM_MAGIC
;
2892 for (i
= 0 ; i
< len
; ++i
)
2893 data
[i
] = jme_smb_read(jme
, i
+ offset
);
2899 jme_set_eeprom(struct net_device
*netdev
,
2900 struct ethtool_eeprom
*eeprom
, u8
*data
)
2902 struct jme_adapter
*jme
= netdev_priv(netdev
);
2903 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2905 if (eeprom
->magic
!= JME_EEPROM_MAGIC
)
2909 * ethtool will check the boundary for us
2911 for (i
= 0 ; i
< len
; ++i
)
2912 jme_smb_write(jme
, i
+ offset
, data
[i
]);
2917 static const struct ethtool_ops jme_ethtool_ops
= {
2918 .get_drvinfo
= jme_get_drvinfo
,
2919 .get_regs_len
= jme_get_regs_len
,
2920 .get_regs
= jme_get_regs
,
2921 .get_coalesce
= jme_get_coalesce
,
2922 .set_coalesce
= jme_set_coalesce
,
2923 .get_pauseparam
= jme_get_pauseparam
,
2924 .set_pauseparam
= jme_set_pauseparam
,
2925 .get_wol
= jme_get_wol
,
2926 .set_wol
= jme_set_wol
,
2927 .get_settings
= jme_get_settings
,
2928 .set_settings
= jme_set_settings
,
2929 .get_link
= jme_get_link
,
2930 .get_msglevel
= jme_get_msglevel
,
2931 .set_msglevel
= jme_set_msglevel
,
2932 .nway_reset
= jme_nway_reset
,
2933 .get_eeprom_len
= jme_get_eeprom_len
,
2934 .get_eeprom
= jme_get_eeprom
,
2935 .set_eeprom
= jme_set_eeprom
,
2939 jme_pci_dma64(struct pci_dev
*pdev
)
2941 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2942 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
2943 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
2946 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2947 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(40)))
2948 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(40)))
2951 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)))
2952 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
2959 jme_phy_init(struct jme_adapter
*jme
)
2963 reg26
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 26);
2964 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 26, reg26
| 0x1000);
2968 jme_check_hw_ver(struct jme_adapter
*jme
)
2972 chipmode
= jread32(jme
, JME_CHIPMODE
);
2974 jme
->fpgaver
= (chipmode
& CM_FPGAVER_MASK
) >> CM_FPGAVER_SHIFT
;
2975 jme
->chiprev
= (chipmode
& CM_CHIPREV_MASK
) >> CM_CHIPREV_SHIFT
;
2976 jme
->chip_main_rev
= jme
->chiprev
& 0xF;
2977 jme
->chip_sub_rev
= (jme
->chiprev
>> 4) & 0xF;
2980 static const struct net_device_ops jme_netdev_ops
= {
2981 .ndo_open
= jme_open
,
2982 .ndo_stop
= jme_close
,
2983 .ndo_validate_addr
= eth_validate_addr
,
2984 .ndo_do_ioctl
= jme_ioctl
,
2985 .ndo_start_xmit
= jme_start_xmit
,
2986 .ndo_set_mac_address
= jme_set_macaddr
,
2987 .ndo_set_rx_mode
= jme_set_multi
,
2988 .ndo_change_mtu
= jme_change_mtu
,
2989 .ndo_tx_timeout
= jme_tx_timeout
,
2990 .ndo_fix_features
= jme_fix_features
,
2991 .ndo_set_features
= jme_set_features
,
2992 #ifdef CONFIG_NET_POLL_CONTROLLER
2993 .ndo_poll_controller
= jme_netpoll
,
2998 jme_init_one(struct pci_dev
*pdev
,
2999 const struct pci_device_id
*ent
)
3001 int rc
= 0, using_dac
, i
;
3002 struct net_device
*netdev
;
3003 struct jme_adapter
*jme
;
3008 * set up PCI device basics
3010 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
| PCIE_LINK_STATE_L1
|
3011 PCIE_LINK_STATE_CLKPM
);
3013 rc
= pci_enable_device(pdev
);
3015 pr_err("Cannot enable PCI device\n");
3019 using_dac
= jme_pci_dma64(pdev
);
3020 if (using_dac
< 0) {
3021 pr_err("Cannot set PCI DMA Mask\n");
3023 goto err_out_disable_pdev
;
3026 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
3027 pr_err("No PCI resource region found\n");
3029 goto err_out_disable_pdev
;
3032 rc
= pci_request_regions(pdev
, DRV_NAME
);
3034 pr_err("Cannot obtain PCI resource region\n");
3035 goto err_out_disable_pdev
;
3038 pci_set_master(pdev
);
3041 * alloc and init net device
3043 netdev
= alloc_etherdev(sizeof(*jme
));
3046 goto err_out_release_regions
;
3048 netdev
->netdev_ops
= &jme_netdev_ops
;
3049 netdev
->ethtool_ops
= &jme_ethtool_ops
;
3050 netdev
->watchdog_timeo
= TX_TIMEOUT
;
3051 netdev
->hw_features
= NETIF_F_IP_CSUM
|
3057 netdev
->features
= NETIF_F_IP_CSUM
|
3062 NETIF_F_HW_VLAN_CTAG_TX
|
3063 NETIF_F_HW_VLAN_CTAG_RX
;
3065 netdev
->features
|= NETIF_F_HIGHDMA
;
3067 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3068 pci_set_drvdata(pdev
, netdev
);
3073 jme
= netdev_priv(netdev
);
3076 jme
->jme_rx
= netif_rx
;
3077 jme
->old_mtu
= netdev
->mtu
= 1500;
3079 jme
->tx_ring_size
= 1 << 10;
3080 jme
->tx_ring_mask
= jme
->tx_ring_size
- 1;
3081 jme
->tx_wake_threshold
= 1 << 9;
3082 jme
->rx_ring_size
= 1 << 9;
3083 jme
->rx_ring_mask
= jme
->rx_ring_size
- 1;
3084 jme
->msg_enable
= JME_DEF_MSG_ENABLE
;
3085 jme
->regs
= ioremap(pci_resource_start(pdev
, 0),
3086 pci_resource_len(pdev
, 0));
3088 pr_err("Mapping PCI resource region error\n");
3090 goto err_out_free_netdev
;
3094 apmc
= jread32(jme
, JME_APMC
) & ~JME_APMC_PSEUDO_HP_EN
;
3095 jwrite32(jme
, JME_APMC
, apmc
);
3096 } else if (force_pseudohp
) {
3097 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PSEUDO_HP_EN
;
3098 jwrite32(jme
, JME_APMC
, apmc
);
3101 NETIF_NAPI_SET(netdev
, &jme
->napi
, jme_poll
, NAPI_POLL_WEIGHT
)
3103 spin_lock_init(&jme
->phy_lock
);
3104 spin_lock_init(&jme
->macaddr_lock
);
3105 spin_lock_init(&jme
->rxmcs_lock
);
3107 atomic_set(&jme
->link_changing
, 1);
3108 atomic_set(&jme
->rx_cleaning
, 1);
3109 atomic_set(&jme
->tx_cleaning
, 1);
3110 atomic_set(&jme
->rx_empty
, 1);
3112 tasklet_init(&jme
->pcc_task
,
3114 (unsigned long) jme
);
3115 jme
->dpi
.cur
= PCC_P1
;
3118 jme
->reg_rxcs
= RXCS_DEFAULT
;
3119 jme
->reg_rxmcs
= RXMCS_DEFAULT
;
3121 jme
->reg_pmcs
= PMCS_MFEN
;
3122 jme
->reg_gpreg1
= GPREG1_DEFAULT
;
3124 if (jme
->reg_rxmcs
& RXMCS_CHECKSUM
)
3125 netdev
->features
|= NETIF_F_RXCSUM
;
3128 * Get Max Read Req Size from PCI Config Space
3130 pci_read_config_byte(pdev
, PCI_DCSR_MRRS
, &jme
->mrrs
);
3131 jme
->mrrs
&= PCI_DCSR_MRRS_MASK
;
3132 switch (jme
->mrrs
) {
3134 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_128B
;
3137 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_256B
;
3140 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_512B
;
3145 * Must check before reset_mac_processor
3147 jme_check_hw_ver(jme
);
3148 jme
->mii_if
.dev
= netdev
;
3150 jme
->mii_if
.phy_id
= 0;
3151 for (i
= 1 ; i
< 32 ; ++i
) {
3152 bmcr
= jme_mdio_read(netdev
, i
, MII_BMCR
);
3153 bmsr
= jme_mdio_read(netdev
, i
, MII_BMSR
);
3154 if (bmcr
!= 0xFFFFU
&& (bmcr
!= 0 || bmsr
!= 0)) {
3155 jme
->mii_if
.phy_id
= i
;
3160 if (!jme
->mii_if
.phy_id
) {
3162 pr_err("Can not find phy_id\n");
3166 jme
->reg_ghc
|= GHC_LINK_POLL
;
3168 jme
->mii_if
.phy_id
= 1;
3170 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
3171 jme
->mii_if
.supports_gmii
= true;
3173 jme
->mii_if
.supports_gmii
= false;
3174 jme
->mii_if
.phy_id_mask
= 0x1F;
3175 jme
->mii_if
.reg_num_mask
= 0x1F;
3176 jme
->mii_if
.mdio_read
= jme_mdio_read
;
3177 jme
->mii_if
.mdio_write
= jme_mdio_write
;
3180 device_set_wakeup_enable(&pdev
->dev
, true);
3182 jme_set_phyfifo_5level(jme
);
3183 jme
->pcirev
= pdev
->revision
;
3189 * Reset MAC processor and reload EEPROM for MAC Address
3191 jme_reset_mac_processor(jme
);
3192 rc
= jme_reload_eeprom(jme
);
3194 pr_err("Reload eeprom for reading MAC Address error\n");
3197 jme_load_macaddr(netdev
);
3200 * Tell stack that we are not ready to work until open()
3202 netif_carrier_off(netdev
);
3204 rc
= register_netdev(netdev
);
3206 pr_err("Cannot register net device\n");
3210 netif_info(jme
, probe
, jme
->dev
, "%s%s chiprev:%x pcirev:%x macaddr:%pM\n",
3211 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
) ?
3212 "JMC250 Gigabit Ethernet" :
3213 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC260
) ?
3214 "JMC260 Fast Ethernet" : "Unknown",
3215 (jme
->fpgaver
!= 0) ? " (FPGA)" : "",
3216 (jme
->fpgaver
!= 0) ? jme
->fpgaver
: jme
->chiprev
,
3217 jme
->pcirev
, netdev
->dev_addr
);
3223 err_out_free_netdev
:
3224 free_netdev(netdev
);
3225 err_out_release_regions
:
3226 pci_release_regions(pdev
);
3227 err_out_disable_pdev
:
3228 pci_disable_device(pdev
);
3234 jme_remove_one(struct pci_dev
*pdev
)
3236 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3237 struct jme_adapter
*jme
= netdev_priv(netdev
);
3239 unregister_netdev(netdev
);
3241 free_netdev(netdev
);
3242 pci_release_regions(pdev
);
3243 pci_disable_device(pdev
);
3248 jme_shutdown(struct pci_dev
*pdev
)
3250 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3251 struct jme_adapter
*jme
= netdev_priv(netdev
);
3253 jme_powersave_phy(jme
);
3254 pci_pme_active(pdev
, true);
3257 #ifdef CONFIG_PM_SLEEP
3259 jme_suspend(struct device
*dev
)
3261 struct pci_dev
*pdev
= to_pci_dev(dev
);
3262 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3263 struct jme_adapter
*jme
= netdev_priv(netdev
);
3265 if (!netif_running(netdev
))
3268 atomic_dec(&jme
->link_changing
);
3270 netif_device_detach(netdev
);
3271 netif_stop_queue(netdev
);
3274 tasklet_disable(&jme
->txclean_task
);
3275 tasklet_disable(&jme
->rxclean_task
);
3276 tasklet_disable(&jme
->rxempty_task
);
3278 if (netif_carrier_ok(netdev
)) {
3279 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
3280 jme_polling_mode(jme
);
3282 jme_stop_pcc_timer(jme
);
3283 jme_disable_rx_engine(jme
);
3284 jme_disable_tx_engine(jme
);
3285 jme_reset_mac_processor(jme
);
3286 jme_free_rx_resources(jme
);
3287 jme_free_tx_resources(jme
);
3288 netif_carrier_off(netdev
);
3292 tasklet_enable(&jme
->txclean_task
);
3293 tasklet_enable(&jme
->rxclean_task
);
3294 tasklet_enable(&jme
->rxempty_task
);
3296 jme_powersave_phy(jme
);
3302 jme_resume(struct device
*dev
)
3304 struct pci_dev
*pdev
= to_pci_dev(dev
);
3305 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3306 struct jme_adapter
*jme
= netdev_priv(netdev
);
3308 if (!netif_running(netdev
))
3313 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
3314 jme_set_settings(netdev
, &jme
->old_ecmd
);
3316 jme_reset_phy_processor(jme
);
3317 jme_phy_calibration(jme
);
3320 netif_device_attach(netdev
);
3322 atomic_inc(&jme
->link_changing
);
3324 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
);