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/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/ethtool.h>
33 #include <linux/mii.h>
34 #include <linux/crc32.h>
35 #include <linux/delay.h>
36 #include <linux/spinlock.h>
39 #include <linux/ipv6.h>
40 #include <linux/tcp.h>
41 #include <linux/udp.h>
42 #include <linux/if_vlan.h>
43 #include <linux/slab.h>
44 #include <net/ip6_checksum.h>
47 static int force_pseudohp
= -1;
48 static int no_pseudohp
= -1;
49 static int no_extplug
= -1;
50 module_param(force_pseudohp
, int, 0);
51 MODULE_PARM_DESC(force_pseudohp
,
52 "Enable pseudo hot-plug feature manually by driver instead of BIOS.");
53 module_param(no_pseudohp
, int, 0);
54 MODULE_PARM_DESC(no_pseudohp
, "Disable pseudo hot-plug feature.");
55 module_param(no_extplug
, int, 0);
56 MODULE_PARM_DESC(no_extplug
,
57 "Do not use external plug signal for pseudo hot-plug.");
60 jme_mdio_read(struct net_device
*netdev
, int phy
, int reg
)
62 struct jme_adapter
*jme
= netdev_priv(netdev
);
63 int i
, val
, again
= (reg
== MII_BMSR
) ? 1 : 0;
66 jwrite32(jme
, JME_SMI
, SMI_OP_REQ
|
71 for (i
= JME_PHY_TIMEOUT
* 50 ; i
> 0 ; --i
) {
73 val
= jread32(jme
, JME_SMI
);
74 if ((val
& SMI_OP_REQ
) == 0)
79 pr_err("phy(%d) read timeout : %d\n", phy
, reg
);
86 return (val
& SMI_DATA_MASK
) >> SMI_DATA_SHIFT
;
90 jme_mdio_write(struct net_device
*netdev
,
91 int phy
, int reg
, int val
)
93 struct jme_adapter
*jme
= netdev_priv(netdev
);
96 jwrite32(jme
, JME_SMI
, SMI_OP_WRITE
| SMI_OP_REQ
|
97 ((val
<< SMI_DATA_SHIFT
) & SMI_DATA_MASK
) |
98 smi_phy_addr(phy
) | smi_reg_addr(reg
));
101 for (i
= JME_PHY_TIMEOUT
* 50 ; i
> 0 ; --i
) {
103 if ((jread32(jme
, JME_SMI
) & SMI_OP_REQ
) == 0)
108 pr_err("phy(%d) write timeout : %d\n", phy
, reg
);
112 jme_reset_phy_processor(struct jme_adapter
*jme
)
116 jme_mdio_write(jme
->dev
,
118 MII_ADVERTISE
, ADVERTISE_ALL
|
119 ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
121 if (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
122 jme_mdio_write(jme
->dev
,
125 ADVERTISE_1000FULL
| ADVERTISE_1000HALF
);
127 val
= jme_mdio_read(jme
->dev
,
131 jme_mdio_write(jme
->dev
,
133 MII_BMCR
, val
| BMCR_RESET
);
137 jme_setup_wakeup_frame(struct jme_adapter
*jme
,
138 const u32
*mask
, u32 crc
, int fnr
)
145 jwrite32(jme
, JME_WFOI
, WFOI_CRC_SEL
| (fnr
& WFOI_FRAME_SEL
));
147 jwrite32(jme
, JME_WFODP
, crc
);
153 for (i
= 0 ; i
< WAKEUP_FRAME_MASK_DWNR
; ++i
) {
154 jwrite32(jme
, JME_WFOI
,
155 ((i
<< WFOI_MASK_SHIFT
) & WFOI_MASK_SEL
) |
156 (fnr
& WFOI_FRAME_SEL
));
158 jwrite32(jme
, JME_WFODP
, mask
[i
]);
164 jme_mac_rxclk_off(struct jme_adapter
*jme
)
166 jme
->reg_gpreg1
|= GPREG1_RXCLKOFF
;
167 jwrite32f(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
171 jme_mac_rxclk_on(struct jme_adapter
*jme
)
173 jme
->reg_gpreg1
&= ~GPREG1_RXCLKOFF
;
174 jwrite32f(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
178 jme_mac_txclk_off(struct jme_adapter
*jme
)
180 jme
->reg_ghc
&= ~(GHC_TO_CLK_SRC
| GHC_TXMAC_CLK_SRC
);
181 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
185 jme_mac_txclk_on(struct jme_adapter
*jme
)
187 u32 speed
= jme
->reg_ghc
& GHC_SPEED
;
188 if (speed
== GHC_SPEED_1000M
)
189 jme
->reg_ghc
|= GHC_TO_CLK_GPHY
| GHC_TXMAC_CLK_GPHY
;
191 jme
->reg_ghc
|= GHC_TO_CLK_PCIE
| GHC_TXMAC_CLK_PCIE
;
192 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
196 jme_reset_ghc_speed(struct jme_adapter
*jme
)
198 jme
->reg_ghc
&= ~(GHC_SPEED
| GHC_DPX
);
199 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
203 jme_reset_250A2_workaround(struct jme_adapter
*jme
)
205 jme
->reg_gpreg1
&= ~(GPREG1_HALFMODEPATCH
|
207 jwrite32(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
211 jme_assert_ghc_reset(struct jme_adapter
*jme
)
213 jme
->reg_ghc
|= GHC_SWRST
;
214 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
218 jme_clear_ghc_reset(struct jme_adapter
*jme
)
220 jme
->reg_ghc
&= ~GHC_SWRST
;
221 jwrite32f(jme
, JME_GHC
, jme
->reg_ghc
);
225 jme_reset_mac_processor(struct jme_adapter
*jme
)
227 static const u32 mask
[WAKEUP_FRAME_MASK_DWNR
] = {0, 0, 0, 0};
228 u32 crc
= 0xCDCDCDCD;
232 jme_reset_ghc_speed(jme
);
233 jme_reset_250A2_workaround(jme
);
235 jme_mac_rxclk_on(jme
);
236 jme_mac_txclk_on(jme
);
238 jme_assert_ghc_reset(jme
);
240 jme_mac_rxclk_off(jme
);
241 jme_mac_txclk_off(jme
);
243 jme_clear_ghc_reset(jme
);
245 jme_mac_rxclk_on(jme
);
246 jme_mac_txclk_on(jme
);
248 jme_mac_rxclk_off(jme
);
249 jme_mac_txclk_off(jme
);
251 jwrite32(jme
, JME_RXDBA_LO
, 0x00000000);
252 jwrite32(jme
, JME_RXDBA_HI
, 0x00000000);
253 jwrite32(jme
, JME_RXQDC
, 0x00000000);
254 jwrite32(jme
, JME_RXNDA
, 0x00000000);
255 jwrite32(jme
, JME_TXDBA_LO
, 0x00000000);
256 jwrite32(jme
, JME_TXDBA_HI
, 0x00000000);
257 jwrite32(jme
, JME_TXQDC
, 0x00000000);
258 jwrite32(jme
, JME_TXNDA
, 0x00000000);
260 jwrite32(jme
, JME_RXMCHT_LO
, 0x00000000);
261 jwrite32(jme
, JME_RXMCHT_HI
, 0x00000000);
262 for (i
= 0 ; i
< WAKEUP_FRAME_NR
; ++i
)
263 jme_setup_wakeup_frame(jme
, mask
, crc
, i
);
265 gpreg0
= GPREG0_DEFAULT
| GPREG0_LNKINTPOLL
;
267 gpreg0
= GPREG0_DEFAULT
;
268 jwrite32(jme
, JME_GPREG0
, gpreg0
);
272 jme_clear_pm(struct jme_adapter
*jme
)
274 jwrite32(jme
, JME_PMCS
, 0xFFFF0000 | jme
->reg_pmcs
);
275 pci_set_power_state(jme
->pdev
, PCI_D0
);
276 device_set_wakeup_enable(&jme
->pdev
->dev
, false);
280 jme_reload_eeprom(struct jme_adapter
*jme
)
285 val
= jread32(jme
, JME_SMBCSR
);
287 if (val
& SMBCSR_EEPROMD
) {
289 jwrite32(jme
, JME_SMBCSR
, val
);
290 val
|= SMBCSR_RELOAD
;
291 jwrite32(jme
, JME_SMBCSR
, val
);
294 for (i
= JME_EEPROM_RELOAD_TIMEOUT
; i
> 0; --i
) {
296 if ((jread32(jme
, JME_SMBCSR
) & SMBCSR_RELOAD
) == 0)
301 pr_err("eeprom reload timeout\n");
310 jme_load_macaddr(struct net_device
*netdev
)
312 struct jme_adapter
*jme
= netdev_priv(netdev
);
313 unsigned char macaddr
[6];
316 spin_lock_bh(&jme
->macaddr_lock
);
317 val
= jread32(jme
, JME_RXUMA_LO
);
318 macaddr
[0] = (val
>> 0) & 0xFF;
319 macaddr
[1] = (val
>> 8) & 0xFF;
320 macaddr
[2] = (val
>> 16) & 0xFF;
321 macaddr
[3] = (val
>> 24) & 0xFF;
322 val
= jread32(jme
, JME_RXUMA_HI
);
323 macaddr
[4] = (val
>> 0) & 0xFF;
324 macaddr
[5] = (val
>> 8) & 0xFF;
325 memcpy(netdev
->dev_addr
, macaddr
, 6);
326 spin_unlock_bh(&jme
->macaddr_lock
);
330 jme_set_rx_pcc(struct jme_adapter
*jme
, int p
)
334 jwrite32(jme
, JME_PCCRX0
,
335 ((PCC_OFF_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
336 ((PCC_OFF_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
339 jwrite32(jme
, JME_PCCRX0
,
340 ((PCC_P1_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
341 ((PCC_P1_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
344 jwrite32(jme
, JME_PCCRX0
,
345 ((PCC_P2_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
346 ((PCC_P2_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
349 jwrite32(jme
, JME_PCCRX0
,
350 ((PCC_P3_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
351 ((PCC_P3_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
358 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
359 netif_info(jme
, rx_status
, jme
->dev
, "Switched to PCC_P%d\n", p
);
363 jme_start_irq(struct jme_adapter
*jme
)
365 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
367 jme_set_rx_pcc(jme
, PCC_P1
);
369 dpi
->attempt
= PCC_P1
;
372 jwrite32(jme
, JME_PCCTX
,
373 ((PCC_TX_TO
<< PCCTXTO_SHIFT
) & PCCTXTO_MASK
) |
374 ((PCC_TX_CNT
<< PCCTX_SHIFT
) & PCCTX_MASK
) |
381 jwrite32(jme
, JME_IENS
, INTR_ENABLE
);
385 jme_stop_irq(struct jme_adapter
*jme
)
390 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
394 jme_linkstat_from_phy(struct jme_adapter
*jme
)
398 phylink
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 17);
399 bmsr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMSR
);
400 if (bmsr
& BMSR_ANCOMP
)
401 phylink
|= PHY_LINK_AUTONEG_COMPLETE
;
407 jme_set_phyfifo_5level(struct jme_adapter
*jme
)
409 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0004);
413 jme_set_phyfifo_8level(struct jme_adapter
*jme
)
415 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0000);
419 jme_check_link(struct net_device
*netdev
, int testonly
)
421 struct jme_adapter
*jme
= netdev_priv(netdev
);
422 u32 phylink
, cnt
= JME_SPDRSV_TIMEOUT
, bmcr
;
429 phylink
= jme_linkstat_from_phy(jme
);
431 phylink
= jread32(jme
, JME_PHY_LINK
);
433 if (phylink
& PHY_LINK_UP
) {
434 if (!(phylink
& PHY_LINK_AUTONEG_COMPLETE
)) {
436 * If we did not enable AN
437 * Speed/Duplex Info should be obtained from SMI
439 phylink
= PHY_LINK_UP
;
441 bmcr
= jme_mdio_read(jme
->dev
,
445 phylink
|= ((bmcr
& BMCR_SPEED1000
) &&
446 (bmcr
& BMCR_SPEED100
) == 0) ?
447 PHY_LINK_SPEED_1000M
:
448 (bmcr
& BMCR_SPEED100
) ?
449 PHY_LINK_SPEED_100M
:
452 phylink
|= (bmcr
& BMCR_FULLDPLX
) ?
455 strcat(linkmsg
, "Forced: ");
458 * Keep polling for speed/duplex resolve complete
460 while (!(phylink
& PHY_LINK_SPEEDDPU_RESOLVED
) &&
466 phylink
= jme_linkstat_from_phy(jme
);
468 phylink
= jread32(jme
, JME_PHY_LINK
);
471 pr_err("Waiting speed resolve timeout\n");
473 strcat(linkmsg
, "ANed: ");
476 if (jme
->phylink
== phylink
) {
483 jme
->phylink
= phylink
;
486 * The speed/duplex setting of jme->reg_ghc already cleared
487 * by jme_reset_mac_processor()
489 switch (phylink
& PHY_LINK_SPEED_MASK
) {
490 case PHY_LINK_SPEED_10M
:
491 jme
->reg_ghc
|= GHC_SPEED_10M
;
492 strcat(linkmsg
, "10 Mbps, ");
494 case PHY_LINK_SPEED_100M
:
495 jme
->reg_ghc
|= GHC_SPEED_100M
;
496 strcat(linkmsg
, "100 Mbps, ");
498 case PHY_LINK_SPEED_1000M
:
499 jme
->reg_ghc
|= GHC_SPEED_1000M
;
500 strcat(linkmsg
, "1000 Mbps, ");
506 if (phylink
& PHY_LINK_DUPLEX
) {
507 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
);
508 jwrite32(jme
, JME_TXTRHD
, TXTRHD_FULLDUPLEX
);
509 jme
->reg_ghc
|= GHC_DPX
;
511 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
|
515 jwrite32(jme
, JME_TXTRHD
, TXTRHD_HALFDUPLEX
);
518 jwrite32(jme
, JME_GHC
, jme
->reg_ghc
);
520 if (is_buggy250(jme
->pdev
->device
, jme
->chiprev
)) {
521 jme
->reg_gpreg1
&= ~(GPREG1_HALFMODEPATCH
|
523 if (!(phylink
& PHY_LINK_DUPLEX
))
524 jme
->reg_gpreg1
|= GPREG1_HALFMODEPATCH
;
525 switch (phylink
& PHY_LINK_SPEED_MASK
) {
526 case PHY_LINK_SPEED_10M
:
527 jme_set_phyfifo_8level(jme
);
528 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
530 case PHY_LINK_SPEED_100M
:
531 jme_set_phyfifo_5level(jme
);
532 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
534 case PHY_LINK_SPEED_1000M
:
535 jme_set_phyfifo_8level(jme
);
541 jwrite32(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
543 strcat(linkmsg
, (phylink
& PHY_LINK_DUPLEX
) ?
546 strcat(linkmsg
, (phylink
& PHY_LINK_MDI_STAT
) ?
549 netif_info(jme
, link
, jme
->dev
, "Link is up at %s\n", linkmsg
);
550 netif_carrier_on(netdev
);
555 netif_info(jme
, link
, jme
->dev
, "Link is down\n");
557 netif_carrier_off(netdev
);
565 jme_setup_tx_resources(struct jme_adapter
*jme
)
567 struct jme_ring
*txring
= &(jme
->txring
[0]);
569 txring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
570 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
580 txring
->desc
= (void *)ALIGN((unsigned long)(txring
->alloc
),
582 txring
->dma
= ALIGN(txring
->dmaalloc
, RING_DESC_ALIGN
);
583 txring
->next_to_use
= 0;
584 atomic_set(&txring
->next_to_clean
, 0);
585 atomic_set(&txring
->nr_free
, jme
->tx_ring_size
);
587 txring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
588 jme
->tx_ring_size
, GFP_ATOMIC
);
589 if (unlikely(!(txring
->bufinf
)))
590 goto err_free_txring
;
593 * Initialize Transmit Descriptors
595 memset(txring
->alloc
, 0, TX_RING_ALLOC_SIZE(jme
->tx_ring_size
));
596 memset(txring
->bufinf
, 0,
597 sizeof(struct jme_buffer_info
) * jme
->tx_ring_size
);
602 dma_free_coherent(&(jme
->pdev
->dev
),
603 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
609 txring
->dmaalloc
= 0;
611 txring
->bufinf
= NULL
;
617 jme_free_tx_resources(struct jme_adapter
*jme
)
620 struct jme_ring
*txring
= &(jme
->txring
[0]);
621 struct jme_buffer_info
*txbi
;
624 if (txring
->bufinf
) {
625 for (i
= 0 ; i
< jme
->tx_ring_size
; ++i
) {
626 txbi
= txring
->bufinf
+ i
;
628 dev_kfree_skb(txbi
->skb
);
634 txbi
->start_xmit
= 0;
636 kfree(txring
->bufinf
);
639 dma_free_coherent(&(jme
->pdev
->dev
),
640 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
644 txring
->alloc
= NULL
;
646 txring
->dmaalloc
= 0;
648 txring
->bufinf
= NULL
;
650 txring
->next_to_use
= 0;
651 atomic_set(&txring
->next_to_clean
, 0);
652 atomic_set(&txring
->nr_free
, 0);
656 jme_enable_tx_engine(struct jme_adapter
*jme
)
661 jwrite32(jme
, JME_TXCS
, TXCS_DEFAULT
| TXCS_SELECT_QUEUE0
);
665 * Setup TX Queue 0 DMA Bass Address
667 jwrite32(jme
, JME_TXDBA_LO
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
668 jwrite32(jme
, JME_TXDBA_HI
, (__u64
)(jme
->txring
[0].dma
) >> 32);
669 jwrite32(jme
, JME_TXNDA
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
672 * Setup TX Descptor Count
674 jwrite32(jme
, JME_TXQDC
, jme
->tx_ring_size
);
680 jwrite32f(jme
, JME_TXCS
, jme
->reg_txcs
|
685 * Start clock for TX MAC Processor
687 jme_mac_txclk_on(jme
);
691 jme_restart_tx_engine(struct jme_adapter
*jme
)
696 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
702 jme_disable_tx_engine(struct jme_adapter
*jme
)
710 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
| TXCS_SELECT_QUEUE0
);
713 val
= jread32(jme
, JME_TXCS
);
714 for (i
= JME_TX_DISABLE_TIMEOUT
; (val
& TXCS_ENABLE
) && i
> 0 ; --i
) {
716 val
= jread32(jme
, JME_TXCS
);
721 pr_err("Disable TX engine timeout\n");
724 * Stop clock for TX MAC Processor
726 jme_mac_txclk_off(jme
);
730 jme_set_clean_rxdesc(struct jme_adapter
*jme
, int i
)
732 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
733 register struct rxdesc
*rxdesc
= rxring
->desc
;
734 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
740 rxdesc
->desc1
.bufaddrh
= cpu_to_le32((__u64
)rxbi
->mapping
>> 32);
741 rxdesc
->desc1
.bufaddrl
= cpu_to_le32(
742 (__u64
)rxbi
->mapping
& 0xFFFFFFFFUL
);
743 rxdesc
->desc1
.datalen
= cpu_to_le16(rxbi
->len
);
744 if (jme
->dev
->features
& NETIF_F_HIGHDMA
)
745 rxdesc
->desc1
.flags
= RXFLAG_64BIT
;
747 rxdesc
->desc1
.flags
|= RXFLAG_OWN
| RXFLAG_INT
;
751 jme_make_new_rx_buf(struct jme_adapter
*jme
, int i
)
753 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
754 struct jme_buffer_info
*rxbi
= rxring
->bufinf
+ i
;
757 skb
= netdev_alloc_skb(jme
->dev
,
758 jme
->dev
->mtu
+ RX_EXTRA_LEN
);
763 rxbi
->len
= skb_tailroom(skb
);
764 rxbi
->mapping
= pci_map_page(jme
->pdev
,
765 virt_to_page(skb
->data
),
766 offset_in_page(skb
->data
),
774 jme_free_rx_buf(struct jme_adapter
*jme
, int i
)
776 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
777 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
781 pci_unmap_page(jme
->pdev
,
785 dev_kfree_skb(rxbi
->skb
);
793 jme_free_rx_resources(struct jme_adapter
*jme
)
796 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
799 if (rxring
->bufinf
) {
800 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
)
801 jme_free_rx_buf(jme
, i
);
802 kfree(rxring
->bufinf
);
805 dma_free_coherent(&(jme
->pdev
->dev
),
806 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
809 rxring
->alloc
= NULL
;
811 rxring
->dmaalloc
= 0;
813 rxring
->bufinf
= NULL
;
815 rxring
->next_to_use
= 0;
816 atomic_set(&rxring
->next_to_clean
, 0);
820 jme_setup_rx_resources(struct jme_adapter
*jme
)
823 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
825 rxring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
826 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
835 rxring
->desc
= (void *)ALIGN((unsigned long)(rxring
->alloc
),
837 rxring
->dma
= ALIGN(rxring
->dmaalloc
, RING_DESC_ALIGN
);
838 rxring
->next_to_use
= 0;
839 atomic_set(&rxring
->next_to_clean
, 0);
841 rxring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
842 jme
->rx_ring_size
, GFP_ATOMIC
);
843 if (unlikely(!(rxring
->bufinf
)))
844 goto err_free_rxring
;
847 * Initiallize Receive Descriptors
849 memset(rxring
->bufinf
, 0,
850 sizeof(struct jme_buffer_info
) * jme
->rx_ring_size
);
851 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
) {
852 if (unlikely(jme_make_new_rx_buf(jme
, i
))) {
853 jme_free_rx_resources(jme
);
857 jme_set_clean_rxdesc(jme
, i
);
863 dma_free_coherent(&(jme
->pdev
->dev
),
864 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
869 rxring
->dmaalloc
= 0;
871 rxring
->bufinf
= NULL
;
877 jme_enable_rx_engine(struct jme_adapter
*jme
)
882 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
887 * Setup RX DMA Bass Address
889 jwrite32(jme
, JME_RXDBA_LO
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
890 jwrite32(jme
, JME_RXDBA_HI
, (__u64
)(jme
->rxring
[0].dma
) >> 32);
891 jwrite32(jme
, JME_RXNDA
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
894 * Setup RX Descriptor Count
896 jwrite32(jme
, JME_RXQDC
, jme
->rx_ring_size
);
899 * Setup Unicast Filter
901 jme_set_unicastaddr(jme
->dev
);
902 jme_set_multi(jme
->dev
);
908 jwrite32f(jme
, JME_RXCS
, jme
->reg_rxcs
|
914 * Start clock for RX MAC Processor
916 jme_mac_rxclk_on(jme
);
920 jme_restart_rx_engine(struct jme_adapter
*jme
)
925 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
932 jme_disable_rx_engine(struct jme_adapter
*jme
)
940 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
);
943 val
= jread32(jme
, JME_RXCS
);
944 for (i
= JME_RX_DISABLE_TIMEOUT
; (val
& RXCS_ENABLE
) && i
> 0 ; --i
) {
946 val
= jread32(jme
, JME_RXCS
);
951 pr_err("Disable RX engine timeout\n");
954 * Stop clock for RX MAC Processor
956 jme_mac_rxclk_off(jme
);
960 jme_udpsum(struct sk_buff
*skb
)
964 if (skb
->len
< (ETH_HLEN
+ sizeof(struct iphdr
)))
966 if (skb
->protocol
!= htons(ETH_P_IP
))
968 skb_set_network_header(skb
, ETH_HLEN
);
969 if ((ip_hdr(skb
)->protocol
!= IPPROTO_UDP
) ||
970 (skb
->len
< (ETH_HLEN
+
971 (ip_hdr(skb
)->ihl
<< 2) +
972 sizeof(struct udphdr
)))) {
973 skb_reset_network_header(skb
);
976 skb_set_transport_header(skb
,
977 ETH_HLEN
+ (ip_hdr(skb
)->ihl
<< 2));
978 csum
= udp_hdr(skb
)->check
;
979 skb_reset_transport_header(skb
);
980 skb_reset_network_header(skb
);
986 jme_rxsum_ok(struct jme_adapter
*jme
, u16 flags
, struct sk_buff
*skb
)
988 if (!(flags
& (RXWBFLAG_TCPON
| RXWBFLAG_UDPON
| RXWBFLAG_IPV4
)))
991 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_TCPON
| RXWBFLAG_TCPCS
))
992 == RXWBFLAG_TCPON
)) {
993 if (flags
& RXWBFLAG_IPV4
)
994 netif_err(jme
, rx_err
, jme
->dev
, "TCP Checksum error\n");
998 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_UDPON
| RXWBFLAG_UDPCS
))
999 == RXWBFLAG_UDPON
) && jme_udpsum(skb
)) {
1000 if (flags
& RXWBFLAG_IPV4
)
1001 netif_err(jme
, rx_err
, jme
->dev
, "UDP Checksum error\n");
1005 if (unlikely((flags
& (RXWBFLAG_IPV4
| RXWBFLAG_IPCS
))
1006 == RXWBFLAG_IPV4
)) {
1007 netif_err(jme
, rx_err
, jme
->dev
, "IPv4 Checksum error\n");
1015 jme_alloc_and_feed_skb(struct jme_adapter
*jme
, int idx
)
1017 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1018 struct rxdesc
*rxdesc
= rxring
->desc
;
1019 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
1020 struct sk_buff
*skb
;
1027 pci_dma_sync_single_for_cpu(jme
->pdev
,
1030 PCI_DMA_FROMDEVICE
);
1032 if (unlikely(jme_make_new_rx_buf(jme
, idx
))) {
1033 pci_dma_sync_single_for_device(jme
->pdev
,
1036 PCI_DMA_FROMDEVICE
);
1038 ++(NET_STAT(jme
).rx_dropped
);
1040 framesize
= le16_to_cpu(rxdesc
->descwb
.framesize
)
1043 skb_reserve(skb
, RX_PREPAD_SIZE
);
1044 skb_put(skb
, framesize
);
1045 skb
->protocol
= eth_type_trans(skb
, jme
->dev
);
1047 if (jme_rxsum_ok(jme
, le16_to_cpu(rxdesc
->descwb
.flags
), skb
))
1048 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1050 skb_checksum_none_assert(skb
);
1052 if (rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_TAGON
)) {
1054 jme
->jme_vlan_rx(skb
, jme
->vlgrp
,
1055 le16_to_cpu(rxdesc
->descwb
.vlan
));
1056 NET_STAT(jme
).rx_bytes
+= 4;
1064 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_DEST
)) ==
1065 cpu_to_le16(RXWBFLAG_DEST_MUL
))
1066 ++(NET_STAT(jme
).multicast
);
1068 NET_STAT(jme
).rx_bytes
+= framesize
;
1069 ++(NET_STAT(jme
).rx_packets
);
1072 jme_set_clean_rxdesc(jme
, idx
);
1077 jme_process_receive(struct jme_adapter
*jme
, int limit
)
1079 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1080 struct rxdesc
*rxdesc
= rxring
->desc
;
1081 int i
, j
, ccnt
, desccnt
, mask
= jme
->rx_ring_mask
;
1083 if (unlikely(!atomic_dec_and_test(&jme
->rx_cleaning
)))
1086 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1089 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1092 i
= atomic_read(&rxring
->next_to_clean
);
1094 rxdesc
= rxring
->desc
;
1097 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_OWN
)) ||
1098 !(rxdesc
->descwb
.desccnt
& RXWBDCNT_WBCPL
))
1103 desccnt
= rxdesc
->descwb
.desccnt
& RXWBDCNT_DCNT
;
1105 if (unlikely(desccnt
> 1 ||
1106 rxdesc
->descwb
.errstat
& RXWBERR_ALLERR
)) {
1108 if (rxdesc
->descwb
.errstat
& RXWBERR_CRCERR
)
1109 ++(NET_STAT(jme
).rx_crc_errors
);
1110 else if (rxdesc
->descwb
.errstat
& RXWBERR_OVERUN
)
1111 ++(NET_STAT(jme
).rx_fifo_errors
);
1113 ++(NET_STAT(jme
).rx_errors
);
1116 limit
-= desccnt
- 1;
1118 for (j
= i
, ccnt
= desccnt
; ccnt
-- ; ) {
1119 jme_set_clean_rxdesc(jme
, j
);
1120 j
= (j
+ 1) & (mask
);
1124 jme_alloc_and_feed_skb(jme
, i
);
1127 i
= (i
+ desccnt
) & (mask
);
1131 atomic_set(&rxring
->next_to_clean
, i
);
1134 atomic_inc(&jme
->rx_cleaning
);
1136 return limit
> 0 ? limit
: 0;
1141 jme_attempt_pcc(struct dynpcc_info
*dpi
, int atmp
)
1143 if (likely(atmp
== dpi
->cur
)) {
1148 if (dpi
->attempt
== atmp
) {
1151 dpi
->attempt
= atmp
;
1158 jme_dynamic_pcc(struct jme_adapter
*jme
)
1160 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
1162 if ((NET_STAT(jme
).rx_bytes
- dpi
->last_bytes
) > PCC_P3_THRESHOLD
)
1163 jme_attempt_pcc(dpi
, PCC_P3
);
1164 else if ((NET_STAT(jme
).rx_packets
- dpi
->last_pkts
) > PCC_P2_THRESHOLD
||
1165 dpi
->intr_cnt
> PCC_INTR_THRESHOLD
)
1166 jme_attempt_pcc(dpi
, PCC_P2
);
1168 jme_attempt_pcc(dpi
, PCC_P1
);
1170 if (unlikely(dpi
->attempt
!= dpi
->cur
&& dpi
->cnt
> 5)) {
1171 if (dpi
->attempt
< dpi
->cur
)
1172 tasklet_schedule(&jme
->rxclean_task
);
1173 jme_set_rx_pcc(jme
, dpi
->attempt
);
1174 dpi
->cur
= dpi
->attempt
;
1180 jme_start_pcc_timer(struct jme_adapter
*jme
)
1182 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1183 dpi
->last_bytes
= NET_STAT(jme
).rx_bytes
;
1184 dpi
->last_pkts
= NET_STAT(jme
).rx_packets
;
1186 jwrite32(jme
, JME_TMCSR
,
1187 TMCSR_EN
| ((0xFFFFFF - PCC_INTERVAL_US
) & TMCSR_CNT
));
1191 jme_stop_pcc_timer(struct jme_adapter
*jme
)
1193 jwrite32(jme
, JME_TMCSR
, 0);
1197 jme_shutdown_nic(struct jme_adapter
*jme
)
1201 phylink
= jme_linkstat_from_phy(jme
);
1203 if (!(phylink
& PHY_LINK_UP
)) {
1205 * Disable all interrupt before issue timer
1208 jwrite32(jme
, JME_TIMER2
, TMCSR_EN
| 0xFFFFFE);
1213 jme_pcc_tasklet(unsigned long arg
)
1215 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1216 struct net_device
*netdev
= jme
->dev
;
1218 if (unlikely(test_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
))) {
1219 jme_shutdown_nic(jme
);
1223 if (unlikely(!netif_carrier_ok(netdev
) ||
1224 (atomic_read(&jme
->link_changing
) != 1)
1226 jme_stop_pcc_timer(jme
);
1230 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
1231 jme_dynamic_pcc(jme
);
1233 jme_start_pcc_timer(jme
);
1237 jme_polling_mode(struct jme_adapter
*jme
)
1239 jme_set_rx_pcc(jme
, PCC_OFF
);
1243 jme_interrupt_mode(struct jme_adapter
*jme
)
1245 jme_set_rx_pcc(jme
, PCC_P1
);
1249 jme_pseudo_hotplug_enabled(struct jme_adapter
*jme
)
1252 apmc
= jread32(jme
, JME_APMC
);
1253 return apmc
& JME_APMC_PSEUDO_HP_EN
;
1257 jme_start_shutdown_timer(struct jme_adapter
*jme
)
1261 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PCIE_SD_EN
;
1262 apmc
&= ~JME_APMC_EPIEN_CTRL
;
1264 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_EN
);
1267 jwrite32f(jme
, JME_APMC
, apmc
);
1269 jwrite32f(jme
, JME_TIMER2
, 0);
1270 set_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1271 jwrite32(jme
, JME_TMCSR
,
1272 TMCSR_EN
| ((0xFFFFFF - APMC_PHP_SHUTDOWN_DELAY
) & TMCSR_CNT
));
1276 jme_stop_shutdown_timer(struct jme_adapter
*jme
)
1280 jwrite32f(jme
, JME_TMCSR
, 0);
1281 jwrite32f(jme
, JME_TIMER2
, 0);
1282 clear_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1284 apmc
= jread32(jme
, JME_APMC
);
1285 apmc
&= ~(JME_APMC_PCIE_SD_EN
| JME_APMC_EPIEN_CTRL
);
1286 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_DIS
);
1288 jwrite32f(jme
, JME_APMC
, apmc
);
1292 jme_link_change_tasklet(unsigned long arg
)
1294 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1295 struct net_device
*netdev
= jme
->dev
;
1298 while (!atomic_dec_and_test(&jme
->link_changing
)) {
1299 atomic_inc(&jme
->link_changing
);
1300 netif_info(jme
, intr
, jme
->dev
, "Get link change lock failed\n");
1301 while (atomic_read(&jme
->link_changing
) != 1)
1302 netif_info(jme
, intr
, jme
->dev
, "Waiting link change lock\n");
1305 if (jme_check_link(netdev
, 1) && jme
->old_mtu
== netdev
->mtu
)
1308 jme
->old_mtu
= netdev
->mtu
;
1309 netif_stop_queue(netdev
);
1310 if (jme_pseudo_hotplug_enabled(jme
))
1311 jme_stop_shutdown_timer(jme
);
1313 jme_stop_pcc_timer(jme
);
1314 tasklet_disable(&jme
->txclean_task
);
1315 tasklet_disable(&jme
->rxclean_task
);
1316 tasklet_disable(&jme
->rxempty_task
);
1318 if (netif_carrier_ok(netdev
)) {
1319 jme_disable_rx_engine(jme
);
1320 jme_disable_tx_engine(jme
);
1321 jme_reset_mac_processor(jme
);
1322 jme_free_rx_resources(jme
);
1323 jme_free_tx_resources(jme
);
1325 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1326 jme_polling_mode(jme
);
1328 netif_carrier_off(netdev
);
1331 jme_check_link(netdev
, 0);
1332 if (netif_carrier_ok(netdev
)) {
1333 rc
= jme_setup_rx_resources(jme
);
1335 pr_err("Allocating resources for RX error, Device STOPPED!\n");
1336 goto out_enable_tasklet
;
1339 rc
= jme_setup_tx_resources(jme
);
1341 pr_err("Allocating resources for TX error, Device STOPPED!\n");
1342 goto err_out_free_rx_resources
;
1345 jme_enable_rx_engine(jme
);
1346 jme_enable_tx_engine(jme
);
1348 netif_start_queue(netdev
);
1350 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1351 jme_interrupt_mode(jme
);
1353 jme_start_pcc_timer(jme
);
1354 } else if (jme_pseudo_hotplug_enabled(jme
)) {
1355 jme_start_shutdown_timer(jme
);
1358 goto out_enable_tasklet
;
1360 err_out_free_rx_resources
:
1361 jme_free_rx_resources(jme
);
1363 tasklet_enable(&jme
->txclean_task
);
1364 tasklet_hi_enable(&jme
->rxclean_task
);
1365 tasklet_hi_enable(&jme
->rxempty_task
);
1367 atomic_inc(&jme
->link_changing
);
1371 jme_rx_clean_tasklet(unsigned long arg
)
1373 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1374 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1376 jme_process_receive(jme
, jme
->rx_ring_size
);
1382 jme_poll(JME_NAPI_HOLDER(holder
), JME_NAPI_WEIGHT(budget
))
1384 struct jme_adapter
*jme
= jme_napi_priv(holder
);
1387 rest
= jme_process_receive(jme
, JME_NAPI_WEIGHT_VAL(budget
));
1389 while (atomic_read(&jme
->rx_empty
) > 0) {
1390 atomic_dec(&jme
->rx_empty
);
1391 ++(NET_STAT(jme
).rx_dropped
);
1392 jme_restart_rx_engine(jme
);
1394 atomic_inc(&jme
->rx_empty
);
1397 JME_RX_COMPLETE(netdev
, holder
);
1398 jme_interrupt_mode(jme
);
1401 JME_NAPI_WEIGHT_SET(budget
, rest
);
1402 return JME_NAPI_WEIGHT_VAL(budget
) - rest
;
1406 jme_rx_empty_tasklet(unsigned long arg
)
1408 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1410 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1413 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1416 netif_info(jme
, rx_status
, jme
->dev
, "RX Queue Full!\n");
1418 jme_rx_clean_tasklet(arg
);
1420 while (atomic_read(&jme
->rx_empty
) > 0) {
1421 atomic_dec(&jme
->rx_empty
);
1422 ++(NET_STAT(jme
).rx_dropped
);
1423 jme_restart_rx_engine(jme
);
1425 atomic_inc(&jme
->rx_empty
);
1429 jme_wake_queue_if_stopped(struct jme_adapter
*jme
)
1431 struct jme_ring
*txring
= &(jme
->txring
[0]);
1434 if (unlikely(netif_queue_stopped(jme
->dev
) &&
1435 atomic_read(&txring
->nr_free
) >= (jme
->tx_wake_threshold
))) {
1436 netif_info(jme
, tx_done
, jme
->dev
, "TX Queue Waked\n");
1437 netif_wake_queue(jme
->dev
);
1443 jme_tx_clean_tasklet(unsigned long arg
)
1445 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1446 struct jme_ring
*txring
= &(jme
->txring
[0]);
1447 struct txdesc
*txdesc
= txring
->desc
;
1448 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
, *ttxbi
;
1449 int i
, j
, cnt
= 0, max
, err
, mask
;
1451 tx_dbg(jme
, "Into txclean\n");
1453 if (unlikely(!atomic_dec_and_test(&jme
->tx_cleaning
)))
1456 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1459 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1462 max
= jme
->tx_ring_size
- atomic_read(&txring
->nr_free
);
1463 mask
= jme
->tx_ring_mask
;
1465 for (i
= atomic_read(&txring
->next_to_clean
) ; cnt
< max
; ) {
1469 if (likely(ctxbi
->skb
&&
1470 !(txdesc
[i
].descwb
.flags
& TXWBFLAG_OWN
))) {
1472 tx_dbg(jme
, "txclean: %d+%d@%lu\n",
1473 i
, ctxbi
->nr_desc
, jiffies
);
1475 err
= txdesc
[i
].descwb
.flags
& TXWBFLAG_ALLERR
;
1477 for (j
= 1 ; j
< ctxbi
->nr_desc
; ++j
) {
1478 ttxbi
= txbi
+ ((i
+ j
) & (mask
));
1479 txdesc
[(i
+ j
) & (mask
)].dw
[0] = 0;
1481 pci_unmap_page(jme
->pdev
,
1490 dev_kfree_skb(ctxbi
->skb
);
1492 cnt
+= ctxbi
->nr_desc
;
1494 if (unlikely(err
)) {
1495 ++(NET_STAT(jme
).tx_carrier_errors
);
1497 ++(NET_STAT(jme
).tx_packets
);
1498 NET_STAT(jme
).tx_bytes
+= ctxbi
->len
;
1503 ctxbi
->start_xmit
= 0;
1509 i
= (i
+ ctxbi
->nr_desc
) & mask
;
1514 tx_dbg(jme
, "txclean: done %d@%lu\n", i
, jiffies
);
1515 atomic_set(&txring
->next_to_clean
, i
);
1516 atomic_add(cnt
, &txring
->nr_free
);
1518 jme_wake_queue_if_stopped(jme
);
1521 atomic_inc(&jme
->tx_cleaning
);
1525 jme_intr_msi(struct jme_adapter
*jme
, u32 intrstat
)
1530 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
1532 if (intrstat
& (INTR_LINKCH
| INTR_SWINTR
)) {
1534 * Link change event is critical
1535 * all other events are ignored
1537 jwrite32(jme
, JME_IEVE
, intrstat
);
1538 tasklet_schedule(&jme
->linkch_task
);
1542 if (intrstat
& INTR_TMINTR
) {
1543 jwrite32(jme
, JME_IEVE
, INTR_TMINTR
);
1544 tasklet_schedule(&jme
->pcc_task
);
1547 if (intrstat
& (INTR_PCCTXTO
| INTR_PCCTX
)) {
1548 jwrite32(jme
, JME_IEVE
, INTR_PCCTXTO
| INTR_PCCTX
| INTR_TX0
);
1549 tasklet_schedule(&jme
->txclean_task
);
1552 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1553 jwrite32(jme
, JME_IEVE
, (intrstat
& (INTR_PCCRX0TO
|
1559 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
1560 if (intrstat
& INTR_RX0EMP
)
1561 atomic_inc(&jme
->rx_empty
);
1563 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1564 if (likely(JME_RX_SCHEDULE_PREP(jme
))) {
1565 jme_polling_mode(jme
);
1566 JME_RX_SCHEDULE(jme
);
1570 if (intrstat
& INTR_RX0EMP
) {
1571 atomic_inc(&jme
->rx_empty
);
1572 tasklet_hi_schedule(&jme
->rxempty_task
);
1573 } else if (intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
)) {
1574 tasklet_hi_schedule(&jme
->rxclean_task
);
1580 * Re-enable interrupt
1582 jwrite32f(jme
, JME_IENS
, INTR_ENABLE
);
1586 jme_intr(int irq
, void *dev_id
)
1588 struct net_device
*netdev
= dev_id
;
1589 struct jme_adapter
*jme
= netdev_priv(netdev
);
1592 intrstat
= jread32(jme
, JME_IEVE
);
1595 * Check if it's really an interrupt for us
1597 if (unlikely((intrstat
& INTR_ENABLE
) == 0))
1601 * Check if the device still exist
1603 if (unlikely(intrstat
== ~((typeof(intrstat
))0)))
1606 jme_intr_msi(jme
, intrstat
);
1612 jme_msi(int irq
, void *dev_id
)
1614 struct net_device
*netdev
= dev_id
;
1615 struct jme_adapter
*jme
= netdev_priv(netdev
);
1618 intrstat
= jread32(jme
, JME_IEVE
);
1620 jme_intr_msi(jme
, intrstat
);
1626 jme_reset_link(struct jme_adapter
*jme
)
1628 jwrite32(jme
, JME_TMCSR
, TMCSR_SWIT
);
1632 jme_restart_an(struct jme_adapter
*jme
)
1636 spin_lock_bh(&jme
->phy_lock
);
1637 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1638 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1639 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1640 spin_unlock_bh(&jme
->phy_lock
);
1644 jme_request_irq(struct jme_adapter
*jme
)
1647 struct net_device
*netdev
= jme
->dev
;
1648 irq_handler_t handler
= jme_intr
;
1649 int irq_flags
= IRQF_SHARED
;
1651 if (!pci_enable_msi(jme
->pdev
)) {
1652 set_bit(JME_FLAG_MSI
, &jme
->flags
);
1657 rc
= request_irq(jme
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
1661 "Unable to request %s interrupt (return: %d)\n",
1662 test_bit(JME_FLAG_MSI
, &jme
->flags
) ? "MSI" : "INTx",
1665 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1666 pci_disable_msi(jme
->pdev
);
1667 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1670 netdev
->irq
= jme
->pdev
->irq
;
1677 jme_free_irq(struct jme_adapter
*jme
)
1679 free_irq(jme
->pdev
->irq
, jme
->dev
);
1680 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1681 pci_disable_msi(jme
->pdev
);
1682 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1683 jme
->dev
->irq
= jme
->pdev
->irq
;
1688 jme_new_phy_on(struct jme_adapter
*jme
)
1692 reg
= jread32(jme
, JME_PHY_PWR
);
1693 reg
&= ~(PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1694 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
);
1695 jwrite32(jme
, JME_PHY_PWR
, reg
);
1697 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1698 reg
&= ~PE1_GPREG0_PBG
;
1699 reg
|= PE1_GPREG0_ENBG
;
1700 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1704 jme_new_phy_off(struct jme_adapter
*jme
)
1708 reg
= jread32(jme
, JME_PHY_PWR
);
1709 reg
|= PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1710 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
;
1711 jwrite32(jme
, JME_PHY_PWR
, reg
);
1713 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1714 reg
&= ~PE1_GPREG0_PBG
;
1715 reg
|= PE1_GPREG0_PDD3COLD
;
1716 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1720 jme_phy_on(struct jme_adapter
*jme
)
1724 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1725 bmcr
&= ~BMCR_PDOWN
;
1726 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1728 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1729 jme_new_phy_on(jme
);
1733 jme_phy_off(struct jme_adapter
*jme
)
1737 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1739 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1741 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1742 jme_new_phy_off(jme
);
1746 jme_open(struct net_device
*netdev
)
1748 struct jme_adapter
*jme
= netdev_priv(netdev
);
1752 JME_NAPI_ENABLE(jme
);
1754 tasklet_enable(&jme
->linkch_task
);
1755 tasklet_enable(&jme
->txclean_task
);
1756 tasklet_hi_enable(&jme
->rxclean_task
);
1757 tasklet_hi_enable(&jme
->rxempty_task
);
1759 rc
= jme_request_irq(jme
);
1766 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
1767 jme_set_settings(netdev
, &jme
->old_ecmd
);
1769 jme_reset_phy_processor(jme
);
1771 jme_reset_link(jme
);
1776 netif_stop_queue(netdev
);
1777 netif_carrier_off(netdev
);
1782 jme_set_100m_half(struct jme_adapter
*jme
)
1787 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1788 tmp
= bmcr
& ~(BMCR_ANENABLE
| BMCR_SPEED100
|
1789 BMCR_SPEED1000
| BMCR_FULLDPLX
);
1790 tmp
|= BMCR_SPEED100
;
1793 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, tmp
);
1796 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
| GHC_LINK_POLL
);
1798 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
);
1801 #define JME_WAIT_LINK_TIME 2000 /* 2000ms */
1803 jme_wait_link(struct jme_adapter
*jme
)
1805 u32 phylink
, to
= JME_WAIT_LINK_TIME
;
1808 phylink
= jme_linkstat_from_phy(jme
);
1809 while (!(phylink
& PHY_LINK_UP
) && (to
-= 10) > 0) {
1811 phylink
= jme_linkstat_from_phy(jme
);
1816 jme_powersave_phy(struct jme_adapter
*jme
)
1818 if (jme
->reg_pmcs
) {
1819 jme_set_100m_half(jme
);
1821 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
1824 jwrite32(jme
, JME_PMCS
, jme
->reg_pmcs
);
1831 jme_close(struct net_device
*netdev
)
1833 struct jme_adapter
*jme
= netdev_priv(netdev
);
1835 netif_stop_queue(netdev
);
1836 netif_carrier_off(netdev
);
1841 JME_NAPI_DISABLE(jme
);
1843 tasklet_disable(&jme
->linkch_task
);
1844 tasklet_disable(&jme
->txclean_task
);
1845 tasklet_disable(&jme
->rxclean_task
);
1846 tasklet_disable(&jme
->rxempty_task
);
1848 jme_disable_rx_engine(jme
);
1849 jme_disable_tx_engine(jme
);
1850 jme_reset_mac_processor(jme
);
1851 jme_free_rx_resources(jme
);
1852 jme_free_tx_resources(jme
);
1860 jme_alloc_txdesc(struct jme_adapter
*jme
,
1861 struct sk_buff
*skb
)
1863 struct jme_ring
*txring
= &(jme
->txring
[0]);
1864 int idx
, nr_alloc
, mask
= jme
->tx_ring_mask
;
1866 idx
= txring
->next_to_use
;
1867 nr_alloc
= skb_shinfo(skb
)->nr_frags
+ 2;
1869 if (unlikely(atomic_read(&txring
->nr_free
) < nr_alloc
))
1872 atomic_sub(nr_alloc
, &txring
->nr_free
);
1874 txring
->next_to_use
= (txring
->next_to_use
+ nr_alloc
) & mask
;
1880 jme_fill_tx_map(struct pci_dev
*pdev
,
1881 struct txdesc
*txdesc
,
1882 struct jme_buffer_info
*txbi
,
1890 dmaaddr
= pci_map_page(pdev
,
1896 pci_dma_sync_single_for_device(pdev
,
1903 txdesc
->desc2
.flags
= TXFLAG_OWN
;
1904 txdesc
->desc2
.flags
|= (hidma
) ? TXFLAG_64BIT
: 0;
1905 txdesc
->desc2
.datalen
= cpu_to_le16(len
);
1906 txdesc
->desc2
.bufaddrh
= cpu_to_le32((__u64
)dmaaddr
>> 32);
1907 txdesc
->desc2
.bufaddrl
= cpu_to_le32(
1908 (__u64
)dmaaddr
& 0xFFFFFFFFUL
);
1910 txbi
->mapping
= dmaaddr
;
1915 jme_map_tx_skb(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
1917 struct jme_ring
*txring
= &(jme
->txring
[0]);
1918 struct txdesc
*txdesc
= txring
->desc
, *ctxdesc
;
1919 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
;
1920 u8 hidma
= jme
->dev
->features
& NETIF_F_HIGHDMA
;
1921 int i
, nr_frags
= skb_shinfo(skb
)->nr_frags
;
1922 int mask
= jme
->tx_ring_mask
;
1923 struct skb_frag_struct
*frag
;
1926 for (i
= 0 ; i
< nr_frags
; ++i
) {
1927 frag
= &skb_shinfo(skb
)->frags
[i
];
1928 ctxdesc
= txdesc
+ ((idx
+ i
+ 2) & (mask
));
1929 ctxbi
= txbi
+ ((idx
+ i
+ 2) & (mask
));
1931 jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
, frag
->page
,
1932 frag
->page_offset
, frag
->size
, hidma
);
1935 len
= skb_is_nonlinear(skb
) ? skb_headlen(skb
) : skb
->len
;
1936 ctxdesc
= txdesc
+ ((idx
+ 1) & (mask
));
1937 ctxbi
= txbi
+ ((idx
+ 1) & (mask
));
1938 jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
, virt_to_page(skb
->data
),
1939 offset_in_page(skb
->data
), len
, hidma
);
1944 jme_expand_header(struct jme_adapter
*jme
, struct sk_buff
*skb
)
1946 if (unlikely(skb_shinfo(skb
)->gso_size
&&
1947 skb_header_cloned(skb
) &&
1948 pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
))) {
1957 jme_tx_tso(struct sk_buff
*skb
, __le16
*mss
, u8
*flags
)
1959 *mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
<< TXDESC_MSS_SHIFT
);
1961 *flags
|= TXFLAG_LSEN
;
1963 if (skb
->protocol
== htons(ETH_P_IP
)) {
1964 struct iphdr
*iph
= ip_hdr(skb
);
1967 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
1972 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
1974 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ip6h
->saddr
,
1987 jme_tx_csum(struct jme_adapter
*jme
, struct sk_buff
*skb
, u8
*flags
)
1989 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1992 switch (skb
->protocol
) {
1993 case htons(ETH_P_IP
):
1994 ip_proto
= ip_hdr(skb
)->protocol
;
1996 case htons(ETH_P_IPV6
):
1997 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
2006 *flags
|= TXFLAG_TCPCS
;
2009 *flags
|= TXFLAG_UDPCS
;
2012 netif_err(jme
, tx_err
, jme
->dev
, "Error upper layer protocol\n");
2019 jme_tx_vlan(struct sk_buff
*skb
, __le16
*vlan
, u8
*flags
)
2021 if (vlan_tx_tag_present(skb
)) {
2022 *flags
|= TXFLAG_TAGON
;
2023 *vlan
= cpu_to_le16(vlan_tx_tag_get(skb
));
2028 jme_fill_tx_desc(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
2030 struct jme_ring
*txring
= &(jme
->txring
[0]);
2031 struct txdesc
*txdesc
;
2032 struct jme_buffer_info
*txbi
;
2035 txdesc
= (struct txdesc
*)txring
->desc
+ idx
;
2036 txbi
= txring
->bufinf
+ idx
;
2042 txdesc
->desc1
.pktsize
= cpu_to_le16(skb
->len
);
2044 * Set OWN bit at final.
2045 * When kernel transmit faster than NIC.
2046 * And NIC trying to send this descriptor before we tell
2047 * it to start sending this TX queue.
2048 * Other fields are already filled correctly.
2051 flags
= TXFLAG_OWN
| TXFLAG_INT
;
2053 * Set checksum flags while not tso
2055 if (jme_tx_tso(skb
, &txdesc
->desc1
.mss
, &flags
))
2056 jme_tx_csum(jme
, skb
, &flags
);
2057 jme_tx_vlan(skb
, &txdesc
->desc1
.vlan
, &flags
);
2058 jme_map_tx_skb(jme
, skb
, idx
);
2059 txdesc
->desc1
.flags
= flags
;
2061 * Set tx buffer info after telling NIC to send
2062 * For better tx_clean timing
2065 txbi
->nr_desc
= skb_shinfo(skb
)->nr_frags
+ 2;
2067 txbi
->len
= skb
->len
;
2068 txbi
->start_xmit
= jiffies
;
2069 if (!txbi
->start_xmit
)
2070 txbi
->start_xmit
= (0UL-1);
2076 jme_stop_queue_if_full(struct jme_adapter
*jme
)
2078 struct jme_ring
*txring
= &(jme
->txring
[0]);
2079 struct jme_buffer_info
*txbi
= txring
->bufinf
;
2080 int idx
= atomic_read(&txring
->next_to_clean
);
2085 if (unlikely(atomic_read(&txring
->nr_free
) < (MAX_SKB_FRAGS
+2))) {
2086 netif_stop_queue(jme
->dev
);
2087 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Paused\n");
2089 if (atomic_read(&txring
->nr_free
)
2090 >= (jme
->tx_wake_threshold
)) {
2091 netif_wake_queue(jme
->dev
);
2092 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Fast Waked\n");
2096 if (unlikely(txbi
->start_xmit
&&
2097 (jiffies
- txbi
->start_xmit
) >= TX_TIMEOUT
&&
2099 netif_stop_queue(jme
->dev
);
2100 netif_info(jme
, tx_queued
, jme
->dev
,
2101 "TX Queue Stopped %d@%lu\n", idx
, jiffies
);
2106 * This function is already protected by netif_tx_lock()
2110 jme_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
2112 struct jme_adapter
*jme
= netdev_priv(netdev
);
2115 if (unlikely(jme_expand_header(jme
, skb
))) {
2116 ++(NET_STAT(jme
).tx_dropped
);
2117 return NETDEV_TX_OK
;
2120 idx
= jme_alloc_txdesc(jme
, skb
);
2122 if (unlikely(idx
< 0)) {
2123 netif_stop_queue(netdev
);
2124 netif_err(jme
, tx_err
, jme
->dev
,
2125 "BUG! Tx ring full when queue awake!\n");
2127 return NETDEV_TX_BUSY
;
2130 jme_fill_tx_desc(jme
, skb
, idx
);
2132 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
2133 TXCS_SELECT_QUEUE0
|
2137 tx_dbg(jme
, "xmit: %d+%d@%lu\n",
2138 idx
, skb_shinfo(skb
)->nr_frags
+ 2, jiffies
);
2139 jme_stop_queue_if_full(jme
);
2141 return NETDEV_TX_OK
;
2145 jme_set_unicastaddr(struct net_device
*netdev
)
2147 struct jme_adapter
*jme
= netdev_priv(netdev
);
2150 val
= (netdev
->dev_addr
[3] & 0xff) << 24 |
2151 (netdev
->dev_addr
[2] & 0xff) << 16 |
2152 (netdev
->dev_addr
[1] & 0xff) << 8 |
2153 (netdev
->dev_addr
[0] & 0xff);
2154 jwrite32(jme
, JME_RXUMA_LO
, val
);
2155 val
= (netdev
->dev_addr
[5] & 0xff) << 8 |
2156 (netdev
->dev_addr
[4] & 0xff);
2157 jwrite32(jme
, JME_RXUMA_HI
, val
);
2161 jme_set_macaddr(struct net_device
*netdev
, void *p
)
2163 struct jme_adapter
*jme
= netdev_priv(netdev
);
2164 struct sockaddr
*addr
= p
;
2166 if (netif_running(netdev
))
2169 spin_lock_bh(&jme
->macaddr_lock
);
2170 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2171 jme_set_unicastaddr(netdev
);
2172 spin_unlock_bh(&jme
->macaddr_lock
);
2178 jme_set_multi(struct net_device
*netdev
)
2180 struct jme_adapter
*jme
= netdev_priv(netdev
);
2181 u32 mc_hash
[2] = {};
2183 spin_lock_bh(&jme
->rxmcs_lock
);
2185 jme
->reg_rxmcs
|= RXMCS_BRDFRAME
| RXMCS_UNIFRAME
;
2187 if (netdev
->flags
& IFF_PROMISC
) {
2188 jme
->reg_rxmcs
|= RXMCS_ALLFRAME
;
2189 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2190 jme
->reg_rxmcs
|= RXMCS_ALLMULFRAME
;
2191 } else if (netdev
->flags
& IFF_MULTICAST
) {
2192 struct netdev_hw_addr
*ha
;
2195 jme
->reg_rxmcs
|= RXMCS_MULFRAME
| RXMCS_MULFILTERED
;
2196 netdev_for_each_mc_addr(ha
, netdev
) {
2197 bit_nr
= ether_crc(ETH_ALEN
, ha
->addr
) & 0x3F;
2198 mc_hash
[bit_nr
>> 5] |= 1 << (bit_nr
& 0x1F);
2201 jwrite32(jme
, JME_RXMCHT_LO
, mc_hash
[0]);
2202 jwrite32(jme
, JME_RXMCHT_HI
, mc_hash
[1]);
2206 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2208 spin_unlock_bh(&jme
->rxmcs_lock
);
2212 jme_change_mtu(struct net_device
*netdev
, int new_mtu
)
2214 struct jme_adapter
*jme
= netdev_priv(netdev
);
2216 if (new_mtu
== jme
->old_mtu
)
2219 if (((new_mtu
+ ETH_HLEN
) > MAX_ETHERNET_JUMBO_PACKET_SIZE
) ||
2220 ((new_mtu
) < IPV6_MIN_MTU
))
2223 if (new_mtu
> 4000) {
2224 jme
->reg_rxcs
&= ~RXCS_FIFOTHNP
;
2225 jme
->reg_rxcs
|= RXCS_FIFOTHNP_64QW
;
2226 jme_restart_rx_engine(jme
);
2228 jme
->reg_rxcs
&= ~RXCS_FIFOTHNP
;
2229 jme
->reg_rxcs
|= RXCS_FIFOTHNP_128QW
;
2230 jme_restart_rx_engine(jme
);
2233 netdev
->mtu
= new_mtu
;
2234 netdev_update_features(netdev
);
2236 jme_reset_link(jme
);
2242 jme_tx_timeout(struct net_device
*netdev
)
2244 struct jme_adapter
*jme
= netdev_priv(netdev
);
2247 jme_reset_phy_processor(jme
);
2248 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
2249 jme_set_settings(netdev
, &jme
->old_ecmd
);
2252 * Force to Reset the link again
2254 jme_reset_link(jme
);
2257 static inline void jme_pause_rx(struct jme_adapter
*jme
)
2259 atomic_dec(&jme
->link_changing
);
2261 jme_set_rx_pcc(jme
, PCC_OFF
);
2262 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2263 JME_NAPI_DISABLE(jme
);
2265 tasklet_disable(&jme
->rxclean_task
);
2266 tasklet_disable(&jme
->rxempty_task
);
2270 static inline void jme_resume_rx(struct jme_adapter
*jme
)
2272 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2274 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2275 JME_NAPI_ENABLE(jme
);
2277 tasklet_hi_enable(&jme
->rxclean_task
);
2278 tasklet_hi_enable(&jme
->rxempty_task
);
2281 dpi
->attempt
= PCC_P1
;
2283 jme_set_rx_pcc(jme
, PCC_P1
);
2285 atomic_inc(&jme
->link_changing
);
2289 jme_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
2291 struct jme_adapter
*jme
= netdev_priv(netdev
);
2299 jme_get_drvinfo(struct net_device
*netdev
,
2300 struct ethtool_drvinfo
*info
)
2302 struct jme_adapter
*jme
= netdev_priv(netdev
);
2304 strcpy(info
->driver
, DRV_NAME
);
2305 strcpy(info
->version
, DRV_VERSION
);
2306 strcpy(info
->bus_info
, pci_name(jme
->pdev
));
2310 jme_get_regs_len(struct net_device
*netdev
)
2316 mmapio_memcpy(struct jme_adapter
*jme
, u32
*p
, u32 reg
, int len
)
2320 for (i
= 0 ; i
< len
; i
+= 4)
2321 p
[i
>> 2] = jread32(jme
, reg
+ i
);
2325 mdio_memcpy(struct jme_adapter
*jme
, u32
*p
, int reg_nr
)
2328 u16
*p16
= (u16
*)p
;
2330 for (i
= 0 ; i
< reg_nr
; ++i
)
2331 p16
[i
] = jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, i
);
2335 jme_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
2337 struct jme_adapter
*jme
= netdev_priv(netdev
);
2338 u32
*p32
= (u32
*)p
;
2340 memset(p
, 0xFF, JME_REG_LEN
);
2343 mmapio_memcpy(jme
, p32
, JME_MAC
, JME_MAC_LEN
);
2346 mmapio_memcpy(jme
, p32
, JME_PHY
, JME_PHY_LEN
);
2349 mmapio_memcpy(jme
, p32
, JME_MISC
, JME_MISC_LEN
);
2352 mmapio_memcpy(jme
, p32
, JME_RSS
, JME_RSS_LEN
);
2355 mdio_memcpy(jme
, p32
, JME_PHY_REG_NR
);
2359 jme_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2361 struct jme_adapter
*jme
= netdev_priv(netdev
);
2363 ecmd
->tx_coalesce_usecs
= PCC_TX_TO
;
2364 ecmd
->tx_max_coalesced_frames
= PCC_TX_CNT
;
2366 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2367 ecmd
->use_adaptive_rx_coalesce
= false;
2368 ecmd
->rx_coalesce_usecs
= 0;
2369 ecmd
->rx_max_coalesced_frames
= 0;
2373 ecmd
->use_adaptive_rx_coalesce
= true;
2375 switch (jme
->dpi
.cur
) {
2377 ecmd
->rx_coalesce_usecs
= PCC_P1_TO
;
2378 ecmd
->rx_max_coalesced_frames
= PCC_P1_CNT
;
2381 ecmd
->rx_coalesce_usecs
= PCC_P2_TO
;
2382 ecmd
->rx_max_coalesced_frames
= PCC_P2_CNT
;
2385 ecmd
->rx_coalesce_usecs
= PCC_P3_TO
;
2386 ecmd
->rx_max_coalesced_frames
= PCC_P3_CNT
;
2396 jme_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2398 struct jme_adapter
*jme
= netdev_priv(netdev
);
2399 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2401 if (netif_running(netdev
))
2404 if (ecmd
->use_adaptive_rx_coalesce
&&
2405 test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2406 clear_bit(JME_FLAG_POLL
, &jme
->flags
);
2407 jme
->jme_rx
= netif_rx
;
2408 jme
->jme_vlan_rx
= vlan_hwaccel_rx
;
2410 dpi
->attempt
= PCC_P1
;
2412 jme_set_rx_pcc(jme
, PCC_P1
);
2413 jme_interrupt_mode(jme
);
2414 } else if (!(ecmd
->use_adaptive_rx_coalesce
) &&
2415 !(test_bit(JME_FLAG_POLL
, &jme
->flags
))) {
2416 set_bit(JME_FLAG_POLL
, &jme
->flags
);
2417 jme
->jme_rx
= netif_receive_skb
;
2418 jme
->jme_vlan_rx
= vlan_hwaccel_receive_skb
;
2419 jme_interrupt_mode(jme
);
2426 jme_get_pauseparam(struct net_device
*netdev
,
2427 struct ethtool_pauseparam
*ecmd
)
2429 struct jme_adapter
*jme
= netdev_priv(netdev
);
2432 ecmd
->tx_pause
= (jme
->reg_txpfc
& TXPFC_PF_EN
) != 0;
2433 ecmd
->rx_pause
= (jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0;
2435 spin_lock_bh(&jme
->phy_lock
);
2436 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2437 spin_unlock_bh(&jme
->phy_lock
);
2440 (val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0;
2444 jme_set_pauseparam(struct net_device
*netdev
,
2445 struct ethtool_pauseparam
*ecmd
)
2447 struct jme_adapter
*jme
= netdev_priv(netdev
);
2450 if (((jme
->reg_txpfc
& TXPFC_PF_EN
) != 0) ^
2451 (ecmd
->tx_pause
!= 0)) {
2454 jme
->reg_txpfc
|= TXPFC_PF_EN
;
2456 jme
->reg_txpfc
&= ~TXPFC_PF_EN
;
2458 jwrite32(jme
, JME_TXPFC
, jme
->reg_txpfc
);
2461 spin_lock_bh(&jme
->rxmcs_lock
);
2462 if (((jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0) ^
2463 (ecmd
->rx_pause
!= 0)) {
2466 jme
->reg_rxmcs
|= RXMCS_FLOWCTRL
;
2468 jme
->reg_rxmcs
&= ~RXMCS_FLOWCTRL
;
2470 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2472 spin_unlock_bh(&jme
->rxmcs_lock
);
2474 spin_lock_bh(&jme
->phy_lock
);
2475 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2476 if (((val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0) ^
2477 (ecmd
->autoneg
!= 0)) {
2480 val
|= (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2482 val
&= ~(ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2484 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
,
2485 MII_ADVERTISE
, val
);
2487 spin_unlock_bh(&jme
->phy_lock
);
2493 jme_get_wol(struct net_device
*netdev
,
2494 struct ethtool_wolinfo
*wol
)
2496 struct jme_adapter
*jme
= netdev_priv(netdev
);
2498 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
2502 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
2503 wol
->wolopts
|= WAKE_PHY
;
2505 if (jme
->reg_pmcs
& PMCS_MFEN
)
2506 wol
->wolopts
|= WAKE_MAGIC
;
2511 jme_set_wol(struct net_device
*netdev
,
2512 struct ethtool_wolinfo
*wol
)
2514 struct jme_adapter
*jme
= netdev_priv(netdev
);
2516 if (wol
->wolopts
& (WAKE_MAGICSECURE
|
2525 if (wol
->wolopts
& WAKE_PHY
)
2526 jme
->reg_pmcs
|= PMCS_LFEN
| PMCS_LREN
;
2528 if (wol
->wolopts
& WAKE_MAGIC
)
2529 jme
->reg_pmcs
|= PMCS_MFEN
;
2531 jwrite32(jme
, JME_PMCS
, jme
->reg_pmcs
);
2533 device_set_wakeup_enable(&jme
->pdev
->dev
, jme
->reg_pmcs
);
2539 jme_get_settings(struct net_device
*netdev
,
2540 struct ethtool_cmd
*ecmd
)
2542 struct jme_adapter
*jme
= netdev_priv(netdev
);
2545 spin_lock_bh(&jme
->phy_lock
);
2546 rc
= mii_ethtool_gset(&(jme
->mii_if
), ecmd
);
2547 spin_unlock_bh(&jme
->phy_lock
);
2552 jme_set_settings(struct net_device
*netdev
,
2553 struct ethtool_cmd
*ecmd
)
2555 struct jme_adapter
*jme
= netdev_priv(netdev
);
2558 if (ethtool_cmd_speed(ecmd
) == SPEED_1000
2559 && ecmd
->autoneg
!= AUTONEG_ENABLE
)
2563 * Check If user changed duplex only while force_media.
2564 * Hardware would not generate link change interrupt.
2566 if (jme
->mii_if
.force_media
&&
2567 ecmd
->autoneg
!= AUTONEG_ENABLE
&&
2568 (jme
->mii_if
.full_duplex
!= ecmd
->duplex
))
2571 spin_lock_bh(&jme
->phy_lock
);
2572 rc
= mii_ethtool_sset(&(jme
->mii_if
), ecmd
);
2573 spin_unlock_bh(&jme
->phy_lock
);
2577 jme_reset_link(jme
);
2578 jme
->old_ecmd
= *ecmd
;
2579 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2586 jme_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
2589 struct jme_adapter
*jme
= netdev_priv(netdev
);
2590 struct mii_ioctl_data
*mii_data
= if_mii(rq
);
2591 unsigned int duplex_chg
;
2593 if (cmd
== SIOCSMIIREG
) {
2594 u16 val
= mii_data
->val_in
;
2595 if (!(val
& (BMCR_RESET
|BMCR_ANENABLE
)) &&
2596 (val
& BMCR_SPEED1000
))
2600 spin_lock_bh(&jme
->phy_lock
);
2601 rc
= generic_mii_ioctl(&jme
->mii_if
, mii_data
, cmd
, &duplex_chg
);
2602 spin_unlock_bh(&jme
->phy_lock
);
2604 if (!rc
&& (cmd
== SIOCSMIIREG
)) {
2606 jme_reset_link(jme
);
2607 jme_get_settings(netdev
, &jme
->old_ecmd
);
2608 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2615 jme_get_link(struct net_device
*netdev
)
2617 struct jme_adapter
*jme
= netdev_priv(netdev
);
2618 return jread32(jme
, JME_PHY_LINK
) & PHY_LINK_UP
;
2622 jme_get_msglevel(struct net_device
*netdev
)
2624 struct jme_adapter
*jme
= netdev_priv(netdev
);
2625 return jme
->msg_enable
;
2629 jme_set_msglevel(struct net_device
*netdev
, u32 value
)
2631 struct jme_adapter
*jme
= netdev_priv(netdev
);
2632 jme
->msg_enable
= value
;
2636 jme_fix_features(struct net_device
*netdev
, u32 features
)
2638 if (netdev
->mtu
> 1900)
2639 features
&= ~(NETIF_F_ALL_TSO
| NETIF_F_ALL_CSUM
);
2644 jme_set_features(struct net_device
*netdev
, u32 features
)
2646 struct jme_adapter
*jme
= netdev_priv(netdev
);
2648 spin_lock_bh(&jme
->rxmcs_lock
);
2649 if (features
& NETIF_F_RXCSUM
)
2650 jme
->reg_rxmcs
|= RXMCS_CHECKSUM
;
2652 jme
->reg_rxmcs
&= ~RXMCS_CHECKSUM
;
2653 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2654 spin_unlock_bh(&jme
->rxmcs_lock
);
2660 jme_nway_reset(struct net_device
*netdev
)
2662 struct jme_adapter
*jme
= netdev_priv(netdev
);
2663 jme_restart_an(jme
);
2668 jme_smb_read(struct jme_adapter
*jme
, unsigned int addr
)
2673 val
= jread32(jme
, JME_SMBCSR
);
2674 to
= JME_SMB_BUSY_TIMEOUT
;
2675 while ((val
& SMBCSR_BUSY
) && --to
) {
2677 val
= jread32(jme
, JME_SMBCSR
);
2680 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2684 jwrite32(jme
, JME_SMBINTF
,
2685 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2686 SMBINTF_HWRWN_READ
|
2689 val
= jread32(jme
, JME_SMBINTF
);
2690 to
= JME_SMB_BUSY_TIMEOUT
;
2691 while ((val
& SMBINTF_HWCMD
) && --to
) {
2693 val
= jread32(jme
, JME_SMBINTF
);
2696 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2700 return (val
& SMBINTF_HWDATR
) >> SMBINTF_HWDATR_SHIFT
;
2704 jme_smb_write(struct jme_adapter
*jme
, unsigned int addr
, u8 data
)
2709 val
= jread32(jme
, JME_SMBCSR
);
2710 to
= JME_SMB_BUSY_TIMEOUT
;
2711 while ((val
& SMBCSR_BUSY
) && --to
) {
2713 val
= jread32(jme
, JME_SMBCSR
);
2716 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2720 jwrite32(jme
, JME_SMBINTF
,
2721 ((data
<< SMBINTF_HWDATW_SHIFT
) & SMBINTF_HWDATW
) |
2722 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2723 SMBINTF_HWRWN_WRITE
|
2726 val
= jread32(jme
, JME_SMBINTF
);
2727 to
= JME_SMB_BUSY_TIMEOUT
;
2728 while ((val
& SMBINTF_HWCMD
) && --to
) {
2730 val
= jread32(jme
, JME_SMBINTF
);
2733 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2741 jme_get_eeprom_len(struct net_device
*netdev
)
2743 struct jme_adapter
*jme
= netdev_priv(netdev
);
2745 val
= jread32(jme
, JME_SMBCSR
);
2746 return (val
& SMBCSR_EEPROMD
) ? JME_SMB_LEN
: 0;
2750 jme_get_eeprom(struct net_device
*netdev
,
2751 struct ethtool_eeprom
*eeprom
, u8
*data
)
2753 struct jme_adapter
*jme
= netdev_priv(netdev
);
2754 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2757 * ethtool will check the boundary for us
2759 eeprom
->magic
= JME_EEPROM_MAGIC
;
2760 for (i
= 0 ; i
< len
; ++i
)
2761 data
[i
] = jme_smb_read(jme
, i
+ offset
);
2767 jme_set_eeprom(struct net_device
*netdev
,
2768 struct ethtool_eeprom
*eeprom
, u8
*data
)
2770 struct jme_adapter
*jme
= netdev_priv(netdev
);
2771 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2773 if (eeprom
->magic
!= JME_EEPROM_MAGIC
)
2777 * ethtool will check the boundary for us
2779 for (i
= 0 ; i
< len
; ++i
)
2780 jme_smb_write(jme
, i
+ offset
, data
[i
]);
2785 static const struct ethtool_ops jme_ethtool_ops
= {
2786 .get_drvinfo
= jme_get_drvinfo
,
2787 .get_regs_len
= jme_get_regs_len
,
2788 .get_regs
= jme_get_regs
,
2789 .get_coalesce
= jme_get_coalesce
,
2790 .set_coalesce
= jme_set_coalesce
,
2791 .get_pauseparam
= jme_get_pauseparam
,
2792 .set_pauseparam
= jme_set_pauseparam
,
2793 .get_wol
= jme_get_wol
,
2794 .set_wol
= jme_set_wol
,
2795 .get_settings
= jme_get_settings
,
2796 .set_settings
= jme_set_settings
,
2797 .get_link
= jme_get_link
,
2798 .get_msglevel
= jme_get_msglevel
,
2799 .set_msglevel
= jme_set_msglevel
,
2800 .nway_reset
= jme_nway_reset
,
2801 .get_eeprom_len
= jme_get_eeprom_len
,
2802 .get_eeprom
= jme_get_eeprom
,
2803 .set_eeprom
= jme_set_eeprom
,
2807 jme_pci_dma64(struct pci_dev
*pdev
)
2809 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2810 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
2811 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
2814 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2815 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(40)))
2816 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(40)))
2819 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)))
2820 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
2827 jme_phy_init(struct jme_adapter
*jme
)
2831 reg26
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 26);
2832 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 26, reg26
| 0x1000);
2836 jme_check_hw_ver(struct jme_adapter
*jme
)
2840 chipmode
= jread32(jme
, JME_CHIPMODE
);
2842 jme
->fpgaver
= (chipmode
& CM_FPGAVER_MASK
) >> CM_FPGAVER_SHIFT
;
2843 jme
->chiprev
= (chipmode
& CM_CHIPREV_MASK
) >> CM_CHIPREV_SHIFT
;
2844 jme
->chip_main_rev
= jme
->chiprev
& 0xF;
2845 jme
->chip_sub_rev
= (jme
->chiprev
>> 4) & 0xF;
2848 static const struct net_device_ops jme_netdev_ops
= {
2849 .ndo_open
= jme_open
,
2850 .ndo_stop
= jme_close
,
2851 .ndo_validate_addr
= eth_validate_addr
,
2852 .ndo_do_ioctl
= jme_ioctl
,
2853 .ndo_start_xmit
= jme_start_xmit
,
2854 .ndo_set_mac_address
= jme_set_macaddr
,
2855 .ndo_set_multicast_list
= jme_set_multi
,
2856 .ndo_change_mtu
= jme_change_mtu
,
2857 .ndo_tx_timeout
= jme_tx_timeout
,
2858 .ndo_vlan_rx_register
= jme_vlan_rx_register
,
2859 .ndo_fix_features
= jme_fix_features
,
2860 .ndo_set_features
= jme_set_features
,
2863 static int __devinit
2864 jme_init_one(struct pci_dev
*pdev
,
2865 const struct pci_device_id
*ent
)
2867 int rc
= 0, using_dac
, i
;
2868 struct net_device
*netdev
;
2869 struct jme_adapter
*jme
;
2874 * set up PCI device basics
2876 rc
= pci_enable_device(pdev
);
2878 pr_err("Cannot enable PCI device\n");
2882 using_dac
= jme_pci_dma64(pdev
);
2883 if (using_dac
< 0) {
2884 pr_err("Cannot set PCI DMA Mask\n");
2886 goto err_out_disable_pdev
;
2889 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
2890 pr_err("No PCI resource region found\n");
2892 goto err_out_disable_pdev
;
2895 rc
= pci_request_regions(pdev
, DRV_NAME
);
2897 pr_err("Cannot obtain PCI resource region\n");
2898 goto err_out_disable_pdev
;
2901 pci_set_master(pdev
);
2904 * alloc and init net device
2906 netdev
= alloc_etherdev(sizeof(*jme
));
2908 pr_err("Cannot allocate netdev structure\n");
2910 goto err_out_release_regions
;
2912 netdev
->netdev_ops
= &jme_netdev_ops
;
2913 netdev
->ethtool_ops
= &jme_ethtool_ops
;
2914 netdev
->watchdog_timeo
= TX_TIMEOUT
;
2915 netdev
->hw_features
= NETIF_F_IP_CSUM
|
2921 netdev
->features
= NETIF_F_IP_CSUM
|
2926 NETIF_F_HW_VLAN_TX
|
2929 netdev
->features
|= NETIF_F_HIGHDMA
;
2931 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2932 pci_set_drvdata(pdev
, netdev
);
2937 jme
= netdev_priv(netdev
);
2940 jme
->jme_rx
= netif_rx
;
2941 jme
->jme_vlan_rx
= vlan_hwaccel_rx
;
2942 jme
->old_mtu
= netdev
->mtu
= 1500;
2944 jme
->tx_ring_size
= 1 << 10;
2945 jme
->tx_ring_mask
= jme
->tx_ring_size
- 1;
2946 jme
->tx_wake_threshold
= 1 << 9;
2947 jme
->rx_ring_size
= 1 << 9;
2948 jme
->rx_ring_mask
= jme
->rx_ring_size
- 1;
2949 jme
->msg_enable
= JME_DEF_MSG_ENABLE
;
2950 jme
->regs
= ioremap(pci_resource_start(pdev
, 0),
2951 pci_resource_len(pdev
, 0));
2953 pr_err("Mapping PCI resource region error\n");
2955 goto err_out_free_netdev
;
2959 apmc
= jread32(jme
, JME_APMC
) & ~JME_APMC_PSEUDO_HP_EN
;
2960 jwrite32(jme
, JME_APMC
, apmc
);
2961 } else if (force_pseudohp
) {
2962 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PSEUDO_HP_EN
;
2963 jwrite32(jme
, JME_APMC
, apmc
);
2966 NETIF_NAPI_SET(netdev
, &jme
->napi
, jme_poll
, jme
->rx_ring_size
>> 2)
2968 spin_lock_init(&jme
->phy_lock
);
2969 spin_lock_init(&jme
->macaddr_lock
);
2970 spin_lock_init(&jme
->rxmcs_lock
);
2972 atomic_set(&jme
->link_changing
, 1);
2973 atomic_set(&jme
->rx_cleaning
, 1);
2974 atomic_set(&jme
->tx_cleaning
, 1);
2975 atomic_set(&jme
->rx_empty
, 1);
2977 tasklet_init(&jme
->pcc_task
,
2979 (unsigned long) jme
);
2980 tasklet_init(&jme
->linkch_task
,
2981 jme_link_change_tasklet
,
2982 (unsigned long) jme
);
2983 tasklet_init(&jme
->txclean_task
,
2984 jme_tx_clean_tasklet
,
2985 (unsigned long) jme
);
2986 tasklet_init(&jme
->rxclean_task
,
2987 jme_rx_clean_tasklet
,
2988 (unsigned long) jme
);
2989 tasklet_init(&jme
->rxempty_task
,
2990 jme_rx_empty_tasklet
,
2991 (unsigned long) jme
);
2992 tasklet_disable_nosync(&jme
->linkch_task
);
2993 tasklet_disable_nosync(&jme
->txclean_task
);
2994 tasklet_disable_nosync(&jme
->rxclean_task
);
2995 tasklet_disable_nosync(&jme
->rxempty_task
);
2996 jme
->dpi
.cur
= PCC_P1
;
2999 jme
->reg_rxcs
= RXCS_DEFAULT
;
3000 jme
->reg_rxmcs
= RXMCS_DEFAULT
;
3002 jme
->reg_pmcs
= PMCS_MFEN
;
3003 jme
->reg_gpreg1
= GPREG1_DEFAULT
;
3005 if (jme
->reg_rxmcs
& RXMCS_CHECKSUM
)
3006 netdev
->features
|= NETIF_F_RXCSUM
;
3009 * Get Max Read Req Size from PCI Config Space
3011 pci_read_config_byte(pdev
, PCI_DCSR_MRRS
, &jme
->mrrs
);
3012 jme
->mrrs
&= PCI_DCSR_MRRS_MASK
;
3013 switch (jme
->mrrs
) {
3015 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_128B
;
3018 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_256B
;
3021 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_512B
;
3026 * Must check before reset_mac_processor
3028 jme_check_hw_ver(jme
);
3029 jme
->mii_if
.dev
= netdev
;
3031 jme
->mii_if
.phy_id
= 0;
3032 for (i
= 1 ; i
< 32 ; ++i
) {
3033 bmcr
= jme_mdio_read(netdev
, i
, MII_BMCR
);
3034 bmsr
= jme_mdio_read(netdev
, i
, MII_BMSR
);
3035 if (bmcr
!= 0xFFFFU
&& (bmcr
!= 0 || bmsr
!= 0)) {
3036 jme
->mii_if
.phy_id
= i
;
3041 if (!jme
->mii_if
.phy_id
) {
3043 pr_err("Can not find phy_id\n");
3047 jme
->reg_ghc
|= GHC_LINK_POLL
;
3049 jme
->mii_if
.phy_id
= 1;
3051 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
3052 jme
->mii_if
.supports_gmii
= true;
3054 jme
->mii_if
.supports_gmii
= false;
3055 jme
->mii_if
.phy_id_mask
= 0x1F;
3056 jme
->mii_if
.reg_num_mask
= 0x1F;
3057 jme
->mii_if
.mdio_read
= jme_mdio_read
;
3058 jme
->mii_if
.mdio_write
= jme_mdio_write
;
3061 jme_set_phyfifo_5level(jme
);
3062 jme
->pcirev
= pdev
->revision
;
3068 * Reset MAC processor and reload EEPROM for MAC Address
3070 jme_reset_mac_processor(jme
);
3071 rc
= jme_reload_eeprom(jme
);
3073 pr_err("Reload eeprom for reading MAC Address error\n");
3076 jme_load_macaddr(netdev
);
3079 * Tell stack that we are not ready to work until open()
3081 netif_carrier_off(netdev
);
3083 rc
= register_netdev(netdev
);
3085 pr_err("Cannot register net device\n");
3089 netif_info(jme
, probe
, jme
->dev
, "%s%s chiprev:%x pcirev:%x macaddr:%pM\n",
3090 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
) ?
3091 "JMC250 Gigabit Ethernet" :
3092 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC260
) ?
3093 "JMC260 Fast Ethernet" : "Unknown",
3094 (jme
->fpgaver
!= 0) ? " (FPGA)" : "",
3095 (jme
->fpgaver
!= 0) ? jme
->fpgaver
: jme
->chiprev
,
3096 jme
->pcirev
, netdev
->dev_addr
);
3102 err_out_free_netdev
:
3103 pci_set_drvdata(pdev
, NULL
);
3104 free_netdev(netdev
);
3105 err_out_release_regions
:
3106 pci_release_regions(pdev
);
3107 err_out_disable_pdev
:
3108 pci_disable_device(pdev
);
3113 static void __devexit
3114 jme_remove_one(struct pci_dev
*pdev
)
3116 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3117 struct jme_adapter
*jme
= netdev_priv(netdev
);
3119 unregister_netdev(netdev
);
3121 pci_set_drvdata(pdev
, NULL
);
3122 free_netdev(netdev
);
3123 pci_release_regions(pdev
);
3124 pci_disable_device(pdev
);
3129 jme_shutdown(struct pci_dev
*pdev
)
3131 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3132 struct jme_adapter
*jme
= netdev_priv(netdev
);
3134 jme_powersave_phy(jme
);
3135 pci_pme_active(pdev
, true);
3139 static int jme_suspend(struct device
*dev
)
3141 struct pci_dev
*pdev
= to_pci_dev(dev
);
3142 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3143 struct jme_adapter
*jme
= netdev_priv(netdev
);
3145 atomic_dec(&jme
->link_changing
);
3147 netif_device_detach(netdev
);
3148 netif_stop_queue(netdev
);
3151 tasklet_disable(&jme
->txclean_task
);
3152 tasklet_disable(&jme
->rxclean_task
);
3153 tasklet_disable(&jme
->rxempty_task
);
3155 if (netif_carrier_ok(netdev
)) {
3156 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
3157 jme_polling_mode(jme
);
3159 jme_stop_pcc_timer(jme
);
3160 jme_disable_rx_engine(jme
);
3161 jme_disable_tx_engine(jme
);
3162 jme_reset_mac_processor(jme
);
3163 jme_free_rx_resources(jme
);
3164 jme_free_tx_resources(jme
);
3165 netif_carrier_off(netdev
);
3169 tasklet_enable(&jme
->txclean_task
);
3170 tasklet_hi_enable(&jme
->rxclean_task
);
3171 tasklet_hi_enable(&jme
->rxempty_task
);
3173 jme_powersave_phy(jme
);
3178 static int jme_resume(struct device
*dev
)
3180 struct pci_dev
*pdev
= to_pci_dev(dev
);
3181 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3182 struct jme_adapter
*jme
= netdev_priv(netdev
);
3184 jwrite32(jme
, JME_PMCS
, 0xFFFF0000 | jme
->reg_pmcs
);
3187 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
3188 jme_set_settings(netdev
, &jme
->old_ecmd
);
3190 jme_reset_phy_processor(jme
);
3193 netif_device_attach(netdev
);
3195 atomic_inc(&jme
->link_changing
);
3197 jme_reset_link(jme
);
3202 static SIMPLE_DEV_PM_OPS(jme_pm_ops
, jme_suspend
, jme_resume
);
3203 #define JME_PM_OPS (&jme_pm_ops)
3207 #define JME_PM_OPS NULL
3210 static DEFINE_PCI_DEVICE_TABLE(jme_pci_tbl
) = {
3211 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC250
) },
3212 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC260
) },
3216 static struct pci_driver jme_driver
= {
3218 .id_table
= jme_pci_tbl
,
3219 .probe
= jme_init_one
,
3220 .remove
= __devexit_p(jme_remove_one
),
3221 .shutdown
= jme_shutdown
,
3222 .driver
.pm
= JME_PM_OPS
,
3226 jme_init_module(void)
3228 pr_info("JMicron JMC2XX ethernet driver version %s\n", DRV_VERSION
);
3229 return pci_register_driver(&jme_driver
);
3233 jme_cleanup_module(void)
3235 pci_unregister_driver(&jme_driver
);
3238 module_init(jme_init_module
);
3239 module_exit(jme_cleanup_module
);
3241 MODULE_AUTHOR("Guo-Fu Tseng <cooldavid@cooldavid.org>");
3242 MODULE_DESCRIPTION("JMicron JMC2x0 PCI Express Ethernet driver");
3243 MODULE_LICENSE("GPL");
3244 MODULE_VERSION(DRV_VERSION
);
3245 MODULE_DEVICE_TABLE(pci
, jme_pci_tbl
);