@@ -82,6 +82,15 @@ struct mlxsw_thermal_module {
82
82
struct thermal_zone_device * tzdev ;
83
83
struct mlxsw_thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
84
84
int module ; /* Module or gearbox number */
85
+ u8 slot_index ;
86
+ };
87
+
88
+ struct mlxsw_thermal_area {
89
+ struct mlxsw_thermal_module * tz_module_arr ;
90
+ u8 tz_module_num ;
91
+ struct mlxsw_thermal_module * tz_gearbox_arr ;
92
+ u8 tz_gearbox_num ;
93
+ u8 slot_index ;
85
94
};
86
95
87
96
struct mlxsw_thermal {
@@ -92,12 +101,9 @@ struct mlxsw_thermal {
92
101
struct thermal_cooling_device * cdevs [MLXSW_MFCR_PWMS_MAX ];
93
102
u8 cooling_levels [MLXSW_THERMAL_MAX_STATE + 1 ];
94
103
struct mlxsw_thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
95
- struct mlxsw_thermal_module * tz_module_arr ;
96
- u8 tz_module_num ;
97
- struct mlxsw_thermal_module * tz_gearbox_arr ;
98
- u8 tz_gearbox_num ;
99
104
unsigned int tz_highest_score ;
100
105
struct thermal_zone_device * tz_highest_dev ;
106
+ struct mlxsw_thermal_area line_cards [];
101
107
};
102
108
103
109
static inline u8 mlxsw_state_to_duty (int state )
@@ -150,13 +156,15 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
150
156
* EEPROM if we got valid thresholds from MTMP.
151
157
*/
152
158
if (!emerg_temp || !crit_temp ) {
153
- err = mlxsw_env_module_temp_thresholds_get (core , 0 , tz -> module ,
159
+ err = mlxsw_env_module_temp_thresholds_get (core , tz -> slot_index ,
160
+ tz -> module ,
154
161
SFP_TEMP_HIGH_WARN ,
155
162
& crit_temp );
156
163
if (err )
157
164
return err ;
158
165
159
- err = mlxsw_env_module_temp_thresholds_get (core , 0 , tz -> module ,
166
+ err = mlxsw_env_module_temp_thresholds_get (core , tz -> slot_index ,
167
+ tz -> module ,
160
168
SFP_TEMP_HIGH_ALARM ,
161
169
& emerg_temp );
162
170
if (err )
@@ -423,15 +431,16 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
423
431
424
432
static void
425
433
mlxsw_thermal_module_temp_and_thresholds_get (struct mlxsw_core * core ,
426
- u16 sensor_index , int * p_temp ,
427
- int * p_crit_temp ,
434
+ u8 slot_index , u16 sensor_index ,
435
+ int * p_temp , int * p_crit_temp ,
428
436
int * p_emerg_temp )
429
437
{
430
438
char mtmp_pl [MLXSW_REG_MTMP_LEN ];
431
439
int err ;
432
440
433
441
/* Read module temperature and thresholds. */
434
- mlxsw_reg_mtmp_pack (mtmp_pl , 0 , sensor_index , false, false);
442
+ mlxsw_reg_mtmp_pack (mtmp_pl , slot_index , sensor_index ,
443
+ false, false);
435
444
err = mlxsw_reg_query (core , MLXSW_REG (mtmp ), mtmp_pl );
436
445
if (err ) {
437
446
/* Set temperature and thresholds to zero to avoid passing
@@ -462,6 +471,7 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
462
471
463
472
/* Read module temperature and thresholds. */
464
473
mlxsw_thermal_module_temp_and_thresholds_get (thermal -> core ,
474
+ tz -> slot_index ,
465
475
sensor_index , & temp ,
466
476
& crit_temp , & emerg_temp );
467
477
* p_temp = temp ;
@@ -576,7 +586,7 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
576
586
int err ;
577
587
578
588
index = MLXSW_REG_MTMP_GBOX_INDEX_MIN + tz -> module ;
579
- mlxsw_reg_mtmp_pack (mtmp_pl , 0 , index , false, false);
589
+ mlxsw_reg_mtmp_pack (mtmp_pl , tz -> slot_index , index , false, false);
580
590
581
591
err = mlxsw_reg_query (thermal -> core , MLXSW_REG (mtmp ), mtmp_pl );
582
592
if (err )
@@ -704,25 +714,28 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
704
714
705
715
static int
706
716
mlxsw_thermal_module_init (struct device * dev , struct mlxsw_core * core ,
707
- struct mlxsw_thermal * thermal , u8 module )
717
+ struct mlxsw_thermal * thermal ,
718
+ struct mlxsw_thermal_area * area , u8 module )
708
719
{
709
720
struct mlxsw_thermal_module * module_tz ;
710
721
int dummy_temp , crit_temp , emerg_temp ;
711
722
u16 sensor_index ;
712
723
713
724
sensor_index = MLXSW_REG_MTMP_MODULE_INDEX_MIN + module ;
714
- module_tz = & thermal -> tz_module_arr [module ];
725
+ module_tz = & area -> tz_module_arr [module ];
715
726
/* Skip if parent is already set (case of port split). */
716
727
if (module_tz -> parent )
717
728
return 0 ;
718
729
module_tz -> module = module ;
730
+ module_tz -> slot_index = area -> slot_index ;
719
731
module_tz -> parent = thermal ;
720
732
memcpy (module_tz -> trips , default_thermal_trips ,
721
733
sizeof (thermal -> trips ));
722
734
/* Initialize all trip point. */
723
735
mlxsw_thermal_module_trips_reset (module_tz );
724
736
/* Read module temperature and thresholds. */
725
- mlxsw_thermal_module_temp_and_thresholds_get (core , sensor_index , & dummy_temp ,
737
+ mlxsw_thermal_module_temp_and_thresholds_get (core , area -> slot_index ,
738
+ sensor_index , & dummy_temp ,
726
739
& crit_temp , & emerg_temp );
727
740
/* Update trip point according to the module data. */
728
741
return mlxsw_thermal_module_trips_update (dev , core , module_tz ,
@@ -740,34 +753,39 @@ static void mlxsw_thermal_module_fini(struct mlxsw_thermal_module *module_tz)
740
753
741
754
static int
742
755
mlxsw_thermal_modules_init (struct device * dev , struct mlxsw_core * core ,
743
- struct mlxsw_thermal * thermal )
756
+ struct mlxsw_thermal * thermal ,
757
+ struct mlxsw_thermal_area * area )
744
758
{
745
759
struct mlxsw_thermal_module * module_tz ;
746
760
char mgpir_pl [MLXSW_REG_MGPIR_LEN ];
747
761
int i , err ;
748
762
749
- mlxsw_reg_mgpir_pack (mgpir_pl , 0 );
763
+ mlxsw_reg_mgpir_pack (mgpir_pl , area -> slot_index );
750
764
err = mlxsw_reg_query (core , MLXSW_REG (mgpir ), mgpir_pl );
751
765
if (err )
752
766
return err ;
753
767
754
768
mlxsw_reg_mgpir_unpack (mgpir_pl , NULL , NULL , NULL ,
755
- & thermal -> tz_module_num , NULL );
769
+ & area -> tz_module_num , NULL );
756
770
757
- thermal -> tz_module_arr = kcalloc (thermal -> tz_module_num ,
758
- sizeof (* thermal -> tz_module_arr ),
759
- GFP_KERNEL );
760
- if (!thermal -> tz_module_arr )
771
+ /* For modular system module counter could be zero. */
772
+ if (!area -> tz_module_num )
773
+ return 0 ;
774
+
775
+ area -> tz_module_arr = kcalloc (area -> tz_module_num ,
776
+ sizeof (* area -> tz_module_arr ),
777
+ GFP_KERNEL );
778
+ if (!area -> tz_module_arr )
761
779
return - ENOMEM ;
762
780
763
- for (i = 0 ; i < thermal -> tz_module_num ; i ++ ) {
764
- err = mlxsw_thermal_module_init (dev , core , thermal , i );
781
+ for (i = 0 ; i < area -> tz_module_num ; i ++ ) {
782
+ err = mlxsw_thermal_module_init (dev , core , thermal , area , i );
765
783
if (err )
766
784
goto err_thermal_module_init ;
767
785
}
768
786
769
- for (i = 0 ; i < thermal -> tz_module_num ; i ++ ) {
770
- module_tz = & thermal -> tz_module_arr [i ];
787
+ for (i = 0 ; i < area -> tz_module_num ; i ++ ) {
788
+ module_tz = & area -> tz_module_arr [i ];
771
789
if (!module_tz -> parent )
772
790
continue ;
773
791
err = mlxsw_thermal_module_tz_init (module_tz );
@@ -779,20 +797,21 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
779
797
780
798
err_thermal_module_tz_init :
781
799
err_thermal_module_init :
782
- for (i = thermal -> tz_module_num - 1 ; i >= 0 ; i -- )
783
- mlxsw_thermal_module_fini (& thermal -> tz_module_arr [i ]);
784
- kfree (thermal -> tz_module_arr );
800
+ for (i = area -> tz_module_num - 1 ; i >= 0 ; i -- )
801
+ mlxsw_thermal_module_fini (& area -> tz_module_arr [i ]);
802
+ kfree (area -> tz_module_arr );
785
803
return err ;
786
804
}
787
805
788
806
static void
789
- mlxsw_thermal_modules_fini (struct mlxsw_thermal * thermal )
807
+ mlxsw_thermal_modules_fini (struct mlxsw_thermal * thermal ,
808
+ struct mlxsw_thermal_area * area )
790
809
{
791
810
int i ;
792
811
793
- for (i = thermal -> tz_module_num - 1 ; i >= 0 ; i -- )
794
- mlxsw_thermal_module_fini (& thermal -> tz_module_arr [i ]);
795
- kfree (thermal -> tz_module_arr );
812
+ for (i = area -> tz_module_num - 1 ; i >= 0 ; i -- )
813
+ mlxsw_thermal_module_fini (& area -> tz_module_arr [i ]);
814
+ kfree (area -> tz_module_arr );
796
815
}
797
816
798
817
static int
@@ -828,7 +847,8 @@ mlxsw_thermal_gearbox_tz_fini(struct mlxsw_thermal_module *gearbox_tz)
828
847
829
848
static int
830
849
mlxsw_thermal_gearboxes_init (struct device * dev , struct mlxsw_core * core ,
831
- struct mlxsw_thermal * thermal )
850
+ struct mlxsw_thermal * thermal ,
851
+ struct mlxsw_thermal_area * area )
832
852
{
833
853
enum mlxsw_reg_mgpir_device_type device_type ;
834
854
struct mlxsw_thermal_module * gearbox_tz ;
@@ -837,7 +857,7 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
837
857
int i ;
838
858
int err ;
839
859
840
- mlxsw_reg_mgpir_pack (mgpir_pl , 0 );
860
+ mlxsw_reg_mgpir_pack (mgpir_pl , area -> slot_index );
841
861
err = mlxsw_reg_query (core , MLXSW_REG (mgpir ), mgpir_pl );
842
862
if (err )
843
863
return err ;
@@ -848,19 +868,20 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
848
868
!gbox_num )
849
869
return 0 ;
850
870
851
- thermal -> tz_gearbox_num = gbox_num ;
852
- thermal -> tz_gearbox_arr = kcalloc (thermal -> tz_gearbox_num ,
853
- sizeof (* thermal -> tz_gearbox_arr ),
854
- GFP_KERNEL );
855
- if (!thermal -> tz_gearbox_arr )
871
+ area -> tz_gearbox_num = gbox_num ;
872
+ area -> tz_gearbox_arr = kcalloc (area -> tz_gearbox_num ,
873
+ sizeof (* area -> tz_gearbox_arr ),
874
+ GFP_KERNEL );
875
+ if (!area -> tz_gearbox_arr )
856
876
return - ENOMEM ;
857
877
858
- for (i = 0 ; i < thermal -> tz_gearbox_num ; i ++ ) {
859
- gearbox_tz = & thermal -> tz_gearbox_arr [i ];
878
+ for (i = 0 ; i < area -> tz_gearbox_num ; i ++ ) {
879
+ gearbox_tz = & area -> tz_gearbox_arr [i ];
860
880
memcpy (gearbox_tz -> trips , default_thermal_trips ,
861
881
sizeof (thermal -> trips ));
862
882
gearbox_tz -> module = i ;
863
883
gearbox_tz -> parent = thermal ;
884
+ gearbox_tz -> slot_index = area -> slot_index ;
864
885
err = mlxsw_thermal_gearbox_tz_init (gearbox_tz );
865
886
if (err )
866
887
goto err_thermal_gearbox_tz_init ;
@@ -870,19 +891,20 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
870
891
871
892
err_thermal_gearbox_tz_init :
872
893
for (i -- ; i >= 0 ; i -- )
873
- mlxsw_thermal_gearbox_tz_fini (& thermal -> tz_gearbox_arr [i ]);
874
- kfree (thermal -> tz_gearbox_arr );
894
+ mlxsw_thermal_gearbox_tz_fini (& area -> tz_gearbox_arr [i ]);
895
+ kfree (area -> tz_gearbox_arr );
875
896
return err ;
876
897
}
877
898
878
899
static void
879
- mlxsw_thermal_gearboxes_fini (struct mlxsw_thermal * thermal )
900
+ mlxsw_thermal_gearboxes_fini (struct mlxsw_thermal * thermal ,
901
+ struct mlxsw_thermal_area * area )
880
902
{
881
903
int i ;
882
904
883
- for (i = thermal -> tz_gearbox_num - 1 ; i >= 0 ; i -- )
884
- mlxsw_thermal_gearbox_tz_fini (& thermal -> tz_gearbox_arr [i ]);
885
- kfree (thermal -> tz_gearbox_arr );
905
+ for (i = area -> tz_gearbox_num - 1 ; i >= 0 ; i -- )
906
+ mlxsw_thermal_gearbox_tz_fini (& area -> tz_gearbox_arr [i ]);
907
+ kfree (area -> tz_gearbox_arr );
886
908
}
887
909
888
910
int mlxsw_thermal_init (struct mlxsw_core * core ,
@@ -892,19 +914,29 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
892
914
char mfcr_pl [MLXSW_REG_MFCR_LEN ] = { 0 };
893
915
enum mlxsw_reg_mfcr_pwm_frequency freq ;
894
916
struct device * dev = bus_info -> dev ;
917
+ char mgpir_pl [MLXSW_REG_MGPIR_LEN ];
895
918
struct mlxsw_thermal * thermal ;
919
+ u8 pwm_active , num_of_slots ;
896
920
u16 tacho_active ;
897
- u8 pwm_active ;
898
921
int err , i ;
899
922
900
- thermal = devm_kzalloc (dev , sizeof (* thermal ),
901
- GFP_KERNEL );
923
+ mlxsw_reg_mgpir_pack (mgpir_pl , 0 );
924
+ err = mlxsw_reg_query (core , MLXSW_REG (mgpir ), mgpir_pl );
925
+ if (err )
926
+ return err ;
927
+
928
+ mlxsw_reg_mgpir_unpack (mgpir_pl , NULL , NULL , NULL , NULL ,
929
+ & num_of_slots );
930
+
931
+ thermal = kzalloc (struct_size (thermal , line_cards , num_of_slots + 1 ),
932
+ GFP_KERNEL );
902
933
if (!thermal )
903
934
return - ENOMEM ;
904
935
905
936
thermal -> core = core ;
906
937
thermal -> bus_info = bus_info ;
907
938
memcpy (thermal -> trips , default_thermal_trips , sizeof (thermal -> trips ));
939
+ thermal -> line_cards [0 ].slot_index = 0 ;
908
940
909
941
err = mlxsw_reg_query (thermal -> core , MLXSW_REG (mfcr ), mfcr_pl );
910
942
if (err ) {
@@ -970,11 +1002,13 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
970
1002
goto err_thermal_zone_device_register ;
971
1003
}
972
1004
973
- err = mlxsw_thermal_modules_init (dev , core , thermal );
1005
+ err = mlxsw_thermal_modules_init (dev , core , thermal ,
1006
+ & thermal -> line_cards [0 ]);
974
1007
if (err )
975
1008
goto err_thermal_modules_init ;
976
1009
977
- err = mlxsw_thermal_gearboxes_init (dev , core , thermal );
1010
+ err = mlxsw_thermal_gearboxes_init (dev , core , thermal ,
1011
+ & thermal -> line_cards [0 ]);
978
1012
if (err )
979
1013
goto err_thermal_gearboxes_init ;
980
1014
@@ -986,9 +1020,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
986
1020
return 0 ;
987
1021
988
1022
err_thermal_zone_device_enable :
989
- mlxsw_thermal_gearboxes_fini (thermal );
1023
+ mlxsw_thermal_gearboxes_fini (thermal , & thermal -> line_cards [ 0 ] );
990
1024
err_thermal_gearboxes_init :
991
- mlxsw_thermal_modules_fini (thermal );
1025
+ mlxsw_thermal_modules_fini (thermal , & thermal -> line_cards [ 0 ] );
992
1026
err_thermal_modules_init :
993
1027
if (thermal -> tzdev ) {
994
1028
thermal_zone_device_unregister (thermal -> tzdev );
@@ -1001,16 +1035,16 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
1001
1035
thermal_cooling_device_unregister (thermal -> cdevs [i ]);
1002
1036
err_reg_write :
1003
1037
err_reg_query :
1004
- devm_kfree ( dev , thermal );
1038
+ kfree ( thermal );
1005
1039
return err ;
1006
1040
}
1007
1041
1008
1042
void mlxsw_thermal_fini (struct mlxsw_thermal * thermal )
1009
1043
{
1010
1044
int i ;
1011
1045
1012
- mlxsw_thermal_gearboxes_fini (thermal );
1013
- mlxsw_thermal_modules_fini (thermal );
1046
+ mlxsw_thermal_gearboxes_fini (thermal , & thermal -> line_cards [ 0 ] );
1047
+ mlxsw_thermal_modules_fini (thermal , & thermal -> line_cards [ 0 ] );
1014
1048
if (thermal -> tzdev ) {
1015
1049
thermal_zone_device_unregister (thermal -> tzdev );
1016
1050
thermal -> tzdev = NULL ;
@@ -1023,5 +1057,5 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
1023
1057
}
1024
1058
}
1025
1059
1026
- devm_kfree ( thermal -> bus_info -> dev , thermal );
1060
+ kfree ( thermal );
1027
1061
}
0 commit comments