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