aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb/smsc75xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/usb/smsc75xx.c')
-rw-r--r--drivers/net/usb/smsc75xx.c131
1 files changed, 48 insertions, 83 deletions
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 753ee6eb7edd..15b3d6888ae9 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -65,7 +65,6 @@ struct smsc75xx_priv {
65 struct usbnet *dev; 65 struct usbnet *dev;
66 u32 rfe_ctl; 66 u32 rfe_ctl;
67 u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN]; 67 u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN];
68 bool use_rx_csum;
69 struct mutex dataport_mutex; 68 struct mutex dataport_mutex;
70 spinlock_t rfe_ctl_lock; 69 spinlock_t rfe_ctl_lock;
71 struct work_struct set_multicast; 70 struct work_struct set_multicast;
@@ -504,7 +503,7 @@ static int smsc75xx_update_flowcontrol(struct usbnet *dev, u8 duplex,
504static int smsc75xx_link_reset(struct usbnet *dev) 503static int smsc75xx_link_reset(struct usbnet *dev)
505{ 504{
506 struct mii_if_info *mii = &dev->mii; 505 struct mii_if_info *mii = &dev->mii;
507 struct ethtool_cmd ecmd; 506 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
508 u16 lcladv, rmtadv; 507 u16 lcladv, rmtadv;
509 int ret; 508 int ret;
510 509
@@ -520,8 +519,9 @@ static int smsc75xx_link_reset(struct usbnet *dev)
520 lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); 519 lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
521 rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA); 520 rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
522 521
523 netif_dbg(dev, link, dev->net, "speed: %d duplex: %d lcladv: %04x" 522 netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x"
524 " rmtadv: %04x", ecmd.speed, ecmd.duplex, lcladv, rmtadv); 523 " rmtadv: %04x", ethtool_cmd_speed(&ecmd),
524 ecmd.duplex, lcladv, rmtadv);
525 525
526 return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); 526 return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
527} 527}
@@ -548,28 +548,6 @@ static void smsc75xx_status(struct usbnet *dev, struct urb *urb)
548 "unexpected interrupt, intdata=0x%08X", intdata); 548 "unexpected interrupt, intdata=0x%08X", intdata);
549} 549}
550 550
551/* Enable or disable Rx checksum offload engine */
552static int smsc75xx_set_rx_csum_offload(struct usbnet *dev)
553{
554 struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
555 unsigned long flags;
556 int ret;
557
558 spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
559
560 if (pdata->use_rx_csum)
561 pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM;
562 else
563 pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM);
564
565 spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
566
567 ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
568 check_warn_return(ret, "Error writing RFE_CTL");
569
570 return 0;
571}
572
573static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net) 551static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net)
574{ 552{
575 return MAX_EEPROM_SIZE; 553 return MAX_EEPROM_SIZE;
@@ -599,34 +577,6 @@ static int smsc75xx_ethtool_set_eeprom(struct net_device *netdev,
599 return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data); 577 return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data);
600} 578}
601 579
602static u32 smsc75xx_ethtool_get_rx_csum(struct net_device *netdev)
603{
604 struct usbnet *dev = netdev_priv(netdev);
605 struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
606
607 return pdata->use_rx_csum;
608}
609
610static int smsc75xx_ethtool_set_rx_csum(struct net_device *netdev, u32 val)
611{
612 struct usbnet *dev = netdev_priv(netdev);
613 struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
614
615 pdata->use_rx_csum = !!val;
616
617 return smsc75xx_set_rx_csum_offload(dev);
618}
619
620static int smsc75xx_ethtool_set_tso(struct net_device *netdev, u32 data)
621{
622 if (data)
623 netdev->features |= NETIF_F_TSO | NETIF_F_TSO6;
624 else
625 netdev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
626
627 return 0;
628}
629
630static const struct ethtool_ops smsc75xx_ethtool_ops = { 580static const struct ethtool_ops smsc75xx_ethtool_ops = {
631 .get_link = usbnet_get_link, 581 .get_link = usbnet_get_link,
632 .nway_reset = usbnet_nway_reset, 582 .nway_reset = usbnet_nway_reset,
@@ -638,12 +588,6 @@ static const struct ethtool_ops smsc75xx_ethtool_ops = {
638 .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len, 588 .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len,
639 .get_eeprom = smsc75xx_ethtool_get_eeprom, 589 .get_eeprom = smsc75xx_ethtool_get_eeprom,
640 .set_eeprom = smsc75xx_ethtool_set_eeprom, 590 .set_eeprom = smsc75xx_ethtool_set_eeprom,
641 .get_tx_csum = ethtool_op_get_tx_csum,
642 .set_tx_csum = ethtool_op_set_tx_hw_csum,
643 .get_rx_csum = smsc75xx_ethtool_get_rx_csum,
644 .set_rx_csum = smsc75xx_ethtool_set_rx_csum,
645 .get_tso = ethtool_op_get_tso,
646 .set_tso = smsc75xx_ethtool_set_tso,
647}; 591};
648 592
649static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 593static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
@@ -782,6 +726,30 @@ static int smsc75xx_change_mtu(struct net_device *netdev, int new_mtu)
782 return usbnet_change_mtu(netdev, new_mtu); 726 return usbnet_change_mtu(netdev, new_mtu);
783} 727}
784 728
729/* Enable or disable Rx checksum offload engine */
730static int smsc75xx_set_features(struct net_device *netdev, u32 features)
731{
732 struct usbnet *dev = netdev_priv(netdev);
733 struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
734 unsigned long flags;
735 int ret;
736
737 spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
738
739 if (features & NETIF_F_RXCSUM)
740 pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM;
741 else
742 pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM);
743
744 spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
745 /* it's racing here! */
746
747 ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
748 check_warn_return(ret, "Error writing RFE_CTL");
749
750 return 0;
751}
752
785static int smsc75xx_reset(struct usbnet *dev) 753static int smsc75xx_reset(struct usbnet *dev)
786{ 754{
787 struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); 755 struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
@@ -960,11 +928,7 @@ static int smsc75xx_reset(struct usbnet *dev)
960 netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x", pdata->rfe_ctl); 928 netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x", pdata->rfe_ctl);
961 929
962 /* Enable or disable checksum offload engines */ 930 /* Enable or disable checksum offload engines */
963 ethtool_op_set_tx_hw_csum(dev->net, DEFAULT_TX_CSUM_ENABLE); 931 smsc75xx_set_features(dev->net, dev->net->features);
964 ret = smsc75xx_set_rx_csum_offload(dev);
965 check_warn_return(ret, "Failed to set rx csum offload: %d", ret);
966
967 smsc75xx_ethtool_set_tso(dev->net, DEFAULT_TSO_ENABLE);
968 932
969 smsc75xx_set_multicast(dev->net); 933 smsc75xx_set_multicast(dev->net);
970 934
@@ -1037,6 +1001,7 @@ static const struct net_device_ops smsc75xx_netdev_ops = {
1037 .ndo_validate_addr = eth_validate_addr, 1001 .ndo_validate_addr = eth_validate_addr,
1038 .ndo_do_ioctl = smsc75xx_ioctl, 1002 .ndo_do_ioctl = smsc75xx_ioctl,
1039 .ndo_set_multicast_list = smsc75xx_set_multicast, 1003 .ndo_set_multicast_list = smsc75xx_set_multicast,
1004 .ndo_set_features = smsc75xx_set_features,
1040}; 1005};
1041 1006
1042static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) 1007static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
@@ -1065,10 +1030,17 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
1065 1030
1066 INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write); 1031 INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write);
1067 1032
1068 pdata->use_rx_csum = DEFAULT_RX_CSUM_ENABLE; 1033 if (DEFAULT_TX_CSUM_ENABLE) {
1034 dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1035 if (DEFAULT_TSO_ENABLE)
1036 dev->net->features |= NETIF_F_SG |
1037 NETIF_F_TSO | NETIF_F_TSO6;
1038 }
1039 if (DEFAULT_RX_CSUM_ENABLE)
1040 dev->net->features |= NETIF_F_RXCSUM;
1069 1041
1070 /* We have to advertise SG otherwise TSO cannot be enabled */ 1042 dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1071 dev->net->features |= NETIF_F_SG; 1043 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_RXCSUM;
1072 1044
1073 /* Init all registers */ 1045 /* Init all registers */
1074 ret = smsc75xx_reset(dev); 1046 ret = smsc75xx_reset(dev);
@@ -1091,10 +1063,11 @@ static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf)
1091 } 1063 }
1092} 1064}
1093 1065
1094static void smsc75xx_rx_csum_offload(struct sk_buff *skb, u32 rx_cmd_a, 1066static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb,
1095 u32 rx_cmd_b) 1067 u32 rx_cmd_a, u32 rx_cmd_b)
1096{ 1068{
1097 if (unlikely(rx_cmd_a & RX_CMD_A_LCSM)) { 1069 if (!(dev->net->features & NETIF_F_RXCSUM) ||
1070 unlikely(rx_cmd_a & RX_CMD_A_LCSM)) {
1098 skb->ip_summed = CHECKSUM_NONE; 1071 skb->ip_summed = CHECKSUM_NONE;
1099 } else { 1072 } else {
1100 skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT)); 1073 skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT));
@@ -1104,8 +1077,6 @@ static void smsc75xx_rx_csum_offload(struct sk_buff *skb, u32 rx_cmd_a,
1104 1077
1105static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 1078static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1106{ 1079{
1107 struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
1108
1109 while (skb->len > 0) { 1080 while (skb->len > 0) {
1110 u32 rx_cmd_a, rx_cmd_b, align_count, size; 1081 u32 rx_cmd_a, rx_cmd_b, align_count, size;
1111 struct sk_buff *ax_skb; 1082 struct sk_buff *ax_skb;
@@ -1145,11 +1116,8 @@ static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1145 1116
1146 /* last frame in this batch */ 1117 /* last frame in this batch */
1147 if (skb->len == size) { 1118 if (skb->len == size) {
1148 if (pdata->use_rx_csum) 1119 smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a,
1149 smsc75xx_rx_csum_offload(skb, rx_cmd_a, 1120 rx_cmd_b);
1150 rx_cmd_b);
1151 else
1152 skb->ip_summed = CHECKSUM_NONE;
1153 1121
1154 skb_trim(skb, skb->len - 4); /* remove fcs */ 1122 skb_trim(skb, skb->len - 4); /* remove fcs */
1155 skb->truesize = size + sizeof(struct sk_buff); 1123 skb->truesize = size + sizeof(struct sk_buff);
@@ -1167,11 +1135,8 @@ static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1167 ax_skb->data = packet; 1135 ax_skb->data = packet;
1168 skb_set_tail_pointer(ax_skb, size); 1136 skb_set_tail_pointer(ax_skb, size);
1169 1137
1170 if (pdata->use_rx_csum) 1138 smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a,
1171 smsc75xx_rx_csum_offload(ax_skb, rx_cmd_a, 1139 rx_cmd_b);
1172 rx_cmd_b);
1173 else
1174 ax_skb->ip_summed = CHECKSUM_NONE;
1175 1140
1176 skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ 1141 skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
1177 ax_skb->truesize = size + sizeof(struct sk_buff); 1142 ax_skb->truesize = size + sizeof(struct sk_buff);