ib_mad.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2. /*
  3. * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  4. * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
  5. * Copyright (c) 2004 Intel Corporation. All rights reserved.
  6. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  7. * Copyright (c) 2004-2006 Voltaire Corporation. All rights reserved.
  8. */
  9. #ifndef IB_MAD_H
  10. #define IB_MAD_H
  11. #include <linux/list.h>
  12. #include <rdma/ib_verbs.h>
  13. #include <uapi/rdma/ib_user_mad.h>
  14. /* Management base versions */
  15. #define IB_MGMT_BASE_VERSION 1
  16. #define OPA_MGMT_BASE_VERSION 0x80
  17. #define OPA_SM_CLASS_VERSION 0x80
  18. /* Management classes */
  19. #define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
  20. #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
  21. #define IB_MGMT_CLASS_SUBN_ADM 0x03
  22. #define IB_MGMT_CLASS_PERF_MGMT 0x04
  23. #define IB_MGMT_CLASS_BM 0x05
  24. #define IB_MGMT_CLASS_DEVICE_MGMT 0x06
  25. #define IB_MGMT_CLASS_CM 0x07
  26. #define IB_MGMT_CLASS_SNMP 0x08
  27. #define IB_MGMT_CLASS_DEVICE_ADM 0x10
  28. #define IB_MGMT_CLASS_BOOT_MGMT 0x11
  29. #define IB_MGMT_CLASS_BIS 0x12
  30. #define IB_MGMT_CLASS_CONG_MGMT 0x21
  31. #define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
  32. #define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
  33. #define IB_OPENIB_OUI (0x001405)
  34. /* Management methods */
  35. #define IB_MGMT_METHOD_GET 0x01
  36. #define IB_MGMT_METHOD_SET 0x02
  37. #define IB_MGMT_METHOD_GET_RESP 0x81
  38. #define IB_MGMT_METHOD_SEND 0x03
  39. #define IB_MGMT_METHOD_TRAP 0x05
  40. #define IB_MGMT_METHOD_REPORT 0x06
  41. #define IB_MGMT_METHOD_REPORT_RESP 0x86
  42. #define IB_MGMT_METHOD_TRAP_REPRESS 0x07
  43. #define IB_MGMT_METHOD_RESP 0x80
  44. #define IB_BM_ATTR_MOD_RESP cpu_to_be32(1)
  45. #define IB_MGMT_MAX_METHODS 128
  46. /* MAD Status field bit masks */
  47. #define IB_MGMT_MAD_STATUS_SUCCESS 0x0000
  48. #define IB_MGMT_MAD_STATUS_BUSY 0x0001
  49. #define IB_MGMT_MAD_STATUS_REDIRECT_REQD 0x0002
  50. #define IB_MGMT_MAD_STATUS_BAD_VERSION 0x0004
  51. #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD 0x0008
  52. #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB 0x000c
  53. #define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE 0x001c
  54. /* RMPP information */
  55. #define IB_MGMT_RMPP_VERSION 1
  56. #define IB_MGMT_RMPP_TYPE_DATA 1
  57. #define IB_MGMT_RMPP_TYPE_ACK 2
  58. #define IB_MGMT_RMPP_TYPE_STOP 3
  59. #define IB_MGMT_RMPP_TYPE_ABORT 4
  60. #define IB_MGMT_RMPP_FLAG_ACTIVE 1
  61. #define IB_MGMT_RMPP_FLAG_FIRST (1<<1)
  62. #define IB_MGMT_RMPP_FLAG_LAST (1<<2)
  63. #define IB_MGMT_RMPP_NO_RESPTIME 0x1F
  64. #define IB_MGMT_RMPP_STATUS_SUCCESS 0
  65. #define IB_MGMT_RMPP_STATUS_RESX 1
  66. #define IB_MGMT_RMPP_STATUS_ABORT_MIN 118
  67. #define IB_MGMT_RMPP_STATUS_T2L 118
  68. #define IB_MGMT_RMPP_STATUS_BAD_LEN 119
  69. #define IB_MGMT_RMPP_STATUS_BAD_SEG 120
  70. #define IB_MGMT_RMPP_STATUS_BADT 121
  71. #define IB_MGMT_RMPP_STATUS_W2S 122
  72. #define IB_MGMT_RMPP_STATUS_S2B 123
  73. #define IB_MGMT_RMPP_STATUS_BAD_STATUS 124
  74. #define IB_MGMT_RMPP_STATUS_UNV 125
  75. #define IB_MGMT_RMPP_STATUS_TMR 126
  76. #define IB_MGMT_RMPP_STATUS_UNSPEC 127
  77. #define IB_MGMT_RMPP_STATUS_ABORT_MAX 127
  78. #define IB_QP0 0
  79. #define IB_QP1 cpu_to_be32(1)
  80. #define IB_QP1_QKEY 0x80010000
  81. #define IB_QP_SET_QKEY 0x80000000
  82. #define IB_DEFAULT_PKEY_PARTIAL 0x7FFF
  83. #define IB_DEFAULT_PKEY_FULL 0xFFFF
  84. /*
  85. * Generic trap/notice types
  86. */
  87. #define IB_NOTICE_TYPE_FATAL 0x80
  88. #define IB_NOTICE_TYPE_URGENT 0x81
  89. #define IB_NOTICE_TYPE_SECURITY 0x82
  90. #define IB_NOTICE_TYPE_SM 0x83
  91. #define IB_NOTICE_TYPE_INFO 0x84
  92. /*
  93. * Generic trap/notice producers
  94. */
  95. #define IB_NOTICE_PROD_CA cpu_to_be16(1)
  96. #define IB_NOTICE_PROD_SWITCH cpu_to_be16(2)
  97. #define IB_NOTICE_PROD_ROUTER cpu_to_be16(3)
  98. #define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16(4)
  99. enum {
  100. IB_MGMT_MAD_HDR = 24,
  101. IB_MGMT_MAD_DATA = 232,
  102. IB_MGMT_RMPP_HDR = 36,
  103. IB_MGMT_RMPP_DATA = 220,
  104. IB_MGMT_VENDOR_HDR = 40,
  105. IB_MGMT_VENDOR_DATA = 216,
  106. IB_MGMT_SA_HDR = 56,
  107. IB_MGMT_SA_DATA = 200,
  108. IB_MGMT_DEVICE_HDR = 64,
  109. IB_MGMT_DEVICE_DATA = 192,
  110. IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,
  111. OPA_MGMT_MAD_DATA = 2024,
  112. OPA_MGMT_RMPP_DATA = 2012,
  113. OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,
  114. };
  115. struct ib_mad_hdr {
  116. u8 base_version;
  117. u8 mgmt_class;
  118. u8 class_version;
  119. u8 method;
  120. __be16 status;
  121. __be16 class_specific;
  122. __be64 tid;
  123. __be16 attr_id;
  124. __be16 resv;
  125. __be32 attr_mod;
  126. };
  127. struct ib_rmpp_hdr {
  128. u8 rmpp_version;
  129. u8 rmpp_type;
  130. u8 rmpp_rtime_flags;
  131. u8 rmpp_status;
  132. __be32 seg_num;
  133. __be32 paylen_newwin;
  134. };
  135. typedef u64 __bitwise ib_sa_comp_mask;
  136. #define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))
  137. /*
  138. * ib_sa_hdr and ib_sa_mad structures must be packed because they have
  139. * 64-bit fields that are only 32-bit aligned. 64-bit architectures will
  140. * lay them out wrong otherwise. (And unfortunately they are sent on
  141. * the wire so we can't change the layout)
  142. */
  143. struct ib_sa_hdr {
  144. __be64 sm_key;
  145. __be16 attr_offset;
  146. __be16 reserved;
  147. ib_sa_comp_mask comp_mask;
  148. } __packed;
  149. struct ib_mad {
  150. struct ib_mad_hdr mad_hdr;
  151. u8 data[IB_MGMT_MAD_DATA];
  152. };
  153. struct opa_mad {
  154. struct ib_mad_hdr mad_hdr;
  155. u8 data[OPA_MGMT_MAD_DATA];
  156. };
  157. struct ib_rmpp_mad {
  158. struct ib_mad_hdr mad_hdr;
  159. struct ib_rmpp_hdr rmpp_hdr;
  160. u8 data[IB_MGMT_RMPP_DATA];
  161. };
  162. struct opa_rmpp_mad {
  163. struct ib_mad_hdr mad_hdr;
  164. struct ib_rmpp_hdr rmpp_hdr;
  165. u8 data[OPA_MGMT_RMPP_DATA];
  166. };
  167. struct ib_sa_mad {
  168. struct ib_mad_hdr mad_hdr;
  169. struct ib_rmpp_hdr rmpp_hdr;
  170. struct ib_sa_hdr sa_hdr;
  171. u8 data[IB_MGMT_SA_DATA];
  172. } __packed;
  173. struct ib_vendor_mad {
  174. struct ib_mad_hdr mad_hdr;
  175. struct ib_rmpp_hdr rmpp_hdr;
  176. u8 reserved;
  177. u8 oui[3];
  178. u8 data[IB_MGMT_VENDOR_DATA];
  179. };
  180. #define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001)
  181. #define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F
  182. #define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5
  183. struct ib_class_port_info {
  184. u8 base_version;
  185. u8 class_version;
  186. __be16 capability_mask;
  187. /* 27 bits for cap_mask2, 5 bits for resp_time */
  188. __be32 cap_mask2_resp_time;
  189. u8 redirect_gid[16];
  190. __be32 redirect_tcslfl;
  191. __be16 redirect_lid;
  192. __be16 redirect_pkey;
  193. __be32 redirect_qp;
  194. __be32 redirect_qkey;
  195. u8 trap_gid[16];
  196. __be32 trap_tcslfl;
  197. __be16 trap_lid;
  198. __be16 trap_pkey;
  199. __be32 trap_hlqp;
  200. __be32 trap_qkey;
  201. };
  202. /* PortInfo CapabilityMask */
  203. enum ib_port_capability_mask_bits {
  204. IB_PORT_SM = 1 << 1,
  205. IB_PORT_NOTICE_SUP = 1 << 2,
  206. IB_PORT_TRAP_SUP = 1 << 3,
  207. IB_PORT_OPT_IPD_SUP = 1 << 4,
  208. IB_PORT_AUTO_MIGR_SUP = 1 << 5,
  209. IB_PORT_SL_MAP_SUP = 1 << 6,
  210. IB_PORT_MKEY_NVRAM = 1 << 7,
  211. IB_PORT_PKEY_NVRAM = 1 << 8,
  212. IB_PORT_LED_INFO_SUP = 1 << 9,
  213. IB_PORT_SM_DISABLED = 1 << 10,
  214. IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  215. IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  216. IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
  217. IB_PORT_CAP_MASK2_SUP = 1 << 15,
  218. IB_PORT_CM_SUP = 1 << 16,
  219. IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  220. IB_PORT_REINIT_SUP = 1 << 18,
  221. IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
  222. IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
  223. IB_PORT_DR_NOTICE_SUP = 1 << 21,
  224. IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  225. IB_PORT_BOOT_MGMT_SUP = 1 << 23,
  226. IB_PORT_LINK_LATENCY_SUP = 1 << 24,
  227. IB_PORT_CLIENT_REG_SUP = 1 << 25,
  228. IB_PORT_OTHER_LOCAL_CHANGES_SUP = 1 << 26,
  229. IB_PORT_LINK_SPEED_WIDTH_TABLE_SUP = 1 << 27,
  230. IB_PORT_VENDOR_SPECIFIC_MADS_TABLE_SUP = 1 << 28,
  231. IB_PORT_MCAST_PKEY_TRAP_SUPPRESSION_SUP = 1 << 29,
  232. IB_PORT_MCAST_FDB_TOP_SUP = 1 << 30,
  233. IB_PORT_HIERARCHY_INFO_SUP = 1ULL << 31,
  234. };
  235. enum ib_port_capability_mask2_bits {
  236. IB_PORT_SET_NODE_DESC_SUP = 1 << 0,
  237. IB_PORT_EX_PORT_INFO_EX_SUP = 1 << 1,
  238. IB_PORT_VIRT_SUP = 1 << 2,
  239. IB_PORT_SWITCH_PORT_STATE_TABLE_SUP = 1 << 3,
  240. IB_PORT_LINK_WIDTH_2X_SUP = 1 << 4,
  241. IB_PORT_LINK_SPEED_HDR_SUP = 1 << 5,
  242. IB_PORT_LINK_SPEED_NDR_SUP = 1 << 10,
  243. };
  244. #define OPA_CLASS_PORT_INFO_PR_SUPPORT BIT(26)
  245. struct opa_class_port_info {
  246. u8 base_version;
  247. u8 class_version;
  248. __be16 cap_mask;
  249. __be32 cap_mask2_resp_time;
  250. u8 redirect_gid[16];
  251. __be32 redirect_tc_fl;
  252. __be32 redirect_lid;
  253. __be32 redirect_sl_qp;
  254. __be32 redirect_qkey;
  255. u8 trap_gid[16];
  256. __be32 trap_tc_fl;
  257. __be32 trap_lid;
  258. __be32 trap_hl_qp;
  259. __be32 trap_qkey;
  260. __be16 trap_pkey;
  261. __be16 redirect_pkey;
  262. u8 trap_sl_rsvd;
  263. u8 reserved[3];
  264. } __packed;
  265. /**
  266. * ib_get_cpi_resp_time - Returns the resp_time value from
  267. * cap_mask2_resp_time in ib_class_port_info.
  268. * @cpi: A struct ib_class_port_info mad.
  269. */
  270. static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)
  271. {
  272. return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &
  273. IB_CLASS_PORT_INFO_RESP_TIME_MASK);
  274. }
  275. /**
  276. * ib_set_cpi_resptime - Sets the response time in an
  277. * ib_class_port_info mad.
  278. * @cpi: A struct ib_class_port_info.
  279. * @rtime: The response time to set.
  280. */
  281. static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,
  282. u8 rtime)
  283. {
  284. cpi->cap_mask2_resp_time =
  285. (cpi->cap_mask2_resp_time &
  286. cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
  287. cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);
  288. }
  289. /**
  290. * ib_get_cpi_capmask2 - Returns the capmask2 value from
  291. * cap_mask2_resp_time in ib_class_port_info.
  292. * @cpi: A struct ib_class_port_info mad.
  293. */
  294. static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)
  295. {
  296. return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
  297. IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
  298. }
  299. /**
  300. * ib_set_cpi_capmask2 - Sets the capmask2 in an
  301. * ib_class_port_info mad.
  302. * @cpi: A struct ib_class_port_info.
  303. * @capmask2: The capmask2 to set.
  304. */
  305. static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,
  306. u32 capmask2)
  307. {
  308. cpi->cap_mask2_resp_time =
  309. (cpi->cap_mask2_resp_time &
  310. cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
  311. cpu_to_be32(capmask2 <<
  312. IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
  313. }
  314. /**
  315. * opa_get_cpi_capmask2 - Returns the capmask2 value from
  316. * cap_mask2_resp_time in ib_class_port_info.
  317. * @cpi: A struct opa_class_port_info mad.
  318. */
  319. static inline u32 opa_get_cpi_capmask2(struct opa_class_port_info *cpi)
  320. {
  321. return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
  322. IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
  323. }
  324. struct ib_mad_notice_attr {
  325. u8 generic_type;
  326. u8 prod_type_msb;
  327. __be16 prod_type_lsb;
  328. __be16 trap_num;
  329. __be16 issuer_lid;
  330. __be16 toggle_count;
  331. union {
  332. struct {
  333. u8 details[54];
  334. } raw_data;
  335. struct {
  336. __be16 reserved;
  337. __be16 lid; /* where violation happened */
  338. u8 port_num; /* where violation happened */
  339. } __packed ntc_129_131;
  340. struct {
  341. __be16 reserved;
  342. __be16 lid; /* LID where change occurred */
  343. u8 reserved2;
  344. u8 local_changes; /* low bit - local changes */
  345. __be32 new_cap_mask; /* new capability mask */
  346. u8 reserved3;
  347. u8 change_flags; /* low 3 bits only */
  348. } __packed ntc_144;
  349. struct {
  350. __be16 reserved;
  351. __be16 lid; /* lid where sys guid changed */
  352. __be16 reserved2;
  353. __be64 new_sys_guid;
  354. } __packed ntc_145;
  355. struct {
  356. __be16 reserved;
  357. __be16 lid;
  358. __be16 dr_slid;
  359. u8 method;
  360. u8 reserved2;
  361. __be16 attr_id;
  362. __be32 attr_mod;
  363. __be64 mkey;
  364. u8 reserved3;
  365. u8 dr_trunc_hop;
  366. u8 dr_rtn_path[30];
  367. } __packed ntc_256;
  368. struct {
  369. __be16 reserved;
  370. __be16 lid1;
  371. __be16 lid2;
  372. __be32 key;
  373. __be32 sl_qp1; /* SL: high 4 bits */
  374. __be32 qp2; /* high 8 bits reserved */
  375. union ib_gid gid1;
  376. union ib_gid gid2;
  377. } __packed ntc_257_258;
  378. } details;
  379. };
  380. /**
  381. * ib_mad_send_buf - MAD data buffer and work request for sends.
  382. * @next: A pointer used to chain together MADs for posting.
  383. * @mad: References an allocated MAD data buffer for MADs that do not have
  384. * RMPP active. For MADs using RMPP, references the common and management
  385. * class specific headers.
  386. * @mad_agent: MAD agent that allocated the buffer.
  387. * @ah: The address handle to use when sending the MAD.
  388. * @context: User-controlled context fields.
  389. * @hdr_len: Indicates the size of the data header of the MAD. This length
  390. * includes the common MAD, RMPP, and class specific headers.
  391. * @data_len: Indicates the total size of user-transferred data.
  392. * @seg_count: The number of RMPP segments allocated for this send.
  393. * @seg_size: Size of the data in each RMPP segment. This does not include
  394. * class specific headers.
  395. * @seg_rmpp_size: Size of each RMPP segment including the class specific
  396. * headers.
  397. * @timeout_ms: Time to wait for a response.
  398. * @retries: Number of times to retry a request for a response. For MADs
  399. * using RMPP, this applies per window. On completion, returns the number
  400. * of retries needed to complete the transfer.
  401. *
  402. * Users are responsible for initializing the MAD buffer itself, with the
  403. * exception of any RMPP header. Additional segment buffer space allocated
  404. * beyond data_len is padding.
  405. */
  406. struct ib_mad_send_buf {
  407. struct ib_mad_send_buf *next;
  408. void *mad;
  409. struct ib_mad_agent *mad_agent;
  410. struct ib_ah *ah;
  411. void *context[2];
  412. int hdr_len;
  413. int data_len;
  414. int seg_count;
  415. int seg_size;
  416. int seg_rmpp_size;
  417. int timeout_ms;
  418. int retries;
  419. };
  420. /**
  421. * ib_response_mad - Returns if the specified MAD has been generated in
  422. * response to a sent request or trap.
  423. */
  424. int ib_response_mad(const struct ib_mad_hdr *hdr);
  425. /**
  426. * ib_get_rmpp_resptime - Returns the RMPP response time.
  427. * @rmpp_hdr: An RMPP header.
  428. */
  429. static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)
  430. {
  431. return rmpp_hdr->rmpp_rtime_flags >> 3;
  432. }
  433. /**
  434. * ib_get_rmpp_flags - Returns the RMPP flags.
  435. * @rmpp_hdr: An RMPP header.
  436. */
  437. static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)
  438. {
  439. return rmpp_hdr->rmpp_rtime_flags & 0x7;
  440. }
  441. /**
  442. * ib_set_rmpp_resptime - Sets the response time in an RMPP header.
  443. * @rmpp_hdr: An RMPP header.
  444. * @rtime: The response time to set.
  445. */
  446. static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)
  447. {
  448. rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);
  449. }
  450. /**
  451. * ib_set_rmpp_flags - Sets the flags in an RMPP header.
  452. * @rmpp_hdr: An RMPP header.
  453. * @flags: The flags to set.
  454. */
  455. static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)
  456. {
  457. rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |
  458. (flags & 0x7);
  459. }
  460. struct ib_mad_agent;
  461. struct ib_mad_send_wc;
  462. struct ib_mad_recv_wc;
  463. /**
  464. * ib_mad_send_handler - callback handler for a sent MAD.
  465. * @mad_agent: MAD agent that sent the MAD.
  466. * @mad_send_wc: Send work completion information on the sent MAD.
  467. */
  468. typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
  469. struct ib_mad_send_wc *mad_send_wc);
  470. /**
  471. * ib_mad_recv_handler - callback handler for a received MAD.
  472. * @mad_agent: MAD agent requesting the received MAD.
  473. * @send_buf: Send buffer if found, else NULL
  474. * @mad_recv_wc: Received work completion information on the received MAD.
  475. *
  476. * MADs received in response to a send request operation will be handed to
  477. * the user before the send operation completes. All data buffers given
  478. * to registered agents through this routine are owned by the receiving
  479. * client.
  480. */
  481. typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
  482. struct ib_mad_send_buf *send_buf,
  483. struct ib_mad_recv_wc *mad_recv_wc);
  484. /**
  485. * ib_mad_agent - Used to track MAD registration with the access layer.
  486. * @device: Reference to device registration is on.
  487. * @qp: Reference to QP used for sending and receiving MADs.
  488. * @mr: Memory region for system memory usable for DMA.
  489. * @recv_handler: Callback handler for a received MAD.
  490. * @send_handler: Callback handler for a sent MAD.
  491. * @context: User-specified context associated with this registration.
  492. * @hi_tid: Access layer assigned transaction ID for this client.
  493. * Unsolicited MADs sent by this client will have the upper 32-bits
  494. * of their TID set to this value.
  495. * @flags: registration flags
  496. * @port_num: Port number on which QP is registered
  497. * @rmpp_version: If set, indicates the RMPP version used by this agent.
  498. */
  499. enum {
  500. IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,
  501. };
  502. struct ib_mad_agent {
  503. struct ib_device *device;
  504. struct ib_qp *qp;
  505. ib_mad_recv_handler recv_handler;
  506. ib_mad_send_handler send_handler;
  507. void *context;
  508. u32 hi_tid;
  509. u32 flags;
  510. void *security;
  511. struct list_head mad_agent_sec_list;
  512. u8 port_num;
  513. u8 rmpp_version;
  514. bool smp_allowed;
  515. };
  516. /**
  517. * ib_mad_send_wc - MAD send completion information.
  518. * @send_buf: Send MAD data buffer associated with the send MAD request.
  519. * @status: Completion status.
  520. * @vendor_err: Optional vendor error information returned with a failed
  521. * request.
  522. */
  523. struct ib_mad_send_wc {
  524. struct ib_mad_send_buf *send_buf;
  525. enum ib_wc_status status;
  526. u32 vendor_err;
  527. };
  528. /**
  529. * ib_mad_recv_buf - received MAD buffer information.
  530. * @list: Reference to next data buffer for a received RMPP MAD.
  531. * @grh: References a data buffer containing the global route header.
  532. * The data refereced by this buffer is only valid if the GRH is
  533. * valid.
  534. * @mad: References the start of the received MAD.
  535. */
  536. struct ib_mad_recv_buf {
  537. struct list_head list;
  538. struct ib_grh *grh;
  539. union {
  540. struct ib_mad *mad;
  541. struct opa_mad *opa_mad;
  542. };
  543. };
  544. /**
  545. * ib_mad_recv_wc - received MAD information.
  546. * @wc: Completion information for the received data.
  547. * @recv_buf: Specifies the location of the received data buffer(s).
  548. * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.
  549. * @mad_len: The length of the received MAD, without duplicated headers.
  550. * @mad_seg_size: The size of individual MAD segments
  551. *
  552. * For received response, the wr_id contains a pointer to the ib_mad_send_buf
  553. * for the corresponding send request.
  554. */
  555. struct ib_mad_recv_wc {
  556. struct ib_wc *wc;
  557. struct ib_mad_recv_buf recv_buf;
  558. struct list_head rmpp_list;
  559. int mad_len;
  560. size_t mad_seg_size;
  561. };
  562. /**
  563. * ib_mad_reg_req - MAD registration request
  564. * @mgmt_class: Indicates which management class of MADs should be receive
  565. * by the caller. This field is only required if the user wishes to
  566. * receive unsolicited MADs, otherwise it should be 0.
  567. * @mgmt_class_version: Indicates which version of MADs for the given
  568. * management class to receive.
  569. * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
  570. * in the range from 0x30 to 0x4f. Otherwise not used.
  571. * @method_mask: The caller will receive unsolicited MADs for any method
  572. * where @method_mask = 1.
  573. *
  574. */
  575. struct ib_mad_reg_req {
  576. u8 mgmt_class;
  577. u8 mgmt_class_version;
  578. u8 oui[3];
  579. DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
  580. };
  581. /**
  582. * ib_register_mad_agent - Register to send/receive MADs.
  583. * @device: The device to register with.
  584. * @port_num: The port on the specified device to use.
  585. * @qp_type: Specifies which QP to access. Must be either
  586. * IB_QPT_SMI or IB_QPT_GSI.
  587. * @mad_reg_req: Specifies which unsolicited MADs should be received
  588. * by the caller. This parameter may be NULL if the caller only
  589. * wishes to receive solicited responses.
  590. * @rmpp_version: If set, indicates that the client will send
  591. * and receive MADs that contain the RMPP header for the given version.
  592. * If set to 0, indicates that RMPP is not used by this client.
  593. * @send_handler: The completion callback routine invoked after a send
  594. * request has completed.
  595. * @recv_handler: The completion callback routine invoked for a received
  596. * MAD.
  597. * @context: User specified context associated with the registration.
  598. * @registration_flags: Registration flags to set for this agent
  599. */
  600. struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
  601. u32 port_num,
  602. enum ib_qp_type qp_type,
  603. struct ib_mad_reg_req *mad_reg_req,
  604. u8 rmpp_version,
  605. ib_mad_send_handler send_handler,
  606. ib_mad_recv_handler recv_handler,
  607. void *context,
  608. u32 registration_flags);
  609. /**
  610. * ib_unregister_mad_agent - Unregisters a client from using MAD services.
  611. * @mad_agent: Corresponding MAD registration request to deregister.
  612. *
  613. * After invoking this routine, MAD services are no longer usable by the
  614. * client on the associated QP.
  615. */
  616. void ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
  617. /**
  618. * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
  619. * with the registered client.
  620. * @send_buf: Specifies the information needed to send the MAD(s).
  621. * @bad_send_buf: Specifies the MAD on which an error was encountered. This
  622. * parameter is optional if only a single MAD is posted.
  623. *
  624. * Sent MADs are not guaranteed to complete in the order that they were posted.
  625. *
  626. * If the MAD requires RMPP, the data buffer should contain a single copy
  627. * of the common MAD, RMPP, and class specific headers, followed by the class
  628. * defined data. If the class defined data would not divide evenly into
  629. * RMPP segments, then space must be allocated at the end of the referenced
  630. * buffer for any required padding. To indicate the amount of class defined
  631. * data being transferred, the paylen_newwin field in the RMPP header should
  632. * be set to the size of the class specific header plus the amount of class
  633. * defined data being transferred. The paylen_newwin field should be
  634. * specified in network-byte order.
  635. */
  636. int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
  637. struct ib_mad_send_buf **bad_send_buf);
  638. /**
  639. * ib_free_recv_mad - Returns data buffers used to receive a MAD.
  640. * @mad_recv_wc: Work completion information for a received MAD.
  641. *
  642. * Clients receiving MADs through their ib_mad_recv_handler must call this
  643. * routine to return the work completion buffers to the access layer.
  644. */
  645. void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
  646. /**
  647. * ib_modify_mad - Modifies an outstanding send MAD operation.
  648. * @send_buf: Indicates the MAD to modify.
  649. * @timeout_ms: New timeout value for sent MAD.
  650. *
  651. * This call will reset the timeout value for a sent MAD to the specified
  652. * value.
  653. */
  654. int ib_modify_mad(struct ib_mad_send_buf *send_buf, u32 timeout_ms);
  655. /**
  656. * ib_cancel_mad - Cancels an outstanding send MAD operation.
  657. * @send_buf: Indicates the MAD to cancel.
  658. *
  659. * MADs will be returned to the user through the corresponding
  660. * ib_mad_send_handler.
  661. */
  662. static inline void ib_cancel_mad(struct ib_mad_send_buf *send_buf)
  663. {
  664. ib_modify_mad(send_buf, 0);
  665. }
  666. /**
  667. * ib_create_send_mad - Allocate and initialize a data buffer and work request
  668. * for sending a MAD.
  669. * @mad_agent: Specifies the registered MAD service to associate with the MAD.
  670. * @remote_qpn: Specifies the QPN of the receiving node.
  671. * @pkey_index: Specifies which PKey the MAD will be sent using. This field
  672. * is valid only if the remote_qpn is QP 1.
  673. * @rmpp_active: Indicates if the send will enable RMPP.
  674. * @hdr_len: Indicates the size of the data header of the MAD. This length
  675. * should include the common MAD header, RMPP header, plus any class
  676. * specific header.
  677. * @data_len: Indicates the size of any user-transferred data. The call will
  678. * automatically adjust the allocated buffer size to account for any
  679. * additional padding that may be necessary.
  680. * @gfp_mask: GFP mask used for the memory allocation.
  681. * @base_version: Base Version of this MAD
  682. *
  683. * This routine allocates a MAD for sending. The returned MAD send buffer
  684. * will reference a data buffer usable for sending a MAD, along
  685. * with an initialized work request structure. Users may modify the returned
  686. * MAD data buffer before posting the send.
  687. *
  688. * The returned MAD header, class specific headers, and any padding will be
  689. * cleared. Users are responsible for initializing the common MAD header,
  690. * any class specific header, and MAD data area.
  691. * If @rmpp_active is set, the RMPP header will be initialized for sending.
  692. */
  693. struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,
  694. u32 remote_qpn, u16 pkey_index,
  695. int rmpp_active,
  696. int hdr_len, int data_len,
  697. gfp_t gfp_mask,
  698. u8 base_version);
  699. /**
  700. * ib_is_mad_class_rmpp - returns whether given management class
  701. * supports RMPP.
  702. * @mgmt_class: management class
  703. *
  704. * This routine returns whether the management class supports RMPP.
  705. */
  706. int ib_is_mad_class_rmpp(u8 mgmt_class);
  707. /**
  708. * ib_get_mad_data_offset - returns the data offset for a given
  709. * management class.
  710. * @mgmt_class: management class
  711. *
  712. * This routine returns the data offset in the MAD for the management
  713. * class requested.
  714. */
  715. int ib_get_mad_data_offset(u8 mgmt_class);
  716. /**
  717. * ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.
  718. * @send_buf: Previously allocated send data buffer.
  719. * @seg_num: number of segment to return
  720. *
  721. * This routine returns a pointer to the data buffer of an RMPP MAD.
  722. * Users must provide synchronization to @send_buf around this call.
  723. */
  724. void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);
  725. /**
  726. * ib_free_send_mad - Returns data buffers used to send a MAD.
  727. * @send_buf: Previously allocated send data buffer.
  728. */
  729. void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
  730. /**
  731. * ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.
  732. * @agent: the agent in question
  733. * @return: true if agent is performing rmpp, false otherwise.
  734. */
  735. int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);
  736. #endif /* IB_MAD_H */