diff options
Diffstat (limited to 'drivers/net/usb/smsc95xx.c')
-rw-r--r-- | drivers/net/usb/smsc95xx.c | 83 |
1 files changed, 19 insertions, 64 deletions
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 727874d9deb6..708f2083898b 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c | |||
@@ -52,8 +52,6 @@ struct smsc95xx_priv { | |||
52 | u32 hash_hi; | 52 | u32 hash_hi; |
53 | u32 hash_lo; | 53 | u32 hash_lo; |
54 | spinlock_t mac_cr_lock; | 54 | spinlock_t mac_cr_lock; |
55 | bool use_tx_csum; | ||
56 | bool use_rx_csum; | ||
57 | }; | 55 | }; |
58 | 56 | ||
59 | struct usb_context { | 57 | struct usb_context { |
@@ -517,22 +515,24 @@ static void smsc95xx_status(struct usbnet *dev, struct urb *urb) | |||
517 | } | 515 | } |
518 | 516 | ||
519 | /* Enable or disable Tx & Rx checksum offload engines */ | 517 | /* Enable or disable Tx & Rx checksum offload engines */ |
520 | static int smsc95xx_set_csums(struct usbnet *dev) | 518 | static int smsc95xx_set_features(struct net_device *netdev, u32 features) |
521 | { | 519 | { |
522 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | 520 | struct usbnet *dev = netdev_priv(netdev); |
523 | u32 read_buf; | 521 | u32 read_buf; |
524 | int ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); | 522 | int ret; |
523 | |||
524 | ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); | ||
525 | if (ret < 0) { | 525 | if (ret < 0) { |
526 | netdev_warn(dev->net, "Failed to read COE_CR: %d\n", ret); | 526 | netdev_warn(dev->net, "Failed to read COE_CR: %d\n", ret); |
527 | return ret; | 527 | return ret; |
528 | } | 528 | } |
529 | 529 | ||
530 | if (pdata->use_tx_csum) | 530 | if (features & NETIF_F_HW_CSUM) |
531 | read_buf |= Tx_COE_EN_; | 531 | read_buf |= Tx_COE_EN_; |
532 | else | 532 | else |
533 | read_buf &= ~Tx_COE_EN_; | 533 | read_buf &= ~Tx_COE_EN_; |
534 | 534 | ||
535 | if (pdata->use_rx_csum) | 535 | if (features & NETIF_F_RXCSUM) |
536 | read_buf |= Rx_COE_EN_; | 536 | read_buf |= Rx_COE_EN_; |
537 | else | 537 | else |
538 | read_buf &= ~Rx_COE_EN_; | 538 | read_buf &= ~Rx_COE_EN_; |
@@ -576,43 +576,6 @@ static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, | |||
576 | return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); | 576 | return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); |
577 | } | 577 | } |
578 | 578 | ||
579 | static u32 smsc95xx_ethtool_get_rx_csum(struct net_device *netdev) | ||
580 | { | ||
581 | struct usbnet *dev = netdev_priv(netdev); | ||
582 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | ||
583 | |||
584 | return pdata->use_rx_csum; | ||
585 | } | ||
586 | |||
587 | static int smsc95xx_ethtool_set_rx_csum(struct net_device *netdev, u32 val) | ||
588 | { | ||
589 | struct usbnet *dev = netdev_priv(netdev); | ||
590 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | ||
591 | |||
592 | pdata->use_rx_csum = !!val; | ||
593 | |||
594 | return smsc95xx_set_csums(dev); | ||
595 | } | ||
596 | |||
597 | static u32 smsc95xx_ethtool_get_tx_csum(struct net_device *netdev) | ||
598 | { | ||
599 | struct usbnet *dev = netdev_priv(netdev); | ||
600 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | ||
601 | |||
602 | return pdata->use_tx_csum; | ||
603 | } | ||
604 | |||
605 | static int smsc95xx_ethtool_set_tx_csum(struct net_device *netdev, u32 val) | ||
606 | { | ||
607 | struct usbnet *dev = netdev_priv(netdev); | ||
608 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | ||
609 | |||
610 | pdata->use_tx_csum = !!val; | ||
611 | |||
612 | ethtool_op_set_tx_hw_csum(netdev, pdata->use_tx_csum); | ||
613 | return smsc95xx_set_csums(dev); | ||
614 | } | ||
615 | |||
616 | static const struct ethtool_ops smsc95xx_ethtool_ops = { | 579 | static const struct ethtool_ops smsc95xx_ethtool_ops = { |
617 | .get_link = usbnet_get_link, | 580 | .get_link = usbnet_get_link, |
618 | .nway_reset = usbnet_nway_reset, | 581 | .nway_reset = usbnet_nway_reset, |
@@ -624,10 +587,6 @@ static const struct ethtool_ops smsc95xx_ethtool_ops = { | |||
624 | .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, | 587 | .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, |
625 | .get_eeprom = smsc95xx_ethtool_get_eeprom, | 588 | .get_eeprom = smsc95xx_ethtool_get_eeprom, |
626 | .set_eeprom = smsc95xx_ethtool_set_eeprom, | 589 | .set_eeprom = smsc95xx_ethtool_set_eeprom, |
627 | .get_tx_csum = smsc95xx_ethtool_get_tx_csum, | ||
628 | .set_tx_csum = smsc95xx_ethtool_set_tx_csum, | ||
629 | .get_rx_csum = smsc95xx_ethtool_get_rx_csum, | ||
630 | .set_rx_csum = smsc95xx_ethtool_set_rx_csum, | ||
631 | }; | 590 | }; |
632 | 591 | ||
633 | static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) | 592 | static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) |
@@ -755,7 +714,6 @@ static int smsc95xx_phy_initialize(struct usbnet *dev) | |||
755 | static int smsc95xx_reset(struct usbnet *dev) | 714 | static int smsc95xx_reset(struct usbnet *dev) |
756 | { | 715 | { |
757 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | 716 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
758 | struct net_device *netdev = dev->net; | ||
759 | u32 read_buf, write_buf, burst_cap; | 717 | u32 read_buf, write_buf, burst_cap; |
760 | int ret = 0, timeout; | 718 | int ret = 0, timeout; |
761 | 719 | ||
@@ -975,12 +933,7 @@ static int smsc95xx_reset(struct usbnet *dev) | |||
975 | } | 933 | } |
976 | 934 | ||
977 | /* Enable or disable checksum offload engines */ | 935 | /* Enable or disable checksum offload engines */ |
978 | ethtool_op_set_tx_hw_csum(netdev, pdata->use_tx_csum); | 936 | smsc95xx_set_features(dev->net, dev->net->features); |
979 | ret = smsc95xx_set_csums(dev); | ||
980 | if (ret < 0) { | ||
981 | netdev_warn(dev->net, "Failed to set csum offload: %d\n", ret); | ||
982 | return ret; | ||
983 | } | ||
984 | 937 | ||
985 | smsc95xx_set_multicast(dev->net); | 938 | smsc95xx_set_multicast(dev->net); |
986 | 939 | ||
@@ -1019,6 +972,7 @@ static const struct net_device_ops smsc95xx_netdev_ops = { | |||
1019 | .ndo_validate_addr = eth_validate_addr, | 972 | .ndo_validate_addr = eth_validate_addr, |
1020 | .ndo_do_ioctl = smsc95xx_ioctl, | 973 | .ndo_do_ioctl = smsc95xx_ioctl, |
1021 | .ndo_set_multicast_list = smsc95xx_set_multicast, | 974 | .ndo_set_multicast_list = smsc95xx_set_multicast, |
975 | .ndo_set_features = smsc95xx_set_features, | ||
1022 | }; | 976 | }; |
1023 | 977 | ||
1024 | static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) | 978 | static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) |
@@ -1045,8 +999,12 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) | |||
1045 | 999 | ||
1046 | spin_lock_init(&pdata->mac_cr_lock); | 1000 | spin_lock_init(&pdata->mac_cr_lock); |
1047 | 1001 | ||
1048 | pdata->use_tx_csum = DEFAULT_TX_CSUM_ENABLE; | 1002 | if (DEFAULT_TX_CSUM_ENABLE) |
1049 | pdata->use_rx_csum = DEFAULT_RX_CSUM_ENABLE; | 1003 | dev->net->features |= NETIF_F_HW_CSUM; |
1004 | if (DEFAULT_RX_CSUM_ENABLE) | ||
1005 | dev->net->features |= NETIF_F_RXCSUM; | ||
1006 | |||
1007 | dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM; | ||
1050 | 1008 | ||
1051 | smsc95xx_init_mac_address(dev); | 1009 | smsc95xx_init_mac_address(dev); |
1052 | 1010 | ||
@@ -1056,7 +1014,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) | |||
1056 | dev->net->netdev_ops = &smsc95xx_netdev_ops; | 1014 | dev->net->netdev_ops = &smsc95xx_netdev_ops; |
1057 | dev->net->ethtool_ops = &smsc95xx_ethtool_ops; | 1015 | dev->net->ethtool_ops = &smsc95xx_ethtool_ops; |
1058 | dev->net->flags |= IFF_MULTICAST; | 1016 | dev->net->flags |= IFF_MULTICAST; |
1059 | dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD; | 1017 | dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; |
1060 | return 0; | 1018 | return 0; |
1061 | } | 1019 | } |
1062 | 1020 | ||
@@ -1080,8 +1038,6 @@ static void smsc95xx_rx_csum_offload(struct sk_buff *skb) | |||
1080 | 1038 | ||
1081 | static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | 1039 | static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) |
1082 | { | 1040 | { |
1083 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | ||
1084 | |||
1085 | while (skb->len > 0) { | 1041 | while (skb->len > 0) { |
1086 | u32 header, align_count; | 1042 | u32 header, align_count; |
1087 | struct sk_buff *ax_skb; | 1043 | struct sk_buff *ax_skb; |
@@ -1123,7 +1079,7 @@ static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | |||
1123 | 1079 | ||
1124 | /* last frame in this batch */ | 1080 | /* last frame in this batch */ |
1125 | if (skb->len == size) { | 1081 | if (skb->len == size) { |
1126 | if (pdata->use_rx_csum) | 1082 | if (dev->net->features & NETIF_F_RXCSUM) |
1127 | smsc95xx_rx_csum_offload(skb); | 1083 | smsc95xx_rx_csum_offload(skb); |
1128 | skb_trim(skb, skb->len - 4); /* remove fcs */ | 1084 | skb_trim(skb, skb->len - 4); /* remove fcs */ |
1129 | skb->truesize = size + sizeof(struct sk_buff); | 1085 | skb->truesize = size + sizeof(struct sk_buff); |
@@ -1141,7 +1097,7 @@ static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | |||
1141 | ax_skb->data = packet; | 1097 | ax_skb->data = packet; |
1142 | skb_set_tail_pointer(ax_skb, size); | 1098 | skb_set_tail_pointer(ax_skb, size); |
1143 | 1099 | ||
1144 | if (pdata->use_rx_csum) | 1100 | if (dev->net->features & NETIF_F_RXCSUM) |
1145 | smsc95xx_rx_csum_offload(ax_skb); | 1101 | smsc95xx_rx_csum_offload(ax_skb); |
1146 | skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ | 1102 | skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ |
1147 | ax_skb->truesize = size + sizeof(struct sk_buff); | 1103 | ax_skb->truesize = size + sizeof(struct sk_buff); |
@@ -1174,8 +1130,7 @@ static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) | |||
1174 | static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, | 1130 | static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, |
1175 | struct sk_buff *skb, gfp_t flags) | 1131 | struct sk_buff *skb, gfp_t flags) |
1176 | { | 1132 | { |
1177 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | 1133 | bool csum = skb->ip_summed == CHECKSUM_PARTIAL; |
1178 | bool csum = pdata->use_tx_csum && (skb->ip_summed == CHECKSUM_PARTIAL); | ||
1179 | int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; | 1134 | int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; |
1180 | u32 tx_cmd_a, tx_cmd_b; | 1135 | u32 tx_cmd_a, tx_cmd_b; |
1181 | 1136 | ||