Skip to contentSkip to conversation

char: xillybus: Add driver for XillyUSB (Xillybus variant for USB)

PATCH Superseded [email protected] 3 participants 9 messages Dec 13, 2020 – Jan 8, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 char: xillybus: Add driver for XillyUSB (Xillybus variant for USB)

From: Eli Billauer <[email protected]>

The XillyUSB driver is the USB variant for the Xillybus FPGA IP core. Even though it presents a nearly identical API on the FPGA and host, it's almost a complete rewrite of the driver: The framework for exchanging data on a USB bus is fundamentally different from doing the same with a PCIe interface, which leaves very little in common between the existing driver and the new one for XillyUSB.

---
 drivers/char/xillybus/Kconfig    |   11 +
 drivers/char/xillybus/Makefile   |    1 +
 drivers/char/xillybus/xillyusb.c | 2363 ++++++++++++++++++++++++++++++
 3 files changed, 2375 insertions(+)
 create mode 100644 drivers/char/xillybus/xillyusb.c
drivers/char/xillybus/Kconfig +11 -0
index 130dbdce858f..18fa99ec1029 100644
@@ -32,3 +32,14 @@ config XILLYBUS_OF
 	  system, say M.
 
 endif # if XILLYBUS
+
+config XILLYUSB
+	tristate "XillyUSB: Xillybus generic FPGA interface for USB"
+	depends on USB
+	select CRC32
+	help
+	  XillyUSB is the Xillybus variant which uses USB for communicating
+	  with the FPGA.
+
+	  Set to M if you want Xillybus to use USB for communicating with
+	  the FPGA.
drivers/char/xillybus/Makefile +1 -0
index 099e9a3585fc..57471fb61a12 100644
@@ -6,3 +6,4 @@
 obj-$(CONFIG_XILLYBUS)		+= xillybus_core.o
 obj-$(CONFIG_XILLYBUS_PCIE)	+= xillybus_pcie.o
 obj-$(CONFIG_XILLYBUS_OF)	+= xillybus_of.o
+obj-$(CONFIG_XILLYUSB)		+= xillyusb.o
drivers/char/xillybus/xillyusb.c new file +2363 -0

2,363 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

drivers/char/xillybus/Kconfig config XILLYBUS_OF · line 35

Quoted 9 lines · On 12/13/20 9:05 AM, [email protected] wrote:
drivers/char/xillybus/Kconfig +1 -0
index 130dbdce858f..18fa99ec1029 100644
@@ -32,3 +32,14 @@ config XILLYBUS_OF
 	  system, say M.
 
 endif # if XILLYBUS
+

Hi Eli,

You don't want this new part inside the "if XILLYBUS" block above? IOW, XILLYUSB does not need XILLYBUS?

drivers/char/xillybus/Kconfig config XILLYBUS_OF · line 45

Quoted 10 lines
drivers/char/xillybus/Kconfig +10 -0
+config XILLYUSB
+	tristate "XillyUSB: Xillybus generic FPGA interface for USB"
+	depends on USB
+	select CRC32
+	help
+	  XillyUSB is the Xillybus variant which uses USB for communicating
+	  with the FPGA.
+
+	  Set to M if you want Xillybus to use USB for communicating with
+	  the FPGA.

thanks.

Signature · 1 line
~Randy
author maintainer
#2 lore raw

Hello Randy,

The new driver doesn't depend on XILLYBUS, so the patch puts it correctly outside the "if XILLYBUS" clause. It indeed looks like a mistake, but it isn't. :)

Thanks for paying attention to this.

Regards,
Eli

Quoted 31 lines · Randy Dunlap

drivers/char/xillybus/Kconfig config XILLYBUS_OF · line 35

Quoted 10 lines · On 12/13/20 9:05 AM, [email protected] wrote:
drivers/char/xillybus/Kconfig +1 -0
index 130dbdce858f..18fa99ec1029 100644
@@ -32,3 +32,14 @@ config XILLYBUS_OF
  	  system, say M.
 
  endif # if XILLYBUS
+

Hi Eli,

You don't want this new part inside the "if XILLYBUS" block above? IOW, XILLYUSB does not need XILLYBUS?

drivers/char/xillybus/Kconfig config XILLYBUS_OF · line 45

Quoted 11 lines
drivers/char/xillybus/Kconfig +10 -0
+config XILLYUSB
+	tristate "XillyUSB: Xillybus generic FPGA interface for USB"
+	depends on USB
+	select CRC32
+	help
+	  XillyUSB is the Xillybus variant which uses USB for communicating
+	  with the FPGA.
+
+	  Set to M if you want Xillybus to use USB for communicating with
+	  the FPGA.

thanks.

maintainer
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Sun, Dec 13, 2020 at 07:05:03PM +0200, [email protected] wrote:

From: Eli Billauer <[email protected]>

The XillyUSB driver is the USB variant for the Xillybus FPGA IP core. Even though it presents a nearly identical API on the FPGA and host, it's almost a complete rewrite of the driver: The framework for exchanging data on a USB bus is fundamentally different from doing the same with a PCIe interface, which leaves very little in common between the existing driver and the new one for XillyUSB.

But in this one you are talking to userspace directly through a char node, why not use the same interface that the xillybus_core.c code uses? Creating yet-another-class-device feels odd when you already have one that is in use.

Try to merge them together to use the same framework, or document the heck out of why this is somehow different, yet looks the same...

thanks,

greg k-h

author maintainer
#4 lore raw

Hello Greg,

Merging XillyUSB's driver into xillybus_core.c was of course the initial idea. Practically, it turned out that this doesn't reduce the number of code lines nor makes the code easier to understand: The XillyUSB driver is a completely different deal internally, in almost every aspect of it.

Indeed, the two drivers do basically the same thing: They create a pipe-like API using a hardware interface that is based upon buffers. This is what most of the code in both drivers is about. As this underlying hardware interface is so fundamentally different, there is little in common between the drivers.

The existing xillybus_core.c driver is based upon direct memory register + DMA interaction with the hardware. XillyUSB relies on the USB framework for all communication. I'll try to demonstrate the practical differences with two examples.

(1) Sending commands to the hardware: The existing Xillybus driver just writes to registers in memory space. Its XillyUSB counterpart calls xillyusb_send_opcode() to prepare a little packet for transmission over USB, and may possibly sleep if there's a (temporary) lack of resources to complete that task.

(2) Data handling: The existing Xillybus driver just copies user data to and from DMA buffers. Its main business is to maintain and juggle these buffers with the hardware. The XillyUSB driver, on the other hand, manages a pool of URBs to efficiently shuffle the data to and from the hardware. The main challenge is to keep the data flowing at 400 MB/s.

This goes on for every single aspect of the two drivers: They do the same things essentially, but the actual actions are completely different, as they have different means to do get the job done. And completely different challenges.

The only sensible code reuse I can see, is to merge the new "xillyusb" device class into the existing "xillybus" class in a new common module file, say xillybus_class.c. Maybe also move the code snippets in the open() methods which look for a major/minor match to that new file. I don't expect that to reduce the total amount of code lines, nor make it friendlier to read. But this will reuse the existing device class name instead of creating a new one. Does this sound like a good idea?

Thanks and regards,
Eli

Quoted 24 lines · Greg KH
Quoted 9 lines · On Sun, Dec 13, 2020 at 07:05:03PM +0200,[email protected] wrote:

From: Eli Billauer<[email protected]>

The XillyUSB driver is the USB variant for the Xillybus FPGA IP core. Even though it presents a nearly identical API on the FPGA and host, it's almost a complete rewrite of the driver: The framework for exchanging data on a USB bus is fundamentally different from doing the same with a PCIe interface, which leaves very little in common between the existing driver and the new one for XillyUSB.

But in this one you are talking to userspace directly through a char node, why not use the same interface that the xillybus_core.c code uses? Creating yet-another-class-device feels odd when you already have one that is in use.

Try to merge them together to use the same framework, or document the heck out of why this is somehow different, yet looks the same...

thanks,

greg k-h

maintainer
#5 lore raw
Quoted 30 lines · Eli Billauer

Hello Greg,

Merging XillyUSB's driver into xillybus_core.c was of course the initial idea. Practically, it turned out that this doesn't reduce the number of code lines nor makes the code easier to understand: The XillyUSB driver is a completely different deal internally, in almost every aspect of it.

Indeed, the two drivers do basically the same thing: They create a pipe-like API using a hardware interface that is based upon buffers. This is what most of the code in both drivers is about. As this underlying hardware interface is so fundamentally different, there is little in common between the drivers.

The existing xillybus_core.c driver is based upon direct memory register + DMA interaction with the hardware. XillyUSB relies on the USB framework for all communication. I'll try to demonstrate the practical differences with two examples.

(1) Sending commands to the hardware: The existing Xillybus driver just writes to registers in memory space. Its XillyUSB counterpart calls xillyusb_send_opcode() to prepare a little packet for transmission over USB, and may possibly sleep if there's a (temporary) lack of resources to complete that task.

(2) Data handling: The existing Xillybus driver just copies user data to and from DMA buffers. Its main business is to maintain and juggle these buffers with the hardware. The XillyUSB driver, on the other hand, manages a pool of URBs to efficiently shuffle the data to and from the hardware. The main challenge is to keep the data flowing at 400 MB/s.

Quoted 4 lines

This goes on for every single aspect of the two drivers: They do the same things essentially, but the actual actions are completely different, as they have different means to do get the job done. And completely different challenges.

That's fine, but I'm talking about the userspace api. You should not be creating two different userspace apis just because the bus transport changed for the hardware.

We don't do that for things like tty devices, right? :)

So please, share the same core code that exports the api to userspace to be common, do not create a new one, like you did here.

thanks,

greg k-h

author maintainer
#6 lore raw

Hello, Greg.

I'm afraid we're not on the same page. As mentioned in the original patch description, XillyUSB and the existing Xillybus variant presents a nearly identical API. User space programs see no difference when using one or the other, except for different device file names. In that sense, it's exactly like tty devices. But unlike ttys, there are no ioctls or any other special API functions to export. Xillybus' API consists only of the basic file operations, which behave like you'd expect from a pipe, more or less.

So even though one would usually expect this API similarity to take the form of common core routines, as it did with xillybus_pcie and xillybus_of, there is very little of that regarding XillyUSB. This is what I tried to explain in my previous mail: Why this common core is very slim.

I can see the benefit of maintaining the formal structure of a single entry point for the fops for all Xillybus variants. However my understanding while writing the XillyUSB driver was that sticking to this structure would be quite artificial, and that it would mess up things more than anything else.

Or have I misunderstood your concern about this patch?

Thanks and regards,
Eli

Quoted 47 lines · Greg KH
Quoted 30 lines · Eli Billauer
Quoted 30 lines

Hello Greg,

Merging XillyUSB's driver into xillybus_core.c was of course the initial idea. Practically, it turned out that this doesn't reduce the number of code lines nor makes the code easier to understand: The XillyUSB driver is a completely different deal internally, in almost every aspect of it.

Indeed, the two drivers do basically the same thing: They create a pipe-like API using a hardware interface that is based upon buffers. This is what most of the code in both drivers is about. As this underlying hardware interface is so fundamentally different, there is little in common between the drivers.

The existing xillybus_core.c driver is based upon direct memory register + DMA interaction with the hardware. XillyUSB relies on the USB framework for all communication. I'll try to demonstrate the practical differences with two examples.

(1) Sending commands to the hardware: The existing Xillybus driver just writes to registers in memory space. Its XillyUSB counterpart calls xillyusb_send_opcode() to prepare a little packet for transmission over USB, and may possibly sleep if there's a (temporary) lack of resources to complete that task.

(2) Data handling: The existing Xillybus driver just copies user data to and from DMA buffers. Its main business is to maintain and juggle these buffers with the hardware. The XillyUSB driver, on the other hand, manages a pool of URBs to efficiently shuffle the data to and from the hardware. The main challenge is to keep the data flowing at 400 MB/s.

Quoted 5 lines
Quoted 4 lines

This goes on for every single aspect of the two drivers: They do the same things essentially, but the actual actions are completely different, as they have different means to do get the job done. And completely different challenges.

That's fine, but I'm talking about the userspace api. You should not be creating two different userspace apis just because the bus transport changed for the hardware.

We don't do that for things like tty devices, right? :)

So please, share the same core code that exports the api to userspace to be common, do not create a new one, like you did here.

maintainer
#7 lore raw

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

Quoted 6 lines · Eli Billauer

Hello, Greg.

I'm afraid we're not on the same page. As mentioned in the original patch description, XillyUSB and the existing Xillybus variant presents a nearly identical API. User space programs see no difference when using one or the other, except for different device file names.

My point is, do NOT have different file names. Userspace should not care about the backing transport layer of a device.

Quoted 4 lines

In that sense, it's exactly
like tty devices. But unlike ttys, there are no ioctls or any other special API functions to export. Xillybus' API consists only of the basic file operations, which behave like you'd expect from a pipe, more or less.

Great, then do like the tty devices do and present the same device name to userspace.

thanks,

greg k-h

author maintainer
#8 lore raw

Hello, Greg.

Quoted 3 lines · Greg KH

My point is, do NOT have different file names. Userspace should not care about the backing transport layer of a device.

Regarding sound cards and such -- we agree perfectly. For a driver like XillyUSB, it's not necessarily clear what is correct formally. Either way, for XillyUSB the choice on this matter was practical.

First thing, this is what users expect. Xillybus is an FPGA project, and its users are hardware oriented. They've spent time designing the FPGA logic, and the connection with the host has been part of the effort. As the connection via PCIe or USB is part of the design, they definitely see these as different things, and don't expect them to appear to be the same.

Also, the application software is virtually always written specially for the project. Even if a specific hardware application is designed with both connection options possible (USB or PCIe), it will be very much desired to distinguish between them. For example, because odds are that the PCIe option will allow a much higher bandwidth capacity.

Another thing is that it's quite possible that some users will connect an FPGA board to a host through USB and PCIe simultaneously. For example, when developing an FPGA to work with the USB variant, but at the same time using the PCIe variant for passing debug data. In this case, using the same namespace for both variants will cause confusion.

So yes, calling the new XillyUSB device files xillyusb_* instead of xillybus_* may appear awkward. But I'm quite sure that no single user will ever thank me or anyone else for merging them. Maybe the formality is still important enough to do this anyhow...?

Thanks and regards,
Eli