Gentoo Archives: gentoo-commits

From: "Mike Pagano (mpagano)" <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] linux-patches r2664 - genpatches-2.6/trunk/3.13
Date: Fri, 07 Feb 2014 14:36:00
Message-Id: 20140207143554.1F7B22004C@flycatcher.gentoo.org
1 Author: mpagano
2 Date: 2014-02-07 14:35:53 +0000 (Fri, 07 Feb 2014)
3 New Revision: 2664
4
5 Added:
6 genpatches-2.6/trunk/3.13/1001_linux-3.13.2.patch
7 Modified:
8 genpatches-2.6/trunk/3.13/0000_README
9 Log:
10 Linux patch 3.13.2
11
12 Modified: genpatches-2.6/trunk/3.13/0000_README
13 ===================================================================
14 --- genpatches-2.6/trunk/3.13/0000_README 2014-02-07 01:18:46 UTC (rev 2663)
15 +++ genpatches-2.6/trunk/3.13/0000_README 2014-02-07 14:35:53 UTC (rev 2664)
16 @@ -46,6 +46,10 @@
17 From: http://www.kernel.org
18 Desc: Linux 3.13.1
19
20 +Patch: 1001_linux-3.13.2.patch
21 +From: http://www.kernel.org
22 +Desc: Linux 3.13.2
23 +
24 Patch: 1500_XATTR_USER_PREFIX.patch
25 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
26 Desc: Support for namespace user.pax.* on tmpfs.
27
28 Added: genpatches-2.6/trunk/3.13/1001_linux-3.13.2.patch
29 ===================================================================
30 --- genpatches-2.6/trunk/3.13/1001_linux-3.13.2.patch (rev 0)
31 +++ genpatches-2.6/trunk/3.13/1001_linux-3.13.2.patch 2014-02-07 14:35:53 UTC (rev 2664)
32 @@ -0,0 +1,5805 @@
33 +diff --git a/Documentation/devicetree/bindings/ata/marvell.txt b/Documentation/devicetree/bindings/ata/marvell.txt
34 +index b5cdd20cde9c..1c8351604d38 100644
35 +--- a/Documentation/devicetree/bindings/ata/marvell.txt
36 ++++ b/Documentation/devicetree/bindings/ata/marvell.txt
37 +@@ -1,7 +1,7 @@
38 + * Marvell Orion SATA
39 +
40 + Required Properties:
41 +-- compatibility : "marvell,orion-sata"
42 ++- compatibility : "marvell,orion-sata" or "marvell,armada-370-sata"
43 + - reg : Address range of controller
44 + - interrupts : Interrupt controller is using
45 + - nr-ports : Number of SATA ports in use.
46 +diff --git a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt b/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
47 +index 82e8f6f17179..582b4652a82a 100644
48 +--- a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
49 ++++ b/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
50 +@@ -5,7 +5,11 @@ Required properties :
51 +
52 + - reg : Offset and length of the register set for the device
53 + - compatible : Should be "marvell,mv64xxx-i2c" or "allwinner,sun4i-i2c"
54 +- or "marvell,mv78230-i2c"
55 ++ or "marvell,mv78230-i2c" or "marvell,mv78230-a0-i2c"
56 ++ Note: Only use "marvell,mv78230-a0-i2c" for a very rare,
57 ++ initial version of the SoC which had broken offload
58 ++ support. Linux auto-detects this and sets it
59 ++ appropriately.
60 + - interrupts : The interrupt number
61 +
62 + Optional properties :
63 +diff --git a/Documentation/i2c/busses/i2c-piix4 b/Documentation/i2c/busses/i2c-piix4
64 +index c097e0f020fe..aa959fd22450 100644
65 +--- a/Documentation/i2c/busses/i2c-piix4
66 ++++ b/Documentation/i2c/busses/i2c-piix4
67 +@@ -13,7 +13,7 @@ Supported adapters:
68 + * AMD SP5100 (SB700 derivative found on some server mainboards)
69 + Datasheet: Publicly available at the AMD website
70 + http://support.amd.com/us/Embedded_TechDocs/44413.pdf
71 +- * AMD Hudson-2, CZ
72 ++ * AMD Hudson-2, ML, CZ
73 + Datasheet: Not publicly available
74 + * Standard Microsystems (SMSC) SLC90E66 (Victory66) southbridge
75 + Datasheet: Publicly available at the SMSC website http://www.smsc.com
76 +diff --git a/Makefile b/Makefile
77 +index de4cda986be2..a7fd5d9e752f 100644
78 +--- a/Makefile
79 ++++ b/Makefile
80 +@@ -1,6 +1,6 @@
81 + VERSION = 3
82 + PATCHLEVEL = 13
83 +-SUBLEVEL = 1
84 ++SUBLEVEL = 2
85 + EXTRAVERSION =
86 + NAME = One Giant Leap for Frogkind
87 +
88 +diff --git a/arch/alpha/lib/csum_partial_copy.c b/arch/alpha/lib/csum_partial_copy.c
89 +index ff3c10721caf..5675dca8dbb1 100644
90 +--- a/arch/alpha/lib/csum_partial_copy.c
91 ++++ b/arch/alpha/lib/csum_partial_copy.c
92 +@@ -378,6 +378,11 @@ csum_partial_copy_from_user(const void __user *src, void *dst, int len,
93 + __wsum
94 + csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
95 + {
96 +- return csum_partial_copy_from_user((__force const void __user *)src,
97 +- dst, len, sum, NULL);
98 ++ __wsum checksum;
99 ++ mm_segment_t oldfs = get_fs();
100 ++ set_fs(KERNEL_DS);
101 ++ checksum = csum_partial_copy_from_user((__force const void __user *)src,
102 ++ dst, len, sum, NULL);
103 ++ set_fs(oldfs);
104 ++ return checksum;
105 + }
106 +diff --git a/arch/arm/boot/dts/armada-370-xp.dtsi b/arch/arm/boot/dts/armada-370-xp.dtsi
107 +index 7f10f627ae5b..80ffacd128f8 100644
108 +--- a/arch/arm/boot/dts/armada-370-xp.dtsi
109 ++++ b/arch/arm/boot/dts/armada-370-xp.dtsi
110 +@@ -152,7 +152,7 @@
111 + };
112 +
113 + sata@a0000 {
114 +- compatible = "marvell,orion-sata";
115 ++ compatible = "marvell,armada-370-sata";
116 + reg = <0xa0000 0x5000>;
117 + interrupts = <55>;
118 + clocks = <&gateclk 15>, <&gateclk 30>;
119 +diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
120 +index c3e514837074..cf7de80377f1 100644
121 +--- a/arch/arm/boot/dts/at91sam9g45.dtsi
122 ++++ b/arch/arm/boot/dts/at91sam9g45.dtsi
123 +@@ -618,6 +618,7 @@
124 + compatible = "atmel,hsmci";
125 + reg = <0xfff80000 0x600>;
126 + interrupts = <11 IRQ_TYPE_LEVEL_HIGH 0>;
127 ++ pinctrl-names = "default";
128 + dmas = <&dma 1 AT91_DMA_CFG_PER_ID(0)>;
129 + dma-names = "rxtx";
130 + #address-cells = <1>;
131 +@@ -629,6 +630,7 @@
132 + compatible = "atmel,hsmci";
133 + reg = <0xfffd0000 0x600>;
134 + interrupts = <29 IRQ_TYPE_LEVEL_HIGH 0>;
135 ++ pinctrl-names = "default";
136 + dmas = <&dma 1 AT91_DMA_CFG_PER_ID(13)>;
137 + dma-names = "rxtx";
138 + #address-cells = <1>;
139 +diff --git a/arch/arm/mach-at91/sam9_smc.c b/arch/arm/mach-at91/sam9_smc.c
140 +index 99a0a1d2b7dc..b26156bf15db 100644
141 +--- a/arch/arm/mach-at91/sam9_smc.c
142 ++++ b/arch/arm/mach-at91/sam9_smc.c
143 +@@ -101,7 +101,7 @@ static void sam9_smc_cs_read(void __iomem *base,
144 + /* Pulse register */
145 + val = __raw_readl(base + AT91_SMC_PULSE);
146 +
147 +- config->nwe_setup = val & AT91_SMC_NWEPULSE;
148 ++ config->nwe_pulse = val & AT91_SMC_NWEPULSE;
149 + config->ncs_write_pulse = (val & AT91_SMC_NCS_WRPULSE) >> 8;
150 + config->nrd_pulse = (val & AT91_SMC_NRDPULSE) >> 16;
151 + config->ncs_read_pulse = (val & AT91_SMC_NCS_RDPULSE) >> 24;
152 +diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
153 +index 2d04f0e21870..878aebe98dcc 100644
154 +--- a/arch/arm/mach-mvebu/Makefile
155 ++++ b/arch/arm/mach-mvebu/Makefile
156 +@@ -3,7 +3,7 @@ ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \
157 +
158 + AFLAGS_coherency_ll.o := -Wa,-march=armv7-a
159 +
160 +-obj-y += system-controller.o
161 ++obj-y += system-controller.o mvebu-soc-id.o
162 + obj-$(CONFIG_MACH_ARMADA_370_XP) += armada-370-xp.o
163 + obj-$(CONFIG_ARCH_MVEBU) += coherency.o coherency_ll.o pmsu.o
164 + obj-$(CONFIG_SMP) += platsmp.o headsmp.o
165 +diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
166 +index e2acff98e750..f6c9d1d85c14 100644
167 +--- a/arch/arm/mach-mvebu/armada-370-xp.c
168 ++++ b/arch/arm/mach-mvebu/armada-370-xp.c
169 +@@ -21,6 +21,7 @@
170 + #include <linux/clocksource.h>
171 + #include <linux/dma-mapping.h>
172 + #include <linux/mbus.h>
173 ++#include <linux/slab.h>
174 + #include <asm/hardware/cache-l2x0.h>
175 + #include <asm/mach/arch.h>
176 + #include <asm/mach/map.h>
177 +@@ -28,6 +29,7 @@
178 + #include "armada-370-xp.h"
179 + #include "common.h"
180 + #include "coherency.h"
181 ++#include "mvebu-soc-id.h"
182 +
183 + static void __init armada_370_xp_map_io(void)
184 + {
185 +@@ -45,8 +47,38 @@ static void __init armada_370_xp_timer_and_clk_init(void)
186 + #endif
187 + }
188 +
189 ++static void __init i2c_quirk(void)
190 ++{
191 ++ struct device_node *np;
192 ++ u32 dev, rev;
193 ++
194 ++ /*
195 ++ * Only revisons more recent than A0 support the offload
196 ++ * mechanism. We can exit only if we are sure that we can
197 ++ * get the SoC revision and it is more recent than A0.
198 ++ */
199 ++ if (mvebu_get_soc_id(&rev, &dev) == 0 && dev > MV78XX0_A0_REV)
200 ++ return;
201 ++
202 ++ for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") {
203 ++ struct property *new_compat;
204 ++
205 ++ new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
206 ++
207 ++ new_compat->name = kstrdup("compatible", GFP_KERNEL);
208 ++ new_compat->length = sizeof("marvell,mv78230-a0-i2c");
209 ++ new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
210 ++ GFP_KERNEL);
211 ++
212 ++ of_update_property(np, new_compat);
213 ++ }
214 ++ return;
215 ++}
216 ++
217 + static void __init armada_370_xp_dt_init(void)
218 + {
219 ++ if (of_machine_is_compatible("plathome,openblocks-ax3-4"))
220 ++ i2c_quirk();
221 + of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
222 + }
223 +
224 +diff --git a/arch/arm/mach-mvebu/mvebu-soc-id.c b/arch/arm/mach-mvebu/mvebu-soc-id.c
225 +new file mode 100644
226 +index 000000000000..fe4fc1cbdfaf
227 +--- /dev/null
228 ++++ b/arch/arm/mach-mvebu/mvebu-soc-id.c
229 +@@ -0,0 +1,119 @@
230 ++/*
231 ++ * ID and revision information for mvebu SoCs
232 ++ *
233 ++ * Copyright (C) 2014 Marvell
234 ++ *
235 ++ * Gregory CLEMENT <gregory.clement@××××××××××××××.com>
236 ++ *
237 ++ * This file is licensed under the terms of the GNU General Public
238 ++ * License version 2. This program is licensed "as is" without any
239 ++ * warranty of any kind, whether express or implied.
240 ++ *
241 ++ * All the mvebu SoCs have information related to their variant and
242 ++ * revision that can be read from the PCI control register. This is
243 ++ * done before the PCI initialization to avoid any conflict. Once the
244 ++ * ID and revision are retrieved, the mapping is freed.
245 ++ */
246 ++
247 ++#define pr_fmt(fmt) "mvebu-soc-id: " fmt
248 ++
249 ++#include <linux/clk.h>
250 ++#include <linux/init.h>
251 ++#include <linux/io.h>
252 ++#include <linux/kernel.h>
253 ++#include <linux/of.h>
254 ++#include <linux/of_address.h>
255 ++#include "mvebu-soc-id.h"
256 ++
257 ++#define PCIE_DEV_ID_OFF 0x0
258 ++#define PCIE_DEV_REV_OFF 0x8
259 ++
260 ++#define SOC_ID_MASK 0xFFFF0000
261 ++#define SOC_REV_MASK 0xFF
262 ++
263 ++static u32 soc_dev_id;
264 ++static u32 soc_rev;
265 ++static bool is_id_valid;
266 ++
267 ++static const struct of_device_id mvebu_pcie_of_match_table[] = {
268 ++ { .compatible = "marvell,armada-xp-pcie", },
269 ++ { .compatible = "marvell,armada-370-pcie", },
270 ++ {},
271 ++};
272 ++
273 ++int mvebu_get_soc_id(u32 *dev, u32 *rev)
274 ++{
275 ++ if (is_id_valid) {
276 ++ *dev = soc_dev_id;
277 ++ *rev = soc_rev;
278 ++ return 0;
279 ++ } else
280 ++ return -1;
281 ++}
282 ++
283 ++static int __init mvebu_soc_id_init(void)
284 ++{
285 ++ struct device_node *np;
286 ++ int ret = 0;
287 ++ void __iomem *pci_base;
288 ++ struct clk *clk;
289 ++ struct device_node *child;
290 ++
291 ++ np = of_find_matching_node(NULL, mvebu_pcie_of_match_table);
292 ++ if (!np)
293 ++ return ret;
294 ++
295 ++ /*
296 ++ * ID and revision are available from any port, so we
297 ++ * just pick the first one
298 ++ */
299 ++ child = of_get_next_child(np, NULL);
300 ++ if (child == NULL) {
301 ++ pr_err("cannot get pci node\n");
302 ++ ret = -ENOMEM;
303 ++ goto clk_err;
304 ++ }
305 ++
306 ++ clk = of_clk_get_by_name(child, NULL);
307 ++ if (IS_ERR(clk)) {
308 ++ pr_err("cannot get clock\n");
309 ++ ret = -ENOMEM;
310 ++ goto clk_err;
311 ++ }
312 ++
313 ++ ret = clk_prepare_enable(clk);
314 ++ if (ret) {
315 ++ pr_err("cannot enable clock\n");
316 ++ goto clk_err;
317 ++ }
318 ++
319 ++ pci_base = of_iomap(child, 0);
320 ++ if (IS_ERR(pci_base)) {
321 ++ pr_err("cannot map registers\n");
322 ++ ret = -ENOMEM;
323 ++ goto res_ioremap;
324 ++ }
325 ++
326 ++ /* SoC ID */
327 ++ soc_dev_id = readl(pci_base + PCIE_DEV_ID_OFF) >> 16;
328 ++
329 ++ /* SoC revision */
330 ++ soc_rev = readl(pci_base + PCIE_DEV_REV_OFF) & SOC_REV_MASK;
331 ++
332 ++ is_id_valid = true;
333 ++
334 ++ pr_info("MVEBU SoC ID=0x%X, Rev=0x%X\n", soc_dev_id, soc_rev);
335 ++
336 ++ iounmap(pci_base);
337 ++
338 ++res_ioremap:
339 ++ clk_disable_unprepare(clk);
340 ++
341 ++clk_err:
342 ++ of_node_put(child);
343 ++ of_node_put(np);
344 ++
345 ++ return ret;
346 ++}
347 ++core_initcall(mvebu_soc_id_init);
348 ++
349 +diff --git a/arch/arm/mach-mvebu/mvebu-soc-id.h b/arch/arm/mach-mvebu/mvebu-soc-id.h
350 +new file mode 100644
351 +index 000000000000..31654252fe35
352 +--- /dev/null
353 ++++ b/arch/arm/mach-mvebu/mvebu-soc-id.h
354 +@@ -0,0 +1,32 @@
355 ++/*
356 ++ * Marvell EBU SoC ID and revision definitions.
357 ++ *
358 ++ * Copyright (C) 2014 Marvell Semiconductor
359 ++ *
360 ++ * This file is licensed under the terms of the GNU General Public
361 ++ * License version 2. This program is licensed "as is" without any
362 ++ * warranty of any kind, whether express or implied.
363 ++ */
364 ++
365 ++#ifndef __LINUX_MVEBU_SOC_ID_H
366 ++#define __LINUX_MVEBU_SOC_ID_H
367 ++
368 ++/* Armada XP ID */
369 ++#define MV78230_DEV_ID 0x7823
370 ++#define MV78260_DEV_ID 0x7826
371 ++#define MV78460_DEV_ID 0x7846
372 ++
373 ++/* Armada XP Revision */
374 ++#define MV78XX0_A0_REV 0x1
375 ++#define MV78XX0_B0_REV 0x2
376 ++
377 ++#ifdef CONFIG_ARCH_MVEBU
378 ++int mvebu_get_soc_id(u32 *dev, u32 *rev);
379 ++#else
380 ++static inline int mvebu_get_soc_id(u32 *dev, u32 *rev)
381 ++{
382 ++ return -1;
383 ++}
384 ++#endif
385 ++
386 ++#endif /* __LINUX_MVEBU_SOC_ID_H */
387 +diff --git a/arch/parisc/include/asm/cacheflush.h b/arch/parisc/include/asm/cacheflush.h
388 +index 2f9b751878ba..de65f66ea64e 100644
389 +--- a/arch/parisc/include/asm/cacheflush.h
390 ++++ b/arch/parisc/include/asm/cacheflush.h
391 +@@ -132,7 +132,6 @@ void mark_rodata_ro(void);
392 + static inline void *kmap(struct page *page)
393 + {
394 + might_sleep();
395 +- flush_dcache_page(page);
396 + return page_address(page);
397 + }
398 +
399 +@@ -144,7 +143,6 @@ static inline void kunmap(struct page *page)
400 + static inline void *kmap_atomic(struct page *page)
401 + {
402 + pagefault_disable();
403 +- flush_dcache_page(page);
404 + return page_address(page);
405 + }
406 +
407 +diff --git a/arch/parisc/include/asm/page.h b/arch/parisc/include/asm/page.h
408 +index c53fc63149e8..637fe031aa84 100644
409 +--- a/arch/parisc/include/asm/page.h
410 ++++ b/arch/parisc/include/asm/page.h
411 +@@ -29,7 +29,8 @@ struct page;
412 + void clear_page_asm(void *page);
413 + void copy_page_asm(void *to, void *from);
414 + #define clear_user_page(vto, vaddr, page) clear_page_asm(vto)
415 +-#define copy_user_page(vto, vfrom, vaddr, page) copy_page_asm(vto, vfrom)
416 ++void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
417 ++ struct page *pg);
418 +
419 + /* #define CONFIG_PARISC_TMPALIAS */
420 +
421 +diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
422 +index a72545554a31..ac87a40502e6 100644
423 +--- a/arch/parisc/kernel/cache.c
424 ++++ b/arch/parisc/kernel/cache.c
425 +@@ -388,6 +388,20 @@ void flush_kernel_dcache_page_addr(void *addr)
426 + }
427 + EXPORT_SYMBOL(flush_kernel_dcache_page_addr);
428 +
429 ++void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
430 ++ struct page *pg)
431 ++{
432 ++ /* Copy using kernel mapping. No coherency is needed (all in
433 ++ kunmap) for the `to' page. However, the `from' page needs to
434 ++ be flushed through a mapping equivalent to the user mapping
435 ++ before it can be accessed through the kernel mapping. */
436 ++ preempt_disable();
437 ++ flush_dcache_page_asm(__pa(vfrom), vaddr);
438 ++ preempt_enable();
439 ++ copy_page_asm(vto, vfrom);
440 ++}
441 ++EXPORT_SYMBOL(copy_user_page);
442 ++
443 + void purge_tlb_entries(struct mm_struct *mm, unsigned long addr)
444 + {
445 + unsigned long flags;
446 +diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
447 +index 89e3ef2496ac..d0b5fca6b077 100644
448 +--- a/arch/powerpc/include/asm/topology.h
449 ++++ b/arch/powerpc/include/asm/topology.h
450 +@@ -22,7 +22,15 @@ struct device_node;
451 +
452 + static inline int cpu_to_node(int cpu)
453 + {
454 +- return numa_cpu_lookup_table[cpu];
455 ++ int nid;
456 ++
457 ++ nid = numa_cpu_lookup_table[cpu];
458 ++
459 ++ /*
460 ++ * During early boot, the numa-cpu lookup table might not have been
461 ++ * setup for all CPUs yet. In such cases, default to node 0.
462 ++ */
463 ++ return (nid < 0) ? 0 : nid;
464 + }
465 +
466 + #define parent_node(node) (node)
467 +diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
468 +index 654932727873..bfb82365bc7a 100644
469 +--- a/arch/powerpc/kernel/cacheinfo.c
470 ++++ b/arch/powerpc/kernel/cacheinfo.c
471 +@@ -794,6 +794,9 @@ static void remove_cache_dir(struct cache_dir *cache_dir)
472 + {
473 + remove_index_dirs(cache_dir);
474 +
475 ++ /* Remove cache dir from sysfs */
476 ++ kobject_del(cache_dir->kobj);
477 ++
478 + kobject_put(cache_dir->kobj);
479 +
480 + kfree(cache_dir);
481 +diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
482 +index b51d5db78068..edeac10a5c3b 100644
483 +--- a/arch/powerpc/kvm/book3s_hv.c
484 ++++ b/arch/powerpc/kvm/book3s_hv.c
485 +@@ -85,10 +85,13 @@ static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
486 +
487 + /* CPU points to the first thread of the core */
488 + if (cpu != me && cpu >= 0 && cpu < nr_cpu_ids) {
489 ++#ifdef CONFIG_KVM_XICS
490 + int real_cpu = cpu + vcpu->arch.ptid;
491 + if (paca[real_cpu].kvm_hstate.xics_phys)
492 + xics_wake_cpu(real_cpu);
493 +- else if (cpu_online(cpu))
494 ++ else
495 ++#endif
496 ++ if (cpu_online(cpu))
497 + smp_send_reschedule(cpu);
498 + }
499 + put_cpu();
500 +@@ -1189,7 +1192,9 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu)
501 + smp_wmb();
502 + #if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP)
503 + if (vcpu->arch.ptid) {
504 ++#ifdef CONFIG_KVM_XICS
505 + xics_wake_cpu(cpu);
506 ++#endif
507 + ++vc->n_woken;
508 + }
509 + #endif
510 +diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
511 +index ebca6b88ea5e..50860e919cb8 100644
512 +--- a/arch/powerpc/kvm/e500_mmu.c
513 ++++ b/arch/powerpc/kvm/e500_mmu.c
514 +@@ -127,7 +127,7 @@ static int kvmppc_e500_tlb_index(struct kvmppc_vcpu_e500 *vcpu_e500,
515 + }
516 +
517 + static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu,
518 +- unsigned int eaddr, int as)
519 ++ gva_t eaddr, int as)
520 + {
521 + struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
522 + unsigned int victim, tsized;
523 +diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
524 +index 078d3e00a616..6847d509162f 100644
525 +--- a/arch/powerpc/mm/numa.c
526 ++++ b/arch/powerpc/mm/numa.c
527 +@@ -31,6 +31,8 @@
528 + #include <asm/sparsemem.h>
529 + #include <asm/prom.h>
530 + #include <asm/smp.h>
531 ++#include <asm/cputhreads.h>
532 ++#include <asm/topology.h>
533 + #include <asm/firmware.h>
534 + #include <asm/paca.h>
535 + #include <asm/hvcall.h>
536 +@@ -152,9 +154,22 @@ static void __init get_node_active_region(unsigned long pfn,
537 + }
538 + }
539 +
540 +-static void map_cpu_to_node(int cpu, int node)
541 ++static void reset_numa_cpu_lookup_table(void)
542 ++{
543 ++ unsigned int cpu;
544 ++
545 ++ for_each_possible_cpu(cpu)
546 ++ numa_cpu_lookup_table[cpu] = -1;
547 ++}
548 ++
549 ++static void update_numa_cpu_lookup_table(unsigned int cpu, int node)
550 + {
551 + numa_cpu_lookup_table[cpu] = node;
552 ++}
553 ++
554 ++static void map_cpu_to_node(int cpu, int node)
555 ++{
556 ++ update_numa_cpu_lookup_table(cpu, node);
557 +
558 + dbg("adding cpu %d to node %d\n", cpu, node);
559 +
560 +@@ -522,11 +537,24 @@ static int of_drconf_to_nid_single(struct of_drconf_cell *drmem,
561 + */
562 + static int numa_setup_cpu(unsigned long lcpu)
563 + {
564 +- int nid = 0;
565 +- struct device_node *cpu = of_get_cpu_node(lcpu, NULL);
566 ++ int nid;
567 ++ struct device_node *cpu;
568 ++
569 ++ /*
570 ++ * If a valid cpu-to-node mapping is already available, use it
571 ++ * directly instead of querying the firmware, since it represents
572 ++ * the most recent mapping notified to us by the platform (eg: VPHN).
573 ++ */
574 ++ if ((nid = numa_cpu_lookup_table[lcpu]) >= 0) {
575 ++ map_cpu_to_node(lcpu, nid);
576 ++ return nid;
577 ++ }
578 ++
579 ++ cpu = of_get_cpu_node(lcpu, NULL);
580 +
581 + if (!cpu) {
582 + WARN_ON(1);
583 ++ nid = 0;
584 + goto out;
585 + }
586 +
587 +@@ -1067,6 +1095,7 @@ void __init do_init_bootmem(void)
588 + */
589 + setup_node_to_cpumask_map();
590 +
591 ++ reset_numa_cpu_lookup_table();
592 + register_cpu_notifier(&ppc64_numa_nb);
593 + cpu_numa_callback(&ppc64_numa_nb, CPU_UP_PREPARE,
594 + (void *)(unsigned long)boot_cpuid);
595 +@@ -1445,6 +1474,33 @@ static int update_cpu_topology(void *data)
596 + return 0;
597 + }
598 +
599 ++static int update_lookup_table(void *data)
600 ++{
601 ++ struct topology_update_data *update;
602 ++
603 ++ if (!data)
604 ++ return -EINVAL;
605 ++
606 ++ /*
607 ++ * Upon topology update, the numa-cpu lookup table needs to be updated
608 ++ * for all threads in the core, including offline CPUs, to ensure that
609 ++ * future hotplug operations respect the cpu-to-node associativity
610 ++ * properly.
611 ++ */
612 ++ for (update = data; update; update = update->next) {
613 ++ int nid, base, j;
614 ++
615 ++ nid = update->new_nid;
616 ++ base = cpu_first_thread_sibling(update->cpu);
617 ++
618 ++ for (j = 0; j < threads_per_core; j++) {
619 ++ update_numa_cpu_lookup_table(base + j, nid);
620 ++ }
621 ++ }
622 ++
623 ++ return 0;
624 ++}
625 ++
626 + /*
627 + * Update the node maps and sysfs entries for each cpu whose home node
628 + * has changed. Returns 1 when the topology has changed, and 0 otherwise.
629 +@@ -1513,6 +1569,14 @@ int arch_update_cpu_topology(void)
630 +
631 + stop_machine(update_cpu_topology, &updates[0], &updated_cpus);
632 +
633 ++ /*
634 ++ * Update the numa-cpu lookup table with the new mappings, even for
635 ++ * offline CPUs. It is best to perform this update from the stop-
636 ++ * machine context.
637 ++ */
638 ++ stop_machine(update_lookup_table, &updates[0],
639 ++ cpumask_of(raw_smp_processor_id()));
640 ++
641 + for (ud = &updates[0]; ud; ud = ud->next) {
642 + unregister_cpu_under_node(ud->cpu, ud->old_nid);
643 + register_cpu_under_node(ud->cpu, ud->new_nid);
644 +diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
645 +index 4bf9da03591e..5d7e8cf83bd6 100644
646 +--- a/arch/s390/include/asm/compat.h
647 ++++ b/arch/s390/include/asm/compat.h
648 +@@ -38,7 +38,8 @@
649 +
650 + #define PSW32_USER_BITS (PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT | \
651 + PSW32_DEFAULT_KEY | PSW32_MASK_BASE | \
652 +- PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | PSW32_ASC_HOME)
653 ++ PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \
654 ++ PSW32_ASC_PRIMARY)
655 +
656 + #define COMPAT_USER_HZ 100
657 + #define COMPAT_UTS_MACHINE "s390\0\0\0\0"
658 +diff --git a/arch/s390/include/uapi/asm/statfs.h b/arch/s390/include/uapi/asm/statfs.h
659 +index a61d538756f2..471eb09184d4 100644
660 +--- a/arch/s390/include/uapi/asm/statfs.h
661 ++++ b/arch/s390/include/uapi/asm/statfs.h
662 +@@ -35,11 +35,11 @@ struct statfs {
663 + struct statfs64 {
664 + unsigned int f_type;
665 + unsigned int f_bsize;
666 +- unsigned long f_blocks;
667 +- unsigned long f_bfree;
668 +- unsigned long f_bavail;
669 +- unsigned long f_files;
670 +- unsigned long f_ffree;
671 ++ unsigned long long f_blocks;
672 ++ unsigned long long f_bfree;
673 ++ unsigned long long f_bavail;
674 ++ unsigned long long f_files;
675 ++ unsigned long long f_ffree;
676 + __kernel_fsid_t f_fsid;
677 + unsigned int f_namelen;
678 + unsigned int f_frsize;
679 +diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
680 +index 78d967f180f4..8216c0e0b2e2 100644
681 +--- a/arch/s390/kvm/diag.c
682 ++++ b/arch/s390/kvm/diag.c
683 +@@ -121,7 +121,7 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu)
684 + * - gpr 4 contains the index on the bus (optionally)
685 + */
686 + ret = kvm_io_bus_write_cookie(vcpu->kvm, KVM_VIRTIO_CCW_NOTIFY_BUS,
687 +- vcpu->run->s.regs.gprs[2],
688 ++ vcpu->run->s.regs.gprs[2] & 0xffffffff,
689 + 8, &vcpu->run->s.regs.gprs[3],
690 + vcpu->run->s.regs.gprs[4]);
691 +
692 +@@ -137,7 +137,7 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu)
693 +
694 + int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
695 + {
696 +- int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
697 ++ int code = kvm_s390_get_base_disp_rs(vcpu) & 0xffff;
698 +
699 + if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
700 + return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
701 +diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
702 +index 569494e01ec6..bb383df32400 100644
703 +--- a/arch/s390/kvm/kvm-s390.c
704 ++++ b/arch/s390/kvm/kvm-s390.c
705 +@@ -885,7 +885,7 @@ static int __guestcopy(struct kvm_vcpu *vcpu, u64 guestdest, void *from,
706 + * KVM_S390_STORE_STATUS_NOADDR: -> 0x1200 on 64 bit
707 + * KVM_S390_STORE_STATUS_PREFIXED: -> prefix
708 + */
709 +-int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr)
710 ++int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr)
711 + {
712 + unsigned char archmode = 1;
713 + int prefix;
714 +@@ -903,15 +903,6 @@ int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr)
715 + } else
716 + prefix = 0;
717 +
718 +- /*
719 +- * The guest FPRS and ACRS are in the host FPRS/ACRS due to the lazy
720 +- * copying in vcpu load/put. Lets update our copies before we save
721 +- * it into the save area
722 +- */
723 +- save_fp_ctl(&vcpu->arch.guest_fpregs.fpc);
724 +- save_fp_regs(vcpu->arch.guest_fpregs.fprs);
725 +- save_access_regs(vcpu->run->s.regs.acrs);
726 +-
727 + if (__guestcopy(vcpu, addr + offsetof(struct save_area, fp_regs),
728 + vcpu->arch.guest_fpregs.fprs, 128, prefix))
729 + return -EFAULT;
730 +@@ -956,6 +947,20 @@ int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr)
731 + return 0;
732 + }
733 +
734 ++int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr)
735 ++{
736 ++ /*
737 ++ * The guest FPRS and ACRS are in the host FPRS/ACRS due to the lazy
738 ++ * copying in vcpu load/put. Lets update our copies before we save
739 ++ * it into the save area
740 ++ */
741 ++ save_fp_ctl(&vcpu->arch.guest_fpregs.fpc);
742 ++ save_fp_regs(vcpu->arch.guest_fpregs.fprs);
743 ++ save_access_regs(vcpu->run->s.regs.acrs);
744 ++
745 ++ return kvm_s390_store_status_unloaded(vcpu, addr);
746 ++}
747 ++
748 + static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
749 + struct kvm_enable_cap *cap)
750 + {
751 +diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
752 +index b44912a32949..72c1391bd25a 100644
753 +--- a/arch/s390/kvm/kvm-s390.h
754 ++++ b/arch/s390/kvm/kvm-s390.h
755 +@@ -150,8 +150,8 @@ int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
756 + int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
757 +
758 + /* implemented in kvm-s390.c */
759 +-int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu,
760 +- unsigned long addr);
761 ++int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
762 ++int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
763 + void s390_vcpu_block(struct kvm_vcpu *vcpu);
764 + void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
765 + void exit_sie(struct kvm_vcpu *vcpu);
766 +diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c
767 +index bec398c57acf..6805601262e0 100644
768 +--- a/arch/s390/kvm/sigp.c
769 ++++ b/arch/s390/kvm/sigp.c
770 +@@ -130,6 +130,7 @@ unlock:
771 + static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action)
772 + {
773 + struct kvm_s390_interrupt_info *inti;
774 ++ int rc = SIGP_CC_ORDER_CODE_ACCEPTED;
775 +
776 + inti = kzalloc(sizeof(*inti), GFP_ATOMIC);
777 + if (!inti)
778 +@@ -139,6 +140,8 @@ static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action)
779 + spin_lock_bh(&li->lock);
780 + if ((atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) {
781 + kfree(inti);
782 ++ if ((action & ACTION_STORE_ON_STOP) != 0)
783 ++ rc = -ESHUTDOWN;
784 + goto out;
785 + }
786 + list_add_tail(&inti->list, &li->list);
787 +@@ -150,7 +153,7 @@ static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action)
788 + out:
789 + spin_unlock_bh(&li->lock);
790 +
791 +- return SIGP_CC_ORDER_CODE_ACCEPTED;
792 ++ return rc;
793 + }
794 +
795 + static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int action)
796 +@@ -174,6 +177,16 @@ static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int action)
797 + unlock:
798 + spin_unlock(&fi->lock);
799 + VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr);
800 ++
801 ++ if ((action & ACTION_STORE_ON_STOP) != 0 && rc == -ESHUTDOWN) {
802 ++ /* If the CPU has already been stopped, we still have
803 ++ * to save the status when doing stop-and-store. This
804 ++ * has to be done after unlocking all spinlocks. */
805 ++ struct kvm_vcpu *dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
806 ++ rc = kvm_s390_store_status_unloaded(dst_vcpu,
807 ++ KVM_S390_STORE_STATUS_NOADDR);
808 ++ }
809 ++
810 + return rc;
811 + }
812 +
813 +diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
814 +index 1df115909758..c7678e43465b 100644
815 +--- a/arch/x86/include/asm/kvm_para.h
816 ++++ b/arch/x86/include/asm/kvm_para.h
817 +@@ -85,28 +85,9 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
818 + return ret;
819 + }
820 +
821 +-static inline uint32_t kvm_cpuid_base(void)
822 +-{
823 +- if (boot_cpu_data.cpuid_level < 0)
824 +- return 0; /* So we don't blow up on old processors */
825 +-
826 +- if (cpu_has_hypervisor)
827 +- return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0);
828 +-
829 +- return 0;
830 +-}
831 +-
832 +-static inline bool kvm_para_available(void)
833 +-{
834 +- return kvm_cpuid_base() != 0;
835 +-}
836 +-
837 +-static inline unsigned int kvm_arch_para_features(void)
838 +-{
839 +- return cpuid_eax(KVM_CPUID_FEATURES);
840 +-}
841 +-
842 + #ifdef CONFIG_KVM_GUEST
843 ++bool kvm_para_available(void);
844 ++unsigned int kvm_arch_para_features(void);
845 + void __init kvm_guest_init(void);
846 + void kvm_async_pf_task_wait(u32 token);
847 + void kvm_async_pf_task_wake(u32 token);
848 +@@ -126,6 +107,16 @@ static inline void kvm_spinlock_init(void)
849 + #define kvm_async_pf_task_wait(T) do {} while(0)
850 + #define kvm_async_pf_task_wake(T) do {} while(0)
851 +
852 ++static inline bool kvm_para_available(void)
853 ++{
854 ++ return 0;
855 ++}
856 ++
857 ++static inline unsigned int kvm_arch_para_features(void)
858 ++{
859 ++ return 0;
860 ++}
861 ++
862 + static inline u32 kvm_read_and_reset_pf_reason(void)
863 + {
864 + return 0;
865 +diff --git a/arch/x86/include/uapi/asm/msr-index.h b/arch/x86/include/uapi/asm/msr-index.h
866 +index 37813b5ddc37..59cea185ad1d 100644
867 +--- a/arch/x86/include/uapi/asm/msr-index.h
868 ++++ b/arch/x86/include/uapi/asm/msr-index.h
869 +@@ -184,6 +184,7 @@
870 + #define MSR_AMD64_PATCH_LOADER 0xc0010020
871 + #define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140
872 + #define MSR_AMD64_OSVW_STATUS 0xc0010141
873 ++#define MSR_AMD64_LS_CFG 0xc0011020
874 + #define MSR_AMD64_DC_CFG 0xc0011022
875 + #define MSR_AMD64_BU_CFG2 0xc001102a
876 + #define MSR_AMD64_IBSFETCHCTL 0xc0011030
877 +diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
878 +index bca023bdd6b2..59bfebc8c805 100644
879 +--- a/arch/x86/kernel/cpu/amd.c
880 ++++ b/arch/x86/kernel/cpu/amd.c
881 +@@ -508,6 +508,16 @@ static void early_init_amd(struct cpuinfo_x86 *c)
882 + set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
883 + }
884 + #endif
885 ++
886 ++ /* F16h erratum 793, CVE-2013-6885 */
887 ++ if (c->x86 == 0x16 && c->x86_model <= 0xf) {
888 ++ u64 val;
889 ++
890 ++ rdmsrl(MSR_AMD64_LS_CFG, val);
891 ++ if (!(val & BIT(15)))
892 ++ wrmsrl(MSR_AMD64_LS_CFG, val | BIT(15));
893 ++ }
894 ++
895 + }
896 +
897 + static const int amd_erratum_383[];
898 +diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
899 +index 6dd802c6d780..f81cadebcc0e 100644
900 +--- a/arch/x86/kernel/kvm.c
901 ++++ b/arch/x86/kernel/kvm.c
902 +@@ -500,6 +500,38 @@ void __init kvm_guest_init(void)
903 + #endif
904 + }
905 +
906 ++static noinline uint32_t __kvm_cpuid_base(void)
907 ++{
908 ++ if (boot_cpu_data.cpuid_level < 0)
909 ++ return 0; /* So we don't blow up on old processors */
910 ++
911 ++ if (cpu_has_hypervisor)
912 ++ return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0);
913 ++
914 ++ return 0;
915 ++}
916 ++
917 ++static inline uint32_t kvm_cpuid_base(void)
918 ++{
919 ++ static int kvm_cpuid_base = -1;
920 ++
921 ++ if (kvm_cpuid_base == -1)
922 ++ kvm_cpuid_base = __kvm_cpuid_base();
923 ++
924 ++ return kvm_cpuid_base;
925 ++}
926 ++
927 ++bool kvm_para_available(void)
928 ++{
929 ++ return kvm_cpuid_base() != 0;
930 ++}
931 ++EXPORT_SYMBOL_GPL(kvm_para_available);
932 ++
933 ++unsigned int kvm_arch_para_features(void)
934 ++{
935 ++ return cpuid_eax(kvm_cpuid_base() | KVM_CPUID_FEATURES);
936 ++}
937 ++
938 + static uint32_t __init kvm_detect(void)
939 + {
940 + return kvm_cpuid_base();
941 +diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
942 +index 412a5aa0ef94..518d86471b76 100644
943 +--- a/arch/x86/kvm/i8254.c
944 ++++ b/arch/x86/kvm/i8254.c
945 +@@ -37,6 +37,7 @@
946 +
947 + #include "irq.h"
948 + #include "i8254.h"
949 ++#include "x86.h"
950 +
951 + #ifndef CONFIG_X86_64
952 + #define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
953 +@@ -349,6 +350,23 @@ static void create_pit_timer(struct kvm *kvm, u32 val, int is_period)
954 + atomic_set(&ps->pending, 0);
955 + ps->irq_ack = 1;
956 +
957 ++ /*
958 ++ * Do not allow the guest to program periodic timers with small
959 ++ * interval, since the hrtimers are not throttled by the host
960 ++ * scheduler.
961 ++ */
962 ++ if (ps->is_periodic) {
963 ++ s64 min_period = min_timer_period_us * 1000LL;
964 ++
965 ++ if (ps->period < min_period) {
966 ++ pr_info_ratelimited(
967 ++ "kvm: requested %lld ns "
968 ++ "i8254 timer period limited to %lld ns\n",
969 ++ ps->period, min_period);
970 ++ ps->period = min_period;
971 ++ }
972 ++ }
973 ++
974 + hrtimer_start(&ps->timer, ktime_add_ns(ktime_get(), interval),
975 + HRTIMER_MODE_ABS);
976 + }
977 +diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
978 +index 775702f649ca..d86ff15fc89f 100644
979 +--- a/arch/x86/kvm/lapic.c
980 ++++ b/arch/x86/kvm/lapic.c
981 +@@ -71,9 +71,6 @@
982 + #define VEC_POS(v) ((v) & (32 - 1))
983 + #define REG_POS(v) (((v) >> 5) << 4)
984 +
985 +-static unsigned int min_timer_period_us = 500;
986 +-module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
987 +-
988 + static inline void apic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
989 + {
990 + *((u32 *) (apic->regs + reg_off)) = val;
991 +diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
992 +index 5d004da1e35d..d89d51b3abf6 100644
993 +--- a/arch/x86/kvm/x86.c
994 ++++ b/arch/x86/kvm/x86.c
995 +@@ -94,6 +94,9 @@ EXPORT_SYMBOL_GPL(kvm_x86_ops);
996 + static bool ignore_msrs = 0;
997 + module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR);
998 +
999 ++unsigned int min_timer_period_us = 500;
1000 ++module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
1001 ++
1002 + bool kvm_has_tsc_control;
1003 + EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
1004 + u32 kvm_max_guest_tsc_khz;
1005 +diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
1006 +index 587fb9ede436..8da5823bcde6 100644
1007 +--- a/arch/x86/kvm/x86.h
1008 ++++ b/arch/x86/kvm/x86.h
1009 +@@ -125,5 +125,7 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
1010 + #define KVM_SUPPORTED_XCR0 (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
1011 + extern u64 host_xcr0;
1012 +
1013 ++extern unsigned int min_timer_period_us;
1014 ++
1015 + extern struct static_key kvm_no_apic_vcpu;
1016 + #endif
1017 +diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
1018 +index cceb813044ef..30075f91040c 100644
1019 +--- a/arch/x86/platform/efi/efi.c
1020 ++++ b/arch/x86/platform/efi/efi.c
1021 +@@ -436,7 +436,7 @@ void __init efi_reserve_boot_services(void)
1022 + * - Not within any part of the kernel
1023 + * - Not the bios reserved area
1024 + */
1025 +- if ((start+size >= __pa_symbol(_text)
1026 ++ if ((start + size > __pa_symbol(_text)
1027 + && start <= __pa_symbol(_end)) ||
1028 + !e820_all_mapped(start, start+size, E820_RAM) ||
1029 + memblock_is_region_reserved(start, size)) {
1030 +diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
1031 +index 1393a5890ed5..1a3dbd1b196e 100644
1032 +--- a/drivers/ata/libata-core.c
1033 ++++ b/drivers/ata/libata-core.c
1034 +@@ -2222,6 +2222,16 @@ int ata_dev_configure(struct ata_device *dev)
1035 + if (rc)
1036 + return rc;
1037 +
1038 ++ /* some WD SATA-1 drives have issues with LPM, turn on NOLPM for them */
1039 ++ if ((dev->horkage & ATA_HORKAGE_WD_BROKEN_LPM) &&
1040 ++ (id[ATA_ID_SATA_CAPABILITY] & 0xe) == 0x2)
1041 ++ dev->horkage |= ATA_HORKAGE_NOLPM;
1042 ++
1043 ++ if (dev->horkage & ATA_HORKAGE_NOLPM) {
1044 ++ ata_dev_warn(dev, "LPM support broken, forcing max_power\n");
1045 ++ dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER;
1046 ++ }
1047 ++
1048 + /* let ACPI work its magic */
1049 + rc = ata_acpi_on_devcfg(dev);
1050 + if (rc)
1051 +@@ -4216,6 +4226,23 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
1052 + { "Micron_M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
1053 + { "Crucial_CT???M500SSD1", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
1054 +
1055 ++ /*
1056 ++ * Some WD SATA-I drives spin up and down erratically when the link
1057 ++ * is put into the slumber mode. We don't have full list of the
1058 ++ * affected devices. Disable LPM if the device matches one of the
1059 ++ * known prefixes and is SATA-1. As a side effect LPM partial is
1060 ++ * lost too.
1061 ++ *
1062 ++ * https://bugzilla.kernel.org/show_bug.cgi?id=57211
1063 ++ */
1064 ++ { "WDC WD800JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
1065 ++ { "WDC WD1200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
1066 ++ { "WDC WD1600JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
1067 ++ { "WDC WD2000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
1068 ++ { "WDC WD2500JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
1069 ++ { "WDC WD3000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
1070 ++ { "WDC WD3200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
1071 ++
1072 + /* End Marker */
1073 + { }
1074 + };
1075 +diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
1076 +index 377eb889f555..ef8567de6a75 100644
1077 +--- a/drivers/ata/libata-scsi.c
1078 ++++ b/drivers/ata/libata-scsi.c
1079 +@@ -111,12 +111,14 @@ static const char *ata_lpm_policy_names[] = {
1080 + [ATA_LPM_MIN_POWER] = "min_power",
1081 + };
1082 +
1083 +-static ssize_t ata_scsi_lpm_store(struct device *dev,
1084 ++static ssize_t ata_scsi_lpm_store(struct device *device,
1085 + struct device_attribute *attr,
1086 + const char *buf, size_t count)
1087 + {
1088 +- struct Scsi_Host *shost = class_to_shost(dev);
1089 ++ struct Scsi_Host *shost = class_to_shost(device);
1090 + struct ata_port *ap = ata_shost_to_port(shost);
1091 ++ struct ata_link *link;
1092 ++ struct ata_device *dev;
1093 + enum ata_lpm_policy policy;
1094 + unsigned long flags;
1095 +
1096 +@@ -132,10 +134,20 @@ static ssize_t ata_scsi_lpm_store(struct device *dev,
1097 + return -EINVAL;
1098 +
1099 + spin_lock_irqsave(ap->lock, flags);
1100 ++
1101 ++ ata_for_each_link(link, ap, EDGE) {
1102 ++ ata_for_each_dev(dev, &ap->link, ENABLED) {
1103 ++ if (dev->horkage & ATA_HORKAGE_NOLPM) {
1104 ++ count = -EOPNOTSUPP;
1105 ++ goto out_unlock;
1106 ++ }
1107 ++ }
1108 ++ }
1109 ++
1110 + ap->target_lpm_policy = policy;
1111 + ata_port_schedule_eh(ap);
1112 ++out_unlock:
1113 + spin_unlock_irqrestore(ap->lock, flags);
1114 +-
1115 + return count;
1116 + }
1117 +
1118 +diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
1119 +index 56be31819897..dc9d4b1ea4ec 100644
1120 +--- a/drivers/ata/sata_mv.c
1121 ++++ b/drivers/ata/sata_mv.c
1122 +@@ -304,6 +304,7 @@ enum {
1123 + MV5_LTMODE = 0x30,
1124 + MV5_PHY_CTL = 0x0C,
1125 + SATA_IFCFG = 0x050,
1126 ++ LP_PHY_CTL = 0x058,
1127 +
1128 + MV_M2_PREAMP_MASK = 0x7e0,
1129 +
1130 +@@ -431,6 +432,7 @@ enum {
1131 + MV_HP_CUT_THROUGH = (1 << 10), /* can use EDMA cut-through */
1132 + MV_HP_FLAG_SOC = (1 << 11), /* SystemOnChip, no PCI */
1133 + MV_HP_QUIRK_LED_BLINK_EN = (1 << 12), /* is led blinking enabled? */
1134 ++ MV_HP_FIX_LP_PHY_CTL = (1 << 13), /* fix speed in LP_PHY_CTL ? */
1135 +
1136 + /* Port private flags (pp_flags) */
1137 + MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */
1138 +@@ -1358,6 +1360,7 @@ static int mv_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val)
1139 +
1140 + if (ofs != 0xffffffffU) {
1141 + void __iomem *addr = mv_ap_base(link->ap) + ofs;
1142 ++ struct mv_host_priv *hpriv = link->ap->host->private_data;
1143 + if (sc_reg_in == SCR_CONTROL) {
1144 + /*
1145 + * Workaround for 88SX60x1 FEr SATA#26:
1146 +@@ -1374,6 +1377,18 @@ static int mv_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val)
1147 + */
1148 + if ((val & 0xf) == 1 || (readl(addr) & 0xf) == 1)
1149 + val |= 0xf000;
1150 ++
1151 ++ if (hpriv->hp_flags & MV_HP_FIX_LP_PHY_CTL) {
1152 ++ void __iomem *lp_phy_addr =
1153 ++ mv_ap_base(link->ap) + LP_PHY_CTL;
1154 ++ /*
1155 ++ * Set PHY speed according to SControl speed.
1156 ++ */
1157 ++ if ((val & 0xf0) == 0x10)
1158 ++ writelfl(0x7, lp_phy_addr);
1159 ++ else
1160 ++ writelfl(0x227, lp_phy_addr);
1161 ++ }
1162 + }
1163 + writelfl(val, addr);
1164 + return 0;
1165 +@@ -4110,6 +4125,15 @@ static int mv_platform_probe(struct platform_device *pdev)
1166 + if (rc)
1167 + goto err;
1168 +
1169 ++ /*
1170 ++ * To allow disk hotplug on Armada 370/XP SoCs, the PHY speed must be
1171 ++ * updated in the LP_PHY_CTL register.
1172 ++ */
1173 ++ if (pdev->dev.of_node &&
1174 ++ of_device_is_compatible(pdev->dev.of_node,
1175 ++ "marvell,armada-370-sata"))
1176 ++ hpriv->hp_flags |= MV_HP_FIX_LP_PHY_CTL;
1177 ++
1178 + /* initialize adapter */
1179 + rc = mv_init_host(host);
1180 + if (rc)
1181 +@@ -4209,6 +4233,7 @@ static int mv_platform_resume(struct platform_device *pdev)
1182 +
1183 + #ifdef CONFIG_OF
1184 + static struct of_device_id mv_sata_dt_ids[] = {
1185 ++ { .compatible = "marvell,armada-370-sata", },
1186 + { .compatible = "marvell,orion-sata", },
1187 + {},
1188 + };
1189 +diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.c b/drivers/char/tpm/tpm_i2c_stm_st33.c
1190 +index a0d6ceb5d005..cf6840385483 100644
1191 +--- a/drivers/char/tpm/tpm_i2c_stm_st33.c
1192 ++++ b/drivers/char/tpm/tpm_i2c_stm_st33.c
1193 +@@ -410,6 +410,8 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
1194 + &chip->vendor.read_queue)
1195 + == 0) {
1196 + burstcnt = get_burstcount(chip);
1197 ++ if (burstcnt < 0)
1198 ++ return burstcnt;
1199 + len = min_t(int, burstcnt, count - size);
1200 + I2C_READ_DATA(client, TPM_DATA_FIFO, buf + size, len);
1201 + size += len;
1202 +@@ -451,7 +453,8 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
1203 + static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
1204 + size_t len)
1205 + {
1206 +- u32 status, burstcnt = 0, i, size;
1207 ++ u32 status, i, size;
1208 ++ int burstcnt = 0;
1209 + int ret;
1210 + u8 data;
1211 + struct i2c_client *client;
1212 +@@ -482,6 +485,8 @@ static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
1213 +
1214 + for (i = 0; i < len - 1;) {
1215 + burstcnt = get_burstcount(chip);
1216 ++ if (burstcnt < 0)
1217 ++ return burstcnt;
1218 + size = min_t(int, len - i - 1, burstcnt);
1219 + ret = I2C_WRITE_DATA(client, TPM_DATA_FIFO, buf, size);
1220 + if (ret < 0)
1221 +diff --git a/drivers/char/tpm/tpm_ppi.c b/drivers/char/tpm/tpm_ppi.c
1222 +index e1f3337a0cf9..2db4419831be 100644
1223 +--- a/drivers/char/tpm/tpm_ppi.c
1224 ++++ b/drivers/char/tpm/tpm_ppi.c
1225 +@@ -172,7 +172,7 @@ static ssize_t tpm_store_ppi_request(struct device *dev,
1226 + * is updated with function index from SUBREQ to SUBREQ2 since PPI
1227 + * version 1.1
1228 + */
1229 +- if (strcmp(version, "1.1") == -1)
1230 ++ if (strcmp(version, "1.1") < 0)
1231 + params[2].integer.value = TPM_PPI_FN_SUBREQ;
1232 + else
1233 + params[2].integer.value = TPM_PPI_FN_SUBREQ2;
1234 +@@ -182,7 +182,7 @@ static ssize_t tpm_store_ppi_request(struct device *dev,
1235 + * string/package type. For PPI version 1.0 and 1.1, use buffer type
1236 + * for compatibility, and use package type since 1.2 according to spec.
1237 + */
1238 +- if (strcmp(version, "1.2") == -1) {
1239 ++ if (strcmp(version, "1.2") < 0) {
1240 + params[3].type = ACPI_TYPE_BUFFER;
1241 + params[3].buffer.length = sizeof(req);
1242 + sscanf(buf, "%d", &req);
1243 +@@ -248,7 +248,7 @@ static ssize_t tpm_show_ppi_transition_action(struct device *dev,
1244 + * (e.g. Capella with PPI 1.0) need integer/string/buffer type, so for
1245 + * compatibility, define params[3].type as buffer, if PPI version < 1.2
1246 + */
1247 +- if (strcmp(version, "1.2") == -1) {
1248 ++ if (strcmp(version, "1.2") < 0) {
1249 + params[3].type = ACPI_TYPE_BUFFER;
1250 + params[3].buffer.length = 0;
1251 + params[3].buffer.pointer = NULL;
1252 +@@ -390,7 +390,7 @@ static ssize_t show_ppi_operations(char *buf, u32 start, u32 end)
1253 + kfree(output.pointer);
1254 + output.length = ACPI_ALLOCATE_BUFFER;
1255 + output.pointer = NULL;
1256 +- if (strcmp(version, "1.2") == -1)
1257 ++ if (strcmp(version, "1.2") < 0)
1258 + return -EPERM;
1259 +
1260 + params[2].integer.value = TPM_PPI_FN_GETOPR;
1261 +diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
1262 +index 644fec54681f..f1e9d7bd131f 100644
1263 +--- a/drivers/edac/e752x_edac.c
1264 ++++ b/drivers/edac/e752x_edac.c
1265 +@@ -1182,9 +1182,11 @@ static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
1266 + pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
1267 + pvt->dev_info->err_dev, pvt->bridge_ck);
1268 +
1269 +- if (pvt->bridge_ck == NULL)
1270 ++ if (pvt->bridge_ck == NULL) {
1271 + pvt->bridge_ck = pci_scan_single_device(pdev->bus,
1272 + PCI_DEVFN(0, 1));
1273 ++ pci_dev_get(pvt->bridge_ck);
1274 ++ }
1275 +
1276 + if (pvt->bridge_ck == NULL) {
1277 + e752x_printk(KERN_ERR, "error reporting device not found:"
1278 +diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
1279 +index d65f3fd895dd..758774f4454c 100644
1280 +--- a/drivers/hwmon/k10temp.c
1281 ++++ b/drivers/hwmon/k10temp.c
1282 +@@ -210,6 +210,7 @@ static DEFINE_PCI_DEVICE_TABLE(k10temp_id_table) = {
1283 + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) },
1284 + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) },
1285 + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) },
1286 ++ { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F3) },
1287 + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) },
1288 + {}
1289 + };
1290 +diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
1291 +index 3b26129f6055..faa3e8e56f6c 100644
1292 +--- a/drivers/i2c/busses/Kconfig
1293 ++++ b/drivers/i2c/busses/Kconfig
1294 +@@ -152,6 +152,7 @@ config I2C_PIIX4
1295 + ATI SB700/SP5100
1296 + ATI SB800
1297 + AMD Hudson-2
1298 ++ AMD ML
1299 + AMD CZ
1300 + Serverworks OSB4
1301 + Serverworks CSB5
1302 +diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
1303 +index 8be7e42aa4de..b8c5187b9ee0 100644
1304 +--- a/drivers/i2c/busses/i2c-mv64xxx.c
1305 ++++ b/drivers/i2c/busses/i2c-mv64xxx.c
1306 +@@ -692,6 +692,7 @@ static const struct of_device_id mv64xxx_i2c_of_match_table[] = {
1307 + { .compatible = "allwinner,sun4i-i2c", .data = &mv64xxx_i2c_regs_sun4i},
1308 + { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
1309 + { .compatible = "marvell,mv78230-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
1310 ++ { .compatible = "marvell,mv78230-a0-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
1311 + {}
1312 + };
1313 + MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table);
1314 +@@ -783,6 +784,10 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
1315 + drv_data->errata_delay = true;
1316 + }
1317 +
1318 ++ if (of_device_is_compatible(np, "marvell,mv78230-a0-i2c")) {
1319 ++ drv_data->offload_enabled = false;
1320 ++ drv_data->errata_delay = true;
1321 ++ }
1322 + out:
1323 + return rc;
1324 + #endif
1325 +diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
1326 +index a028617b8f13..f71b4d381c00 100644
1327 +--- a/drivers/i2c/busses/i2c-piix4.c
1328 ++++ b/drivers/i2c/busses/i2c-piix4.c
1329 +@@ -22,7 +22,7 @@
1330 + Intel PIIX4, 440MX
1331 + Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
1332 + ATI IXP200, IXP300, IXP400, SB600, SB700/SP5100, SB800
1333 +- AMD Hudson-2, CZ
1334 ++ AMD Hudson-2, ML, CZ
1335 + SMSC Victory66
1336 +
1337 + Note: we assume there can only be one device, with one or more
1338 +@@ -235,7 +235,8 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
1339 + {
1340 + unsigned short piix4_smba;
1341 + unsigned short smba_idx = 0xcd6;
1342 +- u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en;
1343 ++ u8 smba_en_lo, smba_en_hi, smb_en, smb_en_status;
1344 ++ u8 i2ccfg, i2ccfg_offset = 0x10;
1345 +
1346 + /* SB800 and later SMBus does not support forcing address */
1347 + if (force || force_addr) {
1348 +@@ -245,7 +246,15 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
1349 + }
1350 +
1351 + /* Determine the address of the SMBus areas */
1352 +- smb_en = (aux) ? 0x28 : 0x2c;
1353 ++ if ((PIIX4_dev->vendor == PCI_VENDOR_ID_AMD &&
1354 ++ PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS &&
1355 ++ PIIX4_dev->revision >= 0x41) ||
1356 ++ (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD &&
1357 ++ PIIX4_dev->device == 0x790b &&
1358 ++ PIIX4_dev->revision >= 0x49))
1359 ++ smb_en = 0x00;
1360 ++ else
1361 ++ smb_en = (aux) ? 0x28 : 0x2c;
1362 +
1363 + if (!request_region(smba_idx, 2, "smba_idx")) {
1364 + dev_err(&PIIX4_dev->dev, "SMBus base address index region "
1365 +@@ -258,13 +267,22 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
1366 + smba_en_hi = inb_p(smba_idx + 1);
1367 + release_region(smba_idx, 2);
1368 +
1369 +- if ((smba_en_lo & 1) == 0) {
1370 ++ if (!smb_en) {
1371 ++ smb_en_status = smba_en_lo & 0x10;
1372 ++ piix4_smba = smba_en_hi << 8;
1373 ++ if (aux)
1374 ++ piix4_smba |= 0x20;
1375 ++ } else {
1376 ++ smb_en_status = smba_en_lo & 0x01;
1377 ++ piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0;
1378 ++ }
1379 ++
1380 ++ if (!smb_en_status) {
1381 + dev_err(&PIIX4_dev->dev,
1382 + "Host SMBus controller not enabled!\n");
1383 + return -ENODEV;
1384 + }
1385 +
1386 +- piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0;
1387 + if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
1388 + return -ENODEV;
1389 +
1390 +diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
1391 +index 7d388b8bb50e..16958704af3b 100644
1392 +--- a/drivers/md/bcache/bset.c
1393 ++++ b/drivers/md/bcache/bset.c
1394 +@@ -955,7 +955,7 @@ static void sort_key_next(struct btree_iter *iter,
1395 + *i = iter->data[--iter->used];
1396 + }
1397 +
1398 +-static void btree_sort_fixup(struct btree_iter *iter)
1399 ++static struct bkey *btree_sort_fixup(struct btree_iter *iter, struct bkey *tmp)
1400 + {
1401 + while (iter->used > 1) {
1402 + struct btree_iter_set *top = iter->data, *i = top + 1;
1403 +@@ -983,9 +983,22 @@ static void btree_sort_fixup(struct btree_iter *iter)
1404 + } else {
1405 + /* can't happen because of comparison func */
1406 + BUG_ON(!bkey_cmp(&START_KEY(top->k), &START_KEY(i->k)));
1407 +- bch_cut_back(&START_KEY(i->k), top->k);
1408 ++
1409 ++ if (bkey_cmp(i->k, top->k) < 0) {
1410 ++ bkey_copy(tmp, top->k);
1411 ++
1412 ++ bch_cut_back(&START_KEY(i->k), tmp);
1413 ++ bch_cut_front(i->k, top->k);
1414 ++ heap_sift(iter, 0, btree_iter_cmp);
1415 ++
1416 ++ return tmp;
1417 ++ } else {
1418 ++ bch_cut_back(&START_KEY(i->k), top->k);
1419 ++ }
1420 + }
1421 + }
1422 ++
1423 ++ return NULL;
1424 + }
1425 +
1426 + static void btree_mergesort(struct btree *b, struct bset *out,
1427 +@@ -993,15 +1006,20 @@ static void btree_mergesort(struct btree *b, struct bset *out,
1428 + bool fixup, bool remove_stale)
1429 + {
1430 + struct bkey *k, *last = NULL;
1431 ++ BKEY_PADDED(k) tmp;
1432 + bool (*bad)(struct btree *, const struct bkey *) = remove_stale
1433 + ? bch_ptr_bad
1434 + : bch_ptr_invalid;
1435 +
1436 + while (!btree_iter_end(iter)) {
1437 + if (fixup && !b->level)
1438 +- btree_sort_fixup(iter);
1439 ++ k = btree_sort_fixup(iter, &tmp.k);
1440 ++ else
1441 ++ k = NULL;
1442 ++
1443 ++ if (!k)
1444 ++ k = bch_btree_iter_next(iter);
1445 +
1446 +- k = bch_btree_iter_next(iter);
1447 + if (bad(b, k))
1448 + continue;
1449 +
1450 +diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
1451 +index 34520cbe8afb..12b3ae3aa7c5 100644
1452 +--- a/drivers/mfd/max77686.c
1453 ++++ b/drivers/mfd/max77686.c
1454 +@@ -104,7 +104,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
1455 + max77686->irq_gpio = pdata->irq_gpio;
1456 + max77686->irq = i2c->irq;
1457 +
1458 +- max77686->regmap = regmap_init_i2c(i2c, &max77686_regmap_config);
1459 ++ max77686->regmap = devm_regmap_init_i2c(i2c, &max77686_regmap_config);
1460 + if (IS_ERR(max77686->regmap)) {
1461 + ret = PTR_ERR(max77686->regmap);
1462 + dev_err(max77686->dev, "Failed to allocate register map: %d\n",
1463 +diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
1464 +index 9b3a0fb7f265..5d9e687a866c 100644
1465 +--- a/drivers/misc/mei/hbm.c
1466 ++++ b/drivers/misc/mei/hbm.c
1467 +@@ -128,6 +128,17 @@ static bool is_treat_specially_client(struct mei_cl *cl,
1468 + return false;
1469 + }
1470 +
1471 ++/**
1472 ++ * mei_hbm_idle - set hbm to idle state
1473 ++ *
1474 ++ * @dev: the device structure
1475 ++ */
1476 ++void mei_hbm_idle(struct mei_device *dev)
1477 ++{
1478 ++ dev->init_clients_timer = 0;
1479 ++ dev->hbm_state = MEI_HBM_IDLE;
1480 ++}
1481 ++
1482 + int mei_hbm_start_wait(struct mei_device *dev)
1483 + {
1484 + int ret;
1485 +@@ -577,6 +588,14 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
1486 + mei_read_slots(dev, dev->rd_msg_buf, hdr->length);
1487 + mei_msg = (struct mei_bus_message *)dev->rd_msg_buf;
1488 +
1489 ++ /* ignore spurious message and prevent reset nesting
1490 ++ * hbm is put to idle during system reset
1491 ++ */
1492 ++ if (dev->hbm_state == MEI_HBM_IDLE) {
1493 ++ dev_dbg(&dev->pdev->dev, "hbm: state is idle ignore spurious messages\n");
1494 ++ return 0;
1495 ++ }
1496 ++
1497 + switch (mei_msg->hbm_cmd) {
1498 + case HOST_START_RES_CMD:
1499 + version_res = (struct hbm_host_version_response *)mei_msg;
1500 +diff --git a/drivers/misc/mei/hbm.h b/drivers/misc/mei/hbm.h
1501 +index 4ae2e56e404f..210757701207 100644
1502 +--- a/drivers/misc/mei/hbm.h
1503 ++++ b/drivers/misc/mei/hbm.h
1504 +@@ -49,6 +49,7 @@ static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length)
1505 + hdr->reserved = 0;
1506 + }
1507 +
1508 ++void mei_hbm_idle(struct mei_device *dev);
1509 + int mei_hbm_start_req(struct mei_device *dev);
1510 + int mei_hbm_start_wait(struct mei_device *dev);
1511 + int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl);
1512 +diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
1513 +index f7f3abbe12b6..53a93908e030 100644
1514 +--- a/drivers/misc/mei/init.c
1515 ++++ b/drivers/misc/mei/init.c
1516 +@@ -151,14 +151,19 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
1517 + dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n",
1518 + mei_dev_state_str(dev->dev_state));
1519 +
1520 ++ /* we're already in reset, cancel the init timer
1521 ++ * if the reset was called due the hbm protocol error
1522 ++ * we need to call it before hw start
1523 ++ * so the hbm watchdog won't kick in
1524 ++ */
1525 ++ mei_hbm_idle(dev);
1526 ++
1527 + ret = mei_hw_reset(dev, interrupts_enabled);
1528 + if (ret) {
1529 + dev_err(&dev->pdev->dev, "hw reset failed disabling the device\n");
1530 + interrupts_enabled = false;
1531 +- dev->dev_state = MEI_DEV_DISABLED;
1532 + }
1533 +
1534 +- dev->hbm_state = MEI_HBM_IDLE;
1535 +
1536 + if (dev->dev_state != MEI_DEV_INITIALIZING &&
1537 + dev->dev_state != MEI_DEV_POWER_UP) {
1538 +@@ -182,8 +187,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
1539 + memset(&dev->wr_ext_msg, 0, sizeof(dev->wr_ext_msg));
1540 + }
1541 +
1542 +- /* we're already in reset, cancel the init timer */
1543 +- dev->init_clients_timer = 0;
1544 +
1545 + dev->me_clients_num = 0;
1546 + dev->rd_msg_hdr = 0;
1547 +@@ -191,6 +194,7 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
1548 +
1549 + if (!interrupts_enabled) {
1550 + dev_dbg(&dev->pdev->dev, "intr not enabled end of reset\n");
1551 ++ dev->dev_state = MEI_DEV_DISABLED;
1552 + return;
1553 + }
1554 +
1555 +diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c
1556 +index 7a95c07e59a6..6ce63f531fa2 100644
1557 +--- a/drivers/misc/mei/interrupt.c
1558 ++++ b/drivers/misc/mei/interrupt.c
1559 +@@ -533,7 +533,6 @@ EXPORT_SYMBOL_GPL(mei_irq_write_handler);
1560 + *
1561 + * @work: pointer to the work_struct structure
1562 + *
1563 +- * NOTE: This function is called by timer interrupt work
1564 + */
1565 + void mei_timer(struct work_struct *work)
1566 + {
1567 +@@ -548,18 +547,24 @@ void mei_timer(struct work_struct *work)
1568 +
1569 +
1570 + mutex_lock(&dev->device_lock);
1571 +- if (dev->dev_state != MEI_DEV_ENABLED) {
1572 +- if (dev->dev_state == MEI_DEV_INIT_CLIENTS) {
1573 +- if (dev->init_clients_timer) {
1574 +- if (--dev->init_clients_timer == 0) {
1575 +- dev_err(&dev->pdev->dev, "reset: init clients timeout hbm_state = %d.\n",
1576 +- dev->hbm_state);
1577 +- mei_reset(dev, 1);
1578 +- }
1579 ++
1580 ++ /* Catch interrupt stalls during HBM init handshake */
1581 ++ if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
1582 ++ dev->hbm_state != MEI_HBM_IDLE) {
1583 ++
1584 ++ if (dev->init_clients_timer) {
1585 ++ if (--dev->init_clients_timer == 0) {
1586 ++ dev_err(&dev->pdev->dev, "timer: init clients timeout hbm_state = %d.\n",
1587 ++ dev->hbm_state);
1588 ++ mei_reset(dev, 1);
1589 ++ goto out;
1590 + }
1591 + }
1592 +- goto out;
1593 + }
1594 ++
1595 ++ if (dev->dev_state != MEI_DEV_ENABLED)
1596 ++ goto out;
1597 ++
1598 + /*** connect/disconnect timeouts ***/
1599 + list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
1600 + if (cl_pos->timer_count) {
1601 +diff --git a/drivers/misc/mic/host/mic_device.h b/drivers/misc/mic/host/mic_device.h
1602 +index 3574cc375bb9..b2da289320c9 100644
1603 +--- a/drivers/misc/mic/host/mic_device.h
1604 ++++ b/drivers/misc/mic/host/mic_device.h
1605 +@@ -134,6 +134,8 @@ struct mic_device {
1606 + * @send_intr: Send an interrupt for a particular doorbell on the card.
1607 + * @ack_interrupt: Hardware specific operations to ack the h/w on
1608 + * receipt of an interrupt.
1609 ++ * @intr_workarounds: Hardware specific workarounds needed after
1610 ++ * handling an interrupt.
1611 + * @reset: Reset the remote processor.
1612 + * @reset_fw_ready: Reset firmware ready field.
1613 + * @is_fw_ready: Check if firmware is ready for OS download.
1614 +@@ -149,6 +151,7 @@ struct mic_hw_ops {
1615 + void (*write_spad)(struct mic_device *mdev, unsigned int idx, u32 val);
1616 + void (*send_intr)(struct mic_device *mdev, int doorbell);
1617 + u32 (*ack_interrupt)(struct mic_device *mdev);
1618 ++ void (*intr_workarounds)(struct mic_device *mdev);
1619 + void (*reset)(struct mic_device *mdev);
1620 + void (*reset_fw_ready)(struct mic_device *mdev);
1621 + bool (*is_fw_ready)(struct mic_device *mdev);
1622 +diff --git a/drivers/misc/mic/host/mic_main.c b/drivers/misc/mic/host/mic_main.c
1623 +index ad838c7651c4..c04a021e20c7 100644
1624 +--- a/drivers/misc/mic/host/mic_main.c
1625 ++++ b/drivers/misc/mic/host/mic_main.c
1626 +@@ -115,7 +115,7 @@ static irqreturn_t mic_shutdown_db(int irq, void *data)
1627 + struct mic_device *mdev = data;
1628 + struct mic_bootparam *bootparam = mdev->dp;
1629 +
1630 +- mdev->ops->ack_interrupt(mdev);
1631 ++ mdev->ops->intr_workarounds(mdev);
1632 +
1633 + switch (bootparam->shutdown_status) {
1634 + case MIC_HALTED:
1635 +diff --git a/drivers/misc/mic/host/mic_virtio.c b/drivers/misc/mic/host/mic_virtio.c
1636 +index e04bb4fe6823..752ff873f891 100644
1637 +--- a/drivers/misc/mic/host/mic_virtio.c
1638 ++++ b/drivers/misc/mic/host/mic_virtio.c
1639 +@@ -369,7 +369,7 @@ static irqreturn_t mic_virtio_intr_handler(int irq, void *data)
1640 + struct mic_vdev *mvdev = data;
1641 + struct mic_device *mdev = mvdev->mdev;
1642 +
1643 +- mdev->ops->ack_interrupt(mdev);
1644 ++ mdev->ops->intr_workarounds(mdev);
1645 + schedule_work(&mvdev->virtio_bh_work);
1646 + return IRQ_HANDLED;
1647 + }
1648 +diff --git a/drivers/misc/mic/host/mic_x100.c b/drivers/misc/mic/host/mic_x100.c
1649 +index 0dfa8a81436e..5562fdd3ef4e 100644
1650 +--- a/drivers/misc/mic/host/mic_x100.c
1651 ++++ b/drivers/misc/mic/host/mic_x100.c
1652 +@@ -174,35 +174,38 @@ static void mic_x100_send_intr(struct mic_device *mdev, int doorbell)
1653 + }
1654 +
1655 + /**
1656 +- * mic_ack_interrupt - Device specific interrupt handling.
1657 +- * @mdev: pointer to mic_device instance
1658 ++ * mic_x100_ack_interrupt - Read the interrupt sources register and
1659 ++ * clear it. This function will be called in the MSI/INTx case.
1660 ++ * @mdev: Pointer to mic_device instance.
1661 + *
1662 +- * Returns: bitmask of doorbell events triggered.
1663 ++ * Returns: bitmask of interrupt sources triggered.
1664 + */
1665 + static u32 mic_x100_ack_interrupt(struct mic_device *mdev)
1666 + {
1667 +- u32 reg = 0;
1668 +- struct mic_mw *mw = &mdev->mmio;
1669 + u32 sicr0 = MIC_X100_SBOX_BASE_ADDRESS + MIC_X100_SBOX_SICR0;
1670 ++ u32 reg = mic_mmio_read(&mdev->mmio, sicr0);
1671 ++ mic_mmio_write(&mdev->mmio, reg, sicr0);
1672 ++ return reg;
1673 ++}
1674 ++
1675 ++/**
1676 ++ * mic_x100_intr_workarounds - These hardware specific workarounds are
1677 ++ * to be invoked everytime an interrupt is handled.
1678 ++ * @mdev: Pointer to mic_device instance.
1679 ++ *
1680 ++ * Returns: none
1681 ++ */
1682 ++static void mic_x100_intr_workarounds(struct mic_device *mdev)
1683 ++{
1684 ++ struct mic_mw *mw = &mdev->mmio;
1685 +
1686 + /* Clear pending bit array. */
1687 + if (MIC_A0_STEP == mdev->stepping)
1688 + mic_mmio_write(mw, 1, MIC_X100_SBOX_BASE_ADDRESS +
1689 + MIC_X100_SBOX_MSIXPBACR);
1690 +
1691 +- if (mdev->irq_info.num_vectors <= 1) {
1692 +- reg = mic_mmio_read(mw, sicr0);
1693 +-
1694 +- if (unlikely(!reg))
1695 +- goto done;
1696 +-
1697 +- mic_mmio_write(mw, reg, sicr0);
1698 +- }
1699 +-
1700 + if (mdev->stepping >= MIC_B0_STEP)
1701 + mdev->intr_ops->enable_interrupts(mdev);
1702 +-done:
1703 +- return reg;
1704 + }
1705 +
1706 + /**
1707 +@@ -553,6 +556,7 @@ struct mic_hw_ops mic_x100_ops = {
1708 + .write_spad = mic_x100_write_spad,
1709 + .send_intr = mic_x100_send_intr,
1710 + .ack_interrupt = mic_x100_ack_interrupt,
1711 ++ .intr_workarounds = mic_x100_intr_workarounds,
1712 + .reset = mic_x100_hw_reset,
1713 + .reset_fw_ready = mic_x100_reset_fw_ready,
1714 + .is_fw_ready = mic_x100_is_fw_ready,
1715 +diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
1716 +index 461a4c3f4ef7..1dcaf8a32be7 100644
1717 +--- a/drivers/mmc/host/sdhci-esdhc-imx.c
1718 ++++ b/drivers/mmc/host/sdhci-esdhc-imx.c
1719 +@@ -558,19 +558,17 @@ static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
1720 + struct pltfm_imx_data *imx_data = pltfm_host->priv;
1721 + struct esdhc_platform_data *boarddata = &imx_data->boarddata;
1722 +
1723 +- u32 f_host = clk_get_rate(pltfm_host->clk);
1724 +-
1725 +- if (boarddata->f_max && (boarddata->f_max < f_host))
1726 ++ if (boarddata->f_max && (boarddata->f_max < pltfm_host->clock))
1727 + return boarddata->f_max;
1728 + else
1729 +- return f_host;
1730 ++ return pltfm_host->clock;
1731 + }
1732 +
1733 + static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
1734 + {
1735 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
1736 +
1737 +- return clk_get_rate(pltfm_host->clk) / 256 / 16;
1738 ++ return pltfm_host->clock / 256 / 16;
1739 + }
1740 +
1741 + static inline void esdhc_pltfm_set_clock(struct sdhci_host *host,
1742 +@@ -578,7 +576,7 @@ static inline void esdhc_pltfm_set_clock(struct sdhci_host *host,
1743 + {
1744 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
1745 + struct pltfm_imx_data *imx_data = pltfm_host->priv;
1746 +- unsigned int host_clock = clk_get_rate(pltfm_host->clk);
1747 ++ unsigned int host_clock = pltfm_host->clock;
1748 + int pre_div = 2;
1749 + int div = 1;
1750 + u32 temp, val;
1751 +@@ -976,7 +974,7 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
1752 + }
1753 +
1754 + pltfm_host->clk = imx_data->clk_per;
1755 +-
1756 ++ pltfm_host->clock = clk_get_rate(pltfm_host->clk);
1757 + clk_prepare_enable(imx_data->clk_per);
1758 + clk_prepare_enable(imx_data->clk_ipg);
1759 + clk_prepare_enable(imx_data->clk_ahb);
1760 +diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
1761 +index 8f753811fc7a..c377c16ab0a2 100644
1762 +--- a/drivers/mmc/host/sdhci-pci.c
1763 ++++ b/drivers/mmc/host/sdhci-pci.c
1764 +@@ -381,6 +381,7 @@ static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
1765 +
1766 + static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
1767 + .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
1768 ++ .quirks2 = SDHCI_QUIRK2_BROKEN_HS200,
1769 + .probe_slot = intel_mrfl_mmc_probe_slot,
1770 + };
1771 +
1772 +diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
1773 +index bd8a0982aec3..3c719209c2cc 100644
1774 +--- a/drivers/mmc/host/sdhci.c
1775 ++++ b/drivers/mmc/host/sdhci.c
1776 +@@ -1845,12 +1845,12 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1777 + unsigned long timeout;
1778 + int err = 0;
1779 + bool requires_tuning_nonuhs = false;
1780 ++ unsigned long flags;
1781 +
1782 + host = mmc_priv(mmc);
1783 +
1784 + sdhci_runtime_pm_get(host);
1785 +- disable_irq(host->irq);
1786 +- spin_lock(&host->lock);
1787 ++ spin_lock_irqsave(&host->lock, flags);
1788 +
1789 + ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1790 +
1791 +@@ -1870,15 +1870,13 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1792 + requires_tuning_nonuhs)
1793 + ctrl |= SDHCI_CTRL_EXEC_TUNING;
1794 + else {
1795 +- spin_unlock(&host->lock);
1796 +- enable_irq(host->irq);
1797 ++ spin_unlock_irqrestore(&host->lock, flags);
1798 + sdhci_runtime_pm_put(host);
1799 + return 0;
1800 + }
1801 +
1802 + if (host->ops->platform_execute_tuning) {
1803 +- spin_unlock(&host->lock);
1804 +- enable_irq(host->irq);
1805 ++ spin_unlock_irqrestore(&host->lock, flags);
1806 + err = host->ops->platform_execute_tuning(host, opcode);
1807 + sdhci_runtime_pm_put(host);
1808 + return err;
1809 +@@ -1951,15 +1949,12 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1810 + host->cmd = NULL;
1811 + host->mrq = NULL;
1812 +
1813 +- spin_unlock(&host->lock);
1814 +- enable_irq(host->irq);
1815 +-
1816 ++ spin_unlock_irqrestore(&host->lock, flags);
1817 + /* Wait for Buffer Read Ready interrupt */
1818 + wait_event_interruptible_timeout(host->buf_ready_int,
1819 + (host->tuning_done == 1),
1820 + msecs_to_jiffies(50));
1821 +- disable_irq(host->irq);
1822 +- spin_lock(&host->lock);
1823 ++ spin_lock_irqsave(&host->lock, flags);
1824 +
1825 + if (!host->tuning_done) {
1826 + pr_info(DRIVER_NAME ": Timeout waiting for "
1827 +@@ -2034,8 +2029,7 @@ out:
1828 + err = 0;
1829 +
1830 + sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier);
1831 +- spin_unlock(&host->lock);
1832 +- enable_irq(host->irq);
1833 ++ spin_unlock_irqrestore(&host->lock, flags);
1834 + sdhci_runtime_pm_put(host);
1835 +
1836 + return err;
1837 +@@ -3004,7 +2998,8 @@ int sdhci_add_host(struct sdhci_host *host)
1838 + /* SD3.0: SDR104 is supported so (for eMMC) the caps2
1839 + * field can be promoted to support HS200.
1840 + */
1841 +- mmc->caps2 |= MMC_CAP2_HS200;
1842 ++ if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200))
1843 ++ mmc->caps2 |= MMC_CAP2_HS200;
1844 + } else if (caps[1] & SDHCI_SUPPORT_SDR50)
1845 + mmc->caps |= MMC_CAP_UHS_SDR50;
1846 +
1847 +diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
1848 +index ed384fee76ac..02479739eaa0 100644
1849 +--- a/drivers/net/vxlan.c
1850 ++++ b/drivers/net/vxlan.c
1851 +@@ -1047,6 +1047,15 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
1852 + if (!vs)
1853 + goto drop;
1854 +
1855 ++ /* If the NIC driver gave us an encapsulated packet
1856 ++ * with the encapsulation mark, the device checksummed it
1857 ++ * for us. Otherwise force the upper layers to verify it.
1858 ++ */
1859 ++ if (skb->ip_summed != CHECKSUM_UNNECESSARY || !skb->encapsulation)
1860 ++ skb->ip_summed = CHECKSUM_NONE;
1861 ++
1862 ++ skb->encapsulation = 0;
1863 ++
1864 + vs->rcv(vs, skb, vxh->vx_vni);
1865 + return 0;
1866 +
1867 +@@ -1105,17 +1114,6 @@ static void vxlan_rcv(struct vxlan_sock *vs,
1868 +
1869 + skb_reset_network_header(skb);
1870 +
1871 +- /* If the NIC driver gave us an encapsulated packet with
1872 +- * CHECKSUM_UNNECESSARY and Rx checksum feature is enabled,
1873 +- * leave the CHECKSUM_UNNECESSARY, the device checksummed it
1874 +- * for us. Otherwise force the upper layers to verify it.
1875 +- */
1876 +- if (skb->ip_summed != CHECKSUM_UNNECESSARY || !skb->encapsulation ||
1877 +- !(vxlan->dev->features & NETIF_F_RXCSUM))
1878 +- skb->ip_summed = CHECKSUM_NONE;
1879 +-
1880 +- skb->encapsulation = 0;
1881 +-
1882 + if (oip6)
1883 + err = IP6_ECN_decapsulate(oip6, skb);
1884 + if (oip)
1885 +diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
1886 +index 8918035da3a3..e79a2cffb4fe 100644
1887 +--- a/drivers/net/wireless/ath/ath9k/hw.c
1888 ++++ b/drivers/net/wireless/ath/ath9k/hw.c
1889 +@@ -2608,13 +2608,6 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1890 + ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
1891 + pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
1892 +
1893 +- /*
1894 +- * Fast channel change across bands is available
1895 +- * only for AR9462 and AR9565.
1896 +- */
1897 +- if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
1898 +- pCap->hw_caps |= ATH9K_HW_CAP_FCC_BAND_SWITCH;
1899 +-
1900 + return 0;
1901 + }
1902 +
1903 +diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
1904 +index 95ddca5495d4..102060332dde 100644
1905 +--- a/drivers/net/wireless/ath/ath9k/recv.c
1906 ++++ b/drivers/net/wireless/ath/ath9k/recv.c
1907 +@@ -851,20 +851,15 @@ static int ath9k_process_rate(struct ath_common *common,
1908 + enum ieee80211_band band;
1909 + unsigned int i = 0;
1910 + struct ath_softc __maybe_unused *sc = common->priv;
1911 ++ struct ath_hw *ah = sc->sc_ah;
1912 +
1913 +- band = hw->conf.chandef.chan->band;
1914 ++ band = ah->curchan->chan->band;
1915 + sband = hw->wiphy->bands[band];
1916 +
1917 +- switch (hw->conf.chandef.width) {
1918 +- case NL80211_CHAN_WIDTH_5:
1919 ++ if (IS_CHAN_QUARTER_RATE(ah->curchan))
1920 + rxs->flag |= RX_FLAG_5MHZ;
1921 +- break;
1922 +- case NL80211_CHAN_WIDTH_10:
1923 ++ else if (IS_CHAN_HALF_RATE(ah->curchan))
1924 + rxs->flag |= RX_FLAG_10MHZ;
1925 +- break;
1926 +- default:
1927 +- break;
1928 +- }
1929 +
1930 + if (rx_stats->rs_rate & 0x80) {
1931 + /* HT rate */
1932 +@@ -1248,6 +1243,14 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1933 + ath_start_rx_poll(sc, 3);
1934 + }
1935 +
1936 ++ /*
1937 ++ * This shouldn't happen, but have a safety check anyway.
1938 ++ */
1939 ++ if (WARN_ON(!ah->curchan)) {
1940 ++ ret = -EINVAL;
1941 ++ goto exit;
1942 ++ }
1943 ++
1944 + if (ath9k_process_rate(common, hw, rx_stats, rx_status)) {
1945 + ret =-EINVAL;
1946 + goto exit;
1947 +@@ -1255,8 +1258,8 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1948 +
1949 + ath9k_process_rssi(common, hw, rx_stats, rx_status);
1950 +
1951 +- rx_status->band = hw->conf.chandef.chan->band;
1952 +- rx_status->freq = hw->conf.chandef.chan->center_freq;
1953 ++ rx_status->band = ah->curchan->chan->band;
1954 ++ rx_status->freq = ah->curchan->chan->center_freq;
1955 + rx_status->antenna = rx_stats->rs_antenna;
1956 + rx_status->flag |= RX_FLAG_MACTIME_END;
1957 +
1958 +diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
1959 +index 7f3d461f7e8d..54376fddfaf9 100644
1960 +--- a/drivers/net/wireless/b43/b43.h
1961 ++++ b/drivers/net/wireless/b43/b43.h
1962 +@@ -731,8 +731,6 @@ enum b43_firmware_file_type {
1963 + struct b43_request_fw_context {
1964 + /* The device we are requesting the fw for. */
1965 + struct b43_wldev *dev;
1966 +- /* a completion event structure needed if this call is asynchronous */
1967 +- struct completion fw_load_complete;
1968 + /* a pointer to the firmware object */
1969 + const struct firmware *blob;
1970 + /* The type of firmware to request. */
1971 +@@ -809,6 +807,8 @@ enum {
1972 + struct b43_wldev {
1973 + struct b43_bus_dev *dev;
1974 + struct b43_wl *wl;
1975 ++ /* a completion event structure needed if this call is asynchronous */
1976 ++ struct completion fw_load_complete;
1977 +
1978 + /* The device initialization status.
1979 + * Use b43_status() to query. */
1980 +diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
1981 +index ccd24f0acb8d..c75237eb55a1 100644
1982 +--- a/drivers/net/wireless/b43/main.c
1983 ++++ b/drivers/net/wireless/b43/main.c
1984 +@@ -2070,6 +2070,7 @@ void b43_do_release_fw(struct b43_firmware_file *fw)
1985 +
1986 + static void b43_release_firmware(struct b43_wldev *dev)
1987 + {
1988 ++ complete(&dev->fw_load_complete);
1989 + b43_do_release_fw(&dev->fw.ucode);
1990 + b43_do_release_fw(&dev->fw.pcm);
1991 + b43_do_release_fw(&dev->fw.initvals);
1992 +@@ -2095,7 +2096,7 @@ static void b43_fw_cb(const struct firmware *firmware, void *context)
1993 + struct b43_request_fw_context *ctx = context;
1994 +
1995 + ctx->blob = firmware;
1996 +- complete(&ctx->fw_load_complete);
1997 ++ complete(&ctx->dev->fw_load_complete);
1998 + }
1999 +
2000 + int b43_do_request_fw(struct b43_request_fw_context *ctx,
2001 +@@ -2142,7 +2143,7 @@ int b43_do_request_fw(struct b43_request_fw_context *ctx,
2002 + }
2003 + if (async) {
2004 + /* do this part asynchronously */
2005 +- init_completion(&ctx->fw_load_complete);
2006 ++ init_completion(&ctx->dev->fw_load_complete);
2007 + err = request_firmware_nowait(THIS_MODULE, 1, ctx->fwname,
2008 + ctx->dev->dev->dev, GFP_KERNEL,
2009 + ctx, b43_fw_cb);
2010 +@@ -2150,12 +2151,11 @@ int b43_do_request_fw(struct b43_request_fw_context *ctx,
2011 + pr_err("Unable to load firmware\n");
2012 + return err;
2013 + }
2014 +- /* stall here until fw ready */
2015 +- wait_for_completion(&ctx->fw_load_complete);
2016 ++ wait_for_completion(&ctx->dev->fw_load_complete);
2017 + if (ctx->blob)
2018 + goto fw_ready;
2019 + /* On some ARM systems, the async request will fail, but the next sync
2020 +- * request works. For this reason, we dall through here
2021 ++ * request works. For this reason, we fall through here
2022 + */
2023 + }
2024 + err = request_firmware(&ctx->blob, ctx->fwname,
2025 +@@ -2424,6 +2424,7 @@ error:
2026 +
2027 + static int b43_one_core_attach(struct b43_bus_dev *dev, struct b43_wl *wl);
2028 + static void b43_one_core_detach(struct b43_bus_dev *dev);
2029 ++static int b43_rng_init(struct b43_wl *wl);
2030 +
2031 + static void b43_request_firmware(struct work_struct *work)
2032 + {
2033 +@@ -2475,6 +2476,10 @@ start_ieee80211:
2034 + goto err_one_core_detach;
2035 + wl->hw_registred = true;
2036 + b43_leds_register(wl->current_dev);
2037 ++
2038 ++ /* Register HW RNG driver */
2039 ++ b43_rng_init(wl);
2040 ++
2041 + goto out;
2042 +
2043 + err_one_core_detach:
2044 +@@ -4636,9 +4641,6 @@ static void b43_wireless_core_exit(struct b43_wldev *dev)
2045 + if (!dev || b43_status(dev) != B43_STAT_INITIALIZED)
2046 + return;
2047 +
2048 +- /* Unregister HW RNG driver */
2049 +- b43_rng_exit(dev->wl);
2050 +-
2051 + b43_set_status(dev, B43_STAT_UNINIT);
2052 +
2053 + /* Stop the microcode PSM. */
2054 +@@ -4795,9 +4797,6 @@ static int b43_wireless_core_init(struct b43_wldev *dev)
2055 +
2056 + b43_set_status(dev, B43_STAT_INITIALIZED);
2057 +
2058 +- /* Register HW RNG driver */
2059 +- b43_rng_init(dev->wl);
2060 +-
2061 + out:
2062 + return err;
2063 +
2064 +@@ -5464,6 +5463,9 @@ static void b43_bcma_remove(struct bcma_device *core)
2065 +
2066 + b43_one_core_detach(wldev->dev);
2067 +
2068 ++ /* Unregister HW RNG driver */
2069 ++ b43_rng_exit(wl);
2070 ++
2071 + b43_leds_unregister(wl);
2072 +
2073 + ieee80211_free_hw(wl->hw);
2074 +@@ -5541,6 +5543,9 @@ static void b43_ssb_remove(struct ssb_device *sdev)
2075 +
2076 + b43_one_core_detach(dev);
2077 +
2078 ++ /* Unregister HW RNG driver */
2079 ++ b43_rng_exit(wl);
2080 ++
2081 + if (list_empty(&wl->devlist)) {
2082 + b43_leds_unregister(wl);
2083 + /* Last core on the chip unregistered.
2084 +diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c
2085 +index 4ae63f4ddfb2..50e5ddb12fb3 100644
2086 +--- a/drivers/net/wireless/b43/xmit.c
2087 ++++ b/drivers/net/wireless/b43/xmit.c
2088 +@@ -821,10 +821,10 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
2089 + * channel number in b43. */
2090 + if (chanstat & B43_RX_CHAN_5GHZ) {
2091 + status.band = IEEE80211_BAND_5GHZ;
2092 +- status.freq = b43_freq_to_channel_5ghz(chanid);
2093 ++ status.freq = b43_channel_to_freq_5ghz(chanid);
2094 + } else {
2095 + status.band = IEEE80211_BAND_2GHZ;
2096 +- status.freq = b43_freq_to_channel_2ghz(chanid);
2097 ++ status.freq = b43_channel_to_freq_2ghz(chanid);
2098 + }
2099 + break;
2100 + default:
2101 +diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
2102 +index 572668821862..349c77605231 100644
2103 +--- a/drivers/net/wireless/b43legacy/main.c
2104 ++++ b/drivers/net/wireless/b43legacy/main.c
2105 +@@ -3919,6 +3919,7 @@ static void b43legacy_remove(struct ssb_device *dev)
2106 + * as the ieee80211 unreg will destroy the workqueue. */
2107 + cancel_work_sync(&wldev->restart_work);
2108 + cancel_work_sync(&wl->firmware_load);
2109 ++ complete(&wldev->fw_load_complete);
2110 +
2111 + B43legacy_WARN_ON(!wl);
2112 + if (!wldev->fw.ucode)
2113 +diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
2114 +index a70c7b9d9bad..07867c60bd63 100644
2115 +--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
2116 ++++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
2117 +@@ -274,4 +274,8 @@ static inline unsigned int SCD_QUEUE_STATUS_BITS(unsigned int chnl)
2118 +
2119 + /*********************** END TX SCHEDULER *************************************/
2120 +
2121 ++/* Oscillator clock */
2122 ++#define OSC_CLK (0xa04068)
2123 ++#define OSC_CLK_FORCE_CONTROL (0x8)
2124 ++
2125 + #endif /* __iwl_prph_h__ */
2126 +diff --git a/drivers/net/wireless/iwlwifi/mvm/ops.c b/drivers/net/wireless/iwlwifi/mvm/ops.c
2127 +index d86083c6f445..bb5834200194 100644
2128 +--- a/drivers/net/wireless/iwlwifi/mvm/ops.c
2129 ++++ b/drivers/net/wireless/iwlwifi/mvm/ops.c
2130 +@@ -470,6 +470,7 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
2131 +
2132 + out_unregister:
2133 + ieee80211_unregister_hw(mvm->hw);
2134 ++ iwl_mvm_leds_exit(mvm);
2135 + out_free:
2136 + iwl_phy_db_free(mvm->phy_db);
2137 + kfree(mvm->scan_cmd);
2138 +diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
2139 +index cde9c16f6e4f..f53ef83a6fd4 100644
2140 +--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
2141 ++++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
2142 +@@ -206,6 +206,28 @@ static int iwl_pcie_apm_init(struct iwl_trans *trans)
2143 + goto out;
2144 + }
2145 +
2146 ++ if (trans->cfg->host_interrupt_operation_mode) {
2147 ++ /*
2148 ++ * This is a bit of an abuse - This is needed for 7260 / 3160
2149 ++ * only check host_interrupt_operation_mode even if this is
2150 ++ * not related to host_interrupt_operation_mode.
2151 ++ *
2152 ++ * Enable the oscillator to count wake up time for L1 exit. This
2153 ++ * consumes slightly more power (100uA) - but allows to be sure
2154 ++ * that we wake up from L1 on time.
2155 ++ *
2156 ++ * This looks weird: read twice the same register, discard the
2157 ++ * value, set a bit, and yet again, read that same register
2158 ++ * just to discard the value. But that's the way the hardware
2159 ++ * seems to like it.
2160 ++ */
2161 ++ iwl_read_prph(trans, OSC_CLK);
2162 ++ iwl_read_prph(trans, OSC_CLK);
2163 ++ iwl_set_bits_prph(trans, OSC_CLK, OSC_CLK_FORCE_CONTROL);
2164 ++ iwl_read_prph(trans, OSC_CLK);
2165 ++ iwl_read_prph(trans, OSC_CLK);
2166 ++ }
2167 ++
2168 + /*
2169 + * Enable DMA clock and wait for it to stabilize.
2170 + *
2171 +diff --git a/drivers/net/wireless/mwifiex/fw.h b/drivers/net/wireless/mwifiex/fw.h
2172 +index c8385ec77a86..7099b0e8add7 100644
2173 +--- a/drivers/net/wireless/mwifiex/fw.h
2174 ++++ b/drivers/net/wireless/mwifiex/fw.h
2175 +@@ -226,7 +226,7 @@ enum MWIFIEX_802_11_PRIVACY_FILTER {
2176 +
2177 + /* HW_SPEC fw_cap_info */
2178 +
2179 +-#define ISSUPP_11ACENABLED(fw_cap_info) (fw_cap_info & (BIT(13)|BIT(14)))
2180 ++#define ISSUPP_11ACENABLED(fw_cap_info) (fw_cap_info & (BIT(12)|BIT(13)))
2181 +
2182 + #define GET_VHTCAP_CHWDSET(vht_cap_info) ((vht_cap_info >> 2) & 0x3)
2183 + #define GET_VHTNSSMCS(mcs_mapset, nss) ((mcs_mapset >> (2 * (nss - 1))) & 0x3)
2184 +diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
2185 +index 8cf7d50a7603..ba48e64673d9 100644
2186 +--- a/drivers/net/wireless/mwifiex/scan.c
2187 ++++ b/drivers/net/wireless/mwifiex/scan.c
2188 +@@ -1681,7 +1681,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
2189 + const u8 *ie_buf;
2190 + size_t ie_len;
2191 + u16 channel = 0;
2192 +- u64 fw_tsf = 0;
2193 ++ __le64 fw_tsf = 0;
2194 + u16 beacon_size = 0;
2195 + u32 curr_bcn_bytes;
2196 + u32 freq;
2197 +@@ -1815,7 +1815,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
2198 + ie_buf, ie_len, rssi, GFP_KERNEL);
2199 + bss_priv = (struct mwifiex_bss_priv *)bss->priv;
2200 + bss_priv->band = band;
2201 +- bss_priv->fw_tsf = fw_tsf;
2202 ++ bss_priv->fw_tsf = le64_to_cpu(fw_tsf);
2203 + if (priv->media_connected &&
2204 + !memcmp(bssid,
2205 + priv->curr_bss_params.bss_descriptor
2206 +diff --git a/drivers/net/wireless/rtlwifi/base.c b/drivers/net/wireless/rtlwifi/base.c
2207 +index ff784072fb42..fcf9b621918c 100644
2208 +--- a/drivers/net/wireless/rtlwifi/base.c
2209 ++++ b/drivers/net/wireless/rtlwifi/base.c
2210 +@@ -1437,7 +1437,8 @@ void rtl_watchdog_wq_callback(void *data)
2211 + /* if we can't recv beacon for 6s, we should
2212 + * reconnect this AP
2213 + */
2214 +- if (rtlpriv->link_info.roam_times >= 3) {
2215 ++ if ((rtlpriv->link_info.roam_times >= 3) &&
2216 ++ !is_zero_ether_addr(rtlpriv->mac80211.bssid)) {
2217 + RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
2218 + "AP off, try to reconnect now\n");
2219 + rtlpriv->link_info.roam_times = 0;
2220 +diff --git a/drivers/net/wireless/rtlwifi/core.c b/drivers/net/wireless/rtlwifi/core.c
2221 +index 210ce7cd94d8..2d337a0c3df0 100644
2222 +--- a/drivers/net/wireless/rtlwifi/core.c
2223 ++++ b/drivers/net/wireless/rtlwifi/core.c
2224 +@@ -46,10 +46,20 @@ void rtl_fw_cb(const struct firmware *firmware, void *context)
2225 + "Firmware callback routine entered!\n");
2226 + complete(&rtlpriv->firmware_loading_complete);
2227 + if (!firmware) {
2228 ++ if (rtlpriv->cfg->alt_fw_name) {
2229 ++ err = request_firmware(&firmware,
2230 ++ rtlpriv->cfg->alt_fw_name,
2231 ++ rtlpriv->io.dev);
2232 ++ pr_info("Loading alternative firmware %s\n",
2233 ++ rtlpriv->cfg->alt_fw_name);
2234 ++ if (!err)
2235 ++ goto found_alt;
2236 ++ }
2237 + pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name);
2238 + rtlpriv->max_fw_size = 0;
2239 + return;
2240 + }
2241 ++found_alt:
2242 + if (firmware->size > rtlpriv->max_fw_size) {
2243 + RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
2244 + "Firmware is too big!\n");
2245 +@@ -184,6 +194,7 @@ static int rtl_op_add_interface(struct ieee80211_hw *hw,
2246 + rtlpriv->cfg->maps
2247 + [RTL_IBSS_INT_MASKS]);
2248 + }
2249 ++ mac->link_state = MAC80211_LINKED;
2250 + break;
2251 + case NL80211_IFTYPE_ADHOC:
2252 + RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
2253 +diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/dm.c b/drivers/net/wireless/rtlwifi/rtl8188ee/dm.c
2254 +index 21a5cf060677..a6184b6e1d57 100644
2255 +--- a/drivers/net/wireless/rtlwifi/rtl8188ee/dm.c
2256 ++++ b/drivers/net/wireless/rtlwifi/rtl8188ee/dm.c
2257 +@@ -1078,7 +1078,7 @@ static void rtl88e_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
2258 + rtldm->swing_flag_ofdm = true;
2259 + }
2260 +
2261 +- if (rtldm->swing_idx_cck != rtldm->swing_idx_cck) {
2262 ++ if (rtldm->swing_idx_cck_cur != rtldm->swing_idx_cck) {
2263 + rtldm->swing_idx_cck_cur = rtldm->swing_idx_cck;
2264 + rtldm->swing_flag_cck = true;
2265 + }
2266 +diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
2267 +index e9caa5d4cff0..fd7e4a7c94de 100644
2268 +--- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
2269 ++++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
2270 +@@ -158,6 +158,42 @@ static const u8 cckswing_table_ch14[CCK_TABLE_SIZE][8] = {
2271 + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}
2272 + };
2273 +
2274 ++static u32 power_index_reg[6] = {0xc90, 0xc91, 0xc92, 0xc98, 0xc99, 0xc9a};
2275 ++
2276 ++void dm_restorepowerindex(struct ieee80211_hw *hw)
2277 ++{
2278 ++ struct rtl_priv *rtlpriv = rtl_priv(hw);
2279 ++ u8 index;
2280 ++
2281 ++ for (index = 0; index < 6; index++)
2282 ++ rtl_write_byte(rtlpriv, power_index_reg[index],
2283 ++ rtlpriv->dm.powerindex_backup[index]);
2284 ++}
2285 ++EXPORT_SYMBOL_GPL(dm_restorepowerindex);
2286 ++
2287 ++void dm_writepowerindex(struct ieee80211_hw *hw, u8 value)
2288 ++{
2289 ++ struct rtl_priv *rtlpriv = rtl_priv(hw);
2290 ++ u8 index;
2291 ++
2292 ++ for (index = 0; index < 6; index++)
2293 ++ rtl_write_byte(rtlpriv, power_index_reg[index], value);
2294 ++}
2295 ++EXPORT_SYMBOL_GPL(dm_writepowerindex);
2296 ++
2297 ++void dm_savepowerindex(struct ieee80211_hw *hw)
2298 ++{
2299 ++ struct rtl_priv *rtlpriv = rtl_priv(hw);
2300 ++ u8 index;
2301 ++ u8 tmp;
2302 ++
2303 ++ for (index = 0; index < 6; index++) {
2304 ++ tmp = rtl_read_byte(rtlpriv, power_index_reg[index]);
2305 ++ rtlpriv->dm.powerindex_backup[index] = tmp;
2306 ++ }
2307 ++}
2308 ++EXPORT_SYMBOL_GPL(dm_savepowerindex);
2309 ++
2310 + static void rtl92c_dm_diginit(struct ieee80211_hw *hw)
2311 + {
2312 + struct rtl_priv *rtlpriv = rtl_priv(hw);
2313 +@@ -180,7 +216,12 @@ static void rtl92c_dm_diginit(struct ieee80211_hw *hw)
2314 + dm_digtable->back_range_max = DM_DIG_BACKOFF_MAX;
2315 + dm_digtable->back_range_min = DM_DIG_BACKOFF_MIN;
2316 + dm_digtable->pre_cck_pd_state = CCK_PD_STAGE_MAX;
2317 +- dm_digtable->cur_cck_pd_state = CCK_PD_STAGE_MAX;
2318 ++ dm_digtable->cur_cck_pd_state = CCK_PD_STAGE_LowRssi;
2319 ++
2320 ++ dm_digtable->forbidden_igi = DM_DIG_MIN;
2321 ++ dm_digtable->large_fa_hit = 0;
2322 ++ dm_digtable->recover_cnt = 0;
2323 ++ dm_digtable->dig_dynamic_min = 0x25;
2324 + }
2325 +
2326 + static u8 rtl92c_dm_initial_gain_min_pwdb(struct ieee80211_hw *hw)
2327 +@@ -206,7 +247,9 @@ static u8 rtl92c_dm_initial_gain_min_pwdb(struct ieee80211_hw *hw)
2328 + rssi_val_min = rtlpriv->dm.entry_min_undec_sm_pwdb;
2329 + }
2330 +
2331 +- return (u8) rssi_val_min;
2332 ++ if (rssi_val_min > 100)
2333 ++ rssi_val_min = 100;
2334 ++ return (u8)rssi_val_min;
2335 + }
2336 +
2337 + static void rtl92c_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw)
2338 +@@ -224,9 +267,17 @@ static void rtl92c_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw)
2339 +
2340 + ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER3, MASKDWORD);
2341 + falsealm_cnt->cnt_mcs_fail = (ret_value & 0xffff);
2342 ++
2343 ++ ret_value = rtl_get_bbreg(hw, ROFDM0_FRAMESYNC, MASKDWORD);
2344 ++ falsealm_cnt->cnt_fast_fsync_fail = (ret_value & 0xffff);
2345 ++ falsealm_cnt->cnt_sb_search_fail = ((ret_value & 0xffff0000) >> 16);
2346 ++
2347 + falsealm_cnt->cnt_ofdm_fail = falsealm_cnt->cnt_parity_fail +
2348 +- falsealm_cnt->cnt_rate_illegal +
2349 +- falsealm_cnt->cnt_crc8_fail + falsealm_cnt->cnt_mcs_fail;
2350 ++ falsealm_cnt->cnt_rate_illegal +
2351 ++ falsealm_cnt->cnt_crc8_fail +
2352 ++ falsealm_cnt->cnt_mcs_fail +
2353 ++ falsealm_cnt->cnt_fast_fsync_fail +
2354 ++ falsealm_cnt->cnt_sb_search_fail;
2355 +
2356 + rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, BIT(14), 1);
2357 + ret_value = rtl_get_bbreg(hw, RCCK0_FACOUNTERLOWER, MASKBYTE0);
2358 +@@ -271,12 +322,14 @@ static void rtl92c_dm_ctrl_initgain_by_fa(struct ieee80211_hw *hw)
2359 + value_igi++;
2360 + else if (rtlpriv->falsealm_cnt.cnt_all >= DM_DIG_FA_TH2)
2361 + value_igi += 2;
2362 ++
2363 + if (value_igi > DM_DIG_FA_UPPER)
2364 + value_igi = DM_DIG_FA_UPPER;
2365 + else if (value_igi < DM_DIG_FA_LOWER)
2366 + value_igi = DM_DIG_FA_LOWER;
2367 ++
2368 + if (rtlpriv->falsealm_cnt.cnt_all > 10000)
2369 +- value_igi = 0x32;
2370 ++ value_igi = DM_DIG_FA_UPPER;
2371 +
2372 + dm_digtable->cur_igvalue = value_igi;
2373 + rtl92c_dm_write_dig(hw);
2374 +@@ -286,32 +339,80 @@ static void rtl92c_dm_ctrl_initgain_by_rssi(struct ieee80211_hw *hw)
2375 + {
2376 + struct rtl_priv *rtlpriv = rtl_priv(hw);
2377 + struct dig_t *digtable = &rtlpriv->dm_digtable;
2378 ++ u32 isbt;
2379 ++
2380 ++ /* modify DIG lower bound, deal with abnorally large false alarm */
2381 ++ if (rtlpriv->falsealm_cnt.cnt_all > 10000) {
2382 ++ digtable->large_fa_hit++;
2383 ++ if (digtable->forbidden_igi < digtable->cur_igvalue) {
2384 ++ digtable->forbidden_igi = digtable->cur_igvalue;
2385 ++ digtable->large_fa_hit = 1;
2386 ++ }
2387 +
2388 +- if (rtlpriv->falsealm_cnt.cnt_all > digtable->fa_highthresh) {
2389 +- if ((digtable->back_val - 2) < digtable->back_range_min)
2390 +- digtable->back_val = digtable->back_range_min;
2391 +- else
2392 +- digtable->back_val -= 2;
2393 +- } else if (rtlpriv->falsealm_cnt.cnt_all < digtable->fa_lowthresh) {
2394 +- if ((digtable->back_val + 2) > digtable->back_range_max)
2395 +- digtable->back_val = digtable->back_range_max;
2396 +- else
2397 +- digtable->back_val += 2;
2398 ++ if (digtable->large_fa_hit >= 3) {
2399 ++ if ((digtable->forbidden_igi + 1) >
2400 ++ digtable->rx_gain_max)
2401 ++ digtable->rx_gain_min = digtable->rx_gain_max;
2402 ++ else
2403 ++ digtable->rx_gain_min = (digtable->forbidden_igi + 1);
2404 ++ digtable->recover_cnt = 3600; /* 3600=2hr */
2405 ++ }
2406 ++ } else {
2407 ++ /* Recovery mechanism for IGI lower bound */
2408 ++ if (digtable->recover_cnt != 0) {
2409 ++ digtable->recover_cnt--;
2410 ++ } else {
2411 ++ if (digtable->large_fa_hit == 0) {
2412 ++ if ((digtable->forbidden_igi-1) < DM_DIG_MIN) {
2413 ++ digtable->forbidden_igi = DM_DIG_MIN;
2414 ++ digtable->rx_gain_min = DM_DIG_MIN;
2415 ++ } else {
2416 ++ digtable->forbidden_igi--;
2417 ++ digtable->rx_gain_min = digtable->forbidden_igi + 1;
2418 ++ }
2419 ++ } else if (digtable->large_fa_hit == 3) {
2420 ++ digtable->large_fa_hit = 0;
2421 ++ }
2422 ++ }
2423 ++ }
2424 ++ if (rtlpriv->falsealm_cnt.cnt_all < 250) {
2425 ++ isbt = rtl_read_byte(rtlpriv, 0x4fd) & 0x01;
2426 ++
2427 ++ if (!isbt) {
2428 ++ if (rtlpriv->falsealm_cnt.cnt_all >
2429 ++ digtable->fa_lowthresh) {
2430 ++ if ((digtable->back_val - 2) <
2431 ++ digtable->back_range_min)
2432 ++ digtable->back_val = digtable->back_range_min;
2433 ++ else
2434 ++ digtable->back_val -= 2;
2435 ++ } else if (rtlpriv->falsealm_cnt.cnt_all <
2436 ++ digtable->fa_lowthresh) {
2437 ++ if ((digtable->back_val + 2) >
2438 ++ digtable->back_range_max)
2439 ++ digtable->back_val = digtable->back_range_max;
2440 ++ else
2441 ++ digtable->back_val += 2;
2442 ++ }
2443 ++ } else {
2444 ++ digtable->back_val = DM_DIG_BACKOFF_DEFAULT;
2445 ++ }
2446 ++ } else {
2447 ++ /* Adjust initial gain by false alarm */
2448 ++ if (rtlpriv->falsealm_cnt.cnt_all > 1000)
2449 ++ digtable->cur_igvalue = digtable->pre_igvalue + 2;
2450 ++ else if (rtlpriv->falsealm_cnt.cnt_all > 750)
2451 ++ digtable->cur_igvalue = digtable->pre_igvalue + 1;
2452 ++ else if (rtlpriv->falsealm_cnt.cnt_all < 500)
2453 ++ digtable->cur_igvalue = digtable->pre_igvalue - 1;
2454 + }
2455 +
2456 +- if ((digtable->rssi_val_min + 10 - digtable->back_val) >
2457 +- digtable->rx_gain_max)
2458 ++ /* Check initial gain by upper/lower bound */
2459 ++ if (digtable->cur_igvalue > digtable->rx_gain_max)
2460 + digtable->cur_igvalue = digtable->rx_gain_max;
2461 +- else if ((digtable->rssi_val_min + 10 -
2462 +- digtable->back_val) < digtable->rx_gain_min)
2463 +- digtable->cur_igvalue = digtable->rx_gain_min;
2464 +- else
2465 +- digtable->cur_igvalue = digtable->rssi_val_min + 10 -
2466 +- digtable->back_val;
2467 +
2468 +- RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE,
2469 +- "rssi_val_min = %x back_val %x\n",
2470 +- digtable->rssi_val_min, digtable->back_val);
2471 ++ if (digtable->cur_igvalue < digtable->rx_gain_min)
2472 ++ digtable->cur_igvalue = digtable->rx_gain_min;
2473 +
2474 + rtl92c_dm_write_dig(hw);
2475 + }
2476 +@@ -329,7 +430,7 @@ static void rtl92c_dm_initial_gain_multi_sta(struct ieee80211_hw *hw)
2477 + multi_sta = true;
2478 +
2479 + if (!multi_sta ||
2480 +- dm_digtable->cursta_cstate != DIG_STA_DISCONNECT) {
2481 ++ dm_digtable->cursta_cstate == DIG_STA_DISCONNECT) {
2482 + initialized = false;
2483 + dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX;
2484 + return;
2485 +@@ -375,7 +476,6 @@ static void rtl92c_dm_initial_gain_sta(struct ieee80211_hw *hw)
2486 + RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE,
2487 + "presta_cstate = %x, cursta_cstate = %x\n",
2488 + dm_digtable->presta_cstate, dm_digtable->cursta_cstate);
2489 +-
2490 + if (dm_digtable->presta_cstate == dm_digtable->cursta_cstate ||
2491 + dm_digtable->cursta_cstate == DIG_STA_BEFORE_CONNECT ||
2492 + dm_digtable->cursta_cstate == DIG_STA_CONNECT) {
2493 +@@ -383,6 +483,8 @@ static void rtl92c_dm_initial_gain_sta(struct ieee80211_hw *hw)
2494 + if (dm_digtable->cursta_cstate != DIG_STA_DISCONNECT) {
2495 + dm_digtable->rssi_val_min =
2496 + rtl92c_dm_initial_gain_min_pwdb(hw);
2497 ++ if (dm_digtable->rssi_val_min > 100)
2498 ++ dm_digtable->rssi_val_min = 100;
2499 + rtl92c_dm_ctrl_initgain_by_rssi(hw);
2500 + }
2501 + } else {
2502 +@@ -398,11 +500,12 @@ static void rtl92c_dm_initial_gain_sta(struct ieee80211_hw *hw)
2503 + static void rtl92c_dm_cck_packet_detection_thresh(struct ieee80211_hw *hw)
2504 + {
2505 + struct rtl_priv *rtlpriv = rtl_priv(hw);
2506 +- struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2507 + struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
2508 +
2509 + if (dm_digtable->cursta_cstate == DIG_STA_CONNECT) {
2510 + dm_digtable->rssi_val_min = rtl92c_dm_initial_gain_min_pwdb(hw);
2511 ++ if (dm_digtable->rssi_val_min > 100)
2512 ++ dm_digtable->rssi_val_min = 100;
2513 +
2514 + if (dm_digtable->pre_cck_pd_state == CCK_PD_STAGE_LowRssi) {
2515 + if (dm_digtable->rssi_val_min <= 25)
2516 +@@ -424,48 +527,14 @@ static void rtl92c_dm_cck_packet_detection_thresh(struct ieee80211_hw *hw)
2517 + }
2518 +
2519 + if (dm_digtable->pre_cck_pd_state != dm_digtable->cur_cck_pd_state) {
2520 +- if (dm_digtable->cur_cck_pd_state == CCK_PD_STAGE_LowRssi) {
2521 +- if (rtlpriv->falsealm_cnt.cnt_cck_fail > 800)
2522 +- dm_digtable->cur_cck_fa_state =
2523 +- CCK_FA_STAGE_High;
2524 +- else
2525 +- dm_digtable->cur_cck_fa_state = CCK_FA_STAGE_Low;
2526 +-
2527 +- if (dm_digtable->pre_cck_fa_state !=
2528 +- dm_digtable->cur_cck_fa_state) {
2529 +- if (dm_digtable->cur_cck_fa_state ==
2530 +- CCK_FA_STAGE_Low)
2531 +- rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2,
2532 +- 0x83);
2533 +- else
2534 +- rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2,
2535 +- 0xcd);
2536 +-
2537 +- dm_digtable->pre_cck_fa_state =
2538 +- dm_digtable->cur_cck_fa_state;
2539 +- }
2540 +-
2541 +- rtl_set_bbreg(hw, RCCK0_SYSTEM, MASKBYTE1, 0x40);
2542 +-
2543 +- if (IS_92C_SERIAL(rtlhal->version))
2544 +- rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT,
2545 +- MASKBYTE2, 0xd7);
2546 +- } else {
2547 ++ if ((dm_digtable->cur_cck_pd_state == CCK_PD_STAGE_LowRssi) ||
2548 ++ (dm_digtable->cur_cck_pd_state == CCK_PD_STAGE_MAX))
2549 ++ rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, 0x83);
2550 ++ else
2551 + rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, 0xcd);
2552 +- rtl_set_bbreg(hw, RCCK0_SYSTEM, MASKBYTE1, 0x47);
2553 +
2554 +- if (IS_92C_SERIAL(rtlhal->version))
2555 +- rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT,
2556 +- MASKBYTE2, 0xd3);
2557 +- }
2558 + dm_digtable->pre_cck_pd_state = dm_digtable->cur_cck_pd_state;
2559 + }
2560 +-
2561 +- RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, "CCKPDStage=%x\n",
2562 +- dm_digtable->cur_cck_pd_state);
2563 +-
2564 +- RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, "is92C=%x\n",
2565 +- IS_92C_SERIAL(rtlhal->version));
2566 + }
2567 +
2568 + static void rtl92c_dm_ctrl_initgain_by_twoport(struct ieee80211_hw *hw)
2569 +@@ -482,6 +551,8 @@ static void rtl92c_dm_ctrl_initgain_by_twoport(struct ieee80211_hw *hw)
2570 + else
2571 + dm_digtable->cursta_cstate = DIG_STA_DISCONNECT;
2572 +
2573 ++ dm_digtable->curmultista_cstate = DIG_MULTISTA_DISCONNECT;
2574 ++
2575 + rtl92c_dm_initial_gain_sta(hw);
2576 + rtl92c_dm_initial_gain_multi_sta(hw);
2577 + rtl92c_dm_cck_packet_detection_thresh(hw);
2578 +@@ -493,23 +564,26 @@ static void rtl92c_dm_ctrl_initgain_by_twoport(struct ieee80211_hw *hw)
2579 + static void rtl92c_dm_dig(struct ieee80211_hw *hw)
2580 + {
2581 + struct rtl_priv *rtlpriv = rtl_priv(hw);
2582 +- struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
2583 +
2584 + if (rtlpriv->dm.dm_initialgain_enable == false)
2585 + return;
2586 +- if (dm_digtable->dig_enable_flag == false)
2587 ++ if (!rtlpriv->dm.dm_flag & DYNAMIC_FUNC_DIG)
2588 + return;
2589 +
2590 + rtl92c_dm_ctrl_initgain_by_twoport(hw);
2591 +-
2592 + }
2593 +
2594 + static void rtl92c_dm_init_dynamic_txpower(struct ieee80211_hw *hw)
2595 + {
2596 + struct rtl_priv *rtlpriv = rtl_priv(hw);
2597 +
2598 +- rtlpriv->dm.dynamic_txpower_enable = false;
2599 +-
2600 ++ if (rtlpriv->rtlhal.interface == INTF_USB &&
2601 ++ rtlpriv->rtlhal.board_type & 0x1) {
2602 ++ dm_savepowerindex(hw);
2603 ++ rtlpriv->dm.dynamic_txpower_enable = true;
2604 ++ } else {
2605 ++ rtlpriv->dm.dynamic_txpower_enable = false;
2606 ++ }
2607 + rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
2608 + rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
2609 + }
2610 +@@ -524,9 +598,14 @@ void rtl92c_dm_write_dig(struct ieee80211_hw *hw)
2611 + dm_digtable->cur_igvalue, dm_digtable->pre_igvalue,
2612 + dm_digtable->back_val);
2613 +
2614 +- dm_digtable->cur_igvalue += 2;
2615 +- if (dm_digtable->cur_igvalue > 0x3f)
2616 +- dm_digtable->cur_igvalue = 0x3f;
2617 ++ if (rtlpriv->rtlhal.interface == INTF_USB &&
2618 ++ !dm_digtable->dig_enable_flag) {
2619 ++ dm_digtable->pre_igvalue = 0x17;
2620 ++ return;
2621 ++ }
2622 ++ dm_digtable->cur_igvalue -= 1;
2623 ++ if (dm_digtable->cur_igvalue < DM_DIG_MIN)
2624 ++ dm_digtable->cur_igvalue = DM_DIG_MIN;
2625 +
2626 + if (dm_digtable->pre_igvalue != dm_digtable->cur_igvalue) {
2627 + rtl_set_bbreg(hw, ROFDM0_XAAGCCORE1, 0x7f,
2628 +@@ -536,11 +615,47 @@ void rtl92c_dm_write_dig(struct ieee80211_hw *hw)
2629 +
2630 + dm_digtable->pre_igvalue = dm_digtable->cur_igvalue;
2631 + }
2632 ++ RT_TRACE(rtlpriv, COMP_DIG, DBG_WARNING,
2633 ++ "dig values 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
2634 ++ dm_digtable->cur_igvalue, dm_digtable->pre_igvalue,
2635 ++ dm_digtable->rssi_val_min, dm_digtable->back_val,
2636 ++ dm_digtable->rx_gain_max, dm_digtable->rx_gain_min,
2637 ++ dm_digtable->large_fa_hit, dm_digtable->forbidden_igi);
2638 + }
2639 + EXPORT_SYMBOL(rtl92c_dm_write_dig);
2640 +
2641 + static void rtl92c_dm_pwdb_monitor(struct ieee80211_hw *hw)
2642 + {
2643 ++ struct rtl_priv *rtlpriv = rtl_priv(hw);
2644 ++ struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2645 ++ long tmpentry_max_pwdb = 0, tmpentry_min_pwdb = 0xff;
2646 ++
2647 ++ if (mac->link_state != MAC80211_LINKED)
2648 ++ return;
2649 ++
2650 ++ if (mac->opmode == NL80211_IFTYPE_ADHOC ||
2651 ++ mac->opmode == NL80211_IFTYPE_AP) {
2652 ++ /* TODO: Handle ADHOC and AP Mode */
2653 ++ }
2654 ++
2655 ++ if (tmpentry_max_pwdb != 0)
2656 ++ rtlpriv->dm.entry_max_undec_sm_pwdb = tmpentry_max_pwdb;
2657 ++ else
2658 ++ rtlpriv->dm.entry_max_undec_sm_pwdb = 0;
2659 ++
2660 ++ if (tmpentry_min_pwdb != 0xff)
2661 ++ rtlpriv->dm.entry_min_undec_sm_pwdb = tmpentry_min_pwdb;
2662 ++ else
2663 ++ rtlpriv->dm.entry_min_undec_sm_pwdb = 0;
2664 ++
2665 ++/* TODO:
2666 ++ * if (mac->opmode == NL80211_IFTYPE_STATION) {
2667 ++ * if (rtlpriv->rtlhal.fw_ready) {
2668 ++ * u32 param = (u32)(rtlpriv->dm.undec_sm_pwdb << 16);
2669 ++ * rtl8192c_set_rssi_cmd(hw, param);
2670 ++ * }
2671 ++ * }
2672 ++ */
2673 + }
2674 +
2675 + void rtl92c_dm_init_edca_turbo(struct ieee80211_hw *hw)
2676 +@@ -750,6 +865,7 @@ static void rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
2677 + rtlpriv->dm.ofdm_index[i] = ofdm_index_old[i];
2678 + rtlpriv->dm.cck_index = cck_index_old;
2679 + }
2680 ++ /* Handle USB High PA boards */
2681 +
2682 + delta = (thermalvalue > rtlpriv->dm.thermalvalue) ?
2683 + (thermalvalue - rtlpriv->dm.thermalvalue) :
2684 +@@ -1140,22 +1256,22 @@ void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal)
2685 + {
2686 + struct rtl_priv *rtlpriv = rtl_priv(hw);
2687 + struct ps_t *dm_pstable = &rtlpriv->dm_pstable;
2688 +- static u8 initialize;
2689 +- static u32 reg_874, reg_c70, reg_85c, reg_a74;
2690 +
2691 +- if (initialize == 0) {
2692 +- reg_874 = (rtl_get_bbreg(hw, RFPGA0_XCD_RFINTERFACESW,
2693 +- MASKDWORD) & 0x1CC000) >> 14;
2694 ++ if (!rtlpriv->reg_init) {
2695 ++ rtlpriv->reg_874 = (rtl_get_bbreg(hw,
2696 ++ RFPGA0_XCD_RFINTERFACESW,
2697 ++ MASKDWORD) & 0x1CC000) >> 14;
2698 +
2699 +- reg_c70 = (rtl_get_bbreg(hw, ROFDM0_AGCPARAMETER1,
2700 +- MASKDWORD) & BIT(3)) >> 3;
2701 ++ rtlpriv->reg_c70 = (rtl_get_bbreg(hw, ROFDM0_AGCPARAMETER1,
2702 ++ MASKDWORD) & BIT(3)) >> 3;
2703 +
2704 +- reg_85c = (rtl_get_bbreg(hw, RFPGA0_XCD_SWITCHCONTROL,
2705 +- MASKDWORD) & 0xFF000000) >> 24;
2706 ++ rtlpriv->reg_85c = (rtl_get_bbreg(hw, RFPGA0_XCD_SWITCHCONTROL,
2707 ++ MASKDWORD) & 0xFF000000) >> 24;
2708 +
2709 +- reg_a74 = (rtl_get_bbreg(hw, 0xa74, MASKDWORD) & 0xF000) >> 12;
2710 ++ rtlpriv->reg_a74 = (rtl_get_bbreg(hw, 0xa74, MASKDWORD) &
2711 ++ 0xF000) >> 12;
2712 +
2713 +- initialize = 1;
2714 ++ rtlpriv->reg_init = true;
2715 + }
2716 +
2717 + if (!bforce_in_normal) {
2718 +@@ -1192,12 +1308,12 @@ void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal)
2719 + rtl_set_bbreg(hw, 0x818, BIT(28), 0x1);
2720 + } else {
2721 + rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW,
2722 +- 0x1CC000, reg_874);
2723 ++ 0x1CC000, rtlpriv->reg_874);
2724 + rtl_set_bbreg(hw, ROFDM0_AGCPARAMETER1, BIT(3),
2725 +- reg_c70);
2726 ++ rtlpriv->reg_c70);
2727 + rtl_set_bbreg(hw, RFPGA0_XCD_SWITCHCONTROL, 0xFF000000,
2728 +- reg_85c);
2729 +- rtl_set_bbreg(hw, 0xa74, 0xF000, reg_a74);
2730 ++ rtlpriv->reg_85c);
2731 ++ rtl_set_bbreg(hw, 0xa74, 0xF000, rtlpriv->reg_a74);
2732 + rtl_set_bbreg(hw, 0x818, BIT(28), 0x0);
2733 + }
2734 +
2735 +@@ -1213,6 +1329,7 @@ static void rtl92c_dm_dynamic_bb_powersaving(struct ieee80211_hw *hw)
2736 + struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2737 + struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2738 +
2739 ++ /* Determine the minimum RSSI */
2740 + if (((mac->link_state == MAC80211_NOLINK)) &&
2741 + (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) {
2742 + dm_pstable->rssi_val_min = 0;
2743 +@@ -1241,6 +1358,7 @@ static void rtl92c_dm_dynamic_bb_powersaving(struct ieee80211_hw *hw)
2744 + dm_pstable->rssi_val_min);
2745 + }
2746 +
2747 ++ /* Power Saving for 92C */
2748 + if (IS_92C_SERIAL(rtlhal->version))
2749 + ;/* rtl92c_dm_1r_cca(hw); */
2750 + else
2751 +@@ -1252,12 +1370,23 @@ void rtl92c_dm_init(struct ieee80211_hw *hw)
2752 + struct rtl_priv *rtlpriv = rtl_priv(hw);
2753 +
2754 + rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER;
2755 ++ rtlpriv->dm.dm_flag = DYNAMIC_FUNC_DISABLE | DYNAMIC_FUNC_DIG;
2756 ++ rtlpriv->dm.undec_sm_pwdb = -1;
2757 ++ rtlpriv->dm.undec_sm_cck = -1;
2758 ++ rtlpriv->dm.dm_initialgain_enable = true;
2759 + rtl92c_dm_diginit(hw);
2760 ++
2761 ++ rtlpriv->dm.dm_flag |= HAL_DM_HIPWR_DISABLE;
2762 + rtl92c_dm_init_dynamic_txpower(hw);
2763 ++
2764 + rtl92c_dm_init_edca_turbo(hw);
2765 + rtl92c_dm_init_rate_adaptive_mask(hw);
2766 ++ rtlpriv->dm.dm_flag |= DYNAMIC_FUNC_SS;
2767 + rtl92c_dm_initialize_txpower_tracking(hw);
2768 + rtl92c_dm_init_dynamic_bb_powersaving(hw);
2769 ++
2770 ++ rtlpriv->dm.ofdm_pkt_cnt = 0;
2771 ++ rtlpriv->dm.dm_rssi_sel = RSSI_DEFAULT;
2772 + }
2773 + EXPORT_SYMBOL(rtl92c_dm_init);
2774 +
2775 +@@ -1308,7 +1437,7 @@ void rtl92c_dm_dynamic_txpower(struct ieee80211_hw *hw)
2776 + }
2777 +
2778 + if (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) {
2779 +- rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
2780 ++ rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL2;
2781 + RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
2782 + "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
2783 + } else if ((undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) &&
2784 +@@ -1328,8 +1457,16 @@ void rtl92c_dm_dynamic_txpower(struct ieee80211_hw *hw)
2785 + "PHY_SetTxPowerLevel8192S() Channel = %d\n",
2786 + rtlphy->current_channel);
2787 + rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
2788 ++ if (rtlpriv->dm.dynamic_txhighpower_lvl ==
2789 ++ TXHIGHPWRLEVEL_NORMAL)
2790 ++ dm_restorepowerindex(hw);
2791 ++ else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
2792 ++ TXHIGHPWRLEVEL_LEVEL1)
2793 ++ dm_writepowerindex(hw, 0x14);
2794 ++ else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
2795 ++ TXHIGHPWRLEVEL_LEVEL2)
2796 ++ dm_writepowerindex(hw, 0x10);
2797 + }
2798 +-
2799 + rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
2800 + }
2801 +
2802 +@@ -1400,12 +1537,6 @@ u8 rtl92c_bt_rssi_state_change(struct ieee80211_hw *hw)
2803 + else
2804 + curr_bt_rssi_state &= (~BT_RSSI_STATE_SPECIAL_LOW);
2805 +
2806 +- /* Set Tx Power according to BT status. */
2807 +- if (undec_sm_pwdb >= 30)
2808 +- curr_bt_rssi_state |= BT_RSSI_STATE_TXPOWER_LOW;
2809 +- else if (undec_sm_pwdb < 25)
2810 +- curr_bt_rssi_state &= (~BT_RSSI_STATE_TXPOWER_LOW);
2811 +-
2812 + /* Check BT state related to BT_Idle in B/G mode. */
2813 + if (undec_sm_pwdb < 15)
2814 + curr_bt_rssi_state |= BT_RSSI_STATE_BG_EDCA_LOW;
2815 +diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h
2816 +index 518e208c0180..4f232a063636 100644
2817 +--- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h
2818 ++++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h
2819 +@@ -91,6 +91,17 @@
2820 + #define TX_POWER_NEAR_FIELD_THRESH_LVL2 74
2821 + #define TX_POWER_NEAR_FIELD_THRESH_LVL1 67
2822 +
2823 ++#define DYNAMIC_FUNC_DISABLE 0x0
2824 ++#define DYNAMIC_FUNC_DIG BIT(0)
2825 ++#define DYNAMIC_FUNC_HP BIT(1)
2826 ++#define DYNAMIC_FUNC_SS BIT(2) /*Tx Power Tracking*/
2827 ++#define DYNAMIC_FUNC_BT BIT(3)
2828 ++#define DYNAMIC_FUNC_ANT_DIV BIT(4)
2829 ++
2830 ++#define RSSI_CCK 0
2831 ++#define RSSI_OFDM 1
2832 ++#define RSSI_DEFAULT 2
2833 ++
2834 + struct swat_t {
2835 + u8 failure_cnt;
2836 + u8 try_flag;
2837 +@@ -167,5 +178,8 @@ void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw);
2838 + void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool recovery);
2839 + void rtl92c_dm_dynamic_txpower(struct ieee80211_hw *hw);
2840 + void rtl92c_dm_bt_coexist(struct ieee80211_hw *hw);
2841 ++void dm_savepowerindex(struct ieee80211_hw *hw);
2842 ++void dm_writepowerindex(struct ieee80211_hw *hw, u8 value);
2843 ++void dm_restorepowerindex(struct ieee80211_hw *hw);
2844 +
2845 + #endif
2846 +diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/dm.c b/drivers/net/wireless/rtlwifi/rtl8192cu/dm.c
2847 +index 16a0b9e59acf..c16209a336ea 100644
2848 +--- a/drivers/net/wireless/rtlwifi/rtl8192cu/dm.c
2849 ++++ b/drivers/net/wireless/rtlwifi/rtl8192cu/dm.c
2850 +@@ -101,6 +101,15 @@ void rtl92cu_dm_dynamic_txpower(struct ieee80211_hw *hw)
2851 + "PHY_SetTxPowerLevel8192S() Channel = %d\n",
2852 + rtlphy->current_channel);
2853 + rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
2854 ++ if (rtlpriv->dm.dynamic_txhighpower_lvl ==
2855 ++ TXHIGHPWRLEVEL_NORMAL)
2856 ++ dm_restorepowerindex(hw);
2857 ++ else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
2858 ++ TXHIGHPWRLEVEL_LEVEL1)
2859 ++ dm_writepowerindex(hw, 0x14);
2860 ++ else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
2861 ++ TXHIGHPWRLEVEL_LEVEL2)
2862 ++ dm_writepowerindex(hw, 0x10);
2863 + }
2864 +
2865 + rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
2866 +diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/dm.h b/drivers/net/wireless/rtlwifi/rtl8192cu/dm.h
2867 +index d947e7d350bb..fafa6bac2a3f 100644
2868 +--- a/drivers/net/wireless/rtlwifi/rtl8192cu/dm.h
2869 ++++ b/drivers/net/wireless/rtlwifi/rtl8192cu/dm.h
2870 +@@ -30,3 +30,6 @@
2871 + #include "../rtl8192ce/dm.h"
2872 +
2873 + void rtl92cu_dm_dynamic_txpower(struct ieee80211_hw *hw);
2874 ++void dm_savepowerindex(struct ieee80211_hw *hw);
2875 ++void dm_writepowerindex(struct ieee80211_hw *hw, u8 value);
2876 ++void dm_restorepowerindex(struct ieee80211_hw *hw);
2877 +diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c b/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c
2878 +index 2119313a737b..b878d56d2f4d 100644
2879 +--- a/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c
2880 ++++ b/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c
2881 +@@ -85,17 +85,15 @@ void rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
2882 + if (mac->act_scanning) {
2883 + tx_agc[RF90_PATH_A] = 0x3f3f3f3f;
2884 + tx_agc[RF90_PATH_B] = 0x3f3f3f3f;
2885 +- if (turbo_scanoff) {
2886 +- for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
2887 +- tx_agc[idx1] = ppowerlevel[idx1] |
2888 +- (ppowerlevel[idx1] << 8) |
2889 +- (ppowerlevel[idx1] << 16) |
2890 +- (ppowerlevel[idx1] << 24);
2891 +- if (rtlhal->interface == INTF_USB) {
2892 +- if (tx_agc[idx1] > 0x20 &&
2893 +- rtlefuse->external_pa)
2894 +- tx_agc[idx1] = 0x20;
2895 +- }
2896 ++ for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
2897 ++ tx_agc[idx1] = ppowerlevel[idx1] |
2898 ++ (ppowerlevel[idx1] << 8) |
2899 ++ (ppowerlevel[idx1] << 16) |
2900 ++ (ppowerlevel[idx1] << 24);
2901 ++ if (rtlhal->interface == INTF_USB) {
2902 ++ if (tx_agc[idx1] > 0x20 &&
2903 ++ rtlefuse->external_pa)
2904 ++ tx_agc[idx1] = 0x20;
2905 + }
2906 + }
2907 + } else {
2908 +@@ -107,7 +105,7 @@ void rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
2909 + TXHIGHPWRLEVEL_LEVEL2) {
2910 + tx_agc[RF90_PATH_A] = 0x00000000;
2911 + tx_agc[RF90_PATH_B] = 0x00000000;
2912 +- } else{
2913 ++ } else {
2914 + for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
2915 + tx_agc[idx1] = ppowerlevel[idx1] |
2916 + (ppowerlevel[idx1] << 8) |
2917 +@@ -373,7 +371,12 @@ static void _rtl92c_write_ofdm_power_reg(struct ieee80211_hw *hw,
2918 + regoffset == RTXAGC_B_MCS07_MCS04)
2919 + regoffset = 0xc98;
2920 + for (i = 0; i < 3; i++) {
2921 +- writeVal = (writeVal > 6) ? (writeVal - 6) : 0;
2922 ++ if (i != 2)
2923 ++ writeVal = (writeVal > 8) ?
2924 ++ (writeVal - 8) : 0;
2925 ++ else
2926 ++ writeVal = (writeVal > 6) ?
2927 ++ (writeVal - 6) : 0;
2928 + rtl_write_byte(rtlpriv, (u32)(regoffset + i),
2929 + (u8)writeVal);
2930 + }
2931 +diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
2932 +index 9936de716ad5..c61311084d7e 100644
2933 +--- a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
2934 ++++ b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
2935 +@@ -50,6 +50,9 @@ MODULE_AUTHOR("Larry Finger <Larry.Finger@××××××××.net>");
2936 + MODULE_LICENSE("GPL");
2937 + MODULE_DESCRIPTION("Realtek 8192C/8188C 802.11n USB wireless");
2938 + MODULE_FIRMWARE("rtlwifi/rtl8192cufw.bin");
2939 ++MODULE_FIRMWARE("rtlwifi/rtl8192cufw_A.bin");
2940 ++MODULE_FIRMWARE("rtlwifi/rtl8192cufw_B.bin");
2941 ++MODULE_FIRMWARE("rtlwifi/rtl8192cufw_TMSC.bin");
2942 +
2943 + static int rtl92cu_init_sw_vars(struct ieee80211_hw *hw)
2944 + {
2945 +@@ -69,14 +72,21 @@ static int rtl92cu_init_sw_vars(struct ieee80211_hw *hw)
2946 + "Can't alloc buffer for fw\n");
2947 + return 1;
2948 + }
2949 +-
2950 ++ if (IS_VENDOR_UMC_A_CUT(rtlpriv->rtlhal.version) &&
2951 ++ !IS_92C_SERIAL(rtlpriv->rtlhal.version)) {
2952 ++ rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cufw_A.bin";
2953 ++ } else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlpriv->rtlhal.version)) {
2954 ++ rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cufw_B.bin";
2955 ++ } else {
2956 ++ rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cufw_TMSC.bin";
2957 ++ }
2958 ++ /* provide name of alternative file */
2959 ++ rtlpriv->cfg->alt_fw_name = "rtlwifi/rtl8192cufw.bin";
2960 + pr_info("Loading firmware %s\n", rtlpriv->cfg->fw_name);
2961 + rtlpriv->max_fw_size = 0x4000;
2962 + err = request_firmware_nowait(THIS_MODULE, 1,
2963 + rtlpriv->cfg->fw_name, rtlpriv->io.dev,
2964 + GFP_KERNEL, hw, rtl_fw_cb);
2965 +-
2966 +-
2967 + return err;
2968 + }
2969 +
2970 +@@ -307,6 +317,7 @@ static struct usb_device_id rtl8192c_usb_ids[] = {
2971 + {RTL_USB_DEVICE(0x0bda, 0x5088, rtl92cu_hal_cfg)}, /*Thinkware-CC&C*/
2972 + {RTL_USB_DEVICE(0x0df6, 0x0052, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/
2973 + {RTL_USB_DEVICE(0x0df6, 0x005c, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/
2974 ++ {RTL_USB_DEVICE(0x0df6, 0x0077, rtl92cu_hal_cfg)}, /*Sitecom-WLA2100V2*/
2975 + {RTL_USB_DEVICE(0x0eb0, 0x9071, rtl92cu_hal_cfg)}, /*NO Brand - Etop*/
2976 + {RTL_USB_DEVICE(0x4856, 0x0091, rtl92cu_hal_cfg)}, /*NetweeN - Feixun*/
2977 + /* HP - Lite-On ,8188CUS Slim Combo */
2978 +diff --git a/drivers/net/wireless/rtlwifi/stats.c b/drivers/net/wireless/rtlwifi/stats.c
2979 +index 8ed31744a054..4f083fc1d360 100644
2980 +--- a/drivers/net/wireless/rtlwifi/stats.c
2981 ++++ b/drivers/net/wireless/rtlwifi/stats.c
2982 +@@ -176,6 +176,7 @@ static void rtl_process_pwdb(struct ieee80211_hw *hw, struct rtl_stats *pstatus)
2983 + struct rtl_sta_info *drv_priv = NULL;
2984 + struct ieee80211_sta *sta = NULL;
2985 + long undec_sm_pwdb;
2986 ++ long undec_sm_cck;
2987 +
2988 + rcu_read_lock();
2989 + if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
2990 +@@ -185,12 +186,16 @@ static void rtl_process_pwdb(struct ieee80211_hw *hw, struct rtl_stats *pstatus)
2991 + if (sta) {
2992 + drv_priv = (struct rtl_sta_info *) sta->drv_priv;
2993 + undec_sm_pwdb = drv_priv->rssi_stat.undec_sm_pwdb;
2994 ++ undec_sm_cck = drv_priv->rssi_stat.undec_sm_cck;
2995 + } else {
2996 + undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
2997 ++ undec_sm_cck = rtlpriv->dm.undec_sm_cck;
2998 + }
2999 +
3000 + if (undec_sm_pwdb < 0)
3001 + undec_sm_pwdb = pstatus->rx_pwdb_all;
3002 ++ if (undec_sm_cck < 0)
3003 ++ undec_sm_cck = pstatus->rx_pwdb_all;
3004 + if (pstatus->rx_pwdb_all > (u32) undec_sm_pwdb) {
3005 + undec_sm_pwdb = (((undec_sm_pwdb) *
3006 + (RX_SMOOTH_FACTOR - 1)) +
3007 +@@ -200,6 +205,15 @@ static void rtl_process_pwdb(struct ieee80211_hw *hw, struct rtl_stats *pstatus)
3008 + undec_sm_pwdb = (((undec_sm_pwdb) * (RX_SMOOTH_FACTOR - 1)) +
3009 + (pstatus->rx_pwdb_all)) / (RX_SMOOTH_FACTOR);
3010 + }
3011 ++ if (pstatus->rx_pwdb_all > (u32) undec_sm_cck) {
3012 ++ undec_sm_cck = (((undec_sm_pwdb) *
3013 ++ (RX_SMOOTH_FACTOR - 1)) +
3014 ++ (pstatus->rx_pwdb_all)) / (RX_SMOOTH_FACTOR);
3015 ++ undec_sm_cck = undec_sm_cck + 1;
3016 ++ } else {
3017 ++ undec_sm_pwdb = (((undec_sm_cck) * (RX_SMOOTH_FACTOR - 1)) +
3018 ++ (pstatus->rx_pwdb_all)) / (RX_SMOOTH_FACTOR);
3019 ++ }
3020 +
3021 + if (sta) {
3022 + drv_priv->rssi_stat.undec_sm_pwdb = undec_sm_pwdb;
3023 +diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
3024 +index 6e2b5c5c83c8..2d56d90c5c53 100644
3025 +--- a/drivers/net/wireless/rtlwifi/usb.c
3026 ++++ b/drivers/net/wireless/rtlwifi/usb.c
3027 +@@ -483,6 +483,8 @@ static void _rtl_usb_rx_process_agg(struct ieee80211_hw *hw,
3028 + if (unicast)
3029 + rtlpriv->link_info.num_rx_inperiod++;
3030 + }
3031 ++ /* static bcn for roaming */
3032 ++ rtl_beacon_statistic(hw, skb);
3033 + }
3034 + }
3035 +
3036 +@@ -553,7 +555,7 @@ static void _rtl_rx_pre_process(struct ieee80211_hw *hw, struct sk_buff *skb)
3037 + }
3038 + }
3039 +
3040 +-#define __RX_SKB_MAX_QUEUED 32
3041 ++#define __RX_SKB_MAX_QUEUED 64
3042 +
3043 + static void _rtl_rx_work(unsigned long param)
3044 + {
3045 +diff --git a/drivers/net/wireless/rtlwifi/wifi.h b/drivers/net/wireless/rtlwifi/wifi.h
3046 +index 0c65386fa30d..8c647391bedf 100644
3047 +--- a/drivers/net/wireless/rtlwifi/wifi.h
3048 ++++ b/drivers/net/wireless/rtlwifi/wifi.h
3049 +@@ -1033,6 +1033,7 @@ struct rtl_ht_agg {
3050 +
3051 + struct rssi_sta {
3052 + long undec_sm_pwdb;
3053 ++ long undec_sm_cck;
3054 + };
3055 +
3056 + struct rtl_tid_data {
3057 +@@ -1323,8 +1324,10 @@ struct fast_ant_training {
3058 + struct rtl_dm {
3059 + /*PHY status for Dynamic Management */
3060 + long entry_min_undec_sm_pwdb;
3061 ++ long undec_sm_cck;
3062 + long undec_sm_pwdb; /*out dm */
3063 + long entry_max_undec_sm_pwdb;
3064 ++ s32 ofdm_pkt_cnt;
3065 + bool dm_initialgain_enable;
3066 + bool dynamic_txpower_enable;
3067 + bool current_turbo_edca;
3068 +@@ -1339,6 +1342,7 @@ struct rtl_dm {
3069 + bool inform_fw_driverctrldm;
3070 + bool current_mrc_switch;
3071 + u8 txpowercount;
3072 ++ u8 powerindex_backup[6];
3073 +
3074 + u8 thermalvalue_rxgain;
3075 + u8 thermalvalue_iqk;
3076 +@@ -1350,7 +1354,9 @@ struct rtl_dm {
3077 + bool done_txpower;
3078 + u8 dynamic_txhighpower_lvl; /*Tx high power level */
3079 + u8 dm_flag; /*Indicate each dynamic mechanism's status. */
3080 ++ u8 dm_flag_tmp;
3081 + u8 dm_type;
3082 ++ u8 dm_rssi_sel;
3083 + u8 txpower_track_control;
3084 + bool interrupt_migration;
3085 + bool disable_tx_int;
3086 +@@ -1804,6 +1810,7 @@ struct rtl_hal_cfg {
3087 + bool write_readback;
3088 + char *name;
3089 + char *fw_name;
3090 ++ char *alt_fw_name;
3091 + struct rtl_hal_ops *ops;
3092 + struct rtl_mod_params *mod_params;
3093 + struct rtl_hal_usbint_cfg *usb_interface_cfg;
3094 +@@ -1948,6 +1955,7 @@ struct dig_t {
3095 + u8 pre_ccastate;
3096 + u8 cur_ccasate;
3097 + u8 large_fa_hit;
3098 ++ u8 dig_dynamic_min;
3099 + u8 forbidden_igi;
3100 + u8 dig_state;
3101 + u8 dig_highpwrstate;
3102 +@@ -2028,22 +2036,15 @@ struct rtl_priv {
3103 + struct dig_t dm_digtable;
3104 + struct ps_t dm_pstable;
3105 +
3106 +- /* section shared by individual drivers */
3107 +- union {
3108 +- struct { /* data buffer pointer for USB reads */
3109 +- __le32 *usb_data;
3110 +- int usb_data_index;
3111 +- bool initialized;
3112 +- };
3113 +- struct { /* section for 8723ae */
3114 +- bool reg_init; /* true if regs saved */
3115 +- u32 reg_874;
3116 +- u32 reg_c70;
3117 +- u32 reg_85c;
3118 +- u32 reg_a74;
3119 +- bool bt_operation_on;
3120 +- };
3121 +- };
3122 ++ u32 reg_874;
3123 ++ u32 reg_c70;
3124 ++ u32 reg_85c;
3125 ++ u32 reg_a74;
3126 ++ bool reg_init; /* true if regs saved */
3127 ++ bool bt_operation_on;
3128 ++ __le32 *usb_data;
3129 ++ int usb_data_index;
3130 ++ bool initialized;
3131 + bool enter_ps; /* true when entering PS */
3132 + u8 rate_mask[5];
3133 +
3134 +diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
3135 +index e59acb1daa23..657f7c588d17 100644
3136 +--- a/drivers/net/xen-netfront.c
3137 ++++ b/drivers/net/xen-netfront.c
3138 +@@ -117,6 +117,7 @@ struct netfront_info {
3139 + } tx_skbs[NET_TX_RING_SIZE];
3140 + grant_ref_t gref_tx_head;
3141 + grant_ref_t grant_tx_ref[NET_TX_RING_SIZE];
3142 ++ struct page *grant_tx_page[NET_TX_RING_SIZE];
3143 + unsigned tx_skb_freelist;
3144 +
3145 + spinlock_t rx_lock ____cacheline_aligned_in_smp;
3146 +@@ -396,6 +397,7 @@ static void xennet_tx_buf_gc(struct net_device *dev)
3147 + gnttab_release_grant_reference(
3148 + &np->gref_tx_head, np->grant_tx_ref[id]);
3149 + np->grant_tx_ref[id] = GRANT_INVALID_REF;
3150 ++ np->grant_tx_page[id] = NULL;
3151 + add_id_to_freelist(&np->tx_skb_freelist, np->tx_skbs, id);
3152 + dev_kfree_skb_irq(skb);
3153 + }
3154 +@@ -452,6 +454,7 @@ static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
3155 + gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
3156 + mfn, GNTMAP_readonly);
3157 +
3158 ++ np->grant_tx_page[id] = virt_to_page(data);
3159 + tx->gref = np->grant_tx_ref[id] = ref;
3160 + tx->offset = offset;
3161 + tx->size = len;
3162 +@@ -497,6 +500,7 @@ static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
3163 + np->xbdev->otherend_id,
3164 + mfn, GNTMAP_readonly);
3165 +
3166 ++ np->grant_tx_page[id] = page;
3167 + tx->gref = np->grant_tx_ref[id] = ref;
3168 + tx->offset = offset;
3169 + tx->size = bytes;
3170 +@@ -596,6 +600,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
3171 + mfn = virt_to_mfn(data);
3172 + gnttab_grant_foreign_access_ref(
3173 + ref, np->xbdev->otherend_id, mfn, GNTMAP_readonly);
3174 ++ np->grant_tx_page[id] = virt_to_page(data);
3175 + tx->gref = np->grant_tx_ref[id] = ref;
3176 + tx->offset = offset;
3177 + tx->size = len;
3178 +@@ -1122,10 +1127,11 @@ static void xennet_release_tx_bufs(struct netfront_info *np)
3179 + continue;
3180 +
3181 + skb = np->tx_skbs[i].skb;
3182 +- gnttab_end_foreign_access_ref(np->grant_tx_ref[i],
3183 +- GNTMAP_readonly);
3184 +- gnttab_release_grant_reference(&np->gref_tx_head,
3185 +- np->grant_tx_ref[i]);
3186 ++ get_page(np->grant_tx_page[i]);
3187 ++ gnttab_end_foreign_access(np->grant_tx_ref[i],
3188 ++ GNTMAP_readonly,
3189 ++ (unsigned long)page_address(np->grant_tx_page[i]));
3190 ++ np->grant_tx_page[i] = NULL;
3191 + np->grant_tx_ref[i] = GRANT_INVALID_REF;
3192 + add_id_to_freelist(&np->tx_skb_freelist, np->tx_skbs, i);
3193 + dev_kfree_skb_irq(skb);
3194 +@@ -1134,78 +1140,35 @@ static void xennet_release_tx_bufs(struct netfront_info *np)
3195 +
3196 + static void xennet_release_rx_bufs(struct netfront_info *np)
3197 + {
3198 +- struct mmu_update *mmu = np->rx_mmu;
3199 +- struct multicall_entry *mcl = np->rx_mcl;
3200 +- struct sk_buff_head free_list;
3201 +- struct sk_buff *skb;
3202 +- unsigned long mfn;
3203 +- int xfer = 0, noxfer = 0, unused = 0;
3204 + int id, ref;
3205 +
3206 +- dev_warn(&np->netdev->dev, "%s: fix me for copying receiver.\n",
3207 +- __func__);
3208 +- return;
3209 +-
3210 +- skb_queue_head_init(&free_list);
3211 +-
3212 + spin_lock_bh(&np->rx_lock);
3213 +
3214 + for (id = 0; id < NET_RX_RING_SIZE; id++) {
3215 +- ref = np->grant_rx_ref[id];
3216 +- if (ref == GRANT_INVALID_REF) {
3217 +- unused++;
3218 +- continue;
3219 +- }
3220 ++ struct sk_buff *skb;
3221 ++ struct page *page;
3222 +
3223 + skb = np->rx_skbs[id];
3224 +- mfn = gnttab_end_foreign_transfer_ref(ref);
3225 +- gnttab_release_grant_reference(&np->gref_rx_head, ref);
3226 +- np->grant_rx_ref[id] = GRANT_INVALID_REF;
3227 +-
3228 +- if (0 == mfn) {
3229 +- skb_shinfo(skb)->nr_frags = 0;
3230 +- dev_kfree_skb(skb);
3231 +- noxfer++;
3232 ++ if (!skb)
3233 + continue;
3234 +- }
3235 +
3236 +- if (!xen_feature(XENFEAT_auto_translated_physmap)) {
3237 +- /* Remap the page. */
3238 +- const struct page *page =
3239 +- skb_frag_page(&skb_shinfo(skb)->frags[0]);
3240 +- unsigned long pfn = page_to_pfn(page);
3241 +- void *vaddr = page_address(page);
3242 ++ ref = np->grant_rx_ref[id];
3243 ++ if (ref == GRANT_INVALID_REF)
3244 ++ continue;
3245 +
3246 +- MULTI_update_va_mapping(mcl, (unsigned long)vaddr,
3247 +- mfn_pte(mfn, PAGE_KERNEL),
3248 +- 0);
3249 +- mcl++;
3250 +- mmu->ptr = ((u64)mfn << PAGE_SHIFT)
3251 +- | MMU_MACHPHYS_UPDATE;
3252 +- mmu->val = pfn;
3253 +- mmu++;
3254 ++ page = skb_frag_page(&skb_shinfo(skb)->frags[0]);
3255 +
3256 +- set_phys_to_machine(pfn, mfn);
3257 +- }
3258 +- __skb_queue_tail(&free_list, skb);
3259 +- xfer++;
3260 +- }
3261 +-
3262 +- dev_info(&np->netdev->dev, "%s: %d xfer, %d noxfer, %d unused\n",
3263 +- __func__, xfer, noxfer, unused);
3264 ++ /* gnttab_end_foreign_access() needs a page ref until
3265 ++ * foreign access is ended (which may be deferred).
3266 ++ */
3267 ++ get_page(page);
3268 ++ gnttab_end_foreign_access(ref, 0,
3269 ++ (unsigned long)page_address(page));
3270 ++ np->grant_rx_ref[id] = GRANT_INVALID_REF;
3271 +
3272 +- if (xfer) {
3273 +- if (!xen_feature(XENFEAT_auto_translated_physmap)) {
3274 +- /* Do all the remapping work and M2P updates. */
3275 +- MULTI_mmu_update(mcl, np->rx_mmu, mmu - np->rx_mmu,
3276 +- NULL, DOMID_SELF);
3277 +- mcl++;
3278 +- HYPERVISOR_multicall(np->rx_mcl, mcl - np->rx_mcl);
3279 +- }
3280 ++ kfree_skb(skb);
3281 + }
3282 +
3283 +- __skb_queue_purge(&free_list);
3284 +-
3285 + spin_unlock_bh(&np->rx_lock);
3286 + }
3287 +
3288 +@@ -1358,6 +1321,7 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
3289 + for (i = 0; i < NET_RX_RING_SIZE; i++) {
3290 + np->rx_skbs[i] = NULL;
3291 + np->grant_rx_ref[i] = GRANT_INVALID_REF;
3292 ++ np->grant_tx_page[i] = NULL;
3293 + }
3294 +
3295 + /* A grant for every tx ring slot */
3296 +diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
3297 +index 963761526229..bb665478cc4b 100644
3298 +--- a/drivers/parport/parport_pc.c
3299 ++++ b/drivers/parport/parport_pc.c
3300 +@@ -2600,8 +2600,6 @@ enum parport_pc_pci_cards {
3301 + syba_2p_epp,
3302 + syba_1p_ecp,
3303 + titan_010l,
3304 +- titan_1284p1,
3305 +- titan_1284p2,
3306 + avlab_1p,
3307 + avlab_2p,
3308 + oxsemi_952,
3309 +@@ -2660,8 +2658,6 @@ static struct parport_pc_pci {
3310 + /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
3311 + /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
3312 + /* titan_010l */ { 1, { { 3, -1 }, } },
3313 +- /* titan_1284p1 */ { 1, { { 0, 1 }, } },
3314 +- /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } },
3315 + /* avlab_1p */ { 1, { { 0, 1}, } },
3316 + /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} },
3317 + /* The Oxford Semi cards are unusual: 954 doesn't support ECP,
3318 +@@ -2677,8 +2673,8 @@ static struct parport_pc_pci {
3319 + /* netmos_9705 */ { 1, { { 0, -1 }, } },
3320 + /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} },
3321 + /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} },
3322 +- /* netmos_9805 */ { 1, { { 0, -1 }, } },
3323 +- /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } },
3324 ++ /* netmos_9805 */ { 1, { { 0, 1 }, } },
3325 ++ /* netmos_9815 */ { 2, { { 0, 1 }, { 2, 3 }, } },
3326 + /* netmos_9901 */ { 1, { { 0, -1 }, } },
3327 + /* netmos_9865 */ { 1, { { 0, -1 }, } },
3328 + /* quatech_sppxp100 */ { 1, { { 0, 1 }, } },
3329 +@@ -2722,8 +2718,6 @@ static const struct pci_device_id parport_pc_pci_tbl[] = {
3330 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
3331 + { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
3332 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
3333 +- { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 },
3334 +- { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
3335 + /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
3336 + /* AFAVLAB_TK9902 */
3337 + { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p},
3338 +diff --git a/drivers/pinctrl/pinctrl-sunxi.c b/drivers/pinctrl/pinctrl-sunxi.c
3339 +index 119d2ddedfe7..6ebf3067bde4 100644
3340 +--- a/drivers/pinctrl/pinctrl-sunxi.c
3341 ++++ b/drivers/pinctrl/pinctrl-sunxi.c
3342 +@@ -469,12 +469,6 @@ static int sunxi_pinctrl_gpio_get(struct gpio_chip *chip, unsigned offset)
3343 + return val;
3344 + }
3345 +
3346 +-static int sunxi_pinctrl_gpio_direction_output(struct gpio_chip *chip,
3347 +- unsigned offset, int value)
3348 +-{
3349 +- return pinctrl_gpio_direction_output(chip->base + offset);
3350 +-}
3351 +-
3352 + static void sunxi_pinctrl_gpio_set(struct gpio_chip *chip,
3353 + unsigned offset, int value)
3354 + {
3355 +@@ -498,6 +492,13 @@ static void sunxi_pinctrl_gpio_set(struct gpio_chip *chip,
3356 + spin_unlock_irqrestore(&pctl->lock, flags);
3357 + }
3358 +
3359 ++static int sunxi_pinctrl_gpio_direction_output(struct gpio_chip *chip,
3360 ++ unsigned offset, int value)
3361 ++{
3362 ++ sunxi_pinctrl_gpio_set(chip, offset, value);
3363 ++ return pinctrl_gpio_direction_output(chip->base + offset);
3364 ++}
3365 ++
3366 + static int sunxi_pinctrl_gpio_of_xlate(struct gpio_chip *gc,
3367 + const struct of_phandle_args *gpiospec,
3368 + u32 *flags)
3369 +diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
3370 +index a8e43cf70fac..0ed96df20162 100644
3371 +--- a/drivers/platform/x86/hp_accel.c
3372 ++++ b/drivers/platform/x86/hp_accel.c
3373 +@@ -77,6 +77,7 @@ static inline void delayed_sysfs_set(struct led_classdev *led_cdev,
3374 + static struct acpi_device_id lis3lv02d_device_ids[] = {
3375 + {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
3376 + {"HPQ6000", 0}, /* HP Mobile Data Protection System PNP */
3377 ++ {"HPQ6007", 0}, /* HP Mobile Data Protection System PNP */
3378 + {"", 0},
3379 + };
3380 + MODULE_DEVICE_TABLE(acpi, lis3lv02d_device_ids);
3381 +diff --git a/drivers/rtc/rtc-max8907.c b/drivers/rtc/rtc-max8907.c
3382 +index 8e45b3c4aa2f..3032178bd9e6 100644
3383 +--- a/drivers/rtc/rtc-max8907.c
3384 ++++ b/drivers/rtc/rtc-max8907.c
3385 +@@ -51,7 +51,7 @@ static irqreturn_t max8907_irq_handler(int irq, void *data)
3386 + {
3387 + struct max8907_rtc *rtc = data;
3388 +
3389 +- regmap_update_bits(rtc->regmap, MAX8907_REG_ALARM0_CNTL, 0x7f, 0);
3390 ++ regmap_write(rtc->regmap, MAX8907_REG_ALARM0_CNTL, 0);
3391 +
3392 + rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
3393 +
3394 +@@ -64,7 +64,7 @@ static void regs_to_tm(u8 *regs, struct rtc_time *tm)
3395 + bcd2bin(regs[RTC_YEAR1]) - 1900;
3396 + tm->tm_mon = bcd2bin(regs[RTC_MONTH] & 0x1f) - 1;
3397 + tm->tm_mday = bcd2bin(regs[RTC_DATE] & 0x3f);
3398 +- tm->tm_wday = (regs[RTC_WEEKDAY] & 0x07) - 1;
3399 ++ tm->tm_wday = (regs[RTC_WEEKDAY] & 0x07);
3400 + if (regs[RTC_HOUR] & HOUR_12) {
3401 + tm->tm_hour = bcd2bin(regs[RTC_HOUR] & 0x01f);
3402 + if (tm->tm_hour == 12)
3403 +@@ -88,7 +88,7 @@ static void tm_to_regs(struct rtc_time *tm, u8 *regs)
3404 + regs[RTC_YEAR1] = bin2bcd(low);
3405 + regs[RTC_MONTH] = bin2bcd(tm->tm_mon + 1);
3406 + regs[RTC_DATE] = bin2bcd(tm->tm_mday);
3407 +- regs[RTC_WEEKDAY] = tm->tm_wday + 1;
3408 ++ regs[RTC_WEEKDAY] = tm->tm_wday;
3409 + regs[RTC_HOUR] = bin2bcd(tm->tm_hour);
3410 + regs[RTC_MIN] = bin2bcd(tm->tm_min);
3411 + regs[RTC_SEC] = bin2bcd(tm->tm_sec);
3412 +@@ -153,7 +153,7 @@ static int max8907_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
3413 + tm_to_regs(&alrm->time, regs);
3414 +
3415 + /* Disable alarm while we update the target time */
3416 +- ret = regmap_update_bits(rtc->regmap, MAX8907_REG_ALARM0_CNTL, 0x7f, 0);
3417 ++ ret = regmap_write(rtc->regmap, MAX8907_REG_ALARM0_CNTL, 0);
3418 + if (ret < 0)
3419 + return ret;
3420 +
3421 +@@ -163,8 +163,7 @@ static int max8907_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
3422 + return ret;
3423 +
3424 + if (alrm->enabled)
3425 +- ret = regmap_update_bits(rtc->regmap, MAX8907_REG_ALARM0_CNTL,
3426 +- 0x7f, 0x7f);
3427 ++ ret = regmap_write(rtc->regmap, MAX8907_REG_ALARM0_CNTL, 0x77);
3428 +
3429 + return ret;
3430 + }
3431 +diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
3432 +index fc80a325a1e6..27e270e00a10 100644
3433 +--- a/drivers/scsi/bfa/bfad.c
3434 ++++ b/drivers/scsi/bfa/bfad.c
3435 +@@ -1802,7 +1802,7 @@ out:
3436 + static u32 *
3437 + bfad_load_fwimg(struct pci_dev *pdev)
3438 + {
3439 +- if (pdev->device == BFA_PCI_DEVICE_ID_CT2) {
3440 ++ if (bfa_asic_id_ct2(pdev->device)) {
3441 + if (bfi_image_ct2_size == 0)
3442 + bfad_read_firmware(pdev, &bfi_image_ct2,
3443 + &bfi_image_ct2_size, BFAD_FW_FILE_CT2);
3444 +@@ -1812,12 +1812,14 @@ bfad_load_fwimg(struct pci_dev *pdev)
3445 + bfad_read_firmware(pdev, &bfi_image_ct,
3446 + &bfi_image_ct_size, BFAD_FW_FILE_CT);
3447 + return bfi_image_ct;
3448 +- } else {
3449 ++ } else if (bfa_asic_id_cb(pdev->device)) {
3450 + if (bfi_image_cb_size == 0)
3451 + bfad_read_firmware(pdev, &bfi_image_cb,
3452 + &bfi_image_cb_size, BFAD_FW_FILE_CB);
3453 + return bfi_image_cb;
3454 + }
3455 ++
3456 ++ return NULL;
3457 + }
3458 +
3459 + static void
3460 +diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
3461 +index a28d5e624aab..cf174a4ffa84 100644
3462 +--- a/drivers/scsi/qla4xxx/ql4_os.c
3463 ++++ b/drivers/scsi/qla4xxx/ql4_os.c
3464 +@@ -802,6 +802,7 @@ static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
3465 + int type;
3466 + int rem = len;
3467 + int rc = 0;
3468 ++ int size;
3469 +
3470 + memset(&chap_rec, 0, sizeof(chap_rec));
3471 +
3472 +@@ -816,12 +817,14 @@ static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
3473 + chap_rec.chap_type = param_info->value[0];
3474 + break;
3475 + case ISCSI_CHAP_PARAM_USERNAME:
3476 +- memcpy(chap_rec.username, param_info->value,
3477 +- param_info->len);
3478 ++ size = min_t(size_t, sizeof(chap_rec.username),
3479 ++ param_info->len);
3480 ++ memcpy(chap_rec.username, param_info->value, size);
3481 + break;
3482 + case ISCSI_CHAP_PARAM_PASSWORD:
3483 +- memcpy(chap_rec.password, param_info->value,
3484 +- param_info->len);
3485 ++ size = min_t(size_t, sizeof(chap_rec.password),
3486 ++ param_info->len);
3487 ++ memcpy(chap_rec.password, param_info->value, size);
3488 + break;
3489 + case ISCSI_CHAP_PARAM_PASSWORD_LEN:
3490 + chap_rec.password_length = param_info->value[0];
3491 +diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
3492 +index c3173dced870..16bfd50cd3fe 100644
3493 +--- a/drivers/scsi/virtio_scsi.c
3494 ++++ b/drivers/scsi/virtio_scsi.c
3495 +@@ -956,6 +956,10 @@ static void virtscsi_remove(struct virtio_device *vdev)
3496 + #ifdef CONFIG_PM_SLEEP
3497 + static int virtscsi_freeze(struct virtio_device *vdev)
3498 + {
3499 ++ struct Scsi_Host *sh = virtio_scsi_host(vdev);
3500 ++ struct virtio_scsi *vscsi = shost_priv(sh);
3501 ++
3502 ++ unregister_hotcpu_notifier(&vscsi->nb);
3503 + virtscsi_remove_vqs(vdev);
3504 + return 0;
3505 + }
3506 +@@ -964,8 +968,17 @@ static int virtscsi_restore(struct virtio_device *vdev)
3507 + {
3508 + struct Scsi_Host *sh = virtio_scsi_host(vdev);
3509 + struct virtio_scsi *vscsi = shost_priv(sh);
3510 ++ int err;
3511 ++
3512 ++ err = virtscsi_init(vdev, vscsi);
3513 ++ if (err)
3514 ++ return err;
3515 ++
3516 ++ err = register_hotcpu_notifier(&vscsi->nb);
3517 ++ if (err)
3518 ++ vdev->config->del_vqs(vdev);
3519 +
3520 +- return virtscsi_init(vdev, vscsi);
3521 ++ return err;
3522 + }
3523 + #endif
3524 +
3525 +diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
3526 +index a0e009717a5a..d6047b9535ae 100644
3527 +--- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
3528 ++++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
3529 +@@ -179,7 +179,7 @@ int ptlrpc_register_bulk(struct ptlrpc_request *req)
3530 + LNET_UNLINK, LNET_INS_AFTER, &me_h);
3531 + if (rc != 0) {
3532 + CERROR("%s: LNetMEAttach failed x"LPU64"/%d: rc = %d\n",
3533 +- desc->bd_export->exp_obd->obd_name, xid,
3534 ++ desc->bd_import->imp_obd->obd_name, xid,
3535 + posted_md, rc);
3536 + break;
3537 + }
3538 +@@ -189,7 +189,7 @@ int ptlrpc_register_bulk(struct ptlrpc_request *req)
3539 + &desc->bd_mds[posted_md]);
3540 + if (rc != 0) {
3541 + CERROR("%s: LNetMDAttach failed x"LPU64"/%d: rc = %d\n",
3542 +- desc->bd_export->exp_obd->obd_name, xid,
3543 ++ desc->bd_import->imp_obd->obd_name, xid,
3544 + posted_md, rc);
3545 + rc2 = LNetMEUnlink(me_h);
3546 + LASSERT(rc2 == 0);
3547 +@@ -219,7 +219,7 @@ int ptlrpc_register_bulk(struct ptlrpc_request *req)
3548 + /* Holler if peer manages to touch buffers before he knows the xid */
3549 + if (desc->bd_md_count != total_md)
3550 + CWARN("%s: Peer %s touched %d buffers while I registered\n",
3551 +- desc->bd_export->exp_obd->obd_name, libcfs_id2str(peer),
3552 ++ desc->bd_import->imp_obd->obd_name, libcfs_id2str(peer),
3553 + total_md - desc->bd_md_count);
3554 + spin_unlock(&desc->bd_lock);
3555 +
3556 +diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c
3557 +index dbefa43e4c2c..bbd5888e316b 100644
3558 +--- a/drivers/staging/rtl8712/usb_intf.c
3559 ++++ b/drivers/staging/rtl8712/usb_intf.c
3560 +@@ -353,6 +353,10 @@ static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
3561 + }
3562 + }
3563 +
3564 ++static const struct device_type wlan_type = {
3565 ++ .name = "wlan",
3566 ++};
3567 ++
3568 + /*
3569 + * drv_init() - a device potentially for us
3570 + *
3571 +@@ -388,6 +392,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
3572 + padapter->pusb_intf = pusb_intf;
3573 + usb_set_intfdata(pusb_intf, pnetdev);
3574 + SET_NETDEV_DEV(pnetdev, &pusb_intf->dev);
3575 ++ pnetdev->dev.type = &wlan_type;
3576 + /* step 2. */
3577 + padapter->dvobj_init = &r8712_usb_dvobj_init;
3578 + padapter->dvobj_deinit = &r8712_usb_dvobj_deinit;
3579 +diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c
3580 +index 4aa5ef54b683..22e117440f94 100644
3581 +--- a/drivers/staging/vt6656/baseband.c
3582 ++++ b/drivers/staging/vt6656/baseband.c
3583 +@@ -1464,7 +1464,6 @@ void BBvUpdatePreEDThreshold(struct vnt_private *pDevice, int bScanning)
3584 +
3585 + if( bScanning )
3586 + { // need Max sensitivity //RSSI -69, -70,....
3587 +- if(pDevice->byBBPreEDIndex == 0) break;
3588 + pDevice->byBBPreEDIndex = 0;
3589 + ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, 0x00); //CR201(0xC9)
3590 + ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xCE, 0x30); //CR206(0xCE)
3591 +@@ -1607,7 +1606,6 @@ void BBvUpdatePreEDThreshold(struct vnt_private *pDevice, int bScanning)
3592 +
3593 + if( bScanning )
3594 + { // need Max sensitivity //RSSI -69, -70, ...
3595 +- if(pDevice->byBBPreEDIndex == 0) break;
3596 + pDevice->byBBPreEDIndex = 0;
3597 + ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, 0x00); //CR201(0xC9)
3598 + ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xCE, 0x24); //CR206(0xCE)
3599 +@@ -1759,7 +1757,6 @@ void BBvUpdatePreEDThreshold(struct vnt_private *pDevice, int bScanning)
3600 + case RF_VT3342A0: //RobertYu:20060627, testing table
3601 + if( bScanning )
3602 + { // need Max sensitivity //RSSI -67, -68, ...
3603 +- if(pDevice->byBBPreEDIndex == 0) break;
3604 + pDevice->byBBPreEDIndex = 0;
3605 + ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, 0x00); //CR201(0xC9)
3606 + ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xCE, 0x38); //CR206(0xCE)
3607 +diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
3608 +index 19d3cf451b88..34a24b78c1a7 100644
3609 +--- a/drivers/staging/vt6656/card.c
3610 ++++ b/drivers/staging/vt6656/card.c
3611 +@@ -731,7 +731,7 @@ u64 CARDqGetNextTBTT(u64 qwTSF, u16 wBeaconInterval)
3612 +
3613 + uBeaconInterval = wBeaconInterval * 1024;
3614 + // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
3615 +- uLowNextTBTT = ((qwTSF & 0xffffffffU) >> 10) << 10;
3616 ++ uLowNextTBTT = ((qwTSF & 0xffffffffULL) >> 10) << 10;
3617 + uLowRemain = (uLowNextTBTT) % uBeaconInterval;
3618 + uHighRemain = ((0x80000000 % uBeaconInterval) * 2 * (u32)(qwTSF >> 32))
3619 + % uBeaconInterval;
3620 +diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
3621 +index 3277d9838f4e..bfbfe579d896 100644
3622 +--- a/drivers/staging/zram/zram_drv.c
3623 ++++ b/drivers/staging/zram/zram_drv.c
3624 +@@ -552,14 +552,14 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
3625 + size_t index;
3626 + struct zram_meta *meta;
3627 +
3628 +- flush_work(&zram->free_work);
3629 +-
3630 + down_write(&zram->init_lock);
3631 + if (!zram->init_done) {
3632 + up_write(&zram->init_lock);
3633 + return;
3634 + }
3635 +
3636 ++ flush_work(&zram->free_work);
3637 ++
3638 + meta = zram->meta;
3639 + zram->init_done = 0;
3640 +
3641 +diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
3642 +index 00867190413c..5049db4651c5 100644
3643 +--- a/drivers/target/iscsi/iscsi_target.c
3644 ++++ b/drivers/target/iscsi/iscsi_target.c
3645 +@@ -52,7 +52,7 @@
3646 + static LIST_HEAD(g_tiqn_list);
3647 + static LIST_HEAD(g_np_list);
3648 + static DEFINE_SPINLOCK(tiqn_lock);
3649 +-static DEFINE_SPINLOCK(np_lock);
3650 ++static DEFINE_MUTEX(np_lock);
3651 +
3652 + static struct idr tiqn_idr;
3653 + struct idr sess_idr;
3654 +@@ -307,6 +307,9 @@ bool iscsit_check_np_match(
3655 + return false;
3656 + }
3657 +
3658 ++/*
3659 ++ * Called with mutex np_lock held
3660 ++ */
3661 + static struct iscsi_np *iscsit_get_np(
3662 + struct __kernel_sockaddr_storage *sockaddr,
3663 + int network_transport)
3664 +@@ -314,11 +317,10 @@ static struct iscsi_np *iscsit_get_np(
3665 + struct iscsi_np *np;
3666 + bool match;
3667 +
3668 +- spin_lock_bh(&np_lock);
3669 + list_for_each_entry(np, &g_np_list, np_list) {
3670 +- spin_lock(&np->np_thread_lock);
3671 ++ spin_lock_bh(&np->np_thread_lock);
3672 + if (np->np_thread_state != ISCSI_NP_THREAD_ACTIVE) {
3673 +- spin_unlock(&np->np_thread_lock);
3674 ++ spin_unlock_bh(&np->np_thread_lock);
3675 + continue;
3676 + }
3677 +
3678 +@@ -330,13 +332,11 @@ static struct iscsi_np *iscsit_get_np(
3679 + * while iscsi_tpg_add_network_portal() is called.
3680 + */
3681 + np->np_exports++;
3682 +- spin_unlock(&np->np_thread_lock);
3683 +- spin_unlock_bh(&np_lock);
3684 ++ spin_unlock_bh(&np->np_thread_lock);
3685 + return np;
3686 + }
3687 +- spin_unlock(&np->np_thread_lock);
3688 ++ spin_unlock_bh(&np->np_thread_lock);
3689 + }
3690 +- spin_unlock_bh(&np_lock);
3691 +
3692 + return NULL;
3693 + }
3694 +@@ -350,16 +350,22 @@ struct iscsi_np *iscsit_add_np(
3695 + struct sockaddr_in6 *sock_in6;
3696 + struct iscsi_np *np;
3697 + int ret;
3698 ++
3699 ++ mutex_lock(&np_lock);
3700 ++
3701 + /*
3702 + * Locate the existing struct iscsi_np if already active..
3703 + */
3704 + np = iscsit_get_np(sockaddr, network_transport);
3705 +- if (np)
3706 ++ if (np) {
3707 ++ mutex_unlock(&np_lock);
3708 + return np;
3709 ++ }
3710 +
3711 + np = kzalloc(sizeof(struct iscsi_np), GFP_KERNEL);
3712 + if (!np) {
3713 + pr_err("Unable to allocate memory for struct iscsi_np\n");
3714 ++ mutex_unlock(&np_lock);
3715 + return ERR_PTR(-ENOMEM);
3716 + }
3717 +
3718 +@@ -382,6 +388,7 @@ struct iscsi_np *iscsit_add_np(
3719 + ret = iscsi_target_setup_login_socket(np, sockaddr);
3720 + if (ret != 0) {
3721 + kfree(np);
3722 ++ mutex_unlock(&np_lock);
3723 + return ERR_PTR(ret);
3724 + }
3725 +
3726 +@@ -390,6 +397,7 @@ struct iscsi_np *iscsit_add_np(
3727 + pr_err("Unable to create kthread: iscsi_np\n");
3728 + ret = PTR_ERR(np->np_thread);
3729 + kfree(np);
3730 ++ mutex_unlock(&np_lock);
3731 + return ERR_PTR(ret);
3732 + }
3733 + /*
3734 +@@ -400,10 +408,10 @@ struct iscsi_np *iscsit_add_np(
3735 + * point because iscsi_np has not been added to g_np_list yet.
3736 + */
3737 + np->np_exports = 1;
3738 ++ np->np_thread_state = ISCSI_NP_THREAD_ACTIVE;
3739 +
3740 +- spin_lock_bh(&np_lock);
3741 + list_add_tail(&np->np_list, &g_np_list);
3742 +- spin_unlock_bh(&np_lock);
3743 ++ mutex_unlock(&np_lock);
3744 +
3745 + pr_debug("CORE[0] - Added Network Portal: %s:%hu on %s\n",
3746 + np->np_ip, np->np_port, np->np_transport->name);
3747 +@@ -470,9 +478,9 @@ int iscsit_del_np(struct iscsi_np *np)
3748 +
3749 + np->np_transport->iscsit_free_np(np);
3750 +
3751 +- spin_lock_bh(&np_lock);
3752 ++ mutex_lock(&np_lock);
3753 + list_del(&np->np_list);
3754 +- spin_unlock_bh(&np_lock);
3755 ++ mutex_unlock(&np_lock);
3756 +
3757 + pr_debug("CORE[0] - Removed Network Portal: %s:%hu on %s\n",
3758 + np->np_ip, np->np_port, np->np_transport->name);
3759 +diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c
3760 +index 83c965c65386..582ba84075ec 100644
3761 +--- a/drivers/target/iscsi/iscsi_target_nego.c
3762 ++++ b/drivers/target/iscsi/iscsi_target_nego.c
3763 +@@ -1192,7 +1192,7 @@ get_target:
3764 + */
3765 + alloc_tags:
3766 + tag_num = max_t(u32, ISCSIT_MIN_TAGS, queue_depth);
3767 +- tag_num += (tag_num / 2) + ISCSIT_EXTRA_TAGS;
3768 ++ tag_num = (tag_num * 2) + ISCSIT_EXTRA_TAGS;
3769 + tag_size = sizeof(struct iscsi_cmd) + conn->conn_transport->priv_size;
3770 +
3771 + ret = transport_alloc_session_tags(sess->se_sess, tag_num, tag_size);
3772 +diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
3773 +index 978db344bda0..b24aa010f68c 100644
3774 +--- a/drivers/tty/Kconfig
3775 ++++ b/drivers/tty/Kconfig
3776 +@@ -366,7 +366,7 @@ config TRACE_SINK
3777 + "Trace data router for MIPI P1149.7 cJTAG standard".
3778 +
3779 + config PPC_EPAPR_HV_BYTECHAN
3780 +- tristate "ePAPR hypervisor byte channel driver"
3781 ++ bool "ePAPR hypervisor byte channel driver"
3782 + depends on PPC
3783 + select EPAPR_PARAVIRT
3784 + help
3785 +diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
3786 +index e33d38cb170f..61ecd709a722 100644
3787 +--- a/drivers/tty/serial/8250/8250_core.c
3788 ++++ b/drivers/tty/serial/8250/8250_core.c
3789 +@@ -2670,6 +2670,10 @@ static void serial8250_config_port(struct uart_port *port, int flags)
3790 + if (port->type == PORT_16550A && port->iotype == UPIO_AU)
3791 + up->bugs |= UART_BUG_NOMSR;
3792 +
3793 ++ /* HW bugs may trigger IRQ while IIR == NO_INT */
3794 ++ if (port->type == PORT_TEGRA)
3795 ++ up->bugs |= UART_BUG_NOMSR;
3796 ++
3797 + if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
3798 + autoconfig_irq(up);
3799 +
3800 +diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
3801 +index 4697a514b80a..77d0aca9050a 100644
3802 +--- a/drivers/tty/serial/8250/8250_pci.c
3803 ++++ b/drivers/tty/serial/8250/8250_pci.c
3804 +@@ -1259,10 +1259,10 @@ static int pci_quatech_init(struct pci_dev *dev)
3805 + unsigned long base = pci_resource_start(dev, 0);
3806 + if (base) {
3807 + u32 tmp;
3808 +- outl(inl(base + 0x38), base + 0x38);
3809 ++ outl(inl(base + 0x38) | 0x00002000, base + 0x38);
3810 + tmp = inl(base + 0x3c);
3811 + outl(tmp | 0x01000000, base + 0x3c);
3812 +- outl(tmp, base + 0x3c);
3813 ++ outl(tmp &= ~0x01000000, base + 0x3c);
3814 + }
3815 + }
3816 + return 0;
3817 +@@ -1744,6 +1744,7 @@ pci_wch_ch353_setup(struct serial_private *priv,
3818 + #define PCI_DEVICE_ID_TITAN_800E 0xA014
3819 + #define PCI_DEVICE_ID_TITAN_200EI 0xA016
3820 + #define PCI_DEVICE_ID_TITAN_200EISI 0xA017
3821 ++#define PCI_DEVICE_ID_TITAN_200V3 0xA306
3822 + #define PCI_DEVICE_ID_TITAN_400V3 0xA310
3823 + #define PCI_DEVICE_ID_TITAN_410V3 0xA312
3824 + #define PCI_DEVICE_ID_TITAN_800V3 0xA314
3825 +@@ -4427,6 +4428,9 @@ static struct pci_device_id serial_pci_tbl[] = {
3826 + { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200EISI,
3827 + PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3828 + pbn_oxsemi_2_4000000 },
3829 ++ { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200V3,
3830 ++ PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3831 ++ pbn_b0_bt_2_921600 },
3832 + { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400V3,
3833 + PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3834 + pbn_b0_4_921600 },
3835 +diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
3836 +index c7d99af46a96..a49f10d269b2 100644
3837 +--- a/drivers/tty/serial/atmel_serial.c
3838 ++++ b/drivers/tty/serial/atmel_serial.c
3839 +@@ -825,9 +825,6 @@ static void atmel_release_rx_dma(struct uart_port *port)
3840 + atmel_port->desc_rx = NULL;
3841 + atmel_port->chan_rx = NULL;
3842 + atmel_port->cookie_rx = -EINVAL;
3843 +-
3844 +- if (!atmel_port->is_usart)
3845 +- del_timer_sync(&atmel_port->uart_timer);
3846 + }
3847 +
3848 + static void atmel_rx_from_dma(struct uart_port *port)
3849 +@@ -1229,9 +1226,6 @@ static void atmel_release_rx_pdc(struct uart_port *port)
3850 + DMA_FROM_DEVICE);
3851 + kfree(pdc->buf);
3852 + }
3853 +-
3854 +- if (!atmel_port->is_usart)
3855 +- del_timer_sync(&atmel_port->uart_timer);
3856 + }
3857 +
3858 + static void atmel_rx_from_pdc(struct uart_port *port)
3859 +@@ -1604,12 +1598,13 @@ static int atmel_startup(struct uart_port *port)
3860 + /* enable xmit & rcvr */
3861 + UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN);
3862 +
3863 ++ setup_timer(&atmel_port->uart_timer,
3864 ++ atmel_uart_timer_callback,
3865 ++ (unsigned long)port);
3866 ++
3867 + if (atmel_use_pdc_rx(port)) {
3868 + /* set UART timeout */
3869 + if (!atmel_port->is_usart) {
3870 +- setup_timer(&atmel_port->uart_timer,
3871 +- atmel_uart_timer_callback,
3872 +- (unsigned long)port);
3873 + mod_timer(&atmel_port->uart_timer,
3874 + jiffies + uart_poll_timeout(port));
3875 + /* set USART timeout */
3876 +@@ -1624,9 +1619,6 @@ static int atmel_startup(struct uart_port *port)
3877 + } else if (atmel_use_dma_rx(port)) {
3878 + /* set UART timeout */
3879 + if (!atmel_port->is_usart) {
3880 +- setup_timer(&atmel_port->uart_timer,
3881 +- atmel_uart_timer_callback,
3882 +- (unsigned long)port);
3883 + mod_timer(&atmel_port->uart_timer,
3884 + jiffies + uart_poll_timeout(port));
3885 + /* set USART timeout */
3886 +@@ -1650,12 +1642,30 @@ static int atmel_startup(struct uart_port *port)
3887 + static void atmel_shutdown(struct uart_port *port)
3888 + {
3889 + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
3890 ++
3891 + /*
3892 +- * Ensure everything is stopped.
3893 ++ * Prevent any tasklets being scheduled during
3894 ++ * cleanup
3895 ++ */
3896 ++ del_timer_sync(&atmel_port->uart_timer);
3897 ++
3898 ++ /*
3899 ++ * Clear out any scheduled tasklets before
3900 ++ * we destroy the buffers
3901 ++ */
3902 ++ tasklet_kill(&atmel_port->tasklet);
3903 ++
3904 ++ /*
3905 ++ * Ensure everything is stopped and
3906 ++ * disable all interrupts, port and break condition.
3907 + */
3908 + atmel_stop_rx(port);
3909 + atmel_stop_tx(port);
3910 +
3911 ++ UART_PUT_CR(port, ATMEL_US_RSTSTA);
3912 ++ UART_PUT_IDR(port, -1);
3913 ++
3914 ++
3915 + /*
3916 + * Shut-down the DMA.
3917 + */
3918 +@@ -1665,10 +1675,10 @@ static void atmel_shutdown(struct uart_port *port)
3919 + atmel_port->release_tx(port);
3920 +
3921 + /*
3922 +- * Disable all interrupts, port and break condition.
3923 ++ * Reset ring buffer pointers
3924 + */
3925 +- UART_PUT_CR(port, ATMEL_US_RSTSTA);
3926 +- UART_PUT_IDR(port, -1);
3927 ++ atmel_port->rx_ring.head = 0;
3928 ++ atmel_port->rx_ring.tail = 0;
3929 +
3930 + /*
3931 + * Free the interrupt
3932 +@@ -2441,11 +2451,12 @@ static int atmel_serial_remove(struct platform_device *pdev)
3933 + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
3934 + int ret = 0;
3935 +
3936 ++ tasklet_kill(&atmel_port->tasklet);
3937 ++
3938 + device_init_wakeup(&pdev->dev, 0);
3939 +
3940 + ret = uart_remove_one_port(&atmel_uart, port);
3941 +
3942 +- tasklet_kill(&atmel_port->tasklet);
3943 + kfree(atmel_port->rx_ring.buf);
3944 +
3945 + /* "port" is allocated statically, so we shouldn't free it */
3946 +diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
3947 +index f7beb6eb40c7..a673e5b6a2e0 100644
3948 +--- a/drivers/uio/uio.c
3949 ++++ b/drivers/uio/uio.c
3950 +@@ -847,7 +847,7 @@ int __uio_register_device(struct module *owner,
3951 + info->uio_dev = idev;
3952 +
3953 + if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) {
3954 +- ret = devm_request_irq(parent, info->irq, uio_interrupt,
3955 ++ ret = devm_request_irq(idev->dev, info->irq, uio_interrupt,
3956 + info->irq_flags, info->name, idev);
3957 + if (ret)
3958 + goto err_request_irq;
3959 +diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
3960 +index 1c94fc5257f4..5ad448d0fb7d 100644
3961 +--- a/drivers/usb/chipidea/ci.h
3962 ++++ b/drivers/usb/chipidea/ci.h
3963 +@@ -135,6 +135,7 @@ struct hw_bank {
3964 + * @id_event: indicates there is an id event, and handled at ci_otg_work
3965 + * @b_sess_valid_event: indicates there is a vbus event, and handled
3966 + * at ci_otg_work
3967 ++ * @imx28_write_fix: Freescale imx28 needs swp instruction for writing
3968 + */
3969 + struct ci_hdrc {
3970 + struct device *dev;
3971 +@@ -173,6 +174,7 @@ struct ci_hdrc {
3972 + struct dentry *debugfs;
3973 + bool id_event;
3974 + bool b_sess_valid_event;
3975 ++ bool imx28_write_fix;
3976 + };
3977 +
3978 + static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci)
3979 +@@ -253,6 +255,26 @@ static inline u32 hw_read(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask)
3980 + return ioread32(ci->hw_bank.regmap[reg]) & mask;
3981 + }
3982 +
3983 ++#ifdef CONFIG_SOC_IMX28
3984 ++static inline void imx28_ci_writel(u32 val, volatile void __iomem *addr)
3985 ++{
3986 ++ __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr));
3987 ++}
3988 ++#else
3989 ++static inline void imx28_ci_writel(u32 val, volatile void __iomem *addr)
3990 ++{
3991 ++}
3992 ++#endif
3993 ++
3994 ++static inline void __hw_write(struct ci_hdrc *ci, u32 val,
3995 ++ void __iomem *addr)
3996 ++{
3997 ++ if (ci->imx28_write_fix)
3998 ++ imx28_ci_writel(val, addr);
3999 ++ else
4000 ++ iowrite32(val, addr);
4001 ++}
4002 ++
4003 + /**
4004 + * hw_write: writes to a hw register
4005 + * @reg: register index
4006 +@@ -266,7 +288,7 @@ static inline void hw_write(struct ci_hdrc *ci, enum ci_hw_regs reg,
4007 + data = (ioread32(ci->hw_bank.regmap[reg]) & ~mask)
4008 + | (data & mask);
4009 +
4010 +- iowrite32(data, ci->hw_bank.regmap[reg]);
4011 ++ __hw_write(ci, data, ci->hw_bank.regmap[reg]);
4012 + }
4013 +
4014 + /**
4015 +@@ -281,7 +303,7 @@ static inline u32 hw_test_and_clear(struct ci_hdrc *ci, enum ci_hw_regs reg,
4016 + {
4017 + u32 val = ioread32(ci->hw_bank.regmap[reg]) & mask;
4018 +
4019 +- iowrite32(val, ci->hw_bank.regmap[reg]);
4020 ++ __hw_write(ci, val, ci->hw_bank.regmap[reg]);
4021 + return val;
4022 + }
4023 +
4024 +diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
4025 +index bb5d976e5b81..c00f77257d36 100644
4026 +--- a/drivers/usb/chipidea/ci_hdrc_imx.c
4027 ++++ b/drivers/usb/chipidea/ci_hdrc_imx.c
4028 +@@ -23,6 +23,26 @@
4029 + #include "ci.h"
4030 + #include "ci_hdrc_imx.h"
4031 +
4032 ++#define CI_HDRC_IMX_IMX28_WRITE_FIX BIT(0)
4033 ++
4034 ++struct ci_hdrc_imx_platform_flag {
4035 ++ unsigned int flags;
4036 ++};
4037 ++
4038 ++static const struct ci_hdrc_imx_platform_flag imx27_usb_data = {
4039 ++};
4040 ++
4041 ++static const struct ci_hdrc_imx_platform_flag imx28_usb_data = {
4042 ++ .flags = CI_HDRC_IMX_IMX28_WRITE_FIX,
4043 ++};
4044 ++
4045 ++static const struct of_device_id ci_hdrc_imx_dt_ids[] = {
4046 ++ { .compatible = "fsl,imx28-usb", .data = &imx28_usb_data},
4047 ++ { .compatible = "fsl,imx27-usb", .data = &imx27_usb_data},
4048 ++ { /* sentinel */ }
4049 ++};
4050 ++MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids);
4051 ++
4052 + struct ci_hdrc_imx_data {
4053 + struct usb_phy *phy;
4054 + struct platform_device *ci_pdev;
4055 +@@ -82,6 +102,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
4056 + CI_HDRC_DISABLE_STREAMING,
4057 + };
4058 + int ret;
4059 ++ const struct of_device_id *of_id =
4060 ++ of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev);
4061 ++ const struct ci_hdrc_imx_platform_flag *imx_platform_flag = of_id->data;
4062 +
4063 + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
4064 + if (!data) {
4065 +@@ -115,6 +138,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
4066 +
4067 + pdata.phy = data->phy;
4068 +
4069 ++ if (imx_platform_flag->flags & CI_HDRC_IMX_IMX28_WRITE_FIX)
4070 ++ pdata.flags |= CI_HDRC_IMX28_WRITE_FIX;
4071 ++
4072 + ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
4073 + if (ret)
4074 + goto err_clk;
4075 +@@ -173,12 +199,6 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
4076 + return 0;
4077 + }
4078 +
4079 +-static const struct of_device_id ci_hdrc_imx_dt_ids[] = {
4080 +- { .compatible = "fsl,imx27-usb", },
4081 +- { /* sentinel */ }
4082 +-};
4083 +-MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids);
4084 +-
4085 + static struct platform_driver ci_hdrc_imx_driver = {
4086 + .probe = ci_hdrc_imx_probe,
4087 + .remove = ci_hdrc_imx_remove,
4088 +diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
4089 +index 6e73f8cd60e5..5efdc9b45f89 100644
4090 +--- a/drivers/usb/chipidea/core.c
4091 ++++ b/drivers/usb/chipidea/core.c
4092 +@@ -554,6 +554,8 @@ static int ci_hdrc_probe(struct platform_device *pdev)
4093 +
4094 + ci->dev = dev;
4095 + ci->platdata = dev->platform_data;
4096 ++ ci->imx28_write_fix = !!(ci->platdata->flags &
4097 ++ CI_HDRC_IMX28_WRITE_FIX);
4098 +
4099 + ret = hw_device_init(ci, base);
4100 + if (ret < 0) {
4101 +diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
4102 +index 526cd77563d8..a8ac6c16dac9 100644
4103 +--- a/drivers/usb/chipidea/host.c
4104 ++++ b/drivers/usb/chipidea/host.c
4105 +@@ -65,6 +65,7 @@ static int host_start(struct ci_hdrc *ci)
4106 + ehci->caps = ci->hw_bank.cap;
4107 + ehci->has_hostpc = ci->hw_bank.lpm;
4108 + ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
4109 ++ ehci->imx28_write_fix = ci->imx28_write_fix;
4110 +
4111 + if (ci->platdata->reg_vbus) {
4112 + ret = regulator_enable(ci->platdata->reg_vbus);
4113 +diff --git a/drivers/usb/chipidea/otg.h b/drivers/usb/chipidea/otg.h
4114 +index 2d9f090733bc..449bee07f4fe 100644
4115 +--- a/drivers/usb/chipidea/otg.h
4116 ++++ b/drivers/usb/chipidea/otg.h
4117 +@@ -1,5 +1,5 @@
4118 + /*
4119 +- * Copyright (C) 2013 Freescale Semiconductor, Inc.
4120 ++ * Copyright (C) 2013-2014 Freescale Semiconductor, Inc.
4121 + *
4122 + * Author: Peter Chen
4123 + *
4124 +@@ -19,12 +19,12 @@ static inline void ci_clear_otg_interrupt(struct ci_hdrc *ci, u32 bits)
4125 +
4126 + static inline void ci_enable_otg_interrupt(struct ci_hdrc *ci, u32 bits)
4127 + {
4128 +- hw_write(ci, OP_OTGSC, bits, bits);
4129 ++ hw_write(ci, OP_OTGSC, bits | OTGSC_INT_STATUS_BITS, bits);
4130 + }
4131 +
4132 + static inline void ci_disable_otg_interrupt(struct ci_hdrc *ci, u32 bits)
4133 + {
4134 +- hw_write(ci, OP_OTGSC, bits, 0);
4135 ++ hw_write(ci, OP_OTGSC, bits | OTGSC_INT_STATUS_BITS, 0);
4136 + }
4137 +
4138 + int ci_hdrc_otg_init(struct ci_hdrc *ci);
4139 +diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
4140 +index 69d20fbb38a2..5875c2a8daf1 100644
4141 +--- a/drivers/usb/chipidea/udc.c
4142 ++++ b/drivers/usb/chipidea/udc.c
4143 +@@ -393,6 +393,14 @@ static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,
4144 + node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES));
4145 + node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES);
4146 + node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE);
4147 ++ if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) {
4148 ++ u32 mul = hwreq->req.length / hwep->ep.maxpacket;
4149 ++
4150 ++ if (hwreq->req.length == 0
4151 ++ || hwreq->req.length % hwep->ep.maxpacket)
4152 ++ mul++;
4153 ++ node->ptr->token |= mul << __ffs(TD_MULTO);
4154 ++ }
4155 +
4156 + temp = (u32) (hwreq->req.dma + hwreq->req.actual);
4157 + if (length) {
4158 +@@ -515,10 +523,11 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
4159 + hwep->qh.ptr->td.token &=
4160 + cpu_to_le32(~(TD_STATUS_HALTED|TD_STATUS_ACTIVE));
4161 +
4162 +- if (hwep->type == USB_ENDPOINT_XFER_ISOC) {
4163 ++ if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == RX) {
4164 + u32 mul = hwreq->req.length / hwep->ep.maxpacket;
4165 +
4166 +- if (hwreq->req.length % hwep->ep.maxpacket)
4167 ++ if (hwreq->req.length == 0
4168 ++ || hwreq->req.length % hwep->ep.maxpacket)
4169 + mul++;
4170 + hwep->qh.ptr->cap |= mul << __ffs(QH_MULT);
4171 + }
4172 +@@ -1173,6 +1182,12 @@ static int ep_enable(struct usb_ep *ep,
4173 + if (hwep->num)
4174 + cap |= QH_ZLT;
4175 + cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT;
4176 ++ /*
4177 ++ * For ISO-TX, we set mult at QH as the largest value, and use
4178 ++ * MultO at TD as real mult value.
4179 ++ */
4180 ++ if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX)
4181 ++ cap |= 3 << __ffs(QH_MULT);
4182 +
4183 + hwep->qh.ptr->cap = cpu_to_le32(cap);
4184 +
4185 +diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
4186 +index 0b23a8639311..a051a7a2b1bd 100644
4187 +--- a/drivers/usb/class/cdc-wdm.c
4188 ++++ b/drivers/usb/class/cdc-wdm.c
4189 +@@ -432,6 +432,38 @@ outnl:
4190 + return rv < 0 ? rv : count;
4191 + }
4192 +
4193 ++/*
4194 ++ * clear WDM_READ flag and possibly submit the read urb if resp_count
4195 ++ * is non-zero.
4196 ++ *
4197 ++ * Called with desc->iuspin locked
4198 ++ */
4199 ++static int clear_wdm_read_flag(struct wdm_device *desc)
4200 ++{
4201 ++ int rv = 0;
4202 ++
4203 ++ clear_bit(WDM_READ, &desc->flags);
4204 ++
4205 ++ /* submit read urb only if the device is waiting for it */
4206 ++ if (!desc->resp_count || !--desc->resp_count)
4207 ++ goto out;
4208 ++
4209 ++ set_bit(WDM_RESPONDING, &desc->flags);
4210 ++ spin_unlock_irq(&desc->iuspin);
4211 ++ rv = usb_submit_urb(desc->response, GFP_KERNEL);
4212 ++ spin_lock_irq(&desc->iuspin);
4213 ++ if (rv) {
4214 ++ dev_err(&desc->intf->dev,
4215 ++ "usb_submit_urb failed with result %d\n", rv);
4216 ++
4217 ++ /* make sure the next notification trigger a submit */
4218 ++ clear_bit(WDM_RESPONDING, &desc->flags);
4219 ++ desc->resp_count = 0;
4220 ++ }
4221 ++out:
4222 ++ return rv;
4223 ++}
4224 ++
4225 + static ssize_t wdm_read
4226 + (struct file *file, char __user *buffer, size_t count, loff_t *ppos)
4227 + {
4228 +@@ -503,8 +535,10 @@ retry:
4229 +
4230 + if (!desc->reslength) { /* zero length read */
4231 + dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__);
4232 +- clear_bit(WDM_READ, &desc->flags);
4233 ++ rv = clear_wdm_read_flag(desc);
4234 + spin_unlock_irq(&desc->iuspin);
4235 ++ if (rv < 0)
4236 ++ goto err;
4237 + goto retry;
4238 + }
4239 + cntr = desc->length;
4240 +@@ -526,37 +560,9 @@ retry:
4241 +
4242 + desc->length -= cntr;
4243 + /* in case we had outstanding data */
4244 +- if (!desc->length) {
4245 +- clear_bit(WDM_READ, &desc->flags);
4246 +-
4247 +- if (--desc->resp_count) {
4248 +- set_bit(WDM_RESPONDING, &desc->flags);
4249 +- spin_unlock_irq(&desc->iuspin);
4250 +-
4251 +- rv = usb_submit_urb(desc->response, GFP_KERNEL);
4252 +- if (rv) {
4253 +- dev_err(&desc->intf->dev,
4254 +- "%s: usb_submit_urb failed with result %d\n",
4255 +- __func__, rv);
4256 +- spin_lock_irq(&desc->iuspin);
4257 +- clear_bit(WDM_RESPONDING, &desc->flags);
4258 +- spin_unlock_irq(&desc->iuspin);
4259 +-
4260 +- if (rv == -ENOMEM) {
4261 +- rv = schedule_work(&desc->rxwork);
4262 +- if (rv)
4263 +- dev_err(&desc->intf->dev, "Cannot schedule work\n");
4264 +- } else {
4265 +- spin_lock_irq(&desc->iuspin);
4266 +- desc->resp_count = 0;
4267 +- spin_unlock_irq(&desc->iuspin);
4268 +- }
4269 +- }
4270 +- } else
4271 +- spin_unlock_irq(&desc->iuspin);
4272 +- } else
4273 +- spin_unlock_irq(&desc->iuspin);
4274 +-
4275 ++ if (!desc->length)
4276 ++ clear_wdm_read_flag(desc);
4277 ++ spin_unlock_irq(&desc->iuspin);
4278 + rv = cntr;
4279 +
4280 + err:
4281 +diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
4282 +index a6b2cabe7930..548d1996590f 100644
4283 +--- a/drivers/usb/core/config.c
4284 ++++ b/drivers/usb/core/config.c
4285 +@@ -651,10 +651,6 @@ void usb_destroy_configuration(struct usb_device *dev)
4286 + *
4287 + * hub-only!! ... and only in reset path, or usb_new_device()
4288 + * (used by real hubs and virtual root hubs)
4289 +- *
4290 +- * NOTE: if this is a WUSB device and is not authorized, we skip the
4291 +- * whole thing. A non-authorized USB device has no
4292 +- * configurations.
4293 + */
4294 + int usb_get_configuration(struct usb_device *dev)
4295 + {
4296 +@@ -666,8 +662,6 @@ int usb_get_configuration(struct usb_device *dev)
4297 + struct usb_config_descriptor *desc;
4298 +
4299 + cfgno = 0;
4300 +- if (dev->authorized == 0) /* Not really an error */
4301 +- goto out_not_authorized;
4302 + result = -ENOMEM;
4303 + if (ncfg > USB_MAXCONFIG) {
4304 + dev_warn(ddev, "too many configurations: %d, "
4305 +@@ -751,7 +745,6 @@ int usb_get_configuration(struct usb_device *dev)
4306 +
4307 + err:
4308 + kfree(desc);
4309 +-out_not_authorized:
4310 + dev->descriptor.bNumConfigurations = cfgno;
4311 + err2:
4312 + if (result == -ENOMEM)
4313 +diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
4314 +index bd9dc3504b51..07e66542ff24 100644
4315 +--- a/drivers/usb/core/hub.c
4316 ++++ b/drivers/usb/core/hub.c
4317 +@@ -1607,7 +1607,7 @@ static void hub_disconnect(struct usb_interface *intf)
4318 + {
4319 + struct usb_hub *hub = usb_get_intfdata(intf);
4320 + struct usb_device *hdev = interface_to_usbdev(intf);
4321 +- int i;
4322 ++ int port1;
4323 +
4324 + /* Take the hub off the event list and don't let it be added again */
4325 + spin_lock_irq(&hub_event_lock);
4326 +@@ -1622,11 +1622,15 @@ static void hub_disconnect(struct usb_interface *intf)
4327 + hub->error = 0;
4328 + hub_quiesce(hub, HUB_DISCONNECT);
4329 +
4330 +- usb_set_intfdata (intf, NULL);
4331 ++ /* Avoid races with recursively_mark_NOTATTACHED() */
4332 ++ spin_lock_irq(&device_state_lock);
4333 ++ port1 = hdev->maxchild;
4334 ++ hdev->maxchild = 0;
4335 ++ usb_set_intfdata(intf, NULL);
4336 ++ spin_unlock_irq(&device_state_lock);
4337 +
4338 +- for (i = 0; i < hdev->maxchild; i++)
4339 +- usb_hub_remove_port_device(hub, i + 1);
4340 +- hub->hdev->maxchild = 0;
4341 ++ for (; port1 > 0; --port1)
4342 ++ usb_hub_remove_port_device(hub, port1);
4343 +
4344 + if (hub->hdev->speed == USB_SPEED_HIGH)
4345 + highspeed_hubs--;
4346 +@@ -2235,17 +2239,13 @@ static int usb_enumerate_device(struct usb_device *udev)
4347 + return err;
4348 + }
4349 + }
4350 +- if (udev->wusb == 1 && udev->authorized == 0) {
4351 +- udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL);
4352 +- udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL);
4353 +- udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL);
4354 +- } else {
4355 +- /* read the standard strings and cache them if present */
4356 +- udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
4357 +- udev->manufacturer = usb_cache_string(udev,
4358 +- udev->descriptor.iManufacturer);
4359 +- udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber);
4360 +- }
4361 ++
4362 ++ /* read the standard strings and cache them if present */
4363 ++ udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
4364 ++ udev->manufacturer = usb_cache_string(udev,
4365 ++ udev->descriptor.iManufacturer);
4366 ++ udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber);
4367 ++
4368 + err = usb_enumerate_device_otg(udev);
4369 + if (err < 0)
4370 + return err;
4371 +@@ -2427,16 +2427,6 @@ int usb_deauthorize_device(struct usb_device *usb_dev)
4372 + usb_dev->authorized = 0;
4373 + usb_set_configuration(usb_dev, -1);
4374 +
4375 +- kfree(usb_dev->product);
4376 +- usb_dev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL);
4377 +- kfree(usb_dev->manufacturer);
4378 +- usb_dev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL);
4379 +- kfree(usb_dev->serial);
4380 +- usb_dev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL);
4381 +-
4382 +- usb_destroy_configuration(usb_dev);
4383 +- usb_dev->descriptor.bNumConfigurations = 0;
4384 +-
4385 + out_unauthorized:
4386 + usb_unlock_device(usb_dev);
4387 + return 0;
4388 +@@ -2464,17 +2454,7 @@ int usb_authorize_device(struct usb_device *usb_dev)
4389 + goto error_device_descriptor;
4390 + }
4391 +
4392 +- kfree(usb_dev->product);
4393 +- usb_dev->product = NULL;
4394 +- kfree(usb_dev->manufacturer);
4395 +- usb_dev->manufacturer = NULL;
4396 +- kfree(usb_dev->serial);
4397 +- usb_dev->serial = NULL;
4398 +-
4399 + usb_dev->authorized = 1;
4400 +- result = usb_enumerate_device(usb_dev);
4401 +- if (result < 0)
4402 +- goto error_enumerate;
4403 + /* Choose and set the configuration. This registers the interfaces
4404 + * with the driver core and lets interface drivers bind to them.
4405 + */
4406 +@@ -2490,7 +2470,6 @@ int usb_authorize_device(struct usb_device *usb_dev)
4407 + }
4408 + dev_info(&usb_dev->dev, "authorized to connect\n");
4409 +
4410 +-error_enumerate:
4411 + error_device_descriptor:
4412 + usb_autosuspend_device(usb_dev);
4413 + error_autoresume:
4414 +diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
4415 +index 8b20c70d91e7..28c8ad79f5e6 100644
4416 +--- a/drivers/usb/dwc3/dwc3-exynos.c
4417 ++++ b/drivers/usb/dwc3/dwc3-exynos.c
4418 +@@ -50,6 +50,7 @@ static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
4419 +
4420 + exynos->usb2_phy = pdev;
4421 + pdata.type = USB_PHY_TYPE_USB2;
4422 ++ pdata.gpio_reset = -1;
4423 +
4424 + ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
4425 + if (ret)
4426 +diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
4427 +index 31443aeedcdb..7e71bfa09b54 100644
4428 +--- a/drivers/usb/dwc3/dwc3-pci.c
4429 ++++ b/drivers/usb/dwc3/dwc3-pci.c
4430 +@@ -52,6 +52,7 @@ static int dwc3_pci_register_phys(struct dwc3_pci *glue)
4431 +
4432 + glue->usb2_phy = pdev;
4433 + pdata.type = USB_PHY_TYPE_USB2;
4434 ++ pdata.gpio_reset = -1;
4435 +
4436 + ret = platform_device_add_data(glue->usb2_phy, &pdata, sizeof(pdata));
4437 + if (ret)
4438 +diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
4439 +index e8f41c5e771b..bf4555abdd06 100644
4440 +--- a/drivers/usb/host/ehci.h
4441 ++++ b/drivers/usb/host/ehci.h
4442 +@@ -225,6 +225,7 @@ struct ehci_hcd { /* one per controller */
4443 + unsigned has_synopsys_hc_bug:1; /* Synopsys HC */
4444 + unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */
4445 + unsigned need_oc_pp_cycle:1; /* MPC834X port power */
4446 ++ unsigned imx28_write_fix:1; /* For Freescale i.MX28 */
4447 +
4448 + /* required for usb32 quirk */
4449 + #define OHCI_CTRL_HCFS (3 << 6)
4450 +@@ -728,6 +729,18 @@ static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
4451 + #endif
4452 + }
4453 +
4454 ++#ifdef CONFIG_SOC_IMX28
4455 ++static inline void imx28_ehci_writel(const unsigned int val,
4456 ++ volatile __u32 __iomem *addr)
4457 ++{
4458 ++ __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr));
4459 ++}
4460 ++#else
4461 ++static inline void imx28_ehci_writel(const unsigned int val,
4462 ++ volatile __u32 __iomem *addr)
4463 ++{
4464 ++}
4465 ++#endif
4466 + static inline void ehci_writel(const struct ehci_hcd *ehci,
4467 + const unsigned int val, __u32 __iomem *regs)
4468 + {
4469 +@@ -736,7 +749,10 @@ static inline void ehci_writel(const struct ehci_hcd *ehci,
4470 + writel_be(val, regs) :
4471 + writel(val, regs);
4472 + #else
4473 +- writel(val, regs);
4474 ++ if (ehci->imx28_write_fix)
4475 ++ imx28_ehci_writel(val, regs);
4476 ++ else
4477 ++ writel(val, regs);
4478 + #endif
4479 + }
4480 +
4481 +diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
4482 +index 53c2e296467f..64c36fe1ea6a 100644
4483 +--- a/drivers/usb/host/xhci-ring.c
4484 ++++ b/drivers/usb/host/xhci-ring.c
4485 +@@ -3008,7 +3008,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
4486 + if (num_trbs >= TRBS_PER_SEGMENT) {
4487 + xhci_err(xhci, "Too many fragments %d, max %d\n",
4488 + num_trbs, TRBS_PER_SEGMENT - 1);
4489 +- return -ENOMEM;
4490 ++ return -EINVAL;
4491 + }
4492 +
4493 + nop_cmd = cpu_to_le32(TRB_TYPE(TRB_TR_NOOP) |
4494 +diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
4495 +index 4265b48856f6..cfa5995c7e1f 100644
4496 +--- a/drivers/usb/host/xhci.c
4497 ++++ b/drivers/usb/host/xhci.c
4498 +@@ -321,6 +321,9 @@ static void xhci_cleanup_msix(struct xhci_hcd *xhci)
4499 + struct usb_hcd *hcd = xhci_to_hcd(xhci);
4500 + struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
4501 +
4502 ++ if (xhci->quirks & XHCI_PLAT)
4503 ++ return;
4504 ++
4505 + xhci_free_irq(xhci);
4506 +
4507 + if (xhci->msix_entries) {
4508 +@@ -4713,8 +4716,8 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4509 + struct device *dev = hcd->self.controller;
4510 + int retval;
4511 +
4512 +- /* Accept arbitrarily long scatter-gather lists */
4513 +- hcd->self.sg_tablesize = ~0;
4514 ++ /* Limit the block layer scatter-gather lists to half a segment. */
4515 ++ hcd->self.sg_tablesize = TRBS_PER_SEGMENT / 2;
4516 +
4517 + /* support to build packet from discontinuous buffers */
4518 + hcd->self.no_sg_constraint = 1;
4519 +diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
4520 +index 03c74b7965f8..c283cf183c48 100644
4521 +--- a/drivers/usb/host/xhci.h
4522 ++++ b/drivers/usb/host/xhci.h
4523 +@@ -1260,7 +1260,7 @@ union xhci_trb {
4524 + * since the command ring is 64-byte aligned.
4525 + * It must also be greater than 16.
4526 + */
4527 +-#define TRBS_PER_SEGMENT 64
4528 ++#define TRBS_PER_SEGMENT 256
4529 + /* Allow two commands + a link TRB, along with any reserved command TRBs */
4530 + #define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
4531 + #define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
4532 +diff --git a/drivers/usb/serial/cypress_m8.h b/drivers/usb/serial/cypress_m8.h
4533 +index b461311a2ae7..ce13e61b7d55 100644
4534 +--- a/drivers/usb/serial/cypress_m8.h
4535 ++++ b/drivers/usb/serial/cypress_m8.h
4536 +@@ -63,7 +63,7 @@
4537 + #define UART_DSR 0x20 /* data set ready - flow control - device to host */
4538 + #define CONTROL_RTS 0x10 /* request to send - flow control - host to device */
4539 + #define UART_CTS 0x10 /* clear to send - flow control - device to host */
4540 +-#define UART_RI 0x10 /* ring indicator - modem - device to host */
4541 ++#define UART_RI 0x80 /* ring indicator - modem - device to host */
4542 + #define UART_CD 0x40 /* carrier detect - modem - device to host */
4543 + #define CYP_ERROR 0x08 /* received from input report - device to host */
4544 + /* Note - the below has nothing to do with the "feature report" reset */
4545 +diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
4546 +index fb0d537435eb..8c204a52d534 100644
4547 +--- a/drivers/usb/serial/ftdi_sio.c
4548 ++++ b/drivers/usb/serial/ftdi_sio.c
4549 +@@ -2124,10 +2124,20 @@ static void ftdi_set_termios(struct tty_struct *tty,
4550 + }
4551 +
4552 + /*
4553 +- * All FTDI UART chips are limited to CS7/8. We won't pretend to
4554 ++ * All FTDI UART chips are limited to CS7/8. We shouldn't pretend to
4555 + * support CS5/6 and revert the CSIZE setting instead.
4556 ++ *
4557 ++ * CS5 however is used to control some smartcard readers which abuse
4558 ++ * this limitation to switch modes. Original FTDI chips fall back to
4559 ++ * eight data bits.
4560 ++ *
4561 ++ * TODO: Implement a quirk to only allow this with mentioned
4562 ++ * readers. One I know of (Argolis Smartreader V1)
4563 ++ * returns "USB smartcard server" as iInterface string.
4564 ++ * The vendor didn't bother with a custom VID/PID of
4565 ++ * course.
4566 + */
4567 +- if ((C_CSIZE(tty) != CS8) && (C_CSIZE(tty) != CS7)) {
4568 ++ if (C_CSIZE(tty) == CS6) {
4569 + dev_warn(ddev, "requested CSIZE setting not supported\n");
4570 +
4571 + termios->c_cflag &= ~CSIZE;
4572 +@@ -2174,6 +2184,9 @@ no_skip:
4573 + urb_value |= FTDI_SIO_SET_DATA_PARITY_NONE;
4574 + }
4575 + switch (cflag & CSIZE) {
4576 ++ case CS5:
4577 ++ dev_dbg(ddev, "Setting CS5 quirk\n");
4578 ++ break;
4579 + case CS7:
4580 + urb_value |= 7;
4581 + dev_dbg(ddev, "Setting CS7\n");
4582 +diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
4583 +index cc7a24154490..5c86f57e4afa 100644
4584 +--- a/drivers/usb/serial/option.c
4585 ++++ b/drivers/usb/serial/option.c
4586 +@@ -320,6 +320,9 @@ static void option_instat_callback(struct urb *urb);
4587 + * It seems to contain a Qualcomm QSC6240/6290 chipset */
4588 + #define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603
4589 +
4590 ++/* iBall 3.5G connect wireless modem */
4591 ++#define IBALL_3_5G_CONNECT 0x9605
4592 ++
4593 + /* Zoom */
4594 + #define ZOOM_PRODUCT_4597 0x9607
4595 +
4596 +@@ -1447,6 +1450,17 @@ static const struct usb_device_id option_ids[] = {
4597 + .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
4598 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0178, 0xff, 0xff, 0xff),
4599 + .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
4600 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xffe9, 0xff, 0xff, 0xff) },
4601 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8b, 0xff, 0xff, 0xff) },
4602 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8c, 0xff, 0xff, 0xff) },
4603 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8d, 0xff, 0xff, 0xff) },
4604 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8e, 0xff, 0xff, 0xff) },
4605 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8f, 0xff, 0xff, 0xff) },
4606 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff90, 0xff, 0xff, 0xff) },
4607 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff91, 0xff, 0xff, 0xff) },
4608 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff92, 0xff, 0xff, 0xff) },
4609 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff93, 0xff, 0xff, 0xff) },
4610 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff94, 0xff, 0xff, 0xff) },
4611 +
4612 + /* NOTE: most ZTE CDMA devices should be driven by zte_ev, not option */
4613 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2718, 0xff, 0xff, 0xff),
4614 +@@ -1489,6 +1503,7 @@ static const struct usb_device_id option_ids[] = {
4615 + .driver_info = (kernel_ulong_t)&four_g_w14_blacklist
4616 + },
4617 + { USB_DEVICE(LONGCHEER_VENDOR_ID, ZOOM_PRODUCT_4597) },
4618 ++ { USB_DEVICE(LONGCHEER_VENDOR_ID, IBALL_3_5G_CONNECT) },
4619 + { USB_DEVICE(HAIER_VENDOR_ID, HAIER_PRODUCT_CE100) },
4620 + /* Pirelli */
4621 + { USB_DEVICE_INTERFACE_CLASS(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_C100_1, 0xff) },
4622 +diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
4623 +index 1e3318dfa1cb..beb8edce4ef2 100644
4624 +--- a/drivers/usb/serial/pl2303.c
4625 ++++ b/drivers/usb/serial/pl2303.c
4626 +@@ -142,6 +142,8 @@ struct pl2303_private {
4627 + spinlock_t lock;
4628 + u8 line_control;
4629 + u8 line_status;
4630 ++
4631 ++ u8 line_settings[7];
4632 + };
4633 +
4634 + static int pl2303_vendor_read(__u16 value, __u16 index,
4635 +@@ -339,11 +341,6 @@ static void pl2303_set_termios(struct tty_struct *tty,
4636 + int i;
4637 + u8 control;
4638 +
4639 +- /*
4640 +- * The PL2303 is reported to lose bytes if you change serial settings
4641 +- * even to the same values as before. Thus we actually need to filter
4642 +- * in this specific case.
4643 +- */
4644 + if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios))
4645 + return;
4646 +
4647 +@@ -428,10 +425,29 @@ static void pl2303_set_termios(struct tty_struct *tty,
4648 + dev_dbg(&port->dev, "parity = none\n");
4649 + }
4650 +
4651 +- i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
4652 +- SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
4653 +- 0, 0, buf, 7, 100);
4654 +- dev_dbg(&port->dev, "0x21:0x20:0:0 %d\n", i);
4655 ++ /*
4656 ++ * Some PL2303 are known to lose bytes if you change serial settings
4657 ++ * even to the same values as before. Thus we actually need to filter
4658 ++ * in this specific case.
4659 ++ *
4660 ++ * Note that the tty_termios_hw_change check above is not sufficient
4661 ++ * as a previously requested baud rate may differ from the one
4662 ++ * actually used (and stored in old_termios).
4663 ++ *
4664 ++ * NOTE: No additional locking needed for line_settings as it is
4665 ++ * only used in set_termios, which is serialised against itself.
4666 ++ */
4667 ++ if (!old_termios || memcmp(buf, priv->line_settings, 7)) {
4668 ++ i = usb_control_msg(serial->dev,
4669 ++ usb_sndctrlpipe(serial->dev, 0),
4670 ++ SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
4671 ++ 0, 0, buf, 7, 100);
4672 ++
4673 ++ dev_dbg(&port->dev, "0x21:0x20:0:0 %d\n", i);
4674 ++
4675 ++ if (i == 7)
4676 ++ memcpy(priv->line_settings, buf, 7);
4677 ++ }
4678 +
4679 + /* change control lines if we are switching to or from B0 */
4680 + spin_lock_irqsave(&priv->lock, flags);
4681 +diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
4682 +index de32cfa5bfa6..ad06255c2ade 100644
4683 +--- a/drivers/usb/storage/unusual_devs.h
4684 ++++ b/drivers/usb/storage/unusual_devs.h
4685 +@@ -234,6 +234,13 @@ UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370,
4686 + USB_SC_DEVICE, USB_PR_DEVICE, NULL,
4687 + US_FL_MAX_SECTORS_64 ),
4688 +
4689 ++/* Patch submitted by Mikhail Zolotaryov <lebon@×××××××××.ua> */
4690 ++UNUSUAL_DEV( 0x0421, 0x06aa, 0x1110, 0x1110,
4691 ++ "Nokia",
4692 ++ "502",
4693 ++ USB_SC_DEVICE, USB_PR_DEVICE, NULL,
4694 ++ US_FL_MAX_SECTORS_64 ),
4695 ++
4696 + #ifdef NO_SDDR09
4697 + UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
4698 + "Microtech",
4699 +diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
4700 +index 4ad24f2c6472..cecd3de01c24 100644
4701 +--- a/drivers/video/console/sticore.c
4702 ++++ b/drivers/video/console/sticore.c
4703 +@@ -488,7 +488,7 @@ static int sti_init_glob_cfg(struct sti_struct *sti, unsigned long rom_address,
4704 + return 0;
4705 + }
4706 +
4707 +-#ifdef CONFIG_FONTS
4708 ++#ifdef CONFIG_FONT_SUPPORT
4709 + static struct sti_cooked_font *
4710 + sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
4711 + {
4712 +diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c
4713 +index 188825122aae..dd9c249ea311 100644
4714 +--- a/drivers/xen/pci.c
4715 ++++ b/drivers/xen/pci.c
4716 +@@ -26,7 +26,9 @@
4717 + #include <asm/xen/hypervisor.h>
4718 + #include <asm/xen/hypercall.h>
4719 + #include "../pci/pci.h"
4720 ++#ifdef CONFIG_PCI_MMCONFIG
4721 + #include <asm/pci_x86.h>
4722 ++#endif
4723 +
4724 + static bool __read_mostly pci_seg_supported = true;
4725 +
4726 +diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
4727 +index 9c01509dd8ab..72d7307151c9 100644
4728 +--- a/fs/btrfs/extent-tree.c
4729 ++++ b/fs/btrfs/extent-tree.c
4730 +@@ -7779,7 +7779,7 @@ out:
4731 + */
4732 + if (!for_reloc && root_dropped == false)
4733 + btrfs_add_dead_root(root);
4734 +- if (err)
4735 ++ if (err && err != -EAGAIN)
4736 + btrfs_std_error(root->fs_info, err);
4737 + return err;
4738 + }
4739 +diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
4740 +index f1a77449d032..34ee498ff1ce 100644
4741 +--- a/fs/btrfs/inode.c
4742 ++++ b/fs/btrfs/inode.c
4743 +@@ -60,7 +60,7 @@
4744 + #include "hash.h"
4745 +
4746 + struct btrfs_iget_args {
4747 +- u64 ino;
4748 ++ struct btrfs_key *location;
4749 + struct btrfs_root *root;
4750 + };
4751 +
4752 +@@ -4818,7 +4818,9 @@ again:
4753 + static int btrfs_init_locked_inode(struct inode *inode, void *p)
4754 + {
4755 + struct btrfs_iget_args *args = p;
4756 +- inode->i_ino = args->ino;
4757 ++ inode->i_ino = args->location->objectid;
4758 ++ memcpy(&BTRFS_I(inode)->location, args->location,
4759 ++ sizeof(*args->location));
4760 + BTRFS_I(inode)->root = args->root;
4761 + return 0;
4762 + }
4763 +@@ -4826,19 +4828,19 @@ static int btrfs_init_locked_inode(struct inode *inode, void *p)
4764 + static int btrfs_find_actor(struct inode *inode, void *opaque)
4765 + {
4766 + struct btrfs_iget_args *args = opaque;
4767 +- return args->ino == btrfs_ino(inode) &&
4768 ++ return args->location->objectid == BTRFS_I(inode)->location.objectid &&
4769 + args->root == BTRFS_I(inode)->root;
4770 + }
4771 +
4772 + static struct inode *btrfs_iget_locked(struct super_block *s,
4773 +- u64 objectid,
4774 ++ struct btrfs_key *location,
4775 + struct btrfs_root *root)
4776 + {
4777 + struct inode *inode;
4778 + struct btrfs_iget_args args;
4779 +- unsigned long hashval = btrfs_inode_hash(objectid, root);
4780 ++ unsigned long hashval = btrfs_inode_hash(location->objectid, root);
4781 +
4782 +- args.ino = objectid;
4783 ++ args.location = location;
4784 + args.root = root;
4785 +
4786 + inode = iget5_locked(s, hashval, btrfs_find_actor,
4787 +@@ -4855,13 +4857,11 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
4788 + {
4789 + struct inode *inode;
4790 +
4791 +- inode = btrfs_iget_locked(s, location->objectid, root);
4792 ++ inode = btrfs_iget_locked(s, location, root);
4793 + if (!inode)
4794 + return ERR_PTR(-ENOMEM);
4795 +
4796 + if (inode->i_state & I_NEW) {
4797 +- BTRFS_I(inode)->root = root;
4798 +- memcpy(&BTRFS_I(inode)->location, location, sizeof(*location));
4799 + btrfs_read_locked_inode(inode);
4800 + if (!is_bad_inode(inode)) {
4801 + inode_tree_add(inode);
4802 +diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
4803 +index 21da5762b0b1..9f831bb3dbee 100644
4804 +--- a/fs/btrfs/ioctl.c
4805 ++++ b/fs/btrfs/ioctl.c
4806 +@@ -1545,6 +1545,12 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file,
4807 + printk(KERN_INFO "btrfs: Snapshot src from "
4808 + "another FS\n");
4809 + ret = -EINVAL;
4810 ++ } else if (!inode_owner_or_capable(src_inode)) {
4811 ++ /*
4812 ++ * Subvolume creation is not restricted, but snapshots
4813 ++ * are limited to own subvolumes only
4814 ++ */
4815 ++ ret = -EPERM;
4816 + } else {
4817 + ret = btrfs_mksubvol(&file->f_path, name, namelen,
4818 + BTRFS_I(src_inode)->root,
4819 +diff --git a/fs/dcache.c b/fs/dcache.c
4820 +index cb4a10690868..fdbe23027810 100644
4821 +--- a/fs/dcache.c
4822 ++++ b/fs/dcache.c
4823 +@@ -3135,7 +3135,6 @@ restart:
4824 + read_seqbegin_or_lock(&rename_lock, &seq);
4825 + while (!IS_ROOT(dentry)) {
4826 + struct dentry *parent = dentry->d_parent;
4827 +- int error;
4828 +
4829 + prefetch(parent);
4830 + error = prepend_name(&end, &len, &dentry->d_name);
4831 +diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
4832 +index bae987549dc3..7f032085cbf1 100644
4833 +--- a/fs/ext4/inline.c
4834 ++++ b/fs/ext4/inline.c
4835 +@@ -1924,9 +1924,11 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
4836 + }
4837 +
4838 + /* Clear the content within i_blocks. */
4839 +- if (i_size < EXT4_MIN_INLINE_DATA_SIZE)
4840 +- memset(ext4_raw_inode(&is.iloc)->i_block + i_size, 0,
4841 +- EXT4_MIN_INLINE_DATA_SIZE - i_size);
4842 ++ if (i_size < EXT4_MIN_INLINE_DATA_SIZE) {
4843 ++ void *p = (void *) ext4_raw_inode(&is.iloc)->i_block;
4844 ++ memset(p + i_size, 0,
4845 ++ EXT4_MIN_INLINE_DATA_SIZE - i_size);
4846 ++ }
4847 +
4848 + EXT4_I(inode)->i_inline_size = i_size <
4849 + EXT4_MIN_INLINE_DATA_SIZE ?
4850 +diff --git a/fs/hpfs/alloc.c b/fs/hpfs/alloc.c
4851 +index cdb84a838068..58b5106186d0 100644
4852 +--- a/fs/hpfs/alloc.c
4853 ++++ b/fs/hpfs/alloc.c
4854 +@@ -8,6 +8,58 @@
4855 +
4856 + #include "hpfs_fn.h"
4857 +
4858 ++static void hpfs_claim_alloc(struct super_block *s, secno sec)
4859 ++{
4860 ++ struct hpfs_sb_info *sbi = hpfs_sb(s);
4861 ++ if (sbi->sb_n_free != (unsigned)-1) {
4862 ++ if (unlikely(!sbi->sb_n_free)) {
4863 ++ hpfs_error(s, "free count underflow, allocating sector %08x", sec);
4864 ++ sbi->sb_n_free = -1;
4865 ++ return;
4866 ++ }
4867 ++ sbi->sb_n_free--;
4868 ++ }
4869 ++}
4870 ++
4871 ++static void hpfs_claim_free(struct super_block *s, secno sec)
4872 ++{
4873 ++ struct hpfs_sb_info *sbi = hpfs_sb(s);
4874 ++ if (sbi->sb_n_free != (unsigned)-1) {
4875 ++ if (unlikely(sbi->sb_n_free >= sbi->sb_fs_size)) {
4876 ++ hpfs_error(s, "free count overflow, freeing sector %08x", sec);
4877 ++ sbi->sb_n_free = -1;
4878 ++ return;
4879 ++ }
4880 ++ sbi->sb_n_free++;
4881 ++ }
4882 ++}
4883 ++
4884 ++static void hpfs_claim_dirband_alloc(struct super_block *s, secno sec)
4885 ++{
4886 ++ struct hpfs_sb_info *sbi = hpfs_sb(s);
4887 ++ if (sbi->sb_n_free_dnodes != (unsigned)-1) {
4888 ++ if (unlikely(!sbi->sb_n_free_dnodes)) {
4889 ++ hpfs_error(s, "dirband free count underflow, allocating sector %08x", sec);
4890 ++ sbi->sb_n_free_dnodes = -1;
4891 ++ return;
4892 ++ }
4893 ++ sbi->sb_n_free_dnodes--;
4894 ++ }
4895 ++}
4896 ++
4897 ++static void hpfs_claim_dirband_free(struct super_block *s, secno sec)
4898 ++{
4899 ++ struct hpfs_sb_info *sbi = hpfs_sb(s);
4900 ++ if (sbi->sb_n_free_dnodes != (unsigned)-1) {
4901 ++ if (unlikely(sbi->sb_n_free_dnodes >= sbi->sb_dirband_size / 4)) {
4902 ++ hpfs_error(s, "dirband free count overflow, freeing sector %08x", sec);
4903 ++ sbi->sb_n_free_dnodes = -1;
4904 ++ return;
4905 ++ }
4906 ++ sbi->sb_n_free_dnodes++;
4907 ++ }
4908 ++}
4909 ++
4910 + /*
4911 + * Check if a sector is allocated in bitmap
4912 + * This is really slow. Turned on only if chk==2
4913 +@@ -203,9 +255,15 @@ secno hpfs_alloc_sector(struct super_block *s, secno near, unsigned n, int forwa
4914 + }
4915 + sec = 0;
4916 + ret:
4917 ++ if (sec) {
4918 ++ i = 0;
4919 ++ do
4920 ++ hpfs_claim_alloc(s, sec + i);
4921 ++ while (unlikely(++i < n));
4922 ++ }
4923 + if (sec && f_p) {
4924 + for (i = 0; i < forward; i++) {
4925 +- if (!hpfs_alloc_if_possible(s, sec + i + 1)) {
4926 ++ if (!hpfs_alloc_if_possible(s, sec + n + i)) {
4927 + hpfs_error(s, "Prealloc doesn't work! Wanted %d, allocated at %08x, can't allocate %d", forward, sec, i);
4928 + sec = 0;
4929 + break;
4930 +@@ -228,6 +286,7 @@ static secno alloc_in_dirband(struct super_block *s, secno near)
4931 + nr >>= 2;
4932 + sec = alloc_in_bmp(s, (~0x3fff) | nr, 1, 0);
4933 + if (!sec) return 0;
4934 ++ hpfs_claim_dirband_alloc(s, sec);
4935 + return ((sec & 0x3fff) << 2) + sbi->sb_dirband_start;
4936 + }
4937 +
4938 +@@ -242,6 +301,7 @@ int hpfs_alloc_if_possible(struct super_block *s, secno sec)
4939 + bmp[(sec & 0x3fff) >> 5] &= cpu_to_le32(~(1 << (sec & 0x1f)));
4940 + hpfs_mark_4buffers_dirty(&qbh);
4941 + hpfs_brelse4(&qbh);
4942 ++ hpfs_claim_alloc(s, sec);
4943 + return 1;
4944 + }
4945 + hpfs_brelse4(&qbh);
4946 +@@ -275,6 +335,7 @@ void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n)
4947 + return;
4948 + }
4949 + bmp[(sec & 0x3fff) >> 5] |= cpu_to_le32(1 << (sec & 0x1f));
4950 ++ hpfs_claim_free(s, sec);
4951 + if (!--n) {
4952 + hpfs_mark_4buffers_dirty(&qbh);
4953 + hpfs_brelse4(&qbh);
4954 +@@ -359,6 +420,7 @@ void hpfs_free_dnode(struct super_block *s, dnode_secno dno)
4955 + bmp[ssec >> 5] |= cpu_to_le32(1 << (ssec & 0x1f));
4956 + hpfs_mark_4buffers_dirty(&qbh);
4957 + hpfs_brelse4(&qbh);
4958 ++ hpfs_claim_dirband_free(s, dno);
4959 + }
4960 + }
4961 +
4962 +@@ -366,7 +428,7 @@ struct dnode *hpfs_alloc_dnode(struct super_block *s, secno near,
4963 + dnode_secno *dno, struct quad_buffer_head *qbh)
4964 + {
4965 + struct dnode *d;
4966 +- if (hpfs_count_one_bitmap(s, hpfs_sb(s)->sb_dmap) > FREE_DNODES_ADD) {
4967 ++ if (hpfs_get_free_dnodes(s) > FREE_DNODES_ADD) {
4968 + if (!(*dno = alloc_in_dirband(s, near)))
4969 + if (!(*dno = hpfs_alloc_sector(s, near, 4, 0))) return NULL;
4970 + } else {
4971 +diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h
4972 +index 6797bf80f6e2..3ba49c080e42 100644
4973 +--- a/fs/hpfs/hpfs_fn.h
4974 ++++ b/fs/hpfs/hpfs_fn.h
4975 +@@ -312,7 +312,7 @@ static inline struct hpfs_sb_info *hpfs_sb(struct super_block *sb)
4976 + __printf(2, 3)
4977 + void hpfs_error(struct super_block *, const char *, ...);
4978 + int hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
4979 +-unsigned hpfs_count_one_bitmap(struct super_block *, secno);
4980 ++unsigned hpfs_get_free_dnodes(struct super_block *);
4981 +
4982 + /*
4983 + * local time (HPFS) to GMT (Unix)
4984 +diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
4985 +index b8d01ef6f531..4534ff688b76 100644
4986 +--- a/fs/hpfs/super.c
4987 ++++ b/fs/hpfs/super.c
4988 +@@ -121,7 +121,7 @@ static void hpfs_put_super(struct super_block *s)
4989 + call_rcu(&hpfs_sb(s)->rcu, lazy_free_sbi);
4990 + }
4991 +
4992 +-unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
4993 ++static unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
4994 + {
4995 + struct quad_buffer_head qbh;
4996 + unsigned long *bits;
4997 +@@ -129,7 +129,7 @@ unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
4998 +
4999 + bits = hpfs_map_4sectors(s, secno, &qbh, 0);
5000 + if (!bits)
5001 +- return 0;
5002 ++ return (unsigned)-1;
5003 + count = bitmap_weight(bits, 2048 * BITS_PER_BYTE);
5004 + hpfs_brelse4(&qbh);
5005 + return count;
5006 +@@ -144,30 +144,45 @@ static unsigned count_bitmaps(struct super_block *s)
5007 + hpfs_prefetch_bitmap(s, n);
5008 + }
5009 + for (n = 0; n < n_bands; n++) {
5010 ++ unsigned c;
5011 + hpfs_prefetch_bitmap(s, n + COUNT_RD_AHEAD);
5012 +- count += hpfs_count_one_bitmap(s, le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[n]));
5013 ++ c = hpfs_count_one_bitmap(s, le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[n]));
5014 ++ if (c != (unsigned)-1)
5015 ++ count += c;
5016 + }
5017 + return count;
5018 + }
5019 +
5020 ++unsigned hpfs_get_free_dnodes(struct super_block *s)
5021 ++{
5022 ++ struct hpfs_sb_info *sbi = hpfs_sb(s);
5023 ++ if (sbi->sb_n_free_dnodes == (unsigned)-1) {
5024 ++ unsigned c = hpfs_count_one_bitmap(s, sbi->sb_dmap);
5025 ++ if (c == (unsigned)-1)
5026 ++ return 0;
5027 ++ sbi->sb_n_free_dnodes = c;
5028 ++ }
5029 ++ return sbi->sb_n_free_dnodes;
5030 ++}
5031 ++
5032 + static int hpfs_statfs(struct dentry *dentry, struct kstatfs *buf)
5033 + {
5034 + struct super_block *s = dentry->d_sb;
5035 + struct hpfs_sb_info *sbi = hpfs_sb(s);
5036 + u64 id = huge_encode_dev(s->s_bdev->bd_dev);
5037 ++
5038 + hpfs_lock(s);
5039 +
5040 +- /*if (sbi->sb_n_free == -1) {*/
5041 ++ if (sbi->sb_n_free == (unsigned)-1)
5042 + sbi->sb_n_free = count_bitmaps(s);
5043 +- sbi->sb_n_free_dnodes = hpfs_count_one_bitmap(s, sbi->sb_dmap);
5044 +- /*}*/
5045 ++
5046 + buf->f_type = s->s_magic;
5047 + buf->f_bsize = 512;
5048 + buf->f_blocks = sbi->sb_fs_size;
5049 + buf->f_bfree = sbi->sb_n_free;
5050 + buf->f_bavail = sbi->sb_n_free;
5051 + buf->f_files = sbi->sb_dirband_size / 4;
5052 +- buf->f_ffree = sbi->sb_n_free_dnodes;
5053 ++ buf->f_ffree = hpfs_get_free_dnodes(s);
5054 + buf->f_fsid.val[0] = (u32)id;
5055 + buf->f_fsid.val[1] = (u32)(id >> 32);
5056 + buf->f_namelen = 254;
5057 +diff --git a/fs/mount.h b/fs/mount.h
5058 +index d64c594be6c4..a17458ca6f29 100644
5059 +--- a/fs/mount.h
5060 ++++ b/fs/mount.h
5061 +@@ -74,7 +74,7 @@ static inline int mnt_has_parent(struct mount *mnt)
5062 + static inline int is_mounted(struct vfsmount *mnt)
5063 + {
5064 + /* neither detached nor internal? */
5065 +- return !IS_ERR_OR_NULL(real_mount(mnt));
5066 ++ return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
5067 + }
5068 +
5069 + extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
5070 +diff --git a/include/linux/libata.h b/include/linux/libata.h
5071 +index 9b503376738f..bec6dbe939a0 100644
5072 +--- a/include/linux/libata.h
5073 ++++ b/include/linux/libata.h
5074 +@@ -419,6 +419,8 @@ enum {
5075 + ATA_HORKAGE_MAX_SEC_LBA48 = (1 << 17), /* Set max sects to 65535 */
5076 + ATA_HORKAGE_ATAPI_DMADIR = (1 << 18), /* device requires dmadir */
5077 + ATA_HORKAGE_NO_NCQ_TRIM = (1 << 19), /* don't use queued TRIM */
5078 ++ ATA_HORKAGE_NOLPM = (1 << 20), /* don't use LPM */
5079 ++ ATA_HORKAGE_WD_BROKEN_LPM = (1 << 21), /* some WDs have broken LPM */
5080 +
5081 + /* DMA mask for user DMA control: User visible values; DO NOT
5082 + renumber */
5083 +diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
5084 +index 3e781b8c0be7..362927c48f97 100644
5085 +--- a/include/linux/mmc/sdhci.h
5086 ++++ b/include/linux/mmc/sdhci.h
5087 +@@ -98,6 +98,8 @@ struct sdhci_host {
5088 + #define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4)
5089 + /* Controller has a non-standard host control register */
5090 + #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
5091 ++/* Controller does not support HS200 */
5092 ++#define SDHCI_QUIRK2_BROKEN_HS200 (1<<6)
5093 +
5094 + int irq; /* Device IRQ */
5095 + void __iomem *ioaddr; /* Mapped address */
5096 +diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
5097 +index 7d399671a566..708bd119627f 100644
5098 +--- a/include/linux/usb/chipidea.h
5099 ++++ b/include/linux/usb/chipidea.h
5100 +@@ -24,6 +24,7 @@ struct ci_hdrc_platform_data {
5101 + * but otg is not supported (no register otgsc).
5102 + */
5103 + #define CI_HDRC_DUAL_ROLE_NOT_OTG BIT(4)
5104 ++#define CI_HDRC_IMX28_WRITE_FIX BIT(5)
5105 + enum usb_dr_mode dr_mode;
5106 + #define CI_HDRC_CONTROLLER_RESET_EVENT 0
5107 + #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
5108 +diff --git a/lib/fonts/Kconfig b/lib/fonts/Kconfig
5109 +index 34fd931b54b5..4dc1b990aa23 100644
5110 +--- a/lib/fonts/Kconfig
5111 ++++ b/lib/fonts/Kconfig
5112 +@@ -9,7 +9,7 @@ if FONT_SUPPORT
5113 +
5114 + config FONTS
5115 + bool "Select compiled-in fonts"
5116 +- depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
5117 ++ depends on FRAMEBUFFER_CONSOLE
5118 + help
5119 + Say Y here if you would like to use fonts other than the default
5120 + your frame buffer console usually use.
5121 +@@ -22,7 +22,7 @@ config FONTS
5122 +
5123 + config FONT_8x8
5124 + bool "VGA 8x8 font" if FONTS
5125 +- depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
5126 ++ depends on FRAMEBUFFER_CONSOLE
5127 + default y if !SPARC && !FONTS
5128 + help
5129 + This is the "high resolution" font for the VGA frame buffer (the one
5130 +@@ -45,7 +45,7 @@ config FONT_8x16
5131 +
5132 + config FONT_6x11
5133 + bool "Mac console 6x11 font (not supported by all drivers)" if FONTS
5134 +- depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
5135 ++ depends on FRAMEBUFFER_CONSOLE
5136 + default y if !SPARC && !FONTS && MAC
5137 + help
5138 + Small console font with Macintosh-style high-half glyphs. Some Mac
5139 +diff --git a/mm/mempolicy.c b/mm/mempolicy.c
5140 +index 0cd2c4d4e270..e1bd99778b9d 100644
5141 +--- a/mm/mempolicy.c
5142 ++++ b/mm/mempolicy.c
5143 +@@ -2928,7 +2928,7 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
5144 + unsigned short mode = MPOL_DEFAULT;
5145 + unsigned short flags = 0;
5146 +
5147 +- if (pol && pol != &default_policy) {
5148 ++ if (pol && pol != &default_policy && !(pol->flags & MPOL_F_MORON)) {
5149 + mode = pol->mode;
5150 + flags = pol->flags;
5151 + }
5152 +diff --git a/net/compat.c b/net/compat.c
5153 +index dd32e34c1e2c..f50161fb812e 100644
5154 +--- a/net/compat.c
5155 ++++ b/net/compat.c
5156 +@@ -780,21 +780,16 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
5157 + if (flags & MSG_CMSG_COMPAT)
5158 + return -EINVAL;
5159 +
5160 +- if (COMPAT_USE_64BIT_TIME)
5161 +- return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
5162 +- flags | MSG_CMSG_COMPAT,
5163 +- (struct timespec *) timeout);
5164 +-
5165 + if (timeout == NULL)
5166 + return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
5167 + flags | MSG_CMSG_COMPAT, NULL);
5168 +
5169 +- if (get_compat_timespec(&ktspec, timeout))
5170 ++ if (compat_get_timespec(&ktspec, timeout))
5171 + return -EFAULT;
5172 +
5173 + datagrams = __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
5174 + flags | MSG_CMSG_COMPAT, &ktspec);
5175 +- if (datagrams > 0 && put_compat_timespec(&ktspec, timeout))
5176 ++ if (datagrams > 0 && compat_put_timespec(&ktspec, timeout))
5177 + datagrams = -EFAULT;
5178 +
5179 + return datagrams;
5180 +diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
5181 +index d846304b7b89..c7539e22868b 100644
5182 +--- a/net/ipv4/fib_frontend.c
5183 ++++ b/net/ipv4/fib_frontend.c
5184 +@@ -1047,6 +1047,8 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
5185 + }
5186 +
5187 + in_dev = __in_dev_get_rtnl(dev);
5188 ++ if (!in_dev)
5189 ++ return NOTIFY_DONE;
5190 +
5191 + switch (event) {
5192 + case NETDEV_UP:
5193 +diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
5194 +index e560ef34cf4b..d30636080a11 100644
5195 +--- a/net/ipv4/ip_gre.c
5196 ++++ b/net/ipv4/ip_gre.c
5197 +@@ -178,7 +178,7 @@ static int ipgre_err(struct sk_buff *skb, u32 info,
5198 + else
5199 + itn = net_generic(net, ipgre_net_id);
5200 +
5201 +- iph = (const struct iphdr *)skb->data;
5202 ++ iph = (const struct iphdr *)(icmp_hdr(skb) + 1);
5203 + t = ip_tunnel_lookup(itn, skb->dev->ifindex, tpi->flags,
5204 + iph->daddr, iph->saddr, tpi->key);
5205 +
5206 +diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
5207 +index 054a3e97d822..3d4da2c16b6a 100644
5208 +--- a/net/ipv4/ip_input.c
5209 ++++ b/net/ipv4/ip_input.c
5210 +@@ -314,7 +314,7 @@ static int ip_rcv_finish(struct sk_buff *skb)
5211 + const struct iphdr *iph = ip_hdr(skb);
5212 + struct rtable *rt;
5213 +
5214 +- if (sysctl_ip_early_demux && !skb_dst(skb)) {
5215 ++ if (sysctl_ip_early_demux && !skb_dst(skb) && skb->sk == NULL) {
5216 + const struct net_protocol *ipprot;
5217 + int protocol = iph->protocol;
5218 +
5219 +diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
5220 +index 90ff9570d7d4..471c8c1f3b67 100644
5221 +--- a/net/ipv4/ip_tunnel.c
5222 ++++ b/net/ipv4/ip_tunnel.c
5223 +@@ -618,6 +618,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
5224 + tunnel->err_time + IPTUNNEL_ERR_TIMEO)) {
5225 + tunnel->err_count--;
5226 +
5227 ++ memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
5228 + dst_link_failure(skb);
5229 + } else
5230 + tunnel->err_count = 0;
5231 +diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
5232 +index 302d6fb1ff2b..51d54dc376f3 100644
5233 +--- a/net/ipv6/ip6_input.c
5234 ++++ b/net/ipv6/ip6_input.c
5235 +@@ -49,7 +49,7 @@
5236 +
5237 + int ip6_rcv_finish(struct sk_buff *skb)
5238 + {
5239 +- if (sysctl_ip_early_demux && !skb_dst(skb)) {
5240 ++ if (sysctl_ip_early_demux && !skb_dst(skb) && skb->sk == NULL) {
5241 + const struct inet6_protocol *ipprot;
5242 +
5243 + ipprot = rcu_dereference(inet6_protos[ipv6_hdr(skb)->nexthdr]);
5244 +diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c
5245 +index c38adcc910fb..1c2a63412656 100644
5246 +--- a/security/integrity/ima/ima_template_lib.c
5247 ++++ b/security/integrity/ima/ima_template_lib.c
5248 +@@ -255,7 +255,7 @@ int ima_eventdigest_ng_init(struct integrity_iint_cache *iint,
5249 + struct evm_ima_xattr_data *xattr_value,
5250 + int xattr_len, struct ima_field_data *field_data)
5251 + {
5252 +- u8 *cur_digest = NULL, hash_algo = HASH_ALGO__LAST;
5253 ++ u8 *cur_digest = NULL, hash_algo = HASH_ALGO_SHA1;
5254 + u32 cur_digestsize = 0;
5255 +
5256 + /* If iint is NULL, we are recording a violation. */
5257 +diff --git a/sound/core/init.c b/sound/core/init.c
5258 +index 1351f22f651c..e3c93cd77ee7 100644
5259 +--- a/sound/core/init.c
5260 ++++ b/sound/core/init.c
5261 +@@ -170,7 +170,7 @@ int snd_card_create(int idx, const char *xid,
5262 + if (idx < 0) {
5263 + for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
5264 + /* idx == -1 == 0xffff means: take any free slot */
5265 +- if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
5266 ++ if (idx2 < 32 && !(idx & (1U << idx2)))
5267 + continue;
5268 + if (!test_bit(idx2, snd_cards_lock)) {
5269 + if (module_slot_match(module, idx2)) {
5270 +@@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
5271 + if (idx < 0) {
5272 + for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
5273 + /* idx == -1 == 0xffff means: take any free slot */
5274 +- if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
5275 ++ if (idx2 < 32 && !(idx & (1U << idx2)))
5276 + continue;
5277 + if (!test_bit(idx2, snd_cards_lock)) {
5278 + if (!slots[idx2] || !*slots[idx2]) {
5279 +diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
5280 +index 46ed9e8ae0fd..cc9fd67a50df 100644
5281 +--- a/sound/pci/Kconfig
5282 ++++ b/sound/pci/Kconfig
5283 +@@ -25,6 +25,7 @@ config SND_ALS300
5284 + select SND_PCM
5285 + select SND_AC97_CODEC
5286 + select SND_OPL3_LIB
5287 ++ select ZONE_DMA
5288 + help
5289 + Say 'Y' or 'M' to include support for Avance Logic ALS300/ALS300+
5290 +
5291 +@@ -49,6 +50,7 @@ config SND_ALI5451
5292 + tristate "ALi M5451 PCI Audio Controller"
5293 + select SND_MPU401_UART
5294 + select SND_AC97_CODEC
5295 ++ select ZONE_DMA
5296 + help
5297 + Say Y here to include support for the integrated AC97 sound
5298 + device on motherboards using the ALi M5451 Audio Controller
5299 +@@ -153,6 +155,7 @@ config SND_AZT3328
5300 + select SND_PCM
5301 + select SND_RAWMIDI
5302 + select SND_AC97_CODEC
5303 ++ select ZONE_DMA
5304 + help
5305 + Say Y here to include support for Aztech AZF3328 (PCI168)
5306 + soundcards.
5307 +@@ -458,6 +461,7 @@ config SND_EMU10K1
5308 + select SND_HWDEP
5309 + select SND_RAWMIDI
5310 + select SND_AC97_CODEC
5311 ++ select ZONE_DMA
5312 + help
5313 + Say Y to include support for Sound Blaster PCI 512, Live!,
5314 + Audigy and E-mu APS (partially supported) soundcards.
5315 +@@ -473,6 +477,7 @@ config SND_EMU10K1X
5316 + tristate "Emu10k1X (Dell OEM Version)"
5317 + select SND_AC97_CODEC
5318 + select SND_RAWMIDI
5319 ++ select ZONE_DMA
5320 + help
5321 + Say Y here to include support for the Dell OEM version of the
5322 + Sound Blaster Live!.
5323 +@@ -506,6 +511,7 @@ config SND_ES1938
5324 + select SND_OPL3_LIB
5325 + select SND_MPU401_UART
5326 + select SND_AC97_CODEC
5327 ++ select ZONE_DMA
5328 + help
5329 + Say Y here to include support for soundcards based on ESS Solo-1
5330 + (ES1938, ES1946, ES1969) chips.
5331 +@@ -517,6 +523,7 @@ config SND_ES1968
5332 + tristate "ESS ES1968/1978 (Maestro-1/2/2E)"
5333 + select SND_MPU401_UART
5334 + select SND_AC97_CODEC
5335 ++ select ZONE_DMA
5336 + help
5337 + Say Y here to include support for soundcards based on ESS Maestro
5338 + 1/2/2E chips.
5339 +@@ -605,6 +612,7 @@ config SND_ICE1712
5340 + select SND_MPU401_UART
5341 + select SND_AC97_CODEC
5342 + select BITREVERSE
5343 ++ select ZONE_DMA
5344 + help
5345 + Say Y here to include support for soundcards based on the
5346 + ICE1712 (Envy24) chip.
5347 +@@ -692,6 +700,7 @@ config SND_LX6464ES
5348 + config SND_MAESTRO3
5349 + tristate "ESS Allegro/Maestro3"
5350 + select SND_AC97_CODEC
5351 ++ select ZONE_DMA
5352 + help
5353 + Say Y here to include support for soundcards based on ESS Maestro 3
5354 + (Allegro) chips.
5355 +@@ -788,6 +797,7 @@ config SND_SIS7019
5356 + tristate "SiS 7019 Audio Accelerator"
5357 + depends on X86 && !X86_64
5358 + select SND_AC97_CODEC
5359 ++ select ZONE_DMA
5360 + help
5361 + Say Y here to include support for the SiS 7019 Audio Accelerator.
5362 +
5363 +@@ -799,6 +809,7 @@ config SND_SONICVIBES
5364 + select SND_OPL3_LIB
5365 + select SND_MPU401_UART
5366 + select SND_AC97_CODEC
5367 ++ select ZONE_DMA
5368 + help
5369 + Say Y here to include support for soundcards based on the S3
5370 + SonicVibes chip.
5371 +@@ -810,6 +821,7 @@ config SND_TRIDENT
5372 + tristate "Trident 4D-Wave DX/NX; SiS 7018"
5373 + select SND_MPU401_UART
5374 + select SND_AC97_CODEC
5375 ++ select ZONE_DMA
5376 + help
5377 + Say Y here to include support for soundcards based on Trident
5378 + 4D-Wave DX/NX or SiS 7018 chips.
5379 +diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
5380 +index c7f6d1cab606..7d4ccfa48008 100644
5381 +--- a/sound/pci/hda/hda_generic.c
5382 ++++ b/sound/pci/hda/hda_generic.c
5383 +@@ -2857,9 +2857,11 @@ static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
5384 + if (num_conns < idx)
5385 + return false;
5386 + nid = list[idx];
5387 +- if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT))
5388 ++ if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
5389 ++ !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
5390 + *mix_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5391 +- if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT))
5392 ++ if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
5393 ++ !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
5394 + *mute_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5395 +
5396 + return *mix_val || *mute_val;
5397 +diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
5398 +index 699262a3e07a..0170318eb220 100644
5399 +--- a/sound/pci/hda/patch_analog.c
5400 ++++ b/sound/pci/hda/patch_analog.c
5401 +@@ -185,7 +185,7 @@ static const struct hda_codec_ops ad198x_auto_patch_ops = {
5402 + };
5403 +
5404 +
5405 +-static int ad198x_parse_auto_config(struct hda_codec *codec)
5406 ++static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp)
5407 + {
5408 + struct ad198x_spec *spec = codec->spec;
5409 + struct auto_pin_cfg *cfg = &spec->gen.autocfg;
5410 +@@ -195,7 +195,7 @@ static int ad198x_parse_auto_config(struct hda_codec *codec)
5411 + codec->no_trigger_sense = 1;
5412 + codec->no_sticky_stream = 1;
5413 +
5414 +- spec->gen.indep_hp = 1;
5415 ++ spec->gen.indep_hp = indep_hp;
5416 +
5417 + err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
5418 + if (err < 0)
5419 +@@ -280,11 +280,11 @@ static const struct hda_fixup ad1986a_fixups[] = {
5420 + .v.pins = (const struct hda_pintbl[]) {
5421 + { 0x1a, 0x02214021 }, /* headphone */
5422 + { 0x1b, 0x01014011 }, /* front */
5423 +- { 0x1c, 0x01013012 }, /* surround */
5424 +- { 0x1d, 0x01019015 }, /* clfe */
5425 ++ { 0x1c, 0x01813030 }, /* line-in */
5426 ++ { 0x1d, 0x01a19020 }, /* rear mic */
5427 + { 0x1e, 0x411111f0 }, /* N/A */
5428 + { 0x1f, 0x02a190f0 }, /* mic */
5429 +- { 0x20, 0x018130f0 }, /* line-in */
5430 ++ { 0x20, 0x411111f0 }, /* N/A */
5431 + {}
5432 + },
5433 + },
5434 +@@ -378,7 +378,7 @@ static int patch_ad1986a(struct hda_codec *codec)
5435 + ad1986a_fixups);
5436 + snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5437 +
5438 +- err = ad198x_parse_auto_config(codec);
5439 ++ err = ad198x_parse_auto_config(codec, false);
5440 + if (err < 0) {
5441 + snd_hda_gen_free(codec);
5442 + return err;
5443 +@@ -480,7 +480,7 @@ static int patch_ad1983(struct hda_codec *codec)
5444 +
5445 + spec->gen.beep_nid = 0x10;
5446 + set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
5447 +- err = ad198x_parse_auto_config(codec);
5448 ++ err = ad198x_parse_auto_config(codec, false);
5449 + if (err < 0)
5450 + goto error;
5451 + err = ad1983_add_spdif_mux_ctl(codec);
5452 +@@ -567,7 +567,7 @@ static int patch_ad1981(struct hda_codec *codec)
5453 + snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
5454 + snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5455 +
5456 +- err = ad198x_parse_auto_config(codec);
5457 ++ err = ad198x_parse_auto_config(codec, false);
5458 + if (err < 0)
5459 + goto error;
5460 + err = ad1983_add_spdif_mux_ctl(codec);
5461 +@@ -893,7 +893,7 @@ static int patch_ad1988(struct hda_codec *codec)
5462 + snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
5463 + snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5464 +
5465 +- err = ad198x_parse_auto_config(codec);
5466 ++ err = ad198x_parse_auto_config(codec, true);
5467 + if (err < 0)
5468 + goto error;
5469 + err = ad1988_add_spdif_mux_ctl(codec);
5470 +@@ -1070,7 +1070,7 @@ static int patch_ad1884(struct hda_codec *codec)
5471 + snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
5472 + snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5473 +
5474 +- err = ad198x_parse_auto_config(codec);
5475 ++ err = ad198x_parse_auto_config(codec, true);
5476 + if (err < 0)
5477 + goto error;
5478 + err = ad1983_add_spdif_mux_ctl(codec);
5479 +@@ -1112,7 +1112,7 @@ static int patch_ad1882(struct hda_codec *codec)
5480 + spec->gen.mixer_merge_nid = 0x21;
5481 + spec->gen.beep_nid = 0x10;
5482 + set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
5483 +- err = ad198x_parse_auto_config(codec);
5484 ++ err = ad198x_parse_auto_config(codec, true);
5485 + if (err < 0)
5486 + goto error;
5487 + err = ad1988_add_spdif_mux_ctl(codec);
5488 +diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
5489 +index 314b77eb1216..6baac4400076 100644
5490 +--- a/sound/pci/hda/patch_hdmi.c
5491 ++++ b/sound/pci/hda/patch_hdmi.c
5492 +@@ -129,6 +129,9 @@ struct hdmi_spec {
5493 +
5494 + struct hdmi_eld temp_eld;
5495 + struct hdmi_ops ops;
5496 ++
5497 ++ bool dyn_pin_out;
5498 ++
5499 + /*
5500 + * Non-generic VIA/NVIDIA specific
5501 + */
5502 +@@ -497,15 +500,25 @@ static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
5503 +
5504 + static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
5505 + {
5506 ++ struct hdmi_spec *spec = codec->spec;
5507 ++ int pin_out;
5508 ++
5509 + /* Unmute */
5510 + if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
5511 + snd_hda_codec_write(codec, pin_nid, 0,
5512 + AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
5513 +- /* Enable pin out: some machines with GM965 gets broken output when
5514 +- * the pin is disabled or changed while using with HDMI
5515 +- */
5516 ++
5517 ++ if (spec->dyn_pin_out)
5518 ++ /* Disable pin out until stream is active */
5519 ++ pin_out = 0;
5520 ++ else
5521 ++ /* Enable pin out: some machines with GM965 gets broken output
5522 ++ * when the pin is disabled or changed while using with HDMI
5523 ++ */
5524 ++ pin_out = PIN_OUT;
5525 ++
5526 + snd_hda_codec_write(codec, pin_nid, 0,
5527 +- AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
5528 ++ AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
5529 + }
5530 +
5531 + static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
5532 +@@ -1747,6 +1760,7 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
5533 + struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
5534 + hda_nid_t pin_nid = per_pin->pin_nid;
5535 + bool non_pcm;
5536 ++ int pinctl;
5537 +
5538 + non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
5539 + mutex_lock(&per_pin->lock);
5540 +@@ -1756,6 +1770,14 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
5541 + hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
5542 + mutex_unlock(&per_pin->lock);
5543 +
5544 ++ if (spec->dyn_pin_out) {
5545 ++ pinctl = snd_hda_codec_read(codec, pin_nid, 0,
5546 ++ AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5547 ++ snd_hda_codec_write(codec, pin_nid, 0,
5548 ++ AC_VERB_SET_PIN_WIDGET_CONTROL,
5549 ++ pinctl | PIN_OUT);
5550 ++ }
5551 ++
5552 + return spec->ops.setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
5553 + }
5554 +
5555 +@@ -1775,6 +1797,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
5556 + int cvt_idx, pin_idx;
5557 + struct hdmi_spec_per_cvt *per_cvt;
5558 + struct hdmi_spec_per_pin *per_pin;
5559 ++ int pinctl;
5560 +
5561 + if (hinfo->nid) {
5562 + cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
5563 +@@ -1791,6 +1814,14 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
5564 + return -EINVAL;
5565 + per_pin = get_pin(spec, pin_idx);
5566 +
5567 ++ if (spec->dyn_pin_out) {
5568 ++ pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
5569 ++ AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5570 ++ snd_hda_codec_write(codec, per_pin->pin_nid, 0,
5571 ++ AC_VERB_SET_PIN_WIDGET_CONTROL,
5572 ++ pinctl & ~PIN_OUT);
5573 ++ }
5574 ++
5575 + snd_hda_spdif_ctls_unassign(codec, pin_idx);
5576 +
5577 + mutex_lock(&per_pin->lock);
5578 +@@ -2848,6 +2879,7 @@ static int patch_nvhdmi(struct hda_codec *codec)
5579 + return err;
5580 +
5581 + spec = codec->spec;
5582 ++ spec->dyn_pin_out = true;
5583 +
5584 + spec->ops.chmap_cea_alloc_validate_get_type =
5585 + nvhdmi_chmap_cea_alloc_validate_get_type;
5586 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
5587 +index c5646941539a..864e6dfaa7a4 100644
5588 +--- a/sound/pci/hda/patch_realtek.c
5589 ++++ b/sound/pci/hda/patch_realtek.c
5590 +@@ -1780,6 +1780,7 @@ enum {
5591 + ALC889_FIXUP_DAC_ROUTE,
5592 + ALC889_FIXUP_MBP_VREF,
5593 + ALC889_FIXUP_IMAC91_VREF,
5594 ++ ALC889_FIXUP_MBA11_VREF,
5595 + ALC889_FIXUP_MBA21_VREF,
5596 + ALC882_FIXUP_INV_DMIC,
5597 + ALC882_FIXUP_NO_PRIMARY_HP,
5598 +@@ -1910,6 +1911,16 @@ static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5599 + alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
5600 + }
5601 +
5602 ++/* Set VREF on speaker pins on mba11 */
5603 ++static void alc889_fixup_mba11_vref(struct hda_codec *codec,
5604 ++ const struct hda_fixup *fix, int action)
5605 ++{
5606 ++ static hda_nid_t nids[1] = { 0x18 };
5607 ++
5608 ++ if (action == HDA_FIXUP_ACT_INIT)
5609 ++ alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
5610 ++}
5611 ++
5612 + /* Set VREF on speaker pins on mba21 */
5613 + static void alc889_fixup_mba21_vref(struct hda_codec *codec,
5614 + const struct hda_fixup *fix, int action)
5615 +@@ -2119,6 +2130,12 @@ static const struct hda_fixup alc882_fixups[] = {
5616 + .chained = true,
5617 + .chain_id = ALC882_FIXUP_GPIO1,
5618 + },
5619 ++ [ALC889_FIXUP_MBA11_VREF] = {
5620 ++ .type = HDA_FIXUP_FUNC,
5621 ++ .v.func = alc889_fixup_mba11_vref,
5622 ++ .chained = true,
5623 ++ .chain_id = ALC889_FIXUP_MBP_VREF,
5624 ++ },
5625 + [ALC889_FIXUP_MBA21_VREF] = {
5626 + .type = HDA_FIXUP_FUNC,
5627 + .v.func = alc889_fixup_mba21_vref,
5628 +@@ -2194,7 +2211,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5629 + SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5630 + SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
5631 + SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5632 +- SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5633 ++ SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBA11_VREF),
5634 + SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBA21_VREF),
5635 + SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5636 + SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5637 +@@ -3526,6 +3543,15 @@ static void alc_fixup_headset_mode_alc255(struct hda_codec *codec,
5638 + alc_fixup_headset_mode(codec, fix, action);
5639 + }
5640 +
5641 ++static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec,
5642 ++ const struct hda_fixup *fix, int action)
5643 ++{
5644 ++ if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5645 ++ struct alc_spec *spec = codec->spec;
5646 ++ spec->gen.auto_mute_via_amp = 1;
5647 ++ }
5648 ++}
5649 ++
5650 + static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
5651 + const struct hda_fixup *fix, int action)
5652 + {
5653 +@@ -4247,7 +4273,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5654 + SND_PCI_QUIRK(0x1028, 0x0606, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5655 + SND_PCI_QUIRK(0x1028, 0x0608, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5656 + SND_PCI_QUIRK(0x1028, 0x0609, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5657 +- SND_PCI_QUIRK(0x1028, 0x0610, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5658 ++ SND_PCI_QUIRK(0x1028, 0x060f, "Dell", ALC269_FIXUP_DELL3_MIC_NO_PRESENCE),
5659 ++ SND_PCI_QUIRK(0x1028, 0x0610, "Dell", ALC269_FIXUP_DELL3_MIC_NO_PRESENCE),
5660 + SND_PCI_QUIRK(0x1028, 0x0613, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5661 + SND_PCI_QUIRK(0x1028, 0x0614, "Dell Inspiron 3135", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5662 + SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_MONO_SPEAKERS),
5663 +@@ -4257,6 +4284,12 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5664 + SND_PCI_QUIRK(0x1028, 0x063e, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5665 + SND_PCI_QUIRK(0x1028, 0x063f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5666 + SND_PCI_QUIRK(0x1028, 0x0640, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5667 ++ SND_PCI_QUIRK(0x1028, 0x064d, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5668 ++ SND_PCI_QUIRK(0x1028, 0x0651, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5669 ++ SND_PCI_QUIRK(0x1028, 0x0652, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5670 ++ SND_PCI_QUIRK(0x1028, 0x0653, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5671 ++ SND_PCI_QUIRK(0x1028, 0x0658, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
5672 ++ SND_PCI_QUIRK(0x1028, 0x0662, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5673 + SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
5674 + SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
5675 + SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
5676 +@@ -4841,6 +4874,7 @@ enum {
5677 + ALC662_FIXUP_BASS_CHMAP,
5678 + ALC662_FIXUP_BASS_1A,
5679 + ALC662_FIXUP_BASS_1A_CHMAP,
5680 ++ ALC668_FIXUP_AUTO_MUTE,
5681 + };
5682 +
5683 + static const struct hda_fixup alc662_fixups[] = {
5684 +@@ -5001,6 +5035,12 @@ static const struct hda_fixup alc662_fixups[] = {
5685 + .type = HDA_FIXUP_FUNC,
5686 + .v.func = alc_fixup_inv_dmic_0x12,
5687 + },
5688 ++ [ALC668_FIXUP_AUTO_MUTE] = {
5689 ++ .type = HDA_FIXUP_FUNC,
5690 ++ .v.func = alc_fixup_auto_mute_via_amp,
5691 ++ .chained = true,
5692 ++ .chain_id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE
5693 ++ },
5694 + [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
5695 + .type = HDA_FIXUP_PINS,
5696 + .v.pins = (const struct hda_pintbl[]) {
5697 +@@ -5046,11 +5086,12 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5698 + SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5699 + SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5700 + SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5701 +- SND_PCI_QUIRK(0x1028, 0x0623, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5702 +- SND_PCI_QUIRK(0x1028, 0x0624, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5703 ++ SND_PCI_QUIRK(0x1028, 0x0623, "Dell", ALC668_FIXUP_AUTO_MUTE),
5704 ++ SND_PCI_QUIRK(0x1028, 0x0624, "Dell", ALC668_FIXUP_AUTO_MUTE),
5705 + SND_PCI_QUIRK(0x1028, 0x0625, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5706 + SND_PCI_QUIRK(0x1028, 0x0626, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5707 +- SND_PCI_QUIRK(0x1028, 0x0628, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5708 ++ SND_PCI_QUIRK(0x1028, 0x0628, "Dell", ALC668_FIXUP_AUTO_MUTE),
5709 ++ SND_PCI_QUIRK(0x1028, 0x064e, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5710 + SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5711 + SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_BASS_1A_CHMAP),
5712 + SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_CHMAP),
5713 +diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
5714 +index b96d9e1adf6d..3717f2dd30be 100644
5715 +--- a/sound/pci/rme9652/rme9652.c
5716 ++++ b/sound/pci/rme9652/rme9652.c
5717 +@@ -285,7 +285,7 @@ static char channel_map_9636_ds[26] = {
5718 + /* ADAT channels are remapped */
5719 + 1, 3, 5, 7, 9, 11, 13, 15,
5720 + /* channels 8 and 9 are S/PDIF */
5721 +- 24, 25
5722 ++ 24, 25,
5723 + /* others don't exist */
5724 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
5725 + };
5726 +diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
5727 +index ebff1128be59..adee866f463f 100644
5728 +--- a/sound/soc/codecs/adau1701.c
5729 ++++ b/sound/soc/codecs/adau1701.c
5730 +@@ -71,7 +71,7 @@
5731 +
5732 + #define ADAU1701_SEROCTL_WORD_LEN_24 0x0000
5733 + #define ADAU1701_SEROCTL_WORD_LEN_20 0x0001
5734 +-#define ADAU1701_SEROCTL_WORD_LEN_16 0x0010
5735 ++#define ADAU1701_SEROCTL_WORD_LEN_16 0x0002
5736 + #define ADAU1701_SEROCTL_WORD_LEN_MASK 0x0003
5737 +
5738 + #define ADAU1701_AUXNPOW_VBPD 0x40
5739 +diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
5740 +index 18cdcca9014c..385dec16eb8a 100644
5741 +--- a/sound/soc/codecs/tlv320aic32x4.c
5742 ++++ b/sound/soc/codecs/tlv320aic32x4.c
5743 +@@ -267,8 +267,8 @@ static const struct regmap_range_cfg aic32x4_regmap_pages[] = {
5744 + .selector_mask = 0xff,
5745 + .window_start = 0,
5746 + .window_len = 128,
5747 +- .range_min = AIC32X4_PAGE1,
5748 +- .range_max = AIC32X4_PAGE1 + 127,
5749 ++ .range_min = 0,
5750 ++ .range_max = AIC32X4_RMICPGAVOL,
5751 + },
5752 + };
5753 +
5754 +diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
5755 +index 0ab2dc296474..c4c9ed7acd78 100644
5756 +--- a/sound/soc/codecs/wm5110.c
5757 ++++ b/sound/soc/codecs/wm5110.c
5758 +@@ -43,6 +43,54 @@ static const struct reg_default wm5110_sysclk_revd_patch[] = {
5759 + { 0x3133, 0x1201 },
5760 + { 0x3183, 0x1501 },
5761 + { 0x31D3, 0x1401 },
5762 ++ { 0x0049, 0x01ea },
5763 ++ { 0x004a, 0x01f2 },
5764 ++ { 0x0057, 0x01e7 },
5765 ++ { 0x0058, 0x01fb },
5766 ++ { 0x33ce, 0xc4f5 },
5767 ++ { 0x33cf, 0x1361 },
5768 ++ { 0x33d0, 0x0402 },
5769 ++ { 0x33d1, 0x4700 },
5770 ++ { 0x33d2, 0x026d },
5771 ++ { 0x33d3, 0xff00 },
5772 ++ { 0x33d4, 0x026d },
5773 ++ { 0x33d5, 0x0101 },
5774 ++ { 0x33d6, 0xc4f5 },
5775 ++ { 0x33d7, 0x0361 },
5776 ++ { 0x33d8, 0x0402 },
5777 ++ { 0x33d9, 0x6701 },
5778 ++ { 0x33da, 0xc4f5 },
5779 ++ { 0x33db, 0x136f },
5780 ++ { 0x33dc, 0xc4f5 },
5781 ++ { 0x33dd, 0x134f },
5782 ++ { 0x33de, 0xc4f5 },
5783 ++ { 0x33df, 0x131f },
5784 ++ { 0x33e0, 0x026d },
5785 ++ { 0x33e1, 0x4f01 },
5786 ++ { 0x33e2, 0x026d },
5787 ++ { 0x33e3, 0xf100 },
5788 ++ { 0x33e4, 0x026d },
5789 ++ { 0x33e5, 0x0001 },
5790 ++ { 0x33e6, 0xc4f5 },
5791 ++ { 0x33e7, 0x0361 },
5792 ++ { 0x33e8, 0x0402 },
5793 ++ { 0x33e9, 0x6601 },
5794 ++ { 0x33ea, 0xc4f5 },
5795 ++ { 0x33eb, 0x136f },
5796 ++ { 0x33ec, 0xc4f5 },
5797 ++ { 0x33ed, 0x134f },
5798 ++ { 0x33ee, 0xc4f5 },
5799 ++ { 0x33ef, 0x131f },
5800 ++ { 0x33f0, 0x026d },
5801 ++ { 0x33f1, 0x4e01 },
5802 ++ { 0x33f2, 0x026d },
5803 ++ { 0x33f3, 0xf000 },
5804 ++ { 0x33f6, 0xc4f5 },
5805 ++ { 0x33f7, 0x1361 },
5806 ++ { 0x33f8, 0x0402 },
5807 ++ { 0x33f9, 0x4600 },
5808 ++ { 0x33fa, 0x026d },
5809 ++ { 0x33fb, 0xfe00 },
5810 + };
5811 +
5812 + static int wm5110_sysclk_ev(struct snd_soc_dapm_widget *w,
5813 +diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
5814 +index f36d24a02445..6bee5f6dfa37 100644
5815 +--- a/tools/perf/util/session.c
5816 ++++ b/tools/perf/util/session.c
5817 +@@ -851,6 +851,7 @@ static struct machine *
5818 + struct perf_sample *sample)
5819 + {
5820 + const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
5821 ++ struct machine *machine;
5822 +
5823 + if (perf_guest &&
5824 + ((cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ||
5825 +@@ -863,7 +864,11 @@ static struct machine *
5826 + else
5827 + pid = sample->pid;
5828 +
5829 +- return perf_session__findnew_machine(session, pid);
5830 ++ machine = perf_session__find_machine(session, pid);
5831 ++ if (!machine)
5832 ++ machine = perf_session__findnew_machine(session,
5833 ++ DEFAULT_GUEST_KERNEL_ID);
5834 ++ return machine;
5835 + }
5836 +
5837 + return &session->machines.host;