diff options
Diffstat (limited to 'drivers/net')
30 files changed, 4053 insertions, 364 deletions
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 8a835eb58808..1e50b8e32add 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig | |||
@@ -131,6 +131,8 @@ config NET_SB1000 | |||
131 | 131 | ||
132 | source "drivers/net/arcnet/Kconfig" | 132 | source "drivers/net/arcnet/Kconfig" |
133 | 133 | ||
134 | source "drivers/net/phy/Kconfig" | ||
135 | |||
134 | # | 136 | # |
135 | # Ethernet | 137 | # Ethernet |
136 | # | 138 | # |
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 63c6d1e6d4d9..a369ae284a9a 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile | |||
@@ -65,6 +65,7 @@ obj-$(CONFIG_ADAPTEC_STARFIRE) += starfire.o | |||
65 | # | 65 | # |
66 | 66 | ||
67 | obj-$(CONFIG_MII) += mii.o | 67 | obj-$(CONFIG_MII) += mii.o |
68 | obj-$(CONFIG_PHYLIB) += phy/ | ||
68 | 69 | ||
69 | obj-$(CONFIG_SUNDANCE) += sundance.o | 70 | obj-$(CONFIG_SUNDANCE) += sundance.o |
70 | obj-$(CONFIG_HAMACHI) += hamachi.o | 71 | obj-$(CONFIG_HAMACHI) += hamachi.o |
diff --git a/drivers/net/Space.c b/drivers/net/Space.c index 3707df6b0cfa..11c44becc08f 100644 --- a/drivers/net/Space.c +++ b/drivers/net/Space.c | |||
@@ -323,12 +323,6 @@ extern struct net_device *proteon_probe(int unit); | |||
323 | extern struct net_device *smctr_probe(int unit); | 323 | extern struct net_device *smctr_probe(int unit); |
324 | 324 | ||
325 | static struct devprobe2 tr_probes2[] __initdata = { | 325 | static struct devprobe2 tr_probes2[] __initdata = { |
326 | #ifdef CONFIG_SKISA | ||
327 | {sk_isa_probe, 0}, | ||
328 | #endif | ||
329 | #ifdef CONFIG_PROTEON | ||
330 | {proteon_probe, 0}, | ||
331 | #endif | ||
332 | #ifdef CONFIG_SMCTR | 326 | #ifdef CONFIG_SMCTR |
333 | {smctr_probe, 0}, | 327 | {smctr_probe, 0}, |
334 | #endif | 328 | #endif |
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index 5ce606d9dc03..19e829b567d0 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c | |||
@@ -1106,18 +1106,13 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav | |||
1106 | } | 1106 | } |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | if (found) { | 1109 | if (!found) |
1110 | /* a slave was found that is using the mac address | 1110 | return 0; |
1111 | * of the new slave | ||
1112 | */ | ||
1113 | printk(KERN_ERR DRV_NAME | ||
1114 | ": Error: the hw address of slave %s is not " | ||
1115 | "unique - cannot enslave it!", | ||
1116 | slave->dev->name); | ||
1117 | return -EINVAL; | ||
1118 | } | ||
1119 | 1111 | ||
1120 | return 0; | 1112 | /* Try setting slave mac to bond address and fall-through |
1113 | to code handling that situation below... */ | ||
1114 | alb_set_slave_mac_addr(slave, bond->dev->dev_addr, | ||
1115 | bond->alb_info.rlb_enabled); | ||
1121 | } | 1116 | } |
1122 | 1117 | ||
1123 | /* The slave's address is equal to the address of the bond. | 1118 | /* The slave's address is equal to the address of the bond. |
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c index 64f0f697c958..f165ae973985 100644 --- a/drivers/net/forcedeth.c +++ b/drivers/net/forcedeth.c | |||
@@ -85,6 +85,14 @@ | |||
85 | * 0.33: 16 May 2005: Support for MCP51 added. | 85 | * 0.33: 16 May 2005: Support for MCP51 added. |
86 | * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics. | 86 | * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics. |
87 | * 0.35: 26 Jun 2005: Support for MCP55 added. | 87 | * 0.35: 26 Jun 2005: Support for MCP55 added. |
88 | * 0.36: 28 Jun 2005: Add jumbo frame support. | ||
89 | * 0.37: 10 Jul 2005: Additional ethtool support, cleanup of pci id list | ||
90 | * 0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of | ||
91 | * per-packet flags. | ||
92 | * 0.39: 18 Jul 2005: Add 64bit descriptor support. | ||
93 | * 0.40: 19 Jul 2005: Add support for mac address change. | ||
94 | * 0.41: 30 Jul 2005: Write back original MAC in nv_close instead | ||
95 | * of nv_remove | ||
88 | * | 96 | * |
89 | * Known bugs: | 97 | * Known bugs: |
90 | * We suspect that on some hardware no TX done interrupts are generated. | 98 | * We suspect that on some hardware no TX done interrupts are generated. |
@@ -96,7 +104,7 @@ | |||
96 | * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few | 104 | * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few |
97 | * superfluous timer interrupts from the nic. | 105 | * superfluous timer interrupts from the nic. |
98 | */ | 106 | */ |
99 | #define FORCEDETH_VERSION "0.35" | 107 | #define FORCEDETH_VERSION "0.41" |
100 | #define DRV_NAME "forcedeth" | 108 | #define DRV_NAME "forcedeth" |
101 | 109 | ||
102 | #include <linux/module.h> | 110 | #include <linux/module.h> |
@@ -131,11 +139,10 @@ | |||
131 | * Hardware access: | 139 | * Hardware access: |
132 | */ | 140 | */ |
133 | 141 | ||
134 | #define DEV_NEED_LASTPACKET1 0x0001 /* set LASTPACKET1 in tx flags */ | 142 | #define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */ |
135 | #define DEV_IRQMASK_1 0x0002 /* use NVREG_IRQMASK_WANTED_1 for irq mask */ | 143 | #define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */ |
136 | #define DEV_IRQMASK_2 0x0004 /* use NVREG_IRQMASK_WANTED_2 for irq mask */ | 144 | #define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */ |
137 | #define DEV_NEED_TIMERIRQ 0x0008 /* set the timer irq flag in the irq mask */ | 145 | #define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */ |
138 | #define DEV_NEED_LINKTIMER 0x0010 /* poll link settings. Relies on the timer irq */ | ||
139 | 146 | ||
140 | enum { | 147 | enum { |
141 | NvRegIrqStatus = 0x000, | 148 | NvRegIrqStatus = 0x000, |
@@ -146,13 +153,16 @@ enum { | |||
146 | #define NVREG_IRQ_RX 0x0002 | 153 | #define NVREG_IRQ_RX 0x0002 |
147 | #define NVREG_IRQ_RX_NOBUF 0x0004 | 154 | #define NVREG_IRQ_RX_NOBUF 0x0004 |
148 | #define NVREG_IRQ_TX_ERR 0x0008 | 155 | #define NVREG_IRQ_TX_ERR 0x0008 |
149 | #define NVREG_IRQ_TX2 0x0010 | 156 | #define NVREG_IRQ_TX_OK 0x0010 |
150 | #define NVREG_IRQ_TIMER 0x0020 | 157 | #define NVREG_IRQ_TIMER 0x0020 |
151 | #define NVREG_IRQ_LINK 0x0040 | 158 | #define NVREG_IRQ_LINK 0x0040 |
159 | #define NVREG_IRQ_TX_ERROR 0x0080 | ||
152 | #define NVREG_IRQ_TX1 0x0100 | 160 | #define NVREG_IRQ_TX1 0x0100 |
153 | #define NVREG_IRQMASK_WANTED_1 0x005f | 161 | #define NVREG_IRQMASK_WANTED 0x00df |
154 | #define NVREG_IRQMASK_WANTED_2 0x0147 | 162 | |
155 | #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR|NVREG_IRQ_TX2|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_TX1)) | 163 | #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \ |
164 | NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_TX_ERROR| \ | ||
165 | NVREG_IRQ_TX1)) | ||
156 | 166 | ||
157 | NvRegUnknownSetupReg6 = 0x008, | 167 | NvRegUnknownSetupReg6 = 0x008, |
158 | #define NVREG_UNKSETUP6_VAL 3 | 168 | #define NVREG_UNKSETUP6_VAL 3 |
@@ -286,6 +296,18 @@ struct ring_desc { | |||
286 | u32 FlagLen; | 296 | u32 FlagLen; |
287 | }; | 297 | }; |
288 | 298 | ||
299 | struct ring_desc_ex { | ||
300 | u32 PacketBufferHigh; | ||
301 | u32 PacketBufferLow; | ||
302 | u32 Reserved; | ||
303 | u32 FlagLen; | ||
304 | }; | ||
305 | |||
306 | typedef union _ring_type { | ||
307 | struct ring_desc* orig; | ||
308 | struct ring_desc_ex* ex; | ||
309 | } ring_type; | ||
310 | |||
289 | #define FLAG_MASK_V1 0xffff0000 | 311 | #define FLAG_MASK_V1 0xffff0000 |
290 | #define FLAG_MASK_V2 0xffffc000 | 312 | #define FLAG_MASK_V2 0xffffc000 |
291 | #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1) | 313 | #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1) |
@@ -293,7 +315,7 @@ struct ring_desc { | |||
293 | 315 | ||
294 | #define NV_TX_LASTPACKET (1<<16) | 316 | #define NV_TX_LASTPACKET (1<<16) |
295 | #define NV_TX_RETRYERROR (1<<19) | 317 | #define NV_TX_RETRYERROR (1<<19) |
296 | #define NV_TX_LASTPACKET1 (1<<24) | 318 | #define NV_TX_FORCED_INTERRUPT (1<<24) |
297 | #define NV_TX_DEFERRED (1<<26) | 319 | #define NV_TX_DEFERRED (1<<26) |
298 | #define NV_TX_CARRIERLOST (1<<27) | 320 | #define NV_TX_CARRIERLOST (1<<27) |
299 | #define NV_TX_LATECOLLISION (1<<28) | 321 | #define NV_TX_LATECOLLISION (1<<28) |
@@ -303,7 +325,7 @@ struct ring_desc { | |||
303 | 325 | ||
304 | #define NV_TX2_LASTPACKET (1<<29) | 326 | #define NV_TX2_LASTPACKET (1<<29) |
305 | #define NV_TX2_RETRYERROR (1<<18) | 327 | #define NV_TX2_RETRYERROR (1<<18) |
306 | #define NV_TX2_LASTPACKET1 (1<<23) | 328 | #define NV_TX2_FORCED_INTERRUPT (1<<30) |
307 | #define NV_TX2_DEFERRED (1<<25) | 329 | #define NV_TX2_DEFERRED (1<<25) |
308 | #define NV_TX2_CARRIERLOST (1<<26) | 330 | #define NV_TX2_CARRIERLOST (1<<26) |
309 | #define NV_TX2_LATECOLLISION (1<<27) | 331 | #define NV_TX2_LATECOLLISION (1<<27) |
@@ -379,9 +401,13 @@ struct ring_desc { | |||
379 | #define TX_LIMIT_START 62 | 401 | #define TX_LIMIT_START 62 |
380 | 402 | ||
381 | /* rx/tx mac addr + type + vlan + align + slack*/ | 403 | /* rx/tx mac addr + type + vlan + align + slack*/ |
382 | #define RX_NIC_BUFSIZE (ETH_DATA_LEN + 64) | 404 | #define NV_RX_HEADERS (64) |
383 | /* even more slack */ | 405 | /* even more slack. */ |
384 | #define RX_ALLOC_BUFSIZE (ETH_DATA_LEN + 128) | 406 | #define NV_RX_ALLOC_PAD (64) |
407 | |||
408 | /* maximum mtu size */ | ||
409 | #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */ | ||
410 | #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */ | ||
385 | 411 | ||
386 | #define OOM_REFILL (1+HZ/20) | 412 | #define OOM_REFILL (1+HZ/20) |
387 | #define POLL_WAIT (1+HZ/100) | 413 | #define POLL_WAIT (1+HZ/100) |
@@ -396,6 +422,7 @@ struct ring_desc { | |||
396 | */ | 422 | */ |
397 | #define DESC_VER_1 0x0 | 423 | #define DESC_VER_1 0x0 |
398 | #define DESC_VER_2 (0x02100|NVREG_TXRXCTL_RXCHECK) | 424 | #define DESC_VER_2 (0x02100|NVREG_TXRXCTL_RXCHECK) |
425 | #define DESC_VER_3 (0x02200|NVREG_TXRXCTL_RXCHECK) | ||
399 | 426 | ||
400 | /* PHY defines */ | 427 | /* PHY defines */ |
401 | #define PHY_OUI_MARVELL 0x5043 | 428 | #define PHY_OUI_MARVELL 0x5043 |
@@ -468,11 +495,12 @@ struct fe_priv { | |||
468 | /* rx specific fields. | 495 | /* rx specific fields. |
469 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); | 496 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); |
470 | */ | 497 | */ |
471 | struct ring_desc *rx_ring; | 498 | ring_type rx_ring; |
472 | unsigned int cur_rx, refill_rx; | 499 | unsigned int cur_rx, refill_rx; |
473 | struct sk_buff *rx_skbuff[RX_RING]; | 500 | struct sk_buff *rx_skbuff[RX_RING]; |
474 | dma_addr_t rx_dma[RX_RING]; | 501 | dma_addr_t rx_dma[RX_RING]; |
475 | unsigned int rx_buf_sz; | 502 | unsigned int rx_buf_sz; |
503 | unsigned int pkt_limit; | ||
476 | struct timer_list oom_kick; | 504 | struct timer_list oom_kick; |
477 | struct timer_list nic_poll; | 505 | struct timer_list nic_poll; |
478 | 506 | ||
@@ -484,7 +512,7 @@ struct fe_priv { | |||
484 | /* | 512 | /* |
485 | * tx specific fields. | 513 | * tx specific fields. |
486 | */ | 514 | */ |
487 | struct ring_desc *tx_ring; | 515 | ring_type tx_ring; |
488 | unsigned int next_tx, nic_tx; | 516 | unsigned int next_tx, nic_tx; |
489 | struct sk_buff *tx_skbuff[TX_RING]; | 517 | struct sk_buff *tx_skbuff[TX_RING]; |
490 | dma_addr_t tx_dma[TX_RING]; | 518 | dma_addr_t tx_dma[TX_RING]; |
@@ -519,6 +547,11 @@ static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v) | |||
519 | & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2); | 547 | & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2); |
520 | } | 548 | } |
521 | 549 | ||
550 | static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v) | ||
551 | { | ||
552 | return le32_to_cpu(prd->FlagLen) & LEN_MASK_V2; | ||
553 | } | ||
554 | |||
522 | static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target, | 555 | static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target, |
523 | int delay, int delaymax, const char *msg) | 556 | int delay, int delaymax, const char *msg) |
524 | { | 557 | { |
@@ -792,7 +825,7 @@ static int nv_alloc_rx(struct net_device *dev) | |||
792 | nr = refill_rx % RX_RING; | 825 | nr = refill_rx % RX_RING; |
793 | if (np->rx_skbuff[nr] == NULL) { | 826 | if (np->rx_skbuff[nr] == NULL) { |
794 | 827 | ||
795 | skb = dev_alloc_skb(RX_ALLOC_BUFSIZE); | 828 | skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD); |
796 | if (!skb) | 829 | if (!skb) |
797 | break; | 830 | break; |
798 | 831 | ||
@@ -803,9 +836,16 @@ static int nv_alloc_rx(struct net_device *dev) | |||
803 | } | 836 | } |
804 | np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data, skb->len, | 837 | np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data, skb->len, |
805 | PCI_DMA_FROMDEVICE); | 838 | PCI_DMA_FROMDEVICE); |
806 | np->rx_ring[nr].PacketBuffer = cpu_to_le32(np->rx_dma[nr]); | 839 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
807 | wmb(); | 840 | np->rx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->rx_dma[nr]); |
808 | np->rx_ring[nr].FlagLen = cpu_to_le32(RX_NIC_BUFSIZE | NV_RX_AVAIL); | 841 | wmb(); |
842 | np->rx_ring.orig[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL); | ||
843 | } else { | ||
844 | np->rx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->rx_dma[nr]) >> 32; | ||
845 | np->rx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF; | ||
846 | wmb(); | ||
847 | np->rx_ring.ex[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL); | ||
848 | } | ||
809 | dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n", | 849 | dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n", |
810 | dev->name, refill_rx); | 850 | dev->name, refill_rx); |
811 | refill_rx++; | 851 | refill_rx++; |
@@ -831,19 +871,37 @@ static void nv_do_rx_refill(unsigned long data) | |||
831 | enable_irq(dev->irq); | 871 | enable_irq(dev->irq); |
832 | } | 872 | } |
833 | 873 | ||
834 | static int nv_init_ring(struct net_device *dev) | 874 | static void nv_init_rx(struct net_device *dev) |
835 | { | 875 | { |
836 | struct fe_priv *np = get_nvpriv(dev); | 876 | struct fe_priv *np = get_nvpriv(dev); |
837 | int i; | 877 | int i; |
838 | 878 | ||
839 | np->next_tx = np->nic_tx = 0; | ||
840 | for (i = 0; i < TX_RING; i++) | ||
841 | np->tx_ring[i].FlagLen = 0; | ||
842 | |||
843 | np->cur_rx = RX_RING; | 879 | np->cur_rx = RX_RING; |
844 | np->refill_rx = 0; | 880 | np->refill_rx = 0; |
845 | for (i = 0; i < RX_RING; i++) | 881 | for (i = 0; i < RX_RING; i++) |
846 | np->rx_ring[i].FlagLen = 0; | 882 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
883 | np->rx_ring.orig[i].FlagLen = 0; | ||
884 | else | ||
885 | np->rx_ring.ex[i].FlagLen = 0; | ||
886 | } | ||
887 | |||
888 | static void nv_init_tx(struct net_device *dev) | ||
889 | { | ||
890 | struct fe_priv *np = get_nvpriv(dev); | ||
891 | int i; | ||
892 | |||
893 | np->next_tx = np->nic_tx = 0; | ||
894 | for (i = 0; i < TX_RING; i++) | ||
895 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) | ||
896 | np->tx_ring.orig[i].FlagLen = 0; | ||
897 | else | ||
898 | np->tx_ring.ex[i].FlagLen = 0; | ||
899 | } | ||
900 | |||
901 | static int nv_init_ring(struct net_device *dev) | ||
902 | { | ||
903 | nv_init_tx(dev); | ||
904 | nv_init_rx(dev); | ||
847 | return nv_alloc_rx(dev); | 905 | return nv_alloc_rx(dev); |
848 | } | 906 | } |
849 | 907 | ||
@@ -852,7 +910,10 @@ static void nv_drain_tx(struct net_device *dev) | |||
852 | struct fe_priv *np = get_nvpriv(dev); | 910 | struct fe_priv *np = get_nvpriv(dev); |
853 | int i; | 911 | int i; |
854 | for (i = 0; i < TX_RING; i++) { | 912 | for (i = 0; i < TX_RING; i++) { |
855 | np->tx_ring[i].FlagLen = 0; | 913 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
914 | np->tx_ring.orig[i].FlagLen = 0; | ||
915 | else | ||
916 | np->tx_ring.ex[i].FlagLen = 0; | ||
856 | if (np->tx_skbuff[i]) { | 917 | if (np->tx_skbuff[i]) { |
857 | pci_unmap_single(np->pci_dev, np->tx_dma[i], | 918 | pci_unmap_single(np->pci_dev, np->tx_dma[i], |
858 | np->tx_skbuff[i]->len, | 919 | np->tx_skbuff[i]->len, |
@@ -869,7 +930,10 @@ static void nv_drain_rx(struct net_device *dev) | |||
869 | struct fe_priv *np = get_nvpriv(dev); | 930 | struct fe_priv *np = get_nvpriv(dev); |
870 | int i; | 931 | int i; |
871 | for (i = 0; i < RX_RING; i++) { | 932 | for (i = 0; i < RX_RING; i++) { |
872 | np->rx_ring[i].FlagLen = 0; | 933 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
934 | np->rx_ring.orig[i].FlagLen = 0; | ||
935 | else | ||
936 | np->rx_ring.ex[i].FlagLen = 0; | ||
873 | wmb(); | 937 | wmb(); |
874 | if (np->rx_skbuff[i]) { | 938 | if (np->rx_skbuff[i]) { |
875 | pci_unmap_single(np->pci_dev, np->rx_dma[i], | 939 | pci_unmap_single(np->pci_dev, np->rx_dma[i], |
@@ -900,11 +964,19 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
900 | np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data,skb->len, | 964 | np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data,skb->len, |
901 | PCI_DMA_TODEVICE); | 965 | PCI_DMA_TODEVICE); |
902 | 966 | ||
903 | np->tx_ring[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]); | 967 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
968 | np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]); | ||
969 | else { | ||
970 | np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32; | ||
971 | np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF; | ||
972 | } | ||
904 | 973 | ||
905 | spin_lock_irq(&np->lock); | 974 | spin_lock_irq(&np->lock); |
906 | wmb(); | 975 | wmb(); |
907 | np->tx_ring[nr].FlagLen = cpu_to_le32( (skb->len-1) | np->tx_flags ); | 976 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
977 | np->tx_ring.orig[nr].FlagLen = cpu_to_le32( (skb->len-1) | np->tx_flags ); | ||
978 | else | ||
979 | np->tx_ring.ex[nr].FlagLen = cpu_to_le32( (skb->len-1) | np->tx_flags ); | ||
908 | dprintk(KERN_DEBUG "%s: nv_start_xmit: packet packet %d queued for transmission.\n", | 980 | dprintk(KERN_DEBUG "%s: nv_start_xmit: packet packet %d queued for transmission.\n", |
909 | dev->name, np->next_tx); | 981 | dev->name, np->next_tx); |
910 | { | 982 | { |
@@ -942,7 +1014,10 @@ static void nv_tx_done(struct net_device *dev) | |||
942 | while (np->nic_tx != np->next_tx) { | 1014 | while (np->nic_tx != np->next_tx) { |
943 | i = np->nic_tx % TX_RING; | 1015 | i = np->nic_tx % TX_RING; |
944 | 1016 | ||
945 | Flags = le32_to_cpu(np->tx_ring[i].FlagLen); | 1017 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
1018 | Flags = le32_to_cpu(np->tx_ring.orig[i].FlagLen); | ||
1019 | else | ||
1020 | Flags = le32_to_cpu(np->tx_ring.ex[i].FlagLen); | ||
946 | 1021 | ||
947 | dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, Flags 0x%x.\n", | 1022 | dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, Flags 0x%x.\n", |
948 | dev->name, np->nic_tx, Flags); | 1023 | dev->name, np->nic_tx, Flags); |
@@ -993,9 +1068,56 @@ static void nv_tx_timeout(struct net_device *dev) | |||
993 | struct fe_priv *np = get_nvpriv(dev); | 1068 | struct fe_priv *np = get_nvpriv(dev); |
994 | u8 __iomem *base = get_hwbase(dev); | 1069 | u8 __iomem *base = get_hwbase(dev); |
995 | 1070 | ||
996 | dprintk(KERN_DEBUG "%s: Got tx_timeout. irq: %08x\n", dev->name, | 1071 | printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, |
997 | readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK); | 1072 | readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK); |
998 | 1073 | ||
1074 | { | ||
1075 | int i; | ||
1076 | |||
1077 | printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n", | ||
1078 | dev->name, (unsigned long)np->ring_addr, | ||
1079 | np->next_tx, np->nic_tx); | ||
1080 | printk(KERN_INFO "%s: Dumping tx registers\n", dev->name); | ||
1081 | for (i=0;i<0x400;i+= 32) { | ||
1082 | printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n", | ||
1083 | i, | ||
1084 | readl(base + i + 0), readl(base + i + 4), | ||
1085 | readl(base + i + 8), readl(base + i + 12), | ||
1086 | readl(base + i + 16), readl(base + i + 20), | ||
1087 | readl(base + i + 24), readl(base + i + 28)); | ||
1088 | } | ||
1089 | printk(KERN_INFO "%s: Dumping tx ring\n", dev->name); | ||
1090 | for (i=0;i<TX_RING;i+= 4) { | ||
1091 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { | ||
1092 | printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n", | ||
1093 | i, | ||
1094 | le32_to_cpu(np->tx_ring.orig[i].PacketBuffer), | ||
1095 | le32_to_cpu(np->tx_ring.orig[i].FlagLen), | ||
1096 | le32_to_cpu(np->tx_ring.orig[i+1].PacketBuffer), | ||
1097 | le32_to_cpu(np->tx_ring.orig[i+1].FlagLen), | ||
1098 | le32_to_cpu(np->tx_ring.orig[i+2].PacketBuffer), | ||
1099 | le32_to_cpu(np->tx_ring.orig[i+2].FlagLen), | ||
1100 | le32_to_cpu(np->tx_ring.orig[i+3].PacketBuffer), | ||
1101 | le32_to_cpu(np->tx_ring.orig[i+3].FlagLen)); | ||
1102 | } else { | ||
1103 | printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n", | ||
1104 | i, | ||
1105 | le32_to_cpu(np->tx_ring.ex[i].PacketBufferHigh), | ||
1106 | le32_to_cpu(np->tx_ring.ex[i].PacketBufferLow), | ||
1107 | le32_to_cpu(np->tx_ring.ex[i].FlagLen), | ||
1108 | le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferHigh), | ||
1109 | le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferLow), | ||
1110 | le32_to_cpu(np->tx_ring.ex[i+1].FlagLen), | ||
1111 | le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferHigh), | ||
1112 | le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferLow), | ||
1113 | le32_to_cpu(np->tx_ring.ex[i+2].FlagLen), | ||
1114 | le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferHigh), | ||
1115 | le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferLow), | ||
1116 | le32_to_cpu(np->tx_ring.ex[i+3].FlagLen)); | ||
1117 | } | ||
1118 | } | ||
1119 | } | ||
1120 | |||
999 | spin_lock_irq(&np->lock); | 1121 | spin_lock_irq(&np->lock); |
1000 | 1122 | ||
1001 | /* 1) stop tx engine */ | 1123 | /* 1) stop tx engine */ |
@@ -1009,7 +1131,10 @@ static void nv_tx_timeout(struct net_device *dev) | |||
1009 | printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name); | 1131 | printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name); |
1010 | nv_drain_tx(dev); | 1132 | nv_drain_tx(dev); |
1011 | np->next_tx = np->nic_tx = 0; | 1133 | np->next_tx = np->nic_tx = 0; |
1012 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); | 1134 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
1135 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); | ||
1136 | else | ||
1137 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); | ||
1013 | netif_wake_queue(dev); | 1138 | netif_wake_queue(dev); |
1014 | } | 1139 | } |
1015 | 1140 | ||
@@ -1084,8 +1209,13 @@ static void nv_rx_process(struct net_device *dev) | |||
1084 | break; /* we scanned the whole ring - do not continue */ | 1209 | break; /* we scanned the whole ring - do not continue */ |
1085 | 1210 | ||
1086 | i = np->cur_rx % RX_RING; | 1211 | i = np->cur_rx % RX_RING; |
1087 | Flags = le32_to_cpu(np->rx_ring[i].FlagLen); | 1212 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
1088 | len = nv_descr_getlength(&np->rx_ring[i], np->desc_ver); | 1213 | Flags = le32_to_cpu(np->rx_ring.orig[i].FlagLen); |
1214 | len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver); | ||
1215 | } else { | ||
1216 | Flags = le32_to_cpu(np->rx_ring.ex[i].FlagLen); | ||
1217 | len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver); | ||
1218 | } | ||
1089 | 1219 | ||
1090 | dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, Flags 0x%x.\n", | 1220 | dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, Flags 0x%x.\n", |
1091 | dev->name, np->cur_rx, Flags); | 1221 | dev->name, np->cur_rx, Flags); |
@@ -1207,15 +1337,133 @@ next_pkt: | |||
1207 | } | 1337 | } |
1208 | } | 1338 | } |
1209 | 1339 | ||
1340 | static void set_bufsize(struct net_device *dev) | ||
1341 | { | ||
1342 | struct fe_priv *np = netdev_priv(dev); | ||
1343 | |||
1344 | if (dev->mtu <= ETH_DATA_LEN) | ||
1345 | np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS; | ||
1346 | else | ||
1347 | np->rx_buf_sz = dev->mtu + NV_RX_HEADERS; | ||
1348 | } | ||
1349 | |||
1210 | /* | 1350 | /* |
1211 | * nv_change_mtu: dev->change_mtu function | 1351 | * nv_change_mtu: dev->change_mtu function |
1212 | * Called with dev_base_lock held for read. | 1352 | * Called with dev_base_lock held for read. |
1213 | */ | 1353 | */ |
1214 | static int nv_change_mtu(struct net_device *dev, int new_mtu) | 1354 | static int nv_change_mtu(struct net_device *dev, int new_mtu) |
1215 | { | 1355 | { |
1216 | if (new_mtu > ETH_DATA_LEN) | 1356 | struct fe_priv *np = get_nvpriv(dev); |
1357 | int old_mtu; | ||
1358 | |||
1359 | if (new_mtu < 64 || new_mtu > np->pkt_limit) | ||
1217 | return -EINVAL; | 1360 | return -EINVAL; |
1361 | |||
1362 | old_mtu = dev->mtu; | ||
1218 | dev->mtu = new_mtu; | 1363 | dev->mtu = new_mtu; |
1364 | |||
1365 | /* return early if the buffer sizes will not change */ | ||
1366 | if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN) | ||
1367 | return 0; | ||
1368 | if (old_mtu == new_mtu) | ||
1369 | return 0; | ||
1370 | |||
1371 | /* synchronized against open : rtnl_lock() held by caller */ | ||
1372 | if (netif_running(dev)) { | ||
1373 | u8 *base = get_hwbase(dev); | ||
1374 | /* | ||
1375 | * It seems that the nic preloads valid ring entries into an | ||
1376 | * internal buffer. The procedure for flushing everything is | ||
1377 | * guessed, there is probably a simpler approach. | ||
1378 | * Changing the MTU is a rare event, it shouldn't matter. | ||
1379 | */ | ||
1380 | disable_irq(dev->irq); | ||
1381 | spin_lock_bh(&dev->xmit_lock); | ||
1382 | spin_lock(&np->lock); | ||
1383 | /* stop engines */ | ||
1384 | nv_stop_rx(dev); | ||
1385 | nv_stop_tx(dev); | ||
1386 | nv_txrx_reset(dev); | ||
1387 | /* drain rx queue */ | ||
1388 | nv_drain_rx(dev); | ||
1389 | nv_drain_tx(dev); | ||
1390 | /* reinit driver view of the rx queue */ | ||
1391 | nv_init_rx(dev); | ||
1392 | nv_init_tx(dev); | ||
1393 | /* alloc new rx buffers */ | ||
1394 | set_bufsize(dev); | ||
1395 | if (nv_alloc_rx(dev)) { | ||
1396 | if (!np->in_shutdown) | ||
1397 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); | ||
1398 | } | ||
1399 | /* reinit nic view of the rx queue */ | ||
1400 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); | ||
1401 | writel((u32) np->ring_addr, base + NvRegRxRingPhysAddr); | ||
1402 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) | ||
1403 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); | ||
1404 | else | ||
1405 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); | ||
1406 | writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT), | ||
1407 | base + NvRegRingSizes); | ||
1408 | pci_push(base); | ||
1409 | writel(NVREG_TXRXCTL_KICK|np->desc_ver, get_hwbase(dev) + NvRegTxRxControl); | ||
1410 | pci_push(base); | ||
1411 | |||
1412 | /* restart rx engine */ | ||
1413 | nv_start_rx(dev); | ||
1414 | nv_start_tx(dev); | ||
1415 | spin_unlock(&np->lock); | ||
1416 | spin_unlock_bh(&dev->xmit_lock); | ||
1417 | enable_irq(dev->irq); | ||
1418 | } | ||
1419 | return 0; | ||
1420 | } | ||
1421 | |||
1422 | static void nv_copy_mac_to_hw(struct net_device *dev) | ||
1423 | { | ||
1424 | u8 *base = get_hwbase(dev); | ||
1425 | u32 mac[2]; | ||
1426 | |||
1427 | mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) + | ||
1428 | (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24); | ||
1429 | mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8); | ||
1430 | |||
1431 | writel(mac[0], base + NvRegMacAddrA); | ||
1432 | writel(mac[1], base + NvRegMacAddrB); | ||
1433 | } | ||
1434 | |||
1435 | /* | ||
1436 | * nv_set_mac_address: dev->set_mac_address function | ||
1437 | * Called with rtnl_lock() held. | ||
1438 | */ | ||
1439 | static int nv_set_mac_address(struct net_device *dev, void *addr) | ||
1440 | { | ||
1441 | struct fe_priv *np = get_nvpriv(dev); | ||
1442 | struct sockaddr *macaddr = (struct sockaddr*)addr; | ||
1443 | |||
1444 | if(!is_valid_ether_addr(macaddr->sa_data)) | ||
1445 | return -EADDRNOTAVAIL; | ||
1446 | |||
1447 | /* synchronized against open : rtnl_lock() held by caller */ | ||
1448 | memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN); | ||
1449 | |||
1450 | if (netif_running(dev)) { | ||
1451 | spin_lock_bh(&dev->xmit_lock); | ||
1452 | spin_lock_irq(&np->lock); | ||
1453 | |||
1454 | /* stop rx engine */ | ||
1455 | nv_stop_rx(dev); | ||
1456 | |||
1457 | /* set mac address */ | ||
1458 | nv_copy_mac_to_hw(dev); | ||
1459 | |||
1460 | /* restart rx engine */ | ||
1461 | nv_start_rx(dev); | ||
1462 | spin_unlock_irq(&np->lock); | ||
1463 | spin_unlock_bh(&dev->xmit_lock); | ||
1464 | } else { | ||
1465 | nv_copy_mac_to_hw(dev); | ||
1466 | } | ||
1219 | return 0; | 1467 | return 0; |
1220 | } | 1468 | } |
1221 | 1469 | ||
@@ -1470,7 +1718,7 @@ static irqreturn_t nv_nic_irq(int foo, void *data, struct pt_regs *regs) | |||
1470 | if (!(events & np->irqmask)) | 1718 | if (!(events & np->irqmask)) |
1471 | break; | 1719 | break; |
1472 | 1720 | ||
1473 | if (events & (NVREG_IRQ_TX1|NVREG_IRQ_TX2|NVREG_IRQ_TX_ERR)) { | 1721 | if (events & (NVREG_IRQ_TX1|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_ERROR|NVREG_IRQ_TX_ERR)) { |
1474 | spin_lock(&np->lock); | 1722 | spin_lock(&np->lock); |
1475 | nv_tx_done(dev); | 1723 | nv_tx_done(dev); |
1476 | spin_unlock(&np->lock); | 1724 | spin_unlock(&np->lock); |
@@ -1761,6 +2009,50 @@ static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | |||
1761 | return 0; | 2009 | return 0; |
1762 | } | 2010 | } |
1763 | 2011 | ||
2012 | #define FORCEDETH_REGS_VER 1 | ||
2013 | #define FORCEDETH_REGS_SIZE 0x400 /* 256 32-bit registers */ | ||
2014 | |||
2015 | static int nv_get_regs_len(struct net_device *dev) | ||
2016 | { | ||
2017 | return FORCEDETH_REGS_SIZE; | ||
2018 | } | ||
2019 | |||
2020 | static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf) | ||
2021 | { | ||
2022 | struct fe_priv *np = get_nvpriv(dev); | ||
2023 | u8 __iomem *base = get_hwbase(dev); | ||
2024 | u32 *rbuf = buf; | ||
2025 | int i; | ||
2026 | |||
2027 | regs->version = FORCEDETH_REGS_VER; | ||
2028 | spin_lock_irq(&np->lock); | ||
2029 | for (i=0;i<FORCEDETH_REGS_SIZE/sizeof(u32);i++) | ||
2030 | rbuf[i] = readl(base + i*sizeof(u32)); | ||
2031 | spin_unlock_irq(&np->lock); | ||
2032 | } | ||
2033 | |||
2034 | static int nv_nway_reset(struct net_device *dev) | ||
2035 | { | ||
2036 | struct fe_priv *np = get_nvpriv(dev); | ||
2037 | int ret; | ||
2038 | |||
2039 | spin_lock_irq(&np->lock); | ||
2040 | if (np->autoneg) { | ||
2041 | int bmcr; | ||
2042 | |||
2043 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); | ||
2044 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); | ||
2045 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); | ||
2046 | |||
2047 | ret = 0; | ||
2048 | } else { | ||
2049 | ret = -EINVAL; | ||
2050 | } | ||
2051 | spin_unlock_irq(&np->lock); | ||
2052 | |||
2053 | return ret; | ||
2054 | } | ||
2055 | |||
1764 | static struct ethtool_ops ops = { | 2056 | static struct ethtool_ops ops = { |
1765 | .get_drvinfo = nv_get_drvinfo, | 2057 | .get_drvinfo = nv_get_drvinfo, |
1766 | .get_link = ethtool_op_get_link, | 2058 | .get_link = ethtool_op_get_link, |
@@ -1768,6 +2060,9 @@ static struct ethtool_ops ops = { | |||
1768 | .set_wol = nv_set_wol, | 2060 | .set_wol = nv_set_wol, |
1769 | .get_settings = nv_get_settings, | 2061 | .get_settings = nv_get_settings, |
1770 | .set_settings = nv_set_settings, | 2062 | .set_settings = nv_set_settings, |
2063 | .get_regs_len = nv_get_regs_len, | ||
2064 | .get_regs = nv_get_regs, | ||
2065 | .nway_reset = nv_nway_reset, | ||
1771 | }; | 2066 | }; |
1772 | 2067 | ||
1773 | static int nv_open(struct net_device *dev) | 2068 | static int nv_open(struct net_device *dev) |
@@ -1792,6 +2087,7 @@ static int nv_open(struct net_device *dev) | |||
1792 | writel(0, base + NvRegAdapterControl); | 2087 | writel(0, base + NvRegAdapterControl); |
1793 | 2088 | ||
1794 | /* 2) initialize descriptor rings */ | 2089 | /* 2) initialize descriptor rings */ |
2090 | set_bufsize(dev); | ||
1795 | oom = nv_init_ring(dev); | 2091 | oom = nv_init_ring(dev); |
1796 | 2092 | ||
1797 | writel(0, base + NvRegLinkSpeed); | 2093 | writel(0, base + NvRegLinkSpeed); |
@@ -1802,20 +2098,14 @@ static int nv_open(struct net_device *dev) | |||
1802 | np->in_shutdown = 0; | 2098 | np->in_shutdown = 0; |
1803 | 2099 | ||
1804 | /* 3) set mac address */ | 2100 | /* 3) set mac address */ |
1805 | { | 2101 | nv_copy_mac_to_hw(dev); |
1806 | u32 mac[2]; | ||
1807 | |||
1808 | mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) + | ||
1809 | (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24); | ||
1810 | mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8); | ||
1811 | |||
1812 | writel(mac[0], base + NvRegMacAddrA); | ||
1813 | writel(mac[1], base + NvRegMacAddrB); | ||
1814 | } | ||
1815 | 2102 | ||
1816 | /* 4) give hw rings */ | 2103 | /* 4) give hw rings */ |
1817 | writel((u32) np->ring_addr, base + NvRegRxRingPhysAddr); | 2104 | writel((u32) np->ring_addr, base + NvRegRxRingPhysAddr); |
1818 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); | 2105 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
2106 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); | ||
2107 | else | ||
2108 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); | ||
1819 | writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT), | 2109 | writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT), |
1820 | base + NvRegRingSizes); | 2110 | base + NvRegRingSizes); |
1821 | 2111 | ||
@@ -1837,7 +2127,7 @@ static int nv_open(struct net_device *dev) | |||
1837 | writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1); | 2127 | writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1); |
1838 | writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus); | 2128 | writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus); |
1839 | writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags); | 2129 | writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags); |
1840 | writel(NVREG_OFFLOAD_NORMAL, base + NvRegOffloadConfig); | 2130 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
1841 | 2131 | ||
1842 | writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus); | 2132 | writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus); |
1843 | get_random_bytes(&i, sizeof(i)); | 2133 | get_random_bytes(&i, sizeof(i)); |
@@ -1942,6 +2232,12 @@ static int nv_close(struct net_device *dev) | |||
1942 | if (np->wolenabled) | 2232 | if (np->wolenabled) |
1943 | nv_start_rx(dev); | 2233 | nv_start_rx(dev); |
1944 | 2234 | ||
2235 | /* special op: write back the misordered MAC address - otherwise | ||
2236 | * the next nv_probe would see a wrong address. | ||
2237 | */ | ||
2238 | writel(np->orig_mac[0], base + NvRegMacAddrA); | ||
2239 | writel(np->orig_mac[1], base + NvRegMacAddrB); | ||
2240 | |||
1945 | /* FIXME: power down nic */ | 2241 | /* FIXME: power down nic */ |
1946 | 2242 | ||
1947 | return 0; | 2243 | return 0; |
@@ -2006,32 +2302,55 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i | |||
2006 | } | 2302 | } |
2007 | 2303 | ||
2008 | /* handle different descriptor versions */ | 2304 | /* handle different descriptor versions */ |
2009 | if (pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_1 || | 2305 | if (id->driver_data & DEV_HAS_HIGH_DMA) { |
2010 | pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_2 || | 2306 | /* packet format 3: supports 40-bit addressing */ |
2011 | pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_3 || | 2307 | np->desc_ver = DESC_VER_3; |
2012 | pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 || | 2308 | if (pci_set_dma_mask(pci_dev, 0x0000007fffffffffULL)) { |
2013 | pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) | 2309 | printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n", |
2014 | np->desc_ver = DESC_VER_1; | 2310 | pci_name(pci_dev)); |
2015 | else | 2311 | } |
2312 | } else if (id->driver_data & DEV_HAS_LARGEDESC) { | ||
2313 | /* packet format 2: supports jumbo frames */ | ||
2016 | np->desc_ver = DESC_VER_2; | 2314 | np->desc_ver = DESC_VER_2; |
2315 | } else { | ||
2316 | /* original packet format */ | ||
2317 | np->desc_ver = DESC_VER_1; | ||
2318 | } | ||
2319 | |||
2320 | np->pkt_limit = NV_PKTLIMIT_1; | ||
2321 | if (id->driver_data & DEV_HAS_LARGEDESC) | ||
2322 | np->pkt_limit = NV_PKTLIMIT_2; | ||
2017 | 2323 | ||
2018 | err = -ENOMEM; | 2324 | err = -ENOMEM; |
2019 | np->base = ioremap(addr, NV_PCI_REGSZ); | 2325 | np->base = ioremap(addr, NV_PCI_REGSZ); |
2020 | if (!np->base) | 2326 | if (!np->base) |
2021 | goto out_relreg; | 2327 | goto out_relreg; |
2022 | dev->base_addr = (unsigned long)np->base; | 2328 | dev->base_addr = (unsigned long)np->base; |
2329 | |||
2023 | dev->irq = pci_dev->irq; | 2330 | dev->irq = pci_dev->irq; |
2024 | np->rx_ring = pci_alloc_consistent(pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), | 2331 | |
2025 | &np->ring_addr); | 2332 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
2026 | if (!np->rx_ring) | 2333 | np->rx_ring.orig = pci_alloc_consistent(pci_dev, |
2027 | goto out_unmap; | 2334 | sizeof(struct ring_desc) * (RX_RING + TX_RING), |
2028 | np->tx_ring = &np->rx_ring[RX_RING]; | 2335 | &np->ring_addr); |
2336 | if (!np->rx_ring.orig) | ||
2337 | goto out_unmap; | ||
2338 | np->tx_ring.orig = &np->rx_ring.orig[RX_RING]; | ||
2339 | } else { | ||
2340 | np->rx_ring.ex = pci_alloc_consistent(pci_dev, | ||
2341 | sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), | ||
2342 | &np->ring_addr); | ||
2343 | if (!np->rx_ring.ex) | ||
2344 | goto out_unmap; | ||
2345 | np->tx_ring.ex = &np->rx_ring.ex[RX_RING]; | ||
2346 | } | ||
2029 | 2347 | ||
2030 | dev->open = nv_open; | 2348 | dev->open = nv_open; |
2031 | dev->stop = nv_close; | 2349 | dev->stop = nv_close; |
2032 | dev->hard_start_xmit = nv_start_xmit; | 2350 | dev->hard_start_xmit = nv_start_xmit; |
2033 | dev->get_stats = nv_get_stats; | 2351 | dev->get_stats = nv_get_stats; |
2034 | dev->change_mtu = nv_change_mtu; | 2352 | dev->change_mtu = nv_change_mtu; |
2353 | dev->set_mac_address = nv_set_mac_address; | ||
2035 | dev->set_multicast_list = nv_set_multicast; | 2354 | dev->set_multicast_list = nv_set_multicast; |
2036 | #ifdef CONFIG_NET_POLL_CONTROLLER | 2355 | #ifdef CONFIG_NET_POLL_CONTROLLER |
2037 | dev->poll_controller = nv_poll_controller; | 2356 | dev->poll_controller = nv_poll_controller; |
@@ -2080,17 +2399,10 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i | |||
2080 | 2399 | ||
2081 | if (np->desc_ver == DESC_VER_1) { | 2400 | if (np->desc_ver == DESC_VER_1) { |
2082 | np->tx_flags = NV_TX_LASTPACKET|NV_TX_VALID; | 2401 | np->tx_flags = NV_TX_LASTPACKET|NV_TX_VALID; |
2083 | if (id->driver_data & DEV_NEED_LASTPACKET1) | ||
2084 | np->tx_flags |= NV_TX_LASTPACKET1; | ||
2085 | } else { | 2402 | } else { |
2086 | np->tx_flags = NV_TX2_LASTPACKET|NV_TX2_VALID; | 2403 | np->tx_flags = NV_TX2_LASTPACKET|NV_TX2_VALID; |
2087 | if (id->driver_data & DEV_NEED_LASTPACKET1) | ||
2088 | np->tx_flags |= NV_TX2_LASTPACKET1; | ||
2089 | } | 2404 | } |
2090 | if (id->driver_data & DEV_IRQMASK_1) | 2405 | np->irqmask = NVREG_IRQMASK_WANTED; |
2091 | np->irqmask = NVREG_IRQMASK_WANTED_1; | ||
2092 | if (id->driver_data & DEV_IRQMASK_2) | ||
2093 | np->irqmask = NVREG_IRQMASK_WANTED_2; | ||
2094 | if (id->driver_data & DEV_NEED_TIMERIRQ) | 2406 | if (id->driver_data & DEV_NEED_TIMERIRQ) |
2095 | np->irqmask |= NVREG_IRQ_TIMER; | 2407 | np->irqmask |= NVREG_IRQ_TIMER; |
2096 | if (id->driver_data & DEV_NEED_LINKTIMER) { | 2408 | if (id->driver_data & DEV_NEED_LINKTIMER) { |
@@ -2155,8 +2467,12 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i | |||
2155 | return 0; | 2467 | return 0; |
2156 | 2468 | ||
2157 | out_freering: | 2469 | out_freering: |
2158 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), | 2470 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
2159 | np->rx_ring, np->ring_addr); | 2471 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), |
2472 | np->rx_ring.orig, np->ring_addr); | ||
2473 | else | ||
2474 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), | ||
2475 | np->rx_ring.ex, np->ring_addr); | ||
2160 | pci_set_drvdata(pci_dev, NULL); | 2476 | pci_set_drvdata(pci_dev, NULL); |
2161 | out_unmap: | 2477 | out_unmap: |
2162 | iounmap(get_hwbase(dev)); | 2478 | iounmap(get_hwbase(dev)); |
@@ -2174,18 +2490,14 @@ static void __devexit nv_remove(struct pci_dev *pci_dev) | |||
2174 | { | 2490 | { |
2175 | struct net_device *dev = pci_get_drvdata(pci_dev); | 2491 | struct net_device *dev = pci_get_drvdata(pci_dev); |
2176 | struct fe_priv *np = get_nvpriv(dev); | 2492 | struct fe_priv *np = get_nvpriv(dev); |
2177 | u8 __iomem *base = get_hwbase(dev); | ||
2178 | 2493 | ||
2179 | unregister_netdev(dev); | 2494 | unregister_netdev(dev); |
2180 | 2495 | ||
2181 | /* special op: write back the misordered MAC address - otherwise | ||
2182 | * the next nv_probe would see a wrong address. | ||
2183 | */ | ||
2184 | writel(np->orig_mac[0], base + NvRegMacAddrA); | ||
2185 | writel(np->orig_mac[1], base + NvRegMacAddrB); | ||
2186 | |||
2187 | /* free all structures */ | 2496 | /* free all structures */ |
2188 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), np->rx_ring, np->ring_addr); | 2497 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
2498 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), np->rx_ring.orig, np->ring_addr); | ||
2499 | else | ||
2500 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), np->rx_ring.ex, np->ring_addr); | ||
2189 | iounmap(get_hwbase(dev)); | 2501 | iounmap(get_hwbase(dev)); |
2190 | pci_release_regions(pci_dev); | 2502 | pci_release_regions(pci_dev); |
2191 | pci_disable_device(pci_dev); | 2503 | pci_disable_device(pci_dev); |
@@ -2195,109 +2507,64 @@ static void __devexit nv_remove(struct pci_dev *pci_dev) | |||
2195 | 2507 | ||
2196 | static struct pci_device_id pci_tbl[] = { | 2508 | static struct pci_device_id pci_tbl[] = { |
2197 | { /* nForce Ethernet Controller */ | 2509 | { /* nForce Ethernet Controller */ |
2198 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2510 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1), |
2199 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_1, | 2511 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
2200 | .subvendor = PCI_ANY_ID, | ||
2201 | .subdevice = PCI_ANY_ID, | ||
2202 | .driver_data = DEV_IRQMASK_1|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2203 | }, | 2512 | }, |
2204 | { /* nForce2 Ethernet Controller */ | 2513 | { /* nForce2 Ethernet Controller */ |
2205 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2514 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2), |
2206 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_2, | 2515 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
2207 | .subvendor = PCI_ANY_ID, | ||
2208 | .subdevice = PCI_ANY_ID, | ||
2209 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2210 | }, | 2516 | }, |
2211 | { /* nForce3 Ethernet Controller */ | 2517 | { /* nForce3 Ethernet Controller */ |
2212 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2518 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3), |
2213 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_3, | 2519 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
2214 | .subvendor = PCI_ANY_ID, | ||
2215 | .subdevice = PCI_ANY_ID, | ||
2216 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2217 | }, | 2520 | }, |
2218 | { /* nForce3 Ethernet Controller */ | 2521 | { /* nForce3 Ethernet Controller */ |
2219 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2522 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4), |
2220 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_4, | 2523 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, |
2221 | .subvendor = PCI_ANY_ID, | ||
2222 | .subdevice = PCI_ANY_ID, | ||
2223 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2224 | }, | 2524 | }, |
2225 | { /* nForce3 Ethernet Controller */ | 2525 | { /* nForce3 Ethernet Controller */ |
2226 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2526 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5), |
2227 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_5, | 2527 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, |
2228 | .subvendor = PCI_ANY_ID, | ||
2229 | .subdevice = PCI_ANY_ID, | ||
2230 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2231 | }, | 2528 | }, |
2232 | { /* nForce3 Ethernet Controller */ | 2529 | { /* nForce3 Ethernet Controller */ |
2233 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2530 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6), |
2234 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_6, | 2531 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, |
2235 | .subvendor = PCI_ANY_ID, | ||
2236 | .subdevice = PCI_ANY_ID, | ||
2237 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2238 | }, | 2532 | }, |
2239 | { /* nForce3 Ethernet Controller */ | 2533 | { /* nForce3 Ethernet Controller */ |
2240 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2534 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7), |
2241 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_7, | 2535 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, |
2242 | .subvendor = PCI_ANY_ID, | ||
2243 | .subdevice = PCI_ANY_ID, | ||
2244 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2245 | }, | 2536 | }, |
2246 | { /* CK804 Ethernet Controller */ | 2537 | { /* CK804 Ethernet Controller */ |
2247 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2538 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8), |
2248 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_8, | 2539 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, |
2249 | .subvendor = PCI_ANY_ID, | ||
2250 | .subdevice = PCI_ANY_ID, | ||
2251 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2252 | }, | 2540 | }, |
2253 | { /* CK804 Ethernet Controller */ | 2541 | { /* CK804 Ethernet Controller */ |
2254 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2542 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9), |
2255 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_9, | 2543 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, |
2256 | .subvendor = PCI_ANY_ID, | ||
2257 | .subdevice = PCI_ANY_ID, | ||
2258 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2259 | }, | 2544 | }, |
2260 | { /* MCP04 Ethernet Controller */ | 2545 | { /* MCP04 Ethernet Controller */ |
2261 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2546 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10), |
2262 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_10, | 2547 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, |
2263 | .subvendor = PCI_ANY_ID, | ||
2264 | .subdevice = PCI_ANY_ID, | ||
2265 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2266 | }, | 2548 | }, |
2267 | { /* MCP04 Ethernet Controller */ | 2549 | { /* MCP04 Ethernet Controller */ |
2268 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2550 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11), |
2269 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_11, | 2551 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, |
2270 | .subvendor = PCI_ANY_ID, | ||
2271 | .subdevice = PCI_ANY_ID, | ||
2272 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2273 | }, | 2552 | }, |
2274 | { /* MCP51 Ethernet Controller */ | 2553 | { /* MCP51 Ethernet Controller */ |
2275 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2554 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12), |
2276 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_12, | 2555 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA, |
2277 | .subvendor = PCI_ANY_ID, | ||
2278 | .subdevice = PCI_ANY_ID, | ||
2279 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2280 | }, | 2556 | }, |
2281 | { /* MCP51 Ethernet Controller */ | 2557 | { /* MCP51 Ethernet Controller */ |
2282 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2558 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13), |
2283 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_13, | 2559 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA, |
2284 | .subvendor = PCI_ANY_ID, | ||
2285 | .subdevice = PCI_ANY_ID, | ||
2286 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2287 | }, | 2560 | }, |
2288 | { /* MCP55 Ethernet Controller */ | 2561 | { /* MCP55 Ethernet Controller */ |
2289 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2562 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14), |
2290 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_14, | 2563 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, |
2291 | .subvendor = PCI_ANY_ID, | ||
2292 | .subdevice = PCI_ANY_ID, | ||
2293 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2294 | }, | 2564 | }, |
2295 | { /* MCP55 Ethernet Controller */ | 2565 | { /* MCP55 Ethernet Controller */ |
2296 | .vendor = PCI_VENDOR_ID_NVIDIA, | 2566 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15), |
2297 | .device = PCI_DEVICE_ID_NVIDIA_NVENET_15, | 2567 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, |
2298 | .subvendor = PCI_ANY_ID, | ||
2299 | .subdevice = PCI_ANY_ID, | ||
2300 | .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, | ||
2301 | }, | 2568 | }, |
2302 | {0,}, | 2569 | {0,}, |
2303 | }; | 2570 | }; |
diff --git a/drivers/net/hamradio/baycom_epp.c b/drivers/net/hamradio/baycom_epp.c index a7f15d9f13e5..5298096afbdb 100644 --- a/drivers/net/hamradio/baycom_epp.c +++ b/drivers/net/hamradio/baycom_epp.c | |||
@@ -54,6 +54,7 @@ | |||
54 | #include <linux/kmod.h> | 54 | #include <linux/kmod.h> |
55 | #include <linux/hdlcdrv.h> | 55 | #include <linux/hdlcdrv.h> |
56 | #include <linux/baycom.h> | 56 | #include <linux/baycom.h> |
57 | #include <linux/jiffies.h> | ||
57 | #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) | 58 | #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) |
58 | /* prototypes for ax25_encapsulate and ax25_rebuild_header */ | 59 | /* prototypes for ax25_encapsulate and ax25_rebuild_header */ |
59 | #include <net/ax25.h> | 60 | #include <net/ax25.h> |
@@ -287,7 +288,7 @@ static inline void baycom_int_freq(struct baycom_state *bc) | |||
287 | * measure the interrupt frequency | 288 | * measure the interrupt frequency |
288 | */ | 289 | */ |
289 | bc->debug_vals.cur_intcnt++; | 290 | bc->debug_vals.cur_intcnt++; |
290 | if ((cur_jiffies - bc->debug_vals.last_jiffies) >= HZ) { | 291 | if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { |
291 | bc->debug_vals.last_jiffies = cur_jiffies; | 292 | bc->debug_vals.last_jiffies = cur_jiffies; |
292 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; | 293 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; |
293 | bc->debug_vals.cur_intcnt = 0; | 294 | bc->debug_vals.cur_intcnt = 0; |
diff --git a/drivers/net/hamradio/baycom_par.c b/drivers/net/hamradio/baycom_par.c index 612ad452bee0..3b1bef1ee215 100644 --- a/drivers/net/hamradio/baycom_par.c +++ b/drivers/net/hamradio/baycom_par.c | |||
@@ -84,6 +84,7 @@ | |||
84 | #include <linux/baycom.h> | 84 | #include <linux/baycom.h> |
85 | #include <linux/parport.h> | 85 | #include <linux/parport.h> |
86 | #include <linux/bitops.h> | 86 | #include <linux/bitops.h> |
87 | #include <linux/jiffies.h> | ||
87 | 88 | ||
88 | #include <asm/bug.h> | 89 | #include <asm/bug.h> |
89 | #include <asm/system.h> | 90 | #include <asm/system.h> |
@@ -165,7 +166,7 @@ static void __inline__ baycom_int_freq(struct baycom_state *bc) | |||
165 | * measure the interrupt frequency | 166 | * measure the interrupt frequency |
166 | */ | 167 | */ |
167 | bc->debug_vals.cur_intcnt++; | 168 | bc->debug_vals.cur_intcnt++; |
168 | if ((cur_jiffies - bc->debug_vals.last_jiffies) >= HZ) { | 169 | if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { |
169 | bc->debug_vals.last_jiffies = cur_jiffies; | 170 | bc->debug_vals.last_jiffies = cur_jiffies; |
170 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; | 171 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; |
171 | bc->debug_vals.cur_intcnt = 0; | 172 | bc->debug_vals.cur_intcnt = 0; |
diff --git a/drivers/net/hamradio/baycom_ser_fdx.c b/drivers/net/hamradio/baycom_ser_fdx.c index 25f270b05378..232793d2ce6b 100644 --- a/drivers/net/hamradio/baycom_ser_fdx.c +++ b/drivers/net/hamradio/baycom_ser_fdx.c | |||
@@ -79,6 +79,7 @@ | |||
79 | #include <asm/io.h> | 79 | #include <asm/io.h> |
80 | #include <linux/hdlcdrv.h> | 80 | #include <linux/hdlcdrv.h> |
81 | #include <linux/baycom.h> | 81 | #include <linux/baycom.h> |
82 | #include <linux/jiffies.h> | ||
82 | 83 | ||
83 | /* --------------------------------------------------------------------- */ | 84 | /* --------------------------------------------------------------------- */ |
84 | 85 | ||
@@ -159,7 +160,7 @@ static inline void baycom_int_freq(struct baycom_state *bc) | |||
159 | * measure the interrupt frequency | 160 | * measure the interrupt frequency |
160 | */ | 161 | */ |
161 | bc->debug_vals.cur_intcnt++; | 162 | bc->debug_vals.cur_intcnt++; |
162 | if ((cur_jiffies - bc->debug_vals.last_jiffies) >= HZ) { | 163 | if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { |
163 | bc->debug_vals.last_jiffies = cur_jiffies; | 164 | bc->debug_vals.last_jiffies = cur_jiffies; |
164 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; | 165 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; |
165 | bc->debug_vals.cur_intcnt = 0; | 166 | bc->debug_vals.cur_intcnt = 0; |
diff --git a/drivers/net/hamradio/baycom_ser_hdx.c b/drivers/net/hamradio/baycom_ser_hdx.c index eead85d00962..be596a3eb3fd 100644 --- a/drivers/net/hamradio/baycom_ser_hdx.c +++ b/drivers/net/hamradio/baycom_ser_hdx.c | |||
@@ -69,6 +69,7 @@ | |||
69 | #include <asm/io.h> | 69 | #include <asm/io.h> |
70 | #include <linux/hdlcdrv.h> | 70 | #include <linux/hdlcdrv.h> |
71 | #include <linux/baycom.h> | 71 | #include <linux/baycom.h> |
72 | #include <linux/jiffies.h> | ||
72 | 73 | ||
73 | /* --------------------------------------------------------------------- */ | 74 | /* --------------------------------------------------------------------- */ |
74 | 75 | ||
@@ -150,7 +151,7 @@ static inline void baycom_int_freq(struct baycom_state *bc) | |||
150 | * measure the interrupt frequency | 151 | * measure the interrupt frequency |
151 | */ | 152 | */ |
152 | bc->debug_vals.cur_intcnt++; | 153 | bc->debug_vals.cur_intcnt++; |
153 | if ((cur_jiffies - bc->debug_vals.last_jiffies) >= HZ) { | 154 | if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { |
154 | bc->debug_vals.last_jiffies = cur_jiffies; | 155 | bc->debug_vals.last_jiffies = cur_jiffies; |
155 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; | 156 | bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; |
156 | bc->debug_vals.cur_intcnt = 0; | 157 | bc->debug_vals.cur_intcnt = 0; |
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c index 3035422f5ad8..e94952e799fe 100644 --- a/drivers/net/hamradio/mkiss.c +++ b/drivers/net/hamradio/mkiss.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <linux/etherdevice.h> | 46 | #include <linux/etherdevice.h> |
47 | #include <linux/skbuff.h> | 47 | #include <linux/skbuff.h> |
48 | #include <linux/if_arp.h> | 48 | #include <linux/if_arp.h> |
49 | #include <linux/jiffies.h> | ||
49 | 50 | ||
50 | #include <net/ax25.h> | 51 | #include <net/ax25.h> |
51 | 52 | ||
@@ -429,7 +430,7 @@ static int ax_xmit(struct sk_buff *skb, struct net_device *dev) | |||
429 | * May be we must check transmitter timeout here ? | 430 | * May be we must check transmitter timeout here ? |
430 | * 14 Oct 1994 Dmitry Gorodchanin. | 431 | * 14 Oct 1994 Dmitry Gorodchanin. |
431 | */ | 432 | */ |
432 | if (jiffies - dev->trans_start < 20 * HZ) { | 433 | if (time_before(jiffies, dev->trans_start + 20 * HZ)) { |
433 | /* 20 sec timeout not reached */ | 434 | /* 20 sec timeout not reached */ |
434 | return 1; | 435 | return 1; |
435 | } | 436 | } |
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index b33111e21313..2cb6f1c8c6ed 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c | |||
@@ -68,6 +68,7 @@ static DEFINE_PER_CPU(struct net_device_stats, loopback_stats); | |||
68 | * of largesending device modulo TCP checksum, which is ignored for loopback. | 68 | * of largesending device modulo TCP checksum, which is ignored for loopback. |
69 | */ | 69 | */ |
70 | 70 | ||
71 | #ifdef LOOPBACK_TSO | ||
71 | static void emulate_large_send_offload(struct sk_buff *skb) | 72 | static void emulate_large_send_offload(struct sk_buff *skb) |
72 | { | 73 | { |
73 | struct iphdr *iph = skb->nh.iph; | 74 | struct iphdr *iph = skb->nh.iph; |
@@ -119,6 +120,7 @@ static void emulate_large_send_offload(struct sk_buff *skb) | |||
119 | 120 | ||
120 | dev_kfree_skb(skb); | 121 | dev_kfree_skb(skb); |
121 | } | 122 | } |
123 | #endif /* LOOPBACK_TSO */ | ||
122 | 124 | ||
123 | /* | 125 | /* |
124 | * The higher levels take care of making this non-reentrant (it's | 126 | * The higher levels take care of making this non-reentrant (it's |
@@ -130,12 +132,13 @@ static int loopback_xmit(struct sk_buff *skb, struct net_device *dev) | |||
130 | 132 | ||
131 | skb_orphan(skb); | 133 | skb_orphan(skb); |
132 | 134 | ||
133 | skb->protocol=eth_type_trans(skb,dev); | 135 | skb->protocol = eth_type_trans(skb,dev); |
134 | skb->dev=dev; | 136 | skb->dev = dev; |
135 | #ifndef LOOPBACK_MUST_CHECKSUM | 137 | #ifndef LOOPBACK_MUST_CHECKSUM |
136 | skb->ip_summed = CHECKSUM_UNNECESSARY; | 138 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
137 | #endif | 139 | #endif |
138 | 140 | ||
141 | #ifdef LOOPBACK_TSO | ||
139 | if (skb_shinfo(skb)->tso_size) { | 142 | if (skb_shinfo(skb)->tso_size) { |
140 | BUG_ON(skb->protocol != htons(ETH_P_IP)); | 143 | BUG_ON(skb->protocol != htons(ETH_P_IP)); |
141 | BUG_ON(skb->nh.iph->protocol != IPPROTO_TCP); | 144 | BUG_ON(skb->nh.iph->protocol != IPPROTO_TCP); |
@@ -143,14 +146,14 @@ static int loopback_xmit(struct sk_buff *skb, struct net_device *dev) | |||
143 | emulate_large_send_offload(skb); | 146 | emulate_large_send_offload(skb); |
144 | return 0; | 147 | return 0; |
145 | } | 148 | } |
146 | 149 | #endif | |
147 | dev->last_rx = jiffies; | 150 | dev->last_rx = jiffies; |
148 | 151 | ||
149 | lb_stats = &per_cpu(loopback_stats, get_cpu()); | 152 | lb_stats = &per_cpu(loopback_stats, get_cpu()); |
150 | lb_stats->rx_bytes += skb->len; | 153 | lb_stats->rx_bytes += skb->len; |
151 | lb_stats->tx_bytes += skb->len; | 154 | lb_stats->tx_bytes = lb_stats->rx_bytes; |
152 | lb_stats->rx_packets++; | 155 | lb_stats->rx_packets++; |
153 | lb_stats->tx_packets++; | 156 | lb_stats->tx_packets = lb_stats->rx_packets; |
154 | put_cpu(); | 157 | put_cpu(); |
155 | 158 | ||
156 | netif_rx(skb); | 159 | netif_rx(skb); |
@@ -208,9 +211,12 @@ struct net_device loopback_dev = { | |||
208 | .type = ARPHRD_LOOPBACK, /* 0x0001*/ | 211 | .type = ARPHRD_LOOPBACK, /* 0x0001*/ |
209 | .rebuild_header = eth_rebuild_header, | 212 | .rebuild_header = eth_rebuild_header, |
210 | .flags = IFF_LOOPBACK, | 213 | .flags = IFF_LOOPBACK, |
211 | .features = NETIF_F_SG|NETIF_F_FRAGLIST | 214 | .features = NETIF_F_SG | NETIF_F_FRAGLIST |
212 | |NETIF_F_NO_CSUM|NETIF_F_HIGHDMA | 215 | #ifdef LOOPBACK_TSO |
213 | |NETIF_F_LLTX, | 216 | | NETIF_F_TSO |
217 | #endif | ||
218 | | NETIF_F_NO_CSUM | NETIF_F_HIGHDMA | ||
219 | | NETIF_F_LLTX, | ||
214 | .ethtool_ops = &loopback_ethtool_ops, | 220 | .ethtool_ops = &loopback_ethtool_ops, |
215 | }; | 221 | }; |
216 | 222 | ||
diff --git a/drivers/net/pci-skeleton.c b/drivers/net/pci-skeleton.c index 4a391ea0f58a..a1ac4bd1696e 100644 --- a/drivers/net/pci-skeleton.c +++ b/drivers/net/pci-skeleton.c | |||
@@ -486,9 +486,9 @@ struct netdrv_private { | |||
486 | MODULE_AUTHOR ("Jeff Garzik <jgarzik@pobox.com>"); | 486 | MODULE_AUTHOR ("Jeff Garzik <jgarzik@pobox.com>"); |
487 | MODULE_DESCRIPTION ("Skeleton for a PCI Fast Ethernet driver"); | 487 | MODULE_DESCRIPTION ("Skeleton for a PCI Fast Ethernet driver"); |
488 | MODULE_LICENSE("GPL"); | 488 | MODULE_LICENSE("GPL"); |
489 | MODULE_PARM (multicast_filter_limit, "i"); | 489 | module_param(multicast_filter_limit, int, 0); |
490 | MODULE_PARM (max_interrupt_work, "i"); | 490 | module_param(max_interrupt_work, int, 0); |
491 | MODULE_PARM (media, "1-" __MODULE_STRING(8) "i"); | 491 | module_param_array(media, int, NULL, 0); |
492 | MODULE_PARM_DESC (multicast_filter_limit, "pci-skeleton maximum number of filtered multicast addresses"); | 492 | MODULE_PARM_DESC (multicast_filter_limit, "pci-skeleton maximum number of filtered multicast addresses"); |
493 | MODULE_PARM_DESC (max_interrupt_work, "pci-skeleton maximum events handled per interrupt"); | 493 | MODULE_PARM_DESC (max_interrupt_work, "pci-skeleton maximum events handled per interrupt"); |
494 | MODULE_PARM_DESC (media, "pci-skeleton: Bits 0-3: media type, bit 17: full duplex"); | 494 | MODULE_PARM_DESC (media, "pci-skeleton: Bits 0-3: media type, bit 17: full duplex"); |
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig new file mode 100644 index 000000000000..8b5db2343cc3 --- /dev/null +++ b/drivers/net/phy/Kconfig | |||
@@ -0,0 +1,57 @@ | |||
1 | # | ||
2 | # PHY Layer Configuration | ||
3 | # | ||
4 | |||
5 | menu "PHY device support" | ||
6 | |||
7 | config PHYLIB | ||
8 | bool "PHY Device support and infrastructure" | ||
9 | depends on NET_ETHERNET | ||
10 | help | ||
11 | Ethernet controllers are usually attached to PHY | ||
12 | devices. This option provides infrastructure for | ||
13 | managing PHY devices. | ||
14 | |||
15 | config PHYCONTROL | ||
16 | bool "Support for automatically handling PHY state changes" | ||
17 | depends on PHYLIB | ||
18 | help | ||
19 | Adds code to perform all the work for keeping PHY link | ||
20 | state (speed/duplex/etc) up-to-date. Also handles | ||
21 | interrupts. | ||
22 | |||
23 | comment "MII PHY device drivers" | ||
24 | depends on PHYLIB | ||
25 | |||
26 | config MARVELL_PHY | ||
27 | bool "Drivers for Marvell PHYs" | ||
28 | depends on PHYLIB | ||
29 | ---help--- | ||
30 | Currently has a driver for the 88E1011S | ||
31 | |||
32 | config DAVICOM_PHY | ||
33 | bool "Drivers for Davicom PHYs" | ||
34 | depends on PHYLIB | ||
35 | ---help--- | ||
36 | Currently supports dm9161e and dm9131 | ||
37 | |||
38 | config QSEMI_PHY | ||
39 | bool "Drivers for Quality Semiconductor PHYs" | ||
40 | depends on PHYLIB | ||
41 | ---help--- | ||
42 | Currently supports the qs6612 | ||
43 | |||
44 | config LXT_PHY | ||
45 | bool "Drivers for the Intel LXT PHYs" | ||
46 | depends on PHYLIB | ||
47 | ---help--- | ||
48 | Currently supports the lxt970, lxt971 | ||
49 | |||
50 | config CICADA_PHY | ||
51 | bool "Drivers for the Cicada PHYs" | ||
52 | depends on PHYLIB | ||
53 | ---help--- | ||
54 | Currently supports the cis8204 | ||
55 | |||
56 | endmenu | ||
57 | |||
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile new file mode 100644 index 000000000000..1af05de6ced0 --- /dev/null +++ b/drivers/net/phy/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # Makefile for Linux PHY drivers | ||
2 | |||
3 | obj-$(CONFIG_PHYLIB) += phy.o phy_device.o mdio_bus.o | ||
4 | |||
5 | obj-$(CONFIG_MARVELL_PHY) += marvell.o | ||
6 | obj-$(CONFIG_DAVICOM_PHY) += davicom.o | ||
7 | obj-$(CONFIG_CICADA_PHY) += cicada.o | ||
8 | obj-$(CONFIG_LXT_PHY) += lxt.o | ||
9 | obj-$(CONFIG_QSEMI_PHY) += qsemi.o | ||
diff --git a/drivers/net/phy/cicada.c b/drivers/net/phy/cicada.c new file mode 100644 index 000000000000..c47fb2ecd147 --- /dev/null +++ b/drivers/net/phy/cicada.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/cicada.c | ||
3 | * | ||
4 | * Driver for Cicada PHYs | ||
5 | * | ||
6 | * Author: Andy Fleming | ||
7 | * | ||
8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/config.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/unistd.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/etherdevice.h> | ||
28 | #include <linux/skbuff.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/mm.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/version.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/ethtool.h> | ||
35 | #include <linux/phy.h> | ||
36 | |||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | ||
39 | #include <asm/uaccess.h> | ||
40 | |||
41 | /* Cicada Extended Control Register 1 */ | ||
42 | #define MII_CIS8201_EXT_CON1 0x17 | ||
43 | #define MII_CIS8201_EXTCON1_INIT 0x0000 | ||
44 | |||
45 | /* Cicada Interrupt Mask Register */ | ||
46 | #define MII_CIS8201_IMASK 0x19 | ||
47 | #define MII_CIS8201_IMASK_IEN 0x8000 | ||
48 | #define MII_CIS8201_IMASK_SPEED 0x4000 | ||
49 | #define MII_CIS8201_IMASK_LINK 0x2000 | ||
50 | #define MII_CIS8201_IMASK_DUPLEX 0x1000 | ||
51 | #define MII_CIS8201_IMASK_MASK 0xf000 | ||
52 | |||
53 | /* Cicada Interrupt Status Register */ | ||
54 | #define MII_CIS8201_ISTAT 0x1a | ||
55 | #define MII_CIS8201_ISTAT_STATUS 0x8000 | ||
56 | #define MII_CIS8201_ISTAT_SPEED 0x4000 | ||
57 | #define MII_CIS8201_ISTAT_LINK 0x2000 | ||
58 | #define MII_CIS8201_ISTAT_DUPLEX 0x1000 | ||
59 | |||
60 | /* Cicada Auxiliary Control/Status Register */ | ||
61 | #define MII_CIS8201_AUX_CONSTAT 0x1c | ||
62 | #define MII_CIS8201_AUXCONSTAT_INIT 0x0004 | ||
63 | #define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020 | ||
64 | #define MII_CIS8201_AUXCONSTAT_SPEED 0x0018 | ||
65 | #define MII_CIS8201_AUXCONSTAT_GBIT 0x0010 | ||
66 | #define MII_CIS8201_AUXCONSTAT_100 0x0008 | ||
67 | |||
68 | MODULE_DESCRIPTION("Cicadia PHY driver"); | ||
69 | MODULE_AUTHOR("Andy Fleming"); | ||
70 | MODULE_LICENSE("GPL"); | ||
71 | |||
72 | static int cis820x_config_init(struct phy_device *phydev) | ||
73 | { | ||
74 | int err; | ||
75 | |||
76 | err = phy_write(phydev, MII_CIS8201_AUX_CONSTAT, | ||
77 | MII_CIS8201_AUXCONSTAT_INIT); | ||
78 | |||
79 | if (err < 0) | ||
80 | return err; | ||
81 | |||
82 | err = phy_write(phydev, MII_CIS8201_EXT_CON1, | ||
83 | MII_CIS8201_EXTCON1_INIT); | ||
84 | |||
85 | return err; | ||
86 | } | ||
87 | |||
88 | static int cis820x_ack_interrupt(struct phy_device *phydev) | ||
89 | { | ||
90 | int err = phy_read(phydev, MII_CIS8201_ISTAT); | ||
91 | |||
92 | return (err < 0) ? err : 0; | ||
93 | } | ||
94 | |||
95 | static int cis820x_config_intr(struct phy_device *phydev) | ||
96 | { | ||
97 | int err; | ||
98 | |||
99 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | ||
100 | err = phy_write(phydev, MII_CIS8201_IMASK, | ||
101 | MII_CIS8201_IMASK_MASK); | ||
102 | else | ||
103 | err = phy_write(phydev, MII_CIS8201_IMASK, 0); | ||
104 | |||
105 | return err; | ||
106 | } | ||
107 | |||
108 | /* Cicada 820x */ | ||
109 | static struct phy_driver cis8204_driver = { | ||
110 | .phy_id = 0x000fc440, | ||
111 | .name = "Cicada Cis8204", | ||
112 | .phy_id_mask = 0x000fffc0, | ||
113 | .features = PHY_GBIT_FEATURES, | ||
114 | .flags = PHY_HAS_INTERRUPT, | ||
115 | .config_init = &cis820x_config_init, | ||
116 | .config_aneg = &genphy_config_aneg, | ||
117 | .read_status = &genphy_read_status, | ||
118 | .ack_interrupt = &cis820x_ack_interrupt, | ||
119 | .config_intr = &cis820x_config_intr, | ||
120 | .driver = { .owner = THIS_MODULE,}, | ||
121 | }; | ||
122 | |||
123 | static int __init cis8204_init(void) | ||
124 | { | ||
125 | return phy_driver_register(&cis8204_driver); | ||
126 | } | ||
127 | |||
128 | static void __exit cis8204_exit(void) | ||
129 | { | ||
130 | phy_driver_unregister(&cis8204_driver); | ||
131 | } | ||
132 | |||
133 | module_init(cis8204_init); | ||
134 | module_exit(cis8204_exit); | ||
diff --git a/drivers/net/phy/davicom.c b/drivers/net/phy/davicom.c new file mode 100644 index 000000000000..6caf499fae32 --- /dev/null +++ b/drivers/net/phy/davicom.c | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/davicom.c | ||
3 | * | ||
4 | * Driver for Davicom PHYs | ||
5 | * | ||
6 | * Author: Andy Fleming | ||
7 | * | ||
8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/config.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/unistd.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/etherdevice.h> | ||
28 | #include <linux/skbuff.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/mm.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/version.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/ethtool.h> | ||
35 | #include <linux/phy.h> | ||
36 | |||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | ||
39 | #include <asm/uaccess.h> | ||
40 | |||
41 | #define MII_DM9161_SCR 0x10 | ||
42 | #define MII_DM9161_SCR_INIT 0x0610 | ||
43 | |||
44 | /* DM9161 Interrupt Register */ | ||
45 | #define MII_DM9161_INTR 0x15 | ||
46 | #define MII_DM9161_INTR_PEND 0x8000 | ||
47 | #define MII_DM9161_INTR_DPLX_MASK 0x0800 | ||
48 | #define MII_DM9161_INTR_SPD_MASK 0x0400 | ||
49 | #define MII_DM9161_INTR_LINK_MASK 0x0200 | ||
50 | #define MII_DM9161_INTR_MASK 0x0100 | ||
51 | #define MII_DM9161_INTR_DPLX_CHANGE 0x0010 | ||
52 | #define MII_DM9161_INTR_SPD_CHANGE 0x0008 | ||
53 | #define MII_DM9161_INTR_LINK_CHANGE 0x0004 | ||
54 | #define MII_DM9161_INTR_INIT 0x0000 | ||
55 | #define MII_DM9161_INTR_STOP \ | ||
56 | (MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK \ | ||
57 | | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK) | ||
58 | |||
59 | /* DM9161 10BT Configuration/Status */ | ||
60 | #define MII_DM9161_10BTCSR 0x12 | ||
61 | #define MII_DM9161_10BTCSR_INIT 0x7800 | ||
62 | |||
63 | MODULE_DESCRIPTION("Davicom PHY driver"); | ||
64 | MODULE_AUTHOR("Andy Fleming"); | ||
65 | MODULE_LICENSE("GPL"); | ||
66 | |||
67 | |||
68 | #define DM9161_DELAY 1 | ||
69 | static int dm9161_config_intr(struct phy_device *phydev) | ||
70 | { | ||
71 | int temp; | ||
72 | |||
73 | temp = phy_read(phydev, MII_DM9161_INTR); | ||
74 | |||
75 | if (temp < 0) | ||
76 | return temp; | ||
77 | |||
78 | if(PHY_INTERRUPT_ENABLED == phydev->interrupts ) | ||
79 | temp &= ~(MII_DM9161_INTR_STOP); | ||
80 | else | ||
81 | temp |= MII_DM9161_INTR_STOP; | ||
82 | |||
83 | temp = phy_write(phydev, MII_DM9161_INTR, temp); | ||
84 | |||
85 | return temp; | ||
86 | } | ||
87 | |||
88 | static int dm9161_config_aneg(struct phy_device *phydev) | ||
89 | { | ||
90 | int err; | ||
91 | |||
92 | /* Isolate the PHY */ | ||
93 | err = phy_write(phydev, MII_BMCR, BMCR_ISOLATE); | ||
94 | |||
95 | if (err < 0) | ||
96 | return err; | ||
97 | |||
98 | /* Configure the new settings */ | ||
99 | err = genphy_config_aneg(phydev); | ||
100 | |||
101 | if (err < 0) | ||
102 | return err; | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int dm9161_config_init(struct phy_device *phydev) | ||
108 | { | ||
109 | int err; | ||
110 | |||
111 | /* Isolate the PHY */ | ||
112 | err = phy_write(phydev, MII_BMCR, BMCR_ISOLATE); | ||
113 | |||
114 | if (err < 0) | ||
115 | return err; | ||
116 | |||
117 | /* Do not bypass the scrambler/descrambler */ | ||
118 | err = phy_write(phydev, MII_DM9161_SCR, MII_DM9161_SCR_INIT); | ||
119 | |||
120 | if (err < 0) | ||
121 | return err; | ||
122 | |||
123 | /* Clear 10BTCSR to default */ | ||
124 | err = phy_write(phydev, MII_DM9161_10BTCSR, MII_DM9161_10BTCSR_INIT); | ||
125 | |||
126 | if (err < 0) | ||
127 | return err; | ||
128 | |||
129 | /* Reconnect the PHY, and enable Autonegotiation */ | ||
130 | err = phy_write(phydev, MII_BMCR, BMCR_ANENABLE); | ||
131 | |||
132 | if (err < 0) | ||
133 | return err; | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | static int dm9161_ack_interrupt(struct phy_device *phydev) | ||
139 | { | ||
140 | int err = phy_read(phydev, MII_DM9161_INTR); | ||
141 | |||
142 | return (err < 0) ? err : 0; | ||
143 | } | ||
144 | |||
145 | static struct phy_driver dm9161_driver = { | ||
146 | .phy_id = 0x0181b880, | ||
147 | .name = "Davicom DM9161E", | ||
148 | .phy_id_mask = 0x0ffffff0, | ||
149 | .features = PHY_BASIC_FEATURES, | ||
150 | .config_init = dm9161_config_init, | ||
151 | .config_aneg = dm9161_config_aneg, | ||
152 | .read_status = genphy_read_status, | ||
153 | .driver = { .owner = THIS_MODULE,}, | ||
154 | }; | ||
155 | |||
156 | static struct phy_driver dm9131_driver = { | ||
157 | .phy_id = 0x00181b80, | ||
158 | .name = "Davicom DM9131", | ||
159 | .phy_id_mask = 0x0ffffff0, | ||
160 | .features = PHY_BASIC_FEATURES, | ||
161 | .flags = PHY_HAS_INTERRUPT, | ||
162 | .config_aneg = genphy_config_aneg, | ||
163 | .read_status = genphy_read_status, | ||
164 | .ack_interrupt = dm9161_ack_interrupt, | ||
165 | .config_intr = dm9161_config_intr, | ||
166 | .driver = { .owner = THIS_MODULE,}, | ||
167 | }; | ||
168 | |||
169 | static int __init davicom_init(void) | ||
170 | { | ||
171 | int ret; | ||
172 | |||
173 | ret = phy_driver_register(&dm9161_driver); | ||
174 | if (ret) | ||
175 | goto err1; | ||
176 | |||
177 | ret = phy_driver_register(&dm9131_driver); | ||
178 | if (ret) | ||
179 | goto err2; | ||
180 | return 0; | ||
181 | |||
182 | err2: | ||
183 | phy_driver_unregister(&dm9161_driver); | ||
184 | err1: | ||
185 | return ret; | ||
186 | } | ||
187 | |||
188 | static void __exit davicom_exit(void) | ||
189 | { | ||
190 | phy_driver_unregister(&dm9161_driver); | ||
191 | phy_driver_unregister(&dm9131_driver); | ||
192 | } | ||
193 | |||
194 | module_init(davicom_init); | ||
195 | module_exit(davicom_exit); | ||
diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c new file mode 100644 index 000000000000..4c840448ec86 --- /dev/null +++ b/drivers/net/phy/lxt.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/lxt.c | ||
3 | * | ||
4 | * Driver for Intel LXT PHYs | ||
5 | * | ||
6 | * Author: Andy Fleming | ||
7 | * | ||
8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/config.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/unistd.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/etherdevice.h> | ||
28 | #include <linux/skbuff.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/mm.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/version.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/ethtool.h> | ||
35 | #include <linux/phy.h> | ||
36 | |||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | ||
39 | #include <asm/uaccess.h> | ||
40 | |||
41 | /* The Level one LXT970 is used by many boards */ | ||
42 | |||
43 | #define MII_LXT970_IER 17 /* Interrupt Enable Register */ | ||
44 | |||
45 | #define MII_LXT970_IER_IEN 0x0002 | ||
46 | |||
47 | #define MII_LXT970_ISR 18 /* Interrupt Status Register */ | ||
48 | |||
49 | #define MII_LXT970_CONFIG 19 /* Configuration Register */ | ||
50 | |||
51 | /* ------------------------------------------------------------------------- */ | ||
52 | /* The Level one LXT971 is used on some of my custom boards */ | ||
53 | |||
54 | /* register definitions for the 971 */ | ||
55 | #define MII_LXT971_IER 18 /* Interrupt Enable Register */ | ||
56 | #define MII_LXT971_IER_IEN 0x00f2 | ||
57 | |||
58 | #define MII_LXT971_ISR 19 /* Interrupt Status Register */ | ||
59 | |||
60 | |||
61 | MODULE_DESCRIPTION("Intel LXT PHY driver"); | ||
62 | MODULE_AUTHOR("Andy Fleming"); | ||
63 | MODULE_LICENSE("GPL"); | ||
64 | |||
65 | static int lxt970_ack_interrupt(struct phy_device *phydev) | ||
66 | { | ||
67 | int err; | ||
68 | |||
69 | err = phy_read(phydev, MII_BMSR); | ||
70 | |||
71 | if (err < 0) | ||
72 | return err; | ||
73 | |||
74 | err = phy_read(phydev, MII_LXT970_ISR); | ||
75 | |||
76 | if (err < 0) | ||
77 | return err; | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | static int lxt970_config_intr(struct phy_device *phydev) | ||
83 | { | ||
84 | int err; | ||
85 | |||
86 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | ||
87 | err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN); | ||
88 | else | ||
89 | err = phy_write(phydev, MII_LXT970_IER, 0); | ||
90 | |||
91 | return err; | ||
92 | } | ||
93 | |||
94 | static int lxt970_config_init(struct phy_device *phydev) | ||
95 | { | ||
96 | int err; | ||
97 | |||
98 | err = phy_write(phydev, MII_LXT970_CONFIG, 0); | ||
99 | |||
100 | return err; | ||
101 | } | ||
102 | |||
103 | |||
104 | static int lxt971_ack_interrupt(struct phy_device *phydev) | ||
105 | { | ||
106 | int err = phy_read(phydev, MII_LXT971_ISR); | ||
107 | |||
108 | if (err < 0) | ||
109 | return err; | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static int lxt971_config_intr(struct phy_device *phydev) | ||
115 | { | ||
116 | int err; | ||
117 | |||
118 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | ||
119 | err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN); | ||
120 | else | ||
121 | err = phy_write(phydev, MII_LXT971_IER, 0); | ||
122 | |||
123 | return err; | ||
124 | } | ||
125 | |||
126 | static struct phy_driver lxt970_driver = { | ||
127 | .phy_id = 0x07810000, | ||
128 | .name = "LXT970", | ||
129 | .phy_id_mask = 0x0fffffff, | ||
130 | .features = PHY_BASIC_FEATURES, | ||
131 | .flags = PHY_HAS_INTERRUPT, | ||
132 | .config_init = lxt970_config_init, | ||
133 | .config_aneg = genphy_config_aneg, | ||
134 | .read_status = genphy_read_status, | ||
135 | .ack_interrupt = lxt970_ack_interrupt, | ||
136 | .config_intr = lxt970_config_intr, | ||
137 | .driver = { .owner = THIS_MODULE,}, | ||
138 | }; | ||
139 | |||
140 | static struct phy_driver lxt971_driver = { | ||
141 | .phy_id = 0x0001378e, | ||
142 | .name = "LXT971", | ||
143 | .phy_id_mask = 0x0fffffff, | ||
144 | .features = PHY_BASIC_FEATURES, | ||
145 | .flags = PHY_HAS_INTERRUPT, | ||
146 | .config_aneg = genphy_config_aneg, | ||
147 | .read_status = genphy_read_status, | ||
148 | .ack_interrupt = lxt971_ack_interrupt, | ||
149 | .config_intr = lxt971_config_intr, | ||
150 | .driver = { .owner = THIS_MODULE,}, | ||
151 | }; | ||
152 | |||
153 | static int __init lxt_init(void) | ||
154 | { | ||
155 | int ret; | ||
156 | |||
157 | ret = phy_driver_register(&lxt970_driver); | ||
158 | if (ret) | ||
159 | goto err1; | ||
160 | |||
161 | ret = phy_driver_register(&lxt971_driver); | ||
162 | if (ret) | ||
163 | goto err2; | ||
164 | return 0; | ||
165 | |||
166 | err2: | ||
167 | phy_driver_unregister(&lxt970_driver); | ||
168 | err1: | ||
169 | return ret; | ||
170 | } | ||
171 | |||
172 | static void __exit lxt_exit(void) | ||
173 | { | ||
174 | phy_driver_unregister(&lxt970_driver); | ||
175 | phy_driver_unregister(&lxt971_driver); | ||
176 | } | ||
177 | |||
178 | module_init(lxt_init); | ||
179 | module_exit(lxt_exit); | ||
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c new file mode 100644 index 000000000000..4a72b025006b --- /dev/null +++ b/drivers/net/phy/marvell.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/marvell.c | ||
3 | * | ||
4 | * Driver for Marvell PHYs | ||
5 | * | ||
6 | * Author: Andy Fleming | ||
7 | * | ||
8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/config.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/unistd.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/etherdevice.h> | ||
28 | #include <linux/skbuff.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/mm.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/version.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/ethtool.h> | ||
35 | #include <linux/phy.h> | ||
36 | |||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | ||
39 | #include <asm/uaccess.h> | ||
40 | |||
41 | #define MII_M1011_IEVENT 0x13 | ||
42 | #define MII_M1011_IEVENT_CLEAR 0x0000 | ||
43 | |||
44 | #define MII_M1011_IMASK 0x12 | ||
45 | #define MII_M1011_IMASK_INIT 0x6400 | ||
46 | #define MII_M1011_IMASK_CLEAR 0x0000 | ||
47 | |||
48 | MODULE_DESCRIPTION("Marvell PHY driver"); | ||
49 | MODULE_AUTHOR("Andy Fleming"); | ||
50 | MODULE_LICENSE("GPL"); | ||
51 | |||
52 | static int marvell_ack_interrupt(struct phy_device *phydev) | ||
53 | { | ||
54 | int err; | ||
55 | |||
56 | /* Clear the interrupts by reading the reg */ | ||
57 | err = phy_read(phydev, MII_M1011_IEVENT); | ||
58 | |||
59 | if (err < 0) | ||
60 | return err; | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int marvell_config_intr(struct phy_device *phydev) | ||
66 | { | ||
67 | int err; | ||
68 | |||
69 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | ||
70 | err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT); | ||
71 | else | ||
72 | err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); | ||
73 | |||
74 | return err; | ||
75 | } | ||
76 | |||
77 | static int marvell_config_aneg(struct phy_device *phydev) | ||
78 | { | ||
79 | int err; | ||
80 | |||
81 | /* The Marvell PHY has an errata which requires | ||
82 | * that certain registers get written in order | ||
83 | * to restart autonegotiation */ | ||
84 | err = phy_write(phydev, MII_BMCR, BMCR_RESET); | ||
85 | |||
86 | if (err < 0) | ||
87 | return err; | ||
88 | |||
89 | err = phy_write(phydev, 0x1d, 0x1f); | ||
90 | if (err < 0) | ||
91 | return err; | ||
92 | |||
93 | err = phy_write(phydev, 0x1e, 0x200c); | ||
94 | if (err < 0) | ||
95 | return err; | ||
96 | |||
97 | err = phy_write(phydev, 0x1d, 0x5); | ||
98 | if (err < 0) | ||
99 | return err; | ||
100 | |||
101 | err = phy_write(phydev, 0x1e, 0); | ||
102 | if (err < 0) | ||
103 | return err; | ||
104 | |||
105 | err = phy_write(phydev, 0x1e, 0x100); | ||
106 | if (err < 0) | ||
107 | return err; | ||
108 | |||
109 | |||
110 | err = genphy_config_aneg(phydev); | ||
111 | |||
112 | return err; | ||
113 | } | ||
114 | |||
115 | |||
116 | static struct phy_driver m88e1101_driver = { | ||
117 | .phy_id = 0x01410c00, | ||
118 | .phy_id_mask = 0xffffff00, | ||
119 | .name = "Marvell 88E1101", | ||
120 | .features = PHY_GBIT_FEATURES, | ||
121 | .flags = PHY_HAS_INTERRUPT, | ||
122 | .config_aneg = &marvell_config_aneg, | ||
123 | .read_status = &genphy_read_status, | ||
124 | .ack_interrupt = &marvell_ack_interrupt, | ||
125 | .config_intr = &marvell_config_intr, | ||
126 | .driver = { .owner = THIS_MODULE,}, | ||
127 | }; | ||
128 | |||
129 | static int __init marvell_init(void) | ||
130 | { | ||
131 | return phy_driver_register(&m88e1101_driver); | ||
132 | } | ||
133 | |||
134 | static void __exit marvell_exit(void) | ||
135 | { | ||
136 | phy_driver_unregister(&m88e1101_driver); | ||
137 | } | ||
138 | |||
139 | module_init(marvell_init); | ||
140 | module_exit(marvell_exit); | ||
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c new file mode 100644 index 000000000000..e75103ba6f86 --- /dev/null +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -0,0 +1,173 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/mdio_bus.c | ||
3 | * | ||
4 | * MDIO Bus interface | ||
5 | * | ||
6 | * Author: Andy Fleming | ||
7 | * | ||
8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/config.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/unistd.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/etherdevice.h> | ||
28 | #include <linux/skbuff.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/mm.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/version.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/ethtool.h> | ||
35 | #include <linux/phy.h> | ||
36 | |||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | ||
39 | #include <asm/uaccess.h> | ||
40 | |||
41 | /* mdiobus_register | ||
42 | * | ||
43 | * description: Called by a bus driver to bring up all the PHYs | ||
44 | * on a given bus, and attach them to the bus | ||
45 | */ | ||
46 | int mdiobus_register(struct mii_bus *bus) | ||
47 | { | ||
48 | int i; | ||
49 | int err = 0; | ||
50 | |||
51 | spin_lock_init(&bus->mdio_lock); | ||
52 | |||
53 | if (NULL == bus || NULL == bus->name || | ||
54 | NULL == bus->read || | ||
55 | NULL == bus->write) | ||
56 | return -EINVAL; | ||
57 | |||
58 | if (bus->reset) | ||
59 | bus->reset(bus); | ||
60 | |||
61 | for (i = 0; i < PHY_MAX_ADDR; i++) { | ||
62 | struct phy_device *phydev; | ||
63 | |||
64 | phydev = get_phy_device(bus, i); | ||
65 | |||
66 | if (IS_ERR(phydev)) | ||
67 | return PTR_ERR(phydev); | ||
68 | |||
69 | /* There's a PHY at this address | ||
70 | * We need to set: | ||
71 | * 1) IRQ | ||
72 | * 2) bus_id | ||
73 | * 3) parent | ||
74 | * 4) bus | ||
75 | * 5) mii_bus | ||
76 | * And, we need to register it */ | ||
77 | if (phydev) { | ||
78 | phydev->irq = bus->irq[i]; | ||
79 | |||
80 | phydev->dev.parent = bus->dev; | ||
81 | phydev->dev.bus = &mdio_bus_type; | ||
82 | sprintf(phydev->dev.bus_id, "phy%d:%d", bus->id, i); | ||
83 | |||
84 | phydev->bus = bus; | ||
85 | |||
86 | err = device_register(&phydev->dev); | ||
87 | |||
88 | if (err) | ||
89 | printk(KERN_ERR "phy %d failed to register\n", | ||
90 | i); | ||
91 | } | ||
92 | |||
93 | bus->phy_map[i] = phydev; | ||
94 | } | ||
95 | |||
96 | pr_info("%s: probed\n", bus->name); | ||
97 | |||
98 | return err; | ||
99 | } | ||
100 | EXPORT_SYMBOL(mdiobus_register); | ||
101 | |||
102 | void mdiobus_unregister(struct mii_bus *bus) | ||
103 | { | ||
104 | int i; | ||
105 | |||
106 | for (i = 0; i < PHY_MAX_ADDR; i++) { | ||
107 | if (bus->phy_map[i]) { | ||
108 | device_unregister(&bus->phy_map[i]->dev); | ||
109 | kfree(bus->phy_map[i]); | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | EXPORT_SYMBOL(mdiobus_unregister); | ||
114 | |||
115 | /* mdio_bus_match | ||
116 | * | ||
117 | * description: Given a PHY device, and a PHY driver, return 1 if | ||
118 | * the driver supports the device. Otherwise, return 0 | ||
119 | */ | ||
120 | static int mdio_bus_match(struct device *dev, struct device_driver *drv) | ||
121 | { | ||
122 | struct phy_device *phydev = to_phy_device(dev); | ||
123 | struct phy_driver *phydrv = to_phy_driver(drv); | ||
124 | |||
125 | return (phydrv->phy_id == (phydev->phy_id & phydrv->phy_id_mask)); | ||
126 | } | ||
127 | |||
128 | /* Suspend and resume. Copied from platform_suspend and | ||
129 | * platform_resume | ||
130 | */ | ||
131 | static int mdio_bus_suspend(struct device * dev, u32 state) | ||
132 | { | ||
133 | int ret = 0; | ||
134 | struct device_driver *drv = dev->driver; | ||
135 | |||
136 | if (drv && drv->suspend) { | ||
137 | ret = drv->suspend(dev, state, SUSPEND_DISABLE); | ||
138 | if (ret == 0) | ||
139 | ret = drv->suspend(dev, state, SUSPEND_SAVE_STATE); | ||
140 | if (ret == 0) | ||
141 | ret = drv->suspend(dev, state, SUSPEND_POWER_DOWN); | ||
142 | } | ||
143 | return ret; | ||
144 | } | ||
145 | |||
146 | static int mdio_bus_resume(struct device * dev) | ||
147 | { | ||
148 | int ret = 0; | ||
149 | struct device_driver *drv = dev->driver; | ||
150 | |||
151 | if (drv && drv->resume) { | ||
152 | ret = drv->resume(dev, RESUME_POWER_ON); | ||
153 | if (ret == 0) | ||
154 | ret = drv->resume(dev, RESUME_RESTORE_STATE); | ||
155 | if (ret == 0) | ||
156 | ret = drv->resume(dev, RESUME_ENABLE); | ||
157 | } | ||
158 | return ret; | ||
159 | } | ||
160 | |||
161 | struct bus_type mdio_bus_type = { | ||
162 | .name = "mdio_bus", | ||
163 | .match = mdio_bus_match, | ||
164 | .suspend = mdio_bus_suspend, | ||
165 | .resume = mdio_bus_resume, | ||
166 | }; | ||
167 | |||
168 | static int __init mdio_bus_init(void) | ||
169 | { | ||
170 | return bus_register(&mdio_bus_type); | ||
171 | } | ||
172 | |||
173 | subsys_initcall(mdio_bus_init); | ||
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c new file mode 100644 index 000000000000..e2c6896b92d2 --- /dev/null +++ b/drivers/net/phy/phy.c | |||
@@ -0,0 +1,862 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/phy.c | ||
3 | * | ||
4 | * Framework for configuring and reading PHY devices | ||
5 | * Based on code in sungem_phy.c and gianfar_phy.c | ||
6 | * | ||
7 | * Author: Andy Fleming | ||
8 | * | ||
9 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the | ||
13 | * Free Software Foundation; either version 2 of the License, or (at your | ||
14 | * option) any later version. | ||
15 | * | ||
16 | */ | ||
17 | #include <linux/config.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/string.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/unistd.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/netdevice.h> | ||
28 | #include <linux/etherdevice.h> | ||
29 | #include <linux/skbuff.h> | ||
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/mm.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/version.h> | ||
34 | #include <linux/mii.h> | ||
35 | #include <linux/ethtool.h> | ||
36 | #include <linux/phy.h> | ||
37 | |||
38 | #include <asm/io.h> | ||
39 | #include <asm/irq.h> | ||
40 | #include <asm/uaccess.h> | ||
41 | |||
42 | static void phy_change(void *data); | ||
43 | static void phy_timer(unsigned long data); | ||
44 | |||
45 | /* Convenience function to print out the current phy status | ||
46 | */ | ||
47 | void phy_print_status(struct phy_device *phydev) | ||
48 | { | ||
49 | pr_info("%s: Link is %s", phydev->dev.bus_id, | ||
50 | phydev->link ? "Up" : "Down"); | ||
51 | if (phydev->link) | ||
52 | printk(" - %d/%s", phydev->speed, | ||
53 | DUPLEX_FULL == phydev->duplex ? | ||
54 | "Full" : "Half"); | ||
55 | |||
56 | printk("\n"); | ||
57 | } | ||
58 | EXPORT_SYMBOL(phy_print_status); | ||
59 | |||
60 | |||
61 | /* Convenience functions for reading/writing a given PHY | ||
62 | * register. They MUST NOT be called from interrupt context, | ||
63 | * because the bus read/write functions may wait for an interrupt | ||
64 | * to conclude the operation. */ | ||
65 | int phy_read(struct phy_device *phydev, u16 regnum) | ||
66 | { | ||
67 | int retval; | ||
68 | struct mii_bus *bus = phydev->bus; | ||
69 | |||
70 | spin_lock_bh(&bus->mdio_lock); | ||
71 | retval = bus->read(bus, phydev->addr, regnum); | ||
72 | spin_unlock_bh(&bus->mdio_lock); | ||
73 | |||
74 | return retval; | ||
75 | } | ||
76 | EXPORT_SYMBOL(phy_read); | ||
77 | |||
78 | int phy_write(struct phy_device *phydev, u16 regnum, u16 val) | ||
79 | { | ||
80 | int err; | ||
81 | struct mii_bus *bus = phydev->bus; | ||
82 | |||
83 | spin_lock_bh(&bus->mdio_lock); | ||
84 | err = bus->write(bus, phydev->addr, regnum, val); | ||
85 | spin_unlock_bh(&bus->mdio_lock); | ||
86 | |||
87 | return err; | ||
88 | } | ||
89 | EXPORT_SYMBOL(phy_write); | ||
90 | |||
91 | |||
92 | int phy_clear_interrupt(struct phy_device *phydev) | ||
93 | { | ||
94 | int err = 0; | ||
95 | |||
96 | if (phydev->drv->ack_interrupt) | ||
97 | err = phydev->drv->ack_interrupt(phydev); | ||
98 | |||
99 | return err; | ||
100 | } | ||
101 | |||
102 | |||
103 | int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) | ||
104 | { | ||
105 | int err = 0; | ||
106 | |||
107 | phydev->interrupts = interrupts; | ||
108 | if (phydev->drv->config_intr) | ||
109 | err = phydev->drv->config_intr(phydev); | ||
110 | |||
111 | return err; | ||
112 | } | ||
113 | |||
114 | |||
115 | /* phy_aneg_done | ||
116 | * | ||
117 | * description: Reads the status register and returns 0 either if | ||
118 | * auto-negotiation is incomplete, or if there was an error. | ||
119 | * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done. | ||
120 | */ | ||
121 | static inline int phy_aneg_done(struct phy_device *phydev) | ||
122 | { | ||
123 | int retval; | ||
124 | |||
125 | retval = phy_read(phydev, MII_BMSR); | ||
126 | |||
127 | return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE); | ||
128 | } | ||
129 | |||
130 | /* phy_start_aneg | ||
131 | * | ||
132 | * description: Calls the PHY driver's config_aneg, and then | ||
133 | * sets the PHY state to PHY_AN if auto-negotiation is enabled, | ||
134 | * and to PHY_FORCING if auto-negotiation is disabled. Unless | ||
135 | * the PHY is currently HALTED. | ||
136 | */ | ||
137 | int phy_start_aneg(struct phy_device *phydev) | ||
138 | { | ||
139 | int err; | ||
140 | |||
141 | spin_lock(&phydev->lock); | ||
142 | |||
143 | if (AUTONEG_DISABLE == phydev->autoneg) | ||
144 | phy_sanitize_settings(phydev); | ||
145 | |||
146 | err = phydev->drv->config_aneg(phydev); | ||
147 | |||
148 | if (err < 0) | ||
149 | goto out_unlock; | ||
150 | |||
151 | if (phydev->state != PHY_HALTED) { | ||
152 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
153 | phydev->state = PHY_AN; | ||
154 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
155 | } else { | ||
156 | phydev->state = PHY_FORCING; | ||
157 | phydev->link_timeout = PHY_FORCE_TIMEOUT; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | out_unlock: | ||
162 | spin_unlock(&phydev->lock); | ||
163 | return err; | ||
164 | } | ||
165 | EXPORT_SYMBOL(phy_start_aneg); | ||
166 | |||
167 | |||
168 | /* A structure for mapping a particular speed and duplex | ||
169 | * combination to a particular SUPPORTED and ADVERTISED value */ | ||
170 | struct phy_setting { | ||
171 | int speed; | ||
172 | int duplex; | ||
173 | u32 setting; | ||
174 | }; | ||
175 | |||
176 | /* A mapping of all SUPPORTED settings to speed/duplex */ | ||
177 | static struct phy_setting settings[] = { | ||
178 | { | ||
179 | .speed = 10000, | ||
180 | .duplex = DUPLEX_FULL, | ||
181 | .setting = SUPPORTED_10000baseT_Full, | ||
182 | }, | ||
183 | { | ||
184 | .speed = SPEED_1000, | ||
185 | .duplex = DUPLEX_FULL, | ||
186 | .setting = SUPPORTED_1000baseT_Full, | ||
187 | }, | ||
188 | { | ||
189 | .speed = SPEED_1000, | ||
190 | .duplex = DUPLEX_HALF, | ||
191 | .setting = SUPPORTED_1000baseT_Half, | ||
192 | }, | ||
193 | { | ||
194 | .speed = SPEED_100, | ||
195 | .duplex = DUPLEX_FULL, | ||
196 | .setting = SUPPORTED_100baseT_Full, | ||
197 | }, | ||
198 | { | ||
199 | .speed = SPEED_100, | ||
200 | .duplex = DUPLEX_HALF, | ||
201 | .setting = SUPPORTED_100baseT_Half, | ||
202 | }, | ||
203 | { | ||
204 | .speed = SPEED_10, | ||
205 | .duplex = DUPLEX_FULL, | ||
206 | .setting = SUPPORTED_10baseT_Full, | ||
207 | }, | ||
208 | { | ||
209 | .speed = SPEED_10, | ||
210 | .duplex = DUPLEX_HALF, | ||
211 | .setting = SUPPORTED_10baseT_Half, | ||
212 | }, | ||
213 | }; | ||
214 | |||
215 | #define MAX_NUM_SETTINGS (sizeof(settings)/sizeof(struct phy_setting)) | ||
216 | |||
217 | /* phy_find_setting | ||
218 | * | ||
219 | * description: Searches the settings array for the setting which | ||
220 | * matches the desired speed and duplex, and returns the index | ||
221 | * of that setting. Returns the index of the last setting if | ||
222 | * none of the others match. | ||
223 | */ | ||
224 | static inline int phy_find_setting(int speed, int duplex) | ||
225 | { | ||
226 | int idx = 0; | ||
227 | |||
228 | while (idx < ARRAY_SIZE(settings) && | ||
229 | (settings[idx].speed != speed || | ||
230 | settings[idx].duplex != duplex)) | ||
231 | idx++; | ||
232 | |||
233 | return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; | ||
234 | } | ||
235 | |||
236 | /* phy_find_valid | ||
237 | * idx: The first index in settings[] to search | ||
238 | * features: A mask of the valid settings | ||
239 | * | ||
240 | * description: Returns the index of the first valid setting less | ||
241 | * than or equal to the one pointed to by idx, as determined by | ||
242 | * the mask in features. Returns the index of the last setting | ||
243 | * if nothing else matches. | ||
244 | */ | ||
245 | static inline int phy_find_valid(int idx, u32 features) | ||
246 | { | ||
247 | while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) | ||
248 | idx++; | ||
249 | |||
250 | return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; | ||
251 | } | ||
252 | |||
253 | /* phy_sanitize_settings | ||
254 | * | ||
255 | * description: Make sure the PHY is set to supported speeds and | ||
256 | * duplexes. Drop down by one in this order: 1000/FULL, | ||
257 | * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF | ||
258 | */ | ||
259 | void phy_sanitize_settings(struct phy_device *phydev) | ||
260 | { | ||
261 | u32 features = phydev->supported; | ||
262 | int idx; | ||
263 | |||
264 | /* Sanitize settings based on PHY capabilities */ | ||
265 | if ((features & SUPPORTED_Autoneg) == 0) | ||
266 | phydev->autoneg = 0; | ||
267 | |||
268 | idx = phy_find_valid(phy_find_setting(phydev->speed, phydev->duplex), | ||
269 | features); | ||
270 | |||
271 | phydev->speed = settings[idx].speed; | ||
272 | phydev->duplex = settings[idx].duplex; | ||
273 | } | ||
274 | EXPORT_SYMBOL(phy_sanitize_settings); | ||
275 | |||
276 | /* phy_force_reduction | ||
277 | * | ||
278 | * description: Reduces the speed/duplex settings by | ||
279 | * one notch. The order is so: | ||
280 | * 1000/FULL, 1000/HALF, 100/FULL, 100/HALF, | ||
281 | * 10/FULL, 10/HALF. The function bottoms out at 10/HALF. | ||
282 | */ | ||
283 | static void phy_force_reduction(struct phy_device *phydev) | ||
284 | { | ||
285 | int idx; | ||
286 | |||
287 | idx = phy_find_setting(phydev->speed, phydev->duplex); | ||
288 | |||
289 | idx++; | ||
290 | |||
291 | idx = phy_find_valid(idx, phydev->supported); | ||
292 | |||
293 | phydev->speed = settings[idx].speed; | ||
294 | phydev->duplex = settings[idx].duplex; | ||
295 | |||
296 | pr_info("Trying %d/%s\n", phydev->speed, | ||
297 | DUPLEX_FULL == phydev->duplex ? | ||
298 | "FULL" : "HALF"); | ||
299 | } | ||
300 | |||
301 | /* phy_ethtool_sset: | ||
302 | * A generic ethtool sset function. Handles all the details | ||
303 | * | ||
304 | * A few notes about parameter checking: | ||
305 | * - We don't set port or transceiver, so we don't care what they | ||
306 | * were set to. | ||
307 | * - phy_start_aneg() will make sure forced settings are sane, and | ||
308 | * choose the next best ones from the ones selected, so we don't | ||
309 | * care if ethtool tries to give us bad values | ||
310 | */ | ||
311 | int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) | ||
312 | { | ||
313 | if (cmd->phy_address != phydev->addr) | ||
314 | return -EINVAL; | ||
315 | |||
316 | /* We make sure that we don't pass unsupported | ||
317 | * values in to the PHY */ | ||
318 | cmd->advertising &= phydev->supported; | ||
319 | |||
320 | /* Verify the settings we care about. */ | ||
321 | if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE) | ||
322 | return -EINVAL; | ||
323 | |||
324 | if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0) | ||
325 | return -EINVAL; | ||
326 | |||
327 | if (cmd->autoneg == AUTONEG_DISABLE | ||
328 | && ((cmd->speed != SPEED_1000 | ||
329 | && cmd->speed != SPEED_100 | ||
330 | && cmd->speed != SPEED_10) | ||
331 | || (cmd->duplex != DUPLEX_HALF | ||
332 | && cmd->duplex != DUPLEX_FULL))) | ||
333 | return -EINVAL; | ||
334 | |||
335 | phydev->autoneg = cmd->autoneg; | ||
336 | |||
337 | phydev->speed = cmd->speed; | ||
338 | |||
339 | phydev->advertising = cmd->advertising; | ||
340 | |||
341 | if (AUTONEG_ENABLE == cmd->autoneg) | ||
342 | phydev->advertising |= ADVERTISED_Autoneg; | ||
343 | else | ||
344 | phydev->advertising &= ~ADVERTISED_Autoneg; | ||
345 | |||
346 | phydev->duplex = cmd->duplex; | ||
347 | |||
348 | /* Restart the PHY */ | ||
349 | phy_start_aneg(phydev); | ||
350 | |||
351 | return 0; | ||
352 | } | ||
353 | |||
354 | int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd) | ||
355 | { | ||
356 | cmd->supported = phydev->supported; | ||
357 | |||
358 | cmd->advertising = phydev->advertising; | ||
359 | |||
360 | cmd->speed = phydev->speed; | ||
361 | cmd->duplex = phydev->duplex; | ||
362 | cmd->port = PORT_MII; | ||
363 | cmd->phy_address = phydev->addr; | ||
364 | cmd->transceiver = XCVR_EXTERNAL; | ||
365 | cmd->autoneg = phydev->autoneg; | ||
366 | |||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | |||
371 | /* Note that this function is currently incompatible with the | ||
372 | * PHYCONTROL layer. It changes registers without regard to | ||
373 | * current state. Use at own risk | ||
374 | */ | ||
375 | int phy_mii_ioctl(struct phy_device *phydev, | ||
376 | struct mii_ioctl_data *mii_data, int cmd) | ||
377 | { | ||
378 | u16 val = mii_data->val_in; | ||
379 | |||
380 | switch (cmd) { | ||
381 | case SIOCGMIIPHY: | ||
382 | mii_data->phy_id = phydev->addr; | ||
383 | break; | ||
384 | case SIOCGMIIREG: | ||
385 | mii_data->val_out = phy_read(phydev, mii_data->reg_num); | ||
386 | break; | ||
387 | |||
388 | case SIOCSMIIREG: | ||
389 | if (!capable(CAP_NET_ADMIN)) | ||
390 | return -EPERM; | ||
391 | |||
392 | if (mii_data->phy_id == phydev->addr) { | ||
393 | switch(mii_data->reg_num) { | ||
394 | case MII_BMCR: | ||
395 | if (val & (BMCR_RESET|BMCR_ANENABLE)) | ||
396 | phydev->autoneg = AUTONEG_DISABLE; | ||
397 | else | ||
398 | phydev->autoneg = AUTONEG_ENABLE; | ||
399 | if ((!phydev->autoneg) && (val & BMCR_FULLDPLX)) | ||
400 | phydev->duplex = DUPLEX_FULL; | ||
401 | else | ||
402 | phydev->duplex = DUPLEX_HALF; | ||
403 | break; | ||
404 | case MII_ADVERTISE: | ||
405 | phydev->advertising = val; | ||
406 | break; | ||
407 | default: | ||
408 | /* do nothing */ | ||
409 | break; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | phy_write(phydev, mii_data->reg_num, val); | ||
414 | |||
415 | if (mii_data->reg_num == MII_BMCR | ||
416 | && val & BMCR_RESET | ||
417 | && phydev->drv->config_init) | ||
418 | phydev->drv->config_init(phydev); | ||
419 | break; | ||
420 | } | ||
421 | |||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | /* phy_start_machine: | ||
426 | * | ||
427 | * description: The PHY infrastructure can run a state machine | ||
428 | * which tracks whether the PHY is starting up, negotiating, | ||
429 | * etc. This function starts the timer which tracks the state | ||
430 | * of the PHY. If you want to be notified when the state | ||
431 | * changes, pass in the callback, otherwise, pass NULL. If you | ||
432 | * want to maintain your own state machine, do not call this | ||
433 | * function. */ | ||
434 | void phy_start_machine(struct phy_device *phydev, | ||
435 | void (*handler)(struct net_device *)) | ||
436 | { | ||
437 | phydev->adjust_state = handler; | ||
438 | |||
439 | init_timer(&phydev->phy_timer); | ||
440 | phydev->phy_timer.function = &phy_timer; | ||
441 | phydev->phy_timer.data = (unsigned long) phydev; | ||
442 | mod_timer(&phydev->phy_timer, jiffies + HZ); | ||
443 | } | ||
444 | |||
445 | /* phy_stop_machine | ||
446 | * | ||
447 | * description: Stops the state machine timer, sets the state to | ||
448 | * UP (unless it wasn't up yet), and then frees the interrupt, | ||
449 | * if it is in use. This function must be called BEFORE | ||
450 | * phy_detach. | ||
451 | */ | ||
452 | void phy_stop_machine(struct phy_device *phydev) | ||
453 | { | ||
454 | del_timer_sync(&phydev->phy_timer); | ||
455 | |||
456 | spin_lock(&phydev->lock); | ||
457 | if (phydev->state > PHY_UP) | ||
458 | phydev->state = PHY_UP; | ||
459 | spin_unlock(&phydev->lock); | ||
460 | |||
461 | if (phydev->irq != PHY_POLL) | ||
462 | phy_stop_interrupts(phydev); | ||
463 | |||
464 | phydev->adjust_state = NULL; | ||
465 | } | ||
466 | |||
467 | #ifdef CONFIG_PHYCONTROL | ||
468 | /* phy_error: | ||
469 | * | ||
470 | * Moves the PHY to the HALTED state in response to a read | ||
471 | * or write error, and tells the controller the link is down. | ||
472 | * Must not be called from interrupt context, or while the | ||
473 | * phydev->lock is held. | ||
474 | */ | ||
475 | void phy_error(struct phy_device *phydev) | ||
476 | { | ||
477 | spin_lock(&phydev->lock); | ||
478 | phydev->state = PHY_HALTED; | ||
479 | spin_unlock(&phydev->lock); | ||
480 | } | ||
481 | |||
482 | /* phy_interrupt | ||
483 | * | ||
484 | * description: When a PHY interrupt occurs, the handler disables | ||
485 | * interrupts, and schedules a work task to clear the interrupt. | ||
486 | */ | ||
487 | static irqreturn_t phy_interrupt(int irq, void *phy_dat, struct pt_regs *regs) | ||
488 | { | ||
489 | struct phy_device *phydev = phy_dat; | ||
490 | |||
491 | /* The MDIO bus is not allowed to be written in interrupt | ||
492 | * context, so we need to disable the irq here. A work | ||
493 | * queue will write the PHY to disable and clear the | ||
494 | * interrupt, and then reenable the irq line. */ | ||
495 | disable_irq_nosync(irq); | ||
496 | |||
497 | schedule_work(&phydev->phy_queue); | ||
498 | |||
499 | return IRQ_HANDLED; | ||
500 | } | ||
501 | |||
502 | /* Enable the interrupts from the PHY side */ | ||
503 | int phy_enable_interrupts(struct phy_device *phydev) | ||
504 | { | ||
505 | int err; | ||
506 | |||
507 | err = phy_clear_interrupt(phydev); | ||
508 | |||
509 | if (err < 0) | ||
510 | return err; | ||
511 | |||
512 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | ||
513 | |||
514 | return err; | ||
515 | } | ||
516 | EXPORT_SYMBOL(phy_enable_interrupts); | ||
517 | |||
518 | /* Disable the PHY interrupts from the PHY side */ | ||
519 | int phy_disable_interrupts(struct phy_device *phydev) | ||
520 | { | ||
521 | int err; | ||
522 | |||
523 | /* Disable PHY interrupts */ | ||
524 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); | ||
525 | |||
526 | if (err) | ||
527 | goto phy_err; | ||
528 | |||
529 | /* Clear the interrupt */ | ||
530 | err = phy_clear_interrupt(phydev); | ||
531 | |||
532 | if (err) | ||
533 | goto phy_err; | ||
534 | |||
535 | return 0; | ||
536 | |||
537 | phy_err: | ||
538 | phy_error(phydev); | ||
539 | |||
540 | return err; | ||
541 | } | ||
542 | EXPORT_SYMBOL(phy_disable_interrupts); | ||
543 | |||
544 | /* phy_start_interrupts | ||
545 | * | ||
546 | * description: Request the interrupt for the given PHY. If | ||
547 | * this fails, then we set irq to PHY_POLL. | ||
548 | * Otherwise, we enable the interrupts in the PHY. | ||
549 | * Returns 0 on success. | ||
550 | * This should only be called with a valid IRQ number. | ||
551 | */ | ||
552 | int phy_start_interrupts(struct phy_device *phydev) | ||
553 | { | ||
554 | int err = 0; | ||
555 | |||
556 | INIT_WORK(&phydev->phy_queue, phy_change, phydev); | ||
557 | |||
558 | if (request_irq(phydev->irq, phy_interrupt, | ||
559 | SA_SHIRQ, | ||
560 | "phy_interrupt", | ||
561 | phydev) < 0) { | ||
562 | printk(KERN_WARNING "%s: Can't get IRQ %d (PHY)\n", | ||
563 | phydev->bus->name, | ||
564 | phydev->irq); | ||
565 | phydev->irq = PHY_POLL; | ||
566 | return 0; | ||
567 | } | ||
568 | |||
569 | err = phy_enable_interrupts(phydev); | ||
570 | |||
571 | return err; | ||
572 | } | ||
573 | EXPORT_SYMBOL(phy_start_interrupts); | ||
574 | |||
575 | int phy_stop_interrupts(struct phy_device *phydev) | ||
576 | { | ||
577 | int err; | ||
578 | |||
579 | err = phy_disable_interrupts(phydev); | ||
580 | |||
581 | if (err) | ||
582 | phy_error(phydev); | ||
583 | |||
584 | free_irq(phydev->irq, phydev); | ||
585 | |||
586 | return err; | ||
587 | } | ||
588 | EXPORT_SYMBOL(phy_stop_interrupts); | ||
589 | |||
590 | |||
591 | /* Scheduled by the phy_interrupt/timer to handle PHY changes */ | ||
592 | static void phy_change(void *data) | ||
593 | { | ||
594 | int err; | ||
595 | struct phy_device *phydev = data; | ||
596 | |||
597 | err = phy_disable_interrupts(phydev); | ||
598 | |||
599 | if (err) | ||
600 | goto phy_err; | ||
601 | |||
602 | spin_lock(&phydev->lock); | ||
603 | if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state)) | ||
604 | phydev->state = PHY_CHANGELINK; | ||
605 | spin_unlock(&phydev->lock); | ||
606 | |||
607 | enable_irq(phydev->irq); | ||
608 | |||
609 | /* Reenable interrupts */ | ||
610 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | ||
611 | |||
612 | if (err) | ||
613 | goto irq_enable_err; | ||
614 | |||
615 | return; | ||
616 | |||
617 | irq_enable_err: | ||
618 | disable_irq(phydev->irq); | ||
619 | phy_err: | ||
620 | phy_error(phydev); | ||
621 | } | ||
622 | |||
623 | /* Bring down the PHY link, and stop checking the status. */ | ||
624 | void phy_stop(struct phy_device *phydev) | ||
625 | { | ||
626 | spin_lock(&phydev->lock); | ||
627 | |||
628 | if (PHY_HALTED == phydev->state) | ||
629 | goto out_unlock; | ||
630 | |||
631 | if (phydev->irq != PHY_POLL) { | ||
632 | /* Clear any pending interrupts */ | ||
633 | phy_clear_interrupt(phydev); | ||
634 | |||
635 | /* Disable PHY Interrupts */ | ||
636 | phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); | ||
637 | } | ||
638 | |||
639 | phydev->state = PHY_HALTED; | ||
640 | |||
641 | out_unlock: | ||
642 | spin_unlock(&phydev->lock); | ||
643 | } | ||
644 | |||
645 | |||
646 | /* phy_start | ||
647 | * | ||
648 | * description: Indicates the attached device's readiness to | ||
649 | * handle PHY-related work. Used during startup to start the | ||
650 | * PHY, and after a call to phy_stop() to resume operation. | ||
651 | * Also used to indicate the MDIO bus has cleared an error | ||
652 | * condition. | ||
653 | */ | ||
654 | void phy_start(struct phy_device *phydev) | ||
655 | { | ||
656 | spin_lock(&phydev->lock); | ||
657 | |||
658 | switch (phydev->state) { | ||
659 | case PHY_STARTING: | ||
660 | phydev->state = PHY_PENDING; | ||
661 | break; | ||
662 | case PHY_READY: | ||
663 | phydev->state = PHY_UP; | ||
664 | break; | ||
665 | case PHY_HALTED: | ||
666 | phydev->state = PHY_RESUMING; | ||
667 | default: | ||
668 | break; | ||
669 | } | ||
670 | spin_unlock(&phydev->lock); | ||
671 | } | ||
672 | EXPORT_SYMBOL(phy_stop); | ||
673 | EXPORT_SYMBOL(phy_start); | ||
674 | |||
675 | /* PHY timer which handles the state machine */ | ||
676 | static void phy_timer(unsigned long data) | ||
677 | { | ||
678 | struct phy_device *phydev = (struct phy_device *)data; | ||
679 | int needs_aneg = 0; | ||
680 | int err = 0; | ||
681 | |||
682 | spin_lock(&phydev->lock); | ||
683 | |||
684 | if (phydev->adjust_state) | ||
685 | phydev->adjust_state(phydev->attached_dev); | ||
686 | |||
687 | switch(phydev->state) { | ||
688 | case PHY_DOWN: | ||
689 | case PHY_STARTING: | ||
690 | case PHY_READY: | ||
691 | case PHY_PENDING: | ||
692 | break; | ||
693 | case PHY_UP: | ||
694 | needs_aneg = 1; | ||
695 | |||
696 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
697 | |||
698 | break; | ||
699 | case PHY_AN: | ||
700 | /* Check if negotiation is done. Break | ||
701 | * if there's an error */ | ||
702 | err = phy_aneg_done(phydev); | ||
703 | if (err < 0) | ||
704 | break; | ||
705 | |||
706 | /* If auto-negotiation is done, we change to | ||
707 | * either RUNNING, or NOLINK */ | ||
708 | if (err > 0) { | ||
709 | err = phy_read_status(phydev); | ||
710 | |||
711 | if (err) | ||
712 | break; | ||
713 | |||
714 | if (phydev->link) { | ||
715 | phydev->state = PHY_RUNNING; | ||
716 | netif_carrier_on(phydev->attached_dev); | ||
717 | } else { | ||
718 | phydev->state = PHY_NOLINK; | ||
719 | netif_carrier_off(phydev->attached_dev); | ||
720 | } | ||
721 | |||
722 | phydev->adjust_link(phydev->attached_dev); | ||
723 | |||
724 | } else if (0 == phydev->link_timeout--) { | ||
725 | /* The counter expired, so either we | ||
726 | * switch to forced mode, or the | ||
727 | * magic_aneg bit exists, and we try aneg | ||
728 | * again */ | ||
729 | if (!(phydev->drv->flags & PHY_HAS_MAGICANEG)) { | ||
730 | int idx; | ||
731 | |||
732 | /* We'll start from the | ||
733 | * fastest speed, and work | ||
734 | * our way down */ | ||
735 | idx = phy_find_valid(0, | ||
736 | phydev->supported); | ||
737 | |||
738 | phydev->speed = settings[idx].speed; | ||
739 | phydev->duplex = settings[idx].duplex; | ||
740 | |||
741 | phydev->autoneg = AUTONEG_DISABLE; | ||
742 | phydev->state = PHY_FORCING; | ||
743 | phydev->link_timeout = | ||
744 | PHY_FORCE_TIMEOUT; | ||
745 | |||
746 | pr_info("Trying %d/%s\n", | ||
747 | phydev->speed, | ||
748 | DUPLEX_FULL == | ||
749 | phydev->duplex ? | ||
750 | "FULL" : "HALF"); | ||
751 | } | ||
752 | |||
753 | needs_aneg = 1; | ||
754 | } | ||
755 | break; | ||
756 | case PHY_NOLINK: | ||
757 | err = phy_read_status(phydev); | ||
758 | |||
759 | if (err) | ||
760 | break; | ||
761 | |||
762 | if (phydev->link) { | ||
763 | phydev->state = PHY_RUNNING; | ||
764 | netif_carrier_on(phydev->attached_dev); | ||
765 | phydev->adjust_link(phydev->attached_dev); | ||
766 | } | ||
767 | break; | ||
768 | case PHY_FORCING: | ||
769 | err = phy_read_status(phydev); | ||
770 | |||
771 | if (err) | ||
772 | break; | ||
773 | |||
774 | if (phydev->link) { | ||
775 | phydev->state = PHY_RUNNING; | ||
776 | netif_carrier_on(phydev->attached_dev); | ||
777 | } else { | ||
778 | if (0 == phydev->link_timeout--) { | ||
779 | phy_force_reduction(phydev); | ||
780 | needs_aneg = 1; | ||
781 | } | ||
782 | } | ||
783 | |||
784 | phydev->adjust_link(phydev->attached_dev); | ||
785 | break; | ||
786 | case PHY_RUNNING: | ||
787 | /* Only register a CHANGE if we are | ||
788 | * polling */ | ||
789 | if (PHY_POLL == phydev->irq) | ||
790 | phydev->state = PHY_CHANGELINK; | ||
791 | break; | ||
792 | case PHY_CHANGELINK: | ||
793 | err = phy_read_status(phydev); | ||
794 | |||
795 | if (err) | ||
796 | break; | ||
797 | |||
798 | if (phydev->link) { | ||
799 | phydev->state = PHY_RUNNING; | ||
800 | netif_carrier_on(phydev->attached_dev); | ||
801 | } else { | ||
802 | phydev->state = PHY_NOLINK; | ||
803 | netif_carrier_off(phydev->attached_dev); | ||
804 | } | ||
805 | |||
806 | phydev->adjust_link(phydev->attached_dev); | ||
807 | |||
808 | if (PHY_POLL != phydev->irq) | ||
809 | err = phy_config_interrupt(phydev, | ||
810 | PHY_INTERRUPT_ENABLED); | ||
811 | break; | ||
812 | case PHY_HALTED: | ||
813 | if (phydev->link) { | ||
814 | phydev->link = 0; | ||
815 | netif_carrier_off(phydev->attached_dev); | ||
816 | phydev->adjust_link(phydev->attached_dev); | ||
817 | } | ||
818 | break; | ||
819 | case PHY_RESUMING: | ||
820 | |||
821 | err = phy_clear_interrupt(phydev); | ||
822 | |||
823 | if (err) | ||
824 | break; | ||
825 | |||
826 | err = phy_config_interrupt(phydev, | ||
827 | PHY_INTERRUPT_ENABLED); | ||
828 | |||
829 | if (err) | ||
830 | break; | ||
831 | |||
832 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
833 | err = phy_aneg_done(phydev); | ||
834 | if (err < 0) | ||
835 | break; | ||
836 | |||
837 | /* err > 0 if AN is done. | ||
838 | * Otherwise, it's 0, and we're | ||
839 | * still waiting for AN */ | ||
840 | if (err > 0) { | ||
841 | phydev->state = PHY_RUNNING; | ||
842 | } else { | ||
843 | phydev->state = PHY_AN; | ||
844 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
845 | } | ||
846 | } else | ||
847 | phydev->state = PHY_RUNNING; | ||
848 | break; | ||
849 | } | ||
850 | |||
851 | spin_unlock(&phydev->lock); | ||
852 | |||
853 | if (needs_aneg) | ||
854 | err = phy_start_aneg(phydev); | ||
855 | |||
856 | if (err < 0) | ||
857 | phy_error(phydev); | ||
858 | |||
859 | mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ); | ||
860 | } | ||
861 | |||
862 | #endif /* CONFIG_PHYCONTROL */ | ||
diff --git a/drivers/net/phy/phy.c.orig b/drivers/net/phy/phy.c.orig new file mode 100644 index 000000000000..6af17cec9ace --- /dev/null +++ b/drivers/net/phy/phy.c.orig | |||
@@ -0,0 +1,860 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/phy.c | ||
3 | * | ||
4 | * Framework for configuring and reading PHY devices | ||
5 | * Based on code in sungem_phy.c and gianfar_phy.c | ||
6 | * | ||
7 | * Author: Andy Fleming | ||
8 | * | ||
9 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the | ||
13 | * Free Software Foundation; either version 2 of the License, or (at your | ||
14 | * option) any later version. | ||
15 | * | ||
16 | */ | ||
17 | #include <linux/config.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/string.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/unistd.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/netdevice.h> | ||
28 | #include <linux/etherdevice.h> | ||
29 | #include <linux/skbuff.h> | ||
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/mm.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/version.h> | ||
34 | #include <linux/mii.h> | ||
35 | #include <linux/ethtool.h> | ||
36 | #include <linux/phy.h> | ||
37 | |||
38 | #include <asm/io.h> | ||
39 | #include <asm/irq.h> | ||
40 | #include <asm/uaccess.h> | ||
41 | |||
42 | static void phy_change(void *data); | ||
43 | static void phy_timer(unsigned long data); | ||
44 | |||
45 | /* Convenience function to print out the current phy status | ||
46 | */ | ||
47 | void phy_print_status(struct phy_device *phydev) | ||
48 | { | ||
49 | pr_info("%s: Link is %s", phydev->dev.bus_id, | ||
50 | phydev->link ? "Up" : "Down"); | ||
51 | if (phydev->link) | ||
52 | printk(" - %d/%s", phydev->speed, | ||
53 | DUPLEX_FULL == phydev->duplex ? | ||
54 | "Full" : "Half"); | ||
55 | |||
56 | printk("\n"); | ||
57 | } | ||
58 | EXPORT_SYMBOL(phy_print_status); | ||
59 | |||
60 | |||
61 | /* Convenience functions for reading/writing a given PHY | ||
62 | * register. They MUST NOT be called from interrupt context, | ||
63 | * because the bus read/write functions may wait for an interrupt | ||
64 | * to conclude the operation. */ | ||
65 | int phy_read(struct phy_device *phydev, u16 regnum) | ||
66 | { | ||
67 | int retval; | ||
68 | struct mii_bus *bus = phydev->bus; | ||
69 | |||
70 | spin_lock_bh(&bus->mdio_lock); | ||
71 | retval = bus->read(bus, phydev->addr, regnum); | ||
72 | spin_unlock_bh(&bus->mdio_lock); | ||
73 | |||
74 | return retval; | ||
75 | } | ||
76 | EXPORT_SYMBOL(phy_read); | ||
77 | |||
78 | int phy_write(struct phy_device *phydev, u16 regnum, u16 val) | ||
79 | { | ||
80 | int err; | ||
81 | struct mii_bus *bus = phydev->bus; | ||
82 | |||
83 | spin_lock_bh(&bus->mdio_lock); | ||
84 | err = bus->write(bus, phydev->addr, regnum, val); | ||
85 | spin_unlock_bh(&bus->mdio_lock); | ||
86 | |||
87 | return err; | ||
88 | } | ||
89 | EXPORT_SYMBOL(phy_write); | ||
90 | |||
91 | |||
92 | int phy_clear_interrupt(struct phy_device *phydev) | ||
93 | { | ||
94 | int err = 0; | ||
95 | |||
96 | if (phydev->drv->ack_interrupt) | ||
97 | err = phydev->drv->ack_interrupt(phydev); | ||
98 | |||
99 | return err; | ||
100 | } | ||
101 | |||
102 | |||
103 | int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) | ||
104 | { | ||
105 | int err = 0; | ||
106 | |||
107 | phydev->interrupts = interrupts; | ||
108 | if (phydev->drv->config_intr) | ||
109 | err = phydev->drv->config_intr(phydev); | ||
110 | |||
111 | return err; | ||
112 | } | ||
113 | |||
114 | |||
115 | /* phy_aneg_done | ||
116 | * | ||
117 | * description: Reads the status register and returns 0 either if | ||
118 | * auto-negotiation is incomplete, or if there was an error. | ||
119 | * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done. | ||
120 | */ | ||
121 | static inline int phy_aneg_done(struct phy_device *phydev) | ||
122 | { | ||
123 | int retval; | ||
124 | |||
125 | retval = phy_read(phydev, MII_BMSR); | ||
126 | |||
127 | return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE); | ||
128 | } | ||
129 | |||
130 | /* phy_start_aneg | ||
131 | * | ||
132 | * description: Calls the PHY driver's config_aneg, and then | ||
133 | * sets the PHY state to PHY_AN if auto-negotiation is enabled, | ||
134 | * and to PHY_FORCING if auto-negotiation is disabled. Unless | ||
135 | * the PHY is currently HALTED. | ||
136 | */ | ||
137 | int phy_start_aneg(struct phy_device *phydev) | ||
138 | { | ||
139 | int err; | ||
140 | |||
141 | spin_lock(&phydev->lock); | ||
142 | |||
143 | if (AUTONEG_DISABLE == phydev->autoneg) | ||
144 | phy_sanitize_settings(phydev); | ||
145 | |||
146 | err = phydev->drv->config_aneg(phydev); | ||
147 | |||
148 | if (err < 0) | ||
149 | goto out_unlock; | ||
150 | |||
151 | if (phydev->state != PHY_HALTED) { | ||
152 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
153 | phydev->state = PHY_AN; | ||
154 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
155 | } else { | ||
156 | phydev->state = PHY_FORCING; | ||
157 | phydev->link_timeout = PHY_FORCE_TIMEOUT; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | out_unlock: | ||
162 | spin_unlock(&phydev->lock); | ||
163 | return err; | ||
164 | } | ||
165 | EXPORT_SYMBOL(phy_start_aneg); | ||
166 | |||
167 | |||
168 | /* A structure for mapping a particular speed and duplex | ||
169 | * combination to a particular SUPPORTED and ADVERTISED value */ | ||
170 | struct phy_setting { | ||
171 | int speed; | ||
172 | int duplex; | ||
173 | u32 setting; | ||
174 | }; | ||
175 | |||
176 | /* A mapping of all SUPPORTED settings to speed/duplex */ | ||
177 | static struct phy_setting settings[] = { | ||
178 | { | ||
179 | .speed = 10000, | ||
180 | .duplex = DUPLEX_FULL, | ||
181 | .setting = SUPPORTED_10000baseT_Full, | ||
182 | }, | ||
183 | { | ||
184 | .speed = SPEED_1000, | ||
185 | .duplex = DUPLEX_FULL, | ||
186 | .setting = SUPPORTED_1000baseT_Full, | ||
187 | }, | ||
188 | { | ||
189 | .speed = SPEED_1000, | ||
190 | .duplex = DUPLEX_HALF, | ||
191 | .setting = SUPPORTED_1000baseT_Half, | ||
192 | }, | ||
193 | { | ||
194 | .speed = SPEED_100, | ||
195 | .duplex = DUPLEX_FULL, | ||
196 | .setting = SUPPORTED_100baseT_Full, | ||
197 | }, | ||
198 | { | ||
199 | .speed = SPEED_100, | ||
200 | .duplex = DUPLEX_HALF, | ||
201 | .setting = SUPPORTED_100baseT_Half, | ||
202 | }, | ||
203 | { | ||
204 | .speed = SPEED_10, | ||
205 | .duplex = DUPLEX_FULL, | ||
206 | .setting = SUPPORTED_10baseT_Full, | ||
207 | }, | ||
208 | { | ||
209 | .speed = SPEED_10, | ||
210 | .duplex = DUPLEX_HALF, | ||
211 | .setting = SUPPORTED_10baseT_Half, | ||
212 | }, | ||
213 | }; | ||
214 | |||
215 | #define MAX_NUM_SETTINGS (sizeof(settings)/sizeof(struct phy_setting)) | ||
216 | |||
217 | /* phy_find_setting | ||
218 | * | ||
219 | * description: Searches the settings array for the setting which | ||
220 | * matches the desired speed and duplex, and returns the index | ||
221 | * of that setting. Returns the index of the last setting if | ||
222 | * none of the others match. | ||
223 | */ | ||
224 | static inline int phy_find_setting(int speed, int duplex) | ||
225 | { | ||
226 | int idx = 0; | ||
227 | |||
228 | while (idx < ARRAY_SIZE(settings) && | ||
229 | (settings[idx].speed != speed || | ||
230 | settings[idx].duplex != duplex)) | ||
231 | idx++; | ||
232 | |||
233 | return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; | ||
234 | } | ||
235 | |||
236 | /* phy_find_valid | ||
237 | * idx: The first index in settings[] to search | ||
238 | * features: A mask of the valid settings | ||
239 | * | ||
240 | * description: Returns the index of the first valid setting less | ||
241 | * than or equal to the one pointed to by idx, as determined by | ||
242 | * the mask in features. Returns the index of the last setting | ||
243 | * if nothing else matches. | ||
244 | */ | ||
245 | static inline int phy_find_valid(int idx, u32 features) | ||
246 | { | ||
247 | while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) | ||
248 | idx++; | ||
249 | |||
250 | return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; | ||
251 | } | ||
252 | |||
253 | /* phy_sanitize_settings | ||
254 | * | ||
255 | * description: Make sure the PHY is set to supported speeds and | ||
256 | * duplexes. Drop down by one in this order: 1000/FULL, | ||
257 | * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF | ||
258 | */ | ||
259 | void phy_sanitize_settings(struct phy_device *phydev) | ||
260 | { | ||
261 | u32 features = phydev->supported; | ||
262 | int idx; | ||
263 | |||
264 | /* Sanitize settings based on PHY capabilities */ | ||
265 | if ((features & SUPPORTED_Autoneg) == 0) | ||
266 | phydev->autoneg = 0; | ||
267 | |||
268 | idx = phy_find_valid(phy_find_setting(phydev->speed, phydev->duplex), | ||
269 | features); | ||
270 | |||
271 | phydev->speed = settings[idx].speed; | ||
272 | phydev->duplex = settings[idx].duplex; | ||
273 | } | ||
274 | EXPORT_SYMBOL(phy_sanitize_settings); | ||
275 | |||
276 | /* phy_force_reduction | ||
277 | * | ||
278 | * description: Reduces the speed/duplex settings by | ||
279 | * one notch. The order is so: | ||
280 | * 1000/FULL, 1000/HALF, 100/FULL, 100/HALF, | ||
281 | * 10/FULL, 10/HALF. The function bottoms out at 10/HALF. | ||
282 | */ | ||
283 | static void phy_force_reduction(struct phy_device *phydev) | ||
284 | { | ||
285 | int idx; | ||
286 | |||
287 | idx = phy_find_setting(phydev->speed, phydev->duplex); | ||
288 | |||
289 | idx++; | ||
290 | |||
291 | idx = phy_find_valid(idx, phydev->supported); | ||
292 | |||
293 | phydev->speed = settings[idx].speed; | ||
294 | phydev->duplex = settings[idx].duplex; | ||
295 | |||
296 | pr_info("Trying %d/%s\n", phydev->speed, | ||
297 | DUPLEX_FULL == phydev->duplex ? | ||
298 | "FULL" : "HALF"); | ||
299 | } | ||
300 | |||
301 | /* phy_ethtool_sset: | ||
302 | * A generic ethtool sset function. Handles all the details | ||
303 | * | ||
304 | * A few notes about parameter checking: | ||
305 | * - We don't set port or transceiver, so we don't care what they | ||
306 | * were set to. | ||
307 | * - phy_start_aneg() will make sure forced settings are sane, and | ||
308 | * choose the next best ones from the ones selected, so we don't | ||
309 | * care if ethtool tries to give us bad values | ||
310 | */ | ||
311 | int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) | ||
312 | { | ||
313 | if (cmd->phy_address != phydev->addr) | ||
314 | return -EINVAL; | ||
315 | |||
316 | /* We make sure that we don't pass unsupported | ||
317 | * values in to the PHY */ | ||
318 | cmd->advertising &= phydev->supported; | ||
319 | |||
320 | /* Verify the settings we care about. */ | ||
321 | if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE) | ||
322 | return -EINVAL; | ||
323 | |||
324 | if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0) | ||
325 | return -EINVAL; | ||
326 | |||
327 | if (cmd->autoneg == AUTONEG_DISABLE | ||
328 | && ((cmd->speed != SPEED_1000 | ||
329 | && cmd->speed != SPEED_100 | ||
330 | && cmd->speed != SPEED_10) | ||
331 | || (cmd->duplex != DUPLEX_HALF | ||
332 | && cmd->duplex != DUPLEX_FULL))) | ||
333 | return -EINVAL; | ||
334 | |||
335 | phydev->autoneg = cmd->autoneg; | ||
336 | |||
337 | phydev->speed = cmd->speed; | ||
338 | |||
339 | phydev->advertising = cmd->advertising; | ||
340 | |||
341 | if (AUTONEG_ENABLE == cmd->autoneg) | ||
342 | phydev->advertising |= ADVERTISED_Autoneg; | ||
343 | else | ||
344 | phydev->advertising &= ~ADVERTISED_Autoneg; | ||
345 | |||
346 | phydev->duplex = cmd->duplex; | ||
347 | |||
348 | /* Restart the PHY */ | ||
349 | phy_start_aneg(phydev); | ||
350 | |||
351 | return 0; | ||
352 | } | ||
353 | |||
354 | int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd) | ||
355 | { | ||
356 | cmd->supported = phydev->supported; | ||
357 | |||
358 | cmd->advertising = phydev->advertising; | ||
359 | |||
360 | cmd->speed = phydev->speed; | ||
361 | cmd->duplex = phydev->duplex; | ||
362 | cmd->port = PORT_MII; | ||
363 | cmd->phy_address = phydev->addr; | ||
364 | cmd->transceiver = XCVR_EXTERNAL; | ||
365 | cmd->autoneg = phydev->autoneg; | ||
366 | |||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | |||
371 | /* Note that this function is currently incompatible with the | ||
372 | * PHYCONTROL layer. It changes registers without regard to | ||
373 | * current state. Use at own risk | ||
374 | */ | ||
375 | int phy_mii_ioctl(struct phy_device *phydev, | ||
376 | struct mii_ioctl_data *mii_data, int cmd) | ||
377 | { | ||
378 | u16 val = mii_data->val_in; | ||
379 | |||
380 | switch (cmd) { | ||
381 | case SIOCGMIIPHY: | ||
382 | mii_data->phy_id = phydev->addr; | ||
383 | break; | ||
384 | case SIOCGMIIREG: | ||
385 | mii_data->val_out = phy_read(phydev, mii_data->reg_num); | ||
386 | break; | ||
387 | |||
388 | case SIOCSMIIREG: | ||
389 | if (!capable(CAP_NET_ADMIN)) | ||
390 | return -EPERM; | ||
391 | |||
392 | if (mii_data->phy_id == phydev->addr) { | ||
393 | switch(mii_data->reg_num) { | ||
394 | case MII_BMCR: | ||
395 | if (val & (BMCR_RESET|BMCR_ANENABLE)) | ||
396 | phydev->autoneg = AUTONEG_DISABLE; | ||
397 | else | ||
398 | phydev->autoneg = AUTONEG_ENABLE; | ||
399 | if ((!phydev->autoneg) && (val & BMCR_FULLDPLX)) | ||
400 | phydev->duplex = DUPLEX_FULL; | ||
401 | else | ||
402 | phydev->duplex = DUPLEX_HALF; | ||
403 | break; | ||
404 | case MII_ADVERTISE: | ||
405 | phydev->advertising = val; | ||
406 | break; | ||
407 | default: | ||
408 | /* do nothing */ | ||
409 | break; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | phy_write(phydev, mii_data->reg_num, val); | ||
414 | |||
415 | if (mii_data->reg_num == MII_BMCR | ||
416 | && val & BMCR_RESET | ||
417 | && phydev->drv->config_init) | ||
418 | phydev->drv->config_init(phydev); | ||
419 | break; | ||
420 | } | ||
421 | |||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | /* phy_start_machine: | ||
426 | * | ||
427 | * description: The PHY infrastructure can run a state machine | ||
428 | * which tracks whether the PHY is starting up, negotiating, | ||
429 | * etc. This function starts the timer which tracks the state | ||
430 | * of the PHY. If you want to be notified when the state | ||
431 | * changes, pass in the callback, otherwise, pass NULL. If you | ||
432 | * want to maintain your own state machine, do not call this | ||
433 | * function. */ | ||
434 | void phy_start_machine(struct phy_device *phydev, | ||
435 | void (*handler)(struct net_device *)) | ||
436 | { | ||
437 | phydev->adjust_state = handler; | ||
438 | |||
439 | init_timer(&phydev->phy_timer); | ||
440 | phydev->phy_timer.function = &phy_timer; | ||
441 | phydev->phy_timer.data = (unsigned long) phydev; | ||
442 | mod_timer(&phydev->phy_timer, jiffies + HZ); | ||
443 | } | ||
444 | |||
445 | /* phy_stop_machine | ||
446 | * | ||
447 | * description: Stops the state machine timer, sets the state to | ||
448 | * UP (unless it wasn't up yet), and then frees the interrupt, | ||
449 | * if it is in use. This function must be called BEFORE | ||
450 | * phy_detach. | ||
451 | */ | ||
452 | void phy_stop_machine(struct phy_device *phydev) | ||
453 | { | ||
454 | del_timer_sync(&phydev->phy_timer); | ||
455 | |||
456 | spin_lock(&phydev->lock); | ||
457 | if (phydev->state > PHY_UP) | ||
458 | phydev->state = PHY_UP; | ||
459 | spin_unlock(&phydev->lock); | ||
460 | |||
461 | if (phydev->irq != PHY_POLL) | ||
462 | phy_stop_interrupts(phydev); | ||
463 | |||
464 | phydev->adjust_state = NULL; | ||
465 | } | ||
466 | |||
467 | #ifdef CONFIG_PHYCONTROL | ||
468 | /* phy_error: | ||
469 | * | ||
470 | * Moves the PHY to the HALTED state in response to a read | ||
471 | * or write error, and tells the controller the link is down. | ||
472 | * Must not be called from interrupt context, or while the | ||
473 | * phydev->lock is held. | ||
474 | */ | ||
475 | void phy_error(struct phy_device *phydev) | ||
476 | { | ||
477 | spin_lock(&phydev->lock); | ||
478 | phydev->state = PHY_HALTED; | ||
479 | spin_unlock(&phydev->lock); | ||
480 | } | ||
481 | |||
482 | /* phy_interrupt | ||
483 | * | ||
484 | * description: When a PHY interrupt occurs, the handler disables | ||
485 | * interrupts, and schedules a work task to clear the interrupt. | ||
486 | */ | ||
487 | static irqreturn_t phy_interrupt(int irq, void *phy_dat, struct pt_regs *regs) | ||
488 | { | ||
489 | struct phy_device *phydev = phy_dat; | ||
490 | |||
491 | /* The MDIO bus is not allowed to be written in interrupt | ||
492 | * context, so we need to disable the irq here. A work | ||
493 | * queue will write the PHY to disable and clear the | ||
494 | * interrupt, and then reenable the irq line. */ | ||
495 | disable_irq_nosync(irq); | ||
496 | |||
497 | schedule_work(&phydev->phy_queue); | ||
498 | |||
499 | return IRQ_HANDLED; | ||
500 | } | ||
501 | |||
502 | /* Enable the interrupts from the PHY side */ | ||
503 | int phy_enable_interrupts(struct phy_device *phydev) | ||
504 | { | ||
505 | int err; | ||
506 | |||
507 | err = phy_clear_interrupt(phydev); | ||
508 | |||
509 | if (err < 0) | ||
510 | return err; | ||
511 | |||
512 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | ||
513 | |||
514 | return err; | ||
515 | } | ||
516 | |||
517 | /* Disable the PHY interrupts from the PHY side */ | ||
518 | int phy_disable_interrupts(struct phy_device *phydev) | ||
519 | { | ||
520 | int err; | ||
521 | |||
522 | /* Disable PHY interrupts */ | ||
523 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); | ||
524 | |||
525 | if (err) | ||
526 | goto phy_err; | ||
527 | |||
528 | /* Clear the interrupt */ | ||
529 | err = phy_clear_interrupt(phydev); | ||
530 | |||
531 | if (err) | ||
532 | goto phy_err; | ||
533 | |||
534 | return 0; | ||
535 | |||
536 | phy_err: | ||
537 | phy_error(phydev); | ||
538 | |||
539 | return err; | ||
540 | } | ||
541 | |||
542 | /* phy_start_interrupts | ||
543 | * | ||
544 | * description: Request the interrupt for the given PHY. If | ||
545 | * this fails, then we set irq to PHY_POLL. | ||
546 | * Otherwise, we enable the interrupts in the PHY. | ||
547 | * Returns 0 on success. | ||
548 | * This should only be called with a valid IRQ number. | ||
549 | */ | ||
550 | int phy_start_interrupts(struct phy_device *phydev) | ||
551 | { | ||
552 | int err = 0; | ||
553 | |||
554 | INIT_WORK(&phydev->phy_queue, phy_change, phydev); | ||
555 | |||
556 | if (request_irq(phydev->irq, phy_interrupt, | ||
557 | SA_SHIRQ, | ||
558 | "phy_interrupt", | ||
559 | phydev) < 0) { | ||
560 | printk(KERN_WARNING "%s: Can't get IRQ %d (PHY)\n", | ||
561 | phydev->bus->name, | ||
562 | phydev->irq); | ||
563 | phydev->irq = PHY_POLL; | ||
564 | return 0; | ||
565 | } | ||
566 | |||
567 | err = phy_enable_interrupts(phydev); | ||
568 | |||
569 | return err; | ||
570 | } | ||
571 | EXPORT_SYMBOL(phy_start_interrupts); | ||
572 | |||
573 | int phy_stop_interrupts(struct phy_device *phydev) | ||
574 | { | ||
575 | int err; | ||
576 | |||
577 | err = phy_disable_interrupts(phydev); | ||
578 | |||
579 | if (err) | ||
580 | phy_error(phydev); | ||
581 | |||
582 | free_irq(phydev->irq, phydev); | ||
583 | |||
584 | return err; | ||
585 | } | ||
586 | EXPORT_SYMBOL(phy_stop_interrupts); | ||
587 | |||
588 | |||
589 | /* Scheduled by the phy_interrupt/timer to handle PHY changes */ | ||
590 | static void phy_change(void *data) | ||
591 | { | ||
592 | int err; | ||
593 | struct phy_device *phydev = data; | ||
594 | |||
595 | err = phy_disable_interrupts(phydev); | ||
596 | |||
597 | if (err) | ||
598 | goto phy_err; | ||
599 | |||
600 | spin_lock(&phydev->lock); | ||
601 | if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state)) | ||
602 | phydev->state = PHY_CHANGELINK; | ||
603 | spin_unlock(&phydev->lock); | ||
604 | |||
605 | enable_irq(phydev->irq); | ||
606 | |||
607 | /* Reenable interrupts */ | ||
608 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | ||
609 | |||
610 | if (err) | ||
611 | goto irq_enable_err; | ||
612 | |||
613 | return; | ||
614 | |||
615 | irq_enable_err: | ||
616 | disable_irq(phydev->irq); | ||
617 | phy_err: | ||
618 | phy_error(phydev); | ||
619 | } | ||
620 | |||
621 | /* Bring down the PHY link, and stop checking the status. */ | ||
622 | void phy_stop(struct phy_device *phydev) | ||
623 | { | ||
624 | spin_lock(&phydev->lock); | ||
625 | |||
626 | if (PHY_HALTED == phydev->state) | ||
627 | goto out_unlock; | ||
628 | |||
629 | if (phydev->irq != PHY_POLL) { | ||
630 | /* Clear any pending interrupts */ | ||
631 | phy_clear_interrupt(phydev); | ||
632 | |||
633 | /* Disable PHY Interrupts */ | ||
634 | phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); | ||
635 | } | ||
636 | |||
637 | phydev->state = PHY_HALTED; | ||
638 | |||
639 | out_unlock: | ||
640 | spin_unlock(&phydev->lock); | ||
641 | } | ||
642 | |||
643 | |||
644 | /* phy_start | ||
645 | * | ||
646 | * description: Indicates the attached device's readiness to | ||
647 | * handle PHY-related work. Used during startup to start the | ||
648 | * PHY, and after a call to phy_stop() to resume operation. | ||
649 | * Also used to indicate the MDIO bus has cleared an error | ||
650 | * condition. | ||
651 | */ | ||
652 | void phy_start(struct phy_device *phydev) | ||
653 | { | ||
654 | spin_lock(&phydev->lock); | ||
655 | |||
656 | switch (phydev->state) { | ||
657 | case PHY_STARTING: | ||
658 | phydev->state = PHY_PENDING; | ||
659 | break; | ||
660 | case PHY_READY: | ||
661 | phydev->state = PHY_UP; | ||
662 | break; | ||
663 | case PHY_HALTED: | ||
664 | phydev->state = PHY_RESUMING; | ||
665 | default: | ||
666 | break; | ||
667 | } | ||
668 | spin_unlock(&phydev->lock); | ||
669 | } | ||
670 | EXPORT_SYMBOL(phy_stop); | ||
671 | EXPORT_SYMBOL(phy_start); | ||
672 | |||
673 | /* PHY timer which handles the state machine */ | ||
674 | static void phy_timer(unsigned long data) | ||
675 | { | ||
676 | struct phy_device *phydev = (struct phy_device *)data; | ||
677 | int needs_aneg = 0; | ||
678 | int err = 0; | ||
679 | |||
680 | spin_lock(&phydev->lock); | ||
681 | |||
682 | if (phydev->adjust_state) | ||
683 | phydev->adjust_state(phydev->attached_dev); | ||
684 | |||
685 | switch(phydev->state) { | ||
686 | case PHY_DOWN: | ||
687 | case PHY_STARTING: | ||
688 | case PHY_READY: | ||
689 | case PHY_PENDING: | ||
690 | break; | ||
691 | case PHY_UP: | ||
692 | needs_aneg = 1; | ||
693 | |||
694 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
695 | |||
696 | break; | ||
697 | case PHY_AN: | ||
698 | /* Check if negotiation is done. Break | ||
699 | * if there's an error */ | ||
700 | err = phy_aneg_done(phydev); | ||
701 | if (err < 0) | ||
702 | break; | ||
703 | |||
704 | /* If auto-negotiation is done, we change to | ||
705 | * either RUNNING, or NOLINK */ | ||
706 | if (err > 0) { | ||
707 | err = phy_read_status(phydev); | ||
708 | |||
709 | if (err) | ||
710 | break; | ||
711 | |||
712 | if (phydev->link) { | ||
713 | phydev->state = PHY_RUNNING; | ||
714 | netif_carrier_on(phydev->attached_dev); | ||
715 | } else { | ||
716 | phydev->state = PHY_NOLINK; | ||
717 | netif_carrier_off(phydev->attached_dev); | ||
718 | } | ||
719 | |||
720 | phydev->adjust_link(phydev->attached_dev); | ||
721 | |||
722 | } else if (0 == phydev->link_timeout--) { | ||
723 | /* The counter expired, so either we | ||
724 | * switch to forced mode, or the | ||
725 | * magic_aneg bit exists, and we try aneg | ||
726 | * again */ | ||
727 | if (!(phydev->drv->flags & PHY_HAS_MAGICANEG)) { | ||
728 | int idx; | ||
729 | |||
730 | /* We'll start from the | ||
731 | * fastest speed, and work | ||
732 | * our way down */ | ||
733 | idx = phy_find_valid(0, | ||
734 | phydev->supported); | ||
735 | |||
736 | phydev->speed = settings[idx].speed; | ||
737 | phydev->duplex = settings[idx].duplex; | ||
738 | |||
739 | phydev->autoneg = AUTONEG_DISABLE; | ||
740 | phydev->state = PHY_FORCING; | ||
741 | phydev->link_timeout = | ||
742 | PHY_FORCE_TIMEOUT; | ||
743 | |||
744 | pr_info("Trying %d/%s\n", | ||
745 | phydev->speed, | ||
746 | DUPLEX_FULL == | ||
747 | phydev->duplex ? | ||
748 | "FULL" : "HALF"); | ||
749 | } | ||
750 | |||
751 | needs_aneg = 1; | ||
752 | } | ||
753 | break; | ||
754 | case PHY_NOLINK: | ||
755 | err = phy_read_status(phydev); | ||
756 | |||
757 | if (err) | ||
758 | break; | ||
759 | |||
760 | if (phydev->link) { | ||
761 | phydev->state = PHY_RUNNING; | ||
762 | netif_carrier_on(phydev->attached_dev); | ||
763 | phydev->adjust_link(phydev->attached_dev); | ||
764 | } | ||
765 | break; | ||
766 | case PHY_FORCING: | ||
767 | err = phy_read_status(phydev); | ||
768 | |||
769 | if (err) | ||
770 | break; | ||
771 | |||
772 | if (phydev->link) { | ||
773 | phydev->state = PHY_RUNNING; | ||
774 | netif_carrier_on(phydev->attached_dev); | ||
775 | } else { | ||
776 | if (0 == phydev->link_timeout--) { | ||
777 | phy_force_reduction(phydev); | ||
778 | needs_aneg = 1; | ||
779 | } | ||
780 | } | ||
781 | |||
782 | phydev->adjust_link(phydev->attached_dev); | ||
783 | break; | ||
784 | case PHY_RUNNING: | ||
785 | /* Only register a CHANGE if we are | ||
786 | * polling */ | ||
787 | if (PHY_POLL == phydev->irq) | ||
788 | phydev->state = PHY_CHANGELINK; | ||
789 | break; | ||
790 | case PHY_CHANGELINK: | ||
791 | err = phy_read_status(phydev); | ||
792 | |||
793 | if (err) | ||
794 | break; | ||
795 | |||
796 | if (phydev->link) { | ||
797 | phydev->state = PHY_RUNNING; | ||
798 | netif_carrier_on(phydev->attached_dev); | ||
799 | } else { | ||
800 | phydev->state = PHY_NOLINK; | ||
801 | netif_carrier_off(phydev->attached_dev); | ||
802 | } | ||
803 | |||
804 | phydev->adjust_link(phydev->attached_dev); | ||
805 | |||
806 | if (PHY_POLL != phydev->irq) | ||
807 | err = phy_config_interrupt(phydev, | ||
808 | PHY_INTERRUPT_ENABLED); | ||
809 | break; | ||
810 | case PHY_HALTED: | ||
811 | if (phydev->link) { | ||
812 | phydev->link = 0; | ||
813 | netif_carrier_off(phydev->attached_dev); | ||
814 | phydev->adjust_link(phydev->attached_dev); | ||
815 | } | ||
816 | break; | ||
817 | case PHY_RESUMING: | ||
818 | |||
819 | err = phy_clear_interrupt(phydev); | ||
820 | |||
821 | if (err) | ||
822 | break; | ||
823 | |||
824 | err = phy_config_interrupt(phydev, | ||
825 | PHY_INTERRUPT_ENABLED); | ||
826 | |||
827 | if (err) | ||
828 | break; | ||
829 | |||
830 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
831 | err = phy_aneg_done(phydev); | ||
832 | if (err < 0) | ||
833 | break; | ||
834 | |||
835 | /* err > 0 if AN is done. | ||
836 | * Otherwise, it's 0, and we're | ||
837 | * still waiting for AN */ | ||
838 | if (err > 0) { | ||
839 | phydev->state = PHY_RUNNING; | ||
840 | } else { | ||
841 | phydev->state = PHY_AN; | ||
842 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
843 | } | ||
844 | } else | ||
845 | phydev->state = PHY_RUNNING; | ||
846 | break; | ||
847 | } | ||
848 | |||
849 | spin_unlock(&phydev->lock); | ||
850 | |||
851 | if (needs_aneg) | ||
852 | err = phy_start_aneg(phydev); | ||
853 | |||
854 | if (err < 0) | ||
855 | phy_error(phydev); | ||
856 | |||
857 | mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ); | ||
858 | } | ||
859 | |||
860 | #endif /* CONFIG_PHYCONTROL */ | ||
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c new file mode 100644 index 000000000000..f0595af4c837 --- /dev/null +++ b/drivers/net/phy/phy_device.c | |||
@@ -0,0 +1,682 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/phy_device.c | ||
3 | * | ||
4 | * Framework for finding and configuring PHYs. | ||
5 | * Also contains generic PHY driver | ||
6 | * | ||
7 | * Author: Andy Fleming | ||
8 | * | ||
9 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the | ||
13 | * Free Software Foundation; either version 2 of the License, or (at your | ||
14 | * option) any later version. | ||
15 | * | ||
16 | */ | ||
17 | #include <linux/config.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/string.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/unistd.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/netdevice.h> | ||
28 | #include <linux/etherdevice.h> | ||
29 | #include <linux/skbuff.h> | ||
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/mm.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/version.h> | ||
34 | #include <linux/mii.h> | ||
35 | #include <linux/ethtool.h> | ||
36 | #include <linux/phy.h> | ||
37 | |||
38 | #include <asm/io.h> | ||
39 | #include <asm/irq.h> | ||
40 | #include <asm/uaccess.h> | ||
41 | |||
42 | /* get_phy_device | ||
43 | * | ||
44 | * description: Reads the ID registers of the PHY at addr on the | ||
45 | * bus, then allocates and returns the phy_device to | ||
46 | * represent it. | ||
47 | */ | ||
48 | struct phy_device * get_phy_device(struct mii_bus *bus, int addr) | ||
49 | { | ||
50 | int phy_reg; | ||
51 | u32 phy_id; | ||
52 | struct phy_device *dev = NULL; | ||
53 | |||
54 | /* Grab the bits from PHYIR1, and put them | ||
55 | * in the upper half */ | ||
56 | phy_reg = bus->read(bus, addr, MII_PHYSID1); | ||
57 | |||
58 | if (phy_reg < 0) | ||
59 | return ERR_PTR(phy_reg); | ||
60 | |||
61 | phy_id = (phy_reg & 0xffff) << 16; | ||
62 | |||
63 | /* Grab the bits from PHYIR2, and put them in the lower half */ | ||
64 | phy_reg = bus->read(bus, addr, MII_PHYSID2); | ||
65 | |||
66 | if (phy_reg < 0) | ||
67 | return ERR_PTR(phy_reg); | ||
68 | |||
69 | phy_id |= (phy_reg & 0xffff); | ||
70 | |||
71 | /* If the phy_id is all Fs, there is no device there */ | ||
72 | if (0xffffffff == phy_id) | ||
73 | return NULL; | ||
74 | |||
75 | /* Otherwise, we allocate the device, and initialize the | ||
76 | * default values */ | ||
77 | dev = kcalloc(1, sizeof(*dev), GFP_KERNEL); | ||
78 | |||
79 | if (NULL == dev) | ||
80 | return ERR_PTR(-ENOMEM); | ||
81 | |||
82 | dev->speed = 0; | ||
83 | dev->duplex = -1; | ||
84 | dev->pause = dev->asym_pause = 0; | ||
85 | dev->link = 1; | ||
86 | |||
87 | dev->autoneg = AUTONEG_ENABLE; | ||
88 | |||
89 | dev->addr = addr; | ||
90 | dev->phy_id = phy_id; | ||
91 | dev->bus = bus; | ||
92 | |||
93 | dev->state = PHY_DOWN; | ||
94 | |||
95 | spin_lock_init(&dev->lock); | ||
96 | |||
97 | return dev; | ||
98 | } | ||
99 | |||
100 | /* phy_prepare_link: | ||
101 | * | ||
102 | * description: Tells the PHY infrastructure to handle the | ||
103 | * gory details on monitoring link status (whether through | ||
104 | * polling or an interrupt), and to call back to the | ||
105 | * connected device driver when the link status changes. | ||
106 | * If you want to monitor your own link state, don't call | ||
107 | * this function */ | ||
108 | void phy_prepare_link(struct phy_device *phydev, | ||
109 | void (*handler)(struct net_device *)) | ||
110 | { | ||
111 | phydev->adjust_link = handler; | ||
112 | } | ||
113 | |||
114 | #ifdef CONFIG_PHYCONTROL | ||
115 | /* phy_connect: | ||
116 | * | ||
117 | * description: Convenience function for connecting ethernet | ||
118 | * devices to PHY devices. The default behavior is for | ||
119 | * the PHY infrastructure to handle everything, and only notify | ||
120 | * the connected driver when the link status changes. If you | ||
121 | * don't want, or can't use the provided functionality, you may | ||
122 | * choose to call only the subset of functions which provide | ||
123 | * the desired functionality. | ||
124 | */ | ||
125 | struct phy_device * phy_connect(struct net_device *dev, const char *phy_id, | ||
126 | void (*handler)(struct net_device *), u32 flags) | ||
127 | { | ||
128 | struct phy_device *phydev; | ||
129 | |||
130 | phydev = phy_attach(dev, phy_id, flags); | ||
131 | |||
132 | if (IS_ERR(phydev)) | ||
133 | return phydev; | ||
134 | |||
135 | phy_prepare_link(phydev, handler); | ||
136 | |||
137 | phy_start_machine(phydev, NULL); | ||
138 | |||
139 | if (phydev->irq > 0) | ||
140 | phy_start_interrupts(phydev); | ||
141 | |||
142 | return phydev; | ||
143 | } | ||
144 | EXPORT_SYMBOL(phy_connect); | ||
145 | |||
146 | void phy_disconnect(struct phy_device *phydev) | ||
147 | { | ||
148 | if (phydev->irq > 0) | ||
149 | phy_stop_interrupts(phydev); | ||
150 | |||
151 | phy_stop_machine(phydev); | ||
152 | |||
153 | phydev->adjust_link = NULL; | ||
154 | |||
155 | phy_detach(phydev); | ||
156 | } | ||
157 | EXPORT_SYMBOL(phy_disconnect); | ||
158 | |||
159 | #endif /* CONFIG_PHYCONTROL */ | ||
160 | |||
161 | /* phy_attach: | ||
162 | * | ||
163 | * description: Called by drivers to attach to a particular PHY | ||
164 | * device. The phy_device is found, and properly hooked up | ||
165 | * to the phy_driver. If no driver is attached, then the | ||
166 | * genphy_driver is used. The phy_device is given a ptr to | ||
167 | * the attaching device, and given a callback for link status | ||
168 | * change. The phy_device is returned to the attaching | ||
169 | * driver. | ||
170 | */ | ||
171 | static int phy_compare_id(struct device *dev, void *data) | ||
172 | { | ||
173 | return strcmp((char *)data, dev->bus_id) ? 0 : 1; | ||
174 | } | ||
175 | |||
176 | struct phy_device *phy_attach(struct net_device *dev, | ||
177 | const char *phy_id, u32 flags) | ||
178 | { | ||
179 | struct bus_type *bus = &mdio_bus_type; | ||
180 | struct phy_device *phydev; | ||
181 | struct device *d; | ||
182 | |||
183 | /* Search the list of PHY devices on the mdio bus for the | ||
184 | * PHY with the requested name */ | ||
185 | d = bus_find_device(bus, NULL, (void *)phy_id, phy_compare_id); | ||
186 | |||
187 | if (d) { | ||
188 | phydev = to_phy_device(d); | ||
189 | } else { | ||
190 | printk(KERN_ERR "%s not found\n", phy_id); | ||
191 | return ERR_PTR(-ENODEV); | ||
192 | } | ||
193 | |||
194 | /* Assume that if there is no driver, that it doesn't | ||
195 | * exist, and we should use the genphy driver. */ | ||
196 | if (NULL == d->driver) { | ||
197 | int err; | ||
198 | down_write(&d->bus->subsys.rwsem); | ||
199 | d->driver = &genphy_driver.driver; | ||
200 | |||
201 | err = d->driver->probe(d); | ||
202 | |||
203 | if (err < 0) | ||
204 | return ERR_PTR(err); | ||
205 | |||
206 | device_bind_driver(d); | ||
207 | up_write(&d->bus->subsys.rwsem); | ||
208 | } | ||
209 | |||
210 | if (phydev->attached_dev) { | ||
211 | printk(KERN_ERR "%s: %s already attached\n", | ||
212 | dev->name, phy_id); | ||
213 | return ERR_PTR(-EBUSY); | ||
214 | } | ||
215 | |||
216 | phydev->attached_dev = dev; | ||
217 | |||
218 | phydev->dev_flags = flags; | ||
219 | |||
220 | return phydev; | ||
221 | } | ||
222 | EXPORT_SYMBOL(phy_attach); | ||
223 | |||
224 | void phy_detach(struct phy_device *phydev) | ||
225 | { | ||
226 | phydev->attached_dev = NULL; | ||
227 | |||
228 | /* If the device had no specific driver before (i.e. - it | ||
229 | * was using the generic driver), we unbind the device | ||
230 | * from the generic driver so that there's a chance a | ||
231 | * real driver could be loaded */ | ||
232 | if (phydev->dev.driver == &genphy_driver.driver) { | ||
233 | down_write(&phydev->dev.bus->subsys.rwsem); | ||
234 | device_release_driver(&phydev->dev); | ||
235 | up_write(&phydev->dev.bus->subsys.rwsem); | ||
236 | } | ||
237 | } | ||
238 | EXPORT_SYMBOL(phy_detach); | ||
239 | |||
240 | |||
241 | /* Generic PHY support and helper functions */ | ||
242 | |||
243 | /* genphy_config_advert | ||
244 | * | ||
245 | * description: Writes MII_ADVERTISE with the appropriate values, | ||
246 | * after sanitizing the values to make sure we only advertise | ||
247 | * what is supported | ||
248 | */ | ||
249 | int genphy_config_advert(struct phy_device *phydev) | ||
250 | { | ||
251 | u32 advertise; | ||
252 | int adv; | ||
253 | int err; | ||
254 | |||
255 | /* Only allow advertising what | ||
256 | * this PHY supports */ | ||
257 | phydev->advertising &= phydev->supported; | ||
258 | advertise = phydev->advertising; | ||
259 | |||
260 | /* Setup standard advertisement */ | ||
261 | adv = phy_read(phydev, MII_ADVERTISE); | ||
262 | |||
263 | if (adv < 0) | ||
264 | return adv; | ||
265 | |||
266 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | | ||
267 | ADVERTISE_PAUSE_ASYM); | ||
268 | if (advertise & ADVERTISED_10baseT_Half) | ||
269 | adv |= ADVERTISE_10HALF; | ||
270 | if (advertise & ADVERTISED_10baseT_Full) | ||
271 | adv |= ADVERTISE_10FULL; | ||
272 | if (advertise & ADVERTISED_100baseT_Half) | ||
273 | adv |= ADVERTISE_100HALF; | ||
274 | if (advertise & ADVERTISED_100baseT_Full) | ||
275 | adv |= ADVERTISE_100FULL; | ||
276 | if (advertise & ADVERTISED_Pause) | ||
277 | adv |= ADVERTISE_PAUSE_CAP; | ||
278 | if (advertise & ADVERTISED_Asym_Pause) | ||
279 | adv |= ADVERTISE_PAUSE_ASYM; | ||
280 | |||
281 | err = phy_write(phydev, MII_ADVERTISE, adv); | ||
282 | |||
283 | if (err < 0) | ||
284 | return err; | ||
285 | |||
286 | /* Configure gigabit if it's supported */ | ||
287 | if (phydev->supported & (SUPPORTED_1000baseT_Half | | ||
288 | SUPPORTED_1000baseT_Full)) { | ||
289 | adv = phy_read(phydev, MII_CTRL1000); | ||
290 | |||
291 | if (adv < 0) | ||
292 | return adv; | ||
293 | |||
294 | adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); | ||
295 | if (advertise & SUPPORTED_1000baseT_Half) | ||
296 | adv |= ADVERTISE_1000HALF; | ||
297 | if (advertise & SUPPORTED_1000baseT_Full) | ||
298 | adv |= ADVERTISE_1000FULL; | ||
299 | err = phy_write(phydev, MII_CTRL1000, adv); | ||
300 | |||
301 | if (err < 0) | ||
302 | return err; | ||
303 | } | ||
304 | |||
305 | return adv; | ||
306 | } | ||
307 | EXPORT_SYMBOL(genphy_config_advert); | ||
308 | |||
309 | /* genphy_setup_forced | ||
310 | * | ||
311 | * description: Configures MII_BMCR to force speed/duplex | ||
312 | * to the values in phydev. Assumes that the values are valid. | ||
313 | * Please see phy_sanitize_settings() */ | ||
314 | int genphy_setup_forced(struct phy_device *phydev) | ||
315 | { | ||
316 | int ctl = BMCR_RESET; | ||
317 | |||
318 | phydev->pause = phydev->asym_pause = 0; | ||
319 | |||
320 | if (SPEED_1000 == phydev->speed) | ||
321 | ctl |= BMCR_SPEED1000; | ||
322 | else if (SPEED_100 == phydev->speed) | ||
323 | ctl |= BMCR_SPEED100; | ||
324 | |||
325 | if (DUPLEX_FULL == phydev->duplex) | ||
326 | ctl |= BMCR_FULLDPLX; | ||
327 | |||
328 | ctl = phy_write(phydev, MII_BMCR, ctl); | ||
329 | |||
330 | if (ctl < 0) | ||
331 | return ctl; | ||
332 | |||
333 | /* We just reset the device, so we'd better configure any | ||
334 | * settings the PHY requires to operate */ | ||
335 | if (phydev->drv->config_init) | ||
336 | ctl = phydev->drv->config_init(phydev); | ||
337 | |||
338 | return ctl; | ||
339 | } | ||
340 | |||
341 | |||
342 | /* Enable and Restart Autonegotiation */ | ||
343 | int genphy_restart_aneg(struct phy_device *phydev) | ||
344 | { | ||
345 | int ctl; | ||
346 | |||
347 | ctl = phy_read(phydev, MII_BMCR); | ||
348 | |||
349 | if (ctl < 0) | ||
350 | return ctl; | ||
351 | |||
352 | ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); | ||
353 | |||
354 | /* Don't isolate the PHY if we're negotiating */ | ||
355 | ctl &= ~(BMCR_ISOLATE); | ||
356 | |||
357 | ctl = phy_write(phydev, MII_BMCR, ctl); | ||
358 | |||
359 | return ctl; | ||
360 | } | ||
361 | |||
362 | |||
363 | /* genphy_config_aneg | ||
364 | * | ||
365 | * description: If auto-negotiation is enabled, we configure the | ||
366 | * advertising, and then restart auto-negotiation. If it is not | ||
367 | * enabled, then we write the BMCR | ||
368 | */ | ||
369 | int genphy_config_aneg(struct phy_device *phydev) | ||
370 | { | ||
371 | int err = 0; | ||
372 | |||
373 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
374 | err = genphy_config_advert(phydev); | ||
375 | |||
376 | if (err < 0) | ||
377 | return err; | ||
378 | |||
379 | err = genphy_restart_aneg(phydev); | ||
380 | } else | ||
381 | err = genphy_setup_forced(phydev); | ||
382 | |||
383 | return err; | ||
384 | } | ||
385 | EXPORT_SYMBOL(genphy_config_aneg); | ||
386 | |||
387 | /* genphy_update_link | ||
388 | * | ||
389 | * description: Update the value in phydev->link to reflect the | ||
390 | * current link value. In order to do this, we need to read | ||
391 | * the status register twice, keeping the second value | ||
392 | */ | ||
393 | int genphy_update_link(struct phy_device *phydev) | ||
394 | { | ||
395 | int status; | ||
396 | |||
397 | /* Do a fake read */ | ||
398 | status = phy_read(phydev, MII_BMSR); | ||
399 | |||
400 | if (status < 0) | ||
401 | return status; | ||
402 | |||
403 | /* Read link and autonegotiation status */ | ||
404 | status = phy_read(phydev, MII_BMSR); | ||
405 | |||
406 | if (status < 0) | ||
407 | return status; | ||
408 | |||
409 | if ((status & BMSR_LSTATUS) == 0) | ||
410 | phydev->link = 0; | ||
411 | else | ||
412 | phydev->link = 1; | ||
413 | |||
414 | return 0; | ||
415 | } | ||
416 | |||
417 | /* genphy_read_status | ||
418 | * | ||
419 | * description: Check the link, then figure out the current state | ||
420 | * by comparing what we advertise with what the link partner | ||
421 | * advertises. Start by checking the gigabit possibilities, | ||
422 | * then move on to 10/100. | ||
423 | */ | ||
424 | int genphy_read_status(struct phy_device *phydev) | ||
425 | { | ||
426 | int adv; | ||
427 | int err; | ||
428 | int lpa; | ||
429 | int lpagb = 0; | ||
430 | |||
431 | /* Update the link, but return if there | ||
432 | * was an error */ | ||
433 | err = genphy_update_link(phydev); | ||
434 | if (err) | ||
435 | return err; | ||
436 | |||
437 | if (AUTONEG_ENABLE == phydev->autoneg) { | ||
438 | if (phydev->supported & (SUPPORTED_1000baseT_Half | ||
439 | | SUPPORTED_1000baseT_Full)) { | ||
440 | lpagb = phy_read(phydev, MII_STAT1000); | ||
441 | |||
442 | if (lpagb < 0) | ||
443 | return lpagb; | ||
444 | |||
445 | adv = phy_read(phydev, MII_CTRL1000); | ||
446 | |||
447 | if (adv < 0) | ||
448 | return adv; | ||
449 | |||
450 | lpagb &= adv << 2; | ||
451 | } | ||
452 | |||
453 | lpa = phy_read(phydev, MII_LPA); | ||
454 | |||
455 | if (lpa < 0) | ||
456 | return lpa; | ||
457 | |||
458 | adv = phy_read(phydev, MII_ADVERTISE); | ||
459 | |||
460 | if (adv < 0) | ||
461 | return adv; | ||
462 | |||
463 | lpa &= adv; | ||
464 | |||
465 | phydev->speed = SPEED_10; | ||
466 | phydev->duplex = DUPLEX_HALF; | ||
467 | phydev->pause = phydev->asym_pause = 0; | ||
468 | |||
469 | if (lpagb & (LPA_1000FULL | LPA_1000HALF)) { | ||
470 | phydev->speed = SPEED_1000; | ||
471 | |||
472 | if (lpagb & LPA_1000FULL) | ||
473 | phydev->duplex = DUPLEX_FULL; | ||
474 | } else if (lpa & (LPA_100FULL | LPA_100HALF)) { | ||
475 | phydev->speed = SPEED_100; | ||
476 | |||
477 | if (lpa & LPA_100FULL) | ||
478 | phydev->duplex = DUPLEX_FULL; | ||
479 | } else | ||
480 | if (lpa & LPA_10FULL) | ||
481 | phydev->duplex = DUPLEX_FULL; | ||
482 | |||
483 | if (phydev->duplex == DUPLEX_FULL){ | ||
484 | phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; | ||
485 | phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0; | ||
486 | } | ||
487 | } else { | ||
488 | int bmcr = phy_read(phydev, MII_BMCR); | ||
489 | if (bmcr < 0) | ||
490 | return bmcr; | ||
491 | |||
492 | if (bmcr & BMCR_FULLDPLX) | ||
493 | phydev->duplex = DUPLEX_FULL; | ||
494 | else | ||
495 | phydev->duplex = DUPLEX_HALF; | ||
496 | |||
497 | if (bmcr & BMCR_SPEED1000) | ||
498 | phydev->speed = SPEED_1000; | ||
499 | else if (bmcr & BMCR_SPEED100) | ||
500 | phydev->speed = SPEED_100; | ||
501 | else | ||
502 | phydev->speed = SPEED_10; | ||
503 | |||
504 | phydev->pause = phydev->asym_pause = 0; | ||
505 | } | ||
506 | |||
507 | return 0; | ||
508 | } | ||
509 | EXPORT_SYMBOL(genphy_read_status); | ||
510 | |||
511 | static int genphy_config_init(struct phy_device *phydev) | ||
512 | { | ||
513 | u32 val; | ||
514 | u32 features; | ||
515 | |||
516 | /* For now, I'll claim that the generic driver supports | ||
517 | * all possible port types */ | ||
518 | features = (SUPPORTED_TP | SUPPORTED_MII | ||
519 | | SUPPORTED_AUI | SUPPORTED_FIBRE | | ||
520 | SUPPORTED_BNC); | ||
521 | |||
522 | /* Do we support autonegotiation? */ | ||
523 | val = phy_read(phydev, MII_BMSR); | ||
524 | |||
525 | if (val < 0) | ||
526 | return val; | ||
527 | |||
528 | if (val & BMSR_ANEGCAPABLE) | ||
529 | features |= SUPPORTED_Autoneg; | ||
530 | |||
531 | if (val & BMSR_100FULL) | ||
532 | features |= SUPPORTED_100baseT_Full; | ||
533 | if (val & BMSR_100HALF) | ||
534 | features |= SUPPORTED_100baseT_Half; | ||
535 | if (val & BMSR_10FULL) | ||
536 | features |= SUPPORTED_10baseT_Full; | ||
537 | if (val & BMSR_10HALF) | ||
538 | features |= SUPPORTED_10baseT_Half; | ||
539 | |||
540 | if (val & BMSR_ESTATEN) { | ||
541 | val = phy_read(phydev, MII_ESTATUS); | ||
542 | |||
543 | if (val < 0) | ||
544 | return val; | ||
545 | |||
546 | if (val & ESTATUS_1000_TFULL) | ||
547 | features |= SUPPORTED_1000baseT_Full; | ||
548 | if (val & ESTATUS_1000_THALF) | ||
549 | features |= SUPPORTED_1000baseT_Half; | ||
550 | } | ||
551 | |||
552 | phydev->supported = features; | ||
553 | phydev->advertising = features; | ||
554 | |||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | |||
559 | /* phy_probe | ||
560 | * | ||
561 | * description: Take care of setting up the phy_device structure, | ||
562 | * set the state to READY (the driver's init function should | ||
563 | * set it to STARTING if needed). | ||
564 | */ | ||
565 | static int phy_probe(struct device *dev) | ||
566 | { | ||
567 | struct phy_device *phydev; | ||
568 | struct phy_driver *phydrv; | ||
569 | struct device_driver *drv; | ||
570 | int err = 0; | ||
571 | |||
572 | phydev = to_phy_device(dev); | ||
573 | |||
574 | /* Make sure the driver is held. | ||
575 | * XXX -- Is this correct? */ | ||
576 | drv = get_driver(phydev->dev.driver); | ||
577 | phydrv = to_phy_driver(drv); | ||
578 | phydev->drv = phydrv; | ||
579 | |||
580 | /* Disable the interrupt if the PHY doesn't support it */ | ||
581 | if (!(phydrv->flags & PHY_HAS_INTERRUPT)) | ||
582 | phydev->irq = PHY_POLL; | ||
583 | |||
584 | spin_lock(&phydev->lock); | ||
585 | |||
586 | /* Start out supporting everything. Eventually, | ||
587 | * a controller will attach, and may modify one | ||
588 | * or both of these values */ | ||
589 | phydev->supported = phydrv->features; | ||
590 | phydev->advertising = phydrv->features; | ||
591 | |||
592 | /* Set the state to READY by default */ | ||
593 | phydev->state = PHY_READY; | ||
594 | |||
595 | if (phydev->drv->probe) | ||
596 | err = phydev->drv->probe(phydev); | ||
597 | |||
598 | spin_unlock(&phydev->lock); | ||
599 | |||
600 | if (err < 0) | ||
601 | return err; | ||
602 | |||
603 | if (phydev->drv->config_init) | ||
604 | err = phydev->drv->config_init(phydev); | ||
605 | |||
606 | return err; | ||
607 | } | ||
608 | |||
609 | static int phy_remove(struct device *dev) | ||
610 | { | ||
611 | struct phy_device *phydev; | ||
612 | |||
613 | phydev = to_phy_device(dev); | ||
614 | |||
615 | spin_lock(&phydev->lock); | ||
616 | phydev->state = PHY_DOWN; | ||
617 | spin_unlock(&phydev->lock); | ||
618 | |||
619 | if (phydev->drv->remove) | ||
620 | phydev->drv->remove(phydev); | ||
621 | |||
622 | put_driver(dev->driver); | ||
623 | phydev->drv = NULL; | ||
624 | |||
625 | return 0; | ||
626 | } | ||
627 | |||
628 | int phy_driver_register(struct phy_driver *new_driver) | ||
629 | { | ||
630 | int retval; | ||
631 | |||
632 | memset(&new_driver->driver, 0, sizeof(new_driver->driver)); | ||
633 | new_driver->driver.name = new_driver->name; | ||
634 | new_driver->driver.bus = &mdio_bus_type; | ||
635 | new_driver->driver.probe = phy_probe; | ||
636 | new_driver->driver.remove = phy_remove; | ||
637 | |||
638 | retval = driver_register(&new_driver->driver); | ||
639 | |||
640 | if (retval) { | ||
641 | printk(KERN_ERR "%s: Error %d in registering driver\n", | ||
642 | new_driver->name, retval); | ||
643 | |||
644 | return retval; | ||
645 | } | ||
646 | |||
647 | pr_info("%s: Registered new driver\n", new_driver->name); | ||
648 | |||
649 | return 0; | ||
650 | } | ||
651 | EXPORT_SYMBOL(phy_driver_register); | ||
652 | |||
653 | void phy_driver_unregister(struct phy_driver *drv) | ||
654 | { | ||
655 | driver_unregister(&drv->driver); | ||
656 | } | ||
657 | EXPORT_SYMBOL(phy_driver_unregister); | ||
658 | |||
659 | static struct phy_driver genphy_driver = { | ||
660 | .phy_id = 0xffffffff, | ||
661 | .phy_id_mask = 0xffffffff, | ||
662 | .name = "Generic PHY", | ||
663 | .config_init = genphy_config_init, | ||
664 | .features = 0, | ||
665 | .config_aneg = genphy_config_aneg, | ||
666 | .read_status = genphy_read_status, | ||
667 | .driver = {.owner = THIS_MODULE, }, | ||
668 | }; | ||
669 | |||
670 | static int __init genphy_init(void) | ||
671 | { | ||
672 | return phy_driver_register(&genphy_driver); | ||
673 | |||
674 | } | ||
675 | |||
676 | static void __exit genphy_exit(void) | ||
677 | { | ||
678 | phy_driver_unregister(&genphy_driver); | ||
679 | } | ||
680 | |||
681 | module_init(genphy_init); | ||
682 | module_exit(genphy_exit); | ||
diff --git a/drivers/net/phy/qsemi.c b/drivers/net/phy/qsemi.c new file mode 100644 index 000000000000..d461ba457631 --- /dev/null +++ b/drivers/net/phy/qsemi.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * drivers/net/phy/qsemi.c | ||
3 | * | ||
4 | * Driver for Quality Semiconductor PHYs | ||
5 | * | ||
6 | * Author: Andy Fleming | ||
7 | * | ||
8 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/config.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/unistd.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/etherdevice.h> | ||
28 | #include <linux/skbuff.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/mm.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/version.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/ethtool.h> | ||
35 | #include <linux/phy.h> | ||
36 | |||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | ||
39 | #include <asm/uaccess.h> | ||
40 | |||
41 | /* ------------------------------------------------------------------------- */ | ||
42 | /* The Quality Semiconductor QS6612 is used on the RPX CLLF */ | ||
43 | |||
44 | /* register definitions */ | ||
45 | |||
46 | #define MII_QS6612_MCR 17 /* Mode Control Register */ | ||
47 | #define MII_QS6612_FTR 27 /* Factory Test Register */ | ||
48 | #define MII_QS6612_MCO 28 /* Misc. Control Register */ | ||
49 | #define MII_QS6612_ISR 29 /* Interrupt Source Register */ | ||
50 | #define MII_QS6612_IMR 30 /* Interrupt Mask Register */ | ||
51 | #define MII_QS6612_IMR_INIT 0x003a | ||
52 | #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */ | ||
53 | |||
54 | #define QS6612_PCR_AN_COMPLETE 0x1000 | ||
55 | #define QS6612_PCR_RLBEN 0x0200 | ||
56 | #define QS6612_PCR_DCREN 0x0100 | ||
57 | #define QS6612_PCR_4B5BEN 0x0040 | ||
58 | #define QS6612_PCR_TX_ISOLATE 0x0020 | ||
59 | #define QS6612_PCR_MLT3_DIS 0x0002 | ||
60 | #define QS6612_PCR_SCRM_DESCRM 0x0001 | ||
61 | |||
62 | MODULE_DESCRIPTION("Quality Semiconductor PHY driver"); | ||
63 | MODULE_AUTHOR("Andy Fleming"); | ||
64 | MODULE_LICENSE("GPL"); | ||
65 | |||
66 | /* Returns 0, unless there's a write error */ | ||
67 | static int qs6612_config_init(struct phy_device *phydev) | ||
68 | { | ||
69 | /* The PHY powers up isolated on the RPX, | ||
70 | * so send a command to allow operation. | ||
71 | * XXX - My docs indicate this should be 0x0940 | ||
72 | * ...or something. The current value sets three | ||
73 | * reserved bits, bit 11, which specifies it should be | ||
74 | * set to one, bit 10, which specifies it should be set | ||
75 | * to 0, and bit 7, which doesn't specify. However, my | ||
76 | * docs are preliminary, and I will leave it like this | ||
77 | * until someone more knowledgable corrects me or it. | ||
78 | * -- Andy Fleming | ||
79 | */ | ||
80 | return phy_write(phydev, MII_QS6612_PCR, 0x0dc0); | ||
81 | } | ||
82 | |||
83 | static int qs6612_ack_interrupt(struct phy_device *phydev) | ||
84 | { | ||
85 | int err; | ||
86 | |||
87 | err = phy_read(phydev, MII_QS6612_ISR); | ||
88 | |||
89 | if (err < 0) | ||
90 | return err; | ||
91 | |||
92 | err = phy_read(phydev, MII_BMSR); | ||
93 | |||
94 | if (err < 0) | ||
95 | return err; | ||
96 | |||
97 | err = phy_read(phydev, MII_EXPANSION); | ||
98 | |||
99 | if (err < 0) | ||
100 | return err; | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static int qs6612_config_intr(struct phy_device *phydev) | ||
106 | { | ||
107 | int err; | ||
108 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) | ||
109 | err = phy_write(phydev, MII_QS6612_IMR, | ||
110 | MII_QS6612_IMR_INIT); | ||
111 | else | ||
112 | err = phy_write(phydev, MII_QS6612_IMR, 0); | ||
113 | |||
114 | return err; | ||
115 | |||
116 | } | ||
117 | |||
118 | static struct phy_driver qs6612_driver = { | ||
119 | .phy_id = 0x00181440, | ||
120 | .name = "QS6612", | ||
121 | .phy_id_mask = 0xfffffff0, | ||
122 | .features = PHY_BASIC_FEATURES, | ||
123 | .flags = PHY_HAS_INTERRUPT, | ||
124 | .config_init = qs6612_config_init, | ||
125 | .config_aneg = genphy_config_aneg, | ||
126 | .read_status = genphy_read_status, | ||
127 | .ack_interrupt = qs6612_ack_interrupt, | ||
128 | .config_intr = qs6612_config_intr, | ||
129 | .driver = { .owner = THIS_MODULE,}, | ||
130 | }; | ||
131 | |||
132 | static int __init qs6612_init(void) | ||
133 | { | ||
134 | return phy_driver_register(&qs6612_driver); | ||
135 | } | ||
136 | |||
137 | static void __exit qs6612_exit(void) | ||
138 | { | ||
139 | phy_driver_unregister(&qs6612_driver); | ||
140 | } | ||
141 | |||
142 | module_init(qs6612_init); | ||
143 | module_exit(qs6612_exit); | ||
diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c index 87103c400999..f1e4ef1188e4 100644 --- a/drivers/net/tokenring/abyss.c +++ b/drivers/net/tokenring/abyss.c | |||
@@ -139,7 +139,7 @@ static int __devinit abyss_attach(struct pci_dev *pdev, const struct pci_device_ | |||
139 | */ | 139 | */ |
140 | dev->base_addr += 0x10; | 140 | dev->base_addr += 0x10; |
141 | 141 | ||
142 | ret = tmsdev_init(dev, PCI_MAX_ADDRESS, pdev); | 142 | ret = tmsdev_init(dev, PCI_MAX_ADDRESS, &pdev->dev); |
143 | if (ret) { | 143 | if (ret) { |
144 | printk("%s: unable to get memory for dev->priv.\n", | 144 | printk("%s: unable to get memory for dev->priv.\n", |
145 | dev->name); | 145 | dev->name); |
diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c index 40ad0fde28af..0a9597738d6c 100644 --- a/drivers/net/tokenring/proteon.c +++ b/drivers/net/tokenring/proteon.c | |||
@@ -62,8 +62,7 @@ static int dmalist[] __initdata = { | |||
62 | }; | 62 | }; |
63 | 63 | ||
64 | static char cardname[] = "Proteon 1392\0"; | 64 | static char cardname[] = "Proteon 1392\0"; |
65 | 65 | static u64 dma_mask = ISA_MAX_ADDRESS; | |
66 | struct net_device *proteon_probe(int unit); | ||
67 | static int proteon_open(struct net_device *dev); | 66 | static int proteon_open(struct net_device *dev); |
68 | static void proteon_read_eeprom(struct net_device *dev); | 67 | static void proteon_read_eeprom(struct net_device *dev); |
69 | static unsigned short proteon_setnselout_pins(struct net_device *dev); | 68 | static unsigned short proteon_setnselout_pins(struct net_device *dev); |
@@ -116,7 +115,7 @@ nodev: | |||
116 | return -ENODEV; | 115 | return -ENODEV; |
117 | } | 116 | } |
118 | 117 | ||
119 | static int __init setup_card(struct net_device *dev) | 118 | static int __init setup_card(struct net_device *dev, struct device *pdev) |
120 | { | 119 | { |
121 | struct net_local *tp; | 120 | struct net_local *tp; |
122 | static int versionprinted; | 121 | static int versionprinted; |
@@ -137,7 +136,7 @@ static int __init setup_card(struct net_device *dev) | |||
137 | } | 136 | } |
138 | } | 137 | } |
139 | if (err) | 138 | if (err) |
140 | goto out4; | 139 | goto out5; |
141 | 140 | ||
142 | /* At this point we have found a valid card. */ | 141 | /* At this point we have found a valid card. */ |
143 | 142 | ||
@@ -145,14 +144,15 @@ static int __init setup_card(struct net_device *dev) | |||
145 | printk(KERN_DEBUG "%s", version); | 144 | printk(KERN_DEBUG "%s", version); |
146 | 145 | ||
147 | err = -EIO; | 146 | err = -EIO; |
148 | if (tmsdev_init(dev, ISA_MAX_ADDRESS, NULL)) | 147 | pdev->dma_mask = &dma_mask; |
148 | if (tmsdev_init(dev, ISA_MAX_ADDRESS, pdev)) | ||
149 | goto out4; | 149 | goto out4; |
150 | 150 | ||
151 | dev->base_addr &= ~3; | 151 | dev->base_addr &= ~3; |
152 | 152 | ||
153 | proteon_read_eeprom(dev); | 153 | proteon_read_eeprom(dev); |
154 | 154 | ||
155 | printk(KERN_DEBUG "%s: Ring Station Address: ", dev->name); | 155 | printk(KERN_DEBUG "proteon.c: Ring Station Address: "); |
156 | printk("%2.2x", dev->dev_addr[0]); | 156 | printk("%2.2x", dev->dev_addr[0]); |
157 | for (j = 1; j < 6; j++) | 157 | for (j = 1; j < 6; j++) |
158 | printk(":%2.2x", dev->dev_addr[j]); | 158 | printk(":%2.2x", dev->dev_addr[j]); |
@@ -185,7 +185,7 @@ static int __init setup_card(struct net_device *dev) | |||
185 | 185 | ||
186 | if(irqlist[j] == 0) | 186 | if(irqlist[j] == 0) |
187 | { | 187 | { |
188 | printk(KERN_INFO "%s: AutoSelect no IRQ available\n", dev->name); | 188 | printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n"); |
189 | goto out3; | 189 | goto out3; |
190 | } | 190 | } |
191 | } | 191 | } |
@@ -196,15 +196,15 @@ static int __init setup_card(struct net_device *dev) | |||
196 | break; | 196 | break; |
197 | if (irqlist[j] == 0) | 197 | if (irqlist[j] == 0) |
198 | { | 198 | { |
199 | printk(KERN_INFO "%s: Illegal IRQ %d specified\n", | 199 | printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n", |
200 | dev->name, dev->irq); | 200 | dev->irq); |
201 | goto out3; | 201 | goto out3; |
202 | } | 202 | } |
203 | if (request_irq(dev->irq, tms380tr_interrupt, 0, | 203 | if (request_irq(dev->irq, tms380tr_interrupt, 0, |
204 | cardname, dev)) | 204 | cardname, dev)) |
205 | { | 205 | { |
206 | printk(KERN_INFO "%s: Selected IRQ %d not available\n", | 206 | printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n", |
207 | dev->name, dev->irq); | 207 | dev->irq); |
208 | goto out3; | 208 | goto out3; |
209 | } | 209 | } |
210 | } | 210 | } |
@@ -220,7 +220,7 @@ static int __init setup_card(struct net_device *dev) | |||
220 | 220 | ||
221 | if(dmalist[j] == 0) | 221 | if(dmalist[j] == 0) |
222 | { | 222 | { |
223 | printk(KERN_INFO "%s: AutoSelect no DMA available\n", dev->name); | 223 | printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n"); |
224 | goto out2; | 224 | goto out2; |
225 | } | 225 | } |
226 | } | 226 | } |
@@ -231,25 +231,25 @@ static int __init setup_card(struct net_device *dev) | |||
231 | break; | 231 | break; |
232 | if (dmalist[j] == 0) | 232 | if (dmalist[j] == 0) |
233 | { | 233 | { |
234 | printk(KERN_INFO "%s: Illegal DMA %d specified\n", | 234 | printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n", |
235 | dev->name, dev->dma); | 235 | dev->dma); |
236 | goto out2; | 236 | goto out2; |
237 | } | 237 | } |
238 | if (request_dma(dev->dma, cardname)) | 238 | if (request_dma(dev->dma, cardname)) |
239 | { | 239 | { |
240 | printk(KERN_INFO "%s: Selected DMA %d not available\n", | 240 | printk(KERN_INFO "proteon.c: Selected DMA %d not available\n", |
241 | dev->name, dev->dma); | 241 | dev->dma); |
242 | goto out2; | 242 | goto out2; |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n", | ||
247 | dev->name, dev->base_addr, dev->irq, dev->dma); | ||
248 | |||
249 | err = register_netdev(dev); | 246 | err = register_netdev(dev); |
250 | if (err) | 247 | if (err) |
251 | goto out; | 248 | goto out; |
252 | 249 | ||
250 | printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n", | ||
251 | dev->name, dev->base_addr, dev->irq, dev->dma); | ||
252 | |||
253 | return 0; | 253 | return 0; |
254 | out: | 254 | out: |
255 | free_dma(dev->dma); | 255 | free_dma(dev->dma); |
@@ -258,34 +258,11 @@ out2: | |||
258 | out3: | 258 | out3: |
259 | tmsdev_term(dev); | 259 | tmsdev_term(dev); |
260 | out4: | 260 | out4: |
261 | release_region(dev->base_addr, PROTEON_IO_EXTENT); | 261 | release_region(dev->base_addr, PROTEON_IO_EXTENT); |
262 | out5: | ||
262 | return err; | 263 | return err; |
263 | } | 264 | } |
264 | 265 | ||
265 | struct net_device * __init proteon_probe(int unit) | ||
266 | { | ||
267 | struct net_device *dev = alloc_trdev(sizeof(struct net_local)); | ||
268 | int err = 0; | ||
269 | |||
270 | if (!dev) | ||
271 | return ERR_PTR(-ENOMEM); | ||
272 | |||
273 | if (unit >= 0) { | ||
274 | sprintf(dev->name, "tr%d", unit); | ||
275 | netdev_boot_setup_check(dev); | ||
276 | } | ||
277 | |||
278 | err = setup_card(dev); | ||
279 | if (err) | ||
280 | goto out; | ||
281 | |||
282 | return dev; | ||
283 | |||
284 | out: | ||
285 | free_netdev(dev); | ||
286 | return ERR_PTR(err); | ||
287 | } | ||
288 | |||
289 | /* | 266 | /* |
290 | * Reads MAC address from adapter RAM, which should've read it from | 267 | * Reads MAC address from adapter RAM, which should've read it from |
291 | * the onboard ROM. | 268 | * the onboard ROM. |
@@ -352,8 +329,6 @@ static int proteon_open(struct net_device *dev) | |||
352 | return tms380tr_open(dev); | 329 | return tms380tr_open(dev); |
353 | } | 330 | } |
354 | 331 | ||
355 | #ifdef MODULE | ||
356 | |||
357 | #define ISATR_MAX_ADAPTERS 3 | 332 | #define ISATR_MAX_ADAPTERS 3 |
358 | 333 | ||
359 | static int io[ISATR_MAX_ADAPTERS]; | 334 | static int io[ISATR_MAX_ADAPTERS]; |
@@ -366,13 +341,23 @@ module_param_array(io, int, NULL, 0); | |||
366 | module_param_array(irq, int, NULL, 0); | 341 | module_param_array(irq, int, NULL, 0); |
367 | module_param_array(dma, int, NULL, 0); | 342 | module_param_array(dma, int, NULL, 0); |
368 | 343 | ||
369 | static struct net_device *proteon_dev[ISATR_MAX_ADAPTERS]; | 344 | static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS]; |
345 | |||
346 | static struct device_driver proteon_driver = { | ||
347 | .name = "proteon", | ||
348 | .bus = &platform_bus_type, | ||
349 | }; | ||
370 | 350 | ||
371 | int init_module(void) | 351 | static int __init proteon_init(void) |
372 | { | 352 | { |
373 | struct net_device *dev; | 353 | struct net_device *dev; |
354 | struct platform_device *pdev; | ||
374 | int i, num = 0, err = 0; | 355 | int i, num = 0, err = 0; |
375 | 356 | ||
357 | err = driver_register(&proteon_driver); | ||
358 | if (err) | ||
359 | return err; | ||
360 | |||
376 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { | 361 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { |
377 | dev = alloc_trdev(sizeof(struct net_local)); | 362 | dev = alloc_trdev(sizeof(struct net_local)); |
378 | if (!dev) | 363 | if (!dev) |
@@ -381,11 +366,15 @@ int init_module(void) | |||
381 | dev->base_addr = io[i]; | 366 | dev->base_addr = io[i]; |
382 | dev->irq = irq[i]; | 367 | dev->irq = irq[i]; |
383 | dev->dma = dma[i]; | 368 | dev->dma = dma[i]; |
384 | err = setup_card(dev); | 369 | pdev = platform_device_register_simple("proteon", |
370 | i, NULL, 0); | ||
371 | err = setup_card(dev, &pdev->dev); | ||
385 | if (!err) { | 372 | if (!err) { |
386 | proteon_dev[i] = dev; | 373 | proteon_dev[i] = pdev; |
374 | dev_set_drvdata(&pdev->dev, dev); | ||
387 | ++num; | 375 | ++num; |
388 | } else { | 376 | } else { |
377 | platform_device_unregister(pdev); | ||
389 | free_netdev(dev); | 378 | free_netdev(dev); |
390 | } | 379 | } |
391 | } | 380 | } |
@@ -399,23 +388,28 @@ int init_module(void) | |||
399 | return (0); | 388 | return (0); |
400 | } | 389 | } |
401 | 390 | ||
402 | void cleanup_module(void) | 391 | static void __exit proteon_cleanup(void) |
403 | { | 392 | { |
393 | struct net_device *dev; | ||
404 | int i; | 394 | int i; |
405 | 395 | ||
406 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { | 396 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { |
407 | struct net_device *dev = proteon_dev[i]; | 397 | struct platform_device *pdev = proteon_dev[i]; |
408 | 398 | ||
409 | if (!dev) | 399 | if (!pdev) |
410 | continue; | 400 | continue; |
411 | 401 | dev = dev_get_drvdata(&pdev->dev); | |
412 | unregister_netdev(dev); | 402 | unregister_netdev(dev); |
413 | release_region(dev->base_addr, PROTEON_IO_EXTENT); | 403 | release_region(dev->base_addr, PROTEON_IO_EXTENT); |
414 | free_irq(dev->irq, dev); | 404 | free_irq(dev->irq, dev); |
415 | free_dma(dev->dma); | 405 | free_dma(dev->dma); |
416 | tmsdev_term(dev); | 406 | tmsdev_term(dev); |
417 | free_netdev(dev); | 407 | free_netdev(dev); |
408 | dev_set_drvdata(&pdev->dev, NULL); | ||
409 | platform_device_unregister(pdev); | ||
418 | } | 410 | } |
411 | driver_unregister(&proteon_driver); | ||
419 | } | 412 | } |
420 | #endif /* MODULE */ | ||
421 | 413 | ||
414 | module_init(proteon_init); | ||
415 | module_exit(proteon_cleanup); | ||
diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c index f26796e2d0e5..03f061941d77 100644 --- a/drivers/net/tokenring/skisa.c +++ b/drivers/net/tokenring/skisa.c | |||
@@ -68,8 +68,7 @@ static int dmalist[] __initdata = { | |||
68 | }; | 68 | }; |
69 | 69 | ||
70 | static char isa_cardname[] = "SK NET TR 4/16 ISA\0"; | 70 | static char isa_cardname[] = "SK NET TR 4/16 ISA\0"; |
71 | 71 | static u64 dma_mask = ISA_MAX_ADDRESS; | |
72 | struct net_device *sk_isa_probe(int unit); | ||
73 | static int sk_isa_open(struct net_device *dev); | 72 | static int sk_isa_open(struct net_device *dev); |
74 | static void sk_isa_read_eeprom(struct net_device *dev); | 73 | static void sk_isa_read_eeprom(struct net_device *dev); |
75 | static unsigned short sk_isa_setnselout_pins(struct net_device *dev); | 74 | static unsigned short sk_isa_setnselout_pins(struct net_device *dev); |
@@ -133,7 +132,7 @@ static int __init sk_isa_probe1(struct net_device *dev, int ioaddr) | |||
133 | return 0; | 132 | return 0; |
134 | } | 133 | } |
135 | 134 | ||
136 | static int __init setup_card(struct net_device *dev) | 135 | static int __init setup_card(struct net_device *dev, struct device *pdev) |
137 | { | 136 | { |
138 | struct net_local *tp; | 137 | struct net_local *tp; |
139 | static int versionprinted; | 138 | static int versionprinted; |
@@ -154,7 +153,7 @@ static int __init setup_card(struct net_device *dev) | |||
154 | } | 153 | } |
155 | } | 154 | } |
156 | if (err) | 155 | if (err) |
157 | goto out4; | 156 | goto out5; |
158 | 157 | ||
159 | /* At this point we have found a valid card. */ | 158 | /* At this point we have found a valid card. */ |
160 | 159 | ||
@@ -162,14 +161,15 @@ static int __init setup_card(struct net_device *dev) | |||
162 | printk(KERN_DEBUG "%s", version); | 161 | printk(KERN_DEBUG "%s", version); |
163 | 162 | ||
164 | err = -EIO; | 163 | err = -EIO; |
165 | if (tmsdev_init(dev, ISA_MAX_ADDRESS, NULL)) | 164 | pdev->dma_mask = &dma_mask; |
165 | if (tmsdev_init(dev, ISA_MAX_ADDRESS, pdev)) | ||
166 | goto out4; | 166 | goto out4; |
167 | 167 | ||
168 | dev->base_addr &= ~3; | 168 | dev->base_addr &= ~3; |
169 | 169 | ||
170 | sk_isa_read_eeprom(dev); | 170 | sk_isa_read_eeprom(dev); |
171 | 171 | ||
172 | printk(KERN_DEBUG "%s: Ring Station Address: ", dev->name); | 172 | printk(KERN_DEBUG "skisa.c: Ring Station Address: "); |
173 | printk("%2.2x", dev->dev_addr[0]); | 173 | printk("%2.2x", dev->dev_addr[0]); |
174 | for (j = 1; j < 6; j++) | 174 | for (j = 1; j < 6; j++) |
175 | printk(":%2.2x", dev->dev_addr[j]); | 175 | printk(":%2.2x", dev->dev_addr[j]); |
@@ -202,7 +202,7 @@ static int __init setup_card(struct net_device *dev) | |||
202 | 202 | ||
203 | if(irqlist[j] == 0) | 203 | if(irqlist[j] == 0) |
204 | { | 204 | { |
205 | printk(KERN_INFO "%s: AutoSelect no IRQ available\n", dev->name); | 205 | printk(KERN_INFO "skisa.c: AutoSelect no IRQ available\n"); |
206 | goto out3; | 206 | goto out3; |
207 | } | 207 | } |
208 | } | 208 | } |
@@ -213,15 +213,15 @@ static int __init setup_card(struct net_device *dev) | |||
213 | break; | 213 | break; |
214 | if (irqlist[j] == 0) | 214 | if (irqlist[j] == 0) |
215 | { | 215 | { |
216 | printk(KERN_INFO "%s: Illegal IRQ %d specified\n", | 216 | printk(KERN_INFO "skisa.c: Illegal IRQ %d specified\n", |
217 | dev->name, dev->irq); | 217 | dev->irq); |
218 | goto out3; | 218 | goto out3; |
219 | } | 219 | } |
220 | if (request_irq(dev->irq, tms380tr_interrupt, 0, | 220 | if (request_irq(dev->irq, tms380tr_interrupt, 0, |
221 | isa_cardname, dev)) | 221 | isa_cardname, dev)) |
222 | { | 222 | { |
223 | printk(KERN_INFO "%s: Selected IRQ %d not available\n", | 223 | printk(KERN_INFO "skisa.c: Selected IRQ %d not available\n", |
224 | dev->name, dev->irq); | 224 | dev->irq); |
225 | goto out3; | 225 | goto out3; |
226 | } | 226 | } |
227 | } | 227 | } |
@@ -237,7 +237,7 @@ static int __init setup_card(struct net_device *dev) | |||
237 | 237 | ||
238 | if(dmalist[j] == 0) | 238 | if(dmalist[j] == 0) |
239 | { | 239 | { |
240 | printk(KERN_INFO "%s: AutoSelect no DMA available\n", dev->name); | 240 | printk(KERN_INFO "skisa.c: AutoSelect no DMA available\n"); |
241 | goto out2; | 241 | goto out2; |
242 | } | 242 | } |
243 | } | 243 | } |
@@ -248,25 +248,25 @@ static int __init setup_card(struct net_device *dev) | |||
248 | break; | 248 | break; |
249 | if (dmalist[j] == 0) | 249 | if (dmalist[j] == 0) |
250 | { | 250 | { |
251 | printk(KERN_INFO "%s: Illegal DMA %d specified\n", | 251 | printk(KERN_INFO "skisa.c: Illegal DMA %d specified\n", |
252 | dev->name, dev->dma); | 252 | dev->dma); |
253 | goto out2; | 253 | goto out2; |
254 | } | 254 | } |
255 | if (request_dma(dev->dma, isa_cardname)) | 255 | if (request_dma(dev->dma, isa_cardname)) |
256 | { | 256 | { |
257 | printk(KERN_INFO "%s: Selected DMA %d not available\n", | 257 | printk(KERN_INFO "skisa.c: Selected DMA %d not available\n", |
258 | dev->name, dev->dma); | 258 | dev->dma); |
259 | goto out2; | 259 | goto out2; |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n", | ||
264 | dev->name, dev->base_addr, dev->irq, dev->dma); | ||
265 | |||
266 | err = register_netdev(dev); | 263 | err = register_netdev(dev); |
267 | if (err) | 264 | if (err) |
268 | goto out; | 265 | goto out; |
269 | 266 | ||
267 | printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n", | ||
268 | dev->name, dev->base_addr, dev->irq, dev->dma); | ||
269 | |||
270 | return 0; | 270 | return 0; |
271 | out: | 271 | out: |
272 | free_dma(dev->dma); | 272 | free_dma(dev->dma); |
@@ -275,33 +275,11 @@ out2: | |||
275 | out3: | 275 | out3: |
276 | tmsdev_term(dev); | 276 | tmsdev_term(dev); |
277 | out4: | 277 | out4: |
278 | release_region(dev->base_addr, SK_ISA_IO_EXTENT); | 278 | release_region(dev->base_addr, SK_ISA_IO_EXTENT); |
279 | out5: | ||
279 | return err; | 280 | return err; |
280 | } | 281 | } |
281 | 282 | ||
282 | struct net_device * __init sk_isa_probe(int unit) | ||
283 | { | ||
284 | struct net_device *dev = alloc_trdev(sizeof(struct net_local)); | ||
285 | int err = 0; | ||
286 | |||
287 | if (!dev) | ||
288 | return ERR_PTR(-ENOMEM); | ||
289 | |||
290 | if (unit >= 0) { | ||
291 | sprintf(dev->name, "tr%d", unit); | ||
292 | netdev_boot_setup_check(dev); | ||
293 | } | ||
294 | |||
295 | err = setup_card(dev); | ||
296 | if (err) | ||
297 | goto out; | ||
298 | |||
299 | return dev; | ||
300 | out: | ||
301 | free_netdev(dev); | ||
302 | return ERR_PTR(err); | ||
303 | } | ||
304 | |||
305 | /* | 283 | /* |
306 | * Reads MAC address from adapter RAM, which should've read it from | 284 | * Reads MAC address from adapter RAM, which should've read it from |
307 | * the onboard ROM. | 285 | * the onboard ROM. |
@@ -361,8 +339,6 @@ static int sk_isa_open(struct net_device *dev) | |||
361 | return tms380tr_open(dev); | 339 | return tms380tr_open(dev); |
362 | } | 340 | } |
363 | 341 | ||
364 | #ifdef MODULE | ||
365 | |||
366 | #define ISATR_MAX_ADAPTERS 3 | 342 | #define ISATR_MAX_ADAPTERS 3 |
367 | 343 | ||
368 | static int io[ISATR_MAX_ADAPTERS]; | 344 | static int io[ISATR_MAX_ADAPTERS]; |
@@ -375,13 +351,23 @@ module_param_array(io, int, NULL, 0); | |||
375 | module_param_array(irq, int, NULL, 0); | 351 | module_param_array(irq, int, NULL, 0); |
376 | module_param_array(dma, int, NULL, 0); | 352 | module_param_array(dma, int, NULL, 0); |
377 | 353 | ||
378 | static struct net_device *sk_isa_dev[ISATR_MAX_ADAPTERS]; | 354 | static struct platform_device *sk_isa_dev[ISATR_MAX_ADAPTERS]; |
379 | 355 | ||
380 | int init_module(void) | 356 | static struct device_driver sk_isa_driver = { |
357 | .name = "skisa", | ||
358 | .bus = &platform_bus_type, | ||
359 | }; | ||
360 | |||
361 | static int __init sk_isa_init(void) | ||
381 | { | 362 | { |
382 | struct net_device *dev; | 363 | struct net_device *dev; |
364 | struct platform_device *pdev; | ||
383 | int i, num = 0, err = 0; | 365 | int i, num = 0, err = 0; |
384 | 366 | ||
367 | err = driver_register(&sk_isa_driver); | ||
368 | if (err) | ||
369 | return err; | ||
370 | |||
385 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { | 371 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { |
386 | dev = alloc_trdev(sizeof(struct net_local)); | 372 | dev = alloc_trdev(sizeof(struct net_local)); |
387 | if (!dev) | 373 | if (!dev) |
@@ -390,12 +376,15 @@ int init_module(void) | |||
390 | dev->base_addr = io[i]; | 376 | dev->base_addr = io[i]; |
391 | dev->irq = irq[i]; | 377 | dev->irq = irq[i]; |
392 | dev->dma = dma[i]; | 378 | dev->dma = dma[i]; |
393 | err = setup_card(dev); | 379 | pdev = platform_device_register_simple("skisa", |
394 | 380 | i, NULL, 0); | |
381 | err = setup_card(dev, &pdev->dev); | ||
395 | if (!err) { | 382 | if (!err) { |
396 | sk_isa_dev[i] = dev; | 383 | sk_isa_dev[i] = pdev; |
384 | dev_set_drvdata(&sk_isa_dev[i]->dev, dev); | ||
397 | ++num; | 385 | ++num; |
398 | } else { | 386 | } else { |
387 | platform_device_unregister(pdev); | ||
399 | free_netdev(dev); | 388 | free_netdev(dev); |
400 | } | 389 | } |
401 | } | 390 | } |
@@ -409,23 +398,28 @@ int init_module(void) | |||
409 | return (0); | 398 | return (0); |
410 | } | 399 | } |
411 | 400 | ||
412 | void cleanup_module(void) | 401 | static void __exit sk_isa_cleanup(void) |
413 | { | 402 | { |
403 | struct net_device *dev; | ||
414 | int i; | 404 | int i; |
415 | 405 | ||
416 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { | 406 | for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { |
417 | struct net_device *dev = sk_isa_dev[i]; | 407 | struct platform_device *pdev = sk_isa_dev[i]; |
418 | 408 | ||
419 | if (!dev) | 409 | if (!pdev) |
420 | continue; | 410 | continue; |
421 | 411 | dev = dev_get_drvdata(&pdev->dev); | |
422 | unregister_netdev(dev); | 412 | unregister_netdev(dev); |
423 | release_region(dev->base_addr, SK_ISA_IO_EXTENT); | 413 | release_region(dev->base_addr, SK_ISA_IO_EXTENT); |
424 | free_irq(dev->irq, dev); | 414 | free_irq(dev->irq, dev); |
425 | free_dma(dev->dma); | 415 | free_dma(dev->dma); |
426 | tmsdev_term(dev); | 416 | tmsdev_term(dev); |
427 | free_netdev(dev); | 417 | free_netdev(dev); |
418 | dev_set_drvdata(&pdev->dev, NULL); | ||
419 | platform_device_unregister(pdev); | ||
428 | } | 420 | } |
421 | driver_unregister(&sk_isa_driver); | ||
429 | } | 422 | } |
430 | #endif /* MODULE */ | ||
431 | 423 | ||
424 | module_init(sk_isa_init); | ||
425 | module_exit(sk_isa_cleanup); | ||
diff --git a/drivers/net/tokenring/tms380tr.c b/drivers/net/tokenring/tms380tr.c index 5e0b0ce98ed7..9a543fe2d0e6 100644 --- a/drivers/net/tokenring/tms380tr.c +++ b/drivers/net/tokenring/tms380tr.c | |||
@@ -62,6 +62,7 @@ | |||
62 | * normal operation. | 62 | * normal operation. |
63 | * 30-Dec-02 JF Removed incorrect __init from | 63 | * 30-Dec-02 JF Removed incorrect __init from |
64 | * tms380tr_init_card. | 64 | * tms380tr_init_card. |
65 | * 22-Jul-05 JF Converted to dma-mapping. | ||
65 | * | 66 | * |
66 | * To do: | 67 | * To do: |
67 | * 1. Multi/Broadcast packet handling (this may have fixed itself) | 68 | * 1. Multi/Broadcast packet handling (this may have fixed itself) |
@@ -89,7 +90,7 @@ static const char version[] = "tms380tr.c: v1.10 30/12/2002 by Christoph Goos, A | |||
89 | #include <linux/time.h> | 90 | #include <linux/time.h> |
90 | #include <linux/errno.h> | 91 | #include <linux/errno.h> |
91 | #include <linux/init.h> | 92 | #include <linux/init.h> |
92 | #include <linux/pci.h> | 93 | #include <linux/dma-mapping.h> |
93 | #include <linux/delay.h> | 94 | #include <linux/delay.h> |
94 | #include <linux/netdevice.h> | 95 | #include <linux/netdevice.h> |
95 | #include <linux/etherdevice.h> | 96 | #include <linux/etherdevice.h> |
@@ -114,8 +115,6 @@ static const char version[] = "tms380tr.c: v1.10 30/12/2002 by Christoph Goos, A | |||
114 | #endif | 115 | #endif |
115 | static unsigned int tms380tr_debug = TMS380TR_DEBUG; | 116 | static unsigned int tms380tr_debug = TMS380TR_DEBUG; |
116 | 117 | ||
117 | static struct device tms_device; | ||
118 | |||
119 | /* Index to functions, as function prototypes. | 118 | /* Index to functions, as function prototypes. |
120 | * Alphabetical by function name. | 119 | * Alphabetical by function name. |
121 | */ | 120 | */ |
@@ -434,7 +433,7 @@ static void tms380tr_init_net_local(struct net_device *dev) | |||
434 | skb_put(tp->Rpl[i].Skb, tp->MaxPacketSize); | 433 | skb_put(tp->Rpl[i].Skb, tp->MaxPacketSize); |
435 | 434 | ||
436 | /* data unreachable for DMA ? then use local buffer */ | 435 | /* data unreachable for DMA ? then use local buffer */ |
437 | dmabuf = pci_map_single(tp->pdev, tp->Rpl[i].Skb->data, tp->MaxPacketSize, PCI_DMA_FROMDEVICE); | 436 | dmabuf = dma_map_single(tp->pdev, tp->Rpl[i].Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE); |
438 | if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit)) | 437 | if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit)) |
439 | { | 438 | { |
440 | tp->Rpl[i].SkbStat = SKB_DATA_COPY; | 439 | tp->Rpl[i].SkbStat = SKB_DATA_COPY; |
@@ -638,10 +637,10 @@ static int tms380tr_hardware_send_packet(struct sk_buff *skb, struct net_device | |||
638 | /* Is buffer reachable for Busmaster-DMA? */ | 637 | /* Is buffer reachable for Busmaster-DMA? */ |
639 | 638 | ||
640 | length = skb->len; | 639 | length = skb->len; |
641 | dmabuf = pci_map_single(tp->pdev, skb->data, length, PCI_DMA_TODEVICE); | 640 | dmabuf = dma_map_single(tp->pdev, skb->data, length, DMA_TO_DEVICE); |
642 | if(tp->dmalimit && (dmabuf + length > tp->dmalimit)) { | 641 | if(tp->dmalimit && (dmabuf + length > tp->dmalimit)) { |
643 | /* Copy frame to local buffer */ | 642 | /* Copy frame to local buffer */ |
644 | pci_unmap_single(tp->pdev, dmabuf, length, PCI_DMA_TODEVICE); | 643 | dma_unmap_single(tp->pdev, dmabuf, length, DMA_TO_DEVICE); |
645 | dmabuf = 0; | 644 | dmabuf = 0; |
646 | i = tp->TplFree->TPLIndex; | 645 | i = tp->TplFree->TPLIndex; |
647 | buf = tp->LocalTxBuffers[i]; | 646 | buf = tp->LocalTxBuffers[i]; |
@@ -1284,9 +1283,7 @@ static int tms380tr_reset_adapter(struct net_device *dev) | |||
1284 | unsigned short count, c, count2; | 1283 | unsigned short count, c, count2; |
1285 | const struct firmware *fw_entry = NULL; | 1284 | const struct firmware *fw_entry = NULL; |
1286 | 1285 | ||
1287 | strncpy(tms_device.bus_id,dev->name, BUS_ID_SIZE); | 1286 | if (request_firmware(&fw_entry, "tms380tr.bin", tp->pdev) != 0) { |
1288 | |||
1289 | if (request_firmware(&fw_entry, "tms380tr.bin", &tms_device) != 0) { | ||
1290 | printk(KERN_ALERT "%s: firmware %s is missing, cannot start.\n", | 1287 | printk(KERN_ALERT "%s: firmware %s is missing, cannot start.\n", |
1291 | dev->name, "tms380tr.bin"); | 1288 | dev->name, "tms380tr.bin"); |
1292 | return (-1); | 1289 | return (-1); |
@@ -2021,7 +2018,7 @@ static void tms380tr_cancel_tx_queue(struct net_local* tp) | |||
2021 | 2018 | ||
2022 | printk(KERN_INFO "Cancel tx (%08lXh).\n", (unsigned long)tpl); | 2019 | printk(KERN_INFO "Cancel tx (%08lXh).\n", (unsigned long)tpl); |
2023 | if (tpl->DMABuff) | 2020 | if (tpl->DMABuff) |
2024 | pci_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, PCI_DMA_TODEVICE); | 2021 | dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE); |
2025 | dev_kfree_skb_any(tpl->Skb); | 2022 | dev_kfree_skb_any(tpl->Skb); |
2026 | } | 2023 | } |
2027 | 2024 | ||
@@ -2090,7 +2087,7 @@ static void tms380tr_tx_status_irq(struct net_device *dev) | |||
2090 | 2087 | ||
2091 | tp->MacStat.tx_packets++; | 2088 | tp->MacStat.tx_packets++; |
2092 | if (tpl->DMABuff) | 2089 | if (tpl->DMABuff) |
2093 | pci_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, PCI_DMA_TODEVICE); | 2090 | dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE); |
2094 | dev_kfree_skb_irq(tpl->Skb); | 2091 | dev_kfree_skb_irq(tpl->Skb); |
2095 | tpl->BusyFlag = 0; /* "free" TPL */ | 2092 | tpl->BusyFlag = 0; /* "free" TPL */ |
2096 | } | 2093 | } |
@@ -2209,7 +2206,7 @@ static void tms380tr_rcv_status_irq(struct net_device *dev) | |||
2209 | tp->MacStat.rx_errors++; | 2206 | tp->MacStat.rx_errors++; |
2210 | } | 2207 | } |
2211 | if (rpl->DMABuff) | 2208 | if (rpl->DMABuff) |
2212 | pci_unmap_single(tp->pdev, rpl->DMABuff, tp->MaxPacketSize, PCI_DMA_TODEVICE); | 2209 | dma_unmap_single(tp->pdev, rpl->DMABuff, tp->MaxPacketSize, DMA_TO_DEVICE); |
2213 | rpl->DMABuff = 0; | 2210 | rpl->DMABuff = 0; |
2214 | 2211 | ||
2215 | /* Allocate new skb for rpl */ | 2212 | /* Allocate new skb for rpl */ |
@@ -2227,7 +2224,7 @@ static void tms380tr_rcv_status_irq(struct net_device *dev) | |||
2227 | skb_put(rpl->Skb, tp->MaxPacketSize); | 2224 | skb_put(rpl->Skb, tp->MaxPacketSize); |
2228 | 2225 | ||
2229 | /* Data unreachable for DMA ? then use local buffer */ | 2226 | /* Data unreachable for DMA ? then use local buffer */ |
2230 | dmabuf = pci_map_single(tp->pdev, rpl->Skb->data, tp->MaxPacketSize, PCI_DMA_FROMDEVICE); | 2227 | dmabuf = dma_map_single(tp->pdev, rpl->Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE); |
2231 | if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit)) | 2228 | if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit)) |
2232 | { | 2229 | { |
2233 | rpl->SkbStat = SKB_DATA_COPY; | 2230 | rpl->SkbStat = SKB_DATA_COPY; |
@@ -2332,12 +2329,12 @@ void tmsdev_term(struct net_device *dev) | |||
2332 | struct net_local *tp; | 2329 | struct net_local *tp; |
2333 | 2330 | ||
2334 | tp = netdev_priv(dev); | 2331 | tp = netdev_priv(dev); |
2335 | pci_unmap_single(tp->pdev, tp->dmabuffer, sizeof(struct net_local), | 2332 | dma_unmap_single(tp->pdev, tp->dmabuffer, sizeof(struct net_local), |
2336 | PCI_DMA_BIDIRECTIONAL); | 2333 | DMA_BIDIRECTIONAL); |
2337 | } | 2334 | } |
2338 | 2335 | ||
2339 | int tmsdev_init(struct net_device *dev, unsigned long dmalimit, | 2336 | int tmsdev_init(struct net_device *dev, unsigned long dmalimit, |
2340 | struct pci_dev *pdev) | 2337 | struct device *pdev) |
2341 | { | 2338 | { |
2342 | struct net_local *tms_local; | 2339 | struct net_local *tms_local; |
2343 | 2340 | ||
@@ -2346,8 +2343,8 @@ int tmsdev_init(struct net_device *dev, unsigned long dmalimit, | |||
2346 | init_waitqueue_head(&tms_local->wait_for_tok_int); | 2343 | init_waitqueue_head(&tms_local->wait_for_tok_int); |
2347 | tms_local->dmalimit = dmalimit; | 2344 | tms_local->dmalimit = dmalimit; |
2348 | tms_local->pdev = pdev; | 2345 | tms_local->pdev = pdev; |
2349 | tms_local->dmabuffer = pci_map_single(pdev, (void *)tms_local, | 2346 | tms_local->dmabuffer = dma_map_single(pdev, (void *)tms_local, |
2350 | sizeof(struct net_local), PCI_DMA_BIDIRECTIONAL); | 2347 | sizeof(struct net_local), DMA_BIDIRECTIONAL); |
2351 | if (tms_local->dmabuffer + sizeof(struct net_local) > dmalimit) | 2348 | if (tms_local->dmabuffer + sizeof(struct net_local) > dmalimit) |
2352 | { | 2349 | { |
2353 | printk(KERN_INFO "%s: Memory not accessible for DMA\n", | 2350 | printk(KERN_INFO "%s: Memory not accessible for DMA\n", |
@@ -2370,8 +2367,6 @@ int tmsdev_init(struct net_device *dev, unsigned long dmalimit, | |||
2370 | return 0; | 2367 | return 0; |
2371 | } | 2368 | } |
2372 | 2369 | ||
2373 | #ifdef MODULE | ||
2374 | |||
2375 | EXPORT_SYMBOL(tms380tr_open); | 2370 | EXPORT_SYMBOL(tms380tr_open); |
2376 | EXPORT_SYMBOL(tms380tr_close); | 2371 | EXPORT_SYMBOL(tms380tr_close); |
2377 | EXPORT_SYMBOL(tms380tr_interrupt); | 2372 | EXPORT_SYMBOL(tms380tr_interrupt); |
@@ -2379,6 +2374,8 @@ EXPORT_SYMBOL(tmsdev_init); | |||
2379 | EXPORT_SYMBOL(tmsdev_term); | 2374 | EXPORT_SYMBOL(tmsdev_term); |
2380 | EXPORT_SYMBOL(tms380tr_wait); | 2375 | EXPORT_SYMBOL(tms380tr_wait); |
2381 | 2376 | ||
2377 | #ifdef MODULE | ||
2378 | |||
2382 | static struct module *TMS380_module = NULL; | 2379 | static struct module *TMS380_module = NULL; |
2383 | 2380 | ||
2384 | int init_module(void) | 2381 | int init_module(void) |
diff --git a/drivers/net/tokenring/tms380tr.h b/drivers/net/tokenring/tms380tr.h index f2c5ba0f37a5..077f568d89d1 100644 --- a/drivers/net/tokenring/tms380tr.h +++ b/drivers/net/tokenring/tms380tr.h | |||
@@ -18,7 +18,7 @@ int tms380tr_open(struct net_device *dev); | |||
18 | int tms380tr_close(struct net_device *dev); | 18 | int tms380tr_close(struct net_device *dev); |
19 | irqreturn_t tms380tr_interrupt(int irq, void *dev_id, struct pt_regs *regs); | 19 | irqreturn_t tms380tr_interrupt(int irq, void *dev_id, struct pt_regs *regs); |
20 | int tmsdev_init(struct net_device *dev, unsigned long dmalimit, | 20 | int tmsdev_init(struct net_device *dev, unsigned long dmalimit, |
21 | struct pci_dev *pdev); | 21 | struct device *pdev); |
22 | void tmsdev_term(struct net_device *dev); | 22 | void tmsdev_term(struct net_device *dev); |
23 | void tms380tr_wait(unsigned long time); | 23 | void tms380tr_wait(unsigned long time); |
24 | 24 | ||
@@ -719,7 +719,7 @@ struct s_TPL { /* Transmit Parameter List (align on even word boundaries) */ | |||
719 | struct sk_buff *Skb; | 719 | struct sk_buff *Skb; |
720 | unsigned char TPLIndex; | 720 | unsigned char TPLIndex; |
721 | volatile unsigned char BusyFlag;/* Flag: TPL busy? */ | 721 | volatile unsigned char BusyFlag;/* Flag: TPL busy? */ |
722 | dma_addr_t DMABuff; /* DMA IO bus address from pci_map */ | 722 | dma_addr_t DMABuff; /* DMA IO bus address from dma_map */ |
723 | }; | 723 | }; |
724 | 724 | ||
725 | /* ---------------------Receive Functions-------------------------------* | 725 | /* ---------------------Receive Functions-------------------------------* |
@@ -1060,7 +1060,7 @@ struct s_RPL { /* Receive Parameter List */ | |||
1060 | struct sk_buff *Skb; | 1060 | struct sk_buff *Skb; |
1061 | SKB_STAT SkbStat; | 1061 | SKB_STAT SkbStat; |
1062 | int RPLIndex; | 1062 | int RPLIndex; |
1063 | dma_addr_t DMABuff; /* DMA IO bus address from pci_map */ | 1063 | dma_addr_t DMABuff; /* DMA IO bus address from dma_map */ |
1064 | }; | 1064 | }; |
1065 | 1065 | ||
1066 | /* Information that need to be kept for each board. */ | 1066 | /* Information that need to be kept for each board. */ |
@@ -1091,7 +1091,7 @@ typedef struct net_local { | |||
1091 | RPL *RplTail; | 1091 | RPL *RplTail; |
1092 | unsigned char LocalRxBuffers[RPL_NUM][DEFAULT_PACKET_SIZE]; | 1092 | unsigned char LocalRxBuffers[RPL_NUM][DEFAULT_PACKET_SIZE]; |
1093 | 1093 | ||
1094 | struct pci_dev *pdev; | 1094 | struct device *pdev; |
1095 | int DataRate; | 1095 | int DataRate; |
1096 | unsigned char ScbInUse; | 1096 | unsigned char ScbInUse; |
1097 | unsigned short CMDqueue; | 1097 | unsigned short CMDqueue; |
diff --git a/drivers/net/tokenring/tmspci.c b/drivers/net/tokenring/tmspci.c index 2e18c0a46482..0014aef5c744 100644 --- a/drivers/net/tokenring/tmspci.c +++ b/drivers/net/tokenring/tmspci.c | |||
@@ -100,7 +100,7 @@ static int __devinit tms_pci_attach(struct pci_dev *pdev, const struct pci_devic | |||
100 | unsigned int pci_irq_line; | 100 | unsigned int pci_irq_line; |
101 | unsigned long pci_ioaddr; | 101 | unsigned long pci_ioaddr; |
102 | struct card_info *cardinfo = &card_info_table[ent->driver_data]; | 102 | struct card_info *cardinfo = &card_info_table[ent->driver_data]; |
103 | 103 | ||
104 | if (versionprinted++ == 0) | 104 | if (versionprinted++ == 0) |
105 | printk("%s", version); | 105 | printk("%s", version); |
106 | 106 | ||
@@ -143,7 +143,7 @@ static int __devinit tms_pci_attach(struct pci_dev *pdev, const struct pci_devic | |||
143 | printk(":%2.2x", dev->dev_addr[i]); | 143 | printk(":%2.2x", dev->dev_addr[i]); |
144 | printk("\n"); | 144 | printk("\n"); |
145 | 145 | ||
146 | ret = tmsdev_init(dev, PCI_MAX_ADDRESS, pdev); | 146 | ret = tmsdev_init(dev, PCI_MAX_ADDRESS, &pdev->dev); |
147 | if (ret) { | 147 | if (ret) { |
148 | printk("%s: unable to get memory for dev->priv.\n", dev->name); | 148 | printk("%s: unable to get memory for dev->priv.\n", dev->name); |
149 | goto err_out_irq; | 149 | goto err_out_irq; |
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c index aabcdc2be05e..9c2d07cde010 100644 --- a/drivers/net/wireless/orinoco.c +++ b/drivers/net/wireless/orinoco.c | |||
@@ -4322,36 +4322,36 @@ static const struct iw_priv_args orinoco_privtab[] = { | |||
4322 | */ | 4322 | */ |
4323 | 4323 | ||
4324 | static const iw_handler orinoco_handler[] = { | 4324 | static const iw_handler orinoco_handler[] = { |
4325 | [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) orinoco_ioctl_commit, | 4325 | [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit, |
4326 | [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getname, | 4326 | [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname, |
4327 | [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfreq, | 4327 | [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq, |
4328 | [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfreq, | 4328 | [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq, |
4329 | [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setmode, | 4329 | [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode, |
4330 | [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getmode, | 4330 | [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode, |
4331 | [SIOCSIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setsens, | 4331 | [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens, |
4332 | [SIOCGIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getsens, | 4332 | [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens, |
4333 | [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwrange, | 4333 | [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange, |
4334 | [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setspy, | 4334 | [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setspy, |
4335 | [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getspy, | 4335 | [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getspy, |
4336 | [SIOCSIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setwap, | 4336 | [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap, |
4337 | [SIOCGIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getwap, | 4337 | [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap, |
4338 | [SIOCSIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setscan, | 4338 | [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan, |
4339 | [SIOCGIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getscan, | 4339 | [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan, |
4340 | [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setessid, | 4340 | [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid, |
4341 | [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getessid, | 4341 | [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid, |
4342 | [SIOCSIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setnick, | 4342 | [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick, |
4343 | [SIOCGIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getnick, | 4343 | [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick, |
4344 | [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrate, | 4344 | [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate, |
4345 | [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrate, | 4345 | [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate, |
4346 | [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrts, | 4346 | [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts, |
4347 | [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrts, | 4347 | [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts, |
4348 | [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfrag, | 4348 | [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag, |
4349 | [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfrag, | 4349 | [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag, |
4350 | [SIOCGIWRETRY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getretry, | 4350 | [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry, |
4351 | [SIOCSIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_setiwencode, | 4351 | [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode, |
4352 | [SIOCGIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwencode, | 4352 | [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode, |
4353 | [SIOCSIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setpower, | 4353 | [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower, |
4354 | [SIOCGIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getpower, | 4354 | [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower, |
4355 | }; | 4355 | }; |
4356 | 4356 | ||
4357 | 4357 | ||
@@ -4359,15 +4359,15 @@ static const iw_handler orinoco_handler[] = { | |||
4359 | Added typecasting since we no longer use iwreq_data -- Moustafa | 4359 | Added typecasting since we no longer use iwreq_data -- Moustafa |
4360 | */ | 4360 | */ |
4361 | static const iw_handler orinoco_private_handler[] = { | 4361 | static const iw_handler orinoco_private_handler[] = { |
4362 | [0] (iw_handler) orinoco_ioctl_reset, | 4362 | [0] = (iw_handler) orinoco_ioctl_reset, |
4363 | [1] (iw_handler) orinoco_ioctl_reset, | 4363 | [1] = (iw_handler) orinoco_ioctl_reset, |
4364 | [2] (iw_handler) orinoco_ioctl_setport3, | 4364 | [2] = (iw_handler) orinoco_ioctl_setport3, |
4365 | [3] (iw_handler) orinoco_ioctl_getport3, | 4365 | [3] = (iw_handler) orinoco_ioctl_getport3, |
4366 | [4] (iw_handler) orinoco_ioctl_setpreamble, | 4366 | [4] = (iw_handler) orinoco_ioctl_setpreamble, |
4367 | [5] (iw_handler) orinoco_ioctl_getpreamble, | 4367 | [5] = (iw_handler) orinoco_ioctl_getpreamble, |
4368 | [6] (iw_handler) orinoco_ioctl_setibssport, | 4368 | [6] = (iw_handler) orinoco_ioctl_setibssport, |
4369 | [7] (iw_handler) orinoco_ioctl_getibssport, | 4369 | [7] = (iw_handler) orinoco_ioctl_getibssport, |
4370 | [9] (iw_handler) orinoco_ioctl_getrid, | 4370 | [9] = (iw_handler) orinoco_ioctl_getrid, |
4371 | }; | 4371 | }; |
4372 | 4372 | ||
4373 | static const struct iw_handler_def orinoco_handler_def = { | 4373 | static const struct iw_handler_def orinoco_handler_def = { |