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 -EPROTONOSUPPORT
;
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
< 0) {
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
)
477 struct mlx4_spec_list spec_eth_outer
= { {NULL
} };
478 struct mlx4_spec_list spec_vxlan
= { {NULL
} };
479 struct mlx4_spec_list spec_eth_inner
= { {NULL
} };
481 struct mlx4_net_trans_rule rule
= {
482 .queue_mode
= MLX4_NET_TRANS_Q_FIFO
,
485 .promisc_mode
= MLX4_FS_REGULAR
,
486 .priority
= MLX4_DOMAIN_NIC
,
489 __be64 mac_mask
= cpu_to_be64(MLX4_MAC_MASK
<< 16);
491 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
492 return 0; /* do nothing */
494 rule
.port
= priv
->port
;
496 INIT_LIST_HEAD(&rule
.list
);
498 spec_eth_outer
.id
= MLX4_NET_TRANS_RULE_ID_ETH
;
499 memcpy(spec_eth_outer
.eth
.dst_mac
, addr
, ETH_ALEN
);
500 memcpy(spec_eth_outer
.eth
.dst_mac_msk
, &mac_mask
, ETH_ALEN
);
502 spec_vxlan
.id
= MLX4_NET_TRANS_RULE_ID_VXLAN
; /* any vxlan header */
503 spec_eth_inner
.id
= MLX4_NET_TRANS_RULE_ID_ETH
; /* any inner eth header */
505 list_add_tail(&spec_eth_outer
.list
, &rule
.list
);
506 list_add_tail(&spec_vxlan
.list
, &rule
.list
);
507 list_add_tail(&spec_eth_inner
.list
, &rule
.list
);
509 err
= mlx4_flow_attach(priv
->mdev
->dev
, &rule
, reg_id
);
511 en_err(priv
, "failed to add vxlan steering rule, err %d\n", err
);
514 en_dbg(DRV
, priv
, "added vxlan steering rule, mac %pM reg_id %llx\n", addr
, *reg_id
);
519 static int mlx4_en_uc_steer_add(struct mlx4_en_priv
*priv
,
520 unsigned char *mac
, int *qpn
, u64
*reg_id
)
522 struct mlx4_en_dev
*mdev
= priv
->mdev
;
523 struct mlx4_dev
*dev
= mdev
->dev
;
526 switch (dev
->caps
.steering_mode
) {
527 case MLX4_STEERING_MODE_B0
: {
532 memcpy(&gid
[10], mac
, ETH_ALEN
);
535 err
= mlx4_unicast_attach(dev
, &qp
, gid
, 0, MLX4_PROT_ETH
);
538 case MLX4_STEERING_MODE_DEVICE_MANAGED
: {
539 struct mlx4_spec_list spec_eth
= { {NULL
} };
540 __be64 mac_mask
= cpu_to_be64(MLX4_MAC_MASK
<< 16);
542 struct mlx4_net_trans_rule rule
= {
543 .queue_mode
= MLX4_NET_TRANS_Q_FIFO
,
546 .promisc_mode
= MLX4_FS_REGULAR
,
547 .priority
= MLX4_DOMAIN_NIC
,
550 rule
.port
= priv
->port
;
552 INIT_LIST_HEAD(&rule
.list
);
554 spec_eth
.id
= MLX4_NET_TRANS_RULE_ID_ETH
;
555 memcpy(spec_eth
.eth
.dst_mac
, mac
, ETH_ALEN
);
556 memcpy(spec_eth
.eth
.dst_mac_msk
, &mac_mask
, ETH_ALEN
);
557 list_add_tail(&spec_eth
.list
, &rule
.list
);
559 err
= mlx4_flow_attach(dev
, &rule
, reg_id
);
566 en_warn(priv
, "Failed Attaching Unicast\n");
571 static void mlx4_en_uc_steer_release(struct mlx4_en_priv
*priv
,
572 unsigned char *mac
, int qpn
, u64 reg_id
)
574 struct mlx4_en_dev
*mdev
= priv
->mdev
;
575 struct mlx4_dev
*dev
= mdev
->dev
;
577 switch (dev
->caps
.steering_mode
) {
578 case MLX4_STEERING_MODE_B0
: {
583 memcpy(&gid
[10], mac
, ETH_ALEN
);
586 mlx4_unicast_detach(dev
, &qp
, gid
, MLX4_PROT_ETH
);
589 case MLX4_STEERING_MODE_DEVICE_MANAGED
: {
590 mlx4_flow_detach(dev
, reg_id
);
594 en_err(priv
, "Invalid steering mode.\n");
598 static int mlx4_en_get_qp(struct mlx4_en_priv
*priv
)
600 struct mlx4_en_dev
*mdev
= priv
->mdev
;
601 struct mlx4_dev
*dev
= mdev
->dev
;
602 struct mlx4_mac_entry
*entry
;
606 int *qpn
= &priv
->base_qpn
;
607 u64 mac
= mlx4_mac_to_u64(priv
->dev
->dev_addr
);
609 en_dbg(DRV
, priv
, "Registering MAC: %pM for adding\n",
610 priv
->dev
->dev_addr
);
611 index
= mlx4_register_mac(dev
, priv
->port
, mac
);
614 en_err(priv
, "Failed adding MAC: %pM\n",
615 priv
->dev
->dev_addr
);
619 if (dev
->caps
.steering_mode
== MLX4_STEERING_MODE_A0
) {
620 int base_qpn
= mlx4_get_base_qpn(dev
, priv
->port
);
621 *qpn
= base_qpn
+ index
;
625 err
= mlx4_qp_reserve_range(dev
, 1, 1, qpn
);
626 en_dbg(DRV
, priv
, "Reserved qp %d\n", *qpn
);
628 en_err(priv
, "Failed to reserve qp for mac registration\n");
632 err
= mlx4_en_uc_steer_add(priv
, priv
->dev
->dev_addr
, qpn
, ®_id
);
636 err
= mlx4_en_tunnel_steer_add(priv
, priv
->dev
->dev_addr
, *qpn
,
637 &priv
->tunnel_reg_id
);
641 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
646 memcpy(entry
->mac
, priv
->dev
->dev_addr
, sizeof(entry
->mac
));
647 entry
->reg_id
= reg_id
;
649 hlist_add_head_rcu(&entry
->hlist
,
650 &priv
->mac_hash
[entry
->mac
[MLX4_EN_MAC_HASH_IDX
]]);
655 if (priv
->tunnel_reg_id
)
656 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
658 mlx4_en_uc_steer_release(priv
, priv
->dev
->dev_addr
, *qpn
, reg_id
);
661 mlx4_qp_release_range(dev
, *qpn
, 1);
664 mlx4_unregister_mac(dev
, priv
->port
, mac
);
668 static void mlx4_en_put_qp(struct mlx4_en_priv
*priv
)
670 struct mlx4_en_dev
*mdev
= priv
->mdev
;
671 struct mlx4_dev
*dev
= mdev
->dev
;
672 int qpn
= priv
->base_qpn
;
675 if (dev
->caps
.steering_mode
== MLX4_STEERING_MODE_A0
) {
676 mac
= mlx4_mac_to_u64(priv
->dev
->dev_addr
);
677 en_dbg(DRV
, priv
, "Registering MAC: %pM for deleting\n",
678 priv
->dev
->dev_addr
);
679 mlx4_unregister_mac(dev
, priv
->port
, mac
);
681 struct mlx4_mac_entry
*entry
;
682 struct hlist_node
*tmp
;
683 struct hlist_head
*bucket
;
686 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
) {
687 bucket
= &priv
->mac_hash
[i
];
688 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
689 mac
= mlx4_mac_to_u64(entry
->mac
);
690 en_dbg(DRV
, priv
, "Registering MAC: %pM for deleting\n",
692 mlx4_en_uc_steer_release(priv
, entry
->mac
,
695 mlx4_unregister_mac(dev
, priv
->port
, mac
);
696 hlist_del_rcu(&entry
->hlist
);
697 kfree_rcu(entry
, rcu
);
701 if (priv
->tunnel_reg_id
) {
702 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
703 priv
->tunnel_reg_id
= 0;
706 en_dbg(DRV
, priv
, "Releasing qp: port %d, qpn %d\n",
708 mlx4_qp_release_range(dev
, qpn
, 1);
709 priv
->flags
&= ~MLX4_EN_FLAG_FORCE_PROMISC
;
713 static int mlx4_en_replace_mac(struct mlx4_en_priv
*priv
, int qpn
,
714 unsigned char *new_mac
, unsigned char *prev_mac
)
716 struct mlx4_en_dev
*mdev
= priv
->mdev
;
717 struct mlx4_dev
*dev
= mdev
->dev
;
719 u64 new_mac_u64
= mlx4_mac_to_u64(new_mac
);
721 if (dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
) {
722 struct hlist_head
*bucket
;
723 unsigned int mac_hash
;
724 struct mlx4_mac_entry
*entry
;
725 struct hlist_node
*tmp
;
726 u64 prev_mac_u64
= mlx4_mac_to_u64(prev_mac
);
728 bucket
= &priv
->mac_hash
[prev_mac
[MLX4_EN_MAC_HASH_IDX
]];
729 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
730 if (ether_addr_equal_64bits(entry
->mac
, prev_mac
)) {
731 mlx4_en_uc_steer_release(priv
, entry
->mac
,
733 mlx4_unregister_mac(dev
, priv
->port
,
735 hlist_del_rcu(&entry
->hlist
);
737 memcpy(entry
->mac
, new_mac
, ETH_ALEN
);
739 mac_hash
= new_mac
[MLX4_EN_MAC_HASH_IDX
];
740 hlist_add_head_rcu(&entry
->hlist
,
741 &priv
->mac_hash
[mac_hash
]);
742 mlx4_register_mac(dev
, priv
->port
, new_mac_u64
);
743 err
= mlx4_en_uc_steer_add(priv
, new_mac
,
748 if (priv
->tunnel_reg_id
) {
749 mlx4_flow_detach(priv
->mdev
->dev
, priv
->tunnel_reg_id
);
750 priv
->tunnel_reg_id
= 0;
752 err
= mlx4_en_tunnel_steer_add(priv
, new_mac
, qpn
,
753 &priv
->tunnel_reg_id
);
760 return __mlx4_replace_mac(dev
, priv
->port
, qpn
, new_mac_u64
);
763 static int mlx4_en_do_set_mac(struct mlx4_en_priv
*priv
)
768 /* Remove old MAC and insert the new one */
769 err
= mlx4_en_replace_mac(priv
, priv
->base_qpn
,
770 priv
->dev
->dev_addr
, priv
->prev_mac
);
772 en_err(priv
, "Failed changing HW MAC address\n");
773 memcpy(priv
->prev_mac
, priv
->dev
->dev_addr
,
774 sizeof(priv
->prev_mac
));
776 en_dbg(HW
, priv
, "Port is down while registering mac, exiting...\n");
781 static int mlx4_en_set_mac(struct net_device
*dev
, void *addr
)
783 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
784 struct mlx4_en_dev
*mdev
= priv
->mdev
;
785 struct sockaddr
*saddr
= addr
;
788 if (!is_valid_ether_addr(saddr
->sa_data
))
789 return -EADDRNOTAVAIL
;
791 memcpy(dev
->dev_addr
, saddr
->sa_data
, ETH_ALEN
);
793 mutex_lock(&mdev
->state_lock
);
794 err
= mlx4_en_do_set_mac(priv
);
795 mutex_unlock(&mdev
->state_lock
);
800 static void mlx4_en_clear_list(struct net_device
*dev
)
802 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
803 struct mlx4_en_mc_list
*tmp
, *mc_to_del
;
805 list_for_each_entry_safe(mc_to_del
, tmp
, &priv
->mc_list
, list
) {
806 list_del(&mc_to_del
->list
);
811 static void mlx4_en_cache_mclist(struct net_device
*dev
)
813 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
814 struct netdev_hw_addr
*ha
;
815 struct mlx4_en_mc_list
*tmp
;
817 mlx4_en_clear_list(dev
);
818 netdev_for_each_mc_addr(ha
, dev
) {
819 tmp
= kzalloc(sizeof(struct mlx4_en_mc_list
), GFP_ATOMIC
);
821 mlx4_en_clear_list(dev
);
824 memcpy(tmp
->addr
, ha
->addr
, ETH_ALEN
);
825 list_add_tail(&tmp
->list
, &priv
->mc_list
);
829 static void update_mclist_flags(struct mlx4_en_priv
*priv
,
830 struct list_head
*dst
,
831 struct list_head
*src
)
833 struct mlx4_en_mc_list
*dst_tmp
, *src_tmp
, *new_mc
;
836 /* Find all the entries that should be removed from dst,
837 * These are the entries that are not found in src
839 list_for_each_entry(dst_tmp
, dst
, list
) {
841 list_for_each_entry(src_tmp
, src
, list
) {
842 if (ether_addr_equal(dst_tmp
->addr
, src_tmp
->addr
)) {
848 dst_tmp
->action
= MCLIST_REM
;
851 /* Add entries that exist in src but not in dst
852 * mark them as need to add
854 list_for_each_entry(src_tmp
, src
, list
) {
856 list_for_each_entry(dst_tmp
, dst
, list
) {
857 if (ether_addr_equal(dst_tmp
->addr
, src_tmp
->addr
)) {
858 dst_tmp
->action
= MCLIST_NONE
;
864 new_mc
= kmemdup(src_tmp
,
865 sizeof(struct mlx4_en_mc_list
),
870 new_mc
->action
= MCLIST_ADD
;
871 list_add_tail(&new_mc
->list
, dst
);
876 static void mlx4_en_set_rx_mode(struct net_device
*dev
)
878 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
883 queue_work(priv
->mdev
->workqueue
, &priv
->rx_mode_task
);
886 static void mlx4_en_set_promisc_mode(struct mlx4_en_priv
*priv
,
887 struct mlx4_en_dev
*mdev
)
891 if (!(priv
->flags
& MLX4_EN_FLAG_PROMISC
)) {
892 if (netif_msg_rx_status(priv
))
893 en_warn(priv
, "Entering promiscuous mode\n");
894 priv
->flags
|= MLX4_EN_FLAG_PROMISC
;
896 /* Enable promiscouos mode */
897 switch (mdev
->dev
->caps
.steering_mode
) {
898 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
899 err
= mlx4_flow_steer_promisc_add(mdev
->dev
,
902 MLX4_FS_ALL_DEFAULT
);
904 en_err(priv
, "Failed enabling promiscuous mode\n");
905 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
908 case MLX4_STEERING_MODE_B0
:
909 err
= mlx4_unicast_promisc_add(mdev
->dev
,
913 en_err(priv
, "Failed enabling unicast promiscuous mode\n");
915 /* Add the default qp number as multicast
918 if (!(priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
)) {
919 err
= mlx4_multicast_promisc_add(mdev
->dev
,
923 en_err(priv
, "Failed enabling multicast promiscuous mode\n");
924 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
928 case MLX4_STEERING_MODE_A0
:
929 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
,
934 en_err(priv
, "Failed enabling promiscuous mode\n");
938 /* Disable port multicast filter (unconditionally) */
939 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
940 0, MLX4_MCAST_DISABLE
);
942 en_err(priv
, "Failed disabling multicast filter\n");
944 /* Disable port VLAN filter */
945 err
= mlx4_SET_VLAN_FLTR(mdev
->dev
, priv
);
947 en_err(priv
, "Failed disabling VLAN filter\n");
951 static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv
*priv
,
952 struct mlx4_en_dev
*mdev
)
956 if (netif_msg_rx_status(priv
))
957 en_warn(priv
, "Leaving promiscuous mode\n");
958 priv
->flags
&= ~MLX4_EN_FLAG_PROMISC
;
960 /* Disable promiscouos mode */
961 switch (mdev
->dev
->caps
.steering_mode
) {
962 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
963 err
= mlx4_flow_steer_promisc_remove(mdev
->dev
,
965 MLX4_FS_ALL_DEFAULT
);
967 en_err(priv
, "Failed disabling promiscuous mode\n");
968 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
971 case MLX4_STEERING_MODE_B0
:
972 err
= mlx4_unicast_promisc_remove(mdev
->dev
,
976 en_err(priv
, "Failed disabling unicast promiscuous mode\n");
977 /* Disable Multicast promisc */
978 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
979 err
= mlx4_multicast_promisc_remove(mdev
->dev
,
983 en_err(priv
, "Failed disabling multicast promiscuous mode\n");
984 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
988 case MLX4_STEERING_MODE_A0
:
989 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
,
993 en_err(priv
, "Failed disabling promiscuous mode\n");
997 /* Enable port VLAN filter */
998 err
= mlx4_SET_VLAN_FLTR(mdev
->dev
, priv
);
1000 en_err(priv
, "Failed enabling VLAN filter\n");
1003 static void mlx4_en_do_multicast(struct mlx4_en_priv
*priv
,
1004 struct net_device
*dev
,
1005 struct mlx4_en_dev
*mdev
)
1007 struct mlx4_en_mc_list
*mclist
, *tmp
;
1009 u8 mc_list
[16] = {0};
1012 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
1013 if (dev
->flags
& IFF_ALLMULTI
) {
1014 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
1015 0, MLX4_MCAST_DISABLE
);
1017 en_err(priv
, "Failed disabling multicast filter\n");
1019 /* Add the default qp number as multicast promisc */
1020 if (!(priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
)) {
1021 switch (mdev
->dev
->caps
.steering_mode
) {
1022 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
1023 err
= mlx4_flow_steer_promisc_add(mdev
->dev
,
1026 MLX4_FS_MC_DEFAULT
);
1029 case MLX4_STEERING_MODE_B0
:
1030 err
= mlx4_multicast_promisc_add(mdev
->dev
,
1035 case MLX4_STEERING_MODE_A0
:
1039 en_err(priv
, "Failed entering multicast promisc mode\n");
1040 priv
->flags
|= MLX4_EN_FLAG_MC_PROMISC
;
1043 /* Disable Multicast promisc */
1044 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
1045 switch (mdev
->dev
->caps
.steering_mode
) {
1046 case MLX4_STEERING_MODE_DEVICE_MANAGED
:
1047 err
= mlx4_flow_steer_promisc_remove(mdev
->dev
,
1049 MLX4_FS_MC_DEFAULT
);
1052 case MLX4_STEERING_MODE_B0
:
1053 err
= mlx4_multicast_promisc_remove(mdev
->dev
,
1058 case MLX4_STEERING_MODE_A0
:
1062 en_err(priv
, "Failed disabling multicast promiscuous mode\n");
1063 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
1066 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
1067 0, MLX4_MCAST_DISABLE
);
1069 en_err(priv
, "Failed disabling multicast filter\n");
1071 /* Flush mcast filter and init it with broadcast address */
1072 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, ETH_BCAST
,
1073 1, MLX4_MCAST_CONFIG
);
1075 /* Update multicast list - we cache all addresses so they won't
1076 * change while HW is updated holding the command semaphor */
1077 netif_addr_lock_bh(dev
);
1078 mlx4_en_cache_mclist(dev
);
1079 netif_addr_unlock_bh(dev
);
1080 list_for_each_entry(mclist
, &priv
->mc_list
, list
) {
1081 mcast_addr
= mlx4_mac_to_u64(mclist
->addr
);
1082 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
,
1083 mcast_addr
, 0, MLX4_MCAST_CONFIG
);
1085 err
= mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0,
1086 0, MLX4_MCAST_ENABLE
);
1088 en_err(priv
, "Failed enabling multicast filter\n");
1090 update_mclist_flags(priv
, &priv
->curr_list
, &priv
->mc_list
);
1091 list_for_each_entry_safe(mclist
, tmp
, &priv
->curr_list
, list
) {
1092 if (mclist
->action
== MCLIST_REM
) {
1093 /* detach this address and delete from list */
1094 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1095 mc_list
[5] = priv
->port
;
1096 err
= mlx4_multicast_detach(mdev
->dev
,
1097 &priv
->rss_map
.indir_qp
,
1102 en_err(priv
, "Fail to detach multicast address\n");
1104 if (mclist
->tunnel_reg_id
) {
1105 err
= mlx4_flow_detach(priv
->mdev
->dev
, mclist
->tunnel_reg_id
);
1107 en_err(priv
, "Failed to detach multicast address\n");
1110 /* remove from list */
1111 list_del(&mclist
->list
);
1113 } else if (mclist
->action
== MCLIST_ADD
) {
1114 /* attach the address */
1115 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1116 /* needed for B0 steering support */
1117 mc_list
[5] = priv
->port
;
1118 err
= mlx4_multicast_attach(mdev
->dev
,
1119 &priv
->rss_map
.indir_qp
,
1125 en_err(priv
, "Fail to attach multicast address\n");
1127 err
= mlx4_en_tunnel_steer_add(priv
, &mc_list
[10], priv
->base_qpn
,
1128 &mclist
->tunnel_reg_id
);
1130 en_err(priv
, "Failed to attach multicast address\n");
1136 static void mlx4_en_do_uc_filter(struct mlx4_en_priv
*priv
,
1137 struct net_device
*dev
,
1138 struct mlx4_en_dev
*mdev
)
1140 struct netdev_hw_addr
*ha
;
1141 struct mlx4_mac_entry
*entry
;
1142 struct hlist_node
*tmp
;
1146 struct hlist_head
*bucket
;
1151 /* Note that we do not need to protect our mac_hash traversal with rcu,
1152 * since all modification code is protected by mdev->state_lock
1155 /* find what to remove */
1156 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
) {
1157 bucket
= &priv
->mac_hash
[i
];
1158 hlist_for_each_entry_safe(entry
, tmp
, bucket
, hlist
) {
1160 netdev_for_each_uc_addr(ha
, dev
) {
1161 if (ether_addr_equal_64bits(entry
->mac
,
1168 /* MAC address of the port is not in uc list */
1169 if (ether_addr_equal_64bits(entry
->mac
, dev
->dev_addr
))
1173 mac
= mlx4_mac_to_u64(entry
->mac
);
1174 mlx4_en_uc_steer_release(priv
, entry
->mac
,
1177 mlx4_unregister_mac(mdev
->dev
, priv
->port
, mac
);
1179 hlist_del_rcu(&entry
->hlist
);
1180 kfree_rcu(entry
, rcu
);
1181 en_dbg(DRV
, priv
, "Removed MAC %pM on port:%d\n",
1182 entry
->mac
, priv
->port
);
1188 /* if we didn't remove anything, there is no use in trying to add
1189 * again once we are in a forced promisc mode state
1191 if ((priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
) && 0 == removed
)
1194 prev_flags
= priv
->flags
;
1195 priv
->flags
&= ~MLX4_EN_FLAG_FORCE_PROMISC
;
1197 /* find what to add */
1198 netdev_for_each_uc_addr(ha
, dev
) {
1200 bucket
= &priv
->mac_hash
[ha
->addr
[MLX4_EN_MAC_HASH_IDX
]];
1201 hlist_for_each_entry(entry
, bucket
, hlist
) {
1202 if (ether_addr_equal_64bits(entry
->mac
, ha
->addr
)) {
1209 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
1211 en_err(priv
, "Failed adding MAC %pM on port:%d (out of memory)\n",
1212 ha
->addr
, priv
->port
);
1213 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1216 mac
= mlx4_mac_to_u64(ha
->addr
);
1217 memcpy(entry
->mac
, ha
->addr
, ETH_ALEN
);
1218 err
= mlx4_register_mac(mdev
->dev
, priv
->port
, mac
);
1220 en_err(priv
, "Failed registering MAC %pM on port %d: %d\n",
1221 ha
->addr
, priv
->port
, err
);
1223 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1226 err
= mlx4_en_uc_steer_add(priv
, ha
->addr
,
1230 en_err(priv
, "Failed adding MAC %pM on port %d: %d\n",
1231 ha
->addr
, priv
->port
, err
);
1232 mlx4_unregister_mac(mdev
->dev
, priv
->port
, mac
);
1234 priv
->flags
|= MLX4_EN_FLAG_FORCE_PROMISC
;
1237 unsigned int mac_hash
;
1238 en_dbg(DRV
, priv
, "Added MAC %pM on port:%d\n",
1239 ha
->addr
, priv
->port
);
1240 mac_hash
= ha
->addr
[MLX4_EN_MAC_HASH_IDX
];
1241 bucket
= &priv
->mac_hash
[mac_hash
];
1242 hlist_add_head_rcu(&entry
->hlist
, bucket
);
1247 if (priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
) {
1248 en_warn(priv
, "Forcing promiscuous mode on port:%d\n",
1250 } else if (prev_flags
& MLX4_EN_FLAG_FORCE_PROMISC
) {
1251 en_warn(priv
, "Stop forcing promiscuous mode on port:%d\n",
1256 static void mlx4_en_do_set_rx_mode(struct work_struct
*work
)
1258 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1260 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1261 struct net_device
*dev
= priv
->dev
;
1263 mutex_lock(&mdev
->state_lock
);
1264 if (!mdev
->device_up
) {
1265 en_dbg(HW
, priv
, "Card is not up, ignoring rx mode change.\n");
1268 if (!priv
->port_up
) {
1269 en_dbg(HW
, priv
, "Port is down, ignoring rx mode change.\n");
1273 if (!netif_carrier_ok(dev
)) {
1274 if (!mlx4_en_QUERY_PORT(mdev
, priv
->port
)) {
1275 if (priv
->port_state
.link_state
) {
1276 priv
->last_link_state
= MLX4_DEV_EVENT_PORT_UP
;
1277 netif_carrier_on(dev
);
1278 en_dbg(LINK
, priv
, "Link Up\n");
1283 if (dev
->priv_flags
& IFF_UNICAST_FLT
)
1284 mlx4_en_do_uc_filter(priv
, dev
, mdev
);
1286 /* Promsicuous mode: disable all filters */
1287 if ((dev
->flags
& IFF_PROMISC
) ||
1288 (priv
->flags
& MLX4_EN_FLAG_FORCE_PROMISC
)) {
1289 mlx4_en_set_promisc_mode(priv
, mdev
);
1293 /* Not in promiscuous mode */
1294 if (priv
->flags
& MLX4_EN_FLAG_PROMISC
)
1295 mlx4_en_clear_promisc_mode(priv
, mdev
);
1297 mlx4_en_do_multicast(priv
, dev
, mdev
);
1299 mutex_unlock(&mdev
->state_lock
);
1302 #ifdef CONFIG_NET_POLL_CONTROLLER
1303 static void mlx4_en_netpoll(struct net_device
*dev
)
1305 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1306 struct mlx4_en_cq
*cq
;
1307 unsigned long flags
;
1310 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1311 cq
= priv
->rx_cq
[i
];
1312 spin_lock_irqsave(&cq
->lock
, flags
);
1313 napi_synchronize(&cq
->napi
);
1314 mlx4_en_process_rx_cq(dev
, cq
, 0);
1315 spin_unlock_irqrestore(&cq
->lock
, flags
);
1320 static void mlx4_en_tx_timeout(struct net_device
*dev
)
1322 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1323 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1326 if (netif_msg_timer(priv
))
1327 en_warn(priv
, "Tx timeout called on port:%d\n", priv
->port
);
1329 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1330 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev
, i
)))
1332 en_warn(priv
, "TX timeout on queue: %d, QP: 0x%x, CQ: 0x%x, Cons: 0x%x, Prod: 0x%x\n",
1333 i
, priv
->tx_ring
[i
]->qpn
, priv
->tx_ring
[i
]->cqn
,
1334 priv
->tx_ring
[i
]->cons
, priv
->tx_ring
[i
]->prod
);
1337 priv
->port_stats
.tx_timeout
++;
1338 en_dbg(DRV
, priv
, "Scheduling watchdog\n");
1339 queue_work(mdev
->workqueue
, &priv
->watchdog_task
);
1343 static struct net_device_stats
*mlx4_en_get_stats(struct net_device
*dev
)
1345 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1347 spin_lock_bh(&priv
->stats_lock
);
1348 memcpy(&priv
->ret_stats
, &priv
->stats
, sizeof(priv
->stats
));
1349 spin_unlock_bh(&priv
->stats_lock
);
1351 return &priv
->ret_stats
;
1354 static void mlx4_en_set_default_moderation(struct mlx4_en_priv
*priv
)
1356 struct mlx4_en_cq
*cq
;
1359 /* If we haven't received a specific coalescing setting
1360 * (module param), we set the moderation parameters as follows:
1361 * - moder_cnt is set to the number of mtu sized packets to
1362 * satisfy our coalescing target.
1363 * - moder_time is set to a fixed value.
1365 priv
->rx_frames
= MLX4_EN_RX_COAL_TARGET
;
1366 priv
->rx_usecs
= MLX4_EN_RX_COAL_TIME
;
1367 priv
->tx_frames
= MLX4_EN_TX_COAL_PKTS
;
1368 priv
->tx_usecs
= MLX4_EN_TX_COAL_TIME
;
1369 en_dbg(INTR
, priv
, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n",
1370 priv
->dev
->mtu
, priv
->rx_frames
, priv
->rx_usecs
);
1372 /* Setup cq moderation params */
1373 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1374 cq
= priv
->rx_cq
[i
];
1375 cq
->moder_cnt
= priv
->rx_frames
;
1376 cq
->moder_time
= priv
->rx_usecs
;
1377 priv
->last_moder_time
[i
] = MLX4_EN_AUTO_CONF
;
1378 priv
->last_moder_packets
[i
] = 0;
1379 priv
->last_moder_bytes
[i
] = 0;
1382 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1383 cq
= priv
->tx_cq
[i
];
1384 cq
->moder_cnt
= priv
->tx_frames
;
1385 cq
->moder_time
= priv
->tx_usecs
;
1388 /* Reset auto-moderation params */
1389 priv
->pkt_rate_low
= MLX4_EN_RX_RATE_LOW
;
1390 priv
->rx_usecs_low
= MLX4_EN_RX_COAL_TIME_LOW
;
1391 priv
->pkt_rate_high
= MLX4_EN_RX_RATE_HIGH
;
1392 priv
->rx_usecs_high
= MLX4_EN_RX_COAL_TIME_HIGH
;
1393 priv
->sample_interval
= MLX4_EN_SAMPLE_INTERVAL
;
1394 priv
->adaptive_rx_coal
= 1;
1395 priv
->last_moder_jiffies
= 0;
1396 priv
->last_moder_tx_packets
= 0;
1399 static void mlx4_en_auto_moderation(struct mlx4_en_priv
*priv
)
1401 unsigned long period
= (unsigned long) (jiffies
- priv
->last_moder_jiffies
);
1402 struct mlx4_en_cq
*cq
;
1403 unsigned long packets
;
1405 unsigned long avg_pkt_size
;
1406 unsigned long rx_packets
;
1407 unsigned long rx_bytes
;
1408 unsigned long rx_pkt_diff
;
1412 if (!priv
->adaptive_rx_coal
|| period
< priv
->sample_interval
* HZ
)
1415 for (ring
= 0; ring
< priv
->rx_ring_num
; ring
++) {
1416 spin_lock_bh(&priv
->stats_lock
);
1417 rx_packets
= priv
->rx_ring
[ring
]->packets
;
1418 rx_bytes
= priv
->rx_ring
[ring
]->bytes
;
1419 spin_unlock_bh(&priv
->stats_lock
);
1421 rx_pkt_diff
= ((unsigned long) (rx_packets
-
1422 priv
->last_moder_packets
[ring
]));
1423 packets
= rx_pkt_diff
;
1424 rate
= packets
* HZ
/ period
;
1425 avg_pkt_size
= packets
? ((unsigned long) (rx_bytes
-
1426 priv
->last_moder_bytes
[ring
])) / packets
: 0;
1428 /* Apply auto-moderation only when packet rate
1429 * exceeds a rate that it matters */
1430 if (rate
> (MLX4_EN_RX_RATE_THRESH
/ priv
->rx_ring_num
) &&
1431 avg_pkt_size
> MLX4_EN_AVG_PKT_SMALL
) {
1432 if (rate
< priv
->pkt_rate_low
)
1433 moder_time
= priv
->rx_usecs_low
;
1434 else if (rate
> priv
->pkt_rate_high
)
1435 moder_time
= priv
->rx_usecs_high
;
1437 moder_time
= (rate
- priv
->pkt_rate_low
) *
1438 (priv
->rx_usecs_high
- priv
->rx_usecs_low
) /
1439 (priv
->pkt_rate_high
- priv
->pkt_rate_low
) +
1442 moder_time
= priv
->rx_usecs_low
;
1445 if (moder_time
!= priv
->last_moder_time
[ring
]) {
1446 priv
->last_moder_time
[ring
] = moder_time
;
1447 cq
= priv
->rx_cq
[ring
];
1448 cq
->moder_time
= moder_time
;
1449 cq
->moder_cnt
= priv
->rx_frames
;
1450 err
= mlx4_en_set_cq_moder(priv
, cq
);
1452 en_err(priv
, "Failed modifying moderation for cq:%d\n",
1455 priv
->last_moder_packets
[ring
] = rx_packets
;
1456 priv
->last_moder_bytes
[ring
] = rx_bytes
;
1459 priv
->last_moder_jiffies
= jiffies
;
1462 static void mlx4_en_do_get_stats(struct work_struct
*work
)
1464 struct delayed_work
*delay
= to_delayed_work(work
);
1465 struct mlx4_en_priv
*priv
= container_of(delay
, struct mlx4_en_priv
,
1467 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1470 mutex_lock(&mdev
->state_lock
);
1471 if (mdev
->device_up
) {
1472 if (priv
->port_up
) {
1473 err
= mlx4_en_DUMP_ETH_STATS(mdev
, priv
->port
, 0);
1475 en_dbg(HW
, priv
, "Could not update stats\n");
1477 mlx4_en_auto_moderation(priv
);
1480 queue_delayed_work(mdev
->workqueue
, &priv
->stats_task
, STATS_DELAY
);
1482 if (mdev
->mac_removed
[MLX4_MAX_PORTS
+ 1 - priv
->port
]) {
1483 mlx4_en_do_set_mac(priv
);
1484 mdev
->mac_removed
[MLX4_MAX_PORTS
+ 1 - priv
->port
] = 0;
1486 mutex_unlock(&mdev
->state_lock
);
1489 /* mlx4_en_service_task - Run service task for tasks that needed to be done
1492 static void mlx4_en_service_task(struct work_struct
*work
)
1494 struct delayed_work
*delay
= to_delayed_work(work
);
1495 struct mlx4_en_priv
*priv
= container_of(delay
, struct mlx4_en_priv
,
1497 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1499 mutex_lock(&mdev
->state_lock
);
1500 if (mdev
->device_up
) {
1501 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
)
1502 mlx4_en_ptp_overflow_check(mdev
);
1504 queue_delayed_work(mdev
->workqueue
, &priv
->service_task
,
1505 SERVICE_TASK_DELAY
);
1507 mutex_unlock(&mdev
->state_lock
);
1510 static void mlx4_en_linkstate(struct work_struct
*work
)
1512 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1514 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1515 int linkstate
= priv
->link_state
;
1517 mutex_lock(&mdev
->state_lock
);
1518 /* If observable port state changed set carrier state and
1519 * report to system log */
1520 if (priv
->last_link_state
!= linkstate
) {
1521 if (linkstate
== MLX4_DEV_EVENT_PORT_DOWN
) {
1522 en_info(priv
, "Link Down\n");
1523 netif_carrier_off(priv
->dev
);
1525 en_info(priv
, "Link Up\n");
1526 netif_carrier_on(priv
->dev
);
1529 priv
->last_link_state
= linkstate
;
1530 mutex_unlock(&mdev
->state_lock
);
1534 int mlx4_en_start_port(struct net_device
*dev
)
1536 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1537 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1538 struct mlx4_en_cq
*cq
;
1539 struct mlx4_en_tx_ring
*tx_ring
;
1545 u8 mc_list
[16] = {0};
1547 if (priv
->port_up
) {
1548 en_dbg(DRV
, priv
, "start port called while port already up\n");
1552 INIT_LIST_HEAD(&priv
->mc_list
);
1553 INIT_LIST_HEAD(&priv
->curr_list
);
1554 INIT_LIST_HEAD(&priv
->ethtool_list
);
1555 memset(&priv
->ethtool_rules
[0], 0,
1556 sizeof(struct ethtool_flow_id
) * MAX_NUM_OF_FS_RULES
);
1558 /* Calculate Rx buf size */
1559 dev
->mtu
= min(dev
->mtu
, priv
->max_mtu
);
1560 mlx4_en_calc_rx_buf(dev
);
1561 en_dbg(DRV
, priv
, "Rx buf size:%d\n", priv
->rx_skb_size
);
1563 /* Configure rx cq's and rings */
1564 err
= mlx4_en_activate_rx_rings(priv
);
1566 en_err(priv
, "Failed to activate RX rings\n");
1569 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1570 cq
= priv
->rx_cq
[i
];
1572 mlx4_en_cq_init_lock(cq
);
1574 err
= mlx4_en_activate_cq(priv
, cq
, i
);
1576 en_err(priv
, "Failed activating Rx CQ\n");
1579 for (j
= 0; j
< cq
->size
; j
++)
1580 cq
->buf
[j
].owner_sr_opcode
= MLX4_CQE_OWNER_MASK
;
1581 err
= mlx4_en_set_cq_moder(priv
, cq
);
1583 en_err(priv
, "Failed setting cq moderation parameters");
1584 mlx4_en_deactivate_cq(priv
, cq
);
1587 mlx4_en_arm_cq(priv
, cq
);
1588 priv
->rx_ring
[i
]->cqn
= cq
->mcq
.cqn
;
1593 en_dbg(DRV
, priv
, "Getting qp number for port %d\n", priv
->port
);
1594 err
= mlx4_en_get_qp(priv
);
1596 en_err(priv
, "Failed getting eth qp\n");
1599 mdev
->mac_removed
[priv
->port
] = 0;
1601 err
= mlx4_en_config_rss_steer(priv
);
1603 en_err(priv
, "Failed configuring rss steering\n");
1607 err
= mlx4_en_create_drop_qp(priv
);
1611 /* Configure tx cq's and rings */
1612 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1614 cq
= priv
->tx_cq
[i
];
1615 err
= mlx4_en_activate_cq(priv
, cq
, i
);
1617 en_err(priv
, "Failed allocating Tx CQ\n");
1620 err
= mlx4_en_set_cq_moder(priv
, cq
);
1622 en_err(priv
, "Failed setting cq moderation parameters");
1623 mlx4_en_deactivate_cq(priv
, cq
);
1626 en_dbg(DRV
, priv
, "Resetting index of collapsed CQ:%d to -1\n", i
);
1627 cq
->buf
->wqe_index
= cpu_to_be16(0xffff);
1629 /* Configure ring */
1630 tx_ring
= priv
->tx_ring
[i
];
1631 err
= mlx4_en_activate_tx_ring(priv
, tx_ring
, cq
->mcq
.cqn
,
1632 i
/ priv
->num_tx_rings_p_up
);
1634 en_err(priv
, "Failed allocating Tx ring\n");
1635 mlx4_en_deactivate_cq(priv
, cq
);
1638 tx_ring
->tx_queue
= netdev_get_tx_queue(dev
, i
);
1640 /* Arm CQ for TX completions */
1641 mlx4_en_arm_cq(priv
, cq
);
1643 /* Set initial ownership of all Tx TXBBs to SW (1) */
1644 for (j
= 0; j
< tx_ring
->buf_size
; j
+= STAMP_STRIDE
)
1645 *((u32
*) (tx_ring
->buf
+ j
)) = 0xffffffff;
1649 /* Configure port */
1650 err
= mlx4_SET_PORT_general(mdev
->dev
, priv
->port
,
1651 priv
->rx_skb_size
+ ETH_FCS_LEN
,
1652 priv
->prof
->tx_pause
,
1654 priv
->prof
->rx_pause
,
1655 priv
->prof
->rx_ppp
);
1657 en_err(priv
, "Failed setting port general configurations for port %d, with error %d\n",
1661 /* Set default qp number */
1662 err
= mlx4_SET_PORT_qpn_calc(mdev
->dev
, priv
->port
, priv
->base_qpn
, 0);
1664 en_err(priv
, "Failed setting default qp numbers\n");
1668 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
1669 err
= mlx4_SET_PORT_VXLAN(mdev
->dev
, priv
->port
, VXLAN_STEER_BY_OUTER_MAC
, 1);
1671 en_err(priv
, "Failed setting port L2 tunnel configuration, err %d\n",
1678 en_dbg(HW
, priv
, "Initializing port\n");
1679 err
= mlx4_INIT_PORT(mdev
->dev
, priv
->port
);
1681 en_err(priv
, "Failed Initializing port\n");
1685 /* Attach rx QP to bradcast address */
1686 memset(&mc_list
[10], 0xff, ETH_ALEN
);
1687 mc_list
[5] = priv
->port
; /* needed for B0 steering support */
1688 if (mlx4_multicast_attach(mdev
->dev
, &priv
->rss_map
.indir_qp
, mc_list
,
1689 priv
->port
, 0, MLX4_PROT_ETH
,
1690 &priv
->broadcast_id
))
1691 mlx4_warn(mdev
, "Failed Attaching Broadcast\n");
1693 /* Must redo promiscuous mode setup. */
1694 priv
->flags
&= ~(MLX4_EN_FLAG_PROMISC
| MLX4_EN_FLAG_MC_PROMISC
);
1696 /* Schedule multicast task to populate multicast list */
1697 queue_work(mdev
->workqueue
, &priv
->rx_mode_task
);
1699 mlx4_set_stats_bitmap(mdev
->dev
, &priv
->stats_bitmap
);
1701 if (priv
->mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS
)
1702 vxlan_get_rx_port(dev
);
1703 priv
->port_up
= true;
1704 netif_tx_start_all_queues(dev
);
1705 netif_device_attach(dev
);
1710 while (tx_index
--) {
1711 mlx4_en_deactivate_tx_ring(priv
, priv
->tx_ring
[tx_index
]);
1712 mlx4_en_deactivate_cq(priv
, priv
->tx_cq
[tx_index
]);
1714 mlx4_en_destroy_drop_qp(priv
);
1716 mlx4_en_release_rss_steer(priv
);
1718 mlx4_en_put_qp(priv
);
1721 mlx4_en_deactivate_cq(priv
, priv
->rx_cq
[rx_index
]);
1722 for (i
= 0; i
< priv
->rx_ring_num
; i
++)
1723 mlx4_en_deactivate_rx_ring(priv
, priv
->rx_ring
[i
]);
1725 return err
; /* need to close devices */
1729 void mlx4_en_stop_port(struct net_device
*dev
, int detach
)
1731 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1732 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1733 struct mlx4_en_mc_list
*mclist
, *tmp
;
1734 struct ethtool_flow_id
*flow
, *tmp_flow
;
1736 u8 mc_list
[16] = {0};
1738 if (!priv
->port_up
) {
1739 en_dbg(DRV
, priv
, "stop port called while port already down\n");
1744 mlx4_CLOSE_PORT(mdev
->dev
, priv
->port
);
1746 /* Synchronize with tx routine */
1747 netif_tx_lock_bh(dev
);
1749 netif_device_detach(dev
);
1750 netif_tx_stop_all_queues(dev
);
1751 netif_tx_unlock_bh(dev
);
1753 netif_tx_disable(dev
);
1755 /* Set port as not active */
1756 priv
->port_up
= false;
1758 /* Promsicuous mode */
1759 if (mdev
->dev
->caps
.steering_mode
==
1760 MLX4_STEERING_MODE_DEVICE_MANAGED
) {
1761 priv
->flags
&= ~(MLX4_EN_FLAG_PROMISC
|
1762 MLX4_EN_FLAG_MC_PROMISC
);
1763 mlx4_flow_steer_promisc_remove(mdev
->dev
,
1765 MLX4_FS_ALL_DEFAULT
);
1766 mlx4_flow_steer_promisc_remove(mdev
->dev
,
1768 MLX4_FS_MC_DEFAULT
);
1769 } else if (priv
->flags
& MLX4_EN_FLAG_PROMISC
) {
1770 priv
->flags
&= ~MLX4_EN_FLAG_PROMISC
;
1772 /* Disable promiscouos mode */
1773 mlx4_unicast_promisc_remove(mdev
->dev
, priv
->base_qpn
,
1776 /* Disable Multicast promisc */
1777 if (priv
->flags
& MLX4_EN_FLAG_MC_PROMISC
) {
1778 mlx4_multicast_promisc_remove(mdev
->dev
, priv
->base_qpn
,
1780 priv
->flags
&= ~MLX4_EN_FLAG_MC_PROMISC
;
1784 /* Detach All multicasts */
1785 memset(&mc_list
[10], 0xff, ETH_ALEN
);
1786 mc_list
[5] = priv
->port
; /* needed for B0 steering support */
1787 mlx4_multicast_detach(mdev
->dev
, &priv
->rss_map
.indir_qp
, mc_list
,
1788 MLX4_PROT_ETH
, priv
->broadcast_id
);
1789 list_for_each_entry(mclist
, &priv
->curr_list
, list
) {
1790 memcpy(&mc_list
[10], mclist
->addr
, ETH_ALEN
);
1791 mc_list
[5] = priv
->port
;
1792 mlx4_multicast_detach(mdev
->dev
, &priv
->rss_map
.indir_qp
,
1793 mc_list
, MLX4_PROT_ETH
, mclist
->reg_id
);
1794 if (mclist
->tunnel_reg_id
)
1795 mlx4_flow_detach(mdev
->dev
, mclist
->tunnel_reg_id
);
1797 mlx4_en_clear_list(dev
);
1798 list_for_each_entry_safe(mclist
, tmp
, &priv
->curr_list
, list
) {
1799 list_del(&mclist
->list
);
1803 /* Flush multicast filter */
1804 mlx4_SET_MCAST_FLTR(mdev
->dev
, priv
->port
, 0, 1, MLX4_MCAST_CONFIG
);
1806 /* Remove flow steering rules for the port*/
1807 if (mdev
->dev
->caps
.steering_mode
==
1808 MLX4_STEERING_MODE_DEVICE_MANAGED
) {
1810 list_for_each_entry_safe(flow
, tmp_flow
,
1811 &priv
->ethtool_list
, list
) {
1812 mlx4_flow_detach(mdev
->dev
, flow
->id
);
1813 list_del(&flow
->list
);
1817 mlx4_en_destroy_drop_qp(priv
);
1820 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1821 mlx4_en_deactivate_tx_ring(priv
, priv
->tx_ring
[i
]);
1822 mlx4_en_deactivate_cq(priv
, priv
->tx_cq
[i
]);
1826 for (i
= 0; i
< priv
->tx_ring_num
; i
++)
1827 mlx4_en_free_tx_buf(dev
, priv
->tx_ring
[i
]);
1830 mlx4_en_release_rss_steer(priv
);
1832 /* Unregister Mac address for the port */
1833 mlx4_en_put_qp(priv
);
1834 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN
))
1835 mdev
->mac_removed
[priv
->port
] = 1;
1838 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1839 struct mlx4_en_cq
*cq
= priv
->rx_cq
[i
];
1842 while (!mlx4_en_cq_lock_napi(cq
)) {
1843 pr_info("CQ %d locked\n", i
);
1848 while (test_bit(NAPI_STATE_SCHED
, &cq
->napi
.state
))
1850 mlx4_en_deactivate_rx_ring(priv
, priv
->rx_ring
[i
]);
1851 mlx4_en_deactivate_cq(priv
, cq
);
1855 static void mlx4_en_restart(struct work_struct
*work
)
1857 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
1859 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1860 struct net_device
*dev
= priv
->dev
;
1862 en_dbg(DRV
, priv
, "Watchdog task called for port %d\n", priv
->port
);
1864 mutex_lock(&mdev
->state_lock
);
1865 if (priv
->port_up
) {
1866 mlx4_en_stop_port(dev
, 1);
1867 if (mlx4_en_start_port(dev
))
1868 en_err(priv
, "Failed restarting port %d\n", priv
->port
);
1870 mutex_unlock(&mdev
->state_lock
);
1873 static void mlx4_en_clear_stats(struct net_device
*dev
)
1875 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1876 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1879 if (mlx4_en_DUMP_ETH_STATS(mdev
, priv
->port
, 1))
1880 en_dbg(HW
, priv
, "Failed dumping statistics\n");
1882 memset(&priv
->stats
, 0, sizeof(priv
->stats
));
1883 memset(&priv
->pstats
, 0, sizeof(priv
->pstats
));
1884 memset(&priv
->pkstats
, 0, sizeof(priv
->pkstats
));
1885 memset(&priv
->port_stats
, 0, sizeof(priv
->port_stats
));
1887 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1888 priv
->tx_ring
[i
]->bytes
= 0;
1889 priv
->tx_ring
[i
]->packets
= 0;
1890 priv
->tx_ring
[i
]->tx_csum
= 0;
1892 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1893 priv
->rx_ring
[i
]->bytes
= 0;
1894 priv
->rx_ring
[i
]->packets
= 0;
1895 priv
->rx_ring
[i
]->csum_ok
= 0;
1896 priv
->rx_ring
[i
]->csum_none
= 0;
1900 static int mlx4_en_open(struct net_device
*dev
)
1902 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1903 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1906 mutex_lock(&mdev
->state_lock
);
1908 if (!mdev
->device_up
) {
1909 en_err(priv
, "Cannot open - device down/disabled\n");
1914 /* Reset HW statistics and SW counters */
1915 mlx4_en_clear_stats(dev
);
1917 err
= mlx4_en_start_port(dev
);
1919 en_err(priv
, "Failed starting port:%d\n", priv
->port
);
1922 mutex_unlock(&mdev
->state_lock
);
1927 static int mlx4_en_close(struct net_device
*dev
)
1929 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1930 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1932 en_dbg(IFDOWN
, priv
, "Close port called\n");
1934 mutex_lock(&mdev
->state_lock
);
1936 mlx4_en_stop_port(dev
, 0);
1937 netif_carrier_off(dev
);
1939 mutex_unlock(&mdev
->state_lock
);
1943 void mlx4_en_free_resources(struct mlx4_en_priv
*priv
)
1947 #ifdef CONFIG_RFS_ACCEL
1948 free_irq_cpu_rmap(priv
->dev
->rx_cpu_rmap
);
1949 priv
->dev
->rx_cpu_rmap
= NULL
;
1952 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1953 if (priv
->tx_ring
&& priv
->tx_ring
[i
])
1954 mlx4_en_destroy_tx_ring(priv
, &priv
->tx_ring
[i
]);
1955 if (priv
->tx_cq
&& priv
->tx_cq
[i
])
1956 mlx4_en_destroy_cq(priv
, &priv
->tx_cq
[i
]);
1959 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
1960 if (priv
->rx_ring
[i
])
1961 mlx4_en_destroy_rx_ring(priv
, &priv
->rx_ring
[i
],
1962 priv
->prof
->rx_ring_size
, priv
->stride
);
1964 mlx4_en_destroy_cq(priv
, &priv
->rx_cq
[i
]);
1967 if (priv
->base_tx_qpn
) {
1968 mlx4_qp_release_range(priv
->mdev
->dev
, priv
->base_tx_qpn
, priv
->tx_ring_num
);
1969 priv
->base_tx_qpn
= 0;
1973 int mlx4_en_alloc_resources(struct mlx4_en_priv
*priv
)
1975 struct mlx4_en_port_profile
*prof
= priv
->prof
;
1980 err
= mlx4_qp_reserve_range(priv
->mdev
->dev
, priv
->tx_ring_num
, 256, &priv
->base_tx_qpn
);
1982 en_err(priv
, "failed reserving range for TX rings\n");
1986 /* Create tx Rings */
1987 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
1988 node
= cpu_to_node(i
% num_online_cpus());
1989 if (mlx4_en_create_cq(priv
, &priv
->tx_cq
[i
],
1990 prof
->tx_ring_size
, i
, TX
, node
))
1993 if (mlx4_en_create_tx_ring(priv
, &priv
->tx_ring
[i
],
1994 priv
->base_tx_qpn
+ i
,
1995 prof
->tx_ring_size
, TXBB_SIZE
,
2000 /* Create rx Rings */
2001 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2002 node
= cpu_to_node(i
% num_online_cpus());
2003 if (mlx4_en_create_cq(priv
, &priv
->rx_cq
[i
],
2004 prof
->rx_ring_size
, i
, RX
, node
))
2007 if (mlx4_en_create_rx_ring(priv
, &priv
->rx_ring
[i
],
2008 prof
->rx_ring_size
, priv
->stride
,
2013 #ifdef CONFIG_RFS_ACCEL
2014 if (priv
->mdev
->dev
->caps
.comp_pool
) {
2015 priv
->dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(priv
->mdev
->dev
->caps
.comp_pool
);
2016 if (!priv
->dev
->rx_cpu_rmap
)
2024 en_err(priv
, "Failed to allocate NIC resources\n");
2025 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
2026 if (priv
->rx_ring
[i
])
2027 mlx4_en_destroy_rx_ring(priv
, &priv
->rx_ring
[i
],
2031 mlx4_en_destroy_cq(priv
, &priv
->rx_cq
[i
]);
2033 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
2034 if (priv
->tx_ring
[i
])
2035 mlx4_en_destroy_tx_ring(priv
, &priv
->tx_ring
[i
]);
2037 mlx4_en_destroy_cq(priv
, &priv
->tx_cq
[i
]);
2043 void mlx4_en_destroy_netdev(struct net_device
*dev
)
2045 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2046 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2048 en_dbg(DRV
, priv
, "Destroying netdev on port:%d\n", priv
->port
);
2050 /* Unregister device - this will close the port if it was up */
2051 if (priv
->registered
)
2052 unregister_netdev(dev
);
2054 if (priv
->allocated
)
2055 mlx4_free_hwq_res(mdev
->dev
, &priv
->res
, MLX4_EN_PAGE_SIZE
);
2057 cancel_delayed_work(&priv
->stats_task
);
2058 cancel_delayed_work(&priv
->service_task
);
2059 /* flush any pending task for this netdev */
2060 flush_workqueue(mdev
->workqueue
);
2062 /* Detach the netdev so tasks would not attempt to access it */
2063 mutex_lock(&mdev
->state_lock
);
2064 mdev
->pndev
[priv
->port
] = NULL
;
2065 mutex_unlock(&mdev
->state_lock
);
2067 mlx4_en_free_resources(priv
);
2069 kfree(priv
->tx_ring
);
2075 static int mlx4_en_change_mtu(struct net_device
*dev
, int new_mtu
)
2077 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2078 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2081 en_dbg(DRV
, priv
, "Change MTU called - current:%d new:%d\n",
2084 if ((new_mtu
< MLX4_EN_MIN_MTU
) || (new_mtu
> priv
->max_mtu
)) {
2085 en_err(priv
, "Bad MTU size:%d.\n", new_mtu
);
2090 if (netif_running(dev
)) {
2091 mutex_lock(&mdev
->state_lock
);
2092 if (!mdev
->device_up
) {
2093 /* NIC is probably restarting - let watchdog task reset
2095 en_dbg(DRV
, priv
, "Change MTU called with card down!?\n");
2097 mlx4_en_stop_port(dev
, 1);
2098 err
= mlx4_en_start_port(dev
);
2100 en_err(priv
, "Failed restarting port:%d\n",
2102 queue_work(mdev
->workqueue
, &priv
->watchdog_task
);
2105 mutex_unlock(&mdev
->state_lock
);
2110 static int mlx4_en_hwtstamp_set(struct net_device
*dev
, struct ifreq
*ifr
)
2112 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2113 struct mlx4_en_dev
*mdev
= priv
->mdev
;
2114 struct hwtstamp_config config
;
2116 if (copy_from_user(&config
, ifr
->ifr_data
, sizeof(config
)))
2119 /* reserved for future extensions */
2123 /* device doesn't support time stamping */
2124 if (!(mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
))
2127 /* TX HW timestamp */
2128 switch (config
.tx_type
) {
2129 case HWTSTAMP_TX_OFF
:
2130 case HWTSTAMP_TX_ON
:
2136 /* RX HW timestamp */
2137 switch (config
.rx_filter
) {
2138 case HWTSTAMP_FILTER_NONE
:
2140 case HWTSTAMP_FILTER_ALL
:
2141 case HWTSTAMP_FILTER_SOME
:
2142 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT
:
2143 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC
:
2144 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
:
2145 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT
:
2146 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC
:
2147 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
:
2148 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT
:
2149 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC
:
2150 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
:
2151 case HWTSTAMP_FILTER_PTP_V2_EVENT
:
2152 case HWTSTAMP_FILTER_PTP_V2_SYNC
:
2153 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
:
2154 config
.rx_filter
= HWTSTAMP_FILTER_ALL
;
2160 if (mlx4_en_timestamp_config(dev
, config
.tx_type
, config
.rx_filter
)) {
2161 config
.tx_type
= HWTSTAMP_TX_OFF
;
2162 config
.rx_filter
= HWTSTAMP_FILTER_NONE
;
2165 return copy_to_user(ifr
->ifr_data
, &config
,
2166 sizeof(config
)) ? -EFAULT
: 0;
2169 static int mlx4_en_hwtstamp_get(struct net_device
*dev
, struct ifreq
*ifr
)
2171 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2173 return copy_to_user(ifr
->ifr_data
, &priv
->hwtstamp_config
,
2174 sizeof(priv
->hwtstamp_config
)) ? -EFAULT
: 0;
2177 static int mlx4_en_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
2181 return mlx4_en_hwtstamp_set(dev
, ifr
);
2183 return mlx4_en_hwtstamp_get(dev
, ifr
);
2189 static int mlx4_en_set_features(struct net_device
*netdev
,
2190 netdev_features_t features
)
2192 struct mlx4_en_priv
*priv
= netdev_priv(netdev
);
2194 if (features
& NETIF_F_LOOPBACK
)
2195 priv
->ctrl_flags
|= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK
);
2198 cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK
);
2200 mlx4_en_update_loopback_state(netdev
, features
);
2206 static int mlx4_en_set_vf_mac(struct net_device
*dev
, int queue
, u8
*mac
)
2208 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2209 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2210 u64 mac_u64
= mlx4_mac_to_u64(mac
);
2212 if (!is_valid_ether_addr(mac
))
2215 return mlx4_set_vf_mac(mdev
->dev
, en_priv
->port
, queue
, mac_u64
);
2218 static int mlx4_en_set_vf_vlan(struct net_device
*dev
, int vf
, u16 vlan
, u8 qos
)
2220 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2221 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2223 return mlx4_set_vf_vlan(mdev
->dev
, en_priv
->port
, vf
, vlan
, qos
);
2226 static int mlx4_en_set_vf_spoofchk(struct net_device
*dev
, int vf
, bool setting
)
2228 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2229 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2231 return mlx4_set_vf_spoofchk(mdev
->dev
, en_priv
->port
, vf
, setting
);
2234 static int mlx4_en_get_vf_config(struct net_device
*dev
, int vf
, struct ifla_vf_info
*ivf
)
2236 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2237 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2239 return mlx4_get_vf_config(mdev
->dev
, en_priv
->port
, vf
, ivf
);
2242 static int mlx4_en_set_vf_link_state(struct net_device
*dev
, int vf
, int link_state
)
2244 struct mlx4_en_priv
*en_priv
= netdev_priv(dev
);
2245 struct mlx4_en_dev
*mdev
= en_priv
->mdev
;
2247 return mlx4_set_vf_link_state(mdev
->dev
, en_priv
->port
, vf
, link_state
);
2250 #define PORT_ID_BYTE_LEN 8
2251 static int mlx4_en_get_phys_port_id(struct net_device
*dev
,
2252 struct netdev_phys_port_id
*ppid
)
2254 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2255 struct mlx4_dev
*mdev
= priv
->mdev
->dev
;
2257 u64 phys_port_id
= mdev
->caps
.phys_port_id
[priv
->port
];
2262 ppid
->id_len
= sizeof(phys_port_id
);
2263 for (i
= PORT_ID_BYTE_LEN
- 1; i
>= 0; --i
) {
2264 ppid
->id
[i
] = phys_port_id
& 0xff;
2270 static void mlx4_en_add_vxlan_offloads(struct work_struct
*work
)
2273 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
2276 ret
= mlx4_config_vxlan_port(priv
->mdev
->dev
, priv
->vxlan_port
);
2280 ret
= mlx4_SET_PORT_VXLAN(priv
->mdev
->dev
, priv
->port
,
2281 VXLAN_STEER_BY_OUTER_MAC
, 1);
2284 en_err(priv
, "failed setting L2 tunnel configuration ret %d\n", ret
);
2287 static void mlx4_en_del_vxlan_offloads(struct work_struct
*work
)
2290 struct mlx4_en_priv
*priv
= container_of(work
, struct mlx4_en_priv
,
2293 ret
= mlx4_SET_PORT_VXLAN(priv
->mdev
->dev
, priv
->port
,
2294 VXLAN_STEER_BY_OUTER_MAC
, 0);
2296 en_err(priv
, "failed setting L2 tunnel configuration ret %d\n", ret
);
2298 priv
->vxlan_port
= 0;
2301 static void mlx4_en_add_vxlan_port(struct net_device
*dev
,
2302 sa_family_t sa_family
, __be16 port
)
2304 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2305 __be16 current_port
;
2307 if (!(priv
->mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS
))
2310 if (sa_family
== AF_INET6
)
2313 current_port
= priv
->vxlan_port
;
2314 if (current_port
&& current_port
!= port
) {
2315 en_warn(priv
, "vxlan port %d configured, can't add port %d\n",
2316 ntohs(current_port
), ntohs(port
));
2320 priv
->vxlan_port
= port
;
2321 queue_work(priv
->mdev
->workqueue
, &priv
->vxlan_add_task
);
2324 static void mlx4_en_del_vxlan_port(struct net_device
*dev
,
2325 sa_family_t sa_family
, __be16 port
)
2327 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
2328 __be16 current_port
;
2330 if (priv
->mdev
->dev
->caps
.tunnel_offload_mode
!= MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
)
2333 if (sa_family
== AF_INET6
)
2336 current_port
= priv
->vxlan_port
;
2337 if (current_port
!= port
) {
2338 en_dbg(DRV
, priv
, "vxlan port %d isn't configured, ignoring\n", ntohs(port
));
2342 queue_work(priv
->mdev
->workqueue
, &priv
->vxlan_del_task
);
2345 static const struct net_device_ops mlx4_netdev_ops
= {
2346 .ndo_open
= mlx4_en_open
,
2347 .ndo_stop
= mlx4_en_close
,
2348 .ndo_start_xmit
= mlx4_en_xmit
,
2349 .ndo_select_queue
= mlx4_en_select_queue
,
2350 .ndo_get_stats
= mlx4_en_get_stats
,
2351 .ndo_set_rx_mode
= mlx4_en_set_rx_mode
,
2352 .ndo_set_mac_address
= mlx4_en_set_mac
,
2353 .ndo_validate_addr
= eth_validate_addr
,
2354 .ndo_change_mtu
= mlx4_en_change_mtu
,
2355 .ndo_do_ioctl
= mlx4_en_ioctl
,
2356 .ndo_tx_timeout
= mlx4_en_tx_timeout
,
2357 .ndo_vlan_rx_add_vid
= mlx4_en_vlan_rx_add_vid
,
2358 .ndo_vlan_rx_kill_vid
= mlx4_en_vlan_rx_kill_vid
,
2359 #ifdef CONFIG_NET_POLL_CONTROLLER
2360 .ndo_poll_controller
= mlx4_en_netpoll
,
2362 .ndo_set_features
= mlx4_en_set_features
,
2363 .ndo_setup_tc
= mlx4_en_setup_tc
,
2364 #ifdef CONFIG_RFS_ACCEL
2365 .ndo_rx_flow_steer
= mlx4_en_filter_rfs
,
2367 #ifdef CONFIG_NET_RX_BUSY_POLL
2368 .ndo_busy_poll
= mlx4_en_low_latency_recv
,
2370 .ndo_get_phys_port_id
= mlx4_en_get_phys_port_id
,
2371 .ndo_add_vxlan_port
= mlx4_en_add_vxlan_port
,
2372 .ndo_del_vxlan_port
= mlx4_en_del_vxlan_port
,
2375 static const struct net_device_ops mlx4_netdev_ops_master
= {
2376 .ndo_open
= mlx4_en_open
,
2377 .ndo_stop
= mlx4_en_close
,
2378 .ndo_start_xmit
= mlx4_en_xmit
,
2379 .ndo_select_queue
= mlx4_en_select_queue
,
2380 .ndo_get_stats
= mlx4_en_get_stats
,
2381 .ndo_set_rx_mode
= mlx4_en_set_rx_mode
,
2382 .ndo_set_mac_address
= mlx4_en_set_mac
,
2383 .ndo_validate_addr
= eth_validate_addr
,
2384 .ndo_change_mtu
= mlx4_en_change_mtu
,
2385 .ndo_tx_timeout
= mlx4_en_tx_timeout
,
2386 .ndo_vlan_rx_add_vid
= mlx4_en_vlan_rx_add_vid
,
2387 .ndo_vlan_rx_kill_vid
= mlx4_en_vlan_rx_kill_vid
,
2388 .ndo_set_vf_mac
= mlx4_en_set_vf_mac
,
2389 .ndo_set_vf_vlan
= mlx4_en_set_vf_vlan
,
2390 .ndo_set_vf_spoofchk
= mlx4_en_set_vf_spoofchk
,
2391 .ndo_set_vf_link_state
= mlx4_en_set_vf_link_state
,
2392 .ndo_get_vf_config
= mlx4_en_get_vf_config
,
2393 #ifdef CONFIG_NET_POLL_CONTROLLER
2394 .ndo_poll_controller
= mlx4_en_netpoll
,
2396 .ndo_set_features
= mlx4_en_set_features
,
2397 .ndo_setup_tc
= mlx4_en_setup_tc
,
2398 #ifdef CONFIG_RFS_ACCEL
2399 .ndo_rx_flow_steer
= mlx4_en_filter_rfs
,
2401 .ndo_get_phys_port_id
= mlx4_en_get_phys_port_id
,
2404 int mlx4_en_init_netdev(struct mlx4_en_dev
*mdev
, int port
,
2405 struct mlx4_en_port_profile
*prof
)
2407 struct net_device
*dev
;
2408 struct mlx4_en_priv
*priv
;
2413 dev
= alloc_etherdev_mqs(sizeof(struct mlx4_en_priv
),
2414 MAX_TX_RINGS
, MAX_RX_RINGS
);
2418 netif_set_real_num_tx_queues(dev
, prof
->tx_ring_num
);
2419 netif_set_real_num_rx_queues(dev
, prof
->rx_ring_num
);
2421 SET_NETDEV_DEV(dev
, &mdev
->dev
->pdev
->dev
);
2422 dev
->dev_port
= port
- 1;
2425 * Initialize driver private data
2428 priv
= netdev_priv(dev
);
2429 memset(priv
, 0, sizeof(struct mlx4_en_priv
));
2432 priv
->ddev
= &mdev
->pdev
->dev
;
2435 priv
->port_up
= false;
2436 priv
->flags
= prof
->flags
;
2437 priv
->ctrl_flags
= cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE
|
2438 MLX4_WQE_CTRL_SOLICITED
);
2439 priv
->num_tx_rings_p_up
= mdev
->profile
.num_tx_rings_p_up
;
2440 priv
->tx_ring_num
= prof
->tx_ring_num
;
2442 priv
->tx_ring
= kzalloc(sizeof(struct mlx4_en_tx_ring
*) * MAX_TX_RINGS
,
2444 if (!priv
->tx_ring
) {
2448 priv
->tx_cq
= kzalloc(sizeof(struct mlx4_en_cq
*) * MAX_TX_RINGS
,
2454 priv
->rx_ring_num
= prof
->rx_ring_num
;
2455 priv
->cqe_factor
= (mdev
->dev
->caps
.cqe_size
== 64) ? 1 : 0;
2456 priv
->mac_index
= -1;
2457 priv
->msg_enable
= MLX4_EN_MSG_LEVEL
;
2458 spin_lock_init(&priv
->stats_lock
);
2459 INIT_WORK(&priv
->rx_mode_task
, mlx4_en_do_set_rx_mode
);
2460 INIT_WORK(&priv
->watchdog_task
, mlx4_en_restart
);
2461 INIT_WORK(&priv
->linkstate_task
, mlx4_en_linkstate
);
2462 INIT_DELAYED_WORK(&priv
->stats_task
, mlx4_en_do_get_stats
);
2463 INIT_DELAYED_WORK(&priv
->service_task
, mlx4_en_service_task
);
2464 INIT_WORK(&priv
->vxlan_add_task
, mlx4_en_add_vxlan_offloads
);
2465 INIT_WORK(&priv
->vxlan_del_task
, mlx4_en_del_vxlan_offloads
);
2466 #ifdef CONFIG_MLX4_EN_DCB
2467 if (!mlx4_is_slave(priv
->mdev
->dev
)) {
2468 if (mdev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_SET_ETH_SCHED
) {
2469 dev
->dcbnl_ops
= &mlx4_en_dcbnl_ops
;
2471 en_info(priv
, "enabling only PFC DCB ops\n");
2472 dev
->dcbnl_ops
= &mlx4_en_dcbnl_pfc_ops
;
2477 for (i
= 0; i
< MLX4_EN_MAC_HASH_SIZE
; ++i
)
2478 INIT_HLIST_HEAD(&priv
->mac_hash
[i
]);
2480 /* Query for default mac and max mtu */
2481 priv
->max_mtu
= mdev
->dev
->caps
.eth_mtu_cap
[priv
->port
];
2483 /* Set default MAC */
2484 dev
->addr_len
= ETH_ALEN
;
2485 mlx4_en_u64_to_mac(dev
->dev_addr
, mdev
->dev
->caps
.def_mac
[priv
->port
]);
2486 if (!is_valid_ether_addr(dev
->dev_addr
)) {
2487 if (mlx4_is_slave(priv
->mdev
->dev
)) {
2488 eth_hw_addr_random(dev
);
2489 en_warn(priv
, "Assigned random MAC address %pM\n", dev
->dev_addr
);
2490 mac_u64
= mlx4_mac_to_u64(dev
->dev_addr
);
2491 mdev
->dev
->caps
.def_mac
[priv
->port
] = mac_u64
;
2493 en_err(priv
, "Port: %d, invalid mac burned: %pM, quiting\n",
2494 priv
->port
, dev
->dev_addr
);
2500 memcpy(priv
->prev_mac
, dev
->dev_addr
, sizeof(priv
->prev_mac
));
2502 priv
->stride
= roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc
) +
2503 DS_SIZE
* MLX4_EN_MAX_RX_FRAGS
);
2504 err
= mlx4_en_alloc_resources(priv
);
2508 #ifdef CONFIG_RFS_ACCEL
2509 INIT_LIST_HEAD(&priv
->filters
);
2510 spin_lock_init(&priv
->filters_lock
);
2513 /* Initialize time stamping config */
2514 priv
->hwtstamp_config
.flags
= 0;
2515 priv
->hwtstamp_config
.tx_type
= HWTSTAMP_TX_OFF
;
2516 priv
->hwtstamp_config
.rx_filter
= HWTSTAMP_FILTER_NONE
;
2518 /* Allocate page for receive rings */
2519 err
= mlx4_alloc_hwq_res(mdev
->dev
, &priv
->res
,
2520 MLX4_EN_PAGE_SIZE
, MLX4_EN_PAGE_SIZE
);
2522 en_err(priv
, "Failed to allocate page for rx qps\n");
2525 priv
->allocated
= 1;
2528 * Initialize netdev entry points
2530 if (mlx4_is_master(priv
->mdev
->dev
))
2531 dev
->netdev_ops
= &mlx4_netdev_ops_master
;
2533 dev
->netdev_ops
= &mlx4_netdev_ops
;
2534 dev
->watchdog_timeo
= MLX4_EN_WATCHDOG_TIMEOUT
;
2535 netif_set_real_num_tx_queues(dev
, priv
->tx_ring_num
);
2536 netif_set_real_num_rx_queues(dev
, priv
->rx_ring_num
);
2538 SET_ETHTOOL_OPS(dev
, &mlx4_en_ethtool_ops
);
2541 * Set driver features
2543 dev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
2544 if (mdev
->LSO_support
)
2545 dev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
2547 dev
->vlan_features
= dev
->hw_features
;
2549 dev
->hw_features
|= NETIF_F_RXCSUM
| NETIF_F_RXHASH
;
2550 dev
->features
= dev
->hw_features
| NETIF_F_HIGHDMA
|
2551 NETIF_F_HW_VLAN_CTAG_TX
| NETIF_F_HW_VLAN_CTAG_RX
|
2552 NETIF_F_HW_VLAN_CTAG_FILTER
;
2553 dev
->hw_features
|= NETIF_F_LOOPBACK
;
2555 if (mdev
->dev
->caps
.steering_mode
==
2556 MLX4_STEERING_MODE_DEVICE_MANAGED
)
2557 dev
->hw_features
|= NETIF_F_NTUPLE
;
2559 if (mdev
->dev
->caps
.steering_mode
!= MLX4_STEERING_MODE_A0
)
2560 dev
->priv_flags
|= IFF_UNICAST_FLT
;
2562 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
2563 dev
->hw_enc_features
|= NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
2564 NETIF_F_TSO
| NETIF_F_GSO_UDP_TUNNEL
;
2565 dev
->hw_features
|= NETIF_F_GSO_UDP_TUNNEL
;
2566 dev
->features
|= NETIF_F_GSO_UDP_TUNNEL
;
2569 mdev
->pndev
[port
] = dev
;
2571 netif_carrier_off(dev
);
2572 mlx4_en_set_default_moderation(priv
);
2574 err
= register_netdev(dev
);
2576 en_err(priv
, "Netdev registration failed for port %d\n", port
);
2579 priv
->registered
= 1;
2581 en_warn(priv
, "Using %d TX rings\n", prof
->tx_ring_num
);
2582 en_warn(priv
, "Using %d RX rings\n", prof
->rx_ring_num
);
2584 mlx4_en_update_loopback_state(priv
->dev
, priv
->dev
->features
);
2586 /* Configure port */
2587 mlx4_en_calc_rx_buf(dev
);
2588 err
= mlx4_SET_PORT_general(mdev
->dev
, priv
->port
,
2589 priv
->rx_skb_size
+ ETH_FCS_LEN
,
2590 prof
->tx_pause
, prof
->tx_ppp
,
2591 prof
->rx_pause
, prof
->rx_ppp
);
2593 en_err(priv
, "Failed setting port general configurations "
2594 "for port %d, with error %d\n", priv
->port
, err
);
2598 if (mdev
->dev
->caps
.tunnel_offload_mode
== MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
) {
2599 err
= mlx4_SET_PORT_VXLAN(mdev
->dev
, priv
->port
, VXLAN_STEER_BY_OUTER_MAC
, 1);
2601 en_err(priv
, "Failed setting port L2 tunnel configuration, err %d\n",
2608 en_warn(priv
, "Initializing port\n");
2609 err
= mlx4_INIT_PORT(mdev
->dev
, priv
->port
);
2611 en_err(priv
, "Failed Initializing port\n");
2614 queue_delayed_work(mdev
->workqueue
, &priv
->stats_task
, STATS_DELAY
);
2616 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
)
2617 queue_delayed_work(mdev
->workqueue
, &priv
->service_task
,
2618 SERVICE_TASK_DELAY
);
2623 mlx4_en_destroy_netdev(dev
);