Lines Matching +full:disable +full:- +full:eop
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 - 2022 Beijing WangXun Technology Co., Ltd. */
32 /* L3: ip non-tunnel */
48 /* IPv4 --> IPv4/IPv6 */
60 /* IPv4 --> GRE/NAT --> NONE/IPv4/IPv6 */
73 /* IPv4 --> GRE/NAT --> MAC --> NONE/IPv4/IPv6 */
86 /* IPv4 --> GRE/NAT --> MAC+VLAN --> NONE/IPv4/IPv6 */
99 /* IPv6 --> IPv4/IPv6 */
111 /* IPv6 --> GRE/NAT -> NONE/IPv4/IPv6 */
124 /* IPv6 --> GRE/NAT -> MAC -> NONE/IPv4/IPv6 */
137 /* IPv6 --> GRE/NAT -> MAC--> NONE/IPv */
157 /* wx_test_staterr - tests bits in Rx descriptor status and error fields */
161 return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits); in wx_test_staterr()
167 struct sk_buff *skb = rx_buffer->skb; in wx_dma_sync_frag()
168 skb_frag_t *frag = &skb_shinfo(skb)->frags[0]; in wx_dma_sync_frag()
170 dma_sync_single_range_for_cpu(rx_ring->dev, in wx_dma_sync_frag()
171 WX_CB(skb)->dma, in wx_dma_sync_frag()
177 if (unlikely(WX_CB(skb)->page_released)) in wx_dma_sync_frag()
178 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_dma_sync_frag()
189 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; in wx_get_rx_buffer()
190 size = le16_to_cpu(rx_desc->wb.upper.length); in wx_get_rx_buffer()
193 *rx_buffer_pgcnt = page_count(rx_buffer->page); in wx_get_rx_buffer()
198 prefetchw(rx_buffer->page); in wx_get_rx_buffer()
199 *skb = rx_buffer->skb; in wx_get_rx_buffer()
203 * Only unmap it when EOP is reached in wx_get_rx_buffer()
214 dma_sync_single_range_for_cpu(rx_ring->dev, in wx_get_rx_buffer()
215 rx_buffer->dma, in wx_get_rx_buffer()
216 rx_buffer->page_offset, in wx_get_rx_buffer()
228 if (!IS_ERR(skb) && WX_CB(skb)->dma == rx_buffer->dma) in wx_put_rx_buffer()
230 WX_CB(skb)->page_released = true; in wx_put_rx_buffer()
233 rx_buffer->page = NULL; in wx_put_rx_buffer()
234 rx_buffer->skb = NULL; in wx_put_rx_buffer()
241 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); in wx_build_skb()
247 struct sk_buff *skb = rx_buffer->skb; in wx_build_skb()
250 void *page_addr = page_address(rx_buffer->page) + in wx_build_skb()
251 rx_buffer->page_offset; in wx_build_skb()
257 skb = napi_alloc_skb(&rx_ring->q_vector->napi, WX_RXBUFFER_256); in wx_build_skb()
261 /* we will be copying header into skb->data in in wx_build_skb()
265 prefetchw(skb->data); in wx_build_skb()
270 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, true); in wx_build_skb()
277 WX_CB(skb)->dma = rx_buffer->dma; in wx_build_skb()
279 skb_add_rx_frag(skb, 0, rx_buffer->page, in wx_build_skb()
280 rx_buffer->page_offset, in wx_build_skb()
285 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, in wx_build_skb()
286 rx_buffer->page_offset, size, truesize); in wx_build_skb()
292 rx_buffer->page_offset ^= truesize; in wx_build_skb()
295 rx_buffer->page_offset += truesize; in wx_build_skb()
304 struct page *page = bi->page; in wx_alloc_mapped_page()
311 page = page_pool_dev_alloc_pages(rx_ring->page_pool); in wx_alloc_mapped_page()
316 bi->page_dma = dma; in wx_alloc_mapped_page()
317 bi->page = page; in wx_alloc_mapped_page()
318 bi->page_offset = 0; in wx_alloc_mapped_page()
324 * wx_alloc_rx_buffers - Replace used receive buffers
330 u16 i = rx_ring->next_to_use; in wx_alloc_rx_buffers()
339 bi = &rx_ring->rx_buffer_info[i]; in wx_alloc_rx_buffers()
340 i -= rx_ring->count; in wx_alloc_rx_buffers()
347 dma_sync_single_range_for_device(rx_ring->dev, bi->dma, in wx_alloc_rx_buffers()
348 bi->page_offset, in wx_alloc_rx_buffers()
352 rx_desc->read.pkt_addr = in wx_alloc_rx_buffers()
353 cpu_to_le64(bi->page_dma + bi->page_offset); in wx_alloc_rx_buffers()
360 bi = rx_ring->rx_buffer_info; in wx_alloc_rx_buffers()
361 i -= rx_ring->count; in wx_alloc_rx_buffers()
365 rx_desc->wb.upper.status_error = 0; in wx_alloc_rx_buffers()
367 cleaned_count--; in wx_alloc_rx_buffers()
370 i += rx_ring->count; in wx_alloc_rx_buffers()
372 if (rx_ring->next_to_use != i) { in wx_alloc_rx_buffers()
373 rx_ring->next_to_use = i; in wx_alloc_rx_buffers()
375 rx_ring->next_to_alloc = i; in wx_alloc_rx_buffers()
379 * applicable for weak-ordered memory model archs, in wx_alloc_rx_buffers()
380 * such as IA-64). in wx_alloc_rx_buffers()
383 writel(i, rx_ring->tail); in wx_alloc_rx_buffers()
389 u16 ntc = ring->next_to_clean; in wx_desc_unused()
390 u16 ntu = ring->next_to_use; in wx_desc_unused()
392 return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; in wx_desc_unused()
396 * wx_is_non_eop - process handling of non-EOP buffers
401 * This function updates next to clean. If the buffer is an EOP buffer
404 * that this is in fact a non-EOP buffer.
410 u32 ntc = rx_ring->next_to_clean + 1; in wx_is_non_eop()
413 ntc = (ntc < rx_ring->count) ? ntc : 0; in wx_is_non_eop()
414 rx_ring->next_to_clean = ntc; in wx_is_non_eop()
422 rx_ring->rx_buffer_info[ntc].skb = skb; in wx_is_non_eop()
423 rx_ring->rx_stats.non_eop_descs++; in wx_is_non_eop()
430 skb_frag_t *frag = &skb_shinfo(skb)->frags[0]; in wx_pull_tail()
441 * 60 bytes if the skb->len is less than 60 for skb_pad. in wx_pull_tail()
443 pull_len = eth_get_headlen(skb->dev, va, WX_RXBUFFER_256); in wx_pull_tail()
451 skb->data_len -= pull_len; in wx_pull_tail()
452 skb->tail += pull_len; in wx_pull_tail()
456 * wx_cleanup_headers - Correct corrupted or empty headers
458 * @rx_desc: pointer to the EOP Rx descriptor
477 struct net_device *netdev = rx_ring->netdev; in wx_cleanup_headers()
482 !(netdev->features & NETIF_F_RXALL))) { in wx_cleanup_headers()
504 if (!(ring->netdev->features & NETIF_F_RXHASH)) in wx_rx_hash()
507 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & in wx_rx_hash()
513 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), in wx_rx_hash()
519 * wx_rx_checksum - indicate in skb if hw indicated a good cksum
532 if (!(ring->netdev->features & NETIF_F_RXCSUM)) in wx_rx_checksum()
540 ring->rx_stats.csum_err++; in wx_rx_checksum()
555 ring->rx_stats.csum_err++; in wx_rx_checksum()
560 skb->ip_summed = CHECKSUM_UNNECESSARY; in wx_rx_checksum()
568 ring->rx_stats.csum_good_cnt++; in wx_rx_checksum()
577 if ((ring->netdev->features & in wx_rx_vlan()
580 idx = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & in wx_rx_vlan()
582 ethertype = ring->q_vector->wx->tpid[idx]; in wx_rx_vlan()
584 le16_to_cpu(rx_desc->wb.upper.vlan)); in wx_rx_vlan()
589 * wx_process_skb_fields - Populate skb header fields from Rx descriptor
591 * @rx_desc: pointer to the EOP Rx descriptor
605 skb_record_rx_queue(skb, rx_ring->queue_index); in wx_process_skb_fields()
606 skb->protocol = eth_type_trans(skb, rx_ring->netdev); in wx_process_skb_fields()
610 * wx_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
641 rx_desc = WX_RX_DESC(rx_ring, rx_ring->next_to_clean); in wx_clean_rx_irq()
658 rx_ring->rx_stats.alloc_rx_buff_failed++; in wx_clean_rx_irq()
674 total_rx_bytes += skb->len; in wx_clean_rx_irq()
678 napi_gro_receive(&q_vector->napi, skb); in wx_clean_rx_irq()
684 u64_stats_update_begin(&rx_ring->syncp); in wx_clean_rx_irq()
685 rx_ring->stats.packets += total_rx_packets; in wx_clean_rx_irq()
686 rx_ring->stats.bytes += total_rx_bytes; in wx_clean_rx_irq()
687 u64_stats_update_end(&rx_ring->syncp); in wx_clean_rx_irq()
688 q_vector->rx.total_packets += total_rx_packets; in wx_clean_rx_irq()
689 q_vector->rx.total_bytes += total_rx_bytes; in wx_clean_rx_irq()
696 return netdev_get_tx_queue(ring->netdev, ring->queue_index); in wx_txring_txq()
700 * wx_clean_tx_irq - Reclaim resources after transmit completes
708 unsigned int budget = q_vector->wx->tx_work_limit; in wx_clean_tx_irq()
710 unsigned int i = tx_ring->next_to_clean; in wx_clean_tx_irq()
714 if (!netif_carrier_ok(tx_ring->netdev)) in wx_clean_tx_irq()
717 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_clean_tx_irq()
719 i -= tx_ring->count; in wx_clean_tx_irq()
722 union wx_tx_desc *eop_desc = tx_buffer->next_to_watch; in wx_clean_tx_irq()
732 if (!(eop_desc->wb.status & cpu_to_le32(WX_TXD_STAT_DD))) in wx_clean_tx_irq()
736 tx_buffer->next_to_watch = NULL; in wx_clean_tx_irq()
739 total_bytes += tx_buffer->bytecount; in wx_clean_tx_irq()
740 total_packets += tx_buffer->gso_segs; in wx_clean_tx_irq()
743 napi_consume_skb(tx_buffer->skb, napi_budget); in wx_clean_tx_irq()
746 dma_unmap_single(tx_ring->dev, in wx_clean_tx_irq()
760 i -= tx_ring->count; in wx_clean_tx_irq()
761 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_irq()
767 dma_unmap_page(tx_ring->dev, in wx_clean_tx_irq()
780 i -= tx_ring->count; in wx_clean_tx_irq()
781 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_irq()
789 budget--; in wx_clean_tx_irq()
792 i += tx_ring->count; in wx_clean_tx_irq()
793 tx_ring->next_to_clean = i; in wx_clean_tx_irq()
794 u64_stats_update_begin(&tx_ring->syncp); in wx_clean_tx_irq()
795 tx_ring->stats.bytes += total_bytes; in wx_clean_tx_irq()
796 tx_ring->stats.packets += total_packets; in wx_clean_tx_irq()
797 u64_stats_update_end(&tx_ring->syncp); in wx_clean_tx_irq()
798 q_vector->tx.total_bytes += total_bytes; in wx_clean_tx_irq()
799 q_vector->tx.total_packets += total_packets; in wx_clean_tx_irq()
805 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && in wx_clean_tx_irq()
812 if (__netif_subqueue_stopped(tx_ring->netdev, in wx_clean_tx_irq()
813 tx_ring->queue_index) && in wx_clean_tx_irq()
814 netif_running(tx_ring->netdev)) { in wx_clean_tx_irq()
815 netif_wake_subqueue(tx_ring->netdev, in wx_clean_tx_irq()
816 tx_ring->queue_index); in wx_clean_tx_irq()
817 ++tx_ring->tx_stats.restart_queue; in wx_clean_tx_irq()
825 * wx_poll - NAPI polling RX/TX cleanup routine
835 struct wx *wx = q_vector->wx; in wx_poll()
839 wx_for_each_ring(ring, q_vector->tx) { in wx_poll()
851 if (q_vector->rx.count > 1) in wx_poll()
852 per_ring_budget = max(budget / q_vector->rx.count, 1); in wx_poll()
856 wx_for_each_ring(ring, q_vector->rx) { in wx_poll()
870 if (netif_running(wx->netdev)) in wx_poll()
871 wx_intr_enable(wx, WX_INTR_Q(q_vector->v_idx)); in wx_poll()
874 return min(work_done, budget - 1); in wx_poll()
882 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); in wx_maybe_stop_tx()
891 return -EBUSY; in wx_maybe_stop_tx()
893 /* A reprieve! - use start_queue because it doesn't call schedule */ in wx_maybe_stop_tx()
894 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); in wx_maybe_stop_tx()
895 ++tx_ring->tx_stats.restart_queue; in wx_maybe_stop_tx()
934 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); in wx_tx_olinfo_status()
941 struct sk_buff *skb = first->skb; in wx_tx_map()
943 u32 tx_flags = first->tx_flags; in wx_tx_map()
944 u16 i = tx_ring->next_to_use; in wx_tx_map()
953 wx_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); in wx_tx_map()
956 data_len = skb->data_len; in wx_tx_map()
957 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); in wx_tx_map()
961 for (frag = &skb_shinfo(skb)->frags[0];; frag++) { in wx_tx_map()
962 if (dma_mapping_error(tx_ring->dev, dma)) in wx_tx_map()
969 tx_desc->read.buffer_addr = cpu_to_le64(dma); in wx_tx_map()
972 tx_desc->read.cmd_type_len = in wx_tx_map()
977 if (i == tx_ring->count) { in wx_tx_map()
981 tx_desc->read.olinfo_status = 0; in wx_tx_map()
984 size -= WX_MAX_DATA_PER_TXD; in wx_tx_map()
986 tx_desc->read.buffer_addr = cpu_to_le64(dma); in wx_tx_map()
992 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); in wx_tx_map()
996 if (i == tx_ring->count) { in wx_tx_map()
1000 tx_desc->read.olinfo_status = 0; in wx_tx_map()
1004 data_len -= size; in wx_tx_map()
1006 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, in wx_tx_map()
1009 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_tx_map()
1012 /* write last descriptor with RS and EOP bits */ in wx_tx_map()
1014 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); in wx_tx_map()
1016 netdev_tx_sent_queue(wx_txring_txq(tx_ring), first->bytecount); in wx_tx_map()
1021 * are new descriptors to fetch. (Only applicable for weak-ordered in wx_tx_map()
1022 * memory model archs, such as IA-64). in wx_tx_map()
1030 first->next_to_watch = tx_desc; in wx_tx_map()
1033 if (i == tx_ring->count) in wx_tx_map()
1036 tx_ring->next_to_use = i; in wx_tx_map()
1041 writel(i, tx_ring->tail); in wx_tx_map()
1045 dev_err(tx_ring->dev, "TX DMA map failed\n"); in wx_tx_map()
1049 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_tx_map()
1051 dma_unmap_page(tx_ring->dev, in wx_tx_map()
1059 i += tx_ring->count; in wx_tx_map()
1060 i--; in wx_tx_map()
1063 dev_kfree_skb_any(first->skb); in wx_tx_map()
1064 first->skb = NULL; in wx_tx_map()
1066 tx_ring->next_to_use = i; in wx_tx_map()
1073 u16 i = tx_ring->next_to_use; in wx_tx_ctxtdesc()
1077 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; in wx_tx_ctxtdesc()
1081 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); in wx_tx_ctxtdesc()
1082 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); in wx_tx_ctxtdesc()
1083 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); in wx_tx_ctxtdesc()
1084 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); in wx_tx_ctxtdesc()
1096 struct sk_buff *skb = first->skb; in wx_encode_tx_desc_ptype()
1100 if (skb->encapsulation) { in wx_encode_tx_desc_ptype()
1103 switch (first->protocol) { in wx_encode_tx_desc_ptype()
1105 tun_prot = ip_hdr(skb)->protocol; in wx_encode_tx_desc_ptype()
1111 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_encode_tx_desc_ptype()
1113 ipv6_skip_exthdr(skb, exthdr - skb->data, &tun_prot, &frag_off); in wx_encode_tx_desc_ptype()
1125 if (skb->inner_protocol_type != ENCAP_TYPE_ETHER || in wx_encode_tx_desc_ptype()
1126 skb->inner_protocol != htons(ETH_P_TEB)) { in wx_encode_tx_desc_ptype()
1129 if (((struct ethhdr *)skb_inner_mac_header(skb))->h_proto in wx_encode_tx_desc_ptype()
1138 if (skb->inner_protocol == htons(ETH_P_IP) || in wx_encode_tx_desc_ptype()
1139 skb->inner_protocol == htons(ETH_P_IPV6)) { in wx_encode_tx_desc_ptype()
1142 if (((struct ethhdr *)skb_inner_mac_header(skb))->h_proto in wx_encode_tx_desc_ptype()
1152 switch (hdr.ipv4->version) { in wx_encode_tx_desc_ptype()
1154 l4_prot = hdr.ipv4->protocol; in wx_encode_tx_desc_ptype()
1159 l4_prot = inner_ipv6_hdr(skb)->nexthdr; in wx_encode_tx_desc_ptype()
1161 ipv6_skip_exthdr(skb, exthdr - skb->data, &l4_prot, &frag_off); in wx_encode_tx_desc_ptype()
1168 switch (first->protocol) { in wx_encode_tx_desc_ptype()
1170 l4_prot = ip_hdr(skb)->protocol; in wx_encode_tx_desc_ptype()
1176 l4_prot = ipv6_hdr(skb)->nexthdr; in wx_encode_tx_desc_ptype()
1178 ipv6_skip_exthdr(skb, exthdr - skb->data, &l4_prot, &frag_off); in wx_encode_tx_desc_ptype()
1207 struct net_device *netdev = tx_ring->netdev; in wx_tso()
1209 struct sk_buff *skb = first->skb; in wx_tso()
1210 bool enc = skb->encapsulation; in wx_tso()
1217 if (skb->ip_summed != CHECKSUM_PARTIAL) in wx_tso()
1229 if (iph->version == 4) { in wx_tso()
1231 iph->tot_len = 0; in wx_tso()
1232 iph->check = 0; in wx_tso()
1233 tcph->check = ~csum_tcpudp_magic(iph->saddr, in wx_tso()
1234 iph->daddr, 0, in wx_tso()
1236 first->tx_flags |= WX_TX_FLAGS_TSO | in wx_tso()
1240 } else if (iph->version == 6 && skb_is_gso_v6(skb)) { in wx_tso()
1243 ipv6h->payload_len = 0; in wx_tso()
1244 tcph->check = ~csum_ipv6_magic(&ipv6h->saddr, in wx_tso()
1245 &ipv6h->daddr, 0, in wx_tso()
1247 first->tx_flags |= WX_TX_FLAGS_TSO | in wx_tso()
1259 first->gso_segs = skb_shinfo(skb)->gso_segs; in wx_tso()
1260 first->bytecount += (first->gso_segs - 1) * *hdr_len; in wx_tso()
1264 mss_l4len_idx |= skb_shinfo(skb)->gso_size << WX_TXD_MSS_SHIFT; in wx_tso()
1271 switch (first->protocol) { in wx_tso()
1273 tun_prot = ip_hdr(skb)->protocol; in wx_tso()
1274 first->tx_flags |= WX_TX_FLAGS_OUTER_IPV4; in wx_tso()
1279 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_tso()
1281 ipv6_skip_exthdr(skb, exthdr - skb->data, &tun_prot, &frag_off); in wx_tso()
1291 (((skb_inner_mac_header(skb) - in wx_tso()
1299 (((skb_inner_mac_header(skb) - in wx_tso()
1305 tunhdr_eiplen_tunlen = (((char *)inner_ip_hdr(skb) - in wx_tso()
1318 vlan_macip_lens |= first->tx_flags & WX_TX_FLAGS_VLAN_MASK; in wx_tso()
1321 if (skb->vlan_proto == htons(ETH_P_8021AD) && in wx_tso()
1322 netdev->features & NETIF_F_HW_VLAN_STAG_TX) in wx_tso()
1323 type_tucmd |= WX_SET_FLAG(first->tx_flags, in wx_tso()
1336 struct net_device *netdev = tx_ring->netdev; in wx_tx_csum()
1338 struct sk_buff *skb = first->skb; in wx_tx_csum()
1341 if (skb->ip_summed != CHECKSUM_PARTIAL) { in wx_tx_csum()
1343 if (!(first->tx_flags & WX_TX_FLAGS_HW_VLAN) && in wx_tx_csum()
1344 !(first->tx_flags & WX_TX_FLAGS_CC)) in wx_tx_csum()
1362 if (skb->encapsulation) { in wx_tx_csum()
1367 switch (first->protocol) { in wx_tx_csum()
1369 tun_prot = ip_hdr(skb)->protocol; in wx_tx_csum()
1374 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_tx_csum()
1376 ipv6_skip_exthdr(skb, exthdr - skb->data, in wx_tx_csum()
1388 (((skb_inner_mac_header(skb) - in wx_tx_csum()
1396 (((skb_inner_mac_header(skb) - in wx_tx_csum()
1402 tunhdr_eiplen_tunlen = (((char *)inner_ip_hdr(skb) - in wx_tx_csum()
1417 switch (network_hdr.ipv4->version) { in wx_tx_csum()
1419 vlan_macip_lens |= (transport_hdr.raw - network_hdr.raw) >> 1; in wx_tx_csum()
1420 l4_prot = network_hdr.ipv4->protocol; in wx_tx_csum()
1423 vlan_macip_lens |= (transport_hdr.raw - network_hdr.raw) >> 1; in wx_tx_csum()
1425 l4_prot = network_hdr.ipv6->nexthdr; in wx_tx_csum()
1427 ipv6_skip_exthdr(skb, exthdr - skb->data, &l4_prot, &frag_off); in wx_tx_csum()
1435 mss_l4len_idx = (transport_hdr.tcphdr->doff * 4) << in wx_tx_csum()
1452 first->tx_flags |= WX_TX_FLAGS_CSUM; in wx_tx_csum()
1454 first->tx_flags |= WX_TX_FLAGS_CC; in wx_tx_csum()
1456 vlan_macip_lens |= first->tx_flags & WX_TX_FLAGS_VLAN_MASK; in wx_tx_csum()
1459 if (skb->vlan_proto == htons(ETH_P_8021AD) && in wx_tx_csum()
1460 netdev->features & NETIF_F_HW_VLAN_STAG_TX) in wx_tx_csum()
1461 type_tucmd |= WX_SET_FLAG(first->tx_flags, in wx_tx_csum()
1471 struct wx *wx = netdev_priv(tx_ring->netdev); in wx_xmit_frame_ring()
1485 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) in wx_xmit_frame_ring()
1486 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)-> in wx_xmit_frame_ring()
1490 tx_ring->tx_stats.tx_busy++; in wx_xmit_frame_ring()
1495 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; in wx_xmit_frame_ring()
1496 first->skb = skb; in wx_xmit_frame_ring()
1497 first->bytecount = skb->len; in wx_xmit_frame_ring()
1498 first->gso_segs = 1; in wx_xmit_frame_ring()
1507 first->tx_flags = tx_flags; in wx_xmit_frame_ring()
1508 first->protocol = vlan_get_protocol(skb); in wx_xmit_frame_ring()
1518 if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags) && tx_ring->atr_sample_rate) in wx_xmit_frame_ring()
1519 wx->atr(tx_ring, first, ptype); in wx_xmit_frame_ring()
1525 dev_kfree_skb_any(first->skb); in wx_xmit_frame_ring()
1526 first->skb = NULL; in wx_xmit_frame_ring()
1534 unsigned int r_idx = skb->queue_mapping; in wx_xmit_frame()
1549 if (r_idx >= wx->num_tx_queues) in wx_xmit_frame()
1550 r_idx = r_idx % wx->num_tx_queues; in wx_xmit_frame()
1551 tx_ring = wx->tx_ring[r_idx]; in wx_xmit_frame()
1562 for (q_idx = 0; q_idx < wx->num_q_vectors; q_idx++) { in wx_napi_enable_all()
1563 q_vector = wx->q_vector[q_idx]; in wx_napi_enable_all()
1564 napi_enable(&q_vector->napi); in wx_napi_enable_all()
1574 for (q_idx = 0; q_idx < wx->num_q_vectors; q_idx++) { in wx_napi_disable_all()
1575 q_vector = wx->q_vector[q_idx]; in wx_napi_disable_all()
1576 napi_disable(&q_vector->napi); in wx_napi_disable_all()
1594 f = &wx->ring_feature[RING_F_RSS]; in wx_set_rss_queues()
1595 f->indices = f->limit; in wx_set_rss_queues()
1597 if (!(test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))) in wx_set_rss_queues()
1600 clear_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_rss_queues()
1606 if (f->indices > 1) { in wx_set_rss_queues()
1607 f = &wx->ring_feature[RING_F_FDIR]; in wx_set_rss_queues()
1609 f->indices = f->limit; in wx_set_rss_queues()
1611 if (!(test_bit(WX_FLAG_FDIR_PERFECT, wx->flags))) in wx_set_rss_queues()
1612 set_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_rss_queues()
1616 wx->num_rx_queues = f->indices; in wx_set_rss_queues()
1617 wx->num_tx_queues = f->indices; in wx_set_rss_queues()
1623 wx->num_rx_queues = 1; in wx_set_num_queues()
1624 wx->num_tx_queues = 1; in wx_set_num_queues()
1625 wx->queues_per_pool = 1; in wx_set_num_queues()
1631 * wx_acquire_msix_vectors - acquire MSI-X vectors
1634 * Attempts to acquire a suitable range of MSI-X vector interrupts. Will
1635 * return a negative error code if unable to acquire MSI-X vectors for any
1644 nvecs = max(wx->num_rx_queues, wx->num_tx_queues); in wx_acquire_msix_vectors()
1646 nvecs = min_t(int, nvecs, wx->mac.max_msix_vectors); in wx_acquire_msix_vectors()
1648 wx->msix_q_entries = kcalloc(nvecs, sizeof(struct msix_entry), in wx_acquire_msix_vectors()
1650 if (!wx->msix_q_entries) in wx_acquire_msix_vectors()
1651 return -ENOMEM; in wx_acquire_msix_vectors()
1653 /* One for non-queue interrupts */ in wx_acquire_msix_vectors()
1656 wx->msix_entry = kcalloc(1, sizeof(struct msix_entry), in wx_acquire_msix_vectors()
1658 if (!wx->msix_entry) { in wx_acquire_msix_vectors()
1659 kfree(wx->msix_q_entries); in wx_acquire_msix_vectors()
1660 wx->msix_q_entries = NULL; in wx_acquire_msix_vectors()
1661 return -ENOMEM; in wx_acquire_msix_vectors()
1664 nvecs = pci_alloc_irq_vectors_affinity(wx->pdev, nvecs, in wx_acquire_msix_vectors()
1669 wx_err(wx, "Failed to allocate MSI-X interrupts. Err: %d\n", nvecs); in wx_acquire_msix_vectors()
1670 kfree(wx->msix_q_entries); in wx_acquire_msix_vectors()
1671 wx->msix_q_entries = NULL; in wx_acquire_msix_vectors()
1672 kfree(wx->msix_entry); in wx_acquire_msix_vectors()
1673 wx->msix_entry = NULL; in wx_acquire_msix_vectors()
1677 wx->msix_entry->entry = 0; in wx_acquire_msix_vectors()
1678 wx->msix_entry->vector = pci_irq_vector(wx->pdev, 0); in wx_acquire_msix_vectors()
1679 nvecs -= 1; in wx_acquire_msix_vectors()
1681 wx->msix_q_entries[i].entry = i; in wx_acquire_msix_vectors()
1682 wx->msix_q_entries[i].vector = pci_irq_vector(wx->pdev, i + 1); in wx_acquire_msix_vectors()
1685 wx->num_q_vectors = nvecs; in wx_acquire_msix_vectors()
1691 * wx_set_interrupt_capability - set MSI-X or MSI if supported
1699 struct pci_dev *pdev = wx->pdev; in wx_set_interrupt_capability()
1702 /* We will try to get MSI-X interrupts first */ in wx_set_interrupt_capability()
1704 if (ret == 0 || (ret == -ENOMEM)) in wx_set_interrupt_capability()
1707 /* Disable RSS */ in wx_set_interrupt_capability()
1708 dev_warn(&wx->pdev->dev, "Disabling RSS support\n"); in wx_set_interrupt_capability()
1709 wx->ring_feature[RING_F_RSS].limit = 1; in wx_set_interrupt_capability()
1718 if (pdev->msi_enabled) in wx_set_interrupt_capability()
1727 pdev->irq = pci_irq_vector(pdev, 0); in wx_set_interrupt_capability()
1728 wx->num_q_vectors = 1; in wx_set_interrupt_capability()
1734 * wx_cache_ring_rss - Descriptor ring to register mapping for RSS
1737 * Cache the descriptor ring offsets for RSS, ATR, FCoE, and SR-IOV.
1744 for (i = 0; i < wx->num_rx_queues; i++) in wx_cache_ring_rss()
1745 wx->rx_ring[i]->reg_idx = i; in wx_cache_ring_rss()
1747 for (i = 0; i < wx->num_tx_queues; i++) in wx_cache_ring_rss()
1748 wx->tx_ring[i]->reg_idx = i; in wx_cache_ring_rss()
1753 ring->next = head->ring; in wx_add_ring()
1754 head->ring = ring; in wx_add_ring()
1755 head->count++; in wx_add_ring()
1759 * wx_alloc_q_vector - Allocate memory for a single interrupt vector
1768 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1785 return -ENOMEM; in wx_alloc_q_vector()
1788 netif_napi_add(wx->netdev, &q_vector->napi, in wx_alloc_q_vector()
1792 wx->q_vector[v_idx] = q_vector; in wx_alloc_q_vector()
1793 q_vector->wx = wx; in wx_alloc_q_vector()
1794 q_vector->v_idx = v_idx; in wx_alloc_q_vector()
1796 q_vector->numa_node = cpu_to_node(v_idx); in wx_alloc_q_vector()
1799 ring = q_vector->ring; in wx_alloc_q_vector()
1801 if (wx->mac.type == wx_mac_sp) in wx_alloc_q_vector()
1808 q_vector->itr = wx->tx_itr_setting ? in wx_alloc_q_vector()
1809 default_itr : wx->tx_itr_setting; in wx_alloc_q_vector()
1812 q_vector->itr = wx->rx_itr_setting ? in wx_alloc_q_vector()
1813 default_itr : wx->rx_itr_setting; in wx_alloc_q_vector()
1817 ring->dev = &wx->pdev->dev; in wx_alloc_q_vector()
1818 ring->netdev = wx->netdev; in wx_alloc_q_vector()
1821 ring->q_vector = q_vector; in wx_alloc_q_vector()
1824 wx_add_ring(ring, &q_vector->tx); in wx_alloc_q_vector()
1827 ring->count = wx->tx_ring_count; in wx_alloc_q_vector()
1829 ring->queue_index = txr_idx; in wx_alloc_q_vector()
1832 wx->tx_ring[txr_idx] = ring; in wx_alloc_q_vector()
1835 txr_count--; in wx_alloc_q_vector()
1844 ring->dev = &wx->pdev->dev; in wx_alloc_q_vector()
1845 ring->netdev = wx->netdev; in wx_alloc_q_vector()
1848 ring->q_vector = q_vector; in wx_alloc_q_vector()
1851 wx_add_ring(ring, &q_vector->rx); in wx_alloc_q_vector()
1854 ring->count = wx->rx_ring_count; in wx_alloc_q_vector()
1855 ring->queue_index = rxr_idx; in wx_alloc_q_vector()
1858 wx->rx_ring[rxr_idx] = ring; in wx_alloc_q_vector()
1861 rxr_count--; in wx_alloc_q_vector()
1872 * wx_free_q_vector - Free memory allocated for specific interrupt vector
1882 struct wx_q_vector *q_vector = wx->q_vector[v_idx]; in wx_free_q_vector()
1885 wx_for_each_ring(ring, q_vector->tx) in wx_free_q_vector()
1886 wx->tx_ring[ring->queue_index] = NULL; in wx_free_q_vector()
1888 wx_for_each_ring(ring, q_vector->rx) in wx_free_q_vector()
1889 wx->rx_ring[ring->queue_index] = NULL; in wx_free_q_vector()
1891 wx->q_vector[v_idx] = NULL; in wx_free_q_vector()
1892 netif_napi_del(&q_vector->napi); in wx_free_q_vector()
1897 * wx_alloc_q_vectors - Allocate memory for interrupt vectors
1901 * return -ENOMEM.
1906 unsigned int rxr_remaining = wx->num_rx_queues; in wx_alloc_q_vectors()
1907 unsigned int txr_remaining = wx->num_tx_queues; in wx_alloc_q_vectors()
1908 unsigned int q_vectors = wx->num_q_vectors; in wx_alloc_q_vectors()
1913 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx); in wx_alloc_q_vectors()
1914 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx); in wx_alloc_q_vectors()
1923 rxr_remaining -= rqpv; in wx_alloc_q_vectors()
1924 txr_remaining -= tqpv; in wx_alloc_q_vectors()
1932 wx->num_tx_queues = 0; in wx_alloc_q_vectors()
1933 wx->num_rx_queues = 0; in wx_alloc_q_vectors()
1934 wx->num_q_vectors = 0; in wx_alloc_q_vectors()
1936 while (v_idx--) in wx_alloc_q_vectors()
1939 return -ENOMEM; in wx_alloc_q_vectors()
1943 * wx_free_q_vectors - Free memory allocated for interrupt vectors
1952 int v_idx = wx->num_q_vectors; in wx_free_q_vectors()
1954 wx->num_tx_queues = 0; in wx_free_q_vectors()
1955 wx->num_rx_queues = 0; in wx_free_q_vectors()
1956 wx->num_q_vectors = 0; in wx_free_q_vectors()
1958 while (v_idx--) in wx_free_q_vectors()
1964 struct pci_dev *pdev = wx->pdev; in wx_reset_interrupt_capability()
1966 if (!pdev->msi_enabled && !pdev->msix_enabled) in wx_reset_interrupt_capability()
1969 if (pdev->msix_enabled) { in wx_reset_interrupt_capability()
1970 kfree(wx->msix_q_entries); in wx_reset_interrupt_capability()
1971 wx->msix_q_entries = NULL; in wx_reset_interrupt_capability()
1972 kfree(wx->msix_entry); in wx_reset_interrupt_capability()
1973 wx->msix_entry = NULL; in wx_reset_interrupt_capability()
1975 pci_free_irq_vectors(wx->pdev); in wx_reset_interrupt_capability()
1980 * wx_clear_interrupt_scheme - Clear the current interrupt scheme settings
1984 * to pre-load conditions
2026 if (q_vector->rx.ring || q_vector->tx.ring) in wx_msix_clean_rings()
2027 napi_schedule_irqoff(&q_vector->napi); in wx_msix_clean_rings()
2035 struct pci_dev *pdev = wx->pdev; in wx_free_irq()
2038 if (!(pdev->msix_enabled)) { in wx_free_irq()
2039 if (!wx->misc_irq_domain) in wx_free_irq()
2040 free_irq(pdev->irq, wx); in wx_free_irq()
2044 for (vector = 0; vector < wx->num_q_vectors; vector++) { in wx_free_irq()
2045 struct wx_q_vector *q_vector = wx->q_vector[vector]; in wx_free_irq()
2046 struct msix_entry *entry = &wx->msix_q_entries[vector]; in wx_free_irq()
2049 if (!q_vector->rx.ring && !q_vector->tx.ring) in wx_free_irq()
2052 free_irq(entry->vector, q_vector); in wx_free_irq()
2055 if (!wx->misc_irq_domain) in wx_free_irq()
2056 free_irq(wx->msix_entry->vector, wx); in wx_free_irq()
2061 * wx_setup_isb_resources - allocate interrupt status resources
2068 struct pci_dev *pdev = wx->pdev; in wx_setup_isb_resources()
2070 if (wx->isb_mem) in wx_setup_isb_resources()
2073 wx->isb_mem = dma_alloc_coherent(&pdev->dev, in wx_setup_isb_resources()
2075 &wx->isb_dma, in wx_setup_isb_resources()
2077 if (!wx->isb_mem) { in wx_setup_isb_resources()
2079 return -ENOMEM; in wx_setup_isb_resources()
2087 * wx_free_isb_resources - allocate all queues Rx resources
2094 struct pci_dev *pdev = wx->pdev; in wx_free_isb_resources()
2096 dma_free_coherent(&pdev->dev, sizeof(u32) * 4, in wx_free_isb_resources()
2097 wx->isb_mem, wx->isb_dma); in wx_free_isb_resources()
2098 wx->isb_mem = NULL; in wx_free_isb_resources()
2106 cur_tag = wx->isb_mem[WX_ISB_HEADER]; in wx_misc_isb()
2107 wx->isb_tag[idx] = cur_tag; in wx_misc_isb()
2109 return (__force u32)cpu_to_le32(wx->isb_mem[idx]); in wx_misc_isb()
2114 * wx_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
2116 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
2126 if (direction == -1) { in wx_set_ivar()
2147 * wx_write_eitr - write EITR register in hardware specific way
2156 struct wx *wx = q_vector->wx; in wx_write_eitr()
2157 int v_idx = q_vector->v_idx; in wx_write_eitr()
2160 if (wx->mac.type == wx_mac_sp) in wx_write_eitr()
2161 itr_reg = q_vector->itr & WX_SP_MAX_EITR; in wx_write_eitr()
2163 itr_reg = q_vector->itr & WX_EM_MAX_EITR; in wx_write_eitr()
2171 * wx_configure_vectors - Configure vectors for hardware
2174 * wx_configure_vectors sets up the hardware to properly generate MSI-X/MSI/INTx
2179 struct pci_dev *pdev = wx->pdev; in wx_configure_vectors()
2183 if (pdev->msix_enabled) { in wx_configure_vectors()
2186 /* use EIAM to auto-mask when MSI-X interrupt is asserted in wx_configure_vectors()
2191 /* legacy interrupts, use EIAM to auto-mask when reading EICR, in wx_configure_vectors()
2200 for (v_idx = 0; v_idx < wx->num_q_vectors; v_idx++) { in wx_configure_vectors()
2201 struct wx_q_vector *q_vector = wx->q_vector[v_idx]; in wx_configure_vectors()
2204 wx_for_each_ring(ring, q_vector->rx) in wx_configure_vectors()
2205 wx_set_ivar(wx, 0, ring->reg_idx, v_idx); in wx_configure_vectors()
2207 wx_for_each_ring(ring, q_vector->tx) in wx_configure_vectors()
2208 wx_set_ivar(wx, 1, ring->reg_idx, v_idx); in wx_configure_vectors()
2213 wx_set_ivar(wx, -1, 0, 0); in wx_configure_vectors()
2214 if (pdev->msix_enabled) in wx_configure_vectors()
2220 * wx_clean_rx_ring - Free Rx Buffers per Queue
2226 u16 i = rx_ring->next_to_clean; in wx_clean_rx_ring()
2228 rx_buffer = &rx_ring->rx_buffer_info[i]; in wx_clean_rx_ring()
2231 while (i != rx_ring->next_to_alloc) { in wx_clean_rx_ring()
2232 if (rx_buffer->skb) { in wx_clean_rx_ring()
2233 struct sk_buff *skb = rx_buffer->skb; in wx_clean_rx_ring()
2235 if (WX_CB(skb)->page_released) in wx_clean_rx_ring()
2236 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_clean_rx_ring()
2244 dma_sync_single_range_for_cpu(rx_ring->dev, in wx_clean_rx_ring()
2245 rx_buffer->dma, in wx_clean_rx_ring()
2246 rx_buffer->page_offset, in wx_clean_rx_ring()
2251 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_clean_rx_ring()
2255 if (i == rx_ring->count) { in wx_clean_rx_ring()
2257 rx_buffer = rx_ring->rx_buffer_info; in wx_clean_rx_ring()
2261 rx_ring->next_to_alloc = 0; in wx_clean_rx_ring()
2262 rx_ring->next_to_clean = 0; in wx_clean_rx_ring()
2263 rx_ring->next_to_use = 0; in wx_clean_rx_ring()
2267 * wx_clean_all_rx_rings - Free Rx Buffers for all queues
2274 for (i = 0; i < wx->num_rx_queues; i++) in wx_clean_all_rx_rings()
2275 wx_clean_rx_ring(wx->rx_ring[i]); in wx_clean_all_rx_rings()
2280 * wx_free_rx_resources - Free Rx Resources
2288 kvfree(rx_ring->rx_buffer_info); in wx_free_rx_resources()
2289 rx_ring->rx_buffer_info = NULL; in wx_free_rx_resources()
2292 if (!rx_ring->desc) in wx_free_rx_resources()
2295 dma_free_coherent(rx_ring->dev, rx_ring->size, in wx_free_rx_resources()
2296 rx_ring->desc, rx_ring->dma); in wx_free_rx_resources()
2298 rx_ring->desc = NULL; in wx_free_rx_resources()
2300 if (rx_ring->page_pool) { in wx_free_rx_resources()
2301 page_pool_destroy(rx_ring->page_pool); in wx_free_rx_resources()
2302 rx_ring->page_pool = NULL; in wx_free_rx_resources()
2307 * wx_free_all_rx_resources - Free Rx Resources for All Queues
2316 for (i = 0; i < wx->num_rx_queues; i++) in wx_free_all_rx_resources()
2317 wx_free_rx_resources(wx->rx_ring[i]); in wx_free_all_rx_resources()
2321 * wx_clean_tx_ring - Free Tx Buffers
2327 u16 i = tx_ring->next_to_clean; in wx_clean_tx_ring()
2329 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_clean_tx_ring()
2331 while (i != tx_ring->next_to_use) { in wx_clean_tx_ring()
2335 dev_kfree_skb_any(tx_buffer->skb); in wx_clean_tx_ring()
2338 dma_unmap_single(tx_ring->dev, in wx_clean_tx_ring()
2344 eop_desc = tx_buffer->next_to_watch; in wx_clean_tx_ring()
2352 if (unlikely(i == tx_ring->count)) { in wx_clean_tx_ring()
2354 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_ring()
2360 dma_unmap_page(tx_ring->dev, in wx_clean_tx_ring()
2369 if (unlikely(i == tx_ring->count)) { in wx_clean_tx_ring()
2371 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_ring()
2378 tx_ring->next_to_use = 0; in wx_clean_tx_ring()
2379 tx_ring->next_to_clean = 0; in wx_clean_tx_ring()
2383 * wx_clean_all_tx_rings - Free Tx Buffers for all queues
2390 for (i = 0; i < wx->num_tx_queues; i++) in wx_clean_all_tx_rings()
2391 wx_clean_tx_ring(wx->tx_ring[i]); in wx_clean_all_tx_rings()
2396 * wx_free_tx_resources - Free Tx Resources per Queue
2404 kvfree(tx_ring->tx_buffer_info); in wx_free_tx_resources()
2405 tx_ring->tx_buffer_info = NULL; in wx_free_tx_resources()
2408 if (!tx_ring->desc) in wx_free_tx_resources()
2411 dma_free_coherent(tx_ring->dev, tx_ring->size, in wx_free_tx_resources()
2412 tx_ring->desc, tx_ring->dma); in wx_free_tx_resources()
2413 tx_ring->desc = NULL; in wx_free_tx_resources()
2417 * wx_free_all_tx_resources - Free Tx Resources for All Queues
2426 for (i = 0; i < wx->num_tx_queues; i++) in wx_free_all_tx_resources()
2427 wx_free_tx_resources(wx->tx_ring[i]); in wx_free_all_tx_resources()
2444 .pool_size = rx_ring->size, in wx_alloc_page_pool()
2445 .nid = dev_to_node(rx_ring->dev), in wx_alloc_page_pool()
2446 .dev = rx_ring->dev, in wx_alloc_page_pool()
2452 rx_ring->page_pool = page_pool_create(&pp_params); in wx_alloc_page_pool()
2453 if (IS_ERR(rx_ring->page_pool)) { in wx_alloc_page_pool()
2454 ret = PTR_ERR(rx_ring->page_pool); in wx_alloc_page_pool()
2455 rx_ring->page_pool = NULL; in wx_alloc_page_pool()
2462 * wx_setup_rx_resources - allocate Rx resources (Descriptors)
2469 struct device *dev = rx_ring->dev; in wx_setup_rx_resources()
2474 size = sizeof(struct wx_rx_buffer) * rx_ring->count; in wx_setup_rx_resources()
2476 if (rx_ring->q_vector) in wx_setup_rx_resources()
2477 numa_node = rx_ring->q_vector->numa_node; in wx_setup_rx_resources()
2479 rx_ring->rx_buffer_info = kvmalloc_node(size, GFP_KERNEL, numa_node); in wx_setup_rx_resources()
2480 if (!rx_ring->rx_buffer_info) in wx_setup_rx_resources()
2481 rx_ring->rx_buffer_info = kvmalloc(size, GFP_KERNEL); in wx_setup_rx_resources()
2482 if (!rx_ring->rx_buffer_info) in wx_setup_rx_resources()
2486 rx_ring->size = rx_ring->count * sizeof(union wx_rx_desc); in wx_setup_rx_resources()
2487 rx_ring->size = ALIGN(rx_ring->size, 4096); in wx_setup_rx_resources()
2490 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, in wx_setup_rx_resources()
2491 &rx_ring->dma, GFP_KERNEL); in wx_setup_rx_resources()
2492 if (!rx_ring->desc) { in wx_setup_rx_resources()
2494 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, in wx_setup_rx_resources()
2495 &rx_ring->dma, GFP_KERNEL); in wx_setup_rx_resources()
2498 if (!rx_ring->desc) in wx_setup_rx_resources()
2501 rx_ring->next_to_clean = 0; in wx_setup_rx_resources()
2502 rx_ring->next_to_use = 0; in wx_setup_rx_resources()
2506 dev_err(rx_ring->dev, "Page pool creation failed: %d\n", ret); in wx_setup_rx_resources()
2513 dma_free_coherent(dev, rx_ring->size, rx_ring->desc, rx_ring->dma); in wx_setup_rx_resources()
2515 kvfree(rx_ring->rx_buffer_info); in wx_setup_rx_resources()
2516 rx_ring->rx_buffer_info = NULL; in wx_setup_rx_resources()
2518 return -ENOMEM; in wx_setup_rx_resources()
2522 * wx_setup_all_rx_resources - allocate all queues Rx resources
2535 for (i = 0; i < wx->num_rx_queues; i++) { in wx_setup_all_rx_resources()
2536 err = wx_setup_rx_resources(wx->rx_ring[i]); in wx_setup_all_rx_resources()
2547 while (i--) in wx_setup_all_rx_resources()
2548 wx_free_rx_resources(wx->rx_ring[i]); in wx_setup_all_rx_resources()
2553 * wx_setup_tx_resources - allocate Tx resources (Descriptors)
2560 struct device *dev = tx_ring->dev; in wx_setup_tx_resources()
2565 size = sizeof(struct wx_tx_buffer) * tx_ring->count; in wx_setup_tx_resources()
2567 if (tx_ring->q_vector) in wx_setup_tx_resources()
2568 numa_node = tx_ring->q_vector->numa_node; in wx_setup_tx_resources()
2570 tx_ring->tx_buffer_info = kvmalloc_node(size, GFP_KERNEL, numa_node); in wx_setup_tx_resources()
2571 if (!tx_ring->tx_buffer_info) in wx_setup_tx_resources()
2572 tx_ring->tx_buffer_info = kvmalloc(size, GFP_KERNEL); in wx_setup_tx_resources()
2573 if (!tx_ring->tx_buffer_info) in wx_setup_tx_resources()
2577 tx_ring->size = tx_ring->count * sizeof(union wx_tx_desc); in wx_setup_tx_resources()
2578 tx_ring->size = ALIGN(tx_ring->size, 4096); in wx_setup_tx_resources()
2581 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, in wx_setup_tx_resources()
2582 &tx_ring->dma, GFP_KERNEL); in wx_setup_tx_resources()
2583 if (!tx_ring->desc) { in wx_setup_tx_resources()
2585 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, in wx_setup_tx_resources()
2586 &tx_ring->dma, GFP_KERNEL); in wx_setup_tx_resources()
2589 if (!tx_ring->desc) in wx_setup_tx_resources()
2592 tx_ring->next_to_use = 0; in wx_setup_tx_resources()
2593 tx_ring->next_to_clean = 0; in wx_setup_tx_resources()
2598 kvfree(tx_ring->tx_buffer_info); in wx_setup_tx_resources()
2599 tx_ring->tx_buffer_info = NULL; in wx_setup_tx_resources()
2601 return -ENOMEM; in wx_setup_tx_resources()
2605 * wx_setup_all_tx_resources - allocate all queues Tx resources
2618 for (i = 0; i < wx->num_tx_queues; i++) { in wx_setup_all_tx_resources()
2619 err = wx_setup_tx_resources(wx->tx_ring[i]); in wx_setup_all_tx_resources()
2630 while (i--) in wx_setup_all_tx_resources()
2631 wx_free_tx_resources(wx->tx_ring[i]); in wx_setup_all_tx_resources()
2665 * wx_get_stats64 - Get System Network Statistics
2679 for (i = 0; i < wx->num_rx_queues; i++) { in wx_get_stats64()
2680 struct wx_ring *ring = READ_ONCE(wx->rx_ring[i]); in wx_get_stats64()
2686 start = u64_stats_fetch_begin(&ring->syncp); in wx_get_stats64()
2687 packets = ring->stats.packets; in wx_get_stats64()
2688 bytes = ring->stats.bytes; in wx_get_stats64()
2689 } while (u64_stats_fetch_retry(&ring->syncp, start)); in wx_get_stats64()
2690 stats->rx_packets += packets; in wx_get_stats64()
2691 stats->rx_bytes += bytes; in wx_get_stats64()
2695 for (i = 0; i < wx->num_tx_queues; i++) { in wx_get_stats64()
2696 struct wx_ring *ring = READ_ONCE(wx->tx_ring[i]); in wx_get_stats64()
2702 start = u64_stats_fetch_begin(&ring->syncp); in wx_get_stats64()
2703 packets = ring->stats.packets; in wx_get_stats64()
2704 bytes = ring->stats.bytes; in wx_get_stats64()
2705 } while (u64_stats_fetch_retry(&ring->syncp, in wx_get_stats64()
2707 stats->tx_packets += packets; in wx_get_stats64()
2708 stats->tx_bytes += bytes; in wx_get_stats64()
2714 hwstats = &wx->stats; in wx_get_stats64()
2715 stats->rx_errors = hwstats->crcerrs + hwstats->rlec; in wx_get_stats64()
2716 stats->multicast = hwstats->qmprc; in wx_get_stats64()
2717 stats->rx_length_errors = hwstats->rlec; in wx_get_stats64()
2718 stats->rx_crc_errors = hwstats->crcerrs; in wx_get_stats64()
2724 netdev_features_t changed = netdev->features ^ features; in wx_set_features()
2731 wx->rss_enabled = true; in wx_set_features()
2734 wx->rss_enabled = false; in wx_set_features()
2737 netdev->features = features; in wx_set_features()
2739 if (wx->mac.type == wx_mac_sp && changed & NETIF_F_HW_VLAN_CTAG_RX) in wx_set_features()
2740 wx->do_reset(netdev); in wx_set_features()
2744 if (!(test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))) in wx_set_features()
2747 /* Check if Flow Director n-tuple support was enabled or disabled. If in wx_set_features()
2753 if (!(test_and_set_bit(WX_FLAG_FDIR_PERFECT, wx->flags))) in wx_set_features()
2756 clear_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_features()
2760 if (test_and_clear_bit(WX_FLAG_FDIR_PERFECT, wx->flags)) in wx_set_features()
2764 if (wx->ring_feature[RING_F_RSS].limit <= 1) in wx_set_features()
2767 set_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_features()
2772 wx->do_reset(netdev); in wx_set_features()
2790 netdev_features_t changed = netdev->features ^ features; in wx_fix_features()
2797 features |= netdev->features & NETIF_VLAN_STRIPPING_FEATURES; in wx_fix_features()
2806 features |= netdev->features & NETIF_VLAN_INSERTION_FEATURES; in wx_fix_features()
2815 features |= netdev->features & NETIF_VLAN_FILTERING_FEATURES; in wx_fix_features()
2834 if (new_tx_count != wx->tx_ring_count) { in wx_set_ring()
2835 for (i = 0; i < wx->num_tx_queues; i++) { in wx_set_ring()
2836 memcpy(&temp_ring[i], wx->tx_ring[i], in wx_set_ring()
2844 i--; in wx_set_ring()
2851 for (i = 0; i < wx->num_tx_queues; i++) { in wx_set_ring()
2852 wx_free_tx_resources(wx->tx_ring[i]); in wx_set_ring()
2854 memcpy(wx->tx_ring[i], &temp_ring[i], in wx_set_ring()
2858 wx->tx_ring_count = new_tx_count; in wx_set_ring()
2862 if (new_rx_count != wx->rx_ring_count) { in wx_set_ring()
2863 for (i = 0; i < wx->num_rx_queues; i++) { in wx_set_ring()
2864 memcpy(&temp_ring[i], wx->rx_ring[i], in wx_set_ring()
2872 i--; in wx_set_ring()
2879 for (i = 0; i < wx->num_rx_queues; i++) { in wx_set_ring()
2880 wx_free_rx_resources(wx->rx_ring[i]); in wx_set_ring()
2881 memcpy(wx->rx_ring[i], &temp_ring[i], in wx_set_ring()
2885 wx->rx_ring_count = new_rx_count; in wx_set_ring()