@@ -39,15 +39,15 @@ static const struct ice_ptp_pin_desc ice_pin_desc_e810[] = {
39
39
{ ONE_PPS , { -1 , 5 }},
40
40
};
41
41
42
- static const char ice_pin_names_e810t [][64 ] = {
42
+ static const char ice_pin_names_nvm [][64 ] = {
43
43
"GNSS" ,
44
44
"SMA1" ,
45
45
"U.FL1" ,
46
46
"SMA2" ,
47
47
"U.FL2" ,
48
48
};
49
49
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 [] = {
51
51
/* name, gpio */
52
52
{ GNSS , { 1 , -1 }},
53
53
{ SMA1 , { 1 , 0 }},
@@ -2385,8 +2385,8 @@ static void ice_ptp_setup_pin_cfg(struct ice_pf *pf)
2385
2385
2386
2386
if (!ice_is_feature_supported (pf , ICE_F_SMA_CTRL ))
2387
2387
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 ];
2390
2390
if (name )
2391
2391
strscpy (pin -> name , name , sizeof (pin -> name ));
2392
2392
@@ -2397,17 +2397,17 @@ static void ice_ptp_setup_pin_cfg(struct ice_pf *pf)
2397
2397
}
2398
2398
2399
2399
/**
2400
- * ice_ptp_disable_sma_pins - Disable SMA pins
2400
+ * ice_ptp_disable_pins - Disable PTP pins
2401
2401
* @pf: pointer to the PF structure
2402
2402
*
2403
2403
* Disable the OS access to the SMA pins. Called to clear out the OS
2404
2404
* indications of pin support when we fail to setup the SMA control register.
2405
2405
*/
2406
- static void ice_ptp_disable_sma_pins (struct ice_pf * pf )
2406
+ static void ice_ptp_disable_pins (struct ice_pf * pf )
2407
2407
{
2408
2408
struct ptp_clock_info * info = & pf -> ptp .info ;
2409
2409
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" );
2411
2411
2412
2412
info -> enable = NULL ;
2413
2413
info -> verify = NULL ;
@@ -2417,23 +2417,75 @@ static void ice_ptp_disable_sma_pins(struct ice_pf *pf)
2417
2417
}
2418
2418
2419
2419
/**
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.
2422
2427
*/
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 )
2424
2431
{
2425
- struct ice_ptp * ptp = & pf -> ptp ;
2426
- int err ;
2432
+ unsigned int n_pins = 0 ;
2433
+ unsigned int i ;
2427
2434
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 ;
2432
2459
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 ;
2437
2489
}
2438
2490
2439
2491
/**
@@ -2474,15 +2526,49 @@ static void ice_ptp_set_funcs_e82x(struct ice_pf *pf)
2474
2526
*/
2475
2527
static void ice_ptp_set_funcs_e810 (struct ice_pf * pf )
2476
2528
{
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 ;
2481
2560
}
2482
2561
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 ;
2485
2563
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
+ }
2486
2572
}
2487
2573
2488
2574
/**
0 commit comments