xilinx_dma.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #! /bin/bash
  2. BAR=0
  3. USE=1
  4. ITERATIONS=2
  5. BUFFERS=16
  6. function pci {
  7. PCILIB_PATH=`pwd`/..
  8. LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
  9. }
  10. function reset {
  11. pci -b $BAR -w 0 1
  12. usleep 1000
  13. pci -b $BAR -w 0 0
  14. pci -b $BAR -w 4 0
  15. }
  16. function read_cfg {
  17. # echo $1 1>&2
  18. pci -a config -r 0x$1 | awk '{ print $2; }'
  19. }
  20. function parse_config {
  21. info=0x`pci -b $BAR -r 0 | awk '{ print $2; }'`
  22. model=`printf "%X" $((info>>24))`
  23. if [ $model -eq 14 ]; then
  24. model="Xilinx Virtex-6"
  25. else
  26. model="Xilinx $model"
  27. fi
  28. version=$(((info >> 8) & 0xFF))
  29. data_width=$((16 * (2 ** ((info >> 16) & 0xF))))
  30. echo "$model, build $version, $data_width bits"
  31. next=`read_cfg 34 | cut -c 7-8`
  32. while [ $next -ne 0 ]; do
  33. cap=`read_cfg $next`
  34. capid=`echo $cap | cut -c 7-8`
  35. if [ $capid -eq 10 ]; then
  36. addr=`printf "%X" $((0x$next + 12))`
  37. pcie_link1=`read_cfg $addr`
  38. addr=`printf "%X" $((0x$next + 16))`
  39. pcie_link2=`read_cfg $addr`
  40. link_speed=$((((0x$pcie_link2 & 0xF0000) >> 16)))
  41. link_width=$((((0x$pcie_link2 & 0x3F00000) >> 20)))
  42. dev_link_speed=$((((0x$pcie_link1 & 0xF))))
  43. dev_link_width=$((((0x$pcie_link1 & 0x3F0) >> 4)))
  44. fi
  45. next=`echo $cap | cut -c 5-6`
  46. done
  47. echo "Link: PCIe gen$link_speed x$link_width"
  48. if [ $link_speed -ne $dev_link_speed -o $link_width -ne $dev_link_width ]; then
  49. echo " * But device capable of gen$dev_link_speed x$dev_link_width"
  50. fi
  51. info=0x`read_cfg 40`
  52. max_tlp=$((2 ** (5 + ((info & 0xE0) >> 5))))
  53. echo "TLP: 32 dwords (transfering 32 TLP per request)"
  54. if [ $max_tlp -ne 32 ]; then
  55. echo " * But device is able to transfer TLP up to $max_tlp bytes"
  56. fi
  57. # 2500 MT/s, but PCIe gen1 and gen2 uses 10 bit encoding
  58. speed=$((link_width * link_speed * 2500 / 10))
  59. }
  60. reset
  61. parse_config
  62. pci --enable-irq
  63. pci --acknowledge-irq
  64. pci --free-kernel-memory $USE
  65. pci --alloc-kernel-memory $USE --type c2s -s $BUFFERS
  66. bus=`pci --list-kernel-memory 00100001 | awk '{ print $4; }' | grep 00`
  67. #ptr=`pci --list-kernel-memory 00100001 | awk '{ print $2; }' | grep 00`
  68. # TLP size
  69. pci -b $BAR -w 0x0C 0x20
  70. # TLP count
  71. pci -b $BAR -w 0x10 0x20
  72. # Data
  73. pci -b $BAR -w 0x14 0x13131313
  74. dmaperf=0
  75. for i in `seq 1 $ITERATIONS`; do
  76. for addr in $bus; do
  77. pci -b $BAR -w 0x08 0x$addr
  78. #Trigger
  79. pci -b $BAR -w 0x04 0x01
  80. pci --wait-irq
  81. # pci -b $BAR -w 0x04 0x00
  82. status=`pci -b $BAR -r 0x04 | awk '{print $2; }' | cut -c 5-8`
  83. if [ $status != "0101" ]; then
  84. echo "Read failed, invalid status: $status"
  85. fi
  86. dmaperf=$((dmaperf + 0x`pci -b $BAR -r 0x28 | awk '{print $2}'`))
  87. reset
  88. done
  89. done
  90. pci --free-kernel-memory $USE
  91. pci --disable-irq
  92. echo
  93. # Don't ask me about this formula
  94. echo "Performance reported by FPGA: $((4096 * BUFFERS * ITERATIONS * $speed / $dmaperf / 8)) MB/s"
  95. #pci -b $BAR -r 0 -s 32