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
, PMCS_STMASK
| jme
->reg_pmcs
);
278 jme_reload_eeprom(struct jme_adapter
*jme
)
283 val
= jread32(jme
, JME_SMBCSR
);
285 if (val
& SMBCSR_EEPROMD
) {
287 jwrite32(jme
, JME_SMBCSR
, val
);
288 val
|= SMBCSR_RELOAD
;
289 jwrite32(jme
, JME_SMBCSR
, val
);
292 for (i
= JME_EEPROM_RELOAD_TIMEOUT
; i
> 0; --i
) {
294 if ((jread32(jme
, JME_SMBCSR
) & SMBCSR_RELOAD
) == 0)
299 pr_err("eeprom reload timeout\n");
308 jme_load_macaddr(struct net_device
*netdev
)
310 struct jme_adapter
*jme
= netdev_priv(netdev
);
311 unsigned char macaddr
[6];
314 spin_lock_bh(&jme
->macaddr_lock
);
315 val
= jread32(jme
, JME_RXUMA_LO
);
316 macaddr
[0] = (val
>> 0) & 0xFF;
317 macaddr
[1] = (val
>> 8) & 0xFF;
318 macaddr
[2] = (val
>> 16) & 0xFF;
319 macaddr
[3] = (val
>> 24) & 0xFF;
320 val
= jread32(jme
, JME_RXUMA_HI
);
321 macaddr
[4] = (val
>> 0) & 0xFF;
322 macaddr
[5] = (val
>> 8) & 0xFF;
323 memcpy(netdev
->dev_addr
, macaddr
, 6);
324 spin_unlock_bh(&jme
->macaddr_lock
);
328 jme_set_rx_pcc(struct jme_adapter
*jme
, int p
)
332 jwrite32(jme
, JME_PCCRX0
,
333 ((PCC_OFF_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
334 ((PCC_OFF_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
337 jwrite32(jme
, JME_PCCRX0
,
338 ((PCC_P1_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
339 ((PCC_P1_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
342 jwrite32(jme
, JME_PCCRX0
,
343 ((PCC_P2_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
344 ((PCC_P2_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
347 jwrite32(jme
, JME_PCCRX0
,
348 ((PCC_P3_TO
<< PCCRXTO_SHIFT
) & PCCRXTO_MASK
) |
349 ((PCC_P3_CNT
<< PCCRX_SHIFT
) & PCCRX_MASK
));
356 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
357 netif_info(jme
, rx_status
, jme
->dev
, "Switched to PCC_P%d\n", p
);
361 jme_start_irq(struct jme_adapter
*jme
)
363 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
365 jme_set_rx_pcc(jme
, PCC_P1
);
367 dpi
->attempt
= PCC_P1
;
370 jwrite32(jme
, JME_PCCTX
,
371 ((PCC_TX_TO
<< PCCTXTO_SHIFT
) & PCCTXTO_MASK
) |
372 ((PCC_TX_CNT
<< PCCTX_SHIFT
) & PCCTX_MASK
) |
379 jwrite32(jme
, JME_IENS
, INTR_ENABLE
);
383 jme_stop_irq(struct jme_adapter
*jme
)
388 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
392 jme_linkstat_from_phy(struct jme_adapter
*jme
)
396 phylink
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 17);
397 bmsr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMSR
);
398 if (bmsr
& BMSR_ANCOMP
)
399 phylink
|= PHY_LINK_AUTONEG_COMPLETE
;
405 jme_set_phyfifo_5level(struct jme_adapter
*jme
)
407 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0004);
411 jme_set_phyfifo_8level(struct jme_adapter
*jme
)
413 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 27, 0x0000);
417 jme_check_link(struct net_device
*netdev
, int testonly
)
419 struct jme_adapter
*jme
= netdev_priv(netdev
);
420 u32 phylink
, cnt
= JME_SPDRSV_TIMEOUT
, bmcr
;
427 phylink
= jme_linkstat_from_phy(jme
);
429 phylink
= jread32(jme
, JME_PHY_LINK
);
431 if (phylink
& PHY_LINK_UP
) {
432 if (!(phylink
& PHY_LINK_AUTONEG_COMPLETE
)) {
434 * If we did not enable AN
435 * Speed/Duplex Info should be obtained from SMI
437 phylink
= PHY_LINK_UP
;
439 bmcr
= jme_mdio_read(jme
->dev
,
443 phylink
|= ((bmcr
& BMCR_SPEED1000
) &&
444 (bmcr
& BMCR_SPEED100
) == 0) ?
445 PHY_LINK_SPEED_1000M
:
446 (bmcr
& BMCR_SPEED100
) ?
447 PHY_LINK_SPEED_100M
:
450 phylink
|= (bmcr
& BMCR_FULLDPLX
) ?
453 strcat(linkmsg
, "Forced: ");
456 * Keep polling for speed/duplex resolve complete
458 while (!(phylink
& PHY_LINK_SPEEDDPU_RESOLVED
) &&
464 phylink
= jme_linkstat_from_phy(jme
);
466 phylink
= jread32(jme
, JME_PHY_LINK
);
469 pr_err("Waiting speed resolve timeout\n");
471 strcat(linkmsg
, "ANed: ");
474 if (jme
->phylink
== phylink
) {
481 jme
->phylink
= phylink
;
484 * The speed/duplex setting of jme->reg_ghc already cleared
485 * by jme_reset_mac_processor()
487 switch (phylink
& PHY_LINK_SPEED_MASK
) {
488 case PHY_LINK_SPEED_10M
:
489 jme
->reg_ghc
|= GHC_SPEED_10M
;
490 strcat(linkmsg
, "10 Mbps, ");
492 case PHY_LINK_SPEED_100M
:
493 jme
->reg_ghc
|= GHC_SPEED_100M
;
494 strcat(linkmsg
, "100 Mbps, ");
496 case PHY_LINK_SPEED_1000M
:
497 jme
->reg_ghc
|= GHC_SPEED_1000M
;
498 strcat(linkmsg
, "1000 Mbps, ");
504 if (phylink
& PHY_LINK_DUPLEX
) {
505 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
);
506 jwrite32(jme
, JME_TXTRHD
, TXTRHD_FULLDUPLEX
);
507 jme
->reg_ghc
|= GHC_DPX
;
509 jwrite32(jme
, JME_TXMCS
, TXMCS_DEFAULT
|
513 jwrite32(jme
, JME_TXTRHD
, TXTRHD_HALFDUPLEX
);
516 jwrite32(jme
, JME_GHC
, jme
->reg_ghc
);
518 if (is_buggy250(jme
->pdev
->device
, jme
->chiprev
)) {
519 jme
->reg_gpreg1
&= ~(GPREG1_HALFMODEPATCH
|
521 if (!(phylink
& PHY_LINK_DUPLEX
))
522 jme
->reg_gpreg1
|= GPREG1_HALFMODEPATCH
;
523 switch (phylink
& PHY_LINK_SPEED_MASK
) {
524 case PHY_LINK_SPEED_10M
:
525 jme_set_phyfifo_8level(jme
);
526 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
528 case PHY_LINK_SPEED_100M
:
529 jme_set_phyfifo_5level(jme
);
530 jme
->reg_gpreg1
|= GPREG1_RSSPATCH
;
532 case PHY_LINK_SPEED_1000M
:
533 jme_set_phyfifo_8level(jme
);
539 jwrite32(jme
, JME_GPREG1
, jme
->reg_gpreg1
);
541 strcat(linkmsg
, (phylink
& PHY_LINK_DUPLEX
) ?
544 strcat(linkmsg
, (phylink
& PHY_LINK_MDI_STAT
) ?
547 netif_info(jme
, link
, jme
->dev
, "Link is up at %s\n", linkmsg
);
548 netif_carrier_on(netdev
);
553 netif_info(jme
, link
, jme
->dev
, "Link is down\n");
555 netif_carrier_off(netdev
);
563 jme_setup_tx_resources(struct jme_adapter
*jme
)
565 struct jme_ring
*txring
= &(jme
->txring
[0]);
567 txring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
568 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
578 txring
->desc
= (void *)ALIGN((unsigned long)(txring
->alloc
),
580 txring
->dma
= ALIGN(txring
->dmaalloc
, RING_DESC_ALIGN
);
581 txring
->next_to_use
= 0;
582 atomic_set(&txring
->next_to_clean
, 0);
583 atomic_set(&txring
->nr_free
, jme
->tx_ring_size
);
585 txring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
586 jme
->tx_ring_size
, GFP_ATOMIC
);
587 if (unlikely(!(txring
->bufinf
)))
588 goto err_free_txring
;
591 * Initialize Transmit Descriptors
593 memset(txring
->alloc
, 0, TX_RING_ALLOC_SIZE(jme
->tx_ring_size
));
594 memset(txring
->bufinf
, 0,
595 sizeof(struct jme_buffer_info
) * jme
->tx_ring_size
);
600 dma_free_coherent(&(jme
->pdev
->dev
),
601 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
607 txring
->dmaalloc
= 0;
609 txring
->bufinf
= NULL
;
615 jme_free_tx_resources(struct jme_adapter
*jme
)
618 struct jme_ring
*txring
= &(jme
->txring
[0]);
619 struct jme_buffer_info
*txbi
;
622 if (txring
->bufinf
) {
623 for (i
= 0 ; i
< jme
->tx_ring_size
; ++i
) {
624 txbi
= txring
->bufinf
+ i
;
626 dev_kfree_skb(txbi
->skb
);
632 txbi
->start_xmit
= 0;
634 kfree(txring
->bufinf
);
637 dma_free_coherent(&(jme
->pdev
->dev
),
638 TX_RING_ALLOC_SIZE(jme
->tx_ring_size
),
642 txring
->alloc
= NULL
;
644 txring
->dmaalloc
= 0;
646 txring
->bufinf
= NULL
;
648 txring
->next_to_use
= 0;
649 atomic_set(&txring
->next_to_clean
, 0);
650 atomic_set(&txring
->nr_free
, 0);
654 jme_enable_tx_engine(struct jme_adapter
*jme
)
659 jwrite32(jme
, JME_TXCS
, TXCS_DEFAULT
| TXCS_SELECT_QUEUE0
);
663 * Setup TX Queue 0 DMA Bass Address
665 jwrite32(jme
, JME_TXDBA_LO
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
666 jwrite32(jme
, JME_TXDBA_HI
, (__u64
)(jme
->txring
[0].dma
) >> 32);
667 jwrite32(jme
, JME_TXNDA
, (__u64
)jme
->txring
[0].dma
& 0xFFFFFFFFUL
);
670 * Setup TX Descptor Count
672 jwrite32(jme
, JME_TXQDC
, jme
->tx_ring_size
);
678 jwrite32f(jme
, JME_TXCS
, jme
->reg_txcs
|
683 * Start clock for TX MAC Processor
685 jme_mac_txclk_on(jme
);
689 jme_restart_tx_engine(struct jme_adapter
*jme
)
694 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
700 jme_disable_tx_engine(struct jme_adapter
*jme
)
708 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
| TXCS_SELECT_QUEUE0
);
711 val
= jread32(jme
, JME_TXCS
);
712 for (i
= JME_TX_DISABLE_TIMEOUT
; (val
& TXCS_ENABLE
) && i
> 0 ; --i
) {
714 val
= jread32(jme
, JME_TXCS
);
719 pr_err("Disable TX engine timeout\n");
722 * Stop clock for TX MAC Processor
724 jme_mac_txclk_off(jme
);
728 jme_set_clean_rxdesc(struct jme_adapter
*jme
, int i
)
730 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
731 register struct rxdesc
*rxdesc
= rxring
->desc
;
732 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
738 rxdesc
->desc1
.bufaddrh
= cpu_to_le32((__u64
)rxbi
->mapping
>> 32);
739 rxdesc
->desc1
.bufaddrl
= cpu_to_le32(
740 (__u64
)rxbi
->mapping
& 0xFFFFFFFFUL
);
741 rxdesc
->desc1
.datalen
= cpu_to_le16(rxbi
->len
);
742 if (jme
->dev
->features
& NETIF_F_HIGHDMA
)
743 rxdesc
->desc1
.flags
= RXFLAG_64BIT
;
745 rxdesc
->desc1
.flags
|= RXFLAG_OWN
| RXFLAG_INT
;
749 jme_make_new_rx_buf(struct jme_adapter
*jme
, int i
)
751 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
752 struct jme_buffer_info
*rxbi
= rxring
->bufinf
+ i
;
756 skb
= netdev_alloc_skb(jme
->dev
,
757 jme
->dev
->mtu
+ RX_EXTRA_LEN
);
761 mapping
= pci_map_page(jme
->pdev
, virt_to_page(skb
->data
),
762 offset_in_page(skb
->data
), skb_tailroom(skb
),
764 if (unlikely(pci_dma_mapping_error(jme
->pdev
, mapping
))) {
769 if (likely(rxbi
->mapping
))
770 pci_unmap_page(jme
->pdev
, rxbi
->mapping
,
771 rxbi
->len
, PCI_DMA_FROMDEVICE
);
774 rxbi
->len
= skb_tailroom(skb
);
775 rxbi
->mapping
= mapping
;
780 jme_free_rx_buf(struct jme_adapter
*jme
, int i
)
782 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
783 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
787 pci_unmap_page(jme
->pdev
,
791 dev_kfree_skb(rxbi
->skb
);
799 jme_free_rx_resources(struct jme_adapter
*jme
)
802 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
805 if (rxring
->bufinf
) {
806 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
)
807 jme_free_rx_buf(jme
, i
);
808 kfree(rxring
->bufinf
);
811 dma_free_coherent(&(jme
->pdev
->dev
),
812 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
815 rxring
->alloc
= NULL
;
817 rxring
->dmaalloc
= 0;
819 rxring
->bufinf
= NULL
;
821 rxring
->next_to_use
= 0;
822 atomic_set(&rxring
->next_to_clean
, 0);
826 jme_setup_rx_resources(struct jme_adapter
*jme
)
829 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
831 rxring
->alloc
= dma_alloc_coherent(&(jme
->pdev
->dev
),
832 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
841 rxring
->desc
= (void *)ALIGN((unsigned long)(rxring
->alloc
),
843 rxring
->dma
= ALIGN(rxring
->dmaalloc
, RING_DESC_ALIGN
);
844 rxring
->next_to_use
= 0;
845 atomic_set(&rxring
->next_to_clean
, 0);
847 rxring
->bufinf
= kmalloc(sizeof(struct jme_buffer_info
) *
848 jme
->rx_ring_size
, GFP_ATOMIC
);
849 if (unlikely(!(rxring
->bufinf
)))
850 goto err_free_rxring
;
853 * Initiallize Receive Descriptors
855 memset(rxring
->bufinf
, 0,
856 sizeof(struct jme_buffer_info
) * jme
->rx_ring_size
);
857 for (i
= 0 ; i
< jme
->rx_ring_size
; ++i
) {
858 if (unlikely(jme_make_new_rx_buf(jme
, i
))) {
859 jme_free_rx_resources(jme
);
863 jme_set_clean_rxdesc(jme
, i
);
869 dma_free_coherent(&(jme
->pdev
->dev
),
870 RX_RING_ALLOC_SIZE(jme
->rx_ring_size
),
875 rxring
->dmaalloc
= 0;
877 rxring
->bufinf
= NULL
;
883 jme_enable_rx_engine(struct jme_adapter
*jme
)
888 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
893 * Setup RX DMA Bass Address
895 jwrite32(jme
, JME_RXDBA_LO
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
896 jwrite32(jme
, JME_RXDBA_HI
, (__u64
)(jme
->rxring
[0].dma
) >> 32);
897 jwrite32(jme
, JME_RXNDA
, (__u64
)(jme
->rxring
[0].dma
) & 0xFFFFFFFFUL
);
900 * Setup RX Descriptor Count
902 jwrite32(jme
, JME_RXQDC
, jme
->rx_ring_size
);
905 * Setup Unicast Filter
907 jme_set_unicastaddr(jme
->dev
);
908 jme_set_multi(jme
->dev
);
914 jwrite32f(jme
, JME_RXCS
, jme
->reg_rxcs
|
920 * Start clock for RX MAC Processor
922 jme_mac_rxclk_on(jme
);
926 jme_restart_rx_engine(struct jme_adapter
*jme
)
931 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
|
938 jme_disable_rx_engine(struct jme_adapter
*jme
)
946 jwrite32(jme
, JME_RXCS
, jme
->reg_rxcs
);
949 val
= jread32(jme
, JME_RXCS
);
950 for (i
= JME_RX_DISABLE_TIMEOUT
; (val
& RXCS_ENABLE
) && i
> 0 ; --i
) {
952 val
= jread32(jme
, JME_RXCS
);
957 pr_err("Disable RX engine timeout\n");
960 * Stop clock for RX MAC Processor
962 jme_mac_rxclk_off(jme
);
966 jme_udpsum(struct sk_buff
*skb
)
970 if (skb
->len
< (ETH_HLEN
+ sizeof(struct iphdr
)))
972 if (skb
->protocol
!= htons(ETH_P_IP
))
974 skb_set_network_header(skb
, ETH_HLEN
);
975 if ((ip_hdr(skb
)->protocol
!= IPPROTO_UDP
) ||
976 (skb
->len
< (ETH_HLEN
+
977 (ip_hdr(skb
)->ihl
<< 2) +
978 sizeof(struct udphdr
)))) {
979 skb_reset_network_header(skb
);
982 skb_set_transport_header(skb
,
983 ETH_HLEN
+ (ip_hdr(skb
)->ihl
<< 2));
984 csum
= udp_hdr(skb
)->check
;
985 skb_reset_transport_header(skb
);
986 skb_reset_network_header(skb
);
992 jme_rxsum_ok(struct jme_adapter
*jme
, u16 flags
, struct sk_buff
*skb
)
994 if (!(flags
& (RXWBFLAG_TCPON
| RXWBFLAG_UDPON
| RXWBFLAG_IPV4
)))
997 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_TCPON
| RXWBFLAG_TCPCS
))
998 == RXWBFLAG_TCPON
)) {
999 if (flags
& RXWBFLAG_IPV4
)
1000 netif_err(jme
, rx_err
, jme
->dev
, "TCP Checksum error\n");
1004 if (unlikely((flags
& (RXWBFLAG_MF
| RXWBFLAG_UDPON
| RXWBFLAG_UDPCS
))
1005 == RXWBFLAG_UDPON
) && jme_udpsum(skb
)) {
1006 if (flags
& RXWBFLAG_IPV4
)
1007 netif_err(jme
, rx_err
, jme
->dev
, "UDP Checksum error\n");
1011 if (unlikely((flags
& (RXWBFLAG_IPV4
| RXWBFLAG_IPCS
))
1012 == RXWBFLAG_IPV4
)) {
1013 netif_err(jme
, rx_err
, jme
->dev
, "IPv4 Checksum error\n");
1021 jme_alloc_and_feed_skb(struct jme_adapter
*jme
, int idx
)
1023 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1024 struct rxdesc
*rxdesc
= rxring
->desc
;
1025 struct jme_buffer_info
*rxbi
= rxring
->bufinf
;
1026 struct sk_buff
*skb
;
1033 pci_dma_sync_single_for_cpu(jme
->pdev
,
1036 PCI_DMA_FROMDEVICE
);
1038 if (unlikely(jme_make_new_rx_buf(jme
, idx
))) {
1039 pci_dma_sync_single_for_device(jme
->pdev
,
1042 PCI_DMA_FROMDEVICE
);
1044 ++(NET_STAT(jme
).rx_dropped
);
1046 framesize
= le16_to_cpu(rxdesc
->descwb
.framesize
)
1049 skb_reserve(skb
, RX_PREPAD_SIZE
);
1050 skb_put(skb
, framesize
);
1051 skb
->protocol
= eth_type_trans(skb
, jme
->dev
);
1053 if (jme_rxsum_ok(jme
, le16_to_cpu(rxdesc
->descwb
.flags
), skb
))
1054 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1056 skb_checksum_none_assert(skb
);
1058 if (rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_TAGON
)) {
1059 u16 vid
= le16_to_cpu(rxdesc
->descwb
.vlan
);
1061 __vlan_hwaccel_put_tag(skb
, vid
);
1062 NET_STAT(jme
).rx_bytes
+= 4;
1066 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_DEST
)) ==
1067 cpu_to_le16(RXWBFLAG_DEST_MUL
))
1068 ++(NET_STAT(jme
).multicast
);
1070 NET_STAT(jme
).rx_bytes
+= framesize
;
1071 ++(NET_STAT(jme
).rx_packets
);
1074 jme_set_clean_rxdesc(jme
, idx
);
1079 jme_process_receive(struct jme_adapter
*jme
, int limit
)
1081 struct jme_ring
*rxring
= &(jme
->rxring
[0]);
1082 struct rxdesc
*rxdesc
= rxring
->desc
;
1083 int i
, j
, ccnt
, desccnt
, mask
= jme
->rx_ring_mask
;
1085 if (unlikely(!atomic_dec_and_test(&jme
->rx_cleaning
)))
1088 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1091 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1094 i
= atomic_read(&rxring
->next_to_clean
);
1096 rxdesc
= rxring
->desc
;
1099 if ((rxdesc
->descwb
.flags
& cpu_to_le16(RXWBFLAG_OWN
)) ||
1100 !(rxdesc
->descwb
.desccnt
& RXWBDCNT_WBCPL
))
1105 desccnt
= rxdesc
->descwb
.desccnt
& RXWBDCNT_DCNT
;
1107 if (unlikely(desccnt
> 1 ||
1108 rxdesc
->descwb
.errstat
& RXWBERR_ALLERR
)) {
1110 if (rxdesc
->descwb
.errstat
& RXWBERR_CRCERR
)
1111 ++(NET_STAT(jme
).rx_crc_errors
);
1112 else if (rxdesc
->descwb
.errstat
& RXWBERR_OVERUN
)
1113 ++(NET_STAT(jme
).rx_fifo_errors
);
1115 ++(NET_STAT(jme
).rx_errors
);
1118 limit
-= desccnt
- 1;
1120 for (j
= i
, ccnt
= desccnt
; ccnt
-- ; ) {
1121 jme_set_clean_rxdesc(jme
, j
);
1122 j
= (j
+ 1) & (mask
);
1126 jme_alloc_and_feed_skb(jme
, i
);
1129 i
= (i
+ desccnt
) & (mask
);
1133 atomic_set(&rxring
->next_to_clean
, i
);
1136 atomic_inc(&jme
->rx_cleaning
);
1138 return limit
> 0 ? limit
: 0;
1143 jme_attempt_pcc(struct dynpcc_info
*dpi
, int atmp
)
1145 if (likely(atmp
== dpi
->cur
)) {
1150 if (dpi
->attempt
== atmp
) {
1153 dpi
->attempt
= atmp
;
1160 jme_dynamic_pcc(struct jme_adapter
*jme
)
1162 register struct dynpcc_info
*dpi
= &(jme
->dpi
);
1164 if ((NET_STAT(jme
).rx_bytes
- dpi
->last_bytes
) > PCC_P3_THRESHOLD
)
1165 jme_attempt_pcc(dpi
, PCC_P3
);
1166 else if ((NET_STAT(jme
).rx_packets
- dpi
->last_pkts
) > PCC_P2_THRESHOLD
||
1167 dpi
->intr_cnt
> PCC_INTR_THRESHOLD
)
1168 jme_attempt_pcc(dpi
, PCC_P2
);
1170 jme_attempt_pcc(dpi
, PCC_P1
);
1172 if (unlikely(dpi
->attempt
!= dpi
->cur
&& dpi
->cnt
> 5)) {
1173 if (dpi
->attempt
< dpi
->cur
)
1174 tasklet_schedule(&jme
->rxclean_task
);
1175 jme_set_rx_pcc(jme
, dpi
->attempt
);
1176 dpi
->cur
= dpi
->attempt
;
1182 jme_start_pcc_timer(struct jme_adapter
*jme
)
1184 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1185 dpi
->last_bytes
= NET_STAT(jme
).rx_bytes
;
1186 dpi
->last_pkts
= NET_STAT(jme
).rx_packets
;
1188 jwrite32(jme
, JME_TMCSR
,
1189 TMCSR_EN
| ((0xFFFFFF - PCC_INTERVAL_US
) & TMCSR_CNT
));
1193 jme_stop_pcc_timer(struct jme_adapter
*jme
)
1195 jwrite32(jme
, JME_TMCSR
, 0);
1199 jme_shutdown_nic(struct jme_adapter
*jme
)
1203 phylink
= jme_linkstat_from_phy(jme
);
1205 if (!(phylink
& PHY_LINK_UP
)) {
1207 * Disable all interrupt before issue timer
1210 jwrite32(jme
, JME_TIMER2
, TMCSR_EN
| 0xFFFFFE);
1215 jme_pcc_tasklet(unsigned long arg
)
1217 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1218 struct net_device
*netdev
= jme
->dev
;
1220 if (unlikely(test_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
))) {
1221 jme_shutdown_nic(jme
);
1225 if (unlikely(!netif_carrier_ok(netdev
) ||
1226 (atomic_read(&jme
->link_changing
) != 1)
1228 jme_stop_pcc_timer(jme
);
1232 if (!(test_bit(JME_FLAG_POLL
, &jme
->flags
)))
1233 jme_dynamic_pcc(jme
);
1235 jme_start_pcc_timer(jme
);
1239 jme_polling_mode(struct jme_adapter
*jme
)
1241 jme_set_rx_pcc(jme
, PCC_OFF
);
1245 jme_interrupt_mode(struct jme_adapter
*jme
)
1247 jme_set_rx_pcc(jme
, PCC_P1
);
1251 jme_pseudo_hotplug_enabled(struct jme_adapter
*jme
)
1254 apmc
= jread32(jme
, JME_APMC
);
1255 return apmc
& JME_APMC_PSEUDO_HP_EN
;
1259 jme_start_shutdown_timer(struct jme_adapter
*jme
)
1263 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PCIE_SD_EN
;
1264 apmc
&= ~JME_APMC_EPIEN_CTRL
;
1266 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_EN
);
1269 jwrite32f(jme
, JME_APMC
, apmc
);
1271 jwrite32f(jme
, JME_TIMER2
, 0);
1272 set_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1273 jwrite32(jme
, JME_TMCSR
,
1274 TMCSR_EN
| ((0xFFFFFF - APMC_PHP_SHUTDOWN_DELAY
) & TMCSR_CNT
));
1278 jme_stop_shutdown_timer(struct jme_adapter
*jme
)
1282 jwrite32f(jme
, JME_TMCSR
, 0);
1283 jwrite32f(jme
, JME_TIMER2
, 0);
1284 clear_bit(JME_FLAG_SHUTDOWN
, &jme
->flags
);
1286 apmc
= jread32(jme
, JME_APMC
);
1287 apmc
&= ~(JME_APMC_PCIE_SD_EN
| JME_APMC_EPIEN_CTRL
);
1288 jwrite32f(jme
, JME_APMC
, apmc
| JME_APMC_EPIEN_CTRL_DIS
);
1290 jwrite32f(jme
, JME_APMC
, apmc
);
1294 jme_link_change_tasklet(unsigned long arg
)
1296 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1297 struct net_device
*netdev
= jme
->dev
;
1300 while (!atomic_dec_and_test(&jme
->link_changing
)) {
1301 atomic_inc(&jme
->link_changing
);
1302 netif_info(jme
, intr
, jme
->dev
, "Get link change lock failed\n");
1303 while (atomic_read(&jme
->link_changing
) != 1)
1304 netif_info(jme
, intr
, jme
->dev
, "Waiting link change lock\n");
1307 if (jme_check_link(netdev
, 1) && jme
->old_mtu
== netdev
->mtu
)
1310 jme
->old_mtu
= netdev
->mtu
;
1311 netif_stop_queue(netdev
);
1312 if (jme_pseudo_hotplug_enabled(jme
))
1313 jme_stop_shutdown_timer(jme
);
1315 jme_stop_pcc_timer(jme
);
1316 tasklet_disable(&jme
->txclean_task
);
1317 tasklet_disable(&jme
->rxclean_task
);
1318 tasklet_disable(&jme
->rxempty_task
);
1320 if (netif_carrier_ok(netdev
)) {
1321 jme_disable_rx_engine(jme
);
1322 jme_disable_tx_engine(jme
);
1323 jme_reset_mac_processor(jme
);
1324 jme_free_rx_resources(jme
);
1325 jme_free_tx_resources(jme
);
1327 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1328 jme_polling_mode(jme
);
1330 netif_carrier_off(netdev
);
1333 jme_check_link(netdev
, 0);
1334 if (netif_carrier_ok(netdev
)) {
1335 rc
= jme_setup_rx_resources(jme
);
1337 pr_err("Allocating resources for RX error, Device STOPPED!\n");
1338 goto out_enable_tasklet
;
1341 rc
= jme_setup_tx_resources(jme
);
1343 pr_err("Allocating resources for TX error, Device STOPPED!\n");
1344 goto err_out_free_rx_resources
;
1347 jme_enable_rx_engine(jme
);
1348 jme_enable_tx_engine(jme
);
1350 netif_start_queue(netdev
);
1352 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
1353 jme_interrupt_mode(jme
);
1355 jme_start_pcc_timer(jme
);
1356 } else if (jme_pseudo_hotplug_enabled(jme
)) {
1357 jme_start_shutdown_timer(jme
);
1360 goto out_enable_tasklet
;
1362 err_out_free_rx_resources
:
1363 jme_free_rx_resources(jme
);
1365 tasklet_enable(&jme
->txclean_task
);
1366 tasklet_hi_enable(&jme
->rxclean_task
);
1367 tasklet_hi_enable(&jme
->rxempty_task
);
1369 atomic_inc(&jme
->link_changing
);
1373 jme_rx_clean_tasklet(unsigned long arg
)
1375 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1376 struct dynpcc_info
*dpi
= &(jme
->dpi
);
1378 jme_process_receive(jme
, jme
->rx_ring_size
);
1384 jme_poll(JME_NAPI_HOLDER(holder
), JME_NAPI_WEIGHT(budget
))
1386 struct jme_adapter
*jme
= jme_napi_priv(holder
);
1389 rest
= jme_process_receive(jme
, JME_NAPI_WEIGHT_VAL(budget
));
1391 while (atomic_read(&jme
->rx_empty
) > 0) {
1392 atomic_dec(&jme
->rx_empty
);
1393 ++(NET_STAT(jme
).rx_dropped
);
1394 jme_restart_rx_engine(jme
);
1396 atomic_inc(&jme
->rx_empty
);
1399 JME_RX_COMPLETE(netdev
, holder
);
1400 jme_interrupt_mode(jme
);
1403 JME_NAPI_WEIGHT_SET(budget
, rest
);
1404 return JME_NAPI_WEIGHT_VAL(budget
) - rest
;
1408 jme_rx_empty_tasklet(unsigned long arg
)
1410 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1412 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1415 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1418 netif_info(jme
, rx_status
, jme
->dev
, "RX Queue Full!\n");
1420 jme_rx_clean_tasklet(arg
);
1422 while (atomic_read(&jme
->rx_empty
) > 0) {
1423 atomic_dec(&jme
->rx_empty
);
1424 ++(NET_STAT(jme
).rx_dropped
);
1425 jme_restart_rx_engine(jme
);
1427 atomic_inc(&jme
->rx_empty
);
1431 jme_wake_queue_if_stopped(struct jme_adapter
*jme
)
1433 struct jme_ring
*txring
= &(jme
->txring
[0]);
1436 if (unlikely(netif_queue_stopped(jme
->dev
) &&
1437 atomic_read(&txring
->nr_free
) >= (jme
->tx_wake_threshold
))) {
1438 netif_info(jme
, tx_done
, jme
->dev
, "TX Queue Waked\n");
1439 netif_wake_queue(jme
->dev
);
1445 jme_tx_clean_tasklet(unsigned long arg
)
1447 struct jme_adapter
*jme
= (struct jme_adapter
*)arg
;
1448 struct jme_ring
*txring
= &(jme
->txring
[0]);
1449 struct txdesc
*txdesc
= txring
->desc
;
1450 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
, *ttxbi
;
1451 int i
, j
, cnt
= 0, max
, err
, mask
;
1453 tx_dbg(jme
, "Into txclean\n");
1455 if (unlikely(!atomic_dec_and_test(&jme
->tx_cleaning
)))
1458 if (unlikely(atomic_read(&jme
->link_changing
) != 1))
1461 if (unlikely(!netif_carrier_ok(jme
->dev
)))
1464 max
= jme
->tx_ring_size
- atomic_read(&txring
->nr_free
);
1465 mask
= jme
->tx_ring_mask
;
1467 for (i
= atomic_read(&txring
->next_to_clean
) ; cnt
< max
; ) {
1471 if (likely(ctxbi
->skb
&&
1472 !(txdesc
[i
].descwb
.flags
& TXWBFLAG_OWN
))) {
1474 tx_dbg(jme
, "txclean: %d+%d@%lu\n",
1475 i
, ctxbi
->nr_desc
, jiffies
);
1477 err
= txdesc
[i
].descwb
.flags
& TXWBFLAG_ALLERR
;
1479 for (j
= 1 ; j
< ctxbi
->nr_desc
; ++j
) {
1480 ttxbi
= txbi
+ ((i
+ j
) & (mask
));
1481 txdesc
[(i
+ j
) & (mask
)].dw
[0] = 0;
1483 pci_unmap_page(jme
->pdev
,
1492 dev_kfree_skb(ctxbi
->skb
);
1494 cnt
+= ctxbi
->nr_desc
;
1496 if (unlikely(err
)) {
1497 ++(NET_STAT(jme
).tx_carrier_errors
);
1499 ++(NET_STAT(jme
).tx_packets
);
1500 NET_STAT(jme
).tx_bytes
+= ctxbi
->len
;
1505 ctxbi
->start_xmit
= 0;
1511 i
= (i
+ ctxbi
->nr_desc
) & mask
;
1516 tx_dbg(jme
, "txclean: done %d@%lu\n", i
, jiffies
);
1517 atomic_set(&txring
->next_to_clean
, i
);
1518 atomic_add(cnt
, &txring
->nr_free
);
1520 jme_wake_queue_if_stopped(jme
);
1523 atomic_inc(&jme
->tx_cleaning
);
1527 jme_intr_msi(struct jme_adapter
*jme
, u32 intrstat
)
1532 jwrite32f(jme
, JME_IENC
, INTR_ENABLE
);
1534 if (intrstat
& (INTR_LINKCH
| INTR_SWINTR
)) {
1536 * Link change event is critical
1537 * all other events are ignored
1539 jwrite32(jme
, JME_IEVE
, intrstat
);
1540 tasklet_schedule(&jme
->linkch_task
);
1544 if (intrstat
& INTR_TMINTR
) {
1545 jwrite32(jme
, JME_IEVE
, INTR_TMINTR
);
1546 tasklet_schedule(&jme
->pcc_task
);
1549 if (intrstat
& (INTR_PCCTXTO
| INTR_PCCTX
)) {
1550 jwrite32(jme
, JME_IEVE
, INTR_PCCTXTO
| INTR_PCCTX
| INTR_TX0
);
1551 tasklet_schedule(&jme
->txclean_task
);
1554 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1555 jwrite32(jme
, JME_IEVE
, (intrstat
& (INTR_PCCRX0TO
|
1561 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
1562 if (intrstat
& INTR_RX0EMP
)
1563 atomic_inc(&jme
->rx_empty
);
1565 if ((intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
| INTR_RX0EMP
))) {
1566 if (likely(JME_RX_SCHEDULE_PREP(jme
))) {
1567 jme_polling_mode(jme
);
1568 JME_RX_SCHEDULE(jme
);
1572 if (intrstat
& INTR_RX0EMP
) {
1573 atomic_inc(&jme
->rx_empty
);
1574 tasklet_hi_schedule(&jme
->rxempty_task
);
1575 } else if (intrstat
& (INTR_PCCRX0TO
| INTR_PCCRX0
)) {
1576 tasklet_hi_schedule(&jme
->rxclean_task
);
1582 * Re-enable interrupt
1584 jwrite32f(jme
, JME_IENS
, INTR_ENABLE
);
1588 jme_intr(int irq
, void *dev_id
)
1590 struct net_device
*netdev
= dev_id
;
1591 struct jme_adapter
*jme
= netdev_priv(netdev
);
1594 intrstat
= jread32(jme
, JME_IEVE
);
1597 * Check if it's really an interrupt for us
1599 if (unlikely((intrstat
& INTR_ENABLE
) == 0))
1603 * Check if the device still exist
1605 if (unlikely(intrstat
== ~((typeof(intrstat
))0)))
1608 jme_intr_msi(jme
, intrstat
);
1614 jme_msi(int irq
, void *dev_id
)
1616 struct net_device
*netdev
= dev_id
;
1617 struct jme_adapter
*jme
= netdev_priv(netdev
);
1620 intrstat
= jread32(jme
, JME_IEVE
);
1622 jme_intr_msi(jme
, intrstat
);
1628 jme_reset_link(struct jme_adapter
*jme
)
1630 jwrite32(jme
, JME_TMCSR
, TMCSR_SWIT
);
1634 jme_restart_an(struct jme_adapter
*jme
)
1638 spin_lock_bh(&jme
->phy_lock
);
1639 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1640 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1641 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1642 spin_unlock_bh(&jme
->phy_lock
);
1646 jme_request_irq(struct jme_adapter
*jme
)
1649 struct net_device
*netdev
= jme
->dev
;
1650 irq_handler_t handler
= jme_intr
;
1651 int irq_flags
= IRQF_SHARED
;
1653 if (!pci_enable_msi(jme
->pdev
)) {
1654 set_bit(JME_FLAG_MSI
, &jme
->flags
);
1659 rc
= request_irq(jme
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
1663 "Unable to request %s interrupt (return: %d)\n",
1664 test_bit(JME_FLAG_MSI
, &jme
->flags
) ? "MSI" : "INTx",
1667 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1668 pci_disable_msi(jme
->pdev
);
1669 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1672 netdev
->irq
= jme
->pdev
->irq
;
1679 jme_free_irq(struct jme_adapter
*jme
)
1681 free_irq(jme
->pdev
->irq
, jme
->dev
);
1682 if (test_bit(JME_FLAG_MSI
, &jme
->flags
)) {
1683 pci_disable_msi(jme
->pdev
);
1684 clear_bit(JME_FLAG_MSI
, &jme
->flags
);
1685 jme
->dev
->irq
= jme
->pdev
->irq
;
1690 jme_new_phy_on(struct jme_adapter
*jme
)
1694 reg
= jread32(jme
, JME_PHY_PWR
);
1695 reg
&= ~(PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1696 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
);
1697 jwrite32(jme
, JME_PHY_PWR
, reg
);
1699 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1700 reg
&= ~PE1_GPREG0_PBG
;
1701 reg
|= PE1_GPREG0_ENBG
;
1702 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1706 jme_new_phy_off(struct jme_adapter
*jme
)
1710 reg
= jread32(jme
, JME_PHY_PWR
);
1711 reg
|= PHY_PWR_DWN1SEL
| PHY_PWR_DWN1SW
|
1712 PHY_PWR_DWN2
| PHY_PWR_CLKSEL
;
1713 jwrite32(jme
, JME_PHY_PWR
, reg
);
1715 pci_read_config_dword(jme
->pdev
, PCI_PRIV_PE1
, ®
);
1716 reg
&= ~PE1_GPREG0_PBG
;
1717 reg
|= PE1_GPREG0_PDD3COLD
;
1718 pci_write_config_dword(jme
->pdev
, PCI_PRIV_PE1
, reg
);
1722 jme_phy_on(struct jme_adapter
*jme
)
1726 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1727 bmcr
&= ~BMCR_PDOWN
;
1728 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1730 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1731 jme_new_phy_on(jme
);
1735 jme_phy_off(struct jme_adapter
*jme
)
1739 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1741 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, bmcr
);
1743 if (new_phy_power_ctrl(jme
->chip_main_rev
))
1744 jme_new_phy_off(jme
);
1748 jme_phy_specreg_read(struct jme_adapter
*jme
, u32 specreg
)
1752 phy_addr
= JM_PHY_SPEC_REG_READ
| specreg
;
1753 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_ADDR_REG
,
1755 return jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
,
1756 JM_PHY_SPEC_DATA_REG
);
1760 jme_phy_specreg_write(struct jme_adapter
*jme
, u32 ext_reg
, u32 phy_data
)
1764 phy_addr
= JM_PHY_SPEC_REG_WRITE
| ext_reg
;
1765 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_DATA_REG
,
1767 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, JM_PHY_SPEC_ADDR_REG
,
1772 jme_phy_calibration(struct jme_adapter
*jme
)
1774 u32 ctrl1000
, phy_data
;
1778 /* Enabel PHY test mode 1 */
1779 ctrl1000
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
);
1780 ctrl1000
&= ~PHY_GAD_TEST_MODE_MSK
;
1781 ctrl1000
|= PHY_GAD_TEST_MODE_1
;
1782 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
, ctrl1000
);
1784 phy_data
= jme_phy_specreg_read(jme
, JM_PHY_EXT_COMM_2_REG
);
1785 phy_data
&= ~JM_PHY_EXT_COMM_2_CALI_MODE_0
;
1786 phy_data
|= JM_PHY_EXT_COMM_2_CALI_LATCH
|
1787 JM_PHY_EXT_COMM_2_CALI_ENABLE
;
1788 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_2_REG
, phy_data
);
1790 phy_data
= jme_phy_specreg_read(jme
, JM_PHY_EXT_COMM_2_REG
);
1791 phy_data
&= ~(JM_PHY_EXT_COMM_2_CALI_ENABLE
|
1792 JM_PHY_EXT_COMM_2_CALI_MODE_0
|
1793 JM_PHY_EXT_COMM_2_CALI_LATCH
);
1794 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_2_REG
, phy_data
);
1796 /* Disable PHY test mode */
1797 ctrl1000
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
);
1798 ctrl1000
&= ~PHY_GAD_TEST_MODE_MSK
;
1799 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_CTRL1000
, ctrl1000
);
1804 jme_phy_setEA(struct jme_adapter
*jme
)
1806 u32 phy_comm0
= 0, phy_comm1
= 0;
1809 pci_read_config_byte(jme
->pdev
, PCI_PRIV_SHARE_NICCTRL
, &nic_ctrl
);
1810 if ((nic_ctrl
& 0x3) == JME_FLAG_PHYEA_ENABLE
)
1813 switch (jme
->pdev
->device
) {
1814 case PCI_DEVICE_ID_JMICRON_JMC250
:
1815 if (((jme
->chip_main_rev
== 5) &&
1816 ((jme
->chip_sub_rev
== 0) || (jme
->chip_sub_rev
== 1) ||
1817 (jme
->chip_sub_rev
== 3))) ||
1818 (jme
->chip_main_rev
>= 6)) {
1822 if ((jme
->chip_main_rev
== 3) &&
1823 ((jme
->chip_sub_rev
== 1) || (jme
->chip_sub_rev
== 2)))
1826 case PCI_DEVICE_ID_JMICRON_JMC260
:
1827 if (((jme
->chip_main_rev
== 5) &&
1828 ((jme
->chip_sub_rev
== 0) || (jme
->chip_sub_rev
== 1) ||
1829 (jme
->chip_sub_rev
== 3))) ||
1830 (jme
->chip_main_rev
>= 6)) {
1834 if ((jme
->chip_main_rev
== 3) &&
1835 ((jme
->chip_sub_rev
== 1) || (jme
->chip_sub_rev
== 2)))
1837 if ((jme
->chip_main_rev
== 2) && (jme
->chip_sub_rev
== 0))
1839 if ((jme
->chip_main_rev
== 2) && (jme
->chip_sub_rev
== 2))
1846 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_0_REG
, phy_comm0
);
1848 jme_phy_specreg_write(jme
, JM_PHY_EXT_COMM_1_REG
, phy_comm1
);
1854 jme_open(struct net_device
*netdev
)
1856 struct jme_adapter
*jme
= netdev_priv(netdev
);
1860 JME_NAPI_ENABLE(jme
);
1862 tasklet_enable(&jme
->linkch_task
);
1863 tasklet_enable(&jme
->txclean_task
);
1864 tasklet_hi_enable(&jme
->rxclean_task
);
1865 tasklet_hi_enable(&jme
->rxempty_task
);
1867 rc
= jme_request_irq(jme
);
1874 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
1875 jme_set_settings(netdev
, &jme
->old_ecmd
);
1877 jme_reset_phy_processor(jme
);
1878 jme_phy_calibration(jme
);
1880 jme_reset_link(jme
);
1885 netif_stop_queue(netdev
);
1886 netif_carrier_off(netdev
);
1891 jme_set_100m_half(struct jme_adapter
*jme
)
1896 bmcr
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
);
1897 tmp
= bmcr
& ~(BMCR_ANENABLE
| BMCR_SPEED100
|
1898 BMCR_SPEED1000
| BMCR_FULLDPLX
);
1899 tmp
|= BMCR_SPEED100
;
1902 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, MII_BMCR
, tmp
);
1905 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
| GHC_LINK_POLL
);
1907 jwrite32(jme
, JME_GHC
, GHC_SPEED_100M
);
1910 #define JME_WAIT_LINK_TIME 2000 /* 2000ms */
1912 jme_wait_link(struct jme_adapter
*jme
)
1914 u32 phylink
, to
= JME_WAIT_LINK_TIME
;
1917 phylink
= jme_linkstat_from_phy(jme
);
1918 while (!(phylink
& PHY_LINK_UP
) && (to
-= 10) > 0) {
1920 phylink
= jme_linkstat_from_phy(jme
);
1925 jme_powersave_phy(struct jme_adapter
*jme
)
1927 if (jme
->reg_pmcs
) {
1928 jme_set_100m_half(jme
);
1929 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
1938 jme_close(struct net_device
*netdev
)
1940 struct jme_adapter
*jme
= netdev_priv(netdev
);
1942 netif_stop_queue(netdev
);
1943 netif_carrier_off(netdev
);
1948 JME_NAPI_DISABLE(jme
);
1950 tasklet_disable(&jme
->linkch_task
);
1951 tasklet_disable(&jme
->txclean_task
);
1952 tasklet_disable(&jme
->rxclean_task
);
1953 tasklet_disable(&jme
->rxempty_task
);
1955 jme_disable_rx_engine(jme
);
1956 jme_disable_tx_engine(jme
);
1957 jme_reset_mac_processor(jme
);
1958 jme_free_rx_resources(jme
);
1959 jme_free_tx_resources(jme
);
1967 jme_alloc_txdesc(struct jme_adapter
*jme
,
1968 struct sk_buff
*skb
)
1970 struct jme_ring
*txring
= &(jme
->txring
[0]);
1971 int idx
, nr_alloc
, mask
= jme
->tx_ring_mask
;
1973 idx
= txring
->next_to_use
;
1974 nr_alloc
= skb_shinfo(skb
)->nr_frags
+ 2;
1976 if (unlikely(atomic_read(&txring
->nr_free
) < nr_alloc
))
1979 atomic_sub(nr_alloc
, &txring
->nr_free
);
1981 txring
->next_to_use
= (txring
->next_to_use
+ nr_alloc
) & mask
;
1987 jme_fill_tx_map(struct pci_dev
*pdev
,
1988 struct txdesc
*txdesc
,
1989 struct jme_buffer_info
*txbi
,
1997 dmaaddr
= pci_map_page(pdev
,
2003 pci_dma_sync_single_for_device(pdev
,
2010 txdesc
->desc2
.flags
= TXFLAG_OWN
;
2011 txdesc
->desc2
.flags
|= (hidma
) ? TXFLAG_64BIT
: 0;
2012 txdesc
->desc2
.datalen
= cpu_to_le16(len
);
2013 txdesc
->desc2
.bufaddrh
= cpu_to_le32((__u64
)dmaaddr
>> 32);
2014 txdesc
->desc2
.bufaddrl
= cpu_to_le32(
2015 (__u64
)dmaaddr
& 0xFFFFFFFFUL
);
2017 txbi
->mapping
= dmaaddr
;
2022 jme_map_tx_skb(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
2024 struct jme_ring
*txring
= &(jme
->txring
[0]);
2025 struct txdesc
*txdesc
= txring
->desc
, *ctxdesc
;
2026 struct jme_buffer_info
*txbi
= txring
->bufinf
, *ctxbi
;
2027 bool hidma
= jme
->dev
->features
& NETIF_F_HIGHDMA
;
2028 int i
, nr_frags
= skb_shinfo(skb
)->nr_frags
;
2029 int mask
= jme
->tx_ring_mask
;
2030 const struct skb_frag_struct
*frag
;
2033 for (i
= 0 ; i
< nr_frags
; ++i
) {
2034 frag
= &skb_shinfo(skb
)->frags
[i
];
2035 ctxdesc
= txdesc
+ ((idx
+ i
+ 2) & (mask
));
2036 ctxbi
= txbi
+ ((idx
+ i
+ 2) & (mask
));
2038 jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
,
2039 skb_frag_page(frag
),
2040 frag
->page_offset
, skb_frag_size(frag
), hidma
);
2043 len
= skb_is_nonlinear(skb
) ? skb_headlen(skb
) : skb
->len
;
2044 ctxdesc
= txdesc
+ ((idx
+ 1) & (mask
));
2045 ctxbi
= txbi
+ ((idx
+ 1) & (mask
));
2046 jme_fill_tx_map(jme
->pdev
, ctxdesc
, ctxbi
, virt_to_page(skb
->data
),
2047 offset_in_page(skb
->data
), len
, hidma
);
2052 jme_expand_header(struct jme_adapter
*jme
, struct sk_buff
*skb
)
2054 if (unlikely(skb_shinfo(skb
)->gso_size
&&
2055 skb_header_cloned(skb
) &&
2056 pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
))) {
2065 jme_tx_tso(struct sk_buff
*skb
, __le16
*mss
, u8
*flags
)
2067 *mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
<< TXDESC_MSS_SHIFT
);
2069 *flags
|= TXFLAG_LSEN
;
2071 if (skb
->protocol
== htons(ETH_P_IP
)) {
2072 struct iphdr
*iph
= ip_hdr(skb
);
2075 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2080 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
2082 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ip6h
->saddr
,
2095 jme_tx_csum(struct jme_adapter
*jme
, struct sk_buff
*skb
, u8
*flags
)
2097 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2100 switch (skb
->protocol
) {
2101 case htons(ETH_P_IP
):
2102 ip_proto
= ip_hdr(skb
)->protocol
;
2104 case htons(ETH_P_IPV6
):
2105 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
2114 *flags
|= TXFLAG_TCPCS
;
2117 *flags
|= TXFLAG_UDPCS
;
2120 netif_err(jme
, tx_err
, jme
->dev
, "Error upper layer protocol\n");
2127 jme_tx_vlan(struct sk_buff
*skb
, __le16
*vlan
, u8
*flags
)
2129 if (vlan_tx_tag_present(skb
)) {
2130 *flags
|= TXFLAG_TAGON
;
2131 *vlan
= cpu_to_le16(vlan_tx_tag_get(skb
));
2136 jme_fill_tx_desc(struct jme_adapter
*jme
, struct sk_buff
*skb
, int idx
)
2138 struct jme_ring
*txring
= &(jme
->txring
[0]);
2139 struct txdesc
*txdesc
;
2140 struct jme_buffer_info
*txbi
;
2143 txdesc
= (struct txdesc
*)txring
->desc
+ idx
;
2144 txbi
= txring
->bufinf
+ idx
;
2150 txdesc
->desc1
.pktsize
= cpu_to_le16(skb
->len
);
2152 * Set OWN bit at final.
2153 * When kernel transmit faster than NIC.
2154 * And NIC trying to send this descriptor before we tell
2155 * it to start sending this TX queue.
2156 * Other fields are already filled correctly.
2159 flags
= TXFLAG_OWN
| TXFLAG_INT
;
2161 * Set checksum flags while not tso
2163 if (jme_tx_tso(skb
, &txdesc
->desc1
.mss
, &flags
))
2164 jme_tx_csum(jme
, skb
, &flags
);
2165 jme_tx_vlan(skb
, &txdesc
->desc1
.vlan
, &flags
);
2166 jme_map_tx_skb(jme
, skb
, idx
);
2167 txdesc
->desc1
.flags
= flags
;
2169 * Set tx buffer info after telling NIC to send
2170 * For better tx_clean timing
2173 txbi
->nr_desc
= skb_shinfo(skb
)->nr_frags
+ 2;
2175 txbi
->len
= skb
->len
;
2176 txbi
->start_xmit
= jiffies
;
2177 if (!txbi
->start_xmit
)
2178 txbi
->start_xmit
= (0UL-1);
2184 jme_stop_queue_if_full(struct jme_adapter
*jme
)
2186 struct jme_ring
*txring
= &(jme
->txring
[0]);
2187 struct jme_buffer_info
*txbi
= txring
->bufinf
;
2188 int idx
= atomic_read(&txring
->next_to_clean
);
2193 if (unlikely(atomic_read(&txring
->nr_free
) < (MAX_SKB_FRAGS
+2))) {
2194 netif_stop_queue(jme
->dev
);
2195 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Paused\n");
2197 if (atomic_read(&txring
->nr_free
)
2198 >= (jme
->tx_wake_threshold
)) {
2199 netif_wake_queue(jme
->dev
);
2200 netif_info(jme
, tx_queued
, jme
->dev
, "TX Queue Fast Waked\n");
2204 if (unlikely(txbi
->start_xmit
&&
2205 (jiffies
- txbi
->start_xmit
) >= TX_TIMEOUT
&&
2207 netif_stop_queue(jme
->dev
);
2208 netif_info(jme
, tx_queued
, jme
->dev
,
2209 "TX Queue Stopped %d@%lu\n", idx
, jiffies
);
2214 * This function is already protected by netif_tx_lock()
2218 jme_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
2220 struct jme_adapter
*jme
= netdev_priv(netdev
);
2223 if (unlikely(jme_expand_header(jme
, skb
))) {
2224 ++(NET_STAT(jme
).tx_dropped
);
2225 return NETDEV_TX_OK
;
2228 idx
= jme_alloc_txdesc(jme
, skb
);
2230 if (unlikely(idx
< 0)) {
2231 netif_stop_queue(netdev
);
2232 netif_err(jme
, tx_err
, jme
->dev
,
2233 "BUG! Tx ring full when queue awake!\n");
2235 return NETDEV_TX_BUSY
;
2238 jme_fill_tx_desc(jme
, skb
, idx
);
2240 jwrite32(jme
, JME_TXCS
, jme
->reg_txcs
|
2241 TXCS_SELECT_QUEUE0
|
2245 tx_dbg(jme
, "xmit: %d+%d@%lu\n",
2246 idx
, skb_shinfo(skb
)->nr_frags
+ 2, jiffies
);
2247 jme_stop_queue_if_full(jme
);
2249 return NETDEV_TX_OK
;
2253 jme_set_unicastaddr(struct net_device
*netdev
)
2255 struct jme_adapter
*jme
= netdev_priv(netdev
);
2258 val
= (netdev
->dev_addr
[3] & 0xff) << 24 |
2259 (netdev
->dev_addr
[2] & 0xff) << 16 |
2260 (netdev
->dev_addr
[1] & 0xff) << 8 |
2261 (netdev
->dev_addr
[0] & 0xff);
2262 jwrite32(jme
, JME_RXUMA_LO
, val
);
2263 val
= (netdev
->dev_addr
[5] & 0xff) << 8 |
2264 (netdev
->dev_addr
[4] & 0xff);
2265 jwrite32(jme
, JME_RXUMA_HI
, val
);
2269 jme_set_macaddr(struct net_device
*netdev
, void *p
)
2271 struct jme_adapter
*jme
= netdev_priv(netdev
);
2272 struct sockaddr
*addr
= p
;
2274 if (netif_running(netdev
))
2277 spin_lock_bh(&jme
->macaddr_lock
);
2278 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2279 jme_set_unicastaddr(netdev
);
2280 spin_unlock_bh(&jme
->macaddr_lock
);
2286 jme_set_multi(struct net_device
*netdev
)
2288 struct jme_adapter
*jme
= netdev_priv(netdev
);
2289 u32 mc_hash
[2] = {};
2291 spin_lock_bh(&jme
->rxmcs_lock
);
2293 jme
->reg_rxmcs
|= RXMCS_BRDFRAME
| RXMCS_UNIFRAME
;
2295 if (netdev
->flags
& IFF_PROMISC
) {
2296 jme
->reg_rxmcs
|= RXMCS_ALLFRAME
;
2297 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2298 jme
->reg_rxmcs
|= RXMCS_ALLMULFRAME
;
2299 } else if (netdev
->flags
& IFF_MULTICAST
) {
2300 struct netdev_hw_addr
*ha
;
2303 jme
->reg_rxmcs
|= RXMCS_MULFRAME
| RXMCS_MULFILTERED
;
2304 netdev_for_each_mc_addr(ha
, netdev
) {
2305 bit_nr
= ether_crc(ETH_ALEN
, ha
->addr
) & 0x3F;
2306 mc_hash
[bit_nr
>> 5] |= 1 << (bit_nr
& 0x1F);
2309 jwrite32(jme
, JME_RXMCHT_LO
, mc_hash
[0]);
2310 jwrite32(jme
, JME_RXMCHT_HI
, mc_hash
[1]);
2314 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2316 spin_unlock_bh(&jme
->rxmcs_lock
);
2320 jme_change_mtu(struct net_device
*netdev
, int new_mtu
)
2322 struct jme_adapter
*jme
= netdev_priv(netdev
);
2324 if (new_mtu
== jme
->old_mtu
)
2327 if (((new_mtu
+ ETH_HLEN
) > MAX_ETHERNET_JUMBO_PACKET_SIZE
) ||
2328 ((new_mtu
) < IPV6_MIN_MTU
))
2332 netdev
->mtu
= new_mtu
;
2333 netdev_update_features(netdev
);
2335 jme_restart_rx_engine(jme
);
2336 jme_reset_link(jme
);
2342 jme_tx_timeout(struct net_device
*netdev
)
2344 struct jme_adapter
*jme
= netdev_priv(netdev
);
2347 jme_reset_phy_processor(jme
);
2348 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
2349 jme_set_settings(netdev
, &jme
->old_ecmd
);
2352 * Force to Reset the link again
2354 jme_reset_link(jme
);
2357 static inline void jme_pause_rx(struct jme_adapter
*jme
)
2359 atomic_dec(&jme
->link_changing
);
2361 jme_set_rx_pcc(jme
, PCC_OFF
);
2362 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2363 JME_NAPI_DISABLE(jme
);
2365 tasklet_disable(&jme
->rxclean_task
);
2366 tasklet_disable(&jme
->rxempty_task
);
2370 static inline void jme_resume_rx(struct jme_adapter
*jme
)
2372 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2374 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2375 JME_NAPI_ENABLE(jme
);
2377 tasklet_hi_enable(&jme
->rxclean_task
);
2378 tasklet_hi_enable(&jme
->rxempty_task
);
2381 dpi
->attempt
= PCC_P1
;
2383 jme_set_rx_pcc(jme
, PCC_P1
);
2385 atomic_inc(&jme
->link_changing
);
2389 jme_get_drvinfo(struct net_device
*netdev
,
2390 struct ethtool_drvinfo
*info
)
2392 struct jme_adapter
*jme
= netdev_priv(netdev
);
2394 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
2395 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
2396 strlcpy(info
->bus_info
, pci_name(jme
->pdev
), sizeof(info
->bus_info
));
2400 jme_get_regs_len(struct net_device
*netdev
)
2406 mmapio_memcpy(struct jme_adapter
*jme
, u32
*p
, u32 reg
, int len
)
2410 for (i
= 0 ; i
< len
; i
+= 4)
2411 p
[i
>> 2] = jread32(jme
, reg
+ i
);
2415 mdio_memcpy(struct jme_adapter
*jme
, u32
*p
, int reg_nr
)
2418 u16
*p16
= (u16
*)p
;
2420 for (i
= 0 ; i
< reg_nr
; ++i
)
2421 p16
[i
] = jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, i
);
2425 jme_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
2427 struct jme_adapter
*jme
= netdev_priv(netdev
);
2428 u32
*p32
= (u32
*)p
;
2430 memset(p
, 0xFF, JME_REG_LEN
);
2433 mmapio_memcpy(jme
, p32
, JME_MAC
, JME_MAC_LEN
);
2436 mmapio_memcpy(jme
, p32
, JME_PHY
, JME_PHY_LEN
);
2439 mmapio_memcpy(jme
, p32
, JME_MISC
, JME_MISC_LEN
);
2442 mmapio_memcpy(jme
, p32
, JME_RSS
, JME_RSS_LEN
);
2445 mdio_memcpy(jme
, p32
, JME_PHY_REG_NR
);
2449 jme_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2451 struct jme_adapter
*jme
= netdev_priv(netdev
);
2453 ecmd
->tx_coalesce_usecs
= PCC_TX_TO
;
2454 ecmd
->tx_max_coalesced_frames
= PCC_TX_CNT
;
2456 if (test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2457 ecmd
->use_adaptive_rx_coalesce
= false;
2458 ecmd
->rx_coalesce_usecs
= 0;
2459 ecmd
->rx_max_coalesced_frames
= 0;
2463 ecmd
->use_adaptive_rx_coalesce
= true;
2465 switch (jme
->dpi
.cur
) {
2467 ecmd
->rx_coalesce_usecs
= PCC_P1_TO
;
2468 ecmd
->rx_max_coalesced_frames
= PCC_P1_CNT
;
2471 ecmd
->rx_coalesce_usecs
= PCC_P2_TO
;
2472 ecmd
->rx_max_coalesced_frames
= PCC_P2_CNT
;
2475 ecmd
->rx_coalesce_usecs
= PCC_P3_TO
;
2476 ecmd
->rx_max_coalesced_frames
= PCC_P3_CNT
;
2486 jme_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ecmd
)
2488 struct jme_adapter
*jme
= netdev_priv(netdev
);
2489 struct dynpcc_info
*dpi
= &(jme
->dpi
);
2491 if (netif_running(netdev
))
2494 if (ecmd
->use_adaptive_rx_coalesce
&&
2495 test_bit(JME_FLAG_POLL
, &jme
->flags
)) {
2496 clear_bit(JME_FLAG_POLL
, &jme
->flags
);
2497 jme
->jme_rx
= netif_rx
;
2499 dpi
->attempt
= PCC_P1
;
2501 jme_set_rx_pcc(jme
, PCC_P1
);
2502 jme_interrupt_mode(jme
);
2503 } else if (!(ecmd
->use_adaptive_rx_coalesce
) &&
2504 !(test_bit(JME_FLAG_POLL
, &jme
->flags
))) {
2505 set_bit(JME_FLAG_POLL
, &jme
->flags
);
2506 jme
->jme_rx
= netif_receive_skb
;
2507 jme_interrupt_mode(jme
);
2514 jme_get_pauseparam(struct net_device
*netdev
,
2515 struct ethtool_pauseparam
*ecmd
)
2517 struct jme_adapter
*jme
= netdev_priv(netdev
);
2520 ecmd
->tx_pause
= (jme
->reg_txpfc
& TXPFC_PF_EN
) != 0;
2521 ecmd
->rx_pause
= (jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0;
2523 spin_lock_bh(&jme
->phy_lock
);
2524 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2525 spin_unlock_bh(&jme
->phy_lock
);
2528 (val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0;
2532 jme_set_pauseparam(struct net_device
*netdev
,
2533 struct ethtool_pauseparam
*ecmd
)
2535 struct jme_adapter
*jme
= netdev_priv(netdev
);
2538 if (((jme
->reg_txpfc
& TXPFC_PF_EN
) != 0) ^
2539 (ecmd
->tx_pause
!= 0)) {
2542 jme
->reg_txpfc
|= TXPFC_PF_EN
;
2544 jme
->reg_txpfc
&= ~TXPFC_PF_EN
;
2546 jwrite32(jme
, JME_TXPFC
, jme
->reg_txpfc
);
2549 spin_lock_bh(&jme
->rxmcs_lock
);
2550 if (((jme
->reg_rxmcs
& RXMCS_FLOWCTRL
) != 0) ^
2551 (ecmd
->rx_pause
!= 0)) {
2554 jme
->reg_rxmcs
|= RXMCS_FLOWCTRL
;
2556 jme
->reg_rxmcs
&= ~RXMCS_FLOWCTRL
;
2558 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2560 spin_unlock_bh(&jme
->rxmcs_lock
);
2562 spin_lock_bh(&jme
->phy_lock
);
2563 val
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, MII_ADVERTISE
);
2564 if (((val
& (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
)) != 0) ^
2565 (ecmd
->autoneg
!= 0)) {
2568 val
|= (ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2570 val
&= ~(ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
);
2572 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
,
2573 MII_ADVERTISE
, val
);
2575 spin_unlock_bh(&jme
->phy_lock
);
2581 jme_get_wol(struct net_device
*netdev
,
2582 struct ethtool_wolinfo
*wol
)
2584 struct jme_adapter
*jme
= netdev_priv(netdev
);
2586 wol
->supported
= WAKE_MAGIC
| WAKE_PHY
;
2590 if (jme
->reg_pmcs
& (PMCS_LFEN
| PMCS_LREN
))
2591 wol
->wolopts
|= WAKE_PHY
;
2593 if (jme
->reg_pmcs
& PMCS_MFEN
)
2594 wol
->wolopts
|= WAKE_MAGIC
;
2599 jme_set_wol(struct net_device
*netdev
,
2600 struct ethtool_wolinfo
*wol
)
2602 struct jme_adapter
*jme
= netdev_priv(netdev
);
2604 if (wol
->wolopts
& (WAKE_MAGICSECURE
|
2613 if (wol
->wolopts
& WAKE_PHY
)
2614 jme
->reg_pmcs
|= PMCS_LFEN
| PMCS_LREN
;
2616 if (wol
->wolopts
& WAKE_MAGIC
)
2617 jme
->reg_pmcs
|= PMCS_MFEN
;
2619 jwrite32(jme
, JME_PMCS
, jme
->reg_pmcs
);
2620 device_set_wakeup_enable(&jme
->pdev
->dev
, !!(jme
->reg_pmcs
));
2626 jme_get_settings(struct net_device
*netdev
,
2627 struct ethtool_cmd
*ecmd
)
2629 struct jme_adapter
*jme
= netdev_priv(netdev
);
2632 spin_lock_bh(&jme
->phy_lock
);
2633 rc
= mii_ethtool_gset(&(jme
->mii_if
), ecmd
);
2634 spin_unlock_bh(&jme
->phy_lock
);
2639 jme_set_settings(struct net_device
*netdev
,
2640 struct ethtool_cmd
*ecmd
)
2642 struct jme_adapter
*jme
= netdev_priv(netdev
);
2645 if (ethtool_cmd_speed(ecmd
) == SPEED_1000
2646 && ecmd
->autoneg
!= AUTONEG_ENABLE
)
2650 * Check If user changed duplex only while force_media.
2651 * Hardware would not generate link change interrupt.
2653 if (jme
->mii_if
.force_media
&&
2654 ecmd
->autoneg
!= AUTONEG_ENABLE
&&
2655 (jme
->mii_if
.full_duplex
!= ecmd
->duplex
))
2658 spin_lock_bh(&jme
->phy_lock
);
2659 rc
= mii_ethtool_sset(&(jme
->mii_if
), ecmd
);
2660 spin_unlock_bh(&jme
->phy_lock
);
2664 jme_reset_link(jme
);
2665 jme
->old_ecmd
= *ecmd
;
2666 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2673 jme_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
2676 struct jme_adapter
*jme
= netdev_priv(netdev
);
2677 struct mii_ioctl_data
*mii_data
= if_mii(rq
);
2678 unsigned int duplex_chg
;
2680 if (cmd
== SIOCSMIIREG
) {
2681 u16 val
= mii_data
->val_in
;
2682 if (!(val
& (BMCR_RESET
|BMCR_ANENABLE
)) &&
2683 (val
& BMCR_SPEED1000
))
2687 spin_lock_bh(&jme
->phy_lock
);
2688 rc
= generic_mii_ioctl(&jme
->mii_if
, mii_data
, cmd
, &duplex_chg
);
2689 spin_unlock_bh(&jme
->phy_lock
);
2691 if (!rc
&& (cmd
== SIOCSMIIREG
)) {
2693 jme_reset_link(jme
);
2694 jme_get_settings(netdev
, &jme
->old_ecmd
);
2695 set_bit(JME_FLAG_SSET
, &jme
->flags
);
2702 jme_get_link(struct net_device
*netdev
)
2704 struct jme_adapter
*jme
= netdev_priv(netdev
);
2705 return jread32(jme
, JME_PHY_LINK
) & PHY_LINK_UP
;
2709 jme_get_msglevel(struct net_device
*netdev
)
2711 struct jme_adapter
*jme
= netdev_priv(netdev
);
2712 return jme
->msg_enable
;
2716 jme_set_msglevel(struct net_device
*netdev
, u32 value
)
2718 struct jme_adapter
*jme
= netdev_priv(netdev
);
2719 jme
->msg_enable
= value
;
2722 static netdev_features_t
2723 jme_fix_features(struct net_device
*netdev
, netdev_features_t features
)
2725 if (netdev
->mtu
> 1900)
2726 features
&= ~(NETIF_F_ALL_TSO
| NETIF_F_ALL_CSUM
);
2731 jme_set_features(struct net_device
*netdev
, netdev_features_t features
)
2733 struct jme_adapter
*jme
= netdev_priv(netdev
);
2735 spin_lock_bh(&jme
->rxmcs_lock
);
2736 if (features
& NETIF_F_RXCSUM
)
2737 jme
->reg_rxmcs
|= RXMCS_CHECKSUM
;
2739 jme
->reg_rxmcs
&= ~RXMCS_CHECKSUM
;
2740 jwrite32(jme
, JME_RXMCS
, jme
->reg_rxmcs
);
2741 spin_unlock_bh(&jme
->rxmcs_lock
);
2747 jme_nway_reset(struct net_device
*netdev
)
2749 struct jme_adapter
*jme
= netdev_priv(netdev
);
2750 jme_restart_an(jme
);
2755 jme_smb_read(struct jme_adapter
*jme
, unsigned int addr
)
2760 val
= jread32(jme
, JME_SMBCSR
);
2761 to
= JME_SMB_BUSY_TIMEOUT
;
2762 while ((val
& SMBCSR_BUSY
) && --to
) {
2764 val
= jread32(jme
, JME_SMBCSR
);
2767 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2771 jwrite32(jme
, JME_SMBINTF
,
2772 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2773 SMBINTF_HWRWN_READ
|
2776 val
= jread32(jme
, JME_SMBINTF
);
2777 to
= JME_SMB_BUSY_TIMEOUT
;
2778 while ((val
& SMBINTF_HWCMD
) && --to
) {
2780 val
= jread32(jme
, JME_SMBINTF
);
2783 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2787 return (val
& SMBINTF_HWDATR
) >> SMBINTF_HWDATR_SHIFT
;
2791 jme_smb_write(struct jme_adapter
*jme
, unsigned int addr
, u8 data
)
2796 val
= jread32(jme
, JME_SMBCSR
);
2797 to
= JME_SMB_BUSY_TIMEOUT
;
2798 while ((val
& SMBCSR_BUSY
) && --to
) {
2800 val
= jread32(jme
, JME_SMBCSR
);
2803 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2807 jwrite32(jme
, JME_SMBINTF
,
2808 ((data
<< SMBINTF_HWDATW_SHIFT
) & SMBINTF_HWDATW
) |
2809 ((addr
<< SMBINTF_HWADDR_SHIFT
) & SMBINTF_HWADDR
) |
2810 SMBINTF_HWRWN_WRITE
|
2813 val
= jread32(jme
, JME_SMBINTF
);
2814 to
= JME_SMB_BUSY_TIMEOUT
;
2815 while ((val
& SMBINTF_HWCMD
) && --to
) {
2817 val
= jread32(jme
, JME_SMBINTF
);
2820 netif_err(jme
, hw
, jme
->dev
, "SMB Bus Busy\n");
2828 jme_get_eeprom_len(struct net_device
*netdev
)
2830 struct jme_adapter
*jme
= netdev_priv(netdev
);
2832 val
= jread32(jme
, JME_SMBCSR
);
2833 return (val
& SMBCSR_EEPROMD
) ? JME_SMB_LEN
: 0;
2837 jme_get_eeprom(struct net_device
*netdev
,
2838 struct ethtool_eeprom
*eeprom
, u8
*data
)
2840 struct jme_adapter
*jme
= netdev_priv(netdev
);
2841 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2844 * ethtool will check the boundary for us
2846 eeprom
->magic
= JME_EEPROM_MAGIC
;
2847 for (i
= 0 ; i
< len
; ++i
)
2848 data
[i
] = jme_smb_read(jme
, i
+ offset
);
2854 jme_set_eeprom(struct net_device
*netdev
,
2855 struct ethtool_eeprom
*eeprom
, u8
*data
)
2857 struct jme_adapter
*jme
= netdev_priv(netdev
);
2858 int i
, offset
= eeprom
->offset
, len
= eeprom
->len
;
2860 if (eeprom
->magic
!= JME_EEPROM_MAGIC
)
2864 * ethtool will check the boundary for us
2866 for (i
= 0 ; i
< len
; ++i
)
2867 jme_smb_write(jme
, i
+ offset
, data
[i
]);
2872 static const struct ethtool_ops jme_ethtool_ops
= {
2873 .get_drvinfo
= jme_get_drvinfo
,
2874 .get_regs_len
= jme_get_regs_len
,
2875 .get_regs
= jme_get_regs
,
2876 .get_coalesce
= jme_get_coalesce
,
2877 .set_coalesce
= jme_set_coalesce
,
2878 .get_pauseparam
= jme_get_pauseparam
,
2879 .set_pauseparam
= jme_set_pauseparam
,
2880 .get_wol
= jme_get_wol
,
2881 .set_wol
= jme_set_wol
,
2882 .get_settings
= jme_get_settings
,
2883 .set_settings
= jme_set_settings
,
2884 .get_link
= jme_get_link
,
2885 .get_msglevel
= jme_get_msglevel
,
2886 .set_msglevel
= jme_set_msglevel
,
2887 .nway_reset
= jme_nway_reset
,
2888 .get_eeprom_len
= jme_get_eeprom_len
,
2889 .get_eeprom
= jme_get_eeprom
,
2890 .set_eeprom
= jme_set_eeprom
,
2894 jme_pci_dma64(struct pci_dev
*pdev
)
2896 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2897 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
2898 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
2901 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
&&
2902 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(40)))
2903 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(40)))
2906 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)))
2907 if (!pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
2914 jme_phy_init(struct jme_adapter
*jme
)
2918 reg26
= jme_mdio_read(jme
->dev
, jme
->mii_if
.phy_id
, 26);
2919 jme_mdio_write(jme
->dev
, jme
->mii_if
.phy_id
, 26, reg26
| 0x1000);
2923 jme_check_hw_ver(struct jme_adapter
*jme
)
2927 chipmode
= jread32(jme
, JME_CHIPMODE
);
2929 jme
->fpgaver
= (chipmode
& CM_FPGAVER_MASK
) >> CM_FPGAVER_SHIFT
;
2930 jme
->chiprev
= (chipmode
& CM_CHIPREV_MASK
) >> CM_CHIPREV_SHIFT
;
2931 jme
->chip_main_rev
= jme
->chiprev
& 0xF;
2932 jme
->chip_sub_rev
= (jme
->chiprev
>> 4) & 0xF;
2935 static const struct net_device_ops jme_netdev_ops
= {
2936 .ndo_open
= jme_open
,
2937 .ndo_stop
= jme_close
,
2938 .ndo_validate_addr
= eth_validate_addr
,
2939 .ndo_do_ioctl
= jme_ioctl
,
2940 .ndo_start_xmit
= jme_start_xmit
,
2941 .ndo_set_mac_address
= jme_set_macaddr
,
2942 .ndo_set_rx_mode
= jme_set_multi
,
2943 .ndo_change_mtu
= jme_change_mtu
,
2944 .ndo_tx_timeout
= jme_tx_timeout
,
2945 .ndo_fix_features
= jme_fix_features
,
2946 .ndo_set_features
= jme_set_features
,
2949 static int __devinit
2950 jme_init_one(struct pci_dev
*pdev
,
2951 const struct pci_device_id
*ent
)
2953 int rc
= 0, using_dac
, i
;
2954 struct net_device
*netdev
;
2955 struct jme_adapter
*jme
;
2960 * set up PCI device basics
2962 rc
= pci_enable_device(pdev
);
2964 pr_err("Cannot enable PCI device\n");
2968 using_dac
= jme_pci_dma64(pdev
);
2969 if (using_dac
< 0) {
2970 pr_err("Cannot set PCI DMA Mask\n");
2972 goto err_out_disable_pdev
;
2975 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
2976 pr_err("No PCI resource region found\n");
2978 goto err_out_disable_pdev
;
2981 rc
= pci_request_regions(pdev
, DRV_NAME
);
2983 pr_err("Cannot obtain PCI resource region\n");
2984 goto err_out_disable_pdev
;
2987 pci_set_master(pdev
);
2990 * alloc and init net device
2992 netdev
= alloc_etherdev(sizeof(*jme
));
2994 pr_err("Cannot allocate netdev structure\n");
2996 goto err_out_release_regions
;
2998 netdev
->netdev_ops
= &jme_netdev_ops
;
2999 netdev
->ethtool_ops
= &jme_ethtool_ops
;
3000 netdev
->watchdog_timeo
= TX_TIMEOUT
;
3001 netdev
->hw_features
= NETIF_F_IP_CSUM
|
3007 netdev
->features
= NETIF_F_IP_CSUM
|
3012 NETIF_F_HW_VLAN_TX
|
3015 netdev
->features
|= NETIF_F_HIGHDMA
;
3017 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3018 pci_set_drvdata(pdev
, netdev
);
3023 jme
= netdev_priv(netdev
);
3026 jme
->jme_rx
= netif_rx
;
3027 jme
->old_mtu
= netdev
->mtu
= 1500;
3029 jme
->tx_ring_size
= 1 << 10;
3030 jme
->tx_ring_mask
= jme
->tx_ring_size
- 1;
3031 jme
->tx_wake_threshold
= 1 << 9;
3032 jme
->rx_ring_size
= 1 << 9;
3033 jme
->rx_ring_mask
= jme
->rx_ring_size
- 1;
3034 jme
->msg_enable
= JME_DEF_MSG_ENABLE
;
3035 jme
->regs
= ioremap(pci_resource_start(pdev
, 0),
3036 pci_resource_len(pdev
, 0));
3038 pr_err("Mapping PCI resource region error\n");
3040 goto err_out_free_netdev
;
3044 apmc
= jread32(jme
, JME_APMC
) & ~JME_APMC_PSEUDO_HP_EN
;
3045 jwrite32(jme
, JME_APMC
, apmc
);
3046 } else if (force_pseudohp
) {
3047 apmc
= jread32(jme
, JME_APMC
) | JME_APMC_PSEUDO_HP_EN
;
3048 jwrite32(jme
, JME_APMC
, apmc
);
3051 NETIF_NAPI_SET(netdev
, &jme
->napi
, jme_poll
, jme
->rx_ring_size
>> 2)
3053 spin_lock_init(&jme
->phy_lock
);
3054 spin_lock_init(&jme
->macaddr_lock
);
3055 spin_lock_init(&jme
->rxmcs_lock
);
3057 atomic_set(&jme
->link_changing
, 1);
3058 atomic_set(&jme
->rx_cleaning
, 1);
3059 atomic_set(&jme
->tx_cleaning
, 1);
3060 atomic_set(&jme
->rx_empty
, 1);
3062 tasklet_init(&jme
->pcc_task
,
3064 (unsigned long) jme
);
3065 tasklet_init(&jme
->linkch_task
,
3066 jme_link_change_tasklet
,
3067 (unsigned long) jme
);
3068 tasklet_init(&jme
->txclean_task
,
3069 jme_tx_clean_tasklet
,
3070 (unsigned long) jme
);
3071 tasklet_init(&jme
->rxclean_task
,
3072 jme_rx_clean_tasklet
,
3073 (unsigned long) jme
);
3074 tasklet_init(&jme
->rxempty_task
,
3075 jme_rx_empty_tasklet
,
3076 (unsigned long) jme
);
3077 tasklet_disable_nosync(&jme
->linkch_task
);
3078 tasklet_disable_nosync(&jme
->txclean_task
);
3079 tasklet_disable_nosync(&jme
->rxclean_task
);
3080 tasklet_disable_nosync(&jme
->rxempty_task
);
3081 jme
->dpi
.cur
= PCC_P1
;
3084 jme
->reg_rxcs
= RXCS_DEFAULT
;
3085 jme
->reg_rxmcs
= RXMCS_DEFAULT
;
3087 jme
->reg_pmcs
= PMCS_MFEN
;
3088 jme
->reg_gpreg1
= GPREG1_DEFAULT
;
3090 if (jme
->reg_rxmcs
& RXMCS_CHECKSUM
)
3091 netdev
->features
|= NETIF_F_RXCSUM
;
3094 * Get Max Read Req Size from PCI Config Space
3096 pci_read_config_byte(pdev
, PCI_DCSR_MRRS
, &jme
->mrrs
);
3097 jme
->mrrs
&= PCI_DCSR_MRRS_MASK
;
3098 switch (jme
->mrrs
) {
3100 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_128B
;
3103 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_256B
;
3106 jme
->reg_txcs
= TXCS_DEFAULT
| TXCS_DMASIZE_512B
;
3111 * Must check before reset_mac_processor
3113 jme_check_hw_ver(jme
);
3114 jme
->mii_if
.dev
= netdev
;
3116 jme
->mii_if
.phy_id
= 0;
3117 for (i
= 1 ; i
< 32 ; ++i
) {
3118 bmcr
= jme_mdio_read(netdev
, i
, MII_BMCR
);
3119 bmsr
= jme_mdio_read(netdev
, i
, MII_BMSR
);
3120 if (bmcr
!= 0xFFFFU
&& (bmcr
!= 0 || bmsr
!= 0)) {
3121 jme
->mii_if
.phy_id
= i
;
3126 if (!jme
->mii_if
.phy_id
) {
3128 pr_err("Can not find phy_id\n");
3132 jme
->reg_ghc
|= GHC_LINK_POLL
;
3134 jme
->mii_if
.phy_id
= 1;
3136 if (pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
)
3137 jme
->mii_if
.supports_gmii
= true;
3139 jme
->mii_if
.supports_gmii
= false;
3140 jme
->mii_if
.phy_id_mask
= 0x1F;
3141 jme
->mii_if
.reg_num_mask
= 0x1F;
3142 jme
->mii_if
.mdio_read
= jme_mdio_read
;
3143 jme
->mii_if
.mdio_write
= jme_mdio_write
;
3146 pci_set_power_state(jme
->pdev
, PCI_D0
);
3147 device_set_wakeup_enable(&pdev
->dev
, true);
3149 jme_set_phyfifo_5level(jme
);
3150 jme
->pcirev
= pdev
->revision
;
3156 * Reset MAC processor and reload EEPROM for MAC Address
3158 jme_reset_mac_processor(jme
);
3159 rc
= jme_reload_eeprom(jme
);
3161 pr_err("Reload eeprom for reading MAC Address error\n");
3164 jme_load_macaddr(netdev
);
3167 * Tell stack that we are not ready to work until open()
3169 netif_carrier_off(netdev
);
3171 rc
= register_netdev(netdev
);
3173 pr_err("Cannot register net device\n");
3177 netif_info(jme
, probe
, jme
->dev
, "%s%s chiprev:%x pcirev:%x macaddr:%pM\n",
3178 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC250
) ?
3179 "JMC250 Gigabit Ethernet" :
3180 (jme
->pdev
->device
== PCI_DEVICE_ID_JMICRON_JMC260
) ?
3181 "JMC260 Fast Ethernet" : "Unknown",
3182 (jme
->fpgaver
!= 0) ? " (FPGA)" : "",
3183 (jme
->fpgaver
!= 0) ? jme
->fpgaver
: jme
->chiprev
,
3184 jme
->pcirev
, netdev
->dev_addr
);
3190 err_out_free_netdev
:
3191 pci_set_drvdata(pdev
, NULL
);
3192 free_netdev(netdev
);
3193 err_out_release_regions
:
3194 pci_release_regions(pdev
);
3195 err_out_disable_pdev
:
3196 pci_disable_device(pdev
);
3201 static void __devexit
3202 jme_remove_one(struct pci_dev
*pdev
)
3204 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3205 struct jme_adapter
*jme
= netdev_priv(netdev
);
3207 unregister_netdev(netdev
);
3209 pci_set_drvdata(pdev
, NULL
);
3210 free_netdev(netdev
);
3211 pci_release_regions(pdev
);
3212 pci_disable_device(pdev
);
3217 jme_shutdown(struct pci_dev
*pdev
)
3219 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3220 struct jme_adapter
*jme
= netdev_priv(netdev
);
3222 jme_powersave_phy(jme
);
3223 pci_pme_active(pdev
, true);
3226 #ifdef CONFIG_PM_SLEEP
3228 jme_suspend(struct device
*dev
)
3230 struct pci_dev
*pdev
= to_pci_dev(dev
);
3231 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3232 struct jme_adapter
*jme
= netdev_priv(netdev
);
3234 if (!netif_running(netdev
))
3237 atomic_dec(&jme
->link_changing
);
3239 netif_device_detach(netdev
);
3240 netif_stop_queue(netdev
);
3243 tasklet_disable(&jme
->txclean_task
);
3244 tasklet_disable(&jme
->rxclean_task
);
3245 tasklet_disable(&jme
->rxempty_task
);
3247 if (netif_carrier_ok(netdev
)) {
3248 if (test_bit(JME_FLAG_POLL
, &jme
->flags
))
3249 jme_polling_mode(jme
);
3251 jme_stop_pcc_timer(jme
);
3252 jme_disable_rx_engine(jme
);
3253 jme_disable_tx_engine(jme
);
3254 jme_reset_mac_processor(jme
);
3255 jme_free_rx_resources(jme
);
3256 jme_free_tx_resources(jme
);
3257 netif_carrier_off(netdev
);
3261 tasklet_enable(&jme
->txclean_task
);
3262 tasklet_hi_enable(&jme
->rxclean_task
);
3263 tasklet_hi_enable(&jme
->rxempty_task
);
3265 jme_powersave_phy(jme
);
3271 jme_resume(struct device
*dev
)
3273 struct pci_dev
*pdev
= to_pci_dev(dev
);
3274 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3275 struct jme_adapter
*jme
= netdev_priv(netdev
);
3277 if (!netif_running(netdev
))
3282 if (test_bit(JME_FLAG_SSET
, &jme
->flags
))
3283 jme_set_settings(netdev
, &jme
->old_ecmd
);
3285 jme_reset_phy_processor(jme
);
3286 jme_phy_calibration(jme
);
3289 netif_device_attach(netdev
);
3291 atomic_inc(&jme
->link_changing
);
3293 jme_reset_link(jme
);
3298 static SIMPLE_DEV_PM_OPS(jme_pm_ops
, jme_suspend
, jme_resume
);
3299 #define JME_PM_OPS (&jme_pm_ops)
3303 #define JME_PM_OPS NULL
3306 static DEFINE_PCI_DEVICE_TABLE(jme_pci_tbl
) = {
3307 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC250
) },
3308 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMC260
) },
3312 static struct pci_driver jme_driver
= {
3314 .id_table
= jme_pci_tbl
,
3315 .probe
= jme_init_one
,
3316 .remove
= __devexit_p(jme_remove_one
),
3317 .shutdown
= jme_shutdown
,
3318 .driver
.pm
= JME_PM_OPS
,
3322 jme_init_module(void)
3324 pr_info("JMicron JMC2XX ethernet driver version %s\n", DRV_VERSION
);
3325 return pci_register_driver(&jme_driver
);
3329 jme_cleanup_module(void)
3331 pci_unregister_driver(&jme_driver
);
3334 module_init(jme_init_module
);
3335 module_exit(jme_cleanup_module
);
3337 MODULE_AUTHOR("Guo-Fu Tseng <cooldavid@cooldavid.org>");
3338 MODULE_DESCRIPTION("JMicron JMC2x0 PCI Express Ethernet driver");
3339 MODULE_LICENSE("GPL");
3340 MODULE_VERSION(DRV_VERSION
);
3341 MODULE_DEVICE_TABLE(pci
, jme_pci_tbl
);