0001
0002
0003
0004
0005
0006 #ifndef _HNS_DSAF_MAC_H
0007 #define _HNS_DSAF_MAC_H
0008
0009 #include <linux/if_vlan.h>
0010 #include <linux/kernel.h>
0011 #include <linux/phy.h>
0012 #include <linux/regmap.h>
0013 #include "hns_dsaf_main.h"
0014
0015 struct dsaf_device;
0016
0017 #define MAC_GMAC_SUPPORTED \
0018 (SUPPORTED_10baseT_Half \
0019 | SUPPORTED_10baseT_Full \
0020 | SUPPORTED_100baseT_Half \
0021 | SUPPORTED_100baseT_Full \
0022 | SUPPORTED_Autoneg)
0023
0024 #define MAC_DEFAULT_MTU (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN + ETH_DATA_LEN)
0025 #define MAC_MAX_MTU 9600
0026 #define MAC_MAX_MTU_V2 9728
0027 #define MAC_MIN_MTU 68
0028 #define MAC_MAX_MTU_DBG MAC_DEFAULT_MTU
0029
0030 #define MAC_DEFAULT_PAUSE_TIME 0xffff
0031
0032 #define MAC_GMAC_IDX 0
0033 #define MAC_XGMAC_IDX 1
0034
0035 #define ETH_STATIC_REG 1
0036 #define ETH_DUMP_REG 5
0037
0038 #define MAC_IS_BROADCAST(p) ((*(p) == 0xff) && (*((p) + 1) == 0xff) && \
0039 (*((p) + 2) == 0xff) && (*((p) + 3) == 0xff) && \
0040 (*((p) + 4) == 0xff) && (*((p) + 5) == 0xff))
0041
0042
0043 #define MAC_IS_L3_MULTICAST(p) ((*((p) + 0) == 0x01) && \
0044 (*((p) + 1) == 0x00) && \
0045 (*((p) + 2) == 0x5e))
0046
0047
0048 #define MAC_IS_ALL_ZEROS(p) ((*(p) == 0) && (*((p) + 1) == 0) && \
0049 (*((p) + 2) == 0) && (*((p) + 3) == 0) && \
0050 (*((p) + 4) == 0) && (*((p) + 5) == 0))
0051
0052
0053 #define MAC_IS_MULTICAST(p) ((*((u8 *)((p) + 0)) & 0x01) ? (1) : (0))
0054
0055 struct mac_priv {
0056 void *mac;
0057 };
0058
0059
0060 enum mac_speed {
0061 MAC_SPEED_10 = 10,
0062 MAC_SPEED_100 = 100,
0063 MAC_SPEED_1000 = 1000,
0064 MAC_SPEED_10000 = 10000
0065 };
0066
0067
0068 enum mac_intf {
0069 MAC_IF_NONE = 0x00000000,
0070 MAC_IF_MII = 0x00010000,
0071 MAC_IF_RMII = 0x00020000,
0072 MAC_IF_SMII = 0x00030000,
0073 MAC_IF_GMII = 0x00040000,
0074 MAC_IF_RGMII = 0x00050000,
0075 MAC_IF_TBI = 0x00060000,
0076 MAC_IF_RTBI = 0x00070000,
0077 MAC_IF_SGMII = 0x00080000,
0078 MAC_IF_XGMII = 0x00090000,
0079 MAC_IF_QSGMII = 0x000a0000
0080 };
0081
0082
0083 enum mac_mode {
0084
0085 MAC_MODE_INVALID = 0,
0086
0087 MAC_MODE_MII_10 = (MAC_IF_MII | MAC_SPEED_10),
0088
0089 MAC_MODE_MII_100 = (MAC_IF_MII | MAC_SPEED_100),
0090
0091 MAC_MODE_RMII_10 = (MAC_IF_RMII | MAC_SPEED_10),
0092
0093 MAC_MODE_RMII_100 = (MAC_IF_RMII | MAC_SPEED_100),
0094
0095 MAC_MODE_SMII_10 = (MAC_IF_SMII | MAC_SPEED_10),
0096
0097 MAC_MODE_SMII_100 = (MAC_IF_SMII | MAC_SPEED_100),
0098
0099 MAC_MODE_GMII_1000 = (MAC_IF_GMII | MAC_SPEED_1000),
0100
0101 MAC_MODE_RGMII_10 = (MAC_IF_RGMII | MAC_SPEED_10),
0102
0103 MAC_MODE_RGMII_100 = (MAC_IF_RGMII | MAC_SPEED_100),
0104
0105 MAC_MODE_RGMII_1000 = (MAC_IF_RGMII | MAC_SPEED_1000),
0106
0107 MAC_MODE_TBI_1000 = (MAC_IF_TBI | MAC_SPEED_1000),
0108
0109 MAC_MODE_RTBI_1000 = (MAC_IF_RTBI | MAC_SPEED_1000),
0110
0111 MAC_MODE_SGMII_10 = (MAC_IF_SGMII | MAC_SPEED_10),
0112
0113 MAC_MODE_SGMII_100 = (MAC_IF_SGMII | MAC_SPEED_100),
0114
0115 MAC_MODE_SGMII_1000 = (MAC_IF_SGMII | MAC_SPEED_1000),
0116
0117 MAC_MODE_XGMII_10000 = (MAC_IF_XGMII | MAC_SPEED_10000),
0118
0119 MAC_MODE_QSGMII_1000 = (MAC_IF_QSGMII | MAC_SPEED_1000)
0120 };
0121
0122
0123 enum mac_commom_mode {
0124 MAC_COMM_MODE_NONE = 0,
0125 MAC_COMM_MODE_RX = 1,
0126 MAC_COMM_MODE_TX = 2,
0127 MAC_COMM_MODE_RX_AND_TX = 3
0128 };
0129
0130
0131 struct mac_statistics {
0132 u64 stat_pkts64;
0133 u64 stat_pkts65to127;
0134 u64 stat_pkts128to255;
0135 u64 stat_pkts256to511;
0136 u64 stat_pkts512to1023;
0137 u64 stat_pkts1024to1518;
0138 u64 stat_pkts1519to1522;
0139
0140
0141 u64 stat_fragments;
0142
0143 u64 stat_jabbers;
0144
0145
0146 u64 stat_drop_events;
0147
0148
0149 u64 stat_crc_align_errors;
0150
0151
0152 u64 stat_undersize_pkts;
0153 u64 stat_oversize_pkts;
0154
0155 u64 stat_rx_pause;
0156 u64 stat_tx_pause;
0157
0158 u64 in_octets;
0159 u64 in_pkts;
0160 u64 in_mcast_pkts;
0161 u64 in_bcast_pkts;
0162
0163
0164 u64 in_discards;
0165 u64 in_errors;
0166
0167
0168
0169
0170 u64 out_octets;
0171 u64 out_pkts;
0172 u64 out_mcast_pkts;
0173 u64 out_bcast_pkts;
0174
0175
0176 u64 out_discards;
0177 u64 out_errors;
0178
0179
0180
0181 };
0182
0183
0184 struct mac_params {
0185 char addr[ETH_ALEN];
0186 u8 __iomem *vaddr;
0187 struct device *dev;
0188 u8 mac_id;
0189
0190 enum mac_mode mac_mode;
0191 };
0192
0193 struct mac_info {
0194 u16 speed;
0195
0196
0197
0198 u8 duplex;
0199 u8 auto_neg;
0200 enum hnae_loop loop_mode;
0201 u8 tx_pause_en;
0202 u8 tx_pause_time;
0203 u8 rx_pause_en;
0204 u8 pad_and_crc_en;
0205 u8 promiscuous_en;
0206 u8 port_en;
0207 };
0208
0209 struct mac_entry_idx {
0210 u8 addr[ETH_ALEN];
0211 u16 vlan_id:12;
0212 u16 valid:1;
0213 u16 qos:3;
0214 };
0215
0216 struct mac_hw_stats {
0217 u64 rx_good_pkts;
0218 u64 rx_good_bytes;
0219 u64 rx_total_pkts;
0220 u64 rx_total_bytes;
0221 u64 rx_bad_bytes;
0222 u64 rx_uc_pkts;
0223 u64 rx_mc_pkts;
0224 u64 rx_bc_pkts;
0225 u64 rx_fragment_err;
0226 u64 rx_undersize;
0227 u64 rx_under_min;
0228 u64 rx_minto64;
0229 u64 rx_64bytes;
0230 u64 rx_65to127;
0231 u64 rx_128to255;
0232 u64 rx_256to511;
0233 u64 rx_512to1023;
0234 u64 rx_1024to1518;
0235 u64 rx_1519tomax;
0236 u64 rx_1519tomax_good;
0237 u64 rx_oversize;
0238 u64 rx_jabber_err;
0239 u64 rx_fcs_err;
0240 u64 rx_vlan_pkts;
0241 u64 rx_data_err;
0242 u64 rx_align_err;
0243 u64 rx_long_err;
0244 u64 rx_pfc_tc0;
0245 u64 rx_pfc_tc1;
0246 u64 rx_pfc_tc2;
0247 u64 rx_pfc_tc3;
0248 u64 rx_pfc_tc4;
0249 u64 rx_pfc_tc5;
0250 u64 rx_pfc_tc6;
0251 u64 rx_pfc_tc7;
0252 u64 rx_unknown_ctrl;
0253 u64 rx_filter_pkts;
0254 u64 rx_filter_bytes;
0255 u64 rx_fifo_overrun_err;
0256 u64 rx_len_err;
0257 u64 rx_comma_err;
0258 u64 rx_symbol_err;
0259 u64 tx_good_to_sw;
0260 u64 tx_bad_to_sw;
0261 u64 rx_1731_pkts;
0262
0263 u64 tx_good_bytes;
0264 u64 tx_good_pkts;
0265 u64 tx_total_bytes;
0266 u64 tx_total_pkts;
0267 u64 tx_bad_bytes;
0268 u64 tx_bad_pkts;
0269 u64 tx_uc_pkts;
0270 u64 tx_mc_pkts;
0271 u64 tx_bc_pkts;
0272 u64 tx_undersize;
0273 u64 tx_fragment_err;
0274 u64 tx_under_min_pkts;
0275 u64 tx_64bytes;
0276 u64 tx_65to127;
0277 u64 tx_128to255;
0278 u64 tx_256to511;
0279 u64 tx_512to1023;
0280 u64 tx_1024to1518;
0281 u64 tx_1519tomax;
0282 u64 tx_1519tomax_good;
0283 u64 tx_oversize;
0284 u64 tx_jabber_err;
0285 u64 tx_underrun_err;
0286 u64 tx_vlan;
0287 u64 tx_crc_err;
0288 u64 tx_pfc_tc0;
0289 u64 tx_pfc_tc1;
0290 u64 tx_pfc_tc2;
0291 u64 tx_pfc_tc3;
0292 u64 tx_pfc_tc4;
0293 u64 tx_pfc_tc5;
0294 u64 tx_pfc_tc6;
0295 u64 tx_pfc_tc7;
0296 u64 tx_ctrl;
0297 u64 tx_1731_pkts;
0298 u64 tx_1588_pkts;
0299 u64 rx_good_from_sw;
0300 u64 rx_bad_from_sw;
0301 };
0302
0303 struct hns_mac_cb {
0304 struct device *dev;
0305 struct dsaf_device *dsaf_dev;
0306 struct mac_priv priv;
0307 struct fwnode_handle *fw_port;
0308 u8 __iomem *vaddr;
0309 u8 __iomem *sys_ctl_vaddr;
0310 u8 __iomem *serdes_vaddr;
0311 struct regmap *serdes_ctrl;
0312 struct regmap *cpld_ctrl;
0313 char mc_mask[ETH_ALEN];
0314 u32 cpld_ctrl_reg;
0315 u32 port_rst_off;
0316 u32 port_mode_off;
0317 struct mac_entry_idx addr_entry_idx[DSAF_MAX_VM_NUM];
0318 u8 sfp_prsnt;
0319 u8 cpld_led_value;
0320 u8 mac_id;
0321
0322 u8 link;
0323 u8 half_duplex;
0324 u16 speed;
0325 u16 max_speed;
0326 u16 max_frm;
0327 u16 tx_pause_frm_time;
0328 u32 if_support;
0329 u64 txpkt_for_led;
0330 u64 rxpkt_for_led;
0331 enum hnae_port_type mac_type;
0332 enum hnae_media_type media_type;
0333 phy_interface_t phy_if;
0334 enum hnae_loop loop_mode;
0335
0336 struct phy_device *phy_dev;
0337
0338 struct mac_hw_stats hw_stats;
0339 };
0340
0341 struct mac_driver {
0342
0343 void (*mac_init)(void *mac_drv);
0344
0345 void (*mac_free)(void *mac_drv);
0346
0347 void (*mac_enable)(void *mac_drv, enum mac_commom_mode mode);
0348
0349 void (*mac_disable)(void *mac_drv, enum mac_commom_mode mode);
0350
0351 void (*set_mac_addr)(void *mac_drv, const char *mac_addr);
0352
0353 int (*adjust_link)(void *mac_drv, enum mac_speed speed,
0354 u32 full_duplex);
0355
0356 bool (*need_adjust_link)(void *mac_drv, enum mac_speed speed,
0357 int duplex);
0358
0359 void (*set_an_mode)(void *mac_drv, u8 enable);
0360
0361 int (*config_loopback)(void *mac_drv, enum hnae_loop loop_mode,
0362 u8 enable);
0363
0364 void (*config_max_frame_length)(void *mac_drv, u16 newval);
0365
0366 void (*config_pad_and_crc)(void *mac_drv, u8 newval);
0367
0368 void (*set_tx_auto_pause_frames)(void *mac_drv, u16 pause_time);
0369
0370 void (*set_promiscuous)(void *mac_drv, u8 enable);
0371 void (*mac_pausefrm_cfg)(void *mac_drv, u32 rx_en, u32 tx_en);
0372
0373 void (*autoneg_stat)(void *mac_drv, u32 *enable);
0374 int (*set_pause_enable)(void *mac_drv, u32 rx_en, u32 tx_en);
0375 void (*get_pause_enable)(void *mac_drv, u32 *rx_en, u32 *tx_en);
0376 void (*get_link_status)(void *mac_drv, u32 *link_stat);
0377
0378 void (*get_regs)(void *mac_drv, void *data);
0379 int (*get_regs_count)(void);
0380
0381 void (*get_strings)(u32 stringset, u8 *data);
0382
0383 int (*get_sset_count)(int stringset);
0384
0385
0386 void (*get_ethtool_stats)(void *mac_drv, u64 *data);
0387
0388
0389 void (*get_info)(void *mac_drv, struct mac_info *mac_info);
0390
0391 void (*update_stats)(void *mac_drv);
0392 int (*wait_fifo_clean)(void *mac_drv);
0393
0394 enum mac_mode mac_mode;
0395 u8 mac_id;
0396 struct hns_mac_cb *mac_cb;
0397 u8 __iomem *io_base;
0398 unsigned int mac_en_flg;
0399 unsigned int virt_dev_num;
0400 struct device *dev;
0401 };
0402
0403 struct mac_stats_string {
0404 const char desc[ETH_GSTRING_LEN];
0405 unsigned long offset;
0406 };
0407
0408 #define MAC_MAKE_MODE(interface, speed) (enum mac_mode)((interface) | (speed))
0409 #define MAC_INTERFACE_FROM_MODE(mode) (enum mac_intf)((mode) & 0xFFFF0000)
0410 #define MAC_SPEED_FROM_MODE(mode) (enum mac_speed)((mode) & 0x0000FFFF)
0411 #define MAC_STATS_FIELD_OFF(field) (offsetof(struct mac_hw_stats, field))
0412
0413 static inline struct mac_driver *hns_mac_get_drv(
0414 const struct hns_mac_cb *mac_cb)
0415 {
0416 return (struct mac_driver *)(mac_cb->priv.mac);
0417 }
0418
0419 void *hns_gmac_config(struct hns_mac_cb *mac_cb,
0420 struct mac_params *mac_param);
0421 void *hns_xgmac_config(struct hns_mac_cb *mac_cb,
0422 struct mac_params *mac_param);
0423
0424 int hns_mac_init(struct dsaf_device *dsaf_dev);
0425 void mac_adjust_link(struct net_device *net_dev);
0426 bool hns_mac_need_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex);
0427 void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status);
0428 int hns_mac_change_vf_addr(struct hns_mac_cb *mac_cb, u32 vmid,
0429 const char *addr);
0430 int hns_mac_set_multi(struct hns_mac_cb *mac_cb,
0431 u32 port_num, char *addr, bool enable);
0432 int hns_mac_vm_config_bc_en(struct hns_mac_cb *mac_cb, u32 vm, bool enable);
0433 void hns_mac_start(struct hns_mac_cb *mac_cb);
0434 void hns_mac_stop(struct hns_mac_cb *mac_cb);
0435 void hns_mac_uninit(struct dsaf_device *dsaf_dev);
0436 void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex);
0437 void hns_mac_reset(struct hns_mac_cb *mac_cb);
0438 void hns_mac_get_autoneg(struct hns_mac_cb *mac_cb, u32 *auto_neg);
0439 void hns_mac_get_pauseparam(struct hns_mac_cb *mac_cb, u32 *rx_en, u32 *tx_en);
0440 int hns_mac_set_autoneg(struct hns_mac_cb *mac_cb, u8 enable);
0441 int hns_mac_set_pauseparam(struct hns_mac_cb *mac_cb, u32 rx_en, u32 tx_en);
0442 int hns_mac_set_mtu(struct hns_mac_cb *mac_cb, u32 new_mtu, u32 buf_size);
0443 int hns_mac_get_port_info(struct hns_mac_cb *mac_cb,
0444 u8 *auto_neg, u16 *speed, u8 *duplex);
0445 int hns_mac_config_mac_loopback(struct hns_mac_cb *mac_cb,
0446 enum hnae_loop loop, int en);
0447 void hns_mac_update_stats(struct hns_mac_cb *mac_cb);
0448 void hns_mac_get_stats(struct hns_mac_cb *mac_cb, u64 *data);
0449 void hns_mac_get_strings(struct hns_mac_cb *mac_cb, int stringset, u8 *data);
0450 int hns_mac_get_sset_count(struct hns_mac_cb *mac_cb, int stringset);
0451 void hns_mac_get_regs(struct hns_mac_cb *mac_cb, void *data);
0452 int hns_mac_get_regs_count(struct hns_mac_cb *mac_cb);
0453 void hns_set_led_opt(struct hns_mac_cb *mac_cb);
0454 int hns_cpld_led_set_id(struct hns_mac_cb *mac_cb,
0455 enum hnae_led_state status);
0456 void hns_mac_set_promisc(struct hns_mac_cb *mac_cb, u8 en);
0457 int hns_mac_get_inner_port_num(struct hns_mac_cb *mac_cb,
0458 u8 vmid, u8 *port_num);
0459 int hns_mac_add_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
0460 const unsigned char *addr);
0461 int hns_mac_rm_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
0462 const unsigned char *addr);
0463 int hns_mac_clr_multicast(struct hns_mac_cb *mac_cb, int vfn);
0464 void hns_mac_enable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode);
0465 void hns_mac_disable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode);
0466 int hns_mac_wait_fifo_clean(struct hns_mac_cb *mac_cb);
0467
0468 #endif