net: hns: add media-type property for hns
authorKejian Yan <yankejian@huawei.com>
Fri, 1 Jul 2016 09:34:12 +0000 (17:34 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 Jul 2016 20:56:52 +0000 (16:56 -0400)
It is PORT_TP type if the service port is GE mode. It is wrong to
judge the port type by using if it is service port. Adding the media
type to know port type.

Reported-by: Jinchuan Tian <tianjinchuan1@huawei.com>
Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns/hnae.h
drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c

index 3869322690ac462bd14051c30995b29ab3958b2e..e093cbf26c8c50d22bf782741b382c96ca29e1d6 100644 (file)
@@ -363,6 +363,14 @@ enum hnae_port_type {
        HNAE_PORT_DEBUG
 };
 
+/* mac media type */
+enum hnae_media_type {
+       HNAE_MEDIA_TYPE_UNKNOWN = 0,
+       HNAE_MEDIA_TYPE_FIBER,
+       HNAE_MEDIA_TYPE_COPPER,
+       HNAE_MEDIA_TYPE_BACKPLANE,
+};
+
 /* This struct defines the operation on the handle.
  *
  * get_handle(): (mandatory)
@@ -525,6 +533,7 @@ struct hnae_handle {
        u32 eport_id;
        u32 dport_id;   /* v2 tx bd should fill the dport_id */
        enum hnae_port_type port_type;
+       enum hnae_media_type media_type;
        struct list_head node;    /* list to hnae_ae_dev->handle_list */
        struct hnae_buf_ops *bops; /* operation for the buffer */
        struct hnae_queue **qs;  /* array base of all queues */
index 835521bf1bbc311f2427c2ff00769d0d915bb6d6..e28d960997af3189885161bd40c355b28aee84af 100644 (file)
@@ -134,6 +134,7 @@ struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev *dev,
        ae_handle->phy_dev = vf_cb->mac_cb->phy_dev;
        ae_handle->if_support = vf_cb->mac_cb->if_support;
        ae_handle->port_type = vf_cb->mac_cb->mac_type;
+       ae_handle->media_type = vf_cb->mac_cb->media_type;
        ae_handle->dport_id = port_id;
 
        return ae_handle;
index d2effcca46c6a00b6fc07c8cb595091c5c733970..3fb87e233c496f152e8709f37a97f06e5c464d2b 100644 (file)
@@ -733,6 +733,18 @@ static void hns_mac_register_phy(struct hns_mac_cb *mac_cb)
                        mac_cb->mac_id, addr);
 }
 
+#define MAC_MEDIA_TYPE_MAX_LEN         16
+
+static const struct {
+       enum hnae_media_type value;
+       const char *name;
+} media_type_defs[] = {
+       {HNAE_MEDIA_TYPE_UNKNOWN,       "unknown" },
+       {HNAE_MEDIA_TYPE_FIBER,         "fiber" },
+       {HNAE_MEDIA_TYPE_COPPER,        "copper" },
+       {HNAE_MEDIA_TYPE_BACKPLANE,     "backplane" },
+};
+
 /**
  *hns_mac_get_info  - get mac information from device node
  *@mac_cb: mac device
@@ -744,10 +756,13 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
        struct device_node *np;
        struct regmap *syscon;
        struct of_phandle_args cpld_args;
+       const char *media_type;
+       u32 i;
        u32 ret;
 
        mac_cb->link = false;
        mac_cb->half_duplex = false;
+       mac_cb->media_type = HNAE_MEDIA_TYPE_UNKNOWN;
        mac_cb->speed = mac_phy_to_speed[mac_cb->phy_if];
        mac_cb->max_speed = mac_cb->speed;
 
@@ -849,6 +864,17 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
                        mac_cb->mac_id);
        }
 
+       if (!fwnode_property_read_string(mac_cb->fw_port, "media-type",
+                                        &media_type)) {
+               for (i = 0; i < ARRAY_SIZE(media_type_defs); i++) {
+                       if (!strncmp(media_type_defs[i].name, media_type,
+                                    MAC_MEDIA_TYPE_MAX_LEN)) {
+                               mac_cb->media_type = media_type_defs[i].value;
+                               break;
+                       }
+               }
+       }
+
        return 0;
 }
 
index 05a6e8f7a4198d0a1c468073203b57fca6d1512b..4cbdf14f5c163e7405dd323327e8d3dc015a6ae5 100644 (file)
@@ -335,6 +335,7 @@ struct hns_mac_cb {
        u64 txpkt_for_led;
        u64 rxpkt_for_led;
        enum hnae_port_type mac_type;
+       enum hnae_media_type media_type;
        phy_interface_t phy_if;
        enum hnae_loop loop_mode;
 
index a395ca1405c3e437317702df66a614167efabaf1..ab33487a5321dd1d40f76be59ae7c49f6cf70757 100644 (file)
@@ -165,13 +165,21 @@ static int hns_nic_get_settings(struct net_device *net_dev,
                cmd->advertising |= ADVERTISED_10000baseKR_Full;
        }
 
-       if (h->port_type == HNAE_PORT_SERVICE) {
+       switch (h->media_type) {
+       case HNAE_MEDIA_TYPE_FIBER:
                cmd->port = PORT_FIBRE;
-               cmd->supported |= SUPPORTED_Pause;
-       } else {
+               break;
+       case HNAE_MEDIA_TYPE_COPPER:
                cmd->port = PORT_TP;
+               break;
+       case HNAE_MEDIA_TYPE_UNKNOWN:
+       default:
+               break;
        }
 
+       if (!(AE_IS_VER1(priv->enet_ver) && h->port_type == HNAE_PORT_DEBUG))
+               cmd->supported |= SUPPORTED_Pause;
+
        cmd->transceiver = XCVR_EXTERNAL;
        cmd->mdio_support = (ETH_MDIO_SUPPORTS_C45 | ETH_MDIO_SUPPORTS_C22);
        hns_get_mdix_mode(net_dev, cmd);