user_mad.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. USERSPACE MAD ACCESS
  2. Device files
  3. Each port of each InfiniBand device has a "umad" device and an
  4. "issm" device attached. For example, a two-port HCA will have two
  5. umad devices and two issm devices, while a switch will have one
  6. device of each type (for switch port 0).
  7. Creating MAD agents
  8. A MAD agent can be created by filling in a struct ib_user_mad_reg_req
  9. and then calling the IB_USER_MAD_REGISTER_AGENT ioctl on a file
  10. descriptor for the appropriate device file. If the registration
  11. request succeeds, a 32-bit id will be returned in the structure.
  12. For example:
  13. struct ib_user_mad_reg_req req = { /* ... */ };
  14. ret = ioctl(fd, IB_USER_MAD_REGISTER_AGENT, (char *) &req);
  15. if (!ret)
  16. my_agent = req.id;
  17. else
  18. perror("agent register");
  19. Agents can be unregistered with the IB_USER_MAD_UNREGISTER_AGENT
  20. ioctl. Also, all agents registered through a file descriptor will
  21. be unregistered when the descriptor is closed.
  22. 2014 -- a new registration ioctl is now provided which allows additional
  23. fields to be provided during registration.
  24. Users of this registration call are implicitly setting the use of
  25. pkey_index (see below).
  26. Receiving MADs
  27. MADs are received using read(). The receive side now supports
  28. RMPP. The buffer passed to read() must be at least one
  29. struct ib_user_mad + 256 bytes. For example:
  30. If the buffer passed is not large enough to hold the received
  31. MAD (RMPP), the errno is set to ENOSPC and the length of the
  32. buffer needed is set in mad.length.
  33. Example for normal MAD (non RMPP) reads:
  34. struct ib_user_mad *mad;
  35. mad = malloc(sizeof *mad + 256);
  36. ret = read(fd, mad, sizeof *mad + 256);
  37. if (ret != sizeof mad + 256) {
  38. perror("read");
  39. free(mad);
  40. }
  41. Example for RMPP reads:
  42. struct ib_user_mad *mad;
  43. mad = malloc(sizeof *mad + 256);
  44. ret = read(fd, mad, sizeof *mad + 256);
  45. if (ret == -ENOSPC)) {
  46. length = mad.length;
  47. free(mad);
  48. mad = malloc(sizeof *mad + length);
  49. ret = read(fd, mad, sizeof *mad + length);
  50. }
  51. if (ret < 0) {
  52. perror("read");
  53. free(mad);
  54. }
  55. In addition to the actual MAD contents, the other struct ib_user_mad
  56. fields will be filled in with information on the received MAD. For
  57. example, the remote LID will be in mad.lid.
  58. If a send times out, a receive will be generated with mad.status set
  59. to ETIMEDOUT. Otherwise when a MAD has been successfully received,
  60. mad.status will be 0.
  61. poll()/select() may be used to wait until a MAD can be read.
  62. Sending MADs
  63. MADs are sent using write(). The agent ID for sending should be
  64. filled into the id field of the MAD, the destination LID should be
  65. filled into the lid field, and so on. The send side does support
  66. RMPP so arbitrary length MAD can be sent. For example:
  67. struct ib_user_mad *mad;
  68. mad = malloc(sizeof *mad + mad_length);
  69. /* fill in mad->data */
  70. mad->hdr.id = my_agent; /* req.id from agent registration */
  71. mad->hdr.lid = my_dest; /* in network byte order... */
  72. /* etc. */
  73. ret = write(fd, &mad, sizeof *mad + mad_length);
  74. if (ret != sizeof *mad + mad_length)
  75. perror("write");
  76. Transaction IDs
  77. Users of the umad devices can use the lower 32 bits of the
  78. transaction ID field (that is, the least significant half of the
  79. field in network byte order) in MADs being sent to match
  80. request/response pairs. The upper 32 bits are reserved for use by
  81. the kernel and will be overwritten before a MAD is sent.
  82. P_Key Index Handling
  83. The old ib_umad interface did not allow setting the P_Key index for
  84. MADs that are sent and did not provide a way for obtaining the P_Key
  85. index of received MADs. A new layout for struct ib_user_mad_hdr
  86. with a pkey_index member has been defined; however, to preserve binary
  87. compatibility with older applications, this new layout will not be used
  88. unless one of IB_USER_MAD_ENABLE_PKEY or IB_USER_MAD_REGISTER_AGENT2 ioctl's
  89. are called before a file descriptor is used for anything else.
  90. In September 2008, the IB_USER_MAD_ABI_VERSION will be incremented
  91. to 6, the new layout of struct ib_user_mad_hdr will be used by
  92. default, and the IB_USER_MAD_ENABLE_PKEY ioctl will be removed.
  93. Setting IsSM Capability Bit
  94. To set the IsSM capability bit for a port, simply open the
  95. corresponding issm device file. If the IsSM bit is already set,
  96. then the open call will block until the bit is cleared (or return
  97. immediately with errno set to EAGAIN if the O_NONBLOCK flag is
  98. passed to open()). The IsSM bit will be cleared when the issm file
  99. is closed. No read, write or other operations can be performed on
  100. the issm file.
  101. /dev files
  102. To create the appropriate character device files automatically with
  103. udev, a rule like
  104. KERNEL=="umad*", NAME="infiniband/%k"
  105. KERNEL=="issm*", NAME="infiniband/%k"
  106. can be used. This will create device nodes named
  107. /dev/infiniband/umad0
  108. /dev/infiniband/issm0
  109. for the first port, and so on. The InfiniBand device and port
  110. associated with these devices can be determined from the files
  111. /sys/class/infiniband_mad/umad0/ibdev
  112. /sys/class/infiniband_mad/umad0/port
  113. and
  114. /sys/class/infiniband_mad/issm0/ibdev
  115. /sys/class/infiniband_mad/issm0/port