@@ -280,6 +280,10 @@ devlink_sb_tc_index_get_from_info(struct devlink_sb *devlink_sb,
280280#define DEVLINK_NL_FLAG_NEED_DEVLINK BIT(0)
281281#define DEVLINK_NL_FLAG_NEED_PORT BIT(1)
282282#define DEVLINK_NL_FLAG_NEED_SB BIT(2)
283+ #define DEVLINK_NL_FLAG_LOCK_PORTS BIT(3)
284+ /* port is not needed but we need to ensure they don't
285+ * change in the middle of command
286+ */
283287
284288static int devlink_nl_pre_doit (const struct genl_ops * ops ,
285289 struct sk_buff * skb , struct genl_info * info )
@@ -306,6 +310,9 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
306310 }
307311 info -> user_ptr [0 ] = devlink_port ;
308312 }
313+ if (ops -> internal_flags & DEVLINK_NL_FLAG_LOCK_PORTS ) {
314+ mutex_lock (& devlink_port_mutex );
315+ }
309316 if (ops -> internal_flags & DEVLINK_NL_FLAG_NEED_SB ) {
310317 struct devlink_sb * devlink_sb ;
311318
@@ -324,7 +331,8 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
324331static void devlink_nl_post_doit (const struct genl_ops * ops ,
325332 struct sk_buff * skb , struct genl_info * info )
326333{
327- if (ops -> internal_flags & DEVLINK_NL_FLAG_NEED_PORT )
334+ if (ops -> internal_flags & DEVLINK_NL_FLAG_NEED_PORT ||
335+ ops -> internal_flags & DEVLINK_NL_FLAG_LOCK_PORTS )
328336 mutex_unlock (& devlink_port_mutex );
329337 mutex_unlock (& devlink_mutex );
330338}
@@ -942,12 +950,13 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
942950 enum devlink_command cmd ,
943951 u32 portid , u32 seq , int flags )
944952{
953+ const struct devlink_ops * ops = devlink -> ops ;
945954 u32 threshold ;
946955 void * hdr ;
947956 int err ;
948957
949- err = devlink -> ops -> sb_port_pool_get (devlink_port , devlink_sb -> index ,
950- pool_index , & threshold );
958+ err = ops -> sb_port_pool_get (devlink_port , devlink_sb -> index ,
959+ pool_index , & threshold );
951960 if (err )
952961 return err ;
953962
@@ -966,6 +975,22 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
966975 if (nla_put_u32 (msg , DEVLINK_ATTR_SB_THRESHOLD , threshold ))
967976 goto nla_put_failure ;
968977
978+ if (ops -> sb_occ_port_pool_get ) {
979+ u32 cur ;
980+ u32 max ;
981+
982+ err = ops -> sb_occ_port_pool_get (devlink_port , devlink_sb -> index ,
983+ pool_index , & cur , & max );
984+ if (err && err != - EOPNOTSUPP )
985+ return err ;
986+ if (!err ) {
987+ if (nla_put_u32 (msg , DEVLINK_ATTR_SB_OCC_CUR , cur ))
988+ goto nla_put_failure ;
989+ if (nla_put_u32 (msg , DEVLINK_ATTR_SB_OCC_MAX , max ))
990+ goto nla_put_failure ;
991+ }
992+ }
993+
969994 genlmsg_end (msg , hdr );
970995 return 0 ;
971996
@@ -1114,14 +1139,15 @@ devlink_nl_sb_tc_pool_bind_fill(struct sk_buff *msg, struct devlink *devlink,
11141139 enum devlink_command cmd ,
11151140 u32 portid , u32 seq , int flags )
11161141{
1142+ const struct devlink_ops * ops = devlink -> ops ;
11171143 u16 pool_index ;
11181144 u32 threshold ;
11191145 void * hdr ;
11201146 int err ;
11211147
1122- err = devlink -> ops -> sb_tc_pool_bind_get (devlink_port , devlink_sb -> index ,
1123- tc_index , pool_type ,
1124- & pool_index , & threshold );
1148+ err = ops -> sb_tc_pool_bind_get (devlink_port , devlink_sb -> index ,
1149+ tc_index , pool_type ,
1150+ & pool_index , & threshold );
11251151 if (err )
11261152 return err ;
11271153
@@ -1144,6 +1170,24 @@ devlink_nl_sb_tc_pool_bind_fill(struct sk_buff *msg, struct devlink *devlink,
11441170 if (nla_put_u32 (msg , DEVLINK_ATTR_SB_THRESHOLD , threshold ))
11451171 goto nla_put_failure ;
11461172
1173+ if (ops -> sb_occ_tc_port_bind_get ) {
1174+ u32 cur ;
1175+ u32 max ;
1176+
1177+ err = ops -> sb_occ_tc_port_bind_get (devlink_port ,
1178+ devlink_sb -> index ,
1179+ tc_index , pool_type ,
1180+ & cur , & max );
1181+ if (err && err != - EOPNOTSUPP )
1182+ return err ;
1183+ if (!err ) {
1184+ if (nla_put_u32 (msg , DEVLINK_ATTR_SB_OCC_CUR , cur ))
1185+ goto nla_put_failure ;
1186+ if (nla_put_u32 (msg , DEVLINK_ATTR_SB_OCC_MAX , max ))
1187+ goto nla_put_failure ;
1188+ }
1189+ }
1190+
11471191 genlmsg_end (msg , hdr );
11481192 return 0 ;
11491193
@@ -1326,6 +1370,30 @@ static int devlink_nl_cmd_sb_tc_pool_bind_set_doit(struct sk_buff *skb,
13261370 pool_index , threshold );
13271371}
13281372
1373+ static int devlink_nl_cmd_sb_occ_snapshot_doit (struct sk_buff * skb ,
1374+ struct genl_info * info )
1375+ {
1376+ struct devlink * devlink = info -> user_ptr [0 ];
1377+ struct devlink_sb * devlink_sb = info -> user_ptr [1 ];
1378+ const struct devlink_ops * ops = devlink -> ops ;
1379+
1380+ if (ops && ops -> sb_occ_snapshot )
1381+ return ops -> sb_occ_snapshot (devlink , devlink_sb -> index );
1382+ return - EOPNOTSUPP ;
1383+ }
1384+
1385+ static int devlink_nl_cmd_sb_occ_max_clear_doit (struct sk_buff * skb ,
1386+ struct genl_info * info )
1387+ {
1388+ struct devlink * devlink = info -> user_ptr [0 ];
1389+ struct devlink_sb * devlink_sb = info -> user_ptr [1 ];
1390+ const struct devlink_ops * ops = devlink -> ops ;
1391+
1392+ if (ops && ops -> sb_occ_max_clear )
1393+ return ops -> sb_occ_max_clear (devlink , devlink_sb -> index );
1394+ return - EOPNOTSUPP ;
1395+ }
1396+
13291397static const struct nla_policy devlink_nl_policy [DEVLINK_ATTR_MAX + 1 ] = {
13301398 [DEVLINK_ATTR_BUS_NAME ] = { .type = NLA_NUL_STRING },
13311399 [DEVLINK_ATTR_DEV_NAME ] = { .type = NLA_NUL_STRING },
@@ -1439,6 +1507,24 @@ static const struct genl_ops devlink_nl_ops[] = {
14391507 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT |
14401508 DEVLINK_NL_FLAG_NEED_SB ,
14411509 },
1510+ {
1511+ .cmd = DEVLINK_CMD_SB_OCC_SNAPSHOT ,
1512+ .doit = devlink_nl_cmd_sb_occ_snapshot_doit ,
1513+ .policy = devlink_nl_policy ,
1514+ .flags = GENL_ADMIN_PERM ,
1515+ .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
1516+ DEVLINK_NL_FLAG_NEED_SB |
1517+ DEVLINK_NL_FLAG_LOCK_PORTS ,
1518+ },
1519+ {
1520+ .cmd = DEVLINK_CMD_SB_OCC_MAX_CLEAR ,
1521+ .doit = devlink_nl_cmd_sb_occ_max_clear_doit ,
1522+ .policy = devlink_nl_policy ,
1523+ .flags = GENL_ADMIN_PERM ,
1524+ .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
1525+ DEVLINK_NL_FLAG_NEED_SB |
1526+ DEVLINK_NL_FLAG_LOCK_PORTS ,
1527+ },
14421528};
14431529
14441530/**
0 commit comments