Skip to content

Commit ebb2693

Browse files
yhagvianguy11
authored andcommitted
ice: Read SDP section from NVM for pin definitions
PTP pins assignment and their related SDPs (Software Definable Pins) are currently hardcoded. Fix that by reading NVM section instead on products supporting this, which are E810 products. If SDP section is not defined in NVM, the driver continues to use the hardcoded table. Reviewed-by: Arkadiusz Kubalewski <[email protected]> Signed-off-by: Yochai Hagvi <[email protected]> Co-developed-by: Karol Kolacinski <[email protected]> Signed-off-by: Karol Kolacinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Pucha Himasekhar Reddy <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent df0b394 commit ebb2693

File tree

5 files changed

+186
-28
lines changed

5 files changed

+186
-28
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,15 @@ struct ice_aqc_nvm {
17421742
};
17431743

17441744
#define ICE_AQC_NVM_START_POINT 0
1745+
#define ICE_AQC_NVM_SECTOR_UNIT 4096
1746+
#define ICE_AQC_NVM_SDP_AC_PTR_OFFSET 0xD8
1747+
#define ICE_AQC_NVM_SDP_AC_PTR_M GENMASK(14, 0)
1748+
#define ICE_AQC_NVM_SDP_AC_PTR_INVAL 0x7FFF
1749+
#define ICE_AQC_NVM_SDP_AC_PTR_TYPE_M BIT(15)
1750+
#define ICE_AQC_NVM_SDP_AC_SDP_NUM_M GENMASK(2, 0)
1751+
#define ICE_AQC_NVM_SDP_AC_DIR_M BIT(3)
1752+
#define ICE_AQC_NVM_SDP_AC_PIN_M GENMASK(15, 6)
1753+
#define ICE_AQC_NVM_SDP_AC_MAX_SIZE 7
17451754

17461755
#define ICE_AQC_NVM_TX_TOPO_MOD_ID 0x14B
17471756

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

Lines changed: 112 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ static const struct ice_ptp_pin_desc ice_pin_desc_e810[] = {
3939
{ ONE_PPS, { -1, 5 }},
4040
};
4141

42-
static const char ice_pin_names_e810t[][64] = {
42+
static const char ice_pin_names_nvm[][64] = {
4343
"GNSS",
4444
"SMA1",
4545
"U.FL1",
4646
"SMA2",
4747
"U.FL2",
4848
};
4949

50-
static const struct ice_ptp_pin_desc ice_pin_desc_e810t[] = {
50+
static const struct ice_ptp_pin_desc ice_pin_desc_e810_sma[] = {
5151
/* name, gpio */
5252
{ GNSS, { 1, -1 }},
5353
{ SMA1, { 1, 0 }},
@@ -2385,8 +2385,8 @@ static void ice_ptp_setup_pin_cfg(struct ice_pf *pf)
23852385

23862386
if (!ice_is_feature_supported(pf, ICE_F_SMA_CTRL))
23872387
name = ice_pin_names[desc->name_idx];
2388-
else
2389-
name = ice_pin_names_e810t[desc->name_idx];
2388+
else if (desc->name_idx != GPIO_NA)
2389+
name = ice_pin_names_nvm[desc->name_idx];
23902390
if (name)
23912391
strscpy(pin->name, name, sizeof(pin->name));
23922392

@@ -2397,17 +2397,17 @@ static void ice_ptp_setup_pin_cfg(struct ice_pf *pf)
23972397
}
23982398

23992399
/**
2400-
* ice_ptp_disable_sma_pins - Disable SMA pins
2400+
* ice_ptp_disable_pins - Disable PTP pins
24012401
* @pf: pointer to the PF structure
24022402
*
24032403
* Disable the OS access to the SMA pins. Called to clear out the OS
24042404
* indications of pin support when we fail to setup the SMA control register.
24052405
*/
2406-
static void ice_ptp_disable_sma_pins(struct ice_pf *pf)
2406+
static void ice_ptp_disable_pins(struct ice_pf *pf)
24072407
{
24082408
struct ptp_clock_info *info = &pf->ptp.info;
24092409

2410-
dev_warn(ice_pf_to_dev(pf), "Failed to configure SMA pin control\n");
2410+
dev_warn(ice_pf_to_dev(pf), "Failed to configure PTP pin control\n");
24112411

24122412
info->enable = NULL;
24132413
info->verify = NULL;
@@ -2417,23 +2417,75 @@ static void ice_ptp_disable_sma_pins(struct ice_pf *pf)
24172417
}
24182418

24192419
/**
2420-
* ice_ptp_setup_pins_e810t - Setup PTP pins in sysfs
2421-
* @pf: pointer to the PF instance
2420+
* ice_ptp_parse_sdp_entries - update ice_ptp_pin_desc structure from NVM
2421+
* @pf: pointer to the PF structure
2422+
* @entries: SDP connection section from NVM
2423+
* @num_entries: number of valid entries in sdp_entries
2424+
* @pins: PTP pins array to update
2425+
*
2426+
* Return: 0 on success, negative error code otherwise.
24222427
*/
2423-
static void ice_ptp_setup_pins_e810t(struct ice_pf *pf)
2428+
static int ice_ptp_parse_sdp_entries(struct ice_pf *pf, __le16 *entries,
2429+
unsigned int num_entries,
2430+
struct ice_ptp_pin_desc *pins)
24242431
{
2425-
struct ice_ptp *ptp = &pf->ptp;
2426-
int err;
2432+
unsigned int n_pins = 0;
2433+
unsigned int i;
24272434

2428-
ptp->ice_pin_desc = ice_pin_desc_e810t;
2429-
ptp->info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810t);
2430-
ptp->info.pin_config = ptp->pin_desc;
2431-
ice_ptp_setup_pin_cfg(pf);
2435+
/* Setup ice_pin_desc array */
2436+
for (i = 0; i < ICE_N_PINS_MAX; i++) {
2437+
pins[i].name_idx = -1;
2438+
pins[i].gpio[0] = -1;
2439+
pins[i].gpio[1] = -1;
2440+
}
2441+
2442+
for (i = 0; i < num_entries; i++) {
2443+
u16 entry = le16_to_cpu(entries[i]);
2444+
DECLARE_BITMAP(bitmap, GPIO_NA);
2445+
unsigned int bitmap_idx;
2446+
bool dir;
2447+
u16 gpio;
2448+
2449+
*bitmap = FIELD_GET(ICE_AQC_NVM_SDP_AC_PIN_M, entry);
2450+
dir = !!FIELD_GET(ICE_AQC_NVM_SDP_AC_DIR_M, entry);
2451+
gpio = FIELD_GET(ICE_AQC_NVM_SDP_AC_SDP_NUM_M, entry);
2452+
for_each_set_bit(bitmap_idx, bitmap, GPIO_NA + 1) {
2453+
unsigned int idx;
2454+
2455+
/* Check if entry's pin bit is valid */
2456+
if (bitmap_idx >= NUM_PTP_PINS_NVM &&
2457+
bitmap_idx != GPIO_NA)
2458+
continue;
24322459

2433-
/* Clear SMA status */
2434-
err = ice_ptp_set_sma_cfg(pf);
2435-
if (err)
2436-
ice_ptp_disable_sma_pins(pf);
2460+
/* Check if pin already exists */
2461+
for (idx = 0; idx < ICE_N_PINS_MAX; idx++)
2462+
if (pins[idx].name_idx == bitmap_idx)
2463+
break;
2464+
2465+
if (idx == ICE_N_PINS_MAX) {
2466+
/* Pin not found, setup its entry and name */
2467+
idx = n_pins++;
2468+
pins[idx].name_idx = bitmap_idx;
2469+
if (bitmap_idx == GPIO_NA)
2470+
strscpy(pf->ptp.pin_desc[idx].name,
2471+
ice_pin_names[gpio],
2472+
sizeof(pf->ptp.pin_desc[idx]
2473+
.name));
2474+
}
2475+
2476+
/* Setup in/out GPIO number */
2477+
pins[idx].gpio[dir] = gpio;
2478+
}
2479+
}
2480+
2481+
for (i = 0; i < n_pins; i++) {
2482+
dev_dbg(ice_pf_to_dev(pf),
2483+
"NVM pin entry[%d] : name_idx %d gpio_out %d gpio_in %d\n",
2484+
i, pins[i].name_idx, pins[i].gpio[1], pins[i].gpio[0]);
2485+
}
2486+
2487+
pf->ptp.info.n_pins = n_pins;
2488+
return 0;
24372489
}
24382490

24392491
/**
@@ -2474,15 +2526,49 @@ static void ice_ptp_set_funcs_e82x(struct ice_pf *pf)
24742526
*/
24752527
static void ice_ptp_set_funcs_e810(struct ice_pf *pf)
24762528
{
2477-
if (ice_is_e810t(&pf->hw) &&
2478-
ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) {
2479-
ice_ptp_setup_pins_e810t(pf);
2480-
return;
2529+
__le16 entries[ICE_AQC_NVM_SDP_AC_MAX_SIZE];
2530+
struct ice_ptp_pin_desc *desc = NULL;
2531+
struct ice_ptp *ptp = &pf->ptp;
2532+
unsigned int num_entries;
2533+
int err;
2534+
2535+
err = ice_ptp_read_sdp_ac(&pf->hw, entries, &num_entries);
2536+
if (err) {
2537+
/* SDP section does not exist in NVM or is corrupted */
2538+
if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) {
2539+
ptp->ice_pin_desc = ice_pin_desc_e810_sma;
2540+
ptp->info.n_pins =
2541+
ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810_sma);
2542+
} else {
2543+
pf->ptp.ice_pin_desc = ice_pin_desc_e810;
2544+
pf->ptp.info.n_pins =
2545+
ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810);
2546+
err = 0;
2547+
}
2548+
} else {
2549+
desc = devm_kcalloc(ice_pf_to_dev(pf), ICE_N_PINS_MAX,
2550+
sizeof(struct ice_ptp_pin_desc),
2551+
GFP_KERNEL);
2552+
if (!desc)
2553+
goto err;
2554+
2555+
err = ice_ptp_parse_sdp_entries(pf, entries, num_entries, desc);
2556+
if (err)
2557+
goto err;
2558+
2559+
ptp->ice_pin_desc = (const struct ice_ptp_pin_desc *)desc;
24812560
}
24822561

2483-
pf->ptp.ice_pin_desc = ice_pin_desc_e810;
2484-
pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810);
2562+
ptp->info.pin_config = ptp->pin_desc;
24852563
ice_ptp_setup_pin_cfg(pf);
2564+
2565+
if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL))
2566+
err = ice_ptp_set_sma_cfg(pf);
2567+
err:
2568+
if (err) {
2569+
devm_kfree(ice_pf_to_dev(pf), desc);
2570+
ice_ptp_disable_pins(pf);
2571+
}
24862572
}
24872573

24882574
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,14 @@ enum ice_ptp_pin {
199199
ONE_PPS
200200
};
201201

202-
enum ice_ptp_pin_e810t {
202+
enum ice_ptp_pin_nvm {
203203
GNSS = 0,
204204
SMA1,
205205
UFL1,
206206
SMA2,
207-
UFL2
207+
UFL2,
208+
NUM_PTP_PINS_NVM,
209+
GPIO_NA = 9
208210
};
209211

210212
/* Per-channel register definitions */

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5313,6 +5313,66 @@ int ice_read_pca9575_reg(struct ice_hw *hw, u8 offset, u8 *data)
53135313
return ice_aq_read_i2c(hw, link_topo, 0, addr, 1, data, NULL);
53145314
}
53155315

5316+
/**
5317+
* ice_ptp_read_sdp_ac - read SDP available connections section from NVM
5318+
* @hw: pointer to the HW struct
5319+
* @entries: returns the SDP available connections section from NVM
5320+
* @num_entries: returns the number of valid entries
5321+
*
5322+
* Return: 0 on success, negative error code if NVM read failed or section does
5323+
* not exist or is corrupted
5324+
*/
5325+
int ice_ptp_read_sdp_ac(struct ice_hw *hw, __le16 *entries, uint *num_entries)
5326+
{
5327+
__le16 data;
5328+
u32 offset;
5329+
int err;
5330+
5331+
err = ice_acquire_nvm(hw, ICE_RES_READ);
5332+
if (err)
5333+
goto exit;
5334+
5335+
/* Read the offset of SDP_AC */
5336+
offset = ICE_AQC_NVM_SDP_AC_PTR_OFFSET;
5337+
err = ice_aq_read_nvm(hw, 0, offset, sizeof(data), &data, false, true,
5338+
NULL);
5339+
if (err)
5340+
goto exit;
5341+
5342+
/* Check if section exist */
5343+
offset = FIELD_GET(ICE_AQC_NVM_SDP_AC_PTR_M, le16_to_cpu(data));
5344+
if (offset == ICE_AQC_NVM_SDP_AC_PTR_INVAL) {
5345+
err = -EINVAL;
5346+
goto exit;
5347+
}
5348+
5349+
if (offset & ICE_AQC_NVM_SDP_AC_PTR_TYPE_M) {
5350+
offset &= ICE_AQC_NVM_SDP_AC_PTR_M;
5351+
offset *= ICE_AQC_NVM_SECTOR_UNIT;
5352+
} else {
5353+
offset *= sizeof(data);
5354+
}
5355+
5356+
/* Skip reading section length and read the number of valid entries */
5357+
offset += sizeof(data);
5358+
err = ice_aq_read_nvm(hw, 0, offset, sizeof(data), &data, false, true,
5359+
NULL);
5360+
if (err)
5361+
goto exit;
5362+
*num_entries = le16_to_cpu(data);
5363+
5364+
/* Read SDP configuration section */
5365+
offset += sizeof(data);
5366+
err = ice_aq_read_nvm(hw, 0, offset, *num_entries * sizeof(data),
5367+
entries, false, true, NULL);
5368+
5369+
exit:
5370+
if (err)
5371+
dev_dbg(ice_hw_to_dev(hw), "Failed to configure SDP connection section\n");
5372+
ice_release_nvm(hw);
5373+
return err;
5374+
}
5375+
53165376
/**
53175377
* ice_ptp_init_phy_e810 - initialize PHY parameters
53185378
* @ptp: pointer to the PTP HW struct

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ int ice_read_sma_ctrl(struct ice_hw *hw, u8 *data);
405405
int ice_write_sma_ctrl(struct ice_hw *hw, u8 data);
406406
int ice_read_pca9575_reg(struct ice_hw *hw, u8 offset, u8 *data);
407407
bool ice_is_pca9575_present(struct ice_hw *hw);
408+
int ice_ptp_read_sdp_ac(struct ice_hw *hw, __le16 *entries, uint *num_entries);
408409
enum dpll_pin_type ice_cgu_get_pin_type(struct ice_hw *hw, u8 pin, bool input);
409410
struct dpll_pin_frequency *
410411
ice_cgu_get_pin_freq_supp(struct ice_hw *hw, u8 pin, bool input, u8 *num);

0 commit comments

Comments
 (0)