Lines Matching +full:disable +full:- +full:eop

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 - 2022 Beijing WangXun Technology Co., Ltd. */
33 /* L3: ip non-tunnel */
49 /* IPv4 --> IPv4/IPv6 */
61 /* IPv4 --> GRE/NAT --> NONE/IPv4/IPv6 */
74 /* IPv4 --> GRE/NAT --> MAC --> NONE/IPv4/IPv6 */
87 /* IPv4 --> GRE/NAT --> MAC+VLAN --> NONE/IPv4/IPv6 */
100 /* IPv6 --> IPv4/IPv6 */
112 /* IPv6 --> GRE/NAT -> NONE/IPv4/IPv6 */
125 /* IPv6 --> GRE/NAT -> MAC -> NONE/IPv4/IPv6 */
138 /* IPv6 --> GRE/NAT -> MAC--> NONE/IPv */
158 /* wx_test_staterr - tests bits in Rx descriptor status and error fields */
162 return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits); in wx_test_staterr()
168 struct sk_buff *skb = rx_buffer->skb; in wx_dma_sync_frag()
169 skb_frag_t *frag = &skb_shinfo(skb)->frags[0]; in wx_dma_sync_frag()
171 dma_sync_single_range_for_cpu(rx_ring->dev, in wx_dma_sync_frag()
172 WX_CB(skb)->dma, in wx_dma_sync_frag()
178 if (unlikely(WX_CB(skb)->page_released)) in wx_dma_sync_frag()
179 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_dma_sync_frag()
190 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; in wx_get_rx_buffer()
191 size = le16_to_cpu(rx_desc->wb.upper.length); in wx_get_rx_buffer()
194 *rx_buffer_pgcnt = page_count(rx_buffer->page); in wx_get_rx_buffer()
199 prefetchw(rx_buffer->page); in wx_get_rx_buffer()
200 *skb = rx_buffer->skb; in wx_get_rx_buffer()
204 * Only unmap it when EOP is reached in wx_get_rx_buffer()
215 dma_sync_single_range_for_cpu(rx_ring->dev, in wx_get_rx_buffer()
216 rx_buffer->dma, in wx_get_rx_buffer()
217 rx_buffer->page_offset, in wx_get_rx_buffer()
229 if (!IS_ERR(skb) && WX_CB(skb)->dma == rx_buffer->dma) in wx_put_rx_buffer()
231 WX_CB(skb)->page_released = true; in wx_put_rx_buffer()
234 rx_buffer->page = NULL; in wx_put_rx_buffer()
235 rx_buffer->skb = NULL; in wx_put_rx_buffer()
242 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); in wx_build_skb()
248 struct sk_buff *skb = rx_buffer->skb; in wx_build_skb()
251 void *page_addr = page_address(rx_buffer->page) + in wx_build_skb()
252 rx_buffer->page_offset; in wx_build_skb()
258 skb = napi_alloc_skb(&rx_ring->q_vector->napi, WX_RXBUFFER_256); in wx_build_skb()
262 /* we will be copying header into skb->data in in wx_build_skb()
266 prefetchw(skb->data); in wx_build_skb()
271 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, true); in wx_build_skb()
278 WX_CB(skb)->dma = rx_buffer->dma; in wx_build_skb()
280 skb_add_rx_frag(skb, 0, rx_buffer->page, in wx_build_skb()
281 rx_buffer->page_offset, in wx_build_skb()
286 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, in wx_build_skb()
287 rx_buffer->page_offset, size, truesize); in wx_build_skb()
293 rx_buffer->page_offset ^= truesize; in wx_build_skb()
296 rx_buffer->page_offset += truesize; in wx_build_skb()
305 struct page *page = bi->page; in wx_alloc_mapped_page()
312 page = page_pool_dev_alloc_pages(rx_ring->page_pool); in wx_alloc_mapped_page()
317 bi->page_dma = dma; in wx_alloc_mapped_page()
318 bi->page = page; in wx_alloc_mapped_page()
319 bi->page_offset = 0; in wx_alloc_mapped_page()
325 * wx_alloc_rx_buffers - Replace used receive buffers
331 u16 i = rx_ring->next_to_use; in wx_alloc_rx_buffers()
340 bi = &rx_ring->rx_buffer_info[i]; in wx_alloc_rx_buffers()
341 i -= rx_ring->count; in wx_alloc_rx_buffers()
348 dma_sync_single_range_for_device(rx_ring->dev, bi->dma, in wx_alloc_rx_buffers()
349 bi->page_offset, in wx_alloc_rx_buffers()
353 rx_desc->read.pkt_addr = in wx_alloc_rx_buffers()
354 cpu_to_le64(bi->page_dma + bi->page_offset); in wx_alloc_rx_buffers()
361 bi = rx_ring->rx_buffer_info; in wx_alloc_rx_buffers()
362 i -= rx_ring->count; in wx_alloc_rx_buffers()
366 rx_desc->wb.upper.status_error = 0; in wx_alloc_rx_buffers()
368 cleaned_count--; in wx_alloc_rx_buffers()
371 i += rx_ring->count; in wx_alloc_rx_buffers()
373 if (rx_ring->next_to_use != i) { in wx_alloc_rx_buffers()
374 rx_ring->next_to_use = i; in wx_alloc_rx_buffers()
376 rx_ring->next_to_alloc = i; in wx_alloc_rx_buffers()
380 * applicable for weak-ordered memory model archs, in wx_alloc_rx_buffers()
381 * such as IA-64). in wx_alloc_rx_buffers()
384 writel(i, rx_ring->tail); in wx_alloc_rx_buffers()
390 u16 ntc = ring->next_to_clean; in wx_desc_unused()
391 u16 ntu = ring->next_to_use; in wx_desc_unused()
393 return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; in wx_desc_unused()
397 * wx_is_non_eop - process handling of non-EOP buffers
402 * This function updates next to clean. If the buffer is an EOP buffer
405 * that this is in fact a non-EOP buffer.
411 u32 ntc = rx_ring->next_to_clean + 1; in wx_is_non_eop()
414 ntc = (ntc < rx_ring->count) ? ntc : 0; in wx_is_non_eop()
415 rx_ring->next_to_clean = ntc; in wx_is_non_eop()
423 rx_ring->rx_buffer_info[ntc].skb = skb; in wx_is_non_eop()
424 rx_ring->rx_stats.non_eop_descs++; in wx_is_non_eop()
431 skb_frag_t *frag = &skb_shinfo(skb)->frags[0]; in wx_pull_tail()
442 * 60 bytes if the skb->len is less than 60 for skb_pad. in wx_pull_tail()
444 pull_len = eth_get_headlen(skb->dev, va, WX_RXBUFFER_256); in wx_pull_tail()
452 skb->data_len -= pull_len; in wx_pull_tail()
453 skb->tail += pull_len; in wx_pull_tail()
457 * wx_cleanup_headers - Correct corrupted or empty headers
459 * @rx_desc: pointer to the EOP Rx descriptor
478 struct net_device *netdev = rx_ring->netdev; in wx_cleanup_headers()
483 !(netdev->features & NETIF_F_RXALL))) { in wx_cleanup_headers()
505 if (!(ring->netdev->features & NETIF_F_RXHASH)) in wx_rx_hash()
508 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & in wx_rx_hash()
514 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), in wx_rx_hash()
520 * wx_rx_checksum - indicate in skb if hw indicated a good cksum
533 if (!(ring->netdev->features & NETIF_F_RXCSUM)) in wx_rx_checksum()
541 ring->rx_stats.csum_err++; in wx_rx_checksum()
556 ring->rx_stats.csum_err++; in wx_rx_checksum()
561 skb->ip_summed = CHECKSUM_UNNECESSARY; in wx_rx_checksum()
569 ring->rx_stats.csum_good_cnt++; in wx_rx_checksum()
578 if ((ring->netdev->features & in wx_rx_vlan()
581 idx = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & in wx_rx_vlan()
583 ethertype = ring->q_vector->wx->tpid[idx]; in wx_rx_vlan()
585 le16_to_cpu(rx_desc->wb.upper.vlan)); in wx_rx_vlan()
590 * wx_process_skb_fields - Populate skb header fields from Rx descriptor
592 * @rx_desc: pointer to the EOP Rx descriptor
603 struct wx *wx = netdev_priv(rx_ring->netdev); in wx_process_skb_fields()
608 if (unlikely(test_bit(WX_FLAG_RX_HWTSTAMP_ENABLED, wx->flags)) && in wx_process_skb_fields()
610 wx_ptp_rx_hwtstamp(rx_ring->q_vector->wx, skb); in wx_process_skb_fields()
611 rx_ring->last_rx_timestamp = jiffies; in wx_process_skb_fields()
615 skb_record_rx_queue(skb, rx_ring->queue_index); in wx_process_skb_fields()
616 skb->protocol = eth_type_trans(skb, rx_ring->netdev); in wx_process_skb_fields()
620 * wx_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
651 rx_desc = WX_RX_DESC(rx_ring, rx_ring->next_to_clean); in wx_clean_rx_irq()
668 rx_ring->rx_stats.alloc_rx_buff_failed++; in wx_clean_rx_irq()
684 total_rx_bytes += skb->len; in wx_clean_rx_irq()
688 napi_gro_receive(&q_vector->napi, skb); in wx_clean_rx_irq()
694 u64_stats_update_begin(&rx_ring->syncp); in wx_clean_rx_irq()
695 rx_ring->stats.packets += total_rx_packets; in wx_clean_rx_irq()
696 rx_ring->stats.bytes += total_rx_bytes; in wx_clean_rx_irq()
697 u64_stats_update_end(&rx_ring->syncp); in wx_clean_rx_irq()
698 q_vector->rx.total_packets += total_rx_packets; in wx_clean_rx_irq()
699 q_vector->rx.total_bytes += total_rx_bytes; in wx_clean_rx_irq()
706 return netdev_get_tx_queue(ring->netdev, ring->queue_index); in wx_txring_txq()
710 * wx_clean_tx_irq - Reclaim resources after transmit completes
718 unsigned int budget = q_vector->wx->tx_work_limit; in wx_clean_tx_irq()
720 struct wx *wx = netdev_priv(tx_ring->netdev); in wx_clean_tx_irq()
721 unsigned int i = tx_ring->next_to_clean; in wx_clean_tx_irq()
725 if (!netif_carrier_ok(tx_ring->netdev)) in wx_clean_tx_irq()
728 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_clean_tx_irq()
730 i -= tx_ring->count; in wx_clean_tx_irq()
733 union wx_tx_desc *eop_desc = tx_buffer->next_to_watch; in wx_clean_tx_irq()
743 if (!(eop_desc->wb.status & cpu_to_le32(WX_TXD_STAT_DD))) in wx_clean_tx_irq()
747 tx_buffer->next_to_watch = NULL; in wx_clean_tx_irq()
750 total_bytes += tx_buffer->bytecount; in wx_clean_tx_irq()
751 total_packets += tx_buffer->gso_segs; in wx_clean_tx_irq()
754 if (unlikely(test_bit(WX_STATE_PTP_TX_IN_PROGRESS, wx->state)) && in wx_clean_tx_irq()
755 skb_shinfo(tx_buffer->skb)->tx_flags & SKBTX_IN_PROGRESS) in wx_clean_tx_irq()
756 ptp_schedule_worker(wx->ptp_clock, 0); in wx_clean_tx_irq()
759 napi_consume_skb(tx_buffer->skb, napi_budget); in wx_clean_tx_irq()
762 dma_unmap_single(tx_ring->dev, in wx_clean_tx_irq()
776 i -= tx_ring->count; in wx_clean_tx_irq()
777 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_irq()
783 dma_unmap_page(tx_ring->dev, in wx_clean_tx_irq()
796 i -= tx_ring->count; in wx_clean_tx_irq()
797 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_irq()
805 budget--; in wx_clean_tx_irq()
808 i += tx_ring->count; in wx_clean_tx_irq()
809 tx_ring->next_to_clean = i; in wx_clean_tx_irq()
810 u64_stats_update_begin(&tx_ring->syncp); in wx_clean_tx_irq()
811 tx_ring->stats.bytes += total_bytes; in wx_clean_tx_irq()
812 tx_ring->stats.packets += total_packets; in wx_clean_tx_irq()
813 u64_stats_update_end(&tx_ring->syncp); in wx_clean_tx_irq()
814 q_vector->tx.total_bytes += total_bytes; in wx_clean_tx_irq()
815 q_vector->tx.total_packets += total_packets; in wx_clean_tx_irq()
821 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && in wx_clean_tx_irq()
828 if (__netif_subqueue_stopped(tx_ring->netdev, in wx_clean_tx_irq()
829 tx_ring->queue_index) && in wx_clean_tx_irq()
830 netif_running(tx_ring->netdev)) { in wx_clean_tx_irq()
831 netif_wake_subqueue(tx_ring->netdev, in wx_clean_tx_irq()
832 tx_ring->queue_index); in wx_clean_tx_irq()
833 ++tx_ring->tx_stats.restart_queue; in wx_clean_tx_irq()
841 * wx_poll - NAPI polling RX/TX cleanup routine
851 struct wx *wx = q_vector->wx; in wx_poll()
855 wx_for_each_ring(ring, q_vector->tx) { in wx_poll()
867 if (q_vector->rx.count > 1) in wx_poll()
868 per_ring_budget = max(budget / q_vector->rx.count, 1); in wx_poll()
872 wx_for_each_ring(ring, q_vector->rx) { in wx_poll()
886 if (netif_running(wx->netdev)) in wx_poll()
887 wx_intr_enable(wx, WX_INTR_Q(q_vector->v_idx)); in wx_poll()
890 return min(work_done, budget - 1); in wx_poll()
898 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); in wx_maybe_stop_tx()
907 return -EBUSY; in wx_maybe_stop_tx()
909 /* A reprieve! - use start_queue because it doesn't call schedule */ in wx_maybe_stop_tx()
910 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); in wx_maybe_stop_tx()
911 ++tx_ring->tx_stats.restart_queue; in wx_maybe_stop_tx()
950 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); in wx_tx_olinfo_status()
957 struct sk_buff *skb = first->skb; in wx_tx_map()
959 u32 tx_flags = first->tx_flags; in wx_tx_map()
960 u16 i = tx_ring->next_to_use; in wx_tx_map()
969 wx_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); in wx_tx_map()
972 data_len = skb->data_len; in wx_tx_map()
973 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); in wx_tx_map()
977 for (frag = &skb_shinfo(skb)->frags[0];; frag++) { in wx_tx_map()
978 if (dma_mapping_error(tx_ring->dev, dma)) in wx_tx_map()
985 tx_desc->read.buffer_addr = cpu_to_le64(dma); in wx_tx_map()
988 tx_desc->read.cmd_type_len = in wx_tx_map()
993 if (i == tx_ring->count) { in wx_tx_map()
997 tx_desc->read.olinfo_status = 0; in wx_tx_map()
1000 size -= WX_MAX_DATA_PER_TXD; in wx_tx_map()
1002 tx_desc->read.buffer_addr = cpu_to_le64(dma); in wx_tx_map()
1008 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); in wx_tx_map()
1012 if (i == tx_ring->count) { in wx_tx_map()
1016 tx_desc->read.olinfo_status = 0; in wx_tx_map()
1020 data_len -= size; in wx_tx_map()
1022 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, in wx_tx_map()
1025 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_tx_map()
1028 /* write last descriptor with RS and EOP bits */ in wx_tx_map()
1030 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); in wx_tx_map()
1032 netdev_tx_sent_queue(wx_txring_txq(tx_ring), first->bytecount); in wx_tx_map()
1035 first->time_stamp = jiffies; in wx_tx_map()
1039 * are new descriptors to fetch. (Only applicable for weak-ordered in wx_tx_map()
1040 * memory model archs, such as IA-64). in wx_tx_map()
1048 first->next_to_watch = tx_desc; in wx_tx_map()
1051 if (i == tx_ring->count) in wx_tx_map()
1054 tx_ring->next_to_use = i; in wx_tx_map()
1059 writel(i, tx_ring->tail); in wx_tx_map()
1063 dev_err(tx_ring->dev, "TX DMA map failed\n"); in wx_tx_map()
1067 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_tx_map()
1069 dma_unmap_page(tx_ring->dev, in wx_tx_map()
1077 i += tx_ring->count; in wx_tx_map()
1078 i--; in wx_tx_map()
1081 dev_kfree_skb_any(first->skb); in wx_tx_map()
1082 first->skb = NULL; in wx_tx_map()
1084 tx_ring->next_to_use = i; in wx_tx_map()
1086 return -ENOMEM; in wx_tx_map()
1093 u16 i = tx_ring->next_to_use; in wx_tx_ctxtdesc()
1097 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; in wx_tx_ctxtdesc()
1101 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); in wx_tx_ctxtdesc()
1102 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); in wx_tx_ctxtdesc()
1103 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); in wx_tx_ctxtdesc()
1104 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); in wx_tx_ctxtdesc()
1116 struct sk_buff *skb = first->skb; in wx_encode_tx_desc_ptype()
1120 if (skb->encapsulation) { in wx_encode_tx_desc_ptype()
1123 switch (first->protocol) { in wx_encode_tx_desc_ptype()
1125 tun_prot = ip_hdr(skb)->protocol; in wx_encode_tx_desc_ptype()
1131 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_encode_tx_desc_ptype()
1133 ipv6_skip_exthdr(skb, exthdr - skb->data, &tun_prot, &frag_off); in wx_encode_tx_desc_ptype()
1145 if (skb->inner_protocol_type != ENCAP_TYPE_ETHER || in wx_encode_tx_desc_ptype()
1146 skb->inner_protocol != htons(ETH_P_TEB)) { in wx_encode_tx_desc_ptype()
1149 if (((struct ethhdr *)skb_inner_mac_header(skb))->h_proto in wx_encode_tx_desc_ptype()
1158 if (skb->inner_protocol == htons(ETH_P_IP) || in wx_encode_tx_desc_ptype()
1159 skb->inner_protocol == htons(ETH_P_IPV6)) { in wx_encode_tx_desc_ptype()
1162 if (((struct ethhdr *)skb_inner_mac_header(skb))->h_proto in wx_encode_tx_desc_ptype()
1172 switch (hdr.ipv4->version) { in wx_encode_tx_desc_ptype()
1174 l4_prot = hdr.ipv4->protocol; in wx_encode_tx_desc_ptype()
1179 l4_prot = inner_ipv6_hdr(skb)->nexthdr; in wx_encode_tx_desc_ptype()
1181 ipv6_skip_exthdr(skb, exthdr - skb->data, &l4_prot, &frag_off); in wx_encode_tx_desc_ptype()
1188 switch (first->protocol) { in wx_encode_tx_desc_ptype()
1190 l4_prot = ip_hdr(skb)->protocol; in wx_encode_tx_desc_ptype()
1196 l4_prot = ipv6_hdr(skb)->nexthdr; in wx_encode_tx_desc_ptype()
1198 ipv6_skip_exthdr(skb, exthdr - skb->data, &l4_prot, &frag_off); in wx_encode_tx_desc_ptype()
1227 struct net_device *netdev = tx_ring->netdev; in wx_tso()
1229 struct sk_buff *skb = first->skb; in wx_tso()
1230 bool enc = skb->encapsulation; in wx_tso()
1237 if (skb->ip_summed != CHECKSUM_PARTIAL) in wx_tso()
1249 if (iph->version == 4) { in wx_tso()
1251 iph->tot_len = 0; in wx_tso()
1252 iph->check = 0; in wx_tso()
1253 tcph->check = ~csum_tcpudp_magic(iph->saddr, in wx_tso()
1254 iph->daddr, 0, in wx_tso()
1256 first->tx_flags |= WX_TX_FLAGS_TSO | in wx_tso()
1260 } else if (iph->version == 6 && skb_is_gso_v6(skb)) { in wx_tso()
1263 ipv6h->payload_len = 0; in wx_tso()
1264 tcph->check = ~csum_ipv6_magic(&ipv6h->saddr, in wx_tso()
1265 &ipv6h->daddr, 0, in wx_tso()
1267 first->tx_flags |= WX_TX_FLAGS_TSO | in wx_tso()
1279 first->gso_segs = skb_shinfo(skb)->gso_segs; in wx_tso()
1280 first->bytecount += (first->gso_segs - 1) * *hdr_len; in wx_tso()
1284 mss_l4len_idx |= skb_shinfo(skb)->gso_size << WX_TXD_MSS_SHIFT; in wx_tso()
1291 switch (first->protocol) { in wx_tso()
1293 tun_prot = ip_hdr(skb)->protocol; in wx_tso()
1294 first->tx_flags |= WX_TX_FLAGS_OUTER_IPV4; in wx_tso()
1299 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_tso()
1301 ipv6_skip_exthdr(skb, exthdr - skb->data, &tun_prot, &frag_off); in wx_tso()
1311 (((skb_inner_mac_header(skb) - in wx_tso()
1319 (((skb_inner_mac_header(skb) - in wx_tso()
1325 tunhdr_eiplen_tunlen = (((char *)inner_ip_hdr(skb) - in wx_tso()
1338 vlan_macip_lens |= first->tx_flags & WX_TX_FLAGS_VLAN_MASK; in wx_tso()
1341 if (skb->vlan_proto == htons(ETH_P_8021AD) && in wx_tso()
1342 netdev->features & NETIF_F_HW_VLAN_STAG_TX) in wx_tso()
1343 type_tucmd |= WX_SET_FLAG(first->tx_flags, in wx_tso()
1356 struct net_device *netdev = tx_ring->netdev; in wx_tx_csum()
1358 struct sk_buff *skb = first->skb; in wx_tx_csum()
1361 if (skb->ip_summed != CHECKSUM_PARTIAL) { in wx_tx_csum()
1363 if (!(first->tx_flags & WX_TX_FLAGS_HW_VLAN) && in wx_tx_csum()
1364 !(first->tx_flags & WX_TX_FLAGS_CC)) in wx_tx_csum()
1382 if (skb->encapsulation) { in wx_tx_csum()
1387 switch (first->protocol) { in wx_tx_csum()
1389 tun_prot = ip_hdr(skb)->protocol; in wx_tx_csum()
1394 tun_prot = ipv6_hdr(skb)->nexthdr; in wx_tx_csum()
1396 ipv6_skip_exthdr(skb, exthdr - skb->data, in wx_tx_csum()
1408 (((skb_inner_mac_header(skb) - in wx_tx_csum()
1416 (((skb_inner_mac_header(skb) - in wx_tx_csum()
1422 tunhdr_eiplen_tunlen = (((char *)inner_ip_hdr(skb) - in wx_tx_csum()
1437 switch (network_hdr.ipv4->version) { in wx_tx_csum()
1439 vlan_macip_lens |= (transport_hdr.raw - network_hdr.raw) >> 1; in wx_tx_csum()
1440 l4_prot = network_hdr.ipv4->protocol; in wx_tx_csum()
1443 vlan_macip_lens |= (transport_hdr.raw - network_hdr.raw) >> 1; in wx_tx_csum()
1445 l4_prot = network_hdr.ipv6->nexthdr; in wx_tx_csum()
1447 ipv6_skip_exthdr(skb, exthdr - skb->data, &l4_prot, &frag_off); in wx_tx_csum()
1455 mss_l4len_idx = (transport_hdr.tcphdr->doff * 4) << in wx_tx_csum()
1472 first->tx_flags |= WX_TX_FLAGS_CSUM; in wx_tx_csum()
1474 first->tx_flags |= WX_TX_FLAGS_CC; in wx_tx_csum()
1476 vlan_macip_lens |= first->tx_flags & WX_TX_FLAGS_VLAN_MASK; in wx_tx_csum()
1479 if (skb->vlan_proto == htons(ETH_P_8021AD) && in wx_tx_csum()
1480 netdev->features & NETIF_F_HW_VLAN_STAG_TX) in wx_tx_csum()
1481 type_tucmd |= WX_SET_FLAG(first->tx_flags, in wx_tx_csum()
1491 struct wx *wx = netdev_priv(tx_ring->netdev); in wx_xmit_frame_ring()
1505 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) in wx_xmit_frame_ring()
1506 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)-> in wx_xmit_frame_ring()
1510 tx_ring->tx_stats.tx_busy++; in wx_xmit_frame_ring()
1515 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; in wx_xmit_frame_ring()
1516 first->skb = skb; in wx_xmit_frame_ring()
1517 first->bytecount = skb->len; in wx_xmit_frame_ring()
1518 first->gso_segs = 1; in wx_xmit_frame_ring()
1526 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && in wx_xmit_frame_ring()
1527 wx->ptp_clock) { in wx_xmit_frame_ring()
1528 if (wx->tstamp_config.tx_type == HWTSTAMP_TX_ON && in wx_xmit_frame_ring()
1530 wx->state)) { in wx_xmit_frame_ring()
1531 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in wx_xmit_frame_ring()
1533 wx->ptp_tx_skb = skb_get(skb); in wx_xmit_frame_ring()
1534 wx->ptp_tx_start = jiffies; in wx_xmit_frame_ring()
1536 wx->tx_hwtstamp_skipped++; in wx_xmit_frame_ring()
1541 first->tx_flags = tx_flags; in wx_xmit_frame_ring()
1542 first->protocol = vlan_get_protocol(skb); in wx_xmit_frame_ring()
1552 if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags) && tx_ring->atr_sample_rate) in wx_xmit_frame_ring()
1553 wx->atr(tx_ring, first, ptype); in wx_xmit_frame_ring()
1560 dev_kfree_skb_any(first->skb); in wx_xmit_frame_ring()
1561 first->skb = NULL; in wx_xmit_frame_ring()
1564 dev_kfree_skb_any(wx->ptp_tx_skb); in wx_xmit_frame_ring()
1565 wx->ptp_tx_skb = NULL; in wx_xmit_frame_ring()
1566 wx->tx_hwtstamp_errors++; in wx_xmit_frame_ring()
1567 clear_bit_unlock(WX_STATE_PTP_TX_IN_PROGRESS, wx->state); in wx_xmit_frame_ring()
1576 unsigned int r_idx = skb->queue_mapping; in wx_xmit_frame()
1591 if (r_idx >= wx->num_tx_queues) in wx_xmit_frame()
1592 r_idx = r_idx % wx->num_tx_queues; in wx_xmit_frame()
1593 tx_ring = wx->tx_ring[r_idx]; in wx_xmit_frame()
1604 for (q_idx = 0; q_idx < wx->num_q_vectors; q_idx++) { in wx_napi_enable_all()
1605 q_vector = wx->q_vector[q_idx]; in wx_napi_enable_all()
1606 napi_enable(&q_vector->napi); in wx_napi_enable_all()
1616 for (q_idx = 0; q_idx < wx->num_q_vectors; q_idx++) { in wx_napi_disable_all()
1617 q_vector = wx->q_vector[q_idx]; in wx_napi_disable_all()
1618 napi_disable(&q_vector->napi); in wx_napi_disable_all()
1636 f = &wx->ring_feature[RING_F_RSS]; in wx_set_rss_queues()
1637 f->indices = f->limit; in wx_set_rss_queues()
1639 if (!(test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))) in wx_set_rss_queues()
1642 clear_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_rss_queues()
1648 if (f->indices > 1) { in wx_set_rss_queues()
1649 f = &wx->ring_feature[RING_F_FDIR]; in wx_set_rss_queues()
1651 f->indices = f->limit; in wx_set_rss_queues()
1653 if (!(test_bit(WX_FLAG_FDIR_PERFECT, wx->flags))) in wx_set_rss_queues()
1654 set_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_rss_queues()
1658 wx->num_rx_queues = f->indices; in wx_set_rss_queues()
1659 wx->num_tx_queues = f->indices; in wx_set_rss_queues()
1665 wx->num_rx_queues = 1; in wx_set_num_queues()
1666 wx->num_tx_queues = 1; in wx_set_num_queues()
1667 wx->queues_per_pool = 1; in wx_set_num_queues()
1673 * wx_acquire_msix_vectors - acquire MSI-X vectors
1676 * Attempts to acquire a suitable range of MSI-X vector interrupts. Will
1677 * return a negative error code if unable to acquire MSI-X vectors for any
1686 nvecs = max(wx->num_rx_queues, wx->num_tx_queues); in wx_acquire_msix_vectors()
1688 nvecs = min_t(int, nvecs, wx->mac.max_msix_vectors); in wx_acquire_msix_vectors()
1690 wx->msix_q_entries = kcalloc(nvecs, sizeof(struct msix_entry), in wx_acquire_msix_vectors()
1692 if (!wx->msix_q_entries) in wx_acquire_msix_vectors()
1693 return -ENOMEM; in wx_acquire_msix_vectors()
1695 /* One for non-queue interrupts */ in wx_acquire_msix_vectors()
1698 wx->msix_entry = kcalloc(1, sizeof(struct msix_entry), in wx_acquire_msix_vectors()
1700 if (!wx->msix_entry) { in wx_acquire_msix_vectors()
1701 kfree(wx->msix_q_entries); in wx_acquire_msix_vectors()
1702 wx->msix_q_entries = NULL; in wx_acquire_msix_vectors()
1703 return -ENOMEM; in wx_acquire_msix_vectors()
1706 nvecs = pci_alloc_irq_vectors_affinity(wx->pdev, nvecs, in wx_acquire_msix_vectors()
1711 wx_err(wx, "Failed to allocate MSI-X interrupts. Err: %d\n", nvecs); in wx_acquire_msix_vectors()
1712 kfree(wx->msix_q_entries); in wx_acquire_msix_vectors()
1713 wx->msix_q_entries = NULL; in wx_acquire_msix_vectors()
1714 kfree(wx->msix_entry); in wx_acquire_msix_vectors()
1715 wx->msix_entry = NULL; in wx_acquire_msix_vectors()
1719 wx->msix_entry->entry = 0; in wx_acquire_msix_vectors()
1720 wx->msix_entry->vector = pci_irq_vector(wx->pdev, 0); in wx_acquire_msix_vectors()
1721 nvecs -= 1; in wx_acquire_msix_vectors()
1723 wx->msix_q_entries[i].entry = i; in wx_acquire_msix_vectors()
1724 wx->msix_q_entries[i].vector = pci_irq_vector(wx->pdev, i + 1); in wx_acquire_msix_vectors()
1727 wx->num_q_vectors = nvecs; in wx_acquire_msix_vectors()
1733 * wx_set_interrupt_capability - set MSI-X or MSI if supported
1741 struct pci_dev *pdev = wx->pdev; in wx_set_interrupt_capability()
1744 /* We will try to get MSI-X interrupts first */ in wx_set_interrupt_capability()
1746 if (ret == 0 || (ret == -ENOMEM)) in wx_set_interrupt_capability()
1749 /* Disable RSS */ in wx_set_interrupt_capability()
1750 dev_warn(&wx->pdev->dev, "Disabling RSS support\n"); in wx_set_interrupt_capability()
1751 wx->ring_feature[RING_F_RSS].limit = 1; in wx_set_interrupt_capability()
1760 if (pdev->msi_enabled) in wx_set_interrupt_capability()
1769 pdev->irq = pci_irq_vector(pdev, 0); in wx_set_interrupt_capability()
1770 wx->num_q_vectors = 1; in wx_set_interrupt_capability()
1776 * wx_cache_ring_rss - Descriptor ring to register mapping for RSS
1779 * Cache the descriptor ring offsets for RSS, ATR, FCoE, and SR-IOV.
1786 for (i = 0; i < wx->num_rx_queues; i++) in wx_cache_ring_rss()
1787 wx->rx_ring[i]->reg_idx = i; in wx_cache_ring_rss()
1789 for (i = 0; i < wx->num_tx_queues; i++) in wx_cache_ring_rss()
1790 wx->tx_ring[i]->reg_idx = i; in wx_cache_ring_rss()
1795 ring->next = head->ring; in wx_add_ring()
1796 head->ring = ring; in wx_add_ring()
1797 head->count++; in wx_add_ring()
1801 * wx_alloc_q_vector - Allocate memory for a single interrupt vector
1810 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1827 return -ENOMEM; in wx_alloc_q_vector()
1830 netif_napi_add(wx->netdev, &q_vector->napi, in wx_alloc_q_vector()
1834 wx->q_vector[v_idx] = q_vector; in wx_alloc_q_vector()
1835 q_vector->wx = wx; in wx_alloc_q_vector()
1836 q_vector->v_idx = v_idx; in wx_alloc_q_vector()
1838 q_vector->numa_node = cpu_to_node(v_idx); in wx_alloc_q_vector()
1841 ring = q_vector->ring; in wx_alloc_q_vector()
1843 switch (wx->mac.type) { in wx_alloc_q_vector()
1856 q_vector->itr = wx->tx_itr_setting ? in wx_alloc_q_vector()
1857 default_itr : wx->tx_itr_setting; in wx_alloc_q_vector()
1860 q_vector->itr = wx->rx_itr_setting ? in wx_alloc_q_vector()
1861 default_itr : wx->rx_itr_setting; in wx_alloc_q_vector()
1865 ring->dev = &wx->pdev->dev; in wx_alloc_q_vector()
1866 ring->netdev = wx->netdev; in wx_alloc_q_vector()
1869 ring->q_vector = q_vector; in wx_alloc_q_vector()
1872 wx_add_ring(ring, &q_vector->tx); in wx_alloc_q_vector()
1875 ring->count = wx->tx_ring_count; in wx_alloc_q_vector()
1877 ring->queue_index = txr_idx; in wx_alloc_q_vector()
1880 wx->tx_ring[txr_idx] = ring; in wx_alloc_q_vector()
1883 txr_count--; in wx_alloc_q_vector()
1892 ring->dev = &wx->pdev->dev; in wx_alloc_q_vector()
1893 ring->netdev = wx->netdev; in wx_alloc_q_vector()
1896 ring->q_vector = q_vector; in wx_alloc_q_vector()
1899 wx_add_ring(ring, &q_vector->rx); in wx_alloc_q_vector()
1902 ring->count = wx->rx_ring_count; in wx_alloc_q_vector()
1903 ring->queue_index = rxr_idx; in wx_alloc_q_vector()
1906 wx->rx_ring[rxr_idx] = ring; in wx_alloc_q_vector()
1909 rxr_count--; in wx_alloc_q_vector()
1920 * wx_free_q_vector - Free memory allocated for specific interrupt vector
1930 struct wx_q_vector *q_vector = wx->q_vector[v_idx]; in wx_free_q_vector()
1933 wx_for_each_ring(ring, q_vector->tx) in wx_free_q_vector()
1934 wx->tx_ring[ring->queue_index] = NULL; in wx_free_q_vector()
1936 wx_for_each_ring(ring, q_vector->rx) in wx_free_q_vector()
1937 wx->rx_ring[ring->queue_index] = NULL; in wx_free_q_vector()
1939 wx->q_vector[v_idx] = NULL; in wx_free_q_vector()
1940 netif_napi_del(&q_vector->napi); in wx_free_q_vector()
1945 * wx_alloc_q_vectors - Allocate memory for interrupt vectors
1949 * return -ENOMEM.
1954 unsigned int rxr_remaining = wx->num_rx_queues; in wx_alloc_q_vectors()
1955 unsigned int txr_remaining = wx->num_tx_queues; in wx_alloc_q_vectors()
1956 unsigned int q_vectors = wx->num_q_vectors; in wx_alloc_q_vectors()
1961 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx); in wx_alloc_q_vectors()
1962 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx); in wx_alloc_q_vectors()
1971 rxr_remaining -= rqpv; in wx_alloc_q_vectors()
1972 txr_remaining -= tqpv; in wx_alloc_q_vectors()
1980 wx->num_tx_queues = 0; in wx_alloc_q_vectors()
1981 wx->num_rx_queues = 0; in wx_alloc_q_vectors()
1982 wx->num_q_vectors = 0; in wx_alloc_q_vectors()
1984 while (v_idx--) in wx_alloc_q_vectors()
1987 return -ENOMEM; in wx_alloc_q_vectors()
1991 * wx_free_q_vectors - Free memory allocated for interrupt vectors
2000 int v_idx = wx->num_q_vectors; in wx_free_q_vectors()
2002 wx->num_tx_queues = 0; in wx_free_q_vectors()
2003 wx->num_rx_queues = 0; in wx_free_q_vectors()
2004 wx->num_q_vectors = 0; in wx_free_q_vectors()
2006 while (v_idx--) in wx_free_q_vectors()
2012 struct pci_dev *pdev = wx->pdev; in wx_reset_interrupt_capability()
2014 if (!pdev->msi_enabled && !pdev->msix_enabled) in wx_reset_interrupt_capability()
2017 if (pdev->msix_enabled) { in wx_reset_interrupt_capability()
2018 kfree(wx->msix_q_entries); in wx_reset_interrupt_capability()
2019 wx->msix_q_entries = NULL; in wx_reset_interrupt_capability()
2020 kfree(wx->msix_entry); in wx_reset_interrupt_capability()
2021 wx->msix_entry = NULL; in wx_reset_interrupt_capability()
2023 pci_free_irq_vectors(wx->pdev); in wx_reset_interrupt_capability()
2028 * wx_clear_interrupt_scheme - Clear the current interrupt scheme settings
2032 * to pre-load conditions
2074 if (q_vector->rx.ring || q_vector->tx.ring) in wx_msix_clean_rings()
2075 napi_schedule_irqoff(&q_vector->napi); in wx_msix_clean_rings()
2083 struct pci_dev *pdev = wx->pdev; in wx_free_irq()
2086 if (!(pdev->msix_enabled)) { in wx_free_irq()
2087 if (!wx->misc_irq_domain) in wx_free_irq()
2088 free_irq(pdev->irq, wx); in wx_free_irq()
2092 for (vector = 0; vector < wx->num_q_vectors; vector++) { in wx_free_irq()
2093 struct wx_q_vector *q_vector = wx->q_vector[vector]; in wx_free_irq()
2094 struct msix_entry *entry = &wx->msix_q_entries[vector]; in wx_free_irq()
2097 if (!q_vector->rx.ring && !q_vector->tx.ring) in wx_free_irq()
2100 free_irq(entry->vector, q_vector); in wx_free_irq()
2103 if (!wx->misc_irq_domain) in wx_free_irq()
2104 free_irq(wx->msix_entry->vector, wx); in wx_free_irq()
2109 * wx_setup_isb_resources - allocate interrupt status resources
2116 struct pci_dev *pdev = wx->pdev; in wx_setup_isb_resources()
2118 if (wx->isb_mem) in wx_setup_isb_resources()
2121 wx->isb_mem = dma_alloc_coherent(&pdev->dev, in wx_setup_isb_resources()
2123 &wx->isb_dma, in wx_setup_isb_resources()
2125 if (!wx->isb_mem) { in wx_setup_isb_resources()
2127 return -ENOMEM; in wx_setup_isb_resources()
2135 * wx_free_isb_resources - allocate all queues Rx resources
2142 struct pci_dev *pdev = wx->pdev; in wx_free_isb_resources()
2144 dma_free_coherent(&pdev->dev, sizeof(u32) * 4, in wx_free_isb_resources()
2145 wx->isb_mem, wx->isb_dma); in wx_free_isb_resources()
2146 wx->isb_mem = NULL; in wx_free_isb_resources()
2154 cur_tag = wx->isb_mem[WX_ISB_HEADER]; in wx_misc_isb()
2155 wx->isb_tag[idx] = cur_tag; in wx_misc_isb()
2157 return (__force u32)cpu_to_le32(wx->isb_mem[idx]); in wx_misc_isb()
2162 * wx_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
2164 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
2174 if (direction == -1) { in wx_set_ivar()
2195 * wx_write_eitr - write EITR register in hardware specific way
2204 struct wx *wx = q_vector->wx; in wx_write_eitr()
2205 int v_idx = q_vector->v_idx; in wx_write_eitr()
2208 switch (wx->mac.type) { in wx_write_eitr()
2210 itr_reg = q_vector->itr & WX_SP_MAX_EITR; in wx_write_eitr()
2213 itr_reg = (q_vector->itr >> 3) & WX_AML_MAX_EITR; in wx_write_eitr()
2216 itr_reg = q_vector->itr & WX_EM_MAX_EITR; in wx_write_eitr()
2226 * wx_configure_vectors - Configure vectors for hardware
2229 * wx_configure_vectors sets up the hardware to properly generate MSI-X/MSI/INTx
2234 struct pci_dev *pdev = wx->pdev; in wx_configure_vectors()
2238 if (pdev->msix_enabled) { in wx_configure_vectors()
2241 /* use EIAM to auto-mask when MSI-X interrupt is asserted in wx_configure_vectors()
2246 /* legacy interrupts, use EIAM to auto-mask when reading EICR, in wx_configure_vectors()
2255 for (v_idx = 0; v_idx < wx->num_q_vectors; v_idx++) { in wx_configure_vectors()
2256 struct wx_q_vector *q_vector = wx->q_vector[v_idx]; in wx_configure_vectors()
2259 wx_for_each_ring(ring, q_vector->rx) in wx_configure_vectors()
2260 wx_set_ivar(wx, 0, ring->reg_idx, v_idx); in wx_configure_vectors()
2262 wx_for_each_ring(ring, q_vector->tx) in wx_configure_vectors()
2263 wx_set_ivar(wx, 1, ring->reg_idx, v_idx); in wx_configure_vectors()
2268 wx_set_ivar(wx, -1, 0, 0); in wx_configure_vectors()
2269 if (pdev->msix_enabled) in wx_configure_vectors()
2275 * wx_clean_rx_ring - Free Rx Buffers per Queue
2281 u16 i = rx_ring->next_to_clean; in wx_clean_rx_ring()
2283 rx_buffer = &rx_ring->rx_buffer_info[i]; in wx_clean_rx_ring()
2286 while (i != rx_ring->next_to_alloc) { in wx_clean_rx_ring()
2287 if (rx_buffer->skb) { in wx_clean_rx_ring()
2288 struct sk_buff *skb = rx_buffer->skb; in wx_clean_rx_ring()
2290 if (WX_CB(skb)->page_released) in wx_clean_rx_ring()
2291 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_clean_rx_ring()
2299 dma_sync_single_range_for_cpu(rx_ring->dev, in wx_clean_rx_ring()
2300 rx_buffer->dma, in wx_clean_rx_ring()
2301 rx_buffer->page_offset, in wx_clean_rx_ring()
2306 page_pool_put_full_page(rx_ring->page_pool, rx_buffer->page, false); in wx_clean_rx_ring()
2310 if (i == rx_ring->count) { in wx_clean_rx_ring()
2312 rx_buffer = rx_ring->rx_buffer_info; in wx_clean_rx_ring()
2316 rx_ring->next_to_alloc = 0; in wx_clean_rx_ring()
2317 rx_ring->next_to_clean = 0; in wx_clean_rx_ring()
2318 rx_ring->next_to_use = 0; in wx_clean_rx_ring()
2322 * wx_clean_all_rx_rings - Free Rx Buffers for all queues
2329 for (i = 0; i < wx->num_rx_queues; i++) in wx_clean_all_rx_rings()
2330 wx_clean_rx_ring(wx->rx_ring[i]); in wx_clean_all_rx_rings()
2335 * wx_free_rx_resources - Free Rx Resources
2343 kvfree(rx_ring->rx_buffer_info); in wx_free_rx_resources()
2344 rx_ring->rx_buffer_info = NULL; in wx_free_rx_resources()
2347 if (!rx_ring->desc) in wx_free_rx_resources()
2350 dma_free_coherent(rx_ring->dev, rx_ring->size, in wx_free_rx_resources()
2351 rx_ring->desc, rx_ring->dma); in wx_free_rx_resources()
2353 rx_ring->desc = NULL; in wx_free_rx_resources()
2355 if (rx_ring->page_pool) { in wx_free_rx_resources()
2356 page_pool_destroy(rx_ring->page_pool); in wx_free_rx_resources()
2357 rx_ring->page_pool = NULL; in wx_free_rx_resources()
2362 * wx_free_all_rx_resources - Free Rx Resources for All Queues
2371 for (i = 0; i < wx->num_rx_queues; i++) in wx_free_all_rx_resources()
2372 wx_free_rx_resources(wx->rx_ring[i]); in wx_free_all_rx_resources()
2376 * wx_clean_tx_ring - Free Tx Buffers
2382 u16 i = tx_ring->next_to_clean; in wx_clean_tx_ring()
2384 tx_buffer = &tx_ring->tx_buffer_info[i]; in wx_clean_tx_ring()
2386 while (i != tx_ring->next_to_use) { in wx_clean_tx_ring()
2390 dev_kfree_skb_any(tx_buffer->skb); in wx_clean_tx_ring()
2393 dma_unmap_single(tx_ring->dev, in wx_clean_tx_ring()
2399 eop_desc = tx_buffer->next_to_watch; in wx_clean_tx_ring()
2407 if (unlikely(i == tx_ring->count)) { in wx_clean_tx_ring()
2409 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_ring()
2415 dma_unmap_page(tx_ring->dev, in wx_clean_tx_ring()
2424 if (unlikely(i == tx_ring->count)) { in wx_clean_tx_ring()
2426 tx_buffer = tx_ring->tx_buffer_info; in wx_clean_tx_ring()
2433 tx_ring->next_to_use = 0; in wx_clean_tx_ring()
2434 tx_ring->next_to_clean = 0; in wx_clean_tx_ring()
2438 * wx_clean_all_tx_rings - Free Tx Buffers for all queues
2445 for (i = 0; i < wx->num_tx_queues; i++) in wx_clean_all_tx_rings()
2446 wx_clean_tx_ring(wx->tx_ring[i]); in wx_clean_all_tx_rings()
2451 * wx_free_tx_resources - Free Tx Resources per Queue
2459 kvfree(tx_ring->tx_buffer_info); in wx_free_tx_resources()
2460 tx_ring->tx_buffer_info = NULL; in wx_free_tx_resources()
2463 if (!tx_ring->desc) in wx_free_tx_resources()
2466 dma_free_coherent(tx_ring->dev, tx_ring->size, in wx_free_tx_resources()
2467 tx_ring->desc, tx_ring->dma); in wx_free_tx_resources()
2468 tx_ring->desc = NULL; in wx_free_tx_resources()
2472 * wx_free_all_tx_resources - Free Tx Resources for All Queues
2481 for (i = 0; i < wx->num_tx_queues; i++) in wx_free_all_tx_resources()
2482 wx_free_tx_resources(wx->tx_ring[i]); in wx_free_all_tx_resources()
2499 .pool_size = rx_ring->size, in wx_alloc_page_pool()
2500 .nid = dev_to_node(rx_ring->dev), in wx_alloc_page_pool()
2501 .dev = rx_ring->dev, in wx_alloc_page_pool()
2507 rx_ring->page_pool = page_pool_create(&pp_params); in wx_alloc_page_pool()
2508 if (IS_ERR(rx_ring->page_pool)) { in wx_alloc_page_pool()
2509 ret = PTR_ERR(rx_ring->page_pool); in wx_alloc_page_pool()
2510 rx_ring->page_pool = NULL; in wx_alloc_page_pool()
2517 * wx_setup_rx_resources - allocate Rx resources (Descriptors)
2524 struct device *dev = rx_ring->dev; in wx_setup_rx_resources()
2529 size = sizeof(struct wx_rx_buffer) * rx_ring->count; in wx_setup_rx_resources()
2531 if (rx_ring->q_vector) in wx_setup_rx_resources()
2532 numa_node = rx_ring->q_vector->numa_node; in wx_setup_rx_resources()
2534 rx_ring->rx_buffer_info = kvmalloc_node(size, GFP_KERNEL, numa_node); in wx_setup_rx_resources()
2535 if (!rx_ring->rx_buffer_info) in wx_setup_rx_resources()
2536 rx_ring->rx_buffer_info = kvmalloc(size, GFP_KERNEL); in wx_setup_rx_resources()
2537 if (!rx_ring->rx_buffer_info) in wx_setup_rx_resources()
2541 rx_ring->size = rx_ring->count * sizeof(union wx_rx_desc); in wx_setup_rx_resources()
2542 rx_ring->size = ALIGN(rx_ring->size, 4096); in wx_setup_rx_resources()
2545 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, in wx_setup_rx_resources()
2546 &rx_ring->dma, GFP_KERNEL); in wx_setup_rx_resources()
2547 if (!rx_ring->desc) { in wx_setup_rx_resources()
2549 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, in wx_setup_rx_resources()
2550 &rx_ring->dma, GFP_KERNEL); in wx_setup_rx_resources()
2553 if (!rx_ring->desc) in wx_setup_rx_resources()
2556 rx_ring->next_to_clean = 0; in wx_setup_rx_resources()
2557 rx_ring->next_to_use = 0; in wx_setup_rx_resources()
2561 dev_err(rx_ring->dev, "Page pool creation failed: %d\n", ret); in wx_setup_rx_resources()
2568 dma_free_coherent(dev, rx_ring->size, rx_ring->desc, rx_ring->dma); in wx_setup_rx_resources()
2570 kvfree(rx_ring->rx_buffer_info); in wx_setup_rx_resources()
2571 rx_ring->rx_buffer_info = NULL; in wx_setup_rx_resources()
2573 return -ENOMEM; in wx_setup_rx_resources()
2577 * wx_setup_all_rx_resources - allocate all queues Rx resources
2590 for (i = 0; i < wx->num_rx_queues; i++) { in wx_setup_all_rx_resources()
2591 err = wx_setup_rx_resources(wx->rx_ring[i]); in wx_setup_all_rx_resources()
2602 while (i--) in wx_setup_all_rx_resources()
2603 wx_free_rx_resources(wx->rx_ring[i]); in wx_setup_all_rx_resources()
2608 * wx_setup_tx_resources - allocate Tx resources (Descriptors)
2615 struct device *dev = tx_ring->dev; in wx_setup_tx_resources()
2620 size = sizeof(struct wx_tx_buffer) * tx_ring->count; in wx_setup_tx_resources()
2622 if (tx_ring->q_vector) in wx_setup_tx_resources()
2623 numa_node = tx_ring->q_vector->numa_node; in wx_setup_tx_resources()
2625 tx_ring->tx_buffer_info = kvmalloc_node(size, GFP_KERNEL, numa_node); in wx_setup_tx_resources()
2626 if (!tx_ring->tx_buffer_info) in wx_setup_tx_resources()
2627 tx_ring->tx_buffer_info = kvmalloc(size, GFP_KERNEL); in wx_setup_tx_resources()
2628 if (!tx_ring->tx_buffer_info) in wx_setup_tx_resources()
2632 tx_ring->size = tx_ring->count * sizeof(union wx_tx_desc); in wx_setup_tx_resources()
2633 tx_ring->size = ALIGN(tx_ring->size, 4096); in wx_setup_tx_resources()
2636 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, in wx_setup_tx_resources()
2637 &tx_ring->dma, GFP_KERNEL); in wx_setup_tx_resources()
2638 if (!tx_ring->desc) { in wx_setup_tx_resources()
2640 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, in wx_setup_tx_resources()
2641 &tx_ring->dma, GFP_KERNEL); in wx_setup_tx_resources()
2644 if (!tx_ring->desc) in wx_setup_tx_resources()
2647 tx_ring->next_to_use = 0; in wx_setup_tx_resources()
2648 tx_ring->next_to_clean = 0; in wx_setup_tx_resources()
2653 kvfree(tx_ring->tx_buffer_info); in wx_setup_tx_resources()
2654 tx_ring->tx_buffer_info = NULL; in wx_setup_tx_resources()
2656 return -ENOMEM; in wx_setup_tx_resources()
2660 * wx_setup_all_tx_resources - allocate all queues Tx resources
2673 for (i = 0; i < wx->num_tx_queues; i++) { in wx_setup_all_tx_resources()
2674 err = wx_setup_tx_resources(wx->tx_ring[i]); in wx_setup_all_tx_resources()
2685 while (i--) in wx_setup_all_tx_resources()
2686 wx_free_tx_resources(wx->tx_ring[i]); in wx_setup_all_tx_resources()
2720 * wx_get_stats64 - Get System Network Statistics
2734 for (i = 0; i < wx->num_rx_queues; i++) { in wx_get_stats64()
2735 struct wx_ring *ring = READ_ONCE(wx->rx_ring[i]); in wx_get_stats64()
2741 start = u64_stats_fetch_begin(&ring->syncp); in wx_get_stats64()
2742 packets = ring->stats.packets; in wx_get_stats64()
2743 bytes = ring->stats.bytes; in wx_get_stats64()
2744 } while (u64_stats_fetch_retry(&ring->syncp, start)); in wx_get_stats64()
2745 stats->rx_packets += packets; in wx_get_stats64()
2746 stats->rx_bytes += bytes; in wx_get_stats64()
2750 for (i = 0; i < wx->num_tx_queues; i++) { in wx_get_stats64()
2751 struct wx_ring *ring = READ_ONCE(wx->tx_ring[i]); in wx_get_stats64()
2757 start = u64_stats_fetch_begin(&ring->syncp); in wx_get_stats64()
2758 packets = ring->stats.packets; in wx_get_stats64()
2759 bytes = ring->stats.bytes; in wx_get_stats64()
2760 } while (u64_stats_fetch_retry(&ring->syncp, in wx_get_stats64()
2762 stats->tx_packets += packets; in wx_get_stats64()
2763 stats->tx_bytes += bytes; in wx_get_stats64()
2769 hwstats = &wx->stats; in wx_get_stats64()
2770 stats->rx_errors = hwstats->crcerrs + hwstats->rlec; in wx_get_stats64()
2771 stats->multicast = hwstats->qmprc; in wx_get_stats64()
2772 stats->rx_length_errors = hwstats->rlec; in wx_get_stats64()
2773 stats->rx_crc_errors = hwstats->crcerrs; in wx_get_stats64()
2779 netdev_features_t changed = netdev->features ^ features; in wx_set_features()
2786 wx->rss_enabled = true; in wx_set_features()
2789 wx->rss_enabled = false; in wx_set_features()
2792 netdev->features = features; in wx_set_features()
2794 if (changed & NETIF_F_HW_VLAN_CTAG_RX && wx->do_reset) in wx_set_features()
2795 wx->do_reset(netdev); in wx_set_features()
2799 if (!(test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))) in wx_set_features()
2802 /* Check if Flow Director n-tuple support was enabled or disabled. If in wx_set_features()
2808 if (!(test_and_set_bit(WX_FLAG_FDIR_PERFECT, wx->flags))) in wx_set_features()
2811 clear_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_features()
2815 if (test_and_clear_bit(WX_FLAG_FDIR_PERFECT, wx->flags)) in wx_set_features()
2819 if (wx->ring_feature[RING_F_RSS].limit <= 1) in wx_set_features()
2822 set_bit(WX_FLAG_FDIR_HASH, wx->flags); in wx_set_features()
2826 if (need_reset && wx->do_reset) in wx_set_features()
2827 wx->do_reset(netdev); in wx_set_features()
2845 netdev_features_t changed = netdev->features ^ features; in wx_fix_features()
2852 features |= netdev->features & NETIF_VLAN_STRIPPING_FEATURES; in wx_fix_features()
2861 features |= netdev->features & NETIF_VLAN_INSERTION_FEATURES; in wx_fix_features()
2870 features |= netdev->features & NETIF_VLAN_FILTERING_FEATURES; in wx_fix_features()
2889 if (new_tx_count != wx->tx_ring_count) { in wx_set_ring()
2890 for (i = 0; i < wx->num_tx_queues; i++) { in wx_set_ring()
2891 memcpy(&temp_ring[i], wx->tx_ring[i], in wx_set_ring()
2899 i--; in wx_set_ring()
2906 for (i = 0; i < wx->num_tx_queues; i++) { in wx_set_ring()
2907 wx_free_tx_resources(wx->tx_ring[i]); in wx_set_ring()
2909 memcpy(wx->tx_ring[i], &temp_ring[i], in wx_set_ring()
2913 wx->tx_ring_count = new_tx_count; in wx_set_ring()
2917 if (new_rx_count != wx->rx_ring_count) { in wx_set_ring()
2918 for (i = 0; i < wx->num_rx_queues; i++) { in wx_set_ring()
2919 memcpy(&temp_ring[i], wx->rx_ring[i], in wx_set_ring()
2927 i--; in wx_set_ring()
2934 for (i = 0; i < wx->num_rx_queues; i++) { in wx_set_ring()
2935 wx_free_rx_resources(wx->rx_ring[i]); in wx_set_ring()
2936 memcpy(wx->rx_ring[i], &temp_ring[i], in wx_set_ring()
2940 wx->rx_ring_count = new_rx_count; in wx_set_ring()