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/bpf.h>
35 #include <linux/etherdevice.h>
36 #include <linux/tcp.h>
37 #include <linux/if_vlan.h>
38 #include <linux/delay.h>
39 #include <linux/slab.h>
40 #include <linux/hash.h>
42 #include <net/busy_poll.h>
43 #include <net/vxlan.h>
44 #include <net/devlink.h>
46 #include <linux/mlx4/driver.h>
47 #include <linux/mlx4/device.h>
48 #include <linux/mlx4/cmd.h>
49 #include <linux/mlx4/cq.h>
54 int mlx4_en_setup_tc(struct net_device
*dev
, u8 up
)
56 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
58 unsigned int offset
= 0;
60 if (up
&& up
!= MLX4_EN_NUM_UP
)
63 netdev_set_num_tc(dev
, up
);
65 /* Partition Tx queues evenly amongst UP's */
66 for (i
= 0; i
< up
; i
++) {
67 netdev_set_tc_queue(dev
, i
, priv
->num_tx_rings_p_up
, offset
);
68 offset
+= priv
->num_tx_rings_p_up
;
71 #ifdef CONFIG_MLX4_EN_DCB
72 if (!mlx4_is_slave(priv
->mdev
->dev
)) {
75 priv
->flags
|= MLX4_EN_FLAG_DCB_ENABLED
;
77 priv
->flags
&= ~MLX4_EN_FLAG_DCB_ENABLED
;
78 priv
->cee_config
.pfc_state
= false;
81 #endif /* CONFIG_MLX4_EN_DCB */
86 static int __mlx4_en_setup_tc(struct net_device
*dev
, u32 handle
, __be16 proto
,
87 struct tc_to_netdev
*tc
)
89 if (tc
->type
!= TC_SETUP_MQPRIO
)
92 return mlx4_en_setup_tc(dev
, tc
->tc
);
95 #ifdef CONFIG_RFS_ACCEL
97 struct mlx4_en_filter
{
98 struct list_head next
;
99 struct work_struct work
;
108 struct mlx4_en_priv
*priv
;
109 u32 flow_id
; /* RFS infrastructure id */
110 int id
; /* mlx4_en driver id */
111 u64 reg_id
; /* Flow steering API id */
112 u8 activated
; /* Used to prevent expiry before filter
115 struct hlist_node filter_chain
;
118 static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv
*priv
);
120 static enum mlx4_net_trans_rule_id
mlx4_ip_proto_to_trans_rule_id(u8 ip_proto
)
124 return MLX4_NET_TRANS_RULE_ID_UDP
;
126 return MLX4_NET_TRANS_RULE_ID_TCP
;
128 return MLX4_NET_TRANS_RULE_NUM
;
132 static void mlx4_en_filter_work(struct work_struct
*work
)
134 struct mlx4_en_filter
*filter
= container_of(work
,
135 struct mlx4_en_filter
,
137 struct mlx4_en_priv
*priv
= filter
->priv
;
138 struct mlx4_spec_list spec_tcp_udp
= {
139 .id
= mlx4_ip_proto_to_trans_rule_id(filter
->ip_proto
),
142 .dst_port
= filter
->dst_port
,
143 .dst_port_msk
= (__force __be16
)-1,
144 .src_port
= filter
->src_port
,
145 .src_port_msk
= (__force __be16
)-1,
149 struct mlx4_spec_list spec_ip
= {
150 .id
= MLX4_NET_TRANS_RULE_ID_IPV4
,
153 .dst_ip
= filter
->dst_ip
,
154 .dst_ip_msk
= (__force __be32
)-1,
155 .src_ip
= filter
->src_ip
,
156 .src_ip_msk
= (__force __be32
)-1,
160 struct mlx4_spec_list spec_eth
= {
161 .id
= MLX4_NET_TRANS_RULE_ID_ETH
,
163 struct mlx4_net_trans_rule rule
= {
164 .list
= LIST_HEAD_INIT(rule
.list
),
165 .queue_mode
= MLX4_NET_TRANS_Q_LIFO
,
168 .promisc_mode
= MLX4_FS_REGULAR
,
170 .priority
= MLX4_DOMAIN_RFS
,
173 __be64 mac_mask
= cpu_to_be64(MLX4_MAC_MASK
<< 16);
175 if (spec_tcp_udp
.id
>= MLX4_NET_TRANS_RULE_NUM
) {
176 en_warn(priv
, "RFS: ignoring unsupported ip protocol (%d)\n",
180 list_add_tail(&spec_eth
.list
, &rule
.list
);
181 list_add_tail(&spec_ip
.list
, &rule
.list
);
182 list_add_tail(&spec_tcp_udp
.list
, &rule
.list
);
184 rule
.qpn
= priv
->rss_map
.qps
[filter
->rxq_index
].qpn
;
185 memcpy(spec_eth
.eth
.dst_mac
, priv
->dev
->dev_addr
, ETH_ALEN
);
186 memcpy(spec_eth
.eth
.dst_mac_msk
, &mac_mask
, ETH_ALEN
);
188 filter
->activated
= 0;
190 if (filter
->reg_id
) {
191 rc
= mlx4_flow_detach(priv
->mdev
->dev
, filter
->reg_id
);
192 if (rc
&& rc
!= -ENOENT
)
193 en_err(priv
, "Error detaching flow. rc = %d\n", rc
);
196 rc
= mlx4_flow_attach(priv
->mdev
->dev
, &rule
, &filter
->reg_id
);
198 en_err(priv
, "Error attaching flow. err = %d\n", rc
);
201 mlx4_en_filter_rfs_expire(priv
);
203 filter
->activated
= 1;
206 static inline struct hlist_head
*
207 filter_hash_bucket(struct mlx4_en_priv
*priv
, __be32 src_ip
, __be32 dst_ip
,
208 __be16 src_port
, __be16 dst_port
)
213 l
= (__force
unsigned long)src_port
|
214 ((__force
unsigned long)dst_port
<< 2);
215 l
^= (__force
unsigned long)(src_ip
^ dst_ip
);
217 bucket_idx
= hash_long(l
, MLX4_EN_FILTER_HASH_SHIFT
);
219 return &priv
->filter_hash
[bucket_idx
];
222 static struct mlx4_en_filter
*
223 mlx4_en_filter_alloc(struct mlx4_en_priv
*priv
, int rxq_index
, __be32 src_ip
,
224 __be32 dst_ip
, u8 ip_proto
, __be16 src_port
,
225 __be16 dst_port
, u32 flow_id
)
227 struct mlx4_en_filter
*filter
= NULL
;
229 filter
= kzalloc(sizeof(struct mlx4_en_filter
), GFP_ATOMIC
);
234 filter
->rxq_index
= rxq_index
;
235 INIT_WORK(&filter
->work
, mlx4_en_filter_work
);
237 filter
->src_ip
= src_ip
;
238 filter
->dst_ip
= dst_ip
;
239 filter
->ip_proto
= ip_proto
;
240 filter
->src_port
= src_port
;
241 filter
->dst_port
= dst_port
;
243 filter
->flow_id
= flow_id
;
245 filter
->id
= priv
->last_filter_id
++ % RPS_NO_FILTER
;
247 list_add_tail(&filter
->next
, &priv
->filters
);
248 hlist_add_head(&filter
->filter_chain
,
249 filter_hash_bucket(priv
, src_ip
, dst_ip
, src_port
,
255 static void mlx4_en_filter_free(struct mlx4_en_filter
*filter
)
257 struct mlx4_en_priv
*priv
= filter
->priv
;
260 list_del(&filter
->next
);
262 rc
= mlx4_flow_detach(priv
->mdev
->dev
, filter
->reg_id
);
263 if (rc
&& rc
!= -ENOENT
)
264 en_err(priv
, "Error detaching flow. rc = %d\n", rc
);
269 static inline struct mlx4_en_filter
*
270 mlx4_en_filter_find(struct mlx4_en_priv
*priv
, __be32 src_ip
, __be32 dst_ip
,
271 u8 ip_proto
, __be16 src_port
, __be16 dst_port
)
273 struct mlx4_en_filter
*filter
;
274 struct mlx4_en_filter
*ret
= NULL
;
276 hlist_for_each_entry(filter
,
277 filter_hash_bucket(priv
, src_ip
, dst_ip
,
280 if (filter
->src_ip
== src_ip
&&
281 filter
->dst_ip
== dst_ip
&&
282 filter
->ip_proto
== ip_proto
&&
283 filter
->src_port
== src_port
&&
284 filter
->dst_port
== dst_port
) {
294 mlx4_en_filter_rfs(struct net_device
*net_dev
, const struct sk_buff
*skb
,
295 u16 rxq_index
, u32 flow_id
)
297 struct mlx4_en_priv
*priv
= netdev_priv(net_dev
);
298 struct mlx4_en_filter
*filter
;
299 const struct iphdr
*ip
;
306 int nhoff
= skb_network_offset(skb
);
309 if (skb
->protocol
!= htons(ETH_P_IP
))
310 return -EPROTONOSUPPORT
;
312 ip
= (const struct iphdr
*)(skb
->data
+ nhoff
);
313 if (ip_is_fragment(ip
))
314 return -EPROTONOSUPPORT
;
316 if ((ip
->protocol
!= IPPROTO_TCP
) && (ip
->protocol
!= IPPROTO_UDP
))
317 return -EPROTONOSUPPORT
;
318 ports
= (const __be16
*)(skb
->data
+ nhoff
+ 4 * ip
->ihl
);
320 ip_proto
= ip
->protocol
;
326 spin_lock_bh(&priv
->filters_lock
);
327 filter
= mlx4_en_filter_find(priv
, src_ip
, dst_ip
, ip_proto
,
330 if (filter
->rxq_index
== rxq_index
)
333 filter
->rxq_index
= rxq_index
;
335 filter
= mlx4_en_filter_alloc(priv
, rxq_index
,
336 src_ip
, dst_ip
, ip_proto
,
337 src_port
, dst_port
, flow_id
);
344 queue_work(priv
->mdev
->workqueue
, &filter
->work
);
349 spin_unlock_bh(&priv
->filters_lock
);
354 void mlx4_en_cleanup_filters(struct mlx4_en_priv
*priv
)
356 struct mlx4_en_filter
*filter
, *tmp
;
359 spin_lock_bh(&priv
->filters_lock
);
360 list_for_each_entry_safe(filter
, tmp
, &priv
->filters
, next
) {
361 list_move(&filter
->next
, &del_list
);
362 hlist_del(&filter
->filter_chain
);
364 spin_unlock_bh(&priv
->filters_lock
);
366 list_for_each_entry_safe(filter
, tmp
, &del_list
, next
) {
367 cancel_work_sync(&filter
->work
);
368 mlx4_en_filter_free(filter
);
372 static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv
*priv
)
374 struct mlx4_en_filter
*filter
= NULL
, *tmp
, *last_filter
= NULL
;
378 spin_lock_bh(&priv
->filters_lock
);
379 list_for_each_entry_safe(filter
, tmp
, &priv
->filters
, next
) {
380 if (i
> MLX4_EN_FILTER_EXPIRY_QUOTA
)
383 if (filter
->activated
&&
384 !work_pending(&filter
->work
) &&
385 rps_may_expire_flow(priv
->dev
,
386 filter
->rxq_index
, filter
->flow_id
,
388 list_move(&filter
->next
, &del_list
);
389 hlist_del(&filter
->filter_chain
);
391 last_filter
= filter
;
396 if (last_filter
&& (&last_filter
->next
!= priv
->filters
.next
))
397 list_move(&priv
->filters
, &last_filter
->next
);
399 spin_unlock_bh(&priv
->filters_lock
);
401 list_for_each_entry_safe(filter
, tmp
, &del_list
, next
)
402 mlx4_en_filter_free(filter
);
406 static int mlx4_en_vlan_rx_add_vid(struct net_device
*dev
,
407 __be16 proto
, u16 vid
)
409 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
410 struct mlx4_en_dev
*mdev
= priv
->mdev
;
414 en_dbg(HW
, priv
, "adding VLAN:%d\n", vid
);
416 set_bit(vid
, priv
->active_vlans
);
418 /* Add VID to port VLAN filter */
419 mutex_lock(&mdev
->state_lock
);
420 if (mdev
->device_up
&& priv
->port_up
) {
421 err
= mlx4_SET_VLAN_FLTR(mdev
->dev
, priv
);
423 en_err(priv
, "Failed configuring VLAN filter\n");
427 err
= mlx4_register_vlan(mdev
->dev
, priv
->port
, vid
, &idx
);
429 en_dbg(HW
, priv
, "Failed adding vlan %d\n", vid
);
432 mutex_unlock(&mdev
->state_lock
);
436 static int mlx4_en_vlan_rx_kill_vid(struct net_device
*dev
,
437 __be16 proto
, u16 vid
)
439 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
440 struct mlx4_en_dev
*mdev
= priv
->mdev
;
443 en_dbg(HW
, priv
, "Killing VID:%d\n", vid
);
445 clear_bit(vid
, priv
->active_vlans
);
447 /* Remove VID from port VLAN filter */
448 mutex_lock(&mdev
->state_lock
);
449 mlx4_unregister_vlan(mdev
->dev
, priv
->port
, vid
);
451 if (mdev
->device_up
&& priv
->port_up
) {
452 err
= mlx4_SET_VLAN_FLTR(mdev
->dev
, priv
);
454 en_err(priv
, "Failed configuring VLAN filter\n");
456 mutex_unlock(&mdev
->state_lock
);
461 static void mlx4_en_u64_to_mac(unsigned char dst_mac
[ETH_ALEN
+ 2], u64 src_mac
)
464 for (i
= ETH_ALEN
- 1; i
>= 0; --i
) {
465 dst_mac
[i
] = src_mac
& 0xff;
468 memset(&dst_mac
[ETH_ALEN
], 0, 2);
472 static int mlx4_en_tunnel_steer_add(struct mlx4_en_priv
*priv
, unsigned char *addr
,
473 int qpn
, u64
*reg_id
)
477 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
||
478 priv
->mdev
->dev
->caps
.dmfs_high_steer_mode
== MLX4_STEERING_DMFS_A0_STATIC
)
479 return 0; /* do nothing */
481 err
= mlx4_tunnel_steer_add(priv
->mdev
->dev
, addr
, priv
->port
, qpn
,
482 MLX4_DOMAIN_NIC
, reg_id
);
484 en_err(priv
, "failed to add vxlan steering rule, err %d\n", err
);
487 en_dbg(DRV
, priv
, "added vxlan steering rule, mac %pM reg_id %llx\n", addr
, *reg_id
);
492 static int mlx4_en_uc_steer_add(struct mlx4_en_priv
*priv
,
493 unsigned char *mac
, int *qpn
, u64
*reg_id
)
495 struct mlx4_en_dev
*mdev
= priv
->mdev
;
496 struct mlx4_dev
*dev
= mdev
->dev
;
499 switch (dev
->caps
.steering_mode
) {
500 case MLX4_STEERING_MODE_B0
: {
505 memcpy(&gid
[10], mac
, ETH_ALEN
);
508 err
= mlx4_unicast_attach(dev
, &qp
, gid
, 0, MLX4_PROT_ETH
);
511 case MLX4_STEERING_MODE_DEVICE_MANAGED
: {
512 struct mlx4_spec_list spec_eth
= { {NULL
} };
513 __be64 mac_mask
= cpu_to_be64(MLX4_MAC_MASK
<< 16);
515 struct mlx4_net_trans_rule rule
= {
516 .queue_mode
= MLX4_NET_TRANS_Q_FIFO
,
519 .promisc_mode
= MLX4_FS_REGULAR
,
520 .priority
= MLX4_DOMAIN_NIC
,
523 rule
.port
= priv
->port
;
525 INIT_LIST_HEAD(&rule
.list
);
527 spec_eth
.id
= MLX4_NET_TRANS_RULE_ID_ETH
;
528 memcpy(spec_eth
.eth
.dst_mac
, mac
, ETH_ALEN
);
529 memcpy(spec_eth
.eth
.dst_mac_msk
, &mac_mask
, ETH_ALEN
);
530 list_add_tail(&spec_eth
.list
, &rule
.list
);
532 err
= mlx4_flow_attach(dev
, &rule
, reg_id
);
539 en_warn(priv
, "Failed Attaching Unicast\n");
544 static void mlx4_en_uc_steer_release(struct mlx4_en_priv
*priv
,
545 unsigned char *mac
, int qpn
, u64 reg_id
)
547 struct mlx4_en_dev
*mdev
= priv
->mdev
;
548 struct mlx4_dev
*dev
= mdev
->dev
;
550 switch (dev
->caps
.steering_mode
) {
551 case MLX4_STEERING_MODE_B0
: {
556 memcpy(&gid
[10], mac
, ETH_ALEN
);
559 mlx4_unicast_detach(dev
, &qp
, gid
, MLX4_PROT_ETH
);
562 case MLX4_STEERING_MODE_DEVICE_MANAGED
: {
563 mlx4_flow_detach(dev
, reg_id
);
567 en_err(priv
, "Invalid steering mode.\n");
571 static int mlx4_en_get_qp(struct mlx4_en_priv
*priv
)
573 struct mlx4_en_dev
*mdev
= priv
->mdev
;
574 struct mlx4_dev
*dev
= mdev
->dev
;
577 int *qpn
= &priv
->base_qpn
;
578 u64 mac
= mlx4_mac_to_u64(priv
->dev
->dev_addr
);
580 en_dbg(DRV
, priv
, "Registering MAC: %pM for adding\n",
581 priv
->dev
->dev_addr
);
582 index
= mlx4_register_mac(dev
, priv
->port
, mac
);
585 en_err(priv
, "Failed adding MAC: %pM\n",
586 priv
->dev
->dev_addr
);
590 if (dev
->caps
.steering_mode
== MLX4_STEERING_MODE_A0
) {
591 int base_qpn
= mlx4_get_base_qpn(dev
, priv
->port
);
592 *qpn
= base_qpn
+ index
;
596 err
= mlx4_qp_reserve_range(dev
, 1, 1, qpn
, MLX4_RESERVE_A0_QP
);
597 en_dbg(DRV
, priv
, "Reserved qp %d\n", *qpn
);
599 en_err(priv
, "Failed to reserve qp for mac registration\n");
600 mlx4_unregister_mac(dev
, priv
->port
, mac
);
607 static void mlx4_en_put_qp(struct mlx4_en_priv
*priv
)
609 struct mlx4_en_dev
*mdev
= priv
->mdev
;
610 struct mlx4_dev
*dev
= mdev
->dev
;
611 int qpn
= priv
->base_qpn
;
613 if (dev
->caps
.steering_mode
== MLX4_STEERING_MODE_A0
) {
614 u64 mac
= mlx4_mac_to_u64(priv
->dev
->dev_addr
);
615 en_dbg(DRV
, priv
, "Registering MAC: %pM for deleting\n",
616 priv
->dev
->dev_addr
);
617 mlx4_unregister_mac(dev
, priv
->port
, mac
);
619 en_dbg(DRV
, priv
, "Releasing qp: port %d, qpn %d\n",
621 mlx4_qp_release_range(dev
, qpn
, 1);
622 priv
->flags
&= ~MLX4_EN_FLAG_FORCE_PROMISC
;
626 static int mlx4_en_replace_mac(struct mlx4_en_priv
*priv
, int qpn
,
627 unsigned char *new_mac
, unsigned char *prev_mac
)
629 struct mlx4_en_dev
*mdev
= priv
->mdev
;
630 struct mlx4_dev
*dev
= mdev
->dev
;
632 u64 new_mac_u64
= mlx4_mac_to_u64(new_mac
);
634 if (dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
) {
635 struct hlist_head
*bucket
;
636 unsigned int mac_hash
;
637 struct mlx4_mac_entry
*entry
;
638 struct hlist_node
*tmp
;
639 u64 prev_mac_u64
= mlx4_mac_to_u64(prev_mac
);
641 bucket
= &priv
->mac_hash
[prev_mac
[MLX4_EN_MAC_HASH_IDX
]];
642 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
643 if (ether_addr_equal_64bits(entry
->mac
, prev_mac
)) {
644 mlx4_en_uc_steer_release(priv
, entry
->mac
,
646 mlx4_unregister_mac(dev
, priv
->port
,
648 hlist_del_rcu(&entry
->hlist
);
650 memcpy(entry
->mac
, new_mac
, ETH_ALEN
);
652 mac_hash
= new_mac
[MLX4_EN_MAC_HASH_IDX
];
653 hlist_add_head_rcu(&entry
->hlist
,
654 &priv
->mac_hash
[mac_hash
]);
655 mlx4_register_mac(dev
, priv
->port
, new_mac_u64
);
656 err
= mlx4_en_uc_steer_add(priv
, new_mac
,
661 if (priv
->tunnel_reg_id
) {
662 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
663 priv
->tunnel_reg_id
= 0;
665 err
= mlx4_en_tunnel_steer_add(priv
, new_mac
, qpn
,
666 &priv
->tunnel_reg_id
);
673 return __mlx4_replace_mac(dev
, priv
->port
, qpn
, new_mac_u64
);
676 static int mlx4_en_do_set_mac(struct mlx4_en_priv
*priv
,
677 unsigned char new_mac
[ETH_ALEN
+ 2])
682 /* Remove old MAC and insert the new one */
683 err
= mlx4_en_replace_mac(priv
, priv
->base_qpn
,
684 new_mac
, priv
->current_mac
);
686 en_err(priv
, "Failed changing HW MAC address\n");
688 en_dbg(HW
, priv
, "Port is down while registering mac, exiting...\n");
691 memcpy(priv
->current_mac
, new_mac
, sizeof(priv
->current_mac
));
696 static int mlx4_en_set_mac(struct net_device
*dev
, void *addr
)
698 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
699 struct mlx4_en_dev
*mdev
= priv
->mdev
;
700 struct sockaddr
*saddr
= addr
;
701 unsigned char new_mac
[ETH_ALEN
+ 2];
704 if (!is_valid_ether_addr(saddr
->sa_data
))
705 return -EADDRNOTAVAIL
;
707 mutex_lock(&mdev
->state_lock
);
708 memcpy(new_mac
, saddr
->sa_data
, ETH_ALEN
);
709 err
= mlx4_en_do_set_mac(priv
, new_mac
);
711 memcpy(dev
->dev_addr
, saddr
->sa_data
, ETH_ALEN
);
712 mutex_unlock(&mdev
->state_lock
);
717 static void mlx4_en_clear_list(struct net_device
*dev
)
719 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
720 struct mlx4_en_mc_list
*tmp
, *mc_to_del
;
722 list_for_each_entry_safe(mc_to_del
, tmp
, &priv
->mc_list
, list
) {
723 list_del(&mc_to_del
->list
);
728 static void mlx4_en_cache_mclist(struct net_device
*dev
)
730 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
731 struct netdev_hw_addr
*ha
;
732 struct mlx4_en_mc_list
*tmp
;
734 mlx4_en_clear_list(dev
);
735 netdev_for_each_mc_addr(ha
, dev
) {
736 tmp
= kzalloc(sizeof(struct mlx4_en_mc_list
), GFP_ATOMIC
);
738 mlx4_en_clear_list(dev
);
741 memcpy(tmp
->addr
, ha
->addr
, ETH_ALEN
);
742 list_add_tail(&tmp
->list
, &priv
->mc_list
);
746 static void update_mclist_flags(struct mlx4_en_priv
*priv
,
747 struct list_head
*dst
,
748 struct list_head
*src
)
750 struct mlx4_en_mc_list
*dst_tmp
, *src_tmp
, *new_mc
;
753 /* Find all the entries that should be removed from dst,
754 * These are the entries that are not found in src
756 list_for_each_entry(dst_tmp
, dst
, list
) {
758 list_for_each_entry(src_tmp
, src
, list
) {
759 if (ether_addr_equal(dst_tmp
->addr
, src_tmp
->addr
)) {
765 dst_tmp
->action
= MCLIST_REM
;
768 /* Add entries that exist in src but not in dst
769 * mark them as need to add
771 list_for_each_entry(src_tmp
, src
, list
) {
773 list_for_each_entry(dst_tmp
, dst
, list
) {
774 if (ether_addr_equal(dst_tmp
->addr
, src_tmp
->addr
)) {
775 dst_tmp
->action
= MCLIST_NONE
;
781 new_mc
= kmemdup(src_tmp
,
782 sizeof(struct mlx4_en_mc_list
),
787 new_mc
->action
= MCLIST_ADD
;
788 list_add_tail(&new_mc
->list
, dst
);
793 static void mlx4_en_set_rx_mode(struct net_device
*dev
)
795 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
800 queue_work(priv
->mdev
->workqueue
, &priv
->rx_mode_task
);
803 static void mlx4_en_set_promisc_mode(struct mlx4_en_priv
*priv
,
804 struct mlx4_en_dev
*mdev
)
808 if (!(priv
->flags
& MLX4_EN_FLAG_PROMISC
)) {
809 if (netif_msg_rx_status(priv
))
810 en_warn(priv
, "Entering promiscuous mode\n");
811 priv
->flags
|= MLX4_EN_FLAG_PROMISC
;
813 /* Enable promiscouos mode */
814 switch (mdev
->dev
->caps
.steering_mode
) {
815 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
816 err
= mlx4_flow_steer_promisc_add(mdev
->dev
,
819 MLX4_FS_ALL_DEFAULT
);
821 en_err(priv
, "Failed enabling promiscuous mode\n");
822 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
825 case MLX4_STEERING_MODE_B0
:
826 err
= mlx4_unicast_promisc_add(mdev
->dev
,
830 en_err(priv
, "Failed enabling unicast promiscuous mode\n");
832 /* Add the default qp number as multicast
835 if (!(priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
)) {
836 err
= mlx4_multicast_promisc_add(mdev
->dev
,
840 en_err(priv
, "Failed enabling multicast promiscuous mode\n");
841 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
845 case MLX4_STEERING_MODE_A0
:
846 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
,
851 en_err(priv
, "Failed enabling promiscuous mode\n");
855 /* Disable port multicast filter (unconditionally) */
856 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
857 0, MLX4_MCAST_DISABLE
);
859 en_err(priv
, "Failed disabling multicast filter\n");
863 static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv
*priv
,
864 struct mlx4_en_dev
*mdev
)
868 if (netif_msg_rx_status(priv
))
869 en_warn(priv
, "Leaving promiscuous mode\n");
870 priv
->flags
&= ~MLX4_EN_FLAG_PROMISC
;
872 /* Disable promiscouos mode */
873 switch (mdev
->dev
->caps
.steering_mode
) {
874 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
875 err
= mlx4_flow_steer_promisc_remove(mdev
->dev
,
877 MLX4_FS_ALL_DEFAULT
);
879 en_err(priv
, "Failed disabling promiscuous mode\n");
880 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
883 case MLX4_STEERING_MODE_B0
:
884 err
= mlx4_unicast_promisc_remove(mdev
->dev
,
888 en_err(priv
, "Failed disabling unicast promiscuous mode\n");
889 /* Disable Multicast promisc */
890 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
891 err
= mlx4_multicast_promisc_remove(mdev
->dev
,
895 en_err(priv
, "Failed disabling multicast promiscuous mode\n");
896 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
900 case MLX4_STEERING_MODE_A0
:
901 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
,
905 en_err(priv
, "Failed disabling promiscuous mode\n");
910 static void mlx4_en_do_multicast(struct mlx4_en_priv
*priv
,
911 struct net_device
*dev
,
912 struct mlx4_en_dev
*mdev
)
914 struct mlx4_en_mc_list
*mclist
, *tmp
;
916 u8 mc_list
[16] = {0};
919 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
920 if (dev
->flags
& IFF_ALLMULTI
) {
921 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
922 0, MLX4_MCAST_DISABLE
);
924 en_err(priv
, "Failed disabling multicast filter\n");
926 /* Add the default qp number as multicast promisc */
927 if (!(priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
)) {
928 switch (mdev
->dev
->caps
.steering_mode
) {
929 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
930 err
= mlx4_flow_steer_promisc_add(mdev
->dev
,
936 case MLX4_STEERING_MODE_B0
:
937 err
= mlx4_multicast_promisc_add(mdev
->dev
,
942 case MLX4_STEERING_MODE_A0
:
946 en_err(priv
, "Failed entering multicast promisc mode\n");
947 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
950 /* Disable Multicast promisc */
951 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
952 switch (mdev
->dev
->caps
.steering_mode
) {
953 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
954 err
= mlx4_flow_steer_promisc_remove(mdev
->dev
,
959 case MLX4_STEERING_MODE_B0
:
960 err
= mlx4_multicast_promisc_remove(mdev
->dev
,
965 case MLX4_STEERING_MODE_A0
:
969 en_err(priv
, "Failed disabling multicast promiscuous mode\n");
970 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
973 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
974 0, MLX4_MCAST_DISABLE
);
976 en_err(priv
, "Failed disabling multicast filter\n");
978 /* Flush mcast filter and init it with broadcast address */
979 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, ETH_BCAST
,
980 1, MLX4_MCAST_CONFIG
);
982 /* Update multicast list - we cache all addresses so they won't
983 * change while HW is updated holding the command semaphor */
984 netif_addr_lock_bh(dev
);
985 mlx4_en_cache_mclist(dev
);
986 netif_addr_unlock_bh(dev
);
987 list_for_each_entry(mclist
, &priv
->mc_list
, list
) {
988 mcast_addr
= mlx4_mac_to_u64(mclist
->addr
);
989 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
,
990 mcast_addr
, 0, MLX4_MCAST_CONFIG
);
992 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
993 0, MLX4_MCAST_ENABLE
);
995 en_err(priv
, "Failed enabling multicast filter\n");
997 update_mclist_flags(priv
, &priv
->curr_list
, &priv
->mc_list
);
998 list_for_each_entry_safe(mclist
, tmp
, &priv
->curr_list
, list
) {
999 if (mclist
->action
== MCLIST_REM
) {
1000 /* detach this address and delete from list */
1001 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1002 mc_list
[5] = priv
->port
;
1003 err
= mlx4_multicast_detach(mdev
->dev
,
1004 &priv
->rss_map
.indir_qp
,
1009 en_err(priv
, "Fail to detach multicast address\n");
1011 if (mclist
->tunnel_reg_id
) {
1012 err
= mlx4_flow_detach(priv
->mdev
->dev
, mclist
->tunnel_reg_id
);
1014 en_err(priv
, "Failed to detach multicast address\n");
1017 /* remove from list */
1018 list_del(&mclist
->list
);
1020 } else if (mclist
->action
== MCLIST_ADD
) {
1021 /* attach the address */
1022 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1023 /* needed for B0 steering support */
1024 mc_list
[5] = priv
->port
;
1025 err
= mlx4_multicast_attach(mdev
->dev
,
1026 &priv
->rss_map
.indir_qp
,
1032 en_err(priv
, "Fail to attach multicast address\n");
1034 err
= mlx4_en_tunnel_steer_add(priv
, &mc_list
[10], priv
->base_qpn
,
1035 &mclist
->tunnel_reg_id
);
1037 en_err(priv
, "Failed to attach multicast address\n");
1043 static void mlx4_en_do_uc_filter(struct mlx4_en_priv
*priv
,
1044 struct net_device
*dev
,
1045 struct mlx4_en_dev
*mdev
)
1047 struct netdev_hw_addr
*ha
;
1048 struct mlx4_mac_entry
*entry
;
1049 struct hlist_node
*tmp
;
1053 struct hlist_head
*bucket
;
1058 /* Note that we do not need to protect our mac_hash traversal with rcu,
1059 * since all modification code is protected by mdev->state_lock
1062 /* find what to remove */
1063 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
) {
1064 bucket
= &priv
->mac_hash
[i
];
1065 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
1067 netdev_for_each_uc_addr(ha
, dev
) {
1068 if (ether_addr_equal_64bits(entry
->mac
,
1075 /* MAC address of the port is not in uc list */
1076 if (ether_addr_equal_64bits(entry
->mac
,
1081 mac
= mlx4_mac_to_u64(entry
->mac
);
1082 mlx4_en_uc_steer_release(priv
, entry
->mac
,
1085 mlx4_unregister_mac(mdev
->dev
, priv
->port
, mac
);
1087 hlist_del_rcu(&entry
->hlist
);
1088 kfree_rcu(entry
, rcu
);
1089 en_dbg(DRV
, priv
, "Removed MAC %pM on port:%d\n",
1090 entry
->mac
, priv
->port
);
1096 /* if we didn't remove anything, there is no use in trying to add
1097 * again once we are in a forced promisc mode state
1099 if ((priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
) && 0 == removed
)
1102 prev_flags
= priv
->flags
;
1103 priv
->flags
&= ~MLX4_EN_FLAG_FORCE_PROMISC
;
1105 /* find what to add */
1106 netdev_for_each_uc_addr(ha
, dev
) {
1108 bucket
= &priv
->mac_hash
[ha
->addr
[MLX4_EN_MAC_HASH_IDX
]];
1109 hlist_for_each_entry(entry
, bucket
, hlist
) {
1110 if (ether_addr_equal_64bits(entry
->mac
, ha
->addr
)) {
1117 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
1119 en_err(priv
, "Failed adding MAC %pM on port:%d (out of memory)\n",
1120 ha
->addr
, priv
->port
);
1121 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1124 mac
= mlx4_mac_to_u64(ha
->addr
);
1125 memcpy(entry
->mac
, ha
->addr
, ETH_ALEN
);
1126 err
= mlx4_register_mac(mdev
->dev
, priv
->port
, mac
);
1128 en_err(priv
, "Failed registering MAC %pM on port %d: %d\n",
1129 ha
->addr
, priv
->port
, err
);
1131 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1134 err
= mlx4_en_uc_steer_add(priv
, ha
->addr
,
1138 en_err(priv
, "Failed adding MAC %pM on port %d: %d\n",
1139 ha
->addr
, priv
->port
, err
);
1140 mlx4_unregister_mac(mdev
->dev
, priv
->port
, mac
);
1142 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1145 unsigned int mac_hash
;
1146 en_dbg(DRV
, priv
, "Added MAC %pM on port:%d\n",
1147 ha
->addr
, priv
->port
);
1148 mac_hash
= ha
->addr
[MLX4_EN_MAC_HASH_IDX
];
1149 bucket
= &priv
->mac_hash
[mac_hash
];
1150 hlist_add_head_rcu(&entry
->hlist
, bucket
);
1155 if (priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
) {
1156 en_warn(priv
, "Forcing promiscuous mode on port:%d\n",
1158 } else if (prev_flags
& MLX4_EN_FLAG_FORCE_PROMISC
) {
1159 en_warn(priv
, "Stop forcing promiscuous mode on port:%d\n",
1164 static void mlx4_en_do_set_rx_mode(struct work_struct
*work
)
1166 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1168 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1169 struct net_device
*dev
= priv
->dev
;
1171 mutex_lock(&mdev
->state_lock
);
1172 if (!mdev
->device_up
) {
1173 en_dbg(HW
, priv
, "Card is not up, ignoring rx mode change.\n");
1176 if (!priv
->port_up
) {
1177 en_dbg(HW
, priv
, "Port is down, ignoring rx mode change.\n");
1181 if (!netif_carrier_ok(dev
)) {
1182 if (!mlx4_en_QUERY_PORT(mdev
, priv
->port
)) {
1183 if (priv
->port_state
.link_state
) {
1184 priv
->last_link_state
= MLX4_DEV_EVENT_PORT_UP
;
1185 netif_carrier_on(dev
);
1186 en_dbg(LINK
, priv
, "Link Up\n");
1191 if (dev
->priv_flags
& IFF_UNICAST_FLT
)
1192 mlx4_en_do_uc_filter(priv
, dev
, mdev
);
1194 /* Promsicuous mode: disable all filters */
1195 if ((dev
->flags
& IFF_PROMISC
) ||
1196 (priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
)) {
1197 mlx4_en_set_promisc_mode(priv
, mdev
);
1201 /* Not in promiscuous mode */
1202 if (priv
->flags
& MLX4_EN_FLAG_PROMISC
)
1203 mlx4_en_clear_promisc_mode(priv
, mdev
);
1205 mlx4_en_do_multicast(priv
, dev
, mdev
);
1207 mutex_unlock(&mdev
->state_lock
);
1210 #ifdef CONFIG_NET_POLL_CONTROLLER
1211 static void mlx4_en_netpoll(struct net_device
*dev
)
1213 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1214 struct mlx4_en_cq
*cq
;
1217 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1218 cq
= priv
->tx_cq
[i
];
1219 napi_schedule(&cq
->napi
);
1224 static int mlx4_en_set_rss_steer_rules(struct mlx4_en_priv
*priv
)
1228 int *qpn
= &priv
->base_qpn
;
1229 struct mlx4_mac_entry
*entry
;
1231 err
= mlx4_en_uc_steer_add(priv
, priv
->dev
->dev_addr
, qpn
, ®_id
);
1235 err
= mlx4_en_tunnel_steer_add(priv
, priv
->dev
->dev_addr
, *qpn
,
1236 &priv
->tunnel_reg_id
);
1240 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
1246 memcpy(entry
->mac
, priv
->dev
->dev_addr
, sizeof(entry
->mac
));
1247 memcpy(priv
->current_mac
, entry
->mac
, sizeof(priv
->current_mac
));
1248 entry
->reg_id
= reg_id
;
1249 hlist_add_head_rcu(&entry
->hlist
,
1250 &priv
->mac_hash
[entry
->mac
[MLX4_EN_MAC_HASH_IDX
]]);
1255 if (priv
->tunnel_reg_id
)
1256 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
1259 mlx4_en_uc_steer_release(priv
, priv
->dev
->dev_addr
, *qpn
, reg_id
);
1263 static void mlx4_en_delete_rss_steer_rules(struct mlx4_en_priv
*priv
)
1267 int qpn
= priv
->base_qpn
;
1268 struct hlist_head
*bucket
;
1269 struct hlist_node
*tmp
;
1270 struct mlx4_mac_entry
*entry
;
1272 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
) {
1273 bucket
= &priv
->mac_hash
[i
];
1274 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
1275 mac
= mlx4_mac_to_u64(entry
->mac
);
1276 en_dbg(DRV
, priv
, "Registering MAC:%pM for deleting\n",
1278 mlx4_en_uc_steer_release(priv
, entry
->mac
,
1279 qpn
, entry
->reg_id
);
1281 mlx4_unregister_mac(priv
->mdev
->dev
, priv
->port
, mac
);
1282 hlist_del_rcu(&entry
->hlist
);
1283 kfree_rcu(entry
, rcu
);
1287 if (priv
->tunnel_reg_id
) {
1288 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
1289 priv
->tunnel_reg_id
= 0;
1293 static void mlx4_en_tx_timeout(struct net_device
*dev
)
1295 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1296 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1299 if (netif_msg_timer(priv
))
1300 en_warn(priv
, "Tx timeout called on port:%d\n", priv
->port
);
1302 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1303 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev
, i
)))
1305 en_warn(priv
, "TX timeout on queue: %d, QP: 0x%x, CQ: 0x%x, Cons: 0x%x, Prod: 0x%x\n",
1306 i
, priv
->tx_ring
[i
]->qpn
, priv
->tx_ring
[i
]->cqn
,
1307 priv
->tx_ring
[i
]->cons
, priv
->tx_ring
[i
]->prod
);
1310 priv
->port_stats
.tx_timeout
++;
1311 en_dbg(DRV
, priv
, "Scheduling watchdog\n");
1312 queue_work(mdev
->workqueue
, &priv
->watchdog_task
);
1316 static struct rtnl_link_stats64
*
1317 mlx4_en_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
1319 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1321 spin_lock_bh(&priv
->stats_lock
);
1322 netdev_stats_to_stats64(stats
, &dev
->stats
);
1323 spin_unlock_bh(&priv
->stats_lock
);
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 static void mlx4_en_init_recycle_ring(struct mlx4_en_priv
*priv
,
1529 struct mlx4_en_tx_ring
*tx_ring
= priv
->tx_ring
[tx_ring_idx
];
1532 rr_index
= (priv
->xdp_ring_num
- priv
->tx_ring_num
) + tx_ring_idx
;
1533 if (rr_index
>= 0) {
1534 tx_ring
->free_tx_desc
= mlx4_en_recycle_tx_desc
;
1535 tx_ring
->recycle_ring
= priv
->rx_ring
[rr_index
];
1537 "Set tx_ring[%d]->recycle_ring = rx_ring[%d]\n",
1538 tx_ring_idx
, rr_index
);
1540 tx_ring
->recycle_ring
= NULL
;
1544 int mlx4_en_start_port(struct net_device
*dev
)
1546 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1547 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1548 struct mlx4_en_cq
*cq
;
1549 struct mlx4_en_tx_ring
*tx_ring
;
1555 u8 mc_list
[16] = {0};
1557 if (priv
->port_up
) {
1558 en_dbg(DRV
, priv
, "start port called while port already up\n");
1562 INIT_LIST_HEAD(&priv
->mc_list
);
1563 INIT_LIST_HEAD(&priv
->curr_list
);
1564 INIT_LIST_HEAD(&priv
->ethtool_list
);
1565 memset(&priv
->ethtool_rules
[0], 0,
1566 sizeof(struct ethtool_flow_id
) * MAX_NUM_OF_FS_RULES
);
1568 /* Calculate Rx buf size */
1569 dev
->mtu
= min(dev
->mtu
, priv
->max_mtu
);
1570 mlx4_en_calc_rx_buf(dev
);
1571 en_dbg(DRV
, priv
, "Rx buf size:%d\n", priv
->rx_skb_size
);
1573 /* Configure rx cq's and rings */
1574 err
= mlx4_en_activate_rx_rings(priv
);
1576 en_err(priv
, "Failed to activate RX rings\n");
1579 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1580 cq
= priv
->rx_cq
[i
];
1582 err
= mlx4_en_init_affinity_hint(priv
, i
);
1584 en_err(priv
, "Failed preparing IRQ affinity hint\n");
1588 err
= mlx4_en_activate_cq(priv
, cq
, i
);
1590 en_err(priv
, "Failed activating Rx CQ\n");
1591 mlx4_en_free_affinity_hint(priv
, i
);
1595 for (j
= 0; j
< cq
->size
; j
++) {
1596 struct mlx4_cqe
*cqe
= NULL
;
1598 cqe
= mlx4_en_get_cqe(cq
->buf
, j
, priv
->cqe_size
) +
1600 cqe
->owner_sr_opcode
= MLX4_CQE_OWNER_MASK
;
1603 err
= mlx4_en_set_cq_moder(priv
, cq
);
1605 en_err(priv
, "Failed setting cq moderation parameters\n");
1606 mlx4_en_deactivate_cq(priv
, cq
);
1607 mlx4_en_free_affinity_hint(priv
, i
);
1610 mlx4_en_arm_cq(priv
, cq
);
1611 priv
->rx_ring
[i
]->cqn
= cq
->mcq
.cqn
;
1616 en_dbg(DRV
, priv
, "Getting qp number for port %d\n", priv
->port
);
1617 err
= mlx4_en_get_qp(priv
);
1619 en_err(priv
, "Failed getting eth qp\n");
1622 mdev
->mac_removed
[priv
->port
] = 0;
1624 priv
->counter_index
=
1625 mlx4_get_default_counter_index(mdev
->dev
, priv
->port
);
1627 err
= mlx4_en_config_rss_steer(priv
);
1629 en_err(priv
, "Failed configuring rss steering\n");
1633 err
= mlx4_en_create_drop_qp(priv
);
1637 /* Configure tx cq's and rings */
1638 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1640 cq
= priv
->tx_cq
[i
];
1641 err
= mlx4_en_activate_cq(priv
, cq
, i
);
1643 en_err(priv
, "Failed allocating Tx CQ\n");
1646 err
= mlx4_en_set_cq_moder(priv
, cq
);
1648 en_err(priv
, "Failed setting cq moderation parameters\n");
1649 mlx4_en_deactivate_cq(priv
, cq
);
1652 en_dbg(DRV
, priv
, "Resetting index of collapsed CQ:%d to -1\n", i
);
1653 cq
->buf
->wqe_index
= cpu_to_be16(0xffff);
1655 /* Configure ring */
1656 tx_ring
= priv
->tx_ring
[i
];
1657 err
= mlx4_en_activate_tx_ring(priv
, tx_ring
, cq
->mcq
.cqn
,
1658 i
/ priv
->num_tx_rings_p_up
);
1660 en_err(priv
, "Failed allocating Tx ring\n");
1661 mlx4_en_deactivate_cq(priv
, cq
);
1664 tx_ring
->tx_queue
= netdev_get_tx_queue(dev
, i
);
1666 mlx4_en_init_recycle_ring(priv
, i
);
1668 /* Arm CQ for TX completions */
1669 mlx4_en_arm_cq(priv
, cq
);
1671 /* Set initial ownership of all Tx TXBBs to SW (1) */
1672 for (j
= 0; j
< tx_ring
->buf_size
; j
+= STAMP_STRIDE
)
1673 *((u32
*) (tx_ring
->buf
+ j
)) = 0xffffffff;
1677 /* Configure port */
1678 err
= mlx4_SET_PORT_general(mdev
->dev
, priv
->port
,
1679 priv
->rx_skb_size
+ ETH_FCS_LEN
,
1680 priv
->prof
->tx_pause
,
1682 priv
->prof
->rx_pause
,
1683 priv
->prof
->rx_ppp
);
1685 en_err(priv
, "Failed setting port general configurations for port %d, with error %d\n",
1689 /* Set default qp number */
1690 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
, priv
->port
, priv
->base_qpn
, 0);
1692 en_err(priv
, "Failed setting default qp numbers\n");
1696 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
1697 err
= mlx4_SET_PORT_VXLAN(mdev
->dev
, priv
->port
, VXLAN_STEER_BY_OUTER_MAC
, 1);
1699 en_err(priv
, "Failed setting port L2 tunnel configuration, err %d\n",
1706 en_dbg(HW
, priv
, "Initializing port\n");
1707 err
= mlx4_INIT_PORT(mdev
->dev
, priv
->port
);
1709 en_err(priv
, "Failed Initializing port\n");
1713 /* Set Unicast and VXLAN steering rules */
1714 if (mdev
->dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
&&
1715 mlx4_en_set_rss_steer_rules(priv
))
1716 mlx4_warn(mdev
, "Failed setting steering rules\n");
1718 /* Attach rx QP to bradcast address */
1719 eth_broadcast_addr(&mc_list
[10]);
1720 mc_list
[5] = priv
->port
; /* needed for B0 steering support */
1721 if (mlx4_multicast_attach(mdev
->dev
, &priv
->rss_map
.indir_qp
, mc_list
,
1722 priv
->port
, 0, MLX4_PROT_ETH
,
1723 &priv
->broadcast_id
))
1724 mlx4_warn(mdev
, "Failed Attaching Broadcast\n");
1726 /* Must redo promiscuous mode setup. */
1727 priv
->flags
&= ~(MLX4_EN_FLAG_PROMISC
| MLX4_EN_FLAG_MC_PROMISC
);
1729 /* Schedule multicast task to populate multicast list */
1730 queue_work(mdev
->workqueue
, &priv
->rx_mode_task
);
1732 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
1733 udp_tunnel_get_rx_info(dev
);
1735 priv
->port_up
= true;
1736 netif_tx_start_all_queues(dev
);
1737 netif_device_attach(dev
);
1742 while (tx_index
--) {
1743 mlx4_en_deactivate_tx_ring(priv
, priv
->tx_ring
[tx_index
]);
1744 mlx4_en_deactivate_cq(priv
, priv
->tx_cq
[tx_index
]);
1746 mlx4_en_destroy_drop_qp(priv
);
1748 mlx4_en_release_rss_steer(priv
);
1750 mlx4_en_put_qp(priv
);
1752 while (rx_index
--) {
1753 mlx4_en_deactivate_cq(priv
, priv
->rx_cq
[rx_index
]);
1754 mlx4_en_free_affinity_hint(priv
, rx_index
);
1756 for (i
= 0; i
< priv
->rx_ring_num
; i
++)
1757 mlx4_en_deactivate_rx_ring(priv
, priv
->rx_ring
[i
]);
1759 return err
; /* need to close devices */
1763 void mlx4_en_stop_port(struct net_device
*dev
, int detach
)
1765 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1766 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1767 struct mlx4_en_mc_list
*mclist
, *tmp
;
1768 struct ethtool_flow_id
*flow
, *tmp_flow
;
1770 u8 mc_list
[16] = {0};
1772 if (!priv
->port_up
) {
1773 en_dbg(DRV
, priv
, "stop port called while port already down\n");
1778 mlx4_CLOSE_PORT(mdev
->dev
, priv
->port
);
1780 /* Synchronize with tx routine */
1781 netif_tx_lock_bh(dev
);
1783 netif_device_detach(dev
);
1784 netif_tx_stop_all_queues(dev
);
1785 netif_tx_unlock_bh(dev
);
1787 netif_tx_disable(dev
);
1789 /* Set port as not active */
1790 priv
->port_up
= false;
1791 priv
->counter_index
= MLX4_SINK_COUNTER_INDEX(mdev
->dev
);
1793 /* Promsicuous mode */
1794 if (mdev
->dev
->caps
.steering_mode
==
1795 MLX4_STEERING_MODE_DEVICE_MANAGED
) {
1796 priv
->flags
&= ~(MLX4_EN_FLAG_PROMISC
|
1797 MLX4_EN_FLAG_MC_PROMISC
);
1798 mlx4_flow_steer_promisc_remove(mdev
->dev
,
1800 MLX4_FS_ALL_DEFAULT
);
1801 mlx4_flow_steer_promisc_remove(mdev
->dev
,
1803 MLX4_FS_MC_DEFAULT
);
1804 } else if (priv
->flags
& MLX4_EN_FLAG_PROMISC
) {
1805 priv
->flags
&= ~MLX4_EN_FLAG_PROMISC
;
1807 /* Disable promiscouos mode */
1808 mlx4_unicast_promisc_remove(mdev
->dev
, priv
->base_qpn
,
1811 /* Disable Multicast promisc */
1812 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
1813 mlx4_multicast_promisc_remove(mdev
->dev
, priv
->base_qpn
,
1815 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
1819 /* Detach All multicasts */
1820 eth_broadcast_addr(&mc_list
[10]);
1821 mc_list
[5] = priv
->port
; /* needed for B0 steering support */
1822 mlx4_multicast_detach(mdev
->dev
, &priv
->rss_map
.indir_qp
, mc_list
,
1823 MLX4_PROT_ETH
, priv
->broadcast_id
);
1824 list_for_each_entry(mclist
, &priv
->curr_list
, list
) {
1825 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1826 mc_list
[5] = priv
->port
;
1827 mlx4_multicast_detach(mdev
->dev
, &priv
->rss_map
.indir_qp
,
1828 mc_list
, MLX4_PROT_ETH
, mclist
->reg_id
);
1829 if (mclist
->tunnel_reg_id
)
1830 mlx4_flow_detach(mdev
->dev
, mclist
->tunnel_reg_id
);
1832 mlx4_en_clear_list(dev
);
1833 list_for_each_entry_safe(mclist
, tmp
, &priv
->curr_list
, list
) {
1834 list_del(&mclist
->list
);
1838 /* Flush multicast filter */
1839 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0, 1, MLX4_MCAST_CONFIG
);
1841 /* Remove flow steering rules for the port*/
1842 if (mdev
->dev
->caps
.steering_mode
==
1843 MLX4_STEERING_MODE_DEVICE_MANAGED
) {
1845 list_for_each_entry_safe(flow
, tmp_flow
,
1846 &priv
->ethtool_list
, list
) {
1847 mlx4_flow_detach(mdev
->dev
, flow
->id
);
1848 list_del(&flow
->list
);
1852 mlx4_en_destroy_drop_qp(priv
);
1855 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1856 mlx4_en_deactivate_tx_ring(priv
, priv
->tx_ring
[i
]);
1857 mlx4_en_deactivate_cq(priv
, priv
->tx_cq
[i
]);
1861 for (i
= 0; i
< priv
->tx_ring_num
; i
++)
1862 mlx4_en_free_tx_buf(dev
, priv
->tx_ring
[i
]);
1864 if (mdev
->dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
)
1865 mlx4_en_delete_rss_steer_rules(priv
);
1868 mlx4_en_release_rss_steer(priv
);
1870 /* Unregister Mac address for the port */
1871 mlx4_en_put_qp(priv
);
1872 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN
))
1873 mdev
->mac_removed
[priv
->port
] = 1;
1876 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1877 struct mlx4_en_cq
*cq
= priv
->rx_cq
[i
];
1879 napi_synchronize(&cq
->napi
);
1880 mlx4_en_deactivate_rx_ring(priv
, priv
->rx_ring
[i
]);
1881 mlx4_en_deactivate_cq(priv
, cq
);
1883 mlx4_en_free_affinity_hint(priv
, i
);
1887 static void mlx4_en_restart(struct work_struct
*work
)
1889 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1891 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1892 struct net_device
*dev
= priv
->dev
;
1894 en_dbg(DRV
, priv
, "Watchdog task called for port %d\n", priv
->port
);
1897 mutex_lock(&mdev
->state_lock
);
1898 if (priv
->port_up
) {
1899 mlx4_en_stop_port(dev
, 1);
1900 if (mlx4_en_start_port(dev
))
1901 en_err(priv
, "Failed restarting port %d\n", priv
->port
);
1903 mutex_unlock(&mdev
->state_lock
);
1907 static void mlx4_en_clear_stats(struct net_device
*dev
)
1909 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1910 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1913 if (mlx4_en_DUMP_ETH_STATS(mdev
, priv
->port
, 1))
1914 en_dbg(HW
, priv
, "Failed dumping statistics\n");
1916 memset(&priv
->pstats
, 0, sizeof(priv
->pstats
));
1917 memset(&priv
->pkstats
, 0, sizeof(priv
->pkstats
));
1918 memset(&priv
->port_stats
, 0, sizeof(priv
->port_stats
));
1919 memset(&priv
->rx_flowstats
, 0, sizeof(priv
->rx_flowstats
));
1920 memset(&priv
->tx_flowstats
, 0, sizeof(priv
->tx_flowstats
));
1921 memset(&priv
->rx_priority_flowstats
, 0,
1922 sizeof(priv
->rx_priority_flowstats
));
1923 memset(&priv
->tx_priority_flowstats
, 0,
1924 sizeof(priv
->tx_priority_flowstats
));
1925 memset(&priv
->pf_stats
, 0, sizeof(priv
->pf_stats
));
1927 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1928 priv
->tx_ring
[i
]->bytes
= 0;
1929 priv
->tx_ring
[i
]->packets
= 0;
1930 priv
->tx_ring
[i
]->tx_csum
= 0;
1931 priv
->tx_ring
[i
]->tx_dropped
= 0;
1932 priv
->tx_ring
[i
]->queue_stopped
= 0;
1933 priv
->tx_ring
[i
]->wake_queue
= 0;
1934 priv
->tx_ring
[i
]->tso_packets
= 0;
1935 priv
->tx_ring
[i
]->xmit_more
= 0;
1937 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1938 priv
->rx_ring
[i
]->bytes
= 0;
1939 priv
->rx_ring
[i
]->packets
= 0;
1940 priv
->rx_ring
[i
]->csum_ok
= 0;
1941 priv
->rx_ring
[i
]->csum_none
= 0;
1942 priv
->rx_ring
[i
]->csum_complete
= 0;
1946 static int mlx4_en_open(struct net_device
*dev
)
1948 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1949 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1952 mutex_lock(&mdev
->state_lock
);
1954 if (!mdev
->device_up
) {
1955 en_err(priv
, "Cannot open - device down/disabled\n");
1960 /* Reset HW statistics and SW counters */
1961 mlx4_en_clear_stats(dev
);
1963 err
= mlx4_en_start_port(dev
);
1965 en_err(priv
, "Failed starting port:%d\n", priv
->port
);
1968 mutex_unlock(&mdev
->state_lock
);
1973 static int mlx4_en_close(struct net_device
*dev
)
1975 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1976 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1978 en_dbg(IFDOWN
, priv
, "Close port called\n");
1980 mutex_lock(&mdev
->state_lock
);
1982 mlx4_en_stop_port(dev
, 0);
1983 netif_carrier_off(dev
);
1985 mutex_unlock(&mdev
->state_lock
);
1989 static void mlx4_en_free_resources(struct mlx4_en_priv
*priv
)
1993 #ifdef CONFIG_RFS_ACCEL
1994 priv
->dev
->rx_cpu_rmap
= NULL
;
1997 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1998 if (priv
->tx_ring
&& priv
->tx_ring
[i
])
1999 mlx4_en_destroy_tx_ring(priv
, &priv
->tx_ring
[i
]);
2000 if (priv
->tx_cq
&& priv
->tx_cq
[i
])
2001 mlx4_en_destroy_cq(priv
, &priv
->tx_cq
[i
]);
2004 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2005 if (priv
->rx_ring
[i
])
2006 mlx4_en_destroy_rx_ring(priv
, &priv
->rx_ring
[i
],
2007 priv
->prof
->rx_ring_size
, priv
->stride
);
2009 mlx4_en_destroy_cq(priv
, &priv
->rx_cq
[i
]);
2014 static int mlx4_en_alloc_resources(struct mlx4_en_priv
*priv
)
2016 struct mlx4_en_port_profile
*prof
= priv
->prof
;
2020 /* Create tx Rings */
2021 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
2022 node
= cpu_to_node(i
% num_online_cpus());
2023 if (mlx4_en_create_cq(priv
, &priv
->tx_cq
[i
],
2024 prof
->tx_ring_size
, i
, TX
, node
))
2027 if (mlx4_en_create_tx_ring(priv
, &priv
->tx_ring
[i
],
2028 prof
->tx_ring_size
, TXBB_SIZE
,
2033 /* Create rx Rings */
2034 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2035 node
= cpu_to_node(i
% num_online_cpus());
2036 if (mlx4_en_create_cq(priv
, &priv
->rx_cq
[i
],
2037 prof
->rx_ring_size
, i
, RX
, node
))
2040 if (mlx4_en_create_rx_ring(priv
, &priv
->rx_ring
[i
],
2041 prof
->rx_ring_size
, priv
->stride
,
2046 #ifdef CONFIG_RFS_ACCEL
2047 priv
->dev
->rx_cpu_rmap
= mlx4_get_cpu_rmap(priv
->mdev
->dev
, priv
->port
);
2053 en_err(priv
, "Failed to allocate NIC resources\n");
2054 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2055 if (priv
->rx_ring
[i
])
2056 mlx4_en_destroy_rx_ring(priv
, &priv
->rx_ring
[i
],
2060 mlx4_en_destroy_cq(priv
, &priv
->rx_cq
[i
]);
2062 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
2063 if (priv
->tx_ring
[i
])
2064 mlx4_en_destroy_tx_ring(priv
, &priv
->tx_ring
[i
]);
2066 mlx4_en_destroy_cq(priv
, &priv
->tx_cq
[i
]);
2071 static void mlx4_en_shutdown(struct net_device
*dev
)
2074 netif_device_detach(dev
);
2079 static int mlx4_en_copy_priv(struct mlx4_en_priv
*dst
,
2080 struct mlx4_en_priv
*src
,
2081 struct mlx4_en_port_profile
*prof
)
2083 memcpy(&dst
->hwtstamp_config
, &prof
->hwtstamp_config
,
2084 sizeof(dst
->hwtstamp_config
));
2085 dst
->num_tx_rings_p_up
= src
->mdev
->profile
.num_tx_rings_p_up
;
2086 dst
->tx_ring_num
= prof
->tx_ring_num
;
2087 dst
->rx_ring_num
= prof
->rx_ring_num
;
2088 dst
->flags
= prof
->flags
;
2089 dst
->mdev
= src
->mdev
;
2090 dst
->port
= src
->port
;
2091 dst
->dev
= src
->dev
;
2093 dst
->stride
= roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc
) +
2094 DS_SIZE
* MLX4_EN_MAX_RX_FRAGS
);
2096 dst
->tx_ring
= kzalloc(sizeof(struct mlx4_en_tx_ring
*) * MAX_TX_RINGS
,
2101 dst
->tx_cq
= kzalloc(sizeof(struct mlx4_en_cq
*) * MAX_TX_RINGS
,
2104 kfree(dst
->tx_ring
);
2110 static void mlx4_en_update_priv(struct mlx4_en_priv
*dst
,
2111 struct mlx4_en_priv
*src
)
2113 memcpy(dst
->rx_ring
, src
->rx_ring
,
2114 sizeof(struct mlx4_en_rx_ring
*) * src
->rx_ring_num
);
2115 memcpy(dst
->rx_cq
, src
->rx_cq
,
2116 sizeof(struct mlx4_en_cq
*) * src
->rx_ring_num
);
2117 memcpy(&dst
->hwtstamp_config
, &src
->hwtstamp_config
,
2118 sizeof(dst
->hwtstamp_config
));
2119 dst
->tx_ring_num
= src
->tx_ring_num
;
2120 dst
->rx_ring_num
= src
->rx_ring_num
;
2121 dst
->tx_ring
= src
->tx_ring
;
2122 dst
->tx_cq
= src
->tx_cq
;
2123 memcpy(dst
->prof
, src
->prof
, sizeof(struct mlx4_en_port_profile
));
2126 int mlx4_en_try_alloc_resources(struct mlx4_en_priv
*priv
,
2127 struct mlx4_en_priv
*tmp
,
2128 struct mlx4_en_port_profile
*prof
)
2130 mlx4_en_copy_priv(tmp
, priv
, prof
);
2132 if (mlx4_en_alloc_resources(tmp
)) {
2134 "%s: Resource allocation failed, using previous configuration\n",
2136 kfree(tmp
->tx_ring
);
2143 void mlx4_en_safe_replace_resources(struct mlx4_en_priv
*priv
,
2144 struct mlx4_en_priv
*tmp
)
2146 mlx4_en_free_resources(priv
);
2147 mlx4_en_update_priv(priv
, tmp
);
2150 void mlx4_en_destroy_netdev(struct net_device
*dev
)
2152 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2153 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2154 bool shutdown
= mdev
->dev
->persist
->interface_state
&
2155 MLX4_INTERFACE_STATE_SHUTDOWN
;
2157 en_dbg(DRV
, priv
, "Destroying netdev on port:%d\n", priv
->port
);
2159 /* Unregister device - this will close the port if it was up */
2160 if (priv
->registered
) {
2161 devlink_port_type_clear(mlx4_get_devlink_port(mdev
->dev
,
2164 mlx4_en_shutdown(dev
);
2166 unregister_netdev(dev
);
2169 if (priv
->allocated
)
2170 mlx4_free_hwq_res(mdev
->dev
, &priv
->res
, MLX4_EN_PAGE_SIZE
);
2172 cancel_delayed_work(&priv
->stats_task
);
2173 cancel_delayed_work(&priv
->service_task
);
2174 /* flush any pending task for this netdev */
2175 flush_workqueue(mdev
->workqueue
);
2177 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
)
2178 mlx4_en_remove_timestamp(mdev
);
2180 /* Detach the netdev so tasks would not attempt to access it */
2181 mutex_lock(&mdev
->state_lock
);
2182 mdev
->pndev
[priv
->port
] = NULL
;
2183 mdev
->upper
[priv
->port
] = NULL
;
2184 mutex_unlock(&mdev
->state_lock
);
2186 #ifdef CONFIG_RFS_ACCEL
2187 mlx4_en_cleanup_filters(priv
);
2190 mlx4_en_free_resources(priv
);
2192 kfree(priv
->tx_ring
);
2199 static int mlx4_en_change_mtu(struct net_device
*dev
, int new_mtu
)
2201 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2202 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2205 en_dbg(DRV
, priv
, "Change MTU called - current:%d new:%d\n",
2208 if ((new_mtu
< MLX4_EN_MIN_MTU
) || (new_mtu
> priv
->max_mtu
)) {
2209 en_err(priv
, "Bad MTU size:%d.\n", new_mtu
);
2212 if (priv
->xdp_ring_num
&& MLX4_EN_EFF_MTU(new_mtu
) > FRAG_SZ0
) {
2213 en_err(priv
, "MTU size:%d requires frags but XDP running\n",
2219 if (netif_running(dev
)) {
2220 mutex_lock(&mdev
->state_lock
);
2221 if (!mdev
->device_up
) {
2222 /* NIC is probably restarting - let watchdog task reset
2224 en_dbg(DRV
, priv
, "Change MTU called with card down!?\n");
2226 mlx4_en_stop_port(dev
, 1);
2227 err
= mlx4_en_start_port(dev
);
2229 en_err(priv
, "Failed restarting port:%d\n",
2231 queue_work(mdev
->workqueue
, &priv
->watchdog_task
);
2234 mutex_unlock(&mdev
->state_lock
);
2239 static int mlx4_en_hwtstamp_set(struct net_device
*dev
, struct ifreq
*ifr
)
2241 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2242 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2243 struct hwtstamp_config config
;
2245 if (copy_from_user(&config
, ifr
->ifr_data
, sizeof(config
)))
2248 /* reserved for future extensions */
2252 /* device doesn't support time stamping */
2253 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
))
2256 /* TX HW timestamp */
2257 switch (config
.tx_type
) {
2258 case HWTSTAMP_TX_OFF
:
2259 case HWTSTAMP_TX_ON
:
2265 /* RX HW timestamp */
2266 switch (config
.rx_filter
) {
2267 case HWTSTAMP_FILTER_NONE
:
2269 case HWTSTAMP_FILTER_ALL
:
2270 case HWTSTAMP_FILTER_SOME
:
2271 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT
:
2272 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC
:
2273 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
:
2274 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT
:
2275 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC
:
2276 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
:
2277 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT
:
2278 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC
:
2279 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
:
2280 case HWTSTAMP_FILTER_PTP_V2_EVENT
:
2281 case HWTSTAMP_FILTER_PTP_V2_SYNC
:
2282 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
:
2283 config
.rx_filter
= HWTSTAMP_FILTER_ALL
;
2289 if (mlx4_en_reset_config(dev
, config
, dev
->features
)) {
2290 config
.tx_type
= HWTSTAMP_TX_OFF
;
2291 config
.rx_filter
= HWTSTAMP_FILTER_NONE
;
2294 return copy_to_user(ifr
->ifr_data
, &config
,
2295 sizeof(config
)) ? -EFAULT
: 0;
2298 static int mlx4_en_hwtstamp_get(struct net_device
*dev
, struct ifreq
*ifr
)
2300 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2302 return copy_to_user(ifr
->ifr_data
, &priv
->hwtstamp_config
,
2303 sizeof(priv
->hwtstamp_config
)) ? -EFAULT
: 0;
2306 static int mlx4_en_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
2310 return mlx4_en_hwtstamp_set(dev
, ifr
);
2312 return mlx4_en_hwtstamp_get(dev
, ifr
);
2318 static netdev_features_t
mlx4_en_fix_features(struct net_device
*netdev
,
2319 netdev_features_t features
)
2321 struct mlx4_en_priv
*en_priv
= netdev_priv(netdev
);
2322 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2324 /* Since there is no support for separate RX C-TAG/S-TAG vlan accel
2325 * enable/disable make sure S-TAG flag is always in same state as
2328 if (features
& NETIF_F_HW_VLAN_CTAG_RX
&&
2329 !(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN
))
2330 features
|= NETIF_F_HW_VLAN_STAG_RX
;
2332 features
&= ~NETIF_F_HW_VLAN_STAG_RX
;
2337 static int mlx4_en_set_features(struct net_device
*netdev
,
2338 netdev_features_t features
)
2340 struct mlx4_en_priv
*priv
= netdev_priv(netdev
);
2344 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_RXFCS
)) {
2345 en_info(priv
, "Turn %s RX-FCS\n",
2346 (features
& NETIF_F_RXFCS
) ? "ON" : "OFF");
2350 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_RXALL
)) {
2351 u8 ignore_fcs_value
= (features
& NETIF_F_RXALL
) ? 1 : 0;
2353 en_info(priv
, "Turn %s RX-ALL\n",
2354 ignore_fcs_value
? "ON" : "OFF");
2355 ret
= mlx4_SET_PORT_fcs_check(priv
->mdev
->dev
,
2356 priv
->port
, ignore_fcs_value
);
2361 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_HW_VLAN_CTAG_RX
)) {
2362 en_info(priv
, "Turn %s RX vlan strip offload\n",
2363 (features
& NETIF_F_HW_VLAN_CTAG_RX
) ? "ON" : "OFF");
2367 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_HW_VLAN_CTAG_TX
))
2368 en_info(priv
, "Turn %s TX vlan strip offload\n",
2369 (features
& NETIF_F_HW_VLAN_CTAG_TX
) ? "ON" : "OFF");
2371 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_HW_VLAN_STAG_TX
))
2372 en_info(priv
, "Turn %s TX S-VLAN strip offload\n",
2373 (features
& NETIF_F_HW_VLAN_STAG_TX
) ? "ON" : "OFF");
2375 if (DEV_FEATURE_CHANGED(netdev
, features
, NETIF_F_LOOPBACK
)) {
2376 en_info(priv
, "Turn %s loopback\n",
2377 (features
& NETIF_F_LOOPBACK
) ? "ON" : "OFF");
2378 mlx4_en_update_loopback_state(netdev
, features
);
2382 ret
= mlx4_en_reset_config(netdev
, priv
->hwtstamp_config
,
2391 static int mlx4_en_set_vf_mac(struct net_device
*dev
, int queue
, u8
*mac
)
2393 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2394 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2395 u64 mac_u64
= mlx4_mac_to_u64(mac
);
2397 if (is_multicast_ether_addr(mac
))
2400 return mlx4_set_vf_mac(mdev
->dev
, en_priv
->port
, queue
, mac_u64
);
2403 static int mlx4_en_set_vf_vlan(struct net_device
*dev
, int vf
, u16 vlan
, u8 qos
)
2405 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2406 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2408 return mlx4_set_vf_vlan(mdev
->dev
, en_priv
->port
, vf
, vlan
, qos
);
2411 static int mlx4_en_set_vf_rate(struct net_device
*dev
, int vf
, int min_tx_rate
,
2414 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2415 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2417 return mlx4_set_vf_rate(mdev
->dev
, en_priv
->port
, vf
, min_tx_rate
,
2421 static int mlx4_en_set_vf_spoofchk(struct net_device
*dev
, int vf
, bool setting
)
2423 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2424 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2426 return mlx4_set_vf_spoofchk(mdev
->dev
, en_priv
->port
, vf
, setting
);
2429 static int mlx4_en_get_vf_config(struct net_device
*dev
, int vf
, struct ifla_vf_info
*ivf
)
2431 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2432 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2434 return mlx4_get_vf_config(mdev
->dev
, en_priv
->port
, vf
, ivf
);
2437 static int mlx4_en_set_vf_link_state(struct net_device
*dev
, int vf
, int link_state
)
2439 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2440 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2442 return mlx4_set_vf_link_state(mdev
->dev
, en_priv
->port
, vf
, link_state
);
2445 static int mlx4_en_get_vf_stats(struct net_device
*dev
, int vf
,
2446 struct ifla_vf_stats
*vf_stats
)
2448 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2449 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2451 return mlx4_get_vf_stats(mdev
->dev
, en_priv
->port
, vf
, vf_stats
);
2454 #define PORT_ID_BYTE_LEN 8
2455 static int mlx4_en_get_phys_port_id(struct net_device
*dev
,
2456 struct netdev_phys_item_id
*ppid
)
2458 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2459 struct mlx4_dev
*mdev
= priv
->mdev
->dev
;
2461 u64 phys_port_id
= mdev
->caps
.phys_port_id
[priv
->port
];
2466 ppid
->id_len
= sizeof(phys_port_id
);
2467 for (i
= PORT_ID_BYTE_LEN
- 1; i
>= 0; --i
) {
2468 ppid
->id
[i
] = phys_port_id
& 0xff;
2474 static void mlx4_en_add_vxlan_offloads(struct work_struct
*work
)
2477 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
2480 ret
= mlx4_config_vxlan_port(priv
->mdev
->dev
, priv
->vxlan_port
);
2484 ret
= mlx4_SET_PORT_VXLAN(priv
->mdev
->dev
, priv
->port
,
2485 VXLAN_STEER_BY_OUTER_MAC
, 1);
2488 en_err(priv
, "failed setting L2 tunnel configuration ret %d\n", ret
);
2493 priv
->dev
->hw_enc_features
|= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
2495 NETIF_F_TSO
| NETIF_F_TSO6
|
2496 NETIF_F_GSO_UDP_TUNNEL
|
2497 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
2498 NETIF_F_GSO_PARTIAL
;
2501 static void mlx4_en_del_vxlan_offloads(struct work_struct
*work
)
2504 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
2506 /* unset offloads */
2507 priv
->dev
->hw_enc_features
&= ~(NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
2509 NETIF_F_TSO
| NETIF_F_TSO6
|
2510 NETIF_F_GSO_UDP_TUNNEL
|
2511 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
2512 NETIF_F_GSO_PARTIAL
);
2514 ret
= mlx4_SET_PORT_VXLAN(priv
->mdev
->dev
, priv
->port
,
2515 VXLAN_STEER_BY_OUTER_MAC
, 0);
2517 en_err(priv
, "failed setting L2 tunnel configuration ret %d\n", ret
);
2519 priv
->vxlan_port
= 0;
2522 static void mlx4_en_add_vxlan_port(struct net_device
*dev
,
2523 struct udp_tunnel_info
*ti
)
2525 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2526 __be16 port
= ti
->port
;
2527 __be16 current_port
;
2529 if (ti
->type
!= UDP_TUNNEL_TYPE_VXLAN
)
2532 if (ti
->sa_family
!= AF_INET
)
2535 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
2538 current_port
= priv
->vxlan_port
;
2539 if (current_port
&& current_port
!= port
) {
2540 en_warn(priv
, "vxlan port %d configured, can't add port %d\n",
2541 ntohs(current_port
), ntohs(port
));
2545 priv
->vxlan_port
= port
;
2546 queue_work(priv
->mdev
->workqueue
, &priv
->vxlan_add_task
);
2549 static void mlx4_en_del_vxlan_port(struct net_device
*dev
,
2550 struct udp_tunnel_info
*ti
)
2552 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2553 __be16 port
= ti
->port
;
2554 __be16 current_port
;
2556 if (ti
->type
!= UDP_TUNNEL_TYPE_VXLAN
)
2559 if (ti
->sa_family
!= AF_INET
)
2562 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
2565 current_port
= priv
->vxlan_port
;
2566 if (current_port
!= port
) {
2567 en_dbg(DRV
, priv
, "vxlan port %d isn't configured, ignoring\n", ntohs(port
));
2571 queue_work(priv
->mdev
->workqueue
, &priv
->vxlan_del_task
);
2574 static netdev_features_t
mlx4_en_features_check(struct sk_buff
*skb
,
2575 struct net_device
*dev
,
2576 netdev_features_t features
)
2578 features
= vlan_features_check(skb
, features
);
2579 features
= vxlan_features_check(skb
, features
);
2581 /* The ConnectX-3 doesn't support outer IPv6 checksums but it does
2582 * support inner IPv6 checksums and segmentation so we need to
2583 * strip that feature if this is an IPv6 encapsulated frame.
2585 if (skb
->encapsulation
&&
2586 (skb
->ip_summed
== CHECKSUM_PARTIAL
)) {
2587 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2589 if (!priv
->vxlan_port
||
2590 (ip_hdr(skb
)->version
!= 4) ||
2591 (udp_hdr(skb
)->dest
!= priv
->vxlan_port
))
2592 features
&= ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
2598 static int mlx4_en_set_tx_maxrate(struct net_device
*dev
, int queue_index
, u32 maxrate
)
2600 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2601 struct mlx4_en_tx_ring
*tx_ring
= priv
->tx_ring
[queue_index
];
2602 struct mlx4_update_qp_params params
;
2605 if (!(priv
->mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT
))
2608 /* rate provided to us in Mbs, check if it fits into 12 bits, if not use Gbs */
2609 if (maxrate
>> 12) {
2610 params
.rate_unit
= MLX4_QP_RATE_LIMIT_GBS
;
2611 params
.rate_val
= maxrate
/ 1000;
2612 } else if (maxrate
) {
2613 params
.rate_unit
= MLX4_QP_RATE_LIMIT_MBS
;
2614 params
.rate_val
= maxrate
;
2615 } else { /* zero serves to revoke the QP rate-limitation */
2616 params
.rate_unit
= 0;
2617 params
.rate_val
= 0;
2620 err
= mlx4_update_qp(priv
->mdev
->dev
, tx_ring
->qpn
, MLX4_UPDATE_QP_RATE_LIMIT
,
2625 static int mlx4_xdp_set(struct net_device
*dev
, struct bpf_prog
*prog
)
2627 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2628 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2629 struct bpf_prog
*old_prog
;
2635 xdp_ring_num
= prog
? ALIGN(priv
->rx_ring_num
, MLX4_EN_NUM_UP
) : 0;
2637 /* No need to reconfigure buffers when simply swapping the
2638 * program for a new one.
2640 if (priv
->xdp_ring_num
== xdp_ring_num
) {
2642 prog
= bpf_prog_add(prog
, priv
->rx_ring_num
- 1);
2644 return PTR_ERR(prog
);
2646 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2647 /* This xchg is paired with READ_ONCE in the fastpath */
2648 old_prog
= xchg(&priv
->rx_ring
[i
]->xdp_prog
, prog
);
2650 bpf_prog_put(old_prog
);
2655 if (priv
->num_frags
> 1) {
2656 en_err(priv
, "Cannot set XDP if MTU requires multiple frags\n");
2660 if (priv
->tx_ring_num
< xdp_ring_num
+ MLX4_EN_NUM_UP
) {
2662 "Minimum %d tx channels required to run XDP\n",
2663 (xdp_ring_num
+ MLX4_EN_NUM_UP
) / MLX4_EN_NUM_UP
);
2668 prog
= bpf_prog_add(prog
, priv
->rx_ring_num
- 1);
2670 return PTR_ERR(prog
);
2673 mutex_lock(&mdev
->state_lock
);
2674 if (priv
->port_up
) {
2676 mlx4_en_stop_port(dev
, 1);
2679 priv
->xdp_ring_num
= xdp_ring_num
;
2680 netif_set_real_num_tx_queues(dev
, priv
->tx_ring_num
-
2681 priv
->xdp_ring_num
);
2683 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2684 old_prog
= xchg(&priv
->rx_ring
[i
]->xdp_prog
, prog
);
2686 bpf_prog_put(old_prog
);
2690 err
= mlx4_en_start_port(dev
);
2692 en_err(priv
, "Failed starting port %d for XDP change\n",
2694 queue_work(mdev
->workqueue
, &priv
->watchdog_task
);
2698 mutex_unlock(&mdev
->state_lock
);
2702 static bool mlx4_xdp_attached(struct net_device
*dev
)
2704 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2706 return !!priv
->xdp_ring_num
;
2709 static int mlx4_xdp(struct net_device
*dev
, struct netdev_xdp
*xdp
)
2711 switch (xdp
->command
) {
2712 case XDP_SETUP_PROG
:
2713 return mlx4_xdp_set(dev
, xdp
->prog
);
2714 case XDP_QUERY_PROG
:
2715 xdp
->prog_attached
= mlx4_xdp_attached(dev
);
2722 static const struct net_device_ops mlx4_netdev_ops
= {
2723 .ndo_open
= mlx4_en_open
,
2724 .ndo_stop
= mlx4_en_close
,
2725 .ndo_start_xmit
= mlx4_en_xmit
,
2726 .ndo_select_queue
= mlx4_en_select_queue
,
2727 .ndo_get_stats64
= mlx4_en_get_stats64
,
2728 .ndo_set_rx_mode
= mlx4_en_set_rx_mode
,
2729 .ndo_set_mac_address
= mlx4_en_set_mac
,
2730 .ndo_validate_addr
= eth_validate_addr
,
2731 .ndo_change_mtu
= mlx4_en_change_mtu
,
2732 .ndo_do_ioctl
= mlx4_en_ioctl
,
2733 .ndo_tx_timeout
= mlx4_en_tx_timeout
,
2734 .ndo_vlan_rx_add_vid
= mlx4_en_vlan_rx_add_vid
,
2735 .ndo_vlan_rx_kill_vid
= mlx4_en_vlan_rx_kill_vid
,
2736 #ifdef CONFIG_NET_POLL_CONTROLLER
2737 .ndo_poll_controller
= mlx4_en_netpoll
,
2739 .ndo_set_features
= mlx4_en_set_features
,
2740 .ndo_fix_features
= mlx4_en_fix_features
,
2741 .ndo_setup_tc
= __mlx4_en_setup_tc
,
2742 #ifdef CONFIG_RFS_ACCEL
2743 .ndo_rx_flow_steer
= mlx4_en_filter_rfs
,
2745 .ndo_get_phys_port_id
= mlx4_en_get_phys_port_id
,
2746 .ndo_udp_tunnel_add
= mlx4_en_add_vxlan_port
,
2747 .ndo_udp_tunnel_del
= mlx4_en_del_vxlan_port
,
2748 .ndo_features_check
= mlx4_en_features_check
,
2749 .ndo_set_tx_maxrate
= mlx4_en_set_tx_maxrate
,
2750 .ndo_xdp
= mlx4_xdp
,
2753 static const struct net_device_ops mlx4_netdev_ops_master
= {
2754 .ndo_open
= mlx4_en_open
,
2755 .ndo_stop
= mlx4_en_close
,
2756 .ndo_start_xmit
= mlx4_en_xmit
,
2757 .ndo_select_queue
= mlx4_en_select_queue
,
2758 .ndo_get_stats64
= mlx4_en_get_stats64
,
2759 .ndo_set_rx_mode
= mlx4_en_set_rx_mode
,
2760 .ndo_set_mac_address
= mlx4_en_set_mac
,
2761 .ndo_validate_addr
= eth_validate_addr
,
2762 .ndo_change_mtu
= mlx4_en_change_mtu
,
2763 .ndo_tx_timeout
= mlx4_en_tx_timeout
,
2764 .ndo_vlan_rx_add_vid
= mlx4_en_vlan_rx_add_vid
,
2765 .ndo_vlan_rx_kill_vid
= mlx4_en_vlan_rx_kill_vid
,
2766 .ndo_set_vf_mac
= mlx4_en_set_vf_mac
,
2767 .ndo_set_vf_vlan
= mlx4_en_set_vf_vlan
,
2768 .ndo_set_vf_rate
= mlx4_en_set_vf_rate
,
2769 .ndo_set_vf_spoofchk
= mlx4_en_set_vf_spoofchk
,
2770 .ndo_set_vf_link_state
= mlx4_en_set_vf_link_state
,
2771 .ndo_get_vf_stats
= mlx4_en_get_vf_stats
,
2772 .ndo_get_vf_config
= mlx4_en_get_vf_config
,
2773 #ifdef CONFIG_NET_POLL_CONTROLLER
2774 .ndo_poll_controller
= mlx4_en_netpoll
,
2776 .ndo_set_features
= mlx4_en_set_features
,
2777 .ndo_fix_features
= mlx4_en_fix_features
,
2778 .ndo_setup_tc
= __mlx4_en_setup_tc
,
2779 #ifdef CONFIG_RFS_ACCEL
2780 .ndo_rx_flow_steer
= mlx4_en_filter_rfs
,
2782 .ndo_get_phys_port_id
= mlx4_en_get_phys_port_id
,
2783 .ndo_udp_tunnel_add
= mlx4_en_add_vxlan_port
,
2784 .ndo_udp_tunnel_del
= mlx4_en_del_vxlan_port
,
2785 .ndo_features_check
= mlx4_en_features_check
,
2786 .ndo_set_tx_maxrate
= mlx4_en_set_tx_maxrate
,
2787 .ndo_xdp
= mlx4_xdp
,
2790 struct mlx4_en_bond
{
2791 struct work_struct work
;
2792 struct mlx4_en_priv
*priv
;
2794 struct mlx4_port_map port_map
;
2797 static void mlx4_en_bond_work(struct work_struct
*work
)
2799 struct mlx4_en_bond
*bond
= container_of(work
,
2800 struct mlx4_en_bond
,
2803 struct mlx4_dev
*dev
= bond
->priv
->mdev
->dev
;
2805 if (bond
->is_bonded
) {
2806 if (!mlx4_is_bonded(dev
)) {
2807 err
= mlx4_bond(dev
);
2809 en_err(bond
->priv
, "Fail to bond device\n");
2812 err
= mlx4_port_map_set(dev
, &bond
->port_map
);
2814 en_err(bond
->priv
, "Fail to set port map [%d][%d]: %d\n",
2815 bond
->port_map
.port1
,
2816 bond
->port_map
.port2
,
2819 } else if (mlx4_is_bonded(dev
)) {
2820 err
= mlx4_unbond(dev
);
2822 en_err(bond
->priv
, "Fail to unbond device\n");
2824 dev_put(bond
->priv
->dev
);
2828 static int mlx4_en_queue_bond_work(struct mlx4_en_priv
*priv
, int is_bonded
,
2829 u8 v2p_p1
, u8 v2p_p2
)
2831 struct mlx4_en_bond
*bond
= NULL
;
2833 bond
= kzalloc(sizeof(*bond
), GFP_ATOMIC
);
2837 INIT_WORK(&bond
->work
, mlx4_en_bond_work
);
2839 bond
->is_bonded
= is_bonded
;
2840 bond
->port_map
.port1
= v2p_p1
;
2841 bond
->port_map
.port2
= v2p_p2
;
2842 dev_hold(priv
->dev
);
2843 queue_work(priv
->mdev
->workqueue
, &bond
->work
);
2847 int mlx4_en_netdev_event(struct notifier_block
*this,
2848 unsigned long event
, void *ptr
)
2850 struct net_device
*ndev
= netdev_notifier_info_to_dev(ptr
);
2852 struct mlx4_en_dev
*mdev
;
2853 struct mlx4_dev
*dev
;
2854 int i
, num_eth_ports
= 0;
2855 bool do_bond
= true;
2856 struct mlx4_en_priv
*priv
;
2860 if (!net_eq(dev_net(ndev
), &init_net
))
2863 mdev
= container_of(this, struct mlx4_en_dev
, nb
);
2866 /* Go into this mode only when two network devices set on two ports
2867 * of the same mlx4 device are slaves of the same bonding master
2869 mlx4_foreach_port(i
, dev
, MLX4_PORT_TYPE_ETH
) {
2871 if (!port
&& (mdev
->pndev
[i
] == ndev
))
2873 mdev
->upper
[i
] = mdev
->pndev
[i
] ?
2874 netdev_master_upper_dev_get(mdev
->pndev
[i
]) : NULL
;
2875 /* condition not met: network device is a slave */
2876 if (!mdev
->upper
[i
])
2878 if (num_eth_ports
< 2)
2880 /* condition not met: same master */
2881 if (mdev
->upper
[i
] != mdev
->upper
[i
-1])
2884 /* condition not met: 2 salves */
2885 do_bond
= (num_eth_ports
== 2) ? do_bond
: false;
2887 /* handle only events that come with enough info */
2888 if ((do_bond
&& (event
!= NETDEV_BONDING_INFO
)) || !port
)
2891 priv
= netdev_priv(ndev
);
2893 struct netdev_notifier_bonding_info
*notifier_info
= ptr
;
2894 struct netdev_bonding_info
*bonding_info
=
2895 ¬ifier_info
->bonding_info
;
2897 /* required mode 1, 2 or 4 */
2898 if ((bonding_info
->master
.bond_mode
!= BOND_MODE_ACTIVEBACKUP
) &&
2899 (bonding_info
->master
.bond_mode
!= BOND_MODE_XOR
) &&
2900 (bonding_info
->master
.bond_mode
!= BOND_MODE_8023AD
))
2903 /* require exactly 2 slaves */
2904 if (bonding_info
->master
.num_slaves
!= 2)
2909 if (bonding_info
->master
.bond_mode
==
2910 BOND_MODE_ACTIVEBACKUP
) {
2911 /* in active-backup mode virtual ports are
2912 * mapped to the physical port of the active
2914 if (bonding_info
->slave
.state
==
2915 BOND_STATE_BACKUP
) {
2923 } else { /* BOND_STATE_ACTIVE */
2932 } else { /* Active-Active */
2933 /* in active-active mode a virtual port is
2934 * mapped to the native physical port if and only
2935 * if the physical port is up */
2936 __s8 link
= bonding_info
->slave
.link
;
2942 if ((link
== BOND_LINK_UP
) ||
2943 (link
== BOND_LINK_FAIL
)) {
2948 } else { /* BOND_LINK_DOWN || BOND_LINK_BACK */
2958 mlx4_en_queue_bond_work(priv
, do_bond
,
2959 v2p_port1
, v2p_port2
);
2964 void mlx4_en_update_pfc_stats_bitmap(struct mlx4_dev
*dev
,
2965 struct mlx4_en_stats_bitmap
*stats_bitmap
,
2966 u8 rx_ppp
, u8 rx_pause
,
2967 u8 tx_ppp
, u8 tx_pause
)
2969 int last_i
= NUM_MAIN_STATS
+ NUM_PORT_STATS
+ NUM_PF_STATS
;
2971 if (!mlx4_is_slave(dev
) &&
2972 (dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN
)) {
2973 mutex_lock(&stats_bitmap
->mutex
);
2974 bitmap_clear(stats_bitmap
->bitmap
, last_i
, NUM_FLOW_STATS
);
2977 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2978 NUM_FLOW_PRIORITY_STATS_RX
);
2979 last_i
+= NUM_FLOW_PRIORITY_STATS_RX
;
2981 if (rx_pause
&& !(rx_ppp
))
2982 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2984 last_i
+= NUM_FLOW_STATS_RX
;
2987 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2988 NUM_FLOW_PRIORITY_STATS_TX
);
2989 last_i
+= NUM_FLOW_PRIORITY_STATS_TX
;
2991 if (tx_pause
&& !(tx_ppp
))
2992 bitmap_set(stats_bitmap
->bitmap
, last_i
,
2994 last_i
+= NUM_FLOW_STATS_TX
;
2996 mutex_unlock(&stats_bitmap
->mutex
);
3000 void mlx4_en_set_stats_bitmap(struct mlx4_dev
*dev
,
3001 struct mlx4_en_stats_bitmap
*stats_bitmap
,
3002 u8 rx_ppp
, u8 rx_pause
,
3003 u8 tx_ppp
, u8 tx_pause
)
3007 mutex_init(&stats_bitmap
->mutex
);
3008 bitmap_zero(stats_bitmap
->bitmap
, NUM_ALL_STATS
);
3010 if (mlx4_is_slave(dev
)) {
3011 bitmap_set(stats_bitmap
->bitmap
, last_i
+
3012 MLX4_FIND_NETDEV_STAT(rx_packets
), 1);
3013 bitmap_set(stats_bitmap
->bitmap
, last_i
+
3014 MLX4_FIND_NETDEV_STAT(tx_packets
), 1);
3015 bitmap_set(stats_bitmap
->bitmap
, last_i
+
3016 MLX4_FIND_NETDEV_STAT(rx_bytes
), 1);
3017 bitmap_set(stats_bitmap
->bitmap
, last_i
+
3018 MLX4_FIND_NETDEV_STAT(tx_bytes
), 1);
3019 bitmap_set(stats_bitmap
->bitmap
, last_i
+
3020 MLX4_FIND_NETDEV_STAT(rx_dropped
), 1);
3021 bitmap_set(stats_bitmap
->bitmap
, last_i
+
3022 MLX4_FIND_NETDEV_STAT(tx_dropped
), 1);
3024 bitmap_set(stats_bitmap
->bitmap
, last_i
, NUM_MAIN_STATS
);
3026 last_i
+= NUM_MAIN_STATS
;
3028 bitmap_set(stats_bitmap
->bitmap
, last_i
, NUM_PORT_STATS
);
3029 last_i
+= NUM_PORT_STATS
;
3031 if (mlx4_is_master(dev
))
3032 bitmap_set(stats_bitmap
->bitmap
, last_i
,
3034 last_i
+= NUM_PF_STATS
;
3036 mlx4_en_update_pfc_stats_bitmap(dev
, stats_bitmap
,
3039 last_i
+= NUM_FLOW_STATS
;
3041 if (!mlx4_is_slave(dev
))
3042 bitmap_set(stats_bitmap
->bitmap
, last_i
, NUM_PKT_STATS
);
3045 int mlx4_en_init_netdev(struct mlx4_en_dev
*mdev
, int port
,
3046 struct mlx4_en_port_profile
*prof
)
3048 struct net_device
*dev
;
3049 struct mlx4_en_priv
*priv
;
3053 dev
= alloc_etherdev_mqs(sizeof(struct mlx4_en_priv
),
3054 MAX_TX_RINGS
, MAX_RX_RINGS
);
3058 netif_set_real_num_tx_queues(dev
, prof
->tx_ring_num
);
3059 netif_set_real_num_rx_queues(dev
, prof
->rx_ring_num
);
3061 SET_NETDEV_DEV(dev
, &mdev
->dev
->persist
->pdev
->dev
);
3062 dev
->dev_port
= port
- 1;
3065 * Initialize driver private data
3068 priv
= netdev_priv(dev
);
3069 memset(priv
, 0, sizeof(struct mlx4_en_priv
));
3070 priv
->counter_index
= MLX4_SINK_COUNTER_INDEX(mdev
->dev
);
3071 spin_lock_init(&priv
->stats_lock
);
3072 INIT_WORK(&priv
->rx_mode_task
, mlx4_en_do_set_rx_mode
);
3073 INIT_WORK(&priv
->watchdog_task
, mlx4_en_restart
);
3074 INIT_WORK(&priv
->linkstate_task
, mlx4_en_linkstate
);
3075 INIT_DELAYED_WORK(&priv
->stats_task
, mlx4_en_do_get_stats
);
3076 INIT_DELAYED_WORK(&priv
->service_task
, mlx4_en_service_task
);
3077 INIT_WORK(&priv
->vxlan_add_task
, mlx4_en_add_vxlan_offloads
);
3078 INIT_WORK(&priv
->vxlan_del_task
, mlx4_en_del_vxlan_offloads
);
3079 #ifdef CONFIG_RFS_ACCEL
3080 INIT_LIST_HEAD(&priv
->filters
);
3081 spin_lock_init(&priv
->filters_lock
);
3086 priv
->ddev
= &mdev
->pdev
->dev
;
3089 priv
->port_up
= false;
3090 priv
->flags
= prof
->flags
;
3091 priv
->pflags
= MLX4_EN_PRIV_FLAGS_BLUEFLAME
;
3092 priv
->ctrl_flags
= cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE
|
3093 MLX4_WQE_CTRL_SOLICITED
);
3094 priv
->num_tx_rings_p_up
= mdev
->profile
.num_tx_rings_p_up
;
3095 priv
->tx_ring_num
= prof
->tx_ring_num
;
3096 priv
->tx_work_limit
= MLX4_EN_DEFAULT_TX_WORK
;
3097 netdev_rss_key_fill(priv
->rss_key
, sizeof(priv
->rss_key
));
3099 priv
->tx_ring
= kzalloc(sizeof(struct mlx4_en_tx_ring
*) * MAX_TX_RINGS
,
3101 if (!priv
->tx_ring
) {
3105 priv
->tx_cq
= kzalloc(sizeof(struct mlx4_en_cq
*) * MAX_TX_RINGS
,
3111 priv
->rx_ring_num
= prof
->rx_ring_num
;
3112 priv
->cqe_factor
= (mdev
->dev
->caps
.cqe_size
== 64) ? 1 : 0;
3113 priv
->cqe_size
= mdev
->dev
->caps
.cqe_size
;
3114 priv
->mac_index
= -1;
3115 priv
->msg_enable
= MLX4_EN_MSG_LEVEL
;
3116 #ifdef CONFIG_MLX4_EN_DCB
3117 if (!mlx4_is_slave(priv
->mdev
->dev
)) {
3118 priv
->dcbx_cap
= DCB_CAP_DCBX_VER_CEE
| DCB_CAP_DCBX_HOST
|
3119 DCB_CAP_DCBX_VER_IEEE
;
3120 priv
->flags
|= MLX4_EN_DCB_ENABLED
;
3121 priv
->cee_config
.pfc_state
= false;
3123 for (i
= 0; i
< MLX4_EN_NUM_UP
; i
++)
3124 priv
->cee_config
.dcb_pfc
[i
] = pfc_disabled
;
3126 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_ETS_CFG
) {
3127 dev
->dcbnl_ops
= &mlx4_en_dcbnl_ops
;
3129 en_info(priv
, "enabling only PFC DCB ops\n");
3130 dev
->dcbnl_ops
= &mlx4_en_dcbnl_pfc_ops
;
3135 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
)
3136 INIT_HLIST_HEAD(&priv
->mac_hash
[i
]);
3138 /* Query for default mac and max mtu */
3139 priv
->max_mtu
= mdev
->dev
->caps
.eth_mtu_cap
[priv
->port
];
3141 if (mdev
->dev
->caps
.rx_checksum_flags_port
[priv
->port
] &
3142 MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP
)
3143 priv
->flags
|= MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP
;
3145 /* Set default MAC */
3146 dev
->addr_len
= ETH_ALEN
;
3147 mlx4_en_u64_to_mac(dev
->dev_addr
, mdev
->dev
->caps
.def_mac
[priv
->port
]);
3148 if (!is_valid_ether_addr(dev
->dev_addr
)) {
3149 en_err(priv
, "Port: %d, invalid mac burned: %pM, quiting\n",
3150 priv
->port
, dev
->dev_addr
);
3153 } else if (mlx4_is_slave(priv
->mdev
->dev
) &&
3154 (priv
->mdev
->dev
->port_random_macs
& 1 << priv
->port
)) {
3155 /* Random MAC was assigned in mlx4_slave_cap
3156 * in mlx4_core module
3158 dev
->addr_assign_type
|= NET_ADDR_RANDOM
;
3159 en_warn(priv
, "Assigned random MAC address %pM\n", dev
->dev_addr
);
3162 memcpy(priv
->current_mac
, dev
->dev_addr
, sizeof(priv
->current_mac
));
3164 priv
->stride
= roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc
) +
3165 DS_SIZE
* MLX4_EN_MAX_RX_FRAGS
);
3166 err
= mlx4_en_alloc_resources(priv
);
3170 /* Initialize time stamping config */
3171 priv
->hwtstamp_config
.flags
= 0;
3172 priv
->hwtstamp_config
.tx_type
= HWTSTAMP_TX_OFF
;
3173 priv
->hwtstamp_config
.rx_filter
= HWTSTAMP_FILTER_NONE
;
3175 /* Allocate page for receive rings */
3176 err
= mlx4_alloc_hwq_res(mdev
->dev
, &priv
->res
,
3179 en_err(priv
, "Failed to allocate page for rx qps\n");
3182 priv
->allocated
= 1;
3185 * Initialize netdev entry points
3187 if (mlx4_is_master(priv
->mdev
->dev
))
3188 dev
->netdev_ops
= &mlx4_netdev_ops_master
;
3190 dev
->netdev_ops
= &mlx4_netdev_ops
;
3191 dev
->watchdog_timeo
= MLX4_EN_WATCHDOG_TIMEOUT
;
3192 netif_set_real_num_tx_queues(dev
, priv
->tx_ring_num
);
3193 netif_set_real_num_rx_queues(dev
, priv
->rx_ring_num
);
3195 dev
->ethtool_ops
= &mlx4_en_ethtool_ops
;
3198 * Set driver features
3200 dev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
3201 if (mdev
->LSO_support
)
3202 dev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
3204 dev
->vlan_features
= dev
->hw_features
;
3206 dev
->hw_features
|= NETIF_F_RXCSUM
| NETIF_F_RXHASH
;
3207 dev
->features
= dev
->hw_features
| NETIF_F_HIGHDMA
|
3208 NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
|
3209 NETIF_F_HW_VLAN_CTAG_FILTER
;
3210 dev
->hw_features
|= NETIF_F_LOOPBACK
|
3211 NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
;
3213 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN
)) {
3214 dev
->features
|= NETIF_F_HW_VLAN_STAG_RX
|
3215 NETIF_F_HW_VLAN_STAG_FILTER
;
3216 dev
->hw_features
|= NETIF_F_HW_VLAN_STAG_RX
;
3219 if (mlx4_is_slave(mdev
->dev
)) {
3222 err
= get_phv_bit(mdev
->dev
, port
, &phv
);
3224 dev
->hw_features
|= NETIF_F_HW_VLAN_STAG_TX
;
3225 priv
->pflags
|= MLX4_EN_PRIV_FLAGS_PHV
;
3228 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_PHV_EN
&&
3229 !(mdev
->dev
->caps
.flags2
&
3230 MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN
))
3231 dev
->hw_features
|= NETIF_F_HW_VLAN_STAG_TX
;
3234 if (mdev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_FCS_KEEP
)
3235 dev
->hw_features
|= NETIF_F_RXFCS
;
3237 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_IGNORE_FCS
)
3238 dev
->hw_features
|= NETIF_F_RXALL
;
3240 if (mdev
->dev
->caps
.steering_mode
==
3241 MLX4_STEERING_MODE_DEVICE_MANAGED
&&
3242 mdev
->dev
->caps
.dmfs_high_steer_mode
!= MLX4_STEERING_DMFS_A0_STATIC
)
3243 dev
->hw_features
|= NETIF_F_NTUPLE
;
3245 if (mdev
->dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
)
3246 dev
->priv_flags
|= IFF_UNICAST_FLT
;
3248 /* Setting a default hash function value */
3249 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_RSS_TOP
) {
3250 priv
->rss_hash_fn
= ETH_RSS_HASH_TOP
;
3251 } else if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_RSS_XOR
) {
3252 priv
->rss_hash_fn
= ETH_RSS_HASH_XOR
;
3255 "No RSS hash capabilities exposed, using Toeplitz\n");
3256 priv
->rss_hash_fn
= ETH_RSS_HASH_TOP
;
3259 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
3260 dev
->hw_features
|= NETIF_F_GSO_UDP_TUNNEL
|
3261 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
3262 NETIF_F_GSO_PARTIAL
;
3263 dev
->features
|= NETIF_F_GSO_UDP_TUNNEL
|
3264 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
3265 NETIF_F_GSO_PARTIAL
;
3266 dev
->gso_partial_features
= NETIF_F_GSO_UDP_TUNNEL_CSUM
;
3269 mdev
->pndev
[port
] = dev
;
3270 mdev
->upper
[port
] = NULL
;
3272 netif_carrier_off(dev
);
3273 mlx4_en_set_default_moderation(priv
);
3275 en_warn(priv
, "Using %d TX rings\n", prof
->tx_ring_num
);
3276 en_warn(priv
, "Using %d RX rings\n", prof
->rx_ring_num
);
3278 mlx4_en_update_loopback_state(priv
->dev
, priv
->dev
->features
);
3280 /* Configure port */
3281 mlx4_en_calc_rx_buf(dev
);
3282 err
= mlx4_SET_PORT_general(mdev
->dev
, priv
->port
,
3283 priv
->rx_skb_size
+ ETH_FCS_LEN
,
3284 prof
->tx_pause
, prof
->tx_ppp
,
3285 prof
->rx_pause
, prof
->rx_ppp
);
3287 en_err(priv
, "Failed setting port general configurations for port %d, with error %d\n",
3292 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
3293 err
= mlx4_SET_PORT_VXLAN(mdev
->dev
, priv
->port
, VXLAN_STEER_BY_OUTER_MAC
, 1);
3295 en_err(priv
, "Failed setting port L2 tunnel configuration, err %d\n",
3302 en_warn(priv
, "Initializing port\n");
3303 err
= mlx4_INIT_PORT(mdev
->dev
, priv
->port
);
3305 en_err(priv
, "Failed Initializing port\n");
3308 queue_delayed_work(mdev
->workqueue
, &priv
->stats_task
, STATS_DELAY
);
3310 /* Initialize time stamp mechanism */
3311 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
)
3312 mlx4_en_init_timestamp(mdev
);
3314 queue_delayed_work(mdev
->workqueue
, &priv
->service_task
,
3315 SERVICE_TASK_DELAY
);
3317 mlx4_en_set_stats_bitmap(mdev
->dev
, &priv
->stats_bitmap
,
3318 mdev
->profile
.prof
[priv
->port
].rx_ppp
,
3319 mdev
->profile
.prof
[priv
->port
].rx_pause
,
3320 mdev
->profile
.prof
[priv
->port
].tx_ppp
,
3321 mdev
->profile
.prof
[priv
->port
].tx_pause
);
3323 err
= register_netdev(dev
);
3325 en_err(priv
, "Netdev registration failed for port %d\n", port
);
3329 priv
->registered
= 1;
3330 devlink_port_type_eth_set(mlx4_get_devlink_port(mdev
->dev
, priv
->port
),
3336 mlx4_en_destroy_netdev(dev
);
3340 int mlx4_en_reset_config(struct net_device
*dev
,
3341 struct hwtstamp_config ts_config
,
3342 netdev_features_t features
)
3344 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
3345 struct mlx4_en_dev
*mdev
= priv
->mdev
;
3346 struct mlx4_en_port_profile new_prof
;
3347 struct mlx4_en_priv
*tmp
;
3351 if (priv
->hwtstamp_config
.tx_type
== ts_config
.tx_type
&&
3352 priv
->hwtstamp_config
.rx_filter
== ts_config
.rx_filter
&&
3353 !DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_HW_VLAN_CTAG_RX
) &&
3354 !DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_RXFCS
))
3355 return 0; /* Nothing to change */
3357 if (DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_HW_VLAN_CTAG_RX
) &&
3358 (features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
3359 (priv
->hwtstamp_config
.rx_filter
!= HWTSTAMP_FILTER_NONE
)) {
3360 en_warn(priv
, "Can't turn ON rx vlan offload while time-stamping rx filter is ON\n");
3364 tmp
= kzalloc(sizeof(*tmp
), GFP_KERNEL
);
3368 mutex_lock(&mdev
->state_lock
);
3370 memcpy(&new_prof
, priv
->prof
, sizeof(struct mlx4_en_port_profile
));
3371 memcpy(&new_prof
.hwtstamp_config
, &ts_config
, sizeof(ts_config
));
3373 err
= mlx4_en_try_alloc_resources(priv
, tmp
, &new_prof
);
3377 if (priv
->port_up
) {
3379 mlx4_en_stop_port(dev
, 1);
3382 en_warn(priv
, "Changing device configuration rx filter(%x) rx vlan(%x)\n",
3383 ts_config
.rx_filter
,
3384 !!(features
& NETIF_F_HW_VLAN_CTAG_RX
));
3386 mlx4_en_safe_replace_resources(priv
, tmp
);
3388 if (DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_HW_VLAN_CTAG_RX
)) {
3389 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
3390 dev
->features
|= NETIF_F_HW_VLAN_CTAG_RX
;
3392 dev
->features
&= ~NETIF_F_HW_VLAN_CTAG_RX
;
3393 } else if (ts_config
.rx_filter
== HWTSTAMP_FILTER_NONE
) {
3394 /* RX time-stamping is OFF, update the RX vlan offload
3395 * to the latest wanted state
3397 if (dev
->wanted_features
& NETIF_F_HW_VLAN_CTAG_RX
)
3398 dev
->features
|= NETIF_F_HW_VLAN_CTAG_RX
;
3400 dev
->features
&= ~NETIF_F_HW_VLAN_CTAG_RX
;
3403 if (DEV_FEATURE_CHANGED(dev
, features
, NETIF_F_RXFCS
)) {
3404 if (features
& NETIF_F_RXFCS
)
3405 dev
->features
|= NETIF_F_RXFCS
;
3407 dev
->features
&= ~NETIF_F_RXFCS
;
3410 /* RX vlan offload and RX time-stamping can't co-exist !
3411 * Regardless of the caller's choice,
3412 * Turn Off RX vlan offload in case of time-stamping is ON
3414 if (ts_config
.rx_filter
!= HWTSTAMP_FILTER_NONE
) {
3415 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
3416 en_warn(priv
, "Turning off RX vlan offload since RX time-stamping is ON\n");
3417 dev
->features
&= ~NETIF_F_HW_VLAN_CTAG_RX
;
3421 err
= mlx4_en_start_port(dev
);
3423 en_err(priv
, "Failed starting port\n");
3427 mutex_unlock(&mdev
->state_lock
);
3430 netdev_features_change(dev
);