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

[topic-usb]First step to rework USB core. #26733

Merged

Conversation

eobalski
Copy link
Collaborator

@eobalski eobalski commented Jul 8, 2020

usb: Rework the USB core internals.

Rework the way how the interfaces are handled by the USB core stack.
Until now USB stack was aware of only the first interface associated
with each class. This led to a problem when not first interface was
addressed by the request.

This patch allow to filter out the request at core level.
This is not done in this PR but inits foreground

The usb_cfg_data struct is legacy of initial implementation
of USB device stack. Initially the USB device stack was
implemented to support single class devices with
no composite support. This structure was intended to be used to
configure the device in run time by calling usb_set_config().

Because of how things grow the structure was used to represent
the classes instead of devices.

This patch removes device configuration descriptor pointer.
Adds pointer to table of USB interface containers associated with
he function it represents. Each container consist of pointer to
interface descriptor, its alternate setting (if exists) and currently
selected alternate setting. This help USB core stack to properly address
SET/GET interface requests.

This patch renames some of the usb_cfg_data fields to better
represent its meaning. The usb_cfg_data struct is renamed itself
as this name is no longer valid (look up).

This patch is first step to rework the USB core stack and is not meant
to be considered as final form of USB core.

Signed-off-by: Emil Obalski [email protected]

usb_cfg_data data structure is handling usb funciton specifig data.
USB device descriptor is single instance located in special RAM section.

This deletion is a step forward to make core stack aware of classes
it handles.

Signed-off-by: Emil Obalski <[email protected]>
@eobalski eobalski added area: USB Universal Serial Bus Breaking API Change Breaking changes to stable, public APIs labels Jul 8, 2020
@github-actions github-actions bot added area: API Changes to public APIs area: Bluetooth area: Networking area: Samples Samples area: Tests Issues related to a particular existing or missing test labels Jul 8, 2020
include/usb/usb_device.h Outdated Show resolved Hide resolved
@eobalski eobalski force-pushed the usb_core_class_interface branch from c6535a5 to 838e625 Compare July 8, 2020 15:30
* only one alternate setting, this may change in the future.
*/
struct usb_if_container {
const struct usb_if_descriptor *const iface;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This well be reworked in subsequent patches as discussed, right? (just to clarify)

Copy link
Collaborator Author

@eobalski eobalski Jul 8, 2020

Choose a reason for hiding this comment

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

Yes. I don't want to make everything in one PR, as it will grow significantly. This is just a base, usb_if_container will be reworked anyway. I treat 'topic-usb' branch as wip/devel branch.

subsys/usb/usb_device.c Outdated Show resolved Hide resolved
subsys/usb/usb_device.c Outdated Show resolved Hide resolved
subsys/usb/usb_device.c Outdated Show resolved Hide resolved
enum usb_dc_status_code cb_status,
const uint8_t *param);
/** USB request handlers */
struct usb_request_handlers request_handlers;
/* Number of interfaces for this function */
/** Number of interfaces for this class */
const uint8_t num_interfaces;
Copy link
Collaborator

Choose a reason for hiding this comment

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

const uint8_t num_interfaces; can be removed? or moved to usb_if_container?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

const uint8_t num_interfaces; is number of usb_if_containers so it must stay here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to rename it too, num_if_containers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely yes. I will rename it. Wondering if We should also rethink the usb_ep_cfg_data and make it consistent with each other.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just usb_ep_data or usb_ep_cfg?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will leave endpoints for now. What I will change is:
usb_cfg_data::interfaces -> usb_cfg_data::if_containers
usb_cfg_data::num_interfaces -> usb_cfg_data::num_if_containers

include/usb/usb_device.h Show resolved Hide resolved
Emil Obalski added 2 commits July 13, 2020 11:29
Rename USB usb_cfg_data structures to better reflect its meaning.

interface -> request_handlers
    Name interface was used here as a communication interface
    between USB core stack and Class implementations.
    This naming could be missleading as USB specification defines
    interface as a part of the USB device descriptor.

endpoint -> endpoints
    This change was made to reflect that there might be more than one
    endpoint.

Signed-off-by: Emil Obalski <[email protected]>
This patch cleans webusb class. WebUSB class were using custom
request handler structure which is not necessary. This one
is removed and API struct is used instead.

Signed-off-by: Emil Obalski <[email protected]>
@eobalski eobalski force-pushed the usb_core_class_interface branch 3 times, most recently from 51f34d1 to 85ca527 Compare July 13, 2020 13:11
Emil Obalski added 2 commits July 13, 2020 16:39
Rework the way how the interfaces are handled by the USB core stack.
Until now USB stack was aware of only the first interface associated
with each class. This led to a problem when not first interface was
addressed by the request.

This patch allow to filter out the request at core level.

The usb_cfg_data struct is legacy of initial implementation
of USB device stack. Initially the USB device stack was
implemented to support single class devices with
no composite support. This structure was intended to be used to
configure the device in run time by calling usb_set_config().

Because of how things grow the structure was used to represent
the classes instead of devices.

This patch removes device configuration descriptor pointer.
Adds pointer to table of USB interface containers associated with
he function it represents. Each container consist of pointer to
interface descriptor, its alternate setting (if exists) and currently
selected alternate setting. This help USB core stack to properly address
SET/GET interface requests.

This patch should be followed by renaming the structure to something
closer to 'class' specific data as described in USB 2.0 spec.

This patch is first step to rework the USB core stack and is not meant
to be considered as final form of USB core.

Signed-off-by: Emil Obalski <[email protected]>
The name 'usb_cfg_data' is legacy of initial implementation
of the USB device stack. This structure was intended to be used to
configure the device in run time by calling usb_set_config().

Because of how things grown this was used to represent the data
of classes rather than the device as a whole. One device may consist of
many classes (composite device). When the stack was initially
developed this was not considered.

Alongside with renaming usb_cfg_data -> usb_class_data, all relevant
functions/macros/variables are updated accordingly.

Signed-off-by: Emil Obalski <[email protected]>
@eobalski eobalski force-pushed the usb_core_class_interface branch from 85ca527 to 6644bff Compare July 13, 2020 14:39
@eobalski eobalski changed the title First step to rework USB core. [topic-usb]First step to rework USB core. Jul 14, 2020
Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

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

This all looks very reasonable to me, including the new names.

@carlescufi carlescufi merged commit 7be5e88 into zephyrproject-rtos:topic-usb Jul 17, 2020
@eobalski eobalski deleted the usb_core_class_interface branch July 17, 2020 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Bluetooth area: Networking area: Samples Samples area: Tests Issues related to a particular existing or missing test area: USB Universal Serial Bus Breaking API Change Breaking changes to stable, public APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants