From 2c3b9c4f763085faa0c4654bc4cce8baaf32b89c Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Wed, 6 Sep 2023 16:11:20 +0800 Subject: [PATCH] [nrf fromlist] Bluetooth: Mesh: Remove bits for adv tag since tag for buf single only, no need for bit, also for save some memory for rfu. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62331 Signed-off-by: Lingao Meng (cherry picked from commit b14d235c31e5e79c857e0e46a1a632f35e2ca77e) --- subsys/bluetooth/mesh/adv.c | 14 +++++------ subsys/bluetooth/mesh/adv.h | 17 +++++++++---- subsys/bluetooth/mesh/adv_ext.c | 42 +++++++++++++++---------------- subsys/bluetooth/mesh/statistic.c | 12 ++++----- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index 2132c14e151..e67d96414e7 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -138,7 +138,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit, k_timeout_t timeout) { #if defined(CONFIG_BT_MESH_RELAY) - if (tag & BT_MESH_RELAY_ADV) { + if (tag == BT_MESH_RELAY_ADV) { return bt_mesh_adv_create_from_pool(&relay_buf_pool, adv_relay_pool, type, tag, xmit, timeout); @@ -146,7 +146,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, #endif #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - if (tag & BT_MESH_FRIEND_ADV) { + if (tag == BT_MESH_FRIEND_ADV) { return bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_friend_pool, type, tag, xmit, timeout); @@ -202,14 +202,14 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return process_events(events, ARRAY_SIZE(events)); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tag & BT_MESH_FRIEND_ADV) { + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_FRIEND_ADV_BIT) { return net_buf_get(&bt_mesh_friend_queue, timeout); } #if CONFIG_BT_MESH_RELAY_ADV_SETS - if (tag & BT_MESH_RELAY_ADV) { + if (tags & BT_MESH_RELAY_ADV_BIT) { return net_buf_get(&bt_mesh_relay_queue, timeout); } #endif @@ -222,9 +222,9 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return net_buf_get(&bt_mesh_adv_queue, timeout); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { - ARG_UNUSED(tag); + ARG_UNUSED(tags); return bt_mesh_adv_buf_get(timeout); } diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 3d0acf8a7ac..22a8e0645e1 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -26,10 +26,17 @@ enum bt_mesh_adv_type { }; enum bt_mesh_adv_tag { - BT_MESH_LOCAL_ADV = BIT(0), - BT_MESH_RELAY_ADV = BIT(1), - BT_MESH_PROXY_ADV = BIT(2), - BT_MESH_FRIEND_ADV = BIT(3), + BT_MESH_LOCAL_ADV, + BT_MESH_RELAY_ADV, + BT_MESH_PROXY_ADV, + BT_MESH_FRIEND_ADV, +}; + +enum bt_mesh_adv_tags { + BT_MESH_LOCAL_ADV_BIT = BIT(BT_MESH_LOCAL_ADV), + BT_MESH_RELAY_ADV_BIT = BIT(BT_MESH_RELAY_ADV), + BT_MESH_PROXY_ADV_BIT = BIT(BT_MESH_PROXY_ADV), + BT_MESH_FRIEND_ADV_BIT = BIT(BT_MESH_FRIEND_ADV), }; struct bt_mesh_adv { @@ -57,7 +64,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); -struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout); +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout); void bt_mesh_adv_gatt_update(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 5c1a2bc3c32..d347602ac09 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -60,7 +60,7 @@ enum { }; struct bt_mesh_ext_adv { - uint8_t tag; + enum bt_mesh_adv_tags tags; ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; struct net_buf *buf; @@ -73,17 +73,17 @@ static void send_pending_adv(struct k_work *work); static bool schedule_send(struct bt_mesh_ext_adv *adv); static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { - .tag = ( + .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_FRIEND_ADV | + BT_MESH_FRIEND_ADV_BIT | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_PROXY_ADV | + BT_MESH_PROXY_ADV_BIT | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_RELAY_ADV | + BT_MESH_RELAY_ADV_BIT | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_LOCAL_ADV), + BT_MESH_LOCAL_ADV_BIT), .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; @@ -91,7 +91,7 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { #if CONFIG_BT_MESH_RELAY_ADV_SETS static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_RELAY_ADV_SETS) = { [0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = { - .tag = BT_MESH_RELAY_ADV, + .tags = BT_MESH_RELAY_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), } }; @@ -100,7 +100,7 @@ static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #define ADV_EXT_FRIEND 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { - .tag = BT_MESH_FRIEND_ADV, + .tags = BT_MESH_FRIEND_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ @@ -110,7 +110,7 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) #define ADV_EXT_GATT 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { - .tag = BT_MESH_PROXY_ADV, + .tags = BT_MESH_PROXY_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ @@ -259,18 +259,18 @@ static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) return err; } -static const char *adv_tag_to_str(enum bt_mesh_adv_tag tag) +static const char *adv_tag_to_str(enum bt_mesh_adv_tags tags) { - if (tag & BT_MESH_LOCAL_ADV) { + if (tags & BT_MESH_LOCAL_ADV_BIT) { return "local adv"; - } else if (tag & BT_MESH_PROXY_ADV) { + } else if (tags & BT_MESH_PROXY_ADV_BIT) { return "proxy adv"; - } else if (tag & BT_MESH_RELAY_ADV) { + } else if (tags & BT_MESH_RELAY_ADV_BIT) { return "relay adv"; - } else if (tag & BT_MESH_FRIEND_ADV) { + } else if (tags & BT_MESH_FRIEND_ADV_BIT) { return "friend adv"; } else { - return "(unknown tag)"; + return "(unknown tags)"; } } @@ -289,8 +289,8 @@ static void send_pending_adv(struct k_work *work) */ int64_t duration = k_uptime_delta(&adv->timestamp); - LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tag, - adv_tag_to_str(adv->tag)); + LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tags, + adv_tag_to_str(adv->tags)); atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); @@ -308,7 +308,7 @@ static void send_pending_adv(struct k_work *work) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULED); - while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tag, K_NO_WAIT))) { + while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tags, K_NO_WAIT))) { /* busy == 0 means this was canceled */ if (!BT_MESH_ADV(buf)->busy) { net_buf_unref(buf); @@ -326,7 +326,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tag & BT_MESH_PROXY_ADV)) { + !(adv->tags & BT_MESH_RELAY_ADV_BIT)) { return; } @@ -369,8 +369,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); - if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tag & BT_MESH_FRIEND_ADV) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tag == BT_MESH_RELAY_ADV)) { + if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tags & BT_MESH_FRIEND_ADV_BIT) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_RELAY_ADV_BIT)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. diff --git a/subsys/bluetooth/mesh/statistic.c b/subsys/bluetooth/mesh/statistic.c index 5b1ffe7e0f5..046fa3c0eeb 100644 --- a/subsys/bluetooth/mesh/statistic.c +++ b/subsys/bluetooth/mesh/statistic.c @@ -24,22 +24,22 @@ void bt_mesh_stat_reset(void) void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) { - if (adv->tag & BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_LOCAL_ADV) { stat.tx_local_planned++; - } else if (adv->tag & BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_RELAY_ADV) { stat.tx_adv_relay_planned++; - } else if (adv->tag & BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_FRIEND_ADV) { stat.tx_friend_planned++; } } void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) { - if (adv->tag & BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_LOCAL_ADV) { stat.tx_local_succeeded++; - } else if (adv->tag & BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_RELAY_ADV) { stat.tx_adv_relay_succeeded++; - } else if (adv->tag & BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_FRIEND_ADV) { stat.tx_friend_succeeded++; } }