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()
315 bi->page_dma = dma; in wx_alloc_mapped_page()
316 bi->page = page; in wx_alloc_mapped_page()
317 bi->page_offset = 0; in wx_alloc_mapped_page()
323 * wx_alloc_rx_buffers - Replace used receive buffers
329 u16 i = rx_ring->next_to_use; in wx_alloc_rx_buffers()
338 bi = &rx_ring->rx_buffer_info[i]; in wx_alloc_rx_buffers()
339 i -= rx_ring->count; in wx_alloc_rx_buffers()
346 dma_sync_single_range_for_device(rx_ring->dev, bi->dma, in wx_alloc_rx_buffers()
347 bi->page_offset, in wx_alloc_rx_buffers()
351 rx_desc->read.pkt_addr = in wx_alloc_rx_buffers()
352 cpu_to_le64(bi->page_dma + bi->page_offset); in wx_alloc_rx_buffers()
359 bi = rx_ring->rx_buffer_info; in wx_alloc_rx_buffers()
360 i -= rx_ring->count; in wx_alloc_rx_buffers()
364 rx_desc->wb.upper.status_error = 0; in wx_alloc_rx_buffers()
366 cleaned_count--; in wx_alloc_rx_buffers()
369 i += rx_ring->count; in wx_alloc_rx_buffers()
371 if (rx_ring->next_to_use != i) { in wx_alloc_rx_buffers()
372 rx_ring->next_to_use = i; in wx_alloc_rx_buffers()
374 rx_ring->next_to_alloc = i; in wx_alloc_rx_buffers()
378 * applicable for weak-ordered memory model archs, in wx_alloc_rx_buffers()
379 * such as IA-64). in wx_alloc_rx_buffers()
382 writel(i, rx_ring->tail); in wx_alloc_rx_buffers()
388 u16 ntc = ring->next_to_clean; in wx_desc_unused()
389 u16 ntu = ring->next_to_use; in wx_desc_unused()
391 return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; in wx_desc_unused()
395 * wx_is_non_eop - process handling of non-EOP buffers
400 * This function updates next to clean. If the buffer is an EOP buffer
403 * that this is in fact a non-EOP buffer.
409 u32 ntc = rx_ring->next_to_clean + 1; in wx_is_non_eop()
412 ntc = (ntc < rx_ring->count) ? ntc : 0; in wx_is_non_eop()
413 rx_ring->next_to_clean = ntc; in wx_is_non_eop()
421 rx_ring->rx_buffer_info[ntc].skb = skb; in wx_is_non_eop()
422 rx_ring->rx_stats.non_eop_descs++; in wx_is_non_eop()
429 skb_frag_t *frag = &skb_shinfo(skb)->frags[0]; in wx_pull_tail()
440 * 60 bytes if the skb->len is less than 60 for skb_pad. in wx_pull_tail()
442 pull_len = eth_get_headlen(skb->dev, va, WX_RXBUFFER_256); in wx_pull_tail()
450 skb->data_len -= pull_len; in wx_pull_tail()
451 skb->tail += pull_len; in wx_pull_tail()
455 * wx_cleanup_headers - Correct corrupted or empty headers
457 * @rx_desc: pointer to the EOP Rx descriptor
476 struct net_device *netdev = rx_ring->netdev; in wx_cleanup_headers()
481 !(netdev->features & NETIF_F_RXALL))) { in wx_cleanup_headers()
503 if (!(ring->netdev->features & NETIF_F_RXHASH)) in wx_rx_hash()
506 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & in wx_rx_hash()
512 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), in wx_rx_hash()
518 * wx_rx_checksum - indicate in skb if hw indicated a good cksum
531 if (!(ring->netdev->features & NETIF_F_RXCSUM)) in wx_rx_checksum()
539 ring->rx_stats.csum_err++; in wx_rx_checksum()
553 ring->rx_stats.csum_err++; in wx_rx_checksum()
558 skb->ip_summed = CHECKSUM_UNNECESSARY; in wx_rx_checksum()
566 ring->rx_stats.csum_good_cnt++; in wx_rx_checksum()
575 if ((ring->netdev->features & in wx_rx_vlan()
578 idx = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & in wx_rx_vlan()
580 ethertype = ring->q_vector->wx->tpid[idx]; in wx_rx_vlan()
582 le16_to_cpu(rx_desc->wb.upper.vlan)); in wx_rx_vlan()
587 * wx_process_skb_fields - Populate skb header fields from Rx descriptor
589 * @rx_desc: pointer to the EOP Rx descriptor
603 skb_record_rx_queue(skb, rx_ring->queue_index); in wx_process_skb_fields()
604 skb->protocol = eth_type_trans(skb, rx_ring->netdev); in wx_process_skb_fields()
608 * wx_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
639 rx_desc = WX_RX_DESC(rx_ring, rx_ring->next_to_clean); in wx_clean_rx_irq()
656 rx_ring->rx_stats.alloc_rx_buff_failed++; in wx_clean_rx_irq()
672 total_rx_bytes += skb->len; in wx_clean_rx_irq()
676 napi_gro_receive(&q_vector->napi, skb); in wx_clean_rx_irq()
682 u64_stats_update_begin(&rx_ring->syncp); in wx_clean_rx_irq()
683 rx_ring->stats.packets += total_rx_packets; in wx_clean_rx_irq()
684 rx_ring->stats.bytes += total_rx_bytes; in wx_clean_rx_irq()
685 u64_stats_update_end(&rx_ring->syncp); in wx_clean_rx_irq()
686 q_vector->rx.total_packets += total_rx_packets; in wx_clean_rx_irq()
687 q_vector->rx.total_bytes += total_rx_bytes; in wx_clean_rx_irq()
694 return netdev_get_tx_queue(ring->netdev, ring->queue_index); in wx_txring_txq()
698 * wx_clean_tx_irq - Reclaim resources after transmit completes
706 unsigned int budget = q_vector->wx->tx_work_limit; in wx_clean_tx_irq()
708 unsigned int i = tx_ring->next_to_clean; in wx_clean_tx_irq()
712 if (!netif_carrier_ok(tx_ring->netdev)) in wx_clean_tx_irq()
715 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_clean_tx_irq()
717 i -= tx_ring->count; in wx_clean_tx_irq()
720 union wx_tx_desc *eop_desc = tx_buffer->next_to_watch; in wx_clean_tx_irq()
730 if (!(eop_desc->wb.status & cpu_to_le32(WX_TXD_STAT_DD))) in wx_clean_tx_irq()
734 tx_buffer->next_to_watch = NULL; in wx_clean_tx_irq()
737 total_bytes += tx_buffer->bytecount; in wx_clean_tx_irq()
738 total_packets += tx_buffer->gso_segs; in wx_clean_tx_irq()
741 napi_consume_skb(tx_buffer->skb, napi_budget); in wx_clean_tx_irq()
744 dma_unmap_single(tx_ring->dev, in wx_clean_tx_irq()
758 i -= tx_ring->count; in wx_clean_tx_irq()
759 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_irq()
765 dma_unmap_page(tx_ring->dev, in wx_clean_tx_irq()
778 i -= tx_ring->count; in wx_clean_tx_irq()
779 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_irq()
787 budget--; in wx_clean_tx_irq()
790 i += tx_ring->count; in wx_clean_tx_irq()
791 tx_ring->next_to_clean = i; in wx_clean_tx_irq()
792 u64_stats_update_begin(&tx_ring->syncp); in wx_clean_tx_irq()
793 tx_ring->stats.bytes += total_bytes; in wx_clean_tx_irq()
794 tx_ring->stats.packets += total_packets; in wx_clean_tx_irq()
795 u64_stats_update_end(&tx_ring->syncp); in wx_clean_tx_irq()
796 q_vector->tx.total_bytes += total_bytes; in wx_clean_tx_irq()
797 q_vector->tx.total_packets += total_packets; in wx_clean_tx_irq()
803 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && in wx_clean_tx_irq()
810 if (__netif_subqueue_stopped(tx_ring->netdev, in wx_clean_tx_irq()
811 tx_ring->queue_index) && in wx_clean_tx_irq()
812 netif_running(tx_ring->netdev)) { in wx_clean_tx_irq()
813 netif_wake_subqueue(tx_ring->netdev, in wx_clean_tx_irq()
814 tx_ring->queue_index); in wx_clean_tx_irq()
815 ++tx_ring->tx_stats.restart_queue; in wx_clean_tx_irq()
823 * wx_poll - NAPI polling RX/TX cleanup routine
833 struct wx *wx = q_vector->wx; in wx_poll()
837 wx_for_each_ring(ring, q_vector->tx) { in wx_poll()
849 if (q_vector->rx.count > 1) in wx_poll()
850 per_ring_budget = max(budget / q_vector->rx.count, 1); in wx_poll()
854 wx_for_each_ring(ring, q_vector->rx) { in wx_poll()
868 if (netif_running(wx->netdev)) in wx_poll()
869 wx_intr_enable(wx, WX_INTR_Q(q_vector->v_idx)); in wx_poll()
872 return min(work_done, budget - 1); in wx_poll()
880 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); in wx_maybe_stop_tx()
889 return -EBUSY; in wx_maybe_stop_tx()
891 /* A reprieve! - use start_queue because it doesn't call schedule */ in wx_maybe_stop_tx()
892 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); in wx_maybe_stop_tx()
893 ++tx_ring->tx_stats.restart_queue; in wx_maybe_stop_tx()
932 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); in wx_tx_olinfo_status()
939 struct sk_buff *skb = first->skb; in wx_tx_map()
941 u32 tx_flags = first->tx_flags; in wx_tx_map()
942 u16 i = tx_ring->next_to_use; in wx_tx_map()
951 wx_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); in wx_tx_map()
954 data_len = skb->data_len; in wx_tx_map()
955 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); in wx_tx_map()
959 for (frag = &skb_shinfo(skb)->frags[0];; frag++) { in wx_tx_map()
960 if (dma_mapping_error(tx_ring->dev, dma)) in wx_tx_map()
967 tx_desc->read.buffer_addr = cpu_to_le64(dma); in wx_tx_map()
970 tx_desc->read.cmd_type_len = in wx_tx_map()
975 if (i == tx_ring->count) { in wx_tx_map()
979 tx_desc->read.olinfo_status = 0; in wx_tx_map()
982 size -= WX_MAX_DATA_PER_TXD; in wx_tx_map()
984 tx_desc->read.buffer_addr = cpu_to_le64(dma); in wx_tx_map()
990 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); in wx_tx_map()
994 if (i == tx_ring->count) { in wx_tx_map()
998 tx_desc->read.olinfo_status = 0; in wx_tx_map()
1002 data_len -= size; in wx_tx_map()
1004 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, in wx_tx_map()
1007 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_tx_map()
1010 /* write last descriptor with RS and EOP bits */ in wx_tx_map()
1012 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); in wx_tx_map()
1014 netdev_tx_sent_queue(wx_txring_txq(tx_ring), first->bytecount); in wx_tx_map()
1019 * are new descriptors to fetch. (Only applicable for weak-ordered in wx_tx_map()
1020 * memory model archs, such as IA-64). in wx_tx_map()
1028 first->next_to_watch = tx_desc; in wx_tx_map()
1031 if (i == tx_ring->count) in wx_tx_map()
1034 tx_ring->next_to_use = i; in wx_tx_map()
1039 writel(i, tx_ring->tail); in wx_tx_map()
1043 dev_err(tx_ring->dev, "TX DMA map failed\n"); in wx_tx_map()
1047 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_tx_map()
1049 dma_unmap_page(tx_ring->dev, in wx_tx_map()
1057 i += tx_ring->count; in wx_tx_map()
1058 i--; in wx_tx_map()
1061 dev_kfree_skb_any(first->skb); in wx_tx_map()
1062 first->skb = NULL; in wx_tx_map()
1064 tx_ring->next_to_use = i; in wx_tx_map()
1071 u16 i = tx_ring->next_to_use; in wx_tx_ctxtdesc()
1075 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; in wx_tx_ctxtdesc()
1079 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); in wx_tx_ctxtdesc()
1080 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); in wx_tx_ctxtdesc()
1081 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); in wx_tx_ctxtdesc()
1082 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); in wx_tx_ctxtdesc()
1087 struct ipv6hdr *hdr = (struct ipv6hdr *)(skb->data + offset); in wx_get_ipv6_proto()
1089 *nexthdr = hdr->nexthdr; in wx_get_ipv6_proto()
1101 *nexthdr = hp->nexthdr; in wx_get_ipv6_proto()
1114 struct sk_buff *skb = first->skb; in wx_encode_tx_desc_ptype()
1116 if (skb->encapsulation) { in wx_encode_tx_desc_ptype()
1119 switch (first->protocol) { in wx_encode_tx_desc_ptype()
1121 tun_prot = ip_hdr(skb)->protocol; in wx_encode_tx_desc_ptype()
1137 if (skb->inner_protocol_type != ENCAP_TYPE_ETHER || in wx_encode_tx_desc_ptype()
1138 skb->inner_protocol != htons(ETH_P_TEB)) { in wx_encode_tx_desc_ptype()
1141 if (((struct ethhdr *)skb_inner_mac_header(skb))->h_proto in wx_encode_tx_desc_ptype()
1150 if (skb->inner_protocol == htons(ETH_P_IP) || in wx_encode_tx_desc_ptype()
1151 skb->inner_protocol == htons(ETH_P_IPV6)) { in wx_encode_tx_desc_ptype()
1154 if (((struct ethhdr *)skb_inner_mac_header(skb))->h_proto in wx_encode_tx_desc_ptype()
1164 switch (hdr.ipv4->version) { in wx_encode_tx_desc_ptype()
1166 l4_prot = hdr.ipv4->protocol; in wx_encode_tx_desc_ptype()
1176 switch (first->protocol) { in wx_encode_tx_desc_ptype()
1178 l4_prot = ip_hdr(skb)->protocol; in wx_encode_tx_desc_ptype()
1211 struct net_device *netdev = tx_ring->netdev; in wx_tso()
1213 struct sk_buff *skb = first->skb; in wx_tso()
1214 bool enc = skb->encapsulation; in wx_tso()
1221 if (skb->ip_summed != CHECKSUM_PARTIAL) in wx_tso()
1233 if (iph->version == 4) { in wx_tso()
1235 iph->tot_len = 0; in wx_tso()
1236 iph->check = 0; in wx_tso()
1237 tcph->check = ~csum_tcpudp_magic(iph->saddr, in wx_tso()
1238 iph->daddr, 0, in wx_tso()
1240 first->tx_flags |= WX_TX_FLAGS_TSO | in wx_tso()
1244 } else if (iph->version == 6 && skb_is_gso_v6(skb)) { in wx_tso()
1247 ipv6h->payload_len = 0; in wx_tso()
1248 tcph->check = ~csum_ipv6_magic(&ipv6h->saddr, in wx_tso()
1249 &ipv6h->daddr, 0, in wx_tso()
1251 first->tx_flags |= WX_TX_FLAGS_TSO | in wx_tso()
1263 first->gso_segs = skb_shinfo(skb)->gso_segs; in wx_tso()
1264 first->bytecount += (first->gso_segs - 1) * *hdr_len; in wx_tso()
1268 mss_l4len_idx |= skb_shinfo(skb)->gso_size << WX_TXD_MSS_SHIFT; in wx_tso()
1272 switch (first->protocol) { in wx_tso()
1274 tun_prot = ip_hdr(skb)->protocol; in wx_tso()
1275 first->tx_flags |= WX_TX_FLAGS_OUTER_IPV4; in wx_tso()
1278 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_tso()
1288 (((skb_inner_mac_header(skb) - in wx_tso()
1296 (((skb_inner_mac_header(skb) - in wx_tso()
1301 tunhdr_eiplen_tunlen = (((char *)inner_ip_hdr(skb) - in wx_tso()
1314 vlan_macip_lens |= first->tx_flags & WX_TX_FLAGS_VLAN_MASK; in wx_tso()
1317 if (skb->vlan_proto == htons(ETH_P_8021AD) && in wx_tso()
1318 netdev->features & NETIF_F_HW_VLAN_STAG_TX) in wx_tso()
1319 type_tucmd |= WX_SET_FLAG(first->tx_flags, in wx_tso()
1332 struct net_device *netdev = tx_ring->netdev; in wx_tx_csum()
1334 struct sk_buff *skb = first->skb; in wx_tx_csum()
1337 if (skb->ip_summed != CHECKSUM_PARTIAL) { in wx_tx_csum()
1338 if (!(first->tx_flags & WX_TX_FLAGS_HW_VLAN) && in wx_tx_csum()
1339 !(first->tx_flags & WX_TX_FLAGS_CC)) in wx_tx_csum()
1355 if (skb->encapsulation) { in wx_tx_csum()
1360 switch (first->protocol) { in wx_tx_csum()
1362 tun_prot = ip_hdr(skb)->protocol; in wx_tx_csum()
1365 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_tx_csum()
1376 (((skb_inner_mac_header(skb) - in wx_tx_csum()
1384 (((skb_inner_mac_header(skb) - in wx_tx_csum()
1389 tunhdr_eiplen_tunlen = (((char *)inner_ip_hdr(skb) - in wx_tx_csum()
1404 switch (network_hdr.ipv4->version) { in wx_tx_csum()
1406 vlan_macip_lens |= (transport_hdr.raw - network_hdr.raw) >> 1; in wx_tx_csum()
1407 l4_prot = network_hdr.ipv4->protocol; in wx_tx_csum()
1410 vlan_macip_lens |= (transport_hdr.raw - network_hdr.raw) >> 1; in wx_tx_csum()
1411 l4_prot = network_hdr.ipv6->nexthdr; in wx_tx_csum()
1419 mss_l4len_idx = (transport_hdr.tcphdr->doff * 4) << in wx_tx_csum()
1435 first->tx_flags |= WX_TX_FLAGS_CSUM; in wx_tx_csum()
1437 first->tx_flags |= WX_TX_FLAGS_CC; in wx_tx_csum()
1439 vlan_macip_lens |= first->tx_flags & WX_TX_FLAGS_VLAN_MASK; in wx_tx_csum()
1442 if (skb->vlan_proto == htons(ETH_P_8021AD) && in wx_tx_csum()
1443 netdev->features & NETIF_F_HW_VLAN_STAG_TX) in wx_tx_csum()
1444 type_tucmd |= WX_SET_FLAG(first->tx_flags, in wx_tx_csum()
1454 struct wx *wx = netdev_priv(tx_ring->netdev); in wx_xmit_frame_ring()
1468 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) in wx_xmit_frame_ring()
1469 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)-> in wx_xmit_frame_ring()
1473 tx_ring->tx_stats.tx_busy++; in wx_xmit_frame_ring()
1478 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; in wx_xmit_frame_ring()
1479 first->skb = skb; in wx_xmit_frame_ring()
1480 first->bytecount = skb->len; in wx_xmit_frame_ring()
1481 first->gso_segs = 1; in wx_xmit_frame_ring()
1490 first->tx_flags = tx_flags; in wx_xmit_frame_ring()
1491 first->protocol = vlan_get_protocol(skb); in wx_xmit_frame_ring()
1501 if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags) && tx_ring->atr_sample_rate) in wx_xmit_frame_ring()
1502 wx->atr(tx_ring, first, ptype); in wx_xmit_frame_ring()
1508 dev_kfree_skb_any(first->skb); in wx_xmit_frame_ring()
1509 first->skb = NULL; in wx_xmit_frame_ring()
1517 unsigned int r_idx = skb->queue_mapping; in wx_xmit_frame()
1532 if (r_idx >= wx->num_tx_queues) in wx_xmit_frame()
1533 r_idx = r_idx % wx->num_tx_queues; in wx_xmit_frame()
1534 tx_ring = wx->tx_ring[r_idx]; in wx_xmit_frame()
1545 for (q_idx = 0; q_idx < wx->num_q_vectors; q_idx++) { in wx_napi_enable_all()
1546 q_vector = wx->q_vector[q_idx]; in wx_napi_enable_all()
1547 napi_enable(&q_vector->napi); in wx_napi_enable_all()
1557 for (q_idx = 0; q_idx < wx->num_q_vectors; q_idx++) { in wx_napi_disable_all()
1558 q_vector = wx->q_vector[q_idx]; in wx_napi_disable_all()
1559 napi_disable(&q_vector->napi); in wx_napi_disable_all()
1577 f = &wx->ring_feature[RING_F_RSS]; in wx_set_rss_queues()
1578 f->indices = f->limit; in wx_set_rss_queues()
1580 if (!(test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))) in wx_set_rss_queues()
1583 clear_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_rss_queues()
1589 if (f->indices > 1) { in wx_set_rss_queues()
1590 f = &wx->ring_feature[RING_F_FDIR]; in wx_set_rss_queues()
1592 f->indices = f->limit; in wx_set_rss_queues()
1594 if (!(test_bit(WX_FLAG_FDIR_PERFECT, wx->flags))) in wx_set_rss_queues()
1595 set_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_rss_queues()
1599 wx->num_rx_queues = f->indices; in wx_set_rss_queues()
1600 wx->num_tx_queues = f->indices; in wx_set_rss_queues()
1606 wx->num_rx_queues = 1; in wx_set_num_queues()
1607 wx->num_tx_queues = 1; in wx_set_num_queues()
1608 wx->queues_per_pool = 1; in wx_set_num_queues()
1614 * wx_acquire_msix_vectors - acquire MSI-X vectors
1617 * Attempts to acquire a suitable range of MSI-X vector interrupts. Will
1618 * return a negative error code if unable to acquire MSI-X vectors for any
1627 nvecs = max(wx->num_rx_queues, wx->num_tx_queues); in wx_acquire_msix_vectors()
1629 nvecs = min_t(int, nvecs, wx->mac.max_msix_vectors); in wx_acquire_msix_vectors()
1631 wx->msix_q_entries = kcalloc(nvecs, sizeof(struct msix_entry), in wx_acquire_msix_vectors()
1633 if (!wx->msix_q_entries) in wx_acquire_msix_vectors()
1634 return -ENOMEM; in wx_acquire_msix_vectors()
1636 /* One for non-queue interrupts */ in wx_acquire_msix_vectors()
1639 wx->msix_entry = kcalloc(1, sizeof(struct msix_entry), in wx_acquire_msix_vectors()
1641 if (!wx->msix_entry) { in wx_acquire_msix_vectors()
1642 kfree(wx->msix_q_entries); in wx_acquire_msix_vectors()
1643 wx->msix_q_entries = NULL; in wx_acquire_msix_vectors()
1644 return -ENOMEM; in wx_acquire_msix_vectors()
1647 nvecs = pci_alloc_irq_vectors_affinity(wx->pdev, nvecs, in wx_acquire_msix_vectors()
1652 wx_err(wx, "Failed to allocate MSI-X interrupts. Err: %d\n", nvecs); in wx_acquire_msix_vectors()
1653 kfree(wx->msix_q_entries); in wx_acquire_msix_vectors()
1654 wx->msix_q_entries = NULL; in wx_acquire_msix_vectors()
1655 kfree(wx->msix_entry); in wx_acquire_msix_vectors()
1656 wx->msix_entry = NULL; in wx_acquire_msix_vectors()
1660 wx->msix_entry->entry = 0; in wx_acquire_msix_vectors()
1661 wx->msix_entry->vector = pci_irq_vector(wx->pdev, 0); in wx_acquire_msix_vectors()
1662 nvecs -= 1; in wx_acquire_msix_vectors()
1664 wx->msix_q_entries[i].entry = i; in wx_acquire_msix_vectors()
1665 wx->msix_q_entries[i].vector = pci_irq_vector(wx->pdev, i + 1); in wx_acquire_msix_vectors()
1668 wx->num_q_vectors = nvecs; in wx_acquire_msix_vectors()
1674 * wx_set_interrupt_capability - set MSI-X or MSI if supported
1682 struct pci_dev *pdev = wx->pdev; in wx_set_interrupt_capability()
1685 /* We will try to get MSI-X interrupts first */ in wx_set_interrupt_capability()
1687 if (ret == 0 || (ret == -ENOMEM)) in wx_set_interrupt_capability()
1690 /* Disable RSS */ in wx_set_interrupt_capability()
1691 dev_warn(&wx->pdev->dev, "Disabling RSS support\n"); in wx_set_interrupt_capability()
1692 wx->ring_feature[RING_F_RSS].limit = 1; in wx_set_interrupt_capability()
1701 if (pdev->msi_enabled) in wx_set_interrupt_capability()
1710 pdev->irq = pci_irq_vector(pdev, 0); in wx_set_interrupt_capability()
1711 wx->num_q_vectors = 1; in wx_set_interrupt_capability()
1717 * wx_cache_ring_rss - Descriptor ring to register mapping for RSS
1720 * Cache the descriptor ring offsets for RSS, ATR, FCoE, and SR-IOV.
1727 for (i = 0; i < wx->num_rx_queues; i++) in wx_cache_ring_rss()
1728 wx->rx_ring[i]->reg_idx = i; in wx_cache_ring_rss()
1730 for (i = 0; i < wx->num_tx_queues; i++) in wx_cache_ring_rss()
1731 wx->tx_ring[i]->reg_idx = i; in wx_cache_ring_rss()
1736 ring->next = head->ring; in wx_add_ring()
1737 head->ring = ring; in wx_add_ring()
1738 head->count++; in wx_add_ring()
1742 * wx_alloc_q_vector - Allocate memory for a single interrupt vector
1751 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1768 return -ENOMEM; in wx_alloc_q_vector()
1771 netif_napi_add(wx->netdev, &q_vector->napi, in wx_alloc_q_vector()
1775 wx->q_vector[v_idx] = q_vector; in wx_alloc_q_vector()
1776 q_vector->wx = wx; in wx_alloc_q_vector()
1777 q_vector->v_idx = v_idx; in wx_alloc_q_vector()
1779 q_vector->numa_node = cpu_to_node(v_idx); in wx_alloc_q_vector()
1782 ring = q_vector->ring; in wx_alloc_q_vector()
1784 if (wx->mac.type == wx_mac_sp) in wx_alloc_q_vector()
1791 q_vector->itr = wx->tx_itr_setting ? in wx_alloc_q_vector()
1792 default_itr : wx->tx_itr_setting; in wx_alloc_q_vector()
1795 q_vector->itr = wx->rx_itr_setting ? in wx_alloc_q_vector()
1796 default_itr : wx->rx_itr_setting; in wx_alloc_q_vector()
1800 ring->dev = &wx->pdev->dev; in wx_alloc_q_vector()
1801 ring->netdev = wx->netdev; in wx_alloc_q_vector()
1804 ring->q_vector = q_vector; in wx_alloc_q_vector()
1807 wx_add_ring(ring, &q_vector->tx); in wx_alloc_q_vector()
1810 ring->count = wx->tx_ring_count; in wx_alloc_q_vector()
1812 ring->queue_index = txr_idx; in wx_alloc_q_vector()
1815 wx->tx_ring[txr_idx] = ring; in wx_alloc_q_vector()
1818 txr_count--; in wx_alloc_q_vector()
1827 ring->dev = &wx->pdev->dev; in wx_alloc_q_vector()
1828 ring->netdev = wx->netdev; in wx_alloc_q_vector()
1831 ring->q_vector = q_vector; in wx_alloc_q_vector()
1834 wx_add_ring(ring, &q_vector->rx); in wx_alloc_q_vector()
1837 ring->count = wx->rx_ring_count; in wx_alloc_q_vector()
1838 ring->queue_index = rxr_idx; in wx_alloc_q_vector()
1841 wx->rx_ring[rxr_idx] = ring; in wx_alloc_q_vector()
1844 rxr_count--; in wx_alloc_q_vector()
1855 * wx_free_q_vector - Free memory allocated for specific interrupt vector
1865 struct wx_q_vector *q_vector = wx->q_vector[v_idx]; in wx_free_q_vector()
1868 wx_for_each_ring(ring, q_vector->tx) in wx_free_q_vector()
1869 wx->tx_ring[ring->queue_index] = NULL; in wx_free_q_vector()
1871 wx_for_each_ring(ring, q_vector->rx) in wx_free_q_vector()
1872 wx->rx_ring[ring->queue_index] = NULL; in wx_free_q_vector()
1874 wx->q_vector[v_idx] = NULL; in wx_free_q_vector()
1875 netif_napi_del(&q_vector->napi); in wx_free_q_vector()
1880 * wx_alloc_q_vectors - Allocate memory for interrupt vectors
1884 * return -ENOMEM.
1889 unsigned int rxr_remaining = wx->num_rx_queues; in wx_alloc_q_vectors()
1890 unsigned int txr_remaining = wx->num_tx_queues; in wx_alloc_q_vectors()
1891 unsigned int q_vectors = wx->num_q_vectors; in wx_alloc_q_vectors()
1896 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx); in wx_alloc_q_vectors()
1897 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx); in wx_alloc_q_vectors()
1906 rxr_remaining -= rqpv; in wx_alloc_q_vectors()
1907 txr_remaining -= tqpv; in wx_alloc_q_vectors()
1915 wx->num_tx_queues = 0; in wx_alloc_q_vectors()
1916 wx->num_rx_queues = 0; in wx_alloc_q_vectors()
1917 wx->num_q_vectors = 0; in wx_alloc_q_vectors()
1919 while (v_idx--) in wx_alloc_q_vectors()
1922 return -ENOMEM; in wx_alloc_q_vectors()
1926 * wx_free_q_vectors - Free memory allocated for interrupt vectors
1935 int v_idx = wx->num_q_vectors; in wx_free_q_vectors()
1937 wx->num_tx_queues = 0; in wx_free_q_vectors()
1938 wx->num_rx_queues = 0; in wx_free_q_vectors()
1939 wx->num_q_vectors = 0; in wx_free_q_vectors()
1941 while (v_idx--) in wx_free_q_vectors()
1947 struct pci_dev *pdev = wx->pdev; in wx_reset_interrupt_capability()
1949 if (!pdev->msi_enabled && !pdev->msix_enabled) in wx_reset_interrupt_capability()
1952 if (pdev->msix_enabled) { in wx_reset_interrupt_capability()
1953 kfree(wx->msix_q_entries); in wx_reset_interrupt_capability()
1954 wx->msix_q_entries = NULL; in wx_reset_interrupt_capability()
1955 kfree(wx->msix_entry); in wx_reset_interrupt_capability()
1956 wx->msix_entry = NULL; in wx_reset_interrupt_capability()
1958 pci_free_irq_vectors(wx->pdev); in wx_reset_interrupt_capability()
1963 * wx_clear_interrupt_scheme - Clear the current interrupt scheme settings
1967 * to pre-load conditions
2009 if (q_vector->rx.ring || q_vector->tx.ring) in wx_msix_clean_rings()
2010 napi_schedule_irqoff(&q_vector->napi); in wx_msix_clean_rings()
2018 struct pci_dev *pdev = wx->pdev; in wx_free_irq()
2021 if (!(pdev->msix_enabled)) { in wx_free_irq()
2022 if (!wx->misc_irq_domain) in wx_free_irq()
2023 free_irq(pdev->irq, wx); in wx_free_irq()
2027 for (vector = 0; vector < wx->num_q_vectors; vector++) { in wx_free_irq()
2028 struct wx_q_vector *q_vector = wx->q_vector[vector]; in wx_free_irq()
2029 struct msix_entry *entry = &wx->msix_q_entries[vector]; in wx_free_irq()
2032 if (!q_vector->rx.ring && !q_vector->tx.ring) in wx_free_irq()
2035 free_irq(entry->vector, q_vector); in wx_free_irq()
2038 if (!wx->misc_irq_domain) in wx_free_irq()
2039 free_irq(wx->msix_entry->vector, wx); in wx_free_irq()
2044 * wx_setup_isb_resources - allocate interrupt status resources
2051 struct pci_dev *pdev = wx->pdev; in wx_setup_isb_resources()
2053 if (wx->isb_mem) in wx_setup_isb_resources()
2056 wx->isb_mem = dma_alloc_coherent(&pdev->dev, in wx_setup_isb_resources()
2058 &wx->isb_dma, in wx_setup_isb_resources()
2060 if (!wx->isb_mem) { in wx_setup_isb_resources()
2062 return -ENOMEM; in wx_setup_isb_resources()
2070 * wx_free_isb_resources - allocate all queues Rx resources
2077 struct pci_dev *pdev = wx->pdev; in wx_free_isb_resources()
2079 dma_free_coherent(&pdev->dev, sizeof(u32) * 4, in wx_free_isb_resources()
2080 wx->isb_mem, wx->isb_dma); in wx_free_isb_resources()
2081 wx->isb_mem = NULL; in wx_free_isb_resources()
2089 cur_tag = wx->isb_mem[WX_ISB_HEADER]; in wx_misc_isb()
2090 wx->isb_tag[idx] = cur_tag; in wx_misc_isb()
2092 return (__force u32)cpu_to_le32(wx->isb_mem[idx]); in wx_misc_isb()
2097 * wx_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
2099 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
2109 if (direction == -1) { in wx_set_ivar()
2130 * wx_write_eitr - write EITR register in hardware specific way
2139 struct wx *wx = q_vector->wx; in wx_write_eitr()
2140 int v_idx = q_vector->v_idx; in wx_write_eitr()
2143 if (wx->mac.type == wx_mac_sp) in wx_write_eitr()
2144 itr_reg = q_vector->itr & WX_SP_MAX_EITR; in wx_write_eitr()
2146 itr_reg = q_vector->itr & WX_EM_MAX_EITR; in wx_write_eitr()
2154 * wx_configure_vectors - Configure vectors for hardware
2157 * wx_configure_vectors sets up the hardware to properly generate MSI-X/MSI/INTx
2162 struct pci_dev *pdev = wx->pdev; in wx_configure_vectors()
2166 if (pdev->msix_enabled) { in wx_configure_vectors()
2169 /* use EIAM to auto-mask when MSI-X interrupt is asserted in wx_configure_vectors()
2174 /* legacy interrupts, use EIAM to auto-mask when reading EICR, in wx_configure_vectors()
2183 for (v_idx = 0; v_idx < wx->num_q_vectors; v_idx++) { in wx_configure_vectors()
2184 struct wx_q_vector *q_vector = wx->q_vector[v_idx]; in wx_configure_vectors()
2187 wx_for_each_ring(ring, q_vector->rx) in wx_configure_vectors()
2188 wx_set_ivar(wx, 0, ring->reg_idx, v_idx); in wx_configure_vectors()
2190 wx_for_each_ring(ring, q_vector->tx) in wx_configure_vectors()
2191 wx_set_ivar(wx, 1, ring->reg_idx, v_idx); in wx_configure_vectors()
2196 wx_set_ivar(wx, -1, 0, 0); in wx_configure_vectors()
2197 if (pdev->msix_enabled) in wx_configure_vectors()
2203 * wx_clean_rx_ring - Free Rx Buffers per Queue
2209 u16 i = rx_ring->next_to_clean; in wx_clean_rx_ring()
2211 rx_buffer = &rx_ring->rx_buffer_info[i]; in wx_clean_rx_ring()
2214 while (i != rx_ring->next_to_alloc) { in wx_clean_rx_ring()
2215 if (rx_buffer->skb) { in wx_clean_rx_ring()
2216 struct sk_buff *skb = rx_buffer->skb; in wx_clean_rx_ring()
2218 if (WX_CB(skb)->page_released) in wx_clean_rx_ring()
2219 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_clean_rx_ring()
2227 dma_sync_single_range_for_cpu(rx_ring->dev, in wx_clean_rx_ring()
2228 rx_buffer->dma, in wx_clean_rx_ring()
2229 rx_buffer->page_offset, in wx_clean_rx_ring()
2234 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_clean_rx_ring()
2238 if (i == rx_ring->count) { in wx_clean_rx_ring()
2240 rx_buffer = rx_ring->rx_buffer_info; in wx_clean_rx_ring()
2244 rx_ring->next_to_alloc = 0; in wx_clean_rx_ring()
2245 rx_ring->next_to_clean = 0; in wx_clean_rx_ring()
2246 rx_ring->next_to_use = 0; in wx_clean_rx_ring()
2250 * wx_clean_all_rx_rings - Free Rx Buffers for all queues
2257 for (i = 0; i < wx->num_rx_queues; i++) in wx_clean_all_rx_rings()
2258 wx_clean_rx_ring(wx->rx_ring[i]); in wx_clean_all_rx_rings()
2263 * wx_free_rx_resources - Free Rx Resources
2271 kvfree(rx_ring->rx_buffer_info); in wx_free_rx_resources()
2272 rx_ring->rx_buffer_info = NULL; in wx_free_rx_resources()
2275 if (!rx_ring->desc) in wx_free_rx_resources()
2278 dma_free_coherent(rx_ring->dev, rx_ring->size, in wx_free_rx_resources()
2279 rx_ring->desc, rx_ring->dma); in wx_free_rx_resources()
2281 rx_ring->desc = NULL; in wx_free_rx_resources()
2283 if (rx_ring->page_pool) { in wx_free_rx_resources()
2284 page_pool_destroy(rx_ring->page_pool); in wx_free_rx_resources()
2285 rx_ring->page_pool = NULL; in wx_free_rx_resources()
2290 * wx_free_all_rx_resources - Free Rx Resources for All Queues
2299 for (i = 0; i < wx->num_rx_queues; i++) in wx_free_all_rx_resources()
2300 wx_free_rx_resources(wx->rx_ring[i]); in wx_free_all_rx_resources()
2304 * wx_clean_tx_ring - Free Tx Buffers
2310 u16 i = tx_ring->next_to_clean; in wx_clean_tx_ring()
2312 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_clean_tx_ring()
2314 while (i != tx_ring->next_to_use) { in wx_clean_tx_ring()
2318 dev_kfree_skb_any(tx_buffer->skb); in wx_clean_tx_ring()
2321 dma_unmap_single(tx_ring->dev, in wx_clean_tx_ring()
2327 eop_desc = tx_buffer->next_to_watch; in wx_clean_tx_ring()
2335 if (unlikely(i == tx_ring->count)) { in wx_clean_tx_ring()
2337 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_ring()
2343 dma_unmap_page(tx_ring->dev, 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()
2361 tx_ring->next_to_use = 0; in wx_clean_tx_ring()
2362 tx_ring->next_to_clean = 0; in wx_clean_tx_ring()
2366 * wx_clean_all_tx_rings - Free Tx Buffers for all queues
2373 for (i = 0; i < wx->num_tx_queues; i++) in wx_clean_all_tx_rings()
2374 wx_clean_tx_ring(wx->tx_ring[i]); in wx_clean_all_tx_rings()
2379 * wx_free_tx_resources - Free Tx Resources per Queue
2387 kvfree(tx_ring->tx_buffer_info); in wx_free_tx_resources()
2388 tx_ring->tx_buffer_info = NULL; in wx_free_tx_resources()
2391 if (!tx_ring->desc) in wx_free_tx_resources()
2394 dma_free_coherent(tx_ring->dev, tx_ring->size, in wx_free_tx_resources()
2395 tx_ring->desc, tx_ring->dma); in wx_free_tx_resources()
2396 tx_ring->desc = NULL; in wx_free_tx_resources()
2400 * wx_free_all_tx_resources - Free Tx Resources for All Queues
2409 for (i = 0; i < wx->num_tx_queues; i++) in wx_free_all_tx_resources()
2410 wx_free_tx_resources(wx->tx_ring[i]); in wx_free_all_tx_resources()
2427 .pool_size = rx_ring->size, in wx_alloc_page_pool()
2428 .nid = dev_to_node(rx_ring->dev), in wx_alloc_page_pool()
2429 .dev = rx_ring->dev, in wx_alloc_page_pool()
2435 rx_ring->page_pool = page_pool_create(&pp_params); in wx_alloc_page_pool()
2436 if (IS_ERR(rx_ring->page_pool)) { in wx_alloc_page_pool()
2437 ret = PTR_ERR(rx_ring->page_pool); in wx_alloc_page_pool()
2438 rx_ring->page_pool = NULL; in wx_alloc_page_pool()
2445 * wx_setup_rx_resources - allocate Rx resources (Descriptors)
2452 struct device *dev = rx_ring->dev; in wx_setup_rx_resources()
2457 size = sizeof(struct wx_rx_buffer) * rx_ring->count; in wx_setup_rx_resources()
2459 if (rx_ring->q_vector) in wx_setup_rx_resources()
2460 numa_node = rx_ring->q_vector->numa_node; in wx_setup_rx_resources()
2462 rx_ring->rx_buffer_info = kvmalloc_node(size, GFP_KERNEL, numa_node); in wx_setup_rx_resources()
2463 if (!rx_ring->rx_buffer_info) in wx_setup_rx_resources()
2464 rx_ring->rx_buffer_info = kvmalloc(size, GFP_KERNEL); in wx_setup_rx_resources()
2465 if (!rx_ring->rx_buffer_info) in wx_setup_rx_resources()
2469 rx_ring->size = rx_ring->count * sizeof(union wx_rx_desc); in wx_setup_rx_resources()
2470 rx_ring->size = ALIGN(rx_ring->size, 4096); in wx_setup_rx_resources()
2473 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, in wx_setup_rx_resources()
2474 &rx_ring->dma, GFP_KERNEL); in wx_setup_rx_resources()
2475 if (!rx_ring->desc) { in wx_setup_rx_resources()
2477 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, in wx_setup_rx_resources()
2478 &rx_ring->dma, GFP_KERNEL); in wx_setup_rx_resources()
2481 if (!rx_ring->desc) in wx_setup_rx_resources()
2484 rx_ring->next_to_clean = 0; in wx_setup_rx_resources()
2485 rx_ring->next_to_use = 0; in wx_setup_rx_resources()
2489 dev_err(rx_ring->dev, "Page pool creation failed: %d\n", ret); in wx_setup_rx_resources()
2496 dma_free_coherent(dev, rx_ring->size, rx_ring->desc, rx_ring->dma); in wx_setup_rx_resources()
2498 kvfree(rx_ring->rx_buffer_info); in wx_setup_rx_resources()
2499 rx_ring->rx_buffer_info = NULL; in wx_setup_rx_resources()
2501 return -ENOMEM; in wx_setup_rx_resources()
2505 * wx_setup_all_rx_resources - allocate all queues Rx resources
2518 for (i = 0; i < wx->num_rx_queues; i++) { in wx_setup_all_rx_resources()
2519 err = wx_setup_rx_resources(wx->rx_ring[i]); in wx_setup_all_rx_resources()
2530 while (i--) in wx_setup_all_rx_resources()
2531 wx_free_rx_resources(wx->rx_ring[i]); in wx_setup_all_rx_resources()
2536 * wx_setup_tx_resources - allocate Tx resources (Descriptors)
2543 struct device *dev = tx_ring->dev; in wx_setup_tx_resources()
2548 size = sizeof(struct wx_tx_buffer) * tx_ring->count; in wx_setup_tx_resources()
2550 if (tx_ring->q_vector) in wx_setup_tx_resources()
2551 numa_node = tx_ring->q_vector->numa_node; in wx_setup_tx_resources()
2553 tx_ring->tx_buffer_info = kvmalloc_node(size, GFP_KERNEL, numa_node); in wx_setup_tx_resources()
2554 if (!tx_ring->tx_buffer_info) in wx_setup_tx_resources()
2555 tx_ring->tx_buffer_info = kvmalloc(size, GFP_KERNEL); in wx_setup_tx_resources()
2556 if (!tx_ring->tx_buffer_info) in wx_setup_tx_resources()
2560 tx_ring->size = tx_ring->count * sizeof(union wx_tx_desc); in wx_setup_tx_resources()
2561 tx_ring->size = ALIGN(tx_ring->size, 4096); in wx_setup_tx_resources()
2564 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, in wx_setup_tx_resources()
2565 &tx_ring->dma, GFP_KERNEL); in wx_setup_tx_resources()
2566 if (!tx_ring->desc) { in wx_setup_tx_resources()
2568 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, in wx_setup_tx_resources()
2569 &tx_ring->dma, GFP_KERNEL); in wx_setup_tx_resources()
2572 if (!tx_ring->desc) in wx_setup_tx_resources()
2575 tx_ring->next_to_use = 0; in wx_setup_tx_resources()
2576 tx_ring->next_to_clean = 0; in wx_setup_tx_resources()
2581 kvfree(tx_ring->tx_buffer_info); in wx_setup_tx_resources()
2582 tx_ring->tx_buffer_info = NULL; in wx_setup_tx_resources()
2584 return -ENOMEM; in wx_setup_tx_resources()
2588 * wx_setup_all_tx_resources - allocate all queues Tx resources
2601 for (i = 0; i < wx->num_tx_queues; i++) { in wx_setup_all_tx_resources()
2602 err = wx_setup_tx_resources(wx->tx_ring[i]); in wx_setup_all_tx_resources()
2613 while (i--) in wx_setup_all_tx_resources()
2614 wx_free_tx_resources(wx->tx_ring[i]); in wx_setup_all_tx_resources()
2648 * wx_get_stats64 - Get System Network Statistics
2662 for (i = 0; i < wx->num_rx_queues; i++) { in wx_get_stats64()
2663 struct wx_ring *ring = READ_ONCE(wx->rx_ring[i]); in wx_get_stats64()
2669 start = u64_stats_fetch_begin(&ring->syncp); in wx_get_stats64()
2670 packets = ring->stats.packets; in wx_get_stats64()
2671 bytes = ring->stats.bytes; in wx_get_stats64()
2672 } while (u64_stats_fetch_retry(&ring->syncp, start)); in wx_get_stats64()
2673 stats->rx_packets += packets; in wx_get_stats64()
2674 stats->rx_bytes += bytes; in wx_get_stats64()
2678 for (i = 0; i < wx->num_tx_queues; i++) { in wx_get_stats64()
2679 struct wx_ring *ring = READ_ONCE(wx->tx_ring[i]); in wx_get_stats64()
2685 start = u64_stats_fetch_begin(&ring->syncp); in wx_get_stats64()
2686 packets = ring->stats.packets; in wx_get_stats64()
2687 bytes = ring->stats.bytes; in wx_get_stats64()
2688 } while (u64_stats_fetch_retry(&ring->syncp, in wx_get_stats64()
2690 stats->tx_packets += packets; in wx_get_stats64()
2691 stats->tx_bytes += bytes; in wx_get_stats64()
2697 hwstats = &wx->stats; in wx_get_stats64()
2698 stats->rx_errors = hwstats->crcerrs + hwstats->rlec; in wx_get_stats64()
2699 stats->multicast = hwstats->qmprc; in wx_get_stats64()
2700 stats->rx_length_errors = hwstats->rlec; in wx_get_stats64()
2701 stats->rx_crc_errors = hwstats->crcerrs; in wx_get_stats64()
2707 netdev_features_t changed = netdev->features ^ features; in wx_set_features()
2714 wx->rss_enabled = true; in wx_set_features()
2717 wx->rss_enabled = false; in wx_set_features()
2720 netdev->features = features; in wx_set_features()
2722 if (wx->mac.type == wx_mac_sp && changed & NETIF_F_HW_VLAN_CTAG_RX) in wx_set_features()
2723 wx->do_reset(netdev); in wx_set_features()
2727 if (!(test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))) in wx_set_features()
2730 /* Check if Flow Director n-tuple support was enabled or disabled. If in wx_set_features()
2736 if (!(test_and_set_bit(WX_FLAG_FDIR_PERFECT, wx->flags))) in wx_set_features()
2739 clear_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_features()
2743 if (test_and_clear_bit(WX_FLAG_FDIR_PERFECT, wx->flags)) in wx_set_features()
2747 if (wx->ring_feature[RING_F_RSS].limit <= 1) in wx_set_features()
2750 set_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_features()
2755 wx->do_reset(netdev); in wx_set_features()
2773 netdev_features_t changed = netdev->features ^ features; in wx_fix_features()
2780 features |= netdev->features & NETIF_VLAN_STRIPPING_FEATURES; in wx_fix_features()
2789 features |= netdev->features & NETIF_VLAN_INSERTION_FEATURES; in wx_fix_features()
2798 features |= netdev->features & NETIF_VLAN_FILTERING_FEATURES; in wx_fix_features()
2817 if (new_tx_count != wx->tx_ring_count) { in wx_set_ring()
2818 for (i = 0; i < wx->num_tx_queues; i++) { in wx_set_ring()
2819 memcpy(&temp_ring[i], wx->tx_ring[i], in wx_set_ring()
2827 i--; in wx_set_ring()
2834 for (i = 0; i < wx->num_tx_queues; i++) { in wx_set_ring()
2835 wx_free_tx_resources(wx->tx_ring[i]); in wx_set_ring()
2837 memcpy(wx->tx_ring[i], &temp_ring[i], in wx_set_ring()
2841 wx->tx_ring_count = new_tx_count; in wx_set_ring()
2845 if (new_rx_count != wx->rx_ring_count) { in wx_set_ring()
2846 for (i = 0; i < wx->num_rx_queues; i++) { in wx_set_ring()
2847 memcpy(&temp_ring[i], wx->rx_ring[i], in wx_set_ring()
2855 i--; in wx_set_ring()
2862 for (i = 0; i < wx->num_rx_queues; i++) { in wx_set_ring()
2863 wx_free_rx_resources(wx->rx_ring[i]); in wx_set_ring()
2864 memcpy(wx->rx_ring[i], &temp_ring[i], in wx_set_ring()
2868 wx->rx_ring_count = new_rx_count; in wx_set_ring()