@@ -23,6 +23,14 @@ struct mlxsw_hwmon_attr {
2323 char name [32 ];
2424};
2525
26+ static int mlxsw_hwmon_get_attr_index (int index , int count )
27+ {
28+ if (index >= count )
29+ return index % count + MLXSW_REG_MTMP_GBOX_INDEX_MIN ;
30+
31+ return index ;
32+ }
33+
2634struct mlxsw_hwmon {
2735 struct mlxsw_core * core ;
2836 const struct mlxsw_bus_info * bus_info ;
@@ -33,6 +41,7 @@ struct mlxsw_hwmon {
3341 struct mlxsw_hwmon_attr hwmon_attrs [MLXSW_HWMON_ATTR_COUNT ];
3442 unsigned int attrs_count ;
3543 u8 sensor_count ;
44+ u8 module_sensor_count ;
3645};
3746
3847static ssize_t mlxsw_hwmon_temp_show (struct device * dev ,
@@ -44,10 +53,12 @@ static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
4453 struct mlxsw_hwmon * mlxsw_hwmon = mlwsw_hwmon_attr -> hwmon ;
4554 char mtmp_pl [MLXSW_REG_MTMP_LEN ];
4655 unsigned int temp ;
56+ int index ;
4757 int err ;
4858
49- mlxsw_reg_mtmp_pack (mtmp_pl , mlwsw_hwmon_attr -> type_index ,
50- false, false);
59+ index = mlxsw_hwmon_get_attr_index (mlwsw_hwmon_attr -> type_index ,
60+ mlxsw_hwmon -> module_sensor_count );
61+ mlxsw_reg_mtmp_pack (mtmp_pl , index , false, false);
5162 err = mlxsw_reg_query (mlxsw_hwmon -> core , MLXSW_REG (mtmp ), mtmp_pl );
5263 if (err ) {
5364 dev_err (mlxsw_hwmon -> bus_info -> dev , "Failed to query temp sensor\n" );
@@ -66,10 +77,12 @@ static ssize_t mlxsw_hwmon_temp_max_show(struct device *dev,
6677 struct mlxsw_hwmon * mlxsw_hwmon = mlwsw_hwmon_attr -> hwmon ;
6778 char mtmp_pl [MLXSW_REG_MTMP_LEN ];
6879 unsigned int temp_max ;
80+ int index ;
6981 int err ;
7082
71- mlxsw_reg_mtmp_pack (mtmp_pl , mlwsw_hwmon_attr -> type_index ,
72- false, false);
83+ index = mlxsw_hwmon_get_attr_index (mlwsw_hwmon_attr -> type_index ,
84+ mlxsw_hwmon -> module_sensor_count );
85+ mlxsw_reg_mtmp_pack (mtmp_pl , index , false, false);
7386 err = mlxsw_reg_query (mlxsw_hwmon -> core , MLXSW_REG (mtmp ), mtmp_pl );
7487 if (err ) {
7588 dev_err (mlxsw_hwmon -> bus_info -> dev , "Failed to query temp sensor\n" );
@@ -88,6 +101,7 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
88101 struct mlxsw_hwmon * mlxsw_hwmon = mlwsw_hwmon_attr -> hwmon ;
89102 char mtmp_pl [MLXSW_REG_MTMP_LEN ];
90103 unsigned long val ;
104+ int index ;
91105 int err ;
92106
93107 err = kstrtoul (buf , 10 , & val );
@@ -96,7 +110,9 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
96110 if (val != 1 )
97111 return - EINVAL ;
98112
99- mlxsw_reg_mtmp_pack (mtmp_pl , mlwsw_hwmon_attr -> type_index , true, true);
113+ index = mlxsw_hwmon_get_attr_index (mlwsw_hwmon_attr -> type_index ,
114+ mlxsw_hwmon -> module_sensor_count );
115+ mlxsw_reg_mtmp_pack (mtmp_pl , index , true, true);
100116 err = mlxsw_reg_write (mlxsw_hwmon -> core , MLXSW_REG (mtmp ), mtmp_pl );
101117 if (err ) {
102118 dev_err (mlxsw_hwmon -> bus_info -> dev , "Failed to reset temp sensor history\n" );
@@ -333,6 +349,20 @@ mlxsw_hwmon_module_temp_label_show(struct device *dev,
333349 mlwsw_hwmon_attr -> type_index );
334350}
335351
352+ static ssize_t
353+ mlxsw_hwmon_gbox_temp_label_show (struct device * dev ,
354+ struct device_attribute * attr ,
355+ char * buf )
356+ {
357+ struct mlxsw_hwmon_attr * mlwsw_hwmon_attr =
358+ container_of (attr , struct mlxsw_hwmon_attr , dev_attr );
359+ struct mlxsw_hwmon * mlxsw_hwmon = mlwsw_hwmon_attr -> hwmon ;
360+ int index = mlwsw_hwmon_attr -> type_index -
361+ mlxsw_hwmon -> module_sensor_count + 1 ;
362+
363+ return sprintf (buf , "gearbox %03u\n" , index );
364+ }
365+
336366enum mlxsw_hwmon_attr_type {
337367 MLXSW_HWMON_ATTR_TYPE_TEMP ,
338368 MLXSW_HWMON_ATTR_TYPE_TEMP_MAX ,
@@ -345,6 +375,7 @@ enum mlxsw_hwmon_attr_type {
345375 MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT ,
346376 MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG ,
347377 MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL ,
378+ MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL ,
348379};
349380
350381static void mlxsw_hwmon_attr_add (struct mlxsw_hwmon * mlxsw_hwmon ,
@@ -428,6 +459,13 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
428459 snprintf (mlxsw_hwmon_attr -> name , sizeof (mlxsw_hwmon_attr -> name ),
429460 "temp%u_label" , num + 1 );
430461 break ;
462+ case MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL :
463+ mlxsw_hwmon_attr -> dev_attr .show =
464+ mlxsw_hwmon_gbox_temp_label_show ;
465+ mlxsw_hwmon_attr -> dev_attr .attr .mode = 0444 ;
466+ snprintf (mlxsw_hwmon_attr -> name , sizeof (mlxsw_hwmon_attr -> name ),
467+ "temp%u_label" , num + 1 );
468+ break ;
431469 default :
432470 WARN_ON (1 );
433471 }
@@ -556,6 +594,54 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
556594 index , index );
557595 index ++ ;
558596 }
597+ mlxsw_hwmon -> module_sensor_count = index ;
598+
599+ return 0 ;
600+ }
601+
602+ static int mlxsw_hwmon_gearbox_init (struct mlxsw_hwmon * mlxsw_hwmon )
603+ {
604+ int index , max_index , sensor_index ;
605+ char mgpir_pl [MLXSW_REG_MGPIR_LEN ];
606+ char mtmp_pl [MLXSW_REG_MTMP_LEN ];
607+ u8 gbox_num ;
608+ int err ;
609+
610+ mlxsw_reg_mgpir_pack (mgpir_pl );
611+ err = mlxsw_reg_query (mlxsw_hwmon -> core , MLXSW_REG (mgpir ), mgpir_pl );
612+ if (err )
613+ return err ;
614+
615+ mlxsw_reg_mgpir_unpack (mgpir_pl , & gbox_num , NULL , NULL );
616+ if (!gbox_num )
617+ return 0 ;
618+
619+ index = mlxsw_hwmon -> module_sensor_count ;
620+ max_index = mlxsw_hwmon -> module_sensor_count + gbox_num ;
621+ while (index < max_index ) {
622+ sensor_index = index % mlxsw_hwmon -> module_sensor_count +
623+ MLXSW_REG_MTMP_GBOX_INDEX_MIN ;
624+ mlxsw_reg_mtmp_pack (mtmp_pl , sensor_index , true, true);
625+ err = mlxsw_reg_write (mlxsw_hwmon -> core ,
626+ MLXSW_REG (mtmp ), mtmp_pl );
627+ if (err ) {
628+ dev_err (mlxsw_hwmon -> bus_info -> dev , "Failed to setup temp sensor number %d\n" ,
629+ sensor_index );
630+ return err ;
631+ }
632+ mlxsw_hwmon_attr_add (mlxsw_hwmon , MLXSW_HWMON_ATTR_TYPE_TEMP ,
633+ index , index );
634+ mlxsw_hwmon_attr_add (mlxsw_hwmon ,
635+ MLXSW_HWMON_ATTR_TYPE_TEMP_MAX , index ,
636+ index );
637+ mlxsw_hwmon_attr_add (mlxsw_hwmon ,
638+ MLXSW_HWMON_ATTR_TYPE_TEMP_RST , index ,
639+ index );
640+ mlxsw_hwmon_attr_add (mlxsw_hwmon ,
641+ MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL ,
642+ index , index );
643+ index ++ ;
644+ }
559645
560646 return 0 ;
561647}
@@ -586,6 +672,10 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
586672 if (err )
587673 goto err_temp_module_init ;
588674
675+ err = mlxsw_hwmon_gearbox_init (mlxsw_hwmon );
676+ if (err )
677+ goto err_temp_gearbox_init ;
678+
589679 mlxsw_hwmon -> groups [0 ] = & mlxsw_hwmon -> group ;
590680 mlxsw_hwmon -> group .attrs = mlxsw_hwmon -> attrs ;
591681
@@ -602,6 +692,7 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
602692 return 0 ;
603693
604694err_hwmon_register :
695+ err_temp_gearbox_init :
605696err_temp_module_init :
606697err_fans_init :
607698err_temp_init :
0 commit comments