user_mad.txt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Receiving MADs
  23. MADs are received using read(). The buffer passed to read() must be
  24. large enough to hold at least one struct ib_user_mad. For example:
  25. struct ib_user_mad mad;
  26. ret = read(fd, &mad, sizeof mad);
  27. if (ret != sizeof mad)
  28. perror("read");
  29. In addition to the actual MAD contents, the other struct ib_user_mad
  30. fields will be filled in with information on the received MAD. For
  31. example, the remote LID will be in mad.lid.
  32. If a send times out, a receive will be generated with mad.status set
  33. to ETIMEDOUT. Otherwise when a MAD has been successfully received,
  34. mad.status will be 0.
  35. poll()/select() may be used to wait until a MAD can be read.
  36. Sending MADs
  37. MADs are sent using write(). The agent ID for sending should be
  38. filled into the id field of the MAD, the destination LID should be
  39. filled into the lid field, and so on. For example:
  40. struct ib_user_mad mad;
  41. /* fill in mad.data */
  42. mad.id = my_agent; /* req.id from agent registration */
  43. mad.lid = my_dest; /* in network byte order... */
  44. /* etc. */
  45. ret = write(fd, &mad, sizeof mad);
  46. if (ret != sizeof mad)
  47. perror("write");
  48. Setting IsSM Capability Bit
  49. To set the IsSM capability bit for a port, simply open the
  50. corresponding issm device file. If the IsSM bit is already set,
  51. then the open call will block until the bit is cleared (or return
  52. immediately with errno set to EAGAIN if the O_NONBLOCK flag is
  53. passed to open()). The IsSM bit will be cleared when the issm file
  54. is closed. No read, write or other operations can be performed on
  55. the issm file.
  56. /dev files
  57. To create the appropriate character device files automatically with
  58. udev, a rule like
  59. KERNEL="umad*", NAME="infiniband/%k"
  60. KERNEL="issm*", NAME="infiniband/%k"
  61. can be used. This will create device nodes named
  62. /dev/infiniband/umad0
  63. /dev/infiniband/issm0
  64. for the first port, and so on. The InfiniBand device and port
  65. associated with these devices can be determined from the files
  66. /sys/class/infiniband_mad/umad0/ibdev
  67. /sys/class/infiniband_mad/umad0/port
  68. and
  69. /sys/class/infiniband_mad/issm0/ibdev
  70. /sys/class/infiniband_mad/issm0/port