gnrc_netif: Add bootstrap function for device setup#9329
gnrc_netif: Add bootstrap function for device setup#9329bergzand wants to merge 14 commits intoRIOT-OS:masterfrom
Conversation
|
This is something that could be useful in a project I am working on. Thanks @bergzand! |
| dev->context = netif; | ||
| /* register the event callback with the device driver */ | ||
| dev->event_callback = _event_cb; | ||
| dev->context = netif; |
sys/include/net/gnrc/netif.h
Outdated
| * | ||
| * @param[in] args The network interface | ||
| */ | ||
| void *gnrc_netif_thread(void *args); |
There was a problem hiding this comment.
Mhhh... Can we somehow get around exposing this function?
There was a problem hiding this comment.
Would it be okay to have it in sys/include/net/gnrc/netif/internal.h?
There was a problem hiding this comment.
Maybe you can use a trampoline function somehow?
sys/include/net/gnrc/netif.h
Outdated
| * | ||
| * @param[in] args The network interface | ||
| */ | ||
| void *gnrc_netif_thread(void *args); |
sys/include/net/gnrc/netif.h
Outdated
| typedef struct { | ||
| const gnrc_netif_ops_t *ops; /**< Operations of the network interface */ | ||
| netdev_t *dev; /**< Network device of the network interface */ | ||
| netdev_t *hwdev; /**< Hardware layer of the network device */ |
There was a problem hiding this comment.
Either change name of hwdev or the name and doc on dev (that is the top-layer of netdev). hwdev can be misleading if you have "virtual" devices.
| static void *_bootstrap(void *args) | ||
| { | ||
| gnrc_netif_t *netif = args; | ||
| netif->hwdev = netif->dev; |
There was a problem hiding this comment.
Why don't netif_ethernet or netif_raw require this change?
There was a problem hiding this comment.
gnrc_netif_ieee802154.c requires access to the ieee802154_netdev struct, for the pan_id, and sequence numbers and more. The other mac layers don't require this.
There was a problem hiding this comment.
If we can build a getter or something for this we can omit the whole hwdev member here altogether (solving the issue above too)
There was a problem hiding this comment.
Mh... if that is possible, I would prefer that. Then most of the changes in #9330 wouldn't be necessary also.
There was a problem hiding this comment.
By "make a separate layer" I mean move the sequence number, pan id, lladdr etc to a gnrc_netif_ieee802154 internal variables, or a proper layer, whichever is most feasible
There was a problem hiding this comment.
@gebart I would like to stick with the proposed solution of doing a get() call for the struct for now. I agree with your solution, but I'd rather not rework half of this PR at the moment, but do it in a follow up afterwards.
There was a problem hiding this comment.
Sounds good. A future possible TSCH implementation needs to use a different frame format than the traditional 802.15.4 frames use, so it would be a good improvement to decouple the framing from the device driver
There was a problem hiding this comment.
See #9335 (comment). I think something is wrong with the concept here.... The layered approach should make it possible that it doesn't matter which pointer you use. And if it's not the case the pointer change should certainly not be implemented here IMHO, but in the netdev_ieee802154 adaption PR.
sys/net/gnrc/netif/gnrc_netif_raw.c
Outdated
| netdev_t *dev) | ||
| { | ||
| return gnrc_netif_create(stack, stacksize, priority, name, dev, | ||
| gnrc_netif_thread, |
There was a problem hiding this comment.
why not here a special _bootstrap method?
There was a problem hiding this comment.
Probably because I forgot to correctly adapt this one
|
I think |
Done! |
Now even on the correct branch |
Adds a bootstrap function to provide setting up the layered structure for the netdev devices. The structs end up on the stack providing some sort of dynamic allocation for the layers
378de5f to
9b9ac70
Compare
|
Reworked a bit to contain only the minimal required for the this PR. Also rebased to resolve the merge conflict. |
|
Hi, while I agree with your approach, now after looking at it after some time, I think the name "bootstrip" might be confusing. I was searching for a while where this "bootstrap" method is called, only to realize that it is the thread handler. Maybe rename the variable to |
|
While I agree that it might be confusing, I think that |
|
The easiest would be |
The idea behind this "setup" function is to be able to have L2 protocol specific setup before the handling of the netif loop starts. In my case specifically to have a place to instantiate netdev structs on the stack of the netif thread. |
|
I know, but what you are doing here at the moment is allowing to customize the thread handler. With a function name called setup I would expect it to be called before starting the thread handler or maybe to be the very first thing to be called within the thread handler, not the thread handler itself. "bootstrap" implies on the otherhand that it is what bootstraps the interface, which is completely wrong here also. |
|
Okay, I was afraid that the goal of the function was not completely clear anymore. I don't have a better idea at the moment, so I'm fine with |
|
Needs rebase. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
This adds a bootstrap function to the gnrc_netif initialization. This bootstrap function can be used to initialize a layered netdev structure. This way the required structures can be kept on the stack of the netif thread while keeping the total structure somewhat dynamic.
For now the bootstrap functions are empty. They are used as soon as there are separate netdev layers that require them.
Issues/PRs references
next step of #8198