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