Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: hns: add attribute port-mode-offset for dsaf port node

Port mode offset for each dsaf port is different. The current code is not
so readability. This patch adds configuration named port-mode-offset to
make the code simple and more readability. If port-mode-offset isn't
exists, default value 0 will be used.

Signed-off-by: Daode Huang <huangdaode@hisilicon.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Yisen.Zhuang\(Zhuangyuzeng\) and committed by
David S. Miller
0d768fc6 850bfa3b

+30 -25
+10
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
··· 665 665 mac_cb->max_frm = MAC_DEFAULT_MTU; 666 666 mac_cb->tx_pause_frm_time = MAC_DEFAULT_PAUSE_TIME; 667 667 mac_cb->port_rst_off = mac_cb->mac_id; 668 + mac_cb->port_mode_off = 0; 668 669 669 670 /* if the dsaf node doesn't contain a port subnode, get phy-handle 670 671 * from dsaf node ··· 701 700 if (ret) { 702 701 dev_dbg(mac_cb->dev, 703 702 "mac%d port-rst-offset not found, use default value.\n", 703 + mac_cb->mac_id); 704 + } 705 + 706 + ret = fwnode_property_read_u32(mac_cb->fw_port, 707 + "port-mode-offset", 708 + &mac_cb->port_mode_off); 709 + if (ret) { 710 + dev_dbg(mac_cb->dev, 711 + "mac%d port-mode-offset not found, use default value.\n", 704 712 mac_cb->mac_id); 705 713 } 706 714
+1
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
··· 319 319 struct regmap *cpld_ctrl; 320 320 u32 cpld_ctrl_reg; 321 321 u32 port_rst_off; 322 + u32 port_mode_off; 322 323 struct mac_entry_idx addr_entry_idx[DSAF_MAX_VM_NUM]; 323 324 u8 sfp_prsnt; 324 325 u8 cpld_led_value;
+19 -25
drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
··· 265 265 { 266 266 u32 mode; 267 267 u32 reg; 268 - u32 shift; 269 - u32 phy_offset; 270 268 bool is_ver1 = AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver); 271 269 int mac_id = mac_cb->mac_id; 272 - phy_interface_t phy_if = PHY_INTERFACE_MODE_NA; 270 + phy_interface_t phy_if; 273 271 274 - if (is_ver1 && HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) { 275 - phy_if = PHY_INTERFACE_MODE_SGMII; 276 - } else if (mac_id >= 0 && mac_id <= 3 && 277 - !HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) { 278 - reg = is_ver1 ? HNS_MAC_HILINK4_REG : HNS_MAC_HILINK4V2_REG; 279 - mode = dsaf_read_sub(mac_cb->dsaf_dev, reg); 280 - /* mac_id 0, 1, 2, 3 ---> hilink4 lane 0, 1, 2, 3 */ 281 - shift = is_ver1 ? 0 : mac_id; 282 - if (dsaf_get_bit(mode, shift)) 283 - phy_if = PHY_INTERFACE_MODE_XGMII; 272 + if (is_ver1) { 273 + if (HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) 274 + return PHY_INTERFACE_MODE_SGMII; 275 + 276 + if (mac_id >= 0 && mac_id <= 3) 277 + reg = HNS_MAC_HILINK4_REG; 284 278 else 285 - phy_if = PHY_INTERFACE_MODE_SGMII; 286 - } else { 287 - reg = is_ver1 ? HNS_MAC_HILINK3_REG : HNS_MAC_HILINK3V2_REG; 288 - mode = dsaf_read_sub(mac_cb->dsaf_dev, reg); 289 - /* mac_id 4, 5,---> hilink3 lane 2, 3 290 - * debug port 0(6), 1(7) ---> hilink3 lane 0, 1 291 - */ 292 - phy_offset = mac_cb->dsaf_dev->reset_offset - 1; 293 - shift = is_ver1 ? 0 : mac_id >= 4 ? mac_id - 2 : phy_offset; 294 - if (dsaf_get_bit(mode, shift)) 295 - phy_if = PHY_INTERFACE_MODE_XGMII; 279 + reg = HNS_MAC_HILINK3_REG; 280 + } else{ 281 + if (!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev) && mac_id <= 3) 282 + reg = HNS_MAC_HILINK4V2_REG; 296 283 else 297 - phy_if = PHY_INTERFACE_MODE_SGMII; 284 + reg = HNS_MAC_HILINK3V2_REG; 298 285 } 286 + 287 + mode = dsaf_read_sub(mac_cb->dsaf_dev, reg); 288 + if (dsaf_get_bit(mode, mac_cb->port_mode_off)) 289 + phy_if = PHY_INTERFACE_MODE_XGMII; 290 + else 291 + phy_if = PHY_INTERFACE_MODE_SGMII; 292 + 299 293 return phy_if; 300 294 } 301 295