xilinx_dma_static_mem.sh 2.7 KB

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