aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/3c523.c2
-rw-r--r--drivers/net/7990.c4
-rw-r--r--drivers/net/8139too.c2
-rw-r--r--drivers/net/Kconfig23
-rw-r--r--drivers/net/Makefile1
-rw-r--r--drivers/net/a2065.c4
-rw-r--r--drivers/net/ariadne.c2
-rw-r--r--drivers/net/arm/ep93xx_eth.c2
-rw-r--r--drivers/net/au1000_eth.c4
-rw-r--r--drivers/net/bnx2.c503
-rw-r--r--drivers/net/bnx2.h66
-rw-r--r--drivers/net/dl2k.c4
-rw-r--r--drivers/net/dm9000.c17
-rw-r--r--drivers/net/dummy.c82
-rw-r--r--drivers/net/eepro100.c2
-rw-r--r--drivers/net/epic100.c2
-rw-r--r--drivers/net/fealnx.c4
-rw-r--r--drivers/net/fec.c2
-rw-r--r--drivers/net/hamachi.c4
-rw-r--r--drivers/net/ifb.c78
-rw-r--r--drivers/net/irda/kingsun-sir.c4
-rw-r--r--drivers/net/irda/vlsi_ir.c27
-rw-r--r--drivers/net/irda/vlsi_ir.h2
-rw-r--r--drivers/net/ixp2000/ixpdev.c2
-rw-r--r--drivers/net/lance.c4
-rw-r--r--drivers/net/natsemi.c4
-rw-r--r--drivers/net/ni52.c2
-rw-r--r--drivers/net/ni65.c4
-rw-r--r--drivers/net/pci-skeleton.c2
-rw-r--r--drivers/net/pcnet32.c4
-rw-r--r--drivers/net/pppol2tp.c2486
-rw-r--r--drivers/net/saa9730.c4
-rw-r--r--drivers/net/sgiseeq.c2
-rw-r--r--drivers/net/sis190.c2
-rw-r--r--drivers/net/starfire.c2
-rw-r--r--drivers/net/sun3_82586.c2
-rw-r--r--drivers/net/sun3lance.c5
-rw-r--r--drivers/net/sunbmac.c2
-rw-r--r--drivers/net/sundance.c2
-rw-r--r--drivers/net/sunlance.c4
-rw-r--r--drivers/net/sunqe.c4
-rw-r--r--drivers/net/tg3.c140
-rw-r--r--drivers/net/tg3.h9
-rw-r--r--drivers/net/tulip/interrupt.c8
-rw-r--r--drivers/net/tulip/winbond-840.c2
-rw-r--r--drivers/net/tulip/xircom_cb.c2
-rw-r--r--drivers/net/tulip/xircom_tulip_cb.c4
-rw-r--r--drivers/net/tun.c15
-rw-r--r--drivers/net/typhoon.c2
-rw-r--r--drivers/net/usb/catc.c2
-rw-r--r--drivers/net/usb/kaweth.c2
-rw-r--r--drivers/net/via-rhine.c4
-rw-r--r--drivers/net/wireless/wl3501_cs.c2
-rw-r--r--drivers/net/yellowfin.c2
54 files changed, 3301 insertions, 271 deletions
diff --git a/drivers/net/3c523.c b/drivers/net/3c523.c
index da1a22c13865..ab18343e58ef 100644
--- a/drivers/net/3c523.c
+++ b/drivers/net/3c523.c
@@ -990,7 +990,7 @@ static void elmc_rcv_int(struct net_device *dev)
990 if (skb != NULL) { 990 if (skb != NULL) {
991 skb_reserve(skb, 2); /* 16 byte alignment */ 991 skb_reserve(skb, 2); /* 16 byte alignment */
992 skb_put(skb,totlen); 992 skb_put(skb,totlen);
993 eth_copy_and_sum(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen,0); 993 skb_copy_to_linear_data(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen);
994 skb->protocol = eth_type_trans(skb, dev); 994 skb->protocol = eth_type_trans(skb, dev);
995 netif_rx(skb); 995 netif_rx(skb);
996 dev->last_rx = jiffies; 996 dev->last_rx = jiffies;
diff --git a/drivers/net/7990.c b/drivers/net/7990.c
index 0877fc372f4b..e89ace109a5d 100644
--- a/drivers/net/7990.c
+++ b/drivers/net/7990.c
@@ -333,9 +333,9 @@ static int lance_rx (struct net_device *dev)
333 333
334 skb_reserve (skb, 2); /* 16 byte align */ 334 skb_reserve (skb, 2); /* 16 byte align */
335 skb_put (skb, len); /* make room */ 335 skb_put (skb, len); /* make room */
336 eth_copy_and_sum(skb, 336 skb_copy_to_linear_data(skb,
337 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]), 337 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
338 len, 0); 338 len);
339 skb->protocol = eth_type_trans (skb, dev); 339 skb->protocol = eth_type_trans (skb, dev);
340 netif_rx (skb); 340 netif_rx (skb);
341 dev->last_rx = jiffies; 341 dev->last_rx = jiffies;
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index a844b1fe2dc4..21a6ccbf92e0 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -2017,7 +2017,7 @@ no_early_rx:
2017#if RX_BUF_IDX == 3 2017#if RX_BUF_IDX == 3
2018 wrap_copy(skb, rx_ring, ring_offset+4, pkt_size); 2018 wrap_copy(skb, rx_ring, ring_offset+4, pkt_size);
2019#else 2019#else
2020 eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0); 2020 skb_copy_to_linear_data (skb, &rx_ring[ring_offset + 4], pkt_size);
2021#endif 2021#endif
2022 skb_put (skb, pkt_size); 2022 skb_put (skb, pkt_size);
2023 2023
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index b941c74a06c4..ba314adf68b8 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -25,6 +25,14 @@ menuconfig NETDEVICES
25# that for each of the symbols. 25# that for each of the symbols.
26if NETDEVICES 26if NETDEVICES
27 27
28config NETDEVICES_MULTIQUEUE
29 bool "Netdevice multiple hardware queue support"
30 ---help---
31 Say Y here if you want to allow the network stack to use multiple
32 hardware TX queues on an ethernet device.
33
34 Most people will say N here.
35
28config IFB 36config IFB
29 tristate "Intermediate Functional Block support" 37 tristate "Intermediate Functional Block support"
30 depends on NET_CLS_ACT 38 depends on NET_CLS_ACT
@@ -877,7 +885,7 @@ config NET_NETX
877 885
878config DM9000 886config DM9000
879 tristate "DM9000 support" 887 tristate "DM9000 support"
880 depends on ARM || MIPS 888 depends on ARM || BLACKFIN || MIPS
881 select CRC32 889 select CRC32
882 select MII 890 select MII
883 ---help--- 891 ---help---
@@ -2784,6 +2792,19 @@ config PPPOATM
2784 which can lead to bad results if the ATM peer loses state and 2792 which can lead to bad results if the ATM peer loses state and
2785 changes its encapsulation unilaterally. 2793 changes its encapsulation unilaterally.
2786 2794
2795config PPPOL2TP
2796 tristate "PPP over L2TP (EXPERIMENTAL)"
2797 depends on EXPERIMENTAL && PPP
2798 help
2799 Support for PPP-over-L2TP socket family. L2TP is a protocol
2800 used by ISPs and enterprises to tunnel PPP traffic over UDP
2801 tunnels. L2TP is replacing PPTP for VPN uses.
2802
2803 This kernel component handles only L2TP data packets: a
2804 userland daemon handles L2TP the control protocol (tunnel
2805 and session setup). One such daemon is OpenL2TP
2806 (http://openl2tp.sourceforge.net/).
2807
2787config SLIP 2808config SLIP
2788 tristate "SLIP (serial line) support" 2809 tristate "SLIP (serial line) support"
2789 ---help--- 2810 ---help---
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 1bbcbedad04a..a2241e6e1457 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -121,6 +121,7 @@ obj-$(CONFIG_PPP_DEFLATE) += ppp_deflate.o
121obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o 121obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o
122obj-$(CONFIG_PPP_MPPE) += ppp_mppe.o 122obj-$(CONFIG_PPP_MPPE) += ppp_mppe.o
123obj-$(CONFIG_PPPOE) += pppox.o pppoe.o 123obj-$(CONFIG_PPPOE) += pppox.o pppoe.o
124obj-$(CONFIG_PPPOL2TP) += pppox.o pppol2tp.o
124 125
125obj-$(CONFIG_SLIP) += slip.o 126obj-$(CONFIG_SLIP) += slip.o
126obj-$(CONFIG_SLHC) += slhc.o 127obj-$(CONFIG_SLHC) += slhc.o
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c
index 81d5a374042a..a45de6975bfe 100644
--- a/drivers/net/a2065.c
+++ b/drivers/net/a2065.c
@@ -322,9 +322,9 @@ static int lance_rx (struct net_device *dev)
322 322
323 skb_reserve (skb, 2); /* 16 byte align */ 323 skb_reserve (skb, 2); /* 16 byte align */
324 skb_put (skb, len); /* make room */ 324 skb_put (skb, len); /* make room */
325 eth_copy_and_sum(skb, 325 skb_copy_to_linear_data(skb,
326 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]), 326 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
327 len, 0); 327 len);
328 skb->protocol = eth_type_trans (skb, dev); 328 skb->protocol = eth_type_trans (skb, dev);
329 netif_rx (skb); 329 netif_rx (skb);
330 dev->last_rx = jiffies; 330 dev->last_rx = jiffies;
diff --git a/drivers/net/ariadne.c b/drivers/net/ariadne.c
index a241ae7855a3..bc5a38a6705f 100644
--- a/drivers/net/ariadne.c
+++ b/drivers/net/ariadne.c
@@ -746,7 +746,7 @@ static int ariadne_rx(struct net_device *dev)
746 746
747 skb_reserve(skb,2); /* 16 byte align */ 747 skb_reserve(skb,2); /* 16 byte align */
748 skb_put(skb,pkt_len); /* Make room */ 748 skb_put(skb,pkt_len); /* Make room */
749 eth_copy_and_sum(skb, (char *)priv->rx_buff[entry], pkt_len,0); 749 skb_copy_to_linear_data(skb, (char *)priv->rx_buff[entry], pkt_len);
750 skb->protocol=eth_type_trans(skb,dev); 750 skb->protocol=eth_type_trans(skb,dev);
751#if 0 751#if 0
752 printk(KERN_DEBUG "RX pkt type 0x%04x from ", 752 printk(KERN_DEBUG "RX pkt type 0x%04x from ",
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index 2438c5bff237..f6ece1d43f6e 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -258,7 +258,7 @@ static int ep93xx_rx(struct net_device *dev, int *budget)
258 skb_reserve(skb, 2); 258 skb_reserve(skb, 2);
259 dma_sync_single(NULL, ep->descs->rdesc[entry].buf_addr, 259 dma_sync_single(NULL, ep->descs->rdesc[entry].buf_addr,
260 length, DMA_FROM_DEVICE); 260 length, DMA_FROM_DEVICE);
261 eth_copy_and_sum(skb, ep->rx_buf[entry], length, 0); 261 skb_copy_to_linear_data(skb, ep->rx_buf[entry], length);
262 skb_put(skb, length); 262 skb_put(skb, length);
263 skb->protocol = eth_type_trans(skb, dev); 263 skb->protocol = eth_type_trans(skb, dev);
264 264
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index c27cfcef45fa..e86b3691765b 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -1205,8 +1205,8 @@ static int au1000_rx(struct net_device *dev)
1205 continue; 1205 continue;
1206 } 1206 }
1207 skb_reserve(skb, 2); /* 16 byte IP header align */ 1207 skb_reserve(skb, 2); /* 16 byte IP header align */
1208 eth_copy_and_sum(skb, 1208 skb_copy_to_linear_data(skb,
1209 (unsigned char *)pDB->vaddr, frmlen, 0); 1209 (unsigned char *)pDB->vaddr, frmlen);
1210 skb_put(skb, frmlen); 1210 skb_put(skb, frmlen);
1211 skb->protocol = eth_type_trans(skb, dev); 1211 skb->protocol = eth_type_trans(skb, dev);
1212 netif_rx(skb); /* pass the packet to upper layers */ 1212 netif_rx(skb); /* pass the packet to upper layers */
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index ce3ed67a878e..d681903c592d 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -40,7 +40,6 @@
40#define BCM_VLAN 1 40#define BCM_VLAN 1
41#endif 41#endif
42#include <net/ip.h> 42#include <net/ip.h>
43#include <net/tcp.h>
44#include <net/checksum.h> 43#include <net/checksum.h>
45#include <linux/workqueue.h> 44#include <linux/workqueue.h>
46#include <linux/crc32.h> 45#include <linux/crc32.h>
@@ -54,8 +53,8 @@
54 53
55#define DRV_MODULE_NAME "bnx2" 54#define DRV_MODULE_NAME "bnx2"
56#define PFX DRV_MODULE_NAME ": " 55#define PFX DRV_MODULE_NAME ": "
57#define DRV_MODULE_VERSION "1.5.11" 56#define DRV_MODULE_VERSION "1.6.2"
58#define DRV_MODULE_RELDATE "June 4, 2007" 57#define DRV_MODULE_RELDATE "July 6, 2007"
59 58
60#define RUN_AT(x) (jiffies + (x)) 59#define RUN_AT(x) (jiffies + (x))
61 60
@@ -550,6 +549,9 @@ bnx2_report_fw_link(struct bnx2 *bp)
550{ 549{
551 u32 fw_link_status = 0; 550 u32 fw_link_status = 0;
552 551
552 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
553 return;
554
553 if (bp->link_up) { 555 if (bp->link_up) {
554 u32 bmsr; 556 u32 bmsr;
555 557
@@ -601,12 +603,21 @@ bnx2_report_fw_link(struct bnx2 *bp)
601 REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status); 603 REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status);
602} 604}
603 605
606static char *
607bnx2_xceiver_str(struct bnx2 *bp)
608{
609 return ((bp->phy_port == PORT_FIBRE) ? "SerDes" :
610 ((bp->phy_flags & PHY_SERDES_FLAG) ? "Remote Copper" :
611 "Copper"));
612}
613
604static void 614static void
605bnx2_report_link(struct bnx2 *bp) 615bnx2_report_link(struct bnx2 *bp)
606{ 616{
607 if (bp->link_up) { 617 if (bp->link_up) {
608 netif_carrier_on(bp->dev); 618 netif_carrier_on(bp->dev);
609 printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name); 619 printk(KERN_INFO PFX "%s NIC %s Link is Up, ", bp->dev->name,
620 bnx2_xceiver_str(bp));
610 621
611 printk("%d Mbps ", bp->line_speed); 622 printk("%d Mbps ", bp->line_speed);
612 623
@@ -630,7 +641,8 @@ bnx2_report_link(struct bnx2 *bp)
630 } 641 }
631 else { 642 else {
632 netif_carrier_off(bp->dev); 643 netif_carrier_off(bp->dev);
633 printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name); 644 printk(KERN_ERR PFX "%s NIC %s Link is Down\n", bp->dev->name,
645 bnx2_xceiver_str(bp));
634 } 646 }
635 647
636 bnx2_report_fw_link(bp); 648 bnx2_report_fw_link(bp);
@@ -1100,6 +1112,9 @@ bnx2_set_link(struct bnx2 *bp)
1100 return 0; 1112 return 0;
1101 } 1113 }
1102 1114
1115 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1116 return 0;
1117
1103 link_up = bp->link_up; 1118 link_up = bp->link_up;
1104 1119
1105 bnx2_enable_bmsr1(bp); 1120 bnx2_enable_bmsr1(bp);
@@ -1210,12 +1225,74 @@ bnx2_phy_get_pause_adv(struct bnx2 *bp)
1210 return adv; 1225 return adv;
1211} 1226}
1212 1227
1228static int bnx2_fw_sync(struct bnx2 *, u32, int);
1229
1213static int 1230static int
1214bnx2_setup_serdes_phy(struct bnx2 *bp) 1231bnx2_setup_remote_phy(struct bnx2 *bp, u8 port)
1232{
1233 u32 speed_arg = 0, pause_adv;
1234
1235 pause_adv = bnx2_phy_get_pause_adv(bp);
1236
1237 if (bp->autoneg & AUTONEG_SPEED) {
1238 speed_arg |= BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG;
1239 if (bp->advertising & ADVERTISED_10baseT_Half)
1240 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10HALF;
1241 if (bp->advertising & ADVERTISED_10baseT_Full)
1242 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10FULL;
1243 if (bp->advertising & ADVERTISED_100baseT_Half)
1244 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100HALF;
1245 if (bp->advertising & ADVERTISED_100baseT_Full)
1246 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100FULL;
1247 if (bp->advertising & ADVERTISED_1000baseT_Full)
1248 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
1249 if (bp->advertising & ADVERTISED_2500baseX_Full)
1250 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
1251 } else {
1252 if (bp->req_line_speed == SPEED_2500)
1253 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
1254 else if (bp->req_line_speed == SPEED_1000)
1255 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
1256 else if (bp->req_line_speed == SPEED_100) {
1257 if (bp->req_duplex == DUPLEX_FULL)
1258 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100FULL;
1259 else
1260 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100HALF;
1261 } else if (bp->req_line_speed == SPEED_10) {
1262 if (bp->req_duplex == DUPLEX_FULL)
1263 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10FULL;
1264 else
1265 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10HALF;
1266 }
1267 }
1268
1269 if (pause_adv & (ADVERTISE_1000XPAUSE | ADVERTISE_PAUSE_CAP))
1270 speed_arg |= BNX2_NETLINK_SET_LINK_FC_SYM_PAUSE;
1271 if (pause_adv & (ADVERTISE_1000XPSE_ASYM | ADVERTISE_1000XPSE_ASYM))
1272 speed_arg |= BNX2_NETLINK_SET_LINK_FC_ASYM_PAUSE;
1273
1274 if (port == PORT_TP)
1275 speed_arg |= BNX2_NETLINK_SET_LINK_PHY_APP_REMOTE |
1276 BNX2_NETLINK_SET_LINK_ETH_AT_WIRESPEED;
1277
1278 REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB_ARG0, speed_arg);
1279
1280 spin_unlock_bh(&bp->phy_lock);
1281 bnx2_fw_sync(bp, BNX2_DRV_MSG_CODE_CMD_SET_LINK, 0);
1282 spin_lock_bh(&bp->phy_lock);
1283
1284 return 0;
1285}
1286
1287static int
1288bnx2_setup_serdes_phy(struct bnx2 *bp, u8 port)
1215{ 1289{
1216 u32 adv, bmcr; 1290 u32 adv, bmcr;
1217 u32 new_adv = 0; 1291 u32 new_adv = 0;
1218 1292
1293 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1294 return (bnx2_setup_remote_phy(bp, port));
1295
1219 if (!(bp->autoneg & AUTONEG_SPEED)) { 1296 if (!(bp->autoneg & AUTONEG_SPEED)) {
1220 u32 new_bmcr; 1297 u32 new_bmcr;
1221 int force_link_down = 0; 1298 int force_link_down = 0;
@@ -1323,7 +1400,9 @@ bnx2_setup_serdes_phy(struct bnx2 *bp)
1323} 1400}
1324 1401
1325#define ETHTOOL_ALL_FIBRE_SPEED \ 1402#define ETHTOOL_ALL_FIBRE_SPEED \
1326 (ADVERTISED_1000baseT_Full) 1403 (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) ? \
1404 (ADVERTISED_2500baseX_Full | ADVERTISED_1000baseT_Full) :\
1405 (ADVERTISED_1000baseT_Full)
1327 1406
1328#define ETHTOOL_ALL_COPPER_SPEED \ 1407#define ETHTOOL_ALL_COPPER_SPEED \
1329 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \ 1408 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
@@ -1335,6 +1414,188 @@ bnx2_setup_serdes_phy(struct bnx2 *bp)
1335 1414
1336#define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL) 1415#define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
1337 1416
1417static void
1418bnx2_set_default_remote_link(struct bnx2 *bp)
1419{
1420 u32 link;
1421
1422 if (bp->phy_port == PORT_TP)
1423 link = REG_RD_IND(bp, bp->shmem_base + BNX2_RPHY_COPPER_LINK);
1424 else
1425 link = REG_RD_IND(bp, bp->shmem_base + BNX2_RPHY_SERDES_LINK);
1426
1427 if (link & BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG) {
1428 bp->req_line_speed = 0;
1429 bp->autoneg |= AUTONEG_SPEED;
1430 bp->advertising = ADVERTISED_Autoneg;
1431 if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
1432 bp->advertising |= ADVERTISED_10baseT_Half;
1433 if (link & BNX2_NETLINK_SET_LINK_SPEED_10FULL)
1434 bp->advertising |= ADVERTISED_10baseT_Full;
1435 if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
1436 bp->advertising |= ADVERTISED_100baseT_Half;
1437 if (link & BNX2_NETLINK_SET_LINK_SPEED_100FULL)
1438 bp->advertising |= ADVERTISED_100baseT_Full;
1439 if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
1440 bp->advertising |= ADVERTISED_1000baseT_Full;
1441 if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
1442 bp->advertising |= ADVERTISED_2500baseX_Full;
1443 } else {
1444 bp->autoneg = 0;
1445 bp->advertising = 0;
1446 bp->req_duplex = DUPLEX_FULL;
1447 if (link & BNX2_NETLINK_SET_LINK_SPEED_10) {
1448 bp->req_line_speed = SPEED_10;
1449 if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
1450 bp->req_duplex = DUPLEX_HALF;
1451 }
1452 if (link & BNX2_NETLINK_SET_LINK_SPEED_100) {
1453 bp->req_line_speed = SPEED_100;
1454 if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
1455 bp->req_duplex = DUPLEX_HALF;
1456 }
1457 if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
1458 bp->req_line_speed = SPEED_1000;
1459 if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
1460 bp->req_line_speed = SPEED_2500;
1461 }
1462}
1463
1464static void
1465bnx2_set_default_link(struct bnx2 *bp)
1466{
1467 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1468 return bnx2_set_default_remote_link(bp);
1469
1470 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
1471 bp->req_line_speed = 0;
1472 if (bp->phy_flags & PHY_SERDES_FLAG) {
1473 u32 reg;
1474
1475 bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
1476
1477 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
1478 reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
1479 if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
1480 bp->autoneg = 0;
1481 bp->req_line_speed = bp->line_speed = SPEED_1000;
1482 bp->req_duplex = DUPLEX_FULL;
1483 }
1484 } else
1485 bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
1486}
1487
1488static void
1489bnx2_send_heart_beat(struct bnx2 *bp)
1490{
1491 u32 msg;
1492 u32 addr;
1493
1494 spin_lock(&bp->indirect_lock);
1495 msg = (u32) (++bp->fw_drv_pulse_wr_seq & BNX2_DRV_PULSE_SEQ_MASK);
1496 addr = bp->shmem_base + BNX2_DRV_PULSE_MB;
1497 REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, addr);
1498 REG_WR(bp, BNX2_PCICFG_REG_WINDOW, msg);
1499 spin_unlock(&bp->indirect_lock);
1500}
1501
1502static void
1503bnx2_remote_phy_event(struct bnx2 *bp)
1504{
1505 u32 msg;
1506 u8 link_up = bp->link_up;
1507 u8 old_port;
1508
1509 msg = REG_RD_IND(bp, bp->shmem_base + BNX2_LINK_STATUS);
1510
1511 if (msg & BNX2_LINK_STATUS_HEART_BEAT_EXPIRED)
1512 bnx2_send_heart_beat(bp);
1513
1514 msg &= ~BNX2_LINK_STATUS_HEART_BEAT_EXPIRED;
1515
1516 if ((msg & BNX2_LINK_STATUS_LINK_UP) == BNX2_LINK_STATUS_LINK_DOWN)
1517 bp->link_up = 0;
1518 else {
1519 u32 speed;
1520
1521 bp->link_up = 1;
1522 speed = msg & BNX2_LINK_STATUS_SPEED_MASK;
1523 bp->duplex = DUPLEX_FULL;
1524 switch (speed) {
1525 case BNX2_LINK_STATUS_10HALF:
1526 bp->duplex = DUPLEX_HALF;
1527 case BNX2_LINK_STATUS_10FULL:
1528 bp->line_speed = SPEED_10;
1529 break;
1530 case BNX2_LINK_STATUS_100HALF:
1531 bp->duplex = DUPLEX_HALF;
1532 case BNX2_LINK_STATUS_100BASE_T4:
1533 case BNX2_LINK_STATUS_100FULL:
1534 bp->line_speed = SPEED_100;
1535 break;
1536 case BNX2_LINK_STATUS_1000HALF:
1537 bp->duplex = DUPLEX_HALF;
1538 case BNX2_LINK_STATUS_1000FULL:
1539 bp->line_speed = SPEED_1000;
1540 break;
1541 case BNX2_LINK_STATUS_2500HALF:
1542 bp->duplex = DUPLEX_HALF;
1543 case BNX2_LINK_STATUS_2500FULL:
1544 bp->line_speed = SPEED_2500;
1545 break;
1546 default:
1547 bp->line_speed = 0;
1548 break;
1549 }
1550
1551 spin_lock(&bp->phy_lock);
1552 bp->flow_ctrl = 0;
1553 if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
1554 (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
1555 if (bp->duplex == DUPLEX_FULL)
1556 bp->flow_ctrl = bp->req_flow_ctrl;
1557 } else {
1558 if (msg & BNX2_LINK_STATUS_TX_FC_ENABLED)
1559 bp->flow_ctrl |= FLOW_CTRL_TX;
1560 if (msg & BNX2_LINK_STATUS_RX_FC_ENABLED)
1561 bp->flow_ctrl |= FLOW_CTRL_RX;
1562 }
1563
1564 old_port = bp->phy_port;
1565 if (msg & BNX2_LINK_STATUS_SERDES_LINK)
1566 bp->phy_port = PORT_FIBRE;
1567 else
1568 bp->phy_port = PORT_TP;
1569
1570 if (old_port != bp->phy_port)
1571 bnx2_set_default_link(bp);
1572
1573 spin_unlock(&bp->phy_lock);
1574 }
1575 if (bp->link_up != link_up)
1576 bnx2_report_link(bp);
1577
1578 bnx2_set_mac_link(bp);
1579}
1580
1581static int
1582bnx2_set_remote_link(struct bnx2 *bp)
1583{
1584 u32 evt_code;
1585
1586 evt_code = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_EVT_CODE_MB);
1587 switch (evt_code) {
1588 case BNX2_FW_EVT_CODE_LINK_EVENT:
1589 bnx2_remote_phy_event(bp);
1590 break;
1591 case BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT:
1592 default:
1593 bnx2_send_heart_beat(bp);
1594 break;
1595 }
1596 return 0;
1597}
1598
1338static int 1599static int
1339bnx2_setup_copper_phy(struct bnx2 *bp) 1600bnx2_setup_copper_phy(struct bnx2 *bp)
1340{ 1601{
@@ -1433,13 +1694,13 @@ bnx2_setup_copper_phy(struct bnx2 *bp)
1433} 1694}
1434 1695
1435static int 1696static int
1436bnx2_setup_phy(struct bnx2 *bp) 1697bnx2_setup_phy(struct bnx2 *bp, u8 port)
1437{ 1698{
1438 if (bp->loopback == MAC_LOOPBACK) 1699 if (bp->loopback == MAC_LOOPBACK)
1439 return 0; 1700 return 0;
1440 1701
1441 if (bp->phy_flags & PHY_SERDES_FLAG) { 1702 if (bp->phy_flags & PHY_SERDES_FLAG) {
1442 return (bnx2_setup_serdes_phy(bp)); 1703 return (bnx2_setup_serdes_phy(bp, port));
1443 } 1704 }
1444 else { 1705 else {
1445 return (bnx2_setup_copper_phy(bp)); 1706 return (bnx2_setup_copper_phy(bp));
@@ -1659,6 +1920,9 @@ bnx2_init_phy(struct bnx2 *bp)
1659 1920
1660 REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK); 1921 REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
1661 1922
1923 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1924 goto setup_phy;
1925
1662 bnx2_read_phy(bp, MII_PHYSID1, &val); 1926 bnx2_read_phy(bp, MII_PHYSID1, &val);
1663 bp->phy_id = val << 16; 1927 bp->phy_id = val << 16;
1664 bnx2_read_phy(bp, MII_PHYSID2, &val); 1928 bnx2_read_phy(bp, MII_PHYSID2, &val);
@@ -1676,7 +1940,9 @@ bnx2_init_phy(struct bnx2 *bp)
1676 rc = bnx2_init_copper_phy(bp); 1940 rc = bnx2_init_copper_phy(bp);
1677 } 1941 }
1678 1942
1679 bnx2_setup_phy(bp); 1943setup_phy:
1944 if (!rc)
1945 rc = bnx2_setup_phy(bp, bp->phy_port);
1680 1946
1681 return rc; 1947 return rc;
1682} 1948}
@@ -1984,6 +2250,9 @@ bnx2_phy_int(struct bnx2 *bp)
1984 bnx2_set_link(bp); 2250 bnx2_set_link(bp);
1985 spin_unlock(&bp->phy_lock); 2251 spin_unlock(&bp->phy_lock);
1986 } 2252 }
2253 if (bnx2_phy_event_is_set(bp, STATUS_ATTN_BITS_TIMER_ABORT))
2254 bnx2_set_remote_link(bp);
2255
1987} 2256}
1988 2257
1989static void 2258static void
@@ -2297,6 +2566,7 @@ bnx2_interrupt(int irq, void *dev_instance)
2297{ 2566{
2298 struct net_device *dev = dev_instance; 2567 struct net_device *dev = dev_instance;
2299 struct bnx2 *bp = netdev_priv(dev); 2568 struct bnx2 *bp = netdev_priv(dev);
2569 struct status_block *sblk = bp->status_blk;
2300 2570
2301 /* When using INTx, it is possible for the interrupt to arrive 2571 /* When using INTx, it is possible for the interrupt to arrive
2302 * at the CPU before the status block posted prior to the 2572 * at the CPU before the status block posted prior to the
@@ -2304,7 +2574,7 @@ bnx2_interrupt(int irq, void *dev_instance)
2304 * When using MSI, the MSI message will always complete after 2574 * When using MSI, the MSI message will always complete after
2305 * the status block write. 2575 * the status block write.
2306 */ 2576 */
2307 if ((bp->status_blk->status_idx == bp->last_status_idx) && 2577 if ((sblk->status_idx == bp->last_status_idx) &&
2308 (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) & 2578 (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
2309 BNX2_PCICFG_MISC_STATUS_INTA_VALUE)) 2579 BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
2310 return IRQ_NONE; 2580 return IRQ_NONE;
@@ -2313,16 +2583,25 @@ bnx2_interrupt(int irq, void *dev_instance)
2313 BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM | 2583 BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
2314 BNX2_PCICFG_INT_ACK_CMD_MASK_INT); 2584 BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
2315 2585
2586 /* Read back to deassert IRQ immediately to avoid too many
2587 * spurious interrupts.
2588 */
2589 REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
2590
2316 /* Return here if interrupt is shared and is disabled. */ 2591 /* Return here if interrupt is shared and is disabled. */
2317 if (unlikely(atomic_read(&bp->intr_sem) != 0)) 2592 if (unlikely(atomic_read(&bp->intr_sem) != 0))
2318 return IRQ_HANDLED; 2593 return IRQ_HANDLED;
2319 2594
2320 netif_rx_schedule(dev); 2595 if (netif_rx_schedule_prep(dev)) {
2596 bp->last_status_idx = sblk->status_idx;
2597 __netif_rx_schedule(dev);
2598 }
2321 2599
2322 return IRQ_HANDLED; 2600 return IRQ_HANDLED;
2323} 2601}
2324 2602
2325#define STATUS_ATTN_EVENTS STATUS_ATTN_BITS_LINK_STATE 2603#define STATUS_ATTN_EVENTS (STATUS_ATTN_BITS_LINK_STATE | \
2604 STATUS_ATTN_BITS_TIMER_ABORT)
2326 2605
2327static inline int 2606static inline int
2328bnx2_has_work(struct bnx2 *bp) 2607bnx2_has_work(struct bnx2 *bp)
@@ -3562,6 +3841,36 @@ nvram_write_end:
3562 return rc; 3841 return rc;
3563} 3842}
3564 3843
3844static void
3845bnx2_init_remote_phy(struct bnx2 *bp)
3846{
3847 u32 val;
3848
3849 bp->phy_flags &= ~REMOTE_PHY_CAP_FLAG;
3850 if (!(bp->phy_flags & PHY_SERDES_FLAG))
3851 return;
3852
3853 val = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_CAP_MB);
3854 if ((val & BNX2_FW_CAP_SIGNATURE_MASK) != BNX2_FW_CAP_SIGNATURE)
3855 return;
3856
3857 if (val & BNX2_FW_CAP_REMOTE_PHY_CAPABLE) {
3858 if (netif_running(bp->dev)) {
3859 val = BNX2_DRV_ACK_CAP_SIGNATURE |
3860 BNX2_FW_CAP_REMOTE_PHY_CAPABLE;
3861 REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_ACK_CAP_MB,
3862 val);
3863 }
3864 bp->phy_flags |= REMOTE_PHY_CAP_FLAG;
3865
3866 val = REG_RD_IND(bp, bp->shmem_base + BNX2_LINK_STATUS);
3867 if (val & BNX2_LINK_STATUS_SERDES_LINK)
3868 bp->phy_port = PORT_FIBRE;
3869 else
3870 bp->phy_port = PORT_TP;
3871 }
3872}
3873
3565static int 3874static int
3566bnx2_reset_chip(struct bnx2 *bp, u32 reset_code) 3875bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
3567{ 3876{
@@ -3642,6 +3951,12 @@ bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
3642 if (rc) 3951 if (rc)
3643 return rc; 3952 return rc;
3644 3953
3954 spin_lock_bh(&bp->phy_lock);
3955 bnx2_init_remote_phy(bp);
3956 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
3957 bnx2_set_default_remote_link(bp);
3958 spin_unlock_bh(&bp->phy_lock);
3959
3645 if (CHIP_ID(bp) == CHIP_ID_5706_A0) { 3960 if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
3646 /* Adjust the voltage regular to two steps lower. The default 3961 /* Adjust the voltage regular to two steps lower. The default
3647 * of this register is 0x0000000e. */ 3962 * of this register is 0x0000000e. */
@@ -3826,7 +4141,7 @@ bnx2_init_chip(struct bnx2 *bp)
3826 rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET, 4141 rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
3827 0); 4142 0);
3828 4143
3829 REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff); 4144 REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, BNX2_MISC_ENABLE_DEFAULT);
3830 REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS); 4145 REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
3831 4146
3832 udelay(20); 4147 udelay(20);
@@ -4069,8 +4384,8 @@ bnx2_init_nic(struct bnx2 *bp)
4069 4384
4070 spin_lock_bh(&bp->phy_lock); 4385 spin_lock_bh(&bp->phy_lock);
4071 bnx2_init_phy(bp); 4386 bnx2_init_phy(bp);
4072 spin_unlock_bh(&bp->phy_lock);
4073 bnx2_set_link(bp); 4387 bnx2_set_link(bp);
4388 spin_unlock_bh(&bp->phy_lock);
4074 return 0; 4389 return 0;
4075} 4390}
4076 4391
@@ -4600,6 +4915,9 @@ bnx2_5706_serdes_timer(struct bnx2 *bp)
4600static void 4915static void
4601bnx2_5708_serdes_timer(struct bnx2 *bp) 4916bnx2_5708_serdes_timer(struct bnx2 *bp)
4602{ 4917{
4918 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
4919 return;
4920
4603 if ((bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) == 0) { 4921 if ((bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) == 0) {
4604 bp->serdes_an_pending = 0; 4922 bp->serdes_an_pending = 0;
4605 return; 4923 return;
@@ -4631,7 +4949,6 @@ static void
4631bnx2_timer(unsigned long data) 4949bnx2_timer(unsigned long data)
4632{ 4950{
4633 struct bnx2 *bp = (struct bnx2 *) data; 4951 struct bnx2 *bp = (struct bnx2 *) data;
4634 u32 msg;
4635 4952
4636 if (!netif_running(bp->dev)) 4953 if (!netif_running(bp->dev))
4637 return; 4954 return;
@@ -4639,8 +4956,7 @@ bnx2_timer(unsigned long data)
4639 if (atomic_read(&bp->intr_sem) != 0) 4956 if (atomic_read(&bp->intr_sem) != 0)
4640 goto bnx2_restart_timer; 4957 goto bnx2_restart_timer;
4641 4958
4642 msg = (u32) ++bp->fw_drv_pulse_wr_seq; 4959 bnx2_send_heart_beat(bp);
4643 REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_PULSE_MB, msg);
4644 4960
4645 bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT); 4961 bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT);
4646 4962
@@ -5083,17 +5399,25 @@ static int
5083bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 5399bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5084{ 5400{
5085 struct bnx2 *bp = netdev_priv(dev); 5401 struct bnx2 *bp = netdev_priv(dev);
5402 int support_serdes = 0, support_copper = 0;
5086 5403
5087 cmd->supported = SUPPORTED_Autoneg; 5404 cmd->supported = SUPPORTED_Autoneg;
5088 if (bp->phy_flags & PHY_SERDES_FLAG) { 5405 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG) {
5406 support_serdes = 1;
5407 support_copper = 1;
5408 } else if (bp->phy_port == PORT_FIBRE)
5409 support_serdes = 1;
5410 else
5411 support_copper = 1;
5412
5413 if (support_serdes) {
5089 cmd->supported |= SUPPORTED_1000baseT_Full | 5414 cmd->supported |= SUPPORTED_1000baseT_Full |
5090 SUPPORTED_FIBRE; 5415 SUPPORTED_FIBRE;
5091 if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) 5416 if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)
5092 cmd->supported |= SUPPORTED_2500baseX_Full; 5417 cmd->supported |= SUPPORTED_2500baseX_Full;
5093 5418
5094 cmd->port = PORT_FIBRE;
5095 } 5419 }
5096 else { 5420 if (support_copper) {
5097 cmd->supported |= SUPPORTED_10baseT_Half | 5421 cmd->supported |= SUPPORTED_10baseT_Half |
5098 SUPPORTED_10baseT_Full | 5422 SUPPORTED_10baseT_Full |
5099 SUPPORTED_100baseT_Half | 5423 SUPPORTED_100baseT_Half |
@@ -5101,9 +5425,10 @@ bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5101 SUPPORTED_1000baseT_Full | 5425 SUPPORTED_1000baseT_Full |
5102 SUPPORTED_TP; 5426 SUPPORTED_TP;
5103 5427
5104 cmd->port = PORT_TP;
5105 } 5428 }
5106 5429
5430 spin_lock_bh(&bp->phy_lock);
5431 cmd->port = bp->phy_port;
5107 cmd->advertising = bp->advertising; 5432 cmd->advertising = bp->advertising;
5108 5433
5109 if (bp->autoneg & AUTONEG_SPEED) { 5434 if (bp->autoneg & AUTONEG_SPEED) {
@@ -5121,6 +5446,7 @@ bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5121 cmd->speed = -1; 5446 cmd->speed = -1;
5122 cmd->duplex = -1; 5447 cmd->duplex = -1;
5123 } 5448 }
5449 spin_unlock_bh(&bp->phy_lock);
5124 5450
5125 cmd->transceiver = XCVR_INTERNAL; 5451 cmd->transceiver = XCVR_INTERNAL;
5126 cmd->phy_address = bp->phy_addr; 5452 cmd->phy_address = bp->phy_addr;
@@ -5136,6 +5462,15 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5136 u8 req_duplex = bp->req_duplex; 5462 u8 req_duplex = bp->req_duplex;
5137 u16 req_line_speed = bp->req_line_speed; 5463 u16 req_line_speed = bp->req_line_speed;
5138 u32 advertising = bp->advertising; 5464 u32 advertising = bp->advertising;
5465 int err = -EINVAL;
5466
5467 spin_lock_bh(&bp->phy_lock);
5468
5469 if (cmd->port != PORT_TP && cmd->port != PORT_FIBRE)
5470 goto err_out_unlock;
5471
5472 if (cmd->port != bp->phy_port && !(bp->phy_flags & REMOTE_PHY_CAP_FLAG))
5473 goto err_out_unlock;
5139 5474
5140 if (cmd->autoneg == AUTONEG_ENABLE) { 5475 if (cmd->autoneg == AUTONEG_ENABLE) {
5141 autoneg |= AUTONEG_SPEED; 5476 autoneg |= AUTONEG_SPEED;
@@ -5148,44 +5483,41 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5148 (cmd->advertising == ADVERTISED_100baseT_Half) || 5483 (cmd->advertising == ADVERTISED_100baseT_Half) ||
5149 (cmd->advertising == ADVERTISED_100baseT_Full)) { 5484 (cmd->advertising == ADVERTISED_100baseT_Full)) {
5150 5485
5151 if (bp->phy_flags & PHY_SERDES_FLAG) 5486 if (cmd->port == PORT_FIBRE)
5152 return -EINVAL; 5487 goto err_out_unlock;
5153 5488
5154 advertising = cmd->advertising; 5489 advertising = cmd->advertising;
5155 5490
5156 } else if (cmd->advertising == ADVERTISED_2500baseX_Full) { 5491 } else if (cmd->advertising == ADVERTISED_2500baseX_Full) {
5157 if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)) 5492 if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) ||
5158 return -EINVAL; 5493 (cmd->port == PORT_TP))
5159 } else if (cmd->advertising == ADVERTISED_1000baseT_Full) { 5494 goto err_out_unlock;
5495 } else if (cmd->advertising == ADVERTISED_1000baseT_Full)
5160 advertising = cmd->advertising; 5496 advertising = cmd->advertising;
5161 } 5497 else if (cmd->advertising == ADVERTISED_1000baseT_Half)
5162 else if (cmd->advertising == ADVERTISED_1000baseT_Half) { 5498 goto err_out_unlock;
5163 return -EINVAL;
5164 }
5165 else { 5499 else {
5166 if (bp->phy_flags & PHY_SERDES_FLAG) { 5500 if (cmd->port == PORT_FIBRE)
5167 advertising = ETHTOOL_ALL_FIBRE_SPEED; 5501 advertising = ETHTOOL_ALL_FIBRE_SPEED;
5168 } 5502 else
5169 else {
5170 advertising = ETHTOOL_ALL_COPPER_SPEED; 5503 advertising = ETHTOOL_ALL_COPPER_SPEED;
5171 }
5172 } 5504 }
5173 advertising |= ADVERTISED_Autoneg; 5505 advertising |= ADVERTISED_Autoneg;
5174 } 5506 }
5175 else { 5507 else {
5176 if (bp->phy_flags & PHY_SERDES_FLAG) { 5508 if (cmd->port == PORT_FIBRE) {
5177 if ((cmd->speed != SPEED_1000 && 5509 if ((cmd->speed != SPEED_1000 &&
5178 cmd->speed != SPEED_2500) || 5510 cmd->speed != SPEED_2500) ||
5179 (cmd->duplex != DUPLEX_FULL)) 5511 (cmd->duplex != DUPLEX_FULL))
5180 return -EINVAL; 5512 goto err_out_unlock;
5181 5513
5182 if (cmd->speed == SPEED_2500 && 5514 if (cmd->speed == SPEED_2500 &&
5183 !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)) 5515 !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
5184 return -EINVAL; 5516 goto err_out_unlock;
5185 }
5186 else if (cmd->speed == SPEED_1000) {
5187 return -EINVAL;
5188 } 5517 }
5518 else if (cmd->speed == SPEED_1000 || cmd->speed == SPEED_2500)
5519 goto err_out_unlock;
5520
5189 autoneg &= ~AUTONEG_SPEED; 5521 autoneg &= ~AUTONEG_SPEED;
5190 req_line_speed = cmd->speed; 5522 req_line_speed = cmd->speed;
5191 req_duplex = cmd->duplex; 5523 req_duplex = cmd->duplex;
@@ -5197,13 +5529,12 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5197 bp->req_line_speed = req_line_speed; 5529 bp->req_line_speed = req_line_speed;
5198 bp->req_duplex = req_duplex; 5530 bp->req_duplex = req_duplex;
5199 5531
5200 spin_lock_bh(&bp->phy_lock); 5532 err = bnx2_setup_phy(bp, cmd->port);
5201
5202 bnx2_setup_phy(bp);
5203 5533
5534err_out_unlock:
5204 spin_unlock_bh(&bp->phy_lock); 5535 spin_unlock_bh(&bp->phy_lock);
5205 5536
5206 return 0; 5537 return err;
5207} 5538}
5208 5539
5209static void 5540static void
@@ -5214,11 +5545,7 @@ bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
5214 strcpy(info->driver, DRV_MODULE_NAME); 5545 strcpy(info->driver, DRV_MODULE_NAME);
5215 strcpy(info->version, DRV_MODULE_VERSION); 5546 strcpy(info->version, DRV_MODULE_VERSION);
5216 strcpy(info->bus_info, pci_name(bp->pdev)); 5547 strcpy(info->bus_info, pci_name(bp->pdev));
5217 info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0'; 5548 strcpy(info->fw_version, bp->fw_version);
5218 info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
5219 info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
5220 info->fw_version[1] = info->fw_version[3] = '.';
5221 info->fw_version[5] = 0;
5222} 5549}
5223 5550
5224#define BNX2_REGDUMP_LEN (32 * 1024) 5551#define BNX2_REGDUMP_LEN (32 * 1024)
@@ -5330,6 +5657,14 @@ bnx2_nway_reset(struct net_device *dev)
5330 5657
5331 spin_lock_bh(&bp->phy_lock); 5658 spin_lock_bh(&bp->phy_lock);
5332 5659
5660 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG) {
5661 int rc;
5662
5663 rc = bnx2_setup_remote_phy(bp, bp->phy_port);
5664 spin_unlock_bh(&bp->phy_lock);
5665 return rc;
5666 }
5667
5333 /* Force a link down visible on the other side */ 5668 /* Force a link down visible on the other side */
5334 if (bp->phy_flags & PHY_SERDES_FLAG) { 5669 if (bp->phy_flags & PHY_SERDES_FLAG) {
5335 bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK); 5670 bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
@@ -5543,7 +5878,7 @@ bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
5543 5878
5544 spin_lock_bh(&bp->phy_lock); 5879 spin_lock_bh(&bp->phy_lock);
5545 5880
5546 bnx2_setup_phy(bp); 5881 bnx2_setup_phy(bp, bp->phy_port);
5547 5882
5548 spin_unlock_bh(&bp->phy_lock); 5883 spin_unlock_bh(&bp->phy_lock);
5549 5884
@@ -5939,6 +6274,9 @@ bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5939 case SIOCGMIIREG: { 6274 case SIOCGMIIREG: {
5940 u32 mii_regval; 6275 u32 mii_regval;
5941 6276
6277 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
6278 return -EOPNOTSUPP;
6279
5942 if (!netif_running(dev)) 6280 if (!netif_running(dev))
5943 return -EAGAIN; 6281 return -EAGAIN;
5944 6282
@@ -5955,6 +6293,9 @@ bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5955 if (!capable(CAP_NET_ADMIN)) 6293 if (!capable(CAP_NET_ADMIN))
5956 return -EPERM; 6294 return -EPERM;
5957 6295
6296 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
6297 return -EOPNOTSUPP;
6298
5958 if (!netif_running(dev)) 6299 if (!netif_running(dev))
5959 return -EAGAIN; 6300 return -EAGAIN;
5960 6301
@@ -6116,7 +6457,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6116{ 6457{
6117 struct bnx2 *bp; 6458 struct bnx2 *bp;
6118 unsigned long mem_len; 6459 unsigned long mem_len;
6119 int rc; 6460 int rc, i, j;
6120 u32 reg; 6461 u32 reg;
6121 u64 dma_mask, persist_dma_mask; 6462 u64 dma_mask, persist_dma_mask;
6122 6463
@@ -6273,7 +6614,35 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6273 goto err_out_unmap; 6614 goto err_out_unmap;
6274 } 6615 }
6275 6616
6276 bp->fw_ver = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV); 6617 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
6618 for (i = 0, j = 0; i < 3; i++) {
6619 u8 num, k, skip0;
6620
6621 num = (u8) (reg >> (24 - (i * 8)));
6622 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
6623 if (num >= k || !skip0 || k == 1) {
6624 bp->fw_version[j++] = (num / k) + '0';
6625 skip0 = 0;
6626 }
6627 }
6628 if (i != 2)
6629 bp->fw_version[j++] = '.';
6630 }
6631 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_BC_STATE_CONDITION);
6632 reg &= BNX2_CONDITION_MFW_RUN_MASK;
6633 if (reg != BNX2_CONDITION_MFW_RUN_UNKNOWN &&
6634 reg != BNX2_CONDITION_MFW_RUN_NONE) {
6635 int i;
6636 u32 addr = REG_RD_IND(bp, bp->shmem_base + BNX2_MFW_VER_PTR);
6637
6638 bp->fw_version[j++] = ' ';
6639 for (i = 0; i < 3; i++) {
6640 reg = REG_RD_IND(bp, addr + i * 4);
6641 reg = swab32(reg);
6642 memcpy(&bp->fw_version[j], &reg, 4);
6643 j += 4;
6644 }
6645 }
6277 6646
6278 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER); 6647 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER);
6279 bp->mac_addr[0] = (u8) (reg >> 8); 6648 bp->mac_addr[0] = (u8) (reg >> 8);
@@ -6315,7 +6684,9 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6315 else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) 6684 else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
6316 bp->phy_flags |= PHY_SERDES_FLAG; 6685 bp->phy_flags |= PHY_SERDES_FLAG;
6317 6686
6687 bp->phy_port = PORT_TP;
6318 if (bp->phy_flags & PHY_SERDES_FLAG) { 6688 if (bp->phy_flags & PHY_SERDES_FLAG) {
6689 bp->phy_port = PORT_FIBRE;
6319 bp->flags |= NO_WOL_FLAG; 6690 bp->flags |= NO_WOL_FLAG;
6320 if (CHIP_NUM(bp) != CHIP_NUM_5706) { 6691 if (CHIP_NUM(bp) != CHIP_NUM_5706) {
6321 bp->phy_addr = 2; 6692 bp->phy_addr = 2;
@@ -6324,6 +6695,8 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6324 if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G) 6695 if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
6325 bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG; 6696 bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
6326 } 6697 }
6698 bnx2_init_remote_phy(bp);
6699
6327 } else if (CHIP_NUM(bp) == CHIP_NUM_5706 || 6700 } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
6328 CHIP_NUM(bp) == CHIP_NUM_5708) 6701 CHIP_NUM(bp) == CHIP_NUM_5708)
6329 bp->phy_flags |= PHY_CRC_FIX_FLAG; 6702 bp->phy_flags |= PHY_CRC_FIX_FLAG;
@@ -6374,23 +6747,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6374 } 6747 }
6375 } 6748 }
6376 6749
6377 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL; 6750 bnx2_set_default_link(bp);
6378 bp->req_line_speed = 0;
6379 if (bp->phy_flags & PHY_SERDES_FLAG) {
6380 bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
6381
6382 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
6383 reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
6384 if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
6385 bp->autoneg = 0;
6386 bp->req_line_speed = bp->line_speed = SPEED_1000;
6387 bp->req_duplex = DUPLEX_FULL;
6388 }
6389 }
6390 else {
6391 bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
6392 }
6393
6394 bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX; 6751 bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
6395 6752
6396 init_timer(&bp->timer); 6753 init_timer(&bp->timer);
@@ -6490,10 +6847,10 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
6490 memcpy(dev->perm_addr, bp->mac_addr, 6); 6847 memcpy(dev->perm_addr, bp->mac_addr, 6);
6491 bp->name = board_info[ent->driver_data].name; 6848 bp->name = board_info[ent->driver_data].name;
6492 6849
6850 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
6493 if (CHIP_NUM(bp) == CHIP_NUM_5709) 6851 if (CHIP_NUM(bp) == CHIP_NUM_5709)
6494 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG; 6852 dev->features |= NETIF_F_IPV6_CSUM;
6495 else 6853
6496 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
6497#ifdef BCM_VLAN 6854#ifdef BCM_VLAN
6498 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; 6855 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
6499#endif 6856#endif
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 49a5de253b17..d8cd1afeb23d 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -6338,6 +6338,8 @@ struct l2_fhdr {
6338 6338
6339#define RX_COPY_THRESH 92 6339#define RX_COPY_THRESH 92
6340 6340
6341#define BNX2_MISC_ENABLE_DEFAULT 0x7ffffff
6342
6341#define DMA_READ_CHANS 5 6343#define DMA_READ_CHANS 5
6342#define DMA_WRITE_CHANS 3 6344#define DMA_WRITE_CHANS 3
6343 6345
@@ -6537,6 +6539,7 @@ struct bnx2 {
6537#define PHY_INT_MODE_AUTO_POLLING_FLAG 0x100 6539#define PHY_INT_MODE_AUTO_POLLING_FLAG 0x100
6538#define PHY_INT_MODE_LINK_READY_FLAG 0x200 6540#define PHY_INT_MODE_LINK_READY_FLAG 0x200
6539#define PHY_DIS_EARLY_DAC_FLAG 0x400 6541#define PHY_DIS_EARLY_DAC_FLAG 0x400
6542#define REMOTE_PHY_CAP_FLAG 0x800
6540 6543
6541 u32 mii_bmcr; 6544 u32 mii_bmcr;
6542 u32 mii_bmsr; 6545 u32 mii_bmsr;
@@ -6625,6 +6628,7 @@ struct bnx2 {
6625 u16 req_line_speed; 6628 u16 req_line_speed;
6626 u8 req_duplex; 6629 u8 req_duplex;
6627 6630
6631 u8 phy_port;
6628 u8 link_up; 6632 u8 link_up;
6629 6633
6630 u16 line_speed; 6634 u16 line_speed;
@@ -6656,7 +6660,7 @@ struct bnx2 {
6656 6660
6657 u32 shmem_base; 6661 u32 shmem_base;
6658 6662
6659 u32 fw_ver; 6663 char fw_version[32];
6660 6664
6661 int pm_cap; 6665 int pm_cap;
6662 int pcix_cap; 6666 int pcix_cap;
@@ -6770,7 +6774,7 @@ struct fw_info {
6770 * the firmware has timed out, the driver will assume there is no firmware 6774 * the firmware has timed out, the driver will assume there is no firmware
6771 * running and there won't be any firmware-driver synchronization during a 6775 * running and there won't be any firmware-driver synchronization during a
6772 * driver reset. */ 6776 * driver reset. */
6773#define FW_ACK_TIME_OUT_MS 100 6777#define FW_ACK_TIME_OUT_MS 1000
6774 6778
6775 6779
6776#define BNX2_DRV_RESET_SIGNATURE 0x00000000 6780#define BNX2_DRV_RESET_SIGNATURE 0x00000000
@@ -6788,6 +6792,7 @@ struct fw_info {
6788#define BNX2_DRV_MSG_CODE_DIAG 0x07000000 6792#define BNX2_DRV_MSG_CODE_DIAG 0x07000000
6789#define BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL 0x09000000 6793#define BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL 0x09000000
6790#define BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN 0x0b000000 6794#define BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN 0x0b000000
6795#define BNX2_DRV_MSG_CODE_CMD_SET_LINK 0x10000000
6791 6796
6792#define BNX2_DRV_MSG_DATA 0x00ff0000 6797#define BNX2_DRV_MSG_DATA 0x00ff0000
6793#define BNX2_DRV_MSG_DATA_WAIT0 0x00010000 6798#define BNX2_DRV_MSG_DATA_WAIT0 0x00010000
@@ -6836,6 +6841,7 @@ struct fw_info {
6836#define BNX2_LINK_STATUS_SERDES_LINK (1<<20) 6841#define BNX2_LINK_STATUS_SERDES_LINK (1<<20)
6837#define BNX2_LINK_STATUS_PARTNER_AD_2500FULL (1<<21) 6842#define BNX2_LINK_STATUS_PARTNER_AD_2500FULL (1<<21)
6838#define BNX2_LINK_STATUS_PARTNER_AD_2500HALF (1<<22) 6843#define BNX2_LINK_STATUS_PARTNER_AD_2500HALF (1<<22)
6844#define BNX2_LINK_STATUS_HEART_BEAT_EXPIRED (1<<31)
6839 6845
6840#define BNX2_DRV_PULSE_MB 0x00000010 6846#define BNX2_DRV_PULSE_MB 0x00000010
6841#define BNX2_DRV_PULSE_SEQ_MASK 0x00007fff 6847#define BNX2_DRV_PULSE_SEQ_MASK 0x00007fff
@@ -6845,6 +6851,30 @@ struct fw_info {
6845 * This is used for debugging. */ 6851 * This is used for debugging. */
6846#define BNX2_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE 0x00080000 6852#define BNX2_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE 0x00080000
6847 6853
6854#define BNX2_DRV_MB_ARG0 0x00000014
6855#define BNX2_NETLINK_SET_LINK_SPEED_10HALF (1<<0)
6856#define BNX2_NETLINK_SET_LINK_SPEED_10FULL (1<<1)
6857#define BNX2_NETLINK_SET_LINK_SPEED_10 \
6858 (BNX2_NETLINK_SET_LINK_SPEED_10HALF | \
6859 BNX2_NETLINK_SET_LINK_SPEED_10FULL)
6860#define BNX2_NETLINK_SET_LINK_SPEED_100HALF (1<<2)
6861#define BNX2_NETLINK_SET_LINK_SPEED_100FULL (1<<3)
6862#define BNX2_NETLINK_SET_LINK_SPEED_100 \
6863 (BNX2_NETLINK_SET_LINK_SPEED_100HALF | \
6864 BNX2_NETLINK_SET_LINK_SPEED_100FULL)
6865#define BNX2_NETLINK_SET_LINK_SPEED_1GHALF (1<<4)
6866#define BNX2_NETLINK_SET_LINK_SPEED_1GFULL (1<<5)
6867#define BNX2_NETLINK_SET_LINK_SPEED_2G5HALF (1<<6)
6868#define BNX2_NETLINK_SET_LINK_SPEED_2G5FULL (1<<7)
6869#define BNX2_NETLINK_SET_LINK_SPEED_10GHALF (1<<8)
6870#define BNX2_NETLINK_SET_LINK_SPEED_10GFULL (1<<9)
6871#define BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG (1<<10)
6872#define BNX2_NETLINK_SET_LINK_PHY_APP_REMOTE (1<<11)
6873#define BNX2_NETLINK_SET_LINK_FC_SYM_PAUSE (1<<12)
6874#define BNX2_NETLINK_SET_LINK_FC_ASYM_PAUSE (1<<13)
6875#define BNX2_NETLINK_SET_LINK_ETH_AT_WIRESPEED (1<<14)
6876#define BNX2_NETLINK_SET_LINK_PHY_RESET (1<<15)
6877
6848#define BNX2_DEV_INFO_SIGNATURE 0x00000020 6878#define BNX2_DEV_INFO_SIGNATURE 0x00000020
6849#define BNX2_DEV_INFO_SIGNATURE_MAGIC 0x44564900 6879#define BNX2_DEV_INFO_SIGNATURE_MAGIC 0x44564900
6850#define BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK 0xffffff00 6880#define BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK 0xffffff00
@@ -7006,6 +7036,8 @@ struct fw_info {
7006#define BNX2_PORT_FEATURE_MBA_VLAN_TAG_MASK 0xffff 7036#define BNX2_PORT_FEATURE_MBA_VLAN_TAG_MASK 0xffff
7007#define BNX2_PORT_FEATURE_MBA_VLAN_ENABLE 0x10000 7037#define BNX2_PORT_FEATURE_MBA_VLAN_ENABLE 0x10000
7008 7038
7039#define BNX2_MFW_VER_PTR 0x00000014c
7040
7009#define BNX2_BC_STATE_RESET_TYPE 0x000001c0 7041#define BNX2_BC_STATE_RESET_TYPE 0x000001c0
7010#define BNX2_BC_STATE_RESET_TYPE_SIG 0x00005254 7042#define BNX2_BC_STATE_RESET_TYPE_SIG 0x00005254
7011#define BNX2_BC_STATE_RESET_TYPE_SIG_MASK 0x0000ffff 7043#define BNX2_BC_STATE_RESET_TYPE_SIG_MASK 0x0000ffff
@@ -7059,12 +7091,42 @@ struct fw_info {
7059#define BNX2_BC_STATE_ERR_NO_RXP (BNX2_BC_STATE_SIGN | 0x0600) 7091#define BNX2_BC_STATE_ERR_NO_RXP (BNX2_BC_STATE_SIGN | 0x0600)
7060#define BNX2_BC_STATE_ERR_TOO_MANY_RBUF (BNX2_BC_STATE_SIGN | 0x0700) 7092#define BNX2_BC_STATE_ERR_TOO_MANY_RBUF (BNX2_BC_STATE_SIGN | 0x0700)
7061 7093
7094#define BNX2_BC_STATE_CONDITION 0x000001c8
7095#define BNX2_CONDITION_MFW_RUN_UNKNOWN 0x00000000
7096#define BNX2_CONDITION_MFW_RUN_IPMI 0x00002000
7097#define BNX2_CONDITION_MFW_RUN_UMP 0x00004000
7098#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000
7099#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000
7100#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000
7101
7062#define BNX2_BC_STATE_DEBUG_CMD 0x1dc 7102#define BNX2_BC_STATE_DEBUG_CMD 0x1dc
7063#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000 7103#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000
7064#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE_MASK 0xffff0000 7104#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE_MASK 0xffff0000
7065#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_CNT_MASK 0xffff 7105#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_CNT_MASK 0xffff
7066#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_INFINITE 0xffff 7106#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_INFINITE 0xffff
7067 7107
7108#define BNX2_FW_EVT_CODE_MB 0x354
7109#define BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT 0x00000000
7110#define BNX2_FW_EVT_CODE_LINK_EVENT 0x00000001
7111
7112#define BNX2_DRV_ACK_CAP_MB 0x364
7113#define BNX2_DRV_ACK_CAP_SIGNATURE 0x35450000
7114#define BNX2_CAPABILITY_SIGNATURE_MASK 0xFFFF0000
7115
7116#define BNX2_FW_CAP_MB 0x368
7117#define BNX2_FW_CAP_SIGNATURE 0xaa550000
7118#define BNX2_FW_ACK_DRV_SIGNATURE 0x52500000
7119#define BNX2_FW_CAP_SIGNATURE_MASK 0xffff0000
7120#define BNX2_FW_CAP_REMOTE_PHY_CAPABLE 0x00000001
7121#define BNX2_FW_CAP_REMOTE_PHY_PRESENT 0x00000002
7122
7123#define BNX2_RPHY_SIGNATURE 0x36c
7124#define BNX2_RPHY_LOAD_SIGNATURE 0x5a5a5a5a
7125
7126#define BNX2_RPHY_FLAGS 0x370
7127#define BNX2_RPHY_SERDES_LINK 0x374
7128#define BNX2_RPHY_COPPER_LINK 0x378
7129
7068#define HOST_VIEW_SHMEM_BASE 0x167c00 7130#define HOST_VIEW_SHMEM_BASE 0x167c00
7069 7131
7070#endif 7132#endif
diff --git a/drivers/net/dl2k.c b/drivers/net/dl2k.c
index 74ec64a1625d..a4ace071f1cb 100644
--- a/drivers/net/dl2k.c
+++ b/drivers/net/dl2k.c
@@ -866,9 +866,9 @@ receive_packet (struct net_device *dev)
866 PCI_DMA_FROMDEVICE); 866 PCI_DMA_FROMDEVICE);
867 /* 16 byte align the IP header */ 867 /* 16 byte align the IP header */
868 skb_reserve (skb, 2); 868 skb_reserve (skb, 2);
869 eth_copy_and_sum (skb, 869 skb_copy_to_linear_data (skb,
870 np->rx_skbuff[entry]->data, 870 np->rx_skbuff[entry]->data,
871 pkt_len, 0); 871 pkt_len);
872 skb_put (skb, pkt_len); 872 skb_put (skb, pkt_len);
873 pci_dma_sync_single_for_device(np->pdev, 873 pci_dma_sync_single_for_device(np->pdev,
874 desc->fraginfo & 874 desc->fraginfo &
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 264fa0e2e075..c3de81bf090a 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -104,6 +104,18 @@
104#define PRINTK(args...) printk(KERN_DEBUG args) 104#define PRINTK(args...) printk(KERN_DEBUG args)
105#endif 105#endif
106 106
107#ifdef CONFIG_BLACKFIN
108#define readsb insb
109#define readsw insw
110#define readsl insl
111#define writesb outsb
112#define writesw outsw
113#define writesl outsl
114#define DM9000_IRQ_FLAGS (IRQF_SHARED | IRQF_TRIGGER_HIGH)
115#else
116#define DM9000_IRQ_FLAGS IRQF_SHARED
117#endif
118
107/* 119/*
108 * Transmit timeout, default 5 seconds. 120 * Transmit timeout, default 5 seconds.
109 */ 121 */
@@ -431,6 +443,9 @@ dm9000_probe(struct platform_device *pdev)
431 db->io_addr = (void __iomem *)base; 443 db->io_addr = (void __iomem *)base;
432 db->io_data = (void __iomem *)(base + 4); 444 db->io_data = (void __iomem *)(base + 4);
433 445
446 /* ensure at least we have a default set of IO routines */
447 dm9000_set_io(db, 2);
448
434 } else { 449 } else {
435 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 450 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
436 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 451 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -614,7 +629,7 @@ dm9000_open(struct net_device *dev)
614 629
615 PRINTK2("entering dm9000_open\n"); 630 PRINTK2("entering dm9000_open\n");
616 631
617 if (request_irq(dev->irq, &dm9000_interrupt, IRQF_SHARED, dev->name, dev)) 632 if (request_irq(dev->irq, &dm9000_interrupt, DM9000_IRQ_FLAGS, dev->name, dev))
618 return -EAGAIN; 633 return -EAGAIN;
619 634
620 /* Initialize DM9000 board */ 635 /* Initialize DM9000 board */
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 60673bc292c0..756a6bcb038d 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -34,11 +34,12 @@
34#include <linux/etherdevice.h> 34#include <linux/etherdevice.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/moduleparam.h> 36#include <linux/moduleparam.h>
37#include <linux/rtnetlink.h>
38#include <net/rtnetlink.h>
37 39
38static int numdummies = 1; 40static int numdummies = 1;
39 41
40static int dummy_xmit(struct sk_buff *skb, struct net_device *dev); 42static int dummy_xmit(struct sk_buff *skb, struct net_device *dev);
41static struct net_device_stats *dummy_get_stats(struct net_device *dev);
42 43
43static int dummy_set_address(struct net_device *dev, void *p) 44static int dummy_set_address(struct net_device *dev, void *p)
44{ 45{
@@ -56,13 +57,13 @@ static void set_multicast_list(struct net_device *dev)
56{ 57{
57} 58}
58 59
59static void __init dummy_setup(struct net_device *dev) 60static void dummy_setup(struct net_device *dev)
60{ 61{
61 /* Initialize the device structure. */ 62 /* Initialize the device structure. */
62 dev->get_stats = dummy_get_stats;
63 dev->hard_start_xmit = dummy_xmit; 63 dev->hard_start_xmit = dummy_xmit;
64 dev->set_multicast_list = set_multicast_list; 64 dev->set_multicast_list = set_multicast_list;
65 dev->set_mac_address = dummy_set_address; 65 dev->set_mac_address = dummy_set_address;
66 dev->destructor = free_netdev;
66 67
67 /* Fill in device structure with ethernet-generic values. */ 68 /* Fill in device structure with ethernet-generic values. */
68 ether_setup(dev); 69 ether_setup(dev);
@@ -76,77 +77,80 @@ static void __init dummy_setup(struct net_device *dev)
76 77
77static int dummy_xmit(struct sk_buff *skb, struct net_device *dev) 78static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
78{ 79{
79 struct net_device_stats *stats = netdev_priv(dev); 80 dev->stats.tx_packets++;
80 81 dev->stats.tx_bytes += skb->len;
81 stats->tx_packets++;
82 stats->tx_bytes+=skb->len;
83 82
84 dev_kfree_skb(skb); 83 dev_kfree_skb(skb);
85 return 0; 84 return 0;
86} 85}
87 86
88static struct net_device_stats *dummy_get_stats(struct net_device *dev) 87static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
89{ 88{
90 return netdev_priv(dev); 89 if (tb[IFLA_ADDRESS]) {
90 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
91 return -EINVAL;
92 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
93 return -EADDRNOTAVAIL;
94 }
95 return 0;
91} 96}
92 97
93static struct net_device **dummies; 98static struct rtnl_link_ops dummy_link_ops __read_mostly = {
99 .kind = "dummy",
100 .setup = dummy_setup,
101 .validate = dummy_validate,
102};
94 103
95/* Number of dummy devices to be set up by this module. */ 104/* Number of dummy devices to be set up by this module. */
96module_param(numdummies, int, 0); 105module_param(numdummies, int, 0);
97MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices"); 106MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices");
98 107
99static int __init dummy_init_one(int index) 108static int __init dummy_init_one(void)
100{ 109{
101 struct net_device *dev_dummy; 110 struct net_device *dev_dummy;
102 int err; 111 int err;
103 112
104 dev_dummy = alloc_netdev(sizeof(struct net_device_stats), 113 dev_dummy = alloc_netdev(0, "dummy%d", dummy_setup);
105 "dummy%d", dummy_setup);
106
107 if (!dev_dummy) 114 if (!dev_dummy)
108 return -ENOMEM; 115 return -ENOMEM;
109 116
110 if ((err = register_netdev(dev_dummy))) { 117 err = dev_alloc_name(dev_dummy, dev_dummy->name);
111 free_netdev(dev_dummy); 118 if (err < 0)
112 dev_dummy = NULL; 119 goto err;
113 } else {
114 dummies[index] = dev_dummy;
115 }
116 120
117 return err; 121 dev_dummy->rtnl_link_ops = &dummy_link_ops;
118} 122 err = register_netdevice(dev_dummy);
123 if (err < 0)
124 goto err;
125 return 0;
119 126
120static void dummy_free_one(int index) 127err:
121{ 128 free_netdev(dev_dummy);
122 unregister_netdev(dummies[index]); 129 return err;
123 free_netdev(dummies[index]);
124} 130}
125 131
126static int __init dummy_init_module(void) 132static int __init dummy_init_module(void)
127{ 133{
128 int i, err = 0; 134 int i, err = 0;
129 dummies = kmalloc(numdummies * sizeof(void *), GFP_KERNEL); 135
130 if (!dummies) 136 rtnl_lock();
131 return -ENOMEM; 137 err = __rtnl_link_register(&dummy_link_ops);
138
132 for (i = 0; i < numdummies && !err; i++) 139 for (i = 0; i < numdummies && !err; i++)
133 err = dummy_init_one(i); 140 err = dummy_init_one();
134 if (err) { 141 if (err < 0)
135 i--; 142 __rtnl_link_unregister(&dummy_link_ops);
136 while (--i >= 0) 143 rtnl_unlock();
137 dummy_free_one(i); 144
138 }
139 return err; 145 return err;
140} 146}
141 147
142static void __exit dummy_cleanup_module(void) 148static void __exit dummy_cleanup_module(void)
143{ 149{
144 int i; 150 rtnl_link_unregister(&dummy_link_ops);
145 for (i = 0; i < numdummies; i++)
146 dummy_free_one(i);
147 kfree(dummies);
148} 151}
149 152
150module_init(dummy_init_module); 153module_init(dummy_init_module);
151module_exit(dummy_cleanup_module); 154module_exit(dummy_cleanup_module);
152MODULE_LICENSE("GPL"); 155MODULE_LICENSE("GPL");
156MODULE_ALIAS_RTNL_LINK("dummy");
diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c
index 9800341956a2..9afa47edfc58 100644
--- a/drivers/net/eepro100.c
+++ b/drivers/net/eepro100.c
@@ -1801,7 +1801,7 @@ speedo_rx(struct net_device *dev)
1801 1801
1802#if 1 || USE_IP_CSUM 1802#if 1 || USE_IP_CSUM
1803 /* Packet is in one chunk -- we can copy + cksum. */ 1803 /* Packet is in one chunk -- we can copy + cksum. */
1804 eth_copy_and_sum(skb, sp->rx_skbuff[entry]->data, pkt_len, 0); 1804 skb_copy_to_linear_data(skb, sp->rx_skbuff[entry]->data, pkt_len);
1805 skb_put(skb, pkt_len); 1805 skb_put(skb, pkt_len);
1806#else 1806#else
1807 skb_copy_from_linear_data(sp->rx_skbuff[entry], 1807 skb_copy_from_linear_data(sp->rx_skbuff[entry],
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index 5e517946f46a..119778401e48 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -1201,7 +1201,7 @@ static int epic_rx(struct net_device *dev, int budget)
1201 ep->rx_ring[entry].bufaddr, 1201 ep->rx_ring[entry].bufaddr,
1202 ep->rx_buf_sz, 1202 ep->rx_buf_sz,
1203 PCI_DMA_FROMDEVICE); 1203 PCI_DMA_FROMDEVICE);
1204 eth_copy_and_sum(skb, ep->rx_skbuff[entry]->data, pkt_len, 0); 1204 skb_copy_to_linear_data(skb, ep->rx_skbuff[entry]->data, pkt_len);
1205 skb_put(skb, pkt_len); 1205 skb_put(skb, pkt_len);
1206 pci_dma_sync_single_for_device(ep->pci_dev, 1206 pci_dma_sync_single_for_device(ep->pci_dev,
1207 ep->rx_ring[entry].bufaddr, 1207 ep->rx_ring[entry].bufaddr,
diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
index abe9b089c610..ff9f177d7157 100644
--- a/drivers/net/fealnx.c
+++ b/drivers/net/fealnx.c
@@ -1727,8 +1727,8 @@ static int netdev_rx(struct net_device *dev)
1727 /* Call copy + cksum if available. */ 1727 /* Call copy + cksum if available. */
1728 1728
1729#if ! defined(__alpha__) 1729#if ! defined(__alpha__)
1730 eth_copy_and_sum(skb, 1730 skb_copy_to_linear_data(skb,
1731 np->cur_rx->skbuff->data, pkt_len, 0); 1731 np->cur_rx->skbuff->data, pkt_len);
1732 skb_put(skb, pkt_len); 1732 skb_put(skb, pkt_len);
1733#else 1733#else
1734 memcpy(skb_put(skb, pkt_len), 1734 memcpy(skb_put(skb, pkt_len),
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 255b09124e11..03023dd17829 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -648,7 +648,7 @@ while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
648 fep->stats.rx_dropped++; 648 fep->stats.rx_dropped++;
649 } else { 649 } else {
650 skb_put(skb,pkt_len-4); /* Make room */ 650 skb_put(skb,pkt_len-4); /* Make room */
651 eth_copy_and_sum(skb, data, pkt_len-4, 0); 651 skb_copy_to_linear_data(skb, data, pkt_len-4);
652 skb->protocol=eth_type_trans(skb,dev); 652 skb->protocol=eth_type_trans(skb,dev);
653 netif_rx(skb); 653 netif_rx(skb);
654 } 654 }
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index 2521b111b3a5..15254dc7876a 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -1575,8 +1575,8 @@ static int hamachi_rx(struct net_device *dev)
1575 PCI_DMA_FROMDEVICE); 1575 PCI_DMA_FROMDEVICE);
1576 /* Call copy + cksum if available. */ 1576 /* Call copy + cksum if available. */
1577#if 1 || USE_IP_COPYSUM 1577#if 1 || USE_IP_COPYSUM
1578 eth_copy_and_sum(skb, 1578 skb_copy_to_linear_data(skb,
1579 hmp->rx_skbuff[entry]->data, pkt_len, 0); 1579 hmp->rx_skbuff[entry]->data, pkt_len);
1580 skb_put(skb, pkt_len); 1580 skb_put(skb, pkt_len);
1581#else 1581#else
1582 memcpy(skb_put(skb, pkt_len), hmp->rx_ring_dma 1582 memcpy(skb_put(skb, pkt_len), hmp->rx_ring_dma
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 07b4c0d7a75c..f5c3598e59af 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -136,13 +136,14 @@ resched:
136 136
137} 137}
138 138
139static void __init ifb_setup(struct net_device *dev) 139static void ifb_setup(struct net_device *dev)
140{ 140{
141 /* Initialize the device structure. */ 141 /* Initialize the device structure. */
142 dev->get_stats = ifb_get_stats; 142 dev->get_stats = ifb_get_stats;
143 dev->hard_start_xmit = ifb_xmit; 143 dev->hard_start_xmit = ifb_xmit;
144 dev->open = &ifb_open; 144 dev->open = &ifb_open;
145 dev->stop = &ifb_close; 145 dev->stop = &ifb_close;
146 dev->destructor = free_netdev;
146 147
147 /* Fill in device structure with ethernet-generic values. */ 148 /* Fill in device structure with ethernet-generic values. */
148 ether_setup(dev); 149 ether_setup(dev);
@@ -197,12 +198,6 @@ static struct net_device_stats *ifb_get_stats(struct net_device *dev)
197 return stats; 198 return stats;
198} 199}
199 200
200static struct net_device **ifbs;
201
202/* Number of ifb devices to be set up by this module. */
203module_param(numifbs, int, 0);
204MODULE_PARM_DESC(numifbs, "Number of ifb devices");
205
206static int ifb_close(struct net_device *dev) 201static int ifb_close(struct net_device *dev)
207{ 202{
208 struct ifb_private *dp = netdev_priv(dev); 203 struct ifb_private *dp = netdev_priv(dev);
@@ -226,6 +221,28 @@ static int ifb_open(struct net_device *dev)
226 return 0; 221 return 0;
227} 222}
228 223
224static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
225{
226 if (tb[IFLA_ADDRESS]) {
227 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
228 return -EINVAL;
229 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
230 return -EADDRNOTAVAIL;
231 }
232 return 0;
233}
234
235static struct rtnl_link_ops ifb_link_ops __read_mostly = {
236 .kind = "ifb",
237 .priv_size = sizeof(struct ifb_private),
238 .setup = ifb_setup,
239 .validate = ifb_validate,
240};
241
242/* Number of ifb devices to be set up by this module. */
243module_param(numifbs, int, 0);
244MODULE_PARM_DESC(numifbs, "Number of ifb devices");
245
229static int __init ifb_init_one(int index) 246static int __init ifb_init_one(int index)
230{ 247{
231 struct net_device *dev_ifb; 248 struct net_device *dev_ifb;
@@ -237,49 +254,44 @@ static int __init ifb_init_one(int index)
237 if (!dev_ifb) 254 if (!dev_ifb)
238 return -ENOMEM; 255 return -ENOMEM;
239 256
240 if ((err = register_netdev(dev_ifb))) { 257 err = dev_alloc_name(dev_ifb, dev_ifb->name);
241 free_netdev(dev_ifb); 258 if (err < 0)
242 dev_ifb = NULL; 259 goto err;
243 } else {
244 ifbs[index] = dev_ifb;
245 }
246 260
247 return err; 261 dev_ifb->rtnl_link_ops = &ifb_link_ops;
248} 262 err = register_netdevice(dev_ifb);
263 if (err < 0)
264 goto err;
265 return 0;
249 266
250static void ifb_free_one(int index) 267err:
251{ 268 free_netdev(dev_ifb);
252 unregister_netdev(ifbs[index]); 269 return err;
253 free_netdev(ifbs[index]);
254} 270}
255 271
256static int __init ifb_init_module(void) 272static int __init ifb_init_module(void)
257{ 273{
258 int i, err = 0; 274 int i, err;
259 ifbs = kmalloc(numifbs * sizeof(void *), GFP_KERNEL); 275
260 if (!ifbs) 276 rtnl_lock();
261 return -ENOMEM; 277 err = __rtnl_link_register(&ifb_link_ops);
278
262 for (i = 0; i < numifbs && !err; i++) 279 for (i = 0; i < numifbs && !err; i++)
263 err = ifb_init_one(i); 280 err = ifb_init_one(i);
264 if (err) { 281 if (err)
265 i--; 282 __rtnl_link_unregister(&ifb_link_ops);
266 while (--i >= 0) 283 rtnl_unlock();
267 ifb_free_one(i);
268 }
269 284
270 return err; 285 return err;
271} 286}
272 287
273static void __exit ifb_cleanup_module(void) 288static void __exit ifb_cleanup_module(void)
274{ 289{
275 int i; 290 rtnl_link_unregister(&ifb_link_ops);
276
277 for (i = 0; i < numifbs; i++)
278 ifb_free_one(i);
279 kfree(ifbs);
280} 291}
281 292
282module_init(ifb_init_module); 293module_init(ifb_init_module);
283module_exit(ifb_cleanup_module); 294module_exit(ifb_cleanup_module);
284MODULE_LICENSE("GPL"); 295MODULE_LICENSE("GPL");
285MODULE_AUTHOR("Jamal Hadi Salim"); 296MODULE_AUTHOR("Jamal Hadi Salim");
297MODULE_ALIAS_RTNL_LINK("ifb");
diff --git a/drivers/net/irda/kingsun-sir.c b/drivers/net/irda/kingsun-sir.c
index 217429122e79..bdd5c979bead 100644
--- a/drivers/net/irda/kingsun-sir.c
+++ b/drivers/net/irda/kingsun-sir.c
@@ -4,7 +4,7 @@
4* Version: 0.1.1 4* Version: 0.1.1
5* Description: Irda KingSun/DonShine USB Dongle 5* Description: Irda KingSun/DonShine USB Dongle
6* Status: Experimental 6* Status: Experimental
7* Author: Alex Villac�s Lasso <a_villacis@palosanto.com> 7* Author: Alex Villacís Lasso <a_villacis@palosanto.com>
8* 8*
9* Based on stir4200 and mcs7780 drivers, with (strange?) differences 9* Based on stir4200 and mcs7780 drivers, with (strange?) differences
10* 10*
@@ -652,6 +652,6 @@ static void __exit kingsun_cleanup(void)
652} 652}
653module_exit(kingsun_cleanup); 653module_exit(kingsun_cleanup);
654 654
655MODULE_AUTHOR("Alex Villac�s Lasso <a_villacis@palosanto.com>"); 655MODULE_AUTHOR("Alex Villacís Lasso <a_villacis@palosanto.com>");
656MODULE_DESCRIPTION("IrDA-USB Dongle Driver for KingSun/DonShine"); 656MODULE_DESCRIPTION("IrDA-USB Dongle Driver for KingSun/DonShine");
657MODULE_LICENSE("GPL"); 657MODULE_LICENSE("GPL");
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index bf78ef1120ad..0538ca9ce058 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -44,6 +44,7 @@ MODULE_LICENSE("GPL");
44#include <linux/time.h> 44#include <linux/time.h>
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/seq_file.h> 46#include <linux/seq_file.h>
47#include <linux/mutex.h>
47#include <asm/uaccess.h> 48#include <asm/uaccess.h>
48#include <asm/byteorder.h> 49#include <asm/byteorder.h>
49 50
@@ -1660,8 +1661,8 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1660 idev = ndev->priv; 1661 idev = ndev->priv;
1661 1662
1662 spin_lock_init(&idev->lock); 1663 spin_lock_init(&idev->lock);
1663 init_MUTEX(&idev->sem); 1664 mutex_init(&idev->mtx);
1664 down(&idev->sem); 1665 mutex_lock(&idev->mtx);
1665 idev->pdev = pdev; 1666 idev->pdev = pdev;
1666 1667
1667 if (vlsi_irda_init(ndev) < 0) 1668 if (vlsi_irda_init(ndev) < 0)
@@ -1689,12 +1690,12 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1689 IRDA_MESSAGE("%s: registered device %s\n", drivername, ndev->name); 1690 IRDA_MESSAGE("%s: registered device %s\n", drivername, ndev->name);
1690 1691
1691 pci_set_drvdata(pdev, ndev); 1692 pci_set_drvdata(pdev, ndev);
1692 up(&idev->sem); 1693 mutex_unlock(&idev->mtx);
1693 1694
1694 return 0; 1695 return 0;
1695 1696
1696out_freedev: 1697out_freedev:
1697 up(&idev->sem); 1698 mutex_unlock(&idev->mtx);
1698 free_netdev(ndev); 1699 free_netdev(ndev);
1699out_disable: 1700out_disable:
1700 pci_disable_device(pdev); 1701 pci_disable_device(pdev);
@@ -1716,12 +1717,12 @@ static void __devexit vlsi_irda_remove(struct pci_dev *pdev)
1716 unregister_netdev(ndev); 1717 unregister_netdev(ndev);
1717 1718
1718 idev = ndev->priv; 1719 idev = ndev->priv;
1719 down(&idev->sem); 1720 mutex_lock(&idev->mtx);
1720 if (idev->proc_entry) { 1721 if (idev->proc_entry) {
1721 remove_proc_entry(ndev->name, vlsi_proc_root); 1722 remove_proc_entry(ndev->name, vlsi_proc_root);
1722 idev->proc_entry = NULL; 1723 idev->proc_entry = NULL;
1723 } 1724 }
1724 up(&idev->sem); 1725 mutex_unlock(&idev->mtx);
1725 1726
1726 free_netdev(ndev); 1727 free_netdev(ndev);
1727 1728
@@ -1751,7 +1752,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1751 return 0; 1752 return 0;
1752 } 1753 }
1753 idev = ndev->priv; 1754 idev = ndev->priv;
1754 down(&idev->sem); 1755 mutex_lock(&idev->mtx);
1755 if (pdev->current_state != 0) { /* already suspended */ 1756 if (pdev->current_state != 0) { /* already suspended */
1756 if (state.event > pdev->current_state) { /* simply go deeper */ 1757 if (state.event > pdev->current_state) { /* simply go deeper */
1757 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1758 pci_set_power_state(pdev, pci_choose_state(pdev, state));
@@ -1759,7 +1760,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1759 } 1760 }
1760 else 1761 else
1761 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, pci_name(pdev), pdev->current_state, state.event); 1762 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, pci_name(pdev), pdev->current_state, state.event);
1762 up(&idev->sem); 1763 mutex_unlock(&idev->mtx);
1763 return 0; 1764 return 0;
1764 } 1765 }
1765 1766
@@ -1775,7 +1776,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1775 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1776 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1776 pdev->current_state = state.event; 1777 pdev->current_state = state.event;
1777 idev->resume_ok = 1; 1778 idev->resume_ok = 1;
1778 up(&idev->sem); 1779 mutex_unlock(&idev->mtx);
1779 return 0; 1780 return 0;
1780} 1781}
1781 1782
@@ -1790,9 +1791,9 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1790 return 0; 1791 return 0;
1791 } 1792 }
1792 idev = ndev->priv; 1793 idev = ndev->priv;
1793 down(&idev->sem); 1794 mutex_lock(&idev->mtx);
1794 if (pdev->current_state == 0) { 1795 if (pdev->current_state == 0) {
1795 up(&idev->sem); 1796 mutex_unlock(&idev->mtx);
1796 IRDA_WARNING("%s - %s: already resumed\n", 1797 IRDA_WARNING("%s - %s: already resumed\n",
1797 __FUNCTION__, pci_name(pdev)); 1798 __FUNCTION__, pci_name(pdev));
1798 return 0; 1799 return 0;
@@ -1814,7 +1815,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1814 * device and independently resume_ok should catch any garbage config. 1815 * device and independently resume_ok should catch any garbage config.
1815 */ 1816 */
1816 IRDA_WARNING("%s - hm, nothing to resume?\n", __FUNCTION__); 1817 IRDA_WARNING("%s - hm, nothing to resume?\n", __FUNCTION__);
1817 up(&idev->sem); 1818 mutex_unlock(&idev->mtx);
1818 return 0; 1819 return 0;
1819 } 1820 }
1820 1821
@@ -1824,7 +1825,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1824 netif_device_attach(ndev); 1825 netif_device_attach(ndev);
1825 } 1826 }
1826 idev->resume_ok = 0; 1827 idev->resume_ok = 0;
1827 up(&idev->sem); 1828 mutex_unlock(&idev->mtx);
1828 return 0; 1829 return 0;
1829} 1830}
1830 1831
diff --git a/drivers/net/irda/vlsi_ir.h b/drivers/net/irda/vlsi_ir.h
index 2d3b773d8e35..ca12a6096419 100644
--- a/drivers/net/irda/vlsi_ir.h
+++ b/drivers/net/irda/vlsi_ir.h
@@ -728,7 +728,7 @@ typedef struct vlsi_irda_dev {
728 struct timeval last_rx; 728 struct timeval last_rx;
729 729
730 spinlock_t lock; 730 spinlock_t lock;
731 struct semaphore sem; 731 struct mutex mtx;
732 732
733 u8 resume_ok; 733 u8 resume_ok;
734 struct proc_dir_entry *proc_entry; 734 struct proc_dir_entry *proc_entry;
diff --git a/drivers/net/ixp2000/ixpdev.c b/drivers/net/ixp2000/ixpdev.c
index d5f694fc4a21..d9ce1aef148a 100644
--- a/drivers/net/ixp2000/ixpdev.c
+++ b/drivers/net/ixp2000/ixpdev.c
@@ -111,7 +111,7 @@ static int ixpdev_rx(struct net_device *dev, int *budget)
111 skb = dev_alloc_skb(desc->pkt_length + 2); 111 skb = dev_alloc_skb(desc->pkt_length + 2);
112 if (likely(skb != NULL)) { 112 if (likely(skb != NULL)) {
113 skb_reserve(skb, 2); 113 skb_reserve(skb, 2);
114 eth_copy_and_sum(skb, buf, desc->pkt_length, 0); 114 skb_copy_to_linear_data(skb, buf, desc->pkt_length);
115 skb_put(skb, desc->pkt_length); 115 skb_put(skb, desc->pkt_length);
116 skb->protocol = eth_type_trans(skb, nds[desc->channel]); 116 skb->protocol = eth_type_trans(skb, nds[desc->channel]);
117 117
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index 0fe96c85828b..a2f37e52b928 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -1186,9 +1186,9 @@ lance_rx(struct net_device *dev)
1186 } 1186 }
1187 skb_reserve(skb,2); /* 16 byte align */ 1187 skb_reserve(skb,2); /* 16 byte align */
1188 skb_put(skb,pkt_len); /* Make room */ 1188 skb_put(skb,pkt_len); /* Make room */
1189 eth_copy_and_sum(skb, 1189 skb_copy_to_linear_data(skb,
1190 (unsigned char *)isa_bus_to_virt((lp->rx_ring[entry].base & 0x00ffffff)), 1190 (unsigned char *)isa_bus_to_virt((lp->rx_ring[entry].base & 0x00ffffff)),
1191 pkt_len,0); 1191 pkt_len);
1192 skb->protocol=eth_type_trans(skb,dev); 1192 skb->protocol=eth_type_trans(skb,dev);
1193 netif_rx(skb); 1193 netif_rx(skb);
1194 dev->last_rx = jiffies; 1194 dev->last_rx = jiffies;
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index 460a08718c69..3450051ae56b 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -2357,8 +2357,8 @@ static void netdev_rx(struct net_device *dev, int *work_done, int work_to_do)
2357 np->rx_dma[entry], 2357 np->rx_dma[entry],
2358 buflen, 2358 buflen,
2359 PCI_DMA_FROMDEVICE); 2359 PCI_DMA_FROMDEVICE);
2360 eth_copy_and_sum(skb, 2360 skb_copy_to_linear_data(skb,
2361 np->rx_skbuff[entry]->data, pkt_len, 0); 2361 np->rx_skbuff[entry]->data, pkt_len);
2362 skb_put(skb, pkt_len); 2362 skb_put(skb, pkt_len);
2363 pci_dma_sync_single_for_device(np->pci_dev, 2363 pci_dma_sync_single_for_device(np->pci_dev,
2364 np->rx_dma[entry], 2364 np->rx_dma[entry],
diff --git a/drivers/net/ni52.c b/drivers/net/ni52.c
index 8dbd6d1900b5..5e7999db2096 100644
--- a/drivers/net/ni52.c
+++ b/drivers/net/ni52.c
@@ -936,7 +936,7 @@ static void ni52_rcv_int(struct net_device *dev)
936 { 936 {
937 skb_reserve(skb,2); 937 skb_reserve(skb,2);
938 skb_put(skb,totlen); 938 skb_put(skb,totlen);
939 eth_copy_and_sum(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen,0); 939 skb_copy_to_linear_data(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen);
940 skb->protocol=eth_type_trans(skb,dev); 940 skb->protocol=eth_type_trans(skb,dev);
941 netif_rx(skb); 941 netif_rx(skb);
942 dev->last_rx = jiffies; 942 dev->last_rx = jiffies;
diff --git a/drivers/net/ni65.c b/drivers/net/ni65.c
index 3818edf0ac18..4ef5fe345191 100644
--- a/drivers/net/ni65.c
+++ b/drivers/net/ni65.c
@@ -1096,7 +1096,7 @@ static void ni65_recv_intr(struct net_device *dev,int csr0)
1096#ifdef RCV_VIA_SKB 1096#ifdef RCV_VIA_SKB
1097 if( (unsigned long) (skb->data + R_BUF_SIZE) > 0x1000000) { 1097 if( (unsigned long) (skb->data + R_BUF_SIZE) > 0x1000000) {
1098 skb_put(skb,len); 1098 skb_put(skb,len);
1099 eth_copy_and_sum(skb, (unsigned char *)(p->recv_skb[p->rmdnum]->data),len,0); 1099 skb_copy_to_linear_data(skb, (unsigned char *)(p->recv_skb[p->rmdnum]->data),len);
1100 } 1100 }
1101 else { 1101 else {
1102 struct sk_buff *skb1 = p->recv_skb[p->rmdnum]; 1102 struct sk_buff *skb1 = p->recv_skb[p->rmdnum];
@@ -1108,7 +1108,7 @@ static void ni65_recv_intr(struct net_device *dev,int csr0)
1108 } 1108 }
1109#else 1109#else
1110 skb_put(skb,len); 1110 skb_put(skb,len);
1111 eth_copy_and_sum(skb, (unsigned char *) p->recvbounce[p->rmdnum],len,0); 1111 skb_copy_to_linear_data(skb, (unsigned char *) p->recvbounce[p->rmdnum],len);
1112#endif 1112#endif
1113 p->stats.rx_packets++; 1113 p->stats.rx_packets++;
1114 p->stats.rx_bytes += len; 1114 p->stats.rx_bytes += len;
diff --git a/drivers/net/pci-skeleton.c b/drivers/net/pci-skeleton.c
index df8998b4f37e..3cdbe118200b 100644
--- a/drivers/net/pci-skeleton.c
+++ b/drivers/net/pci-skeleton.c
@@ -1567,7 +1567,7 @@ static void netdrv_rx_interrupt (struct net_device *dev,
1567 if (skb) { 1567 if (skb) {
1568 skb_reserve (skb, 2); /* 16 byte align the IP fields. */ 1568 skb_reserve (skb, 2); /* 16 byte align the IP fields. */
1569 1569
1570 eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0); 1570 skb_copy_to_linear_data (skb, &rx_ring[ring_offset + 4], pkt_size);
1571 skb_put (skb, pkt_size); 1571 skb_put (skb, pkt_size);
1572 1572
1573 skb->protocol = eth_type_trans (skb, dev); 1573 skb->protocol = eth_type_trans (skb, dev);
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 9c171a7390e2..465485a3fbc6 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -1235,9 +1235,9 @@ static void pcnet32_rx_entry(struct net_device *dev,
1235 lp->rx_dma_addr[entry], 1235 lp->rx_dma_addr[entry],
1236 pkt_len, 1236 pkt_len,
1237 PCI_DMA_FROMDEVICE); 1237 PCI_DMA_FROMDEVICE);
1238 eth_copy_and_sum(skb, 1238 skb_copy_to_linear_data(skb,
1239 (unsigned char *)(lp->rx_skbuff[entry]->data), 1239 (unsigned char *)(lp->rx_skbuff[entry]->data),
1240 pkt_len, 0); 1240 pkt_len);
1241 pci_dma_sync_single_for_device(lp->pci_dev, 1241 pci_dma_sync_single_for_device(lp->pci_dev,
1242 lp->rx_dma_addr[entry], 1242 lp->rx_dma_addr[entry],
1243 pkt_len, 1243 pkt_len,
diff --git a/drivers/net/pppol2tp.c b/drivers/net/pppol2tp.c
new file mode 100644
index 000000000000..5891a0fbdc8b
--- /dev/null
+++ b/drivers/net/pppol2tp.c
@@ -0,0 +1,2486 @@
1/*****************************************************************************
2 * Linux PPP over L2TP (PPPoX/PPPoL2TP) Sockets
3 *
4 * PPPoX --- Generic PPP encapsulation socket family
5 * PPPoL2TP --- PPP over L2TP (RFC 2661)
6 *
7 * Version: 1.0.0
8 *
9 * Authors: Martijn van Oosterhout <kleptog@svana.org>
10 * James Chapman (jchapman@katalix.com)
11 * Contributors:
12 * Michal Ostrowski <mostrows@speakeasy.net>
13 * Arnaldo Carvalho de Melo <acme@xconectiva.com.br>
14 * David S. Miller (davem@redhat.com)
15 *
16 * License:
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 *
22 */
23
24/* This driver handles only L2TP data frames; control frames are handled by a
25 * userspace application.
26 *
27 * To send data in an L2TP session, userspace opens a PPPoL2TP socket and
28 * attaches it to a bound UDP socket with local tunnel_id / session_id and
29 * peer tunnel_id / session_id set. Data can then be sent or received using
30 * regular socket sendmsg() / recvmsg() calls. Kernel parameters of the socket
31 * can be read or modified using ioctl() or [gs]etsockopt() calls.
32 *
33 * When a PPPoL2TP socket is connected with local and peer session_id values
34 * zero, the socket is treated as a special tunnel management socket.
35 *
36 * Here's example userspace code to create a socket for sending/receiving data
37 * over an L2TP session:-
38 *
39 * struct sockaddr_pppol2tp sax;
40 * int fd;
41 * int session_fd;
42 *
43 * fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
44 *
45 * sax.sa_family = AF_PPPOX;
46 * sax.sa_protocol = PX_PROTO_OL2TP;
47 * sax.pppol2tp.fd = tunnel_fd; // bound UDP socket
48 * sax.pppol2tp.addr.sin_addr.s_addr = addr->sin_addr.s_addr;
49 * sax.pppol2tp.addr.sin_port = addr->sin_port;
50 * sax.pppol2tp.addr.sin_family = AF_INET;
51 * sax.pppol2tp.s_tunnel = tunnel_id;
52 * sax.pppol2tp.s_session = session_id;
53 * sax.pppol2tp.d_tunnel = peer_tunnel_id;
54 * sax.pppol2tp.d_session = peer_session_id;
55 *
56 * session_fd = connect(fd, (struct sockaddr *)&sax, sizeof(sax));
57 *
58 * A pppd plugin that allows PPP traffic to be carried over L2TP using
59 * this driver is available from the OpenL2TP project at
60 * http://openl2tp.sourceforge.net.
61 */
62
63#include <linux/module.h>
64#include <linux/version.h>
65#include <linux/string.h>
66#include <linux/list.h>
67#include <asm/uaccess.h>
68
69#include <linux/kernel.h>
70#include <linux/spinlock.h>
71#include <linux/kthread.h>
72#include <linux/sched.h>
73#include <linux/slab.h>
74#include <linux/errno.h>
75#include <linux/jiffies.h>
76
77#include <linux/netdevice.h>
78#include <linux/net.h>
79#include <linux/inetdevice.h>
80#include <linux/skbuff.h>
81#include <linux/init.h>
82#include <linux/ip.h>
83#include <linux/udp.h>
84#include <linux/if_pppox.h>
85#include <linux/if_pppol2tp.h>
86#include <net/sock.h>
87#include <linux/ppp_channel.h>
88#include <linux/ppp_defs.h>
89#include <linux/if_ppp.h>
90#include <linux/file.h>
91#include <linux/hash.h>
92#include <linux/sort.h>
93#include <linux/proc_fs.h>
94#include <net/dst.h>
95#include <net/ip.h>
96#include <net/udp.h>
97#include <net/xfrm.h>
98
99#include <asm/byteorder.h>
100#include <asm/atomic.h>
101
102
103#define PPPOL2TP_DRV_VERSION "V1.0"
104
105/* L2TP header constants */
106#define L2TP_HDRFLAG_T 0x8000
107#define L2TP_HDRFLAG_L 0x4000
108#define L2TP_HDRFLAG_S 0x0800
109#define L2TP_HDRFLAG_O 0x0200
110#define L2TP_HDRFLAG_P 0x0100
111
112#define L2TP_HDR_VER_MASK 0x000F
113#define L2TP_HDR_VER 0x0002
114
115/* Space for UDP, L2TP and PPP headers */
116#define PPPOL2TP_HEADER_OVERHEAD 40
117
118/* Just some random numbers */
119#define L2TP_TUNNEL_MAGIC 0x42114DDA
120#define L2TP_SESSION_MAGIC 0x0C04EB7D
121
122#define PPPOL2TP_HASH_BITS 4
123#define PPPOL2TP_HASH_SIZE (1 << PPPOL2TP_HASH_BITS)
124
125/* Default trace flags */
126#define PPPOL2TP_DEFAULT_DEBUG_FLAGS 0
127
128#define PRINTK(_mask, _type, _lvl, _fmt, args...) \
129 do { \
130 if ((_mask) & (_type)) \
131 printk(_lvl "PPPOL2TP: " _fmt, ##args); \
132 } while(0)
133
134/* Number of bytes to build transmit L2TP headers.
135 * Unfortunately the size is different depending on whether sequence numbers
136 * are enabled.
137 */
138#define PPPOL2TP_L2TP_HDR_SIZE_SEQ 10
139#define PPPOL2TP_L2TP_HDR_SIZE_NOSEQ 6
140
141struct pppol2tp_tunnel;
142
143/* Describes a session. It is the sk_user_data field in the PPPoL2TP
144 * socket. Contains information to determine incoming packets and transmit
145 * outgoing ones.
146 */
147struct pppol2tp_session
148{
149 int magic; /* should be
150 * L2TP_SESSION_MAGIC */
151 int owner; /* pid that opened the socket */
152
153 struct sock *sock; /* Pointer to the session
154 * PPPoX socket */
155 struct sock *tunnel_sock; /* Pointer to the tunnel UDP
156 * socket */
157
158 struct pppol2tp_addr tunnel_addr; /* Description of tunnel */
159
160 struct pppol2tp_tunnel *tunnel; /* back pointer to tunnel
161 * context */
162
163 char name[20]; /* "sess xxxxx/yyyyy", where
164 * x=tunnel_id, y=session_id */
165 int mtu;
166 int mru;
167 int flags; /* accessed by PPPIOCGFLAGS.
168 * Unused. */
169 unsigned recv_seq:1; /* expect receive packets with
170 * sequence numbers? */
171 unsigned send_seq:1; /* send packets with sequence
172 * numbers? */
173 unsigned lns_mode:1; /* behave as LNS? LAC enables
174 * sequence numbers under
175 * control of LNS. */
176 int debug; /* bitmask of debug message
177 * categories */
178 int reorder_timeout; /* configured reorder timeout
179 * (in jiffies) */
180 u16 nr; /* session NR state (receive) */
181 u16 ns; /* session NR state (send) */
182 struct sk_buff_head reorder_q; /* receive reorder queue */
183 struct pppol2tp_ioc_stats stats;
184 struct hlist_node hlist; /* Hash list node */
185};
186
187/* The sk_user_data field of the tunnel's UDP socket. It contains info to track
188 * all the associated sessions so incoming packets can be sorted out
189 */
190struct pppol2tp_tunnel
191{
192 int magic; /* Should be L2TP_TUNNEL_MAGIC */
193 rwlock_t hlist_lock; /* protect session_hlist */
194 struct hlist_head session_hlist[PPPOL2TP_HASH_SIZE];
195 /* hashed list of sessions,
196 * hashed by id */
197 int debug; /* bitmask of debug message
198 * categories */
199 char name[12]; /* "tunl xxxxx" */
200 struct pppol2tp_ioc_stats stats;
201
202 void (*old_sk_destruct)(struct sock *);
203
204 struct sock *sock; /* Parent socket */
205 struct list_head list; /* Keep a list of all open
206 * prepared sockets */
207
208 atomic_t ref_count;
209};
210
211/* Private data stored for received packets in the skb.
212 */
213struct pppol2tp_skb_cb {
214 u16 ns;
215 u16 nr;
216 u16 has_seq;
217 u16 length;
218 unsigned long expires;
219};
220
221#define PPPOL2TP_SKB_CB(skb) ((struct pppol2tp_skb_cb *) &skb->cb[sizeof(struct inet_skb_parm)])
222
223static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb);
224static void pppol2tp_tunnel_free(struct pppol2tp_tunnel *tunnel);
225
226static atomic_t pppol2tp_tunnel_count;
227static atomic_t pppol2tp_session_count;
228static struct ppp_channel_ops pppol2tp_chan_ops = { pppol2tp_xmit , NULL };
229static struct proto_ops pppol2tp_ops;
230static LIST_HEAD(pppol2tp_tunnel_list);
231static DEFINE_RWLOCK(pppol2tp_tunnel_list_lock);
232
233/* Helpers to obtain tunnel/session contexts from sockets.
234 */
235static inline struct pppol2tp_session *pppol2tp_sock_to_session(struct sock *sk)
236{
237 struct pppol2tp_session *session;
238
239 if (sk == NULL)
240 return NULL;
241
242 session = (struct pppol2tp_session *)(sk->sk_user_data);
243 if (session == NULL)
244 return NULL;
245
246 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
247
248 return session;
249}
250
251static inline struct pppol2tp_tunnel *pppol2tp_sock_to_tunnel(struct sock *sk)
252{
253 struct pppol2tp_tunnel *tunnel;
254
255 if (sk == NULL)
256 return NULL;
257
258 tunnel = (struct pppol2tp_tunnel *)(sk->sk_user_data);
259 if (tunnel == NULL)
260 return NULL;
261
262 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
263
264 return tunnel;
265}
266
267/* Tunnel reference counts. Incremented per session that is added to
268 * the tunnel.
269 */
270static inline void pppol2tp_tunnel_inc_refcount(struct pppol2tp_tunnel *tunnel)
271{
272 atomic_inc(&tunnel->ref_count);
273}
274
275static inline void pppol2tp_tunnel_dec_refcount(struct pppol2tp_tunnel *tunnel)
276{
277 if (atomic_dec_and_test(&tunnel->ref_count))
278 pppol2tp_tunnel_free(tunnel);
279}
280
281/* Session hash list.
282 * The session_id SHOULD be random according to RFC2661, but several
283 * L2TP implementations (Cisco and Microsoft) use incrementing
284 * session_ids. So we do a real hash on the session_id, rather than a
285 * simple bitmask.
286 */
287static inline struct hlist_head *
288pppol2tp_session_id_hash(struct pppol2tp_tunnel *tunnel, u16 session_id)
289{
290 unsigned long hash_val = (unsigned long) session_id;
291 return &tunnel->session_hlist[hash_long(hash_val, PPPOL2TP_HASH_BITS)];
292}
293
294/* Lookup a session by id
295 */
296static struct pppol2tp_session *
297pppol2tp_session_find(struct pppol2tp_tunnel *tunnel, u16 session_id)
298{
299 struct hlist_head *session_list =
300 pppol2tp_session_id_hash(tunnel, session_id);
301 struct pppol2tp_session *session;
302 struct hlist_node *walk;
303
304 read_lock(&tunnel->hlist_lock);
305 hlist_for_each_entry(session, walk, session_list, hlist) {
306 if (session->tunnel_addr.s_session == session_id) {
307 read_unlock(&tunnel->hlist_lock);
308 return session;
309 }
310 }
311 read_unlock(&tunnel->hlist_lock);
312
313 return NULL;
314}
315
316/* Lookup a tunnel by id
317 */
318static struct pppol2tp_tunnel *pppol2tp_tunnel_find(u16 tunnel_id)
319{
320 struct pppol2tp_tunnel *tunnel = NULL;
321
322 read_lock(&pppol2tp_tunnel_list_lock);
323 list_for_each_entry(tunnel, &pppol2tp_tunnel_list, list) {
324 if (tunnel->stats.tunnel_id == tunnel_id) {
325 read_unlock(&pppol2tp_tunnel_list_lock);
326 return tunnel;
327 }
328 }
329 read_unlock(&pppol2tp_tunnel_list_lock);
330
331 return NULL;
332}
333
334/*****************************************************************************
335 * Receive data handling
336 *****************************************************************************/
337
338/* Queue a skb in order. We come here only if the skb has an L2TP sequence
339 * number.
340 */
341static void pppol2tp_recv_queue_skb(struct pppol2tp_session *session, struct sk_buff *skb)
342{
343 struct sk_buff *skbp;
344 u16 ns = PPPOL2TP_SKB_CB(skb)->ns;
345
346 spin_lock(&session->reorder_q.lock);
347 skb_queue_walk(&session->reorder_q, skbp) {
348 if (PPPOL2TP_SKB_CB(skbp)->ns > ns) {
349 __skb_insert(skb, skbp->prev, skbp, &session->reorder_q);
350 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
351 "%s: pkt %hu, inserted before %hu, reorder_q len=%d\n",
352 session->name, ns, PPPOL2TP_SKB_CB(skbp)->ns,
353 skb_queue_len(&session->reorder_q));
354 session->stats.rx_oos_packets++;
355 goto out;
356 }
357 }
358
359 __skb_queue_tail(&session->reorder_q, skb);
360
361out:
362 spin_unlock(&session->reorder_q.lock);
363}
364
365/* Dequeue a single skb.
366 */
367static void pppol2tp_recv_dequeue_skb(struct pppol2tp_session *session, struct sk_buff *skb)
368{
369 struct pppol2tp_tunnel *tunnel = session->tunnel;
370 int length = PPPOL2TP_SKB_CB(skb)->length;
371 struct sock *session_sock = NULL;
372
373 /* We're about to requeue the skb, so unlink it and return resources
374 * to its current owner (a socket receive buffer).
375 */
376 skb_unlink(skb, &session->reorder_q);
377 skb_orphan(skb);
378
379 tunnel->stats.rx_packets++;
380 tunnel->stats.rx_bytes += length;
381 session->stats.rx_packets++;
382 session->stats.rx_bytes += length;
383
384 if (PPPOL2TP_SKB_CB(skb)->has_seq) {
385 /* Bump our Nr */
386 session->nr++;
387 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
388 "%s: updated nr to %hu\n", session->name, session->nr);
389 }
390
391 /* If the socket is bound, send it in to PPP's input queue. Otherwise
392 * queue it on the session socket.
393 */
394 session_sock = session->sock;
395 if (session_sock->sk_state & PPPOX_BOUND) {
396 struct pppox_sock *po;
397 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
398 "%s: recv %d byte data frame, passing to ppp\n",
399 session->name, length);
400
401 /* We need to forget all info related to the L2TP packet
402 * gathered in the skb as we are going to reuse the same
403 * skb for the inner packet.
404 * Namely we need to:
405 * - reset xfrm (IPSec) information as it applies to
406 * the outer L2TP packet and not to the inner one
407 * - release the dst to force a route lookup on the inner
408 * IP packet since skb->dst currently points to the dst
409 * of the UDP tunnel
410 * - reset netfilter information as it doesn't apply
411 * to the inner packet either
412 */
413 secpath_reset(skb);
414 dst_release(skb->dst);
415 skb->dst = NULL;
416 nf_reset(skb);
417
418 po = pppox_sk(session_sock);
419 ppp_input(&po->chan, skb);
420 } else {
421 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
422 "%s: socket not bound\n", session->name);
423
424 /* Not bound. Nothing we can do, so discard. */
425 session->stats.rx_errors++;
426 kfree_skb(skb);
427 }
428
429 sock_put(session->sock);
430}
431
432/* Dequeue skbs from the session's reorder_q, subject to packet order.
433 * Skbs that have been in the queue for too long are simply discarded.
434 */
435static void pppol2tp_recv_dequeue(struct pppol2tp_session *session)
436{
437 struct sk_buff *skb;
438 struct sk_buff *tmp;
439
440 /* If the pkt at the head of the queue has the nr that we
441 * expect to send up next, dequeue it and any other
442 * in-sequence packets behind it.
443 */
444 spin_lock(&session->reorder_q.lock);
445 skb_queue_walk_safe(&session->reorder_q, skb, tmp) {
446 if (time_after(jiffies, PPPOL2TP_SKB_CB(skb)->expires)) {
447 session->stats.rx_seq_discards++;
448 session->stats.rx_errors++;
449 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
450 "%s: oos pkt %hu len %d discarded (too old), "
451 "waiting for %hu, reorder_q_len=%d\n",
452 session->name, PPPOL2TP_SKB_CB(skb)->ns,
453 PPPOL2TP_SKB_CB(skb)->length, session->nr,
454 skb_queue_len(&session->reorder_q));
455 __skb_unlink(skb, &session->reorder_q);
456 kfree_skb(skb);
457 continue;
458 }
459
460 if (PPPOL2TP_SKB_CB(skb)->has_seq) {
461 if (PPPOL2TP_SKB_CB(skb)->ns != session->nr) {
462 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
463 "%s: holding oos pkt %hu len %d, "
464 "waiting for %hu, reorder_q_len=%d\n",
465 session->name, PPPOL2TP_SKB_CB(skb)->ns,
466 PPPOL2TP_SKB_CB(skb)->length, session->nr,
467 skb_queue_len(&session->reorder_q));
468 goto out;
469 }
470 }
471 spin_unlock(&session->reorder_q.lock);
472 pppol2tp_recv_dequeue_skb(session, skb);
473 spin_lock(&session->reorder_q.lock);
474 }
475
476out:
477 spin_unlock(&session->reorder_q.lock);
478}
479
480/* Internal receive frame. Do the real work of receiving an L2TP data frame
481 * here. The skb is not on a list when we get here.
482 * Returns 0 if the packet was a data packet and was successfully passed on.
483 * Returns 1 if the packet was not a good data packet and could not be
484 * forwarded. All such packets are passed up to userspace to deal with.
485 */
486static int pppol2tp_recv_core(struct sock *sock, struct sk_buff *skb)
487{
488 struct pppol2tp_session *session = NULL;
489 struct pppol2tp_tunnel *tunnel;
490 unsigned char *ptr;
491 u16 hdrflags;
492 u16 tunnel_id, session_id;
493 int length;
494 struct udphdr *uh;
495
496 tunnel = pppol2tp_sock_to_tunnel(sock);
497 if (tunnel == NULL)
498 goto error;
499
500 /* Short packet? */
501 if (skb->len < sizeof(struct udphdr)) {
502 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
503 "%s: recv short packet (len=%d)\n", tunnel->name, skb->len);
504 goto error;
505 }
506
507 /* Point to L2TP header */
508 ptr = skb->data + sizeof(struct udphdr);
509
510 /* Get L2TP header flags */
511 hdrflags = ntohs(*(__be16*)ptr);
512
513 /* Trace packet contents, if enabled */
514 if (tunnel->debug & PPPOL2TP_MSG_DATA) {
515 printk(KERN_DEBUG "%s: recv: ", tunnel->name);
516
517 for (length = 0; length < 16; length++)
518 printk(" %02X", ptr[length]);
519 printk("\n");
520 }
521
522 /* Get length of L2TP packet */
523 uh = (struct udphdr *) skb_transport_header(skb);
524 length = ntohs(uh->len) - sizeof(struct udphdr);
525
526 /* Too short? */
527 if (length < 12) {
528 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
529 "%s: recv short L2TP packet (len=%d)\n", tunnel->name, length);
530 goto error;
531 }
532
533 /* If type is control packet, it is handled by userspace. */
534 if (hdrflags & L2TP_HDRFLAG_T) {
535 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
536 "%s: recv control packet, len=%d\n", tunnel->name, length);
537 goto error;
538 }
539
540 /* Skip flags */
541 ptr += 2;
542
543 /* If length is present, skip it */
544 if (hdrflags & L2TP_HDRFLAG_L)
545 ptr += 2;
546
547 /* Extract tunnel and session ID */
548 tunnel_id = ntohs(*(__be16 *) ptr);
549 ptr += 2;
550 session_id = ntohs(*(__be16 *) ptr);
551 ptr += 2;
552
553 /* Find the session context */
554 session = pppol2tp_session_find(tunnel, session_id);
555 if (!session) {
556 /* Not found? Pass to userspace to deal with */
557 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
558 "%s: no socket found (%hu/%hu). Passing up.\n",
559 tunnel->name, tunnel_id, session_id);
560 goto error;
561 }
562 sock_hold(session->sock);
563
564 /* The ref count on the socket was increased by the above call since
565 * we now hold a pointer to the session. Take care to do sock_put()
566 * when exiting this function from now on...
567 */
568
569 /* Handle the optional sequence numbers. If we are the LAC,
570 * enable/disable sequence numbers under the control of the LNS. If
571 * no sequence numbers present but we were expecting them, discard
572 * frame.
573 */
574 if (hdrflags & L2TP_HDRFLAG_S) {
575 u16 ns, nr;
576 ns = ntohs(*(__be16 *) ptr);
577 ptr += 2;
578 nr = ntohs(*(__be16 *) ptr);
579 ptr += 2;
580
581 /* Received a packet with sequence numbers. If we're the LNS,
582 * check if we sre sending sequence numbers and if not,
583 * configure it so.
584 */
585 if ((!session->lns_mode) && (!session->send_seq)) {
586 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_INFO,
587 "%s: requested to enable seq numbers by LNS\n",
588 session->name);
589 session->send_seq = -1;
590 }
591
592 /* Store L2TP info in the skb */
593 PPPOL2TP_SKB_CB(skb)->ns = ns;
594 PPPOL2TP_SKB_CB(skb)->nr = nr;
595 PPPOL2TP_SKB_CB(skb)->has_seq = 1;
596
597 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
598 "%s: recv data ns=%hu, nr=%hu, session nr=%hu\n",
599 session->name, ns, nr, session->nr);
600 } else {
601 /* No sequence numbers.
602 * If user has configured mandatory sequence numbers, discard.
603 */
604 if (session->recv_seq) {
605 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_WARNING,
606 "%s: recv data has no seq numbers when required. "
607 "Discarding\n", session->name);
608 session->stats.rx_seq_discards++;
609 session->stats.rx_errors++;
610 goto discard;
611 }
612
613 /* If we're the LAC and we're sending sequence numbers, the
614 * LNS has requested that we no longer send sequence numbers.
615 * If we're the LNS and we're sending sequence numbers, the
616 * LAC is broken. Discard the frame.
617 */
618 if ((!session->lns_mode) && (session->send_seq)) {
619 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_INFO,
620 "%s: requested to disable seq numbers by LNS\n",
621 session->name);
622 session->send_seq = 0;
623 } else if (session->send_seq) {
624 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_WARNING,
625 "%s: recv data has no seq numbers when required. "
626 "Discarding\n", session->name);
627 session->stats.rx_seq_discards++;
628 session->stats.rx_errors++;
629 goto discard;
630 }
631
632 /* Store L2TP info in the skb */
633 PPPOL2TP_SKB_CB(skb)->has_seq = 0;
634 }
635
636 /* If offset bit set, skip it. */
637 if (hdrflags & L2TP_HDRFLAG_O)
638 ptr += 2 + ntohs(*(__be16 *) ptr);
639
640 skb_pull(skb, ptr - skb->data);
641
642 /* Skip PPP header, if present. In testing, Microsoft L2TP clients
643 * don't send the PPP header (PPP header compression enabled), but
644 * other clients can include the header. So we cope with both cases
645 * here. The PPP header is always FF03 when using L2TP.
646 *
647 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
648 * the field may be unaligned.
649 */
650 if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
651 skb_pull(skb, 2);
652
653 /* Prepare skb for adding to the session's reorder_q. Hold
654 * packets for max reorder_timeout or 1 second if not
655 * reordering.
656 */
657 PPPOL2TP_SKB_CB(skb)->length = length;
658 PPPOL2TP_SKB_CB(skb)->expires = jiffies +
659 (session->reorder_timeout ? session->reorder_timeout : HZ);
660
661 /* Add packet to the session's receive queue. Reordering is done here, if
662 * enabled. Saved L2TP protocol info is stored in skb->sb[].
663 */
664 if (PPPOL2TP_SKB_CB(skb)->has_seq) {
665 if (session->reorder_timeout != 0) {
666 /* Packet reordering enabled. Add skb to session's
667 * reorder queue, in order of ns.
668 */
669 pppol2tp_recv_queue_skb(session, skb);
670 } else {
671 /* Packet reordering disabled. Discard out-of-sequence
672 * packets
673 */
674 if (PPPOL2TP_SKB_CB(skb)->ns != session->nr) {
675 session->stats.rx_seq_discards++;
676 session->stats.rx_errors++;
677 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
678 "%s: oos pkt %hu len %d discarded, "
679 "waiting for %hu, reorder_q_len=%d\n",
680 session->name, PPPOL2TP_SKB_CB(skb)->ns,
681 PPPOL2TP_SKB_CB(skb)->length, session->nr,
682 skb_queue_len(&session->reorder_q));
683 goto discard;
684 }
685 skb_queue_tail(&session->reorder_q, skb);
686 }
687 } else {
688 /* No sequence numbers. Add the skb to the tail of the
689 * reorder queue. This ensures that it will be
690 * delivered after all previous sequenced skbs.
691 */
692 skb_queue_tail(&session->reorder_q, skb);
693 }
694
695 /* Try to dequeue as many skbs from reorder_q as we can. */
696 pppol2tp_recv_dequeue(session);
697
698 return 0;
699
700discard:
701 kfree_skb(skb);
702 sock_put(session->sock);
703
704 return 0;
705
706error:
707 return 1;
708}
709
710/* UDP encapsulation receive handler. See net/ipv4/udp.c.
711 * Return codes:
712 * 0 : success.
713 * <0: error
714 * >0: skb should be passed up to userspace as UDP.
715 */
716static int pppol2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
717{
718 struct pppol2tp_tunnel *tunnel;
719
720 tunnel = pppol2tp_sock_to_tunnel(sk);
721 if (tunnel == NULL)
722 goto pass_up;
723
724 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
725 "%s: received %d bytes\n", tunnel->name, skb->len);
726
727 if (pppol2tp_recv_core(sk, skb))
728 goto pass_up;
729
730 return 0;
731
732pass_up:
733 return 1;
734}
735
736/* Receive message. This is the recvmsg for the PPPoL2TP socket.
737 */
738static int pppol2tp_recvmsg(struct kiocb *iocb, struct socket *sock,
739 struct msghdr *msg, size_t len,
740 int flags)
741{
742 int err;
743 struct sk_buff *skb;
744 struct sock *sk = sock->sk;
745
746 err = -EIO;
747 if (sk->sk_state & PPPOX_BOUND)
748 goto end;
749
750 msg->msg_namelen = 0;
751
752 err = 0;
753 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
754 flags & MSG_DONTWAIT, &err);
755 if (skb) {
756 err = memcpy_toiovec(msg->msg_iov, (unsigned char *) skb->data,
757 skb->len);
758 if (err < 0)
759 goto do_skb_free;
760 err = skb->len;
761 }
762do_skb_free:
763 kfree_skb(skb);
764end:
765 return err;
766}
767
768/************************************************************************
769 * Transmit handling
770 ***********************************************************************/
771
772/* Tell how big L2TP headers are for a particular session. This
773 * depends on whether sequence numbers are being used.
774 */
775static inline int pppol2tp_l2tp_header_len(struct pppol2tp_session *session)
776{
777 if (session->send_seq)
778 return PPPOL2TP_L2TP_HDR_SIZE_SEQ;
779
780 return PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
781}
782
783/* Build an L2TP header for the session into the buffer provided.
784 */
785static void pppol2tp_build_l2tp_header(struct pppol2tp_session *session,
786 void *buf)
787{
788 __be16 *bufp = buf;
789 u16 flags = L2TP_HDR_VER;
790
791 if (session->send_seq)
792 flags |= L2TP_HDRFLAG_S;
793
794 /* Setup L2TP header.
795 * FIXME: Can this ever be unaligned? Is direct dereferencing of
796 * 16-bit header fields safe here for all architectures?
797 */
798 *bufp++ = htons(flags);
799 *bufp++ = htons(session->tunnel_addr.d_tunnel);
800 *bufp++ = htons(session->tunnel_addr.d_session);
801 if (session->send_seq) {
802 *bufp++ = htons(session->ns);
803 *bufp++ = 0;
804 session->ns++;
805 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
806 "%s: updated ns to %hu\n", session->name, session->ns);
807 }
808}
809
810/* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here
811 * when a user application does a sendmsg() on the session socket. L2TP and
812 * PPP headers must be inserted into the user's data.
813 */
814static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
815 size_t total_len)
816{
817 static const unsigned char ppph[2] = { 0xff, 0x03 };
818 struct sock *sk = sock->sk;
819 struct inet_sock *inet;
820 __wsum csum = 0;
821 struct sk_buff *skb;
822 int error;
823 int hdr_len;
824 struct pppol2tp_session *session;
825 struct pppol2tp_tunnel *tunnel;
826 struct udphdr *uh;
827
828 error = -ENOTCONN;
829 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
830 goto error;
831
832 /* Get session and tunnel contexts */
833 error = -EBADF;
834 session = pppol2tp_sock_to_session(sk);
835 if (session == NULL)
836 goto error;
837
838 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
839 if (tunnel == NULL)
840 goto error;
841
842 /* What header length is configured for this session? */
843 hdr_len = pppol2tp_l2tp_header_len(session);
844
845 /* Allocate a socket buffer */
846 error = -ENOMEM;
847 skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) +
848 sizeof(struct udphdr) + hdr_len +
849 sizeof(ppph) + total_len,
850 0, GFP_KERNEL);
851 if (!skb)
852 goto error;
853
854 /* Reserve space for headers. */
855 skb_reserve(skb, NET_SKB_PAD);
856 skb_reset_network_header(skb);
857 skb_reserve(skb, sizeof(struct iphdr));
858 skb_reset_transport_header(skb);
859
860 /* Build UDP header */
861 inet = inet_sk(session->tunnel_sock);
862 uh = (struct udphdr *) skb->data;
863 uh->source = inet->sport;
864 uh->dest = inet->dport;
865 uh->len = htons(hdr_len + sizeof(ppph) + total_len);
866 uh->check = 0;
867 skb_put(skb, sizeof(struct udphdr));
868
869 /* Build L2TP header */
870 pppol2tp_build_l2tp_header(session, skb->data);
871 skb_put(skb, hdr_len);
872
873 /* Add PPP header */
874 skb->data[0] = ppph[0];
875 skb->data[1] = ppph[1];
876 skb_put(skb, 2);
877
878 /* Copy user data into skb */
879 error = memcpy_fromiovec(skb->data, m->msg_iov, total_len);
880 if (error < 0) {
881 kfree_skb(skb);
882 goto error;
883 }
884 skb_put(skb, total_len);
885
886 /* Calculate UDP checksum if configured to do so */
887 if (session->tunnel_sock->sk_no_check != UDP_CSUM_NOXMIT)
888 csum = udp_csum_outgoing(sk, skb);
889
890 /* Debug */
891 if (session->send_seq)
892 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
893 "%s: send %Zd bytes, ns=%hu\n", session->name,
894 total_len, session->ns - 1);
895 else
896 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
897 "%s: send %Zd bytes\n", session->name, total_len);
898
899 if (session->debug & PPPOL2TP_MSG_DATA) {
900 int i;
901 unsigned char *datap = skb->data;
902
903 printk(KERN_DEBUG "%s: xmit:", session->name);
904 for (i = 0; i < total_len; i++) {
905 printk(" %02X", *datap++);
906 if (i == 15) {
907 printk(" ...");
908 break;
909 }
910 }
911 printk("\n");
912 }
913
914 /* Queue the packet to IP for output */
915 error = ip_queue_xmit(skb, 1);
916
917 /* Update stats */
918 if (error >= 0) {
919 tunnel->stats.tx_packets++;
920 tunnel->stats.tx_bytes += skb->len;
921 session->stats.tx_packets++;
922 session->stats.tx_bytes += skb->len;
923 } else {
924 tunnel->stats.tx_errors++;
925 session->stats.tx_errors++;
926 }
927
928error:
929 return error;
930}
931
932/* Transmit function called by generic PPP driver. Sends PPP frame
933 * over PPPoL2TP socket.
934 *
935 * This is almost the same as pppol2tp_sendmsg(), but rather than
936 * being called with a msghdr from userspace, it is called with a skb
937 * from the kernel.
938 *
939 * The supplied skb from ppp doesn't have enough headroom for the
940 * insertion of L2TP, UDP and IP headers so we need to allocate more
941 * headroom in the skb. This will create a cloned skb. But we must be
942 * careful in the error case because the caller will expect to free
943 * the skb it supplied, not our cloned skb. So we take care to always
944 * leave the original skb unfreed if we return an error.
945 */
946static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
947{
948 static const u8 ppph[2] = { 0xff, 0x03 };
949 struct sock *sk = (struct sock *) chan->private;
950 struct sock *sk_tun;
951 int hdr_len;
952 struct pppol2tp_session *session;
953 struct pppol2tp_tunnel *tunnel;
954 int rc;
955 int headroom;
956 int data_len = skb->len;
957 struct inet_sock *inet;
958 __wsum csum = 0;
959 struct sk_buff *skb2 = NULL;
960 struct udphdr *uh;
961
962 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
963 goto abort;
964
965 /* Get session and tunnel contexts from the socket */
966 session = pppol2tp_sock_to_session(sk);
967 if (session == NULL)
968 goto abort;
969
970 sk_tun = session->tunnel_sock;
971 if (sk_tun == NULL)
972 goto abort;
973 tunnel = pppol2tp_sock_to_tunnel(sk_tun);
974 if (tunnel == NULL)
975 goto abort;
976
977 /* What header length is configured for this session? */
978 hdr_len = pppol2tp_l2tp_header_len(session);
979
980 /* Check that there's enough headroom in the skb to insert IP,
981 * UDP and L2TP and PPP headers. If not enough, expand it to
982 * make room. Note that a new skb (or a clone) is
983 * allocated. If we return an error from this point on, make
984 * sure we free the new skb but do not free the original skb
985 * since that is done by the caller for the error case.
986 */
987 headroom = NET_SKB_PAD + sizeof(struct iphdr) +
988 sizeof(struct udphdr) + hdr_len + sizeof(ppph);
989 if (skb_headroom(skb) < headroom) {
990 skb2 = skb_realloc_headroom(skb, headroom);
991 if (skb2 == NULL)
992 goto abort;
993 } else
994 skb2 = skb;
995
996 /* Check that the socket has room */
997 if (atomic_read(&sk_tun->sk_wmem_alloc) < sk_tun->sk_sndbuf)
998 skb_set_owner_w(skb2, sk_tun);
999 else
1000 goto discard;
1001
1002 /* Setup PPP header */
1003 skb_push(skb2, sizeof(ppph));
1004 skb2->data[0] = ppph[0];
1005 skb2->data[1] = ppph[1];
1006
1007 /* Setup L2TP header */
1008 skb_push(skb2, hdr_len);
1009 pppol2tp_build_l2tp_header(session, skb2->data);
1010
1011 /* Setup UDP header */
1012 inet = inet_sk(sk_tun);
1013 skb_push(skb2, sizeof(struct udphdr));
1014 skb_reset_transport_header(skb2);
1015 uh = (struct udphdr *) skb2->data;
1016 uh->source = inet->sport;
1017 uh->dest = inet->dport;
1018 uh->len = htons(sizeof(struct udphdr) + hdr_len + sizeof(ppph) + data_len);
1019 uh->check = 0;
1020
1021 /* Calculate UDP checksum if configured to do so */
1022 if (sk_tun->sk_no_check != UDP_CSUM_NOXMIT)
1023 csum = udp_csum_outgoing(sk_tun, skb2);
1024
1025 /* Debug */
1026 if (session->send_seq)
1027 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
1028 "%s: send %d bytes, ns=%hu\n", session->name,
1029 data_len, session->ns - 1);
1030 else
1031 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
1032 "%s: send %d bytes\n", session->name, data_len);
1033
1034 if (session->debug & PPPOL2TP_MSG_DATA) {
1035 int i;
1036 unsigned char *datap = skb2->data;
1037
1038 printk(KERN_DEBUG "%s: xmit:", session->name);
1039 for (i = 0; i < data_len; i++) {
1040 printk(" %02X", *datap++);
1041 if (i == 31) {
1042 printk(" ...");
1043 break;
1044 }
1045 }
1046 printk("\n");
1047 }
1048
1049 /* Get routing info from the tunnel socket */
1050 skb2->dst = sk_dst_get(sk_tun);
1051
1052 /* Queue the packet to IP for output */
1053 rc = ip_queue_xmit(skb2, 1);
1054
1055 /* Update stats */
1056 if (rc >= 0) {
1057 tunnel->stats.tx_packets++;
1058 tunnel->stats.tx_bytes += skb2->len;
1059 session->stats.tx_packets++;
1060 session->stats.tx_bytes += skb2->len;
1061 } else {
1062 tunnel->stats.tx_errors++;
1063 session->stats.tx_errors++;
1064 }
1065
1066 /* Free the original skb */
1067 kfree_skb(skb);
1068
1069 return 1;
1070
1071discard:
1072 /* Free the new skb. Caller will free original skb. */
1073 if (skb2 != skb)
1074 kfree_skb(skb2);
1075abort:
1076 return 0;
1077}
1078
1079/*****************************************************************************
1080 * Session (and tunnel control) socket create/destroy.
1081 *****************************************************************************/
1082
1083/* When the tunnel UDP socket is closed, all the attached sockets need to go
1084 * too.
1085 */
1086static void pppol2tp_tunnel_closeall(struct pppol2tp_tunnel *tunnel)
1087{
1088 int hash;
1089 struct hlist_node *walk;
1090 struct hlist_node *tmp;
1091 struct pppol2tp_session *session;
1092 struct sock *sk;
1093
1094 if (tunnel == NULL)
1095 BUG();
1096
1097 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1098 "%s: closing all sessions...\n", tunnel->name);
1099
1100 write_lock(&tunnel->hlist_lock);
1101 for (hash = 0; hash < PPPOL2TP_HASH_SIZE; hash++) {
1102again:
1103 hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) {
1104 session = hlist_entry(walk, struct pppol2tp_session, hlist);
1105
1106 sk = session->sock;
1107
1108 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1109 "%s: closing session\n", session->name);
1110
1111 hlist_del_init(&session->hlist);
1112
1113 /* Since we should hold the sock lock while
1114 * doing any unbinding, we need to release the
1115 * lock we're holding before taking that lock.
1116 * Hold a reference to the sock so it doesn't
1117 * disappear as we're jumping between locks.
1118 */
1119 sock_hold(sk);
1120 write_unlock(&tunnel->hlist_lock);
1121 lock_sock(sk);
1122
1123 if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
1124 pppox_unbind_sock(sk);
1125 sk->sk_state = PPPOX_DEAD;
1126 sk->sk_state_change(sk);
1127 }
1128
1129 /* Purge any queued data */
1130 skb_queue_purge(&sk->sk_receive_queue);
1131 skb_queue_purge(&sk->sk_write_queue);
1132 skb_queue_purge(&session->reorder_q);
1133
1134 release_sock(sk);
1135 sock_put(sk);
1136
1137 /* Now restart from the beginning of this hash
1138 * chain. We always remove a session from the
1139 * list so we are guaranteed to make forward
1140 * progress.
1141 */
1142 write_lock(&tunnel->hlist_lock);
1143 goto again;
1144 }
1145 }
1146 write_unlock(&tunnel->hlist_lock);
1147}
1148
1149/* Really kill the tunnel.
1150 * Come here only when all sessions have been cleared from the tunnel.
1151 */
1152static void pppol2tp_tunnel_free(struct pppol2tp_tunnel *tunnel)
1153{
1154 /* Remove from socket list */
1155 write_lock(&pppol2tp_tunnel_list_lock);
1156 list_del_init(&tunnel->list);
1157 write_unlock(&pppol2tp_tunnel_list_lock);
1158
1159 atomic_dec(&pppol2tp_tunnel_count);
1160 kfree(tunnel);
1161}
1162
1163/* Tunnel UDP socket destruct hook.
1164 * The tunnel context is deleted only when all session sockets have been
1165 * closed.
1166 */
1167static void pppol2tp_tunnel_destruct(struct sock *sk)
1168{
1169 struct pppol2tp_tunnel *tunnel;
1170
1171 tunnel = pppol2tp_sock_to_tunnel(sk);
1172 if (tunnel == NULL)
1173 goto end;
1174
1175 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1176 "%s: closing...\n", tunnel->name);
1177
1178 /* Close all sessions */
1179 pppol2tp_tunnel_closeall(tunnel);
1180
1181 /* No longer an encapsulation socket. See net/ipv4/udp.c */
1182 (udp_sk(sk))->encap_type = 0;
1183 (udp_sk(sk))->encap_rcv = NULL;
1184
1185 /* Remove hooks into tunnel socket */
1186 tunnel->sock = NULL;
1187 sk->sk_destruct = tunnel->old_sk_destruct;
1188 sk->sk_user_data = NULL;
1189
1190 /* Call original (UDP) socket descructor */
1191 if (sk->sk_destruct != NULL)
1192 (*sk->sk_destruct)(sk);
1193
1194 pppol2tp_tunnel_dec_refcount(tunnel);
1195
1196end:
1197 return;
1198}
1199
1200/* Really kill the session socket. (Called from sock_put() if
1201 * refcnt == 0.)
1202 */
1203static void pppol2tp_session_destruct(struct sock *sk)
1204{
1205 struct pppol2tp_session *session = NULL;
1206
1207 if (sk->sk_user_data != NULL) {
1208 struct pppol2tp_tunnel *tunnel;
1209
1210 session = pppol2tp_sock_to_session(sk);
1211 if (session == NULL)
1212 goto out;
1213
1214 /* Don't use pppol2tp_sock_to_tunnel() here to
1215 * get the tunnel context because the tunnel
1216 * socket might have already been closed (its
1217 * sk->sk_user_data will be NULL) so use the
1218 * session's private tunnel ptr instead.
1219 */
1220 tunnel = session->tunnel;
1221 if (tunnel != NULL) {
1222 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
1223
1224 /* If session_id is zero, this is a null
1225 * session context, which was created for a
1226 * socket that is being used only to manage
1227 * tunnels.
1228 */
1229 if (session->tunnel_addr.s_session != 0) {
1230 /* Delete the session socket from the
1231 * hash
1232 */
1233 write_lock(&tunnel->hlist_lock);
1234 hlist_del_init(&session->hlist);
1235 write_unlock(&tunnel->hlist_lock);
1236
1237 atomic_dec(&pppol2tp_session_count);
1238 }
1239
1240 /* This will delete the tunnel context if this
1241 * is the last session on the tunnel.
1242 */
1243 session->tunnel = NULL;
1244 session->tunnel_sock = NULL;
1245 pppol2tp_tunnel_dec_refcount(tunnel);
1246 }
1247 }
1248
1249 kfree(session);
1250out:
1251 return;
1252}
1253
1254/* Called when the PPPoX socket (session) is closed.
1255 */
1256static int pppol2tp_release(struct socket *sock)
1257{
1258 struct sock *sk = sock->sk;
1259 int error;
1260
1261 if (!sk)
1262 return 0;
1263
1264 error = -EBADF;
1265 lock_sock(sk);
1266 if (sock_flag(sk, SOCK_DEAD) != 0)
1267 goto error;
1268
1269 pppox_unbind_sock(sk);
1270
1271 /* Signal the death of the socket. */
1272 sk->sk_state = PPPOX_DEAD;
1273 sock_orphan(sk);
1274 sock->sk = NULL;
1275
1276 /* Purge any queued data */
1277 skb_queue_purge(&sk->sk_receive_queue);
1278 skb_queue_purge(&sk->sk_write_queue);
1279
1280 release_sock(sk);
1281
1282 /* This will delete the session context via
1283 * pppol2tp_session_destruct() if the socket's refcnt drops to
1284 * zero.
1285 */
1286 sock_put(sk);
1287
1288 return 0;
1289
1290error:
1291 release_sock(sk);
1292 return error;
1293}
1294
1295/* Internal function to prepare a tunnel (UDP) socket to have PPPoX
1296 * sockets attached to it.
1297 */
1298static struct sock *pppol2tp_prepare_tunnel_socket(int fd, u16 tunnel_id,
1299 int *error)
1300{
1301 int err;
1302 struct socket *sock = NULL;
1303 struct sock *sk;
1304 struct pppol2tp_tunnel *tunnel;
1305 struct sock *ret = NULL;
1306
1307 /* Get the tunnel UDP socket from the fd, which was opened by
1308 * the userspace L2TP daemon.
1309 */
1310 err = -EBADF;
1311 sock = sockfd_lookup(fd, &err);
1312 if (!sock) {
1313 PRINTK(-1, PPPOL2TP_MSG_CONTROL, KERN_ERR,
1314 "tunl %hu: sockfd_lookup(fd=%d) returned %d\n",
1315 tunnel_id, fd, err);
1316 goto err;
1317 }
1318
1319 /* Quick sanity checks */
1320 err = -ESOCKTNOSUPPORT;
1321 if (sock->type != SOCK_DGRAM) {
1322 PRINTK(-1, PPPOL2TP_MSG_CONTROL, KERN_ERR,
1323 "tunl %hu: fd %d wrong type, got %d, expected %d\n",
1324 tunnel_id, fd, sock->type, SOCK_DGRAM);
1325 goto err;
1326 }
1327 err = -EAFNOSUPPORT;
1328 if (sock->ops->family != AF_INET) {
1329 PRINTK(-1, PPPOL2TP_MSG_CONTROL, KERN_ERR,
1330 "tunl %hu: fd %d wrong family, got %d, expected %d\n",
1331 tunnel_id, fd, sock->ops->family, AF_INET);
1332 goto err;
1333 }
1334
1335 err = -ENOTCONN;
1336 sk = sock->sk;
1337
1338 /* Check if this socket has already been prepped */
1339 tunnel = (struct pppol2tp_tunnel *)sk->sk_user_data;
1340 if (tunnel != NULL) {
1341 /* User-data field already set */
1342 err = -EBUSY;
1343 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
1344
1345 /* This socket has already been prepped */
1346 ret = tunnel->sock;
1347 goto out;
1348 }
1349
1350 /* This socket is available and needs prepping. Create a new tunnel
1351 * context and init it.
1352 */
1353 sk->sk_user_data = tunnel = kzalloc(sizeof(struct pppol2tp_tunnel), GFP_KERNEL);
1354 if (sk->sk_user_data == NULL) {
1355 err = -ENOMEM;
1356 goto err;
1357 }
1358
1359 tunnel->magic = L2TP_TUNNEL_MAGIC;
1360 sprintf(&tunnel->name[0], "tunl %hu", tunnel_id);
1361
1362 tunnel->stats.tunnel_id = tunnel_id;
1363 tunnel->debug = PPPOL2TP_DEFAULT_DEBUG_FLAGS;
1364
1365 /* Hook on the tunnel socket destructor so that we can cleanup
1366 * if the tunnel socket goes away.
1367 */
1368 tunnel->old_sk_destruct = sk->sk_destruct;
1369 sk->sk_destruct = &pppol2tp_tunnel_destruct;
1370
1371 tunnel->sock = sk;
1372 sk->sk_allocation = GFP_ATOMIC;
1373
1374 /* Misc init */
1375 rwlock_init(&tunnel->hlist_lock);
1376
1377 /* Add tunnel to our list */
1378 INIT_LIST_HEAD(&tunnel->list);
1379 write_lock(&pppol2tp_tunnel_list_lock);
1380 list_add(&tunnel->list, &pppol2tp_tunnel_list);
1381 write_unlock(&pppol2tp_tunnel_list_lock);
1382 atomic_inc(&pppol2tp_tunnel_count);
1383
1384 /* Bump the reference count. The tunnel context is deleted
1385 * only when this drops to zero.
1386 */
1387 pppol2tp_tunnel_inc_refcount(tunnel);
1388
1389 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
1390 (udp_sk(sk))->encap_type = UDP_ENCAP_L2TPINUDP;
1391 (udp_sk(sk))->encap_rcv = pppol2tp_udp_encap_recv;
1392
1393 ret = tunnel->sock;
1394
1395 *error = 0;
1396out:
1397 if (sock)
1398 sockfd_put(sock);
1399
1400 return ret;
1401
1402err:
1403 *error = err;
1404 goto out;
1405}
1406
1407static struct proto pppol2tp_sk_proto = {
1408 .name = "PPPOL2TP",
1409 .owner = THIS_MODULE,
1410 .obj_size = sizeof(struct pppox_sock),
1411};
1412
1413/* socket() handler. Initialize a new struct sock.
1414 */
1415static int pppol2tp_create(struct socket *sock)
1416{
1417 int error = -ENOMEM;
1418 struct sock *sk;
1419
1420 sk = sk_alloc(PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto, 1);
1421 if (!sk)
1422 goto out;
1423
1424 sock_init_data(sock, sk);
1425
1426 sock->state = SS_UNCONNECTED;
1427 sock->ops = &pppol2tp_ops;
1428
1429 sk->sk_backlog_rcv = pppol2tp_recv_core;
1430 sk->sk_protocol = PX_PROTO_OL2TP;
1431 sk->sk_family = PF_PPPOX;
1432 sk->sk_state = PPPOX_NONE;
1433 sk->sk_type = SOCK_STREAM;
1434 sk->sk_destruct = pppol2tp_session_destruct;
1435
1436 error = 0;
1437
1438out:
1439 return error;
1440}
1441
1442/* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
1443 */
1444static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
1445 int sockaddr_len, int flags)
1446{
1447 struct sock *sk = sock->sk;
1448 struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr;
1449 struct pppox_sock *po = pppox_sk(sk);
1450 struct sock *tunnel_sock = NULL;
1451 struct pppol2tp_session *session = NULL;
1452 struct pppol2tp_tunnel *tunnel;
1453 struct dst_entry *dst;
1454 int error = 0;
1455
1456 lock_sock(sk);
1457
1458 error = -EINVAL;
1459 if (sp->sa_protocol != PX_PROTO_OL2TP)
1460 goto end;
1461
1462 /* Check for already bound sockets */
1463 error = -EBUSY;
1464 if (sk->sk_state & PPPOX_CONNECTED)
1465 goto end;
1466
1467 /* We don't supporting rebinding anyway */
1468 error = -EALREADY;
1469 if (sk->sk_user_data)
1470 goto end; /* socket is already attached */
1471
1472 /* Don't bind if s_tunnel is 0 */
1473 error = -EINVAL;
1474 if (sp->pppol2tp.s_tunnel == 0)
1475 goto end;
1476
1477 /* Special case: prepare tunnel socket if s_session and
1478 * d_session is 0. Otherwise look up tunnel using supplied
1479 * tunnel id.
1480 */
1481 if ((sp->pppol2tp.s_session == 0) && (sp->pppol2tp.d_session == 0)) {
1482 tunnel_sock = pppol2tp_prepare_tunnel_socket(sp->pppol2tp.fd,
1483 sp->pppol2tp.s_tunnel,
1484 &error);
1485 if (tunnel_sock == NULL)
1486 goto end;
1487
1488 tunnel = tunnel_sock->sk_user_data;
1489 } else {
1490 tunnel = pppol2tp_tunnel_find(sp->pppol2tp.s_tunnel);
1491
1492 /* Error if we can't find the tunnel */
1493 error = -ENOENT;
1494 if (tunnel == NULL)
1495 goto end;
1496
1497 tunnel_sock = tunnel->sock;
1498 }
1499
1500 /* Check that this session doesn't already exist */
1501 error = -EEXIST;
1502 session = pppol2tp_session_find(tunnel, sp->pppol2tp.s_session);
1503 if (session != NULL)
1504 goto end;
1505
1506 /* Allocate and initialize a new session context. */
1507 session = kzalloc(sizeof(struct pppol2tp_session), GFP_KERNEL);
1508 if (session == NULL) {
1509 error = -ENOMEM;
1510 goto end;
1511 }
1512
1513 skb_queue_head_init(&session->reorder_q);
1514
1515 session->magic = L2TP_SESSION_MAGIC;
1516 session->owner = current->pid;
1517 session->sock = sk;
1518 session->tunnel = tunnel;
1519 session->tunnel_sock = tunnel_sock;
1520 session->tunnel_addr = sp->pppol2tp;
1521 sprintf(&session->name[0], "sess %hu/%hu",
1522 session->tunnel_addr.s_tunnel,
1523 session->tunnel_addr.s_session);
1524
1525 session->stats.tunnel_id = session->tunnel_addr.s_tunnel;
1526 session->stats.session_id = session->tunnel_addr.s_session;
1527
1528 INIT_HLIST_NODE(&session->hlist);
1529
1530 /* Inherit debug options from tunnel */
1531 session->debug = tunnel->debug;
1532
1533 /* Default MTU must allow space for UDP/L2TP/PPP
1534 * headers.
1535 */
1536 session->mtu = session->mru = 1500 - PPPOL2TP_HEADER_OVERHEAD;
1537
1538 /* If PMTU discovery was enabled, use the MTU that was discovered */
1539 dst = sk_dst_get(sk);
1540 if (dst != NULL) {
1541 u32 pmtu = dst_mtu(__sk_dst_get(sk));
1542 if (pmtu != 0)
1543 session->mtu = session->mru = pmtu -
1544 PPPOL2TP_HEADER_OVERHEAD;
1545 dst_release(dst);
1546 }
1547
1548 /* Special case: if source & dest session_id == 0x0000, this socket is
1549 * being created to manage the tunnel. Don't add the session to the
1550 * session hash list, just set up the internal context for use by
1551 * ioctl() and sockopt() handlers.
1552 */
1553 if ((session->tunnel_addr.s_session == 0) &&
1554 (session->tunnel_addr.d_session == 0)) {
1555 error = 0;
1556 sk->sk_user_data = session;
1557 goto out_no_ppp;
1558 }
1559
1560 /* Get tunnel context from the tunnel socket */
1561 tunnel = pppol2tp_sock_to_tunnel(tunnel_sock);
1562 if (tunnel == NULL) {
1563 error = -EBADF;
1564 goto end;
1565 }
1566
1567 /* Right now, because we don't have a way to push the incoming skb's
1568 * straight through the UDP layer, the only header we need to worry
1569 * about is the L2TP header. This size is different depending on
1570 * whether sequence numbers are enabled for the data channel.
1571 */
1572 po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1573
1574 po->chan.private = sk;
1575 po->chan.ops = &pppol2tp_chan_ops;
1576 po->chan.mtu = session->mtu;
1577
1578 error = ppp_register_channel(&po->chan);
1579 if (error)
1580 goto end;
1581
1582 /* This is how we get the session context from the socket. */
1583 sk->sk_user_data = session;
1584
1585 /* Add session to the tunnel's hash list */
1586 write_lock(&tunnel->hlist_lock);
1587 hlist_add_head(&session->hlist,
1588 pppol2tp_session_id_hash(tunnel,
1589 session->tunnel_addr.s_session));
1590 write_unlock(&tunnel->hlist_lock);
1591
1592 atomic_inc(&pppol2tp_session_count);
1593
1594out_no_ppp:
1595 pppol2tp_tunnel_inc_refcount(tunnel);
1596 sk->sk_state = PPPOX_CONNECTED;
1597 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1598 "%s: created\n", session->name);
1599
1600end:
1601 release_sock(sk);
1602
1603 if (error != 0)
1604 PRINTK(session ? session->debug : -1, PPPOL2TP_MSG_CONTROL, KERN_WARNING,
1605 "%s: connect failed: %d\n", session->name, error);
1606
1607 return error;
1608}
1609
1610/* getname() support.
1611 */
1612static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
1613 int *usockaddr_len, int peer)
1614{
1615 int len = sizeof(struct sockaddr_pppol2tp);
1616 struct sockaddr_pppol2tp sp;
1617 int error = 0;
1618 struct pppol2tp_session *session;
1619
1620 error = -ENOTCONN;
1621 if (sock->sk->sk_state != PPPOX_CONNECTED)
1622 goto end;
1623
1624 session = pppol2tp_sock_to_session(sock->sk);
1625 if (session == NULL) {
1626 error = -EBADF;
1627 goto end;
1628 }
1629
1630 sp.sa_family = AF_PPPOX;
1631 sp.sa_protocol = PX_PROTO_OL2TP;
1632 memcpy(&sp.pppol2tp, &session->tunnel_addr,
1633 sizeof(struct pppol2tp_addr));
1634
1635 memcpy(uaddr, &sp, len);
1636
1637 *usockaddr_len = len;
1638
1639 error = 0;
1640
1641end:
1642 return error;
1643}
1644
1645/****************************************************************************
1646 * ioctl() handlers.
1647 *
1648 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1649 * sockets. However, in order to control kernel tunnel features, we allow
1650 * userspace to create a special "tunnel" PPPoX socket which is used for
1651 * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
1652 * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
1653 * calls.
1654 ****************************************************************************/
1655
1656/* Session ioctl helper.
1657 */
1658static int pppol2tp_session_ioctl(struct pppol2tp_session *session,
1659 unsigned int cmd, unsigned long arg)
1660{
1661 struct ifreq ifr;
1662 int err = 0;
1663 struct sock *sk = session->sock;
1664 int val = (int) arg;
1665
1666 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1667 "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
1668 session->name, cmd, arg);
1669
1670 sock_hold(sk);
1671
1672 switch (cmd) {
1673 case SIOCGIFMTU:
1674 err = -ENXIO;
1675 if (!(sk->sk_state & PPPOX_CONNECTED))
1676 break;
1677
1678 err = -EFAULT;
1679 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1680 break;
1681 ifr.ifr_mtu = session->mtu;
1682 if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
1683 break;
1684
1685 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1686 "%s: get mtu=%d\n", session->name, session->mtu);
1687 err = 0;
1688 break;
1689
1690 case SIOCSIFMTU:
1691 err = -ENXIO;
1692 if (!(sk->sk_state & PPPOX_CONNECTED))
1693 break;
1694
1695 err = -EFAULT;
1696 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1697 break;
1698
1699 session->mtu = ifr.ifr_mtu;
1700
1701 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1702 "%s: set mtu=%d\n", session->name, session->mtu);
1703 err = 0;
1704 break;
1705
1706 case PPPIOCGMRU:
1707 err = -ENXIO;
1708 if (!(sk->sk_state & PPPOX_CONNECTED))
1709 break;
1710
1711 err = -EFAULT;
1712 if (put_user(session->mru, (int __user *) arg))
1713 break;
1714
1715 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1716 "%s: get mru=%d\n", session->name, session->mru);
1717 err = 0;
1718 break;
1719
1720 case PPPIOCSMRU:
1721 err = -ENXIO;
1722 if (!(sk->sk_state & PPPOX_CONNECTED))
1723 break;
1724
1725 err = -EFAULT;
1726 if (get_user(val,(int __user *) arg))
1727 break;
1728
1729 session->mru = val;
1730 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1731 "%s: set mru=%d\n", session->name, session->mru);
1732 err = 0;
1733 break;
1734
1735 case PPPIOCGFLAGS:
1736 err = -EFAULT;
1737 if (put_user(session->flags, (int __user *) arg))
1738 break;
1739
1740 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1741 "%s: get flags=%d\n", session->name, session->flags);
1742 err = 0;
1743 break;
1744
1745 case PPPIOCSFLAGS:
1746 err = -EFAULT;
1747 if (get_user(val, (int __user *) arg))
1748 break;
1749 session->flags = val;
1750 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1751 "%s: set flags=%d\n", session->name, session->flags);
1752 err = 0;
1753 break;
1754
1755 case PPPIOCGL2TPSTATS:
1756 err = -ENXIO;
1757 if (!(sk->sk_state & PPPOX_CONNECTED))
1758 break;
1759
1760 if (copy_to_user((void __user *) arg, &session->stats,
1761 sizeof(session->stats)))
1762 break;
1763 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1764 "%s: get L2TP stats\n", session->name);
1765 err = 0;
1766 break;
1767
1768 default:
1769 err = -ENOSYS;
1770 break;
1771 }
1772
1773 sock_put(sk);
1774
1775 return err;
1776}
1777
1778/* Tunnel ioctl helper.
1779 *
1780 * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
1781 * specifies a session_id, the session ioctl handler is called. This allows an
1782 * application to retrieve session stats via a tunnel socket.
1783 */
1784static int pppol2tp_tunnel_ioctl(struct pppol2tp_tunnel *tunnel,
1785 unsigned int cmd, unsigned long arg)
1786{
1787 int err = 0;
1788 struct sock *sk = tunnel->sock;
1789 struct pppol2tp_ioc_stats stats_req;
1790
1791 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1792 "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n", tunnel->name,
1793 cmd, arg);
1794
1795 sock_hold(sk);
1796
1797 switch (cmd) {
1798 case PPPIOCGL2TPSTATS:
1799 err = -ENXIO;
1800 if (!(sk->sk_state & PPPOX_CONNECTED))
1801 break;
1802
1803 if (copy_from_user(&stats_req, (void __user *) arg,
1804 sizeof(stats_req))) {
1805 err = -EFAULT;
1806 break;
1807 }
1808 if (stats_req.session_id != 0) {
1809 /* resend to session ioctl handler */
1810 struct pppol2tp_session *session =
1811 pppol2tp_session_find(tunnel, stats_req.session_id);
1812 if (session != NULL)
1813 err = pppol2tp_session_ioctl(session, cmd, arg);
1814 else
1815 err = -EBADR;
1816 break;
1817 }
1818#ifdef CONFIG_XFRM
1819 tunnel->stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
1820#endif
1821 if (copy_to_user((void __user *) arg, &tunnel->stats,
1822 sizeof(tunnel->stats))) {
1823 err = -EFAULT;
1824 break;
1825 }
1826 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1827 "%s: get L2TP stats\n", tunnel->name);
1828 err = 0;
1829 break;
1830
1831 default:
1832 err = -ENOSYS;
1833 break;
1834 }
1835
1836 sock_put(sk);
1837
1838 return err;
1839}
1840
1841/* Main ioctl() handler.
1842 * Dispatch to tunnel or session helpers depending on the socket.
1843 */
1844static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1845 unsigned long arg)
1846{
1847 struct sock *sk = sock->sk;
1848 struct pppol2tp_session *session;
1849 struct pppol2tp_tunnel *tunnel;
1850 int err;
1851
1852 if (!sk)
1853 return 0;
1854
1855 err = -EBADF;
1856 if (sock_flag(sk, SOCK_DEAD) != 0)
1857 goto end;
1858
1859 err = -ENOTCONN;
1860 if ((sk->sk_user_data == NULL) ||
1861 (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
1862 goto end;
1863
1864 /* Get session context from the socket */
1865 err = -EBADF;
1866 session = pppol2tp_sock_to_session(sk);
1867 if (session == NULL)
1868 goto end;
1869
1870 /* Special case: if session's session_id is zero, treat ioctl as a
1871 * tunnel ioctl
1872 */
1873 if ((session->tunnel_addr.s_session == 0) &&
1874 (session->tunnel_addr.d_session == 0)) {
1875 err = -EBADF;
1876 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
1877 if (tunnel == NULL)
1878 goto end;
1879
1880 err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
1881 goto end;
1882 }
1883
1884 err = pppol2tp_session_ioctl(session, cmd, arg);
1885
1886end:
1887 return err;
1888}
1889
1890/*****************************************************************************
1891 * setsockopt() / getsockopt() support.
1892 *
1893 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1894 * sockets. In order to control kernel tunnel features, we allow userspace to
1895 * create a special "tunnel" PPPoX socket which is used for control only.
1896 * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
1897 * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
1898 *****************************************************************************/
1899
1900/* Tunnel setsockopt() helper.
1901 */
1902static int pppol2tp_tunnel_setsockopt(struct sock *sk,
1903 struct pppol2tp_tunnel *tunnel,
1904 int optname, int val)
1905{
1906 int err = 0;
1907
1908 switch (optname) {
1909 case PPPOL2TP_SO_DEBUG:
1910 tunnel->debug = val;
1911 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1912 "%s: set debug=%x\n", tunnel->name, tunnel->debug);
1913 break;
1914
1915 default:
1916 err = -ENOPROTOOPT;
1917 break;
1918 }
1919
1920 return err;
1921}
1922
1923/* Session setsockopt helper.
1924 */
1925static int pppol2tp_session_setsockopt(struct sock *sk,
1926 struct pppol2tp_session *session,
1927 int optname, int val)
1928{
1929 int err = 0;
1930
1931 switch (optname) {
1932 case PPPOL2TP_SO_RECVSEQ:
1933 if ((val != 0) && (val != 1)) {
1934 err = -EINVAL;
1935 break;
1936 }
1937 session->recv_seq = val ? -1 : 0;
1938 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1939 "%s: set recv_seq=%d\n", session->name,
1940 session->recv_seq);
1941 break;
1942
1943 case PPPOL2TP_SO_SENDSEQ:
1944 if ((val != 0) && (val != 1)) {
1945 err = -EINVAL;
1946 break;
1947 }
1948 session->send_seq = val ? -1 : 0;
1949 {
1950 struct sock *ssk = session->sock;
1951 struct pppox_sock *po = pppox_sk(ssk);
1952 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1953 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1954 }
1955 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1956 "%s: set send_seq=%d\n", session->name, session->send_seq);
1957 break;
1958
1959 case PPPOL2TP_SO_LNSMODE:
1960 if ((val != 0) && (val != 1)) {
1961 err = -EINVAL;
1962 break;
1963 }
1964 session->lns_mode = val ? -1 : 0;
1965 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1966 "%s: set lns_mode=%d\n", session->name,
1967 session->lns_mode);
1968 break;
1969
1970 case PPPOL2TP_SO_DEBUG:
1971 session->debug = val;
1972 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1973 "%s: set debug=%x\n", session->name, session->debug);
1974 break;
1975
1976 case PPPOL2TP_SO_REORDERTO:
1977 session->reorder_timeout = msecs_to_jiffies(val);
1978 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1979 "%s: set reorder_timeout=%d\n", session->name,
1980 session->reorder_timeout);
1981 break;
1982
1983 default:
1984 err = -ENOPROTOOPT;
1985 break;
1986 }
1987
1988 return err;
1989}
1990
1991/* Main setsockopt() entry point.
1992 * Does API checks, then calls either the tunnel or session setsockopt
1993 * handler, according to whether the PPPoL2TP socket is a for a regular
1994 * session or the special tunnel type.
1995 */
1996static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
1997 char __user *optval, int optlen)
1998{
1999 struct sock *sk = sock->sk;
2000 struct pppol2tp_session *session = sk->sk_user_data;
2001 struct pppol2tp_tunnel *tunnel;
2002 int val;
2003 int err;
2004
2005 if (level != SOL_PPPOL2TP)
2006 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
2007
2008 if (optlen < sizeof(int))
2009 return -EINVAL;
2010
2011 if (get_user(val, (int __user *)optval))
2012 return -EFAULT;
2013
2014 err = -ENOTCONN;
2015 if (sk->sk_user_data == NULL)
2016 goto end;
2017
2018 /* Get session context from the socket */
2019 err = -EBADF;
2020 session = pppol2tp_sock_to_session(sk);
2021 if (session == NULL)
2022 goto end;
2023
2024 /* Special case: if session_id == 0x0000, treat as operation on tunnel
2025 */
2026 if ((session->tunnel_addr.s_session == 0) &&
2027 (session->tunnel_addr.d_session == 0)) {
2028 err = -EBADF;
2029 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
2030 if (tunnel == NULL)
2031 goto end;
2032
2033 err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
2034 } else
2035 err = pppol2tp_session_setsockopt(sk, session, optname, val);
2036
2037 err = 0;
2038
2039end:
2040 return err;
2041}
2042
2043/* Tunnel getsockopt helper. Called with sock locked.
2044 */
2045static int pppol2tp_tunnel_getsockopt(struct sock *sk,
2046 struct pppol2tp_tunnel *tunnel,
2047 int optname, int __user *val)
2048{
2049 int err = 0;
2050
2051 switch (optname) {
2052 case PPPOL2TP_SO_DEBUG:
2053 *val = tunnel->debug;
2054 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2055 "%s: get debug=%x\n", tunnel->name, tunnel->debug);
2056 break;
2057
2058 default:
2059 err = -ENOPROTOOPT;
2060 break;
2061 }
2062
2063 return err;
2064}
2065
2066/* Session getsockopt helper. Called with sock locked.
2067 */
2068static int pppol2tp_session_getsockopt(struct sock *sk,
2069 struct pppol2tp_session *session,
2070 int optname, int __user *val)
2071{
2072 int err = 0;
2073
2074 switch (optname) {
2075 case PPPOL2TP_SO_RECVSEQ:
2076 *val = session->recv_seq;
2077 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2078 "%s: get recv_seq=%d\n", session->name, *val);
2079 break;
2080
2081 case PPPOL2TP_SO_SENDSEQ:
2082 *val = session->send_seq;
2083 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2084 "%s: get send_seq=%d\n", session->name, *val);
2085 break;
2086
2087 case PPPOL2TP_SO_LNSMODE:
2088 *val = session->lns_mode;
2089 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2090 "%s: get lns_mode=%d\n", session->name, *val);
2091 break;
2092
2093 case PPPOL2TP_SO_DEBUG:
2094 *val = session->debug;
2095 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2096 "%s: get debug=%d\n", session->name, *val);
2097 break;
2098
2099 case PPPOL2TP_SO_REORDERTO:
2100 *val = (int) jiffies_to_msecs(session->reorder_timeout);
2101 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2102 "%s: get reorder_timeout=%d\n", session->name, *val);
2103 break;
2104
2105 default:
2106 err = -ENOPROTOOPT;
2107 }
2108
2109 return err;
2110}
2111
2112/* Main getsockopt() entry point.
2113 * Does API checks, then calls either the tunnel or session getsockopt
2114 * handler, according to whether the PPPoX socket is a for a regular session
2115 * or the special tunnel type.
2116 */
2117static int pppol2tp_getsockopt(struct socket *sock, int level,
2118 int optname, char __user *optval, int __user *optlen)
2119{
2120 struct sock *sk = sock->sk;
2121 struct pppol2tp_session *session = sk->sk_user_data;
2122 struct pppol2tp_tunnel *tunnel;
2123 int val, len;
2124 int err;
2125
2126 if (level != SOL_PPPOL2TP)
2127 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
2128
2129 if (get_user(len, (int __user *) optlen))
2130 return -EFAULT;
2131
2132 len = min_t(unsigned int, len, sizeof(int));
2133
2134 if (len < 0)
2135 return -EINVAL;
2136
2137 err = -ENOTCONN;
2138 if (sk->sk_user_data == NULL)
2139 goto end;
2140
2141 /* Get the session context */
2142 err = -EBADF;
2143 session = pppol2tp_sock_to_session(sk);
2144 if (session == NULL)
2145 goto end;
2146
2147 /* Special case: if session_id == 0x0000, treat as operation on tunnel */
2148 if ((session->tunnel_addr.s_session == 0) &&
2149 (session->tunnel_addr.d_session == 0)) {
2150 err = -EBADF;
2151 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
2152 if (tunnel == NULL)
2153 goto end;
2154
2155 err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
2156 } else
2157 err = pppol2tp_session_getsockopt(sk, session, optname, &val);
2158
2159 err = -EFAULT;
2160 if (put_user(len, (int __user *) optlen))
2161 goto end;
2162
2163 if (copy_to_user((void __user *) optval, &val, len))
2164 goto end;
2165
2166 err = 0;
2167end:
2168 return err;
2169}
2170
2171/*****************************************************************************
2172 * /proc filesystem for debug
2173 *****************************************************************************/
2174
2175#ifdef CONFIG_PROC_FS
2176
2177#include <linux/seq_file.h>
2178
2179struct pppol2tp_seq_data {
2180 struct pppol2tp_tunnel *tunnel; /* current tunnel */
2181 struct pppol2tp_session *session; /* NULL means get first session in tunnel */
2182};
2183
2184static struct pppol2tp_session *next_session(struct pppol2tp_tunnel *tunnel, struct pppol2tp_session *curr)
2185{
2186 struct pppol2tp_session *session = NULL;
2187 struct hlist_node *walk;
2188 int found = 0;
2189 int next = 0;
2190 int i;
2191
2192 read_lock(&tunnel->hlist_lock);
2193 for (i = 0; i < PPPOL2TP_HASH_SIZE; i++) {
2194 hlist_for_each_entry(session, walk, &tunnel->session_hlist[i], hlist) {
2195 if (curr == NULL) {
2196 found = 1;
2197 goto out;
2198 }
2199 if (session == curr) {
2200 next = 1;
2201 continue;
2202 }
2203 if (next) {
2204 found = 1;
2205 goto out;
2206 }
2207 }
2208 }
2209out:
2210 read_unlock(&tunnel->hlist_lock);
2211 if (!found)
2212 session = NULL;
2213
2214 return session;
2215}
2216
2217static struct pppol2tp_tunnel *next_tunnel(struct pppol2tp_tunnel *curr)
2218{
2219 struct pppol2tp_tunnel *tunnel = NULL;
2220
2221 read_lock(&pppol2tp_tunnel_list_lock);
2222 if (list_is_last(&curr->list, &pppol2tp_tunnel_list)) {
2223 goto out;
2224 }
2225 tunnel = list_entry(curr->list.next, struct pppol2tp_tunnel, list);
2226out:
2227 read_unlock(&pppol2tp_tunnel_list_lock);
2228
2229 return tunnel;
2230}
2231
2232static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
2233{
2234 struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
2235 loff_t pos = *offs;
2236
2237 if (!pos)
2238 goto out;
2239
2240 BUG_ON(m->private == NULL);
2241 pd = m->private;
2242
2243 if (pd->tunnel == NULL) {
2244 if (!list_empty(&pppol2tp_tunnel_list))
2245 pd->tunnel = list_entry(pppol2tp_tunnel_list.next, struct pppol2tp_tunnel, list);
2246 } else {
2247 pd->session = next_session(pd->tunnel, pd->session);
2248 if (pd->session == NULL) {
2249 pd->tunnel = next_tunnel(pd->tunnel);
2250 }
2251 }
2252
2253 /* NULL tunnel and session indicates end of list */
2254 if ((pd->tunnel == NULL) && (pd->session == NULL))
2255 pd = NULL;
2256
2257out:
2258 return pd;
2259}
2260
2261static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
2262{
2263 (*pos)++;
2264 return NULL;
2265}
2266
2267static void pppol2tp_seq_stop(struct seq_file *p, void *v)
2268{
2269 /* nothing to do */
2270}
2271
2272static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
2273{
2274 struct pppol2tp_tunnel *tunnel = v;
2275
2276 seq_printf(m, "\nTUNNEL '%s', %c %d\n",
2277 tunnel->name,
2278 (tunnel == tunnel->sock->sk_user_data) ? 'Y':'N',
2279 atomic_read(&tunnel->ref_count) - 1);
2280 seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n",
2281 tunnel->debug,
2282 tunnel->stats.tx_packets, tunnel->stats.tx_bytes,
2283 tunnel->stats.tx_errors,
2284 tunnel->stats.rx_packets, tunnel->stats.rx_bytes,
2285 tunnel->stats.rx_errors);
2286}
2287
2288static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
2289{
2290 struct pppol2tp_session *session = v;
2291
2292 seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
2293 "%04X/%04X %d %c\n",
2294 session->name,
2295 ntohl(session->tunnel_addr.addr.sin_addr.s_addr),
2296 ntohs(session->tunnel_addr.addr.sin_port),
2297 session->tunnel_addr.s_tunnel,
2298 session->tunnel_addr.s_session,
2299 session->tunnel_addr.d_tunnel,
2300 session->tunnel_addr.d_session,
2301 session->sock->sk_state,
2302 (session == session->sock->sk_user_data) ?
2303 'Y' : 'N');
2304 seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
2305 session->mtu, session->mru,
2306 session->recv_seq ? 'R' : '-',
2307 session->send_seq ? 'S' : '-',
2308 session->lns_mode ? "LNS" : "LAC",
2309 session->debug,
2310 jiffies_to_msecs(session->reorder_timeout));
2311 seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n",
2312 session->nr, session->ns,
2313 session->stats.tx_packets,
2314 session->stats.tx_bytes,
2315 session->stats.tx_errors,
2316 session->stats.rx_packets,
2317 session->stats.rx_bytes,
2318 session->stats.rx_errors);
2319}
2320
2321static int pppol2tp_seq_show(struct seq_file *m, void *v)
2322{
2323 struct pppol2tp_seq_data *pd = v;
2324
2325 /* display header on line 1 */
2326 if (v == SEQ_START_TOKEN) {
2327 seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
2328 seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
2329 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
2330 seq_puts(m, " SESSION name, addr/port src-tid/sid "
2331 "dest-tid/sid state user-data-ok\n");
2332 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
2333 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
2334 goto out;
2335 }
2336
2337 /* Show the tunnel or session context.
2338 */
2339 if (pd->session == NULL)
2340 pppol2tp_seq_tunnel_show(m, pd->tunnel);
2341 else
2342 pppol2tp_seq_session_show(m, pd->session);
2343
2344out:
2345 return 0;
2346}
2347
2348static struct seq_operations pppol2tp_seq_ops = {
2349 .start = pppol2tp_seq_start,
2350 .next = pppol2tp_seq_next,
2351 .stop = pppol2tp_seq_stop,
2352 .show = pppol2tp_seq_show,
2353};
2354
2355/* Called when our /proc file is opened. We allocate data for use when
2356 * iterating our tunnel / session contexts and store it in the private
2357 * data of the seq_file.
2358 */
2359static int pppol2tp_proc_open(struct inode *inode, struct file *file)
2360{
2361 struct seq_file *m;
2362 struct pppol2tp_seq_data *pd;
2363 int ret = 0;
2364
2365 ret = seq_open(file, &pppol2tp_seq_ops);
2366 if (ret < 0)
2367 goto out;
2368
2369 m = file->private_data;
2370
2371 /* Allocate and fill our proc_data for access later */
2372 ret = -ENOMEM;
2373 m->private = kzalloc(sizeof(struct pppol2tp_seq_data), GFP_KERNEL);
2374 if (m->private == NULL)
2375 goto out;
2376
2377 pd = m->private;
2378 ret = 0;
2379
2380out:
2381 return ret;
2382}
2383
2384/* Called when /proc file access completes.
2385 */
2386static int pppol2tp_proc_release(struct inode *inode, struct file *file)
2387{
2388 struct seq_file *m = (struct seq_file *)file->private_data;
2389
2390 kfree(m->private);
2391 m->private = NULL;
2392
2393 return seq_release(inode, file);
2394}
2395
2396static struct file_operations pppol2tp_proc_fops = {
2397 .owner = THIS_MODULE,
2398 .open = pppol2tp_proc_open,
2399 .read = seq_read,
2400 .llseek = seq_lseek,
2401 .release = pppol2tp_proc_release,
2402};
2403
2404static struct proc_dir_entry *pppol2tp_proc;
2405
2406#endif /* CONFIG_PROC_FS */
2407
2408/*****************************************************************************
2409 * Init and cleanup
2410 *****************************************************************************/
2411
2412static struct proto_ops pppol2tp_ops = {
2413 .family = AF_PPPOX,
2414 .owner = THIS_MODULE,
2415 .release = pppol2tp_release,
2416 .bind = sock_no_bind,
2417 .connect = pppol2tp_connect,
2418 .socketpair = sock_no_socketpair,
2419 .accept = sock_no_accept,
2420 .getname = pppol2tp_getname,
2421 .poll = datagram_poll,
2422 .listen = sock_no_listen,
2423 .shutdown = sock_no_shutdown,
2424 .setsockopt = pppol2tp_setsockopt,
2425 .getsockopt = pppol2tp_getsockopt,
2426 .sendmsg = pppol2tp_sendmsg,
2427 .recvmsg = pppol2tp_recvmsg,
2428 .mmap = sock_no_mmap,
2429 .ioctl = pppox_ioctl,
2430};
2431
2432static struct pppox_proto pppol2tp_proto = {
2433 .create = pppol2tp_create,
2434 .ioctl = pppol2tp_ioctl
2435};
2436
2437static int __init pppol2tp_init(void)
2438{
2439 int err;
2440
2441 err = proto_register(&pppol2tp_sk_proto, 0);
2442 if (err)
2443 goto out;
2444 err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
2445 if (err)
2446 goto out_unregister_pppol2tp_proto;
2447
2448#ifdef CONFIG_PROC_FS
2449 pppol2tp_proc = create_proc_entry("pppol2tp", 0, proc_net);
2450 if (!pppol2tp_proc) {
2451 err = -ENOMEM;
2452 goto out_unregister_pppox_proto;
2453 }
2454 pppol2tp_proc->proc_fops = &pppol2tp_proc_fops;
2455#endif /* CONFIG_PROC_FS */
2456 printk(KERN_INFO "PPPoL2TP kernel driver, %s\n",
2457 PPPOL2TP_DRV_VERSION);
2458
2459out:
2460 return err;
2461
2462out_unregister_pppox_proto:
2463 unregister_pppox_proto(PX_PROTO_OL2TP);
2464out_unregister_pppol2tp_proto:
2465 proto_unregister(&pppol2tp_sk_proto);
2466 goto out;
2467}
2468
2469static void __exit pppol2tp_exit(void)
2470{
2471 unregister_pppox_proto(PX_PROTO_OL2TP);
2472
2473#ifdef CONFIG_PROC_FS
2474 remove_proc_entry("pppol2tp", proc_net);
2475#endif
2476 proto_unregister(&pppol2tp_sk_proto);
2477}
2478
2479module_init(pppol2tp_init);
2480module_exit(pppol2tp_exit);
2481
2482MODULE_AUTHOR("Martijn van Oosterhout <kleptog@svana.org>,"
2483 "James Chapman <jchapman@katalix.com>");
2484MODULE_DESCRIPTION("PPP over L2TP over UDP");
2485MODULE_LICENSE("GPL");
2486MODULE_VERSION(PPPOL2TP_DRV_VERSION);
diff --git a/drivers/net/saa9730.c b/drivers/net/saa9730.c
index ad94358ece89..451486b32f23 100644
--- a/drivers/net/saa9730.c
+++ b/drivers/net/saa9730.c
@@ -690,9 +690,9 @@ static int lan_saa9730_rx(struct net_device *dev)
690 lp->stats.rx_packets++; 690 lp->stats.rx_packets++;
691 skb_reserve(skb, 2); /* 16 byte align */ 691 skb_reserve(skb, 2); /* 16 byte align */
692 skb_put(skb, len); /* make room */ 692 skb_put(skb, len); /* make room */
693 eth_copy_and_sum(skb, 693 skb_copy_to_linear_data(skb,
694 (unsigned char *) pData, 694 (unsigned char *) pData,
695 len, 0); 695 len);
696 skb->protocol = eth_type_trans(skb, dev); 696 skb->protocol = eth_type_trans(skb, dev);
697 netif_rx(skb); 697 netif_rx(skb);
698 dev->last_rx = jiffies; 698 dev->last_rx = jiffies;
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index 2106becf6990..384b4685e977 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -320,7 +320,7 @@ static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp
320 skb_put(skb, len); 320 skb_put(skb, len);
321 321
322 /* Copy out of kseg1 to avoid silly cache flush. */ 322 /* Copy out of kseg1 to avoid silly cache flush. */
323 eth_copy_and_sum(skb, pkt_pointer + 2, len, 0); 323 skb_copy_to_linear_data(skb, pkt_pointer + 2, len);
324 skb->protocol = eth_type_trans(skb, dev); 324 skb->protocol = eth_type_trans(skb, dev);
325 325
326 /* We don't want to receive our own packets */ 326 /* We don't want to receive our own packets */
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index bc8de48da313..ec2ad9f0efa2 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -548,7 +548,7 @@ static inline int sis190_try_rx_copy(struct sk_buff **sk_buff, int pkt_size,
548 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN); 548 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN);
549 if (skb) { 549 if (skb) {
550 skb_reserve(skb, NET_IP_ALIGN); 550 skb_reserve(skb, NET_IP_ALIGN);
551 eth_copy_and_sum(skb, sk_buff[0]->data, pkt_size, 0); 551 skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size);
552 *sk_buff = skb; 552 *sk_buff = skb;
553 sis190_give_to_asic(desc, rx_buf_sz); 553 sis190_give_to_asic(desc, rx_buf_sz);
554 ret = 0; 554 ret = 0;
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index 786d4b9c07ec..f2e101967204 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -1456,7 +1456,7 @@ static int __netdev_rx(struct net_device *dev, int *quota)
1456 pci_dma_sync_single_for_cpu(np->pci_dev, 1456 pci_dma_sync_single_for_cpu(np->pci_dev,
1457 np->rx_info[entry].mapping, 1457 np->rx_info[entry].mapping,
1458 pkt_len, PCI_DMA_FROMDEVICE); 1458 pkt_len, PCI_DMA_FROMDEVICE);
1459 eth_copy_and_sum(skb, np->rx_info[entry].skb->data, pkt_len, 0); 1459 skb_copy_to_linear_data(skb, np->rx_info[entry].skb->data, pkt_len);
1460 pci_dma_sync_single_for_device(np->pci_dev, 1460 pci_dma_sync_single_for_device(np->pci_dev,
1461 np->rx_info[entry].mapping, 1461 np->rx_info[entry].mapping,
1462 pkt_len, PCI_DMA_FROMDEVICE); 1462 pkt_len, PCI_DMA_FROMDEVICE);
diff --git a/drivers/net/sun3_82586.c b/drivers/net/sun3_82586.c
index a123ea87893b..b77ab6e8fd35 100644
--- a/drivers/net/sun3_82586.c
+++ b/drivers/net/sun3_82586.c
@@ -777,7 +777,7 @@ static void sun3_82586_rcv_int(struct net_device *dev)
777 { 777 {
778 skb_reserve(skb,2); 778 skb_reserve(skb,2);
779 skb_put(skb,totlen); 779 skb_put(skb,totlen);
780 eth_copy_and_sum(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen,0); 780 skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen);
781 skb->protocol=eth_type_trans(skb,dev); 781 skb->protocol=eth_type_trans(skb,dev);
782 netif_rx(skb); 782 netif_rx(skb);
783 p->stats.rx_packets++; 783 p->stats.rx_packets++;
diff --git a/drivers/net/sun3lance.c b/drivers/net/sun3lance.c
index 791e081fdc15..f1548c033327 100644
--- a/drivers/net/sun3lance.c
+++ b/drivers/net/sun3lance.c
@@ -853,10 +853,9 @@ static int lance_rx( struct net_device *dev )
853 853
854 skb_reserve( skb, 2 ); /* 16 byte align */ 854 skb_reserve( skb, 2 ); /* 16 byte align */
855 skb_put( skb, pkt_len ); /* Make room */ 855 skb_put( skb, pkt_len ); /* Make room */
856// skb_copy_to_linear_data(skb, PKTBUF_ADDR(head), pkt_len); 856 skb_copy_to_linear_data(skb,
857 eth_copy_and_sum(skb,
858 PKTBUF_ADDR(head), 857 PKTBUF_ADDR(head),
859 pkt_len, 0); 858 pkt_len);
860 859
861 skb->protocol = eth_type_trans( skb, dev ); 860 skb->protocol = eth_type_trans( skb, dev );
862 netif_rx( skb ); 861 netif_rx( skb );
diff --git a/drivers/net/sunbmac.c b/drivers/net/sunbmac.c
index 2ad8d58dee3b..b3e0158def4f 100644
--- a/drivers/net/sunbmac.c
+++ b/drivers/net/sunbmac.c
@@ -860,7 +860,7 @@ static void bigmac_rx(struct bigmac *bp)
860 sbus_dma_sync_single_for_cpu(bp->bigmac_sdev, 860 sbus_dma_sync_single_for_cpu(bp->bigmac_sdev,
861 this->rx_addr, len, 861 this->rx_addr, len,
862 SBUS_DMA_FROMDEVICE); 862 SBUS_DMA_FROMDEVICE);
863 eth_copy_and_sum(copy_skb, (unsigned char *)skb->data, len, 0); 863 skb_copy_to_linear_data(copy_skb, (unsigned char *)skb->data, len);
864 sbus_dma_sync_single_for_device(bp->bigmac_sdev, 864 sbus_dma_sync_single_for_device(bp->bigmac_sdev,
865 this->rx_addr, len, 865 this->rx_addr, len,
866 SBUS_DMA_FROMDEVICE); 866 SBUS_DMA_FROMDEVICE);
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index e1f912d04043..c8ba534c17bf 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -1313,7 +1313,7 @@ static void rx_poll(unsigned long data)
1313 np->rx_buf_sz, 1313 np->rx_buf_sz,
1314 PCI_DMA_FROMDEVICE); 1314 PCI_DMA_FROMDEVICE);
1315 1315
1316 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0); 1316 skb_copy_to_linear_data(skb, np->rx_skbuff[entry]->data, pkt_len);
1317 pci_dma_sync_single_for_device(np->pci_dev, 1317 pci_dma_sync_single_for_device(np->pci_dev,
1318 desc->frag[0].addr, 1318 desc->frag[0].addr,
1319 np->rx_buf_sz, 1319 np->rx_buf_sz,
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index 42722530ab24..053b7cb0d944 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -549,9 +549,9 @@ static void lance_rx_dvma(struct net_device *dev)
549 549
550 skb_reserve(skb, 2); /* 16 byte align */ 550 skb_reserve(skb, 2); /* 16 byte align */
551 skb_put(skb, len); /* make room */ 551 skb_put(skb, len); /* make room */
552 eth_copy_and_sum(skb, 552 skb_copy_to_linear_data(skb,
553 (unsigned char *)&(ib->rx_buf [entry][0]), 553 (unsigned char *)&(ib->rx_buf [entry][0]),
554 len, 0); 554 len);
555 skb->protocol = eth_type_trans(skb, dev); 555 skb->protocol = eth_type_trans(skb, dev);
556 netif_rx(skb); 556 netif_rx(skb);
557 dev->last_rx = jiffies; 557 dev->last_rx = jiffies;
diff --git a/drivers/net/sunqe.c b/drivers/net/sunqe.c
index fa70e0b78af7..1b65ae8a1c7c 100644
--- a/drivers/net/sunqe.c
+++ b/drivers/net/sunqe.c
@@ -439,8 +439,8 @@ static void qe_rx(struct sunqe *qep)
439 } else { 439 } else {
440 skb_reserve(skb, 2); 440 skb_reserve(skb, 2);
441 skb_put(skb, len); 441 skb_put(skb, len);
442 eth_copy_and_sum(skb, (unsigned char *) this_qbuf, 442 skb_copy_to_linear_data(skb, (unsigned char *) this_qbuf,
443 len, 0); 443 len);
444 skb->protocol = eth_type_trans(skb, qep->dev); 444 skb->protocol = eth_type_trans(skb, qep->dev);
445 netif_rx(skb); 445 netif_rx(skb);
446 qep->dev->last_rx = jiffies; 446 qep->dev->last_rx = jiffies;
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 2f3184184ad9..3245f16baabc 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -64,8 +64,8 @@
64 64
65#define DRV_MODULE_NAME "tg3" 65#define DRV_MODULE_NAME "tg3"
66#define PFX DRV_MODULE_NAME ": " 66#define PFX DRV_MODULE_NAME ": "
67#define DRV_MODULE_VERSION "3.77" 67#define DRV_MODULE_VERSION "3.78"
68#define DRV_MODULE_RELDATE "May 31, 2007" 68#define DRV_MODULE_RELDATE "July 11, 2007"
69 69
70#define TG3_DEF_MAC_MODE 0 70#define TG3_DEF_MAC_MODE 0
71#define TG3_DEF_RX_MODE 0 71#define TG3_DEF_RX_MODE 0
@@ -721,6 +721,44 @@ static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
721 return ret; 721 return ret;
722} 722}
723 723
724static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable)
725{
726 u32 phy;
727
728 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
729 (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
730 return;
731
732 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
733 u32 ephy;
734
735 if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &ephy)) {
736 tg3_writephy(tp, MII_TG3_EPHY_TEST,
737 ephy | MII_TG3_EPHY_SHADOW_EN);
738 if (!tg3_readphy(tp, MII_TG3_EPHYTST_MISCCTRL, &phy)) {
739 if (enable)
740 phy |= MII_TG3_EPHYTST_MISCCTRL_MDIX;
741 else
742 phy &= ~MII_TG3_EPHYTST_MISCCTRL_MDIX;
743 tg3_writephy(tp, MII_TG3_EPHYTST_MISCCTRL, phy);
744 }
745 tg3_writephy(tp, MII_TG3_EPHY_TEST, ephy);
746 }
747 } else {
748 phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC |
749 MII_TG3_AUXCTL_SHDWSEL_MISC;
750 if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) &&
751 !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) {
752 if (enable)
753 phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
754 else
755 phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
756 phy |= MII_TG3_AUXCTL_MISC_WREN;
757 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
758 }
759 }
760}
761
724static void tg3_phy_set_wirespeed(struct tg3 *tp) 762static void tg3_phy_set_wirespeed(struct tg3 *tp)
725{ 763{
726 u32 val; 764 u32 val;
@@ -1045,23 +1083,11 @@ out:
1045 } 1083 }
1046 1084
1047 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { 1085 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1048 u32 phy_reg;
1049
1050 /* adjust output voltage */ 1086 /* adjust output voltage */
1051 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12); 1087 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
1052
1053 if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
1054 u32 phy_reg2;
1055
1056 tg3_writephy(tp, MII_TG3_EPHY_TEST,
1057 phy_reg | MII_TG3_EPHY_SHADOW_EN);
1058 /* Enable auto-MDIX */
1059 if (!tg3_readphy(tp, 0x10, &phy_reg2))
1060 tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
1061 tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
1062 }
1063 } 1088 }
1064 1089
1090 tg3_phy_toggle_automdix(tp, 1);
1065 tg3_phy_set_wirespeed(tp); 1091 tg3_phy_set_wirespeed(tp);
1066 return 0; 1092 return 0;
1067} 1093}
@@ -1162,6 +1188,19 @@ static void tg3_frob_aux_power(struct tg3 *tp)
1162 } 1188 }
1163} 1189}
1164 1190
1191static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
1192{
1193 if (tp->led_ctrl == LED_CTRL_MODE_PHY_2)
1194 return 1;
1195 else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411) {
1196 if (speed != SPEED_10)
1197 return 1;
1198 } else if (speed == SPEED_10)
1199 return 1;
1200
1201 return 0;
1202}
1203
1165static int tg3_setup_phy(struct tg3 *, int); 1204static int tg3_setup_phy(struct tg3 *, int);
1166 1205
1167#define RESET_KIND_SHUTDOWN 0 1206#define RESET_KIND_SHUTDOWN 0
@@ -1320,9 +1359,17 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1320 else 1359 else
1321 mac_mode = MAC_MODE_PORT_MODE_MII; 1360 mac_mode = MAC_MODE_PORT_MODE_MII;
1322 1361
1323 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 || 1362 mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY;
1324 !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)) 1363 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
1325 mac_mode |= MAC_MODE_LINK_POLARITY; 1364 ASIC_REV_5700) {
1365 u32 speed = (tp->tg3_flags &
1366 TG3_FLAG_WOL_SPEED_100MB) ?
1367 SPEED_100 : SPEED_10;
1368 if (tg3_5700_link_polarity(tp, speed))
1369 mac_mode |= MAC_MODE_LINK_POLARITY;
1370 else
1371 mac_mode &= ~MAC_MODE_LINK_POLARITY;
1372 }
1326 } else { 1373 } else {
1327 mac_mode = MAC_MODE_PORT_MODE_TBI; 1374 mac_mode = MAC_MODE_PORT_MODE_TBI;
1328 } 1375 }
@@ -1990,15 +2037,12 @@ relink:
1990 if (tp->link_config.active_duplex == DUPLEX_HALF) 2037 if (tp->link_config.active_duplex == DUPLEX_HALF)
1991 tp->mac_mode |= MAC_MODE_HALF_DUPLEX; 2038 tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
1992 2039
1993 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
1994 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { 2040 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
1995 if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) || 2041 if (current_link_up == 1 &&
1996 (current_link_up == 1 && 2042 tg3_5700_link_polarity(tp, tp->link_config.active_speed))
1997 tp->link_config.active_speed == SPEED_10))
1998 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
1999 } else {
2000 if (current_link_up == 1)
2001 tp->mac_mode |= MAC_MODE_LINK_POLARITY; 2043 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
2044 else
2045 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
2002 } 2046 }
2003 2047
2004 /* ??? Without this setting Netgear GA302T PHY does not 2048 /* ??? Without this setting Netgear GA302T PHY does not
@@ -2639,6 +2683,9 @@ static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
2639 2683
2640 tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); 2684 tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
2641 udelay(40); 2685 udelay(40);
2686
2687 tw32_f(MAC_MODE, tp->mac_mode);
2688 udelay(40);
2642 } 2689 }
2643 2690
2644out: 2691out:
@@ -2698,10 +2745,6 @@ static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
2698 else 2745 else
2699 current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); 2746 current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
2700 2747
2701 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
2702 tw32_f(MAC_MODE, tp->mac_mode);
2703 udelay(40);
2704
2705 tp->hw_status->status = 2748 tp->hw_status->status =
2706 (SD_STATUS_UPDATED | 2749 (SD_STATUS_UPDATED |
2707 (tp->hw_status->status & ~SD_STATUS_LINK_CHG)); 2750 (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
@@ -3512,9 +3555,9 @@ static inline int tg3_irq_sync(struct tg3 *tp)
3512 */ 3555 */
3513static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) 3556static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
3514{ 3557{
3558 spin_lock_bh(&tp->lock);
3515 if (irq_sync) 3559 if (irq_sync)
3516 tg3_irq_quiesce(tp); 3560 tg3_irq_quiesce(tp);
3517 spin_lock_bh(&tp->lock);
3518} 3561}
3519 3562
3520static inline void tg3_full_unlock(struct tg3 *tp) 3563static inline void tg3_full_unlock(struct tg3 *tp)
@@ -6444,6 +6487,10 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
6444 6487
6445 tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | 6488 tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
6446 MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; 6489 MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
6490 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
6491 !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
6492 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
6493 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
6447 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); 6494 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
6448 udelay(40); 6495 udelay(40);
6449 6496
@@ -8805,7 +8852,9 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8805 return 0; 8852 return 0;
8806 8853
8807 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8854 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8808 MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY; 8855 MAC_MODE_PORT_INT_LPBACK;
8856 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
8857 mac_mode |= MAC_MODE_LINK_POLARITY;
8809 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY) 8858 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
8810 mac_mode |= MAC_MODE_PORT_MODE_MII; 8859 mac_mode |= MAC_MODE_PORT_MODE_MII;
8811 else 8860 else
@@ -8824,19 +8873,18 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8824 phytest | MII_TG3_EPHY_SHADOW_EN); 8873 phytest | MII_TG3_EPHY_SHADOW_EN);
8825 if (!tg3_readphy(tp, 0x1b, &phy)) 8874 if (!tg3_readphy(tp, 0x1b, &phy))
8826 tg3_writephy(tp, 0x1b, phy & ~0x20); 8875 tg3_writephy(tp, 0x1b, phy & ~0x20);
8827 if (!tg3_readphy(tp, 0x10, &phy))
8828 tg3_writephy(tp, 0x10, phy & ~0x4000);
8829 tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest); 8876 tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
8830 } 8877 }
8831 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; 8878 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
8832 } else 8879 } else
8833 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; 8880 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
8834 8881
8882 tg3_phy_toggle_automdix(tp, 0);
8883
8835 tg3_writephy(tp, MII_BMCR, val); 8884 tg3_writephy(tp, MII_BMCR, val);
8836 udelay(40); 8885 udelay(40);
8837 8886
8838 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8887 mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
8839 MAC_MODE_LINK_POLARITY;
8840 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { 8888 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
8841 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800); 8889 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
8842 mac_mode |= MAC_MODE_PORT_MODE_MII; 8890 mac_mode |= MAC_MODE_PORT_MODE_MII;
@@ -8849,8 +8897,11 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8849 udelay(10); 8897 udelay(10);
8850 tw32_f(MAC_RX_MODE, tp->rx_mode); 8898 tw32_f(MAC_RX_MODE, tp->rx_mode);
8851 } 8899 }
8852 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) { 8900 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
8853 mac_mode &= ~MAC_MODE_LINK_POLARITY; 8901 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
8902 mac_mode &= ~MAC_MODE_LINK_POLARITY;
8903 else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411)
8904 mac_mode |= MAC_MODE_LINK_POLARITY;
8854 tg3_writephy(tp, MII_TG3_EXT_CTRL, 8905 tg3_writephy(tp, MII_TG3_EXT_CTRL,
8855 MII_TG3_EXT_CTRL_LNK3_LED_MODE); 8906 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
8856 } 8907 }
@@ -9116,10 +9167,10 @@ static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
9116 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */ 9167 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
9117 __tg3_set_rx_mode(dev); 9168 __tg3_set_rx_mode(dev);
9118 9169
9119 tg3_full_unlock(tp);
9120
9121 if (netif_running(dev)) 9170 if (netif_running(dev))
9122 tg3_netif_start(tp); 9171 tg3_netif_start(tp);
9172
9173 tg3_full_unlock(tp);
9123} 9174}
9124#endif 9175#endif
9125 9176
@@ -9410,11 +9461,13 @@ static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
9410 case FLASH_5755VENDOR_ATMEL_FLASH_1: 9461 case FLASH_5755VENDOR_ATMEL_FLASH_1:
9411 case FLASH_5755VENDOR_ATMEL_FLASH_2: 9462 case FLASH_5755VENDOR_ATMEL_FLASH_2:
9412 case FLASH_5755VENDOR_ATMEL_FLASH_3: 9463 case FLASH_5755VENDOR_ATMEL_FLASH_3:
9464 case FLASH_5755VENDOR_ATMEL_FLASH_5:
9413 tp->nvram_jedecnum = JEDEC_ATMEL; 9465 tp->nvram_jedecnum = JEDEC_ATMEL;
9414 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; 9466 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
9415 tp->tg3_flags2 |= TG3_FLG2_FLASH; 9467 tp->tg3_flags2 |= TG3_FLG2_FLASH;
9416 tp->nvram_pagesize = 264; 9468 tp->nvram_pagesize = 264;
9417 if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1) 9469 if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
9470 nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
9418 tp->nvram_size = (protect ? 0x3e200 : 0x80000); 9471 tp->nvram_size = (protect ? 0x3e200 : 0x80000);
9419 else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) 9472 else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
9420 tp->nvram_size = (protect ? 0x1f200 : 0x40000); 9473 tp->nvram_size = (protect ? 0x1f200 : 0x40000);
@@ -11944,12 +11997,11 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11944 * checksumming. 11997 * checksumming.
11945 */ 11998 */
11946 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) { 11999 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
12000 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
11947 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 12001 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
11948 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 12002 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
11949 dev->features |= NETIF_F_HW_CSUM; 12003 dev->features |= NETIF_F_IPV6_CSUM;
11950 else 12004
11951 dev->features |= NETIF_F_IP_CSUM;
11952 dev->features |= NETIF_F_SG;
11953 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; 12005 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
11954 } else 12006 } else
11955 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS; 12007 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index bd9f4f428e5b..d84e75e7365d 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -1467,6 +1467,7 @@
1467#define FLASH_5755VENDOR_ATMEL_FLASH_2 0x03400002 1467#define FLASH_5755VENDOR_ATMEL_FLASH_2 0x03400002
1468#define FLASH_5755VENDOR_ATMEL_FLASH_3 0x03400000 1468#define FLASH_5755VENDOR_ATMEL_FLASH_3 0x03400000
1469#define FLASH_5755VENDOR_ATMEL_FLASH_4 0x00000003 1469#define FLASH_5755VENDOR_ATMEL_FLASH_4 0x00000003
1470#define FLASH_5755VENDOR_ATMEL_FLASH_5 0x02000003
1470#define FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ 0x03c00003 1471#define FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ 0x03c00003
1471#define FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ 0x03c00002 1472#define FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ 0x03c00002
1472#define FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ 0x03000003 1473#define FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ 0x03000003
@@ -1642,6 +1643,11 @@
1642 1643
1643#define MII_TG3_AUX_CTRL 0x18 /* auxilliary control register */ 1644#define MII_TG3_AUX_CTRL 0x18 /* auxilliary control register */
1644 1645
1646#define MII_TG3_AUXCTL_MISC_WREN 0x8000
1647#define MII_TG3_AUXCTL_MISC_FORCE_AMDIX 0x0200
1648#define MII_TG3_AUXCTL_MISC_RDSEL_MISC 0x7000
1649#define MII_TG3_AUXCTL_SHDWSEL_MISC 0x0007
1650
1645#define MII_TG3_AUX_STAT 0x19 /* auxilliary status register */ 1651#define MII_TG3_AUX_STAT 0x19 /* auxilliary status register */
1646#define MII_TG3_AUX_STAT_LPASS 0x0004 1652#define MII_TG3_AUX_STAT_LPASS 0x0004
1647#define MII_TG3_AUX_STAT_SPDMASK 0x0700 1653#define MII_TG3_AUX_STAT_SPDMASK 0x0700
@@ -1667,6 +1673,9 @@
1667#define MII_TG3_EPHY_TEST 0x1f /* 5906 PHY register */ 1673#define MII_TG3_EPHY_TEST 0x1f /* 5906 PHY register */
1668#define MII_TG3_EPHY_SHADOW_EN 0x80 1674#define MII_TG3_EPHY_SHADOW_EN 0x80
1669 1675
1676#define MII_TG3_EPHYTST_MISCCTRL 0x10 /* 5906 EPHY misc ctrl shadow register */
1677#define MII_TG3_EPHYTST_MISCCTRL_MDIX 0x4000
1678
1670#define MII_TG3_TEST1 0x1e 1679#define MII_TG3_TEST1 0x1e
1671#define MII_TG3_TEST1_TRIM_EN 0x0010 1680#define MII_TG3_TEST1_TRIM_EN 0x0010
1672#define MII_TG3_TEST1_CRC_EN 0x8000 1681#define MII_TG3_TEST1_CRC_EN 0x8000
diff --git a/drivers/net/tulip/interrupt.c b/drivers/net/tulip/interrupt.c
index ea896777bcaf..53efd6694e75 100644
--- a/drivers/net/tulip/interrupt.c
+++ b/drivers/net/tulip/interrupt.c
@@ -197,8 +197,8 @@ int tulip_poll(struct net_device *dev, int *budget)
197 tp->rx_buffers[entry].mapping, 197 tp->rx_buffers[entry].mapping,
198 pkt_len, PCI_DMA_FROMDEVICE); 198 pkt_len, PCI_DMA_FROMDEVICE);
199#if ! defined(__alpha__) 199#if ! defined(__alpha__)
200 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data, 200 skb_copy_to_linear_data(skb, tp->rx_buffers[entry].skb->data,
201 pkt_len, 0); 201 pkt_len);
202 skb_put(skb, pkt_len); 202 skb_put(skb, pkt_len);
203#else 203#else
204 memcpy(skb_put(skb, pkt_len), 204 memcpy(skb_put(skb, pkt_len),
@@ -420,8 +420,8 @@ static int tulip_rx(struct net_device *dev)
420 tp->rx_buffers[entry].mapping, 420 tp->rx_buffers[entry].mapping,
421 pkt_len, PCI_DMA_FROMDEVICE); 421 pkt_len, PCI_DMA_FROMDEVICE);
422#if ! defined(__alpha__) 422#if ! defined(__alpha__)
423 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data, 423 skb_copy_to_linear_data(skb, tp->rx_buffers[entry].skb->data,
424 pkt_len, 0); 424 pkt_len);
425 skb_put(skb, pkt_len); 425 skb_put(skb, pkt_len);
426#else 426#else
427 memcpy(skb_put(skb, pkt_len), 427 memcpy(skb_put(skb, pkt_len),
diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
index 38f3b99716b8..5824f6a35495 100644
--- a/drivers/net/tulip/winbond-840.c
+++ b/drivers/net/tulip/winbond-840.c
@@ -1232,7 +1232,7 @@ static int netdev_rx(struct net_device *dev)
1232 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry], 1232 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry],
1233 np->rx_skbuff[entry]->len, 1233 np->rx_skbuff[entry]->len,
1234 PCI_DMA_FROMDEVICE); 1234 PCI_DMA_FROMDEVICE);
1235 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0); 1235 skb_copy_to_linear_data(skb, np->rx_skbuff[entry]->data, pkt_len);
1236 skb_put(skb, pkt_len); 1236 skb_put(skb, pkt_len);
1237 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry], 1237 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry],
1238 np->rx_skbuff[entry]->len, 1238 np->rx_skbuff[entry]->len,
diff --git a/drivers/net/tulip/xircom_cb.c b/drivers/net/tulip/xircom_cb.c
index 2470b1ee33c0..37e35cd277a1 100644
--- a/drivers/net/tulip/xircom_cb.c
+++ b/drivers/net/tulip/xircom_cb.c
@@ -1208,7 +1208,7 @@ static void investigate_read_descriptor(struct net_device *dev,struct xircom_pri
1208 goto out; 1208 goto out;
1209 } 1209 }
1210 skb_reserve(skb, 2); 1210 skb_reserve(skb, 2);
1211 eth_copy_and_sum(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len, 0); 1211 skb_copy_to_linear_data(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len);
1212 skb_put(skb, pkt_len); 1212 skb_put(skb, pkt_len);
1213 skb->protocol = eth_type_trans(skb, dev); 1213 skb->protocol = eth_type_trans(skb, dev);
1214 netif_rx(skb); 1214 netif_rx(skb);
diff --git a/drivers/net/tulip/xircom_tulip_cb.c b/drivers/net/tulip/xircom_tulip_cb.c
index f64172927377..f984fbde8b23 100644
--- a/drivers/net/tulip/xircom_tulip_cb.c
+++ b/drivers/net/tulip/xircom_tulip_cb.c
@@ -1242,8 +1242,8 @@ xircom_rx(struct net_device *dev)
1242 && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) { 1242 && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1243 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1243 skb_reserve(skb, 2); /* 16 byte align the IP header */
1244#if ! defined(__alpha__) 1244#if ! defined(__alpha__)
1245 eth_copy_and_sum(skb, bus_to_virt(tp->rx_ring[entry].buffer1), 1245 skb_copy_to_linear_data(skb, bus_to_virt(tp->rx_ring[entry].buffer1),
1246 pkt_len, 0); 1246 pkt_len);
1247 skb_put(skb, pkt_len); 1247 skb_put(skb, pkt_len);
1248#else 1248#else
1249 memcpy(skb_put(skb, pkt_len), 1249 memcpy(skb_put(skb, pkt_len),
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index a2c6caaaae93..62b2b3005019 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -432,6 +432,7 @@ static void tun_setup(struct net_device *dev)
432 init_waitqueue_head(&tun->read_wait); 432 init_waitqueue_head(&tun->read_wait);
433 433
434 tun->owner = -1; 434 tun->owner = -1;
435 tun->group = -1;
435 436
436 SET_MODULE_OWNER(dev); 437 SET_MODULE_OWNER(dev);
437 dev->open = tun_net_open; 438 dev->open = tun_net_open;
@@ -467,8 +468,11 @@ static int tun_set_iff(struct file *file, struct ifreq *ifr)
467 return -EBUSY; 468 return -EBUSY;
468 469
469 /* Check permissions */ 470 /* Check permissions */
470 if (tun->owner != -1 && 471 if (((tun->owner != -1 &&
471 current->euid != tun->owner && !capable(CAP_NET_ADMIN)) 472 current->euid != tun->owner) ||
473 (tun->group != -1 &&
474 current->egid != tun->group)) &&
475 !capable(CAP_NET_ADMIN))
472 return -EPERM; 476 return -EPERM;
473 } 477 }
474 else if (__dev_get_by_name(ifr->ifr_name)) 478 else if (__dev_get_by_name(ifr->ifr_name))
@@ -610,6 +614,13 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
610 DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner); 614 DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner);
611 break; 615 break;
612 616
617 case TUNSETGROUP:
618 /* Set group of the device */
619 tun->group= (gid_t) arg;
620
621 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
622 break;
623
613 case TUNSETLINK: 624 case TUNSETLINK:
614 /* Only allow setting the type when the interface is down */ 625 /* Only allow setting the type when the interface is down */
615 if (tun->dev->flags & IFF_UP) { 626 if (tun->dev->flags & IFF_UP) {
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 15b2fb8aa492..df524548d531 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -1703,7 +1703,7 @@ typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile u32 * ready,
1703 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, 1703 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr,
1704 PKT_BUF_SZ, 1704 PKT_BUF_SZ,
1705 PCI_DMA_FROMDEVICE); 1705 PCI_DMA_FROMDEVICE);
1706 eth_copy_and_sum(new_skb, skb->data, pkt_len, 0); 1706 skb_copy_to_linear_data(new_skb, skb->data, pkt_len);
1707 pci_dma_sync_single_for_device(tp->pdev, dma_addr, 1707 pci_dma_sync_single_for_device(tp->pdev, dma_addr,
1708 PKT_BUF_SZ, 1708 PKT_BUF_SZ,
1709 PCI_DMA_FROMDEVICE); 1709 PCI_DMA_FROMDEVICE);
diff --git a/drivers/net/usb/catc.c b/drivers/net/usb/catc.c
index 86e90c59d551..76752d84a30f 100644
--- a/drivers/net/usb/catc.c
+++ b/drivers/net/usb/catc.c
@@ -255,7 +255,7 @@ static void catc_rx_done(struct urb *urb)
255 if (!(skb = dev_alloc_skb(pkt_len))) 255 if (!(skb = dev_alloc_skb(pkt_len)))
256 return; 256 return;
257 257
258 eth_copy_and_sum(skb, pkt_start + pkt_offset, pkt_len, 0); 258 skb_copy_to_linear_data(skb, pkt_start + pkt_offset, pkt_len);
259 skb_put(skb, pkt_len); 259 skb_put(skb, pkt_len);
260 260
261 skb->protocol = eth_type_trans(skb, catc->netdev); 261 skb->protocol = eth_type_trans(skb, catc->netdev);
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 60d29440f316..524dc5f5e46d 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -635,7 +635,7 @@ static void kaweth_usb_receive(struct urb *urb)
635 635
636 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 636 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
637 637
638 eth_copy_and_sum(skb, kaweth->rx_buf + 2, pkt_len, 0); 638 skb_copy_to_linear_data(skb, kaweth->rx_buf + 2, pkt_len);
639 639
640 skb_put(skb, pkt_len); 640 skb_put(skb, pkt_len);
641 641
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index adea290a9d5e..565f6cc185ce 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -1492,9 +1492,9 @@ static int rhine_rx(struct net_device *dev, int limit)
1492 rp->rx_buf_sz, 1492 rp->rx_buf_sz,
1493 PCI_DMA_FROMDEVICE); 1493 PCI_DMA_FROMDEVICE);
1494 1494
1495 eth_copy_and_sum(skb, 1495 skb_copy_to_linear_data(skb,
1496 rp->rx_skbuff[entry]->data, 1496 rp->rx_skbuff[entry]->data,
1497 pkt_len, 0); 1497 pkt_len);
1498 skb_put(skb, pkt_len); 1498 skb_put(skb, pkt_len);
1499 pci_dma_sync_single_for_device(rp->pdev, 1499 pci_dma_sync_single_for_device(rp->pdev,
1500 rp->rx_skbuff_dma[entry], 1500 rp->rx_skbuff_dma[entry],
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index ce9230b2f630..c8b5c2271938 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -1011,7 +1011,7 @@ static inline void wl3501_md_ind_interrupt(struct net_device *dev,
1011 } else { 1011 } else {
1012 skb->dev = dev; 1012 skb->dev = dev;
1013 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */ 1013 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
1014 eth_copy_and_sum(skb, (unsigned char *)&sig.daddr, 12, 0); 1014 skb_copy_to_linear_data(skb, (unsigned char *)&sig.daddr, 12);
1015 wl3501_receive(this, skb->data, pkt_len); 1015 wl3501_receive(this, skb->data, pkt_len);
1016 skb_put(skb, pkt_len); 1016 skb_put(skb, pkt_len);
1017 skb->protocol = eth_type_trans(skb, dev); 1017 skb->protocol = eth_type_trans(skb, dev);
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index f2a90a7fa2d6..870c5393c21a 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -1137,7 +1137,7 @@ static int yellowfin_rx(struct net_device *dev)
1137 if (skb == NULL) 1137 if (skb == NULL)
1138 break; 1138 break;
1139 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1139 skb_reserve(skb, 2); /* 16 byte align the IP header */
1140 eth_copy_and_sum(skb, rx_skb->data, pkt_len, 0); 1140 skb_copy_to_linear_data(skb, rx_skb->data, pkt_len);
1141 skb_put(skb, pkt_len); 1141 skb_put(skb, pkt_len);
1142 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr, 1142 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr,
1143 yp->rx_buf_sz, 1143 yp->rx_buf_sz,