https://source.android.com/docs/security/bulletin/2024-02-01 * tag 'ASB-2024-02-05_4.19-stable' of https://android.googlesource.com/kernel/common: Reapply "perf: Fix perf_event_validate_size()" UPSTREAM: usb: raw-gadget: properly handle interrupted requests UPSTREAM: mm/cma: use nth_page() in place of direct struct page manipulation UPSTREAM: wireguard: allowedips: expand maximum node depth UPSTREAM: coresight: tmc: Explicit type conversions to prevent integer overflow UPSTREAM: wireguard: netlink: send staged packets when setting initial private key UPSTREAM: wireguard: queueing: use saner cpu selection wrapping UPSTREAM: kheaders: Use array declaration instead of char UPSTREAM: arm64: efi: Make efi_rt_lock a raw_spinlock UPSTREAM: sched/psi: Fix use-after-free in ep_remove_wait_queue() UPSTREAM: usb: musb: mediatek: don't unregister something that wasn't registered UPSTREAM: xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr() UPSTREAM: xfrm: compat: change expression for switch in xfrm_xlate64 UPSTREAM: perf/core: Call LSM hook after copying perf_event_attr Linux 4.19.306 crypto: scompress - initialize per-CPU variables on each CPU Revert "NFSD: Fix possible sleep during nfsd4_release_lockowner()" i2c: s3c24xx: fix transferring more than one message in polling mode i2c: s3c24xx: fix read transfers in polling mode kdb: Fix a potential buffer overflow in kdb_local() kdb: Censor attempts to set PROMPT without ENABLE_MEM_READ ipvs: avoid stat macros calls from preemptible context net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe net: ravb: Fix dma_addr_t truncation in error case net: qualcomm: rmnet: fix global oob in rmnet_policy serial: imx: Correct clock error message in function probe() apparmor: avoid crash when parsed profile name is empty perf genelf: Set ELF program header addresses properly acpi: property: Let args be NULL in __acpi_node_get_property_reference MIPS: Alchemy: Fix an out-of-bound access in db1550_dev_setup() MIPS: Alchemy: Fix an out-of-bound access in db1200_dev_setup() HID: wacom: Correct behavior when processing some confidence == false touches wifi: mwifiex: configure BSSID consistently when starting AP wifi: rtlwifi: Convert LNKCTL change to PCIe cap RMW accessors wifi: rtlwifi: Remove bogus and dangerous ASPM disable/enable code fbdev: flush deferred work in fb_deferred_io_fsync() ALSA: oxygen: Fix right channel of capture volume mixer usb: mon: Fix atomicity violation in mon_bin_vma_fault usb: typec: class: fix typec_altmode_put_partner to put plugs Revert "usb: typec: class: fix typec_altmode_put_partner to put plugs" usb: chipidea: wait controller resume finished for wakeup irq Revert "usb: dwc3: don't reset device side if dwc3 was configured as host-only" Revert "usb: dwc3: Soft reset phy on probe for host" usb: dwc: ep0: Update request status in dwc3_ep0_stall_restart usb: phy: mxs: remove CONFIG_USB_OTG condition for mxs_phy_is_otg_host() tick-sched: Fix idle and iowait sleeptime accounting vs CPU hotplug binder: fix unused alloc->free_async_space binder: fix race between mmput() and do_exit() xen-netback: don't produce zero-size SKB frags Revert "ASoC: atmel: Remove system clock tree configuration for at91sam9g20ek" Input: atkbd - use ab83 as id when skipping the getid command binder: fix async space check for 0-sized buffers of: unittest: Fix of_count_phandle_with_args() expected value message of: Fix double free in of_parse_phandle_with_args_map mmc: sdhci_omap: Fix TI SoC dependencies watchdog: bcm2835_wdt: Fix WDIOC_SETTIMEOUT handling watchdog/hpwdt: Only claim UNKNOWN NMI if from iLO watchdog: set cdev owner before adding gpu/drm/radeon: fix two memleaks in radeon_vm_init drivers/amd/pm: fix a use-after-free in kv_parse_power_table drm/amd/pm: fix a double-free in si_dpm_init drm/amdgpu/debugfs: fix error code when smc register accessors are NULL media: dvbdev: drop refcount on error path in dvb_device_open() media: cx231xx: fix a memleak in cx231xx_init_isoc drm/radeon/trinity_dpm: fix a memleak in trinity_parse_power_table drm/radeon/dpm: fix a memleak in sumo_parse_power_table drm/radeon: check the alloc_workqueue return value in radeon_crtc_init() drm/drv: propagate errors from drm_modeset_register_all() drm/msm/mdp4: flush vblank event on disable ASoC: cs35l34: Fix GPIO name and drop legacy include ASoC: cs35l33: Fix GPIO name and drop legacy include drm/radeon: check return value of radeon_ring_lock() drm/radeon/r100: Fix integer overflow issues in r100_cs_track_check() drm/radeon/r600_cs: Fix possible int overflows in r600_cs_check_reg() f2fs: fix to avoid dirent corruption drm/bridge: Fix typo in post_disable() description media: pvrusb2: fix use after free on context disconnection RDMA/usnic: Silence uninitialized symbol smatch warnings ip6_tunnel: fix NEXTHDR_FRAGMENT handling in ip6_tnl_parse_tlv_enc_lim() Bluetooth: btmtkuart: fix recv_buf() return value Bluetooth: Fix bogus check for re-auth no supported with non-ssp wifi: rtlwifi: rtl8192se: using calculate_bit_shift() wifi: rtlwifi: rtl8192ee: using calculate_bit_shift() wifi: rtlwifi: rtl8192de: using calculate_bit_shift() rtlwifi: rtl8192de: make arrays static const, makes object smaller wifi: rtlwifi: rtl8192ce: using calculate_bit_shift() wifi: rtlwifi: rtl8192cu: using calculate_bit_shift() wifi: rtlwifi: rtl8192c: using calculate_bit_shift() wifi: rtlwifi: rtl8188ee: phy: using calculate_bit_shift() wifi: rtlwifi: add calculate_bit_shift() dma-mapping: clear dev->dma_mem to NULL after freeing it scsi: hisi_sas: Replace with standard error code return value wifi: rtlwifi: rtl8821ae: phy: fix an undefined bitwise shift behavior rtlwifi: Use ffs in <foo>_phy_calculate_bit_shift firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create() net/ncsi: Fix netlink major/minor version numbers ncsi: internal.h: Fix a spello ARM: dts: qcom: apq8064: correct XOADC register address wifi: libertas: stop selecting wext bpf, lpm: Fix check prefixlen before walking trie NFSv4.1/pnfs: Ensure we handle the error NFS4ERR_RETURNCONFLICT blocklayoutdriver: Fix reference leak of pnfs_device_node crypto: scomp - fix req->dst buffer overflow crypto: scompress - Use per-CPU struct instead multiple variables crypto: scompress - return proper error code for allocation failure crypto: sahara - do not resize req->src when doing hash operations crypto: sahara - fix processing hash requests with req->nbytes < sg->length crypto: sahara - improve error handling in sahara_sha_process() crypto: sahara - fix wait_for_completion_timeout() error handling crypto: sahara - fix ahash reqsize crypto: virtio - Wait for tasklet to complete on device remove pstore: ram_core: fix possible overflow in persistent_ram_init_ecc() crypto: sahara - fix error handling in sahara_hw_descriptor_create() crypto: sahara - fix processing requests with cryptlen < sg->length crypto: sahara - fix ahash selftest failure crypto: sahara - remove FLAGS_NEW_KEY logic crypto: af_alg - Disallow multiple in-flight AIO requests crypto: ccp - fix memleak in ccp_init_dm_workarea crypto: virtio - Handle dataq logic with tasklet selinux: Fix error priority for bind with AF_UNSPEC on PF_INET6 socket mtd: Fix gluebi NULL pointer dereference caused by ftl notifier calipso: fix memory leak in netlbl_calipso_add_pass() netlabel: remove unused parameter in netlbl_netlink_auditinfo() net: netlabel: Fix kerneldoc warnings ACPI: LPIT: Avoid u32 multiplication overflow ACPI: video: check for error while searching for backlight device parent mtd: rawnand: Increment IFC_TIMEOUT_MSECS for nand controller response powerpc/imc-pmu: Add a null pointer check in update_events_in_group() powerpc/powernv: Add a null pointer check in opal_event_init() selftests/powerpc: Fix error handling in FPU/VMX preemption tests powerpc/pseries/memhp: Fix access beyond end of drmem array powerpc/pseries/memhotplug: Quieten some DLPAR operations powerpc/44x: select I2C for CURRITUCK powerpc: remove redundant 'default n' from Kconfig-s powerpc: add crtsavres.o to always-y instead of extra-y EDAC/thunderx: Fix possible out-of-bounds string access x86/lib: Fix overflow when counting digits coresight: etm4x: Fix width of CCITMIN field uio: Fix use-after-free in uio_open binder: fix comment on binder_alloc_new_buf() return value binder: use EPOLLERR from eventpoll.h drm/crtc: fix uninitialized variable use ARM: sun9i: smp: fix return code check of of_property_match_string Input: xpad - add Razer Wolverine V2 support ARC: fix spare error s390/scm: fix virtual vs physical address confusion Input: i8042 - add nomux quirk for Acer P459-G2-M Input: atkbd - skip ATKBD_CMD_GETID in translated mode reset: hisilicon: hi6220: fix Wvoid-pointer-to-enum-cast warning ring-buffer: Do not record in NMI if the arch does not support cmpxchg in NMI tracing: Add size check when printing trace_marker output tracing: Have large events show up as '[LINE TOO BIG]' instead of nothing drm/crtc: Fix uninit-value bug in drm_mode_setcrtc jbd2: correct the printing of write_flags in jbd2_write_superblock() clk: rockchip: rk3128: Fix HCLK_OTG gate register drm/exynos: fix a potential error pointer dereference ASoC: da7219: Support low DC impedance headset net/tg3: fix race condition in tg3_reset_task() ASoC: rt5650: add mutex to avoid the jack detection failure ASoC: cs43130: Fix incorrect frame delay configuration ASoC: cs43130: Fix the position of const qualifier ASoC: Intel: Skylake: mem leak in skl register function f2fs: explicitly null-terminate the xattr list UPSTREAM: wifi: cfg80211: fix buffer overflow in elem comparison UPSTREAM: gcov: clang: fix the buffer overflow issue BACKPORT: selinux: enable use of both GFP_KERNEL and GFP_ATOMIC in convert_context() UPSTREAM: wifi: cfg80211: avoid nontransmitted BSS list corruption UPSTREAM: wifi: cfg80211: fix BSS refcounting bugs UPSTREAM: wifi: cfg80211: ensure length byte is present before access UPSTREAM: wifi: cfg80211: fix u8 overflow in cfg80211_update_notlisted_nontrans() UPSTREAM: wireguard: netlink: avoid variable-sized memcpy on sockaddr UPSTREAM: wireguard: ratelimiter: disable timings test by default UPSTREAM: crypto: lib - remove unneeded selection of XOR_BLOCKS UPSTREAM: wireguard: allowedips: don't corrupt stack when detecting overflow UPSTREAM: wireguard: ratelimiter: use hrtimer in selftest UPSTREAM: crypto: arm64/poly1305 - fix a read out-of-bound UPSTREAM: wifi: mac80211_hwsim: set virtio device ready in probe() UPSTREAM: crypto: memneq - move into lib/ UPSTREAM: dma-buf: fix use of DMA_BUF_SET_NAME_{A,B} in userspace BACKPORT: usb: typec: mux: Check dev_set_name() return value UPSTREAM: wireguard: device: check for metadata_dst with skb_valid_dst() UPSTREAM: sched/fair: Fix cfs_rq_clock_pelt() for throttled cfs_rq UPSTREAM: cfg80211: hold bss_lock while updating nontrans_list UPSTREAM: wireguard: socket: ignore v6 endpoints when ipv6 is disabled UPSTREAM: wireguard: socket: free skb in send6 when ipv6 is disabled UPSTREAM: wireguard: queueing: use CFI-safe ptr_ring cleanup function UPSTREAM: mm: don't try to NUMA-migrate COW pages that have other uses UPSTREAM: copy_process(): Move fd_install() out of sighand->siglock critical section UPSTREAM: usb: raw-gadget: fix handling of dual-direction-capable endpoints UPSTREAM: psi: Fix "no previous prototype" warnings when CONFIG_CGROUPS=n UPSTREAM: sched/uclamp: Fix rq->uclamp_max not set on first enqueue UPSTREAM: wireguard: selftests: increase default dmesg log size UPSTREAM: wireguard: allowedips: add missing __rcu annotation to satisfy sparse UPSTREAM: sched/uclamp: Fix uclamp_tg_restrict() UPSTREAM: coresight: etm4x: Fix etm4_count race by moving cpuhp callbacks to init UPSTREAM: sched/uclamp: Fix a deadlock when enabling uclamp static key UPSTREAM: mac80211_hwsim: use GFP_ATOMIC under spin lock UPSTREAM: usercopy: Avoid soft lockups in test_check_nonzero_user() UPSTREAM: lib: test_user_copy: style cleanup UPSTREAM: fork: return proper negative error code Revert "ipv6: make ip6_rt_gc_expire an atomic_t" Revert "ipv6: remove max_size check inline with ipv4" Linux 4.19.305 ipv6: remove max_size check inline with ipv4 ipv6: make ip6_rt_gc_expire an atomic_t net/dst: use a smaller percpu_counter batch for dst entries accounting net: add a route cache full diagnostic message PCI: Disable ATS for specific Intel IPU E2000 devices PCI: Extract ATS disabling to a helper function netfilter: nf_tables: Reject tables of unsupported family fuse: nlookup missing decrement in fuse_direntplus_link mmc: core: Cancel delayed work before releasing host mmc: rpmb: fixes pause retune on all RPMB partitions. mm: fix unmap_mapping_range high bits shift bug firewire: ohci: suppress unexpected system reboot in AMD Ryzen machines and ASM108x/VT630x PCIe cards mm/memory-failure: check the mapcount of the precise page bnxt_en: Remove mis-applied code from bnxt_cfg_ntp_filters() asix: Add check for usbnet_get_endpoints net/qla3xxx: fix potential memleak in ql_alloc_buffer_queues net/qla3xxx: switch from 'pci_' to 'dma_' API i40e: Restore VF MSI-X state during PCI reset i40e: fix use-after-free in i40e_aqc_add_filters() net: Save and restore msg_namelen in sock_sendmsg net: bcmgenet: Fix FCS generation for fragmented skbuffs ARM: sun9i: smp: Fix array-index-out-of-bounds read in sunxi_mc_smp_init net: sched: em_text: fix possible memory leak in em_text_destroy() i40e: Fix filter input checks to prevent config with invalid values nfc: llcp_core: Hold a ref to llcp_local->dev when holding a ref to llcp_local UPSTREAM: fsverity: skip PKCS#7 parser when keyring is empty Conflicts: drivers/hwtracing/coresight/coresight-etm4x.c drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c include/linux/psi.h mm/memory-failure.c net/wireless/scan.c Change-Id: I49b769cb8387e5d5f28730d13cbdf4ffd335dc70
782 lines
18 KiB
C
782 lines
18 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
|
|
*
|
|
* RMNET configuration engine
|
|
*
|
|
*/
|
|
|
|
#include <net/sock.h>
|
|
#include <linux/module.h>
|
|
#include <linux/netlink.h>
|
|
#include <linux/netdevice.h>
|
|
#include "rmnet_config.h"
|
|
#include "rmnet_handlers.h"
|
|
#include "rmnet_vnd.h"
|
|
#include "rmnet_private.h"
|
|
#include "rmnet_map.h"
|
|
#include "rmnet_descriptor.h"
|
|
#include "rmnet_genl.h"
|
|
#include <soc/qcom/rmnet_qmi.h>
|
|
#include <soc/qcom/qmi_rmnet.h>
|
|
|
|
/* Locking scheme -
|
|
* The shared resource which needs to be protected is realdev->rx_handler_data.
|
|
* For the writer path, this is using rtnl_lock(). The writer paths are
|
|
* rmnet_newlink(), rmnet_dellink() and rmnet_force_unassociate_device(). These
|
|
* paths are already called with rtnl_lock() acquired in. There is also an
|
|
* ASSERT_RTNL() to ensure that we are calling with rtnl acquired. For
|
|
* dereference here, we will need to use rtnl_dereference(). Dev list writing
|
|
* needs to happen with rtnl_lock() acquired for netdev_master_upper_dev_link().
|
|
* For the reader path, the real_dev->rx_handler_data is called in the TX / RX
|
|
* path. We only need rcu_read_lock() for these scenarios. In these cases,
|
|
* the rcu_read_lock() is held in __dev_queue_xmit() and
|
|
* netif_receive_skb_internal(), so readers need to use rcu_dereference_rtnl()
|
|
* to get the relevant information. For dev list reading, we again acquire
|
|
* rcu_read_lock() in rmnet_dellink() for netdev_master_upper_dev_get_rcu().
|
|
* We also use unregister_netdevice_many() to free all rmnet devices in
|
|
* rmnet_force_unassociate_device() so we dont lose the rtnl_lock() and free in
|
|
* same context.
|
|
*/
|
|
|
|
/* Local Definitions and Declarations */
|
|
|
|
enum {
|
|
IFLA_RMNET_DFC_QOS = __IFLA_RMNET_MAX,
|
|
IFLA_RMNET_UL_AGG_PARAMS,
|
|
__IFLA_RMNET_EXT_MAX,
|
|
};
|
|
|
|
#define IFLA_RMNET_EXT_MAX (__IFLA_RMNET_EXT_MAX - 1)
|
|
|
|
static const struct nla_policy rmnet_policy[__IFLA_RMNET_EXT_MAX] = {
|
|
[IFLA_RMNET_MUX_ID] = {
|
|
.type = NLA_U16
|
|
},
|
|
[IFLA_RMNET_FLAGS] = {
|
|
.len = sizeof(struct ifla_rmnet_flags)
|
|
},
|
|
[IFLA_RMNET_DFC_QOS] = {
|
|
.len = sizeof(struct tcmsg)
|
|
},
|
|
[IFLA_RMNET_UL_AGG_PARAMS] = {
|
|
.len = sizeof(struct rmnet_egress_agg_params)
|
|
},
|
|
};
|
|
|
|
int rmnet_is_real_dev_registered(const struct net_device *real_dev)
|
|
{
|
|
return rcu_access_pointer(real_dev->rx_handler) == rmnet_rx_handler;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_is_real_dev_registered);
|
|
|
|
/* Needs rtnl lock */
|
|
static struct rmnet_port*
|
|
rmnet_get_port_rtnl(const struct net_device *real_dev)
|
|
{
|
|
return rtnl_dereference(real_dev->rx_handler_data);
|
|
}
|
|
|
|
static int rmnet_unregister_real_device(struct net_device *real_dev,
|
|
struct rmnet_port *port)
|
|
{
|
|
if (port->nr_rmnet_devs)
|
|
return -EINVAL;
|
|
|
|
netdev_rx_handler_unregister(real_dev);
|
|
|
|
rmnet_map_cmd_exit(port);
|
|
rmnet_map_tx_aggregate_exit(port);
|
|
|
|
rmnet_descriptor_deinit(port);
|
|
|
|
kfree(port);
|
|
|
|
/* release reference on real_dev */
|
|
dev_put(real_dev);
|
|
|
|
netdev_dbg(real_dev, "Removed from rmnet\n");
|
|
return 0;
|
|
}
|
|
|
|
static int rmnet_register_real_device(struct net_device *real_dev,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct rmnet_port *port;
|
|
int rc, entry;
|
|
|
|
ASSERT_RTNL();
|
|
|
|
if (rmnet_is_real_dev_registered(real_dev)) {
|
|
port = rmnet_get_port_rtnl(real_dev);
|
|
if (port->rmnet_mode != RMNET_EPMODE_VND) {
|
|
NL_SET_ERR_MSG_MOD(extack, "bridge device already exists");
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
port = kzalloc(sizeof(*port), GFP_ATOMIC);
|
|
if (!port)
|
|
return -ENOMEM;
|
|
|
|
port->dev = real_dev;
|
|
rc = netdev_rx_handler_register(real_dev, rmnet_rx_handler, port);
|
|
if (rc) {
|
|
kfree(port);
|
|
return -EBUSY;
|
|
}
|
|
/* hold on to real dev for MAP data */
|
|
dev_hold(real_dev);
|
|
|
|
for (entry = 0; entry < RMNET_MAX_LOGICAL_EP; entry++)
|
|
INIT_HLIST_HEAD(&port->muxed_ep[entry]);
|
|
|
|
rc = rmnet_descriptor_init(port);
|
|
if (rc) {
|
|
rmnet_descriptor_deinit(port);
|
|
return rc;
|
|
}
|
|
|
|
rmnet_map_tx_aggregate_init(port);
|
|
rmnet_map_cmd_init(port);
|
|
|
|
netdev_dbg(real_dev, "registered with rmnet\n");
|
|
return 0;
|
|
}
|
|
|
|
static void rmnet_unregister_bridge(struct net_device *dev,
|
|
struct rmnet_port *port)
|
|
{
|
|
struct rmnet_port *bridge_port;
|
|
struct net_device *bridge_dev;
|
|
|
|
if (port->rmnet_mode != RMNET_EPMODE_BRIDGE)
|
|
return;
|
|
|
|
/* bridge slave handling */
|
|
if (!port->nr_rmnet_devs) {
|
|
bridge_dev = port->bridge_ep;
|
|
|
|
bridge_port = rmnet_get_port_rtnl(bridge_dev);
|
|
bridge_port->bridge_ep = NULL;
|
|
bridge_port->rmnet_mode = RMNET_EPMODE_VND;
|
|
} else {
|
|
bridge_dev = port->bridge_ep;
|
|
|
|
bridge_port = rmnet_get_port_rtnl(bridge_dev);
|
|
rmnet_unregister_real_device(bridge_dev, bridge_port);
|
|
}
|
|
}
|
|
|
|
static int rmnet_newlink(struct net *src_net, struct net_device *dev,
|
|
struct nlattr *tb[], struct nlattr *data[],
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct net_device *real_dev;
|
|
int mode = RMNET_EPMODE_VND;
|
|
struct rmnet_endpoint *ep;
|
|
struct rmnet_port *port;
|
|
u32 data_format;
|
|
int err = 0;
|
|
u16 mux_id;
|
|
|
|
real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
|
|
if (!real_dev || !dev)
|
|
return -ENODEV;
|
|
|
|
if (!data[IFLA_RMNET_MUX_ID])
|
|
return -EINVAL;
|
|
|
|
ep = kzalloc(sizeof(*ep), GFP_ATOMIC);
|
|
if (!ep)
|
|
return -ENOMEM;
|
|
|
|
mux_id = nla_get_u16(data[IFLA_RMNET_MUX_ID]);
|
|
|
|
err = rmnet_register_real_device(real_dev, extack);
|
|
if (err)
|
|
goto err0;
|
|
|
|
port = rmnet_get_port_rtnl(real_dev);
|
|
err = rmnet_vnd_newlink(mux_id, dev, port, real_dev, ep);
|
|
if (err)
|
|
goto err1;
|
|
|
|
port->rmnet_mode = mode;
|
|
|
|
hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]);
|
|
|
|
if (data[IFLA_RMNET_FLAGS]) {
|
|
struct ifla_rmnet_flags *flags;
|
|
|
|
flags = nla_data(data[IFLA_RMNET_FLAGS]);
|
|
data_format = flags->flags & flags->mask;
|
|
netdev_dbg(dev, "data format [0x%08X]\n", data_format);
|
|
port->data_format = data_format;
|
|
}
|
|
|
|
if (data[IFLA_RMNET_UL_AGG_PARAMS]) {
|
|
void *agg_params;
|
|
unsigned long irq_flags;
|
|
|
|
agg_params = nla_data(data[IFLA_RMNET_UL_AGG_PARAMS]);
|
|
spin_lock_irqsave(&port->agg_lock, irq_flags);
|
|
memcpy(&port->egress_agg_params, agg_params,
|
|
sizeof(port->egress_agg_params));
|
|
spin_unlock_irqrestore(&port->agg_lock, irq_flags);
|
|
}
|
|
|
|
return 0;
|
|
|
|
err1:
|
|
rmnet_unregister_real_device(real_dev, port);
|
|
err0:
|
|
kfree(ep);
|
|
return err;
|
|
}
|
|
|
|
static void rmnet_dellink(struct net_device *dev, struct list_head *head)
|
|
{
|
|
struct rmnet_priv *priv = netdev_priv(dev);
|
|
struct net_device *real_dev;
|
|
struct rmnet_endpoint *ep;
|
|
struct rmnet_port *port;
|
|
u8 mux_id;
|
|
|
|
real_dev = priv->real_dev;
|
|
|
|
if (!real_dev || !rmnet_is_real_dev_registered(real_dev))
|
|
return;
|
|
|
|
port = rmnet_get_port_rtnl(real_dev);
|
|
|
|
mux_id = rmnet_vnd_get_mux(dev);
|
|
|
|
ep = rmnet_get_endpoint(port, mux_id);
|
|
if (ep) {
|
|
hlist_del_init_rcu(&ep->hlnode);
|
|
rmnet_unregister_bridge(dev, port);
|
|
rmnet_vnd_dellink(mux_id, port, ep);
|
|
synchronize_rcu();
|
|
kfree(ep);
|
|
}
|
|
|
|
if (!port->nr_rmnet_devs)
|
|
qmi_rmnet_qmi_exit(port->qmi_info, port);
|
|
|
|
unregister_netdevice(dev);
|
|
|
|
qmi_rmnet_qos_exit_post();
|
|
|
|
rmnet_unregister_real_device(real_dev, port);
|
|
}
|
|
|
|
static void rmnet_force_unassociate_device(struct net_device *dev)
|
|
{
|
|
struct net_device *real_dev = dev;
|
|
struct hlist_node *tmp_ep;
|
|
struct rmnet_endpoint *ep;
|
|
struct rmnet_port *port;
|
|
unsigned long bkt_ep;
|
|
LIST_HEAD(list);
|
|
HLIST_HEAD(cleanup_list);
|
|
|
|
if (!rmnet_is_real_dev_registered(real_dev))
|
|
return;
|
|
|
|
ASSERT_RTNL();
|
|
|
|
port = rmnet_get_port_rtnl(dev);
|
|
qmi_rmnet_qmi_exit(port->qmi_info, port);
|
|
|
|
rmnet_unregister_bridge(dev, port);
|
|
|
|
hash_for_each_safe(port->muxed_ep, bkt_ep, tmp_ep, ep, hlnode) {
|
|
unregister_netdevice_queue(ep->egress_dev, &list);
|
|
rmnet_vnd_dellink(ep->mux_id, port, ep);
|
|
|
|
hlist_del_init_rcu(&ep->hlnode);
|
|
hlist_add_head(&ep->hlnode, &cleanup_list);
|
|
}
|
|
|
|
synchronize_rcu();
|
|
|
|
hlist_for_each_entry_safe(ep, tmp_ep, &cleanup_list, hlnode) {
|
|
hlist_del(&ep->hlnode);
|
|
kfree(ep);
|
|
}
|
|
|
|
/* Unregistering devices in context before freeing port.
|
|
* If this API becomes non-context their order should switch.
|
|
*/
|
|
unregister_netdevice_many(&list);
|
|
|
|
qmi_rmnet_qos_exit_post();
|
|
|
|
rmnet_unregister_real_device(real_dev, port);
|
|
}
|
|
|
|
static int rmnet_config_notify_cb(struct notifier_block *nb,
|
|
unsigned long event, void *data)
|
|
{
|
|
struct net_device *dev = netdev_notifier_info_to_dev(data);
|
|
|
|
if (!dev)
|
|
return NOTIFY_DONE;
|
|
|
|
switch (event) {
|
|
case NETDEV_UNREGISTER:
|
|
netdev_dbg(dev, "Kernel unregister\n");
|
|
rmnet_force_unassociate_device(dev);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
static struct notifier_block rmnet_dev_notifier __read_mostly = {
|
|
.notifier_call = rmnet_config_notify_cb,
|
|
};
|
|
|
|
static int rmnet_rtnl_validate(struct nlattr *tb[], struct nlattr *data[],
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct rmnet_egress_agg_params *agg_params;
|
|
u16 mux_id;
|
|
|
|
if (!data) {
|
|
return -EINVAL;
|
|
} else {
|
|
if (data[IFLA_RMNET_MUX_ID]) {
|
|
mux_id = nla_get_u16(data[IFLA_RMNET_MUX_ID]);
|
|
if (mux_id > (RMNET_MAX_LOGICAL_EP - 1))
|
|
return -ERANGE;
|
|
}
|
|
|
|
if (data[IFLA_RMNET_UL_AGG_PARAMS]) {
|
|
agg_params = nla_data(data[IFLA_RMNET_UL_AGG_PARAMS]);
|
|
if (agg_params->agg_time < 1000000)
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[],
|
|
struct nlattr *data[],
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct rmnet_priv *priv = netdev_priv(dev);
|
|
struct net_device *real_dev;
|
|
struct rmnet_endpoint *ep;
|
|
struct rmnet_port *port;
|
|
u16 mux_id;
|
|
|
|
if (!dev)
|
|
return -ENODEV;
|
|
|
|
real_dev = __dev_get_by_index(dev_net(dev),
|
|
nla_get_u32(tb[IFLA_LINK]));
|
|
|
|
if (!real_dev || !rmnet_is_real_dev_registered(real_dev))
|
|
return -ENODEV;
|
|
|
|
port = rmnet_get_port_rtnl(real_dev);
|
|
|
|
if (data[IFLA_RMNET_MUX_ID]) {
|
|
mux_id = nla_get_u16(data[IFLA_RMNET_MUX_ID]);
|
|
ep = rmnet_get_endpoint(port, priv->mux_id);
|
|
if (!ep)
|
|
return -ENODEV;
|
|
|
|
hlist_del_init_rcu(&ep->hlnode);
|
|
hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]);
|
|
|
|
ep->mux_id = mux_id;
|
|
priv->mux_id = mux_id;
|
|
}
|
|
|
|
if (data[IFLA_RMNET_FLAGS]) {
|
|
struct ifla_rmnet_flags *flags;
|
|
|
|
flags = nla_data(data[IFLA_RMNET_FLAGS]);
|
|
port->data_format = flags->flags & flags->mask;
|
|
}
|
|
|
|
if (data[IFLA_RMNET_DFC_QOS]) {
|
|
struct tcmsg *tcm;
|
|
|
|
tcm = nla_data(data[IFLA_RMNET_DFC_QOS]);
|
|
qmi_rmnet_change_link(dev, port, tcm);
|
|
}
|
|
|
|
if (data[IFLA_RMNET_UL_AGG_PARAMS]) {
|
|
struct rmnet_egress_agg_params *agg_params;
|
|
|
|
agg_params = nla_data(data[IFLA_RMNET_UL_AGG_PARAMS]);
|
|
rmnet_map_update_ul_agg_config(port, agg_params->agg_size,
|
|
agg_params->agg_count,
|
|
agg_params->agg_features,
|
|
agg_params->agg_time);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static size_t rmnet_get_size(const struct net_device *dev)
|
|
{
|
|
return
|
|
/* IFLA_RMNET_MUX_ID */
|
|
nla_total_size(2) +
|
|
/* IFLA_RMNET_FLAGS */
|
|
nla_total_size(sizeof(struct ifla_rmnet_flags)) +
|
|
/* IFLA_RMNET_DFC_QOS */
|
|
nla_total_size(sizeof(struct tcmsg)) +
|
|
/* IFLA_RMNET_UL_AGG_PARAMS */
|
|
nla_total_size(sizeof(struct rmnet_egress_agg_params));
|
|
}
|
|
|
|
static int rmnet_fill_info(struct sk_buff *skb, const struct net_device *dev)
|
|
{
|
|
struct rmnet_priv *priv = netdev_priv(dev);
|
|
struct net_device *real_dev;
|
|
struct ifla_rmnet_flags f;
|
|
struct rmnet_port *port = NULL;
|
|
|
|
real_dev = priv->real_dev;
|
|
|
|
if (nla_put_u16(skb, IFLA_RMNET_MUX_ID, priv->mux_id))
|
|
goto nla_put_failure;
|
|
|
|
if (rmnet_is_real_dev_registered(real_dev)) {
|
|
port = rmnet_get_port_rtnl(real_dev);
|
|
f.flags = port->data_format;
|
|
} else {
|
|
f.flags = 0;
|
|
}
|
|
|
|
f.mask = ~0;
|
|
|
|
if (nla_put(skb, IFLA_RMNET_FLAGS, sizeof(f), &f))
|
|
goto nla_put_failure;
|
|
|
|
if (port) {
|
|
if (nla_put(skb, IFLA_RMNET_UL_AGG_PARAMS,
|
|
sizeof(port->egress_agg_params),
|
|
&port->egress_agg_params))
|
|
goto nla_put_failure;
|
|
}
|
|
|
|
return 0;
|
|
|
|
nla_put_failure:
|
|
return -EMSGSIZE;
|
|
}
|
|
|
|
struct rtnl_link_ops rmnet_link_ops __read_mostly = {
|
|
.kind = "rmnet",
|
|
.maxtype = IFLA_RMNET_EXT_MAX,
|
|
.priv_size = sizeof(struct rmnet_priv),
|
|
.setup = rmnet_vnd_setup,
|
|
.validate = rmnet_rtnl_validate,
|
|
.newlink = rmnet_newlink,
|
|
.dellink = rmnet_dellink,
|
|
.get_size = rmnet_get_size,
|
|
.changelink = rmnet_changelink,
|
|
.policy = rmnet_policy,
|
|
.fill_info = rmnet_fill_info,
|
|
};
|
|
|
|
/* Needs either rcu_read_lock() or rtnl lock */
|
|
struct rmnet_port *rmnet_get_port(struct net_device *real_dev)
|
|
{
|
|
if (rmnet_is_real_dev_registered(real_dev))
|
|
return rcu_dereference_rtnl(real_dev->rx_handler_data);
|
|
else
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_port);
|
|
|
|
struct rmnet_endpoint *rmnet_get_endpoint(struct rmnet_port *port, u8 mux_id)
|
|
{
|
|
struct rmnet_endpoint *ep;
|
|
|
|
hlist_for_each_entry_rcu(ep, &port->muxed_ep[mux_id], hlnode) {
|
|
if (ep->mux_id == mux_id)
|
|
return ep;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_endpoint);
|
|
|
|
int rmnet_add_bridge(struct net_device *rmnet_dev,
|
|
struct net_device *slave_dev,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct rmnet_priv *priv = netdev_priv(rmnet_dev);
|
|
struct net_device *real_dev = priv->real_dev;
|
|
struct rmnet_port *port, *slave_port;
|
|
int err;
|
|
|
|
port = rmnet_get_port(real_dev);
|
|
|
|
/* If there is more than one rmnet dev attached, its probably being
|
|
* used for muxing. Skip the briding in that case
|
|
*/
|
|
if (port->nr_rmnet_devs > 1)
|
|
return -EINVAL;
|
|
|
|
if (rmnet_is_real_dev_registered(slave_dev))
|
|
return -EBUSY;
|
|
|
|
err = rmnet_register_real_device(slave_dev, extack);
|
|
if (err)
|
|
return -EBUSY;
|
|
|
|
slave_port = rmnet_get_port(slave_dev);
|
|
slave_port->rmnet_mode = RMNET_EPMODE_BRIDGE;
|
|
slave_port->bridge_ep = real_dev;
|
|
|
|
port->rmnet_mode = RMNET_EPMODE_BRIDGE;
|
|
port->bridge_ep = slave_dev;
|
|
|
|
netdev_dbg(slave_dev, "registered with rmnet as slave\n");
|
|
return 0;
|
|
}
|
|
|
|
int rmnet_del_bridge(struct net_device *rmnet_dev,
|
|
struct net_device *slave_dev)
|
|
{
|
|
struct rmnet_priv *priv = netdev_priv(rmnet_dev);
|
|
struct net_device *real_dev = priv->real_dev;
|
|
struct rmnet_port *port, *slave_port;
|
|
|
|
port = rmnet_get_port(real_dev);
|
|
port->rmnet_mode = RMNET_EPMODE_VND;
|
|
port->bridge_ep = NULL;
|
|
|
|
slave_port = rmnet_get_port(slave_dev);
|
|
rmnet_unregister_real_device(slave_dev, slave_port);
|
|
|
|
netdev_dbg(slave_dev, "removed from rmnet as slave\n");
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_QCOM_QMI_RMNET
|
|
void *rmnet_get_qmi_pt(void *port)
|
|
{
|
|
if (port)
|
|
return ((struct rmnet_port *)port)->qmi_info;
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_qmi_pt);
|
|
|
|
void *rmnet_get_qos_pt(struct net_device *dev)
|
|
{
|
|
struct rmnet_priv *priv;
|
|
|
|
if (dev) {
|
|
priv = netdev_priv(dev);
|
|
return rcu_dereference(priv->qos_info);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_qos_pt);
|
|
|
|
void *rmnet_get_rmnet_port(struct net_device *dev)
|
|
{
|
|
struct rmnet_priv *priv;
|
|
|
|
if (dev) {
|
|
priv = netdev_priv(dev);
|
|
return (void *)rmnet_get_port(priv->real_dev);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_rmnet_port);
|
|
|
|
struct net_device *rmnet_get_rmnet_dev(void *port, u8 mux_id)
|
|
{
|
|
struct rmnet_endpoint *ep;
|
|
|
|
if (port) {
|
|
ep = rmnet_get_endpoint((struct rmnet_port *)port, mux_id);
|
|
if (ep)
|
|
return ep->egress_dev;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_rmnet_dev);
|
|
|
|
void rmnet_reset_qmi_pt(void *port)
|
|
{
|
|
if (port)
|
|
((struct rmnet_port *)port)->qmi_info = NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_reset_qmi_pt);
|
|
|
|
void rmnet_init_qmi_pt(void *port, void *qmi)
|
|
{
|
|
if (port)
|
|
((struct rmnet_port *)port)->qmi_info = qmi;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_init_qmi_pt);
|
|
|
|
void rmnet_get_packets(void *port, u64 *rx, u64 *tx)
|
|
{
|
|
struct rmnet_priv *priv;
|
|
struct rmnet_pcpu_stats *ps;
|
|
unsigned int cpu, start;
|
|
|
|
struct rmnet_endpoint *ep;
|
|
unsigned long bkt;
|
|
|
|
if (!port || !tx || !rx)
|
|
return;
|
|
|
|
*tx = 0;
|
|
*rx = 0;
|
|
rcu_read_lock();
|
|
hash_for_each(((struct rmnet_port *)port)->muxed_ep, bkt, ep, hlnode) {
|
|
priv = netdev_priv(ep->egress_dev);
|
|
for_each_possible_cpu(cpu) {
|
|
ps = per_cpu_ptr(priv->pcpu_stats, cpu);
|
|
do {
|
|
start = u64_stats_fetch_begin_irq(&ps->syncp);
|
|
*tx += ps->stats.tx_pkts;
|
|
*rx += ps->stats.rx_pkts;
|
|
} while (u64_stats_fetch_retry_irq(&ps->syncp, start));
|
|
}
|
|
}
|
|
rcu_read_unlock();
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_packets);
|
|
|
|
void rmnet_set_powersave_format(void *port)
|
|
{
|
|
if (!port)
|
|
return;
|
|
((struct rmnet_port *)port)->data_format |= RMNET_INGRESS_FORMAT_PS;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_set_powersave_format);
|
|
|
|
void rmnet_clear_powersave_format(void *port)
|
|
{
|
|
if (!port)
|
|
return;
|
|
((struct rmnet_port *)port)->data_format &= ~RMNET_INGRESS_FORMAT_PS;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_clear_powersave_format);
|
|
|
|
void rmnet_enable_all_flows(void *port)
|
|
{
|
|
struct rmnet_endpoint *ep;
|
|
unsigned long bkt;
|
|
|
|
if (unlikely(!port))
|
|
return;
|
|
|
|
rcu_read_lock();
|
|
hash_for_each_rcu(((struct rmnet_port *)port)->muxed_ep,
|
|
bkt, ep, hlnode) {
|
|
qmi_rmnet_enable_all_flows(ep->egress_dev);
|
|
}
|
|
rcu_read_unlock();
|
|
}
|
|
EXPORT_SYMBOL(rmnet_enable_all_flows);
|
|
|
|
bool rmnet_all_flows_enabled(void *port)
|
|
{
|
|
struct rmnet_endpoint *ep;
|
|
unsigned long bkt;
|
|
bool ret = true;
|
|
|
|
if (unlikely(!port))
|
|
return true;
|
|
|
|
rcu_read_lock();
|
|
hash_for_each_rcu(((struct rmnet_port *)port)->muxed_ep,
|
|
bkt, ep, hlnode) {
|
|
if (!qmi_rmnet_all_flows_enabled(ep->egress_dev)) {
|
|
ret = false;
|
|
goto out;
|
|
}
|
|
}
|
|
out:
|
|
rcu_read_unlock();
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_all_flows_enabled);
|
|
|
|
int rmnet_get_powersave_notif(void *port)
|
|
{
|
|
if (!port)
|
|
return 0;
|
|
return ((struct rmnet_port *)port)->data_format & RMNET_FORMAT_PS_NOTIF;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_powersave_notif);
|
|
|
|
struct net_device *rmnet_get_real_dev(void *port)
|
|
{
|
|
if (port)
|
|
return ((struct rmnet_port *)port)->dev;
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_real_dev);
|
|
|
|
int rmnet_get_dlmarker_info(void *port)
|
|
{
|
|
if (!port)
|
|
return 0;
|
|
|
|
return ((struct rmnet_port *)port)->data_format &
|
|
(RMNET_INGRESS_FORMAT_DL_MARKER_V1 |
|
|
RMNET_INGRESS_FORMAT_DL_MARKER_V2);
|
|
}
|
|
EXPORT_SYMBOL(rmnet_get_dlmarker_info);
|
|
|
|
#endif
|
|
|
|
/* Startup/Shutdown */
|
|
|
|
static int __init rmnet_init(void)
|
|
{
|
|
int rc;
|
|
|
|
rc = register_netdevice_notifier(&rmnet_dev_notifier);
|
|
if (rc != 0)
|
|
return rc;
|
|
|
|
rc = rtnl_link_register(&rmnet_link_ops);
|
|
if (rc != 0) {
|
|
unregister_netdevice_notifier(&rmnet_dev_notifier);
|
|
return rc;
|
|
}
|
|
rmnet_core_genl_init();
|
|
|
|
return rc;
|
|
}
|
|
|
|
static void __exit rmnet_exit(void)
|
|
{
|
|
unregister_netdevice_notifier(&rmnet_dev_notifier);
|
|
rtnl_link_unregister(&rmnet_link_ops);
|
|
rmnet_core_genl_deinit();
|
|
}
|
|
|
|
module_init(rmnet_init)
|
|
module_exit(rmnet_exit)
|
|
MODULE_LICENSE("GPL v2");
|