mad.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  2. * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/mlx5/cmd.h>
  33. #include <linux/mlx5/vport.h>
  34. #include <rdma/ib_mad.h>
  35. #include <rdma/ib_smi.h>
  36. #include <rdma/ib_pma.h>
  37. #include "mlx5_ib.h"
  38. enum {
  39. MLX5_IB_VENDOR_CLASS1 = 0x9,
  40. MLX5_IB_VENDOR_CLASS2 = 0xa
  41. };
  42. static bool can_do_mad_ifc(struct mlx5_ib_dev *dev, u8 port_num,
  43. struct ib_mad *in_mad)
  44. {
  45. if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED &&
  46. in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  47. return true;
  48. return dev->mdev->port_caps[port_num - 1].has_smi;
  49. }
  50. int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
  51. u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  52. const void *in_mad, void *response_mad)
  53. {
  54. u8 op_modifier = 0;
  55. if (!can_do_mad_ifc(dev, port, (struct ib_mad *)in_mad))
  56. return -EPERM;
  57. /* Key check traps can't be generated unless we have in_wc to
  58. * tell us where to send the trap.
  59. */
  60. if (ignore_mkey || !in_wc)
  61. op_modifier |= 0x1;
  62. if (ignore_bkey || !in_wc)
  63. op_modifier |= 0x2;
  64. return mlx5_core_mad_ifc(dev->mdev, in_mad, response_mad, op_modifier, port);
  65. }
  66. static int process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  67. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  68. const struct ib_mad *in_mad, struct ib_mad *out_mad)
  69. {
  70. u16 slid;
  71. int err;
  72. slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);
  73. if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP && slid == 0)
  74. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  75. if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
  76. in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
  77. if (in_mad->mad_hdr.method != IB_MGMT_METHOD_GET &&
  78. in_mad->mad_hdr.method != IB_MGMT_METHOD_SET &&
  79. in_mad->mad_hdr.method != IB_MGMT_METHOD_TRAP_REPRESS)
  80. return IB_MAD_RESULT_SUCCESS;
  81. /* Don't process SMInfo queries -- the SMA can't handle them.
  82. */
  83. if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_SM_INFO)
  84. return IB_MAD_RESULT_SUCCESS;
  85. } else if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT ||
  86. in_mad->mad_hdr.mgmt_class == MLX5_IB_VENDOR_CLASS1 ||
  87. in_mad->mad_hdr.mgmt_class == MLX5_IB_VENDOR_CLASS2 ||
  88. in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_CONG_MGMT) {
  89. if (in_mad->mad_hdr.method != IB_MGMT_METHOD_GET &&
  90. in_mad->mad_hdr.method != IB_MGMT_METHOD_SET)
  91. return IB_MAD_RESULT_SUCCESS;
  92. } else {
  93. return IB_MAD_RESULT_SUCCESS;
  94. }
  95. err = mlx5_MAD_IFC(to_mdev(ibdev),
  96. mad_flags & IB_MAD_IGNORE_MKEY,
  97. mad_flags & IB_MAD_IGNORE_BKEY,
  98. port_num, in_wc, in_grh, in_mad, out_mad);
  99. if (err)
  100. return IB_MAD_RESULT_FAILURE;
  101. /* set return bit in status of directed route responses */
  102. if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  103. out_mad->mad_hdr.status |= cpu_to_be16(1 << 15);
  104. if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS)
  105. /* no response for trap repress */
  106. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  107. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  108. }
  109. static void pma_cnt_ext_assign(struct ib_pma_portcounters_ext *pma_cnt_ext,
  110. void *out)
  111. {
  112. #define MLX5_SUM_CNT(p, cntr1, cntr2) \
  113. (MLX5_GET64(query_vport_counter_out, p, cntr1) + \
  114. MLX5_GET64(query_vport_counter_out, p, cntr2))
  115. pma_cnt_ext->port_xmit_data =
  116. cpu_to_be64(MLX5_SUM_CNT(out, transmitted_ib_unicast.octets,
  117. transmitted_ib_multicast.octets) >> 2);
  118. pma_cnt_ext->port_rcv_data =
  119. cpu_to_be64(MLX5_SUM_CNT(out, received_ib_unicast.octets,
  120. received_ib_multicast.octets) >> 2);
  121. pma_cnt_ext->port_xmit_packets =
  122. cpu_to_be64(MLX5_SUM_CNT(out, transmitted_ib_unicast.packets,
  123. transmitted_ib_multicast.packets));
  124. pma_cnt_ext->port_rcv_packets =
  125. cpu_to_be64(MLX5_SUM_CNT(out, received_ib_unicast.packets,
  126. received_ib_multicast.packets));
  127. pma_cnt_ext->port_unicast_xmit_packets =
  128. MLX5_GET64_BE(query_vport_counter_out,
  129. out, transmitted_ib_unicast.packets);
  130. pma_cnt_ext->port_unicast_rcv_packets =
  131. MLX5_GET64_BE(query_vport_counter_out,
  132. out, received_ib_unicast.packets);
  133. pma_cnt_ext->port_multicast_xmit_packets =
  134. MLX5_GET64_BE(query_vport_counter_out,
  135. out, transmitted_ib_multicast.packets);
  136. pma_cnt_ext->port_multicast_rcv_packets =
  137. MLX5_GET64_BE(query_vport_counter_out,
  138. out, received_ib_multicast.packets);
  139. }
  140. static void pma_cnt_assign(struct ib_pma_portcounters *pma_cnt,
  141. void *out)
  142. {
  143. /* Traffic counters will be reported in
  144. * their 64bit form via ib_pma_portcounters_ext by default.
  145. */
  146. void *out_pma = MLX5_ADDR_OF(ppcnt_reg, out,
  147. counter_set);
  148. #define MLX5_ASSIGN_PMA_CNTR(counter_var, counter_name) { \
  149. counter_var = MLX5_GET_BE(typeof(counter_var), \
  150. ib_port_cntrs_grp_data_layout, \
  151. out_pma, counter_name); \
  152. }
  153. MLX5_ASSIGN_PMA_CNTR(pma_cnt->symbol_error_counter,
  154. symbol_error_counter);
  155. MLX5_ASSIGN_PMA_CNTR(pma_cnt->link_error_recovery_counter,
  156. link_error_recovery_counter);
  157. MLX5_ASSIGN_PMA_CNTR(pma_cnt->link_downed_counter,
  158. link_downed_counter);
  159. MLX5_ASSIGN_PMA_CNTR(pma_cnt->port_rcv_errors,
  160. port_rcv_errors);
  161. MLX5_ASSIGN_PMA_CNTR(pma_cnt->port_rcv_remphys_errors,
  162. port_rcv_remote_physical_errors);
  163. MLX5_ASSIGN_PMA_CNTR(pma_cnt->port_rcv_switch_relay_errors,
  164. port_rcv_switch_relay_errors);
  165. MLX5_ASSIGN_PMA_CNTR(pma_cnt->port_xmit_discards,
  166. port_xmit_discards);
  167. MLX5_ASSIGN_PMA_CNTR(pma_cnt->port_xmit_constraint_errors,
  168. port_xmit_constraint_errors);
  169. MLX5_ASSIGN_PMA_CNTR(pma_cnt->port_rcv_constraint_errors,
  170. port_rcv_constraint_errors);
  171. MLX5_ASSIGN_PMA_CNTR(pma_cnt->link_overrun_errors,
  172. link_overrun_errors);
  173. MLX5_ASSIGN_PMA_CNTR(pma_cnt->vl15_dropped,
  174. vl_15_dropped);
  175. }
  176. static int process_pma_cmd(struct ib_device *ibdev, u8 port_num,
  177. const struct ib_mad *in_mad, struct ib_mad *out_mad)
  178. {
  179. struct mlx5_ib_dev *dev = to_mdev(ibdev);
  180. int err;
  181. void *out_cnt;
  182. /* Decalring support of extended counters */
  183. if (in_mad->mad_hdr.attr_id == IB_PMA_CLASS_PORT_INFO) {
  184. struct ib_class_port_info cpi = {};
  185. cpi.capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
  186. memcpy((out_mad->data + 40), &cpi, sizeof(cpi));
  187. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  188. }
  189. if (in_mad->mad_hdr.attr_id == IB_PMA_PORT_COUNTERS_EXT) {
  190. struct ib_pma_portcounters_ext *pma_cnt_ext =
  191. (struct ib_pma_portcounters_ext *)(out_mad->data + 40);
  192. int sz = MLX5_ST_SZ_BYTES(query_vport_counter_out);
  193. out_cnt = mlx5_vzalloc(sz);
  194. if (!out_cnt)
  195. return IB_MAD_RESULT_FAILURE;
  196. err = mlx5_core_query_vport_counter(dev->mdev, 0, 0,
  197. port_num, out_cnt, sz);
  198. if (!err)
  199. pma_cnt_ext_assign(pma_cnt_ext, out_cnt);
  200. } else {
  201. struct ib_pma_portcounters *pma_cnt =
  202. (struct ib_pma_portcounters *)(out_mad->data + 40);
  203. int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
  204. out_cnt = mlx5_vzalloc(sz);
  205. if (!out_cnt)
  206. return IB_MAD_RESULT_FAILURE;
  207. err = mlx5_core_query_ib_ppcnt(dev->mdev, port_num,
  208. out_cnt, sz);
  209. if (!err)
  210. pma_cnt_assign(pma_cnt, out_cnt);
  211. }
  212. kvfree(out_cnt);
  213. if (err)
  214. return IB_MAD_RESULT_FAILURE;
  215. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  216. }
  217. int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  218. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  219. const struct ib_mad_hdr *in, size_t in_mad_size,
  220. struct ib_mad_hdr *out, size_t *out_mad_size,
  221. u16 *out_mad_pkey_index)
  222. {
  223. struct mlx5_ib_dev *dev = to_mdev(ibdev);
  224. struct mlx5_core_dev *mdev = dev->mdev;
  225. const struct ib_mad *in_mad = (const struct ib_mad *)in;
  226. struct ib_mad *out_mad = (struct ib_mad *)out;
  227. if (WARN_ON_ONCE(in_mad_size != sizeof(*in_mad) ||
  228. *out_mad_size != sizeof(*out_mad)))
  229. return IB_MAD_RESULT_FAILURE;
  230. memset(out_mad->data, 0, sizeof(out_mad->data));
  231. if (MLX5_CAP_GEN(mdev, vport_counters) &&
  232. in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT &&
  233. in_mad->mad_hdr.method == IB_MGMT_METHOD_GET) {
  234. return process_pma_cmd(ibdev, port_num, in_mad, out_mad);
  235. } else {
  236. return process_mad(ibdev, mad_flags, port_num, in_wc, in_grh,
  237. in_mad, out_mad);
  238. }
  239. }
  240. int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port)
  241. {
  242. struct ib_smp *in_mad = NULL;
  243. struct ib_smp *out_mad = NULL;
  244. int err = -ENOMEM;
  245. u16 packet_error;
  246. in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
  247. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  248. if (!in_mad || !out_mad)
  249. goto out;
  250. init_query_mad(in_mad);
  251. in_mad->attr_id = MLX5_ATTR_EXTENDED_PORT_INFO;
  252. in_mad->attr_mod = cpu_to_be32(port);
  253. err = mlx5_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
  254. packet_error = be16_to_cpu(out_mad->status);
  255. dev->mdev->port_caps[port - 1].ext_port_cap = (!err && !packet_error) ?
  256. MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO : 0;
  257. out:
  258. kfree(in_mad);
  259. kfree(out_mad);
  260. return err;
  261. }
  262. int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
  263. struct ib_smp *out_mad)
  264. {
  265. struct ib_smp *in_mad = NULL;
  266. int err = -ENOMEM;
  267. in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
  268. if (!in_mad)
  269. return -ENOMEM;
  270. init_query_mad(in_mad);
  271. in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
  272. err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, 1, NULL, NULL, in_mad,
  273. out_mad);
  274. kfree(in_mad);
  275. return err;
  276. }
  277. int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
  278. __be64 *sys_image_guid)
  279. {
  280. struct ib_smp *out_mad = NULL;
  281. int err = -ENOMEM;
  282. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  283. if (!out_mad)
  284. return -ENOMEM;
  285. err = mlx5_query_mad_ifc_smp_attr_node_info(ibdev, out_mad);
  286. if (err)
  287. goto out;
  288. memcpy(sys_image_guid, out_mad->data + 4, 8);
  289. out:
  290. kfree(out_mad);
  291. return err;
  292. }
  293. int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
  294. u16 *max_pkeys)
  295. {
  296. struct ib_smp *out_mad = NULL;
  297. int err = -ENOMEM;
  298. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  299. if (!out_mad)
  300. return -ENOMEM;
  301. err = mlx5_query_mad_ifc_smp_attr_node_info(ibdev, out_mad);
  302. if (err)
  303. goto out;
  304. *max_pkeys = be16_to_cpup((__be16 *)(out_mad->data + 28));
  305. out:
  306. kfree(out_mad);
  307. return err;
  308. }
  309. int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
  310. u32 *vendor_id)
  311. {
  312. struct ib_smp *out_mad = NULL;
  313. int err = -ENOMEM;
  314. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  315. if (!out_mad)
  316. return -ENOMEM;
  317. err = mlx5_query_mad_ifc_smp_attr_node_info(ibdev, out_mad);
  318. if (err)
  319. goto out;
  320. *vendor_id = be32_to_cpup((__be32 *)(out_mad->data + 36)) & 0xffff;
  321. out:
  322. kfree(out_mad);
  323. return err;
  324. }
  325. int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc)
  326. {
  327. struct ib_smp *in_mad = NULL;
  328. struct ib_smp *out_mad = NULL;
  329. int err = -ENOMEM;
  330. in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
  331. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  332. if (!in_mad || !out_mad)
  333. goto out;
  334. init_query_mad(in_mad);
  335. in_mad->attr_id = IB_SMP_ATTR_NODE_DESC;
  336. err = mlx5_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
  337. if (err)
  338. goto out;
  339. memcpy(node_desc, out_mad->data, IB_DEVICE_NODE_DESC_MAX);
  340. out:
  341. kfree(in_mad);
  342. kfree(out_mad);
  343. return err;
  344. }
  345. int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid)
  346. {
  347. struct ib_smp *in_mad = NULL;
  348. struct ib_smp *out_mad = NULL;
  349. int err = -ENOMEM;
  350. in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
  351. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  352. if (!in_mad || !out_mad)
  353. goto out;
  354. init_query_mad(in_mad);
  355. in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
  356. err = mlx5_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
  357. if (err)
  358. goto out;
  359. memcpy(node_guid, out_mad->data + 12, 8);
  360. out:
  361. kfree(in_mad);
  362. kfree(out_mad);
  363. return err;
  364. }
  365. int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
  366. u16 *pkey)
  367. {
  368. struct ib_smp *in_mad = NULL;
  369. struct ib_smp *out_mad = NULL;
  370. int err = -ENOMEM;
  371. in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
  372. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  373. if (!in_mad || !out_mad)
  374. goto out;
  375. init_query_mad(in_mad);
  376. in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE;
  377. in_mad->attr_mod = cpu_to_be32(index / 32);
  378. err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad,
  379. out_mad);
  380. if (err)
  381. goto out;
  382. *pkey = be16_to_cpu(((__be16 *)out_mad->data)[index % 32]);
  383. out:
  384. kfree(in_mad);
  385. kfree(out_mad);
  386. return err;
  387. }
  388. int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
  389. union ib_gid *gid)
  390. {
  391. struct ib_smp *in_mad = NULL;
  392. struct ib_smp *out_mad = NULL;
  393. int err = -ENOMEM;
  394. in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
  395. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  396. if (!in_mad || !out_mad)
  397. goto out;
  398. init_query_mad(in_mad);
  399. in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
  400. in_mad->attr_mod = cpu_to_be32(port);
  401. err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad,
  402. out_mad);
  403. if (err)
  404. goto out;
  405. memcpy(gid->raw, out_mad->data + 8, 8);
  406. init_query_mad(in_mad);
  407. in_mad->attr_id = IB_SMP_ATTR_GUID_INFO;
  408. in_mad->attr_mod = cpu_to_be32(index / 8);
  409. err = mlx5_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad,
  410. out_mad);
  411. if (err)
  412. goto out;
  413. memcpy(gid->raw + 8, out_mad->data + (index % 8) * 8, 8);
  414. out:
  415. kfree(in_mad);
  416. kfree(out_mad);
  417. return err;
  418. }
  419. int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
  420. struct ib_port_attr *props)
  421. {
  422. struct mlx5_ib_dev *dev = to_mdev(ibdev);
  423. struct mlx5_core_dev *mdev = dev->mdev;
  424. struct ib_smp *in_mad = NULL;
  425. struct ib_smp *out_mad = NULL;
  426. int ext_active_speed;
  427. int err = -ENOMEM;
  428. if (port < 1 || port > MLX5_CAP_GEN(mdev, num_ports)) {
  429. mlx5_ib_warn(dev, "invalid port number %d\n", port);
  430. return -EINVAL;
  431. }
  432. in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
  433. out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
  434. if (!in_mad || !out_mad)
  435. goto out;
  436. /* props being zeroed by the caller, avoid zeroing it here */
  437. init_query_mad(in_mad);
  438. in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
  439. in_mad->attr_mod = cpu_to_be32(port);
  440. err = mlx5_MAD_IFC(dev, 1, 1, port, NULL, NULL, in_mad, out_mad);
  441. if (err) {
  442. mlx5_ib_warn(dev, "err %d\n", err);
  443. goto out;
  444. }
  445. props->lid = be16_to_cpup((__be16 *)(out_mad->data + 16));
  446. props->lmc = out_mad->data[34] & 0x7;
  447. props->sm_lid = be16_to_cpup((__be16 *)(out_mad->data + 18));
  448. props->sm_sl = out_mad->data[36] & 0xf;
  449. props->state = out_mad->data[32] & 0xf;
  450. props->phys_state = out_mad->data[33] >> 4;
  451. props->port_cap_flags = be32_to_cpup((__be32 *)(out_mad->data + 20));
  452. props->gid_tbl_len = out_mad->data[50];
  453. props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg);
  454. props->pkey_tbl_len = mdev->port_caps[port - 1].pkey_table_len;
  455. props->bad_pkey_cntr = be16_to_cpup((__be16 *)(out_mad->data + 46));
  456. props->qkey_viol_cntr = be16_to_cpup((__be16 *)(out_mad->data + 48));
  457. props->active_width = out_mad->data[31] & 0xf;
  458. props->active_speed = out_mad->data[35] >> 4;
  459. props->max_mtu = out_mad->data[41] & 0xf;
  460. props->active_mtu = out_mad->data[36] >> 4;
  461. props->subnet_timeout = out_mad->data[51] & 0x1f;
  462. props->max_vl_num = out_mad->data[37] >> 4;
  463. props->init_type_reply = out_mad->data[41] >> 4;
  464. /* Check if extended speeds (EDR/FDR/...) are supported */
  465. if (props->port_cap_flags & IB_PORT_EXTENDED_SPEEDS_SUP) {
  466. ext_active_speed = out_mad->data[62] >> 4;
  467. switch (ext_active_speed) {
  468. case 1:
  469. props->active_speed = 16; /* FDR */
  470. break;
  471. case 2:
  472. props->active_speed = 32; /* EDR */
  473. break;
  474. }
  475. }
  476. /* If reported active speed is QDR, check if is FDR-10 */
  477. if (props->active_speed == 4) {
  478. if (mdev->port_caps[port - 1].ext_port_cap &
  479. MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO) {
  480. init_query_mad(in_mad);
  481. in_mad->attr_id = MLX5_ATTR_EXTENDED_PORT_INFO;
  482. in_mad->attr_mod = cpu_to_be32(port);
  483. err = mlx5_MAD_IFC(dev, 1, 1, port,
  484. NULL, NULL, in_mad, out_mad);
  485. if (err)
  486. goto out;
  487. /* Checking LinkSpeedActive for FDR-10 */
  488. if (out_mad->data[15] & 0x1)
  489. props->active_speed = 8;
  490. }
  491. }
  492. out:
  493. kfree(in_mad);
  494. kfree(out_mad);
  495. return err;
  496. }