net/mlx4_en: Implement ndo_get_phys_port_id
[deliverable/linux.git] / drivers / net / ethernet / mellanox / mlx4 / en_netdev.c
index e72d8a112a6bdc03e3d1f33763e8134b19f92d99..d2e9666f2fb82b16f7c5c651eb1856c9ea36da92 100644 (file)
@@ -2025,7 +2025,7 @@ static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
        return 0;
 }
 
-static int mlx4_en_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
+static int mlx4_en_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 {
        struct mlx4_en_priv *priv = netdev_priv(dev);
        struct mlx4_en_dev *mdev = priv->mdev;
@@ -2084,11 +2084,21 @@ static int mlx4_en_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
                            sizeof(config)) ? -EFAULT : 0;
 }
 
+static int mlx4_en_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
+{
+       struct mlx4_en_priv *priv = netdev_priv(dev);
+
+       return copy_to_user(ifr->ifr_data, &priv->hwtstamp_config,
+                           sizeof(priv->hwtstamp_config)) ? -EFAULT : 0;
+}
+
 static int mlx4_en_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
        switch (cmd) {
        case SIOCSHWTSTAMP:
-               return mlx4_en_hwtstamp_ioctl(dev, ifr);
+               return mlx4_en_hwtstamp_set(dev, ifr);
+       case SIOCGHWTSTAMP:
+               return mlx4_en_hwtstamp_get(dev, ifr);
        default:
                return -EOPNOTSUPP;
        }
@@ -2154,6 +2164,27 @@ static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_st
 
        return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
 }
+
+#define PORT_ID_BYTE_LEN 8
+static int mlx4_en_get_phys_port_id(struct net_device *dev,
+                                   struct netdev_phys_port_id *ppid)
+{
+       struct mlx4_en_priv *priv = netdev_priv(dev);
+       struct mlx4_dev *mdev = priv->mdev->dev;
+       int i;
+       u64 phys_port_id = mdev->caps.phys_port_id[priv->port];
+
+       if (!phys_port_id)
+               return -EOPNOTSUPP;
+
+       ppid->id_len = sizeof(phys_port_id);
+       for (i = PORT_ID_BYTE_LEN - 1; i >= 0; --i) {
+               ppid->id[i] =  phys_port_id & 0xff;
+               phys_port_id >>= 8;
+       }
+       return 0;
+}
+
 static const struct net_device_ops mlx4_netdev_ops = {
        .ndo_open               = mlx4_en_open,
        .ndo_stop               = mlx4_en_close,
@@ -2179,6 +2210,7 @@ static const struct net_device_ops mlx4_netdev_ops = {
 #ifdef CONFIG_NET_RX_BUSY_POLL
        .ndo_busy_poll          = mlx4_en_low_latency_recv,
 #endif
+       .ndo_get_phys_port_id   = mlx4_en_get_phys_port_id,
 };
 
 static const struct net_device_ops mlx4_netdev_ops_master = {
@@ -2207,6 +2239,7 @@ static const struct net_device_ops mlx4_netdev_ops_master = {
 #ifdef CONFIG_RFS_ACCEL
        .ndo_rx_flow_steer      = mlx4_en_filter_rfs,
 #endif
+       .ndo_get_phys_port_id   = mlx4_en_get_phys_port_id,
 };
 
 int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
This page took 0.061187 seconds and 5 git commands to generate.