From fe74ffe2d51a5e15bb77ecb8cc4f2170d8b1cbde Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Sun, 10 Dec 2023 22:03:41 +0100 Subject: [PATCH] drivers: can: drop POSIX from the native Linux SocketCAN driver name Rename the native Linux SocketCAN driver to reflect that it can can now be used in both native_posix and native_sim (with or without an embedded C-library). Signed-off-by: Henrik Brix Andersen --- boards/posix/native_sim/doc/index.rst | 2 +- boards/posix/native_sim/native_sim.dts | 2 +- doc/releases/migration-guide-3.6.rst | 9 ++ doc/releases/release-notes-3.2.rst | 2 +- drivers/can/CMakeLists.txt | 12 +- drivers/can/Kconfig | 2 +- ...ative_posix_linux => Kconfig.native_linux} | 10 +- ...ative_posix_linux.c => can_native_linux.c} | 128 +++++++++--------- ...x_socketcan.c => can_native_linux_adapt.c} | 2 +- ...x_socketcan.h => can_native_linux_adapt.h} | 0 ...-can.yaml => zephyr,native-linux-can.yaml} | 2 +- tests/drivers/build_all/can/testcase.yaml | 2 +- 12 files changed, 92 insertions(+), 81 deletions(-) rename drivers/can/{Kconfig.native_posix_linux => Kconfig.native_linux} (76%) rename drivers/can/{can_native_posix_linux.c => can_native_linux.c} (69%) rename drivers/can/{can_native_posix_linux_socketcan.c => can_native_linux_adapt.c} (98%) rename drivers/can/{can_native_posix_linux_socketcan.h => can_native_linux_adapt.h} (100%) rename dts/bindings/can/{zephyr,native-posix-linux-can.yaml => zephyr,native-linux-can.yaml} (87%) diff --git a/boards/posix/native_sim/doc/index.rst b/boards/posix/native_sim/doc/index.rst index b88f5283dc3..b92d0bf911a 100644 --- a/boards/posix/native_sim/doc/index.rst +++ b/boards/posix/native_sim/doc/index.rst @@ -615,7 +615,7 @@ host libC (:kconfig:option:`CONFIG_EXTERNAL_LIBC`): adc, ADC emul, :kconfig:option:`CONFIG_ADC_EMUL`, all bluetooth, userchan, :kconfig:option:`CONFIG_BT_USERCHAN`, host libC - can, can native posix, :kconfig:option:`CONFIG_CAN_NATIVE_POSIX_LINUX`, all + can, can native Linux, :kconfig:option:`CONFIG_CAN_NATIVE_LINUX`, all console backend, POSIX arch console, :kconfig:option:`CONFIG_POSIX_ARCH_CONSOLE`, all display, display SDL, :kconfig:option:`CONFIG_SDL_DISPLAY`, all entropy, native posix entropy, :kconfig:option:`CONFIG_FAKE_ENTROPY_NATIVE_POSIX`, all diff --git a/boards/posix/native_sim/native_sim.dts b/boards/posix/native_sim/native_sim.dts index 26a38593484..682049c63ca 100644 --- a/boards/posix/native_sim/native_sim.dts +++ b/boards/posix/native_sim/native_sim.dts @@ -195,7 +195,7 @@ can0: can { status = "disabled"; - compatible = "zephyr,native-posix-linux-can"; + compatible = "zephyr,native-linux-can"; /* adjust zcan0 to desired host interface or create an alternative * name, e.g.: sudo ip link property add dev vcan0 altname zcan0 */ diff --git a/doc/releases/migration-guide-3.6.rst b/doc/releases/migration-guide-3.6.rst index f22e921fa15..c944a2ae4c6 100644 --- a/doc/releases/migration-guide-3.6.rst +++ b/doc/releases/migration-guide-3.6.rst @@ -128,6 +128,15 @@ Device Drivers and Device Tree status = "okay"; }; +* The native Linux SocketCAN driver, which can now be used in both :ref:`native_posix` + and :ref:`native_sim` with or without an embedded C-library, has been renamed to + reflect this: + + * The devicetree compatible was renamed from ``zephyr,native-posix-linux-can`` to + :dtcompatible:`zephyr,native-linux-can`. + * The main Kconfig option was renamed from ``CONFIG_CAN_NATIVE_POSIX_LINUX`` to + :kconfig:option:`CONFIG_CAN_NATIVE_LINUX`. + Power Management ================ diff --git a/doc/releases/release-notes-3.2.rst b/doc/releases/release-notes-3.2.rst index d902ac4481b..cf27f017fcb 100644 --- a/doc/releases/release-notes-3.2.rst +++ b/doc/releases/release-notes-3.2.rst @@ -1166,7 +1166,7 @@ Devicetree * :dtcompatible:`zephyr,coredump` * :dtcompatible:`zephyr,ieee802154-uart-pipe` * :dtcompatible:`zephyr,native-posix-counter` - * :dtcompatible:`zephyr,native-posix-linux-can` + * ``zephyr,native-posix-linux-can`` * :dtcompatible:`zephyr,sdl-kscan` * :dtcompatible:`zephyr,sdmmc-disk` * :dtcompatible:`zephyr,w1-serial` diff --git a/drivers/can/CMakeLists.txt b/drivers/can/CMakeLists.txt index 18e3ba67ac8..e704402e1fd 100644 --- a/drivers/can/CMakeLists.txt +++ b/drivers/can/CMakeLists.txt @@ -28,21 +28,21 @@ zephyr_library_sources_ifdef(CONFIG_USERSPACE can_handlers.c) zephyr_library_sources_ifdef(CONFIG_CAN_SHELL can_shell.c) zephyr_library_sources_ifdef(CONFIG_CAN_NXP_S32_CANXL can_nxp_s32_canxl.c) -if(CONFIG_CAN_NATIVE_POSIX_LINUX) +if(CONFIG_CAN_NATIVE_LINUX) if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Linux) zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/l2) - zephyr_library_sources(can_native_posix_linux.c) + zephyr_library_sources(can_native_linux.c) if (CONFIG_NATIVE_APPLICATION) - set_source_files_properties(can_native_posix_linux_socketcan.c + set_source_files_properties(can_native_linux_adapt.c PROPERTIES COMPILE_DEFINITIONS "NO_POSIX_CHEATS;_BSD_SOURCE;_DEFAULT_SOURCE") - zephyr_library_sources(can_native_posix_linux_socketcan.c) + zephyr_library_sources(can_native_linux_adapt.c) else() - target_sources(native_simulator INTERFACE can_native_posix_linux_socketcan.c) + target_sources(native_simulator INTERFACE can_native_linux_adapt.c) endif() else() - message(FATAL_ERROR "CONFIG_CAN_NATIVE_POSIX_LINUX only available on Linux") + message(FATAL_ERROR "CONFIG_CAN_NATIVE_LINUX is only available on Linux") endif() endif() diff --git a/drivers/can/Kconfig b/drivers/can/Kconfig index ed0818d3508..e4fd4709505 100644 --- a/drivers/can/Kconfig +++ b/drivers/can/Kconfig @@ -93,7 +93,7 @@ source "drivers/can/Kconfig.mcan" source "drivers/can/Kconfig.rcar" source "drivers/can/Kconfig.numaker" source "drivers/can/Kconfig.loopback" -source "drivers/can/Kconfig.native_posix_linux" +source "drivers/can/Kconfig.native_linux" source "drivers/can/Kconfig.sja1000" source "drivers/can/Kconfig.esp32" source "drivers/can/Kconfig.kvaser" diff --git a/drivers/can/Kconfig.native_posix_linux b/drivers/can/Kconfig.native_linux similarity index 76% rename from drivers/can/Kconfig.native_posix_linux rename to drivers/can/Kconfig.native_linux index f11006ec6da..54969fd7de1 100644 --- a/drivers/can/Kconfig.native_posix_linux +++ b/drivers/can/Kconfig.native_linux @@ -3,17 +3,17 @@ # Copyright (c) 2022 Martin Jäger # SPDX-License-Identifier: Apache-2.0 -config CAN_NATIVE_POSIX_LINUX +config CAN_NATIVE_LINUX bool "Native Linux SocketCAN Driver" default y - depends on DT_HAS_ZEPHYR_NATIVE_POSIX_LINUX_CAN_ENABLED + depends on DT_HAS_ZEPHYR_NATIVE_LINUX_CAN_ENABLED depends on ARCH_POSIX help Enable native Linux SocketCAN Driver -if CAN_NATIVE_POSIX_LINUX +if CAN_NATIVE_LINUX -config CAN_NATIVE_POSIX_LINUX_RX_THREAD_PRIORITY +config CAN_NATIVE_LINUX_RX_THREAD_PRIORITY int "Priority for internal RX thread" default 2 help @@ -28,4 +28,4 @@ config CAN_MAX_FILTER Defines the array size of the callback/msgq pointers. Must be at least the size of concurrent reads. -endif # CAN_NATIVE_POSIX_LINUX +endif # CAN_NATIVE_LINUX diff --git a/drivers/can/can_native_posix_linux.c b/drivers/can/can_native_linux.c similarity index 69% rename from drivers/can/can_native_posix_linux.c rename to drivers/can/can_native_linux.c index 7f8a0ea494f..5ada2a5b47c 100644 --- a/drivers/can/can_native_posix_linux.c +++ b/drivers/can/can_native_linux.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define DT_DRV_COMPAT zephyr_native_posix_linux_can +#define DT_DRV_COMPAT zephyr_native_linux_can #include #include @@ -17,9 +17,9 @@ #include #include -#include "can_native_posix_linux_socketcan.h" +#include "can_native_linux_adapt.h" -LOG_MODULE_REGISTER(can_npl, CONFIG_CAN_LOG_LEVEL); +LOG_MODULE_REGISTER(can_native_linux, CONFIG_CAN_LOG_LEVEL); struct can_filter_context { can_rx_callback_t rx_cb; @@ -27,7 +27,7 @@ struct can_filter_context { struct can_filter filter; }; -struct can_npl_data { +struct can_native_linux_data { struct can_filter_context filters[CONFIG_CAN_MAX_FILTER]; struct k_mutex filter_mutex; struct k_sem tx_idle; @@ -42,13 +42,13 @@ struct can_npl_data { K_KERNEL_STACK_MEMBER(rx_thread_stack, CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE); }; -struct can_npl_config { +struct can_native_linux_config { const char *if_name; }; static void dispatch_frame(const struct device *dev, struct can_frame *frame) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; can_rx_callback_t callback; struct can_frame tmp_frame; @@ -76,7 +76,7 @@ static void dispatch_frame(const struct device *dev, struct can_frame *frame) static void rx_thread(void *arg1, void *arg2, void *arg3) { const struct device *dev = arg1; - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; struct socketcan_frame sframe; struct can_frame frame; bool msg_confirm; @@ -113,15 +113,15 @@ static void rx_thread(void *arg1, void *arg2, void *arg3) dispatch_frame(dev, &frame); } - /* short sleep required to avoid blocking the whole native_posix process */ + /* short sleep required to avoid blocking the whole native process */ k_sleep(K_MSEC(1)); } } -static int can_npl_send(const struct device *dev, const struct can_frame *frame, - k_timeout_t timeout, can_tx_callback_t callback, void *user_data) +static int can_native_linux_send(const struct device *dev, const struct can_frame *frame, + k_timeout_t timeout, can_tx_callback_t callback, void *user_data) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; struct socketcan_frame sframe; uint8_t max_dlc = CAN_MAX_DLC; size_t mtu = CAN_MTU; @@ -187,10 +187,10 @@ static int can_npl_send(const struct device *dev, const struct can_frame *frame, return 0; } -static int can_npl_add_rx_filter(const struct device *dev, can_rx_callback_t cb, - void *cb_arg, const struct can_filter *filter) +static int can_native_linux_add_rx_filter(const struct device *dev, can_rx_callback_t cb, + void *cb_arg, const struct can_filter *filter) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; struct can_filter_context *filter_ctx; int filter_id = -ENOSPC; @@ -234,9 +234,9 @@ static int can_npl_add_rx_filter(const struct device *dev, can_rx_callback_t cb, return filter_id; } -static void can_npl_remove_rx_filter(const struct device *dev, int filter_id) +static void can_native_linux_remove_rx_filter(const struct device *dev, int filter_id) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; if (filter_id < 0 || filter_id >= ARRAY_SIZE(data->filters)) { LOG_ERR("filter ID %d out of bounds"); @@ -250,7 +250,7 @@ static void can_npl_remove_rx_filter(const struct device *dev, int filter_id) LOG_DBG("Filter removed. ID: %d", filter_id); } -static int can_npl_get_capabilities(const struct device *dev, can_mode_t *cap) +static int can_native_linux_get_capabilities(const struct device *dev, can_mode_t *cap) { ARG_UNUSED(dev); @@ -263,9 +263,9 @@ static int can_npl_get_capabilities(const struct device *dev, can_mode_t *cap) return 0; } -static int can_npl_start(const struct device *dev) +static int can_native_linux_start(const struct device *dev) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; if (data->started) { return -EALREADY; @@ -276,9 +276,9 @@ static int can_npl_start(const struct device *dev) return 0; } -static int can_npl_stop(const struct device *dev) +static int can_native_linux_stop(const struct device *dev) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; if (!data->started) { return -EALREADY; @@ -289,9 +289,9 @@ static int can_npl_stop(const struct device *dev) return 0; } -static int can_npl_set_mode(const struct device *dev, can_mode_t mode) +static int can_native_linux_set_mode(const struct device *dev, can_mode_t mode) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; #ifdef CONFIG_CAN_FD_MODE if ((mode & ~(CAN_MODE_LOOPBACK | CAN_MODE_FD)) != 0) { @@ -318,9 +318,9 @@ static int can_npl_set_mode(const struct device *dev, can_mode_t mode) return 0; } -static int can_npl_set_timing(const struct device *dev, const struct can_timing *timing) +static int can_native_linux_set_timing(const struct device *dev, const struct can_timing *timing) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; ARG_UNUSED(timing); @@ -332,9 +332,10 @@ static int can_npl_set_timing(const struct device *dev, const struct can_timing } #ifdef CONFIG_CAN_FD_MODE -static int can_npl_set_timing_data(const struct device *dev, const struct can_timing *timing) +static int can_native_linux_set_timing_data(const struct device *dev, + const struct can_timing *timing) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; ARG_UNUSED(timing); @@ -346,10 +347,10 @@ static int can_npl_set_timing_data(const struct device *dev, const struct can_ti } #endif /* CONFIG_CAN_FD_MODE */ -static int can_npl_get_state(const struct device *dev, enum can_state *state, - struct can_bus_err_cnt *err_cnt) +static int can_native_linux_get_state(const struct device *dev, enum can_state *state, + struct can_bus_err_cnt *err_cnt) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; if (state != NULL) { if (!data->started) { @@ -369,9 +370,9 @@ static int can_npl_get_state(const struct device *dev, enum can_state *state, } #ifndef CONFIG_CAN_AUTO_BUS_OFF_RECOVERY -static int can_npl_recover(const struct device *dev, k_timeout_t timeout) +static int can_native_linux_recover(const struct device *dev, k_timeout_t timeout) { - struct can_npl_data *data = dev->data; + struct can_native_linux_data *data = dev->data; ARG_UNUSED(timeout); @@ -383,16 +384,16 @@ static int can_npl_recover(const struct device *dev, k_timeout_t timeout) } #endif /* CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */ -static void can_npl_set_state_change_callback(const struct device *dev, - can_state_change_callback_t cb, - void *user_data) +static void can_native_linux_set_state_change_callback(const struct device *dev, + can_state_change_callback_t cb, + void *user_data) { ARG_UNUSED(dev); ARG_UNUSED(cb); ARG_UNUSED(user_data); } -static int can_npl_get_core_clock(const struct device *dev, uint32_t *rate) +static int can_native_linux_get_core_clock(const struct device *dev, uint32_t *rate) { /* Return 16MHz as an realistic value for the testcases */ *rate = 16000000; @@ -400,29 +401,29 @@ static int can_npl_get_core_clock(const struct device *dev, uint32_t *rate) return 0; } -static int can_npl_get_max_filters(const struct device *dev, bool ide) +static int can_native_linux_get_max_filters(const struct device *dev, bool ide) { ARG_UNUSED(ide); return CONFIG_CAN_MAX_FILTER; } -static const struct can_driver_api can_npl_driver_api = { - .start = can_npl_start, - .stop = can_npl_stop, - .get_capabilities = can_npl_get_capabilities, - .set_mode = can_npl_set_mode, - .set_timing = can_npl_set_timing, - .send = can_npl_send, - .add_rx_filter = can_npl_add_rx_filter, - .remove_rx_filter = can_npl_remove_rx_filter, - .get_state = can_npl_get_state, +static const struct can_driver_api can_native_linux_driver_api = { + .start = can_native_linux_start, + .stop = can_native_linux_stop, + .get_capabilities = can_native_linux_get_capabilities, + .set_mode = can_native_linux_set_mode, + .set_timing = can_native_linux_set_timing, + .send = can_native_linux_send, + .add_rx_filter = can_native_linux_add_rx_filter, + .remove_rx_filter = can_native_linux_remove_rx_filter, + .get_state = can_native_linux_get_state, #ifndef CONFIG_CAN_AUTO_BUS_OFF_RECOVERY - .recover = can_npl_recover, + .recover = can_native_linux_recover, #endif - .set_state_change_callback = can_npl_set_state_change_callback, - .get_core_clock = can_npl_get_core_clock, - .get_max_filters = can_npl_get_max_filters, + .set_state_change_callback = can_native_linux_set_state_change_callback, + .get_core_clock = can_native_linux_get_core_clock, + .get_max_filters = can_native_linux_get_max_filters, .timing_min = { .sjw = 0x1, .prop_seg = 0x01, @@ -438,7 +439,7 @@ static const struct can_driver_api can_npl_driver_api = { .prescaler = 0xFFFF }, #ifdef CONFIG_CAN_FD_MODE - .set_timing_data = can_npl_set_timing_data, + .set_timing_data = can_native_linux_set_timing_data, .timing_data_min = { .sjw = 0x1, .prop_seg = 0x01, @@ -456,10 +457,10 @@ static const struct can_driver_api can_npl_driver_api = { #endif /* CONFIG_CAN_FD_MODE */ }; -static int can_npl_init(const struct device *dev) +static int can_native_linux_init(const struct device *dev) { - const struct can_npl_config *cfg = dev->config; - struct can_npl_data *data = dev->data; + const struct can_native_linux_config *cfg = dev->config; + struct can_native_linux_data *data = dev->data; k_mutex_init(&data->filter_mutex); k_sem_init(&data->tx_idle, 1, 1); @@ -473,7 +474,7 @@ static int can_npl_init(const struct device *dev) k_thread_create(&data->rx_thread, data->rx_thread_stack, K_KERNEL_STACK_SIZEOF(data->rx_thread_stack), rx_thread, (void *)dev, NULL, NULL, - CONFIG_CAN_NATIVE_POSIX_LINUX_RX_THREAD_PRIORITY, + CONFIG_CAN_NATIVE_LINUX_RX_THREAD_PRIORITY, 0, K_NO_WAIT); LOG_DBG("Init of %s done", dev->name); @@ -481,17 +482,18 @@ static int can_npl_init(const struct device *dev) return 0; } -#define CAN_NATIVE_POSIX_LINUX_INIT(inst) \ +#define CAN_NATIVE_LINUX_INIT(inst) \ \ -static const struct can_npl_config can_npl_cfg_##inst = { \ +static const struct can_native_linux_config can_native_linux_cfg_##inst = { \ .if_name = DT_INST_PROP(inst, host_interface), \ }; \ \ -static struct can_npl_data can_npl_data_##inst; \ +static struct can_native_linux_data can_native_linux_data_##inst; \ \ -CAN_DEVICE_DT_INST_DEFINE(inst, can_npl_init, NULL, \ - &can_npl_data_##inst, &can_npl_cfg_##inst, \ +CAN_DEVICE_DT_INST_DEFINE(inst, can_native_linux_init, NULL, \ + &can_native_linux_data_##inst, \ + &can_native_linux_cfg_##inst, \ POST_KERNEL, CONFIG_CAN_INIT_PRIORITY, \ - &can_npl_driver_api); + &can_native_linux_driver_api); -DT_INST_FOREACH_STATUS_OKAY(CAN_NATIVE_POSIX_LINUX_INIT) +DT_INST_FOREACH_STATUS_OKAY(CAN_NATIVE_LINUX_INIT) diff --git a/drivers/can/can_native_posix_linux_socketcan.c b/drivers/can/can_native_linux_adapt.c similarity index 98% rename from drivers/can/can_native_posix_linux_socketcan.c rename to drivers/can/can_native_linux_adapt.c index 63b955e76e3..675dd01de79 100644 --- a/drivers/can/can_native_posix_linux_socketcan.c +++ b/drivers/can/can_native_linux_adapt.c @@ -34,7 +34,7 @@ #error "This driver can only be built on Linux systems" #endif -#include "can_native_posix_linux_socketcan.h" +#include "can_native_linux_adapt.h" #ifndef CANFD_FDF /* Linux kernels before v5.14 do not define CANFD_FDF */ diff --git a/drivers/can/can_native_posix_linux_socketcan.h b/drivers/can/can_native_linux_adapt.h similarity index 100% rename from drivers/can/can_native_posix_linux_socketcan.h rename to drivers/can/can_native_linux_adapt.h diff --git a/dts/bindings/can/zephyr,native-posix-linux-can.yaml b/dts/bindings/can/zephyr,native-linux-can.yaml similarity index 87% rename from dts/bindings/can/zephyr,native-posix-linux-can.yaml rename to dts/bindings/can/zephyr,native-linux-can.yaml index 275019a2c9e..4175617403b 100644 --- a/dts/bindings/can/zephyr,native-posix-linux-can.yaml +++ b/dts/bindings/can/zephyr,native-linux-can.yaml @@ -3,7 +3,7 @@ description: Zephyr CAN driver using Linux SocketCAN -compatible: "zephyr,native-posix-linux-can" +compatible: "zephyr,native-linux-can" include: can-controller.yaml diff --git a/tests/drivers/build_all/can/testcase.yaml b/tests/drivers/build_all/can/testcase.yaml index 6cce877620e..bf38398ed4b 100644 --- a/tests/drivers/build_all/can/testcase.yaml +++ b/tests/drivers/build_all/can/testcase.yaml @@ -19,7 +19,7 @@ tests: drivers.can.build_all.mcp251xfd: extra_args: SHIELD=mikroe_mcp2518fd_click platform_allow: lpcxpresso55s28 - drivers.can.build_all.native_posix_linux: + drivers.can.build_all.native_linux: platform_allow: - native_posix - native_posix_64