Skip to content

Commit

Permalink
net: hns3: add support for multiple media type
Browse files Browse the repository at this point in the history
Previously, we can only identify copper and fiber type, the
supported link modes of port information are always showing
SR type. This patch adds support for multiple media types,
include SR, LR CR, KR. Driver needs to query the media type
from firmware periodicly, and updates the port information.

The new port information looks like this:
Settings for eth0:
        Supported ports: [ FIBRE ]
        Supported link modes:   25000baseCR/Full
                                25000baseSR/Full
                                1000baseX/Full
                                10000baseCR/Full
                                10000baseSR/Full
                                10000baseLR/Full
        Supported pause frame use: Symmetric
        Supports auto-negotiation: No
        Supported FEC modes: None BaseR
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Advertised FEC modes: Not reported
        Speed: 10000Mb/s
        Duplex: Full
        Port: FIBRE
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off
        Current message level: 0x00000036 (54)
                               probe link ifdown ifup
        Link detected: yes

In order to be compatible with old firmware which only support
sfp speed, we remained using the same query command, and kept
the former logic.

Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
IronShen authored and davem330 committed May 4, 2019
1 parent e28441e commit 88d10bd
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 63 deletions.
18 changes: 14 additions & 4 deletions drivers/net/ethernet/hisilicon/hns3/hnae3.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ enum hnae3_media_type {
HNAE3_MEDIA_TYPE_NONE,
};

/* must be consistent with definition in firmware */
enum hnae3_module_type {
HNAE3_MODULE_TYPE_UNKNOWN = 0x00,
HNAE3_MODULE_TYPE_FIBRE_LR = 0x01,
HNAE3_MODULE_TYPE_FIBRE_SR = 0x02,
HNAE3_MODULE_TYPE_AOC = 0x03,
HNAE3_MODULE_TYPE_CR = 0x04,
HNAE3_MODULE_TYPE_KR = 0x05,
HNAE3_MODULE_TYPE_TP = 0x06,

};

enum hnae3_reset_notify_type {
HNAE3_UP_CLIENT,
HNAE3_DOWN_CLIENT,
Expand Down Expand Up @@ -230,8 +242,6 @@ struct hnae3_ae_dev {
* non-ok
* get_ksettings_an_result()
* Get negotiation status,speed and duplex
* update_speed_duplex_h()
* Update hardware speed and duplex
* get_media_type()
* Get media type of MAC
* adjust_link()
Expand Down Expand Up @@ -340,11 +350,11 @@ struct hnae3_ae_ops {
void (*get_ksettings_an_result)(struct hnae3_handle *handle,
u8 *auto_neg, u32 *speed, u8 *duplex);

int (*update_speed_duplex_h)(struct hnae3_handle *handle);
int (*cfg_mac_speed_dup_h)(struct hnae3_handle *handle, int speed,
u8 duplex);

void (*get_media_type)(struct hnae3_handle *handle, u8 *media_type);
void (*get_media_type)(struct hnae3_handle *handle, u8 *media_type,
u8 *module_type);
void (*adjust_link)(struct hnae3_handle *handle, int speed, int duplex);
int (*set_loopback)(struct hnae3_handle *handle,
enum hnae3_loop loop_mode, bool en);
Expand Down
13 changes: 11 additions & 2 deletions drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ static int hns3_get_link_ksettings(struct net_device *netdev,
{
struct hnae3_handle *h = hns3_get_handle(netdev);
const struct hnae3_ae_ops *ops;
u8 module_type;
u8 media_type;
u8 link_stat;

Expand All @@ -612,7 +613,7 @@ static int hns3_get_link_ksettings(struct net_device *netdev,

ops = h->ae_algo->ops;
if (ops->get_media_type)
ops->get_media_type(h, &media_type);
ops->get_media_type(h, &media_type, &module_type);
else
return -EOPNOTSUPP;

Expand All @@ -622,7 +623,15 @@ static int hns3_get_link_ksettings(struct net_device *netdev,
hns3_get_ksettings(h, cmd);
break;
case HNAE3_MEDIA_TYPE_FIBER:
cmd->base.port = PORT_FIBRE;
if (module_type == HNAE3_MODULE_TYPE_CR)
cmd->base.port = PORT_DA;
else
cmd->base.port = PORT_FIBRE;

hns3_get_ksettings(h, cmd);
break;
case HNAE3_MEDIA_TYPE_BACKPLANE:
cmd->base.port = PORT_NONE;
hns3_get_ksettings(h, cmd);
break;
case HNAE3_MEDIA_TYPE_COPPER:
Expand Down
14 changes: 10 additions & 4 deletions drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ enum hclge_opcode_type {
HCLGE_OPC_QUERY_NCL_CONFIG = 0x7011,

/* SFP command */
HCLGE_OPC_SFP_GET_SPEED = 0x7104,
HCLGE_OPC_GET_SFP_INFO = 0x7104,

/* Error INT commands */
HCLGE_MAC_COMMON_INT_EN = 0x030E,
Expand Down Expand Up @@ -599,9 +599,15 @@ struct hclge_config_auto_neg_cmd {
u8 rsv[20];
};

struct hclge_sfp_speed_cmd {
__le32 sfp_speed;
u32 rsv[5];
struct hclge_sfp_info_cmd {
__le32 speed;
u8 query_type; /* 0: sfp speed, 1: active speed */
u8 active_fec;
u8 autoneg; /* autoneg state */
u8 autoneg_ability; /* whether support autoneg */
__le32 speed_ability; /* speed ability for current media */
__le32 module_type;
u8 rsv[8];
};

#define HCLGE_MAC_UPLINK_PORT 0x100
Expand Down

0 comments on commit 88d10bd

Please sign in to comment.