Skip to content

Commit 14304d3

Browse files
committed
ice: Read SDP section from NVM for pin definitions
JIRA: https://issues.redhat.com/browse/RHEL-29207 Conflicts: - adjusted context conflict in ice_ptp_hw.h due to already applied 6e58c33 ("ice: fix crash on probe for DPLL enabled E810 LOM") Upstream commit(s): commit ebb2693 Author: Yochai Hagvi <yochai.hagvi@intel.com> Date: Fri Aug 30 13:07:22 2024 +0200 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 <arkadiusz.kubalewski@intel.com> Signed-off-by: Yochai Hagvi <yochai.hagvi@intel.com> Co-developed-by: Karol Kolacinski <karol.kolacinski@intel.com> Signed-off-by: Karol Kolacinski <karol.kolacinski@intel.com> Reviewed-by: Simon Horman <horms@kernel.org> 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> Signed-off-by: Petr Oros <poros@redhat.com>
1 parent c5ca120 commit 14304d3

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
@@ -1743,6 +1743,15 @@ struct ice_aqc_nvm {
17431743
};
17441744

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

17471756
#define ICE_AQC_NVM_TX_TOPO_MOD_ID 0x14B
17481757

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 }},
@@ -2403,8 +2403,8 @@ static void ice_ptp_setup_pin_cfg(struct ice_pf *pf)
24032403

24042404
if (!ice_is_feature_supported(pf, ICE_F_SMA_CTRL))
24052405
name = ice_pin_names[desc->name_idx];
2406-
else
2407-
name = ice_pin_names_e810t[desc->name_idx];
2406+
else if (desc->name_idx != GPIO_NA)
2407+
name = ice_pin_names_nvm[desc->name_idx];
24082408
if (name)
24092409
strscpy(pin->name, name, sizeof(pin->name));
24102410

@@ -2415,17 +2415,17 @@ static void ice_ptp_setup_pin_cfg(struct ice_pf *pf)
24152415
}
24162416

24172417
/**
2418-
* ice_ptp_disable_sma_pins - Disable SMA pins
2418+
* ice_ptp_disable_pins - Disable PTP pins
24192419
* @pf: pointer to the PF structure
24202420
*
24212421
* Disable the OS access to the SMA pins. Called to clear out the OS
24222422
* indications of pin support when we fail to setup the SMA control register.
24232423
*/
2424-
static void ice_ptp_disable_sma_pins(struct ice_pf *pf)
2424+
static void ice_ptp_disable_pins(struct ice_pf *pf)
24252425
{
24262426
struct ptp_clock_info *info = &pf->ptp.info;
24272427

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

24302430
info->enable = NULL;
24312431
info->verify = NULL;
@@ -2435,23 +2435,75 @@ static void ice_ptp_disable_sma_pins(struct ice_pf *pf)
24352435
}
24362436

24372437
/**
2438-
* ice_ptp_setup_pins_e810t - Setup PTP pins in sysfs
2439-
* @pf: pointer to the PF instance
2438+
* ice_ptp_parse_sdp_entries - update ice_ptp_pin_desc structure from NVM
2439+
* @pf: pointer to the PF structure
2440+
* @entries: SDP connection section from NVM
2441+
* @num_entries: number of valid entries in sdp_entries
2442+
* @pins: PTP pins array to update
2443+
*
2444+
* Return: 0 on success, negative error code otherwise.
24402445
*/
2441-
static void ice_ptp_setup_pins_e810t(struct ice_pf *pf)
2446+
static int ice_ptp_parse_sdp_entries(struct ice_pf *pf, __le16 *entries,
2447+
unsigned int num_entries,
2448+
struct ice_ptp_pin_desc *pins)
24422449
{
2443-
struct ice_ptp *ptp = &pf->ptp;
2444-
int err;
2450+
unsigned int n_pins = 0;
2451+
unsigned int i;
24452452

2446-
ptp->ice_pin_desc = ice_pin_desc_e810t;
2447-
ptp->info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810t);
2448-
ptp->info.pin_config = ptp->pin_desc;
2449-
ice_ptp_setup_pin_cfg(pf);
2453+
/* Setup ice_pin_desc array */
2454+
for (i = 0; i < ICE_N_PINS_MAX; i++) {
2455+
pins[i].name_idx = -1;
2456+
pins[i].gpio[0] = -1;
2457+
pins[i].gpio[1] = -1;
2458+
}
2459+
2460+
for (i = 0; i < num_entries; i++) {
2461+
u16 entry = le16_to_cpu(entries[i]);
2462+
DECLARE_BITMAP(bitmap, GPIO_NA);
2463+
unsigned int bitmap_idx;
2464+
bool dir;
2465+
u16 gpio;
2466+
2467+
*bitmap = FIELD_GET(ICE_AQC_NVM_SDP_AC_PIN_M, entry);
2468+
dir = !!FIELD_GET(ICE_AQC_NVM_SDP_AC_DIR_M, entry);
2469+
gpio = FIELD_GET(ICE_AQC_NVM_SDP_AC_SDP_NUM_M, entry);
2470+
for_each_set_bit(bitmap_idx, bitmap, GPIO_NA + 1) {
2471+
unsigned int idx;
2472+
2473+
/* Check if entry's pin bit is valid */
2474+
if (bitmap_idx >= NUM_PTP_PINS_NVM &&
2475+
bitmap_idx != GPIO_NA)
2476+
continue;
24502477

2451-
/* Clear SMA status */
2452-
err = ice_ptp_set_sma_cfg(pf);
2453-
if (err)
2454-
ice_ptp_disable_sma_pins(pf);
2478+
/* Check if pin already exists */
2479+
for (idx = 0; idx < ICE_N_PINS_MAX; idx++)
2480+
if (pins[idx].name_idx == bitmap_idx)
2481+
break;
2482+
2483+
if (idx == ICE_N_PINS_MAX) {
2484+
/* Pin not found, setup its entry and name */
2485+
idx = n_pins++;
2486+
pins[idx].name_idx = bitmap_idx;
2487+
if (bitmap_idx == GPIO_NA)
2488+
strscpy(pf->ptp.pin_desc[idx].name,
2489+
ice_pin_names[gpio],
2490+
sizeof(pf->ptp.pin_desc[idx]
2491+
.name));
2492+
}
2493+
2494+
/* Setup in/out GPIO number */
2495+
pins[idx].gpio[dir] = gpio;
2496+
}
2497+
}
2498+
2499+
for (i = 0; i < n_pins; i++) {
2500+
dev_dbg(ice_pf_to_dev(pf),
2501+
"NVM pin entry[%d] : name_idx %d gpio_out %d gpio_in %d\n",
2502+
i, pins[i].name_idx, pins[i].gpio[1], pins[i].gpio[0]);
2503+
}
2504+
2505+
pf->ptp.info.n_pins = n_pins;
2506+
return 0;
24552507
}
24562508

24572509
/**
@@ -2492,15 +2544,49 @@ static void ice_ptp_set_funcs_e82x(struct ice_pf *pf)
24922544
*/
24932545
static void ice_ptp_set_funcs_e810(struct ice_pf *pf)
24942546
{
2495-
if (ice_is_e810t(&pf->hw) &&
2496-
ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) {
2497-
ice_ptp_setup_pins_e810t(pf);
2498-
return;
2547+
__le16 entries[ICE_AQC_NVM_SDP_AC_MAX_SIZE];
2548+
struct ice_ptp_pin_desc *desc = NULL;
2549+
struct ice_ptp *ptp = &pf->ptp;
2550+
unsigned int num_entries;
2551+
int err;
2552+
2553+
err = ice_ptp_read_sdp_ac(&pf->hw, entries, &num_entries);
2554+
if (err) {
2555+
/* SDP section does not exist in NVM or is corrupted */
2556+
if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) {
2557+
ptp->ice_pin_desc = ice_pin_desc_e810_sma;
2558+
ptp->info.n_pins =
2559+
ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810_sma);
2560+
} else {
2561+
pf->ptp.ice_pin_desc = ice_pin_desc_e810;
2562+
pf->ptp.info.n_pins =
2563+
ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810);
2564+
err = 0;
2565+
}
2566+
} else {
2567+
desc = devm_kcalloc(ice_pf_to_dev(pf), ICE_N_PINS_MAX,
2568+
sizeof(struct ice_ptp_pin_desc),
2569+
GFP_KERNEL);
2570+
if (!desc)
2571+
goto err;
2572+
2573+
err = ice_ptp_parse_sdp_entries(pf, entries, num_entries, desc);
2574+
if (err)
2575+
goto err;
2576+
2577+
ptp->ice_pin_desc = (const struct ice_ptp_pin_desc *)desc;
24992578
}
25002579

2501-
pf->ptp.ice_pin_desc = ice_pin_desc_e810;
2502-
pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810);
2580+
ptp->info.pin_config = ptp->pin_desc;
25032581
ice_ptp_setup_pin_cfg(pf);
2582+
2583+
if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL))
2584+
err = ice_ptp_set_sma_cfg(pf);
2585+
err:
2586+
if (err) {
2587+
devm_kfree(ice_pf_to_dev(pf), desc);
2588+
ice_ptp_disable_pins(pf);
2589+
}
25042590
}
25052591

25062592
/**

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
@@ -5448,6 +5448,66 @@ int ice_read_pca9575_reg(struct ice_hw *hw, u8 offset, u8 *data)
54485448
return ice_aq_read_i2c(hw, link_topo, 0, addr, 1, data, NULL);
54495449
}
54505450

5451+
/**
5452+
* ice_ptp_read_sdp_ac - read SDP available connections section from NVM
5453+
* @hw: pointer to the HW struct
5454+
* @entries: returns the SDP available connections section from NVM
5455+
* @num_entries: returns the number of valid entries
5456+
*
5457+
* Return: 0 on success, negative error code if NVM read failed or section does
5458+
* not exist or is corrupted
5459+
*/
5460+
int ice_ptp_read_sdp_ac(struct ice_hw *hw, __le16 *entries, uint *num_entries)
5461+
{
5462+
__le16 data;
5463+
u32 offset;
5464+
int err;
5465+
5466+
err = ice_acquire_nvm(hw, ICE_RES_READ);
5467+
if (err)
5468+
goto exit;
5469+
5470+
/* Read the offset of SDP_AC */
5471+
offset = ICE_AQC_NVM_SDP_AC_PTR_OFFSET;
5472+
err = ice_aq_read_nvm(hw, 0, offset, sizeof(data), &data, false, true,
5473+
NULL);
5474+
if (err)
5475+
goto exit;
5476+
5477+
/* Check if section exist */
5478+
offset = FIELD_GET(ICE_AQC_NVM_SDP_AC_PTR_M, le16_to_cpu(data));
5479+
if (offset == ICE_AQC_NVM_SDP_AC_PTR_INVAL) {
5480+
err = -EINVAL;
5481+
goto exit;
5482+
}
5483+
5484+
if (offset & ICE_AQC_NVM_SDP_AC_PTR_TYPE_M) {
5485+
offset &= ICE_AQC_NVM_SDP_AC_PTR_M;
5486+
offset *= ICE_AQC_NVM_SECTOR_UNIT;
5487+
} else {
5488+
offset *= sizeof(data);
5489+
}
5490+
5491+
/* Skip reading section length and read the number of valid entries */
5492+
offset += sizeof(data);
5493+
err = ice_aq_read_nvm(hw, 0, offset, sizeof(data), &data, false, true,
5494+
NULL);
5495+
if (err)
5496+
goto exit;
5497+
*num_entries = le16_to_cpu(data);
5498+
5499+
/* Read SDP configuration section */
5500+
offset += sizeof(data);
5501+
err = ice_aq_read_nvm(hw, 0, offset, *num_entries * sizeof(data),
5502+
entries, false, true, NULL);
5503+
5504+
exit:
5505+
if (err)
5506+
dev_dbg(ice_hw_to_dev(hw), "Failed to configure SDP connection section\n");
5507+
ice_release_nvm(hw);
5508+
return err;
5509+
}
5510+
54515511
/**
54525512
* ice_ptp_init_phy_e810 - initialize PHY parameters
54535513
* @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
@@ -404,6 +404,7 @@ int ice_phy_cfg_intr_e82x(struct ice_hw *hw, u8 quad, bool ena, u8 threshold);
404404
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);
407+
int ice_ptp_read_sdp_ac(struct ice_hw *hw, __le16 *entries, uint *num_entries);
407408
int ice_cgu_get_num_pins(struct ice_hw *hw, bool input);
408409
enum dpll_pin_type ice_cgu_get_pin_type(struct ice_hw *hw, u8 pin, bool input);
409410
struct dpll_pin_frequency *

0 commit comments

Comments
 (0)