Guest User

Untitled

a guest
Dec 27th, 2023
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. // Transmit a PCIE TLP packet waiting for ACK
  2. void pciePktSend(const u32 *pkt, int len)
  3. {
  4. u32 pciePktSeq = regRead(0x7d10);
  5. u32 nextPciePktSeq = (pciePktSeq + 1) & 0xfff;
  6.  
  7. while(len--) regWrite(0x7d38, *pkt++);
  8.  
  9. int timeout = 10000;
  10. regWrite(0x7d10, nextPciePktSeq);
  11. while(((regRead(0x7d18) & 0xfff) != pciePktSeq) && timeout--);
  12. }
  13.  
  14. // Write to remote PCIe device memory
  15. void pcieHostMemWrite(u32 addr, u32 data)
  16. {
  17. u32 pkt[] = { 0x40000001, 0x0000000f, addr, __builtin_bswap32(data)};
  18. pciePktSend(pkt, ARRAY_SIZE(pkt));
  19. }
  20.  
  21. // Write to remote PCIe device config space
  22. void pcieHostConfWrite(u32 addr, u32 data)
  23. {
  24. u32 pkt[] = { 0x44000001, 0x0000000f, addr & 0xfff, __builtin_bswap32(data)};
  25. pciePktSend(pkt, ARRAY_SIZE(pkt));
  26. }
  27.  
  28. // Act as upstream device - send config and memory access requests!!!
  29. void pcieHostInit()
  30. {
  31. int timeout;
  32.  
  33. #if CONFIG_PCIE_HOST_INIT2
  34. regWrite(0x7e08, BIT(0)); // go to disable state
  35. timeout = 1<<22;
  36. while((regRead(0x7e08) & BIT(0)) && --timeout);
  37. // reset PCIE PHY
  38. regWrite(0x7e00, BIT(0));
  39. #endif
  40.  
  41. // enable internal loopback mode
  42. regWrite(0x7e2c,BIT(11)|BIT(9)|BIT(8)|BIT(0));
  43.  
  44. // wait for link up
  45. timeout = 1<<22;
  46. while(!(regRead(0x7d04) & BIT(16)) && --timeout);
  47.  
  48. // set config request packets
  49. for(int i = 0; i < 10; i++)
  50. pcieHostConfWrite(0, 0);
  51.  
  52. // regModify(0x7c00, 0,BIT(29)|BIT(25));
  53.  
  54. regWrite(0x7c00, BIT(31)|BIT(29)|BIT(27)|BIT(26)|BIT(25)|BIT(22)|0x2f);
  55. regWrite(0x7c04, BIT(8)|BIT(7)|BIT(3)|BIT(2)|BIT(1)|BIT(0));
  56. // regWrite(0x7d00, 0x100);
  57. // while(regRead(0x7e00) & BIT(0));
  58.  
  59. // enable downstream lane mode
  60. regWrite(0x7e2c,BIT(11)|BIT(9)|BIT(8)|BIT(3));
  61. // enable copying of received TLPs into retry buffer
  62. // regWrite(0x7d4c,BIT(15)); // |BIT(14));
  63. // regWrite(0x7d4c, 0xffffc000);
  64.  
  65. pcieReadTag = 0;
  66. #if CONFIG_PCIE_HOST_INIT2
  67. regWrite(0x7e08, BIT(6)); // go to detect state
  68. while(regRead(0x7e08) & BIT(6));
  69. #endif
  70.  
  71. // wait for link up
  72. timeout = 1<<22;
  73. while(!(regRead(0x7d04) & BIT(16)) && --timeout);
  74.  
  75. // Timeout exceeded, probably due to reset or clock glitches, try and force
  76. reset
  77. if(timeout == 0) {
  78. errFail(LED_FAIL_PCIE_LINK_UP);
  79. //oledPrintFail("Link Up Timeout");
  80. //delay_ms(100);
  81. //regWrite(0x7e08, BIT(1)); // via hot reset
  82. //delay_ms(100);
  83. //regWrite(0x7e00, BIT(1)); // now reset pcie
  84. //delay_ms(100);
  85. //regModify(0x68d, 0, BIT(0)); // reset entire system
  86. }
  87.  
  88. // configure NIC to be visible from GPU
  89. regWrite(0x10, 0xf0000000); // base address register
  90. regWrite(0x14, 0);
  91. regWrite(0x18, 0xe0000000); // base address register
  92. regWrite(0x1c, 0);
  93. regWrite(0x30, 0xd0000000); // ROM base address register
  94. regWrite(0x04, BIT(2)|BIT(1));
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment