Skip to contentSkip to conversation

can: usb: IXXAT USB-to-CAN adapters drivers

PATCH New Peter Seiderer 1 participant 3 messages Jul 7, 2023 CAN network drivers

lore
Share & tools
lore
#0 lore raw

PATCH v10 1/3 can: usb: IXXAT USB-to-CAN adapters drivers

From: Florian Ferg <[email protected]>

This patch adds the driver for the IXXAT USB-to-CAN interfaces. There is an adapter for the older communication layer cl1 and another adapter for the newer communication layer cl2.

---
Changes v1 -> v7 (Florian Ferg <[email protected]>):
- for detailed history see
https://codeberg.org/psreport/socketcan-linux-ix-usb-can

Changes v7 -> v8 (Marc Kleine-Budde <[email protected]>):
- port to recent net-next

Changes v8 -> v9 (Peter Seiderer <[email protected]>):
Addressed review comments by Vincent Mailhol:
- update copyright headers (use SPDX identifier 'GPL-2.0-only'
instead of 'GPL-2.0', remove full GPL boilerplate)
- reorder includes (lexicographic order)
- remove IXXAT_USB_MODES defines (move modes directly in the
declaration of structs)
- remove bittiming defines (move directly in declaration of structs)
- remove _EP1_IN/_EP1_OUT defines (move directly in declaration of structs)
- remove rcv_size/snd_size vars (use sizeof(*cmd) and sizeof(cmd->res) directly)
- use GENMASK/FIELD_PREP (IXXAT_USB_CAN_BTR1_TIME_SEG1_MASK/IXXAT_USB_CAN_BTR1_TIME_SEG2_MASK)
- update dev_err/netdev_err (use %pe, remove 'Error:' prefix)
- use U32_MAX instead of 0x00000000FFFFFFFF
- do not increase the rx_bytes count when receiving a remove frame
- ixxat_can_msg_cl1/ixxat_can_msg_cl2 use union __le32 status
- do not increase the statistics for error frames
- do not use parenthesis in log messages
- remove double brackets (sparse workaround for struct init)
- fill netdev->ethtool_ops with default
- fill netdev->dev_port
- use FIELD_GET/FIELD_PREP instead of IXXAT_USB_DECODE_DLC/IXXAT_USB_ENCODE_DLC
- use driver_info intead of open coded ixxat_usb_get_adapter
Addressed checkpatch.pl warnings:
- change MODULE_LICENSE to 'GPL' - checkpatch.pl WARNING: Prefer "GPL" over "GPL v2"

Changes v9 -> v10 (Peter Seiderer <[email protected]>):
Addressed review comments by Vincent Mailhol:
- use '8 * MEGA' in ixxat_usb_cl1.c for IXXAT_USB_CLOCK
- use '80 * MEGA' in ixxat_usb_cl2.c for IXXAT_USB_CLOCK
- direct set of cmd->mode in cl1 ixxat_usb_init_ctrl()
- direct set of cmd->btr0 and cmd->btr1 in cl1 ixxat_usb_init_ctrl()
- direct set of cmd->opmode in cl2 ixxat_usb_init_ctrl()
- direct set of cmd->exmode in cl2 ixxat_usb_init_ctrl()
- use 'void * const req' in ixxat_usb_send_cmd()
- avoid goto in ixxat_usb_send_cmd()
- avoid goto in ixxat_usb_restart()
- fix struct ixxat_tx_urb_context documentation (remove legacy/wrong dlc and count description)
- use 'u8 _padding[3]' in struct ixxat_usb_power_cmd
- remove IXXAT_USB_DRIVER_NAME, use KBUILD_MODNAME instead
- use IXXAT_USB_BUS_TYPE_MASK and FIELD_GET(IXXAT_USB_BUS_TYPE_MASK, type)
- use U16_MAX/U32_MAX/U32_MIN in ixxat_usb_setup_cmd()
- rename req/req_size to cmd/cmd_size in ixxat_usb_send_cmd
- use IXXAT_USB_REQ_SIZE and direct sizeof in ixxat_usb_stop_ctrl()
- use IXXAT_USB_REQ_SIZE and direct sizeof in ixxat_usb_power_ctrl()
- use direct sizeof in ixxat_usb_reset_ctrl()
- use IXXAT_USB_RES_SIZE and direct sizeof in ixxat_usb_get_dev_caps()
- use IXXAT_USB_RES_SIZE and direct sizeof in ixxat_usb_get_dev_info()
- use IXXAT_USB_RES_SIZE and direct sizeof in ixxat_usb_start_ctrl()
- avoid goto and remove unneded time_ref check in ixxat_usb_start_ctrl()
- use IXXAT_USB_REQ_SIZE in ixxat_usb_init_ctrl()
- restructure code in ixxat_usb_decode_buf (no opaque pointer, reduce message size if, reduce logging)
Additional changes:
- avoid possible overflow in ixxat_usb_decode_buf(), u8 vs. u16 for variable 'size' calculations
- update Kconfig text (add IXXAT CAN-IDM200)
- fix ep_msg_in vs ep_msg_out typo in ixxat_usb_probe (as already fixed

    in upstream driver ix_usb_can_2.0.366-REL)
---
 drivers/net/can/usb/Kconfig                   |   18 +
 drivers/net/can/usb/Makefile                  |    1 +
 drivers/net/can/usb/ixxat_usb/Makefile        |    2 +
 drivers/net/can/usb/ixxat_usb/ixxat_usb_cl1.c |  100 ++
 drivers/net/can/usb/ixxat_usb/ixxat_usb_cl2.c |  177 +++
 .../net/can/usb/ixxat_usb/ixxat_usb_core.c    | 1251 +++++++++++++++++
 .../net/can/usb/ixxat_usb/ixxat_usb_core.h    |  509 +++++++
 7 files changed, 2058 insertions(+)
 create mode 100644 drivers/net/can/usb/ixxat_usb/Makefile
 create mode 100644 drivers/net/can/usb/ixxat_usb/ixxat_usb_cl1.c
 create mode 100644 drivers/net/can/usb/ixxat_usb/ixxat_usb_cl2.c
 create mode 100644 drivers/net/can/usb/ixxat_usb/ixxat_usb_core.c
 create mode 100644 drivers/net/can/usb/ixxat_usb/ixxat_usb_core.h
drivers/net/can/usb/Kconfig +18 -0
index 58fcd2b34820..da4b49b318d2 100644
@@ -62,6 +62,24 @@ config CAN_GS_USB
 	  choose Y for built in support,
 	  M to compile as module (module will be named: gs_usb).
 
+config CAN_IXXAT_USB
+	tristate "IXXAT USB-to-CAN interfaces"
+	help
+	  This driver adds support for IXXAT USB-to-CAN devices.
+
+	  The driver provides support for the following devices:
+	    - IXXAT USB-to-CAN compact
+	    - IXXAT USB-to-CAN embedded
+	    - IXXAT USB-to-CAN professional
+	    - IXXAT USB-to-CAN automotive
+	    - IXXAT USB-to-CAN FD compact
+	    - IXXAT USB-to-CAN FD professional
+	    - IXXAT USB-to-CAN FD automotive
+	    - IXXAT USB-to-CAN FD MiniPCIe
+	    - IXXAT USB-to-CAR
+	    - IXXAT CAN-IDM101
+	    - IXXAT CAN-IDM200
+
 config CAN_KVASER_USB
 	tristate "Kvaser CAN/USB interface"
 	help
drivers/net/can/usb/Makefile +1 -0
index 8b11088e9a59..52b4cc66ff30 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_ESD_USB) += esd_usb.o
 obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x/
 obj-$(CONFIG_CAN_F81604) += f81604.o
 obj-$(CONFIG_CAN_GS_USB) += gs_usb.o
+obj-$(CONFIG_CAN_IXXAT_USB) += ixxat_usb/
 obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb/
 obj-$(CONFIG_CAN_MCBA_USB) += mcba_usb.o
 obj-$(CONFIG_CAN_PEAK_USB) += peak_usb/
drivers/net/can/usb/ixxat_usb/Makefile new file +2 -0
new file mode 100644
index 000000000000..125d2705979f
@@ -0,0 +1,2 @@
+obj-$(CONFIG_CAN_IXXAT_USB) += ixxat_usb2can.o
+ixxat_usb2can-y = ixxat_usb_cl1.o ixxat_usb_cl2.o ixxat_usb_core.o
drivers/net/can/usb/ixxat_usb/ixxat_usb_cl1.c new file +100 -0

100 lines not on this page · raw message

drivers/net/can/usb/ixxat_usb/ixxat_usb_cl2.c new file +177 -0

177 lines not on this page · raw message

drivers/net/can/usb/ixxat_usb/ixxat_usb_core.c new file +1251 -0

1,251 lines not on this page · raw message

drivers/net/can/usb/ixxat_usb/ixxat_usb_core.h new file +509 -0

509 lines not on this page · raw message

Signature · 1 line
2.41.0
#1 lore raw

PATCH v10 2/3 can: usb: ixxat_usb: add USB2CAN_PLUGIN_PRODUCT_ID (IXXAT USB Plugin)

- add USB2CAN_PLUGIN_PRODUCT_ID (IXXAT USB Plugin) support (backported from upstream driver ix_usb_can_2.0.366-REL)

---
Changes v9 -> v10 (Peter Seiderer <[email protected]>):
- new patch

---
 drivers/net/can/usb/Kconfig                    | 1 +
 drivers/net/can/usb/ixxat_usb/ixxat_usb_core.c | 2 ++
 drivers/net/can/usb/ixxat_usb/ixxat_usb_core.h | 1 +
 3 files changed, 4 insertions(+)
drivers/net/can/usb/Kconfig +1 -0
index da4b49b318d2..34deaa76f3a0 100644
@@ -72,6 +72,7 @@ config CAN_IXXAT_USB
 	    - IXXAT USB-to-CAN embedded
 	    - IXXAT USB-to-CAN professional
 	    - IXXAT USB-to-CAN automotive
+	    - IXXAT USB-to-CAN plugin
 	    - IXXAT USB-to-CAN FD compact
 	    - IXXAT USB-to-CAN FD professional
 	    - IXXAT USB-to-CAN FD automotive
drivers/net/can/usb/ixxat_usb/ixxat_usb_core.c +2 -0
index c2728f6d3fd0..894836bdeed3 100644
@@ -26,6 +26,8 @@ static const struct usb_device_id ixxat_usb_table[] = {
 	  .driver_info = (kernel_ulong_t)&usb2can_cl1, },
 	{ USB_DEVICE(IXXAT_USB_VENDOR_ID, USB2CAN_AUTOMOTIVE_PRODUCT_ID),
 	  .driver_info = (kernel_ulong_t)&usb2can_cl1, },
+	{ USB_DEVICE(IXXAT_USB_VENDOR_ID, USB2CAN_PLUGIN_PRODUCT_ID),
+	  .driver_info = (kernel_ulong_t)&usb2can_cl1, },
 	{ USB_DEVICE(IXXAT_USB_VENDOR_ID, USB2CAN_FD_COMPACT_PRODUCT_ID),
 	  .driver_info = (kernel_ulong_t)&usb2can_cl2, },
 	{ USB_DEVICE(IXXAT_USB_VENDOR_ID, USB2CAN_FD_PROFESSIONAL_PRODUCT_ID),
drivers/net/can/usb/ixxat_usb/ixxat_usb_core.h +1 -0
index a6ea6d682282..5810c481a875 100644
@@ -15,6 +15,7 @@
 #define USB2CAN_EMBEDDED_PRODUCT_ID 0x0009
 #define USB2CAN_PROFESSIONAL_PRODUCT_ID 0x000A
 #define USB2CAN_AUTOMOTIVE_PRODUCT_ID 0x000B
+#define USB2CAN_PLUGIN_PRODUCT_ID 0x001F
 
 /* supported device ids: CL2 */
 #define USB2CAN_FD_COMPACT_PRODUCT_ID 0x0014
Signature · 1 line
2.41.0
#2 lore raw

PATCH v10 3/3 can: usb: ixxat_usb: promote legacy adapters with up-todate firmware to cl2

In reply to Peter Seiderer

- add IXXAT_USB_BRD_CMD_GET_FWINFO support to retrieve firmware info and promote all legacy adapters with up-to-date firmware to communication layer cl2 (backported from upstream driver ix_usb_can_2.0.366-REL)

---
Changes v9 -> v10 (Peter Seiderer <[email protected]>):
- new patch

---
 drivers/net/can/usb/ixxat_usb/ixxat_usb_cl2.c | 40 +++++++++++++++++
 .../net/can/usb/ixxat_usb/ixxat_usb_core.c    | 44 +++++++++++++++++++
 .../net/can/usb/ixxat_usb/ixxat_usb_core.h    | 35 +++++++++++++++
 3 files changed, 119 insertions(+)
drivers/net/can/usb/ixxat_usb/ixxat_usb_cl2.c +40 -0
index 3c9d05c4b34f..07853607282f 100644
@@ -12,6 +12,8 @@
 
 #define IXXAT_USB_CLOCK (80 * MEGA /* Hz */)
 
+#define IXXAT_USBV2_CLOCK (36 * MEGA /* Hz */)
+
 #define IXXAT_USB_BUFFER_SIZE_RX 512
 #define IXXAT_USB_BUFFER_SIZE_TX 512
 
@@ -41,6 +43,18 @@ static const struct can_bittiming_const usb2can_btd = {
 	.brp_inc = 1,
 };
 
+static const struct can_bittiming_const usb2can_v2_bt = {
+	.name = IXXAT_USB_CTRL_NAME,
+	.tseg1_min = 1,
+	.tseg1_max = 16,
+	.tseg2_min = 1,
+	.tseg2_max = 8,
+	.sjw_max = 4,
+	.brp_min = 1,
+	.brp_max = 1024,
+	.brp_inc = 1,
+};
+
 static const struct can_bittiming_const canidm_bt = {
 	.name = IXXAT_USB_CTRL_NAME,
 	.tseg1_min = 1,
@@ -149,6 +163,32 @@ const struct ixxat_usb_adapter usb2can_cl2 = {
 	.init_ctrl = ixxat_usb_init_ctrl
 };
 
+const struct ixxat_usb_adapter usb2can_v2 = {
+	.clock = IXXAT_USBV2_CLOCK,
+	.bt = &usb2can_v2_bt,
+	.btd = NULL,
+	.modes = CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY |
+		CAN_CTRLMODE_BERR_REPORTING,
+	.buffer_size_rx = IXXAT_USB_BUFFER_SIZE_RX,
+	.buffer_size_tx = IXXAT_USB_BUFFER_SIZE_TX,
+	.ep_msg_in = {
+		1 | USB_DIR_IN,
+		2 | USB_DIR_IN,
+		3 | USB_DIR_IN,
+		4 | USB_DIR_IN,
+		5 | USB_DIR_IN
+	},
+	.ep_msg_out = {
+		1 | USB_DIR_IN,
+		2 | USB_DIR_IN,
+		3 | USB_DIR_IN,
+		4 | USB_DIR_IN,
+		5 | USB_DIR_IN
+	},
+	.ep_offs = 0,
+	.init_ctrl = ixxat_usb_init_ctrl
+};
+
 const struct ixxat_usb_adapter can_idm = {
 	.clock = IXXAT_USB_CLOCK,
 	.bt = &canidm_bt,
drivers/net/can/usb/ixxat_usb/ixxat_usb_core.c +44 -0

62 lines not on this page · raw message

drivers/net/can/usb/ixxat_usb/ixxat_usb_core.h +35 -0
index 5810c481a875..1c53d989d8fa 100644
@@ -101,6 +101,7 @@
 #define IXXAT_USB_CAN_CMD_STOP 0x327
 #define IXXAT_USB_CAN_CMD_RESET 0x328
 
+#define IXXAT_USB_BRD_CMD_GET_FWINFO  0x400
 #define IXXAT_USB_BRD_CMD_GET_DEVCAPS 0x401
 #define IXXAT_USB_BRD_CMD_GET_DEVINFO 0x402
 #define IXXAT_USB_BRD_CMD_POWER 0x421
@@ -217,6 +218,25 @@ struct ixxat_dev_info {
 	__le32 device_fpga_version;
 } __packed;
 
+/**
+ * struct ixxat_fw_info IXXAT usb firmware information
+ * @firmware_type: type of currently running firmware
+ * @reserved: reserved bytes
+ * @major_version: major firmware version number
+ * @minor_version: minor firmware version number
+ * @build_version: build firmware version number
+ *
+ * Contains firmware information of IXXAT USB devices
+ */
+
+struct ixxat_fw_info {
+	__le32 firmware_type;
+	u8 reserved[2];
+	__le16 major_version;
+	__le16 minor_version;
+	__le16 build_version;
+} __packed;
+
 /**
  * struct ixxat_time_ref Time reference
  * @kt_host_0: Latest time on the host
@@ -449,6 +469,20 @@ struct ixxat_usb_info_cmd {
 	struct ixxat_dev_info info;
 } __packed;
 
+/**
+ * struct ixxat_usb_fwinfo_cmd Firmware information command
+ * @req: Request block
+ * @res: Response block
+ * @fw_info: Firmware information
+ *
+ * Can be sent to a device to request its firmware information
+ */
+struct ixxat_usb_fwinfo_cmd {
+	struct ixxat_usb_dal_req req;
+	struct ixxat_usb_dal_res res;
+	struct ixxat_fw_info fw_info;
+} __packed;
+
 /**
  * struct ixxat_usb_adapter IXXAT USB device adapter
  * @clock: Clock frequency
@@ -478,6 +512,7 @@ struct ixxat_usb_adapter {
 
 extern const struct ixxat_usb_adapter usb2can_cl1;
 extern const struct ixxat_usb_adapter usb2can_cl2;
+extern const struct ixxat_usb_adapter usb2can_v2;
 extern const struct ixxat_usb_adapter can_idm;
 
 /**
Signature · 1 line
2.41.0