Skip to content
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

modem: modem_cellular: Configurable MTU for CMUX #87115

Merged
merged 3 commits into from
Mar 24, 2025

Conversation

SeppoTakalo
Copy link
Collaborator

Allow configuring MTU for CMUX.
Some AT manual and specification define this as a
frame size. Linux ldattach default to 127 bytes,
3GPP TS 27.010 defaults to 31.

We should limit our CMUX frames to a size that
remote end is capable of handling.
Linux silently drops oversized frames.

Also, deprecate MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE as this was only limiting a buffer sizes, and resulted CMUX frames to be capped to same value.
Use MODEM_CMUX_WORK_BUFFER_SIZE and MODEM_CMUX_MTU instead.

For reference:
Linux kernel n_gsm.c driver on receiving side: https://elixir.bootlin.com/linux/v6.13.6/source/drivers/tty/n_gsm.c#L2885
You can see that all frames larger than MTU/MRU are silently dropped.

ldattach(8) utility from Util-linux package: https://github.com/util-linux/util-linux/blob/master/sys-utils/ldattach.c#L260-L276 you can see that it sets default to 127 and there is no command line parameters to configure this.

rlubos
rlubos previously approved these changes Mar 14, 2025
jukkar
jukkar previously approved these changes Mar 14, 2025
rerickson1
rerickson1 previously approved these changes Mar 14, 2025
Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it :)

@SeppoTakalo SeppoTakalo force-pushed the modem_cmux_mtu_upstream branch from a1774bd to 2fb412a Compare March 17, 2025 09:24
rlubos
rlubos previously approved these changes Mar 20, 2025
rerickson1
rerickson1 previously approved these changes Mar 20, 2025
jukkar
jukkar previously approved these changes Mar 21, 2025
@SeppoTakalo
Copy link
Collaborator Author

Rebased on top of main and fixed the conflict on migration-guide-4.2.rst

@SeppoTakalo
Copy link
Collaborator Author

Please merge this soon, as I would otherwise have to constantly rebase it on top of main, because changelog keeps changing and I get conflicts.

@tomi-font
Copy link
Collaborator

tomi-font commented Mar 24, 2025

I see. I renamed the Kconfig as I want to keep all DLCI buffers to same as CMUX size. It seem to work OK and we then save lots of RAM.

Uhm, weird numbers considering your changes (regarding ROM), are you sure your branch is based off the same main as what you are using for comparison?

Also, of course you'll get big RAM savings for nrf9160dk/nrf52840 by changing the buffer sizes from 1500 to 38, but I think this is gonna be very sub-ideal for the bandwidth as every PPP frame will be very small due to the CMUX MTU.
For the SLM-based board targets I'd actually support keeping a bigger CMUX MTU in the sample.

@SeppoTakalo
Copy link
Collaborator Author

Uhm, weird numbers considering your changes (regarding ROM), are you sure your branch is based off the same main as what you are using for comparison?

Not weird numbers. I took a look of why this happens.
struct modem_cellular_data contains all buffers so when all modem instances are defined using static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = {...} then all fields of that struct are stored in flash, and then copied into .datasection.

So even though we only initialize some of the fields, the whole structure is stored. So all buffers are going to be zero initialized.

@SeppoTakalo
Copy link
Collaborator Author

sub-ideal for the bandwidth as every PPP frame will be very small due to the CMUX MTU.

I'm unsure if I follow this correctly. The CMUX MTU does not affect PPP MTU.
One PPP frame might need multiple CMUX frames to be send.

For performance wise, all buffer sizes should be optimized only once you define your final baud rate. So it is pointless to try to tweak them here.

Allow configuring MTU for CMUX.
Some AT manual and specification define this as a
frame size. Linux ldattach default to 127 bytes,
3GPP TS 27.010 defaults to 31.

We should limit our CMUX frames to a size that
remote end is capable of handling.
Linux silently drops oversized frames.

Also, remove MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE as
this was only limiting a buffer sizes, and resulted
CMUX frames to be capped to same value.
Use MODEM_CMUX_WORK_BUFFER_SIZE and MODEM_CMUX_MTU instead.

Also rename CONFIG_MODEM_CELLULAR_CHAT_BUFFER_SIZES to
CONFIG_MODEM_CELLULAR_CHAT_BUFFER_SIZE as it is now
only used as a Chat module. DLCI pipes use
CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Add migration guide for configuring MTU for CMUX.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
If we end up writing zero bytes to cmux output, we can return
zero instead of -ENOMEM as it would break various modules when
using small buffers. For example modem_chat.c does not tolerate
-ENOMEM but handles zero OK.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
@SeppoTakalo SeppoTakalo force-pushed the modem_cmux_mtu_upstream branch from eb59a1e to 40a2c87 Compare March 24, 2025 12:55
@SeppoTakalo
Copy link
Collaborator Author

Sorry for changing this PR:
I separated the migration guide to its own commit so I'm able to pull these changes in nRF Connect SDK.

Otherwise I would end up conflicting the migration guide again when cherry-picking.

@tomi-font
Copy link
Collaborator

Not weird numbers. I took a look of why this happens.
struct modem_cellular_data contains all buffers so when all modem instances are defined using static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = {...} then all fields of that struct are stored in flash, and then copied into .datasection.

So even though we only initialize some of the fields, the whole structure is stored. So all buffers are going to be zero initialized.

Oh wow. That's bad. Wondering what could be done to avoid that. 🤔

I'm unsure if I follow this correctly. The CMUX MTU does not affect PPP MTU.
One PPP frame might need multiple CMUX frames to be send.

Yeah sorry I was too simplistic in what I said. The PPP frames being sent across many small CMUX frames will reduce the MCU <=> modem bandwidth (and increase at least a little bit the processing overhead). But I don't disagree that this needs to be tuned according to every use case and configuration.

@tomi-font
Copy link
Collaborator

Sorry for changing this PR:
I separated the migration guide to its own commit so I'm able to pull these changes in nRF Connect SDK.

Otherwise I would end up conflicting the migration guide again when cherry-picking.

The diff didn't change so the reviews weren't dismissed. 🙂

@kartben kartben merged commit 15b0f90 into zephyrproject-rtos:main Mar 24, 2025
25 checks passed
@SeppoTakalo SeppoTakalo deleted the modem_cmux_mtu_upstream branch March 24, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants