1 /* QLogic qede NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/version.h>
12 #include <linux/device.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <linux/skbuff.h>
16 #include <linux/errno.h>
17 #include <linux/list.h>
18 #include <linux/string.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/interrupt.h>
21 #include <asm/byteorder.h>
22 #include <asm/param.h>
24 #include <linux/netdev_features.h>
25 #include <linux/udp.h>
26 #include <linux/tcp.h>
27 #include <net/vxlan.h>
31 #include <linux/if_ether.h>
32 #include <linux/if_vlan.h>
33 #include <linux/pkt_sched.h>
34 #include <linux/ethtool.h>
36 #include <linux/random.h>
37 #include <net/ip6_checksum.h>
38 #include <linux/bitops.h>
42 static const char version
[] = "QLogic QL4xxx 40G/100G Ethernet Driver qede "
43 DRV_MODULE_VERSION
"\n";
45 MODULE_DESCRIPTION("QLogic 40G/100G Ethernet Driver");
46 MODULE_LICENSE("GPL");
47 MODULE_VERSION(DRV_MODULE_VERSION
);
50 module_param(debug
, uint
, 0);
51 MODULE_PARM_DESC(debug
, " Default debug msglevel");
53 static const struct qed_eth_ops
*qed_ops
;
55 #define CHIP_NUM_57980S_40 0x1634
56 #define CHIP_NUM_57980S_10 0x1666
57 #define CHIP_NUM_57980S_MF 0x1636
58 #define CHIP_NUM_57980S_100 0x1644
59 #define CHIP_NUM_57980S_50 0x1654
60 #define CHIP_NUM_57980S_25 0x1656
62 #ifndef PCI_DEVICE_ID_NX2_57980E
63 #define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40
64 #define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10
65 #define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF
66 #define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100
67 #define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50
68 #define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25
71 static const struct pci_device_id qede_pci_tbl
[] = {
72 { PCI_VDEVICE(QLOGIC
, PCI_DEVICE_ID_57980S_40
), 0 },
73 { PCI_VDEVICE(QLOGIC
, PCI_DEVICE_ID_57980S_10
), 0 },
74 { PCI_VDEVICE(QLOGIC
, PCI_DEVICE_ID_57980S_MF
), 0 },
75 { PCI_VDEVICE(QLOGIC
, PCI_DEVICE_ID_57980S_100
), 0 },
76 { PCI_VDEVICE(QLOGIC
, PCI_DEVICE_ID_57980S_50
), 0 },
77 { PCI_VDEVICE(QLOGIC
, PCI_DEVICE_ID_57980S_25
), 0 },
81 MODULE_DEVICE_TABLE(pci
, qede_pci_tbl
);
83 static int qede_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
);
85 #define TX_TIMEOUT (5 * HZ)
87 static void qede_remove(struct pci_dev
*pdev
);
88 static int qede_alloc_rx_buffer(struct qede_dev
*edev
,
89 struct qede_rx_queue
*rxq
);
90 static void qede_link_update(void *dev
, struct qed_link_output
*link
);
92 static struct pci_driver qede_pci_driver
= {
94 .id_table
= qede_pci_tbl
,
96 .remove
= qede_remove
,
99 static struct qed_eth_cb_ops qede_ll_ops
= {
101 .link_update
= qede_link_update
,
105 static int qede_netdev_event(struct notifier_block
*this, unsigned long event
,
108 struct net_device
*ndev
= netdev_notifier_info_to_dev(ptr
);
109 struct ethtool_drvinfo drvinfo
;
110 struct qede_dev
*edev
;
112 /* Currently only support name change */
113 if (event
!= NETDEV_CHANGENAME
)
116 /* Check whether this is a qede device */
117 if (!ndev
|| !ndev
->ethtool_ops
|| !ndev
->ethtool_ops
->get_drvinfo
)
120 memset(&drvinfo
, 0, sizeof(drvinfo
));
121 ndev
->ethtool_ops
->get_drvinfo(ndev
, &drvinfo
);
122 if (strcmp(drvinfo
.driver
, "qede"))
124 edev
= netdev_priv(ndev
);
126 /* Notify qed of the name change */
127 if (!edev
->ops
|| !edev
->ops
->common
)
129 edev
->ops
->common
->set_id(edev
->cdev
, edev
->ndev
->name
,
136 static struct notifier_block qede_netdev_notifier
= {
137 .notifier_call
= qede_netdev_event
,
141 int __init
qede_init(void)
146 pr_notice("qede_init: %s\n", version
);
148 qed_ver
= qed_get_protocol_version(QED_PROTOCOL_ETH
);
149 if (qed_ver
!= QEDE_ETH_INTERFACE_VERSION
) {
150 pr_notice("Version mismatch [%08x != %08x]\n",
152 QEDE_ETH_INTERFACE_VERSION
);
156 qed_ops
= qed_get_eth_ops(QEDE_ETH_INTERFACE_VERSION
);
158 pr_notice("Failed to get qed ethtool operations\n");
162 /* Must register notifier before pci ops, since we might miss
163 * interface rename after pci probe and netdev registeration.
165 ret
= register_netdevice_notifier(&qede_netdev_notifier
);
167 pr_notice("Failed to register netdevice_notifier\n");
172 ret
= pci_register_driver(&qede_pci_driver
);
174 pr_notice("Failed to register driver\n");
175 unregister_netdevice_notifier(&qede_netdev_notifier
);
183 static void __exit
qede_cleanup(void)
185 pr_notice("qede_cleanup called\n");
187 unregister_netdevice_notifier(&qede_netdev_notifier
);
188 pci_unregister_driver(&qede_pci_driver
);
192 module_init(qede_init
);
193 module_exit(qede_cleanup
);
195 /* -------------------------------------------------------------------------
197 * -------------------------------------------------------------------------
200 /* Unmap the data and free skb */
201 static int qede_free_tx_pkt(struct qede_dev
*edev
,
202 struct qede_tx_queue
*txq
,
205 u16 idx
= txq
->sw_tx_cons
& NUM_TX_BDS_MAX
;
206 struct sk_buff
*skb
= txq
->sw_tx_ring
[idx
].skb
;
207 struct eth_tx_1st_bd
*first_bd
;
208 struct eth_tx_bd
*tx_data_bd
;
209 int bds_consumed
= 0;
211 bool data_split
= txq
->sw_tx_ring
[idx
].flags
& QEDE_TSO_SPLIT_BD
;
212 int i
, split_bd_len
= 0;
214 if (unlikely(!skb
)) {
216 "skb is null for txq idx=%d txq->sw_tx_cons=%d txq->sw_tx_prod=%d\n",
217 idx
, txq
->sw_tx_cons
, txq
->sw_tx_prod
);
223 first_bd
= (struct eth_tx_1st_bd
*)qed_chain_consume(&txq
->tx_pbl
);
227 nbds
= first_bd
->data
.nbds
;
230 struct eth_tx_bd
*split
= (struct eth_tx_bd
*)
231 qed_chain_consume(&txq
->tx_pbl
);
232 split_bd_len
= BD_UNMAP_LEN(split
);
235 dma_unmap_page(&edev
->pdev
->dev
, BD_UNMAP_ADDR(first_bd
),
236 BD_UNMAP_LEN(first_bd
) + split_bd_len
, DMA_TO_DEVICE
);
238 /* Unmap the data of the skb frags */
239 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++, bds_consumed
++) {
240 tx_data_bd
= (struct eth_tx_bd
*)
241 qed_chain_consume(&txq
->tx_pbl
);
242 dma_unmap_page(&edev
->pdev
->dev
, BD_UNMAP_ADDR(tx_data_bd
),
243 BD_UNMAP_LEN(tx_data_bd
), DMA_TO_DEVICE
);
246 while (bds_consumed
++ < nbds
)
247 qed_chain_consume(&txq
->tx_pbl
);
250 dev_kfree_skb_any(skb
);
251 txq
->sw_tx_ring
[idx
].skb
= NULL
;
252 txq
->sw_tx_ring
[idx
].flags
= 0;
257 /* Unmap the data and free skb when mapping failed during start_xmit */
258 static void qede_free_failed_tx_pkt(struct qede_dev
*edev
,
259 struct qede_tx_queue
*txq
,
260 struct eth_tx_1st_bd
*first_bd
,
264 u16 idx
= txq
->sw_tx_prod
& NUM_TX_BDS_MAX
;
265 struct sk_buff
*skb
= txq
->sw_tx_ring
[idx
].skb
;
266 struct eth_tx_bd
*tx_data_bd
;
267 int i
, split_bd_len
= 0;
269 /* Return prod to its position before this skb was handled */
270 qed_chain_set_prod(&txq
->tx_pbl
,
271 le16_to_cpu(txq
->tx_db
.data
.bd_prod
),
274 first_bd
= (struct eth_tx_1st_bd
*)qed_chain_produce(&txq
->tx_pbl
);
277 struct eth_tx_bd
*split
= (struct eth_tx_bd
*)
278 qed_chain_produce(&txq
->tx_pbl
);
279 split_bd_len
= BD_UNMAP_LEN(split
);
283 dma_unmap_page(&edev
->pdev
->dev
, BD_UNMAP_ADDR(first_bd
),
284 BD_UNMAP_LEN(first_bd
) + split_bd_len
, DMA_TO_DEVICE
);
286 /* Unmap the data of the skb frags */
287 for (i
= 0; i
< nbd
; i
++) {
288 tx_data_bd
= (struct eth_tx_bd
*)
289 qed_chain_produce(&txq
->tx_pbl
);
290 if (tx_data_bd
->nbytes
)
291 dma_unmap_page(&edev
->pdev
->dev
,
292 BD_UNMAP_ADDR(tx_data_bd
),
293 BD_UNMAP_LEN(tx_data_bd
), DMA_TO_DEVICE
);
296 /* Return again prod to its position before this skb was handled */
297 qed_chain_set_prod(&txq
->tx_pbl
,
298 le16_to_cpu(txq
->tx_db
.data
.bd_prod
),
302 dev_kfree_skb_any(skb
);
303 txq
->sw_tx_ring
[idx
].skb
= NULL
;
304 txq
->sw_tx_ring
[idx
].flags
= 0;
307 static u32
qede_xmit_type(struct qede_dev
*edev
,
311 u32 rc
= XMIT_L4_CSUM
;
314 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
317 l3_proto
= vlan_get_protocol(skb
);
318 if (l3_proto
== htons(ETH_P_IPV6
) &&
319 (ipv6_hdr(skb
)->nexthdr
== NEXTHDR_IPV6
))
328 static void qede_set_params_for_ipv6_ext(struct sk_buff
*skb
,
329 struct eth_tx_2nd_bd
*second_bd
,
330 struct eth_tx_3rd_bd
*third_bd
)
333 u16 bd2_bits1
= 0, bd2_bits2
= 0;
335 bd2_bits1
|= (1 << ETH_TX_DATA_2ND_BD_IPV6_EXT_SHIFT
);
337 bd2_bits2
|= ((((u8
*)skb_transport_header(skb
) - skb
->data
) >> 1) &
338 ETH_TX_DATA_2ND_BD_L4_HDR_START_OFFSET_W_MASK
)
339 << ETH_TX_DATA_2ND_BD_L4_HDR_START_OFFSET_W_SHIFT
;
341 bd2_bits1
|= (ETH_L4_PSEUDO_CSUM_CORRECT_LENGTH
<<
342 ETH_TX_DATA_2ND_BD_L4_PSEUDO_CSUM_MODE_SHIFT
);
344 if (vlan_get_protocol(skb
) == htons(ETH_P_IPV6
))
345 l4_proto
= ipv6_hdr(skb
)->nexthdr
;
347 l4_proto
= ip_hdr(skb
)->protocol
;
349 if (l4_proto
== IPPROTO_UDP
)
350 bd2_bits1
|= 1 << ETH_TX_DATA_2ND_BD_L4_UDP_SHIFT
;
353 third_bd
->data
.bitfields
|=
354 cpu_to_le16(((tcp_hdrlen(skb
) / 4) &
355 ETH_TX_DATA_3RD_BD_TCP_HDR_LEN_DW_MASK
) <<
356 ETH_TX_DATA_3RD_BD_TCP_HDR_LEN_DW_SHIFT
);
358 second_bd
->data
.bitfields1
= cpu_to_le16(bd2_bits1
);
359 second_bd
->data
.bitfields2
= cpu_to_le16(bd2_bits2
);
362 static int map_frag_to_bd(struct qede_dev
*edev
,
364 struct eth_tx_bd
*bd
)
368 /* Map skb non-linear frag data for DMA */
369 mapping
= skb_frag_dma_map(&edev
->pdev
->dev
, frag
, 0,
372 if (unlikely(dma_mapping_error(&edev
->pdev
->dev
, mapping
))) {
373 DP_NOTICE(edev
, "Unable to map frag - dropping packet\n");
377 /* Setup the data pointer of the frag data */
378 BD_SET_UNMAP_ADDR_LEN(bd
, mapping
, skb_frag_size(frag
));
383 /* +2 for 1st BD for headers and 2nd BD for headlen (if required) */
384 #if ((MAX_SKB_FRAGS + 2) > ETH_TX_MAX_BDS_PER_NON_LSO_PACKET)
385 static bool qede_pkt_req_lin(struct qede_dev
*edev
, struct sk_buff
*skb
,
388 int allowed_frags
= ETH_TX_MAX_BDS_PER_NON_LSO_PACKET
- 1;
390 if (xmit_type
& XMIT_LSO
) {
393 hlen
= skb_transport_header(skb
) +
394 tcp_hdrlen(skb
) - skb
->data
;
396 /* linear payload would require its own BD */
397 if (skb_headlen(skb
) > hlen
)
401 return (skb_shinfo(skb
)->nr_frags
> allowed_frags
);
405 /* Main transmit function */
407 netdev_tx_t
qede_start_xmit(struct sk_buff
*skb
,
408 struct net_device
*ndev
)
410 struct qede_dev
*edev
= netdev_priv(ndev
);
411 struct netdev_queue
*netdev_txq
;
412 struct qede_tx_queue
*txq
;
413 struct eth_tx_1st_bd
*first_bd
;
414 struct eth_tx_2nd_bd
*second_bd
= NULL
;
415 struct eth_tx_3rd_bd
*third_bd
= NULL
;
416 struct eth_tx_bd
*tx_data_bd
= NULL
;
420 int rc
, frag_idx
= 0, ipv6_ext
= 0;
426 /* Get tx-queue context and netdev index */
427 txq_index
= skb_get_queue_mapping(skb
);
428 WARN_ON(txq_index
>= QEDE_TSS_CNT(edev
));
429 txq
= QEDE_TX_QUEUE(edev
, txq_index
);
430 netdev_txq
= netdev_get_tx_queue(ndev
, txq_index
);
432 WARN_ON(qed_chain_get_elem_left(&txq
->tx_pbl
) <
433 (MAX_SKB_FRAGS
+ 1));
435 xmit_type
= qede_xmit_type(edev
, skb
, &ipv6_ext
);
437 #if ((MAX_SKB_FRAGS + 2) > ETH_TX_MAX_BDS_PER_NON_LSO_PACKET)
438 if (qede_pkt_req_lin(edev
, skb
, xmit_type
)) {
439 if (skb_linearize(skb
)) {
441 "SKB linearization failed - silently dropping this SKB\n");
442 dev_kfree_skb_any(skb
);
448 /* Fill the entry in the SW ring and the BDs in the FW ring */
449 idx
= txq
->sw_tx_prod
& NUM_TX_BDS_MAX
;
450 txq
->sw_tx_ring
[idx
].skb
= skb
;
451 first_bd
= (struct eth_tx_1st_bd
*)
452 qed_chain_produce(&txq
->tx_pbl
);
453 memset(first_bd
, 0, sizeof(*first_bd
));
454 first_bd
->data
.bd_flags
.bitfields
=
455 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT
;
457 /* Map skb linear data for DMA and set in the first BD */
458 mapping
= dma_map_single(&edev
->pdev
->dev
, skb
->data
,
459 skb_headlen(skb
), DMA_TO_DEVICE
);
460 if (unlikely(dma_mapping_error(&edev
->pdev
->dev
, mapping
))) {
461 DP_NOTICE(edev
, "SKB mapping failed\n");
462 qede_free_failed_tx_pkt(edev
, txq
, first_bd
, 0, false);
466 BD_SET_UNMAP_ADDR_LEN(first_bd
, mapping
, skb_headlen(skb
));
468 /* In case there is IPv6 with extension headers or LSO we need 2nd and
471 if (unlikely((xmit_type
& XMIT_LSO
) | ipv6_ext
)) {
472 second_bd
= (struct eth_tx_2nd_bd
*)
473 qed_chain_produce(&txq
->tx_pbl
);
474 memset(second_bd
, 0, sizeof(*second_bd
));
477 third_bd
= (struct eth_tx_3rd_bd
*)
478 qed_chain_produce(&txq
->tx_pbl
);
479 memset(third_bd
, 0, sizeof(*third_bd
));
482 /* We need to fill in additional data in second_bd... */
483 tx_data_bd
= (struct eth_tx_bd
*)second_bd
;
486 if (skb_vlan_tag_present(skb
)) {
487 first_bd
->data
.vlan
= cpu_to_le16(skb_vlan_tag_get(skb
));
488 first_bd
->data
.bd_flags
.bitfields
|=
489 1 << ETH_TX_1ST_BD_FLAGS_VLAN_INSERTION_SHIFT
;
492 /* Fill the parsing flags & params according to the requested offload */
493 if (xmit_type
& XMIT_L4_CSUM
) {
494 u16 temp
= 1 << ETH_TX_DATA_1ST_BD_TUNN_CFG_OVERRIDE_SHIFT
;
496 /* We don't re-calculate IP checksum as it is already done by
499 first_bd
->data
.bd_flags
.bitfields
|=
500 1 << ETH_TX_1ST_BD_FLAGS_L4_CSUM_SHIFT
;
502 first_bd
->data
.bitfields
|= cpu_to_le16(temp
);
504 /* If the packet is IPv6 with extension header, indicate that
505 * to FW and pass few params, since the device cracker doesn't
506 * support parsing IPv6 with extension header/s.
508 if (unlikely(ipv6_ext
))
509 qede_set_params_for_ipv6_ext(skb
, second_bd
, third_bd
);
512 if (xmit_type
& XMIT_LSO
) {
513 first_bd
->data
.bd_flags
.bitfields
|=
514 (1 << ETH_TX_1ST_BD_FLAGS_LSO_SHIFT
);
515 third_bd
->data
.lso_mss
=
516 cpu_to_le16(skb_shinfo(skb
)->gso_size
);
518 first_bd
->data
.bd_flags
.bitfields
|=
519 1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT
;
520 hlen
= skb_transport_header(skb
) +
521 tcp_hdrlen(skb
) - skb
->data
;
523 /* @@@TBD - if will not be removed need to check */
524 third_bd
->data
.bitfields
|=
525 cpu_to_le16((1 << ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT
));
527 /* Make life easier for FW guys who can't deal with header and
528 * data on same BD. If we need to split, use the second bd...
530 if (unlikely(skb_headlen(skb
) > hlen
)) {
531 DP_VERBOSE(edev
, NETIF_MSG_TX_QUEUED
,
532 "TSO split header size is %d (%x:%x)\n",
533 first_bd
->nbytes
, first_bd
->addr
.hi
,
536 mapping
= HILO_U64(le32_to_cpu(first_bd
->addr
.hi
),
537 le32_to_cpu(first_bd
->addr
.lo
)) +
540 BD_SET_UNMAP_ADDR_LEN(tx_data_bd
, mapping
,
541 le16_to_cpu(first_bd
->nbytes
) -
544 /* this marks the BD as one that has no
547 txq
->sw_tx_ring
[idx
].flags
|= QEDE_TSO_SPLIT_BD
;
549 first_bd
->nbytes
= cpu_to_le16(hlen
);
551 tx_data_bd
= (struct eth_tx_bd
*)third_bd
;
556 /* Handle fragmented skb */
557 /* special handle for frags inside 2nd and 3rd bds.. */
558 while (tx_data_bd
&& frag_idx
< skb_shinfo(skb
)->nr_frags
) {
559 rc
= map_frag_to_bd(edev
,
560 &skb_shinfo(skb
)->frags
[frag_idx
],
563 qede_free_failed_tx_pkt(edev
, txq
, first_bd
, nbd
,
568 if (tx_data_bd
== (struct eth_tx_bd
*)second_bd
)
569 tx_data_bd
= (struct eth_tx_bd
*)third_bd
;
576 /* map last frags into 4th, 5th .... */
577 for (; frag_idx
< skb_shinfo(skb
)->nr_frags
; frag_idx
++, nbd
++) {
578 tx_data_bd
= (struct eth_tx_bd
*)
579 qed_chain_produce(&txq
->tx_pbl
);
581 memset(tx_data_bd
, 0, sizeof(*tx_data_bd
));
583 rc
= map_frag_to_bd(edev
,
584 &skb_shinfo(skb
)->frags
[frag_idx
],
587 qede_free_failed_tx_pkt(edev
, txq
, first_bd
, nbd
,
593 /* update the first BD with the actual num BDs */
594 first_bd
->data
.nbds
= nbd
;
596 netdev_tx_sent_queue(netdev_txq
, skb
->len
);
598 skb_tx_timestamp(skb
);
600 /* Advance packet producer only before sending the packet since mapping
605 /* 'next page' entries are counted in the producer value */
606 txq
->tx_db
.data
.bd_prod
=
607 cpu_to_le16(qed_chain_get_prod_idx(&txq
->tx_pbl
));
609 /* wmb makes sure that the BDs data is updated before updating the
610 * producer, otherwise FW may read old data from the BDs.
614 writel(txq
->tx_db
.raw
, txq
->doorbell_addr
);
616 /* mmiowb is needed to synchronize doorbell writes from more than one
617 * processor. It guarantees that the write arrives to the device before
618 * the queue lock is released and another start_xmit is called (possibly
619 * on another CPU). Without this barrier, the next doorbell can bypass
620 * this doorbell. This is applicable to IA64/Altix systems.
624 if (unlikely(qed_chain_get_elem_left(&txq
->tx_pbl
)
625 < (MAX_SKB_FRAGS
+ 1))) {
626 netif_tx_stop_queue(netdev_txq
);
627 DP_VERBOSE(edev
, NETIF_MSG_TX_QUEUED
,
628 "Stop queue was called\n");
629 /* paired memory barrier is in qede_tx_int(), we have to keep
630 * ordering of set_bit() in netif_tx_stop_queue() and read of
635 if (qed_chain_get_elem_left(&txq
->tx_pbl
)
636 >= (MAX_SKB_FRAGS
+ 1) &&
637 (edev
->state
== QEDE_STATE_OPEN
)) {
638 netif_tx_wake_queue(netdev_txq
);
639 DP_VERBOSE(edev
, NETIF_MSG_TX_QUEUED
,
640 "Wake queue was called\n");
647 static int qede_txq_has_work(struct qede_tx_queue
*txq
)
651 /* Tell compiler that consumer and producer can change */
653 hw_bd_cons
= le16_to_cpu(*txq
->hw_cons_ptr
);
654 if (qed_chain_get_cons_idx(&txq
->tx_pbl
) == hw_bd_cons
+ 1)
657 return hw_bd_cons
!= qed_chain_get_cons_idx(&txq
->tx_pbl
);
660 static int qede_tx_int(struct qede_dev
*edev
,
661 struct qede_tx_queue
*txq
)
663 struct netdev_queue
*netdev_txq
;
665 unsigned int pkts_compl
= 0, bytes_compl
= 0;
668 netdev_txq
= netdev_get_tx_queue(edev
->ndev
, txq
->index
);
670 hw_bd_cons
= le16_to_cpu(*txq
->hw_cons_ptr
);
673 while (hw_bd_cons
!= qed_chain_get_cons_idx(&txq
->tx_pbl
)) {
676 rc
= qede_free_tx_pkt(edev
, txq
, &len
);
678 DP_NOTICE(edev
, "hw_bd_cons = %d, chain_cons=%d\n",
680 qed_chain_get_cons_idx(&txq
->tx_pbl
));
689 netdev_tx_completed_queue(netdev_txq
, pkts_compl
, bytes_compl
);
691 /* Need to make the tx_bd_cons update visible to start_xmit()
692 * before checking for netif_tx_queue_stopped(). Without the
693 * memory barrier, there is a small possibility that
694 * start_xmit() will miss it and cause the queue to be stopped
696 * On the other hand we need an rmb() here to ensure the proper
697 * ordering of bit testing in the following
698 * netif_tx_queue_stopped(txq) call.
702 if (unlikely(netif_tx_queue_stopped(netdev_txq
))) {
703 /* Taking tx_lock is needed to prevent reenabling the queue
704 * while it's empty. This could have happen if rx_action() gets
705 * suspended in qede_tx_int() after the condition before
706 * netif_tx_wake_queue(), while tx_action (qede_start_xmit()):
708 * stops the queue->sees fresh tx_bd_cons->releases the queue->
709 * sends some packets consuming the whole queue again->
713 __netif_tx_lock(netdev_txq
, smp_processor_id());
715 if ((netif_tx_queue_stopped(netdev_txq
)) &&
716 (edev
->state
== QEDE_STATE_OPEN
) &&
717 (qed_chain_get_elem_left(&txq
->tx_pbl
)
718 >= (MAX_SKB_FRAGS
+ 1))) {
719 netif_tx_wake_queue(netdev_txq
);
720 DP_VERBOSE(edev
, NETIF_MSG_TX_DONE
,
721 "Wake queue was called\n");
724 __netif_tx_unlock(netdev_txq
);
730 static bool qede_has_rx_work(struct qede_rx_queue
*rxq
)
732 u16 hw_comp_cons
, sw_comp_cons
;
734 /* Tell compiler that status block fields can change */
737 hw_comp_cons
= le16_to_cpu(*rxq
->hw_cons_ptr
);
738 sw_comp_cons
= qed_chain_get_cons_idx(&rxq
->rx_comp_ring
);
740 return hw_comp_cons
!= sw_comp_cons
;
743 static bool qede_has_tx_work(struct qede_fastpath
*fp
)
747 for (tc
= 0; tc
< fp
->edev
->num_tc
; tc
++)
748 if (qede_txq_has_work(&fp
->txqs
[tc
]))
753 /* This function reuses the buffer(from an offset) from
754 * consumer index to producer index in the bd ring
756 static inline void qede_reuse_page(struct qede_dev
*edev
,
757 struct qede_rx_queue
*rxq
,
758 struct sw_rx_data
*curr_cons
)
760 struct eth_rx_bd
*rx_bd_prod
= qed_chain_produce(&rxq
->rx_bd_ring
);
761 struct sw_rx_data
*curr_prod
;
762 dma_addr_t new_mapping
;
764 curr_prod
= &rxq
->sw_rx_ring
[rxq
->sw_rx_prod
& NUM_RX_BDS_MAX
];
765 *curr_prod
= *curr_cons
;
767 new_mapping
= curr_prod
->mapping
+ curr_prod
->page_offset
;
769 rx_bd_prod
->addr
.hi
= cpu_to_le32(upper_32_bits(new_mapping
));
770 rx_bd_prod
->addr
.lo
= cpu_to_le32(lower_32_bits(new_mapping
));
773 curr_cons
->data
= NULL
;
776 static inline int qede_realloc_rx_buffer(struct qede_dev
*edev
,
777 struct qede_rx_queue
*rxq
,
778 struct sw_rx_data
*curr_cons
)
780 /* Move to the next segment in the page */
781 curr_cons
->page_offset
+= rxq
->rx_buf_seg_size
;
783 if (curr_cons
->page_offset
== PAGE_SIZE
) {
784 if (unlikely(qede_alloc_rx_buffer(edev
, rxq
)))
787 dma_unmap_page(&edev
->pdev
->dev
, curr_cons
->mapping
,
788 PAGE_SIZE
, DMA_FROM_DEVICE
);
790 /* Increment refcount of the page as we don't want
791 * network stack to take the ownership of the page
792 * which can be recycled multiple times by the driver.
794 atomic_inc(&curr_cons
->data
->_count
);
795 qede_reuse_page(edev
, rxq
, curr_cons
);
801 static inline void qede_update_rx_prod(struct qede_dev
*edev
,
802 struct qede_rx_queue
*rxq
)
804 u16 bd_prod
= qed_chain_get_prod_idx(&rxq
->rx_bd_ring
);
805 u16 cqe_prod
= qed_chain_get_prod_idx(&rxq
->rx_comp_ring
);
806 struct eth_rx_prod_data rx_prods
= {0};
808 /* Update producers */
809 rx_prods
.bd_prod
= cpu_to_le16(bd_prod
);
810 rx_prods
.cqe_prod
= cpu_to_le16(cqe_prod
);
812 /* Make sure that the BD and SGE data is updated before updating the
813 * producers since FW might read the BD/SGE right after the producer
818 internal_ram_wr(rxq
->hw_rxq_prod_addr
, sizeof(rx_prods
),
821 /* mmiowb is needed to synchronize doorbell writes from more than one
822 * processor. It guarantees that the write arrives to the device before
823 * the napi lock is released and another qede_poll is called (possibly
824 * on another CPU). Without this barrier, the next doorbell can bypass
825 * this doorbell. This is applicable to IA64/Altix systems.
830 static u32
qede_get_rxhash(struct qede_dev
*edev
,
833 enum pkt_hash_types
*rxhash_type
)
835 enum rss_hash_type htype
;
837 htype
= GET_FIELD(bitfields
, ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE
);
839 if ((edev
->ndev
->features
& NETIF_F_RXHASH
) && htype
) {
840 *rxhash_type
= ((htype
== RSS_HASH_TYPE_IPV4
) ||
841 (htype
== RSS_HASH_TYPE_IPV6
)) ?
842 PKT_HASH_TYPE_L3
: PKT_HASH_TYPE_L4
;
843 return le32_to_cpu(rss_hash
);
845 *rxhash_type
= PKT_HASH_TYPE_NONE
;
849 static void qede_set_skb_csum(struct sk_buff
*skb
, u8 csum_flag
)
851 skb_checksum_none_assert(skb
);
853 if (csum_flag
& QEDE_CSUM_UNNECESSARY
)
854 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
857 static inline void qede_skb_receive(struct qede_dev
*edev
,
858 struct qede_fastpath
*fp
,
863 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
),
866 napi_gro_receive(&fp
->napi
, skb
);
869 static u8
qede_check_csum(u16 flag
)
874 if ((PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK
<<
875 PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT
) & flag
) {
876 csum_flag
|= PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK
<<
877 PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT
;
878 csum
= QEDE_CSUM_UNNECESSARY
;
881 csum_flag
|= PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK
<<
882 PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT
;
884 if (csum_flag
& flag
)
885 return QEDE_CSUM_ERROR
;
890 static int qede_rx_int(struct qede_fastpath
*fp
, int budget
)
892 struct qede_dev
*edev
= fp
->edev
;
893 struct qede_rx_queue
*rxq
= fp
->rxq
;
895 u16 hw_comp_cons
, sw_comp_cons
, sw_rx_index
, parse_flag
;
899 hw_comp_cons
= le16_to_cpu(*rxq
->hw_cons_ptr
);
900 sw_comp_cons
= qed_chain_get_cons_idx(&rxq
->rx_comp_ring
);
902 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
903 * / BD in the while-loop before reading hw_comp_cons. If the CQE is
904 * read before it is written by FW, then FW writes CQE and SB, and then
905 * the CPU reads the hw_comp_cons, it will use an old CQE.
909 /* Loop to complete all indicated BDs */
910 while (sw_comp_cons
!= hw_comp_cons
) {
911 struct eth_fast_path_rx_reg_cqe
*fp_cqe
;
912 enum pkt_hash_types rxhash_type
;
913 enum eth_rx_cqe_type cqe_type
;
914 struct sw_rx_data
*sw_rx_data
;
915 union eth_rx_cqe
*cqe
;
922 /* Get the CQE from the completion ring */
923 cqe
= (union eth_rx_cqe
*)
924 qed_chain_consume(&rxq
->rx_comp_ring
);
925 cqe_type
= cqe
->fast_path_regular
.type
;
927 if (unlikely(cqe_type
== ETH_RX_CQE_TYPE_SLOW_PATH
)) {
928 edev
->ops
->eth_cqe_completion(
929 edev
->cdev
, fp
->rss_id
,
930 (struct eth_slow_path_rx_cqe
*)cqe
);
934 /* Get the data from the SW ring */
935 sw_rx_index
= rxq
->sw_rx_cons
& NUM_RX_BDS_MAX
;
936 sw_rx_data
= &rxq
->sw_rx_ring
[sw_rx_index
];
937 data
= sw_rx_data
->data
;
939 fp_cqe
= &cqe
->fast_path_regular
;
940 len
= le16_to_cpu(fp_cqe
->len_on_first_bd
);
941 pad
= fp_cqe
->placement_offset
;
942 flags
= cqe
->fast_path_regular
.pars_flags
.flags
;
944 /* If this is an error packet then drop it */
945 parse_flag
= le16_to_cpu(flags
);
947 csum_flag
= qede_check_csum(parse_flag
);
948 if (unlikely(csum_flag
== QEDE_CSUM_ERROR
)) {
950 "CQE in CONS = %u has error, flags = %x, dropping incoming packet\n",
951 sw_comp_cons
, parse_flag
);
953 qede_reuse_page(edev
, rxq
, sw_rx_data
);
957 skb
= netdev_alloc_skb(edev
->ndev
, QEDE_RX_HDR_SIZE
);
958 if (unlikely(!skb
)) {
960 "Build_skb failed, dropping incoming packet\n");
961 qede_reuse_page(edev
, rxq
, sw_rx_data
);
962 rxq
->rx_alloc_errors
++;
966 /* Copy data into SKB */
967 if (len
+ pad
<= QEDE_RX_HDR_SIZE
) {
968 memcpy(skb_put(skb
, len
),
969 page_address(data
) + pad
+
970 sw_rx_data
->page_offset
, len
);
971 qede_reuse_page(edev
, rxq
, sw_rx_data
);
973 struct skb_frag_struct
*frag
;
974 unsigned int pull_len
;
977 frag
= &skb_shinfo(skb
)->frags
[0];
979 skb_add_rx_frag(skb
, skb_shinfo(skb
)->nr_frags
, data
,
980 pad
+ sw_rx_data
->page_offset
,
981 len
, rxq
->rx_buf_seg_size
);
983 va
= skb_frag_address(frag
);
984 pull_len
= eth_get_headlen(va
, QEDE_RX_HDR_SIZE
);
986 /* Align the pull_len to optimize memcpy */
987 memcpy(skb
->data
, va
, ALIGN(pull_len
, sizeof(long)));
989 skb_frag_size_sub(frag
, pull_len
);
990 frag
->page_offset
+= pull_len
;
991 skb
->data_len
-= pull_len
;
992 skb
->tail
+= pull_len
;
994 if (unlikely(qede_realloc_rx_buffer(edev
, rxq
,
996 DP_ERR(edev
, "Failed to allocate rx buffer\n");
997 rxq
->rx_alloc_errors
++;
1002 if (fp_cqe
->bd_num
!= 1) {
1003 u16 pkt_len
= le16_to_cpu(fp_cqe
->pkt_len
);
1008 for (num_frags
= fp_cqe
->bd_num
- 1; num_frags
> 0;
1010 u16 cur_size
= pkt_len
> rxq
->rx_buf_size
?
1011 rxq
->rx_buf_size
: pkt_len
;
1013 WARN_ONCE(!cur_size
,
1014 "Still got %d BDs for mapping jumbo, but length became 0\n",
1017 if (unlikely(qede_alloc_rx_buffer(edev
, rxq
)))
1021 sw_rx_index
= rxq
->sw_rx_cons
& NUM_RX_BDS_MAX
;
1022 sw_rx_data
= &rxq
->sw_rx_ring
[sw_rx_index
];
1023 qed_chain_consume(&rxq
->rx_bd_ring
);
1024 dma_unmap_page(&edev
->pdev
->dev
,
1025 sw_rx_data
->mapping
,
1026 PAGE_SIZE
, DMA_FROM_DEVICE
);
1028 skb_fill_page_desc(skb
,
1029 skb_shinfo(skb
)->nr_frags
++,
1030 sw_rx_data
->data
, 0,
1033 skb
->truesize
+= PAGE_SIZE
;
1034 skb
->data_len
+= cur_size
;
1035 skb
->len
+= cur_size
;
1036 pkt_len
-= cur_size
;
1041 "Mapped all BDs of jumbo, but still have %d bytes\n",
1045 skb
->protocol
= eth_type_trans(skb
, edev
->ndev
);
1047 rx_hash
= qede_get_rxhash(edev
, fp_cqe
->bitfields
,
1051 skb_set_hash(skb
, rx_hash
, rxhash_type
);
1053 qede_set_skb_csum(skb
, csum_flag
);
1055 skb_record_rx_queue(skb
, fp
->rss_id
);
1057 qede_skb_receive(edev
, fp
, skb
, le16_to_cpu(fp_cqe
->vlan_tag
));
1059 qed_chain_consume(&rxq
->rx_bd_ring
);
1065 next_cqe
: /* don't consume bd rx buffer */
1066 qed_chain_recycle_consumed(&rxq
->rx_comp_ring
);
1067 sw_comp_cons
= qed_chain_get_cons_idx(&rxq
->rx_comp_ring
);
1068 /* CR TPA - revisit how to handle budget in TPA perhaps
1071 if (rx_pkt
== budget
)
1073 } /* repeat while sw_comp_cons != hw_comp_cons... */
1075 /* Update producers */
1076 qede_update_rx_prod(edev
, rxq
);
1081 static int qede_poll(struct napi_struct
*napi
, int budget
)
1084 struct qede_fastpath
*fp
= container_of(napi
, struct qede_fastpath
,
1086 struct qede_dev
*edev
= fp
->edev
;
1091 for (tc
= 0; tc
< edev
->num_tc
; tc
++)
1092 if (qede_txq_has_work(&fp
->txqs
[tc
]))
1093 qede_tx_int(edev
, &fp
->txqs
[tc
]);
1095 if (qede_has_rx_work(fp
->rxq
)) {
1096 work_done
+= qede_rx_int(fp
, budget
- work_done
);
1098 /* must not complete if we consumed full budget */
1099 if (work_done
>= budget
)
1103 /* Fall out from the NAPI loop if needed */
1104 if (!(qede_has_rx_work(fp
->rxq
) || qede_has_tx_work(fp
))) {
1105 qed_sb_update_sb_idx(fp
->sb_info
);
1106 /* *_has_*_work() reads the status block,
1107 * thus we need to ensure that status block indices
1108 * have been actually read (qed_sb_update_sb_idx)
1109 * prior to this check (*_has_*_work) so that
1110 * we won't write the "newer" value of the status block
1111 * to HW (if there was a DMA right after
1112 * qede_has_rx_work and if there is no rmb, the memory
1113 * reading (qed_sb_update_sb_idx) may be postponed
1114 * to right before *_ack_sb). In this case there
1115 * will never be another interrupt until there is
1116 * another update of the status block, while there
1117 * is still unhandled work.
1121 if (!(qede_has_rx_work(fp
->rxq
) ||
1122 qede_has_tx_work(fp
))) {
1123 napi_complete(napi
);
1124 /* Update and reenable interrupts */
1125 qed_sb_ack(fp
->sb_info
, IGU_INT_ENABLE
,
1135 static irqreturn_t
qede_msix_fp_int(int irq
, void *fp_cookie
)
1137 struct qede_fastpath
*fp
= fp_cookie
;
1139 qed_sb_ack(fp
->sb_info
, IGU_INT_DISABLE
, 0 /*do not update*/);
1141 napi_schedule_irqoff(&fp
->napi
);
1145 /* -------------------------------------------------------------------------
1147 * -------------------------------------------------------------------------
1150 static int qede_open(struct net_device
*ndev
);
1151 static int qede_close(struct net_device
*ndev
);
1152 static int qede_set_mac_addr(struct net_device
*ndev
, void *p
);
1153 static void qede_set_rx_mode(struct net_device
*ndev
);
1154 static void qede_config_rx_mode(struct net_device
*ndev
);
1156 static int qede_set_ucast_rx_mac(struct qede_dev
*edev
,
1157 enum qed_filter_xcast_params_type opcode
,
1158 unsigned char mac
[ETH_ALEN
])
1160 struct qed_filter_params filter_cmd
;
1162 memset(&filter_cmd
, 0, sizeof(filter_cmd
));
1163 filter_cmd
.type
= QED_FILTER_TYPE_UCAST
;
1164 filter_cmd
.filter
.ucast
.type
= opcode
;
1165 filter_cmd
.filter
.ucast
.mac_valid
= 1;
1166 ether_addr_copy(filter_cmd
.filter
.ucast
.mac
, mac
);
1168 return edev
->ops
->filter_config(edev
->cdev
, &filter_cmd
);
1171 static int qede_set_ucast_rx_vlan(struct qede_dev
*edev
,
1172 enum qed_filter_xcast_params_type opcode
,
1175 struct qed_filter_params filter_cmd
;
1177 memset(&filter_cmd
, 0, sizeof(filter_cmd
));
1178 filter_cmd
.type
= QED_FILTER_TYPE_UCAST
;
1179 filter_cmd
.filter
.ucast
.type
= opcode
;
1180 filter_cmd
.filter
.ucast
.vlan_valid
= 1;
1181 filter_cmd
.filter
.ucast
.vlan
= vid
;
1183 return edev
->ops
->filter_config(edev
->cdev
, &filter_cmd
);
1186 void qede_fill_by_demand_stats(struct qede_dev
*edev
)
1188 struct qed_eth_stats stats
;
1190 edev
->ops
->get_vport_stats(edev
->cdev
, &stats
);
1191 edev
->stats
.no_buff_discards
= stats
.no_buff_discards
;
1192 edev
->stats
.rx_ucast_bytes
= stats
.rx_ucast_bytes
;
1193 edev
->stats
.rx_mcast_bytes
= stats
.rx_mcast_bytes
;
1194 edev
->stats
.rx_bcast_bytes
= stats
.rx_bcast_bytes
;
1195 edev
->stats
.rx_ucast_pkts
= stats
.rx_ucast_pkts
;
1196 edev
->stats
.rx_mcast_pkts
= stats
.rx_mcast_pkts
;
1197 edev
->stats
.rx_bcast_pkts
= stats
.rx_bcast_pkts
;
1198 edev
->stats
.mftag_filter_discards
= stats
.mftag_filter_discards
;
1199 edev
->stats
.mac_filter_discards
= stats
.mac_filter_discards
;
1201 edev
->stats
.tx_ucast_bytes
= stats
.tx_ucast_bytes
;
1202 edev
->stats
.tx_mcast_bytes
= stats
.tx_mcast_bytes
;
1203 edev
->stats
.tx_bcast_bytes
= stats
.tx_bcast_bytes
;
1204 edev
->stats
.tx_ucast_pkts
= stats
.tx_ucast_pkts
;
1205 edev
->stats
.tx_mcast_pkts
= stats
.tx_mcast_pkts
;
1206 edev
->stats
.tx_bcast_pkts
= stats
.tx_bcast_pkts
;
1207 edev
->stats
.tx_err_drop_pkts
= stats
.tx_err_drop_pkts
;
1208 edev
->stats
.coalesced_pkts
= stats
.tpa_coalesced_pkts
;
1209 edev
->stats
.coalesced_events
= stats
.tpa_coalesced_events
;
1210 edev
->stats
.coalesced_aborts_num
= stats
.tpa_aborts_num
;
1211 edev
->stats
.non_coalesced_pkts
= stats
.tpa_not_coalesced_pkts
;
1212 edev
->stats
.coalesced_bytes
= stats
.tpa_coalesced_bytes
;
1214 edev
->stats
.rx_64_byte_packets
= stats
.rx_64_byte_packets
;
1215 edev
->stats
.rx_127_byte_packets
= stats
.rx_127_byte_packets
;
1216 edev
->stats
.rx_255_byte_packets
= stats
.rx_255_byte_packets
;
1217 edev
->stats
.rx_511_byte_packets
= stats
.rx_511_byte_packets
;
1218 edev
->stats
.rx_1023_byte_packets
= stats
.rx_1023_byte_packets
;
1219 edev
->stats
.rx_1518_byte_packets
= stats
.rx_1518_byte_packets
;
1220 edev
->stats
.rx_1522_byte_packets
= stats
.rx_1522_byte_packets
;
1221 edev
->stats
.rx_2047_byte_packets
= stats
.rx_2047_byte_packets
;
1222 edev
->stats
.rx_4095_byte_packets
= stats
.rx_4095_byte_packets
;
1223 edev
->stats
.rx_9216_byte_packets
= stats
.rx_9216_byte_packets
;
1224 edev
->stats
.rx_16383_byte_packets
= stats
.rx_16383_byte_packets
;
1225 edev
->stats
.rx_crc_errors
= stats
.rx_crc_errors
;
1226 edev
->stats
.rx_mac_crtl_frames
= stats
.rx_mac_crtl_frames
;
1227 edev
->stats
.rx_pause_frames
= stats
.rx_pause_frames
;
1228 edev
->stats
.rx_pfc_frames
= stats
.rx_pfc_frames
;
1229 edev
->stats
.rx_align_errors
= stats
.rx_align_errors
;
1230 edev
->stats
.rx_carrier_errors
= stats
.rx_carrier_errors
;
1231 edev
->stats
.rx_oversize_packets
= stats
.rx_oversize_packets
;
1232 edev
->stats
.rx_jabbers
= stats
.rx_jabbers
;
1233 edev
->stats
.rx_undersize_packets
= stats
.rx_undersize_packets
;
1234 edev
->stats
.rx_fragments
= stats
.rx_fragments
;
1235 edev
->stats
.tx_64_byte_packets
= stats
.tx_64_byte_packets
;
1236 edev
->stats
.tx_65_to_127_byte_packets
= stats
.tx_65_to_127_byte_packets
;
1237 edev
->stats
.tx_128_to_255_byte_packets
=
1238 stats
.tx_128_to_255_byte_packets
;
1239 edev
->stats
.tx_256_to_511_byte_packets
=
1240 stats
.tx_256_to_511_byte_packets
;
1241 edev
->stats
.tx_512_to_1023_byte_packets
=
1242 stats
.tx_512_to_1023_byte_packets
;
1243 edev
->stats
.tx_1024_to_1518_byte_packets
=
1244 stats
.tx_1024_to_1518_byte_packets
;
1245 edev
->stats
.tx_1519_to_2047_byte_packets
=
1246 stats
.tx_1519_to_2047_byte_packets
;
1247 edev
->stats
.tx_2048_to_4095_byte_packets
=
1248 stats
.tx_2048_to_4095_byte_packets
;
1249 edev
->stats
.tx_4096_to_9216_byte_packets
=
1250 stats
.tx_4096_to_9216_byte_packets
;
1251 edev
->stats
.tx_9217_to_16383_byte_packets
=
1252 stats
.tx_9217_to_16383_byte_packets
;
1253 edev
->stats
.tx_pause_frames
= stats
.tx_pause_frames
;
1254 edev
->stats
.tx_pfc_frames
= stats
.tx_pfc_frames
;
1255 edev
->stats
.tx_lpi_entry_count
= stats
.tx_lpi_entry_count
;
1256 edev
->stats
.tx_total_collisions
= stats
.tx_total_collisions
;
1257 edev
->stats
.brb_truncates
= stats
.brb_truncates
;
1258 edev
->stats
.brb_discards
= stats
.brb_discards
;
1259 edev
->stats
.tx_mac_ctrl_frames
= stats
.tx_mac_ctrl_frames
;
1262 static struct rtnl_link_stats64
*qede_get_stats64(
1263 struct net_device
*dev
,
1264 struct rtnl_link_stats64
*stats
)
1266 struct qede_dev
*edev
= netdev_priv(dev
);
1268 qede_fill_by_demand_stats(edev
);
1270 stats
->rx_packets
= edev
->stats
.rx_ucast_pkts
+
1271 edev
->stats
.rx_mcast_pkts
+
1272 edev
->stats
.rx_bcast_pkts
;
1273 stats
->tx_packets
= edev
->stats
.tx_ucast_pkts
+
1274 edev
->stats
.tx_mcast_pkts
+
1275 edev
->stats
.tx_bcast_pkts
;
1277 stats
->rx_bytes
= edev
->stats
.rx_ucast_bytes
+
1278 edev
->stats
.rx_mcast_bytes
+
1279 edev
->stats
.rx_bcast_bytes
;
1281 stats
->tx_bytes
= edev
->stats
.tx_ucast_bytes
+
1282 edev
->stats
.tx_mcast_bytes
+
1283 edev
->stats
.tx_bcast_bytes
;
1285 stats
->tx_errors
= edev
->stats
.tx_err_drop_pkts
;
1286 stats
->multicast
= edev
->stats
.rx_mcast_pkts
+
1287 edev
->stats
.rx_bcast_pkts
;
1289 stats
->rx_fifo_errors
= edev
->stats
.no_buff_discards
;
1291 stats
->collisions
= edev
->stats
.tx_total_collisions
;
1292 stats
->rx_crc_errors
= edev
->stats
.rx_crc_errors
;
1293 stats
->rx_frame_errors
= edev
->stats
.rx_align_errors
;
1298 static void qede_config_accept_any_vlan(struct qede_dev
*edev
, bool action
)
1300 struct qed_update_vport_params params
;
1303 /* Proceed only if action actually needs to be performed */
1304 if (edev
->accept_any_vlan
== action
)
1307 memset(¶ms
, 0, sizeof(params
));
1309 params
.vport_id
= 0;
1310 params
.accept_any_vlan
= action
;
1311 params
.update_accept_any_vlan_flg
= 1;
1313 rc
= edev
->ops
->vport_update(edev
->cdev
, ¶ms
);
1315 DP_ERR(edev
, "Failed to %s accept-any-vlan\n",
1316 action
? "enable" : "disable");
1318 DP_INFO(edev
, "%s accept-any-vlan\n",
1319 action
? "enabled" : "disabled");
1320 edev
->accept_any_vlan
= action
;
1324 static int qede_vlan_rx_add_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
1326 struct qede_dev
*edev
= netdev_priv(dev
);
1327 struct qede_vlan
*vlan
, *tmp
;
1330 DP_VERBOSE(edev
, NETIF_MSG_IFUP
, "Adding vlan 0x%04x\n", vid
);
1332 vlan
= kzalloc(sizeof(*vlan
), GFP_KERNEL
);
1334 DP_INFO(edev
, "Failed to allocate struct for vlan\n");
1337 INIT_LIST_HEAD(&vlan
->list
);
1339 vlan
->configured
= false;
1341 /* Verify vlan isn't already configured */
1342 list_for_each_entry(tmp
, &edev
->vlan_list
, list
) {
1343 if (tmp
->vid
== vlan
->vid
) {
1344 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
1345 "vlan already configured\n");
1351 /* If interface is down, cache this VLAN ID and return */
1352 if (edev
->state
!= QEDE_STATE_OPEN
) {
1353 DP_VERBOSE(edev
, NETIF_MSG_IFDOWN
,
1354 "Interface is down, VLAN %d will be configured when interface is up\n",
1357 edev
->non_configured_vlans
++;
1358 list_add(&vlan
->list
, &edev
->vlan_list
);
1363 /* Check for the filter limit.
1364 * Note - vlan0 has a reserved filter and can be added without
1365 * worrying about quota
1367 if ((edev
->configured_vlans
< edev
->dev_info
.num_vlan_filters
) ||
1369 rc
= qede_set_ucast_rx_vlan(edev
,
1370 QED_FILTER_XCAST_TYPE_ADD
,
1373 DP_ERR(edev
, "Failed to configure VLAN %d\n",
1378 vlan
->configured
= true;
1380 /* vlan0 filter isn't consuming out of our quota */
1382 edev
->configured_vlans
++;
1384 /* Out of quota; Activate accept-any-VLAN mode */
1385 if (!edev
->non_configured_vlans
)
1386 qede_config_accept_any_vlan(edev
, true);
1388 edev
->non_configured_vlans
++;
1391 list_add(&vlan
->list
, &edev
->vlan_list
);
1396 static void qede_del_vlan_from_list(struct qede_dev
*edev
,
1397 struct qede_vlan
*vlan
)
1399 /* vlan0 filter isn't consuming out of our quota */
1400 if (vlan
->vid
!= 0) {
1401 if (vlan
->configured
)
1402 edev
->configured_vlans
--;
1404 edev
->non_configured_vlans
--;
1407 list_del(&vlan
->list
);
1411 static int qede_configure_vlan_filters(struct qede_dev
*edev
)
1413 int rc
= 0, real_rc
= 0, accept_any_vlan
= 0;
1414 struct qed_dev_eth_info
*dev_info
;
1415 struct qede_vlan
*vlan
= NULL
;
1417 if (list_empty(&edev
->vlan_list
))
1420 dev_info
= &edev
->dev_info
;
1422 /* Configure non-configured vlans */
1423 list_for_each_entry(vlan
, &edev
->vlan_list
, list
) {
1424 if (vlan
->configured
)
1427 /* We have used all our credits, now enable accept_any_vlan */
1428 if ((vlan
->vid
!= 0) &&
1429 (edev
->configured_vlans
== dev_info
->num_vlan_filters
)) {
1430 accept_any_vlan
= 1;
1434 DP_VERBOSE(edev
, NETIF_MSG_IFUP
, "Adding vlan %d\n", vlan
->vid
);
1436 rc
= qede_set_ucast_rx_vlan(edev
, QED_FILTER_XCAST_TYPE_ADD
,
1439 DP_ERR(edev
, "Failed to configure VLAN %u\n",
1445 vlan
->configured
= true;
1446 /* vlan0 filter doesn't consume our VLAN filter's quota */
1447 if (vlan
->vid
!= 0) {
1448 edev
->non_configured_vlans
--;
1449 edev
->configured_vlans
++;
1453 /* enable accept_any_vlan mode if we have more VLANs than credits,
1454 * or remove accept_any_vlan mode if we've actually removed
1455 * a non-configured vlan, and all remaining vlans are truly configured.
1458 if (accept_any_vlan
)
1459 qede_config_accept_any_vlan(edev
, true);
1460 else if (!edev
->non_configured_vlans
)
1461 qede_config_accept_any_vlan(edev
, false);
1466 static int qede_vlan_rx_kill_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
1468 struct qede_dev
*edev
= netdev_priv(dev
);
1469 struct qede_vlan
*vlan
= NULL
;
1472 DP_VERBOSE(edev
, NETIF_MSG_IFDOWN
, "Removing vlan 0x%04x\n", vid
);
1474 /* Find whether entry exists */
1475 list_for_each_entry(vlan
, &edev
->vlan_list
, list
)
1476 if (vlan
->vid
== vid
)
1479 if (!vlan
|| (vlan
->vid
!= vid
)) {
1480 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
1481 "Vlan isn't configured\n");
1485 if (edev
->state
!= QEDE_STATE_OPEN
) {
1486 /* As interface is already down, we don't have a VPORT
1487 * instance to remove vlan filter. So just update vlan list
1489 DP_VERBOSE(edev
, NETIF_MSG_IFDOWN
,
1490 "Interface is down, removing VLAN from list only\n");
1491 qede_del_vlan_from_list(edev
, vlan
);
1496 rc
= qede_set_ucast_rx_vlan(edev
, QED_FILTER_XCAST_TYPE_DEL
, vid
);
1498 DP_ERR(edev
, "Failed to remove VLAN %d\n", vid
);
1502 qede_del_vlan_from_list(edev
, vlan
);
1504 /* We have removed a VLAN - try to see if we can
1505 * configure non-configured VLAN from the list.
1507 rc
= qede_configure_vlan_filters(edev
);
1512 static void qede_vlan_mark_nonconfigured(struct qede_dev
*edev
)
1514 struct qede_vlan
*vlan
= NULL
;
1516 if (list_empty(&edev
->vlan_list
))
1519 list_for_each_entry(vlan
, &edev
->vlan_list
, list
) {
1520 if (!vlan
->configured
)
1523 vlan
->configured
= false;
1525 /* vlan0 filter isn't consuming out of our quota */
1526 if (vlan
->vid
!= 0) {
1527 edev
->non_configured_vlans
++;
1528 edev
->configured_vlans
--;
1531 DP_VERBOSE(edev
, NETIF_MSG_IFDOWN
,
1532 "marked vlan %d as non-configured\n",
1536 edev
->accept_any_vlan
= false;
1539 static const struct net_device_ops qede_netdev_ops
= {
1540 .ndo_open
= qede_open
,
1541 .ndo_stop
= qede_close
,
1542 .ndo_start_xmit
= qede_start_xmit
,
1543 .ndo_set_rx_mode
= qede_set_rx_mode
,
1544 .ndo_set_mac_address
= qede_set_mac_addr
,
1545 .ndo_validate_addr
= eth_validate_addr
,
1546 .ndo_change_mtu
= qede_change_mtu
,
1547 .ndo_vlan_rx_add_vid
= qede_vlan_rx_add_vid
,
1548 .ndo_vlan_rx_kill_vid
= qede_vlan_rx_kill_vid
,
1549 .ndo_get_stats64
= qede_get_stats64
,
1552 /* -------------------------------------------------------------------------
1553 * START OF PROBE / REMOVE
1554 * -------------------------------------------------------------------------
1557 static struct qede_dev
*qede_alloc_etherdev(struct qed_dev
*cdev
,
1558 struct pci_dev
*pdev
,
1559 struct qed_dev_eth_info
*info
,
1563 struct net_device
*ndev
;
1564 struct qede_dev
*edev
;
1566 ndev
= alloc_etherdev_mqs(sizeof(*edev
),
1570 pr_err("etherdev allocation failed\n");
1574 edev
= netdev_priv(ndev
);
1578 edev
->dp_module
= dp_module
;
1579 edev
->dp_level
= dp_level
;
1580 edev
->ops
= qed_ops
;
1581 edev
->q_num_rx_buffers
= NUM_RX_BDS_DEF
;
1582 edev
->q_num_tx_buffers
= NUM_TX_BDS_DEF
;
1584 DP_INFO(edev
, "Allocated netdev with 64 tx queues and 64 rx queues\n");
1586 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
1588 memset(&edev
->stats
, 0, sizeof(edev
->stats
));
1589 memcpy(&edev
->dev_info
, info
, sizeof(*info
));
1591 edev
->num_tc
= edev
->dev_info
.num_tc
;
1593 INIT_LIST_HEAD(&edev
->vlan_list
);
1598 static void qede_init_ndev(struct qede_dev
*edev
)
1600 struct net_device
*ndev
= edev
->ndev
;
1601 struct pci_dev
*pdev
= edev
->pdev
;
1604 pci_set_drvdata(pdev
, ndev
);
1606 ndev
->mem_start
= edev
->dev_info
.common
.pci_mem_start
;
1607 ndev
->base_addr
= ndev
->mem_start
;
1608 ndev
->mem_end
= edev
->dev_info
.common
.pci_mem_end
;
1609 ndev
->irq
= edev
->dev_info
.common
.pci_irq
;
1611 ndev
->watchdog_timeo
= TX_TIMEOUT
;
1613 ndev
->netdev_ops
= &qede_netdev_ops
;
1615 qede_set_ethtool_ops(ndev
);
1617 /* user-changeble features */
1618 hw_features
= NETIF_F_GRO
| NETIF_F_SG
|
1619 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
1620 NETIF_F_TSO
| NETIF_F_TSO6
;
1622 ndev
->vlan_features
= hw_features
| NETIF_F_RXHASH
| NETIF_F_RXCSUM
|
1624 ndev
->features
= hw_features
| NETIF_F_RXHASH
| NETIF_F_RXCSUM
|
1625 NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HIGHDMA
|
1626 NETIF_F_HW_VLAN_CTAG_FILTER
| NETIF_F_HW_VLAN_CTAG_TX
;
1628 ndev
->hw_features
= hw_features
;
1630 /* Set network device HW mac */
1631 ether_addr_copy(edev
->ndev
->dev_addr
, edev
->dev_info
.common
.hw_mac
);
1634 /* This function converts from 32b param to two params of level and module
1635 * Input 32b decoding:
1636 * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
1637 * 'happy' flow, e.g. memory allocation failed.
1638 * b30 - enable all INFO prints. INFO prints are for major steps in the flow
1639 * and provide important parameters.
1640 * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
1641 * module. VERBOSE prints are for tracking the specific flow in low level.
1643 * Notice that the level should be that of the lowest required logs.
1645 void qede_config_debug(uint debug
, u32
*p_dp_module
, u8
*p_dp_level
)
1647 *p_dp_level
= QED_LEVEL_NOTICE
;
1650 if (debug
& QED_LOG_VERBOSE_MASK
) {
1651 *p_dp_level
= QED_LEVEL_VERBOSE
;
1652 *p_dp_module
= (debug
& 0x3FFFFFFF);
1653 } else if (debug
& QED_LOG_INFO_MASK
) {
1654 *p_dp_level
= QED_LEVEL_INFO
;
1655 } else if (debug
& QED_LOG_NOTICE_MASK
) {
1656 *p_dp_level
= QED_LEVEL_NOTICE
;
1660 static void qede_free_fp_array(struct qede_dev
*edev
)
1662 if (edev
->fp_array
) {
1663 struct qede_fastpath
*fp
;
1667 fp
= &edev
->fp_array
[i
];
1673 kfree(edev
->fp_array
);
1678 static int qede_alloc_fp_array(struct qede_dev
*edev
)
1680 struct qede_fastpath
*fp
;
1683 edev
->fp_array
= kcalloc(QEDE_RSS_CNT(edev
),
1684 sizeof(*edev
->fp_array
), GFP_KERNEL
);
1685 if (!edev
->fp_array
) {
1686 DP_NOTICE(edev
, "fp array allocation failed\n");
1691 fp
= &edev
->fp_array
[i
];
1693 fp
->sb_info
= kcalloc(1, sizeof(*fp
->sb_info
), GFP_KERNEL
);
1695 DP_NOTICE(edev
, "sb info struct allocation failed\n");
1699 fp
->rxq
= kcalloc(1, sizeof(*fp
->rxq
), GFP_KERNEL
);
1701 DP_NOTICE(edev
, "RXQ struct allocation failed\n");
1705 fp
->txqs
= kcalloc(edev
->num_tc
, sizeof(*fp
->txqs
), GFP_KERNEL
);
1707 DP_NOTICE(edev
, "TXQ array allocation failed\n");
1714 qede_free_fp_array(edev
);
1718 static void qede_sp_task(struct work_struct
*work
)
1720 struct qede_dev
*edev
= container_of(work
, struct qede_dev
,
1722 mutex_lock(&edev
->qede_lock
);
1724 if (edev
->state
== QEDE_STATE_OPEN
) {
1725 if (test_and_clear_bit(QEDE_SP_RX_MODE
, &edev
->sp_flags
))
1726 qede_config_rx_mode(edev
->ndev
);
1729 mutex_unlock(&edev
->qede_lock
);
1732 static void qede_update_pf_params(struct qed_dev
*cdev
)
1734 struct qed_pf_params pf_params
;
1737 memset(&pf_params
, 0, sizeof(struct qed_pf_params
));
1738 pf_params
.eth_pf_params
.num_cons
= 32;
1739 qed_ops
->common
->update_pf_params(cdev
, &pf_params
);
1742 enum qede_probe_mode
{
1746 static int __qede_probe(struct pci_dev
*pdev
, u32 dp_module
, u8 dp_level
,
1747 enum qede_probe_mode mode
)
1749 struct qed_slowpath_params params
;
1750 struct qed_dev_eth_info dev_info
;
1751 struct qede_dev
*edev
;
1752 struct qed_dev
*cdev
;
1755 if (unlikely(dp_level
& QED_LEVEL_INFO
))
1756 pr_notice("Starting qede probe\n");
1758 cdev
= qed_ops
->common
->probe(pdev
, QED_PROTOCOL_ETH
,
1759 dp_module
, dp_level
);
1765 qede_update_pf_params(cdev
);
1767 /* Start the Slowpath-process */
1768 memset(¶ms
, 0, sizeof(struct qed_slowpath_params
));
1769 params
.int_mode
= QED_INT_MODE_MSIX
;
1770 params
.drv_major
= QEDE_MAJOR_VERSION
;
1771 params
.drv_minor
= QEDE_MINOR_VERSION
;
1772 params
.drv_rev
= QEDE_REVISION_VERSION
;
1773 params
.drv_eng
= QEDE_ENGINEERING_VERSION
;
1774 strlcpy(params
.name
, "qede LAN", QED_DRV_VER_STR_SIZE
);
1775 rc
= qed_ops
->common
->slowpath_start(cdev
, ¶ms
);
1777 pr_notice("Cannot start slowpath\n");
1781 /* Learn information crucial for qede to progress */
1782 rc
= qed_ops
->fill_dev_info(cdev
, &dev_info
);
1786 edev
= qede_alloc_etherdev(cdev
, pdev
, &dev_info
, dp_module
,
1793 qede_init_ndev(edev
);
1795 rc
= register_netdev(edev
->ndev
);
1797 DP_NOTICE(edev
, "Cannot register net-device\n");
1801 edev
->ops
->common
->set_id(cdev
, edev
->ndev
->name
, DRV_MODULE_VERSION
);
1803 edev
->ops
->register_ops(cdev
, &qede_ll_ops
, edev
);
1805 INIT_DELAYED_WORK(&edev
->sp_task
, qede_sp_task
);
1806 mutex_init(&edev
->qede_lock
);
1808 DP_INFO(edev
, "Ending successfully qede probe\n");
1813 free_netdev(edev
->ndev
);
1815 qed_ops
->common
->slowpath_stop(cdev
);
1817 qed_ops
->common
->remove(cdev
);
1822 static int qede_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1827 qede_config_debug(debug
, &dp_module
, &dp_level
);
1829 return __qede_probe(pdev
, dp_module
, dp_level
,
1833 enum qede_remove_mode
{
1837 static void __qede_remove(struct pci_dev
*pdev
, enum qede_remove_mode mode
)
1839 struct net_device
*ndev
= pci_get_drvdata(pdev
);
1840 struct qede_dev
*edev
= netdev_priv(ndev
);
1841 struct qed_dev
*cdev
= edev
->cdev
;
1843 DP_INFO(edev
, "Starting qede_remove\n");
1845 cancel_delayed_work_sync(&edev
->sp_task
);
1846 unregister_netdev(ndev
);
1848 edev
->ops
->common
->set_power_state(cdev
, PCI_D0
);
1850 pci_set_drvdata(pdev
, NULL
);
1854 /* Use global ops since we've freed edev */
1855 qed_ops
->common
->slowpath_stop(cdev
);
1856 qed_ops
->common
->remove(cdev
);
1858 pr_notice("Ending successfully qede_remove\n");
1861 static void qede_remove(struct pci_dev
*pdev
)
1863 __qede_remove(pdev
, QEDE_REMOVE_NORMAL
);
1866 /* -------------------------------------------------------------------------
1867 * START OF LOAD / UNLOAD
1868 * -------------------------------------------------------------------------
1871 static int qede_set_num_queues(struct qede_dev
*edev
)
1876 /* Setup queues according to possible resources*/
1878 rss_num
= edev
->req_rss
;
1880 rss_num
= netif_get_num_default_rss_queues() *
1881 edev
->dev_info
.common
.num_hwfns
;
1883 rss_num
= min_t(u16
, QEDE_MAX_RSS_CNT(edev
), rss_num
);
1885 rc
= edev
->ops
->common
->set_fp_int(edev
->cdev
, rss_num
);
1887 /* Managed to request interrupts for our queues */
1889 DP_INFO(edev
, "Managed %d [of %d] RSS queues\n",
1890 QEDE_RSS_CNT(edev
), rss_num
);
1896 static void qede_free_mem_sb(struct qede_dev
*edev
,
1897 struct qed_sb_info
*sb_info
)
1899 if (sb_info
->sb_virt
)
1900 dma_free_coherent(&edev
->pdev
->dev
, sizeof(*sb_info
->sb_virt
),
1901 (void *)sb_info
->sb_virt
, sb_info
->sb_phys
);
1904 /* This function allocates fast-path status block memory */
1905 static int qede_alloc_mem_sb(struct qede_dev
*edev
,
1906 struct qed_sb_info
*sb_info
,
1909 struct status_block
*sb_virt
;
1913 sb_virt
= dma_alloc_coherent(&edev
->pdev
->dev
,
1915 &sb_phys
, GFP_KERNEL
);
1917 DP_ERR(edev
, "Status block allocation failed\n");
1921 rc
= edev
->ops
->common
->sb_init(edev
->cdev
, sb_info
,
1922 sb_virt
, sb_phys
, sb_id
,
1923 QED_SB_TYPE_L2_QUEUE
);
1925 DP_ERR(edev
, "Status block initialization failed\n");
1926 dma_free_coherent(&edev
->pdev
->dev
, sizeof(*sb_virt
),
1934 static void qede_free_rx_buffers(struct qede_dev
*edev
,
1935 struct qede_rx_queue
*rxq
)
1939 for (i
= rxq
->sw_rx_cons
; i
!= rxq
->sw_rx_prod
; i
++) {
1940 struct sw_rx_data
*rx_buf
;
1943 rx_buf
= &rxq
->sw_rx_ring
[i
& NUM_RX_BDS_MAX
];
1944 data
= rx_buf
->data
;
1946 dma_unmap_page(&edev
->pdev
->dev
,
1948 PAGE_SIZE
, DMA_FROM_DEVICE
);
1950 rx_buf
->data
= NULL
;
1955 static void qede_free_mem_rxq(struct qede_dev
*edev
,
1956 struct qede_rx_queue
*rxq
)
1958 /* Free rx buffers */
1959 qede_free_rx_buffers(edev
, rxq
);
1961 /* Free the parallel SW ring */
1962 kfree(rxq
->sw_rx_ring
);
1964 /* Free the real RQ ring used by FW */
1965 edev
->ops
->common
->chain_free(edev
->cdev
, &rxq
->rx_bd_ring
);
1966 edev
->ops
->common
->chain_free(edev
->cdev
, &rxq
->rx_comp_ring
);
1969 static int qede_alloc_rx_buffer(struct qede_dev
*edev
,
1970 struct qede_rx_queue
*rxq
)
1972 struct sw_rx_data
*sw_rx_data
;
1973 struct eth_rx_bd
*rx_bd
;
1978 rx_buf_size
= rxq
->rx_buf_size
;
1980 data
= alloc_pages(GFP_ATOMIC
, 0);
1981 if (unlikely(!data
)) {
1982 DP_NOTICE(edev
, "Failed to allocate Rx data [page]\n");
1986 /* Map the entire page as it would be used
1987 * for multiple RX buffer segment size mapping.
1989 mapping
= dma_map_page(&edev
->pdev
->dev
, data
, 0,
1990 PAGE_SIZE
, DMA_FROM_DEVICE
);
1991 if (unlikely(dma_mapping_error(&edev
->pdev
->dev
, mapping
))) {
1993 DP_NOTICE(edev
, "Failed to map Rx buffer\n");
1997 sw_rx_data
= &rxq
->sw_rx_ring
[rxq
->sw_rx_prod
& NUM_RX_BDS_MAX
];
1998 sw_rx_data
->page_offset
= 0;
1999 sw_rx_data
->data
= data
;
2000 sw_rx_data
->mapping
= mapping
;
2002 /* Advance PROD and get BD pointer */
2003 rx_bd
= (struct eth_rx_bd
*)qed_chain_produce(&rxq
->rx_bd_ring
);
2005 rx_bd
->addr
.hi
= cpu_to_le32(upper_32_bits(mapping
));
2006 rx_bd
->addr
.lo
= cpu_to_le32(lower_32_bits(mapping
));
2013 /* This function allocates all memory needed per Rx queue */
2014 static int qede_alloc_mem_rxq(struct qede_dev
*edev
,
2015 struct qede_rx_queue
*rxq
)
2017 int i
, rc
, size
, num_allocated
;
2019 rxq
->num_rx_buffers
= edev
->q_num_rx_buffers
;
2021 rxq
->rx_buf_size
= NET_IP_ALIGN
+ ETH_OVERHEAD
+
2023 if (rxq
->rx_buf_size
> PAGE_SIZE
)
2024 rxq
->rx_buf_size
= PAGE_SIZE
;
2026 /* Segment size to spilt a page in multiple equal parts */
2027 rxq
->rx_buf_seg_size
= roundup_pow_of_two(rxq
->rx_buf_size
);
2029 /* Allocate the parallel driver ring for Rx buffers */
2030 size
= sizeof(*rxq
->sw_rx_ring
) * RX_RING_SIZE
;
2031 rxq
->sw_rx_ring
= kzalloc(size
, GFP_KERNEL
);
2032 if (!rxq
->sw_rx_ring
) {
2033 DP_ERR(edev
, "Rx buffers ring allocation failed\n");
2037 /* Allocate FW Rx ring */
2038 rc
= edev
->ops
->common
->chain_alloc(edev
->cdev
,
2039 QED_CHAIN_USE_TO_CONSUME_PRODUCE
,
2040 QED_CHAIN_MODE_NEXT_PTR
,
2042 sizeof(struct eth_rx_bd
),
2048 /* Allocate FW completion ring */
2049 rc
= edev
->ops
->common
->chain_alloc(edev
->cdev
,
2050 QED_CHAIN_USE_TO_CONSUME
,
2053 sizeof(union eth_rx_cqe
),
2054 &rxq
->rx_comp_ring
);
2058 /* Allocate buffers for the Rx ring */
2059 for (i
= 0; i
< rxq
->num_rx_buffers
; i
++) {
2060 rc
= qede_alloc_rx_buffer(edev
, rxq
);
2065 if (!num_allocated
) {
2066 DP_ERR(edev
, "Rx buffers allocation failed\n");
2068 } else if (num_allocated
< rxq
->num_rx_buffers
) {
2070 "Allocated less buffers than desired (%d allocated)\n",
2077 qede_free_mem_rxq(edev
, rxq
);
2081 static void qede_free_mem_txq(struct qede_dev
*edev
,
2082 struct qede_tx_queue
*txq
)
2084 /* Free the parallel SW ring */
2085 kfree(txq
->sw_tx_ring
);
2087 /* Free the real RQ ring used by FW */
2088 edev
->ops
->common
->chain_free(edev
->cdev
, &txq
->tx_pbl
);
2091 /* This function allocates all memory needed per Tx queue */
2092 static int qede_alloc_mem_txq(struct qede_dev
*edev
,
2093 struct qede_tx_queue
*txq
)
2096 union eth_tx_bd_types
*p_virt
;
2098 txq
->num_tx_buffers
= edev
->q_num_tx_buffers
;
2100 /* Allocate the parallel driver ring for Tx buffers */
2101 size
= sizeof(*txq
->sw_tx_ring
) * NUM_TX_BDS_MAX
;
2102 txq
->sw_tx_ring
= kzalloc(size
, GFP_KERNEL
);
2103 if (!txq
->sw_tx_ring
) {
2104 DP_NOTICE(edev
, "Tx buffers ring allocation failed\n");
2108 rc
= edev
->ops
->common
->chain_alloc(edev
->cdev
,
2109 QED_CHAIN_USE_TO_CONSUME_PRODUCE
,
2120 qede_free_mem_txq(edev
, txq
);
2124 /* This function frees all memory of a single fp */
2125 static void qede_free_mem_fp(struct qede_dev
*edev
,
2126 struct qede_fastpath
*fp
)
2130 qede_free_mem_sb(edev
, fp
->sb_info
);
2132 qede_free_mem_rxq(edev
, fp
->rxq
);
2134 for (tc
= 0; tc
< edev
->num_tc
; tc
++)
2135 qede_free_mem_txq(edev
, &fp
->txqs
[tc
]);
2138 /* This function allocates all memory needed for a single fp (i.e. an entity
2139 * which contains status block, one rx queue and multiple per-TC tx queues.
2141 static int qede_alloc_mem_fp(struct qede_dev
*edev
,
2142 struct qede_fastpath
*fp
)
2146 rc
= qede_alloc_mem_sb(edev
, fp
->sb_info
, fp
->rss_id
);
2150 rc
= qede_alloc_mem_rxq(edev
, fp
->rxq
);
2154 for (tc
= 0; tc
< edev
->num_tc
; tc
++) {
2155 rc
= qede_alloc_mem_txq(edev
, &fp
->txqs
[tc
]);
2163 qede_free_mem_fp(edev
, fp
);
2167 static void qede_free_mem_load(struct qede_dev
*edev
)
2172 struct qede_fastpath
*fp
= &edev
->fp_array
[i
];
2174 qede_free_mem_fp(edev
, fp
);
2178 /* This function allocates all qede memory at NIC load. */
2179 static int qede_alloc_mem_load(struct qede_dev
*edev
)
2183 for (rss_id
= 0; rss_id
< QEDE_RSS_CNT(edev
); rss_id
++) {
2184 struct qede_fastpath
*fp
= &edev
->fp_array
[rss_id
];
2186 rc
= qede_alloc_mem_fp(edev
, fp
);
2191 if (rss_id
!= QEDE_RSS_CNT(edev
)) {
2192 /* Failed allocating memory for all the queues */
2195 "Failed to allocate memory for the leading queue\n");
2199 "Failed to allocate memory for all of RSS queues\n Desired: %d queues, allocated: %d queues\n",
2200 QEDE_RSS_CNT(edev
), rss_id
);
2202 edev
->num_rss
= rss_id
;
2208 /* This function inits fp content and resets the SB, RXQ and TXQ structures */
2209 static void qede_init_fp(struct qede_dev
*edev
)
2211 int rss_id
, txq_index
, tc
;
2212 struct qede_fastpath
*fp
;
2214 for_each_rss(rss_id
) {
2215 fp
= &edev
->fp_array
[rss_id
];
2218 fp
->rss_id
= rss_id
;
2220 memset((void *)&fp
->napi
, 0, sizeof(fp
->napi
));
2222 memset((void *)fp
->sb_info
, 0, sizeof(*fp
->sb_info
));
2224 memset((void *)fp
->rxq
, 0, sizeof(*fp
->rxq
));
2225 fp
->rxq
->rxq_id
= rss_id
;
2227 memset((void *)fp
->txqs
, 0, (edev
->num_tc
* sizeof(*fp
->txqs
)));
2228 for (tc
= 0; tc
< edev
->num_tc
; tc
++) {
2229 txq_index
= tc
* QEDE_RSS_CNT(edev
) + rss_id
;
2230 fp
->txqs
[tc
].index
= txq_index
;
2233 snprintf(fp
->name
, sizeof(fp
->name
), "%s-fp-%d",
2234 edev
->ndev
->name
, rss_id
);
2238 static int qede_set_real_num_queues(struct qede_dev
*edev
)
2242 rc
= netif_set_real_num_tx_queues(edev
->ndev
, QEDE_TSS_CNT(edev
));
2244 DP_NOTICE(edev
, "Failed to set real number of Tx queues\n");
2247 rc
= netif_set_real_num_rx_queues(edev
->ndev
, QEDE_RSS_CNT(edev
));
2249 DP_NOTICE(edev
, "Failed to set real number of Rx queues\n");
2256 static void qede_napi_disable_remove(struct qede_dev
*edev
)
2261 napi_disable(&edev
->fp_array
[i
].napi
);
2263 netif_napi_del(&edev
->fp_array
[i
].napi
);
2267 static void qede_napi_add_enable(struct qede_dev
*edev
)
2271 /* Add NAPI objects */
2273 netif_napi_add(edev
->ndev
, &edev
->fp_array
[i
].napi
,
2274 qede_poll
, NAPI_POLL_WEIGHT
);
2275 napi_enable(&edev
->fp_array
[i
].napi
);
2279 static void qede_sync_free_irqs(struct qede_dev
*edev
)
2283 for (i
= 0; i
< edev
->int_info
.used_cnt
; i
++) {
2284 if (edev
->int_info
.msix_cnt
) {
2285 synchronize_irq(edev
->int_info
.msix
[i
].vector
);
2286 free_irq(edev
->int_info
.msix
[i
].vector
,
2287 &edev
->fp_array
[i
]);
2289 edev
->ops
->common
->simd_handler_clean(edev
->cdev
, i
);
2293 edev
->int_info
.used_cnt
= 0;
2296 static int qede_req_msix_irqs(struct qede_dev
*edev
)
2300 /* Sanitize number of interrupts == number of prepared RSS queues */
2301 if (QEDE_RSS_CNT(edev
) > edev
->int_info
.msix_cnt
) {
2303 "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n",
2304 QEDE_RSS_CNT(edev
), edev
->int_info
.msix_cnt
);
2308 for (i
= 0; i
< QEDE_RSS_CNT(edev
); i
++) {
2309 rc
= request_irq(edev
->int_info
.msix
[i
].vector
,
2310 qede_msix_fp_int
, 0, edev
->fp_array
[i
].name
,
2311 &edev
->fp_array
[i
]);
2313 DP_ERR(edev
, "Request fp %d irq failed\n", i
);
2314 qede_sync_free_irqs(edev
);
2317 DP_VERBOSE(edev
, NETIF_MSG_INTR
,
2318 "Requested fp irq for %s [entry %d]. Cookie is at %p\n",
2319 edev
->fp_array
[i
].name
, i
,
2320 &edev
->fp_array
[i
]);
2321 edev
->int_info
.used_cnt
++;
2327 static void qede_simd_fp_handler(void *cookie
)
2329 struct qede_fastpath
*fp
= (struct qede_fastpath
*)cookie
;
2331 napi_schedule_irqoff(&fp
->napi
);
2334 static int qede_setup_irqs(struct qede_dev
*edev
)
2338 /* Learn Interrupt configuration */
2339 rc
= edev
->ops
->common
->get_fp_int(edev
->cdev
, &edev
->int_info
);
2343 if (edev
->int_info
.msix_cnt
) {
2344 rc
= qede_req_msix_irqs(edev
);
2347 edev
->ndev
->irq
= edev
->int_info
.msix
[0].vector
;
2349 const struct qed_common_ops
*ops
;
2351 /* qed should learn receive the RSS ids and callbacks */
2352 ops
= edev
->ops
->common
;
2353 for (i
= 0; i
< QEDE_RSS_CNT(edev
); i
++)
2354 ops
->simd_handler_config(edev
->cdev
,
2355 &edev
->fp_array
[i
], i
,
2356 qede_simd_fp_handler
);
2357 edev
->int_info
.used_cnt
= QEDE_RSS_CNT(edev
);
2362 static int qede_drain_txq(struct qede_dev
*edev
,
2363 struct qede_tx_queue
*txq
,
2368 while (txq
->sw_tx_cons
!= txq
->sw_tx_prod
) {
2372 "Tx queue[%d] is stuck, requesting MCP to drain\n",
2374 rc
= edev
->ops
->common
->drain(edev
->cdev
);
2377 return qede_drain_txq(edev
, txq
, false);
2380 "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n",
2381 txq
->index
, txq
->sw_tx_prod
,
2386 usleep_range(1000, 2000);
2390 /* FW finished processing, wait for HW to transmit all tx packets */
2391 usleep_range(1000, 2000);
2396 static int qede_stop_queues(struct qede_dev
*edev
)
2398 struct qed_update_vport_params vport_update_params
;
2399 struct qed_dev
*cdev
= edev
->cdev
;
2402 /* Disable the vport */
2403 memset(&vport_update_params
, 0, sizeof(vport_update_params
));
2404 vport_update_params
.vport_id
= 0;
2405 vport_update_params
.update_vport_active_flg
= 1;
2406 vport_update_params
.vport_active_flg
= 0;
2407 vport_update_params
.update_rss_flg
= 0;
2409 rc
= edev
->ops
->vport_update(cdev
, &vport_update_params
);
2411 DP_ERR(edev
, "Failed to update vport\n");
2415 /* Flush Tx queues. If needed, request drain from MCP */
2417 struct qede_fastpath
*fp
= &edev
->fp_array
[i
];
2419 for (tc
= 0; tc
< edev
->num_tc
; tc
++) {
2420 struct qede_tx_queue
*txq
= &fp
->txqs
[tc
];
2422 rc
= qede_drain_txq(edev
, txq
, true);
2428 /* Stop all Queues in reverse order*/
2429 for (i
= QEDE_RSS_CNT(edev
) - 1; i
>= 0; i
--) {
2430 struct qed_stop_rxq_params rx_params
;
2432 /* Stop the Tx Queue(s)*/
2433 for (tc
= 0; tc
< edev
->num_tc
; tc
++) {
2434 struct qed_stop_txq_params tx_params
;
2436 tx_params
.rss_id
= i
;
2437 tx_params
.tx_queue_id
= tc
* QEDE_RSS_CNT(edev
) + i
;
2438 rc
= edev
->ops
->q_tx_stop(cdev
, &tx_params
);
2440 DP_ERR(edev
, "Failed to stop TXQ #%d\n",
2441 tx_params
.tx_queue_id
);
2446 /* Stop the Rx Queue*/
2447 memset(&rx_params
, 0, sizeof(rx_params
));
2448 rx_params
.rss_id
= i
;
2449 rx_params
.rx_queue_id
= i
;
2451 rc
= edev
->ops
->q_rx_stop(cdev
, &rx_params
);
2453 DP_ERR(edev
, "Failed to stop RXQ #%d\n", i
);
2458 /* Stop the vport */
2459 rc
= edev
->ops
->vport_stop(cdev
, 0);
2461 DP_ERR(edev
, "Failed to stop VPORT\n");
2466 static int qede_start_queues(struct qede_dev
*edev
)
2469 int vport_id
= 0, drop_ttl0_flg
= 1, vlan_removal_en
= 1;
2470 struct qed_dev
*cdev
= edev
->cdev
;
2471 struct qed_update_vport_rss_params
*rss_params
= &edev
->rss_params
;
2472 struct qed_update_vport_params vport_update_params
;
2473 struct qed_queue_start_common_params q_params
;
2475 if (!edev
->num_rss
) {
2477 "Cannot update V-VPORT as active as there are no Rx queues\n");
2481 rc
= edev
->ops
->vport_start(cdev
, vport_id
,
2487 DP_ERR(edev
, "Start V-PORT failed %d\n", rc
);
2491 DP_VERBOSE(edev
, NETIF_MSG_IFUP
,
2492 "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
2493 vport_id
, edev
->ndev
->mtu
+ 0xe, vlan_removal_en
);
2496 struct qede_fastpath
*fp
= &edev
->fp_array
[i
];
2497 dma_addr_t phys_table
= fp
->rxq
->rx_comp_ring
.pbl
.p_phys_table
;
2499 memset(&q_params
, 0, sizeof(q_params
));
2500 q_params
.rss_id
= i
;
2501 q_params
.queue_id
= i
;
2502 q_params
.vport_id
= 0;
2503 q_params
.sb
= fp
->sb_info
->igu_sb_id
;
2504 q_params
.sb_idx
= RX_PI
;
2506 rc
= edev
->ops
->q_rx_start(cdev
, &q_params
,
2507 fp
->rxq
->rx_buf_size
,
2508 fp
->rxq
->rx_bd_ring
.p_phys_addr
,
2510 fp
->rxq
->rx_comp_ring
.page_cnt
,
2511 &fp
->rxq
->hw_rxq_prod_addr
);
2513 DP_ERR(edev
, "Start RXQ #%d failed %d\n", i
, rc
);
2517 fp
->rxq
->hw_cons_ptr
= &fp
->sb_info
->sb_virt
->pi_array
[RX_PI
];
2519 qede_update_rx_prod(edev
, fp
->rxq
);
2521 for (tc
= 0; tc
< edev
->num_tc
; tc
++) {
2522 struct qede_tx_queue
*txq
= &fp
->txqs
[tc
];
2523 int txq_index
= tc
* QEDE_RSS_CNT(edev
) + i
;
2525 memset(&q_params
, 0, sizeof(q_params
));
2526 q_params
.rss_id
= i
;
2527 q_params
.queue_id
= txq_index
;
2528 q_params
.vport_id
= 0;
2529 q_params
.sb
= fp
->sb_info
->igu_sb_id
;
2530 q_params
.sb_idx
= TX_PI(tc
);
2532 rc
= edev
->ops
->q_tx_start(cdev
, &q_params
,
2533 txq
->tx_pbl
.pbl
.p_phys_table
,
2534 txq
->tx_pbl
.page_cnt
,
2535 &txq
->doorbell_addr
);
2537 DP_ERR(edev
, "Start TXQ #%d failed %d\n",
2543 &fp
->sb_info
->sb_virt
->pi_array
[TX_PI(tc
)];
2544 SET_FIELD(txq
->tx_db
.data
.params
,
2545 ETH_DB_DATA_DEST
, DB_DEST_XCM
);
2546 SET_FIELD(txq
->tx_db
.data
.params
, ETH_DB_DATA_AGG_CMD
,
2548 SET_FIELD(txq
->tx_db
.data
.params
,
2549 ETH_DB_DATA_AGG_VAL_SEL
,
2550 DQ_XCM_ETH_TX_BD_PROD_CMD
);
2552 txq
->tx_db
.data
.agg_flags
= DQ_XCM_ETH_DQ_CF_CMD
;
2556 /* Prepare and send the vport enable */
2557 memset(&vport_update_params
, 0, sizeof(vport_update_params
));
2558 vport_update_params
.vport_id
= vport_id
;
2559 vport_update_params
.update_vport_active_flg
= 1;
2560 vport_update_params
.vport_active_flg
= 1;
2562 /* Fill struct with RSS params */
2563 if (QEDE_RSS_CNT(edev
) > 1) {
2564 vport_update_params
.update_rss_flg
= 1;
2565 for (i
= 0; i
< 128; i
++)
2566 rss_params
->rss_ind_table
[i
] =
2567 ethtool_rxfh_indir_default(i
, QEDE_RSS_CNT(edev
));
2568 netdev_rss_key_fill(rss_params
->rss_key
,
2569 sizeof(rss_params
->rss_key
));
2571 memset(rss_params
, 0, sizeof(*rss_params
));
2573 memcpy(&vport_update_params
.rss_params
, rss_params
,
2574 sizeof(*rss_params
));
2576 rc
= edev
->ops
->vport_update(cdev
, &vport_update_params
);
2578 DP_ERR(edev
, "Update V-PORT failed %d\n", rc
);
2585 static int qede_set_mcast_rx_mac(struct qede_dev
*edev
,
2586 enum qed_filter_xcast_params_type opcode
,
2587 unsigned char *mac
, int num_macs
)
2589 struct qed_filter_params filter_cmd
;
2592 memset(&filter_cmd
, 0, sizeof(filter_cmd
));
2593 filter_cmd
.type
= QED_FILTER_TYPE_MCAST
;
2594 filter_cmd
.filter
.mcast
.type
= opcode
;
2595 filter_cmd
.filter
.mcast
.num
= num_macs
;
2597 for (i
= 0; i
< num_macs
; i
++, mac
+= ETH_ALEN
)
2598 ether_addr_copy(filter_cmd
.filter
.mcast
.mac
[i
], mac
);
2600 return edev
->ops
->filter_config(edev
->cdev
, &filter_cmd
);
2603 enum qede_unload_mode
{
2607 static void qede_unload(struct qede_dev
*edev
, enum qede_unload_mode mode
)
2609 struct qed_link_params link_params
;
2612 DP_INFO(edev
, "Starting qede unload\n");
2614 mutex_lock(&edev
->qede_lock
);
2615 edev
->state
= QEDE_STATE_CLOSED
;
2618 netif_tx_disable(edev
->ndev
);
2619 netif_carrier_off(edev
->ndev
);
2621 /* Reset the link */
2622 memset(&link_params
, 0, sizeof(link_params
));
2623 link_params
.link_up
= false;
2624 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
2625 rc
= qede_stop_queues(edev
);
2627 qede_sync_free_irqs(edev
);
2631 DP_INFO(edev
, "Stopped Queues\n");
2633 qede_vlan_mark_nonconfigured(edev
);
2634 edev
->ops
->fastpath_stop(edev
->cdev
);
2636 /* Release the interrupts */
2637 qede_sync_free_irqs(edev
);
2638 edev
->ops
->common
->set_fp_int(edev
->cdev
, 0);
2640 qede_napi_disable_remove(edev
);
2642 qede_free_mem_load(edev
);
2643 qede_free_fp_array(edev
);
2646 mutex_unlock(&edev
->qede_lock
);
2647 DP_INFO(edev
, "Ending qede unload\n");
2650 enum qede_load_mode
{
2654 static int qede_load(struct qede_dev
*edev
, enum qede_load_mode mode
)
2656 struct qed_link_params link_params
;
2657 struct qed_link_output link_output
;
2660 DP_INFO(edev
, "Starting qede load\n");
2662 rc
= qede_set_num_queues(edev
);
2666 rc
= qede_alloc_fp_array(edev
);
2672 rc
= qede_alloc_mem_load(edev
);
2675 DP_INFO(edev
, "Allocated %d RSS queues on %d TC/s\n",
2676 QEDE_RSS_CNT(edev
), edev
->num_tc
);
2678 rc
= qede_set_real_num_queues(edev
);
2682 qede_napi_add_enable(edev
);
2683 DP_INFO(edev
, "Napi added and enabled\n");
2685 rc
= qede_setup_irqs(edev
);
2688 DP_INFO(edev
, "Setup IRQs succeeded\n");
2690 rc
= qede_start_queues(edev
);
2693 DP_INFO(edev
, "Start VPORT, RXQ and TXQ succeeded\n");
2695 /* Add primary mac and set Rx filters */
2696 ether_addr_copy(edev
->primary_mac
, edev
->ndev
->dev_addr
);
2698 mutex_lock(&edev
->qede_lock
);
2699 edev
->state
= QEDE_STATE_OPEN
;
2700 mutex_unlock(&edev
->qede_lock
);
2702 /* Program un-configured VLANs */
2703 qede_configure_vlan_filters(edev
);
2705 /* Ask for link-up using current configuration */
2706 memset(&link_params
, 0, sizeof(link_params
));
2707 link_params
.link_up
= true;
2708 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
2710 /* Query whether link is already-up */
2711 memset(&link_output
, 0, sizeof(link_output
));
2712 edev
->ops
->common
->get_link(edev
->cdev
, &link_output
);
2713 qede_link_update(edev
, &link_output
);
2715 DP_INFO(edev
, "Ending successfully qede load\n");
2720 qede_sync_free_irqs(edev
);
2721 memset(&edev
->int_info
.msix_cnt
, 0, sizeof(struct qed_int_info
));
2723 qede_napi_disable_remove(edev
);
2725 qede_free_mem_load(edev
);
2727 edev
->ops
->common
->set_fp_int(edev
->cdev
, 0);
2728 qede_free_fp_array(edev
);
2734 void qede_reload(struct qede_dev
*edev
,
2735 void (*func
)(struct qede_dev
*, union qede_reload_args
*),
2736 union qede_reload_args
*args
)
2738 qede_unload(edev
, QEDE_UNLOAD_NORMAL
);
2739 /* Call function handler to update parameters
2740 * needed for function load.
2745 qede_load(edev
, QEDE_LOAD_NORMAL
);
2747 mutex_lock(&edev
->qede_lock
);
2748 qede_config_rx_mode(edev
->ndev
);
2749 mutex_unlock(&edev
->qede_lock
);
2752 /* called with rtnl_lock */
2753 static int qede_open(struct net_device
*ndev
)
2755 struct qede_dev
*edev
= netdev_priv(ndev
);
2757 netif_carrier_off(ndev
);
2759 edev
->ops
->common
->set_power_state(edev
->cdev
, PCI_D0
);
2761 return qede_load(edev
, QEDE_LOAD_NORMAL
);
2764 static int qede_close(struct net_device
*ndev
)
2766 struct qede_dev
*edev
= netdev_priv(ndev
);
2768 qede_unload(edev
, QEDE_UNLOAD_NORMAL
);
2773 static void qede_link_update(void *dev
, struct qed_link_output
*link
)
2775 struct qede_dev
*edev
= dev
;
2777 if (!netif_running(edev
->ndev
)) {
2778 DP_VERBOSE(edev
, NETIF_MSG_LINK
, "Interface is not running\n");
2782 if (link
->link_up
) {
2783 if (!netif_carrier_ok(edev
->ndev
)) {
2784 DP_NOTICE(edev
, "Link is up\n");
2785 netif_tx_start_all_queues(edev
->ndev
);
2786 netif_carrier_on(edev
->ndev
);
2789 if (netif_carrier_ok(edev
->ndev
)) {
2790 DP_NOTICE(edev
, "Link is down\n");
2791 netif_tx_disable(edev
->ndev
);
2792 netif_carrier_off(edev
->ndev
);
2797 static int qede_set_mac_addr(struct net_device
*ndev
, void *p
)
2799 struct qede_dev
*edev
= netdev_priv(ndev
);
2800 struct sockaddr
*addr
= p
;
2803 ASSERT_RTNL(); /* @@@TBD To be removed */
2805 DP_INFO(edev
, "Set_mac_addr called\n");
2807 if (!is_valid_ether_addr(addr
->sa_data
)) {
2808 DP_NOTICE(edev
, "The MAC address is not valid\n");
2812 ether_addr_copy(ndev
->dev_addr
, addr
->sa_data
);
2814 if (!netif_running(ndev
)) {
2815 DP_NOTICE(edev
, "The device is currently down\n");
2819 /* Remove the previous primary mac */
2820 rc
= qede_set_ucast_rx_mac(edev
, QED_FILTER_XCAST_TYPE_DEL
,
2825 /* Add MAC filter according to the new unicast HW MAC address */
2826 ether_addr_copy(edev
->primary_mac
, ndev
->dev_addr
);
2827 return qede_set_ucast_rx_mac(edev
, QED_FILTER_XCAST_TYPE_ADD
,
2832 qede_configure_mcast_filtering(struct net_device
*ndev
,
2833 enum qed_filter_rx_mode_type
*accept_flags
)
2835 struct qede_dev
*edev
= netdev_priv(ndev
);
2836 unsigned char *mc_macs
, *temp
;
2837 struct netdev_hw_addr
*ha
;
2838 int rc
= 0, mc_count
;
2841 size
= 64 * ETH_ALEN
;
2843 mc_macs
= kzalloc(size
, GFP_KERNEL
);
2846 "Failed to allocate memory for multicast MACs\n");
2853 /* Remove all previously configured MAC filters */
2854 rc
= qede_set_mcast_rx_mac(edev
, QED_FILTER_XCAST_TYPE_DEL
,
2859 netif_addr_lock_bh(ndev
);
2861 mc_count
= netdev_mc_count(ndev
);
2862 if (mc_count
< 64) {
2863 netdev_for_each_mc_addr(ha
, ndev
) {
2864 ether_addr_copy(temp
, ha
->addr
);
2869 netif_addr_unlock_bh(ndev
);
2871 /* Check for all multicast @@@TBD resource allocation */
2872 if ((ndev
->flags
& IFF_ALLMULTI
) ||
2874 if (*accept_flags
== QED_FILTER_RX_MODE_TYPE_REGULAR
)
2875 *accept_flags
= QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC
;
2877 /* Add all multicast MAC filters */
2878 rc
= qede_set_mcast_rx_mac(edev
, QED_FILTER_XCAST_TYPE_ADD
,
2887 static void qede_set_rx_mode(struct net_device
*ndev
)
2889 struct qede_dev
*edev
= netdev_priv(ndev
);
2891 DP_INFO(edev
, "qede_set_rx_mode called\n");
2893 if (edev
->state
!= QEDE_STATE_OPEN
) {
2895 "qede_set_rx_mode called while interface is down\n");
2897 set_bit(QEDE_SP_RX_MODE
, &edev
->sp_flags
);
2898 schedule_delayed_work(&edev
->sp_task
, 0);
2902 /* Must be called with qede_lock held */
2903 static void qede_config_rx_mode(struct net_device
*ndev
)
2905 enum qed_filter_rx_mode_type accept_flags
= QED_FILTER_TYPE_UCAST
;
2906 struct qede_dev
*edev
= netdev_priv(ndev
);
2907 struct qed_filter_params rx_mode
;
2908 unsigned char *uc_macs
, *temp
;
2909 struct netdev_hw_addr
*ha
;
2913 netif_addr_lock_bh(ndev
);
2915 uc_count
= netdev_uc_count(ndev
);
2916 size
= uc_count
* ETH_ALEN
;
2918 uc_macs
= kzalloc(size
, GFP_ATOMIC
);
2920 DP_NOTICE(edev
, "Failed to allocate memory for unicast MACs\n");
2921 netif_addr_unlock_bh(ndev
);
2926 netdev_for_each_uc_addr(ha
, ndev
) {
2927 ether_addr_copy(temp
, ha
->addr
);
2931 netif_addr_unlock_bh(ndev
);
2933 /* Configure the struct for the Rx mode */
2934 memset(&rx_mode
, 0, sizeof(struct qed_filter_params
));
2935 rx_mode
.type
= QED_FILTER_TYPE_RX_MODE
;
2937 /* Remove all previous unicast secondary macs and multicast macs
2938 * (configrue / leave the primary mac)
2940 rc
= qede_set_ucast_rx_mac(edev
, QED_FILTER_XCAST_TYPE_REPLACE
,
2945 /* Check for promiscuous */
2946 if ((ndev
->flags
& IFF_PROMISC
) ||
2947 (uc_count
> 15)) { /* @@@TBD resource allocation - 1 */
2948 accept_flags
= QED_FILTER_RX_MODE_TYPE_PROMISC
;
2950 /* Add MAC filters according to the unicast secondary macs */
2954 for (i
= 0; i
< uc_count
; i
++) {
2955 rc
= qede_set_ucast_rx_mac(edev
,
2956 QED_FILTER_XCAST_TYPE_ADD
,
2964 rc
= qede_configure_mcast_filtering(ndev
, &accept_flags
);
2969 /* take care of VLAN mode */
2970 if (ndev
->flags
& IFF_PROMISC
) {
2971 qede_config_accept_any_vlan(edev
, true);
2972 } else if (!edev
->non_configured_vlans
) {
2973 /* It's possible that accept_any_vlan mode is set due to a
2974 * previous setting of IFF_PROMISC. If vlan credits are
2975 * sufficient, disable accept_any_vlan.
2977 qede_config_accept_any_vlan(edev
, false);
2980 rx_mode
.filter
.accept_flags
= accept_flags
;
2981 edev
->ops
->filter_config(edev
->cdev
, &rx_mode
);