Skip to content

Commit bc4e12f

Browse files
ayalevin123Saeed Mahameed
authored andcommitted
net/mlx5: Refactor queries to speed fields in Port Type and Speed register
This patch fascicles queries to speed related fields in Port Type and Speed register (PTYS) into a single API. I addition, this patch refactors functions which serves only Ethernet driver: remove the protocol type as an input parameter, move code from 'core' directory into 'en' directory and add 'eth' prefix to the function's name. The patch also encapsulates functions that are not used outside the Ethernet driver removes redundant include files. Signed-off-by: Aya Levin <ayal@mellanox.com> Reviewed-by: Eran Ben Elisha <eranbe@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
1 parent cd7e418 commit bc4e12f

6 files changed

Lines changed: 91 additions & 142 deletions

File tree

‎drivers/infiniband/hw/mlx5/main.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static int mlx5_query_port_roce(struct ib_device *device, u8 port_num,
393393
struct ib_port_attr *props)
394394
{
395395
struct mlx5_ib_dev *dev = to_mdev(device);
396+
u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {0};
396397
struct mlx5_core_dev *mdev;
397398
struct net_device *ndev, *upper;
398399
enum ib_mtu ndev_ib_mtu;
@@ -416,10 +417,11 @@ static int mlx5_query_port_roce(struct ib_device *device, u8 port_num,
416417
/* Possible bad flows are checked before filling out props so in case
417418
* of an error it will still be zeroed out.
418419
*/
419-
err = mlx5_query_port_eth_proto_oper(mdev, &eth_prot_oper,
420-
mdev_port_num);
420+
err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
421+
mdev_port_num);
421422
if (err)
422423
goto out;
424+
eth_prot_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
423425

424426
props->active_width = IB_WIDTH_4X;
425427
props->active_speed = IB_SPEED_QDR;

‎drivers/net/ethernet/mellanox/mlx5/core/en/port.c‎

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,67 @@ static const u32 mlx5e_link_speed[MLX5E_LINK_MODES_NUMBER] = {
6363
[MLX5E_50GBASE_KR2] = 50000,
6464
};
6565

66+
int mlx5_port_query_eth_proto(struct mlx5_core_dev *dev, u8 port,
67+
struct mlx5e_port_eth_proto *eproto)
68+
{
69+
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
70+
int err;
71+
72+
if (!eproto)
73+
return -EINVAL;
74+
75+
err = mlx5_query_port_ptys(dev, out, sizeof(out), MLX5_PTYS_EN, port);
76+
if (err)
77+
return err;
78+
79+
eproto->cap = MLX5_GET(ptys_reg, out, eth_proto_capability);
80+
eproto->admin = MLX5_GET(ptys_reg, out, eth_proto_admin);
81+
eproto->oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
82+
return 0;
83+
}
84+
85+
void mlx5_port_query_eth_autoneg(struct mlx5_core_dev *dev, u8 *an_status,
86+
u8 *an_disable_cap, u8 *an_disable_admin)
87+
{
88+
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
89+
90+
*an_status = 0;
91+
*an_disable_cap = 0;
92+
*an_disable_admin = 0;
93+
94+
if (mlx5_query_port_ptys(dev, out, sizeof(out), MLX5_PTYS_EN, 1))
95+
return;
96+
97+
*an_status = MLX5_GET(ptys_reg, out, an_status);
98+
*an_disable_cap = MLX5_GET(ptys_reg, out, an_disable_cap);
99+
*an_disable_admin = MLX5_GET(ptys_reg, out, an_disable_admin);
100+
}
101+
102+
int mlx5_port_set_eth_ptys(struct mlx5_core_dev *dev, bool an_disable,
103+
u32 proto_admin)
104+
{
105+
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
106+
u32 in[MLX5_ST_SZ_DW(ptys_reg)];
107+
u8 an_disable_admin;
108+
u8 an_disable_cap;
109+
u8 an_status;
110+
111+
mlx5_port_query_eth_autoneg(dev, &an_status, &an_disable_cap,
112+
&an_disable_admin);
113+
if (!an_disable_cap && an_disable)
114+
return -EPERM;
115+
116+
memset(in, 0, sizeof(in));
117+
118+
MLX5_SET(ptys_reg, in, local_port, 1);
119+
MLX5_SET(ptys_reg, in, an_disable_admin, an_disable);
120+
MLX5_SET(ptys_reg, in, proto_mask, MLX5_PTYS_EN);
121+
MLX5_SET(ptys_reg, in, eth_proto_admin, proto_admin);
122+
123+
return mlx5_core_access_reg(dev, in, sizeof(in), out,
124+
sizeof(out), MLX5_REG_PTYS, 0, 1);
125+
}
126+
66127
u32 mlx5e_port_ptys2speed(u32 eth_proto_oper)
67128
{
68129
unsigned long temp = eth_proto_oper;
@@ -78,16 +139,14 @@ u32 mlx5e_port_ptys2speed(u32 eth_proto_oper)
78139

79140
int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
80141
{
81-
u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {};
82-
u32 eth_proto_oper;
142+
struct mlx5e_port_eth_proto eproto;
83143
int err;
84144

85-
err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, 1);
145+
err = mlx5_port_query_eth_proto(mdev, 1, &eproto);
86146
if (err)
87147
return err;
88148

89-
eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
90-
*speed = mlx5e_port_ptys2speed(eth_proto_oper);
149+
*speed = mlx5e_port_ptys2speed(eproto.oper);
91150
if (!(*speed))
92151
err = -EINVAL;
93152

@@ -96,17 +155,17 @@ int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
96155

97156
int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
98157
{
158+
struct mlx5e_port_eth_proto eproto;
99159
u32 max_speed = 0;
100-
u32 proto_cap;
101160
int err;
102161
int i;
103162

104-
err = mlx5_query_port_proto_cap(mdev, &proto_cap, MLX5_PTYS_EN);
163+
err = mlx5_port_query_eth_proto(mdev, 1, &eproto);
105164
if (err)
106165
return err;
107166

108167
for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i)
109-
if (proto_cap & MLX5E_PROT_MASK(i))
168+
if (eproto.cap & MLX5E_PROT_MASK(i))
110169
max_speed = max(max_speed, mlx5e_link_speed[i]);
111170

112171
*speed = max_speed;

‎drivers/net/ethernet/mellanox/mlx5/core/en/port.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
#include <linux/mlx5/driver.h>
3737
#include "en.h"
3838

39+
struct mlx5e_port_eth_proto {
40+
u32 cap;
41+
u32 admin;
42+
u32 oper;
43+
};
44+
45+
int mlx5_port_query_eth_proto(struct mlx5_core_dev *dev, u8 port,
46+
struct mlx5e_port_eth_proto *eproto);
47+
void mlx5_port_query_eth_autoneg(struct mlx5_core_dev *dev, u8 *an_status,
48+
u8 *an_disable_cap, u8 *an_disable_admin);
49+
int mlx5_port_set_eth_ptys(struct mlx5_core_dev *dev, bool an_disable,
50+
u32 proto_admin);
3951
u32 mlx5e_port_ptys2speed(u32 eth_proto_oper);
4052
int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
4153
int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);

‎drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ int mlx5e_ethtool_set_link_ksettings(struct mlx5e_priv *priv,
882882
const struct ethtool_link_ksettings *link_ksettings)
883883
{
884884
struct mlx5_core_dev *mdev = priv->mdev;
885-
u32 eth_proto_cap, eth_proto_admin;
885+
struct mlx5e_port_eth_proto eproto;
886886
bool an_changes = false;
887887
u8 an_disable_admin;
888888
u8 an_disable_cap;
@@ -898,39 +898,32 @@ int mlx5e_ethtool_set_link_ksettings(struct mlx5e_priv *priv,
898898
mlx5e_ethtool2ptys_adver_link(link_ksettings->link_modes.advertising) :
899899
mlx5e_port_speed2linkmodes(speed);
900900

901-
err = mlx5_query_port_proto_cap(mdev, &eth_proto_cap, MLX5_PTYS_EN);
901+
err = mlx5_port_query_eth_proto(mdev, 1, &eproto);
902902
if (err) {
903-
netdev_err(priv->netdev, "%s: query port eth proto cap failed: %d\n",
903+
netdev_err(priv->netdev, "%s: query port eth proto failed: %d\n",
904904
__func__, err);
905905
goto out;
906906
}
907907

908-
link_modes = link_modes & eth_proto_cap;
908+
link_modes = link_modes & eproto.cap;
909909
if (!link_modes) {
910910
netdev_err(priv->netdev, "%s: Not supported link mode(s) requested",
911911
__func__);
912912
err = -EINVAL;
913913
goto out;
914914
}
915915

916-
err = mlx5_query_port_proto_admin(mdev, &eth_proto_admin, MLX5_PTYS_EN);
917-
if (err) {
918-
netdev_err(priv->netdev, "%s: query port eth proto admin failed: %d\n",
919-
__func__, err);
920-
goto out;
921-
}
922-
923-
mlx5_query_port_autoneg(mdev, MLX5_PTYS_EN, &an_status,
924-
&an_disable_cap, &an_disable_admin);
916+
mlx5_port_query_eth_autoneg(mdev, &an_status, &an_disable_cap,
917+
&an_disable_admin);
925918

926919
an_disable = link_ksettings->base.autoneg == AUTONEG_DISABLE;
927920
an_changes = ((!an_disable && an_disable_admin) ||
928921
(an_disable && !an_disable_admin));
929922

930-
if (!an_changes && link_modes == eth_proto_admin)
923+
if (!an_changes && link_modes == eproto.admin)
931924
goto out;
932925

933-
mlx5_set_port_ptys(mdev, an_disable, link_modes, MLX5_PTYS_EN);
926+
mlx5_port_set_eth_ptys(mdev, an_disable, link_modes);
934927
mlx5_toggle_port_link(mdev);
935928

936929
out:

‎drivers/net/ethernet/mellanox/mlx5/core/port.c‎

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030
* SOFTWARE.
3131
*/
3232

33-
#include <linux/module.h>
34-
#include <linux/mlx5/driver.h>
3533
#include <linux/mlx5/port.h>
36-
#include <linux/mlx5/cmd.h>
3734
#include "mlx5_core.h"
3835

3936
int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
@@ -157,44 +154,6 @@ int mlx5_set_port_beacon(struct mlx5_core_dev *dev, u16 beacon_duration)
157154
sizeof(out), MLX5_REG_MLCR, 0, 1);
158155
}
159156

160-
int mlx5_query_port_proto_cap(struct mlx5_core_dev *dev,
161-
u32 *proto_cap, int proto_mask)
162-
{
163-
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
164-
int err;
165-
166-
err = mlx5_query_port_ptys(dev, out, sizeof(out), proto_mask, 1);
167-
if (err)
168-
return err;
169-
170-
if (proto_mask == MLX5_PTYS_EN)
171-
*proto_cap = MLX5_GET(ptys_reg, out, eth_proto_capability);
172-
else
173-
*proto_cap = MLX5_GET(ptys_reg, out, ib_proto_capability);
174-
175-
return 0;
176-
}
177-
EXPORT_SYMBOL_GPL(mlx5_query_port_proto_cap);
178-
179-
int mlx5_query_port_proto_admin(struct mlx5_core_dev *dev,
180-
u32 *proto_admin, int proto_mask)
181-
{
182-
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
183-
int err;
184-
185-
err = mlx5_query_port_ptys(dev, out, sizeof(out), proto_mask, 1);
186-
if (err)
187-
return err;
188-
189-
if (proto_mask == MLX5_PTYS_EN)
190-
*proto_admin = MLX5_GET(ptys_reg, out, eth_proto_admin);
191-
else
192-
*proto_admin = MLX5_GET(ptys_reg, out, ib_proto_admin);
193-
194-
return 0;
195-
}
196-
EXPORT_SYMBOL_GPL(mlx5_query_port_proto_admin);
197-
198157
int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,
199158
u8 *link_width_oper, u8 local_port)
200159
{
@@ -211,23 +170,6 @@ int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,
211170
}
212171
EXPORT_SYMBOL_GPL(mlx5_query_port_link_width_oper);
213172

214-
int mlx5_query_port_eth_proto_oper(struct mlx5_core_dev *dev,
215-
u32 *proto_oper, u8 local_port)
216-
{
217-
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
218-
int err;
219-
220-
err = mlx5_query_port_ptys(dev, out, sizeof(out), MLX5_PTYS_EN,
221-
local_port);
222-
if (err)
223-
return err;
224-
225-
*proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
226-
227-
return 0;
228-
}
229-
EXPORT_SYMBOL(mlx5_query_port_eth_proto_oper);
230-
231173
int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev,
232174
u8 *proto_oper, u8 local_port)
233175
{
@@ -245,35 +187,6 @@ int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev,
245187
}
246188
EXPORT_SYMBOL(mlx5_query_port_ib_proto_oper);
247189

248-
int mlx5_set_port_ptys(struct mlx5_core_dev *dev, bool an_disable,
249-
u32 proto_admin, int proto_mask)
250-
{
251-
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
252-
u32 in[MLX5_ST_SZ_DW(ptys_reg)];
253-
u8 an_disable_admin;
254-
u8 an_disable_cap;
255-
u8 an_status;
256-
257-
mlx5_query_port_autoneg(dev, proto_mask, &an_status,
258-
&an_disable_cap, &an_disable_admin);
259-
if (!an_disable_cap && an_disable)
260-
return -EPERM;
261-
262-
memset(in, 0, sizeof(in));
263-
264-
MLX5_SET(ptys_reg, in, local_port, 1);
265-
MLX5_SET(ptys_reg, in, an_disable_admin, an_disable);
266-
MLX5_SET(ptys_reg, in, proto_mask, proto_mask);
267-
if (proto_mask == MLX5_PTYS_EN)
268-
MLX5_SET(ptys_reg, in, eth_proto_admin, proto_admin);
269-
else
270-
MLX5_SET(ptys_reg, in, ib_proto_admin, proto_admin);
271-
272-
return mlx5_core_access_reg(dev, in, sizeof(in), out,
273-
sizeof(out), MLX5_REG_PTYS, 0, 1);
274-
}
275-
EXPORT_SYMBOL_GPL(mlx5_set_port_ptys);
276-
277190
/* This function should be used after setting a port register only */
278191
void mlx5_toggle_port_link(struct mlx5_core_dev *dev)
279192
{
@@ -606,25 +519,6 @@ int mlx5_query_port_pfc(struct mlx5_core_dev *dev, u8 *pfc_en_tx, u8 *pfc_en_rx)
606519
}
607520
EXPORT_SYMBOL_GPL(mlx5_query_port_pfc);
608521

609-
void mlx5_query_port_autoneg(struct mlx5_core_dev *dev, int proto_mask,
610-
u8 *an_status,
611-
u8 *an_disable_cap, u8 *an_disable_admin)
612-
{
613-
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
614-
615-
*an_status = 0;
616-
*an_disable_cap = 0;
617-
*an_disable_admin = 0;
618-
619-
if (mlx5_query_port_ptys(dev, out, sizeof(out), proto_mask, 1))
620-
return;
621-
622-
*an_status = MLX5_GET(ptys_reg, out, an_status);
623-
*an_disable_cap = MLX5_GET(ptys_reg, out, an_disable_cap);
624-
*an_disable_admin = MLX5_GET(ptys_reg, out, an_disable_admin);
625-
}
626-
EXPORT_SYMBOL_GPL(mlx5_query_port_autoneg);
627-
628522
int mlx5_max_tc(struct mlx5_core_dev *mdev)
629523
{
630524
u8 num_tc = MLX5_CAP_GEN(mdev, max_tc) ? : 8;

‎include/linux/mlx5/port.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,16 @@ enum mlx5e_connector_type {
110110
int mlx5_set_port_caps(struct mlx5_core_dev *dev, u8 port_num, u32 caps);
111111
int mlx5_query_port_ptys(struct mlx5_core_dev *dev, u32 *ptys,
112112
int ptys_size, int proto_mask, u8 local_port);
113-
int mlx5_query_port_proto_cap(struct mlx5_core_dev *dev,
114-
u32 *proto_cap, int proto_mask);
115-
int mlx5_query_port_proto_admin(struct mlx5_core_dev *dev,
116-
u32 *proto_admin, int proto_mask);
117113
int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,
118114
u8 *link_width_oper, u8 local_port);
119115
int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev,
120116
u8 *proto_oper, u8 local_port);
121-
int mlx5_query_port_eth_proto_oper(struct mlx5_core_dev *dev,
122-
u32 *proto_oper, u8 local_port);
123-
int mlx5_set_port_ptys(struct mlx5_core_dev *dev, bool an_disable,
124-
u32 proto_admin, int proto_mask);
125117
void mlx5_toggle_port_link(struct mlx5_core_dev *dev);
126118
int mlx5_set_port_admin_status(struct mlx5_core_dev *dev,
127119
enum mlx5_port_status status);
128120
int mlx5_query_port_admin_status(struct mlx5_core_dev *dev,
129121
enum mlx5_port_status *status);
130122
int mlx5_set_port_beacon(struct mlx5_core_dev *dev, u16 beacon_duration);
131-
void mlx5_query_port_autoneg(struct mlx5_core_dev *dev, int proto_mask,
132-
u8 *an_status,
133-
u8 *an_disable_cap, u8 *an_disable_admin);
134123

135124
int mlx5_set_port_mtu(struct mlx5_core_dev *dev, u16 mtu, u8 port);
136125
void mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, u16 *max_mtu, u8 port);

0 commit comments

Comments
 (0)