Skip to content

Commit 980e900

Browse files
Jack Morgensteinrolandd
authored andcommitted
mlx4_core: INIT/CLOSE port logic for IB ports in SR-IOV mode
Normally, INIT_PORT and CLOSE_PORT are invoked when special QP0 transitions to RTR, or transitions to ERR/RESET respectively. In SR-IOV mode, however, the master is also paravirtualized. This in turn requires that we not do INIT_PORT until the entire QP0 path (real QP0 and proxy QP0) is ready to receive. When the real QP0 goes down, we should indicate that the port is not active. Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il> Signed-off-by: Roland Dreier <roland@purestorage.com>
1 parent efcd235 commit 980e900

2 files changed

Lines changed: 92 additions & 17 deletions

File tree

  • drivers/net/ethernet/mellanox/mlx4

‎drivers/net/ethernet/mellanox/mlx4/fw.c‎

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,19 @@ int mlx4_QUERY_HCA(struct mlx4_dev *dev,
13651365
return err;
13661366
}
13671367

1368+
/* for IB-type ports only in SRIOV mode. Checks that both proxy QP0
1369+
* and real QP0 are active, so that the paravirtualized QP0 is ready
1370+
* to operate */
1371+
static int check_qp0_state(struct mlx4_dev *dev, int function, int port)
1372+
{
1373+
struct mlx4_priv *priv = mlx4_priv(dev);
1374+
/* irrelevant if not infiniband */
1375+
if (priv->mfunc.master.qp0_state[port].proxy_qp0_active &&
1376+
priv->mfunc.master.qp0_state[port].qp0_active)
1377+
return 1;
1378+
return 0;
1379+
}
1380+
13681381
int mlx4_INIT_PORT_wrapper(struct mlx4_dev *dev, int slave,
13691382
struct mlx4_vhcr *vhcr,
13701383
struct mlx4_cmd_mailbox *inbox,
@@ -1381,14 +1394,29 @@ int mlx4_INIT_PORT_wrapper(struct mlx4_dev *dev, int slave,
13811394
if (dev->caps.port_mask[port] == MLX4_PORT_TYPE_IB)
13821395
return -ENODEV;
13831396

1384-
/* Enable port only if it was previously disabled */
1385-
if (!priv->mfunc.master.init_port_ref[port]) {
1386-
err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
1387-
MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
1388-
if (err)
1389-
return err;
1397+
if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) {
1398+
/* Enable port only if it was previously disabled */
1399+
if (!priv->mfunc.master.init_port_ref[port]) {
1400+
err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
1401+
MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
1402+
if (err)
1403+
return err;
1404+
}
1405+
priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
1406+
} else {
1407+
if (slave == mlx4_master_func_num(dev)) {
1408+
if (check_qp0_state(dev, slave, port) &&
1409+
!priv->mfunc.master.qp0_state[port].port_active) {
1410+
err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
1411+
MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
1412+
if (err)
1413+
return err;
1414+
priv->mfunc.master.qp0_state[port].port_active = 1;
1415+
priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
1416+
}
1417+
} else
1418+
priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
13901419
}
1391-
priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
13921420
++priv->mfunc.master.init_port_ref[port];
13931421
return 0;
13941422
}
@@ -1463,13 +1491,30 @@ int mlx4_CLOSE_PORT_wrapper(struct mlx4_dev *dev, int slave,
14631491

14641492
if (dev->caps.port_mask[port] == MLX4_PORT_TYPE_IB)
14651493
return -ENODEV;
1466-
if (priv->mfunc.master.init_port_ref[port] == 1) {
1467-
err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT, 1000,
1468-
MLX4_CMD_NATIVE);
1469-
if (err)
1470-
return err;
1494+
1495+
if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) {
1496+
if (priv->mfunc.master.init_port_ref[port] == 1) {
1497+
err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT,
1498+
1000, MLX4_CMD_NATIVE);
1499+
if (err)
1500+
return err;
1501+
}
1502+
priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
1503+
} else {
1504+
/* infiniband port */
1505+
if (slave == mlx4_master_func_num(dev)) {
1506+
if (!priv->mfunc.master.qp0_state[port].qp0_active &&
1507+
priv->mfunc.master.qp0_state[port].port_active) {
1508+
err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT,
1509+
1000, MLX4_CMD_NATIVE);
1510+
if (err)
1511+
return err;
1512+
priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
1513+
priv->mfunc.master.qp0_state[port].port_active = 0;
1514+
}
1515+
} else
1516+
priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
14711517
}
1472-
priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
14731518
--priv->mfunc.master.init_port_ref[port];
14741519
return 0;
14751520
}

‎drivers/net/ethernet/mellanox/mlx4/qp.c‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type)
6767
complete(&qp->free);
6868
}
6969

70-
static int is_qp0(struct mlx4_dev *dev, struct mlx4_qp *qp)
70+
/* used for INIT/CLOSE port logic */
71+
static int is_qp0(struct mlx4_dev *dev, struct mlx4_qp *qp, int *real_qp0, int *proxy_qp0)
7172
{
72-
return qp->qpn >= dev->caps.sqp_start &&
73+
/* qp0 is either the proxy qp0, or the real qp0 */
74+
*proxy_qp0 = qp->qpn >= dev->caps.sqp_start &&
7375
qp->qpn <= dev->caps.sqp_start + 1;
76+
77+
*real_qp0 = mlx4_is_master(dev) &&
78+
qp->qpn >= dev->caps.base_sqpn &&
79+
qp->qpn <= dev->caps.base_sqpn + 1;
80+
81+
return *real_qp0 || *proxy_qp0;
7482
}
7583

7684
static int __mlx4_qp_modify(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
@@ -122,6 +130,8 @@ static int __mlx4_qp_modify(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
122130
struct mlx4_priv *priv = mlx4_priv(dev);
123131
struct mlx4_cmd_mailbox *mailbox;
124132
int ret = 0;
133+
int real_qp0 = 0;
134+
int proxy_qp0 = 0;
125135
u8 port;
126136

127137
if (cur_state >= MLX4_QP_NUM_STATE || new_state >= MLX4_QP_NUM_STATE ||
@@ -133,9 +143,12 @@ static int __mlx4_qp_modify(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
133143
MLX4_CMD_2RST_QP, MLX4_CMD_TIME_CLASS_A, native);
134144
if (mlx4_is_master(dev) && cur_state != MLX4_QP_STATE_ERR &&
135145
cur_state != MLX4_QP_STATE_RST &&
136-
is_qp0(dev, qp)) {
146+
is_qp0(dev, qp, &real_qp0, &proxy_qp0)) {
137147
port = (qp->qpn & 1) + 1;
138-
priv->mfunc.master.qp0_state[port].qp0_active = 0;
148+
if (proxy_qp0)
149+
priv->mfunc.master.qp0_state[port].proxy_qp0_active = 0;
150+
else
151+
priv->mfunc.master.qp0_state[port].qp0_active = 0;
139152
}
140153
return ret;
141154
}
@@ -162,6 +175,23 @@ static int __mlx4_qp_modify(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
162175
new_state == MLX4_QP_STATE_RST ? 2 : 0,
163176
op[cur_state][new_state], MLX4_CMD_TIME_CLASS_C, native);
164177

178+
if (mlx4_is_master(dev) && is_qp0(dev, qp, &real_qp0, &proxy_qp0)) {
179+
port = (qp->qpn & 1) + 1;
180+
if (cur_state != MLX4_QP_STATE_ERR &&
181+
cur_state != MLX4_QP_STATE_RST &&
182+
new_state == MLX4_QP_STATE_ERR) {
183+
if (proxy_qp0)
184+
priv->mfunc.master.qp0_state[port].proxy_qp0_active = 0;
185+
else
186+
priv->mfunc.master.qp0_state[port].qp0_active = 0;
187+
} else if (new_state == MLX4_QP_STATE_RTR) {
188+
if (proxy_qp0)
189+
priv->mfunc.master.qp0_state[port].proxy_qp0_active = 1;
190+
else
191+
priv->mfunc.master.qp0_state[port].qp0_active = 1;
192+
}
193+
}
194+
165195
mlx4_free_cmd_mailbox(dev, mailbox);
166196
return ret;
167197
}

0 commit comments

Comments
 (0)