Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'net-6.17-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net

Pull networking fixes from Jakub Kicinski:
"Including fixes from netfilter, wireless and Bluetooth.

We're reverting the removal of a Sundance driver, a user has appeared.
This makes the PR rather large in terms of LoC.

There's a conspicuous absence of real, user-reported 6.17 issues.
Slightly worried that the summer distracted people from testing.

Previous releases - regressions:

- ax25: properly unshare skbs in ax25_kiss_rcv()

Previous releases - always broken:

- phylink: disable autoneg for interfaces that have no inband, fix
regression on pcs-lynx (NXP LS1088)

- vxlan: fix null-deref when using nexthop objects

- batman-adv: fix OOB read/write in network-coding decode

- icmp: icmp_ndo_send: fix reversing address translation for replies

- tcp: fix socket ref leak in TCP-AO failure handling for IPv6

- mctp:
- mctp_fraq_queue should take ownership of passed skb
- usb: initialise mac header in RX path, avoid WARN

- wifi: mac80211: do not permit 40 MHz EHT operation on 5/6 GHz,
respect device limitations

- wifi: wilc1000: avoid buffer overflow in WID string configuration

- wifi: mt76:
- fix regressions from mt7996 MLO support rework
- fix offchannel handling issues on mt7996
- fix multiple wcid linked list corruption issues
- mt7921: don't disconnect when AP requests switch to a channel
which requires radar detection
- mt7925u: use connac3 tx aggr check in tx complete

- wifi: intel:
- improve validation of ACPI DSM data
- cfg: restore some 1000 series configs

- wifi: ath:
- ath11k: a fix for GTK rekeying
- ath12k: a missed WiFi7 capability (multi-link EMLSR)

- eth: intel:
- ice: fix races in "low latency" firmware interface for Tx timestamps
- idpf: set mac type when adding and removing MAC filters
- i40e: remove racy read access to some debugfs files

Misc:

- Revert "eth: remove the DLink/Sundance (ST201) driver"

- netfilter: conntrack: helper: Replace -EEXIST by -EBUSY, avoid
confusing modprobe"

* tag 'net-6.17-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (99 commits)
phy: mscc: Stop taking ts_lock for tx_queue and use its own lock
selftest: net: Fix weird setsockopt() in bind_bhash.c.
MAINTAINERS: add Sabrina to TLS maintainers
gve: update MAINTAINERS
ppp: fix memory leak in pad_compress_skb
net: xilinx: axienet: Add error handling for RX metadata pointer retrieval
net: atm: fix memory leak in atm_register_sysfs when device_register fail
netfilter: nf_tables: Introduce NFTA_DEVICE_PREFIX
selftests: netfilter: fix udpclash tool hang
ax25: properly unshare skbs in ax25_kiss_rcv()
mctp: return -ENOPROTOOPT for unknown getsockopt options
net/smc: Remove validation of reserved bits in CLC Decline message
ipv4: Fix NULL vs error pointer check in inet_blackhole_dev_init()
net: thunder_bgx: decrement cleanup index before use
net: thunder_bgx: add a missing of_node_put
net: phylink: move PHY interrupt request to non-fail path
net: lockless sock_i_ino()
tools: ynl-gen: fix nested array counting
wifi: wilc1000: avoid buffer overflow in WID string configuration
wifi: cfg80211: sme: cap SSID length in __cfg80211_connect_result()
...

+3117 -492
+2 -3
Documentation/networking/napi.rst
··· 433 433 434 434 Threaded NAPI is an operating mode that uses dedicated kernel 435 435 threads rather than software IRQ context for NAPI processing. 436 - The configuration is per netdevice and will affect all 437 - NAPI instances of that device. Each NAPI instance will spawn a separate 438 - thread (called ``napi/${ifc-name}-${napi-id}``). 436 + Each threaded NAPI instance will spawn a separate thread 437 + (called ``napi/${ifc-name}-${napi-id}``). 439 438 440 439 It is recommended to pin each kernel thread to a single CPU, the same 441 440 CPU as the CPU which services the interrupt. Note that the mapping
+8 -1
MAINTAINERS
··· 10389 10389 F: drivers/input/touchscreen/goodix* 10390 10390 10391 10391 GOOGLE ETHERNET DRIVERS 10392 - M: Jeroen de Borst <jeroendb@google.com> 10392 + M: Joshua Washington <joshwash@google.com> 10393 10393 M: Harshitha Ramamurthy <hramamurthy@google.com> 10394 10394 L: netdev@vger.kernel.org 10395 10395 S: Maintained ··· 17851 17851 NETWORKING [TLS] 17852 17852 M: John Fastabend <john.fastabend@gmail.com> 17853 17853 M: Jakub Kicinski <kuba@kernel.org> 17854 + M: Sabrina Dubroca <sd@queasysnail.net> 17854 17855 L: netdev@vger.kernel.org 17855 17856 S: Maintained 17856 17857 F: include/net/tls.h ··· 24253 24252 S: Maintained 24254 24253 F: Documentation/devicetree/bindings/input/allwinner,sun4i-a10-lradc-keys.yaml 24255 24254 F: drivers/input/keyboard/sun4i-lradc-keys.c 24255 + 24256 + SUNDANCE NETWORK DRIVER 24257 + M: Denis Kirjanov <dkirjanov@suse.de> 24258 + L: netdev@vger.kernel.org 24259 + S: Maintained 24260 + F: drivers/net/ethernet/dlink/sundance.c 24256 24261 24257 24262 SUNPLUS ETHERNET DRIVER 24258 24263 M: Wells Lu <wellslutw@gmail.com>
+1
arch/mips/configs/mtx1_defconfig
··· 273 273 CONFIG_ULI526X=m 274 274 CONFIG_PCMCIA_XIRCOM=m 275 275 CONFIG_DL2K=m 276 + CONFIG_SUNDANCE=m 276 277 CONFIG_PCMCIA_FMVJ18X=m 277 278 CONFIG_E100=m 278 279 CONFIG_E1000=m
+1
arch/powerpc/configs/ppc6xx_defconfig
··· 433 433 CONFIG_ULI526X=m 434 434 CONFIG_PCMCIA_XIRCOM=m 435 435 CONFIG_DL2K=m 436 + CONFIG_SUNDANCE=m 436 437 CONFIG_S2IO=m 437 438 CONFIG_FEC_MPC52xx=m 438 439 CONFIG_GIANFAR=m
+41 -16
drivers/bluetooth/hci_vhci.c
··· 380 380 .write = force_devcd_write, 381 381 }; 382 382 383 + static void vhci_debugfs_init(struct vhci_data *data) 384 + { 385 + struct hci_dev *hdev = data->hdev; 386 + 387 + debugfs_create_file("force_suspend", 0644, hdev->debugfs, data, 388 + &force_suspend_fops); 389 + 390 + debugfs_create_file("force_wakeup", 0644, hdev->debugfs, data, 391 + &force_wakeup_fops); 392 + 393 + if (IS_ENABLED(CONFIG_BT_MSFTEXT)) 394 + debugfs_create_file("msft_opcode", 0644, hdev->debugfs, data, 395 + &msft_opcode_fops); 396 + 397 + if (IS_ENABLED(CONFIG_BT_AOSPEXT)) 398 + debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data, 399 + &aosp_capable_fops); 400 + 401 + debugfs_create_file("force_devcoredump", 0644, hdev->debugfs, data, 402 + &force_devcoredump_fops); 403 + } 404 + 383 405 static int __vhci_create_device(struct vhci_data *data, __u8 opcode) 384 406 { 385 407 struct hci_dev *hdev; ··· 456 434 return -EBUSY; 457 435 } 458 436 459 - debugfs_create_file("force_suspend", 0644, hdev->debugfs, data, 460 - &force_suspend_fops); 461 - 462 - debugfs_create_file("force_wakeup", 0644, hdev->debugfs, data, 463 - &force_wakeup_fops); 464 - 465 - if (IS_ENABLED(CONFIG_BT_MSFTEXT)) 466 - debugfs_create_file("msft_opcode", 0644, hdev->debugfs, data, 467 - &msft_opcode_fops); 468 - 469 - if (IS_ENABLED(CONFIG_BT_AOSPEXT)) 470 - debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data, 471 - &aosp_capable_fops); 472 - 473 - debugfs_create_file("force_devcoredump", 0644, hdev->debugfs, data, 474 - &force_devcoredump_fops); 437 + if (!IS_ERR_OR_NULL(hdev->debugfs)) 438 + vhci_debugfs_init(data); 475 439 476 440 hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; 477 441 ··· 659 651 return 0; 660 652 } 661 653 654 + static void vhci_debugfs_remove(struct hci_dev *hdev) 655 + { 656 + debugfs_lookup_and_remove("force_suspend", hdev->debugfs); 657 + 658 + debugfs_lookup_and_remove("force_wakeup", hdev->debugfs); 659 + 660 + if (IS_ENABLED(CONFIG_BT_MSFTEXT)) 661 + debugfs_lookup_and_remove("msft_opcode", hdev->debugfs); 662 + 663 + if (IS_ENABLED(CONFIG_BT_AOSPEXT)) 664 + debugfs_lookup_and_remove("aosp_capable", hdev->debugfs); 665 + 666 + debugfs_lookup_and_remove("force_devcoredump", hdev->debugfs); 667 + } 668 + 662 669 static int vhci_release(struct inode *inode, struct file *file) 663 670 { 664 671 struct vhci_data *data = file->private_data; ··· 685 662 hdev = data->hdev; 686 663 687 664 if (hdev) { 665 + if (!IS_ERR_OR_NULL(hdev->debugfs)) 666 + vhci_debugfs_remove(hdev); 688 667 hci_unregister_dev(hdev); 689 668 hci_free_dev(hdev); 690 669 }
+3 -3
drivers/isdn/mISDN/dsp_hwec.c
··· 51 51 goto _do; 52 52 53 53 { 54 - char *dup, *tok, *name, *val; 54 + char *dup, *next, *tok, *name, *val; 55 55 int tmp; 56 56 57 - dup = kstrdup(arg, GFP_ATOMIC); 57 + dup = next = kstrdup(arg, GFP_ATOMIC); 58 58 if (!dup) 59 59 return; 60 60 61 - while ((tok = strsep(&dup, ","))) { 61 + while ((tok = strsep(&next, ","))) { 62 62 if (!strlen(tok)) 63 63 continue; 64 64 name = strsep(&tok, "=");
+13 -4
drivers/net/dsa/mv88e6xxx/leds.c
··· 779 779 continue; 780 780 if (led_num > 1) { 781 781 dev_err(dev, "invalid LED specified port %d\n", port); 782 - return -EINVAL; 782 + ret = -EINVAL; 783 + goto err_put_led; 783 784 } 784 785 785 786 if (led_num == 0) ··· 824 823 init_data.devname_mandatory = true; 825 824 init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d:0%d", chip->info->name, 826 825 port, led_num); 827 - if (!init_data.devicename) 828 - return -ENOMEM; 826 + if (!init_data.devicename) { 827 + ret = -ENOMEM; 828 + goto err_put_led; 829 + } 829 830 830 831 ret = devm_led_classdev_register_ext(dev, l, &init_data); 831 832 kfree(init_data.devicename); 832 833 833 834 if (ret) { 834 835 dev_err(dev, "Failed to init LED %d for port %d", led_num, port); 835 - return ret; 836 + goto err_put_led; 836 837 } 837 838 } 838 839 840 + fwnode_handle_put(leds); 839 841 return 0; 842 + 843 + err_put_led: 844 + fwnode_handle_put(led); 845 + fwnode_handle_put(leds); 846 + return ret; 840 847 }
+1 -1
drivers/net/ethernet/broadcom/bnxt/bnxt.c
··· 4397 4397 for (i = 0; i < bp->rx_agg_ring_size; i++) { 4398 4398 if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_KERNEL)) { 4399 4399 netdev_warn(bp->dev, "init'ed rx ring %d with %d/%d pages only\n", 4400 - ring_nr, i, bp->rx_ring_size); 4400 + ring_nr, i, bp->rx_agg_ring_size); 4401 4401 break; 4402 4402 } 4403 4403 prod = NEXT_RX_AGG(prod);
+16 -12
drivers/net/ethernet/cadence/macb_main.c
··· 1223 1223 { 1224 1224 struct macb *bp = queue->bp; 1225 1225 u16 queue_index = queue - bp->queues; 1226 + unsigned long flags; 1226 1227 unsigned int tail; 1227 1228 unsigned int head; 1228 1229 int packets = 0; 1229 1230 u32 bytes = 0; 1230 1231 1231 - spin_lock(&queue->tx_ptr_lock); 1232 + spin_lock_irqsave(&queue->tx_ptr_lock, flags); 1232 1233 head = queue->tx_head; 1233 1234 for (tail = queue->tx_tail; tail != head && packets < budget; tail++) { 1234 1235 struct macb_tx_skb *tx_skb; ··· 1292 1291 CIRC_CNT(queue->tx_head, queue->tx_tail, 1293 1292 bp->tx_ring_size) <= MACB_TX_WAKEUP_THRESH(bp)) 1294 1293 netif_wake_subqueue(bp->dev, queue_index); 1295 - spin_unlock(&queue->tx_ptr_lock); 1294 + spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); 1296 1295 1297 1296 return packets; 1298 1297 } ··· 1708 1707 { 1709 1708 struct macb *bp = queue->bp; 1710 1709 unsigned int head_idx, tbqp; 1710 + unsigned long flags; 1711 1711 1712 - spin_lock(&queue->tx_ptr_lock); 1712 + spin_lock_irqsave(&queue->tx_ptr_lock, flags); 1713 1713 1714 1714 if (queue->tx_head == queue->tx_tail) 1715 1715 goto out_tx_ptr_unlock; ··· 1722 1720 if (tbqp == head_idx) 1723 1721 goto out_tx_ptr_unlock; 1724 1722 1725 - spin_lock_irq(&bp->lock); 1723 + spin_lock(&bp->lock); 1726 1724 macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); 1727 - spin_unlock_irq(&bp->lock); 1725 + spin_unlock(&bp->lock); 1728 1726 1729 1727 out_tx_ptr_unlock: 1730 - spin_unlock(&queue->tx_ptr_lock); 1728 + spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); 1731 1729 } 1732 1730 1733 1731 static bool macb_tx_complete_pending(struct macb_queue *queue) 1734 1732 { 1735 1733 bool retval = false; 1734 + unsigned long flags; 1736 1735 1737 - spin_lock(&queue->tx_ptr_lock); 1736 + spin_lock_irqsave(&queue->tx_ptr_lock, flags); 1738 1737 if (queue->tx_head != queue->tx_tail) { 1739 1738 /* Make hw descriptor updates visible to CPU */ 1740 1739 rmb(); ··· 1743 1740 if (macb_tx_desc(queue, queue->tx_tail)->ctrl & MACB_BIT(TX_USED)) 1744 1741 retval = true; 1745 1742 } 1746 - spin_unlock(&queue->tx_ptr_lock); 1743 + spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); 1747 1744 return retval; 1748 1745 } 1749 1746 ··· 2311 2308 struct macb_queue *queue = &bp->queues[queue_index]; 2312 2309 unsigned int desc_cnt, nr_frags, frag_size, f; 2313 2310 unsigned int hdrlen; 2311 + unsigned long flags; 2314 2312 bool is_lso; 2315 2313 netdev_tx_t ret = NETDEV_TX_OK; 2316 2314 ··· 2372 2368 desc_cnt += DIV_ROUND_UP(frag_size, bp->max_tx_length); 2373 2369 } 2374 2370 2375 - spin_lock_bh(&queue->tx_ptr_lock); 2371 + spin_lock_irqsave(&queue->tx_ptr_lock, flags); 2376 2372 2377 2373 /* This is a hard error, log it. */ 2378 2374 if (CIRC_SPACE(queue->tx_head, queue->tx_tail, ··· 2396 2392 netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index), 2397 2393 skb->len); 2398 2394 2399 - spin_lock_irq(&bp->lock); 2395 + spin_lock(&bp->lock); 2400 2396 macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); 2401 - spin_unlock_irq(&bp->lock); 2397 + spin_unlock(&bp->lock); 2402 2398 2403 2399 if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1) 2404 2400 netif_stop_subqueue(dev, queue_index); 2405 2401 2406 2402 unlock: 2407 - spin_unlock_bh(&queue->tx_ptr_lock); 2403 + spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); 2408 2404 2409 2405 return ret; 2410 2406 }
+12 -8
drivers/net/ethernet/cavium/thunder/thunder_bgx.c
··· 1493 1493 * this cortina phy, for which there is no driver 1494 1494 * support, ignore it. 1495 1495 */ 1496 - if (phy_np && 1497 - !of_device_is_compatible(phy_np, "cortina,cs4223-slice")) { 1498 - /* Wait until the phy drivers are available */ 1499 - pd = of_phy_find_device(phy_np); 1500 - if (!pd) 1501 - goto defer; 1502 - bgx->lmac[lmac].phydev = pd; 1496 + if (phy_np) { 1497 + if (!of_device_is_compatible(phy_np, "cortina,cs4223-slice")) { 1498 + /* Wait until the phy drivers are available */ 1499 + pd = of_phy_find_device(phy_np); 1500 + if (!pd) { 1501 + of_node_put(phy_np); 1502 + goto defer; 1503 + } 1504 + bgx->lmac[lmac].phydev = pd; 1505 + } 1506 + of_node_put(phy_np); 1503 1507 } 1504 1508 1505 1509 lmac++; ··· 1519 1515 * for phy devices we may have already found. 1520 1516 */ 1521 1517 while (lmac) { 1518 + lmac--; 1522 1519 if (bgx->lmac[lmac].phydev) { 1523 1520 put_device(&bgx->lmac[lmac].phydev->mdio.dev); 1524 1521 bgx->lmac[lmac].phydev = NULL; 1525 1522 } 1526 - lmac--; 1527 1523 } 1528 1524 of_node_put(node); 1529 1525 return -EPROBE_DEFER;
+20
drivers/net/ethernet/dlink/Kconfig
··· 32 32 To compile this driver as a module, choose M here: the 33 33 module will be called dl2k. 34 34 35 + config SUNDANCE 36 + tristate "Sundance Alta support" 37 + depends on PCI 38 + select CRC32 39 + select MII 40 + help 41 + This driver is for the Sundance "Alta" chip. 42 + More specific information and updates are available from 43 + <http://www.scyld.com/network/sundance.html>. 44 + 45 + config SUNDANCE_MMIO 46 + bool "Use MMIO instead of PIO" 47 + depends on SUNDANCE 48 + help 49 + Enable memory-mapped I/O for interaction with Sundance NIC registers. 50 + Do NOT enable this by default, PIO (enabled when MMIO is disabled) 51 + is known to solve bugs on certain chips. 52 + 53 + If unsure, say N. 54 + 35 55 endif # NET_VENDOR_DLINK
+1
drivers/net/ethernet/dlink/Makefile
··· 4 4 # 5 5 6 6 obj-$(CONFIG_DL2K) += dl2k.o 7 + obj-$(CONFIG_SUNDANCE) += sundance.o
+1990
drivers/net/ethernet/dlink/sundance.c
··· 1 + /* sundance.c: A Linux device driver for the Sundance ST201 "Alta". */ 2 + /* 3 + Written 1999-2000 by Donald Becker. 4 + 5 + This software may be used and distributed according to the terms of 6 + the GNU General Public License (GPL), incorporated herein by reference. 7 + Drivers based on or derived from this code fall under the GPL and must 8 + retain the authorship, copyright and license notice. This file is not 9 + a complete program and may only be used when the entire operating 10 + system is licensed under the GPL. 11 + 12 + The author may be reached as becker@scyld.com, or C/O 13 + Scyld Computing Corporation 14 + 410 Severn Ave., Suite 210 15 + Annapolis MD 21403 16 + 17 + Support and updates available at 18 + http://www.scyld.com/network/sundance.html 19 + [link no longer provides useful info -jgarzik] 20 + Archives of the mailing list are still available at 21 + https://www.beowulf.org/pipermail/netdrivers/ 22 + 23 + */ 24 + 25 + #define DRV_NAME "sundance" 26 + 27 + /* The user-configurable values. 28 + These may be modified when a driver module is loaded.*/ 29 + static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */ 30 + /* Maximum number of multicast addresses to filter (vs. rx-all-multicast). 31 + Typical is a 64 element hash table based on the Ethernet CRC. */ 32 + static const int multicast_filter_limit = 32; 33 + 34 + /* Set the copy breakpoint for the copy-only-tiny-frames scheme. 35 + Setting to > 1518 effectively disables this feature. 36 + This chip can receive into offset buffers, so the Alpha does not 37 + need a copy-align. */ 38 + static int rx_copybreak; 39 + static int flowctrl=1; 40 + 41 + /* media[] specifies the media type the NIC operates at. 42 + autosense Autosensing active media. 43 + 10mbps_hd 10Mbps half duplex. 44 + 10mbps_fd 10Mbps full duplex. 45 + 100mbps_hd 100Mbps half duplex. 46 + 100mbps_fd 100Mbps full duplex. 47 + 0 Autosensing active media. 48 + 1 10Mbps half duplex. 49 + 2 10Mbps full duplex. 50 + 3 100Mbps half duplex. 51 + 4 100Mbps full duplex. 52 + */ 53 + #define MAX_UNITS 8 54 + static char *media[MAX_UNITS]; 55 + 56 + 57 + /* Operational parameters that are set at compile time. */ 58 + 59 + /* Keep the ring sizes a power of two for compile efficiency. 60 + The compiler will convert <unsigned>'%'<2^N> into a bit mask. 61 + Making the Tx ring too large decreases the effectiveness of channel 62 + bonding and packet priority, and more than 128 requires modifying the 63 + Tx error recovery. 64 + Large receive rings merely waste memory. */ 65 + #define TX_RING_SIZE 32 66 + #define TX_QUEUE_LEN (TX_RING_SIZE - 1) /* Limit ring entries actually used. */ 67 + #define RX_RING_SIZE 64 68 + #define RX_BUDGET 32 69 + #define TX_TOTAL_SIZE TX_RING_SIZE*sizeof(struct netdev_desc) 70 + #define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct netdev_desc) 71 + 72 + /* Operational parameters that usually are not changed. */ 73 + /* Time in jiffies before concluding the transmitter is hung. */ 74 + #define TX_TIMEOUT (4*HZ) 75 + #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/ 76 + 77 + /* Include files, designed to support most kernel versions 2.0.0 and later. */ 78 + #include <linux/module.h> 79 + #include <linux/kernel.h> 80 + #include <linux/string.h> 81 + #include <linux/timer.h> 82 + #include <linux/errno.h> 83 + #include <linux/ioport.h> 84 + #include <linux/interrupt.h> 85 + #include <linux/pci.h> 86 + #include <linux/netdevice.h> 87 + #include <linux/etherdevice.h> 88 + #include <linux/skbuff.h> 89 + #include <linux/init.h> 90 + #include <linux/bitops.h> 91 + #include <linux/uaccess.h> 92 + #include <asm/processor.h> /* Processor type for cache alignment. */ 93 + #include <asm/io.h> 94 + #include <linux/delay.h> 95 + #include <linux/spinlock.h> 96 + #include <linux/dma-mapping.h> 97 + #include <linux/crc32.h> 98 + #include <linux/ethtool.h> 99 + #include <linux/mii.h> 100 + 101 + MODULE_AUTHOR("Donald Becker <becker@scyld.com>"); 102 + MODULE_DESCRIPTION("Sundance Alta Ethernet driver"); 103 + MODULE_LICENSE("GPL"); 104 + 105 + module_param(debug, int, 0); 106 + module_param(rx_copybreak, int, 0); 107 + module_param_array(media, charp, NULL, 0); 108 + module_param(flowctrl, int, 0); 109 + MODULE_PARM_DESC(debug, "Sundance Alta debug level (0-5)"); 110 + MODULE_PARM_DESC(rx_copybreak, "Sundance Alta copy breakpoint for copy-only-tiny-frames"); 111 + MODULE_PARM_DESC(flowctrl, "Sundance Alta flow control [0|1]"); 112 + 113 + /* 114 + Theory of Operation 115 + 116 + I. Board Compatibility 117 + 118 + This driver is designed for the Sundance Technologies "Alta" ST201 chip. 119 + 120 + II. Board-specific settings 121 + 122 + III. Driver operation 123 + 124 + IIIa. Ring buffers 125 + 126 + This driver uses two statically allocated fixed-size descriptor lists 127 + formed into rings by a branch from the final descriptor to the beginning of 128 + the list. The ring sizes are set at compile time by RX/TX_RING_SIZE. 129 + Some chips explicitly use only 2^N sized rings, while others use a 130 + 'next descriptor' pointer that the driver forms into rings. 131 + 132 + IIIb/c. Transmit/Receive Structure 133 + 134 + This driver uses a zero-copy receive and transmit scheme. 135 + The driver allocates full frame size skbuffs for the Rx ring buffers at 136 + open() time and passes the skb->data field to the chip as receive data 137 + buffers. When an incoming frame is less than RX_COPYBREAK bytes long, 138 + a fresh skbuff is allocated and the frame is copied to the new skbuff. 139 + When the incoming frame is larger, the skbuff is passed directly up the 140 + protocol stack. Buffers consumed this way are replaced by newly allocated 141 + skbuffs in a later phase of receives. 142 + 143 + The RX_COPYBREAK value is chosen to trade-off the memory wasted by 144 + using a full-sized skbuff for small frames vs. the copying costs of larger 145 + frames. New boards are typically used in generously configured machines 146 + and the underfilled buffers have negligible impact compared to the benefit of 147 + a single allocation size, so the default value of zero results in never 148 + copying packets. When copying is done, the cost is usually mitigated by using 149 + a combined copy/checksum routine. Copying also preloads the cache, which is 150 + most useful with small frames. 151 + 152 + A subtle aspect of the operation is that the IP header at offset 14 in an 153 + ethernet frame isn't longword aligned for further processing. 154 + Unaligned buffers are permitted by the Sundance hardware, so 155 + frames are received into the skbuff at an offset of "+2", 16-byte aligning 156 + the IP header. 157 + 158 + IIId. Synchronization 159 + 160 + The driver runs as two independent, single-threaded flows of control. One 161 + is the send-packet routine, which enforces single-threaded use by the 162 + dev->tbusy flag. The other thread is the interrupt handler, which is single 163 + threaded by the hardware and interrupt handling software. 164 + 165 + The send packet thread has partial control over the Tx ring and 'dev->tbusy' 166 + flag. It sets the tbusy flag whenever it's queuing a Tx packet. If the next 167 + queue slot is empty, it clears the tbusy flag when finished otherwise it sets 168 + the 'lp->tx_full' flag. 169 + 170 + The interrupt handler has exclusive control over the Rx ring and records stats 171 + from the Tx ring. After reaping the stats, it marks the Tx queue entry as 172 + empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it 173 + clears both the tx_full and tbusy flags. 174 + 175 + IV. Notes 176 + 177 + IVb. References 178 + 179 + The Sundance ST201 datasheet, preliminary version. 180 + The Kendin KS8723 datasheet, preliminary version. 181 + The ICplus IP100 datasheet, preliminary version. 182 + http://www.scyld.com/expert/100mbps.html 183 + http://www.scyld.com/expert/NWay.html 184 + 185 + IVc. Errata 186 + 187 + */ 188 + 189 + /* Work-around for Kendin chip bugs. */ 190 + #ifndef CONFIG_SUNDANCE_MMIO 191 + #define USE_IO_OPS 1 192 + #endif 193 + 194 + static const struct pci_device_id sundance_pci_tbl[] = { 195 + { 0x1186, 0x1002, 0x1186, 0x1002, 0, 0, 0 }, 196 + { 0x1186, 0x1002, 0x1186, 0x1003, 0, 0, 1 }, 197 + { 0x1186, 0x1002, 0x1186, 0x1012, 0, 0, 2 }, 198 + { 0x1186, 0x1002, 0x1186, 0x1040, 0, 0, 3 }, 199 + { 0x1186, 0x1002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, 200 + { 0x13F0, 0x0201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 }, 201 + { 0x13F0, 0x0200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 }, 202 + { } 203 + }; 204 + MODULE_DEVICE_TABLE(pci, sundance_pci_tbl); 205 + 206 + enum { 207 + netdev_io_size = 128 208 + }; 209 + 210 + struct pci_id_info { 211 + const char *name; 212 + }; 213 + static const struct pci_id_info pci_id_tbl[] = { 214 + {"D-Link DFE-550TX FAST Ethernet Adapter"}, 215 + {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"}, 216 + {"D-Link DFE-580TX 4 port Server Adapter"}, 217 + {"D-Link DFE-530TXS FAST Ethernet Adapter"}, 218 + {"D-Link DL10050-based FAST Ethernet Adapter"}, 219 + {"Sundance Technology Alta"}, 220 + {"IC Plus Corporation IP100A FAST Ethernet Adapter"}, 221 + { } /* terminate list. */ 222 + }; 223 + 224 + /* This driver was written to use PCI memory space, however x86-oriented 225 + hardware often uses I/O space accesses. */ 226 + 227 + /* Offsets to the device registers. 228 + Unlike software-only systems, device drivers interact with complex hardware. 229 + It's not useful to define symbolic names for every register bit in the 230 + device. The name can only partially document the semantics and make 231 + the driver longer and more difficult to read. 232 + In general, only the important configuration values or bits changed 233 + multiple times should be defined symbolically. 234 + */ 235 + enum alta_offsets { 236 + DMACtrl = 0x00, 237 + TxListPtr = 0x04, 238 + TxDMABurstThresh = 0x08, 239 + TxDMAUrgentThresh = 0x09, 240 + TxDMAPollPeriod = 0x0a, 241 + RxDMAStatus = 0x0c, 242 + RxListPtr = 0x10, 243 + DebugCtrl0 = 0x1a, 244 + DebugCtrl1 = 0x1c, 245 + RxDMABurstThresh = 0x14, 246 + RxDMAUrgentThresh = 0x15, 247 + RxDMAPollPeriod = 0x16, 248 + LEDCtrl = 0x1a, 249 + ASICCtrl = 0x30, 250 + EEData = 0x34, 251 + EECtrl = 0x36, 252 + FlashAddr = 0x40, 253 + FlashData = 0x44, 254 + WakeEvent = 0x45, 255 + TxStatus = 0x46, 256 + TxFrameId = 0x47, 257 + DownCounter = 0x18, 258 + IntrClear = 0x4a, 259 + IntrEnable = 0x4c, 260 + IntrStatus = 0x4e, 261 + MACCtrl0 = 0x50, 262 + MACCtrl1 = 0x52, 263 + StationAddr = 0x54, 264 + MaxFrameSize = 0x5A, 265 + RxMode = 0x5c, 266 + MIICtrl = 0x5e, 267 + MulticastFilter0 = 0x60, 268 + MulticastFilter1 = 0x64, 269 + RxOctetsLow = 0x68, 270 + RxOctetsHigh = 0x6a, 271 + TxOctetsLow = 0x6c, 272 + TxOctetsHigh = 0x6e, 273 + TxFramesOK = 0x70, 274 + RxFramesOK = 0x72, 275 + StatsCarrierError = 0x74, 276 + StatsLateColl = 0x75, 277 + StatsMultiColl = 0x76, 278 + StatsOneColl = 0x77, 279 + StatsTxDefer = 0x78, 280 + RxMissed = 0x79, 281 + StatsTxXSDefer = 0x7a, 282 + StatsTxAbort = 0x7b, 283 + StatsBcastTx = 0x7c, 284 + StatsBcastRx = 0x7d, 285 + StatsMcastTx = 0x7e, 286 + StatsMcastRx = 0x7f, 287 + /* Aliased and bogus values! */ 288 + RxStatus = 0x0c, 289 + }; 290 + 291 + #define ASIC_HI_WORD(x) ((x) + 2) 292 + 293 + enum ASICCtrl_HiWord_bit { 294 + GlobalReset = 0x0001, 295 + RxReset = 0x0002, 296 + TxReset = 0x0004, 297 + DMAReset = 0x0008, 298 + FIFOReset = 0x0010, 299 + NetworkReset = 0x0020, 300 + HostReset = 0x0040, 301 + ResetBusy = 0x0400, 302 + }; 303 + 304 + /* Bits in the interrupt status/mask registers. */ 305 + enum intr_status_bits { 306 + IntrSummary=0x0001, IntrPCIErr=0x0002, IntrMACCtrl=0x0008, 307 + IntrTxDone=0x0004, IntrRxDone=0x0010, IntrRxStart=0x0020, 308 + IntrDrvRqst=0x0040, 309 + StatsMax=0x0080, LinkChange=0x0100, 310 + IntrTxDMADone=0x0200, IntrRxDMADone=0x0400, 311 + }; 312 + 313 + /* Bits in the RxMode register. */ 314 + enum rx_mode_bits { 315 + AcceptAllIPMulti=0x20, AcceptMultiHash=0x10, AcceptAll=0x08, 316 + AcceptBroadcast=0x04, AcceptMulticast=0x02, AcceptMyPhys=0x01, 317 + }; 318 + /* Bits in MACCtrl. */ 319 + enum mac_ctrl0_bits { 320 + EnbFullDuplex=0x20, EnbRcvLargeFrame=0x40, 321 + EnbFlowCtrl=0x100, EnbPassRxCRC=0x200, 322 + }; 323 + enum mac_ctrl1_bits { 324 + StatsEnable=0x0020, StatsDisable=0x0040, StatsEnabled=0x0080, 325 + TxEnable=0x0100, TxDisable=0x0200, TxEnabled=0x0400, 326 + RxEnable=0x0800, RxDisable=0x1000, RxEnabled=0x2000, 327 + }; 328 + 329 + /* Bits in WakeEvent register. */ 330 + enum wake_event_bits { 331 + WakePktEnable = 0x01, 332 + MagicPktEnable = 0x02, 333 + LinkEventEnable = 0x04, 334 + WolEnable = 0x80, 335 + }; 336 + 337 + /* The Rx and Tx buffer descriptors. */ 338 + /* Note that using only 32 bit fields simplifies conversion to big-endian 339 + architectures. */ 340 + struct netdev_desc { 341 + __le32 next_desc; 342 + __le32 status; 343 + struct desc_frag { __le32 addr, length; } frag; 344 + }; 345 + 346 + /* Bits in netdev_desc.status */ 347 + enum desc_status_bits { 348 + DescOwn=0x8000, 349 + DescEndPacket=0x4000, 350 + DescEndRing=0x2000, 351 + LastFrag=0x80000000, 352 + DescIntrOnTx=0x8000, 353 + DescIntrOnDMADone=0x80000000, 354 + DisableAlign = 0x00000001, 355 + }; 356 + 357 + #define PRIV_ALIGN 15 /* Required alignment mask */ 358 + /* Use __attribute__((aligned (L1_CACHE_BYTES))) to maintain alignment 359 + within the structure. */ 360 + #define MII_CNT 4 361 + struct netdev_private { 362 + /* Descriptor rings first for alignment. */ 363 + struct netdev_desc *rx_ring; 364 + struct netdev_desc *tx_ring; 365 + struct sk_buff* rx_skbuff[RX_RING_SIZE]; 366 + struct sk_buff* tx_skbuff[TX_RING_SIZE]; 367 + dma_addr_t tx_ring_dma; 368 + dma_addr_t rx_ring_dma; 369 + struct timer_list timer; /* Media monitoring timer. */ 370 + struct net_device *ndev; /* backpointer */ 371 + /* ethtool extra stats */ 372 + struct { 373 + u64 tx_multiple_collisions; 374 + u64 tx_single_collisions; 375 + u64 tx_late_collisions; 376 + u64 tx_deferred; 377 + u64 tx_deferred_excessive; 378 + u64 tx_aborted; 379 + u64 tx_bcasts; 380 + u64 rx_bcasts; 381 + u64 tx_mcasts; 382 + u64 rx_mcasts; 383 + } xstats; 384 + /* Frequently used values: keep some adjacent for cache effect. */ 385 + spinlock_t lock; 386 + int msg_enable; 387 + int chip_id; 388 + unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */ 389 + unsigned int rx_buf_sz; /* Based on MTU+slack. */ 390 + struct netdev_desc *last_tx; /* Last Tx descriptor used. */ 391 + unsigned int cur_tx, dirty_tx; 392 + /* These values are keep track of the transceiver/media in use. */ 393 + unsigned int flowctrl:1; 394 + unsigned int default_port:4; /* Last dev->if_port value. */ 395 + unsigned int an_enable:1; 396 + unsigned int speed; 397 + unsigned int wol_enabled:1; /* Wake on LAN enabled */ 398 + struct tasklet_struct rx_tasklet; 399 + struct tasklet_struct tx_tasklet; 400 + int budget; 401 + int cur_task; 402 + /* Multicast and receive mode. */ 403 + spinlock_t mcastlock; /* SMP lock multicast updates. */ 404 + u16 mcast_filter[4]; 405 + /* MII transceiver section. */ 406 + struct mii_if_info mii_if; 407 + int mii_preamble_required; 408 + unsigned char phys[MII_CNT]; /* MII device addresses, only first one used. */ 409 + struct pci_dev *pci_dev; 410 + void __iomem *base; 411 + spinlock_t statlock; 412 + }; 413 + 414 + /* The station address location in the EEPROM. */ 415 + #define EEPROM_SA_OFFSET 0x10 416 + #define DEFAULT_INTR (IntrRxDMADone | IntrPCIErr | \ 417 + IntrDrvRqst | IntrTxDone | StatsMax | \ 418 + LinkChange) 419 + 420 + static int change_mtu(struct net_device *dev, int new_mtu); 421 + static int eeprom_read(void __iomem *ioaddr, int location); 422 + static int mdio_read(struct net_device *dev, int phy_id, int location); 423 + static void mdio_write(struct net_device *dev, int phy_id, int location, int value); 424 + static int mdio_wait_link(struct net_device *dev, int wait); 425 + static int netdev_open(struct net_device *dev); 426 + static void check_duplex(struct net_device *dev); 427 + static void netdev_timer(struct timer_list *t); 428 + static void tx_timeout(struct net_device *dev, unsigned int txqueue); 429 + static void init_ring(struct net_device *dev); 430 + static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev); 431 + static int reset_tx (struct net_device *dev); 432 + static irqreturn_t intr_handler(int irq, void *dev_instance); 433 + static void rx_poll(struct tasklet_struct *t); 434 + static void tx_poll(struct tasklet_struct *t); 435 + static void refill_rx (struct net_device *dev); 436 + static void netdev_error(struct net_device *dev, int intr_status); 437 + static void netdev_error(struct net_device *dev, int intr_status); 438 + static void set_rx_mode(struct net_device *dev); 439 + static int __set_mac_addr(struct net_device *dev); 440 + static int sundance_set_mac_addr(struct net_device *dev, void *data); 441 + static struct net_device_stats *get_stats(struct net_device *dev); 442 + static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 443 + static int netdev_close(struct net_device *dev); 444 + static const struct ethtool_ops ethtool_ops; 445 + 446 + static void sundance_reset(struct net_device *dev, unsigned long reset_cmd) 447 + { 448 + struct netdev_private *np = netdev_priv(dev); 449 + void __iomem *ioaddr = np->base + ASICCtrl; 450 + int countdown; 451 + 452 + /* ST201 documentation states ASICCtrl is a 32bit register */ 453 + iowrite32 (reset_cmd | ioread32 (ioaddr), ioaddr); 454 + /* ST201 documentation states reset can take up to 1 ms */ 455 + countdown = 10 + 1; 456 + while (ioread32 (ioaddr) & (ResetBusy << 16)) { 457 + if (--countdown == 0) { 458 + printk(KERN_WARNING "%s : reset not completed !!\n", dev->name); 459 + break; 460 + } 461 + udelay(100); 462 + } 463 + } 464 + 465 + #ifdef CONFIG_NET_POLL_CONTROLLER 466 + static void sundance_poll_controller(struct net_device *dev) 467 + { 468 + struct netdev_private *np = netdev_priv(dev); 469 + 470 + disable_irq(np->pci_dev->irq); 471 + intr_handler(np->pci_dev->irq, dev); 472 + enable_irq(np->pci_dev->irq); 473 + } 474 + #endif 475 + 476 + static const struct net_device_ops netdev_ops = { 477 + .ndo_open = netdev_open, 478 + .ndo_stop = netdev_close, 479 + .ndo_start_xmit = start_tx, 480 + .ndo_get_stats = get_stats, 481 + .ndo_set_rx_mode = set_rx_mode, 482 + .ndo_eth_ioctl = netdev_ioctl, 483 + .ndo_tx_timeout = tx_timeout, 484 + .ndo_change_mtu = change_mtu, 485 + .ndo_set_mac_address = sundance_set_mac_addr, 486 + .ndo_validate_addr = eth_validate_addr, 487 + #ifdef CONFIG_NET_POLL_CONTROLLER 488 + .ndo_poll_controller = sundance_poll_controller, 489 + #endif 490 + }; 491 + 492 + static int sundance_probe1(struct pci_dev *pdev, 493 + const struct pci_device_id *ent) 494 + { 495 + struct net_device *dev; 496 + struct netdev_private *np; 497 + static int card_idx; 498 + int chip_idx = ent->driver_data; 499 + int irq; 500 + int i; 501 + void __iomem *ioaddr; 502 + u16 mii_ctl; 503 + void *ring_space; 504 + dma_addr_t ring_dma; 505 + #ifdef USE_IO_OPS 506 + int bar = 0; 507 + #else 508 + int bar = 1; 509 + #endif 510 + int phy, phy_end, phy_idx = 0; 511 + __le16 addr[ETH_ALEN / 2]; 512 + 513 + if (pci_enable_device(pdev)) 514 + return -EIO; 515 + pci_set_master(pdev); 516 + 517 + irq = pdev->irq; 518 + 519 + dev = alloc_etherdev(sizeof(*np)); 520 + if (!dev) 521 + return -ENOMEM; 522 + SET_NETDEV_DEV(dev, &pdev->dev); 523 + 524 + if (pci_request_regions(pdev, DRV_NAME)) 525 + goto err_out_netdev; 526 + 527 + ioaddr = pci_iomap(pdev, bar, netdev_io_size); 528 + if (!ioaddr) 529 + goto err_out_res; 530 + 531 + for (i = 0; i < 3; i++) 532 + addr[i] = 533 + cpu_to_le16(eeprom_read(ioaddr, i + EEPROM_SA_OFFSET)); 534 + eth_hw_addr_set(dev, (u8 *)addr); 535 + 536 + np = netdev_priv(dev); 537 + np->ndev = dev; 538 + np->base = ioaddr; 539 + np->pci_dev = pdev; 540 + np->chip_id = chip_idx; 541 + np->msg_enable = (1 << debug) - 1; 542 + spin_lock_init(&np->lock); 543 + spin_lock_init(&np->statlock); 544 + tasklet_setup(&np->rx_tasklet, rx_poll); 545 + tasklet_setup(&np->tx_tasklet, tx_poll); 546 + 547 + ring_space = dma_alloc_coherent(&pdev->dev, TX_TOTAL_SIZE, 548 + &ring_dma, GFP_KERNEL); 549 + if (!ring_space) 550 + goto err_out_cleardev; 551 + np->tx_ring = (struct netdev_desc *)ring_space; 552 + np->tx_ring_dma = ring_dma; 553 + 554 + ring_space = dma_alloc_coherent(&pdev->dev, RX_TOTAL_SIZE, 555 + &ring_dma, GFP_KERNEL); 556 + if (!ring_space) 557 + goto err_out_unmap_tx; 558 + np->rx_ring = (struct netdev_desc *)ring_space; 559 + np->rx_ring_dma = ring_dma; 560 + 561 + np->mii_if.dev = dev; 562 + np->mii_if.mdio_read = mdio_read; 563 + np->mii_if.mdio_write = mdio_write; 564 + np->mii_if.phy_id_mask = 0x1f; 565 + np->mii_if.reg_num_mask = 0x1f; 566 + 567 + /* The chip-specific entries in the device structure. */ 568 + dev->netdev_ops = &netdev_ops; 569 + dev->ethtool_ops = &ethtool_ops; 570 + dev->watchdog_timeo = TX_TIMEOUT; 571 + 572 + /* MTU range: 68 - 8191 */ 573 + dev->min_mtu = ETH_MIN_MTU; 574 + dev->max_mtu = 8191; 575 + 576 + pci_set_drvdata(pdev, dev); 577 + 578 + i = register_netdev(dev); 579 + if (i) 580 + goto err_out_unmap_rx; 581 + 582 + printk(KERN_INFO "%s: %s at %p, %pM, IRQ %d.\n", 583 + dev->name, pci_id_tbl[chip_idx].name, ioaddr, 584 + dev->dev_addr, irq); 585 + 586 + np->phys[0] = 1; /* Default setting */ 587 + np->mii_preamble_required++; 588 + 589 + /* 590 + * It seems some phys doesn't deal well with address 0 being accessed 591 + * first 592 + */ 593 + if (sundance_pci_tbl[np->chip_id].device == 0x0200) { 594 + phy = 0; 595 + phy_end = 31; 596 + } else { 597 + phy = 1; 598 + phy_end = 32; /* wraps to zero, due to 'phy & 0x1f' */ 599 + } 600 + for (; phy <= phy_end && phy_idx < MII_CNT; phy++) { 601 + int phyx = phy & 0x1f; 602 + int mii_status = mdio_read(dev, phyx, MII_BMSR); 603 + if (mii_status != 0xffff && mii_status != 0x0000) { 604 + np->phys[phy_idx++] = phyx; 605 + np->mii_if.advertising = mdio_read(dev, phyx, MII_ADVERTISE); 606 + if ((mii_status & 0x0040) == 0) 607 + np->mii_preamble_required++; 608 + printk(KERN_INFO "%s: MII PHY found at address %d, status " 609 + "0x%4.4x advertising %4.4x.\n", 610 + dev->name, phyx, mii_status, np->mii_if.advertising); 611 + } 612 + } 613 + np->mii_preamble_required--; 614 + 615 + if (phy_idx == 0) { 616 + printk(KERN_INFO "%s: No MII transceiver found, aborting. ASIC status %x\n", 617 + dev->name, ioread32(ioaddr + ASICCtrl)); 618 + goto err_out_unregister; 619 + } 620 + 621 + np->mii_if.phy_id = np->phys[0]; 622 + 623 + /* Parse override configuration */ 624 + np->an_enable = 1; 625 + if (card_idx < MAX_UNITS) { 626 + if (media[card_idx] != NULL) { 627 + np->an_enable = 0; 628 + if (strcmp (media[card_idx], "100mbps_fd") == 0 || 629 + strcmp (media[card_idx], "4") == 0) { 630 + np->speed = 100; 631 + np->mii_if.full_duplex = 1; 632 + } else if (strcmp (media[card_idx], "100mbps_hd") == 0 || 633 + strcmp (media[card_idx], "3") == 0) { 634 + np->speed = 100; 635 + np->mii_if.full_duplex = 0; 636 + } else if (strcmp (media[card_idx], "10mbps_fd") == 0 || 637 + strcmp (media[card_idx], "2") == 0) { 638 + np->speed = 10; 639 + np->mii_if.full_duplex = 1; 640 + } else if (strcmp (media[card_idx], "10mbps_hd") == 0 || 641 + strcmp (media[card_idx], "1") == 0) { 642 + np->speed = 10; 643 + np->mii_if.full_duplex = 0; 644 + } else { 645 + np->an_enable = 1; 646 + } 647 + } 648 + if (flowctrl == 1) 649 + np->flowctrl = 1; 650 + } 651 + 652 + /* Fibre PHY? */ 653 + if (ioread32 (ioaddr + ASICCtrl) & 0x80) { 654 + /* Default 100Mbps Full */ 655 + if (np->an_enable) { 656 + np->speed = 100; 657 + np->mii_if.full_duplex = 1; 658 + np->an_enable = 0; 659 + } 660 + } 661 + /* Reset PHY */ 662 + mdio_write (dev, np->phys[0], MII_BMCR, BMCR_RESET); 663 + mdelay (300); 664 + /* If flow control enabled, we need to advertise it.*/ 665 + if (np->flowctrl) 666 + mdio_write (dev, np->phys[0], MII_ADVERTISE, np->mii_if.advertising | 0x0400); 667 + mdio_write (dev, np->phys[0], MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART); 668 + /* Force media type */ 669 + if (!np->an_enable) { 670 + mii_ctl = 0; 671 + mii_ctl |= (np->speed == 100) ? BMCR_SPEED100 : 0; 672 + mii_ctl |= (np->mii_if.full_duplex) ? BMCR_FULLDPLX : 0; 673 + mdio_write (dev, np->phys[0], MII_BMCR, mii_ctl); 674 + printk (KERN_INFO "Override speed=%d, %s duplex\n", 675 + np->speed, np->mii_if.full_duplex ? "Full" : "Half"); 676 + 677 + } 678 + 679 + /* Perhaps move the reset here? */ 680 + /* Reset the chip to erase previous misconfiguration. */ 681 + if (netif_msg_hw(np)) 682 + printk("ASIC Control is %x.\n", ioread32(ioaddr + ASICCtrl)); 683 + sundance_reset(dev, 0x00ff << 16); 684 + if (netif_msg_hw(np)) 685 + printk("ASIC Control is now %x.\n", ioread32(ioaddr + ASICCtrl)); 686 + 687 + card_idx++; 688 + return 0; 689 + 690 + err_out_unregister: 691 + unregister_netdev(dev); 692 + err_out_unmap_rx: 693 + dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, 694 + np->rx_ring, np->rx_ring_dma); 695 + err_out_unmap_tx: 696 + dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, 697 + np->tx_ring, np->tx_ring_dma); 698 + err_out_cleardev: 699 + pci_iounmap(pdev, ioaddr); 700 + err_out_res: 701 + pci_release_regions(pdev); 702 + err_out_netdev: 703 + free_netdev (dev); 704 + return -ENODEV; 705 + } 706 + 707 + static int change_mtu(struct net_device *dev, int new_mtu) 708 + { 709 + if (netif_running(dev)) 710 + return -EBUSY; 711 + WRITE_ONCE(dev->mtu, new_mtu); 712 + return 0; 713 + } 714 + 715 + #define eeprom_delay(ee_addr) ioread32(ee_addr) 716 + /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces. */ 717 + static int eeprom_read(void __iomem *ioaddr, int location) 718 + { 719 + int boguscnt = 10000; /* Typical 1900 ticks. */ 720 + iowrite16(0x0200 | (location & 0xff), ioaddr + EECtrl); 721 + do { 722 + eeprom_delay(ioaddr + EECtrl); 723 + if (! (ioread16(ioaddr + EECtrl) & 0x8000)) { 724 + return ioread16(ioaddr + EEData); 725 + } 726 + } while (--boguscnt > 0); 727 + return 0; 728 + } 729 + 730 + /* MII transceiver control section. 731 + Read and write the MII registers using software-generated serial 732 + MDIO protocol. See the MII specifications or DP83840A data sheet 733 + for details. 734 + 735 + The maximum data clock rate is 2.5 Mhz. The minimum timing is usually 736 + met by back-to-back 33Mhz PCI cycles. */ 737 + #define mdio_delay() ioread8(mdio_addr) 738 + 739 + enum mii_reg_bits { 740 + MDIO_ShiftClk=0x0001, MDIO_Data=0x0002, MDIO_EnbOutput=0x0004, 741 + }; 742 + #define MDIO_EnbIn (0) 743 + #define MDIO_WRITE0 (MDIO_EnbOutput) 744 + #define MDIO_WRITE1 (MDIO_Data | MDIO_EnbOutput) 745 + 746 + /* Generate the preamble required for initial synchronization and 747 + a few older transceivers. */ 748 + static void mdio_sync(void __iomem *mdio_addr) 749 + { 750 + int bits = 32; 751 + 752 + /* Establish sync by sending at least 32 logic ones. */ 753 + while (--bits >= 0) { 754 + iowrite8(MDIO_WRITE1, mdio_addr); 755 + mdio_delay(); 756 + iowrite8(MDIO_WRITE1 | MDIO_ShiftClk, mdio_addr); 757 + mdio_delay(); 758 + } 759 + } 760 + 761 + static int mdio_read(struct net_device *dev, int phy_id, int location) 762 + { 763 + struct netdev_private *np = netdev_priv(dev); 764 + void __iomem *mdio_addr = np->base + MIICtrl; 765 + int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location; 766 + int i, retval = 0; 767 + 768 + if (np->mii_preamble_required) 769 + mdio_sync(mdio_addr); 770 + 771 + /* Shift the read command bits out. */ 772 + for (i = 15; i >= 0; i--) { 773 + int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0; 774 + 775 + iowrite8(dataval, mdio_addr); 776 + mdio_delay(); 777 + iowrite8(dataval | MDIO_ShiftClk, mdio_addr); 778 + mdio_delay(); 779 + } 780 + /* Read the two transition, 16 data, and wire-idle bits. */ 781 + for (i = 19; i > 0; i--) { 782 + iowrite8(MDIO_EnbIn, mdio_addr); 783 + mdio_delay(); 784 + retval = (retval << 1) | ((ioread8(mdio_addr) & MDIO_Data) ? 1 : 0); 785 + iowrite8(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr); 786 + mdio_delay(); 787 + } 788 + return (retval>>1) & 0xffff; 789 + } 790 + 791 + static void mdio_write(struct net_device *dev, int phy_id, int location, int value) 792 + { 793 + struct netdev_private *np = netdev_priv(dev); 794 + void __iomem *mdio_addr = np->base + MIICtrl; 795 + int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value; 796 + int i; 797 + 798 + if (np->mii_preamble_required) 799 + mdio_sync(mdio_addr); 800 + 801 + /* Shift the command bits out. */ 802 + for (i = 31; i >= 0; i--) { 803 + int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0; 804 + 805 + iowrite8(dataval, mdio_addr); 806 + mdio_delay(); 807 + iowrite8(dataval | MDIO_ShiftClk, mdio_addr); 808 + mdio_delay(); 809 + } 810 + /* Clear out extra bits. */ 811 + for (i = 2; i > 0; i--) { 812 + iowrite8(MDIO_EnbIn, mdio_addr); 813 + mdio_delay(); 814 + iowrite8(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr); 815 + mdio_delay(); 816 + } 817 + } 818 + 819 + static int mdio_wait_link(struct net_device *dev, int wait) 820 + { 821 + int bmsr; 822 + int phy_id; 823 + struct netdev_private *np; 824 + 825 + np = netdev_priv(dev); 826 + phy_id = np->phys[0]; 827 + 828 + do { 829 + bmsr = mdio_read(dev, phy_id, MII_BMSR); 830 + if (bmsr & 0x0004) 831 + return 0; 832 + mdelay(1); 833 + } while (--wait > 0); 834 + return -1; 835 + } 836 + 837 + static int netdev_open(struct net_device *dev) 838 + { 839 + struct netdev_private *np = netdev_priv(dev); 840 + void __iomem *ioaddr = np->base; 841 + const int irq = np->pci_dev->irq; 842 + unsigned long flags; 843 + int i; 844 + 845 + sundance_reset(dev, 0x00ff << 16); 846 + 847 + i = request_irq(irq, intr_handler, IRQF_SHARED, dev->name, dev); 848 + if (i) 849 + return i; 850 + 851 + if (netif_msg_ifup(np)) 852 + printk(KERN_DEBUG "%s: netdev_open() irq %d\n", dev->name, irq); 853 + 854 + init_ring(dev); 855 + 856 + iowrite32(np->rx_ring_dma, ioaddr + RxListPtr); 857 + /* The Tx list pointer is written as packets are queued. */ 858 + 859 + /* Initialize other registers. */ 860 + __set_mac_addr(dev); 861 + #if IS_ENABLED(CONFIG_VLAN_8021Q) 862 + iowrite16(dev->mtu + 18, ioaddr + MaxFrameSize); 863 + #else 864 + iowrite16(dev->mtu + 14, ioaddr + MaxFrameSize); 865 + #endif 866 + if (dev->mtu > 2047) 867 + iowrite32(ioread32(ioaddr + ASICCtrl) | 0x0C, ioaddr + ASICCtrl); 868 + 869 + /* Configure the PCI bus bursts and FIFO thresholds. */ 870 + 871 + if (dev->if_port == 0) 872 + dev->if_port = np->default_port; 873 + 874 + spin_lock_init(&np->mcastlock); 875 + 876 + set_rx_mode(dev); 877 + iowrite16(0, ioaddr + IntrEnable); 878 + iowrite16(0, ioaddr + DownCounter); 879 + /* Set the chip to poll every N*320nsec. */ 880 + iowrite8(100, ioaddr + RxDMAPollPeriod); 881 + iowrite8(127, ioaddr + TxDMAPollPeriod); 882 + /* Fix DFE-580TX packet drop issue */ 883 + if (np->pci_dev->revision >= 0x14) 884 + iowrite8(0x01, ioaddr + DebugCtrl1); 885 + netif_start_queue(dev); 886 + 887 + spin_lock_irqsave(&np->lock, flags); 888 + reset_tx(dev); 889 + spin_unlock_irqrestore(&np->lock, flags); 890 + 891 + iowrite16 (StatsEnable | RxEnable | TxEnable, ioaddr + MACCtrl1); 892 + 893 + /* Disable Wol */ 894 + iowrite8(ioread8(ioaddr + WakeEvent) | 0x00, ioaddr + WakeEvent); 895 + np->wol_enabled = 0; 896 + 897 + if (netif_msg_ifup(np)) 898 + printk(KERN_DEBUG "%s: Done netdev_open(), status: Rx %x Tx %x " 899 + "MAC Control %x, %4.4x %4.4x.\n", 900 + dev->name, ioread32(ioaddr + RxStatus), ioread8(ioaddr + TxStatus), 901 + ioread32(ioaddr + MACCtrl0), 902 + ioread16(ioaddr + MACCtrl1), ioread16(ioaddr + MACCtrl0)); 903 + 904 + /* Set the timer to check for link beat. */ 905 + timer_setup(&np->timer, netdev_timer, 0); 906 + np->timer.expires = jiffies + 3*HZ; 907 + add_timer(&np->timer); 908 + 909 + /* Enable interrupts by setting the interrupt mask. */ 910 + iowrite16(DEFAULT_INTR, ioaddr + IntrEnable); 911 + 912 + return 0; 913 + } 914 + 915 + static void check_duplex(struct net_device *dev) 916 + { 917 + struct netdev_private *np = netdev_priv(dev); 918 + void __iomem *ioaddr = np->base; 919 + int mii_lpa = mdio_read(dev, np->phys[0], MII_LPA); 920 + int negotiated = mii_lpa & np->mii_if.advertising; 921 + int duplex; 922 + 923 + /* Force media */ 924 + if (!np->an_enable || mii_lpa == 0xffff) { 925 + if (np->mii_if.full_duplex) 926 + iowrite16 (ioread16 (ioaddr + MACCtrl0) | EnbFullDuplex, 927 + ioaddr + MACCtrl0); 928 + return; 929 + } 930 + 931 + /* Autonegotiation */ 932 + duplex = (negotiated & 0x0100) || (negotiated & 0x01C0) == 0x0040; 933 + if (np->mii_if.full_duplex != duplex) { 934 + np->mii_if.full_duplex = duplex; 935 + if (netif_msg_link(np)) 936 + printk(KERN_INFO "%s: Setting %s-duplex based on MII #%d " 937 + "negotiated capability %4.4x.\n", dev->name, 938 + duplex ? "full" : "half", np->phys[0], negotiated); 939 + iowrite16(ioread16(ioaddr + MACCtrl0) | (duplex ? 0x20 : 0), ioaddr + MACCtrl0); 940 + } 941 + } 942 + 943 + static void netdev_timer(struct timer_list *t) 944 + { 945 + struct netdev_private *np = timer_container_of(np, t, timer); 946 + struct net_device *dev = np->mii_if.dev; 947 + void __iomem *ioaddr = np->base; 948 + int next_tick = 10*HZ; 949 + 950 + if (netif_msg_timer(np)) { 951 + printk(KERN_DEBUG "%s: Media selection timer tick, intr status %4.4x, " 952 + "Tx %x Rx %x.\n", 953 + dev->name, ioread16(ioaddr + IntrEnable), 954 + ioread8(ioaddr + TxStatus), ioread32(ioaddr + RxStatus)); 955 + } 956 + check_duplex(dev); 957 + np->timer.expires = jiffies + next_tick; 958 + add_timer(&np->timer); 959 + } 960 + 961 + static void tx_timeout(struct net_device *dev, unsigned int txqueue) 962 + { 963 + struct netdev_private *np = netdev_priv(dev); 964 + void __iomem *ioaddr = np->base; 965 + unsigned long flag; 966 + 967 + netif_stop_queue(dev); 968 + tasklet_disable_in_atomic(&np->tx_tasklet); 969 + iowrite16(0, ioaddr + IntrEnable); 970 + printk(KERN_WARNING "%s: Transmit timed out, TxStatus %2.2x " 971 + "TxFrameId %2.2x," 972 + " resetting...\n", dev->name, ioread8(ioaddr + TxStatus), 973 + ioread8(ioaddr + TxFrameId)); 974 + 975 + { 976 + int i; 977 + for (i=0; i<TX_RING_SIZE; i++) { 978 + printk(KERN_DEBUG "%02x %08llx %08x %08x(%02x) %08x %08x\n", i, 979 + (unsigned long long)(np->tx_ring_dma + i*sizeof(*np->tx_ring)), 980 + le32_to_cpu(np->tx_ring[i].next_desc), 981 + le32_to_cpu(np->tx_ring[i].status), 982 + (le32_to_cpu(np->tx_ring[i].status) >> 2) & 0xff, 983 + le32_to_cpu(np->tx_ring[i].frag.addr), 984 + le32_to_cpu(np->tx_ring[i].frag.length)); 985 + } 986 + printk(KERN_DEBUG "TxListPtr=%08x netif_queue_stopped=%d\n", 987 + ioread32(np->base + TxListPtr), 988 + netif_queue_stopped(dev)); 989 + printk(KERN_DEBUG "cur_tx=%d(%02x) dirty_tx=%d(%02x)\n", 990 + np->cur_tx, np->cur_tx % TX_RING_SIZE, 991 + np->dirty_tx, np->dirty_tx % TX_RING_SIZE); 992 + printk(KERN_DEBUG "cur_rx=%d dirty_rx=%d\n", np->cur_rx, np->dirty_rx); 993 + printk(KERN_DEBUG "cur_task=%d\n", np->cur_task); 994 + } 995 + spin_lock_irqsave(&np->lock, flag); 996 + 997 + /* Stop and restart the chip's Tx processes . */ 998 + reset_tx(dev); 999 + spin_unlock_irqrestore(&np->lock, flag); 1000 + 1001 + dev->if_port = 0; 1002 + 1003 + netif_trans_update(dev); /* prevent tx timeout */ 1004 + dev->stats.tx_errors++; 1005 + if (np->cur_tx - np->dirty_tx < TX_QUEUE_LEN - 4) { 1006 + netif_wake_queue(dev); 1007 + } 1008 + iowrite16(DEFAULT_INTR, ioaddr + IntrEnable); 1009 + tasklet_enable(&np->tx_tasklet); 1010 + } 1011 + 1012 + 1013 + /* Initialize the Rx and Tx rings, along with various 'dev' bits. */ 1014 + static void init_ring(struct net_device *dev) 1015 + { 1016 + struct netdev_private *np = netdev_priv(dev); 1017 + int i; 1018 + 1019 + np->cur_rx = np->cur_tx = 0; 1020 + np->dirty_rx = np->dirty_tx = 0; 1021 + np->cur_task = 0; 1022 + 1023 + np->rx_buf_sz = (dev->mtu <= 1520 ? PKT_BUF_SZ : dev->mtu + 16); 1024 + 1025 + /* Initialize all Rx descriptors. */ 1026 + for (i = 0; i < RX_RING_SIZE; i++) { 1027 + np->rx_ring[i].next_desc = cpu_to_le32(np->rx_ring_dma + 1028 + ((i+1)%RX_RING_SIZE)*sizeof(*np->rx_ring)); 1029 + np->rx_ring[i].status = 0; 1030 + np->rx_ring[i].frag.length = 0; 1031 + np->rx_skbuff[i] = NULL; 1032 + } 1033 + 1034 + /* Fill in the Rx buffers. Handle allocation failure gracefully. */ 1035 + for (i = 0; i < RX_RING_SIZE; i++) { 1036 + dma_addr_t addr; 1037 + 1038 + struct sk_buff *skb = 1039 + netdev_alloc_skb(dev, np->rx_buf_sz + 2); 1040 + np->rx_skbuff[i] = skb; 1041 + if (skb == NULL) 1042 + break; 1043 + skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1044 + addr = dma_map_single(&np->pci_dev->dev, skb->data, 1045 + np->rx_buf_sz, DMA_FROM_DEVICE); 1046 + if (dma_mapping_error(&np->pci_dev->dev, addr)) { 1047 + dev_kfree_skb(skb); 1048 + np->rx_skbuff[i] = NULL; 1049 + break; 1050 + } 1051 + np->rx_ring[i].frag.addr = cpu_to_le32(addr); 1052 + np->rx_ring[i].frag.length = cpu_to_le32(np->rx_buf_sz | LastFrag); 1053 + } 1054 + np->dirty_rx = (unsigned int)(i - RX_RING_SIZE); 1055 + 1056 + for (i = 0; i < TX_RING_SIZE; i++) { 1057 + np->tx_skbuff[i] = NULL; 1058 + np->tx_ring[i].status = 0; 1059 + } 1060 + } 1061 + 1062 + static void tx_poll(struct tasklet_struct *t) 1063 + { 1064 + struct netdev_private *np = from_tasklet(np, t, tx_tasklet); 1065 + unsigned head = np->cur_task % TX_RING_SIZE; 1066 + struct netdev_desc *txdesc = 1067 + &np->tx_ring[(np->cur_tx - 1) % TX_RING_SIZE]; 1068 + 1069 + /* Chain the next pointer */ 1070 + for (; np->cur_tx - np->cur_task > 0; np->cur_task++) { 1071 + int entry = np->cur_task % TX_RING_SIZE; 1072 + txdesc = &np->tx_ring[entry]; 1073 + if (np->last_tx) { 1074 + np->last_tx->next_desc = cpu_to_le32(np->tx_ring_dma + 1075 + entry*sizeof(struct netdev_desc)); 1076 + } 1077 + np->last_tx = txdesc; 1078 + } 1079 + /* Indicate the latest descriptor of tx ring */ 1080 + txdesc->status |= cpu_to_le32(DescIntrOnTx); 1081 + 1082 + if (ioread32 (np->base + TxListPtr) == 0) 1083 + iowrite32 (np->tx_ring_dma + head * sizeof(struct netdev_desc), 1084 + np->base + TxListPtr); 1085 + } 1086 + 1087 + static netdev_tx_t 1088 + start_tx (struct sk_buff *skb, struct net_device *dev) 1089 + { 1090 + struct netdev_private *np = netdev_priv(dev); 1091 + struct netdev_desc *txdesc; 1092 + dma_addr_t addr; 1093 + unsigned entry; 1094 + 1095 + /* Calculate the next Tx descriptor entry. */ 1096 + entry = np->cur_tx % TX_RING_SIZE; 1097 + np->tx_skbuff[entry] = skb; 1098 + txdesc = &np->tx_ring[entry]; 1099 + 1100 + addr = dma_map_single(&np->pci_dev->dev, skb->data, skb->len, 1101 + DMA_TO_DEVICE); 1102 + if (dma_mapping_error(&np->pci_dev->dev, addr)) 1103 + goto drop_frame; 1104 + 1105 + txdesc->next_desc = 0; 1106 + txdesc->status = cpu_to_le32 ((entry << 2) | DisableAlign); 1107 + txdesc->frag.addr = cpu_to_le32(addr); 1108 + txdesc->frag.length = cpu_to_le32 (skb->len | LastFrag); 1109 + 1110 + /* Increment cur_tx before tasklet_schedule() */ 1111 + np->cur_tx++; 1112 + mb(); 1113 + /* Schedule a tx_poll() task */ 1114 + tasklet_schedule(&np->tx_tasklet); 1115 + 1116 + /* On some architectures: explicitly flush cache lines here. */ 1117 + if (np->cur_tx - np->dirty_tx < TX_QUEUE_LEN - 1 && 1118 + !netif_queue_stopped(dev)) { 1119 + /* do nothing */ 1120 + } else { 1121 + netif_stop_queue (dev); 1122 + } 1123 + if (netif_msg_tx_queued(np)) { 1124 + printk (KERN_DEBUG 1125 + "%s: Transmit frame #%d queued in slot %d.\n", 1126 + dev->name, np->cur_tx, entry); 1127 + } 1128 + return NETDEV_TX_OK; 1129 + 1130 + drop_frame: 1131 + dev_kfree_skb_any(skb); 1132 + np->tx_skbuff[entry] = NULL; 1133 + dev->stats.tx_dropped++; 1134 + return NETDEV_TX_OK; 1135 + } 1136 + 1137 + /* Reset hardware tx and free all of tx buffers */ 1138 + static int 1139 + reset_tx (struct net_device *dev) 1140 + { 1141 + struct netdev_private *np = netdev_priv(dev); 1142 + void __iomem *ioaddr = np->base; 1143 + struct sk_buff *skb; 1144 + int i; 1145 + 1146 + /* Reset tx logic, TxListPtr will be cleaned */ 1147 + iowrite16 (TxDisable, ioaddr + MACCtrl1); 1148 + sundance_reset(dev, (NetworkReset|FIFOReset|DMAReset|TxReset) << 16); 1149 + 1150 + /* free all tx skbuff */ 1151 + for (i = 0; i < TX_RING_SIZE; i++) { 1152 + np->tx_ring[i].next_desc = 0; 1153 + 1154 + skb = np->tx_skbuff[i]; 1155 + if (skb) { 1156 + dma_unmap_single(&np->pci_dev->dev, 1157 + le32_to_cpu(np->tx_ring[i].frag.addr), 1158 + skb->len, DMA_TO_DEVICE); 1159 + dev_kfree_skb_any(skb); 1160 + np->tx_skbuff[i] = NULL; 1161 + dev->stats.tx_dropped++; 1162 + } 1163 + } 1164 + np->cur_tx = np->dirty_tx = 0; 1165 + np->cur_task = 0; 1166 + 1167 + np->last_tx = NULL; 1168 + iowrite8(127, ioaddr + TxDMAPollPeriod); 1169 + 1170 + iowrite16 (StatsEnable | RxEnable | TxEnable, ioaddr + MACCtrl1); 1171 + return 0; 1172 + } 1173 + 1174 + /* The interrupt handler cleans up after the Tx thread, 1175 + and schedule a Rx thread work */ 1176 + static irqreturn_t intr_handler(int irq, void *dev_instance) 1177 + { 1178 + struct net_device *dev = (struct net_device *)dev_instance; 1179 + struct netdev_private *np = netdev_priv(dev); 1180 + void __iomem *ioaddr = np->base; 1181 + int hw_frame_id; 1182 + int tx_cnt; 1183 + int tx_status; 1184 + int handled = 0; 1185 + int i; 1186 + 1187 + do { 1188 + int intr_status = ioread16(ioaddr + IntrStatus); 1189 + iowrite16(intr_status, ioaddr + IntrStatus); 1190 + 1191 + if (netif_msg_intr(np)) 1192 + printk(KERN_DEBUG "%s: Interrupt, status %4.4x.\n", 1193 + dev->name, intr_status); 1194 + 1195 + if (!(intr_status & DEFAULT_INTR)) 1196 + break; 1197 + 1198 + handled = 1; 1199 + 1200 + if (intr_status & (IntrRxDMADone)) { 1201 + iowrite16(DEFAULT_INTR & ~(IntrRxDone|IntrRxDMADone), 1202 + ioaddr + IntrEnable); 1203 + if (np->budget < 0) 1204 + np->budget = RX_BUDGET; 1205 + tasklet_schedule(&np->rx_tasklet); 1206 + } 1207 + if (intr_status & (IntrTxDone | IntrDrvRqst)) { 1208 + tx_status = ioread16 (ioaddr + TxStatus); 1209 + for (tx_cnt=32; tx_status & 0x80; --tx_cnt) { 1210 + if (netif_msg_tx_done(np)) 1211 + printk 1212 + ("%s: Transmit status is %2.2x.\n", 1213 + dev->name, tx_status); 1214 + if (tx_status & 0x1e) { 1215 + if (netif_msg_tx_err(np)) 1216 + printk("%s: Transmit error status %4.4x.\n", 1217 + dev->name, tx_status); 1218 + dev->stats.tx_errors++; 1219 + if (tx_status & 0x10) 1220 + dev->stats.tx_fifo_errors++; 1221 + if (tx_status & 0x08) 1222 + dev->stats.collisions++; 1223 + if (tx_status & 0x04) 1224 + dev->stats.tx_fifo_errors++; 1225 + if (tx_status & 0x02) 1226 + dev->stats.tx_window_errors++; 1227 + 1228 + /* 1229 + ** This reset has been verified on 1230 + ** DFE-580TX boards ! phdm@macqel.be. 1231 + */ 1232 + if (tx_status & 0x10) { /* TxUnderrun */ 1233 + /* Restart Tx FIFO and transmitter */ 1234 + sundance_reset(dev, (NetworkReset|FIFOReset|TxReset) << 16); 1235 + /* No need to reset the Tx pointer here */ 1236 + } 1237 + /* Restart the Tx. Need to make sure tx enabled */ 1238 + i = 10; 1239 + do { 1240 + iowrite16(ioread16(ioaddr + MACCtrl1) | TxEnable, ioaddr + MACCtrl1); 1241 + if (ioread16(ioaddr + MACCtrl1) & TxEnabled) 1242 + break; 1243 + mdelay(1); 1244 + } while (--i); 1245 + } 1246 + /* Yup, this is a documentation bug. It cost me *hours*. */ 1247 + iowrite16 (0, ioaddr + TxStatus); 1248 + if (tx_cnt < 0) { 1249 + iowrite32(5000, ioaddr + DownCounter); 1250 + break; 1251 + } 1252 + tx_status = ioread16 (ioaddr + TxStatus); 1253 + } 1254 + hw_frame_id = (tx_status >> 8) & 0xff; 1255 + } else { 1256 + hw_frame_id = ioread8(ioaddr + TxFrameId); 1257 + } 1258 + 1259 + if (np->pci_dev->revision >= 0x14) { 1260 + spin_lock(&np->lock); 1261 + for (; np->cur_tx - np->dirty_tx > 0; np->dirty_tx++) { 1262 + int entry = np->dirty_tx % TX_RING_SIZE; 1263 + struct sk_buff *skb; 1264 + int sw_frame_id; 1265 + sw_frame_id = (le32_to_cpu( 1266 + np->tx_ring[entry].status) >> 2) & 0xff; 1267 + if (sw_frame_id == hw_frame_id && 1268 + !(le32_to_cpu(np->tx_ring[entry].status) 1269 + & 0x00010000)) 1270 + break; 1271 + if (sw_frame_id == (hw_frame_id + 1) % 1272 + TX_RING_SIZE) 1273 + break; 1274 + skb = np->tx_skbuff[entry]; 1275 + /* Free the original skb. */ 1276 + dma_unmap_single(&np->pci_dev->dev, 1277 + le32_to_cpu(np->tx_ring[entry].frag.addr), 1278 + skb->len, DMA_TO_DEVICE); 1279 + dev_consume_skb_irq(np->tx_skbuff[entry]); 1280 + np->tx_skbuff[entry] = NULL; 1281 + np->tx_ring[entry].frag.addr = 0; 1282 + np->tx_ring[entry].frag.length = 0; 1283 + } 1284 + spin_unlock(&np->lock); 1285 + } else { 1286 + spin_lock(&np->lock); 1287 + for (; np->cur_tx - np->dirty_tx > 0; np->dirty_tx++) { 1288 + int entry = np->dirty_tx % TX_RING_SIZE; 1289 + struct sk_buff *skb; 1290 + if (!(le32_to_cpu(np->tx_ring[entry].status) 1291 + & 0x00010000)) 1292 + break; 1293 + skb = np->tx_skbuff[entry]; 1294 + /* Free the original skb. */ 1295 + dma_unmap_single(&np->pci_dev->dev, 1296 + le32_to_cpu(np->tx_ring[entry].frag.addr), 1297 + skb->len, DMA_TO_DEVICE); 1298 + dev_consume_skb_irq(np->tx_skbuff[entry]); 1299 + np->tx_skbuff[entry] = NULL; 1300 + np->tx_ring[entry].frag.addr = 0; 1301 + np->tx_ring[entry].frag.length = 0; 1302 + } 1303 + spin_unlock(&np->lock); 1304 + } 1305 + 1306 + if (netif_queue_stopped(dev) && 1307 + np->cur_tx - np->dirty_tx < TX_QUEUE_LEN - 4) { 1308 + /* The ring is no longer full, clear busy flag. */ 1309 + netif_wake_queue (dev); 1310 + } 1311 + /* Abnormal error summary/uncommon events handlers. */ 1312 + if (intr_status & (IntrPCIErr | LinkChange | StatsMax)) 1313 + netdev_error(dev, intr_status); 1314 + } while (0); 1315 + if (netif_msg_intr(np)) 1316 + printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n", 1317 + dev->name, ioread16(ioaddr + IntrStatus)); 1318 + return IRQ_RETVAL(handled); 1319 + } 1320 + 1321 + static void rx_poll(struct tasklet_struct *t) 1322 + { 1323 + struct netdev_private *np = from_tasklet(np, t, rx_tasklet); 1324 + struct net_device *dev = np->ndev; 1325 + int entry = np->cur_rx % RX_RING_SIZE; 1326 + int boguscnt = np->budget; 1327 + void __iomem *ioaddr = np->base; 1328 + int received = 0; 1329 + 1330 + /* If EOP is set on the next entry, it's a new packet. Send it up. */ 1331 + while (1) { 1332 + struct netdev_desc *desc = &(np->rx_ring[entry]); 1333 + u32 frame_status = le32_to_cpu(desc->status); 1334 + int pkt_len; 1335 + 1336 + if (--boguscnt < 0) { 1337 + goto not_done; 1338 + } 1339 + if (!(frame_status & DescOwn)) 1340 + break; 1341 + pkt_len = frame_status & 0x1fff; /* Chip omits the CRC. */ 1342 + if (netif_msg_rx_status(np)) 1343 + printk(KERN_DEBUG " netdev_rx() status was %8.8x.\n", 1344 + frame_status); 1345 + if (frame_status & 0x001f4000) { 1346 + /* There was a error. */ 1347 + if (netif_msg_rx_err(np)) 1348 + printk(KERN_DEBUG " netdev_rx() Rx error was %8.8x.\n", 1349 + frame_status); 1350 + dev->stats.rx_errors++; 1351 + if (frame_status & 0x00100000) 1352 + dev->stats.rx_length_errors++; 1353 + if (frame_status & 0x00010000) 1354 + dev->stats.rx_fifo_errors++; 1355 + if (frame_status & 0x00060000) 1356 + dev->stats.rx_frame_errors++; 1357 + if (frame_status & 0x00080000) 1358 + dev->stats.rx_crc_errors++; 1359 + if (frame_status & 0x00100000) { 1360 + printk(KERN_WARNING "%s: Oversized Ethernet frame," 1361 + " status %8.8x.\n", 1362 + dev->name, frame_status); 1363 + } 1364 + } else { 1365 + struct sk_buff *skb; 1366 + #ifndef final_version 1367 + if (netif_msg_rx_status(np)) 1368 + printk(KERN_DEBUG " netdev_rx() normal Rx pkt length %d" 1369 + ", bogus_cnt %d.\n", 1370 + pkt_len, boguscnt); 1371 + #endif 1372 + /* Check if the packet is long enough to accept without copying 1373 + to a minimally-sized skbuff. */ 1374 + if (pkt_len < rx_copybreak && 1375 + (skb = netdev_alloc_skb(dev, pkt_len + 2)) != NULL) { 1376 + skb_reserve(skb, 2); /* 16 byte align the IP header */ 1377 + dma_sync_single_for_cpu(&np->pci_dev->dev, 1378 + le32_to_cpu(desc->frag.addr), 1379 + np->rx_buf_sz, DMA_FROM_DEVICE); 1380 + skb_copy_to_linear_data(skb, np->rx_skbuff[entry]->data, pkt_len); 1381 + dma_sync_single_for_device(&np->pci_dev->dev, 1382 + le32_to_cpu(desc->frag.addr), 1383 + np->rx_buf_sz, DMA_FROM_DEVICE); 1384 + skb_put(skb, pkt_len); 1385 + } else { 1386 + dma_unmap_single(&np->pci_dev->dev, 1387 + le32_to_cpu(desc->frag.addr), 1388 + np->rx_buf_sz, DMA_FROM_DEVICE); 1389 + skb_put(skb = np->rx_skbuff[entry], pkt_len); 1390 + np->rx_skbuff[entry] = NULL; 1391 + } 1392 + skb->protocol = eth_type_trans(skb, dev); 1393 + /* Note: checksum -> skb->ip_summed = CHECKSUM_UNNECESSARY; */ 1394 + netif_rx(skb); 1395 + } 1396 + entry = (entry + 1) % RX_RING_SIZE; 1397 + received++; 1398 + } 1399 + np->cur_rx = entry; 1400 + refill_rx (dev); 1401 + np->budget -= received; 1402 + iowrite16(DEFAULT_INTR, ioaddr + IntrEnable); 1403 + return; 1404 + 1405 + not_done: 1406 + np->cur_rx = entry; 1407 + refill_rx (dev); 1408 + if (!received) 1409 + received = 1; 1410 + np->budget -= received; 1411 + if (np->budget <= 0) 1412 + np->budget = RX_BUDGET; 1413 + tasklet_schedule(&np->rx_tasklet); 1414 + } 1415 + 1416 + static void refill_rx (struct net_device *dev) 1417 + { 1418 + struct netdev_private *np = netdev_priv(dev); 1419 + int entry; 1420 + 1421 + /* Refill the Rx ring buffers. */ 1422 + for (;(np->cur_rx - np->dirty_rx + RX_RING_SIZE) % RX_RING_SIZE > 0; 1423 + np->dirty_rx = (np->dirty_rx + 1) % RX_RING_SIZE) { 1424 + struct sk_buff *skb; 1425 + dma_addr_t addr; 1426 + 1427 + entry = np->dirty_rx % RX_RING_SIZE; 1428 + if (np->rx_skbuff[entry] == NULL) { 1429 + skb = netdev_alloc_skb(dev, np->rx_buf_sz + 2); 1430 + np->rx_skbuff[entry] = skb; 1431 + if (skb == NULL) 1432 + break; /* Better luck next round. */ 1433 + skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1434 + addr = dma_map_single(&np->pci_dev->dev, skb->data, 1435 + np->rx_buf_sz, DMA_FROM_DEVICE); 1436 + if (dma_mapping_error(&np->pci_dev->dev, addr)) { 1437 + dev_kfree_skb_irq(skb); 1438 + np->rx_skbuff[entry] = NULL; 1439 + break; 1440 + } 1441 + 1442 + np->rx_ring[entry].frag.addr = cpu_to_le32(addr); 1443 + } 1444 + /* Perhaps we need not reset this field. */ 1445 + np->rx_ring[entry].frag.length = 1446 + cpu_to_le32(np->rx_buf_sz | LastFrag); 1447 + np->rx_ring[entry].status = 0; 1448 + } 1449 + } 1450 + static void netdev_error(struct net_device *dev, int intr_status) 1451 + { 1452 + struct netdev_private *np = netdev_priv(dev); 1453 + void __iomem *ioaddr = np->base; 1454 + u16 mii_ctl, mii_advertise, mii_lpa; 1455 + int speed; 1456 + 1457 + if (intr_status & LinkChange) { 1458 + if (mdio_wait_link(dev, 10) == 0) { 1459 + printk(KERN_INFO "%s: Link up\n", dev->name); 1460 + if (np->an_enable) { 1461 + mii_advertise = mdio_read(dev, np->phys[0], 1462 + MII_ADVERTISE); 1463 + mii_lpa = mdio_read(dev, np->phys[0], MII_LPA); 1464 + mii_advertise &= mii_lpa; 1465 + printk(KERN_INFO "%s: Link changed: ", 1466 + dev->name); 1467 + if (mii_advertise & ADVERTISE_100FULL) { 1468 + np->speed = 100; 1469 + printk("100Mbps, full duplex\n"); 1470 + } else if (mii_advertise & ADVERTISE_100HALF) { 1471 + np->speed = 100; 1472 + printk("100Mbps, half duplex\n"); 1473 + } else if (mii_advertise & ADVERTISE_10FULL) { 1474 + np->speed = 10; 1475 + printk("10Mbps, full duplex\n"); 1476 + } else if (mii_advertise & ADVERTISE_10HALF) { 1477 + np->speed = 10; 1478 + printk("10Mbps, half duplex\n"); 1479 + } else 1480 + printk("\n"); 1481 + 1482 + } else { 1483 + mii_ctl = mdio_read(dev, np->phys[0], MII_BMCR); 1484 + speed = (mii_ctl & BMCR_SPEED100) ? 100 : 10; 1485 + np->speed = speed; 1486 + printk(KERN_INFO "%s: Link changed: %dMbps ,", 1487 + dev->name, speed); 1488 + printk("%s duplex.\n", 1489 + (mii_ctl & BMCR_FULLDPLX) ? 1490 + "full" : "half"); 1491 + } 1492 + check_duplex(dev); 1493 + if (np->flowctrl && np->mii_if.full_duplex) { 1494 + iowrite16(ioread16(ioaddr + MulticastFilter1+2) | 0x0200, 1495 + ioaddr + MulticastFilter1+2); 1496 + iowrite16(ioread16(ioaddr + MACCtrl0) | EnbFlowCtrl, 1497 + ioaddr + MACCtrl0); 1498 + } 1499 + netif_carrier_on(dev); 1500 + } else { 1501 + printk(KERN_INFO "%s: Link down\n", dev->name); 1502 + netif_carrier_off(dev); 1503 + } 1504 + } 1505 + if (intr_status & StatsMax) { 1506 + get_stats(dev); 1507 + } 1508 + if (intr_status & IntrPCIErr) { 1509 + printk(KERN_ERR "%s: Something Wicked happened! %4.4x.\n", 1510 + dev->name, intr_status); 1511 + /* We must do a global reset of DMA to continue. */ 1512 + } 1513 + } 1514 + 1515 + static struct net_device_stats *get_stats(struct net_device *dev) 1516 + { 1517 + struct netdev_private *np = netdev_priv(dev); 1518 + void __iomem *ioaddr = np->base; 1519 + unsigned long flags; 1520 + u8 late_coll, single_coll, mult_coll; 1521 + 1522 + spin_lock_irqsave(&np->statlock, flags); 1523 + /* The chip only need report frame silently dropped. */ 1524 + dev->stats.rx_missed_errors += ioread8(ioaddr + RxMissed); 1525 + dev->stats.tx_packets += ioread16(ioaddr + TxFramesOK); 1526 + dev->stats.rx_packets += ioread16(ioaddr + RxFramesOK); 1527 + dev->stats.tx_carrier_errors += ioread8(ioaddr + StatsCarrierError); 1528 + 1529 + mult_coll = ioread8(ioaddr + StatsMultiColl); 1530 + np->xstats.tx_multiple_collisions += mult_coll; 1531 + single_coll = ioread8(ioaddr + StatsOneColl); 1532 + np->xstats.tx_single_collisions += single_coll; 1533 + late_coll = ioread8(ioaddr + StatsLateColl); 1534 + np->xstats.tx_late_collisions += late_coll; 1535 + dev->stats.collisions += mult_coll 1536 + + single_coll 1537 + + late_coll; 1538 + 1539 + np->xstats.tx_deferred += ioread8(ioaddr + StatsTxDefer); 1540 + np->xstats.tx_deferred_excessive += ioread8(ioaddr + StatsTxXSDefer); 1541 + np->xstats.tx_aborted += ioread8(ioaddr + StatsTxAbort); 1542 + np->xstats.tx_bcasts += ioread8(ioaddr + StatsBcastTx); 1543 + np->xstats.rx_bcasts += ioread8(ioaddr + StatsBcastRx); 1544 + np->xstats.tx_mcasts += ioread8(ioaddr + StatsMcastTx); 1545 + np->xstats.rx_mcasts += ioread8(ioaddr + StatsMcastRx); 1546 + 1547 + dev->stats.tx_bytes += ioread16(ioaddr + TxOctetsLow); 1548 + dev->stats.tx_bytes += ioread16(ioaddr + TxOctetsHigh) << 16; 1549 + dev->stats.rx_bytes += ioread16(ioaddr + RxOctetsLow); 1550 + dev->stats.rx_bytes += ioread16(ioaddr + RxOctetsHigh) << 16; 1551 + 1552 + spin_unlock_irqrestore(&np->statlock, flags); 1553 + 1554 + return &dev->stats; 1555 + } 1556 + 1557 + static void set_rx_mode(struct net_device *dev) 1558 + { 1559 + struct netdev_private *np = netdev_priv(dev); 1560 + void __iomem *ioaddr = np->base; 1561 + u16 mc_filter[4]; /* Multicast hash filter */ 1562 + u32 rx_mode; 1563 + int i; 1564 + 1565 + if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ 1566 + memset(mc_filter, 0xff, sizeof(mc_filter)); 1567 + rx_mode = AcceptBroadcast | AcceptMulticast | AcceptAll | AcceptMyPhys; 1568 + } else if ((netdev_mc_count(dev) > multicast_filter_limit) || 1569 + (dev->flags & IFF_ALLMULTI)) { 1570 + /* Too many to match, or accept all multicasts. */ 1571 + memset(mc_filter, 0xff, sizeof(mc_filter)); 1572 + rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; 1573 + } else if (!netdev_mc_empty(dev)) { 1574 + struct netdev_hw_addr *ha; 1575 + int bit; 1576 + int index; 1577 + int crc; 1578 + memset (mc_filter, 0, sizeof (mc_filter)); 1579 + netdev_for_each_mc_addr(ha, dev) { 1580 + crc = ether_crc_le(ETH_ALEN, ha->addr); 1581 + for (index=0, bit=0; bit < 6; bit++, crc <<= 1) 1582 + if (crc & 0x80000000) index |= 1 << bit; 1583 + mc_filter[index/16] |= (1 << (index % 16)); 1584 + } 1585 + rx_mode = AcceptBroadcast | AcceptMultiHash | AcceptMyPhys; 1586 + } else { 1587 + iowrite8(AcceptBroadcast | AcceptMyPhys, ioaddr + RxMode); 1588 + return; 1589 + } 1590 + if (np->mii_if.full_duplex && np->flowctrl) 1591 + mc_filter[3] |= 0x0200; 1592 + 1593 + for (i = 0; i < 4; i++) 1594 + iowrite16(mc_filter[i], ioaddr + MulticastFilter0 + i*2); 1595 + iowrite8(rx_mode, ioaddr + RxMode); 1596 + } 1597 + 1598 + static int __set_mac_addr(struct net_device *dev) 1599 + { 1600 + struct netdev_private *np = netdev_priv(dev); 1601 + u16 addr16; 1602 + 1603 + addr16 = (dev->dev_addr[0] | (dev->dev_addr[1] << 8)); 1604 + iowrite16(addr16, np->base + StationAddr); 1605 + addr16 = (dev->dev_addr[2] | (dev->dev_addr[3] << 8)); 1606 + iowrite16(addr16, np->base + StationAddr+2); 1607 + addr16 = (dev->dev_addr[4] | (dev->dev_addr[5] << 8)); 1608 + iowrite16(addr16, np->base + StationAddr+4); 1609 + return 0; 1610 + } 1611 + 1612 + /* Invoked with rtnl_lock held */ 1613 + static int sundance_set_mac_addr(struct net_device *dev, void *data) 1614 + { 1615 + const struct sockaddr *addr = data; 1616 + 1617 + if (!is_valid_ether_addr(addr->sa_data)) 1618 + return -EADDRNOTAVAIL; 1619 + eth_hw_addr_set(dev, addr->sa_data); 1620 + __set_mac_addr(dev); 1621 + 1622 + return 0; 1623 + } 1624 + 1625 + static const struct { 1626 + const char name[ETH_GSTRING_LEN]; 1627 + } sundance_stats[] = { 1628 + { "tx_multiple_collisions" }, 1629 + { "tx_single_collisions" }, 1630 + { "tx_late_collisions" }, 1631 + { "tx_deferred" }, 1632 + { "tx_deferred_excessive" }, 1633 + { "tx_aborted" }, 1634 + { "tx_bcasts" }, 1635 + { "rx_bcasts" }, 1636 + { "tx_mcasts" }, 1637 + { "rx_mcasts" }, 1638 + }; 1639 + 1640 + static int check_if_running(struct net_device *dev) 1641 + { 1642 + if (!netif_running(dev)) 1643 + return -EINVAL; 1644 + return 0; 1645 + } 1646 + 1647 + static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 1648 + { 1649 + struct netdev_private *np = netdev_priv(dev); 1650 + strscpy(info->driver, DRV_NAME, sizeof(info->driver)); 1651 + strscpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info)); 1652 + } 1653 + 1654 + static int get_link_ksettings(struct net_device *dev, 1655 + struct ethtool_link_ksettings *cmd) 1656 + { 1657 + struct netdev_private *np = netdev_priv(dev); 1658 + spin_lock_irq(&np->lock); 1659 + mii_ethtool_get_link_ksettings(&np->mii_if, cmd); 1660 + spin_unlock_irq(&np->lock); 1661 + return 0; 1662 + } 1663 + 1664 + static int set_link_ksettings(struct net_device *dev, 1665 + const struct ethtool_link_ksettings *cmd) 1666 + { 1667 + struct netdev_private *np = netdev_priv(dev); 1668 + int res; 1669 + spin_lock_irq(&np->lock); 1670 + res = mii_ethtool_set_link_ksettings(&np->mii_if, cmd); 1671 + spin_unlock_irq(&np->lock); 1672 + return res; 1673 + } 1674 + 1675 + static int nway_reset(struct net_device *dev) 1676 + { 1677 + struct netdev_private *np = netdev_priv(dev); 1678 + return mii_nway_restart(&np->mii_if); 1679 + } 1680 + 1681 + static u32 get_link(struct net_device *dev) 1682 + { 1683 + struct netdev_private *np = netdev_priv(dev); 1684 + return mii_link_ok(&np->mii_if); 1685 + } 1686 + 1687 + static u32 get_msglevel(struct net_device *dev) 1688 + { 1689 + struct netdev_private *np = netdev_priv(dev); 1690 + return np->msg_enable; 1691 + } 1692 + 1693 + static void set_msglevel(struct net_device *dev, u32 val) 1694 + { 1695 + struct netdev_private *np = netdev_priv(dev); 1696 + np->msg_enable = val; 1697 + } 1698 + 1699 + static void get_strings(struct net_device *dev, u32 stringset, 1700 + u8 *data) 1701 + { 1702 + if (stringset == ETH_SS_STATS) 1703 + memcpy(data, sundance_stats, sizeof(sundance_stats)); 1704 + } 1705 + 1706 + static int get_sset_count(struct net_device *dev, int sset) 1707 + { 1708 + switch (sset) { 1709 + case ETH_SS_STATS: 1710 + return ARRAY_SIZE(sundance_stats); 1711 + default: 1712 + return -EOPNOTSUPP; 1713 + } 1714 + } 1715 + 1716 + static void get_ethtool_stats(struct net_device *dev, 1717 + struct ethtool_stats *stats, u64 *data) 1718 + { 1719 + struct netdev_private *np = netdev_priv(dev); 1720 + int i = 0; 1721 + 1722 + get_stats(dev); 1723 + data[i++] = np->xstats.tx_multiple_collisions; 1724 + data[i++] = np->xstats.tx_single_collisions; 1725 + data[i++] = np->xstats.tx_late_collisions; 1726 + data[i++] = np->xstats.tx_deferred; 1727 + data[i++] = np->xstats.tx_deferred_excessive; 1728 + data[i++] = np->xstats.tx_aborted; 1729 + data[i++] = np->xstats.tx_bcasts; 1730 + data[i++] = np->xstats.rx_bcasts; 1731 + data[i++] = np->xstats.tx_mcasts; 1732 + data[i++] = np->xstats.rx_mcasts; 1733 + } 1734 + 1735 + #ifdef CONFIG_PM 1736 + 1737 + static void sundance_get_wol(struct net_device *dev, 1738 + struct ethtool_wolinfo *wol) 1739 + { 1740 + struct netdev_private *np = netdev_priv(dev); 1741 + void __iomem *ioaddr = np->base; 1742 + u8 wol_bits; 1743 + 1744 + wol->wolopts = 0; 1745 + 1746 + wol->supported = (WAKE_PHY | WAKE_MAGIC); 1747 + if (!np->wol_enabled) 1748 + return; 1749 + 1750 + wol_bits = ioread8(ioaddr + WakeEvent); 1751 + if (wol_bits & MagicPktEnable) 1752 + wol->wolopts |= WAKE_MAGIC; 1753 + if (wol_bits & LinkEventEnable) 1754 + wol->wolopts |= WAKE_PHY; 1755 + } 1756 + 1757 + static int sundance_set_wol(struct net_device *dev, 1758 + struct ethtool_wolinfo *wol) 1759 + { 1760 + struct netdev_private *np = netdev_priv(dev); 1761 + void __iomem *ioaddr = np->base; 1762 + u8 wol_bits; 1763 + 1764 + if (!device_can_wakeup(&np->pci_dev->dev)) 1765 + return -EOPNOTSUPP; 1766 + 1767 + np->wol_enabled = !!(wol->wolopts); 1768 + wol_bits = ioread8(ioaddr + WakeEvent); 1769 + wol_bits &= ~(WakePktEnable | MagicPktEnable | 1770 + LinkEventEnable | WolEnable); 1771 + 1772 + if (np->wol_enabled) { 1773 + if (wol->wolopts & WAKE_MAGIC) 1774 + wol_bits |= (MagicPktEnable | WolEnable); 1775 + if (wol->wolopts & WAKE_PHY) 1776 + wol_bits |= (LinkEventEnable | WolEnable); 1777 + } 1778 + iowrite8(wol_bits, ioaddr + WakeEvent); 1779 + 1780 + device_set_wakeup_enable(&np->pci_dev->dev, np->wol_enabled); 1781 + 1782 + return 0; 1783 + } 1784 + #else 1785 + #define sundance_get_wol NULL 1786 + #define sundance_set_wol NULL 1787 + #endif /* CONFIG_PM */ 1788 + 1789 + static const struct ethtool_ops ethtool_ops = { 1790 + .begin = check_if_running, 1791 + .get_drvinfo = get_drvinfo, 1792 + .nway_reset = nway_reset, 1793 + .get_link = get_link, 1794 + .get_wol = sundance_get_wol, 1795 + .set_wol = sundance_set_wol, 1796 + .get_msglevel = get_msglevel, 1797 + .set_msglevel = set_msglevel, 1798 + .get_strings = get_strings, 1799 + .get_sset_count = get_sset_count, 1800 + .get_ethtool_stats = get_ethtool_stats, 1801 + .get_link_ksettings = get_link_ksettings, 1802 + .set_link_ksettings = set_link_ksettings, 1803 + }; 1804 + 1805 + static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1806 + { 1807 + struct netdev_private *np = netdev_priv(dev); 1808 + int rc; 1809 + 1810 + if (!netif_running(dev)) 1811 + return -EINVAL; 1812 + 1813 + spin_lock_irq(&np->lock); 1814 + rc = generic_mii_ioctl(&np->mii_if, if_mii(rq), cmd, NULL); 1815 + spin_unlock_irq(&np->lock); 1816 + 1817 + return rc; 1818 + } 1819 + 1820 + static int netdev_close(struct net_device *dev) 1821 + { 1822 + struct netdev_private *np = netdev_priv(dev); 1823 + void __iomem *ioaddr = np->base; 1824 + struct sk_buff *skb; 1825 + int i; 1826 + 1827 + /* Wait and kill tasklet */ 1828 + tasklet_kill(&np->rx_tasklet); 1829 + tasklet_kill(&np->tx_tasklet); 1830 + np->cur_tx = 0; 1831 + np->dirty_tx = 0; 1832 + np->cur_task = 0; 1833 + np->last_tx = NULL; 1834 + 1835 + netif_stop_queue(dev); 1836 + 1837 + if (netif_msg_ifdown(np)) { 1838 + printk(KERN_DEBUG "%s: Shutting down ethercard, status was Tx %2.2x " 1839 + "Rx %4.4x Int %2.2x.\n", 1840 + dev->name, ioread8(ioaddr + TxStatus), 1841 + ioread32(ioaddr + RxStatus), ioread16(ioaddr + IntrStatus)); 1842 + printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d, Rx %d / %d.\n", 1843 + dev->name, np->cur_tx, np->dirty_tx, np->cur_rx, np->dirty_rx); 1844 + } 1845 + 1846 + /* Disable interrupts by clearing the interrupt mask. */ 1847 + iowrite16(0x0000, ioaddr + IntrEnable); 1848 + 1849 + /* Disable Rx and Tx DMA for safely release resource */ 1850 + iowrite32(0x500, ioaddr + DMACtrl); 1851 + 1852 + /* Stop the chip's Tx and Rx processes. */ 1853 + iowrite16(TxDisable | RxDisable | StatsDisable, ioaddr + MACCtrl1); 1854 + 1855 + for (i = 2000; i > 0; i--) { 1856 + if ((ioread32(ioaddr + DMACtrl) & 0xc000) == 0) 1857 + break; 1858 + mdelay(1); 1859 + } 1860 + 1861 + iowrite16(GlobalReset | DMAReset | FIFOReset | NetworkReset, 1862 + ioaddr + ASIC_HI_WORD(ASICCtrl)); 1863 + 1864 + for (i = 2000; i > 0; i--) { 1865 + if ((ioread16(ioaddr + ASIC_HI_WORD(ASICCtrl)) & ResetBusy) == 0) 1866 + break; 1867 + mdelay(1); 1868 + } 1869 + 1870 + #ifdef __i386__ 1871 + if (netif_msg_hw(np)) { 1872 + printk(KERN_DEBUG " Tx ring at %8.8x:\n", 1873 + (int)(np->tx_ring_dma)); 1874 + for (i = 0; i < TX_RING_SIZE; i++) 1875 + printk(KERN_DEBUG " #%d desc. %4.4x %8.8x %8.8x.\n", 1876 + i, np->tx_ring[i].status, np->tx_ring[i].frag.addr, 1877 + np->tx_ring[i].frag.length); 1878 + printk(KERN_DEBUG " Rx ring %8.8x:\n", 1879 + (int)(np->rx_ring_dma)); 1880 + for (i = 0; i < /*RX_RING_SIZE*/4 ; i++) { 1881 + printk(KERN_DEBUG " #%d desc. %4.4x %4.4x %8.8x\n", 1882 + i, np->rx_ring[i].status, np->rx_ring[i].frag.addr, 1883 + np->rx_ring[i].frag.length); 1884 + } 1885 + } 1886 + #endif /* __i386__ debugging only */ 1887 + 1888 + free_irq(np->pci_dev->irq, dev); 1889 + 1890 + timer_delete_sync(&np->timer); 1891 + 1892 + /* Free all the skbuffs in the Rx queue. */ 1893 + for (i = 0; i < RX_RING_SIZE; i++) { 1894 + np->rx_ring[i].status = 0; 1895 + skb = np->rx_skbuff[i]; 1896 + if (skb) { 1897 + dma_unmap_single(&np->pci_dev->dev, 1898 + le32_to_cpu(np->rx_ring[i].frag.addr), 1899 + np->rx_buf_sz, DMA_FROM_DEVICE); 1900 + dev_kfree_skb(skb); 1901 + np->rx_skbuff[i] = NULL; 1902 + } 1903 + np->rx_ring[i].frag.addr = cpu_to_le32(0xBADF00D0); /* poison */ 1904 + } 1905 + for (i = 0; i < TX_RING_SIZE; i++) { 1906 + np->tx_ring[i].next_desc = 0; 1907 + skb = np->tx_skbuff[i]; 1908 + if (skb) { 1909 + dma_unmap_single(&np->pci_dev->dev, 1910 + le32_to_cpu(np->tx_ring[i].frag.addr), 1911 + skb->len, DMA_TO_DEVICE); 1912 + dev_kfree_skb(skb); 1913 + np->tx_skbuff[i] = NULL; 1914 + } 1915 + } 1916 + 1917 + return 0; 1918 + } 1919 + 1920 + static void sundance_remove1(struct pci_dev *pdev) 1921 + { 1922 + struct net_device *dev = pci_get_drvdata(pdev); 1923 + 1924 + if (dev) { 1925 + struct netdev_private *np = netdev_priv(dev); 1926 + unregister_netdev(dev); 1927 + dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, 1928 + np->rx_ring, np->rx_ring_dma); 1929 + dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, 1930 + np->tx_ring, np->tx_ring_dma); 1931 + pci_iounmap(pdev, np->base); 1932 + pci_release_regions(pdev); 1933 + free_netdev(dev); 1934 + } 1935 + } 1936 + 1937 + static int __maybe_unused sundance_suspend(struct device *dev_d) 1938 + { 1939 + struct net_device *dev = dev_get_drvdata(dev_d); 1940 + struct netdev_private *np = netdev_priv(dev); 1941 + void __iomem *ioaddr = np->base; 1942 + 1943 + if (!netif_running(dev)) 1944 + return 0; 1945 + 1946 + netdev_close(dev); 1947 + netif_device_detach(dev); 1948 + 1949 + if (np->wol_enabled) { 1950 + iowrite8(AcceptBroadcast | AcceptMyPhys, ioaddr + RxMode); 1951 + iowrite16(RxEnable, ioaddr + MACCtrl1); 1952 + } 1953 + 1954 + device_set_wakeup_enable(dev_d, np->wol_enabled); 1955 + 1956 + return 0; 1957 + } 1958 + 1959 + static int __maybe_unused sundance_resume(struct device *dev_d) 1960 + { 1961 + struct net_device *dev = dev_get_drvdata(dev_d); 1962 + int err = 0; 1963 + 1964 + if (!netif_running(dev)) 1965 + return 0; 1966 + 1967 + err = netdev_open(dev); 1968 + if (err) { 1969 + printk(KERN_ERR "%s: Can't resume interface!\n", 1970 + dev->name); 1971 + goto out; 1972 + } 1973 + 1974 + netif_device_attach(dev); 1975 + 1976 + out: 1977 + return err; 1978 + } 1979 + 1980 + static SIMPLE_DEV_PM_OPS(sundance_pm_ops, sundance_suspend, sundance_resume); 1981 + 1982 + static struct pci_driver sundance_driver = { 1983 + .name = DRV_NAME, 1984 + .id_table = sundance_pci_tbl, 1985 + .probe = sundance_probe1, 1986 + .remove = sundance_remove1, 1987 + .driver.pm = &sundance_pm_ops, 1988 + }; 1989 + 1990 + module_pci_driver(sundance_driver);
+7 -3
drivers/net/ethernet/intel/e1000e/ethtool.c
··· 549 549 { 550 550 struct e1000_adapter *adapter = netdev_priv(netdev); 551 551 struct e1000_hw *hw = &adapter->hw; 552 + size_t total_len, max_len; 552 553 u16 *eeprom_buff; 553 - void *ptr; 554 - int max_len; 554 + int ret_val = 0; 555 555 int first_word; 556 556 int last_word; 557 - int ret_val = 0; 557 + void *ptr; 558 558 u16 i; 559 559 560 560 if (eeprom->len == 0) ··· 568 568 return -EINVAL; 569 569 570 570 max_len = hw->nvm.word_size * 2; 571 + 572 + if (check_add_overflow(eeprom->offset, eeprom->len, &total_len) || 573 + total_len > max_len) 574 + return -EFBIG; 571 575 572 576 first_word = eeprom->offset >> 1; 573 577 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
+2 -2
drivers/net/ethernet/intel/i40e/i40e_client.c
··· 359 359 if (i40e_client_get_params(vsi, &cdev->lan_info.params)) 360 360 goto free_cdev; 361 361 362 - mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list, 363 - struct netdev_hw_addr, list); 362 + mac = list_first_entry_or_null(&cdev->lan_info.netdev->dev_addrs.list, 363 + struct netdev_hw_addr, list); 364 364 if (mac) 365 365 ether_addr_copy(cdev->lan_info.lanmac, mac->addr); 366 366 else
+19 -104
drivers/net/ethernet/intel/i40e/i40e_debugfs.c
··· 40 40 * setup, adding or removing filters, or other things. Many of 41 41 * these will be useful for some forms of unit testing. 42 42 **************************************************************/ 43 - static char i40e_dbg_command_buf[256] = ""; 44 - 45 - /** 46 - * i40e_dbg_command_read - read for command datum 47 - * @filp: the opened file 48 - * @buffer: where to write the data for the user to read 49 - * @count: the size of the user's buffer 50 - * @ppos: file position offset 51 - **/ 52 - static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer, 53 - size_t count, loff_t *ppos) 54 - { 55 - struct i40e_pf *pf = filp->private_data; 56 - struct i40e_vsi *main_vsi; 57 - int bytes_not_copied; 58 - int buf_size = 256; 59 - char *buf; 60 - int len; 61 - 62 - /* don't allow partial reads */ 63 - if (*ppos != 0) 64 - return 0; 65 - if (count < buf_size) 66 - return -ENOSPC; 67 - 68 - buf = kzalloc(buf_size, GFP_KERNEL); 69 - if (!buf) 70 - return -ENOSPC; 71 - 72 - main_vsi = i40e_pf_get_main_vsi(pf); 73 - len = snprintf(buf, buf_size, "%s: %s\n", main_vsi->netdev->name, 74 - i40e_dbg_command_buf); 75 - 76 - bytes_not_copied = copy_to_user(buffer, buf, len); 77 - kfree(buf); 78 - 79 - if (bytes_not_copied) 80 - return -EFAULT; 81 - 82 - *ppos = len; 83 - return len; 84 - } 85 43 86 44 static char *i40e_filter_state_string[] = { 87 45 "INVALID", ··· 1579 1621 static const struct file_operations i40e_dbg_command_fops = { 1580 1622 .owner = THIS_MODULE, 1581 1623 .open = simple_open, 1582 - .read = i40e_dbg_command_read, 1583 1624 .write = i40e_dbg_command_write, 1584 1625 }; 1585 1626 ··· 1587 1630 * The netdev_ops entry in debugfs is for giving the driver commands 1588 1631 * to be executed from the netdev operations. 1589 1632 **************************************************************/ 1590 - static char i40e_dbg_netdev_ops_buf[256] = ""; 1591 - 1592 - /** 1593 - * i40e_dbg_netdev_ops_read - read for netdev_ops datum 1594 - * @filp: the opened file 1595 - * @buffer: where to write the data for the user to read 1596 - * @count: the size of the user's buffer 1597 - * @ppos: file position offset 1598 - **/ 1599 - static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer, 1600 - size_t count, loff_t *ppos) 1601 - { 1602 - struct i40e_pf *pf = filp->private_data; 1603 - struct i40e_vsi *main_vsi; 1604 - int bytes_not_copied; 1605 - int buf_size = 256; 1606 - char *buf; 1607 - int len; 1608 - 1609 - /* don't allow partal reads */ 1610 - if (*ppos != 0) 1611 - return 0; 1612 - if (count < buf_size) 1613 - return -ENOSPC; 1614 - 1615 - buf = kzalloc(buf_size, GFP_KERNEL); 1616 - if (!buf) 1617 - return -ENOSPC; 1618 - 1619 - main_vsi = i40e_pf_get_main_vsi(pf); 1620 - len = snprintf(buf, buf_size, "%s: %s\n", main_vsi->netdev->name, 1621 - i40e_dbg_netdev_ops_buf); 1622 - 1623 - bytes_not_copied = copy_to_user(buffer, buf, len); 1624 - kfree(buf); 1625 - 1626 - if (bytes_not_copied) 1627 - return -EFAULT; 1628 - 1629 - *ppos = len; 1630 - return len; 1631 - } 1632 1633 1633 1634 /** 1634 1635 * i40e_dbg_netdev_ops_write - write into netdev_ops datum ··· 1600 1685 size_t count, loff_t *ppos) 1601 1686 { 1602 1687 struct i40e_pf *pf = filp->private_data; 1688 + char *cmd_buf, *buf_tmp; 1603 1689 int bytes_not_copied; 1604 1690 struct i40e_vsi *vsi; 1605 - char *buf_tmp; 1606 1691 int vsi_seid; 1607 1692 int i, cnt; 1608 1693 1609 1694 /* don't allow partial writes */ 1610 1695 if (*ppos != 0) 1611 1696 return 0; 1612 - if (count >= sizeof(i40e_dbg_netdev_ops_buf)) 1613 - return -ENOSPC; 1614 1697 1615 - memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf)); 1616 - bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf, 1617 - buffer, count); 1618 - if (bytes_not_copied) 1698 + cmd_buf = kzalloc(count + 1, GFP_KERNEL); 1699 + if (!cmd_buf) 1700 + return count; 1701 + bytes_not_copied = copy_from_user(cmd_buf, buffer, count); 1702 + if (bytes_not_copied) { 1703 + kfree(cmd_buf); 1619 1704 return -EFAULT; 1620 - i40e_dbg_netdev_ops_buf[count] = '\0'; 1705 + } 1706 + cmd_buf[count] = '\0'; 1621 1707 1622 - buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n'); 1708 + buf_tmp = strchr(cmd_buf, '\n'); 1623 1709 if (buf_tmp) { 1624 1710 *buf_tmp = '\0'; 1625 - count = buf_tmp - i40e_dbg_netdev_ops_buf + 1; 1711 + count = buf_tmp - cmd_buf + 1; 1626 1712 } 1627 1713 1628 - if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) { 1714 + if (strncmp(cmd_buf, "change_mtu", 10) == 0) { 1629 1715 int mtu; 1630 1716 1631 - cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i", 1717 + cnt = sscanf(&cmd_buf[11], "%i %i", 1632 1718 &vsi_seid, &mtu); 1633 1719 if (cnt != 2) { 1634 1720 dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n"); ··· 1651 1735 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n"); 1652 1736 } 1653 1737 1654 - } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) { 1655 - cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid); 1738 + } else if (strncmp(cmd_buf, "set_rx_mode", 11) == 0) { 1739 + cnt = sscanf(&cmd_buf[11], "%i", &vsi_seid); 1656 1740 if (cnt != 1) { 1657 1741 dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n"); 1658 1742 goto netdev_ops_write_done; ··· 1672 1756 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n"); 1673 1757 } 1674 1758 1675 - } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) { 1676 - cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid); 1759 + } else if (strncmp(cmd_buf, "napi", 4) == 0) { 1760 + cnt = sscanf(&cmd_buf[4], "%i", &vsi_seid); 1677 1761 if (cnt != 1) { 1678 1762 dev_info(&pf->pdev->dev, "napi <vsi_seid>\n"); 1679 1763 goto netdev_ops_write_done; ··· 1691 1775 dev_info(&pf->pdev->dev, "napi called\n"); 1692 1776 } 1693 1777 } else { 1694 - dev_info(&pf->pdev->dev, "unknown command '%s'\n", 1695 - i40e_dbg_netdev_ops_buf); 1778 + dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf); 1696 1779 dev_info(&pf->pdev->dev, "available commands\n"); 1697 1780 dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n"); 1698 1781 dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n"); 1699 1782 dev_info(&pf->pdev->dev, " napi <vsi_seid>\n"); 1700 1783 } 1701 1784 netdev_ops_write_done: 1785 + kfree(cmd_buf); 1702 1786 return count; 1703 1787 } 1704 1788 1705 1789 static const struct file_operations i40e_dbg_netdev_ops_fops = { 1706 1790 .owner = THIS_MODULE, 1707 1791 .open = simple_open, 1708 - .read = i40e_dbg_netdev_ops_read, 1709 1792 .write = i40e_dbg_netdev_ops_write, 1710 1793 }; 1711 1794
+7 -5
drivers/net/ethernet/intel/ice/ice_main.c
··· 3176 3176 hw = &pf->hw; 3177 3177 tx = &pf->ptp.port.tx; 3178 3178 spin_lock_irqsave(&tx->lock, flags); 3179 - ice_ptp_complete_tx_single_tstamp(tx); 3179 + if (tx->init) { 3180 + ice_ptp_complete_tx_single_tstamp(tx); 3180 3181 3181 - idx = find_next_bit_wrap(tx->in_use, tx->len, 3182 - tx->last_ll_ts_idx_read + 1); 3183 - if (idx != tx->len) 3184 - ice_ptp_req_tx_single_tstamp(tx, idx); 3182 + idx = find_next_bit_wrap(tx->in_use, tx->len, 3183 + tx->last_ll_ts_idx_read + 1); 3184 + if (idx != tx->len) 3185 + ice_ptp_req_tx_single_tstamp(tx, idx); 3186 + } 3185 3187 spin_unlock_irqrestore(&tx->lock, flags); 3186 3188 3187 3189 val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
+8 -5
drivers/net/ethernet/intel/ice/ice_ptp.c
··· 2701 2701 */ 2702 2702 if (hw->dev_caps.ts_dev_info.ts_ll_int_read) { 2703 2703 struct ice_ptp_tx *tx = &pf->ptp.port.tx; 2704 - u8 idx; 2704 + u8 idx, last; 2705 2705 2706 2706 if (!ice_pf_state_is_nominal(pf)) 2707 2707 return IRQ_HANDLED; 2708 2708 2709 2709 spin_lock(&tx->lock); 2710 - idx = find_next_bit_wrap(tx->in_use, tx->len, 2711 - tx->last_ll_ts_idx_read + 1); 2712 - if (idx != tx->len) 2713 - ice_ptp_req_tx_single_tstamp(tx, idx); 2710 + if (tx->init) { 2711 + last = tx->last_ll_ts_idx_read + 1; 2712 + idx = find_next_bit_wrap(tx->in_use, tx->len, 2713 + last); 2714 + if (idx != tx->len) 2715 + ice_ptp_req_tx_single_tstamp(tx, idx); 2716 + } 2714 2717 spin_unlock(&tx->lock); 2715 2718 2716 2719 return IRQ_HANDLED;
+2 -2
drivers/net/ethernet/intel/idpf/idpf_idc.c
··· 247 247 if (!adev) 248 248 return; 249 249 250 + ida_free(&idpf_idc_ida, adev->id); 251 + 250 252 auxiliary_device_delete(adev); 251 253 auxiliary_device_uninit(adev); 252 - 253 - ida_free(&idpf_idc_ida, adev->id); 254 254 } 255 255 256 256 /**
+6 -3
drivers/net/ethernet/intel/idpf/idpf_lib.c
··· 2344 2344 struct idpf_netdev_priv *np = netdev_priv(netdev); 2345 2345 struct idpf_vport_config *vport_config; 2346 2346 struct sockaddr *addr = p; 2347 + u8 old_mac_addr[ETH_ALEN]; 2347 2348 struct idpf_vport *vport; 2348 2349 int err = 0; 2349 2350 ··· 2368 2367 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) 2369 2368 goto unlock_mutex; 2370 2369 2370 + ether_addr_copy(old_mac_addr, vport->default_mac_addr); 2371 + ether_addr_copy(vport->default_mac_addr, addr->sa_data); 2371 2372 vport_config = vport->adapter->vport_config[vport->idx]; 2372 2373 err = idpf_add_mac_filter(vport, np, addr->sa_data, false); 2373 2374 if (err) { 2374 2375 __idpf_del_mac_filter(vport_config, addr->sa_data); 2376 + ether_addr_copy(vport->default_mac_addr, netdev->dev_addr); 2375 2377 goto unlock_mutex; 2376 2378 } 2377 2379 2378 - if (is_valid_ether_addr(vport->default_mac_addr)) 2379 - idpf_del_mac_filter(vport, np, vport->default_mac_addr, false); 2380 + if (is_valid_ether_addr(old_mac_addr)) 2381 + __idpf_del_mac_filter(vport_config, old_mac_addr); 2380 2382 2381 - ether_addr_copy(vport->default_mac_addr, addr->sa_data); 2382 2383 eth_hw_addr_set(netdev, addr->sa_data); 2383 2384 2384 2385 unlock_mutex:
+12
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
··· 3765 3765 return le32_to_cpu(vport_msg->vport_id); 3766 3766 } 3767 3767 3768 + static void idpf_set_mac_type(struct idpf_vport *vport, 3769 + struct virtchnl2_mac_addr *mac_addr) 3770 + { 3771 + bool is_primary; 3772 + 3773 + is_primary = ether_addr_equal(vport->default_mac_addr, mac_addr->addr); 3774 + mac_addr->type = is_primary ? VIRTCHNL2_MAC_ADDR_PRIMARY : 3775 + VIRTCHNL2_MAC_ADDR_EXTRA; 3776 + } 3777 + 3768 3778 /** 3769 3779 * idpf_mac_filter_async_handler - Async callback for mac filters 3770 3780 * @adapter: private data struct ··· 3904 3894 list) { 3905 3895 if (add && f->add) { 3906 3896 ether_addr_copy(mac_addr[i].addr, f->macaddr); 3897 + idpf_set_mac_type(vport, &mac_addr[i]); 3907 3898 i++; 3908 3899 f->add = false; 3909 3900 if (i == total_filters) ··· 3912 3901 } 3913 3902 if (!add && f->remove) { 3914 3903 ether_addr_copy(mac_addr[i].addr, f->macaddr); 3904 + idpf_set_mac_type(vport, &mac_addr[i]); 3915 3905 i++; 3916 3906 f->remove = false; 3917 3907 if (i == total_filters)
+2 -2
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
··· 3571 3571 3572 3572 for (i = 0; i < ARRAY_SIZE(ixgbe_ls_map); ++i) { 3573 3573 if (hw->phy.eee_speeds_supported & ixgbe_ls_map[i].mac_speed) 3574 - linkmode_set_bit(ixgbe_lp_map[i].link_mode, 3574 + linkmode_set_bit(ixgbe_ls_map[i].link_mode, 3575 3575 edata->supported); 3576 3576 } 3577 3577 3578 3578 for (i = 0; i < ARRAY_SIZE(ixgbe_ls_map); ++i) { 3579 3579 if (hw->phy.eee_speeds_advertised & ixgbe_ls_map[i].mac_speed) 3580 - linkmode_set_bit(ixgbe_lp_map[i].link_mode, 3580 + linkmode_set_bit(ixgbe_ls_map[i].link_mode, 3581 3581 edata->advertised); 3582 3582 } 3583 3583
+9 -1
drivers/net/ethernet/mediatek/mtk_eth_soc.c
··· 1761 1761 bool gso = false; 1762 1762 int tx_num; 1763 1763 1764 + if (skb_vlan_tag_present(skb) && 1765 + !eth_proto_is_802_3(eth_hdr(skb)->h_proto)) { 1766 + skb = __vlan_hwaccel_push_inside(skb); 1767 + if (!skb) 1768 + goto dropped; 1769 + } 1770 + 1764 1771 /* normally we can rely on the stack not calling this more than once, 1765 1772 * however we have 2 queues running on the same ring so we need to lock 1766 1773 * the ring access ··· 1813 1806 1814 1807 drop: 1815 1808 spin_unlock(&eth->page_lock); 1816 - stats->tx_dropped++; 1817 1809 dev_kfree_skb_any(skb); 1810 + dropped: 1811 + stats->tx_dropped++; 1818 1812 return NETDEV_TX_OK; 1819 1813 } 1820 1814
+3 -1
drivers/net/ethernet/mellanox/mlx4/en_rx.c
··· 267 267 pp.dma_dir = priv->dma_dir; 268 268 269 269 ring->pp = page_pool_create(&pp); 270 - if (!ring->pp) 270 + if (IS_ERR(ring->pp)) { 271 + err = PTR_ERR(ring->pp); 271 272 goto err_ring; 273 + } 272 274 273 275 if (xdp_rxq_info_reg(&ring->xdp_rxq, priv->dev, queue_index, 0) < 0) 274 276 goto err_pp;
+5 -2
drivers/net/ethernet/microchip/lan865x/lan865x.c
··· 423 423 free_netdev(priv->netdev); 424 424 } 425 425 426 - static const struct spi_device_id spidev_spi_ids[] = { 426 + static const struct spi_device_id lan865x_ids[] = { 427 427 { .name = "lan8650" }, 428 + { .name = "lan8651" }, 428 429 {}, 429 430 }; 431 + MODULE_DEVICE_TABLE(spi, lan865x_ids); 430 432 431 433 static const struct of_device_id lan865x_dt_ids[] = { 432 434 { .compatible = "microchip,lan8650" }, 435 + { .compatible = "microchip,lan8651" }, 433 436 { /* Sentinel */ } 434 437 }; 435 438 MODULE_DEVICE_TABLE(of, lan865x_dt_ids); ··· 444 441 }, 445 442 .probe = lan865x_probe, 446 443 .remove = lan865x_remove, 447 - .id_table = spidev_spi_ids, 444 + .id_table = lan865x_ids, 448 445 }; 449 446 module_spi_driver(lan865x_driver); 450 447
+2 -1
drivers/net/ethernet/oa_tc6.c
··· 1249 1249 1250 1250 /* Set the SPI controller to pump at realtime priority */ 1251 1251 tc6->spi->rt = true; 1252 - spi_setup(tc6->spi); 1252 + if (spi_setup(tc6->spi) < 0) 1253 + return NULL; 1253 1254 1254 1255 tc6->spi_ctrl_tx_buf = devm_kzalloc(&tc6->spi->dev, 1255 1256 OA_TC6_CTRL_SPI_BUF_SIZE,
+1 -1
drivers/net/ethernet/ti/am65-cpsw-nuss.c
··· 1522 1522 } 1523 1523 } 1524 1524 1525 - if (single_port) { 1525 + if (single_port && num_tx) { 1526 1526 netif_txq = netdev_get_tx_queue(ndev, chn); 1527 1527 netdev_tx_completed_queue(netif_txq, num_tx, total_bytes); 1528 1528 am65_cpsw_nuss_tx_wake(tx_chn, ndev, netif_txq);
+10
drivers/net/ethernet/xilinx/xilinx_axienet_main.c
··· 1168 1168 &meta_max_len); 1169 1169 dma_unmap_single(lp->dev, skbuf_dma->dma_address, lp->max_frm_size, 1170 1170 DMA_FROM_DEVICE); 1171 + 1172 + if (IS_ERR(app_metadata)) { 1173 + if (net_ratelimit()) 1174 + netdev_err(lp->ndev, "Failed to get RX metadata pointer\n"); 1175 + dev_kfree_skb_any(skb); 1176 + lp->ndev->stats.rx_dropped++; 1177 + goto rx_submit; 1178 + } 1179 + 1171 1180 /* TODO: Derive app word index programmatically */ 1172 1181 rx_len = (app_metadata[LEN_APP] & 0xFFFF); 1173 1182 skb_put(skb, rx_len); ··· 1189 1180 u64_stats_add(&lp->rx_bytes, rx_len); 1190 1181 u64_stats_update_end(&lp->rx_stat_sync); 1191 1182 1183 + rx_submit: 1192 1184 for (i = 0; i < CIRC_SPACE(lp->rx_ring_head, lp->rx_ring_tail, 1193 1185 RX_BUF_NUM_DEFAULT); i++) 1194 1186 axienet_rx_submit_desc(lp->ndev);
+1 -1
drivers/net/ethernet/xircom/xirc2ps_cs.c
··· 1576 1576 msleep(40); /* wait 40 msec to let it complete */ 1577 1577 } 1578 1578 if (full_duplex) 1579 - PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex)); 1579 + PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR) | FullDuplex); 1580 1580 } else { /* No MII */ 1581 1581 SelectPage(0); 1582 1582 value = GetByte(XIRCREG_ESR); /* read the ESR */
+4 -4
drivers/net/macsec.c
··· 1844 1844 1845 1845 if (tb_sa[MACSEC_SA_ATTR_PN]) { 1846 1846 spin_lock_bh(&rx_sa->lock); 1847 - rx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]); 1847 + rx_sa->next_pn = nla_get_uint(tb_sa[MACSEC_SA_ATTR_PN]); 1848 1848 spin_unlock_bh(&rx_sa->lock); 1849 1849 } 1850 1850 ··· 2086 2086 } 2087 2087 2088 2088 spin_lock_bh(&tx_sa->lock); 2089 - tx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]); 2089 + tx_sa->next_pn = nla_get_uint(tb_sa[MACSEC_SA_ATTR_PN]); 2090 2090 spin_unlock_bh(&tx_sa->lock); 2091 2091 2092 2092 if (tb_sa[MACSEC_SA_ATTR_ACTIVE]) ··· 2398 2398 2399 2399 spin_lock_bh(&tx_sa->lock); 2400 2400 prev_pn = tx_sa->next_pn_halves; 2401 - tx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]); 2401 + tx_sa->next_pn = nla_get_uint(tb_sa[MACSEC_SA_ATTR_PN]); 2402 2402 spin_unlock_bh(&tx_sa->lock); 2403 2403 } 2404 2404 ··· 2496 2496 2497 2497 spin_lock_bh(&rx_sa->lock); 2498 2498 prev_pn = rx_sa->next_pn_halves; 2499 - rx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]); 2499 + rx_sa->next_pn = nla_get_uint(tb_sa[MACSEC_SA_ATTR_PN]); 2500 2500 spin_unlock_bh(&rx_sa->lock); 2501 2501 } 2502 2502
+1
drivers/net/mctp/mctp-usb.c
··· 183 183 struct mctp_usb_hdr *hdr; 184 184 u8 pkt_len; /* length of MCTP packet, no USB header */ 185 185 186 + skb_reset_mac_header(skb); 186 187 hdr = skb_pull_data(skb, sizeof(*hdr)); 187 188 if (!hdr) 188 189 break;
+1 -1
drivers/net/pcs/pcs-rzn1-miic.c
··· 19 19 #define MIIC_PRCMD 0x0 20 20 #define MIIC_ESID_CODE 0x4 21 21 22 - #define MIIC_MODCTRL 0x20 22 + #define MIIC_MODCTRL 0x8 23 23 #define MIIC_MODCTRL_SW_MODE GENMASK(4, 0) 24 24 25 25 #define MIIC_CONVCTRL(port) (0x100 + (port) * 4)
+8 -10
drivers/net/phy/mscc/mscc_ptp.c
··· 456 456 *p++ = (reg >> 24) & 0xff; 457 457 } 458 458 459 - len = skb_queue_len(&ptp->tx_queue); 459 + len = skb_queue_len_lockless(&ptp->tx_queue); 460 460 if (len < 1) 461 461 return; 462 462 463 463 while (len--) { 464 - skb = __skb_dequeue(&ptp->tx_queue); 464 + skb = skb_dequeue(&ptp->tx_queue); 465 465 if (!skb) 466 466 return; 467 467 ··· 486 486 * packet in the FIFO right now, reschedule it for later 487 487 * packets. 488 488 */ 489 - __skb_queue_tail(&ptp->tx_queue, skb); 489 + skb_queue_tail(&ptp->tx_queue, skb); 490 490 } 491 491 } 492 492 ··· 1068 1068 case HWTSTAMP_TX_ON: 1069 1069 break; 1070 1070 case HWTSTAMP_TX_OFF: 1071 + skb_queue_purge(&vsc8531->ptp->tx_queue); 1071 1072 break; 1072 1073 default: 1073 1074 return -ERANGE; ··· 1092 1091 vsc8531->ptp->rx_filter = cfg->rx_filter; 1093 1092 1094 1093 mutex_lock(&vsc8531->ts_lock); 1095 - 1096 - __skb_queue_purge(&vsc8531->ptp->tx_queue); 1097 - __skb_queue_head_init(&vsc8531->ptp->tx_queue); 1098 1094 1099 1095 /* Disable predictor while configuring the 1588 block */ 1100 1096 val = vsc85xx_ts_read_csr(phydev, PROCESSOR, ··· 1178 1180 1179 1181 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 1180 1182 1181 - mutex_lock(&vsc8531->ts_lock); 1182 - __skb_queue_tail(&vsc8531->ptp->tx_queue, skb); 1183 - mutex_unlock(&vsc8531->ts_lock); 1183 + skb_queue_tail(&vsc8531->ptp->tx_queue, skb); 1184 1184 return; 1185 1185 1186 1186 out: ··· 1544 1548 if (vsc8531->ptp->ptp_clock) { 1545 1549 ptp_clock_unregister(vsc8531->ptp->ptp_clock); 1546 1550 skb_queue_purge(&vsc8531->rx_skbs_list); 1551 + skb_queue_purge(&vsc8531->ptp->tx_queue); 1547 1552 } 1548 1553 } 1549 1554 ··· 1568 1571 if (rc & VSC85XX_1588_INT_FIFO_ADD) { 1569 1572 vsc85xx_get_tx_ts(priv->ptp); 1570 1573 } else if (rc & VSC85XX_1588_INT_FIFO_OVERFLOW) { 1571 - __skb_queue_purge(&priv->ptp->tx_queue); 1574 + skb_queue_purge(&priv->ptp->tx_queue); 1572 1575 vsc85xx_ts_reset_fifo(phydev); 1573 1576 } 1574 1577 ··· 1588 1591 mutex_init(&vsc8531->phc_lock); 1589 1592 mutex_init(&vsc8531->ts_lock); 1590 1593 skb_queue_head_init(&vsc8531->rx_skbs_list); 1594 + skb_queue_head_init(&vsc8531->ptp->tx_queue); 1591 1595 1592 1596 /* Retrieve the shared load/save GPIO. Request it as non exclusive as 1593 1597 * the same GPIO can be requested by all the PHYs of the same package.
+65 -38
drivers/net/phy/phylink.c
··· 1016 1016 pl->pcs->ops->pcs_an_restart(pl->pcs); 1017 1017 } 1018 1018 1019 + enum inband_type { 1020 + INBAND_NONE, 1021 + INBAND_CISCO_SGMII, 1022 + INBAND_BASEX, 1023 + }; 1024 + 1025 + static enum inband_type phylink_get_inband_type(phy_interface_t interface) 1026 + { 1027 + switch (interface) { 1028 + case PHY_INTERFACE_MODE_SGMII: 1029 + case PHY_INTERFACE_MODE_QSGMII: 1030 + case PHY_INTERFACE_MODE_QUSGMII: 1031 + case PHY_INTERFACE_MODE_USXGMII: 1032 + case PHY_INTERFACE_MODE_10G_QXGMII: 1033 + /* These protocols are designed for use with a PHY which 1034 + * communicates its negotiation result back to the MAC via 1035 + * inband communication. Note: there exist PHYs that run 1036 + * with SGMII but do not send the inband data. 1037 + */ 1038 + return INBAND_CISCO_SGMII; 1039 + 1040 + case PHY_INTERFACE_MODE_1000BASEX: 1041 + case PHY_INTERFACE_MODE_2500BASEX: 1042 + /* 1000base-X is designed for use media-side for Fibre 1043 + * connections, and thus the Autoneg bit needs to be 1044 + * taken into account. We also do this for 2500base-X 1045 + * as well, but drivers may not support this, so may 1046 + * need to override this. 1047 + */ 1048 + return INBAND_BASEX; 1049 + 1050 + default: 1051 + return INBAND_NONE; 1052 + } 1053 + } 1054 + 1019 1055 /** 1020 1056 * phylink_pcs_neg_mode() - helper to determine PCS inband mode 1021 1057 * @pl: a pointer to a &struct phylink returned from phylink_create() ··· 1079 1043 unsigned int pcs_ib_caps = 0; 1080 1044 unsigned int phy_ib_caps = 0; 1081 1045 unsigned int neg_mode, mode; 1082 - enum { 1083 - INBAND_CISCO_SGMII, 1084 - INBAND_BASEX, 1085 - } type; 1046 + enum inband_type type; 1047 + 1048 + type = phylink_get_inband_type(interface); 1049 + if (type == INBAND_NONE) { 1050 + pl->pcs_neg_mode = PHYLINK_PCS_NEG_NONE; 1051 + pl->act_link_an_mode = pl->req_link_an_mode; 1052 + return; 1053 + } 1086 1054 1087 1055 mode = pl->req_link_an_mode; 1088 1056 1089 1057 pl->phy_ib_mode = 0; 1090 - 1091 - switch (interface) { 1092 - case PHY_INTERFACE_MODE_SGMII: 1093 - case PHY_INTERFACE_MODE_QSGMII: 1094 - case PHY_INTERFACE_MODE_QUSGMII: 1095 - case PHY_INTERFACE_MODE_USXGMII: 1096 - case PHY_INTERFACE_MODE_10G_QXGMII: 1097 - /* These protocols are designed for use with a PHY which 1098 - * communicates its negotiation result back to the MAC via 1099 - * inband communication. Note: there exist PHYs that run 1100 - * with SGMII but do not send the inband data. 1101 - */ 1102 - type = INBAND_CISCO_SGMII; 1103 - break; 1104 - 1105 - case PHY_INTERFACE_MODE_1000BASEX: 1106 - case PHY_INTERFACE_MODE_2500BASEX: 1107 - /* 1000base-X is designed for use media-side for Fibre 1108 - * connections, and thus the Autoneg bit needs to be 1109 - * taken into account. We also do this for 2500base-X 1110 - * as well, but drivers may not support this, so may 1111 - * need to override this. 1112 - */ 1113 - type = INBAND_BASEX; 1114 - break; 1115 - 1116 - default: 1117 - pl->pcs_neg_mode = PHYLINK_PCS_NEG_NONE; 1118 - pl->act_link_an_mode = mode; 1119 - return; 1120 - } 1121 1058 1122 1059 if (pcs) 1123 1060 pcs_ib_caps = phylink_pcs_inband_caps(pcs, interface); ··· 2141 2132 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, 2142 2133 __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising); 2143 2134 2144 - if (phy_interrupt_is_valid(phy)) 2145 - phy_request_interrupt(phy); 2146 - 2147 2135 if (pl->config->mac_managed_pm) 2148 2136 phy->mac_managed_pm = true; 2149 2137 ··· 2156 2150 if (ret == -EOPNOTSUPP) 2157 2151 ret = 0; 2158 2152 } 2153 + 2154 + if (ret == 0 && phy_interrupt_is_valid(phy)) 2155 + phy_request_interrupt(phy); 2159 2156 2160 2157 return ret; 2161 2158 } ··· 3634 3625 { 3635 3626 __ETHTOOL_DECLARE_LINK_MODE_MASK(support); 3636 3627 struct phylink_link_state config; 3628 + enum inband_type inband_type; 3637 3629 phy_interface_t interface; 3638 3630 int ret; 3639 3631 ··· 3680 3670 3681 3671 phylink_dbg(pl, "optical SFP: chosen %s interface\n", 3682 3672 phy_modes(interface)); 3673 + 3674 + inband_type = phylink_get_inband_type(interface); 3675 + if (inband_type == INBAND_NONE) { 3676 + /* If this is the sole interface, and there is no inband 3677 + * support, clear the advertising mask and Autoneg bit in 3678 + * the support mask. Otherwise, just clear the Autoneg bit 3679 + * in the advertising mask. 3680 + */ 3681 + if (phy_interface_weight(pl->sfp_interfaces) == 1) { 3682 + linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, 3683 + pl->sfp_support); 3684 + linkmode_zero(config.advertising); 3685 + } else { 3686 + linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, 3687 + config.advertising); 3688 + } 3689 + } 3683 3690 3684 3691 if (!phylink_validate_pcs_inband_autoneg(pl, interface, 3685 3692 config.advertising)) {
+3
drivers/net/phy/sfp.c
··· 492 492 SFP_QUIRK("ALCATELLUCENT", "3FE46541AA", sfp_quirk_2500basex, 493 493 sfp_fixup_nokia), 494 494 495 + // FLYPRO SFP-10GT-CS-30M uses Rollball protocol to talk to the PHY. 496 + SFP_QUIRK_F("FLYPRO", "SFP-10GT-CS-30M", sfp_fixup_rollball), 497 + 495 498 // Fiberstore SFP-10G-T doesn't identify as copper, uses the Rollball 496 499 // protocol to talk to the PHY and needs 4 sec wait before probing the 497 500 // PHY.
+3 -3
drivers/net/ppp/ppp_generic.c
··· 1744 1744 */ 1745 1745 if (net_ratelimit()) 1746 1746 netdev_err(ppp->dev, "ppp: compressor dropped pkt\n"); 1747 - kfree_skb(skb); 1748 1747 consume_skb(new_skb); 1749 1748 new_skb = NULL; 1750 1749 } ··· 1844 1845 "down - pkt dropped.\n"); 1845 1846 goto drop; 1846 1847 } 1847 - skb = pad_compress_skb(ppp, skb); 1848 - if (!skb) 1848 + new_skb = pad_compress_skb(ppp, skb); 1849 + if (!new_skb) 1849 1850 goto drop; 1851 + skb = new_skb; 1850 1852 } 1851 1853 1852 1854 /*
+12 -6
drivers/net/vxlan/vxlan_core.c
··· 1445 1445 if (READ_ONCE(f->updated) != now) 1446 1446 WRITE_ONCE(f->updated, now); 1447 1447 1448 + /* Don't override an fdb with nexthop with a learnt entry */ 1449 + if (rcu_access_pointer(f->nh)) 1450 + return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; 1451 + 1448 1452 if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) && 1449 1453 rdst->remote_ifindex == ifindex)) 1450 1454 return SKB_NOT_DROPPED_YET; 1451 1455 1452 1456 /* Don't migrate static entries, drop packets */ 1453 1457 if (f->state & (NUD_PERMANENT | NUD_NOARP)) 1454 - return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; 1455 - 1456 - /* Don't override an fdb with nexthop with a learnt entry */ 1457 - if (rcu_access_pointer(f->nh)) 1458 1458 return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; 1459 1459 1460 1460 if (net_ratelimit()) ··· 1877 1877 n = neigh_lookup(&arp_tbl, &tip, dev); 1878 1878 1879 1879 if (n) { 1880 + struct vxlan_rdst *rdst = NULL; 1880 1881 struct vxlan_fdb *f; 1881 1882 struct sk_buff *reply; 1882 1883 ··· 1888 1887 1889 1888 rcu_read_lock(); 1890 1889 f = vxlan_find_mac_tx(vxlan, n->ha, vni); 1891 - if (f && vxlan_addr_any(&(first_remote_rcu(f)->remote_ip))) { 1890 + if (f) 1891 + rdst = first_remote_rcu(f); 1892 + if (rdst && vxlan_addr_any(&rdst->remote_ip)) { 1892 1893 /* bridge-local neighbor */ 1893 1894 neigh_release(n); 1894 1895 rcu_read_unlock(); ··· 2047 2044 n = neigh_lookup(ipv6_stub->nd_tbl, &msg->target, dev); 2048 2045 2049 2046 if (n) { 2047 + struct vxlan_rdst *rdst = NULL; 2050 2048 struct vxlan_fdb *f; 2051 2049 struct sk_buff *reply; 2052 2050 ··· 2057 2053 } 2058 2054 2059 2055 f = vxlan_find_mac_tx(vxlan, n->ha, vni); 2060 - if (f && vxlan_addr_any(&(first_remote_rcu(f)->remote_ip))) { 2056 + if (f) 2057 + rdst = first_remote_rcu(f); 2058 + if (rdst && vxlan_addr_any(&rdst->remote_ip)) { 2061 2059 /* bridge-local neighbor */ 2062 2060 neigh_release(n); 2063 2061 goto out;
+1 -3
drivers/net/vxlan/vxlan_private.h
··· 61 61 return &vn->sock_list[hash_32(ntohs(port), PORT_HASH_BITS)]; 62 62 } 63 63 64 - /* First remote destination for a forwarding entry. 65 - * Guaranteed to be non-NULL because remotes are never deleted. 66 - */ 64 + /* First remote destination for a forwarding entry. */ 67 65 static inline struct vxlan_rdst *first_remote_rcu(struct vxlan_fdb *fdb) 68 66 { 69 67 if (rcu_access_pointer(fdb->nh))
+2
drivers/net/wireless/ath/ath11k/core.h
··· 411 411 bool do_not_send_tmpl; 412 412 struct ath11k_arp_ns_offload arp_ns_offload; 413 413 struct ath11k_rekey_data rekey_data; 414 + u32 num_stations; 415 + bool reinstall_group_keys; 414 416 415 417 struct ath11k_reg_tpc_power_info reg_tpc_info; 416 418
+102 -9
drivers/net/wireless/ath/ath11k/mac.c
··· 4317 4317 return first_errno; 4318 4318 } 4319 4319 4320 + static int ath11k_set_group_keys(struct ath11k_vif *arvif) 4321 + { 4322 + struct ath11k *ar = arvif->ar; 4323 + struct ath11k_base *ab = ar->ab; 4324 + const u8 *addr = arvif->bssid; 4325 + int i, ret, first_errno = 0; 4326 + struct ath11k_peer *peer; 4327 + 4328 + spin_lock_bh(&ab->base_lock); 4329 + peer = ath11k_peer_find(ab, arvif->vdev_id, addr); 4330 + spin_unlock_bh(&ab->base_lock); 4331 + 4332 + if (!peer) 4333 + return -ENOENT; 4334 + 4335 + for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { 4336 + struct ieee80211_key_conf *key = peer->keys[i]; 4337 + 4338 + if (!key || (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) 4339 + continue; 4340 + 4341 + ret = ath11k_install_key(arvif, key, SET_KEY, addr, 4342 + WMI_KEY_GROUP); 4343 + if (ret < 0 && first_errno == 0) 4344 + first_errno = ret; 4345 + 4346 + if (ret < 0) 4347 + ath11k_warn(ab, "failed to set group key of idx %d for vdev %d: %d\n", 4348 + i, arvif->vdev_id, ret); 4349 + } 4350 + 4351 + return first_errno; 4352 + } 4353 + 4320 4354 static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 4321 4355 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 4322 4356 struct ieee80211_key_conf *key) ··· 4360 4326 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); 4361 4327 struct ath11k_peer *peer; 4362 4328 struct ath11k_sta *arsta; 4329 + bool is_ap_with_no_sta; 4363 4330 const u8 *peer_addr; 4364 4331 int ret = 0; 4365 4332 u32 flags = 0; ··· 4421 4386 else 4422 4387 flags |= WMI_KEY_GROUP; 4423 4388 4424 - ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags); 4425 - if (ret) { 4426 - ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret); 4427 - goto exit; 4428 - } 4389 + ath11k_dbg(ar->ab, ATH11K_DBG_MAC, 4390 + "%s for peer %pM on vdev %d flags 0x%X, type = %d, num_sta %d\n", 4391 + cmd == SET_KEY ? "SET_KEY" : "DEL_KEY", peer_addr, arvif->vdev_id, 4392 + flags, arvif->vdev_type, arvif->num_stations); 4429 4393 4430 - ret = ath11k_dp_peer_rx_pn_replay_config(arvif, peer_addr, cmd, key); 4431 - if (ret) { 4432 - ath11k_warn(ab, "failed to offload PN replay detection %d\n", ret); 4433 - goto exit; 4394 + /* Allow group key clearing only in AP mode when no stations are 4395 + * associated. There is a known race condition in firmware where 4396 + * group addressed packets may be dropped if the key is cleared 4397 + * and immediately set again during rekey. 4398 + * 4399 + * During GTK rekey, mac80211 issues a clear key (if the old key 4400 + * exists) followed by an install key operation for same key 4401 + * index. This causes ath11k to send two WMI commands in quick 4402 + * succession: one to clear the old key and another to install the 4403 + * new key in the same slot. 4404 + * 4405 + * Under certain conditions—especially under high load or time 4406 + * sensitive scenarios, firmware may process these commands 4407 + * asynchronously in a way that firmware assumes the key is 4408 + * cleared whereas hardware has a valid key. This inconsistency 4409 + * between hardware and firmware leads to group addressed packet 4410 + * drops after rekey. 4411 + * Only setting the same key again can restore a valid key in 4412 + * firmware and allow packets to be transmitted. 4413 + * 4414 + * There is a use case where an AP can transition from Secure mode 4415 + * to open mode without a vdev restart by just deleting all 4416 + * associated peers and clearing key, Hence allow clear key for 4417 + * that case alone. Mark arvif->reinstall_group_keys in such cases 4418 + * and reinstall the same key when the first peer is added, 4419 + * allowing firmware to recover from the race if it had occurred. 4420 + */ 4421 + 4422 + is_ap_with_no_sta = (vif->type == NL80211_IFTYPE_AP && 4423 + !arvif->num_stations); 4424 + if ((flags & WMI_KEY_PAIRWISE) || cmd == SET_KEY || is_ap_with_no_sta) { 4425 + ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags); 4426 + if (ret) { 4427 + ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret); 4428 + goto exit; 4429 + } 4430 + 4431 + ret = ath11k_dp_peer_rx_pn_replay_config(arvif, peer_addr, cmd, key); 4432 + if (ret) { 4433 + ath11k_warn(ab, "failed to offload PN replay detection %d\n", 4434 + ret); 4435 + goto exit; 4436 + } 4437 + 4438 + if ((flags & WMI_KEY_GROUP) && cmd == SET_KEY && is_ap_with_no_sta) 4439 + arvif->reinstall_group_keys = true; 4434 4440 } 4435 4441 4436 4442 spin_lock_bh(&ab->base_lock); ··· 5070 4994 return -ENOBUFS; 5071 4995 5072 4996 ar->num_stations++; 4997 + arvif->num_stations++; 5073 4998 5074 4999 return 0; 5075 5000 } ··· 5086 5009 return; 5087 5010 5088 5011 ar->num_stations--; 5012 + arvif->num_stations--; 5089 5013 } 5090 5014 5091 5015 static u32 ath11k_mac_ieee80211_sta_bw_to_wmi(struct ath11k *ar, ··· 9616 9538 ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n", 9617 9539 ar->max_num_stations); 9618 9540 goto exit; 9541 + } 9542 + 9543 + /* Driver allows the DEL KEY followed by SET KEY sequence for 9544 + * group keys for only when there is no clients associated, if at 9545 + * all firmware has entered the race during that window, 9546 + * reinstalling the same key when the first sta connects will allow 9547 + * firmware to recover from the race. 9548 + */ 9549 + if (arvif->num_stations == 1 && arvif->reinstall_group_keys) { 9550 + ath11k_dbg(ab, ATH11K_DBG_MAC, "set group keys on 1st station add for vdev %d\n", 9551 + arvif->vdev_id); 9552 + ret = ath11k_set_group_keys(arvif); 9553 + if (ret) 9554 + goto dec_num_station; 9555 + arvif->reinstall_group_keys = false; 9619 9556 } 9620 9557 9621 9558 arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL);
+1
drivers/net/wireless/ath/ath12k/wmi.c
··· 2423 2423 2424 2424 eml_cap = arg->ml.eml_cap; 2425 2425 if (u16_get_bits(eml_cap, IEEE80211_EML_CAP_EMLSR_SUPP)) { 2426 + ml_params->flags |= cpu_to_le32(ATH12K_WMI_FLAG_MLO_EMLSR_SUPPORT); 2426 2427 /* Padding delay */ 2427 2428 eml_pad_delay = ieee80211_emlsr_pad_delay_in_us(eml_cap); 2428 2429 ml_params->emlsr_padding_delay_us = cpu_to_le32(eml_pad_delay);
+2 -4
drivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c
··· 393 393 if (!cfg->btcoex) 394 394 return; 395 395 396 - if (cfg->btcoex->timer_on) { 397 - cfg->btcoex->timer_on = false; 398 - timer_shutdown_sync(&cfg->btcoex->timer); 399 - } 396 + timer_shutdown_sync(&cfg->btcoex->timer); 397 + cfg->btcoex->timer_on = false; 400 398 401 399 cancel_work_sync(&cfg->btcoex->work); 402 400
+24 -1
drivers/net/wireless/intel/iwlwifi/fw/acpi.c
··· 169 169 170 170 BUILD_BUG_ON(ARRAY_SIZE(acpi_dsm_size) != DSM_FUNC_NUM_FUNCS); 171 171 172 - if (WARN_ON(func >= ARRAY_SIZE(acpi_dsm_size))) 172 + if (WARN_ON(func >= ARRAY_SIZE(acpi_dsm_size) || !func)) 173 173 return -EINVAL; 174 174 175 175 expected_size = acpi_dsm_size[func]; ··· 177 177 /* Currently all ACPI DSMs are either 8-bit or 32-bit */ 178 178 if (expected_size != sizeof(u8) && expected_size != sizeof(u32)) 179 179 return -EOPNOTSUPP; 180 + 181 + if (!fwrt->acpi_dsm_funcs_valid) { 182 + ret = iwl_acpi_get_dsm_integer(fwrt->dev, ACPI_DSM_REV, 183 + DSM_FUNC_QUERY, 184 + &iwl_guid, &tmp, 185 + acpi_dsm_size[DSM_FUNC_QUERY]); 186 + if (ret) { 187 + /* always indicate BIT(0) to avoid re-reading */ 188 + fwrt->acpi_dsm_funcs_valid = BIT(0); 189 + return ret; 190 + } 191 + 192 + IWL_DEBUG_RADIO(fwrt, "ACPI DSM validity bitmap 0x%x\n", 193 + (u32)tmp); 194 + /* always indicate BIT(0) to avoid re-reading */ 195 + fwrt->acpi_dsm_funcs_valid = tmp | BIT(0); 196 + } 197 + 198 + if (!(fwrt->acpi_dsm_funcs_valid & BIT(func))) { 199 + IWL_DEBUG_RADIO(fwrt, "ACPI DSM %d not indicated as valid\n", 200 + func); 201 + return -ENODATA; 202 + } 180 203 181 204 ret = iwl_acpi_get_dsm_integer(fwrt->dev, ACPI_DSM_REV, func, 182 205 &iwl_guid, &tmp, expected_size);
+8
drivers/net/wireless/intel/iwlwifi/fw/runtime.h
··· 113 113 * @phy_filters: specific phy filters as read from WPFC BIOS table 114 114 * @ppag_bios_rev: PPAG BIOS revision 115 115 * @ppag_bios_source: see &enum bios_source 116 + * @acpi_dsm_funcs_valid: bitmap indicating which DSM values are valid, 117 + * zero (default initialization) means it hasn't been read yet, 118 + * and BIT(0) is set when it has since function 0 also has this 119 + * bitmap and is always supported 116 120 */ 117 121 struct iwl_fw_runtime { 118 122 struct iwl_trans *trans; ··· 193 189 bool uats_valid; 194 190 u8 uefi_tables_lock_status; 195 191 struct iwl_phy_specific_cfg phy_filters; 192 + 193 + #ifdef CONFIG_ACPI 194 + u32 acpi_dsm_funcs_valid; 195 + #endif 196 196 }; 197 197 198 198 void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans,
+6
drivers/net/wireless/intel/iwlwifi/fw/uefi.c
··· 747 747 goto out; 748 748 } 749 749 750 + if (!(data->functions[DSM_FUNC_QUERY] & BIT(func))) { 751 + IWL_DEBUG_RADIO(fwrt, "DSM func %d not in 0x%x\n", 752 + func, data->functions[DSM_FUNC_QUERY]); 753 + goto out; 754 + } 755 + 750 756 *value = data->functions[func]; 751 757 752 758 IWL_DEBUG_RADIO(fwrt,
+17 -5
drivers/net/wireless/intel/iwlwifi/pcie/drv.c
··· 673 673 674 674 IWL_DEV_INFO(iwl6005_n_cfg, iwl6005_2agn_sff_name, 675 675 DEVICE(0x0082), SUBDEV_MASKED(0xC000, 0xF000)), 676 + IWL_DEV_INFO(iwl6005_n_cfg, iwl6005_2agn_sff_name, 677 + DEVICE(0x0085), SUBDEV_MASKED(0xC000, 0xF000)), 676 678 IWL_DEV_INFO(iwl6005_n_cfg, iwl6005_2agn_d_name, 677 679 DEVICE(0x0082), SUBDEV(0x4820)), 678 680 IWL_DEV_INFO(iwl6005_n_cfg, iwl6005_2agn_mow1_name, ··· 731 729 DEVICE(0x0083), SUBDEV_MASKED(0x5, 0xF)), 732 730 IWL_DEV_INFO(iwl1000_bg_cfg, iwl1000_bg_name, 733 731 DEVICE(0x0083), SUBDEV_MASKED(0x6, 0xF)), 732 + IWL_DEV_INFO(iwl1000_bgn_cfg, iwl1000_bgn_name, 733 + DEVICE(0x0084), SUBDEV_MASKED(0x5, 0xF)), 734 734 IWL_DEV_INFO(iwl1000_bg_cfg, iwl1000_bg_name, 735 - DEVICE(0x0084), SUBDEV(0x1216)), 736 - IWL_DEV_INFO(iwl1000_bg_cfg, iwl1000_bg_name, 737 - DEVICE(0x0084), SUBDEV(0x1316)), 735 + DEVICE(0x0084), SUBDEV_MASKED(0x6, 0xF)), 738 736 739 737 /* 100 Series WiFi */ 740 738 IWL_DEV_INFO(iwl100_bgn_cfg, iwl100_bgn_name, ··· 966 964 DEVICE(0x24F3), SUBDEV(0x0004)), 967 965 IWL_DEV_INFO(iwl8260_cfg, iwl8260_2n_name, 968 966 DEVICE(0x24F3), SUBDEV(0x0044)), 967 + IWL_DEV_INFO(iwl8260_cfg, iwl8260_2ac_name, 968 + DEVICE(0x24F4)), 969 + IWL_DEV_INFO(iwl8260_cfg, iwl4165_2ac_name, 970 + DEVICE(0x24F5)), 971 + IWL_DEV_INFO(iwl8260_cfg, iwl4165_2ac_name, 972 + DEVICE(0x24F6)), 969 973 IWL_DEV_INFO(iwl8265_cfg, iwl8265_2ac_name, 970 974 DEVICE(0x24FD)), 971 975 IWL_DEV_INFO(iwl8265_cfg, iwl8275_2ac_name, ··· 1230 1222 * Note: MAC (bits 0:7) will be cleared upon suspend even with wowlan, 1231 1223 * but not bits [15:8]. So if we have bits set in lower word, assume 1232 1224 * the device is alive. 1225 + * Alternatively, if the scratch value is 0xFFFFFFFF, then we no longer 1226 + * have access to the device and consider it powered off. 1233 1227 * For older devices, just try silently to grab the NIC. 1234 1228 */ 1235 1229 if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { 1236 - if (!(iwl_read32(trans, CSR_FUNC_SCRATCH) & 1237 - CSR_FUNC_SCRATCH_POWER_OFF_MASK)) 1230 + u32 scratch = iwl_read32(trans, CSR_FUNC_SCRATCH); 1231 + 1232 + if (!(scratch & CSR_FUNC_SCRATCH_POWER_OFF_MASK) || 1233 + scratch == ~0U) 1238 1234 device_was_powered_off = true; 1239 1235 } else { 1240 1236 /*
+2 -1
drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c
··· 2092 2092 break; 2093 2093 } 2094 2094 2095 - if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) 2095 + if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_9000 && 2096 + trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) 2096 2097 len = DIV_ROUND_UP(len, 4); 2097 2098 2098 2099 if (WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX))
+6 -3
drivers/net/wireless/marvell/libertas/cfg.c
··· 1151 1151 /* add SSID TLV */ 1152 1152 rcu_read_lock(); 1153 1153 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); 1154 - if (ssid_eid) 1155 - pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]); 1156 - else 1154 + if (ssid_eid) { 1155 + u32 ssid_len = min(ssid_eid[1], IEEE80211_MAX_SSID_LEN); 1156 + 1157 + pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_len); 1158 + } else { 1157 1159 lbs_deb_assoc("no SSID\n"); 1160 + } 1158 1161 rcu_read_unlock(); 1159 1162 1160 1163 /* add DS param TLV */
+3 -2
drivers/net/wireless/marvell/mwifiex/cfg80211.c
··· 4673 4673 * additional active scan request for hidden SSIDs on passive channels. 4674 4674 */ 4675 4675 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a); 4676 - adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats), 4677 - adapter->num_in_chan_stats)); 4676 + adapter->chan_stats = kcalloc(adapter->num_in_chan_stats, 4677 + sizeof(*adapter->chan_stats), 4678 + GFP_KERNEL); 4678 4679 4679 4680 if (!adapter->chan_stats) 4680 4681 return -ENOMEM;
+2 -2
drivers/net/wireless/marvell/mwifiex/main.c
··· 642 642 goto done; 643 643 644 644 err_add_intf: 645 - vfree(adapter->chan_stats); 645 + kfree(adapter->chan_stats); 646 646 err_init_chan_scan: 647 647 wiphy_unregister(adapter->wiphy); 648 648 wiphy_free(adapter->wiphy); ··· 1485 1485 wiphy_free(adapter->wiphy); 1486 1486 adapter->wiphy = NULL; 1487 1487 1488 - vfree(adapter->chan_stats); 1488 + kfree(adapter->chan_stats); 1489 1489 mwifiex_free_cmd_buffers(adapter); 1490 1490 } 1491 1491
+42 -1
drivers/net/wireless/mediatek/mt76/mac80211.c
··· 818 818 } 819 819 EXPORT_SYMBOL_GPL(mt76_free_device); 820 820 821 + static void mt76_reset_phy(struct mt76_phy *phy) 822 + { 823 + if (!phy) 824 + return; 825 + 826 + INIT_LIST_HEAD(&phy->tx_list); 827 + } 828 + 829 + void mt76_reset_device(struct mt76_dev *dev) 830 + { 831 + int i; 832 + 833 + rcu_read_lock(); 834 + for (i = 0; i < ARRAY_SIZE(dev->wcid); i++) { 835 + struct mt76_wcid *wcid; 836 + 837 + wcid = rcu_dereference(dev->wcid[i]); 838 + if (!wcid) 839 + continue; 840 + 841 + wcid->sta = 0; 842 + mt76_wcid_cleanup(dev, wcid); 843 + rcu_assign_pointer(dev->wcid[i], NULL); 844 + } 845 + rcu_read_unlock(); 846 + 847 + INIT_LIST_HEAD(&dev->wcid_list); 848 + INIT_LIST_HEAD(&dev->sta_poll_list); 849 + dev->vif_mask = 0; 850 + memset(dev->wcid_mask, 0, sizeof(dev->wcid_mask)); 851 + 852 + mt76_reset_phy(&dev->phy); 853 + for (i = 0; i < ARRAY_SIZE(dev->phys); i++) 854 + mt76_reset_phy(dev->phys[i]); 855 + } 856 + EXPORT_SYMBOL_GPL(mt76_reset_device); 857 + 821 858 struct mt76_phy *mt76_vif_phy(struct ieee80211_hw *hw, 822 859 struct ieee80211_vif *vif) 823 860 { ··· 1716 1679 skb_queue_splice_tail_init(&wcid->tx_pending, &list); 1717 1680 spin_unlock(&wcid->tx_pending.lock); 1718 1681 1682 + spin_lock(&wcid->tx_offchannel.lock); 1683 + skb_queue_splice_tail_init(&wcid->tx_offchannel, &list); 1684 + spin_unlock(&wcid->tx_offchannel.lock); 1685 + 1719 1686 spin_unlock_bh(&phy->tx_lock); 1720 1687 1721 1688 while ((skb = __skb_dequeue(&list)) != NULL) { ··· 1731 1690 1732 1691 void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid) 1733 1692 { 1734 - if (test_bit(MT76_MCU_RESET, &dev->phy.state)) 1693 + if (test_bit(MT76_MCU_RESET, &dev->phy.state) || !wcid->sta) 1735 1694 return; 1736 1695 1737 1696 spin_lock_bh(&dev->sta_poll_lock);
+1
drivers/net/wireless/mediatek/mt76/mt76.h
··· 1243 1243 struct ieee80211_rate *rates, int n_rates); 1244 1244 void mt76_unregister_device(struct mt76_dev *dev); 1245 1245 void mt76_free_device(struct mt76_dev *dev); 1246 + void mt76_reset_device(struct mt76_dev *dev); 1246 1247 void mt76_unregister_phy(struct mt76_phy *phy); 1247 1248 1248 1249 struct mt76_phy *mt76_alloc_radio_phy(struct mt76_dev *dev, unsigned int size,
+5 -7
drivers/net/wireless/mediatek/mt76/mt7915/mac.c
··· 1460 1460 if (i == 10) 1461 1461 dev_err(dev->mt76.dev, "chip full reset failed\n"); 1462 1462 1463 - spin_lock_bh(&dev->mt76.sta_poll_lock); 1464 - while (!list_empty(&dev->mt76.sta_poll_list)) 1465 - list_del_init(dev->mt76.sta_poll_list.next); 1466 - spin_unlock_bh(&dev->mt76.sta_poll_lock); 1467 - 1468 - memset(dev->mt76.wcid_mask, 0, sizeof(dev->mt76.wcid_mask)); 1469 - dev->mt76.vif_mask = 0; 1470 1463 dev->phy.omac_mask = 0; 1471 1464 if (phy2) 1472 1465 phy2->omac_mask = 0; 1466 + 1467 + mt76_reset_device(&dev->mt76); 1468 + 1469 + INIT_LIST_HEAD(&dev->sta_rc_list); 1470 + INIT_LIST_HEAD(&dev->twt_list); 1473 1471 1474 1472 i = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA); 1475 1473 dev->mt76.global_wcid.idx = i;
+1 -4
drivers/net/wireless/mediatek/mt76/mt7921/main.c
··· 1459 1459 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc) 1460 1460 return -EOPNOTSUPP; 1461 1461 1462 - /* Avoid beacon loss due to the CAC(Channel Availability Check) time 1463 - * of the AP. 1464 - */ 1465 1462 if (!cfg80211_chandef_usable(hw->wiphy, &chsw->chandef, 1466 - IEEE80211_CHAN_RADAR)) 1463 + IEEE80211_CHAN_DISABLED)) 1467 1464 return -EOPNOTSUPP; 1468 1465 1469 1466 return 0;
+1 -1
drivers/net/wireless/mediatek/mt76/mt7925/mac.c
··· 1449 1449 sta = wcid_to_sta(wcid); 1450 1450 1451 1451 if (sta && likely(e->skb->protocol != cpu_to_be16(ETH_P_PAE))) 1452 - mt76_connac2_tx_check_aggr(sta, txwi); 1452 + mt7925_tx_check_aggr(sta, e->skb, wcid); 1453 1453 1454 1454 skb_pull(e->skb, headroom); 1455 1455 mt76_tx_complete_skb(mdev, e->wcid, e->skb);
+6 -1
drivers/net/wireless/mediatek/mt76/mt7925/main.c
··· 1191 1191 struct mt792x_bss_conf *mconf; 1192 1192 struct mt792x_link_sta *mlink; 1193 1193 1194 + if (vif->type == NL80211_IFTYPE_AP) 1195 + break; 1196 + 1194 1197 link_sta = mt792x_sta_to_link_sta(vif, sta, link_id); 1195 1198 if (!link_sta) 1196 1199 continue; ··· 2072 2069 GFP_KERNEL); 2073 2070 mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), 2074 2071 GFP_KERNEL); 2075 - if (!mconf || !mlink) 2072 + if (!mconf || !mlink) { 2073 + mt792x_mutex_release(dev); 2076 2074 return -ENOMEM; 2075 + } 2077 2076 } 2078 2077 2079 2078 mconfs[link_id] = mconf;
+8 -4
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
··· 1834 1834 struct tlv *tlv; 1835 1835 u16 eml_cap; 1836 1836 1837 + if (!ieee80211_vif_is_mld(vif)) 1838 + return; 1839 + 1837 1840 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_EHT_MLD, sizeof(*eht_mld)); 1838 1841 eht_mld = (struct sta_rec_eht_mld *)tlv; 1839 1842 eht_mld->mld_type = 0xff; 1840 - 1841 - if (!ieee80211_vif_is_mld(vif)) 1842 - return; 1843 1843 1844 1844 ext_capa = cfg80211_get_iftype_ext_capa(wiphy, 1845 1845 ieee80211_vif_type_p2p(vif)); ··· 1912 1912 struct mt76_dev *dev = phy->dev; 1913 1913 struct mt792x_bss_conf *mconf; 1914 1914 struct sk_buff *skb; 1915 + int conn_state; 1915 1916 1916 1917 mconf = mt792x_vif_to_link(mvif, info->wcid->link_id); 1917 1918 ··· 1921 1920 if (IS_ERR(skb)) 1922 1921 return PTR_ERR(skb); 1923 1922 1923 + conn_state = info->enable ? CONN_STATE_PORT_SECURE : 1924 + CONN_STATE_DISCONNECT; 1925 + 1924 1926 if (info->enable && info->link_sta) { 1925 1927 mt76_connac_mcu_sta_basic_tlv(dev, skb, info->link_conf, 1926 1928 info->link_sta, 1927 - info->enable, info->newly); 1929 + conn_state, info->newly); 1928 1930 mt7925_mcu_sta_phy_tlv(skb, info->vif, info->link_sta); 1929 1931 mt7925_mcu_sta_ht_tlv(skb, info->link_sta); 1930 1932 mt7925_mcu_sta_vht_tlv(skb, info->link_sta);
+38 -22
drivers/net/wireless/mediatek/mt76/mt7996/mac.c
··· 62 62 int i; 63 63 64 64 wcid = mt76_wcid_ptr(dev, idx); 65 - if (!wcid) 65 + if (!wcid || !wcid->sta) 66 66 return NULL; 67 67 68 68 if (!mt7996_band_valid(dev, band_idx)) ··· 903 903 IEEE80211_TX_CTRL_MLO_LINK); 904 904 905 905 mvif = vif ? (struct mt7996_vif *)vif->drv_priv : NULL; 906 - if (mvif) 907 - mlink = rcu_dereference(mvif->mt76.link[link_id]); 906 + if (mvif) { 907 + if (wcid->offchannel) 908 + mlink = rcu_dereference(mvif->mt76.offchannel_link); 909 + if (!mlink) 910 + mlink = rcu_dereference(mvif->mt76.link[link_id]); 911 + } 908 912 909 913 if (mlink) { 910 914 omac_idx = mlink->omac_idx; ··· 1247 1243 idx = FIELD_GET(MT_TXFREE_INFO_WLAN_ID, info); 1248 1244 wcid = mt76_wcid_ptr(dev, idx); 1249 1245 sta = wcid_to_sta(wcid); 1250 - if (!sta) 1246 + if (!sta) { 1247 + link_sta = NULL; 1251 1248 goto next; 1249 + } 1252 1250 1253 1251 link_sta = rcu_dereference(sta->link[wcid->link_id]); 1254 1252 if (!link_sta) ··· 1700 1694 static void 1701 1695 mt7996_update_vif_beacon(void *priv, u8 *mac, struct ieee80211_vif *vif) 1702 1696 { 1703 - struct ieee80211_hw *hw = priv; 1697 + struct ieee80211_bss_conf *link_conf; 1698 + struct mt7996_phy *phy = priv; 1699 + struct mt7996_dev *dev = phy->dev; 1700 + unsigned int link_id; 1701 + 1704 1702 1705 1703 switch (vif->type) { 1706 1704 case NL80211_IFTYPE_MESH_POINT: 1707 1705 case NL80211_IFTYPE_ADHOC: 1708 1706 case NL80211_IFTYPE_AP: 1709 - mt7996_mcu_add_beacon(hw, vif, &vif->bss_conf); 1710 1707 break; 1711 1708 default: 1712 - break; 1709 + return; 1713 1710 } 1711 + 1712 + for_each_vif_active_link(vif, link_conf, link_id) { 1713 + struct mt7996_vif_link *link; 1714 + 1715 + link = mt7996_vif_link(dev, vif, link_id); 1716 + if (!link || link->phy != phy) 1717 + continue; 1718 + 1719 + mt7996_mcu_add_beacon(dev->mt76.hw, vif, link_conf); 1720 + } 1721 + } 1722 + 1723 + void mt7996_mac_update_beacons(struct mt7996_phy *phy) 1724 + { 1725 + ieee80211_iterate_active_interfaces(phy->mt76->hw, 1726 + IEEE80211_IFACE_ITER_RESUME_ALL, 1727 + mt7996_update_vif_beacon, phy); 1714 1728 } 1715 1729 1716 1730 static void ··· 1738 1712 { 1739 1713 struct mt76_phy *phy2, *phy3; 1740 1714 1741 - ieee80211_iterate_active_interfaces(dev->mt76.hw, 1742 - IEEE80211_IFACE_ITER_RESUME_ALL, 1743 - mt7996_update_vif_beacon, dev->mt76.hw); 1715 + mt7996_mac_update_beacons(&dev->phy); 1744 1716 1745 1717 phy2 = dev->mt76.phys[MT_BAND1]; 1746 - if (!phy2) 1747 - return; 1748 - 1749 - ieee80211_iterate_active_interfaces(phy2->hw, 1750 - IEEE80211_IFACE_ITER_RESUME_ALL, 1751 - mt7996_update_vif_beacon, phy2->hw); 1718 + if (phy2) 1719 + mt7996_mac_update_beacons(phy2->priv); 1752 1720 1753 1721 phy3 = dev->mt76.phys[MT_BAND2]; 1754 - if (!phy3) 1755 - return; 1756 - 1757 - ieee80211_iterate_active_interfaces(phy3->hw, 1758 - IEEE80211_IFACE_ITER_RESUME_ALL, 1759 - mt7996_update_vif_beacon, phy3->hw); 1722 + if (phy3) 1723 + mt7996_mac_update_beacons(phy3->priv); 1760 1724 } 1761 1725 1762 1726 void mt7996_tx_token_put(struct mt7996_dev *dev)
+5
drivers/net/wireless/mediatek/mt76/mt7996/main.c
··· 516 516 struct mt7996_phy *phy = mphy->priv; 517 517 int ret; 518 518 519 + if (mphy->offchannel) 520 + mt7996_mac_update_beacons(phy); 521 + 519 522 ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_SWITCH); 520 523 if (ret) 521 524 goto out; ··· 536 533 537 534 mt7996_mac_reset_counters(phy); 538 535 phy->noise = 0; 536 + if (!mphy->offchannel) 537 + mt7996_mac_update_beacons(phy); 539 538 540 539 out: 541 540 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
+10 -5
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
··· 1879 1879 int mt7996_mcu_set_fixed_rate_ctrl(struct mt7996_dev *dev, 1880 1880 void *data, u16 version) 1881 1881 { 1882 + struct uni_header hdr = {}; 1882 1883 struct ra_fixed_rate *req; 1883 - struct uni_header hdr; 1884 1884 struct sk_buff *skb; 1885 1885 struct tlv *tlv; 1886 1886 int len; ··· 2755 2755 struct ieee80211_bss_conf *link_conf) 2756 2756 { 2757 2757 struct mt7996_dev *dev = mt7996_hw_dev(hw); 2758 - struct mt76_vif_link *mlink = mt76_vif_conf_link(&dev->mt76, vif, link_conf); 2758 + struct mt7996_vif_link *link = mt7996_vif_conf_link(dev, vif, link_conf); 2759 + struct mt76_vif_link *mlink = link ? &link->mt76 : NULL; 2759 2760 struct ieee80211_mutable_offsets offs; 2760 2761 struct ieee80211_tx_info *info; 2761 2762 struct sk_buff *skb, *rskb; 2762 2763 struct tlv *tlv; 2763 2764 struct bss_bcn_content_tlv *bcn; 2764 2765 int len, extra_len = 0; 2766 + bool enabled = link_conf->enable_beacon; 2765 2767 2766 2768 if (link_conf->nontransmitted) 2767 2769 return 0; ··· 2771 2769 if (!mlink) 2772 2770 return -EINVAL; 2773 2771 2772 + if (link->phy && link->phy->mt76->offchannel) 2773 + enabled = false; 2774 + 2774 2775 rskb = __mt7996_mcu_alloc_bss_req(&dev->mt76, mlink, 2775 2776 MT7996_MAX_BSS_OFFLOAD_SIZE); 2776 2777 if (IS_ERR(rskb)) 2777 2778 return PTR_ERR(rskb); 2778 2779 2779 2780 skb = ieee80211_beacon_get_template(hw, vif, &offs, link_conf->link_id); 2780 - if (link_conf->enable_beacon && !skb) { 2781 + if (enabled && !skb) { 2781 2782 dev_kfree_skb(rskb); 2782 2783 return -EINVAL; 2783 2784 } ··· 2799 2794 len = ALIGN(sizeof(*bcn) + MT_TXD_SIZE + extra_len, 4); 2800 2795 tlv = mt7996_mcu_add_uni_tlv(rskb, UNI_BSS_INFO_BCN_CONTENT, len); 2801 2796 bcn = (struct bss_bcn_content_tlv *)tlv; 2802 - bcn->enable = link_conf->enable_beacon; 2797 + bcn->enable = enabled; 2803 2798 if (!bcn->enable) 2804 2799 goto out; 2805 2800 ··· 3377 3372 { 3378 3373 struct { 3379 3374 u8 __rsv[4]; 3380 - } __packed hdr; 3375 + } __packed hdr = {}; 3381 3376 struct hdr_trans_blacklist *req_blacklist; 3382 3377 struct hdr_trans_en *req_en; 3383 3378 struct sk_buff *skb;
+1
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
··· 732 732 struct sk_buff *skb, struct mt76_wcid *wcid, 733 733 struct ieee80211_key_conf *key, int pid, 734 734 enum mt76_txq_id qid, u32 changed); 735 + void mt7996_mac_update_beacons(struct mt7996_phy *phy); 735 736 void mt7996_mac_set_coverage_class(struct mt7996_phy *phy); 736 737 void mt7996_mac_work(struct work_struct *work); 737 738 void mt7996_mac_reset_work(struct work_struct *work);
+6 -6
drivers/net/wireless/mediatek/mt76/tx.c
··· 332 332 struct mt76_wcid *wcid, struct sk_buff *skb) 333 333 { 334 334 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 335 + struct ieee80211_hdr *hdr = (void *)skb->data; 335 336 struct sk_buff_head *head; 336 337 337 338 if (mt76_testmode_enabled(phy)) { ··· 350 349 info->hw_queue |= FIELD_PREP(MT_TX_HW_QUEUE_PHY, phy->band_idx); 351 350 352 351 if ((info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) || 353 - (info->control.flags & IEEE80211_TX_CTRL_DONT_USE_RATE_MASK)) 352 + ((info->control.flags & IEEE80211_TX_CTRL_DONT_USE_RATE_MASK) && 353 + ieee80211_is_probe_req(hdr->frame_control))) 354 354 head = &wcid->tx_offchannel; 355 355 else 356 356 head = &wcid->tx_pending; ··· 646 644 static void mt76_txq_schedule_pending(struct mt76_phy *phy) 647 645 { 648 646 LIST_HEAD(tx_list); 647 + int ret = 0; 649 648 650 649 if (list_empty(&phy->tx_list)) 651 650 return; ··· 658 655 list_splice_init(&phy->tx_list, &tx_list); 659 656 while (!list_empty(&tx_list)) { 660 657 struct mt76_wcid *wcid; 661 - int ret; 662 658 663 659 wcid = list_first_entry(&tx_list, struct mt76_wcid, tx_list); 664 660 list_del_init(&wcid->tx_list); 665 661 666 662 spin_unlock(&phy->tx_lock); 667 - ret = mt76_txq_schedule_pending_wcid(phy, wcid, &wcid->tx_offchannel); 663 + if (ret >= 0) 664 + ret = mt76_txq_schedule_pending_wcid(phy, wcid, &wcid->tx_offchannel); 668 665 if (ret >= 0 && !phy->offchannel) 669 666 ret = mt76_txq_schedule_pending_wcid(phy, wcid, &wcid->tx_pending); 670 667 spin_lock(&phy->tx_lock); ··· 673 670 !skb_queue_empty(&wcid->tx_offchannel) && 674 671 list_empty(&wcid->tx_list)) 675 672 list_add_tail(&wcid->tx_list, &phy->tx_list); 676 - 677 - if (ret < 0) 678 - break; 679 673 } 680 674 spin_unlock(&phy->tx_lock); 681 675
+28 -11
drivers/net/wireless/microchip/wilc1000/wlan_cfg.c
··· 41 41 }; 42 42 43 43 static const struct wilc_cfg_str g_cfg_str[] = { 44 - {WID_FIRMWARE_VERSION, NULL}, 45 - {WID_MAC_ADDR, NULL}, 46 - {WID_ASSOC_RES_INFO, NULL}, 47 - {WID_NIL, NULL} 44 + {WID_FIRMWARE_VERSION, 0, NULL}, 45 + {WID_MAC_ADDR, 0, NULL}, 46 + {WID_ASSOC_RES_INFO, 0, NULL}, 47 + {WID_NIL, 0, NULL} 48 48 }; 49 49 50 50 #define WILC_RESP_MSG_TYPE_CONFIG_REPLY 'R' ··· 147 147 148 148 switch (FIELD_GET(WILC_WID_TYPE, wid)) { 149 149 case WID_CHAR: 150 + len = 3; 151 + if (len + 2 > size) 152 + return; 153 + 150 154 while (cfg->b[i].id != WID_NIL && cfg->b[i].id != wid) 151 155 i++; 152 156 153 157 if (cfg->b[i].id == wid) 154 158 cfg->b[i].val = info[4]; 155 159 156 - len = 3; 157 160 break; 158 161 159 162 case WID_SHORT: 163 + len = 4; 164 + if (len + 2 > size) 165 + return; 166 + 160 167 while (cfg->hw[i].id != WID_NIL && cfg->hw[i].id != wid) 161 168 i++; 162 169 163 170 if (cfg->hw[i].id == wid) 164 171 cfg->hw[i].val = get_unaligned_le16(&info[4]); 165 172 166 - len = 4; 167 173 break; 168 174 169 175 case WID_INT: 176 + len = 6; 177 + if (len + 2 > size) 178 + return; 179 + 170 180 while (cfg->w[i].id != WID_NIL && cfg->w[i].id != wid) 171 181 i++; 172 182 173 183 if (cfg->w[i].id == wid) 174 184 cfg->w[i].val = get_unaligned_le32(&info[4]); 175 185 176 - len = 6; 177 186 break; 178 187 179 188 case WID_STR: 189 + len = 2 + get_unaligned_le16(&info[2]); 190 + 180 191 while (cfg->s[i].id != WID_NIL && cfg->s[i].id != wid) 181 192 i++; 182 193 183 - if (cfg->s[i].id == wid) 184 - memcpy(cfg->s[i].str, &info[2], 185 - get_unaligned_le16(&info[2]) + 2); 194 + if (cfg->s[i].id == wid) { 195 + if (len > cfg->s[i].len || (len + 2 > size)) 196 + return; 186 197 187 - len = 2 + get_unaligned_le16(&info[2]); 198 + memcpy(cfg->s[i].str, &info[2], 199 + len); 200 + } 201 + 188 202 break; 189 203 190 204 default: ··· 398 384 /* store the string cfg parameters */ 399 385 wl->cfg.s[i].id = WID_FIRMWARE_VERSION; 400 386 wl->cfg.s[i].str = str_vals->firmware_version; 387 + wl->cfg.s[i].len = sizeof(str_vals->firmware_version); 401 388 i++; 402 389 wl->cfg.s[i].id = WID_MAC_ADDR; 403 390 wl->cfg.s[i].str = str_vals->mac_address; 391 + wl->cfg.s[i].len = sizeof(str_vals->mac_address); 404 392 i++; 405 393 wl->cfg.s[i].id = WID_ASSOC_RES_INFO; 406 394 wl->cfg.s[i].str = str_vals->assoc_rsp; 395 + wl->cfg.s[i].len = sizeof(str_vals->assoc_rsp); 407 396 i++; 408 397 wl->cfg.s[i].id = WID_NIL; 409 398 wl->cfg.s[i].str = NULL;
+3 -2
drivers/net/wireless/microchip/wilc1000/wlan_cfg.h
··· 24 24 25 25 struct wilc_cfg_str { 26 26 u16 id; 27 + u16 len; 27 28 u8 *str; 28 29 }; 29 30 30 31 struct wilc_cfg_str_vals { 31 - u8 mac_address[7]; 32 - u8 firmware_version[129]; 32 + u8 mac_address[8]; 33 + u8 firmware_version[130]; 33 34 u8 assoc_rsp[WILC_MAX_ASSOC_RESP_FRAME_SIZE]; 34 35 }; 35 36
+2 -2
drivers/net/wireless/ralink/rt2x00/Kconfig
··· 66 66 select RT2X00_LIB_PCI 67 67 select RT2X00_LIB_FIRMWARE 68 68 select RT2X00_LIB_CRYPTO 69 - select CRC_CCITT 70 69 select EEPROM_93CX6 71 70 help 72 71 This adds support for rt27xx/rt28xx/rt30xx wireless chipset family. ··· 141 142 select RT2X00_LIB_USB 142 143 select RT2X00_LIB_FIRMWARE 143 144 select RT2X00_LIB_CRYPTO 144 - select CRC_CCITT 145 145 help 146 146 This adds support for rt27xx/rt28xx/rt30xx wireless chipset family. 147 147 Supported chips: RT2770, RT2870 & RT3070, RT3071 & RT3072 ··· 215 217 216 218 config RT2800_LIB 217 219 tristate 220 + select CRC_CCITT 218 221 219 222 config RT2800_LIB_MMIO 220 223 tristate ··· 224 225 225 226 config RT2X00_LIB_MMIO 226 227 tristate 228 + select RT2X00_LIB 227 229 228 230 config RT2X00_LIB_PCI 229 231 tristate
+1 -1
drivers/net/wireless/st/cw1200/sta.c
··· 1291 1291 rcu_read_lock(); 1292 1292 ssidie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); 1293 1293 if (ssidie) { 1294 - join.ssid_len = ssidie[1]; 1294 + join.ssid_len = min(ssidie[1], IEEE80211_MAX_SSID_LEN); 1295 1295 memcpy(join.ssid, &ssidie[2], join.ssid_len); 1296 1296 } 1297 1297 rcu_read_unlock();
+1 -2
drivers/ptp/ptp_ocp.c
··· 4557 4557 ptp_ocp_debugfs_remove_device(bp); 4558 4558 ptp_ocp_detach_sysfs(bp); 4559 4559 ptp_ocp_attr_group_del(bp); 4560 - if (timer_pending(&bp->watchdog)) 4561 - timer_delete_sync(&bp->watchdog); 4560 + timer_delete_sync(&bp->watchdog); 4562 4561 if (bp->ts0) 4563 4562 ptp_ocp_unregister_ext(bp->ts0); 4564 4563 if (bp->ts1)
+5
include/linux/phy.h
··· 169 169 return bitmap_empty(intf, PHY_INTERFACE_MODE_MAX); 170 170 } 171 171 172 + static inline unsigned int phy_interface_weight(const unsigned long *intf) 173 + { 174 + return bitmap_weight(intf, PHY_INTERFACE_MODE_MAX); 175 + } 176 + 172 177 static inline void phy_interface_and(unsigned long *dst, const unsigned long *a, 173 178 const unsigned long *b) 174 179 {
+13 -4
include/net/sock.h
··· 285 285 * @sk_ack_backlog: current listen backlog 286 286 * @sk_max_ack_backlog: listen backlog set in listen() 287 287 * @sk_uid: user id of owner 288 + * @sk_ino: inode number (zero if orphaned) 288 289 * @sk_prefer_busy_poll: prefer busypolling over softirq processing 289 290 * @sk_busy_poll_budget: napi processing budget when busypolling 290 291 * @sk_priority: %SO_PRIORITY setting ··· 519 518 u32 sk_ack_backlog; 520 519 u32 sk_max_ack_backlog; 521 520 kuid_t sk_uid; 521 + unsigned long sk_ino; 522 522 spinlock_t sk_peer_lock; 523 523 int sk_bind_phc; 524 524 struct pid *sk_peer_pid; ··· 2058 2056 static inline void sk_set_socket(struct sock *sk, struct socket *sock) 2059 2057 { 2060 2058 sk->sk_socket = sock; 2059 + if (sock) { 2060 + WRITE_ONCE(sk->sk_uid, SOCK_INODE(sock)->i_uid); 2061 + WRITE_ONCE(sk->sk_ino, SOCK_INODE(sock)->i_ino); 2062 + } 2061 2063 } 2062 2064 2063 2065 static inline wait_queue_head_t *sk_sleep(struct sock *sk) ··· 2083 2077 sk_set_socket(sk, NULL); 2084 2078 sk->sk_wq = NULL; 2085 2079 /* Note: sk_uid is unchanged. */ 2080 + WRITE_ONCE(sk->sk_ino, 0); 2086 2081 write_unlock_bh(&sk->sk_callback_lock); 2087 2082 } 2088 2083 ··· 2094 2087 rcu_assign_pointer(sk->sk_wq, &parent->wq); 2095 2088 parent->sk = sk; 2096 2089 sk_set_socket(sk, parent); 2097 - WRITE_ONCE(sk->sk_uid, SOCK_INODE(parent)->i_uid); 2098 2090 security_sock_graft(sk, parent); 2099 2091 write_unlock_bh(&sk->sk_callback_lock); 2092 + } 2093 + 2094 + static inline unsigned long sock_i_ino(const struct sock *sk) 2095 + { 2096 + /* Paired with WRITE_ONCE() in sock_graft() and sock_orphan() */ 2097 + return READ_ONCE(sk->sk_ino); 2100 2098 } 2101 2099 2102 2100 static inline kuid_t sk_uid(const struct sock *sk) ··· 2109 2097 /* Paired with WRITE_ONCE() in sockfs_setattr() */ 2110 2098 return READ_ONCE(sk->sk_uid); 2111 2099 } 2112 - 2113 - unsigned long __sock_i_ino(struct sock *sk); 2114 - unsigned long sock_i_ino(struct sock *sk); 2115 2100 2116 2101 static inline kuid_t sock_net_uid(const struct net *net, const struct sock *sk) 2117 2102 {
+2
include/uapi/linux/netfilter/nf_tables.h
··· 1784 1784 * enum nft_device_attributes - nf_tables device netlink attributes 1785 1785 * 1786 1786 * @NFTA_DEVICE_NAME: name of this device (NLA_STRING) 1787 + * @NFTA_DEVICE_PREFIX: device name prefix, a simple wildcard (NLA_STRING) 1787 1788 */ 1788 1789 enum nft_devices_attributes { 1789 1790 NFTA_DEVICE_UNSPEC, 1790 1791 NFTA_DEVICE_NAME, 1792 + NFTA_DEVICE_PREFIX, 1791 1793 __NFTA_DEVICE_MAX 1792 1794 }; 1793 1795 #define NFTA_DEVICE_MAX (__NFTA_DEVICE_MAX - 1)
+4 -2
net/atm/resources.c
··· 112 112 113 113 if (atm_proc_dev_register(dev) < 0) { 114 114 pr_err("atm_proc_dev_register failed for dev %s\n", type); 115 - goto out_fail; 115 + mutex_unlock(&atm_dev_mutex); 116 + kfree(dev); 117 + return NULL; 116 118 } 117 119 118 120 if (atm_register_sysfs(dev, parent) < 0) { ··· 130 128 return dev; 131 129 132 130 out_fail: 133 - kfree(dev); 131 + put_device(&dev->class_dev); 134 132 dev = NULL; 135 133 goto out; 136 134 }
+4
net/ax25/ax25_in.c
··· 433 433 int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev, 434 434 struct packet_type *ptype, struct net_device *orig_dev) 435 435 { 436 + skb = skb_share_check(skb, GFP_ATOMIC); 437 + if (!skb) 438 + return NET_RX_DROP; 439 + 436 440 skb_orphan(skb); 437 441 438 442 if (!net_eq(dev_net(dev), &init_net)) {
+6 -1
net/batman-adv/network-coding.c
··· 1687 1687 1688 1688 coding_len = ntohs(coded_packet_tmp.coded_len); 1689 1689 1690 - if (coding_len > skb->len) 1690 + /* ensure dst buffer is large enough (payload only) */ 1691 + if (coding_len + h_size > skb->len) 1692 + return NULL; 1693 + 1694 + /* ensure src buffer is large enough (payload only) */ 1695 + if (coding_len + h_size > nc_packet->skb->len) 1691 1696 return NULL; 1692 1697 1693 1698 /* Here the magic is reversed:
+3
net/bluetooth/l2cap_sock.c
··· 1422 1422 if (!sk) 1423 1423 return 0; 1424 1424 1425 + lock_sock_nested(sk, L2CAP_NESTING_PARENT); 1425 1426 l2cap_sock_cleanup_listen(sk); 1427 + release_sock(sk); 1428 + 1426 1429 bt_sock_unlink(&l2cap_sk_list, sk); 1427 1430 1428 1431 err = l2cap_sock_shutdown(sock, SHUT_RDWR);
-3
net/bridge/br_netfilter_hooks.c
··· 626 626 break; 627 627 } 628 628 629 - ct = container_of(nfct, struct nf_conn, ct_general); 630 - WARN_ON_ONCE(!nf_ct_is_confirmed(ct)); 631 - 632 629 return ret; 633 630 } 634 631 #endif
+2
net/core/gen_estimator.c
··· 90 90 rate = (b_packets - est->last_packets) << (10 - est->intvl_log); 91 91 rate = (rate >> est->ewma_log) - (est->avpps >> est->ewma_log); 92 92 93 + preempt_disable_nested(); 93 94 write_seqcount_begin(&est->seq); 94 95 est->avbps += brate; 95 96 est->avpps += rate; 96 97 write_seqcount_end(&est->seq); 98 + preempt_enable_nested(); 97 99 98 100 est->last_bytes = b_bytes; 99 101 est->last_packets = b_packets;
-22
net/core/sock.c
··· 2780 2780 EXPORT_SYMBOL(sock_pfree); 2781 2781 #endif /* CONFIG_INET */ 2782 2782 2783 - unsigned long __sock_i_ino(struct sock *sk) 2784 - { 2785 - unsigned long ino; 2786 - 2787 - read_lock(&sk->sk_callback_lock); 2788 - ino = sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_ino : 0; 2789 - read_unlock(&sk->sk_callback_lock); 2790 - return ino; 2791 - } 2792 - EXPORT_SYMBOL(__sock_i_ino); 2793 - 2794 - unsigned long sock_i_ino(struct sock *sk) 2795 - { 2796 - unsigned long ino; 2797 - 2798 - local_bh_disable(); 2799 - ino = __sock_i_ino(sk); 2800 - local_bh_enable(); 2801 - return ino; 2802 - } 2803 - EXPORT_SYMBOL(sock_i_ino); 2804 - 2805 2783 /* 2806 2784 * Allocate a skb from the socket's send buffer. 2807 2785 */
+3 -4
net/ipv4/devinet.c
··· 340 340 341 341 static int __init inet_blackhole_dev_init(void) 342 342 { 343 - int err = 0; 343 + struct in_device *in_dev; 344 344 345 345 rtnl_lock(); 346 - if (!inetdev_init(blackhole_netdev)) 347 - err = -ENOMEM; 346 + in_dev = inetdev_init(blackhole_netdev); 348 347 rtnl_unlock(); 349 348 350 - return err; 349 + return PTR_ERR_OR_ZERO(in_dev); 351 350 } 352 351 late_initcall(inet_blackhole_dev_init); 353 352
+4 -2
net/ipv4/icmp.c
··· 799 799 struct sk_buff *cloned_skb = NULL; 800 800 struct ip_options opts = { 0 }; 801 801 enum ip_conntrack_info ctinfo; 802 + enum ip_conntrack_dir dir; 802 803 struct nf_conn *ct; 803 804 __be32 orig_ip; 804 805 805 806 ct = nf_ct_get(skb_in, &ctinfo); 806 - if (!ct || !(ct->status & IPS_SRC_NAT)) { 807 + if (!ct || !(READ_ONCE(ct->status) & IPS_NAT_MASK)) { 807 808 __icmp_send(skb_in, type, code, info, &opts); 808 809 return; 809 810 } ··· 819 818 goto out; 820 819 821 820 orig_ip = ip_hdr(skb_in)->saddr; 822 - ip_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.ip; 821 + dir = CTINFO2DIR(ctinfo); 822 + ip_hdr(skb_in)->saddr = ct->tuplehash[dir].tuple.src.u3.ip; 823 823 __icmp_send(skb_in, type, code, info, &opts); 824 824 ip_hdr(skb_in)->saddr = orig_ip; 825 825 out:
+2 -4
net/ipv6/exthdrs.c
··· 494 494 495 495 idev = __in6_dev_get(skb->dev); 496 496 497 - accept_rpl_seg = net->ipv6.devconf_all->rpl_seg_enabled; 498 - if (accept_rpl_seg > idev->cnf.rpl_seg_enabled) 499 - accept_rpl_seg = idev->cnf.rpl_seg_enabled; 500 - 497 + accept_rpl_seg = min(READ_ONCE(net->ipv6.devconf_all->rpl_seg_enabled), 498 + READ_ONCE(idev->cnf.rpl_seg_enabled)); 501 499 if (!accept_rpl_seg) { 502 500 kfree_skb(skb); 503 501 return -1;
+4 -2
net/ipv6/ip6_icmp.c
··· 54 54 struct inet6_skb_parm parm = { 0 }; 55 55 struct sk_buff *cloned_skb = NULL; 56 56 enum ip_conntrack_info ctinfo; 57 + enum ip_conntrack_dir dir; 57 58 struct in6_addr orig_ip; 58 59 struct nf_conn *ct; 59 60 60 61 ct = nf_ct_get(skb_in, &ctinfo); 61 - if (!ct || !(ct->status & IPS_SRC_NAT)) { 62 + if (!ct || !(READ_ONCE(ct->status) & IPS_NAT_MASK)) { 62 63 __icmpv6_send(skb_in, type, code, info, &parm); 63 64 return; 64 65 } ··· 74 73 goto out; 75 74 76 75 orig_ip = ipv6_hdr(skb_in)->saddr; 77 - ipv6_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.in6; 76 + dir = CTINFO2DIR(ctinfo); 77 + ipv6_hdr(skb_in)->saddr = ct->tuplehash[dir].tuple.src.u3.in6; 78 78 __icmpv6_send(skb_in, type, code, info, &parm); 79 79 ipv6_hdr(skb_in)->saddr = orig_ip; 80 80 out:
+15 -17
net/ipv6/tcp_ipv6.c
··· 1431 1431 ireq = inet_rsk(req); 1432 1432 1433 1433 if (sk_acceptq_is_full(sk)) 1434 - goto out_overflow; 1434 + goto exit_overflow; 1435 1435 1436 1436 if (!dst) { 1437 1437 dst = inet6_csk_route_req(sk, &fl6, req, IPPROTO_TCP); 1438 1438 if (!dst) 1439 - goto out; 1439 + goto exit; 1440 1440 } 1441 1441 1442 1442 newsk = tcp_create_openreq_child(sk, req, skb); 1443 1443 if (!newsk) 1444 - goto out_nonewsk; 1444 + goto exit_nonewsk; 1445 1445 1446 1446 /* 1447 1447 * No need to charge this sock to the relevant IPv6 refcnt debug socks ··· 1525 1525 const union tcp_md5_addr *addr; 1526 1526 1527 1527 addr = (union tcp_md5_addr *)&newsk->sk_v6_daddr; 1528 - if (tcp_md5_key_copy(newsk, addr, AF_INET6, 128, l3index, key)) { 1529 - inet_csk_prepare_forced_close(newsk); 1530 - tcp_done(newsk); 1531 - goto out; 1532 - } 1528 + if (tcp_md5_key_copy(newsk, addr, AF_INET6, 128, l3index, key)) 1529 + goto put_and_exit; 1533 1530 } 1534 1531 } 1535 1532 #endif 1536 1533 #ifdef CONFIG_TCP_AO 1537 1534 /* Copy over tcp_ao_info if any */ 1538 1535 if (tcp_ao_copy_all_matching(sk, newsk, req, skb, AF_INET6)) 1539 - goto out; /* OOM */ 1536 + goto put_and_exit; /* OOM */ 1540 1537 #endif 1541 1538 1542 - if (__inet_inherit_port(sk, newsk) < 0) { 1543 - inet_csk_prepare_forced_close(newsk); 1544 - tcp_done(newsk); 1545 - goto out; 1546 - } 1539 + if (__inet_inherit_port(sk, newsk) < 0) 1540 + goto put_and_exit; 1547 1541 *own_req = inet_ehash_nolisten(newsk, req_to_sk(req_unhash), 1548 1542 &found_dup_sk); 1549 1543 if (*own_req) { ··· 1564 1570 1565 1571 return newsk; 1566 1572 1567 - out_overflow: 1573 + exit_overflow: 1568 1574 __NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); 1569 - out_nonewsk: 1575 + exit_nonewsk: 1570 1576 dst_release(dst); 1571 - out: 1577 + exit: 1572 1578 tcp_listendrop(sk); 1573 1579 return NULL; 1580 + put_and_exit: 1581 + inet_csk_prepare_forced_close(newsk); 1582 + tcp_done(newsk); 1583 + goto exit; 1574 1584 } 1575 1585 1576 1586 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,
+1 -1
net/mac80211/driver-ops.h
··· 1416 1416 struct ieee80211_sub_if_data *sdata, 1417 1417 struct cfg80211_ftm_responder_stats *ftm_stats) 1418 1418 { 1419 - u32 ret = -EOPNOTSUPP; 1419 + int ret = -EOPNOTSUPP; 1420 1420 1421 1421 might_sleep(); 1422 1422 lockdep_assert_wiphy(local->hw.wiphy);
+6 -1
net/mac80211/main.c
··· 1111 1111 int result, i; 1112 1112 enum nl80211_band band; 1113 1113 int channels, max_bitrates; 1114 - bool supp_ht, supp_vht, supp_he, supp_eht; 1114 + bool supp_ht, supp_vht, supp_he, supp_eht, supp_s1g; 1115 1115 struct cfg80211_chan_def dflt_chandef = {}; 1116 1116 1117 1117 if (ieee80211_hw_check(hw, QUEUE_CONTROL) && ··· 1227 1227 supp_vht = false; 1228 1228 supp_he = false; 1229 1229 supp_eht = false; 1230 + supp_s1g = false; 1230 1231 for (band = 0; band < NUM_NL80211_BANDS; band++) { 1231 1232 const struct ieee80211_sband_iftype_data *iftd; 1232 1233 struct ieee80211_supported_band *sband; ··· 1275 1274 max_bitrates = sband->n_bitrates; 1276 1275 supp_ht = supp_ht || sband->ht_cap.ht_supported; 1277 1276 supp_vht = supp_vht || sband->vht_cap.vht_supported; 1277 + supp_s1g = supp_s1g || sband->s1g_cap.s1g; 1278 1278 1279 1279 for_each_sband_iftype_data(sband, i, iftd) { 1280 1280 u8 he_40_mhz_cap; ··· 1407 1405 if (supp_vht) 1408 1406 local->scan_ies_len += 1409 1407 2 + sizeof(struct ieee80211_vht_cap); 1408 + 1409 + if (supp_s1g) 1410 + local->scan_ies_len += 2 + sizeof(struct ieee80211_s1g_cap); 1410 1411 1411 1412 /* 1412 1413 * HE cap element is variable in size - set len to allow max size */
+8
net/mac80211/mlme.c
··· 1189 1189 "required MCSes not supported, disabling EHT\n"); 1190 1190 } 1191 1191 1192 + if (conn->mode >= IEEE80211_CONN_MODE_EHT && 1193 + channel->band != NL80211_BAND_2GHZ && 1194 + conn->bw_limit == IEEE80211_CONN_BW_LIMIT_40) { 1195 + conn->mode = IEEE80211_CONN_MODE_HE; 1196 + link_id_info(sdata, link_id, 1197 + "required bandwidth not supported, disabling EHT\n"); 1198 + } 1199 + 1192 1200 /* the mode can only decrease, so this must terminate */ 1193 1201 if (ap_mode != conn->mode) { 1194 1202 kfree(elems);
+25 -5
net/mac80211/tests/chan-mode.c
··· 2 2 /* 3 3 * KUnit tests for channel mode functions 4 4 * 5 - * Copyright (C) 2024 Intel Corporation 5 + * Copyright (C) 2024-2025 Intel Corporation 6 6 */ 7 7 #include <net/cfg80211.h> 8 8 #include <kunit/test.h> ··· 28 28 u8 vht_basic_mcs_1_4, vht_basic_mcs_5_8; 29 29 u8 he_basic_mcs_1_4, he_basic_mcs_5_8; 30 30 u8 eht_mcs7_min_nss; 31 + u16 eht_disabled_subchannels; 32 + u8 eht_bw; 33 + enum ieee80211_conn_bw_limit conn_bw_limit; 34 + enum ieee80211_conn_bw_limit expected_bw_limit; 31 35 int error; 32 36 } determine_chan_mode_cases[] = { 33 37 { ··· 132 128 .conn_mode = IEEE80211_CONN_MODE_EHT, 133 129 .eht_mcs7_min_nss = 0x15, 134 130 .error = EINVAL, 131 + }, { 132 + .desc = "80 MHz EHT is downgraded to 40 MHz HE due to puncturing", 133 + .conn_mode = IEEE80211_CONN_MODE_EHT, 134 + .expected_mode = IEEE80211_CONN_MODE_HE, 135 + .conn_bw_limit = IEEE80211_CONN_BW_LIMIT_80, 136 + .expected_bw_limit = IEEE80211_CONN_BW_LIMIT_40, 137 + .eht_disabled_subchannels = 0x08, 138 + .eht_bw = IEEE80211_EHT_OPER_CHAN_WIDTH_80MHZ, 135 139 } 136 140 }; 137 141 KUNIT_ARRAY_PARAM_DESC(determine_chan_mode, determine_chan_mode_cases, desc) ··· 150 138 struct t_sdata *t_sdata = T_SDATA(test); 151 139 struct ieee80211_conn_settings conn = { 152 140 .mode = params->conn_mode, 153 - .bw_limit = IEEE80211_CONN_BW_LIMIT_20, 141 + .bw_limit = params->conn_bw_limit, 154 142 }; 155 143 struct cfg80211_bss cbss = { 156 144 .channel = &t_sdata->band_5ghz.channels[0], ··· 203 191 0x7f, 0x01, 0x00, 0x88, 0x88, 0x88, 0x00, 0x00, 204 192 0x00, 205 193 /* EHT Operation */ 206 - WLAN_EID_EXTENSION, 0x09, WLAN_EID_EXT_EHT_OPERATION, 207 - 0x01, params->eht_mcs7_min_nss ? params->eht_mcs7_min_nss : 0x11, 208 - 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 194 + WLAN_EID_EXTENSION, 0x0b, WLAN_EID_EXT_EHT_OPERATION, 195 + 0x03, params->eht_mcs7_min_nss ? params->eht_mcs7_min_nss : 0x11, 196 + 0x00, 0x00, 0x00, params->eht_bw, 197 + params->eht_bw == IEEE80211_EHT_OPER_CHAN_WIDTH_80MHZ ? 42 : 36, 198 + 0x00, 199 + u16_get_bits(params->eht_disabled_subchannels, 0xff), 200 + u16_get_bits(params->eht_disabled_subchannels, 0xff00), 209 201 }; 210 202 struct ieee80211_chan_req chanreq = {}; 211 203 struct cfg80211_chan_def ap_chandef = {}; 212 204 struct ieee802_11_elems *elems; 205 + 206 + /* To force EHT downgrade to HE on punctured 80 MHz downgraded to 40 MHz */ 207 + set_bit(IEEE80211_HW_DISALLOW_PUNCTURING, t_sdata->local.hw.flags); 213 208 214 209 if (params->strict) 215 210 set_bit(IEEE80211_HW_STRICT, t_sdata->local.hw.flags); ··· 256 237 } else { 257 238 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, elems); 258 239 KUNIT_ASSERT_EQ(test, conn.mode, params->expected_mode); 240 + KUNIT_ASSERT_EQ(test, conn.bw_limit, params->expected_bw_limit); 259 241 } 260 242 } 261 243
+1 -1
net/mctp/af_mctp.c
··· 425 425 return 0; 426 426 } 427 427 428 - return -EINVAL; 428 + return -ENOPROTOOPT; 429 429 } 430 430 431 431 /* helpers for reading/writing the tag ioc, handling compatibility across the
+19 -16
net/mctp/route.c
··· 378 378 static void mctp_flow_prepare_output(struct sk_buff *skb, struct mctp_dev *dev) {} 379 379 #endif 380 380 381 + /* takes ownership of skb, both in success and failure cases */ 381 382 static int mctp_frag_queue(struct mctp_sk_key *key, struct sk_buff *skb) 382 383 { 383 384 struct mctp_hdr *hdr = mctp_hdr(skb); ··· 388 387 & MCTP_HDR_SEQ_MASK; 389 388 390 389 if (!key->reasm_head) { 391 - /* Since we're manipulating the shared frag_list, ensure it isn't 392 - * shared with any other SKBs. 390 + /* Since we're manipulating the shared frag_list, ensure it 391 + * isn't shared with any other SKBs. In the cloned case, 392 + * this will free the skb; callers can no longer access it 393 + * safely. 393 394 */ 394 395 key->reasm_head = skb_unshare(skb, GFP_ATOMIC); 395 396 if (!key->reasm_head) ··· 405 402 exp_seq = (key->last_seq + 1) & MCTP_HDR_SEQ_MASK; 406 403 407 404 if (this_seq != exp_seq) 408 - return -EINVAL; 405 + goto err_free; 409 406 410 407 if (key->reasm_head->len + skb->len > mctp_message_maxlen) 411 - return -EINVAL; 408 + goto err_free; 412 409 413 410 skb->next = NULL; 414 411 skb->sk = NULL; ··· 422 419 key->reasm_head->truesize += skb->truesize; 423 420 424 421 return 0; 422 + 423 + err_free: 424 + kfree_skb(skb); 425 + return -EINVAL; 425 426 } 426 427 427 428 static int mctp_dst_input(struct mctp_dst *dst, struct sk_buff *skb) ··· 539 532 * key isn't observable yet 540 533 */ 541 534 mctp_frag_queue(key, skb); 535 + skb = NULL; 542 536 543 537 /* if the key_add fails, we've raced with another 544 538 * SOM packet with the same src, dest and tag. There's 545 539 * no way to distinguish future packets, so all we 546 - * can do is drop; we'll free the skb on exit from 547 - * this function. 540 + * can do is drop. 548 541 */ 549 542 rc = mctp_key_add(key, msk); 550 - if (!rc) { 543 + if (!rc) 551 544 trace_mctp_key_acquire(key); 552 - skb = NULL; 553 - } 554 545 555 546 /* we don't need to release key->lock on exit, so 556 547 * clean up here and suppress the unlock via ··· 566 561 key = NULL; 567 562 } else { 568 563 rc = mctp_frag_queue(key, skb); 569 - if (!rc) 570 - skb = NULL; 564 + skb = NULL; 571 565 } 572 566 } 573 567 ··· 576 572 */ 577 573 578 574 /* we need to be continuing an existing reassembly... */ 579 - if (!key->reasm_head) 575 + if (!key->reasm_head) { 580 576 rc = -EINVAL; 581 - else 577 + } else { 582 578 rc = mctp_frag_queue(key, skb); 579 + skb = NULL; 580 + } 583 581 584 582 if (rc) 585 583 goto out_unlock; 586 - 587 - /* we've queued; the queue owns the skb now */ 588 - skb = NULL; 589 584 590 585 /* end of message? deliver to socket, and we're done with 591 586 * the reassembly/response key
-1
net/mptcp/protocol.c
··· 3554 3554 write_lock_bh(&sk->sk_callback_lock); 3555 3555 rcu_assign_pointer(sk->sk_wq, &parent->wq); 3556 3556 sk_set_socket(sk, parent); 3557 - WRITE_ONCE(sk->sk_uid, SOCK_INODE(parent)->i_uid); 3558 3557 write_unlock_bh(&sk->sk_callback_lock); 3559 3558 } 3560 3559
+2 -2
net/netfilter/nf_conntrack_helper.c
··· 368 368 (cur->tuple.src.l3num == NFPROTO_UNSPEC || 369 369 cur->tuple.src.l3num == me->tuple.src.l3num) && 370 370 cur->tuple.dst.protonum == me->tuple.dst.protonum) { 371 - ret = -EEXIST; 371 + ret = -EBUSY; 372 372 goto out; 373 373 } 374 374 } ··· 379 379 hlist_for_each_entry(cur, &nf_ct_helper_hash[h], hnode) { 380 380 if (nf_ct_tuple_src_mask_cmp(&cur->tuple, &me->tuple, 381 381 &mask)) { 382 - ret = -EEXIST; 382 + ret = -EBUSY; 383 383 goto out; 384 384 } 385 385 }
+31 -11
net/netfilter/nf_tables_api.c
··· 1959 1959 return -ENOSPC; 1960 1960 } 1961 1961 1962 + static bool hook_is_prefix(struct nft_hook *hook) 1963 + { 1964 + return strlen(hook->ifname) >= hook->ifnamelen; 1965 + } 1966 + 1967 + static int nft_nla_put_hook_dev(struct sk_buff *skb, struct nft_hook *hook) 1968 + { 1969 + int attr = hook_is_prefix(hook) ? NFTA_DEVICE_PREFIX : NFTA_DEVICE_NAME; 1970 + 1971 + return nla_put_string(skb, attr, hook->ifname); 1972 + } 1973 + 1962 1974 static int nft_dump_basechain_hook(struct sk_buff *skb, 1963 1975 const struct net *net, int family, 1964 1976 const struct nft_base_chain *basechain, ··· 2002 1990 if (!first) 2003 1991 first = hook; 2004 1992 2005 - if (nla_put(skb, NFTA_DEVICE_NAME, 2006 - hook->ifnamelen, hook->ifname)) 1993 + if (nft_nla_put_hook_dev(skb, hook)) 2007 1994 goto nla_put_failure; 2008 1995 n++; 2009 1996 } 2010 1997 nla_nest_end(skb, nest_devs); 2011 1998 2012 1999 if (n == 1 && 2013 - nla_put(skb, NFTA_HOOK_DEV, 2014 - first->ifnamelen, first->ifname)) 2000 + !hook_is_prefix(first) && 2001 + nla_put_string(skb, NFTA_HOOK_DEV, first->ifname)) 2015 2002 goto nla_put_failure; 2016 2003 } 2017 2004 nla_nest_end(skb, nest); ··· 2321 2310 } 2322 2311 2323 2312 static struct nft_hook *nft_netdev_hook_alloc(struct net *net, 2324 - const struct nlattr *attr) 2313 + const struct nlattr *attr, 2314 + bool prefix) 2325 2315 { 2326 2316 struct nf_hook_ops *ops; 2327 2317 struct net_device *dev; ··· 2339 2327 if (err < 0) 2340 2328 goto err_hook_free; 2341 2329 2342 - hook->ifnamelen = nla_len(attr); 2330 + /* include the terminating NUL-char when comparing non-prefixes */ 2331 + hook->ifnamelen = strlen(hook->ifname) + !prefix; 2343 2332 2344 2333 /* nf_tables_netdev_event() is called under rtnl_mutex, this is 2345 2334 * indirectly serializing all the other holders of the commit_mutex with ··· 2387 2374 struct nft_hook *hook, *next; 2388 2375 const struct nlattr *tmp; 2389 2376 int rem, n = 0, err; 2377 + bool prefix; 2390 2378 2391 2379 nla_for_each_nested(tmp, attr, rem) { 2392 - if (nla_type(tmp) != NFTA_DEVICE_NAME) { 2380 + switch (nla_type(tmp)) { 2381 + case NFTA_DEVICE_NAME: 2382 + prefix = false; 2383 + break; 2384 + case NFTA_DEVICE_PREFIX: 2385 + prefix = true; 2386 + break; 2387 + default: 2393 2388 err = -EINVAL; 2394 2389 goto err_hook; 2395 2390 } 2396 2391 2397 - hook = nft_netdev_hook_alloc(net, tmp); 2392 + hook = nft_netdev_hook_alloc(net, tmp, prefix); 2398 2393 if (IS_ERR(hook)) { 2399 2394 NL_SET_BAD_ATTR(extack, tmp); 2400 2395 err = PTR_ERR(hook); ··· 2448 2427 int err; 2449 2428 2450 2429 if (tb[NFTA_HOOK_DEV]) { 2451 - hook = nft_netdev_hook_alloc(net, tb[NFTA_HOOK_DEV]); 2430 + hook = nft_netdev_hook_alloc(net, tb[NFTA_HOOK_DEV], false); 2452 2431 if (IS_ERR(hook)) { 2453 2432 NL_SET_BAD_ATTR(extack, tb[NFTA_HOOK_DEV]); 2454 2433 return PTR_ERR(hook); ··· 9479 9458 9480 9459 list_for_each_entry_rcu(hook, hook_list, list, 9481 9460 lockdep_commit_lock_is_held(net)) { 9482 - if (nla_put(skb, NFTA_DEVICE_NAME, 9483 - hook->ifnamelen, hook->ifname)) 9461 + if (nft_nla_put_hook_dev(skb, hook)) 9484 9462 goto nla_put_failure; 9485 9463 } 9486 9464 nla_nest_end(skb, nest_devs);
+1 -1
net/netlink/diag.c
··· 168 168 NETLINK_CB(cb->skb).portid, 169 169 cb->nlh->nlmsg_seq, 170 170 NLM_F_MULTI, 171 - __sock_i_ino(sk)) < 0) { 171 + sock_i_ino(sk)) < 0) { 172 172 ret = 1; 173 173 break; 174 174 }
-2
net/smc/smc_clc.c
··· 426 426 { 427 427 struct smc_clc_msg_hdr *hdr = &dclc->hdr; 428 428 429 - if (hdr->typev1 != SMC_TYPE_R && hdr->typev1 != SMC_TYPE_D) 430 - return false; 431 429 if (hdr->version == SMC_V1) { 432 430 if (ntohs(hdr->length) != sizeof(struct smc_clc_msg_decline)) 433 431 return false;
+3
net/smc/smc_ib.c
··· 742 742 unsigned int i; 743 743 bool ret = false; 744 744 745 + if (!lnk->smcibdev->ibdev->dma_device) 746 + return ret; 747 + 745 748 /* for now there is just one DMA address */ 746 749 for_each_sg(buf_slot->sgt[lnk->link_idx].sgl, sg, 747 750 buf_slot->sgt[lnk->link_idx].nents, i) {
+2 -1
net/wireless/scan.c
··· 1916 1916 */ 1917 1917 1918 1918 f = rcu_access_pointer(new->pub.beacon_ies); 1919 - kfree_rcu((struct cfg80211_bss_ies *)f, rcu_head); 1919 + if (!new->pub.hidden_beacon_bss) 1920 + kfree_rcu((struct cfg80211_bss_ies *)f, rcu_head); 1920 1921 return false; 1921 1922 } 1922 1923
+4 -1
net/wireless/sme.c
··· 900 900 if (!wdev->u.client.ssid_len) { 901 901 rcu_read_lock(); 902 902 for_each_valid_link(cr, link) { 903 + u32 ssid_len; 904 + 903 905 ssid = ieee80211_bss_get_elem(cr->links[link].bss, 904 906 WLAN_EID_SSID); 905 907 906 908 if (!ssid || !ssid->datalen) 907 909 continue; 908 910 909 - memcpy(wdev->u.client.ssid, ssid->data, ssid->datalen); 911 + ssid_len = min(ssid->datalen, IEEE80211_MAX_SSID_LEN); 912 + memcpy(wdev->u.client.ssid, ssid->data, ssid_len); 910 913 wdev->u.client.ssid_len = ssid->datalen; 911 914 break; 912 915 }
+1 -1
tools/net/ynl/pyynl/ynl_gen_c.py
··· 830 830 'ynl_attr_for_each_nested(attr2, attr) {', 831 831 '\tif (ynl_attr_validate(yarg, attr2))', 832 832 '\t\treturn YNL_PARSE_CB_ERROR;', 833 - f'\t{var}->_count.{self.c_name}++;', 833 + f'\tn_{self.c_name}++;', 834 834 '}'] 835 835 return get_lines, None, local_vars 836 836
+2 -2
tools/testing/selftests/drivers/net/hw/csum.py
··· 17 17 ip_args = f"-{ipver} -S {cfg.remote_addr_v[ipver]} -D {cfg.addr_v[ipver]}" 18 18 19 19 rx_cmd = f"{cfg.bin_local} -i {cfg.ifname} -n 100 {ip_args} -r 1 -R {extra_args}" 20 - tx_cmd = f"{cfg.bin_remote} -i {cfg.ifname} -n 100 {ip_args} -r 1 -T {extra_args}" 20 + tx_cmd = f"{cfg.bin_remote} -i {cfg.remote_ifname} -n 100 {ip_args} -r 1 -T {extra_args}" 21 21 22 22 with bkg(rx_cmd, exit_wait=True): 23 23 wait_port_listen(34000, proto="udp") ··· 37 37 if extra_args != "-U -Z": 38 38 extra_args += " -r 1" 39 39 40 - rx_cmd = f"{cfg.bin_remote} -i {cfg.ifname} -L 1 -n 100 {ip_args} -R {extra_args}" 40 + rx_cmd = f"{cfg.bin_remote} -i {cfg.remote_ifname} -L 1 -n 100 {ip_args} -R {extra_args}" 41 41 tx_cmd = f"{cfg.bin_local} -i {cfg.ifname} -L 1 -n 100 {ip_args} -T {extra_args}" 42 42 43 43 with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
+1
tools/testing/selftests/net/Makefile
··· 99 99 TEST_GEN_PROGS += bind_timewait 100 100 TEST_PROGS += test_vxlan_mdb.sh 101 101 TEST_PROGS += test_bridge_neigh_suppress.sh 102 + TEST_PROGS += test_vxlan_nh.sh 102 103 TEST_PROGS += test_vxlan_nolocalbypass.sh 103 104 TEST_PROGS += test_bridge_backup_port.sh 104 105 TEST_PROGS += test_neigh.sh
+2 -2
tools/testing/selftests/net/bind_bhash.c
··· 75 75 int *array = (int *)arg; 76 76 77 77 for (i = 0; i < MAX_CONNECTIONS; i++) { 78 - sock_fd = bind_socket(SO_REUSEADDR | SO_REUSEPORT, setup_addr); 78 + sock_fd = bind_socket(SO_REUSEPORT, setup_addr); 79 79 if (sock_fd < 0) { 80 80 ret = sock_fd; 81 81 pthread_exit(&ret); ··· 103 103 104 104 setup_addr = use_v6 ? setup_addr_v6 : setup_addr_v4; 105 105 106 - listener_fd = bind_socket(SO_REUSEADDR | SO_REUSEPORT, setup_addr); 106 + listener_fd = bind_socket(SO_REUSEPORT, setup_addr); 107 107 if (listen(listener_fd, 100) < 0) { 108 108 perror("listen failed"); 109 109 return -1;
+1 -1
tools/testing/selftests/net/netfilter/conntrack_clash.sh
··· 99 99 local entries 100 100 local cre 101 101 102 - if ! ip netns exec "$ns" ./udpclash $daddr $dport;then 102 + if ! ip netns exec "$ns" timeout 30 ./udpclash $daddr $dport;then 103 103 echo "INFO: did not receive expected number of replies for $daddr:$dport" 104 104 ip netns exec "$ctns" conntrack -S 105 105 # don't fail: check if clash resolution triggered after all.
+3 -2
tools/testing/selftests/net/netfilter/conntrack_resize.sh
··· 187 187 [ -x udpclash ] || return 188 188 189 189 while [ $now -lt $end ]; do 190 - ip netns exec "$ns" ./udpclash 127.0.0.1 $((RANDOM%65536)) > /dev/null 2>&1 190 + ip netns exec "$ns" timeout 30 ./udpclash 127.0.0.1 $((RANDOM%65536)) > /dev/null 2>&1 191 191 192 192 now=$(date +%s) 193 193 done ··· 277 277 insert_flood() 278 278 { 279 279 local n="$1" 280 + local timeout="$2" 280 281 local r=0 281 282 282 283 r=$((RANDOM%$insert_count)) ··· 303 302 read tainted_then < /proc/sys/kernel/tainted 304 303 305 304 for n in "$nsclient1" "$nsclient2";do 306 - insert_flood "$n" & 305 + insert_flood "$n" "$timeout" & 307 306 done 308 307 309 308 # resize table constantly while flood/insert/dump/flushs
+76 -37
tools/testing/selftests/net/netfilter/nft_flowtable.sh
··· 20 20 SOCAT_TIMEOUT=60 21 21 22 22 nsin="" 23 + nsin_small="" 23 24 ns1out="" 24 25 ns2out="" 25 26 ··· 37 36 38 37 cleanup_all_ns 39 38 40 - rm -f "$nsin" "$ns1out" "$ns2out" 39 + rm -f "$nsin" "$nsin_small" "$ns1out" "$ns2out" 41 40 42 41 [ "$log_netns" -eq 0 ] && sysctl -q net.netfilter.nf_log_all_netns="$log_netns" 43 42 } ··· 73 72 rmtu=2000 74 73 75 74 filesize=$((2 * 1024 * 1024)) 75 + filesize_small=$((filesize / 16)) 76 76 77 77 usage(){ 78 78 echo "nft_flowtable.sh [OPTIONS]" ··· 91 89 o) omtu=$OPTARG;; 92 90 l) lmtu=$OPTARG;; 93 91 r) rmtu=$OPTARG;; 94 - s) filesize=$OPTARG;; 92 + s) 93 + filesize=$OPTARG 94 + filesize_small=$((OPTARG / 16)) 95 + ;; 95 96 *) usage;; 96 97 esac 97 98 done ··· 220 215 fi 221 216 222 217 nsin=$(mktemp) 218 + nsin_small=$(mktemp) 223 219 ns1out=$(mktemp) 224 220 ns2out=$(mktemp) 225 221 ··· 271 265 check_dscp() 272 266 { 273 267 local what=$1 268 + local pmtud="$2" 274 269 local ok=1 275 270 276 271 local counter ··· 284 277 local pc4z=${counter%*bytes*} 285 278 local pc4z=${pc4z#*packets} 286 279 280 + local failmsg="FAIL: pmtu $pmtu: $what counters do not match, expected" 281 + 287 282 case "$what" in 288 283 "dscp_none") 289 284 if [ "$pc4" -gt 0 ] || [ "$pc4z" -eq 0 ]; then 290 - echo "FAIL: dscp counters do not match, expected dscp3 == 0, dscp0 > 0, but got $pc4,$pc4z" 1>&2 285 + echo "$failmsg dscp3 == 0, dscp0 > 0, but got $pc4,$pc4z" 1>&2 291 286 ret=1 292 287 ok=0 293 288 fi 294 289 ;; 295 290 "dscp_fwd") 296 291 if [ "$pc4" -eq 0 ] || [ "$pc4z" -eq 0 ]; then 297 - echo "FAIL: dscp counters do not match, expected dscp3 and dscp0 > 0 but got $pc4,$pc4z" 1>&2 292 + echo "$failmsg dscp3 and dscp0 > 0 but got $pc4,$pc4z" 1>&2 298 293 ret=1 299 294 ok=0 300 295 fi 301 296 ;; 302 297 "dscp_ingress") 303 298 if [ "$pc4" -eq 0 ] || [ "$pc4z" -gt 0 ]; then 304 - echo "FAIL: dscp counters do not match, expected dscp3 > 0, dscp0 == 0 but got $pc4,$pc4z" 1>&2 299 + echo "$failmsg dscp3 > 0, dscp0 == 0 but got $pc4,$pc4z" 1>&2 305 300 ret=1 306 301 ok=0 307 302 fi 308 303 ;; 309 304 "dscp_egress") 310 305 if [ "$pc4" -eq 0 ] || [ "$pc4z" -gt 0 ]; then 311 - echo "FAIL: dscp counters do not match, expected dscp3 > 0, dscp0 == 0 but got $pc4,$pc4z" 1>&2 306 + echo "$failmsg dscp3 > 0, dscp0 == 0 but got $pc4,$pc4z" 1>&2 312 307 ret=1 313 308 ok=0 314 309 fi 315 310 ;; 316 311 *) 317 - echo "FAIL: Unknown DSCP check" 1>&2 312 + echo "$failmsg: Unknown DSCP check" 1>&2 318 313 ret=1 319 314 ok=0 320 315 esac ··· 328 319 329 320 check_transfer() 330 321 { 331 - in=$1 332 - out=$2 333 - what=$3 322 + local in=$1 323 + local out=$2 324 + local what=$3 334 325 335 326 if ! cmp "$in" "$out" > /dev/null 2>&1; then 336 327 echo "FAIL: file mismatch for $what" 1>&2 ··· 351 342 { 352 343 local nsa=$1 353 344 local nsb=$2 354 - local dstip=$3 355 - local dstport=$4 345 + local pmtu=$3 346 + local dstip=$4 347 + local dstport=$5 356 348 local lret=0 349 + local socatc 350 + local socatl 351 + local infile="$nsin" 357 352 358 - timeout "$SOCAT_TIMEOUT" ip netns exec "$nsb" socat -4 TCP-LISTEN:12345,reuseaddr STDIO < "$nsin" > "$ns2out" & 353 + if [ $pmtu -eq 0 ]; then 354 + infile="$nsin_small" 355 + fi 356 + 357 + timeout "$SOCAT_TIMEOUT" ip netns exec "$nsb" socat -4 TCP-LISTEN:12345,reuseaddr STDIO < "$infile" > "$ns2out" & 359 358 lpid=$! 360 359 361 360 busywait 1000 listener_ready 362 361 363 - timeout "$SOCAT_TIMEOUT" ip netns exec "$nsa" socat -4 TCP:"$dstip":"$dstport" STDIO < "$nsin" > "$ns1out" 362 + timeout "$SOCAT_TIMEOUT" ip netns exec "$nsa" socat -4 TCP:"$dstip":"$dstport" STDIO < "$infile" > "$ns1out" 363 + socatc=$? 364 364 365 365 wait $lpid 366 + socatl=$? 366 367 367 - if ! check_transfer "$nsin" "$ns2out" "ns1 -> ns2"; then 368 + if [ $socatl -ne 0 ] || [ $socatc -ne 0 ];then 369 + rc=1 370 + fi 371 + 372 + if ! check_transfer "$infile" "$ns2out" "ns1 -> ns2"; then 368 373 lret=1 369 374 ret=1 370 375 fi 371 376 372 - if ! check_transfer "$nsin" "$ns1out" "ns1 <- ns2"; then 377 + if ! check_transfer "$infile" "$ns1out" "ns1 <- ns2"; then 373 378 lret=1 374 379 ret=1 375 380 fi ··· 393 370 394 371 test_tcp_forwarding() 395 372 { 396 - test_tcp_forwarding_ip "$1" "$2" 10.0.2.99 12345 373 + local pmtu="$3" 374 + 375 + test_tcp_forwarding_ip "$1" "$2" "$pmtu" 10.0.2.99 12345 397 376 398 377 return $? 399 378 } 400 379 401 380 test_tcp_forwarding_set_dscp() 402 381 { 403 - check_dscp "dscp_none" 382 + local pmtu="$3" 404 383 405 384 ip netns exec "$nsr1" nft -f - <<EOF 406 385 table netdev dscpmangle { ··· 413 388 } 414 389 EOF 415 390 if [ $? -eq 0 ]; then 416 - test_tcp_forwarding_ip "$1" "$2" 10.0.2.99 12345 417 - check_dscp "dscp_ingress" 391 + test_tcp_forwarding_ip "$1" "$2" "$3" 10.0.2.99 12345 392 + check_dscp "dscp_ingress" "$pmtu" 418 393 419 394 ip netns exec "$nsr1" nft delete table netdev dscpmangle 420 395 else ··· 430 405 } 431 406 EOF 432 407 if [ $? -eq 0 ]; then 433 - test_tcp_forwarding_ip "$1" "$2" 10.0.2.99 12345 434 - check_dscp "dscp_egress" 408 + test_tcp_forwarding_ip "$1" "$2" "$pmtu" 10.0.2.99 12345 409 + check_dscp "dscp_egress" "$pmtu" 435 410 436 - ip netns exec "$nsr1" nft flush table netdev dscpmangle 411 + ip netns exec "$nsr1" nft delete table netdev dscpmangle 437 412 else 438 413 echo "SKIP: Could not load netdev:egress for veth1" 439 414 fi ··· 441 416 # partial. If flowtable really works, then both dscp-is-0 and dscp-is-cs3 442 417 # counters should have seen packets (before and after ft offload kicks in). 443 418 ip netns exec "$nsr1" nft -a insert rule inet filter forward ip dscp set cs3 444 - test_tcp_forwarding_ip "$1" "$2" 10.0.2.99 12345 445 - check_dscp "dscp_fwd" 419 + test_tcp_forwarding_ip "$1" "$2" "$pmtu" 10.0.2.99 12345 420 + check_dscp "dscp_fwd" "$pmtu" 446 421 } 447 422 448 423 test_tcp_forwarding_nat() 449 424 { 425 + local nsa="$1" 426 + local nsb="$2" 427 + local pmtu="$3" 428 + local what="$4" 450 429 local lret 451 - local pmtu 452 430 453 - test_tcp_forwarding_ip "$1" "$2" 10.0.2.99 12345 431 + [ "$pmtu" -eq 0 ] && what="$what (pmtu disabled)" 432 + 433 + test_tcp_forwarding_ip "$nsa" "$nsb" "$pmtu" 10.0.2.99 12345 454 434 lret=$? 455 - 456 - pmtu=$3 457 - what=$4 458 435 459 436 if [ "$lret" -eq 0 ] ; then 460 437 if [ "$pmtu" -eq 1 ] ;then 461 - check_counters "flow offload for ns1/ns2 with masquerade and pmtu discovery $what" 438 + check_counters "flow offload for ns1/ns2 with masquerade $what" 462 439 else 463 440 echo "PASS: flow offload for ns1/ns2 with masquerade $what" 464 441 fi 465 442 466 - test_tcp_forwarding_ip "$1" "$2" 10.6.6.6 1666 443 + test_tcp_forwarding_ip "$1" "$2" "$pmtu" 10.6.6.6 1666 467 444 lret=$? 468 445 if [ "$pmtu" -eq 1 ] ;then 469 - check_counters "flow offload for ns1/ns2 with dnat and pmtu discovery $what" 446 + check_counters "flow offload for ns1/ns2 with dnat $what" 470 447 elif [ "$lret" -eq 0 ] ; then 471 448 echo "PASS: flow offload for ns1/ns2 with dnat $what" 472 449 fi 450 + else 451 + echo "FAIL: flow offload for ns1/ns2 with dnat $what" 473 452 fi 474 453 475 454 return $lret 476 455 } 477 456 478 457 make_file "$nsin" "$filesize" 458 + make_file "$nsin_small" "$filesize_small" 479 459 480 460 # First test: 481 461 # No PMTU discovery, nsr1 is expected to fragment packets from ns1 to ns2 as needed. 482 462 # Due to MTU mismatch in both directions, all packets (except small packets like pure 483 463 # acks) have to be handled by normal forwarding path. Therefore, packet counters 484 464 # are not checked. 485 - if test_tcp_forwarding "$ns1" "$ns2"; then 465 + if test_tcp_forwarding "$ns1" "$ns2" 0; then 486 466 echo "PASS: flow offloaded for ns1/ns2" 487 467 else 488 468 echo "FAIL: flow offload for ns1/ns2:" 1>&2 ··· 519 489 } 520 490 EOF 521 491 492 + check_dscp "dscp_none" "0" 522 493 if ! test_tcp_forwarding_set_dscp "$ns1" "$ns2" 0 ""; then 523 - echo "FAIL: flow offload for ns1/ns2 with dscp update" 1>&2 494 + echo "FAIL: flow offload for ns1/ns2 with dscp update and no pmtu discovery" 1>&2 524 495 exit 0 525 496 fi 526 497 ··· 543 512 # are lower than file size and packets were forwarded via flowtable layer. 544 513 # For earlier tests (large mtus), packets cannot be handled via flowtable 545 514 # (except pure acks and other small packets). 515 + ip netns exec "$nsr1" nft reset counters table inet filter >/dev/null 516 + ip netns exec "$ns2" nft reset counters table inet filter >/dev/null 517 + 518 + if ! test_tcp_forwarding_set_dscp "$ns1" "$ns2" 1 ""; then 519 + echo "FAIL: flow offload for ns1/ns2 with dscp update and pmtu discovery" 1>&2 520 + exit 0 521 + fi 522 + 546 523 ip netns exec "$nsr1" nft reset counters table inet filter >/dev/null 547 524 548 525 if ! test_tcp_forwarding_nat "$ns1" "$ns2" 1 ""; then ··· 683 644 ip -net "$ns2" route add default via 10.0.2.1 684 645 ip -net "$ns2" route add default via dead:2::1 685 646 686 - if test_tcp_forwarding "$ns1" "$ns2"; then 647 + if test_tcp_forwarding "$ns1" "$ns2" 1; then 687 648 check_counters "ipsec tunnel mode for ns1/ns2" 688 649 else 689 650 echo "FAIL: ipsec tunnel mode for ns1/ns2" ··· 707 668 fi 708 669 709 670 echo "re-run with random mtus and file size: -o $o -l $l -r $r -s $filesize" 710 - $0 -o "$o" -l "$l" -r "$r" -s "$filesize" 671 + $0 -o "$o" -l "$l" -r "$r" -s "$filesize" || ret=1 711 672 fi 712 673 713 674 exit $ret
+1 -1
tools/testing/selftests/net/netfilter/udpclash.c
··· 29 29 int sockfd; 30 30 }; 31 31 32 - static int wait = 1; 32 + static volatile int wait = 1; 33 33 34 34 static void *thread_main(void *varg) 35 35 {
+223
tools/testing/selftests/net/test_vxlan_nh.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + source lib.sh 5 + TESTS=" 6 + basic_tx_ipv4 7 + basic_tx_ipv6 8 + learning 9 + proxy_ipv4 10 + proxy_ipv6 11 + " 12 + VERBOSE=0 13 + 14 + ################################################################################ 15 + # Utilities 16 + 17 + run_cmd() 18 + { 19 + local cmd="$1" 20 + local out 21 + local stderr="2>/dev/null" 22 + 23 + if [ "$VERBOSE" = "1" ]; then 24 + echo "COMMAND: $cmd" 25 + stderr= 26 + fi 27 + 28 + out=$(eval "$cmd" "$stderr") 29 + rc=$? 30 + if [ "$VERBOSE" -eq 1 ] && [ -n "$out" ]; then 31 + echo " $out" 32 + fi 33 + 34 + return $rc 35 + } 36 + 37 + ################################################################################ 38 + # Cleanup 39 + 40 + exit_cleanup_all() 41 + { 42 + cleanup_all_ns 43 + exit "${EXIT_STATUS}" 44 + } 45 + 46 + ################################################################################ 47 + # Tests 48 + 49 + nh_stats_get() 50 + { 51 + ip -n "$ns1" -s -j nexthop show id 10 | jq ".[][\"group_stats\"][][\"packets\"]" 52 + } 53 + 54 + tc_stats_get() 55 + { 56 + tc_rule_handle_stats_get "dev dummy1 egress" 101 ".packets" "-n $ns1" 57 + } 58 + 59 + basic_tx_common() 60 + { 61 + local af_str=$1; shift 62 + local proto=$1; shift 63 + local local_addr=$1; shift 64 + local plen=$1; shift 65 + local remote_addr=$1; shift 66 + 67 + RET=0 68 + 69 + # Test basic Tx functionality. Check that stats are incremented on 70 + # both the FDB nexthop group and the egress device. 71 + 72 + run_cmd "ip -n $ns1 link add name dummy1 up type dummy" 73 + run_cmd "ip -n $ns1 route add $remote_addr/$plen dev dummy1" 74 + run_cmd "tc -n $ns1 qdisc add dev dummy1 clsact" 75 + run_cmd "tc -n $ns1 filter add dev dummy1 egress proto $proto pref 1 handle 101 flower ip_proto udp dst_ip $remote_addr dst_port 4789 action pass" 76 + 77 + run_cmd "ip -n $ns1 address add $local_addr/$plen dev lo" 78 + 79 + run_cmd "ip -n $ns1 nexthop add id 1 via $remote_addr fdb" 80 + run_cmd "ip -n $ns1 nexthop add id 10 group 1 fdb" 81 + 82 + run_cmd "ip -n $ns1 link add name vx0 up type vxlan id 10010 local $local_addr dstport 4789" 83 + run_cmd "bridge -n $ns1 fdb add 00:11:22:33:44:55 dev vx0 self static nhid 10" 84 + 85 + run_cmd "ip netns exec $ns1 mausezahn vx0 -a own -b 00:11:22:33:44:55 -c 1 -q" 86 + 87 + busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== 1" nh_stats_get > /dev/null 88 + check_err $? "FDB nexthop group stats did not increase" 89 + 90 + busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== 1" tc_stats_get > /dev/null 91 + check_err $? "tc filter stats did not increase" 92 + 93 + log_test "VXLAN FDB nexthop: $af_str basic Tx" 94 + } 95 + 96 + basic_tx_ipv4() 97 + { 98 + basic_tx_common "IPv4" ipv4 192.0.2.1 32 192.0.2.2 99 + } 100 + 101 + basic_tx_ipv6() 102 + { 103 + basic_tx_common "IPv6" ipv6 2001:db8:1::1 128 2001:db8:1::2 104 + } 105 + 106 + learning() 107 + { 108 + RET=0 109 + 110 + # When learning is enabled on the VXLAN device, an incoming packet 111 + # might try to refresh an FDB entry that points to an FDB nexthop group 112 + # instead of an ordinary remote destination. Check that the kernel does 113 + # not crash in this situation. 114 + 115 + run_cmd "ip -n $ns1 address add 192.0.2.1/32 dev lo" 116 + run_cmd "ip -n $ns1 address add 192.0.2.2/32 dev lo" 117 + 118 + run_cmd "ip -n $ns1 nexthop add id 1 via 192.0.2.3 fdb" 119 + run_cmd "ip -n $ns1 nexthop add id 10 group 1 fdb" 120 + 121 + run_cmd "ip -n $ns1 link add name vx0 up type vxlan id 10010 local 192.0.2.1 dstport 12345 localbypass" 122 + run_cmd "ip -n $ns1 link add name vx1 up type vxlan id 10020 local 192.0.2.2 dstport 54321 learning" 123 + 124 + run_cmd "bridge -n $ns1 fdb add 00:11:22:33:44:55 dev vx0 self static dst 192.0.2.2 port 54321 vni 10020" 125 + run_cmd "bridge -n $ns1 fdb add 00:aa:bb:cc:dd:ee dev vx1 self static nhid 10" 126 + 127 + run_cmd "ip netns exec $ns1 mausezahn vx0 -a 00:aa:bb:cc:dd:ee -b 00:11:22:33:44:55 -c 1 -q" 128 + 129 + log_test "VXLAN FDB nexthop: learning" 130 + } 131 + 132 + proxy_common() 133 + { 134 + local af_str=$1; shift 135 + local local_addr=$1; shift 136 + local plen=$1; shift 137 + local remote_addr=$1; shift 138 + local neigh_addr=$1; shift 139 + local ping_cmd=$1; shift 140 + 141 + RET=0 142 + 143 + # When the "proxy" option is enabled on the VXLAN device, the device 144 + # will suppress ARP requests and IPv6 Neighbor Solicitation messages if 145 + # it is able to reply on behalf of the remote host. That is, if a 146 + # matching and valid neighbor entry is configured on the VXLAN device 147 + # whose MAC address is not behind the "any" remote (0.0.0.0 / ::). The 148 + # FDB entry for the neighbor's MAC address might point to an FDB 149 + # nexthop group instead of an ordinary remote destination. Check that 150 + # the kernel does not crash in this situation. 151 + 152 + run_cmd "ip -n $ns1 address add $local_addr/$plen dev lo" 153 + 154 + run_cmd "ip -n $ns1 nexthop add id 1 via $remote_addr fdb" 155 + run_cmd "ip -n $ns1 nexthop add id 10 group 1 fdb" 156 + 157 + run_cmd "ip -n $ns1 link add name vx0 up type vxlan id 10010 local $local_addr dstport 4789 proxy" 158 + 159 + run_cmd "ip -n $ns1 neigh add $neigh_addr lladdr 00:11:22:33:44:55 nud perm dev vx0" 160 + 161 + run_cmd "bridge -n $ns1 fdb add 00:11:22:33:44:55 dev vx0 self static nhid 10" 162 + 163 + run_cmd "ip netns exec $ns1 $ping_cmd" 164 + 165 + log_test "VXLAN FDB nexthop: $af_str proxy" 166 + } 167 + 168 + proxy_ipv4() 169 + { 170 + proxy_common "IPv4" 192.0.2.1 32 192.0.2.2 192.0.2.3 \ 171 + "arping -b -c 1 -s 192.0.2.1 -I vx0 192.0.2.3" 172 + } 173 + 174 + proxy_ipv6() 175 + { 176 + proxy_common "IPv6" 2001:db8:1::1 128 2001:db8:1::2 2001:db8:1::3 \ 177 + "ndisc6 -r 1 -s 2001:db8:1::1 -w 1 2001:db8:1::3 vx0" 178 + } 179 + 180 + ################################################################################ 181 + # Usage 182 + 183 + usage() 184 + { 185 + cat <<EOF 186 + usage: ${0##*/} OPTS 187 + 188 + -t <test> Test(s) to run (default: all) 189 + (options: $TESTS) 190 + -p Pause on fail 191 + -v Verbose mode (show commands and output) 192 + EOF 193 + } 194 + 195 + ################################################################################ 196 + # Main 197 + 198 + while getopts ":t:pvh" opt; do 199 + case $opt in 200 + t) TESTS=$OPTARG;; 201 + p) PAUSE_ON_FAIL=yes;; 202 + v) VERBOSE=$((VERBOSE + 1));; 203 + h) usage; exit 0;; 204 + *) usage; exit 1;; 205 + esac 206 + done 207 + 208 + require_command mausezahn 209 + require_command arping 210 + require_command ndisc6 211 + require_command jq 212 + 213 + if ! ip nexthop help 2>&1 | grep -q "stats"; then 214 + echo "SKIP: iproute2 ip too old, missing nexthop stats support" 215 + exit "$ksft_skip" 216 + fi 217 + 218 + trap exit_cleanup_all EXIT 219 + 220 + for t in $TESTS 221 + do 222 + setup_ns ns1; $t; cleanup_all_ns; 223 + done