ib_mad.h 25 KB

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