|
@@ -69,6 +69,186 @@ MODULE_PARM_DESC(rx_weight, "Number Rx packets for NAPI budget (default=64)");
|
|
|
|
|
|
static int change_mac_addr(struct net_device *netdev, const u8 *addr);
|
|
static int change_mac_addr(struct net_device *netdev, const u8 *addr);
|
|
|
|
|
|
|
|
+static void set_link_speed(struct ethtool_link_ksettings *link_ksettings,
|
|
|
|
+ enum hinic_speed speed)
|
|
|
|
+{
|
|
|
|
+ switch (speed) {
|
|
|
|
+ case HINIC_SPEED_10MB_LINK:
|
|
|
|
+ link_ksettings->base.speed = SPEED_10;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case HINIC_SPEED_100MB_LINK:
|
|
|
|
+ link_ksettings->base.speed = SPEED_100;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case HINIC_SPEED_1000MB_LINK:
|
|
|
|
+ link_ksettings->base.speed = SPEED_1000;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case HINIC_SPEED_10GB_LINK:
|
|
|
|
+ link_ksettings->base.speed = SPEED_10000;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case HINIC_SPEED_25GB_LINK:
|
|
|
|
+ link_ksettings->base.speed = SPEED_25000;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case HINIC_SPEED_40GB_LINK:
|
|
|
|
+ link_ksettings->base.speed = SPEED_40000;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case HINIC_SPEED_100GB_LINK:
|
|
|
|
+ link_ksettings->base.speed = SPEED_100000;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ link_ksettings->base.speed = SPEED_UNKNOWN;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int hinic_get_link_ksettings(struct net_device *netdev,
|
|
|
|
+ struct ethtool_link_ksettings
|
|
|
|
+ *link_ksettings)
|
|
|
|
+{
|
|
|
|
+ struct hinic_dev *nic_dev = netdev_priv(netdev);
|
|
|
|
+ enum hinic_port_link_state link_state;
|
|
|
|
+ struct hinic_port_cap port_cap;
|
|
|
|
+ int err;
|
|
|
|
+
|
|
|
|
+ ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
|
|
|
|
+ ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
|
|
|
|
+ Autoneg);
|
|
|
|
+
|
|
|
|
+ link_ksettings->base.speed = SPEED_UNKNOWN;
|
|
|
|
+ link_ksettings->base.autoneg = AUTONEG_DISABLE;
|
|
|
|
+ link_ksettings->base.duplex = DUPLEX_UNKNOWN;
|
|
|
|
+
|
|
|
|
+ err = hinic_port_get_cap(nic_dev, &port_cap);
|
|
|
|
+ if (err) {
|
|
|
|
+ netif_err(nic_dev, drv, netdev,
|
|
|
|
+ "Failed to get port capabilities\n");
|
|
|
|
+ return err;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = hinic_port_link_state(nic_dev, &link_state);
|
|
|
|
+ if (err) {
|
|
|
|
+ netif_err(nic_dev, drv, netdev,
|
|
|
|
+ "Failed to get port link state\n");
|
|
|
|
+ return err;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (link_state != HINIC_LINK_STATE_UP) {
|
|
|
|
+ netif_info(nic_dev, drv, netdev, "No link\n");
|
|
|
|
+ return err;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ set_link_speed(link_ksettings, port_cap.speed);
|
|
|
|
+
|
|
|
|
+ if (!!(port_cap.autoneg_cap & HINIC_AUTONEG_SUPPORTED))
|
|
|
|
+ ethtool_link_ksettings_add_link_mode(link_ksettings,
|
|
|
|
+ advertising, Autoneg);
|
|
|
|
+
|
|
|
|
+ if (port_cap.autoneg_state == HINIC_AUTONEG_ACTIVE)
|
|
|
|
+ link_ksettings->base.autoneg = AUTONEG_ENABLE;
|
|
|
|
+
|
|
|
|
+ link_ksettings->base.duplex = (port_cap.duplex == HINIC_DUPLEX_FULL) ?
|
|
|
|
+ DUPLEX_FULL : DUPLEX_HALF;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void hinic_get_drvinfo(struct net_device *netdev,
|
|
|
|
+ struct ethtool_drvinfo *info)
|
|
|
|
+{
|
|
|
|
+ struct hinic_dev *nic_dev = netdev_priv(netdev);
|
|
|
|
+ struct hinic_hwdev *hwdev = nic_dev->hwdev;
|
|
|
|
+ struct hinic_hwif *hwif = hwdev->hwif;
|
|
|
|
+
|
|
|
|
+ strlcpy(info->driver, HINIC_DRV_NAME, sizeof(info->driver));
|
|
|
|
+ strlcpy(info->bus_info, pci_name(hwif->pdev), sizeof(info->bus_info));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void hinic_get_ringparam(struct net_device *netdev,
|
|
|
|
+ struct ethtool_ringparam *ring)
|
|
|
|
+{
|
|
|
|
+ ring->rx_max_pending = HINIC_RQ_DEPTH;
|
|
|
|
+ ring->tx_max_pending = HINIC_SQ_DEPTH;
|
|
|
|
+ ring->rx_pending = HINIC_RQ_DEPTH;
|
|
|
|
+ ring->tx_pending = HINIC_SQ_DEPTH;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void hinic_get_channels(struct net_device *netdev,
|
|
|
|
+ struct ethtool_channels *channels)
|
|
|
|
+{
|
|
|
|
+ struct hinic_dev *nic_dev = netdev_priv(netdev);
|
|
|
|
+ struct hinic_hwdev *hwdev = nic_dev->hwdev;
|
|
|
|
+
|
|
|
|
+ channels->max_rx = hwdev->nic_cap.max_qps;
|
|
|
|
+ channels->max_tx = hwdev->nic_cap.max_qps;
|
|
|
|
+ channels->max_other = 0;
|
|
|
|
+ channels->max_combined = 0;
|
|
|
|
+ channels->rx_count = hinic_hwdev_num_qps(hwdev);
|
|
|
|
+ channels->tx_count = hinic_hwdev_num_qps(hwdev);
|
|
|
|
+ channels->other_count = 0;
|
|
|
|
+ channels->combined_count = 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static const struct ethtool_ops hinic_ethtool_ops = {
|
|
|
|
+ .get_link_ksettings = hinic_get_link_ksettings,
|
|
|
|
+ .get_drvinfo = hinic_get_drvinfo,
|
|
|
|
+ .get_link = ethtool_op_get_link,
|
|
|
|
+ .get_ringparam = hinic_get_ringparam,
|
|
|
|
+ .get_channels = hinic_get_channels,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static void update_rx_stats(struct hinic_dev *nic_dev, struct hinic_rxq *rxq)
|
|
|
|
+{
|
|
|
|
+ struct hinic_rxq_stats *nic_rx_stats = &nic_dev->rx_stats;
|
|
|
|
+ struct hinic_rxq_stats rx_stats;
|
|
|
|
+
|
|
|
|
+ u64_stats_init(&rx_stats.syncp);
|
|
|
|
+
|
|
|
|
+ hinic_rxq_get_stats(rxq, &rx_stats);
|
|
|
|
+
|
|
|
|
+ u64_stats_update_begin(&nic_rx_stats->syncp);
|
|
|
|
+ nic_rx_stats->bytes += rx_stats.bytes;
|
|
|
|
+ nic_rx_stats->pkts += rx_stats.pkts;
|
|
|
|
+ u64_stats_update_end(&nic_rx_stats->syncp);
|
|
|
|
+
|
|
|
|
+ hinic_rxq_clean_stats(rxq);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void update_tx_stats(struct hinic_dev *nic_dev, struct hinic_txq *txq)
|
|
|
|
+{
|
|
|
|
+ struct hinic_txq_stats *nic_tx_stats = &nic_dev->tx_stats;
|
|
|
|
+ struct hinic_txq_stats tx_stats;
|
|
|
|
+
|
|
|
|
+ u64_stats_init(&tx_stats.syncp);
|
|
|
|
+
|
|
|
|
+ hinic_txq_get_stats(txq, &tx_stats);
|
|
|
|
+
|
|
|
|
+ u64_stats_update_begin(&nic_tx_stats->syncp);
|
|
|
|
+ nic_tx_stats->bytes += tx_stats.bytes;
|
|
|
|
+ nic_tx_stats->pkts += tx_stats.pkts;
|
|
|
|
+ nic_tx_stats->tx_busy += tx_stats.tx_busy;
|
|
|
|
+ nic_tx_stats->tx_wake += tx_stats.tx_wake;
|
|
|
|
+ nic_tx_stats->tx_dropped += tx_stats.tx_dropped;
|
|
|
|
+ u64_stats_update_end(&nic_tx_stats->syncp);
|
|
|
|
+
|
|
|
|
+ hinic_txq_clean_stats(txq);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void update_nic_stats(struct hinic_dev *nic_dev)
|
|
|
|
+{
|
|
|
|
+ int i, num_qps = hinic_hwdev_num_qps(nic_dev->hwdev);
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < num_qps; i++)
|
|
|
|
+ update_rx_stats(nic_dev, &nic_dev->rxqs[i]);
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < num_qps; i++)
|
|
|
|
+ update_tx_stats(nic_dev, &nic_dev->txqs[i]);
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* create_txqs - Create the Logical Tx Queues of specific NIC device
|
|
* create_txqs - Create the Logical Tx Queues of specific NIC device
|
|
* @nic_dev: the specific NIC device
|
|
* @nic_dev: the specific NIC device
|
|
@@ -303,6 +483,8 @@ static int hinic_close(struct net_device *netdev)
|
|
netif_carrier_off(netdev);
|
|
netif_carrier_off(netdev);
|
|
netif_tx_disable(netdev);
|
|
netif_tx_disable(netdev);
|
|
|
|
|
|
|
|
+ update_nic_stats(nic_dev);
|
|
|
|
+
|
|
up(&nic_dev->mgmt_lock);
|
|
up(&nic_dev->mgmt_lock);
|
|
|
|
|
|
err = hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE);
|
|
err = hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE);
|
|
@@ -580,6 +762,31 @@ static void hinic_tx_timeout(struct net_device *netdev)
|
|
netif_err(nic_dev, drv, netdev, "Tx timeout\n");
|
|
netif_err(nic_dev, drv, netdev, "Tx timeout\n");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void hinic_get_stats64(struct net_device *netdev,
|
|
|
|
+ struct rtnl_link_stats64 *stats)
|
|
|
|
+{
|
|
|
|
+ struct hinic_dev *nic_dev = netdev_priv(netdev);
|
|
|
|
+ struct hinic_rxq_stats *nic_rx_stats;
|
|
|
|
+ struct hinic_txq_stats *nic_tx_stats;
|
|
|
|
+
|
|
|
|
+ nic_rx_stats = &nic_dev->rx_stats;
|
|
|
|
+ nic_tx_stats = &nic_dev->tx_stats;
|
|
|
|
+
|
|
|
|
+ down(&nic_dev->mgmt_lock);
|
|
|
|
+
|
|
|
|
+ if (nic_dev->flags & HINIC_INTF_UP)
|
|
|
|
+ update_nic_stats(nic_dev);
|
|
|
|
+
|
|
|
|
+ up(&nic_dev->mgmt_lock);
|
|
|
|
+
|
|
|
|
+ stats->rx_bytes = nic_rx_stats->bytes;
|
|
|
|
+ stats->rx_packets = nic_rx_stats->pkts;
|
|
|
|
+
|
|
|
|
+ stats->tx_bytes = nic_tx_stats->bytes;
|
|
|
|
+ stats->tx_packets = nic_tx_stats->pkts;
|
|
|
|
+ stats->tx_errors = nic_tx_stats->tx_dropped;
|
|
|
|
+}
|
|
|
|
+
|
|
static const struct net_device_ops hinic_netdev_ops = {
|
|
static const struct net_device_ops hinic_netdev_ops = {
|
|
.ndo_open = hinic_open,
|
|
.ndo_open = hinic_open,
|
|
.ndo_stop = hinic_close,
|
|
.ndo_stop = hinic_close,
|
|
@@ -591,7 +798,7 @@ static const struct net_device_ops hinic_netdev_ops = {
|
|
.ndo_set_rx_mode = hinic_set_rx_mode,
|
|
.ndo_set_rx_mode = hinic_set_rx_mode,
|
|
.ndo_start_xmit = hinic_xmit_frame,
|
|
.ndo_start_xmit = hinic_xmit_frame,
|
|
.ndo_tx_timeout = hinic_tx_timeout,
|
|
.ndo_tx_timeout = hinic_tx_timeout,
|
|
- /* more operations should be filled */
|
|
|
|
|
|
+ .ndo_get_stats64 = hinic_get_stats64,
|
|
};
|
|
};
|
|
|
|
|
|
static void netdev_features_init(struct net_device *netdev)
|
|
static void netdev_features_init(struct net_device *netdev)
|
|
@@ -663,6 +870,8 @@ static void link_status_event_handler(void *handle, void *buf_in, u16 in_size,
|
|
static int nic_dev_init(struct pci_dev *pdev)
|
|
static int nic_dev_init(struct pci_dev *pdev)
|
|
{
|
|
{
|
|
struct hinic_rx_mode_work *rx_mode_work;
|
|
struct hinic_rx_mode_work *rx_mode_work;
|
|
|
|
+ struct hinic_txq_stats *tx_stats;
|
|
|
|
+ struct hinic_rxq_stats *rx_stats;
|
|
struct hinic_dev *nic_dev;
|
|
struct hinic_dev *nic_dev;
|
|
struct net_device *netdev;
|
|
struct net_device *netdev;
|
|
struct hinic_hwdev *hwdev;
|
|
struct hinic_hwdev *hwdev;
|
|
@@ -689,6 +898,7 @@ static int nic_dev_init(struct pci_dev *pdev)
|
|
}
|
|
}
|
|
|
|
|
|
netdev->netdev_ops = &hinic_netdev_ops;
|
|
netdev->netdev_ops = &hinic_netdev_ops;
|
|
|
|
+ netdev->ethtool_ops = &hinic_ethtool_ops;
|
|
|
|
|
|
nic_dev = netdev_priv(netdev);
|
|
nic_dev = netdev_priv(netdev);
|
|
nic_dev->netdev = netdev;
|
|
nic_dev->netdev = netdev;
|
|
@@ -702,6 +912,12 @@ static int nic_dev_init(struct pci_dev *pdev)
|
|
|
|
|
|
sema_init(&nic_dev->mgmt_lock, 1);
|
|
sema_init(&nic_dev->mgmt_lock, 1);
|
|
|
|
|
|
|
|
+ tx_stats = &nic_dev->tx_stats;
|
|
|
|
+ rx_stats = &nic_dev->rx_stats;
|
|
|
|
+
|
|
|
|
+ u64_stats_init(&tx_stats->syncp);
|
|
|
|
+ u64_stats_init(&rx_stats->syncp);
|
|
|
|
+
|
|
nic_dev->vlan_bitmap = devm_kzalloc(&pdev->dev,
|
|
nic_dev->vlan_bitmap = devm_kzalloc(&pdev->dev,
|
|
VLAN_BITMAP_SIZE(nic_dev),
|
|
VLAN_BITMAP_SIZE(nic_dev),
|
|
GFP_KERNEL);
|
|
GFP_KERNEL);
|