Skip to content

Commit

Permalink
net/ngbe: identify and reset PHY
Browse files Browse the repository at this point in the history
Identify PHY to get the PHY type, and perform a PHY reset.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
  • Loading branch information
Jiawen Wu authored and ol-andrewr committed Jul 12, 2021
1 parent 7871087 commit 44e9755
Show file tree
Hide file tree
Showing 13 changed files with 1,095 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/net/ngbe/base/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ sources = [
'ngbe_eeprom.c',
'ngbe_hw.c',
'ngbe_mng.c',
'ngbe_phy.c',
'ngbe_phy_rtl.c',
'ngbe_phy_mvl.c',
'ngbe_phy_yt.c',
]

error_cflags = []
Expand Down
40 changes: 40 additions & 0 deletions drivers/net/ngbe/base/ngbe_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,39 @@ static inline s32 ngbe_mac_init_thermal_ssth_dummy(struct ngbe_hw *TUP0)
{
return NGBE_ERR_OPS_DUMMY;
}
static inline s32 ngbe_mac_check_overtemp_dummy(struct ngbe_hw *TUP0)
{
return NGBE_ERR_OPS_DUMMY;
}
/* struct ngbe_phy_operations */
static inline s32 ngbe_phy_identify_dummy(struct ngbe_hw *TUP0)
{
return NGBE_ERR_OPS_DUMMY;
}
static inline s32 ngbe_phy_reset_hw_dummy(struct ngbe_hw *TUP0)
{
return NGBE_ERR_OPS_DUMMY;
}
static inline s32 ngbe_phy_read_reg_dummy(struct ngbe_hw *TUP0, u32 TUP1,
u32 TUP2, u16 *TUP3)
{
return NGBE_ERR_OPS_DUMMY;
}
static inline s32 ngbe_phy_write_reg_dummy(struct ngbe_hw *TUP0, u32 TUP1,
u32 TUP2, u16 TUP3)
{
return NGBE_ERR_OPS_DUMMY;
}
static inline s32 ngbe_phy_read_reg_unlocked_dummy(struct ngbe_hw *TUP0,
u32 TUP1, u32 TUP2, u16 *TUP3)
{
return NGBE_ERR_OPS_DUMMY;
}
static inline s32 ngbe_phy_write_reg_unlocked_dummy(struct ngbe_hw *TUP0,
u32 TUP1, u32 TUP2, u16 TUP3)
{
return NGBE_ERR_OPS_DUMMY;
}
static inline void ngbe_init_ops_dummy(struct ngbe_hw *hw)
{
hw->bus.set_lan_id = ngbe_bus_set_lan_id_dummy;
Expand All @@ -75,6 +108,13 @@ static inline void ngbe_init_ops_dummy(struct ngbe_hw *hw)
hw->mac.acquire_swfw_sync = ngbe_mac_acquire_swfw_sync_dummy;
hw->mac.release_swfw_sync = ngbe_mac_release_swfw_sync_dummy;
hw->mac.init_thermal_sensor_thresh = ngbe_mac_init_thermal_ssth_dummy;
hw->mac.check_overtemp = ngbe_mac_check_overtemp_dummy;
hw->phy.identify = ngbe_phy_identify_dummy;
hw->phy.reset_hw = ngbe_phy_reset_hw_dummy;
hw->phy.read_reg = ngbe_phy_read_reg_dummy;
hw->phy.write_reg = ngbe_phy_write_reg_dummy;
hw->phy.read_reg_unlocked = ngbe_phy_read_reg_unlocked_dummy;
hw->phy.write_reg_unlocked = ngbe_phy_write_reg_unlocked_dummy;
}

#endif /* _NGBE_TYPE_DUMMY_H_ */
Expand Down
38 changes: 38 additions & 0 deletions drivers/net/ngbe/base/ngbe_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "ngbe_type.h"
#include "ngbe_phy.h"
#include "ngbe_eeprom.h"
#include "ngbe_mng.h"
#include "ngbe_hw.h"
Expand Down Expand Up @@ -124,6 +125,15 @@ s32 ngbe_reset_hw_em(struct ngbe_hw *hw)
if (status != 0)
return status;

/* Identify PHY and related function pointers */
status = ngbe_init_phy(hw);
if (status)
return status;

/* Reset PHY */
if (!hw->phy.reset_disable)
hw->phy.reset_hw(hw);

wr32(hw, NGBE_RST, NGBE_RST_LAN(hw->bus.lan_id));
ngbe_flush(hw);
msec_delay(50);
Expand Down Expand Up @@ -307,6 +317,24 @@ s32 ngbe_init_thermal_sensor_thresh(struct ngbe_hw *hw)
return 0;
}

s32 ngbe_mac_check_overtemp(struct ngbe_hw *hw)
{
s32 status = 0;
u32 ts_state;

DEBUGFUNC("ngbe_mac_check_overtemp");

/* Check that the LASI temp alarm status was triggered */
ts_state = rd32(hw, NGBE_TSALM);

if (ts_state & NGBE_TSALM_HI)
status = NGBE_ERR_UNDERTEMP;
else if (ts_state & NGBE_TSALM_LO)
status = NGBE_ERR_OVERTEMP;

return status;
}

void ngbe_disable_rx(struct ngbe_hw *hw)
{
u32 pfdtxgswc;
Expand Down Expand Up @@ -434,13 +462,22 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
{
struct ngbe_bus_info *bus = &hw->bus;
struct ngbe_mac_info *mac = &hw->mac;
struct ngbe_phy_info *phy = &hw->phy;
struct ngbe_rom_info *rom = &hw->rom;

DEBUGFUNC("ngbe_init_ops_pf");

/* BUS */
bus->set_lan_id = ngbe_set_lan_id_multi_port;

/* PHY */
phy->identify = ngbe_identify_phy;
phy->read_reg = ngbe_read_phy_reg;
phy->write_reg = ngbe_write_phy_reg;
phy->read_reg_unlocked = ngbe_read_phy_reg_mdi;
phy->write_reg_unlocked = ngbe_write_phy_reg_mdi;
phy->reset_hw = ngbe_reset_phy;

/* MAC */
mac->init_hw = ngbe_init_hw;
mac->reset_hw = ngbe_reset_hw_em;
Expand All @@ -450,6 +487,7 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)

/* Manageability interface */
mac->init_thermal_sensor_thresh = ngbe_init_thermal_sensor_thresh;
mac->check_overtemp = ngbe_mac_check_overtemp;

/* EEPROM */
rom->init_params = ngbe_init_eeprom_params;
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ngbe/base/ngbe_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask);
void ngbe_release_swfw_sync(struct ngbe_hw *hw, u32 mask);

s32 ngbe_init_thermal_sensor_thresh(struct ngbe_hw *hw);
s32 ngbe_mac_check_overtemp(struct ngbe_hw *hw);
void ngbe_disable_rx(struct ngbe_hw *hw);
s32 ngbe_init_shared_code(struct ngbe_hw *hw);
s32 ngbe_set_mac_type(struct ngbe_hw *hw);
s32 ngbe_init_ops_pf(struct ngbe_hw *hw);
s32 ngbe_init_phy(struct ngbe_hw *hw);
void ngbe_map_device_id(struct ngbe_hw *hw);

#endif /* _NGBE_HW_H_ */

0 comments on commit 44e9755

Please sign in to comment.