37 #include <linux/export.h>
51 spin_lock(&qp_table->
lock);
53 qp = __mlx4_qp_lookup(dev, qpn);
57 spin_unlock(&qp_table->
lock);
60 mlx4_dbg(dev,
"Async event for none existent QP %08x\n", qpn);
64 qp->
event(qp, event_type);
71 static int is_master_qp0(
struct mlx4_dev *
dev,
struct mlx4_qp *qp,
int *real_qp0,
int *proxy_qp0)
75 u32 pf_proxy_offset = dev->
phys_caps.base_proxy_sqpn + 8 * mlx4_master_func_num(dev);
76 *proxy_qp0 = qp->
qpn >= pf_proxy_offset && qp->
qpn <= pf_proxy_offset + 1;
81 return *real_qp0 || *proxy_qp0;
88 int sqd_event,
struct mlx4_qp *qp,
int native)
138 !op[cur_state][new_state])
146 is_master_qp0(dev, qp, &real_qp0, &proxy_qp0)) {
147 port = (qp->
qpn & 1) + 1;
149 priv->
mfunc.master.qp0_state[
port].proxy_qp0_active = 0;
151 priv->
mfunc.master.qp0_state[
port].qp0_active = 0;
158 return PTR_ERR(mailbox);
168 memcpy(mailbox->
buf + 8, context,
sizeof *context);
174 qp->
qpn | (!!sqd_event << 31),
178 if (mlx4_is_master(dev) && is_master_qp0(dev, qp, &real_qp0, &proxy_qp0)) {
179 port = (qp->
qpn & 1) + 1;
184 priv->
mfunc.master.qp0_state[
port].proxy_qp0_active = 0;
186 priv->
mfunc.master.qp0_state[
port].qp0_active = 0;
189 priv->
mfunc.master.qp0_state[
port].proxy_qp0_active = 1;
191 priv->
mfunc.master.qp0_state[
port].qp0_active = 1;
203 int sqd_event,
struct mlx4_qp *qp)
205 return __mlx4_qp_modify(dev, mtt, cur_state, new_state, context,
206 optpar, sqd_event, qp, 0);
229 if (mlx4_is_mfunc(dev)) {
230 set_param_l(&in_param, cnt);
231 set_param_h(&in_param, align);
232 err = mlx4_cmd_imm(dev, in_param, &out_param,
239 *base = get_param_l(&out_param);
251 if (mlx4_is_qp_reserved(dev, (
u32) base_qpn))
261 if (mlx4_is_mfunc(dev)) {
262 set_param_l(&in_param, base_qpn);
263 set_param_h(&in_param, cnt);
268 mlx4_warn(dev,
"Failed to release qp range"
269 " base:%d cnt:%d\n", base_qpn, cnt);
320 static int mlx4_qp_alloc_icm(
struct mlx4_dev *dev,
int qpn)
324 if (mlx4_is_mfunc(dev)) {
325 set_param_l(¶m, qpn);
345 static void mlx4_qp_free_icm(
struct mlx4_dev *dev,
int qpn)
349 if (mlx4_is_mfunc(dev)) {
350 set_param_l(&in_param, qpn);
354 mlx4_warn(dev,
"Failed to free icm of qp:%d\n", qpn);
370 err = mlx4_qp_alloc_icm(dev, qpn);
374 spin_lock_irq(&qp_table->
lock);
376 (dev->
caps.num_qps - 1), qp);
377 spin_unlock_irq(&qp_table->
lock);
382 init_completion(&qp->
free);
387 mlx4_qp_free_icm(dev, qpn);
400 spin_unlock_irqrestore(&qp_table->
lock, flags);
410 mlx4_qp_free_icm(dev, qp->
qpn);
414 static int mlx4_CONF_SPECIAL_QP(
struct mlx4_dev *dev,
u32 base_qpn)
424 int reserved_from_top = 0;
429 if (mlx4_is_slave(dev))
446 int last_base = dev->
caps.num_qps;
451 for (i = MLX4_NUM_QP_REGION; i > 0; --
i) {
452 for (j = 2; j <
i; ++
j) {
453 if (dev->
caps.reserved_qps_cnt[sort[j]] >
454 dev->
caps.reserved_qps_cnt[sort[j - 1]]) {
456 sort[
j] = sort[j - 1];
463 last_base -= dev->
caps.reserved_qps_cnt[sort[
i]];
464 dev->
caps.reserved_qps_base[sort[
i]] = last_base;
466 dev->
caps.reserved_qps_cnt[sort[
i]];
483 (1 << 23) - 1, dev->
phys_caps.base_sqpn + 8 +
489 if (mlx4_is_mfunc(dev)) {
501 if (!dev->
caps.qp0_tunnel || !dev->
caps.qp0_proxy ||
502 !dev->
caps.qp1_tunnel || !dev->
caps.qp1_proxy) {
507 for (k = 0; k < dev->
caps.num_ports; k++) {
509 8 * mlx4_master_func_num(dev) +
k;
518 err = mlx4_CONF_SPECIAL_QP(dev, dev->
phys_caps.base_sqpn);
528 dev->
caps.qp0_tunnel = dev->
caps.qp0_proxy =
535 if (mlx4_is_slave(dev))
538 mlx4_CONF_SPECIAL_QP(dev, 0);
550 return PTR_ERR(mailbox);
552 err = mlx4_cmd_box(dev, 0, mailbox->
dma, qp->
qpn, 0,
556 memcpy(context, mailbox->
buf + 8,
sizeof *context);
576 for (i = 0; i <
ARRAY_SIZE(states) - 1; i++) {
582 mlx4_err(dev,
"Failed to bring QP to state: "
583 "%d with error: %d\n",
588 *qp_state = states[i + 1];