ntb.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. ===========
  2. NTB Drivers
  3. ===========
  4. NTB (Non-Transparent Bridge) is a type of PCI-Express bridge chip that connects
  5. the separate memory systems of two or more computers to the same PCI-Express
  6. fabric. Existing NTB hardware supports a common feature set: doorbell
  7. registers and memory translation windows, as well as non common features like
  8. scratchpad and message registers. Scratchpad registers are read-and-writable
  9. registers that are accessible from either side of the device, so that peers can
  10. exchange a small amount of information at a fixed address. Message registers can
  11. be utilized for the same purpose. Additionally they are provided with
  12. special status bits to make sure the information isn't rewritten by another
  13. peer. Doorbell registers provide a way for peers to send interrupt events.
  14. Memory windows allow translated read and write access to the peer memory.
  15. NTB Core Driver (ntb)
  16. =====================
  17. The NTB core driver defines an api wrapping the common feature set, and allows
  18. clients interested in NTB features to discover NTB the devices supported by
  19. hardware drivers. The term "client" is used here to mean an upper layer
  20. component making use of the NTB api. The term "driver," or "hardware driver,"
  21. is used here to mean a driver for a specific vendor and model of NTB hardware.
  22. NTB Client Drivers
  23. ==================
  24. NTB client drivers should register with the NTB core driver. After
  25. registering, the client probe and remove functions will be called appropriately
  26. as ntb hardware, or hardware drivers, are inserted and removed. The
  27. registration uses the Linux Device framework, so it should feel familiar to
  28. anyone who has written a pci driver.
  29. NTB Typical client driver implementation
  30. ----------------------------------------
  31. Primary purpose of NTB is to share some peace of memory between at least two
  32. systems. So the NTB device features like Scratchpad/Message registers are
  33. mainly used to perform the proper memory window initialization. Typically
  34. there are two types of memory window interfaces supported by the NTB API:
  35. inbound translation configured on the local ntb port and outbound translation
  36. configured by the peer, on the peer ntb port. The first type is
  37. depicted on the next figure::
  38. Inbound translation:
  39. Memory: Local NTB Port: Peer NTB Port: Peer MMIO:
  40. ____________
  41. | dma-mapped |-ntb_mw_set_trans(addr) |
  42. | memory | _v____________ | ______________
  43. | (addr) |<======| MW xlat addr |<====| MW base addr |<== memory-mapped IO
  44. |------------| |--------------| | |--------------|
  45. So typical scenario of the first type memory window initialization looks:
  46. 1) allocate a memory region, 2) put translated address to NTB config,
  47. 3) somehow notify a peer device of performed initialization, 4) peer device
  48. maps corresponding outbound memory window so to have access to the shared
  49. memory region.
  50. The second type of interface, that implies the shared windows being
  51. initialized by a peer device, is depicted on the figure::
  52. Outbound translation:
  53. Memory: Local NTB Port: Peer NTB Port: Peer MMIO:
  54. ____________ ______________
  55. | dma-mapped | | | MW base addr |<== memory-mapped IO
  56. | memory | | |--------------|
  57. | (addr) |<===================| MW xlat addr |<-ntb_peer_mw_set_trans(addr)
  58. |------------| | |--------------|
  59. Typical scenario of the second type interface initialization would be:
  60. 1) allocate a memory region, 2) somehow deliver a translated address to a peer
  61. device, 3) peer puts the translated address to NTB config, 4) peer device maps
  62. outbound memory window so to have access to the shared memory region.
  63. As one can see the described scenarios can be combined in one portable
  64. algorithm.
  65. Local device:
  66. 1) Allocate memory for a shared window
  67. 2) Initialize memory window by translated address of the allocated region
  68. (it may fail if local memory window initialization is unsupported)
  69. 3) Send the translated address and memory window index to a peer device
  70. Peer device:
  71. 1) Initialize memory window with retrieved address of the allocated
  72. by another device memory region (it may fail if peer memory window
  73. initialization is unsupported)
  74. 2) Map outbound memory window
  75. In accordance with this scenario, the NTB Memory Window API can be used as
  76. follows:
  77. Local device:
  78. 1) ntb_mw_count(pidx) - retrieve number of memory ranges, which can
  79. be allocated for memory windows between local device and peer device
  80. of port with specified index.
  81. 2) ntb_get_align(pidx, midx) - retrieve parameters restricting the
  82. shared memory region alignment and size. Then memory can be properly
  83. allocated.
  84. 3) Allocate physically contiguous memory region in compliance with
  85. restrictions retrieved in 2).
  86. 4) ntb_mw_set_trans(pidx, midx) - try to set translation address of
  87. the memory window with specified index for the defined peer device
  88. (it may fail if local translated address setting is not supported)
  89. 5) Send translated base address (usually together with memory window
  90. number) to the peer device using, for instance, scratchpad or message
  91. registers.
  92. Peer device:
  93. 1) ntb_peer_mw_set_trans(pidx, midx) - try to set received from other
  94. device (related to pidx) translated address for specified memory
  95. window. It may fail if retrieved address, for instance, exceeds
  96. maximum possible address or isn't properly aligned.
  97. 2) ntb_peer_mw_get_addr(widx) - retrieve MMIO address to map the memory
  98. window so to have an access to the shared memory.
  99. Also it is worth to note, that method ntb_mw_count(pidx) should return the
  100. same value as ntb_peer_mw_count() on the peer with port index - pidx.
  101. NTB Transport Client (ntb\_transport) and NTB Netdev (ntb\_netdev)
  102. ------------------------------------------------------------------
  103. The primary client for NTB is the Transport client, used in tandem with NTB
  104. Netdev. These drivers function together to create a logical link to the peer,
  105. across the ntb, to exchange packets of network data. The Transport client
  106. establishes a logical link to the peer, and creates queue pairs to exchange
  107. messages and data. The NTB Netdev then creates an ethernet device using a
  108. Transport queue pair. Network data is copied between socket buffers and the
  109. Transport queue pair buffer. The Transport client may be used for other things
  110. besides Netdev, however no other applications have yet been written.
  111. NTB Ping Pong Test Client (ntb\_pingpong)
  112. -----------------------------------------
  113. The Ping Pong test client serves as a demonstration to exercise the doorbell
  114. and scratchpad registers of NTB hardware, and as an example simple NTB client.
  115. Ping Pong enables the link when started, waits for the NTB link to come up, and
  116. then proceeds to read and write the doorbell scratchpad registers of the NTB.
  117. The peers interrupt each other using a bit mask of doorbell bits, which is
  118. shifted by one in each round, to test the behavior of multiple doorbell bits
  119. and interrupt vectors. The Ping Pong driver also reads the first local
  120. scratchpad, and writes the value plus one to the first peer scratchpad, each
  121. round before writing the peer doorbell register.
  122. Module Parameters:
  123. * unsafe - Some hardware has known issues with scratchpad and doorbell
  124. registers. By default, Ping Pong will not attempt to exercise such
  125. hardware. You may override this behavior at your own risk by setting
  126. unsafe=1.
  127. * delay\_ms - Specify the delay between receiving a doorbell
  128. interrupt event and setting the peer doorbell register for the next
  129. round.
  130. * init\_db - Specify the doorbell bits to start new series of rounds. A new
  131. series begins once all the doorbell bits have been shifted out of
  132. range.
  133. * dyndbg - It is suggested to specify dyndbg=+p when loading this module, and
  134. then to observe debugging output on the console.
  135. NTB Tool Test Client (ntb\_tool)
  136. --------------------------------
  137. The Tool test client serves for debugging, primarily, ntb hardware and drivers.
  138. The Tool provides access through debugfs for reading, setting, and clearing the
  139. NTB doorbell, and reading and writing scratchpads.
  140. The Tool does not currently have any module parameters.
  141. Debugfs Files:
  142. * *debugfs*/ntb\_tool/*hw*/
  143. A directory in debugfs will be created for each
  144. NTB device probed by the tool. This directory is shortened to *hw*
  145. below.
  146. * *hw*/db
  147. This file is used to read, set, and clear the local doorbell. Not
  148. all operations may be supported by all hardware. To read the doorbell,
  149. read the file. To set the doorbell, write `s` followed by the bits to
  150. set (eg: `echo 's 0x0101' > db`). To clear the doorbell, write `c`
  151. followed by the bits to clear.
  152. * *hw*/mask
  153. This file is used to read, set, and clear the local doorbell mask.
  154. See *db* for details.
  155. * *hw*/peer\_db
  156. This file is used to read, set, and clear the peer doorbell.
  157. See *db* for details.
  158. * *hw*/peer\_mask
  159. This file is used to read, set, and clear the peer doorbell
  160. mask. See *db* for details.
  161. * *hw*/spad
  162. This file is used to read and write local scratchpads. To read
  163. the values of all scratchpads, read the file. To write values, write a
  164. series of pairs of scratchpad number and value
  165. (eg: `echo '4 0x123 7 0xabc' > spad`
  166. # to set scratchpads `4` and `7` to `0x123` and `0xabc`, respectively).
  167. * *hw*/peer\_spad
  168. This file is used to read and write peer scratchpads. See
  169. *spad* for details.
  170. NTB MSI Test Client (ntb\_msi\_test)
  171. ------------------------------------
  172. The MSI test client serves to test and debug the MSI library which
  173. allows for passing MSI interrupts across NTB memory windows. The
  174. test client is interacted with through the debugfs filesystem:
  175. * *debugfs*/ntb\_tool/*hw*/
  176. A directory in debugfs will be created for each
  177. NTB device probed by the tool. This directory is shortened to *hw*
  178. below.
  179. * *hw*/port
  180. This file describes the local port number
  181. * *hw*/irq*_occurrences
  182. One occurrences file exists for each interrupt and, when read,
  183. returns the number of times the interrupt has been triggered.
  184. * *hw*/peer*/port
  185. This file describes the port number for each peer
  186. * *hw*/peer*/count
  187. This file describes the number of interrupts that can be
  188. triggered on each peer
  189. * *hw*/peer*/trigger
  190. Writing an interrupt number (any number less than the value
  191. specified in count) will trigger the interrupt on the
  192. specified peer. That peer's interrupt's occurrence file
  193. should be incremented.
  194. NTB Hardware Drivers
  195. ====================
  196. NTB hardware drivers should register devices with the NTB core driver. After
  197. registering, clients probe and remove functions will be called.
  198. NTB Intel Hardware Driver (ntb\_hw\_intel)
  199. ------------------------------------------
  200. The Intel hardware driver supports NTB on Xeon and Atom CPUs.
  201. Module Parameters:
  202. * b2b\_mw\_idx
  203. If the peer ntb is to be accessed via a memory window, then use
  204. this memory window to access the peer ntb. A value of zero or positive
  205. starts from the first mw idx, and a negative value starts from the last
  206. mw idx. Both sides MUST set the same value here! The default value is
  207. `-1`.
  208. * b2b\_mw\_share
  209. If the peer ntb is to be accessed via a memory window, and if
  210. the memory window is large enough, still allow the client to use the
  211. second half of the memory window for address translation to the peer.
  212. * xeon\_b2b\_usd\_bar2\_addr64
  213. If using B2B topology on Xeon hardware, use
  214. this 64 bit address on the bus between the NTB devices for the window
  215. at BAR2, on the upstream side of the link.
  216. * xeon\_b2b\_usd\_bar4\_addr64 - See *xeon\_b2b\_bar2\_addr64*.
  217. * xeon\_b2b\_usd\_bar4\_addr32 - See *xeon\_b2b\_bar2\_addr64*.
  218. * xeon\_b2b\_usd\_bar5\_addr32 - See *xeon\_b2b\_bar2\_addr64*.
  219. * xeon\_b2b\_dsd\_bar2\_addr64 - See *xeon\_b2b\_bar2\_addr64*.
  220. * xeon\_b2b\_dsd\_bar4\_addr64 - See *xeon\_b2b\_bar2\_addr64*.
  221. * xeon\_b2b\_dsd\_bar4\_addr32 - See *xeon\_b2b\_bar2\_addr64*.
  222. * xeon\_b2b\_dsd\_bar5\_addr32 - See *xeon\_b2b\_bar2\_addr64*.