Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) | mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num) | ||||
{ | { | ||||
struct mlx5_ib_dev *dev = to_mdev(device); | struct mlx5_ib_dev *dev = to_mdev(device); | ||||
int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); | int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type); | ||||
return mlx5_port_type_cap_to_rdma_ll(port_type_cap); | return mlx5_port_type_cap_to_rdma_ll(port_type_cap); | ||||
} | } | ||||
static bool mlx5_netdev_match(struct net_device *ndev, | static bool mlx5_netdev_match(struct ifnet *ndev, | ||||
struct mlx5_core_dev *mdev, | struct mlx5_core_dev *mdev, | ||||
const char *dname) | const char *dname) | ||||
{ | { | ||||
return ndev->if_type == IFT_ETHER && | return ndev->if_type == IFT_ETHER && | ||||
ndev->if_dname != NULL && | ndev->if_dname != NULL && | ||||
strcmp(ndev->if_dname, dname) == 0 && | strcmp(ndev->if_dname, dname) == 0 && | ||||
ndev->if_softc != NULL && | ndev->if_softc != NULL && | ||||
*(struct mlx5_core_dev **)ndev->if_softc == mdev; | *(struct mlx5_core_dev **)ndev->if_softc == mdev; | ||||
} | } | ||||
static int mlx5_netdev_event(struct notifier_block *this, | static int mlx5_netdev_event(struct notifier_block *this, | ||||
unsigned long event, void *ptr) | unsigned long event, void *ptr) | ||||
{ | { | ||||
struct net_device *ndev = netdev_notifier_info_to_dev(ptr); | struct ifnet *ndev = netdev_notifier_info_to_dev(ptr); | ||||
hselasky: Is the call to netdev_notifier_info_to_dev() still OK? | |||||
Done Inline ActionsGood catch. Yes it is. Though we should leave the explicit netdevice.h include for that. bz: Good catch. Yes it is. Though we should leave the explicit netdevice.h include for that.
I… | |||||
struct mlx5_ib_dev *ibdev = container_of(this, struct mlx5_ib_dev, | struct mlx5_ib_dev *ibdev = container_of(this, struct mlx5_ib_dev, | ||||
roce.nb); | roce.nb); | ||||
switch (event) { | switch (event) { | ||||
case NETDEV_REGISTER: | case NETDEV_REGISTER: | ||||
case NETDEV_UNREGISTER: | case NETDEV_UNREGISTER: | ||||
write_lock(&ibdev->roce.netdev_lock); | write_lock(&ibdev->roce.netdev_lock); | ||||
/* check if network interface belongs to mlx5en */ | /* check if network interface belongs to mlx5en */ | ||||
if (mlx5_netdev_match(ndev, ibdev->mdev, "mce")) | if (mlx5_netdev_match(ndev, ibdev->mdev, "mce")) | ||||
ibdev->roce.netdev = (event == NETDEV_UNREGISTER) ? | ibdev->roce.netdev = (event == NETDEV_UNREGISTER) ? | ||||
NULL : ndev; | NULL : ndev; | ||||
write_unlock(&ibdev->roce.netdev_lock); | write_unlock(&ibdev->roce.netdev_lock); | ||||
break; | break; | ||||
case NETDEV_UP: | case NETDEV_UP: | ||||
case NETDEV_DOWN: { | case NETDEV_DOWN: { | ||||
struct net_device *upper = NULL; | struct ifnet *upper = NULL; | ||||
if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev)) | if ((upper == ndev || (!upper && ndev == ibdev->roce.netdev)) | ||||
&& ibdev->ib_active) { | && ibdev->ib_active) { | ||||
struct ib_event ibev = {0}; | struct ib_event ibev = {0}; | ||||
ibev.device = &ibdev->ib_dev; | ibev.device = &ibdev->ib_dev; | ||||
ibev.event = (event == NETDEV_UP) ? | ibev.event = (event == NETDEV_UP) ? | ||||
IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; | IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR; | ||||
ibev.element.port_num = 1; | ibev.element.port_num = 1; | ||||
ib_dispatch_event(&ibev); | ib_dispatch_event(&ibev); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
return NOTIFY_DONE; | return NOTIFY_DONE; | ||||
} | } | ||||
static struct net_device *mlx5_ib_get_netdev(struct ib_device *device, | static struct ifnet *mlx5_ib_get_netdev(struct ib_device *device, | ||||
u8 port_num) | u8 port_num) | ||||
{ | { | ||||
struct mlx5_ib_dev *ibdev = to_mdev(device); | struct mlx5_ib_dev *ibdev = to_mdev(device); | ||||
struct net_device *ndev; | struct ifnet *ndev; | ||||
/* Ensure ndev does not disappear before we invoke dev_hold() | /* Ensure ndev does not disappear before we invoke if_ref() | ||||
*/ | */ | ||||
read_lock(&ibdev->roce.netdev_lock); | read_lock(&ibdev->roce.netdev_lock); | ||||
ndev = ibdev->roce.netdev; | ndev = ibdev->roce.netdev; | ||||
if (ndev) | if (ndev) | ||||
dev_hold(ndev); | if_ref(ndev); | ||||
read_unlock(&ibdev->roce.netdev_lock); | read_unlock(&ibdev->roce.netdev_lock); | ||||
return ndev; | return ndev; | ||||
} | } | ||||
static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, | static int translate_eth_proto_oper(u32 eth_proto_oper, u8 *active_speed, | ||||
u8 *active_width) | u8 *active_width) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | static int translate_eth_ext_proto_oper(u32 eth_proto_oper, u8 *active_speed, | ||||
return 0; | return 0; | ||||
} | } | ||||
static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, | ||||
struct ib_port_attr *props) | struct ib_port_attr *props) | ||||
{ | { | ||||
struct mlx5_ib_dev *dev = to_mdev(device); | struct mlx5_ib_dev *dev = to_mdev(device); | ||||
u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {}; | u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {}; | ||||
struct net_device *ndev; | struct ifnet *ndev; | ||||
enum ib_mtu ndev_ib_mtu; | enum ib_mtu ndev_ib_mtu; | ||||
u16 qkey_viol_cntr; | u16 qkey_viol_cntr; | ||||
u32 eth_prot_oper; | u32 eth_prot_oper; | ||||
bool ext; | bool ext; | ||||
int err; | int err; | ||||
memset(props, 0, sizeof(*props)); | memset(props, 0, sizeof(*props)); | ||||
Show All 28 Lines | static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, | ||||
mlx5_query_nic_vport_qkey_viol_cntr(dev->mdev, &qkey_viol_cntr); | mlx5_query_nic_vport_qkey_viol_cntr(dev->mdev, &qkey_viol_cntr); | ||||
props->qkey_viol_cntr = qkey_viol_cntr; | props->qkey_viol_cntr = qkey_viol_cntr; | ||||
ndev = mlx5_ib_get_netdev(device, port_num); | ndev = mlx5_ib_get_netdev(device, port_num); | ||||
if (!ndev) | if (!ndev) | ||||
return 0; | return 0; | ||||
if (netif_running(ndev) && netif_carrier_ok(ndev)) { | if (ndev->if_drv_flags & IFF_DRV_RUNNING && | ||||
ndev->if_link_state == LINK_STATE_UP) { | |||||
props->state = IB_PORT_ACTIVE; | props->state = IB_PORT_ACTIVE; | ||||
props->phys_state = 5; | props->phys_state = 5; | ||||
} | } | ||||
ndev_ib_mtu = iboe_get_mtu(ndev->if_mtu); | ndev_ib_mtu = iboe_get_mtu(ndev->if_mtu); | ||||
dev_put(ndev); | if_rele(ndev); | ||||
props->active_mtu = min(props->max_mtu, ndev_ib_mtu); | props->active_mtu = min(props->max_mtu, ndev_ib_mtu); | ||||
return 0; | return 0; | ||||
} | } | ||||
static void ib_gid_to_mlx5_roce_addr(const union ib_gid *gid, | static void ib_gid_to_mlx5_roce_addr(const union ib_gid *gid, | ||||
const struct ib_gid_attr *attr, | const struct ib_gid_attr *attr, | ||||
void *mlx5_addr) | void *mlx5_addr) | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num, | ||||
union ib_gid gid; | union ib_gid gid; | ||||
if (ib_get_cached_gid(&dev->ib_dev, port_num, index, &gid, &attr)) | if (ib_get_cached_gid(&dev->ib_dev, port_num, index, &gid, &attr)) | ||||
return 0; | return 0; | ||||
if (!attr.ndev) | if (!attr.ndev) | ||||
return 0; | return 0; | ||||
dev_put(attr.ndev); | if_rele(attr.ndev); | ||||
if (attr.gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) | if (attr.gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP) | ||||
return 0; | return 0; | ||||
return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); | return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port)); | ||||
} | } | ||||
int mlx5_get_roce_gid_type(struct mlx5_ib_dev *dev, u8 port_num, | int mlx5_get_roce_gid_type(struct mlx5_ib_dev *dev, u8 port_num, | ||||
int index, enum ib_gid_type *gid_type) | int index, enum ib_gid_type *gid_type) | ||||
{ | { | ||||
struct ib_gid_attr attr; | struct ib_gid_attr attr; | ||||
union ib_gid gid; | union ib_gid gid; | ||||
int ret; | int ret; | ||||
ret = ib_get_cached_gid(&dev->ib_dev, port_num, index, &gid, &attr); | ret = ib_get_cached_gid(&dev->ib_dev, port_num, index, &gid, &attr); | ||||
if (ret) | if (ret) | ||||
return ret; | return ret; | ||||
if (!attr.ndev) | if (!attr.ndev) | ||||
return -ENODEV; | return -ENODEV; | ||||
dev_put(attr.ndev); | if_rele(attr.ndev); | ||||
*gid_type = attr.gid_type; | *gid_type = attr.gid_type; | ||||
return 0; | return 0; | ||||
} | } | ||||
static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) | static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 2,584 Lines • ▼ Show 20 Lines | if (dev->roce.nb.notifier_call) { | ||||
unregister_netdevice_notifier(&dev->roce.nb); | unregister_netdevice_notifier(&dev->roce.nb); | ||||
dev->roce.nb.notifier_call = NULL; | dev->roce.nb.notifier_call = NULL; | ||||
} | } | ||||
} | } | ||||
static int mlx5_enable_roce(struct mlx5_ib_dev *dev) | static int mlx5_enable_roce(struct mlx5_ib_dev *dev) | ||||
{ | { | ||||
VNET_ITERATOR_DECL(vnet_iter); | VNET_ITERATOR_DECL(vnet_iter); | ||||
struct net_device *idev; | struct ifnet *idev; | ||||
int err; | int err; | ||||
/* Check if mlx5en net device already exists */ | /* Check if mlx5en net device already exists */ | ||||
VNET_LIST_RLOCK(); | VNET_LIST_RLOCK(); | ||||
VNET_FOREACH(vnet_iter) { | VNET_FOREACH(vnet_iter) { | ||||
IFNET_RLOCK(); | IFNET_RLOCK(); | ||||
CURVNET_SET_QUIET(vnet_iter); | CURVNET_SET_QUIET(vnet_iter); | ||||
CK_STAILQ_FOREACH(idev, &V_ifnet, if_link) { | CK_STAILQ_FOREACH(idev, &V_ifnet, if_link) { | ||||
▲ Show 20 Lines • Show All 512 Lines • Show Last 20 Lines |
Is the call to netdev_notifier_info_to_dev() still OK?