@@ -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 */
24752527static 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/**
0 commit comments