diff options
author | 2023-02-21 18:24:12 -0800 | |
---|---|---|
committer | 2023-02-21 18:24:12 -0800 | |
commit | 5b7c4cabbb65f5c469464da6c5f614cbd7f730f2 (patch) | |
tree | cc5c2d0a898769fd59549594fedb3ee6f84e59a0 /drivers/pnp/card.c | |
download | linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.tar.gz linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.zip |
Merge tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-nextgrafted
Pull networking updates from Jakub Kicinski:
"Core:
- Add dedicated kmem_cache for typical/small skb->head, avoid having
to access struct page at kfree time, and improve memory use.
- Introduce sysctl to set default RPS configuration for new netdevs.
- Define Netlink protocol specification format which can be used to
describe messages used by each family and auto-generate parsers.
Add tools for generating kernel data structures and uAPI headers.
- Expose all net/core sysctls inside netns.
- Remove 4s sleep in netpoll if carrier is instantly detected on
boot.
- Add configurable limit of MDB entries per port, and port-vlan.
- Continue populating drop reasons throughout the stack.
- Retire a handful of legacy Qdiscs and classifiers.
Protocols:
- Support IPv4 big TCP (TSO frames larger than 64kB).
- Add IP_LOCAL_PORT_RANGE socket option, to control local port range
on socket by socket basis.
- Track and report in procfs number of MPTCP sockets used.
- Support mixing IPv4 and IPv6 flows in the in-kernel MPTCP path
manager.
- IPv6: don't check net.ipv6.route.max_size and rely on garbage
collection to free memory (similarly to IPv4).
- Support Penultimate Segment Pop (PSP) flavor in SRv6 (RFC8986).
- ICMP: add per-rate limit counters.
- Add support for user scanning requests in ieee802154.
- Remove static WEP support.
- Support minimal Wi-Fi 7 Extremely High Throughput (EHT) rate
reporting.
- WiFi 7 EHT channel puncturing support (client & AP).
BPF:
- Add a rbtree data structure following the "next-gen data structure"
precedent set by recently added linked list, that is, by using
kfunc + kptr instead of adding a new BPF map type.
- Expose XDP hints via kfuncs with initial support for RX hash and
timestamp metadata.
- Add BPF_F_NO_TUNNEL_KEY extension to bpf_skb_set_tunnel_key to
better support decap on GRE tunnel devices not operating in collect
metadata.
- Improve x86 JIT's codegen for PROBE_MEM runtime error checks.
- Remove the need for trace_printk_lock for bpf_trace_printk and
bpf_trace_vprintk helpers.
- Extend libbpf's bpf_tracing.h support for tracing arguments of
kprobes/uprobes and syscall as a special case.
- Significantly reduce the search time for module symbols by
livepatch and BPF.
- Enable cpumasks to be used as kptrs, which is useful for tracing
programs tracking which tasks end up running on which CPUs in
different time intervals.
- Add support for BPF trampoline on s390x and riscv64.
- Add capability to export the XDP features supported by the NIC.
- Add __bpf_kfunc tag for marking kernel functions as kfuncs.
- Add cgroup.memory=nobpf kernel parameter option to disable BPF
memory accounting for container environments.
Netfilter:
- Remove the CLUSTERIP target. It has been marked as obsolete for
years, and we still have WARN splats wrt races of the out-of-band
/proc interface installed by this target.
- Add 'destroy' commands to nf_tables. They are identical to the
existing 'delete' commands, but do not return an error if the
referenced object (set, chain, rule...) did not exist.
Driver API:
- Improve cpumask_local_spread() locality to help NICs set the right
IRQ affinity on AMD platforms.
- Separate C22 and C45 MDIO bus transactions more clearly.
- Introduce new DCB table to control DSCP rewrite on egress.
- Support configuration of Physical Layer Collision Avoidance (PLCA)
Reconciliation Sublayer (RS) (802.3cg-2019). Modern version of
shared medium Ethernet.
- Support for MAC Merge layer (IEEE 802.3-2018 clause 99). Allowing
preemption of low priority frames by high priority frames.
- Add support for controlling MACSec offload using netlink SET.
- Rework devlink instance refcounts to allow registration and
de-registration under the instance lock. Split the code into
multiple files, drop some of the unnecessarily granular locks and
factor out common parts of netlink operation handling.
- Add TX frame aggregation parameters (for USB drivers).
- Add a new attr TCA_EXT_WARN_MSG to report TC (offload) warning
messages with notifications for debug.
- Allow offloading of UDP NEW connections via act_ct.
- Add support for per action HW stats in TC.
- Support hardware miss to TC action (continue processing in SW from
a specific point in the action chain).
- Warn if old Wireless Extension user space interface is used with
modern cfg80211/mac80211 drivers. Do not support Wireless
Extensions for Wi-Fi 7 devices at all. Everyone should switch to
using nl80211 interface instead.
- Improve the CAN bit timing configuration. Use extack to return
error messages directly to user space, update the SJW handling,
including the definition of a new default value that will benefit
CAN-FD controllers, by increasing their oscillator tolerance.
New hardware / drivers:
- Ethernet:
- nVidia BlueField-3 support (control traffic driver)
- Ethernet support for imx93 SoCs
- Motorcomm yt8531 gigabit Ethernet PHY
- onsemi NCN26000 10BASE-T1S PHY (with support for PLCA)
- Microchip LAN8841 PHY (incl. cable diagnostics and PTP)
- Amlogic gxl MDIO mux
- WiFi:
- RealTek RTL8188EU (rtl8xxxu)
- Qualcomm Wi-Fi 7 devices (ath12k)
- CAN:
- Renesas R-Car V4H
Drivers:
- Bluetooth:
- Set Per Platform Antenna Gain (PPAG) for Intel controllers.
- Ethernet NICs:
- Intel (1G, igc):
- support TSN / Qbv / packet scheduling features of i226 model
- Intel (100G, ice):
- use GNSS subsystem instead of TTY
- multi-buffer XDP support
- extend support for GPIO pins to E823 devices
- nVidia/Mellanox:
- update the shared buffer configuration on PFC commands
- implement PTP adjphase function for HW offset control
- TC support for Geneve and GRE with VF tunnel offload
- more efficient crypto key management method
- multi-port eswitch support
- Netronome/Corigine:
- add DCB IEEE support
- support IPsec offloading for NFP3800
- Freescale/NXP (enetc):
- support XDP_REDIRECT for XDP non-linear buffers
- improve reconfig, avoid link flap and waiting for idle
- support MAC Merge layer
- Other NICs:
- sfc/ef100: add basic devlink support for ef100
- ionic: rx_push mode operation (writing descriptors via MMIO)
- bnxt: use the auxiliary bus abstraction for RDMA
- r8169: disable ASPM and reset bus in case of tx timeout
- cpsw: support QSGMII mode for J721e CPSW9G
- cpts: support pulse-per-second output
- ngbe: add an mdio bus driver
- usbnet: optimize usbnet_bh() by avoiding unnecessary queuing
- r8152: handle devices with FW with NCM support
- amd-xgbe: support 10Mbps, 2.5GbE speeds and rx-adaptation
- virtio-net: support multi buffer XDP
- virtio/vsock: replace virtio_vsock_pkt with sk_buff
- tsnep: XDP support
- Ethernet high-speed switches:
- nVidia/Mellanox (mlxsw):
- add support for latency TLV (in FW control messages)
- Microchip (sparx5):
- separate explicit and implicit traffic forwarding rules, make
the implicit rules always active
- add support for egress DSCP rewrite
- IS0 VCAP support (Ingress Classification)
- IS2 VCAP filters (protos, L3 addrs, L4 ports, flags, ToS
etc.)
- ES2 VCAP support (Egress Access Control)
- support for Per-Stream Filtering and Policing (802.1Q,
8.6.5.1)
- Ethernet embedded switches:
- Marvell (mv88e6xxx):
- add MAB (port auth) offload support
- enable PTP receive for mv88e6390
- NXP (ocelot):
- support MAC Merge layer
- support for the the vsc7512 internal copper phys
- Microchip:
- lan9303: convert to PHYLINK
- lan966x: support TC flower filter statistics
- lan937x: PTP support for KSZ9563/KSZ8563 and LAN937x
- lan937x: support Credit Based Shaper configuration
- ksz9477: support Energy Efficient Ethernet
- other:
- qca8k: convert to regmap read/write API, use bulk operations
- rswitch: Improve TX timestamp accuracy
- Intel WiFi (iwlwifi):
- EHT (Wi-Fi 7) rate reporting
- STEP equalizer support: transfer some STEP (connection to radio
on platforms with integrated wifi) related parameters from the
BIOS to the firmware.
- Qualcomm 802.11ax WiFi (ath11k):
- IPQ5018 support
- Fine Timing Measurement (FTM) responder role support
- channel 177 support
- MediaTek WiFi (mt76):
- per-PHY LED support
- mt7996: EHT (Wi-Fi 7) support
- Wireless Ethernet Dispatch (WED) reset support
- switch to using page pool allocator
- RealTek WiFi (rtw89):
- support new version of Bluetooth co-existance
- Mobile:
- rmnet: support TX aggregation"
* tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (1872 commits)
page_pool: add a comment explaining the fragment counter usage
net: ethtool: fix __ethtool_dev_mm_supported() implementation
ethtool: pse-pd: Fix double word in comments
xsk: add linux/vmalloc.h to xsk.c
sefltests: netdevsim: wait for devlink instance after netns removal
selftest: fib_tests: Always cleanup before exit
net/mlx5e: Align IPsec ASO result memory to be as required by hardware
net/mlx5e: TC, Set CT miss to the specific ct action instance
net/mlx5e: Rename CHAIN_TO_REG to MAPPED_OBJ_TO_REG
net/mlx5: Refactor tc miss handling to a single function
net/mlx5: Kconfig: Make tc offload depend on tc skb extension
net/sched: flower: Support hardware miss to tc action
net/sched: flower: Move filter handle initialization earlier
net/sched: cls_api: Support hardware miss to tc action
net/sched: Rename user cookie and act cookie
sfc: fix builds without CONFIG_RTC_LIB
sfc: clean up some inconsistent indentings
net/mlx4_en: Introduce flexible array to silence overflow warning
net: lan966x: Fix possible deadlock inside PTP
net/ulp: Remove redundant ->clone() test in inet_clone_ulp().
...
Diffstat (limited to 'drivers/pnp/card.c')
-rw-r--r-- | drivers/pnp/card.c | 457 |
1 files changed, 457 insertions, 0 deletions
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c new file mode 100644 index 000000000..9610a9f08 --- /dev/null +++ b/drivers/pnp/card.c @@ -0,0 +1,457 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * card.c - contains functions for managing groups of PnP devices + * + * Copyright 2002 Adam Belay <ambx1@neo.rr.com> + */ + +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/ctype.h> +#include <linux/slab.h> +#include <linux/pnp.h> +#include <linux/dma-mapping.h> +#include "base.h" + +LIST_HEAD(pnp_cards); +static LIST_HEAD(pnp_card_drivers); + +static const struct pnp_card_device_id *match_card(struct pnp_card_driver *drv, + struct pnp_card *card) +{ + const struct pnp_card_device_id *drv_id = drv->id_table; + + while (*drv_id->id) { + if (compare_pnp_id(card->id, drv_id->id)) { + int i = 0; + + for (;;) { + int found; + struct pnp_dev *dev; + + if (i == PNP_MAX_DEVICES || + !*drv_id->devs[i].id) + return drv_id; + found = 0; + card_for_each_dev(card, dev) { + if (compare_pnp_id(dev->id, + drv_id->devs[i].id)) { + found = 1; + break; + } + } + if (!found) + break; + i++; + } + } + drv_id++; + } + return NULL; +} + +static void card_remove(struct pnp_dev *dev) +{ + dev->card_link = NULL; +} + +static void card_remove_first(struct pnp_dev *dev) +{ + struct pnp_card_driver *drv = to_pnp_card_driver(dev->driver); + + if (!dev->card || !drv) + return; + if (drv->remove) + drv->remove(dev->card_link); + drv->link.remove = &card_remove; + kfree(dev->card_link); + card_remove(dev); +} + +static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv) +{ + const struct pnp_card_device_id *id; + struct pnp_card_link *clink; + struct pnp_dev *dev; + + if (!drv->probe) + return 0; + id = match_card(drv, card); + if (!id) + return 0; + + clink = kzalloc(sizeof(*clink), GFP_KERNEL); + if (!clink) + return 0; + clink->card = card; + clink->driver = drv; + clink->pm_state = PMSG_ON; + + if (drv->probe(clink, id) >= 0) + return 1; + + /* Recovery */ + card_for_each_dev(card, dev) { + if (dev->card_link == clink) + pnp_release_card_device(dev); + } + kfree(clink); + return 0; +} + +/** + * pnp_add_card_id - adds an EISA id to the specified card + * @id: pointer to a pnp_id structure + * @card: pointer to the desired card + */ +static struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id) +{ + struct pnp_id *dev_id, *ptr; + + dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); + if (!dev_id) + return NULL; + + dev_id->id[0] = id[0]; + dev_id->id[1] = id[1]; + dev_id->id[2] = id[2]; + dev_id->id[3] = tolower(id[3]); + dev_id->id[4] = tolower(id[4]); + dev_id->id[5] = tolower(id[5]); + dev_id->id[6] = tolower(id[6]); + dev_id->id[7] = '\0'; + + dev_id->next = NULL; + ptr = card->id; + while (ptr && ptr->next) + ptr = ptr->next; + if (ptr) + ptr->next = dev_id; + else + card->id = dev_id; + + return dev_id; +} + +static void pnp_free_card_ids(struct pnp_card *card) +{ + struct pnp_id *id; + struct pnp_id *next; + + id = card->id; + while (id) { + next = id->next; + kfree(id); + id = next; + } +} + +static void pnp_release_card(struct device *dmdev) +{ + struct pnp_card *card = to_pnp_card(dmdev); + + pnp_free_card_ids(card); + kfree(card); +} + +struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid) +{ + struct pnp_card *card; + struct pnp_id *dev_id; + + card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL); + if (!card) + return NULL; + + card->protocol = protocol; + card->number = id; + + card->dev.parent = &card->protocol->dev; + dev_set_name(&card->dev, "%02x:%02x", card->protocol->number, card->number); + + card->dev.coherent_dma_mask = DMA_BIT_MASK(24); + card->dev.dma_mask = &card->dev.coherent_dma_mask; + + dev_id = pnp_add_card_id(card, pnpid); + if (!dev_id) { + kfree(card); + return NULL; + } + + return card; +} + +static ssize_t name_show(struct device *dmdev, + struct device_attribute *attr, char *buf) +{ + char *str = buf; + struct pnp_card *card = to_pnp_card(dmdev); + + str += sprintf(str, "%s\n", card->name); + return (str - buf); +} + +static DEVICE_ATTR_RO(name); + +static ssize_t card_id_show(struct device *dmdev, + struct device_attribute *attr, char *buf) +{ + char *str = buf; + struct pnp_card *card = to_pnp_card(dmdev); + struct pnp_id *pos = card->id; + + while (pos) { + str += sprintf(str, "%s\n", pos->id); + pos = pos->next; + } + return (str - buf); +} + +static DEVICE_ATTR_RO(card_id); + +static int pnp_interface_attach_card(struct pnp_card *card) +{ + int rc = device_create_file(&card->dev, &dev_attr_name); + + if (rc) + return rc; + + rc = device_create_file(&card->dev, &dev_attr_card_id); + if (rc) + goto err_name; + + return 0; + +err_name: + device_remove_file(&card->dev, &dev_attr_name); + return rc; +} + +/** + * pnp_add_card - adds a PnP card to the PnP Layer + * @card: pointer to the card to add + */ +int pnp_add_card(struct pnp_card *card) +{ + int error; + struct list_head *pos, *temp; + + card->dev.bus = NULL; + card->dev.release = &pnp_release_card; + error = device_register(&card->dev); + if (error) { + dev_err(&card->dev, "could not register (err=%d)\n", error); + put_device(&card->dev); + return error; + } + + pnp_interface_attach_card(card); + mutex_lock(&pnp_lock); + list_add_tail(&card->global_list, &pnp_cards); + list_add_tail(&card->protocol_list, &card->protocol->cards); + mutex_unlock(&pnp_lock); + + /* we wait until now to add devices in order to ensure the drivers + * will be able to use all of the related devices on the card + * without waiting an unreasonable length of time */ + list_for_each(pos, &card->devices) { + struct pnp_dev *dev = card_to_pnp_dev(pos); + __pnp_add_device(dev); + } + + /* match with card drivers */ + list_for_each_safe(pos, temp, &pnp_card_drivers) { + struct pnp_card_driver *drv = + list_entry(pos, struct pnp_card_driver, + global_list); + card_probe(card, drv); + } + return 0; +} + +/** + * pnp_remove_card - removes a PnP card from the PnP Layer + * @card: pointer to the card to remove + */ +void pnp_remove_card(struct pnp_card *card) +{ + struct list_head *pos, *temp; + + device_unregister(&card->dev); + mutex_lock(&pnp_lock); + list_del(&card->global_list); + list_del(&card->protocol_list); + mutex_unlock(&pnp_lock); + list_for_each_safe(pos, temp, &card->devices) { + struct pnp_dev *dev = card_to_pnp_dev(pos); + pnp_remove_card_device(dev); + } +} + +/** + * pnp_add_card_device - adds a device to the specified card + * @card: pointer to the card to add to + * @dev: pointer to the device to add + */ +int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) +{ + dev->dev.parent = &card->dev; + dev->card_link = NULL; + dev_set_name(&dev->dev, "%02x:%02x.%02x", + dev->protocol->number, card->number, dev->number); + mutex_lock(&pnp_lock); + dev->card = card; + list_add_tail(&dev->card_list, &card->devices); + mutex_unlock(&pnp_lock); + return 0; +} + +/** + * pnp_remove_card_device- removes a device from the specified card + * @dev: pointer to the device to remove + */ +void pnp_remove_card_device(struct pnp_dev *dev) +{ + mutex_lock(&pnp_lock); + dev->card = NULL; + list_del(&dev->card_list); + mutex_unlock(&pnp_lock); + __pnp_remove_device(dev); +} + +/** + * pnp_request_card_device - Searches for a PnP device under the specified card + * @clink: pointer to the card link, cannot be NULL + * @id: pointer to a PnP ID structure that explains the rules for finding the device + * @from: Starting place to search from. If NULL it will start from the beginning. + */ +struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, + const char *id, struct pnp_dev *from) +{ + struct list_head *pos; + struct pnp_dev *dev; + struct pnp_card_driver *drv; + struct pnp_card *card; + + if (!clink || !id) + return NULL; + + card = clink->card; + drv = clink->driver; + if (!from) { + pos = card->devices.next; + } else { + if (from->card != card) + return NULL; + pos = from->card_list.next; + } + while (pos != &card->devices) { + dev = card_to_pnp_dev(pos); + if ((!dev->card_link) && compare_pnp_id(dev->id, id)) + goto found; + pos = pos->next; + } + + return NULL; + +found: + dev->card_link = clink; + dev->dev.driver = &drv->link.driver; + if (pnp_bus_type.probe(&dev->dev)) + goto err_out; + if (device_bind_driver(&dev->dev)) + goto err_out; + + return dev; + +err_out: + dev->dev.driver = NULL; + dev->card_link = NULL; + return NULL; +} +EXPORT_SYMBOL(pnp_request_card_device); + +/** + * pnp_release_card_device - call this when the driver no longer needs the device + * @dev: pointer to the PnP device structure + */ +void pnp_release_card_device(struct pnp_dev *dev) +{ + struct pnp_card_driver *drv = dev->card_link->driver; + + drv->link.remove = &card_remove; + device_release_driver(&dev->dev); + drv->link.remove = &card_remove_first; +} +EXPORT_SYMBOL(pnp_release_card_device); + +/* + * suspend/resume callbacks + */ +static int card_suspend(struct pnp_dev *dev, pm_message_t state) +{ + struct pnp_card_link *link = dev->card_link; + + if (link->pm_state.event == state.event) + return 0; + link->pm_state = state; + return link->driver->suspend(link, state); +} + +static int card_resume(struct pnp_dev *dev) +{ + struct pnp_card_link *link = dev->card_link; + + if (link->pm_state.event == PM_EVENT_ON) + return 0; + link->pm_state = PMSG_ON; + link->driver->resume(link); + return 0; +} + +/** + * pnp_register_card_driver - registers a PnP card driver with the PnP Layer + * @drv: pointer to the driver to register + */ +int pnp_register_card_driver(struct pnp_card_driver *drv) +{ + int error; + struct list_head *pos, *temp; + + drv->link.name = drv->name; + drv->link.id_table = NULL; /* this will disable auto matching */ + drv->link.flags = drv->flags; + drv->link.probe = NULL; + drv->link.remove = &card_remove_first; + drv->link.suspend = drv->suspend ? card_suspend : NULL; + drv->link.resume = drv->resume ? card_resume : NULL; + + error = pnp_register_driver(&drv->link); + if (error < 0) + return error; + + mutex_lock(&pnp_lock); + list_add_tail(&drv->global_list, &pnp_card_drivers); + mutex_unlock(&pnp_lock); + + list_for_each_safe(pos, temp, &pnp_cards) { + struct pnp_card *card = + list_entry(pos, struct pnp_card, global_list); + card_probe(card, drv); + } + return 0; +} +EXPORT_SYMBOL(pnp_register_card_driver); + +/** + * pnp_unregister_card_driver - unregisters a PnP card driver from the PnP Layer + * @drv: pointer to the driver to unregister + */ +void pnp_unregister_card_driver(struct pnp_card_driver *drv) +{ + mutex_lock(&pnp_lock); + list_del(&drv->global_list); + mutex_unlock(&pnp_lock); + pnp_unregister_driver(&drv->link); +} +EXPORT_SYMBOL(pnp_unregister_card_driver); |