Skip to content

Commit be16574

Browse files
jacob-kelleranguy11
authored andcommitted
ice: introduce hw->phy_model for handling PTP PHY differences
The ice driver has PTP support which works across a couple of different device families. The device families each have different PHY hardware which have unique requirements for programming. Today, there is E810-based hardware, and E822-based hardware. To handle this, the driver checks the ice_is_e810() function to separate between the two existing families of hardware. Future development is going to add new hardware designs which have further unique requirements. To make this easier, introduce a phy_model field to the HW structure. This field represents what PHY model the current device has, and is used to allow distinguishing which logic a particular device needs. This will make supporting future upcoming hardware easier, by providing an obvious place to initialize the PHY model, and by already using switch/case statements instead of the previous if statements. Astute reviewers may notice that there are a handful of remaining checks for ice_is_e810() left in ice_ptp.c These conflict with some other cleanup patches in development, and will be fixed in the near future. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 88c360e commit be16574

4 files changed

Lines changed: 117 additions & 27 deletions

File tree

drivers/net/ethernet/intel/ice/ice_ptp.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ ice_ptp_port_phy_restart(struct ice_ptp_port *ptp_port)
13661366
void ice_ptp_link_change(struct ice_pf *pf, u8 port, bool linkup)
13671367
{
13681368
struct ice_ptp_port *ptp_port;
1369+
struct ice_hw *hw = &pf->hw;
13691370

13701371
if (!test_bit(ICE_FLAG_PTP, pf->flags))
13711372
return;
@@ -1380,11 +1381,16 @@ void ice_ptp_link_change(struct ice_pf *pf, u8 port, bool linkup)
13801381
/* Update cached link status for this port immediately */
13811382
ptp_port->link_up = linkup;
13821383

1383-
/* E810 devices do not need to reconfigure the PHY */
1384-
if (ice_is_e810(&pf->hw))
1384+
switch (hw->phy_model) {
1385+
case ICE_PHY_E810:
1386+
/* Do not reconfigure E810 PHY */
13851387
return;
1386-
1387-
ice_ptp_port_phy_restart(ptp_port);
1388+
case ICE_PHY_E822:
1389+
ice_ptp_port_phy_restart(ptp_port);
1390+
return;
1391+
default:
1392+
dev_warn(ice_pf_to_dev(pf), "%s: Unknown PHY type\n", __func__);
1393+
}
13881394
}
13891395

13901396
/**
@@ -2702,14 +2708,22 @@ static int ice_ptp_init_work(struct ice_pf *pf, struct ice_ptp *ptp)
27022708
*/
27032709
static int ice_ptp_init_port(struct ice_pf *pf, struct ice_ptp_port *ptp_port)
27042710
{
2711+
struct ice_hw *hw = &pf->hw;
2712+
27052713
mutex_init(&ptp_port->ps_lock);
27062714

2707-
if (ice_is_e810(&pf->hw))
2715+
switch (hw->phy_model) {
2716+
case ICE_PHY_E810:
27082717
return ice_ptp_init_tx_e810(pf, &ptp_port->tx);
2718+
case ICE_PHY_E822:
2719+
kthread_init_delayed_work(&ptp_port->ov_work,
2720+
ice_ptp_wait_for_offsets);
27092721

2710-
kthread_init_delayed_work(&ptp_port->ov_work,
2711-
ice_ptp_wait_for_offsets);
2712-
return ice_ptp_init_tx_e822(pf, &ptp_port->tx, ptp_port->port_num);
2722+
return ice_ptp_init_tx_e822(pf, &ptp_port->tx,
2723+
ptp_port->port_num);
2724+
default:
2725+
return -ENODEV;
2726+
}
27132727
}
27142728

27152729
/**
@@ -2730,6 +2744,8 @@ void ice_ptp_init(struct ice_pf *pf)
27302744
struct ice_hw *hw = &pf->hw;
27312745
int err;
27322746

2747+
ice_ptp_init_phy_model(hw);
2748+
27332749
/* If this function owns the clock hardware, it must allocate and
27342750
* configure the PTP clock device to represent it.
27352751
*/

drivers/net/ethernet/intel/ice/ice_ptp_hw.c

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,21 @@ void ice_ptp_unlock(struct ice_hw *hw)
32763276
wr32(hw, PFTSYN_SEM + (PFTSYN_SEM_BYTES * hw->pf_id), 0);
32773277
}
32783278

3279+
/**
3280+
* ice_ptp_init_phy_model - Initialize hw->phy_model based on device type
3281+
* @hw: pointer to the HW structure
3282+
*
3283+
* Determine the PHY model for the device, and initialize hw->phy_model
3284+
* for use by other functions.
3285+
*/
3286+
void ice_ptp_init_phy_model(struct ice_hw *hw)
3287+
{
3288+
if (ice_is_e810(hw))
3289+
hw->phy_model = ICE_PHY_E810;
3290+
else
3291+
hw->phy_model = ICE_PHY_E822;
3292+
}
3293+
32793294
/**
32803295
* ice_ptp_tmr_cmd - Prepare and trigger a timer sync command
32813296
* @hw: pointer to HW struct
@@ -3294,10 +3309,17 @@ static int ice_ptp_tmr_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd)
32943309
ice_ptp_src_cmd(hw, cmd);
32953310

32963311
/* Next, prepare the ports */
3297-
if (ice_is_e810(hw))
3312+
switch (hw->phy_model) {
3313+
case ICE_PHY_E810:
32983314
err = ice_ptp_port_cmd_e810(hw, cmd);
3299-
else
3315+
break;
3316+
case ICE_PHY_E822:
33003317
err = ice_ptp_port_cmd_e822(hw, cmd);
3318+
break;
3319+
default:
3320+
err = -EOPNOTSUPP;
3321+
}
3322+
33013323
if (err) {
33023324
ice_debug(hw, ICE_DBG_PTP, "Failed to prepare PHY ports for timer command %u, err %d\n",
33033325
cmd, err);
@@ -3339,10 +3361,17 @@ int ice_ptp_init_time(struct ice_hw *hw, u64 time)
33393361

33403362
/* PHY timers */
33413363
/* Fill Rx and Tx ports and send msg to PHY */
3342-
if (ice_is_e810(hw))
3364+
switch (hw->phy_model) {
3365+
case ICE_PHY_E810:
33433366
err = ice_ptp_prep_phy_time_e810(hw, time & 0xFFFFFFFF);
3344-
else
3367+
break;
3368+
case ICE_PHY_E822:
33453369
err = ice_ptp_prep_phy_time_e822(hw, time & 0xFFFFFFFF);
3370+
break;
3371+
default:
3372+
err = -EOPNOTSUPP;
3373+
}
3374+
33463375
if (err)
33473376
return err;
33483377

@@ -3374,10 +3403,17 @@ int ice_ptp_write_incval(struct ice_hw *hw, u64 incval)
33743403
wr32(hw, GLTSYN_SHADJ_L(tmr_idx), lower_32_bits(incval));
33753404
wr32(hw, GLTSYN_SHADJ_H(tmr_idx), upper_32_bits(incval));
33763405

3377-
if (ice_is_e810(hw))
3406+
switch (hw->phy_model) {
3407+
case ICE_PHY_E810:
33783408
err = ice_ptp_prep_phy_incval_e810(hw, incval);
3379-
else
3409+
break;
3410+
case ICE_PHY_E822:
33803411
err = ice_ptp_prep_phy_incval_e822(hw, incval);
3412+
break;
3413+
default:
3414+
err = -EOPNOTSUPP;
3415+
}
3416+
33813417
if (err)
33823418
return err;
33833419

@@ -3433,10 +3469,17 @@ int ice_ptp_adj_clock(struct ice_hw *hw, s32 adj)
34333469
wr32(hw, GLTSYN_SHADJ_L(tmr_idx), 0);
34343470
wr32(hw, GLTSYN_SHADJ_H(tmr_idx), adj);
34353471

3436-
if (ice_is_e810(hw))
3472+
switch (hw->phy_model) {
3473+
case ICE_PHY_E810:
34373474
err = ice_ptp_prep_phy_adj_e810(hw, adj);
3438-
else
3475+
break;
3476+
case ICE_PHY_E822:
34393477
err = ice_ptp_prep_phy_adj_e822(hw, adj);
3478+
break;
3479+
default:
3480+
err = -EOPNOTSUPP;
3481+
}
3482+
34403483
if (err)
34413484
return err;
34423485

@@ -3456,10 +3499,14 @@ int ice_ptp_adj_clock(struct ice_hw *hw, s32 adj)
34563499
*/
34573500
int ice_read_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx, u64 *tstamp)
34583501
{
3459-
if (ice_is_e810(hw))
3502+
switch (hw->phy_model) {
3503+
case ICE_PHY_E810:
34603504
return ice_read_phy_tstamp_e810(hw, block, idx, tstamp);
3461-
else
3505+
case ICE_PHY_E822:
34623506
return ice_read_phy_tstamp_e822(hw, block, idx, tstamp);
3507+
default:
3508+
return -EOPNOTSUPP;
3509+
}
34633510
}
34643511

34653512
/**
@@ -3474,10 +3521,14 @@ int ice_read_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx, u64 *tstamp)
34743521
*/
34753522
int ice_clear_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx)
34763523
{
3477-
if (ice_is_e810(hw))
3524+
switch (hw->phy_model) {
3525+
case ICE_PHY_E810:
34783526
return ice_clear_phy_tstamp_e810(hw, block, idx);
3479-
else
3527+
case ICE_PHY_E822:
34803528
return ice_clear_phy_tstamp_e822(hw, block, idx);
3529+
default:
3530+
return -EOPNOTSUPP;
3531+
}
34813532
}
34823533

34833534
/**
@@ -3570,10 +3621,14 @@ int ice_get_pf_c827_idx(struct ice_hw *hw, u8 *idx)
35703621
*/
35713622
void ice_ptp_reset_ts_memory(struct ice_hw *hw)
35723623
{
3573-
if (ice_is_e810(hw))
3624+
switch (hw->phy_model) {
3625+
case ICE_PHY_E822:
3626+
ice_ptp_reset_ts_memory_e822(hw);
3627+
break;
3628+
case ICE_PHY_E810:
3629+
default:
35743630
return;
3575-
3576-
ice_ptp_reset_ts_memory_e822(hw);
3631+
}
35773632
}
35783633

35793634
/**
@@ -3592,10 +3647,14 @@ int ice_ptp_init_phc(struct ice_hw *hw)
35923647
/* Clear event err indications for auxiliary pins */
35933648
(void)rd32(hw, GLTSYN_STAT(src_idx));
35943649

3595-
if (ice_is_e810(hw))
3650+
switch (hw->phy_model) {
3651+
case ICE_PHY_E810:
35963652
return ice_ptp_init_phc_e810(hw);
3597-
else
3653+
case ICE_PHY_E822:
35983654
return ice_ptp_init_phc_e822(hw);
3655+
default:
3656+
return -EOPNOTSUPP;
3657+
}
35993658
}
36003659

36013660
/**
@@ -3611,12 +3670,17 @@ int ice_ptp_init_phc(struct ice_hw *hw)
36113670
*/
36123671
int ice_get_phy_tx_tstamp_ready(struct ice_hw *hw, u8 block, u64 *tstamp_ready)
36133672
{
3614-
if (ice_is_e810(hw))
3673+
switch (hw->phy_model) {
3674+
case ICE_PHY_E810:
36153675
return ice_get_phy_tx_tstamp_ready_e810(hw, block,
36163676
tstamp_ready);
3617-
else
3677+
case ICE_PHY_E822:
36183678
return ice_get_phy_tx_tstamp_ready_e822(hw, block,
36193679
tstamp_ready);
3680+
break;
3681+
default:
3682+
return -EOPNOTSUPP;
3683+
}
36203684
}
36213685

36223686
/**

drivers/net/ethernet/intel/ice/ice_ptp_hw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ int ice_get_cgu_state(struct ice_hw *hw, u8 dpll_idx,
285285
enum dpll_lock_status *dpll_state);
286286
int ice_get_cgu_rclk_pin_info(struct ice_hw *hw, u8 *base_idx, u8 *pin_num);
287287

288+
void ice_ptp_init_phy_model(struct ice_hw *hw);
289+
288290
#define PFTSYN_SEM_BYTES 4
289291

290292
#define ICE_PTP_CLOCK_INDEX_0 0x00

drivers/net/ethernet/intel/ice/ice_type.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,13 @@ struct ice_mbx_data {
822822
u16 async_watermark_val;
823823
};
824824

825+
/* PHY model */
826+
enum ice_phy_model {
827+
ICE_PHY_UNSUP = -1,
828+
ICE_PHY_E810 = 1,
829+
ICE_PHY_E822,
830+
};
831+
825832
/* Port hardware description */
826833
struct ice_hw {
827834
u8 __iomem *hw_addr;
@@ -843,6 +850,7 @@ struct ice_hw {
843850
u8 revision_id;
844851

845852
u8 pf_id; /* device profile info */
853+
enum ice_phy_model phy_model;
846854

847855
u16 max_burst_size; /* driver sets this value */
848856

0 commit comments

Comments
 (0)