History

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.

Aya Levin committed 7 years ago

Commit bc4e12f1 parent cd7e4186 files · +91 −142Browse files

Unified · Split

6 files
  1. drivers/infiniband/hw/mlx5/main.c +4 −2
  2. drivers/net/ethernet/mellanox/mlx5/core/en/port.c +67 −8
  3. drivers/net/ethernet/mellanox/mlx5/core/en/port.h +12 −0
  4. drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +8 −15
  5. drivers/net/ethernet/mellanox/mlx5/core/port.c +0 −106
  6. include/linux/mlx5/port.h +0 −11
drivers/infiniband/hw/mlx5/main.c+4−2
@@ -393,6 +393,7 @@ static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, · 392 unmodified lines
393 struct ib_port_attr *props)393 struct ib_port_attr *props)
394{394{
395 struct mlx5_ib_dev *dev = to_mdev(device);395 struct mlx5_ib_dev *dev = to_mdev(device);
396 u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {0};
396 struct mlx5_core_dev *mdev;397 struct mlx5_core_dev *mdev;
397 struct net_device *ndev, *upper;398 struct net_device *ndev, *upper;
398 enum ib_mtu ndev_ib_mtu;399 enum ib_mtu ndev_ib_mtu;
@@ -416,10 +417,11 @@ static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, · 17 unmodified lines
416 /* Possible bad flows are checked before filling out props so in case417 /* Possible bad flows are checked before filling out props so in case
417 * of an error it will still be zeroed out.418 * of an error it will still be zeroed out.
418 */419 */
419 err = mlx5_query_port_eth_proto_oper(mdev, &eth_prot_oper,420 err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
420 mdev_port_num);421 mdev_port_num);
421 if (err)422 if (err)
422 goto out;423 goto out;
424 eth_prot_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
423 425
424 props->active_width = IB_WIDTH_4X;426 props->active_width = IB_WIDTH_4X;
425 props->active_speed = IB_SPEED_QDR;427 props->active_speed = IB_SPEED_QDR;
drivers/net/ethernet/mellanox/mlx5/core/en/port.c+67−8
@@ -63,6 +63,67 @@ static const u32 mlx5e_link_speed[MLX5E_LINK_MODES_NUMBER] = { · 62 unmodified lines
63 [MLX5E_50GBASE_KR2] = 50000,63 [MLX5E_50GBASE_KR2] = 50000,
64};64};
65 65
66int 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
85void 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
102int 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
66u32 mlx5e_port_ptys2speed(u32 eth_proto_oper)127u32 mlx5e_port_ptys2speed(u32 eth_proto_oper)
67{128{
68 unsigned long temp = eth_proto_oper;129 unsigned long temp = eth_proto_oper;
@@ -78,16 +139,14 @@ u32 mlx5e_port_ptys2speed(u32 eth_proto_oper) · 9 unmodified lines
78 139
79int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)140int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
80{141{
81 u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {};142 struct mlx5e_port_eth_proto eproto;
82 u32 eth_proto_oper;
83 int err;143 int err;
84 144
85 err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, 1);145 err = mlx5_port_query_eth_proto(mdev, 1, &eproto);
86 if (err)146 if (err)
87 return err;147 return err;
88 148
89 eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);149 *speed = mlx5e_port_ptys2speed(eproto.oper);
90 *speed = mlx5e_port_ptys2speed(eth_proto_oper);
91 if (!(*speed))150 if (!(*speed))
92 err = -EINVAL;151 err = -EINVAL;
93 152
@@ -96,17 +155,17 @@ int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed) · 2 unmodified lines
96 155
97int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)156int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
98{157{
158 struct mlx5e_port_eth_proto eproto;
99 u32 max_speed = 0;159 u32 max_speed = 0;
100 u32 proto_cap;
101 int err;160 int err;
102 int i;161 int i;
103 162
104 err = mlx5_query_port_proto_cap(mdev, &proto_cap, MLX5_PTYS_EN);163 err = mlx5_port_query_eth_proto(mdev, 1, &eproto);
105 if (err)164 if (err)
106 return err;165 return err;
107 166
108 for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i)167 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))
110 max_speed = max(max_speed, mlx5e_link_speed[i]);169 max_speed = max(max_speed, mlx5e_link_speed[i]);
111 170
112 *speed = max_speed;171 *speed = max_speed;
drivers/net/ethernet/mellanox/mlx5/core/en/port.h+12−0
@@ -36,6 +36,18 @@ · 35 unmodified lines
36#include <linux/mlx5/driver.h>36#include <linux/mlx5/driver.h>
37#include "en.h"37#include "en.h"
38 38
39struct mlx5e_port_eth_proto {
40 u32 cap;
41 u32 admin;
42 u32 oper;
43};
44
45int mlx5_port_query_eth_proto(struct mlx5_core_dev *dev, u8 port,
46 struct mlx5e_port_eth_proto *eproto);
47void mlx5_port_query_eth_autoneg(struct mlx5_core_dev *dev, u8 *an_status,
48 u8 *an_disable_cap, u8 *an_disable_admin);
49int mlx5_port_set_eth_ptys(struct mlx5_core_dev *dev, bool an_disable,
50 u32 proto_admin);
39u32 mlx5e_port_ptys2speed(u32 eth_proto_oper);51u32 mlx5e_port_ptys2speed(u32 eth_proto_oper);
40int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);52int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
41int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);53int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c+8−15
@@ -882,7 +882,7 @@ int mlx5e_ethtool_set_link_ksettings(struct mlx5e_priv *priv, · 881 unmodified lines
882 const struct ethtool_link_ksettings *link_ksettings)882 const struct ethtool_link_ksettings *link_ksettings)
883{883{
884 struct mlx5_core_dev *mdev = priv->mdev;884 struct mlx5_core_dev *mdev = priv->mdev;
885 u32 eth_proto_cap, eth_proto_admin;885 struct mlx5e_port_eth_proto eproto;
886 bool an_changes = false;886 bool an_changes = false;
887 u8 an_disable_admin;887 u8 an_disable_admin;
888 u8 an_disable_cap;888 u8 an_disable_cap;
@@ -898,14 +898,14 @@ int mlx5e_ethtool_set_link_ksettings(struct mlx5e_priv *priv, · 9 unmodified lines
898 mlx5e_ethtool2ptys_adver_link(link_ksettings->link_modes.advertising) :898 mlx5e_ethtool2ptys_adver_link(link_ksettings->link_modes.advertising) :
899 mlx5e_port_speed2linkmodes(speed);899 mlx5e_port_speed2linkmodes(speed);
900 900
901 err = mlx5_query_port_proto_cap(mdev, &eth_proto_cap, MLX5_PTYS_EN);901 err = mlx5_port_query_eth_proto(mdev, 1, &eproto);
902 if (err) {902 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",
904 __func__, err);904 __func__, err);
905 goto out;905 goto out;
906 }906 }
907 907
908 link_modes = link_modes & eth_proto_cap;908 link_modes = link_modes & eproto.cap;
909 if (!link_modes) {909 if (!link_modes) {
910 netdev_err(priv->netdev, "%s: Not supported link mode(s) requested",910 netdev_err(priv->netdev, "%s: Not supported link mode(s) requested",
911 __func__);911 __func__);
@@ -913,24 +913,17 @@ int mlx5e_ethtool_set_link_ksettings(struct mlx5e_priv *priv, · 1 unmodified line
913 goto out;913 goto out;
914 }914 }
915 915
916 err = mlx5_query_port_proto_admin(mdev, &eth_proto_admin, MLX5_PTYS_EN);916 mlx5_port_query_eth_autoneg(mdev, &an_status, &an_disable_cap,
917 if (err) {917 &an_disable_admin);
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);
925 918
926 an_disable = link_ksettings->base.autoneg == AUTONEG_DISABLE;919 an_disable = link_ksettings->base.autoneg == AUTONEG_DISABLE;
927 an_changes = ((!an_disable && an_disable_admin) ||920 an_changes = ((!an_disable && an_disable_admin) ||
928 (an_disable && !an_disable_admin));921 (an_disable && !an_disable_admin));
929 922
930 if (!an_changes && link_modes == eth_proto_admin)923 if (!an_changes && link_modes == eproto.admin)
931 goto out;924 goto out;
932 925
933 mlx5_set_port_ptys(mdev, an_disable, link_modes, MLX5_PTYS_EN);926 mlx5_port_set_eth_ptys(mdev, an_disable, link_modes);
934 mlx5_toggle_port_link(mdev);927 mlx5_toggle_port_link(mdev);
935 928
936out:929out:
drivers/net/ethernet/mellanox/mlx5/core/port.c+0−106
@@ -30,10 +30,7 @@ · 29 unmodified lines
30 * SOFTWARE.30 * SOFTWARE.
31 */31 */
32 32
33#include <linux/module.h>
34#include <linux/mlx5/driver.h>
35#include <linux/mlx5/port.h>33#include <linux/mlx5/port.h>
36#include <linux/mlx5/cmd.h>
37#include "mlx5_core.h"34#include "mlx5_core.h"
38 35
39int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,36int 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) · 117 unmodified lines
157 sizeof(out), MLX5_REG_MLCR, 0, 1);154 sizeof(out), MLX5_REG_MLCR, 0, 1);
158}155}
159 156
160int 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}
177EXPORT_SYMBOL_GPL(mlx5_query_port_proto_cap);
178
179int 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}
196EXPORT_SYMBOL_GPL(mlx5_query_port_proto_admin);
197
198int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,157int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,
199 u8 *link_width_oper, u8 local_port)158 u8 *link_width_oper, u8 local_port)
200{159{
@@ -211,23 +170,6 @@ int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev, · 10 unmodified lines
211}170}
212EXPORT_SYMBOL_GPL(mlx5_query_port_link_width_oper);171EXPORT_SYMBOL_GPL(mlx5_query_port_link_width_oper);
213 172
214int 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}
229EXPORT_SYMBOL(mlx5_query_port_eth_proto_oper);
230
231int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev,173int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev,
232 u8 *proto_oper, u8 local_port)174 u8 *proto_oper, u8 local_port)
233{175{
@@ -245,35 +187,6 @@ int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev, · 11 unmodified lines
245}187}
246EXPORT_SYMBOL(mlx5_query_port_ib_proto_oper);188EXPORT_SYMBOL(mlx5_query_port_ib_proto_oper);
247 189
248int 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}
275EXPORT_SYMBOL_GPL(mlx5_set_port_ptys);
276
277/* This function should be used after setting a port register only */190/* This function should be used after setting a port register only */
278void mlx5_toggle_port_link(struct mlx5_core_dev *dev)191void mlx5_toggle_port_link(struct mlx5_core_dev *dev)
279{192{
@@ -606,25 +519,6 @@ int mlx5_query_port_pfc(struct mlx5_core_dev *dev, u8 *pfc_en_tx, u8 *pfc_en_rx) · 326 unmodified lines
606}519}
607EXPORT_SYMBOL_GPL(mlx5_query_port_pfc);520EXPORT_SYMBOL_GPL(mlx5_query_port_pfc);
608 521
609void 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}
626EXPORT_SYMBOL_GPL(mlx5_query_port_autoneg);
627
628int mlx5_max_tc(struct mlx5_core_dev *mdev)522int mlx5_max_tc(struct mlx5_core_dev *mdev)
629{523{
630 u8 num_tc = MLX5_CAP_GEN(mdev, max_tc) ? : 8;524 u8 num_tc = MLX5_CAP_GEN(mdev, max_tc) ? : 8;
include/linux/mlx5/port.h+0−11
@@ -110,27 +110,16 @@ enum mlx5e_connector_type { · 109 unmodified lines
110int mlx5_set_port_caps(struct mlx5_core_dev *dev, u8 port_num, u32 caps);110int mlx5_set_port_caps(struct mlx5_core_dev *dev, u8 port_num, u32 caps);
111int mlx5_query_port_ptys(struct mlx5_core_dev *dev, u32 *ptys,111int mlx5_query_port_ptys(struct mlx5_core_dev *dev, u32 *ptys,
112 int ptys_size, int proto_mask, u8 local_port);112 int ptys_size, int proto_mask, u8 local_port);
113int mlx5_query_port_proto_cap(struct mlx5_core_dev *dev,
114 u32 *proto_cap, int proto_mask);
115int mlx5_query_port_proto_admin(struct mlx5_core_dev *dev,
116 u32 *proto_admin, int proto_mask);
117int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,113int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,
118 u8 *link_width_oper, u8 local_port);114 u8 *link_width_oper, u8 local_port);
119int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev,115int mlx5_query_port_ib_proto_oper(struct mlx5_core_dev *dev,
120 u8 *proto_oper, u8 local_port);116 u8 *proto_oper, u8 local_port);
121int mlx5_query_port_eth_proto_oper(struct mlx5_core_dev *dev,
122 u32 *proto_oper, u8 local_port);
123int mlx5_set_port_ptys(struct mlx5_core_dev *dev, bool an_disable,
124 u32 proto_admin, int proto_mask);
125void mlx5_toggle_port_link(struct mlx5_core_dev *dev);117void mlx5_toggle_port_link(struct mlx5_core_dev *dev);
126int mlx5_set_port_admin_status(struct mlx5_core_dev *dev,118int mlx5_set_port_admin_status(struct mlx5_core_dev *dev,
127 enum mlx5_port_status status);119 enum mlx5_port_status status);
128int mlx5_query_port_admin_status(struct mlx5_core_dev *dev,120int mlx5_query_port_admin_status(struct mlx5_core_dev *dev,
129 enum mlx5_port_status *status);121 enum mlx5_port_status *status);
130int mlx5_set_port_beacon(struct mlx5_core_dev *dev, u16 beacon_duration);122int mlx5_set_port_beacon(struct mlx5_core_dev *dev, u16 beacon_duration);
131void 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);
134 123
135int mlx5_set_port_mtu(struct mlx5_core_dev *dev, u16 mtu, u8 port);124int mlx5_set_port_mtu(struct mlx5_core_dev *dev, u16 mtu, u8 port);
136void mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, u16 *max_mtu, u8 port);125void mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, u16 *max_mtu, u8 port);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t