Commit 579a2302 authored by Jacob Keller's avatar Jacob Keller Committed by Jakub Kicinski

ice: Introduce helper to get tmr_cmd_reg values

Multiple places in the driver code need to convert enum ice_ptp_tmr_cmd
values into register bits for both the main timer and the PHY port
timers. The main MAC register has one bit scheme for timer commands,
while the PHY commands use a different scheme.

The E810 and E830 devices use the same scheme for port commands as used
for the main timer. However, E822 and ETH56G hardware has a separate
scheme used by the PHY.

Introduce helper functions to convert the timer command enumeration into
the register values, reducing some code duplication, and making it
easier to later refactor the individual port write commands.
Reviewed-by: default avatarPrzemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: default avatarArkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Signed-off-by: default avatarKarol Kolacinski <karol.kolacinski@intel.com>
Tested-by: default avatarPucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com>
Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20240528-next-2024-05-28-ptp-refactors-v1-2-c082739bb6f6@intel.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d551d075
...@@ -227,40 +227,114 @@ static u64 ice_ptp_read_src_incval(struct ice_hw *hw) ...@@ -227,40 +227,114 @@ static u64 ice_ptp_read_src_incval(struct ice_hw *hw)
} }
/** /**
* ice_ptp_src_cmd - Prepare source timer for a timer command * ice_ptp_tmr_cmd_to_src_reg - Convert to source timer command value
* @hw: pointer to HW structure * @hw: pointer to HW struct
* @cmd: Timer command * @cmd: Timer command
* *
* Prepare the source timer for an upcoming timer sync command. * Return: the source timer command register value for the given PTP timer
* command.
*/ */
void ice_ptp_src_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd) static u32 ice_ptp_tmr_cmd_to_src_reg(struct ice_hw *hw,
enum ice_ptp_tmr_cmd cmd)
{ {
u32 cmd_val; u32 cmd_val, tmr_idx;
u8 tmr_idx;
switch (cmd) {
case ICE_PTP_INIT_TIME:
cmd_val = GLTSYN_CMD_INIT_TIME;
break;
case ICE_PTP_INIT_INCVAL:
cmd_val = GLTSYN_CMD_INIT_INCVAL;
break;
case ICE_PTP_ADJ_TIME:
cmd_val = GLTSYN_CMD_ADJ_TIME;
break;
case ICE_PTP_ADJ_TIME_AT_TIME:
cmd_val = GLTSYN_CMD_ADJ_INIT_TIME;
break;
case ICE_PTP_NOP:
case ICE_PTP_READ_TIME:
cmd_val = GLTSYN_CMD_READ_TIME;
break;
default:
dev_warn(ice_hw_to_dev(hw),
"Ignoring unrecognized timer command %u\n", cmd);
cmd_val = 0;
}
tmr_idx = ice_get_ptp_src_clock_index(hw); tmr_idx = ice_get_ptp_src_clock_index(hw);
cmd_val = tmr_idx << SEL_CPK_SRC;
return tmr_idx << SEL_CPK_SRC | cmd_val;
}
/**
* ice_ptp_tmr_cmd_to_port_reg- Convert to port timer command value
* @hw: pointer to HW struct
* @cmd: Timer command
*
* Note that some hardware families use a different command register value for
* the PHY ports, while other hardware families use the same register values
* as the source timer.
*
* Return: the PHY port timer command register value for the given PTP timer
* command.
*/
static u32 ice_ptp_tmr_cmd_to_port_reg(struct ice_hw *hw,
enum ice_ptp_tmr_cmd cmd)
{
u32 cmd_val, tmr_idx;
/* Certain hardware families share the same register values for the
* port register and source timer register.
*/
switch (hw->ptp.phy_model) {
case ICE_PHY_E810:
return ice_ptp_tmr_cmd_to_src_reg(hw, cmd) & TS_CMD_MASK_E810;
default:
break;
}
switch (cmd) { switch (cmd) {
case ICE_PTP_INIT_TIME: case ICE_PTP_INIT_TIME:
cmd_val |= GLTSYN_CMD_INIT_TIME; cmd_val = PHY_CMD_INIT_TIME;
break; break;
case ICE_PTP_INIT_INCVAL: case ICE_PTP_INIT_INCVAL:
cmd_val |= GLTSYN_CMD_INIT_INCVAL; cmd_val = PHY_CMD_INIT_INCVAL;
break; break;
case ICE_PTP_ADJ_TIME: case ICE_PTP_ADJ_TIME:
cmd_val |= GLTSYN_CMD_ADJ_TIME; cmd_val = PHY_CMD_ADJ_TIME;
break; break;
case ICE_PTP_ADJ_TIME_AT_TIME: case ICE_PTP_ADJ_TIME_AT_TIME:
cmd_val |= GLTSYN_CMD_ADJ_INIT_TIME; cmd_val = PHY_CMD_ADJ_TIME_AT_TIME;
break; break;
case ICE_PTP_READ_TIME: case ICE_PTP_READ_TIME:
cmd_val |= GLTSYN_CMD_READ_TIME; cmd_val = PHY_CMD_READ_TIME;
break; break;
case ICE_PTP_NOP: case ICE_PTP_NOP:
cmd_val = 0;
break; break;
default:
dev_warn(ice_hw_to_dev(hw),
"Ignoring unrecognized timer command %u\n", cmd);
cmd_val = 0;
} }
tmr_idx = ice_get_ptp_src_clock_index(hw);
return tmr_idx << SEL_PHY_SRC | cmd_val;
}
/**
* ice_ptp_src_cmd - Prepare source timer for a timer command
* @hw: pointer to HW structure
* @cmd: Timer command
*
* Prepare the source timer for an upcoming timer sync command.
*/
void ice_ptp_src_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd)
{
u32 cmd_val = ice_ptp_tmr_cmd_to_src_reg(hw, cmd);
wr32(hw, GLTSYN_CMD, cmd_val); wr32(hw, GLTSYN_CMD, cmd_val);
} }
...@@ -3029,47 +3103,9 @@ static int ice_ptp_prep_phy_incval_e810(struct ice_hw *hw, u64 incval) ...@@ -3029,47 +3103,9 @@ static int ice_ptp_prep_phy_incval_e810(struct ice_hw *hw, u64 incval)
*/ */
static int ice_ptp_port_cmd_e810(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd) static int ice_ptp_port_cmd_e810(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd)
{ {
u32 cmd_val, val; u32 val = ice_ptp_tmr_cmd_to_port_reg(hw, cmd);
int err;
switch (cmd) { return ice_write_phy_reg_e810(hw, E810_ETH_GLTSYN_CMD, val);
case ICE_PTP_INIT_TIME:
cmd_val = GLTSYN_CMD_INIT_TIME;
break;
case ICE_PTP_INIT_INCVAL:
cmd_val = GLTSYN_CMD_INIT_INCVAL;
break;
case ICE_PTP_ADJ_TIME:
cmd_val = GLTSYN_CMD_ADJ_TIME;
break;
case ICE_PTP_READ_TIME:
cmd_val = GLTSYN_CMD_READ_TIME;
break;
case ICE_PTP_ADJ_TIME_AT_TIME:
cmd_val = GLTSYN_CMD_ADJ_INIT_TIME;
break;
case ICE_PTP_NOP:
return 0;
}
/* Read, modify, write */
err = ice_read_phy_reg_e810(hw, ETH_GLTSYN_CMD, &val);
if (err) {
ice_debug(hw, ICE_DBG_PTP, "Failed to read GLTSYN_CMD, err %d\n", err);
return err;
}
/* Modify necessary bits only and perform write */
val &= ~TS_CMD_MASK_E810;
val |= cmd_val;
err = ice_write_phy_reg_e810(hw, ETH_GLTSYN_CMD, val);
if (err) {
ice_debug(hw, ICE_DBG_PTP, "Failed to write back GLTSYN_CMD, err %d\n", err);
return err;
}
return 0;
} }
/** /**
......
...@@ -485,7 +485,7 @@ int ice_cgu_get_output_pin_state_caps(struct ice_hw *hw, u8 pin_id, ...@@ -485,7 +485,7 @@ int ice_cgu_get_output_pin_state_caps(struct ice_hw *hw, u8 pin_id,
#define ETH_GLTSYN_SHADJ_H(_i) (0x0300037C + ((_i) * 32)) #define ETH_GLTSYN_SHADJ_H(_i) (0x0300037C + ((_i) * 32))
/* E810 timer command register */ /* E810 timer command register */
#define ETH_GLTSYN_CMD 0x03000344 #define E810_ETH_GLTSYN_CMD 0x03000344
/* Source timer incval macros */ /* Source timer incval macros */
#define INCVAL_HIGH_M 0xFF #define INCVAL_HIGH_M 0xFF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment