Giter VIP home page Giter VIP logo

axisfifo's Introduction

Xilinx AXI-Stream FIFO v4.1/v4.2 IP core driver

This IP core has read and write AXI-Stream FIFOs, the contents of which can be accessed from the AXI4 memory-mapped interface. This is useful for transferring data from a processor into the FPGA fabric. The driver creates a character device that can be read/written to with standard open/read/write/close.

See Xilinx PG080 document for IP details.

The driver currently supports only store-forward mode with a 32-bit AXI4 Lite interface. DOES NOT support:

  • cut-through mode
  • AXI4 (non-lite)

You should find a character device in /dev (e.g. /dev/axis_fifo_########) for each AXI-Stream fifo you create in your hardware. The device can be read and written to like a normal file.

API

To quickly test things, you can write a packet to your fifo from the command line with
echo -n -e '\xDE\xAD\xBE\xEF' > /dev/axis_fifo<#>
and read from it with
cat /dev/axis_fifo<#> | hexdump -C.

When you write data to the fifo, the block of data is written as a packet as dictated by the length passed to write. When you call read(), a single packet is returned regardless of how many bytes were requested.

For example:

// assuming the fifo is configured in loopback mode in hardware
// e.g. axis tx interface feeds back into axis rx interface
// note that in this case a single file descriptor could be opened for both read and write,
// but separate read/write descriptors are used for illustrative purposes
int f_wr = open("/dev/axis_fifo_43c00000", O_WRONLY);
int f_rd = open("/dev/axis_fifo_43c00000", O_RDONLY);

// writes a packet of 12 bytes (3 words)
write(f_wr, &write_buff, 12);

// returns 12 bytes
ssize_t bytes_read = read(f_rd, &read_buff, 100);

close(f_wr);
close(f_rd);

By default, read() and write() will block for one second before timing out. You can change this behavior by loading the module with command line arguments "read_timeout" and "write_timeout" (in milliseconds):

insmod /lib/modules/4.9.0-xilinx-v2017.4/extra/axis-fifo.ko read_timeout=100 write_timeout=5000

You can set "read_timeout" / "write_timeout" to a negative value if you want read() / write() to block indefinitely:

insmod /lib/modules/4.9.0-xilinx-v2017.4/extra/axis-fifo.ko read_timeout=-1 write_timeout=-1

You can also make non-blocking reads/writes by opening the file with the O_NONBLOCK flag set which will cause read() and write() to return immediately:

int f = open("/dev/axis_fifo_43c00000", O_RDWR | O_NONBLOCK);

See fifo-test.c for more detailed usage code and to test functionality/throughput of your FIFO.

See fifo-test-eth.c provided for simple echo server demo using the fifo.

See axis-fifo.txt to see example device tree entry.

Word and Byte read/write alignments and TKEEP

The AXI-Stream protocol requires the TKEEP flag to be enabled in order to process byte width transactions over a 32-bit bus. When the TKEEP flag is NOT used then the FIFO is only able to process on word boundaries.

TKEEP must be both enabled on the IP Core and the device-tree by use of the has-axis-tkeep = <1> entry in the device tree. When it is NOT enabled byte width read/write requests will present an error and not be written to the core.

fifo-test.c supports testing of both modes.

Poll

The poll mechanism works off of the assumption that the user has an idea for a minimum and maximum packet size with respect to the AXI-Stream framing. To support this there are two entries in the device tree,

	xlnx,rx-min-pkt-size = <255>; /* 1020 bytes */
	xlnx,tx-max-pkt-size = <257>; /* 1028 bytes */

When the Transmit Data FIFO Vacancy register (TDFV) is greater than tx-max-pkt-size poll will return POLLOUT.

When the Receive Data FIFO Occupancy register (RDFO) is greater than rx-min-pkt-size poll will return POLLIN.

Example code using poll is provided in fifo-test.c

NOTE : tx-max-pkt-size and rx-min-pkt-size are defined as WORDS not BYTES.

Sysfs direct register access

You can access the IP registers directly if you wish using sysfs. They are located in
/sys/class/axis_fifo/axis_fifo_########/ip_registers/
For example, you can read the RDFO with
cat /sys/class/axis_fifo/axis_fifo_########/ip_registers/rdfo
or write to the fifo/TDFD with
echo 0xdeadbeef > /sys/class/axis_fifo/axis_fifo_########/ip_registers/tdfd.

IOCTLS

The driver supports a number of ioctls for setting,

  • read/write to any register
  • reseting the core
  • set/get tx-max-pkt-size for poll()
  • set/get rx-min-pkt-size for poll()

axisfifo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

axisfifo's Issues

axis_fifo is not found under /dev

Hi @jacobfeder ,
I am trying to create an application using PetaLinux which uses AXIS Stream FIFO. I had created a module and put the axis-fifo.c file under it and created an application and put the fifo-test.c file under it. After building and booting the system image on Zynq board, the axis_fifo device was not found under /dev folder. I am not sure what I am missing in the entire proceduer. Could you please help fix the problem?

Inappropriate IOCTL for device

I am using AXI FIFO with AXI4-Lite configuration in PL.
I have used this driver and could find character device in /dev.
But when I run echo.c application (after making base address changes). I am getting error 'inappropriate ioctl for device'
How to correct this?

over read error

If transmitting larger packets over fifo in non-blocking mode it comes to over-read error after certain data amount is transmitted.
The proposed solution is to check occupancy and rxLength so that all bytes indicated by rxLength are in the fifo.

Problem with 2 AXi FIFOs

Hi!
I am using Zynq7020 based design and have Ubuntu 20.4 rootfs with Petalinux 2020.2 kernel on one ARM cortex, and I have run the last version of the axis-fifo driver.

On the PL side I have 2 AXI-Stream FIFOs (v4.2):

  • one connected only to read data from PL (DB FIFO) which is periodically being written to from the PL:
    Data Interface : AXI4 Lite
    Enabled check-boxes: Enable Receive Data, TDEST Width 4
    Receive Fifo Depth 512
    Full Threshold 507
    Empty Threshold 5

  • the other connected to write to/read from PL, with the loopback implemented on PL:
    Data Interface : AXI4 Lite
    Enabled check-boxes: Enable Transmit/Receive Data, TDEST Width 4
    Transmit/Receive Fifo Depth 512
    Full Threshold 507
    Empty Threshold 5

In addition, in the driver code I commented the lines related to checking tdest, tx-max-pkt-size and rx-min-pkt-size.

Both AXI FIFOs are created correctly:

axis_fifo 40001000.axi_fifo_mm_s: axis-fifo created at 0x40001000 mapped to 0x0xf080a000, irq=54, major=241, minor=0
axis_fifo 40000000.axi_fifo_mm_s: axis-fifo created at 0x40000000 mapped to 0x0xf080c000, irq=55, major=240, minor=0

I have made two examples:

  • fifo_read to read data from DB FIFO, and
  • fifo_rw_loop based on axis-fifo-echo-test.c for ARM FIFO.

When both examples are running everything is working ok. But when the fifo_read is stopped (or not run at all), as soon as the DB FIFO becomes full, the fifo_rw_loop keeps getting ARM FIFO empty, i.e. does not read any data from the ARM FIFO while the write process to the ARM FIFO continues to work fine. I tried both BLOCKING (it jumps out with the read timeout for the read_timeout values of 1000ms or 5000ms, but with read_timeout of -1 it stays indefinitely in wait_event_interruptible_lock_irq_timeout) and NON_BLOCKING read with the same results. As soon as I run the fifo_read and start reading DB FIFO, everything starts working ok again.

The same happens when I restart the driver (rmmod/insmod) – everything works ok until DB FIFO is detected as full.

How/why does the state of one FIFO affect the (wrong) state of the other FIFO? How are these two instances of the driver related?

README.md quick test instructions clarification?

In the README.md in the home page you have these instructions to quickly test.

To quickly test things, you can write a packet to your fifo from the command line with
echo -n -e '\xDE\xAD\xBE\xEF' > /dev/axis_fifo<#>
and read from it with
cat /dev/axis_fifo<#> | hexdump -C.

I want to clarify, if our axis-fifo is wired in hardware for loopback, we won't get data when we cat, correct?

Thank you!

Read register ioctl causes crash

The following code causes a crash

  int fifo_fd = open("/dev/axis_fifo_0x43c00000", O_RDWR);
  if (fifo_fd < 0)
      return 1;

  struct axis_fifo_kern_regInfo reg_info{XLLF_RLR_OFFSET, 0};
  int rc = ioctl(fifo_fd, AXIS_FIFO_GET_REG, &reg_info);

  if (rc) {
      return EXIT_FAILURE;
  } else {
      return EXIT_SUCCESS;
  }

Reads and writes are successful, other ioctl operations work fine, and the provided test app functions correctly. When I try the above code I get:

Internal error: Oops - BUG: 1406 [#1] PREEMPT SMP ARM
Modules linked in: axis_fifo(O) uio_pdrv_genirq
CPU: 1 PID: 492 Comm: fifo_benchmark Tainted: G           O      5.10.0-xilinx-v2021.2 #1
Hardware name: Xilinx Zynq Platform
PC is at axis_fifo_ioctl+0x1c0/0x29c [axis_fifo]
LR is at 0x0
pc : [<bf012960>]    lr : [<00000000>]    psr: 60010013
sp : c1c93ef0  ip : 00000018  fp : 00000000
r10: c1c92000  r9 : c18a2f00  r8 : c1c92000
r7 : 80085100  r6 : befffab4  r5 : 00000000  r4 : c1a0f540
r3 : 00000000  r2 : 00000024  r1 : befffabc  r0 : 00000000
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 18c5387d  Table: 01a1404a  DAC: 00000051
Process fifo_benchmark (pid: 492, stack limit = 0xc7d15f33)
Stack: (0xc1c93ef0 to 0xc1c94000)
3ee0:                                     00000000 00000024 00000000 4fb846c8
3f00: 80085100 befffab4 c18a2f00 c19d58d0 00000003 c0210d60 80085100 c0211738
3f20: c1c92000 00000000 00000000 c1c92000 c1c93f40 ffffe000 00000000 c0108704
3f40: 00000000 00000005 00000000 00000001 00401544 00000000 00000000 00000000
3f60: 00000005 00000000 00000001 00401544 00000000 00000000 00000000 4fb846c8
3f80: 00000000 00414ed4 00414ed4 004016ad 00000036 c0100264 c1c92000 00000036
3fa0: 00000000 c0100060 00414ed4 00414ed4 00000003 80085100 befffab4 00000003
3fc0: 00414ed4 00414ed4 004016ad 00000036 00000000 00000000 00414ed4 00000000
3fe0: 00414f4c befffaa4 00403531 b6e10228 40010030 00000003 00000000 00000000
[<bf012960>] (axis_fifo_ioctl [axis_fifo]) from [<c0210d60>] (vfs_ioctl+0x20/0x38)
[<c0210d60>] (vfs_ioctl) from [<c0211738>] (sys_ioctl+0xc0/0x770)
[<c0211738>] (sys_ioctl) from [<c0100060>] (ret_fast_syscall+0x0/0x54)
Exception stack(0xc1c93fa8 to 0xc1c93ff0)
3fa0:                   00414ed4 00414ed4 00000003 80085100 befffab4 00000003
3fc0: 00414ed4 00414ed4 004016ad 00000036 00000000 00000000 00414ed4 00000000
3fe0: 00414f4c befffaa4 00403531 b6e10228
Code: e59d2004 e0833002 e5933000 f57ff04f (e28d1004) 
---[ end trace 5d0f1f8cb441a56f ]---

I am using PetaLinux 2021.2 with the following FIFO configuration
image
Let me know if you need any more information.

a problem using axis-fifo-test in loopback

Hi jacob ,
a problem with axis-fifo-test program on my zynq target :

root@os:~# axis-fifo-test 512 1 /dev/axis_fifo_0x43c10000
START :

TKEEP enabled ... testing byte boundary read/writes

axis_fifo 43c10000.axi_fifo_mm_s: user read buffer too small (available bytes=8 user buffer bytes=4) - fifo core will be reset
TESTING error conditions...
axis_fifo 43c10000.axi_fifo_mm_s: tried to send a packet of length 0
Reseting with ioctl...
ioctl: Inappropriate ioctl for device

my IP configuration :

Capture d’écran de 2022-05-28 20-43-55

my block design :

Capture d’écran de 2022-05-28 20-44-02

xilinx-linux and axis-fifo forked development

I am developing an application using the AXI4 FIFO and started by using the axis-fifo driver included in xilinx-linux. I have found that modifications made in this repository are not in the xilinx-linux, and likewise, patches made to the xilinix-linux driver are not in this repository.

Has anyone made the effort to merge these two development paths back together?

blocking mode with no timeout

When I set timeout to -1 in blocking mode, I wont be able to write
It gives "wait_event_interruptible_timeout() error in write (ret=-1)"
But when i make it bigger than zero, it works.
What could be wrong?

unable to change read and write timeout

Hi, since the driver is now build in the petalinux kernel, i was unable to run

insmod /lib/modules/4.9.0-xilinx-v2017.4/extra/axis-fifo.ko read_timeout=-1 write_timeout=-1

because the axis-fifo.ko is not found. Where can i change these values?

no axis_fifo_XXXXXXXX in /dev repertory

Hi Jacob,
I am trying to use your "axi-fifo" driver, in a project using petalinux 2021.1 and Vivado 2021.1, as tools. The problem is that on my target system (Zynq -> Eclypse Z7), there is no /dev/axis_fifo_43c00000, when the linux kernel boots there is only one message about axi-fifo :

root@os:~# dmesg|grep axis
axis-fifo driver loaded with parameters read_timeout = 1000, write_timeout = 1000

on the target system, I just replaced in the /boot/decice-tree.dts file :
compatible = "xlnx,axi-fifo-mm-s-4.2";

with:
compatible = "xlnx,axi-fifo-mm-s-4.1";

and recompiled to obtain the file device-tree.dtb

I've been trying to solve the problem for several days, do you have any ideas?

Can't find axisfifo under the /dev

I tried to use AXI_Stream_FIFO v4.2 IP core in Petalinux. I enabled the Xilinx AXI-Stream FIFO v4.1/v4.2 IP core driver directly in the petalinux kernel configuration, but after booting I did not find a device like /dev/axis_fifo__########. I'd like to ask what's going on, is there an operation I'm missing?

Board: ZCU104
Petalinux Version: 2020.2
Vivado Version: 2020.2

dmesg:
dmesg.txt

pl.dtsi:
pl.dtsi.txt

vivado bd:
top_design.pdf

axis fifo giving resource unavailable error

I have the axis_stream_fifo setup.

I attempt to read the data and display it in ascii.
I can read some data which should be a counter that I am clocking in, but all I get are zeros and then I get
Failed to read from FIFO: Resource temporarily unavailable

root@platform:/apps# poke 0x41200000 1 && ./readfifo
Read 8 bytes from FIFO:
00 00 00 00 00 00 00 00
root@platform:/apps# poke 0x41200000 1 && ./readfifo
Read 8 bytes from FIFO:
00 00 00 00 00 00 00 00
root@platform:/apps# poke 0x41200000 1 && ./readfifo
Read 8 bytes from FIFO:
00 00 00 00 00 00 00 00
root@platform:/apps# poke 0x41200000 1 && ./readfifo
Read 8 bytes from FIFO:
00 00 00 00 00 00 00 00
root@platform:/apps# poke 0x41200000 1 && ./readfifo
Read 8 bytes from FIFO:
00 00 00 00 00 00 00 00
root@platform:/apps# poke 0x41200000 1 && ./readfifo
Failed to read from FIFO: Resource temporarily unavailable

I cannot read again unless I reboot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.