You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ib_mad.c 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. This software is available to you under a choice of one of two
  3. licenses. You may choose to be licensed under the terms of the GNU
  4. General Public License (GPL) Version 2, available at
  5. <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
  6. license, available in the LICENSE.TXT file accompanying this
  7. software. These details are also available at
  8. <http://openib.org/license.html>.
  9. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. SOFTWARE.
  17. Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  18. */
  19. #include "ib_mad.h"
  20. #include "mad_attrib.h"
  21. #include "cmdif.h"
  22. #include "ib_driver.h"
  23. #define TID_START 0x1234
  24. #define TID_INC 117
  25. static u32 next_tid = TID_START;
  26. /*
  27. * get_port_info
  28. *
  29. * query the local device for the portinfo attribute
  30. *
  31. * port(in) port number to query
  32. * buf(out) buffer to hold the result
  33. */
  34. static int get_port_info(__u8 port, struct port_info_st *buf, __u16 * status)
  35. {
  36. union port_info_mad_u *inprm;
  37. union port_info_mad_u *outprm;
  38. int rc;
  39. inprm = get_inprm_buf();
  40. outprm = get_outprm_buf();
  41. memset(inprm, 0, sizeof *inprm);
  42. inprm->mad.mad_hdr.method = IB_MGMT_METHOD_GET;
  43. inprm->mad.mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  44. inprm->mad.mad_hdr.class_version = 1;
  45. inprm->mad.mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  46. inprm->mad.mad_hdr.attr_id = IB_SMP_ATTR_PORT_INFO;
  47. inprm->mad.mad_hdr.attr_mod = port;
  48. rc = cmd_mad_ifc(inprm, (struct ib_mad_st *)outprm, port);
  49. if (!rc) {
  50. memcpy(buf, &outprm->mad.port_info,
  51. sizeof(outprm->mad.port_info));
  52. *status = inprm->mad.mad_hdr.status;
  53. if (!(*status)) {
  54. ib_data.sm_lid = outprm->mad.port_info.mastersm_lid;
  55. memcpy(&ib_data.port_gid.raw[0],
  56. outprm->mad.port_info.gid_prefix, 8);
  57. cpu_to_be_buf(&ib_data.port_gid.raw[0], 8);
  58. }
  59. }
  60. return rc;
  61. }
  62. /*
  63. * get_guid_info
  64. *
  65. * query the local device for the guidinfo attribute
  66. *
  67. * buf(out) buffer to hold the result
  68. */
  69. static int get_guid_info(__u16 * status)
  70. {
  71. union guid_info_mad_u *inprm;
  72. union guid_info_mad_u *outprm;
  73. int rc;
  74. inprm = get_inprm_buf();
  75. outprm = get_outprm_buf();
  76. memset(inprm, 0, sizeof *inprm);
  77. inprm->mad.mad_hdr.method = IB_MGMT_METHOD_GET;
  78. inprm->mad.mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  79. inprm->mad.mad_hdr.class_version = 1;
  80. inprm->mad.mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  81. inprm->mad.mad_hdr.attr_id = IB_SMP_ATTR_GUID_INFO;
  82. inprm->mad.mad_hdr.attr_mod = 0;
  83. rc = cmd_mad_ifc(inprm, (struct ib_mad_st *)outprm, ib_data.port);
  84. if (!rc) {
  85. *status = inprm->mad.mad_hdr.status;
  86. if (!(*status)) {
  87. memcpy(&ib_data.port_gid.raw[8],
  88. &outprm->mad.guid_info.gid_tbl[0], 8);
  89. cpu_to_be_buf(&ib_data.port_gid.raw[8], 8);
  90. }
  91. }
  92. return rc;
  93. }
  94. static int get_pkey_tbl(struct pkey_tbl_st *pkey_tbl, __u16 * status)
  95. {
  96. union pkey_tbl_mad_u *inprm;
  97. union pkey_tbl_mad_u *outprm;
  98. int rc;
  99. inprm = get_inprm_buf();
  100. outprm = get_outprm_buf();
  101. memset(inprm, 0, sizeof *inprm);
  102. memset(outprm, 0, sizeof *outprm);
  103. inprm->mad.mad_hdr.method = IB_MGMT_METHOD_GET;
  104. inprm->mad.mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  105. inprm->mad.mad_hdr.class_version = 1;
  106. inprm->mad.mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  107. inprm->mad.mad_hdr.attr_id = IB_SMP_ATTR_PKEY_TABLE;
  108. inprm->mad.mad_hdr.attr_mod = 0;
  109. rc = cmd_mad_ifc(inprm, (struct ib_mad_st *)outprm, 1);
  110. if (!rc) {
  111. if (pkey_tbl)
  112. memcpy(pkey_tbl, &outprm->mad.pkey_tbl, 2);
  113. *status = inprm->mad.mad_hdr.status;
  114. if (!(*status)) {
  115. ib_data.pkey = outprm->mad.pkey_tbl.pkey_tbl[0][1];
  116. ib_data.bcast_gid.raw[4] =
  117. outprm->mad.pkey_tbl.pkey_tbl[0][1] >> 8;
  118. ib_data.bcast_gid.raw[5] =
  119. outprm->mad.pkey_tbl.pkey_tbl[0][1] & 0xff;
  120. }
  121. }
  122. return rc;
  123. }
  124. static int join_mc_group(__u32 * qkey_p, __u16 * mlid_p, __u8 join)
  125. {
  126. struct mc_member_mad_st *mad, *rcv_mad;
  127. void *snd_wqe;
  128. void *tmp_wqe;
  129. udqp_t qp;
  130. void *av;
  131. int rc;
  132. u32 tid;
  133. void *rcv_wqe;
  134. int is_good;
  135. qp = ib_data.mads_qp;
  136. snd_wqe = alloc_send_wqe(qp);
  137. if (!snd_wqe) {
  138. eprintf("");
  139. return -1;
  140. }
  141. tprintf("allocated snd_wqe=0x%lx", snd_wqe);
  142. mad = get_send_wqe_buf(snd_wqe, 0);
  143. memset(mad, 0, 256);
  144. av = alloc_ud_av();
  145. if (!av) {
  146. eprintf("");
  147. free_wqe(snd_wqe);
  148. return -1;
  149. }
  150. modify_av_params(av, ib_data.sm_lid, 0, 0, 0, NULL, SA_QPN);
  151. prep_send_wqe_buf(qp, av, snd_wqe, NULL, 0, 256, 0);
  152. mad->mad_hdr.method = join ? IB_MGMT_METHOD_SET : IB_MGMT_METHOD_DELETE;
  153. mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  154. mad->mad_hdr.class_version = 2;
  155. mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  156. mad->mad_hdr.attr_id = IB_SA_ATTR_MC_MEMBER_REC;
  157. tid = next_tid;
  158. next_tid += TID_INC;
  159. mad->mad_hdr.tid[1] = tid;
  160. mad->sa_hdr.comp_mask[1] = IB_SA_MCMEMBER_REC_MGID |
  161. IB_SA_MCMEMBER_REC_PORT_GID | IB_SA_MCMEMBER_REC_JOIN_STATE;
  162. mad->mc_member.combined4 |= (1 << 24); /*mad->mc_member.join_state = 1; */
  163. be_to_cpu_buf(mad, sizeof *mad);
  164. memcpy(mad->mc_member.mgid, ib_data.bcast_gid.raw, 16);
  165. memcpy(mad->mc_member.port_gid, ib_data.port_gid.raw, 16);
  166. rc = post_send_req(qp, snd_wqe, 1);
  167. if (rc) {
  168. eprintf("");
  169. free_ud_av(av);
  170. free_wqe(snd_wqe);
  171. return -1;
  172. }
  173. tprintf("");
  174. /* poll the CQ to get the completions
  175. on the send and the expected receive */
  176. /* send completion */
  177. rc = poll_cqe_tout(ib_data.mads_snd_cq, SEND_CQE_POLL_TOUT, &tmp_wqe,
  178. &is_good);
  179. if (rc) {
  180. eprintf("");
  181. return -1;
  182. }
  183. if (tmp_wqe != snd_wqe) {
  184. eprintf("");
  185. return -1;
  186. }
  187. if (free_wqe(snd_wqe)) {
  188. eprintf("");
  189. return -1;
  190. }
  191. free_ud_av(av);
  192. if (!is_good) {
  193. eprintf("");
  194. return -1;
  195. }
  196. /* receive completion */
  197. rc = poll_cqe_tout(ib_data.mads_rcv_cq, SA_RESP_POLL_TOUT, &rcv_wqe,
  198. &is_good);
  199. if (rc) {
  200. eprintf("");
  201. return -1;
  202. }
  203. if (is_good) {
  204. rcv_mad = get_rcv_wqe_buf(rcv_wqe, 1);
  205. be_to_cpu_buf(rcv_mad, sizeof *rcv_mad);
  206. if (rcv_mad->mad_hdr.tid[1] == tid) {
  207. /* that's our response */
  208. if (mad->mad_hdr.status == 0) {
  209. /* good response - save results */
  210. *qkey_p = rcv_mad->mc_member.q_key;
  211. *mlid_p = rcv_mad->mc_member.combined1 >> 16; // rcv_mad->mc_member.mlid;
  212. } else {
  213. /* join failed */
  214. eprintf("");
  215. return -1;
  216. }
  217. } else {
  218. /* not our response */
  219. eprintf("");
  220. return -1;
  221. }
  222. }
  223. if (free_wqe(rcv_wqe)) {
  224. eprintf("");
  225. return -1;
  226. }
  227. return is_good ? 0 : -1;
  228. }
  229. static int get_path_record(union ib_gid_u *dgid, __u16 * dlid_p, u8 * sl_p,
  230. u8 * rate_p)
  231. {
  232. struct path_record_mad_st *mad, *rcv_mad;
  233. void *snd_wqe;
  234. udqp_t qp;
  235. ud_av_t av;
  236. void *tmp_wqe;
  237. void *rcv_wqe;
  238. u32 tid;
  239. int rc;
  240. int is_good;
  241. tprintf("gid=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:"
  242. "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  243. dgid->raw[0], dgid->raw[1], dgid->raw[2], dgid->raw[3],
  244. dgid->raw[4], dgid->raw[5], dgid->raw[6], dgid->raw[7],
  245. dgid->raw[8], dgid->raw[9], dgid->raw[10], dgid->raw[11],
  246. dgid->raw[12], dgid->raw[13], dgid->raw[14], dgid->raw[15]);
  247. qp = ib_data.mads_qp;
  248. snd_wqe = alloc_send_wqe(qp);
  249. if (!snd_wqe) {
  250. eprintf("");
  251. return -1;
  252. }
  253. mad = get_send_wqe_buf(snd_wqe, 0);
  254. memset(mad, 0, 256);
  255. av = alloc_ud_av();
  256. if (!av) {
  257. eprintf("");
  258. free_wqe(snd_wqe);
  259. return -1;
  260. }
  261. modify_av_params(av, ib_data.sm_lid, 0, 0, 0, NULL, SA_QPN);
  262. prep_send_wqe_buf(qp, av, snd_wqe, NULL, 0, 256, 0);
  263. mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  264. mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  265. mad->mad_hdr.class_version = 2;
  266. mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
  267. mad->mad_hdr.attr_id = IB_SA_ATTR_PATH_REC;
  268. tid = next_tid;
  269. next_tid += TID_INC;
  270. mad->mad_hdr.tid[1] = tid;
  271. memcpy(mad->path_record.dgid.raw, dgid->raw, 16);
  272. cpu_to_be_buf(mad->path_record.dgid.raw, 16);
  273. mad->sa_hdr.comp_mask[1] = IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID;
  274. cpu_to_be_buf(mad, sizeof *mad);
  275. memcpy(mad->path_record.sgid.raw, ib_data.port_gid.raw, 16);
  276. rc = post_send_req(qp, snd_wqe, 1);
  277. if (rc) {
  278. eprintf("");
  279. free_ud_av(av);
  280. free_wqe(snd_wqe);
  281. return rc;
  282. }
  283. /* poll the CQ to get the completions
  284. on the send and the expected receive */
  285. /* send completion */
  286. rc = poll_cqe_tout(ib_data.mads_snd_cq, SEND_CQE_POLL_TOUT, &tmp_wqe,
  287. &is_good);
  288. if (rc) {
  289. eprintf("");
  290. return -1;
  291. }
  292. if (tmp_wqe != snd_wqe) {
  293. eprintf("");
  294. return -1;
  295. }
  296. if (free_wqe(snd_wqe)) {
  297. eprintf("");
  298. return -1;
  299. }
  300. free_ud_av(av);
  301. if (!is_good) {
  302. eprintf("");
  303. return -1;
  304. }
  305. /* receive completion */
  306. rc = poll_cqe_tout(ib_data.mads_rcv_cq, SA_RESP_POLL_TOUT, &rcv_wqe,
  307. &is_good);
  308. if (rc) {
  309. eprintf("");
  310. return -1;
  311. }
  312. if (is_good) {
  313. rcv_mad = get_rcv_wqe_buf(rcv_wqe, 1);
  314. be_to_cpu_buf(rcv_mad, sizeof *rcv_mad);
  315. if (rcv_mad->mad_hdr.tid[1] == tid) {
  316. /* that's our response */
  317. if (mad->mad_hdr.status == 0) {
  318. /* good response - save results */
  319. *dlid_p = rcv_mad->path_record.dlid;
  320. *sl_p = (rcv_mad->path_record.combined3 >> 16) & 0xf; // rcv_mad->path_record.sl;
  321. *rate_p = rcv_mad->path_record.combined3 & 0x3f; //rcv_mad->path_record.rate;
  322. } else {
  323. /* join failed */
  324. eprintf("");
  325. return -1;
  326. }
  327. } else {
  328. /* not our response */
  329. eprintf("");
  330. return -1;
  331. }
  332. }
  333. if (free_wqe(rcv_wqe)) {
  334. eprintf("");
  335. return -1;
  336. }
  337. tprintf("");
  338. return is_good ? 0 : -1;
  339. }