2 * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
34 #include <linux/etherdevice.h>
35 #include <linux/tcp.h>
36 #include <linux/if_vlan.h>
37 #include <linux/delay.h>
38 #include <linux/slab.h>
39 #include <linux/hash.h>
41 #include <net/busy_poll.h>
42 #include <net/vxlan.h>
44 #include <linux/mlx4/driver.h>
45 #include <linux/mlx4/device.h>
46 #include <linux/mlx4/cmd.h>
47 #include <linux/mlx4/cq.h>
52 int mlx4_en_setup_tc(struct net_device
*dev
, u8 up
)
54 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
56 unsigned int offset
= 0;
58 if (up
&& up
!= MLX4_EN_NUM_UP
)
61 netdev_set_num_tc(dev
, up
);
63 /* Partition Tx queues evenly amongst UP's */
64 for (i
= 0; i
< up
; i
++) {
65 netdev_set_tc_queue(dev
, i
, priv
->num_tx_rings_p_up
, offset
);
66 offset
+= priv
->num_tx_rings_p_up
;
72 #ifdef CONFIG_NET_RX_BUSY_POLL
73 /* must be called with local_bh_disable()d */
74 static int mlx4_en_low_latency_recv(struct napi_struct
*napi
)
76 struct mlx4_en_cq
*cq
= container_of(napi
, struct mlx4_en_cq
, napi
);
77 struct net_device
*dev
= cq
->dev
;
78 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
79 struct mlx4_en_rx_ring
*rx_ring
= priv
->rx_ring
[cq
->ring
];
83 return LL_FLUSH_FAILED
;
85 if (!mlx4_en_cq_lock_poll(cq
))
88 done
= mlx4_en_process_rx_cq(dev
, cq
, 4);
90 rx_ring
->cleaned
+= done
;
94 mlx4_en_cq_unlock_poll(cq
);
98 #endif /* CONFIG_NET_RX_BUSY_POLL */
100 #ifdef CONFIG_RFS_ACCEL
102 struct mlx4_en_filter
{
103 struct list_head next
;
104 struct work_struct work
;
113 struct mlx4_en_priv
*priv
;
114 u32 flow_id
; /* RFS infrastructure id */
115 int id
; /* mlx4_en driver id */
116 u64 reg_id
; /* Flow steering API id */
117 u8 activated
; /* Used to prevent expiry before filter
120 struct hlist_node filter_chain
;
123 static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv
*priv
);
125 static enum mlx4_net_trans_rule_id
mlx4_ip_proto_to_trans_rule_id(u8 ip_proto
)
129 return MLX4_NET_TRANS_RULE_ID_UDP
;
131 return MLX4_NET_TRANS_RULE_ID_TCP
;
133 return MLX4_NET_TRANS_RULE_NUM
;
137 static void mlx4_en_filter_work(struct work_struct
*work
)
139 struct mlx4_en_filter
*filter
= container_of(work
,
140 struct mlx4_en_filter
,
142 struct mlx4_en_priv
*priv
= filter
->priv
;
143 struct mlx4_spec_list spec_tcp_udp
= {
144 .id
= mlx4_ip_proto_to_trans_rule_id(filter
->ip_proto
),
147 .dst_port
= filter
->dst_port
,
148 .dst_port_msk
= (__force __be16
)-1,
149 .src_port
= filter
->src_port
,
150 .src_port_msk
= (__force __be16
)-1,
154 struct mlx4_spec_list spec_ip
= {
155 .id
= MLX4_NET_TRANS_RULE_ID_IPV4
,
158 .dst_ip
= filter
->dst_ip
,
159 .dst_ip_msk
= (__force __be32
)-1,
160 .src_ip
= filter
->src_ip
,
161 .src_ip_msk
= (__force __be32
)-1,
165 struct mlx4_spec_list spec_eth
= {
166 .id
= MLX4_NET_TRANS_RULE_ID_ETH
,
168 struct mlx4_net_trans_rule rule
= {
169 .list
= LIST_HEAD_INIT(rule
.list
),
170 .queue_mode
= MLX4_NET_TRANS_Q_LIFO
,
173 .promisc_mode
= MLX4_FS_REGULAR
,
175 .priority
= MLX4_DOMAIN_RFS
,
178 __be64 mac_mask
= cpu_to_be64(MLX4_MAC_MASK
<< 16);
180 if (spec_tcp_udp
.id
>= MLX4_NET_TRANS_RULE_NUM
) {
181 en_warn(priv
, "RFS: ignoring unsupported ip protocol (%d)\n",
185 list_add_tail(&spec_eth
.list
, &rule
.list
);
186 list_add_tail(&spec_ip
.list
, &rule
.list
);
187 list_add_tail(&spec_tcp_udp
.list
, &rule
.list
);
189 rule
.qpn
= priv
->rss_map
.qps
[filter
->rxq_index
].qpn
;
190 memcpy(spec_eth
.eth
.dst_mac
, priv
->dev
->dev_addr
, ETH_ALEN
);
191 memcpy(spec_eth
.eth
.dst_mac_msk
, &mac_mask
, ETH_ALEN
);
193 filter
->activated
= 0;
195 if (filter
->reg_id
) {
196 rc
= mlx4_flow_detach(priv
->mdev
->dev
, filter
->reg_id
);
197 if (rc
&& rc
!= -ENOENT
)
198 en_err(priv
, "Error detaching flow. rc = %d\n", rc
);
201 rc
= mlx4_flow_attach(priv
->mdev
->dev
, &rule
, &filter
->reg_id
);
203 en_err(priv
, "Error attaching flow. err = %d\n", rc
);
206 mlx4_en_filter_rfs_expire(priv
);
208 filter
->activated
= 1;
211 static inline struct hlist_head
*
212 filter_hash_bucket(struct mlx4_en_priv
*priv
, __be32 src_ip
, __be32 dst_ip
,
213 __be16 src_port
, __be16 dst_port
)
218 l
= (__force
unsigned long)src_port
|
219 ((__force
unsigned long)dst_port
<< 2);
220 l
^= (__force
unsigned long)(src_ip
^ dst_ip
);
222 bucket_idx
= hash_long(l
, MLX4_EN_FILTER_HASH_SHIFT
);
224 return &priv
->filter_hash
[bucket_idx
];
227 static struct mlx4_en_filter
*
228 mlx4_en_filter_alloc(struct mlx4_en_priv
*priv
, int rxq_index
, __be32 src_ip
,
229 __be32 dst_ip
, u8 ip_proto
, __be16 src_port
,
230 __be16 dst_port
, u32 flow_id
)
232 struct mlx4_en_filter
*filter
= NULL
;
234 filter
= kzalloc(sizeof(struct mlx4_en_filter
), GFP_ATOMIC
);
239 filter
->rxq_index
= rxq_index
;
240 INIT_WORK(&filter
->work
, mlx4_en_filter_work
);
242 filter
->src_ip
= src_ip
;
243 filter
->dst_ip
= dst_ip
;
244 filter
->ip_proto
= ip_proto
;
245 filter
->src_port
= src_port
;
246 filter
->dst_port
= dst_port
;
248 filter
->flow_id
= flow_id
;
250 filter
->id
= priv
->last_filter_id
++ % RPS_NO_FILTER
;
252 list_add_tail(&filter
->next
, &priv
->filters
);
253 hlist_add_head(&filter
->filter_chain
,
254 filter_hash_bucket(priv
, src_ip
, dst_ip
, src_port
,
260 static void mlx4_en_filter_free(struct mlx4_en_filter
*filter
)
262 struct mlx4_en_priv
*priv
= filter
->priv
;
265 list_del(&filter
->next
);
267 rc
= mlx4_flow_detach(priv
->mdev
->dev
, filter
->reg_id
);
268 if (rc
&& rc
!= -ENOENT
)
269 en_err(priv
, "Error detaching flow. rc = %d\n", rc
);
274 static inline struct mlx4_en_filter
*
275 mlx4_en_filter_find(struct mlx4_en_priv
*priv
, __be32 src_ip
, __be32 dst_ip
,
276 u8 ip_proto
, __be16 src_port
, __be16 dst_port
)
278 struct mlx4_en_filter
*filter
;
279 struct mlx4_en_filter
*ret
= NULL
;
281 hlist_for_each_entry(filter
,
282 filter_hash_bucket(priv
, src_ip
, dst_ip
,
285 if (filter
->src_ip
== src_ip
&&
286 filter
->dst_ip
== dst_ip
&&
287 filter
->ip_proto
== ip_proto
&&
288 filter
->src_port
== src_port
&&
289 filter
->dst_port
== dst_port
) {
299 mlx4_en_filter_rfs(struct net_device
*net_dev
, const struct sk_buff
*skb
,
300 u16 rxq_index
, u32 flow_id
)
302 struct mlx4_en_priv
*priv
= netdev_priv(net_dev
);
303 struct mlx4_en_filter
*filter
;
304 const struct iphdr
*ip
;
311 int nhoff
= skb_network_offset(skb
);
314 if (skb
->protocol
!= htons(ETH_P_IP
))
315 return -EPROTONOSUPPORT
;
317 ip
= (const struct iphdr
*)(skb
->data
+ nhoff
);
318 if (ip_is_fragment(ip
))
319 return -EPROTONOSUPPORT
;
321 if ((ip
->protocol
!= IPPROTO_TCP
) && (ip
->protocol
!= IPPROTO_UDP
))
322 return -EPROTONOSUPPORT
;
323 ports
= (const __be16
*)(skb
->data
+ nhoff
+ 4 * ip
->ihl
);
325 ip_proto
= ip
->protocol
;
331 spin_lock_bh(&priv
->filters_lock
);
332 filter
= mlx4_en_filter_find(priv
, src_ip
, dst_ip
, ip_proto
,
335 if (filter
->rxq_index
== rxq_index
)
338 filter
->rxq_index
= rxq_index
;
340 filter
= mlx4_en_filter_alloc(priv
, rxq_index
,
341 src_ip
, dst_ip
, ip_proto
,
342 src_port
, dst_port
, flow_id
);
349 queue_work(priv
->mdev
->workqueue
, &filter
->work
);
354 spin_unlock_bh(&priv
->filters_lock
);
359 void mlx4_en_cleanup_filters(struct mlx4_en_priv
*priv
)
361 struct mlx4_en_filter
*filter
, *tmp
;
364 spin_lock_bh(&priv
->filters_lock
);
365 list_for_each_entry_safe(filter
, tmp
, &priv
->filters
, next
) {
366 list_move(&filter
->next
, &del_list
);
367 hlist_del(&filter
->filter_chain
);
369 spin_unlock_bh(&priv
->filters_lock
);
371 list_for_each_entry_safe(filter
, tmp
, &del_list
, next
) {
372 cancel_work_sync(&filter
->work
);
373 mlx4_en_filter_free(filter
);
377 static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv
*priv
)
379 struct mlx4_en_filter
*filter
= NULL
, *tmp
, *last_filter
= NULL
;
383 spin_lock_bh(&priv
->filters_lock
);
384 list_for_each_entry_safe(filter
, tmp
, &priv
->filters
, next
) {
385 if (i
> MLX4_EN_FILTER_EXPIRY_QUOTA
)
388 if (filter
->activated
&&
389 !work_pending(&filter
->work
) &&
390 rps_may_expire_flow(priv
->dev
,
391 filter
->rxq_index
, filter
->flow_id
,
393 list_move(&filter
->next
, &del_list
);
394 hlist_del(&filter
->filter_chain
);
396 last_filter
= filter
;
401 if (last_filter
&& (&last_filter
->next
!= priv
->filters
.next
))
402 list_move(&priv
->filters
, &last_filter
->next
);
404 spin_unlock_bh(&priv
->filters_lock
);
406 list_for_each_entry_safe(filter
, tmp
, &del_list
, next
)
407 mlx4_en_filter_free(filter
);
411 static int mlx4_en_vlan_rx_add_vid(struct net_device
*dev
,
412 __be16 proto
, u16 vid
)
414 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
415 struct mlx4_en_dev
*mdev
= priv
->mdev
;
419 en_dbg(HW
, priv
, "adding VLAN:%d\n", vid
);
421 set_bit(vid
, priv
->active_vlans
);
423 /* Add VID to port VLAN filter */
424 mutex_lock(&mdev
->state_lock
);
425 if (mdev
->device_up
&& priv
->port_up
) {
426 err
= mlx4_SET_VLAN_FLTR(mdev
->dev
, priv
);
428 en_err(priv
, "Failed configuring VLAN filter\n");
430 if (mlx4_register_vlan(mdev
->dev
, priv
->port
, vid
, &idx
))
431 en_dbg(HW
, priv
, "failed adding vlan %d\n", vid
);
432 mutex_unlock(&mdev
->state_lock
);
437 static int mlx4_en_vlan_rx_kill_vid(struct net_device
*dev
,
438 __be16 proto
, u16 vid
)
440 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
441 struct mlx4_en_dev
*mdev
= priv
->mdev
;
444 en_dbg(HW
, priv
, "Killing VID:%d\n", vid
);
446 clear_bit(vid
, priv
->active_vlans
);
448 /* Remove VID from port VLAN filter */
449 mutex_lock(&mdev
->state_lock
);
450 mlx4_unregister_vlan(mdev
->dev
, priv
->port
, vid
);
452 if (mdev
->device_up
&& priv
->port_up
) {
453 err
= mlx4_SET_VLAN_FLTR(mdev
->dev
, priv
);
455 en_err(priv
, "Failed configuring VLAN filter\n");
457 mutex_unlock(&mdev
->state_lock
);
462 static void mlx4_en_u64_to_mac(unsigned char dst_mac
[ETH_ALEN
+ 2], u64 src_mac
)
465 for (i
= ETH_ALEN
- 1; i
>= 0; --i
) {
466 dst_mac
[i
] = src_mac
& 0xff;
469 memset(&dst_mac
[ETH_ALEN
], 0, 2);
473 static int mlx4_en_tunnel_steer_add(struct mlx4_en_priv
*priv
, unsigned char *addr
,
474 int qpn
, u64
*reg_id
)
478 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
||
479 priv
->mdev
->dev
->caps
.dmfs_high_steer_mode
== MLX4_STEERING_DMFS_A0_STATIC
)
480 return 0; /* do nothing */
482 err
= mlx4_tunnel_steer_add(priv
->mdev
->dev
, addr
, priv
->port
, qpn
,
483 MLX4_DOMAIN_NIC
, reg_id
);
485 en_err(priv
, "failed to add vxlan steering rule, err %d\n", err
);
488 en_dbg(DRV
, priv
, "added vxlan steering rule, mac %pM reg_id %llx\n", addr
, *reg_id
);
493 static int mlx4_en_uc_steer_add(struct mlx4_en_priv
*priv
,
494 unsigned char *mac
, int *qpn
, u64
*reg_id
)
496 struct mlx4_en_dev
*mdev
= priv
->mdev
;
497 struct mlx4_dev
*dev
= mdev
->dev
;
500 switch (dev
->caps
.steering_mode
) {
501 case MLX4_STEERING_MODE_B0
: {
506 memcpy(&gid
[10], mac
, ETH_ALEN
);
509 err
= mlx4_unicast_attach(dev
, &qp
, gid
, 0, MLX4_PROT_ETH
);
512 case MLX4_STEERING_MODE_DEVICE_MANAGED
: {
513 struct mlx4_spec_list spec_eth
= { {NULL
} };
514 __be64 mac_mask
= cpu_to_be64(MLX4_MAC_MASK
<< 16);
516 struct mlx4_net_trans_rule rule
= {
517 .queue_mode
= MLX4_NET_TRANS_Q_FIFO
,
520 .promisc_mode
= MLX4_FS_REGULAR
,
521 .priority
= MLX4_DOMAIN_NIC
,
524 rule
.port
= priv
->port
;
526 INIT_LIST_HEAD(&rule
.list
);
528 spec_eth
.id
= MLX4_NET_TRANS_RULE_ID_ETH
;
529 memcpy(spec_eth
.eth
.dst_mac
, mac
, ETH_ALEN
);
530 memcpy(spec_eth
.eth
.dst_mac_msk
, &mac_mask
, ETH_ALEN
);
531 list_add_tail(&spec_eth
.list
, &rule
.list
);
533 err
= mlx4_flow_attach(dev
, &rule
, reg_id
);
540 en_warn(priv
, "Failed Attaching Unicast\n");
545 static void mlx4_en_uc_steer_release(struct mlx4_en_priv
*priv
,
546 unsigned char *mac
, int qpn
, u64 reg_id
)
548 struct mlx4_en_dev
*mdev
= priv
->mdev
;
549 struct mlx4_dev
*dev
= mdev
->dev
;
551 switch (dev
->caps
.steering_mode
) {
552 case MLX4_STEERING_MODE_B0
: {
557 memcpy(&gid
[10], mac
, ETH_ALEN
);
560 mlx4_unicast_detach(dev
, &qp
, gid
, MLX4_PROT_ETH
);
563 case MLX4_STEERING_MODE_DEVICE_MANAGED
: {
564 mlx4_flow_detach(dev
, reg_id
);
568 en_err(priv
, "Invalid steering mode.\n");
572 static int mlx4_en_get_qp(struct mlx4_en_priv
*priv
)
574 struct mlx4_en_dev
*mdev
= priv
->mdev
;
575 struct mlx4_dev
*dev
= mdev
->dev
;
578 int *qpn
= &priv
->base_qpn
;
579 u64 mac
= mlx4_mac_to_u64(priv
->dev
->dev_addr
);
581 en_dbg(DRV
, priv
, "Registering MAC: %pM for adding\n",
582 priv
->dev
->dev_addr
);
583 index
= mlx4_register_mac(dev
, priv
->port
, mac
);
586 en_err(priv
, "Failed adding MAC: %pM\n",
587 priv
->dev
->dev_addr
);
591 if (dev
->caps
.steering_mode
== MLX4_STEERING_MODE_A0
) {
592 int base_qpn
= mlx4_get_base_qpn(dev
, priv
->port
);
593 *qpn
= base_qpn
+ index
;
597 err
= mlx4_qp_reserve_range(dev
, 1, 1, qpn
, MLX4_RESERVE_A0_QP
);
598 en_dbg(DRV
, priv
, "Reserved qp %d\n", *qpn
);
600 en_err(priv
, "Failed to reserve qp for mac registration\n");
601 mlx4_unregister_mac(dev
, priv
->port
, mac
);
608 static void mlx4_en_put_qp(struct mlx4_en_priv
*priv
)
610 struct mlx4_en_dev
*mdev
= priv
->mdev
;
611 struct mlx4_dev
*dev
= mdev
->dev
;
612 int qpn
= priv
->base_qpn
;
614 if (dev
->caps
.steering_mode
== MLX4_STEERING_MODE_A0
) {
615 u64 mac
= mlx4_mac_to_u64(priv
->dev
->dev_addr
);
616 en_dbg(DRV
, priv
, "Registering MAC: %pM for deleting\n",
617 priv
->dev
->dev_addr
);
618 mlx4_unregister_mac(dev
, priv
->port
, mac
);
620 en_dbg(DRV
, priv
, "Releasing qp: port %d, qpn %d\n",
622 mlx4_qp_release_range(dev
, qpn
, 1);
623 priv
->flags
&= ~MLX4_EN_FLAG_FORCE_PROMISC
;
627 static int mlx4_en_replace_mac(struct mlx4_en_priv
*priv
, int qpn
,
628 unsigned char *new_mac
, unsigned char *prev_mac
)
630 struct mlx4_en_dev
*mdev
= priv
->mdev
;
631 struct mlx4_dev
*dev
= mdev
->dev
;
633 u64 new_mac_u64
= mlx4_mac_to_u64(new_mac
);
635 if (dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
) {
636 struct hlist_head
*bucket
;
637 unsigned int mac_hash
;
638 struct mlx4_mac_entry
*entry
;
639 struct hlist_node
*tmp
;
640 u64 prev_mac_u64
= mlx4_mac_to_u64(prev_mac
);
642 bucket
= &priv
->mac_hash
[prev_mac
[MLX4_EN_MAC_HASH_IDX
]];
643 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
644 if (ether_addr_equal_64bits(entry
->mac
, prev_mac
)) {
645 mlx4_en_uc_steer_release(priv
, entry
->mac
,
647 mlx4_unregister_mac(dev
, priv
->port
,
649 hlist_del_rcu(&entry
->hlist
);
651 memcpy(entry
->mac
, new_mac
, ETH_ALEN
);
653 mac_hash
= new_mac
[MLX4_EN_MAC_HASH_IDX
];
654 hlist_add_head_rcu(&entry
->hlist
,
655 &priv
->mac_hash
[mac_hash
]);
656 mlx4_register_mac(dev
, priv
->port
, new_mac_u64
);
657 err
= mlx4_en_uc_steer_add(priv
, new_mac
,
662 if (priv
->tunnel_reg_id
) {
663 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
664 priv
->tunnel_reg_id
= 0;
666 err
= mlx4_en_tunnel_steer_add(priv
, new_mac
, qpn
,
667 &priv
->tunnel_reg_id
);
674 return __mlx4_replace_mac(dev
, priv
->port
, qpn
, new_mac_u64
);
677 static int mlx4_en_do_set_mac(struct mlx4_en_priv
*priv
,
678 unsigned char new_mac
[ETH_ALEN
+ 2])
683 /* Remove old MAC and insert the new one */
684 err
= mlx4_en_replace_mac(priv
, priv
->base_qpn
,
685 new_mac
, priv
->current_mac
);
687 en_err(priv
, "Failed changing HW MAC address\n");
689 en_dbg(HW
, priv
, "Port is down while registering mac, exiting...\n");
692 memcpy(priv
->current_mac
, new_mac
, sizeof(priv
->current_mac
));
697 static int mlx4_en_set_mac(struct net_device
*dev
, void *addr
)
699 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
700 struct mlx4_en_dev
*mdev
= priv
->mdev
;
701 struct sockaddr
*saddr
= addr
;
702 unsigned char new_mac
[ETH_ALEN
+ 2];
705 if (!is_valid_ether_addr(saddr
->sa_data
))
706 return -EADDRNOTAVAIL
;
708 mutex_lock(&mdev
->state_lock
);
709 memcpy(new_mac
, saddr
->sa_data
, ETH_ALEN
);
710 err
= mlx4_en_do_set_mac(priv
, new_mac
);
712 memcpy(dev
->dev_addr
, saddr
->sa_data
, ETH_ALEN
);
713 mutex_unlock(&mdev
->state_lock
);
718 static void mlx4_en_clear_list(struct net_device
*dev
)
720 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
721 struct mlx4_en_mc_list
*tmp
, *mc_to_del
;
723 list_for_each_entry_safe(mc_to_del
, tmp
, &priv
->mc_list
, list
) {
724 list_del(&mc_to_del
->list
);
729 static void mlx4_en_cache_mclist(struct net_device
*dev
)
731 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
732 struct netdev_hw_addr
*ha
;
733 struct mlx4_en_mc_list
*tmp
;
735 mlx4_en_clear_list(dev
);
736 netdev_for_each_mc_addr(ha
, dev
) {
737 tmp
= kzalloc(sizeof(struct mlx4_en_mc_list
), GFP_ATOMIC
);
739 mlx4_en_clear_list(dev
);
742 memcpy(tmp
->addr
, ha
->addr
, ETH_ALEN
);
743 list_add_tail(&tmp
->list
, &priv
->mc_list
);
747 static void update_mclist_flags(struct mlx4_en_priv
*priv
,
748 struct list_head
*dst
,
749 struct list_head
*src
)
751 struct mlx4_en_mc_list
*dst_tmp
, *src_tmp
, *new_mc
;
754 /* Find all the entries that should be removed from dst,
755 * These are the entries that are not found in src
757 list_for_each_entry(dst_tmp
, dst
, list
) {
759 list_for_each_entry(src_tmp
, src
, list
) {
760 if (ether_addr_equal(dst_tmp
->addr
, src_tmp
->addr
)) {
766 dst_tmp
->action
= MCLIST_REM
;
769 /* Add entries that exist in src but not in dst
770 * mark them as need to add
772 list_for_each_entry(src_tmp
, src
, list
) {
774 list_for_each_entry(dst_tmp
, dst
, list
) {
775 if (ether_addr_equal(dst_tmp
->addr
, src_tmp
->addr
)) {
776 dst_tmp
->action
= MCLIST_NONE
;
782 new_mc
= kmemdup(src_tmp
,
783 sizeof(struct mlx4_en_mc_list
),
788 new_mc
->action
= MCLIST_ADD
;
789 list_add_tail(&new_mc
->list
, dst
);
794 static void mlx4_en_set_rx_mode(struct net_device
*dev
)
796 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
801 queue_work(priv
->mdev
->workqueue
, &priv
->rx_mode_task
);
804 static void mlx4_en_set_promisc_mode(struct mlx4_en_priv
*priv
,
805 struct mlx4_en_dev
*mdev
)
809 if (!(priv
->flags
& MLX4_EN_FLAG_PROMISC
)) {
810 if (netif_msg_rx_status(priv
))
811 en_warn(priv
, "Entering promiscuous mode\n");
812 priv
->flags
|= MLX4_EN_FLAG_PROMISC
;
814 /* Enable promiscouos mode */
815 switch (mdev
->dev
->caps
.steering_mode
) {
816 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
817 err
= mlx4_flow_steer_promisc_add(mdev
->dev
,
820 MLX4_FS_ALL_DEFAULT
);
822 en_err(priv
, "Failed enabling promiscuous mode\n");
823 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
826 case MLX4_STEERING_MODE_B0
:
827 err
= mlx4_unicast_promisc_add(mdev
->dev
,
831 en_err(priv
, "Failed enabling unicast promiscuous mode\n");
833 /* Add the default qp number as multicast
836 if (!(priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
)) {
837 err
= mlx4_multicast_promisc_add(mdev
->dev
,
841 en_err(priv
, "Failed enabling multicast promiscuous mode\n");
842 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
846 case MLX4_STEERING_MODE_A0
:
847 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
,
852 en_err(priv
, "Failed enabling promiscuous mode\n");
856 /* Disable port multicast filter (unconditionally) */
857 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
858 0, MLX4_MCAST_DISABLE
);
860 en_err(priv
, "Failed disabling multicast filter\n");
864 static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv
*priv
,
865 struct mlx4_en_dev
*mdev
)
869 if (netif_msg_rx_status(priv
))
870 en_warn(priv
, "Leaving promiscuous mode\n");
871 priv
->flags
&= ~MLX4_EN_FLAG_PROMISC
;
873 /* Disable promiscouos mode */
874 switch (mdev
->dev
->caps
.steering_mode
) {
875 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
876 err
= mlx4_flow_steer_promisc_remove(mdev
->dev
,
878 MLX4_FS_ALL_DEFAULT
);
880 en_err(priv
, "Failed disabling promiscuous mode\n");
881 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
884 case MLX4_STEERING_MODE_B0
:
885 err
= mlx4_unicast_promisc_remove(mdev
->dev
,
889 en_err(priv
, "Failed disabling unicast promiscuous mode\n");
890 /* Disable Multicast promisc */
891 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
892 err
= mlx4_multicast_promisc_remove(mdev
->dev
,
896 en_err(priv
, "Failed disabling multicast promiscuous mode\n");
897 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
901 case MLX4_STEERING_MODE_A0
:
902 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
,
906 en_err(priv
, "Failed disabling promiscuous mode\n");
911 static void mlx4_en_do_multicast(struct mlx4_en_priv
*priv
,
912 struct net_device
*dev
,
913 struct mlx4_en_dev
*mdev
)
915 struct mlx4_en_mc_list
*mclist
, *tmp
;
917 u8 mc_list
[16] = {0};
920 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
921 if (dev
->flags
& IFF_ALLMULTI
) {
922 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
923 0, MLX4_MCAST_DISABLE
);
925 en_err(priv
, "Failed disabling multicast filter\n");
927 /* Add the default qp number as multicast promisc */
928 if (!(priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
)) {
929 switch (mdev
->dev
->caps
.steering_mode
) {
930 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
931 err
= mlx4_flow_steer_promisc_add(mdev
->dev
,
937 case MLX4_STEERING_MODE_B0
:
938 err
= mlx4_multicast_promisc_add(mdev
->dev
,
943 case MLX4_STEERING_MODE_A0
:
947 en_err(priv
, "Failed entering multicast promisc mode\n");
948 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
951 /* Disable Multicast promisc */
952 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
953 switch (mdev
->dev
->caps
.steering_mode
) {
954 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
955 err
= mlx4_flow_steer_promisc_remove(mdev
->dev
,
960 case MLX4_STEERING_MODE_B0
:
961 err
= mlx4_multicast_promisc_remove(mdev
->dev
,
966 case MLX4_STEERING_MODE_A0
:
970 en_err(priv
, "Failed disabling multicast promiscuous mode\n");
971 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
974 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
975 0, MLX4_MCAST_DISABLE
);
977 en_err(priv
, "Failed disabling multicast filter\n");
979 /* Flush mcast filter and init it with broadcast address */
980 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, ETH_BCAST
,
981 1, MLX4_MCAST_CONFIG
);
983 /* Update multicast list - we cache all addresses so they won't
984 * change while HW is updated holding the command semaphor */
985 netif_addr_lock_bh(dev
);
986 mlx4_en_cache_mclist(dev
);
987 netif_addr_unlock_bh(dev
);
988 list_for_each_entry(mclist
, &priv
->mc_list
, list
) {
989 mcast_addr
= mlx4_mac_to_u64(mclist
->addr
);
990 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
,
991 mcast_addr
, 0, MLX4_MCAST_CONFIG
);
993 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
994 0, MLX4_MCAST_ENABLE
);
996 en_err(priv
, "Failed enabling multicast filter\n");
998 update_mclist_flags(priv
, &priv
->curr_list
, &priv
->mc_list
);
999 list_for_each_entry_safe(mclist
, tmp
, &priv
->curr_list
, list
) {
1000 if (mclist
->action
== MCLIST_REM
) {
1001 /* detach this address and delete from list */
1002 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1003 mc_list
[5] = priv
->port
;
1004 err
= mlx4_multicast_detach(mdev
->dev
,
1005 &priv
->rss_map
.indir_qp
,
1010 en_err(priv
, "Fail to detach multicast address\n");
1012 if (mclist
->tunnel_reg_id
) {
1013 err
= mlx4_flow_detach(priv
->mdev
->dev
, mclist
->tunnel_reg_id
);
1015 en_err(priv
, "Failed to detach multicast address\n");
1018 /* remove from list */
1019 list_del(&mclist
->list
);
1021 } else if (mclist
->action
== MCLIST_ADD
) {
1022 /* attach the address */
1023 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1024 /* needed for B0 steering support */
1025 mc_list
[5] = priv
->port
;
1026 err
= mlx4_multicast_attach(mdev
->dev
,
1027 &priv
->rss_map
.indir_qp
,
1033 en_err(priv
, "Fail to attach multicast address\n");
1035 err
= mlx4_en_tunnel_steer_add(priv
, &mc_list
[10], priv
->base_qpn
,
1036 &mclist
->tunnel_reg_id
);
1038 en_err(priv
, "Failed to attach multicast address\n");
1044 static void mlx4_en_do_uc_filter(struct mlx4_en_priv
*priv
,
1045 struct net_device
*dev
,
1046 struct mlx4_en_dev
*mdev
)
1048 struct netdev_hw_addr
*ha
;
1049 struct mlx4_mac_entry
*entry
;
1050 struct hlist_node
*tmp
;
1054 struct hlist_head
*bucket
;
1059 /* Note that we do not need to protect our mac_hash traversal with rcu,
1060 * since all modification code is protected by mdev->state_lock
1063 /* find what to remove */
1064 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
) {
1065 bucket
= &priv
->mac_hash
[i
];
1066 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
1068 netdev_for_each_uc_addr(ha
, dev
) {
1069 if (ether_addr_equal_64bits(entry
->mac
,
1076 /* MAC address of the port is not in uc list */
1077 if (ether_addr_equal_64bits(entry
->mac
,
1082 mac
= mlx4_mac_to_u64(entry
->mac
);
1083 mlx4_en_uc_steer_release(priv
, entry
->mac
,
1086 mlx4_unregister_mac(mdev
->dev
, priv
->port
, mac
);
1088 hlist_del_rcu(&entry
->hlist
);
1089 kfree_rcu(entry
, rcu
);
1090 en_dbg(DRV
, priv
, "Removed MAC %pM on port:%d\n",
1091 entry
->mac
, priv
->port
);
1097 /* if we didn't remove anything, there is no use in trying to add
1098 * again once we are in a forced promisc mode state
1100 if ((priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
) && 0 == removed
)
1103 prev_flags
= priv
->flags
;
1104 priv
->flags
&= ~MLX4_EN_FLAG_FORCE_PROMISC
;
1106 /* find what to add */
1107 netdev_for_each_uc_addr(ha
, dev
) {
1109 bucket
= &priv
->mac_hash
[ha
->addr
[MLX4_EN_MAC_HASH_IDX
]];
1110 hlist_for_each_entry(entry
, bucket
, hlist
) {
1111 if (ether_addr_equal_64bits(entry
->mac
, ha
->addr
)) {
1118 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
1120 en_err(priv
, "Failed adding MAC %pM on port:%d (out of memory)\n",
1121 ha
->addr
, priv
->port
);
1122 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1125 mac
= mlx4_mac_to_u64(ha
->addr
);
1126 memcpy(entry
->mac
, ha
->addr
, ETH_ALEN
);
1127 err
= mlx4_register_mac(mdev
->dev
, priv
->port
, mac
);
1129 en_err(priv
, "Failed registering MAC %pM on port %d: %d\n",
1130 ha
->addr
, priv
->port
, err
);
1132 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1135 err
= mlx4_en_uc_steer_add(priv
, ha
->addr
,
1139 en_err(priv
, "Failed adding MAC %pM on port %d: %d\n",
1140 ha
->addr
, priv
->port
, err
);
1141 mlx4_unregister_mac(mdev
->dev
, priv
->port
, mac
);
1143 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1146 unsigned int mac_hash
;
1147 en_dbg(DRV
, priv
, "Added MAC %pM on port:%d\n",
1148 ha
->addr
, priv
->port
);
1149 mac_hash
= ha
->addr
[MLX4_EN_MAC_HASH_IDX
];
1150 bucket
= &priv
->mac_hash
[mac_hash
];
1151 hlist_add_head_rcu(&entry
->hlist
, bucket
);
1156 if (priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
) {
1157 en_warn(priv
, "Forcing promiscuous mode on port:%d\n",
1159 } else if (prev_flags
& MLX4_EN_FLAG_FORCE_PROMISC
) {
1160 en_warn(priv
, "Stop forcing promiscuous mode on port:%d\n",
1165 static void mlx4_en_do_set_rx_mode(struct work_struct
*work
)
1167 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1169 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1170 struct net_device
*dev
= priv
->dev
;
1172 mutex_lock(&mdev
->state_lock
);
1173 if (!mdev
->device_up
) {
1174 en_dbg(HW
, priv
, "Card is not up, ignoring rx mode change.\n");
1177 if (!priv
->port_up
) {
1178 en_dbg(HW
, priv
, "Port is down, ignoring rx mode change.\n");
1182 if (!netif_carrier_ok(dev
)) {
1183 if (!mlx4_en_QUERY_PORT(mdev
, priv
->port
)) {
1184 if (priv
->port_state
.link_state
) {
1185 priv
->last_link_state
= MLX4_DEV_EVENT_PORT_UP
;
1186 netif_carrier_on(dev
);
1187 en_dbg(LINK
, priv
, "Link Up\n");
1192 if (dev
->priv_flags
& IFF_UNICAST_FLT
)
1193 mlx4_en_do_uc_filter(priv
, dev
, mdev
);
1195 /* Promsicuous mode: disable all filters */
1196 if ((dev
->flags
& IFF_PROMISC
) ||
1197 (priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
)) {
1198 mlx4_en_set_promisc_mode(priv
, mdev
);
1202 /* Not in promiscuous mode */
1203 if (priv
->flags
& MLX4_EN_FLAG_PROMISC
)
1204 mlx4_en_clear_promisc_mode(priv
, mdev
);
1206 mlx4_en_do_multicast(priv
, dev
, mdev
);
1208 mutex_unlock(&mdev
->state_lock
);
1211 #ifdef CONFIG_NET_POLL_CONTROLLER
1212 static void mlx4_en_netpoll(struct net_device
*dev
)
1214 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1215 struct mlx4_en_cq
*cq
;
1218 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1219 cq
= priv
->rx_cq
[i
];
1220 napi_schedule(&cq
->napi
);
1225 static int mlx4_en_set_rss_steer_rules(struct mlx4_en_priv
*priv
)
1229 int *qpn
= &priv
->base_qpn
;
1230 struct mlx4_mac_entry
*entry
;
1232 err
= mlx4_en_uc_steer_add(priv
, priv
->dev
->dev_addr
, qpn
, ®_id
);
1236 err
= mlx4_en_tunnel_steer_add(priv
, priv
->dev
->dev_addr
, *qpn
,
1237 &priv
->tunnel_reg_id
);
1241 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
1247 memcpy(entry
->mac
, priv
->dev
->dev_addr
, sizeof(entry
->mac
));
1248 memcpy(priv
->current_mac
, entry
->mac
, sizeof(priv
->current_mac
));
1249 entry
->reg_id
= reg_id
;
1250 hlist_add_head_rcu(&entry
->hlist
,
1251 &priv
->mac_hash
[entry
->mac
[MLX4_EN_MAC_HASH_IDX
]]);
1256 if (priv
->tunnel_reg_id
)
1257 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
1260 mlx4_en_uc_steer_release(priv
, priv
->dev
->dev_addr
, *qpn
, reg_id
);
1264 static void mlx4_en_delete_rss_steer_rules(struct mlx4_en_priv
*priv
)
1268 int qpn
= priv
->base_qpn
;
1269 struct hlist_head
*bucket
;
1270 struct hlist_node
*tmp
;
1271 struct mlx4_mac_entry
*entry
;
1273 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
) {
1274 bucket
= &priv
->mac_hash
[i
];
1275 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
1276 mac
= mlx4_mac_to_u64(entry
->mac
);
1277 en_dbg(DRV
, priv
, "Registering MAC:%pM for deleting\n",
1279 mlx4_en_uc_steer_release(priv
, entry
->mac
,
1280 qpn
, entry
->reg_id
);
1282 mlx4_unregister_mac(priv
->mdev
->dev
, priv
->port
, mac
);
1283 hlist_del_rcu(&entry
->hlist
);
1284 kfree_rcu(entry
, rcu
);
1288 if (priv
->tunnel_reg_id
) {
1289 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
1290 priv
->tunnel_reg_id
= 0;
1294 static void mlx4_en_tx_timeout(struct net_device
*dev
)
1296 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1297 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1300 if (netif_msg_timer(priv
))
1301 en_warn(priv
, "Tx timeout called on port:%d\n", priv
->port
);
1303 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1304 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev
, i
)))
1306 en_warn(priv
, "TX timeout on queue: %d, QP: 0x%x, CQ: 0x%x, Cons: 0x%x, Prod: 0x%x\n",
1307 i
, priv
->tx_ring
[i
]->qpn
, priv
->tx_ring
[i
]->cqn
,
1308 priv
->tx_ring
[i
]->cons
, priv
->tx_ring
[i
]->prod
);
1311 priv
->port_stats
.tx_timeout
++;
1312 en_dbg(DRV
, priv
, "Scheduling watchdog\n");
1313 queue_work(mdev
->workqueue
, &priv
->watchdog_task
);
1317 static struct net_device_stats
*mlx4_en_get_stats(struct net_device
*dev
)
1319 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1321 spin_lock_bh(&priv
->stats_lock
);
1322 memcpy(&priv
->ret_stats
, &priv
->stats
, sizeof(priv
->stats
));
1323 spin_unlock_bh(&priv
->stats_lock
);
1325 return &priv
->ret_stats
;
1328 static void mlx4_en_set_default_moderation(struct mlx4_en_priv
*priv
)
1330 struct mlx4_en_cq
*cq
;
1333 /* If we haven't received a specific coalescing setting
1334 * (module param), we set the moderation parameters as follows:
1335 * - moder_cnt is set to the number of mtu sized packets to
1336 * satisfy our coalescing target.
1337 * - moder_time is set to a fixed value.
1339 priv
->rx_frames
= MLX4_EN_RX_COAL_TARGET
;
1340 priv
->rx_usecs
= MLX4_EN_RX_COAL_TIME
;
1341 priv
->tx_frames
= MLX4_EN_TX_COAL_PKTS
;
1342 priv
->tx_usecs
= MLX4_EN_TX_COAL_TIME
;
1343 en_dbg(INTR
, priv
, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n",
1344 priv
->dev
->mtu
, priv
->rx_frames
, priv
->rx_usecs
);
1346 /* Setup cq moderation params */
1347 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1348 cq
= priv
->rx_cq
[i
];
1349 cq
->moder_cnt
= priv
->rx_frames
;
1350 cq
->moder_time
= priv
->rx_usecs
;
1351 priv
->last_moder_time
[i
] = MLX4_EN_AUTO_CONF
;
1352 priv
->last_moder_packets
[i
] = 0;
1353 priv
->last_moder_bytes
[i
] = 0;
1356 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1357 cq
= priv
->tx_cq
[i
];
1358 cq
->moder_cnt
= priv
->tx_frames
;
1359 cq
->moder_time
= priv
->tx_usecs
;
1362 /* Reset auto-moderation params */
1363 priv
->pkt_rate_low
= MLX4_EN_RX_RATE_LOW
;
1364 priv
->rx_usecs_low
= MLX4_EN_RX_COAL_TIME_LOW
;
1365 priv
->pkt_rate_high
= MLX4_EN_RX_RATE_HIGH
;
1366 priv
->rx_usecs_high
= MLX4_EN_RX_COAL_TIME_HIGH
;
1367 priv
->sample_interval
= MLX4_EN_SAMPLE_INTERVAL
;
1368 priv
->adaptive_rx_coal
= 1;
1369 priv
->last_moder_jiffies
= 0;
1370 priv
->last_moder_tx_packets
= 0;
1373 static void mlx4_en_auto_moderation(struct mlx4_en_priv
*priv
)
1375 unsigned long period
= (unsigned long) (jiffies
- priv
->last_moder_jiffies
);
1376 struct mlx4_en_cq
*cq
;
1377 unsigned long packets
;
1379 unsigned long avg_pkt_size
;
1380 unsigned long rx_packets
;
1381 unsigned long rx_bytes
;
1382 unsigned long rx_pkt_diff
;
1386 if (!priv
->adaptive_rx_coal
|| period
< priv
->sample_interval
* HZ
)
1389 for (ring
= 0; ring
< priv
->rx_ring_num
; ring
++) {
1390 spin_lock_bh(&priv
->stats_lock
);
1391 rx_packets
= priv
->rx_ring
[ring
]->packets
;
1392 rx_bytes
= priv
->rx_ring
[ring
]->bytes
;
1393 spin_unlock_bh(&priv
->stats_lock
);
1395 rx_pkt_diff
= ((unsigned long) (rx_packets
-
1396 priv
->last_moder_packets
[ring
]));
1397 packets
= rx_pkt_diff
;
1398 rate
= packets
* HZ
/ period
;
1399 avg_pkt_size
= packets
? ((unsigned long) (rx_bytes
-
1400 priv
->last_moder_bytes
[ring
])) / packets
: 0;
1402 /* Apply auto-moderation only when packet rate
1403 * exceeds a rate that it matters */
1404 if (rate
> (MLX4_EN_RX_RATE_THRESH
/ priv
->rx_ring_num
) &&
1405 avg_pkt_size
> MLX4_EN_AVG_PKT_SMALL
) {
1406 if (rate
< priv
->pkt_rate_low
)
1407 moder_time
= priv
->rx_usecs_low
;
1408 else if (rate
> priv
->pkt_rate_high
)
1409 moder_time
= priv
->rx_usecs_high
;
1411 moder_time
= (rate
- priv
->pkt_rate_low
) *
1412 (priv
->rx_usecs_high
- priv
->rx_usecs_low
) /
1413 (priv
->pkt_rate_high
- priv
->pkt_rate_low
) +
1416 moder_time
= priv
->rx_usecs_low
;
1419 if (moder_time
!= priv
->last_moder_time
[ring
]) {
1420 priv
->last_moder_time
[ring
] = moder_time
;
1421 cq
= priv
->rx_cq
[ring
];
1422 cq
->moder_time
= moder_time
;
1423 cq
->moder_cnt
= priv
->rx_frames
;
1424 err
= mlx4_en_set_cq_moder(priv
, cq
);
1426 en_err(priv
, "Failed modifying moderation for cq:%d\n",
1429 priv
->last_moder_packets
[ring
] = rx_packets
;
1430 priv
->last_moder_bytes
[ring
] = rx_bytes
;
1433 priv
->last_moder_jiffies
= jiffies
;
1436 static void mlx4_en_do_get_stats(struct work_struct
*work
)
1438 struct delayed_work
*delay
= to_delayed_work(work
);
1439 struct mlx4_en_priv
*priv
= container_of(delay
, struct mlx4_en_priv
,
1441 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1444 mutex_lock(&mdev
->state_lock
);
1445 if (mdev
->device_up
) {
1446 if (priv
->port_up
) {
1447 err
= mlx4_en_DUMP_ETH_STATS(mdev
, priv
->port
, 0);
1449 en_dbg(HW
, priv
, "Could not update stats\n");
1451 mlx4_en_auto_moderation(priv
);
1454 queue_delayed_work(mdev
->workqueue
, &priv
->stats_task
, STATS_DELAY
);
1456 if (mdev
->mac_removed
[MLX4_MAX_PORTS
+ 1 - priv
->port
]) {
1457 mlx4_en_do_set_mac(priv
, priv
->current_mac
);
1458 mdev
->mac_removed
[MLX4_MAX_PORTS
+ 1 - priv
->port
] = 0;
1460 mutex_unlock(&mdev
->state_lock
);
1463 /* mlx4_en_service_task - Run service task for tasks that needed to be done
1466 static void mlx4_en_service_task(struct work_struct
*work
)
1468 struct delayed_work
*delay
= to_delayed_work(work
);
1469 struct mlx4_en_priv
*priv
= container_of(delay
, struct mlx4_en_priv
,
1471 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1473 mutex_lock(&mdev
->state_lock
);
1474 if (mdev
->device_up
) {
1475 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
)
1476 mlx4_en_ptp_overflow_check(mdev
);
1478 mlx4_en_recover_from_oom(priv
);
1479 queue_delayed_work(mdev
->workqueue
, &priv
->service_task
,
1480 SERVICE_TASK_DELAY
);
1482 mutex_unlock(&mdev
->state_lock
);
1485 static void mlx4_en_linkstate(struct work_struct
*work
)
1487 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1489 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1490 int linkstate
= priv
->link_state
;
1492 mutex_lock(&mdev
->state_lock
);
1493 /* If observable port state changed set carrier state and
1494 * report to system log */
1495 if (priv
->last_link_state
!= linkstate
) {
1496 if (linkstate
== MLX4_DEV_EVENT_PORT_DOWN
) {
1497 en_info(priv
, "Link Down\n");
1498 netif_carrier_off(priv
->dev
);
1500 en_info(priv
, "Link Up\n");
1501 netif_carrier_on(priv
->dev
);
1504 priv
->last_link_state
= linkstate
;
1505 mutex_unlock(&mdev
->state_lock
);
1508 static int mlx4_en_init_affinity_hint(struct mlx4_en_priv
*priv
, int ring_idx
)
1510 struct mlx4_en_rx_ring
*ring
= priv
->rx_ring
[ring_idx
];
1511 int numa_node
= priv
->mdev
->dev
->numa_node
;
1513 if (!zalloc_cpumask_var(&ring
->affinity_mask
, GFP_KERNEL
))
1516 cpumask_set_cpu(cpumask_local_spread(ring_idx
, numa_node
),
1517 ring
->affinity_mask
);
1521 static void mlx4_en_free_affinity_hint(struct mlx4_en_priv
*priv
, int ring_idx
)
1523 free_cpumask_var(priv
->rx_ring
[ring_idx
]->affinity_mask
);
1526 int mlx4_en_start_port(struct net_device
*dev
)
1528 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1529 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1530 struct mlx4_en_cq
*cq
;
1531 struct mlx4_en_tx_ring
*tx_ring
;
1537 u8 mc_list
[16] = {0};
1539 if (priv
->port_up
) {
1540 en_dbg(DRV
, priv
, "start port called while port already up\n");
1544 INIT_LIST_HEAD(&priv
->mc_list
);
1545 INIT_LIST_HEAD(&priv
->curr_list
);
1546 INIT_LIST_HEAD(&priv
->ethtool_list
);
1547 memset(&priv
->ethtool_rules
[0], 0,
1548 sizeof(struct ethtool_flow_id
) * MAX_NUM_OF_FS_RULES
);
1550 /* Calculate Rx buf size */
1551 dev
->mtu
= min(dev
->mtu
, priv
->max_mtu
);
1552 mlx4_en_calc_rx_buf(dev
);
1553 en_dbg(DRV
, priv
, "Rx buf size:%d\n", priv
->rx_skb_size
);
1555 /* Configure rx cq's and rings */
1556 err
= mlx4_en_activate_rx_rings(priv
);
1558 en_err(priv
, "Failed to activate RX rings\n");
1561 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1562 cq
= priv
->rx_cq
[i
];
1564 mlx4_en_cq_init_lock(cq
);
1566 err
= mlx4_en_init_affinity_hint(priv
, i
);
1568 en_err(priv
, "Failed preparing IRQ affinity hint\n");
1572 err
= mlx4_en_activate_cq(priv
, cq
, i
);
1574 en_err(priv
, "Failed activating Rx CQ\n");
1575 mlx4_en_free_affinity_hint(priv
, i
);
1579 for (j
= 0; j
< cq
->size
; j
++) {
1580 struct mlx4_cqe
*cqe
= NULL
;
1582 cqe
= mlx4_en_get_cqe(cq
->buf
, j
, priv
->cqe_size
) +
1584 cqe
->owner_sr_opcode
= MLX4_CQE_OWNER_MASK
;
1587 err
= mlx4_en_set_cq_moder(priv
, cq
);
1589 en_err(priv
, "Failed setting cq moderation parameters\n");
1590 mlx4_en_deactivate_cq(priv
, cq
);
1591 mlx4_en_free_affinity_hint(priv
, i
);
1594 mlx4_en_arm_cq(priv
, cq
);
1595 priv
->rx_ring
[i
]->cqn
= cq
->mcq
.cqn
;
1600 en_dbg(DRV
, priv
, "Getting qp number for port %d\n", priv
->port
);
1601 err
= mlx4_en_get_qp(priv
);
1603 en_err(priv
, "Failed getting eth qp\n");
1606 mdev
->mac_removed
[priv
->port
] = 0;
1608 priv
->counter_index
=
1609 mlx4_get_default_counter_index(mdev
->dev
, priv
->port
);
1611 err
= mlx4_en_config_rss_steer(priv
);
1613 en_err(priv
, "Failed configuring rss steering\n");
1617 err
= mlx4_en_create_drop_qp(priv
);
1621 /* Configure tx cq's and rings */
1622 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1624 cq
= priv
->tx_cq
[i
];
1625 err
= mlx4_en_activate_cq(priv
, cq
, i
);
1627 en_err(priv
, "Failed allocating Tx CQ\n");
1630 err
= mlx4_en_set_cq_moder(priv
, cq
);
1632 en_err(priv
, "Failed setting cq moderation parameters\n");
1633 mlx4_en_deactivate_cq(priv
, cq
);
1636 en_dbg(DRV
, priv
, "Resetting index of collapsed CQ:%d to -1\n", i
);
1637 cq
->buf
->wqe_index
= cpu_to_be16(0xffff);
1639 /* Configure ring */
1640 tx_ring
= priv
->tx_ring
[i
];
1641 err
= mlx4_en_activate_tx_ring(priv
, tx_ring
, cq
->mcq
.cqn
,
1642 i
/ priv
->num_tx_rings_p_up
);
1644 en_err(priv
, "Failed allocating Tx ring\n");
1645 mlx4_en_deactivate_cq(priv
, cq
);
1648 tx_ring
->tx_queue
= netdev_get_tx_queue(dev
, i
);
1650 /* Arm CQ for TX completions */
1651 mlx4_en_arm_cq(priv
, cq
);
1653 /* Set initial ownership of all Tx TXBBs to SW (1) */
1654 for (j
= 0; j
< tx_ring
->buf_size
; j
+= STAMP_STRIDE
)
1655 *((u32
*) (tx_ring
->buf
+ j
)) = 0xffffffff;
1659 /* Configure port */
1660 err
= mlx4_SET_PORT_general(mdev
->dev
, priv
->port
,
1661 priv
->rx_skb_size
+ ETH_FCS_LEN
,
1662 priv
->prof
->tx_pause
,
1664 priv
->prof
->rx_pause
,
1665 priv
->prof
->rx_ppp
);
1667 en_err(priv
, "Failed setting port general configurations for port %d, with error %d\n",
1671 /* Set default qp number */
1672 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
, priv
->port
, priv
->base_qpn
, 0);
1674 en_err(priv
, "Failed setting default qp numbers\n");
1678 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
1679 err
= mlx4_SET_PORT_VXLAN(mdev
->dev
, priv
->port
, VXLAN_STEER_BY_OUTER_MAC
, 1);
1681 en_err(priv
, "Failed setting port L2 tunnel configuration, err %d\n",
1688 en_dbg(HW
, priv
, "Initializing port\n");
1689 err
= mlx4_INIT_PORT(mdev
->dev
, priv
->port
);
1691 en_err(priv
, "Failed Initializing port\n");
1695 /* Set Unicast and VXLAN steering rules */
1696 if (mdev
->dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
&&
1697 mlx4_en_set_rss_steer_rules(priv
))
1698 mlx4_warn(mdev
, "Failed setting steering rules\n");
1700 /* Attach rx QP to bradcast address */
1701 eth_broadcast_addr(&mc_list
[10]);
1702 mc_list
[5] = priv
->port
; /* needed for B0 steering support */
1703 if (mlx4_multicast_attach(mdev
->dev
, &priv
->rss_map
.indir_qp
, mc_list
,
1704 priv
->port
, 0, MLX4_PROT_ETH
,
1705 &priv
->broadcast_id
))
1706 mlx4_warn(mdev
, "Failed Attaching Broadcast\n");
1708 /* Must redo promiscuous mode setup. */
1709 priv
->flags
&= ~(MLX4_EN_FLAG_PROMISC
| MLX4_EN_FLAG_MC_PROMISC
);
1711 /* Schedule multicast task to populate multicast list */
1712 queue_work(mdev
->workqueue
, &priv
->rx_mode_task
);
1714 #ifdef CONFIG_MLX4_EN_VXLAN
1715 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
1716 vxlan_get_rx_port(dev
);
1718 priv
->port_up
= true;
1719 netif_tx_start_all_queues(dev
);
1720 netif_device_attach(dev
);
1725 while (tx_index
--) {
1726 mlx4_en_deactivate_tx_ring(priv
, priv
->tx_ring
[tx_index
]);
1727 mlx4_en_deactivate_cq(priv
, priv
->tx_cq
[tx_index
]);
1729 mlx4_en_destroy_drop_qp(priv
);
1731 mlx4_en_release_rss_steer(priv
);
1733 mlx4_en_put_qp(priv
);
1735 while (rx_index
--) {
1736 mlx4_en_deactivate_cq(priv
, priv
->rx_cq
[rx_index
]);
1737 mlx4_en_free_affinity_hint(priv
, rx_index
);
1739 for (i
= 0; i
< priv
->rx_ring_num
; i
++)
1740 mlx4_en_deactivate_rx_ring(priv
, priv
->rx_ring
[i
]);
1742 return err
; /* need to close devices */
1746 void mlx4_en_stop_port(struct net_device
*dev
, int detach
)
1748 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1749 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1750 struct mlx4_en_mc_list
*mclist
, *tmp
;
1751 struct ethtool_flow_id
*flow
, *tmp_flow
;
1753 u8 mc_list
[16] = {0};
1755 if (!priv
->port_up
) {
1756 en_dbg(DRV
, priv
, "stop port called while port already down\n");
1761 mlx4_CLOSE_PORT(mdev
->dev
, priv
->port
);
1763 /* Synchronize with tx routine */
1764 netif_tx_lock_bh(dev
);
1766 netif_device_detach(dev
);
1767 netif_tx_stop_all_queues(dev
);
1768 netif_tx_unlock_bh(dev
);
1770 netif_tx_disable(dev
);
1772 /* Set port as not active */
1773 priv
->port_up
= false;
1774 priv
->counter_index
= MLX4_SINK_COUNTER_INDEX(mdev
->dev
);
1776 /* Promsicuous mode */
1777 if (mdev
->dev
->caps
.steering_mode
==
1778 MLX4_STEERING_MODE_DEVICE_MANAGED
) {
1779 priv
->flags
&= ~(MLX4_EN_FLAG_PROMISC
|
1780 MLX4_EN_FLAG_MC_PROMISC
);
1781 mlx4_flow_steer_promisc_remove(mdev
->dev
,
1783 MLX4_FS_ALL_DEFAULT
);
1784 mlx4_flow_steer_promisc_remove(mdev
->dev
,
1786 MLX4_FS_MC_DEFAULT
);
1787 } else if (priv
->flags
& MLX4_EN_FLAG_PROMISC
) {
1788 priv
->flags
&= ~MLX4_EN_FLAG_PROMISC
;
1790 /* Disable promiscouos mode */
1791 mlx4_unicast_promisc_remove(mdev
->dev
, priv
->base_qpn
,
1794 /* Disable Multicast promisc */
1795 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
1796 mlx4_multicast_promisc_remove(mdev
->dev
, priv
->base_qpn
,
1798 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
1802 /* Detach All multicasts */
1803 eth_broadcast_addr(&mc_list
[10]);
1804 mc_list
[5] = priv
->port
; /* needed for B0 steering support */
1805 mlx4_multicast_detach(mdev
->dev
, &priv
->rss_map
.indir_qp
, mc_list
,
1806 MLX4_PROT_ETH
, priv
->broadcast_id
);
1807 list_for_each_entry(mclist
, &priv
->curr_list
, list
) {
1808 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1809 mc_list
[5] = priv
->port
;
1810 mlx4_multicast_detach(mdev
->dev
, &priv
->rss_map
.indir_qp
,
1811 mc_list
, MLX4_PROT_ETH
, mclist
->reg_id
);
1812 if (mclist
->tunnel_reg_id
)
1813 mlx4_flow_detach(mdev
->dev
, mclist
->tunnel_reg_id
);
1815 mlx4_en_clear_list(dev
);
1816 list_for_each_entry_safe(mclist
, tmp
, &priv
->curr_list
, list
) {
1817 list_del(&mclist
->list
);
1821 /* Flush multicast filter */
1822 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0, 1, MLX4_MCAST_CONFIG
);
1824 /* Remove flow steering rules for the port*/
1825 if (mdev
->dev
->caps
.steering_mode
==
1826 MLX4_STEERING_MODE_DEVICE_MANAGED
) {
1828 list_for_each_entry_safe(flow
, tmp_flow
,
1829 &priv
->ethtool_list
, list
) {
1830 mlx4_flow_detach(mdev
->dev
, flow
->id
);
1831 list_del(&flow
->list
);
1835 mlx4_en_destroy_drop_qp(priv
);
1838 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1839 mlx4_en_deactivate_tx_ring(priv
, priv
->tx_ring
[i
]);
1840 mlx4_en_deactivate_cq(priv
, priv
->tx_cq
[i
]);
1844 for (i
= 0; i
< priv
->tx_ring_num
; i
++)
1845 mlx4_en_free_tx_buf(dev
, priv
->tx_ring
[i
]);
1847 if (mdev
->dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
)
1848 mlx4_en_delete_rss_steer_rules(priv
);
1851 mlx4_en_release_rss_steer(priv
);
1853 /* Unregister Mac address for the port */
1854 mlx4_en_put_qp(priv
);
1855 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN
))
1856 mdev
->mac_removed
[priv
->port
] = 1;
1859 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1860 struct mlx4_en_cq
*cq
= priv
->rx_cq
[i
];
1863 while (!mlx4_en_cq_lock_napi(cq
)) {
1864 pr_info("CQ %d locked\n", i
);
1869 napi_synchronize(&cq
->napi
);
1870 mlx4_en_deactivate_rx_ring(priv
, priv
->rx_ring
[i
]);
1871 mlx4_en_deactivate_cq(priv
, cq
);
1873 mlx4_en_free_affinity_hint(priv
, i
);
1877 static void mlx4_en_restart(struct work_struct
*work
)
1879 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1881 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1882 struct net_device
*dev
= priv
->dev
;
1884 en_dbg(DRV
, priv
, "Watchdog task called for port %d\n", priv
->port
);
1886 mutex_lock(&mdev
->state_lock
);
1887 if (priv
->port_up
) {
1888 mlx4_en_stop_port(dev
, 1);
1889 if (mlx4_en_start_port(dev
))
1890 en_err(priv
, "Failed restarting port %d\n", priv
->port
);
1892 mutex_unlock(&mdev
->state_lock
);
1895 static void mlx4_en_clear_stats(struct net_device
*dev
)
1897 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1898 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1901 if (mlx4_en_DUMP_ETH_STATS(mdev
, priv
->port
, 1))
1902 en_dbg(HW
, priv
, "Failed dumping statistics\n");
1904 memset(&priv
->stats
, 0, sizeof(priv
->stats
));
1905 memset(&priv
->pstats
, 0, sizeof(priv
->pstats
));
1906 memset(&priv
->pkstats
, 0, sizeof(priv
->pkstats
));
1907 memset(&priv
->port_stats
, 0, sizeof(priv
->port_stats
));
1908 memset(&priv
->rx_flowstats
, 0, sizeof(priv
->rx_flowstats
));
1909 memset(&priv
->tx_flowstats
, 0, sizeof(priv
->tx_flowstats
));
1910 memset(&priv
->rx_priority_flowstats
, 0,
1911 sizeof(priv
->rx_priority_flowstats
));
1912 memset(&priv
->tx_priority_flowstats
, 0,
1913 sizeof(priv
->tx_priority_flowstats
));
1914 memset(&priv
->pf_stats
, 0, sizeof(priv
->pf_stats
));
1916 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1917 priv
->tx_ring
[i
]->bytes
= 0;
1918 priv
->tx_ring
[i
]->packets
= 0;
1919 priv
->tx_ring
[i
]->tx_csum
= 0;
1921 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1922 priv
->rx_ring
[i
]->bytes
= 0;
1923 priv
->rx_ring
[i
]->packets
= 0;
1924 priv
->rx_ring
[i
]->csum_ok
= 0;
1925 priv
->rx_ring
[i
]->csum_none
= 0;
1926 priv
->rx_ring
[i
]->csum_complete
= 0;
1930 static int mlx4_en_open(struct net_device
*dev
)
1932 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1933 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1936 mutex_lock(&mdev
->state_lock
);
1938 if (!mdev
->device_up
) {
1939 en_err(priv
, "Cannot open - device down/disabled\n");
1944 /* Reset HW statistics and SW counters */
1945 mlx4_en_clear_stats(dev
);
1947 err
= mlx4_en_start_port(dev
);
1949 en_err(priv
, "Failed starting port:%d\n", priv
->port
);
1952 mutex_unlock(&mdev
->state_lock
);
1957 static int mlx4_en_close(struct net_device
*dev
)
1959 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1960 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1962 en_dbg(IFDOWN
, priv
, "Close port called\n");
1964 mutex_lock(&mdev
->state_lock
);
1966 mlx4_en_stop_port(dev
, 0);
1967 netif_carrier_off(dev
);
1969 mutex_unlock(&mdev
->state_lock
);
1973 void mlx4_en_free_resources(struct mlx4_en_priv
*priv
)
1977 #ifdef CONFIG_RFS_ACCEL
1978 priv
->dev
->rx_cpu_rmap
= NULL
;
1981 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1982 if (priv
->tx_ring
&& priv
->tx_ring
[i
])
1983 mlx4_en_destroy_tx_ring(priv
, &priv
->tx_ring
[i
]);
1984 if (priv
->tx_cq
&& priv
->tx_cq
[i
])
1985 mlx4_en_destroy_cq(priv
, &priv
->tx_cq
[i
]);
1988 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1989 if (priv
->rx_ring
[i
])
1990 mlx4_en_destroy_rx_ring(priv
, &priv
->rx_ring
[i
],
1991 priv
->prof
->rx_ring_size
, priv
->stride
);
1993 mlx4_en_destroy_cq(priv
, &priv
->rx_cq
[i
]);
1998 int mlx4_en_alloc_resources(struct mlx4_en_priv
*priv
)
2000 struct mlx4_en_port_profile
*prof
= priv
->prof
;
2004 /* Create tx Rings */
2005 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
2006 node
= cpu_to_node(i
% num_online_cpus());
2007 if (mlx4_en_create_cq(priv
, &priv
->tx_cq
[i
],
2008 prof
->tx_ring_size
, i
, TX
, node
))
2011 if (mlx4_en_create_tx_ring(priv
, &priv
->tx_ring
[i
],
2012 prof
->tx_ring_size
, TXBB_SIZE
,
2017 /* Create rx Rings */
2018 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2019 node
= cpu_to_node(i
% num_online_cpus());
2020 if (mlx4_en_create_cq(priv
, &priv
->rx_cq
[i
],
2021 prof
->rx_ring_size
, i
, RX
, node
))
2024 if (mlx4_en_create_rx_ring(priv
, &priv
->rx_ring
[i
],
2025 prof
->rx_ring_size
, priv
->stride
,
2030 #ifdef CONFIG_RFS_ACCEL
2031 priv
->dev
->rx_cpu_rmap
= mlx4_get_cpu_rmap(priv
->mdev
->dev
, priv
->port
);
2037 en_err(priv
, "Failed to allocate NIC resources\n");
2038 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2039 if (priv
->rx_ring
[i
])
2040 mlx4_en_destroy_rx_ring(priv
, &priv
->rx_ring
[i
],
2044 mlx4_en_destroy_cq(priv
, &priv
->rx_cq
[i
]);
2046 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
2047 if (priv
->tx_ring
[i
])
2048 mlx4_en_destroy_tx_ring(priv
, &priv
->tx_ring
[i
]);
2050 mlx4_en_destroy_cq(priv
, &priv
->tx_cq
[i
]);
2056 void mlx4_en_destroy_netdev(struct net_device
*dev
)
2058 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2059 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2061 en_dbg(DRV
, priv
, "Destroying netdev on port:%d\n", priv
->port
);
2063 /* Unregister device - this will close the port if it was up */
2064 if (priv
->registered
)
2065 unregister_netdev(dev
);
2067 if (priv
->allocated
)
2068 mlx4_free_hwq_res(mdev
->dev
, &priv
->res
, MLX4_EN_PAGE_SIZE
);
2070 cancel_delayed_work(&priv
->stats_task
);
2071 cancel_delayed_work(&priv
->service_task
);
2072 /* flush any pending task for this netdev */
2073 flush_workqueue(mdev
->workqueue
);
2075 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
)
2076 mlx4_en_remove_timestamp(mdev
);
2078 /* Detach the netdev so tasks would not attempt to access it */
2079 mutex_lock(&mdev
->state_lock
);
2080 mdev
->pndev
[priv
->port
] = NULL
;
2081 mdev
->upper
[priv
->port
] = NULL
;
2082 mutex_unlock(&mdev
->state_lock
);
2084 mlx4_en_free_resources(priv
);
2086 kfree(priv
->tx_ring
);
2092 static int mlx4_en_change_mtu(struct net_device
*dev
, int new_mtu
)
2094 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2095 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2098 en_dbg(DRV
, priv
, "Change MTU called - current:%d new:%d\n",
2101 if ((new_mtu
< MLX4_EN_MIN_MTU
) || (new_mtu
> priv
->max_mtu
)) {
2102 en_err(priv
, "Bad MTU size:%d.\n", new_mtu
);
2107 if (netif_running(dev
)) {
2108 mutex_lock(&mdev
->state_lock
);
2109 if (!mdev
->device_up
) {
2110 /* NIC is probably restarting - let watchdog task reset
2112 en_dbg(DRV
, priv
, "Change MTU called with card down!?\n");
2114 mlx4_en_stop_port(dev
, 1);
2115 err
= mlx4_en_start_port(dev
);
2117 en_err(priv
, "Failed restarting port:%d\n",
2119 queue_work(mdev
->workqueue
, &priv
->watchdog_task
);
2122 mutex_unlock(&mdev
->state_lock
);
2127 static int mlx4_en_hwtstamp_set(struct net_device
*dev
, struct ifreq
*ifr
)
2129 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2130 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2131 struct hwtstamp_config config
;
2133 if (copy_from_user(&config
, ifr
->ifr_data
, sizeof(config
)))
2136 /* reserved for future extensions */
2140 /* device doesn't support time stamping */
2141 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
))
2144 /* TX HW timestamp */
2145 switch (config
.tx_type
) {
2146 case HWTSTAMP_TX_OFF
:
2147 case HWTSTAMP_TX_ON
:
2153 /* RX HW timestamp */
2154 switch (config
.rx_filter
) {
2155 case HWTSTAMP_FILTER_NONE
:
2157 case HWTSTAMP_FILTER_ALL
:
2158 case HWTSTAMP_FILTER_SOME
:
2159 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT
:
2160 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC
:
2161 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
:
2162 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT
:
2163 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC
:
2164 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
:
2165 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT
:
2166 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC
:
2167 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
:
2168 case HWTSTAMP_FILTER_PTP_V2_EVENT
:
2169 case HWTSTAMP_FILTER_PTP_V2_SYNC
:
2170 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
:
2171 config
.rx_filter
= HWTSTAMP_FILTER_ALL
;
2177 if (mlx4_en_reset_config(dev
, config
, dev
->features
)) {
2178 config
.tx_type
= HWTSTAMP_TX_OFF
;
2179 config
.rx_filter
= HWTSTAMP_FILTER_NONE
;
2182 return copy_to_user(ifr
->ifr_data
, &config
,
2183 sizeof(config
)) ? -EFAULT
: 0;
2186 static int mlx4_en_hwtstamp_get(struct net_device
*dev
, struct ifreq
*ifr
)
2188 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2190 return copy_to_user(ifr
->ifr_data
, &priv
->hwtstamp_config
,
2191 sizeof(priv
->hwtstamp_config
)) ? -EFAULT
: 0;
2194 static int mlx4_en_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
2198 return mlx4_en_hwtstamp_set(dev
, ifr
);
2200 return mlx4_en_hwtstamp_get(dev
, ifr
);
2206 static netdev_features_t
mlx4_en_fix_features(struct net_device
*netdev
,
2207 netdev_features_t features
)
2209 struct mlx4_en_priv
*en_priv
= netdev_priv(netdev
);
2210 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2212 /* Since there is no support for separate RX C-TAG/S-TAG vlan accel
2213 * enable/disable make sure S-TAG flag is always in same state as
2216 if (features
& NETIF_F_HW_VLAN_CTAG_RX
&&
2217 !(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN
))
2218 features
|= NETIF_F_HW_VLAN_STAG_RX
;
2220 features
&= ~NETIF_F_HW_VLAN_STAG_RX
;
2225 static int mlx4_en_set_features(struct net_device
*netdev
,
2226 netdev_features_t features
)
2228 struct mlx4_en_priv
*priv
= netdev_priv(netdev
);
2232 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_RXFCS
)) {
2233 en_info(priv
, "Turn %s RX-FCS\n",
2234 (features
& NETIF_F_RXFCS
) ? "ON" : "OFF");
2238 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_RXALL
)) {
2239 u8 ignore_fcs_value
= (features
& NETIF_F_RXALL
) ? 1 : 0;
2241 en_info(priv
, "Turn %s RX-ALL\n",
2242 ignore_fcs_value
? "ON" : "OFF");
2243 ret
= mlx4_SET_PORT_fcs_check(priv
->mdev
->dev
,
2244 priv
->port
, ignore_fcs_value
);
2249 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_HW_VLAN_CTAG_RX
)) {
2250 en_info(priv
, "Turn %s RX vlan strip offload\n",
2251 (features
& NETIF_F_HW_VLAN_CTAG_RX
) ? "ON" : "OFF");
2255 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_HW_VLAN_CTAG_TX
))
2256 en_info(priv
, "Turn %s TX vlan strip offload\n",
2257 (features
& NETIF_F_HW_VLAN_CTAG_TX
) ? "ON" : "OFF");
2259 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_HW_VLAN_STAG_TX
))
2260 en_info(priv
, "Turn %s TX S-VLAN strip offload\n",
2261 (features
& NETIF_F_HW_VLAN_STAG_TX
) ? "ON" : "OFF");
2263 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_LOOPBACK
)) {
2264 en_info(priv
, "Turn %s loopback\n",
2265 (features
& NETIF_F_LOOPBACK
) ? "ON" : "OFF");
2266 mlx4_en_update_loopback_state(netdev
, features
);
2270 ret
= mlx4_en_reset_config(netdev
, priv
->hwtstamp_config
,
2279 static int mlx4_en_set_vf_mac(struct net_device
*dev
, int queue
, u8
*mac
)
2281 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2282 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2283 u64 mac_u64
= mlx4_mac_to_u64(mac
);
2285 if (!is_valid_ether_addr(mac
))
2288 return mlx4_set_vf_mac(mdev
->dev
, en_priv
->port
, queue
, mac_u64
);
2291 static int mlx4_en_set_vf_vlan(struct net_device
*dev
, int vf
, u16 vlan
, u8 qos
)
2293 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2294 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2296 return mlx4_set_vf_vlan(mdev
->dev
, en_priv
->port
, vf
, vlan
, qos
);
2299 static int mlx4_en_set_vf_rate(struct net_device
*dev
, int vf
, int min_tx_rate
,
2302 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2303 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2305 return mlx4_set_vf_rate(mdev
->dev
, en_priv
->port
, vf
, min_tx_rate
,
2309 static int mlx4_en_set_vf_spoofchk(struct net_device
*dev
, int vf
, bool setting
)
2311 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2312 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2314 return mlx4_set_vf_spoofchk(mdev
->dev
, en_priv
->port
, vf
, setting
);
2317 static int mlx4_en_get_vf_config(struct net_device
*dev
, int vf
, struct ifla_vf_info
*ivf
)
2319 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2320 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2322 return mlx4_get_vf_config(mdev
->dev
, en_priv
->port
, vf
, ivf
);
2325 static int mlx4_en_set_vf_link_state(struct net_device
*dev
, int vf
, int link_state
)
2327 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2328 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2330 return mlx4_set_vf_link_state(mdev
->dev
, en_priv
->port
, vf
, link_state
);
2333 static int mlx4_en_get_vf_stats(struct net_device
*dev
, int vf
,
2334 struct ifla_vf_stats
*vf_stats
)
2336 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2337 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2339 return mlx4_get_vf_stats(mdev
->dev
, en_priv
->port
, vf
, vf_stats
);
2342 #define PORT_ID_BYTE_LEN 8
2343 static int mlx4_en_get_phys_port_id(struct net_device
*dev
,
2344 struct netdev_phys_item_id
*ppid
)
2346 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2347 struct mlx4_dev
*mdev
= priv
->mdev
->dev
;
2349 u64 phys_port_id
= mdev
->caps
.phys_port_id
[priv
->port
];
2354 ppid
->id_len
= sizeof(phys_port_id
);
2355 for (i
= PORT_ID_BYTE_LEN
- 1; i
>= 0; --i
) {
2356 ppid
->id
[i
] = phys_port_id
& 0xff;
2362 #ifdef CONFIG_MLX4_EN_VXLAN
2363 static void mlx4_en_add_vxlan_offloads(struct work_struct
*work
)
2366 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
2369 ret
= mlx4_config_vxlan_port(priv
->mdev
->dev
, priv
->vxlan_port
);
2373 ret
= mlx4_SET_PORT_VXLAN(priv
->mdev
->dev
, priv
->port
,
2374 VXLAN_STEER_BY_OUTER_MAC
, 1);
2377 en_err(priv
, "failed setting L2 tunnel configuration ret %d\n", ret
);
2382 priv
->dev
->hw_enc_features
|= NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
2383 NETIF_F_TSO
| NETIF_F_GSO_UDP_TUNNEL
;
2384 priv
->dev
->hw_features
|= NETIF_F_GSO_UDP_TUNNEL
;
2385 priv
->dev
->features
|= NETIF_F_GSO_UDP_TUNNEL
;
2388 static void mlx4_en_del_vxlan_offloads(struct work_struct
*work
)
2391 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
2393 /* unset offloads */
2394 priv
->dev
->hw_enc_features
&= ~(NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
2395 NETIF_F_TSO
| NETIF_F_GSO_UDP_TUNNEL
);
2396 priv
->dev
->hw_features
&= ~NETIF_F_GSO_UDP_TUNNEL
;
2397 priv
->dev
->features
&= ~NETIF_F_GSO_UDP_TUNNEL
;
2399 ret
= mlx4_SET_PORT_VXLAN(priv
->mdev
->dev
, priv
->port
,
2400 VXLAN_STEER_BY_OUTER_MAC
, 0);
2402 en_err(priv
, "failed setting L2 tunnel configuration ret %d\n", ret
);
2404 priv
->vxlan_port
= 0;
2407 static void mlx4_en_add_vxlan_port(struct net_device
*dev
,
2408 sa_family_t sa_family
, __be16 port
)
2410 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2411 __be16 current_port
;
2413 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
2416 if (sa_family
== AF_INET6
)
2419 current_port
= priv
->vxlan_port
;
2420 if (current_port
&& current_port
!= port
) {
2421 en_warn(priv
, "vxlan port %d configured, can't add port %d\n",
2422 ntohs(current_port
), ntohs(port
));
2426 priv
->vxlan_port
= port
;
2427 queue_work(priv
->mdev
->workqueue
, &priv
->vxlan_add_task
);
2430 static void mlx4_en_del_vxlan_port(struct net_device
*dev
,
2431 sa_family_t sa_family
, __be16 port
)
2433 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2434 __be16 current_port
;
2436 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
2439 if (sa_family
== AF_INET6
)
2442 current_port
= priv
->vxlan_port
;
2443 if (current_port
!= port
) {
2444 en_dbg(DRV
, priv
, "vxlan port %d isn't configured, ignoring\n", ntohs(port
));
2448 queue_work(priv
->mdev
->workqueue
, &priv
->vxlan_del_task
);
2451 static netdev_features_t
mlx4_en_features_check(struct sk_buff
*skb
,
2452 struct net_device
*dev
,
2453 netdev_features_t features
)
2455 features
= vlan_features_check(skb
, features
);
2456 return vxlan_features_check(skb
, features
);
2460 static int mlx4_en_set_tx_maxrate(struct net_device
*dev
, int queue_index
, u32 maxrate
)
2462 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2463 struct mlx4_en_tx_ring
*tx_ring
= priv
->tx_ring
[queue_index
];
2464 struct mlx4_update_qp_params params
;
2467 if (!(priv
->mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT
))
2470 /* rate provided to us in Mbs, check if it fits into 12 bits, if not use Gbs */
2471 if (maxrate
>> 12) {
2472 params
.rate_unit
= MLX4_QP_RATE_LIMIT_GBS
;
2473 params
.rate_val
= maxrate
/ 1000;
2474 } else if (maxrate
) {
2475 params
.rate_unit
= MLX4_QP_RATE_LIMIT_MBS
;
2476 params
.rate_val
= maxrate
;
2477 } else { /* zero serves to revoke the QP rate-limitation */
2478 params
.rate_unit
= 0;
2479 params
.rate_val
= 0;
2482 err
= mlx4_update_qp(priv
->mdev
->dev
, tx_ring
->qpn
, MLX4_UPDATE_QP_RATE_LIMIT
,
2487 static const struct net_device_ops mlx4_netdev_ops
= {
2488 .ndo_open
= mlx4_en_open
,
2489 .ndo_stop
= mlx4_en_close
,
2490 .ndo_start_xmit
= mlx4_en_xmit
,
2491 .ndo_select_queue
= mlx4_en_select_queue
,
2492 .ndo_get_stats
= mlx4_en_get_stats
,
2493 .ndo_set_rx_mode
= mlx4_en_set_rx_mode
,
2494 .ndo_set_mac_address
= mlx4_en_set_mac
,
2495 .ndo_validate_addr
= eth_validate_addr
,
2496 .ndo_change_mtu
= mlx4_en_change_mtu
,
2497 .ndo_do_ioctl
= mlx4_en_ioctl
,
2498 .ndo_tx_timeout
= mlx4_en_tx_timeout
,
2499 .ndo_vlan_rx_add_vid
= mlx4_en_vlan_rx_add_vid
,
2500 .ndo_vlan_rx_kill_vid
= mlx4_en_vlan_rx_kill_vid
,
2501 #ifdef CONFIG_NET_POLL_CONTROLLER
2502 .ndo_poll_controller
= mlx4_en_netpoll
,
2504 .ndo_set_features
= mlx4_en_set_features
,
2505 .ndo_fix_features
= mlx4_en_fix_features
,
2506 .ndo_setup_tc
= mlx4_en_setup_tc
,
2507 #ifdef CONFIG_RFS_ACCEL
2508 .ndo_rx_flow_steer
= mlx4_en_filter_rfs
,
2510 #ifdef CONFIG_NET_RX_BUSY_POLL
2511 .ndo_busy_poll
= mlx4_en_low_latency_recv
,
2513 .ndo_get_phys_port_id
= mlx4_en_get_phys_port_id
,
2514 #ifdef CONFIG_MLX4_EN_VXLAN
2515 .ndo_add_vxlan_port
= mlx4_en_add_vxlan_port
,
2516 .ndo_del_vxlan_port
= mlx4_en_del_vxlan_port
,
2517 .ndo_features_check
= mlx4_en_features_check
,
2519 .ndo_set_tx_maxrate
= mlx4_en_set_tx_maxrate
,
2522 static const struct net_device_ops mlx4_netdev_ops_master
= {
2523 .ndo_open
= mlx4_en_open
,
2524 .ndo_stop
= mlx4_en_close
,
2525 .ndo_start_xmit
= mlx4_en_xmit
,
2526 .ndo_select_queue
= mlx4_en_select_queue
,
2527 .ndo_get_stats
= mlx4_en_get_stats
,
2528 .ndo_set_rx_mode
= mlx4_en_set_rx_mode
,
2529 .ndo_set_mac_address
= mlx4_en_set_mac
,
2530 .ndo_validate_addr
= eth_validate_addr
,
2531 .ndo_change_mtu
= mlx4_en_change_mtu
,
2532 .ndo_tx_timeout
= mlx4_en_tx_timeout
,
2533 .ndo_vlan_rx_add_vid
= mlx4_en_vlan_rx_add_vid
,
2534 .ndo_vlan_rx_kill_vid
= mlx4_en_vlan_rx_kill_vid
,
2535 .ndo_set_vf_mac
= mlx4_en_set_vf_mac
,
2536 .ndo_set_vf_vlan
= mlx4_en_set_vf_vlan
,
2537 .ndo_set_vf_rate
= mlx4_en_set_vf_rate
,
2538 .ndo_set_vf_spoofchk
= mlx4_en_set_vf_spoofchk
,
2539 .ndo_set_vf_link_state
= mlx4_en_set_vf_link_state
,
2540 .ndo_get_vf_stats
= mlx4_en_get_vf_stats
,
2541 .ndo_get_vf_config
= mlx4_en_get_vf_config
,
2542 #ifdef CONFIG_NET_POLL_CONTROLLER
2543 .ndo_poll_controller
= mlx4_en_netpoll
,
2545 .ndo_set_features
= mlx4_en_set_features
,
2546 .ndo_fix_features
= mlx4_en_fix_features
,
2547 .ndo_setup_tc
= mlx4_en_setup_tc
,
2548 #ifdef CONFIG_RFS_ACCEL
2549 .ndo_rx_flow_steer
= mlx4_en_filter_rfs
,
2551 .ndo_get_phys_port_id
= mlx4_en_get_phys_port_id
,
2552 #ifdef CONFIG_MLX4_EN_VXLAN
2553 .ndo_add_vxlan_port
= mlx4_en_add_vxlan_port
,
2554 .ndo_del_vxlan_port
= mlx4_en_del_vxlan_port
,
2555 .ndo_features_check
= mlx4_en_features_check
,
2557 .ndo_set_tx_maxrate
= mlx4_en_set_tx_maxrate
,
2560 struct mlx4_en_bond
{
2561 struct work_struct work
;
2562 struct mlx4_en_priv
*priv
;
2564 struct mlx4_port_map port_map
;
2567 static void mlx4_en_bond_work(struct work_struct
*work
)
2569 struct mlx4_en_bond
*bond
= container_of(work
,
2570 struct mlx4_en_bond
,
2573 struct mlx4_dev
*dev
= bond
->priv
->mdev
->dev
;
2575 if (bond
->is_bonded
) {
2576 if (!mlx4_is_bonded(dev
)) {
2577 err
= mlx4_bond(dev
);
2579 en_err(bond
->priv
, "Fail to bond device\n");
2582 err
= mlx4_port_map_set(dev
, &bond
->port_map
);
2584 en_err(bond
->priv
, "Fail to set port map [%d][%d]: %d\n",
2585 bond
->port_map
.port1
,
2586 bond
->port_map
.port2
,
2589 } else if (mlx4_is_bonded(dev
)) {
2590 err
= mlx4_unbond(dev
);
2592 en_err(bond
->priv
, "Fail to unbond device\n");
2594 dev_put(bond
->priv
->dev
);
2598 static int mlx4_en_queue_bond_work(struct mlx4_en_priv
*priv
, int is_bonded
,
2599 u8 v2p_p1
, u8 v2p_p2
)
2601 struct mlx4_en_bond
*bond
= NULL
;
2603 bond
= kzalloc(sizeof(*bond
), GFP_ATOMIC
);
2607 INIT_WORK(&bond
->work
, mlx4_en_bond_work
);
2609 bond
->is_bonded
= is_bonded
;
2610 bond
->port_map
.port1
= v2p_p1
;
2611 bond
->port_map
.port2
= v2p_p2
;
2612 dev_hold(priv
->dev
);
2613 queue_work(priv
->mdev
->workqueue
, &bond
->work
);
2617 int mlx4_en_netdev_event(struct notifier_block
*this,
2618 unsigned long event
, void *ptr
)
2620 struct net_device
*ndev
= netdev_notifier_info_to_dev(ptr
);
2622 struct mlx4_en_dev
*mdev
;
2623 struct mlx4_dev
*dev
;
2624 int i
, num_eth_ports
= 0;
2625 bool do_bond
= true;
2626 struct mlx4_en_priv
*priv
;
2630 if (!net_eq(dev_net(ndev
), &init_net
))
2633 mdev
= container_of(this, struct mlx4_en_dev
, nb
);
2636 /* Go into this mode only when two network devices set on two ports
2637 * of the same mlx4 device are slaves of the same bonding master
2639 mlx4_foreach_port(i
, dev
, MLX4_PORT_TYPE_ETH
) {
2641 if (!port
&& (mdev
->pndev
[i
] == ndev
))
2643 mdev
->upper
[i
] = mdev
->pndev
[i
] ?
2644 netdev_master_upper_dev_get(mdev
->pndev
[i
]) : NULL
;
2645 /* condition not met: network device is a slave */
2646 if (!mdev
->upper
[i
])
2648 if (num_eth_ports
< 2)
2650 /* condition not met: same master */
2651 if (mdev
->upper
[i
] != mdev
->upper
[i
-1])
2654 /* condition not met: 2 salves */
2655 do_bond
= (num_eth_ports
== 2) ? do_bond
: false;
2657 /* handle only events that come with enough info */
2658 if ((do_bond
&& (event
!= NETDEV_BONDING_INFO
)) || !port
)
2661 priv
= netdev_priv(ndev
);
2663 struct netdev_notifier_bonding_info
*notifier_info
= ptr
;
2664 struct netdev_bonding_info
*bonding_info
=
2665 ¬ifier_info
->bonding_info
;
2667 /* required mode 1, 2 or 4 */
2668 if ((bonding_info
->master
.bond_mode
!= BOND_MODE_ACTIVEBACKUP
) &&
2669 (bonding_info
->master
.bond_mode
!= BOND_MODE_XOR
) &&
2670 (bonding_info
->master
.bond_mode
!= BOND_MODE_8023AD
))
2673 /* require exactly 2 slaves */
2674 if (bonding_info
->master
.num_slaves
!= 2)
2679 if (bonding_info
->master
.bond_mode
==
2680 BOND_MODE_ACTIVEBACKUP
) {
2681 /* in active-backup mode virtual ports are
2682 * mapped to the physical port of the active
2684 if (bonding_info
->slave
.state
==
2685 BOND_STATE_BACKUP
) {
2693 } else { /* BOND_STATE_ACTIVE */
2702 } else { /* Active-Active */
2703 /* in active-active mode a virtual port is
2704 * mapped to the native physical port if and only
2705 * if the physical port is up */
2706 __s8 link
= bonding_info
->slave
.link
;
2712 if ((link
== BOND_LINK_UP
) ||
2713 (link
== BOND_LINK_FAIL
)) {
2718 } else { /* BOND_LINK_DOWN || BOND_LINK_BACK */
2728 mlx4_en_queue_bond_work(priv
, do_bond
,
2729 v2p_port1
, v2p_port2
);
2734 void mlx4_en_update_pfc_stats_bitmap(struct mlx4_dev
*dev
,
2735 struct mlx4_en_stats_bitmap
*stats_bitmap
,
2736 u8 rx_ppp
, u8 rx_pause
,
2737 u8 tx_ppp
, u8 tx_pause
)
2739 int last_i
= NUM_MAIN_STATS
+ NUM_PORT_STATS
+ NUM_PF_STATS
;
2741 if (!mlx4_is_slave(dev
) &&
2742 (dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN
)) {
2743 mutex_lock(&stats_bitmap
->mutex
);
2744 bitmap_clear(stats_bitmap
->bitmap
, last_i
, NUM_FLOW_STATS
);
2747 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2748 NUM_FLOW_PRIORITY_STATS_RX
);
2749 last_i
+= NUM_FLOW_PRIORITY_STATS_RX
;
2751 if (rx_pause
&& !(rx_ppp
))
2752 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2754 last_i
+= NUM_FLOW_STATS_RX
;
2757 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2758 NUM_FLOW_PRIORITY_STATS_TX
);
2759 last_i
+= NUM_FLOW_PRIORITY_STATS_TX
;
2761 if (tx_pause
&& !(tx_ppp
))
2762 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2764 last_i
+= NUM_FLOW_STATS_TX
;
2766 mutex_unlock(&stats_bitmap
->mutex
);
2770 void mlx4_en_set_stats_bitmap(struct mlx4_dev
*dev
,
2771 struct mlx4_en_stats_bitmap
*stats_bitmap
,
2772 u8 rx_ppp
, u8 rx_pause
,
2773 u8 tx_ppp
, u8 tx_pause
)
2777 mutex_init(&stats_bitmap
->mutex
);
2778 bitmap_zero(stats_bitmap
->bitmap
, NUM_ALL_STATS
);
2780 if (mlx4_is_slave(dev
)) {
2781 bitmap_set(stats_bitmap
->bitmap
, last_i
+
2782 MLX4_FIND_NETDEV_STAT(rx_packets
), 1);
2783 bitmap_set(stats_bitmap
->bitmap
, last_i
+
2784 MLX4_FIND_NETDEV_STAT(tx_packets
), 1);
2785 bitmap_set(stats_bitmap
->bitmap
, last_i
+
2786 MLX4_FIND_NETDEV_STAT(rx_bytes
), 1);
2787 bitmap_set(stats_bitmap
->bitmap
, last_i
+
2788 MLX4_FIND_NETDEV_STAT(tx_bytes
), 1);
2789 bitmap_set(stats_bitmap
->bitmap
, last_i
+
2790 MLX4_FIND_NETDEV_STAT(rx_dropped
), 1);
2791 bitmap_set(stats_bitmap
->bitmap
, last_i
+
2792 MLX4_FIND_NETDEV_STAT(tx_dropped
), 1);
2794 bitmap_set(stats_bitmap
->bitmap
, last_i
, NUM_MAIN_STATS
);
2796 last_i
+= NUM_MAIN_STATS
;
2798 bitmap_set(stats_bitmap
->bitmap
, last_i
, NUM_PORT_STATS
);
2799 last_i
+= NUM_PORT_STATS
;
2801 if (mlx4_is_master(dev
))
2802 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2804 last_i
+= NUM_PF_STATS
;
2806 mlx4_en_update_pfc_stats_bitmap(dev
, stats_bitmap
,
2809 last_i
+= NUM_FLOW_STATS
;
2811 if (!mlx4_is_slave(dev
))
2812 bitmap_set(stats_bitmap
->bitmap
, last_i
, NUM_PKT_STATS
);
2815 int mlx4_en_init_netdev(struct mlx4_en_dev
*mdev
, int port
,
2816 struct mlx4_en_port_profile
*prof
)
2818 struct net_device
*dev
;
2819 struct mlx4_en_priv
*priv
;
2823 dev
= alloc_etherdev_mqs(sizeof(struct mlx4_en_priv
),
2824 MAX_TX_RINGS
, MAX_RX_RINGS
);
2828 netif_set_real_num_tx_queues(dev
, prof
->tx_ring_num
);
2829 netif_set_real_num_rx_queues(dev
, prof
->rx_ring_num
);
2831 SET_NETDEV_DEV(dev
, &mdev
->dev
->persist
->pdev
->dev
);
2832 dev
->dev_port
= port
- 1;
2835 * Initialize driver private data
2838 priv
= netdev_priv(dev
);
2839 memset(priv
, 0, sizeof(struct mlx4_en_priv
));
2840 priv
->counter_index
= MLX4_SINK_COUNTER_INDEX(mdev
->dev
);
2841 spin_lock_init(&priv
->stats_lock
);
2842 INIT_WORK(&priv
->rx_mode_task
, mlx4_en_do_set_rx_mode
);
2843 INIT_WORK(&priv
->watchdog_task
, mlx4_en_restart
);
2844 INIT_WORK(&priv
->linkstate_task
, mlx4_en_linkstate
);
2845 INIT_DELAYED_WORK(&priv
->stats_task
, mlx4_en_do_get_stats
);
2846 INIT_DELAYED_WORK(&priv
->service_task
, mlx4_en_service_task
);
2847 #ifdef CONFIG_MLX4_EN_VXLAN
2848 INIT_WORK(&priv
->vxlan_add_task
, mlx4_en_add_vxlan_offloads
);
2849 INIT_WORK(&priv
->vxlan_del_task
, mlx4_en_del_vxlan_offloads
);
2851 #ifdef CONFIG_RFS_ACCEL
2852 INIT_LIST_HEAD(&priv
->filters
);
2853 spin_lock_init(&priv
->filters_lock
);
2858 priv
->ddev
= &mdev
->pdev
->dev
;
2861 priv
->port_up
= false;
2862 priv
->flags
= prof
->flags
;
2863 priv
->pflags
= MLX4_EN_PRIV_FLAGS_BLUEFLAME
;
2864 priv
->ctrl_flags
= cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE
|
2865 MLX4_WQE_CTRL_SOLICITED
);
2866 priv
->num_tx_rings_p_up
= mdev
->profile
.num_tx_rings_p_up
;
2867 priv
->tx_ring_num
= prof
->tx_ring_num
;
2868 priv
->tx_work_limit
= MLX4_EN_DEFAULT_TX_WORK
;
2869 netdev_rss_key_fill(priv
->rss_key
, sizeof(priv
->rss_key
));
2871 priv
->tx_ring
= kzalloc(sizeof(struct mlx4_en_tx_ring
*) * MAX_TX_RINGS
,
2873 if (!priv
->tx_ring
) {
2877 priv
->tx_cq
= kzalloc(sizeof(struct mlx4_en_cq
*) * MAX_TX_RINGS
,
2883 priv
->rx_ring_num
= prof
->rx_ring_num
;
2884 priv
->cqe_factor
= (mdev
->dev
->caps
.cqe_size
== 64) ? 1 : 0;
2885 priv
->cqe_size
= mdev
->dev
->caps
.cqe_size
;
2886 priv
->mac_index
= -1;
2887 priv
->msg_enable
= MLX4_EN_MSG_LEVEL
;
2888 #ifdef CONFIG_MLX4_EN_DCB
2889 if (!mlx4_is_slave(priv
->mdev
->dev
)) {
2890 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_ETS_CFG
) {
2891 dev
->dcbnl_ops
= &mlx4_en_dcbnl_ops
;
2893 en_info(priv
, "enabling only PFC DCB ops\n");
2894 dev
->dcbnl_ops
= &mlx4_en_dcbnl_pfc_ops
;
2899 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
)
2900 INIT_HLIST_HEAD(&priv
->mac_hash
[i
]);
2902 /* Query for default mac and max mtu */
2903 priv
->max_mtu
= mdev
->dev
->caps
.eth_mtu_cap
[priv
->port
];
2905 if (mdev
->dev
->caps
.rx_checksum_flags_port
[priv
->port
] &
2906 MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP
)
2907 priv
->flags
|= MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP
;
2909 /* Set default MAC */
2910 dev
->addr_len
= ETH_ALEN
;
2911 mlx4_en_u64_to_mac(dev
->dev_addr
, mdev
->dev
->caps
.def_mac
[priv
->port
]);
2912 if (!is_valid_ether_addr(dev
->dev_addr
)) {
2913 en_err(priv
, "Port: %d, invalid mac burned: %pM, quiting\n",
2914 priv
->port
, dev
->dev_addr
);
2917 } else if (mlx4_is_slave(priv
->mdev
->dev
) &&
2918 (priv
->mdev
->dev
->port_random_macs
& 1 << priv
->port
)) {
2919 /* Random MAC was assigned in mlx4_slave_cap
2920 * in mlx4_core module
2922 dev
->addr_assign_type
|= NET_ADDR_RANDOM
;
2923 en_warn(priv
, "Assigned random MAC address %pM\n", dev
->dev_addr
);
2926 memcpy(priv
->current_mac
, dev
->dev_addr
, sizeof(priv
->current_mac
));
2928 priv
->stride
= roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc
) +
2929 DS_SIZE
* MLX4_EN_MAX_RX_FRAGS
);
2930 err
= mlx4_en_alloc_resources(priv
);
2934 /* Initialize time stamping config */
2935 priv
->hwtstamp_config
.flags
= 0;
2936 priv
->hwtstamp_config
.tx_type
= HWTSTAMP_TX_OFF
;
2937 priv
->hwtstamp_config
.rx_filter
= HWTSTAMP_FILTER_NONE
;
2939 /* Allocate page for receive rings */
2940 err
= mlx4_alloc_hwq_res(mdev
->dev
, &priv
->res
,
2941 MLX4_EN_PAGE_SIZE
, MLX4_EN_PAGE_SIZE
);
2943 en_err(priv
, "Failed to allocate page for rx qps\n");
2946 priv
->allocated
= 1;
2949 * Initialize netdev entry points
2951 if (mlx4_is_master(priv
->mdev
->dev
))
2952 dev
->netdev_ops
= &mlx4_netdev_ops_master
;
2954 dev
->netdev_ops
= &mlx4_netdev_ops
;
2955 dev
->watchdog_timeo
= MLX4_EN_WATCHDOG_TIMEOUT
;
2956 netif_set_real_num_tx_queues(dev
, priv
->tx_ring_num
);
2957 netif_set_real_num_rx_queues(dev
, priv
->rx_ring_num
);
2959 dev
->ethtool_ops
= &mlx4_en_ethtool_ops
;
2962 * Set driver features
2964 dev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
2965 if (mdev
->LSO_support
)
2966 dev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
2968 dev
->vlan_features
= dev
->hw_features
;
2970 dev
->hw_features
|= NETIF_F_RXCSUM
| NETIF_F_RXHASH
;
2971 dev
->features
= dev
->hw_features
| NETIF_F_HIGHDMA
|
2972 NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
|
2973 NETIF_F_HW_VLAN_CTAG_FILTER
;
2974 dev
->hw_features
|= NETIF_F_LOOPBACK
|
2975 NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
;
2977 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN
)) {
2978 dev
->features
|= NETIF_F_HW_VLAN_STAG_RX
|
2979 NETIF_F_HW_VLAN_STAG_FILTER
;
2980 dev
->hw_features
|= NETIF_F_HW_VLAN_STAG_RX
;
2983 if (mlx4_is_slave(mdev
->dev
)) {
2986 err
= get_phv_bit(mdev
->dev
, port
, &phv
);
2988 dev
->hw_features
|= NETIF_F_HW_VLAN_STAG_TX
;
2989 priv
->pflags
|= MLX4_EN_PRIV_FLAGS_PHV
;
2992 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_PHV_EN
&&
2993 !(mdev
->dev
->caps
.flags2
&
2994 MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN
))
2995 dev
->hw_features
|= NETIF_F_HW_VLAN_STAG_TX
;
2998 if (mdev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_FCS_KEEP
)
2999 dev
->hw_features
|= NETIF_F_RXFCS
;
3001 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_IGNORE_FCS
)
3002 dev
->hw_features
|= NETIF_F_RXALL
;
3004 if (mdev
->dev
->caps
.steering_mode
==
3005 MLX4_STEERING_MODE_DEVICE_MANAGED
&&
3006 mdev
->dev
->caps
.dmfs_high_steer_mode
!= MLX4_STEERING_DMFS_A0_STATIC
)
3007 dev
->hw_features
|= NETIF_F_NTUPLE
;
3009 if (mdev
->dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
)
3010 dev
->priv_flags
|= IFF_UNICAST_FLT
;
3012 /* Setting a default hash function value */
3013 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_RSS_TOP
) {
3014 priv
->rss_hash_fn
= ETH_RSS_HASH_TOP
;
3015 } else if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_RSS_XOR
) {
3016 priv
->rss_hash_fn
= ETH_RSS_HASH_XOR
;
3019 "No RSS hash capabilities exposed, using Toeplitz\n");
3020 priv
->rss_hash_fn
= ETH_RSS_HASH_TOP
;
3023 mdev
->pndev
[port
] = dev
;
3024 mdev
->upper
[port
] = NULL
;
3026 netif_carrier_off(dev
);
3027 mlx4_en_set_default_moderation(priv
);
3029 en_warn(priv
, "Using %d TX rings\n", prof
->tx_ring_num
);
3030 en_warn(priv
, "Using %d RX rings\n", prof
->rx_ring_num
);
3032 mlx4_en_update_loopback_state(priv
->dev
, priv
->dev
->features
);
3034 /* Configure port */
3035 mlx4_en_calc_rx_buf(dev
);
3036 err
= mlx4_SET_PORT_general(mdev
->dev
, priv
->port
,
3037 priv
->rx_skb_size
+ ETH_FCS_LEN
,
3038 prof
->tx_pause
, prof
->tx_ppp
,
3039 prof
->rx_pause
, prof
->rx_ppp
);
3041 en_err(priv
, "Failed setting port general configurations for port %d, with error %d\n",
3046 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
3047 err
= mlx4_SET_PORT_VXLAN(mdev
->dev
, priv
->port
, VXLAN_STEER_BY_OUTER_MAC
, 1);
3049 en_err(priv
, "Failed setting port L2 tunnel configuration, err %d\n",
3056 en_warn(priv
, "Initializing port\n");
3057 err
= mlx4_INIT_PORT(mdev
->dev
, priv
->port
);
3059 en_err(priv
, "Failed Initializing port\n");
3062 queue_delayed_work(mdev
->workqueue
, &priv
->stats_task
, STATS_DELAY
);
3064 /* Initialize time stamp mechanism */
3065 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
)
3066 mlx4_en_init_timestamp(mdev
);
3068 queue_delayed_work(mdev
->workqueue
, &priv
->service_task
,
3069 SERVICE_TASK_DELAY
);
3071 mlx4_en_set_stats_bitmap(mdev
->dev
, &priv
->stats_bitmap
,
3072 mdev
->profile
.prof
[priv
->port
].rx_ppp
,
3073 mdev
->profile
.prof
[priv
->port
].rx_pause
,
3074 mdev
->profile
.prof
[priv
->port
].tx_ppp
,
3075 mdev
->profile
.prof
[priv
->port
].tx_pause
);
3077 err
= register_netdev(dev
);
3079 en_err(priv
, "Netdev registration failed for port %d\n", port
);
3083 priv
->registered
= 1;
3088 mlx4_en_destroy_netdev(dev
);
3092 int mlx4_en_reset_config(struct net_device
*dev
,
3093 struct hwtstamp_config ts_config
,
3094 netdev_features_t features
)
3096 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
3097 struct mlx4_en_dev
*mdev
= priv
->mdev
;
3101 if (priv
->hwtstamp_config
.tx_type
== ts_config
.tx_type
&&
3102 priv
->hwtstamp_config
.rx_filter
== ts_config
.rx_filter
&&
3103 !DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_HW_VLAN_CTAG_RX
) &&
3104 !DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_RXFCS
))
3105 return 0; /* Nothing to change */
3107 if (DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_HW_VLAN_CTAG_RX
) &&
3108 (features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
3109 (priv
->hwtstamp_config
.rx_filter
!= HWTSTAMP_FILTER_NONE
)) {
3110 en_warn(priv
, "Can't turn ON rx vlan offload while time-stamping rx filter is ON\n");
3114 mutex_lock(&mdev
->state_lock
);
3115 if (priv
->port_up
) {
3117 mlx4_en_stop_port(dev
, 1);
3120 mlx4_en_free_resources(priv
);
3122 en_warn(priv
, "Changing device configuration rx filter(%x) rx vlan(%x)\n",
3123 ts_config
.rx_filter
, !!(features
& NETIF_F_HW_VLAN_CTAG_RX
));
3125 priv
->hwtstamp_config
.tx_type
= ts_config
.tx_type
;
3126 priv
->hwtstamp_config
.rx_filter
= ts_config
.rx_filter
;
3128 if (DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_HW_VLAN_CTAG_RX
)) {
3129 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
3130 dev
->features
|= NETIF_F_HW_VLAN_CTAG_RX
;
3132 dev
->features
&= ~NETIF_F_HW_VLAN_CTAG_RX
;
3133 } else if (ts_config
.rx_filter
== HWTSTAMP_FILTER_NONE
) {
3134 /* RX time-stamping is OFF, update the RX vlan offload
3135 * to the latest wanted state
3137 if (dev
->wanted_features
& NETIF_F_HW_VLAN_CTAG_RX
)
3138 dev
->features
|= NETIF_F_HW_VLAN_CTAG_RX
;
3140 dev
->features
&= ~NETIF_F_HW_VLAN_CTAG_RX
;
3143 if (DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_RXFCS
)) {
3144 if (features
& NETIF_F_RXFCS
)
3145 dev
->features
|= NETIF_F_RXFCS
;
3147 dev
->features
&= ~NETIF_F_RXFCS
;
3150 /* RX vlan offload and RX time-stamping can't co-exist !
3151 * Regardless of the caller's choice,
3152 * Turn Off RX vlan offload in case of time-stamping is ON
3154 if (ts_config
.rx_filter
!= HWTSTAMP_FILTER_NONE
) {
3155 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
3156 en_warn(priv
, "Turning off RX vlan offload since RX time-stamping is ON\n");
3157 dev
->features
&= ~NETIF_F_HW_VLAN_CTAG_RX
;
3160 err
= mlx4_en_alloc_resources(priv
);
3162 en_err(priv
, "Failed reallocating port resources\n");
3166 err
= mlx4_en_start_port(dev
);
3168 en_err(priv
, "Failed starting port\n");
3172 mutex_unlock(&mdev
->state_lock
);
3173 netdev_features_change(dev
);