1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
4 * Authors: Leon Romanovsky <leonro@mellanox.com>
10 static const char *path_mig_to_str(uint8_t idx
)
12 static const char *const path_mig_str
[] = { "MIGRATED", "REARM",
15 if (idx
< ARRAY_SIZE(path_mig_str
))
16 return path_mig_str
[idx
];
20 static const char *qp_states_to_str(uint8_t idx
)
22 static const char *const qp_states_str
[] = { "RESET", "INIT", "RTR",
26 if (idx
< ARRAY_SIZE(qp_states_str
))
27 return qp_states_str
[idx
];
31 static void print_rqpn(struct rd
*rd
, uint32_t val
, struct nlattr
**nla_line
)
33 if (!nla_line
[RDMA_NLDEV_ATTR_RES_RQPN
])
37 jsonw_uint_field(rd
->jw
, "rqpn", val
);
39 pr_out("rqpn %u ", val
);
42 static void print_type(struct rd
*rd
, uint32_t val
)
45 jsonw_string_field(rd
->jw
, "type", qp_types_to_str(val
));
47 pr_out("type %s ", qp_types_to_str(val
));
50 static void print_state(struct rd
*rd
, uint32_t val
)
53 jsonw_string_field(rd
->jw
, "state", qp_states_to_str(val
));
55 pr_out("state %s ", qp_states_to_str(val
));
58 static void print_rqpsn(struct rd
*rd
, uint32_t val
, struct nlattr
**nla_line
)
60 if (!nla_line
[RDMA_NLDEV_ATTR_RES_RQ_PSN
])
64 jsonw_uint_field(rd
->jw
, "rq-psn", val
);
66 pr_out("rq-psn %u ", val
);
69 static void print_pathmig(struct rd
*rd
, uint32_t val
, struct nlattr
**nla_line
)
71 if (!nla_line
[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE
])
75 jsonw_string_field(rd
->jw
, "path-mig-state",
76 path_mig_to_str(val
));
78 pr_out("path-mig-state %s ", path_mig_to_str(val
));
81 int res_qp_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
83 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
84 struct nlattr
*nla_table
, *nla_entry
;
89 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
90 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
91 !tb
[RDMA_NLDEV_ATTR_RES_QP
])
94 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
95 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
96 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_QP
];
98 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
99 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
100 uint32_t lqpn
, rqpn
= 0, rq_psn
= 0, sq_psn
;
101 uint8_t type
, state
, path_mig_state
= 0;
102 uint32_t port
= 0, pid
= 0;
107 err
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
108 if (err
!= MNL_CB_OK
)
111 if (!nla_line
[RDMA_NLDEV_ATTR_RES_LQPN
] ||
112 !nla_line
[RDMA_NLDEV_ATTR_RES_SQ_PSN
] ||
113 !nla_line
[RDMA_NLDEV_ATTR_RES_TYPE
] ||
114 !nla_line
[RDMA_NLDEV_ATTR_RES_STATE
] ||
115 (!nla_line
[RDMA_NLDEV_ATTR_RES_PID
] &&
116 !nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])) {
120 if (nla_line
[RDMA_NLDEV_ATTR_PORT_INDEX
])
121 port
= mnl_attr_get_u32(
122 nla_line
[RDMA_NLDEV_ATTR_PORT_INDEX
]);
124 if (port
!= rd
->port_idx
)
127 lqpn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_LQPN
]);
128 if (rd_check_is_filtered(rd
, "lqpn", lqpn
))
131 if (nla_line
[RDMA_NLDEV_ATTR_RES_PDN
])
132 pdn
= mnl_attr_get_u32(
133 nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]);
134 if (rd_check_is_filtered(rd
, "pdn", pdn
))
137 if (nla_line
[RDMA_NLDEV_ATTR_RES_RQPN
]) {
138 rqpn
= mnl_attr_get_u32(
139 nla_line
[RDMA_NLDEV_ATTR_RES_RQPN
]);
140 if (rd_check_is_filtered(rd
, "rqpn", rqpn
))
143 if (rd_check_is_key_exist(rd
, "rqpn"))
147 if (nla_line
[RDMA_NLDEV_ATTR_RES_RQ_PSN
]) {
148 rq_psn
= mnl_attr_get_u32(
149 nla_line
[RDMA_NLDEV_ATTR_RES_RQ_PSN
]);
150 if (rd_check_is_filtered(rd
, "rq-psn", rq_psn
))
153 if (rd_check_is_key_exist(rd
, "rq-psn"))
157 sq_psn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_SQ_PSN
]);
158 if (rd_check_is_filtered(rd
, "sq-psn", sq_psn
))
161 if (nla_line
[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE
]) {
162 path_mig_state
= mnl_attr_get_u8(
163 nla_line
[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE
]);
164 if (rd_check_is_string_filtered(
165 rd
, "path-mig-state",
166 path_mig_to_str(path_mig_state
)))
169 if (rd_check_is_key_exist(rd
, "path-mig-state"))
173 type
= mnl_attr_get_u8(nla_line
[RDMA_NLDEV_ATTR_RES_TYPE
]);
174 if (rd_check_is_string_filtered(rd
, "type",
175 qp_types_to_str(type
)))
178 state
= mnl_attr_get_u8(nla_line
[RDMA_NLDEV_ATTR_RES_STATE
]);
179 if (rd_check_is_string_filtered(rd
, "state",
180 qp_states_to_str(state
)))
183 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
184 pid
= mnl_attr_get_u32(
185 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
186 comm
= get_task_name(pid
);
189 if (rd_check_is_filtered(rd
, "pid", pid
)) {
194 if (nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])
195 /* discard const from mnl_attr_get_str */
196 comm
= (char *)mnl_attr_get_str(
197 nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
]);
200 jsonw_start_array(rd
->jw
);
202 print_link(rd
, idx
, name
, port
, nla_line
);
204 res_print_uint(rd
, "lqpn", lqpn
);
205 if (nla_line
[RDMA_NLDEV_ATTR_RES_PDN
])
206 res_print_uint(rd
, "pdn", pdn
);
207 print_rqpn(rd
, rqpn
, nla_line
);
209 print_type(rd
, type
);
210 print_state(rd
, state
);
212 print_rqpsn(rd
, rq_psn
, nla_line
);
213 res_print_uint(rd
, "sq-psn", sq_psn
);
215 print_pathmig(rd
, path_mig_state
, nla_line
);
216 res_print_uint(rd
, "pid", pid
);
217 print_comm(rd
, comm
, nla_line
);
219 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
222 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);