Skip to content

hm2_eth: Xenomai4 OOB improvements - #4503

Open
hdiethelm wants to merge 5 commits into
LinuxCNC:masterfrom
hdiethelm:hm2_eth_oob_improvements
Open

hm2_eth: Xenomai4 OOB improvements#4503
hdiethelm wants to merge 5 commits into
LinuxCNC:masterfrom
hdiethelm:hm2_eth_oob_improvements

Conversation

@hdiethelm

@hdiethelm hdiethelm commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

While creating Xenomai3 support, a better way to do the initialization without needing to first use posix and then switch to OOB was discovered: By attaching also rtapi_app to the EVL core, OOB functions can also be used in rtapi_app_main.

This should have no side effects due to SCHED_WEAK is used for rtapi_app: https://v4.xenomai.org/core/user-api/scheduling/index.html#SCHED_WEAK. But it gets rid of the realtime-init function which is deprecated.

This PR also moves the firewall init / cleanup from the Ethernet implementations out to hm2_eth.c. This slightly alters the calling order but should have no side effects, simplifies the code and allows support library's with less shared symbols.

Tested:

  • Firewall config with nft and iptables are equal before and after this PR
  • Posix and Xenomai4 hm2_eth still works fine
  • No difference in realtime performance observed
  • Test with Modbus (Thanks @zz912)

Open:

  • realtime-init is deprecated now. Should I just fully remove it? I guess not that many people use this already but the few that do will run into trouble. So deprecating it for some time might be better.
  • Are there applications where multiple mesa cards are connected over a switch to a single Ethernet port? This might be an issue with the actual way of initializing the interfaces for Xenomai4. Different ports should work but I have no way of testing this due to I have only one card. Theoretically fixed. But I can not test it.

@hdiethelm

Copy link
Copy Markdown
Contributor Author

@zz912 Can you test if this branch works on your setup?
initf hm2_eth.realtime-init servo-thread is not needed any more which simplifies the configuration.

@zz912

zz912 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

I commented:
#initf hm2_eth.realtime-init servo-thread

It works:

zdenek@cnc:~/linuxcnc/linuxcnc-fork-hm2_eth_oob_improvements/scripts$ ./linuxcnc
LINUXCNC - 2.10.0~pre1
Machine configuration directory is '/home/zdenek/linuxcnc/configs/DedaCNC-013'
Machine configuration file is 'DedaCNC-013.ini'
Starting LinuxCNC...
Note: Using XENOMAI4 EVL realtime
linuxcnc TPMOD=tpmod HOMEMOD=homemod EMCMOT=motmod
Found file(REL): ./DedaCNC-013.hal
hm2: loading Mesa HostMot2 driver version 0.15
hm2_eth: loading Mesa AnyIO HostMot2 ethernet driver version 0.2
hm2_eth: 10.10.10.10: INFO: init board (Xenomai EVL)
hm2_eth: 10.10.10.10: INFO: enable OOB for board on if enp1s0f0
hm2_eth: 10.10.10.10: INFO: Hardware address (MAC): 00:60:1b:16:80:30
hm2_eth: discovered 7I96S
hm2/hm2_7i96s.0: Low Level init 0.15
hm2/hm2_7i96s.0: created PktUART Interface function hm2_7i96s.0.pktuart.0.
hm2/hm2_7i96s.0: 51 I/O Pins used:
hm2/hm2_7i96s.0:     IO Pin 000 (TB3-01): InM Input Module #0, pin in0,enca0 (Input)
hm2/hm2_7i96s.0:     IO Pin 001 (TB3-02): InM Input Module #0, pin in1,encb0 (Input)
hm2/hm2_7i96s.0:     IO Pin 002 (TB3-03): InM Input Module #0, pin in2,enca1 (Input)
.......

@hdiethelm

Copy link
Copy Markdown
Contributor Author

It works:

Thanks for testing!

@hdiethelm

Copy link
Copy Markdown
Contributor Author

The last commit should theoretically solve the issue when two boards are on the same Ethernet interface using a switch. By first sending reset and then switching all interfaces from OOB to Posix, there should be no issue if the same interface is used for two boards. It also removes some duplicated code. But I can not test two boards, I have only one.

The way Xenomai4 is implemented, there is no error if you switch an interface twice to OOB or twice to Posix.

Tested again with posix and evl including the error cleanup case. I call this ready.

@hdiethelm
hdiethelm marked this pull request as ready for review September 6, 2026 21:19
//oob_enable_port needs: sockfd / server_addr / ip / ifname
//However, it must be called before the first ethernet
//communication in fetch_hwaddr.
ret = oob_enable_port(board);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If fetch_hwaddr() below fails here (board powered off, wrong IP), rtapi_app_main sets board_ip[i] = NULL, which makes cleanup() skip this board entirely. What state is the interface left in then, now that oob_enable_port() has already run? And what happens if the user retries afterwards with board_rtnet=posix on that same interface?

Would it make sense to call oob_disable_port() on any failure path after this point, so a failed init leaves nothing behind?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. In this case, the port will stay in oob mode until:

  • evl net -di PORT
  • Reboot
  • You run linuxcnc again with board_rtnet=evl. This works, I tested this case already.
  • board_rtnet=posix will indeed fail to connect the board.

I need to look into it. There is a similar issue in the posix variant since probably forever, not all is cleaned up in this case but it won't have any noticeable side effect, just the socket is leaked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, it should be fixed for posix and EVL. But I still have to test it tomorrow.
I found also an other bug in error handling I introduced in an old PR and fixed it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, should be fine now. I found one other missed error case and improved a few messages.
Tested all error cases in posix and evl, all is cleaned up fine and no crash.

@hdiethelm
hdiethelm force-pushed the hm2_eth_oob_improvements branch 2 times, most recently from 62bab83 to 9b9b247 Compare September 9, 2026 10:02
By attaching rtapi_app also to the EVL core, no posix initialization is
needed and all can be set up in rtapi_app_main().

Deprecate realtime-init, this function is not needed anymore.
This way, the specific network implementations don't have to know
anything about the firewall.
This should avoid an issue with hm2_eth_net_evl when an interface is
already set back to posix mode in close_board when an other instance
is using the same interface to reset an other board.

Also reduce duplicated code and improve reset message.
This is a bug introduced in LinuxCNC#4199. Restores the behaivour from before
where a failed ifname resulted in a skipped
install_firewall_perinterface but does continue. Additionally, add a
warning.

For OOB, ifname is mandatory to be able to switch the interface to OOB
mode.
The socket was leaked and oob was not disabled.
@hdiethelm
hdiethelm force-pushed the hm2_eth_oob_improvements branch from 9b9b247 to 9a871db Compare September 9, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants