ib_mad.h 25 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. };
  243. #define OPA_CLASS_PORT_INFO_PR_SUPPORT BIT(26)
  244. struct opa_class_port_info {
  245. u8 base_version;
  246. u8 class_version;
  247. __be16 cap_mask;
  248. __be32 cap_mask2_resp_time;
  249. u8 redirect_gid[16];
  250. __be32 redirect_tc_fl;
  251. __be32 redirect_lid;
  252. __be32 redirect_sl_qp;
  253. __be32 redirect_qkey;
  254. u8 trap_gid[16];
  255. __be32 trap_tc_fl;
  256. __be32 trap_lid;
  257. __be32 trap_hl_qp;
  258. __be32 trap_qkey;
  259. __be16 trap_pkey;
  260. __be16 redirect_pkey;
  261. u8 trap_sl_rsvd;
  262. u8 reserved[3];
  263. } __packed;
  264. /**
  265. * ib_get_cpi_resp_time - Returns the resp_time value from
  266. * cap_mask2_resp_time in ib_class_port_info.
  267. * @cpi: A struct ib_class_port_info mad.
  268. */
  269. static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)
  270. {
  271. return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &
  272. IB_CLASS_PORT_INFO_RESP_TIME_MASK);
  273. }
  274. /**
  275. * ib_set_cpi_resptime - Sets the response time in an
  276. * ib_class_port_info mad.
  277. * @cpi: A struct ib_class_port_info.
  278. * @rtime: The response time to set.
  279. */
  280. static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,
  281. u8 rtime)
  282. {
  283. cpi->cap_mask2_resp_time =
  284. (cpi->cap_mask2_resp_time &
  285. cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
  286. cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);
  287. }
  288. /**
  289. * ib_get_cpi_capmask2 - Returns the capmask2 value from
  290. * cap_mask2_resp_time in ib_class_port_info.
  291. * @cpi: A struct ib_class_port_info mad.
  292. */
  293. static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)
  294. {
  295. return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
  296. IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
  297. }
  298. /**
  299. * ib_set_cpi_capmask2 - Sets the capmask2 in an
  300. * ib_class_port_info mad.
  301. * @cpi: A struct ib_class_port_info.
  302. * @capmask2: The capmask2 to set.
  303. */
  304. static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,
  305. u32 capmask2)
  306. {
  307. cpi->cap_mask2_resp_time =
  308. (cpi->cap_mask2_resp_time &
  309. cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
  310. cpu_to_be32(capmask2 <<
  311. IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
  312. }
  313. /**
  314. * opa_get_cpi_capmask2 - Returns the capmask2 value from
  315. * cap_mask2_resp_time in ib_class_port_info.
  316. * @cpi: A struct opa_class_port_info mad.
  317. */
  318. static inline u32 opa_get_cpi_capmask2(struct opa_class_port_info *cpi)
  319. {
  320. return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
  321. IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
  322. }
  323. struct ib_mad_notice_attr {
  324. u8 generic_type;
  325. u8 prod_type_msb;
  326. __be16 prod_type_lsb;
  327. __be16 trap_num;
  328. __be16 issuer_lid;
  329. __be16 toggle_count;
  330. union {
  331. struct {
  332. u8 details[54];
  333. } raw_data;
  334. struct {
  335. __be16 reserved;
  336. __be16 lid; /* where violation happened */
  337. u8 port_num; /* where violation happened */
  338. } __packed ntc_129_131;
  339. struct {
  340. __be16 reserved;
  341. __be16 lid; /* LID where change occurred */
  342. u8 reserved2;
  343. u8 local_changes; /* low bit - local changes */
  344. __be32 new_cap_mask; /* new capability mask */
  345. u8 reserved3;
  346. u8 change_flags; /* low 3 bits only */
  347. } __packed ntc_144;
  348. struct {
  349. __be16 reserved;
  350. __be16 lid; /* lid where sys guid changed */
  351. __be16 reserved2;
  352. __be64 new_sys_guid;
  353. } __packed ntc_145;
  354. struct {
  355. __be16 reserved;
  356. __be16 lid;
  357. __be16 dr_slid;
  358. u8 method;
  359. u8 reserved2;
  360. __be16 attr_id;
  361. __be32 attr_mod;
  362. __be64 mkey;
  363. u8 reserved3;
  364. u8 dr_trunc_hop;
  365. u8 dr_rtn_path[30];
  366. } __packed ntc_256;
  367. struct {
  368. __be16 reserved;
  369. __be16 lid1;
  370. __be16 lid2;
  371. __be32 key;
  372. __be32 sl_qp1; /* SL: high 4 bits */
  373. __be32 qp2; /* high 8 bits reserved */
  374. union ib_gid gid1;
  375. union ib_gid gid2;
  376. } __packed ntc_257_258;
  377. } details;
  378. };
  379. /**
  380. * ib_mad_send_buf - MAD data buffer and work request for sends.
  381. * @next: A pointer used to chain together MADs for posting.
  382. * @mad: References an allocated MAD data buffer for MADs that do not have
  383. * RMPP active. For MADs using RMPP, references the common and management
  384. * class specific headers.
  385. * @mad_agent: MAD agent that allocated the buffer.
  386. * @ah: The address handle to use when sending the MAD.
  387. * @context: User-controlled context fields.
  388. * @hdr_len: Indicates the size of the data header of the MAD. This length
  389. * includes the common MAD, RMPP, and class specific headers.
  390. * @data_len: Indicates the total size of user-transferred data.
  391. * @seg_count: The number of RMPP segments allocated for this send.
  392. * @seg_size: Size of the data in each RMPP segment. This does not include
  393. * class specific headers.
  394. * @seg_rmpp_size: Size of each RMPP segment including the class specific
  395. * headers.
  396. * @timeout_ms: Time to wait for a response.
  397. * @retries: Number of times to retry a request for a response. For MADs
  398. * using RMPP, this applies per window. On completion, returns the number
  399. * of retries needed to complete the transfer.
  400. *
  401. * Users are responsible for initializing the MAD buffer itself, with the
  402. * exception of any RMPP header. Additional segment buffer space allocated
  403. * beyond data_len is padding.
  404. */
  405. struct ib_mad_send_buf {
  406. struct ib_mad_send_buf *next;
  407. void *mad;
  408. struct ib_mad_agent *mad_agent;
  409. struct ib_ah *ah;
  410. void *context[2];
  411. int hdr_len;
  412. int data_len;
  413. int seg_count;
  414. int seg_size;
  415. int seg_rmpp_size;
  416. int timeout_ms;
  417. int retries;
  418. };
  419. /**
  420. * ib_response_mad - Returns if the specified MAD has been generated in
  421. * response to a sent request or trap.
  422. */
  423. int ib_response_mad(const struct ib_mad_hdr *hdr);
  424. /**
  425. * ib_get_rmpp_resptime - Returns the RMPP response time.
  426. * @rmpp_hdr: An RMPP header.
  427. */
  428. static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)
  429. {
  430. return rmpp_hdr->rmpp_rtime_flags >> 3;
  431. }
  432. /**
  433. * ib_get_rmpp_flags - Returns the RMPP flags.
  434. * @rmpp_hdr: An RMPP header.
  435. */
  436. static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)
  437. {
  438. return rmpp_hdr->rmpp_rtime_flags & 0x7;
  439. }
  440. /**
  441. * ib_set_rmpp_resptime - Sets the response time in an RMPP header.
  442. * @rmpp_hdr: An RMPP header.
  443. * @rtime: The response time to set.
  444. */
  445. static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)
  446. {
  447. rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);
  448. }
  449. /**
  450. * ib_set_rmpp_flags - Sets the flags in an RMPP header.
  451. * @rmpp_hdr: An RMPP header.
  452. * @flags: The flags to set.
  453. */
  454. static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)
  455. {
  456. rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |
  457. (flags & 0x7);
  458. }
  459. struct ib_mad_agent;
  460. struct ib_mad_send_wc;
  461. struct ib_mad_recv_wc;
  462. /**
  463. * ib_mad_send_handler - callback handler for a sent MAD.
  464. * @mad_agent: MAD agent that sent the MAD.
  465. * @mad_send_wc: Send work completion information on the sent MAD.
  466. */
  467. typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
  468. struct ib_mad_send_wc *mad_send_wc);
  469. /**
  470. * ib_mad_recv_handler - callback handler for a received MAD.
  471. * @mad_agent: MAD agent requesting the received MAD.
  472. * @send_buf: Send buffer if found, else NULL
  473. * @mad_recv_wc: Received work completion information on the received MAD.
  474. *
  475. * MADs received in response to a send request operation will be handed to
  476. * the user before the send operation completes. All data buffers given
  477. * to registered agents through this routine are owned by the receiving
  478. * client.
  479. */
  480. typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
  481. struct ib_mad_send_buf *send_buf,
  482. struct ib_mad_recv_wc *mad_recv_wc);
  483. /**
  484. * ib_mad_agent - Used to track MAD registration with the access layer.
  485. * @device: Reference to device registration is on.
  486. * @qp: Reference to QP used for sending and receiving MADs.
  487. * @mr: Memory region for system memory usable for DMA.
  488. * @recv_handler: Callback handler for a received MAD.
  489. * @send_handler: Callback handler for a sent MAD.
  490. * @context: User-specified context associated with this registration.
  491. * @hi_tid: Access layer assigned transaction ID for this client.
  492. * Unsolicited MADs sent by this client will have the upper 32-bits
  493. * of their TID set to this value.
  494. * @flags: registration flags
  495. * @port_num: Port number on which QP is registered
  496. * @rmpp_version: If set, indicates the RMPP version used by this agent.
  497. */
  498. enum {
  499. IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,
  500. };
  501. struct ib_mad_agent {
  502. struct ib_device *device;
  503. struct ib_qp *qp;
  504. ib_mad_recv_handler recv_handler;
  505. ib_mad_send_handler send_handler;
  506. void *context;
  507. u32 hi_tid;
  508. u32 flags;
  509. void *security;
  510. struct list_head mad_agent_sec_list;
  511. u8 port_num;
  512. u8 rmpp_version;
  513. bool smp_allowed;
  514. };
  515. /**
  516. * ib_mad_send_wc - MAD send completion information.
  517. * @send_buf: Send MAD data buffer associated with the send MAD request.
  518. * @status: Completion status.
  519. * @vendor_err: Optional vendor error information returned with a failed
  520. * request.
  521. */
  522. struct ib_mad_send_wc {
  523. struct ib_mad_send_buf *send_buf;
  524. enum ib_wc_status status;
  525. u32 vendor_err;
  526. };
  527. /**
  528. * ib_mad_recv_buf - received MAD buffer information.
  529. * @list: Reference to next data buffer for a received RMPP MAD.
  530. * @grh: References a data buffer containing the global route header.
  531. * The data refereced by this buffer is only valid if the GRH is
  532. * valid.
  533. * @mad: References the start of the received MAD.
  534. */
  535. struct ib_mad_recv_buf {
  536. struct list_head list;
  537. struct ib_grh *grh;
  538. union {
  539. struct ib_mad *mad;
  540. struct opa_mad *opa_mad;
  541. };
  542. };
  543. /**
  544. * ib_mad_recv_wc - received MAD information.
  545. * @wc: Completion information for the received data.
  546. * @recv_buf: Specifies the location of the received data buffer(s).
  547. * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.
  548. * @mad_len: The length of the received MAD, without duplicated headers.
  549. * @mad_seg_size: The size of individual MAD segments
  550. *
  551. * For received response, the wr_id contains a pointer to the ib_mad_send_buf
  552. * for the corresponding send request.
  553. */
  554. struct ib_mad_recv_wc {
  555. struct ib_wc *wc;
  556. struct ib_mad_recv_buf recv_buf;
  557. struct list_head rmpp_list;
  558. int mad_len;
  559. size_t mad_seg_size;
  560. };
  561. /**
  562. * ib_mad_reg_req - MAD registration request
  563. * @mgmt_class: Indicates which management class of MADs should be receive
  564. * by the caller. This field is only required if the user wishes to
  565. * receive unsolicited MADs, otherwise it should be 0.
  566. * @mgmt_class_version: Indicates which version of MADs for the given
  567. * management class to receive.
  568. * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
  569. * in the range from 0x30 to 0x4f. Otherwise not used.
  570. * @method_mask: The caller will receive unsolicited MADs for any method
  571. * where @method_mask = 1.
  572. *
  573. */
  574. struct ib_mad_reg_req {
  575. u8 mgmt_class;
  576. u8 mgmt_class_version;
  577. u8 oui[3];
  578. DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
  579. };
  580. /**
  581. * ib_register_mad_agent - Register to send/receive MADs.
  582. * @device: The device to register with.
  583. * @port_num: The port on the specified device to use.
  584. * @qp_type: Specifies which QP to access. Must be either
  585. * IB_QPT_SMI or IB_QPT_GSI.
  586. * @mad_reg_req: Specifies which unsolicited MADs should be received
  587. * by the caller. This parameter may be NULL if the caller only
  588. * wishes to receive solicited responses.
  589. * @rmpp_version: If set, indicates that the client will send
  590. * and receive MADs that contain the RMPP header for the given version.
  591. * If set to 0, indicates that RMPP is not used by this client.
  592. * @send_handler: The completion callback routine invoked after a send
  593. * request has completed.
  594. * @recv_handler: The completion callback routine invoked for a received
  595. * MAD.
  596. * @context: User specified context associated with the registration.
  597. * @registration_flags: Registration flags to set for this agent
  598. */
  599. struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
  600. u8 port_num,
  601. enum ib_qp_type qp_type,
  602. struct ib_mad_reg_req *mad_reg_req,
  603. u8 rmpp_version,
  604. ib_mad_send_handler send_handler,
  605. ib_mad_recv_handler recv_handler,
  606. void *context,
  607. u32 registration_flags);
  608. /**
  609. * ib_unregister_mad_agent - Unregisters a client from using MAD services.
  610. * @mad_agent: Corresponding MAD registration request to deregister.
  611. *
  612. * After invoking this routine, MAD services are no longer usable by the
  613. * client on the associated QP.
  614. */
  615. void ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
  616. /**
  617. * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
  618. * with the registered client.
  619. * @send_buf: Specifies the information needed to send the MAD(s).
  620. * @bad_send_buf: Specifies the MAD on which an error was encountered. This
  621. * parameter is optional if only a single MAD is posted.
  622. *
  623. * Sent MADs are not guaranteed to complete in the order that they were posted.
  624. *
  625. * If the MAD requires RMPP, the data buffer should contain a single copy
  626. * of the common MAD, RMPP, and class specific headers, followed by the class
  627. * defined data. If the class defined data would not divide evenly into
  628. * RMPP segments, then space must be allocated at the end of the referenced
  629. * buffer for any required padding. To indicate the amount of class defined
  630. * data being transferred, the paylen_newwin field in the RMPP header should
  631. * be set to the size of the class specific header plus the amount of class
  632. * defined data being transferred. The paylen_newwin field should be
  633. * specified in network-byte order.
  634. */
  635. int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
  636. struct ib_mad_send_buf **bad_send_buf);
  637. /**
  638. * ib_free_recv_mad - Returns data buffers used to receive a MAD.
  639. * @mad_recv_wc: Work completion information for a received MAD.
  640. *
  641. * Clients receiving MADs through their ib_mad_recv_handler must call this
  642. * routine to return the work completion buffers to the access layer.
  643. */
  644. void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
  645. /**
  646. * ib_cancel_mad - Cancels an outstanding send MAD operation.
  647. * @mad_agent: Specifies the registration associated with sent MAD.
  648. * @send_buf: Indicates the MAD to cancel.
  649. *
  650. * MADs will be returned to the user through the corresponding
  651. * ib_mad_send_handler.
  652. */
  653. void ib_cancel_mad(struct ib_mad_agent *mad_agent,
  654. struct ib_mad_send_buf *send_buf);
  655. /**
  656. * ib_modify_mad - Modifies an outstanding send MAD operation.
  657. * @mad_agent: Specifies the registration associated with sent MAD.
  658. * @send_buf: Indicates the MAD to modify.
  659. * @timeout_ms: New timeout value for sent MAD.
  660. *
  661. * This call will reset the timeout value for a sent MAD to the specified
  662. * value.
  663. */
  664. int ib_modify_mad(struct ib_mad_agent *mad_agent,
  665. struct ib_mad_send_buf *send_buf, u32 timeout_ms);
  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 */