Skip to content

usb: device_next: Simple NCM driver for usb-next #72310

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

Closed
wants to merge 3 commits into from

Conversation

rgrr
Copy link

@rgrr rgrr commented May 4, 2024

This is a first version of an NCM driver for usb-next. As a template the usb-next ECM driver has been used.

The driver has been kept very simple (one datagram per NTB and one buffer per direction). Current idea is not to optimize performance, focus is more on existence of an NCM driver for Zephyr.

To make the driver work with iperf (my testcase), CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y must be used.

Discussion about this PR can be found in #71451.

Resolves: #71451

@zephyrbot zephyrbot added area: Ethernet area: Networking area: USB Universal Serial Bus area: Samples Samples area: Devicetree Binding PR modifies or adds a Device Tree binding labels May 4, 2024
@rgrr rgrr changed the title Draft: Simple NCM driver for usb-next (2nd try) Draft: usb: device_next: Simple NCM driver for usb-next (2nd try) May 4, 2024
@rgrr rgrr changed the title Draft: usb: device_next: Simple NCM driver for usb-next (2nd try) usb: device_next: Simple NCM driver for usb-next (2nd try) May 6, 2024
@zephyrbot zephyrbot requested a review from lmajewski May 7, 2024 17:23
@rgrr rgrr changed the title usb: device_next: Simple NCM driver for usb-next (2nd try) usb: device_next: Simple NCM driver for usb-next May 8, 2024
@rgrr rgrr force-pushed the cdc-ncm2 branch 2 times, most recently from a4b0e57 to 94b376e Compare May 8, 2024 11:43
@rgrr rgrr force-pushed the cdc-ncm2 branch 2 times, most recently from 33e603f to 387704e Compare June 30, 2024 14:49
Copy link
Collaborator

@josuah josuah left a comment

Choose a reason for hiding this comment

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

This is a recent modification on upstream Zephyr: usbd_contex had a typo and was adjusted to usbd_context.

8d344cc

@josuah
Copy link
Collaborator

josuah commented Jul 1, 2024

To help with maintenance and troubleshooting, I believe Zephyr maintainers like to have only meaningful commits.
Maybe making a single commit that introduces the class would work?

git rebase -i HEAD^4 and modifying the lines for the two commits that needs to be changed from pick to squash would likely work.

@rgrr
Copy link
Author

rgrr commented Jul 2, 2024

This is a recent modification on upstream Zephyr: usbd_contex had a typo and was adjusted to usbd_context.

Haha... first time I couldn't compile before pushing, because my environment was broken (see eclipse-cdt/cdt#846). And then the CI shows you that that's a bad idea.

Squashed the commits (again). I actually don't like that, because history is lost (and actually I'm not a fan of rebasing because history is rewritten, but that is another story...))

@@ -41,6 +41,8 @@ instance (`n`) and is used as an argument to the :c:func:`usbd_register_class`.
+-----------------------------------+-------------------------+-------------------------+
| USB CDC ECM class | Ethernet device | :samp:`cdc_ecm_{n}` |
+-----------------------------------+-------------------------+-------------------------+
| USB CDC NCM class | Ethernet device | :samp:`cdc_ncm_{n}` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move changes in doc/connectivity/usb/device_next/usb_device.rst to a separate commit, it would also make it easier for you to rebase.

Copy link
Author

Choose a reason for hiding this comment

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

ok... I have created three branches and soon two more PRs will appear here. New code stays in this PR.

Concerning review procedure: who is resolving conversations? You? Me?

Copy link
Collaborator

Choose a reason for hiding this comment

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

One branch (one PR) with N commits is the preferred way.

Copy link
Author

Choose a reason for hiding this comment

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

gosh... what have I done!? Misunderstood Johanns point completely. Will go back.

Copy link
Author

Choose a reason for hiding this comment

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

what commit comments do you expect in this case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If by commit comments you mean the commit messages, then each commit message should describe what the individual commit does. Do not reuse the title for all of the commits, make each of them point to the respective part. For example the commit changing sample should start its commit title with samples: net: zperf:.

Things like "This PR contains the actual driver." do not belong in commit message.

@@ -199,7 +202,7 @@ struct cdc_acm_notification {
} __packed;

/** Ethernet Networking Functional Descriptor */
struct cdc_ecm_descriptor {
struct cdc_eth_functional_descriptor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think you should rename it here or at all.

Copy link
Author

Choose a reason for hiding this comment

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

Hmm... but cdc_ecm_descriptor is the wrong name. Will change it back anyway

Comment on lines +4 to +9
CONFIG_NET_PKT_RX_COUNT=14
CONFIG_NET_PKT_TX_COUNT=14
CONFIG_NET_BUF_RX_COUNT=28
CONFIG_NET_BUF_TX_COUNT=28
CONFIG_NET_BUF_DATA_SIZE=1500

Copy link
Collaborator

Choose a reason for hiding this comment

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

This configuration overlay is not used if sample is build for the new USB device support. Stray changes?

Copy link
Author

Choose a reason for hiding this comment

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

I have to rethink why I have done this ;-)

Comment on lines +1 to +10
CONFIG_USB_DEVICE_STACK_NEXT=y

# next-ncm does not work well with the static-size buffers
CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE=10000
CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=10000
CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y

CONFIG_LOG=y
CONFIG_USBD_LOG_LEVEL_WRN=y
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move sample changes to a separate commit.
Looks like there should be three commits in your PR, 1) USB NCM implementation + bindings, 2) sample changes, 3) doc update.

Copy link
Author

Choose a reason for hiding this comment

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

done that

Comment on lines +7 to +12
/ {
cdc_ncm_eth0: cdc_ncm_eth0 {
compatible = "zephyr,cdc-ncm-ethernet";
remote-mac-address = "00005E005301";
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please indent with tabs, always.

/*
* check (first) NDP(16)
*/
const struct ndp16_t *ndp16 = (const struct ndp16_t *)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Variable definition should be at the top of a block. Please clean up and fix your code, I will continue the review after that.




static bool _cdc_ncm_frame_ok(struct cdc_ncm_eth_data *data, struct net_buf *const buf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefixing with _ is not okay.

#define CFG_CDC_NCM_RCV_NTB_MAX_SIZE 3200

/* Table 6.2 Class-Specific Request Codes for Network Control Model subclass */
typedef enum {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No typedefs.

Comment on lines +12 to +18
#ifndef CFG_CDC_NCM_ALIGNMENT
#define CFG_CDC_NCM_ALIGNMENT 4
#endif
#if (CFG_CDC_NCM_ALIGNMENT != 4)
/* headers and start of datagrams in structs have to be aligned differently */
#error "CFG_CDC_NCM_ALIGNMENT must be 4"
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it not the same as just #define CFG_CDC_NCM_ALIGNMENT 4?
Please remove all the CFG_ prefixes and move whatever make sense to Kconfig options.

Copy link
Author

Choose a reason for hiding this comment

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

I have "reserved" those CFGs for future extensions. Currently there is no meaning in them, so they don't appear in Kconfig. Will change it.


#define NTH16_SIGNATURE 0x484D434E
#define NDP16_SIGNATURE_NCM0 0x304D434E
#define NDP16_SIGNATURE_NCM1 0x314D434E
Copy link
Collaborator

Choose a reason for hiding this comment

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

#define NTH16_SIGNATURE      0x484D434EUL
#define NDP16_SIGNATURE_NCM0 0x304D434EUL
#define NDP16_SIGNATURE_NCM1 0x314D434EUL

Copy link
Author

Choose a reason for hiding this comment

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

@jfischer-no : many thanks for the extensive review, I will change accordingly (or comment on it). But this will take some time.

rgrr added 3 commits July 31, 2024 07:26
This is a simple USB-NCM driver. It just has one NTB
per direction and within the NTB only one datagram
can be received/transmitted.
Main goal is existance of an NCM driver, performance
will follow in further steps.

This PR contains the actual driver.

Signed-off-by: Hardy Griech <[email protected]>
Sample changes.

Signed-off-by: Hardy Griech <[email protected]>
Documentation changes.

Signed-off-by: Hardy Griech <[email protected]>
@jfischer-no
Copy link
Collaborator

@rgrr There still seems to be no changes since the last review, do you have any challenges with git?

@rgrr
Copy link
Author

rgrr commented Sep 6, 2024

@rgrr There still seems to be no changes since the last review, do you have any challenges with git?

No... sorry... I'm currently too busy to work on the PR. Don't drop it, if there is time I will polish it.

@rgrr rgrr marked this pull request as draft September 6, 2024 16:17
@jukkar jukkar removed their request for review October 18, 2024 07:38
@josuah
Copy link
Collaborator

josuah commented Oct 23, 2024

Following this initial effort on bringing CDC NCM to Zephyr, an independent PR was started after this message and is now merged:

The outline of functions is the same, but their implementation differ in several places.
I suppose this PR content helped in giving insight in how the problem could be solved, and was supportive on the other PR which led to CDC NCM merged Zephyr.

Thank you @rgrr !
It might be possible to close this PR now, as the NCM development effort were pursued on the other PR.

@josuah josuah removed their request for review October 23, 2024 22:17
@rgrr
Copy link
Author

rgrr commented Oct 24, 2024

:

The outline of functions is the same, but their implementation differ in several places. I suppose this PR content helped in giving insight in how the problem could be solved, and was supportive on the other PR which led to CDC NCM merged Zephyr.

Great, if my implementation was of any help!

Thank you @rgrr ! It might be possible to close this PR now, as the NCM development effort were pursued on the other PR.

Of course close it. I will check the other implementation soon and provide comments if required.

Sorry for wasting your time for reviewing my PR.

@josuah
Copy link
Collaborator

josuah commented Oct 24, 2024

Sorry for wasting your time for reviewing my PR

No issue at all ! I learned in the process and that was useful in other ways (UVC).

@josuah josuah closed this Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Ethernet area: Networking area: Samples Samples area: USB Universal Serial Bus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there any interest in USB CDC-NCM driver?
6 participants