-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/mlx5e: Move port speed code from en_ethtool.c to en/port.c
Move four below functions from en_ethtool.c to en/port.c. These functions are used by both en_ethtool.c and en_main.c. Future code can use these functions without ethtool link mode dependency. u32 mlx5e_port_ptys2speed(u32 eth_proto_oper); int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed); int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed); u32 mlx5e_port_speed2linkmodes(u32 speed); Delete the speed field from table mlx5e_build_ptys2ethtool_map. This table only keeps the mapping between the mlx5e link mode and ethtool link mode. Add new table mlx5e_link_speed for translation from mlx5e link mode to actual speed. Signed-off-by: Huy Nguyen <huyn@mellanox.com> Reviewed-by: Parav Pandit <parav@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
- Loading branch information
Huy Nguyen
authored and
Saeed Mahameed
committed
May 24, 2018
1 parent
e549f6f
commit 2c81bfd
Showing
8 changed files
with
213 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
subdir-ccflags-y += -I$(src)/.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright (c) 2018, Mellanox Technologies. All rights reserved. | ||
* | ||
* This software is available to you under a choice of one of two | ||
* licenses. You may choose to be licensed under the terms of the GNU | ||
* General Public License (GPL) Version 2, available from the file | ||
* COPYING in the main directory of this source tree, or the | ||
* OpenIB.org BSD license below: | ||
* | ||
* Redistribution and use in source and binary forms, with or | ||
* without modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include "port.h" | ||
|
||
/* speed in units of 1Mb */ | ||
static const u32 mlx5e_link_speed[MLX5E_LINK_MODES_NUMBER] = { | ||
[MLX5E_1000BASE_CX_SGMII] = 1000, | ||
[MLX5E_1000BASE_KX] = 1000, | ||
[MLX5E_10GBASE_CX4] = 10000, | ||
[MLX5E_10GBASE_KX4] = 10000, | ||
[MLX5E_10GBASE_KR] = 10000, | ||
[MLX5E_20GBASE_KR2] = 20000, | ||
[MLX5E_40GBASE_CR4] = 40000, | ||
[MLX5E_40GBASE_KR4] = 40000, | ||
[MLX5E_56GBASE_R4] = 56000, | ||
[MLX5E_10GBASE_CR] = 10000, | ||
[MLX5E_10GBASE_SR] = 10000, | ||
[MLX5E_10GBASE_ER] = 10000, | ||
[MLX5E_40GBASE_SR4] = 40000, | ||
[MLX5E_40GBASE_LR4] = 40000, | ||
[MLX5E_50GBASE_SR2] = 50000, | ||
[MLX5E_100GBASE_CR4] = 100000, | ||
[MLX5E_100GBASE_SR4] = 100000, | ||
[MLX5E_100GBASE_KR4] = 100000, | ||
[MLX5E_100GBASE_LR4] = 100000, | ||
[MLX5E_100BASE_TX] = 100, | ||
[MLX5E_1000BASE_T] = 1000, | ||
[MLX5E_10GBASE_T] = 10000, | ||
[MLX5E_25GBASE_CR] = 25000, | ||
[MLX5E_25GBASE_KR] = 25000, | ||
[MLX5E_25GBASE_SR] = 25000, | ||
[MLX5E_50GBASE_CR2] = 50000, | ||
[MLX5E_50GBASE_KR2] = 50000, | ||
}; | ||
|
||
u32 mlx5e_port_ptys2speed(u32 eth_proto_oper) | ||
{ | ||
unsigned long temp = eth_proto_oper; | ||
u32 speed = 0; | ||
int i; | ||
|
||
i = find_first_bit(&temp, MLX5E_LINK_MODES_NUMBER); | ||
if (i < MLX5E_LINK_MODES_NUMBER) | ||
speed = mlx5e_link_speed[i]; | ||
|
||
return speed; | ||
} | ||
|
||
int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed) | ||
{ | ||
u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {}; | ||
u32 eth_proto_oper; | ||
int err; | ||
|
||
err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, 1); | ||
if (err) | ||
return err; | ||
|
||
eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper); | ||
*speed = mlx5e_port_ptys2speed(eth_proto_oper); | ||
if (!(*speed)) { | ||
mlx5_core_warn(mdev, "cannot get port speed\n"); | ||
err = -EINVAL; | ||
} | ||
|
||
return err; | ||
} | ||
|
||
int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed) | ||
{ | ||
u32 max_speed = 0; | ||
u32 proto_cap; | ||
int err; | ||
int i; | ||
|
||
err = mlx5_query_port_proto_cap(mdev, &proto_cap, MLX5_PTYS_EN); | ||
if (err) | ||
return err; | ||
|
||
for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) | ||
if (proto_cap & MLX5E_PROT_MASK(i)) | ||
max_speed = max(max_speed, mlx5e_link_speed[i]); | ||
|
||
*speed = max_speed; | ||
return 0; | ||
} | ||
|
||
u32 mlx5e_port_speed2linkmodes(u32 speed) | ||
{ | ||
u32 link_modes = 0; | ||
int i; | ||
|
||
for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) { | ||
if (mlx5e_link_speed[i] == speed) | ||
link_modes |= MLX5E_PROT_MASK(i); | ||
} | ||
|
||
return link_modes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2018, Mellanox Technologies. All rights reserved. | ||
* | ||
* This software is available to you under a choice of one of two | ||
* licenses. You may choose to be licensed under the terms of the GNU | ||
* General Public License (GPL) Version 2, available from the file | ||
* COPYING in the main directory of this source tree, or the | ||
* OpenIB.org BSD license below: | ||
* | ||
* Redistribution and use in source and binary forms, with or | ||
* without modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#ifndef __MLX5E_EN_PORT_H | ||
#define __MLX5E_EN_PORT_H | ||
|
||
#include <linux/mlx5/driver.h> | ||
#include "en.h" | ||
|
||
u32 mlx5e_port_ptys2speed(u32 eth_proto_oper); | ||
int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed); | ||
int mlx5e_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed); | ||
u32 mlx5e_port_speed2linkmodes(u32 speed); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.