-
Notifications
You must be signed in to change notification settings - Fork 8.1k
net_buf: support large size #97440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
net_buf: support large size #97440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,14 @@ extern "C" { | |
.__buf = net_buf_data_##_name, \ | ||
} | ||
|
||
#if defined(CONFIG_NET_BUF_LARGE_SIZE) | ||
/** @brief net buf size type */ | ||
typedef uint32_t net_buf_size_t; | ||
#else | ||
/** @brief net buf size type */ | ||
typedef uint16_t net_buf_size_t; | ||
#endif | ||
|
||
/** | ||
* @brief Simple network buffer representation. | ||
* | ||
|
@@ -95,10 +103,10 @@ struct net_buf_simple { | |
* | ||
* To determine the max length, use net_buf_simple_max_len(), not #size! | ||
*/ | ||
uint16_t len; | ||
net_buf_size_t len; | ||
|
||
/** Amount of data that net_buf_simple#__buf can store. */ | ||
uint16_t size; | ||
net_buf_size_t size; | ||
|
||
/** Start of the data storage. Not to be accessed directly | ||
* (the data pointer should be used instead). | ||
|
@@ -938,7 +946,7 @@ size_t net_buf_simple_tailroom(const struct net_buf_simple *buf); | |
* | ||
* @return Number of bytes usable behind the net_buf_simple::data pointer. | ||
*/ | ||
uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf); | ||
size_t net_buf_simple_max_len(const struct net_buf_simple *buf); | ||
|
||
/** | ||
* @brief Parsing state of a buffer. | ||
|
@@ -949,9 +957,9 @@ uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf); | |
*/ | ||
struct net_buf_simple_state { | ||
/** Offset of the data pointer from the beginning of the storage */ | ||
uint16_t offset; | ||
net_buf_size_t offset; | ||
/** Length of data */ | ||
uint16_t len; | ||
net_buf_size_t len; | ||
}; | ||
|
||
/** | ||
|
@@ -965,7 +973,7 @@ struct net_buf_simple_state { | |
static inline void net_buf_simple_save(const struct net_buf_simple *buf, | ||
struct net_buf_simple_state *state) | ||
{ | ||
state->offset = (uint16_t)net_buf_simple_headroom(buf); | ||
state->offset = (net_buf_size_t)net_buf_simple_headroom(buf); | ||
state->len = buf->len; | ||
} | ||
|
||
|
@@ -1032,10 +1040,10 @@ struct net_buf { | |
uint8_t *data; | ||
|
||
/** Length of the data behind the data pointer. */ | ||
uint16_t len; | ||
net_buf_size_t len; | ||
|
||
/** Amount of data that this buffer can store. */ | ||
uint16_t size; | ||
net_buf_size_t size; | ||
|
||
/** Start of the data storage. Not to be accessed | ||
* directly (the data pointer should be used | ||
|
@@ -1097,7 +1105,7 @@ struct net_buf_pool { | |
atomic_t avail_count; | ||
|
||
/** Total size of the pool. */ | ||
const uint16_t pool_size; | ||
const net_buf_size_t pool_size; | ||
|
||
/** Maximum count of used buffers. */ | ||
uint16_t max_used; | ||
|
@@ -2523,7 +2531,7 @@ static inline size_t net_buf_headroom(const struct net_buf *buf) | |
* | ||
* @return Number of bytes usable behind the net_buf::data pointer. | ||
*/ | ||
static inline uint16_t net_buf_max_len(const struct net_buf *buf) | ||
static inline size_t net_buf_max_len(const struct net_buf *buf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
{ | ||
return net_buf_simple_max_len(&buf->b); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,4 +59,9 @@ config NET_BUF_ALIGNMENT | |
Default value of 0 means the alignment will be the size of a void pointer, | ||
any other value will force the alignment of a net buffer in bytes. | ||
|
||
config NET_BUF_LARGE_SIZE | ||
bool "Network buffer large size" | ||
help | ||
Enable support for large network buffers. | ||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this should specify exactly what the larger size is. |
||
|
||
endif # NET_BUF |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -620,7 +620,7 @@ size_t net_buf_simple_tailroom(const struct net_buf_simple *buf) | |
return buf->size - net_buf_simple_headroom(buf) - buf->len; | ||
} | ||
|
||
uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf) | ||
size_t net_buf_simple_max_len(const struct net_buf_simple *buf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate commit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
{ | ||
return buf->size - net_buf_simple_headroom(buf); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,9 @@ tests: | |
min_ram: 16 | ||
tags: | ||
- net_buf | ||
libraries.net_buf.large_buf: | ||
min_ram: 16 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not so sure this will help. One memory constrained platform which uses net_bufs (for Bluetooth) is nRF51 with 16k RAM, so the above wouldn't exclude it. I'd propose to use 32. |
||
extra_configs: | ||
- CONFIG_NET_BUF_LARGE_SIZE=y | ||
tags: | ||
- net_buf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a separate commit, with the commit message explaining that it's just aligning this with the rest of the net_buf APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a breaking API change, though.