1 /* 2 * Copyright (c) 2007, 2014 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: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and/or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 * 32 */ 33 34 #include <linux/etherdevice.h> 35 #include <linux/delay.h> 36 #include <linux/slab.h> 37 #ifdef CONFIG_NET_RX_BUSY_POLL 38 #include <net/busy_poll.h> 39 #endif 40 41 #include <linux/list.h> 42 #include <linux/if_ether.h> 43 44 #include <dev/mlx4/driver.h> 45 #include <dev/mlx4/device.h> 46 #include <dev/mlx4/cmd.h> 47 #include <dev/mlx4/cq.h> 48 49 #include <sys/sockio.h> 50 #include <sys/sysctl.h> 51 52 #include "en.h" 53 #include "en_port.h" 54 55 static void mlx4_en_sysctl_stat(struct mlx4_en_priv *priv); 56 static void mlx4_en_sysctl_conf(struct mlx4_en_priv *priv); 57 static int mlx4_en_unit; 58 59 #ifdef CONFIG_NET_RX_BUSY_POLL 60 /* must be called with local_bh_disable()d */ 61 static int mlx4_en_low_latency_recv(struct napi_struct *napi) 62 { 63 struct mlx4_en_cq *cq = container_of(napi, struct mlx4_en_cq, napi); 64 struct net_device *dev = cq->dev; 65 struct mlx4_en_priv *priv = netdev_priv(dev); 66 struct mlx4_en_rx_ring *rx_ring = priv->rx_ring[cq->ring]; 67 int done; 68 69 if (!priv->port_up) 70 return LL_FLUSH_FAILED; 71 72 if (!mlx4_en_cq_lock_poll(cq)) 73 return LL_FLUSH_BUSY; 74 75 done = mlx4_en_process_rx_cq(dev, cq, 4); 76 #ifdef LL_EXTENDED_STATS 77 if (done) 78 rx_ring->cleaned += done; 79 else 80 rx_ring->misses++; 81 #endif 82 83 mlx4_en_cq_unlock_poll(cq); 84 85 return done; 86 } 87 #endif /* CONFIG_NET_RX_BUSY_POLL */ 88 89 #ifdef CONFIG_RFS_ACCEL 90 91 struct mlx4_en_filter { 92 struct list_head next; 93 struct work_struct work; 94 95 u8 ip_proto; 96 __be32 src_ip; 97 __be32 dst_ip; 98 __be16 src_port; 99 __be16 dst_port; 100 101 int rxq_index; 102 struct mlx4_en_priv *priv; 103 u32 flow_id; /* RFS infrastructure id */ 104 int id; /* mlx4_en driver id */ 105 u64 reg_id; /* Flow steering API id */ 106 u8 activated; /* Used to prevent expiry before filter 107 * is attached 108 */ 109 struct hlist_node filter_chain; 110 }; 111 112 static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv); 113 114 static enum mlx4_net_trans_rule_id mlx4_ip_proto_to_trans_rule_id(u8 ip_proto) 115 { 116 switch (ip_proto) { 117 case IPPROTO_UDP: 118 return MLX4_NET_TRANS_RULE_ID_UDP; 119 case IPPROTO_TCP: 120 return MLX4_NET_TRANS_RULE_ID_TCP; 121 default: 122 return -EPROTONOSUPPORT; 123 } 124 }; 125 126 static void mlx4_en_filter_work(struct work_struct *work) 127 { 128 struct mlx4_en_filter *filter = container_of(work, 129 struct mlx4_en_filter, 130 work); 131 struct mlx4_en_priv *priv = filter->priv; 132 struct mlx4_spec_list spec_tcp_udp = { 133 .id = mlx4_ip_proto_to_trans_rule_id(filter->ip_proto), 134 { 135 .tcp_udp = { 136 .dst_port = filter->dst_port, 137 .dst_port_msk = (__force __be16)-1, 138 .src_port = filter->src_port, 139 .src_port_msk = (__force __be16)-1, 140 }, 141 }, 142 }; 143 struct mlx4_spec_list spec_ip = { 144 .id = MLX4_NET_TRANS_RULE_ID_IPV4, 145 { 146 .ipv4 = { 147 .dst_ip = filter->dst_ip, 148 .dst_ip_msk = (__force __be32)-1, 149 .src_ip = filter->src_ip, 150 .src_ip_msk = (__force __be32)-1, 151 }, 152 }, 153 }; 154 struct mlx4_spec_list spec_eth = { 155 .id = MLX4_NET_TRANS_RULE_ID_ETH, 156 }; 157 struct mlx4_net_trans_rule rule = { 158 .list = LIST_HEAD_INIT(rule.list), 159 .queue_mode = MLX4_NET_TRANS_Q_LIFO, 160 .exclusive = 1, 161 .allow_loopback = 1, 162 .promisc_mode = MLX4_FS_REGULAR, 163 .port = priv->port, 164 .priority = MLX4_DOMAIN_RFS, 165 }; 166 int rc; 167 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16); 168 169 if (spec_tcp_udp.id < 0) { 170 en_warn(priv, "RFS: ignoring unsupported ip protocol (%d)\n", 171 filter->ip_proto); 172 goto ignore; 173 } 174 list_add_tail(&spec_eth.list, &rule.list); 175 list_add_tail(&spec_ip.list, &rule.list); 176 list_add_tail(&spec_tcp_udp.list, &rule.list); 177 178 rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn; 179 memcpy(spec_eth.eth.dst_mac, priv->dev->dev_addr, ETH_ALEN); 180 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN); 181 182 filter->activated = 0; 183 184 if (filter->reg_id) { 185 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id); 186 if (rc && rc != -ENOENT) 187 en_err(priv, "Error detaching flow. rc = %d\n", rc); 188 } 189 190 rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id); 191 if (rc) 192 en_err(priv, "Error attaching flow. err = %d\n", rc); 193 194 ignore: 195 mlx4_en_filter_rfs_expire(priv); 196 197 filter->activated = 1; 198 } 199 200 static inline struct hlist_head * 201 filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip, 202 __be16 src_port, __be16 dst_port) 203 { 204 unsigned long l; 205 int bucket_idx; 206 207 l = (__force unsigned long)src_port | 208 ((__force unsigned long)dst_port << 2); 209 l ^= (__force unsigned long)(src_ip ^ dst_ip); 210 211 bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT); 212 213 return &priv->filter_hash[bucket_idx]; 214 } 215 216 static struct mlx4_en_filter * 217 mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip, 218 __be32 dst_ip, u8 ip_proto, __be16 src_port, 219 __be16 dst_port, u32 flow_id) 220 { 221 struct mlx4_en_filter *filter = NULL; 222 223 filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC); 224 if (!filter) 225 return NULL; 226 227 filter->priv = priv; 228 filter->rxq_index = rxq_index; 229 INIT_WORK(&filter->work, mlx4_en_filter_work); 230 231 filter->src_ip = src_ip; 232 filter->dst_ip = dst_ip; 233 filter->ip_proto = ip_proto; 234 filter->src_port = src_port; 235 filter->dst_port = dst_port; 236 237 filter->flow_id = flow_id; 238 239 filter->id = priv->last_filter_id++ % RPS_NO_FILTER; 240 241 list_add_tail(&filter->next, &priv->filters); 242 hlist_add_head(&filter->filter_chain, 243 filter_hash_bucket(priv, src_ip, dst_ip, src_port, 244 dst_port)); 245 246 return filter; 247 } 248 249 static void mlx4_en_filter_free(struct mlx4_en_filter *filter) 250 { 251 struct mlx4_en_priv *priv = filter->priv; 252 int rc; 253 254 list_del(&filter->next); 255 256 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id); 257 if (rc && rc != -ENOENT) 258 en_err(priv, "Error detaching flow. rc = %d\n", rc); 259 260 kfree(filter); 261 } 262 263 static inline struct mlx4_en_filter * 264 mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip, 265 u8 ip_proto, __be16 src_port, __be16 dst_port) 266 { 267 struct mlx4_en_filter *filter; 268 struct mlx4_en_filter *ret = NULL; 269 270 hlist_for_each_entry(filter, 271 filter_hash_bucket(priv, src_ip, dst_ip, 272 src_port, dst_port), 273 filter_chain) { 274 if (filter->src_ip == src_ip && 275 filter->dst_ip == dst_ip && 276 filter->ip_proto == ip_proto && 277 filter->src_port == src_port && 278 filter->dst_port == dst_port) { 279 ret = filter; 280 break; 281 } 282 } 283 284 return ret; 285 } 286 287 static int 288 mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb, 289 u16 rxq_index, u32 flow_id) 290 { 291 struct mlx4_en_priv *priv = netdev_priv(net_dev); 292 struct mlx4_en_filter *filter; 293 const struct iphdr *ip; 294 const __be16 *ports; 295 u8 ip_proto; 296 __be32 src_ip; 297 __be32 dst_ip; 298 __be16 src_port; 299 __be16 dst_port; 300 int nhoff = skb_network_offset(skb); 301 int ret = 0; 302 303 if (skb->protocol != htons(ETH_P_IP)) 304 return -EPROTONOSUPPORT; 305 306 ip = (const struct iphdr *)(skb->data + nhoff); 307 if (ip_is_fragment(ip)) 308 return -EPROTONOSUPPORT; 309 310 if ((ip->protocol != IPPROTO_TCP) && (ip->protocol != IPPROTO_UDP)) 311 return -EPROTONOSUPPORT; 312 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl); 313 314 ip_proto = ip->protocol; 315 src_ip = ip->saddr; 316 dst_ip = ip->daddr; 317 src_port = ports[0]; 318 dst_port = ports[1]; 319 320 spin_lock_bh(&priv->filters_lock); 321 filter = mlx4_en_filter_find(priv, src_ip, dst_ip, ip_proto, 322 src_port, dst_port); 323 if (filter) { 324 if (filter->rxq_index == rxq_index) 325 goto out; 326 327 filter->rxq_index = rxq_index; 328 } else { 329 filter = mlx4_en_filter_alloc(priv, rxq_index, 330 src_ip, dst_ip, ip_proto, 331 src_port, dst_port, flow_id); 332 if (!filter) { 333 ret = -ENOMEM; 334 goto err; 335 } 336 } 337 338 queue_work(priv->mdev->workqueue, &filter->work); 339 340 out: 341 ret = filter->id; 342 err: 343 spin_unlock_bh(&priv->filters_lock); 344 345 return ret; 346 } 347 348 void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv, 349 struct mlx4_en_rx_ring *rx_ring) 350 { 351 struct mlx4_en_filter *filter, *tmp; 352 LIST_HEAD(del_list); 353 354 spin_lock_bh(&priv->filters_lock); 355 list_for_each_entry_safe(filter, tmp, &priv->filters, next) { 356 list_move(&filter->next, &del_list); 357 hlist_del(&filter->filter_chain); 358 } 359 spin_unlock_bh(&priv->filters_lock); 360 361 list_for_each_entry_safe(filter, tmp, &del_list, next) { 362 cancel_work_sync(&filter->work); 363 mlx4_en_filter_free(filter); 364 } 365 } 366 367 static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv) 368 { 369 struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL; 370 LIST_HEAD(del_list); 371 int i = 0; 372 373 spin_lock_bh(&priv->filters_lock); 374 list_for_each_entry_safe(filter, tmp, &priv->filters, next) { 375 if (i > MLX4_EN_FILTER_EXPIRY_QUOTA) 376 break; 377 378 if (filter->activated && 379 !work_pending(&filter->work) && 380 rps_may_expire_flow(priv->dev, 381 filter->rxq_index, filter->flow_id, 382 filter->id)) { 383 list_move(&filter->next, &del_list); 384 hlist_del(&filter->filter_chain); 385 } else 386 last_filter = filter; 387 388 i++; 389 } 390 391 if (last_filter && (&last_filter->next != priv->filters.next)) 392 list_move(&priv->filters, &last_filter->next); 393 394 spin_unlock_bh(&priv->filters_lock); 395 396 list_for_each_entry_safe(filter, tmp, &del_list, next) 397 mlx4_en_filter_free(filter); 398 } 399 #endif 400 401 static void mlx4_en_vlan_rx_add_vid(void *arg, struct net_device *dev, u16 vid) 402 { 403 struct mlx4_en_priv *priv = netdev_priv(dev); 404 struct mlx4_en_dev *mdev = priv->mdev; 405 int err; 406 int idx; 407 408 if (arg != priv) 409 return; 410 411 en_dbg(HW, priv, "adding VLAN:%d\n", vid); 412 413 set_bit(vid, priv->active_vlans); 414 415 /* Add VID to port VLAN filter */ 416 mutex_lock(&mdev->state_lock); 417 if (mdev->device_up && priv->port_up) { 418 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); 419 if (err) 420 en_err(priv, "Failed configuring VLAN filter\n"); 421 } 422 if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx)) 423 en_dbg(HW, priv, "failed adding vlan %d\n", vid); 424 mutex_unlock(&mdev->state_lock); 425 426 } 427 428 static void mlx4_en_vlan_rx_kill_vid(void *arg, struct net_device *dev, u16 vid) 429 { 430 struct mlx4_en_priv *priv = netdev_priv(dev); 431 struct mlx4_en_dev *mdev = priv->mdev; 432 int err; 433 434 if (arg != priv) 435 return; 436 437 en_dbg(HW, priv, "Killing VID:%d\n", vid); 438 439 clear_bit(vid, priv->active_vlans); 440 441 /* Remove VID from port VLAN filter */ 442 mutex_lock(&mdev->state_lock); 443 mlx4_unregister_vlan(mdev->dev, priv->port, vid); 444 445 if (mdev->device_up && priv->port_up) { 446 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); 447 if (err) 448 en_err(priv, "Failed configuring VLAN filter\n"); 449 } 450 mutex_unlock(&mdev->state_lock); 451 452 } 453 454 static int mlx4_en_uc_steer_add(struct mlx4_en_priv *priv, 455 unsigned char *mac, int *qpn, u64 *reg_id) 456 { 457 struct mlx4_en_dev *mdev = priv->mdev; 458 struct mlx4_dev *dev = mdev->dev; 459 int err; 460 461 switch (dev->caps.steering_mode) { 462 case MLX4_STEERING_MODE_B0: { 463 struct mlx4_qp qp; 464 u8 gid[16] = {0}; 465 466 qp.qpn = *qpn; 467 memcpy(&gid[10], mac, ETH_ALEN); 468 gid[5] = priv->port; 469 470 err = mlx4_unicast_attach(dev, &qp, gid, 0, MLX4_PROT_ETH); 471 break; 472 } 473 case MLX4_STEERING_MODE_DEVICE_MANAGED: { 474 struct mlx4_spec_list spec_eth = { {NULL} }; 475 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16); 476 477 struct mlx4_net_trans_rule rule = { 478 .queue_mode = MLX4_NET_TRANS_Q_FIFO, 479 .exclusive = 0, 480 .allow_loopback = 1, 481 .promisc_mode = MLX4_FS_REGULAR, 482 .priority = MLX4_DOMAIN_NIC, 483 }; 484 485 rule.port = priv->port; 486 rule.qpn = *qpn; 487 INIT_LIST_HEAD(&rule.list); 488 489 spec_eth.id = MLX4_NET_TRANS_RULE_ID_ETH; 490 memcpy(spec_eth.eth.dst_mac, mac, ETH_ALEN); 491 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN); 492 list_add_tail(&spec_eth.list, &rule.list); 493 494 err = mlx4_flow_attach(dev, &rule, reg_id); 495 break; 496 } 497 default: 498 return -EINVAL; 499 } 500 if (err) 501 en_warn(priv, "Failed Attaching Unicast\n"); 502 503 return err; 504 } 505 506 static void mlx4_en_uc_steer_release(struct mlx4_en_priv *priv, 507 unsigned char *mac, int qpn, u64 reg_id) 508 { 509 struct mlx4_en_dev *mdev = priv->mdev; 510 struct mlx4_dev *dev = mdev->dev; 511 512 switch (dev->caps.steering_mode) { 513 case MLX4_STEERING_MODE_B0: { 514 struct mlx4_qp qp; 515 u8 gid[16] = {0}; 516 517 qp.qpn = qpn; 518 memcpy(&gid[10], mac, ETH_ALEN); 519 gid[5] = priv->port; 520 521 mlx4_unicast_detach(dev, &qp, gid, MLX4_PROT_ETH); 522 break; 523 } 524 case MLX4_STEERING_MODE_DEVICE_MANAGED: { 525 mlx4_flow_detach(dev, reg_id); 526 break; 527 } 528 default: 529 en_err(priv, "Invalid steering mode.\n"); 530 } 531 } 532 533 static int mlx4_en_get_qp(struct mlx4_en_priv *priv) 534 { 535 struct mlx4_en_dev *mdev = priv->mdev; 536 struct mlx4_dev *dev = mdev->dev; 537 struct mlx4_mac_entry *entry; 538 int index = 0; 539 int err = 0; 540 u64 reg_id; 541 int *qpn = &priv->base_qpn; 542 u64 mac = mlx4_mac_to_u64(IF_LLADDR(priv->dev)); 543 544 en_dbg(DRV, priv, "Registering MAC: %pM for adding\n", 545 IF_LLADDR(priv->dev)); 546 index = mlx4_register_mac(dev, priv->port, mac); 547 if (index < 0) { 548 err = index; 549 en_err(priv, "Failed adding MAC: %pM\n", 550 IF_LLADDR(priv->dev)); 551 return err; 552 } 553 554 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) { 555 int base_qpn = mlx4_get_base_qpn(dev, priv->port); 556 *qpn = base_qpn + index; 557 return 0; 558 } 559 560 err = mlx4_qp_reserve_range(dev, 1, 1, qpn, 0); 561 en_dbg(DRV, priv, "Reserved qp %d\n", *qpn); 562 if (err) { 563 en_err(priv, "Failed to reserve qp for mac registration\n"); 564 goto qp_err; 565 } 566 567 err = mlx4_en_uc_steer_add(priv, IF_LLADDR(priv->dev), qpn, ®_id); 568 if (err) 569 goto steer_err; 570 571 entry = kmalloc(sizeof(*entry), GFP_KERNEL); 572 if (!entry) { 573 err = -ENOMEM; 574 goto alloc_err; 575 } 576 memcpy(entry->mac, IF_LLADDR(priv->dev), sizeof(entry->mac)); 577 entry->reg_id = reg_id; 578 579 hlist_add_head(&entry->hlist, 580 &priv->mac_hash[entry->mac[MLX4_EN_MAC_HASH_IDX]]); 581 582 return 0; 583 584 alloc_err: 585 mlx4_en_uc_steer_release(priv, IF_LLADDR(priv->dev), *qpn, reg_id); 586 587 steer_err: 588 mlx4_qp_release_range(dev, *qpn, 1); 589 590 qp_err: 591 mlx4_unregister_mac(dev, priv->port, mac); 592 return err; 593 } 594 595 static void mlx4_en_put_qp(struct mlx4_en_priv *priv) 596 { 597 struct mlx4_en_dev *mdev = priv->mdev; 598 struct mlx4_dev *dev = mdev->dev; 599 int qpn = priv->base_qpn; 600 u64 mac; 601 602 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) { 603 mac = mlx4_mac_to_u64(IF_LLADDR(priv->dev)); 604 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n", 605 IF_LLADDR(priv->dev)); 606 mlx4_unregister_mac(dev, priv->port, mac); 607 } else { 608 struct mlx4_mac_entry *entry; 609 struct hlist_node *tmp; 610 struct hlist_head *bucket; 611 unsigned int i; 612 613 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) { 614 bucket = &priv->mac_hash[i]; 615 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) { 616 mac = mlx4_mac_to_u64(entry->mac); 617 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n", 618 entry->mac); 619 mlx4_en_uc_steer_release(priv, entry->mac, 620 qpn, entry->reg_id); 621 622 mlx4_unregister_mac(dev, priv->port, mac); 623 hlist_del(&entry->hlist); 624 kfree(entry); 625 } 626 } 627 628 en_dbg(DRV, priv, "Releasing qp: port %d, qpn %d\n", 629 priv->port, qpn); 630 mlx4_qp_release_range(dev, qpn, 1); 631 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC; 632 } 633 } 634 635 static void mlx4_en_clear_list(struct net_device *dev) 636 { 637 struct mlx4_en_priv *priv = netdev_priv(dev); 638 struct mlx4_en_mc_list *tmp, *mc_to_del; 639 640 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) { 641 list_del(&mc_to_del->list); 642 kfree(mc_to_del); 643 } 644 } 645 646 static void mlx4_en_cache_mclist(struct net_device *dev) 647 { 648 struct ifmultiaddr *ifma; 649 struct mlx4_en_mc_list *tmp; 650 struct mlx4_en_priv *priv = netdev_priv(dev); 651 652 if_maddr_rlock(dev); 653 TAILQ_FOREACH(ifma, &dev->if_multiaddrs, ifma_link) { 654 if (ifma->ifma_addr->sa_family != AF_LINK) 655 continue; 656 if (((struct sockaddr_dl *)ifma->ifma_addr)->sdl_alen != 657 ETHER_ADDR_LEN) 658 continue; 659 /* Make sure the list didn't grow. */ 660 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC); 661 if (tmp == NULL) { 662 en_err(priv, "Failed to allocate multicast list\n"); 663 break; 664 } 665 memcpy(tmp->addr, 666 LLADDR((struct sockaddr_dl *)ifma->ifma_addr), ETH_ALEN); 667 list_add_tail(&tmp->list, &priv->mc_list); 668 } 669 if_maddr_runlock(dev); 670 } 671 672 static void update_mclist_flags(struct mlx4_en_priv *priv, 673 struct list_head *dst, 674 struct list_head *src) 675 { 676 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc; 677 bool found; 678 679 /* Find all the entries that should be removed from dst, 680 * These are the entries that are not found in src 681 */ 682 list_for_each_entry(dst_tmp, dst, list) { 683 found = false; 684 list_for_each_entry(src_tmp, src, list) { 685 if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) { 686 found = true; 687 break; 688 } 689 } 690 if (!found) 691 dst_tmp->action = MCLIST_REM; 692 } 693 694 /* Add entries that exist in src but not in dst 695 * mark them as need to add 696 */ 697 list_for_each_entry(src_tmp, src, list) { 698 found = false; 699 list_for_each_entry(dst_tmp, dst, list) { 700 if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) { 701 dst_tmp->action = MCLIST_NONE; 702 found = true; 703 break; 704 } 705 } 706 if (!found) { 707 new_mc = kmalloc(sizeof(struct mlx4_en_mc_list), 708 GFP_KERNEL); 709 if (!new_mc) { 710 en_err(priv, "Failed to allocate current multicast list\n"); 711 return; 712 } 713 memcpy(new_mc, src_tmp, 714 sizeof(struct mlx4_en_mc_list)); 715 new_mc->action = MCLIST_ADD; 716 list_add_tail(&new_mc->list, dst); 717 } 718 } 719 } 720 721 static void mlx4_en_set_rx_mode(struct net_device *dev) 722 { 723 struct mlx4_en_priv *priv = netdev_priv(dev); 724 725 if (!priv->port_up) 726 return; 727 728 queue_work(priv->mdev->workqueue, &priv->rx_mode_task); 729 } 730 731 static void mlx4_en_set_promisc_mode(struct mlx4_en_priv *priv, 732 struct mlx4_en_dev *mdev) 733 { 734 int err = 0; 735 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) { 736 priv->flags |= MLX4_EN_FLAG_PROMISC; 737 738 /* Enable promiscouos mode */ 739 switch (mdev->dev->caps.steering_mode) { 740 case MLX4_STEERING_MODE_DEVICE_MANAGED: 741 err = mlx4_flow_steer_promisc_add(mdev->dev, 742 priv->port, 743 priv->base_qpn, 744 MLX4_FS_ALL_DEFAULT); 745 if (err) 746 en_err(priv, "Failed enabling promiscuous mode\n"); 747 priv->flags |= MLX4_EN_FLAG_MC_PROMISC; 748 break; 749 750 case MLX4_STEERING_MODE_B0: 751 err = mlx4_unicast_promisc_add(mdev->dev, 752 priv->base_qpn, 753 priv->port); 754 if (err) 755 en_err(priv, "Failed enabling unicast promiscuous mode\n"); 756 757 /* Add the default qp number as multicast 758 * promisc 759 */ 760 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { 761 err = mlx4_multicast_promisc_add(mdev->dev, 762 priv->base_qpn, 763 priv->port); 764 if (err) 765 en_err(priv, "Failed enabling multicast promiscuous mode\n"); 766 priv->flags |= MLX4_EN_FLAG_MC_PROMISC; 767 } 768 break; 769 770 case MLX4_STEERING_MODE_A0: 771 err = mlx4_SET_PORT_qpn_calc(mdev->dev, 772 priv->port, 773 priv->base_qpn, 774 1); 775 if (err) 776 en_err(priv, "Failed enabling promiscuous mode\n"); 777 break; 778 } 779 780 /* Disable port multicast filter (unconditionally) */ 781 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 782 0, MLX4_MCAST_DISABLE); 783 if (err) 784 en_err(priv, "Failed disabling multicast filter\n"); 785 } 786 } 787 788 static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv *priv, 789 struct mlx4_en_dev *mdev) 790 { 791 int err = 0; 792 793 priv->flags &= ~MLX4_EN_FLAG_PROMISC; 794 795 /* Disable promiscouos mode */ 796 switch (mdev->dev->caps.steering_mode) { 797 case MLX4_STEERING_MODE_DEVICE_MANAGED: 798 err = mlx4_flow_steer_promisc_remove(mdev->dev, 799 priv->port, 800 MLX4_FS_ALL_DEFAULT); 801 if (err) 802 en_err(priv, "Failed disabling promiscuous mode\n"); 803 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; 804 break; 805 806 case MLX4_STEERING_MODE_B0: 807 err = mlx4_unicast_promisc_remove(mdev->dev, 808 priv->base_qpn, 809 priv->port); 810 if (err) 811 en_err(priv, "Failed disabling unicast promiscuous mode\n"); 812 /* Disable Multicast promisc */ 813 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { 814 err = mlx4_multicast_promisc_remove(mdev->dev, 815 priv->base_qpn, 816 priv->port); 817 if (err) 818 en_err(priv, "Failed disabling multicast promiscuous mode\n"); 819 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; 820 } 821 break; 822 823 case MLX4_STEERING_MODE_A0: 824 err = mlx4_SET_PORT_qpn_calc(mdev->dev, 825 priv->port, 826 priv->base_qpn, 0); 827 if (err) 828 en_err(priv, "Failed disabling promiscuous mode\n"); 829 break; 830 } 831 } 832 833 static void mlx4_en_do_multicast(struct mlx4_en_priv *priv, 834 struct net_device *dev, 835 struct mlx4_en_dev *mdev) 836 { 837 struct mlx4_en_mc_list *mclist, *tmp; 838 u8 mc_list[16] = {0}; 839 int err = 0; 840 u64 mcast_addr = 0; 841 842 843 /* Enable/disable the multicast filter according to IFF_ALLMULTI */ 844 if (dev->if_flags & IFF_ALLMULTI) { 845 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 846 0, MLX4_MCAST_DISABLE); 847 if (err) 848 en_err(priv, "Failed disabling multicast filter\n"); 849 850 /* Add the default qp number as multicast promisc */ 851 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { 852 switch (mdev->dev->caps.steering_mode) { 853 case MLX4_STEERING_MODE_DEVICE_MANAGED: 854 err = mlx4_flow_steer_promisc_add(mdev->dev, 855 priv->port, 856 priv->base_qpn, 857 MLX4_FS_MC_DEFAULT); 858 break; 859 860 case MLX4_STEERING_MODE_B0: 861 err = mlx4_multicast_promisc_add(mdev->dev, 862 priv->base_qpn, 863 priv->port); 864 break; 865 866 case MLX4_STEERING_MODE_A0: 867 break; 868 } 869 if (err) 870 en_err(priv, "Failed entering multicast promisc mode\n"); 871 priv->flags |= MLX4_EN_FLAG_MC_PROMISC; 872 } 873 } else { 874 /* Disable Multicast promisc */ 875 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { 876 switch (mdev->dev->caps.steering_mode) { 877 case MLX4_STEERING_MODE_DEVICE_MANAGED: 878 err = mlx4_flow_steer_promisc_remove(mdev->dev, 879 priv->port, 880 MLX4_FS_MC_DEFAULT); 881 break; 882 883 case MLX4_STEERING_MODE_B0: 884 err = mlx4_multicast_promisc_remove(mdev->dev, 885 priv->base_qpn, 886 priv->port); 887 break; 888 889 case MLX4_STEERING_MODE_A0: 890 break; 891 } 892 if (err) 893 en_err(priv, "Failed disabling multicast promiscuous mode\n"); 894 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; 895 } 896 897 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 898 0, MLX4_MCAST_DISABLE); 899 if (err) 900 en_err(priv, "Failed disabling multicast filter\n"); 901 902 /* Flush mcast filter and init it with broadcast address */ 903 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST, 904 1, MLX4_MCAST_CONFIG); 905 906 /* Update multicast list - we cache all addresses so they won't 907 * change while HW is updated holding the command semaphor */ 908 mlx4_en_cache_mclist(dev); 909 list_for_each_entry(mclist, &priv->mc_list, list) { 910 mcast_addr = mlx4_mac_to_u64(mclist->addr); 911 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 912 mcast_addr, 0, MLX4_MCAST_CONFIG); 913 } 914 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 915 0, MLX4_MCAST_ENABLE); 916 if (err) 917 en_err(priv, "Failed enabling multicast filter\n"); 918 919 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list); 920 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { 921 if (mclist->action == MCLIST_REM) { 922 /* detach this address and delete from list */ 923 memcpy(&mc_list[10], mclist->addr, ETH_ALEN); 924 mc_list[5] = priv->port; 925 err = mlx4_multicast_detach(mdev->dev, 926 &priv->rss_map.indir_qp, 927 mc_list, 928 MLX4_PROT_ETH, 929 mclist->reg_id); 930 if (err) 931 en_err(priv, "Fail to detach multicast address\n"); 932 933 /* remove from list */ 934 list_del(&mclist->list); 935 kfree(mclist); 936 } else if (mclist->action == MCLIST_ADD) { 937 /* attach the address */ 938 memcpy(&mc_list[10], mclist->addr, ETH_ALEN); 939 /* needed for B0 steering support */ 940 mc_list[5] = priv->port; 941 err = mlx4_multicast_attach(mdev->dev, 942 &priv->rss_map.indir_qp, 943 mc_list, 944 priv->port, 0, 945 MLX4_PROT_ETH, 946 &mclist->reg_id); 947 if (err) 948 en_err(priv, "Fail to attach multicast address\n"); 949 950 } 951 } 952 } 953 } 954 955 static void mlx4_en_do_set_rx_mode(struct work_struct *work) 956 { 957 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, 958 rx_mode_task); 959 struct mlx4_en_dev *mdev = priv->mdev; 960 struct net_device *dev = priv->dev; 961 962 963 mutex_lock(&mdev->state_lock); 964 if (!mdev->device_up) { 965 en_dbg(HW, priv, "Card is not up, ignoring rx mode change.\n"); 966 goto out; 967 } 968 if (!priv->port_up) { 969 en_dbg(HW, priv, "Port is down, ignoring rx mode change.\n"); 970 goto out; 971 } 972 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) { 973 if (priv->port_state.link_state) { 974 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP; 975 /* update netif baudrate */ 976 priv->dev->if_baudrate = 977 IF_Mbps(priv->port_state.link_speed); 978 /* Important note: the following call for if_link_state_change 979 * is needed for interface up scenario (start port, link state 980 * change) */ 981 if_link_state_change(priv->dev, LINK_STATE_UP); 982 en_dbg(HW, priv, "Link Up\n"); 983 } 984 } 985 986 /* Promsicuous mode: disable all filters */ 987 if ((dev->if_flags & IFF_PROMISC) || 988 (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC)) { 989 mlx4_en_set_promisc_mode(priv, mdev); 990 goto out; 991 } 992 993 /* Not in promiscuous mode */ 994 if (priv->flags & MLX4_EN_FLAG_PROMISC) 995 mlx4_en_clear_promisc_mode(priv, mdev); 996 997 mlx4_en_do_multicast(priv, dev, mdev); 998 out: 999 mutex_unlock(&mdev->state_lock); 1000 } 1001 1002 #ifdef CONFIG_NET_POLL_CONTROLLER 1003 static void mlx4_en_netpoll(struct net_device *dev) 1004 { 1005 struct mlx4_en_priv *priv = netdev_priv(dev); 1006 struct mlx4_en_cq *cq; 1007 unsigned long flags; 1008 int i; 1009 1010 for (i = 0; i < priv->rx_ring_num; i++) { 1011 cq = priv->rx_cq[i]; 1012 spin_lock_irqsave(&cq->lock, flags); 1013 napi_synchronize(&cq->napi); 1014 mlx4_en_process_rx_cq(dev, cq, 0); 1015 spin_unlock_irqrestore(&cq->lock, flags); 1016 } 1017 } 1018 #endif 1019 1020 static void mlx4_en_watchdog_timeout(void *arg) 1021 { 1022 struct mlx4_en_priv *priv = arg; 1023 struct mlx4_en_dev *mdev = priv->mdev; 1024 1025 en_dbg(DRV, priv, "Scheduling watchdog\n"); 1026 queue_work(mdev->workqueue, &priv->watchdog_task); 1027 if (priv->port_up) 1028 callout_reset(&priv->watchdog_timer, MLX4_EN_WATCHDOG_TIMEOUT, 1029 mlx4_en_watchdog_timeout, priv); 1030 } 1031 1032 1033 1034 static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv) 1035 { 1036 struct mlx4_en_cq *cq; 1037 int i; 1038 1039 /* If we haven't received a specific coalescing setting 1040 * (module param), we set the moderation parameters as follows: 1041 * - moder_cnt is set to the number of mtu sized packets to 1042 * satisfy our coelsing target. 1043 * - moder_time is set to a fixed value. 1044 */ 1045 priv->rx_frames = MLX4_EN_RX_COAL_TARGET / priv->dev->if_mtu + 1; 1046 priv->rx_usecs = MLX4_EN_RX_COAL_TIME; 1047 priv->tx_frames = MLX4_EN_TX_COAL_PKTS; 1048 priv->tx_usecs = MLX4_EN_TX_COAL_TIME; 1049 en_dbg(INTR, priv, "Default coalesing params for mtu: %u - " 1050 "rx_frames:%d rx_usecs:%d\n", 1051 (unsigned)priv->dev->if_mtu, priv->rx_frames, priv->rx_usecs); 1052 1053 /* Setup cq moderation params */ 1054 for (i = 0; i < priv->rx_ring_num; i++) { 1055 cq = priv->rx_cq[i]; 1056 cq->moder_cnt = priv->rx_frames; 1057 cq->moder_time = priv->rx_usecs; 1058 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; 1059 priv->last_moder_packets[i] = 0; 1060 priv->last_moder_bytes[i] = 0; 1061 } 1062 1063 for (i = 0; i < priv->tx_ring_num; i++) { 1064 cq = priv->tx_cq[i]; 1065 cq->moder_cnt = priv->tx_frames; 1066 cq->moder_time = priv->tx_usecs; 1067 } 1068 1069 /* Reset auto-moderation params */ 1070 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW; 1071 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW; 1072 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH; 1073 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH; 1074 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL; 1075 priv->adaptive_rx_coal = 1; 1076 priv->last_moder_jiffies = 0; 1077 priv->last_moder_tx_packets = 0; 1078 } 1079 1080 static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv) 1081 { 1082 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies); 1083 struct mlx4_en_cq *cq; 1084 unsigned long packets; 1085 unsigned long rate; 1086 unsigned long avg_pkt_size; 1087 unsigned long rx_packets; 1088 unsigned long rx_bytes; 1089 unsigned long rx_pkt_diff; 1090 int moder_time; 1091 int ring, err; 1092 1093 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ) 1094 return; 1095 1096 for (ring = 0; ring < priv->rx_ring_num; ring++) { 1097 spin_lock(&priv->stats_lock); 1098 rx_packets = priv->rx_ring[ring]->packets; 1099 rx_bytes = priv->rx_ring[ring]->bytes; 1100 spin_unlock(&priv->stats_lock); 1101 1102 rx_pkt_diff = ((unsigned long) (rx_packets - 1103 priv->last_moder_packets[ring])); 1104 packets = rx_pkt_diff; 1105 rate = packets * HZ / period; 1106 avg_pkt_size = packets ? ((unsigned long) (rx_bytes - 1107 priv->last_moder_bytes[ring])) / packets : 0; 1108 1109 /* Apply auto-moderation only when packet rate 1110 * exceeds a rate that it matters */ 1111 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) && 1112 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) { 1113 if (rate < priv->pkt_rate_low) 1114 moder_time = priv->rx_usecs_low; 1115 else if (rate > priv->pkt_rate_high) 1116 moder_time = priv->rx_usecs_high; 1117 else 1118 moder_time = (rate - priv->pkt_rate_low) * 1119 (priv->rx_usecs_high - priv->rx_usecs_low) / 1120 (priv->pkt_rate_high - priv->pkt_rate_low) + 1121 priv->rx_usecs_low; 1122 } else { 1123 moder_time = priv->rx_usecs_low; 1124 } 1125 1126 if (moder_time != priv->last_moder_time[ring]) { 1127 priv->last_moder_time[ring] = moder_time; 1128 cq = priv->rx_cq[ring]; 1129 cq->moder_time = moder_time; 1130 err = mlx4_en_set_cq_moder(priv, cq); 1131 if (err) 1132 en_err(priv, "Failed modifying moderation for cq:%d\n", 1133 ring); 1134 } 1135 priv->last_moder_packets[ring] = rx_packets; 1136 priv->last_moder_bytes[ring] = rx_bytes; 1137 } 1138 1139 priv->last_moder_jiffies = jiffies; 1140 } 1141 1142 static void mlx4_en_do_get_stats(struct work_struct *work) 1143 { 1144 struct delayed_work *delay = to_delayed_work(work); 1145 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, 1146 stats_task); 1147 struct mlx4_en_dev *mdev = priv->mdev; 1148 int err; 1149 1150 mutex_lock(&mdev->state_lock); 1151 if (mdev->device_up) { 1152 if (priv->port_up) { 1153 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0); 1154 if (err) 1155 en_dbg(HW, priv, "Could not update stats\n"); 1156 1157 mlx4_en_auto_moderation(priv); 1158 } 1159 1160 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); 1161 } 1162 mutex_unlock(&mdev->state_lock); 1163 } 1164 1165 /* mlx4_en_service_task - Run service task for tasks that needed to be done 1166 * periodically 1167 */ 1168 static void mlx4_en_service_task(struct work_struct *work) 1169 { 1170 struct delayed_work *delay = to_delayed_work(work); 1171 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, 1172 service_task); 1173 struct mlx4_en_dev *mdev = priv->mdev; 1174 1175 mutex_lock(&mdev->state_lock); 1176 if (mdev->device_up) { 1177 queue_delayed_work(mdev->workqueue, &priv->service_task, 1178 SERVICE_TASK_DELAY); 1179 } 1180 mutex_unlock(&mdev->state_lock); 1181 } 1182 1183 static void mlx4_en_linkstate(struct work_struct *work) 1184 { 1185 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, 1186 linkstate_task); 1187 struct mlx4_en_dev *mdev = priv->mdev; 1188 int linkstate = priv->link_state; 1189 1190 mutex_lock(&mdev->state_lock); 1191 /* If observable port state changed set carrier state and 1192 * report to system log */ 1193 if (priv->last_link_state != linkstate) { 1194 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) { 1195 en_info(priv, "Link Down\n"); 1196 if_link_state_change(priv->dev, LINK_STATE_DOWN); 1197 /* update netif baudrate */ 1198 priv->dev->if_baudrate = 0; 1199 1200 /* make sure the port is up before notifying the OS. 1201 * This is tricky since we get here on INIT_PORT and 1202 * in such case we can't tell the OS the port is up. 1203 * To solve this there is a call to if_link_state_change 1204 * in set_rx_mode. 1205 * */ 1206 } else if (priv->port_up && (linkstate == MLX4_DEV_EVENT_PORT_UP)){ 1207 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port)) 1208 en_info(priv, "Query port failed\n"); 1209 priv->dev->if_baudrate = 1210 IF_Mbps(priv->port_state.link_speed); 1211 en_info(priv, "Link Up\n"); 1212 if_link_state_change(priv->dev, LINK_STATE_UP); 1213 } 1214 } 1215 priv->last_link_state = linkstate; 1216 mutex_unlock(&mdev->state_lock); 1217 } 1218 1219 1220 int mlx4_en_start_port(struct net_device *dev) 1221 { 1222 struct mlx4_en_priv *priv = netdev_priv(dev); 1223 struct mlx4_en_dev *mdev = priv->mdev; 1224 struct mlx4_en_cq *cq; 1225 struct mlx4_en_tx_ring *tx_ring; 1226 int rx_index = 0; 1227 int tx_index = 0; 1228 int err = 0; 1229 int i; 1230 int j; 1231 u8 mc_list[16] = {0}; 1232 1233 1234 if (priv->port_up) { 1235 en_dbg(DRV, priv, "start port called while port already up\n"); 1236 return 0; 1237 } 1238 1239 INIT_LIST_HEAD(&priv->mc_list); 1240 INIT_LIST_HEAD(&priv->curr_list); 1241 INIT_LIST_HEAD(&priv->ethtool_list); 1242 1243 /* Calculate Rx buf size */ 1244 dev->if_mtu = min(dev->if_mtu, priv->max_mtu); 1245 mlx4_en_calc_rx_buf(dev); 1246 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_mb_size); 1247 1248 /* Configure rx cq's and rings */ 1249 err = mlx4_en_activate_rx_rings(priv); 1250 if (err) { 1251 en_err(priv, "Failed to activate RX rings\n"); 1252 return err; 1253 } 1254 for (i = 0; i < priv->rx_ring_num; i++) { 1255 cq = priv->rx_cq[i]; 1256 1257 mlx4_en_cq_init_lock(cq); 1258 err = mlx4_en_activate_cq(priv, cq, i); 1259 if (err) { 1260 en_err(priv, "Failed activating Rx CQ\n"); 1261 goto cq_err; 1262 } 1263 for (j = 0; j < cq->size; j++) 1264 cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK; 1265 err = mlx4_en_set_cq_moder(priv, cq); 1266 if (err) { 1267 en_err(priv, "Failed setting cq moderation parameters"); 1268 mlx4_en_deactivate_cq(priv, cq); 1269 goto cq_err; 1270 } 1271 mlx4_en_arm_cq(priv, cq); 1272 priv->rx_ring[i]->cqn = cq->mcq.cqn; 1273 ++rx_index; 1274 } 1275 1276 /* Set qp number */ 1277 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port); 1278 err = mlx4_en_get_qp(priv); 1279 if (err) { 1280 en_err(priv, "Failed getting eth qp\n"); 1281 goto cq_err; 1282 } 1283 mdev->mac_removed[priv->port] = 0; 1284 1285 /* gets default allocated counter index from func cap */ 1286 /* or sink counter index if no resources */ 1287 priv->counter_index = mdev->dev->caps.def_counter_index[priv->port - 1]; 1288 1289 en_dbg(DRV, priv, "%s: default counter index %d for port %d\n", 1290 __func__, priv->counter_index, priv->port); 1291 1292 err = mlx4_en_config_rss_steer(priv); 1293 if (err) { 1294 en_err(priv, "Failed configuring rss steering\n"); 1295 goto mac_err; 1296 } 1297 1298 err = mlx4_en_create_drop_qp(priv); 1299 if (err) 1300 goto rss_err; 1301 1302 /* Configure tx cq's and rings */ 1303 for (i = 0; i < priv->tx_ring_num; i++) { 1304 /* Configure cq */ 1305 cq = priv->tx_cq[i]; 1306 err = mlx4_en_activate_cq(priv, cq, i); 1307 if (err) { 1308 en_err(priv, "Failed activating Tx CQ\n"); 1309 goto tx_err; 1310 } 1311 err = mlx4_en_set_cq_moder(priv, cq); 1312 if (err) { 1313 en_err(priv, "Failed setting cq moderation parameters"); 1314 mlx4_en_deactivate_cq(priv, cq); 1315 goto tx_err; 1316 } 1317 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i); 1318 cq->buf->wqe_index = cpu_to_be16(0xffff); 1319 1320 /* Configure ring */ 1321 tx_ring = priv->tx_ring[i]; 1322 1323 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn, 1324 i / priv->num_tx_rings_p_up); 1325 if (err) { 1326 en_err(priv, "Failed activating Tx ring %d\n", i); 1327 mlx4_en_deactivate_cq(priv, cq); 1328 goto tx_err; 1329 } 1330 1331 /* Arm CQ for TX completions */ 1332 mlx4_en_arm_cq(priv, cq); 1333 1334 /* Set initial ownership of all Tx TXBBs to SW (1) */ 1335 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE) 1336 *((u32 *) (tx_ring->buf + j)) = 0xffffffff; 1337 ++tx_index; 1338 } 1339 1340 /* Configure port */ 1341 err = mlx4_SET_PORT_general(mdev->dev, priv->port, 1342 priv->rx_mb_size, 1343 priv->prof->tx_pause, 1344 priv->prof->tx_ppp, 1345 priv->prof->rx_pause, 1346 priv->prof->rx_ppp); 1347 if (err) { 1348 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n", 1349 priv->port, err); 1350 goto tx_err; 1351 } 1352 /* Set default qp number */ 1353 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0); 1354 if (err) { 1355 en_err(priv, "Failed setting default qp numbers\n"); 1356 goto tx_err; 1357 } 1358 1359 /* Init port */ 1360 en_dbg(HW, priv, "Initializing port\n"); 1361 err = mlx4_INIT_PORT(mdev->dev, priv->port); 1362 if (err) { 1363 en_err(priv, "Failed Initializing port\n"); 1364 goto tx_err; 1365 } 1366 1367 /* Attach rx QP to bradcast address */ 1368 memset(&mc_list[10], 0xff, ETH_ALEN); 1369 mc_list[5] = priv->port; /* needed for B0 steering support */ 1370 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list, 1371 priv->port, 0, MLX4_PROT_ETH, 1372 &priv->broadcast_id)) 1373 mlx4_warn(mdev, "Failed Attaching Broadcast\n"); 1374 1375 /* Must redo promiscuous mode setup. */ 1376 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC); 1377 1378 /* Schedule multicast task to populate multicast list */ 1379 queue_work(mdev->workqueue, &priv->rx_mode_task); 1380 1381 mlx4_set_stats_bitmap(mdev->dev, priv->stats_bitmap); 1382 1383 priv->port_up = true; 1384 1385 /* Enable the queues. */ 1386 dev->if_drv_flags &= ~IFF_DRV_OACTIVE; 1387 dev->if_drv_flags |= IFF_DRV_RUNNING; 1388 #ifdef CONFIG_DEBUG_FS 1389 mlx4_en_create_debug_files(priv); 1390 #endif 1391 callout_reset(&priv->watchdog_timer, MLX4_EN_WATCHDOG_TIMEOUT, 1392 mlx4_en_watchdog_timeout, priv); 1393 1394 1395 return 0; 1396 1397 tx_err: 1398 while (tx_index--) { 1399 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[tx_index]); 1400 mlx4_en_deactivate_cq(priv, priv->tx_cq[tx_index]); 1401 } 1402 mlx4_en_destroy_drop_qp(priv); 1403 rss_err: 1404 mlx4_en_release_rss_steer(priv); 1405 mac_err: 1406 mlx4_en_put_qp(priv); 1407 cq_err: 1408 while (rx_index--) 1409 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]); 1410 for (i = 0; i < priv->rx_ring_num; i++) 1411 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]); 1412 1413 return err; /* need to close devices */ 1414 } 1415 1416 1417 void mlx4_en_stop_port(struct net_device *dev) 1418 { 1419 struct mlx4_en_priv *priv = netdev_priv(dev); 1420 struct mlx4_en_dev *mdev = priv->mdev; 1421 struct mlx4_en_mc_list *mclist, *tmp; 1422 int i; 1423 u8 mc_list[16] = {0}; 1424 1425 if (!priv->port_up) { 1426 en_dbg(DRV, priv, "stop port called while port already down\n"); 1427 return; 1428 } 1429 1430 #ifdef CONFIG_DEBUG_FS 1431 mlx4_en_delete_debug_files(priv); 1432 #endif 1433 1434 /* close port*/ 1435 mlx4_CLOSE_PORT(mdev->dev, priv->port); 1436 1437 /* Set port as not active */ 1438 priv->port_up = false; 1439 if (priv->counter_index != 0xff) { 1440 mlx4_counter_free(mdev->dev, priv->port, priv->counter_index); 1441 priv->counter_index = 0xff; 1442 } 1443 1444 /* Promsicuous mode */ 1445 if (mdev->dev->caps.steering_mode == 1446 MLX4_STEERING_MODE_DEVICE_MANAGED) { 1447 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | 1448 MLX4_EN_FLAG_MC_PROMISC); 1449 mlx4_flow_steer_promisc_remove(mdev->dev, 1450 priv->port, 1451 MLX4_FS_ALL_DEFAULT); 1452 mlx4_flow_steer_promisc_remove(mdev->dev, 1453 priv->port, 1454 MLX4_FS_MC_DEFAULT); 1455 } else if (priv->flags & MLX4_EN_FLAG_PROMISC) { 1456 priv->flags &= ~MLX4_EN_FLAG_PROMISC; 1457 1458 /* Disable promiscouos mode */ 1459 mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn, 1460 priv->port); 1461 1462 /* Disable Multicast promisc */ 1463 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { 1464 mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn, 1465 priv->port); 1466 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; 1467 } 1468 } 1469 1470 /* Detach All multicasts */ 1471 memset(&mc_list[10], 0xff, ETH_ALEN); 1472 mc_list[5] = priv->port; /* needed for B0 steering support */ 1473 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list, 1474 MLX4_PROT_ETH, priv->broadcast_id); 1475 list_for_each_entry(mclist, &priv->curr_list, list) { 1476 memcpy(&mc_list[10], mclist->addr, ETH_ALEN); 1477 mc_list[5] = priv->port; 1478 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, 1479 mc_list, MLX4_PROT_ETH, mclist->reg_id); 1480 } 1481 mlx4_en_clear_list(dev); 1482 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { 1483 list_del(&mclist->list); 1484 kfree(mclist); 1485 } 1486 1487 /* Flush multicast filter */ 1488 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG); 1489 mlx4_en_destroy_drop_qp(priv); 1490 1491 /* Free TX Rings */ 1492 for (i = 0; i < priv->tx_ring_num; i++) { 1493 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[i]); 1494 mlx4_en_deactivate_cq(priv, priv->tx_cq[i]); 1495 } 1496 msleep(10); 1497 1498 for (i = 0; i < priv->tx_ring_num; i++) 1499 mlx4_en_free_tx_buf(dev, priv->tx_ring[i]); 1500 1501 /* Free RSS qps */ 1502 mlx4_en_release_rss_steer(priv); 1503 1504 /* Unregister Mac address for the port */ 1505 mlx4_en_put_qp(priv); 1506 mdev->mac_removed[priv->port] = 1; 1507 1508 /* Free RX Rings */ 1509 for (i = 0; i < priv->rx_ring_num; i++) { 1510 struct mlx4_en_cq *cq = priv->rx_cq[i]; 1511 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]); 1512 mlx4_en_deactivate_cq(priv, cq); 1513 } 1514 1515 callout_stop(&priv->watchdog_timer); 1516 1517 dev->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 1518 } 1519 1520 static void mlx4_en_restart(struct work_struct *work) 1521 { 1522 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, 1523 watchdog_task); 1524 struct mlx4_en_dev *mdev = priv->mdev; 1525 struct net_device *dev = priv->dev; 1526 struct mlx4_en_tx_ring *ring; 1527 int i; 1528 1529 1530 if (priv->blocked == 0 || priv->port_up == 0) 1531 return; 1532 for (i = 0; i < priv->tx_ring_num; i++) { 1533 ring = priv->tx_ring[i]; 1534 if (ring->blocked && 1535 ring->watchdog_time + MLX4_EN_WATCHDOG_TIMEOUT < ticks) 1536 goto reset; 1537 } 1538 return; 1539 1540 reset: 1541 priv->port_stats.tx_timeout++; 1542 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port); 1543 1544 mutex_lock(&mdev->state_lock); 1545 if (priv->port_up) { 1546 mlx4_en_stop_port(dev); 1547 //for (i = 0; i < priv->tx_ring_num; i++) 1548 // netdev_tx_reset_queue(priv->tx_ring[i]->tx_queue); 1549 if (mlx4_en_start_port(dev)) 1550 en_err(priv, "Failed restarting port %d\n", priv->port); 1551 } 1552 mutex_unlock(&mdev->state_lock); 1553 } 1554 1555 static void mlx4_en_clear_stats(struct net_device *dev) 1556 { 1557 struct mlx4_en_priv *priv = netdev_priv(dev); 1558 struct mlx4_en_dev *mdev = priv->mdev; 1559 int i; 1560 1561 if (!mlx4_is_slave(mdev->dev)) 1562 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1)) 1563 en_dbg(HW, priv, "Failed dumping statistics\n"); 1564 1565 memset(&priv->pstats, 0, sizeof(priv->pstats)); 1566 memset(&priv->pkstats, 0, sizeof(priv->pkstats)); 1567 memset(&priv->port_stats, 0, sizeof(priv->port_stats)); 1568 memset(&priv->vport_stats, 0, sizeof(priv->vport_stats)); 1569 1570 for (i = 0; i < priv->tx_ring_num; i++) { 1571 priv->tx_ring[i]->bytes = 0; 1572 priv->tx_ring[i]->packets = 0; 1573 priv->tx_ring[i]->tx_csum = 0; 1574 priv->tx_ring[i]->oversized_packets = 0; 1575 } 1576 for (i = 0; i < priv->rx_ring_num; i++) { 1577 priv->rx_ring[i]->bytes = 0; 1578 priv->rx_ring[i]->packets = 0; 1579 priv->rx_ring[i]->csum_ok = 0; 1580 priv->rx_ring[i]->csum_none = 0; 1581 } 1582 } 1583 1584 static void mlx4_en_open(void* arg) 1585 { 1586 1587 struct mlx4_en_priv *priv; 1588 struct mlx4_en_dev *mdev; 1589 struct net_device *dev; 1590 int err = 0; 1591 1592 priv = arg; 1593 mdev = priv->mdev; 1594 dev = priv->dev; 1595 1596 1597 mutex_lock(&mdev->state_lock); 1598 1599 if (!mdev->device_up) { 1600 en_err(priv, "Cannot open - device down/disabled\n"); 1601 goto out; 1602 } 1603 1604 /* Reset HW statistics and SW counters */ 1605 mlx4_en_clear_stats(dev); 1606 1607 err = mlx4_en_start_port(dev); 1608 if (err) 1609 en_err(priv, "Failed starting port:%d\n", priv->port); 1610 1611 out: 1612 mutex_unlock(&mdev->state_lock); 1613 return; 1614 } 1615 1616 void mlx4_en_free_resources(struct mlx4_en_priv *priv) 1617 { 1618 int i; 1619 1620 #ifdef CONFIG_RFS_ACCEL 1621 if (priv->dev->rx_cpu_rmap) { 1622 free_irq_cpu_rmap(priv->dev->rx_cpu_rmap); 1623 priv->dev->rx_cpu_rmap = NULL; 1624 } 1625 #endif 1626 1627 for (i = 0; i < priv->tx_ring_num; i++) { 1628 if (priv->tx_ring && priv->tx_ring[i]) 1629 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]); 1630 if (priv->tx_cq && priv->tx_cq[i]) 1631 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]); 1632 } 1633 1634 for (i = 0; i < priv->rx_ring_num; i++) { 1635 if (priv->rx_ring[i]) 1636 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i], 1637 priv->prof->rx_ring_size, priv->stride); 1638 if (priv->rx_cq[i]) 1639 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]); 1640 } 1641 1642 if (priv->sysctl) 1643 sysctl_ctx_free(&priv->stat_ctx); 1644 } 1645 1646 int mlx4_en_alloc_resources(struct mlx4_en_priv *priv) 1647 { 1648 struct mlx4_en_port_profile *prof = priv->prof; 1649 int i; 1650 int node = 0; 1651 1652 /* Create rx Rings */ 1653 for (i = 0; i < priv->rx_ring_num; i++) { 1654 if (mlx4_en_create_cq(priv, &priv->rx_cq[i], 1655 prof->rx_ring_size, i, RX, node)) 1656 goto err; 1657 1658 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i], 1659 prof->rx_ring_size, node)) 1660 goto err; 1661 } 1662 1663 /* Create tx Rings */ 1664 for (i = 0; i < priv->tx_ring_num; i++) { 1665 if (mlx4_en_create_cq(priv, &priv->tx_cq[i], 1666 prof->tx_ring_size, i, TX, node)) 1667 goto err; 1668 1669 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i], 1670 prof->tx_ring_size, TXBB_SIZE, node, i)) 1671 goto err; 1672 } 1673 1674 #ifdef CONFIG_RFS_ACCEL 1675 priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->rx_ring_num); 1676 if (!priv->dev->rx_cpu_rmap) 1677 goto err; 1678 #endif 1679 /* Re-create stat sysctls in case the number of rings changed. */ 1680 mlx4_en_sysctl_stat(priv); 1681 return 0; 1682 1683 err: 1684 en_err(priv, "Failed to allocate NIC resources\n"); 1685 for (i = 0; i < priv->rx_ring_num; i++) { 1686 if (priv->rx_ring[i]) 1687 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i], 1688 prof->rx_ring_size, 1689 priv->stride); 1690 if (priv->rx_cq[i]) 1691 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]); 1692 } 1693 for (i = 0; i < priv->tx_ring_num; i++) { 1694 if (priv->tx_ring[i]) 1695 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]); 1696 if (priv->tx_cq[i]) 1697 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]); 1698 } 1699 priv->port_up = false; 1700 return -ENOMEM; 1701 } 1702 1703 struct en_port_attribute { 1704 struct attribute attr; 1705 ssize_t (*show)(struct en_port *, struct en_port_attribute *, char *buf); 1706 ssize_t (*store)(struct en_port *, struct en_port_attribute *, char *buf, size_t count); 1707 }; 1708 1709 #define PORT_ATTR_RO(_name) \ 1710 struct en_port_attribute en_port_attr_##_name = __ATTR_RO(_name) 1711 1712 #define EN_PORT_ATTR(_name, _mode, _show, _store) \ 1713 struct en_port_attribute en_port_attr_##_name = __ATTR(_name, _mode, _show, _store) 1714 1715 void mlx4_en_destroy_netdev(struct net_device *dev) 1716 { 1717 struct mlx4_en_priv *priv = netdev_priv(dev); 1718 struct mlx4_en_dev *mdev = priv->mdev; 1719 1720 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port); 1721 1722 if (priv->vlan_attach != NULL) 1723 EVENTHANDLER_DEREGISTER(vlan_config, priv->vlan_attach); 1724 if (priv->vlan_detach != NULL) 1725 EVENTHANDLER_DEREGISTER(vlan_unconfig, priv->vlan_detach); 1726 1727 /* Unregister device - this will close the port if it was up */ 1728 if (priv->registered) { 1729 mutex_lock(&mdev->state_lock); 1730 ether_ifdetach(dev); 1731 mutex_unlock(&mdev->state_lock); 1732 } 1733 1734 if (priv->allocated) 1735 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE); 1736 1737 mutex_lock(&mdev->state_lock); 1738 mlx4_en_stop_port(dev); 1739 mutex_unlock(&mdev->state_lock); 1740 1741 1742 cancel_delayed_work(&priv->stats_task); 1743 cancel_delayed_work(&priv->service_task); 1744 /* flush any pending task for this netdev */ 1745 flush_workqueue(mdev->workqueue); 1746 callout_drain(&priv->watchdog_timer); 1747 1748 /* Detach the netdev so tasks would not attempt to access it */ 1749 mutex_lock(&mdev->state_lock); 1750 mdev->pndev[priv->port] = NULL; 1751 mutex_unlock(&mdev->state_lock); 1752 1753 1754 mlx4_en_free_resources(priv); 1755 1756 /* freeing the sysctl conf cannot be called from within mlx4_en_free_resources */ 1757 if (priv->sysctl) 1758 sysctl_ctx_free(&priv->conf_ctx); 1759 1760 kfree(priv->tx_ring); 1761 kfree(priv->tx_cq); 1762 1763 kfree(priv); 1764 if_free(dev); 1765 1766 } 1767 1768 static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu) 1769 { 1770 struct mlx4_en_priv *priv = netdev_priv(dev); 1771 struct mlx4_en_dev *mdev = priv->mdev; 1772 int err = 0; 1773 1774 en_dbg(DRV, priv, "Change MTU called - current:%u new:%u\n", 1775 (unsigned)dev->if_mtu, (unsigned)new_mtu); 1776 1777 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) { 1778 en_err(priv, "Bad MTU size:%d.\n", new_mtu); 1779 return -EPERM; 1780 } 1781 mutex_lock(&mdev->state_lock); 1782 dev->if_mtu = new_mtu; 1783 if (dev->if_drv_flags & IFF_DRV_RUNNING) { 1784 if (!mdev->device_up) { 1785 /* NIC is probably restarting - let watchdog task reset 1786 * * the port */ 1787 en_dbg(DRV, priv, "Change MTU called with card down!?\n"); 1788 } else { 1789 mlx4_en_stop_port(dev); 1790 err = mlx4_en_start_port(dev); 1791 if (err) { 1792 en_err(priv, "Failed restarting port:%d\n", 1793 priv->port); 1794 queue_work(mdev->workqueue, &priv->watchdog_task); 1795 } 1796 } 1797 } 1798 mutex_unlock(&mdev->state_lock); 1799 return 0; 1800 } 1801 1802 static int mlx4_en_calc_media(struct mlx4_en_priv *priv) 1803 { 1804 int trans_type; 1805 int active; 1806 1807 active = IFM_ETHER; 1808 if (priv->last_link_state == MLX4_DEV_EVENT_PORT_DOWN) 1809 return (active); 1810 active |= IFM_FDX; 1811 trans_type = priv->port_state.transciver; 1812 /* XXX I don't know all of the transceiver values. */ 1813 switch (priv->port_state.link_speed) { 1814 case 1000: 1815 active |= IFM_1000_T; 1816 break; 1817 case 10000: 1818 if (trans_type > 0 && trans_type <= 0xC) 1819 active |= IFM_10G_SR; 1820 else if (trans_type == 0x80 || trans_type == 0) 1821 active |= IFM_10G_CX4; 1822 break; 1823 case 40000: 1824 active |= IFM_40G_CR4; 1825 break; 1826 } 1827 if (priv->prof->tx_pause) 1828 active |= IFM_ETH_TXPAUSE; 1829 if (priv->prof->rx_pause) 1830 active |= IFM_ETH_RXPAUSE; 1831 1832 return (active); 1833 } 1834 1835 static void mlx4_en_media_status(struct ifnet *dev, struct ifmediareq *ifmr) 1836 { 1837 struct mlx4_en_priv *priv; 1838 1839 priv = dev->if_softc; 1840 ifmr->ifm_status = IFM_AVALID; 1841 if (priv->last_link_state != MLX4_DEV_EVENT_PORT_DOWN) 1842 ifmr->ifm_status |= IFM_ACTIVE; 1843 ifmr->ifm_active = mlx4_en_calc_media(priv); 1844 1845 return; 1846 } 1847 1848 static int mlx4_en_media_change(struct ifnet *dev) 1849 { 1850 struct mlx4_en_priv *priv; 1851 struct ifmedia *ifm; 1852 int rxpause; 1853 int txpause; 1854 int error; 1855 1856 priv = dev->if_softc; 1857 ifm = &priv->media; 1858 rxpause = txpause = 0; 1859 error = 0; 1860 1861 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 1862 return (EINVAL); 1863 switch (IFM_SUBTYPE(ifm->ifm_media)) { 1864 case IFM_AUTO: 1865 break; 1866 case IFM_10G_SR: 1867 case IFM_10G_CX4: 1868 case IFM_1000_T: 1869 case IFM_40G_CR4: 1870 if ((IFM_SUBTYPE(ifm->ifm_media) 1871 == IFM_SUBTYPE(mlx4_en_calc_media(priv))) 1872 && (ifm->ifm_media & IFM_FDX)) 1873 break; 1874 /* Fallthrough */ 1875 default: 1876 printf("%s: Only auto media type\n", if_name(dev)); 1877 return (EINVAL); 1878 } 1879 /* Allow user to set/clear pause */ 1880 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_RXPAUSE) 1881 rxpause = 1; 1882 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_TXPAUSE) 1883 txpause = 1; 1884 if (priv->prof->tx_pause != txpause || priv->prof->rx_pause != rxpause) { 1885 priv->prof->tx_pause = txpause; 1886 priv->prof->rx_pause = rxpause; 1887 error = -mlx4_SET_PORT_general(priv->mdev->dev, priv->port, 1888 priv->rx_mb_size + ETHER_CRC_LEN, priv->prof->tx_pause, 1889 priv->prof->tx_ppp, priv->prof->rx_pause, 1890 priv->prof->rx_ppp); 1891 } 1892 return (error); 1893 } 1894 1895 static int mlx4_en_ioctl(struct ifnet *dev, u_long command, caddr_t data) 1896 { 1897 struct mlx4_en_priv *priv; 1898 struct mlx4_en_dev *mdev; 1899 struct ifreq *ifr; 1900 int error; 1901 int mask; 1902 1903 error = 0; 1904 mask = 0; 1905 priv = dev->if_softc; 1906 mdev = priv->mdev; 1907 ifr = (struct ifreq *) data; 1908 switch (command) { 1909 1910 case SIOCSIFMTU: 1911 error = -mlx4_en_change_mtu(dev, ifr->ifr_mtu); 1912 break; 1913 case SIOCSIFFLAGS: 1914 if (dev->if_flags & IFF_UP) { 1915 if ((dev->if_drv_flags & IFF_DRV_RUNNING) == 0) { 1916 mutex_lock(&mdev->state_lock); 1917 mlx4_en_start_port(dev); 1918 mutex_unlock(&mdev->state_lock); 1919 } else { 1920 mlx4_en_set_rx_mode(dev); 1921 } 1922 } else { 1923 mutex_lock(&mdev->state_lock); 1924 if (dev->if_drv_flags & IFF_DRV_RUNNING) { 1925 mlx4_en_stop_port(dev); 1926 if_link_state_change(dev, LINK_STATE_DOWN); 1927 } 1928 mutex_unlock(&mdev->state_lock); 1929 } 1930 break; 1931 case SIOCADDMULTI: 1932 case SIOCDELMULTI: 1933 mlx4_en_set_rx_mode(dev); 1934 break; 1935 case SIOCSIFMEDIA: 1936 case SIOCGIFMEDIA: 1937 error = ifmedia_ioctl(dev, ifr, &priv->media, command); 1938 break; 1939 case SIOCSIFCAP: 1940 mutex_lock(&mdev->state_lock); 1941 mask = ifr->ifr_reqcap ^ dev->if_capenable; 1942 if (mask & IFCAP_TXCSUM) { 1943 dev->if_capenable ^= IFCAP_TXCSUM; 1944 dev->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP); 1945 1946 if (IFCAP_TSO4 & dev->if_capenable && 1947 !(IFCAP_TXCSUM & dev->if_capenable)) { 1948 dev->if_capenable &= ~IFCAP_TSO4; 1949 dev->if_hwassist &= ~CSUM_IP_TSO; 1950 if_printf(dev, 1951 "tso4 disabled due to -txcsum.\n"); 1952 } 1953 } 1954 if (mask & IFCAP_TXCSUM_IPV6) { 1955 dev->if_capenable ^= IFCAP_TXCSUM_IPV6; 1956 dev->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6); 1957 1958 if (IFCAP_TSO6 & dev->if_capenable && 1959 !(IFCAP_TXCSUM_IPV6 & dev->if_capenable)) { 1960 dev->if_capenable &= ~IFCAP_TSO6; 1961 dev->if_hwassist &= ~CSUM_IP6_TSO; 1962 if_printf(dev, 1963 "tso6 disabled due to -txcsum6.\n"); 1964 } 1965 } 1966 if (mask & IFCAP_RXCSUM) 1967 dev->if_capenable ^= IFCAP_RXCSUM; 1968 if (mask & IFCAP_RXCSUM_IPV6) 1969 dev->if_capenable ^= IFCAP_RXCSUM_IPV6; 1970 1971 if (mask & IFCAP_TSO4) { 1972 if (!(IFCAP_TSO4 & dev->if_capenable) && 1973 !(IFCAP_TXCSUM & dev->if_capenable)) { 1974 if_printf(dev, "enable txcsum first.\n"); 1975 error = EAGAIN; 1976 goto out; 1977 } 1978 dev->if_capenable ^= IFCAP_TSO4; 1979 dev->if_hwassist ^= CSUM_IP_TSO; 1980 } 1981 if (mask & IFCAP_TSO6) { 1982 if (!(IFCAP_TSO6 & dev->if_capenable) && 1983 !(IFCAP_TXCSUM_IPV6 & dev->if_capenable)) { 1984 if_printf(dev, "enable txcsum6 first.\n"); 1985 error = EAGAIN; 1986 goto out; 1987 } 1988 dev->if_capenable ^= IFCAP_TSO6; 1989 dev->if_hwassist ^= CSUM_IP6_TSO; 1990 } 1991 if (mask & IFCAP_LRO) 1992 dev->if_capenable ^= IFCAP_LRO; 1993 if (mask & IFCAP_VLAN_HWTAGGING) 1994 dev->if_capenable ^= IFCAP_VLAN_HWTAGGING; 1995 if (mask & IFCAP_VLAN_HWFILTER) 1996 dev->if_capenable ^= IFCAP_VLAN_HWFILTER; 1997 if (mask & IFCAP_WOL_MAGIC) 1998 dev->if_capenable ^= IFCAP_WOL_MAGIC; 1999 if (dev->if_drv_flags & IFF_DRV_RUNNING) 2000 mlx4_en_start_port(dev); 2001 out: 2002 mutex_unlock(&mdev->state_lock); 2003 VLAN_CAPABILITIES(dev); 2004 break; 2005 #if __FreeBSD_version >= 1100036 2006 case SIOCGI2C: { 2007 struct ifi2creq i2c; 2008 2009 error = copyin(ifr->ifr_data, &i2c, sizeof(i2c)); 2010 if (error) 2011 break; 2012 if (i2c.len > sizeof(i2c.data)) { 2013 error = EINVAL; 2014 break; 2015 } 2016 /* 2017 * Note that we ignore i2c.addr here. The driver hardcodes 2018 * the address to 0x50, while standard expects it to be 0xA0. 2019 */ 2020 error = mlx4_get_module_info(mdev->dev, priv->port, 2021 i2c.offset, i2c.len, i2c.data); 2022 if (error < 0) { 2023 error = -error; 2024 break; 2025 } 2026 error = copyout(&i2c, ifr->ifr_data, sizeof(i2c)); 2027 break; 2028 } 2029 #endif 2030 default: 2031 error = ether_ioctl(dev, command, data); 2032 break; 2033 } 2034 2035 return (error); 2036 } 2037 2038 2039 int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, 2040 struct mlx4_en_port_profile *prof) 2041 { 2042 struct net_device *dev; 2043 struct mlx4_en_priv *priv; 2044 uint8_t dev_addr[ETHER_ADDR_LEN]; 2045 int err; 2046 int i; 2047 2048 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 2049 dev = priv->dev = if_alloc(IFT_ETHER); 2050 if (dev == NULL) { 2051 en_err(priv, "Net device allocation failed\n"); 2052 kfree(priv); 2053 return -ENOMEM; 2054 } 2055 dev->if_softc = priv; 2056 if_initname(dev, "mlxen", atomic_fetchadd_int(&mlx4_en_unit, 1)); 2057 dev->if_mtu = ETHERMTU; 2058 dev->if_init = mlx4_en_open; 2059 dev->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 2060 dev->if_ioctl = mlx4_en_ioctl; 2061 dev->if_transmit = mlx4_en_transmit; 2062 dev->if_qflush = mlx4_en_qflush; 2063 dev->if_snd.ifq_maxlen = prof->tx_ring_size; 2064 2065 /* 2066 * Initialize driver private data 2067 */ 2068 priv->counter_index = 0xff; 2069 spin_lock_init(&priv->stats_lock); 2070 INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode); 2071 INIT_WORK(&priv->watchdog_task, mlx4_en_restart); 2072 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate); 2073 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats); 2074 INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task); 2075 callout_init(&priv->watchdog_timer, 1); 2076 #ifdef CONFIG_RFS_ACCEL 2077 INIT_LIST_HEAD(&priv->filters); 2078 spin_lock_init(&priv->filters_lock); 2079 #endif 2080 2081 priv->msg_enable = MLX4_EN_MSG_LEVEL; 2082 priv->dev = dev; 2083 priv->mdev = mdev; 2084 priv->ddev = &mdev->pdev->dev; 2085 priv->prof = prof; 2086 priv->port = port; 2087 priv->port_up = false; 2088 priv->flags = prof->flags; 2089 2090 priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up; 2091 priv->tx_ring_num = prof->tx_ring_num; 2092 priv->tx_ring = kcalloc(MAX_TX_RINGS, 2093 sizeof(struct mlx4_en_tx_ring *), GFP_KERNEL); 2094 if (!priv->tx_ring) { 2095 err = -ENOMEM; 2096 goto out; 2097 } 2098 priv->tx_cq = kcalloc(sizeof(struct mlx4_en_cq *), MAX_TX_RINGS, 2099 GFP_KERNEL); 2100 if (!priv->tx_cq) { 2101 err = -ENOMEM; 2102 goto out; 2103 } 2104 2105 priv->rx_ring_num = prof->rx_ring_num; 2106 priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0; 2107 priv->mac_index = -1; 2108 priv->last_ifq_jiffies = 0; 2109 priv->if_counters_rx_errors = 0; 2110 priv->if_counters_rx_no_buffer = 0; 2111 #ifdef CONFIG_MLX4_EN_DCB 2112 if (!mlx4_is_slave(priv->mdev->dev)) { 2113 priv->dcbx_cap = DCB_CAP_DCBX_HOST; 2114 priv->flags |= MLX4_EN_FLAG_DCB_ENABLED; 2115 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) { 2116 dev->dcbnl_ops = &mlx4_en_dcbnl_ops; 2117 } else { 2118 en_info(priv, "QoS disabled - no HW support\n"); 2119 dev->dcbnl_ops = &mlx4_en_dcbnl_pfc_ops; 2120 } 2121 } 2122 #endif 2123 2124 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) 2125 INIT_HLIST_HEAD(&priv->mac_hash[i]); 2126 2127 /* Query for default mac and max mtu */ 2128 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port]; 2129 priv->mac = mdev->dev->caps.def_mac[priv->port]; 2130 if (ILLEGAL_MAC(priv->mac)) { 2131 #if BITS_PER_LONG == 64 2132 en_err(priv, "Port: %d, invalid mac burned: 0x%lx, quiting\n", 2133 priv->port, priv->mac); 2134 #elif BITS_PER_LONG == 32 2135 en_err(priv, "Port: %d, invalid mac burned: 0x%llx, quiting\n", 2136 priv->port, priv->mac); 2137 #endif 2138 err = -EINVAL; 2139 goto out; 2140 } 2141 2142 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) + 2143 DS_SIZE); 2144 2145 mlx4_en_sysctl_conf(priv); 2146 2147 err = mlx4_en_alloc_resources(priv); 2148 if (err) 2149 goto out; 2150 2151 /* Allocate page for receive rings */ 2152 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res, 2153 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE); 2154 if (err) { 2155 en_err(priv, "Failed to allocate page for rx qps\n"); 2156 goto out; 2157 } 2158 priv->allocated = 1; 2159 2160 /* 2161 * Set driver features 2162 */ 2163 dev->if_capabilities |= IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6; 2164 dev->if_capabilities |= IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING; 2165 dev->if_capabilities |= IFCAP_VLAN_HWCSUM | IFCAP_VLAN_HWFILTER; 2166 dev->if_capabilities |= IFCAP_LINKSTATE | IFCAP_JUMBO_MTU; 2167 dev->if_capabilities |= IFCAP_LRO; 2168 dev->if_capabilities |= IFCAP_HWSTATS; 2169 2170 if (mdev->LSO_support) 2171 dev->if_capabilities |= IFCAP_TSO4 | IFCAP_TSO6 | IFCAP_VLAN_HWTSO; 2172 2173 #if __FreeBSD_version >= 1100000 2174 /* set TSO limits so that we don't have to drop TX packets */ 2175 dev->if_hw_tsomax = MLX4_EN_TX_MAX_PAYLOAD_SIZE - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN) /* hdr */; 2176 dev->if_hw_tsomaxsegcount = MLX4_EN_TX_MAX_MBUF_FRAGS - 1 /* hdr */; 2177 dev->if_hw_tsomaxsegsize = MLX4_EN_TX_MAX_MBUF_SIZE; 2178 #endif 2179 2180 dev->if_capenable = dev->if_capabilities; 2181 2182 dev->if_hwassist = 0; 2183 if (dev->if_capenable & (IFCAP_TSO4 | IFCAP_TSO6)) 2184 dev->if_hwassist |= CSUM_TSO; 2185 if (dev->if_capenable & IFCAP_TXCSUM) 2186 dev->if_hwassist |= (CSUM_TCP | CSUM_UDP | CSUM_IP); 2187 if (dev->if_capenable & IFCAP_TXCSUM_IPV6) 2188 dev->if_hwassist |= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6); 2189 2190 2191 /* Register for VLAN events */ 2192 priv->vlan_attach = EVENTHANDLER_REGISTER(vlan_config, 2193 mlx4_en_vlan_rx_add_vid, priv, EVENTHANDLER_PRI_FIRST); 2194 priv->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig, 2195 mlx4_en_vlan_rx_kill_vid, priv, EVENTHANDLER_PRI_FIRST); 2196 2197 mdev->pndev[priv->port] = dev; 2198 2199 priv->last_link_state = MLX4_DEV_EVENT_PORT_DOWN; 2200 mlx4_en_set_default_moderation(priv); 2201 2202 /* Set default MAC */ 2203 for (i = 0; i < ETHER_ADDR_LEN; i++) 2204 dev_addr[ETHER_ADDR_LEN - 1 - i] = (u8) (priv->mac >> (8 * i)); 2205 2206 2207 ether_ifattach(dev, dev_addr); 2208 if_link_state_change(dev, LINK_STATE_DOWN); 2209 ifmedia_init(&priv->media, IFM_IMASK | IFM_ETH_FMASK, 2210 mlx4_en_media_change, mlx4_en_media_status); 2211 ifmedia_add(&priv->media, IFM_ETHER | IFM_FDX | IFM_1000_T, 0, NULL); 2212 ifmedia_add(&priv->media, IFM_ETHER | IFM_FDX | IFM_10G_SR, 0, NULL); 2213 ifmedia_add(&priv->media, IFM_ETHER | IFM_FDX | IFM_10G_CX4, 0, NULL); 2214 ifmedia_add(&priv->media, IFM_ETHER | IFM_FDX | IFM_40G_CR4, 0, NULL); 2215 ifmedia_add(&priv->media, IFM_ETHER | IFM_AUTO, 0, NULL); 2216 ifmedia_set(&priv->media, IFM_ETHER | IFM_AUTO); 2217 2218 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num); 2219 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num); 2220 2221 priv->registered = 1; 2222 2223 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num); 2224 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num); 2225 2226 2227 priv->rx_mb_size = dev->if_mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN; 2228 err = mlx4_SET_PORT_general(mdev->dev, priv->port, 2229 priv->rx_mb_size, 2230 prof->tx_pause, prof->tx_ppp, 2231 prof->rx_pause, prof->rx_ppp); 2232 if (err) { 2233 en_err(priv, "Failed setting port general configurations " 2234 "for port %d, with error %d\n", priv->port, err); 2235 goto out; 2236 } 2237 2238 /* Init port */ 2239 en_warn(priv, "Initializing port\n"); 2240 err = mlx4_INIT_PORT(mdev->dev, priv->port); 2241 if (err) { 2242 en_err(priv, "Failed Initializing port\n"); 2243 goto out; 2244 } 2245 2246 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); 2247 2248 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) 2249 queue_delayed_work(mdev->workqueue, &priv->service_task, SERVICE_TASK_DELAY); 2250 2251 return 0; 2252 2253 out: 2254 mlx4_en_destroy_netdev(dev); 2255 return err; 2256 } 2257 2258 static int mlx4_en_set_ring_size(struct net_device *dev, 2259 int rx_size, int tx_size) 2260 { 2261 struct mlx4_en_priv *priv = netdev_priv(dev); 2262 struct mlx4_en_dev *mdev = priv->mdev; 2263 int port_up = 0; 2264 int err = 0; 2265 2266 rx_size = roundup_pow_of_two(rx_size); 2267 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE); 2268 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE); 2269 tx_size = roundup_pow_of_two(tx_size); 2270 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE); 2271 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE); 2272 2273 if (rx_size == (priv->port_up ? 2274 priv->rx_ring[0]->actual_size : priv->rx_ring[0]->size) && 2275 tx_size == priv->tx_ring[0]->size) 2276 return 0; 2277 mutex_lock(&mdev->state_lock); 2278 if (priv->port_up) { 2279 port_up = 1; 2280 mlx4_en_stop_port(dev); 2281 } 2282 mlx4_en_free_resources(priv); 2283 priv->prof->tx_ring_size = tx_size; 2284 priv->prof->rx_ring_size = rx_size; 2285 err = mlx4_en_alloc_resources(priv); 2286 if (err) { 2287 en_err(priv, "Failed reallocating port resources\n"); 2288 goto out; 2289 } 2290 if (port_up) { 2291 err = mlx4_en_start_port(dev); 2292 if (err) 2293 en_err(priv, "Failed starting port\n"); 2294 } 2295 out: 2296 mutex_unlock(&mdev->state_lock); 2297 return err; 2298 } 2299 static int mlx4_en_set_rx_ring_size(SYSCTL_HANDLER_ARGS) 2300 { 2301 struct mlx4_en_priv *priv; 2302 int size; 2303 int error; 2304 2305 priv = arg1; 2306 size = priv->prof->rx_ring_size; 2307 error = sysctl_handle_int(oidp, &size, 0, req); 2308 if (error || !req->newptr) 2309 return (error); 2310 error = -mlx4_en_set_ring_size(priv->dev, size, 2311 priv->prof->tx_ring_size); 2312 return (error); 2313 } 2314 2315 static int mlx4_en_set_tx_ring_size(SYSCTL_HANDLER_ARGS) 2316 { 2317 struct mlx4_en_priv *priv; 2318 int size; 2319 int error; 2320 2321 priv = arg1; 2322 size = priv->prof->tx_ring_size; 2323 error = sysctl_handle_int(oidp, &size, 0, req); 2324 if (error || !req->newptr) 2325 return (error); 2326 error = -mlx4_en_set_ring_size(priv->dev, priv->prof->rx_ring_size, 2327 size); 2328 2329 return (error); 2330 } 2331 2332 static int mlx4_en_get_module_info(struct net_device *dev, 2333 struct ethtool_modinfo *modinfo) 2334 { 2335 struct mlx4_en_priv *priv = netdev_priv(dev); 2336 struct mlx4_en_dev *mdev = priv->mdev; 2337 int ret; 2338 u8 data[4]; 2339 2340 /* Read first 2 bytes to get Module & REV ID */ 2341 ret = mlx4_get_module_info(mdev->dev, priv->port, 2342 0/*offset*/, 2/*size*/, data); 2343 2344 if (ret < 2) { 2345 en_err(priv, "Failed to read eeprom module first two bytes, error: 0x%x\n", -ret); 2346 return -EIO; 2347 } 2348 2349 switch (data[0] /* identifier */) { 2350 case MLX4_MODULE_ID_QSFP: 2351 modinfo->type = ETH_MODULE_SFF_8436; 2352 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 2353 break; 2354 case MLX4_MODULE_ID_QSFP_PLUS: 2355 if (data[1] >= 0x3) { /* revision id */ 2356 modinfo->type = ETH_MODULE_SFF_8636; 2357 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 2358 } else { 2359 modinfo->type = ETH_MODULE_SFF_8436; 2360 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 2361 } 2362 break; 2363 case MLX4_MODULE_ID_QSFP28: 2364 modinfo->type = ETH_MODULE_SFF_8636; 2365 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 2366 break; 2367 case MLX4_MODULE_ID_SFP: 2368 modinfo->type = ETH_MODULE_SFF_8472; 2369 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 2370 break; 2371 default: 2372 en_err(priv, "mlx4_en_get_module_info : Not recognized cable type\n"); 2373 return -EINVAL; 2374 } 2375 2376 return 0; 2377 } 2378 2379 static int mlx4_en_get_module_eeprom(struct net_device *dev, 2380 struct ethtool_eeprom *ee, 2381 u8 *data) 2382 { 2383 struct mlx4_en_priv *priv = netdev_priv(dev); 2384 struct mlx4_en_dev *mdev = priv->mdev; 2385 int offset = ee->offset; 2386 int i = 0, ret; 2387 2388 if (ee->len == 0) 2389 return -EINVAL; 2390 2391 memset(data, 0, ee->len); 2392 2393 while (i < ee->len) { 2394 en_dbg(DRV, priv, 2395 "mlx4_get_module_info i(%d) offset(%d) len(%d)\n", 2396 i, offset, ee->len - i); 2397 2398 ret = mlx4_get_module_info(mdev->dev, priv->port, 2399 offset, ee->len - i, data + i); 2400 2401 if (!ret) /* Done reading */ 2402 return 0; 2403 2404 if (ret < 0) { 2405 en_err(priv, 2406 "mlx4_get_module_info i(%d) offset(%d) bytes_to_read(%d) - FAILED (0x%x)\n", 2407 i, offset, ee->len - i, ret); 2408 return -1; 2409 } 2410 2411 i += ret; 2412 offset += ret; 2413 } 2414 return 0; 2415 } 2416 2417 static void mlx4_en_print_eeprom(u8 *data, __u32 len) 2418 { 2419 int i; 2420 int j = 0; 2421 int row = 0; 2422 const int NUM_OF_BYTES = 16; 2423 2424 printf("\nOffset\t\tValues\n"); 2425 printf("------\t\t------\n"); 2426 while(row < len){ 2427 printf("0x%04x\t\t",row); 2428 for(i=0; i < NUM_OF_BYTES; i++){ 2429 printf("%02x ", data[j]); 2430 row++; 2431 j++; 2432 } 2433 printf("\n"); 2434 } 2435 } 2436 2437 /* Read cable EEPROM module information by first inspecting the first 2438 * two bytes to get the length and then read the rest of the information. 2439 * The information is printed to dmesg. */ 2440 static int mlx4_en_read_eeprom(SYSCTL_HANDLER_ARGS) 2441 { 2442 2443 u8* data; 2444 int error; 2445 int result = 0; 2446 struct mlx4_en_priv *priv; 2447 struct net_device *dev; 2448 struct ethtool_modinfo modinfo; 2449 struct ethtool_eeprom ee; 2450 2451 error = sysctl_handle_int(oidp, &result, 0, req); 2452 if (error || !req->newptr) 2453 return (error); 2454 2455 if (result == 1) { 2456 priv = arg1; 2457 dev = priv->dev; 2458 data = kmalloc(PAGE_SIZE, GFP_KERNEL); 2459 2460 error = mlx4_en_get_module_info(dev, &modinfo); 2461 if (error) { 2462 en_err(priv, 2463 "mlx4_en_get_module_info returned with error - FAILED (0x%x)\n", 2464 -error); 2465 goto out; 2466 } 2467 2468 ee.len = modinfo.eeprom_len; 2469 ee.offset = 0; 2470 2471 error = mlx4_en_get_module_eeprom(dev, &ee, data); 2472 if (error) { 2473 en_err(priv, 2474 "mlx4_en_get_module_eeprom returned with error - FAILED (0x%x)\n", 2475 -error); 2476 /* Continue printing partial information in case of an error */ 2477 } 2478 2479 /* EEPROM information will be printed in dmesg */ 2480 mlx4_en_print_eeprom(data, ee.len); 2481 out: 2482 kfree(data); 2483 } 2484 /* Return zero to prevent sysctl failure. */ 2485 return (0); 2486 } 2487 2488 static int mlx4_en_set_tx_ppp(SYSCTL_HANDLER_ARGS) 2489 { 2490 struct mlx4_en_priv *priv; 2491 int ppp; 2492 int error; 2493 2494 priv = arg1; 2495 ppp = priv->prof->tx_ppp; 2496 error = sysctl_handle_int(oidp, &ppp, 0, req); 2497 if (error || !req->newptr) 2498 return (error); 2499 if (ppp > 0xff || ppp < 0) 2500 return (-EINVAL); 2501 priv->prof->tx_ppp = ppp; 2502 error = -mlx4_SET_PORT_general(priv->mdev->dev, priv->port, 2503 priv->rx_mb_size + ETHER_CRC_LEN, 2504 priv->prof->tx_pause, 2505 priv->prof->tx_ppp, 2506 priv->prof->rx_pause, 2507 priv->prof->rx_ppp); 2508 2509 return (error); 2510 } 2511 2512 static int mlx4_en_set_rx_ppp(SYSCTL_HANDLER_ARGS) 2513 { 2514 struct mlx4_en_priv *priv; 2515 struct mlx4_en_dev *mdev; 2516 int ppp; 2517 int error; 2518 int port_up; 2519 2520 port_up = 0; 2521 priv = arg1; 2522 mdev = priv->mdev; 2523 ppp = priv->prof->rx_ppp; 2524 error = sysctl_handle_int(oidp, &ppp, 0, req); 2525 if (error || !req->newptr) 2526 return (error); 2527 if (ppp > 0xff || ppp < 0) 2528 return (-EINVAL); 2529 /* See if we have to change the number of tx queues. */ 2530 if (!ppp != !priv->prof->rx_ppp) { 2531 mutex_lock(&mdev->state_lock); 2532 if (priv->port_up) { 2533 port_up = 1; 2534 mlx4_en_stop_port(priv->dev); 2535 } 2536 mlx4_en_free_resources(priv); 2537 priv->prof->rx_ppp = ppp; 2538 error = -mlx4_en_alloc_resources(priv); 2539 if (error) 2540 en_err(priv, "Failed reallocating port resources\n"); 2541 if (error == 0 && port_up) { 2542 error = -mlx4_en_start_port(priv->dev); 2543 if (error) 2544 en_err(priv, "Failed starting port\n"); 2545 } 2546 mutex_unlock(&mdev->state_lock); 2547 return (error); 2548 2549 } 2550 priv->prof->rx_ppp = ppp; 2551 error = -mlx4_SET_PORT_general(priv->mdev->dev, priv->port, 2552 priv->rx_mb_size + ETHER_CRC_LEN, 2553 priv->prof->tx_pause, 2554 priv->prof->tx_ppp, 2555 priv->prof->rx_pause, 2556 priv->prof->rx_ppp); 2557 2558 return (error); 2559 } 2560 2561 static void mlx4_en_sysctl_conf(struct mlx4_en_priv *priv) 2562 { 2563 struct net_device *dev; 2564 struct sysctl_ctx_list *ctx; 2565 struct sysctl_oid *node; 2566 struct sysctl_oid_list *node_list; 2567 struct sysctl_oid *coal; 2568 struct sysctl_oid_list *coal_list; 2569 const char *pnameunit; 2570 2571 dev = priv->dev; 2572 ctx = &priv->conf_ctx; 2573 pnameunit = device_get_nameunit(priv->mdev->pdev->dev.bsddev); 2574 2575 sysctl_ctx_init(ctx); 2576 priv->sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_hw), 2577 OID_AUTO, dev->if_xname, CTLFLAG_RD, 0, "mlx4 10gig ethernet"); 2578 node = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(priv->sysctl), OID_AUTO, 2579 "conf", CTLFLAG_RD, NULL, "Configuration"); 2580 node_list = SYSCTL_CHILDREN(node); 2581 2582 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "msg_enable", 2583 CTLFLAG_RW, &priv->msg_enable, 0, 2584 "Driver message enable bitfield"); 2585 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "rx_rings", 2586 CTLFLAG_RD, &priv->rx_ring_num, 0, 2587 "Number of receive rings"); 2588 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "tx_rings", 2589 CTLFLAG_RD, &priv->tx_ring_num, 0, 2590 "Number of transmit rings"); 2591 SYSCTL_ADD_PROC(ctx, node_list, OID_AUTO, "rx_size", 2592 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, 2593 mlx4_en_set_rx_ring_size, "I", "Receive ring size"); 2594 SYSCTL_ADD_PROC(ctx, node_list, OID_AUTO, "tx_size", 2595 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, 2596 mlx4_en_set_tx_ring_size, "I", "Transmit ring size"); 2597 SYSCTL_ADD_PROC(ctx, node_list, OID_AUTO, "tx_ppp", 2598 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, 2599 mlx4_en_set_tx_ppp, "I", "TX Per-priority pause"); 2600 SYSCTL_ADD_PROC(ctx, node_list, OID_AUTO, "rx_ppp", 2601 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, 2602 mlx4_en_set_rx_ppp, "I", "RX Per-priority pause"); 2603 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "port_num", 2604 CTLFLAG_RD, &priv->port, 0, 2605 "Port Number"); 2606 SYSCTL_ADD_STRING(ctx, node_list, OID_AUTO, "device_name", 2607 CTLFLAG_RD, __DECONST(void *, pnameunit), 0, 2608 "PCI device name"); 2609 2610 /* Add coalescer configuration. */ 2611 coal = SYSCTL_ADD_NODE(ctx, node_list, OID_AUTO, 2612 "coalesce", CTLFLAG_RD, NULL, "Interrupt coalesce configuration"); 2613 coal_list = SYSCTL_CHILDREN(coal); 2614 SYSCTL_ADD_UINT(ctx, coal_list, OID_AUTO, "pkt_rate_low", 2615 CTLFLAG_RW, &priv->pkt_rate_low, 0, 2616 "Packets per-second for minimum delay"); 2617 SYSCTL_ADD_UINT(ctx, coal_list, OID_AUTO, "rx_usecs_low", 2618 CTLFLAG_RW, &priv->rx_usecs_low, 0, 2619 "Minimum RX delay in micro-seconds"); 2620 SYSCTL_ADD_UINT(ctx, coal_list, OID_AUTO, "pkt_rate_high", 2621 CTLFLAG_RW, &priv->pkt_rate_high, 0, 2622 "Packets per-second for maximum delay"); 2623 SYSCTL_ADD_UINT(ctx, coal_list, OID_AUTO, "rx_usecs_high", 2624 CTLFLAG_RW, &priv->rx_usecs_high, 0, 2625 "Maximum RX delay in micro-seconds"); 2626 SYSCTL_ADD_UINT(ctx, coal_list, OID_AUTO, "sample_interval", 2627 CTLFLAG_RW, &priv->sample_interval, 0, 2628 "adaptive frequency in units of HZ ticks"); 2629 SYSCTL_ADD_UINT(ctx, coal_list, OID_AUTO, "adaptive_rx_coal", 2630 CTLFLAG_RW, &priv->adaptive_rx_coal, 0, 2631 "Enable adaptive rx coalescing"); 2632 /* EEPROM support */ 2633 SYSCTL_ADD_PROC(ctx, node_list, OID_AUTO, "eeprom_info", 2634 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, 2635 mlx4_en_read_eeprom, "I", "EEPROM information"); 2636 } 2637 2638 static void mlx4_en_sysctl_stat(struct mlx4_en_priv *priv) 2639 { 2640 struct sysctl_ctx_list *ctx; 2641 struct sysctl_oid *node; 2642 struct sysctl_oid_list *node_list; 2643 struct sysctl_oid *ring_node; 2644 struct sysctl_oid_list *ring_list; 2645 struct mlx4_en_tx_ring *tx_ring; 2646 struct mlx4_en_rx_ring *rx_ring; 2647 char namebuf[128]; 2648 int i; 2649 2650 ctx = &priv->stat_ctx; 2651 sysctl_ctx_init(ctx); 2652 node = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(priv->sysctl), OID_AUTO, 2653 "stat", CTLFLAG_RD, NULL, "Statistics"); 2654 node_list = SYSCTL_CHILDREN(node); 2655 2656 #ifdef MLX4_EN_PERF_STAT 2657 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "tx_poll", CTLFLAG_RD, 2658 &priv->pstats.tx_poll, "TX Poll calls"); 2659 SYSCTL_ADD_QUAD(ctx, node_list, OID_AUTO, "tx_pktsz_avg", CTLFLAG_RD, 2660 &priv->pstats.tx_pktsz_avg, "TX average packet size"); 2661 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "inflight_avg", CTLFLAG_RD, 2662 &priv->pstats.inflight_avg, "TX average packets in-flight"); 2663 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "tx_coal_avg", CTLFLAG_RD, 2664 &priv->pstats.tx_coal_avg, "TX average coalesced completions"); 2665 SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "rx_coal_avg", CTLFLAG_RD, 2666 &priv->pstats.rx_coal_avg, "RX average coalesced completions"); 2667 #endif 2668 2669 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tso_packets", CTLFLAG_RD, 2670 &priv->port_stats.tso_packets, "TSO packets sent"); 2671 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "queue_stopped", CTLFLAG_RD, 2672 &priv->port_stats.queue_stopped, "Queue full"); 2673 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "wake_queue", CTLFLAG_RD, 2674 &priv->port_stats.wake_queue, "Queue resumed after full"); 2675 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_timeout", CTLFLAG_RD, 2676 &priv->port_stats.tx_timeout, "Transmit timeouts"); 2677 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_oversized_packets", CTLFLAG_RD, 2678 &priv->port_stats.oversized_packets, "TX oversized packets, m_defrag failed"); 2679 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_alloc_failed", CTLFLAG_RD, 2680 &priv->port_stats.rx_alloc_failed, "RX failed to allocate mbuf"); 2681 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_chksum_good", CTLFLAG_RD, 2682 &priv->port_stats.rx_chksum_good, "RX checksum offload success"); 2683 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_chksum_none", CTLFLAG_RD, 2684 &priv->port_stats.rx_chksum_none, "RX without checksum offload"); 2685 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_chksum_offload", 2686 CTLFLAG_RD, &priv->port_stats.tx_chksum_offload, 2687 "TX checksum offloads"); 2688 2689 /* Could strdup the names and add in a loop. This is simpler. */ 2690 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_bytes", CTLFLAG_RD, 2691 &priv->pkstats.rx_bytes, "RX Bytes"); 2692 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_packets", CTLFLAG_RD, 2693 &priv->pkstats.rx_packets, "RX packets"); 2694 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_multicast_packets", CTLFLAG_RD, 2695 &priv->pkstats.rx_multicast_packets, "RX Multicast Packets"); 2696 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_broadcast_packets", CTLFLAG_RD, 2697 &priv->pkstats.rx_broadcast_packets, "RX Broadcast Packets"); 2698 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_errors", CTLFLAG_RD, 2699 &priv->pkstats.rx_errors, "RX Errors"); 2700 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_dropped", CTLFLAG_RD, 2701 &priv->pkstats.rx_dropped, "RX Dropped"); 2702 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_length_errors", CTLFLAG_RD, 2703 &priv->pkstats.rx_length_errors, "RX Length Errors"); 2704 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_over_errors", CTLFLAG_RD, 2705 &priv->pkstats.rx_over_errors, "RX Over Errors"); 2706 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_crc_errors", CTLFLAG_RD, 2707 &priv->pkstats.rx_crc_errors, "RX CRC Errors"); 2708 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_jabbers", CTLFLAG_RD, 2709 &priv->pkstats.rx_jabbers, "RX Jabbers"); 2710 2711 2712 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_in_range_length_error", CTLFLAG_RD, 2713 &priv->pkstats.rx_in_range_length_error, "RX IN_Range Length Error"); 2714 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_out_range_length_error", 2715 CTLFLAG_RD, &priv->pkstats.rx_out_range_length_error, 2716 "RX Out Range Length Error"); 2717 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_lt_64_bytes_packets", CTLFLAG_RD, 2718 &priv->pkstats.rx_lt_64_bytes_packets, "RX Lt 64 Bytes Packets"); 2719 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_127_bytes_packets", CTLFLAG_RD, 2720 &priv->pkstats.rx_127_bytes_packets, "RX 127 bytes Packets"); 2721 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_255_bytes_packets", CTLFLAG_RD, 2722 &priv->pkstats.rx_255_bytes_packets, "RX 255 bytes Packets"); 2723 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_511_bytes_packets", CTLFLAG_RD, 2724 &priv->pkstats.rx_511_bytes_packets, "RX 511 bytes Packets"); 2725 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_1023_bytes_packets", CTLFLAG_RD, 2726 &priv->pkstats.rx_1023_bytes_packets, "RX 1023 bytes Packets"); 2727 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_1518_bytes_packets", CTLFLAG_RD, 2728 &priv->pkstats.rx_1518_bytes_packets, "RX 1518 bytes Packets"); 2729 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_1522_bytes_packets", CTLFLAG_RD, 2730 &priv->pkstats.rx_1522_bytes_packets, "RX 1522 bytes Packets"); 2731 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_1548_bytes_packets", CTLFLAG_RD, 2732 &priv->pkstats.rx_1548_bytes_packets, "RX 1548 bytes Packets"); 2733 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "rx_gt_1548_bytes_packets", CTLFLAG_RD, 2734 &priv->pkstats.rx_gt_1548_bytes_packets, 2735 "RX Greater Then 1548 bytes Packets"); 2736 2737 struct mlx4_en_pkt_stats { 2738 unsigned long tx_packets; 2739 unsigned long tx_bytes; 2740 unsigned long tx_multicast_packets; 2741 unsigned long tx_broadcast_packets; 2742 unsigned long tx_errors; 2743 unsigned long tx_dropped; 2744 unsigned long tx_lt_64_bytes_packets; 2745 unsigned long tx_127_bytes_packets; 2746 unsigned long tx_255_bytes_packets; 2747 unsigned long tx_511_bytes_packets; 2748 unsigned long tx_1023_bytes_packets; 2749 unsigned long tx_1518_bytes_packets; 2750 unsigned long tx_1522_bytes_packets; 2751 unsigned long tx_1548_bytes_packets; 2752 unsigned long tx_gt_1548_bytes_packets; 2753 unsigned long rx_prio[NUM_PRIORITIES][NUM_PRIORITY_STATS]; 2754 unsigned long tx_prio[NUM_PRIORITIES][NUM_PRIORITY_STATS]; 2755 #define NUM_PKT_STATS 72 2756 }; 2757 2758 2759 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_packets", CTLFLAG_RD, 2760 &priv->pkstats.tx_packets, "TX packets"); 2761 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_bytes", CTLFLAG_RD, 2762 &priv->pkstats.tx_bytes, "TX Bytes"); 2763 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_multicast_packets", CTLFLAG_RD, 2764 &priv->pkstats.tx_multicast_packets, "TX Multicast Packets"); 2765 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_broadcast_packets", CTLFLAG_RD, 2766 &priv->pkstats.tx_broadcast_packets, "TX Broadcast Packets"); 2767 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_errors", CTLFLAG_RD, 2768 &priv->pkstats.tx_errors, "TX Errors"); 2769 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_dropped", CTLFLAG_RD, 2770 &priv->pkstats.tx_dropped, "TX Dropped"); 2771 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_lt_64_bytes_packets", CTLFLAG_RD, 2772 &priv->pkstats.tx_lt_64_bytes_packets, "TX Less Then 64 Bytes Packets"); 2773 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_127_bytes_packets", CTLFLAG_RD, 2774 &priv->pkstats.tx_127_bytes_packets, "TX 127 Bytes Packets"); 2775 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_255_bytes_packets", CTLFLAG_RD, 2776 &priv->pkstats.tx_255_bytes_packets, "TX 255 Bytes Packets"); 2777 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_511_bytes_packets", CTLFLAG_RD, 2778 &priv->pkstats.tx_511_bytes_packets, "TX 511 Bytes Packets"); 2779 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_1023_bytes_packets", CTLFLAG_RD, 2780 &priv->pkstats.tx_1023_bytes_packets, "TX 1023 Bytes Packets"); 2781 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_1518_bytes_packets", CTLFLAG_RD, 2782 &priv->pkstats.tx_1518_bytes_packets, "TX 1518 Bytes Packets"); 2783 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_1522_bytes_packets", CTLFLAG_RD, 2784 &priv->pkstats.tx_1522_bytes_packets, "TX 1522 Bytes Packets"); 2785 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_1548_bytes_packets", CTLFLAG_RD, 2786 &priv->pkstats.tx_1548_bytes_packets, "TX 1548 Bytes Packets"); 2787 SYSCTL_ADD_ULONG(ctx, node_list, OID_AUTO, "tx_gt_1548_bytes_packets", CTLFLAG_RD, 2788 &priv->pkstats.tx_gt_1548_bytes_packets, 2789 "TX Greater Then 1548 Bytes Packets"); 2790 2791 2792 2793 for (i = 0; i < priv->tx_ring_num; i++) { 2794 tx_ring = priv->tx_ring[i]; 2795 snprintf(namebuf, sizeof(namebuf), "tx_ring%d", i); 2796 ring_node = SYSCTL_ADD_NODE(ctx, node_list, OID_AUTO, namebuf, 2797 CTLFLAG_RD, NULL, "TX Ring"); 2798 ring_list = SYSCTL_CHILDREN(ring_node); 2799 SYSCTL_ADD_ULONG(ctx, ring_list, OID_AUTO, "packets", 2800 CTLFLAG_RD, &tx_ring->packets, "TX packets"); 2801 SYSCTL_ADD_ULONG(ctx, ring_list, OID_AUTO, "bytes", 2802 CTLFLAG_RD, &tx_ring->bytes, "TX bytes"); 2803 } 2804 2805 for (i = 0; i < priv->rx_ring_num; i++) { 2806 rx_ring = priv->rx_ring[i]; 2807 snprintf(namebuf, sizeof(namebuf), "rx_ring%d", i); 2808 ring_node = SYSCTL_ADD_NODE(ctx, node_list, OID_AUTO, namebuf, 2809 CTLFLAG_RD, NULL, "RX Ring"); 2810 ring_list = SYSCTL_CHILDREN(ring_node); 2811 SYSCTL_ADD_ULONG(ctx, ring_list, OID_AUTO, "packets", 2812 CTLFLAG_RD, &rx_ring->packets, "RX packets"); 2813 SYSCTL_ADD_ULONG(ctx, ring_list, OID_AUTO, "bytes", 2814 CTLFLAG_RD, &rx_ring->bytes, "RX bytes"); 2815 SYSCTL_ADD_ULONG(ctx, ring_list, OID_AUTO, "error", 2816 CTLFLAG_RD, &rx_ring->errors, "RX soft errors"); 2817 } 2818 } 2819