main.c (b740e76936c14354a9c5676a3eed839ea8472c41) | main.c (095b0927f0ce74f7211b9046f8493dbba26ca930) |
---|---|
1/* 2 * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: --- 46 unchanged lines hidden (view full) --- 55#include <linux/in.h> 56#include <linux/etherdevice.h> 57#include <linux/mlx5/fs.h> 58#include <linux/mlx5/vport.h> 59#include "mlx5_ib.h" 60#include "cmd.h" 61 62#define DRIVER_NAME "mlx5_ib" | 1/* 2 * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: --- 46 unchanged lines hidden (view full) --- 55#include <linux/in.h> 56#include <linux/etherdevice.h> 57#include <linux/mlx5/fs.h> 58#include <linux/mlx5/vport.h> 59#include "mlx5_ib.h" 60#include "cmd.h" 61 62#define DRIVER_NAME "mlx5_ib" |
63#define DRIVER_VERSION "2.2-1" 64#define DRIVER_RELDATE "Feb 2014" | 63#define DRIVER_VERSION "5.0-0" |
65 66MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); 67MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); 68MODULE_LICENSE("Dual BSD/GPL"); 69MODULE_VERSION(DRIVER_VERSION); 70 71static char mlx5_version[] = 72 DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" | 64 65MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); 66MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); 67MODULE_LICENSE("Dual BSD/GPL"); 68MODULE_VERSION(DRIVER_VERSION); 69 70static char mlx5_version[] = 71 DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v" |
73 DRIVER_VERSION " (" DRIVER_RELDATE ")\n"; | 72 DRIVER_VERSION "\n"; |
74 75enum { 76 MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, 77}; 78 79static enum rdma_link_layer 80mlx5_port_type_cap_to_rdma_ll(int port_type_cap) 81{ --- 137 unchanged lines hidden (view full) --- 219 break; 220 default: 221 return -EINVAL; 222 } 223 224 return 0; 225} 226 | 73 74enum { 75 MLX5_ATOMIC_SIZE_QP_8BYTES = 1 << 3, 76}; 77 78static enum rdma_link_layer 79mlx5_port_type_cap_to_rdma_ll(int port_type_cap) 80{ --- 137 unchanged lines hidden (view full) --- 218 break; 219 default: 220 return -EINVAL; 221 } 222 223 return 0; 224} 225 |
227static void mlx5_query_port_roce(struct ib_device *device, u8 port_num, 228 struct ib_port_attr *props) | 226static int mlx5_query_port_roce(struct ib_device *device, u8 port_num, 227 struct ib_port_attr *props) |
229{ 230 struct mlx5_ib_dev *dev = to_mdev(device); 231 struct mlx5_core_dev *mdev = dev->mdev; 232 struct net_device *ndev, *upper; 233 enum ib_mtu ndev_ib_mtu; 234 u16 qkey_viol_cntr; 235 u32 eth_prot_oper; | 228{ 229 struct mlx5_ib_dev *dev = to_mdev(device); 230 struct mlx5_core_dev *mdev = dev->mdev; 231 struct net_device *ndev, *upper; 232 enum ib_mtu ndev_ib_mtu; 233 u16 qkey_viol_cntr; 234 u32 eth_prot_oper; |
235 int err; |
|
236 237 /* Possible bad flows are checked before filling out props so in case 238 * of an error it will still be zeroed out. 239 */ | 236 237 /* Possible bad flows are checked before filling out props so in case 238 * of an error it will still be zeroed out. 239 */ |
240 if (mlx5_query_port_eth_proto_oper(mdev, ð_prot_oper, port_num)) 241 return; | 240 err = mlx5_query_port_eth_proto_oper(mdev, ð_prot_oper, port_num); 241 if (err) 242 return err; |
242 243 translate_eth_proto_oper(eth_prot_oper, &props->active_speed, 244 &props->active_width); 245 246 props->port_cap_flags |= IB_PORT_CM_SUP; 247 props->port_cap_flags |= IB_PORT_IP_BASED_GIDS; 248 249 props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, --- 4 unchanged lines hidden (view full) --- 254 props->state = IB_PORT_DOWN; 255 props->phys_state = 3; 256 257 mlx5_query_nic_vport_qkey_viol_cntr(dev->mdev, &qkey_viol_cntr); 258 props->qkey_viol_cntr = qkey_viol_cntr; 259 260 ndev = mlx5_ib_get_netdev(device, port_num); 261 if (!ndev) | 243 244 translate_eth_proto_oper(eth_prot_oper, &props->active_speed, 245 &props->active_width); 246 247 props->port_cap_flags |= IB_PORT_CM_SUP; 248 props->port_cap_flags |= IB_PORT_IP_BASED_GIDS; 249 250 props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev, --- 4 unchanged lines hidden (view full) --- 255 props->state = IB_PORT_DOWN; 256 props->phys_state = 3; 257 258 mlx5_query_nic_vport_qkey_viol_cntr(dev->mdev, &qkey_viol_cntr); 259 props->qkey_viol_cntr = qkey_viol_cntr; 260 261 ndev = mlx5_ib_get_netdev(device, port_num); 262 if (!ndev) |
262 return; | 263 return 0; |
263 264 if (mlx5_lag_is_active(dev->mdev)) { 265 rcu_read_lock(); 266 upper = netdev_master_upper_dev_get_rcu(ndev); 267 if (upper) { 268 dev_put(ndev); 269 ndev = upper; 270 dev_hold(ndev); --- 6 unchanged lines hidden (view full) --- 277 props->phys_state = 5; 278 } 279 280 ndev_ib_mtu = iboe_get_mtu(ndev->mtu); 281 282 dev_put(ndev); 283 284 props->active_mtu = min(props->max_mtu, ndev_ib_mtu); | 264 265 if (mlx5_lag_is_active(dev->mdev)) { 266 rcu_read_lock(); 267 upper = netdev_master_upper_dev_get_rcu(ndev); 268 if (upper) { 269 dev_put(ndev); 270 ndev = upper; 271 dev_hold(ndev); --- 6 unchanged lines hidden (view full) --- 278 props->phys_state = 5; 279 } 280 281 ndev_ib_mtu = iboe_get_mtu(ndev->mtu); 282 283 dev_put(ndev); 284 285 props->active_mtu = min(props->max_mtu, ndev_ib_mtu); |
286 return 0; |
|
285} 286 | 287} 288 |
287static void ib_gid_to_mlx5_roce_addr(const union ib_gid *gid, 288 const struct ib_gid_attr *attr, 289 void *mlx5_addr) | 289static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, 290 unsigned int index, const union ib_gid *gid, 291 const struct ib_gid_attr *attr) |
290{ | 292{ |
291#define MLX5_SET_RA(p, f, v) MLX5_SET(roce_addr_layout, p, f, v) 292 char *mlx5_addr_l3_addr = MLX5_ADDR_OF(roce_addr_layout, mlx5_addr, 293 source_l3_address); 294 void *mlx5_addr_mac = MLX5_ADDR_OF(roce_addr_layout, mlx5_addr, 295 source_mac_47_32); | 293 enum ib_gid_type gid_type = IB_GID_TYPE_IB; 294 u8 roce_version = 0; 295 u8 roce_l3_type = 0; 296 bool vlan = false; 297 u8 mac[ETH_ALEN]; 298 u16 vlan_id = 0; |
296 | 299 |
297 if (!gid) 298 return; | 300 if (gid) { 301 gid_type = attr->gid_type; 302 ether_addr_copy(mac, attr->ndev->dev_addr); |
299 | 303 |
300 ether_addr_copy(mlx5_addr_mac, attr->ndev->dev_addr); 301 302 if (is_vlan_dev(attr->ndev)) { 303 MLX5_SET_RA(mlx5_addr, vlan_valid, 1); 304 MLX5_SET_RA(mlx5_addr, vlan_id, vlan_dev_vlan_id(attr->ndev)); | 304 if (is_vlan_dev(attr->ndev)) { 305 vlan = true; 306 vlan_id = vlan_dev_vlan_id(attr->ndev); 307 } |
305 } 306 | 308 } 309 |
307 switch (attr->gid_type) { | 310 switch (gid_type) { |
308 case IB_GID_TYPE_IB: | 311 case IB_GID_TYPE_IB: |
309 MLX5_SET_RA(mlx5_addr, roce_version, MLX5_ROCE_VERSION_1); | 312 roce_version = MLX5_ROCE_VERSION_1; |
310 break; 311 case IB_GID_TYPE_ROCE_UDP_ENCAP: | 313 break; 314 case IB_GID_TYPE_ROCE_UDP_ENCAP: |
312 MLX5_SET_RA(mlx5_addr, roce_version, MLX5_ROCE_VERSION_2); | 315 roce_version = MLX5_ROCE_VERSION_2; 316 if (ipv6_addr_v4mapped((void *)gid)) 317 roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4; 318 else 319 roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6; |
313 break; 314 315 default: | 320 break; 321 322 default: |
316 WARN_ON(true); | 323 mlx5_ib_warn(dev, "Unexpected GID type %u\n", gid_type); |
317 } 318 | 324 } 325 |
319 if (attr->gid_type != IB_GID_TYPE_IB) { 320 if (ipv6_addr_v4mapped((void *)gid)) 321 MLX5_SET_RA(mlx5_addr, roce_l3_type, 322 MLX5_ROCE_L3_TYPE_IPV4); 323 else 324 MLX5_SET_RA(mlx5_addr, roce_l3_type, 325 MLX5_ROCE_L3_TYPE_IPV6); 326 } 327 328 if ((attr->gid_type == IB_GID_TYPE_IB) || 329 !ipv6_addr_v4mapped((void *)gid)) 330 memcpy(mlx5_addr_l3_addr, gid, sizeof(*gid)); 331 else 332 memcpy(&mlx5_addr_l3_addr[12], &gid->raw[12], 4); | 326 return mlx5_core_roce_gid_set(dev->mdev, index, roce_version, 327 roce_l3_type, gid->raw, mac, vlan, 328 vlan_id); |
333} 334 | 329} 330 |
335static int set_roce_addr(struct ib_device *device, u8 port_num, 336 unsigned int index, 337 const union ib_gid *gid, 338 const struct ib_gid_attr *attr) 339{ 340 struct mlx5_ib_dev *dev = to_mdev(device); 341 u32 in[MLX5_ST_SZ_DW(set_roce_address_in)] = {0}; 342 u32 out[MLX5_ST_SZ_DW(set_roce_address_out)] = {0}; 343 void *in_addr = MLX5_ADDR_OF(set_roce_address_in, in, roce_address); 344 enum rdma_link_layer ll = mlx5_ib_port_link_layer(device, port_num); 345 346 if (ll != IB_LINK_LAYER_ETHERNET) 347 return -EINVAL; 348 349 ib_gid_to_mlx5_roce_addr(gid, attr, in_addr); 350 351 MLX5_SET(set_roce_address_in, in, roce_address_index, index); 352 MLX5_SET(set_roce_address_in, in, opcode, MLX5_CMD_OP_SET_ROCE_ADDRESS); 353 return mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out)); 354} 355 | |
356static int mlx5_ib_add_gid(struct ib_device *device, u8 port_num, 357 unsigned int index, const union ib_gid *gid, 358 const struct ib_gid_attr *attr, 359 __always_unused void **context) 360{ | 331static int mlx5_ib_add_gid(struct ib_device *device, u8 port_num, 332 unsigned int index, const union ib_gid *gid, 333 const struct ib_gid_attr *attr, 334 __always_unused void **context) 335{ |
361 return set_roce_addr(device, port_num, index, gid, attr); | 336 return set_roce_addr(to_mdev(device), port_num, index, gid, attr); |
362} 363 364static int mlx5_ib_del_gid(struct ib_device *device, u8 port_num, 365 unsigned int index, __always_unused void **context) 366{ | 337} 338 339static int mlx5_ib_del_gid(struct ib_device *device, u8 port_num, 340 unsigned int index, __always_unused void **context) 341{ |
367 return set_roce_addr(device, port_num, index, NULL, NULL); | 342 return set_roce_addr(to_mdev(device), port_num, index, NULL, NULL); |
368} 369 370__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num, 371 int index) 372{ 373 struct ib_gid_attr attr; 374 union ib_gid gid; 375 --- 59 unchanged lines hidden (view full) --- 435 436static void get_atomic_caps(struct mlx5_ib_dev *dev, 437 struct ib_device_attr *props) 438{ 439 u8 tmp; 440 u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); 441 u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); 442 u8 atomic_req_8B_endianness_mode = | 343} 344 345__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num, 346 int index) 347{ 348 struct ib_gid_attr attr; 349 union ib_gid gid; 350 --- 59 unchanged lines hidden (view full) --- 410 411static void get_atomic_caps(struct mlx5_ib_dev *dev, 412 struct ib_device_attr *props) 413{ 414 u8 tmp; 415 u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); 416 u8 atomic_size_qp = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); 417 u8 atomic_req_8B_endianness_mode = |
443 MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianess_mode); | 418 MLX5_CAP_ATOMIC(dev->mdev, atomic_req_8B_endianness_mode); |
444 445 /* Check if HW supports 8 bytes standard atomic operations and capable 446 * of host endianness respond 447 */ 448 tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; 449 if (((atomic_operations & tmp) == tmp) && 450 (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && 451 (atomic_req_8B_endianness_mode)) { --- 522 unchanged lines hidden (view full) --- 974out: 975 kfree(rep); 976 return err; 977} 978 979int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, 980 struct ib_port_attr *props) 981{ | 419 420 /* Check if HW supports 8 bytes standard atomic operations and capable 421 * of host endianness respond 422 */ 423 tmp = MLX5_ATOMIC_OPS_CMP_SWAP | MLX5_ATOMIC_OPS_FETCH_ADD; 424 if (((atomic_operations & tmp) == tmp) && 425 (atomic_size_qp & MLX5_ATOMIC_SIZE_QP_8BYTES) && 426 (atomic_req_8B_endianness_mode)) { --- 522 unchanged lines hidden (view full) --- 949out: 950 kfree(rep); 951 return err; 952} 953 954int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, 955 struct ib_port_attr *props) 956{ |
957 unsigned int count; 958 int ret; 959 |
|
982 switch (mlx5_get_vport_access_method(ibdev)) { 983 case MLX5_VPORT_ACCESS_METHOD_MAD: | 960 switch (mlx5_get_vport_access_method(ibdev)) { 961 case MLX5_VPORT_ACCESS_METHOD_MAD: |
984 return mlx5_query_mad_ifc_port(ibdev, port, props); | 962 ret = mlx5_query_mad_ifc_port(ibdev, port, props); 963 break; |
985 986 case MLX5_VPORT_ACCESS_METHOD_HCA: | 964 965 case MLX5_VPORT_ACCESS_METHOD_HCA: |
987 return mlx5_query_hca_port(ibdev, port, props); | 966 ret = mlx5_query_hca_port(ibdev, port, props); 967 break; |
988 989 case MLX5_VPORT_ACCESS_METHOD_NIC: | 968 969 case MLX5_VPORT_ACCESS_METHOD_NIC: |
990 mlx5_query_port_roce(ibdev, port, props); 991 return 0; | 970 ret = mlx5_query_port_roce(ibdev, port, props); 971 break; |
992 993 default: | 972 973 default: |
994 return -EINVAL; | 974 ret = -EINVAL; |
995 } | 975 } |
976 977 if (!ret && props) { 978 count = mlx5_core_reserved_gids_count(to_mdev(ibdev)->mdev); 979 props->gid_tbl_len -= count; 980 } 981 return ret; |
|
996} 997 998static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, 999 union ib_gid *gid) 1000{ 1001 struct mlx5_ib_dev *dev = to_mdev(ibdev); 1002 struct mlx5_core_dev *mdev = dev->mdev; 1003 --- 1254 unchanged lines hidden (view full) --- 2258 u32 flow_tag = MLX5_FS_DEFAULT_FLOW_TAG; 2259 bool is_drop = false; 2260 int err = 0; 2261 int dest_num = 1; 2262 2263 if (!is_valid_attr(dev->mdev, flow_attr)) 2264 return ERR_PTR(-EINVAL); 2265 | 982} 983 984static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index, 985 union ib_gid *gid) 986{ 987 struct mlx5_ib_dev *dev = to_mdev(ibdev); 988 struct mlx5_core_dev *mdev = dev->mdev; 989 --- 1254 unchanged lines hidden (view full) --- 2244 u32 flow_tag = MLX5_FS_DEFAULT_FLOW_TAG; 2245 bool is_drop = false; 2246 int err = 0; 2247 int dest_num = 1; 2248 2249 if (!is_valid_attr(dev->mdev, flow_attr)) 2250 return ERR_PTR(-EINVAL); 2251 |
2266 spec = mlx5_vzalloc(sizeof(*spec)); | 2252 spec = kvzalloc(sizeof(*spec), GFP_KERNEL); |
2267 handler = kzalloc(sizeof(*handler), GFP_KERNEL); 2268 if (!handler || !spec) { 2269 err = -ENOMEM; 2270 goto free; 2271 } 2272 2273 INIT_LIST_HEAD(&handler->list); 2274 --- 1188 unchanged lines hidden (view full) --- 3463 struct mlx5_ib_port *port, 3464 struct rdma_hw_stats *stats) 3465{ 3466 int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); 3467 void *out; 3468 __be32 val; 3469 int ret, i; 3470 | 2253 handler = kzalloc(sizeof(*handler), GFP_KERNEL); 2254 if (!handler || !spec) { 2255 err = -ENOMEM; 2256 goto free; 2257 } 2258 2259 INIT_LIST_HEAD(&handler->list); 2260 --- 1188 unchanged lines hidden (view full) --- 3449 struct mlx5_ib_port *port, 3450 struct rdma_hw_stats *stats) 3451{ 3452 int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); 3453 void *out; 3454 __be32 val; 3455 int ret, i; 3456 |
3471 out = mlx5_vzalloc(outlen); | 3457 out = kvzalloc(outlen, GFP_KERNEL); |
3472 if (!out) 3473 return -ENOMEM; 3474 3475 ret = mlx5_core_query_q_counter(dev->mdev, 3476 port->cnts.set_id, 0, 3477 out, outlen); 3478 if (ret) 3479 goto free; --- 12 unchanged lines hidden (view full) --- 3492 struct mlx5_ib_port *port, 3493 struct rdma_hw_stats *stats) 3494{ 3495 int outlen = MLX5_ST_SZ_BYTES(query_cong_statistics_out); 3496 void *out; 3497 int ret, i; 3498 int offset = port->cnts.num_q_counters; 3499 | 3458 if (!out) 3459 return -ENOMEM; 3460 3461 ret = mlx5_core_query_q_counter(dev->mdev, 3462 port->cnts.set_id, 0, 3463 out, outlen); 3464 if (ret) 3465 goto free; --- 12 unchanged lines hidden (view full) --- 3478 struct mlx5_ib_port *port, 3479 struct rdma_hw_stats *stats) 3480{ 3481 int outlen = MLX5_ST_SZ_BYTES(query_cong_statistics_out); 3482 void *out; 3483 int ret, i; 3484 int offset = port->cnts.num_q_counters; 3485 |
3500 out = mlx5_vzalloc(outlen); | 3486 out = kvzalloc(outlen, GFP_KERNEL); |
3501 if (!out) 3502 return -ENOMEM; 3503 3504 ret = mlx5_cmd_query_cong_counter(dev->mdev, false, out, outlen); 3505 if (ret) 3506 goto free; 3507 3508 for (i = 0; i < port->cnts.num_cong_counters; i++) { --- 391 unchanged lines hidden --- | 3487 if (!out) 3488 return -ENOMEM; 3489 3490 ret = mlx5_cmd_query_cong_counter(dev->mdev, false, out, outlen); 3491 if (ret) 3492 goto free; 3493 3494 for (i = 0; i < port->cnts.num_cong_counters; i++) { --- 391 unchanged lines hidden --- |