net: qlcnic: convert to hw_features
authorMichał Mirosław <mirq-linux@rere.qmqm.pl>
Tue, 19 Apr 2011 03:03:57 +0000 (03:03 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 20 Apr 2011 08:30:44 +0000 (01:30 -0700)
Bit more than minimal conversion. There might be some issues because
of qlcnic_set_netdev_features() if it's called after netdev init.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/qlcnic/qlcnic.h
drivers/net/qlcnic/qlcnic_ethtool.c
drivers/net/qlcnic/qlcnic_hw.c
drivers/net/qlcnic/qlcnic_init.c
drivers/net/qlcnic/qlcnic_main.c

index e5d30538f3730d2100abd777ad8bb279a6b657ce..fa5b15c474b050d61266201c64efa062da1367a0 100644 (file)
@@ -926,7 +926,6 @@ struct qlcnic_adapter {
        u8 max_rds_rings;
        u8 max_sds_rings;
        u8 msix_supported;
-       u8 rx_csum;
        u8 portnum;
        u8 physical_port;
        u8 reset_context;
@@ -1247,6 +1246,8 @@ void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup);
 
 int qlcnic_fw_cmd_set_mtu(struct qlcnic_adapter *adapter, int mtu);
 int qlcnic_change_mtu(struct net_device *netdev, int new_mtu);
+u32 qlcnic_fix_features(struct net_device *netdev, u32 features);
+int qlcnic_set_features(struct net_device *netdev, u32 features);
 int qlcnic_config_hw_lro(struct qlcnic_adapter *adapter, int enable);
 int qlcnic_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable);
 int qlcnic_send_lro_cleanup(struct qlcnic_adapter *adapter);
index 3cd8a169694acf88ccfcb8aada87726be0575301..615a5ab88456d6ddb465fb65f0f7722fbdea5104 100644 (file)
@@ -764,73 +764,6 @@ qlcnic_get_ethtool_stats(struct net_device *dev,
        qlcnic_fill_device_stats(&index, data, &port_stats.tx);
 }
 
-static int qlcnic_set_tx_csum(struct net_device *dev, u32 data)
-{
-       struct qlcnic_adapter *adapter = netdev_priv(dev);
-
-       if ((adapter->flags & QLCNIC_ESWITCH_ENABLED))
-               return -EOPNOTSUPP;
-       if (data)
-               dev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
-       else
-               dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
-
-       return 0;
-
-}
-static u32 qlcnic_get_tx_csum(struct net_device *dev)
-{
-       return dev->features & NETIF_F_IP_CSUM;
-}
-
-static u32 qlcnic_get_rx_csum(struct net_device *dev)
-{
-       struct qlcnic_adapter *adapter = netdev_priv(dev);
-       return adapter->rx_csum;
-}
-
-static int qlcnic_set_rx_csum(struct net_device *dev, u32 data)
-{
-       struct qlcnic_adapter *adapter = netdev_priv(dev);
-
-       if ((adapter->flags & QLCNIC_ESWITCH_ENABLED))
-               return -EOPNOTSUPP;
-       if (!!data) {
-               adapter->rx_csum = !!data;
-               return 0;
-       }
-
-       if (dev->features & NETIF_F_LRO) {
-               if (qlcnic_config_hw_lro(adapter, QLCNIC_LRO_DISABLED))
-                       return -EIO;
-
-               dev->features &= ~NETIF_F_LRO;
-               qlcnic_send_lro_cleanup(adapter);
-               dev_info(&adapter->pdev->dev,
-                                       "disabling LRO as rx_csum is off\n");
-       }
-       adapter->rx_csum = !!data;
-       return 0;
-}
-
-static u32 qlcnic_get_tso(struct net_device *dev)
-{
-       return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
-}
-
-static int qlcnic_set_tso(struct net_device *dev, u32 data)
-{
-       struct qlcnic_adapter *adapter = netdev_priv(dev);
-       if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO))
-               return -EOPNOTSUPP;
-       if (data)
-               dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
-       else
-               dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
-
-       return 0;
-}
-
 static int qlcnic_set_led(struct net_device *dev,
                          enum ethtool_phys_id_state state)
 {
@@ -993,50 +926,6 @@ static int qlcnic_get_intr_coalesce(struct net_device *netdev,
        return 0;
 }
 
-static int qlcnic_set_flags(struct net_device *netdev, u32 data)
-{
-       struct qlcnic_adapter *adapter = netdev_priv(netdev);
-       int hw_lro;
-
-       if (ethtool_invalid_flags(netdev, data, ETH_FLAG_LRO))
-               return -EINVAL;
-
-       if (data & ETH_FLAG_LRO) {
-
-               if (netdev->features & NETIF_F_LRO)
-                       return 0;
-
-               if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO))
-                       return -EINVAL;
-
-               if (!adapter->rx_csum) {
-                       dev_info(&adapter->pdev->dev, "rx csum is off, "
-                               "cannot toggle lro\n");
-                       return -EINVAL;
-               }
-
-               hw_lro = QLCNIC_LRO_ENABLED;
-               netdev->features |= NETIF_F_LRO;
-
-       } else {
-
-               if (!(netdev->features & NETIF_F_LRO))
-                       return 0;
-
-               hw_lro = 0;
-               netdev->features &= ~NETIF_F_LRO;
-       }
-
-       if (qlcnic_config_hw_lro(adapter, hw_lro))
-               return -EIO;
-
-       if ((hw_lro == 0) && qlcnic_send_lro_cleanup(adapter))
-               return -EIO;
-
-
-       return 0;
-}
-
 static u32 qlcnic_get_msglevel(struct net_device *netdev)
 {
        struct qlcnic_adapter *adapter = netdev_priv(netdev);
@@ -1064,23 +953,14 @@ const struct ethtool_ops qlcnic_ethtool_ops = {
        .set_ringparam = qlcnic_set_ringparam,
        .get_pauseparam = qlcnic_get_pauseparam,
        .set_pauseparam = qlcnic_set_pauseparam,
-       .get_tx_csum = qlcnic_get_tx_csum,
-       .set_tx_csum = qlcnic_set_tx_csum,
-       .set_sg = ethtool_op_set_sg,
-       .get_tso = qlcnic_get_tso,
-       .set_tso = qlcnic_set_tso,
        .get_wol = qlcnic_get_wol,
        .set_wol = qlcnic_set_wol,
        .self_test = qlcnic_diag_test,
        .get_strings = qlcnic_get_strings,
        .get_ethtool_stats = qlcnic_get_ethtool_stats,
        .get_sset_count = qlcnic_get_sset_count,
-       .get_rx_csum = qlcnic_get_rx_csum,
-       .set_rx_csum = qlcnic_set_rx_csum,
        .get_coalesce = qlcnic_get_intr_coalesce,
        .set_coalesce = qlcnic_set_intr_coalesce,
-       .get_flags = ethtool_op_get_flags,
-       .set_flags = qlcnic_set_flags,
        .set_phys_id = qlcnic_set_led,
        .set_msglevel = qlcnic_set_msglevel,
        .get_msglevel = qlcnic_get_msglevel,
index 498cca92126a8b26b66774e748cb3dd1ec3ea3da..cbb27f2df0083b19b94ff956419c947c38c094e2 100644 (file)
@@ -758,6 +758,43 @@ int qlcnic_change_mtu(struct net_device *netdev, int mtu)
        return rc;
 }
 
+
+u32 qlcnic_fix_features(struct net_device *netdev, u32 features)
+{
+       struct qlcnic_adapter *adapter = netdev_priv(netdev);
+
+       if ((adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
+               u32 changed = features ^ netdev->features;
+               features ^= changed & (NETIF_F_ALL_CSUM | NETIF_F_RXCSUM);
+       }
+
+       if (!(features & NETIF_F_RXCSUM))
+               features &= ~NETIF_F_LRO;
+
+       return features;
+}
+
+
+int qlcnic_set_features(struct net_device *netdev, u32 features)
+{
+       struct qlcnic_adapter *adapter = netdev_priv(netdev);
+       u32 changed = netdev->features ^ features;
+       int hw_lro = (features & NETIF_F_LRO) ? QLCNIC_LRO_ENABLED : 0;
+
+       if (!(changed & NETIF_F_LRO))
+               return 0;
+
+       netdev->features = features ^ NETIF_F_LRO;
+
+       if (qlcnic_config_hw_lro(adapter, hw_lro))
+               return -EIO;
+
+       if ((hw_lro == 0) && qlcnic_send_lro_cleanup(adapter))
+               return -EIO;
+
+       return 0;
+}
+
 /*
  * Changes the CRB window to the specified window.
  */
index 4ec0eeb6bff9de22e4fc7ea21d7d035405b5604a..d0f338b013964ac39a38db1cf1467972af3135b8 100644 (file)
@@ -1390,8 +1390,8 @@ static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
 
        skb = buffer->skb;
 
-       if (likely(adapter->rx_csum && (cksum == STATUS_CKSUM_OK ||
-                                               cksum == STATUS_CKSUM_LOOP))) {
+       if (likely((adapter->netdev->features & NETIF_F_RXCSUM) &&
+           (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) {
                adapter->stats.csummed++;
                skb->ip_summed = CHECKSUM_UNNECESSARY;
        } else {
index e9e9ba6efc5f5e9209916643bf71ca781c1c6f7e..6e619514feeebb6d0de692dc036789701972fa8e 100644 (file)
@@ -328,6 +328,8 @@ static const struct net_device_ops qlcnic_netdev_ops = {
        .ndo_set_multicast_list = qlcnic_set_multi,
        .ndo_set_mac_address    = qlcnic_set_mac,
        .ndo_change_mtu    = qlcnic_change_mtu,
+       .ndo_fix_features  = qlcnic_fix_features,
+       .ndo_set_features  = qlcnic_set_features,
        .ndo_tx_timeout    = qlcnic_tx_timeout,
        .ndo_vlan_rx_add_vid    = qlcnic_vlan_rx_add,
        .ndo_vlan_rx_kill_vid   = qlcnic_vlan_rx_del,
@@ -764,7 +766,7 @@ qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
        struct net_device *netdev = adapter->netdev;
        unsigned long features, vlan_features;
 
-       features = (NETIF_F_SG | NETIF_F_IP_CSUM |
+       features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
                        NETIF_F_IPV6_CSUM | NETIF_F_GRO);
        vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
                        NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER);
@@ -779,14 +781,12 @@ qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
 
        if (esw_cfg->offload_flags & BIT_0) {
                netdev->features |= features;
-               adapter->rx_csum = 1;
                if (!(esw_cfg->offload_flags & BIT_1))
                        netdev->features &= ~NETIF_F_TSO;
                if (!(esw_cfg->offload_flags & BIT_2))
                        netdev->features &= ~NETIF_F_TSO6;
        } else {
                netdev->features &= ~features;
-               adapter->rx_csum = 0;
        }
 
        netdev->vlan_features = (features & vlan_features);
@@ -1436,7 +1436,6 @@ qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
        int err;
        struct pci_dev *pdev = adapter->pdev;
 
-       adapter->rx_csum = 1;
        adapter->mc_enabled = 0;
        adapter->max_mc_count = 38;
 
@@ -1447,26 +1446,24 @@ qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
 
        SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
 
-       netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
-               NETIF_F_IPV6_CSUM | NETIF_F_GRO | NETIF_F_HW_VLAN_RX);
-       netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
-               NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER);
+       netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
+               NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM;
 
-       if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
-               netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
-               netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
-       }
+       if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
+               netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
+       if (pci_using_dac)
+               netdev->hw_features |= NETIF_F_HIGHDMA;
 
-       if (pci_using_dac) {
-               netdev->features |= NETIF_F_HIGHDMA;
-               netdev->vlan_features |= NETIF_F_HIGHDMA;
-       }
+       netdev->vlan_features = netdev->hw_features;
 
        if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX)
-               netdev->features |= (NETIF_F_HW_VLAN_TX);
-
+               netdev->hw_features |= NETIF_F_HW_VLAN_TX;
        if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
-               netdev->features |= NETIF_F_LRO;
+               netdev->hw_features |= NETIF_F_LRO;
+
+       netdev->features |= netdev->hw_features |
+               NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
+
        netdev->irq = adapter->msix_entries[0].vector;
 
        netif_carrier_off(netdev);