diff --git a/config/kernel/linux-sunxi-edge.config b/config/kernel/linux-sunxi-edge.config index 22a366b48c..b6b5b8e5d7 100644 --- a/config/kernel/linux-sunxi-edge.config +++ b/config/kernel/linux-sunxi-edge.config @@ -1,6 +1,6 @@ # # Automatically generated file; DO NOT EDIT. -# Linux/arm 5.14.0 Kernel Configuration +# Linux/arm 5.14.6 Kernel Configuration # CONFIG_CC_VERSION_TEXT="arm-linux-gnueabihf-gcc (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)) 8.3.0" CONFIG_CC_IS_GCC=y @@ -1404,7 +1404,6 @@ CONFIG_BRIDGE_VLAN_FILTERING=y CONFIG_BRIDGE_MRP=y # CONFIG_BRIDGE_CFM is not set CONFIG_NET_DSA=m -CONFIG_NET_DSA_TAG_8021Q=m CONFIG_NET_DSA_TAG_AR9331=m CONFIG_NET_DSA_TAG_BRCM_COMMON=m CONFIG_NET_DSA_TAG_BRCM=m @@ -6185,6 +6184,7 @@ CONFIG_VIDEO_SUNXI_CEDRUS=m # CONFIG_LTE_GDM724X is not set # CONFIG_GS_FPGABOOT is not set # CONFIG_UNISYSSPAR is not set +CONFIG_COMMON_CLK_XLNX_CLKWZRD=m CONFIG_FB_TFT=m CONFIG_FB_TFT_AGM1264K_FL=m CONFIG_FB_TFT_BD663474=m diff --git a/config/kernel/linux-sunxi64-edge.config b/config/kernel/linux-sunxi64-edge.config index c76723133c..d07476ecb9 100644 --- a/config/kernel/linux-sunxi64-edge.config +++ b/config/kernel/linux-sunxi64-edge.config @@ -1,6 +1,6 @@ # # Automatically generated file; DO NOT EDIT. -# Linux/arm64 5.14.0 Kernel Configuration +# Linux/arm64 5.14.6 Kernel Configuration # CONFIG_CC_VERSION_TEXT="aarch64-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)) 8.3.0" CONFIG_CC_IS_GCC=y @@ -1427,7 +1427,6 @@ CONFIG_BRIDGE_VLAN_FILTERING=y CONFIG_BRIDGE_MRP=y # CONFIG_BRIDGE_CFM is not set CONFIG_NET_DSA=m -CONFIG_NET_DSA_TAG_8021Q=m CONFIG_NET_DSA_TAG_AR9331=m CONFIG_NET_DSA_TAG_BRCM_COMMON=m CONFIG_NET_DSA_TAG_BRCM=m @@ -5997,6 +5996,7 @@ CONFIG_VIDEO_SUNXI_CEDRUS=m # CONFIG_LTE_GDM724X is not set # CONFIG_GS_FPGABOOT is not set # CONFIG_UNISYSSPAR is not set +CONFIG_COMMON_CLK_XLNX_CLKWZRD=m CONFIG_FB_TFT=m CONFIG_FB_TFT_AGM1264K_FL=m CONFIG_FB_TFT_BD663474=m diff --git a/patch/kernel/archive/sunxi-5.14/patch-5.14.1-2.patch b/patch/kernel/archive/sunxi-5.14/patch-5.14.1-2.patch deleted file mode 100644 index be5d674cf1..0000000000 --- a/patch/kernel/archive/sunxi-5.14/patch-5.14.1-2.patch +++ /dev/null @@ -1,336 +0,0 @@ -diff --git a/Makefile b/Makefile -index 83d1f7c1fd304..9a2b00ecc6af4 100644 ---- a/Makefile -+++ b/Makefile -@@ -1,7 +1,7 @@ - # SPDX-License-Identifier: GPL-2.0 - VERSION = 5 - PATCHLEVEL = 14 --SUBLEVEL = 1 -+SUBLEVEL = 2 - EXTRAVERSION = - NAME = Opossums on Parade - -diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig -index 3878880469d10..b843902ad9fd7 100644 ---- a/arch/xtensa/Kconfig -+++ b/arch/xtensa/Kconfig -@@ -30,7 +30,7 @@ config XTENSA - select HAVE_DMA_CONTIGUOUS - select HAVE_EXIT_THREAD - select HAVE_FUNCTION_TRACER -- select HAVE_FUTEX_CMPXCHG if !MMU -+ select HAVE_FUTEX_CMPXCHG if !MMU && FUTEX - select HAVE_HW_BREAKPOINT if PERF_EVENTS - select HAVE_IRQ_TIME_ACCOUNTING - select HAVE_PCI -diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c -index 06130dc431a04..b234958f883a4 100644 ---- a/drivers/hid/usbhid/hid-core.c -+++ b/drivers/hid/usbhid/hid-core.c -@@ -377,27 +377,27 @@ static int hid_submit_ctrl(struct hid_device *hid) - len = hid_report_len(report); - if (dir == USB_DIR_OUT) { - usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); -- usbhid->urbctrl->transfer_buffer_length = len; - if (raw_report) { - memcpy(usbhid->ctrlbuf, raw_report, len); - kfree(raw_report); - usbhid->ctrl[usbhid->ctrltail].raw_report = NULL; - } - } else { -- int maxpacket, padlen; -+ int maxpacket; - - usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0); - maxpacket = usb_maxpacket(hid_to_usb_dev(hid), - usbhid->urbctrl->pipe, 0); - if (maxpacket > 0) { -- padlen = DIV_ROUND_UP(len, maxpacket); -- padlen *= maxpacket; -- if (padlen > usbhid->bufsize) -- padlen = usbhid->bufsize; -+ len += (len == 0); /* Don't allow 0-length reports */ -+ len = DIV_ROUND_UP(len, maxpacket); -+ len *= maxpacket; -+ if (len > usbhid->bufsize) -+ len = usbhid->bufsize; - } else -- padlen = 0; -- usbhid->urbctrl->transfer_buffer_length = padlen; -+ len = 0; - } -+ usbhid->urbctrl->transfer_buffer_length = len; - usbhid->urbctrl->dev = hid_to_usb_dev(hid); - - usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; -diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c -index a45d464427c4c..0e231e576dc3d 100644 ---- a/drivers/media/usb/stkwebcam/stk-webcam.c -+++ b/drivers/media/usb/stkwebcam/stk-webcam.c -@@ -1346,7 +1346,7 @@ static int stk_camera_probe(struct usb_interface *interface, - if (!dev->isoc_ep) { - pr_err("Could not find isoc-in endpoint\n"); - err = -ENODEV; -- goto error; -+ goto error_put; - } - dev->vsettings.palette = V4L2_PIX_FMT_RGB565; - dev->vsettings.mode = MODE_VGA; -@@ -1359,10 +1359,12 @@ static int stk_camera_probe(struct usb_interface *interface, - - err = stk_register_video_device(dev); - if (err) -- goto error; -+ goto error_put; - - return 0; - -+error_put: -+ usb_put_intf(interface); - error: - v4l2_ctrl_handler_free(hdl); - v4l2_device_unregister(&dev->v4l2_dev); -diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c -index 3c80bfbf3bec9..d48bed5782a5c 100644 ---- a/drivers/usb/serial/cp210x.c -+++ b/drivers/usb/serial/cp210x.c -@@ -1164,10 +1164,8 @@ static int cp210x_set_chars(struct usb_serial_port *port, - - kfree(dmabuf); - -- if (result < 0) { -- dev_err(&port->dev, "failed to set special chars: %d\n", result); -+ if (result < 0) - return result; -- } - - return 0; - } -@@ -1192,6 +1190,7 @@ static void cp210x_set_flow_control(struct tty_struct *tty, - struct cp210x_flow_ctl flow_ctl; - u32 flow_repl; - u32 ctl_hs; -+ bool crtscts; - int ret; - - /* -@@ -1219,8 +1218,10 @@ static void cp210x_set_flow_control(struct tty_struct *tty, - chars.bXoffChar = STOP_CHAR(tty); - - ret = cp210x_set_chars(port, &chars); -- if (ret) -- return; -+ if (ret) { -+ dev_err(&port->dev, "failed to set special chars: %d\n", -+ ret); -+ } - } - - mutex_lock(&port_priv->mutex); -@@ -1249,14 +1250,14 @@ static void cp210x_set_flow_control(struct tty_struct *tty, - flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; - else - flow_repl |= CP210X_SERIAL_RTS_INACTIVE; -- port_priv->crtscts = true; -+ crtscts = true; - } else { - ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; - if (port_priv->rts) - flow_repl |= CP210X_SERIAL_RTS_ACTIVE; - else - flow_repl |= CP210X_SERIAL_RTS_INACTIVE; -- port_priv->crtscts = false; -+ crtscts = false; - } - - if (I_IXOFF(tty)) { -@@ -1279,8 +1280,12 @@ static void cp210x_set_flow_control(struct tty_struct *tty, - flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); - flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); - -- cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, -+ ret = cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, - sizeof(flow_ctl)); -+ if (ret) -+ goto out_unlock; -+ -+ port_priv->crtscts = crtscts; - out_unlock: - mutex_unlock(&port_priv->mutex); - } -diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c -index 930b3d50a3308..f45ca7ddf78ea 100644 ---- a/drivers/usb/serial/pl2303.c -+++ b/drivers/usb/serial/pl2303.c -@@ -433,6 +433,7 @@ static int pl2303_detect_type(struct usb_serial *serial) - switch (bcdDevice) { - case 0x100: - case 0x305: -+ case 0x405: - /* - * Assume it's an HXN-type if the device doesn't - * support the old read request value. -diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c -index 70cb64db33f73..24e994e75f5ca 100644 ---- a/fs/ext4/inline.c -+++ b/fs/ext4/inline.c -@@ -750,6 +750,12 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, - ext4_write_lock_xattr(inode, &no_expand); - BUG_ON(!ext4_has_inline_data(inode)); - -+ /* -+ * ei->i_inline_off may have changed since ext4_write_begin() -+ * called ext4_try_to_write_inline_data() -+ */ -+ (void) ext4_find_inline_data_nolock(inode); -+ - kaddr = kmap_atomic(page); - ext4_write_inline_data(inode, &iloc, kaddr, pos, len); - kunmap_atomic(kaddr); -diff --git a/fs/ext4/super.c b/fs/ext4/super.c -index dfa09a277b56f..970013c93d3ea 100644 ---- a/fs/ext4/super.c -+++ b/fs/ext4/super.c -@@ -5032,6 +5032,14 @@ no_journal: - err = percpu_counter_init(&sbi->s_freeinodes_counter, freei, - GFP_KERNEL); - } -+ /* -+ * Update the checksum after updating free space/inode -+ * counters. Otherwise the superblock can have an incorrect -+ * checksum in the buffer cache until it is written out and -+ * e2fsprogs programs trying to open a file system immediately -+ * after it is mounted can fail. -+ */ -+ ext4_superblock_csum_set(sb); - if (!err) - err = percpu_counter_init(&sbi->s_dirs_counter, - ext4_count_dirs(sb), GFP_KERNEL); -diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c -index 7d5883432085a..a144a3f68e9eb 100644 ---- a/sound/core/pcm_lib.c -+++ b/sound/core/pcm_lib.c -@@ -1746,7 +1746,7 @@ static int snd_pcm_lib_ioctl_fifo_size(struct snd_pcm_substream *substream, - channels = params_channels(params); - frame_size = snd_pcm_format_size(format, channels); - if (frame_size > 0) -- params->fifo_size /= (unsigned)frame_size; -+ params->fifo_size /= frame_size; - } - return 0; - } -diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c -index 7ad689f991e7e..70516527ebce3 100644 ---- a/sound/pci/hda/patch_realtek.c -+++ b/sound/pci/hda/patch_realtek.c -@@ -8438,6 +8438,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { - SND_PCI_QUIRK(0x103c, 0x87f2, "HP ProBook 640 G8 Notebook PC", ALC236_FIXUP_HP_GPIO_LED), - SND_PCI_QUIRK(0x103c, 0x87f4, "HP", ALC287_FIXUP_HP_GPIO_LED), - SND_PCI_QUIRK(0x103c, 0x87f5, "HP", ALC287_FIXUP_HP_GPIO_LED), -+ SND_PCI_QUIRK(0x103c, 0x87f6, "HP Spectre x360 14", ALC245_FIXUP_HP_X360_AMP), - SND_PCI_QUIRK(0x103c, 0x87f7, "HP Spectre x360 14", ALC245_FIXUP_HP_X360_AMP), - SND_PCI_QUIRK(0x103c, 0x8805, "HP ProBook 650 G8 Notebook PC", ALC236_FIXUP_HP_GPIO_LED), - SND_PCI_QUIRK(0x103c, 0x880d, "HP EliteBook 830 G8 Notebook PC", ALC285_FIXUP_HP_GPIO_LED), -@@ -9521,6 +9522,16 @@ static int patch_alc269(struct hda_codec *codec) - - snd_hda_pick_fixup(codec, alc269_fixup_models, - alc269_fixup_tbl, alc269_fixups); -+ /* FIXME: both TX300 and ROG Strix G17 have the same SSID, and -+ * the quirk breaks the latter (bko#214101). -+ * Clear the wrong entry. -+ */ -+ if (codec->fixup_id == ALC282_FIXUP_ASUS_TX300 && -+ codec->core.vendor_id == 0x10ec0294) { -+ codec_dbg(codec, "Clear wrong fixup for ASUS ROG Strix G17\n"); -+ codec->fixup_id = HDA_FIXUP_ID_NOT_SET; -+ } -+ - snd_hda_pick_pin_fixup(codec, alc269_pin_fixup_tbl, alc269_fixups, true); - snd_hda_pick_pin_fixup(codec, alc269_fallback_pin_fixup_tbl, alc269_fixups, false); - snd_hda_pick_fixup(codec, NULL, alc269_fixup_vendor_tbl, -diff --git a/sound/usb/card.h b/sound/usb/card.h -index 6c0a052a28f99..5b19901f305a3 100644 ---- a/sound/usb/card.h -+++ b/sound/usb/card.h -@@ -94,6 +94,7 @@ struct snd_usb_endpoint { - struct list_head ready_playback_urbs; /* playback URB FIFO for implicit fb */ - - unsigned int nurbs; /* # urbs */ -+ unsigned int nominal_queue_size; /* total buffer sizes in URBs */ - unsigned long active_mask; /* bitmask of active urbs */ - unsigned long unlink_mask; /* bitmask of unlinked urbs */ - char *syncbuf; /* sync buffer for all sync URBs */ -@@ -187,6 +188,7 @@ struct snd_usb_substream { - } dsd_dop; - - bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */ -+ bool early_playback_start; /* early start needed for playback? */ - struct media_ctl *media_ctl; - }; - -diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c -index 4f856771216b4..bf26c04cf4716 100644 ---- a/sound/usb/endpoint.c -+++ b/sound/usb/endpoint.c -@@ -1126,6 +1126,10 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep) - INIT_LIST_HEAD(&u->ready_list); - } - -+ /* total buffer bytes of all URBs plus the next queue; -+ * referred in pcm.c -+ */ -+ ep->nominal_queue_size = maxsize * urb_packs * (ep->nurbs + 1); - return 0; - - out_of_memory: -@@ -1287,6 +1291,11 @@ int snd_usb_endpoint_configure(struct snd_usb_audio *chip, - * to be set up before parameter setups - */ - iface_first = ep->cur_audiofmt->protocol == UAC_VERSION_1; -+ /* Workaround for Sony WALKMAN NW-A45 DAC; -+ * it requires the interface setup at first like UAC1 -+ */ -+ if (chip->usb_id == USB_ID(0x054c, 0x0b8c)) -+ iface_first = true; - if (iface_first) { - err = endpoint_set_interface(chip, ep, true); - if (err < 0) -diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c -index 4e5031a680647..f5cbf61ac366e 100644 ---- a/sound/usb/pcm.c -+++ b/sound/usb/pcm.c -@@ -614,6 +614,14 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) - subs->period_elapsed_pending = 0; - runtime->delay = 0; - -+ /* check whether early start is needed for playback stream */ -+ subs->early_playback_start = -+ subs->direction == SNDRV_PCM_STREAM_PLAYBACK && -+ subs->data_endpoint->nominal_queue_size >= subs->buffer_bytes; -+ -+ if (subs->early_playback_start) -+ ret = start_endpoints(subs); -+ - unlock: - snd_usb_unlock_shutdown(chip); - return ret; -@@ -1394,7 +1402,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs, - subs->trigger_tstamp_pending_update = false; - } - -- if (period_elapsed && !subs->running) { -+ if (period_elapsed && !subs->running && !subs->early_playback_start) { - subs->period_elapsed_pending = 1; - period_elapsed = 0; - } -@@ -1448,7 +1456,8 @@ static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substrea - prepare_playback_urb, - retire_playback_urb, - subs); -- if (cmd == SNDRV_PCM_TRIGGER_START) { -+ if (!subs->early_playback_start && -+ cmd == SNDRV_PCM_TRIGGER_START) { - err = start_endpoints(subs); - if (err < 0) { - snd_usb_endpoint_set_callback(subs->data_endpoint, diff --git a/patch/kernel/archive/sunxi-5.14/patch-5.14.5-6.patch b/patch/kernel/archive/sunxi-5.14/patch-5.14.5-6.patch new file mode 100644 index 0000000000..657c7b3f8e --- /dev/null +++ b/patch/kernel/archive/sunxi-5.14/patch-5.14.5-6.patch @@ -0,0 +1,19126 @@ +diff --git a/Documentation/admin-guide/devices.txt b/Documentation/admin-guide/devices.txt +index 9c2be821c2254..922c23bb4372a 100644 +--- a/Documentation/admin-guide/devices.txt ++++ b/Documentation/admin-guide/devices.txt +@@ -2993,10 +2993,10 @@ + 65 = /dev/infiniband/issm1 Second InfiniBand IsSM device + ... + 127 = /dev/infiniband/issm63 63rd InfiniBand IsSM device +- 128 = /dev/infiniband/uverbs0 First InfiniBand verbs device +- 129 = /dev/infiniband/uverbs1 Second InfiniBand verbs device ++ 192 = /dev/infiniband/uverbs0 First InfiniBand verbs device ++ 193 = /dev/infiniband/uverbs1 Second InfiniBand verbs device + ... +- 159 = /dev/infiniband/uverbs31 31st InfiniBand verbs device ++ 223 = /dev/infiniband/uverbs31 31st InfiniBand verbs device + + 232 char Biometric Devices + 0 = /dev/biometric/sensor0/fingerprint first fingerprint sensor on first device +diff --git a/Documentation/devicetree/bindings/display/panel/samsung,lms397kf04.yaml b/Documentation/devicetree/bindings/display/panel/samsung,lms397kf04.yaml +index 4cb75a5f2e3a2..cd62968426fb5 100644 +--- a/Documentation/devicetree/bindings/display/panel/samsung,lms397kf04.yaml ++++ b/Documentation/devicetree/bindings/display/panel/samsung,lms397kf04.yaml +@@ -33,8 +33,11 @@ properties: + + backlight: true + ++ spi-cpha: true ++ ++ spi-cpol: true ++ + spi-max-frequency: +- $ref: /schemas/types.yaml#/definitions/uint32 + description: inherited as a SPI client node, the datasheet specifies + maximum 300 ns minimum cycle which gives around 3 MHz max frequency + maximum: 3000000 +@@ -44,6 +47,9 @@ properties: + required: + - compatible + - reg ++ - spi-cpha ++ - spi-cpol ++ - port + + additionalProperties: false + +@@ -52,15 +58,23 @@ examples: + #include + + spi { ++ compatible = "spi-gpio"; ++ sck-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>; ++ miso-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>; ++ mosi-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>; ++ cs-gpios = <&gpio 3 GPIO_ACTIVE_HIGH>; ++ num-chipselects = <1>; + #address-cells = <1>; + #size-cells = <0>; + panel@0 { + compatible = "samsung,lms397kf04"; + spi-max-frequency = <3000000>; ++ spi-cpha; ++ spi-cpol; + reg = <0>; + vci-supply = <&lcd_3v0_reg>; + vccio-supply = <&lcd_1v8_reg>; +- reset-gpios = <&gpio 1 GPIO_ACTIVE_LOW>; ++ reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; + backlight = <&ktd259>; + + port { +diff --git a/Documentation/devicetree/bindings/pinctrl/marvell,armada-37xx-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/marvell,armada-37xx-pinctrl.txt +index 38dc56a577604..ecec514b31550 100644 +--- a/Documentation/devicetree/bindings/pinctrl/marvell,armada-37xx-pinctrl.txt ++++ b/Documentation/devicetree/bindings/pinctrl/marvell,armada-37xx-pinctrl.txt +@@ -43,19 +43,19 @@ group emmc_nb + + group pwm0 + - pin 11 (GPIO1-11) +- - functions pwm, gpio ++ - functions pwm, led, gpio + + group pwm1 + - pin 12 +- - functions pwm, gpio ++ - functions pwm, led, gpio + + group pwm2 + - pin 13 +- - functions pwm, gpio ++ - functions pwm, led, gpio + + group pwm3 + - pin 14 +- - functions pwm, gpio ++ - functions pwm, led, gpio + + group pmic1 + - pin 7 +diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst +index ff9e7cc97c65a..b5285599d9725 100644 +--- a/Documentation/filesystems/f2fs.rst ++++ b/Documentation/filesystems/f2fs.rst +@@ -185,6 +185,7 @@ fault_type=%d Support configuring fault injection type, should be + FAULT_KVMALLOC 0x000000002 + FAULT_PAGE_ALLOC 0x000000004 + FAULT_PAGE_GET 0x000000008 ++ FAULT_ALLOC_BIO 0x000000010 (obsolete) + FAULT_ALLOC_NID 0x000000020 + FAULT_ORPHAN 0x000000040 + FAULT_BLOCK 0x000000080 +diff --git a/Makefile b/Makefile +index 0eaa5623f4060..f9c8bbf8cf71e 100644 +--- a/Makefile ++++ b/Makefile +@@ -1,7 +1,7 @@ + # SPDX-License-Identifier: GPL-2.0 + VERSION = 5 + PATCHLEVEL = 14 +-SUBLEVEL = 5 ++SUBLEVEL = 6 + EXTRAVERSION = + NAME = Opossums on Parade + +@@ -404,6 +404,11 @@ ifeq ($(ARCH),sparc64) + SRCARCH := sparc + endif + ++# Additional ARCH settings for parisc ++ifeq ($(ARCH),parisc64) ++ SRCARCH := parisc ++endif ++ + export cross_compiling := + ifneq ($(SRCARCH),$(SUBARCH)) + cross_compiling := 1 +@@ -803,6 +808,8 @@ else + # Disabled for clang while comment to attribute conversion happens and + # https://github.com/ClangBuiltLinux/linux/issues/636 is discussed. + KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,) ++# gcc inanely warns about local variables called 'main' ++KBUILD_CFLAGS += -Wno-main + endif + + # These warnings generated too much noise in a regular build. +diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile +index 9d91ae1091b0b..91265e7ff672f 100644 +--- a/arch/arm/boot/compressed/Makefile ++++ b/arch/arm/boot/compressed/Makefile +@@ -85,6 +85,8 @@ compress-$(CONFIG_KERNEL_LZ4) = lz4 + libfdt_objs := fdt_rw.o fdt_ro.o fdt_wip.o fdt.o + + ifeq ($(CONFIG_ARM_ATAG_DTB_COMPAT),y) ++CFLAGS_REMOVE_atags_to_fdt.o += -Wframe-larger-than=${CONFIG_FRAME_WARN} ++CFLAGS_atags_to_fdt.o += -Wframe-larger-than=1280 + OBJS += $(libfdt_objs) atags_to_fdt.o + endif + ifeq ($(CONFIG_USE_OF),y) +diff --git a/arch/arm/boot/dts/at91-kizbox3_common.dtsi b/arch/arm/boot/dts/at91-kizbox3_common.dtsi +index c4b3750495da8..abe27adfa4d65 100644 +--- a/arch/arm/boot/dts/at91-kizbox3_common.dtsi ++++ b/arch/arm/boot/dts/at91-kizbox3_common.dtsi +@@ -336,7 +336,7 @@ + }; + + &shutdown_controller { +- atmel,shdwc-debouncer = <976>; ++ debounce-delay-us = <976>; + atmel,wakeup-rtc-timer; + + input@0 { +diff --git a/arch/arm/boot/dts/at91-sam9x60ek.dts b/arch/arm/boot/dts/at91-sam9x60ek.dts +index ebbc9b23aef1c..b1068cca42287 100644 +--- a/arch/arm/boot/dts/at91-sam9x60ek.dts ++++ b/arch/arm/boot/dts/at91-sam9x60ek.dts +@@ -662,7 +662,7 @@ + }; + + &shutdown_controller { +- atmel,shdwc-debouncer = <976>; ++ debounce-delay-us = <976>; + status = "okay"; + + input@0 { +diff --git a/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts b/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts +index a9e6fee55a2a8..8034e5dacc808 100644 +--- a/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts ++++ b/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts +@@ -138,7 +138,7 @@ + }; + + shdwc@f8048010 { +- atmel,shdwc-debouncer = <976>; ++ debounce-delay-us = <976>; + atmel,wakeup-rtc-timer; + + input@0 { +diff --git a/arch/arm/boot/dts/at91-sama5d27_wlsom1_ek.dts b/arch/arm/boot/dts/at91-sama5d27_wlsom1_ek.dts +index ff83967fd0082..c145c4e5ef582 100644 +--- a/arch/arm/boot/dts/at91-sama5d27_wlsom1_ek.dts ++++ b/arch/arm/boot/dts/at91-sama5d27_wlsom1_ek.dts +@@ -205,7 +205,7 @@ + }; + + &shutdown_controller { +- atmel,shdwc-debouncer = <976>; ++ debounce-delay-us = <976>; + atmel,wakeup-rtc-timer; + + input@0 { +diff --git a/arch/arm/boot/dts/at91-sama5d2_icp.dts b/arch/arm/boot/dts/at91-sama5d2_icp.dts +index bd64721fa23ca..34faca597c352 100644 +--- a/arch/arm/boot/dts/at91-sama5d2_icp.dts ++++ b/arch/arm/boot/dts/at91-sama5d2_icp.dts +@@ -693,7 +693,7 @@ + }; + + &shutdown_controller { +- atmel,shdwc-debouncer = <976>; ++ debounce-delay-us = <976>; + atmel,wakeup-rtc-timer; + + input@0 { +diff --git a/arch/arm/boot/dts/at91-sama5d2_ptc_ek.dts b/arch/arm/boot/dts/at91-sama5d2_ptc_ek.dts +index dfd150eb0fd86..3f972a4086c37 100644 +--- a/arch/arm/boot/dts/at91-sama5d2_ptc_ek.dts ++++ b/arch/arm/boot/dts/at91-sama5d2_ptc_ek.dts +@@ -203,7 +203,7 @@ + }; + + shdwc@f8048010 { +- atmel,shdwc-debouncer = <976>; ++ debounce-delay-us = <976>; + + input@0 { + reg = <0>; +diff --git a/arch/arm/boot/dts/at91-sama5d2_xplained.dts b/arch/arm/boot/dts/at91-sama5d2_xplained.dts +index 509c732a0d8b4..627b7bf88d83b 100644 +--- a/arch/arm/boot/dts/at91-sama5d2_xplained.dts ++++ b/arch/arm/boot/dts/at91-sama5d2_xplained.dts +@@ -347,7 +347,7 @@ + }; + + shdwc@f8048010 { +- atmel,shdwc-debouncer = <976>; ++ debounce-delay-us = <976>; + atmel,wakeup-rtc-timer; + + input@0 { +diff --git a/arch/arm/boot/dts/imx53-ppd.dts b/arch/arm/boot/dts/imx53-ppd.dts +index 5a5fa6190a528..37d0cffea99c5 100644 +--- a/arch/arm/boot/dts/imx53-ppd.dts ++++ b/arch/arm/boot/dts/imx53-ppd.dts +@@ -70,6 +70,12 @@ + clock-frequency = <11289600>; + }; + ++ achc_24M: achc-clock { ++ compatible = "fixed-clock"; ++ #clock-cells = <0>; ++ clock-frequency = <24000000>; ++ }; ++ + sgtlsound: sound { + compatible = "fsl,imx53-cpuvo-sgtl5000", + "fsl,imx-audio-sgtl5000"; +@@ -314,16 +320,13 @@ + &gpio4 12 GPIO_ACTIVE_LOW>; + status = "okay"; + +- spidev0: spi@0 { +- compatible = "ge,achc"; +- reg = <0>; +- spi-max-frequency = <1000000>; +- }; +- +- spidev1: spi@1 { +- compatible = "ge,achc"; +- reg = <1>; +- spi-max-frequency = <1000000>; ++ spidev0: spi@1 { ++ compatible = "ge,achc", "nxp,kinetis-k20"; ++ reg = <1>, <0>; ++ vdd-supply = <®_3v3>; ++ vdda-supply = <®_3v3>; ++ clocks = <&achc_24M>; ++ reset-gpios = <&gpio3 6 GPIO_ACTIVE_LOW>; + }; + + gpioxra0: gpio@2 { +diff --git a/arch/arm/boot/dts/intel-ixp42x-linksys-nslu2.dts b/arch/arm/boot/dts/intel-ixp42x-linksys-nslu2.dts +index 5b8dcc19deeef..b9a5268fe7ad6 100644 +--- a/arch/arm/boot/dts/intel-ixp42x-linksys-nslu2.dts ++++ b/arch/arm/boot/dts/intel-ixp42x-linksys-nslu2.dts +@@ -124,20 +124,20 @@ + */ + interrupt-map = + /* IDSEL 1 */ +- <0x0800 0 0 1 &gpio0 11 3>, /* INT A on slot 1 is irq 11 */ +- <0x0800 0 0 2 &gpio0 10 3>, /* INT B on slot 1 is irq 10 */ +- <0x0800 0 0 3 &gpio0 9 3>, /* INT C on slot 1 is irq 9 */ +- <0x0800 0 0 4 &gpio0 8 3>, /* INT D on slot 1 is irq 8 */ ++ <0x0800 0 0 1 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 1 is irq 11 */ ++ <0x0800 0 0 2 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 1 is irq 10 */ ++ <0x0800 0 0 3 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 1 is irq 9 */ ++ <0x0800 0 0 4 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT D on slot 1 is irq 8 */ + /* IDSEL 2 */ +- <0x1000 0 0 1 &gpio0 10 3>, /* INT A on slot 2 is irq 10 */ +- <0x1000 0 0 2 &gpio0 9 3>, /* INT B on slot 2 is irq 9 */ +- <0x1000 0 0 3 &gpio0 11 3>, /* INT C on slot 2 is irq 11 */ +- <0x1000 0 0 4 &gpio0 8 3>, /* INT D on slot 2 is irq 8 */ ++ <0x1000 0 0 1 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 2 is irq 10 */ ++ <0x1000 0 0 2 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 2 is irq 9 */ ++ <0x1000 0 0 3 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 2 is irq 11 */ ++ <0x1000 0 0 4 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT D on slot 2 is irq 8 */ + /* IDSEL 3 */ +- <0x1800 0 0 1 &gpio0 9 3>, /* INT A on slot 3 is irq 9 */ +- <0x1800 0 0 2 &gpio0 11 3>, /* INT B on slot 3 is irq 11 */ +- <0x1800 0 0 3 &gpio0 10 3>, /* INT C on slot 3 is irq 10 */ +- <0x1800 0 0 4 &gpio0 8 3>; /* INT D on slot 3 is irq 8 */ ++ <0x1800 0 0 1 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 3 is irq 9 */ ++ <0x1800 0 0 2 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 3 is irq 11 */ ++ <0x1800 0 0 3 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 3 is irq 10 */ ++ <0x1800 0 0 4 &gpio0 8 IRQ_TYPE_LEVEL_LOW>; /* INT D on slot 3 is irq 8 */ + }; + + ethernet@c8009000 { +diff --git a/arch/arm/boot/dts/intel-ixp43x-gateworks-gw2358.dts b/arch/arm/boot/dts/intel-ixp43x-gateworks-gw2358.dts +index 60a1228a970fc..f5fe309f7762d 100644 +--- a/arch/arm/boot/dts/intel-ixp43x-gateworks-gw2358.dts ++++ b/arch/arm/boot/dts/intel-ixp43x-gateworks-gw2358.dts +@@ -108,35 +108,35 @@ + */ + interrupt-map = + /* IDSEL 1 */ +- <0x0800 0 0 1 &gpio0 11 3>, /* INT A on slot 1 is irq 11 */ +- <0x0800 0 0 2 &gpio0 10 3>, /* INT B on slot 1 is irq 10 */ +- <0x0800 0 0 3 &gpio0 9 3>, /* INT C on slot 1 is irq 9 */ +- <0x0800 0 0 4 &gpio0 8 3>, /* INT D on slot 1 is irq 8 */ ++ <0x0800 0 0 1 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 1 is irq 11 */ ++ <0x0800 0 0 2 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 1 is irq 10 */ ++ <0x0800 0 0 3 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 1 is irq 9 */ ++ <0x0800 0 0 4 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT D on slot 1 is irq 8 */ + /* IDSEL 2 */ +- <0x1000 0 0 1 &gpio0 10 3>, /* INT A on slot 2 is irq 10 */ +- <0x1000 0 0 2 &gpio0 9 3>, /* INT B on slot 2 is irq 9 */ +- <0x1000 0 0 3 &gpio0 8 3>, /* INT C on slot 2 is irq 8 */ +- <0x1000 0 0 4 &gpio0 11 3>, /* INT D on slot 2 is irq 11 */ ++ <0x1000 0 0 1 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 2 is irq 10 */ ++ <0x1000 0 0 2 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 2 is irq 9 */ ++ <0x1000 0 0 3 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 2 is irq 8 */ ++ <0x1000 0 0 4 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT D on slot 2 is irq 11 */ + /* IDSEL 3 */ +- <0x1800 0 0 1 &gpio0 9 3>, /* INT A on slot 3 is irq 9 */ +- <0x1800 0 0 2 &gpio0 8 3>, /* INT B on slot 3 is irq 8 */ +- <0x1800 0 0 3 &gpio0 11 3>, /* INT C on slot 3 is irq 11 */ +- <0x1800 0 0 4 &gpio0 10 3>, /* INT D on slot 3 is irq 10 */ ++ <0x1800 0 0 1 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 3 is irq 9 */ ++ <0x1800 0 0 2 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 3 is irq 8 */ ++ <0x1800 0 0 3 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 3 is irq 11 */ ++ <0x1800 0 0 4 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT D on slot 3 is irq 10 */ + /* IDSEL 4 */ +- <0x2000 0 0 1 &gpio0 8 3>, /* INT A on slot 3 is irq 8 */ +- <0x2000 0 0 2 &gpio0 11 3>, /* INT B on slot 3 is irq 11 */ +- <0x2000 0 0 3 &gpio0 10 3>, /* INT C on slot 3 is irq 10 */ +- <0x2000 0 0 4 &gpio0 9 3>, /* INT D on slot 3 is irq 9 */ ++ <0x2000 0 0 1 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 3 is irq 8 */ ++ <0x2000 0 0 2 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 3 is irq 11 */ ++ <0x2000 0 0 3 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 3 is irq 10 */ ++ <0x2000 0 0 4 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT D on slot 3 is irq 9 */ + /* IDSEL 6 */ +- <0x3000 0 0 1 &gpio0 10 3>, /* INT A on slot 3 is irq 10 */ +- <0x3000 0 0 2 &gpio0 9 3>, /* INT B on slot 3 is irq 9 */ +- <0x3000 0 0 3 &gpio0 8 3>, /* INT C on slot 3 is irq 8 */ +- <0x3000 0 0 4 &gpio0 11 3>, /* INT D on slot 3 is irq 11 */ ++ <0x3000 0 0 1 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 3 is irq 10 */ ++ <0x3000 0 0 2 &gpio0 9 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 3 is irq 9 */ ++ <0x3000 0 0 3 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 3 is irq 8 */ ++ <0x3000 0 0 4 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT D on slot 3 is irq 11 */ + /* IDSEL 15 */ +- <0x7800 0 0 1 &gpio0 8 3>, /* INT A on slot 3 is irq 8 */ +- <0x7800 0 0 2 &gpio0 11 3>, /* INT B on slot 3 is irq 11 */ +- <0x7800 0 0 3 &gpio0 10 3>, /* INT C on slot 3 is irq 10 */ +- <0x7800 0 0 4 &gpio0 9 3>; /* INT D on slot 3 is irq 9 */ ++ <0x7800 0 0 1 &gpio0 8 IRQ_TYPE_LEVEL_LOW>, /* INT A on slot 3 is irq 8 */ ++ <0x7800 0 0 2 &gpio0 11 IRQ_TYPE_LEVEL_LOW>, /* INT B on slot 3 is irq 11 */ ++ <0x7800 0 0 3 &gpio0 10 IRQ_TYPE_LEVEL_LOW>, /* INT C on slot 3 is irq 10 */ ++ <0x7800 0 0 4 &gpio0 9 IRQ_TYPE_LEVEL_LOW>; /* INT D on slot 3 is irq 9 */ + }; + + ethernet@c800a000 { +diff --git a/arch/arm/boot/dts/qcom-apq8064.dtsi b/arch/arm/boot/dts/qcom-apq8064.dtsi +index 2687c4e890ba8..e36d590e83732 100644 +--- a/arch/arm/boot/dts/qcom-apq8064.dtsi ++++ b/arch/arm/boot/dts/qcom-apq8064.dtsi +@@ -1262,9 +1262,9 @@ + <&mmcc DSI1_BYTE_CLK>, + <&mmcc DSI_PIXEL_CLK>, + <&mmcc DSI1_ESC_CLK>; +- clock-names = "iface_clk", "bus_clk", "core_mmss_clk", +- "src_clk", "byte_clk", "pixel_clk", +- "core_clk"; ++ clock-names = "iface", "bus", "core_mmss", ++ "src", "byte", "pixel", ++ "core"; + + assigned-clocks = <&mmcc DSI1_BYTE_SRC>, + <&mmcc DSI1_ESC_SRC>, +diff --git a/arch/arm/boot/dts/stm32mp15xx-dhcom-pdk2.dtsi b/arch/arm/boot/dts/stm32mp15xx-dhcom-pdk2.dtsi +index 6cf1c8b4c6e28..c9577ba2973d3 100644 +--- a/arch/arm/boot/dts/stm32mp15xx-dhcom-pdk2.dtsi ++++ b/arch/arm/boot/dts/stm32mp15xx-dhcom-pdk2.dtsi +@@ -172,15 +172,15 @@ + sgtl5000_tx_endpoint: endpoint@0 { + reg = <0>; + remote-endpoint = <&sai2a_endpoint>; +- frame-master; +- bitclock-master; ++ frame-master = <&sgtl5000_tx_endpoint>; ++ bitclock-master = <&sgtl5000_tx_endpoint>; + }; + + sgtl5000_rx_endpoint: endpoint@1 { + reg = <1>; + remote-endpoint = <&sai2b_endpoint>; +- frame-master; +- bitclock-master; ++ frame-master = <&sgtl5000_rx_endpoint>; ++ bitclock-master = <&sgtl5000_rx_endpoint>; + }; + }; + +diff --git a/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi b/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi +index 64dca5b7f748d..6885948f3024e 100644 +--- a/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi ++++ b/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi +@@ -220,8 +220,8 @@ + &i2c4 { + hdmi-transmitter@3d { + compatible = "adi,adv7513"; +- reg = <0x3d>, <0x2d>, <0x4d>, <0x5d>; +- reg-names = "main", "cec", "edid", "packet"; ++ reg = <0x3d>, <0x4d>, <0x2d>, <0x5d>; ++ reg-names = "main", "edid", "cec", "packet"; + clocks = <&cec_clock>; + clock-names = "cec"; + +@@ -239,8 +239,6 @@ + adi,input-depth = <8>; + adi,input-colorspace = "rgb"; + adi,input-clock = "1x"; +- adi,input-style = <1>; +- adi,input-justification = "evenly"; + + ports { + #address-cells = <1>; +diff --git a/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi b/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi +index 59f18846cf5d0..586aac8a998c0 100644 +--- a/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi ++++ b/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi +@@ -220,15 +220,15 @@ + cs42l51_tx_endpoint: endpoint@0 { + reg = <0>; + remote-endpoint = <&sai2a_endpoint>; +- frame-master; +- bitclock-master; ++ frame-master = <&cs42l51_tx_endpoint>; ++ bitclock-master = <&cs42l51_tx_endpoint>; + }; + + cs42l51_rx_endpoint: endpoint@1 { + reg = <1>; + remote-endpoint = <&sai2b_endpoint>; +- frame-master; +- bitclock-master; ++ frame-master = <&cs42l51_rx_endpoint>; ++ bitclock-master = <&cs42l51_rx_endpoint>; + }; + }; + }; +diff --git a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts +index 1976c383912aa..05bd0add258c6 100644 +--- a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts ++++ b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts +@@ -719,7 +719,6 @@ + nvidia,xcvr-setup-use-fuses; + nvidia,xcvr-lsfslew = <2>; + nvidia,xcvr-lsrslew = <2>; +- vbus-supply = <&vdd_vbus1>; + }; + + usb@c5008000 { +@@ -731,7 +730,7 @@ + nvidia,xcvr-setup-use-fuses; + nvidia,xcvr-lsfslew = <2>; + nvidia,xcvr-lsrslew = <2>; +- vbus-supply = <&vdd_vbus3>; ++ vbus-supply = <&vdd_5v0_sys>; + }; + + brcm_wifi_pwrseq: wifi-pwrseq { +@@ -991,28 +990,6 @@ + vin-supply = <&vdd_5v0_sys>; + }; + +- vdd_vbus1: regulator@4 { +- compatible = "regulator-fixed"; +- regulator-name = "vdd_usb1_vbus"; +- regulator-min-microvolt = <5000000>; +- regulator-max-microvolt = <5000000>; +- regulator-always-on; +- gpio = <&gpio TEGRA_GPIO(D, 0) GPIO_ACTIVE_HIGH>; +- enable-active-high; +- vin-supply = <&vdd_5v0_sys>; +- }; +- +- vdd_vbus3: regulator@5 { +- compatible = "regulator-fixed"; +- regulator-name = "vdd_usb3_vbus"; +- regulator-min-microvolt = <5000000>; +- regulator-max-microvolt = <5000000>; +- regulator-always-on; +- gpio = <&gpio TEGRA_GPIO(D, 3) GPIO_ACTIVE_HIGH>; +- enable-active-high; +- vin-supply = <&vdd_5v0_sys>; +- }; +- + sound { + compatible = "nvidia,tegra-audio-wm8903-picasso", + "nvidia,tegra-audio-wm8903"; +diff --git a/arch/arm/boot/dts/tegra20-tamonten.dtsi b/arch/arm/boot/dts/tegra20-tamonten.dtsi +index 95e6bccdb4f6e..dd4d506683de7 100644 +--- a/arch/arm/boot/dts/tegra20-tamonten.dtsi ++++ b/arch/arm/boot/dts/tegra20-tamonten.dtsi +@@ -185,8 +185,9 @@ + nvidia,pins = "ata", "atb", "atc", "atd", "ate", + "cdev1", "cdev2", "dap1", "dtb", "gma", + "gmb", "gmc", "gmd", "gme", "gpu7", +- "gpv", "i2cp", "pta", "rm", "slxa", +- "slxk", "spia", "spib", "uac"; ++ "gpv", "i2cp", "irrx", "irtx", "pta", ++ "rm", "slxa", "slxk", "spia", "spib", ++ "uac"; + nvidia,pull = ; + nvidia,tristate = ; + }; +@@ -211,7 +212,7 @@ + conf_ddc { + nvidia,pins = "ddc", "dta", "dtd", "kbca", + "kbcb", "kbcc", "kbcd", "kbce", "kbcf", +- "sdc"; ++ "sdc", "uad", "uca"; + nvidia,pull = ; + nvidia,tristate = ; + }; +@@ -221,10 +222,9 @@ + "lvp0", "owc", "sdb"; + nvidia,tristate = ; + }; +- conf_irrx { +- nvidia,pins = "irrx", "irtx", "sdd", "spic", +- "spie", "spih", "uaa", "uab", "uad", +- "uca", "ucb"; ++ conf_sdd { ++ nvidia,pins = "sdd", "spic", "spie", "spih", ++ "uaa", "uab", "ucb"; + nvidia,pull = ; + nvidia,tristate = ; + }; +diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h6-tanix-tx6.dts b/arch/arm64/boot/dts/allwinner/sun50i-h6-tanix-tx6.dts +index be81330db14f6..02641191682e0 100644 +--- a/arch/arm64/boot/dts/allwinner/sun50i-h6-tanix-tx6.dts ++++ b/arch/arm64/boot/dts/allwinner/sun50i-h6-tanix-tx6.dts +@@ -32,14 +32,14 @@ + }; + }; + +- reg_vcc3v3: vcc3v3 { ++ reg_vcc3v3: regulator-vcc3v3 { + compatible = "regulator-fixed"; + regulator-name = "vcc3v3"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + }; + +- reg_vdd_cpu_gpu: vdd-cpu-gpu { ++ reg_vdd_cpu_gpu: regulator-vdd-cpu-gpu { + compatible = "regulator-fixed"; + regulator-name = "vdd-cpu-gpu"; + regulator-min-microvolt = <1135000>; +diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a-frwy.dts b/arch/arm64/boot/dts/freescale/fsl-ls1046a-frwy.dts +index db3d303093f61..6d22efbd645cb 100644 +--- a/arch/arm64/boot/dts/freescale/fsl-ls1046a-frwy.dts ++++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a-frwy.dts +@@ -83,15 +83,9 @@ + }; + + eeprom@52 { +- compatible = "atmel,24c512"; ++ compatible = "onnn,cat24c04", "atmel,24c04"; + reg = <0x52>; + }; +- +- eeprom@53 { +- compatible = "atmel,24c512"; +- reg = <0x53>; +- }; +- + }; + }; + }; +diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts b/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts +index 60acdf0b689ee..7025aad8ae897 100644 +--- a/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts ++++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts +@@ -59,14 +59,9 @@ + }; + + eeprom@52 { +- compatible = "atmel,24c512"; ++ compatible = "onnn,cat24c05", "atmel,24c04"; + reg = <0x52>; + }; +- +- eeprom@53 { +- compatible = "atmel,24c512"; +- reg = <0x53>; +- }; + }; + + &i2c3 { +diff --git a/arch/arm64/boot/dts/freescale/imx8mm-venice-gw700x.dtsi b/arch/arm64/boot/dts/freescale/imx8mm-venice-gw700x.dtsi +index c769fadbd008f..00f86cada30d2 100644 +--- a/arch/arm64/boot/dts/freescale/imx8mm-venice-gw700x.dtsi ++++ b/arch/arm64/boot/dts/freescale/imx8mm-venice-gw700x.dtsi +@@ -278,70 +278,86 @@ + + pmic@69 { + compatible = "mps,mp5416"; +- pinctrl-names = "default"; +- pinctrl-0 = <&pinctrl_pmic>; + reg = <0x69>; + + regulators { ++ /* vdd_0p95: DRAM/GPU/VPU */ + buck1 { +- regulator-name = "vdd_0p95"; +- regulator-min-microvolt = <805000>; ++ regulator-name = "buck1"; ++ regulator-min-microvolt = <800000>; + regulator-max-microvolt = <1000000>; +- regulator-max-microamp = <2500000>; ++ regulator-min-microamp = <3800000>; ++ regulator-max-microamp = <6800000>; + regulator-boot-on; ++ regulator-always-on; + }; + ++ /* vdd_soc */ + buck2 { +- regulator-name = "vdd_soc"; +- regulator-min-microvolt = <805000>; ++ regulator-name = "buck2"; ++ regulator-min-microvolt = <800000>; + regulator-max-microvolt = <900000>; +- regulator-max-microamp = <1000000>; ++ regulator-min-microamp = <2200000>; ++ regulator-max-microamp = <5200000>; + regulator-boot-on; ++ regulator-always-on; + }; + ++ /* vdd_arm */ + buck3_reg: buck3 { +- regulator-name = "vdd_arm"; +- regulator-min-microvolt = <805000>; ++ regulator-name = "buck3"; ++ regulator-min-microvolt = <800000>; + regulator-max-microvolt = <1000000>; +- regulator-max-microamp = <2200000>; +- regulator-boot-on; ++ regulator-min-microamp = <3800000>; ++ regulator-max-microamp = <6800000>; ++ regulator-always-on; + }; + ++ /* vdd_1p8 */ + buck4 { +- regulator-name = "vdd_1p8"; ++ regulator-name = "buck4"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; +- regulator-max-microamp = <500000>; ++ regulator-min-microamp = <2200000>; ++ regulator-max-microamp = <5200000>; + regulator-boot-on; ++ regulator-always-on; + }; + ++ /* nvcc_snvs_1p8 */ + ldo1 { +- regulator-name = "nvcc_snvs_1p8"; ++ regulator-name = "ldo1"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; +- regulator-max-microamp = <300000>; + regulator-boot-on; ++ regulator-always-on; + }; + ++ /* vdd_snvs_0p8 */ + ldo2 { +- regulator-name = "vdd_snvs_0p8"; ++ regulator-name = "ldo2"; + regulator-min-microvolt = <800000>; + regulator-max-microvolt = <800000>; + regulator-boot-on; ++ regulator-always-on; + }; + ++ /* vdd_0p9 */ + ldo3 { +- regulator-name = "vdd_0p95"; +- regulator-min-microvolt = <800000>; +- regulator-max-microvolt = <800000>; ++ regulator-name = "ldo3"; ++ regulator-min-microvolt = <900000>; ++ regulator-max-microvolt = <900000>; + regulator-boot-on; ++ regulator-always-on; + }; + ++ /* vdd_1p8 */ + ldo4 { +- regulator-name = "vdd_1p8"; ++ regulator-name = "ldo4"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-boot-on; ++ regulator-always-on; + }; + }; + }; +@@ -426,12 +442,6 @@ + >; + }; + +- pinctrl_pmic: pmicgrp { +- fsl,pins = < +- MX8MM_IOMUXC_GPIO1_IO03_GPIO1_IO3 0x41 +- >; +- }; +- + pinctrl_uart2: uart2grp { + fsl,pins = < + MX8MM_IOMUXC_UART2_RXD_UART2_DCE_RX 0x140 +diff --git a/arch/arm64/boot/dts/freescale/imx8mm-venice-gw71xx.dtsi b/arch/arm64/boot/dts/freescale/imx8mm-venice-gw71xx.dtsi +index 905b68a3daa5a..8e4a0ce99790b 100644 +--- a/arch/arm64/boot/dts/freescale/imx8mm-venice-gw71xx.dtsi ++++ b/arch/arm64/boot/dts/freescale/imx8mm-venice-gw71xx.dtsi +@@ -46,7 +46,7 @@ + pinctrl-0 = <&pinctrl_reg_usb1_en>; + compatible = "regulator-fixed"; + regulator-name = "usb_otg1_vbus"; +- gpio = <&gpio1 12 GPIO_ACTIVE_HIGH>; ++ gpio = <&gpio1 10 GPIO_ACTIVE_HIGH>; + enable-active-high; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; +@@ -156,7 +156,8 @@ + + pinctrl_reg_usb1_en: regusb1grp { + fsl,pins = < +- MX8MM_IOMUXC_GPIO1_IO12_GPIO1_IO12 0x41 ++ MX8MM_IOMUXC_GPIO1_IO10_GPIO1_IO10 0x41 ++ MX8MM_IOMUXC_GPIO1_IO12_GPIO1_IO12 0x141 + MX8MM_IOMUXC_GPIO1_IO13_USB1_OTG_OC 0x41 + >; + }; +diff --git a/arch/arm64/boot/dts/nvidia/tegra132.dtsi b/arch/arm64/boot/dts/nvidia/tegra132.dtsi +index 9928a87f593a5..b0bcda8cc51f4 100644 +--- a/arch/arm64/boot/dts/nvidia/tegra132.dtsi ++++ b/arch/arm64/boot/dts/nvidia/tegra132.dtsi +@@ -1227,13 +1227,13 @@ + + cpu@0 { + device_type = "cpu"; +- compatible = "nvidia,denver"; ++ compatible = "nvidia,tegra132-denver"; + reg = <0>; + }; + + cpu@1 { + device_type = "cpu"; +- compatible = "nvidia,denver"; ++ compatible = "nvidia,tegra132-denver"; + reg = <1>; + }; + }; +diff --git a/arch/arm64/boot/dts/nvidia/tegra194.dtsi b/arch/arm64/boot/dts/nvidia/tegra194.dtsi +index 5ba7a4519b956..c8250a3f7891f 100644 +--- a/arch/arm64/boot/dts/nvidia/tegra194.dtsi ++++ b/arch/arm64/boot/dts/nvidia/tegra194.dtsi +@@ -2122,7 +2122,7 @@ + }; + + pcie_ep@14160000 { +- compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep"; ++ compatible = "nvidia,tegra194-pcie-ep"; + power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX4A>; + reg = <0x00 0x14160000 0x0 0x00020000>, /* appl registers (128K) */ + <0x00 0x36040000 0x0 0x00040000>, /* iATU_DMA reg space (256K) */ +@@ -2162,7 +2162,7 @@ + }; + + pcie_ep@14180000 { +- compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep"; ++ compatible = "nvidia,tegra194-pcie-ep"; + power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8B>; + reg = <0x00 0x14180000 0x0 0x00020000>, /* appl registers (128K) */ + <0x00 0x38040000 0x0 0x00040000>, /* iATU_DMA reg space (256K) */ +@@ -2202,7 +2202,7 @@ + }; + + pcie_ep@141a0000 { +- compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep"; ++ compatible = "nvidia,tegra194-pcie-ep"; + power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>; + reg = <0x00 0x141a0000 0x0 0x00020000>, /* appl registers (128K) */ + <0x00 0x3a040000 0x0 0x00040000>, /* iATU_DMA reg space (256K) */ +diff --git a/arch/arm64/boot/dts/qcom/ipq6018.dtsi b/arch/arm64/boot/dts/qcom/ipq6018.dtsi +index 9fa5b028e4f39..23ee1bfa43189 100644 +--- a/arch/arm64/boot/dts/qcom/ipq6018.dtsi ++++ b/arch/arm64/boot/dts/qcom/ipq6018.dtsi +@@ -151,7 +151,7 @@ + #size-cells = <2>; + ranges; + +- rpm_msg_ram: memory@0x60000 { ++ rpm_msg_ram: memory@60000 { + reg = <0x0 0x60000 0x0 0x6000>; + no-map; + }; +diff --git a/arch/arm64/boot/dts/qcom/ipq8074-hk01.dts b/arch/arm64/boot/dts/qcom/ipq8074-hk01.dts +index e8c37a1693d3b..cc08dc4eb56a5 100644 +--- a/arch/arm64/boot/dts/qcom/ipq8074-hk01.dts ++++ b/arch/arm64/boot/dts/qcom/ipq8074-hk01.dts +@@ -20,7 +20,7 @@ + stdout-path = "serial0"; + }; + +- memory { ++ memory@40000000 { + device_type = "memory"; + reg = <0x0 0x40000000 0x0 0x20000000>; + }; +diff --git a/arch/arm64/boot/dts/qcom/ipq8074.dtsi b/arch/arm64/boot/dts/qcom/ipq8074.dtsi +index f39bc10cc5bd7..d64a6e81d1a55 100644 +--- a/arch/arm64/boot/dts/qcom/ipq8074.dtsi ++++ b/arch/arm64/boot/dts/qcom/ipq8074.dtsi +@@ -583,10 +583,10 @@ + + pcie1: pci@10000000 { + compatible = "qcom,pcie-ipq8074"; +- reg = <0x10000000 0xf1d +- 0x10000f20 0xa8 +- 0x00088000 0x2000 +- 0x10100000 0x1000>; ++ reg = <0x10000000 0xf1d>, ++ <0x10000f20 0xa8>, ++ <0x00088000 0x2000>, ++ <0x10100000 0x1000>; + reg-names = "dbi", "elbi", "parf", "config"; + device_type = "pci"; + linux,pci-domain = <1>; +@@ -645,10 +645,10 @@ + + pcie0: pci@20000000 { + compatible = "qcom,pcie-ipq8074"; +- reg = <0x20000000 0xf1d +- 0x20000f20 0xa8 +- 0x00080000 0x2000 +- 0x20100000 0x1000>; ++ reg = <0x20000000 0xf1d>, ++ <0x20000f20 0xa8>, ++ <0x00080000 0x2000>, ++ <0x20100000 0x1000>; + reg-names = "dbi", "elbi", "parf", "config"; + device_type = "pci"; + linux,pci-domain = <0>; +diff --git a/arch/arm64/boot/dts/qcom/msm8994.dtsi b/arch/arm64/boot/dts/qcom/msm8994.dtsi +index f9f0b5aa6a266..87a3217e88efa 100644 +--- a/arch/arm64/boot/dts/qcom/msm8994.dtsi ++++ b/arch/arm64/boot/dts/qcom/msm8994.dtsi +@@ -15,16 +15,18 @@ + chosen { }; + + clocks { +- xo_board: xo_board { ++ xo_board: xo-board { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <19200000>; ++ clock-output-names = "xo_board"; + }; + +- sleep_clk: sleep_clk { ++ sleep_clk: sleep-clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <32768>; ++ clock-output-names = "sleep_clk"; + }; + }; + +diff --git a/arch/arm64/boot/dts/qcom/msm8996.dtsi b/arch/arm64/boot/dts/qcom/msm8996.dtsi +index 78c55ca10ba9b..77bc233f83805 100644 +--- a/arch/arm64/boot/dts/qcom/msm8996.dtsi ++++ b/arch/arm64/boot/dts/qcom/msm8996.dtsi +@@ -19,14 +19,14 @@ + chosen { }; + + clocks { +- xo_board: xo_board { ++ xo_board: xo-board { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <19200000>; + clock-output-names = "xo_board"; + }; + +- sleep_clk: sleep_clk { ++ sleep_clk: sleep-clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <32764>; +diff --git a/arch/arm64/boot/dts/qcom/sa8155p-adp.dts b/arch/arm64/boot/dts/qcom/sa8155p-adp.dts +index 0da7a3b8d1bf3..5ae2ddc65f7e4 100644 +--- a/arch/arm64/boot/dts/qcom/sa8155p-adp.dts ++++ b/arch/arm64/boot/dts/qcom/sa8155p-adp.dts +@@ -307,10 +307,6 @@ + status = "okay"; + }; + +-&tlmm { +- gpio-reserved-ranges = <0 4>; +-}; +- + &uart2 { + status = "okay"; + }; +@@ -337,6 +333,16 @@ + vdda-pll-max-microamp = <18300>; + }; + ++&usb_1 { ++ status = "okay"; ++}; ++ ++&usb_1_dwc3 { ++ dr_mode = "host"; ++ ++ pinctrl-names = "default"; ++ pinctrl-0 = <&usb2phy_ac_en1_default>; ++}; + + &usb_1_hsphy { + status = "okay"; +@@ -346,15 +352,51 @@ + }; + + &usb_1_qmpphy { ++ status = "disabled"; ++}; ++ ++&usb_2 { + status = "okay"; +- vdda-phy-supply = <&vreg_l8c_1p2>; +- vdda-pll-supply = <&vdda_usb_ss_dp_core_1>; + }; + +-&usb_1 { ++&usb_2_dwc3 { ++ dr_mode = "host"; ++ ++ pinctrl-names = "default"; ++ pinctrl-0 = <&usb2phy_ac_en2_default>; ++}; ++ ++&usb_2_hsphy { + status = "okay"; ++ vdda-pll-supply = <&vdd_usb_hs_core>; ++ vdda33-supply = <&vdda_usb_hs_3p1>; ++ vdda18-supply = <&vdda_usb_hs_1p8>; + }; + +-&usb_1_dwc3 { +- dr_mode = "peripheral"; ++&usb_2_qmpphy { ++ status = "okay"; ++ vdda-phy-supply = <&vreg_l8c_1p2>; ++ vdda-pll-supply = <&vdda_usb_ss_dp_core_1>; ++}; ++ ++&tlmm { ++ gpio-reserved-ranges = <0 4>; ++ ++ usb2phy_ac_en1_default: usb2phy_ac_en1_default { ++ mux { ++ pins = "gpio113"; ++ function = "usb2phy_ac"; ++ bias-disable; ++ drive-strength = <2>; ++ }; ++ }; ++ ++ usb2phy_ac_en2_default: usb2phy_ac_en2_default { ++ mux { ++ pins = "gpio123"; ++ function = "usb2phy_ac"; ++ bias-disable; ++ drive-strength = <2>; ++ }; ++ }; + }; +diff --git a/arch/arm64/boot/dts/qcom/sdm630.dtsi b/arch/arm64/boot/dts/qcom/sdm630.dtsi +index f91a928466c3b..06a0ae773ad50 100644 +--- a/arch/arm64/boot/dts/qcom/sdm630.dtsi ++++ b/arch/arm64/boot/dts/qcom/sdm630.dtsi +@@ -17,14 +17,14 @@ + chosen { }; + + clocks { +- xo_board: xo_board { ++ xo_board: xo-board { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <19200000>; + clock-output-names = "xo_board"; + }; + +- sleep_clk: sleep_clk { ++ sleep_clk: sleep-clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <32764>; +@@ -343,10 +343,19 @@ + }; + + qhee_code: qhee-code@85800000 { +- reg = <0x0 0x85800000 0x0 0x3700000>; ++ reg = <0x0 0x85800000 0x0 0x600000>; + no-map; + }; + ++ rmtfs_mem: memory@85e00000 { ++ compatible = "qcom,rmtfs-mem"; ++ reg = <0x0 0x85e00000 0x0 0x200000>; ++ no-map; ++ ++ qcom,client-id = <1>; ++ qcom,vmid = <15>; ++ }; ++ + smem_region: smem-mem@86000000 { + reg = <0 0x86000000 0 0x200000>; + no-map; +@@ -357,58 +366,44 @@ + no-map; + }; + +- modem_fw_mem: modem-fw-region@8ac00000 { ++ mpss_region: mpss@8ac00000 { + reg = <0x0 0x8ac00000 0x0 0x7e00000>; + no-map; + }; + +- adsp_fw_mem: adsp-fw-region@92a00000 { ++ adsp_region: adsp@92a00000 { + reg = <0x0 0x92a00000 0x0 0x1e00000>; + no-map; + }; + +- pil_mba_mem: pil-mba-region@94800000 { ++ mba_region: mba@94800000 { + reg = <0x0 0x94800000 0x0 0x200000>; + no-map; + }; + +- buffer_mem: buffer-region@94a00000 { ++ buffer_mem: tzbuffer@94a00000 { + reg = <0x0 0x94a00000 0x0 0x100000>; + no-map; + }; + +- venus_fw_mem: venus-fw-region@9f800000 { ++ venus_region: venus@9f800000 { + reg = <0x0 0x9f800000 0x0 0x800000>; + no-map; + }; + +- secure_region2: secure-region2@f7c00000 { +- reg = <0x0 0xf7c00000 0x0 0x5c00000>; +- no-map; +- }; +- + adsp_mem: adsp-region@f6000000 { + reg = <0x0 0xf6000000 0x0 0x800000>; + no-map; + }; + +- qseecom_ta_mem: qseecom-ta-region@fec00000 { +- reg = <0x0 0xfec00000 0x0 0x1000000>; +- no-map; +- }; +- + qseecom_mem: qseecom-region@f6800000 { + reg = <0x0 0xf6800000 0x0 0x1400000>; + no-map; + }; + +- secure_display_memory: secure-region@f5c00000 { +- reg = <0x0 0xf5c00000 0x0 0x5c00000>; +- no-map; +- }; +- +- cont_splash_mem: cont-splash-region@9d400000 { +- reg = <0x0 0x9d400000 0x0 0x23ff000>; ++ zap_shader_region: gpu@fed00000 { ++ compatible = "shared-dma-pool"; ++ reg = <0x0 0xfed00000 0x0 0xa00000>; + no-map; + }; + }; +@@ -527,14 +522,18 @@ + reg = <0x01f40000 0x20000>; + }; + +- tlmm: pinctrl@3000000 { ++ tlmm: pinctrl@3100000 { + compatible = "qcom,sdm630-pinctrl"; +- reg = <0x03000000 0xc00000>; ++ reg = <0x03100000 0x400000>, ++ <0x03500000 0x400000>, ++ <0x03900000 0x400000>; ++ reg-names = "south", "center", "north"; + interrupts = ; + gpio-controller; +- #gpio-cells = <0x2>; ++ gpio-ranges = <&tlmm 0 0 114>; ++ #gpio-cells = <2>; + interrupt-controller; +- #interrupt-cells = <0x2>; ++ #interrupt-cells = <2>; + + blsp1_uart1_default: blsp1-uart1-default { + pins = "gpio0", "gpio1", "gpio2", "gpio3"; +@@ -554,40 +553,48 @@ + bias-disable; + }; + +- blsp2_uart1_tx_active: blsp2-uart1-tx-active { +- pins = "gpio16"; +- drive-strength = <2>; +- bias-disable; +- }; +- +- blsp2_uart1_tx_sleep: blsp2-uart1-tx-sleep { +- pins = "gpio16"; +- drive-strength = <2>; +- bias-pull-up; +- }; ++ blsp2_uart1_default: blsp2-uart1-active { ++ tx-rts { ++ pins = "gpio16", "gpio19"; ++ function = "blsp_uart5"; ++ drive-strength = <2>; ++ bias-disable; ++ }; + +- blsp2_uart1_rxcts_active: blsp2-uart1-rxcts-active { +- pins = "gpio17", "gpio18"; +- drive-strength = <2>; +- bias-disable; +- }; ++ rx { ++ /* ++ * Avoid garbage data while BT module ++ * is powered off or not driving signal ++ */ ++ pins = "gpio17"; ++ function = "blsp_uart5"; ++ drive-strength = <2>; ++ bias-pull-up; ++ }; + +- blsp2_uart1_rxcts_sleep: blsp2-uart1-rxcts-sleep { +- pins = "gpio17", "gpio18"; +- drive-strength = <2>; +- bias-no-pull; ++ cts { ++ /* Match the pull of the BT module */ ++ pins = "gpio18"; ++ function = "blsp_uart5"; ++ drive-strength = <2>; ++ bias-pull-down; ++ }; + }; + +- blsp2_uart1_rfr_active: blsp2-uart1-rfr-active { +- pins = "gpio19"; +- drive-strength = <2>; +- bias-disable; +- }; ++ blsp2_uart1_sleep: blsp2-uart1-sleep { ++ tx { ++ pins = "gpio16"; ++ function = "gpio"; ++ drive-strength = <2>; ++ bias-pull-up; ++ }; + +- blsp2_uart1_rfr_sleep: blsp2-uart1-rfr-sleep { +- pins = "gpio19"; +- drive-strength = <2>; +- bias-no-pull; ++ rx-cts-rts { ++ pins = "gpio17", "gpio18", "gpio19"; ++ function = "gpio"; ++ drive-strength = <2>; ++ bias-no-pull; ++ }; + }; + + i2c1_default: i2c1-default { +@@ -686,50 +693,106 @@ + bias-pull-up; + }; + +- sdc1_clk_on: sdc1-clk-on { +- pins = "sdc1_clk"; +- bias-disable; +- drive-strength = <16>; +- }; ++ sdc1_state_on: sdc1-on { ++ clk { ++ pins = "sdc1_clk"; ++ bias-disable; ++ drive-strength = <16>; ++ }; + +- sdc1_clk_off: sdc1-clk-off { +- pins = "sdc1_clk"; +- bias-disable; +- drive-strength = <2>; +- }; ++ cmd { ++ pins = "sdc1_cmd"; ++ bias-pull-up; ++ drive-strength = <10>; ++ }; + +- sdc1_cmd_on: sdc1-cmd-on { +- pins = "sdc1_cmd"; +- bias-pull-up; +- drive-strength = <10>; +- }; ++ data { ++ pins = "sdc1_data"; ++ bias-pull-up; ++ drive-strength = <10>; ++ }; + +- sdc1_cmd_off: sdc1-cmd-off { +- pins = "sdc1_cmd"; +- bias-pull-up; +- drive-strength = <2>; ++ rclk { ++ pins = "sdc1_rclk"; ++ bias-pull-down; ++ }; + }; + +- sdc1_data_on: sdc1-data-on { +- pins = "sdc1_data"; +- bias-pull-up; +- drive-strength = <8>; +- }; ++ sdc1_state_off: sdc1-off { ++ clk { ++ pins = "sdc1_clk"; ++ bias-disable; ++ drive-strength = <2>; ++ }; + +- sdc1_data_off: sdc1-data-off { +- pins = "sdc1_data"; +- bias-pull-up; +- drive-strength = <2>; ++ cmd { ++ pins = "sdc1_cmd"; ++ bias-pull-up; ++ drive-strength = <2>; ++ }; ++ ++ data { ++ pins = "sdc1_data"; ++ bias-pull-up; ++ drive-strength = <2>; ++ }; ++ ++ rclk { ++ pins = "sdc1_rclk"; ++ bias-pull-down; ++ }; + }; + +- sdc1_rclk_on: sdc1-rclk-on { +- pins = "sdc1_rclk"; +- bias-pull-down; ++ sdc2_state_on: sdc2-on { ++ clk { ++ pins = "sdc2_clk"; ++ bias-disable; ++ drive-strength = <16>; ++ }; ++ ++ cmd { ++ pins = "sdc2_cmd"; ++ bias-pull-up; ++ drive-strength = <10>; ++ }; ++ ++ data { ++ pins = "sdc2_data"; ++ bias-pull-up; ++ drive-strength = <10>; ++ }; ++ ++ sd-cd { ++ pins = "gpio54"; ++ bias-pull-up; ++ drive-strength = <2>; ++ }; + }; + +- sdc1_rclk_off: sdc1-rclk-off { +- pins = "sdc1_rclk"; +- bias-pull-down; ++ sdc2_state_off: sdc2-off { ++ clk { ++ pins = "sdc2_clk"; ++ bias-disable; ++ drive-strength = <2>; ++ }; ++ ++ cmd { ++ pins = "sdc2_cmd"; ++ bias-pull-up; ++ drive-strength = <2>; ++ }; ++ ++ data { ++ pins = "sdc2_data"; ++ bias-pull-up; ++ drive-strength = <2>; ++ }; ++ ++ sd-cd { ++ pins = "gpio54"; ++ bias-disable; ++ drive-strength = <2>; ++ }; + }; + }; + +@@ -823,8 +886,8 @@ + clock-names = "core", "iface", "xo", "ice"; + + pinctrl-names = "default", "sleep"; +- pinctrl-0 = <&sdc1_clk_on &sdc1_cmd_on &sdc1_data_on &sdc1_rclk_on>; +- pinctrl-1 = <&sdc1_clk_off &sdc1_cmd_off &sdc1_data_off &sdc1_rclk_off>; ++ pinctrl-0 = <&sdc1_state_on>; ++ pinctrl-1 = <&sdc1_state_off>; + + bus-width = <8>; + non-removable; +@@ -969,10 +1032,8 @@ + dmas = <&blsp2_dma 0>, <&blsp2_dma 1>; + dma-names = "tx", "rx"; + pinctrl-names = "default", "sleep"; +- pinctrl-0 = <&blsp2_uart1_tx_active &blsp2_uart1_rxcts_active +- &blsp2_uart1_rfr_active>; +- pinctrl-1 = <&blsp2_uart1_tx_sleep &blsp2_uart1_rxcts_sleep +- &blsp2_uart1_rfr_sleep>; ++ pinctrl-0 = <&blsp2_uart1_default>; ++ pinctrl-1 = <&blsp2_uart1_sleep>; + status = "disabled"; + }; + +diff --git a/arch/arm64/boot/dts/qcom/sm8250.dtsi b/arch/arm64/boot/dts/qcom/sm8250.dtsi +index 9a6eff1813a68..7f7c8f467bfc0 100644 +--- a/arch/arm64/boot/dts/qcom/sm8250.dtsi ++++ b/arch/arm64/boot/dts/qcom/sm8250.dtsi +@@ -3955,7 +3955,7 @@ + }; + }; + +- epss_l3: interconnect@18591000 { ++ epss_l3: interconnect@18590000 { + compatible = "qcom,sm8250-epss-l3"; + reg = <0 0x18590000 0 0x1000>; + +diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h +index b83fb24954b77..3198acb2aad8c 100644 +--- a/arch/arm64/include/asm/el2_setup.h ++++ b/arch/arm64/include/asm/el2_setup.h +@@ -149,8 +149,17 @@ + ubfx x1, x1, #ID_AA64MMFR0_FGT_SHIFT, #4 + cbz x1, .Lskip_fgt_\@ + +- msr_s SYS_HDFGRTR_EL2, xzr +- msr_s SYS_HDFGWTR_EL2, xzr ++ mov x0, xzr ++ mrs x1, id_aa64dfr0_el1 ++ ubfx x1, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4 ++ cmp x1, #3 ++ b.lt .Lset_fgt_\@ ++ /* Disable PMSNEVFR_EL1 read and write traps */ ++ orr x0, x0, #(1 << 62) ++ ++.Lset_fgt_\@: ++ msr_s SYS_HDFGRTR_EL2, x0 ++ msr_s SYS_HDFGWTR_EL2, x0 + msr_s SYS_HFGRTR_EL2, xzr + msr_s SYS_HFGWTR_EL2, xzr + msr_s SYS_HFGITR_EL2, xzr +diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h +index 3512184cfec17..96dc0f7da258d 100644 +--- a/arch/arm64/include/asm/kernel-pgtable.h ++++ b/arch/arm64/include/asm/kernel-pgtable.h +@@ -65,8 +65,8 @@ + #define EARLY_KASLR (0) + #endif + +-#define EARLY_ENTRIES(vstart, vend, shift) (((vend) >> (shift)) \ +- - ((vstart) >> (shift)) + 1 + EARLY_KASLR) ++#define EARLY_ENTRIES(vstart, vend, shift) \ ++ ((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1 + EARLY_KASLR) + + #define EARLY_PGDS(vstart, vend) (EARLY_ENTRIES(vstart, vend, PGDIR_SHIFT)) + +diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h +index 75beffe2ee8a8..e9c30859f80cd 100644 +--- a/arch/arm64/include/asm/mmu.h ++++ b/arch/arm64/include/asm/mmu.h +@@ -27,11 +27,32 @@ typedef struct { + } mm_context_t; + + /* +- * This macro is only used by the TLBI and low-level switch_mm() code, +- * neither of which can race with an ASID change. We therefore don't +- * need to reload the counter using atomic64_read(). ++ * We use atomic64_read() here because the ASID for an 'mm_struct' can ++ * be reallocated when scheduling one of its threads following a ++ * rollover event (see new_context() and flush_context()). In this case, ++ * a concurrent TLBI (e.g. via try_to_unmap_one() and ptep_clear_flush()) ++ * may use a stale ASID. This is fine in principle as the new ASID is ++ * guaranteed to be clean in the TLB, but the TLBI routines have to take ++ * care to handle the following race: ++ * ++ * CPU 0 CPU 1 CPU 2 ++ * ++ * // ptep_clear_flush(mm) ++ * xchg_relaxed(pte, 0) ++ * DSB ISHST ++ * old = ASID(mm) ++ * | ++ * | new = new_context(mm) ++ * \-----------------> atomic_set(mm->context.id, new) ++ * cpu_switch_mm(mm) ++ * // Hardware walk of pte using new ASID ++ * TLBI(old) ++ * ++ * In this scenario, the barrier on CPU 0 and the dependency on CPU 1 ++ * ensure that the page-table walker on CPU 1 *must* see the invalid PTE ++ * written by CPU 0. + */ +-#define ASID(mm) ((mm)->context.id.counter & 0xffff) ++#define ASID(mm) (atomic64_read(&(mm)->context.id) & 0xffff) + + static inline bool arm64_kernel_unmapped_at_el0(void) + { +diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h +index cc3f5a33ff9c5..36f02892e1df8 100644 +--- a/arch/arm64/include/asm/tlbflush.h ++++ b/arch/arm64/include/asm/tlbflush.h +@@ -245,9 +245,10 @@ static inline void flush_tlb_all(void) + + static inline void flush_tlb_mm(struct mm_struct *mm) + { +- unsigned long asid = __TLBI_VADDR(0, ASID(mm)); ++ unsigned long asid; + + dsb(ishst); ++ asid = __TLBI_VADDR(0, ASID(mm)); + __tlbi(aside1is, asid); + __tlbi_user(aside1is, asid); + dsb(ish); +@@ -256,9 +257,10 @@ static inline void flush_tlb_mm(struct mm_struct *mm) + static inline void flush_tlb_page_nosync(struct vm_area_struct *vma, + unsigned long uaddr) + { +- unsigned long addr = __TLBI_VADDR(uaddr, ASID(vma->vm_mm)); ++ unsigned long addr; + + dsb(ishst); ++ addr = __TLBI_VADDR(uaddr, ASID(vma->vm_mm)); + __tlbi(vale1is, addr); + __tlbi_user(vale1is, addr); + } +@@ -283,9 +285,7 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma, + { + int num = 0; + int scale = 0; +- unsigned long asid = ASID(vma->vm_mm); +- unsigned long addr; +- unsigned long pages; ++ unsigned long asid, addr, pages; + + start = round_down(start, stride); + end = round_up(end, stride); +@@ -305,6 +305,7 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma, + } + + dsb(ishst); ++ asid = ASID(vma->vm_mm); + + /* + * When the CPU does not support TLB range operations, flush the TLB +diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S +index c5c994a73a645..17962452e31de 100644 +--- a/arch/arm64/kernel/head.S ++++ b/arch/arm64/kernel/head.S +@@ -177,7 +177,7 @@ SYM_CODE_END(preserve_boot_args) + * to be composed of multiple pages. (This effectively scales the end index). + * + * vstart: virtual address of start of range +- * vend: virtual address of end of range ++ * vend: virtual address of end of range - we map [vstart, vend] + * shift: shift used to transform virtual address into index + * ptrs: number of entries in page table + * istart: index in table corresponding to vstart +@@ -214,17 +214,18 @@ SYM_CODE_END(preserve_boot_args) + * + * tbl: location of page table + * rtbl: address to be used for first level page table entry (typically tbl + PAGE_SIZE) +- * vstart: start address to map +- * vend: end address to map - we map [vstart, vend] ++ * vstart: virtual address of start of range ++ * vend: virtual address of end of range - we map [vstart, vend - 1] + * flags: flags to use to map last level entries + * phys: physical address corresponding to vstart - physical memory is contiguous + * pgds: the number of pgd entries + * + * Temporaries: istart, iend, tmp, count, sv - these need to be different registers +- * Preserves: vstart, vend, flags +- * Corrupts: tbl, rtbl, istart, iend, tmp, count, sv ++ * Preserves: vstart, flags ++ * Corrupts: tbl, rtbl, vend, istart, iend, tmp, count, sv + */ + .macro map_memory, tbl, rtbl, vstart, vend, flags, phys, pgds, istart, iend, tmp, count, sv ++ sub \vend, \vend, #1 + add \rtbl, \tbl, #PAGE_SIZE + mov \sv, \rtbl + mov \count, #0 +diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S +index 709d2c433c5e9..f6b1a88245db2 100644 +--- a/arch/arm64/kernel/vmlinux.lds.S ++++ b/arch/arm64/kernel/vmlinux.lds.S +@@ -181,6 +181,8 @@ SECTIONS + /* everything from this point to __init_begin will be marked RO NX */ + RO_DATA(PAGE_SIZE) + ++ HYPERVISOR_DATA_SECTIONS ++ + idmap_pg_dir = .; + . += IDMAP_DIR_SIZE; + idmap_pg_end = .; +@@ -260,8 +262,6 @@ SECTIONS + _sdata = .; + RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) + +- HYPERVISOR_DATA_SECTIONS +- + /* + * Data written with the MMU off but read with the MMU on requires + * cache lines to be invalidated, discarding up to a Cache Writeback +diff --git a/arch/m68k/Kconfig.bus b/arch/m68k/Kconfig.bus +index f1be832e2b746..d1e93a39cd3bc 100644 +--- a/arch/m68k/Kconfig.bus ++++ b/arch/m68k/Kconfig.bus +@@ -63,7 +63,7 @@ source "drivers/zorro/Kconfig" + + endif + +-if !MMU ++if COLDFIRE + + config ISA_DMA_API + def_bool !M5272 +diff --git a/arch/mips/mti-malta/malta-dtshim.c b/arch/mips/mti-malta/malta-dtshim.c +index 0ddf03df62688..f451268f6c384 100644 +--- a/arch/mips/mti-malta/malta-dtshim.c ++++ b/arch/mips/mti-malta/malta-dtshim.c +@@ -22,7 +22,7 @@ + #define ROCIT_CONFIG_GEN1_MEMMAP_SHIFT 8 + #define ROCIT_CONFIG_GEN1_MEMMAP_MASK (0xf << 8) + +-static unsigned char fdt_buf[16 << 10] __initdata; ++static unsigned char fdt_buf[16 << 10] __initdata __aligned(8); + + /* determined physical memory size, not overridden by command line args */ + extern unsigned long physical_memsize; +diff --git a/arch/openrisc/kernel/entry.S b/arch/openrisc/kernel/entry.S +index bc657e55c15f8..98e4f97db5159 100644 +--- a/arch/openrisc/kernel/entry.S ++++ b/arch/openrisc/kernel/entry.S +@@ -547,6 +547,7 @@ EXCEPTION_ENTRY(_external_irq_handler) + l.bnf 1f // ext irq enabled, all ok. + l.nop + ++#ifdef CONFIG_PRINTK + l.addi r1,r1,-0x8 + l.movhi r3,hi(42f) + l.ori r3,r3,lo(42f) +@@ -560,6 +561,7 @@ EXCEPTION_ENTRY(_external_irq_handler) + .string "\n\rESR interrupt bug: in _external_irq_handler (ESR %x)\n\r" + .align 4 + .previous ++#endif + + l.ori r4,r4,SPR_SR_IEE // fix the bug + // l.sw PT_SR(r1),r4 +diff --git a/arch/parisc/Makefile b/arch/parisc/Makefile +index aed8ea29268bb..2d019aa73b8f0 100644 +--- a/arch/parisc/Makefile ++++ b/arch/parisc/Makefile +@@ -25,18 +25,18 @@ CHECKFLAGS += -D__hppa__=1 + ifdef CONFIG_64BIT + UTS_MACHINE := parisc64 + CHECKFLAGS += -D__LP64__=1 +-CC_ARCHES = hppa64 + LD_BFD := elf64-hppa-linux + else # 32-bit +-CC_ARCHES = hppa hppa2.0 hppa1.1 + LD_BFD := elf32-hppa-linux + endif + + # select defconfig based on actual architecture +-ifeq ($(shell uname -m),parisc64) ++ifeq ($(ARCH),parisc64) + KBUILD_DEFCONFIG := generic-64bit_defconfig ++ CC_ARCHES := hppa64 + else + KBUILD_DEFCONFIG := generic-32bit_defconfig ++ CC_ARCHES := hppa hppa2.0 hppa1.1 + endif + + export LD_BFD +diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c +index fb1e94a3982bc..db1a47cf424dd 100644 +--- a/arch/parisc/kernel/signal.c ++++ b/arch/parisc/kernel/signal.c +@@ -237,6 +237,12 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs, + #endif + + usp = (regs->gr[30] & ~(0x01UL)); ++#ifdef CONFIG_64BIT ++ if (is_compat_task()) { ++ /* The gcc alloca implementation leaves garbage in the upper 32 bits of sp */ ++ usp = (compat_uint_t)usp; ++ } ++#endif + /*FIXME: frame_size parameter is unused, remove it. */ + frame = get_sigframe(&ksig->ka, usp, sizeof(*frame)); + +diff --git a/arch/powerpc/configs/mpc885_ads_defconfig b/arch/powerpc/configs/mpc885_ads_defconfig +index d21f266cea9a5..cd08f9ed2c8dd 100644 +--- a/arch/powerpc/configs/mpc885_ads_defconfig ++++ b/arch/powerpc/configs/mpc885_ads_defconfig +@@ -21,7 +21,6 @@ CONFIG_INET=y + CONFIG_IP_MULTICAST=y + CONFIG_IP_PNP=y + CONFIG_SYN_COOKIES=y +-# CONFIG_IPV6 is not set + # CONFIG_FW_LOADER is not set + CONFIG_MTD=y + CONFIG_MTD_BLOCK=y +@@ -34,6 +33,7 @@ CONFIG_MTD_CFI_GEOMETRY=y + # CONFIG_MTD_CFI_I2 is not set + CONFIG_MTD_CFI_I4=y + CONFIG_MTD_CFI_AMDSTD=y ++CONFIG_MTD_PHYSMAP=y + CONFIG_MTD_PHYSMAP_OF=y + # CONFIG_BLK_DEV is not set + CONFIG_NETDEVICES=y +@@ -76,7 +76,6 @@ CONFIG_PERF_EVENTS=y + CONFIG_MATH_EMULATION=y + CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y + CONFIG_STRICT_KERNEL_RWX=y +-CONFIG_IPV6=y + CONFIG_BPF_JIT=y + CONFIG_DEBUG_VM_PGTABLE=y + CONFIG_BDI_SWITCH=y +diff --git a/arch/powerpc/include/asm/pmc.h b/arch/powerpc/include/asm/pmc.h +index c6bbe9778d3cd..3c09109e708ef 100644 +--- a/arch/powerpc/include/asm/pmc.h ++++ b/arch/powerpc/include/asm/pmc.h +@@ -34,6 +34,13 @@ static inline void ppc_set_pmu_inuse(int inuse) + #endif + } + ++#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE ++static inline int ppc_get_pmu_inuse(void) ++{ ++ return get_paca()->pmcregs_in_use; ++} ++#endif ++ + extern void power4_enable_pmcs(void); + + #else /* CONFIG_PPC64 */ +diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c +index 447b78a87c8f2..12c75b95646a5 100644 +--- a/arch/powerpc/kernel/smp.c ++++ b/arch/powerpc/kernel/smp.c +@@ -1085,7 +1085,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus) + } + + if (cpu_to_chip_id(boot_cpuid) != -1) { +- int idx = num_possible_cpus() / threads_per_core; ++ int idx = DIV_ROUND_UP(num_possible_cpus(), threads_per_core); + + /* + * All threads of a core will all belong to the same core, +@@ -1503,6 +1503,7 @@ static void add_cpu_to_masks(int cpu) + * add it to it's own thread sibling mask. + */ + cpumask_set_cpu(cpu, cpu_sibling_mask(cpu)); ++ cpumask_set_cpu(cpu, cpu_core_mask(cpu)); + + for (i = first_thread; i < first_thread + threads_per_core; i++) + if (cpu_online(i)) +@@ -1520,11 +1521,6 @@ static void add_cpu_to_masks(int cpu) + if (chip_id_lookup_table && ret) + chip_id = cpu_to_chip_id(cpu); + +- if (chip_id == -1) { +- cpumask_copy(per_cpu(cpu_core_map, cpu), cpu_cpu_mask(cpu)); +- goto out; +- } +- + if (shared_caches) + submask_fn = cpu_l2_cache_mask; + +@@ -1534,6 +1530,10 @@ static void add_cpu_to_masks(int cpu) + /* Skip all CPUs already part of current CPU core mask */ + cpumask_andnot(mask, cpu_online_mask, cpu_core_mask(cpu)); + ++ /* If chip_id is -1; limit the cpu_core_mask to within DIE*/ ++ if (chip_id == -1) ++ cpumask_and(mask, mask, cpu_cpu_mask(cpu)); ++ + for_each_cpu(i, mask) { + if (chip_id == cpu_to_chip_id(i)) { + or_cpumasks_related(cpu, i, submask_fn, cpu_core_mask); +@@ -1543,7 +1543,6 @@ static void add_cpu_to_masks(int cpu) + } + } + +-out: + free_cpumask_var(mask); + } + +diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c +index 2b0d04a1b7d2d..9e4a4a7af380c 100644 +--- a/arch/powerpc/kernel/stacktrace.c ++++ b/arch/powerpc/kernel/stacktrace.c +@@ -8,6 +8,7 @@ + * Copyright 2018 Nick Piggin, Michael Ellerman, IBM Corp. + */ + ++#include + #include + #include + #include +diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c +index b5905ae4377c2..44eb7b1ef289e 100644 +--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c ++++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c +@@ -65,10 +65,12 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid, + } + isync(); + ++ pagefault_disable(); + if (is_load) +- ret = copy_from_user_nofault(to, (const void __user *)from, n); ++ ret = __copy_from_user_inatomic(to, (const void __user *)from, n); + else +- ret = copy_to_user_nofault((void __user *)to, from, n); ++ ret = __copy_to_user_inatomic((void __user *)to, from, n); ++ pagefault_enable(); + + /* switch the pid first to avoid running host with unallocated pid */ + if (quadrant == 1 && pid != old_pid) +diff --git a/arch/powerpc/kvm/book3s_64_vio_hv.c b/arch/powerpc/kvm/book3s_64_vio_hv.c +index dc6591548f0cf..636c6ae0939b4 100644 +--- a/arch/powerpc/kvm/book3s_64_vio_hv.c ++++ b/arch/powerpc/kvm/book3s_64_vio_hv.c +@@ -173,10 +173,13 @@ static void kvmppc_rm_tce_put(struct kvmppc_spapr_tce_table *stt, + idx -= stt->offset; + page = stt->pages[idx / TCES_PER_PAGE]; + /* +- * page must not be NULL in real mode, +- * kvmppc_rm_ioba_validate() must have taken care of this. ++ * kvmppc_rm_ioba_validate() allows pages not be allocated if TCE is ++ * being cleared, otherwise it returns H_TOO_HARD and we skip this. + */ +- WARN_ON_ONCE_RM(!page); ++ if (!page) { ++ WARN_ON_ONCE_RM(tce != 0); ++ return; ++ } + tbl = kvmppc_page_address(page); + + tbl[idx % TCES_PER_PAGE] = tce; +diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c +index 085fb8ecbf688..af822f09785ff 100644 +--- a/arch/powerpc/kvm/book3s_hv.c ++++ b/arch/powerpc/kvm/book3s_hv.c +@@ -59,6 +59,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -3852,6 +3853,18 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, + cpu_has_feature(CPU_FTR_P9_TM_HV_ASSIST)) + kvmppc_restore_tm_hv(vcpu, vcpu->arch.shregs.msr, true); + ++#ifdef CONFIG_PPC_PSERIES ++ if (kvmhv_on_pseries()) { ++ barrier(); ++ if (vcpu->arch.vpa.pinned_addr) { ++ struct lppaca *lp = vcpu->arch.vpa.pinned_addr; ++ get_lppaca()->pmcregs_in_use = lp->pmcregs_in_use; ++ } else { ++ get_lppaca()->pmcregs_in_use = 1; ++ } ++ barrier(); ++ } ++#endif + kvmhv_load_guest_pmu(vcpu); + + msr_check_and_set(MSR_FP | MSR_VEC | MSR_VSX); +@@ -3986,6 +3999,13 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, + save_pmu |= nesting_enabled(vcpu->kvm); + + kvmhv_save_guest_pmu(vcpu, save_pmu); ++#ifdef CONFIG_PPC_PSERIES ++ if (kvmhv_on_pseries()) { ++ barrier(); ++ get_lppaca()->pmcregs_in_use = ppc_get_pmu_inuse(); ++ barrier(); ++ } ++#endif + + vc->entry_exit_map = 0x101; + vc->in_guest = 0; +diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c +index f2bf98bdcea28..094a1076fd1fe 100644 +--- a/arch/powerpc/mm/numa.c ++++ b/arch/powerpc/mm/numa.c +@@ -893,7 +893,7 @@ static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn) + static void __init find_possible_nodes(void) + { + struct device_node *rtas; +- const __be32 *domains; ++ const __be32 *domains = NULL; + int prop_length, max_nodes; + u32 i; + +@@ -909,9 +909,14 @@ static void __init find_possible_nodes(void) + * it doesn't exist, then fallback on ibm,max-associativity-domains. + * Current denotes what the platform can support compared to max + * which denotes what the Hypervisor can support. ++ * ++ * If the LPAR is migratable, new nodes might be activated after a LPM, ++ * so we should consider the max number in that case. + */ +- domains = of_get_property(rtas, "ibm,current-associativity-domains", +- &prop_length); ++ if (!of_get_property(of_root, "ibm,migratable-partition", NULL)) ++ domains = of_get_property(rtas, ++ "ibm,current-associativity-domains", ++ &prop_length); + if (!domains) { + domains = of_get_property(rtas, "ibm,max-associativity-domains", + &prop_length); +@@ -920,6 +925,8 @@ static void __init find_possible_nodes(void) + } + + max_nodes = of_read_number(&domains[min_common_depth], 1); ++ pr_info("Partition configured for %d NUMA nodes.\n", max_nodes); ++ + for (i = 0; i < max_nodes; i++) { + if (!node_possible(i)) + node_set(i, node_possible_map); +diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c +index bb0ee716de912..b0a5894090391 100644 +--- a/arch/powerpc/perf/core-book3s.c ++++ b/arch/powerpc/perf/core-book3s.c +@@ -2251,18 +2251,10 @@ unsigned long perf_misc_flags(struct pt_regs *regs) + */ + unsigned long perf_instruction_pointer(struct pt_regs *regs) + { +- bool use_siar = regs_use_siar(regs); + unsigned long siar = mfspr(SPRN_SIAR); + +- if (ppmu && (ppmu->flags & PPMU_P10_DD1)) { +- if (siar) +- return siar; +- else +- return regs->nip; +- } else if (use_siar && siar_valid(regs)) +- return mfspr(SPRN_SIAR) + perf_ip_adjust(regs); +- else if (use_siar) +- return 0; // no valid instruction pointer ++ if (regs_use_siar(regs) && siar_valid(regs) && siar) ++ return siar + perf_ip_adjust(regs); + else + return regs->nip; + } +diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c +index d48413e28c39e..c756228a081fb 100644 +--- a/arch/powerpc/perf/hv-gpci.c ++++ b/arch/powerpc/perf/hv-gpci.c +@@ -175,7 +175,7 @@ static unsigned long single_gpci_request(u32 req, u32 starting_index, + */ + count = 0; + for (i = offset; i < offset + length; i++) +- count |= arg->bytes[i] << (i - offset); ++ count |= (u64)(arg->bytes[i]) << ((length - 1 - (i - offset)) * 8); + + *value = count; + out: +diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h +index 3a77aa96d0925..bdb0c77bcfd9f 100644 +--- a/arch/s390/include/asm/setup.h ++++ b/arch/s390/include/asm/setup.h +@@ -36,6 +36,7 @@ + #define MACHINE_FLAG_NX BIT(15) + #define MACHINE_FLAG_GS BIT(16) + #define MACHINE_FLAG_SCC BIT(17) ++#define MACHINE_FLAG_PCI_MIO BIT(18) + + #define LPP_MAGIC BIT(31) + #define LPP_PID_MASK _AC(0xffffffff, UL) +@@ -110,6 +111,7 @@ extern unsigned long mio_wb_bit_mask; + #define MACHINE_HAS_NX (S390_lowcore.machine_flags & MACHINE_FLAG_NX) + #define MACHINE_HAS_GS (S390_lowcore.machine_flags & MACHINE_FLAG_GS) + #define MACHINE_HAS_SCC (S390_lowcore.machine_flags & MACHINE_FLAG_SCC) ++#define MACHINE_HAS_PCI_MIO (S390_lowcore.machine_flags & MACHINE_FLAG_PCI_MIO) + + /* + * Console mode. Override with conmode= +diff --git a/arch/s390/include/asm/smp.h b/arch/s390/include/asm/smp.h +index e317fd4866c15..f16f4d054ae25 100644 +--- a/arch/s390/include/asm/smp.h ++++ b/arch/s390/include/asm/smp.h +@@ -18,6 +18,7 @@ extern struct mutex smp_cpu_state_mutex; + extern unsigned int smp_cpu_mt_shift; + extern unsigned int smp_cpu_mtid; + extern __vector128 __initdata boot_cpu_vector_save_area[__NUM_VXRS]; ++extern cpumask_t cpu_setup_mask; + + extern int __cpu_up(unsigned int cpu, struct task_struct *tidle); + +diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c +index fb84e3fc1686d..9857cb0467268 100644 +--- a/arch/s390/kernel/early.c ++++ b/arch/s390/kernel/early.c +@@ -236,6 +236,10 @@ static __init void detect_machine_facilities(void) + clock_comparator_max = -1ULL >> 1; + __ctl_set_bit(0, 53); + } ++ if (IS_ENABLED(CONFIG_PCI) && test_facility(153)) { ++ S390_lowcore.machine_flags |= MACHINE_FLAG_PCI_MIO; ++ /* the control bit is set during PCI initialization */ ++ } + } + + static inline void save_vector_registers(void) +diff --git a/arch/s390/kernel/jump_label.c b/arch/s390/kernel/jump_label.c +index ab584e8e35275..9156653b56f69 100644 +--- a/arch/s390/kernel/jump_label.c ++++ b/arch/s390/kernel/jump_label.c +@@ -36,7 +36,7 @@ static void jump_label_bug(struct jump_entry *entry, struct insn *expected, + unsigned char *ipe = (unsigned char *)expected; + unsigned char *ipn = (unsigned char *)new; + +- pr_emerg("Jump label code mismatch at %pS [%p]\n", ipc, ipc); ++ pr_emerg("Jump label code mismatch at %pS [%px]\n", ipc, ipc); + pr_emerg("Found: %6ph\n", ipc); + pr_emerg("Expected: %6ph\n", ipe); + pr_emerg("New: %6ph\n", ipn); +diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c +index 8e8ace899407c..1909ec99d47d7 100644 +--- a/arch/s390/kernel/smp.c ++++ b/arch/s390/kernel/smp.c +@@ -95,6 +95,7 @@ __vector128 __initdata boot_cpu_vector_save_area[__NUM_VXRS]; + #endif + + static unsigned int smp_max_threads __initdata = -1U; ++cpumask_t cpu_setup_mask; + + static int __init early_nosmt(char *s) + { +@@ -894,13 +895,14 @@ static void smp_init_secondary(void) + vtime_init(); + vdso_getcpu_init(); + pfault_init(); ++ cpumask_set_cpu(cpu, &cpu_setup_mask); ++ update_cpu_masks(); + notify_cpu_starting(cpu); + if (topology_cpu_dedicated(cpu)) + set_cpu_flag(CIF_DEDICATED_CPU); + else + clear_cpu_flag(CIF_DEDICATED_CPU); + set_cpu_online(cpu, true); +- update_cpu_masks(); + inc_irq_stat(CPU_RST); + local_irq_enable(); + cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); +@@ -955,10 +957,13 @@ early_param("possible_cpus", _setup_possible_cpus); + int __cpu_disable(void) + { + unsigned long cregs[16]; ++ int cpu; + + /* Handle possible pending IPIs */ + smp_handle_ext_call(); +- set_cpu_online(smp_processor_id(), false); ++ cpu = smp_processor_id(); ++ set_cpu_online(cpu, false); ++ cpumask_clear_cpu(cpu, &cpu_setup_mask); + update_cpu_masks(); + /* Disable pseudo page faults on this cpu. */ + pfault_fini(); +diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c +index 26aa2614ee352..eb4047c9da9a3 100644 +--- a/arch/s390/kernel/topology.c ++++ b/arch/s390/kernel/topology.c +@@ -67,7 +67,7 @@ static void cpu_group_map(cpumask_t *dst, struct mask_info *info, unsigned int c + static cpumask_t mask; + + cpumask_clear(&mask); +- if (!cpu_online(cpu)) ++ if (!cpumask_test_cpu(cpu, &cpu_setup_mask)) + goto out; + cpumask_set_cpu(cpu, &mask); + switch (topology_mode) { +@@ -88,7 +88,7 @@ static void cpu_group_map(cpumask_t *dst, struct mask_info *info, unsigned int c + case TOPOLOGY_MODE_SINGLE: + break; + } +- cpumask_and(&mask, &mask, cpu_online_mask); ++ cpumask_and(&mask, &mask, &cpu_setup_mask); + out: + cpumask_copy(dst, &mask); + } +@@ -99,16 +99,16 @@ static void cpu_thread_map(cpumask_t *dst, unsigned int cpu) + int i; + + cpumask_clear(&mask); +- if (!cpu_online(cpu)) ++ if (!cpumask_test_cpu(cpu, &cpu_setup_mask)) + goto out; + cpumask_set_cpu(cpu, &mask); + if (topology_mode != TOPOLOGY_MODE_HW) + goto out; + cpu -= cpu % (smp_cpu_mtid + 1); +- for (i = 0; i <= smp_cpu_mtid; i++) +- if (cpu_present(cpu + i)) ++ for (i = 0; i <= smp_cpu_mtid; i++) { ++ if (cpumask_test_cpu(cpu + i, &cpu_setup_mask)) + cpumask_set_cpu(cpu + i, &mask); +- cpumask_and(&mask, &mask, cpu_online_mask); ++ } + out: + cpumask_copy(dst, &mask); + } +@@ -569,6 +569,7 @@ void __init topology_init_early(void) + alloc_masks(info, &book_info, 2); + alloc_masks(info, &drawer_info, 3); + out: ++ cpumask_set_cpu(0, &cpu_setup_mask); + __arch_update_cpu_topology(); + __arch_update_dedicated_flag(NULL); + } +diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c +index 8ac710de1ab1b..07bbee9b7320d 100644 +--- a/arch/s390/mm/init.c ++++ b/arch/s390/mm/init.c +@@ -186,9 +186,9 @@ static void pv_init(void) + return; + + /* make sure bounce buffers are shared */ ++ swiotlb_force = SWIOTLB_FORCE; + swiotlb_init(1); + swiotlb_update_mem_attributes(); +- swiotlb_force = SWIOTLB_FORCE; + } + + void __init mem_init(void) +diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c +index 77cd965cffefa..34839bad33e4d 100644 +--- a/arch/s390/pci/pci.c ++++ b/arch/s390/pci/pci.c +@@ -893,7 +893,6 @@ static void zpci_mem_exit(void) + } + + static unsigned int s390_pci_probe __initdata = 1; +-static unsigned int s390_pci_no_mio __initdata; + unsigned int s390_pci_force_floating __initdata; + static unsigned int s390_pci_initialized; + +@@ -904,7 +903,7 @@ char * __init pcibios_setup(char *str) + return NULL; + } + if (!strcmp(str, "nomio")) { +- s390_pci_no_mio = 1; ++ S390_lowcore.machine_flags &= ~MACHINE_FLAG_PCI_MIO; + return NULL; + } + if (!strcmp(str, "force_floating")) { +@@ -935,7 +934,7 @@ static int __init pci_base_init(void) + return 0; + } + +- if (test_facility(153) && !s390_pci_no_mio) { ++ if (MACHINE_HAS_PCI_MIO) { + static_branch_enable(&have_mio); + ctl_set_bit(2, 5); + } +diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c +index c890d67a64ad0..ba54c44a64e2e 100644 +--- a/arch/x86/kernel/cpu/mshyperv.c ++++ b/arch/x86/kernel/cpu/mshyperv.c +@@ -375,8 +375,6 @@ static void __init ms_hyperv_init_platform(void) + if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) { + wrmsrl(HV_X64_MSR_TSC_INVARIANT_CONTROL, 0x1); + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); +- } else { +- mark_tsc_unstable("running on Hyper-V"); + } + + /* +@@ -437,6 +435,13 @@ static void __init ms_hyperv_init_platform(void) + /* Register Hyper-V specific clocksource */ + hv_init_clocksource(); + #endif ++ /* ++ * TSC should be marked as unstable only after Hyper-V ++ * clocksource has been initialized. This ensures that the ++ * stability of the sched_clock is not altered. ++ */ ++ if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT)) ++ mark_tsc_unstable("running on Hyper-V"); + } + + static bool __init ms_hyperv_x2apic_available(void) +diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c +index ac06ca32e9ef7..5e6e236977c75 100644 +--- a/arch/x86/xen/p2m.c ++++ b/arch/x86/xen/p2m.c +@@ -618,8 +618,8 @@ int xen_alloc_p2m_entry(unsigned long pfn) + } + + /* Expanded the p2m? */ +- if (pfn > xen_p2m_last_pfn) { +- xen_p2m_last_pfn = pfn; ++ if (pfn >= xen_p2m_last_pfn) { ++ xen_p2m_last_pfn = ALIGN(pfn + 1, P2M_PER_PAGE); + HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; + } + +diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c +index 21184488c277f..0108504dfb454 100644 +--- a/arch/xtensa/platforms/iss/console.c ++++ b/arch/xtensa/platforms/iss/console.c +@@ -136,9 +136,13 @@ static const struct tty_operations serial_ops = { + + static int __init rs_init(void) + { +- tty_port_init(&serial_port); ++ int ret; + + serial_driver = alloc_tty_driver(SERIAL_MAX_NUM_LINES); ++ if (!serial_driver) ++ return -ENOMEM; ++ ++ tty_port_init(&serial_port); + + /* Initialize the tty_driver structure */ + +@@ -156,8 +160,15 @@ static int __init rs_init(void) + tty_set_operations(serial_driver, &serial_ops); + tty_port_link_device(&serial_port, serial_driver, 0); + +- if (tty_register_driver(serial_driver)) +- panic("Couldn't register serial driver\n"); ++ ret = tty_register_driver(serial_driver); ++ if (ret) { ++ pr_err("Couldn't register serial driver\n"); ++ tty_driver_kref_put(serial_driver); ++ tty_port_destroy(&serial_port); ++ ++ return ret; ++ } ++ + return 0; + } + +diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c +index 673a634eadd9f..9360c65169ff4 100644 +--- a/block/bfq-iosched.c ++++ b/block/bfq-iosched.c +@@ -5296,7 +5296,7 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic) + if (bfqq->new_ioprio >= IOPRIO_BE_NR) { + pr_crit("bfq_set_next_ioprio_data: new_ioprio %d\n", + bfqq->new_ioprio); +- bfqq->new_ioprio = IOPRIO_BE_NR; ++ bfqq->new_ioprio = IOPRIO_BE_NR - 1; + } + + bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio); +diff --git a/block/blk-zoned.c b/block/blk-zoned.c +index 86fce751bb173..1d0c76c18fc52 100644 +--- a/block/blk-zoned.c ++++ b/block/blk-zoned.c +@@ -360,9 +360,6 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, + if (!blk_queue_is_zoned(q)) + return -ENOTTY; + +- if (!capable(CAP_SYS_ADMIN)) +- return -EACCES; +- + if (copy_from_user(&rep, argp, sizeof(struct blk_zone_report))) + return -EFAULT; + +@@ -421,9 +418,6 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, + if (!blk_queue_is_zoned(q)) + return -ENOTTY; + +- if (!capable(CAP_SYS_ADMIN)) +- return -EACCES; +- + if (!(mode & FMODE_WRITE)) + return -EBADF; + +diff --git a/block/bsg.c b/block/bsg.c +index 1f196563ae6ca..79b42c5cafeb8 100644 +--- a/block/bsg.c ++++ b/block/bsg.c +@@ -373,10 +373,13 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) + case SG_GET_RESERVED_SIZE: + case SG_SET_RESERVED_SIZE: + case SG_EMULATED_HOST: +- case SCSI_IOCTL_SEND_COMMAND: + return scsi_cmd_ioctl(bd->queue, NULL, file->f_mode, cmd, uarg); + case SG_IO: + return bsg_sg_io(bd->queue, file->f_mode, uarg); ++ case SCSI_IOCTL_SEND_COMMAND: ++ pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n", ++ current->comm); ++ return -EINVAL; + default: + return -ENOTTY; + } +diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c +index 44f434acfce08..0e6e73b8023fc 100644 +--- a/drivers/ata/libata-core.c ++++ b/drivers/ata/libata-core.c +@@ -3950,6 +3950,10 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = { + ATA_HORKAGE_ZERO_AFTER_TRIM, }, + { "Samsung SSD 850*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | + ATA_HORKAGE_ZERO_AFTER_TRIM, }, ++ { "Samsung SSD 860*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | ++ ATA_HORKAGE_ZERO_AFTER_TRIM, }, ++ { "Samsung SSD 870*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | ++ ATA_HORKAGE_ZERO_AFTER_TRIM, }, + { "FCCT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | + ATA_HORKAGE_ZERO_AFTER_TRIM, }, + +diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c +index f0ef844428bb4..338c2e50f7591 100644 +--- a/drivers/ata/sata_dwc_460ex.c ++++ b/drivers/ata/sata_dwc_460ex.c +@@ -1259,24 +1259,20 @@ static int sata_dwc_probe(struct platform_device *ofdev) + irq = irq_of_parse_and_map(np, 0); + if (irq == NO_IRQ) { + dev_err(&ofdev->dev, "no SATA DMA irq\n"); +- err = -ENODEV; +- goto error_out; ++ return -ENODEV; + } + + #ifdef CONFIG_SATA_DWC_OLD_DMA + if (!of_find_property(np, "dmas", NULL)) { + err = sata_dwc_dma_init_old(ofdev, hsdev); + if (err) +- goto error_out; ++ return err; + } + #endif + + hsdev->phy = devm_phy_optional_get(hsdev->dev, "sata-phy"); +- if (IS_ERR(hsdev->phy)) { +- err = PTR_ERR(hsdev->phy); +- hsdev->phy = NULL; +- goto error_out; +- } ++ if (IS_ERR(hsdev->phy)) ++ return PTR_ERR(hsdev->phy); + + err = phy_init(hsdev->phy); + if (err) +diff --git a/drivers/base/core.c b/drivers/base/core.c +index 6c0ef9d55a343..8c77e14987d4b 100644 +--- a/drivers/base/core.c ++++ b/drivers/base/core.c +@@ -886,6 +886,8 @@ static void device_link_put_kref(struct device_link *link) + { + if (link->flags & DL_FLAG_STATELESS) + kref_put(&link->kref, __device_link_del); ++ else if (!device_is_registered(link->consumer)) ++ __device_link_del(&link->kref); + else + WARN(1, "Unable to drop a managed device link reference\n"); + } +diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c +index 09c8ab5e0959e..32b2b6d9bde0b 100644 +--- a/drivers/bus/fsl-mc/fsl-mc-bus.c ++++ b/drivers/bus/fsl-mc/fsl-mc-bus.c +@@ -68,6 +68,8 @@ struct fsl_mc_addr_translation_range { + #define MC_FAPR_PL BIT(18) + #define MC_FAPR_BMT BIT(17) + ++static phys_addr_t mc_portal_base_phys_addr; ++ + /** + * fsl_mc_bus_match - device to driver matching callback + * @dev: the fsl-mc device to match against +@@ -220,7 +222,7 @@ static int scan_fsl_mc_bus(struct device *dev, void *data) + root_mc_dev = to_fsl_mc_device(dev); + root_mc_bus = to_fsl_mc_bus(root_mc_dev); + mutex_lock(&root_mc_bus->scan_mutex); +- dprc_scan_objects(root_mc_dev, NULL); ++ dprc_scan_objects(root_mc_dev, false); + mutex_unlock(&root_mc_bus->scan_mutex); + + exit: +@@ -703,14 +705,30 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev, + * If base address is in the region_desc use it otherwise + * revert to old mechanism + */ +- if (region_desc.base_address) ++ if (region_desc.base_address) { + regions[i].start = region_desc.base_address + + region_desc.base_offset; +- else ++ } else { + error = translate_mc_addr(mc_dev, mc_region_type, + region_desc.base_offset, + ®ions[i].start); + ++ /* ++ * Some versions of the MC firmware wrongly report ++ * 0 for register base address of the DPMCP associated ++ * with child DPRC objects thus rendering them unusable. ++ * This is particularly troublesome in ACPI boot ++ * scenarios where the legacy way of extracting this ++ * base address from the device tree does not apply. ++ * Given that DPMCPs share the same base address, ++ * workaround this by using the base address extracted ++ * from the root DPRC container. ++ */ ++ if (is_fsl_mc_bus_dprc(mc_dev) && ++ regions[i].start == region_desc.base_offset) ++ regions[i].start += mc_portal_base_phys_addr; ++ } ++ + if (error < 0) { + dev_err(parent_dev, + "Invalid MC offset: %#x (for %s.%d\'s region %d)\n", +@@ -1126,6 +1144,8 @@ static int fsl_mc_bus_probe(struct platform_device *pdev) + plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + mc_portal_phys_addr = plat_res->start; + mc_portal_size = resource_size(plat_res); ++ mc_portal_base_phys_addr = mc_portal_phys_addr & ~0x3ffffff; ++ + error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr, + mc_portal_size, NULL, + FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, &mc_io); +diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c +index b4fc8d71daf20..b656d25a97678 100644 +--- a/drivers/clk/at91/clk-generated.c ++++ b/drivers/clk/at91/clk-generated.c +@@ -128,6 +128,12 @@ static int clk_generated_determine_rate(struct clk_hw *hw, + int i; + u32 div; + ++ /* do not look for a rate that is outside of our range */ ++ if (gck->range.max && req->rate > gck->range.max) ++ req->rate = gck->range.max; ++ if (gck->range.min && req->rate < gck->range.min) ++ req->rate = gck->range.min; ++ + for (i = 0; i < clk_hw_get_num_parents(hw); i++) { + if (gck->chg_pid == i) + continue; +diff --git a/drivers/clk/imx/clk-composite-8m.c b/drivers/clk/imx/clk-composite-8m.c +index 2c309e3dc8e34..04e728538cefe 100644 +--- a/drivers/clk/imx/clk-composite-8m.c ++++ b/drivers/clk/imx/clk-composite-8m.c +@@ -216,7 +216,8 @@ struct clk_hw *imx8m_clk_hw_composite_flags(const char *name, + div->width = PCG_PREDIV_WIDTH; + divider_ops = &imx8m_clk_composite_divider_ops; + mux_ops = &clk_mux_ops; +- flags |= CLK_SET_PARENT_GATE; ++ if (!(composite_flags & IMX_COMPOSITE_FW_MANAGED)) ++ flags |= CLK_SET_PARENT_GATE; + } + + div->lock = &imx_ccm_lock; +diff --git a/drivers/clk/imx/clk-imx8mm.c b/drivers/clk/imx/clk-imx8mm.c +index f1919fafb1247..e92621fa8b9cd 100644 +--- a/drivers/clk/imx/clk-imx8mm.c ++++ b/drivers/clk/imx/clk-imx8mm.c +@@ -407,10 +407,10 @@ static int imx8mm_clocks_probe(struct platform_device *pdev) + hws[IMX8MM_SYS_PLL2_500M] = imx_clk_hw_fixed_factor("sys_pll2_500m", "sys_pll2_500m_cg", 1, 2); + hws[IMX8MM_SYS_PLL2_1000M] = imx_clk_hw_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1); + +- hws[IMX8MM_CLK_CLKOUT1_SEL] = imx_clk_hw_mux("clkout1_sel", base + 0x128, 4, 4, clkout_sels, ARRAY_SIZE(clkout_sels)); ++ hws[IMX8MM_CLK_CLKOUT1_SEL] = imx_clk_hw_mux2("clkout1_sel", base + 0x128, 4, 4, clkout_sels, ARRAY_SIZE(clkout_sels)); + hws[IMX8MM_CLK_CLKOUT1_DIV] = imx_clk_hw_divider("clkout1_div", "clkout1_sel", base + 0x128, 0, 4); + hws[IMX8MM_CLK_CLKOUT1] = imx_clk_hw_gate("clkout1", "clkout1_div", base + 0x128, 8); +- hws[IMX8MM_CLK_CLKOUT2_SEL] = imx_clk_hw_mux("clkout2_sel", base + 0x128, 20, 4, clkout_sels, ARRAY_SIZE(clkout_sels)); ++ hws[IMX8MM_CLK_CLKOUT2_SEL] = imx_clk_hw_mux2("clkout2_sel", base + 0x128, 20, 4, clkout_sels, ARRAY_SIZE(clkout_sels)); + hws[IMX8MM_CLK_CLKOUT2_DIV] = imx_clk_hw_divider("clkout2_div", "clkout2_sel", base + 0x128, 16, 4); + hws[IMX8MM_CLK_CLKOUT2] = imx_clk_hw_gate("clkout2", "clkout2_div", base + 0x128, 24); + +@@ -470,10 +470,11 @@ static int imx8mm_clocks_probe(struct platform_device *pdev) + + /* + * DRAM clocks are manipulated from TF-A outside clock framework. +- * Mark with GET_RATE_NOCACHE to always read div value from hardware ++ * The fw_managed helper sets GET_RATE_NOCACHE and clears SET_PARENT_GATE ++ * as div value should always be read from hardware + */ +- hws[IMX8MM_CLK_DRAM_ALT] = __imx8m_clk_hw_composite("dram_alt", imx8mm_dram_alt_sels, base + 0xa000, CLK_GET_RATE_NOCACHE); +- hws[IMX8MM_CLK_DRAM_APB] = __imx8m_clk_hw_composite("dram_apb", imx8mm_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE); ++ hws[IMX8MM_CLK_DRAM_ALT] = imx8m_clk_hw_fw_managed_composite("dram_alt", imx8mm_dram_alt_sels, base + 0xa000); ++ hws[IMX8MM_CLK_DRAM_APB] = imx8m_clk_hw_fw_managed_composite_critical("dram_apb", imx8mm_dram_apb_sels, base + 0xa080); + + /* IP */ + hws[IMX8MM_CLK_VPU_G1] = imx8m_clk_hw_composite("vpu_g1", imx8mm_vpu_g1_sels, base + 0xa100); +diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c +index 88f6630cd472f..0a76f969b28b3 100644 +--- a/drivers/clk/imx/clk-imx8mn.c ++++ b/drivers/clk/imx/clk-imx8mn.c +@@ -453,10 +453,11 @@ static int imx8mn_clocks_probe(struct platform_device *pdev) + + /* + * DRAM clocks are manipulated from TF-A outside clock framework. +- * Mark with GET_RATE_NOCACHE to always read div value from hardware ++ * The fw_managed helper sets GET_RATE_NOCACHE and clears SET_PARENT_GATE ++ * as div value should always be read from hardware + */ +- hws[IMX8MN_CLK_DRAM_ALT] = __imx8m_clk_hw_composite("dram_alt", imx8mn_dram_alt_sels, base + 0xa000, CLK_GET_RATE_NOCACHE); +- hws[IMX8MN_CLK_DRAM_APB] = __imx8m_clk_hw_composite("dram_apb", imx8mn_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE); ++ hws[IMX8MN_CLK_DRAM_ALT] = imx8m_clk_hw_fw_managed_composite("dram_alt", imx8mn_dram_alt_sels, base + 0xa000); ++ hws[IMX8MN_CLK_DRAM_APB] = imx8m_clk_hw_fw_managed_composite_critical("dram_apb", imx8mn_dram_apb_sels, base + 0xa080); + + hws[IMX8MN_CLK_DISP_PIXEL] = imx8m_clk_hw_composite("disp_pixel", imx8mn_disp_pixel_sels, base + 0xa500); + hws[IMX8MN_CLK_SAI2] = imx8m_clk_hw_composite("sai2", imx8mn_sai2_sels, base + 0xa600); +diff --git a/drivers/clk/imx/clk-imx8mq.c b/drivers/clk/imx/clk-imx8mq.c +index c491bc9c61ce7..83cc2b1c32947 100644 +--- a/drivers/clk/imx/clk-imx8mq.c ++++ b/drivers/clk/imx/clk-imx8mq.c +@@ -449,11 +449,12 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) + + /* + * DRAM clocks are manipulated from TF-A outside clock framework. +- * Mark with GET_RATE_NOCACHE to always read div value from hardware ++ * The fw_managed helper sets GET_RATE_NOCACHE and clears SET_PARENT_GATE ++ * as div value should always be read from hardware + */ + hws[IMX8MQ_CLK_DRAM_CORE] = imx_clk_hw_mux2_flags("dram_core_clk", base + 0x9800, 24, 1, imx8mq_dram_core_sels, ARRAY_SIZE(imx8mq_dram_core_sels), CLK_IS_CRITICAL); +- hws[IMX8MQ_CLK_DRAM_ALT] = __imx8m_clk_hw_composite("dram_alt", imx8mq_dram_alt_sels, base + 0xa000, CLK_GET_RATE_NOCACHE); +- hws[IMX8MQ_CLK_DRAM_APB] = __imx8m_clk_hw_composite("dram_apb", imx8mq_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE); ++ hws[IMX8MQ_CLK_DRAM_ALT] = imx8m_clk_hw_fw_managed_composite("dram_alt", imx8mq_dram_alt_sels, base + 0xa000); ++ hws[IMX8MQ_CLK_DRAM_APB] = imx8m_clk_hw_fw_managed_composite_critical("dram_apb", imx8mq_dram_apb_sels, base + 0xa080); + + /* IP */ + hws[IMX8MQ_CLK_VPU_G1] = imx8m_clk_hw_composite("vpu_g1", imx8mq_vpu_g1_sels, base + 0xa100); +diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h +index 7571603bee23b..e144f983fd8ce 100644 +--- a/drivers/clk/imx/clk.h ++++ b/drivers/clk/imx/clk.h +@@ -530,8 +530,9 @@ struct clk_hw *imx_clk_hw_cpu(const char *name, const char *parent_name, + struct clk *div, struct clk *mux, struct clk *pll, + struct clk *step); + +-#define IMX_COMPOSITE_CORE BIT(0) +-#define IMX_COMPOSITE_BUS BIT(1) ++#define IMX_COMPOSITE_CORE BIT(0) ++#define IMX_COMPOSITE_BUS BIT(1) ++#define IMX_COMPOSITE_FW_MANAGED BIT(2) + + struct clk_hw *imx8m_clk_hw_composite_flags(const char *name, + const char * const *parent_names, +@@ -567,6 +568,17 @@ struct clk_hw *imx8m_clk_hw_composite_flags(const char *name, + ARRAY_SIZE(parent_names), reg, 0, \ + flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE) + ++#define __imx8m_clk_hw_fw_managed_composite(name, parent_names, reg, flags) \ ++ imx8m_clk_hw_composite_flags(name, parent_names, \ ++ ARRAY_SIZE(parent_names), reg, IMX_COMPOSITE_FW_MANAGED, \ ++ flags | CLK_GET_RATE_NOCACHE | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE) ++ ++#define imx8m_clk_hw_fw_managed_composite(name, parent_names, reg) \ ++ __imx8m_clk_hw_fw_managed_composite(name, parent_names, reg, 0) ++ ++#define imx8m_clk_hw_fw_managed_composite_critical(name, parent_names, reg) \ ++ __imx8m_clk_hw_fw_managed_composite(name, parent_names, reg, CLK_IS_CRITICAL) ++ + #define __imx8m_clk_composite(name, parent_names, reg, flags) \ + to_clk(__imx8m_clk_hw_composite(name, parent_names, reg, flags)) + +diff --git a/drivers/clk/ralink/clk-mt7621.c b/drivers/clk/ralink/clk-mt7621.c +index 857da1e274be9..a2c045390f008 100644 +--- a/drivers/clk/ralink/clk-mt7621.c ++++ b/drivers/clk/ralink/clk-mt7621.c +@@ -131,14 +131,7 @@ static int mt7621_gate_ops_init(struct device *dev, + struct mt7621_gate *sclk) + { + struct clk_init_data init = { +- /* +- * Until now no clock driver existed so +- * these SoC drivers are not prepared +- * yet for the clock. We don't want kernel to +- * disable anything so we add CLK_IS_CRITICAL +- * flag here. +- */ +- .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, ++ .flags = CLK_SET_RATE_PARENT, + .num_parents = 1, + .parent_names = &sclk->parent_name, + .ops = &mt7621_gate_ops, +diff --git a/drivers/clk/renesas/renesas-rzg2l-cpg.c b/drivers/clk/renesas/renesas-rzg2l-cpg.c +index e7c59af2a1d85..f894a210de902 100644 +--- a/drivers/clk/renesas/renesas-rzg2l-cpg.c ++++ b/drivers/clk/renesas/renesas-rzg2l-cpg.c +@@ -229,7 +229,7 @@ static struct clk + + case CPG_MOD: + type = "module"; +- if (clkidx > priv->num_mod_clks) { ++ if (clkidx >= priv->num_mod_clks) { + dev_err(dev, "Invalid %s clock index %u\n", type, + clkidx); + return ERR_PTR(-EINVAL); +diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c +index fe937bcdb4876..f7827b3b7fc1c 100644 +--- a/drivers/clk/rockchip/clk-pll.c ++++ b/drivers/clk/rockchip/clk-pll.c +@@ -940,7 +940,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx, + switch (pll_type) { + case pll_rk3036: + case pll_rk3328: +- if (!pll->rate_table || IS_ERR(ctx->grf)) ++ if (!pll->rate_table) + init.ops = &rockchip_rk3036_pll_clk_norate_ops; + else + init.ops = &rockchip_rk3036_pll_clk_ops; +diff --git a/drivers/clk/socfpga/clk-agilex.c b/drivers/clk/socfpga/clk-agilex.c +index 1cb21ea79c640..242e94c0cf8a3 100644 +--- a/drivers/clk/socfpga/clk-agilex.c ++++ b/drivers/clk/socfpga/clk-agilex.c +@@ -107,10 +107,10 @@ static const struct clk_parent_data gpio_db_free_mux[] = { + }; + + static const struct clk_parent_data psi_ref_free_mux[] = { +- { .fw_name = "main_pll_c3", +- .name = "main_pll_c3", }, +- { .fw_name = "peri_pll_c3", +- .name = "peri_pll_c3", }, ++ { .fw_name = "main_pll_c2", ++ .name = "main_pll_c2", }, ++ { .fw_name = "peri_pll_c2", ++ .name = "peri_pll_c2", }, + { .fw_name = "osc1", + .name = "osc1", }, + { .fw_name = "cb-intosc-hs-div2-clk", +@@ -195,6 +195,13 @@ static const struct clk_parent_data sdmmc_mux[] = { + .name = "boot_clk", }, + }; + ++static const struct clk_parent_data s2f_user0_mux[] = { ++ { .fw_name = "s2f_user0_free_clk", ++ .name = "s2f_user0_free_clk", }, ++ { .fw_name = "boot_clk", ++ .name = "boot_clk", }, ++}; ++ + static const struct clk_parent_data s2f_user1_mux[] = { + { .fw_name = "s2f_user1_free_clk", + .name = "s2f_user1_free_clk", }, +@@ -273,7 +280,7 @@ static const struct stratix10_perip_cnt_clock agilex_main_perip_cnt_clks[] = { + { AGILEX_SDMMC_FREE_CLK, "sdmmc_free_clk", NULL, sdmmc_free_mux, + ARRAY_SIZE(sdmmc_free_mux), 0, 0xE4, 0, 0, 0}, + { AGILEX_S2F_USER0_FREE_CLK, "s2f_user0_free_clk", NULL, s2f_usr0_free_mux, +- ARRAY_SIZE(s2f_usr0_free_mux), 0, 0xE8, 0, 0, 0}, ++ ARRAY_SIZE(s2f_usr0_free_mux), 0, 0xE8, 0, 0x30, 2}, + { AGILEX_S2F_USER1_FREE_CLK, "s2f_user1_free_clk", NULL, s2f_usr1_free_mux, + ARRAY_SIZE(s2f_usr1_free_mux), 0, 0xEC, 0, 0x88, 5}, + { AGILEX_PSI_REF_FREE_CLK, "psi_ref_free_clk", NULL, psi_ref_free_mux, +@@ -319,6 +326,8 @@ static const struct stratix10_gate_clock agilex_gate_clks[] = { + 4, 0x98, 0, 16, 0x88, 3, 0}, + { AGILEX_SDMMC_CLK, "sdmmc_clk", NULL, sdmmc_mux, ARRAY_SIZE(sdmmc_mux), 0, 0x7C, + 5, 0, 0, 0, 0x88, 4, 4}, ++ { AGILEX_S2F_USER0_CLK, "s2f_user0_clk", NULL, s2f_user0_mux, ARRAY_SIZE(s2f_user0_mux), 0, 0x24, ++ 6, 0, 0, 0, 0x30, 2, 0}, + { AGILEX_S2F_USER1_CLK, "s2f_user1_clk", NULL, s2f_user1_mux, ARRAY_SIZE(s2f_user1_mux), 0, 0x7C, + 6, 0, 0, 0, 0x88, 5, 0}, + { AGILEX_PSI_REF_CLK, "psi_ref_clk", NULL, psi_mux, ARRAY_SIZE(psi_mux), 0, 0x7C, +diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c +index 005600cef2730..6fbb46b2f6dac 100644 +--- a/drivers/cpufreq/powernv-cpufreq.c ++++ b/drivers/cpufreq/powernv-cpufreq.c +@@ -36,6 +36,7 @@ + #define MAX_PSTATE_SHIFT 32 + #define LPSTATE_SHIFT 48 + #define GPSTATE_SHIFT 56 ++#define MAX_NR_CHIPS 32 + + #define MAX_RAMP_DOWN_TIME 5120 + /* +@@ -1046,12 +1047,20 @@ static int init_chip_info(void) + unsigned int *chip; + unsigned int cpu, i; + unsigned int prev_chip_id = UINT_MAX; ++ cpumask_t *chip_cpu_mask; + int ret = 0; + + chip = kcalloc(num_possible_cpus(), sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + ++ /* Allocate a chip cpu mask large enough to fit mask for all chips */ ++ chip_cpu_mask = kcalloc(MAX_NR_CHIPS, sizeof(cpumask_t), GFP_KERNEL); ++ if (!chip_cpu_mask) { ++ ret = -ENOMEM; ++ goto free_and_return; ++ } ++ + for_each_possible_cpu(cpu) { + unsigned int id = cpu_to_chip_id(cpu); + +@@ -1059,22 +1068,25 @@ static int init_chip_info(void) + prev_chip_id = id; + chip[nr_chips++] = id; + } ++ cpumask_set_cpu(cpu, &chip_cpu_mask[nr_chips-1]); + } + + chips = kcalloc(nr_chips, sizeof(struct chip), GFP_KERNEL); + if (!chips) { + ret = -ENOMEM; +- goto free_and_return; ++ goto out_free_chip_cpu_mask; + } + + for (i = 0; i < nr_chips; i++) { + chips[i].id = chip[i]; +- cpumask_copy(&chips[i].mask, cpumask_of_node(chip[i])); ++ cpumask_copy(&chips[i].mask, &chip_cpu_mask[i]); + INIT_WORK(&chips[i].throttle, powernv_cpufreq_work_fn); + for_each_cpu(cpu, &chips[i].mask) + per_cpu(chip_info, cpu) = &chips[i]; + } + ++out_free_chip_cpu_mask: ++ kfree(chip_cpu_mask); + free_and_return: + kfree(chip); + return ret; +diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c +index a2b5c6f60cf0e..ff164dec8422e 100644 +--- a/drivers/cpuidle/cpuidle-pseries.c ++++ b/drivers/cpuidle/cpuidle-pseries.c +@@ -402,7 +402,7 @@ static void __init fixup_cede0_latency(void) + * pseries_idle_probe() + * Choose state table for shared versus dedicated partition + */ +-static int pseries_idle_probe(void) ++static int __init pseries_idle_probe(void) + { + + if (cpuidle_disable != IDLE_NO_OVERRIDE) +@@ -419,7 +419,21 @@ static int pseries_idle_probe(void) + cpuidle_state_table = shared_states; + max_idle_state = ARRAY_SIZE(shared_states); + } else { +- fixup_cede0_latency(); ++ /* ++ * Use firmware provided latency values ++ * starting with POWER10 platforms. In the ++ * case that we are running on a POWER10 ++ * platform but in an earlier compat mode, we ++ * can still use the firmware provided values. ++ * ++ * However, on platforms prior to POWER10, we ++ * cannot rely on the accuracy of the firmware ++ * provided latency values. On such platforms, ++ * go with the conservative default estimate ++ * of 10us. ++ */ ++ if (cpu_has_feature(CPU_FTR_ARCH_31) || pvr_version_is(PVR_POWER10)) ++ fixup_cede0_latency(); + cpuidle_state_table = dedicated_states; + max_idle_state = NR_DEDICATED_STATES; + } +diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c +index 91808402e0bf2..2ecb0e1f65d8d 100644 +--- a/drivers/crypto/ccp/sev-dev.c ++++ b/drivers/crypto/ccp/sev-dev.c +@@ -300,6 +300,9 @@ static int __sev_platform_shutdown_locked(int *error) + struct sev_device *sev = psp_master->sev_data; + int ret; + ++ if (sev->state == SEV_STATE_UNINIT) ++ return 0; ++ + ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error); + if (ret) + return ret; +@@ -1019,6 +1022,20 @@ e_err: + return ret; + } + ++static void sev_firmware_shutdown(struct sev_device *sev) ++{ ++ sev_platform_shutdown(NULL); ++ ++ if (sev_es_tmr) { ++ /* The TMR area was encrypted, flush it from the cache */ ++ wbinvd_on_all_cpus(); ++ ++ free_pages((unsigned long)sev_es_tmr, ++ get_order(SEV_ES_TMR_SIZE)); ++ sev_es_tmr = NULL; ++ } ++} ++ + void sev_dev_destroy(struct psp_device *psp) + { + struct sev_device *sev = psp->sev_data; +@@ -1026,6 +1043,8 @@ void sev_dev_destroy(struct psp_device *psp) + if (!sev) + return; + ++ sev_firmware_shutdown(sev); ++ + if (sev->misc) + kref_put(&misc_dev->refcount, sev_exit); + +@@ -1056,21 +1075,6 @@ void sev_pci_init(void) + if (sev_get_api_version()) + goto err; + +- /* +- * If platform is not in UNINIT state then firmware upgrade and/or +- * platform INIT command will fail. These command require UNINIT state. +- * +- * In a normal boot we should never run into case where the firmware +- * is not in UNINIT state on boot. But in case of kexec boot, a reboot +- * may not go through a typical shutdown sequence and may leave the +- * firmware in INIT or WORKING state. +- */ +- +- if (sev->state != SEV_STATE_UNINIT) { +- sev_platform_shutdown(NULL); +- sev->state = SEV_STATE_UNINIT; +- } +- + if (sev_version_greater_or_equal(0, 15) && + sev_update_firmware(sev->dev) == 0) + sev_get_api_version(); +@@ -1115,17 +1119,10 @@ err: + + void sev_pci_exit(void) + { +- if (!psp_master->sev_data) +- return; +- +- sev_platform_shutdown(NULL); ++ struct sev_device *sev = psp_master->sev_data; + +- if (sev_es_tmr) { +- /* The TMR area was encrypted, flush it from the cache */ +- wbinvd_on_all_cpus(); ++ if (!sev) ++ return; + +- free_pages((unsigned long)sev_es_tmr, +- get_order(SEV_ES_TMR_SIZE)); +- sev_es_tmr = NULL; +- } ++ sev_firmware_shutdown(sev); + } +diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c +index 6fb6ba35f89d4..9bcc1884c06a1 100644 +--- a/drivers/crypto/ccp/sp-pci.c ++++ b/drivers/crypto/ccp/sp-pci.c +@@ -241,6 +241,17 @@ e_err: + return ret; + } + ++static void sp_pci_shutdown(struct pci_dev *pdev) ++{ ++ struct device *dev = &pdev->dev; ++ struct sp_device *sp = dev_get_drvdata(dev); ++ ++ if (!sp) ++ return; ++ ++ sp_destroy(sp); ++} ++ + static void sp_pci_remove(struct pci_dev *pdev) + { + struct device *dev = &pdev->dev; +@@ -371,6 +382,7 @@ static struct pci_driver sp_pci_driver = { + .id_table = sp_pci_table, + .probe = sp_pci_probe, + .remove = sp_pci_remove, ++ .shutdown = sp_pci_shutdown, + .driver.pm = &sp_pci_pm_ops, + }; + +diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c +index f397cc5bf1021..d19e5ffb5104b 100644 +--- a/drivers/crypto/mxs-dcp.c ++++ b/drivers/crypto/mxs-dcp.c +@@ -300,21 +300,20 @@ static int mxs_dcp_aes_block_crypt(struct crypto_async_request *arq) + + struct scatterlist *dst = req->dst; + struct scatterlist *src = req->src; +- const int nents = sg_nents(req->src); ++ int dst_nents = sg_nents(dst); + + const int out_off = DCP_BUF_SZ; + uint8_t *in_buf = sdcp->coh->aes_in_buf; + uint8_t *out_buf = sdcp->coh->aes_out_buf; + +- uint8_t *out_tmp, *src_buf, *dst_buf = NULL; + uint32_t dst_off = 0; ++ uint8_t *src_buf = NULL; + uint32_t last_out_len = 0; + + uint8_t *key = sdcp->coh->aes_key; + + int ret = 0; +- int split = 0; +- unsigned int i, len, clen, rem = 0, tlen = 0; ++ unsigned int i, len, clen, tlen = 0; + int init = 0; + bool limit_hit = false; + +@@ -332,7 +331,7 @@ static int mxs_dcp_aes_block_crypt(struct crypto_async_request *arq) + memset(key + AES_KEYSIZE_128, 0, AES_KEYSIZE_128); + } + +- for_each_sg(req->src, src, nents, i) { ++ for_each_sg(req->src, src, sg_nents(src), i) { + src_buf = sg_virt(src); + len = sg_dma_len(src); + tlen += len; +@@ -357,34 +356,17 @@ static int mxs_dcp_aes_block_crypt(struct crypto_async_request *arq) + * submit the buffer. + */ + if (actx->fill == out_off || sg_is_last(src) || +- limit_hit) { ++ limit_hit) { + ret = mxs_dcp_run_aes(actx, req, init); + if (ret) + return ret; + init = 0; + +- out_tmp = out_buf; ++ sg_pcopy_from_buffer(dst, dst_nents, out_buf, ++ actx->fill, dst_off); ++ dst_off += actx->fill; + last_out_len = actx->fill; +- while (dst && actx->fill) { +- if (!split) { +- dst_buf = sg_virt(dst); +- dst_off = 0; +- } +- rem = min(sg_dma_len(dst) - dst_off, +- actx->fill); +- +- memcpy(dst_buf + dst_off, out_tmp, rem); +- out_tmp += rem; +- dst_off += rem; +- actx->fill -= rem; +- +- if (dst_off == sg_dma_len(dst)) { +- dst = sg_next(dst); +- split = 0; +- } else { +- split = 1; +- } +- } ++ actx->fill = 0; + } + } while (len); + +diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c +index f26c71747d43a..e744fd87c63c8 100644 +--- a/drivers/dma-buf/dma-resv.c ++++ b/drivers/dma-buf/dma-resv.c +@@ -615,25 +615,21 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence) + */ + bool dma_resv_test_signaled(struct dma_resv *obj, bool test_all) + { +- unsigned int seq, shared_count; ++ struct dma_fence *fence; ++ unsigned int seq; + int ret; + + rcu_read_lock(); + retry: + ret = true; +- shared_count = 0; + seq = read_seqcount_begin(&obj->seq); + + if (test_all) { + struct dma_resv_list *fobj = dma_resv_shared_list(obj); +- unsigned int i; +- +- if (fobj) +- shared_count = fobj->shared_count; ++ unsigned int i, shared_count; + ++ shared_count = fobj ? fobj->shared_count : 0; + for (i = 0; i < shared_count; ++i) { +- struct dma_fence *fence; +- + fence = rcu_dereference(fobj->shared[i]); + ret = dma_resv_test_signaled_single(fence); + if (ret < 0) +@@ -641,24 +637,19 @@ retry: + else if (!ret) + break; + } +- +- if (read_seqcount_retry(&obj->seq, seq)) +- goto retry; + } + +- if (!shared_count) { +- struct dma_fence *fence_excl = dma_resv_excl_fence(obj); +- +- if (fence_excl) { +- ret = dma_resv_test_signaled_single(fence_excl); +- if (ret < 0) +- goto retry; ++ fence = dma_resv_excl_fence(obj); ++ if (ret && fence) { ++ ret = dma_resv_test_signaled_single(fence); ++ if (ret < 0) ++ goto retry; + +- if (read_seqcount_retry(&obj->seq, seq)) +- goto retry; +- } + } + ++ if (read_seqcount_retry(&obj->seq, seq)) ++ goto retry; ++ + rcu_read_unlock(); + return ret; + } +diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c +index 8070fd664bfc6..665ccbf2b8be8 100644 +--- a/drivers/dma/imx-sdma.c ++++ b/drivers/dma/imx-sdma.c +@@ -433,7 +433,6 @@ struct sdma_channel { + unsigned long watermark_level; + u32 shp_addr, per_addr; + enum dma_status status; +- bool context_loaded; + struct imx_dma_data data; + struct work_struct terminate_worker; + }; +@@ -1008,9 +1007,6 @@ static int sdma_load_context(struct sdma_channel *sdmac) + int ret; + unsigned long flags; + +- if (sdmac->context_loaded) +- return 0; +- + if (sdmac->direction == DMA_DEV_TO_MEM) + load_address = sdmac->pc_from_device; + else if (sdmac->direction == DMA_DEV_TO_DEV) +@@ -1053,8 +1049,6 @@ static int sdma_load_context(struct sdma_channel *sdmac) + + spin_unlock_irqrestore(&sdma->channel_0_lock, flags); + +- sdmac->context_loaded = true; +- + return ret; + } + +@@ -1093,7 +1087,6 @@ static void sdma_channel_terminate_work(struct work_struct *work) + vchan_get_all_descriptors(&sdmac->vc, &head); + spin_unlock_irqrestore(&sdmac->vc.lock, flags); + vchan_dma_desc_free_list(&sdmac->vc, &head); +- sdmac->context_loaded = false; + } + + static int sdma_terminate_all(struct dma_chan *chan) +@@ -1168,7 +1161,6 @@ static void sdma_set_watermarklevel_for_p2p(struct sdma_channel *sdmac) + static int sdma_config_channel(struct dma_chan *chan) + { + struct sdma_channel *sdmac = to_sdma_chan(chan); +- int ret; + + sdma_disable_channel(chan); + +@@ -1208,9 +1200,7 @@ static int sdma_config_channel(struct dma_chan *chan) + sdmac->watermark_level = 0; /* FIXME: M3_BASE_ADDRESS */ + } + +- ret = sdma_load_context(sdmac); +- +- return ret; ++ return 0; + } + + static int sdma_set_channel_priority(struct sdma_channel *sdmac, +@@ -1361,7 +1351,6 @@ static void sdma_free_chan_resources(struct dma_chan *chan) + + sdmac->event_id0 = 0; + sdmac->event_id1 = 0; +- sdmac->context_loaded = false; + + sdma_set_channel_priority(sdmac, 0); + +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +index 8e5a7ac8c36fc..7a73167319116 100644 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +@@ -522,6 +522,7 @@ uint32_t amdgpu_display_supported_domains(struct amdgpu_device *adev, + break; + case CHIP_RENOIR: + case CHIP_VANGOGH: ++ case CHIP_YELLOW_CARP: + domain |= AMDGPU_GEM_DOMAIN_GTT; + break; + +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +index 854fc497844b8..9a67746c10edd 100644 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +@@ -341,21 +341,18 @@ retry: + r = amdgpu_gem_object_create(adev, size, args->in.alignment, + initial_domain, + flags, ttm_bo_type_device, resv, &gobj); +- if (r) { +- if (r != -ERESTARTSYS) { +- if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) { +- flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; +- goto retry; +- } ++ if (r && r != -ERESTARTSYS) { ++ if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) { ++ flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; ++ goto retry; ++ } + +- if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) { +- initial_domain |= AMDGPU_GEM_DOMAIN_GTT; +- goto retry; +- } +- DRM_DEBUG("Failed to allocate GEM object (%llu, %d, %llu, %d)\n", +- size, initial_domain, args->in.alignment, r); ++ if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) { ++ initial_domain |= AMDGPU_GEM_DOMAIN_GTT; ++ goto retry; + } +- return r; ++ DRM_DEBUG("Failed to allocate GEM object (%llu, %d, %llu, %d)\n", ++ size, initial_domain, args->in.alignment, r); + } + + if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) { +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +index bca4dddd5a15b..82608df433964 100644 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +@@ -339,7 +339,7 @@ static void amdgpu_i2c_put_byte(struct amdgpu_i2c_chan *i2c_bus, + void + amdgpu_i2c_router_select_ddc_port(const struct amdgpu_connector *amdgpu_connector) + { +- u8 val; ++ u8 val = 0; + + if (!amdgpu_connector->router.ddc_valid) + return; +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +index 92c8e6e7f346b..def812f6231aa 100644 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +@@ -196,7 +196,7 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain) + c++; + } + +- BUG_ON(c >= AMDGPU_BO_MAX_PLACEMENTS); ++ BUG_ON(c > AMDGPU_BO_MAX_PLACEMENTS); + + placement->num_placement = c; + placement->placement = places; +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +index fc66aca285944..95d5842385b32 100644 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +@@ -1966,11 +1966,20 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev) + bool exc_err_limit = false; + int ret; + +- if (adev->ras_enabled && con) +- data = &con->eh_data; +- else ++ if (!con) ++ return 0; ++ ++ /* Allow access to RAS EEPROM via debugfs, when the ASIC ++ * supports RAS and debugfs is enabled, but when ++ * adev->ras_enabled is unset, i.e. when "ras_enable" ++ * module parameter is set to 0. ++ */ ++ con->adev = adev; ++ ++ if (!adev->ras_enabled) + return 0; + ++ data = &con->eh_data; + *data = kmalloc(sizeof(**data), GFP_KERNEL | __GFP_ZERO); + if (!*data) { + ret = -ENOMEM; +@@ -1980,7 +1989,6 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev) + mutex_init(&con->recovery_lock); + INIT_WORK(&con->recovery_work, amdgpu_ras_do_recovery); + atomic_set(&con->in_recovery, 0); +- con->adev = adev; + + max_eeprom_records_len = amdgpu_ras_eeprom_get_record_max_length(); + amdgpu_ras_validate_threshold(adev, max_eeprom_records_len); +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +index 38222de921d15..8dd151c9e4591 100644 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +@@ -325,7 +325,7 @@ int amdgpu_ras_eeprom_init(struct amdgpu_ras_eeprom_control *control, + return ret; + } + +- __decode_table_header_from_buff(hdr, &buff[2]); ++ __decode_table_header_from_buff(hdr, buff); + + if (hdr->header == EEPROM_TABLE_HDR_VAL) { + control->num_recs = (hdr->tbl_size - EEPROM_TABLE_HEADER_SIZE) / +diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +index 284bb42d6c866..121ee9f2b8d16 100644 +--- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c ++++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +@@ -119,7 +119,7 @@ static int vcn_v1_0_sw_init(void *handle) + adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw; + adev->firmware.fw_size += + ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE); +- DRM_INFO("PSP loading VCN firmware\n"); ++ dev_info(adev->dev, "Will use PSP to load VCN firmware\n"); + } + + r = amdgpu_vcn_resume(adev); +diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +index 8af567c546dbc..f4686e918e0d1 100644 +--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c ++++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +@@ -122,7 +122,7 @@ static int vcn_v2_0_sw_init(void *handle) + adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw; + adev->firmware.fw_size += + ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE); +- DRM_INFO("PSP loading VCN firmware\n"); ++ dev_info(adev->dev, "Will use PSP to load VCN firmware\n"); + } + + r = amdgpu_vcn_resume(adev); +diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +index 888b17d84691c..e0c0c3734432e 100644 +--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c ++++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +@@ -152,7 +152,7 @@ static int vcn_v2_5_sw_init(void *handle) + adev->firmware.fw_size += + ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE); + } +- DRM_INFO("PSP loading VCN firmware\n"); ++ dev_info(adev->dev, "Will use PSP to load VCN firmware\n"); + } + + r = amdgpu_vcn_resume(adev); +diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +index 47d4f04cbd69e..2f017560948eb 100644 +--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c ++++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +@@ -160,7 +160,7 @@ static int vcn_v3_0_sw_init(void *handle) + adev->firmware.fw_size += + ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE); + } +- DRM_INFO("PSP loading VCN firmware\n"); ++ dev_info(adev->dev, "Will use PSP to load VCN firmware\n"); + } + + r = amdgpu_vcn_resume(adev); +diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c +index 88813dad731fa..c021519af8106 100644 +--- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c ++++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c +@@ -98,36 +98,78 @@ void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm, + uint32_t *se_mask) + { + struct kfd_cu_info cu_info; +- uint32_t cu_per_se[KFD_MAX_NUM_SE] = {0}; +- int i, se, sh, cu = 0; +- ++ uint32_t cu_per_sh[KFD_MAX_NUM_SE][KFD_MAX_NUM_SH_PER_SE] = {0}; ++ int i, se, sh, cu; + amdgpu_amdkfd_get_cu_info(mm->dev->kgd, &cu_info); + + if (cu_mask_count > cu_info.cu_active_number) + cu_mask_count = cu_info.cu_active_number; + ++ /* Exceeding these bounds corrupts the stack and indicates a coding error. ++ * Returning with no CU's enabled will hang the queue, which should be ++ * attention grabbing. ++ */ ++ if (cu_info.num_shader_engines > KFD_MAX_NUM_SE) { ++ pr_err("Exceeded KFD_MAX_NUM_SE, chip reports %d\n", cu_info.num_shader_engines); ++ return; ++ } ++ if (cu_info.num_shader_arrays_per_engine > KFD_MAX_NUM_SH_PER_SE) { ++ pr_err("Exceeded KFD_MAX_NUM_SH, chip reports %d\n", ++ cu_info.num_shader_arrays_per_engine * cu_info.num_shader_engines); ++ return; ++ } ++ /* Count active CUs per SH. ++ * ++ * Some CUs in an SH may be disabled. HW expects disabled CUs to be ++ * represented in the high bits of each SH's enable mask (the upper and lower ++ * 16 bits of se_mask) and will take care of the actual distribution of ++ * disabled CUs within each SH automatically. ++ * Each half of se_mask must be filled only on bits 0-cu_per_sh[se][sh]-1. ++ * ++ * See note on Arcturus cu_bitmap layout in gfx_v9_0_get_cu_info. ++ */ + for (se = 0; se < cu_info.num_shader_engines; se++) + for (sh = 0; sh < cu_info.num_shader_arrays_per_engine; sh++) +- cu_per_se[se] += hweight32(cu_info.cu_bitmap[se % 4][sh + (se / 4)]); +- +- /* Symmetrically map cu_mask to all SEs: +- * cu_mask[0] bit0 -> se_mask[0] bit0; +- * cu_mask[0] bit1 -> se_mask[1] bit0; +- * ... (if # SE is 4) +- * cu_mask[0] bit4 -> se_mask[0] bit1; ++ cu_per_sh[se][sh] = hweight32(cu_info.cu_bitmap[se % 4][sh + (se / 4)]); ++ ++ /* Symmetrically map cu_mask to all SEs & SHs: ++ * se_mask programs up to 2 SH in the upper and lower 16 bits. ++ * ++ * Examples ++ * Assuming 1 SH/SE, 4 SEs: ++ * cu_mask[0] bit0 -> se_mask[0] bit0 ++ * cu_mask[0] bit1 -> se_mask[1] bit0 ++ * ... ++ * cu_mask[0] bit4 -> se_mask[0] bit1 ++ * ... ++ * ++ * Assuming 2 SH/SE, 4 SEs ++ * cu_mask[0] bit0 -> se_mask[0] bit0 (SE0,SH0,CU0) ++ * cu_mask[0] bit1 -> se_mask[1] bit0 (SE1,SH0,CU0) ++ * ... ++ * cu_mask[0] bit4 -> se_mask[0] bit16 (SE0,SH1,CU0) ++ * cu_mask[0] bit5 -> se_mask[1] bit16 (SE1,SH1,CU0) ++ * ... ++ * cu_mask[0] bit8 -> se_mask[0] bit1 (SE0,SH0,CU1) + * ... ++ * ++ * First ensure all CUs are disabled, then enable user specified CUs. + */ +- se = 0; +- for (i = 0; i < cu_mask_count; i++) { +- if (cu_mask[i / 32] & (1 << (i % 32))) +- se_mask[se] |= 1 << cu; +- +- do { +- se++; +- if (se == cu_info.num_shader_engines) { +- se = 0; +- cu++; ++ for (i = 0; i < cu_info.num_shader_engines; i++) ++ se_mask[i] = 0; ++ ++ i = 0; ++ for (cu = 0; cu < 16; cu++) { ++ for (sh = 0; sh < cu_info.num_shader_arrays_per_engine; sh++) { ++ for (se = 0; se < cu_info.num_shader_engines; se++) { ++ if (cu_per_sh[se][sh] > cu) { ++ if (cu_mask[i / 32] & (1 << (i % 32))) ++ se_mask[se] |= 1 << (cu + sh * 16); ++ i++; ++ if (i == cu_mask_count) ++ return; ++ } + } +- } while (cu >= cu_per_se[se] && cu < 32); ++ } + } + } +diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h +index b5e2ea7550d41..6e6918ccedfdb 100644 +--- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h ++++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h +@@ -27,6 +27,7 @@ + #include "kfd_priv.h" + + #define KFD_MAX_NUM_SE 8 ++#define KFD_MAX_NUM_SH_PER_SE 2 + + /** + * struct mqd_manager +diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +index e883731c3f8ff..0f7f1e5621ea4 100644 +--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c ++++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +@@ -2426,7 +2426,8 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid, + } + if (!p->xnack_enabled) { + pr_debug("XNACK not enabled for pasid 0x%x\n", pasid); +- return -EFAULT; ++ r = -EFAULT; ++ goto out; + } + svms = &p->svms; + +diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +index afa96c8f721b7..3f913e4abd49e 100644 +--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c ++++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +@@ -1202,7 +1202,7 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) + dc_hardware_init(adev->dm.dc); + + #if defined(CONFIG_DRM_AMD_DC_DCN) +- if (adev->apu_flags) { ++ if ((adev->flags & AMD_IS_APU) && (adev->asic_type >= CHIP_CARRIZO)) { + struct dc_phy_addr_space_config pa_config; + + mmhub_read_system_context(adev, &pa_config); +diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +index f1145086a4688..1d15a9af99560 100644 +--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c ++++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +@@ -197,29 +197,29 @@ static ssize_t dp_link_settings_read(struct file *f, char __user *buf, + + rd_buf_ptr = rd_buf; + +- str_len = strlen("Current: %d %d %d "); +- snprintf(rd_buf_ptr, str_len, "Current: %d %d %d ", ++ str_len = strlen("Current: %d 0x%x %d "); ++ snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ", + link->cur_link_settings.lane_count, + link->cur_link_settings.link_rate, + link->cur_link_settings.link_spread); + rd_buf_ptr += str_len; + +- str_len = strlen("Verified: %d %d %d "); +- snprintf(rd_buf_ptr, str_len, "Verified: %d %d %d ", ++ str_len = strlen("Verified: %d 0x%x %d "); ++ snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ", + link->verified_link_cap.lane_count, + link->verified_link_cap.link_rate, + link->verified_link_cap.link_spread); + rd_buf_ptr += str_len; + +- str_len = strlen("Reported: %d %d %d "); +- snprintf(rd_buf_ptr, str_len, "Reported: %d %d %d ", ++ str_len = strlen("Reported: %d 0x%x %d "); ++ snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ", + link->reported_link_cap.lane_count, + link->reported_link_cap.link_rate, + link->reported_link_cap.link_spread); + rd_buf_ptr += str_len; + +- str_len = strlen("Preferred: %d %d %d "); +- snprintf(rd_buf_ptr, str_len, "Preferred: %d %d %d\n", ++ str_len = strlen("Preferred: %d 0x%x %d "); ++ snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n", + link->preferred_link_setting.lane_count, + link->preferred_link_setting.link_rate, + link->preferred_link_setting.link_spread); +diff --git a/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c b/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c +index 10d42ae0cffef..3428334c6c575 100644 +--- a/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c ++++ b/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c +@@ -207,7 +207,7 @@ static void dmub_psr_set_level(struct dmub_psr *dmub, uint16_t psr_level, uint8_ + cmd.psr_set_level.header.sub_type = DMUB_CMD__PSR_SET_LEVEL; + cmd.psr_set_level.header.payload_bytes = sizeof(struct dmub_cmd_psr_set_level_data); + cmd.psr_set_level.psr_set_level_data.psr_level = psr_level; +- cmd.psr_set_level.psr_set_level_data.cmd_version = PSR_VERSION_1; ++ cmd.psr_set_level.psr_set_level_data.cmd_version = DMUB_CMD_PSR_CONTROL_VERSION_1; + cmd.psr_set_level.psr_set_level_data.panel_inst = panel_inst; + dc_dmub_srv_cmd_queue(dc->dmub_srv, &cmd); + dc_dmub_srv_cmd_execute(dc->dmub_srv); +@@ -293,7 +293,7 @@ static bool dmub_psr_copy_settings(struct dmub_psr *dmub, + copy_settings_data->debug.bitfields.use_hw_lock_mgr = 1; + copy_settings_data->fec_enable_status = (link->fec_state == dc_link_fec_enabled); + copy_settings_data->fec_enable_delay_in100us = link->dc->debug.fec_enable_delay_in100us; +- copy_settings_data->cmd_version = PSR_VERSION_1; ++ copy_settings_data->cmd_version = DMUB_CMD_PSR_CONTROL_VERSION_1; + copy_settings_data->panel_inst = panel_inst; + + dc_dmub_srv_cmd_queue(dc->dmub_srv, &cmd); +diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c +index c545eddabdcca..75fa4adcf5f40 100644 +--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c ++++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c +@@ -1502,25 +1502,22 @@ void dcn10_init_hw(struct dc *dc) + void dcn10_power_down_on_boot(struct dc *dc) + { + struct dc_link *edp_links[MAX_NUM_EDP]; +- struct dc_link *edp_link; ++ struct dc_link *edp_link = NULL; + int edp_num; + int i = 0; + + get_edp_links(dc, edp_links, &edp_num); +- +- if (edp_num) { +- for (i = 0; i < edp_num; i++) { +- edp_link = edp_links[i]; +- if (edp_link->link_enc->funcs->is_dig_enabled && +- edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) && +- dc->hwseq->funcs.edp_backlight_control && +- dc->hwss.power_down && +- dc->hwss.edp_power_control) { +- dc->hwseq->funcs.edp_backlight_control(edp_link, false); +- dc->hwss.power_down(dc); +- dc->hwss.edp_power_control(edp_link, false); +- } +- } ++ if (edp_num) ++ edp_link = edp_links[0]; ++ ++ if (edp_link && edp_link->link_enc->funcs->is_dig_enabled && ++ edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) && ++ dc->hwseq->funcs.edp_backlight_control && ++ dc->hwss.power_down && ++ dc->hwss.edp_power_control) { ++ dc->hwseq->funcs.edp_backlight_control(edp_link, false); ++ dc->hwss.power_down(dc); ++ dc->hwss.edp_power_control(edp_link, false); + } else { + for (i = 0; i < dc->link_count; i++) { + struct dc_link *link = dc->links[i]; +@@ -3631,13 +3628,12 @@ enum dc_status dcn10_set_clock(struct dc *dc, + struct dc_clock_config clock_cfg = {0}; + struct dc_clocks *current_clocks = &context->bw_ctx.bw.dcn.clk; + +- if (dc->clk_mgr && dc->clk_mgr->funcs->get_clock) +- dc->clk_mgr->funcs->get_clock(dc->clk_mgr, +- context, clock_type, &clock_cfg); +- +- if (!dc->clk_mgr->funcs->get_clock) ++ if (!dc->clk_mgr || !dc->clk_mgr->funcs->get_clock) + return DC_FAIL_UNSUPPORTED_1; + ++ dc->clk_mgr->funcs->get_clock(dc->clk_mgr, ++ context, clock_type, &clock_cfg); ++ + if (clk_khz > clock_cfg.max_clock_khz) + return DC_FAIL_CLK_EXCEED_MAX; + +@@ -3655,7 +3651,7 @@ enum dc_status dcn10_set_clock(struct dc *dc, + else + return DC_ERROR_UNEXPECTED; + +- if (dc->clk_mgr && dc->clk_mgr->funcs->update_clocks) ++ if (dc->clk_mgr->funcs->update_clocks) + dc->clk_mgr->funcs->update_clocks(dc->clk_mgr, + context, true); + return DC_OK; +diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c +index 5c2853654ccad..a47ba1d45be92 100644 +--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c ++++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c +@@ -1723,13 +1723,15 @@ void dcn20_program_front_end_for_ctx( + + pipe = pipe->bottom_pipe; + } +- /* Program secondary blending tree and writeback pipes */ +- pipe = &context->res_ctx.pipe_ctx[i]; +- if (!pipe->prev_odm_pipe && pipe->stream->num_wb_info > 0 +- && (pipe->update_flags.raw || pipe->plane_state->update_flags.raw || pipe->stream->update_flags.raw) +- && hws->funcs.program_all_writeback_pipes_in_tree) +- hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context); + } ++ /* Program secondary blending tree and writeback pipes */ ++ pipe = &context->res_ctx.pipe_ctx[i]; ++ if (!pipe->top_pipe && !pipe->prev_odm_pipe ++ && pipe->stream && pipe->stream->num_wb_info > 0 ++ && (pipe->update_flags.raw || (pipe->plane_state && pipe->plane_state->update_flags.raw) ++ || pipe->stream->update_flags.raw) ++ && hws->funcs.program_all_writeback_pipes_in_tree) ++ hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context); + } + } + +diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +index b173fa3653b55..c78933a9d31c1 100644 +--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c ++++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +@@ -2462,7 +2462,7 @@ void dcn20_set_mcif_arb_params( + wb_arb_params->cli_watermark[k] = get_wm_writeback_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; + wb_arb_params->pstate_watermark[k] = get_wm_writeback_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; + } +- wb_arb_params->time_per_pixel = 16.0 / context->res_ctx.pipe_ctx[i].stream->phy_pix_clk; /* 4 bit fraction, ms */ ++ wb_arb_params->time_per_pixel = 16.0 * 1000 / (context->res_ctx.pipe_ctx[i].stream->phy_pix_clk / 1000); /* 4 bit fraction, ms */ + wb_arb_params->slice_lines = 32; + wb_arb_params->arbitration_slice = 2; + wb_arb_params->max_scaled_time = dcn20_calc_max_scaled_time(wb_arb_params->time_per_pixel, +diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c +index 3fe9e41e4dbd7..6a3d3a0ec0a36 100644 +--- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c ++++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c +@@ -49,6 +49,11 @@ + static void dwb3_get_reg_field_ogam(struct dcn30_dwbc *dwbc30, + struct dcn3_xfer_func_reg *reg) + { ++ reg->shifts.field_region_start_base = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_BASE_B; ++ reg->masks.field_region_start_base = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_START_BASE_B; ++ reg->shifts.field_offset = dwbc30->dwbc_shift->DWB_OGAM_RAMA_OFFSET_B; ++ reg->masks.field_offset = dwbc30->dwbc_mask->DWB_OGAM_RAMA_OFFSET_B; ++ + reg->shifts.exp_region0_lut_offset = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION0_LUT_OFFSET; + reg->masks.exp_region0_lut_offset = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION0_LUT_OFFSET; + reg->shifts.exp_region0_num_segments = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION0_NUM_SEGMENTS; +@@ -66,8 +71,6 @@ static void dwb3_get_reg_field_ogam(struct dcn30_dwbc *dwbc30, + reg->masks.field_region_end_base = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_END_BASE_B; + reg->shifts.field_region_linear_slope = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_SLOPE_B; + reg->masks.field_region_linear_slope = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_START_SLOPE_B; +- reg->masks.field_offset = dwbc30->dwbc_mask->DWB_OGAM_RAMA_OFFSET_B; +- reg->shifts.field_offset = dwbc30->dwbc_shift->DWB_OGAM_RAMA_OFFSET_B; + reg->shifts.exp_region_start = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_B; + reg->masks.exp_region_start = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_START_B; + reg->shifts.exp_resion_start_segment = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_SEGMENT_B; +@@ -147,18 +150,19 @@ static enum dc_lut_mode dwb3_get_ogam_current( + uint32_t state_mode; + uint32_t ram_select; + +- REG_GET(DWB_OGAM_CONTROL, +- DWB_OGAM_MODE, &state_mode); +- REG_GET(DWB_OGAM_CONTROL, +- DWB_OGAM_SELECT, &ram_select); ++ REG_GET_2(DWB_OGAM_CONTROL, ++ DWB_OGAM_MODE_CURRENT, &state_mode, ++ DWB_OGAM_SELECT_CURRENT, &ram_select); + + if (state_mode == 0) { + mode = LUT_BYPASS; + } else if (state_mode == 2) { + if (ram_select == 0) + mode = LUT_RAM_A; +- else ++ else if (ram_select == 1) + mode = LUT_RAM_B; ++ else ++ mode = LUT_BYPASS; + } else { + // Reserved value + mode = LUT_BYPASS; +@@ -172,10 +176,10 @@ static void dwb3_configure_ogam_lut( + struct dcn30_dwbc *dwbc30, + bool is_ram_a) + { +- REG_UPDATE(DWB_OGAM_LUT_CONTROL, +- DWB_OGAM_LUT_READ_COLOR_SEL, 7); +- REG_UPDATE(DWB_OGAM_CONTROL, +- DWB_OGAM_SELECT, is_ram_a == true ? 0 : 1); ++ REG_UPDATE_2(DWB_OGAM_LUT_CONTROL, ++ DWB_OGAM_LUT_WRITE_COLOR_MASK, 7, ++ DWB_OGAM_LUT_HOST_SEL, (is_ram_a == true) ? 0 : 1); ++ + REG_SET(DWB_OGAM_LUT_INDEX, 0, DWB_OGAM_LUT_INDEX, 0); + } + +@@ -185,17 +189,45 @@ static void dwb3_program_ogam_pwl(struct dcn30_dwbc *dwbc30, + { + uint32_t i; + +- // triple base implementation +- for (i = 0; i < num/2; i++) { +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+0].red_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+0].green_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+0].blue_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+1].red_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+1].green_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+1].blue_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+2].red_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+2].green_reg); +- REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[2*i+2].blue_reg); ++ uint32_t last_base_value_red = rgb[num-1].red_reg + rgb[num-1].delta_red_reg; ++ uint32_t last_base_value_green = rgb[num-1].green_reg + rgb[num-1].delta_green_reg; ++ uint32_t last_base_value_blue = rgb[num-1].blue_reg + rgb[num-1].delta_blue_reg; ++ ++ if (is_rgb_equal(rgb, num)) { ++ for (i = 0 ; i < num; i++) ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].red_reg); ++ ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_red); ++ ++ } else { ++ ++ REG_UPDATE(DWB_OGAM_LUT_CONTROL, ++ DWB_OGAM_LUT_WRITE_COLOR_MASK, 4); ++ ++ for (i = 0 ; i < num; i++) ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].red_reg); ++ ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_red); ++ ++ REG_SET(DWB_OGAM_LUT_INDEX, 0, DWB_OGAM_LUT_INDEX, 0); ++ ++ REG_UPDATE(DWB_OGAM_LUT_CONTROL, ++ DWB_OGAM_LUT_WRITE_COLOR_MASK, 2); ++ ++ for (i = 0 ; i < num; i++) ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].green_reg); ++ ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_green); ++ ++ REG_SET(DWB_OGAM_LUT_INDEX, 0, DWB_OGAM_LUT_INDEX, 0); ++ ++ REG_UPDATE(DWB_OGAM_LUT_CONTROL, ++ DWB_OGAM_LUT_WRITE_COLOR_MASK, 1); ++ ++ for (i = 0 ; i < num; i++) ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].blue_reg); ++ ++ REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_blue); + } + } + +@@ -211,6 +243,8 @@ static bool dwb3_program_ogam_lut( + return false; + } + ++ REG_SET(DWB_OGAM_CONTROL, 0, DWB_OGAM_MODE, 2); ++ + current_mode = dwb3_get_ogam_current(dwbc30); + if (current_mode == LUT_BYPASS || current_mode == LUT_RAM_A) + next_mode = LUT_RAM_B; +@@ -227,8 +261,7 @@ static bool dwb3_program_ogam_lut( + dwb3_program_ogam_pwl( + dwbc30, params->rgb_resulted, params->hw_points_num); + +- REG_SET(DWB_OGAM_CONTROL, 0, DWB_OGAM_MODE, 2); +- REG_SET(DWB_OGAM_CONTROL, 0, DWB_OGAM_SELECT, next_mode == LUT_RAM_A ? 0 : 1); ++ REG_UPDATE(DWB_OGAM_CONTROL, DWB_OGAM_SELECT, next_mode == LUT_RAM_A ? 0 : 1); + + return true; + } +@@ -271,14 +304,19 @@ static void dwb3_program_gamut_remap( + + struct color_matrices_reg gam_regs; + +- REG_UPDATE(DWB_GAMUT_REMAP_COEF_FORMAT, DWB_GAMUT_REMAP_COEF_FORMAT, coef_format); +- + if (regval == NULL || select == CM_GAMUT_REMAP_MODE_BYPASS) { + REG_SET(DWB_GAMUT_REMAP_MODE, 0, + DWB_GAMUT_REMAP_MODE, 0); + return; + } + ++ REG_UPDATE(DWB_GAMUT_REMAP_COEF_FORMAT, DWB_GAMUT_REMAP_COEF_FORMAT, coef_format); ++ ++ gam_regs.shifts.csc_c11 = dwbc30->dwbc_shift->DWB_GAMUT_REMAPA_C11; ++ gam_regs.masks.csc_c11 = dwbc30->dwbc_mask->DWB_GAMUT_REMAPA_C11; ++ gam_regs.shifts.csc_c12 = dwbc30->dwbc_shift->DWB_GAMUT_REMAPA_C12; ++ gam_regs.masks.csc_c12 = dwbc30->dwbc_mask->DWB_GAMUT_REMAPA_C12; ++ + switch (select) { + case CM_GAMUT_REMAP_MODE_RAMA_COEFF: + gam_regs.csc_c11_c12 = REG(DWB_GAMUT_REMAPA_C11_C12); +diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c +index c68e3a708a335..fafed1e4a998d 100644 +--- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c ++++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c +@@ -398,12 +398,22 @@ void dcn30_program_all_writeback_pipes_in_tree( + for (i_pipe = 0; i_pipe < dc->res_pool->pipe_count; i_pipe++) { + struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i_pipe]; + ++ if (!pipe_ctx->plane_state) ++ continue; ++ + if (pipe_ctx->plane_state == wb_info.writeback_source_plane) { + wb_info.mpcc_inst = pipe_ctx->plane_res.mpcc_inst; + break; + } + } +- ASSERT(wb_info.mpcc_inst != -1); ++ ++ if (wb_info.mpcc_inst == -1) { ++ /* Disable writeback pipe and disconnect from MPCC ++ * if source plane has been removed ++ */ ++ dc->hwss.disable_writeback(dc, wb_info.dwb_pipe_inst); ++ continue; ++ } + + ASSERT(wb_info.dwb_pipe_inst < dc->res_pool->res_cap->num_dwb); + dwb = dc->res_pool->dwbc[wb_info.dwb_pipe_inst]; +@@ -580,22 +590,19 @@ void dcn30_init_hw(struct dc *dc) + */ + if (dc->config.power_down_display_on_boot) { + struct dc_link *edp_links[MAX_NUM_EDP]; +- struct dc_link *edp_link; ++ struct dc_link *edp_link = NULL; + + get_edp_links(dc, edp_links, &edp_num); +- if (edp_num) { +- for (i = 0; i < edp_num; i++) { +- edp_link = edp_links[i]; +- if (edp_link->link_enc->funcs->is_dig_enabled && +- edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) && +- dc->hwss.edp_backlight_control && +- dc->hwss.power_down && +- dc->hwss.edp_power_control) { +- dc->hwss.edp_backlight_control(edp_link, false); +- dc->hwss.power_down(dc); +- dc->hwss.edp_power_control(edp_link, false); +- } +- } ++ if (edp_num) ++ edp_link = edp_links[0]; ++ if (edp_link && edp_link->link_enc->funcs->is_dig_enabled && ++ edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) && ++ dc->hwss.edp_backlight_control && ++ dc->hwss.power_down && ++ dc->hwss.edp_power_control) { ++ dc->hwss.edp_backlight_control(edp_link, false); ++ dc->hwss.power_down(dc); ++ dc->hwss.edp_power_control(edp_link, false); + } else { + for (i = 0; i < dc->link_count; i++) { + struct dc_link *link = dc->links[i]; +diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c +index 28e15ebf2f431..23a246b62d5d7 100644 +--- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c ++++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c +@@ -2398,16 +2398,37 @@ void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params + dc->dml.soc.dispclk_dppclk_vco_speed_mhz = dc->clk_mgr->dentist_vco_freq_khz / 1000.0; + + if (bw_params->clk_table.entries[0].memclk_mhz) { ++ int max_dcfclk_mhz = 0, max_dispclk_mhz = 0, max_dppclk_mhz = 0, max_phyclk_mhz = 0; ++ ++ for (i = 0; i < MAX_NUM_DPM_LVL; i++) { ++ if (bw_params->clk_table.entries[i].dcfclk_mhz > max_dcfclk_mhz) ++ max_dcfclk_mhz = bw_params->clk_table.entries[i].dcfclk_mhz; ++ if (bw_params->clk_table.entries[i].dispclk_mhz > max_dispclk_mhz) ++ max_dispclk_mhz = bw_params->clk_table.entries[i].dispclk_mhz; ++ if (bw_params->clk_table.entries[i].dppclk_mhz > max_dppclk_mhz) ++ max_dppclk_mhz = bw_params->clk_table.entries[i].dppclk_mhz; ++ if (bw_params->clk_table.entries[i].phyclk_mhz > max_phyclk_mhz) ++ max_phyclk_mhz = bw_params->clk_table.entries[i].phyclk_mhz; ++ } ++ ++ if (!max_dcfclk_mhz) ++ max_dcfclk_mhz = dcn3_0_soc.clock_limits[0].dcfclk_mhz; ++ if (!max_dispclk_mhz) ++ max_dispclk_mhz = dcn3_0_soc.clock_limits[0].dispclk_mhz; ++ if (!max_dppclk_mhz) ++ max_dppclk_mhz = dcn3_0_soc.clock_limits[0].dppclk_mhz; ++ if (!max_phyclk_mhz) ++ max_phyclk_mhz = dcn3_0_soc.clock_limits[0].phyclk_mhz; + +- if (bw_params->clk_table.entries[1].dcfclk_mhz > dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { ++ if (max_dcfclk_mhz > dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { + // If max DCFCLK is greater than the max DCFCLK STA target, insert into the DCFCLK STA target array +- dcfclk_sta_targets[num_dcfclk_sta_targets] = bw_params->clk_table.entries[1].dcfclk_mhz; ++ dcfclk_sta_targets[num_dcfclk_sta_targets] = max_dcfclk_mhz; + num_dcfclk_sta_targets++; +- } else if (bw_params->clk_table.entries[1].dcfclk_mhz < dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { ++ } else if (max_dcfclk_mhz < dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { + // If max DCFCLK is less than the max DCFCLK STA target, cap values and remove duplicates + for (i = 0; i < num_dcfclk_sta_targets; i++) { +- if (dcfclk_sta_targets[i] > bw_params->clk_table.entries[1].dcfclk_mhz) { +- dcfclk_sta_targets[i] = bw_params->clk_table.entries[1].dcfclk_mhz; ++ if (dcfclk_sta_targets[i] > max_dcfclk_mhz) { ++ dcfclk_sta_targets[i] = max_dcfclk_mhz; + break; + } + } +@@ -2447,7 +2468,7 @@ void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params + dcfclk_mhz[num_states] = dcfclk_sta_targets[i]; + dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++]; + } else { +- if (j < num_uclk_states && optimal_dcfclk_for_uclk[j] <= bw_params->clk_table.entries[1].dcfclk_mhz) { ++ if (j < num_uclk_states && optimal_dcfclk_for_uclk[j] <= max_dcfclk_mhz) { + dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j]; + dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16; + } else { +@@ -2462,11 +2483,12 @@ void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params + } + + while (j < num_uclk_states && num_states < DC__VOLTAGE_STATES && +- optimal_dcfclk_for_uclk[j] <= bw_params->clk_table.entries[1].dcfclk_mhz) { ++ optimal_dcfclk_for_uclk[j] <= max_dcfclk_mhz) { + dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j]; + dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16; + } + ++ dcn3_0_soc.num_states = num_states; + for (i = 0; i < dcn3_0_soc.num_states; i++) { + dcn3_0_soc.clock_limits[i].state = i; + dcn3_0_soc.clock_limits[i].dcfclk_mhz = dcfclk_mhz[i]; +@@ -2474,9 +2496,9 @@ void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params + dcn3_0_soc.clock_limits[i].dram_speed_mts = dram_speed_mts[i]; + + /* Fill all states with max values of all other clocks */ +- dcn3_0_soc.clock_limits[i].dispclk_mhz = bw_params->clk_table.entries[1].dispclk_mhz; +- dcn3_0_soc.clock_limits[i].dppclk_mhz = bw_params->clk_table.entries[1].dppclk_mhz; +- dcn3_0_soc.clock_limits[i].phyclk_mhz = bw_params->clk_table.entries[1].phyclk_mhz; ++ dcn3_0_soc.clock_limits[i].dispclk_mhz = max_dispclk_mhz; ++ dcn3_0_soc.clock_limits[i].dppclk_mhz = max_dppclk_mhz; ++ dcn3_0_soc.clock_limits[i].phyclk_mhz = max_phyclk_mhz; + dcn3_0_soc.clock_limits[i].dtbclk_mhz = dcn3_0_soc.clock_limits[0].dtbclk_mhz; + /* These clocks cannot come from bw_params, always fill from dcn3_0_soc[1] */ + /* FCLK, PHYCLK_D18, SOCCLK, DSCCLK */ +diff --git a/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_hwseq.c b/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_hwseq.c +index 8a2119d8ca0de..8189606537c5a 100644 +--- a/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_hwseq.c ++++ b/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_hwseq.c +@@ -226,6 +226,7 @@ void dcn31_init_hw(struct dc *dc) + if (dc->config.power_down_display_on_boot) { + struct dc_link *edp_links[MAX_NUM_EDP]; + struct dc_link *edp_link; ++ bool power_down = false; + + get_edp_links(dc, edp_links, &edp_num); + if (edp_num) { +@@ -239,9 +240,11 @@ void dcn31_init_hw(struct dc *dc) + dc->hwss.edp_backlight_control(edp_link, false); + dc->hwss.power_down(dc); + dc->hwss.edp_power_control(edp_link, false); ++ power_down = true; + } + } +- } else { ++ } ++ if (!power_down) { + for (i = 0; i < dc->link_count; i++) { + struct dc_link *link = dc->links[i]; + +diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h +index 911f9f4147741..39ca338eb80b3 100644 +--- a/drivers/gpu/drm/ast/ast_drv.h ++++ b/drivers/gpu/drm/ast/ast_drv.h +@@ -337,6 +337,11 @@ int ast_mode_config_init(struct ast_private *ast); + #define AST_DP501_LINKRATE 0xf014 + #define AST_DP501_EDID_DATA 0xf020 + ++/* Define for Soc scratched reg */ ++#define AST_VRAM_INIT_STATUS_MASK GENMASK(7, 6) ++//#define AST_VRAM_INIT_BY_BMC BIT(7) ++//#define AST_VRAM_INIT_READY BIT(6) ++ + int ast_mm_init(struct ast_private *ast); + + /* ast post */ +@@ -346,6 +351,7 @@ bool ast_is_vga_enabled(struct drm_device *dev); + void ast_post_gpu(struct drm_device *dev); + u32 ast_mindwm(struct ast_private *ast, u32 r); + void ast_moutdwm(struct ast_private *ast, u32 r, u32 v); ++void ast_patch_ahb_2500(struct ast_private *ast); + /* ast dp501 */ + void ast_set_dp501_video_output(struct drm_device *dev, u8 mode); + bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size); +diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c +index 2aff2e6cf450c..79a3618679554 100644 +--- a/drivers/gpu/drm/ast/ast_main.c ++++ b/drivers/gpu/drm/ast/ast_main.c +@@ -97,6 +97,11 @@ static void ast_detect_config_mode(struct drm_device *dev, u32 *scu_rev) + jregd0 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); + jregd1 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff); + if (!(jregd0 & 0x80) || !(jregd1 & 0x10)) { ++ /* Patch AST2500 */ ++ if (((pdev->revision & 0xF0) == 0x40) ++ && ((jregd0 & AST_VRAM_INIT_STATUS_MASK) == 0)) ++ ast_patch_ahb_2500(ast); ++ + /* Double check it's actually working */ + data = ast_read32(ast, 0xf004); + if ((data != 0xFFFFFFFF) && (data != 0x00)) { +diff --git a/drivers/gpu/drm/ast/ast_post.c b/drivers/gpu/drm/ast/ast_post.c +index 0607658dde51b..b5d92f652fd85 100644 +--- a/drivers/gpu/drm/ast/ast_post.c ++++ b/drivers/gpu/drm/ast/ast_post.c +@@ -2028,6 +2028,40 @@ static bool ast_dram_init_2500(struct ast_private *ast) + return true; + } + ++void ast_patch_ahb_2500(struct ast_private *ast) ++{ ++ u32 data; ++ ++ /* Clear bus lock condition */ ++ ast_moutdwm(ast, 0x1e600000, 0xAEED1A03); ++ ast_moutdwm(ast, 0x1e600084, 0x00010000); ++ ast_moutdwm(ast, 0x1e600088, 0x00000000); ++ ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8); ++ data = ast_mindwm(ast, 0x1e6e2070); ++ if (data & 0x08000000) { /* check fast reset */ ++ /* ++ * If "Fast restet" is enabled for ARM-ICE debugger, ++ * then WDT needs to enable, that ++ * WDT04 is WDT#1 Reload reg. ++ * WDT08 is WDT#1 counter restart reg to avoid system deadlock ++ * WDT0C is WDT#1 control reg ++ * [6:5]:= 01:Full chip ++ * [4]:= 1:1MHz clock source ++ * [1]:= 1:WDT will be cleeared and disabled after timeout occurs ++ * [0]:= 1:WDT enable ++ */ ++ ast_moutdwm(ast, 0x1E785004, 0x00000010); ++ ast_moutdwm(ast, 0x1E785008, 0x00004755); ++ ast_moutdwm(ast, 0x1E78500c, 0x00000033); ++ udelay(1000); ++ } ++ do { ++ ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8); ++ data = ast_mindwm(ast, 0x1e6e2000); ++ } while (data != 1); ++ ast_moutdwm(ast, 0x1e6e207c, 0x08000000); /* clear fast reset */ ++} ++ + void ast_post_chip_2500(struct drm_device *dev) + { + struct ast_private *ast = to_ast_private(dev); +@@ -2035,39 +2069,44 @@ void ast_post_chip_2500(struct drm_device *dev) + u8 reg; + + reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); +- if ((reg & 0x80) == 0) {/* vga only */ ++ if ((reg & AST_VRAM_INIT_STATUS_MASK) == 0) {/* vga only */ + /* Clear bus lock condition */ +- ast_moutdwm(ast, 0x1e600000, 0xAEED1A03); +- ast_moutdwm(ast, 0x1e600084, 0x00010000); +- ast_moutdwm(ast, 0x1e600088, 0x00000000); +- ast_moutdwm(ast, 0x1e6e2000, 0x1688A8A8); +- ast_write32(ast, 0xf004, 0x1e6e0000); +- ast_write32(ast, 0xf000, 0x1); +- ast_write32(ast, 0x12000, 0x1688a8a8); +- while (ast_read32(ast, 0x12000) != 0x1) +- ; +- +- ast_write32(ast, 0x10000, 0xfc600309); +- while (ast_read32(ast, 0x10000) != 0x1) +- ; ++ ast_patch_ahb_2500(ast); ++ ++ /* Disable watchdog */ ++ ast_moutdwm(ast, 0x1E78502C, 0x00000000); ++ ast_moutdwm(ast, 0x1E78504C, 0x00000000); ++ ++ /* ++ * Reset USB port to patch USB unknown device issue ++ * SCU90 is Multi-function Pin Control #5 ++ * [29]:= 1:Enable USB2.0 Host port#1 (that the mutually shared USB2.0 Hub ++ * port). ++ * SCU94 is Multi-function Pin Control #6 ++ * [14:13]:= 1x:USB2.0 Host2 controller ++ * SCU70 is Hardware Strap reg ++ * [23]:= 1:CLKIN is 25MHz and USBCK1 = 24/48 MHz (determined by ++ * [18]: 0(24)/1(48) MHz) ++ * SCU7C is Write clear reg to SCU70 ++ * [23]:= write 1 and then SCU70[23] will be clear as 0b. ++ */ ++ ast_moutdwm(ast, 0x1E6E2090, 0x20000000); ++ ast_moutdwm(ast, 0x1E6E2094, 0x00004000); ++ if (ast_mindwm(ast, 0x1E6E2070) & 0x00800000) { ++ ast_moutdwm(ast, 0x1E6E207C, 0x00800000); ++ mdelay(100); ++ ast_moutdwm(ast, 0x1E6E2070, 0x00800000); ++ } ++ /* Modify eSPI reset pin */ ++ temp = ast_mindwm(ast, 0x1E6E2070); ++ if (temp & 0x02000000) ++ ast_moutdwm(ast, 0x1E6E207C, 0x00004000); + + /* Slow down CPU/AHB CLK in VGA only mode */ + temp = ast_read32(ast, 0x12008); + temp |= 0x73; + ast_write32(ast, 0x12008, temp); + +- /* Reset USB port to patch USB unknown device issue */ +- ast_moutdwm(ast, 0x1e6e2090, 0x20000000); +- temp = ast_mindwm(ast, 0x1e6e2094); +- temp |= 0x00004000; +- ast_moutdwm(ast, 0x1e6e2094, temp); +- temp = ast_mindwm(ast, 0x1e6e2070); +- if (temp & 0x00800000) { +- ast_moutdwm(ast, 0x1e6e207c, 0x00800000); +- mdelay(100); +- ast_moutdwm(ast, 0x1e6e2070, 0x00800000); +- } +- + if (!ast_dram_init_2500(ast)) + drm_err(dev, "DRAM init failed !\n"); + +diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c +index 873995f0a7416..6002404ffcb9d 100644 +--- a/drivers/gpu/drm/bridge/nwl-dsi.c ++++ b/drivers/gpu/drm/bridge/nwl-dsi.c +@@ -196,7 +196,7 @@ static u32 ps2bc(struct nwl_dsi *dsi, unsigned long long ps) + u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); + + return DIV64_U64_ROUND_UP(ps * dsi->mode.clock * bpp, +- dsi->lanes * 8 * NSEC_PER_SEC); ++ dsi->lanes * 8ULL * NSEC_PER_SEC); + } + + /* +diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c +index b59b26a71ad5d..3a298df00901d 100644 +--- a/drivers/gpu/drm/drm_auth.c ++++ b/drivers/gpu/drm/drm_auth.c +@@ -135,16 +135,18 @@ static void drm_set_master(struct drm_device *dev, struct drm_file *fpriv, + static int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv) + { + struct drm_master *old_master; ++ struct drm_master *new_master; + + lockdep_assert_held_once(&dev->master_mutex); + + WARN_ON(fpriv->is_master); + old_master = fpriv->master; +- fpriv->master = drm_master_create(dev); +- if (!fpriv->master) { +- fpriv->master = old_master; ++ new_master = drm_master_create(dev); ++ if (!new_master) + return -ENOMEM; +- } ++ spin_lock(&fpriv->master_lookup_lock); ++ fpriv->master = new_master; ++ spin_unlock(&fpriv->master_lookup_lock); + + fpriv->is_master = 1; + fpriv->authenticated = 1; +@@ -303,10 +305,13 @@ int drm_master_open(struct drm_file *file_priv) + * any master object for render clients + */ + mutex_lock(&dev->master_mutex); +- if (!dev->master) ++ if (!dev->master) { + ret = drm_new_set_master(dev, file_priv); +- else ++ } else { ++ spin_lock(&file_priv->master_lookup_lock); + file_priv->master = drm_master_get(dev->master); ++ spin_unlock(&file_priv->master_lookup_lock); ++ } + mutex_unlock(&dev->master_mutex); + + return ret; +@@ -372,6 +377,31 @@ struct drm_master *drm_master_get(struct drm_master *master) + } + EXPORT_SYMBOL(drm_master_get); + ++/** ++ * drm_file_get_master - reference &drm_file.master of @file_priv ++ * @file_priv: DRM file private ++ * ++ * Increments the reference count of @file_priv's &drm_file.master and returns ++ * the &drm_file.master. If @file_priv has no &drm_file.master, returns NULL. ++ * ++ * Master pointers returned from this function should be unreferenced using ++ * drm_master_put(). ++ */ ++struct drm_master *drm_file_get_master(struct drm_file *file_priv) ++{ ++ struct drm_master *master = NULL; ++ ++ spin_lock(&file_priv->master_lookup_lock); ++ if (!file_priv->master) ++ goto unlock; ++ master = drm_master_get(file_priv->master); ++ ++unlock: ++ spin_unlock(&file_priv->master_lookup_lock); ++ return master; ++} ++EXPORT_SYMBOL(drm_file_get_master); ++ + static void drm_master_destroy(struct kref *kref) + { + struct drm_master *master = container_of(kref, struct drm_master, refcount); +diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c +index 3d7182001004d..b0a8264894885 100644 +--- a/drivers/gpu/drm/drm_debugfs.c ++++ b/drivers/gpu/drm/drm_debugfs.c +@@ -91,6 +91,7 @@ static int drm_clients_info(struct seq_file *m, void *data) + mutex_lock(&dev->filelist_mutex); + list_for_each_entry_reverse(priv, &dev->filelist, lhead) { + struct task_struct *task; ++ bool is_current_master = drm_is_current_master(priv); + + rcu_read_lock(); /* locks pid_task()->comm */ + task = pid_task(priv->pid, PIDTYPE_PID); +@@ -99,7 +100,7 @@ static int drm_clients_info(struct seq_file *m, void *data) + task ? task->comm : "", + pid_vnr(priv->pid), + priv->minor->index, +- drm_is_current_master(priv) ? 'y' : 'n', ++ is_current_master ? 'y' : 'n', + priv->authenticated ? 'y' : 'n', + from_kuid_munged(seq_user_ns(m), uid), + priv->magic); +diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c +index ad0795afc21cf..86d13d6bc4631 100644 +--- a/drivers/gpu/drm/drm_dp_mst_topology.c ++++ b/drivers/gpu/drm/drm_dp_mst_topology.c +@@ -2872,11 +2872,13 @@ static int process_single_tx_qlock(struct drm_dp_mst_topology_mgr *mgr, + idx += tosend + 1; + + ret = drm_dp_send_sideband_msg(mgr, up, chunk, idx); +- if (unlikely(ret) && drm_debug_enabled(DRM_UT_DP)) { +- struct drm_printer p = drm_debug_printer(DBG_PREFIX); ++ if (ret) { ++ if (drm_debug_enabled(DRM_UT_DP)) { ++ struct drm_printer p = drm_debug_printer(DBG_PREFIX); + +- drm_printf(&p, "sideband msg failed to send\n"); +- drm_dp_mst_dump_sideband_msg_tx(&p, txmsg); ++ drm_printf(&p, "sideband msg failed to send\n"); ++ drm_dp_mst_dump_sideband_msg_tx(&p, txmsg); ++ } + return ret; + } + +diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c +index d4f0bac6f8f8a..ceb1a9723855f 100644 +--- a/drivers/gpu/drm/drm_file.c ++++ b/drivers/gpu/drm/drm_file.c +@@ -176,6 +176,7 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor) + init_waitqueue_head(&file->event_wait); + file->event_space = 4096; /* set aside 4k for event buffer */ + ++ spin_lock_init(&file->master_lookup_lock); + mutex_init(&file->event_read_lock); + + if (drm_core_check_feature(dev, DRIVER_GEM)) +diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c +index 00fb433bcef1a..92eac73d9001f 100644 +--- a/drivers/gpu/drm/drm_lease.c ++++ b/drivers/gpu/drm/drm_lease.c +@@ -106,10 +106,19 @@ static bool _drm_has_leased(struct drm_master *master, int id) + */ + bool _drm_lease_held(struct drm_file *file_priv, int id) + { +- if (!file_priv || !file_priv->master) ++ bool ret; ++ struct drm_master *master; ++ ++ if (!file_priv) + return true; + +- return _drm_lease_held_master(file_priv->master, id); ++ master = drm_file_get_master(file_priv); ++ if (!master) ++ return true; ++ ret = _drm_lease_held_master(master, id); ++ drm_master_put(&master); ++ ++ return ret; + } + + /** +@@ -128,13 +137,22 @@ bool drm_lease_held(struct drm_file *file_priv, int id) + struct drm_master *master; + bool ret; + +- if (!file_priv || !file_priv->master || !file_priv->master->lessor) ++ if (!file_priv) + return true; + +- master = file_priv->master; ++ master = drm_file_get_master(file_priv); ++ if (!master) ++ return true; ++ if (!master->lessor) { ++ ret = true; ++ goto out; ++ } + mutex_lock(&master->dev->mode_config.idr_mutex); + ret = _drm_lease_held_master(master, id); + mutex_unlock(&master->dev->mode_config.idr_mutex); ++ ++out: ++ drm_master_put(&master); + return ret; + } + +@@ -154,10 +172,16 @@ uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs_in) + int count_in, count_out; + uint32_t crtcs_out = 0; + +- if (!file_priv || !file_priv->master || !file_priv->master->lessor) ++ if (!file_priv) + return crtcs_in; + +- master = file_priv->master; ++ master = drm_file_get_master(file_priv); ++ if (!master) ++ return crtcs_in; ++ if (!master->lessor) { ++ crtcs_out = crtcs_in; ++ goto out; ++ } + dev = master->dev; + + count_in = count_out = 0; +@@ -176,6 +200,9 @@ uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs_in) + count_in++; + } + mutex_unlock(&master->dev->mode_config.idr_mutex); ++ ++out: ++ drm_master_put(&master); + return crtcs_out; + } + +@@ -489,7 +516,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, + size_t object_count; + int ret = 0; + struct idr leases; +- struct drm_master *lessor = lessor_priv->master; ++ struct drm_master *lessor; + struct drm_master *lessee = NULL; + struct file *lessee_file = NULL; + struct file *lessor_file = lessor_priv->filp; +@@ -501,12 +528,6 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return -EOPNOTSUPP; + +- /* Do not allow sub-leases */ +- if (lessor->lessor) { +- DRM_DEBUG_LEASE("recursive leasing not allowed\n"); +- return -EINVAL; +- } +- + /* need some objects */ + if (cl->object_count == 0) { + DRM_DEBUG_LEASE("no objects in lease\n"); +@@ -518,12 +539,22 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, + return -EINVAL; + } + ++ lessor = drm_file_get_master(lessor_priv); ++ /* Do not allow sub-leases */ ++ if (lessor->lessor) { ++ DRM_DEBUG_LEASE("recursive leasing not allowed\n"); ++ ret = -EINVAL; ++ goto out_lessor; ++ } ++ + object_count = cl->object_count; + + object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), + array_size(object_count, sizeof(__u32))); +- if (IS_ERR(object_ids)) +- return PTR_ERR(object_ids); ++ if (IS_ERR(object_ids)) { ++ ret = PTR_ERR(object_ids); ++ goto out_lessor; ++ } + + idr_init(&leases); + +@@ -534,14 +565,15 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, + if (ret) { + DRM_DEBUG_LEASE("lease object lookup failed: %i\n", ret); + idr_destroy(&leases); +- return ret; ++ goto out_lessor; + } + + /* Allocate a file descriptor for the lease */ + fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK)); + if (fd < 0) { + idr_destroy(&leases); +- return fd; ++ ret = fd; ++ goto out_lessor; + } + + DRM_DEBUG_LEASE("Creating lease\n"); +@@ -577,6 +609,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev, + /* Hook up the fd */ + fd_install(fd, lessee_file); + ++ drm_master_put(&lessor); + DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl succeeded\n"); + return 0; + +@@ -586,6 +619,8 @@ out_lessee: + out_leases: + put_unused_fd(fd); + ++out_lessor: ++ drm_master_put(&lessor); + DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl failed: %d\n", ret); + return ret; + } +@@ -608,7 +643,7 @@ int drm_mode_list_lessees_ioctl(struct drm_device *dev, + struct drm_mode_list_lessees *arg = data; + __u32 __user *lessee_ids = (__u32 __user *) (uintptr_t) (arg->lessees_ptr); + __u32 count_lessees = arg->count_lessees; +- struct drm_master *lessor = lessor_priv->master, *lessee; ++ struct drm_master *lessor, *lessee; + int count; + int ret = 0; + +@@ -619,6 +654,7 @@ int drm_mode_list_lessees_ioctl(struct drm_device *dev, + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return -EOPNOTSUPP; + ++ lessor = drm_file_get_master(lessor_priv); + DRM_DEBUG_LEASE("List lessees for %d\n", lessor->lessee_id); + + mutex_lock(&dev->mode_config.idr_mutex); +@@ -642,6 +678,7 @@ int drm_mode_list_lessees_ioctl(struct drm_device *dev, + arg->count_lessees = count; + + mutex_unlock(&dev->mode_config.idr_mutex); ++ drm_master_put(&lessor); + + return ret; + } +@@ -661,7 +698,7 @@ int drm_mode_get_lease_ioctl(struct drm_device *dev, + struct drm_mode_get_lease *arg = data; + __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr); + __u32 count_objects = arg->count_objects; +- struct drm_master *lessee = lessee_priv->master; ++ struct drm_master *lessee; + struct idr *object_idr; + int count; + void *entry; +@@ -675,6 +712,7 @@ int drm_mode_get_lease_ioctl(struct drm_device *dev, + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return -EOPNOTSUPP; + ++ lessee = drm_file_get_master(lessee_priv); + DRM_DEBUG_LEASE("get lease for %d\n", lessee->lessee_id); + + mutex_lock(&dev->mode_config.idr_mutex); +@@ -702,6 +740,7 @@ int drm_mode_get_lease_ioctl(struct drm_device *dev, + arg->count_objects = count; + + mutex_unlock(&dev->mode_config.idr_mutex); ++ drm_master_put(&lessee); + + return ret; + } +@@ -720,7 +759,7 @@ int drm_mode_revoke_lease_ioctl(struct drm_device *dev, + void *data, struct drm_file *lessor_priv) + { + struct drm_mode_revoke_lease *arg = data; +- struct drm_master *lessor = lessor_priv->master; ++ struct drm_master *lessor; + struct drm_master *lessee; + int ret = 0; + +@@ -730,6 +769,7 @@ int drm_mode_revoke_lease_ioctl(struct drm_device *dev, + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return -EOPNOTSUPP; + ++ lessor = drm_file_get_master(lessor_priv); + mutex_lock(&dev->mode_config.idr_mutex); + + lessee = _drm_find_lessee(lessor, arg->lessee_id); +@@ -750,6 +790,7 @@ int drm_mode_revoke_lease_ioctl(struct drm_device *dev, + + fail: + mutex_unlock(&dev->mode_config.idr_mutex); ++ drm_master_put(&lessor); + + return ret; + } +diff --git a/drivers/gpu/drm/exynos/exynos_drm_dma.c b/drivers/gpu/drm/exynos/exynos_drm_dma.c +index 0644936afee26..bf33c3084cb41 100644 +--- a/drivers/gpu/drm/exynos/exynos_drm_dma.c ++++ b/drivers/gpu/drm/exynos/exynos_drm_dma.c +@@ -115,6 +115,8 @@ int exynos_drm_register_dma(struct drm_device *drm, struct device *dev, + EXYNOS_DEV_ADDR_START, EXYNOS_DEV_ADDR_SIZE); + else if (IS_ENABLED(CONFIG_IOMMU_DMA)) + mapping = iommu_get_domain_for_dev(priv->dma_dev); ++ else ++ mapping = ERR_PTR(-ENODEV); + + if (IS_ERR(mapping)) + return PTR_ERR(mapping); +diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h +index 749a075fe9e4c..d1b51c133e27a 100644 +--- a/drivers/gpu/drm/mgag200/mgag200_drv.h ++++ b/drivers/gpu/drm/mgag200/mgag200_drv.h +@@ -43,6 +43,22 @@ + #define ATTR_INDEX 0x1fc0 + #define ATTR_DATA 0x1fc1 + ++#define WREG_MISC(v) \ ++ WREG8(MGA_MISC_OUT, v) ++ ++#define RREG_MISC(v) \ ++ ((v) = RREG8(MGA_MISC_IN)) ++ ++#define WREG_MISC_MASKED(v, mask) \ ++ do { \ ++ u8 misc_; \ ++ u8 mask_ = (mask); \ ++ RREG_MISC(misc_); \ ++ misc_ &= ~mask_; \ ++ misc_ |= ((v) & mask_); \ ++ WREG_MISC(misc_); \ ++ } while (0) ++ + #define WREG_ATTR(reg, v) \ + do { \ + RREG8(0x1fda); \ +diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c +index 9d576240faedd..555e3181e52b0 100644 +--- a/drivers/gpu/drm/mgag200/mgag200_mode.c ++++ b/drivers/gpu/drm/mgag200/mgag200_mode.c +@@ -174,6 +174,8 @@ static int mgag200_g200_set_plls(struct mga_device *mdev, long clock) + drm_dbg_kms(dev, "clock: %ld vco: %ld m: %d n: %d p: %d s: %d\n", + clock, f_vco, m, n, p, s); + ++ WREG_MISC_MASKED(MGAREG_MISC_CLKSEL_MGA, MGAREG_MISC_CLKSEL_MASK); ++ + WREG_DAC(MGA1064_PIX_PLLC_M, m); + WREG_DAC(MGA1064_PIX_PLLC_N, n); + WREG_DAC(MGA1064_PIX_PLLC_P, (p | (s << 3))); +@@ -289,6 +291,8 @@ static int mga_g200se_set_plls(struct mga_device *mdev, long clock) + return 1; + } + ++ WREG_MISC_MASKED(MGAREG_MISC_CLKSEL_MGA, MGAREG_MISC_CLKSEL_MASK); ++ + WREG_DAC(MGA1064_PIX_PLLC_M, m); + WREG_DAC(MGA1064_PIX_PLLC_N, n); + WREG_DAC(MGA1064_PIX_PLLC_P, p); +@@ -385,6 +389,8 @@ static int mga_g200wb_set_plls(struct mga_device *mdev, long clock) + } + } + ++ WREG_MISC_MASKED(MGAREG_MISC_CLKSEL_MGA, MGAREG_MISC_CLKSEL_MASK); ++ + for (i = 0; i <= 32 && pll_locked == false; i++) { + if (i > 0) { + WREG8(MGAREG_CRTC_INDEX, 0x1e); +@@ -522,6 +528,8 @@ static int mga_g200ev_set_plls(struct mga_device *mdev, long clock) + } + } + ++ WREG_MISC_MASKED(MGAREG_MISC_CLKSEL_MGA, MGAREG_MISC_CLKSEL_MASK); ++ + WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); + tmp = RREG8(DAC_DATA); + tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS; +@@ -654,6 +662,9 @@ static int mga_g200eh_set_plls(struct mga_device *mdev, long clock) + } + } + } ++ ++ WREG_MISC_MASKED(MGAREG_MISC_CLKSEL_MGA, MGAREG_MISC_CLKSEL_MASK); ++ + for (i = 0; i <= 32 && pll_locked == false; i++) { + WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); + tmp = RREG8(DAC_DATA); +@@ -754,6 +765,8 @@ static int mga_g200er_set_plls(struct mga_device *mdev, long clock) + } + } + ++ WREG_MISC_MASKED(MGAREG_MISC_CLKSEL_MGA, MGAREG_MISC_CLKSEL_MASK); ++ + WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); + tmp = RREG8(DAC_DATA); + tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS; +@@ -787,8 +800,6 @@ static int mga_g200er_set_plls(struct mga_device *mdev, long clock) + + static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock) + { +- u8 misc; +- + switch(mdev->type) { + case G200_PCI: + case G200_AGP: +@@ -808,11 +819,6 @@ static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock) + return mga_g200er_set_plls(mdev, clock); + } + +- misc = RREG8(MGA_MISC_IN); +- misc &= ~MGAREG_MISC_CLK_SEL_MASK; +- misc |= MGAREG_MISC_CLK_SEL_MGA_MSK; +- WREG8(MGA_MISC_OUT, misc); +- + return 0; + } + +diff --git a/drivers/gpu/drm/mgag200/mgag200_reg.h b/drivers/gpu/drm/mgag200/mgag200_reg.h +index 977be0565c061..60e705283fe84 100644 +--- a/drivers/gpu/drm/mgag200/mgag200_reg.h ++++ b/drivers/gpu/drm/mgag200/mgag200_reg.h +@@ -222,11 +222,10 @@ + + #define MGAREG_MISC_IOADSEL (0x1 << 0) + #define MGAREG_MISC_RAMMAPEN (0x1 << 1) +-#define MGAREG_MISC_CLK_SEL_MASK GENMASK(3, 2) +-#define MGAREG_MISC_CLK_SEL_VGA25 (0x0 << 2) +-#define MGAREG_MISC_CLK_SEL_VGA28 (0x1 << 2) +-#define MGAREG_MISC_CLK_SEL_MGA_PIX (0x2 << 2) +-#define MGAREG_MISC_CLK_SEL_MGA_MSK (0x3 << 2) ++#define MGAREG_MISC_CLKSEL_MASK GENMASK(3, 2) ++#define MGAREG_MISC_CLKSEL_VGA25 (0x0 << 2) ++#define MGAREG_MISC_CLKSEL_VGA28 (0x1 << 2) ++#define MGAREG_MISC_CLKSEL_MGA (0x3 << 2) + #define MGAREG_MISC_VIDEO_DIS (0x1 << 4) + #define MGAREG_MISC_HIGH_PG_SEL (0x1 << 5) + #define MGAREG_MISC_HSYNCPOL BIT(6) +diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c +index 9c5e4618aa0ae..183b9f9c1b315 100644 +--- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c ++++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c +@@ -1383,13 +1383,13 @@ static void a6xx_llc_activate(struct a6xx_gpu *a6xx_gpu) + { + struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; + struct msm_gpu *gpu = &adreno_gpu->base; +- u32 cntl1_regval = 0; ++ u32 gpu_scid, cntl1_regval = 0; + + if (IS_ERR(a6xx_gpu->llc_mmio)) + return; + + if (!llcc_slice_activate(a6xx_gpu->llc_slice)) { +- u32 gpu_scid = llcc_get_slice_id(a6xx_gpu->llc_slice); ++ gpu_scid = llcc_get_slice_id(a6xx_gpu->llc_slice); + + gpu_scid &= 0x1f; + cntl1_regval = (gpu_scid << 0) | (gpu_scid << 5) | (gpu_scid << 10) | +@@ -1409,26 +1409,34 @@ static void a6xx_llc_activate(struct a6xx_gpu *a6xx_gpu) + } + } + +- if (cntl1_regval) { ++ if (!cntl1_regval) ++ return; ++ ++ /* ++ * Program the slice IDs for the various GPU blocks and GPU MMU ++ * pagetables ++ */ ++ if (!a6xx_gpu->have_mmu500) { ++ a6xx_llc_write(a6xx_gpu, ++ REG_A6XX_CX_MISC_SYSTEM_CACHE_CNTL_1, cntl1_regval); ++ + /* +- * Program the slice IDs for the various GPU blocks and GPU MMU +- * pagetables ++ * Program cacheability overrides to not allocate cache ++ * lines on a write miss + */ +- if (a6xx_gpu->have_mmu500) +- gpu_rmw(gpu, REG_A6XX_GBIF_SCACHE_CNTL1, GENMASK(24, 0), +- cntl1_regval); +- else { +- a6xx_llc_write(a6xx_gpu, +- REG_A6XX_CX_MISC_SYSTEM_CACHE_CNTL_1, cntl1_regval); +- +- /* +- * Program cacheability overrides to not allocate cache +- * lines on a write miss +- */ +- a6xx_llc_rmw(a6xx_gpu, +- REG_A6XX_CX_MISC_SYSTEM_CACHE_CNTL_0, 0xF, 0x03); +- } ++ a6xx_llc_rmw(a6xx_gpu, ++ REG_A6XX_CX_MISC_SYSTEM_CACHE_CNTL_0, 0xF, 0x03); ++ return; + } ++ ++ gpu_rmw(gpu, REG_A6XX_GBIF_SCACHE_CNTL1, GENMASK(24, 0), cntl1_regval); ++ ++ /* On A660, the SCID programming for UCHE traffic is done in ++ * A6XX_GBIF_SCACHE_CNTL0[14:10] ++ */ ++ if (adreno_is_a660(adreno_gpu)) ++ gpu_rmw(gpu, REG_A6XX_GBIF_SCACHE_CNTL0, (0x1f << 10) | ++ (1 << 8), (gpu_scid << 10) | (1 << 8)); + } + + static void a6xx_llc_slices_destroy(struct a6xx_gpu *a6xx_gpu) +diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c +index 704dace895cbe..b131fd376192b 100644 +--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c ++++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c +@@ -974,6 +974,7 @@ static const struct dpu_perf_cfg sdm845_perf_data = { + .amortizable_threshold = 25, + .min_prefill_lines = 24, + .danger_lut_tbl = {0xf, 0xffff, 0x0}, ++ .safe_lut_tbl = {0xfff0, 0xf000, 0xffff}, + .qos_lut_tbl = { + {.nentry = ARRAY_SIZE(sdm845_qos_linear), + .entries = sdm845_qos_linear +@@ -1001,6 +1002,7 @@ static const struct dpu_perf_cfg sc7180_perf_data = { + .min_dram_ib = 1600000, + .min_prefill_lines = 24, + .danger_lut_tbl = {0xff, 0xffff, 0x0}, ++ .safe_lut_tbl = {0xfff0, 0xff00, 0xffff}, + .qos_lut_tbl = { + {.nentry = ARRAY_SIZE(sc7180_qos_linear), + .entries = sc7180_qos_linear +@@ -1028,6 +1030,7 @@ static const struct dpu_perf_cfg sm8150_perf_data = { + .min_dram_ib = 800000, + .min_prefill_lines = 24, + .danger_lut_tbl = {0xf, 0xffff, 0x0}, ++ .safe_lut_tbl = {0xfff8, 0xf000, 0xffff}, + .qos_lut_tbl = { + {.nentry = ARRAY_SIZE(sm8150_qos_linear), + .entries = sm8150_qos_linear +@@ -1056,6 +1059,7 @@ static const struct dpu_perf_cfg sm8250_perf_data = { + .min_dram_ib = 800000, + .min_prefill_lines = 35, + .danger_lut_tbl = {0xf, 0xffff, 0x0}, ++ .safe_lut_tbl = {0xfff0, 0xff00, 0xffff}, + .qos_lut_tbl = { + {.nentry = ARRAY_SIZE(sc7180_qos_linear), + .entries = sc7180_qos_linear +@@ -1084,6 +1088,7 @@ static const struct dpu_perf_cfg sc7280_perf_data = { + .min_dram_ib = 1600000, + .min_prefill_lines = 24, + .danger_lut_tbl = {0xffff, 0xffff, 0x0}, ++ .safe_lut_tbl = {0xff00, 0xff00, 0xffff}, + .qos_lut_tbl = { + {.nentry = ARRAY_SIZE(sc7180_qos_macrotile), + .entries = sc7180_qos_macrotile +diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +index 0712752742f4f..cdcaf470f1480 100644 +--- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c ++++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +@@ -89,13 +89,6 @@ static void mdp4_disable_commit(struct msm_kms *kms) + + static void mdp4_prepare_commit(struct msm_kms *kms, struct drm_atomic_state *state) + { +- int i; +- struct drm_crtc *crtc; +- struct drm_crtc_state *crtc_state; +- +- /* see 119ecb7fd */ +- for_each_new_crtc_in_state(state, crtc, crtc_state, i) +- drm_crtc_vblank_get(crtc); + } + + static void mdp4_flush_commit(struct msm_kms *kms, unsigned crtc_mask) +@@ -114,12 +107,6 @@ static void mdp4_wait_flush(struct msm_kms *kms, unsigned crtc_mask) + + static void mdp4_complete_commit(struct msm_kms *kms, unsigned crtc_mask) + { +- struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms)); +- struct drm_crtc *crtc; +- +- /* see 119ecb7fd */ +- for_each_crtc_mask(mdp4_kms->dev, crtc, crtc_mask) +- drm_crtc_vblank_put(crtc); + } + + static long mdp4_round_pixclk(struct msm_kms *kms, unsigned long rate, +@@ -412,6 +399,7 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev) + { + struct platform_device *pdev = to_platform_device(dev->dev); + struct mdp4_platform_config *config = mdp4_get_config(pdev); ++ struct msm_drm_private *priv = dev->dev_private; + struct mdp4_kms *mdp4_kms; + struct msm_kms *kms = NULL; + struct msm_gem_address_space *aspace; +@@ -431,7 +419,8 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev) + goto fail; + } + +- kms = &mdp4_kms->base.base; ++ priv->kms = &mdp4_kms->base.base; ++ kms = priv->kms; + + mdp4_kms->dev = dev; + +diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c b/drivers/gpu/drm/msm/dp/dp_aux.c +index 4a3293b590b05..eb40d8413bca9 100644 +--- a/drivers/gpu/drm/msm/dp/dp_aux.c ++++ b/drivers/gpu/drm/msm/dp/dp_aux.c +@@ -353,6 +353,9 @@ static ssize_t dp_aux_transfer(struct drm_dp_aux *dp_aux, + if (!(aux->retry_cnt % MAX_AUX_RETRIES)) + dp_catalog_aux_update_cfg(aux->catalog); + } ++ /* reset aux if link is in connected state */ ++ if (dp_catalog_link_is_connected(aux->catalog)) ++ dp_catalog_aux_reset(aux->catalog); + } else { + aux->retry_cnt = 0; + switch (aux->aux_error_num) { +diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c +index eaddfd7398850..6f5e45d54b268 100644 +--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c ++++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c +@@ -81,13 +81,6 @@ struct dp_ctrl_private { + struct completion video_comp; + }; + +-struct dp_cr_status { +- u8 lane_0_1; +- u8 lane_2_3; +-}; +- +-#define DP_LANE0_1_CR_DONE 0x11 +- + static int dp_aux_link_configure(struct drm_dp_aux *aux, + struct dp_link_info *link) + { +@@ -1078,7 +1071,7 @@ static int dp_ctrl_read_link_status(struct dp_ctrl_private *ctrl, + } + + static int dp_ctrl_link_train_1(struct dp_ctrl_private *ctrl, +- struct dp_cr_status *cr, int *training_step) ++ int *training_step) + { + int tries, old_v_level, ret = 0; + u8 link_status[DP_LINK_STATUS_SIZE]; +@@ -1107,9 +1100,6 @@ static int dp_ctrl_link_train_1(struct dp_ctrl_private *ctrl, + if (ret) + return ret; + +- cr->lane_0_1 = link_status[0]; +- cr->lane_2_3 = link_status[1]; +- + if (drm_dp_clock_recovery_ok(link_status, + ctrl->link->link_params.num_lanes)) { + return 0; +@@ -1186,7 +1176,7 @@ static void dp_ctrl_clear_training_pattern(struct dp_ctrl_private *ctrl) + } + + static int dp_ctrl_link_train_2(struct dp_ctrl_private *ctrl, +- struct dp_cr_status *cr, int *training_step) ++ int *training_step) + { + int tries = 0, ret = 0; + char pattern; +@@ -1202,10 +1192,6 @@ static int dp_ctrl_link_train_2(struct dp_ctrl_private *ctrl, + else + pattern = DP_TRAINING_PATTERN_2; + +- ret = dp_ctrl_update_vx_px(ctrl); +- if (ret) +- return ret; +- + ret = dp_catalog_ctrl_set_pattern(ctrl->catalog, pattern); + if (ret) + return ret; +@@ -1218,8 +1204,6 @@ static int dp_ctrl_link_train_2(struct dp_ctrl_private *ctrl, + ret = dp_ctrl_read_link_status(ctrl, link_status); + if (ret) + return ret; +- cr->lane_0_1 = link_status[0]; +- cr->lane_2_3 = link_status[1]; + + if (drm_dp_channel_eq_ok(link_status, + ctrl->link->link_params.num_lanes)) { +@@ -1239,7 +1223,7 @@ static int dp_ctrl_link_train_2(struct dp_ctrl_private *ctrl, + static int dp_ctrl_reinitialize_mainlink(struct dp_ctrl_private *ctrl); + + static int dp_ctrl_link_train(struct dp_ctrl_private *ctrl, +- struct dp_cr_status *cr, int *training_step) ++ int *training_step) + { + int ret = 0; + u8 encoding = DP_SET_ANSI_8B10B; +@@ -1255,7 +1239,7 @@ static int dp_ctrl_link_train(struct dp_ctrl_private *ctrl, + drm_dp_dpcd_write(ctrl->aux, DP_MAIN_LINK_CHANNEL_CODING_SET, + &encoding, 1); + +- ret = dp_ctrl_link_train_1(ctrl, cr, training_step); ++ ret = dp_ctrl_link_train_1(ctrl, training_step); + if (ret) { + DRM_ERROR("link training #1 failed. ret=%d\n", ret); + goto end; +@@ -1264,7 +1248,7 @@ static int dp_ctrl_link_train(struct dp_ctrl_private *ctrl, + /* print success info as this is a result of user initiated action */ + DRM_DEBUG_DP("link training #1 successful\n"); + +- ret = dp_ctrl_link_train_2(ctrl, cr, training_step); ++ ret = dp_ctrl_link_train_2(ctrl, training_step); + if (ret) { + DRM_ERROR("link training #2 failed. ret=%d\n", ret); + goto end; +@@ -1280,7 +1264,7 @@ end: + } + + static int dp_ctrl_setup_main_link(struct dp_ctrl_private *ctrl, +- struct dp_cr_status *cr, int *training_step) ++ int *training_step) + { + int ret = 0; + +@@ -1295,7 +1279,7 @@ static int dp_ctrl_setup_main_link(struct dp_ctrl_private *ctrl, + * a link training pattern, we have to first do soft reset. + */ + +- ret = dp_ctrl_link_train(ctrl, cr, training_step); ++ ret = dp_ctrl_link_train(ctrl, training_step); + + return ret; + } +@@ -1492,14 +1476,16 @@ static int dp_ctrl_deinitialize_mainlink(struct dp_ctrl_private *ctrl) + static int dp_ctrl_link_maintenance(struct dp_ctrl_private *ctrl) + { + int ret = 0; +- struct dp_cr_status cr; + int training_step = DP_TRAINING_NONE; + + dp_ctrl_push_idle(&ctrl->dp_ctrl); + ++ ctrl->link->phy_params.p_level = 0; ++ ctrl->link->phy_params.v_level = 0; ++ + ctrl->dp_ctrl.pixel_rate = ctrl->panel->dp_mode.drm_mode.clock; + +- ret = dp_ctrl_setup_main_link(ctrl, &cr, &training_step); ++ ret = dp_ctrl_setup_main_link(ctrl, &training_step); + if (ret) + goto end; + +@@ -1630,6 +1616,35 @@ void dp_ctrl_handle_sink_request(struct dp_ctrl *dp_ctrl) + } + } + ++static bool dp_ctrl_clock_recovery_any_ok( ++ const u8 link_status[DP_LINK_STATUS_SIZE], ++ int lane_count) ++{ ++ int reduced_cnt; ++ ++ if (lane_count <= 1) ++ return false; ++ ++ /* ++ * only interested in the lane number after reduced ++ * lane_count = 4, then only interested in 2 lanes ++ * lane_count = 2, then only interested in 1 lane ++ */ ++ reduced_cnt = lane_count >> 1; ++ ++ return drm_dp_clock_recovery_ok(link_status, reduced_cnt); ++} ++ ++static bool dp_ctrl_channel_eq_ok(struct dp_ctrl_private *ctrl) ++{ ++ u8 link_status[DP_LINK_STATUS_SIZE]; ++ int num_lanes = ctrl->link->link_params.num_lanes; ++ ++ dp_ctrl_read_link_status(ctrl, link_status); ++ ++ return drm_dp_channel_eq_ok(link_status, num_lanes); ++} ++ + int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl) + { + int rc = 0; +@@ -1637,7 +1652,7 @@ int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl) + u32 rate = 0; + int link_train_max_retries = 5; + u32 const phy_cts_pixel_clk_khz = 148500; +- struct dp_cr_status cr; ++ u8 link_status[DP_LINK_STATUS_SIZE]; + unsigned int training_step; + + if (!dp_ctrl) +@@ -1664,6 +1679,9 @@ int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl) + ctrl->link->link_params.rate, + ctrl->link->link_params.num_lanes, ctrl->dp_ctrl.pixel_rate); + ++ ctrl->link->phy_params.p_level = 0; ++ ctrl->link->phy_params.v_level = 0; ++ + rc = dp_ctrl_enable_mainlink_clocks(ctrl); + if (rc) + return rc; +@@ -1677,19 +1695,21 @@ int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl) + } + + training_step = DP_TRAINING_NONE; +- rc = dp_ctrl_setup_main_link(ctrl, &cr, &training_step); ++ rc = dp_ctrl_setup_main_link(ctrl, &training_step); + if (rc == 0) { + /* training completed successfully */ + break; + } else if (training_step == DP_TRAINING_1) { + /* link train_1 failed */ +- if (!dp_catalog_link_is_connected(ctrl->catalog)) { ++ if (!dp_catalog_link_is_connected(ctrl->catalog)) + break; +- } ++ ++ dp_ctrl_read_link_status(ctrl, link_status); + + rc = dp_ctrl_link_rate_down_shift(ctrl); + if (rc < 0) { /* already in RBR = 1.6G */ +- if (cr.lane_0_1 & DP_LANE0_1_CR_DONE) { ++ if (dp_ctrl_clock_recovery_any_ok(link_status, ++ ctrl->link->link_params.num_lanes)) { + /* + * some lanes are ready, + * reduce lane number +@@ -1705,12 +1725,18 @@ int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl) + } + } + } else if (training_step == DP_TRAINING_2) { +- /* link train_2 failed, lower lane rate */ +- if (!dp_catalog_link_is_connected(ctrl->catalog)) { ++ /* link train_2 failed */ ++ if (!dp_catalog_link_is_connected(ctrl->catalog)) + break; +- } + +- rc = dp_ctrl_link_lane_down_shift(ctrl); ++ dp_ctrl_read_link_status(ctrl, link_status); ++ ++ if (!drm_dp_clock_recovery_ok(link_status, ++ ctrl->link->link_params.num_lanes)) ++ rc = dp_ctrl_link_rate_down_shift(ctrl); ++ else ++ rc = dp_ctrl_link_lane_down_shift(ctrl); ++ + if (rc < 0) { + /* end with failure */ + break; /* lane == 1 already */ +@@ -1721,17 +1747,19 @@ int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl) + if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) + return rc; + +- /* stop txing train pattern */ +- dp_ctrl_clear_training_pattern(ctrl); ++ if (rc == 0) { /* link train successfully */ ++ /* ++ * do not stop train pattern here ++ * stop link training at on_stream ++ * to pass compliance test ++ */ ++ } else { ++ /* ++ * link training failed ++ * end txing train pattern here ++ */ ++ dp_ctrl_clear_training_pattern(ctrl); + +- /* +- * keep transmitting idle pattern until video ready +- * to avoid main link from loss of sync +- */ +- if (rc == 0) /* link train successfully */ +- dp_ctrl_push_idle(dp_ctrl); +- else { +- /* link training failed */ + dp_ctrl_deinitialize_mainlink(ctrl); + rc = -ECONNRESET; + } +@@ -1739,9 +1767,15 @@ int dp_ctrl_on_link(struct dp_ctrl *dp_ctrl) + return rc; + } + ++static int dp_ctrl_link_retrain(struct dp_ctrl_private *ctrl) ++{ ++ int training_step = DP_TRAINING_NONE; ++ ++ return dp_ctrl_setup_main_link(ctrl, &training_step); ++} ++ + int dp_ctrl_on_stream(struct dp_ctrl *dp_ctrl) + { +- u32 rate = 0; + int ret = 0; + bool mainlink_ready = false; + struct dp_ctrl_private *ctrl; +@@ -1751,10 +1785,6 @@ int dp_ctrl_on_stream(struct dp_ctrl *dp_ctrl) + + ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); + +- rate = ctrl->panel->link_info.rate; +- +- ctrl->link->link_params.rate = rate; +- ctrl->link->link_params.num_lanes = ctrl->panel->link_info.num_lanes; + ctrl->dp_ctrl.pixel_rate = ctrl->panel->dp_mode.drm_mode.clock; + + DRM_DEBUG_DP("rate=%d, num_lanes=%d, pixel_rate=%d\n", +@@ -1769,6 +1799,12 @@ int dp_ctrl_on_stream(struct dp_ctrl *dp_ctrl) + } + } + ++ if (!dp_ctrl_channel_eq_ok(ctrl)) ++ dp_ctrl_link_retrain(ctrl); ++ ++ /* stop txing train pattern to end link training */ ++ dp_ctrl_clear_training_pattern(ctrl); ++ + ret = dp_ctrl_enable_stream_clocks(ctrl); + if (ret) { + DRM_ERROR("Failed to start pixel clocks. ret=%d\n", ret); +diff --git a/drivers/gpu/drm/msm/dp/dp_panel.c b/drivers/gpu/drm/msm/dp/dp_panel.c +index 440b327534302..2181b60e1d1d8 100644 +--- a/drivers/gpu/drm/msm/dp/dp_panel.c ++++ b/drivers/gpu/drm/msm/dp/dp_panel.c +@@ -271,7 +271,7 @@ static u8 dp_panel_get_edid_checksum(struct edid *edid) + { + struct edid *last_block; + u8 *raw_edid; +- bool is_edid_corrupt; ++ bool is_edid_corrupt = false; + + if (!edid) { + DRM_ERROR("invalid edid input\n"); +@@ -303,7 +303,12 @@ void dp_panel_handle_sink_request(struct dp_panel *dp_panel) + panel = container_of(dp_panel, struct dp_panel_private, dp_panel); + + if (panel->link->sink_request & DP_TEST_LINK_EDID_READ) { +- u8 checksum = dp_panel_get_edid_checksum(dp_panel->edid); ++ u8 checksum; ++ ++ if (dp_panel->edid) ++ checksum = dp_panel_get_edid_checksum(dp_panel->edid); ++ else ++ checksum = dp_panel->connector->real_edid_checksum; + + dp_link_send_edid_checksum(panel->link, checksum); + dp_link_send_test_response(panel->link); +diff --git a/drivers/gpu/drm/msm/dsi/dsi_cfg.c b/drivers/gpu/drm/msm/dsi/dsi_cfg.c +index f3f1c03c7db95..763f127e46213 100644 +--- a/drivers/gpu/drm/msm/dsi/dsi_cfg.c ++++ b/drivers/gpu/drm/msm/dsi/dsi_cfg.c +@@ -154,7 +154,6 @@ static const struct msm_dsi_config sdm660_dsi_cfg = { + .reg_cfg = { + .num = 2, + .regs = { +- {"vdd", 73400, 32 }, /* 0.9 V */ + {"vdda", 12560, 4 }, /* 1.2 V */ + }, + }, +diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c +index a34cf151c5170..bb31230721bdd 100644 +--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c ++++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c +@@ -1050,7 +1050,7 @@ const struct msm_dsi_phy_cfg dsi_phy_14nm_660_cfgs = { + .reg_cfg = { + .num = 1, + .regs = { +- {"vcca", 17000, 32}, ++ {"vcca", 73400, 32}, + }, + }, + .ops = { +diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c +index 801da917507d5..512af976b7e90 100644 +--- a/drivers/gpu/drm/omapdrm/omap_plane.c ++++ b/drivers/gpu/drm/omapdrm/omap_plane.c +@@ -6,6 +6,7 @@ + + #include + #include ++#include + #include + + #include "omap_dmm_tiler.h" +@@ -29,6 +30,8 @@ static int omap_plane_prepare_fb(struct drm_plane *plane, + if (!new_state->fb) + return 0; + ++ drm_gem_plane_helper_prepare_fb(plane, new_state); ++ + return omap_framebuffer_pin(new_state->fb); + } + +diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h +index f614e98771e49..8b2cdb8c701d8 100644 +--- a/drivers/gpu/drm/panfrost/panfrost_device.h ++++ b/drivers/gpu/drm/panfrost/panfrost_device.h +@@ -121,8 +121,12 @@ struct panfrost_device { + }; + + struct panfrost_mmu { ++ struct panfrost_device *pfdev; ++ struct kref refcount; + struct io_pgtable_cfg pgtbl_cfg; + struct io_pgtable_ops *pgtbl_ops; ++ struct drm_mm mm; ++ spinlock_t mm_lock; + int as; + atomic_t as_count; + struct list_head list; +@@ -133,9 +137,7 @@ struct panfrost_file_priv { + + struct drm_sched_entity sched_entity[NUM_JOB_SLOTS]; + +- struct panfrost_mmu mmu; +- struct drm_mm mm; +- spinlock_t mm_lock; ++ struct panfrost_mmu *mmu; + }; + + static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev) +diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c +index 075ec0ef746cf..945133db1857f 100644 +--- a/drivers/gpu/drm/panfrost/panfrost_drv.c ++++ b/drivers/gpu/drm/panfrost/panfrost_drv.c +@@ -417,7 +417,7 @@ static int panfrost_ioctl_madvise(struct drm_device *dev, void *data, + * anyway, so let's not bother. + */ + if (!list_is_singular(&bo->mappings.list) || +- WARN_ON_ONCE(first->mmu != &priv->mmu)) { ++ WARN_ON_ONCE(first->mmu != priv->mmu)) { + ret = -EINVAL; + goto out_unlock_mappings; + } +@@ -449,32 +449,6 @@ int panfrost_unstable_ioctl_check(void) + return 0; + } + +-#define PFN_4G (SZ_4G >> PAGE_SHIFT) +-#define PFN_4G_MASK (PFN_4G - 1) +-#define PFN_16M (SZ_16M >> PAGE_SHIFT) +- +-static void panfrost_drm_mm_color_adjust(const struct drm_mm_node *node, +- unsigned long color, +- u64 *start, u64 *end) +-{ +- /* Executable buffers can't start or end on a 4GB boundary */ +- if (!(color & PANFROST_BO_NOEXEC)) { +- u64 next_seg; +- +- if ((*start & PFN_4G_MASK) == 0) +- (*start)++; +- +- if ((*end & PFN_4G_MASK) == 0) +- (*end)--; +- +- next_seg = ALIGN(*start, PFN_4G); +- if (next_seg - *start <= PFN_16M) +- *start = next_seg + 1; +- +- *end = min(*end, ALIGN(*start, PFN_4G) - 1); +- } +-} +- + static int + panfrost_open(struct drm_device *dev, struct drm_file *file) + { +@@ -489,15 +463,11 @@ panfrost_open(struct drm_device *dev, struct drm_file *file) + panfrost_priv->pfdev = pfdev; + file->driver_priv = panfrost_priv; + +- spin_lock_init(&panfrost_priv->mm_lock); +- +- /* 4G enough for now. can be 48-bit */ +- drm_mm_init(&panfrost_priv->mm, SZ_32M >> PAGE_SHIFT, (SZ_4G - SZ_32M) >> PAGE_SHIFT); +- panfrost_priv->mm.color_adjust = panfrost_drm_mm_color_adjust; +- +- ret = panfrost_mmu_pgtable_alloc(panfrost_priv); +- if (ret) +- goto err_pgtable; ++ panfrost_priv->mmu = panfrost_mmu_ctx_create(pfdev); ++ if (IS_ERR(panfrost_priv->mmu)) { ++ ret = PTR_ERR(panfrost_priv->mmu); ++ goto err_free; ++ } + + ret = panfrost_job_open(panfrost_priv); + if (ret) +@@ -506,9 +476,8 @@ panfrost_open(struct drm_device *dev, struct drm_file *file) + return 0; + + err_job: +- panfrost_mmu_pgtable_free(panfrost_priv); +-err_pgtable: +- drm_mm_takedown(&panfrost_priv->mm); ++ panfrost_mmu_ctx_put(panfrost_priv->mmu); ++err_free: + kfree(panfrost_priv); + return ret; + } +@@ -521,8 +490,7 @@ panfrost_postclose(struct drm_device *dev, struct drm_file *file) + panfrost_perfcnt_close(file); + panfrost_job_close(panfrost_priv); + +- panfrost_mmu_pgtable_free(panfrost_priv); +- drm_mm_takedown(&panfrost_priv->mm); ++ panfrost_mmu_ctx_put(panfrost_priv->mmu); + kfree(panfrost_priv); + } + +diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c +index 3e0723bc36bda..23377481f4e31 100644 +--- a/drivers/gpu/drm/panfrost/panfrost_gem.c ++++ b/drivers/gpu/drm/panfrost/panfrost_gem.c +@@ -60,7 +60,7 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo, + + mutex_lock(&bo->mappings.lock); + list_for_each_entry(iter, &bo->mappings.list, node) { +- if (iter->mmu == &priv->mmu) { ++ if (iter->mmu == priv->mmu) { + kref_get(&iter->refcount); + mapping = iter; + break; +@@ -74,16 +74,13 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo, + static void + panfrost_gem_teardown_mapping(struct panfrost_gem_mapping *mapping) + { +- struct panfrost_file_priv *priv; +- + if (mapping->active) + panfrost_mmu_unmap(mapping); + +- priv = container_of(mapping->mmu, struct panfrost_file_priv, mmu); +- spin_lock(&priv->mm_lock); ++ spin_lock(&mapping->mmu->mm_lock); + if (drm_mm_node_allocated(&mapping->mmnode)) + drm_mm_remove_node(&mapping->mmnode); +- spin_unlock(&priv->mm_lock); ++ spin_unlock(&mapping->mmu->mm_lock); + } + + static void panfrost_gem_mapping_release(struct kref *kref) +@@ -94,6 +91,7 @@ static void panfrost_gem_mapping_release(struct kref *kref) + + panfrost_gem_teardown_mapping(mapping); + drm_gem_object_put(&mapping->obj->base.base); ++ panfrost_mmu_ctx_put(mapping->mmu); + kfree(mapping); + } + +@@ -143,11 +141,11 @@ int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv) + else + align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; + +- mapping->mmu = &priv->mmu; +- spin_lock(&priv->mm_lock); +- ret = drm_mm_insert_node_generic(&priv->mm, &mapping->mmnode, ++ mapping->mmu = panfrost_mmu_ctx_get(priv->mmu); ++ spin_lock(&mapping->mmu->mm_lock); ++ ret = drm_mm_insert_node_generic(&mapping->mmu->mm, &mapping->mmnode, + size >> PAGE_SHIFT, align, color, 0); +- spin_unlock(&priv->mm_lock); ++ spin_unlock(&mapping->mmu->mm_lock); + if (ret) + goto err; + +@@ -176,7 +174,7 @@ void panfrost_gem_close(struct drm_gem_object *obj, struct drm_file *file_priv) + + mutex_lock(&bo->mappings.lock); + list_for_each_entry(iter, &bo->mappings.list, node) { +- if (iter->mmu == &priv->mmu) { ++ if (iter->mmu == priv->mmu) { + mapping = iter; + list_del(&iter->node); + break; +diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c +index 2df3e999a38d0..3757c6eb30238 100644 +--- a/drivers/gpu/drm/panfrost/panfrost_job.c ++++ b/drivers/gpu/drm/panfrost/panfrost_job.c +@@ -165,7 +165,7 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js) + return; + } + +- cfg = panfrost_mmu_as_get(pfdev, &job->file_priv->mmu); ++ cfg = panfrost_mmu_as_get(pfdev, job->file_priv->mmu); + + job_write(pfdev, JS_HEAD_NEXT_LO(js), jc_head & 0xFFFFFFFF); + job_write(pfdev, JS_HEAD_NEXT_HI(js), jc_head >> 32); +@@ -527,7 +527,7 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data) + if (job) { + pfdev->jobs[j] = NULL; + +- panfrost_mmu_as_put(pfdev, &job->file_priv->mmu); ++ panfrost_mmu_as_put(pfdev, job->file_priv->mmu); + panfrost_devfreq_record_idle(&pfdev->pfdevfreq); + + dma_fence_signal_locked(job->done_fence); +diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c +index 0581186ebfb3a..eea6ade902cb4 100644 +--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c ++++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c +@@ -1,5 +1,8 @@ + // SPDX-License-Identifier: GPL-2.0 + /* Copyright 2019 Linaro, Ltd, Rob Herring */ ++ ++#include ++ + #include + #include + #include +@@ -52,25 +55,16 @@ static int write_cmd(struct panfrost_device *pfdev, u32 as_nr, u32 cmd) + } + + static void lock_region(struct panfrost_device *pfdev, u32 as_nr, +- u64 iova, size_t size) ++ u64 iova, u64 size) + { + u8 region_width; + u64 region = iova & PAGE_MASK; +- /* +- * fls returns: +- * 1 .. 32 +- * +- * 10 + fls(num_pages) +- * results in the range (11 .. 42) +- */ +- +- size = round_up(size, PAGE_SIZE); + +- region_width = 10 + fls(size >> PAGE_SHIFT); +- if ((size >> PAGE_SHIFT) != (1ul << (region_width - 11))) { +- /* not pow2, so must go up to the next pow2 */ +- region_width += 1; +- } ++ /* The size is encoded as ceil(log2) minus(1), which may be calculated ++ * with fls. The size must be clamped to hardware bounds. ++ */ ++ size = max_t(u64, size, AS_LOCK_REGION_MIN_SIZE); ++ region_width = fls64(size - 1) - 1; + region |= region_width; + + /* Lock the region that needs to be updated */ +@@ -81,7 +75,7 @@ static void lock_region(struct panfrost_device *pfdev, u32 as_nr, + + + static int mmu_hw_do_operation_locked(struct panfrost_device *pfdev, int as_nr, +- u64 iova, size_t size, u32 op) ++ u64 iova, u64 size, u32 op) + { + if (as_nr < 0) + return 0; +@@ -98,7 +92,7 @@ static int mmu_hw_do_operation_locked(struct panfrost_device *pfdev, int as_nr, + + static int mmu_hw_do_operation(struct panfrost_device *pfdev, + struct panfrost_mmu *mmu, +- u64 iova, size_t size, u32 op) ++ u64 iova, u64 size, u32 op) + { + int ret; + +@@ -115,7 +109,7 @@ static void panfrost_mmu_enable(struct panfrost_device *pfdev, struct panfrost_m + u64 transtab = cfg->arm_mali_lpae_cfg.transtab; + u64 memattr = cfg->arm_mali_lpae_cfg.memattr; + +- mmu_hw_do_operation_locked(pfdev, as_nr, 0, ~0UL, AS_COMMAND_FLUSH_MEM); ++ mmu_hw_do_operation_locked(pfdev, as_nr, 0, ~0ULL, AS_COMMAND_FLUSH_MEM); + + mmu_write(pfdev, AS_TRANSTAB_LO(as_nr), transtab & 0xffffffffUL); + mmu_write(pfdev, AS_TRANSTAB_HI(as_nr), transtab >> 32); +@@ -131,7 +125,7 @@ static void panfrost_mmu_enable(struct panfrost_device *pfdev, struct panfrost_m + + static void panfrost_mmu_disable(struct panfrost_device *pfdev, u32 as_nr) + { +- mmu_hw_do_operation_locked(pfdev, as_nr, 0, ~0UL, AS_COMMAND_FLUSH_MEM); ++ mmu_hw_do_operation_locked(pfdev, as_nr, 0, ~0ULL, AS_COMMAND_FLUSH_MEM); + + mmu_write(pfdev, AS_TRANSTAB_LO(as_nr), 0); + mmu_write(pfdev, AS_TRANSTAB_HI(as_nr), 0); +@@ -231,7 +225,7 @@ static size_t get_pgsize(u64 addr, size_t size) + + static void panfrost_mmu_flush_range(struct panfrost_device *pfdev, + struct panfrost_mmu *mmu, +- u64 iova, size_t size) ++ u64 iova, u64 size) + { + if (mmu->as < 0) + return; +@@ -337,7 +331,7 @@ static void mmu_tlb_inv_context_s1(void *cookie) + + static void mmu_tlb_sync_context(void *cookie) + { +- //struct panfrost_device *pfdev = cookie; ++ //struct panfrost_mmu *mmu = cookie; + // TODO: Wait 1000 GPU cycles for HW_ISSUE_6367/T60X + } + +@@ -352,57 +346,10 @@ static const struct iommu_flush_ops mmu_tlb_ops = { + .tlb_flush_walk = mmu_tlb_flush_walk, + }; + +-int panfrost_mmu_pgtable_alloc(struct panfrost_file_priv *priv) +-{ +- struct panfrost_mmu *mmu = &priv->mmu; +- struct panfrost_device *pfdev = priv->pfdev; +- +- INIT_LIST_HEAD(&mmu->list); +- mmu->as = -1; +- +- mmu->pgtbl_cfg = (struct io_pgtable_cfg) { +- .pgsize_bitmap = SZ_4K | SZ_2M, +- .ias = FIELD_GET(0xff, pfdev->features.mmu_features), +- .oas = FIELD_GET(0xff00, pfdev->features.mmu_features), +- .coherent_walk = pfdev->coherent, +- .tlb = &mmu_tlb_ops, +- .iommu_dev = pfdev->dev, +- }; +- +- mmu->pgtbl_ops = alloc_io_pgtable_ops(ARM_MALI_LPAE, &mmu->pgtbl_cfg, +- priv); +- if (!mmu->pgtbl_ops) +- return -EINVAL; +- +- return 0; +-} +- +-void panfrost_mmu_pgtable_free(struct panfrost_file_priv *priv) +-{ +- struct panfrost_device *pfdev = priv->pfdev; +- struct panfrost_mmu *mmu = &priv->mmu; +- +- spin_lock(&pfdev->as_lock); +- if (mmu->as >= 0) { +- pm_runtime_get_noresume(pfdev->dev); +- if (pm_runtime_active(pfdev->dev)) +- panfrost_mmu_disable(pfdev, mmu->as); +- pm_runtime_put_autosuspend(pfdev->dev); +- +- clear_bit(mmu->as, &pfdev->as_alloc_mask); +- clear_bit(mmu->as, &pfdev->as_in_use_mask); +- list_del(&mmu->list); +- } +- spin_unlock(&pfdev->as_lock); +- +- free_io_pgtable_ops(mmu->pgtbl_ops); +-} +- + static struct panfrost_gem_mapping * + addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr) + { + struct panfrost_gem_mapping *mapping = NULL; +- struct panfrost_file_priv *priv; + struct drm_mm_node *node; + u64 offset = addr >> PAGE_SHIFT; + struct panfrost_mmu *mmu; +@@ -415,11 +362,10 @@ addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr) + goto out; + + found_mmu: +- priv = container_of(mmu, struct panfrost_file_priv, mmu); + +- spin_lock(&priv->mm_lock); ++ spin_lock(&mmu->mm_lock); + +- drm_mm_for_each_node(node, &priv->mm) { ++ drm_mm_for_each_node(node, &mmu->mm) { + if (offset >= node->start && + offset < (node->start + node->size)) { + mapping = drm_mm_node_to_panfrost_mapping(node); +@@ -429,7 +375,7 @@ found_mmu: + } + } + +- spin_unlock(&priv->mm_lock); ++ spin_unlock(&mmu->mm_lock); + out: + spin_unlock(&pfdev->as_lock); + return mapping; +@@ -542,6 +488,107 @@ err_bo: + return ret; + } + ++static void panfrost_mmu_release_ctx(struct kref *kref) ++{ ++ struct panfrost_mmu *mmu = container_of(kref, struct panfrost_mmu, ++ refcount); ++ struct panfrost_device *pfdev = mmu->pfdev; ++ ++ spin_lock(&pfdev->as_lock); ++ if (mmu->as >= 0) { ++ pm_runtime_get_noresume(pfdev->dev); ++ if (pm_runtime_active(pfdev->dev)) ++ panfrost_mmu_disable(pfdev, mmu->as); ++ pm_runtime_put_autosuspend(pfdev->dev); ++ ++ clear_bit(mmu->as, &pfdev->as_alloc_mask); ++ clear_bit(mmu->as, &pfdev->as_in_use_mask); ++ list_del(&mmu->list); ++ } ++ spin_unlock(&pfdev->as_lock); ++ ++ free_io_pgtable_ops(mmu->pgtbl_ops); ++ drm_mm_takedown(&mmu->mm); ++ kfree(mmu); ++} ++ ++void panfrost_mmu_ctx_put(struct panfrost_mmu *mmu) ++{ ++ kref_put(&mmu->refcount, panfrost_mmu_release_ctx); ++} ++ ++struct panfrost_mmu *panfrost_mmu_ctx_get(struct panfrost_mmu *mmu) ++{ ++ kref_get(&mmu->refcount); ++ ++ return mmu; ++} ++ ++#define PFN_4G (SZ_4G >> PAGE_SHIFT) ++#define PFN_4G_MASK (PFN_4G - 1) ++#define PFN_16M (SZ_16M >> PAGE_SHIFT) ++ ++static void panfrost_drm_mm_color_adjust(const struct drm_mm_node *node, ++ unsigned long color, ++ u64 *start, u64 *end) ++{ ++ /* Executable buffers can't start or end on a 4GB boundary */ ++ if (!(color & PANFROST_BO_NOEXEC)) { ++ u64 next_seg; ++ ++ if ((*start & PFN_4G_MASK) == 0) ++ (*start)++; ++ ++ if ((*end & PFN_4G_MASK) == 0) ++ (*end)--; ++ ++ next_seg = ALIGN(*start, PFN_4G); ++ if (next_seg - *start <= PFN_16M) ++ *start = next_seg + 1; ++ ++ *end = min(*end, ALIGN(*start, PFN_4G) - 1); ++ } ++} ++ ++struct panfrost_mmu *panfrost_mmu_ctx_create(struct panfrost_device *pfdev) ++{ ++ struct panfrost_mmu *mmu; ++ ++ mmu = kzalloc(sizeof(*mmu), GFP_KERNEL); ++ if (!mmu) ++ return ERR_PTR(-ENOMEM); ++ ++ mmu->pfdev = pfdev; ++ spin_lock_init(&mmu->mm_lock); ++ ++ /* 4G enough for now. can be 48-bit */ ++ drm_mm_init(&mmu->mm, SZ_32M >> PAGE_SHIFT, (SZ_4G - SZ_32M) >> PAGE_SHIFT); ++ mmu->mm.color_adjust = panfrost_drm_mm_color_adjust; ++ ++ INIT_LIST_HEAD(&mmu->list); ++ mmu->as = -1; ++ ++ mmu->pgtbl_cfg = (struct io_pgtable_cfg) { ++ .pgsize_bitmap = SZ_4K | SZ_2M, ++ .ias = FIELD_GET(0xff, pfdev->features.mmu_features), ++ .oas = FIELD_GET(0xff00, pfdev->features.mmu_features), ++ .coherent_walk = pfdev->coherent, ++ .tlb = &mmu_tlb_ops, ++ .iommu_dev = pfdev->dev, ++ }; ++ ++ mmu->pgtbl_ops = alloc_io_pgtable_ops(ARM_MALI_LPAE, &mmu->pgtbl_cfg, ++ mmu); ++ if (!mmu->pgtbl_ops) { ++ kfree(mmu); ++ return ERR_PTR(-EINVAL); ++ } ++ ++ kref_init(&mmu->refcount); ++ ++ return mmu; ++} ++ + static const char *access_type_name(struct panfrost_device *pfdev, + u32 fault_status) + { +diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.h b/drivers/gpu/drm/panfrost/panfrost_mmu.h +index 44fc2edf63ce6..cc2a0d307febc 100644 +--- a/drivers/gpu/drm/panfrost/panfrost_mmu.h ++++ b/drivers/gpu/drm/panfrost/panfrost_mmu.h +@@ -18,7 +18,8 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev); + u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); + void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); + +-int panfrost_mmu_pgtable_alloc(struct panfrost_file_priv *priv); +-void panfrost_mmu_pgtable_free(struct panfrost_file_priv *priv); ++struct panfrost_mmu *panfrost_mmu_ctx_get(struct panfrost_mmu *mmu); ++void panfrost_mmu_ctx_put(struct panfrost_mmu *mmu); ++struct panfrost_mmu *panfrost_mmu_ctx_create(struct panfrost_device *pfdev); + + #endif +diff --git a/drivers/gpu/drm/panfrost/panfrost_regs.h b/drivers/gpu/drm/panfrost/panfrost_regs.h +index dc9df5457f1c3..db3d9930b19c1 100644 +--- a/drivers/gpu/drm/panfrost/panfrost_regs.h ++++ b/drivers/gpu/drm/panfrost/panfrost_regs.h +@@ -319,6 +319,8 @@ + #define AS_FAULTSTATUS_ACCESS_TYPE_READ (0x2 << 8) + #define AS_FAULTSTATUS_ACCESS_TYPE_WRITE (0x3 << 8) + ++#define AS_LOCK_REGION_MIN_SIZE (1ULL << 15) ++ + #define gpu_write(dev, reg, data) writel(data, dev->iomem + reg) + #define gpu_read(dev, reg) readl(dev->iomem + reg) + +diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c b/drivers/gpu/drm/rcar-du/rcar_du_drv.c +index c22551c2facb1..2a06ec1cbefb0 100644 +--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c ++++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c +@@ -559,6 +559,13 @@ static int rcar_du_remove(struct platform_device *pdev) + return 0; + } + ++static void rcar_du_shutdown(struct platform_device *pdev) ++{ ++ struct rcar_du_device *rcdu = platform_get_drvdata(pdev); ++ ++ drm_atomic_helper_shutdown(&rcdu->ddev); ++} ++ + static int rcar_du_probe(struct platform_device *pdev) + { + struct rcar_du_device *rcdu; +@@ -615,6 +622,7 @@ error: + static struct platform_driver rcar_du_platform_driver = { + .probe = rcar_du_probe, + .remove = rcar_du_remove, ++ .shutdown = rcar_du_shutdown, + .driver = { + .name = "rcar-du", + .pm = &rcar_du_pm_ops, +diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c +index 8d7fd65ccced3..32202385073a2 100644 +--- a/drivers/gpu/drm/ttm/ttm_bo.c ++++ b/drivers/gpu/drm/ttm/ttm_bo.c +@@ -488,6 +488,31 @@ void ttm_bo_unlock_delayed_workqueue(struct ttm_device *bdev, int resched) + } + EXPORT_SYMBOL(ttm_bo_unlock_delayed_workqueue); + ++static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo, ++ struct ttm_resource **mem, ++ struct ttm_operation_ctx *ctx, ++ struct ttm_place *hop) ++{ ++ struct ttm_placement hop_placement; ++ struct ttm_resource *hop_mem; ++ int ret; ++ ++ hop_placement.num_placement = hop_placement.num_busy_placement = 1; ++ hop_placement.placement = hop_placement.busy_placement = hop; ++ ++ /* find space in the bounce domain */ ++ ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx); ++ if (ret) ++ return ret; ++ /* move to the bounce domain */ ++ ret = ttm_bo_handle_move_mem(bo, hop_mem, false, ctx, NULL); ++ if (ret) { ++ ttm_resource_free(bo, &hop_mem); ++ return ret; ++ } ++ return 0; ++} ++ + static int ttm_bo_evict(struct ttm_buffer_object *bo, + struct ttm_operation_ctx *ctx) + { +@@ -527,12 +552,17 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, + goto out; + } + ++bounce: + ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop); +- if (unlikely(ret)) { +- WARN(ret == -EMULTIHOP, "Unexpected multihop in eviction - likely driver bug\n"); +- if (ret != -ERESTARTSYS) ++ if (ret == -EMULTIHOP) { ++ ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop); ++ if (ret) { + pr_err("Buffer eviction failed\n"); +- ttm_resource_free(bo, &evict_mem); ++ ttm_resource_free(bo, &evict_mem); ++ goto out; ++ } ++ /* try and move to final place now. */ ++ goto bounce; + } + out: + return ret; +@@ -847,31 +877,6 @@ error: + } + EXPORT_SYMBOL(ttm_bo_mem_space); + +-static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo, +- struct ttm_resource **mem, +- struct ttm_operation_ctx *ctx, +- struct ttm_place *hop) +-{ +- struct ttm_placement hop_placement; +- struct ttm_resource *hop_mem; +- int ret; +- +- hop_placement.num_placement = hop_placement.num_busy_placement = 1; +- hop_placement.placement = hop_placement.busy_placement = hop; +- +- /* find space in the bounce domain */ +- ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx); +- if (ret) +- return ret; +- /* move to the bounce domain */ +- ret = ttm_bo_handle_move_mem(bo, hop_mem, false, ctx, NULL); +- if (ret) { +- ttm_resource_free(bo, &hop_mem); +- return ret; +- } +- return 0; +-} +- + static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, + struct ttm_placement *placement, + struct ttm_operation_ctx *ctx) +diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c +index 763fa6f4e07de..1c5ffe2935af5 100644 +--- a/drivers/gpu/drm/ttm/ttm_bo_util.c ++++ b/drivers/gpu/drm/ttm/ttm_bo_util.c +@@ -143,7 +143,6 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, + struct ttm_resource *src_mem = bo->resource; + struct ttm_resource_manager *src_man = + ttm_manager_type(bdev, src_mem->mem_type); +- struct ttm_resource src_copy = *src_mem; + union { + struct ttm_kmap_iter_tt tt; + struct ttm_kmap_iter_linear_io io; +@@ -173,11 +172,11 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, + } + + ttm_move_memcpy(bo, dst_mem->num_pages, dst_iter, src_iter); +- src_copy = *src_mem; +- ttm_bo_move_sync_cleanup(bo, dst_mem); + + if (!src_iter->ops->maps_tt) +- ttm_kmap_iter_linear_io_fini(&_src_iter.io, bdev, &src_copy); ++ ttm_kmap_iter_linear_io_fini(&_src_iter.io, bdev, src_mem); ++ ttm_bo_move_sync_cleanup(bo, dst_mem); ++ + out_src_iter: + if (!dst_iter->ops->maps_tt) + ttm_kmap_iter_linear_io_fini(&_dst_iter.io, bdev, dst_mem); +diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c +index c2876731ee2dc..f91d37beb1133 100644 +--- a/drivers/gpu/drm/vc4/vc4_hdmi.c ++++ b/drivers/gpu/drm/vc4/vc4_hdmi.c +@@ -613,12 +613,12 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder, + + HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, 0); + +- HDMI_WRITE(HDMI_VID_CTL, HDMI_READ(HDMI_VID_CTL) | +- VC4_HD_VID_CTL_CLRRGB | VC4_HD_VID_CTL_CLRSYNC); ++ HDMI_WRITE(HDMI_VID_CTL, HDMI_READ(HDMI_VID_CTL) | VC4_HD_VID_CTL_CLRRGB); + +- HDMI_WRITE(HDMI_VID_CTL, +- HDMI_READ(HDMI_VID_CTL) | VC4_HD_VID_CTL_BLANKPIX); ++ mdelay(1); + ++ HDMI_WRITE(HDMI_VID_CTL, ++ HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_ENABLE); + vc4_hdmi_disable_scrambling(encoder); + } + +@@ -628,12 +628,12 @@ static void vc4_hdmi_encoder_post_crtc_powerdown(struct drm_encoder *encoder, + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); + int ret; + ++ HDMI_WRITE(HDMI_VID_CTL, ++ HDMI_READ(HDMI_VID_CTL) | VC4_HD_VID_CTL_BLANKPIX); ++ + if (vc4_hdmi->variant->phy_disable) + vc4_hdmi->variant->phy_disable(vc4_hdmi); + +- HDMI_WRITE(HDMI_VID_CTL, +- HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_ENABLE); +- + clk_disable_unprepare(vc4_hdmi->pixel_bvb_clock); + clk_disable_unprepare(vc4_hdmi->pixel_clock); + +@@ -1015,6 +1015,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, + + HDMI_WRITE(HDMI_VID_CTL, + VC4_HD_VID_CTL_ENABLE | ++ VC4_HD_VID_CTL_CLRRGB | + VC4_HD_VID_CTL_UNDERFLOW_ENABLE | + VC4_HD_VID_CTL_FRAME_COUNTER_RESET | + (vsync_pos ? 0 : VC4_HD_VID_CTL_VSYNC_LOW) | +@@ -1372,7 +1373,9 @@ static int vc4_hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd, + HDMI_WRITE(HDMI_MAI_CTL, + VC4_SET_FIELD(vc4_hdmi->audio.channels, + VC4_HD_MAI_CTL_CHNUM) | +- VC4_HD_MAI_CTL_ENABLE); ++ VC4_HD_MAI_CTL_WHOLSMP | ++ VC4_HD_MAI_CTL_CHALIGN | ++ VC4_HD_MAI_CTL_ENABLE); + break; + case SNDRV_PCM_TRIGGER_STOP: + HDMI_WRITE(HDMI_MAI_CTL, +diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c +index 107521ace597a..092514a2155fe 100644 +--- a/drivers/gpu/drm/vkms/vkms_plane.c ++++ b/drivers/gpu/drm/vkms/vkms_plane.c +@@ -8,7 +8,6 @@ + #include + #include + #include +-#include + + #include "vkms_drv.h" + +@@ -150,45 +149,10 @@ static int vkms_plane_atomic_check(struct drm_plane *plane, + return 0; + } + +-static int vkms_prepare_fb(struct drm_plane *plane, +- struct drm_plane_state *state) +-{ +- struct drm_gem_object *gem_obj; +- struct dma_buf_map map; +- int ret; +- +- if (!state->fb) +- return 0; +- +- gem_obj = drm_gem_fb_get_obj(state->fb, 0); +- ret = drm_gem_shmem_vmap(gem_obj, &map); +- if (ret) +- DRM_ERROR("vmap failed: %d\n", ret); +- +- return drm_gem_plane_helper_prepare_fb(plane, state); +-} +- +-static void vkms_cleanup_fb(struct drm_plane *plane, +- struct drm_plane_state *old_state) +-{ +- struct drm_gem_object *gem_obj; +- struct drm_gem_shmem_object *shmem_obj; +- struct dma_buf_map map; +- +- if (!old_state->fb) +- return; +- +- gem_obj = drm_gem_fb_get_obj(old_state->fb, 0); +- shmem_obj = to_drm_gem_shmem_obj(drm_gem_fb_get_obj(old_state->fb, 0)); +- dma_buf_map_set_vaddr(&map, shmem_obj->vaddr); +- drm_gem_shmem_vunmap(gem_obj, &map); +-} +- + static const struct drm_plane_helper_funcs vkms_primary_helper_funcs = { + .atomic_update = vkms_plane_atomic_update, + .atomic_check = vkms_plane_atomic_check, +- .prepare_fb = vkms_prepare_fb, +- .cleanup_fb = vkms_cleanup_fb, ++ DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, + }; + + struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, +diff --git a/drivers/gpu/drm/vmwgfx/ttm_memory.c b/drivers/gpu/drm/vmwgfx/ttm_memory.c +index aeb0a22a2c347..edd17c30d5a51 100644 +--- a/drivers/gpu/drm/vmwgfx/ttm_memory.c ++++ b/drivers/gpu/drm/vmwgfx/ttm_memory.c +@@ -435,8 +435,10 @@ int ttm_mem_global_init(struct ttm_mem_global *glob, struct device *dev) + + si_meminfo(&si); + ++ spin_lock(&glob->lock); + /* set it as 0 by default to keep original behavior of OOM */ + glob->lower_mem_limit = 0; ++ spin_unlock(&glob->lock); + + ret = ttm_mem_init_kernel_zone(glob, &si); + if (unlikely(ret != 0)) +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c +index 05b3248259007..ea6d8c86985f6 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c +@@ -715,7 +715,7 @@ static int vmw_binding_scrub_cb(struct vmw_ctx_bindinfo *bi, bool rebind) + * without checking which bindings actually need to be emitted + * + * @cbs: Pointer to the context's struct vmw_ctx_binding_state +- * @bi: Pointer to where the binding info array is stored in @cbs ++ * @biv: Pointer to where the binding info array is stored in @cbs + * @max_num: Maximum number of entries in the @bi array. + * + * Scans the @bi array for bindings and builds a buffer of view id data. +@@ -725,11 +725,9 @@ static int vmw_binding_scrub_cb(struct vmw_ctx_bindinfo *bi, bool rebind) + * contains the command data. + */ + static void vmw_collect_view_ids(struct vmw_ctx_binding_state *cbs, +- const struct vmw_ctx_bindinfo *bi, ++ const struct vmw_ctx_bindinfo_view *biv, + u32 max_num) + { +- const struct vmw_ctx_bindinfo_view *biv = +- container_of(bi, struct vmw_ctx_bindinfo_view, bi); + unsigned long i; + + cbs->bind_cmd_count = 0; +@@ -838,7 +836,7 @@ static int vmw_emit_set_sr(struct vmw_ctx_binding_state *cbs, + */ + static int vmw_emit_set_rt(struct vmw_ctx_binding_state *cbs) + { +- const struct vmw_ctx_bindinfo *loc = &cbs->render_targets[0].bi; ++ const struct vmw_ctx_bindinfo_view *loc = &cbs->render_targets[0]; + struct { + SVGA3dCmdHeader header; + SVGA3dCmdDXSetRenderTargets body; +@@ -874,7 +872,7 @@ static int vmw_emit_set_rt(struct vmw_ctx_binding_state *cbs) + * without checking which bindings actually need to be emitted + * + * @cbs: Pointer to the context's struct vmw_ctx_binding_state +- * @bi: Pointer to where the binding info array is stored in @cbs ++ * @biso: Pointer to where the binding info array is stored in @cbs + * @max_num: Maximum number of entries in the @bi array. + * + * Scans the @bi array for bindings and builds a buffer of SVGA3dSoTarget data. +@@ -884,11 +882,9 @@ static int vmw_emit_set_rt(struct vmw_ctx_binding_state *cbs) + * contains the command data. + */ + static void vmw_collect_so_targets(struct vmw_ctx_binding_state *cbs, +- const struct vmw_ctx_bindinfo *bi, ++ const struct vmw_ctx_bindinfo_so_target *biso, + u32 max_num) + { +- const struct vmw_ctx_bindinfo_so_target *biso = +- container_of(bi, struct vmw_ctx_bindinfo_so_target, bi); + unsigned long i; + SVGA3dSoTarget *so_buffer = (SVGA3dSoTarget *) cbs->bind_cmd_buffer; + +@@ -919,7 +915,7 @@ static void vmw_collect_so_targets(struct vmw_ctx_binding_state *cbs, + */ + static int vmw_emit_set_so_target(struct vmw_ctx_binding_state *cbs) + { +- const struct vmw_ctx_bindinfo *loc = &cbs->so_targets[0].bi; ++ const struct vmw_ctx_bindinfo_so_target *loc = &cbs->so_targets[0]; + struct { + SVGA3dCmdHeader header; + SVGA3dCmdDXSetSOTargets body; +@@ -1066,7 +1062,7 @@ static int vmw_emit_set_vb(struct vmw_ctx_binding_state *cbs) + + static int vmw_emit_set_uav(struct vmw_ctx_binding_state *cbs) + { +- const struct vmw_ctx_bindinfo *loc = &cbs->ua_views[0].views[0].bi; ++ const struct vmw_ctx_bindinfo_view *loc = &cbs->ua_views[0].views[0]; + struct { + SVGA3dCmdHeader header; + SVGA3dCmdDXSetUAViews body; +@@ -1096,7 +1092,7 @@ static int vmw_emit_set_uav(struct vmw_ctx_binding_state *cbs) + + static int vmw_emit_set_cs_uav(struct vmw_ctx_binding_state *cbs) + { +- const struct vmw_ctx_bindinfo *loc = &cbs->ua_views[1].views[0].bi; ++ const struct vmw_ctx_bindinfo_view *loc = &cbs->ua_views[1].views[0]; + struct { + SVGA3dCmdHeader header; + SVGA3dCmdDXSetCSUAViews body; +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c +index 6bb4961e64a57..9656d4a2abff8 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c +@@ -516,7 +516,7 @@ static void vmw_cmdbuf_work_func(struct work_struct *work) + struct vmw_cmdbuf_man *man = + container_of(work, struct vmw_cmdbuf_man, work); + struct vmw_cmdbuf_header *entry, *next; +- uint32_t dummy; ++ uint32_t dummy = 0; + bool send_fence = false; + struct list_head restart_head[SVGA_CB_CONTEXT_MAX]; + int i; +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c +index b262d61d839d5..9487faff52293 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c +@@ -159,6 +159,7 @@ void vmw_cmdbuf_res_commit(struct list_head *list) + void vmw_cmdbuf_res_revert(struct list_head *list) + { + struct vmw_cmdbuf_res *entry, *next; ++ int ret; + + list_for_each_entry_safe(entry, next, list, head) { + switch (entry->state) { +@@ -166,7 +167,8 @@ void vmw_cmdbuf_res_revert(struct list_head *list) + vmw_cmdbuf_res_free(entry->man, entry); + break; + case VMW_CMDBUF_RES_DEL: +- drm_ht_insert_item(&entry->man->resources, &entry->hash); ++ ret = drm_ht_insert_item(&entry->man->resources, &entry->hash); ++ BUG_ON(ret); + list_del(&entry->head); + list_add_tail(&entry->head, &entry->man->list); + entry->state = VMW_CMDBUF_RES_COMMITTED; +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +index a2b8464b3f566..06e8332682c5e 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +@@ -2546,6 +2546,8 @@ static int vmw_cmd_dx_so_define(struct vmw_private *dev_priv, + + so_type = vmw_so_cmd_to_type(header->id); + res = vmw_context_cotable(ctx_node->ctx, vmw_so_cotables[so_type]); ++ if (IS_ERR(res)) ++ return PTR_ERR(res); + cmd = container_of(header, typeof(*cmd), header); + ret = vmw_cotable_notify(res, cmd->defined_id); + +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c +index f2d6254154585..2d8caf09f1727 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c +@@ -506,11 +506,13 @@ static void vmw_mob_pt_setup(struct vmw_mob *mob, + { + unsigned long num_pt_pages = 0; + struct ttm_buffer_object *bo = mob->pt_bo; +- struct vmw_piter save_pt_iter; ++ struct vmw_piter save_pt_iter = {0}; + struct vmw_piter pt_iter; + const struct vmw_sg_table *vsgt; + int ret; + ++ BUG_ON(num_data_pages == 0); ++ + ret = ttm_bo_reserve(bo, false, true, NULL); + BUG_ON(ret != 0); + +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +index 3d08f5700bdb4..7e3f99722d026 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +@@ -155,6 +155,7 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel, + /* HB port can't access encrypted memory. */ + if (hb && !mem_encrypt_active()) { + unsigned long bp = channel->cookie_high; ++ u32 channel_id = (channel->channel_id << 16); + + si = (uintptr_t) msg; + di = channel->cookie_low; +@@ -162,7 +163,7 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel, + VMW_PORT_HB_OUT( + (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG, + msg_len, si, di, +- VMWARE_HYPERVISOR_HB | (channel->channel_id << 16) | ++ VMWARE_HYPERVISOR_HB | channel_id | + VMWARE_HYPERVISOR_OUT, + VMW_HYPERVISOR_MAGIC, bp, + eax, ebx, ecx, edx, si, di); +@@ -210,6 +211,7 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply, + /* HB port can't access encrypted memory */ + if (hb && !mem_encrypt_active()) { + unsigned long bp = channel->cookie_low; ++ u32 channel_id = (channel->channel_id << 16); + + si = channel->cookie_high; + di = (uintptr_t) reply; +@@ -217,7 +219,7 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply, + VMW_PORT_HB_IN( + (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG, + reply_len, si, di, +- VMWARE_HYPERVISOR_HB | (channel->channel_id << 16), ++ VMWARE_HYPERVISOR_HB | channel_id, + VMW_HYPERVISOR_MAGIC, bp, + eax, ebx, ecx, edx, si, di); + +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +index 7b45393ad98e9..3b6f6044c3259 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +@@ -114,6 +114,7 @@ static void vmw_resource_release(struct kref *kref) + container_of(kref, struct vmw_resource, kref); + struct vmw_private *dev_priv = res->dev_priv; + int id; ++ int ret; + struct idr *idr = &dev_priv->res_idr[res->func->res_type]; + + spin_lock(&dev_priv->resource_lock); +@@ -122,7 +123,8 @@ static void vmw_resource_release(struct kref *kref) + if (res->backup) { + struct ttm_buffer_object *bo = &res->backup->base; + +- ttm_bo_reserve(bo, false, false, NULL); ++ ret = ttm_bo_reserve(bo, false, false, NULL); ++ BUG_ON(ret); + if (vmw_resource_mob_attached(res) && + res->func->unbind != NULL) { + struct ttm_validate_buffer val_buf; +@@ -1001,7 +1003,9 @@ int vmw_resource_pin(struct vmw_resource *res, bool interruptible) + if (res->backup) { + vbo = res->backup; + +- ttm_bo_reserve(&vbo->base, interruptible, false, NULL); ++ ret = ttm_bo_reserve(&vbo->base, interruptible, false, NULL); ++ if (ret) ++ goto out_no_validate; + if (!vbo->base.pin_count) { + ret = ttm_bo_validate + (&vbo->base, +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c +index c3a8d6e8380e4..9efb4463ce997 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c +@@ -539,7 +539,8 @@ const SVGACOTableType vmw_so_cotables[] = { + [vmw_so_ds] = SVGA_COTABLE_DEPTHSTENCIL, + [vmw_so_rs] = SVGA_COTABLE_RASTERIZERSTATE, + [vmw_so_ss] = SVGA_COTABLE_SAMPLER, +- [vmw_so_so] = SVGA_COTABLE_STREAMOUTPUT ++ [vmw_so_so] = SVGA_COTABLE_STREAMOUTPUT, ++ [vmw_so_max]= SVGA_COTABLE_MAX + }; + + +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +index 0835468bb2eed..a04ad7812960c 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +@@ -865,7 +865,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, + user_srf->prime.base.shareable = false; + user_srf->prime.base.tfile = NULL; + if (drm_is_primary_client(file_priv)) +- user_srf->master = drm_master_get(file_priv->master); ++ user_srf->master = drm_file_get_master(file_priv); + + /** + * From this point, the generic resource management functions +@@ -1534,7 +1534,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev, + + user_srf = container_of(srf, struct vmw_user_surface, srf); + if (drm_is_primary_client(file_priv)) +- user_srf->master = drm_master_get(file_priv->master); ++ user_srf->master = drm_file_get_master(file_priv); + + res = &user_srf->srf.res; + +@@ -1872,7 +1872,6 @@ static void vmw_surface_dirty_range_add(struct vmw_resource *res, size_t start, + static int vmw_surface_dirty_sync(struct vmw_resource *res) + { + struct vmw_private *dev_priv = res->dev_priv; +- bool has_dx = 0; + u32 i, num_dirty; + struct vmw_surface_dirty *dirty = + (struct vmw_surface_dirty *) res->dirty; +@@ -1899,7 +1898,7 @@ static int vmw_surface_dirty_sync(struct vmw_resource *res) + if (!num_dirty) + goto out; + +- alloc_size = num_dirty * ((has_dx) ? sizeof(*cmd1) : sizeof(*cmd2)); ++ alloc_size = num_dirty * ((has_sm4_context(dev_priv)) ? sizeof(*cmd1) : sizeof(*cmd2)); + cmd = VMW_CMD_RESERVE(dev_priv, alloc_size); + if (!cmd) + return -ENOMEM; +@@ -1917,7 +1916,7 @@ static int vmw_surface_dirty_sync(struct vmw_resource *res) + * DX_UPDATE_SUBRESOURCE is aware of array surfaces. + * UPDATE_GB_IMAGE is not. + */ +- if (has_dx) { ++ if (has_sm4_context(dev_priv)) { + cmd1->header.id = SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE; + cmd1->header.size = sizeof(cmd1->body); + cmd1->body.sid = res->id; +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +index 8338b1d20f2a3..b09094b50c5d0 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +@@ -586,13 +586,13 @@ int vmw_validation_bo_validate(struct vmw_validation_context *ctx, bool intr) + container_of(entry->base.bo, typeof(*vbo), base); + + if (entry->cpu_blit) { +- struct ttm_operation_ctx ctx = { ++ struct ttm_operation_ctx ttm_ctx = { + .interruptible = intr, + .no_wait_gpu = false + }; + + ret = ttm_bo_validate(entry->base.bo, +- &vmw_nonfixed_placement, &ctx); ++ &vmw_nonfixed_placement, &ttm_ctx); + } else { + ret = vmw_validation_bo_validate_single + (entry->base.bo, intr, entry->as_mob); +diff --git a/drivers/gpu/drm/xlnx/zynqmp_disp.c b/drivers/gpu/drm/xlnx/zynqmp_disp.c +index 109d627968ac0..01c6ce7784ddb 100644 +--- a/drivers/gpu/drm/xlnx/zynqmp_disp.c ++++ b/drivers/gpu/drm/xlnx/zynqmp_disp.c +@@ -1452,9 +1452,10 @@ zynqmp_disp_crtc_atomic_enable(struct drm_crtc *crtc, + struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode; + int ret, vrefresh; + ++ pm_runtime_get_sync(disp->dev); ++ + zynqmp_disp_crtc_setup_clock(crtc, adjusted_mode); + +- pm_runtime_get_sync(disp->dev); + ret = clk_prepare_enable(disp->pclk); + if (ret) { + dev_err(disp->dev, "failed to enable a pixel clock\n"); +diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c +index 82430ca9b9133..6f588dc09ba63 100644 +--- a/drivers/gpu/drm/xlnx/zynqmp_dp.c ++++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c +@@ -402,10 +402,6 @@ static int zynqmp_dp_phy_init(struct zynqmp_dp *dp) + } + } + +- ret = zynqmp_dp_reset(dp, false); +- if (ret < 0) +- return ret; +- + zynqmp_dp_clr(dp, ZYNQMP_DP_PHY_RESET, ZYNQMP_DP_PHY_RESET_ALL_RESET); + + /* +@@ -441,8 +437,6 @@ static void zynqmp_dp_phy_exit(struct zynqmp_dp *dp) + ret); + } + +- zynqmp_dp_reset(dp, true); +- + for (i = 0; i < dp->num_lanes; i++) { + ret = phy_exit(dp->phy[i]); + if (ret) +@@ -1683,9 +1677,13 @@ int zynqmp_dp_probe(struct zynqmp_dpsub *dpsub, struct drm_device *drm) + return PTR_ERR(dp->reset); + } + ++ ret = zynqmp_dp_reset(dp, false); ++ if (ret < 0) ++ return ret; ++ + ret = zynqmp_dp_phy_probe(dp); + if (ret) +- return ret; ++ goto err_reset; + + /* Initialize the hardware. */ + zynqmp_dp_write(dp, ZYNQMP_DP_TX_PHY_POWER_DOWN, +@@ -1697,7 +1695,7 @@ int zynqmp_dp_probe(struct zynqmp_dpsub *dpsub, struct drm_device *drm) + + ret = zynqmp_dp_phy_init(dp); + if (ret) +- return ret; ++ goto err_reset; + + zynqmp_dp_write(dp, ZYNQMP_DP_TRANSMITTER_ENABLE, 1); + +@@ -1709,15 +1707,18 @@ int zynqmp_dp_probe(struct zynqmp_dpsub *dpsub, struct drm_device *drm) + zynqmp_dp_irq_handler, IRQF_ONESHOT, + dev_name(dp->dev), dp); + if (ret < 0) +- goto error; ++ goto err_phy_exit; + + dev_dbg(dp->dev, "ZynqMP DisplayPort Tx probed with %u lanes\n", + dp->num_lanes); + + return 0; + +-error: ++err_phy_exit: + zynqmp_dp_phy_exit(dp); ++err_reset: ++ zynqmp_dp_reset(dp, true); ++ + return ret; + } + +@@ -1735,4 +1736,5 @@ void zynqmp_dp_remove(struct zynqmp_dpsub *dpsub) + zynqmp_dp_write(dp, ZYNQMP_DP_INT_DS, 0xffffffff); + + zynqmp_dp_phy_exit(dp); ++ zynqmp_dp_reset(dp, true); + } +diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile +index 1ea1a7c0b20fe..e29efcb1c0402 100644 +--- a/drivers/hid/Makefile ++++ b/drivers/hid/Makefile +@@ -115,7 +115,6 @@ obj-$(CONFIG_HID_STEELSERIES) += hid-steelseries.o + obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o + obj-$(CONFIG_HID_GREENASIA) += hid-gaff.o + obj-$(CONFIG_HID_THRUSTMASTER) += hid-tmff.o hid-thrustmaster.o +-obj-$(CONFIG_HID_TMINIT) += hid-tminit.o + obj-$(CONFIG_HID_TIVO) += hid-tivo.o + obj-$(CONFIG_HID_TOPSEED) += hid-topseed.o + obj-$(CONFIG_HID_TWINHAN) += hid-twinhan.o +diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c +index efb849411d254..4710b9aa24a57 100644 +--- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c ++++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c +@@ -184,7 +184,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) + rc = -ENOMEM; + goto cleanup; + } +- info.period = msecs_to_jiffies(AMD_SFH_IDLE_LOOP); ++ info.period = AMD_SFH_IDLE_LOOP; + info.sensor_idx = cl_idx; + info.dma_address = cl_data->sensor_dma_addr[i]; + +diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c +index 4286a51f7f169..4b5ebeacd2836 100644 +--- a/drivers/hid/hid-input.c ++++ b/drivers/hid/hid-input.c +@@ -419,8 +419,6 @@ static int hidinput_get_battery_property(struct power_supply *psy, + + if (dev->battery_status == HID_BATTERY_UNKNOWN) + val->intval = POWER_SUPPLY_STATUS_UNKNOWN; +- else if (dev->battery_capacity == 100) +- val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + break; +diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c +index 51b39bda9a9d2..2e104682c22b9 100644 +--- a/drivers/hid/hid-quirks.c ++++ b/drivers/hid/hid-quirks.c +@@ -662,8 +662,6 @@ static const struct hid_device_id hid_have_special_driver[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) }, + { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, + { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) }, +-#endif +-#if IS_ENABLED(CONFIG_HID_TMINIT) + { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65d) }, + #endif + #if IS_ENABLED(CONFIG_HID_TIVO) +diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c +index 46474612e73c6..517141138b007 100644 +--- a/drivers/hid/i2c-hid/i2c-hid-core.c ++++ b/drivers/hid/i2c-hid/i2c-hid-core.c +@@ -171,8 +171,6 @@ static const struct i2c_hid_quirks { + I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, + { I2C_VENDOR_ID_RAYDIUM, I2C_PRODUCT_ID_RAYDIUM_3118, + I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, +- { USB_VENDOR_ID_ELAN, HID_ANY_ID, +- I2C_HID_QUIRK_BOGUS_IRQ }, + { USB_VENDOR_ID_ALPS_JP, HID_ANY_ID, + I2C_HID_QUIRK_RESET_ON_RESUME }, + { I2C_VENDOR_ID_SYNAPTICS, I2C_PRODUCT_ID_SYNAPTICS_SYNA2393, +@@ -183,7 +181,8 @@ static const struct i2c_hid_quirks { + * Sending the wakeup after reset actually break ELAN touchscreen controller + */ + { USB_VENDOR_ID_ELAN, HID_ANY_ID, +- I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET }, ++ I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET | ++ I2C_HID_QUIRK_BOGUS_IRQ }, + { 0, 0 } + }; + +diff --git a/drivers/hwmon/pmbus/ibm-cffps.c b/drivers/hwmon/pmbus/ibm-cffps.c +index 5668d8305b78e..df712ce4b164d 100644 +--- a/drivers/hwmon/pmbus/ibm-cffps.c ++++ b/drivers/hwmon/pmbus/ibm-cffps.c +@@ -50,9 +50,9 @@ + #define CFFPS_MFR_VAUX_FAULT BIT(6) + #define CFFPS_MFR_CURRENT_SHARE_WARNING BIT(7) + +-#define CFFPS_LED_BLINK BIT(0) +-#define CFFPS_LED_ON BIT(1) +-#define CFFPS_LED_OFF BIT(2) ++#define CFFPS_LED_BLINK (BIT(0) | BIT(6)) ++#define CFFPS_LED_ON (BIT(1) | BIT(6)) ++#define CFFPS_LED_OFF (BIT(2) | BIT(6)) + #define CFFPS_BLINK_RATE_MS 250 + + enum { +diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c +index 9bde869829121..530529feebb51 100644 +--- a/drivers/iio/dac/ad5624r_spi.c ++++ b/drivers/iio/dac/ad5624r_spi.c +@@ -229,7 +229,7 @@ static int ad5624r_probe(struct spi_device *spi) + if (!indio_dev) + return -ENOMEM; + st = iio_priv(indio_dev); +- st->reg = devm_regulator_get(&spi->dev, "vcc"); ++ st->reg = devm_regulator_get_optional(&spi->dev, "vref"); + if (!IS_ERR(st->reg)) { + ret = regulator_enable(st->reg); + if (ret) +@@ -240,6 +240,22 @@ static int ad5624r_probe(struct spi_device *spi) + goto error_disable_reg; + + voltage_uv = ret; ++ } else { ++ if (PTR_ERR(st->reg) != -ENODEV) ++ return PTR_ERR(st->reg); ++ /* Backwards compatibility. This naming is not correct */ ++ st->reg = devm_regulator_get_optional(&spi->dev, "vcc"); ++ if (!IS_ERR(st->reg)) { ++ ret = regulator_enable(st->reg); ++ if (ret) ++ return ret; ++ ++ ret = regulator_get_voltage(st->reg); ++ if (ret < 0) ++ goto error_disable_reg; ++ ++ voltage_uv = ret; ++ } + } + + spi_set_drvdata(spi, indio_dev); +diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c +index 3b5ba26d7d867..3b4a0e60e6059 100644 +--- a/drivers/iio/temperature/ltc2983.c ++++ b/drivers/iio/temperature/ltc2983.c +@@ -89,6 +89,8 @@ + + #define LTC2983_STATUS_START_MASK BIT(7) + #define LTC2983_STATUS_START(x) FIELD_PREP(LTC2983_STATUS_START_MASK, x) ++#define LTC2983_STATUS_UP_MASK GENMASK(7, 6) ++#define LTC2983_STATUS_UP(reg) FIELD_GET(LTC2983_STATUS_UP_MASK, reg) + + #define LTC2983_STATUS_CHAN_SEL_MASK GENMASK(4, 0) + #define LTC2983_STATUS_CHAN_SEL(x) \ +@@ -1362,17 +1364,16 @@ put_child: + + static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) + { +- u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0; ++ u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0, status; + int ret; +- unsigned long time; +- +- /* make sure the device is up */ +- time = wait_for_completion_timeout(&st->completion, +- msecs_to_jiffies(250)); + +- if (!time) { ++ /* make sure the device is up: start bit (7) is 0 and done bit (6) is 1 */ ++ ret = regmap_read_poll_timeout(st->regmap, LTC2983_STATUS_REG, status, ++ LTC2983_STATUS_UP(status) == 1, 25000, ++ 25000 * 10); ++ if (ret) { + dev_err(&st->spi->dev, "Device startup timed out\n"); +- return -ETIMEDOUT; ++ return ret; + } + + st->iio_chan = devm_kzalloc(&st->spi->dev, +@@ -1492,10 +1493,11 @@ static int ltc2983_probe(struct spi_device *spi) + ret = ltc2983_parse_dt(st); + if (ret) + return ret; +- /* +- * let's request the irq now so it is used to sync the device +- * startup in ltc2983_setup() +- */ ++ ++ ret = ltc2983_setup(st, true); ++ if (ret) ++ return ret; ++ + ret = devm_request_irq(&spi->dev, spi->irq, ltc2983_irq_handler, + IRQF_TRIGGER_RISING, name, st); + if (ret) { +@@ -1503,10 +1505,6 @@ static int ltc2983_probe(struct spi_device *spi) + return ret; + } + +- ret = ltc2983_setup(st, true); +- if (ret) +- return ret; +- + indio_dev->name = name; + indio_dev->num_channels = st->iio_channels; + indio_dev->channels = st->iio_chan; +diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c +index 42261152b4892..2b47073c61a65 100644 +--- a/drivers/infiniband/core/iwcm.c ++++ b/drivers/infiniband/core/iwcm.c +@@ -1186,29 +1186,34 @@ static int __init iw_cm_init(void) + + ret = iwpm_init(RDMA_NL_IWCM); + if (ret) +- pr_err("iw_cm: couldn't init iwpm\n"); +- else +- rdma_nl_register(RDMA_NL_IWCM, iwcm_nl_cb_table); ++ return ret; ++ + iwcm_wq = alloc_ordered_workqueue("iw_cm_wq", 0); + if (!iwcm_wq) +- return -ENOMEM; ++ goto err_alloc; + + iwcm_ctl_table_hdr = register_net_sysctl(&init_net, "net/iw_cm", + iwcm_ctl_table); + if (!iwcm_ctl_table_hdr) { + pr_err("iw_cm: couldn't register sysctl paths\n"); +- destroy_workqueue(iwcm_wq); +- return -ENOMEM; ++ goto err_sysctl; + } + ++ rdma_nl_register(RDMA_NL_IWCM, iwcm_nl_cb_table); + return 0; ++ ++err_sysctl: ++ destroy_workqueue(iwcm_wq); ++err_alloc: ++ iwpm_exit(RDMA_NL_IWCM); ++ return -ENOMEM; + } + + static void __exit iw_cm_cleanup(void) + { ++ rdma_nl_unregister(RDMA_NL_IWCM); + unregister_net_sysctl_table(iwcm_ctl_table_hdr); + destroy_workqueue(iwcm_wq); +- rdma_nl_unregister(RDMA_NL_IWCM); + iwpm_exit(RDMA_NL_IWCM); + } + +diff --git a/drivers/infiniband/hw/efa/efa_verbs.c b/drivers/infiniband/hw/efa/efa_verbs.c +index be6d3ff0f1be2..29c9df9f25aa3 100644 +--- a/drivers/infiniband/hw/efa/efa_verbs.c ++++ b/drivers/infiniband/hw/efa/efa_verbs.c +@@ -717,7 +717,6 @@ struct ib_qp *efa_create_qp(struct ib_pd *ibpd, + + qp->qp_handle = create_qp_resp.qp_handle; + qp->ibqp.qp_num = create_qp_resp.qp_num; +- qp->ibqp.qp_type = init_attr->qp_type; + qp->max_send_wr = init_attr->cap.max_send_wr; + qp->max_recv_wr = init_attr->cap.max_recv_wr; + qp->max_send_sge = init_attr->cap.max_send_sge; +diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c +index 0986aa065418a..34106e5be6794 100644 +--- a/drivers/infiniband/hw/hfi1/init.c ++++ b/drivers/infiniband/hw/hfi1/init.c +@@ -650,12 +650,7 @@ void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd, + + ppd->pkeys[default_pkey_idx] = DEFAULT_P_KEY; + ppd->part_enforce |= HFI1_PART_ENFORCE_IN; +- +- if (loopback) { +- dd_dev_err(dd, "Faking data partition 0x8001 in idx %u\n", +- !default_pkey_idx); +- ppd->pkeys[!default_pkey_idx] = 0x8001; +- } ++ ppd->pkeys[0] = 0x8001; + + INIT_WORK(&ppd->link_vc_work, handle_verify_cap); + INIT_WORK(&ppd->link_up_work, handle_link_up); +diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h +index 991f65269fa61..8518b1571f2c6 100644 +--- a/drivers/infiniband/hw/hns/hns_roce_device.h ++++ b/drivers/infiniband/hw/hns/hns_roce_device.h +@@ -496,6 +496,12 @@ struct hns_roce_bank { + u32 next; /* Next ID to allocate. */ + }; + ++struct hns_roce_idx_table { ++ u32 *spare_idx; ++ u32 head; ++ u32 tail; ++}; ++ + struct hns_roce_qp_table { + struct hns_roce_hem_table qp_table; + struct hns_roce_hem_table irrl_table; +@@ -504,6 +510,7 @@ struct hns_roce_qp_table { + struct mutex scc_mutex; + struct hns_roce_bank bank[HNS_ROCE_QP_BANK_NUM]; + struct mutex bank_mutex; ++ struct hns_roce_idx_table idx_table; + }; + + struct hns_roce_cq_table { +@@ -1146,7 +1153,7 @@ int hns_roce_mtr_map(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, + void hns_roce_init_pd_table(struct hns_roce_dev *hr_dev); + void hns_roce_init_mr_table(struct hns_roce_dev *hr_dev); + void hns_roce_init_cq_table(struct hns_roce_dev *hr_dev); +-void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev); ++int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev); + int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev); + void hns_roce_init_xrcd_table(struct hns_roce_dev *hr_dev); + +diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +index 594d4cef31b36..bf4d9f6658ff9 100644 +--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c ++++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +@@ -4114,6 +4114,9 @@ static void modify_qp_reset_to_init(struct ib_qp *ibqp, + if (hr_qp->en_flags & HNS_ROCE_QP_CAP_RQ_RECORD_DB) + hr_reg_enable(context, QPC_RQ_RECORD_EN); + ++ if (hr_qp->en_flags & HNS_ROCE_QP_CAP_OWNER_DB) ++ hr_reg_enable(context, QPC_OWNER_MODE); ++ + hr_reg_write(context, QPC_RQ_DB_RECORD_ADDR_L, + lower_32_bits(hr_qp->rdb.dma) >> 1); + hr_reg_write(context, QPC_RQ_DB_RECORD_ADDR_H, +@@ -4486,9 +4489,6 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp, + + hr_reg_clear(qpc_mask, QPC_CHECK_FLG); + +- hr_reg_write(context, QPC_LSN, 0x100); +- hr_reg_clear(qpc_mask, QPC_LSN); +- + hr_reg_clear(qpc_mask, QPC_V2_IRRL_HEAD); + + return 0; +@@ -4507,15 +4507,23 @@ static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr, + { + const struct ib_global_route *grh = rdma_ah_read_grh(&attr->ah_attr); + struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device); ++ u32 *spare_idx = hr_dev->qp_table.idx_table.spare_idx; ++ u32 *head = &hr_dev->qp_table.idx_table.head; ++ u32 *tail = &hr_dev->qp_table.idx_table.tail; + struct hns_roce_dip *hr_dip; + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&hr_dev->dip_list_lock, flags); + ++ spare_idx[*tail] = ibqp->qp_num; ++ *tail = (*tail == hr_dev->caps.num_qps - 1) ? 0 : (*tail + 1); ++ + list_for_each_entry(hr_dip, &hr_dev->dip_list, node) { +- if (!memcmp(grh->dgid.raw, hr_dip->dgid, 16)) ++ if (!memcmp(grh->dgid.raw, hr_dip->dgid, 16)) { ++ *dip_idx = hr_dip->dip_idx; + goto out; ++ } + } + + /* If no dgid is found, a new dip and a mapping between dgid and +@@ -4528,7 +4536,8 @@ static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr, + } + + memcpy(hr_dip->dgid, grh->dgid.raw, sizeof(grh->dgid.raw)); +- hr_dip->dip_idx = *dip_idx = ibqp->qp_num; ++ hr_dip->dip_idx = *dip_idx = spare_idx[*head]; ++ *head = (*head == hr_dev->caps.num_qps - 1) ? 0 : (*head + 1); + list_add_tail(&hr_dip->node, &hr_dev->dip_list); + + out: +@@ -5127,7 +5136,7 @@ static int hns_roce_v2_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, + + qp_attr->rq_psn = hr_reg_read(&context, QPC_RX_REQ_EPSN); + qp_attr->sq_psn = (u32)hr_reg_read(&context, QPC_SQ_CUR_PSN); +- qp_attr->dest_qp_num = (u8)hr_reg_read(&context, QPC_DQPN); ++ qp_attr->dest_qp_num = hr_reg_read(&context, QPC_DQPN); + qp_attr->qp_access_flags = + ((hr_reg_read(&context, QPC_RRE)) << V2_QP_RRE_S) | + ((hr_reg_read(&context, QPC_RWE)) << V2_QP_RWE_S) | +diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h +index b8a09d411e2e5..68c8c4b225ca3 100644 +--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h ++++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h +@@ -1447,7 +1447,7 @@ struct hns_roce_v2_priv { + + struct hns_roce_dip { + u8 dgid[GID_LEN_V2]; +- u8 dip_idx; ++ u32 dip_idx; + struct list_head node; /* all dips are on a list */ + }; + +diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c +index cc6eab14a2220..217aad8d9bd93 100644 +--- a/drivers/infiniband/hw/hns/hns_roce_main.c ++++ b/drivers/infiniband/hw/hns/hns_roce_main.c +@@ -748,6 +748,12 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev) + goto err_uar_table_free; + } + ++ ret = hns_roce_init_qp_table(hr_dev); ++ if (ret) { ++ dev_err(dev, "Failed to init qp_table.\n"); ++ goto err_uar_table_free; ++ } ++ + hns_roce_init_pd_table(hr_dev); + + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC) +@@ -757,8 +763,6 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev) + + hns_roce_init_cq_table(hr_dev); + +- hns_roce_init_qp_table(hr_dev); +- + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SRQ) { + ret = hns_roce_init_srq_table(hr_dev); + if (ret) { +diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c +index 006c84bb3f9fd..7089ac7802913 100644 +--- a/drivers/infiniband/hw/hns/hns_roce_mr.c ++++ b/drivers/infiniband/hw/hns/hns_roce_mr.c +@@ -352,7 +352,9 @@ struct ib_mr *hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, + free_cmd_mbox: + hns_roce_free_cmd_mailbox(hr_dev, mailbox); + +- return ERR_PTR(ret); ++ if (ret) ++ return ERR_PTR(ret); ++ return NULL; + } + + int hns_roce_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata) +diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c +index b101b7e578f25..a6d1e44b75cf7 100644 +--- a/drivers/infiniband/hw/hns/hns_roce_qp.c ++++ b/drivers/infiniband/hw/hns/hns_roce_qp.c +@@ -848,7 +848,6 @@ static int alloc_qp_db(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp, + goto err_out; + } + hr_qp->en_flags |= HNS_ROCE_QP_CAP_SQ_RECORD_DB; +- resp->cap_flags |= HNS_ROCE_QP_CAP_SQ_RECORD_DB; + } + + if (user_qp_has_rdb(hr_dev, init_attr, udata, resp)) { +@@ -861,7 +860,6 @@ static int alloc_qp_db(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp, + goto err_sdb; + } + hr_qp->en_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB; +- resp->cap_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB; + } + } else { + if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09) +@@ -1073,6 +1071,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, + } + + if (udata) { ++ resp.cap_flags = hr_qp->en_flags; + ret = ib_copy_to_udata(udata, &resp, + min(udata->outlen, sizeof(resp))); + if (ret) { +@@ -1171,14 +1170,8 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd, + if (!hr_qp) + return ERR_PTR(-ENOMEM); + +- if (init_attr->qp_type == IB_QPT_XRC_INI) +- init_attr->recv_cq = NULL; +- +- if (init_attr->qp_type == IB_QPT_XRC_TGT) { ++ if (init_attr->qp_type == IB_QPT_XRC_TGT) + hr_qp->xrcdn = to_hr_xrcd(init_attr->xrcd)->xrcdn; +- init_attr->recv_cq = NULL; +- init_attr->send_cq = NULL; +- } + + if (init_attr->qp_type == IB_QPT_GSI) { + hr_qp->port = init_attr->port_num - 1; +@@ -1429,12 +1422,17 @@ bool hns_roce_wq_overflow(struct hns_roce_wq *hr_wq, u32 nreq, + return cur + nreq >= hr_wq->wqe_cnt; + } + +-void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev) ++int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev) + { + struct hns_roce_qp_table *qp_table = &hr_dev->qp_table; + unsigned int reserved_from_bot; + unsigned int i; + ++ qp_table->idx_table.spare_idx = kcalloc(hr_dev->caps.num_qps, ++ sizeof(u32), GFP_KERNEL); ++ if (!qp_table->idx_table.spare_idx) ++ return -ENOMEM; ++ + mutex_init(&qp_table->scc_mutex); + mutex_init(&qp_table->bank_mutex); + xa_init(&hr_dev->qp_table_xa); +@@ -1452,6 +1450,8 @@ void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev) + HNS_ROCE_QP_BANK_NUM - 1; + hr_dev->qp_table.bank[i].next = hr_dev->qp_table.bank[i].min; + } ++ ++ return 0; + } + + void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev) +@@ -1460,4 +1460,5 @@ void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev) + + for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++) + ida_destroy(&hr_dev->qp_table.bank[i].ida); ++ kfree(hr_dev->qp_table.idx_table.spare_idx); + } +diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c +index a77db29f83914..fd88b9ae96fe8 100644 +--- a/drivers/infiniband/hw/mlx5/qp.c ++++ b/drivers/infiniband/hw/mlx5/qp.c +@@ -1906,7 +1906,6 @@ static int get_atomic_mode(struct mlx5_ib_dev *dev, + static int create_xrc_tgt_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, + struct mlx5_create_qp_params *params) + { +- struct mlx5_ib_create_qp *ucmd = params->ucmd; + struct ib_qp_init_attr *attr = params->attr; + u32 uidx = params->uidx; + struct mlx5_ib_resources *devr = &dev->devr; +@@ -1926,8 +1925,6 @@ static int create_xrc_tgt_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, + if (!in) + return -ENOMEM; + +- if (MLX5_CAP_GEN(mdev, ece_support) && ucmd) +- MLX5_SET(create_qp_in, in, ece, ucmd->ece_options); + qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); + + MLX5_SET(qpc, qpc, st, MLX5_QP_ST_XRC); +diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c +index f2c40e50f25ea..ece3205531b8e 100644 +--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c ++++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c +@@ -478,7 +478,7 @@ static int rtrs_post_send_rdma(struct rtrs_clt_con *con, + * From time to time we have to post signalled sends, + * or send queue will fill up and only QP reset can help. + */ +- flags = atomic_inc_return(&con->io_cnt) % sess->queue_depth ? ++ flags = atomic_inc_return(&con->c.wr_cnt) % sess->s.signal_interval ? + 0 : IB_SEND_SIGNALED; + + ib_dma_sync_single_for_device(sess->s.dev->ib_dev, req->iu->dma_addr, +@@ -680,6 +680,7 @@ static void rtrs_clt_rdma_done(struct ib_cq *cq, struct ib_wc *wc) + case IB_WC_RDMA_WRITE: + /* + * post_send() RDMA write completions of IO reqs (read/write) ++ * and hb. + */ + break; + +@@ -1043,7 +1044,7 @@ static int rtrs_post_rdma_write_sg(struct rtrs_clt_con *con, + * From time to time we have to post signalled sends, + * or send queue will fill up and only QP reset can help. + */ +- flags = atomic_inc_return(&con->io_cnt) % sess->queue_depth ? ++ flags = atomic_inc_return(&con->c.wr_cnt) % sess->s.signal_interval ? + 0 : IB_SEND_SIGNALED; + + ib_dma_sync_single_for_device(sess->s.dev->ib_dev, req->iu->dma_addr, +@@ -1601,7 +1602,8 @@ static int create_con(struct rtrs_clt_sess *sess, unsigned int cid) + con->cpu = (cid ? cid - 1 : 0) % nr_cpu_ids; + con->c.cid = cid; + con->c.sess = &sess->s; +- atomic_set(&con->io_cnt, 0); ++ /* Align with srv, init as 1 */ ++ atomic_set(&con->c.wr_cnt, 1); + mutex_init(&con->con_mutex); + + sess->s.con[cid] = &con->c; +@@ -1678,6 +1680,7 @@ static int create_con_cq_qp(struct rtrs_clt_con *con) + sess->queue_depth * 3 + 1); + max_send_sge = 2; + } ++ atomic_set(&con->c.sq_wr_avail, max_send_wr); + cq_num = max_send_wr + max_recv_wr; + /* alloc iu to recv new rkey reply when server reports flags set */ + if (sess->flags & RTRS_MSG_NEW_RKEY_F || con->c.cid == 0) { +@@ -1848,6 +1851,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con, + return -ENOMEM; + } + sess->queue_depth = queue_depth; ++ sess->s.signal_interval = min_not_zero(queue_depth, ++ (unsigned short) SERVICE_CON_QUEUE_DEPTH); + sess->max_hdr_size = le32_to_cpu(msg->max_hdr_size); + sess->max_io_size = le32_to_cpu(msg->max_io_size); + sess->flags = le32_to_cpu(msg->flags); +diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.h b/drivers/infiniband/ulp/rtrs/rtrs-clt.h +index e276a2dfcf7c7..3c3ff094588cb 100644 +--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.h ++++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.h +@@ -74,7 +74,6 @@ struct rtrs_clt_con { + u32 queue_num; + unsigned int cpu; + struct mutex con_mutex; +- atomic_t io_cnt; + int cm_err; + }; + +diff --git a/drivers/infiniband/ulp/rtrs/rtrs-pri.h b/drivers/infiniband/ulp/rtrs/rtrs-pri.h +index 36f184a3b6761..119aa3f7eafe2 100644 +--- a/drivers/infiniband/ulp/rtrs/rtrs-pri.h ++++ b/drivers/infiniband/ulp/rtrs/rtrs-pri.h +@@ -96,6 +96,8 @@ struct rtrs_con { + struct rdma_cm_id *cm_id; + unsigned int cid; + int nr_cqe; ++ atomic_t wr_cnt; ++ atomic_t sq_wr_avail; + }; + + struct rtrs_sess { +@@ -108,6 +110,7 @@ struct rtrs_sess { + unsigned int con_num; + unsigned int irq_con_num; + unsigned int recon_cnt; ++ unsigned int signal_interval; + struct rtrs_ib_dev *dev; + int dev_ref; + struct ib_cqe *hb_cqe; +diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c +index 3df2900861697..cd9a4ccf4c289 100644 +--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c ++++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c +@@ -201,7 +201,6 @@ static int rdma_write_sg(struct rtrs_srv_op *id) + struct rtrs_srv_sess *sess = to_srv_sess(s); + dma_addr_t dma_addr = sess->dma_addr[id->msg_id]; + struct rtrs_srv_mr *srv_mr; +- struct rtrs_srv *srv = sess->srv; + struct ib_send_wr inv_wr; + struct ib_rdma_wr imm_wr; + struct ib_rdma_wr *wr = NULL; +@@ -269,7 +268,7 @@ static int rdma_write_sg(struct rtrs_srv_op *id) + * From time to time we have to post signaled sends, + * or send queue will fill up and only QP reset can help. + */ +- flags = (atomic_inc_return(&id->con->wr_cnt) % srv->queue_depth) ? ++ flags = (atomic_inc_return(&id->con->c.wr_cnt) % s->signal_interval) ? + 0 : IB_SEND_SIGNALED; + + if (need_inval) { +@@ -347,7 +346,6 @@ static int send_io_resp_imm(struct rtrs_srv_con *con, struct rtrs_srv_op *id, + struct ib_send_wr inv_wr, *wr = NULL; + struct ib_rdma_wr imm_wr; + struct ib_reg_wr rwr; +- struct rtrs_srv *srv = sess->srv; + struct rtrs_srv_mr *srv_mr; + bool need_inval = false; + enum ib_send_flags flags; +@@ -396,7 +394,7 @@ static int send_io_resp_imm(struct rtrs_srv_con *con, struct rtrs_srv_op *id, + * From time to time we have to post signalled sends, + * or send queue will fill up and only QP reset can help. + */ +- flags = (atomic_inc_return(&con->wr_cnt) % srv->queue_depth) ? ++ flags = (atomic_inc_return(&con->c.wr_cnt) % s->signal_interval) ? + 0 : IB_SEND_SIGNALED; + imm = rtrs_to_io_rsp_imm(id->msg_id, errno, need_inval); + imm_wr.wr.next = NULL; +@@ -509,11 +507,11 @@ bool rtrs_srv_resp_rdma(struct rtrs_srv_op *id, int status) + ib_update_fast_reg_key(mr->mr, ib_inc_rkey(mr->mr->rkey)); + } + if (unlikely(atomic_sub_return(1, +- &con->sq_wr_avail) < 0)) { ++ &con->c.sq_wr_avail) < 0)) { + rtrs_err(s, "IB send queue full: sess=%s cid=%d\n", + kobject_name(&sess->kobj), + con->c.cid); +- atomic_add(1, &con->sq_wr_avail); ++ atomic_add(1, &con->c.sq_wr_avail); + spin_lock(&con->rsp_wr_wait_lock); + list_add_tail(&id->wait_list, &con->rsp_wr_wait_list); + spin_unlock(&con->rsp_wr_wait_lock); +@@ -1268,8 +1266,9 @@ static void rtrs_srv_rdma_done(struct ib_cq *cq, struct ib_wc *wc) + case IB_WC_SEND: + /* + * post_send() RDMA write completions of IO reqs (read/write) ++ * and hb. + */ +- atomic_add(srv->queue_depth, &con->sq_wr_avail); ++ atomic_add(s->signal_interval, &con->c.sq_wr_avail); + + if (unlikely(!list_empty_careful(&con->rsp_wr_wait_list))) + rtrs_rdma_process_wr_wait_list(con); +@@ -1648,7 +1647,7 @@ static int create_con(struct rtrs_srv_sess *sess, + con->c.cm_id = cm_id; + con->c.sess = &sess->s; + con->c.cid = cid; +- atomic_set(&con->wr_cnt, 1); ++ atomic_set(&con->c.wr_cnt, 1); + wr_limit = sess->s.dev->ib_dev->attrs.max_qp_wr; + + if (con->c.cid == 0) { +@@ -1659,6 +1658,8 @@ static int create_con(struct rtrs_srv_sess *sess, + max_send_wr = min_t(int, wr_limit, + SERVICE_CON_QUEUE_DEPTH * 2 + 2); + max_recv_wr = max_send_wr; ++ s->signal_interval = min_not_zero(srv->queue_depth, ++ (size_t)SERVICE_CON_QUEUE_DEPTH); + } else { + /* when always_invlaidate enalbed, we need linv+rinv+mr+imm */ + if (always_invalidate) +@@ -1679,7 +1680,7 @@ static int create_con(struct rtrs_srv_sess *sess, + */ + } + cq_num = max_send_wr + max_recv_wr; +- atomic_set(&con->sq_wr_avail, max_send_wr); ++ atomic_set(&con->c.sq_wr_avail, max_send_wr); + cq_vector = rtrs_srv_get_next_cq_vector(sess); + + /* TODO: SOFTIRQ can be faster, but be careful with softirq context */ +diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.h b/drivers/infiniband/ulp/rtrs/rtrs-srv.h +index f8da2e3f0bdac..e81774f5acd33 100644 +--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.h ++++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.h +@@ -42,8 +42,6 @@ struct rtrs_srv_stats { + + struct rtrs_srv_con { + struct rtrs_con c; +- atomic_t wr_cnt; +- atomic_t sq_wr_avail; + struct list_head rsp_wr_wait_list; + spinlock_t rsp_wr_wait_lock; + }; +diff --git a/drivers/infiniband/ulp/rtrs/rtrs.c b/drivers/infiniband/ulp/rtrs/rtrs.c +index 61919ebd92b2d..0a4b4e1b5e5ff 100644 +--- a/drivers/infiniband/ulp/rtrs/rtrs.c ++++ b/drivers/infiniband/ulp/rtrs/rtrs.c +@@ -187,10 +187,16 @@ int rtrs_post_rdma_write_imm_empty(struct rtrs_con *con, struct ib_cqe *cqe, + struct ib_send_wr *head) + { + struct ib_rdma_wr wr; ++ struct rtrs_sess *sess = con->sess; ++ enum ib_send_flags sflags; ++ ++ atomic_dec_if_positive(&con->sq_wr_avail); ++ sflags = (atomic_inc_return(&con->wr_cnt) % sess->signal_interval) ? ++ 0 : IB_SEND_SIGNALED; + + wr = (struct ib_rdma_wr) { + .wr.wr_cqe = cqe, +- .wr.send_flags = flags, ++ .wr.send_flags = sflags, + .wr.opcode = IB_WR_RDMA_WRITE_WITH_IMM, + .wr.ex.imm_data = cpu_to_be32(imm_data), + }; +diff --git a/drivers/input/mouse/elan_i2c.h b/drivers/input/mouse/elan_i2c.h +index dc4a240f44895..3c84deefa327d 100644 +--- a/drivers/input/mouse/elan_i2c.h ++++ b/drivers/input/mouse/elan_i2c.h +@@ -55,8 +55,9 @@ + #define ETP_FW_PAGE_SIZE_512 512 + #define ETP_FW_SIGNATURE_SIZE 6 + +-#define ETP_PRODUCT_ID_DELBIN 0x00C2 ++#define ETP_PRODUCT_ID_WHITEBOX 0x00B8 + #define ETP_PRODUCT_ID_VOXEL 0x00BF ++#define ETP_PRODUCT_ID_DELBIN 0x00C2 + #define ETP_PRODUCT_ID_MAGPIE 0x0120 + #define ETP_PRODUCT_ID_BOBBA 0x0121 + +diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c +index dad22c1ea6a0f..47af62c122672 100644 +--- a/drivers/input/mouse/elan_i2c_core.c ++++ b/drivers/input/mouse/elan_i2c_core.c +@@ -105,6 +105,7 @@ static u32 elan_i2c_lookup_quirks(u16 ic_type, u16 product_id) + u32 quirks; + } elan_i2c_quirks[] = { + { 0x0D, ETP_PRODUCT_ID_DELBIN, ETP_QUIRK_QUICK_WAKEUP }, ++ { 0x0D, ETP_PRODUCT_ID_WHITEBOX, ETP_QUIRK_QUICK_WAKEUP }, + { 0x10, ETP_PRODUCT_ID_VOXEL, ETP_QUIRK_QUICK_WAKEUP }, + { 0x14, ETP_PRODUCT_ID_MAGPIE, ETP_QUIRK_QUICK_WAKEUP }, + { 0x14, ETP_PRODUCT_ID_BOBBA, ETP_QUIRK_QUICK_WAKEUP }, +diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h +index c11bc8b833b8e..d5552e2c160d2 100644 +--- a/drivers/iommu/intel/pasid.h ++++ b/drivers/iommu/intel/pasid.h +@@ -28,12 +28,12 @@ + #define VCMD_CMD_ALLOC 0x1 + #define VCMD_CMD_FREE 0x2 + #define VCMD_VRSP_IP 0x1 +-#define VCMD_VRSP_SC(e) (((e) >> 1) & 0x3) ++#define VCMD_VRSP_SC(e) (((e) & 0xff) >> 1) + #define VCMD_VRSP_SC_SUCCESS 0 +-#define VCMD_VRSP_SC_NO_PASID_AVAIL 2 +-#define VCMD_VRSP_SC_INVALID_PASID 2 +-#define VCMD_VRSP_RESULT_PASID(e) (((e) >> 8) & 0xfffff) +-#define VCMD_CMD_OPERAND(e) ((e) << 8) ++#define VCMD_VRSP_SC_NO_PASID_AVAIL 16 ++#define VCMD_VRSP_SC_INVALID_PASID 16 ++#define VCMD_VRSP_RESULT_PASID(e) (((e) >> 16) & 0xfffff) ++#define VCMD_CMD_OPERAND(e) ((e) << 16) + /* + * Domain ID reserved for pasid entries programmed for first-level + * only and pass-through transfer modes. +diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c +index 67a42b514429e..4f907e8f3894b 100644 +--- a/drivers/mailbox/mtk-cmdq-mailbox.c ++++ b/drivers/mailbox/mtk-cmdq-mailbox.c +@@ -168,7 +168,8 @@ static void cmdq_task_insert_into_thread(struct cmdq_task *task) + dma_sync_single_for_cpu(dev, prev_task->pa_base, + prev_task->pkt->cmd_buf_size, DMA_TO_DEVICE); + prev_task_base[CMDQ_NUM_CMD(prev_task->pkt) - 1] = +- (u64)CMDQ_JUMP_BY_PA << 32 | task->pa_base; ++ (u64)CMDQ_JUMP_BY_PA << 32 | ++ (task->pa_base >> task->cmdq->shift_pa); + dma_sync_single_for_device(dev, prev_task->pa_base, + prev_task->pkt->cmd_buf_size, DMA_TO_DEVICE); + +diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c +index 50f4cbd600d58..8c0c3d1f54bba 100644 +--- a/drivers/md/dm-crypt.c ++++ b/drivers/md/dm-crypt.c +@@ -2661,7 +2661,12 @@ static void *crypt_page_alloc(gfp_t gfp_mask, void *pool_data) + struct crypt_config *cc = pool_data; + struct page *page; + +- if (unlikely(percpu_counter_compare(&cc->n_allocated_pages, dm_crypt_pages_per_client) >= 0) && ++ /* ++ * Note, percpu_counter_read_positive() may over (and under) estimate ++ * the current usage by at most (batch - 1) * num_online_cpus() pages, ++ * but avoids potential spinlock contention of an exact result. ++ */ ++ if (unlikely(percpu_counter_read_positive(&cc->n_allocated_pages) >= dm_crypt_pages_per_client) && + likely(gfp_mask & __GFP_NORETRY)) + return NULL; + +diff --git a/drivers/media/cec/platform/stm32/stm32-cec.c b/drivers/media/cec/platform/stm32/stm32-cec.c +index ea4b1ebfca991..0ffd89712536b 100644 +--- a/drivers/media/cec/platform/stm32/stm32-cec.c ++++ b/drivers/media/cec/platform/stm32/stm32-cec.c +@@ -305,14 +305,16 @@ static int stm32_cec_probe(struct platform_device *pdev) + + cec->clk_hdmi_cec = devm_clk_get(&pdev->dev, "hdmi-cec"); + if (IS_ERR(cec->clk_hdmi_cec) && +- PTR_ERR(cec->clk_hdmi_cec) == -EPROBE_DEFER) +- return -EPROBE_DEFER; ++ PTR_ERR(cec->clk_hdmi_cec) == -EPROBE_DEFER) { ++ ret = -EPROBE_DEFER; ++ goto err_unprepare_cec_clk; ++ } + + if (!IS_ERR(cec->clk_hdmi_cec)) { + ret = clk_prepare(cec->clk_hdmi_cec); + if (ret) { + dev_err(&pdev->dev, "Can't prepare hdmi-cec clock\n"); +- return ret; ++ goto err_unprepare_cec_clk; + } + } + +@@ -324,19 +326,27 @@ static int stm32_cec_probe(struct platform_device *pdev) + CEC_NAME, caps, CEC_MAX_LOG_ADDRS); + ret = PTR_ERR_OR_ZERO(cec->adap); + if (ret) +- return ret; ++ goto err_unprepare_hdmi_cec_clk; + + ret = cec_register_adapter(cec->adap, &pdev->dev); +- if (ret) { +- cec_delete_adapter(cec->adap); +- return ret; +- } ++ if (ret) ++ goto err_delete_adapter; + + cec_hw_init(cec); + + platform_set_drvdata(pdev, cec); + + return 0; ++ ++err_delete_adapter: ++ cec_delete_adapter(cec->adap); ++ ++err_unprepare_hdmi_cec_clk: ++ clk_unprepare(cec->clk_hdmi_cec); ++ ++err_unprepare_cec_clk: ++ clk_unprepare(cec->clk_cec); ++ return ret; + } + + static int stm32_cec_remove(struct platform_device *pdev) +diff --git a/drivers/media/cec/platform/tegra/tegra_cec.c b/drivers/media/cec/platform/tegra/tegra_cec.c +index 1ac0c70a59818..5e907395ca2e5 100644 +--- a/drivers/media/cec/platform/tegra/tegra_cec.c ++++ b/drivers/media/cec/platform/tegra/tegra_cec.c +@@ -366,7 +366,11 @@ static int tegra_cec_probe(struct platform_device *pdev) + return -ENOENT; + } + +- clk_prepare_enable(cec->clk); ++ ret = clk_prepare_enable(cec->clk); ++ if (ret) { ++ dev_err(&pdev->dev, "Unable to prepare clock for CEC\n"); ++ return ret; ++ } + + /* set context info. */ + cec->dev = &pdev->dev; +@@ -446,9 +450,7 @@ static int tegra_cec_resume(struct platform_device *pdev) + + dev_notice(&pdev->dev, "Resuming\n"); + +- clk_prepare_enable(cec->clk); +- +- return 0; ++ return clk_prepare_enable(cec->clk); + } + #endif + +diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-frontends/dib8000.c +index 082796534b0ae..bb02354a48b81 100644 +--- a/drivers/media/dvb-frontends/dib8000.c ++++ b/drivers/media/dvb-frontends/dib8000.c +@@ -2107,32 +2107,55 @@ static void dib8000_load_ana_fe_coefs(struct dib8000_state *state, const s16 *an + dib8000_write_word(state, 117 + mode, ana_fe[mode]); + } + +-static const u16 lut_prbs_2k[14] = { +- 0, 0x423, 0x009, 0x5C7, 0x7A6, 0x3D8, 0x527, 0x7FF, 0x79B, 0x3D6, 0x3A2, 0x53B, 0x2F4, 0x213 ++static const u16 lut_prbs_2k[13] = { ++ 0x423, 0x009, 0x5C7, ++ 0x7A6, 0x3D8, 0x527, ++ 0x7FF, 0x79B, 0x3D6, ++ 0x3A2, 0x53B, 0x2F4, ++ 0x213 + }; +-static const u16 lut_prbs_4k[14] = { +- 0, 0x208, 0x0C3, 0x7B9, 0x423, 0x5C7, 0x3D8, 0x7FF, 0x3D6, 0x53B, 0x213, 0x029, 0x0D0, 0x48E ++ ++static const u16 lut_prbs_4k[13] = { ++ 0x208, 0x0C3, 0x7B9, ++ 0x423, 0x5C7, 0x3D8, ++ 0x7FF, 0x3D6, 0x53B, ++ 0x213, 0x029, 0x0D0, ++ 0x48E + }; +-static const u16 lut_prbs_8k[14] = { +- 0, 0x740, 0x069, 0x7DD, 0x208, 0x7B9, 0x5C7, 0x7FF, 0x53B, 0x029, 0x48E, 0x4C4, 0x367, 0x684 ++ ++static const u16 lut_prbs_8k[13] = { ++ 0x740, 0x069, 0x7DD, ++ 0x208, 0x7B9, 0x5C7, ++ 0x7FF, 0x53B, 0x029, ++ 0x48E, 0x4C4, 0x367, ++ 0x684 + }; + + static u16 dib8000_get_init_prbs(struct dib8000_state *state, u16 subchannel) + { + int sub_channel_prbs_group = 0; ++ int prbs_group; + +- sub_channel_prbs_group = (subchannel / 3) + 1; +- dprintk("sub_channel_prbs_group = %d , subchannel =%d prbs = 0x%04x\n", sub_channel_prbs_group, subchannel, lut_prbs_8k[sub_channel_prbs_group]); ++ sub_channel_prbs_group = subchannel / 3; ++ if (sub_channel_prbs_group >= ARRAY_SIZE(lut_prbs_2k)) ++ return 0; + + switch (state->fe[0]->dtv_property_cache.transmission_mode) { + case TRANSMISSION_MODE_2K: +- return lut_prbs_2k[sub_channel_prbs_group]; ++ prbs_group = lut_prbs_2k[sub_channel_prbs_group]; ++ break; + case TRANSMISSION_MODE_4K: +- return lut_prbs_4k[sub_channel_prbs_group]; ++ prbs_group = lut_prbs_4k[sub_channel_prbs_group]; ++ break; + default: + case TRANSMISSION_MODE_8K: +- return lut_prbs_8k[sub_channel_prbs_group]; ++ prbs_group = lut_prbs_8k[sub_channel_prbs_group]; + } ++ ++ dprintk("sub_channel_prbs_group = %d , subchannel =%d prbs = 0x%04x\n", ++ sub_channel_prbs_group, subchannel, prbs_group); ++ ++ return prbs_group; + } + + static void dib8000_set_13seg_channel(struct dib8000_state *state) +@@ -2409,10 +2432,8 @@ static void dib8000_set_isdbt_common_channel(struct dib8000_state *state, u8 seq + /* TSB or ISDBT ? apply it now */ + if (c->isdbt_sb_mode) { + dib8000_set_sb_channel(state); +- if (c->isdbt_sb_subchannel < 14) +- init_prbs = dib8000_get_init_prbs(state, c->isdbt_sb_subchannel); +- else +- init_prbs = 0; ++ init_prbs = dib8000_get_init_prbs(state, ++ c->isdbt_sb_subchannel); + } else { + dib8000_set_13seg_channel(state); + init_prbs = 0xfff; +@@ -3004,6 +3025,7 @@ static int dib8000_tune(struct dvb_frontend *fe) + + unsigned long *timeout = &state->timeout; + unsigned long now = jiffies; ++ u16 init_prbs; + #ifdef DIB8000_AGC_FREEZE + u16 agc1, agc2; + #endif +@@ -3302,8 +3324,10 @@ static int dib8000_tune(struct dvb_frontend *fe) + break; + + case CT_DEMOD_STEP_11: /* 41 : init prbs autosearch */ +- if (state->subchannel <= 41) { +- dib8000_set_subchannel_prbs(state, dib8000_get_init_prbs(state, state->subchannel)); ++ init_prbs = dib8000_get_init_prbs(state, state->subchannel); ++ ++ if (init_prbs) { ++ dib8000_set_subchannel_prbs(state, init_prbs); + *tune_state = CT_DEMOD_STEP_9; + } else { + *tune_state = CT_DEMOD_STOP; +diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c +index 7ab9e5f9f2676..81cdf37216ca7 100644 +--- a/drivers/media/i2c/imx258.c ++++ b/drivers/media/i2c/imx258.c +@@ -23,7 +23,7 @@ + #define IMX258_CHIP_ID 0x0258 + + /* V_TIMING internal */ +-#define IMX258_VTS_30FPS 0x0c98 ++#define IMX258_VTS_30FPS 0x0c50 + #define IMX258_VTS_30FPS_2K 0x0638 + #define IMX258_VTS_30FPS_VGA 0x034c + #define IMX258_VTS_MAX 0xffff +@@ -47,7 +47,7 @@ + /* Analog gain control */ + #define IMX258_REG_ANALOG_GAIN 0x0204 + #define IMX258_ANA_GAIN_MIN 0 +-#define IMX258_ANA_GAIN_MAX 0x1fff ++#define IMX258_ANA_GAIN_MAX 480 + #define IMX258_ANA_GAIN_STEP 1 + #define IMX258_ANA_GAIN_DEFAULT 0x0 + +diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c +index 3a191e257fad0..ef726faee2a4c 100644 +--- a/drivers/media/i2c/tda1997x.c ++++ b/drivers/media/i2c/tda1997x.c +@@ -1695,14 +1695,15 @@ static int tda1997x_query_dv_timings(struct v4l2_subdev *sd, + struct v4l2_dv_timings *timings) + { + struct tda1997x_state *state = to_state(sd); ++ int ret; + + v4l_dbg(1, debug, state->client, "%s\n", __func__); + memset(timings, 0, sizeof(struct v4l2_dv_timings)); + mutex_lock(&state->lock); +- tda1997x_detect_std(state, timings); ++ ret = tda1997x_detect_std(state, timings); + mutex_unlock(&state->lock); + +- return 0; ++ return ret; + } + + static const struct v4l2_subdev_video_ops tda1997x_video_ops = { +diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c +index 124a4e2bdefe0..e2e384a887ac2 100644 +--- a/drivers/media/platform/ti-vpe/cal-camerarx.c ++++ b/drivers/media/platform/ti-vpe/cal-camerarx.c +@@ -845,7 +845,9 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal, + if (ret) + goto error; + +- cal_camerarx_sd_init_cfg(sd, NULL); ++ ret = cal_camerarx_sd_init_cfg(sd, NULL); ++ if (ret) ++ goto error; + + ret = v4l2_device_register_subdev(&cal->v4l2_dev, sd); + if (ret) +diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c +index 15fb5360cf13c..552619cb81a81 100644 +--- a/drivers/media/platform/ti-vpe/cal-video.c ++++ b/drivers/media/platform/ti-vpe/cal-video.c +@@ -694,7 +694,7 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count) + + spin_lock_irq(&ctx->dma.lock); + buf = list_first_entry(&ctx->dma.queue, struct cal_buffer, list); +- ctx->dma.pending = buf; ++ ctx->dma.active = buf; + list_del(&buf->list); + spin_unlock_irq(&ctx->dma.lock); + +diff --git a/drivers/media/rc/rc-loopback.c b/drivers/media/rc/rc-loopback.c +index 1ba3f96ffa7dc..40ab66c850f23 100644 +--- a/drivers/media/rc/rc-loopback.c ++++ b/drivers/media/rc/rc-loopback.c +@@ -42,7 +42,7 @@ static int loop_set_tx_mask(struct rc_dev *dev, u32 mask) + + if ((mask & (RXMASK_REGULAR | RXMASK_LEARNING)) != mask) { + dprintk("invalid tx mask: %u\n", mask); +- return -EINVAL; ++ return 2; + } + + dprintk("setting tx mask: %u\n", mask); +diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c +index 252136cc885ce..6acb8013de08b 100644 +--- a/drivers/media/usb/uvc/uvc_v4l2.c ++++ b/drivers/media/usb/uvc/uvc_v4l2.c +@@ -899,8 +899,8 @@ static int uvc_ioctl_g_input(struct file *file, void *fh, unsigned int *input) + { + struct uvc_fh *handle = fh; + struct uvc_video_chain *chain = handle->chain; ++ u8 *buf; + int ret; +- u8 i; + + if (chain->selector == NULL || + (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { +@@ -908,22 +908,27 @@ static int uvc_ioctl_g_input(struct file *file, void *fh, unsigned int *input) + return 0; + } + ++ buf = kmalloc(1, GFP_KERNEL); ++ if (!buf) ++ return -ENOMEM; ++ + ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, chain->selector->id, + chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, +- &i, 1); +- if (ret < 0) +- return ret; ++ buf, 1); ++ if (!ret) ++ *input = *buf - 1; + +- *input = i - 1; +- return 0; ++ kfree(buf); ++ ++ return ret; + } + + static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input) + { + struct uvc_fh *handle = fh; + struct uvc_video_chain *chain = handle->chain; ++ u8 *buf; + int ret; +- u32 i; + + ret = uvc_acquire_privileges(handle); + if (ret < 0) +@@ -939,10 +944,17 @@ static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input) + if (input >= chain->selector->bNrInPins) + return -EINVAL; + +- i = input + 1; +- return uvc_query_ctrl(chain->dev, UVC_SET_CUR, chain->selector->id, +- chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, +- &i, 1); ++ buf = kmalloc(1, GFP_KERNEL); ++ if (!buf) ++ return -ENOMEM; ++ ++ *buf = input + 1; ++ ret = uvc_query_ctrl(chain->dev, UVC_SET_CUR, chain->selector->id, ++ chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, ++ buf, 1); ++ kfree(buf); ++ ++ return ret; + } + + static int uvc_ioctl_queryctrl(struct file *file, void *fh, +diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c b/drivers/media/v4l2-core/v4l2-dv-timings.c +index 230d65a642178..af48705c704f8 100644 +--- a/drivers/media/v4l2-core/v4l2-dv-timings.c ++++ b/drivers/media/v4l2-core/v4l2-dv-timings.c +@@ -196,7 +196,7 @@ bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t, + if (!v4l2_valid_dv_timings(t, cap, fnc, fnc_handle)) + return false; + +- for (i = 0; i < v4l2_dv_timings_presets[i].bt.width; i++) { ++ for (i = 0; v4l2_dv_timings_presets[i].bt.width; i++) { + if (v4l2_valid_dv_timings(v4l2_dv_timings_presets + i, cap, + fnc, fnc_handle) && + v4l2_match_dv_timings(t, v4l2_dv_timings_presets + i, +@@ -218,7 +218,7 @@ bool v4l2_find_dv_timings_cea861_vic(struct v4l2_dv_timings *t, u8 vic) + { + unsigned int i; + +- for (i = 0; i < v4l2_dv_timings_presets[i].bt.width; i++) { ++ for (i = 0; v4l2_dv_timings_presets[i].bt.width; i++) { + const struct v4l2_bt_timings *bt = + &v4l2_dv_timings_presets[i].bt; + +diff --git a/drivers/misc/pvpanic/pvpanic-pci.c b/drivers/misc/pvpanic/pvpanic-pci.c +index a43c401017ae2..741116b3d9958 100644 +--- a/drivers/misc/pvpanic/pvpanic-pci.c ++++ b/drivers/misc/pvpanic/pvpanic-pci.c +@@ -108,4 +108,6 @@ static struct pci_driver pvpanic_pci_driver = { + }, + }; + ++MODULE_DEVICE_TABLE(pci, pvpanic_pci_id_tbl); ++ + module_pci_driver(pvpanic_pci_driver); +diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c +index 93638ae2753af..4c26b19f5154a 100644 +--- a/drivers/misc/sram.c ++++ b/drivers/misc/sram.c +@@ -97,7 +97,24 @@ static int sram_add_partition(struct sram_dev *sram, struct sram_reserve *block, + struct sram_partition *part = &sram->partition[sram->partitions]; + + mutex_init(&part->lock); +- part->base = sram->virt_base + block->start; ++ ++ if (sram->config && sram->config->map_only_reserved) { ++ void __iomem *virt_base; ++ ++ if (sram->no_memory_wc) ++ virt_base = devm_ioremap_resource(sram->dev, &block->res); ++ else ++ virt_base = devm_ioremap_resource_wc(sram->dev, &block->res); ++ ++ if (IS_ERR(virt_base)) { ++ dev_err(sram->dev, "could not map SRAM at %pr\n", &block->res); ++ return PTR_ERR(virt_base); ++ } ++ ++ part->base = virt_base; ++ } else { ++ part->base = sram->virt_base + block->start; ++ } + + if (block->pool) { + ret = sram_add_pool(sram, block, start, part); +@@ -198,6 +215,7 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) + + block->start = child_res.start - res->start; + block->size = resource_size(&child_res); ++ block->res = child_res; + list_add_tail(&block->list, &reserve_list); + + if (of_find_property(child, "export", NULL)) +@@ -295,15 +313,17 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) + */ + cur_size = block->start - cur_start; + +- dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n", +- cur_start, cur_start + cur_size); ++ if (sram->pool) { ++ dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n", ++ cur_start, cur_start + cur_size); + +- ret = gen_pool_add_virt(sram->pool, +- (unsigned long)sram->virt_base + cur_start, +- res->start + cur_start, cur_size, -1); +- if (ret < 0) { +- sram_free_partitions(sram); +- goto err_chunks; ++ ret = gen_pool_add_virt(sram->pool, ++ (unsigned long)sram->virt_base + cur_start, ++ res->start + cur_start, cur_size, -1); ++ if (ret < 0) { ++ sram_free_partitions(sram); ++ goto err_chunks; ++ } + } + + /* next allocation after this reserved block */ +@@ -331,40 +351,63 @@ static int atmel_securam_wait(void) + 10000, 500000); + } + ++static const struct sram_config atmel_securam_config = { ++ .init = atmel_securam_wait, ++}; ++ ++/* ++ * SYSRAM contains areas that are not accessible by the ++ * kernel, such as the first 256K that is reserved for TZ. ++ * Accesses to those areas (including speculative accesses) ++ * trigger SErrors. As such we must map only the areas of ++ * SYSRAM specified in the device tree. ++ */ ++static const struct sram_config tegra_sysram_config = { ++ .map_only_reserved = true, ++}; ++ + static const struct of_device_id sram_dt_ids[] = { + { .compatible = "mmio-sram" }, +- { .compatible = "atmel,sama5d2-securam", .data = atmel_securam_wait }, ++ { .compatible = "atmel,sama5d2-securam", .data = &atmel_securam_config }, ++ { .compatible = "nvidia,tegra186-sysram", .data = &tegra_sysram_config }, ++ { .compatible = "nvidia,tegra194-sysram", .data = &tegra_sysram_config }, + {} + }; + + static int sram_probe(struct platform_device *pdev) + { ++ const struct sram_config *config; + struct sram_dev *sram; + int ret; + struct resource *res; +- int (*init_func)(void); ++ ++ config = of_device_get_match_data(&pdev->dev); + + sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); + if (!sram) + return -ENOMEM; + + sram->dev = &pdev->dev; ++ sram->no_memory_wc = of_property_read_bool(pdev->dev.of_node, "no-memory-wc"); ++ sram->config = config; ++ ++ if (!config || !config->map_only_reserved) { ++ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ++ if (sram->no_memory_wc) ++ sram->virt_base = devm_ioremap_resource(&pdev->dev, res); ++ else ++ sram->virt_base = devm_ioremap_resource_wc(&pdev->dev, res); ++ if (IS_ERR(sram->virt_base)) { ++ dev_err(&pdev->dev, "could not map SRAM registers\n"); ++ return PTR_ERR(sram->virt_base); ++ } + +- res = platform_get_resource(pdev, IORESOURCE_MEM, 0); +- if (of_property_read_bool(pdev->dev.of_node, "no-memory-wc")) +- sram->virt_base = devm_ioremap_resource(&pdev->dev, res); +- else +- sram->virt_base = devm_ioremap_resource_wc(&pdev->dev, res); +- if (IS_ERR(sram->virt_base)) { +- dev_err(&pdev->dev, "could not map SRAM registers\n"); +- return PTR_ERR(sram->virt_base); ++ sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), ++ NUMA_NO_NODE, NULL); ++ if (IS_ERR(sram->pool)) ++ return PTR_ERR(sram->pool); + } + +- sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), +- NUMA_NO_NODE, NULL); +- if (IS_ERR(sram->pool)) +- return PTR_ERR(sram->pool); +- + sram->clk = devm_clk_get(sram->dev, NULL); + if (IS_ERR(sram->clk)) + sram->clk = NULL; +@@ -378,15 +421,15 @@ static int sram_probe(struct platform_device *pdev) + + platform_set_drvdata(pdev, sram); + +- init_func = of_device_get_match_data(&pdev->dev); +- if (init_func) { +- ret = init_func(); ++ if (config && config->init) { ++ ret = config->init(); + if (ret) + goto err_free_partitions; + } + +- dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n", +- gen_pool_size(sram->pool) / 1024, sram->virt_base); ++ if (sram->pool) ++ dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n", ++ gen_pool_size(sram->pool) / 1024, sram->virt_base); + + return 0; + +@@ -405,7 +448,7 @@ static int sram_remove(struct platform_device *pdev) + + sram_free_partitions(sram); + +- if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) ++ if (sram->pool && gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) + dev_err(sram->dev, "removed while SRAM allocated\n"); + + if (sram->clk) +diff --git a/drivers/misc/sram.h b/drivers/misc/sram.h +index 9c1d21ff73476..d2058d8c8f1d2 100644 +--- a/drivers/misc/sram.h ++++ b/drivers/misc/sram.h +@@ -5,6 +5,11 @@ + #ifndef __SRAM_H + #define __SRAM_H + ++struct sram_config { ++ int (*init)(void); ++ bool map_only_reserved; ++}; ++ + struct sram_partition { + void __iomem *base; + +@@ -15,8 +20,11 @@ struct sram_partition { + }; + + struct sram_dev { ++ const struct sram_config *config; ++ + struct device *dev; + void __iomem *virt_base; ++ bool no_memory_wc; + + struct gen_pool *pool; + struct clk *clk; +@@ -29,6 +37,7 @@ struct sram_reserve { + struct list_head list; + u32 start; + u32 size; ++ struct resource res; + bool export; + bool pool; + bool protect_exec; +diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c +index 880c33ab9f47b..94ebf7f3fd58a 100644 +--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c ++++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c +@@ -2243,7 +2243,8 @@ int vmci_qp_broker_map(struct vmci_handle handle, + + result = VMCI_SUCCESS; + +- if (context_id != VMCI_HOST_CONTEXT_ID) { ++ if (context_id != VMCI_HOST_CONTEXT_ID && ++ !QPBROKERSTATE_HAS_MEM(entry)) { + struct vmci_qp_page_store page_store; + + page_store.pages = guest_mem; +@@ -2350,7 +2351,8 @@ int vmci_qp_broker_unmap(struct vmci_handle handle, + goto out; + } + +- if (context_id != VMCI_HOST_CONTEXT_ID) { ++ if (context_id != VMCI_HOST_CONTEXT_ID && ++ QPBROKERSTATE_HAS_MEM(entry)) { + qp_acquire_queue_mutex(entry->produce_q); + result = qp_save_headers(entry); + if (result < VMCI_SUCCESS) +diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c +index ce8aed5629295..c3ecec3f6ddc6 100644 +--- a/drivers/mmc/core/block.c ++++ b/drivers/mmc/core/block.c +@@ -98,6 +98,11 @@ static int max_devices; + static DEFINE_IDA(mmc_blk_ida); + static DEFINE_IDA(mmc_rpmb_ida); + ++struct mmc_blk_busy_data { ++ struct mmc_card *card; ++ u32 status; ++}; ++ + /* + * There is one mmc_blk_data per slot. + */ +@@ -417,42 +422,6 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr, + return 0; + } + +-static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, +- u32 *resp_errs) +-{ +- unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); +- int err = 0; +- u32 status; +- +- do { +- bool done = time_after(jiffies, timeout); +- +- err = __mmc_send_status(card, &status, 5); +- if (err) { +- dev_err(mmc_dev(card->host), +- "error %d requesting status\n", err); +- return err; +- } +- +- /* Accumulate any response error bits seen */ +- if (resp_errs) +- *resp_errs |= status; +- +- /* +- * Timeout if the device never becomes ready for data and never +- * leaves the program state. +- */ +- if (done) { +- dev_err(mmc_dev(card->host), +- "Card stuck in wrong state! %s status: %#x\n", +- __func__, status); +- return -ETIMEDOUT; +- } +- } while (!mmc_ready_for_data(status)); +- +- return err; +-} +- + static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, + struct mmc_blk_ioc_data *idata) + { +@@ -549,6 +518,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, + return mmc_sanitize(card, idata->ic.cmd_timeout_ms); + + mmc_wait_for_req(card->host, &mrq); ++ memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp)); + + if (cmd.error) { + dev_err(mmc_dev(card->host), "%s: cmd error %d\n", +@@ -598,14 +568,13 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, + if (idata->ic.postsleep_min_us) + usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us); + +- memcpy(&(idata->ic.response), cmd.resp, sizeof(cmd.resp)); +- + if (idata->rpmb || (cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) { + /* + * Ensure RPMB/R1B command has completed by polling CMD13 + * "Send Status". + */ +- err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, NULL); ++ err = mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, false, ++ MMC_BUSY_IO); + } + + return err; +@@ -1636,7 +1605,7 @@ static int mmc_blk_fix_state(struct mmc_card *card, struct request *req) + + mmc_blk_send_stop(card, timeout); + +- err = card_busy_detect(card, timeout, NULL); ++ err = mmc_poll_for_busy(card, timeout, false, MMC_BUSY_IO); + + mmc_retune_release(card->host); + +@@ -1851,28 +1820,48 @@ static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq) + brq->data.error || brq->cmd.resp[0] & CMD_ERRORS; + } + ++static int mmc_blk_busy_cb(void *cb_data, bool *busy) ++{ ++ struct mmc_blk_busy_data *data = cb_data; ++ u32 status = 0; ++ int err; ++ ++ err = mmc_send_status(data->card, &status); ++ if (err) ++ return err; ++ ++ /* Accumulate response error bits. */ ++ data->status |= status; ++ ++ *busy = !mmc_ready_for_data(status); ++ return 0; ++} ++ + static int mmc_blk_card_busy(struct mmc_card *card, struct request *req) + { + struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); +- u32 status = 0; ++ struct mmc_blk_busy_data cb_data; + int err; + + if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ) + return 0; + +- err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, &status); ++ cb_data.card = card; ++ cb_data.status = 0; ++ err = __mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, &mmc_blk_busy_cb, ++ &cb_data); + + /* + * Do not assume data transferred correctly if there are any error bits + * set. + */ +- if (status & mmc_blk_stop_err_bits(&mqrq->brq)) { ++ if (cb_data.status & mmc_blk_stop_err_bits(&mqrq->brq)) { + mqrq->brq.data.bytes_xfered = 0; + err = err ? err : -EIO; + } + + /* Copy the exception bit so it will be seen later on */ +- if (mmc_card_mmc(card) && status & R1_EXCEPTION_EVENT) ++ if (mmc_card_mmc(card) && cb_data.status & R1_EXCEPTION_EVENT) + mqrq->brq.cmd.resp[0] |= R1_EXCEPTION_EVENT; + + return err; +diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c +index 973756ed4016f..90d213a2203f4 100644 +--- a/drivers/mmc/core/mmc_ops.c ++++ b/drivers/mmc/core/mmc_ops.c +@@ -435,7 +435,7 @@ static int mmc_busy_cb(void *cb_data, bool *busy) + u32 status = 0; + int err; + +- if (host->ops->card_busy) { ++ if (data->busy_cmd != MMC_BUSY_IO && host->ops->card_busy) { + *busy = host->ops->card_busy(host); + return 0; + } +@@ -457,6 +457,7 @@ static int mmc_busy_cb(void *cb_data, bool *busy) + break; + case MMC_BUSY_HPI: + case MMC_BUSY_EXTR_SINGLE: ++ case MMC_BUSY_IO: + break; + default: + err = -EINVAL; +@@ -509,6 +510,7 @@ int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + + return 0; + } ++EXPORT_SYMBOL_GPL(__mmc_poll_for_busy); + + int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + bool retry_crc_err, enum mmc_busy_cmd busy_cmd) +@@ -521,6 +523,7 @@ int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + + return __mmc_poll_for_busy(card, timeout_ms, &mmc_busy_cb, &cb_data); + } ++EXPORT_SYMBOL_GPL(mmc_poll_for_busy); + + bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, + unsigned int timeout_ms) +diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h +index 41ab4f573a310..ae25ffc2e8704 100644 +--- a/drivers/mmc/core/mmc_ops.h ++++ b/drivers/mmc/core/mmc_ops.h +@@ -15,6 +15,7 @@ enum mmc_busy_cmd { + MMC_BUSY_ERASE, + MMC_BUSY_HPI, + MMC_BUSY_EXTR_SINGLE, ++ MMC_BUSY_IO, + }; + + struct mmc_host; +diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c +index 4ca9374157348..58cfaffa3c2d8 100644 +--- a/drivers/mmc/host/rtsx_pci_sdmmc.c ++++ b/drivers/mmc/host/rtsx_pci_sdmmc.c +@@ -542,9 +542,22 @@ static int sd_write_long_data(struct realtek_pci_sdmmc *host, + return 0; + } + ++static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host) ++{ ++ rtsx_pci_write_register(host->pcr, SD_CFG1, ++ SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_128); ++} ++ ++static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host) ++{ ++ rtsx_pci_write_register(host->pcr, SD_CFG1, ++ SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0); ++} ++ + static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq) + { + struct mmc_data *data = mrq->data; ++ int err; + + if (host->sg_count < 0) { + data->error = host->sg_count; +@@ -553,22 +566,19 @@ static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq) + return data->error; + } + +- if (data->flags & MMC_DATA_READ) +- return sd_read_long_data(host, mrq); ++ if (data->flags & MMC_DATA_READ) { ++ if (host->initial_mode) ++ sd_disable_initial_mode(host); + +- return sd_write_long_data(host, mrq); +-} ++ err = sd_read_long_data(host, mrq); + +-static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host) +-{ +- rtsx_pci_write_register(host->pcr, SD_CFG1, +- SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_128); +-} ++ if (host->initial_mode) ++ sd_enable_initial_mode(host); + +-static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host) +-{ +- rtsx_pci_write_register(host->pcr, SD_CFG1, +- SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0); ++ return err; ++ } ++ ++ return sd_write_long_data(host, mrq); + } + + static void sd_normal_rw(struct realtek_pci_sdmmc *host, +diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c +index 0e7c07ed96904..b6902447d7797 100644 +--- a/drivers/mmc/host/sdhci-of-arasan.c ++++ b/drivers/mmc/host/sdhci-of-arasan.c +@@ -159,6 +159,12 @@ struct sdhci_arasan_data { + /* Controller immediately reports SDHCI_CLOCK_INT_STABLE after enabling the + * internal clock even when the clock isn't stable */ + #define SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE BIT(1) ++/* ++ * Some of the Arasan variations might not have timing requirements ++ * met at 25MHz for Default Speed mode, those controllers work at ++ * 19MHz instead ++ */ ++#define SDHCI_ARASAN_QUIRK_CLOCK_25_BROKEN BIT(2) + }; + + struct sdhci_arasan_of_data { +@@ -267,7 +273,12 @@ static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock) + * through low speeds without power cycling. + */ + sdhci_set_clock(host, host->max_clk); +- phy_power_on(sdhci_arasan->phy); ++ if (phy_power_on(sdhci_arasan->phy)) { ++ pr_err("%s: Cannot power on phy.\n", ++ mmc_hostname(host->mmc)); ++ return; ++ } ++ + sdhci_arasan->is_phy_on = true; + + /* +@@ -290,6 +301,16 @@ static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock) + sdhci_arasan->is_phy_on = false; + } + ++ if (sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_CLOCK_25_BROKEN) { ++ /* ++ * Some of the Arasan variations might not have timing ++ * requirements met at 25MHz for Default Speed mode, ++ * those controllers work at 19MHz instead. ++ */ ++ if (clock == DEFAULT_SPEED_MAX_DTR) ++ clock = (DEFAULT_SPEED_MAX_DTR * 19) / 25; ++ } ++ + /* Set the Input and Output Clock Phase Delays */ + if (clk_data->set_clk_delays) + clk_data->set_clk_delays(host); +@@ -307,7 +328,12 @@ static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock) + msleep(20); + + if (ctrl_phy) { +- phy_power_on(sdhci_arasan->phy); ++ if (phy_power_on(sdhci_arasan->phy)) { ++ pr_err("%s: Cannot power on phy.\n", ++ mmc_hostname(host->mmc)); ++ return; ++ } ++ + sdhci_arasan->is_phy_on = true; + } + } +@@ -463,7 +489,9 @@ static int sdhci_arasan_suspend(struct device *dev) + ret = phy_power_off(sdhci_arasan->phy); + if (ret) { + dev_err(dev, "Cannot power off phy.\n"); +- sdhci_resume_host(host); ++ if (sdhci_resume_host(host)) ++ dev_err(dev, "Cannot resume host.\n"); ++ + return ret; + } + sdhci_arasan->is_phy_on = false; +@@ -1608,6 +1636,8 @@ static int sdhci_arasan_probe(struct platform_device *pdev) + if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) { + host->mmc_host_ops.execute_tuning = + arasan_zynqmp_execute_tuning; ++ ++ sdhci_arasan->quirks |= SDHCI_ARASAN_QUIRK_CLOCK_25_BROKEN; + } + + arasan_dt_parse_clk_phases(dev, &sdhci_arasan->clk_data); +diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c +index 8b49fd56cf964..29e8a546dcd60 100644 +--- a/drivers/mtd/nand/raw/intel-nand-controller.c ++++ b/drivers/mtd/nand/raw/intel-nand-controller.c +@@ -631,19 +631,26 @@ static int ebu_nand_probe(struct platform_device *pdev) + ebu_host->clk_rate = clk_get_rate(ebu_host->clk); + + ebu_host->dma_tx = dma_request_chan(dev, "tx"); +- if (IS_ERR(ebu_host->dma_tx)) +- return dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx), +- "failed to request DMA tx chan!.\n"); ++ if (IS_ERR(ebu_host->dma_tx)) { ++ ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx), ++ "failed to request DMA tx chan!.\n"); ++ goto err_disable_unprepare_clk; ++ } + + ebu_host->dma_rx = dma_request_chan(dev, "rx"); +- if (IS_ERR(ebu_host->dma_rx)) +- return dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx), +- "failed to request DMA rx chan!.\n"); ++ if (IS_ERR(ebu_host->dma_rx)) { ++ ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx), ++ "failed to request DMA rx chan!.\n"); ++ ebu_host->dma_rx = NULL; ++ goto err_cleanup_dma; ++ } + + resname = devm_kasprintf(dev, GFP_KERNEL, "addr_sel%d", cs); + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname); +- if (!res) +- return -EINVAL; ++ if (!res) { ++ ret = -EINVAL; ++ goto err_cleanup_dma; ++ } + ebu_host->cs[cs].addr_sel = res->start; + writel(ebu_host->cs[cs].addr_sel | EBU_ADDR_MASK(5) | EBU_ADDR_SEL_REGEN, + ebu_host->ebu + EBU_ADDR_SEL(cs)); +@@ -653,7 +660,8 @@ static int ebu_nand_probe(struct platform_device *pdev) + mtd = nand_to_mtd(&ebu_host->chip); + if (!mtd->name) { + dev_err(ebu_host->dev, "NAND label property is mandatory\n"); +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_cleanup_dma; + } + + mtd->dev.parent = dev; +@@ -681,6 +689,7 @@ err_clean_nand: + nand_cleanup(&ebu_host->chip); + err_cleanup_dma: + ebu_dma_cleanup(ebu_host); ++err_disable_unprepare_clk: + clk_disable_unprepare(ebu_host->clk); + + return ret; +diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c +index 31730efa75382..8aef6005bfee1 100644 +--- a/drivers/net/bonding/bond_main.c ++++ b/drivers/net/bonding/bond_main.c +@@ -2252,7 +2252,6 @@ static int __bond_release_one(struct net_device *bond_dev, + /* recompute stats just before removing the slave */ + bond_get_stats(bond->dev, &bond->bond_stats); + +- bond_upper_dev_unlink(bond, slave); + /* unregister rx_handler early so bond_handle_frame wouldn't be called + * for this slave anymore. + */ +@@ -2261,6 +2260,8 @@ static int __bond_release_one(struct net_device *bond_dev, + if (BOND_MODE(bond) == BOND_MODE_8023AD) + bond_3ad_unbind_slave(slave); + ++ bond_upper_dev_unlink(bond, slave); ++ + if (bond_mode_can_use_xmit_hash(bond)) + bond_update_slave_arr(bond, slave); + +diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c +index e78026ef6d8cc..64d6dfa831220 100644 +--- a/drivers/net/dsa/lantiq_gswip.c ++++ b/drivers/net/dsa/lantiq_gswip.c +@@ -843,7 +843,8 @@ static int gswip_setup(struct dsa_switch *ds) + + gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN, + GSWIP_MAC_CTRL_2p(cpu_port)); +- gswip_switch_w(priv, VLAN_ETH_FRAME_LEN + 8, GSWIP_MAC_FLEN); ++ gswip_switch_w(priv, VLAN_ETH_FRAME_LEN + 8 + ETH_FCS_LEN, ++ GSWIP_MAC_FLEN); + gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD, + GSWIP_BM_QUEUE_GCTRL); + +diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +index 98cc0133c3437..5ad5419e8be36 100644 +--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c ++++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +@@ -3231,12 +3231,6 @@ static int dpaa2_switch_probe(struct fsl_mc_device *sw_dev) + ðsw->fq[i].napi, dpaa2_switch_poll, + NAPI_POLL_WEIGHT); + +- err = dpsw_enable(ethsw->mc_io, 0, ethsw->dpsw_handle); +- if (err) { +- dev_err(ethsw->dev, "dpsw_enable err %d\n", err); +- goto err_free_netdev; +- } +- + /* Setup IRQs */ + err = dpaa2_switch_setup_irqs(sw_dev); + if (err) +diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +index c0a478ae95834..0dbed35645eda 100644 +--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c ++++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +@@ -10,7 +10,14 @@ + + static u16 hclge_errno_to_resp(int errno) + { +- return abs(errno); ++ int resp = abs(errno); ++ ++ /* The status for pf to vf msg cmd is u16, constrainted by HW. ++ * We need to keep the same type with it. ++ * The intput errno is the stander error code, it's safely to ++ * use a u16 to store the abs(errno). ++ */ ++ return (u16)resp; + } + + /* hclge_gen_resp_to_vf: used to generate a synchronous response to VF when PF +diff --git a/drivers/net/ethernet/intel/iavf/iavf.h b/drivers/net/ethernet/intel/iavf/iavf.h +index 90793b36126e6..68c80f04113c8 100644 +--- a/drivers/net/ethernet/intel/iavf/iavf.h ++++ b/drivers/net/ethernet/intel/iavf/iavf.h +@@ -186,12 +186,6 @@ enum iavf_state_t { + __IAVF_RUNNING, /* opened, working */ + }; + +-enum iavf_critical_section_t { +- __IAVF_IN_CRITICAL_TASK, /* cannot be interrupted */ +- __IAVF_IN_CLIENT_TASK, +- __IAVF_IN_REMOVE_TASK, /* device being removed */ +-}; +- + #define IAVF_CLOUD_FIELD_OMAC 0x01 + #define IAVF_CLOUD_FIELD_IMAC 0x02 + #define IAVF_CLOUD_FIELD_IVLAN 0x04 +@@ -236,6 +230,9 @@ struct iavf_adapter { + struct iavf_q_vector *q_vectors; + struct list_head vlan_filter_list; + struct list_head mac_filter_list; ++ struct mutex crit_lock; ++ struct mutex client_lock; ++ struct mutex remove_lock; + /* Lock to protect accesses to MAC and VLAN lists */ + spinlock_t mac_vlan_list_lock; + char misc_vector_name[IFNAMSIZ + 9]; +diff --git a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c +index af43fbd8cb75e..edbeb27213f83 100644 +--- a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c ++++ b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c +@@ -1352,8 +1352,7 @@ static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rx + if (!fltr) + return -ENOMEM; + +- while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section)) { ++ while (!mutex_trylock(&adapter->crit_lock)) { + if (--count == 0) { + kfree(fltr); + return -EINVAL; +@@ -1378,7 +1377,7 @@ ret: + if (err && fltr) + kfree(fltr); + +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + return err; + } + +@@ -1563,8 +1562,7 @@ iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter, + return -EINVAL; + } + +- while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section)) { ++ while (!mutex_trylock(&adapter->crit_lock)) { + if (--count == 0) { + kfree(rss_new); + return -EINVAL; +@@ -1600,7 +1598,7 @@ iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter, + if (!err) + mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0); + +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + + if (!rss_new_add) + kfree(rss_new); +diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c +index 606a01ce40739..23762a7ef740b 100644 +--- a/drivers/net/ethernet/intel/iavf/iavf_main.c ++++ b/drivers/net/ethernet/intel/iavf/iavf_main.c +@@ -131,6 +131,27 @@ enum iavf_status iavf_free_virt_mem_d(struct iavf_hw *hw, + return 0; + } + ++/** ++ * iavf_lock_timeout - try to lock mutex but give up after timeout ++ * @lock: mutex that should be locked ++ * @msecs: timeout in msecs ++ * ++ * Returns 0 on success, negative on failure ++ **/ ++static int iavf_lock_timeout(struct mutex *lock, unsigned int msecs) ++{ ++ unsigned int wait, delay = 10; ++ ++ for (wait = 0; wait < msecs; wait += delay) { ++ if (mutex_trylock(lock)) ++ return 0; ++ ++ msleep(delay); ++ } ++ ++ return -1; ++} ++ + /** + * iavf_schedule_reset - Set the flags and schedule a reset event + * @adapter: board private structure +@@ -1916,7 +1937,7 @@ static void iavf_watchdog_task(struct work_struct *work) + struct iavf_hw *hw = &adapter->hw; + u32 reg_val; + +- if (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section)) ++ if (!mutex_trylock(&adapter->crit_lock)) + goto restart_watchdog; + + if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) +@@ -1934,8 +1955,7 @@ static void iavf_watchdog_task(struct work_struct *work) + adapter->state = __IAVF_STARTUP; + adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED; + queue_delayed_work(iavf_wq, &adapter->init_task, 10); +- clear_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + /* Don't reschedule the watchdog, since we've restarted + * the init task. When init_task contacts the PF and + * gets everything set up again, it'll restart the +@@ -1945,14 +1965,13 @@ static void iavf_watchdog_task(struct work_struct *work) + } + adapter->aq_required = 0; + adapter->current_op = VIRTCHNL_OP_UNKNOWN; +- clear_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + queue_delayed_work(iavf_wq, + &adapter->watchdog_task, + msecs_to_jiffies(10)); + goto watchdog_done; + case __IAVF_RESETTING: +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + queue_delayed_work(iavf_wq, &adapter->watchdog_task, HZ * 2); + return; + case __IAVF_DOWN: +@@ -1975,7 +1994,7 @@ static void iavf_watchdog_task(struct work_struct *work) + } + break; + case __IAVF_REMOVE: +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + return; + default: + goto restart_watchdog; +@@ -1984,7 +2003,6 @@ static void iavf_watchdog_task(struct work_struct *work) + /* check for hw reset */ + reg_val = rd32(hw, IAVF_VF_ARQLEN1) & IAVF_VF_ARQLEN1_ARQENABLE_MASK; + if (!reg_val) { +- adapter->state = __IAVF_RESETTING; + adapter->flags |= IAVF_FLAG_RESET_PENDING; + adapter->aq_required = 0; + adapter->current_op = VIRTCHNL_OP_UNKNOWN; +@@ -1998,7 +2016,7 @@ watchdog_done: + if (adapter->state == __IAVF_RUNNING || + adapter->state == __IAVF_COMM_FAILED) + iavf_detect_recover_hung(&adapter->vsi); +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + restart_watchdog: + if (adapter->aq_required) + queue_delayed_work(iavf_wq, &adapter->watchdog_task, +@@ -2062,7 +2080,7 @@ static void iavf_disable_vf(struct iavf_adapter *adapter) + memset(adapter->vf_res, 0, IAVF_VIRTCHNL_VF_RESOURCE_SIZE); + iavf_shutdown_adminq(&adapter->hw); + adapter->netdev->flags &= ~IFF_UP; +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + adapter->flags &= ~IAVF_FLAG_RESET_PENDING; + adapter->state = __IAVF_DOWN; + wake_up(&adapter->down_waitqueue); +@@ -2095,11 +2113,14 @@ static void iavf_reset_task(struct work_struct *work) + /* When device is being removed it doesn't make sense to run the reset + * task, just return in such a case. + */ +- if (test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) ++ if (mutex_is_locked(&adapter->remove_lock)) + return; + +- while (test_and_set_bit(__IAVF_IN_CLIENT_TASK, +- &adapter->crit_section)) ++ if (iavf_lock_timeout(&adapter->crit_lock, 200)) { ++ schedule_work(&adapter->reset_task); ++ return; ++ } ++ while (!mutex_trylock(&adapter->client_lock)) + usleep_range(500, 1000); + if (CLIENT_ENABLED(adapter)) { + adapter->flags &= ~(IAVF_FLAG_CLIENT_NEEDS_OPEN | +@@ -2151,7 +2172,7 @@ static void iavf_reset_task(struct work_struct *work) + dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n", + reg_val); + iavf_disable_vf(adapter); +- clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->client_lock); + return; /* Do not attempt to reinit. It's dead, Jim. */ + } + +@@ -2278,13 +2299,13 @@ continue_reset: + adapter->state = __IAVF_DOWN; + wake_up(&adapter->down_waitqueue); + } +- clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section); +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->client_lock); ++ mutex_unlock(&adapter->crit_lock); + + return; + reset_err: +- clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section); +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->client_lock); ++ mutex_unlock(&adapter->crit_lock); + dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n"); + iavf_close(netdev); + } +@@ -2312,6 +2333,8 @@ static void iavf_adminq_task(struct work_struct *work) + if (!event.msg_buf) + goto out; + ++ if (iavf_lock_timeout(&adapter->crit_lock, 200)) ++ goto freedom; + do { + ret = iavf_clean_arq_element(hw, &event, &pending); + v_op = (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); +@@ -2325,6 +2348,7 @@ static void iavf_adminq_task(struct work_struct *work) + if (pending != 0) + memset(event.msg_buf, 0, IAVF_MAX_AQ_BUF_SIZE); + } while (pending); ++ mutex_unlock(&adapter->crit_lock); + + if ((adapter->flags & + (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED)) || +@@ -2391,7 +2415,7 @@ static void iavf_client_task(struct work_struct *work) + * later. + */ + +- if (test_and_set_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section)) ++ if (!mutex_trylock(&adapter->client_lock)) + return; + + if (adapter->flags & IAVF_FLAG_SERVICE_CLIENT_REQUESTED) { +@@ -2414,7 +2438,7 @@ static void iavf_client_task(struct work_struct *work) + adapter->flags &= ~IAVF_FLAG_CLIENT_NEEDS_OPEN; + } + out: +- clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->client_lock); + } + + /** +@@ -3017,8 +3041,7 @@ static int iavf_configure_clsflower(struct iavf_adapter *adapter, + if (!filter) + return -ENOMEM; + +- while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section)) { ++ while (!mutex_trylock(&adapter->crit_lock)) { + if (--count == 0) + goto err; + udelay(1); +@@ -3049,7 +3072,7 @@ err: + if (err) + kfree(filter); + +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + return err; + } + +@@ -3196,8 +3219,7 @@ static int iavf_open(struct net_device *netdev) + return -EIO; + } + +- while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section)) ++ while (!mutex_trylock(&adapter->crit_lock)) + usleep_range(500, 1000); + + if (adapter->state != __IAVF_DOWN) { +@@ -3232,7 +3254,7 @@ static int iavf_open(struct net_device *netdev) + + iavf_irq_enable(adapter, true); + +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + + return 0; + +@@ -3244,7 +3266,7 @@ err_setup_rx: + err_setup_tx: + iavf_free_all_tx_resources(adapter); + err_unlock: +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + + return err; + } +@@ -3268,8 +3290,7 @@ static int iavf_close(struct net_device *netdev) + if (adapter->state <= __IAVF_DOWN_PENDING) + return 0; + +- while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section)) ++ while (!mutex_trylock(&adapter->crit_lock)) + usleep_range(500, 1000); + + set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); +@@ -3280,7 +3301,7 @@ static int iavf_close(struct net_device *netdev) + adapter->state = __IAVF_DOWN_PENDING; + iavf_free_traffic_irqs(adapter); + +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + + /* We explicitly don't free resources here because the hardware is + * still active and can DMA into memory. Resources are cleared in +@@ -3629,6 +3650,10 @@ static void iavf_init_task(struct work_struct *work) + init_task.work); + struct iavf_hw *hw = &adapter->hw; + ++ if (iavf_lock_timeout(&adapter->crit_lock, 5000)) { ++ dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n", __FUNCTION__); ++ return; ++ } + switch (adapter->state) { + case __IAVF_STARTUP: + if (iavf_startup(adapter) < 0) +@@ -3641,14 +3666,14 @@ static void iavf_init_task(struct work_struct *work) + case __IAVF_INIT_GET_RESOURCES: + if (iavf_init_get_resources(adapter) < 0) + goto init_failed; +- return; ++ goto out; + default: + goto init_failed; + } + + queue_delayed_work(iavf_wq, &adapter->init_task, + msecs_to_jiffies(30)); +- return; ++ goto out; + init_failed: + if (++adapter->aq_wait_count > IAVF_AQ_MAX_ERR) { + dev_err(&adapter->pdev->dev, +@@ -3657,9 +3682,11 @@ init_failed: + iavf_shutdown_adminq(hw); + adapter->state = __IAVF_STARTUP; + queue_delayed_work(iavf_wq, &adapter->init_task, HZ * 5); +- return; ++ goto out; + } + queue_delayed_work(iavf_wq, &adapter->init_task, HZ); ++out: ++ mutex_unlock(&adapter->crit_lock); + } + + /** +@@ -3676,9 +3703,12 @@ static void iavf_shutdown(struct pci_dev *pdev) + if (netif_running(netdev)) + iavf_close(netdev); + ++ if (iavf_lock_timeout(&adapter->crit_lock, 5000)) ++ dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n", __FUNCTION__); + /* Prevent the watchdog from running. */ + adapter->state = __IAVF_REMOVE; + adapter->aq_required = 0; ++ mutex_unlock(&adapter->crit_lock); + + #ifdef CONFIG_PM + pci_save_state(pdev); +@@ -3772,6 +3802,9 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) + /* set up the locks for the AQ, do this only once in probe + * and destroy them only once in remove + */ ++ mutex_init(&adapter->crit_lock); ++ mutex_init(&adapter->client_lock); ++ mutex_init(&adapter->remove_lock); + mutex_init(&hw->aq.asq_mutex); + mutex_init(&hw->aq.arq_mutex); + +@@ -3823,8 +3856,7 @@ static int __maybe_unused iavf_suspend(struct device *dev_d) + + netif_device_detach(netdev); + +- while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, +- &adapter->crit_section)) ++ while (!mutex_trylock(&adapter->crit_lock)) + usleep_range(500, 1000); + + if (netif_running(netdev)) { +@@ -3835,7 +3867,7 @@ static int __maybe_unused iavf_suspend(struct device *dev_d) + iavf_free_misc_irq(adapter); + iavf_reset_interrupt_capability(adapter); + +- clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section); ++ mutex_unlock(&adapter->crit_lock); + + return 0; + } +@@ -3897,7 +3929,7 @@ static void iavf_remove(struct pci_dev *pdev) + struct iavf_hw *hw = &adapter->hw; + int err; + /* Indicate we are in remove and not to run reset_task */ +- set_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section); ++ mutex_lock(&adapter->remove_lock); + cancel_delayed_work_sync(&adapter->init_task); + cancel_work_sync(&adapter->reset_task); + cancel_delayed_work_sync(&adapter->client_task); +@@ -3912,10 +3944,6 @@ static void iavf_remove(struct pci_dev *pdev) + err); + } + +- /* Shut down all the garbage mashers on the detention level */ +- adapter->state = __IAVF_REMOVE; +- adapter->aq_required = 0; +- adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; + iavf_request_reset(adapter); + msleep(50); + /* If the FW isn't responding, kick it once, but only once. */ +@@ -3923,6 +3951,13 @@ static void iavf_remove(struct pci_dev *pdev) + iavf_request_reset(adapter); + msleep(50); + } ++ if (iavf_lock_timeout(&adapter->crit_lock, 5000)) ++ dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n", __FUNCTION__); ++ ++ /* Shut down all the garbage mashers on the detention level */ ++ adapter->state = __IAVF_REMOVE; ++ adapter->aq_required = 0; ++ adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; + iavf_free_all_tx_resources(adapter); + iavf_free_all_rx_resources(adapter); + iavf_misc_irq_disable(adapter); +@@ -3942,6 +3977,11 @@ static void iavf_remove(struct pci_dev *pdev) + /* destroy the locks only once, here */ + mutex_destroy(&hw->aq.arq_mutex); + mutex_destroy(&hw->aq.asq_mutex); ++ mutex_destroy(&adapter->client_lock); ++ mutex_unlock(&adapter->crit_lock); ++ mutex_destroy(&adapter->crit_lock); ++ mutex_unlock(&adapter->remove_lock); ++ mutex_destroy(&adapter->remove_lock); + + iounmap(hw->hw_addr); + pci_release_regions(pdev); +diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c +index ed2d66bc2d6c3..f62982c4d933d 100644 +--- a/drivers/net/ethernet/intel/igc/igc_main.c ++++ b/drivers/net/ethernet/intel/igc/igc_main.c +@@ -4817,6 +4817,7 @@ static irqreturn_t igc_msix_ring(int irq, void *data) + */ + static int igc_request_msix(struct igc_adapter *adapter) + { ++ unsigned int num_q_vectors = adapter->num_q_vectors; + int i = 0, err = 0, vector = 0, free_vector = 0; + struct net_device *netdev = adapter->netdev; + +@@ -4825,7 +4826,13 @@ static int igc_request_msix(struct igc_adapter *adapter) + if (err) + goto err_out; + +- for (i = 0; i < adapter->num_q_vectors; i++) { ++ if (num_q_vectors > MAX_Q_VECTORS) { ++ num_q_vectors = MAX_Q_VECTORS; ++ dev_warn(&adapter->pdev->dev, ++ "The number of queue vectors (%d) is higher than max allowed (%d)\n", ++ adapter->num_q_vectors, MAX_Q_VECTORS); ++ } ++ for (i = 0; i < num_q_vectors; i++) { + struct igc_q_vector *q_vector = adapter->q_vector[i]; + + vector++; +diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h +index f5ec39de026a5..05f4334700e90 100644 +--- a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h ++++ b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h +@@ -717,6 +717,7 @@ struct nix_lf_alloc_rsp { + u8 cgx_links; /* No. of CGX links present in HW */ + u8 lbk_links; /* No. of LBK links present in HW */ + u8 sdp_links; /* No. of SDP links present in HW */ ++ u8 tx_link; /* Transmit channel link number */ + }; + + struct nix_lf_free_req { +diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +index c32195073e8a5..87af164951eae 100644 +--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c ++++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +@@ -249,9 +249,11 @@ static bool is_valid_txschq(struct rvu *rvu, int blkaddr, + return true; + } + +-static int nix_interface_init(struct rvu *rvu, u16 pcifunc, int type, int nixlf) ++static int nix_interface_init(struct rvu *rvu, u16 pcifunc, int type, int nixlf, ++ struct nix_lf_alloc_rsp *rsp) + { + struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc); ++ struct rvu_hwinfo *hw = rvu->hw; + struct mac_ops *mac_ops; + int pkind, pf, vf, lbkid; + u8 cgx_id, lmac_id; +@@ -276,6 +278,8 @@ static int nix_interface_init(struct rvu *rvu, u16 pcifunc, int type, int nixlf) + pfvf->tx_chan_base = pfvf->rx_chan_base; + pfvf->rx_chan_cnt = 1; + pfvf->tx_chan_cnt = 1; ++ rsp->tx_link = cgx_id * hw->lmac_per_cgx + lmac_id; ++ + cgx_set_pkind(rvu_cgx_pdata(cgx_id, rvu), lmac_id, pkind); + rvu_npc_set_pkind(rvu, pkind, pfvf); + +@@ -309,6 +313,7 @@ static int nix_interface_init(struct rvu *rvu, u16 pcifunc, int type, int nixlf) + rvu_nix_chan_lbk(rvu, lbkid, vf + 1); + pfvf->rx_chan_cnt = 1; + pfvf->tx_chan_cnt = 1; ++ rsp->tx_link = hw->cgx_links + lbkid; + rvu_npc_set_pkind(rvu, NPC_RX_LBK_PKIND, pfvf); + rvu_npc_install_promisc_entry(rvu, pcifunc, nixlf, + pfvf->rx_chan_base, +@@ -1258,7 +1263,7 @@ int rvu_mbox_handler_nix_lf_alloc(struct rvu *rvu, + rvu_write64(rvu, blkaddr, NIX_AF_LFX_TX_PARSE_CFG(nixlf), cfg); + + intf = is_afvf(pcifunc) ? NIX_INTF_TYPE_LBK : NIX_INTF_TYPE_CGX; +- err = nix_interface_init(rvu, pcifunc, intf, nixlf); ++ err = nix_interface_init(rvu, pcifunc, intf, nixlf, rsp); + if (err) + goto free_mem; + +diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +index 94dfd64f526fa..124465b3987c4 100644 +--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c ++++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +@@ -586,25 +586,6 @@ void otx2_get_mac_from_af(struct net_device *netdev) + } + EXPORT_SYMBOL(otx2_get_mac_from_af); + +-static int otx2_get_link(struct otx2_nic *pfvf) +-{ +- int link = 0; +- u16 map; +- +- /* cgx lmac link */ +- if (pfvf->hw.tx_chan_base >= CGX_CHAN_BASE) { +- map = pfvf->hw.tx_chan_base & 0x7FF; +- link = 4 * ((map >> 8) & 0xF) + ((map >> 4) & 0xF); +- } +- /* LBK channel */ +- if (pfvf->hw.tx_chan_base < SDP_CHAN_BASE) { +- map = pfvf->hw.tx_chan_base & 0x7FF; +- link = pfvf->hw.cgx_links | ((map >> 8) & 0xF); +- } +- +- return link; +-} +- + int otx2_txschq_config(struct otx2_nic *pfvf, int lvl) + { + struct otx2_hw *hw = &pfvf->hw; +@@ -660,8 +641,7 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl) + req->regval[1] = TXSCH_TL1_DFLT_RR_PRIO << 24 | DFLT_RR_QTM; + + req->num_regs++; +- req->reg[2] = NIX_AF_TL3_TL2X_LINKX_CFG(schq, +- otx2_get_link(pfvf)); ++ req->reg[2] = NIX_AF_TL3_TL2X_LINKX_CFG(schq, hw->tx_link); + /* Enable this queue and backpressure */ + req->regval[2] = BIT_ULL(13) | BIT_ULL(12); + +@@ -1204,7 +1184,22 @@ static int otx2_aura_init(struct otx2_nic *pfvf, int aura_id, + /* Enable backpressure for RQ aura */ + if (aura_id < pfvf->hw.rqpool_cnt && !is_otx2_lbkvf(pfvf->pdev)) { + aq->aura.bp_ena = 0; ++ /* If NIX1 LF is attached then specify NIX1_RX. ++ * ++ * Below NPA_AURA_S[BP_ENA] is set according to the ++ * NPA_BPINTF_E enumeration given as: ++ * 0x0 + a*0x1 where 'a' is 0 for NIX0_RX and 1 for NIX1_RX so ++ * NIX0_RX is 0x0 + 0*0x1 = 0 ++ * NIX1_RX is 0x0 + 1*0x1 = 1 ++ * But in HRM it is given that ++ * "NPA_AURA_S[BP_ENA](w1[33:32]) - Enable aura backpressure to ++ * NIX-RX based on [BP] level. One bit per NIX-RX; index ++ * enumerated by NPA_BPINTF_E." ++ */ ++ if (pfvf->nix_blkaddr == BLKADDR_NIX1) ++ aq->aura.bp_ena = 1; + aq->aura.nix0_bpid = pfvf->bpid[0]; ++ + /* Set backpressure level for RQ's Aura */ + aq->aura.bp = RQ_BP_LVL_AURA; + } +@@ -1591,6 +1586,7 @@ void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf, + pfvf->hw.lso_tsov6_idx = rsp->lso_tsov6_idx; + pfvf->hw.cgx_links = rsp->cgx_links; + pfvf->hw.lbk_links = rsp->lbk_links; ++ pfvf->hw.tx_link = rsp->tx_link; + } + EXPORT_SYMBOL(mbox_handler_nix_lf_alloc); + +diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +index 8c602d27108a7..11686c5cf45bd 100644 +--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h ++++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +@@ -215,6 +215,7 @@ struct otx2_hw { + u64 cgx_fec_uncorr_blks; + u8 cgx_links; /* No. of CGX links present in HW */ + u8 lbk_links; /* No. of LBK links present in HW */ ++ u8 tx_link; /* Transmit channel link number */ + #define HW_TSO 0 + #define CN10K_MBOX 1 + #define CN10K_LMTST 2 +diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +index 9d79c5ec31e9f..db5dfff585c99 100644 +--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c ++++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +@@ -877,7 +877,7 @@ static void cb_timeout_handler(struct work_struct *work) + ent->ret = -ETIMEDOUT; + mlx5_core_warn(dev, "cmd[%d]: %s(0x%x) Async, timeout. Will cause a leak of a command resource\n", + ent->idx, mlx5_command_str(msg_to_opcode(ent->in)), msg_to_opcode(ent->in)); +- mlx5_cmd_comp_handler(dev, 1UL << ent->idx, true); ++ mlx5_cmd_comp_handler(dev, 1ULL << ent->idx, true); + + out: + cmd_ent_put(ent); /* for the cmd_ent_get() took on schedule delayed work */ +@@ -994,7 +994,7 @@ static void cmd_work_handler(struct work_struct *work) + MLX5_SET(mbox_out, ent->out, status, status); + MLX5_SET(mbox_out, ent->out, syndrome, drv_synd); + +- mlx5_cmd_comp_handler(dev, 1UL << ent->idx, true); ++ mlx5_cmd_comp_handler(dev, 1ULL << ent->idx, true); + return; + } + +@@ -1008,7 +1008,7 @@ static void cmd_work_handler(struct work_struct *work) + poll_timeout(ent); + /* make sure we read the descriptor after ownership is SW */ + rmb(); +- mlx5_cmd_comp_handler(dev, 1UL << ent->idx, (ent->ret == -ETIMEDOUT)); ++ mlx5_cmd_comp_handler(dev, 1ULL << ent->idx, (ent->ret == -ETIMEDOUT)); + } + } + +@@ -1068,7 +1068,7 @@ static void wait_func_handle_exec_timeout(struct mlx5_core_dev *dev, + mlx5_command_str(msg_to_opcode(ent->in)), msg_to_opcode(ent->in)); + + ent->ret = -ETIMEDOUT; +- mlx5_cmd_comp_handler(dev, 1UL << ent->idx, true); ++ mlx5_cmd_comp_handler(dev, 1ULL << ent->idx, true); + } + + static int wait_func(struct mlx5_core_dev *dev, struct mlx5_cmd_work_ent *ent) +diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c +index 43356fad53deb..ffdfb5a94b14b 100644 +--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c ++++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c +@@ -846,9 +846,9 @@ again: + new_htbl = dr_rule_rehash(rule, nic_rule, cur_htbl, + ste_location, send_ste_list); + if (!new_htbl) { +- mlx5dr_htbl_put(cur_htbl); + mlx5dr_err(dmn, "Failed creating rehash table, htbl-log_size: %d\n", + cur_htbl->chunk_size); ++ mlx5dr_htbl_put(cur_htbl); + } else { + cur_htbl = new_htbl; + } +diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_send.c +index 9df0e73d1c358..69b49deb66b22 100644 +--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_send.c ++++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_send.c +@@ -620,6 +620,7 @@ static int dr_cmd_modify_qp_rtr2rts(struct mlx5_core_dev *mdev, + + MLX5_SET(qpc, qpc, retry_count, attr->retry_cnt); + MLX5_SET(qpc, qpc, rnr_retry, attr->rnr_retry); ++ MLX5_SET(qpc, qpc, primary_address_path.ack_timeout, 0x8); /* ~1ms */ + + MLX5_SET(rtr2rts_qp_in, in, opcode, MLX5_CMD_OP_RTR2RTS_QP); + MLX5_SET(rtr2rts_qp_in, in, qpn, dr_qp->qpn); +diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +index 5dfa4799c34f2..ed2ade2a4f043 100644 +--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c ++++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +@@ -1697,7 +1697,7 @@ nfp_net_parse_meta(struct net_device *netdev, struct nfp_meta_parsed *meta, + case NFP_NET_META_RESYNC_INFO: + if (nfp_net_tls_rx_resync_req(netdev, data, pkt, + pkt_len)) +- return NULL; ++ return false; + data += sizeof(struct nfp_net_tls_resync_req); + break; + default: +diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +index 28dd0ed85a824..f7dc8458cde86 100644 +--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c ++++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +@@ -289,10 +289,7 @@ static int ipq806x_gmac_probe(struct platform_device *pdev) + val &= ~NSS_COMMON_GMAC_CTL_PHY_IFACE_SEL; + break; + default: +- dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n", +- phy_modes(gmac->phy_mode)); +- err = -EINVAL; +- goto err_remove_config_dt; ++ goto err_unsupported_phy; + } + regmap_write(gmac->nss_common, NSS_COMMON_GMAC_CTL(gmac->id), val); + +@@ -309,10 +306,7 @@ static int ipq806x_gmac_probe(struct platform_device *pdev) + NSS_COMMON_CLK_SRC_CTRL_OFFSET(gmac->id); + break; + default: +- dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n", +- phy_modes(gmac->phy_mode)); +- err = -EINVAL; +- goto err_remove_config_dt; ++ goto err_unsupported_phy; + } + regmap_write(gmac->nss_common, NSS_COMMON_CLK_SRC_CTRL, val); + +@@ -329,8 +323,7 @@ static int ipq806x_gmac_probe(struct platform_device *pdev) + NSS_COMMON_CLK_GATE_GMII_TX_EN(gmac->id); + break; + default: +- /* We don't get here; the switch above will have errored out */ +- unreachable(); ++ goto err_unsupported_phy; + } + regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val); + +@@ -361,6 +354,11 @@ static int ipq806x_gmac_probe(struct platform_device *pdev) + + return 0; + ++err_unsupported_phy: ++ dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n", ++ phy_modes(gmac->phy_mode)); ++ err = -EINVAL; ++ + err_remove_config_dt: + stmmac_remove_config_dt(pdev, plat_dat); + +diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +index fa90bcdf4e455..8a150cc462dcf 100644 +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +@@ -5342,7 +5342,7 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *napi, int budget) + struct stmmac_channel *ch = + container_of(napi, struct stmmac_channel, rxtx_napi); + struct stmmac_priv *priv = ch->priv_data; +- int rx_done, tx_done; ++ int rx_done, tx_done, rxtx_done; + u32 chan = ch->index; + + priv->xstats.napi_poll++; +@@ -5352,14 +5352,16 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *napi, int budget) + + rx_done = stmmac_rx_zc(priv, budget, chan); + ++ rxtx_done = max(tx_done, rx_done); ++ + /* If either TX or RX work is not complete, return budget + * and keep pooling + */ +- if (tx_done >= budget || rx_done >= budget) ++ if (rxtx_done >= budget) + return budget; + + /* all work done, exit the polling mode */ +- if (napi_complete_done(napi, rx_done)) { ++ if (napi_complete_done(napi, rxtx_done)) { + unsigned long flags; + + spin_lock_irqsave(&ch->lock, flags); +@@ -5370,7 +5372,7 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *napi, int budget) + spin_unlock_irqrestore(&ch->lock, flags); + } + +- return min(rx_done, budget - 1); ++ return min(rxtx_done, budget - 1); + } + + /** +diff --git a/drivers/net/ethernet/wiznet/w5100.c b/drivers/net/ethernet/wiznet/w5100.c +index 811815f8cd3bb..f974e70a82e8b 100644 +--- a/drivers/net/ethernet/wiznet/w5100.c ++++ b/drivers/net/ethernet/wiznet/w5100.c +@@ -1047,6 +1047,8 @@ static int w5100_mmio_probe(struct platform_device *pdev) + mac_addr = data->mac_addr; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); ++ if (!mem) ++ return -EINVAL; + if (resource_size(mem) < W5100_BUS_DIRECT_SIZE) + ops = &w5100_mmio_indirect_ops; + else +diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c +index af44ca41189e3..bda8677eae88d 100644 +--- a/drivers/net/ipa/ipa_cmd.c ++++ b/drivers/net/ipa/ipa_cmd.c +@@ -159,35 +159,45 @@ static void ipa_cmd_validate_build(void) + BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); + #undef TABLE_COUNT_MAX + #undef TABLE_SIZE +-} + +-#ifdef IPA_VALIDATE ++ /* Hashed and non-hashed fields are assumed to be the same size */ ++ BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_SIZE_FMASK) != ++ field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); ++ BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) != ++ field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK)); ++} + + /* Validate a memory region holding a table */ +-bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, +- bool route, bool ipv6, bool hashed) ++bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route) + { ++ u32 offset_max = field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); ++ u32 size_max = field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK); ++ const char *table = route ? "route" : "filter"; + struct device *dev = &ipa->pdev->dev; +- u32 offset_max; + +- offset_max = hashed ? field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) +- : field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); ++ /* Size must fit in the immediate command field that holds it */ ++ if (mem->size > size_max) { ++ dev_err(dev, "%s table region size too large\n", table); ++ dev_err(dev, " (0x%04x > 0x%04x)\n", ++ mem->size, size_max); ++ ++ return false; ++ } ++ ++ /* Offset must fit in the immediate command field that holds it */ + if (mem->offset > offset_max || + ipa->mem_offset > offset_max - mem->offset) { +- dev_err(dev, "IPv%c %s%s table region offset too large\n", +- ipv6 ? '6' : '4', hashed ? "hashed " : "", +- route ? "route" : "filter"); ++ dev_err(dev, "%s table region offset too large\n", table); + dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", + ipa->mem_offset, mem->offset, offset_max); + + return false; + } + ++ /* Entire memory range must fit within IPA-local memory */ + if (mem->offset > ipa->mem_size || + mem->size > ipa->mem_size - mem->offset) { +- dev_err(dev, "IPv%c %s%s table region out of range\n", +- ipv6 ? '6' : '4', hashed ? "hashed " : "", +- route ? "route" : "filter"); ++ dev_err(dev, "%s table region out of range\n", table); + dev_err(dev, " (0x%04x + 0x%04x > 0x%04x)\n", + mem->offset, mem->size, ipa->mem_size); + +@@ -197,6 +207,8 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, + return true; + } + ++#ifdef IPA_VALIDATE ++ + /* Validate the memory region that holds headers */ + static bool ipa_cmd_header_valid(struct ipa *ipa) + { +diff --git a/drivers/net/ipa/ipa_cmd.h b/drivers/net/ipa/ipa_cmd.h +index b99262281f41c..ea723419c826b 100644 +--- a/drivers/net/ipa/ipa_cmd.h ++++ b/drivers/net/ipa/ipa_cmd.h +@@ -57,20 +57,18 @@ struct ipa_cmd_info { + enum dma_data_direction direction; + }; + +-#ifdef IPA_VALIDATE +- + /** + * ipa_cmd_table_valid() - Validate a memory region holding a table + * @ipa: - IPA pointer + * @mem: - IPA memory region descriptor + * @route: - Whether the region holds a route or filter table +- * @ipv6: - Whether the table is for IPv6 or IPv4 +- * @hashed: - Whether the table is hashed or non-hashed + * + * Return: true if region is valid, false otherwise + */ + bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, +- bool route, bool ipv6, bool hashed); ++ bool route); ++ ++#ifdef IPA_VALIDATE + + /** + * ipa_cmd_data_valid() - Validate command-realted configuration is valid +@@ -82,13 +80,6 @@ bool ipa_cmd_data_valid(struct ipa *ipa); + + #else /* !IPA_VALIDATE */ + +-static inline bool ipa_cmd_table_valid(struct ipa *ipa, +- const struct ipa_mem *mem, bool route, +- bool ipv6, bool hashed) +-{ +- return true; +-} +- + static inline bool ipa_cmd_data_valid(struct ipa *ipa) + { + return true; +diff --git a/drivers/net/ipa/ipa_data-v4.11.c b/drivers/net/ipa/ipa_data-v4.11.c +index 9353efbd504fb..598b410cd7ab4 100644 +--- a/drivers/net/ipa/ipa_data-v4.11.c ++++ b/drivers/net/ipa/ipa_data-v4.11.c +@@ -368,18 +368,13 @@ static const struct ipa_mem_data ipa_mem_data = { + static const struct ipa_interconnect_data ipa_interconnect_data[] = { + { + .name = "memory", +- .peak_bandwidth = 465000, /* 465 MBps */ +- .average_bandwidth = 80000, /* 80 MBps */ +- }, +- /* Average rate is unused for the next two interconnects */ +- { +- .name = "imem", +- .peak_bandwidth = 68570, /* 68.57 MBps */ +- .average_bandwidth = 80000, /* 80 MBps (unused?) */ ++ .peak_bandwidth = 600000, /* 600 MBps */ ++ .average_bandwidth = 150000, /* 150 MBps */ + }, ++ /* Average rate is unused for the next interconnect */ + { + .name = "config", +- .peak_bandwidth = 30000, /* 30 MBps */ ++ .peak_bandwidth = 74000, /* 74 MBps */ + .average_bandwidth = 0, /* unused */ + }, + }; +diff --git a/drivers/net/ipa/ipa_data-v4.9.c b/drivers/net/ipa/ipa_data-v4.9.c +index 798d43e1eb133..4cce5dce92158 100644 +--- a/drivers/net/ipa/ipa_data-v4.9.c ++++ b/drivers/net/ipa/ipa_data-v4.9.c +@@ -416,18 +416,13 @@ static const struct ipa_mem_data ipa_mem_data = { + /* Interconnect rates are in 1000 byte/second units */ + static const struct ipa_interconnect_data ipa_interconnect_data[] = { + { +- .name = "ipa_to_llcc", ++ .name = "memory", + .peak_bandwidth = 600000, /* 600 MBps */ + .average_bandwidth = 150000, /* 150 MBps */ + }, +- { +- .name = "llcc_to_ebi1", +- .peak_bandwidth = 1804000, /* 1.804 GBps */ +- .average_bandwidth = 150000, /* 150 MBps */ +- }, + /* Average rate is unused for the next interconnect */ + { +- .name = "appss_to_ipa", ++ .name = "config", + .peak_bandwidth = 74000, /* 74 MBps */ + .average_bandwidth = 0, /* unused */ + }, +diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c +index c617a9156f26d..c607ebec74567 100644 +--- a/drivers/net/ipa/ipa_table.c ++++ b/drivers/net/ipa/ipa_table.c +@@ -120,8 +120,6 @@ + */ + #define IPA_ZERO_RULE_SIZE (2 * sizeof(__le32)) + +-#ifdef IPA_VALIDATE +- + /* Check things that can be validated at build time. */ + static void ipa_table_validate_build(void) + { +@@ -161,7 +159,7 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route) + else + size = (1 + IPA_FILTER_COUNT_MAX) * sizeof(__le64); + +- if (!ipa_cmd_table_valid(ipa, mem, route, ipv6, hashed)) ++ if (!ipa_cmd_table_valid(ipa, mem, route)) + return false; + + /* mem->size >= size is sufficient, but we'll demand more */ +@@ -169,7 +167,7 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route) + return true; + + /* Hashed table regions can be zero size if hashing is not supported */ +- if (hashed && !mem->size) ++ if (ipa_table_hash_support(ipa) && !mem->size) + return true; + + dev_err(dev, "%s table region %u size 0x%02x, expected 0x%02x\n", +@@ -183,14 +181,22 @@ bool ipa_table_valid(struct ipa *ipa) + { + bool valid; + +- valid = ipa_table_valid_one(IPA_MEM_V4_FILTER, false); +- valid = valid && ipa_table_valid_one(IPA_MEM_V4_FILTER_HASHED, false); +- valid = valid && ipa_table_valid_one(IPA_MEM_V6_FILTER, false); +- valid = valid && ipa_table_valid_one(IPA_MEM_V6_FILTER_HASHED, false); +- valid = valid && ipa_table_valid_one(IPA_MEM_V4_ROUTE, true); +- valid = valid && ipa_table_valid_one(IPA_MEM_V4_ROUTE_HASHED, true); +- valid = valid && ipa_table_valid_one(IPA_MEM_V6_ROUTE, true); +- valid = valid && ipa_table_valid_one(IPA_MEM_V6_ROUTE_HASHED, true); ++ valid = ipa_table_valid_one(ipa, IPA_MEM_V4_FILTER, false); ++ valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_FILTER, false); ++ valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V4_ROUTE, true); ++ valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_ROUTE, true); ++ ++ if (!ipa_table_hash_support(ipa)) ++ return valid; ++ ++ valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V4_FILTER_HASHED, ++ false); ++ valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_FILTER_HASHED, ++ false); ++ valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V4_ROUTE_HASHED, ++ true); ++ valid = valid && ipa_table_valid_one(ipa, IPA_MEM_V6_ROUTE_HASHED, ++ true); + + return valid; + } +@@ -217,14 +223,6 @@ bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_map) + return true; + } + +-#else /* !IPA_VALIDATE */ +-static void ipa_table_validate_build(void) +- +-{ +-} +- +-#endif /* !IPA_VALIDATE */ +- + /* Zero entry count means no table, so just return a 0 address */ + static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count) + { +diff --git a/drivers/net/ipa/ipa_table.h b/drivers/net/ipa/ipa_table.h +index 1e2be9fce2f81..b6a9a0d79d68e 100644 +--- a/drivers/net/ipa/ipa_table.h ++++ b/drivers/net/ipa/ipa_table.h +@@ -16,8 +16,6 @@ struct ipa; + /* The maximum number of route table entries (IPv4, IPv6; hashed or not) */ + #define IPA_ROUTE_COUNT_MAX 15 + +-#ifdef IPA_VALIDATE +- + /** + * ipa_table_valid() - Validate route and filter table memory regions + * @ipa: IPA pointer +@@ -35,20 +33,6 @@ bool ipa_table_valid(struct ipa *ipa); + */ + bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_mask); + +-#else /* !IPA_VALIDATE */ +- +-static inline bool ipa_table_valid(struct ipa *ipa) +-{ +- return true; +-} +- +-static inline bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_mask) +-{ +- return true; +-} +- +-#endif /* !IPA_VALIDATE */ +- + /** + * ipa_table_hash_support() - Return true if hashed tables are supported + * @ipa: IPA pointer +diff --git a/drivers/net/phy/dp83822.c b/drivers/net/phy/dp83822.c +index f7a2ec150e542..211b5476a6f51 100644 +--- a/drivers/net/phy/dp83822.c ++++ b/drivers/net/phy/dp83822.c +@@ -326,11 +326,9 @@ static irqreturn_t dp83822_handle_interrupt(struct phy_device *phydev) + + static int dp8382x_disable_wol(struct phy_device *phydev) + { +- int value = DP83822_WOL_EN | DP83822_WOL_MAGIC_EN | +- DP83822_WOL_SECURE_ON; +- +- return phy_clear_bits_mmd(phydev, DP83822_DEVADDR, +- MII_DP83822_WOL_CFG, value); ++ return phy_clear_bits_mmd(phydev, DP83822_DEVADDR, MII_DP83822_WOL_CFG, ++ DP83822_WOL_EN | DP83822_WOL_MAGIC_EN | ++ DP83822_WOL_SECURE_ON); + } + + static int dp83822_read_status(struct phy_device *phydev) +diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +index b4885a700296e..b0a4ca3559fd8 100644 +--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c ++++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +@@ -3351,7 +3351,8 @@ found: + "Found block at %x: code=%d ref=%d length=%d major=%d minor=%d\n", + cptr, code, reference, length, major, minor); + if ((!AR_SREV_9485(ah) && length >= 1024) || +- (AR_SREV_9485(ah) && length > EEPROM_DATA_LEN_9485)) { ++ (AR_SREV_9485(ah) && length > EEPROM_DATA_LEN_9485) || ++ (length > cptr)) { + ath_dbg(common, EEPROM, "Skipping bad header\n"); + cptr -= COMP_HDR_LEN; + continue; +diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c +index 2ca3b86714a9d..172081ffe4774 100644 +--- a/drivers/net/wireless/ath/ath9k/hw.c ++++ b/drivers/net/wireless/ath/ath9k/hw.c +@@ -1621,7 +1621,6 @@ static void ath9k_hw_apply_gpio_override(struct ath_hw *ah) + ath9k_hw_gpio_request_out(ah, i, NULL, + AR_GPIO_OUTPUT_MUX_AS_OUTPUT); + ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i))); +- ath9k_hw_gpio_free(ah, i); + } + } + +@@ -2728,14 +2727,17 @@ static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah, u32 gpio, u32 type) + static void ath9k_hw_gpio_cfg_soc(struct ath_hw *ah, u32 gpio, bool out, + const char *label) + { ++ int err; ++ + if (ah->caps.gpio_requested & BIT(gpio)) + return; + +- /* may be requested by BSP, free anyway */ +- gpio_free(gpio); +- +- if (gpio_request_one(gpio, out ? GPIOF_OUT_INIT_LOW : GPIOF_IN, label)) ++ err = gpio_request_one(gpio, out ? GPIOF_OUT_INIT_LOW : GPIOF_IN, label); ++ if (err) { ++ ath_err(ath9k_hw_common(ah), "request GPIO%d failed:%d\n", ++ gpio, err); + return; ++ } + + ah->caps.gpio_requested |= BIT(gpio); + } +diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c +index d202f2128df23..67f4db662402b 100644 +--- a/drivers/net/wireless/ath/wcn36xx/main.c ++++ b/drivers/net/wireless/ath/wcn36xx/main.c +@@ -408,13 +408,14 @@ static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed) + wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n", + ch); + +- if (wcn->sw_scan_opchannel == ch) { ++ if (wcn->sw_scan_opchannel == ch && wcn->sw_scan_channel) { + /* If channel is the initial operating channel, we may + * want to receive/transmit regular data packets, then + * simply stop the scan session and exit PS mode. + */ + wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN, + wcn->sw_scan_vif); ++ wcn->sw_scan_channel = 0; + } else if (wcn->sw_scan) { + /* A scan is ongoing, do not change the operating + * channel, but start a scan session on the channel. +@@ -422,6 +423,7 @@ static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed) + wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN, + wcn->sw_scan_vif); + wcn36xx_smd_start_scan(wcn, ch); ++ wcn->sw_scan_channel = ch; + } else { + wcn36xx_change_opchannel(wcn, ch); + } +@@ -702,6 +704,7 @@ static void wcn36xx_sw_scan_start(struct ieee80211_hw *hw, + + wcn->sw_scan = true; + wcn->sw_scan_vif = vif; ++ wcn->sw_scan_channel = 0; + if (vif_priv->sta_assoc) + wcn->sw_scan_opchannel = WCN36XX_HW_CHANNEL(wcn); + else +diff --git a/drivers/net/wireless/ath/wcn36xx/txrx.c b/drivers/net/wireless/ath/wcn36xx/txrx.c +index 1b831157ede17..cab196bb38cd4 100644 +--- a/drivers/net/wireless/ath/wcn36xx/txrx.c ++++ b/drivers/net/wireless/ath/wcn36xx/txrx.c +@@ -287,6 +287,10 @@ int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb) + status.rate_idx = 0; + } + ++ if (ieee80211_is_beacon(hdr->frame_control) || ++ ieee80211_is_probe_resp(hdr->frame_control)) ++ status.boottime_ns = ktime_get_boottime_ns(); ++ + memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); + + if (ieee80211_is_beacon(hdr->frame_control)) { +diff --git a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h +index 6121d8a5641ab..0feb235b5a426 100644 +--- a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h ++++ b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h +@@ -246,6 +246,7 @@ struct wcn36xx { + struct cfg80211_scan_request *scan_req; + bool sw_scan; + u8 sw_scan_opchannel; ++ u8 sw_scan_channel; + struct ieee80211_vif *sw_scan_vif; + struct mutex scan_lock; + bool scan_aborted; +diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h b/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h +index b2605aefc2909..8b200379f7c20 100644 +--- a/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h ++++ b/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h +@@ -1,6 +1,6 @@ + /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ + /* +- * Copyright (C) 2012-2014, 2018-2020 Intel Corporation ++ * Copyright (C) 2012-2014, 2018-2021 Intel Corporation + * Copyright (C) 2013-2015 Intel Mobile Communications GmbH + * Copyright (C) 2016-2017 Intel Deutschland GmbH + */ +@@ -874,7 +874,7 @@ struct iwl_scan_probe_params_v3 { + u8 reserved; + struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX]; + __le32 short_ssid[SCAN_SHORT_SSID_MAX_SIZE]; +- u8 bssid_array[ETH_ALEN][SCAN_BSSID_MAX_SIZE]; ++ u8 bssid_array[SCAN_BSSID_MAX_SIZE][ETH_ALEN]; + } __packed; /* SCAN_PROBE_PARAMS_API_S_VER_3 */ + + /** +@@ -894,7 +894,7 @@ struct iwl_scan_probe_params_v4 { + __le16 reserved; + struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX]; + __le32 short_ssid[SCAN_SHORT_SSID_MAX_SIZE]; +- u8 bssid_array[ETH_ALEN][SCAN_BSSID_MAX_SIZE]; ++ u8 bssid_array[SCAN_BSSID_MAX_SIZE][ETH_ALEN]; + } __packed; /* SCAN_PROBE_PARAMS_API_S_VER_4 */ + + #define SCAN_MAX_NUM_CHANS_V3 67 +diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +index df7c55e06f54e..a13fe01e487b9 100644 +--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c ++++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +@@ -2321,7 +2321,7 @@ static void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt, + return; + + if (dump_data->monitor_only) +- dump_mask &= IWL_FW_ERROR_DUMP_FW_MONITOR; ++ dump_mask &= BIT(IWL_FW_ERROR_DUMP_FW_MONITOR); + + fw_error_dump.trans_ptr = iwl_trans_dump_data(fwrt->trans, dump_mask); + file_len = le32_to_cpu(dump_file->file_len); +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c +index fd5e089616515..7f0c821898082 100644 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c +@@ -1005,8 +1005,10 @@ int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm, + return -ENOMEM; + + #ifdef CONFIG_IWLWIFI_DEBUGFS +- if (mvm->beacon_inject_active) ++ if (mvm->beacon_inject_active) { ++ dev_kfree_skb(beacon); + return -EBUSY; ++ } + #endif + + ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon); +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +index 70ebecb73c244..79f44435972e4 100644 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +@@ -2987,16 +2987,20 @@ static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, + void *_data) + { + struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; ++ const struct cfg80211_bss_ies *ies; + const struct element *elem; + +- elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, bss->ies->data, +- bss->ies->len); ++ rcu_read_lock(); ++ ies = rcu_dereference(bss->ies); ++ elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, ++ ies->len); + + if (!elem || elem->datalen < 10 || + !(elem->data[10] & + WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { + data->tolerated = false; + } ++ rcu_read_unlock(); + } + + static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c +index 20e8d343a9501..b637cf9d85fd7 100644 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c +@@ -792,10 +792,26 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg, + + mvm->fw_restart = iwlwifi_mod_params.fw_restart ? -1 : 0; + +- mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE; +- mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE; +- mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE; +- mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE; ++ if (iwl_mvm_has_new_tx_api(mvm)) { ++ /* ++ * If we have the new TX/queue allocation API initialize them ++ * all to invalid numbers. We'll rewrite the ones that we need ++ * later, but that doesn't happen for all of them all of the ++ * time (e.g. P2P Device is optional), and if a dynamic queue ++ * ends up getting number 2 (IWL_MVM_DQA_P2P_DEVICE_QUEUE) then ++ * iwl_mvm_is_static_queue() erroneously returns true, and we ++ * might have things getting stuck. ++ */ ++ mvm->aux_queue = IWL_MVM_INVALID_QUEUE; ++ mvm->snif_queue = IWL_MVM_INVALID_QUEUE; ++ mvm->probe_queue = IWL_MVM_INVALID_QUEUE; ++ mvm->p2p_dev_queue = IWL_MVM_INVALID_QUEUE; ++ } else { ++ mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE; ++ mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE; ++ mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE; ++ mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE; ++ } + + mvm->sf_state = SF_UNINIT; + if (iwl_mvm_has_unified_ucode(mvm)) +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c +index 0368b7101222c..2d600a8b20ed7 100644 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c +@@ -1648,7 +1648,7 @@ iwl_mvm_umac_scan_cfg_channels_v6(struct iwl_mvm *mvm, + struct iwl_scan_channel_cfg_umac *cfg = &cp->channel_config[i]; + u32 n_aps_flag = + iwl_mvm_scan_ch_n_aps_flag(vif_type, +- cfg->v2.channel_num); ++ channels[i]->hw_value); + + cfg->flags = cpu_to_le32(flags | n_aps_flag); + cfg->v2.channel_num = channels[i]->hw_value; +@@ -2368,14 +2368,17 @@ static int iwl_mvm_scan_umac_v14(struct iwl_mvm *mvm, struct ieee80211_vif *vif, + if (ret) + return ret; + +- iwl_mvm_scan_umac_fill_probe_p_v4(params, &scan_p->probe_params, +- &bitmap_ssid); + if (!params->scan_6ghz) { ++ iwl_mvm_scan_umac_fill_probe_p_v4(params, &scan_p->probe_params, ++ &bitmap_ssid); + iwl_mvm_scan_umac_fill_ch_p_v6(mvm, params, vif, +- &scan_p->channel_params, bitmap_ssid); ++ &scan_p->channel_params, bitmap_ssid); + + return 0; ++ } else { ++ pb->preq = params->preq; + } ++ + cp->flags = iwl_mvm_scan_umac_chan_flags_v2(mvm, params, vif); + cp->n_aps_override[0] = IWL_SCAN_ADWELL_N_APS_GO_FRIENDLY; + cp->n_aps_override[1] = IWL_SCAN_ADWELL_N_APS_SOCIAL_CHS; +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c +index 9c45a64c50094..252b81b1dc8cf 100644 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c +@@ -316,8 +316,9 @@ static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue, + } + + static int iwl_mvm_disable_txq(struct iwl_mvm *mvm, struct ieee80211_sta *sta, +- int queue, u8 tid, u8 flags) ++ u16 *queueptr, u8 tid, u8 flags) + { ++ int queue = *queueptr; + struct iwl_scd_txq_cfg_cmd cmd = { + .scd_queue = queue, + .action = SCD_CFG_DISABLE_QUEUE, +@@ -326,6 +327,7 @@ static int iwl_mvm_disable_txq(struct iwl_mvm *mvm, struct ieee80211_sta *sta, + + if (iwl_mvm_has_new_tx_api(mvm)) { + iwl_trans_txq_free(mvm->trans, queue); ++ *queueptr = IWL_MVM_INVALID_QUEUE; + + return 0; + } +@@ -487,6 +489,7 @@ static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue, + u8 sta_id, tid; + unsigned long disable_agg_tids = 0; + bool same_sta; ++ u16 queue_tmp = queue; + int ret; + + lockdep_assert_held(&mvm->mutex); +@@ -509,7 +512,7 @@ static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue, + iwl_mvm_invalidate_sta_queue(mvm, queue, + disable_agg_tids, false); + +- ret = iwl_mvm_disable_txq(mvm, old_sta, queue, tid, 0); ++ ret = iwl_mvm_disable_txq(mvm, old_sta, &queue_tmp, tid, 0); + if (ret) { + IWL_ERR(mvm, + "Failed to free inactive queue %d (ret=%d)\n", +@@ -1184,6 +1187,7 @@ static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm, + unsigned int wdg_timeout = + iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); + int queue = -1; ++ u16 queue_tmp; + unsigned long disable_agg_tids = 0; + enum iwl_mvm_agg_state queue_state; + bool shared_queue = false, inc_ssn; +@@ -1332,7 +1336,8 @@ static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm, + return 0; + + out_err: +- iwl_mvm_disable_txq(mvm, sta, queue, tid, 0); ++ queue_tmp = queue; ++ iwl_mvm_disable_txq(mvm, sta, &queue_tmp, tid, 0); + + return ret; + } +@@ -1779,7 +1784,7 @@ static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, + if (mvm_sta->tid_data[i].txq_id == IWL_MVM_INVALID_QUEUE) + continue; + +- iwl_mvm_disable_txq(mvm, sta, mvm_sta->tid_data[i].txq_id, i, ++ iwl_mvm_disable_txq(mvm, sta, &mvm_sta->tid_data[i].txq_id, i, + 0); + mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE; + } +@@ -1987,7 +1992,7 @@ static int iwl_mvm_add_int_sta_with_queue(struct iwl_mvm *mvm, int macidx, + ret = iwl_mvm_add_int_sta_common(mvm, sta, addr, macidx, maccolor); + if (ret) { + if (!iwl_mvm_has_new_tx_api(mvm)) +- iwl_mvm_disable_txq(mvm, NULL, *queue, ++ iwl_mvm_disable_txq(mvm, NULL, queue, + IWL_MAX_TID_COUNT, 0); + return ret; + } +@@ -2060,7 +2065,7 @@ int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) + if (WARN_ON_ONCE(mvm->snif_sta.sta_id == IWL_MVM_INVALID_STA)) + return -EINVAL; + +- iwl_mvm_disable_txq(mvm, NULL, mvm->snif_queue, IWL_MAX_TID_COUNT, 0); ++ iwl_mvm_disable_txq(mvm, NULL, &mvm->snif_queue, IWL_MAX_TID_COUNT, 0); + ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); + if (ret) + IWL_WARN(mvm, "Failed sending remove station\n"); +@@ -2077,7 +2082,7 @@ int iwl_mvm_rm_aux_sta(struct iwl_mvm *mvm) + if (WARN_ON_ONCE(mvm->aux_sta.sta_id == IWL_MVM_INVALID_STA)) + return -EINVAL; + +- iwl_mvm_disable_txq(mvm, NULL, mvm->aux_queue, IWL_MAX_TID_COUNT, 0); ++ iwl_mvm_disable_txq(mvm, NULL, &mvm->aux_queue, IWL_MAX_TID_COUNT, 0); + ret = iwl_mvm_rm_sta_common(mvm, mvm->aux_sta.sta_id); + if (ret) + IWL_WARN(mvm, "Failed sending remove station\n"); +@@ -2173,7 +2178,7 @@ static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm, + struct ieee80211_vif *vif) + { + struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); +- int queue; ++ u16 *queueptr, queue; + + lockdep_assert_held(&mvm->mutex); + +@@ -2182,10 +2187,10 @@ static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm, + switch (vif->type) { + case NL80211_IFTYPE_AP: + case NL80211_IFTYPE_ADHOC: +- queue = mvm->probe_queue; ++ queueptr = &mvm->probe_queue; + break; + case NL80211_IFTYPE_P2P_DEVICE: +- queue = mvm->p2p_dev_queue; ++ queueptr = &mvm->p2p_dev_queue; + break; + default: + WARN(1, "Can't free bcast queue on vif type %d\n", +@@ -2193,7 +2198,8 @@ static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm, + return; + } + +- iwl_mvm_disable_txq(mvm, NULL, queue, IWL_MAX_TID_COUNT, 0); ++ queue = *queueptr; ++ iwl_mvm_disable_txq(mvm, NULL, queueptr, IWL_MAX_TID_COUNT, 0); + if (iwl_mvm_has_new_tx_api(mvm)) + return; + +@@ -2428,7 +2434,7 @@ int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) + + iwl_mvm_flush_sta(mvm, &mvmvif->mcast_sta, true); + +- iwl_mvm_disable_txq(mvm, NULL, mvmvif->cab_queue, 0, 0); ++ iwl_mvm_disable_txq(mvm, NULL, &mvmvif->cab_queue, 0, 0); + + ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id); + if (ret) +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c b/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c +index d3307a11fcac4..24b658a3098aa 100644 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c +@@ -246,6 +246,18 @@ static void iwl_mvm_te_check_trigger(struct iwl_mvm *mvm, + } + } + ++static void iwl_mvm_p2p_roc_finished(struct iwl_mvm *mvm) ++{ ++ /* ++ * If the IWL_MVM_STATUS_NEED_FLUSH_P2P is already set, then the ++ * roc_done_wk is already scheduled or running, so don't schedule it ++ * again to avoid a race where the roc_done_wk clears this bit after ++ * it is set here, affecting the next run of the roc_done_wk. ++ */ ++ if (!test_and_set_bit(IWL_MVM_STATUS_NEED_FLUSH_P2P, &mvm->status)) ++ iwl_mvm_roc_finished(mvm); ++} ++ + /* + * Handles a FW notification for an event that is known to the driver. + * +@@ -297,8 +309,7 @@ static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm, + switch (te_data->vif->type) { + case NL80211_IFTYPE_P2P_DEVICE: + ieee80211_remain_on_channel_expired(mvm->hw); +- set_bit(IWL_MVM_STATUS_NEED_FLUSH_P2P, &mvm->status); +- iwl_mvm_roc_finished(mvm); ++ iwl_mvm_p2p_roc_finished(mvm); + break; + case NL80211_IFTYPE_STATION: + /* +@@ -674,8 +685,7 @@ static bool __iwl_mvm_remove_time_event(struct iwl_mvm *mvm, + /* Session protection is still ongoing. Cancel it */ + iwl_mvm_cancel_session_protection(mvm, mvmvif, id); + if (iftype == NL80211_IFTYPE_P2P_DEVICE) { +- set_bit(IWL_MVM_STATUS_NEED_FLUSH_P2P, &mvm->status); +- iwl_mvm_roc_finished(mvm); ++ iwl_mvm_p2p_roc_finished(mvm); + } + } + return false; +@@ -842,8 +852,7 @@ void iwl_mvm_rx_session_protect_notif(struct iwl_mvm *mvm, + /* End TE, notify mac80211 */ + mvmvif->time_event_data.id = SESSION_PROTECT_CONF_MAX_ID; + ieee80211_remain_on_channel_expired(mvm->hw); +- set_bit(IWL_MVM_STATUS_NEED_FLUSH_P2P, &mvm->status); +- iwl_mvm_roc_finished(mvm); ++ iwl_mvm_p2p_roc_finished(mvm); + } else if (le32_to_cpu(notif->start)) { + if (WARN_ON(mvmvif->time_event_data.id != + le32_to_cpu(notif->conf_id))) +@@ -1004,14 +1013,13 @@ void iwl_mvm_stop_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif) + if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { + iwl_mvm_cancel_session_protection(mvm, mvmvif, + mvmvif->time_event_data.id); +- set_bit(IWL_MVM_STATUS_NEED_FLUSH_P2P, &mvm->status); ++ iwl_mvm_p2p_roc_finished(mvm); + } else { + iwl_mvm_remove_aux_roc_te(mvm, mvmvif, + &mvmvif->time_event_data); ++ iwl_mvm_roc_finished(mvm); + } + +- iwl_mvm_roc_finished(mvm); +- + return; + } + +@@ -1025,12 +1033,11 @@ void iwl_mvm_stop_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif) + + if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) { + iwl_mvm_remove_time_event(mvm, mvmvif, te_data); +- set_bit(IWL_MVM_STATUS_NEED_FLUSH_P2P, &mvm->status); ++ iwl_mvm_p2p_roc_finished(mvm); + } else { + iwl_mvm_remove_aux_roc_te(mvm, mvmvif, te_data); ++ iwl_mvm_roc_finished(mvm); + } +- +- iwl_mvm_roc_finished(mvm); + } + + void iwl_mvm_remove_csa_period(struct iwl_mvm *mvm, +diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +index 4f6f4b2720f01..ff7ca3c57f34d 100644 +--- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c ++++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +@@ -487,6 +487,9 @@ void iwl_pcie_free_rbs_pool(struct iwl_trans *trans) + struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + int i; + ++ if (!trans_pcie->rx_pool) ++ return; ++ + for (i = 0; i < RX_POOL_SIZE(trans_pcie->num_rx_bufs); i++) { + if (!trans_pcie->rx_pool[i].page) + continue; +@@ -1062,7 +1065,7 @@ static int _iwl_pcie_rx_init(struct iwl_trans *trans) + INIT_LIST_HEAD(&rba->rbd_empty); + spin_unlock_bh(&rba->lock); + +- /* free all first - we might be reconfigured for a different size */ ++ /* free all first - we overwrite everything here */ + iwl_pcie_free_rbs_pool(trans); + + for (i = 0; i < RX_QUEUE_SIZE; i++) +diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +index bee6b45742268..65cc25cbb9ec0 100644 +--- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c ++++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +@@ -1866,6 +1866,9 @@ static void iwl_trans_pcie_configure(struct iwl_trans *trans, + { + struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + ++ /* free all first - we might be reconfigured for a different size */ ++ iwl_pcie_free_rbs_pool(trans); ++ + trans->txqs.cmd.q_id = trans_cfg->cmd_queue; + trans->txqs.cmd.fifo = trans_cfg->cmd_fifo; + trans->txqs.cmd.wdg_timeout = trans_cfg->cmd_q_wdg_timeout; +diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +index 01735776345a9..7ddce3c3f0c48 100644 +--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h ++++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +@@ -1378,6 +1378,8 @@ struct rtl8xxxu_priv { + u8 no_pape:1; + u8 int_buf[USB_INTR_CONTENT_LENGTH]; + u8 rssi_level; ++ DECLARE_BITMAP(tx_aggr_started, IEEE80211_NUM_TIDS); ++ DECLARE_BITMAP(tid_tx_operational, IEEE80211_NUM_TIDS); + /* + * Only one virtual interface permitted because only STA mode + * is supported and no iface_combinations are provided. +diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +index ac1061caacd65..3285a91efb91e 100644 +--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c ++++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +@@ -4805,6 +4805,8 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr, + struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info); + struct rtl8xxxu_priv *priv = hw->priv; + struct device *dev = &priv->udev->dev; ++ u8 *qc = ieee80211_get_qos_ctl(hdr); ++ u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; + u32 rate; + u16 rate_flags = tx_info->control.rates[0].flags; + u16 seq_number; +@@ -4828,7 +4830,7 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr, + + tx_desc->txdw3 = cpu_to_le32((u32)seq_number << TXDESC32_SEQ_SHIFT); + +- if (ampdu_enable) ++ if (ampdu_enable && test_bit(tid, priv->tid_tx_operational)) + tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_ENABLE); + else + tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_BREAK); +@@ -4876,6 +4878,8 @@ rtl8xxxu_fill_txdesc_v2(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr, + struct rtl8xxxu_priv *priv = hw->priv; + struct device *dev = &priv->udev->dev; + struct rtl8xxxu_txdesc40 *tx_desc40; ++ u8 *qc = ieee80211_get_qos_ctl(hdr); ++ u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; + u32 rate; + u16 rate_flags = tx_info->control.rates[0].flags; + u16 seq_number; +@@ -4902,7 +4906,7 @@ rtl8xxxu_fill_txdesc_v2(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr, + + tx_desc40->txdw9 = cpu_to_le32((u32)seq_number << TXDESC40_SEQ_SHIFT); + +- if (ampdu_enable) ++ if (ampdu_enable && test_bit(tid, priv->tid_tx_operational)) + tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_ENABLE); + else + tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_BREAK); +@@ -5015,12 +5019,19 @@ static void rtl8xxxu_tx(struct ieee80211_hw *hw, + if (ieee80211_is_data_qos(hdr->frame_control) && sta) { + if (sta->ht_cap.ht_supported) { + u32 ampdu, val32; ++ u8 *qc = ieee80211_get_qos_ctl(hdr); ++ u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; + + ampdu = (u32)sta->ht_cap.ampdu_density; + val32 = ampdu << TXDESC_AMPDU_DENSITY_SHIFT; + tx_desc->txdw2 |= cpu_to_le32(val32); + + ampdu_enable = true; ++ ++ if (!test_bit(tid, priv->tx_aggr_started) && ++ !(skb->protocol == cpu_to_be16(ETH_P_PAE))) ++ if (!ieee80211_start_tx_ba_session(sta, tid, 0)) ++ set_bit(tid, priv->tx_aggr_started); + } + } + +@@ -6096,6 +6107,7 @@ rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + struct device *dev = &priv->udev->dev; + u8 ampdu_factor, ampdu_density; + struct ieee80211_sta *sta = params->sta; ++ u16 tid = params->tid; + enum ieee80211_ampdu_mlme_action action = params->action; + + switch (action) { +@@ -6108,17 +6120,20 @@ rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + dev_dbg(dev, + "Changed HT: ampdu_factor %02x, ampdu_density %02x\n", + ampdu_factor, ampdu_density); +- break; ++ return IEEE80211_AMPDU_TX_START_IMMEDIATE; ++ case IEEE80211_AMPDU_TX_STOP_CONT: + case IEEE80211_AMPDU_TX_STOP_FLUSH: +- dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH\n", __func__); +- rtl8xxxu_set_ampdu_factor(priv, 0); +- rtl8xxxu_set_ampdu_min_space(priv, 0); +- break; + case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: +- dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH_CONT\n", +- __func__); ++ dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_STOP\n", __func__); + rtl8xxxu_set_ampdu_factor(priv, 0); + rtl8xxxu_set_ampdu_min_space(priv, 0); ++ clear_bit(tid, priv->tx_aggr_started); ++ clear_bit(tid, priv->tid_tx_operational); ++ ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); ++ break; ++ case IEEE80211_AMPDU_TX_OPERATIONAL: ++ dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_OPERATIONAL\n", __func__); ++ set_bit(tid, priv->tid_tx_operational); + break; + case IEEE80211_AMPDU_RX_START: + dev_dbg(dev, "%s: IEEE80211_AMPDU_RX_START\n", __func__); +diff --git a/drivers/net/wireless/realtek/rtw88/Makefile b/drivers/net/wireless/realtek/rtw88/Makefile +index c0e4b111c8b4e..73d6807a8cdfb 100644 +--- a/drivers/net/wireless/realtek/rtw88/Makefile ++++ b/drivers/net/wireless/realtek/rtw88/Makefile +@@ -15,9 +15,9 @@ rtw88_core-y += main.o \ + ps.o \ + sec.o \ + bf.o \ +- wow.o \ + regd.o + ++rtw88_core-$(CONFIG_PM) += wow.o + + obj-$(CONFIG_RTW88_8822B) += rtw88_8822b.o + rtw88_8822b-objs := rtw8822b.o rtw8822b_table.o +diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c +index 3bfa5ecc00537..e6399519584bd 100644 +--- a/drivers/net/wireless/realtek/rtw88/fw.c ++++ b/drivers/net/wireless/realtek/rtw88/fw.c +@@ -819,7 +819,7 @@ static u16 rtw_get_rsvd_page_probe_req_size(struct rtw_dev *rtwdev, + continue; + if ((!ssid && !rsvd_pkt->ssid) || + rtw_ssid_equal(rsvd_pkt->ssid, ssid)) +- size = rsvd_pkt->skb->len; ++ size = rsvd_pkt->probe_req_size; + } + + return size; +@@ -1047,6 +1047,8 @@ static struct sk_buff *rtw_get_rsvd_page_skb(struct ieee80211_hw *hw, + ssid->ssid_len, 0); + else + skb_new = ieee80211_probereq_get(hw, vif->addr, NULL, 0, 0); ++ if (skb_new) ++ rsvd_pkt->probe_req_size = (u16)skb_new->len; + break; + case RSVD_NLO_INFO: + skb_new = rtw_nlo_info_get(hw); +@@ -1643,6 +1645,7 @@ int rtw_fw_dump_fifo(struct rtw_dev *rtwdev, u8 fifo_sel, u32 addr, u32 size, + static void __rtw_fw_update_pkt(struct rtw_dev *rtwdev, u8 pkt_id, u16 size, + u8 location) + { ++ struct rtw_chip_info *chip = rtwdev->chip; + u8 h2c_pkt[H2C_PKT_SIZE] = {0}; + u16 total_size = H2C_PKT_HDR_SIZE + H2C_PKT_UPDATE_PKT_LEN; + +@@ -1653,6 +1656,7 @@ static void __rtw_fw_update_pkt(struct rtw_dev *rtwdev, u8 pkt_id, u16 size, + UPDATE_PKT_SET_LOCATION(h2c_pkt, location); + + /* include txdesc size */ ++ size += chip->tx_pkt_desc_sz; + UPDATE_PKT_SET_SIZE(h2c_pkt, size); + + rtw_fw_send_h2c_packet(rtwdev, h2c_pkt); +@@ -1662,7 +1666,7 @@ void rtw_fw_update_pkt_probe_req(struct rtw_dev *rtwdev, + struct cfg80211_ssid *ssid) + { + u8 loc; +- u32 size; ++ u16 size; + + loc = rtw_get_rsvd_page_probe_req_location(rtwdev, ssid); + if (!loc) { +diff --git a/drivers/net/wireless/realtek/rtw88/fw.h b/drivers/net/wireless/realtek/rtw88/fw.h +index a8a7162fbe64c..a3a28ac6f1ded 100644 +--- a/drivers/net/wireless/realtek/rtw88/fw.h ++++ b/drivers/net/wireless/realtek/rtw88/fw.h +@@ -147,6 +147,7 @@ struct rtw_rsvd_page { + u8 page; + bool add_txdesc; + struct cfg80211_ssid *ssid; ++ u16 probe_req_size; + }; + + enum rtw_keep_alive_pkt_type { +diff --git a/drivers/net/wireless/realtek/rtw88/wow.c b/drivers/net/wireless/realtek/rtw88/wow.c +index fc9544f4e5e45..bdccfa70dddc7 100644 +--- a/drivers/net/wireless/realtek/rtw88/wow.c ++++ b/drivers/net/wireless/realtek/rtw88/wow.c +@@ -283,15 +283,26 @@ static void rtw_wow_rx_dma_start(struct rtw_dev *rtwdev) + + static int rtw_wow_check_fw_status(struct rtw_dev *rtwdev, bool wow_enable) + { +- /* wait 100ms for wow firmware to finish work */ +- msleep(100); ++ int ret; ++ u8 check; ++ u32 check_dis; + + if (wow_enable) { +- if (rtw_read8(rtwdev, REG_WOWLAN_WAKE_REASON)) ++ ret = read_poll_timeout(rtw_read8, check, !check, 1000, ++ 100000, true, rtwdev, ++ REG_WOWLAN_WAKE_REASON); ++ if (ret) + goto wow_fail; + } else { +- if (rtw_read32_mask(rtwdev, REG_FE1IMR, BIT_FS_RXDONE) || +- rtw_read32_mask(rtwdev, REG_RXPKT_NUM, BIT_RW_RELEASE)) ++ ret = read_poll_timeout(rtw_read32_mask, check_dis, ++ !check_dis, 1000, 100000, true, rtwdev, ++ REG_FE1IMR, BIT_FS_RXDONE); ++ if (ret) ++ goto wow_fail; ++ ret = read_poll_timeout(rtw_read32_mask, check_dis, ++ !check_dis, 1000, 100000, false, rtwdev, ++ REG_RXPKT_NUM, BIT_RW_RELEASE); ++ if (ret) + goto wow_fail; + } + +diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c +index 1e0615b8565e7..72de88ff0d30d 100644 +--- a/drivers/nvdimm/pmem.c ++++ b/drivers/nvdimm/pmem.c +@@ -450,11 +450,11 @@ static int pmem_attach_disk(struct device *dev, + pmem->pfn_flags |= PFN_MAP; + bb_range = pmem->pgmap.range; + } else { ++ addr = devm_memremap(dev, pmem->phys_addr, ++ pmem->size, ARCH_MEMREMAP_PMEM); + if (devm_add_action_or_reset(dev, pmem_release_queue, + &pmem->pgmap)) + return -ENOMEM; +- addr = devm_memremap(dev, pmem->phys_addr, +- pmem->size, ARCH_MEMREMAP_PMEM); + bb_range.start = res->start; + bb_range.end = res->end; + } +diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c +index dfd9dec0c1f60..2f0cbaba12ac4 100644 +--- a/drivers/nvme/host/core.c ++++ b/drivers/nvme/host/core.c +@@ -1029,7 +1029,8 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) + return BLK_STS_IOERR; + } + +- cmd->common.command_id = req->tag; ++ nvme_req(req)->genctr++; ++ cmd->common.command_id = nvme_cid(req); + trace_nvme_setup_cmd(req, cmd); + return ret; + } +diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h +index 5cd1fa3b8464d..26511794629bc 100644 +--- a/drivers/nvme/host/nvme.h ++++ b/drivers/nvme/host/nvme.h +@@ -158,6 +158,7 @@ enum nvme_quirks { + struct nvme_request { + struct nvme_command *cmd; + union nvme_result result; ++ u8 genctr; + u8 retries; + u8 flags; + u16 status; +@@ -497,6 +498,49 @@ struct nvme_ctrl_ops { + int (*get_address)(struct nvme_ctrl *ctrl, char *buf, int size); + }; + ++/* ++ * nvme command_id is constructed as such: ++ * | xxxx | xxxxxxxxxxxx | ++ * gen request tag ++ */ ++#define nvme_genctr_mask(gen) (gen & 0xf) ++#define nvme_cid_install_genctr(gen) (nvme_genctr_mask(gen) << 12) ++#define nvme_genctr_from_cid(cid) ((cid & 0xf000) >> 12) ++#define nvme_tag_from_cid(cid) (cid & 0xfff) ++ ++static inline u16 nvme_cid(struct request *rq) ++{ ++ return nvme_cid_install_genctr(nvme_req(rq)->genctr) | rq->tag; ++} ++ ++static inline struct request *nvme_find_rq(struct blk_mq_tags *tags, ++ u16 command_id) ++{ ++ u8 genctr = nvme_genctr_from_cid(command_id); ++ u16 tag = nvme_tag_from_cid(command_id); ++ struct request *rq; ++ ++ rq = blk_mq_tag_to_rq(tags, tag); ++ if (unlikely(!rq)) { ++ pr_err("could not locate request for tag %#x\n", ++ tag); ++ return NULL; ++ } ++ if (unlikely(nvme_genctr_mask(nvme_req(rq)->genctr) != genctr)) { ++ dev_err(nvme_req(rq)->ctrl->device, ++ "request %#x genctr mismatch (got %#x expected %#x)\n", ++ tag, genctr, nvme_genctr_mask(nvme_req(rq)->genctr)); ++ return NULL; ++ } ++ return rq; ++} ++ ++static inline struct request *nvme_cid_to_rq(struct blk_mq_tags *tags, ++ u16 command_id) ++{ ++ return blk_mq_tag_to_rq(tags, nvme_tag_from_cid(command_id)); ++} ++ + #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS + void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj, + const char *dev_name); +@@ -594,7 +638,8 @@ static inline void nvme_put_ctrl(struct nvme_ctrl *ctrl) + + static inline bool nvme_is_aen_req(u16 qid, __u16 command_id) + { +- return !qid && command_id >= NVME_AQ_BLK_MQ_DEPTH; ++ return !qid && ++ nvme_tag_from_cid(command_id) >= NVME_AQ_BLK_MQ_DEPTH; + } + + void nvme_complete_rq(struct request *req); +diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c +index 51852085239ef..c246fdacba2e5 100644 +--- a/drivers/nvme/host/pci.c ++++ b/drivers/nvme/host/pci.c +@@ -1014,7 +1014,7 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx) + return; + } + +- req = blk_mq_tag_to_rq(nvme_queue_tagset(nvmeq), command_id); ++ req = nvme_find_rq(nvme_queue_tagset(nvmeq), command_id); + if (unlikely(!req)) { + dev_warn(nvmeq->dev->ctrl.device, + "invalid id %d completed on queue %d\n", +diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c +index 3bd9cbc80246f..a68704e39084e 100644 +--- a/drivers/nvme/host/rdma.c ++++ b/drivers/nvme/host/rdma.c +@@ -1730,10 +1730,10 @@ static void nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue, + struct request *rq; + struct nvme_rdma_request *req; + +- rq = blk_mq_tag_to_rq(nvme_rdma_tagset(queue), cqe->command_id); ++ rq = nvme_find_rq(nvme_rdma_tagset(queue), cqe->command_id); + if (!rq) { + dev_err(queue->ctrl->ctrl.device, +- "tag 0x%x on QP %#x not found\n", ++ "got bad command_id %#x on QP %#x\n", + cqe->command_id, queue->qp->qp_num); + nvme_rdma_error_recovery(queue->ctrl); + return; +diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c +index 18bd68b82d78f..48b70e5235a39 100644 +--- a/drivers/nvme/host/tcp.c ++++ b/drivers/nvme/host/tcp.c +@@ -487,11 +487,11 @@ static int nvme_tcp_process_nvme_cqe(struct nvme_tcp_queue *queue, + { + struct request *rq; + +- rq = blk_mq_tag_to_rq(nvme_tcp_tagset(queue), cqe->command_id); ++ rq = nvme_find_rq(nvme_tcp_tagset(queue), cqe->command_id); + if (!rq) { + dev_err(queue->ctrl->ctrl.device, +- "queue %d tag 0x%x not found\n", +- nvme_tcp_queue_id(queue), cqe->command_id); ++ "got bad cqe.command_id %#x on queue %d\n", ++ cqe->command_id, nvme_tcp_queue_id(queue)); + nvme_tcp_error_recovery(&queue->ctrl->ctrl); + return -EINVAL; + } +@@ -508,11 +508,11 @@ static int nvme_tcp_handle_c2h_data(struct nvme_tcp_queue *queue, + { + struct request *rq; + +- rq = blk_mq_tag_to_rq(nvme_tcp_tagset(queue), pdu->command_id); ++ rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); + if (!rq) { + dev_err(queue->ctrl->ctrl.device, +- "queue %d tag %#x not found\n", +- nvme_tcp_queue_id(queue), pdu->command_id); ++ "got bad c2hdata.command_id %#x on queue %d\n", ++ pdu->command_id, nvme_tcp_queue_id(queue)); + return -ENOENT; + } + +@@ -606,7 +606,7 @@ static int nvme_tcp_setup_h2c_data_pdu(struct nvme_tcp_request *req, + data->hdr.plen = + cpu_to_le32(data->hdr.hlen + hdgst + req->pdu_len + ddgst); + data->ttag = pdu->ttag; +- data->command_id = rq->tag; ++ data->command_id = nvme_cid(rq); + data->data_offset = cpu_to_le32(req->data_sent); + data->data_length = cpu_to_le32(req->pdu_len); + return 0; +@@ -619,11 +619,11 @@ static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue, + struct request *rq; + int ret; + +- rq = blk_mq_tag_to_rq(nvme_tcp_tagset(queue), pdu->command_id); ++ rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); + if (!rq) { + dev_err(queue->ctrl->ctrl.device, +- "queue %d tag %#x not found\n", +- nvme_tcp_queue_id(queue), pdu->command_id); ++ "got bad r2t.command_id %#x on queue %d\n", ++ pdu->command_id, nvme_tcp_queue_id(queue)); + return -ENOENT; + } + req = blk_mq_rq_to_pdu(rq); +@@ -702,17 +702,9 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, + unsigned int *offset, size_t *len) + { + struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; +- struct nvme_tcp_request *req; +- struct request *rq; +- +- rq = blk_mq_tag_to_rq(nvme_tcp_tagset(queue), pdu->command_id); +- if (!rq) { +- dev_err(queue->ctrl->ctrl.device, +- "queue %d tag %#x not found\n", +- nvme_tcp_queue_id(queue), pdu->command_id); +- return -ENOENT; +- } +- req = blk_mq_rq_to_pdu(rq); ++ struct request *rq = ++ nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id); ++ struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + + while (true) { + int recv_len, ret; +@@ -804,8 +796,8 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, + } + + if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) { +- struct request *rq = blk_mq_tag_to_rq(nvme_tcp_tagset(queue), +- pdu->command_id); ++ struct request *rq = nvme_cid_to_rq(nvme_tcp_tagset(queue), ++ pdu->command_id); + + nvme_tcp_end_request(rq, NVME_SC_SUCCESS); + queue->nr_cqe++; +diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c +index 3a17a7e26bbfc..0285ccc7541f6 100644 +--- a/drivers/nvme/target/loop.c ++++ b/drivers/nvme/target/loop.c +@@ -107,10 +107,10 @@ static void nvme_loop_queue_response(struct nvmet_req *req) + } else { + struct request *rq; + +- rq = blk_mq_tag_to_rq(nvme_loop_tagset(queue), cqe->command_id); ++ rq = nvme_find_rq(nvme_loop_tagset(queue), cqe->command_id); + if (!rq) { + dev_err(queue->ctrl->ctrl.device, +- "tag 0x%x on queue %d not found\n", ++ "got bad command_id %#x on queue %d\n", + cqe->command_id, nvme_loop_queue_idx(queue)); + return; + } +diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c +index b3bc30a04ed7c..3d87fadaa160d 100644 +--- a/drivers/nvmem/core.c ++++ b/drivers/nvmem/core.c +@@ -824,8 +824,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) + + if (nvmem->nkeepout) { + rval = nvmem_validate_keepouts(nvmem); +- if (rval) +- goto err_put_device; ++ if (rval) { ++ ida_free(&nvmem_ida, nvmem->id); ++ kfree(nvmem); ++ return ERR_PTR(rval); ++ } + } + + dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); +diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c +index 81fbad5e939df..b0ca4c6264665 100644 +--- a/drivers/nvmem/qfprom.c ++++ b/drivers/nvmem/qfprom.c +@@ -139,6 +139,9 @@ static void qfprom_disable_fuse_blowing(const struct qfprom_priv *priv, + { + int ret; + ++ writel(old->timer_val, priv->qfpconf + QFPROM_BLOW_TIMER_OFFSET); ++ writel(old->accel_val, priv->qfpconf + QFPROM_ACCEL_OFFSET); ++ + /* + * This may be a shared rail and may be able to run at a lower rate + * when we're not blowing fuses. At the moment, the regulator framework +@@ -159,9 +162,6 @@ static void qfprom_disable_fuse_blowing(const struct qfprom_priv *priv, + "Failed to set clock rate for disable (ignoring)\n"); + + clk_disable_unprepare(priv->secclk); +- +- writel(old->timer_val, priv->qfpconf + QFPROM_BLOW_TIMER_OFFSET); +- writel(old->accel_val, priv->qfpconf + QFPROM_ACCEL_OFFSET); + } + + /** +diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c +index a32e60b024b8d..6675b5e56960c 100644 +--- a/drivers/of/kobj.c ++++ b/drivers/of/kobj.c +@@ -119,7 +119,7 @@ int __of_attach_node_sysfs(struct device_node *np) + struct property *pp; + int rc; + +- if (!of_kset) ++ if (!IS_ENABLED(CONFIG_SYSFS) || !of_kset) + return 0; + + np->kobj.kset = of_kset; +diff --git a/drivers/opp/of.c b/drivers/opp/of.c +index 67f2e0710e79c..2a97c6535c4c6 100644 +--- a/drivers/opp/of.c ++++ b/drivers/opp/of.c +@@ -95,15 +95,7 @@ static struct dev_pm_opp *_find_opp_of_np(struct opp_table *opp_table, + static struct device_node *of_parse_required_opp(struct device_node *np, + int index) + { +- struct device_node *required_np; +- +- required_np = of_parse_phandle(np, "required-opps", index); +- if (unlikely(!required_np)) { +- pr_err("%s: Unable to parse required-opps: %pOF, index: %d\n", +- __func__, np, index); +- } +- +- return required_np; ++ return of_parse_phandle(np, "required-opps", index); + } + + /* The caller must call dev_pm_opp_put_opp_table() after the table is used */ +@@ -1328,7 +1320,7 @@ int of_get_required_opp_performance_state(struct device_node *np, int index) + + required_np = of_parse_required_opp(np, index); + if (!required_np) +- return -EINVAL; ++ return -ENODEV; + + opp_table = _find_table_of_opp_np(required_np); + if (IS_ERR(opp_table)) { +diff --git a/drivers/parport/ieee1284_ops.c b/drivers/parport/ieee1284_ops.c +index 2c11bd3fe1fd6..17061f1df0f44 100644 +--- a/drivers/parport/ieee1284_ops.c ++++ b/drivers/parport/ieee1284_ops.c +@@ -518,7 +518,7 @@ size_t parport_ieee1284_ecp_read_data (struct parport *port, + goto out; + + /* Yield the port for a while. */ +- if (count && dev->port->irq != PARPORT_IRQ_NONE) { ++ if (dev->port->irq != PARPORT_IRQ_NONE) { + parport_release (dev); + schedule_timeout_interruptible(msecs_to_jiffies(40)); + parport_claim_or_block (dev); +diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c +index c95ebe808f92b..fdbf051586970 100644 +--- a/drivers/pci/controller/pci-aardvark.c ++++ b/drivers/pci/controller/pci-aardvark.c +@@ -58,6 +58,7 @@ + #define PIO_COMPLETION_STATUS_CRS 2 + #define PIO_COMPLETION_STATUS_CA 4 + #define PIO_NON_POSTED_REQ BIT(10) ++#define PIO_ERR_STATUS BIT(11) + #define PIO_ADDR_LS (PIO_BASE_ADDR + 0x8) + #define PIO_ADDR_MS (PIO_BASE_ADDR + 0xc) + #define PIO_WR_DATA (PIO_BASE_ADDR + 0x10) +@@ -118,6 +119,46 @@ + #define PCIE_MSI_MASK_REG (CONTROL_BASE_ADDR + 0x5C) + #define PCIE_MSI_PAYLOAD_REG (CONTROL_BASE_ADDR + 0x9C) + ++/* PCIe window configuration */ ++#define OB_WIN_BASE_ADDR 0x4c00 ++#define OB_WIN_BLOCK_SIZE 0x20 ++#define OB_WIN_COUNT 8 ++#define OB_WIN_REG_ADDR(win, offset) (OB_WIN_BASE_ADDR + \ ++ OB_WIN_BLOCK_SIZE * (win) + \ ++ (offset)) ++#define OB_WIN_MATCH_LS(win) OB_WIN_REG_ADDR(win, 0x00) ++#define OB_WIN_ENABLE BIT(0) ++#define OB_WIN_MATCH_MS(win) OB_WIN_REG_ADDR(win, 0x04) ++#define OB_WIN_REMAP_LS(win) OB_WIN_REG_ADDR(win, 0x08) ++#define OB_WIN_REMAP_MS(win) OB_WIN_REG_ADDR(win, 0x0c) ++#define OB_WIN_MASK_LS(win) OB_WIN_REG_ADDR(win, 0x10) ++#define OB_WIN_MASK_MS(win) OB_WIN_REG_ADDR(win, 0x14) ++#define OB_WIN_ACTIONS(win) OB_WIN_REG_ADDR(win, 0x18) ++#define OB_WIN_DEFAULT_ACTIONS (OB_WIN_ACTIONS(OB_WIN_COUNT-1) + 0x4) ++#define OB_WIN_FUNC_NUM_MASK GENMASK(31, 24) ++#define OB_WIN_FUNC_NUM_SHIFT 24 ++#define OB_WIN_FUNC_NUM_ENABLE BIT(23) ++#define OB_WIN_BUS_NUM_BITS_MASK GENMASK(22, 20) ++#define OB_WIN_BUS_NUM_BITS_SHIFT 20 ++#define OB_WIN_MSG_CODE_ENABLE BIT(22) ++#define OB_WIN_MSG_CODE_MASK GENMASK(21, 14) ++#define OB_WIN_MSG_CODE_SHIFT 14 ++#define OB_WIN_MSG_PAYLOAD_LEN BIT(12) ++#define OB_WIN_ATTR_ENABLE BIT(11) ++#define OB_WIN_ATTR_TC_MASK GENMASK(10, 8) ++#define OB_WIN_ATTR_TC_SHIFT 8 ++#define OB_WIN_ATTR_RELAXED BIT(7) ++#define OB_WIN_ATTR_NOSNOOP BIT(6) ++#define OB_WIN_ATTR_POISON BIT(5) ++#define OB_WIN_ATTR_IDO BIT(4) ++#define OB_WIN_TYPE_MASK GENMASK(3, 0) ++#define OB_WIN_TYPE_SHIFT 0 ++#define OB_WIN_TYPE_MEM 0x0 ++#define OB_WIN_TYPE_IO 0x4 ++#define OB_WIN_TYPE_CONFIG_TYPE0 0x8 ++#define OB_WIN_TYPE_CONFIG_TYPE1 0x9 ++#define OB_WIN_TYPE_MSG 0xc ++ + /* LMI registers base address and register offsets */ + #define LMI_BASE_ADDR 0x6000 + #define CFG_REG (LMI_BASE_ADDR + 0x0) +@@ -166,7 +207,7 @@ + #define PCIE_CONFIG_WR_TYPE0 0xa + #define PCIE_CONFIG_WR_TYPE1 0xb + +-#define PIO_RETRY_CNT 500 ++#define PIO_RETRY_CNT 750000 /* 1.5 s */ + #define PIO_RETRY_DELAY 2 /* 2 us*/ + + #define LINK_WAIT_MAX_RETRIES 10 +@@ -180,8 +221,16 @@ + struct advk_pcie { + struct platform_device *pdev; + void __iomem *base; ++ struct { ++ phys_addr_t match; ++ phys_addr_t remap; ++ phys_addr_t mask; ++ u32 actions; ++ } wins[OB_WIN_COUNT]; ++ u8 wins_count; + struct irq_domain *irq_domain; + struct irq_chip irq_chip; ++ raw_spinlock_t irq_lock; + struct irq_domain *msi_domain; + struct irq_domain *msi_inner_domain; + struct irq_chip msi_bottom_irq_chip; +@@ -366,9 +415,39 @@ err: + dev_err(dev, "link never came up\n"); + } + ++/* ++ * Set PCIe address window register which could be used for memory ++ * mapping. ++ */ ++static void advk_pcie_set_ob_win(struct advk_pcie *pcie, u8 win_num, ++ phys_addr_t match, phys_addr_t remap, ++ phys_addr_t mask, u32 actions) ++{ ++ advk_writel(pcie, OB_WIN_ENABLE | ++ lower_32_bits(match), OB_WIN_MATCH_LS(win_num)); ++ advk_writel(pcie, upper_32_bits(match), OB_WIN_MATCH_MS(win_num)); ++ advk_writel(pcie, lower_32_bits(remap), OB_WIN_REMAP_LS(win_num)); ++ advk_writel(pcie, upper_32_bits(remap), OB_WIN_REMAP_MS(win_num)); ++ advk_writel(pcie, lower_32_bits(mask), OB_WIN_MASK_LS(win_num)); ++ advk_writel(pcie, upper_32_bits(mask), OB_WIN_MASK_MS(win_num)); ++ advk_writel(pcie, actions, OB_WIN_ACTIONS(win_num)); ++} ++ ++static void advk_pcie_disable_ob_win(struct advk_pcie *pcie, u8 win_num) ++{ ++ advk_writel(pcie, 0, OB_WIN_MATCH_LS(win_num)); ++ advk_writel(pcie, 0, OB_WIN_MATCH_MS(win_num)); ++ advk_writel(pcie, 0, OB_WIN_REMAP_LS(win_num)); ++ advk_writel(pcie, 0, OB_WIN_REMAP_MS(win_num)); ++ advk_writel(pcie, 0, OB_WIN_MASK_LS(win_num)); ++ advk_writel(pcie, 0, OB_WIN_MASK_MS(win_num)); ++ advk_writel(pcie, 0, OB_WIN_ACTIONS(win_num)); ++} ++ + static void advk_pcie_setup_hw(struct advk_pcie *pcie) + { + u32 reg; ++ int i; + + /* Enable TX */ + reg = advk_readl(pcie, PCIE_CORE_REF_CLK_REG); +@@ -447,15 +526,51 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) + reg = PCIE_IRQ_ALL_MASK & (~PCIE_IRQ_ENABLE_INTS_MASK); + advk_writel(pcie, reg, HOST_CTRL_INT_MASK_REG); + ++ /* ++ * Enable AXI address window location generation: ++ * When it is enabled, the default outbound window ++ * configurations (Default User Field: 0xD0074CFC) ++ * are used to transparent address translation for ++ * the outbound transactions. Thus, PCIe address ++ * windows are not required for transparent memory ++ * access when default outbound window configuration ++ * is set for memory access. ++ */ + reg = advk_readl(pcie, PCIE_CORE_CTRL2_REG); + reg |= PCIE_CORE_CTRL2_OB_WIN_ENABLE; + advk_writel(pcie, reg, PCIE_CORE_CTRL2_REG); + +- /* Bypass the address window mapping for PIO */ ++ /* ++ * Set memory access in Default User Field so it ++ * is not required to configure PCIe address for ++ * transparent memory access. ++ */ ++ advk_writel(pcie, OB_WIN_TYPE_MEM, OB_WIN_DEFAULT_ACTIONS); ++ ++ /* ++ * Bypass the address window mapping for PIO: ++ * Since PIO access already contains all required ++ * info over AXI interface by PIO registers, the ++ * address window is not required. ++ */ + reg = advk_readl(pcie, PIO_CTRL); + reg |= PIO_CTRL_ADDR_WIN_DISABLE; + advk_writel(pcie, reg, PIO_CTRL); + ++ /* ++ * Configure PCIe address windows for non-memory or ++ * non-transparent access as by default PCIe uses ++ * transparent memory access. ++ */ ++ for (i = 0; i < pcie->wins_count; i++) ++ advk_pcie_set_ob_win(pcie, i, ++ pcie->wins[i].match, pcie->wins[i].remap, ++ pcie->wins[i].mask, pcie->wins[i].actions); ++ ++ /* Disable remaining PCIe outbound windows */ ++ for (i = pcie->wins_count; i < OB_WIN_COUNT; i++) ++ advk_pcie_disable_ob_win(pcie, i); ++ + advk_pcie_train_link(pcie); + + /* +@@ -472,7 +587,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) + advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG); + } + +-static void advk_pcie_check_pio_status(struct advk_pcie *pcie) ++static int advk_pcie_check_pio_status(struct advk_pcie *pcie, u32 *val) + { + struct device *dev = &pcie->pdev->dev; + u32 reg; +@@ -483,14 +598,49 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie) + status = (reg & PIO_COMPLETION_STATUS_MASK) >> + PIO_COMPLETION_STATUS_SHIFT; + +- if (!status) +- return; +- ++ /* ++ * According to HW spec, the PIO status check sequence as below: ++ * 1) even if COMPLETION_STATUS(bit9:7) indicates successful, ++ * it still needs to check Error Status(bit11), only when this bit ++ * indicates no error happen, the operation is successful. ++ * 2) value Unsupported Request(1) of COMPLETION_STATUS(bit9:7) only ++ * means a PIO write error, and for PIO read it is successful with ++ * a read value of 0xFFFFFFFF. ++ * 3) value Completion Retry Status(CRS) of COMPLETION_STATUS(bit9:7) ++ * only means a PIO write error, and for PIO read it is successful ++ * with a read value of 0xFFFF0001. ++ * 4) value Completer Abort (CA) of COMPLETION_STATUS(bit9:7) means ++ * error for both PIO read and PIO write operation. ++ * 5) other errors are indicated as 'unknown'. ++ */ + switch (status) { ++ case PIO_COMPLETION_STATUS_OK: ++ if (reg & PIO_ERR_STATUS) { ++ strcomp_status = "COMP_ERR"; ++ break; ++ } ++ /* Get the read result */ ++ if (val) ++ *val = advk_readl(pcie, PIO_RD_DATA); ++ /* No error */ ++ strcomp_status = NULL; ++ break; + case PIO_COMPLETION_STATUS_UR: + strcomp_status = "UR"; + break; + case PIO_COMPLETION_STATUS_CRS: ++ /* PCIe r4.0, sec 2.3.2, says: ++ * If CRS Software Visibility is not enabled, the Root Complex ++ * must re-issue the Configuration Request as a new Request. ++ * A Root Complex implementation may choose to limit the number ++ * of Configuration Request/CRS Completion Status loops before ++ * determining that something is wrong with the target of the ++ * Request and taking appropriate action, e.g., complete the ++ * Request to the host as a failed transaction. ++ * ++ * To simplify implementation do not re-issue the Configuration ++ * Request and complete the Request as a failed transaction. ++ */ + strcomp_status = "CRS"; + break; + case PIO_COMPLETION_STATUS_CA: +@@ -501,6 +651,9 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie) + break; + } + ++ if (!strcomp_status) ++ return 0; ++ + if (reg & PIO_NON_POSTED_REQ) + str_posted = "Non-posted"; + else +@@ -508,6 +661,8 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie) + + dev_err(dev, "%s PIO Response Status: %s, %#x @ %#x\n", + str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS)); ++ ++ return -EFAULT; + } + + static int advk_pcie_wait_pio(struct advk_pcie *pcie) +@@ -745,10 +900,13 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn, + return PCIBIOS_SET_FAILED; + } + +- advk_pcie_check_pio_status(pcie); ++ /* Check PIO status and get the read result */ ++ ret = advk_pcie_check_pio_status(pcie, val); ++ if (ret < 0) { ++ *val = 0xffffffff; ++ return PCIBIOS_SET_FAILED; ++ } + +- /* Get the read result */ +- *val = advk_readl(pcie, PIO_RD_DATA); + if (size == 1) + *val = (*val >> (8 * (where & 3))) & 0xff; + else if (size == 2) +@@ -812,7 +970,9 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn, + if (ret < 0) + return PCIBIOS_SET_FAILED; + +- advk_pcie_check_pio_status(pcie); ++ ret = advk_pcie_check_pio_status(pcie, NULL); ++ if (ret < 0) ++ return PCIBIOS_SET_FAILED; + + return PCIBIOS_SUCCESSFUL; + } +@@ -886,22 +1046,28 @@ static void advk_pcie_irq_mask(struct irq_data *d) + { + struct advk_pcie *pcie = d->domain->host_data; + irq_hw_number_t hwirq = irqd_to_hwirq(d); ++ unsigned long flags; + u32 mask; + ++ raw_spin_lock_irqsave(&pcie->irq_lock, flags); + mask = advk_readl(pcie, PCIE_ISR1_MASK_REG); + mask |= PCIE_ISR1_INTX_ASSERT(hwirq); + advk_writel(pcie, mask, PCIE_ISR1_MASK_REG); ++ raw_spin_unlock_irqrestore(&pcie->irq_lock, flags); + } + + static void advk_pcie_irq_unmask(struct irq_data *d) + { + struct advk_pcie *pcie = d->domain->host_data; + irq_hw_number_t hwirq = irqd_to_hwirq(d); ++ unsigned long flags; + u32 mask; + ++ raw_spin_lock_irqsave(&pcie->irq_lock, flags); + mask = advk_readl(pcie, PCIE_ISR1_MASK_REG); + mask &= ~PCIE_ISR1_INTX_ASSERT(hwirq); + advk_writel(pcie, mask, PCIE_ISR1_MASK_REG); ++ raw_spin_unlock_irqrestore(&pcie->irq_lock, flags); + } + + static int advk_pcie_irq_map(struct irq_domain *h, +@@ -985,6 +1151,8 @@ static int advk_pcie_init_irq_domain(struct advk_pcie *pcie) + struct irq_chip *irq_chip; + int ret = 0; + ++ raw_spin_lock_init(&pcie->irq_lock); ++ + pcie_intc_node = of_get_next_child(node, NULL); + if (!pcie_intc_node) { + dev_err(dev, "No PCIe Intc node found\n"); +@@ -1162,6 +1330,7 @@ static int advk_pcie_probe(struct platform_device *pdev) + struct device *dev = &pdev->dev; + struct advk_pcie *pcie; + struct pci_host_bridge *bridge; ++ struct resource_entry *entry; + int ret, irq; + + bridge = devm_pci_alloc_host_bridge(dev, sizeof(struct advk_pcie)); +@@ -1172,6 +1341,80 @@ static int advk_pcie_probe(struct platform_device *pdev) + pcie->pdev = pdev; + platform_set_drvdata(pdev, pcie); + ++ resource_list_for_each_entry(entry, &bridge->windows) { ++ resource_size_t start = entry->res->start; ++ resource_size_t size = resource_size(entry->res); ++ unsigned long type = resource_type(entry->res); ++ u64 win_size; ++ ++ /* ++ * Aardvark hardware allows to configure also PCIe window ++ * for config type 0 and type 1 mapping, but driver uses ++ * only PIO for issuing configuration transfers which does ++ * not use PCIe window configuration. ++ */ ++ if (type != IORESOURCE_MEM && type != IORESOURCE_MEM_64 && ++ type != IORESOURCE_IO) ++ continue; ++ ++ /* ++ * Skip transparent memory resources. Default outbound access ++ * configuration is set to transparent memory access so it ++ * does not need window configuration. ++ */ ++ if ((type == IORESOURCE_MEM || type == IORESOURCE_MEM_64) && ++ entry->offset == 0) ++ continue; ++ ++ /* ++ * The n-th PCIe window is configured by tuple (match, remap, mask) ++ * and an access to address A uses this window if A matches the ++ * match with given mask. ++ * So every PCIe window size must be a power of two and every start ++ * address must be aligned to window size. Minimal size is 64 KiB ++ * because lower 16 bits of mask must be zero. Remapped address ++ * may have set only bits from the mask. ++ */ ++ while (pcie->wins_count < OB_WIN_COUNT && size > 0) { ++ /* Calculate the largest aligned window size */ ++ win_size = (1ULL << (fls64(size)-1)) | ++ (start ? (1ULL << __ffs64(start)) : 0); ++ win_size = 1ULL << __ffs64(win_size); ++ if (win_size < 0x10000) ++ break; ++ ++ dev_dbg(dev, ++ "Configuring PCIe window %d: [0x%llx-0x%llx] as %lu\n", ++ pcie->wins_count, (unsigned long long)start, ++ (unsigned long long)start + win_size, type); ++ ++ if (type == IORESOURCE_IO) { ++ pcie->wins[pcie->wins_count].actions = OB_WIN_TYPE_IO; ++ pcie->wins[pcie->wins_count].match = pci_pio_to_address(start); ++ } else { ++ pcie->wins[pcie->wins_count].actions = OB_WIN_TYPE_MEM; ++ pcie->wins[pcie->wins_count].match = start; ++ } ++ pcie->wins[pcie->wins_count].remap = start - entry->offset; ++ pcie->wins[pcie->wins_count].mask = ~(win_size - 1); ++ ++ if (pcie->wins[pcie->wins_count].remap & (win_size - 1)) ++ break; ++ ++ start += win_size; ++ size -= win_size; ++ pcie->wins_count++; ++ } ++ ++ if (size > 0) { ++ dev_err(&pcie->pdev->dev, ++ "Invalid PCIe region [0x%llx-0x%llx]\n", ++ (unsigned long long)entry->res->start, ++ (unsigned long long)entry->res->end + 1); ++ return -EINVAL; ++ } ++ } ++ + pcie->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(pcie->base)) + return PTR_ERR(pcie->base); +@@ -1252,6 +1495,7 @@ static int advk_pcie_remove(struct platform_device *pdev) + { + struct advk_pcie *pcie = platform_get_drvdata(pdev); + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); ++ int i; + + pci_lock_rescan_remove(); + pci_stop_root_bus(bridge->bus); +@@ -1261,6 +1505,10 @@ static int advk_pcie_remove(struct platform_device *pdev) + advk_pcie_remove_msi_irq_domain(pcie); + advk_pcie_remove_irq_domain(pcie); + ++ /* Disable outbound address windows mapping */ ++ for (i = 0; i < OB_WIN_COUNT; i++) ++ advk_pcie_disable_ob_win(pcie, i); ++ + return 0; + } + +diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c +index 8689311c5ef66..1c3d5b87ef20e 100644 +--- a/drivers/pci/controller/pcie-xilinx-nwl.c ++++ b/drivers/pci/controller/pcie-xilinx-nwl.c +@@ -6,6 +6,7 @@ + * (C) Copyright 2014 - 2015, Xilinx, Inc. + */ + ++#include + #include + #include + #include +@@ -169,6 +170,7 @@ struct nwl_pcie { + u8 last_busno; + struct nwl_msi msi; + struct irq_domain *legacy_irq_domain; ++ struct clk *clk; + raw_spinlock_t leg_mask_lock; + }; + +@@ -823,6 +825,16 @@ static int nwl_pcie_probe(struct platform_device *pdev) + return err; + } + ++ pcie->clk = devm_clk_get(dev, NULL); ++ if (IS_ERR(pcie->clk)) ++ return PTR_ERR(pcie->clk); ++ ++ err = clk_prepare_enable(pcie->clk); ++ if (err) { ++ dev_err(dev, "can't enable PCIe ref clock\n"); ++ return err; ++ } ++ + err = nwl_pcie_bridge_init(pcie); + if (err) { + dev_err(dev, "HW Initialization failed\n"); +diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c +index 3f353572588df..a5e6759c407b9 100644 +--- a/drivers/pci/pci.c ++++ b/drivers/pci/pci.c +@@ -1906,11 +1906,7 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) + * so that things like MSI message writing will behave as expected + * (e.g. if the device really is in D0 at enable time). + */ +- if (dev->pm_cap) { +- u16 pmcsr; +- pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); +- dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); +- } ++ pci_update_current_state(dev, dev->current_state); + + if (atomic_inc_return(&dev->enable_cnt) > 1) + return 0; /* already enabled */ +diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c +index e1fed6649c41f..3ee63968deaa5 100644 +--- a/drivers/pci/pcie/portdrv_core.c ++++ b/drivers/pci/pcie/portdrv_core.c +@@ -257,8 +257,13 @@ static int get_port_device_capability(struct pci_dev *dev) + services |= PCIE_PORT_SERVICE_DPC; + + if (pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM || +- pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) +- services |= PCIE_PORT_SERVICE_BWNOTIF; ++ pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) { ++ u32 linkcap; ++ ++ pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &linkcap); ++ if (linkcap & PCI_EXP_LNKCAP_LBNC) ++ services |= PCIE_PORT_SERVICE_BWNOTIF; ++ } + + return services; + } +diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c +index 7b1c81b899cdf..1905ee0297a4c 100644 +--- a/drivers/pci/quirks.c ++++ b/drivers/pci/quirks.c +@@ -3241,6 +3241,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SOLARFLARE, + PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1, fixup_mpss_256); + DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SOLARFLARE, + PCI_DEVICE_ID_SOLARFLARE_SFC4000B, fixup_mpss_256); ++DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ASMEDIA, 0x0612, fixup_mpss_256); + + /* + * Intel 5000 and 5100 Memory controllers have an erratum with read completion +diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c +index 8b003c890b87b..c9f03418e71e0 100644 +--- a/drivers/pci/syscall.c ++++ b/drivers/pci/syscall.c +@@ -22,8 +22,10 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn, + long err; + int cfg_ret; + ++ err = -EPERM; ++ dev = NULL; + if (!capable(CAP_SYS_ADMIN)) +- return -EPERM; ++ goto error; + + err = -ENODEV; + dev = pci_get_domain_bus_and_slot(0, bus, dfn); +diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +index 5a68e242f6b34..5cb018f988003 100644 +--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c ++++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +@@ -167,10 +167,14 @@ static struct armada_37xx_pin_group armada_37xx_nb_groups[] = { + PIN_GRP_GPIO("jtag", 20, 5, BIT(0), "jtag"), + PIN_GRP_GPIO("sdio0", 8, 3, BIT(1), "sdio"), + PIN_GRP_GPIO("emmc_nb", 27, 9, BIT(2), "emmc"), +- PIN_GRP_GPIO("pwm0", 11, 1, BIT(3), "pwm"), +- PIN_GRP_GPIO("pwm1", 12, 1, BIT(4), "pwm"), +- PIN_GRP_GPIO("pwm2", 13, 1, BIT(5), "pwm"), +- PIN_GRP_GPIO("pwm3", 14, 1, BIT(6), "pwm"), ++ PIN_GRP_GPIO_3("pwm0", 11, 1, BIT(3) | BIT(20), 0, BIT(20), BIT(3), ++ "pwm", "led"), ++ PIN_GRP_GPIO_3("pwm1", 12, 1, BIT(4) | BIT(21), 0, BIT(21), BIT(4), ++ "pwm", "led"), ++ PIN_GRP_GPIO_3("pwm2", 13, 1, BIT(5) | BIT(22), 0, BIT(22), BIT(5), ++ "pwm", "led"), ++ PIN_GRP_GPIO_3("pwm3", 14, 1, BIT(6) | BIT(23), 0, BIT(23), BIT(6), ++ "pwm", "led"), + PIN_GRP_GPIO("pmic1", 7, 1, BIT(7), "pmic"), + PIN_GRP_GPIO("pmic0", 6, 1, BIT(8), "pmic"), + PIN_GRP_GPIO("i2c2", 2, 2, BIT(9), "i2c"), +@@ -184,10 +188,6 @@ static struct armada_37xx_pin_group armada_37xx_nb_groups[] = { + PIN_GRP_EXTRA("uart2", 9, 2, BIT(1) | BIT(13) | BIT(14) | BIT(19), + BIT(1) | BIT(13) | BIT(14), BIT(1) | BIT(19), + 18, 2, "gpio", "uart"), +- PIN_GRP_GPIO_2("led0_od", 11, 1, BIT(20), BIT(20), 0, "led"), +- PIN_GRP_GPIO_2("led1_od", 12, 1, BIT(21), BIT(21), 0, "led"), +- PIN_GRP_GPIO_2("led2_od", 13, 1, BIT(22), BIT(22), 0, "led"), +- PIN_GRP_GPIO_2("led3_od", 14, 1, BIT(23), BIT(23), 0, "led"), + }; + + static struct armada_37xx_pin_group armada_37xx_sb_groups[] = { +diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c +index 983ba9865f772..263498be8e319 100644 +--- a/drivers/pinctrl/pinctrl-ingenic.c ++++ b/drivers/pinctrl/pinctrl-ingenic.c +@@ -710,7 +710,7 @@ static const struct ingenic_chip_info jz4755_chip_info = { + }; + + static const u32 jz4760_pull_ups[6] = { +- 0xffffffff, 0xfffcf3ff, 0xffffffff, 0xffffcfff, 0xfffffb7c, 0xfffff00f, ++ 0xffffffff, 0xfffcf3ff, 0xffffffff, 0xffffcfff, 0xfffffb7c, 0x0000000f, + }; + + static const u32 jz4760_pull_downs[6] = { +@@ -936,11 +936,11 @@ static const struct ingenic_chip_info jz4760_chip_info = { + }; + + static const u32 jz4770_pull_ups[6] = { +- 0x3fffffff, 0xfff0030c, 0xffffffff, 0xffff4fff, 0xfffffb7c, 0xffa7f00f, ++ 0x3fffffff, 0xfff0f3fc, 0xffffffff, 0xffff4fff, 0xfffffb7c, 0x0024f00f, + }; + + static const u32 jz4770_pull_downs[6] = { +- 0x00000000, 0x000f0c03, 0x00000000, 0x0000b000, 0x00000483, 0x00580ff0, ++ 0x00000000, 0x000f0c03, 0x00000000, 0x0000b000, 0x00000483, 0x005b0ff0, + }; + + static int jz4770_uart0_data_pins[] = { 0xa0, 0xa3, }; +@@ -3441,17 +3441,17 @@ static void ingenic_set_bias(struct ingenic_pinctrl *jzpc, + { + if (jzpc->info->version >= ID_X2000) { + switch (bias) { +- case PIN_CONFIG_BIAS_PULL_UP: ++ case GPIO_PULL_UP: + ingenic_config_pin(jzpc, pin, X2000_GPIO_PEPD, false); + ingenic_config_pin(jzpc, pin, X2000_GPIO_PEPU, true); + break; + +- case PIN_CONFIG_BIAS_PULL_DOWN: ++ case GPIO_PULL_DOWN: + ingenic_config_pin(jzpc, pin, X2000_GPIO_PEPU, false); + ingenic_config_pin(jzpc, pin, X2000_GPIO_PEPD, true); + break; + +- case PIN_CONFIG_BIAS_DISABLE: ++ case GPIO_PULL_DIS: + default: + ingenic_config_pin(jzpc, pin, X2000_GPIO_PEPU, false); + ingenic_config_pin(jzpc, pin, X2000_GPIO_PEPD, false); +diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c +index e3aa64798f7d3..4fcae8458359c 100644 +--- a/drivers/pinctrl/pinctrl-single.c ++++ b/drivers/pinctrl/pinctrl-single.c +@@ -1224,6 +1224,7 @@ static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs, + + if (PCS_HAS_PINCONF) { + dev_err(pcs->dev, "pinconf not supported\n"); ++ res = -ENOTSUPP; + goto free_pingroups; + } + +diff --git a/drivers/pinctrl/pinctrl-stmfx.c b/drivers/pinctrl/pinctrl-stmfx.c +index 008c83107a3ca..5fa2488fae87a 100644 +--- a/drivers/pinctrl/pinctrl-stmfx.c ++++ b/drivers/pinctrl/pinctrl-stmfx.c +@@ -566,7 +566,7 @@ static irqreturn_t stmfx_pinctrl_irq_thread_fn(int irq, void *dev_id) + u8 pending[NR_GPIO_REGS]; + u8 src[NR_GPIO_REGS] = {0, 0, 0}; + unsigned long n, status; +- int ret; ++ int i, ret; + + ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_IRQ_GPI_PENDING, + &pending, NR_GPIO_REGS); +@@ -576,7 +576,9 @@ static irqreturn_t stmfx_pinctrl_irq_thread_fn(int irq, void *dev_id) + regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, + src, NR_GPIO_REGS); + +- status = *(unsigned long *)pending; ++ BUILD_BUG_ON(NR_GPIO_REGS > sizeof(status)); ++ for (i = 0, status = 0; i < NR_GPIO_REGS; i++) ++ status |= (unsigned long)pending[i] << (i * 8); + for_each_set_bit(n, &status, gc->ngpio) { + handle_nested_irq(irq_find_mapping(gc->irq.domain, n)); + stmfx_pinctrl_irq_toggle_trigger(pctl, n); +diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c +index 376876bd66058..2975b4369f32f 100644 +--- a/drivers/pinctrl/samsung/pinctrl-samsung.c ++++ b/drivers/pinctrl/samsung/pinctrl-samsung.c +@@ -918,7 +918,7 @@ static int samsung_pinctrl_register(struct platform_device *pdev, + pin_bank->grange.pin_base = drvdata->pin_base + + pin_bank->pin_base; + pin_bank->grange.base = pin_bank->grange.pin_base; +- pin_bank->grange.npins = pin_bank->gpio_chip.ngpio; ++ pin_bank->grange.npins = pin_bank->nr_pins; + pin_bank->grange.gc = &pin_bank->gpio_chip; + pinctrl_add_gpio_range(drvdata->pctl_dev, &pin_bank->grange); + } +diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c +index aa7f7aa772971..a7404d69b2d32 100644 +--- a/drivers/platform/chrome/cros_ec_proto.c ++++ b/drivers/platform/chrome/cros_ec_proto.c +@@ -279,6 +279,15 @@ static int cros_ec_host_command_proto_query(struct cros_ec_device *ec_dev, + msg->insize = sizeof(struct ec_response_get_protocol_info); + + ret = send_command(ec_dev, msg); ++ /* ++ * Send command once again when timeout occurred. ++ * Fingerprint MCU (FPMCU) is restarted during system boot which ++ * introduces small window in which FPMCU won't respond for any ++ * messages sent by kernel. There is no need to wait before next ++ * attempt because we waited at least EC_MSG_DEADLINE_MS. ++ */ ++ if (ret == -ETIMEDOUT) ++ ret = send_command(ec_dev, msg); + + if (ret < 0) { + dev_dbg(ec_dev->dev, +diff --git a/drivers/platform/x86/dell/dell-smbios-wmi.c b/drivers/platform/x86/dell/dell-smbios-wmi.c +index 33f8237727335..8e761991455af 100644 +--- a/drivers/platform/x86/dell/dell-smbios-wmi.c ++++ b/drivers/platform/x86/dell/dell-smbios-wmi.c +@@ -69,6 +69,7 @@ static int run_smbios_call(struct wmi_device *wdev) + if (obj->type == ACPI_TYPE_INTEGER) + dev_dbg(&wdev->dev, "SMBIOS call failed: %llu\n", + obj->integer.value); ++ kfree(output.pointer); + return -EIO; + } + memcpy(&priv->buf->std, obj->buffer.pointer, obj->buffer.length); +diff --git a/drivers/platform/x86/intel_speed_select_if/isst_if_common.c b/drivers/platform/x86/intel_speed_select_if/isst_if_common.c +index 6f0cc679c8e5c..8a4d52a9028d5 100644 +--- a/drivers/platform/x86/intel_speed_select_if/isst_if_common.c ++++ b/drivers/platform/x86/intel_speed_select_if/isst_if_common.c +@@ -379,6 +379,8 @@ static int isst_if_cpu_online(unsigned int cpu) + u64 data; + int ret; + ++ isst_cpu_info[cpu].numa_node = cpu_to_node(cpu); ++ + ret = rdmsrl_safe(MSR_CPU_BUS_NUMBER, &data); + if (ret) { + /* This is not a fatal error on MSR mailbox only I/F */ +@@ -397,7 +399,6 @@ static int isst_if_cpu_online(unsigned int cpu) + return ret; + } + isst_cpu_info[cpu].punit_cpu_id = data; +- isst_cpu_info[cpu].numa_node = cpu_to_node(cpu); + + isst_restore_msr_local(cpu); + +diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c +index 215e77d3b6d93..622bdae6182c0 100644 +--- a/drivers/power/supply/max17042_battery.c ++++ b/drivers/power/supply/max17042_battery.c +@@ -869,8 +869,12 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) + { + struct max17042_chip *chip = dev; + u32 val; ++ int ret; ++ ++ ret = regmap_read(chip->regmap, MAX17042_STATUS, &val); ++ if (ret) ++ return IRQ_HANDLED; + +- regmap_read(chip->regmap, MAX17042_STATUS, &val); + if ((val & STATUS_INTR_SOCMIN_BIT) || + (val & STATUS_INTR_SOCMAX_BIT)) { + dev_info(&chip->client->dev, "SOC threshold INTR\n"); +diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c +index bc89c62ccb9b5..75e4c2d777b9c 100644 +--- a/drivers/rtc/rtc-tps65910.c ++++ b/drivers/rtc/rtc-tps65910.c +@@ -467,6 +467,6 @@ static struct platform_driver tps65910_rtc_driver = { + }; + + module_platform_driver(tps65910_rtc_driver); +-MODULE_ALIAS("platform:rtc-tps65910"); ++MODULE_ALIAS("platform:tps65910-rtc"); + MODULE_AUTHOR("Venu Byravarasu "); + MODULE_LICENSE("GPL"); +diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c +index 3052fab00597c..3567912440dc3 100644 +--- a/drivers/s390/cio/qdio_main.c ++++ b/drivers/s390/cio/qdio_main.c +@@ -890,6 +890,33 @@ static void qdio_shutdown_queues(struct qdio_irq *irq_ptr) + } + } + ++static int qdio_cancel_ccw(struct qdio_irq *irq, int how) ++{ ++ struct ccw_device *cdev = irq->cdev; ++ int rc; ++ ++ spin_lock_irq(get_ccwdev_lock(cdev)); ++ qdio_set_state(irq, QDIO_IRQ_STATE_CLEANUP); ++ if (how & QDIO_FLAG_CLEANUP_USING_CLEAR) ++ rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP); ++ else ++ /* default behaviour is halt */ ++ rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); ++ spin_unlock_irq(get_ccwdev_lock(cdev)); ++ if (rc) { ++ DBF_ERROR("%4x SHUTD ERR", irq->schid.sch_no); ++ DBF_ERROR("rc:%4d", rc); ++ return rc; ++ } ++ ++ wait_event_interruptible_timeout(cdev->private->wait_q, ++ irq->state == QDIO_IRQ_STATE_INACTIVE || ++ irq->state == QDIO_IRQ_STATE_ERR, ++ 10 * HZ); ++ ++ return 0; ++} ++ + /** + * qdio_shutdown - shut down a qdio subchannel + * @cdev: associated ccw device +@@ -927,27 +954,7 @@ int qdio_shutdown(struct ccw_device *cdev, int how) + qdio_shutdown_queues(irq_ptr); + qdio_shutdown_debug_entries(irq_ptr); + +- /* cleanup subchannel */ +- spin_lock_irq(get_ccwdev_lock(cdev)); +- qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP); +- if (how & QDIO_FLAG_CLEANUP_USING_CLEAR) +- rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP); +- else +- /* default behaviour is halt */ +- rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); +- spin_unlock_irq(get_ccwdev_lock(cdev)); +- if (rc) { +- DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no); +- DBF_ERROR("rc:%4d", rc); +- goto no_cleanup; +- } +- +- wait_event_interruptible_timeout(cdev->private->wait_q, +- irq_ptr->state == QDIO_IRQ_STATE_INACTIVE || +- irq_ptr->state == QDIO_IRQ_STATE_ERR, +- 10 * HZ); +- +-no_cleanup: ++ rc = qdio_cancel_ccw(irq_ptr, how); + qdio_shutdown_thinint(irq_ptr); + qdio_shutdown_irq(irq_ptr); + +@@ -1083,6 +1090,7 @@ int qdio_establish(struct ccw_device *cdev, + { + struct qdio_irq *irq_ptr = cdev->private->qdio_data; + struct subchannel_id schid; ++ long timeout; + int rc; + + ccw_device_get_schid(cdev, &schid); +@@ -1111,11 +1119,8 @@ int qdio_establish(struct ccw_device *cdev, + qdio_setup_irq(irq_ptr, init_data); + + rc = qdio_establish_thinint(irq_ptr); +- if (rc) { +- qdio_shutdown_irq(irq_ptr); +- mutex_unlock(&irq_ptr->setup_mutex); +- return rc; +- } ++ if (rc) ++ goto err_thinint; + + /* establish q */ + irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd; +@@ -1131,15 +1136,16 @@ int qdio_establish(struct ccw_device *cdev, + if (rc) { + DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no); + DBF_ERROR("rc:%4x", rc); +- qdio_shutdown_thinint(irq_ptr); +- qdio_shutdown_irq(irq_ptr); +- mutex_unlock(&irq_ptr->setup_mutex); +- return rc; ++ goto err_ccw_start; + } + +- wait_event_interruptible_timeout(cdev->private->wait_q, +- irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || +- irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ); ++ timeout = wait_event_interruptible_timeout(cdev->private->wait_q, ++ irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || ++ irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ); ++ if (timeout <= 0) { ++ rc = (timeout == -ERESTARTSYS) ? -EINTR : -ETIME; ++ goto err_ccw_timeout; ++ } + + if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) { + mutex_unlock(&irq_ptr->setup_mutex); +@@ -1156,6 +1162,16 @@ int qdio_establish(struct ccw_device *cdev, + qdio_print_subchannel_info(irq_ptr); + qdio_setup_debug_entries(irq_ptr); + return 0; ++ ++err_ccw_timeout: ++ qdio_cancel_ccw(irq_ptr, QDIO_FLAG_CLEANUP_USING_CLEAR); ++err_ccw_start: ++ qdio_shutdown_thinint(irq_ptr); ++err_thinint: ++ qdio_shutdown_irq(irq_ptr); ++ qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); ++ mutex_unlock(&irq_ptr->setup_mutex); ++ return rc; + } + EXPORT_SYMBOL_GPL(qdio_establish); + +diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c +index adddcd5899416..0df93d2cd3c36 100644 +--- a/drivers/scsi/BusLogic.c ++++ b/drivers/scsi/BusLogic.c +@@ -1711,7 +1711,7 @@ static bool __init blogic_reportconfig(struct blogic_adapter *adapter) + if (adapter->adapter_bus_type != BLOGIC_PCI_BUS) { + blogic_info(" DMA Channel: None, ", adapter); + if (adapter->bios_addr > 0) +- blogic_info("BIOS Address: 0x%lX, ", adapter, ++ blogic_info("BIOS Address: 0x%X, ", adapter, + adapter->bios_addr); + else + blogic_info("BIOS Address: None, ", adapter); +@@ -3451,7 +3451,7 @@ static void blogic_msg(enum blogic_msglevel msglevel, char *fmt, + if (buf[0] != '\n' || len > 1) + printk("%sscsi%d: %s", blogic_msglevelmap[msglevel], adapter->host_no, buf); + } else +- printk("%s", buf); ++ pr_cont("%s", buf); + } else { + if (begin) { + if (adapter != NULL && adapter->adapter_initd) +@@ -3459,7 +3459,7 @@ static void blogic_msg(enum blogic_msglevel msglevel, char *fmt, + else + printk("%s%s", blogic_msglevelmap[msglevel], buf); + } else +- printk("%s", buf); ++ pr_cont("%s", buf); + } + begin = (buf[len - 1] == '\n'); + } +diff --git a/drivers/scsi/pcmcia/fdomain_cs.c b/drivers/scsi/pcmcia/fdomain_cs.c +index e42acf314d068..33df6a9ba9b5f 100644 +--- a/drivers/scsi/pcmcia/fdomain_cs.c ++++ b/drivers/scsi/pcmcia/fdomain_cs.c +@@ -45,8 +45,10 @@ static int fdomain_probe(struct pcmcia_device *link) + goto fail_disable; + + if (!request_region(link->resource[0]->start, FDOMAIN_REGION_SIZE, +- "fdomain_cs")) ++ "fdomain_cs")) { ++ ret = -EBUSY; + goto fail_disable; ++ } + + sh = fdomain_create(link->resource[0]->start, link->irq, 7, &link->dev); + if (!sh) { +diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c +index 85f41abcb56c1..42d0d941dba5c 100644 +--- a/drivers/scsi/qedf/qedf_main.c ++++ b/drivers/scsi/qedf/qedf_main.c +@@ -3004,7 +3004,7 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf) + { + u32 *list; + int i; +- int status = 0, rc; ++ int status; + u32 *pbl; + dma_addr_t page; + int num_pages; +@@ -3016,7 +3016,7 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf) + */ + if (!qedf->num_queues) { + QEDF_ERR(&(qedf->dbg_ctx), "No MSI-X vectors available!\n"); +- return 1; ++ return -ENOMEM; + } + + /* +@@ -3024,7 +3024,7 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf) + * addresses of our queues + */ + if (!qedf->p_cpuq) { +- status = 1; ++ status = -EINVAL; + QEDF_ERR(&qedf->dbg_ctx, "p_cpuq is NULL.\n"); + goto mem_alloc_failure; + } +@@ -3040,8 +3040,8 @@ static int qedf_alloc_global_queues(struct qedf_ctx *qedf) + "qedf->global_queues=%p.\n", qedf->global_queues); + + /* Allocate DMA coherent buffers for BDQ */ +- rc = qedf_alloc_bdq(qedf); +- if (rc) { ++ status = qedf_alloc_bdq(qedf); ++ if (status) { + QEDF_ERR(&qedf->dbg_ctx, "Unable to allocate bdq.\n"); + goto mem_alloc_failure; + } +diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c +index 0b0acb8270719..e6dc0b495a829 100644 +--- a/drivers/scsi/qedi/qedi_main.c ++++ b/drivers/scsi/qedi/qedi_main.c +@@ -1621,7 +1621,7 @@ static int qedi_alloc_global_queues(struct qedi_ctx *qedi) + { + u32 *list; + int i; +- int status = 0, rc; ++ int status; + u32 *pbl; + dma_addr_t page; + int num_pages; +@@ -1632,14 +1632,14 @@ static int qedi_alloc_global_queues(struct qedi_ctx *qedi) + */ + if (!qedi->num_queues) { + QEDI_ERR(&qedi->dbg_ctx, "No MSI-X vectors available!\n"); +- return 1; ++ return -ENOMEM; + } + + /* Make sure we allocated the PBL that will contain the physical + * addresses of our queues + */ + if (!qedi->p_cpuq) { +- status = 1; ++ status = -EINVAL; + goto mem_alloc_failure; + } + +@@ -1654,13 +1654,13 @@ static int qedi_alloc_global_queues(struct qedi_ctx *qedi) + "qedi->global_queues=%p.\n", qedi->global_queues); + + /* Allocate DMA coherent buffers for BDQ */ +- rc = qedi_alloc_bdq(qedi); +- if (rc) ++ status = qedi_alloc_bdq(qedi); ++ if (status) + goto mem_alloc_failure; + + /* Allocate DMA coherent buffers for NVM_ISCSI_CFG */ +- rc = qedi_alloc_nvm_iscsi_cfg(qedi); +- if (rc) ++ status = qedi_alloc_nvm_iscsi_cfg(qedi); ++ if (status) + goto mem_alloc_failure; + + /* Allocate a CQ and an associated PBL for each MSI-X +diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c +index 3e5c70a1d969c..a7259733e4709 100644 +--- a/drivers/scsi/qla2xxx/qla_nvme.c ++++ b/drivers/scsi/qla2xxx/qla_nvme.c +@@ -91,8 +91,9 @@ static int qla_nvme_alloc_queue(struct nvme_fc_local_port *lport, + struct qla_hw_data *ha; + struct qla_qpair *qpair; + +- if (!qidx) +- qidx++; ++ /* Map admin queue and 1st IO queue to index 0 */ ++ if (qidx) ++ qidx--; + + vha = (struct scsi_qla_host *)lport->private; + ha = vha->hw; +diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c +index cedd558f65ebf..37ab71b6a8a78 100644 +--- a/drivers/scsi/qla2xxx/qla_os.c ++++ b/drivers/scsi/qla2xxx/qla_os.c +@@ -14,6 +14,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -2818,6 +2819,11 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) + return ret; + } + ++ if (is_kdump_kernel()) { ++ ql2xmqsupport = 0; ++ ql2xallocfwdump = 0; ++ } ++ + /* This may fail but that's ok */ + pci_enable_pcie_error_reporting(pdev); + +diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c +index dcc0b9618a649..8819a407c02b6 100644 +--- a/drivers/scsi/smartpqi/smartpqi_init.c ++++ b/drivers/scsi/smartpqi/smartpqi_init.c +@@ -1322,6 +1322,7 @@ static int pqi_get_raid_map(struct pqi_ctrl_info *ctrl_info, + "requested %u bytes, received %u bytes\n", + raid_map_size, + get_unaligned_le32(&raid_map->structure_size)); ++ rc = -EINVAL; + goto error; + } + } +diff --git a/drivers/scsi/ufs/ufs-exynos.c b/drivers/scsi/ufs/ufs-exynos.c +index cf46d6f86e0ed..427a2ff7e9da1 100644 +--- a/drivers/scsi/ufs/ufs-exynos.c ++++ b/drivers/scsi/ufs/ufs-exynos.c +@@ -260,7 +260,7 @@ static int exynos_ufs_get_clk_info(struct exynos_ufs *ufs) + struct ufs_hba *hba = ufs->hba; + struct list_head *head = &hba->clk_list_head; + struct ufs_clk_info *clki; +- u32 pclk_rate; ++ unsigned long pclk_rate; + u32 f_min, f_max; + u8 div = 0; + int ret = 0; +@@ -299,7 +299,7 @@ static int exynos_ufs_get_clk_info(struct exynos_ufs *ufs) + } + + if (unlikely(pclk_rate < f_min || pclk_rate > f_max)) { +- dev_err(hba->dev, "not available pclk range %d\n", pclk_rate); ++ dev_err(hba->dev, "not available pclk range %lu\n", pclk_rate); + ret = -EINVAL; + goto out; + } +diff --git a/drivers/scsi/ufs/ufs-exynos.h b/drivers/scsi/ufs/ufs-exynos.h +index 67505fe32ebf9..dadf4fd10dd80 100644 +--- a/drivers/scsi/ufs/ufs-exynos.h ++++ b/drivers/scsi/ufs/ufs-exynos.h +@@ -184,7 +184,7 @@ struct exynos_ufs { + u32 pclk_div; + u32 pclk_avail_min; + u32 pclk_avail_max; +- u32 mclk_rate; ++ unsigned long mclk_rate; + int avail_ln_rx; + int avail_ln_tx; + int rx_sel_idx; +diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c +index 708b3b62fc4d1..15ac5fa148058 100644 +--- a/drivers/scsi/ufs/ufshcd.c ++++ b/drivers/scsi/ufs/ufshcd.c +@@ -2766,15 +2766,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) + WARN_ON(ufshcd_is_clkgating_allowed(hba) && + (hba->clk_gating.state != CLKS_ON)); + +- if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { +- if (hba->pm_op_in_progress) +- set_host_byte(cmd, DID_BAD_TARGET); +- else +- err = SCSI_MLQUEUE_HOST_BUSY; +- ufshcd_release(hba); +- goto out; +- } +- + lrbp = &hba->lrb[tag]; + WARN_ON(lrbp->cmd); + lrbp->cmd = cmd; +@@ -2949,11 +2940,11 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, + enum dev_cmd_type cmd_type, int timeout) + { + struct request_queue *q = hba->cmd_queue; ++ DECLARE_COMPLETION_ONSTACK(wait); + struct request *req; + struct ufshcd_lrb *lrbp; + int err; + int tag; +- struct completion wait; + + down_read(&hba->clk_scaling_lock); + +@@ -2973,12 +2964,6 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, + req->timeout = msecs_to_jiffies(2 * timeout); + blk_mq_start_request(req); + +- if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { +- err = -EBUSY; +- goto out; +- } +- +- init_completion(&wait); + lrbp = &hba->lrb[tag]; + WARN_ON(lrbp->cmd); + err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag); +@@ -3419,9 +3404,11 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, + + if (is_kmalloc) { + /* Make sure we don't copy more data than available */ +- if (param_offset + param_size > buff_len) +- param_size = buff_len - param_offset; +- memcpy(param_read_buf, &desc_buf[param_offset], param_size); ++ if (param_offset >= buff_len) ++ ret = -EINVAL; ++ else ++ memcpy(param_read_buf, &desc_buf[param_offset], ++ min_t(u32, param_size, buff_len - param_offset)); + } + out: + if (is_kmalloc) +@@ -3983,14 +3970,13 @@ EXPORT_SYMBOL_GPL(ufshcd_dme_get_attr); + */ + static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) + { +- struct completion uic_async_done; ++ DECLARE_COMPLETION_ONSTACK(uic_async_done); + unsigned long flags; + u8 status; + int ret; + bool reenable_intr = false; + + mutex_lock(&hba->uic_cmd_mutex); +- init_completion(&uic_async_done); + ufshcd_add_delay_before_dme_cmd(hba); + + spin_lock_irqsave(hba->host->host_lock, flags); +@@ -5020,15 +5006,34 @@ static int ufshcd_slave_configure(struct scsi_device *sdev) + static void ufshcd_slave_destroy(struct scsi_device *sdev) + { + struct ufs_hba *hba; ++ unsigned long flags; + + hba = shost_priv(sdev->host); + /* Drop the reference as it won't be needed anymore */ + if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) { +- unsigned long flags; +- + spin_lock_irqsave(hba->host->host_lock, flags); + hba->sdev_ufs_device = NULL; + spin_unlock_irqrestore(hba->host->host_lock, flags); ++ } else if (hba->sdev_ufs_device) { ++ struct device *supplier = NULL; ++ ++ /* Ensure UFS Device WLUN exists and does not disappear */ ++ spin_lock_irqsave(hba->host->host_lock, flags); ++ if (hba->sdev_ufs_device) { ++ supplier = &hba->sdev_ufs_device->sdev_gendev; ++ get_device(supplier); ++ } ++ spin_unlock_irqrestore(hba->host->host_lock, flags); ++ ++ if (supplier) { ++ /* ++ * If a LUN fails to probe (e.g. absent BOOT WLUN), the ++ * device will not have been registered but can still ++ * have a device link holding a reference to the device. ++ */ ++ device_link_remove(&sdev->sdev_gendev, supplier); ++ put_device(supplier); ++ } + } + } + +@@ -6663,11 +6668,11 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, + enum query_opcode desc_op) + { + struct request_queue *q = hba->cmd_queue; ++ DECLARE_COMPLETION_ONSTACK(wait); + struct request *req; + struct ufshcd_lrb *lrbp; + int err = 0; + int tag; +- struct completion wait; + u8 upiu_flags; + + down_read(&hba->clk_scaling_lock); +@@ -6685,7 +6690,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, + goto out; + } + +- init_completion(&wait); + lrbp = &hba->lrb[tag]; + WARN_ON(lrbp->cmd); + lrbp->cmd = NULL; +@@ -6984,8 +6988,8 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) + struct Scsi_Host *host; + struct ufs_hba *hba; + unsigned long flags; +- unsigned int tag; +- int err = 0; ++ int tag; ++ int err = FAILED; + struct ufshcd_lrb *lrbp; + u32 reg; + +@@ -7002,12 +7006,12 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) + + ufshcd_hold(hba, false); + reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); +- /* If command is already aborted/completed, return SUCCESS */ ++ /* If command is already aborted/completed, return FAILED. */ + if (!(test_bit(tag, &hba->outstanding_reqs))) { + dev_err(hba->dev, + "%s: cmd at tag %d already completed, outstanding=0x%lx, doorbell=0x%x\n", + __func__, tag, hba->outstanding_reqs, reg); +- goto out; ++ goto release; + } + + /* Print Transfer Request of aborted task */ +@@ -7036,7 +7040,8 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) + dev_err(hba->dev, + "%s: cmd was completed, but without a notifying intr, tag = %d", + __func__, tag); +- goto cleanup; ++ __ufshcd_transfer_req_compl(hba, 1UL << tag); ++ goto release; + } + + /* +@@ -7049,36 +7054,33 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) + */ + if (lrbp->lun == UFS_UPIU_UFS_DEVICE_WLUN) { + ufshcd_update_evt_hist(hba, UFS_EVT_ABORT, lrbp->lun); +- __ufshcd_transfer_req_compl(hba, (1UL << tag)); +- set_bit(tag, &hba->outstanding_reqs); ++ + spin_lock_irqsave(host->host_lock, flags); + hba->force_reset = true; + ufshcd_schedule_eh_work(hba); + spin_unlock_irqrestore(host->host_lock, flags); +- goto out; ++ goto release; + } + + /* Skip task abort in case previous aborts failed and report failure */ +- if (lrbp->req_abort_skip) +- err = -EIO; +- else +- err = ufshcd_try_to_abort_task(hba, tag); ++ if (lrbp->req_abort_skip) { ++ dev_err(hba->dev, "%s: skipping abort\n", __func__); ++ ufshcd_set_req_abort_skip(hba, hba->outstanding_reqs); ++ goto release; ++ } + +- if (!err) { +-cleanup: +- __ufshcd_transfer_req_compl(hba, (1UL << tag)); +-out: +- err = SUCCESS; +- } else { ++ err = ufshcd_try_to_abort_task(hba, tag); ++ if (err) { + dev_err(hba->dev, "%s: failed with err %d\n", __func__, err); + ufshcd_set_req_abort_skip(hba, hba->outstanding_reqs); + err = FAILED; ++ goto release; + } + +- /* +- * This ufshcd_release() corresponds to the original scsi cmd that got +- * aborted here (as we won't get any IRQ for it). +- */ ++ err = SUCCESS; ++ ++release: ++ /* Matches the ufshcd_hold() call at the start of this function. */ + ufshcd_release(hba); + return err; + } +diff --git a/drivers/soc/aspeed/aspeed-lpc-ctrl.c b/drivers/soc/aspeed/aspeed-lpc-ctrl.c +index c557ffd0992c7..55e46fa6cf424 100644 +--- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c ++++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c +@@ -51,7 +51,7 @@ static int aspeed_lpc_ctrl_mmap(struct file *file, struct vm_area_struct *vma) + unsigned long vsize = vma->vm_end - vma->vm_start; + pgprot_t prot = vma->vm_page_prot; + +- if (vma->vm_pgoff + vsize > lpc_ctrl->mem_base + lpc_ctrl->mem_size) ++ if (vma->vm_pgoff + vma_pages(vma) > lpc_ctrl->mem_size >> PAGE_SHIFT) + return -EINVAL; + + /* ast2400/2500 AHB accesses are not cache coherent */ +diff --git a/drivers/soc/aspeed/aspeed-p2a-ctrl.c b/drivers/soc/aspeed/aspeed-p2a-ctrl.c +index b60fbeaffcbd0..20b5fb2a207cc 100644 +--- a/drivers/soc/aspeed/aspeed-p2a-ctrl.c ++++ b/drivers/soc/aspeed/aspeed-p2a-ctrl.c +@@ -110,7 +110,7 @@ static int aspeed_p2a_mmap(struct file *file, struct vm_area_struct *vma) + vsize = vma->vm_end - vma->vm_start; + prot = vma->vm_page_prot; + +- if (vma->vm_pgoff + vsize > ctrl->mem_base + ctrl->mem_size) ++ if (vma->vm_pgoff + vma_pages(vma) > ctrl->mem_size >> PAGE_SHIFT) + return -EINVAL; + + /* ast2400/2500 AHB accesses are not cache coherent */ +diff --git a/drivers/soc/mediatek/mtk-mmsys.h b/drivers/soc/mediatek/mtk-mmsys.h +index 5f3e2bf0c40bc..9e2b81bd38db1 100644 +--- a/drivers/soc/mediatek/mtk-mmsys.h ++++ b/drivers/soc/mediatek/mtk-mmsys.h +@@ -262,6 +262,10 @@ static const struct mtk_mmsys_routes mmsys_default_routing_table[] = { + DDP_COMPONENT_RDMA2, DDP_COMPONENT_DSI3, + DISP_REG_CONFIG_DSIO_SEL_IN, DSI3_SEL_IN_MASK, + DSI3_SEL_IN_RDMA2 ++ }, { ++ DDP_COMPONENT_UFOE, DDP_COMPONENT_DSI0, ++ DISP_REG_CONFIG_DISP_UFOE_MOUT_EN, UFOE_MOUT_EN_DSI0, ++ UFOE_MOUT_EN_DSI0 + } + }; + +diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c +index 934fcc4d2b057..7b6b94332510a 100644 +--- a/drivers/soc/qcom/qcom_aoss.c ++++ b/drivers/soc/qcom/qcom_aoss.c +@@ -476,12 +476,12 @@ static int qmp_cooling_device_add(struct qmp *qmp, + static int qmp_cooling_devices_register(struct qmp *qmp) + { + struct device_node *np, *child; +- int count = QMP_NUM_COOLING_RESOURCES; ++ int count = 0; + int ret; + + np = qmp->dev->of_node; + +- qmp->cooling_devs = devm_kcalloc(qmp->dev, count, ++ qmp->cooling_devs = devm_kcalloc(qmp->dev, QMP_NUM_COOLING_RESOURCES, + sizeof(*qmp->cooling_devs), + GFP_KERNEL); + +@@ -497,12 +497,16 @@ static int qmp_cooling_devices_register(struct qmp *qmp) + goto unroll; + } + ++ if (!count) ++ devm_kfree(qmp->dev, qmp->cooling_devs); ++ + return 0; + + unroll: + while (--count >= 0) + thermal_cooling_device_unregister + (qmp->cooling_devs[count].cdev); ++ devm_kfree(qmp->dev, qmp->cooling_devs); + + return ret; + } +diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c +index c11e3d8cd308f..f156de765c68c 100644 +--- a/drivers/soundwire/intel.c ++++ b/drivers/soundwire/intel.c +@@ -537,12 +537,14 @@ static int intel_link_power_down(struct sdw_intel *sdw) + + mutex_lock(sdw->link_res->shim_lock); + +- intel_shim_master_ip_to_glue(sdw); +- + if (!(*shim_mask & BIT(link_id))) + dev_err(sdw->cdns.dev, + "%s: Unbalanced power-up/down calls\n", __func__); + ++ sdw->cdns.link_up = false; ++ ++ intel_shim_master_ip_to_glue(sdw); ++ + *shim_mask &= ~BIT(link_id); + + if (!*shim_mask) { +@@ -559,18 +561,19 @@ static int intel_link_power_down(struct sdw_intel *sdw) + link_control &= spa_mask; + + ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask); ++ if (ret < 0) { ++ dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__); ++ ++ /* ++ * we leave the sdw->cdns.link_up flag as false since we've disabled ++ * the link at this point and cannot handle interrupts any longer. ++ */ ++ } + } + + mutex_unlock(sdw->link_res->shim_lock); + +- if (ret < 0) { +- dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__); +- +- return ret; +- } +- +- sdw->cdns.link_up = false; +- return 0; ++ return ret; + } + + static void intel_shim_sync_arm(struct sdw_intel *sdw) +diff --git a/drivers/spi/spi-fsi.c b/drivers/spi/spi-fsi.c +index 87f8829c39952..829770b8ec74c 100644 +--- a/drivers/spi/spi-fsi.c ++++ b/drivers/spi/spi-fsi.c +@@ -25,16 +25,11 @@ + + #define SPI_FSI_BASE 0x70000 + #define SPI_FSI_INIT_TIMEOUT_MS 1000 +-#define SPI_FSI_MAX_XFR_SIZE 2048 +-#define SPI_FSI_MAX_XFR_SIZE_RESTRICTED 8 ++#define SPI_FSI_MAX_RX_SIZE 8 ++#define SPI_FSI_MAX_TX_SIZE 40 + + #define SPI_FSI_ERROR 0x0 + #define SPI_FSI_COUNTER_CFG 0x1 +-#define SPI_FSI_COUNTER_CFG_LOOPS(x) (((u64)(x) & 0xffULL) << 32) +-#define SPI_FSI_COUNTER_CFG_N2_RX BIT_ULL(8) +-#define SPI_FSI_COUNTER_CFG_N2_TX BIT_ULL(9) +-#define SPI_FSI_COUNTER_CFG_N2_IMPLICIT BIT_ULL(10) +-#define SPI_FSI_COUNTER_CFG_N2_RELOAD BIT_ULL(11) + #define SPI_FSI_CFG1 0x2 + #define SPI_FSI_CLOCK_CFG 0x3 + #define SPI_FSI_CLOCK_CFG_MM_ENABLE BIT_ULL(32) +@@ -76,8 +71,6 @@ struct fsi_spi { + struct device *dev; /* SPI controller device */ + struct fsi_device *fsi; /* FSI2SPI CFAM engine device */ + u32 base; +- size_t max_xfr_size; +- bool restricted; + }; + + struct fsi_spi_sequence { +@@ -241,7 +234,7 @@ static int fsi_spi_reset(struct fsi_spi *ctx) + return fsi_spi_write_reg(ctx, SPI_FSI_STATUS, 0ULL); + } + +-static int fsi_spi_sequence_add(struct fsi_spi_sequence *seq, u8 val) ++static void fsi_spi_sequence_add(struct fsi_spi_sequence *seq, u8 val) + { + /* + * Add the next byte of instruction to the 8-byte sequence register. +@@ -251,8 +244,6 @@ static int fsi_spi_sequence_add(struct fsi_spi_sequence *seq, u8 val) + */ + seq->data |= (u64)val << seq->bit; + seq->bit -= 8; +- +- return ((64 - seq->bit) / 8) - 2; + } + + static void fsi_spi_sequence_init(struct fsi_spi_sequence *seq) +@@ -261,71 +252,11 @@ static void fsi_spi_sequence_init(struct fsi_spi_sequence *seq) + seq->data = 0ULL; + } + +-static int fsi_spi_sequence_transfer(struct fsi_spi *ctx, +- struct fsi_spi_sequence *seq, +- struct spi_transfer *transfer) +-{ +- int loops; +- int idx; +- int rc; +- u8 val = 0; +- u8 len = min(transfer->len, 8U); +- u8 rem = transfer->len % len; +- +- loops = transfer->len / len; +- +- if (transfer->tx_buf) { +- val = SPI_FSI_SEQUENCE_SHIFT_OUT(len); +- idx = fsi_spi_sequence_add(seq, val); +- +- if (rem) +- rem = SPI_FSI_SEQUENCE_SHIFT_OUT(rem); +- } else if (transfer->rx_buf) { +- val = SPI_FSI_SEQUENCE_SHIFT_IN(len); +- idx = fsi_spi_sequence_add(seq, val); +- +- if (rem) +- rem = SPI_FSI_SEQUENCE_SHIFT_IN(rem); +- } else { +- return -EINVAL; +- } +- +- if (ctx->restricted && loops > 1) { +- dev_warn(ctx->dev, +- "Transfer too large; no branches permitted.\n"); +- return -EINVAL; +- } +- +- if (loops > 1) { +- u64 cfg = SPI_FSI_COUNTER_CFG_LOOPS(loops - 1); +- +- fsi_spi_sequence_add(seq, SPI_FSI_SEQUENCE_BRANCH(idx)); +- +- if (transfer->rx_buf) +- cfg |= SPI_FSI_COUNTER_CFG_N2_RX | +- SPI_FSI_COUNTER_CFG_N2_TX | +- SPI_FSI_COUNTER_CFG_N2_IMPLICIT | +- SPI_FSI_COUNTER_CFG_N2_RELOAD; +- +- rc = fsi_spi_write_reg(ctx, SPI_FSI_COUNTER_CFG, cfg); +- if (rc) +- return rc; +- } else { +- fsi_spi_write_reg(ctx, SPI_FSI_COUNTER_CFG, 0ULL); +- } +- +- if (rem) +- fsi_spi_sequence_add(seq, rem); +- +- return 0; +-} +- + static int fsi_spi_transfer_data(struct fsi_spi *ctx, + struct spi_transfer *transfer) + { + int rc = 0; + u64 status = 0ULL; +- u64 cfg = 0ULL; + + if (transfer->tx_buf) { + int nb; +@@ -363,16 +294,6 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx, + u64 in = 0ULL; + u8 *rx = transfer->rx_buf; + +- rc = fsi_spi_read_reg(ctx, SPI_FSI_COUNTER_CFG, &cfg); +- if (rc) +- return rc; +- +- if (cfg & SPI_FSI_COUNTER_CFG_N2_IMPLICIT) { +- rc = fsi_spi_write_reg(ctx, SPI_FSI_DATA_TX, 0); +- if (rc) +- return rc; +- } +- + while (transfer->len > recv) { + do { + rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS, +@@ -439,6 +360,10 @@ static int fsi_spi_transfer_init(struct fsi_spi *ctx) + } + } while (seq_state && (seq_state != SPI_FSI_STATUS_SEQ_STATE_IDLE)); + ++ rc = fsi_spi_write_reg(ctx, SPI_FSI_COUNTER_CFG, 0ULL); ++ if (rc) ++ return rc; ++ + rc = fsi_spi_read_reg(ctx, SPI_FSI_CLOCK_CFG, &clock_cfg); + if (rc) + return rc; +@@ -459,6 +384,7 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr, + { + int rc; + u8 seq_slave = SPI_FSI_SEQUENCE_SEL_SLAVE(mesg->spi->chip_select + 1); ++ unsigned int len; + struct spi_transfer *transfer; + struct fsi_spi *ctx = spi_controller_get_devdata(ctlr); + +@@ -471,8 +397,7 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr, + struct spi_transfer *next = NULL; + + /* Sequencer must do shift out (tx) first. */ +- if (!transfer->tx_buf || +- transfer->len > (ctx->max_xfr_size + 8)) { ++ if (!transfer->tx_buf || transfer->len > SPI_FSI_MAX_TX_SIZE) { + rc = -EINVAL; + goto error; + } +@@ -486,9 +411,13 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr, + fsi_spi_sequence_init(&seq); + fsi_spi_sequence_add(&seq, seq_slave); + +- rc = fsi_spi_sequence_transfer(ctx, &seq, transfer); +- if (rc) +- goto error; ++ len = transfer->len; ++ while (len > 8) { ++ fsi_spi_sequence_add(&seq, ++ SPI_FSI_SEQUENCE_SHIFT_OUT(8)); ++ len -= 8; ++ } ++ fsi_spi_sequence_add(&seq, SPI_FSI_SEQUENCE_SHIFT_OUT(len)); + + if (!list_is_last(&transfer->transfer_list, + &mesg->transfers)) { +@@ -496,7 +425,9 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr, + + /* Sequencer can only do shift in (rx) after tx. */ + if (next->rx_buf) { +- if (next->len > ctx->max_xfr_size) { ++ u8 shift; ++ ++ if (next->len > SPI_FSI_MAX_RX_SIZE) { + rc = -EINVAL; + goto error; + } +@@ -504,10 +435,8 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr, + dev_dbg(ctx->dev, "Sequence rx of %d bytes.\n", + next->len); + +- rc = fsi_spi_sequence_transfer(ctx, &seq, +- next); +- if (rc) +- goto error; ++ shift = SPI_FSI_SEQUENCE_SHIFT_IN(next->len); ++ fsi_spi_sequence_add(&seq, shift); + } else { + next = NULL; + } +@@ -541,9 +470,7 @@ error: + + static size_t fsi_spi_max_transfer_size(struct spi_device *spi) + { +- struct fsi_spi *ctx = spi_controller_get_devdata(spi->controller); +- +- return ctx->max_xfr_size; ++ return SPI_FSI_MAX_RX_SIZE; + } + + static int fsi_spi_probe(struct device *dev) +@@ -582,14 +509,6 @@ static int fsi_spi_probe(struct device *dev) + ctx->fsi = fsi; + ctx->base = base + SPI_FSI_BASE; + +- if (of_device_is_compatible(np, "ibm,fsi2spi-restricted")) { +- ctx->restricted = true; +- ctx->max_xfr_size = SPI_FSI_MAX_XFR_SIZE_RESTRICTED; +- } else { +- ctx->restricted = false; +- ctx->max_xfr_size = SPI_FSI_MAX_XFR_SIZE; +- } +- + rc = devm_spi_register_controller(dev, ctlr); + if (rc) + spi_controller_put(ctlr); +diff --git a/drivers/staging/board/board.c b/drivers/staging/board/board.c +index cb6feb34dd401..f980af0373452 100644 +--- a/drivers/staging/board/board.c ++++ b/drivers/staging/board/board.c +@@ -136,6 +136,7 @@ int __init board_staging_register_clock(const struct board_staging_clk *bsc) + static int board_staging_add_dev_domain(struct platform_device *pdev, + const char *domain) + { ++ struct device *dev = &pdev->dev; + struct of_phandle_args pd_args; + struct device_node *np; + +@@ -148,7 +149,11 @@ static int board_staging_add_dev_domain(struct platform_device *pdev, + pd_args.np = np; + pd_args.args_count = 0; + +- return of_genpd_add_device(&pd_args, &pdev->dev); ++ /* Initialization similar to device_pm_init_common() */ ++ spin_lock_init(&dev->power.lock); ++ dev->power.early_init = true; ++ ++ return of_genpd_add_device(&pd_args, dev); + } + #else + static inline int board_staging_add_dev_domain(struct platform_device *pdev, +diff --git a/drivers/staging/hikey9xx/hisilicon,hi6421-spmi-pmic.yaml b/drivers/staging/hikey9xx/hisilicon,hi6421-spmi-pmic.yaml +index 8e355cddd437d..6c348578e4a24 100644 +--- a/drivers/staging/hikey9xx/hisilicon,hi6421-spmi-pmic.yaml ++++ b/drivers/staging/hikey9xx/hisilicon,hi6421-spmi-pmic.yaml +@@ -41,6 +41,8 @@ properties: + regulators: + type: object + ++ additionalProperties: false ++ + properties: + '#address-cells': + const: 1 +@@ -49,11 +51,13 @@ properties: + const: 0 + + patternProperties: +- '^ldo[0-9]+@[0-9a-f]$': ++ '^(ldo|LDO)[0-9]+$': + type: object + + $ref: "/schemas/regulator/regulator.yaml#" + ++ unevaluatedProperties: false ++ + required: + - compatible + - reg +diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c +index cbc0032c16045..98d759e7cc957 100644 +--- a/drivers/staging/ks7010/ks7010_sdio.c ++++ b/drivers/staging/ks7010/ks7010_sdio.c +@@ -939,9 +939,9 @@ static void ks7010_private_init(struct ks_wlan_private *priv, + memset(&priv->wstats, 0, sizeof(priv->wstats)); + + /* sleep mode */ ++ atomic_set(&priv->sleepstatus.status, 0); + atomic_set(&priv->sleepstatus.doze_request, 0); + atomic_set(&priv->sleepstatus.wakeup_request, 0); +- atomic_set(&priv->sleepstatus.wakeup_request, 0); + + trx_device_init(priv); + hostif_init(priv); +diff --git a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c +index 948769ca6539d..1e324f1f656e5 100644 +--- a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c ++++ b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c +@@ -1763,7 +1763,8 @@ static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i + if (err < 0) + goto register_entities_fail; + /* init atomisp wdts */ +- if (init_atomisp_wdts(isp) != 0) ++ err = init_atomisp_wdts(isp); ++ if (err != 0) + goto wdt_work_queue_fail; + + /* save the iunit context only once after all the values are init'ed. */ +@@ -1815,6 +1816,7 @@ request_irq_fail: + hmm_cleanup(); + hmm_pool_unregister(HMM_POOL_TYPE_RESERVED); + hmm_pool_fail: ++ pm_runtime_get_noresume(&pdev->dev); + destroy_workqueue(isp->wdt_work_queue); + wdt_work_queue_fail: + atomisp_acc_cleanup(isp); +diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c +index 96622a7f8279e..2afd5996d75f8 100644 +--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c ++++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c +@@ -376,12 +376,17 @@ static void cfg_ref(struct hantro_ctx *ctx, + vb2_dst = hantro_get_dst_buf(ctx); + + ref = hantro_get_ref(ctx, hdr->last_frame_ts); +- if (!ref) ++ if (!ref) { ++ vpu_debug(0, "failed to find last frame ts=%llu\n", ++ hdr->last_frame_ts); + ref = vb2_dma_contig_plane_dma_addr(&vb2_dst->vb2_buf, 0); ++ } + vdpu_write_relaxed(vpu, ref, G1_REG_ADDR_REF(0)); + + ref = hantro_get_ref(ctx, hdr->golden_frame_ts); +- WARN_ON(!ref && hdr->golden_frame_ts); ++ if (!ref && hdr->golden_frame_ts) ++ vpu_debug(0, "failed to find golden frame ts=%llu\n", ++ hdr->golden_frame_ts); + if (!ref) + ref = vb2_dma_contig_plane_dma_addr(&vb2_dst->vb2_buf, 0); + if (hdr->flags & V4L2_VP8_FRAME_FLAG_SIGN_BIAS_GOLDEN) +@@ -389,7 +394,9 @@ static void cfg_ref(struct hantro_ctx *ctx, + vdpu_write_relaxed(vpu, ref, G1_REG_ADDR_REF(4)); + + ref = hantro_get_ref(ctx, hdr->alt_frame_ts); +- WARN_ON(!ref && hdr->alt_frame_ts); ++ if (!ref && hdr->alt_frame_ts) ++ vpu_debug(0, "failed to find alt frame ts=%llu\n", ++ hdr->alt_frame_ts); + if (!ref) + ref = vb2_dma_contig_plane_dma_addr(&vb2_dst->vb2_buf, 0); + if (hdr->flags & V4L2_VP8_FRAME_FLAG_SIGN_BIAS_ALT) +diff --git a/drivers/staging/media/hantro/rockchip_vpu2_hw_vp8_dec.c b/drivers/staging/media/hantro/rockchip_vpu2_hw_vp8_dec.c +index 951b55f58a612..704607511b57f 100644 +--- a/drivers/staging/media/hantro/rockchip_vpu2_hw_vp8_dec.c ++++ b/drivers/staging/media/hantro/rockchip_vpu2_hw_vp8_dec.c +@@ -453,12 +453,17 @@ static void cfg_ref(struct hantro_ctx *ctx, + vb2_dst = hantro_get_dst_buf(ctx); + + ref = hantro_get_ref(ctx, hdr->last_frame_ts); +- if (!ref) ++ if (!ref) { ++ vpu_debug(0, "failed to find last frame ts=%llu\n", ++ hdr->last_frame_ts); + ref = vb2_dma_contig_plane_dma_addr(&vb2_dst->vb2_buf, 0); ++ } + vdpu_write_relaxed(vpu, ref, VDPU_REG_VP8_ADDR_REF0); + + ref = hantro_get_ref(ctx, hdr->golden_frame_ts); +- WARN_ON(!ref && hdr->golden_frame_ts); ++ if (!ref && hdr->golden_frame_ts) ++ vpu_debug(0, "failed to find golden frame ts=%llu\n", ++ hdr->golden_frame_ts); + if (!ref) + ref = vb2_dma_contig_plane_dma_addr(&vb2_dst->vb2_buf, 0); + if (hdr->flags & V4L2_VP8_FRAME_FLAG_SIGN_BIAS_GOLDEN) +@@ -466,7 +471,9 @@ static void cfg_ref(struct hantro_ctx *ctx, + vdpu_write_relaxed(vpu, ref, VDPU_REG_VP8_ADDR_REF2_5(2)); + + ref = hantro_get_ref(ctx, hdr->alt_frame_ts); +- WARN_ON(!ref && hdr->alt_frame_ts); ++ if (!ref && hdr->alt_frame_ts) ++ vpu_debug(0, "failed to find alt frame ts=%llu\n", ++ hdr->alt_frame_ts); + if (!ref) + ref = vb2_dma_contig_plane_dma_addr(&vb2_dst->vb2_buf, 0); + if (hdr->flags & V4L2_VP8_FRAME_FLAG_SIGN_BIAS_ALT) +diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c +index 894c4de31790e..2882964b85136 100644 +--- a/drivers/staging/media/imx/imx7-media-csi.c ++++ b/drivers/staging/media/imx/imx7-media-csi.c +@@ -361,6 +361,7 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi, + + vb->timestamp = ktime_get_ns(); + vb2_buffer_done(vb, return_status); ++ csi->active_vb2_buf[i] = NULL; + } + } + } +@@ -386,9 +387,10 @@ static int imx7_csi_dma_setup(struct imx7_csi *csi) + return 0; + } + +-static void imx7_csi_dma_cleanup(struct imx7_csi *csi) ++static void imx7_csi_dma_cleanup(struct imx7_csi *csi, ++ enum vb2_buffer_state return_status) + { +- imx7_csi_dma_unsetup_vb2_buf(csi, VB2_BUF_STATE_ERROR); ++ imx7_csi_dma_unsetup_vb2_buf(csi, return_status); + imx_media_free_dma_buf(csi->dev, &csi->underrun_buf); + } + +@@ -537,9 +539,10 @@ static int imx7_csi_init(struct imx7_csi *csi) + return 0; + } + +-static void imx7_csi_deinit(struct imx7_csi *csi) ++static void imx7_csi_deinit(struct imx7_csi *csi, ++ enum vb2_buffer_state return_status) + { +- imx7_csi_dma_cleanup(csi); ++ imx7_csi_dma_cleanup(csi, return_status); + imx7_csi_init_default(csi); + imx7_csi_dmareq_rff_disable(csi); + clk_disable_unprepare(csi->mclk); +@@ -702,7 +705,7 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable) + + ret = v4l2_subdev_call(csi->src_sd, video, s_stream, 1); + if (ret < 0) { +- imx7_csi_deinit(csi); ++ imx7_csi_deinit(csi, VB2_BUF_STATE_QUEUED); + goto out_unlock; + } + +@@ -712,7 +715,7 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable) + + v4l2_subdev_call(csi->src_sd, video, s_stream, 0); + +- imx7_csi_deinit(csi); ++ imx7_csi_deinit(csi, VB2_BUF_STATE_ERROR); + } + + csi->is_streaming = !!enable; +diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +index bb7941aee0c47..fcf31f6d4b36f 100644 +--- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c ++++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +@@ -463,7 +463,7 @@ static void PHY_StoreTxPowerByRateNew( + if (RfPath > ODM_RF_PATH_D) + return; + +- if (TxNum > ODM_RF_PATH_D) ++ if (TxNum > RF_MAX_TX_NUM) + return; + + for (i = 0; i < rateNum; ++i) { +diff --git a/drivers/staging/rts5208/rtsx_scsi.c b/drivers/staging/rts5208/rtsx_scsi.c +index 1deb74112ad43..11d9d9155eef2 100644 +--- a/drivers/staging/rts5208/rtsx_scsi.c ++++ b/drivers/staging/rts5208/rtsx_scsi.c +@@ -2802,10 +2802,10 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) + } + + if (dev_info_id == 0x15) { +- buf_len = 0x3A; ++ buf_len = 0x3C; + data_len = 0x3A; + } else { +- buf_len = 0x6A; ++ buf_len = 0x6C; + data_len = 0x6A; + } + +@@ -2855,11 +2855,7 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) + } + + rtsx_stor_set_xfer_buf(buf, buf_len, srb); +- +- if (dev_info_id == 0x15) +- scsi_set_resid(srb, scsi_bufflen(srb) - 0x3C); +- else +- scsi_set_resid(srb, scsi_bufflen(srb) - 0x6C); ++ scsi_set_resid(srb, scsi_bufflen(srb) - buf_len); + + kfree(buf); + return STATUS_SUCCESS; +diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c +index 10d6b228cc941..eec59030c3a73 100644 +--- a/drivers/thunderbolt/switch.c ++++ b/drivers/thunderbolt/switch.c +@@ -2443,7 +2443,7 @@ static void tb_switch_default_link_ports(struct tb_switch *sw) + { + int i; + +- for (i = 1; i <= sw->config.max_port_number; i += 2) { ++ for (i = 1; i <= sw->config.max_port_number; i++) { + struct tb_port *port = &sw->ports[i]; + struct tb_port *subordinate; + +diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c +index bfc15279d5bc9..f0bc8e7800512 100644 +--- a/drivers/tty/hvc/hvsi.c ++++ b/drivers/tty/hvc/hvsi.c +@@ -1038,7 +1038,7 @@ static const struct tty_operations hvsi_ops = { + + static int __init hvsi_init(void) + { +- int i; ++ int i, ret; + + hvsi_driver = alloc_tty_driver(hvsi_count); + if (!hvsi_driver) +@@ -1069,12 +1069,25 @@ static int __init hvsi_init(void) + } + hvsi_wait = wait_for_state; /* irqs active now */ + +- if (tty_register_driver(hvsi_driver)) +- panic("Couldn't register hvsi console driver\n"); ++ ret = tty_register_driver(hvsi_driver); ++ if (ret) { ++ pr_err("Couldn't register hvsi console driver\n"); ++ goto err_free_irq; ++ } + + printk(KERN_DEBUG "HVSI: registered %i devices\n", hvsi_count); + + return 0; ++err_free_irq: ++ hvsi_wait = poll_for_state; ++ for (i = 0; i < hvsi_count; i++) { ++ struct hvsi_struct *hp = &hvsi_ports[i]; ++ ++ free_irq(hp->virq, hp); ++ } ++ tty_driver_kref_put(hvsi_driver); ++ ++ return ret; + } + device_initcall(hvsi_init); + +diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c +index 79418d4beb48f..b6c731a267d26 100644 +--- a/drivers/tty/serial/8250/8250_omap.c ++++ b/drivers/tty/serial/8250/8250_omap.c +@@ -617,7 +617,7 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) + struct uart_port *port = dev_id; + struct omap8250_priv *priv = port->private_data; + struct uart_8250_port *up = up_to_u8250p(port); +- unsigned int iir; ++ unsigned int iir, lsr; + int ret; + + #ifdef CONFIG_SERIAL_8250_DMA +@@ -628,6 +628,7 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) + #endif + + serial8250_rpm_get(up); ++ lsr = serial_port_in(port, UART_LSR); + iir = serial_port_in(port, UART_IIR); + ret = serial8250_handle_irq(port, iir); + +@@ -642,6 +643,24 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) + serial_port_in(port, UART_RX); + } + ++ /* Stop processing interrupts on input overrun */ ++ if ((lsr & UART_LSR_OE) && up->overrun_backoff_time_ms > 0) { ++ unsigned long delay; ++ ++ up->ier = port->serial_in(port, UART_IER); ++ if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { ++ port->ops->stop_rx(port); ++ } else { ++ /* Keep restarting the timer until ++ * the input overrun subsides. ++ */ ++ cancel_delayed_work(&up->overrun_backoff); ++ } ++ ++ delay = msecs_to_jiffies(up->overrun_backoff_time_ms); ++ schedule_delayed_work(&up->overrun_backoff, delay); ++ } ++ + serial8250_rpm_put(up); + + return IRQ_RETVAL(ret); +@@ -1353,6 +1372,10 @@ static int omap8250_probe(struct platform_device *pdev) + } + } + ++ if (of_property_read_u32(np, "overrun-throttle-ms", ++ &up.overrun_backoff_time_ms) != 0) ++ up.overrun_backoff_time_ms = 0; ++ + priv->wakeirq = irq_of_parse_and_map(np, 1); + + pdata = of_device_get_match_data(&pdev->dev); +diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c +index a808c283883e0..726912b16a559 100644 +--- a/drivers/tty/serial/8250/8250_pci.c ++++ b/drivers/tty/serial/8250/8250_pci.c +@@ -87,7 +87,7 @@ static void moan_device(const char *str, struct pci_dev *dev) + + static int + setup_port(struct serial_private *priv, struct uart_8250_port *port, +- int bar, int offset, int regshift) ++ u8 bar, unsigned int offset, int regshift) + { + struct pci_dev *dev = priv->dev; + +diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c +index 1da29a219842b..66374704747ec 100644 +--- a/drivers/tty/serial/8250/8250_port.c ++++ b/drivers/tty/serial/8250/8250_port.c +@@ -122,7 +122,8 @@ static const struct serial8250_config uart_config[] = { + .name = "16C950/954", + .fifo_size = 128, + .tx_loadsz = 128, +- .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, ++ .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01, ++ .rxtrig_bytes = {16, 32, 112, 120}, + /* UART_CAP_EFR breaks billionon CF bluetooth card. */ + .flags = UART_CAP_FIFO | UART_CAP_SLEEP, + }, +diff --git a/drivers/tty/serial/jsm/jsm_neo.c b/drivers/tty/serial/jsm/jsm_neo.c +index bf0e2a4cb0cef..c6f927a76c3be 100644 +--- a/drivers/tty/serial/jsm/jsm_neo.c ++++ b/drivers/tty/serial/jsm/jsm_neo.c +@@ -815,7 +815,9 @@ static void neo_parse_isr(struct jsm_board *brd, u32 port) + /* Parse any modem signal changes */ + jsm_dbg(INTR, &ch->ch_bd->pci_dev, + "MOD_STAT: sending to parse_modem_sigs\n"); ++ spin_lock_irqsave(&ch->uart_port.lock, lock_flags); + neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr)); ++ spin_unlock_irqrestore(&ch->uart_port.lock, lock_flags); + } + } + +diff --git a/drivers/tty/serial/jsm/jsm_tty.c b/drivers/tty/serial/jsm/jsm_tty.c +index 8e42a7682c63d..d74cbbbf33c62 100644 +--- a/drivers/tty/serial/jsm/jsm_tty.c ++++ b/drivers/tty/serial/jsm/jsm_tty.c +@@ -187,6 +187,7 @@ static void jsm_tty_break(struct uart_port *port, int break_state) + + static int jsm_tty_open(struct uart_port *port) + { ++ unsigned long lock_flags; + struct jsm_board *brd; + struct jsm_channel *channel = + container_of(port, struct jsm_channel, uart_port); +@@ -240,6 +241,7 @@ static int jsm_tty_open(struct uart_port *port) + channel->ch_cached_lsr = 0; + channel->ch_stops_sent = 0; + ++ spin_lock_irqsave(&port->lock, lock_flags); + termios = &port->state->port.tty->termios; + channel->ch_c_cflag = termios->c_cflag; + channel->ch_c_iflag = termios->c_iflag; +@@ -259,6 +261,7 @@ static int jsm_tty_open(struct uart_port *port) + jsm_carrier(channel); + + channel->ch_open_count++; ++ spin_unlock_irqrestore(&port->lock, lock_flags); + + jsm_dbg(OPEN, &channel->ch_bd->pci_dev, "finish\n"); + return 0; +diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c +index ef11860cd69e5..3df0788ddeb0f 100644 +--- a/drivers/tty/serial/max310x.c ++++ b/drivers/tty/serial/max310x.c +@@ -1271,18 +1271,13 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty + /* Always ask for fixed clock rate from a property. */ + device_property_read_u32(dev, "clock-frequency", &uartclk); + +- s->clk = devm_clk_get_optional(dev, "osc"); ++ xtal = device_property_match_string(dev, "clock-names", "osc") < 0; ++ if (xtal) ++ s->clk = devm_clk_get_optional(dev, "xtal"); ++ else ++ s->clk = devm_clk_get_optional(dev, "osc"); + if (IS_ERR(s->clk)) + return PTR_ERR(s->clk); +- if (s->clk) { +- xtal = false; +- } else { +- s->clk = devm_clk_get_optional(dev, "xtal"); +- if (IS_ERR(s->clk)) +- return PTR_ERR(s->clk); +- +- xtal = true; +- } + + ret = clk_prepare_enable(s->clk); + if (ret) +diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c +index 07eb56294371b..89ee43061d3ae 100644 +--- a/drivers/tty/serial/sh-sci.c ++++ b/drivers/tty/serial/sh-sci.c +@@ -1758,6 +1758,10 @@ static irqreturn_t sci_br_interrupt(int irq, void *ptr) + + /* Handle BREAKs */ + sci_handle_breaks(port); ++ ++ /* drop invalid character received before break was detected */ ++ serial_port_in(port, SCxRDR); ++ + sci_clear_SCxSR(port, SCxSR_BREAK_CLEAR(port)); + + return IRQ_HANDLED; +@@ -1837,7 +1841,8 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) + ret = sci_er_interrupt(irq, ptr); + + /* Break Interrupt */ +- if ((ssr_status & SCxSR_BRK(port)) && err_enabled) ++ if (s->irqs[SCIx_ERI_IRQ] != s->irqs[SCIx_BRI_IRQ] && ++ (ssr_status & SCxSR_BRK(port)) && err_enabled) + ret = sci_br_interrupt(irq, ptr); + + /* Overrun Interrupt */ +diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c +index 4b0d69042ceb6..bf6efebeb4bd8 100644 +--- a/drivers/tty/vt/keyboard.c ++++ b/drivers/tty/vt/keyboard.c +@@ -1171,7 +1171,7 @@ static inline unsigned char getleds(void) + * + * Check the status of a keyboard led flag and report it back + */ +-int vt_get_leds(int console, int flag) ++int vt_get_leds(unsigned int console, int flag) + { + struct kbd_struct *kb = kbd_table + console; + int ret; +@@ -1193,7 +1193,7 @@ EXPORT_SYMBOL_GPL(vt_get_leds); + * Set the LEDs on a console. This is a wrapper for the VT layer + * so that we can keep kbd knowledge internal + */ +-void vt_set_led_state(int console, int leds) ++void vt_set_led_state(unsigned int console, int leds) + { + struct kbd_struct *kb = kbd_table + console; + setledstate(kb, leds); +@@ -1212,7 +1212,7 @@ void vt_set_led_state(int console, int leds) + * don't hold the lock. We probably need to split out an LED lock + * but not during an -rc release! + */ +-void vt_kbd_con_start(int console) ++void vt_kbd_con_start(unsigned int console) + { + struct kbd_struct *kb = kbd_table + console; + unsigned long flags; +@@ -1229,7 +1229,7 @@ void vt_kbd_con_start(int console) + * Handle console stop. This is a wrapper for the VT layer + * so that we can keep kbd knowledge internal + */ +-void vt_kbd_con_stop(int console) ++void vt_kbd_con_stop(unsigned int console) + { + struct kbd_struct *kb = kbd_table + console; + unsigned long flags; +@@ -1825,7 +1825,7 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) + * Update the keyboard mode bits while holding the correct locks. + * Return 0 for success or an error code. + */ +-int vt_do_kdskbmode(int console, unsigned int arg) ++int vt_do_kdskbmode(unsigned int console, unsigned int arg) + { + struct kbd_struct *kb = kbd_table + console; + int ret = 0; +@@ -1865,7 +1865,7 @@ int vt_do_kdskbmode(int console, unsigned int arg) + * Update the keyboard meta bits while holding the correct locks. + * Return 0 for success or an error code. + */ +-int vt_do_kdskbmeta(int console, unsigned int arg) ++int vt_do_kdskbmeta(unsigned int console, unsigned int arg) + { + struct kbd_struct *kb = kbd_table + console; + int ret = 0; +@@ -2008,7 +2008,7 @@ out: + } + + int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, +- int console) ++ unsigned int console) + { + struct kbd_struct *kb = kbd_table + console; + struct kbentry kbe; +@@ -2097,7 +2097,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) + return ret; + } + +-int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm) ++int vt_do_kdskled(unsigned int console, int cmd, unsigned long arg, int perm) + { + struct kbd_struct *kb = kbd_table + console; + unsigned long flags; +@@ -2139,7 +2139,7 @@ int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm) + return -ENOIOCTLCMD; + } + +-int vt_do_kdgkbmode(int console) ++int vt_do_kdgkbmode(unsigned int console) + { + struct kbd_struct *kb = kbd_table + console; + /* This is a spot read so needs no locking */ +@@ -2163,7 +2163,7 @@ int vt_do_kdgkbmode(int console) + * + * Report the meta flag status of this console + */ +-int vt_do_kdgkbmeta(int console) ++int vt_do_kdgkbmeta(unsigned int console) + { + struct kbd_struct *kb = kbd_table + console; + /* Again a spot read so no locking */ +@@ -2176,7 +2176,7 @@ int vt_do_kdgkbmeta(int console) + * + * Restore the unicode console state to its default + */ +-void vt_reset_unicode(int console) ++void vt_reset_unicode(unsigned int console) + { + unsigned long flags; + +@@ -2204,7 +2204,7 @@ int vt_get_shift_state(void) + * Reset the keyboard bits for a console as part of a general console + * reset event + */ +-void vt_reset_keyboard(int console) ++void vt_reset_keyboard(unsigned int console) + { + struct kbd_struct *kb = kbd_table + console; + unsigned long flags; +@@ -2234,7 +2234,7 @@ void vt_reset_keyboard(int console) + * caller must be sure that there are no synchronization needs + */ + +-int vt_get_kbd_mode_bit(int console, int bit) ++int vt_get_kbd_mode_bit(unsigned int console, int bit) + { + struct kbd_struct *kb = kbd_table + console; + return vc_kbd_mode(kb, bit); +@@ -2249,7 +2249,7 @@ int vt_get_kbd_mode_bit(int console, int bit) + * caller must be sure that there are no synchronization needs + */ + +-void vt_set_kbd_mode_bit(int console, int bit) ++void vt_set_kbd_mode_bit(unsigned int console, int bit) + { + struct kbd_struct *kb = kbd_table + console; + unsigned long flags; +@@ -2268,7 +2268,7 @@ void vt_set_kbd_mode_bit(int console, int bit) + * caller must be sure that there are no synchronization needs + */ + +-void vt_clr_kbd_mode_bit(int console, int bit) ++void vt_clr_kbd_mode_bit(unsigned int console, int bit) + { + struct kbd_struct *kb = kbd_table + console; + unsigned long flags; +diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c +index e86d13c04bdbe..bdc3885c0d493 100644 +--- a/drivers/usb/chipidea/host.c ++++ b/drivers/usb/chipidea/host.c +@@ -240,15 +240,18 @@ static int ci_ehci_hub_control( + ) + { + struct ehci_hcd *ehci = hcd_to_ehci(hcd); ++ unsigned int ports = HCS_N_PORTS(ehci->hcs_params); + u32 __iomem *status_reg; +- u32 temp; ++ u32 temp, port_index; + unsigned long flags; + int retval = 0; + bool done = false; + struct device *dev = hcd->self.controller; + struct ci_hdrc *ci = dev_get_drvdata(dev); + +- status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1]; ++ port_index = wIndex & 0xff; ++ port_index -= (port_index > 0); ++ status_reg = &ehci->regs->port_status[port_index]; + + spin_lock_irqsave(&ehci->lock, flags); + +@@ -260,6 +263,11 @@ static int ci_ehci_hub_control( + } + + if (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_SUSPEND) { ++ if (!wIndex || wIndex > ports) { ++ retval = -EPIPE; ++ goto done; ++ } ++ + temp = ehci_readl(ehci, status_reg); + if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) != 0) { + retval = -EPIPE; +@@ -288,7 +296,7 @@ static int ci_ehci_hub_control( + ehci_writel(ehci, temp, status_reg); + } + +- set_bit((wIndex & 0xff) - 1, &ehci->suspended_ports); ++ set_bit(port_index, &ehci->suspended_ports); + goto done; + } + +diff --git a/drivers/usb/dwc3/dwc3-imx8mp.c b/drivers/usb/dwc3/dwc3-imx8mp.c +index 756faa46d33a7..d328d20abfbc4 100644 +--- a/drivers/usb/dwc3/dwc3-imx8mp.c ++++ b/drivers/usb/dwc3/dwc3-imx8mp.c +@@ -152,13 +152,6 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev) + } + dwc3_imx->irq = irq; + +- err = devm_request_threaded_irq(dev, irq, NULL, dwc3_imx8mp_interrupt, +- IRQF_ONESHOT, dev_name(dev), dwc3_imx); +- if (err) { +- dev_err(dev, "failed to request IRQ #%d --> %d\n", irq, err); +- goto disable_clks; +- } +- + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + err = pm_runtime_get_sync(dev); +@@ -186,6 +179,13 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev) + } + of_node_put(dwc3_np); + ++ err = devm_request_threaded_irq(dev, irq, NULL, dwc3_imx8mp_interrupt, ++ IRQF_ONESHOT, dev_name(dev), dwc3_imx); ++ if (err) { ++ dev_err(dev, "failed to request IRQ #%d --> %d\n", irq, err); ++ goto depopulate; ++ } ++ + device_set_wakeup_capable(dev, true); + pm_runtime_put(dev); + +diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c +index 72a9797dbbae0..504c1cbc255d1 100644 +--- a/drivers/usb/gadget/composite.c ++++ b/drivers/usb/gadget/composite.c +@@ -482,7 +482,7 @@ static u8 encode_bMaxPower(enum usb_device_speed speed, + { + unsigned val; + +- if (c->MaxPower) ++ if (c->MaxPower || (c->bmAttributes & USB_CONFIG_ATT_SELFPOWER)) + val = c->MaxPower; + else + val = CONFIG_USB_GADGET_VBUS_DRAW; +@@ -936,7 +936,11 @@ static int set_config(struct usb_composite_dev *cdev, + } + + /* when we return, be sure our power usage is valid */ +- power = c->MaxPower ? c->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW; ++ if (c->MaxPower || (c->bmAttributes & USB_CONFIG_ATT_SELFPOWER)) ++ power = c->MaxPower; ++ else ++ power = CONFIG_USB_GADGET_VBUS_DRAW; ++ + if (gadget->speed < USB_SPEED_SUPER) + power = min(power, 500U); + else +diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c +index d1d044d9f8594..85a3f6d4b5af3 100644 +--- a/drivers/usb/gadget/function/u_ether.c ++++ b/drivers/usb/gadget/function/u_ether.c +@@ -492,8 +492,9 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, + } + spin_unlock_irqrestore(&dev->lock, flags); + +- if (skb && !in) { +- dev_kfree_skb_any(skb); ++ if (!in) { ++ if (skb) ++ dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + } + +diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c +index cffdc8d01b2a8..8fd27249ad257 100644 +--- a/drivers/usb/host/ehci-mv.c ++++ b/drivers/usb/host/ehci-mv.c +@@ -42,26 +42,25 @@ struct ehci_hcd_mv { + int (*set_vbus)(unsigned int vbus); + }; + +-static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv) ++static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv) + { +- clk_prepare_enable(ehci_mv->clk); +-} ++ int retval; + +-static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv) +-{ +- clk_disable_unprepare(ehci_mv->clk); +-} ++ retval = clk_prepare_enable(ehci_mv->clk); ++ if (retval) ++ return retval; + +-static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv) +-{ +- ehci_clock_enable(ehci_mv); +- return phy_init(ehci_mv->phy); ++ retval = phy_init(ehci_mv->phy); ++ if (retval) ++ clk_disable_unprepare(ehci_mv->clk); ++ ++ return retval; + } + + static void mv_ehci_disable(struct ehci_hcd_mv *ehci_mv) + { + phy_exit(ehci_mv->phy); +- ehci_clock_disable(ehci_mv); ++ clk_disable_unprepare(ehci_mv->clk); + } + + static int mv_ehci_reset(struct usb_hcd *hcd) +diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c +index 05fb8d97cf027..aeb235ce06c1c 100644 +--- a/drivers/usb/host/fotg210-hcd.c ++++ b/drivers/usb/host/fotg210-hcd.c +@@ -2510,11 +2510,6 @@ retry_xacterr: + return count; + } + +-/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */ +-#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03)) +-/* ... and packet size, for any kind of endpoint descriptor */ +-#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) +- + /* reverse of qh_urb_transaction: free a list of TDs. + * used for cleanup after errors, before HC sees an URB's TDs. + */ +@@ -2600,7 +2595,7 @@ static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210, + token |= (1 /* "in" */ << 8); + /* else it's already initted to "out" pid (0 << 8) */ + +- maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input)); ++ maxpacket = usb_maxpacket(urb->dev, urb->pipe, !is_input); + + /* + * buffer gets wrapped in one or more qtds; +@@ -2714,9 +2709,11 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, + gfp_t flags) + { + struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags); ++ struct usb_host_endpoint *ep; + u32 info1 = 0, info2 = 0; + int is_input, type; + int maxp = 0; ++ int mult; + struct usb_tt *tt = urb->dev->tt; + struct fotg210_qh_hw *hw; + +@@ -2731,14 +2728,15 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, + + is_input = usb_pipein(urb->pipe); + type = usb_pipetype(urb->pipe); +- maxp = usb_maxpacket(urb->dev, urb->pipe, !is_input); ++ ep = usb_pipe_endpoint(urb->dev, urb->pipe); ++ maxp = usb_endpoint_maxp(&ep->desc); ++ mult = usb_endpoint_maxp_mult(&ep->desc); + + /* 1024 byte maxpacket is a hardware ceiling. High bandwidth + * acts like up to 3KB, but is built from smaller packets. + */ +- if (max_packet(maxp) > 1024) { +- fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", +- max_packet(maxp)); ++ if (maxp > 1024) { ++ fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", maxp); + goto done; + } + +@@ -2752,8 +2750,7 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, + */ + if (type == PIPE_INTERRUPT) { + qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, +- is_input, 0, +- hb_mult(maxp) * max_packet(maxp))); ++ is_input, 0, mult * maxp)); + qh->start = NO_FRAME; + + if (urb->dev->speed == USB_SPEED_HIGH) { +@@ -2790,7 +2787,7 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, + think_time = tt ? tt->think_time : 0; + qh->tt_usecs = NS_TO_US(think_time + + usb_calc_bus_time(urb->dev->speed, +- is_input, 0, max_packet(maxp))); ++ is_input, 0, maxp)); + qh->period = urb->interval; + if (qh->period > fotg210->periodic_size) { + qh->period = fotg210->periodic_size; +@@ -2853,11 +2850,11 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, + * to help them do so. So now people expect to use + * such nonconformant devices with Linux too; sigh. + */ +- info1 |= max_packet(maxp) << 16; ++ info1 |= maxp << 16; + info2 |= (FOTG210_TUNE_MULT_HS << 30); + } else { /* PIPE_INTERRUPT */ +- info1 |= max_packet(maxp) << 16; +- info2 |= hb_mult(maxp) << 30; ++ info1 |= maxp << 16; ++ info2 |= mult << 30; + } + break; + default: +@@ -3927,6 +3924,7 @@ static void iso_stream_init(struct fotg210_hcd *fotg210, + int is_input; + long bandwidth; + unsigned multi; ++ struct usb_host_endpoint *ep; + + /* + * this might be a "high bandwidth" highspeed endpoint, +@@ -3934,14 +3932,14 @@ static void iso_stream_init(struct fotg210_hcd *fotg210, + */ + epnum = usb_pipeendpoint(pipe); + is_input = usb_pipein(pipe) ? USB_DIR_IN : 0; +- maxp = usb_maxpacket(dev, pipe, !is_input); ++ ep = usb_pipe_endpoint(dev, pipe); ++ maxp = usb_endpoint_maxp(&ep->desc); + if (is_input) + buf1 = (1 << 11); + else + buf1 = 0; + +- maxp = max_packet(maxp); +- multi = hb_mult(maxp); ++ multi = usb_endpoint_maxp_mult(&ep->desc); + buf1 |= maxp; + maxp *= multi; + +@@ -4462,13 +4460,12 @@ static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd) + + /* HC need not update length with this error */ + if (!(t & FOTG210_ISOC_BABBLE)) { +- desc->actual_length = +- fotg210_itdlen(urb, desc, t); ++ desc->actual_length = FOTG210_ITD_LENGTH(t); + urb->actual_length += desc->actual_length; + } + } else if (likely((t & FOTG210_ISOC_ACTIVE) == 0)) { + desc->status = 0; +- desc->actual_length = fotg210_itdlen(urb, desc, t); ++ desc->actual_length = FOTG210_ITD_LENGTH(t); + urb->actual_length += desc->actual_length; + } else { + /* URB was too late */ +diff --git a/drivers/usb/host/fotg210.h b/drivers/usb/host/fotg210.h +index 0a91061a0551d..0781442b7a24a 100644 +--- a/drivers/usb/host/fotg210.h ++++ b/drivers/usb/host/fotg210.h +@@ -683,11 +683,6 @@ static inline unsigned fotg210_read_frame_index(struct fotg210_hcd *fotg210) + return fotg210_readl(fotg210, &fotg210->regs->frame_index); + } + +-#define fotg210_itdlen(urb, desc, t) ({ \ +- usb_pipein((urb)->pipe) ? \ +- (desc)->length - FOTG210_ITD_LENGTH(t) : \ +- FOTG210_ITD_LENGTH(t); \ +-}) + /*-------------------------------------------------------------------------*/ + + #endif /* __LINUX_FOTG210_H */ +diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c +index 0bb1a6295d64a..f8adf393875f3 100644 +--- a/drivers/usb/host/xhci-mtk-sch.c ++++ b/drivers/usb/host/xhci-mtk-sch.c +@@ -80,7 +80,7 @@ decode_ep(struct usb_host_endpoint *ep, enum usb_device_speed speed) + interval /= 1000; + } + +- snprintf(buf, DBG_BUF_EN, "%s ep%d%s %s, mpkt:%d, interval:%d/%d%s\n", ++ snprintf(buf, DBG_BUF_EN, "%s ep%d%s %s, mpkt:%d, interval:%d/%d%s", + usb_speed_string(speed), usb_endpoint_num(epd), + usb_endpoint_dir_in(epd) ? "in" : "out", + usb_ep_type_string(usb_endpoint_type(epd)), +@@ -129,6 +129,10 @@ get_bw_info(struct xhci_hcd_mtk *mtk, struct usb_device *udev, + int bw_index; + + virt_dev = xhci->devs[udev->slot_id]; ++ if (!virt_dev->real_port) { ++ WARN_ONCE(1, "%s invalid real_port\n", dev_name(&udev->dev)); ++ return NULL; ++ } + + if (udev->speed >= USB_SPEED_SUPER) { + if (usb_endpoint_dir_out(&ep->desc)) +@@ -236,14 +240,20 @@ static void drop_tt(struct usb_device *udev) + } + } + +-static struct mu3h_sch_ep_info *create_sch_ep(struct usb_device *udev, +- struct usb_host_endpoint *ep, struct xhci_ep_ctx *ep_ctx) ++static struct mu3h_sch_ep_info * ++create_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev, ++ struct usb_host_endpoint *ep, struct xhci_ep_ctx *ep_ctx) + { + struct mu3h_sch_ep_info *sch_ep; ++ struct mu3h_sch_bw_info *bw_info; + struct mu3h_sch_tt *tt = NULL; + u32 len_bw_budget_table; + size_t mem_size; + ++ bw_info = get_bw_info(mtk, udev, ep); ++ if (!bw_info) ++ return ERR_PTR(-ENODEV); ++ + if (is_fs_or_ls(udev->speed)) + len_bw_budget_table = TT_MICROFRAMES_MAX; + else if ((udev->speed >= USB_SPEED_SUPER) +@@ -266,11 +276,13 @@ static struct mu3h_sch_ep_info *create_sch_ep(struct usb_device *udev, + } + } + ++ sch_ep->bw_info = bw_info; + sch_ep->sch_tt = tt; + sch_ep->ep = ep; + sch_ep->speed = udev->speed; + INIT_LIST_HEAD(&sch_ep->endpoint); + INIT_LIST_HEAD(&sch_ep->tt_endpoint); ++ INIT_HLIST_NODE(&sch_ep->hentry); + + return sch_ep; + } +@@ -587,9 +599,9 @@ static u32 get_esit_boundary(struct mu3h_sch_ep_info *sch_ep) + return boundary; + } + +-static int check_sch_bw(struct mu3h_sch_bw_info *sch_bw, +- struct mu3h_sch_ep_info *sch_ep) ++static int check_sch_bw(struct mu3h_sch_ep_info *sch_ep) + { ++ struct mu3h_sch_bw_info *sch_bw = sch_ep->bw_info; + const u32 esit_boundary = get_esit_boundary(sch_ep); + const u32 bw_boundary = get_bw_boundary(sch_ep->speed); + u32 offset; +@@ -635,23 +647,26 @@ static int check_sch_bw(struct mu3h_sch_bw_info *sch_bw, + return load_ep_bw(sch_bw, sch_ep, true); + } + +-static void destroy_sch_ep(struct usb_device *udev, +- struct mu3h_sch_bw_info *sch_bw, struct mu3h_sch_ep_info *sch_ep) ++static void destroy_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev, ++ struct mu3h_sch_ep_info *sch_ep) + { + /* only release ep bw check passed by check_sch_bw() */ + if (sch_ep->allocated) +- load_ep_bw(sch_bw, sch_ep, false); ++ load_ep_bw(sch_ep->bw_info, sch_ep, false); + + if (sch_ep->sch_tt) + drop_tt(udev); + + list_del(&sch_ep->endpoint); ++ hlist_del(&sch_ep->hentry); + kfree(sch_ep); + } + +-static bool need_bw_sch(struct usb_host_endpoint *ep, +- enum usb_device_speed speed, int has_tt) ++static bool need_bw_sch(struct usb_device *udev, ++ struct usb_host_endpoint *ep) + { ++ bool has_tt = udev->tt && udev->tt->hub->parent; ++ + /* only for periodic endpoints */ + if (usb_endpoint_xfer_control(&ep->desc) + || usb_endpoint_xfer_bulk(&ep->desc)) +@@ -662,7 +677,7 @@ static bool need_bw_sch(struct usb_host_endpoint *ep, + * a TT are also ignored, root-hub will schedule them directly, + * but need set @bpkts field of endpoint context to 1. + */ +- if (is_fs_or_ls(speed) && !has_tt) ++ if (is_fs_or_ls(udev->speed) && !has_tt) + return false; + + /* skip endpoint with zero maxpkt */ +@@ -677,7 +692,6 @@ int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk) + struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd); + struct mu3h_sch_bw_info *sch_array; + int num_usb_bus; +- int i; + + /* ss IN and OUT are separated */ + num_usb_bus = xhci->usb3_rhub.num_ports * 2 + xhci->usb2_rhub.num_ports; +@@ -686,12 +700,10 @@ int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk) + if (sch_array == NULL) + return -ENOMEM; + +- for (i = 0; i < num_usb_bus; i++) +- INIT_LIST_HEAD(&sch_array[i].bw_ep_list); +- + mtk->sch_array = sch_array; + + INIT_LIST_HEAD(&mtk->bw_ep_chk_list); ++ hash_init(mtk->sch_ep_hash); + + return 0; + } +@@ -715,9 +727,7 @@ static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, + ep_index = xhci_get_endpoint_index(&ep->desc); + ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); + +- xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed)); +- +- if (!need_bw_sch(ep, udev->speed, !!virt_dev->tt_info)) { ++ if (!need_bw_sch(udev, ep)) { + /* + * set @bpkts to 1 if it is LS or FS periodic endpoint, and its + * device does not connected through an external HS hub +@@ -729,13 +739,16 @@ static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, + return 0; + } + +- sch_ep = create_sch_ep(udev, ep, ep_ctx); ++ xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed)); ++ ++ sch_ep = create_sch_ep(mtk, udev, ep, ep_ctx); + if (IS_ERR_OR_NULL(sch_ep)) + return -ENOMEM; + + setup_sch_info(ep_ctx, sch_ep); + + list_add_tail(&sch_ep->endpoint, &mtk->bw_ep_chk_list); ++ hash_add(mtk->sch_ep_hash, &sch_ep->hentry, (unsigned long)ep); + + return 0; + } +@@ -745,22 +758,18 @@ static void drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, + { + struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); +- struct xhci_virt_device *virt_dev; +- struct mu3h_sch_bw_info *sch_bw; +- struct mu3h_sch_ep_info *sch_ep, *tmp; +- +- virt_dev = xhci->devs[udev->slot_id]; +- +- xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed)); ++ struct mu3h_sch_ep_info *sch_ep; ++ struct hlist_node *hn; + +- if (!need_bw_sch(ep, udev->speed, !!virt_dev->tt_info)) ++ if (!need_bw_sch(udev, ep)) + return; + +- sch_bw = get_bw_info(mtk, udev, ep); ++ xhci_err(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed)); + +- list_for_each_entry_safe(sch_ep, tmp, &sch_bw->bw_ep_list, endpoint) { ++ hash_for_each_possible_safe(mtk->sch_ep_hash, sch_ep, ++ hn, hentry, (unsigned long)ep) { + if (sch_ep->ep == ep) { +- destroy_sch_ep(udev, sch_bw, sch_ep); ++ destroy_sch_ep(mtk, udev, sch_ep); + break; + } + } +@@ -771,30 +780,22 @@ int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) + struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id]; +- struct mu3h_sch_bw_info *sch_bw; +- struct mu3h_sch_ep_info *sch_ep, *tmp; ++ struct mu3h_sch_ep_info *sch_ep; + int ret; + + xhci_dbg(xhci, "%s() udev %s\n", __func__, dev_name(&udev->dev)); + + list_for_each_entry(sch_ep, &mtk->bw_ep_chk_list, endpoint) { +- sch_bw = get_bw_info(mtk, udev, sch_ep->ep); ++ struct xhci_ep_ctx *ep_ctx; ++ struct usb_host_endpoint *ep = sch_ep->ep; ++ unsigned int ep_index = xhci_get_endpoint_index(&ep->desc); + +- ret = check_sch_bw(sch_bw, sch_ep); ++ ret = check_sch_bw(sch_ep); + if (ret) { + xhci_err(xhci, "Not enough bandwidth! (%s)\n", + sch_error_string(-ret)); + return -ENOSPC; + } +- } +- +- list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_chk_list, endpoint) { +- struct xhci_ep_ctx *ep_ctx; +- struct usb_host_endpoint *ep = sch_ep->ep; +- unsigned int ep_index = xhci_get_endpoint_index(&ep->desc); +- +- sch_bw = get_bw_info(mtk, udev, ep); +- list_move_tail(&sch_ep->endpoint, &sch_bw->bw_ep_list); + + ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); + ep_ctx->reserved[0] = cpu_to_le32(EP_BPKTS(sch_ep->pkts) +@@ -808,22 +809,23 @@ int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) + sch_ep->offset, sch_ep->repeat); + } + +- return xhci_check_bandwidth(hcd, udev); ++ ret = xhci_check_bandwidth(hcd, udev); ++ if (!ret) ++ INIT_LIST_HEAD(&mtk->bw_ep_chk_list); ++ ++ return ret; + } + + void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) + { + struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); +- struct mu3h_sch_bw_info *sch_bw; + struct mu3h_sch_ep_info *sch_ep, *tmp; + + xhci_dbg(xhci, "%s() udev %s\n", __func__, dev_name(&udev->dev)); + +- list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_chk_list, endpoint) { +- sch_bw = get_bw_info(mtk, udev, sch_ep->ep); +- destroy_sch_ep(udev, sch_bw, sch_ep); +- } ++ list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_chk_list, endpoint) ++ destroy_sch_ep(mtk, udev, sch_ep); + + xhci_reset_bandwidth(hcd, udev); + } +diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c +index 2548976bcf05c..cb27569186a0d 100644 +--- a/drivers/usb/host/xhci-mtk.c ++++ b/drivers/usb/host/xhci-mtk.c +@@ -569,7 +569,7 @@ disable_ldos: + xhci_mtk_ldos_disable(mtk); + + disable_pm: +- pm_runtime_put_sync_autosuspend(dev); ++ pm_runtime_put_noidle(dev); + pm_runtime_disable(dev); + return ret; + } +diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h +index ace432356c412..f87d199b08181 100644 +--- a/drivers/usb/host/xhci-mtk.h ++++ b/drivers/usb/host/xhci-mtk.h +@@ -10,11 +10,15 @@ + #define _XHCI_MTK_H_ + + #include ++#include + + #include "xhci.h" + + #define BULK_CLKS_NUM 5 + ++/* support at most 64 ep, use 32 size hash table */ ++#define SCH_EP_HASH_BITS 5 ++ + /** + * To simplify scheduler algorithm, set a upper limit for ESIT, + * if a synchromous ep's ESIT is larger than @XHCI_MTK_MAX_ESIT, +@@ -36,14 +40,12 @@ struct mu3h_sch_tt { + * struct mu3h_sch_bw_info: schedule information for bandwidth domain + * + * @bus_bw: array to keep track of bandwidth already used at each uframes +- * @bw_ep_list: eps in the bandwidth domain + * + * treat a HS root port as a bandwidth domain, but treat a SS root port as + * two bandwidth domains, one for IN eps and another for OUT eps. + */ + struct mu3h_sch_bw_info { + u32 bus_bw[XHCI_MTK_MAX_ESIT]; +- struct list_head bw_ep_list; + }; + + /** +@@ -53,8 +55,10 @@ struct mu3h_sch_bw_info { + * @num_budget_microframes: number of continuous uframes + * (@repeat==1) scheduled within the interval + * @bw_cost_per_microframe: bandwidth cost per microframe ++ * @hentry: hash table entry + * @endpoint: linked into bandwidth domain which it belongs to + * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to ++ * @bw_info: bandwidth domain which this endpoint belongs + * @sch_tt: mu3h_sch_tt linked into + * @ep_type: endpoint type + * @maxpkt: max packet size of endpoint +@@ -82,7 +86,9 @@ struct mu3h_sch_ep_info { + u32 num_budget_microframes; + u32 bw_cost_per_microframe; + struct list_head endpoint; ++ struct hlist_node hentry; + struct list_head tt_endpoint; ++ struct mu3h_sch_bw_info *bw_info; + struct mu3h_sch_tt *sch_tt; + u32 ep_type; + u32 maxpkt; +@@ -135,6 +141,7 @@ struct xhci_hcd_mtk { + struct usb_hcd *hcd; + struct mu3h_sch_bw_info *sch_array; + struct list_head bw_ep_chk_list; ++ DECLARE_HASHTABLE(sch_ep_hash, SCH_EP_HASH_BITS); + struct mu3c_ippc_regs __iomem *ippc_regs; + int num_u2_ports; + int num_u3_ports; +diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c +index 3618070eba786..18a203c9011eb 100644 +--- a/drivers/usb/host/xhci.c ++++ b/drivers/usb/host/xhci.c +@@ -4705,19 +4705,19 @@ static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci, + { + unsigned long long timeout_ns; + +- if (xhci->quirks & XHCI_INTEL_HOST) +- timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc); +- else +- timeout_ns = udev->u1_params.sel; +- + /* Prevent U1 if service interval is shorter than U1 exit latency */ + if (usb_endpoint_xfer_int(desc) || usb_endpoint_xfer_isoc(desc)) { +- if (xhci_service_interval_to_ns(desc) <= timeout_ns) { ++ if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { + dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); + return USB3_LPM_DISABLED; + } + } + ++ if (xhci->quirks & XHCI_INTEL_HOST) ++ timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc); ++ else ++ timeout_ns = udev->u1_params.sel; ++ + /* The U1 timeout is encoded in 1us intervals. + * Don't return a timeout of zero, because that's USB3_LPM_DISABLED. + */ +@@ -4769,19 +4769,19 @@ static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci, + { + unsigned long long timeout_ns; + +- if (xhci->quirks & XHCI_INTEL_HOST) +- timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc); +- else +- timeout_ns = udev->u2_params.sel; +- + /* Prevent U2 if service interval is shorter than U2 exit latency */ + if (usb_endpoint_xfer_int(desc) || usb_endpoint_xfer_isoc(desc)) { +- if (xhci_service_interval_to_ns(desc) <= timeout_ns) { ++ if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { + dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); + return USB3_LPM_DISABLED; + } + } + ++ if (xhci->quirks & XHCI_INTEL_HOST) ++ timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc); ++ else ++ timeout_ns = udev->u2_params.sel; ++ + /* The U2 timeout is encoded in 256us intervals */ + timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000); + /* If the necessary timeout value is bigger than what we can set in the +diff --git a/drivers/usb/isp1760/isp1760-core.c b/drivers/usb/isp1760/isp1760-core.c +index ff07e28906922..1f2ca22384b03 100644 +--- a/drivers/usb/isp1760/isp1760-core.c ++++ b/drivers/usb/isp1760/isp1760-core.c +@@ -30,6 +30,7 @@ static int isp1760_init_core(struct isp1760_device *isp) + { + struct isp1760_hcd *hcd = &isp->hcd; + struct isp1760_udc *udc = &isp->udc; ++ u32 otg_ctrl; + + /* Low-level chip reset */ + if (isp->rst_gpio) { +@@ -83,16 +84,17 @@ static int isp1760_init_core(struct isp1760_device *isp) + * + * TODO: Really support OTG. For now we configure port 1 in device mode + */ +- if (((isp->devflags & ISP1760_FLAG_ISP1761) || +- (isp->devflags & ISP1760_FLAG_ISP1763)) && +- (isp->devflags & ISP1760_FLAG_PERIPHERAL_EN)) { +- isp1760_field_set(hcd->fields, HW_DM_PULLDOWN); +- isp1760_field_set(hcd->fields, HW_DP_PULLDOWN); +- isp1760_field_set(hcd->fields, HW_OTG_DISABLE); +- } else { +- isp1760_field_set(hcd->fields, HW_SW_SEL_HC_DC); +- isp1760_field_set(hcd->fields, HW_VBUS_DRV); +- isp1760_field_set(hcd->fields, HW_SEL_CP_EXT); ++ if (isp->devflags & ISP1760_FLAG_ISP1761) { ++ if (isp->devflags & ISP1760_FLAG_PERIPHERAL_EN) { ++ otg_ctrl = (ISP176x_HW_DM_PULLDOWN_CLEAR | ++ ISP176x_HW_DP_PULLDOWN_CLEAR | ++ ISP176x_HW_OTG_DISABLE); ++ } else { ++ otg_ctrl = (ISP176x_HW_SW_SEL_HC_DC_CLEAR | ++ ISP176x_HW_VBUS_DRV | ++ ISP176x_HW_SEL_CP_EXT); ++ } ++ isp1760_reg_write(hcd->regs, ISP176x_HC_OTG_CTRL, otg_ctrl); + } + + dev_info(isp->dev, "%s bus width: %u, oc: %s\n", +@@ -235,20 +237,20 @@ static const struct reg_field isp1760_hc_reg_fields[] = { + [HC_ISO_IRQ_MASK_AND] = REG_FIELD(ISP176x_HC_ISO_IRQ_MASK_AND, 0, 31), + [HC_INT_IRQ_MASK_AND] = REG_FIELD(ISP176x_HC_INT_IRQ_MASK_AND, 0, 31), + [HC_ATL_IRQ_MASK_AND] = REG_FIELD(ISP176x_HC_ATL_IRQ_MASK_AND, 0, 31), +- [HW_OTG_DISABLE] = REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 10, 10), +- [HW_SW_SEL_HC_DC] = REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 7, 7), +- [HW_VBUS_DRV] = REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 4, 4), +- [HW_SEL_CP_EXT] = REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 3, 3), +- [HW_DM_PULLDOWN] = REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 2, 2), +- [HW_DP_PULLDOWN] = REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 1, 1), +- [HW_DP_PULLUP] = REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 0, 0), +- [HW_OTG_DISABLE_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 10, 10), +- [HW_SW_SEL_HC_DC_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 7, 7), +- [HW_VBUS_DRV_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 4, 4), +- [HW_SEL_CP_EXT_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 3, 3), +- [HW_DM_PULLDOWN_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 2, 2), +- [HW_DP_PULLDOWN_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 1, 1), +- [HW_DP_PULLUP_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 0, 0), ++ [HW_OTG_DISABLE_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 26, 26), ++ [HW_SW_SEL_HC_DC_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 23, 23), ++ [HW_VBUS_DRV_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 20, 20), ++ [HW_SEL_CP_EXT_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 19, 19), ++ [HW_DM_PULLDOWN_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 18, 18), ++ [HW_DP_PULLDOWN_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 17, 17), ++ [HW_DP_PULLUP_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 16, 16), ++ [HW_OTG_DISABLE] = REG_FIELD(ISP176x_HC_OTG_CTRL, 10, 10), ++ [HW_SW_SEL_HC_DC] = REG_FIELD(ISP176x_HC_OTG_CTRL, 7, 7), ++ [HW_VBUS_DRV] = REG_FIELD(ISP176x_HC_OTG_CTRL, 4, 4), ++ [HW_SEL_CP_EXT] = REG_FIELD(ISP176x_HC_OTG_CTRL, 3, 3), ++ [HW_DM_PULLDOWN] = REG_FIELD(ISP176x_HC_OTG_CTRL, 2, 2), ++ [HW_DP_PULLDOWN] = REG_FIELD(ISP176x_HC_OTG_CTRL, 1, 1), ++ [HW_DP_PULLUP] = REG_FIELD(ISP176x_HC_OTG_CTRL, 0, 0), + }; + + static const struct reg_field isp1763_hc_reg_fields[] = { +diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c +index 27168b4a4ef22..e517376c32917 100644 +--- a/drivers/usb/isp1760/isp1760-hcd.c ++++ b/drivers/usb/isp1760/isp1760-hcd.c +@@ -182,7 +182,7 @@ struct urb_listitem { + struct urb *urb; + }; + +-static const u32 isp1763_hc_portsc1_fields[] = { ++static const u32 isp176x_hc_portsc1_fields[] = { + [PORT_OWNER] = BIT(13), + [PORT_POWER] = BIT(12), + [PORT_LSTATUS] = BIT(10), +@@ -205,27 +205,28 @@ static u32 isp1760_hcd_read(struct usb_hcd *hcd, u32 field) + } + + /* +- * We need, in isp1763, to write directly the values to the portsc1 ++ * We need, in isp176x, to write directly the values to the portsc1 + * register so it will make the other values to trigger. + */ + static void isp1760_hcd_portsc1_set_clear(struct isp1760_hcd *priv, u32 field, + u32 val) + { +- u32 bit = isp1763_hc_portsc1_fields[field]; +- u32 port_status = readl(priv->base + ISP1763_HC_PORTSC1); ++ u32 bit = isp176x_hc_portsc1_fields[field]; ++ u16 portsc1_reg = priv->is_isp1763 ? ISP1763_HC_PORTSC1 : ++ ISP176x_HC_PORTSC1; ++ u32 port_status = readl(priv->base + portsc1_reg); + + if (val) +- writel(port_status | bit, priv->base + ISP1763_HC_PORTSC1); ++ writel(port_status | bit, priv->base + portsc1_reg); + else +- writel(port_status & ~bit, priv->base + ISP1763_HC_PORTSC1); ++ writel(port_status & ~bit, priv->base + portsc1_reg); + } + + static void isp1760_hcd_write(struct usb_hcd *hcd, u32 field, u32 val) + { + struct isp1760_hcd *priv = hcd_to_priv(hcd); + +- if (unlikely(priv->is_isp1763 && +- (field >= PORT_OWNER && field <= PORT_CONNECT))) ++ if (unlikely((field >= PORT_OWNER && field <= PORT_CONNECT))) + return isp1760_hcd_portsc1_set_clear(priv, field, val); + + isp1760_field_write(priv->fields, field, val); +@@ -367,8 +368,7 @@ static void isp1760_mem_read(struct usb_hcd *hcd, u32 src_offset, void *dst, + { + struct isp1760_hcd *priv = hcd_to_priv(hcd); + +- isp1760_hcd_write(hcd, MEM_BANK_SEL, ISP_BANK_0); +- isp1760_hcd_write(hcd, MEM_START_ADDR, src_offset); ++ isp1760_reg_write(priv->regs, ISP176x_HC_MEMORY, src_offset); + ndelay(100); + + bank_reads8(priv->base, src_offset, ISP_BANK_0, dst, bytes); +@@ -496,8 +496,7 @@ static void isp1760_ptd_read(struct usb_hcd *hcd, u32 ptd_offset, u32 slot, + u16 src_offset = ptd_offset + slot * sizeof(*ptd); + struct isp1760_hcd *priv = hcd_to_priv(hcd); + +- isp1760_hcd_write(hcd, MEM_BANK_SEL, ISP_BANK_0); +- isp1760_hcd_write(hcd, MEM_START_ADDR, src_offset); ++ isp1760_reg_write(priv->regs, ISP176x_HC_MEMORY, src_offset); + ndelay(90); + + bank_reads8(priv->base, src_offset, ISP_BANK_0, (void *)ptd, +@@ -588,8 +587,8 @@ static void init_memory(struct isp1760_hcd *priv) + + payload_addr = PAYLOAD_OFFSET; + +- for (i = 0, curr = 0; i < ARRAY_SIZE(mem->blocks); i++) { +- for (j = 0; j < mem->blocks[i]; j++, curr++) { ++ for (i = 0, curr = 0; i < ARRAY_SIZE(mem->blocks); i++, curr += j) { ++ for (j = 0; j < mem->blocks[i]; j++) { + priv->memory_pool[curr + j].start = payload_addr; + priv->memory_pool[curr + j].size = mem->blocks_size[i]; + priv->memory_pool[curr + j].free = 1; +@@ -1826,9 +1825,11 @@ static void packetize_urb(struct usb_hcd *hcd, + goto cleanup; + + if (len > mem->blocks_size[ISP176x_BLOCK_NUM - 1]) +- len = mem->blocks_size[ISP176x_BLOCK_NUM - 1]; ++ this_qtd_len = mem->blocks_size[ISP176x_BLOCK_NUM - 1]; ++ else ++ this_qtd_len = len; + +- this_qtd_len = qtd_fill(qtd, buf, len); ++ this_qtd_len = qtd_fill(qtd, buf, this_qtd_len); + list_add_tail(&qtd->qtd_list, head); + + len -= this_qtd_len; +diff --git a/drivers/usb/isp1760/isp1760-regs.h b/drivers/usb/isp1760/isp1760-regs.h +index 94ea60c20b2a4..3a6751197e970 100644 +--- a/drivers/usb/isp1760/isp1760-regs.h ++++ b/drivers/usb/isp1760/isp1760-regs.h +@@ -61,6 +61,7 @@ + #define ISP176x_HC_INT_IRQ_MASK_AND 0x328 + #define ISP176x_HC_ATL_IRQ_MASK_AND 0x32c + ++#define ISP176x_HC_OTG_CTRL 0x374 + #define ISP176x_HC_OTG_CTRL_SET 0x374 + #define ISP176x_HC_OTG_CTRL_CLEAR 0x376 + +@@ -179,6 +180,21 @@ enum isp176x_host_controller_fields { + #define ISP176x_DC_IESUSP BIT(3) + #define ISP176x_DC_IEBRST BIT(0) + ++#define ISP176x_HW_OTG_DISABLE_CLEAR BIT(26) ++#define ISP176x_HW_SW_SEL_HC_DC_CLEAR BIT(23) ++#define ISP176x_HW_VBUS_DRV_CLEAR BIT(20) ++#define ISP176x_HW_SEL_CP_EXT_CLEAR BIT(19) ++#define ISP176x_HW_DM_PULLDOWN_CLEAR BIT(18) ++#define ISP176x_HW_DP_PULLDOWN_CLEAR BIT(17) ++#define ISP176x_HW_DP_PULLUP_CLEAR BIT(16) ++#define ISP176x_HW_OTG_DISABLE BIT(10) ++#define ISP176x_HW_SW_SEL_HC_DC BIT(7) ++#define ISP176x_HW_VBUS_DRV BIT(4) ++#define ISP176x_HW_SEL_CP_EXT BIT(3) ++#define ISP176x_HW_DM_PULLDOWN BIT(2) ++#define ISP176x_HW_DP_PULLDOWN BIT(1) ++#define ISP176x_HW_DP_PULLUP BIT(0) ++ + #define ISP176x_DC_ENDPTYP_ISOC 0x01 + #define ISP176x_DC_ENDPTYP_BULK 0x02 + #define ISP176x_DC_ENDPTYP_INTERRUPT 0x03 +diff --git a/drivers/usb/isp1760/isp1760-udc.c b/drivers/usb/isp1760/isp1760-udc.c +index a78da59d6417b..5cafd23345cad 100644 +--- a/drivers/usb/isp1760/isp1760-udc.c ++++ b/drivers/usb/isp1760/isp1760-udc.c +@@ -1363,7 +1363,7 @@ static irqreturn_t isp1760_udc_irq(int irq, void *dev) + + status = isp1760_udc_irq_get_status(udc); + +- if (status & DC_IEVBUS) { ++ if (status & ISP176x_DC_IEVBUS) { + dev_dbg(udc->isp->dev, "%s(VBUS)\n", __func__); + /* The VBUS interrupt is only triggered when VBUS appears. */ + spin_lock(&udc->lock); +@@ -1371,7 +1371,7 @@ static irqreturn_t isp1760_udc_irq(int irq, void *dev) + spin_unlock(&udc->lock); + } + +- if (status & DC_IEBRST) { ++ if (status & ISP176x_DC_IEBRST) { + dev_dbg(udc->isp->dev, "%s(BRST)\n", __func__); + + isp1760_udc_reset(udc); +@@ -1391,18 +1391,18 @@ static irqreturn_t isp1760_udc_irq(int irq, void *dev) + } + } + +- if (status & DC_IEP0SETUP) { ++ if (status & ISP176x_DC_IEP0SETUP) { + dev_dbg(udc->isp->dev, "%s(EP0SETUP)\n", __func__); + + isp1760_ep0_setup(udc); + } + +- if (status & DC_IERESM) { ++ if (status & ISP176x_DC_IERESM) { + dev_dbg(udc->isp->dev, "%s(RESM)\n", __func__); + isp1760_udc_resume(udc); + } + +- if (status & DC_IESUSP) { ++ if (status & ISP176x_DC_IESUSP) { + dev_dbg(udc->isp->dev, "%s(SUSP)\n", __func__); + + spin_lock(&udc->lock); +@@ -1413,7 +1413,7 @@ static irqreturn_t isp1760_udc_irq(int irq, void *dev) + spin_unlock(&udc->lock); + } + +- if (status & DC_IEHS_STA) { ++ if (status & ISP176x_DC_IEHS_STA) { + dev_dbg(udc->isp->dev, "%s(HS_STA)\n", __func__); + udc->gadget.speed = USB_SPEED_HIGH; + } +diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c +index 5892f3ce0cdc8..ce9fc46c92661 100644 +--- a/drivers/usb/musb/musb_dsps.c ++++ b/drivers/usb/musb/musb_dsps.c +@@ -890,23 +890,22 @@ static int dsps_probe(struct platform_device *pdev) + if (!glue->usbss_base) + return -ENXIO; + +- if (usb_get_dr_mode(&pdev->dev) == USB_DR_MODE_PERIPHERAL) { +- ret = dsps_setup_optional_vbus_irq(pdev, glue); +- if (ret) +- goto err_iounmap; +- } +- + platform_set_drvdata(pdev, glue); + pm_runtime_enable(&pdev->dev); + ret = dsps_create_musb_pdev(glue, pdev); + if (ret) + goto err; + ++ if (usb_get_dr_mode(&pdev->dev) == USB_DR_MODE_PERIPHERAL) { ++ ret = dsps_setup_optional_vbus_irq(pdev, glue); ++ if (ret) ++ goto err; ++ } ++ + return 0; + + err: + pm_runtime_disable(&pdev->dev); +-err_iounmap: + iounmap(glue->usbss_base); + return ret; + } +diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c +index 4ba6bcdaa8e9d..b07b2925ff78b 100644 +--- a/drivers/usb/usbip/vhci_hcd.c ++++ b/drivers/usb/usbip/vhci_hcd.c +@@ -455,8 +455,14 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, + vhci_hcd->port_status[rhport] &= ~(1 << USB_PORT_FEAT_RESET); + vhci_hcd->re_timeout = 0; + ++ /* ++ * A few drivers do usb reset during probe when ++ * the device could be in VDEV_ST_USED state ++ */ + if (vhci_hcd->vdev[rhport].ud.status == +- VDEV_ST_NOTASSIGNED) { ++ VDEV_ST_NOTASSIGNED || ++ vhci_hcd->vdev[rhport].ud.status == ++ VDEV_ST_USED) { + usbip_dbg_vhci_rh( + " enable rhport %d (status %u)\n", + rhport, +@@ -957,8 +963,32 @@ static void vhci_device_unlink_cleanup(struct vhci_device *vdev) + spin_lock(&vdev->priv_lock); + + list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { ++ struct urb *urb; ++ ++ /* give back urb of unsent unlink request */ + pr_info("unlink cleanup tx %lu\n", unlink->unlink_seqnum); ++ ++ urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum); ++ if (!urb) { ++ list_del(&unlink->list); ++ kfree(unlink); ++ continue; ++ } ++ ++ urb->status = -ENODEV; ++ ++ usb_hcd_unlink_urb_from_ep(hcd, urb); ++ + list_del(&unlink->list); ++ ++ spin_unlock(&vdev->priv_lock); ++ spin_unlock_irqrestore(&vhci->lock, flags); ++ ++ usb_hcd_giveback_urb(hcd, urb, urb->status); ++ ++ spin_lock_irqsave(&vhci->lock, flags); ++ spin_lock(&vdev->priv_lock); ++ + kfree(unlink); + } + +diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig +index 67d0bf4efa160..e44bf736e2b22 100644 +--- a/drivers/vfio/Kconfig ++++ b/drivers/vfio/Kconfig +@@ -29,7 +29,7 @@ menuconfig VFIO + + If you don't know what to do here, say N. + +-menuconfig VFIO_NOIOMMU ++config VFIO_NOIOMMU + bool "VFIO No-IOMMU support" + depends on VFIO + help +diff --git a/drivers/video/fbdev/asiliantfb.c b/drivers/video/fbdev/asiliantfb.c +index 3e006da477523..84c56f525889f 100644 +--- a/drivers/video/fbdev/asiliantfb.c ++++ b/drivers/video/fbdev/asiliantfb.c +@@ -227,6 +227,9 @@ static int asiliantfb_check_var(struct fb_var_screeninfo *var, + { + unsigned long Ftarget, ratio, remainder; + ++ if (!var->pixclock) ++ return -EINVAL; ++ + ratio = 1000000 / var->pixclock; + remainder = 1000000 % var->pixclock; + Ftarget = 1000000 * ratio + (1000000 * remainder) / var->pixclock; +diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c +index 8fbde92ae8b9c..25801e8e3f74a 100644 +--- a/drivers/video/fbdev/kyro/fbdev.c ++++ b/drivers/video/fbdev/kyro/fbdev.c +@@ -372,6 +372,11 @@ static int kyro_dev_overlay_viewport_set(u32 x, u32 y, u32 ulWidth, u32 ulHeight + /* probably haven't called CreateOverlay yet */ + return -EINVAL; + ++ if (ulWidth == 0 || ulWidth == 0xffffffff || ++ ulHeight == 0 || ulHeight == 0xffffffff || ++ (x < 2 && ulWidth + 2 == 0)) ++ return -EINVAL; ++ + /* Stop Ramdac Output */ + DisableRamdacOutput(deviceInfo.pSTGReg); + +@@ -394,6 +399,9 @@ static int kyrofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) + { + struct kyrofb_info *par = info->par; + ++ if (!var->pixclock) ++ return -EINVAL; ++ + if (var->bits_per_pixel != 16 && var->bits_per_pixel != 32) { + printk(KERN_WARNING "kyrofb: depth not supported: %u\n", var->bits_per_pixel); + return -EINVAL; +diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c +index 55554b0433cb4..84d5e23ad7d38 100644 +--- a/drivers/video/fbdev/riva/fbdev.c ++++ b/drivers/video/fbdev/riva/fbdev.c +@@ -1084,6 +1084,9 @@ static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) + int mode_valid = 0; + + NVTRACE_ENTER(); ++ if (!var->pixclock) ++ return -EINVAL; ++ + switch (var->bits_per_pixel) { + case 1 ... 8: + var->red.offset = var->green.offset = var->blue.offset = 0; +diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c +index b3f604669e2c3..643c6c2d0b728 100644 +--- a/drivers/watchdog/iTCO_wdt.c ++++ b/drivers/watchdog/iTCO_wdt.c +@@ -362,7 +362,7 @@ static int iTCO_wdt_set_timeout(struct watchdog_device *wd_dev, unsigned int t) + * Otherwise, the BIOS generally reboots when the SMI triggers. + */ + if (p->smi_res && +- (SMI_EN(p) & (TCO_EN | GBL_SMI_EN)) != (TCO_EN | GBL_SMI_EN)) ++ (inl(SMI_EN(p)) & (TCO_EN | GBL_SMI_EN)) != (TCO_EN | GBL_SMI_EN)) + tmrval /= 2; + + /* from the specs: */ +diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c +index 9e7d9d0c763dd..b1492cb5c6be5 100644 +--- a/fs/btrfs/block-group.c ++++ b/fs/btrfs/block-group.c +@@ -1561,7 +1561,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) + div64_u64(zone_unusable * 100, bg->length)); + trace_btrfs_reclaim_block_group(bg); + ret = btrfs_relocate_chunk(fs_info, bg->start); +- if (ret) ++ if (ret && ret != -EAGAIN) + btrfs_err(fs_info, "error relocating chunk %llu", + bg->start); + +diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h +index e5e53e592d4f9..4aa4f4760b726 100644 +--- a/fs/btrfs/ctree.h ++++ b/fs/btrfs/ctree.h +@@ -2781,10 +2781,11 @@ enum btrfs_flush_state { + FLUSH_DELAYED_REFS = 4, + FLUSH_DELALLOC = 5, + FLUSH_DELALLOC_WAIT = 6, +- ALLOC_CHUNK = 7, +- ALLOC_CHUNK_FORCE = 8, +- RUN_DELAYED_IPUTS = 9, +- COMMIT_TRANS = 10, ++ FLUSH_DELALLOC_FULL = 7, ++ ALLOC_CHUNK = 8, ++ ALLOC_CHUNK_FORCE = 9, ++ RUN_DELAYED_IPUTS = 10, ++ COMMIT_TRANS = 11, + }; + + int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, +diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c +index a59ab7b9aea08..b2f713c759e87 100644 +--- a/fs/btrfs/disk-io.c ++++ b/fs/btrfs/disk-io.c +@@ -3314,6 +3314,30 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device + */ + fs_info->compress_type = BTRFS_COMPRESS_ZLIB; + ++ /* ++ * Flag our filesystem as having big metadata blocks if they are bigger ++ * than the page size. ++ */ ++ if (btrfs_super_nodesize(disk_super) > PAGE_SIZE) { ++ if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) ++ btrfs_info(fs_info, ++ "flagging fs with big metadata feature"); ++ features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; ++ } ++ ++ /* Set up fs_info before parsing mount options */ ++ nodesize = btrfs_super_nodesize(disk_super); ++ sectorsize = btrfs_super_sectorsize(disk_super); ++ stripesize = sectorsize; ++ fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids)); ++ fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); ++ ++ fs_info->nodesize = nodesize; ++ fs_info->sectorsize = sectorsize; ++ fs_info->sectorsize_bits = ilog2(sectorsize); ++ fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size; ++ fs_info->stripesize = stripesize; ++ + ret = btrfs_parse_options(fs_info, options, sb->s_flags); + if (ret) { + err = ret; +@@ -3340,30 +3364,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device + if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA) + btrfs_info(fs_info, "has skinny extents"); + +- /* +- * flag our filesystem as having big metadata blocks if +- * they are bigger than the page size +- */ +- if (btrfs_super_nodesize(disk_super) > PAGE_SIZE) { +- if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) +- btrfs_info(fs_info, +- "flagging fs with big metadata feature"); +- features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; +- } +- +- nodesize = btrfs_super_nodesize(disk_super); +- sectorsize = btrfs_super_sectorsize(disk_super); +- stripesize = sectorsize; +- fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids)); +- fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); +- +- /* Cache block sizes */ +- fs_info->nodesize = nodesize; +- fs_info->sectorsize = sectorsize; +- fs_info->sectorsize_bits = ilog2(sectorsize); +- fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size; +- fs_info->stripesize = stripesize; +- + /* + * mixed block groups end up with duplicate but slightly offset + * extent buffers for the same range. It leads to corruptions +diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c +index 2131ae5b9ed78..c92643e4c6787 100644 +--- a/fs/btrfs/free-space-cache.c ++++ b/fs/btrfs/free-space-cache.c +@@ -2652,8 +2652,11 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group, + * btrfs_pin_extent_for_log_replay() when replaying the log. + * Advance the pointer not to overwrite the tree-log nodes. + */ +- if (block_group->alloc_offset < offset + bytes) +- block_group->alloc_offset = offset + bytes; ++ if (block_group->start + block_group->alloc_offset < ++ offset + bytes) { ++ block_group->alloc_offset = ++ offset + bytes - block_group->start; ++ } + return 0; + } + +diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c +index bd5689fa290e7..8132d503c83d7 100644 +--- a/fs/btrfs/inode.c ++++ b/fs/btrfs/inode.c +@@ -1290,11 +1290,6 @@ static noinline void async_cow_submit(struct btrfs_work *work) + nr_pages = (async_chunk->end - async_chunk->start + PAGE_SIZE) >> + PAGE_SHIFT; + +- /* atomic_sub_return implies a barrier */ +- if (atomic_sub_return(nr_pages, &fs_info->async_delalloc_pages) < +- 5 * SZ_1M) +- cond_wake_up_nomb(&fs_info->async_submit_wait); +- + /* + * ->inode could be NULL if async_chunk_start has failed to compress, + * in which case we don't have anything to submit, yet we need to +@@ -1303,6 +1298,11 @@ static noinline void async_cow_submit(struct btrfs_work *work) + */ + if (async_chunk->inode) + submit_compressed_extents(async_chunk); ++ ++ /* atomic_sub_return implies a barrier */ ++ if (atomic_sub_return(nr_pages, &fs_info->async_delalloc_pages) < ++ 5 * SZ_1M) ++ cond_wake_up_nomb(&fs_info->async_submit_wait); + } + + static noinline void async_cow_free(struct btrfs_work *work) +@@ -5088,15 +5088,13 @@ static int maybe_insert_hole(struct btrfs_root *root, struct btrfs_inode *inode, + int ret; + + /* +- * Still need to make sure the inode looks like it's been updated so +- * that any holes get logged if we fsync. ++ * If NO_HOLES is enabled, we don't need to do anything. ++ * Later, up in the call chain, either btrfs_set_inode_last_sub_trans() ++ * or btrfs_update_inode() will be called, which guarantee that the next ++ * fsync will know this inode was changed and needs to be logged. + */ +- if (btrfs_fs_incompat(fs_info, NO_HOLES)) { +- inode->last_trans = fs_info->generation; +- inode->last_sub_trans = root->log_transid; +- inode->last_log_commit = root->last_log_commit; ++ if (btrfs_fs_incompat(fs_info, NO_HOLES)) + return 0; +- } + + /* + * 1 - for the one we're dropping +@@ -9809,10 +9807,6 @@ static int start_delalloc_inodes(struct btrfs_root *root, + &work->work); + } else { + ret = sync_inode(inode, wbc); +- if (!ret && +- test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, +- &BTRFS_I(inode)->runtime_flags)) +- ret = sync_inode(inode, wbc); + btrfs_add_delayed_iput(inode); + if (ret || wbc->nr_to_write <= 0) + goto out; +diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c +index 5c0f8481e25e0..182d9fb3f5e94 100644 +--- a/fs/btrfs/ordered-data.c ++++ b/fs/btrfs/ordered-data.c +@@ -1052,6 +1052,7 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos, + u64 len) + { + struct inode *inode = ordered->inode; ++ struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; + u64 file_offset = ordered->file_offset + pos; + u64 disk_bytenr = ordered->disk_bytenr + pos; + u64 num_bytes = len; +@@ -1069,6 +1070,13 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos, + else + type = __ffs(flags_masked); + ++ /* ++ * The splitting extent is already counted and will be added again ++ * in btrfs_add_ordered_extent_*(). Subtract num_bytes to avoid ++ * double counting. ++ */ ++ percpu_counter_add_batch(&fs_info->ordered_bytes, -num_bytes, ++ fs_info->delalloc_batch); + if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered->flags)) { + WARN_ON_ONCE(1); + ret = btrfs_add_ordered_extent_compress(BTRFS_I(inode), +diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c +index f79bf85f24399..46e8415fa2c55 100644 +--- a/fs/btrfs/space-info.c ++++ b/fs/btrfs/space-info.c +@@ -493,6 +493,11 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, + long time_left; + int loops; + ++ delalloc_bytes = percpu_counter_sum_positive(&fs_info->delalloc_bytes); ++ ordered_bytes = percpu_counter_sum_positive(&fs_info->ordered_bytes); ++ if (delalloc_bytes == 0 && ordered_bytes == 0) ++ return; ++ + /* Calc the number of the pages we need flush for space reservation */ + if (to_reclaim == U64_MAX) { + items = U64_MAX; +@@ -500,22 +505,21 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, + /* + * to_reclaim is set to however much metadata we need to + * reclaim, but reclaiming that much data doesn't really track +- * exactly, so increase the amount to reclaim by 2x in order to +- * make sure we're flushing enough delalloc to hopefully reclaim +- * some metadata reservations. ++ * exactly. What we really want to do is reclaim full inode's ++ * worth of reservations, however that's not available to us ++ * here. We will take a fraction of the delalloc bytes for our ++ * flushing loops and hope for the best. Delalloc will expand ++ * the amount we write to cover an entire dirty extent, which ++ * will reclaim the metadata reservation for that range. If ++ * it's not enough subsequent flush stages will be more ++ * aggressive. + */ ++ to_reclaim = max(to_reclaim, delalloc_bytes >> 3); + items = calc_reclaim_items_nr(fs_info, to_reclaim) * 2; +- to_reclaim = items * EXTENT_SIZE_PER_ITEM; + } + + trans = (struct btrfs_trans_handle *)current->journal_info; + +- delalloc_bytes = percpu_counter_sum_positive( +- &fs_info->delalloc_bytes); +- ordered_bytes = percpu_counter_sum_positive(&fs_info->ordered_bytes); +- if (delalloc_bytes == 0 && ordered_bytes == 0) +- return; +- + /* + * If we are doing more ordered than delalloc we need to just wait on + * ordered extents, otherwise we'll waste time trying to flush delalloc +@@ -528,9 +532,49 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, + while ((delalloc_bytes || ordered_bytes) && loops < 3) { + u64 temp = min(delalloc_bytes, to_reclaim) >> PAGE_SHIFT; + long nr_pages = min_t(u64, temp, LONG_MAX); ++ int async_pages; + + btrfs_start_delalloc_roots(fs_info, nr_pages, true); + ++ /* ++ * We need to make sure any outstanding async pages are now ++ * processed before we continue. This is because things like ++ * sync_inode() try to be smart and skip writing if the inode is ++ * marked clean. We don't use filemap_fwrite for flushing ++ * because we want to control how many pages we write out at a ++ * time, thus this is the only safe way to make sure we've ++ * waited for outstanding compressed workers to have started ++ * their jobs and thus have ordered extents set up properly. ++ * ++ * This exists because we do not want to wait for each ++ * individual inode to finish its async work, we simply want to ++ * start the IO on everybody, and then come back here and wait ++ * for all of the async work to catch up. Once we're done with ++ * that we know we'll have ordered extents for everything and we ++ * can decide if we wait for that or not. ++ * ++ * If we choose to replace this in the future, make absolutely ++ * sure that the proper waiting is being done in the async case, ++ * as there have been bugs in that area before. ++ */ ++ async_pages = atomic_read(&fs_info->async_delalloc_pages); ++ if (!async_pages) ++ goto skip_async; ++ ++ /* ++ * We don't want to wait forever, if we wrote less pages in this ++ * loop than we have outstanding, only wait for that number of ++ * pages, otherwise we can wait for all async pages to finish ++ * before continuing. ++ */ ++ if (async_pages > nr_pages) ++ async_pages -= nr_pages; ++ else ++ async_pages = 0; ++ wait_event(fs_info->async_submit_wait, ++ atomic_read(&fs_info->async_delalloc_pages) <= ++ async_pages); ++skip_async: + loops++; + if (wait_ordered && !trans) { + btrfs_wait_ordered_roots(fs_info, items, 0, (u64)-1); +@@ -595,8 +639,11 @@ static void flush_space(struct btrfs_fs_info *fs_info, + break; + case FLUSH_DELALLOC: + case FLUSH_DELALLOC_WAIT: ++ case FLUSH_DELALLOC_FULL: ++ if (state == FLUSH_DELALLOC_FULL) ++ num_bytes = U64_MAX; + shrink_delalloc(fs_info, space_info, num_bytes, +- state == FLUSH_DELALLOC_WAIT, for_preempt); ++ state != FLUSH_DELALLOC, for_preempt); + break; + case FLUSH_DELAYED_REFS_NR: + case FLUSH_DELAYED_REFS: +@@ -686,7 +733,7 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info, + { + u64 global_rsv_size = fs_info->global_block_rsv.reserved; + u64 ordered, delalloc; +- u64 thresh = div_factor_fine(space_info->total_bytes, 98); ++ u64 thresh = div_factor_fine(space_info->total_bytes, 90); + u64 used; + + /* If we're just plain full then async reclaim just slows us down. */ +@@ -694,6 +741,20 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info, + global_rsv_size) >= thresh) + return false; + ++ used = space_info->bytes_may_use + space_info->bytes_pinned; ++ ++ /* The total flushable belongs to the global rsv, don't flush. */ ++ if (global_rsv_size >= used) ++ return false; ++ ++ /* ++ * 128MiB is 1/4 of the maximum global rsv size. If we have less than ++ * that devoted to other reservations then there's no sense in flushing, ++ * we don't have a lot of things that need flushing. ++ */ ++ if (used - global_rsv_size <= SZ_128M) ++ return false; ++ + /* + * We have tickets queued, bail so we don't compete with the async + * flushers. +@@ -904,6 +965,14 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work) + commit_cycles--; + } + ++ /* ++ * We do not want to empty the system of delalloc unless we're ++ * under heavy pressure, so allow one trip through the flushing ++ * logic before we start doing a FLUSH_DELALLOC_FULL. ++ */ ++ if (flush_state == FLUSH_DELALLOC_FULL && !commit_cycles) ++ flush_state++; ++ + /* + * We don't want to force a chunk allocation until we've tried + * pretty hard to reclaim space. Think of the case where we +@@ -1067,7 +1136,7 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work) + * so if we now have space to allocate do the force chunk allocation. + */ + static const enum btrfs_flush_state data_flush_states[] = { +- FLUSH_DELALLOC_WAIT, ++ FLUSH_DELALLOC_FULL, + RUN_DELAYED_IPUTS, + COMMIT_TRANS, + ALLOC_CHUNK_FORCE, +@@ -1156,6 +1225,7 @@ static const enum btrfs_flush_state evict_flush_states[] = { + FLUSH_DELAYED_REFS, + FLUSH_DELALLOC, + FLUSH_DELALLOC_WAIT, ++ FLUSH_DELALLOC_FULL, + ALLOC_CHUNK, + COMMIT_TRANS, + }; +diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c +index e6430ac9bbe85..7037e5855d2a8 100644 +--- a/fs/btrfs/tree-log.c ++++ b/fs/btrfs/tree-log.c +@@ -753,7 +753,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, + */ + ret = btrfs_lookup_data_extent(fs_info, ins.objectid, + ins.offset); +- if (ret == 0) { ++ if (ret < 0) { ++ goto out; ++ } else if (ret == 0) { + btrfs_init_generic_ref(&ref, + BTRFS_ADD_DELAYED_REF, + ins.objectid, ins.offset, 0); +diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c +index 354ffd8f81af9..10dd2d210b0f4 100644 +--- a/fs/btrfs/volumes.c ++++ b/fs/btrfs/volumes.c +@@ -1130,6 +1130,9 @@ static void btrfs_close_one_device(struct btrfs_device *device) + fs_devices->rw_devices--; + } + ++ if (device->devid == BTRFS_DEV_REPLACE_DEVID) ++ clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state); ++ + if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)) + fs_devices->missing_devices--; + +diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c +index 39db97f149b9b..ba562efdf07b8 100644 +--- a/fs/ceph/caps.c ++++ b/fs/ceph/caps.c +@@ -1746,6 +1746,9 @@ struct ceph_cap_flush *ceph_alloc_cap_flush(void) + struct ceph_cap_flush *cf; + + cf = kmem_cache_alloc(ceph_cap_flush_cachep, GFP_KERNEL); ++ if (!cf) ++ return NULL; ++ + cf->is_capsnap = false; + return cf; + } +diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c +index c5785fd3f52e8..606fd7d6cb713 100644 +--- a/fs/cifs/sess.c ++++ b/fs/cifs/sess.c +@@ -877,7 +877,7 @@ sess_alloc_buffer(struct sess_data *sess_data, int wct) + return 0; + + out_free_smb_buf: +- kfree(smb_buf); ++ cifs_small_buf_release(smb_buf); + sess_data->iov[0].iov_base = NULL; + sess_data->iov[0].iov_len = 0; + sess_data->buf0_type = CIFS_NO_BUFFER; +diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c +index 455561826c7dc..b8b3f1160afa6 100644 +--- a/fs/f2fs/compress.c ++++ b/fs/f2fs/compress.c +@@ -1340,12 +1340,6 @@ out_destroy_crypt: + + for (--i; i >= 0; i--) + fscrypt_finalize_bounce_page(&cc->cpages[i]); +- for (i = 0; i < cc->nr_cpages; i++) { +- if (!cc->cpages[i]) +- continue; +- f2fs_compress_free_page(cc->cpages[i]); +- cc->cpages[i] = NULL; +- } + out_put_cic: + kmem_cache_free(cic_entry_slab, cic); + out_put_dnode: +@@ -1356,6 +1350,12 @@ out_unlock_op: + else + f2fs_unlock_op(sbi); + out_free: ++ for (i = 0; i < cc->nr_cpages; i++) { ++ if (!cc->cpages[i]) ++ continue; ++ f2fs_compress_free_page(cc->cpages[i]); ++ cc->cpages[i] = NULL; ++ } + page_array_free(cc->inode, cc->cpages, cc->nr_cpages); + cc->cpages = NULL; + return -EAGAIN; +diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c +index d2cf48c5a2e49..a86f004c0c07e 100644 +--- a/fs/f2fs/data.c ++++ b/fs/f2fs/data.c +@@ -116,6 +116,7 @@ struct bio_post_read_ctx { + struct f2fs_sb_info *sbi; + struct work_struct work; + unsigned int enabled_steps; ++ block_t fs_blkaddr; + }; + + static void f2fs_finish_read_bio(struct bio *bio) +@@ -228,7 +229,7 @@ static void f2fs_handle_step_decompress(struct bio_post_read_ctx *ctx) + struct bio_vec *bv; + struct bvec_iter_all iter_all; + bool all_compressed = true; +- block_t blkaddr = SECTOR_TO_BLOCK(ctx->bio->bi_iter.bi_sector); ++ block_t blkaddr = ctx->fs_blkaddr; + + bio_for_each_segment_all(bv, ctx->bio, iter_all) { + struct page *page = bv->bv_page; +@@ -1003,6 +1004,7 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, + ctx->bio = bio; + ctx->sbi = sbi; + ctx->enabled_steps = post_read_steps; ++ ctx->fs_blkaddr = blkaddr; + bio->bi_private = ctx; + } + +@@ -1490,7 +1492,21 @@ next_dnode: + if (err) { + if (flag == F2FS_GET_BLOCK_BMAP) + map->m_pblk = 0; ++ + if (err == -ENOENT) { ++ /* ++ * There is one exceptional case that read_node_page() ++ * may return -ENOENT due to filesystem has been ++ * shutdown or cp_error, so force to convert error ++ * number to EIO for such case. ++ */ ++ if (map->m_may_create && ++ (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || ++ f2fs_cp_error(sbi))) { ++ err = -EIO; ++ goto unlock_out; ++ } ++ + err = 0; + if (map->m_next_pgofs) + *map->m_next_pgofs = +@@ -2137,6 +2153,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, + continue; + } + unlock_page(page); ++ if (for_write) ++ put_page(page); + cc->rpages[i] = NULL; + cc->nr_rpages--; + } +@@ -2498,6 +2516,8 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio) + return true; + if (f2fs_is_atomic_file(inode)) + return true; ++ if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) ++ return true; + + /* swap file is migrating in aligned write mode */ + if (is_inode_flag_set(inode, FI_ALIGNED_WRITE)) +diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c +index 456651682daf4..c250bf46ef5ed 100644 +--- a/fs/f2fs/dir.c ++++ b/fs/f2fs/dir.c +@@ -1000,6 +1000,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, + struct f2fs_sb_info *sbi = F2FS_I_SB(d->inode); + struct blk_plug plug; + bool readdir_ra = sbi->readdir_ra == 1; ++ bool found_valid_dirent = false; + int err = 0; + + bit_pos = ((unsigned long)ctx->pos % d->max); +@@ -1014,13 +1015,15 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, + + de = &d->dentry[bit_pos]; + if (de->name_len == 0) { ++ if (found_valid_dirent || !bit_pos) { ++ printk_ratelimited( ++ "%sF2FS-fs (%s): invalid namelen(0), ino:%u, run fsck to fix.", ++ KERN_WARNING, sbi->sb->s_id, ++ le32_to_cpu(de->ino)); ++ set_sbi_flag(sbi, SBI_NEED_FSCK); ++ } + bit_pos++; + ctx->pos = start_pos + bit_pos; +- printk_ratelimited( +- "%sF2FS-fs (%s): invalid namelen(0), ino:%u, run fsck to fix.", +- KERN_WARNING, sbi->sb->s_id, +- le32_to_cpu(de->ino)); +- set_sbi_flag(sbi, SBI_NEED_FSCK); + continue; + } + +@@ -1063,6 +1066,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, + f2fs_ra_node_page(sbi, le32_to_cpu(de->ino)); + + ctx->pos = start_pos + bit_pos; ++ found_valid_dirent = true; + } + out: + if (readdir_ra) +diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h +index ee8eb33e2c25c..db95829904e5c 100644 +--- a/fs/f2fs/f2fs.h ++++ b/fs/f2fs/f2fs.h +@@ -43,6 +43,7 @@ enum { + FAULT_KVMALLOC, + FAULT_PAGE_ALLOC, + FAULT_PAGE_GET, ++ FAULT_ALLOC_BIO, /* it's obsolete due to bio_alloc() will never fail */ + FAULT_ALLOC_NID, + FAULT_ORPHAN, + FAULT_BLOCK, +@@ -4137,7 +4138,8 @@ static inline void set_compress_context(struct inode *inode) + 1 << COMPRESS_CHKSUM : 0; + F2FS_I(inode)->i_cluster_size = + 1 << F2FS_I(inode)->i_log_cluster_size; +- if (F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 && ++ if ((F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 || ++ F2FS_I(inode)->i_compress_algorithm == COMPRESS_ZSTD) && + F2FS_OPTION(sbi).compress_level) + F2FS_I(inode)->i_compress_flag |= + F2FS_OPTION(sbi).compress_level << +diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c +index 97d48c5bdebcb..74f934da825f2 100644 +--- a/fs/f2fs/file.c ++++ b/fs/f2fs/file.c +@@ -1084,7 +1084,6 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len) + } + + if (pg_start < pg_end) { +- struct address_space *mapping = inode->i_mapping; + loff_t blk_start, blk_end; + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); + +@@ -1096,8 +1095,7 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len) + down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); + down_write(&F2FS_I(inode)->i_mmap_sem); + +- truncate_inode_pages_range(mapping, blk_start, +- blk_end - 1); ++ truncate_pagecache_range(inode, blk_start, blk_end - 1); + + f2fs_lock_op(sbi); + ret = f2fs_truncate_hole(inode, pg_start, pg_end); +diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c +index 0e42ee5f77707..70234a7040c88 100644 +--- a/fs/f2fs/gc.c ++++ b/fs/f2fs/gc.c +@@ -1497,8 +1497,10 @@ next_step: + int err; + + if (S_ISREG(inode->i_mode)) { +- if (!down_write_trylock(&fi->i_gc_rwsem[READ])) ++ if (!down_write_trylock(&fi->i_gc_rwsem[READ])) { ++ sbi->skipped_gc_rwsem++; + continue; ++ } + if (!down_write_trylock( + &fi->i_gc_rwsem[WRITE])) { + sbi->skipped_gc_rwsem++; +diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c +index 0be9e2d7120e3..1b0fe6e64b7d3 100644 +--- a/fs/f2fs/node.c ++++ b/fs/f2fs/node.c +@@ -1321,7 +1321,8 @@ static int read_node_page(struct page *page, int op_flags) + if (err) + return err; + +- if (unlikely(ni.blk_addr == NULL_ADDR) || ++ /* NEW_ADDR can be seen, after cp_error drops some dirty node pages */ ++ if (unlikely(ni.blk_addr == NULL_ADDR || ni.blk_addr == NEW_ADDR) || + is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN)) { + ClearPageUptodate(page); + return -ENOENT; +diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c +index 15cc89eef28d6..f9b7fb785e1d7 100644 +--- a/fs/f2fs/segment.c ++++ b/fs/f2fs/segment.c +@@ -3563,7 +3563,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) + goto drop_bio; + } + +- if (is_sbi_flag_set(sbi, SBI_NEED_FSCK) || f2fs_cp_error(sbi)) { ++ if (f2fs_cp_error(sbi)) { + err = -EIO; + goto drop_bio; + } +diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c +index ce703e6fdafc0..2b093a209ae40 100644 +--- a/fs/f2fs/super.c ++++ b/fs/f2fs/super.c +@@ -2071,11 +2071,10 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) + bool need_restart_ckpt = false, need_stop_ckpt = false; + bool need_restart_flush = false, need_stop_flush = false; + bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); +- bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT); ++ bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT); + bool no_io_align = !F2FS_IO_ALIGNED(sbi); + bool no_atgc = !test_opt(sbi, ATGC); + bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE); +- bool checkpoint_changed; + #ifdef CONFIG_QUOTA + int i, j; + #endif +@@ -2120,8 +2119,6 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) + err = parse_options(sb, data, true); + if (err) + goto restore_opts; +- checkpoint_changed = +- disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT); + + /* + * Previous and new state of filesystem is RO, +@@ -2243,7 +2240,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) + need_stop_flush = true; + } + +- if (checkpoint_changed) { ++ if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) { + if (test_opt(sbi, DISABLE_CHECKPOINT)) { + err = f2fs_disable_checkpoint(sbi); + if (err) +@@ -2527,6 +2524,33 @@ static int f2fs_enable_quotas(struct super_block *sb) + return 0; + } + ++static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type) ++{ ++ struct quota_info *dqopt = sb_dqopt(sbi->sb); ++ struct address_space *mapping = dqopt->files[type]->i_mapping; ++ int ret = 0; ++ ++ ret = dquot_writeback_dquots(sbi->sb, type); ++ if (ret) ++ goto out; ++ ++ ret = filemap_fdatawrite(mapping); ++ if (ret) ++ goto out; ++ ++ /* if we are using journalled quota */ ++ if (is_journalled_quota(sbi)) ++ goto out; ++ ++ ret = filemap_fdatawait(mapping); ++ ++ truncate_inode_pages(&dqopt->files[type]->i_data, 0); ++out: ++ if (ret) ++ set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); ++ return ret; ++} ++ + int f2fs_quota_sync(struct super_block *sb, int type) + { + struct f2fs_sb_info *sbi = F2FS_SB(sb); +@@ -2534,57 +2558,42 @@ int f2fs_quota_sync(struct super_block *sb, int type) + int cnt; + int ret; + +- /* +- * do_quotactl +- * f2fs_quota_sync +- * down_read(quota_sem) +- * dquot_writeback_dquots() +- * f2fs_dquot_commit +- * block_operation +- * down_read(quota_sem) +- */ +- f2fs_lock_op(sbi); +- +- down_read(&sbi->quota_sem); +- ret = dquot_writeback_dquots(sb, type); +- if (ret) +- goto out; +- + /* + * Now when everything is written we can discard the pagecache so + * that userspace sees the changes. + */ + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { +- struct address_space *mapping; + + if (type != -1 && cnt != type) + continue; +- if (!sb_has_quota_active(sb, cnt)) +- continue; + +- mapping = dqopt->files[cnt]->i_mapping; ++ if (!sb_has_quota_active(sb, type)) ++ return 0; + +- ret = filemap_fdatawrite(mapping); +- if (ret) +- goto out; ++ inode_lock(dqopt->files[cnt]); + +- /* if we are using journalled quota */ +- if (is_journalled_quota(sbi)) +- continue; ++ /* ++ * do_quotactl ++ * f2fs_quota_sync ++ * down_read(quota_sem) ++ * dquot_writeback_dquots() ++ * f2fs_dquot_commit ++ * block_operation ++ * down_read(quota_sem) ++ */ ++ f2fs_lock_op(sbi); ++ down_read(&sbi->quota_sem); + +- ret = filemap_fdatawait(mapping); +- if (ret) +- set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); ++ ret = f2fs_quota_sync_file(sbi, cnt); ++ ++ up_read(&sbi->quota_sem); ++ f2fs_unlock_op(sbi); + +- inode_lock(dqopt->files[cnt]); +- truncate_inode_pages(&dqopt->files[cnt]->i_data, 0); + inode_unlock(dqopt->files[cnt]); ++ ++ if (ret) ++ break; + } +-out: +- if (ret) +- set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); +- up_read(&sbi->quota_sem); +- f2fs_unlock_op(sbi); + return ret; + } + +@@ -3217,11 +3226,13 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, + return -EFSCORRUPTED; + } + +- if (le32_to_cpu(raw_super->cp_payload) > +- (blocks_per_seg - F2FS_CP_PACKS)) { +- f2fs_info(sbi, "Insane cp_payload (%u > %u)", ++ if (le32_to_cpu(raw_super->cp_payload) >= ++ (blocks_per_seg - F2FS_CP_PACKS - ++ NR_CURSEG_PERSIST_TYPE)) { ++ f2fs_info(sbi, "Insane cp_payload (%u >= %u)", + le32_to_cpu(raw_super->cp_payload), +- blocks_per_seg - F2FS_CP_PACKS); ++ blocks_per_seg - F2FS_CP_PACKS - ++ NR_CURSEG_PERSIST_TYPE); + return -EFSCORRUPTED; + } + +@@ -3257,6 +3268,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) + unsigned int cp_pack_start_sum, cp_payload; + block_t user_block_count, valid_user_blocks; + block_t avail_node_count, valid_node_count; ++ unsigned int nat_blocks, nat_bits_bytes, nat_bits_blocks; + int i, j; + + total = le32_to_cpu(raw_super->segment_count); +@@ -3387,6 +3399,17 @@ skip_cross: + return 1; + } + ++ nat_blocks = nat_segs << log_blocks_per_seg; ++ nat_bits_bytes = nat_blocks / BITS_PER_BYTE; ++ nat_bits_blocks = F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); ++ if (__is_set_ckpt_flags(ckpt, CP_NAT_BITS_FLAG) && ++ (cp_payload + F2FS_CP_PACKS + ++ NR_CURSEG_PERSIST_TYPE + nat_bits_blocks >= blocks_per_seg)) { ++ f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)", ++ cp_payload, nat_bits_blocks); ++ return -EFSCORRUPTED; ++ } ++ + if (unlikely(f2fs_cp_error(sbi))) { + f2fs_err(sbi, "A bug case: need to run fsck"); + return 1; +diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c +index 751bc5b1cddf9..6104f627cc712 100644 +--- a/fs/fscache/cookie.c ++++ b/fs/fscache/cookie.c +@@ -74,10 +74,8 @@ void fscache_free_cookie(struct fscache_cookie *cookie) + static int fscache_set_key(struct fscache_cookie *cookie, + const void *index_key, size_t index_key_len) + { +- unsigned long long h; + u32 *buf; + int bufs; +- int i; + + bufs = DIV_ROUND_UP(index_key_len, sizeof(*buf)); + +@@ -91,17 +89,7 @@ static int fscache_set_key(struct fscache_cookie *cookie, + } + + memcpy(buf, index_key, index_key_len); +- +- /* Calculate a hash and combine this with the length in the first word +- * or first half word +- */ +- h = (unsigned long)cookie->parent; +- h += index_key_len + cookie->type; +- +- for (i = 0; i < bufs; i++) +- h += buf[i]; +- +- cookie->key_hash = h ^ (h >> 32); ++ cookie->key_hash = fscache_hash(0, buf, bufs); + return 0; + } + +diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h +index c483863b740ad..aee639d980bad 100644 +--- a/fs/fscache/internal.h ++++ b/fs/fscache/internal.h +@@ -97,6 +97,8 @@ extern struct workqueue_struct *fscache_object_wq; + extern struct workqueue_struct *fscache_op_wq; + DECLARE_PER_CPU(wait_queue_head_t, fscache_object_cong_wait); + ++extern unsigned int fscache_hash(unsigned int salt, unsigned int *data, unsigned int n); ++ + static inline bool fscache_object_congested(void) + { + return workqueue_congested(WORK_CPU_UNBOUND, fscache_object_wq); +diff --git a/fs/fscache/main.c b/fs/fscache/main.c +index c1e6cc9091aac..4207f98e405fd 100644 +--- a/fs/fscache/main.c ++++ b/fs/fscache/main.c +@@ -93,6 +93,45 @@ static struct ctl_table fscache_sysctls_root[] = { + }; + #endif + ++/* ++ * Mixing scores (in bits) for (7,20): ++ * Input delta: 1-bit 2-bit ++ * 1 round: 330.3 9201.6 ++ * 2 rounds: 1246.4 25475.4 ++ * 3 rounds: 1907.1 31295.1 ++ * 4 rounds: 2042.3 31718.6 ++ * Perfect: 2048 31744 ++ * (32*64) (32*31/2 * 64) ++ */ ++#define HASH_MIX(x, y, a) \ ++ ( x ^= (a), \ ++ y ^= x, x = rol32(x, 7),\ ++ x += y, y = rol32(y,20),\ ++ y *= 9 ) ++ ++static inline unsigned int fold_hash(unsigned long x, unsigned long y) ++{ ++ /* Use arch-optimized multiply if one exists */ ++ return __hash_32(y ^ __hash_32(x)); ++} ++ ++/* ++ * Generate a hash. This is derived from full_name_hash(), but we want to be ++ * sure it is arch independent and that it doesn't change as bits of the ++ * computed hash value might appear on disk. The caller also guarantees that ++ * the hashed data will be a series of aligned 32-bit words. ++ */ ++unsigned int fscache_hash(unsigned int salt, unsigned int *data, unsigned int n) ++{ ++ unsigned int a, x = 0, y = salt; ++ ++ for (; n; n--) { ++ a = *data++; ++ HASH_MIX(x, y, a); ++ } ++ return fold_hash(x, y); ++} ++ + /* + * initialise the fs caching module + */ +diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c +index 54d3fbeb3002f..384565d63eea8 100644 +--- a/fs/gfs2/glops.c ++++ b/fs/gfs2/glops.c +@@ -610,16 +610,13 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl) + j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); + + error = gfs2_find_jhead(sdp->sd_jdesc, &head, false); +- if (error) +- gfs2_consist(sdp); +- if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) +- gfs2_consist(sdp); +- +- /* Initialize some head of the log stuff */ +- if (!gfs2_withdrawn(sdp)) { +- sdp->sd_log_sequence = head.lh_sequence + 1; +- gfs2_log_pointers_init(sdp, head.lh_blkno); +- } ++ if (gfs2_assert_withdraw_delayed(sdp, !error)) ++ return error; ++ if (gfs2_assert_withdraw_delayed(sdp, head.lh_flags & ++ GFS2_LOG_HEAD_UNMOUNT)) ++ return -EIO; ++ sdp->sd_log_sequence = head.lh_sequence + 1; ++ gfs2_log_pointers_init(sdp, head.lh_blkno); + } + return 0; + } +diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c +index dac040162ecc1..50578f881e6de 100644 +--- a/fs/gfs2/lock_dlm.c ++++ b/fs/gfs2/lock_dlm.c +@@ -299,6 +299,11 @@ static void gdlm_put_lock(struct gfs2_glock *gl) + gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT); + gfs2_update_request_times(gl); + ++ /* don't want to call dlm if we've unmounted the lock protocol */ ++ if (test_bit(DFL_UNMOUNT, &ls->ls_recover_flags)) { ++ gfs2_glock_free(gl); ++ return; ++ } + /* don't want to skip dlm_unlock writing the lvb when lock has one */ + + if (test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags) && +diff --git a/fs/io-wq.c b/fs/io-wq.c +index 2cc7f75ff24d7..cb5d84f6b7693 100644 +--- a/fs/io-wq.c ++++ b/fs/io-wq.c +@@ -236,9 +236,9 @@ static bool io_wqe_activate_free_worker(struct io_wqe *wqe) + * We need a worker. If we find a free one, we're good. If not, and we're + * below the max number of workers, create one. + */ +-static void io_wqe_wake_worker(struct io_wqe *wqe, struct io_wqe_acct *acct) ++static void io_wqe_create_worker(struct io_wqe *wqe, struct io_wqe_acct *acct) + { +- bool ret; ++ bool do_create = false, first = false; + + /* + * Most likely an attempt to queue unbounded work on an io_wq that +@@ -247,25 +247,18 @@ static void io_wqe_wake_worker(struct io_wqe *wqe, struct io_wqe_acct *acct) + if (unlikely(!acct->max_workers)) + pr_warn_once("io-wq is not configured for unbound workers"); + +- rcu_read_lock(); +- ret = io_wqe_activate_free_worker(wqe); +- rcu_read_unlock(); +- +- if (!ret) { +- bool do_create = false, first = false; +- +- raw_spin_lock_irq(&wqe->lock); +- if (acct->nr_workers < acct->max_workers) { +- atomic_inc(&acct->nr_running); +- atomic_inc(&wqe->wq->worker_refs); +- if (!acct->nr_workers) +- first = true; +- acct->nr_workers++; +- do_create = true; +- } +- raw_spin_unlock_irq(&wqe->lock); +- if (do_create) +- create_io_worker(wqe->wq, wqe, acct->index, first); ++ raw_spin_lock_irq(&wqe->lock); ++ if (acct->nr_workers < acct->max_workers) { ++ if (!acct->nr_workers) ++ first = true; ++ acct->nr_workers++; ++ do_create = true; ++ } ++ raw_spin_unlock_irq(&wqe->lock); ++ if (do_create) { ++ atomic_inc(&acct->nr_running); ++ atomic_inc(&wqe->wq->worker_refs); ++ create_io_worker(wqe->wq, wqe, acct->index, first); + } + } + +@@ -793,7 +786,8 @@ append: + static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work) + { + struct io_wqe_acct *acct = io_work_get_acct(wqe, work); +- int work_flags; ++ unsigned work_flags = work->flags; ++ bool do_create; + unsigned long flags; + + /* +@@ -806,15 +800,19 @@ static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work) + return; + } + +- work_flags = work->flags; + raw_spin_lock_irqsave(&wqe->lock, flags); + io_wqe_insert_work(wqe, work); + wqe->flags &= ~IO_WQE_FLAG_STALLED; ++ ++ rcu_read_lock(); ++ do_create = !io_wqe_activate_free_worker(wqe); ++ rcu_read_unlock(); ++ + raw_spin_unlock_irqrestore(&wqe->lock, flags); + +- if ((work_flags & IO_WQ_WORK_CONCURRENT) || +- !atomic_read(&acct->nr_running)) +- io_wqe_wake_worker(wqe, acct); ++ if (do_create && ((work_flags & IO_WQ_WORK_CONCURRENT) || ++ !atomic_read(&acct->nr_running))) ++ io_wqe_create_worker(wqe, acct); + } + + void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work) +diff --git a/fs/io_uring.c b/fs/io_uring.c +index 14bebc62db2d4..c5d4638f6d7fd 100644 +--- a/fs/io_uring.c ++++ b/fs/io_uring.c +@@ -3484,7 +3484,7 @@ static int io_renameat_prep(struct io_kiocb *req, + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->buf_index) ++ if (sqe->ioprio || sqe->buf_index || sqe->splice_fd_in) + return -EINVAL; + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; +@@ -3535,7 +3535,8 @@ static int io_unlinkat_prep(struct io_kiocb *req, + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->off || sqe->len || sqe->buf_index) ++ if (sqe->ioprio || sqe->off || sqe->len || sqe->buf_index || ++ sqe->splice_fd_in) + return -EINVAL; + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; +@@ -3581,8 +3582,8 @@ static int io_shutdown_prep(struct io_kiocb *req, + #if defined(CONFIG_NET) + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->off || sqe->addr || sqe->rw_flags || +- sqe->buf_index) ++ if (unlikely(sqe->ioprio || sqe->off || sqe->addr || sqe->rw_flags || ++ sqe->buf_index || sqe->splice_fd_in)) + return -EINVAL; + + req->shutdown.how = READ_ONCE(sqe->len); +@@ -3730,7 +3731,8 @@ static int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + + if (unlikely(ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (unlikely(sqe->addr || sqe->ioprio || sqe->buf_index)) ++ if (unlikely(sqe->addr || sqe->ioprio || sqe->buf_index || ++ sqe->splice_fd_in)) + return -EINVAL; + + req->sync.flags = READ_ONCE(sqe->fsync_flags); +@@ -3763,7 +3765,8 @@ static int io_fsync(struct io_kiocb *req, unsigned int issue_flags) + static int io_fallocate_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) + { +- if (sqe->ioprio || sqe->buf_index || sqe->rw_flags) ++ if (sqe->ioprio || sqe->buf_index || sqe->rw_flags || ++ sqe->splice_fd_in) + return -EINVAL; + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +@@ -3794,7 +3797,7 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe + const char __user *fname; + int ret; + +- if (unlikely(sqe->ioprio || sqe->buf_index)) ++ if (unlikely(sqe->ioprio || sqe->buf_index || sqe->splice_fd_in)) + return -EINVAL; + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; +@@ -3918,7 +3921,8 @@ static int io_remove_buffers_prep(struct io_kiocb *req, + struct io_provide_buf *p = &req->pbuf; + u64 tmp; + +- if (sqe->ioprio || sqe->rw_flags || sqe->addr || sqe->len || sqe->off) ++ if (sqe->ioprio || sqe->rw_flags || sqe->addr || sqe->len || sqe->off || ++ sqe->splice_fd_in) + return -EINVAL; + + tmp = READ_ONCE(sqe->fd); +@@ -3989,7 +3993,7 @@ static int io_provide_buffers_prep(struct io_kiocb *req, + struct io_provide_buf *p = &req->pbuf; + u64 tmp; + +- if (sqe->ioprio || sqe->rw_flags) ++ if (sqe->ioprio || sqe->rw_flags || sqe->splice_fd_in) + return -EINVAL; + + tmp = READ_ONCE(sqe->fd); +@@ -4076,7 +4080,7 @@ static int io_epoll_ctl_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) + { + #if defined(CONFIG_EPOLL) +- if (sqe->ioprio || sqe->buf_index) ++ if (sqe->ioprio || sqe->buf_index || sqe->splice_fd_in) + return -EINVAL; + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +@@ -4122,7 +4126,7 @@ static int io_epoll_ctl(struct io_kiocb *req, unsigned int issue_flags) + static int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + { + #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) +- if (sqe->ioprio || sqe->buf_index || sqe->off) ++ if (sqe->ioprio || sqe->buf_index || sqe->off || sqe->splice_fd_in) + return -EINVAL; + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +@@ -4157,7 +4161,7 @@ static int io_madvise(struct io_kiocb *req, unsigned int issue_flags) + + static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + { +- if (sqe->ioprio || sqe->buf_index || sqe->addr) ++ if (sqe->ioprio || sqe->buf_index || sqe->addr || sqe->splice_fd_in) + return -EINVAL; + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +@@ -4195,7 +4199,7 @@ static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + { + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->buf_index) ++ if (sqe->ioprio || sqe->buf_index || sqe->splice_fd_in) + return -EINVAL; + if (req->flags & REQ_F_FIXED_FILE) + return -EBADF; +@@ -4231,7 +4235,7 @@ static int io_close_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; + if (sqe->ioprio || sqe->off || sqe->addr || sqe->len || +- sqe->rw_flags || sqe->buf_index) ++ sqe->rw_flags || sqe->buf_index || sqe->splice_fd_in) + return -EINVAL; + if (req->flags & REQ_F_FIXED_FILE) + return -EBADF; +@@ -4292,7 +4296,8 @@ static int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + + if (unlikely(ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (unlikely(sqe->addr || sqe->ioprio || sqe->buf_index)) ++ if (unlikely(sqe->addr || sqe->ioprio || sqe->buf_index || ++ sqe->splice_fd_in)) + return -EINVAL; + + req->sync.off = READ_ONCE(sqe->off); +@@ -4719,7 +4724,7 @@ static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->len || sqe->buf_index) ++ if (sqe->ioprio || sqe->len || sqe->buf_index || sqe->splice_fd_in) + return -EINVAL; + + accept->addr = u64_to_user_ptr(READ_ONCE(sqe->addr)); +@@ -4767,7 +4772,8 @@ static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->len || sqe->buf_index || sqe->rw_flags) ++ if (sqe->ioprio || sqe->len || sqe->buf_index || sqe->rw_flags || ++ sqe->splice_fd_in) + return -EINVAL; + + conn->addr = u64_to_user_ptr(READ_ONCE(sqe->addr)); +@@ -5375,7 +5381,7 @@ static int io_poll_update_prep(struct io_kiocb *req, + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->buf_index) ++ if (sqe->ioprio || sqe->buf_index || sqe->splice_fd_in) + return -EINVAL; + flags = READ_ONCE(sqe->len); + if (flags & ~(IORING_POLL_UPDATE_EVENTS | IORING_POLL_UPDATE_USER_DATA | +@@ -5610,7 +5616,7 @@ static int io_timeout_remove_prep(struct io_kiocb *req, + return -EINVAL; + if (unlikely(req->flags & (REQ_F_FIXED_FILE | REQ_F_BUFFER_SELECT))) + return -EINVAL; +- if (sqe->ioprio || sqe->buf_index || sqe->len) ++ if (sqe->ioprio || sqe->buf_index || sqe->len || sqe->splice_fd_in) + return -EINVAL; + + tr->addr = READ_ONCE(sqe->addr); +@@ -5669,7 +5675,8 @@ static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe, + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; +- if (sqe->ioprio || sqe->buf_index || sqe->len != 1) ++ if (sqe->ioprio || sqe->buf_index || sqe->len != 1 || ++ sqe->splice_fd_in) + return -EINVAL; + if (off && is_timeout_link) + return -EINVAL; +@@ -5820,7 +5827,8 @@ static int io_async_cancel_prep(struct io_kiocb *req, + return -EINVAL; + if (unlikely(req->flags & (REQ_F_FIXED_FILE | REQ_F_BUFFER_SELECT))) + return -EINVAL; +- if (sqe->ioprio || sqe->off || sqe->len || sqe->cancel_flags) ++ if (sqe->ioprio || sqe->off || sqe->len || sqe->cancel_flags || ++ sqe->splice_fd_in) + return -EINVAL; + + req->cancel.addr = READ_ONCE(sqe->addr); +@@ -5877,7 +5885,7 @@ static int io_rsrc_update_prep(struct io_kiocb *req, + { + if (unlikely(req->flags & (REQ_F_FIXED_FILE | REQ_F_BUFFER_SELECT))) + return -EINVAL; +- if (sqe->ioprio || sqe->rw_flags) ++ if (sqe->ioprio || sqe->rw_flags || sqe->splice_fd_in) + return -EINVAL; + + req->rsrc_update.offset = READ_ONCE(sqe->off); +@@ -6302,6 +6310,7 @@ static void io_wq_submit_work(struct io_wq_work *work) + if (timeout) + io_queue_linked_timeout(timeout); + ++ /* either cancelled or io-wq is dying, so don't touch tctx->iowq */ + if (work->flags & IO_WQ_WORK_CANCEL) + ret = -ECANCELED; + +@@ -7126,14 +7135,14 @@ static void **io_alloc_page_table(size_t size) + size_t init_size = size; + void **table; + +- table = kcalloc(nr_tables, sizeof(*table), GFP_KERNEL); ++ table = kcalloc(nr_tables, sizeof(*table), GFP_KERNEL_ACCOUNT); + if (!table) + return NULL; + + for (i = 0; i < nr_tables; i++) { + unsigned int this_size = min_t(size_t, size, PAGE_SIZE); + +- table[i] = kzalloc(this_size, GFP_KERNEL); ++ table[i] = kzalloc(this_size, GFP_KERNEL_ACCOUNT); + if (!table[i]) { + io_free_page_table(table, init_size); + return NULL; +@@ -9129,8 +9138,8 @@ static void io_uring_clean_tctx(struct io_uring_task *tctx) + * Must be after io_uring_del_task_file() (removes nodes under + * uring_lock) to avoid race with io_uring_try_cancel_iowq(). + */ +- tctx->io_wq = NULL; + io_wq_put_and_exit(wq); ++ tctx->io_wq = NULL; + } + } + +diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c +index 87ccb3438becd..b06138c6190be 100644 +--- a/fs/iomap/buffered-io.c ++++ b/fs/iomap/buffered-io.c +@@ -1016,7 +1016,7 @@ iomap_finish_page_writeback(struct inode *inode, struct page *page, + + if (error) { + SetPageError(page); +- mapping_set_error(inode->i_mapping, -EIO); ++ mapping_set_error(inode->i_mapping, error); + } + + WARN_ON_ONCE(i_blocks_per_page(inode, page) > 1 && !iop); +diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c +index 498cb70c2c0d0..273a81971ed57 100644 +--- a/fs/lockd/svclock.c ++++ b/fs/lockd/svclock.c +@@ -395,28 +395,10 @@ nlmsvc_release_lockowner(struct nlm_lock *lock) + nlmsvc_put_lockowner(lock->fl.fl_owner); + } + +-static void nlmsvc_locks_copy_lock(struct file_lock *new, struct file_lock *fl) +-{ +- struct nlm_lockowner *nlm_lo = (struct nlm_lockowner *)fl->fl_owner; +- new->fl_owner = nlmsvc_get_lockowner(nlm_lo); +-} +- +-static void nlmsvc_locks_release_private(struct file_lock *fl) +-{ +- nlmsvc_put_lockowner((struct nlm_lockowner *)fl->fl_owner); +-} +- +-static const struct file_lock_operations nlmsvc_lock_ops = { +- .fl_copy_lock = nlmsvc_locks_copy_lock, +- .fl_release_private = nlmsvc_locks_release_private, +-}; +- + void nlmsvc_locks_init_private(struct file_lock *fl, struct nlm_host *host, + pid_t pid) + { + fl->fl_owner = nlmsvc_find_lockowner(host, pid); +- if (fl->fl_owner != NULL) +- fl->fl_ops = &nlmsvc_lock_ops; + } + + /* +@@ -788,9 +770,21 @@ nlmsvc_notify_blocked(struct file_lock *fl) + printk(KERN_WARNING "lockd: notification for unknown block!\n"); + } + ++static fl_owner_t nlmsvc_get_owner(fl_owner_t owner) ++{ ++ return nlmsvc_get_lockowner(owner); ++} ++ ++static void nlmsvc_put_owner(fl_owner_t owner) ++{ ++ nlmsvc_put_lockowner(owner); ++} ++ + const struct lock_manager_operations nlmsvc_lock_operations = { + .lm_notify = nlmsvc_notify_blocked, + .lm_grant = nlmsvc_grant_deferred, ++ .lm_get_owner = nlmsvc_get_owner, ++ .lm_put_owner = nlmsvc_put_owner, + }; + + /* +diff --git a/fs/nfs/export.c b/fs/nfs/export.c +index 37a1a88df7717..d772c20bbfd15 100644 +--- a/fs/nfs/export.c ++++ b/fs/nfs/export.c +@@ -180,5 +180,5 @@ const struct export_operations nfs_export_ops = { + .fetch_iversion = nfs_fetch_iversion, + .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK| + EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS| +- EXPORT_OP_NOATOMIC_ATTR, ++ EXPORT_OP_NOATOMIC_ATTR|EXPORT_OP_SYNC_LOCKS, + }; +diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c +index ef14ea0b6ab8d..51049499e98ff 100644 +--- a/fs/nfs/pnfs.c ++++ b/fs/nfs/pnfs.c +@@ -335,7 +335,7 @@ static bool pnfs_seqid_is_newer(u32 s1, u32 s2) + + static void pnfs_barrier_update(struct pnfs_layout_hdr *lo, u32 newseq) + { +- if (pnfs_seqid_is_newer(newseq, lo->plh_barrier)) ++ if (pnfs_seqid_is_newer(newseq, lo->plh_barrier) || !lo->plh_barrier) + lo->plh_barrier = newseq; + } + +@@ -347,11 +347,15 @@ pnfs_set_plh_return_info(struct pnfs_layout_hdr *lo, enum pnfs_iomode iomode, + iomode = IOMODE_ANY; + lo->plh_return_iomode = iomode; + set_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags); +- if (seq != 0) { +- WARN_ON_ONCE(lo->plh_return_seq != 0 && lo->plh_return_seq != seq); ++ /* ++ * We must set lo->plh_return_seq to avoid livelocks with ++ * pnfs_layout_need_return() ++ */ ++ if (seq == 0) ++ seq = be32_to_cpu(lo->plh_stateid.seqid); ++ if (!lo->plh_return_seq || pnfs_seqid_is_newer(seq, lo->plh_return_seq)) + lo->plh_return_seq = seq; +- pnfs_barrier_update(lo, seq); +- } ++ pnfs_barrier_update(lo, seq); + } + + static void +@@ -1000,7 +1004,7 @@ pnfs_layout_stateid_blocked(const struct pnfs_layout_hdr *lo, + { + u32 seqid = be32_to_cpu(stateid->seqid); + +- return !pnfs_seqid_is_newer(seqid, lo->plh_barrier) && lo->plh_barrier; ++ return lo->plh_barrier && pnfs_seqid_is_newer(lo->plh_barrier, seqid); + } + + /* lget is set to 1 if called from inside send_layoutget call chain */ +diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c +index 2bedc7839ec56..3d805f5b1f5d2 100644 +--- a/fs/nfsd/nfs4state.c ++++ b/fs/nfsd/nfs4state.c +@@ -6835,6 +6835,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, + struct nfsd4_blocked_lock *nbl = NULL; + struct file_lock *file_lock = NULL; + struct file_lock *conflock = NULL; ++ struct super_block *sb; + __be32 status = 0; + int lkflg; + int err; +@@ -6856,6 +6857,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, + dprintk("NFSD: nfsd4_lock: permission denied!\n"); + return status; + } ++ sb = cstate->current_fh.fh_dentry->d_sb; + + if (lock->lk_is_new) { + if (nfsd4_has_session(cstate)) +@@ -6904,7 +6906,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, + fp = lock_stp->st_stid.sc_file; + switch (lock->lk_type) { + case NFS4_READW_LT: +- if (nfsd4_has_session(cstate)) ++ if (nfsd4_has_session(cstate) && ++ !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS)) + fl_flags |= FL_SLEEP; + fallthrough; + case NFS4_READ_LT: +@@ -6916,7 +6919,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, + fl_type = F_RDLCK; + break; + case NFS4_WRITEW_LT: +- if (nfsd4_has_session(cstate)) ++ if (nfsd4_has_session(cstate) && ++ !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS)) + fl_flags |= FL_SLEEP; + fallthrough; + case NFS4_WRITE_LT: +@@ -7036,8 +7040,7 @@ out: + /* + * The NFSv4 spec allows a client to do a LOCKT without holding an OPEN, + * so we do a temporary open here just to get an open file to pass to +- * vfs_test_lock. (Arguably perhaps test_lock should be done with an +- * inode operation.) ++ * vfs_test_lock. + */ + static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock) + { +@@ -7052,7 +7055,9 @@ static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct + NFSD_MAY_READ)); + if (err) + goto out; ++ lock->fl_file = nf->nf_file; + err = nfserrno(vfs_test_lock(nf->nf_file, lock)); ++ lock->fl_file = NULL; + out: + fh_unlock(fhp); + nfsd_file_put(nf); +diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c +index 93efe7048a771..7c1850adec288 100644 +--- a/fs/overlayfs/dir.c ++++ b/fs/overlayfs/dir.c +@@ -542,8 +542,10 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, + goto out_cleanup; + } + err = ovl_instantiate(dentry, inode, newdentry, hardlink); +- if (err) +- goto out_cleanup; ++ if (err) { ++ ovl_cleanup(udir, newdentry); ++ dput(newdentry); ++ } + out_dput: + dput(upper); + out_unlock: +diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c +index 5c2d806e6ae53..c830cc4ea60fb 100644 +--- a/fs/userfaultfd.c ++++ b/fs/userfaultfd.c +@@ -33,11 +33,6 @@ int sysctl_unprivileged_userfaultfd __read_mostly; + + static struct kmem_cache *userfaultfd_ctx_cachep __read_mostly; + +-enum userfaultfd_state { +- UFFD_STATE_WAIT_API, +- UFFD_STATE_RUNNING, +-}; +- + /* + * Start with fault_pending_wqh and fault_wqh so they're more likely + * to be in the same cacheline. +@@ -69,8 +64,6 @@ struct userfaultfd_ctx { + unsigned int flags; + /* features requested from the userspace */ + unsigned int features; +- /* state machine */ +- enum userfaultfd_state state; + /* released */ + bool released; + /* memory mappings are changing because of non-cooperative event */ +@@ -104,6 +97,14 @@ struct userfaultfd_wake_range { + unsigned long len; + }; + ++/* internal indication that UFFD_API ioctl was successfully executed */ ++#define UFFD_FEATURE_INITIALIZED (1u << 31) ++ ++static bool userfaultfd_is_initialized(struct userfaultfd_ctx *ctx) ++{ ++ return ctx->features & UFFD_FEATURE_INITIALIZED; ++} ++ + static int userfaultfd_wake_function(wait_queue_entry_t *wq, unsigned mode, + int wake_flags, void *key) + { +@@ -666,7 +667,6 @@ int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs) + + refcount_set(&ctx->refcount, 1); + ctx->flags = octx->flags; +- ctx->state = UFFD_STATE_RUNNING; + ctx->features = octx->features; + ctx->released = false; + ctx->mmap_changing = false; +@@ -943,38 +943,33 @@ static __poll_t userfaultfd_poll(struct file *file, poll_table *wait) + + poll_wait(file, &ctx->fd_wqh, wait); + +- switch (ctx->state) { +- case UFFD_STATE_WAIT_API: ++ if (!userfaultfd_is_initialized(ctx)) + return EPOLLERR; +- case UFFD_STATE_RUNNING: +- /* +- * poll() never guarantees that read won't block. +- * userfaults can be waken before they're read(). +- */ +- if (unlikely(!(file->f_flags & O_NONBLOCK))) +- return EPOLLERR; +- /* +- * lockless access to see if there are pending faults +- * __pollwait last action is the add_wait_queue but +- * the spin_unlock would allow the waitqueue_active to +- * pass above the actual list_add inside +- * add_wait_queue critical section. So use a full +- * memory barrier to serialize the list_add write of +- * add_wait_queue() with the waitqueue_active read +- * below. +- */ +- ret = 0; +- smp_mb(); +- if (waitqueue_active(&ctx->fault_pending_wqh)) +- ret = EPOLLIN; +- else if (waitqueue_active(&ctx->event_wqh)) +- ret = EPOLLIN; + +- return ret; +- default: +- WARN_ON_ONCE(1); ++ /* ++ * poll() never guarantees that read won't block. ++ * userfaults can be waken before they're read(). ++ */ ++ if (unlikely(!(file->f_flags & O_NONBLOCK))) + return EPOLLERR; +- } ++ /* ++ * lockless access to see if there are pending faults ++ * __pollwait last action is the add_wait_queue but ++ * the spin_unlock would allow the waitqueue_active to ++ * pass above the actual list_add inside ++ * add_wait_queue critical section. So use a full ++ * memory barrier to serialize the list_add write of ++ * add_wait_queue() with the waitqueue_active read ++ * below. ++ */ ++ ret = 0; ++ smp_mb(); ++ if (waitqueue_active(&ctx->fault_pending_wqh)) ++ ret = EPOLLIN; ++ else if (waitqueue_active(&ctx->event_wqh)) ++ ret = EPOLLIN; ++ ++ return ret; + } + + static const struct file_operations userfaultfd_fops; +@@ -1169,7 +1164,7 @@ static ssize_t userfaultfd_read(struct file *file, char __user *buf, + int no_wait = file->f_flags & O_NONBLOCK; + struct inode *inode = file_inode(file); + +- if (ctx->state == UFFD_STATE_WAIT_API) ++ if (!userfaultfd_is_initialized(ctx)) + return -EINVAL; + + for (;;) { +@@ -1908,9 +1903,10 @@ out: + static inline unsigned int uffd_ctx_features(__u64 user_features) + { + /* +- * For the current set of features the bits just coincide ++ * For the current set of features the bits just coincide. Set ++ * UFFD_FEATURE_INITIALIZED to mark the features as enabled. + */ +- return (unsigned int)user_features; ++ return (unsigned int)user_features | UFFD_FEATURE_INITIALIZED; + } + + /* +@@ -1923,12 +1919,10 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, + { + struct uffdio_api uffdio_api; + void __user *buf = (void __user *)arg; ++ unsigned int ctx_features; + int ret; + __u64 features; + +- ret = -EINVAL; +- if (ctx->state != UFFD_STATE_WAIT_API) +- goto out; + ret = -EFAULT; + if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api))) + goto out; +@@ -1952,9 +1946,13 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, + ret = -EFAULT; + if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) + goto out; +- ctx->state = UFFD_STATE_RUNNING; ++ + /* only enable the requested features for this uffd context */ +- ctx->features = uffd_ctx_features(features); ++ ctx_features = uffd_ctx_features(features); ++ ret = -EINVAL; ++ if (cmpxchg(&ctx->features, 0, ctx_features) != 0) ++ goto err_out; ++ + ret = 0; + out: + return ret; +@@ -1971,7 +1969,7 @@ static long userfaultfd_ioctl(struct file *file, unsigned cmd, + int ret = -EINVAL; + struct userfaultfd_ctx *ctx = file->private_data; + +- if (cmd != UFFDIO_API && ctx->state == UFFD_STATE_WAIT_API) ++ if (cmd != UFFDIO_API && !userfaultfd_is_initialized(ctx)) + return -EINVAL; + + switch(cmd) { +@@ -2085,7 +2083,6 @@ SYSCALL_DEFINE1(userfaultfd, int, flags) + refcount_set(&ctx->refcount, 1); + ctx->flags = flags; + ctx->features = 0; +- ctx->state = UFFD_STATE_WAIT_API; + ctx->released = false; + ctx->mmap_changing = false; + ctx->mm = current->mm; +diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h +index 47accec68cb0f..f603325c0c30d 100644 +--- a/include/crypto/public_key.h ++++ b/include/crypto/public_key.h +@@ -38,9 +38,9 @@ extern void public_key_free(struct public_key *key); + struct public_key_signature { + struct asymmetric_key_id *auth_ids[2]; + u8 *s; /* Signature */ +- u32 s_size; /* Number of bytes in signature */ + u8 *digest; +- u8 digest_size; /* Number of bytes in digest */ ++ u32 s_size; /* Number of bytes in signature */ ++ u32 digest_size; /* Number of bytes in digest */ + const char *pkey_algo; + const char *hash_algo; + const char *encoding; +diff --git a/include/drm/drm_auth.h b/include/drm/drm_auth.h +index 6bf8b2b789919..f99d3417f3042 100644 +--- a/include/drm/drm_auth.h ++++ b/include/drm/drm_auth.h +@@ -107,6 +107,7 @@ struct drm_master { + }; + + struct drm_master *drm_master_get(struct drm_master *master); ++struct drm_master *drm_file_get_master(struct drm_file *file_priv); + void drm_master_put(struct drm_master **master); + bool drm_is_current_master(struct drm_file *fpriv); + +diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h +index b81b3bfb08c8d..726cfe0ff5f5c 100644 +--- a/include/drm/drm_file.h ++++ b/include/drm/drm_file.h +@@ -226,15 +226,27 @@ struct drm_file { + /** + * @master: + * +- * Master this node is currently associated with. Only relevant if +- * drm_is_primary_client() returns true. Note that this only +- * matches &drm_device.master if the master is the currently active one. ++ * Master this node is currently associated with. Protected by struct ++ * &drm_device.master_mutex, and serialized by @master_lookup_lock. ++ * ++ * Only relevant if drm_is_primary_client() returns true. Note that ++ * this only matches &drm_device.master if the master is the currently ++ * active one. ++ * ++ * When dereferencing this pointer, either hold struct ++ * &drm_device.master_mutex for the duration of the pointer's use, or ++ * use drm_file_get_master() if struct &drm_device.master_mutex is not ++ * currently held and there is no other need to hold it. This prevents ++ * @master from being freed during use. + * + * See also @authentication and @is_master and the :ref:`section on + * primary nodes and authentication `. + */ + struct drm_master *master; + ++ /** @master_lock: Serializes @master. */ ++ spinlock_t master_lookup_lock; ++ + /** @pid: Process that opened this file. */ + struct pid *pid; + +diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h +index 232daaec56e44..4711b96dae0c7 100644 +--- a/include/linux/ethtool.h ++++ b/include/linux/ethtool.h +@@ -17,8 +17,6 @@ + #include + #include + +-#ifdef CONFIG_COMPAT +- + struct compat_ethtool_rx_flow_spec { + u32 flow_type; + union ethtool_flow_union h_u; +@@ -38,8 +36,6 @@ struct compat_ethtool_rxnfc { + u32 rule_locs[]; + }; + +-#endif /* CONFIG_COMPAT */ +- + #include + + /** +diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h +index fe848901fcc3a..3260fe7148462 100644 +--- a/include/linux/exportfs.h ++++ b/include/linux/exportfs.h +@@ -221,6 +221,8 @@ struct export_operations { + #define EXPORT_OP_NOATOMIC_ATTR (0x10) /* Filesystem cannot supply + atomic attribute updates + */ ++#define EXPORT_OP_SYNC_LOCKS (0x20) /* Filesystem can't do ++ asychronous blocking locks */ + unsigned long flags; + }; + +diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h +index f7ca1a3870ea5..1faebe1cd0ed5 100644 +--- a/include/linux/hugetlb.h ++++ b/include/linux/hugetlb.h +@@ -858,6 +858,11 @@ static inline spinlock_t *huge_pte_lockptr(struct hstate *h, + + void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm); + ++static inline void hugetlb_count_init(struct mm_struct *mm) ++{ ++ atomic_long_set(&mm->hugetlb_usage, 0); ++} ++ + static inline void hugetlb_count_add(long l, struct mm_struct *mm) + { + atomic_long_add(l, &mm->hugetlb_usage); +@@ -1042,6 +1047,10 @@ static inline spinlock_t *huge_pte_lockptr(struct hstate *h, + return &mm->page_table_lock; + } + ++static inline void hugetlb_count_init(struct mm_struct *mm) ++{ ++} ++ + static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m) + { + } +diff --git a/include/linux/hugetlb_cgroup.h b/include/linux/hugetlb_cgroup.h +index 0b8d1fdda3a11..c137396129db6 100644 +--- a/include/linux/hugetlb_cgroup.h ++++ b/include/linux/hugetlb_cgroup.h +@@ -121,6 +121,13 @@ static inline void hugetlb_cgroup_put_rsvd_cgroup(struct hugetlb_cgroup *h_cg) + css_put(&h_cg->css); + } + ++static inline void resv_map_dup_hugetlb_cgroup_uncharge_info( ++ struct resv_map *resv_map) ++{ ++ if (resv_map->css) ++ css_get(resv_map->css); ++} ++ + extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, + struct hugetlb_cgroup **ptr); + extern int hugetlb_cgroup_charge_cgroup_rsvd(int idx, unsigned long nr_pages, +@@ -199,6 +206,11 @@ static inline void hugetlb_cgroup_put_rsvd_cgroup(struct hugetlb_cgroup *h_cg) + { + } + ++static inline void resv_map_dup_hugetlb_cgroup_uncharge_info( ++ struct resv_map *resv_map) ++{ ++} ++ + static inline int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, + struct hugetlb_cgroup **ptr) + { +diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h +index d0fa0b31994d0..05a65eb155f76 100644 +--- a/include/linux/intel-iommu.h ++++ b/include/linux/intel-iommu.h +@@ -124,9 +124,9 @@ + #define DMAR_MTRR_PHYSMASK8_REG 0x208 + #define DMAR_MTRR_PHYSBASE9_REG 0x210 + #define DMAR_MTRR_PHYSMASK9_REG 0x218 +-#define DMAR_VCCAP_REG 0xe00 /* Virtual command capability register */ +-#define DMAR_VCMD_REG 0xe10 /* Virtual command register */ +-#define DMAR_VCRSP_REG 0xe20 /* Virtual command response register */ ++#define DMAR_VCCAP_REG 0xe30 /* Virtual command capability register */ ++#define DMAR_VCMD_REG 0xe00 /* Virtual command register */ ++#define DMAR_VCRSP_REG 0xe10 /* Virtual command response register */ + + #define DMAR_IQER_REG_IQEI(reg) FIELD_GET(GENMASK_ULL(3, 0), reg) + #define DMAR_IQER_REG_ITESID(reg) FIELD_GET(GENMASK_ULL(47, 32), reg) +diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h +index a7fd2c3ccb777..d01b504ce06fe 100644 +--- a/include/linux/memory_hotplug.h ++++ b/include/linux/memory_hotplug.h +@@ -339,8 +339,8 @@ extern void sparse_remove_section(struct mem_section *ms, + unsigned long map_offset, struct vmem_altmap *altmap); + extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, + unsigned long pnum); +-extern struct zone *zone_for_pfn_range(int online_type, int nid, unsigned start_pfn, +- unsigned long nr_pages); ++extern struct zone *zone_for_pfn_range(int online_type, int nid, ++ unsigned long start_pfn, unsigned long nr_pages); + extern int arch_create_linear_mapping(int nid, u64 start, u64 size, + struct mhp_params *params); + void arch_remove_linear_mapping(u64 start, u64 size); +diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h +index d9680b798b211..955c82b4737c5 100644 +--- a/include/linux/rcupdate.h ++++ b/include/linux/rcupdate.h +@@ -167,7 +167,7 @@ void synchronize_rcu_tasks(void); + # define synchronize_rcu_tasks synchronize_rcu + # endif + +-# ifdef CONFIG_TASKS_RCU_TRACE ++# ifdef CONFIG_TASKS_TRACE_RCU + # define rcu_tasks_trace_qs(t) \ + do { \ + if (!likely(READ_ONCE((t)->trc_reader_checked)) && \ +diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h +index d1672de9ca89e..87b325aec5085 100644 +--- a/include/linux/rtmutex.h ++++ b/include/linux/rtmutex.h +@@ -52,17 +52,22 @@ do { \ + } while (0) + + #ifdef CONFIG_DEBUG_LOCK_ALLOC +-#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ +- , .dep_map = { .name = #mutexname } ++#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ ++ .dep_map = { \ ++ .name = #mutexname, \ ++ .wait_type_inner = LD_WAIT_SLEEP, \ ++ } + #else + #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) + #endif + +-#define __RT_MUTEX_INITIALIZER(mutexname) \ +- { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ +- , .waiters = RB_ROOT_CACHED \ +- , .owner = NULL \ +- __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)} ++#define __RT_MUTEX_INITIALIZER(mutexname) \ ++{ \ ++ .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock), \ ++ .waiters = RB_ROOT_CACHED, \ ++ .owner = NULL, \ ++ __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ ++} + + #define DEFINE_RT_MUTEX(mutexname) \ + struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) +diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h +index c8c39f22d3b16..59cd97da895b7 100644 +--- a/include/linux/sunrpc/xprt.h ++++ b/include/linux/sunrpc/xprt.h +@@ -432,6 +432,7 @@ void xprt_release_write(struct rpc_xprt *, struct rpc_task *); + #define XPRT_CONGESTED (9) + #define XPRT_CWND_WAIT (10) + #define XPRT_WRITE_SPACE (11) ++#define XPRT_SND_IS_COOKIE (12) + + static inline void xprt_set_connected(struct rpc_xprt *xprt) + { +diff --git a/include/linux/vt_kern.h b/include/linux/vt_kern.h +index 0da94a6dee15e..b5ab452fca5b5 100644 +--- a/include/linux/vt_kern.h ++++ b/include/linux/vt_kern.h +@@ -148,26 +148,26 @@ void hide_boot_cursor(bool hide); + + /* keyboard provided interfaces */ + int vt_do_diacrit(unsigned int cmd, void __user *up, int eperm); +-int vt_do_kdskbmode(int console, unsigned int arg); +-int vt_do_kdskbmeta(int console, unsigned int arg); ++int vt_do_kdskbmode(unsigned int console, unsigned int arg); ++int vt_do_kdskbmeta(unsigned int console, unsigned int arg); + int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, + int perm); + int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, +- int console); ++ unsigned int console); + int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm); +-int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm); +-int vt_do_kdgkbmode(int console); +-int vt_do_kdgkbmeta(int console); +-void vt_reset_unicode(int console); ++int vt_do_kdskled(unsigned int console, int cmd, unsigned long arg, int perm); ++int vt_do_kdgkbmode(unsigned int console); ++int vt_do_kdgkbmeta(unsigned int console); ++void vt_reset_unicode(unsigned int console); + int vt_get_shift_state(void); +-void vt_reset_keyboard(int console); +-int vt_get_leds(int console, int flag); +-int vt_get_kbd_mode_bit(int console, int bit); +-void vt_set_kbd_mode_bit(int console, int bit); +-void vt_clr_kbd_mode_bit(int console, int bit); +-void vt_set_led_state(int console, int leds); +-void vt_kbd_con_start(int console); +-void vt_kbd_con_stop(int console); ++void vt_reset_keyboard(unsigned int console); ++int vt_get_leds(unsigned int console, int flag); ++int vt_get_kbd_mode_bit(unsigned int console, int bit); ++void vt_set_kbd_mode_bit(unsigned int console, int bit); ++void vt_clr_kbd_mode_bit(unsigned int console, int bit); ++void vt_set_led_state(unsigned int console, int leds); ++void vt_kbd_con_start(unsigned int console); ++void vt_kbd_con_stop(unsigned int console); + + void vc_scrolldelta_helper(struct vc_data *c, int lines, + unsigned int rolled_over, void *_base, unsigned int size); +diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h +index db4312e44d470..c17e5557a0078 100644 +--- a/include/net/bluetooth/hci_core.h ++++ b/include/net/bluetooth/hci_core.h +@@ -1412,6 +1412,10 @@ void hci_conn_del_sysfs(struct hci_conn *conn); + !hci_dev_test_flag(dev, HCI_AUTO_OFF)) + #define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \ + hci_dev_test_flag(dev, HCI_SC_ENABLED)) ++#define rpa_valid(dev) (bacmp(&dev->rpa, BDADDR_ANY) && \ ++ !hci_dev_test_flag(dev, HCI_RPA_EXPIRED)) ++#define adv_rpa_valid(adv) (bacmp(&adv->random_addr, BDADDR_ANY) && \ ++ !adv->rpa_expired) + + #define scan_1m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_1M) || \ + ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_1M)) +diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h +index 1b9d75aedb225..3961461d9c8bc 100644 +--- a/include/net/flow_offload.h ++++ b/include/net/flow_offload.h +@@ -451,6 +451,7 @@ struct flow_block_offload { + struct list_head *driver_block_list; + struct netlink_ext_ack *extack; + struct Qdisc *sch; ++ struct list_head *cb_list_head; + }; + + enum tc_setup_type; +diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h +index b671b1f2ce0fd..3b93509af246c 100644 +--- a/include/trace/events/btrfs.h ++++ b/include/trace/events/btrfs.h +@@ -94,6 +94,7 @@ struct btrfs_space_info; + EM( FLUSH_DELAYED_ITEMS, "FLUSH_DELAYED_ITEMS") \ + EM( FLUSH_DELALLOC, "FLUSH_DELALLOC") \ + EM( FLUSH_DELALLOC_WAIT, "FLUSH_DELALLOC_WAIT") \ ++ EM( FLUSH_DELALLOC_FULL, "FLUSH_DELALLOC_FULL") \ + EM( FLUSH_DELAYED_REFS_NR, "FLUSH_DELAYED_REFS_NR") \ + EM( FLUSH_DELAYED_REFS, "FLUSH_ELAYED_REFS") \ + EM( ALLOC_CHUNK, "ALLOC_CHUNK") \ +diff --git a/include/uapi/linux/serial_reg.h b/include/uapi/linux/serial_reg.h +index be07b5470f4bb..f51bc8f368134 100644 +--- a/include/uapi/linux/serial_reg.h ++++ b/include/uapi/linux/serial_reg.h +@@ -62,6 +62,7 @@ + * ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 + * TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 + * TI16C752: 8 16 56 60 8 16 32 56 ++ * OX16C950: 16 32 112 120 16 32 64 112 PORT_16C950 + * Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA + */ + #define UART_FCR_R_TRIG_00 0x00 +diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c +index dadae6255d055..f2faa13534e57 100644 +--- a/kernel/dma/debug.c ++++ b/kernel/dma/debug.c +@@ -792,7 +792,7 @@ static int dump_show(struct seq_file *seq, void *v) + } + DEFINE_SHOW_ATTRIBUTE(dump); + +-static void dma_debug_fs_init(void) ++static int __init dma_debug_fs_init(void) + { + struct dentry *dentry = debugfs_create_dir("dma-api", NULL); + +@@ -805,7 +805,10 @@ static void dma_debug_fs_init(void) + debugfs_create_u32("nr_total_entries", 0444, dentry, &nr_total_entries); + debugfs_create_file("driver_filter", 0644, dentry, NULL, &filter_fops); + debugfs_create_file("dump", 0444, dentry, NULL, &dump_fops); ++ ++ return 0; + } ++core_initcall_sync(dma_debug_fs_init); + + static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry) + { +@@ -890,8 +893,6 @@ static int dma_debug_init(void) + spin_lock_init(&dma_entry_hash[i].lock); + } + +- dma_debug_fs_init(); +- + nr_pages = DIV_ROUND_UP(nr_prealloc_entries, DMA_DEBUG_DYNAMIC_ENTRIES); + for (i = 0; i < nr_pages; ++i) + dma_debug_create_entries(GFP_KERNEL); +diff --git a/kernel/fork.c b/kernel/fork.c +index 44f4c2d83763f..cbba21e3a58df 100644 +--- a/kernel/fork.c ++++ b/kernel/fork.c +@@ -1050,6 +1050,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, + mm->pmd_huge_pte = NULL; + #endif + mm_init_uprobes_state(mm); ++ hugetlb_count_init(mm); + + if (current->mm) { + mm->flags = current->mm->flags & MMF_INIT_MASK; +diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c +index ad0db322ed3b4..1a7e3f838077b 100644 +--- a/kernel/locking/rtmutex.c ++++ b/kernel/locking/rtmutex.c +@@ -1556,7 +1556,7 @@ void __sched __rt_mutex_init(struct rt_mutex *lock, const char *name, + struct lock_class_key *key) + { + debug_check_no_locks_freed((void *)lock, sizeof(*lock)); +- lockdep_init_map(&lock->dep_map, name, key, 0); ++ lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP); + + __rt_mutex_basic_init(lock); + } +diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c +index ca43239a255ad..cb5a25a8a0cc7 100644 +--- a/kernel/pid_namespace.c ++++ b/kernel/pid_namespace.c +@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cachep(unsigned int level) + mutex_lock(&pid_caches_mutex); + /* Name collision forces to do allocation under mutex. */ + if (!*pkc) +- *pkc = kmem_cache_create(name, len, 0, SLAB_HWCACHE_ALIGN, 0); ++ *pkc = kmem_cache_create(name, len, 0, ++ SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, 0); + mutex_unlock(&pid_caches_mutex); + /* current can fail, but someone else can succeed. */ + return READ_ONCE(*pkc); +diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c +index 142a58d124d95..6dad7da8f383e 100644 +--- a/kernel/printk/printk.c ++++ b/kernel/printk/printk.c +@@ -2545,6 +2545,7 @@ void console_unlock(void) + bool do_cond_resched, retry; + struct printk_info info; + struct printk_record r; ++ u64 __maybe_unused next_seq; + + if (console_suspended) { + up_console_sem(); +@@ -2654,8 +2655,10 @@ skip: + cond_resched(); + } + +- console_locked = 0; ++ /* Get consistent value of the next-to-be-used sequence number. */ ++ next_seq = console_seq; + ++ console_locked = 0; + up_console_sem(); + + /* +@@ -2664,7 +2667,7 @@ skip: + * there's a new owner and the console_unlock() from them will do the + * flush, no worries. + */ +- retry = prb_read_valid(prb, console_seq, NULL); ++ retry = prb_read_valid(prb, next_seq, NULL); + printk_safe_exit_irqrestore(flags); + + if (retry && console_trylock()) +diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h +index de1dc3bb7f701..6ce104242b23d 100644 +--- a/kernel/rcu/tree_plugin.h ++++ b/kernel/rcu/tree_plugin.h +@@ -2982,17 +2982,17 @@ static void noinstr rcu_dynticks_task_exit(void) + /* Turn on heavyweight RCU tasks trace readers on idle/user entry. */ + static void rcu_dynticks_task_trace_enter(void) + { +-#ifdef CONFIG_TASKS_RCU_TRACE ++#ifdef CONFIG_TASKS_TRACE_RCU + if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB)) + current->trc_reader_special.b.need_mb = true; +-#endif /* #ifdef CONFIG_TASKS_RCU_TRACE */ ++#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ + } + + /* Turn off heavyweight RCU tasks trace readers on idle/user exit. */ + static void rcu_dynticks_task_trace_exit(void) + { +-#ifdef CONFIG_TASKS_RCU_TRACE ++#ifdef CONFIG_TASKS_TRACE_RCU + if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB)) + current->trc_reader_special.b.need_mb = false; +-#endif /* #ifdef CONFIG_TASKS_RCU_TRACE */ ++#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ + } +diff --git a/kernel/sched/core.c b/kernel/sched/core.c +index a2403432f3abb..399c37c95392e 100644 +--- a/kernel/sched/core.c ++++ b/kernel/sched/core.c +@@ -8536,7 +8536,6 @@ static void balance_push(struct rq *rq) + struct task_struct *push_task = rq->curr; + + lockdep_assert_rq_held(rq); +- SCHED_WARN_ON(rq->cpu != smp_processor_id()); + + /* + * Ensure the thing is persistent until balance_push_set(.on = false); +@@ -8544,9 +8543,10 @@ static void balance_push(struct rq *rq) + rq->balance_callback = &balance_push_callback; + + /* +- * Only active while going offline. ++ * Only active while going offline and when invoked on the outgoing ++ * CPU. + */ +- if (!cpu_dying(rq->cpu)) ++ if (!cpu_dying(rq->cpu) || rq != this_rq()) + return; + + /* +diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c +index b61eefe5ccf53..7b3c754821e55 100644 +--- a/kernel/trace/trace_osnoise.c ++++ b/kernel/trace/trace_osnoise.c +@@ -1548,7 +1548,7 @@ static int start_kthread(unsigned int cpu) + static int start_per_cpu_kthreads(struct trace_array *tr) + { + struct cpumask *current_mask = &save_cpumask; +- int retval; ++ int retval = 0; + int cpu; + + get_online_cpus(); +@@ -1568,13 +1568,13 @@ static int start_per_cpu_kthreads(struct trace_array *tr) + retval = start_kthread(cpu); + if (retval) { + stop_per_cpu_kthreads(); +- return retval; ++ break; + } + } + + put_online_cpus(); + +- return 0; ++ return retval; + } + + #ifdef CONFIG_HOTPLUG_CPU +diff --git a/kernel/workqueue.c b/kernel/workqueue.c +index f148eacda55a9..542c2d03dab65 100644 +--- a/kernel/workqueue.c ++++ b/kernel/workqueue.c +@@ -5902,6 +5902,13 @@ static void __init wq_numa_init(void) + return; + } + ++ for_each_possible_cpu(cpu) { ++ if (WARN_ON(cpu_to_node(cpu) == NUMA_NO_NODE)) { ++ pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu); ++ return; ++ } ++ } ++ + wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs(); + BUG_ON(!wq_update_unbound_numa_attrs_buf); + +@@ -5919,11 +5926,6 @@ static void __init wq_numa_init(void) + + for_each_possible_cpu(cpu) { + node = cpu_to_node(cpu); +- if (WARN_ON(node == NUMA_NO_NODE)) { +- pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu); +- /* happens iff arch is bonkers, let's just proceed */ +- return; +- } + cpumask_set_cpu(cpu, tbl[node]); + } + +diff --git a/lib/test_bpf.c b/lib/test_bpf.c +index d500320778c76..f6d5d30d01bf2 100644 +--- a/lib/test_bpf.c ++++ b/lib/test_bpf.c +@@ -4286,8 +4286,8 @@ static struct bpf_test tests[] = { + .u.insns_int = { + BPF_LD_IMM64(R0, 0), + BPF_LD_IMM64(R1, 0xffffffffffffffffLL), +- BPF_STX_MEM(BPF_W, R10, R1, -40), +- BPF_LDX_MEM(BPF_W, R0, R10, -40), ++ BPF_STX_MEM(BPF_DW, R10, R1, -40), ++ BPF_LDX_MEM(BPF_DW, R0, R10, -40), + BPF_EXIT_INSN(), + }, + INTERNAL, +@@ -6659,7 +6659,14 @@ static int run_one(const struct bpf_prog *fp, struct bpf_test *test) + u64 duration; + u32 ret; + +- if (test->test[i].data_size == 0 && ++ /* ++ * NOTE: Several sub-tests may be present, in which case ++ * a zero {data_size, result} tuple indicates the end of ++ * the sub-test array. The first test is always run, ++ * even if both data_size and result happen to be zero. ++ */ ++ if (i > 0 && ++ test->test[i].data_size == 0 && + test->test[i].result == 0) + break; + +diff --git a/lib/test_stackinit.c b/lib/test_stackinit.c +index f93b1e145ada7..16b1d3a3a4975 100644 +--- a/lib/test_stackinit.c ++++ b/lib/test_stackinit.c +@@ -67,10 +67,10 @@ static bool range_contains(char *haystack_start, size_t haystack_size, + #define INIT_STRUCT_none /**/ + #define INIT_STRUCT_zero = { } + #define INIT_STRUCT_static_partial = { .two = 0, } +-#define INIT_STRUCT_static_all = { .one = arg->one, \ +- .two = arg->two, \ +- .three = arg->three, \ +- .four = arg->four, \ ++#define INIT_STRUCT_static_all = { .one = 0, \ ++ .two = 0, \ ++ .three = 0, \ ++ .four = 0, \ + } + #define INIT_STRUCT_dynamic_partial = { .two = arg->two, } + #define INIT_STRUCT_dynamic_all = { .one = arg->one, \ +@@ -84,8 +84,7 @@ static bool range_contains(char *haystack_start, size_t haystack_size, + var.one = 0; \ + var.two = 0; \ + var.three = 0; \ +- memset(&var.four, 0, \ +- sizeof(var.four)) ++ var.four = 0 + + /* + * @name: unique string name for the test +@@ -210,18 +209,13 @@ struct test_small_hole { + unsigned long four; + }; + +-/* Try to trigger unhandled padding in a structure. */ +-struct test_aligned { +- u32 internal1; +- u64 internal2; +-} __aligned(64); +- ++/* Trigger unhandled padding in a structure. */ + struct test_big_hole { + u8 one; + u8 two; + u8 three; + /* 61 byte padding hole here. */ +- struct test_aligned four; ++ u8 four __aligned(64); + } __aligned(64); + + struct test_trailing_hole { +diff --git a/mm/hmm.c b/mm/hmm.c +index fad6be2bf0727..842e265992380 100644 +--- a/mm/hmm.c ++++ b/mm/hmm.c +@@ -295,10 +295,13 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, + goto fault; + + /* ++ * Bypass devmap pte such as DAX page when all pfn requested ++ * flags(pfn_req_flags) are fulfilled. + * Since each architecture defines a struct page for the zero page, just + * fall through and treat it like a normal page. + */ +- if (pte_special(pte) && !is_zero_pfn(pte_pfn(pte))) { ++ if (pte_special(pte) && !pte_devmap(pte) && ++ !is_zero_pfn(pte_pfn(pte))) { + if (hmm_pte_need_fault(hmm_vma_walk, pfn_req_flags, 0)) { + pte_unmap(ptep); + return -EFAULT; +diff --git a/mm/hugetlb.c b/mm/hugetlb.c +index 8ea35ba6699f2..6c583ef079e3d 100644 +--- a/mm/hugetlb.c ++++ b/mm/hugetlb.c +@@ -4033,8 +4033,10 @@ static void hugetlb_vm_op_open(struct vm_area_struct *vma) + * after this open call completes. It is therefore safe to take a + * new reference here without additional locking. + */ +- if (resv && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) ++ if (resv && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) { ++ resv_map_dup_hugetlb_cgroup_uncharge_info(resv); + kref_get(&resv->refs); ++ } + } + + static void hugetlb_vm_op_close(struct vm_area_struct *vma) +diff --git a/mm/memory-failure.c b/mm/memory-failure.c +index 470400cc75136..83811c976c0cb 100644 +--- a/mm/memory-failure.c ++++ b/mm/memory-failure.c +@@ -68,7 +68,7 @@ atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); + + static bool __page_handle_poison(struct page *page) + { +- bool ret; ++ int ret; + + zone_pcp_disable(page_zone(page)); + ret = dissolve_free_huge_page(page); +@@ -76,7 +76,7 @@ static bool __page_handle_poison(struct page *page) + ret = take_page_off_buddy(page); + zone_pcp_enable(page_zone(page)); + +- return ret; ++ return ret > 0; + } + + static bool page_handle_poison(struct page *page, bool hugepage_or_freepage, bool release) +diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c +index 86c3af79e874e..97698a761221e 100644 +--- a/mm/memory_hotplug.c ++++ b/mm/memory_hotplug.c +@@ -708,8 +708,8 @@ static inline struct zone *default_zone_for_pfn(int nid, unsigned long start_pfn + return movable_node_enabled ? movable_zone : kernel_zone; + } + +-struct zone *zone_for_pfn_range(int online_type, int nid, unsigned start_pfn, +- unsigned long nr_pages) ++struct zone *zone_for_pfn_range(int online_type, int nid, ++ unsigned long start_pfn, unsigned long nr_pages) + { + if (online_type == MMOP_ONLINE_KERNEL) + return default_kernel_zone_for_pfn(nid, start_pfn, nr_pages); +diff --git a/mm/mempolicy.c b/mm/mempolicy.c +index e32360e902744..54f6eaff18c52 100644 +--- a/mm/mempolicy.c ++++ b/mm/mempolicy.c +@@ -1965,17 +1965,26 @@ unsigned int mempolicy_slab_node(void) + */ + static unsigned offset_il_node(struct mempolicy *pol, unsigned long n) + { +- unsigned nnodes = nodes_weight(pol->nodes); +- unsigned target; ++ nodemask_t nodemask = pol->nodes; ++ unsigned int target, nnodes; + int i; + int nid; ++ /* ++ * The barrier will stabilize the nodemask in a register or on ++ * the stack so that it will stop changing under the code. ++ * ++ * Between first_node() and next_node(), pol->nodes could be changed ++ * by other threads. So we put pol->nodes in a local stack. ++ */ ++ barrier(); + ++ nnodes = nodes_weight(nodemask); + if (!nnodes) + return numa_node_id(); + target = (unsigned int)n % nnodes; +- nid = first_node(pol->nodes); ++ nid = first_node(nodemask); + for (i = 0; i < target; i++) +- nid = next_node(nid, pol->nodes); ++ nid = next_node(nid, nodemask); + return nid; + } + +diff --git a/mm/page_alloc.c b/mm/page_alloc.c +index eeb3a9cb36bb4..7a28f7db7d286 100644 +--- a/mm/page_alloc.c ++++ b/mm/page_alloc.c +@@ -3445,8 +3445,10 @@ void free_unref_page_list(struct list_head *list) + /* Prepare pages for freeing */ + list_for_each_entry_safe(page, next, list, lru) { + pfn = page_to_pfn(page); +- if (!free_unref_page_prepare(page, pfn, 0)) ++ if (!free_unref_page_prepare(page, pfn, 0)) { + list_del(&page->lru); ++ continue; ++ } + + /* + * Free isolated pages directly to the allocator, see +diff --git a/mm/vmscan.c b/mm/vmscan.c +index eeae2f6bc5320..f1782b816c983 100644 +--- a/mm/vmscan.c ++++ b/mm/vmscan.c +@@ -2592,7 +2592,7 @@ out: + cgroup_size = max(cgroup_size, protection); + + scan = lruvec_size - lruvec_size * protection / +- cgroup_size; ++ (cgroup_size + 1); + + /* + * Minimally target SWAP_CLUSTER_MAX pages to keep +diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c +index f4fea28e05da6..3ec1a51a6944e 100644 +--- a/net/9p/trans_xen.c ++++ b/net/9p/trans_xen.c +@@ -138,7 +138,7 @@ static bool p9_xen_write_todo(struct xen_9pfs_dataring *ring, RING_IDX size) + + static int p9_xen_request(struct p9_client *client, struct p9_req_t *p9_req) + { +- struct xen_9pfs_front_priv *priv = NULL; ++ struct xen_9pfs_front_priv *priv; + RING_IDX cons, prod, masked_cons, masked_prod; + unsigned long flags; + u32 size = p9_req->tc.size; +@@ -151,7 +151,7 @@ static int p9_xen_request(struct p9_client *client, struct p9_req_t *p9_req) + break; + } + read_unlock(&xen_9pfs_lock); +- if (!priv || priv->client != client) ++ if (list_entry_is_head(priv, &xen_9pfs_devs, list)) + return -EINVAL; + + num = p9_req->tc.tag % priv->num_rings; +diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c +index 1c30182025645..0d0b958b7fe7e 100644 +--- a/net/bluetooth/hci_event.c ++++ b/net/bluetooth/hci_event.c +@@ -40,6 +40,8 @@ + #define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ + "\x00\x00\x00\x00\x00\x00\x00\x00" + ++#define secs_to_jiffies(_secs) msecs_to_jiffies((_secs) * 1000) ++ + /* Handle HCI Event packets */ + + static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb, +@@ -1171,6 +1173,12 @@ static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb) + + bacpy(&hdev->random_addr, sent); + ++ if (!bacmp(&hdev->rpa, sent)) { ++ hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); ++ queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, ++ secs_to_jiffies(hdev->rpa_timeout)); ++ } ++ + hci_dev_unlock(hdev); + } + +@@ -1201,24 +1209,30 @@ static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, + { + __u8 status = *((__u8 *) skb->data); + struct hci_cp_le_set_adv_set_rand_addr *cp; +- struct adv_info *adv_instance; ++ struct adv_info *adv; + + if (status) + return; + + cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR); +- if (!cp) ++ /* Update only in case the adv instance since handle 0x00 shall be using ++ * HCI_OP_LE_SET_RANDOM_ADDR since that allows both extended and ++ * non-extended adverting. ++ */ ++ if (!cp || !cp->handle) + return; + + hci_dev_lock(hdev); + +- if (!cp->handle) { +- /* Store in hdev for instance 0 (Set adv and Directed advs) */ +- bacpy(&hdev->random_addr, &cp->bdaddr); +- } else { +- adv_instance = hci_find_adv_instance(hdev, cp->handle); +- if (adv_instance) +- bacpy(&adv_instance->random_addr, &cp->bdaddr); ++ adv = hci_find_adv_instance(hdev, cp->handle); ++ if (adv) { ++ bacpy(&adv->random_addr, &cp->bdaddr); ++ if (!bacmp(&hdev->rpa, &cp->bdaddr)) { ++ adv->rpa_expired = false; ++ queue_delayed_work(hdev->workqueue, ++ &adv->rpa_expired_cb, ++ secs_to_jiffies(hdev->rpa_timeout)); ++ } + } + + hci_dev_unlock(hdev); +@@ -3268,11 +3282,9 @@ unlock: + hci_dev_unlock(hdev); + } + +-static inline void handle_cmd_cnt_and_timer(struct hci_dev *hdev, +- u16 opcode, u8 ncmd) ++static inline void handle_cmd_cnt_and_timer(struct hci_dev *hdev, u8 ncmd) + { +- if (opcode != HCI_OP_NOP) +- cancel_delayed_work(&hdev->cmd_timer); ++ cancel_delayed_work(&hdev->cmd_timer); + + if (!test_bit(HCI_RESET, &hdev->flags)) { + if (ncmd) { +@@ -3647,7 +3659,7 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, + break; + } + +- handle_cmd_cnt_and_timer(hdev, *opcode, ev->ncmd); ++ handle_cmd_cnt_and_timer(hdev, ev->ncmd); + + hci_req_cmd_complete(hdev, *opcode, *status, req_complete, + req_complete_skb); +@@ -3748,7 +3760,7 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb, + break; + } + +- handle_cmd_cnt_and_timer(hdev, *opcode, ev->ncmd); ++ handle_cmd_cnt_and_timer(hdev, ev->ncmd); + + /* Indicate request completion if the command failed. Also, if + * we're not waiting for a special event and we get a success +@@ -4382,6 +4394,21 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, + + switch (ev->status) { + case 0x00: ++ /* The synchronous connection complete event should only be ++ * sent once per new connection. Receiving a successful ++ * complete event when the connection status is already ++ * BT_CONNECTED means that the device is misbehaving and sent ++ * multiple complete event packets for the same new connection. ++ * ++ * Registering the device more than once can corrupt kernel ++ * memory, hence upon detecting this invalid event, we report ++ * an error and ignore the packet. ++ */ ++ if (conn->state == BT_CONNECTED) { ++ bt_dev_err(hdev, "Ignoring connect complete event for existing connection"); ++ goto unlock; ++ } ++ + conn->handle = __le16_to_cpu(ev->handle); + conn->state = BT_CONNECTED; + conn->type = ev->link_type; +@@ -5104,9 +5131,64 @@ static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev, + } + #endif + ++static void le_conn_update_addr(struct hci_conn *conn, bdaddr_t *bdaddr, ++ u8 bdaddr_type, bdaddr_t *local_rpa) ++{ ++ if (conn->out) { ++ conn->dst_type = bdaddr_type; ++ conn->resp_addr_type = bdaddr_type; ++ bacpy(&conn->resp_addr, bdaddr); ++ ++ /* Check if the controller has set a Local RPA then it must be ++ * used instead or hdev->rpa. ++ */ ++ if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) { ++ conn->init_addr_type = ADDR_LE_DEV_RANDOM; ++ bacpy(&conn->init_addr, local_rpa); ++ } else if (hci_dev_test_flag(conn->hdev, HCI_PRIVACY)) { ++ conn->init_addr_type = ADDR_LE_DEV_RANDOM; ++ bacpy(&conn->init_addr, &conn->hdev->rpa); ++ } else { ++ hci_copy_identity_address(conn->hdev, &conn->init_addr, ++ &conn->init_addr_type); ++ } ++ } else { ++ conn->resp_addr_type = conn->hdev->adv_addr_type; ++ /* Check if the controller has set a Local RPA then it must be ++ * used instead or hdev->rpa. ++ */ ++ if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) { ++ conn->resp_addr_type = ADDR_LE_DEV_RANDOM; ++ bacpy(&conn->resp_addr, local_rpa); ++ } else if (conn->hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) { ++ /* In case of ext adv, resp_addr will be updated in ++ * Adv Terminated event. ++ */ ++ if (!ext_adv_capable(conn->hdev)) ++ bacpy(&conn->resp_addr, ++ &conn->hdev->random_addr); ++ } else { ++ bacpy(&conn->resp_addr, &conn->hdev->bdaddr); ++ } ++ ++ conn->init_addr_type = bdaddr_type; ++ bacpy(&conn->init_addr, bdaddr); ++ ++ /* For incoming connections, set the default minimum ++ * and maximum connection interval. They will be used ++ * to check if the parameters are in range and if not ++ * trigger the connection update procedure. ++ */ ++ conn->le_conn_min_interval = conn->hdev->le_conn_min_interval; ++ conn->le_conn_max_interval = conn->hdev->le_conn_max_interval; ++ } ++} ++ + static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, +- bdaddr_t *bdaddr, u8 bdaddr_type, u8 role, u16 handle, +- u16 interval, u16 latency, u16 supervision_timeout) ++ bdaddr_t *bdaddr, u8 bdaddr_type, ++ bdaddr_t *local_rpa, u8 role, u16 handle, ++ u16 interval, u16 latency, ++ u16 supervision_timeout) + { + struct hci_conn_params *params; + struct hci_conn *conn; +@@ -5154,32 +5236,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, + cancel_delayed_work(&conn->le_conn_timeout); + } + +- if (!conn->out) { +- /* Set the responder (our side) address type based on +- * the advertising address type. +- */ +- conn->resp_addr_type = hdev->adv_addr_type; +- if (hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) { +- /* In case of ext adv, resp_addr will be updated in +- * Adv Terminated event. +- */ +- if (!ext_adv_capable(hdev)) +- bacpy(&conn->resp_addr, &hdev->random_addr); +- } else { +- bacpy(&conn->resp_addr, &hdev->bdaddr); +- } +- +- conn->init_addr_type = bdaddr_type; +- bacpy(&conn->init_addr, bdaddr); +- +- /* For incoming connections, set the default minimum +- * and maximum connection interval. They will be used +- * to check if the parameters are in range and if not +- * trigger the connection update procedure. +- */ +- conn->le_conn_min_interval = hdev->le_conn_min_interval; +- conn->le_conn_max_interval = hdev->le_conn_max_interval; +- } ++ le_conn_update_addr(conn, bdaddr, bdaddr_type, local_rpa); + + /* Lookup the identity address from the stored connection + * address and address type. +@@ -5290,7 +5347,7 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) + BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); + + le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type, +- ev->role, le16_to_cpu(ev->handle), ++ NULL, ev->role, le16_to_cpu(ev->handle), + le16_to_cpu(ev->interval), + le16_to_cpu(ev->latency), + le16_to_cpu(ev->supervision_timeout)); +@@ -5304,7 +5361,7 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, + BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); + + le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type, +- ev->role, le16_to_cpu(ev->handle), ++ &ev->local_rpa, ev->role, le16_to_cpu(ev->handle), + le16_to_cpu(ev->interval), + le16_to_cpu(ev->latency), + le16_to_cpu(ev->supervision_timeout)); +@@ -5340,7 +5397,8 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb) + if (conn) { + struct adv_info *adv_instance; + +- if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM) ++ if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM || ++ bacmp(&conn->resp_addr, BDADDR_ANY)) + return; + + if (!ev->handle) { +diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c +index 1d14adc023e96..f15626607b2d6 100644 +--- a/net/bluetooth/hci_request.c ++++ b/net/bluetooth/hci_request.c +@@ -2072,8 +2072,6 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, + * current RPA has expired then generate a new one. + */ + if (use_rpa) { +- int to; +- + /* If Controller supports LL Privacy use own address type is + * 0x03 + */ +@@ -2084,14 +2082,10 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, + *own_addr_type = ADDR_LE_DEV_RANDOM; + + if (adv_instance) { +- if (!adv_instance->rpa_expired && +- !bacmp(&adv_instance->random_addr, &hdev->rpa)) ++ if (adv_rpa_valid(adv_instance)) + return 0; +- +- adv_instance->rpa_expired = false; + } else { +- if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && +- !bacmp(&hdev->random_addr, &hdev->rpa)) ++ if (rpa_valid(hdev)) + return 0; + } + +@@ -2103,14 +2097,6 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, + + bacpy(rand_addr, &hdev->rpa); + +- to = msecs_to_jiffies(hdev->rpa_timeout * 1000); +- if (adv_instance) +- queue_delayed_work(hdev->workqueue, +- &adv_instance->rpa_expired_cb, to); +- else +- queue_delayed_work(hdev->workqueue, +- &hdev->rpa_expired, to); +- + return 0; + } + +@@ -2153,6 +2139,30 @@ void __hci_req_clear_ext_adv_sets(struct hci_request *req) + hci_req_add(req, HCI_OP_LE_CLEAR_ADV_SETS, 0, NULL); + } + ++static void set_random_addr(struct hci_request *req, bdaddr_t *rpa) ++{ ++ struct hci_dev *hdev = req->hdev; ++ ++ /* If we're advertising or initiating an LE connection we can't ++ * go ahead and change the random address at this time. This is ++ * because the eventual initiator address used for the ++ * subsequently created connection will be undefined (some ++ * controllers use the new address and others the one we had ++ * when the operation started). ++ * ++ * In this kind of scenario skip the update and let the random ++ * address be updated at the next cycle. ++ */ ++ if (hci_dev_test_flag(hdev, HCI_LE_ADV) || ++ hci_lookup_le_connect(hdev)) { ++ bt_dev_dbg(hdev, "Deferring random address update"); ++ hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); ++ return; ++ } ++ ++ hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6, rpa); ++} ++ + int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) + { + struct hci_cp_le_set_ext_adv_params cp; +@@ -2255,6 +2265,13 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) + } else { + if (!bacmp(&random_addr, &hdev->random_addr)) + return 0; ++ /* Instance 0x00 doesn't have an adv_info, instead it ++ * uses hdev->random_addr to track its address so ++ * whenever it needs to be updated this also set the ++ * random address since hdev->random_addr is shared with ++ * scan state machine. ++ */ ++ set_random_addr(req, &random_addr); + } + + memset(&cp, 0, sizeof(cp)); +@@ -2512,30 +2529,6 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, + false); + } + +-static void set_random_addr(struct hci_request *req, bdaddr_t *rpa) +-{ +- struct hci_dev *hdev = req->hdev; +- +- /* If we're advertising or initiating an LE connection we can't +- * go ahead and change the random address at this time. This is +- * because the eventual initiator address used for the +- * subsequently created connection will be undefined (some +- * controllers use the new address and others the one we had +- * when the operation started). +- * +- * In this kind of scenario skip the update and let the random +- * address be updated at the next cycle. +- */ +- if (hci_dev_test_flag(hdev, HCI_LE_ADV) || +- hci_lookup_le_connect(hdev)) { +- bt_dev_dbg(hdev, "Deferring random address update"); +- hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); +- return; +- } +- +- hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6, rpa); +-} +- + int hci_update_random_address(struct hci_request *req, bool require_privacy, + bool use_rpa, u8 *own_addr_type) + { +@@ -2547,8 +2540,6 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, + * the current RPA in use, then generate a new one. + */ + if (use_rpa) { +- int to; +- + /* If Controller supports LL Privacy use own address type is + * 0x03 + */ +@@ -2558,8 +2549,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, + else + *own_addr_type = ADDR_LE_DEV_RANDOM; + +- if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && +- !bacmp(&hdev->random_addr, &hdev->rpa)) ++ if (rpa_valid(hdev)) + return 0; + + err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); +@@ -2570,9 +2560,6 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, + + set_random_addr(req, &hdev->rpa); + +- to = msecs_to_jiffies(hdev->rpa_timeout * 1000); +- queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, to); +- + return 0; + } + +diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c +index b5ab842c7c4a8..110cfd6aa2b77 100644 +--- a/net/bluetooth/sco.c ++++ b/net/bluetooth/sco.c +@@ -48,6 +48,8 @@ struct sco_conn { + spinlock_t lock; + struct sock *sk; + ++ struct delayed_work timeout_work; ++ + unsigned int mtu; + }; + +@@ -74,9 +76,20 @@ struct sco_pinfo { + #define SCO_CONN_TIMEOUT (HZ * 40) + #define SCO_DISCONN_TIMEOUT (HZ * 2) + +-static void sco_sock_timeout(struct timer_list *t) ++static void sco_sock_timeout(struct work_struct *work) + { +- struct sock *sk = from_timer(sk, t, sk_timer); ++ struct sco_conn *conn = container_of(work, struct sco_conn, ++ timeout_work.work); ++ struct sock *sk; ++ ++ sco_conn_lock(conn); ++ sk = conn->sk; ++ if (sk) ++ sock_hold(sk); ++ sco_conn_unlock(conn); ++ ++ if (!sk) ++ return; + + BT_DBG("sock %p state %d", sk, sk->sk_state); + +@@ -90,14 +103,21 @@ static void sco_sock_timeout(struct timer_list *t) + + static void sco_sock_set_timer(struct sock *sk, long timeout) + { ++ if (!sco_pi(sk)->conn) ++ return; ++ + BT_DBG("sock %p state %d timeout %ld", sk, sk->sk_state, timeout); +- sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout); ++ cancel_delayed_work(&sco_pi(sk)->conn->timeout_work); ++ schedule_delayed_work(&sco_pi(sk)->conn->timeout_work, timeout); + } + + static void sco_sock_clear_timer(struct sock *sk) + { ++ if (!sco_pi(sk)->conn) ++ return; ++ + BT_DBG("sock %p state %d", sk, sk->sk_state); +- sk_stop_timer(sk, &sk->sk_timer); ++ cancel_delayed_work(&sco_pi(sk)->conn->timeout_work); + } + + /* ---- SCO connections ---- */ +@@ -177,6 +197,9 @@ static void sco_conn_del(struct hci_conn *hcon, int err) + sco_chan_del(sk, err); + bh_unlock_sock(sk); + sock_put(sk); ++ ++ /* Ensure no more work items will run before freeing conn. */ ++ cancel_delayed_work_sync(&conn->timeout_work); + } + + hcon->sco_data = NULL; +@@ -191,6 +214,8 @@ static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, + sco_pi(sk)->conn = conn; + conn->sk = sk; + ++ INIT_DELAYED_WORK(&conn->timeout_work, sco_sock_timeout); ++ + if (parent) + bt_accept_enqueue(parent, sk, true); + } +@@ -210,44 +235,32 @@ static int sco_chan_add(struct sco_conn *conn, struct sock *sk, + return err; + } + +-static int sco_connect(struct sock *sk) ++static int sco_connect(struct hci_dev *hdev, struct sock *sk) + { + struct sco_conn *conn; + struct hci_conn *hcon; +- struct hci_dev *hdev; + int err, type; + + BT_DBG("%pMR -> %pMR", &sco_pi(sk)->src, &sco_pi(sk)->dst); + +- hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src, BDADDR_BREDR); +- if (!hdev) +- return -EHOSTUNREACH; +- +- hci_dev_lock(hdev); +- + if (lmp_esco_capable(hdev) && !disable_esco) + type = ESCO_LINK; + else + type = SCO_LINK; + + if (sco_pi(sk)->setting == BT_VOICE_TRANSPARENT && +- (!lmp_transp_capable(hdev) || !lmp_esco_capable(hdev))) { +- err = -EOPNOTSUPP; +- goto done; +- } ++ (!lmp_transp_capable(hdev) || !lmp_esco_capable(hdev))) ++ return -EOPNOTSUPP; + + hcon = hci_connect_sco(hdev, type, &sco_pi(sk)->dst, + sco_pi(sk)->setting); +- if (IS_ERR(hcon)) { +- err = PTR_ERR(hcon); +- goto done; +- } ++ if (IS_ERR(hcon)) ++ return PTR_ERR(hcon); + + conn = sco_conn_add(hcon); + if (!conn) { + hci_conn_drop(hcon); +- err = -ENOMEM; +- goto done; ++ return -ENOMEM; + } + + /* Update source addr of the socket */ +@@ -255,7 +268,7 @@ static int sco_connect(struct sock *sk) + + err = sco_chan_add(conn, sk, NULL); + if (err) +- goto done; ++ return err; + + if (hcon->state == BT_CONNECTED) { + sco_sock_clear_timer(sk); +@@ -265,9 +278,6 @@ static int sco_connect(struct sock *sk) + sco_sock_set_timer(sk, sk->sk_sndtimeo); + } + +-done: +- hci_dev_unlock(hdev); +- hci_dev_put(hdev); + return err; + } + +@@ -496,8 +506,6 @@ static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, + + sco_pi(sk)->setting = BT_VOICE_CVSD_16BIT; + +- timer_setup(&sk->sk_timer, sco_sock_timeout, 0); +- + bt_sock_link(&sco_sk_list, sk); + return sk; + } +@@ -562,6 +570,7 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen + { + struct sockaddr_sco *sa = (struct sockaddr_sco *) addr; + struct sock *sk = sock->sk; ++ struct hci_dev *hdev; + int err; + + BT_DBG("sk %p", sk); +@@ -576,12 +585,19 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen + if (sk->sk_type != SOCK_SEQPACKET) + return -EINVAL; + ++ hdev = hci_get_route(&sa->sco_bdaddr, &sco_pi(sk)->src, BDADDR_BREDR); ++ if (!hdev) ++ return -EHOSTUNREACH; ++ hci_dev_lock(hdev); ++ + lock_sock(sk); + + /* Set destination address and psm */ + bacpy(&sco_pi(sk)->dst, &sa->sco_bdaddr); + +- err = sco_connect(sk); ++ err = sco_connect(hdev, sk); ++ hci_dev_unlock(hdev); ++ hci_dev_put(hdev); + if (err) + goto done; + +diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c +index 4b2415d34873a..bac0184cf3de7 100644 +--- a/net/core/flow_dissector.c ++++ b/net/core/flow_dissector.c +@@ -1056,8 +1056,10 @@ proto_again: + FLOW_DISSECTOR_KEY_IPV4_ADDRS, + target_container); + +- memcpy(&key_addrs->v4addrs, &iph->saddr, +- sizeof(key_addrs->v4addrs)); ++ memcpy(&key_addrs->v4addrs.src, &iph->saddr, ++ sizeof(key_addrs->v4addrs.src)); ++ memcpy(&key_addrs->v4addrs.dst, &iph->daddr, ++ sizeof(key_addrs->v4addrs.dst)); + key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; + } + +@@ -1101,8 +1103,10 @@ proto_again: + FLOW_DISSECTOR_KEY_IPV6_ADDRS, + target_container); + +- memcpy(&key_addrs->v6addrs, &iph->saddr, +- sizeof(key_addrs->v6addrs)); ++ memcpy(&key_addrs->v6addrs.src, &iph->saddr, ++ sizeof(key_addrs->v6addrs.src)); ++ memcpy(&key_addrs->v6addrs.dst, &iph->daddr, ++ sizeof(key_addrs->v6addrs.dst)); + key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS; + } + +diff --git a/net/core/flow_offload.c b/net/core/flow_offload.c +index 715b67f6c62f3..e3f0d59068117 100644 +--- a/net/core/flow_offload.c ++++ b/net/core/flow_offload.c +@@ -321,6 +321,7 @@ EXPORT_SYMBOL(flow_block_cb_setup_simple); + static DEFINE_MUTEX(flow_indr_block_lock); + static LIST_HEAD(flow_block_indr_list); + static LIST_HEAD(flow_block_indr_dev_list); ++static LIST_HEAD(flow_indir_dev_list); + + struct flow_indr_dev { + struct list_head list; +@@ -346,6 +347,33 @@ static struct flow_indr_dev *flow_indr_dev_alloc(flow_indr_block_bind_cb_t *cb, + return indr_dev; + } + ++struct flow_indir_dev_info { ++ void *data; ++ struct net_device *dev; ++ struct Qdisc *sch; ++ enum tc_setup_type type; ++ void (*cleanup)(struct flow_block_cb *block_cb); ++ struct list_head list; ++ enum flow_block_command command; ++ enum flow_block_binder_type binder_type; ++ struct list_head *cb_list; ++}; ++ ++static void existing_qdiscs_register(flow_indr_block_bind_cb_t *cb, void *cb_priv) ++{ ++ struct flow_block_offload bo; ++ struct flow_indir_dev_info *cur; ++ ++ list_for_each_entry(cur, &flow_indir_dev_list, list) { ++ memset(&bo, 0, sizeof(bo)); ++ bo.command = cur->command; ++ bo.binder_type = cur->binder_type; ++ INIT_LIST_HEAD(&bo.cb_list); ++ cb(cur->dev, cur->sch, cb_priv, cur->type, &bo, cur->data, cur->cleanup); ++ list_splice(&bo.cb_list, cur->cb_list); ++ } ++} ++ + int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv) + { + struct flow_indr_dev *indr_dev; +@@ -367,6 +395,7 @@ int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv) + } + + list_add(&indr_dev->list, &flow_block_indr_dev_list); ++ existing_qdiscs_register(cb, cb_priv); + mutex_unlock(&flow_indr_block_lock); + + return 0; +@@ -463,7 +492,59 @@ out: + } + EXPORT_SYMBOL(flow_indr_block_cb_alloc); + +-int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, ++static struct flow_indir_dev_info *find_indir_dev(void *data) ++{ ++ struct flow_indir_dev_info *cur; ++ ++ list_for_each_entry(cur, &flow_indir_dev_list, list) { ++ if (cur->data == data) ++ return cur; ++ } ++ return NULL; ++} ++ ++static int indir_dev_add(void *data, struct net_device *dev, struct Qdisc *sch, ++ enum tc_setup_type type, void (*cleanup)(struct flow_block_cb *block_cb), ++ struct flow_block_offload *bo) ++{ ++ struct flow_indir_dev_info *info; ++ ++ info = find_indir_dev(data); ++ if (info) ++ return -EEXIST; ++ ++ info = kzalloc(sizeof(*info), GFP_KERNEL); ++ if (!info) ++ return -ENOMEM; ++ ++ info->data = data; ++ info->dev = dev; ++ info->sch = sch; ++ info->type = type; ++ info->cleanup = cleanup; ++ info->command = bo->command; ++ info->binder_type = bo->binder_type; ++ info->cb_list = bo->cb_list_head; ++ ++ list_add(&info->list, &flow_indir_dev_list); ++ return 0; ++} ++ ++static int indir_dev_remove(void *data) ++{ ++ struct flow_indir_dev_info *info; ++ ++ info = find_indir_dev(data); ++ if (!info) ++ return -ENOENT; ++ ++ list_del(&info->list); ++ ++ kfree(info); ++ return 0; ++} ++ ++int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, + enum tc_setup_type type, void *data, + struct flow_block_offload *bo, + void (*cleanup)(struct flow_block_cb *block_cb)) +@@ -471,6 +552,12 @@ int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, + struct flow_indr_dev *this; + + mutex_lock(&flow_indr_block_lock); ++ ++ if (bo->command == FLOW_BLOCK_BIND) ++ indir_dev_add(data, dev, sch, type, cleanup, bo); ++ else if (bo->command == FLOW_BLOCK_UNBIND) ++ indir_dev_remove(data); ++ + list_for_each_entry(this, &flow_block_indr_dev_list, list) + this->cb(dev, sch, this->cb_priv, type, bo, data, cleanup); + +diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c +index baa5d10043cb0..6134b180f59f8 100644 +--- a/net/ethtool/ioctl.c ++++ b/net/ethtool/ioctl.c +@@ -7,6 +7,7 @@ + * the information ethtool needs. + */ + ++#include + #include + #include + #include +@@ -807,6 +808,120 @@ out: + return ret; + } + ++static noinline_for_stack int ++ethtool_rxnfc_copy_from_compat(struct ethtool_rxnfc *rxnfc, ++ const struct compat_ethtool_rxnfc __user *useraddr, ++ size_t size) ++{ ++ struct compat_ethtool_rxnfc crxnfc = {}; ++ ++ /* We expect there to be holes between fs.m_ext and ++ * fs.ring_cookie and at the end of fs, but nowhere else. ++ * On non-x86, no conversion should be needed. ++ */ ++ BUILD_BUG_ON(!IS_ENABLED(CONFIG_X86_64) && ++ sizeof(struct compat_ethtool_rxnfc) != ++ sizeof(struct ethtool_rxnfc)); ++ BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.m_ext) + ++ sizeof(useraddr->fs.m_ext) != ++ offsetof(struct ethtool_rxnfc, fs.m_ext) + ++ sizeof(rxnfc->fs.m_ext)); ++ BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.location) - ++ offsetof(struct compat_ethtool_rxnfc, fs.ring_cookie) != ++ offsetof(struct ethtool_rxnfc, fs.location) - ++ offsetof(struct ethtool_rxnfc, fs.ring_cookie)); ++ ++ if (copy_from_user(&crxnfc, useraddr, min(size, sizeof(crxnfc)))) ++ return -EFAULT; ++ ++ *rxnfc = (struct ethtool_rxnfc) { ++ .cmd = crxnfc.cmd, ++ .flow_type = crxnfc.flow_type, ++ .data = crxnfc.data, ++ .fs = { ++ .flow_type = crxnfc.fs.flow_type, ++ .h_u = crxnfc.fs.h_u, ++ .h_ext = crxnfc.fs.h_ext, ++ .m_u = crxnfc.fs.m_u, ++ .m_ext = crxnfc.fs.m_ext, ++ .ring_cookie = crxnfc.fs.ring_cookie, ++ .location = crxnfc.fs.location, ++ }, ++ .rule_cnt = crxnfc.rule_cnt, ++ }; ++ ++ return 0; ++} ++ ++static int ethtool_rxnfc_copy_from_user(struct ethtool_rxnfc *rxnfc, ++ const void __user *useraddr, ++ size_t size) ++{ ++ if (compat_need_64bit_alignment_fixup()) ++ return ethtool_rxnfc_copy_from_compat(rxnfc, useraddr, size); ++ ++ if (copy_from_user(rxnfc, useraddr, size)) ++ return -EFAULT; ++ ++ return 0; ++} ++ ++static int ethtool_rxnfc_copy_to_compat(void __user *useraddr, ++ const struct ethtool_rxnfc *rxnfc, ++ size_t size, const u32 *rule_buf) ++{ ++ struct compat_ethtool_rxnfc crxnfc; ++ ++ memset(&crxnfc, 0, sizeof(crxnfc)); ++ crxnfc = (struct compat_ethtool_rxnfc) { ++ .cmd = rxnfc->cmd, ++ .flow_type = rxnfc->flow_type, ++ .data = rxnfc->data, ++ .fs = { ++ .flow_type = rxnfc->fs.flow_type, ++ .h_u = rxnfc->fs.h_u, ++ .h_ext = rxnfc->fs.h_ext, ++ .m_u = rxnfc->fs.m_u, ++ .m_ext = rxnfc->fs.m_ext, ++ .ring_cookie = rxnfc->fs.ring_cookie, ++ .location = rxnfc->fs.location, ++ }, ++ .rule_cnt = rxnfc->rule_cnt, ++ }; ++ ++ if (copy_to_user(useraddr, &crxnfc, min(size, sizeof(crxnfc)))) ++ return -EFAULT; ++ ++ return 0; ++} ++ ++static int ethtool_rxnfc_copy_to_user(void __user *useraddr, ++ const struct ethtool_rxnfc *rxnfc, ++ size_t size, const u32 *rule_buf) ++{ ++ int ret; ++ ++ if (compat_need_64bit_alignment_fixup()) { ++ ret = ethtool_rxnfc_copy_to_compat(useraddr, rxnfc, size, ++ rule_buf); ++ useraddr += offsetof(struct compat_ethtool_rxnfc, rule_locs); ++ } else { ++ ret = copy_to_user(useraddr, &rxnfc, size); ++ useraddr += offsetof(struct ethtool_rxnfc, rule_locs); ++ } ++ ++ if (ret) ++ return -EFAULT; ++ ++ if (rule_buf) { ++ if (copy_to_user(useraddr, rule_buf, ++ rxnfc->rule_cnt * sizeof(u32))) ++ return -EFAULT; ++ } ++ ++ return 0; ++} ++ + static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, + u32 cmd, void __user *useraddr) + { +@@ -825,7 +940,7 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, + info_size = (offsetof(struct ethtool_rxnfc, data) + + sizeof(info.data)); + +- if (copy_from_user(&info, useraddr, info_size)) ++ if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size)) + return -EFAULT; + + rc = dev->ethtool_ops->set_rxnfc(dev, &info); +@@ -833,7 +948,7 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, + return rc; + + if (cmd == ETHTOOL_SRXCLSRLINS && +- copy_to_user(useraddr, &info, info_size)) ++ ethtool_rxnfc_copy_to_user(useraddr, &info, info_size, NULL)) + return -EFAULT; + + return 0; +@@ -859,7 +974,7 @@ static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, + info_size = (offsetof(struct ethtool_rxnfc, data) + + sizeof(info.data)); + +- if (copy_from_user(&info, useraddr, info_size)) ++ if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size)) + return -EFAULT; + + /* If FLOW_RSS was requested then user-space must be using the +@@ -867,7 +982,7 @@ static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, + */ + if (cmd == ETHTOOL_GRXFH && info.flow_type & FLOW_RSS) { + info_size = sizeof(info); +- if (copy_from_user(&info, useraddr, info_size)) ++ if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size)) + return -EFAULT; + /* Since malicious users may modify the original data, + * we need to check whether FLOW_RSS is still requested. +@@ -893,18 +1008,7 @@ static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, + if (ret < 0) + goto err_out; + +- ret = -EFAULT; +- if (copy_to_user(useraddr, &info, info_size)) +- goto err_out; +- +- if (rule_buf) { +- useraddr += offsetof(struct ethtool_rxnfc, rule_locs); +- if (copy_to_user(useraddr, rule_buf, +- info.rule_cnt * sizeof(u32))) +- goto err_out; +- } +- ret = 0; +- ++ ret = ethtool_rxnfc_copy_to_user(useraddr, &info, info_size, rule_buf); + err_out: + kfree(rule_buf); + +diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c +index 8d8a8da3ae7e0..a202dcec0dc27 100644 +--- a/net/ipv4/ip_output.c ++++ b/net/ipv4/ip_output.c +@@ -446,8 +446,9 @@ static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4) + { + BUILD_BUG_ON(offsetof(typeof(*fl4), daddr) != + offsetof(typeof(*fl4), saddr) + sizeof(fl4->saddr)); +- memcpy(&iph->saddr, &fl4->saddr, +- sizeof(fl4->saddr) + sizeof(fl4->daddr)); ++ ++ iph->saddr = fl4->saddr; ++ iph->daddr = fl4->daddr; + } + + /* Note: skb->sk can be different from sk, in case of tunnels */ +diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c +index 25fa4c01a17f6..f1e90fc1cd187 100644 +--- a/net/ipv4/tcp_fastopen.c ++++ b/net/ipv4/tcp_fastopen.c +@@ -379,8 +379,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, + return NULL; + } + +- if (syn_data && +- tcp_fastopen_no_cookie(sk, dst, TFO_SERVER_COOKIE_NOT_REQD)) ++ if (tcp_fastopen_no_cookie(sk, dst, TFO_SERVER_COOKIE_NOT_REQD)) + goto fastopen; + + if (foc->len == 0) { +diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c +index 1e5e9fc455230..cd96cd337aa89 100644 +--- a/net/mac80211/iface.c ++++ b/net/mac80211/iface.c +@@ -2001,9 +2001,16 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name, + + netdev_set_default_ethtool_ops(ndev, &ieee80211_ethtool_ops); + +- /* MTU range: 256 - 2304 */ ++ /* MTU range is normally 256 - 2304, where the upper limit is ++ * the maximum MSDU size. Monitor interfaces send and receive ++ * MPDU and A-MSDU frames which may be much larger so we do ++ * not impose an upper limit in that case. ++ */ + ndev->min_mtu = 256; +- ndev->max_mtu = local->hw.max_mtu; ++ if (type == NL80211_IFTYPE_MONITOR) ++ ndev->max_mtu = 0; ++ else ++ ndev->max_mtu = local->hw.max_mtu; + + ret = cfg80211_register_netdevice(ndev); + if (ret) { +diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c +index f92006cec94c4..cbd9f59098b74 100644 +--- a/net/netfilter/nf_flow_table_offload.c ++++ b/net/netfilter/nf_flow_table_offload.c +@@ -1097,6 +1097,7 @@ static void nf_flow_table_block_offload_init(struct flow_block_offload *bo, + bo->command = cmd; + bo->binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS; + bo->extack = extack; ++ bo->cb_list_head = &flowtable->flow_block.cb_list; + INIT_LIST_HEAD(&bo->cb_list); + } + +diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c +index b58d73a965232..9656c16462222 100644 +--- a/net/netfilter/nf_tables_offload.c ++++ b/net/netfilter/nf_tables_offload.c +@@ -353,6 +353,7 @@ static void nft_flow_block_offload_init(struct flow_block_offload *bo, + bo->command = cmd; + bo->binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS; + bo->extack = extack; ++ bo->cb_list_head = &basechain->flow_block.cb_list; + INIT_LIST_HEAD(&bo->cb_list); + } + +diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c +index 639c337c885b1..272bcdb1392df 100644 +--- a/net/netfilter/nft_compat.c ++++ b/net/netfilter/nft_compat.c +@@ -683,14 +683,12 @@ static int nfnl_compat_get_rcu(struct sk_buff *skb, + goto out_put; + } + +- ret = netlink_unicast(info->sk, skb2, NETLINK_CB(skb).portid, +- MSG_DONTWAIT); +- if (ret > 0) +- ret = 0; ++ ret = nfnetlink_unicast(skb2, info->net, NETLINK_CB(skb).portid); + out_put: + rcu_read_lock(); + module_put(THIS_MODULE); +- return ret == -EAGAIN ? -ENOBUFS : ret; ++ ++ return ret; + } + + static const struct nla_policy nfnl_compat_policy_get[NFTA_COMPAT_MAX+1] = { +diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c +index 000bb3da4f77f..894e6b8f1a868 100644 +--- a/net/netlabel/netlabel_cipso_v4.c ++++ b/net/netlabel/netlabel_cipso_v4.c +@@ -144,8 +144,8 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, + return -ENOMEM; + doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL); + if (doi_def->map.std == NULL) { +- ret_val = -ENOMEM; +- goto add_std_failure; ++ kfree(doi_def); ++ return -ENOMEM; + } + doi_def->type = CIPSO_V4_MAP_TRANS; + +diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c +index 380f95aacdec9..24b7cf447bc55 100644 +--- a/net/netlink/af_netlink.c ++++ b/net/netlink/af_netlink.c +@@ -2545,13 +2545,15 @@ int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 portid, + /* errors reported via destination sk->sk_err, but propagate + * delivery errors if NETLINK_BROADCAST_ERROR flag is set */ + err = nlmsg_multicast(sk, skb, exclude_portid, group, flags); ++ if (err == -ESRCH) ++ err = 0; + } + + if (report) { + int err2; + + err2 = nlmsg_unicast(sk, skb, portid); +- if (!err || err == -ESRCH) ++ if (!err) + err = err2; + } + +diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c +index e3e79e9bd7067..9b276d14be4c4 100644 +--- a/net/sched/cls_api.c ++++ b/net/sched/cls_api.c +@@ -634,6 +634,7 @@ static void tcf_block_offload_init(struct flow_block_offload *bo, + bo->block_shared = shared; + bo->extack = extack; + bo->sch = sch; ++ bo->cb_list_head = &flow_block->cb_list; + INIT_LIST_HEAD(&bo->cb_list); + } + +diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c +index 9c79374457a00..1ab2fc933a214 100644 +--- a/net/sched/sch_taprio.c ++++ b/net/sched/sch_taprio.c +@@ -1513,7 +1513,9 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt, + taprio_set_picos_per_byte(dev, q); + + if (mqprio) { +- netdev_set_num_tc(dev, mqprio->num_tc); ++ err = netdev_set_num_tc(dev, mqprio->num_tc); ++ if (err) ++ goto free_sched; + for (i = 0; i < mqprio->num_tc; i++) + netdev_set_tc_queue(dev, i, + mqprio->count[i], +diff --git a/net/socket.c b/net/socket.c +index 8808b3617dac9..c5b6f5c5cad98 100644 +--- a/net/socket.c ++++ b/net/socket.c +@@ -3154,128 +3154,6 @@ static int compat_dev_ifconf(struct net *net, struct compat_ifconf __user *uifc3 + return 0; + } + +-static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32) +-{ +- struct compat_ethtool_rxnfc __user *compat_rxnfc; +- bool convert_in = false, convert_out = false; +- size_t buf_size = 0; +- struct ethtool_rxnfc __user *rxnfc = NULL; +- struct ifreq ifr; +- u32 rule_cnt = 0, actual_rule_cnt; +- u32 ethcmd; +- u32 data; +- int ret; +- +- if (get_user(data, &ifr32->ifr_ifru.ifru_data)) +- return -EFAULT; +- +- compat_rxnfc = compat_ptr(data); +- +- if (get_user(ethcmd, &compat_rxnfc->cmd)) +- return -EFAULT; +- +- /* Most ethtool structures are defined without padding. +- * Unfortunately struct ethtool_rxnfc is an exception. +- */ +- switch (ethcmd) { +- default: +- break; +- case ETHTOOL_GRXCLSRLALL: +- /* Buffer size is variable */ +- if (get_user(rule_cnt, &compat_rxnfc->rule_cnt)) +- return -EFAULT; +- if (rule_cnt > KMALLOC_MAX_SIZE / sizeof(u32)) +- return -ENOMEM; +- buf_size += rule_cnt * sizeof(u32); +- fallthrough; +- case ETHTOOL_GRXRINGS: +- case ETHTOOL_GRXCLSRLCNT: +- case ETHTOOL_GRXCLSRULE: +- case ETHTOOL_SRXCLSRLINS: +- convert_out = true; +- fallthrough; +- case ETHTOOL_SRXCLSRLDEL: +- buf_size += sizeof(struct ethtool_rxnfc); +- convert_in = true; +- rxnfc = compat_alloc_user_space(buf_size); +- break; +- } +- +- if (copy_from_user(&ifr.ifr_name, &ifr32->ifr_name, IFNAMSIZ)) +- return -EFAULT; +- +- ifr.ifr_data = convert_in ? rxnfc : (void __user *)compat_rxnfc; +- +- if (convert_in) { +- /* We expect there to be holes between fs.m_ext and +- * fs.ring_cookie and at the end of fs, but nowhere else. +- */ +- BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.m_ext) + +- sizeof(compat_rxnfc->fs.m_ext) != +- offsetof(struct ethtool_rxnfc, fs.m_ext) + +- sizeof(rxnfc->fs.m_ext)); +- BUILD_BUG_ON( +- offsetof(struct compat_ethtool_rxnfc, fs.location) - +- offsetof(struct compat_ethtool_rxnfc, fs.ring_cookie) != +- offsetof(struct ethtool_rxnfc, fs.location) - +- offsetof(struct ethtool_rxnfc, fs.ring_cookie)); +- +- if (copy_in_user(rxnfc, compat_rxnfc, +- (void __user *)(&rxnfc->fs.m_ext + 1) - +- (void __user *)rxnfc) || +- copy_in_user(&rxnfc->fs.ring_cookie, +- &compat_rxnfc->fs.ring_cookie, +- (void __user *)(&rxnfc->fs.location + 1) - +- (void __user *)&rxnfc->fs.ring_cookie)) +- return -EFAULT; +- if (ethcmd == ETHTOOL_GRXCLSRLALL) { +- if (put_user(rule_cnt, &rxnfc->rule_cnt)) +- return -EFAULT; +- } else if (copy_in_user(&rxnfc->rule_cnt, +- &compat_rxnfc->rule_cnt, +- sizeof(rxnfc->rule_cnt))) +- return -EFAULT; +- } +- +- ret = dev_ioctl(net, SIOCETHTOOL, &ifr, NULL); +- if (ret) +- return ret; +- +- if (convert_out) { +- if (copy_in_user(compat_rxnfc, rxnfc, +- (const void __user *)(&rxnfc->fs.m_ext + 1) - +- (const void __user *)rxnfc) || +- copy_in_user(&compat_rxnfc->fs.ring_cookie, +- &rxnfc->fs.ring_cookie, +- (const void __user *)(&rxnfc->fs.location + 1) - +- (const void __user *)&rxnfc->fs.ring_cookie) || +- copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt, +- sizeof(rxnfc->rule_cnt))) +- return -EFAULT; +- +- if (ethcmd == ETHTOOL_GRXCLSRLALL) { +- /* As an optimisation, we only copy the actual +- * number of rules that the underlying +- * function returned. Since Mallory might +- * change the rule count in user memory, we +- * check that it is less than the rule count +- * originally given (as the user buffer size), +- * which has been range-checked. +- */ +- if (get_user(actual_rule_cnt, &rxnfc->rule_cnt)) +- return -EFAULT; +- if (actual_rule_cnt < rule_cnt) +- rule_cnt = actual_rule_cnt; +- if (copy_in_user(&compat_rxnfc->rule_locs[0], +- &rxnfc->rule_locs[0], +- rule_cnt * sizeof(u32))) +- return -EFAULT; +- } +- } +- +- return 0; +-} +- + static int compat_siocwandev(struct net *net, struct compat_ifreq __user *uifr32) + { + compat_uptr_t uptr32; +@@ -3432,8 +3310,6 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock, + return old_bridge_ioctl(argp); + case SIOCGIFCONF: + return compat_dev_ifconf(net, argp); +- case SIOCETHTOOL: +- return ethtool_ioctl(net, argp); + case SIOCWANDEV: + return compat_siocwandev(net, argp); + case SIOCGIFMAP: +@@ -3446,6 +3322,7 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock, + return sock->ops->gettstamp(sock, argp, cmd == SIOCGSTAMP_OLD, + !COMPAT_USE_64BIT_TIME); + ++ case SIOCETHTOOL: + case SIOCBONDSLAVEINFOQUERY: + case SIOCBONDINFOQUERY: + case SIOCSHWTSTAMP: +diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c +index a81be45f40d9f..3d685fe328fad 100644 +--- a/net/sunrpc/auth_gss/svcauth_gss.c ++++ b/net/sunrpc/auth_gss/svcauth_gss.c +@@ -1980,7 +1980,7 @@ gss_svc_init_net(struct net *net) + goto out2; + return 0; + out2: +- destroy_use_gss_proxy_proc_entry(net); ++ rsi_cache_destroy_net(net); + out1: + rsc_cache_destroy_net(net); + return rv; +diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c +index fb6db09725c76..d55e980521da8 100644 +--- a/net/sunrpc/xprt.c ++++ b/net/sunrpc/xprt.c +@@ -775,9 +775,9 @@ void xprt_force_disconnect(struct rpc_xprt *xprt) + /* Try to schedule an autoclose RPC call */ + if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) + queue_work(xprtiod_workqueue, &xprt->task_cleanup); +- else if (xprt->snd_task) ++ else if (xprt->snd_task && !test_bit(XPRT_SND_IS_COOKIE, &xprt->state)) + rpc_wake_up_queued_task_set_status(&xprt->pending, +- xprt->snd_task, -ENOTCONN); ++ xprt->snd_task, -ENOTCONN); + spin_unlock(&xprt->transport_lock); + } + EXPORT_SYMBOL_GPL(xprt_force_disconnect); +@@ -866,12 +866,14 @@ bool xprt_lock_connect(struct rpc_xprt *xprt, + goto out; + if (xprt->snd_task != task) + goto out; ++ set_bit(XPRT_SND_IS_COOKIE, &xprt->state); + xprt->snd_task = cookie; + ret = true; + out: + spin_unlock(&xprt->transport_lock); + return ret; + } ++EXPORT_SYMBOL_GPL(xprt_lock_connect); + + void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie) + { +@@ -881,12 +883,14 @@ void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie) + if (!test_bit(XPRT_LOCKED, &xprt->state)) + goto out; + xprt->snd_task =NULL; ++ clear_bit(XPRT_SND_IS_COOKIE, &xprt->state); + xprt->ops->release_xprt(xprt, NULL); + xprt_schedule_autodisconnect(xprt); + out: + spin_unlock(&xprt->transport_lock); + wake_up_bit(&xprt->state, XPRT_LOCKED); + } ++EXPORT_SYMBOL_GPL(xprt_unlock_connect); + + /** + * xprt_connect - schedule a transport connect operation +diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c +index 9c2ffc67c0fde..975aef16ad345 100644 +--- a/net/sunrpc/xprtrdma/transport.c ++++ b/net/sunrpc/xprtrdma/transport.c +@@ -250,12 +250,9 @@ xprt_rdma_connect_worker(struct work_struct *work) + xprt->stat.connect_start; + xprt_set_connected(xprt); + rc = -EAGAIN; +- } else { +- /* Force a call to xprt_rdma_close to clean up */ +- spin_lock(&xprt->transport_lock); +- set_bit(XPRT_CLOSE_WAIT, &xprt->state); +- spin_unlock(&xprt->transport_lock); +- } ++ } else ++ rpcrdma_xprt_disconnect(r_xprt); ++ xprt_unlock_connect(xprt, r_xprt); + xprt_wake_pending_tasks(xprt, rc); + } + +@@ -489,6 +486,8 @@ xprt_rdma_connect(struct rpc_xprt *xprt, struct rpc_task *task) + struct rpcrdma_ep *ep = r_xprt->rx_ep; + unsigned long delay; + ++ WARN_ON_ONCE(!xprt_lock_connect(xprt, task, r_xprt)); ++ + delay = 0; + if (ep && ep->re_connect_status != 0) { + delay = xprt_reconnect_delay(xprt); +diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c +index 649c23518ec04..5a11e318a0d99 100644 +--- a/net/sunrpc/xprtrdma/verbs.c ++++ b/net/sunrpc/xprtrdma/verbs.c +@@ -1416,11 +1416,6 @@ void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp) + + rc = ib_post_recv(ep->re_id->qp, wr, + (const struct ib_recv_wr **)&bad_wr); +- if (atomic_dec_return(&ep->re_receiving) > 0) +- complete(&ep->re_done); +- +-out: +- trace_xprtrdma_post_recvs(r_xprt, count, rc); + if (rc) { + for (wr = bad_wr; wr;) { + struct rpcrdma_rep *rep; +@@ -1431,6 +1426,11 @@ out: + --count; + } + } ++ if (atomic_dec_return(&ep->re_receiving) > 0) ++ complete(&ep->re_done); ++ ++out: ++ trace_xprtrdma_post_recvs(r_xprt, count, rc); + ep->re_receive_count += count; + return; + } +diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c +index e573dcecdd66f..02b071dbdd225 100644 +--- a/net/sunrpc/xprtsock.c ++++ b/net/sunrpc/xprtsock.c +@@ -1656,7 +1656,7 @@ static int xs_get_srcport(struct sock_xprt *transport) + unsigned short get_srcport(struct rpc_xprt *xprt) + { + struct sock_xprt *sock = container_of(xprt, struct sock_xprt, xprt); +- return sock->srcport; ++ return xs_sock_getport(sock->sock); + } + EXPORT_SYMBOL(get_srcport); + +diff --git a/net/tipc/socket.c b/net/tipc/socket.c +index 8754bd885169d..a155cfaf01f2e 100644 +--- a/net/tipc/socket.c ++++ b/net/tipc/socket.c +@@ -1886,6 +1886,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, + bool connected = !tipc_sk_type_connectionless(sk); + struct tipc_sock *tsk = tipc_sk(sk); + int rc, err, hlen, dlen, copy; ++ struct tipc_skb_cb *skb_cb; + struct sk_buff_head xmitq; + struct tipc_msg *hdr; + struct sk_buff *skb; +@@ -1909,6 +1910,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, + if (unlikely(rc)) + goto exit; + skb = skb_peek(&sk->sk_receive_queue); ++ skb_cb = TIPC_SKB_CB(skb); + hdr = buf_msg(skb); + dlen = msg_data_sz(hdr); + hlen = msg_hdr_sz(hdr); +@@ -1928,18 +1930,33 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, + + /* Capture data if non-error msg, otherwise just set return value */ + if (likely(!err)) { +- copy = min_t(int, dlen, buflen); +- if (unlikely(copy != dlen)) +- m->msg_flags |= MSG_TRUNC; +- rc = skb_copy_datagram_msg(skb, hlen, m, copy); ++ int offset = skb_cb->bytes_read; ++ ++ copy = min_t(int, dlen - offset, buflen); ++ rc = skb_copy_datagram_msg(skb, hlen + offset, m, copy); ++ if (unlikely(rc)) ++ goto exit; ++ if (unlikely(offset + copy < dlen)) { ++ if (flags & MSG_EOR) { ++ if (!(flags & MSG_PEEK)) ++ skb_cb->bytes_read = offset + copy; ++ } else { ++ m->msg_flags |= MSG_TRUNC; ++ skb_cb->bytes_read = 0; ++ } ++ } else { ++ if (flags & MSG_EOR) ++ m->msg_flags |= MSG_EOR; ++ skb_cb->bytes_read = 0; ++ } + } else { + copy = 0; + rc = 0; +- if (err != TIPC_CONN_SHUTDOWN && connected && !m->msg_control) ++ if (err != TIPC_CONN_SHUTDOWN && connected && !m->msg_control) { + rc = -ECONNRESET; ++ goto exit; ++ } + } +- if (unlikely(rc)) +- goto exit; + + /* Mark message as group event if applicable */ + if (unlikely(grp_evt)) { +@@ -1962,9 +1979,10 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, + tipc_node_distr_xmit(sock_net(sk), &xmitq); + } + +- tsk_advance_rx_queue(sk); ++ if (!skb_cb->bytes_read) ++ tsk_advance_rx_queue(sk); + +- if (likely(!connected)) ++ if (likely(!connected) || skb_cb->bytes_read) + goto exit; + + /* Send connection flow control advertisement when applicable */ +diff --git a/samples/bpf/test_override_return.sh b/samples/bpf/test_override_return.sh +index e68b9ee6814b8..35db26f736b9d 100755 +--- a/samples/bpf/test_override_return.sh ++++ b/samples/bpf/test_override_return.sh +@@ -1,5 +1,6 @@ + #!/bin/bash + ++rm -r tmpmnt + rm -f testfile.img + dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1 + DEVICE=$(losetup --show -f testfile.img) +diff --git a/samples/bpf/tracex7_user.c b/samples/bpf/tracex7_user.c +index fdcd6580dd736..8be7ce18d3ba0 100644 +--- a/samples/bpf/tracex7_user.c ++++ b/samples/bpf/tracex7_user.c +@@ -14,6 +14,11 @@ int main(int argc, char **argv) + int ret = 0; + FILE *f; + ++ if (!argv[1]) { ++ fprintf(stderr, "ERROR: Run with the btrfs device argument!\n"); ++ return 0; ++ } ++ + snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + obj = bpf_object__open_file(filename, NULL); + if (libbpf_get_error(obj)) { +diff --git a/samples/pktgen/pktgen_sample03_burst_single_flow.sh b/samples/pktgen/pktgen_sample03_burst_single_flow.sh +index ab87de4402772..8bf2fdffba16e 100755 +--- a/samples/pktgen/pktgen_sample03_burst_single_flow.sh ++++ b/samples/pktgen/pktgen_sample03_burst_single_flow.sh +@@ -85,7 +85,7 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do + done + + # Run if user hits control-c +-function control_c() { ++function print_result() { + # Print results + for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do + dev=${DEV}@${thread} +@@ -94,11 +94,13 @@ function control_c() { + done + } + # trap keyboard interrupt (Ctrl-C) +-trap control_c SIGINT ++trap true SIGINT + + if [ -z "$APPEND" ]; then + echo "Running... ctrl^C to stop" >&2 + pg_ctrl "start" ++ ++ print_result + else + echo "Append mode: config done. Do more or use 'pg_ctrl start' to run" + fi +diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c +index 6c0f229db36a1..b4aaeab377545 100644 +--- a/samples/vfio-mdev/mbochs.c ++++ b/samples/vfio-mdev/mbochs.c +@@ -129,7 +129,7 @@ static dev_t mbochs_devt; + static struct class *mbochs_class; + static struct cdev mbochs_cdev; + static struct device mbochs_dev; +-static int mbochs_used_mbytes; ++static atomic_t mbochs_avail_mbytes; + static const struct vfio_device_ops mbochs_dev_ops; + + struct vfio_region_info_ext { +@@ -507,18 +507,22 @@ static int mbochs_reset(struct mdev_state *mdev_state) + + static int mbochs_probe(struct mdev_device *mdev) + { ++ int avail_mbytes = atomic_read(&mbochs_avail_mbytes); + const struct mbochs_type *type = + &mbochs_types[mdev_get_type_group_id(mdev)]; + struct device *dev = mdev_dev(mdev); + struct mdev_state *mdev_state; + int ret = -ENOMEM; + +- if (type->mbytes + mbochs_used_mbytes > max_mbytes) +- return -ENOMEM; ++ do { ++ if (avail_mbytes < type->mbytes) ++ return -ENOSPC; ++ } while (!atomic_try_cmpxchg(&mbochs_avail_mbytes, &avail_mbytes, ++ avail_mbytes - type->mbytes)); + + mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); + if (mdev_state == NULL) +- return -ENOMEM; ++ goto err_avail; + vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mbochs_dev_ops); + + mdev_state->vconfig = kzalloc(MBOCHS_CONFIG_SPACE_SIZE, GFP_KERNEL); +@@ -549,17 +553,17 @@ static int mbochs_probe(struct mdev_device *mdev) + mbochs_create_config_space(mdev_state); + mbochs_reset(mdev_state); + +- mbochs_used_mbytes += type->mbytes; +- + ret = vfio_register_group_dev(&mdev_state->vdev); + if (ret) + goto err_mem; + dev_set_drvdata(&mdev->dev, mdev_state); + return 0; +- + err_mem: ++ kfree(mdev_state->pages); + kfree(mdev_state->vconfig); + kfree(mdev_state); ++err_avail: ++ atomic_add(type->mbytes, &mbochs_avail_mbytes); + return ret; + } + +@@ -567,8 +571,8 @@ static void mbochs_remove(struct mdev_device *mdev) + { + struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); + +- mbochs_used_mbytes -= mdev_state->type->mbytes; + vfio_unregister_group_dev(&mdev_state->vdev); ++ atomic_add(mdev_state->type->mbytes, &mbochs_avail_mbytes); + kfree(mdev_state->pages); + kfree(mdev_state->vconfig); + kfree(mdev_state); +@@ -1355,7 +1359,7 @@ static ssize_t available_instances_show(struct mdev_type *mtype, + { + const struct mbochs_type *type = + &mbochs_types[mtype_get_type_group_id(mtype)]; +- int count = (max_mbytes - mbochs_used_mbytes) / type->mbytes; ++ int count = atomic_read(&mbochs_avail_mbytes) / type->mbytes; + + return sprintf(buf, "%d\n", count); + } +@@ -1437,6 +1441,8 @@ static int __init mbochs_dev_init(void) + { + int ret = 0; + ++ atomic_set(&mbochs_avail_mbytes, max_mbytes); ++ + ret = alloc_chrdev_region(&mbochs_devt, 0, MINORMASK + 1, MBOCHS_NAME); + if (ret < 0) { + pr_err("Error: failed to register mbochs_dev, err: %d\n", ret); +diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh +index 1324986e1362c..725e8c9c1b53f 100755 +--- a/scripts/gen_ksymdeps.sh ++++ b/scripts/gen_ksymdeps.sh +@@ -4,7 +4,13 @@ + set -e + + # List of exported symbols +-ksyms=$($NM $1 | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z) ++# ++# If the object has no symbol, $NM warns 'no symbols'. ++# Suppress the stderr. ++# TODO: ++# Use -q instead of 2>/dev/null when we upgrade the minimum version of ++# binutils to 2.37, llvm to 13.0.0. ++ksyms=$($NM $1 2>/dev/null | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z) + + if [ -z "$ksyms" ]; then + exit 0 +diff --git a/scripts/subarch.include b/scripts/subarch.include +index 650682821126c..776849a3c500f 100644 +--- a/scripts/subarch.include ++++ b/scripts/subarch.include +@@ -7,7 +7,7 @@ + SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ + -e s/sun4u/sparc64/ \ + -e s/arm.*/arm/ -e s/sa110/arm/ \ +- -e s/s390x/s390/ -e s/parisc64/parisc/ \ ++ -e s/s390x/s390/ \ + -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/) +diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c +index 1f391f6a3d470..d2186e2757be8 100644 +--- a/security/smack/smack_access.c ++++ b/security/smack/smack_access.c +@@ -81,23 +81,22 @@ int log_policy = SMACK_AUDIT_DENIED; + int smk_access_entry(char *subject_label, char *object_label, + struct list_head *rule_list) + { +- int may = -ENOENT; + struct smack_rule *srp; + + list_for_each_entry_rcu(srp, rule_list, list) { + if (srp->smk_object->smk_known == object_label && + srp->smk_subject->smk_known == subject_label) { +- may = srp->smk_access; +- break; ++ int may = srp->smk_access; ++ /* ++ * MAY_WRITE implies MAY_LOCK. ++ */ ++ if ((may & MAY_WRITE) == MAY_WRITE) ++ may |= MAY_LOCK; ++ return may; + } + } + +- /* +- * MAY_WRITE implies MAY_LOCK. +- */ +- if ((may & MAY_WRITE) == MAY_WRITE) +- may |= MAY_LOCK; +- return may; ++ return -ENOENT; + } + + /** +diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig +index ec04e3386bc0e..8617793ed9557 100644 +--- a/sound/soc/atmel/Kconfig ++++ b/sound/soc/atmel/Kconfig +@@ -11,7 +11,6 @@ if SND_ATMEL_SOC + + config SND_ATMEL_SOC_PDC + bool +- depends on HAS_DMA + + config SND_ATMEL_SOC_DMA + bool +diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c +index 91a6d712eb585..c403fb6725944 100644 +--- a/sound/soc/intel/boards/bytcr_rt5640.c ++++ b/sound/soc/intel/boards/bytcr_rt5640.c +@@ -290,9 +290,6 @@ static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { + static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { + {"Headphone", NULL, "Platform Clock"}, + {"Headset Mic", NULL, "Platform Clock"}, +- {"Internal Mic", NULL, "Platform Clock"}, +- {"Speaker", NULL, "Platform Clock"}, +- + {"Headset Mic", NULL, "MICBIAS1"}, + {"IN2P", NULL, "Headset Mic"}, + {"Headphone", NULL, "HPOL"}, +@@ -300,19 +297,23 @@ static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { + }; + + static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = { ++ {"Internal Mic", NULL, "Platform Clock"}, + {"DMIC1", NULL, "Internal Mic"}, + }; + + static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = { ++ {"Internal Mic", NULL, "Platform Clock"}, + {"DMIC2", NULL, "Internal Mic"}, + }; + + static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = { ++ {"Internal Mic", NULL, "Platform Clock"}, + {"Internal Mic", NULL, "MICBIAS1"}, + {"IN1P", NULL, "Internal Mic"}, + }; + + static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = { ++ {"Internal Mic", NULL, "Platform Clock"}, + {"Internal Mic", NULL, "MICBIAS1"}, + {"IN3P", NULL, "Internal Mic"}, + }; +@@ -354,6 +355,7 @@ static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = { + }; + + static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = { ++ {"Speaker", NULL, "Platform Clock"}, + {"Speaker", NULL, "SPOLP"}, + {"Speaker", NULL, "SPOLN"}, + {"Speaker", NULL, "SPORP"}, +@@ -361,6 +363,7 @@ static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = { + }; + + static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = { ++ {"Speaker", NULL, "Platform Clock"}, + {"Speaker", NULL, "SPOLP"}, + {"Speaker", NULL, "SPOLN"}, + }; +diff --git a/sound/soc/intel/boards/sof_pcm512x.c b/sound/soc/intel/boards/sof_pcm512x.c +index 2ec9c62366e2e..6815204e58d58 100644 +--- a/sound/soc/intel/boards/sof_pcm512x.c ++++ b/sound/soc/intel/boards/sof_pcm512x.c +@@ -26,11 +26,16 @@ + + #define SOF_PCM512X_SSP_CODEC(quirk) ((quirk) & GENMASK(3, 0)) + #define SOF_PCM512X_SSP_CODEC_MASK (GENMASK(3, 0)) ++#define SOF_PCM512X_ENABLE_SSP_CAPTURE BIT(4) ++#define SOF_PCM512X_ENABLE_DMIC BIT(5) + + #define IDISP_CODEC_MASK 0x4 + + /* Default: SSP5 */ +-static unsigned long sof_pcm512x_quirk = SOF_PCM512X_SSP_CODEC(5); ++static unsigned long sof_pcm512x_quirk = ++ SOF_PCM512X_SSP_CODEC(5) | ++ SOF_PCM512X_ENABLE_SSP_CAPTURE | ++ SOF_PCM512X_ENABLE_DMIC; + + static bool is_legacy_cpu; + +@@ -244,8 +249,9 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, + links[id].dpcm_playback = 1; + /* + * capture only supported with specific versions of the Hifiberry DAC+ +- * links[id].dpcm_capture = 1; + */ ++ if (sof_pcm512x_quirk & SOF_PCM512X_ENABLE_SSP_CAPTURE) ++ links[id].dpcm_capture = 1; + links[id].no_pcm = 1; + links[id].cpus = &cpus[id]; + links[id].num_cpus = 1; +@@ -380,6 +386,9 @@ static int sof_audio_probe(struct platform_device *pdev) + + ssp_codec = sof_pcm512x_quirk & SOF_PCM512X_SSP_CODEC_MASK; + ++ if (!(sof_pcm512x_quirk & SOF_PCM512X_ENABLE_DMIC)) ++ dmic_be_num = 0; ++ + /* compute number of dai links */ + sof_audio_card_pcm512x.num_links = 1 + dmic_be_num + hdmi_num; + +diff --git a/sound/soc/intel/skylake/skl-messages.c b/sound/soc/intel/skylake/skl-messages.c +index 476ef1897961d..79c6cf2c14bfb 100644 +--- a/sound/soc/intel/skylake/skl-messages.c ++++ b/sound/soc/intel/skylake/skl-messages.c +@@ -802,9 +802,12 @@ static u16 skl_get_module_param_size(struct skl_dev *skl, + + case SKL_MODULE_TYPE_BASE_OUTFMT: + case SKL_MODULE_TYPE_MIC_SELECT: +- case SKL_MODULE_TYPE_KPB: + return sizeof(struct skl_base_outfmt_cfg); + ++ case SKL_MODULE_TYPE_MIXER: ++ case SKL_MODULE_TYPE_KPB: ++ return sizeof(struct skl_base_cfg); ++ + default: + /* + * return only base cfg when no specific module type is +@@ -857,10 +860,14 @@ static int skl_set_module_format(struct skl_dev *skl, + + case SKL_MODULE_TYPE_BASE_OUTFMT: + case SKL_MODULE_TYPE_MIC_SELECT: +- case SKL_MODULE_TYPE_KPB: + skl_set_base_outfmt_format(skl, module_config, *param_data); + break; + ++ case SKL_MODULE_TYPE_MIXER: ++ case SKL_MODULE_TYPE_KPB: ++ skl_set_base_module_format(skl, module_config, *param_data); ++ break; ++ + default: + skl_set_base_module_format(skl, module_config, *param_data); + break; +diff --git a/sound/soc/intel/skylake/skl-pcm.c b/sound/soc/intel/skylake/skl-pcm.c +index b1ca64d2f7ea6..031d5dc7e6601 100644 +--- a/sound/soc/intel/skylake/skl-pcm.c ++++ b/sound/soc/intel/skylake/skl-pcm.c +@@ -1317,21 +1317,6 @@ static int skl_get_module_info(struct skl_dev *skl, + return -EIO; + } + +- list_for_each_entry(module, &skl->uuid_list, list) { +- if (guid_equal(uuid_mod, &module->uuid)) { +- mconfig->id.module_id = module->id; +- if (mconfig->module) +- mconfig->module->loadable = module->is_loadable; +- ret = 0; +- break; +- } +- } +- +- if (ret) +- return ret; +- +- uuid_mod = &module->uuid; +- ret = -EIO; + for (i = 0; i < skl->nr_modules; i++) { + skl_module = skl->modules[i]; + uuid_tplg = &skl_module->uuid; +@@ -1341,10 +1326,18 @@ static int skl_get_module_info(struct skl_dev *skl, + break; + } + } ++ + if (skl->nr_modules && ret) + return ret; + ++ ret = -EIO; + list_for_each_entry(module, &skl->uuid_list, list) { ++ if (guid_equal(uuid_mod, &module->uuid)) { ++ mconfig->id.module_id = module->id; ++ mconfig->module->loadable = module->is_loadable; ++ ret = 0; ++ } ++ + for (i = 0; i < MAX_IN_QUEUE; i++) { + pin_id = &mconfig->m_in_pin[i].id; + if (guid_equal(&pin_id->mod_uuid, &module->uuid)) +@@ -1358,7 +1351,7 @@ static int skl_get_module_info(struct skl_dev *skl, + } + } + +- return 0; ++ return ret; + } + + static int skl_populate_modules(struct skl_dev *skl) +diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c +index c7dc3509bceb6..b65dfbc3545b9 100644 +--- a/sound/soc/rockchip/rockchip_i2s.c ++++ b/sound/soc/rockchip/rockchip_i2s.c +@@ -186,7 +186,9 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + { + struct rk_i2s_dev *i2s = to_info(cpu_dai); + unsigned int mask = 0, val = 0; ++ int ret = 0; + ++ pm_runtime_get_sync(cpu_dai->dev); + mask = I2S_CKR_MSS_MASK; + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { + case SND_SOC_DAIFMT_CBS_CFS: +@@ -199,7 +201,8 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + i2s->is_master_mode = false; + break; + default: +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_pm_put; + } + + regmap_update_bits(i2s->regmap, I2S_CKR, mask, val); +@@ -213,7 +216,8 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + val = I2S_CKR_CKP_POS; + break; + default: +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_pm_put; + } + + regmap_update_bits(i2s->regmap, I2S_CKR, mask, val); +@@ -229,14 +233,15 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + case SND_SOC_DAIFMT_I2S: + val = I2S_TXCR_IBM_NORMAL; + break; +- case SND_SOC_DAIFMT_DSP_A: /* PCM no delay mode */ +- val = I2S_TXCR_TFS_PCM; +- break; +- case SND_SOC_DAIFMT_DSP_B: /* PCM delay 1 mode */ ++ case SND_SOC_DAIFMT_DSP_A: /* PCM delay 1 bit mode */ + val = I2S_TXCR_TFS_PCM | I2S_TXCR_PBM_MODE(1); + break; ++ case SND_SOC_DAIFMT_DSP_B: /* PCM no delay mode */ ++ val = I2S_TXCR_TFS_PCM; ++ break; + default: +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_pm_put; + } + + regmap_update_bits(i2s->regmap, I2S_TXCR, mask, val); +@@ -252,19 +257,23 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + case SND_SOC_DAIFMT_I2S: + val = I2S_RXCR_IBM_NORMAL; + break; +- case SND_SOC_DAIFMT_DSP_A: /* PCM no delay mode */ +- val = I2S_RXCR_TFS_PCM; +- break; +- case SND_SOC_DAIFMT_DSP_B: /* PCM delay 1 mode */ ++ case SND_SOC_DAIFMT_DSP_A: /* PCM delay 1 bit mode */ + val = I2S_RXCR_TFS_PCM | I2S_RXCR_PBM_MODE(1); + break; ++ case SND_SOC_DAIFMT_DSP_B: /* PCM no delay mode */ ++ val = I2S_RXCR_TFS_PCM; ++ break; + default: +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_pm_put; + } + + regmap_update_bits(i2s->regmap, I2S_RXCR, mask, val); + +- return 0; ++err_pm_put: ++ pm_runtime_put(cpu_dai->dev); ++ ++ return ret; + } + + static int rockchip_i2s_hw_params(struct snd_pcm_substream *substream, +diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c +index 0ebee1ed06a90..5f1e72edfee04 100644 +--- a/sound/soc/sh/rcar/adg.c ++++ b/sound/soc/sh/rcar/adg.c +@@ -391,9 +391,9 @@ static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv, + struct clk *clk; + + clk = clk_register_fixed_rate(dev, name, parent, 0, 0); +- if (IS_ERR(clk)) { ++ if (IS_ERR_OR_NULL(clk)) { + dev_err(dev, "create null clk error\n"); +- return NULL; ++ return ERR_CAST(clk); + } + + return clk; +@@ -430,9 +430,9 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv) + for (i = 0; i < CLKMAX; i++) { + clk = devm_clk_get(dev, clk_name[i]); + +- if (IS_ERR(clk)) ++ if (IS_ERR_OR_NULL(clk)) + clk = rsnd_adg_null_clk_get(priv); +- if (IS_ERR(clk)) ++ if (IS_ERR_OR_NULL(clk)) + goto err; + + adg->clk[i] = clk; +@@ -582,7 +582,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) + if (!count) { + clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT], + parent_clk_name, 0, req_rate[0]); +- if (IS_ERR(clk)) ++ if (IS_ERR_OR_NULL(clk)) + goto err; + + adg->clkout[CLKOUT] = clk; +@@ -596,7 +596,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) + clk = clk_register_fixed_rate(dev, clkout_name[i], + parent_clk_name, 0, + req_rate[0]); +- if (IS_ERR(clk)) ++ if (IS_ERR_OR_NULL(clk)) + goto err; + + adg->clkout[i] = clk; +diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c +index d1c570ca21ea7..b944f56a469a6 100644 +--- a/sound/soc/soc-pcm.c ++++ b/sound/soc/soc-pcm.c +@@ -2001,6 +2001,8 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, + struct snd_soc_pcm_runtime *be; + struct snd_soc_dpcm *dpcm; + int ret = 0; ++ unsigned long flags; ++ enum snd_soc_dpcm_state state; + + for_each_dpcm_be(fe, stream, dpcm) { + struct snd_pcm_substream *be_substream; +@@ -2017,76 +2019,141 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); + if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && + (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) && +- (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) ++ (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) { ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + continue; ++ } ++ state = be->dpcm[stream].state; ++ be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + + ret = soc_pcm_trigger(be_substream, cmd); +- if (ret) ++ if (ret) { ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ be->dpcm[stream].state = state; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + goto end; ++ } + +- be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; + break; + case SNDRV_PCM_TRIGGER_RESUME: +- if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND)) ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND) { ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + continue; ++ } ++ ++ state = be->dpcm[stream].state; ++ be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + + ret = soc_pcm_trigger(be_substream, cmd); +- if (ret) ++ if (ret) { ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ be->dpcm[stream].state = state; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + goto end; ++ } + +- be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; + break; + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: +- if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) { ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + continue; ++ } ++ ++ state = be->dpcm[stream].state; ++ be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + + ret = soc_pcm_trigger(be_substream, cmd); +- if (ret) ++ if (ret) { ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ be->dpcm[stream].state = state; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + goto end; ++ } + +- be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; + break; + case SNDRV_PCM_TRIGGER_STOP: ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); + if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) && +- (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) ++ (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) { ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + continue; ++ } ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + + if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) + continue; + ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ state = be->dpcm[stream].state; ++ be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); ++ + ret = soc_pcm_trigger(be_substream, cmd); +- if (ret) ++ if (ret) { ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ be->dpcm[stream].state = state; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + goto end; ++ } + +- be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; + break; + case SNDRV_PCM_TRIGGER_SUSPEND: +- if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) { ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + continue; ++ } ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + + if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) + continue; + ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ state = be->dpcm[stream].state; ++ be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); ++ + ret = soc_pcm_trigger(be_substream, cmd); +- if (ret) ++ if (ret) { ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ be->dpcm[stream].state = state; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + goto end; ++ } + +- be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND; + break; + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: +- if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) { ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + continue; ++ } ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + + if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) + continue; + ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ state = be->dpcm[stream].state; ++ be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); ++ + ret = soc_pcm_trigger(be_substream, cmd); +- if (ret) ++ if (ret) { ++ spin_lock_irqsave(&fe->card->dpcm_lock, flags); ++ be->dpcm[stream].state = state; ++ spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + goto end; ++ } + +- be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; + break; + } + } +diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c +index 017a5a5e56cd1..64ec6d4858348 100644 +--- a/sound/soc/ti/davinci-mcasp.c ++++ b/sound/soc/ti/davinci-mcasp.c +@@ -83,6 +83,8 @@ struct davinci_mcasp { + struct snd_pcm_substream *substreams[2]; + unsigned int dai_fmt; + ++ u32 iec958_status; ++ + /* Audio can not be enabled due to missing parameter(s) */ + bool missing_audio_param; + +@@ -757,6 +759,9 @@ static int davinci_mcasp_set_tdm_slot(struct snd_soc_dai *dai, + { + struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); + ++ if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE) ++ return 0; ++ + dev_dbg(mcasp->dev, + "%s() tx_mask 0x%08x rx_mask 0x%08x slots %d width %d\n", + __func__, tx_mask, rx_mask, slots, slot_width); +@@ -827,6 +832,20 @@ static int davinci_config_channel_size(struct davinci_mcasp *mcasp, + mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXROT(rx_rotate), + RXROT(7)); + mcasp_set_reg(mcasp, DAVINCI_MCASP_RXMASK_REG, mask); ++ } else { ++ /* ++ * according to the TRM it should be TXROT=0, this one works: ++ * 16 bit to 23-8 (TXROT=6, rotate 24 bits) ++ * 24 bit to 23-0 (TXROT=0, rotate 0 bits) ++ * ++ * TXROT = 0 only works with 24bit samples ++ */ ++ tx_rotate = (sample_width / 4 + 2) & 0x7; ++ ++ mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(tx_rotate), ++ TXROT(7)); ++ mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(15), ++ TXSSZ(0x0F)); + } + + mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask); +@@ -842,10 +861,16 @@ static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream, + u8 tx_ser = 0; + u8 rx_ser = 0; + u8 slots = mcasp->tdm_slots; +- u8 max_active_serializers = (channels + slots - 1) / slots; +- u8 max_rx_serializers, max_tx_serializers; ++ u8 max_active_serializers, max_rx_serializers, max_tx_serializers; + int active_serializers, numevt; + u32 reg; ++ ++ /* In DIT mode we only allow maximum of one serializers for now */ ++ if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE) ++ max_active_serializers = 1; ++ else ++ max_active_serializers = (channels + slots - 1) / slots; ++ + /* Default configuration */ + if (mcasp->version < MCASP_VERSION_3) + mcasp_set_bits(mcasp, DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT); +@@ -1031,16 +1056,18 @@ static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream, + static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp, + unsigned int rate) + { +- u32 cs_value = 0; +- u8 *cs_bytes = (u8*) &cs_value; ++ u8 *cs_bytes = (u8 *)&mcasp->iec958_status; + +- /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0 +- and LSB first */ +- mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(6) | TXSSZ(15)); ++ if (!mcasp->dat_port) ++ mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSEL); ++ else ++ mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSEL); + + /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */ + mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE | FSXMOD(0x180)); + ++ mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, 0xFFFF); ++ + /* Set the TX tdm : for all the slots */ + mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF); + +@@ -1049,16 +1076,8 @@ static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp, + + mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS); + +- /* Only 44100 and 48000 are valid, both have the same setting */ +- mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3)); +- +- /* Enable the DIT */ +- mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN); +- + /* Set S/PDIF channel status bits */ +- cs_bytes[0] = IEC958_AES0_CON_NOT_COPYRIGHT; +- cs_bytes[1] = IEC958_AES1_CON_PCM_CODER; +- ++ cs_bytes[3] &= ~IEC958_AES3_CON_FS; + switch (rate) { + case 22050: + cs_bytes[3] |= IEC958_AES3_CON_FS_22050; +@@ -1088,12 +1107,15 @@ static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp, + cs_bytes[3] |= IEC958_AES3_CON_FS_192000; + break; + default: +- printk(KERN_WARNING "unsupported sampling rate: %d\n", rate); ++ dev_err(mcasp->dev, "unsupported sampling rate: %d\n", rate); + return -EINVAL; + } + +- mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRA_REG, cs_value); +- mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRB_REG, cs_value); ++ mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRA_REG, mcasp->iec958_status); ++ mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRB_REG, mcasp->iec958_status); ++ ++ /* Enable the DIT */ ++ mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN); + + return 0; + } +@@ -1237,12 +1259,18 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, + int slots = mcasp->tdm_slots; + int rate = params_rate(params); + int sbits = params_width(params); ++ unsigned int bclk_target; + + if (mcasp->slot_width) + sbits = mcasp->slot_width; + ++ if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) ++ bclk_target = rate * sbits * slots; ++ else ++ bclk_target = rate * 128; ++ + davinci_mcasp_calc_clk_div(mcasp, mcasp->sysclk_freq, +- rate * sbits * slots, true); ++ bclk_target, true); + } + + ret = mcasp_common_hw_param(mcasp, substream->stream, +@@ -1598,6 +1626,77 @@ static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = { + .set_tdm_slot = davinci_mcasp_set_tdm_slot, + }; + ++static int davinci_mcasp_iec958_info(struct snd_kcontrol *kcontrol, ++ struct snd_ctl_elem_info *uinfo) ++{ ++ uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; ++ uinfo->count = 1; ++ ++ return 0; ++} ++ ++static int davinci_mcasp_iec958_get(struct snd_kcontrol *kcontrol, ++ struct snd_ctl_elem_value *uctl) ++{ ++ struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol); ++ struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); ++ ++ memcpy(uctl->value.iec958.status, &mcasp->iec958_status, ++ sizeof(mcasp->iec958_status)); ++ ++ return 0; ++} ++ ++static int davinci_mcasp_iec958_put(struct snd_kcontrol *kcontrol, ++ struct snd_ctl_elem_value *uctl) ++{ ++ struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol); ++ struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); ++ ++ memcpy(&mcasp->iec958_status, uctl->value.iec958.status, ++ sizeof(mcasp->iec958_status)); ++ ++ return 0; ++} ++ ++static int davinci_mcasp_iec958_con_mask_get(struct snd_kcontrol *kcontrol, ++ struct snd_ctl_elem_value *ucontrol) ++{ ++ struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol); ++ struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); ++ ++ memset(ucontrol->value.iec958.status, 0xff, sizeof(mcasp->iec958_status)); ++ return 0; ++} ++ ++static const struct snd_kcontrol_new davinci_mcasp_iec958_ctls[] = { ++ { ++ .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | ++ SNDRV_CTL_ELEM_ACCESS_VOLATILE), ++ .iface = SNDRV_CTL_ELEM_IFACE_PCM, ++ .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), ++ .info = davinci_mcasp_iec958_info, ++ .get = davinci_mcasp_iec958_get, ++ .put = davinci_mcasp_iec958_put, ++ }, { ++ .access = SNDRV_CTL_ELEM_ACCESS_READ, ++ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, ++ .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), ++ .info = davinci_mcasp_iec958_info, ++ .get = davinci_mcasp_iec958_con_mask_get, ++ }, ++}; ++ ++static void davinci_mcasp_init_iec958_status(struct davinci_mcasp *mcasp) ++{ ++ unsigned char *cs = (u8 *)&mcasp->iec958_status; ++ ++ cs[0] = IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS_NONE; ++ cs[1] = IEC958_AES1_CON_PCM_CODER; ++ cs[2] = IEC958_AES2_CON_SOURCE_UNSPEC | IEC958_AES2_CON_CHANNEL_UNSPEC; ++ cs[3] = IEC958_AES3_CON_CLOCK_1000PPM; ++} ++ + static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai) + { + struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); +@@ -1605,6 +1704,12 @@ static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai) + dai->playback_dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK]; + dai->capture_dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE]; + ++ if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE) { ++ davinci_mcasp_init_iec958_status(mcasp); ++ snd_soc_add_dai_controls(dai, davinci_mcasp_iec958_ctls, ++ ARRAY_SIZE(davinci_mcasp_iec958_ctls)); ++ } ++ + return 0; + } + +@@ -1651,7 +1756,8 @@ static struct snd_soc_dai_driver davinci_mcasp_dai[] = { + .channels_min = 1, + .channels_max = 384, + .rates = DAVINCI_MCASP_RATES, +- .formats = DAVINCI_MCASP_PCM_FMTS, ++ .formats = SNDRV_PCM_FMTBIT_S16_LE | ++ SNDRV_PCM_FMTBIT_S24_LE, + }, + .ops = &davinci_mcasp_dai_ops, + }, +@@ -1871,6 +1977,8 @@ out: + } else { + mcasp->tdm_slots = pdata->tdm_slots; + } ++ } else { ++ mcasp->tdm_slots = 32; + } + + mcasp->num_serializer = pdata->num_serializer; +diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c +index 2234d5c33177a..d27e017ebfbea 100644 +--- a/tools/lib/bpf/libbpf.c ++++ b/tools/lib/bpf/libbpf.c +@@ -3894,6 +3894,42 @@ static int bpf_map_find_btf_info(struct bpf_object *obj, struct bpf_map *map) + return 0; + } + ++static int bpf_get_map_info_from_fdinfo(int fd, struct bpf_map_info *info) ++{ ++ char file[PATH_MAX], buff[4096]; ++ FILE *fp; ++ __u32 val; ++ int err; ++ ++ snprintf(file, sizeof(file), "/proc/%d/fdinfo/%d", getpid(), fd); ++ memset(info, 0, sizeof(*info)); ++ ++ fp = fopen(file, "r"); ++ if (!fp) { ++ err = -errno; ++ pr_warn("failed to open %s: %d. No procfs support?\n", file, ++ err); ++ return err; ++ } ++ ++ while (fgets(buff, sizeof(buff), fp)) { ++ if (sscanf(buff, "map_type:\t%u", &val) == 1) ++ info->type = val; ++ else if (sscanf(buff, "key_size:\t%u", &val) == 1) ++ info->key_size = val; ++ else if (sscanf(buff, "value_size:\t%u", &val) == 1) ++ info->value_size = val; ++ else if (sscanf(buff, "max_entries:\t%u", &val) == 1) ++ info->max_entries = val; ++ else if (sscanf(buff, "map_flags:\t%i", &val) == 1) ++ info->map_flags = val; ++ } ++ ++ fclose(fp); ++ ++ return 0; ++} ++ + int bpf_map__reuse_fd(struct bpf_map *map, int fd) + { + struct bpf_map_info info = {}; +@@ -3902,6 +3938,8 @@ int bpf_map__reuse_fd(struct bpf_map *map, int fd) + char *new_name; + + err = bpf_obj_get_info_by_fd(fd, &info, &len); ++ if (err && errno == EINVAL) ++ err = bpf_get_map_info_from_fdinfo(fd, &info); + if (err) + return libbpf_err(err); + +@@ -4381,12 +4419,16 @@ static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd) + struct bpf_map_info map_info = {}; + char msg[STRERR_BUFSIZE]; + __u32 map_info_len; ++ int err; + + map_info_len = sizeof(map_info); + +- if (bpf_obj_get_info_by_fd(map_fd, &map_info, &map_info_len)) { +- pr_warn("failed to get map info for map FD %d: %s\n", +- map_fd, libbpf_strerror_r(errno, msg, sizeof(msg))); ++ err = bpf_obj_get_info_by_fd(map_fd, &map_info, &map_info_len); ++ if (err && errno == EINVAL) ++ err = bpf_get_map_info_from_fdinfo(map_fd, &map_info); ++ if (err) { ++ pr_warn("failed to get map info for map FD %d: %s\n", map_fd, ++ libbpf_strerror_r(errno, msg, sizeof(msg))); + return false; + } + +@@ -4614,10 +4656,13 @@ bpf_object__create_maps(struct bpf_object *obj) + char *cp, errmsg[STRERR_BUFSIZE]; + unsigned int i, j; + int err; ++ bool retried; + + for (i = 0; i < obj->nr_maps; i++) { + map = &obj->maps[i]; + ++ retried = false; ++retry: + if (map->pin_path) { + err = bpf_object__reuse_map(map); + if (err) { +@@ -4625,6 +4670,12 @@ bpf_object__create_maps(struct bpf_object *obj) + map->name); + goto err_out; + } ++ if (retried && map->fd < 0) { ++ pr_warn("map '%s': cannot find pinned map\n", ++ map->name); ++ err = -ENOENT; ++ goto err_out; ++ } + } + + if (map->fd >= 0) { +@@ -4658,9 +4709,13 @@ bpf_object__create_maps(struct bpf_object *obj) + if (map->pin_path && !map->pinned) { + err = bpf_map__pin(map, NULL); + if (err) { ++ zclose(map->fd); ++ if (!retried && err == -EEXIST) { ++ retried = true; ++ goto retry; ++ } + pr_warn("map '%s': failed to auto-pin at '%s': %d\n", + map->name, map->pin_path, err); +- zclose(map->fd); + goto err_out; + } + } +diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c +index f50ac31920d13..0328a1e08f659 100644 +--- a/tools/testing/selftests/arm64/mte/mte_common_util.c ++++ b/tools/testing/selftests/arm64/mte/mte_common_util.c +@@ -298,7 +298,7 @@ int mte_default_setup(void) + int ret; + + if (!(hwcaps2 & HWCAP2_MTE)) { +- ksft_print_msg("FAIL: MTE features unavailable\n"); ++ ksft_print_msg("SKIP: MTE features unavailable\n"); + return KSFT_SKIP; + } + /* Get current mte mode */ +diff --git a/tools/testing/selftests/arm64/pauth/pac.c b/tools/testing/selftests/arm64/pauth/pac.c +index 592fe538506e3..b743daa772f55 100644 +--- a/tools/testing/selftests/arm64/pauth/pac.c ++++ b/tools/testing/selftests/arm64/pauth/pac.c +@@ -25,13 +25,15 @@ + do { \ + unsigned long hwcaps = getauxval(AT_HWCAP); \ + /* data key instructions are not in NOP space. This prevents a SIGILL */ \ +- ASSERT_NE(0, hwcaps & HWCAP_PACA) TH_LOG("PAUTH not enabled"); \ ++ if (!(hwcaps & HWCAP_PACA)) \ ++ SKIP(return, "PAUTH not enabled"); \ + } while (0) + #define ASSERT_GENERIC_PAUTH_ENABLED() \ + do { \ + unsigned long hwcaps = getauxval(AT_HWCAP); \ + /* generic key instructions are not in NOP space. This prevents a SIGILL */ \ +- ASSERT_NE(0, hwcaps & HWCAP_PACG) TH_LOG("Generic PAUTH not enabled"); \ ++ if (!(hwcaps & HWCAP_PACG)) \ ++ SKIP(return, "Generic PAUTH not enabled"); \ + } while (0) + + void sign_specific(struct signatures *sign, size_t val) +@@ -256,7 +258,7 @@ TEST(single_thread_different_keys) + unsigned long hwcaps = getauxval(AT_HWCAP); + + /* generic and data key instructions are not in NOP space. This prevents a SIGILL */ +- ASSERT_NE(0, hwcaps & HWCAP_PACA) TH_LOG("PAUTH not enabled"); ++ ASSERT_PAUTH_ENABLED(); + if (!(hwcaps & HWCAP_PACG)) { + TH_LOG("WARNING: Generic PAUTH not enabled. Skipping generic key checks"); + nkeys = NKEYS - 1; +@@ -299,7 +301,7 @@ TEST(exec_changed_keys) + unsigned long hwcaps = getauxval(AT_HWCAP); + + /* generic and data key instructions are not in NOP space. This prevents a SIGILL */ +- ASSERT_NE(0, hwcaps & HWCAP_PACA) TH_LOG("PAUTH not enabled"); ++ ASSERT_PAUTH_ENABLED(); + if (!(hwcaps & HWCAP_PACG)) { + TH_LOG("WARNING: Generic PAUTH not enabled. Skipping generic key checks"); + nkeys = NKEYS - 1; +diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c +index 023cc532992d3..839f7ddaec16c 100644 +--- a/tools/testing/selftests/bpf/prog_tests/send_signal.c ++++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c +@@ -1,5 +1,7 @@ + // SPDX-License-Identifier: GPL-2.0 + #include ++#include ++#include + #include "test_send_signal_kern.skel.h" + + int sigusr1_received = 0; +@@ -41,12 +43,23 @@ static void test_send_signal_common(struct perf_event_attr *attr, + } + + if (pid == 0) { ++ int old_prio; ++ + /* install signal handler and notify parent */ + signal(SIGUSR1, sigusr1_handler); + + close(pipe_c2p[0]); /* close read */ + close(pipe_p2c[1]); /* close write */ + ++ /* boost with a high priority so we got a higher chance ++ * that if an interrupt happens, the underlying task ++ * is this process. ++ */ ++ errno = 0; ++ old_prio = getpriority(PRIO_PROCESS, 0); ++ ASSERT_OK(errno, "getpriority"); ++ ASSERT_OK(setpriority(PRIO_PROCESS, 0, -20), "setpriority"); ++ + /* notify parent signal handler is installed */ + CHECK(write(pipe_c2p[1], buf, 1) != 1, "pipe_write", "err %d\n", -errno); + +@@ -62,6 +75,9 @@ static void test_send_signal_common(struct perf_event_attr *attr, + /* wait for parent notification and exit */ + CHECK(read(pipe_p2c[0], buf, 1) != 1, "pipe_read", "err %d\n", -errno); + ++ /* restore the old priority */ ++ ASSERT_OK(setpriority(PRIO_PROCESS, 0, old_prio), "setpriority"); ++ + close(pipe_c2p[1]); + close(pipe_p2c[0]); + exit(0); +diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +index ec281b0363b82..86f97681ad898 100644 +--- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c ++++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +@@ -195,8 +195,10 @@ static void run_test(int cgroup_fd) + + pthread_mutex_lock(&server_started_mtx); + if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread, +- (void *)&server_fd))) ++ (void *)&server_fd))) { ++ pthread_mutex_unlock(&server_started_mtx); + goto close_server_fd; ++ } + pthread_cond_wait(&server_started, &server_started_mtx); + pthread_mutex_unlock(&server_started_mtx); + +diff --git a/tools/testing/selftests/bpf/progs/xdp_tx.c b/tools/testing/selftests/bpf/progs/xdp_tx.c +index 94e6c2b281cb6..5f725c720e008 100644 +--- a/tools/testing/selftests/bpf/progs/xdp_tx.c ++++ b/tools/testing/selftests/bpf/progs/xdp_tx.c +@@ -3,7 +3,7 @@ + #include + #include + +-SEC("tx") ++SEC("xdp") + int xdp_tx(struct xdp_md *xdp) + { + return XDP_TX; +diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c +index abdfc41f7685a..4fd01450a4089 100644 +--- a/tools/testing/selftests/bpf/test_maps.c ++++ b/tools/testing/selftests/bpf/test_maps.c +@@ -985,7 +985,7 @@ static void test_sockmap(unsigned int tasks, void *data) + + FD_ZERO(&w); + FD_SET(sfd[3], &w); +- to.tv_sec = 1; ++ to.tv_sec = 30; + to.tv_usec = 0; + s = select(sfd[3] + 1, &w, NULL, NULL, &to); + if (s == -1) { +diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c +index 6f103106a39bb..bfbf2277b61a6 100644 +--- a/tools/testing/selftests/bpf/test_progs.c ++++ b/tools/testing/selftests/bpf/test_progs.c +@@ -148,18 +148,18 @@ void test__end_subtest() + struct prog_test_def *test = env.test; + int sub_error_cnt = test->error_cnt - test->old_error_cnt; + +- if (sub_error_cnt) +- env.fail_cnt++; +- else if (test->skip_cnt == 0) +- env.sub_succ_cnt++; +- skip_account(); +- + dump_test_log(test, sub_error_cnt); + + fprintf(env.stdout, "#%d/%d %s:%s\n", + test->test_num, test->subtest_num, test->subtest_name, + sub_error_cnt ? "FAIL" : (test->skip_cnt ? "SKIP" : "OK")); + ++ if (sub_error_cnt) ++ env.fail_cnt++; ++ else if (test->skip_cnt == 0) ++ env.sub_succ_cnt++; ++ skip_account(); ++ + free(test->subtest_name); + test->subtest_name = NULL; + } +@@ -786,17 +786,18 @@ int main(int argc, char **argv) + test__end_subtest(); + + test->tested = true; +- if (test->error_cnt) +- env.fail_cnt++; +- else +- env.succ_cnt++; +- skip_account(); + + dump_test_log(test, test->error_cnt); + + fprintf(env.stdout, "#%d %s:%s\n", + test->test_num, test->test_name, +- test->error_cnt ? "FAIL" : "OK"); ++ test->error_cnt ? "FAIL" : (test->skip_cnt ? "SKIP" : "OK")); ++ ++ if (test->error_cnt) ++ env.fail_cnt++; ++ else ++ env.succ_cnt++; ++ skip_account(); + + reset_affinity(); + restore_netns(); +diff --git a/tools/testing/selftests/bpf/test_xdp_veth.sh b/tools/testing/selftests/bpf/test_xdp_veth.sh +index ba8ffcdaac302..995278e684b6e 100755 +--- a/tools/testing/selftests/bpf/test_xdp_veth.sh ++++ b/tools/testing/selftests/bpf/test_xdp_veth.sh +@@ -108,7 +108,7 @@ ip link set dev veth2 xdp pinned $BPF_DIR/progs/redirect_map_1 + ip link set dev veth3 xdp pinned $BPF_DIR/progs/redirect_map_2 + + ip -n ns1 link set dev veth11 xdp obj xdp_dummy.o sec xdp_dummy +-ip -n ns2 link set dev veth22 xdp obj xdp_tx.o sec tx ++ip -n ns2 link set dev veth22 xdp obj xdp_tx.o sec xdp + ip -n ns3 link set dev veth33 xdp obj xdp_dummy.o sec xdp_dummy + + trap cleanup EXIT +diff --git a/tools/testing/selftests/firmware/fw_namespace.c b/tools/testing/selftests/firmware/fw_namespace.c +index 0e393cb5f42de..4c6f0cd83c5b0 100644 +--- a/tools/testing/selftests/firmware/fw_namespace.c ++++ b/tools/testing/selftests/firmware/fw_namespace.c +@@ -129,7 +129,8 @@ int main(int argc, char **argv) + die("mounting tmpfs to /lib/firmware failed\n"); + + sys_path = argv[1]; +- asprintf(&fw_path, "/lib/firmware/%s", fw_name); ++ if (asprintf(&fw_path, "/lib/firmware/%s", fw_name) < 0) ++ die("error: failed to build full fw_path\n"); + + setup_fw(fw_path); + +diff --git a/tools/testing/selftests/ftrace/test.d/functions b/tools/testing/selftests/ftrace/test.d/functions +index a6fac927ee82f..0cee6b067a374 100644 +--- a/tools/testing/selftests/ftrace/test.d/functions ++++ b/tools/testing/selftests/ftrace/test.d/functions +@@ -115,7 +115,7 @@ check_requires() { # Check required files and tracers + echo "Required tracer $t is not configured." + exit_unsupported + fi +- elif [ $r != $i ]; then ++ elif [ "$r" != "$i" ]; then + if ! grep -Fq "$r" README ; then + echo "Required feature pattern \"$r\" is not in README." + exit_unsupported +diff --git a/tools/testing/selftests/nci/nci_dev.c b/tools/testing/selftests/nci/nci_dev.c +index 57b505cb15618..acd4125ff39fe 100644 +--- a/tools/testing/selftests/nci/nci_dev.c ++++ b/tools/testing/selftests/nci/nci_dev.c +@@ -110,11 +110,11 @@ static int send_cmd_mt_nla(int sd, __u16 nlmsg_type, __u32 nlmsg_pid, + na->nla_type = nla_type[cnt]; + na->nla_len = nla_len[cnt] + NLA_HDRLEN; + +- if (nla_len > 0) ++ if (nla_len[cnt] > 0) + memcpy(NLA_DATA(na), nla_data[cnt], nla_len[cnt]); + +- msg.n.nlmsg_len += NLMSG_ALIGN(na->nla_len); +- prv_len = na->nla_len; ++ prv_len = NLA_ALIGN(nla_len[cnt]) + NLA_HDRLEN; ++ msg.n.nlmsg_len += prv_len; + } + + buf = (char *)&msg; +diff --git a/tools/thermal/tmon/Makefile b/tools/thermal/tmon/Makefile +index 9db867df76794..610334f86f631 100644 +--- a/tools/thermal/tmon/Makefile ++++ b/tools/thermal/tmon/Makefile +@@ -10,7 +10,7 @@ override CFLAGS+= $(call cc-option,-O3,-O1) ${WARNFLAGS} + # Add "-fstack-protector" only if toolchain supports it. + override CFLAGS+= $(call cc-option,-fstack-protector-strong) + CC?= $(CROSS_COMPILE)gcc +-PKG_CONFIG?= pkg-config ++PKG_CONFIG?= $(CROSS_COMPILE)pkg-config + + override CFLAGS+=-D VERSION=\"$(VERSION)\" + LDFLAGS+=