Annotation of /trunk/kernel-alx-legacy/patches-4.9/0286-4.9.187-all-fixes.patch
Parent Directory
|
Revision Log
Revision 3608 -
(hide annotations)
(download)
Fri Aug 14 07:34:29 2020 UTC (3 years, 10 months ago) by niro
File size: 374178 byte(s)
Fri Aug 14 07:34:29 2020 UTC (3 years, 10 months ago) by niro
File size: 374178 byte(s)
-added kerenl-alx-legacy pkg
1 | niro | 3608 | diff --git a/Documentation/devicetree/bindings/serial/mvebu-uart.txt b/Documentation/devicetree/bindings/serial/mvebu-uart.txt |
2 | index 6087defd9f93..d37fabe17bd1 100644 | ||
3 | --- a/Documentation/devicetree/bindings/serial/mvebu-uart.txt | ||
4 | +++ b/Documentation/devicetree/bindings/serial/mvebu-uart.txt | ||
5 | @@ -8,6 +8,6 @@ Required properties: | ||
6 | Example: | ||
7 | serial@12000 { | ||
8 | compatible = "marvell,armada-3700-uart"; | ||
9 | - reg = <0x12000 0x400>; | ||
10 | + reg = <0x12000 0x200>; | ||
11 | interrupts = <43>; | ||
12 | }; | ||
13 | diff --git a/Makefile b/Makefile | ||
14 | index 1ab22a85118f..65ed5dc69ec9 100644 | ||
15 | --- a/Makefile | ||
16 | +++ b/Makefile | ||
17 | @@ -1,6 +1,6 @@ | ||
18 | VERSION = 4 | ||
19 | PATCHLEVEL = 9 | ||
20 | -SUBLEVEL = 186 | ||
21 | +SUBLEVEL = 187 | ||
22 | EXTRAVERSION = | ||
23 | NAME = Roaring Lionus | ||
24 | |||
25 | @@ -515,6 +515,7 @@ ifneq ($(GCC_TOOLCHAIN),) | ||
26 | CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) | ||
27 | endif | ||
28 | CLANG_FLAGS += -no-integrated-as | ||
29 | +CLANG_FLAGS += -Werror=unknown-warning-option | ||
30 | KBUILD_CFLAGS += $(CLANG_FLAGS) | ||
31 | KBUILD_AFLAGS += $(CLANG_FLAGS) | ||
32 | endif | ||
33 | diff --git a/arch/arm64/boot/dts/marvell/armada-37xx.dtsi b/arch/arm64/boot/dts/marvell/armada-37xx.dtsi | ||
34 | index 68e6f88bdcfe..f2004b0955f1 100644 | ||
35 | --- a/arch/arm64/boot/dts/marvell/armada-37xx.dtsi | ||
36 | +++ b/arch/arm64/boot/dts/marvell/armada-37xx.dtsi | ||
37 | @@ -96,7 +96,7 @@ | ||
38 | |||
39 | uart0: serial@12000 { | ||
40 | compatible = "marvell,armada-3700-uart"; | ||
41 | - reg = <0x12000 0x400>; | ||
42 | + reg = <0x12000 0x200>; | ||
43 | interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>; | ||
44 | status = "disabled"; | ||
45 | }; | ||
46 | diff --git a/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi b/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi | ||
47 | index 906fb836d241..6a51d282ec63 100644 | ||
48 | --- a/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi | ||
49 | +++ b/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi | ||
50 | @@ -306,7 +306,8 @@ | ||
51 | regulator-max-microvolt = <1320000>; | ||
52 | enable-gpios = <&pmic 6 GPIO_ACTIVE_HIGH>; | ||
53 | regulator-ramp-delay = <80>; | ||
54 | - regulator-enable-ramp-delay = <1000>; | ||
55 | + regulator-enable-ramp-delay = <2000>; | ||
56 | + regulator-settling-time-us = <160>; | ||
57 | }; | ||
58 | }; | ||
59 | }; | ||
60 | diff --git a/arch/arm64/boot/dts/nvidia/tegra210.dtsi b/arch/arm64/boot/dts/nvidia/tegra210.dtsi | ||
61 | index 46045fe719da..87ef72bffd86 100644 | ||
62 | --- a/arch/arm64/boot/dts/nvidia/tegra210.dtsi | ||
63 | +++ b/arch/arm64/boot/dts/nvidia/tegra210.dtsi | ||
64 | @@ -1020,7 +1020,7 @@ | ||
65 | compatible = "nvidia,tegra210-agic"; | ||
66 | #interrupt-cells = <3>; | ||
67 | interrupt-controller; | ||
68 | - reg = <0x702f9000 0x2000>, | ||
69 | + reg = <0x702f9000 0x1000>, | ||
70 | <0x702fa000 0x2000>; | ||
71 | interrupts = <GIC_SPI 102 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>; | ||
72 | clocks = <&tegra_car TEGRA210_CLK_APE>; | ||
73 | diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c | ||
74 | index ea319c055f5d..1b7b4684c35b 100644 | ||
75 | --- a/arch/arm64/crypto/sha1-ce-glue.c | ||
76 | +++ b/arch/arm64/crypto/sha1-ce-glue.c | ||
77 | @@ -50,7 +50,7 @@ static int sha1_ce_finup(struct shash_desc *desc, const u8 *data, | ||
78 | unsigned int len, u8 *out) | ||
79 | { | ||
80 | struct sha1_ce_state *sctx = shash_desc_ctx(desc); | ||
81 | - bool finalize = !sctx->sst.count && !(len % SHA1_BLOCK_SIZE); | ||
82 | + bool finalize = !sctx->sst.count && !(len % SHA1_BLOCK_SIZE) && len; | ||
83 | |||
84 | /* | ||
85 | * Allow the asm code to perform the finalization if there is no | ||
86 | diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c | ||
87 | index 0ed9486f75dd..356ca9397a86 100644 | ||
88 | --- a/arch/arm64/crypto/sha2-ce-glue.c | ||
89 | +++ b/arch/arm64/crypto/sha2-ce-glue.c | ||
90 | @@ -52,7 +52,7 @@ static int sha256_ce_finup(struct shash_desc *desc, const u8 *data, | ||
91 | unsigned int len, u8 *out) | ||
92 | { | ||
93 | struct sha256_ce_state *sctx = shash_desc_ctx(desc); | ||
94 | - bool finalize = !sctx->sst.count && !(len % SHA256_BLOCK_SIZE); | ||
95 | + bool finalize = !sctx->sst.count && !(len % SHA256_BLOCK_SIZE) && len; | ||
96 | |||
97 | /* | ||
98 | * Allow the asm code to perform the finalization if there is no | ||
99 | diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h | ||
100 | index eb8432bb82b8..b69e27152ea5 100644 | ||
101 | --- a/arch/arm64/include/asm/compat.h | ||
102 | +++ b/arch/arm64/include/asm/compat.h | ||
103 | @@ -234,6 +234,7 @@ static inline compat_uptr_t ptr_to_compat(void __user *uptr) | ||
104 | } | ||
105 | |||
106 | #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current))) | ||
107 | +#define COMPAT_MINSIGSTKSZ 2048 | ||
108 | |||
109 | static inline void __user *arch_compat_alloc_user_space(long len) | ||
110 | { | ||
111 | diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c | ||
112 | index 252a6d9c1da5..1a95d135def2 100644 | ||
113 | --- a/arch/arm64/kernel/acpi.c | ||
114 | +++ b/arch/arm64/kernel/acpi.c | ||
115 | @@ -157,10 +157,14 @@ static int __init acpi_fadt_sanity_check(void) | ||
116 | */ | ||
117 | if (table->revision < 5 || | ||
118 | (table->revision == 5 && fadt->minor_revision < 1)) { | ||
119 | - pr_err("Unsupported FADT revision %d.%d, should be 5.1+\n", | ||
120 | + pr_err(FW_BUG "Unsupported FADT revision %d.%d, should be 5.1+\n", | ||
121 | table->revision, fadt->minor_revision); | ||
122 | - ret = -EINVAL; | ||
123 | - goto out; | ||
124 | + | ||
125 | + if (!fadt->arm_boot_flags) { | ||
126 | + ret = -EINVAL; | ||
127 | + goto out; | ||
128 | + } | ||
129 | + pr_err("FADT has ARM boot flags set, assuming 5.1\n"); | ||
130 | } | ||
131 | |||
132 | if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) { | ||
133 | diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h | ||
134 | index c7fcb232fe47..d3e8c901274d 100644 | ||
135 | --- a/arch/arm64/kernel/image.h | ||
136 | +++ b/arch/arm64/kernel/image.h | ||
137 | @@ -73,7 +73,11 @@ | ||
138 | |||
139 | #ifdef CONFIG_EFI | ||
140 | |||
141 | -__efistub_stext_offset = stext - _text; | ||
142 | +/* | ||
143 | + * Use ABSOLUTE() to avoid ld.lld treating this as a relative symbol: | ||
144 | + * https://github.com/ClangBuiltLinux/linux/issues/561 | ||
145 | + */ | ||
146 | +__efistub_stext_offset = ABSOLUTE(stext - _text); | ||
147 | |||
148 | /* | ||
149 | * Prevent the symbol aliases below from being emitted into the kallsyms | ||
150 | diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile | ||
151 | index 90aca95fe314..ad31c76c7a29 100644 | ||
152 | --- a/arch/mips/boot/compressed/Makefile | ||
153 | +++ b/arch/mips/boot/compressed/Makefile | ||
154 | @@ -75,6 +75,8 @@ OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.bin.z \ | ||
155 | $(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.bin.z FORCE | ||
156 | $(call if_changed,objcopy) | ||
157 | |||
158 | +HOSTCFLAGS_calc_vmlinuz_load_addr.o += $(LINUXINCLUDE) | ||
159 | + | ||
160 | # Calculate the load address of the compressed kernel image | ||
161 | hostprogs-y := calc_vmlinuz_load_addr | ||
162 | |||
163 | diff --git a/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | ||
164 | index 542c3ede9722..d14f75ec8273 100644 | ||
165 | --- a/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | ||
166 | +++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | ||
167 | @@ -13,7 +13,7 @@ | ||
168 | #include <stdint.h> | ||
169 | #include <stdio.h> | ||
170 | #include <stdlib.h> | ||
171 | -#include "../../../../include/linux/sizes.h" | ||
172 | +#include <linux/sizes.h> | ||
173 | |||
174 | int main(int argc, char *argv[]) | ||
175 | { | ||
176 | diff --git a/arch/mips/include/asm/mach-ath79/ar933x_uart.h b/arch/mips/include/asm/mach-ath79/ar933x_uart.h | ||
177 | index c2917b39966b..bba2c8837951 100644 | ||
178 | --- a/arch/mips/include/asm/mach-ath79/ar933x_uart.h | ||
179 | +++ b/arch/mips/include/asm/mach-ath79/ar933x_uart.h | ||
180 | @@ -27,8 +27,8 @@ | ||
181 | #define AR933X_UART_CS_PARITY_S 0 | ||
182 | #define AR933X_UART_CS_PARITY_M 0x3 | ||
183 | #define AR933X_UART_CS_PARITY_NONE 0 | ||
184 | -#define AR933X_UART_CS_PARITY_ODD 1 | ||
185 | -#define AR933X_UART_CS_PARITY_EVEN 2 | ||
186 | +#define AR933X_UART_CS_PARITY_ODD 2 | ||
187 | +#define AR933X_UART_CS_PARITY_EVEN 3 | ||
188 | #define AR933X_UART_CS_IF_MODE_S 2 | ||
189 | #define AR933X_UART_CS_IF_MODE_M 0x3 | ||
190 | #define AR933X_UART_CS_IF_MODE_NONE 0 | ||
191 | diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c | ||
192 | index 0780c375fe2e..e204fc49517d 100644 | ||
193 | --- a/arch/parisc/kernel/ptrace.c | ||
194 | +++ b/arch/parisc/kernel/ptrace.c | ||
195 | @@ -170,6 +170,9 @@ long arch_ptrace(struct task_struct *child, long request, | ||
196 | if ((addr & (sizeof(unsigned long)-1)) || | ||
197 | addr >= sizeof(struct pt_regs)) | ||
198 | break; | ||
199 | + if (addr == PT_IAOQ0 || addr == PT_IAOQ1) { | ||
200 | + data |= 3; /* ensure userspace privilege */ | ||
201 | + } | ||
202 | if ((addr >= PT_GR1 && addr <= PT_GR31) || | ||
203 | addr == PT_IAOQ0 || addr == PT_IAOQ1 || | ||
204 | (addr >= PT_FR0 && addr <= PT_FR31 + 4) || | ||
205 | @@ -231,16 +234,18 @@ long arch_ptrace(struct task_struct *child, long request, | ||
206 | |||
207 | static compat_ulong_t translate_usr_offset(compat_ulong_t offset) | ||
208 | { | ||
209 | - if (offset < 0) | ||
210 | - return sizeof(struct pt_regs); | ||
211 | - else if (offset <= 32*4) /* gr[0..31] */ | ||
212 | - return offset * 2 + 4; | ||
213 | - else if (offset <= 32*4+32*8) /* gr[0..31] + fr[0..31] */ | ||
214 | - return offset + 32*4; | ||
215 | - else if (offset < sizeof(struct pt_regs)/2 + 32*4) | ||
216 | - return offset * 2 + 4 - 32*8; | ||
217 | + compat_ulong_t pos; | ||
218 | + | ||
219 | + if (offset < 32*4) /* gr[0..31] */ | ||
220 | + pos = offset * 2 + 4; | ||
221 | + else if (offset < 32*4+32*8) /* fr[0] ... fr[31] */ | ||
222 | + pos = (offset - 32*4) + PT_FR0; | ||
223 | + else if (offset < sizeof(struct pt_regs)/2 + 32*4) /* sr[0] ... ipsw */ | ||
224 | + pos = (offset - 32*4 - 32*8) * 2 + PT_SR0 + 4; | ||
225 | else | ||
226 | - return sizeof(struct pt_regs); | ||
227 | + pos = sizeof(struct pt_regs); | ||
228 | + | ||
229 | + return pos; | ||
230 | } | ||
231 | |||
232 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | ||
233 | @@ -284,9 +289,12 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | ||
234 | addr = translate_usr_offset(addr); | ||
235 | if (addr >= sizeof(struct pt_regs)) | ||
236 | break; | ||
237 | + if (addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4) { | ||
238 | + data |= 3; /* ensure userspace privilege */ | ||
239 | + } | ||
240 | if (addr >= PT_FR0 && addr <= PT_FR31 + 4) { | ||
241 | /* Special case, fp regs are 64 bits anyway */ | ||
242 | - *(__u64 *) ((char *) task_regs(child) + addr) = data; | ||
243 | + *(__u32 *) ((char *) task_regs(child) + addr) = data; | ||
244 | ret = 0; | ||
245 | } | ||
246 | else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) || | ||
247 | @@ -499,7 +507,8 @@ static void set_reg(struct pt_regs *regs, int num, unsigned long val) | ||
248 | return; | ||
249 | case RI(iaoq[0]): | ||
250 | case RI(iaoq[1]): | ||
251 | - regs->iaoq[num - RI(iaoq[0])] = val; | ||
252 | + /* set 2 lowest bits to ensure userspace privilege: */ | ||
253 | + regs->iaoq[num - RI(iaoq[0])] = val | 3; | ||
254 | return; | ||
255 | case RI(sar): regs->sar = val; | ||
256 | return; | ||
257 | diff --git a/arch/powerpc/boot/xz_config.h b/arch/powerpc/boot/xz_config.h | ||
258 | index 5c6afdbca642..21b52c15aafc 100644 | ||
259 | --- a/arch/powerpc/boot/xz_config.h | ||
260 | +++ b/arch/powerpc/boot/xz_config.h | ||
261 | @@ -19,10 +19,30 @@ static inline uint32_t swab32p(void *p) | ||
262 | |||
263 | #ifdef __LITTLE_ENDIAN__ | ||
264 | #define get_le32(p) (*((uint32_t *) (p))) | ||
265 | +#define cpu_to_be32(x) swab32(x) | ||
266 | +static inline u32 be32_to_cpup(const u32 *p) | ||
267 | +{ | ||
268 | + return swab32p((u32 *)p); | ||
269 | +} | ||
270 | #else | ||
271 | #define get_le32(p) swab32p(p) | ||
272 | +#define cpu_to_be32(x) (x) | ||
273 | +static inline u32 be32_to_cpup(const u32 *p) | ||
274 | +{ | ||
275 | + return *p; | ||
276 | +} | ||
277 | #endif | ||
278 | |||
279 | +static inline uint32_t get_unaligned_be32(const void *p) | ||
280 | +{ | ||
281 | + return be32_to_cpup(p); | ||
282 | +} | ||
283 | + | ||
284 | +static inline void put_unaligned_be32(u32 val, void *p) | ||
285 | +{ | ||
286 | + *((u32 *)p) = cpu_to_be32(val); | ||
287 | +} | ||
288 | + | ||
289 | #define memeq(a, b, size) (memcmp(a, b, size) == 0) | ||
290 | #define memzero(buf, size) memset(buf, 0, size) | ||
291 | |||
292 | diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c | ||
293 | index 8336b9016ca9..a7f229e59892 100644 | ||
294 | --- a/arch/powerpc/kernel/eeh.c | ||
295 | +++ b/arch/powerpc/kernel/eeh.c | ||
296 | @@ -362,10 +362,19 @@ static inline unsigned long eeh_token_to_phys(unsigned long token) | ||
297 | NULL, &hugepage_shift); | ||
298 | if (!ptep) | ||
299 | return token; | ||
300 | - WARN_ON(hugepage_shift); | ||
301 | - pa = pte_pfn(*ptep) << PAGE_SHIFT; | ||
302 | |||
303 | - return pa | (token & (PAGE_SIZE-1)); | ||
304 | + pa = pte_pfn(*ptep); | ||
305 | + | ||
306 | + /* On radix we can do hugepage mappings for io, so handle that */ | ||
307 | + if (hugepage_shift) { | ||
308 | + pa <<= hugepage_shift; | ||
309 | + pa |= token & ((1ul << hugepage_shift) - 1); | ||
310 | + } else { | ||
311 | + pa <<= PAGE_SHIFT; | ||
312 | + pa |= token & (PAGE_SIZE - 1); | ||
313 | + } | ||
314 | + | ||
315 | + return pa; | ||
316 | } | ||
317 | |||
318 | /* | ||
319 | diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S | ||
320 | index d50cc9b38b80..92474227262b 100644 | ||
321 | --- a/arch/powerpc/kernel/exceptions-64s.S | ||
322 | +++ b/arch/powerpc/kernel/exceptions-64s.S | ||
323 | @@ -1505,7 +1505,7 @@ handle_page_fault: | ||
324 | addi r3,r1,STACK_FRAME_OVERHEAD | ||
325 | bl do_page_fault | ||
326 | cmpdi r3,0 | ||
327 | - beq+ 12f | ||
328 | + beq+ ret_from_except_lite | ||
329 | bl save_nvgprs | ||
330 | mr r5,r3 | ||
331 | addi r3,r1,STACK_FRAME_OVERHEAD | ||
332 | @@ -1520,7 +1520,12 @@ handle_dabr_fault: | ||
333 | ld r5,_DSISR(r1) | ||
334 | addi r3,r1,STACK_FRAME_OVERHEAD | ||
335 | bl do_break | ||
336 | -12: b ret_from_except_lite | ||
337 | + /* | ||
338 | + * do_break() may have changed the NV GPRS while handling a breakpoint. | ||
339 | + * If so, we need to restore them with their updated values. Don't use | ||
340 | + * ret_from_except_lite here. | ||
341 | + */ | ||
342 | + b ret_from_except | ||
343 | |||
344 | |||
345 | #ifdef CONFIG_PPC_STD_MMU_64 | ||
346 | diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c | ||
347 | index ea3d98115b88..e0648a09d9c8 100644 | ||
348 | --- a/arch/powerpc/kernel/pci_of_scan.c | ||
349 | +++ b/arch/powerpc/kernel/pci_of_scan.c | ||
350 | @@ -45,6 +45,8 @@ static unsigned int pci_parse_of_flags(u32 addr0, int bridge) | ||
351 | if (addr0 & 0x02000000) { | ||
352 | flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY; | ||
353 | flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64; | ||
354 | + if (flags & PCI_BASE_ADDRESS_MEM_TYPE_64) | ||
355 | + flags |= IORESOURCE_MEM_64; | ||
356 | flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M; | ||
357 | if (addr0 & 0x40000000) | ||
358 | flags |= IORESOURCE_PREFETCH | ||
359 | diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c | ||
360 | index 2bfa5a7bb672..a378b1e80a1a 100644 | ||
361 | --- a/arch/powerpc/kernel/signal_32.c | ||
362 | +++ b/arch/powerpc/kernel/signal_32.c | ||
363 | @@ -1281,6 +1281,9 @@ long sys_rt_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8, | ||
364 | goto bad; | ||
365 | |||
366 | if (MSR_TM_ACTIVE(msr_hi<<32)) { | ||
367 | + /* Trying to start TM on non TM system */ | ||
368 | + if (!cpu_has_feature(CPU_FTR_TM)) | ||
369 | + goto bad; | ||
370 | /* We only recheckpoint on return if we're | ||
371 | * transaction. | ||
372 | */ | ||
373 | diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c | ||
374 | index bdf2f7b995bb..f4c46b0ec611 100644 | ||
375 | --- a/arch/powerpc/kernel/signal_64.c | ||
376 | +++ b/arch/powerpc/kernel/signal_64.c | ||
377 | @@ -741,6 +741,11 @@ int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5, | ||
378 | if (MSR_TM_ACTIVE(msr)) { | ||
379 | /* We recheckpoint on return. */ | ||
380 | struct ucontext __user *uc_transact; | ||
381 | + | ||
382 | + /* Trying to start TM on non TM system */ | ||
383 | + if (!cpu_has_feature(CPU_FTR_TM)) | ||
384 | + goto badframe; | ||
385 | + | ||
386 | if (__get_user(uc_transact, &uc->uc_link)) | ||
387 | goto badframe; | ||
388 | if (restore_tm_sigcontexts(current, &uc->uc_mcontext, | ||
389 | diff --git a/arch/powerpc/kernel/swsusp_32.S b/arch/powerpc/kernel/swsusp_32.S | ||
390 | index ba4dee3d233f..884d1c3a187b 100644 | ||
391 | --- a/arch/powerpc/kernel/swsusp_32.S | ||
392 | +++ b/arch/powerpc/kernel/swsusp_32.S | ||
393 | @@ -23,11 +23,19 @@ | ||
394 | #define SL_IBAT2 0x48 | ||
395 | #define SL_DBAT3 0x50 | ||
396 | #define SL_IBAT3 0x58 | ||
397 | -#define SL_TB 0x60 | ||
398 | -#define SL_R2 0x68 | ||
399 | -#define SL_CR 0x6c | ||
400 | -#define SL_LR 0x70 | ||
401 | -#define SL_R12 0x74 /* r12 to r31 */ | ||
402 | +#define SL_DBAT4 0x60 | ||
403 | +#define SL_IBAT4 0x68 | ||
404 | +#define SL_DBAT5 0x70 | ||
405 | +#define SL_IBAT5 0x78 | ||
406 | +#define SL_DBAT6 0x80 | ||
407 | +#define SL_IBAT6 0x88 | ||
408 | +#define SL_DBAT7 0x90 | ||
409 | +#define SL_IBAT7 0x98 | ||
410 | +#define SL_TB 0xa0 | ||
411 | +#define SL_R2 0xa8 | ||
412 | +#define SL_CR 0xac | ||
413 | +#define SL_LR 0xb0 | ||
414 | +#define SL_R12 0xb4 /* r12 to r31 */ | ||
415 | #define SL_SIZE (SL_R12 + 80) | ||
416 | |||
417 | .section .data | ||
418 | @@ -112,6 +120,41 @@ _GLOBAL(swsusp_arch_suspend) | ||
419 | mfibatl r4,3 | ||
420 | stw r4,SL_IBAT3+4(r11) | ||
421 | |||
422 | +BEGIN_MMU_FTR_SECTION | ||
423 | + mfspr r4,SPRN_DBAT4U | ||
424 | + stw r4,SL_DBAT4(r11) | ||
425 | + mfspr r4,SPRN_DBAT4L | ||
426 | + stw r4,SL_DBAT4+4(r11) | ||
427 | + mfspr r4,SPRN_DBAT5U | ||
428 | + stw r4,SL_DBAT5(r11) | ||
429 | + mfspr r4,SPRN_DBAT5L | ||
430 | + stw r4,SL_DBAT5+4(r11) | ||
431 | + mfspr r4,SPRN_DBAT6U | ||
432 | + stw r4,SL_DBAT6(r11) | ||
433 | + mfspr r4,SPRN_DBAT6L | ||
434 | + stw r4,SL_DBAT6+4(r11) | ||
435 | + mfspr r4,SPRN_DBAT7U | ||
436 | + stw r4,SL_DBAT7(r11) | ||
437 | + mfspr r4,SPRN_DBAT7L | ||
438 | + stw r4,SL_DBAT7+4(r11) | ||
439 | + mfspr r4,SPRN_IBAT4U | ||
440 | + stw r4,SL_IBAT4(r11) | ||
441 | + mfspr r4,SPRN_IBAT4L | ||
442 | + stw r4,SL_IBAT4+4(r11) | ||
443 | + mfspr r4,SPRN_IBAT5U | ||
444 | + stw r4,SL_IBAT5(r11) | ||
445 | + mfspr r4,SPRN_IBAT5L | ||
446 | + stw r4,SL_IBAT5+4(r11) | ||
447 | + mfspr r4,SPRN_IBAT6U | ||
448 | + stw r4,SL_IBAT6(r11) | ||
449 | + mfspr r4,SPRN_IBAT6L | ||
450 | + stw r4,SL_IBAT6+4(r11) | ||
451 | + mfspr r4,SPRN_IBAT7U | ||
452 | + stw r4,SL_IBAT7(r11) | ||
453 | + mfspr r4,SPRN_IBAT7L | ||
454 | + stw r4,SL_IBAT7+4(r11) | ||
455 | +END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS) | ||
456 | + | ||
457 | #if 0 | ||
458 | /* Backup various CPU config stuffs */ | ||
459 | bl __save_cpu_setup | ||
460 | @@ -277,27 +320,41 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) | ||
461 | mtibatu 3,r4 | ||
462 | lwz r4,SL_IBAT3+4(r11) | ||
463 | mtibatl 3,r4 | ||
464 | -#endif | ||
465 | - | ||
466 | BEGIN_MMU_FTR_SECTION | ||
467 | - li r4,0 | ||
468 | + lwz r4,SL_DBAT4(r11) | ||
469 | mtspr SPRN_DBAT4U,r4 | ||
470 | + lwz r4,SL_DBAT4+4(r11) | ||
471 | mtspr SPRN_DBAT4L,r4 | ||
472 | + lwz r4,SL_DBAT5(r11) | ||
473 | mtspr SPRN_DBAT5U,r4 | ||
474 | + lwz r4,SL_DBAT5+4(r11) | ||
475 | mtspr SPRN_DBAT5L,r4 | ||
476 | + lwz r4,SL_DBAT6(r11) | ||
477 | mtspr SPRN_DBAT6U,r4 | ||
478 | + lwz r4,SL_DBAT6+4(r11) | ||
479 | mtspr SPRN_DBAT6L,r4 | ||
480 | + lwz r4,SL_DBAT7(r11) | ||
481 | mtspr SPRN_DBAT7U,r4 | ||
482 | + lwz r4,SL_DBAT7+4(r11) | ||
483 | mtspr SPRN_DBAT7L,r4 | ||
484 | + lwz r4,SL_IBAT4(r11) | ||
485 | mtspr SPRN_IBAT4U,r4 | ||
486 | + lwz r4,SL_IBAT4+4(r11) | ||
487 | mtspr SPRN_IBAT4L,r4 | ||
488 | + lwz r4,SL_IBAT5(r11) | ||
489 | mtspr SPRN_IBAT5U,r4 | ||
490 | + lwz r4,SL_IBAT5+4(r11) | ||
491 | mtspr SPRN_IBAT5L,r4 | ||
492 | + lwz r4,SL_IBAT6(r11) | ||
493 | mtspr SPRN_IBAT6U,r4 | ||
494 | + lwz r4,SL_IBAT6+4(r11) | ||
495 | mtspr SPRN_IBAT6L,r4 | ||
496 | + lwz r4,SL_IBAT7(r11) | ||
497 | mtspr SPRN_IBAT7U,r4 | ||
498 | + lwz r4,SL_IBAT7+4(r11) | ||
499 | mtspr SPRN_IBAT7L,r4 | ||
500 | END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS) | ||
501 | +#endif | ||
502 | |||
503 | /* Flush all TLBs */ | ||
504 | lis r4,0x1000 | ||
505 | diff --git a/arch/powerpc/platforms/powermac/sleep.S b/arch/powerpc/platforms/powermac/sleep.S | ||
506 | index 1c2802fabd57..c856cd7fcdc4 100644 | ||
507 | --- a/arch/powerpc/platforms/powermac/sleep.S | ||
508 | +++ b/arch/powerpc/platforms/powermac/sleep.S | ||
509 | @@ -37,10 +37,18 @@ | ||
510 | #define SL_IBAT2 0x48 | ||
511 | #define SL_DBAT3 0x50 | ||
512 | #define SL_IBAT3 0x58 | ||
513 | -#define SL_TB 0x60 | ||
514 | -#define SL_R2 0x68 | ||
515 | -#define SL_CR 0x6c | ||
516 | -#define SL_R12 0x70 /* r12 to r31 */ | ||
517 | +#define SL_DBAT4 0x60 | ||
518 | +#define SL_IBAT4 0x68 | ||
519 | +#define SL_DBAT5 0x70 | ||
520 | +#define SL_IBAT5 0x78 | ||
521 | +#define SL_DBAT6 0x80 | ||
522 | +#define SL_IBAT6 0x88 | ||
523 | +#define SL_DBAT7 0x90 | ||
524 | +#define SL_IBAT7 0x98 | ||
525 | +#define SL_TB 0xa0 | ||
526 | +#define SL_R2 0xa8 | ||
527 | +#define SL_CR 0xac | ||
528 | +#define SL_R12 0xb0 /* r12 to r31 */ | ||
529 | #define SL_SIZE (SL_R12 + 80) | ||
530 | |||
531 | .section .text | ||
532 | @@ -125,6 +133,41 @@ _GLOBAL(low_sleep_handler) | ||
533 | mfibatl r4,3 | ||
534 | stw r4,SL_IBAT3+4(r1) | ||
535 | |||
536 | +BEGIN_MMU_FTR_SECTION | ||
537 | + mfspr r4,SPRN_DBAT4U | ||
538 | + stw r4,SL_DBAT4(r1) | ||
539 | + mfspr r4,SPRN_DBAT4L | ||
540 | + stw r4,SL_DBAT4+4(r1) | ||
541 | + mfspr r4,SPRN_DBAT5U | ||
542 | + stw r4,SL_DBAT5(r1) | ||
543 | + mfspr r4,SPRN_DBAT5L | ||
544 | + stw r4,SL_DBAT5+4(r1) | ||
545 | + mfspr r4,SPRN_DBAT6U | ||
546 | + stw r4,SL_DBAT6(r1) | ||
547 | + mfspr r4,SPRN_DBAT6L | ||
548 | + stw r4,SL_DBAT6+4(r1) | ||
549 | + mfspr r4,SPRN_DBAT7U | ||
550 | + stw r4,SL_DBAT7(r1) | ||
551 | + mfspr r4,SPRN_DBAT7L | ||
552 | + stw r4,SL_DBAT7+4(r1) | ||
553 | + mfspr r4,SPRN_IBAT4U | ||
554 | + stw r4,SL_IBAT4(r1) | ||
555 | + mfspr r4,SPRN_IBAT4L | ||
556 | + stw r4,SL_IBAT4+4(r1) | ||
557 | + mfspr r4,SPRN_IBAT5U | ||
558 | + stw r4,SL_IBAT5(r1) | ||
559 | + mfspr r4,SPRN_IBAT5L | ||
560 | + stw r4,SL_IBAT5+4(r1) | ||
561 | + mfspr r4,SPRN_IBAT6U | ||
562 | + stw r4,SL_IBAT6(r1) | ||
563 | + mfspr r4,SPRN_IBAT6L | ||
564 | + stw r4,SL_IBAT6+4(r1) | ||
565 | + mfspr r4,SPRN_IBAT7U | ||
566 | + stw r4,SL_IBAT7(r1) | ||
567 | + mfspr r4,SPRN_IBAT7L | ||
568 | + stw r4,SL_IBAT7+4(r1) | ||
569 | +END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS) | ||
570 | + | ||
571 | /* Backup various CPU config stuffs */ | ||
572 | bl __save_cpu_setup | ||
573 | |||
574 | @@ -325,22 +368,37 @@ grackle_wake_up: | ||
575 | mtibatl 3,r4 | ||
576 | |||
577 | BEGIN_MMU_FTR_SECTION | ||
578 | - li r4,0 | ||
579 | + lwz r4,SL_DBAT4(r1) | ||
580 | mtspr SPRN_DBAT4U,r4 | ||
581 | + lwz r4,SL_DBAT4+4(r1) | ||
582 | mtspr SPRN_DBAT4L,r4 | ||
583 | + lwz r4,SL_DBAT5(r1) | ||
584 | mtspr SPRN_DBAT5U,r4 | ||
585 | + lwz r4,SL_DBAT5+4(r1) | ||
586 | mtspr SPRN_DBAT5L,r4 | ||
587 | + lwz r4,SL_DBAT6(r1) | ||
588 | mtspr SPRN_DBAT6U,r4 | ||
589 | + lwz r4,SL_DBAT6+4(r1) | ||
590 | mtspr SPRN_DBAT6L,r4 | ||
591 | + lwz r4,SL_DBAT7(r1) | ||
592 | mtspr SPRN_DBAT7U,r4 | ||
593 | + lwz r4,SL_DBAT7+4(r1) | ||
594 | mtspr SPRN_DBAT7L,r4 | ||
595 | + lwz r4,SL_IBAT4(r1) | ||
596 | mtspr SPRN_IBAT4U,r4 | ||
597 | + lwz r4,SL_IBAT4+4(r1) | ||
598 | mtspr SPRN_IBAT4L,r4 | ||
599 | + lwz r4,SL_IBAT5(r1) | ||
600 | mtspr SPRN_IBAT5U,r4 | ||
601 | + lwz r4,SL_IBAT5+4(r1) | ||
602 | mtspr SPRN_IBAT5L,r4 | ||
603 | + lwz r4,SL_IBAT6(r1) | ||
604 | mtspr SPRN_IBAT6U,r4 | ||
605 | + lwz r4,SL_IBAT6+4(r1) | ||
606 | mtspr SPRN_IBAT6L,r4 | ||
607 | + lwz r4,SL_IBAT7(r1) | ||
608 | mtspr SPRN_IBAT7U,r4 | ||
609 | + lwz r4,SL_IBAT7+4(r1) | ||
610 | mtspr SPRN_IBAT7L,r4 | ||
611 | END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS) | ||
612 | |||
613 | diff --git a/arch/powerpc/sysdev/uic.c b/arch/powerpc/sysdev/uic.c | ||
614 | index a00949f3e378..a8ebc96dfed2 100644 | ||
615 | --- a/arch/powerpc/sysdev/uic.c | ||
616 | +++ b/arch/powerpc/sysdev/uic.c | ||
617 | @@ -158,6 +158,7 @@ static int uic_set_irq_type(struct irq_data *d, unsigned int flow_type) | ||
618 | |||
619 | mtdcr(uic->dcrbase + UIC_PR, pr); | ||
620 | mtdcr(uic->dcrbase + UIC_TR, tr); | ||
621 | + mtdcr(uic->dcrbase + UIC_SR, ~mask); | ||
622 | |||
623 | raw_spin_unlock_irqrestore(&uic->lock, flags); | ||
624 | |||
625 | diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h | ||
626 | index 3280a6bfa503..b2592c3864ad 100644 | ||
627 | --- a/arch/sh/include/asm/io.h | ||
628 | +++ b/arch/sh/include/asm/io.h | ||
629 | @@ -370,7 +370,11 @@ static inline int iounmap_fixed(void __iomem *addr) { return -EINVAL; } | ||
630 | |||
631 | #define ioremap_nocache ioremap | ||
632 | #define ioremap_uc ioremap | ||
633 | -#define iounmap __iounmap | ||
634 | + | ||
635 | +static inline void iounmap(void __iomem *addr) | ||
636 | +{ | ||
637 | + __iounmap(addr); | ||
638 | +} | ||
639 | |||
640 | /* | ||
641 | * Convert a physical pointer to a virtual kernel pointer for /dev/mem | ||
642 | diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h | ||
643 | index 1a60e1328e2f..6aca4c90aa1a 100644 | ||
644 | --- a/arch/um/include/asm/mmu_context.h | ||
645 | +++ b/arch/um/include/asm/mmu_context.h | ||
646 | @@ -56,7 +56,7 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new) | ||
647 | * when the new ->mm is used for the first time. | ||
648 | */ | ||
649 | __switch_mm(&new->context.id); | ||
650 | - down_write(&new->mmap_sem); | ||
651 | + down_write_nested(&new->mmap_sem, 1); | ||
652 | uml_setup_stubs(new); | ||
653 | up_write(&new->mmap_sem); | ||
654 | } | ||
655 | diff --git a/arch/um/include/asm/thread_info.h b/arch/um/include/asm/thread_info.h | ||
656 | index 053baff03674..9300f7630d2a 100644 | ||
657 | --- a/arch/um/include/asm/thread_info.h | ||
658 | +++ b/arch/um/include/asm/thread_info.h | ||
659 | @@ -11,6 +11,7 @@ | ||
660 | #include <asm/types.h> | ||
661 | #include <asm/page.h> | ||
662 | #include <asm/segment.h> | ||
663 | +#include <sysdep/ptrace_user.h> | ||
664 | |||
665 | struct thread_info { | ||
666 | struct task_struct *task; /* main task structure */ | ||
667 | @@ -22,6 +23,8 @@ struct thread_info { | ||
668 | 0-0xBFFFFFFF for user | ||
669 | 0-0xFFFFFFFF for kernel */ | ||
670 | struct thread_info *real_thread; /* Points to non-IRQ stack */ | ||
671 | + unsigned long aux_fp_regs[FP_SIZE]; /* auxiliary fp_regs to save/restore | ||
672 | + them out-of-band */ | ||
673 | }; | ||
674 | |||
675 | #define INIT_THREAD_INFO(tsk) \ | ||
676 | diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h | ||
677 | index de5d572225f3..cc64f0579949 100644 | ||
678 | --- a/arch/um/include/shared/os.h | ||
679 | +++ b/arch/um/include/shared/os.h | ||
680 | @@ -274,7 +274,7 @@ extern int protect(struct mm_id * mm_idp, unsigned long addr, | ||
681 | extern int is_skas_winch(int pid, int fd, void *data); | ||
682 | extern int start_userspace(unsigned long stub_stack); | ||
683 | extern int copy_context_skas0(unsigned long stack, int pid); | ||
684 | -extern void userspace(struct uml_pt_regs *regs); | ||
685 | +extern void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs); | ||
686 | extern int map_stub_pages(int fd, unsigned long code, unsigned long data, | ||
687 | unsigned long stack); | ||
688 | extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)); | ||
689 | diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c | ||
690 | index 034b42c7ab40..787568044a2a 100644 | ||
691 | --- a/arch/um/kernel/process.c | ||
692 | +++ b/arch/um/kernel/process.c | ||
693 | @@ -128,7 +128,7 @@ void new_thread_handler(void) | ||
694 | * callback returns only if the kernel thread execs a process | ||
695 | */ | ||
696 | n = fn(arg); | ||
697 | - userspace(¤t->thread.regs.regs); | ||
698 | + userspace(¤t->thread.regs.regs, current_thread_info()->aux_fp_regs); | ||
699 | } | ||
700 | |||
701 | /* Called magically, see new_thread_handler above */ | ||
702 | @@ -147,7 +147,7 @@ void fork_handler(void) | ||
703 | |||
704 | current->thread.prev_sched = NULL; | ||
705 | |||
706 | - userspace(¤t->thread.regs.regs); | ||
707 | + userspace(¤t->thread.regs.regs, current_thread_info()->aux_fp_regs); | ||
708 | } | ||
709 | |||
710 | int copy_thread(unsigned long clone_flags, unsigned long sp, | ||
711 | diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c | ||
712 | index 0a99d4515065..cd4a6ff676a8 100644 | ||
713 | --- a/arch/um/os-Linux/skas/process.c | ||
714 | +++ b/arch/um/os-Linux/skas/process.c | ||
715 | @@ -87,12 +87,11 @@ bad_wait: | ||
716 | |||
717 | extern unsigned long current_stub_stack(void); | ||
718 | |||
719 | -static void get_skas_faultinfo(int pid, struct faultinfo *fi) | ||
720 | +static void get_skas_faultinfo(int pid, struct faultinfo *fi, unsigned long *aux_fp_regs) | ||
721 | { | ||
722 | int err; | ||
723 | - unsigned long fpregs[FP_SIZE]; | ||
724 | |||
725 | - err = get_fp_registers(pid, fpregs); | ||
726 | + err = get_fp_registers(pid, aux_fp_regs); | ||
727 | if (err < 0) { | ||
728 | printk(UM_KERN_ERR "save_fp_registers returned %d\n", | ||
729 | err); | ||
730 | @@ -112,7 +111,7 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi) | ||
731 | */ | ||
732 | memcpy(fi, (void *)current_stub_stack(), sizeof(*fi)); | ||
733 | |||
734 | - err = put_fp_registers(pid, fpregs); | ||
735 | + err = put_fp_registers(pid, aux_fp_regs); | ||
736 | if (err < 0) { | ||
737 | printk(UM_KERN_ERR "put_fp_registers returned %d\n", | ||
738 | err); | ||
739 | @@ -120,9 +119,9 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi) | ||
740 | } | ||
741 | } | ||
742 | |||
743 | -static void handle_segv(int pid, struct uml_pt_regs * regs) | ||
744 | +static void handle_segv(int pid, struct uml_pt_regs *regs, unsigned long *aux_fp_regs) | ||
745 | { | ||
746 | - get_skas_faultinfo(pid, ®s->faultinfo); | ||
747 | + get_skas_faultinfo(pid, ®s->faultinfo, aux_fp_regs); | ||
748 | segv(regs->faultinfo, 0, 1, NULL); | ||
749 | } | ||
750 | |||
751 | @@ -305,7 +304,7 @@ int start_userspace(unsigned long stub_stack) | ||
752 | return err; | ||
753 | } | ||
754 | |||
755 | -void userspace(struct uml_pt_regs *regs) | ||
756 | +void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs) | ||
757 | { | ||
758 | int err, status, op, pid = userspace_pid[0]; | ||
759 | /* To prevent races if using_sysemu changes under us.*/ | ||
760 | @@ -374,11 +373,11 @@ void userspace(struct uml_pt_regs *regs) | ||
761 | case SIGSEGV: | ||
762 | if (PTRACE_FULL_FAULTINFO) { | ||
763 | get_skas_faultinfo(pid, | ||
764 | - ®s->faultinfo); | ||
765 | + ®s->faultinfo, aux_fp_regs); | ||
766 | (*sig_info[SIGSEGV])(SIGSEGV, (struct siginfo *)&si, | ||
767 | regs); | ||
768 | } | ||
769 | - else handle_segv(pid, regs); | ||
770 | + else handle_segv(pid, regs, aux_fp_regs); | ||
771 | break; | ||
772 | case SIGTRAP + 0x80: | ||
773 | handle_trap(pid, regs, local_using_sysemu); | ||
774 | diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c | ||
775 | index 65577f081d07..c16c99bc2a10 100644 | ||
776 | --- a/arch/x86/events/amd/uncore.c | ||
777 | +++ b/arch/x86/events/amd/uncore.c | ||
778 | @@ -19,13 +19,14 @@ | ||
779 | #include <asm/cpufeature.h> | ||
780 | #include <asm/perf_event.h> | ||
781 | #include <asm/msr.h> | ||
782 | +#include <asm/smp.h> | ||
783 | |||
784 | #define NUM_COUNTERS_NB 4 | ||
785 | #define NUM_COUNTERS_L2 4 | ||
786 | #define MAX_COUNTERS NUM_COUNTERS_NB | ||
787 | |||
788 | #define RDPMC_BASE_NB 6 | ||
789 | -#define RDPMC_BASE_L2 10 | ||
790 | +#define RDPMC_BASE_LLC 10 | ||
791 | |||
792 | #define COUNTER_SHIFT 16 | ||
793 | |||
794 | @@ -45,30 +46,30 @@ struct amd_uncore { | ||
795 | }; | ||
796 | |||
797 | static struct amd_uncore * __percpu *amd_uncore_nb; | ||
798 | -static struct amd_uncore * __percpu *amd_uncore_l2; | ||
799 | +static struct amd_uncore * __percpu *amd_uncore_llc; | ||
800 | |||
801 | static struct pmu amd_nb_pmu; | ||
802 | -static struct pmu amd_l2_pmu; | ||
803 | +static struct pmu amd_llc_pmu; | ||
804 | |||
805 | static cpumask_t amd_nb_active_mask; | ||
806 | -static cpumask_t amd_l2_active_mask; | ||
807 | +static cpumask_t amd_llc_active_mask; | ||
808 | |||
809 | static bool is_nb_event(struct perf_event *event) | ||
810 | { | ||
811 | return event->pmu->type == amd_nb_pmu.type; | ||
812 | } | ||
813 | |||
814 | -static bool is_l2_event(struct perf_event *event) | ||
815 | +static bool is_llc_event(struct perf_event *event) | ||
816 | { | ||
817 | - return event->pmu->type == amd_l2_pmu.type; | ||
818 | + return event->pmu->type == amd_llc_pmu.type; | ||
819 | } | ||
820 | |||
821 | static struct amd_uncore *event_to_amd_uncore(struct perf_event *event) | ||
822 | { | ||
823 | if (is_nb_event(event) && amd_uncore_nb) | ||
824 | return *per_cpu_ptr(amd_uncore_nb, event->cpu); | ||
825 | - else if (is_l2_event(event) && amd_uncore_l2) | ||
826 | - return *per_cpu_ptr(amd_uncore_l2, event->cpu); | ||
827 | + else if (is_llc_event(event) && amd_uncore_llc) | ||
828 | + return *per_cpu_ptr(amd_uncore_llc, event->cpu); | ||
829 | |||
830 | return NULL; | ||
831 | } | ||
832 | @@ -183,16 +184,16 @@ static int amd_uncore_event_init(struct perf_event *event) | ||
833 | return -ENOENT; | ||
834 | |||
835 | /* | ||
836 | - * NB and L2 counters (MSRs) are shared across all cores that share the | ||
837 | - * same NB / L2 cache. Interrupts can be directed to a single target | ||
838 | - * core, however, event counts generated by processes running on other | ||
839 | - * cores cannot be masked out. So we do not support sampling and | ||
840 | - * per-thread events. | ||
841 | + * NB and Last level cache counters (MSRs) are shared across all cores | ||
842 | + * that share the same NB / Last level cache. Interrupts can be directed | ||
843 | + * to a single target core, however, event counts generated by processes | ||
844 | + * running on other cores cannot be masked out. So we do not support | ||
845 | + * sampling and per-thread events. | ||
846 | */ | ||
847 | if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK) | ||
848 | return -EINVAL; | ||
849 | |||
850 | - /* NB and L2 counters do not have usr/os/guest/host bits */ | ||
851 | + /* NB and Last level cache counters do not have usr/os/guest/host bits */ | ||
852 | if (event->attr.exclude_user || event->attr.exclude_kernel || | ||
853 | event->attr.exclude_host || event->attr.exclude_guest) | ||
854 | return -EINVAL; | ||
855 | @@ -226,8 +227,8 @@ static ssize_t amd_uncore_attr_show_cpumask(struct device *dev, | ||
856 | |||
857 | if (pmu->type == amd_nb_pmu.type) | ||
858 | active_mask = &amd_nb_active_mask; | ||
859 | - else if (pmu->type == amd_l2_pmu.type) | ||
860 | - active_mask = &amd_l2_active_mask; | ||
861 | + else if (pmu->type == amd_llc_pmu.type) | ||
862 | + active_mask = &amd_llc_active_mask; | ||
863 | else | ||
864 | return 0; | ||
865 | |||
866 | @@ -276,7 +277,7 @@ static struct pmu amd_nb_pmu = { | ||
867 | .read = amd_uncore_read, | ||
868 | }; | ||
869 | |||
870 | -static struct pmu amd_l2_pmu = { | ||
871 | +static struct pmu amd_llc_pmu = { | ||
872 | .task_ctx_nr = perf_invalid_context, | ||
873 | .attr_groups = amd_uncore_attr_groups, | ||
874 | .name = "amd_l2", | ||
875 | @@ -296,7 +297,7 @@ static struct amd_uncore *amd_uncore_alloc(unsigned int cpu) | ||
876 | |||
877 | static int amd_uncore_cpu_up_prepare(unsigned int cpu) | ||
878 | { | ||
879 | - struct amd_uncore *uncore_nb = NULL, *uncore_l2; | ||
880 | + struct amd_uncore *uncore_nb = NULL, *uncore_llc; | ||
881 | |||
882 | if (amd_uncore_nb) { | ||
883 | uncore_nb = amd_uncore_alloc(cpu); | ||
884 | @@ -312,18 +313,18 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) | ||
885 | *per_cpu_ptr(amd_uncore_nb, cpu) = uncore_nb; | ||
886 | } | ||
887 | |||
888 | - if (amd_uncore_l2) { | ||
889 | - uncore_l2 = amd_uncore_alloc(cpu); | ||
890 | - if (!uncore_l2) | ||
891 | + if (amd_uncore_llc) { | ||
892 | + uncore_llc = amd_uncore_alloc(cpu); | ||
893 | + if (!uncore_llc) | ||
894 | goto fail; | ||
895 | - uncore_l2->cpu = cpu; | ||
896 | - uncore_l2->num_counters = NUM_COUNTERS_L2; | ||
897 | - uncore_l2->rdpmc_base = RDPMC_BASE_L2; | ||
898 | - uncore_l2->msr_base = MSR_F16H_L2I_PERF_CTL; | ||
899 | - uncore_l2->active_mask = &amd_l2_active_mask; | ||
900 | - uncore_l2->pmu = &amd_l2_pmu; | ||
901 | - uncore_l2->id = -1; | ||
902 | - *per_cpu_ptr(amd_uncore_l2, cpu) = uncore_l2; | ||
903 | + uncore_llc->cpu = cpu; | ||
904 | + uncore_llc->num_counters = NUM_COUNTERS_L2; | ||
905 | + uncore_llc->rdpmc_base = RDPMC_BASE_LLC; | ||
906 | + uncore_llc->msr_base = MSR_F16H_L2I_PERF_CTL; | ||
907 | + uncore_llc->active_mask = &amd_llc_active_mask; | ||
908 | + uncore_llc->pmu = &amd_llc_pmu; | ||
909 | + uncore_llc->id = -1; | ||
910 | + *per_cpu_ptr(amd_uncore_llc, cpu) = uncore_llc; | ||
911 | } | ||
912 | |||
913 | return 0; | ||
914 | @@ -376,17 +377,12 @@ static int amd_uncore_cpu_starting(unsigned int cpu) | ||
915 | *per_cpu_ptr(amd_uncore_nb, cpu) = uncore; | ||
916 | } | ||
917 | |||
918 | - if (amd_uncore_l2) { | ||
919 | - unsigned int apicid = cpu_data(cpu).apicid; | ||
920 | - unsigned int nshared; | ||
921 | + if (amd_uncore_llc) { | ||
922 | + uncore = *per_cpu_ptr(amd_uncore_llc, cpu); | ||
923 | + uncore->id = per_cpu(cpu_llc_id, cpu); | ||
924 | |||
925 | - uncore = *per_cpu_ptr(amd_uncore_l2, cpu); | ||
926 | - cpuid_count(0x8000001d, 2, &eax, &ebx, &ecx, &edx); | ||
927 | - nshared = ((eax >> 14) & 0xfff) + 1; | ||
928 | - uncore->id = apicid - (apicid % nshared); | ||
929 | - | ||
930 | - uncore = amd_uncore_find_online_sibling(uncore, amd_uncore_l2); | ||
931 | - *per_cpu_ptr(amd_uncore_l2, cpu) = uncore; | ||
932 | + uncore = amd_uncore_find_online_sibling(uncore, amd_uncore_llc); | ||
933 | + *per_cpu_ptr(amd_uncore_llc, cpu) = uncore; | ||
934 | } | ||
935 | |||
936 | return 0; | ||
937 | @@ -419,8 +415,8 @@ static int amd_uncore_cpu_online(unsigned int cpu) | ||
938 | if (amd_uncore_nb) | ||
939 | uncore_online(cpu, amd_uncore_nb); | ||
940 | |||
941 | - if (amd_uncore_l2) | ||
942 | - uncore_online(cpu, amd_uncore_l2); | ||
943 | + if (amd_uncore_llc) | ||
944 | + uncore_online(cpu, amd_uncore_llc); | ||
945 | |||
946 | return 0; | ||
947 | } | ||
948 | @@ -456,8 +452,8 @@ static int amd_uncore_cpu_down_prepare(unsigned int cpu) | ||
949 | if (amd_uncore_nb) | ||
950 | uncore_down_prepare(cpu, amd_uncore_nb); | ||
951 | |||
952 | - if (amd_uncore_l2) | ||
953 | - uncore_down_prepare(cpu, amd_uncore_l2); | ||
954 | + if (amd_uncore_llc) | ||
955 | + uncore_down_prepare(cpu, amd_uncore_llc); | ||
956 | |||
957 | return 0; | ||
958 | } | ||
959 | @@ -479,8 +475,8 @@ static int amd_uncore_cpu_dead(unsigned int cpu) | ||
960 | if (amd_uncore_nb) | ||
961 | uncore_dead(cpu, amd_uncore_nb); | ||
962 | |||
963 | - if (amd_uncore_l2) | ||
964 | - uncore_dead(cpu, amd_uncore_l2); | ||
965 | + if (amd_uncore_llc) | ||
966 | + uncore_dead(cpu, amd_uncore_llc); | ||
967 | |||
968 | return 0; | ||
969 | } | ||
970 | @@ -510,16 +506,16 @@ static int __init amd_uncore_init(void) | ||
971 | } | ||
972 | |||
973 | if (boot_cpu_has(X86_FEATURE_PERFCTR_L2)) { | ||
974 | - amd_uncore_l2 = alloc_percpu(struct amd_uncore *); | ||
975 | - if (!amd_uncore_l2) { | ||
976 | + amd_uncore_llc = alloc_percpu(struct amd_uncore *); | ||
977 | + if (!amd_uncore_llc) { | ||
978 | ret = -ENOMEM; | ||
979 | - goto fail_l2; | ||
980 | + goto fail_llc; | ||
981 | } | ||
982 | - ret = perf_pmu_register(&amd_l2_pmu, amd_l2_pmu.name, -1); | ||
983 | + ret = perf_pmu_register(&amd_llc_pmu, amd_llc_pmu.name, -1); | ||
984 | if (ret) | ||
985 | - goto fail_l2; | ||
986 | + goto fail_llc; | ||
987 | |||
988 | - pr_info("perf: AMD L2I counters detected\n"); | ||
989 | + pr_info("perf: AMD LLC counters detected\n"); | ||
990 | ret = 0; | ||
991 | } | ||
992 | |||
993 | @@ -529,7 +525,7 @@ static int __init amd_uncore_init(void) | ||
994 | if (cpuhp_setup_state(CPUHP_PERF_X86_AMD_UNCORE_PREP, | ||
995 | "PERF_X86_AMD_UNCORE_PREP", | ||
996 | amd_uncore_cpu_up_prepare, amd_uncore_cpu_dead)) | ||
997 | - goto fail_l2; | ||
998 | + goto fail_llc; | ||
999 | |||
1000 | if (cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING, | ||
1001 | "AP_PERF_X86_AMD_UNCORE_STARTING", | ||
1002 | @@ -546,11 +542,11 @@ fail_start: | ||
1003 | cpuhp_remove_state(CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING); | ||
1004 | fail_prep: | ||
1005 | cpuhp_remove_state(CPUHP_PERF_X86_AMD_UNCORE_PREP); | ||
1006 | -fail_l2: | ||
1007 | +fail_llc: | ||
1008 | if (boot_cpu_has(X86_FEATURE_PERFCTR_NB)) | ||
1009 | perf_pmu_unregister(&amd_nb_pmu); | ||
1010 | - if (amd_uncore_l2) | ||
1011 | - free_percpu(amd_uncore_l2); | ||
1012 | + if (amd_uncore_llc) | ||
1013 | + free_percpu(amd_uncore_llc); | ||
1014 | fail_nb: | ||
1015 | if (amd_uncore_nb) | ||
1016 | free_percpu(amd_uncore_nb); | ||
1017 | diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c | ||
1018 | index 07a6c1fa173b..a4f343ac042e 100644 | ||
1019 | --- a/arch/x86/kernel/cpu/bugs.c | ||
1020 | +++ b/arch/x86/kernel/cpu/bugs.c | ||
1021 | @@ -1205,7 +1205,7 @@ static ssize_t l1tf_show_state(char *buf) | ||
1022 | static ssize_t mds_show_state(char *buf) | ||
1023 | { | ||
1024 | #ifdef CONFIG_HYPERVISOR_GUEST | ||
1025 | - if (x86_hyper) { | ||
1026 | + if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) { | ||
1027 | return sprintf(buf, "%s; SMT Host state unknown\n", | ||
1028 | mds_strings[mds_mitigation]); | ||
1029 | } | ||
1030 | diff --git a/arch/x86/kernel/cpu/mkcapflags.sh b/arch/x86/kernel/cpu/mkcapflags.sh | ||
1031 | index 6988c74409a8..711b74e0e623 100644 | ||
1032 | --- a/arch/x86/kernel/cpu/mkcapflags.sh | ||
1033 | +++ b/arch/x86/kernel/cpu/mkcapflags.sh | ||
1034 | @@ -3,6 +3,8 @@ | ||
1035 | # Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h | ||
1036 | # | ||
1037 | |||
1038 | +set -e | ||
1039 | + | ||
1040 | IN=$1 | ||
1041 | OUT=$2 | ||
1042 | |||
1043 | diff --git a/arch/x86/kernel/sysfb_efi.c b/arch/x86/kernel/sysfb_efi.c | ||
1044 | index 623965e86b65..897da526e40e 100644 | ||
1045 | --- a/arch/x86/kernel/sysfb_efi.c | ||
1046 | +++ b/arch/x86/kernel/sysfb_efi.c | ||
1047 | @@ -231,9 +231,55 @@ static const struct dmi_system_id efifb_dmi_system_table[] __initconst = { | ||
1048 | {}, | ||
1049 | }; | ||
1050 | |||
1051 | +/* | ||
1052 | + * Some devices have a portrait LCD but advertise a landscape resolution (and | ||
1053 | + * pitch). We simply swap width and height for these devices so that we can | ||
1054 | + * correctly deal with some of them coming with multiple resolutions. | ||
1055 | + */ | ||
1056 | +static const struct dmi_system_id efifb_dmi_swap_width_height[] __initconst = { | ||
1057 | + { | ||
1058 | + /* | ||
1059 | + * Lenovo MIIX310-10ICR, only some batches have the troublesome | ||
1060 | + * 800x1280 portrait screen. Luckily the portrait version has | ||
1061 | + * its own BIOS version, so we match on that. | ||
1062 | + */ | ||
1063 | + .matches = { | ||
1064 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"), | ||
1065 | + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "MIIX 310-10ICR"), | ||
1066 | + DMI_EXACT_MATCH(DMI_BIOS_VERSION, "1HCN44WW"), | ||
1067 | + }, | ||
1068 | + }, | ||
1069 | + { | ||
1070 | + /* Lenovo MIIX 320-10ICR with 800x1280 portrait screen */ | ||
1071 | + .matches = { | ||
1072 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"), | ||
1073 | + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, | ||
1074 | + "Lenovo MIIX 320-10ICR"), | ||
1075 | + }, | ||
1076 | + }, | ||
1077 | + { | ||
1078 | + /* Lenovo D330 with 800x1280 or 1200x1920 portrait screen */ | ||
1079 | + .matches = { | ||
1080 | + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"), | ||
1081 | + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, | ||
1082 | + "Lenovo ideapad D330-10IGM"), | ||
1083 | + }, | ||
1084 | + }, | ||
1085 | + {}, | ||
1086 | +}; | ||
1087 | + | ||
1088 | __init void sysfb_apply_efi_quirks(void) | ||
1089 | { | ||
1090 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || | ||
1091 | !(screen_info.capabilities & VIDEO_CAPABILITY_SKIP_QUIRKS)) | ||
1092 | dmi_check_system(efifb_dmi_system_table); | ||
1093 | + | ||
1094 | + if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI && | ||
1095 | + dmi_check_system(efifb_dmi_swap_width_height)) { | ||
1096 | + u16 temp = screen_info.lfb_width; | ||
1097 | + | ||
1098 | + screen_info.lfb_width = screen_info.lfb_height; | ||
1099 | + screen_info.lfb_height = temp; | ||
1100 | + screen_info.lfb_linelength = 4 * screen_info.lfb_width; | ||
1101 | + } | ||
1102 | } | ||
1103 | diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c | ||
1104 | index 06ce377dcbc9..0827ee7d0e9b 100644 | ||
1105 | --- a/arch/x86/kvm/pmu.c | ||
1106 | +++ b/arch/x86/kvm/pmu.c | ||
1107 | @@ -124,8 +124,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type, | ||
1108 | intr ? kvm_perf_overflow_intr : | ||
1109 | kvm_perf_overflow, pmc); | ||
1110 | if (IS_ERR(event)) { | ||
1111 | - printk_once("kvm_pmu: event creation failed %ld\n", | ||
1112 | - PTR_ERR(event)); | ||
1113 | + pr_debug_ratelimited("kvm_pmu: event creation failed %ld for pmc->idx = %d\n", | ||
1114 | + PTR_ERR(event), pmc->idx); | ||
1115 | return; | ||
1116 | } | ||
1117 | |||
1118 | diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c | ||
1119 | index 00f54a91bb4b..3c423dfcd78b 100644 | ||
1120 | --- a/arch/x86/um/os-Linux/registers.c | ||
1121 | +++ b/arch/x86/um/os-Linux/registers.c | ||
1122 | @@ -5,6 +5,7 @@ | ||
1123 | */ | ||
1124 | |||
1125 | #include <errno.h> | ||
1126 | +#include <stdlib.h> | ||
1127 | #include <sys/ptrace.h> | ||
1128 | #ifdef __i386__ | ||
1129 | #include <sys/user.h> | ||
1130 | @@ -26,17 +27,18 @@ int save_i387_registers(int pid, unsigned long *fp_regs) | ||
1131 | |||
1132 | int save_fp_registers(int pid, unsigned long *fp_regs) | ||
1133 | { | ||
1134 | +#ifdef PTRACE_GETREGSET | ||
1135 | struct iovec iov; | ||
1136 | |||
1137 | if (have_xstate_support) { | ||
1138 | iov.iov_base = fp_regs; | ||
1139 | - iov.iov_len = sizeof(struct _xstate); | ||
1140 | + iov.iov_len = FP_SIZE * sizeof(unsigned long); | ||
1141 | if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0) | ||
1142 | return -errno; | ||
1143 | return 0; | ||
1144 | - } else { | ||
1145 | + } else | ||
1146 | +#endif | ||
1147 | return save_i387_registers(pid, fp_regs); | ||
1148 | - } | ||
1149 | } | ||
1150 | |||
1151 | int restore_i387_registers(int pid, unsigned long *fp_regs) | ||
1152 | @@ -48,17 +50,17 @@ int restore_i387_registers(int pid, unsigned long *fp_regs) | ||
1153 | |||
1154 | int restore_fp_registers(int pid, unsigned long *fp_regs) | ||
1155 | { | ||
1156 | +#ifdef PTRACE_SETREGSET | ||
1157 | struct iovec iov; | ||
1158 | - | ||
1159 | if (have_xstate_support) { | ||
1160 | iov.iov_base = fp_regs; | ||
1161 | - iov.iov_len = sizeof(struct _xstate); | ||
1162 | + iov.iov_len = FP_SIZE * sizeof(unsigned long); | ||
1163 | if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0) | ||
1164 | return -errno; | ||
1165 | return 0; | ||
1166 | - } else { | ||
1167 | + } else | ||
1168 | +#endif | ||
1169 | return restore_i387_registers(pid, fp_regs); | ||
1170 | - } | ||
1171 | } | ||
1172 | |||
1173 | #ifdef __i386__ | ||
1174 | @@ -122,13 +124,21 @@ int put_fp_registers(int pid, unsigned long *regs) | ||
1175 | |||
1176 | void arch_init_registers(int pid) | ||
1177 | { | ||
1178 | - struct _xstate fp_regs; | ||
1179 | +#ifdef PTRACE_GETREGSET | ||
1180 | + void * fp_regs; | ||
1181 | struct iovec iov; | ||
1182 | |||
1183 | - iov.iov_base = &fp_regs; | ||
1184 | - iov.iov_len = sizeof(struct _xstate); | ||
1185 | + fp_regs = malloc(FP_SIZE * sizeof(unsigned long)); | ||
1186 | + if(fp_regs == NULL) | ||
1187 | + return; | ||
1188 | + | ||
1189 | + iov.iov_base = fp_regs; | ||
1190 | + iov.iov_len = FP_SIZE * sizeof(unsigned long); | ||
1191 | if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0) | ||
1192 | have_xstate_support = 1; | ||
1193 | + | ||
1194 | + free(fp_regs); | ||
1195 | +#endif | ||
1196 | } | ||
1197 | #endif | ||
1198 | |||
1199 | diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c | ||
1200 | index cb3c22370cf5..7bcd10614f8b 100644 | ||
1201 | --- a/arch/x86/um/user-offsets.c | ||
1202 | +++ b/arch/x86/um/user-offsets.c | ||
1203 | @@ -50,7 +50,11 @@ void foo(void) | ||
1204 | DEFINE(HOST_GS, GS); | ||
1205 | DEFINE(HOST_ORIG_AX, ORIG_EAX); | ||
1206 | #else | ||
1207 | - DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long)); | ||
1208 | +#ifdef FP_XSTATE_MAGIC1 | ||
1209 | + DEFINE_LONGS(HOST_FP_SIZE, 2696); | ||
1210 | +#else | ||
1211 | + DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long)); | ||
1212 | +#endif | ||
1213 | DEFINE_LONGS(HOST_BX, RBX); | ||
1214 | DEFINE_LONGS(HOST_CX, RCX); | ||
1215 | DEFINE_LONGS(HOST_DI, RDI); | ||
1216 | diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c | ||
1217 | index 556826ac7cb4..3c9fdd6983aa 100644 | ||
1218 | --- a/block/compat_ioctl.c | ||
1219 | +++ b/block/compat_ioctl.c | ||
1220 | @@ -4,7 +4,6 @@ | ||
1221 | #include <linux/cdrom.h> | ||
1222 | #include <linux/compat.h> | ||
1223 | #include <linux/elevator.h> | ||
1224 | -#include <linux/fd.h> | ||
1225 | #include <linux/hdreg.h> | ||
1226 | #include <linux/slab.h> | ||
1227 | #include <linux/syscalls.h> | ||
1228 | @@ -209,318 +208,6 @@ static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, | ||
1229 | #define BLKBSZSET_32 _IOW(0x12, 113, int) | ||
1230 | #define BLKGETSIZE64_32 _IOR(0x12, 114, int) | ||
1231 | |||
1232 | -struct compat_floppy_drive_params { | ||
1233 | - char cmos; | ||
1234 | - compat_ulong_t max_dtr; | ||
1235 | - compat_ulong_t hlt; | ||
1236 | - compat_ulong_t hut; | ||
1237 | - compat_ulong_t srt; | ||
1238 | - compat_ulong_t spinup; | ||
1239 | - compat_ulong_t spindown; | ||
1240 | - unsigned char spindown_offset; | ||
1241 | - unsigned char select_delay; | ||
1242 | - unsigned char rps; | ||
1243 | - unsigned char tracks; | ||
1244 | - compat_ulong_t timeout; | ||
1245 | - unsigned char interleave_sect; | ||
1246 | - struct floppy_max_errors max_errors; | ||
1247 | - char flags; | ||
1248 | - char read_track; | ||
1249 | - short autodetect[8]; | ||
1250 | - compat_int_t checkfreq; | ||
1251 | - compat_int_t native_format; | ||
1252 | -}; | ||
1253 | - | ||
1254 | -struct compat_floppy_drive_struct { | ||
1255 | - signed char flags; | ||
1256 | - compat_ulong_t spinup_date; | ||
1257 | - compat_ulong_t select_date; | ||
1258 | - compat_ulong_t first_read_date; | ||
1259 | - short probed_format; | ||
1260 | - short track; | ||
1261 | - short maxblock; | ||
1262 | - short maxtrack; | ||
1263 | - compat_int_t generation; | ||
1264 | - compat_int_t keep_data; | ||
1265 | - compat_int_t fd_ref; | ||
1266 | - compat_int_t fd_device; | ||
1267 | - compat_int_t last_checked; | ||
1268 | - compat_caddr_t dmabuf; | ||
1269 | - compat_int_t bufblocks; | ||
1270 | -}; | ||
1271 | - | ||
1272 | -struct compat_floppy_fdc_state { | ||
1273 | - compat_int_t spec1; | ||
1274 | - compat_int_t spec2; | ||
1275 | - compat_int_t dtr; | ||
1276 | - unsigned char version; | ||
1277 | - unsigned char dor; | ||
1278 | - compat_ulong_t address; | ||
1279 | - unsigned int rawcmd:2; | ||
1280 | - unsigned int reset:1; | ||
1281 | - unsigned int need_configure:1; | ||
1282 | - unsigned int perp_mode:2; | ||
1283 | - unsigned int has_fifo:1; | ||
1284 | - unsigned int driver_version; | ||
1285 | - unsigned char track[4]; | ||
1286 | -}; | ||
1287 | - | ||
1288 | -struct compat_floppy_write_errors { | ||
1289 | - unsigned int write_errors; | ||
1290 | - compat_ulong_t first_error_sector; | ||
1291 | - compat_int_t first_error_generation; | ||
1292 | - compat_ulong_t last_error_sector; | ||
1293 | - compat_int_t last_error_generation; | ||
1294 | - compat_uint_t badness; | ||
1295 | -}; | ||
1296 | - | ||
1297 | -#define FDSETPRM32 _IOW(2, 0x42, struct compat_floppy_struct) | ||
1298 | -#define FDDEFPRM32 _IOW(2, 0x43, struct compat_floppy_struct) | ||
1299 | -#define FDSETDRVPRM32 _IOW(2, 0x90, struct compat_floppy_drive_params) | ||
1300 | -#define FDGETDRVPRM32 _IOR(2, 0x11, struct compat_floppy_drive_params) | ||
1301 | -#define FDGETDRVSTAT32 _IOR(2, 0x12, struct compat_floppy_drive_struct) | ||
1302 | -#define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct compat_floppy_drive_struct) | ||
1303 | -#define FDGETFDCSTAT32 _IOR(2, 0x15, struct compat_floppy_fdc_state) | ||
1304 | -#define FDWERRORGET32 _IOR(2, 0x17, struct compat_floppy_write_errors) | ||
1305 | - | ||
1306 | -static struct { | ||
1307 | - unsigned int cmd32; | ||
1308 | - unsigned int cmd; | ||
1309 | -} fd_ioctl_trans_table[] = { | ||
1310 | - { FDSETPRM32, FDSETPRM }, | ||
1311 | - { FDDEFPRM32, FDDEFPRM }, | ||
1312 | - { FDGETPRM32, FDGETPRM }, | ||
1313 | - { FDSETDRVPRM32, FDSETDRVPRM }, | ||
1314 | - { FDGETDRVPRM32, FDGETDRVPRM }, | ||
1315 | - { FDGETDRVSTAT32, FDGETDRVSTAT }, | ||
1316 | - { FDPOLLDRVSTAT32, FDPOLLDRVSTAT }, | ||
1317 | - { FDGETFDCSTAT32, FDGETFDCSTAT }, | ||
1318 | - { FDWERRORGET32, FDWERRORGET } | ||
1319 | -}; | ||
1320 | - | ||
1321 | -#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table) | ||
1322 | - | ||
1323 | -static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode, | ||
1324 | - unsigned int cmd, unsigned long arg) | ||
1325 | -{ | ||
1326 | - mm_segment_t old_fs = get_fs(); | ||
1327 | - void *karg = NULL; | ||
1328 | - unsigned int kcmd = 0; | ||
1329 | - int i, err; | ||
1330 | - | ||
1331 | - for (i = 0; i < NR_FD_IOCTL_TRANS; i++) | ||
1332 | - if (cmd == fd_ioctl_trans_table[i].cmd32) { | ||
1333 | - kcmd = fd_ioctl_trans_table[i].cmd; | ||
1334 | - break; | ||
1335 | - } | ||
1336 | - if (!kcmd) | ||
1337 | - return -EINVAL; | ||
1338 | - | ||
1339 | - switch (cmd) { | ||
1340 | - case FDSETPRM32: | ||
1341 | - case FDDEFPRM32: | ||
1342 | - case FDGETPRM32: | ||
1343 | - { | ||
1344 | - compat_uptr_t name; | ||
1345 | - struct compat_floppy_struct __user *uf; | ||
1346 | - struct floppy_struct *f; | ||
1347 | - | ||
1348 | - uf = compat_ptr(arg); | ||
1349 | - f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL); | ||
1350 | - if (!karg) | ||
1351 | - return -ENOMEM; | ||
1352 | - if (cmd == FDGETPRM32) | ||
1353 | - break; | ||
1354 | - err = __get_user(f->size, &uf->size); | ||
1355 | - err |= __get_user(f->sect, &uf->sect); | ||
1356 | - err |= __get_user(f->head, &uf->head); | ||
1357 | - err |= __get_user(f->track, &uf->track); | ||
1358 | - err |= __get_user(f->stretch, &uf->stretch); | ||
1359 | - err |= __get_user(f->gap, &uf->gap); | ||
1360 | - err |= __get_user(f->rate, &uf->rate); | ||
1361 | - err |= __get_user(f->spec1, &uf->spec1); | ||
1362 | - err |= __get_user(f->fmt_gap, &uf->fmt_gap); | ||
1363 | - err |= __get_user(name, &uf->name); | ||
1364 | - f->name = compat_ptr(name); | ||
1365 | - if (err) { | ||
1366 | - err = -EFAULT; | ||
1367 | - goto out; | ||
1368 | - } | ||
1369 | - break; | ||
1370 | - } | ||
1371 | - case FDSETDRVPRM32: | ||
1372 | - case FDGETDRVPRM32: | ||
1373 | - { | ||
1374 | - struct compat_floppy_drive_params __user *uf; | ||
1375 | - struct floppy_drive_params *f; | ||
1376 | - | ||
1377 | - uf = compat_ptr(arg); | ||
1378 | - f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL); | ||
1379 | - if (!karg) | ||
1380 | - return -ENOMEM; | ||
1381 | - if (cmd == FDGETDRVPRM32) | ||
1382 | - break; | ||
1383 | - err = __get_user(f->cmos, &uf->cmos); | ||
1384 | - err |= __get_user(f->max_dtr, &uf->max_dtr); | ||
1385 | - err |= __get_user(f->hlt, &uf->hlt); | ||
1386 | - err |= __get_user(f->hut, &uf->hut); | ||
1387 | - err |= __get_user(f->srt, &uf->srt); | ||
1388 | - err |= __get_user(f->spinup, &uf->spinup); | ||
1389 | - err |= __get_user(f->spindown, &uf->spindown); | ||
1390 | - err |= __get_user(f->spindown_offset, &uf->spindown_offset); | ||
1391 | - err |= __get_user(f->select_delay, &uf->select_delay); | ||
1392 | - err |= __get_user(f->rps, &uf->rps); | ||
1393 | - err |= __get_user(f->tracks, &uf->tracks); | ||
1394 | - err |= __get_user(f->timeout, &uf->timeout); | ||
1395 | - err |= __get_user(f->interleave_sect, &uf->interleave_sect); | ||
1396 | - err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors)); | ||
1397 | - err |= __get_user(f->flags, &uf->flags); | ||
1398 | - err |= __get_user(f->read_track, &uf->read_track); | ||
1399 | - err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect)); | ||
1400 | - err |= __get_user(f->checkfreq, &uf->checkfreq); | ||
1401 | - err |= __get_user(f->native_format, &uf->native_format); | ||
1402 | - if (err) { | ||
1403 | - err = -EFAULT; | ||
1404 | - goto out; | ||
1405 | - } | ||
1406 | - break; | ||
1407 | - } | ||
1408 | - case FDGETDRVSTAT32: | ||
1409 | - case FDPOLLDRVSTAT32: | ||
1410 | - karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL); | ||
1411 | - if (!karg) | ||
1412 | - return -ENOMEM; | ||
1413 | - break; | ||
1414 | - case FDGETFDCSTAT32: | ||
1415 | - karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL); | ||
1416 | - if (!karg) | ||
1417 | - return -ENOMEM; | ||
1418 | - break; | ||
1419 | - case FDWERRORGET32: | ||
1420 | - karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL); | ||
1421 | - if (!karg) | ||
1422 | - return -ENOMEM; | ||
1423 | - break; | ||
1424 | - default: | ||
1425 | - return -EINVAL; | ||
1426 | - } | ||
1427 | - set_fs(KERNEL_DS); | ||
1428 | - err = __blkdev_driver_ioctl(bdev, mode, kcmd, (unsigned long)karg); | ||
1429 | - set_fs(old_fs); | ||
1430 | - if (err) | ||
1431 | - goto out; | ||
1432 | - switch (cmd) { | ||
1433 | - case FDGETPRM32: | ||
1434 | - { | ||
1435 | - struct floppy_struct *f = karg; | ||
1436 | - struct compat_floppy_struct __user *uf = compat_ptr(arg); | ||
1437 | - | ||
1438 | - err = __put_user(f->size, &uf->size); | ||
1439 | - err |= __put_user(f->sect, &uf->sect); | ||
1440 | - err |= __put_user(f->head, &uf->head); | ||
1441 | - err |= __put_user(f->track, &uf->track); | ||
1442 | - err |= __put_user(f->stretch, &uf->stretch); | ||
1443 | - err |= __put_user(f->gap, &uf->gap); | ||
1444 | - err |= __put_user(f->rate, &uf->rate); | ||
1445 | - err |= __put_user(f->spec1, &uf->spec1); | ||
1446 | - err |= __put_user(f->fmt_gap, &uf->fmt_gap); | ||
1447 | - err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name); | ||
1448 | - break; | ||
1449 | - } | ||
1450 | - case FDGETDRVPRM32: | ||
1451 | - { | ||
1452 | - struct compat_floppy_drive_params __user *uf; | ||
1453 | - struct floppy_drive_params *f = karg; | ||
1454 | - | ||
1455 | - uf = compat_ptr(arg); | ||
1456 | - err = __put_user(f->cmos, &uf->cmos); | ||
1457 | - err |= __put_user(f->max_dtr, &uf->max_dtr); | ||
1458 | - err |= __put_user(f->hlt, &uf->hlt); | ||
1459 | - err |= __put_user(f->hut, &uf->hut); | ||
1460 | - err |= __put_user(f->srt, &uf->srt); | ||
1461 | - err |= __put_user(f->spinup, &uf->spinup); | ||
1462 | - err |= __put_user(f->spindown, &uf->spindown); | ||
1463 | - err |= __put_user(f->spindown_offset, &uf->spindown_offset); | ||
1464 | - err |= __put_user(f->select_delay, &uf->select_delay); | ||
1465 | - err |= __put_user(f->rps, &uf->rps); | ||
1466 | - err |= __put_user(f->tracks, &uf->tracks); | ||
1467 | - err |= __put_user(f->timeout, &uf->timeout); | ||
1468 | - err |= __put_user(f->interleave_sect, &uf->interleave_sect); | ||
1469 | - err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors)); | ||
1470 | - err |= __put_user(f->flags, &uf->flags); | ||
1471 | - err |= __put_user(f->read_track, &uf->read_track); | ||
1472 | - err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect)); | ||
1473 | - err |= __put_user(f->checkfreq, &uf->checkfreq); | ||
1474 | - err |= __put_user(f->native_format, &uf->native_format); | ||
1475 | - break; | ||
1476 | - } | ||
1477 | - case FDGETDRVSTAT32: | ||
1478 | - case FDPOLLDRVSTAT32: | ||
1479 | - { | ||
1480 | - struct compat_floppy_drive_struct __user *uf; | ||
1481 | - struct floppy_drive_struct *f = karg; | ||
1482 | - | ||
1483 | - uf = compat_ptr(arg); | ||
1484 | - err = __put_user(f->flags, &uf->flags); | ||
1485 | - err |= __put_user(f->spinup_date, &uf->spinup_date); | ||
1486 | - err |= __put_user(f->select_date, &uf->select_date); | ||
1487 | - err |= __put_user(f->first_read_date, &uf->first_read_date); | ||
1488 | - err |= __put_user(f->probed_format, &uf->probed_format); | ||
1489 | - err |= __put_user(f->track, &uf->track); | ||
1490 | - err |= __put_user(f->maxblock, &uf->maxblock); | ||
1491 | - err |= __put_user(f->maxtrack, &uf->maxtrack); | ||
1492 | - err |= __put_user(f->generation, &uf->generation); | ||
1493 | - err |= __put_user(f->keep_data, &uf->keep_data); | ||
1494 | - err |= __put_user(f->fd_ref, &uf->fd_ref); | ||
1495 | - err |= __put_user(f->fd_device, &uf->fd_device); | ||
1496 | - err |= __put_user(f->last_checked, &uf->last_checked); | ||
1497 | - err |= __put_user((u64)f->dmabuf, &uf->dmabuf); | ||
1498 | - err |= __put_user((u64)f->bufblocks, &uf->bufblocks); | ||
1499 | - break; | ||
1500 | - } | ||
1501 | - case FDGETFDCSTAT32: | ||
1502 | - { | ||
1503 | - struct compat_floppy_fdc_state __user *uf; | ||
1504 | - struct floppy_fdc_state *f = karg; | ||
1505 | - | ||
1506 | - uf = compat_ptr(arg); | ||
1507 | - err = __put_user(f->spec1, &uf->spec1); | ||
1508 | - err |= __put_user(f->spec2, &uf->spec2); | ||
1509 | - err |= __put_user(f->dtr, &uf->dtr); | ||
1510 | - err |= __put_user(f->version, &uf->version); | ||
1511 | - err |= __put_user(f->dor, &uf->dor); | ||
1512 | - err |= __put_user(f->address, &uf->address); | ||
1513 | - err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address), | ||
1514 | - (char *)&f->address + sizeof(f->address), sizeof(int)); | ||
1515 | - err |= __put_user(f->driver_version, &uf->driver_version); | ||
1516 | - err |= __copy_to_user(uf->track, f->track, sizeof(f->track)); | ||
1517 | - break; | ||
1518 | - } | ||
1519 | - case FDWERRORGET32: | ||
1520 | - { | ||
1521 | - struct compat_floppy_write_errors __user *uf; | ||
1522 | - struct floppy_write_errors *f = karg; | ||
1523 | - | ||
1524 | - uf = compat_ptr(arg); | ||
1525 | - err = __put_user(f->write_errors, &uf->write_errors); | ||
1526 | - err |= __put_user(f->first_error_sector, &uf->first_error_sector); | ||
1527 | - err |= __put_user(f->first_error_generation, &uf->first_error_generation); | ||
1528 | - err |= __put_user(f->last_error_sector, &uf->last_error_sector); | ||
1529 | - err |= __put_user(f->last_error_generation, &uf->last_error_generation); | ||
1530 | - err |= __put_user(f->badness, &uf->badness); | ||
1531 | - break; | ||
1532 | - } | ||
1533 | - default: | ||
1534 | - break; | ||
1535 | - } | ||
1536 | - if (err) | ||
1537 | - err = -EFAULT; | ||
1538 | - | ||
1539 | -out: | ||
1540 | - kfree(karg); | ||
1541 | - return err; | ||
1542 | -} | ||
1543 | - | ||
1544 | static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, | ||
1545 | unsigned cmd, unsigned long arg) | ||
1546 | { | ||
1547 | @@ -537,16 +224,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, | ||
1548 | case HDIO_GET_ADDRESS: | ||
1549 | case HDIO_GET_BUSSTATE: | ||
1550 | return compat_hdio_ioctl(bdev, mode, cmd, arg); | ||
1551 | - case FDSETPRM32: | ||
1552 | - case FDDEFPRM32: | ||
1553 | - case FDGETPRM32: | ||
1554 | - case FDSETDRVPRM32: | ||
1555 | - case FDGETDRVPRM32: | ||
1556 | - case FDGETDRVSTAT32: | ||
1557 | - case FDPOLLDRVSTAT32: | ||
1558 | - case FDGETFDCSTAT32: | ||
1559 | - case FDWERRORGET32: | ||
1560 | - return compat_fd_ioctl(bdev, mode, cmd, arg); | ||
1561 | case CDROMREADAUDIO: | ||
1562 | return compat_cdrom_read_audio(bdev, mode, cmd, arg); | ||
1563 | case CDROM_SEND_PACKET: | ||
1564 | @@ -566,23 +243,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, | ||
1565 | case HDIO_DRIVE_CMD: | ||
1566 | /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */ | ||
1567 | case 0x330: | ||
1568 | - /* 0x02 -- Floppy ioctls */ | ||
1569 | - case FDMSGON: | ||
1570 | - case FDMSGOFF: | ||
1571 | - case FDSETEMSGTRESH: | ||
1572 | - case FDFLUSH: | ||
1573 | - case FDWERRORCLR: | ||
1574 | - case FDSETMAXERRS: | ||
1575 | - case FDGETMAXERRS: | ||
1576 | - case FDGETDRVTYP: | ||
1577 | - case FDEJECT: | ||
1578 | - case FDCLRPRM: | ||
1579 | - case FDFMTBEG: | ||
1580 | - case FDFMTEND: | ||
1581 | - case FDRESET: | ||
1582 | - case FDTWADDLE: | ||
1583 | - case FDFMTTRK: | ||
1584 | - case FDRAWCMD: | ||
1585 | /* CDROM stuff */ | ||
1586 | case CDROMPAUSE: | ||
1587 | case CDROMRESUME: | ||
1588 | diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig | ||
1589 | index 331f6baf2df8..13f3de68b479 100644 | ||
1590 | --- a/crypto/asymmetric_keys/Kconfig | ||
1591 | +++ b/crypto/asymmetric_keys/Kconfig | ||
1592 | @@ -14,6 +14,7 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE | ||
1593 | select MPILIB | ||
1594 | select CRYPTO_HASH_INFO | ||
1595 | select CRYPTO_AKCIPHER | ||
1596 | + select CRYPTO_HASH | ||
1597 | help | ||
1598 | This option provides support for asymmetric public key type handling. | ||
1599 | If signature generation and/or verification are to be used, | ||
1600 | @@ -33,6 +34,7 @@ config X509_CERTIFICATE_PARSER | ||
1601 | config PKCS7_MESSAGE_PARSER | ||
1602 | tristate "PKCS#7 message parser" | ||
1603 | depends on X509_CERTIFICATE_PARSER | ||
1604 | + select CRYPTO_HASH | ||
1605 | select ASN1 | ||
1606 | select OID_REGISTRY | ||
1607 | help | ||
1608 | @@ -55,6 +57,7 @@ config SIGNED_PE_FILE_VERIFICATION | ||
1609 | bool "Support for PE file signature verification" | ||
1610 | depends on PKCS7_MESSAGE_PARSER=y | ||
1611 | depends on SYSTEM_DATA_VERIFICATION | ||
1612 | + select CRYPTO_HASH | ||
1613 | select ASN1 | ||
1614 | select OID_REGISTRY | ||
1615 | help | ||
1616 | diff --git a/crypto/chacha20poly1305.c b/crypto/chacha20poly1305.c | ||
1617 | index 246905bf00aa..96d842a13ffc 100644 | ||
1618 | --- a/crypto/chacha20poly1305.c | ||
1619 | +++ b/crypto/chacha20poly1305.c | ||
1620 | @@ -67,6 +67,8 @@ struct chachapoly_req_ctx { | ||
1621 | unsigned int cryptlen; | ||
1622 | /* Actual AD, excluding IV */ | ||
1623 | unsigned int assoclen; | ||
1624 | + /* request flags, with MAY_SLEEP cleared if needed */ | ||
1625 | + u32 flags; | ||
1626 | union { | ||
1627 | struct poly_req poly; | ||
1628 | struct chacha_req chacha; | ||
1629 | @@ -76,8 +78,12 @@ struct chachapoly_req_ctx { | ||
1630 | static inline void async_done_continue(struct aead_request *req, int err, | ||
1631 | int (*cont)(struct aead_request *)) | ||
1632 | { | ||
1633 | - if (!err) | ||
1634 | + if (!err) { | ||
1635 | + struct chachapoly_req_ctx *rctx = aead_request_ctx(req); | ||
1636 | + | ||
1637 | + rctx->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP; | ||
1638 | err = cont(req); | ||
1639 | + } | ||
1640 | |||
1641 | if (err != -EINPROGRESS && err != -EBUSY) | ||
1642 | aead_request_complete(req, err); | ||
1643 | @@ -144,7 +150,7 @@ static int chacha_decrypt(struct aead_request *req) | ||
1644 | dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen); | ||
1645 | } | ||
1646 | |||
1647 | - skcipher_request_set_callback(&creq->req, aead_request_flags(req), | ||
1648 | + skcipher_request_set_callback(&creq->req, rctx->flags, | ||
1649 | chacha_decrypt_done, req); | ||
1650 | skcipher_request_set_tfm(&creq->req, ctx->chacha); | ||
1651 | skcipher_request_set_crypt(&creq->req, src, dst, | ||
1652 | @@ -188,7 +194,7 @@ static int poly_tail(struct aead_request *req) | ||
1653 | memcpy(&preq->tail.cryptlen, &len, sizeof(len)); | ||
1654 | sg_set_buf(preq->src, &preq->tail, sizeof(preq->tail)); | ||
1655 | |||
1656 | - ahash_request_set_callback(&preq->req, aead_request_flags(req), | ||
1657 | + ahash_request_set_callback(&preq->req, rctx->flags, | ||
1658 | poly_tail_done, req); | ||
1659 | ahash_request_set_tfm(&preq->req, ctx->poly); | ||
1660 | ahash_request_set_crypt(&preq->req, preq->src, | ||
1661 | @@ -219,7 +225,7 @@ static int poly_cipherpad(struct aead_request *req) | ||
1662 | sg_init_table(preq->src, 1); | ||
1663 | sg_set_buf(preq->src, &preq->pad, padlen); | ||
1664 | |||
1665 | - ahash_request_set_callback(&preq->req, aead_request_flags(req), | ||
1666 | + ahash_request_set_callback(&preq->req, rctx->flags, | ||
1667 | poly_cipherpad_done, req); | ||
1668 | ahash_request_set_tfm(&preq->req, ctx->poly); | ||
1669 | ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen); | ||
1670 | @@ -250,7 +256,7 @@ static int poly_cipher(struct aead_request *req) | ||
1671 | sg_init_table(rctx->src, 2); | ||
1672 | crypt = scatterwalk_ffwd(rctx->src, crypt, req->assoclen); | ||
1673 | |||
1674 | - ahash_request_set_callback(&preq->req, aead_request_flags(req), | ||
1675 | + ahash_request_set_callback(&preq->req, rctx->flags, | ||
1676 | poly_cipher_done, req); | ||
1677 | ahash_request_set_tfm(&preq->req, ctx->poly); | ||
1678 | ahash_request_set_crypt(&preq->req, crypt, NULL, rctx->cryptlen); | ||
1679 | @@ -280,7 +286,7 @@ static int poly_adpad(struct aead_request *req) | ||
1680 | sg_init_table(preq->src, 1); | ||
1681 | sg_set_buf(preq->src, preq->pad, padlen); | ||
1682 | |||
1683 | - ahash_request_set_callback(&preq->req, aead_request_flags(req), | ||
1684 | + ahash_request_set_callback(&preq->req, rctx->flags, | ||
1685 | poly_adpad_done, req); | ||
1686 | ahash_request_set_tfm(&preq->req, ctx->poly); | ||
1687 | ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen); | ||
1688 | @@ -304,7 +310,7 @@ static int poly_ad(struct aead_request *req) | ||
1689 | struct poly_req *preq = &rctx->u.poly; | ||
1690 | int err; | ||
1691 | |||
1692 | - ahash_request_set_callback(&preq->req, aead_request_flags(req), | ||
1693 | + ahash_request_set_callback(&preq->req, rctx->flags, | ||
1694 | poly_ad_done, req); | ||
1695 | ahash_request_set_tfm(&preq->req, ctx->poly); | ||
1696 | ahash_request_set_crypt(&preq->req, req->src, NULL, rctx->assoclen); | ||
1697 | @@ -331,7 +337,7 @@ static int poly_setkey(struct aead_request *req) | ||
1698 | sg_init_table(preq->src, 1); | ||
1699 | sg_set_buf(preq->src, rctx->key, sizeof(rctx->key)); | ||
1700 | |||
1701 | - ahash_request_set_callback(&preq->req, aead_request_flags(req), | ||
1702 | + ahash_request_set_callback(&preq->req, rctx->flags, | ||
1703 | poly_setkey_done, req); | ||
1704 | ahash_request_set_tfm(&preq->req, ctx->poly); | ||
1705 | ahash_request_set_crypt(&preq->req, preq->src, NULL, sizeof(rctx->key)); | ||
1706 | @@ -355,7 +361,7 @@ static int poly_init(struct aead_request *req) | ||
1707 | struct poly_req *preq = &rctx->u.poly; | ||
1708 | int err; | ||
1709 | |||
1710 | - ahash_request_set_callback(&preq->req, aead_request_flags(req), | ||
1711 | + ahash_request_set_callback(&preq->req, rctx->flags, | ||
1712 | poly_init_done, req); | ||
1713 | ahash_request_set_tfm(&preq->req, ctx->poly); | ||
1714 | |||
1715 | @@ -393,7 +399,7 @@ static int poly_genkey(struct aead_request *req) | ||
1716 | |||
1717 | chacha_iv(creq->iv, req, 0); | ||
1718 | |||
1719 | - skcipher_request_set_callback(&creq->req, aead_request_flags(req), | ||
1720 | + skcipher_request_set_callback(&creq->req, rctx->flags, | ||
1721 | poly_genkey_done, req); | ||
1722 | skcipher_request_set_tfm(&creq->req, ctx->chacha); | ||
1723 | skcipher_request_set_crypt(&creq->req, creq->src, creq->src, | ||
1724 | @@ -433,7 +439,7 @@ static int chacha_encrypt(struct aead_request *req) | ||
1725 | dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen); | ||
1726 | } | ||
1727 | |||
1728 | - skcipher_request_set_callback(&creq->req, aead_request_flags(req), | ||
1729 | + skcipher_request_set_callback(&creq->req, rctx->flags, | ||
1730 | chacha_encrypt_done, req); | ||
1731 | skcipher_request_set_tfm(&creq->req, ctx->chacha); | ||
1732 | skcipher_request_set_crypt(&creq->req, src, dst, | ||
1733 | @@ -451,6 +457,7 @@ static int chachapoly_encrypt(struct aead_request *req) | ||
1734 | struct chachapoly_req_ctx *rctx = aead_request_ctx(req); | ||
1735 | |||
1736 | rctx->cryptlen = req->cryptlen; | ||
1737 | + rctx->flags = aead_request_flags(req); | ||
1738 | |||
1739 | /* encrypt call chain: | ||
1740 | * - chacha_encrypt/done() | ||
1741 | @@ -472,6 +479,7 @@ static int chachapoly_decrypt(struct aead_request *req) | ||
1742 | struct chachapoly_req_ctx *rctx = aead_request_ctx(req); | ||
1743 | |||
1744 | rctx->cryptlen = req->cryptlen - POLY1305_DIGEST_SIZE; | ||
1745 | + rctx->flags = aead_request_flags(req); | ||
1746 | |||
1747 | /* decrypt call chain: | ||
1748 | * - poly_genkey/done() | ||
1749 | diff --git a/crypto/ghash-generic.c b/crypto/ghash-generic.c | ||
1750 | index 12ad3e3a84e3..73b56f2f44f1 100644 | ||
1751 | --- a/crypto/ghash-generic.c | ||
1752 | +++ b/crypto/ghash-generic.c | ||
1753 | @@ -34,6 +34,7 @@ static int ghash_setkey(struct crypto_shash *tfm, | ||
1754 | const u8 *key, unsigned int keylen) | ||
1755 | { | ||
1756 | struct ghash_ctx *ctx = crypto_shash_ctx(tfm); | ||
1757 | + be128 k; | ||
1758 | |||
1759 | if (keylen != GHASH_BLOCK_SIZE) { | ||
1760 | crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); | ||
1761 | @@ -42,7 +43,12 @@ static int ghash_setkey(struct crypto_shash *tfm, | ||
1762 | |||
1763 | if (ctx->gf128) | ||
1764 | gf128mul_free_4k(ctx->gf128); | ||
1765 | - ctx->gf128 = gf128mul_init_4k_lle((be128 *)key); | ||
1766 | + | ||
1767 | + BUILD_BUG_ON(sizeof(k) != GHASH_BLOCK_SIZE); | ||
1768 | + memcpy(&k, key, GHASH_BLOCK_SIZE); /* avoid violating alignment rules */ | ||
1769 | + ctx->gf128 = gf128mul_init_4k_lle(&k); | ||
1770 | + memzero_explicit(&k, GHASH_BLOCK_SIZE); | ||
1771 | + | ||
1772 | if (!ctx->gf128) | ||
1773 | return -ENOMEM; | ||
1774 | |||
1775 | diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c | ||
1776 | index 90c38778bc1f..16f8fda89981 100644 | ||
1777 | --- a/drivers/ata/libata-eh.c | ||
1778 | +++ b/drivers/ata/libata-eh.c | ||
1779 | @@ -1600,7 +1600,7 @@ static int ata_eh_read_log_10h(struct ata_device *dev, | ||
1780 | tf->hob_lbah = buf[10]; | ||
1781 | tf->nsect = buf[12]; | ||
1782 | tf->hob_nsect = buf[13]; | ||
1783 | - if (ata_id_has_ncq_autosense(dev->id)) | ||
1784 | + if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id)) | ||
1785 | tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16]; | ||
1786 | |||
1787 | return 0; | ||
1788 | @@ -1849,7 +1849,8 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) | ||
1789 | memcpy(&qc->result_tf, &tf, sizeof(tf)); | ||
1790 | qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48; | ||
1791 | qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; | ||
1792 | - if ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary) { | ||
1793 | + if (dev->class == ATA_DEV_ZAC && | ||
1794 | + ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) { | ||
1795 | char sense_key, asc, ascq; | ||
1796 | |||
1797 | sense_key = (qc->result_tf.auxiliary >> 16) & 0xff; | ||
1798 | @@ -1903,10 +1904,11 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc, | ||
1799 | } | ||
1800 | |||
1801 | switch (qc->dev->class) { | ||
1802 | - case ATA_DEV_ATA: | ||
1803 | case ATA_DEV_ZAC: | ||
1804 | if (stat & ATA_SENSE) | ||
1805 | ata_eh_request_sense(qc, qc->scsicmd); | ||
1806 | + /* fall through */ | ||
1807 | + case ATA_DEV_ATA: | ||
1808 | if (err & ATA_ICRC) | ||
1809 | qc->err_mask |= AC_ERR_ATA_BUS; | ||
1810 | if (err & (ATA_UNC | ATA_AMNF)) | ||
1811 | diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c | ||
1812 | index 69c84fddfe8a..1799a1dfa46e 100644 | ||
1813 | --- a/drivers/base/regmap/regmap.c | ||
1814 | +++ b/drivers/base/regmap/regmap.c | ||
1815 | @@ -1506,6 +1506,8 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, | ||
1816 | map->format.reg_bytes + | ||
1817 | map->format.pad_bytes, | ||
1818 | val, val_len); | ||
1819 | + else | ||
1820 | + ret = -ENOTSUPP; | ||
1821 | |||
1822 | /* If that didn't work fall back on linearising by hand. */ | ||
1823 | if (ret == -ENOTSUPP) { | ||
1824 | diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c | ||
1825 | index 6914c6e1e1a8..6930abef42b3 100644 | ||
1826 | --- a/drivers/block/floppy.c | ||
1827 | +++ b/drivers/block/floppy.c | ||
1828 | @@ -192,6 +192,7 @@ static int print_unex = 1; | ||
1829 | #include <linux/io.h> | ||
1830 | #include <linux/uaccess.h> | ||
1831 | #include <linux/async.h> | ||
1832 | +#include <linux/compat.h> | ||
1833 | |||
1834 | /* | ||
1835 | * PS/2 floppies have much slower step rates than regular floppies. | ||
1836 | @@ -2113,6 +2114,9 @@ static void setup_format_params(int track) | ||
1837 | raw_cmd->kernel_data = floppy_track_buffer; | ||
1838 | raw_cmd->length = 4 * F_SECT_PER_TRACK; | ||
1839 | |||
1840 | + if (!F_SECT_PER_TRACK) | ||
1841 | + return; | ||
1842 | + | ||
1843 | /* allow for about 30ms for data transport per track */ | ||
1844 | head_shift = (F_SECT_PER_TRACK + 5) / 6; | ||
1845 | |||
1846 | @@ -3233,8 +3237,12 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g, | ||
1847 | int cnt; | ||
1848 | |||
1849 | /* sanity checking for parameters. */ | ||
1850 | - if (g->sect <= 0 || | ||
1851 | - g->head <= 0 || | ||
1852 | + if ((int)g->sect <= 0 || | ||
1853 | + (int)g->head <= 0 || | ||
1854 | + /* check for overflow in max_sector */ | ||
1855 | + (int)(g->sect * g->head) <= 0 || | ||
1856 | + /* check for zero in F_SECT_PER_TRACK */ | ||
1857 | + (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 || | ||
1858 | g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) || | ||
1859 | /* check if reserved bits are set */ | ||
1860 | (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0) | ||
1861 | @@ -3378,6 +3386,24 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo) | ||
1862 | return 0; | ||
1863 | } | ||
1864 | |||
1865 | +static bool valid_floppy_drive_params(const short autodetect[8], | ||
1866 | + int native_format) | ||
1867 | +{ | ||
1868 | + size_t floppy_type_size = ARRAY_SIZE(floppy_type); | ||
1869 | + size_t i = 0; | ||
1870 | + | ||
1871 | + for (i = 0; i < 8; ++i) { | ||
1872 | + if (autodetect[i] < 0 || | ||
1873 | + autodetect[i] >= floppy_type_size) | ||
1874 | + return false; | ||
1875 | + } | ||
1876 | + | ||
1877 | + if (native_format < 0 || native_format >= floppy_type_size) | ||
1878 | + return false; | ||
1879 | + | ||
1880 | + return true; | ||
1881 | +} | ||
1882 | + | ||
1883 | static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, | ||
1884 | unsigned long param) | ||
1885 | { | ||
1886 | @@ -3504,6 +3530,9 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int | ||
1887 | SUPBOUND(size, strlen((const char *)outparam) + 1); | ||
1888 | break; | ||
1889 | case FDSETDRVPRM: | ||
1890 | + if (!valid_floppy_drive_params(inparam.dp.autodetect, | ||
1891 | + inparam.dp.native_format)) | ||
1892 | + return -EINVAL; | ||
1893 | *UDP = inparam.dp; | ||
1894 | break; | ||
1895 | case FDGETDRVPRM: | ||
1896 | @@ -3569,6 +3598,332 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, | ||
1897 | return ret; | ||
1898 | } | ||
1899 | |||
1900 | +#ifdef CONFIG_COMPAT | ||
1901 | + | ||
1902 | +struct compat_floppy_drive_params { | ||
1903 | + char cmos; | ||
1904 | + compat_ulong_t max_dtr; | ||
1905 | + compat_ulong_t hlt; | ||
1906 | + compat_ulong_t hut; | ||
1907 | + compat_ulong_t srt; | ||
1908 | + compat_ulong_t spinup; | ||
1909 | + compat_ulong_t spindown; | ||
1910 | + unsigned char spindown_offset; | ||
1911 | + unsigned char select_delay; | ||
1912 | + unsigned char rps; | ||
1913 | + unsigned char tracks; | ||
1914 | + compat_ulong_t timeout; | ||
1915 | + unsigned char interleave_sect; | ||
1916 | + struct floppy_max_errors max_errors; | ||
1917 | + char flags; | ||
1918 | + char read_track; | ||
1919 | + short autodetect[8]; | ||
1920 | + compat_int_t checkfreq; | ||
1921 | + compat_int_t native_format; | ||
1922 | +}; | ||
1923 | + | ||
1924 | +struct compat_floppy_drive_struct { | ||
1925 | + signed char flags; | ||
1926 | + compat_ulong_t spinup_date; | ||
1927 | + compat_ulong_t select_date; | ||
1928 | + compat_ulong_t first_read_date; | ||
1929 | + short probed_format; | ||
1930 | + short track; | ||
1931 | + short maxblock; | ||
1932 | + short maxtrack; | ||
1933 | + compat_int_t generation; | ||
1934 | + compat_int_t keep_data; | ||
1935 | + compat_int_t fd_ref; | ||
1936 | + compat_int_t fd_device; | ||
1937 | + compat_int_t last_checked; | ||
1938 | + compat_caddr_t dmabuf; | ||
1939 | + compat_int_t bufblocks; | ||
1940 | +}; | ||
1941 | + | ||
1942 | +struct compat_floppy_fdc_state { | ||
1943 | + compat_int_t spec1; | ||
1944 | + compat_int_t spec2; | ||
1945 | + compat_int_t dtr; | ||
1946 | + unsigned char version; | ||
1947 | + unsigned char dor; | ||
1948 | + compat_ulong_t address; | ||
1949 | + unsigned int rawcmd:2; | ||
1950 | + unsigned int reset:1; | ||
1951 | + unsigned int need_configure:1; | ||
1952 | + unsigned int perp_mode:2; | ||
1953 | + unsigned int has_fifo:1; | ||
1954 | + unsigned int driver_version; | ||
1955 | + unsigned char track[4]; | ||
1956 | +}; | ||
1957 | + | ||
1958 | +struct compat_floppy_write_errors { | ||
1959 | + unsigned int write_errors; | ||
1960 | + compat_ulong_t first_error_sector; | ||
1961 | + compat_int_t first_error_generation; | ||
1962 | + compat_ulong_t last_error_sector; | ||
1963 | + compat_int_t last_error_generation; | ||
1964 | + compat_uint_t badness; | ||
1965 | +}; | ||
1966 | + | ||
1967 | +#define FDSETPRM32 _IOW(2, 0x42, struct compat_floppy_struct) | ||
1968 | +#define FDDEFPRM32 _IOW(2, 0x43, struct compat_floppy_struct) | ||
1969 | +#define FDSETDRVPRM32 _IOW(2, 0x90, struct compat_floppy_drive_params) | ||
1970 | +#define FDGETDRVPRM32 _IOR(2, 0x11, struct compat_floppy_drive_params) | ||
1971 | +#define FDGETDRVSTAT32 _IOR(2, 0x12, struct compat_floppy_drive_struct) | ||
1972 | +#define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct compat_floppy_drive_struct) | ||
1973 | +#define FDGETFDCSTAT32 _IOR(2, 0x15, struct compat_floppy_fdc_state) | ||
1974 | +#define FDWERRORGET32 _IOR(2, 0x17, struct compat_floppy_write_errors) | ||
1975 | + | ||
1976 | +static int compat_set_geometry(struct block_device *bdev, fmode_t mode, unsigned int cmd, | ||
1977 | + struct compat_floppy_struct __user *arg) | ||
1978 | +{ | ||
1979 | + struct floppy_struct v; | ||
1980 | + int drive, type; | ||
1981 | + int err; | ||
1982 | + | ||
1983 | + BUILD_BUG_ON(offsetof(struct floppy_struct, name) != | ||
1984 | + offsetof(struct compat_floppy_struct, name)); | ||
1985 | + | ||
1986 | + if (!(mode & (FMODE_WRITE | FMODE_WRITE_IOCTL))) | ||
1987 | + return -EPERM; | ||
1988 | + | ||
1989 | + memset(&v, 0, sizeof(struct floppy_struct)); | ||
1990 | + if (copy_from_user(&v, arg, offsetof(struct floppy_struct, name))) | ||
1991 | + return -EFAULT; | ||
1992 | + | ||
1993 | + mutex_lock(&floppy_mutex); | ||
1994 | + drive = (long)bdev->bd_disk->private_data; | ||
1995 | + type = ITYPE(UDRS->fd_device); | ||
1996 | + err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM, | ||
1997 | + &v, drive, type, bdev); | ||
1998 | + mutex_unlock(&floppy_mutex); | ||
1999 | + return err; | ||
2000 | +} | ||
2001 | + | ||
2002 | +static int compat_get_prm(int drive, | ||
2003 | + struct compat_floppy_struct __user *arg) | ||
2004 | +{ | ||
2005 | + struct compat_floppy_struct v; | ||
2006 | + struct floppy_struct *p; | ||
2007 | + int err; | ||
2008 | + | ||
2009 | + memset(&v, 0, sizeof(v)); | ||
2010 | + mutex_lock(&floppy_mutex); | ||
2011 | + err = get_floppy_geometry(drive, ITYPE(UDRS->fd_device), &p); | ||
2012 | + if (err) { | ||
2013 | + mutex_unlock(&floppy_mutex); | ||
2014 | + return err; | ||
2015 | + } | ||
2016 | + memcpy(&v, p, offsetof(struct floppy_struct, name)); | ||
2017 | + mutex_unlock(&floppy_mutex); | ||
2018 | + if (copy_to_user(arg, &v, sizeof(struct compat_floppy_struct))) | ||
2019 | + return -EFAULT; | ||
2020 | + return 0; | ||
2021 | +} | ||
2022 | + | ||
2023 | +static int compat_setdrvprm(int drive, | ||
2024 | + struct compat_floppy_drive_params __user *arg) | ||
2025 | +{ | ||
2026 | + struct compat_floppy_drive_params v; | ||
2027 | + | ||
2028 | + if (!capable(CAP_SYS_ADMIN)) | ||
2029 | + return -EPERM; | ||
2030 | + if (copy_from_user(&v, arg, sizeof(struct compat_floppy_drive_params))) | ||
2031 | + return -EFAULT; | ||
2032 | + if (!valid_floppy_drive_params(v.autodetect, v.native_format)) | ||
2033 | + return -EINVAL; | ||
2034 | + mutex_lock(&floppy_mutex); | ||
2035 | + UDP->cmos = v.cmos; | ||
2036 | + UDP->max_dtr = v.max_dtr; | ||
2037 | + UDP->hlt = v.hlt; | ||
2038 | + UDP->hut = v.hut; | ||
2039 | + UDP->srt = v.srt; | ||
2040 | + UDP->spinup = v.spinup; | ||
2041 | + UDP->spindown = v.spindown; | ||
2042 | + UDP->spindown_offset = v.spindown_offset; | ||
2043 | + UDP->select_delay = v.select_delay; | ||
2044 | + UDP->rps = v.rps; | ||
2045 | + UDP->tracks = v.tracks; | ||
2046 | + UDP->timeout = v.timeout; | ||
2047 | + UDP->interleave_sect = v.interleave_sect; | ||
2048 | + UDP->max_errors = v.max_errors; | ||
2049 | + UDP->flags = v.flags; | ||
2050 | + UDP->read_track = v.read_track; | ||
2051 | + memcpy(UDP->autodetect, v.autodetect, sizeof(v.autodetect)); | ||
2052 | + UDP->checkfreq = v.checkfreq; | ||
2053 | + UDP->native_format = v.native_format; | ||
2054 | + mutex_unlock(&floppy_mutex); | ||
2055 | + return 0; | ||
2056 | +} | ||
2057 | + | ||
2058 | +static int compat_getdrvprm(int drive, | ||
2059 | + struct compat_floppy_drive_params __user *arg) | ||
2060 | +{ | ||
2061 | + struct compat_floppy_drive_params v; | ||
2062 | + | ||
2063 | + memset(&v, 0, sizeof(struct compat_floppy_drive_params)); | ||
2064 | + mutex_lock(&floppy_mutex); | ||
2065 | + v.cmos = UDP->cmos; | ||
2066 | + v.max_dtr = UDP->max_dtr; | ||
2067 | + v.hlt = UDP->hlt; | ||
2068 | + v.hut = UDP->hut; | ||
2069 | + v.srt = UDP->srt; | ||
2070 | + v.spinup = UDP->spinup; | ||
2071 | + v.spindown = UDP->spindown; | ||
2072 | + v.spindown_offset = UDP->spindown_offset; | ||
2073 | + v.select_delay = UDP->select_delay; | ||
2074 | + v.rps = UDP->rps; | ||
2075 | + v.tracks = UDP->tracks; | ||
2076 | + v.timeout = UDP->timeout; | ||
2077 | + v.interleave_sect = UDP->interleave_sect; | ||
2078 | + v.max_errors = UDP->max_errors; | ||
2079 | + v.flags = UDP->flags; | ||
2080 | + v.read_track = UDP->read_track; | ||
2081 | + memcpy(v.autodetect, UDP->autodetect, sizeof(v.autodetect)); | ||
2082 | + v.checkfreq = UDP->checkfreq; | ||
2083 | + v.native_format = UDP->native_format; | ||
2084 | + mutex_unlock(&floppy_mutex); | ||
2085 | + | ||
2086 | + if (copy_from_user(arg, &v, sizeof(struct compat_floppy_drive_params))) | ||
2087 | + return -EFAULT; | ||
2088 | + return 0; | ||
2089 | +} | ||
2090 | + | ||
2091 | +static int compat_getdrvstat(int drive, bool poll, | ||
2092 | + struct compat_floppy_drive_struct __user *arg) | ||
2093 | +{ | ||
2094 | + struct compat_floppy_drive_struct v; | ||
2095 | + | ||
2096 | + memset(&v, 0, sizeof(struct compat_floppy_drive_struct)); | ||
2097 | + mutex_lock(&floppy_mutex); | ||
2098 | + | ||
2099 | + if (poll) { | ||
2100 | + if (lock_fdc(drive)) | ||
2101 | + goto Eintr; | ||
2102 | + if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR) | ||
2103 | + goto Eintr; | ||
2104 | + process_fd_request(); | ||
2105 | + } | ||
2106 | + v.spinup_date = UDRS->spinup_date; | ||
2107 | + v.select_date = UDRS->select_date; | ||
2108 | + v.first_read_date = UDRS->first_read_date; | ||
2109 | + v.probed_format = UDRS->probed_format; | ||
2110 | + v.track = UDRS->track; | ||
2111 | + v.maxblock = UDRS->maxblock; | ||
2112 | + v.maxtrack = UDRS->maxtrack; | ||
2113 | + v.generation = UDRS->generation; | ||
2114 | + v.keep_data = UDRS->keep_data; | ||
2115 | + v.fd_ref = UDRS->fd_ref; | ||
2116 | + v.fd_device = UDRS->fd_device; | ||
2117 | + v.last_checked = UDRS->last_checked; | ||
2118 | + v.dmabuf = (uintptr_t)UDRS->dmabuf; | ||
2119 | + v.bufblocks = UDRS->bufblocks; | ||
2120 | + mutex_unlock(&floppy_mutex); | ||
2121 | + | ||
2122 | + if (copy_from_user(arg, &v, sizeof(struct compat_floppy_drive_struct))) | ||
2123 | + return -EFAULT; | ||
2124 | + return 0; | ||
2125 | +Eintr: | ||
2126 | + mutex_unlock(&floppy_mutex); | ||
2127 | + return -EINTR; | ||
2128 | +} | ||
2129 | + | ||
2130 | +static int compat_getfdcstat(int drive, | ||
2131 | + struct compat_floppy_fdc_state __user *arg) | ||
2132 | +{ | ||
2133 | + struct compat_floppy_fdc_state v32; | ||
2134 | + struct floppy_fdc_state v; | ||
2135 | + | ||
2136 | + mutex_lock(&floppy_mutex); | ||
2137 | + v = *UFDCS; | ||
2138 | + mutex_unlock(&floppy_mutex); | ||
2139 | + | ||
2140 | + memset(&v32, 0, sizeof(struct compat_floppy_fdc_state)); | ||
2141 | + v32.spec1 = v.spec1; | ||
2142 | + v32.spec2 = v.spec2; | ||
2143 | + v32.dtr = v.dtr; | ||
2144 | + v32.version = v.version; | ||
2145 | + v32.dor = v.dor; | ||
2146 | + v32.address = v.address; | ||
2147 | + v32.rawcmd = v.rawcmd; | ||
2148 | + v32.reset = v.reset; | ||
2149 | + v32.need_configure = v.need_configure; | ||
2150 | + v32.perp_mode = v.perp_mode; | ||
2151 | + v32.has_fifo = v.has_fifo; | ||
2152 | + v32.driver_version = v.driver_version; | ||
2153 | + memcpy(v32.track, v.track, 4); | ||
2154 | + if (copy_to_user(arg, &v32, sizeof(struct compat_floppy_fdc_state))) | ||
2155 | + return -EFAULT; | ||
2156 | + return 0; | ||
2157 | +} | ||
2158 | + | ||
2159 | +static int compat_werrorget(int drive, | ||
2160 | + struct compat_floppy_write_errors __user *arg) | ||
2161 | +{ | ||
2162 | + struct compat_floppy_write_errors v32; | ||
2163 | + struct floppy_write_errors v; | ||
2164 | + | ||
2165 | + memset(&v32, 0, sizeof(struct compat_floppy_write_errors)); | ||
2166 | + mutex_lock(&floppy_mutex); | ||
2167 | + v = *UDRWE; | ||
2168 | + mutex_unlock(&floppy_mutex); | ||
2169 | + v32.write_errors = v.write_errors; | ||
2170 | + v32.first_error_sector = v.first_error_sector; | ||
2171 | + v32.first_error_generation = v.first_error_generation; | ||
2172 | + v32.last_error_sector = v.last_error_sector; | ||
2173 | + v32.last_error_generation = v.last_error_generation; | ||
2174 | + v32.badness = v.badness; | ||
2175 | + if (copy_to_user(arg, &v32, sizeof(struct compat_floppy_write_errors))) | ||
2176 | + return -EFAULT; | ||
2177 | + return 0; | ||
2178 | +} | ||
2179 | + | ||
2180 | +static int fd_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, | ||
2181 | + unsigned long param) | ||
2182 | +{ | ||
2183 | + int drive = (long)bdev->bd_disk->private_data; | ||
2184 | + switch (cmd) { | ||
2185 | + case FDMSGON: | ||
2186 | + case FDMSGOFF: | ||
2187 | + case FDSETEMSGTRESH: | ||
2188 | + case FDFLUSH: | ||
2189 | + case FDWERRORCLR: | ||
2190 | + case FDEJECT: | ||
2191 | + case FDCLRPRM: | ||
2192 | + case FDFMTBEG: | ||
2193 | + case FDRESET: | ||
2194 | + case FDTWADDLE: | ||
2195 | + return fd_ioctl(bdev, mode, cmd, param); | ||
2196 | + case FDSETMAXERRS: | ||
2197 | + case FDGETMAXERRS: | ||
2198 | + case FDGETDRVTYP: | ||
2199 | + case FDFMTEND: | ||
2200 | + case FDFMTTRK: | ||
2201 | + case FDRAWCMD: | ||
2202 | + return fd_ioctl(bdev, mode, cmd, | ||
2203 | + (unsigned long)compat_ptr(param)); | ||
2204 | + case FDSETPRM32: | ||
2205 | + case FDDEFPRM32: | ||
2206 | + return compat_set_geometry(bdev, mode, cmd, compat_ptr(param)); | ||
2207 | + case FDGETPRM32: | ||
2208 | + return compat_get_prm(drive, compat_ptr(param)); | ||
2209 | + case FDSETDRVPRM32: | ||
2210 | + return compat_setdrvprm(drive, compat_ptr(param)); | ||
2211 | + case FDGETDRVPRM32: | ||
2212 | + return compat_getdrvprm(drive, compat_ptr(param)); | ||
2213 | + case FDPOLLDRVSTAT32: | ||
2214 | + return compat_getdrvstat(drive, true, compat_ptr(param)); | ||
2215 | + case FDGETDRVSTAT32: | ||
2216 | + return compat_getdrvstat(drive, false, compat_ptr(param)); | ||
2217 | + case FDGETFDCSTAT32: | ||
2218 | + return compat_getfdcstat(drive, compat_ptr(param)); | ||
2219 | + case FDWERRORGET32: | ||
2220 | + return compat_werrorget(drive, compat_ptr(param)); | ||
2221 | + } | ||
2222 | + return -EINVAL; | ||
2223 | +} | ||
2224 | +#endif | ||
2225 | + | ||
2226 | static void __init config_types(void) | ||
2227 | { | ||
2228 | bool has_drive = false; | ||
2229 | @@ -3891,6 +4246,9 @@ static const struct block_device_operations floppy_fops = { | ||
2230 | .getgeo = fd_getgeo, | ||
2231 | .check_events = floppy_check_events, | ||
2232 | .revalidate_disk = floppy_revalidate, | ||
2233 | +#ifdef CONFIG_COMPAT | ||
2234 | + .compat_ioctl = fd_compat_ioctl, | ||
2235 | +#endif | ||
2236 | }; | ||
2237 | |||
2238 | /* | ||
2239 | diff --git a/drivers/bluetooth/hci_ath.c b/drivers/bluetooth/hci_ath.c | ||
2240 | index 0ccf6bf01ed4..c50b68bbecdc 100644 | ||
2241 | --- a/drivers/bluetooth/hci_ath.c | ||
2242 | +++ b/drivers/bluetooth/hci_ath.c | ||
2243 | @@ -101,6 +101,9 @@ static int ath_open(struct hci_uart *hu) | ||
2244 | |||
2245 | BT_DBG("hu %p", hu); | ||
2246 | |||
2247 | + if (!hci_uart_has_flow_control(hu)) | ||
2248 | + return -EOPNOTSUPP; | ||
2249 | + | ||
2250 | ath = kzalloc(sizeof(*ath), GFP_KERNEL); | ||
2251 | if (!ath) | ||
2252 | return -ENOMEM; | ||
2253 | diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c | ||
2254 | index deed58013555..25042c794852 100644 | ||
2255 | --- a/drivers/bluetooth/hci_bcm.c | ||
2256 | +++ b/drivers/bluetooth/hci_bcm.c | ||
2257 | @@ -279,6 +279,9 @@ static int bcm_open(struct hci_uart *hu) | ||
2258 | |||
2259 | bt_dev_dbg(hu->hdev, "hu %p", hu); | ||
2260 | |||
2261 | + if (!hci_uart_has_flow_control(hu)) | ||
2262 | + return -EOPNOTSUPP; | ||
2263 | + | ||
2264 | bcm = kzalloc(sizeof(*bcm), GFP_KERNEL); | ||
2265 | if (!bcm) | ||
2266 | return -ENOMEM; | ||
2267 | diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c | ||
2268 | index a2c921faaa12..34e04bf87a62 100644 | ||
2269 | --- a/drivers/bluetooth/hci_bcsp.c | ||
2270 | +++ b/drivers/bluetooth/hci_bcsp.c | ||
2271 | @@ -759,6 +759,11 @@ static int bcsp_close(struct hci_uart *hu) | ||
2272 | skb_queue_purge(&bcsp->rel); | ||
2273 | skb_queue_purge(&bcsp->unrel); | ||
2274 | |||
2275 | + if (bcsp->rx_skb) { | ||
2276 | + kfree_skb(bcsp->rx_skb); | ||
2277 | + bcsp->rx_skb = NULL; | ||
2278 | + } | ||
2279 | + | ||
2280 | kfree(bcsp); | ||
2281 | return 0; | ||
2282 | } | ||
2283 | diff --git a/drivers/bluetooth/hci_intel.c b/drivers/bluetooth/hci_intel.c | ||
2284 | index 73306384af6c..f822e862b689 100644 | ||
2285 | --- a/drivers/bluetooth/hci_intel.c | ||
2286 | +++ b/drivers/bluetooth/hci_intel.c | ||
2287 | @@ -407,6 +407,9 @@ static int intel_open(struct hci_uart *hu) | ||
2288 | |||
2289 | BT_DBG("hu %p", hu); | ||
2290 | |||
2291 | + if (!hci_uart_has_flow_control(hu)) | ||
2292 | + return -EOPNOTSUPP; | ||
2293 | + | ||
2294 | intel = kzalloc(sizeof(*intel), GFP_KERNEL); | ||
2295 | if (!intel) | ||
2296 | return -ENOMEM; | ||
2297 | diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c | ||
2298 | index 2230f9368c21..a2f6953a86f5 100644 | ||
2299 | --- a/drivers/bluetooth/hci_ldisc.c | ||
2300 | +++ b/drivers/bluetooth/hci_ldisc.c | ||
2301 | @@ -263,6 +263,15 @@ static int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb) | ||
2302 | return 0; | ||
2303 | } | ||
2304 | |||
2305 | +/* Check the underlying device or tty has flow control support */ | ||
2306 | +bool hci_uart_has_flow_control(struct hci_uart *hu) | ||
2307 | +{ | ||
2308 | + if (hu->tty->driver->ops->tiocmget && hu->tty->driver->ops->tiocmset) | ||
2309 | + return true; | ||
2310 | + | ||
2311 | + return false; | ||
2312 | +} | ||
2313 | + | ||
2314 | /* Flow control or un-flow control the device */ | ||
2315 | void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) | ||
2316 | { | ||
2317 | diff --git a/drivers/bluetooth/hci_mrvl.c b/drivers/bluetooth/hci_mrvl.c | ||
2318 | index bbc4b39b1dbf..716d89a90907 100644 | ||
2319 | --- a/drivers/bluetooth/hci_mrvl.c | ||
2320 | +++ b/drivers/bluetooth/hci_mrvl.c | ||
2321 | @@ -66,6 +66,9 @@ static int mrvl_open(struct hci_uart *hu) | ||
2322 | |||
2323 | BT_DBG("hu %p", hu); | ||
2324 | |||
2325 | + if (!hci_uart_has_flow_control(hu)) | ||
2326 | + return -EOPNOTSUPP; | ||
2327 | + | ||
2328 | mrvl = kzalloc(sizeof(*mrvl), GFP_KERNEL); | ||
2329 | if (!mrvl) | ||
2330 | return -ENOMEM; | ||
2331 | diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h | ||
2332 | index 070139513e65..aeef870e31b8 100644 | ||
2333 | --- a/drivers/bluetooth/hci_uart.h | ||
2334 | +++ b/drivers/bluetooth/hci_uart.h | ||
2335 | @@ -109,6 +109,7 @@ int hci_uart_tx_wakeup(struct hci_uart *hu); | ||
2336 | int hci_uart_init_ready(struct hci_uart *hu); | ||
2337 | void hci_uart_init_tty(struct hci_uart *hu); | ||
2338 | void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed); | ||
2339 | +bool hci_uart_has_flow_control(struct hci_uart *hu); | ||
2340 | void hci_uart_set_flow_control(struct hci_uart *hu, bool enable); | ||
2341 | void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, | ||
2342 | unsigned int oper_speed); | ||
2343 | diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c | ||
2344 | index 818a8d40e5c9..bedfd2412ec1 100644 | ||
2345 | --- a/drivers/char/hpet.c | ||
2346 | +++ b/drivers/char/hpet.c | ||
2347 | @@ -569,8 +569,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets, | ||
2348 | unsigned long long m; | ||
2349 | |||
2350 | m = hpets->hp_tick_freq + (dis >> 1); | ||
2351 | - do_div(m, dis); | ||
2352 | - return (unsigned long)m; | ||
2353 | + return div64_ul(m, dis); | ||
2354 | } | ||
2355 | |||
2356 | static int | ||
2357 | diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c | ||
2358 | index fb0cf8b74516..d32248e2ceab 100644 | ||
2359 | --- a/drivers/clocksource/exynos_mct.c | ||
2360 | +++ b/drivers/clocksource/exynos_mct.c | ||
2361 | @@ -211,7 +211,7 @@ static void exynos4_frc_resume(struct clocksource *cs) | ||
2362 | |||
2363 | static struct clocksource mct_frc = { | ||
2364 | .name = "mct-frc", | ||
2365 | - .rating = 400, | ||
2366 | + .rating = 450, /* use value higher than ARM arch timer */ | ||
2367 | .read = exynos4_frc_read, | ||
2368 | .mask = CLOCKSOURCE_MASK(32), | ||
2369 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | ||
2370 | @@ -466,7 +466,7 @@ static int exynos4_mct_starting_cpu(unsigned int cpu) | ||
2371 | evt->set_state_oneshot_stopped = set_state_shutdown; | ||
2372 | evt->tick_resume = set_state_shutdown; | ||
2373 | evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; | ||
2374 | - evt->rating = 450; | ||
2375 | + evt->rating = 500; /* use value higher than ARM arch timer */ | ||
2376 | |||
2377 | exynos4_mct_write(TICK_BASE_CNT, mevt->base + MCT_L_TCNTB_OFFSET); | ||
2378 | |||
2379 | diff --git a/drivers/crypto/amcc/crypto4xx_trng.c b/drivers/crypto/amcc/crypto4xx_trng.c | ||
2380 | index 368c5599515e..a194ee0ddbb6 100644 | ||
2381 | --- a/drivers/crypto/amcc/crypto4xx_trng.c | ||
2382 | +++ b/drivers/crypto/amcc/crypto4xx_trng.c | ||
2383 | @@ -111,7 +111,6 @@ void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev) | ||
2384 | return; | ||
2385 | |||
2386 | err_out: | ||
2387 | - of_node_put(trng); | ||
2388 | iounmap(dev->trng_base); | ||
2389 | kfree(rng); | ||
2390 | dev->trng_base = NULL; | ||
2391 | diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c | ||
2392 | index 88caca3370f2..f8ac768ed5d7 100644 | ||
2393 | --- a/drivers/crypto/caam/caamalg.c | ||
2394 | +++ b/drivers/crypto/caam/caamalg.c | ||
2395 | @@ -2015,6 +2015,7 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err, | ||
2396 | struct ablkcipher_request *req = context; | ||
2397 | struct ablkcipher_edesc *edesc; | ||
2398 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); | ||
2399 | + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); | ||
2400 | int ivsize = crypto_ablkcipher_ivsize(ablkcipher); | ||
2401 | |||
2402 | #ifdef DEBUG | ||
2403 | @@ -2040,10 +2041,11 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err, | ||
2404 | |||
2405 | /* | ||
2406 | * The crypto API expects us to set the IV (req->info) to the last | ||
2407 | - * ciphertext block. This is used e.g. by the CTS mode. | ||
2408 | + * ciphertext block when running in CBC mode. | ||
2409 | */ | ||
2410 | - scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize, | ||
2411 | - ivsize, 0); | ||
2412 | + if ((ctx->class1_alg_type & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC) | ||
2413 | + scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - | ||
2414 | + ivsize, ivsize, 0); | ||
2415 | |||
2416 | kfree(edesc); | ||
2417 | |||
2418 | @@ -2056,6 +2058,7 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err, | ||
2419 | struct ablkcipher_request *req = context; | ||
2420 | struct ablkcipher_edesc *edesc; | ||
2421 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); | ||
2422 | + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); | ||
2423 | int ivsize = crypto_ablkcipher_ivsize(ablkcipher); | ||
2424 | |||
2425 | #ifdef DEBUG | ||
2426 | @@ -2080,10 +2083,11 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err, | ||
2427 | |||
2428 | /* | ||
2429 | * The crypto API expects us to set the IV (req->info) to the last | ||
2430 | - * ciphertext block. | ||
2431 | + * ciphertext block when running in CBC mode. | ||
2432 | */ | ||
2433 | - scatterwalk_map_and_copy(req->info, req->src, req->nbytes - ivsize, | ||
2434 | - ivsize, 0); | ||
2435 | + if ((ctx->class1_alg_type & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC) | ||
2436 | + scatterwalk_map_and_copy(req->info, req->src, req->nbytes - | ||
2437 | + ivsize, ivsize, 0); | ||
2438 | |||
2439 | kfree(edesc); | ||
2440 | |||
2441 | diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c | ||
2442 | index f796e36d7ec3..46d18f39fa7b 100644 | ||
2443 | --- a/drivers/crypto/ccp/ccp-dev.c | ||
2444 | +++ b/drivers/crypto/ccp/ccp-dev.c | ||
2445 | @@ -40,57 +40,63 @@ struct ccp_tasklet_data { | ||
2446 | struct ccp_cmd *cmd; | ||
2447 | }; | ||
2448 | |||
2449 | -/* Human-readable error strings */ | ||
2450 | -char *ccp_error_codes[] = { | ||
2451 | - "", | ||
2452 | - "ERR 01: ILLEGAL_ENGINE", | ||
2453 | - "ERR 02: ILLEGAL_KEY_ID", | ||
2454 | - "ERR 03: ILLEGAL_FUNCTION_TYPE", | ||
2455 | - "ERR 04: ILLEGAL_FUNCTION_MODE", | ||
2456 | - "ERR 05: ILLEGAL_FUNCTION_ENCRYPT", | ||
2457 | - "ERR 06: ILLEGAL_FUNCTION_SIZE", | ||
2458 | - "ERR 07: Zlib_MISSING_INIT_EOM", | ||
2459 | - "ERR 08: ILLEGAL_FUNCTION_RSVD", | ||
2460 | - "ERR 09: ILLEGAL_BUFFER_LENGTH", | ||
2461 | - "ERR 10: VLSB_FAULT", | ||
2462 | - "ERR 11: ILLEGAL_MEM_ADDR", | ||
2463 | - "ERR 12: ILLEGAL_MEM_SEL", | ||
2464 | - "ERR 13: ILLEGAL_CONTEXT_ID", | ||
2465 | - "ERR 14: ILLEGAL_KEY_ADDR", | ||
2466 | - "ERR 15: 0xF Reserved", | ||
2467 | - "ERR 16: Zlib_ILLEGAL_MULTI_QUEUE", | ||
2468 | - "ERR 17: Zlib_ILLEGAL_JOBID_CHANGE", | ||
2469 | - "ERR 18: CMD_TIMEOUT", | ||
2470 | - "ERR 19: IDMA0_AXI_SLVERR", | ||
2471 | - "ERR 20: IDMA0_AXI_DECERR", | ||
2472 | - "ERR 21: 0x15 Reserved", | ||
2473 | - "ERR 22: IDMA1_AXI_SLAVE_FAULT", | ||
2474 | - "ERR 23: IDMA1_AIXI_DECERR", | ||
2475 | - "ERR 24: 0x18 Reserved", | ||
2476 | - "ERR 25: ZLIBVHB_AXI_SLVERR", | ||
2477 | - "ERR 26: ZLIBVHB_AXI_DECERR", | ||
2478 | - "ERR 27: 0x1B Reserved", | ||
2479 | - "ERR 27: ZLIB_UNEXPECTED_EOM", | ||
2480 | - "ERR 27: ZLIB_EXTRA_DATA", | ||
2481 | - "ERR 30: ZLIB_BTYPE", | ||
2482 | - "ERR 31: ZLIB_UNDEFINED_SYMBOL", | ||
2483 | - "ERR 32: ZLIB_UNDEFINED_DISTANCE_S", | ||
2484 | - "ERR 33: ZLIB_CODE_LENGTH_SYMBOL", | ||
2485 | - "ERR 34: ZLIB _VHB_ILLEGAL_FETCH", | ||
2486 | - "ERR 35: ZLIB_UNCOMPRESSED_LEN", | ||
2487 | - "ERR 36: ZLIB_LIMIT_REACHED", | ||
2488 | - "ERR 37: ZLIB_CHECKSUM_MISMATCH0", | ||
2489 | - "ERR 38: ODMA0_AXI_SLVERR", | ||
2490 | - "ERR 39: ODMA0_AXI_DECERR", | ||
2491 | - "ERR 40: 0x28 Reserved", | ||
2492 | - "ERR 41: ODMA1_AXI_SLVERR", | ||
2493 | - "ERR 42: ODMA1_AXI_DECERR", | ||
2494 | - "ERR 43: LSB_PARITY_ERR", | ||
2495 | + /* Human-readable error strings */ | ||
2496 | +#define CCP_MAX_ERROR_CODE 64 | ||
2497 | + static char *ccp_error_codes[] = { | ||
2498 | + "", | ||
2499 | + "ILLEGAL_ENGINE", | ||
2500 | + "ILLEGAL_KEY_ID", | ||
2501 | + "ILLEGAL_FUNCTION_TYPE", | ||
2502 | + "ILLEGAL_FUNCTION_MODE", | ||
2503 | + "ILLEGAL_FUNCTION_ENCRYPT", | ||
2504 | + "ILLEGAL_FUNCTION_SIZE", | ||
2505 | + "Zlib_MISSING_INIT_EOM", | ||
2506 | + "ILLEGAL_FUNCTION_RSVD", | ||
2507 | + "ILLEGAL_BUFFER_LENGTH", | ||
2508 | + "VLSB_FAULT", | ||
2509 | + "ILLEGAL_MEM_ADDR", | ||
2510 | + "ILLEGAL_MEM_SEL", | ||
2511 | + "ILLEGAL_CONTEXT_ID", | ||
2512 | + "ILLEGAL_KEY_ADDR", | ||
2513 | + "0xF Reserved", | ||
2514 | + "Zlib_ILLEGAL_MULTI_QUEUE", | ||
2515 | + "Zlib_ILLEGAL_JOBID_CHANGE", | ||
2516 | + "CMD_TIMEOUT", | ||
2517 | + "IDMA0_AXI_SLVERR", | ||
2518 | + "IDMA0_AXI_DECERR", | ||
2519 | + "0x15 Reserved", | ||
2520 | + "IDMA1_AXI_SLAVE_FAULT", | ||
2521 | + "IDMA1_AIXI_DECERR", | ||
2522 | + "0x18 Reserved", | ||
2523 | + "ZLIBVHB_AXI_SLVERR", | ||
2524 | + "ZLIBVHB_AXI_DECERR", | ||
2525 | + "0x1B Reserved", | ||
2526 | + "ZLIB_UNEXPECTED_EOM", | ||
2527 | + "ZLIB_EXTRA_DATA", | ||
2528 | + "ZLIB_BTYPE", | ||
2529 | + "ZLIB_UNDEFINED_SYMBOL", | ||
2530 | + "ZLIB_UNDEFINED_DISTANCE_S", | ||
2531 | + "ZLIB_CODE_LENGTH_SYMBOL", | ||
2532 | + "ZLIB _VHB_ILLEGAL_FETCH", | ||
2533 | + "ZLIB_UNCOMPRESSED_LEN", | ||
2534 | + "ZLIB_LIMIT_REACHED", | ||
2535 | + "ZLIB_CHECKSUM_MISMATCH0", | ||
2536 | + "ODMA0_AXI_SLVERR", | ||
2537 | + "ODMA0_AXI_DECERR", | ||
2538 | + "0x28 Reserved", | ||
2539 | + "ODMA1_AXI_SLVERR", | ||
2540 | + "ODMA1_AXI_DECERR", | ||
2541 | }; | ||
2542 | |||
2543 | -void ccp_log_error(struct ccp_device *d, int e) | ||
2544 | +void ccp_log_error(struct ccp_device *d, unsigned int e) | ||
2545 | { | ||
2546 | - dev_err(d->dev, "CCP error: %s (0x%x)\n", ccp_error_codes[e], e); | ||
2547 | + if (WARN_ON(e >= CCP_MAX_ERROR_CODE)) | ||
2548 | + return; | ||
2549 | + | ||
2550 | + if (e < ARRAY_SIZE(ccp_error_codes)) | ||
2551 | + dev_err(d->dev, "CCP error %d: %s\n", e, ccp_error_codes[e]); | ||
2552 | + else | ||
2553 | + dev_err(d->dev, "CCP error %d: Unknown Error\n", e); | ||
2554 | } | ||
2555 | |||
2556 | /* List of CCPs, CCP count, read-write access lock, and access functions | ||
2557 | diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h | ||
2558 | index 347b77108baa..cfe21d033745 100644 | ||
2559 | --- a/drivers/crypto/ccp/ccp-dev.h | ||
2560 | +++ b/drivers/crypto/ccp/ccp-dev.h | ||
2561 | @@ -607,7 +607,7 @@ void ccp_platform_exit(void); | ||
2562 | void ccp_add_device(struct ccp_device *ccp); | ||
2563 | void ccp_del_device(struct ccp_device *ccp); | ||
2564 | |||
2565 | -extern void ccp_log_error(struct ccp_device *, int); | ||
2566 | +extern void ccp_log_error(struct ccp_device *, unsigned int); | ||
2567 | |||
2568 | struct ccp_device *ccp_alloc_struct(struct device *dev); | ||
2569 | bool ccp_queues_suspended(struct ccp_device *ccp); | ||
2570 | diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c | ||
2571 | index 5a24a484ecc7..ea8595d2c3d8 100644 | ||
2572 | --- a/drivers/crypto/talitos.c | ||
2573 | +++ b/drivers/crypto/talitos.c | ||
2574 | @@ -984,7 +984,6 @@ static void ipsec_esp_encrypt_done(struct device *dev, | ||
2575 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); | ||
2576 | unsigned int authsize = crypto_aead_authsize(authenc); | ||
2577 | struct talitos_edesc *edesc; | ||
2578 | - struct scatterlist *sg; | ||
2579 | void *icvdata; | ||
2580 | |||
2581 | edesc = container_of(desc, struct talitos_edesc, desc); | ||
2582 | @@ -998,9 +997,8 @@ static void ipsec_esp_encrypt_done(struct device *dev, | ||
2583 | else | ||
2584 | icvdata = &edesc->link_tbl[edesc->src_nents + | ||
2585 | edesc->dst_nents + 2]; | ||
2586 | - sg = sg_last(areq->dst, edesc->dst_nents); | ||
2587 | - memcpy((char *)sg_virt(sg) + sg->length - authsize, | ||
2588 | - icvdata, authsize); | ||
2589 | + sg_pcopy_from_buffer(areq->dst, edesc->dst_nents ? : 1, icvdata, | ||
2590 | + authsize, areq->assoclen + areq->cryptlen); | ||
2591 | } | ||
2592 | |||
2593 | kfree(edesc); | ||
2594 | @@ -1016,7 +1014,6 @@ static void ipsec_esp_decrypt_swauth_done(struct device *dev, | ||
2595 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); | ||
2596 | unsigned int authsize = crypto_aead_authsize(authenc); | ||
2597 | struct talitos_edesc *edesc; | ||
2598 | - struct scatterlist *sg; | ||
2599 | char *oicv, *icv; | ||
2600 | struct talitos_private *priv = dev_get_drvdata(dev); | ||
2601 | bool is_sec1 = has_ftr_sec1(priv); | ||
2602 | @@ -1026,9 +1023,18 @@ static void ipsec_esp_decrypt_swauth_done(struct device *dev, | ||
2603 | ipsec_esp_unmap(dev, edesc, req); | ||
2604 | |||
2605 | if (!err) { | ||
2606 | + char icvdata[SHA512_DIGEST_SIZE]; | ||
2607 | + int nents = edesc->dst_nents ? : 1; | ||
2608 | + unsigned int len = req->assoclen + req->cryptlen; | ||
2609 | + | ||
2610 | /* auth check */ | ||
2611 | - sg = sg_last(req->dst, edesc->dst_nents ? : 1); | ||
2612 | - icv = (char *)sg_virt(sg) + sg->length - authsize; | ||
2613 | + if (nents > 1) { | ||
2614 | + sg_pcopy_to_buffer(req->dst, nents, icvdata, authsize, | ||
2615 | + len - authsize); | ||
2616 | + icv = icvdata; | ||
2617 | + } else { | ||
2618 | + icv = (char *)sg_virt(req->dst) + len - authsize; | ||
2619 | + } | ||
2620 | |||
2621 | if (edesc->dma_len) { | ||
2622 | if (is_sec1) | ||
2623 | @@ -1458,7 +1464,6 @@ static int aead_decrypt(struct aead_request *req) | ||
2624 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); | ||
2625 | struct talitos_private *priv = dev_get_drvdata(ctx->dev); | ||
2626 | struct talitos_edesc *edesc; | ||
2627 | - struct scatterlist *sg; | ||
2628 | void *icvdata; | ||
2629 | |||
2630 | req->cryptlen -= authsize; | ||
2631 | @@ -1493,9 +1498,8 @@ static int aead_decrypt(struct aead_request *req) | ||
2632 | else | ||
2633 | icvdata = &edesc->link_tbl[0]; | ||
2634 | |||
2635 | - sg = sg_last(req->src, edesc->src_nents ? : 1); | ||
2636 | - | ||
2637 | - memcpy(icvdata, (char *)sg_virt(sg) + sg->length - authsize, authsize); | ||
2638 | + sg_pcopy_to_buffer(req->src, edesc->src_nents ? : 1, icvdata, authsize, | ||
2639 | + req->assoclen + req->cryptlen - authsize); | ||
2640 | |||
2641 | return ipsec_esp(edesc, req, ipsec_esp_decrypt_swauth_done); | ||
2642 | } | ||
2643 | @@ -1544,11 +1548,15 @@ static void ablkcipher_done(struct device *dev, | ||
2644 | int err) | ||
2645 | { | ||
2646 | struct ablkcipher_request *areq = context; | ||
2647 | + struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); | ||
2648 | + struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); | ||
2649 | + unsigned int ivsize = crypto_ablkcipher_ivsize(cipher); | ||
2650 | struct talitos_edesc *edesc; | ||
2651 | |||
2652 | edesc = container_of(desc, struct talitos_edesc, desc); | ||
2653 | |||
2654 | common_nonsnoop_unmap(dev, edesc, areq); | ||
2655 | + memcpy(areq->info, ctx->iv, ivsize); | ||
2656 | |||
2657 | kfree(edesc); | ||
2658 | |||
2659 | @@ -3111,7 +3119,10 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, | ||
2660 | alg->cra_priority = t_alg->algt.priority; | ||
2661 | else | ||
2662 | alg->cra_priority = TALITOS_CRA_PRIORITY; | ||
2663 | - alg->cra_alignmask = 0; | ||
2664 | + if (has_ftr_sec1(priv)) | ||
2665 | + alg->cra_alignmask = 3; | ||
2666 | + else | ||
2667 | + alg->cra_alignmask = 0; | ||
2668 | alg->cra_ctxsize = sizeof(struct talitos_ctx); | ||
2669 | alg->cra_flags |= CRYPTO_ALG_KERN_DRIVER_ONLY; | ||
2670 | |||
2671 | diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c | ||
2672 | index 84856ac75a09..9f240b2d85a5 100644 | ||
2673 | --- a/drivers/dma/imx-sdma.c | ||
2674 | +++ b/drivers/dma/imx-sdma.c | ||
2675 | @@ -1821,27 +1821,6 @@ static int sdma_probe(struct platform_device *pdev) | ||
2676 | if (pdata && pdata->script_addrs) | ||
2677 | sdma_add_scripts(sdma, pdata->script_addrs); | ||
2678 | |||
2679 | - if (pdata) { | ||
2680 | - ret = sdma_get_firmware(sdma, pdata->fw_name); | ||
2681 | - if (ret) | ||
2682 | - dev_warn(&pdev->dev, "failed to get firmware from platform data\n"); | ||
2683 | - } else { | ||
2684 | - /* | ||
2685 | - * Because that device tree does not encode ROM script address, | ||
2686 | - * the RAM script in firmware is mandatory for device tree | ||
2687 | - * probe, otherwise it fails. | ||
2688 | - */ | ||
2689 | - ret = of_property_read_string(np, "fsl,sdma-ram-script-name", | ||
2690 | - &fw_name); | ||
2691 | - if (ret) | ||
2692 | - dev_warn(&pdev->dev, "failed to get firmware name\n"); | ||
2693 | - else { | ||
2694 | - ret = sdma_get_firmware(sdma, fw_name); | ||
2695 | - if (ret) | ||
2696 | - dev_warn(&pdev->dev, "failed to get firmware from device tree\n"); | ||
2697 | - } | ||
2698 | - } | ||
2699 | - | ||
2700 | sdma->dma_device.dev = &pdev->dev; | ||
2701 | |||
2702 | sdma->dma_device.device_alloc_chan_resources = sdma_alloc_chan_resources; | ||
2703 | @@ -1883,6 +1862,33 @@ static int sdma_probe(struct platform_device *pdev) | ||
2704 | of_node_put(spba_bus); | ||
2705 | } | ||
2706 | |||
2707 | + /* | ||
2708 | + * Kick off firmware loading as the very last step: | ||
2709 | + * attempt to load firmware only if we're not on the error path, because | ||
2710 | + * the firmware callback requires a fully functional and allocated sdma | ||
2711 | + * instance. | ||
2712 | + */ | ||
2713 | + if (pdata) { | ||
2714 | + ret = sdma_get_firmware(sdma, pdata->fw_name); | ||
2715 | + if (ret) | ||
2716 | + dev_warn(&pdev->dev, "failed to get firmware from platform data\n"); | ||
2717 | + } else { | ||
2718 | + /* | ||
2719 | + * Because that device tree does not encode ROM script address, | ||
2720 | + * the RAM script in firmware is mandatory for device tree | ||
2721 | + * probe, otherwise it fails. | ||
2722 | + */ | ||
2723 | + ret = of_property_read_string(np, "fsl,sdma-ram-script-name", | ||
2724 | + &fw_name); | ||
2725 | + if (ret) { | ||
2726 | + dev_warn(&pdev->dev, "failed to get firmware name\n"); | ||
2727 | + } else { | ||
2728 | + ret = sdma_get_firmware(sdma, fw_name); | ||
2729 | + if (ret) | ||
2730 | + dev_warn(&pdev->dev, "failed to get firmware from device tree\n"); | ||
2731 | + } | ||
2732 | + } | ||
2733 | + | ||
2734 | return 0; | ||
2735 | |||
2736 | err_register: | ||
2737 | diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c | ||
2738 | index 40d792e96b75..d59641194860 100644 | ||
2739 | --- a/drivers/edac/edac_mc_sysfs.c | ||
2740 | +++ b/drivers/edac/edac_mc_sysfs.c | ||
2741 | @@ -26,7 +26,7 @@ | ||
2742 | static int edac_mc_log_ue = 1; | ||
2743 | static int edac_mc_log_ce = 1; | ||
2744 | static int edac_mc_panic_on_ue; | ||
2745 | -static int edac_mc_poll_msec = 1000; | ||
2746 | +static unsigned int edac_mc_poll_msec = 1000; | ||
2747 | |||
2748 | /* Getter functions for above */ | ||
2749 | int edac_mc_get_log_ue(void) | ||
2750 | @@ -45,30 +45,30 @@ int edac_mc_get_panic_on_ue(void) | ||
2751 | } | ||
2752 | |||
2753 | /* this is temporary */ | ||
2754 | -int edac_mc_get_poll_msec(void) | ||
2755 | +unsigned int edac_mc_get_poll_msec(void) | ||
2756 | { | ||
2757 | return edac_mc_poll_msec; | ||
2758 | } | ||
2759 | |||
2760 | static int edac_set_poll_msec(const char *val, struct kernel_param *kp) | ||
2761 | { | ||
2762 | - unsigned long l; | ||
2763 | + unsigned int i; | ||
2764 | int ret; | ||
2765 | |||
2766 | if (!val) | ||
2767 | return -EINVAL; | ||
2768 | |||
2769 | - ret = kstrtoul(val, 0, &l); | ||
2770 | + ret = kstrtouint(val, 0, &i); | ||
2771 | if (ret) | ||
2772 | return ret; | ||
2773 | |||
2774 | - if (l < 1000) | ||
2775 | + if (i < 1000) | ||
2776 | return -EINVAL; | ||
2777 | |||
2778 | - *((unsigned long *)kp->arg) = l; | ||
2779 | + *((unsigned int *)kp->arg) = i; | ||
2780 | |||
2781 | /* notify edac_mc engine to reset the poll period */ | ||
2782 | - edac_mc_reset_delay_period(l); | ||
2783 | + edac_mc_reset_delay_period(i); | ||
2784 | |||
2785 | return 0; | ||
2786 | } | ||
2787 | @@ -82,7 +82,7 @@ MODULE_PARM_DESC(edac_mc_log_ue, | ||
2788 | module_param(edac_mc_log_ce, int, 0644); | ||
2789 | MODULE_PARM_DESC(edac_mc_log_ce, | ||
2790 | "Log correctable error to console: 0=off 1=on"); | ||
2791 | -module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_int, | ||
2792 | +module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_uint, | ||
2793 | &edac_mc_poll_msec, 0644); | ||
2794 | MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds"); | ||
2795 | |||
2796 | @@ -426,6 +426,8 @@ static inline int nr_pages_per_csrow(struct csrow_info *csrow) | ||
2797 | static int edac_create_csrow_object(struct mem_ctl_info *mci, | ||
2798 | struct csrow_info *csrow, int index) | ||
2799 | { | ||
2800 | + int err; | ||
2801 | + | ||
2802 | csrow->dev.type = &csrow_attr_type; | ||
2803 | csrow->dev.bus = mci->bus; | ||
2804 | csrow->dev.groups = csrow_dev_groups; | ||
2805 | @@ -438,7 +440,11 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci, | ||
2806 | edac_dbg(0, "creating (virtual) csrow node %s\n", | ||
2807 | dev_name(&csrow->dev)); | ||
2808 | |||
2809 | - return device_add(&csrow->dev); | ||
2810 | + err = device_add(&csrow->dev); | ||
2811 | + if (err) | ||
2812 | + put_device(&csrow->dev); | ||
2813 | + | ||
2814 | + return err; | ||
2815 | } | ||
2816 | |||
2817 | /* Create a CSROW object under specifed edac_mc_device */ | ||
2818 | diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h | ||
2819 | index cfaacb99c973..c36f9f721fb2 100644 | ||
2820 | --- a/drivers/edac/edac_module.h | ||
2821 | +++ b/drivers/edac/edac_module.h | ||
2822 | @@ -33,7 +33,7 @@ extern int edac_mc_get_log_ue(void); | ||
2823 | extern int edac_mc_get_log_ce(void); | ||
2824 | extern int edac_mc_get_panic_on_ue(void); | ||
2825 | extern int edac_get_poll_msec(void); | ||
2826 | -extern int edac_mc_get_poll_msec(void); | ||
2827 | +extern unsigned int edac_mc_get_poll_msec(void); | ||
2828 | |||
2829 | unsigned edac_dimm_info_location(struct dimm_info *dimm, char *buf, | ||
2830 | unsigned len); | ||
2831 | diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c | ||
2832 | index 038882183bdf..fc841ce24db7 100644 | ||
2833 | --- a/drivers/gpio/gpio-omap.c | ||
2834 | +++ b/drivers/gpio/gpio-omap.c | ||
2835 | @@ -786,9 +786,9 @@ static void omap_gpio_irq_shutdown(struct irq_data *d) | ||
2836 | |||
2837 | raw_spin_lock_irqsave(&bank->lock, flags); | ||
2838 | bank->irq_usage &= ~(BIT(offset)); | ||
2839 | - omap_set_gpio_irqenable(bank, offset, 0); | ||
2840 | - omap_clear_gpio_irqstatus(bank, offset); | ||
2841 | omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); | ||
2842 | + omap_clear_gpio_irqstatus(bank, offset); | ||
2843 | + omap_set_gpio_irqenable(bank, offset, 0); | ||
2844 | if (!LINE_USED(bank->mod_usage, offset)) | ||
2845 | omap_clear_gpio_debounce(bank, offset); | ||
2846 | omap_disable_gpio_module(bank, offset); | ||
2847 | @@ -830,8 +830,8 @@ static void omap_gpio_mask_irq(struct irq_data *d) | ||
2848 | unsigned long flags; | ||
2849 | |||
2850 | raw_spin_lock_irqsave(&bank->lock, flags); | ||
2851 | - omap_set_gpio_irqenable(bank, offset, 0); | ||
2852 | omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); | ||
2853 | + omap_set_gpio_irqenable(bank, offset, 0); | ||
2854 | raw_spin_unlock_irqrestore(&bank->lock, flags); | ||
2855 | } | ||
2856 | |||
2857 | @@ -843,9 +843,6 @@ static void omap_gpio_unmask_irq(struct irq_data *d) | ||
2858 | unsigned long flags; | ||
2859 | |||
2860 | raw_spin_lock_irqsave(&bank->lock, flags); | ||
2861 | - if (trigger) | ||
2862 | - omap_set_gpio_triggering(bank, offset, trigger); | ||
2863 | - | ||
2864 | omap_set_gpio_irqenable(bank, offset, 1); | ||
2865 | |||
2866 | /* | ||
2867 | @@ -853,9 +850,13 @@ static void omap_gpio_unmask_irq(struct irq_data *d) | ||
2868 | * is cleared, thus after the handler has run. OMAP4 needs this done | ||
2869 | * after enabing the interrupt to clear the wakeup status. | ||
2870 | */ | ||
2871 | - if (bank->level_mask & BIT(offset)) | ||
2872 | + if (bank->regs->leveldetect0 && bank->regs->wkup_en && | ||
2873 | + trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) | ||
2874 | omap_clear_gpio_irqstatus(bank, offset); | ||
2875 | |||
2876 | + if (trigger) | ||
2877 | + omap_set_gpio_triggering(bank, offset, trigger); | ||
2878 | + | ||
2879 | raw_spin_unlock_irqrestore(&bank->lock, flags); | ||
2880 | } | ||
2881 | |||
2882 | @@ -1585,6 +1586,8 @@ static struct omap_gpio_reg_offs omap4_gpio_regs = { | ||
2883 | .clr_dataout = OMAP4_GPIO_CLEARDATAOUT, | ||
2884 | .irqstatus = OMAP4_GPIO_IRQSTATUS0, | ||
2885 | .irqstatus2 = OMAP4_GPIO_IRQSTATUS1, | ||
2886 | + .irqstatus_raw0 = OMAP4_GPIO_IRQSTATUSRAW0, | ||
2887 | + .irqstatus_raw1 = OMAP4_GPIO_IRQSTATUSRAW1, | ||
2888 | .irqenable = OMAP4_GPIO_IRQSTATUSSET0, | ||
2889 | .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1, | ||
2890 | .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0, | ||
2891 | diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c | ||
2892 | index 9e2fe12c2858..a3251faa3ed8 100644 | ||
2893 | --- a/drivers/gpio/gpiolib.c | ||
2894 | +++ b/drivers/gpio/gpiolib.c | ||
2895 | @@ -2411,7 +2411,7 @@ static int _gpiod_get_raw_value(const struct gpio_desc *desc) | ||
2896 | int gpiod_get_raw_value(const struct gpio_desc *desc) | ||
2897 | { | ||
2898 | VALIDATE_DESC(desc); | ||
2899 | - /* Should be using gpio_get_value_cansleep() */ | ||
2900 | + /* Should be using gpiod_get_raw_value_cansleep() */ | ||
2901 | WARN_ON(desc->gdev->chip->can_sleep); | ||
2902 | return _gpiod_get_raw_value(desc); | ||
2903 | } | ||
2904 | @@ -2432,7 +2432,7 @@ int gpiod_get_value(const struct gpio_desc *desc) | ||
2905 | int value; | ||
2906 | |||
2907 | VALIDATE_DESC(desc); | ||
2908 | - /* Should be using gpio_get_value_cansleep() */ | ||
2909 | + /* Should be using gpiod_get_value_cansleep() */ | ||
2910 | WARN_ON(desc->gdev->chip->can_sleep); | ||
2911 | |||
2912 | value = _gpiod_get_raw_value(desc); | ||
2913 | @@ -2608,7 +2608,7 @@ void gpiod_set_array_value_complex(bool raw, bool can_sleep, | ||
2914 | void gpiod_set_raw_value(struct gpio_desc *desc, int value) | ||
2915 | { | ||
2916 | VALIDATE_DESC_VOID(desc); | ||
2917 | - /* Should be using gpiod_set_value_cansleep() */ | ||
2918 | + /* Should be using gpiod_set_raw_value_cansleep() */ | ||
2919 | WARN_ON(desc->gdev->chip->can_sleep); | ||
2920 | _gpiod_set_raw_value(desc, value); | ||
2921 | } | ||
2922 | diff --git a/drivers/gpu/drm/bridge/sii902x.c b/drivers/gpu/drm/bridge/sii902x.c | ||
2923 | index 9126d0306ab5..51e2d03995a1 100644 | ||
2924 | --- a/drivers/gpu/drm/bridge/sii902x.c | ||
2925 | +++ b/drivers/gpu/drm/bridge/sii902x.c | ||
2926 | @@ -250,10 +250,11 @@ static void sii902x_bridge_mode_set(struct drm_bridge *bridge, | ||
2927 | struct regmap *regmap = sii902x->regmap; | ||
2928 | u8 buf[HDMI_INFOFRAME_SIZE(AVI)]; | ||
2929 | struct hdmi_avi_infoframe frame; | ||
2930 | + u16 pixel_clock_10kHz = adj->clock / 10; | ||
2931 | int ret; | ||
2932 | |||
2933 | - buf[0] = adj->clock; | ||
2934 | - buf[1] = adj->clock >> 8; | ||
2935 | + buf[0] = pixel_clock_10kHz & 0xff; | ||
2936 | + buf[1] = pixel_clock_10kHz >> 8; | ||
2937 | buf[2] = adj->vrefresh; | ||
2938 | buf[3] = 0x00; | ||
2939 | buf[4] = adj->hdisplay; | ||
2940 | diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c | ||
2941 | index fa3f2f039a74..80993a8734e0 100644 | ||
2942 | --- a/drivers/gpu/drm/bridge/tc358767.c | ||
2943 | +++ b/drivers/gpu/drm/bridge/tc358767.c | ||
2944 | @@ -1153,6 +1153,13 @@ static int tc_connector_get_modes(struct drm_connector *connector) | ||
2945 | struct tc_data *tc = connector_to_tc(connector); | ||
2946 | struct edid *edid; | ||
2947 | unsigned int count; | ||
2948 | + int ret; | ||
2949 | + | ||
2950 | + ret = tc_get_display_props(tc); | ||
2951 | + if (ret < 0) { | ||
2952 | + dev_err(tc->dev, "failed to read display props: %d\n", ret); | ||
2953 | + return 0; | ||
2954 | + } | ||
2955 | |||
2956 | if (tc->panel && tc->panel->funcs && tc->panel->funcs->get_modes) { | ||
2957 | count = tc->panel->funcs->get_modes(tc->panel); | ||
2958 | diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c | ||
2959 | index ecacb22834d7..719345074711 100644 | ||
2960 | --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c | ||
2961 | +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c | ||
2962 | @@ -184,6 +184,25 @@ nvkm_i2c_fini(struct nvkm_subdev *subdev, bool suspend) | ||
2963 | return 0; | ||
2964 | } | ||
2965 | |||
2966 | +static int | ||
2967 | +nvkm_i2c_preinit(struct nvkm_subdev *subdev) | ||
2968 | +{ | ||
2969 | + struct nvkm_i2c *i2c = nvkm_i2c(subdev); | ||
2970 | + struct nvkm_i2c_bus *bus; | ||
2971 | + struct nvkm_i2c_pad *pad; | ||
2972 | + | ||
2973 | + /* | ||
2974 | + * We init our i2c busses as early as possible, since they may be | ||
2975 | + * needed by the vbios init scripts on some cards | ||
2976 | + */ | ||
2977 | + list_for_each_entry(pad, &i2c->pad, head) | ||
2978 | + nvkm_i2c_pad_init(pad); | ||
2979 | + list_for_each_entry(bus, &i2c->bus, head) | ||
2980 | + nvkm_i2c_bus_init(bus); | ||
2981 | + | ||
2982 | + return 0; | ||
2983 | +} | ||
2984 | + | ||
2985 | static int | ||
2986 | nvkm_i2c_init(struct nvkm_subdev *subdev) | ||
2987 | { | ||
2988 | @@ -238,6 +257,7 @@ nvkm_i2c_dtor(struct nvkm_subdev *subdev) | ||
2989 | static const struct nvkm_subdev_func | ||
2990 | nvkm_i2c = { | ||
2991 | .dtor = nvkm_i2c_dtor, | ||
2992 | + .preinit = nvkm_i2c_preinit, | ||
2993 | .init = nvkm_i2c_init, | ||
2994 | .fini = nvkm_i2c_fini, | ||
2995 | .intr = nvkm_i2c_intr, | ||
2996 | diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c | ||
2997 | index 5b2a9f97ff04..68a2b25deb50 100644 | ||
2998 | --- a/drivers/gpu/drm/panel/panel-simple.c | ||
2999 | +++ b/drivers/gpu/drm/panel/panel-simple.c | ||
3000 | @@ -1944,7 +1944,14 @@ static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi) | ||
3001 | dsi->format = desc->format; | ||
3002 | dsi->lanes = desc->lanes; | ||
3003 | |||
3004 | - return mipi_dsi_attach(dsi); | ||
3005 | + err = mipi_dsi_attach(dsi); | ||
3006 | + if (err) { | ||
3007 | + struct panel_simple *panel = dev_get_drvdata(&dsi->dev); | ||
3008 | + | ||
3009 | + drm_panel_remove(&panel->base); | ||
3010 | + } | ||
3011 | + | ||
3012 | + return err; | ||
3013 | } | ||
3014 | |||
3015 | static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi) | ||
3016 | diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c | ||
3017 | index 32d87c6035c9..5bed63eee5f0 100644 | ||
3018 | --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c | ||
3019 | +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c | ||
3020 | @@ -865,7 +865,8 @@ static bool vop_crtc_mode_fixup(struct drm_crtc *crtc, | ||
3021 | struct vop *vop = to_vop(crtc); | ||
3022 | |||
3023 | adjusted_mode->clock = | ||
3024 | - clk_round_rate(vop->dclk, mode->clock * 1000) / 1000; | ||
3025 | + DIV_ROUND_UP(clk_round_rate(vop->dclk, mode->clock * 1000), | ||
3026 | + 1000); | ||
3027 | |||
3028 | return true; | ||
3029 | } | ||
3030 | diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c | ||
3031 | index 54639395aba0..a3559b1a3a0f 100644 | ||
3032 | --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c | ||
3033 | +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c | ||
3034 | @@ -521,6 +521,9 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev, | ||
3035 | ret = wait_event_timeout(vgdev->resp_wq, | ||
3036 | atomic_read(&cache_ent->is_valid), 5 * HZ); | ||
3037 | |||
3038 | + /* is_valid check must proceed before copy of the cache entry. */ | ||
3039 | + smp_rmb(); | ||
3040 | + | ||
3041 | ptr = cache_ent->caps_cache; | ||
3042 | |||
3043 | copy_exit: | ||
3044 | diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c | ||
3045 | index 52436b3c01bb..a1b3ea1ccb65 100644 | ||
3046 | --- a/drivers/gpu/drm/virtio/virtgpu_vq.c | ||
3047 | +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c | ||
3048 | @@ -618,6 +618,8 @@ static void virtio_gpu_cmd_capset_cb(struct virtio_gpu_device *vgdev, | ||
3049 | cache_ent->id == le32_to_cpu(cmd->capset_id)) { | ||
3050 | memcpy(cache_ent->caps_cache, resp->capset_data, | ||
3051 | cache_ent->size); | ||
3052 | + /* Copy must occur before is_valid is signalled. */ | ||
3053 | + smp_wmb(); | ||
3054 | atomic_set(&cache_ent->is_valid, 1); | ||
3055 | break; | ||
3056 | } | ||
3057 | diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c | ||
3058 | index 321eb983c2f5..65d7daf944b0 100644 | ||
3059 | --- a/drivers/gpu/ipu-v3/ipu-ic.c | ||
3060 | +++ b/drivers/gpu/ipu-v3/ipu-ic.c | ||
3061 | @@ -256,7 +256,7 @@ static int init_csc(struct ipu_ic *ic, | ||
3062 | writel(param, base++); | ||
3063 | |||
3064 | param = ((a[0] & 0x1fe0) >> 5) | (params->scale << 8) | | ||
3065 | - (params->sat << 9); | ||
3066 | + (params->sat << 10); | ||
3067 | writel(param, base++); | ||
3068 | |||
3069 | param = ((a[1] & 0x1f) << 27) | ((c[0][1] & 0x1ff) << 18) | | ||
3070 | diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/msu.c | ||
3071 | index aadae9dc2aad..7bdd1bfbeedd 100644 | ||
3072 | --- a/drivers/hwtracing/intel_th/msu.c | ||
3073 | +++ b/drivers/hwtracing/intel_th/msu.c | ||
3074 | @@ -638,7 +638,7 @@ static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size) | ||
3075 | goto err_out; | ||
3076 | |||
3077 | ret = -ENOMEM; | ||
3078 | - page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); | ||
3079 | + page = alloc_pages(GFP_KERNEL | __GFP_ZERO | GFP_DMA32, order); | ||
3080 | if (!page) | ||
3081 | goto err_free_sgt; | ||
3082 | |||
3083 | diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c | ||
3084 | index a8497cfdae6f..7524e17ac966 100644 | ||
3085 | --- a/drivers/i2c/busses/i2c-qup.c | ||
3086 | +++ b/drivers/i2c/busses/i2c-qup.c | ||
3087 | @@ -808,6 +808,8 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg, | ||
3088 | } | ||
3089 | |||
3090 | if (ret || qup->bus_err || qup->qup_err) { | ||
3091 | + reinit_completion(&qup->xfer); | ||
3092 | + | ||
3093 | if (qup_i2c_change_state(qup, QUP_RUN_STATE)) { | ||
3094 | dev_err(qup->dev, "change to run state timed out"); | ||
3095 | goto desc_err; | ||
3096 | diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c | ||
3097 | index 095912fb3201..c3d2400e36b9 100644 | ||
3098 | --- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c | ||
3099 | +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c | ||
3100 | @@ -812,6 +812,8 @@ static int i40iw_query_qp(struct ib_qp *ibqp, | ||
3101 | struct i40iw_qp *iwqp = to_iwqp(ibqp); | ||
3102 | struct i40iw_sc_qp *qp = &iwqp->sc_qp; | ||
3103 | |||
3104 | + attr->qp_state = iwqp->ibqp_state; | ||
3105 | + attr->cur_qp_state = attr->qp_state; | ||
3106 | attr->qp_access_flags = 0; | ||
3107 | attr->cap.max_send_wr = qp->qp_uk.sq_size; | ||
3108 | attr->cap.max_recv_wr = qp->qp_uk.rq_size; | ||
3109 | diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c | ||
3110 | index 297653ab4004..5bfea23f3b60 100644 | ||
3111 | --- a/drivers/infiniband/sw/rxe/rxe_resp.c | ||
3112 | +++ b/drivers/infiniband/sw/rxe/rxe_resp.c | ||
3113 | @@ -432,6 +432,7 @@ static enum resp_states check_rkey(struct rxe_qp *qp, | ||
3114 | qp->resp.va = reth_va(pkt); | ||
3115 | qp->resp.rkey = reth_rkey(pkt); | ||
3116 | qp->resp.resid = reth_len(pkt); | ||
3117 | + qp->resp.length = reth_len(pkt); | ||
3118 | } | ||
3119 | access = (pkt->mask & RXE_READ_MASK) ? IB_ACCESS_REMOTE_READ | ||
3120 | : IB_ACCESS_REMOTE_WRITE; | ||
3121 | @@ -841,7 +842,9 @@ static enum resp_states do_complete(struct rxe_qp *qp, | ||
3122 | pkt->mask & RXE_WRITE_MASK) ? | ||
3123 | IB_WC_RECV_RDMA_WITH_IMM : IB_WC_RECV; | ||
3124 | wc->vendor_err = 0; | ||
3125 | - wc->byte_len = wqe->dma.length - wqe->dma.resid; | ||
3126 | + wc->byte_len = (pkt->mask & RXE_IMMDT_MASK && | ||
3127 | + pkt->mask & RXE_WRITE_MASK) ? | ||
3128 | + qp->resp.length : wqe->dma.length - wqe->dma.resid; | ||
3129 | |||
3130 | /* fields after byte_len are different between kernel and user | ||
3131 | * space | ||
3132 | diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h | ||
3133 | index cac1d52a08f0..47003d2a4a46 100644 | ||
3134 | --- a/drivers/infiniband/sw/rxe/rxe_verbs.h | ||
3135 | +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h | ||
3136 | @@ -209,6 +209,7 @@ struct rxe_resp_info { | ||
3137 | struct rxe_mem *mr; | ||
3138 | u32 resid; | ||
3139 | u32 rkey; | ||
3140 | + u32 length; | ||
3141 | u64 atomic_orig; | ||
3142 | |||
3143 | /* SRQ only */ | ||
3144 | diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c | ||
3145 | index 17c5bc7e8957..45504febbc2a 100644 | ||
3146 | --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c | ||
3147 | +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c | ||
3148 | @@ -1751,6 +1751,7 @@ static int ipoib_get_vf_config(struct net_device *dev, int vf, | ||
3149 | return err; | ||
3150 | |||
3151 | ivf->vf = vf; | ||
3152 | + memcpy(ivf->mac, dev->dev_addr, dev->addr_len); | ||
3153 | |||
3154 | return 0; | ||
3155 | } | ||
3156 | diff --git a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c | ||
3157 | index 339a0e2d2f86..8af736dc4b18 100644 | ||
3158 | --- a/drivers/input/tablet/gtco.c | ||
3159 | +++ b/drivers/input/tablet/gtco.c | ||
3160 | @@ -78,6 +78,7 @@ Scott Hill shill@gtcocalcomp.com | ||
3161 | |||
3162 | /* Max size of a single report */ | ||
3163 | #define REPORT_MAX_SIZE 10 | ||
3164 | +#define MAX_COLLECTION_LEVELS 10 | ||
3165 | |||
3166 | |||
3167 | /* Bitmask whether pen is in range */ | ||
3168 | @@ -223,8 +224,7 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | ||
3169 | char maintype = 'x'; | ||
3170 | char globtype[12]; | ||
3171 | int indent = 0; | ||
3172 | - char indentstr[10] = ""; | ||
3173 | - | ||
3174 | + char indentstr[MAX_COLLECTION_LEVELS + 1] = { 0 }; | ||
3175 | |||
3176 | dev_dbg(ddev, "======>>>>>>PARSE<<<<<<======\n"); | ||
3177 | |||
3178 | @@ -350,6 +350,13 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | ||
3179 | case TAG_MAIN_COL_START: | ||
3180 | maintype = 'S'; | ||
3181 | |||
3182 | + if (indent == MAX_COLLECTION_LEVELS) { | ||
3183 | + dev_err(ddev, "Collection level %d would exceed limit of %d\n", | ||
3184 | + indent + 1, | ||
3185 | + MAX_COLLECTION_LEVELS); | ||
3186 | + break; | ||
3187 | + } | ||
3188 | + | ||
3189 | if (data == 0) { | ||
3190 | dev_dbg(ddev, "======>>>>>> Physical\n"); | ||
3191 | strcpy(globtype, "Physical"); | ||
3192 | @@ -369,8 +376,15 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | ||
3193 | break; | ||
3194 | |||
3195 | case TAG_MAIN_COL_END: | ||
3196 | - dev_dbg(ddev, "<<<<<<======\n"); | ||
3197 | maintype = 'E'; | ||
3198 | + | ||
3199 | + if (indent == 0) { | ||
3200 | + dev_err(ddev, "Collection level already at zero\n"); | ||
3201 | + break; | ||
3202 | + } | ||
3203 | + | ||
3204 | + dev_dbg(ddev, "<<<<<<======\n"); | ||
3205 | + | ||
3206 | indent--; | ||
3207 | for (x = 0; x < indent; x++) | ||
3208 | indentstr[x] = '-'; | ||
3209 | diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c b/drivers/isdn/hardware/mISDN/hfcsusb.c | ||
3210 | index 114f3bcba1b0..c60c7998af17 100644 | ||
3211 | --- a/drivers/isdn/hardware/mISDN/hfcsusb.c | ||
3212 | +++ b/drivers/isdn/hardware/mISDN/hfcsusb.c | ||
3213 | @@ -1963,6 +1963,9 @@ hfcsusb_probe(struct usb_interface *intf, const struct usb_device_id *id) | ||
3214 | |||
3215 | /* get endpoint base */ | ||
3216 | idx = ((ep_addr & 0x7f) - 1) * 2; | ||
3217 | + if (idx > 15) | ||
3218 | + return -EIO; | ||
3219 | + | ||
3220 | if (ep_addr & 0x80) | ||
3221 | idx++; | ||
3222 | attr = ep->desc.bmAttributes; | ||
3223 | diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c | ||
3224 | index 87ef465c6947..c1c43800c4aa 100644 | ||
3225 | --- a/drivers/mailbox/mailbox.c | ||
3226 | +++ b/drivers/mailbox/mailbox.c | ||
3227 | @@ -389,11 +389,13 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, | ||
3228 | |||
3229 | of_property_for_each_string(np, "mbox-names", prop, mbox_name) { | ||
3230 | if (!strncmp(name, mbox_name, strlen(name))) | ||
3231 | - break; | ||
3232 | + return mbox_request_channel(cl, index); | ||
3233 | index++; | ||
3234 | } | ||
3235 | |||
3236 | - return mbox_request_channel(cl, index); | ||
3237 | + dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", | ||
3238 | + __func__, name); | ||
3239 | + return ERR_PTR(-EINVAL); | ||
3240 | } | ||
3241 | EXPORT_SYMBOL_GPL(mbox_request_channel_byname); | ||
3242 | |||
3243 | diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c | ||
3244 | index 9f2588eaaf5f..c5bc3e5e921e 100644 | ||
3245 | --- a/drivers/md/bcache/super.c | ||
3246 | +++ b/drivers/md/bcache/super.c | ||
3247 | @@ -1405,7 +1405,7 @@ static void cache_set_flush(struct closure *cl) | ||
3248 | kobject_put(&c->internal); | ||
3249 | kobject_del(&c->kobj); | ||
3250 | |||
3251 | - if (c->gc_thread) | ||
3252 | + if (!IS_ERR_OR_NULL(c->gc_thread)) | ||
3253 | kthread_stop(c->gc_thread); | ||
3254 | |||
3255 | if (!IS_ERR_OR_NULL(c->root)) | ||
3256 | diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c | ||
3257 | index c837defb5e4d..673ce38735ff 100644 | ||
3258 | --- a/drivers/md/dm-bufio.c | ||
3259 | +++ b/drivers/md/dm-bufio.c | ||
3260 | @@ -1585,9 +1585,7 @@ dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) | ||
3261 | unsigned long freed; | ||
3262 | |||
3263 | c = container_of(shrink, struct dm_bufio_client, shrinker); | ||
3264 | - if (sc->gfp_mask & __GFP_FS) | ||
3265 | - dm_bufio_lock(c); | ||
3266 | - else if (!dm_bufio_trylock(c)) | ||
3267 | + if (!dm_bufio_trylock(c)) | ||
3268 | return SHRINK_STOP; | ||
3269 | |||
3270 | freed = __scan(c, sc->nr_to_scan, sc->gfp_mask); | ||
3271 | diff --git a/drivers/media/dvb-frontends/tua6100.c b/drivers/media/dvb-frontends/tua6100.c | ||
3272 | index 6da12b9e55eb..02c734b8718b 100644 | ||
3273 | --- a/drivers/media/dvb-frontends/tua6100.c | ||
3274 | +++ b/drivers/media/dvb-frontends/tua6100.c | ||
3275 | @@ -80,8 +80,8 @@ static int tua6100_set_params(struct dvb_frontend *fe) | ||
3276 | struct i2c_msg msg1 = { .addr = priv->i2c_address, .flags = 0, .buf = reg1, .len = 4 }; | ||
3277 | struct i2c_msg msg2 = { .addr = priv->i2c_address, .flags = 0, .buf = reg2, .len = 3 }; | ||
3278 | |||
3279 | -#define _R 4 | ||
3280 | -#define _P 32 | ||
3281 | +#define _R_VAL 4 | ||
3282 | +#define _P_VAL 32 | ||
3283 | #define _ri 4000000 | ||
3284 | |||
3285 | // setup register 0 | ||
3286 | @@ -96,14 +96,14 @@ static int tua6100_set_params(struct dvb_frontend *fe) | ||
3287 | else | ||
3288 | reg1[1] = 0x0c; | ||
3289 | |||
3290 | - if (_P == 64) | ||
3291 | + if (_P_VAL == 64) | ||
3292 | reg1[1] |= 0x40; | ||
3293 | if (c->frequency >= 1525000) | ||
3294 | reg1[1] |= 0x80; | ||
3295 | |||
3296 | // register 2 | ||
3297 | - reg2[1] = (_R >> 8) & 0x03; | ||
3298 | - reg2[2] = _R; | ||
3299 | + reg2[1] = (_R_VAL >> 8) & 0x03; | ||
3300 | + reg2[2] = _R_VAL; | ||
3301 | if (c->frequency < 1455000) | ||
3302 | reg2[1] |= 0x1c; | ||
3303 | else if (c->frequency < 1630000) | ||
3304 | @@ -115,18 +115,18 @@ static int tua6100_set_params(struct dvb_frontend *fe) | ||
3305 | * The N divisor ratio (note: c->frequency is in kHz, but we | ||
3306 | * need it in Hz) | ||
3307 | */ | ||
3308 | - prediv = (c->frequency * _R) / (_ri / 1000); | ||
3309 | - div = prediv / _P; | ||
3310 | + prediv = (c->frequency * _R_VAL) / (_ri / 1000); | ||
3311 | + div = prediv / _P_VAL; | ||
3312 | reg1[1] |= (div >> 9) & 0x03; | ||
3313 | reg1[2] = div >> 1; | ||
3314 | reg1[3] = (div << 7); | ||
3315 | - priv->frequency = ((div * _P) * (_ri / 1000)) / _R; | ||
3316 | + priv->frequency = ((div * _P_VAL) * (_ri / 1000)) / _R_VAL; | ||
3317 | |||
3318 | // Finally, calculate and store the value for A | ||
3319 | - reg1[3] |= (prediv - (div*_P)) & 0x7f; | ||
3320 | + reg1[3] |= (prediv - (div*_P_VAL)) & 0x7f; | ||
3321 | |||
3322 | -#undef _R | ||
3323 | -#undef _P | ||
3324 | +#undef _R_VAL | ||
3325 | +#undef _P_VAL | ||
3326 | #undef _ri | ||
3327 | |||
3328 | if (fe->ops.i2c_gate_ctrl) | ||
3329 | diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile | ||
3330 | index 92773b2e6225..bfe0afc209b8 100644 | ||
3331 | --- a/drivers/media/i2c/Makefile | ||
3332 | +++ b/drivers/media/i2c/Makefile | ||
3333 | @@ -29,7 +29,7 @@ obj-$(CONFIG_VIDEO_ADV7393) += adv7393.o | ||
3334 | obj-$(CONFIG_VIDEO_ADV7604) += adv7604.o | ||
3335 | obj-$(CONFIG_VIDEO_ADV7842) += adv7842.o | ||
3336 | obj-$(CONFIG_VIDEO_AD9389B) += ad9389b.o | ||
3337 | -obj-$(CONFIG_VIDEO_ADV7511) += adv7511.o | ||
3338 | +obj-$(CONFIG_VIDEO_ADV7511) += adv7511-v4l2.o | ||
3339 | obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o | ||
3340 | obj-$(CONFIG_VIDEO_VS6624) += vs6624.o | ||
3341 | obj-$(CONFIG_VIDEO_BT819) += bt819.o | ||
3342 | diff --git a/drivers/media/i2c/adv7511-v4l2.c b/drivers/media/i2c/adv7511-v4l2.c | ||
3343 | new file mode 100644 | ||
3344 | index 000000000000..b87c9e7ff146 | ||
3345 | --- /dev/null | ||
3346 | +++ b/drivers/media/i2c/adv7511-v4l2.c | ||
3347 | @@ -0,0 +1,2008 @@ | ||
3348 | +/* | ||
3349 | + * Analog Devices ADV7511 HDMI Transmitter Device Driver | ||
3350 | + * | ||
3351 | + * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | ||
3352 | + * | ||
3353 | + * This program is free software; you may redistribute it and/or modify | ||
3354 | + * it under the terms of the GNU General Public License as published by | ||
3355 | + * the Free Software Foundation; version 2 of the License. | ||
3356 | + * | ||
3357 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
3358 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
3359 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
3360 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
3361 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
3362 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
3363 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
3364 | + * SOFTWARE. | ||
3365 | + */ | ||
3366 | + | ||
3367 | +/* | ||
3368 | + * This file is named adv7511-v4l2.c so it doesn't conflict with the Analog | ||
3369 | + * Device ADV7511 (config fragment CONFIG_DRM_I2C_ADV7511). | ||
3370 | + */ | ||
3371 | + | ||
3372 | + | ||
3373 | +#include <linux/kernel.h> | ||
3374 | +#include <linux/module.h> | ||
3375 | +#include <linux/slab.h> | ||
3376 | +#include <linux/i2c.h> | ||
3377 | +#include <linux/delay.h> | ||
3378 | +#include <linux/videodev2.h> | ||
3379 | +#include <linux/gpio.h> | ||
3380 | +#include <linux/workqueue.h> | ||
3381 | +#include <linux/hdmi.h> | ||
3382 | +#include <linux/v4l2-dv-timings.h> | ||
3383 | +#include <media/v4l2-device.h> | ||
3384 | +#include <media/v4l2-common.h> | ||
3385 | +#include <media/v4l2-ctrls.h> | ||
3386 | +#include <media/v4l2-dv-timings.h> | ||
3387 | +#include <media/i2c/adv7511.h> | ||
3388 | +#include <media/cec.h> | ||
3389 | + | ||
3390 | +static int debug; | ||
3391 | +module_param(debug, int, 0644); | ||
3392 | +MODULE_PARM_DESC(debug, "debug level (0-2)"); | ||
3393 | + | ||
3394 | +MODULE_DESCRIPTION("Analog Devices ADV7511 HDMI Transmitter Device Driver"); | ||
3395 | +MODULE_AUTHOR("Hans Verkuil"); | ||
3396 | +MODULE_LICENSE("GPL v2"); | ||
3397 | + | ||
3398 | +#define MASK_ADV7511_EDID_RDY_INT 0x04 | ||
3399 | +#define MASK_ADV7511_MSEN_INT 0x40 | ||
3400 | +#define MASK_ADV7511_HPD_INT 0x80 | ||
3401 | + | ||
3402 | +#define MASK_ADV7511_HPD_DETECT 0x40 | ||
3403 | +#define MASK_ADV7511_MSEN_DETECT 0x20 | ||
3404 | +#define MASK_ADV7511_EDID_RDY 0x10 | ||
3405 | + | ||
3406 | +#define EDID_MAX_RETRIES (8) | ||
3407 | +#define EDID_DELAY 250 | ||
3408 | +#define EDID_MAX_SEGM 8 | ||
3409 | + | ||
3410 | +#define ADV7511_MAX_WIDTH 1920 | ||
3411 | +#define ADV7511_MAX_HEIGHT 1200 | ||
3412 | +#define ADV7511_MIN_PIXELCLOCK 20000000 | ||
3413 | +#define ADV7511_MAX_PIXELCLOCK 225000000 | ||
3414 | + | ||
3415 | +#define ADV7511_MAX_ADDRS (3) | ||
3416 | + | ||
3417 | +/* | ||
3418 | +********************************************************************** | ||
3419 | +* | ||
3420 | +* Arrays with configuration parameters for the ADV7511 | ||
3421 | +* | ||
3422 | +********************************************************************** | ||
3423 | +*/ | ||
3424 | + | ||
3425 | +struct i2c_reg_value { | ||
3426 | + unsigned char reg; | ||
3427 | + unsigned char value; | ||
3428 | +}; | ||
3429 | + | ||
3430 | +struct adv7511_state_edid { | ||
3431 | + /* total number of blocks */ | ||
3432 | + u32 blocks; | ||
3433 | + /* Number of segments read */ | ||
3434 | + u32 segments; | ||
3435 | + u8 data[EDID_MAX_SEGM * 256]; | ||
3436 | + /* Number of EDID read retries left */ | ||
3437 | + unsigned read_retries; | ||
3438 | + bool complete; | ||
3439 | +}; | ||
3440 | + | ||
3441 | +struct adv7511_state { | ||
3442 | + struct adv7511_platform_data pdata; | ||
3443 | + struct v4l2_subdev sd; | ||
3444 | + struct media_pad pad; | ||
3445 | + struct v4l2_ctrl_handler hdl; | ||
3446 | + int chip_revision; | ||
3447 | + u8 i2c_edid_addr; | ||
3448 | + u8 i2c_pktmem_addr; | ||
3449 | + u8 i2c_cec_addr; | ||
3450 | + | ||
3451 | + struct i2c_client *i2c_cec; | ||
3452 | + struct cec_adapter *cec_adap; | ||
3453 | + u8 cec_addr[ADV7511_MAX_ADDRS]; | ||
3454 | + u8 cec_valid_addrs; | ||
3455 | + bool cec_enabled_adap; | ||
3456 | + | ||
3457 | + /* Is the adv7511 powered on? */ | ||
3458 | + bool power_on; | ||
3459 | + /* Did we receive hotplug and rx-sense signals? */ | ||
3460 | + bool have_monitor; | ||
3461 | + bool enabled_irq; | ||
3462 | + /* timings from s_dv_timings */ | ||
3463 | + struct v4l2_dv_timings dv_timings; | ||
3464 | + u32 fmt_code; | ||
3465 | + u32 colorspace; | ||
3466 | + u32 ycbcr_enc; | ||
3467 | + u32 quantization; | ||
3468 | + u32 xfer_func; | ||
3469 | + u32 content_type; | ||
3470 | + /* controls */ | ||
3471 | + struct v4l2_ctrl *hdmi_mode_ctrl; | ||
3472 | + struct v4l2_ctrl *hotplug_ctrl; | ||
3473 | + struct v4l2_ctrl *rx_sense_ctrl; | ||
3474 | + struct v4l2_ctrl *have_edid0_ctrl; | ||
3475 | + struct v4l2_ctrl *rgb_quantization_range_ctrl; | ||
3476 | + struct v4l2_ctrl *content_type_ctrl; | ||
3477 | + struct i2c_client *i2c_edid; | ||
3478 | + struct i2c_client *i2c_pktmem; | ||
3479 | + struct adv7511_state_edid edid; | ||
3480 | + /* Running counter of the number of detected EDIDs (for debugging) */ | ||
3481 | + unsigned edid_detect_counter; | ||
3482 | + struct workqueue_struct *work_queue; | ||
3483 | + struct delayed_work edid_handler; /* work entry */ | ||
3484 | +}; | ||
3485 | + | ||
3486 | +static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd); | ||
3487 | +static bool adv7511_check_edid_status(struct v4l2_subdev *sd); | ||
3488 | +static void adv7511_setup(struct v4l2_subdev *sd); | ||
3489 | +static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq); | ||
3490 | +static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq); | ||
3491 | + | ||
3492 | + | ||
3493 | +static const struct v4l2_dv_timings_cap adv7511_timings_cap = { | ||
3494 | + .type = V4L2_DV_BT_656_1120, | ||
3495 | + /* keep this initialization for compatibility with GCC < 4.4.6 */ | ||
3496 | + .reserved = { 0 }, | ||
3497 | + V4L2_INIT_BT_TIMINGS(640, ADV7511_MAX_WIDTH, 350, ADV7511_MAX_HEIGHT, | ||
3498 | + ADV7511_MIN_PIXELCLOCK, ADV7511_MAX_PIXELCLOCK, | ||
3499 | + V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT | | ||
3500 | + V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT, | ||
3501 | + V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING | | ||
3502 | + V4L2_DV_BT_CAP_CUSTOM) | ||
3503 | +}; | ||
3504 | + | ||
3505 | +static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd) | ||
3506 | +{ | ||
3507 | + return container_of(sd, struct adv7511_state, sd); | ||
3508 | +} | ||
3509 | + | ||
3510 | +static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) | ||
3511 | +{ | ||
3512 | + return &container_of(ctrl->handler, struct adv7511_state, hdl)->sd; | ||
3513 | +} | ||
3514 | + | ||
3515 | +/* ------------------------ I2C ----------------------------------------------- */ | ||
3516 | + | ||
3517 | +static s32 adv_smbus_read_byte_data_check(struct i2c_client *client, | ||
3518 | + u8 command, bool check) | ||
3519 | +{ | ||
3520 | + union i2c_smbus_data data; | ||
3521 | + | ||
3522 | + if (!i2c_smbus_xfer(client->adapter, client->addr, client->flags, | ||
3523 | + I2C_SMBUS_READ, command, | ||
3524 | + I2C_SMBUS_BYTE_DATA, &data)) | ||
3525 | + return data.byte; | ||
3526 | + if (check) | ||
3527 | + v4l_err(client, "error reading %02x, %02x\n", | ||
3528 | + client->addr, command); | ||
3529 | + return -1; | ||
3530 | +} | ||
3531 | + | ||
3532 | +static s32 adv_smbus_read_byte_data(struct i2c_client *client, u8 command) | ||
3533 | +{ | ||
3534 | + int i; | ||
3535 | + for (i = 0; i < 3; i++) { | ||
3536 | + int ret = adv_smbus_read_byte_data_check(client, command, true); | ||
3537 | + if (ret >= 0) { | ||
3538 | + if (i) | ||
3539 | + v4l_err(client, "read ok after %d retries\n", i); | ||
3540 | + return ret; | ||
3541 | + } | ||
3542 | + } | ||
3543 | + v4l_err(client, "read failed\n"); | ||
3544 | + return -1; | ||
3545 | +} | ||
3546 | + | ||
3547 | +static int adv7511_rd(struct v4l2_subdev *sd, u8 reg) | ||
3548 | +{ | ||
3549 | + struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
3550 | + | ||
3551 | + return adv_smbus_read_byte_data(client, reg); | ||
3552 | +} | ||
3553 | + | ||
3554 | +static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val) | ||
3555 | +{ | ||
3556 | + struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
3557 | + int ret; | ||
3558 | + int i; | ||
3559 | + | ||
3560 | + for (i = 0; i < 3; i++) { | ||
3561 | + ret = i2c_smbus_write_byte_data(client, reg, val); | ||
3562 | + if (ret == 0) | ||
3563 | + return 0; | ||
3564 | + } | ||
3565 | + v4l2_err(sd, "%s: i2c write error\n", __func__); | ||
3566 | + return ret; | ||
3567 | +} | ||
3568 | + | ||
3569 | +/* To set specific bits in the register, a clear-mask is given (to be AND-ed), | ||
3570 | + and then the value-mask (to be OR-ed). */ | ||
3571 | +static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask) | ||
3572 | +{ | ||
3573 | + adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask); | ||
3574 | +} | ||
3575 | + | ||
3576 | +static int adv_smbus_read_i2c_block_data(struct i2c_client *client, | ||
3577 | + u8 command, unsigned length, u8 *values) | ||
3578 | +{ | ||
3579 | + union i2c_smbus_data data; | ||
3580 | + int ret; | ||
3581 | + | ||
3582 | + if (length > I2C_SMBUS_BLOCK_MAX) | ||
3583 | + length = I2C_SMBUS_BLOCK_MAX; | ||
3584 | + data.block[0] = length; | ||
3585 | + | ||
3586 | + ret = i2c_smbus_xfer(client->adapter, client->addr, client->flags, | ||
3587 | + I2C_SMBUS_READ, command, | ||
3588 | + I2C_SMBUS_I2C_BLOCK_DATA, &data); | ||
3589 | + memcpy(values, data.block + 1, length); | ||
3590 | + return ret; | ||
3591 | +} | ||
3592 | + | ||
3593 | +static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf) | ||
3594 | +{ | ||
3595 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3596 | + int i; | ||
3597 | + int err = 0; | ||
3598 | + | ||
3599 | + v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
3600 | + | ||
3601 | + for (i = 0; !err && i < len; i += I2C_SMBUS_BLOCK_MAX) | ||
3602 | + err = adv_smbus_read_i2c_block_data(state->i2c_edid, i, | ||
3603 | + I2C_SMBUS_BLOCK_MAX, buf + i); | ||
3604 | + if (err) | ||
3605 | + v4l2_err(sd, "%s: i2c read error\n", __func__); | ||
3606 | +} | ||
3607 | + | ||
3608 | +static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg) | ||
3609 | +{ | ||
3610 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3611 | + | ||
3612 | + return i2c_smbus_read_byte_data(state->i2c_cec, reg); | ||
3613 | +} | ||
3614 | + | ||
3615 | +static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) | ||
3616 | +{ | ||
3617 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3618 | + int ret; | ||
3619 | + int i; | ||
3620 | + | ||
3621 | + for (i = 0; i < 3; i++) { | ||
3622 | + ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val); | ||
3623 | + if (ret == 0) | ||
3624 | + return 0; | ||
3625 | + } | ||
3626 | + v4l2_err(sd, "%s: I2C Write Problem\n", __func__); | ||
3627 | + return ret; | ||
3628 | +} | ||
3629 | + | ||
3630 | +static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, | ||
3631 | + u8 val) | ||
3632 | +{ | ||
3633 | + return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val); | ||
3634 | +} | ||
3635 | + | ||
3636 | +static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg) | ||
3637 | +{ | ||
3638 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3639 | + | ||
3640 | + return adv_smbus_read_byte_data(state->i2c_pktmem, reg); | ||
3641 | +} | ||
3642 | + | ||
3643 | +static int adv7511_pktmem_wr(struct v4l2_subdev *sd, u8 reg, u8 val) | ||
3644 | +{ | ||
3645 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3646 | + int ret; | ||
3647 | + int i; | ||
3648 | + | ||
3649 | + for (i = 0; i < 3; i++) { | ||
3650 | + ret = i2c_smbus_write_byte_data(state->i2c_pktmem, reg, val); | ||
3651 | + if (ret == 0) | ||
3652 | + return 0; | ||
3653 | + } | ||
3654 | + v4l2_err(sd, "%s: i2c write error\n", __func__); | ||
3655 | + return ret; | ||
3656 | +} | ||
3657 | + | ||
3658 | +/* To set specific bits in the register, a clear-mask is given (to be AND-ed), | ||
3659 | + and then the value-mask (to be OR-ed). */ | ||
3660 | +static inline void adv7511_pktmem_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask) | ||
3661 | +{ | ||
3662 | + adv7511_pktmem_wr(sd, reg, (adv7511_pktmem_rd(sd, reg) & clr_mask) | val_mask); | ||
3663 | +} | ||
3664 | + | ||
3665 | +static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd) | ||
3666 | +{ | ||
3667 | + return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT; | ||
3668 | +} | ||
3669 | + | ||
3670 | +static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd) | ||
3671 | +{ | ||
3672 | + return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT; | ||
3673 | +} | ||
3674 | + | ||
3675 | +static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode) | ||
3676 | +{ | ||
3677 | + adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5); | ||
3678 | +} | ||
3679 | + | ||
3680 | +static void adv7511_csc_coeff(struct v4l2_subdev *sd, | ||
3681 | + u16 A1, u16 A2, u16 A3, u16 A4, | ||
3682 | + u16 B1, u16 B2, u16 B3, u16 B4, | ||
3683 | + u16 C1, u16 C2, u16 C3, u16 C4) | ||
3684 | +{ | ||
3685 | + /* A */ | ||
3686 | + adv7511_wr_and_or(sd, 0x18, 0xe0, A1>>8); | ||
3687 | + adv7511_wr(sd, 0x19, A1); | ||
3688 | + adv7511_wr_and_or(sd, 0x1A, 0xe0, A2>>8); | ||
3689 | + adv7511_wr(sd, 0x1B, A2); | ||
3690 | + adv7511_wr_and_or(sd, 0x1c, 0xe0, A3>>8); | ||
3691 | + adv7511_wr(sd, 0x1d, A3); | ||
3692 | + adv7511_wr_and_or(sd, 0x1e, 0xe0, A4>>8); | ||
3693 | + adv7511_wr(sd, 0x1f, A4); | ||
3694 | + | ||
3695 | + /* B */ | ||
3696 | + adv7511_wr_and_or(sd, 0x20, 0xe0, B1>>8); | ||
3697 | + adv7511_wr(sd, 0x21, B1); | ||
3698 | + adv7511_wr_and_or(sd, 0x22, 0xe0, B2>>8); | ||
3699 | + adv7511_wr(sd, 0x23, B2); | ||
3700 | + adv7511_wr_and_or(sd, 0x24, 0xe0, B3>>8); | ||
3701 | + adv7511_wr(sd, 0x25, B3); | ||
3702 | + adv7511_wr_and_or(sd, 0x26, 0xe0, B4>>8); | ||
3703 | + adv7511_wr(sd, 0x27, B4); | ||
3704 | + | ||
3705 | + /* C */ | ||
3706 | + adv7511_wr_and_or(sd, 0x28, 0xe0, C1>>8); | ||
3707 | + adv7511_wr(sd, 0x29, C1); | ||
3708 | + adv7511_wr_and_or(sd, 0x2A, 0xe0, C2>>8); | ||
3709 | + adv7511_wr(sd, 0x2B, C2); | ||
3710 | + adv7511_wr_and_or(sd, 0x2C, 0xe0, C3>>8); | ||
3711 | + adv7511_wr(sd, 0x2D, C3); | ||
3712 | + adv7511_wr_and_or(sd, 0x2E, 0xe0, C4>>8); | ||
3713 | + adv7511_wr(sd, 0x2F, C4); | ||
3714 | +} | ||
3715 | + | ||
3716 | +static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable) | ||
3717 | +{ | ||
3718 | + if (enable) { | ||
3719 | + u8 csc_mode = 0; | ||
3720 | + adv7511_csc_conversion_mode(sd, csc_mode); | ||
3721 | + adv7511_csc_coeff(sd, | ||
3722 | + 4096-564, 0, 0, 256, | ||
3723 | + 0, 4096-564, 0, 256, | ||
3724 | + 0, 0, 4096-564, 256); | ||
3725 | + /* enable CSC */ | ||
3726 | + adv7511_wr_and_or(sd, 0x18, 0x7f, 0x80); | ||
3727 | + /* AVI infoframe: Limited range RGB (16-235) */ | ||
3728 | + adv7511_wr_and_or(sd, 0x57, 0xf3, 0x04); | ||
3729 | + } else { | ||
3730 | + /* disable CSC */ | ||
3731 | + adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); | ||
3732 | + /* AVI infoframe: Full range RGB (0-255) */ | ||
3733 | + adv7511_wr_and_or(sd, 0x57, 0xf3, 0x08); | ||
3734 | + } | ||
3735 | +} | ||
3736 | + | ||
3737 | +static void adv7511_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl) | ||
3738 | +{ | ||
3739 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3740 | + | ||
3741 | + /* Only makes sense for RGB formats */ | ||
3742 | + if (state->fmt_code != MEDIA_BUS_FMT_RGB888_1X24) { | ||
3743 | + /* so just keep quantization */ | ||
3744 | + adv7511_csc_rgb_full2limit(sd, false); | ||
3745 | + return; | ||
3746 | + } | ||
3747 | + | ||
3748 | + switch (ctrl->val) { | ||
3749 | + case V4L2_DV_RGB_RANGE_AUTO: | ||
3750 | + /* automatic */ | ||
3751 | + if (state->dv_timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) { | ||
3752 | + /* CE format, RGB limited range (16-235) */ | ||
3753 | + adv7511_csc_rgb_full2limit(sd, true); | ||
3754 | + } else { | ||
3755 | + /* not CE format, RGB full range (0-255) */ | ||
3756 | + adv7511_csc_rgb_full2limit(sd, false); | ||
3757 | + } | ||
3758 | + break; | ||
3759 | + case V4L2_DV_RGB_RANGE_LIMITED: | ||
3760 | + /* RGB limited range (16-235) */ | ||
3761 | + adv7511_csc_rgb_full2limit(sd, true); | ||
3762 | + break; | ||
3763 | + case V4L2_DV_RGB_RANGE_FULL: | ||
3764 | + /* RGB full range (0-255) */ | ||
3765 | + adv7511_csc_rgb_full2limit(sd, false); | ||
3766 | + break; | ||
3767 | + } | ||
3768 | +} | ||
3769 | + | ||
3770 | +/* ------------------------------ CTRL OPS ------------------------------ */ | ||
3771 | + | ||
3772 | +static int adv7511_s_ctrl(struct v4l2_ctrl *ctrl) | ||
3773 | +{ | ||
3774 | + struct v4l2_subdev *sd = to_sd(ctrl); | ||
3775 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3776 | + | ||
3777 | + v4l2_dbg(1, debug, sd, "%s: ctrl id: %d, ctrl->val %d\n", __func__, ctrl->id, ctrl->val); | ||
3778 | + | ||
3779 | + if (state->hdmi_mode_ctrl == ctrl) { | ||
3780 | + /* Set HDMI or DVI-D */ | ||
3781 | + adv7511_wr_and_or(sd, 0xaf, 0xfd, ctrl->val == V4L2_DV_TX_MODE_HDMI ? 0x02 : 0x00); | ||
3782 | + return 0; | ||
3783 | + } | ||
3784 | + if (state->rgb_quantization_range_ctrl == ctrl) { | ||
3785 | + adv7511_set_rgb_quantization_mode(sd, ctrl); | ||
3786 | + return 0; | ||
3787 | + } | ||
3788 | + if (state->content_type_ctrl == ctrl) { | ||
3789 | + u8 itc, cn; | ||
3790 | + | ||
3791 | + state->content_type = ctrl->val; | ||
3792 | + itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC; | ||
3793 | + cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS; | ||
3794 | + adv7511_wr_and_or(sd, 0x57, 0x7f, itc << 7); | ||
3795 | + adv7511_wr_and_or(sd, 0x59, 0xcf, cn << 4); | ||
3796 | + return 0; | ||
3797 | + } | ||
3798 | + | ||
3799 | + return -EINVAL; | ||
3800 | +} | ||
3801 | + | ||
3802 | +static const struct v4l2_ctrl_ops adv7511_ctrl_ops = { | ||
3803 | + .s_ctrl = adv7511_s_ctrl, | ||
3804 | +}; | ||
3805 | + | ||
3806 | +/* ---------------------------- CORE OPS ------------------------------------------- */ | ||
3807 | + | ||
3808 | +#ifdef CONFIG_VIDEO_ADV_DEBUG | ||
3809 | +static void adv7511_inv_register(struct v4l2_subdev *sd) | ||
3810 | +{ | ||
3811 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3812 | + | ||
3813 | + v4l2_info(sd, "0x000-0x0ff: Main Map\n"); | ||
3814 | + if (state->i2c_cec) | ||
3815 | + v4l2_info(sd, "0x100-0x1ff: CEC Map\n"); | ||
3816 | +} | ||
3817 | + | ||
3818 | +static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) | ||
3819 | +{ | ||
3820 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3821 | + | ||
3822 | + reg->size = 1; | ||
3823 | + switch (reg->reg >> 8) { | ||
3824 | + case 0: | ||
3825 | + reg->val = adv7511_rd(sd, reg->reg & 0xff); | ||
3826 | + break; | ||
3827 | + case 1: | ||
3828 | + if (state->i2c_cec) { | ||
3829 | + reg->val = adv7511_cec_read(sd, reg->reg & 0xff); | ||
3830 | + break; | ||
3831 | + } | ||
3832 | + /* fall through */ | ||
3833 | + default: | ||
3834 | + v4l2_info(sd, "Register %03llx not supported\n", reg->reg); | ||
3835 | + adv7511_inv_register(sd); | ||
3836 | + break; | ||
3837 | + } | ||
3838 | + return 0; | ||
3839 | +} | ||
3840 | + | ||
3841 | +static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) | ||
3842 | +{ | ||
3843 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3844 | + | ||
3845 | + switch (reg->reg >> 8) { | ||
3846 | + case 0: | ||
3847 | + adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff); | ||
3848 | + break; | ||
3849 | + case 1: | ||
3850 | + if (state->i2c_cec) { | ||
3851 | + adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff); | ||
3852 | + break; | ||
3853 | + } | ||
3854 | + /* fall through */ | ||
3855 | + default: | ||
3856 | + v4l2_info(sd, "Register %03llx not supported\n", reg->reg); | ||
3857 | + adv7511_inv_register(sd); | ||
3858 | + break; | ||
3859 | + } | ||
3860 | + return 0; | ||
3861 | +} | ||
3862 | +#endif | ||
3863 | + | ||
3864 | +struct adv7511_cfg_read_infoframe { | ||
3865 | + const char *desc; | ||
3866 | + u8 present_reg; | ||
3867 | + u8 present_mask; | ||
3868 | + u8 header[3]; | ||
3869 | + u16 payload_addr; | ||
3870 | +}; | ||
3871 | + | ||
3872 | +static u8 hdmi_infoframe_checksum(u8 *ptr, size_t size) | ||
3873 | +{ | ||
3874 | + u8 csum = 0; | ||
3875 | + size_t i; | ||
3876 | + | ||
3877 | + /* compute checksum */ | ||
3878 | + for (i = 0; i < size; i++) | ||
3879 | + csum += ptr[i]; | ||
3880 | + | ||
3881 | + return 256 - csum; | ||
3882 | +} | ||
3883 | + | ||
3884 | +static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri) | ||
3885 | +{ | ||
3886 | + struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
3887 | + struct device *dev = &client->dev; | ||
3888 | + union hdmi_infoframe frame; | ||
3889 | + u8 buffer[32]; | ||
3890 | + u8 len; | ||
3891 | + int i; | ||
3892 | + | ||
3893 | + if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) { | ||
3894 | + v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc); | ||
3895 | + return; | ||
3896 | + } | ||
3897 | + | ||
3898 | + memcpy(buffer, cri->header, sizeof(cri->header)); | ||
3899 | + | ||
3900 | + len = buffer[2]; | ||
3901 | + | ||
3902 | + if (len + 4 > sizeof(buffer)) { | ||
3903 | + v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len); | ||
3904 | + return; | ||
3905 | + } | ||
3906 | + | ||
3907 | + if (cri->payload_addr >= 0x100) { | ||
3908 | + for (i = 0; i < len; i++) | ||
3909 | + buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100); | ||
3910 | + } else { | ||
3911 | + for (i = 0; i < len; i++) | ||
3912 | + buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i); | ||
3913 | + } | ||
3914 | + buffer[3] = 0; | ||
3915 | + buffer[3] = hdmi_infoframe_checksum(buffer, len + 4); | ||
3916 | + | ||
3917 | + if (hdmi_infoframe_unpack(&frame, buffer) < 0) { | ||
3918 | + v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc); | ||
3919 | + return; | ||
3920 | + } | ||
3921 | + | ||
3922 | + hdmi_infoframe_log(KERN_INFO, dev, &frame); | ||
3923 | +} | ||
3924 | + | ||
3925 | +static void adv7511_log_infoframes(struct v4l2_subdev *sd) | ||
3926 | +{ | ||
3927 | + static const struct adv7511_cfg_read_infoframe cri[] = { | ||
3928 | + { "AVI", 0x44, 0x10, { 0x82, 2, 13 }, 0x55 }, | ||
3929 | + { "Audio", 0x44, 0x08, { 0x84, 1, 10 }, 0x73 }, | ||
3930 | + { "SDP", 0x40, 0x40, { 0x83, 1, 25 }, 0x103 }, | ||
3931 | + }; | ||
3932 | + int i; | ||
3933 | + | ||
3934 | + for (i = 0; i < ARRAY_SIZE(cri); i++) | ||
3935 | + log_infoframe(sd, &cri[i]); | ||
3936 | +} | ||
3937 | + | ||
3938 | +static int adv7511_log_status(struct v4l2_subdev *sd) | ||
3939 | +{ | ||
3940 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
3941 | + struct adv7511_state_edid *edid = &state->edid; | ||
3942 | + int i; | ||
3943 | + | ||
3944 | + static const char * const states[] = { | ||
3945 | + "in reset", | ||
3946 | + "reading EDID", | ||
3947 | + "idle", | ||
3948 | + "initializing HDCP", | ||
3949 | + "HDCP enabled", | ||
3950 | + "initializing HDCP repeater", | ||
3951 | + "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" | ||
3952 | + }; | ||
3953 | + static const char * const errors[] = { | ||
3954 | + "no error", | ||
3955 | + "bad receiver BKSV", | ||
3956 | + "Ri mismatch", | ||
3957 | + "Pj mismatch", | ||
3958 | + "i2c error", | ||
3959 | + "timed out", | ||
3960 | + "max repeater cascade exceeded", | ||
3961 | + "hash check failed", | ||
3962 | + "too many devices", | ||
3963 | + "9", "A", "B", "C", "D", "E", "F" | ||
3964 | + }; | ||
3965 | + | ||
3966 | + v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off"); | ||
3967 | + v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n", | ||
3968 | + (adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT) ? "detected" : "no", | ||
3969 | + (adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT) ? "detected" : "no", | ||
3970 | + edid->segments ? "found" : "no", | ||
3971 | + edid->blocks); | ||
3972 | + v4l2_info(sd, "%s output %s\n", | ||
3973 | + (adv7511_rd(sd, 0xaf) & 0x02) ? | ||
3974 | + "HDMI" : "DVI-D", | ||
3975 | + (adv7511_rd(sd, 0xa1) & 0x3c) ? | ||
3976 | + "disabled" : "enabled"); | ||
3977 | + v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n", | ||
3978 | + states[adv7511_rd(sd, 0xc8) & 0xf], | ||
3979 | + errors[adv7511_rd(sd, 0xc8) >> 4], state->edid_detect_counter, | ||
3980 | + adv7511_rd(sd, 0x94), adv7511_rd(sd, 0x96)); | ||
3981 | + v4l2_info(sd, "RGB quantization: %s range\n", adv7511_rd(sd, 0x18) & 0x80 ? "limited" : "full"); | ||
3982 | + if (adv7511_rd(sd, 0xaf) & 0x02) { | ||
3983 | + /* HDMI only */ | ||
3984 | + u8 manual_cts = adv7511_rd(sd, 0x0a) & 0x80; | ||
3985 | + u32 N = (adv7511_rd(sd, 0x01) & 0xf) << 16 | | ||
3986 | + adv7511_rd(sd, 0x02) << 8 | | ||
3987 | + adv7511_rd(sd, 0x03); | ||
3988 | + u8 vic_detect = adv7511_rd(sd, 0x3e) >> 2; | ||
3989 | + u8 vic_sent = adv7511_rd(sd, 0x3d) & 0x3f; | ||
3990 | + u32 CTS; | ||
3991 | + | ||
3992 | + if (manual_cts) | ||
3993 | + CTS = (adv7511_rd(sd, 0x07) & 0xf) << 16 | | ||
3994 | + adv7511_rd(sd, 0x08) << 8 | | ||
3995 | + adv7511_rd(sd, 0x09); | ||
3996 | + else | ||
3997 | + CTS = (adv7511_rd(sd, 0x04) & 0xf) << 16 | | ||
3998 | + adv7511_rd(sd, 0x05) << 8 | | ||
3999 | + adv7511_rd(sd, 0x06); | ||
4000 | + v4l2_info(sd, "CTS %s mode: N %d, CTS %d\n", | ||
4001 | + manual_cts ? "manual" : "automatic", N, CTS); | ||
4002 | + v4l2_info(sd, "VIC: detected %d, sent %d\n", | ||
4003 | + vic_detect, vic_sent); | ||
4004 | + adv7511_log_infoframes(sd); | ||
4005 | + } | ||
4006 | + if (state->dv_timings.type == V4L2_DV_BT_656_1120) | ||
4007 | + v4l2_print_dv_timings(sd->name, "timings: ", | ||
4008 | + &state->dv_timings, false); | ||
4009 | + else | ||
4010 | + v4l2_info(sd, "no timings set\n"); | ||
4011 | + v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr); | ||
4012 | + | ||
4013 | + if (state->i2c_cec == NULL) | ||
4014 | + return 0; | ||
4015 | + | ||
4016 | + v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr); | ||
4017 | + | ||
4018 | + v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ? | ||
4019 | + "enabled" : "disabled"); | ||
4020 | + if (state->cec_enabled_adap) { | ||
4021 | + for (i = 0; i < ADV7511_MAX_ADDRS; i++) { | ||
4022 | + bool is_valid = state->cec_valid_addrs & (1 << i); | ||
4023 | + | ||
4024 | + if (is_valid) | ||
4025 | + v4l2_info(sd, "CEC Logical Address: 0x%x\n", | ||
4026 | + state->cec_addr[i]); | ||
4027 | + } | ||
4028 | + } | ||
4029 | + v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr); | ||
4030 | + return 0; | ||
4031 | +} | ||
4032 | + | ||
4033 | +/* Power up/down adv7511 */ | ||
4034 | +static int adv7511_s_power(struct v4l2_subdev *sd, int on) | ||
4035 | +{ | ||
4036 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4037 | + const int retries = 20; | ||
4038 | + int i; | ||
4039 | + | ||
4040 | + v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off"); | ||
4041 | + | ||
4042 | + state->power_on = on; | ||
4043 | + | ||
4044 | + if (!on) { | ||
4045 | + /* Power down */ | ||
4046 | + adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); | ||
4047 | + return true; | ||
4048 | + } | ||
4049 | + | ||
4050 | + /* Power up */ | ||
4051 | + /* The adv7511 does not always come up immediately. | ||
4052 | + Retry multiple times. */ | ||
4053 | + for (i = 0; i < retries; i++) { | ||
4054 | + adv7511_wr_and_or(sd, 0x41, 0xbf, 0x0); | ||
4055 | + if ((adv7511_rd(sd, 0x41) & 0x40) == 0) | ||
4056 | + break; | ||
4057 | + adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); | ||
4058 | + msleep(10); | ||
4059 | + } | ||
4060 | + if (i == retries) { | ||
4061 | + v4l2_dbg(1, debug, sd, "%s: failed to powerup the adv7511!\n", __func__); | ||
4062 | + adv7511_s_power(sd, 0); | ||
4063 | + return false; | ||
4064 | + } | ||
4065 | + if (i > 1) | ||
4066 | + v4l2_dbg(1, debug, sd, "%s: needed %d retries to powerup the adv7511\n", __func__, i); | ||
4067 | + | ||
4068 | + /* Reserved registers that must be set */ | ||
4069 | + adv7511_wr(sd, 0x98, 0x03); | ||
4070 | + adv7511_wr_and_or(sd, 0x9a, 0xfe, 0x70); | ||
4071 | + adv7511_wr(sd, 0x9c, 0x30); | ||
4072 | + adv7511_wr_and_or(sd, 0x9d, 0xfc, 0x01); | ||
4073 | + adv7511_wr(sd, 0xa2, 0xa4); | ||
4074 | + adv7511_wr(sd, 0xa3, 0xa4); | ||
4075 | + adv7511_wr(sd, 0xe0, 0xd0); | ||
4076 | + adv7511_wr(sd, 0xf9, 0x00); | ||
4077 | + | ||
4078 | + adv7511_wr(sd, 0x43, state->i2c_edid_addr); | ||
4079 | + adv7511_wr(sd, 0x45, state->i2c_pktmem_addr); | ||
4080 | + | ||
4081 | + /* Set number of attempts to read the EDID */ | ||
4082 | + adv7511_wr(sd, 0xc9, 0xf); | ||
4083 | + return true; | ||
4084 | +} | ||
4085 | + | ||
4086 | +#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) | ||
4087 | +static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) | ||
4088 | +{ | ||
4089 | + struct adv7511_state *state = adap->priv; | ||
4090 | + struct v4l2_subdev *sd = &state->sd; | ||
4091 | + | ||
4092 | + if (state->i2c_cec == NULL) | ||
4093 | + return -EIO; | ||
4094 | + | ||
4095 | + if (!state->cec_enabled_adap && enable) { | ||
4096 | + /* power up cec section */ | ||
4097 | + adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01); | ||
4098 | + /* legacy mode and clear all rx buffers */ | ||
4099 | + adv7511_cec_write(sd, 0x4a, 0x07); | ||
4100 | + adv7511_cec_write(sd, 0x4a, 0); | ||
4101 | + adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */ | ||
4102 | + /* enabled irqs: */ | ||
4103 | + /* tx: ready */ | ||
4104 | + /* tx: arbitration lost */ | ||
4105 | + /* tx: retry timeout */ | ||
4106 | + /* rx: ready 1 */ | ||
4107 | + if (state->enabled_irq) | ||
4108 | + adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39); | ||
4109 | + } else if (state->cec_enabled_adap && !enable) { | ||
4110 | + if (state->enabled_irq) | ||
4111 | + adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00); | ||
4112 | + /* disable address mask 1-3 */ | ||
4113 | + adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00); | ||
4114 | + /* power down cec section */ | ||
4115 | + adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00); | ||
4116 | + state->cec_valid_addrs = 0; | ||
4117 | + } | ||
4118 | + state->cec_enabled_adap = enable; | ||
4119 | + return 0; | ||
4120 | +} | ||
4121 | + | ||
4122 | +static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr) | ||
4123 | +{ | ||
4124 | + struct adv7511_state *state = adap->priv; | ||
4125 | + struct v4l2_subdev *sd = &state->sd; | ||
4126 | + unsigned int i, free_idx = ADV7511_MAX_ADDRS; | ||
4127 | + | ||
4128 | + if (!state->cec_enabled_adap) | ||
4129 | + return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO; | ||
4130 | + | ||
4131 | + if (addr == CEC_LOG_ADDR_INVALID) { | ||
4132 | + adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0); | ||
4133 | + state->cec_valid_addrs = 0; | ||
4134 | + return 0; | ||
4135 | + } | ||
4136 | + | ||
4137 | + for (i = 0; i < ADV7511_MAX_ADDRS; i++) { | ||
4138 | + bool is_valid = state->cec_valid_addrs & (1 << i); | ||
4139 | + | ||
4140 | + if (free_idx == ADV7511_MAX_ADDRS && !is_valid) | ||
4141 | + free_idx = i; | ||
4142 | + if (is_valid && state->cec_addr[i] == addr) | ||
4143 | + return 0; | ||
4144 | + } | ||
4145 | + if (i == ADV7511_MAX_ADDRS) { | ||
4146 | + i = free_idx; | ||
4147 | + if (i == ADV7511_MAX_ADDRS) | ||
4148 | + return -ENXIO; | ||
4149 | + } | ||
4150 | + state->cec_addr[i] = addr; | ||
4151 | + state->cec_valid_addrs |= 1 << i; | ||
4152 | + | ||
4153 | + switch (i) { | ||
4154 | + case 0: | ||
4155 | + /* enable address mask 0 */ | ||
4156 | + adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10); | ||
4157 | + /* set address for mask 0 */ | ||
4158 | + adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr); | ||
4159 | + break; | ||
4160 | + case 1: | ||
4161 | + /* enable address mask 1 */ | ||
4162 | + adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20); | ||
4163 | + /* set address for mask 1 */ | ||
4164 | + adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4); | ||
4165 | + break; | ||
4166 | + case 2: | ||
4167 | + /* enable address mask 2 */ | ||
4168 | + adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40); | ||
4169 | + /* set address for mask 1 */ | ||
4170 | + adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr); | ||
4171 | + break; | ||
4172 | + } | ||
4173 | + return 0; | ||
4174 | +} | ||
4175 | + | ||
4176 | +static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, | ||
4177 | + u32 signal_free_time, struct cec_msg *msg) | ||
4178 | +{ | ||
4179 | + struct adv7511_state *state = adap->priv; | ||
4180 | + struct v4l2_subdev *sd = &state->sd; | ||
4181 | + u8 len = msg->len; | ||
4182 | + unsigned int i; | ||
4183 | + | ||
4184 | + v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len); | ||
4185 | + | ||
4186 | + if (len > 16) { | ||
4187 | + v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len); | ||
4188 | + return -EINVAL; | ||
4189 | + } | ||
4190 | + | ||
4191 | + /* | ||
4192 | + * The number of retries is the number of attempts - 1, but retry | ||
4193 | + * at least once. It's not clear if a value of 0 is allowed, so | ||
4194 | + * let's do at least one retry. | ||
4195 | + */ | ||
4196 | + adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4); | ||
4197 | + | ||
4198 | + /* blocking, clear cec tx irq status */ | ||
4199 | + adv7511_wr_and_or(sd, 0x97, 0xc7, 0x38); | ||
4200 | + | ||
4201 | + /* write data */ | ||
4202 | + for (i = 0; i < len; i++) | ||
4203 | + adv7511_cec_write(sd, i, msg->msg[i]); | ||
4204 | + | ||
4205 | + /* set length (data + header) */ | ||
4206 | + adv7511_cec_write(sd, 0x10, len); | ||
4207 | + /* start transmit, enable tx */ | ||
4208 | + adv7511_cec_write(sd, 0x11, 0x01); | ||
4209 | + return 0; | ||
4210 | +} | ||
4211 | + | ||
4212 | +static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status) | ||
4213 | +{ | ||
4214 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4215 | + | ||
4216 | + if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) { | ||
4217 | + v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__); | ||
4218 | + return; | ||
4219 | + } | ||
4220 | + | ||
4221 | + if (tx_raw_status & 0x10) { | ||
4222 | + v4l2_dbg(1, debug, sd, | ||
4223 | + "%s: tx raw: arbitration lost\n", __func__); | ||
4224 | + cec_transmit_done(state->cec_adap, CEC_TX_STATUS_ARB_LOST, | ||
4225 | + 1, 0, 0, 0); | ||
4226 | + return; | ||
4227 | + } | ||
4228 | + if (tx_raw_status & 0x08) { | ||
4229 | + u8 status; | ||
4230 | + u8 nack_cnt; | ||
4231 | + u8 low_drive_cnt; | ||
4232 | + | ||
4233 | + v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__); | ||
4234 | + /* | ||
4235 | + * We set this status bit since this hardware performs | ||
4236 | + * retransmissions. | ||
4237 | + */ | ||
4238 | + status = CEC_TX_STATUS_MAX_RETRIES; | ||
4239 | + nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf; | ||
4240 | + if (nack_cnt) | ||
4241 | + status |= CEC_TX_STATUS_NACK; | ||
4242 | + low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4; | ||
4243 | + if (low_drive_cnt) | ||
4244 | + status |= CEC_TX_STATUS_LOW_DRIVE; | ||
4245 | + cec_transmit_done(state->cec_adap, status, | ||
4246 | + 0, nack_cnt, low_drive_cnt, 0); | ||
4247 | + return; | ||
4248 | + } | ||
4249 | + if (tx_raw_status & 0x20) { | ||
4250 | + v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__); | ||
4251 | + cec_transmit_done(state->cec_adap, CEC_TX_STATUS_OK, 0, 0, 0, 0); | ||
4252 | + return; | ||
4253 | + } | ||
4254 | +} | ||
4255 | + | ||
4256 | +static const struct cec_adap_ops adv7511_cec_adap_ops = { | ||
4257 | + .adap_enable = adv7511_cec_adap_enable, | ||
4258 | + .adap_log_addr = adv7511_cec_adap_log_addr, | ||
4259 | + .adap_transmit = adv7511_cec_adap_transmit, | ||
4260 | +}; | ||
4261 | +#endif | ||
4262 | + | ||
4263 | +/* Enable interrupts */ | ||
4264 | +static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable) | ||
4265 | +{ | ||
4266 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4267 | + u8 irqs = MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT; | ||
4268 | + u8 irqs_rd; | ||
4269 | + int retries = 100; | ||
4270 | + | ||
4271 | + v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable"); | ||
4272 | + | ||
4273 | + if (state->enabled_irq == enable) | ||
4274 | + return; | ||
4275 | + state->enabled_irq = enable; | ||
4276 | + | ||
4277 | + /* The datasheet says that the EDID ready interrupt should be | ||
4278 | + disabled if there is no hotplug. */ | ||
4279 | + if (!enable) | ||
4280 | + irqs = 0; | ||
4281 | + else if (adv7511_have_hotplug(sd)) | ||
4282 | + irqs |= MASK_ADV7511_EDID_RDY_INT; | ||
4283 | + | ||
4284 | + adv7511_wr_and_or(sd, 0x95, 0xc0, | ||
4285 | + (state->cec_enabled_adap && enable) ? 0x39 : 0x00); | ||
4286 | + | ||
4287 | + /* | ||
4288 | + * This i2c write can fail (approx. 1 in 1000 writes). But it | ||
4289 | + * is essential that this register is correct, so retry it | ||
4290 | + * multiple times. | ||
4291 | + * | ||
4292 | + * Note that the i2c write does not report an error, but the readback | ||
4293 | + * clearly shows the wrong value. | ||
4294 | + */ | ||
4295 | + do { | ||
4296 | + adv7511_wr(sd, 0x94, irqs); | ||
4297 | + irqs_rd = adv7511_rd(sd, 0x94); | ||
4298 | + } while (retries-- && irqs_rd != irqs); | ||
4299 | + | ||
4300 | + if (irqs_rd == irqs) | ||
4301 | + return; | ||
4302 | + v4l2_err(sd, "Could not set interrupts: hw failure?\n"); | ||
4303 | +} | ||
4304 | + | ||
4305 | +/* Interrupt handler */ | ||
4306 | +static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled) | ||
4307 | +{ | ||
4308 | + u8 irq_status; | ||
4309 | + u8 cec_irq; | ||
4310 | + | ||
4311 | + /* disable interrupts to prevent a race condition */ | ||
4312 | + adv7511_set_isr(sd, false); | ||
4313 | + irq_status = adv7511_rd(sd, 0x96); | ||
4314 | + cec_irq = adv7511_rd(sd, 0x97); | ||
4315 | + /* clear detected interrupts */ | ||
4316 | + adv7511_wr(sd, 0x96, irq_status); | ||
4317 | + adv7511_wr(sd, 0x97, cec_irq); | ||
4318 | + | ||
4319 | + v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__, | ||
4320 | + irq_status, cec_irq); | ||
4321 | + | ||
4322 | + if (irq_status & (MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT)) | ||
4323 | + adv7511_check_monitor_present_status(sd); | ||
4324 | + if (irq_status & MASK_ADV7511_EDID_RDY_INT) | ||
4325 | + adv7511_check_edid_status(sd); | ||
4326 | + | ||
4327 | +#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) | ||
4328 | + if (cec_irq & 0x38) | ||
4329 | + adv_cec_tx_raw_status(sd, cec_irq); | ||
4330 | + | ||
4331 | + if (cec_irq & 1) { | ||
4332 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4333 | + struct cec_msg msg; | ||
4334 | + | ||
4335 | + msg.len = adv7511_cec_read(sd, 0x25) & 0x1f; | ||
4336 | + | ||
4337 | + v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__, | ||
4338 | + msg.len); | ||
4339 | + | ||
4340 | + if (msg.len > 16) | ||
4341 | + msg.len = 16; | ||
4342 | + | ||
4343 | + if (msg.len) { | ||
4344 | + u8 i; | ||
4345 | + | ||
4346 | + for (i = 0; i < msg.len; i++) | ||
4347 | + msg.msg[i] = adv7511_cec_read(sd, i + 0x15); | ||
4348 | + | ||
4349 | + adv7511_cec_write(sd, 0x4a, 1); /* toggle to re-enable rx 1 */ | ||
4350 | + adv7511_cec_write(sd, 0x4a, 0); | ||
4351 | + cec_received_msg(state->cec_adap, &msg); | ||
4352 | + } | ||
4353 | + } | ||
4354 | +#endif | ||
4355 | + | ||
4356 | + /* enable interrupts */ | ||
4357 | + adv7511_set_isr(sd, true); | ||
4358 | + | ||
4359 | + if (handled) | ||
4360 | + *handled = true; | ||
4361 | + return 0; | ||
4362 | +} | ||
4363 | + | ||
4364 | +static const struct v4l2_subdev_core_ops adv7511_core_ops = { | ||
4365 | + .log_status = adv7511_log_status, | ||
4366 | +#ifdef CONFIG_VIDEO_ADV_DEBUG | ||
4367 | + .g_register = adv7511_g_register, | ||
4368 | + .s_register = adv7511_s_register, | ||
4369 | +#endif | ||
4370 | + .s_power = adv7511_s_power, | ||
4371 | + .interrupt_service_routine = adv7511_isr, | ||
4372 | +}; | ||
4373 | + | ||
4374 | +/* ------------------------------ VIDEO OPS ------------------------------ */ | ||
4375 | + | ||
4376 | +/* Enable/disable adv7511 output */ | ||
4377 | +static int adv7511_s_stream(struct v4l2_subdev *sd, int enable) | ||
4378 | +{ | ||
4379 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4380 | + | ||
4381 | + v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); | ||
4382 | + adv7511_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c)); | ||
4383 | + if (enable) { | ||
4384 | + adv7511_check_monitor_present_status(sd); | ||
4385 | + } else { | ||
4386 | + adv7511_s_power(sd, 0); | ||
4387 | + state->have_monitor = false; | ||
4388 | + } | ||
4389 | + return 0; | ||
4390 | +} | ||
4391 | + | ||
4392 | +static int adv7511_s_dv_timings(struct v4l2_subdev *sd, | ||
4393 | + struct v4l2_dv_timings *timings) | ||
4394 | +{ | ||
4395 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4396 | + struct v4l2_bt_timings *bt = &timings->bt; | ||
4397 | + u32 fps; | ||
4398 | + | ||
4399 | + v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
4400 | + | ||
4401 | + /* quick sanity check */ | ||
4402 | + if (!v4l2_valid_dv_timings(timings, &adv7511_timings_cap, NULL, NULL)) | ||
4403 | + return -EINVAL; | ||
4404 | + | ||
4405 | + /* Fill the optional fields .standards and .flags in struct v4l2_dv_timings | ||
4406 | + if the format is one of the CEA or DMT timings. */ | ||
4407 | + v4l2_find_dv_timings_cap(timings, &adv7511_timings_cap, 0, NULL, NULL); | ||
4408 | + | ||
4409 | + /* save timings */ | ||
4410 | + state->dv_timings = *timings; | ||
4411 | + | ||
4412 | + /* set h/vsync polarities */ | ||
4413 | + adv7511_wr_and_or(sd, 0x17, 0x9f, | ||
4414 | + ((bt->polarities & V4L2_DV_VSYNC_POS_POL) ? 0 : 0x40) | | ||
4415 | + ((bt->polarities & V4L2_DV_HSYNC_POS_POL) ? 0 : 0x20)); | ||
4416 | + | ||
4417 | + fps = (u32)bt->pixelclock / (V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt)); | ||
4418 | + switch (fps) { | ||
4419 | + case 24: | ||
4420 | + adv7511_wr_and_or(sd, 0xfb, 0xf9, 1 << 1); | ||
4421 | + break; | ||
4422 | + case 25: | ||
4423 | + adv7511_wr_and_or(sd, 0xfb, 0xf9, 2 << 1); | ||
4424 | + break; | ||
4425 | + case 30: | ||
4426 | + adv7511_wr_and_or(sd, 0xfb, 0xf9, 3 << 1); | ||
4427 | + break; | ||
4428 | + default: | ||
4429 | + adv7511_wr_and_or(sd, 0xfb, 0xf9, 0); | ||
4430 | + break; | ||
4431 | + } | ||
4432 | + | ||
4433 | + /* update quantization range based on new dv_timings */ | ||
4434 | + adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); | ||
4435 | + | ||
4436 | + return 0; | ||
4437 | +} | ||
4438 | + | ||
4439 | +static int adv7511_g_dv_timings(struct v4l2_subdev *sd, | ||
4440 | + struct v4l2_dv_timings *timings) | ||
4441 | +{ | ||
4442 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4443 | + | ||
4444 | + v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
4445 | + | ||
4446 | + if (!timings) | ||
4447 | + return -EINVAL; | ||
4448 | + | ||
4449 | + *timings = state->dv_timings; | ||
4450 | + | ||
4451 | + return 0; | ||
4452 | +} | ||
4453 | + | ||
4454 | +static int adv7511_enum_dv_timings(struct v4l2_subdev *sd, | ||
4455 | + struct v4l2_enum_dv_timings *timings) | ||
4456 | +{ | ||
4457 | + if (timings->pad != 0) | ||
4458 | + return -EINVAL; | ||
4459 | + | ||
4460 | + return v4l2_enum_dv_timings_cap(timings, &adv7511_timings_cap, NULL, NULL); | ||
4461 | +} | ||
4462 | + | ||
4463 | +static int adv7511_dv_timings_cap(struct v4l2_subdev *sd, | ||
4464 | + struct v4l2_dv_timings_cap *cap) | ||
4465 | +{ | ||
4466 | + if (cap->pad != 0) | ||
4467 | + return -EINVAL; | ||
4468 | + | ||
4469 | + *cap = adv7511_timings_cap; | ||
4470 | + return 0; | ||
4471 | +} | ||
4472 | + | ||
4473 | +static const struct v4l2_subdev_video_ops adv7511_video_ops = { | ||
4474 | + .s_stream = adv7511_s_stream, | ||
4475 | + .s_dv_timings = adv7511_s_dv_timings, | ||
4476 | + .g_dv_timings = adv7511_g_dv_timings, | ||
4477 | +}; | ||
4478 | + | ||
4479 | +/* ------------------------------ AUDIO OPS ------------------------------ */ | ||
4480 | +static int adv7511_s_audio_stream(struct v4l2_subdev *sd, int enable) | ||
4481 | +{ | ||
4482 | + v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); | ||
4483 | + | ||
4484 | + if (enable) | ||
4485 | + adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x80); | ||
4486 | + else | ||
4487 | + adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x40); | ||
4488 | + | ||
4489 | + return 0; | ||
4490 | +} | ||
4491 | + | ||
4492 | +static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq) | ||
4493 | +{ | ||
4494 | + u32 N; | ||
4495 | + | ||
4496 | + switch (freq) { | ||
4497 | + case 32000: N = 4096; break; | ||
4498 | + case 44100: N = 6272; break; | ||
4499 | + case 48000: N = 6144; break; | ||
4500 | + case 88200: N = 12544; break; | ||
4501 | + case 96000: N = 12288; break; | ||
4502 | + case 176400: N = 25088; break; | ||
4503 | + case 192000: N = 24576; break; | ||
4504 | + default: | ||
4505 | + return -EINVAL; | ||
4506 | + } | ||
4507 | + | ||
4508 | + /* Set N (used with CTS to regenerate the audio clock) */ | ||
4509 | + adv7511_wr(sd, 0x01, (N >> 16) & 0xf); | ||
4510 | + adv7511_wr(sd, 0x02, (N >> 8) & 0xff); | ||
4511 | + adv7511_wr(sd, 0x03, N & 0xff); | ||
4512 | + | ||
4513 | + return 0; | ||
4514 | +} | ||
4515 | + | ||
4516 | +static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq) | ||
4517 | +{ | ||
4518 | + u32 i2s_sf; | ||
4519 | + | ||
4520 | + switch (freq) { | ||
4521 | + case 32000: i2s_sf = 0x30; break; | ||
4522 | + case 44100: i2s_sf = 0x00; break; | ||
4523 | + case 48000: i2s_sf = 0x20; break; | ||
4524 | + case 88200: i2s_sf = 0x80; break; | ||
4525 | + case 96000: i2s_sf = 0xa0; break; | ||
4526 | + case 176400: i2s_sf = 0xc0; break; | ||
4527 | + case 192000: i2s_sf = 0xe0; break; | ||
4528 | + default: | ||
4529 | + return -EINVAL; | ||
4530 | + } | ||
4531 | + | ||
4532 | + /* Set sampling frequency for I2S audio to 48 kHz */ | ||
4533 | + adv7511_wr_and_or(sd, 0x15, 0xf, i2s_sf); | ||
4534 | + | ||
4535 | + return 0; | ||
4536 | +} | ||
4537 | + | ||
4538 | +static int adv7511_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config) | ||
4539 | +{ | ||
4540 | + /* Only 2 channels in use for application */ | ||
4541 | + adv7511_wr_and_or(sd, 0x73, 0xf8, 0x1); | ||
4542 | + /* Speaker mapping */ | ||
4543 | + adv7511_wr(sd, 0x76, 0x00); | ||
4544 | + | ||
4545 | + /* 16 bit audio word length */ | ||
4546 | + adv7511_wr_and_or(sd, 0x14, 0xf0, 0x02); | ||
4547 | + | ||
4548 | + return 0; | ||
4549 | +} | ||
4550 | + | ||
4551 | +static const struct v4l2_subdev_audio_ops adv7511_audio_ops = { | ||
4552 | + .s_stream = adv7511_s_audio_stream, | ||
4553 | + .s_clock_freq = adv7511_s_clock_freq, | ||
4554 | + .s_i2s_clock_freq = adv7511_s_i2s_clock_freq, | ||
4555 | + .s_routing = adv7511_s_routing, | ||
4556 | +}; | ||
4557 | + | ||
4558 | +/* ---------------------------- PAD OPS ------------------------------------- */ | ||
4559 | + | ||
4560 | +static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid) | ||
4561 | +{ | ||
4562 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4563 | + | ||
4564 | + memset(edid->reserved, 0, sizeof(edid->reserved)); | ||
4565 | + | ||
4566 | + if (edid->pad != 0) | ||
4567 | + return -EINVAL; | ||
4568 | + | ||
4569 | + if (edid->start_block == 0 && edid->blocks == 0) { | ||
4570 | + edid->blocks = state->edid.segments * 2; | ||
4571 | + return 0; | ||
4572 | + } | ||
4573 | + | ||
4574 | + if (state->edid.segments == 0) | ||
4575 | + return -ENODATA; | ||
4576 | + | ||
4577 | + if (edid->start_block >= state->edid.segments * 2) | ||
4578 | + return -EINVAL; | ||
4579 | + | ||
4580 | + if (edid->start_block + edid->blocks > state->edid.segments * 2) | ||
4581 | + edid->blocks = state->edid.segments * 2 - edid->start_block; | ||
4582 | + | ||
4583 | + memcpy(edid->edid, &state->edid.data[edid->start_block * 128], | ||
4584 | + 128 * edid->blocks); | ||
4585 | + | ||
4586 | + return 0; | ||
4587 | +} | ||
4588 | + | ||
4589 | +static int adv7511_enum_mbus_code(struct v4l2_subdev *sd, | ||
4590 | + struct v4l2_subdev_pad_config *cfg, | ||
4591 | + struct v4l2_subdev_mbus_code_enum *code) | ||
4592 | +{ | ||
4593 | + if (code->pad != 0) | ||
4594 | + return -EINVAL; | ||
4595 | + | ||
4596 | + switch (code->index) { | ||
4597 | + case 0: | ||
4598 | + code->code = MEDIA_BUS_FMT_RGB888_1X24; | ||
4599 | + break; | ||
4600 | + case 1: | ||
4601 | + code->code = MEDIA_BUS_FMT_YUYV8_1X16; | ||
4602 | + break; | ||
4603 | + case 2: | ||
4604 | + code->code = MEDIA_BUS_FMT_UYVY8_1X16; | ||
4605 | + break; | ||
4606 | + default: | ||
4607 | + return -EINVAL; | ||
4608 | + } | ||
4609 | + return 0; | ||
4610 | +} | ||
4611 | + | ||
4612 | +static void adv7511_fill_format(struct adv7511_state *state, | ||
4613 | + struct v4l2_mbus_framefmt *format) | ||
4614 | +{ | ||
4615 | + format->width = state->dv_timings.bt.width; | ||
4616 | + format->height = state->dv_timings.bt.height; | ||
4617 | + format->field = V4L2_FIELD_NONE; | ||
4618 | +} | ||
4619 | + | ||
4620 | +static int adv7511_get_fmt(struct v4l2_subdev *sd, | ||
4621 | + struct v4l2_subdev_pad_config *cfg, | ||
4622 | + struct v4l2_subdev_format *format) | ||
4623 | +{ | ||
4624 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4625 | + | ||
4626 | + if (format->pad != 0) | ||
4627 | + return -EINVAL; | ||
4628 | + | ||
4629 | + memset(&format->format, 0, sizeof(format->format)); | ||
4630 | + adv7511_fill_format(state, &format->format); | ||
4631 | + | ||
4632 | + if (format->which == V4L2_SUBDEV_FORMAT_TRY) { | ||
4633 | + struct v4l2_mbus_framefmt *fmt; | ||
4634 | + | ||
4635 | + fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); | ||
4636 | + format->format.code = fmt->code; | ||
4637 | + format->format.colorspace = fmt->colorspace; | ||
4638 | + format->format.ycbcr_enc = fmt->ycbcr_enc; | ||
4639 | + format->format.quantization = fmt->quantization; | ||
4640 | + format->format.xfer_func = fmt->xfer_func; | ||
4641 | + } else { | ||
4642 | + format->format.code = state->fmt_code; | ||
4643 | + format->format.colorspace = state->colorspace; | ||
4644 | + format->format.ycbcr_enc = state->ycbcr_enc; | ||
4645 | + format->format.quantization = state->quantization; | ||
4646 | + format->format.xfer_func = state->xfer_func; | ||
4647 | + } | ||
4648 | + | ||
4649 | + return 0; | ||
4650 | +} | ||
4651 | + | ||
4652 | +static int adv7511_set_fmt(struct v4l2_subdev *sd, | ||
4653 | + struct v4l2_subdev_pad_config *cfg, | ||
4654 | + struct v4l2_subdev_format *format) | ||
4655 | +{ | ||
4656 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4657 | + /* | ||
4658 | + * Bitfield namings come the CEA-861-F standard, table 8 "Auxiliary | ||
4659 | + * Video Information (AVI) InfoFrame Format" | ||
4660 | + * | ||
4661 | + * c = Colorimetry | ||
4662 | + * ec = Extended Colorimetry | ||
4663 | + * y = RGB or YCbCr | ||
4664 | + * q = RGB Quantization Range | ||
4665 | + * yq = YCC Quantization Range | ||
4666 | + */ | ||
4667 | + u8 c = HDMI_COLORIMETRY_NONE; | ||
4668 | + u8 ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; | ||
4669 | + u8 y = HDMI_COLORSPACE_RGB; | ||
4670 | + u8 q = HDMI_QUANTIZATION_RANGE_DEFAULT; | ||
4671 | + u8 yq = HDMI_YCC_QUANTIZATION_RANGE_LIMITED; | ||
4672 | + u8 itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC; | ||
4673 | + u8 cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS; | ||
4674 | + | ||
4675 | + if (format->pad != 0) | ||
4676 | + return -EINVAL; | ||
4677 | + switch (format->format.code) { | ||
4678 | + case MEDIA_BUS_FMT_UYVY8_1X16: | ||
4679 | + case MEDIA_BUS_FMT_YUYV8_1X16: | ||
4680 | + case MEDIA_BUS_FMT_RGB888_1X24: | ||
4681 | + break; | ||
4682 | + default: | ||
4683 | + return -EINVAL; | ||
4684 | + } | ||
4685 | + | ||
4686 | + adv7511_fill_format(state, &format->format); | ||
4687 | + if (format->which == V4L2_SUBDEV_FORMAT_TRY) { | ||
4688 | + struct v4l2_mbus_framefmt *fmt; | ||
4689 | + | ||
4690 | + fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); | ||
4691 | + fmt->code = format->format.code; | ||
4692 | + fmt->colorspace = format->format.colorspace; | ||
4693 | + fmt->ycbcr_enc = format->format.ycbcr_enc; | ||
4694 | + fmt->quantization = format->format.quantization; | ||
4695 | + fmt->xfer_func = format->format.xfer_func; | ||
4696 | + return 0; | ||
4697 | + } | ||
4698 | + | ||
4699 | + switch (format->format.code) { | ||
4700 | + case MEDIA_BUS_FMT_UYVY8_1X16: | ||
4701 | + adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); | ||
4702 | + adv7511_wr_and_or(sd, 0x16, 0x03, 0xb8); | ||
4703 | + y = HDMI_COLORSPACE_YUV422; | ||
4704 | + break; | ||
4705 | + case MEDIA_BUS_FMT_YUYV8_1X16: | ||
4706 | + adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); | ||
4707 | + adv7511_wr_and_or(sd, 0x16, 0x03, 0xbc); | ||
4708 | + y = HDMI_COLORSPACE_YUV422; | ||
4709 | + break; | ||
4710 | + case MEDIA_BUS_FMT_RGB888_1X24: | ||
4711 | + default: | ||
4712 | + adv7511_wr_and_or(sd, 0x15, 0xf0, 0x00); | ||
4713 | + adv7511_wr_and_or(sd, 0x16, 0x03, 0x00); | ||
4714 | + break; | ||
4715 | + } | ||
4716 | + state->fmt_code = format->format.code; | ||
4717 | + state->colorspace = format->format.colorspace; | ||
4718 | + state->ycbcr_enc = format->format.ycbcr_enc; | ||
4719 | + state->quantization = format->format.quantization; | ||
4720 | + state->xfer_func = format->format.xfer_func; | ||
4721 | + | ||
4722 | + switch (format->format.colorspace) { | ||
4723 | + case V4L2_COLORSPACE_ADOBERGB: | ||
4724 | + c = HDMI_COLORIMETRY_EXTENDED; | ||
4725 | + ec = y ? HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601 : | ||
4726 | + HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB; | ||
4727 | + break; | ||
4728 | + case V4L2_COLORSPACE_SMPTE170M: | ||
4729 | + c = y ? HDMI_COLORIMETRY_ITU_601 : HDMI_COLORIMETRY_NONE; | ||
4730 | + if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV601) { | ||
4731 | + c = HDMI_COLORIMETRY_EXTENDED; | ||
4732 | + ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; | ||
4733 | + } | ||
4734 | + break; | ||
4735 | + case V4L2_COLORSPACE_REC709: | ||
4736 | + c = y ? HDMI_COLORIMETRY_ITU_709 : HDMI_COLORIMETRY_NONE; | ||
4737 | + if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV709) { | ||
4738 | + c = HDMI_COLORIMETRY_EXTENDED; | ||
4739 | + ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_709; | ||
4740 | + } | ||
4741 | + break; | ||
4742 | + case V4L2_COLORSPACE_SRGB: | ||
4743 | + c = y ? HDMI_COLORIMETRY_EXTENDED : HDMI_COLORIMETRY_NONE; | ||
4744 | + ec = y ? HDMI_EXTENDED_COLORIMETRY_S_YCC_601 : | ||
4745 | + HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; | ||
4746 | + break; | ||
4747 | + case V4L2_COLORSPACE_BT2020: | ||
4748 | + c = HDMI_COLORIMETRY_EXTENDED; | ||
4749 | + if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_BT2020_CONST_LUM) | ||
4750 | + ec = 5; /* Not yet available in hdmi.h */ | ||
4751 | + else | ||
4752 | + ec = 6; /* Not yet available in hdmi.h */ | ||
4753 | + break; | ||
4754 | + default: | ||
4755 | + break; | ||
4756 | + } | ||
4757 | + | ||
4758 | + /* | ||
4759 | + * CEA-861-F says that for RGB formats the YCC range must match the | ||
4760 | + * RGB range, although sources should ignore the YCC range. | ||
4761 | + * | ||
4762 | + * The RGB quantization range shouldn't be non-zero if the EDID doesn't | ||
4763 | + * have the Q bit set in the Video Capabilities Data Block, however this | ||
4764 | + * isn't checked at the moment. The assumption is that the application | ||
4765 | + * knows the EDID and can detect this. | ||
4766 | + * | ||
4767 | + * The same is true for the YCC quantization range: non-standard YCC | ||
4768 | + * quantization ranges should only be sent if the EDID has the YQ bit | ||
4769 | + * set in the Video Capabilities Data Block. | ||
4770 | + */ | ||
4771 | + switch (format->format.quantization) { | ||
4772 | + case V4L2_QUANTIZATION_FULL_RANGE: | ||
4773 | + q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT : | ||
4774 | + HDMI_QUANTIZATION_RANGE_FULL; | ||
4775 | + yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_FULL; | ||
4776 | + break; | ||
4777 | + case V4L2_QUANTIZATION_LIM_RANGE: | ||
4778 | + q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT : | ||
4779 | + HDMI_QUANTIZATION_RANGE_LIMITED; | ||
4780 | + yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_LIMITED; | ||
4781 | + break; | ||
4782 | + } | ||
4783 | + | ||
4784 | + adv7511_wr_and_or(sd, 0x4a, 0xbf, 0); | ||
4785 | + adv7511_wr_and_or(sd, 0x55, 0x9f, y << 5); | ||
4786 | + adv7511_wr_and_or(sd, 0x56, 0x3f, c << 6); | ||
4787 | + adv7511_wr_and_or(sd, 0x57, 0x83, (ec << 4) | (q << 2) | (itc << 7)); | ||
4788 | + adv7511_wr_and_or(sd, 0x59, 0x0f, (yq << 6) | (cn << 4)); | ||
4789 | + adv7511_wr_and_or(sd, 0x4a, 0xff, 1); | ||
4790 | + adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); | ||
4791 | + | ||
4792 | + return 0; | ||
4793 | +} | ||
4794 | + | ||
4795 | +static const struct v4l2_subdev_pad_ops adv7511_pad_ops = { | ||
4796 | + .get_edid = adv7511_get_edid, | ||
4797 | + .enum_mbus_code = adv7511_enum_mbus_code, | ||
4798 | + .get_fmt = adv7511_get_fmt, | ||
4799 | + .set_fmt = adv7511_set_fmt, | ||
4800 | + .enum_dv_timings = adv7511_enum_dv_timings, | ||
4801 | + .dv_timings_cap = adv7511_dv_timings_cap, | ||
4802 | +}; | ||
4803 | + | ||
4804 | +/* --------------------- SUBDEV OPS --------------------------------------- */ | ||
4805 | + | ||
4806 | +static const struct v4l2_subdev_ops adv7511_ops = { | ||
4807 | + .core = &adv7511_core_ops, | ||
4808 | + .pad = &adv7511_pad_ops, | ||
4809 | + .video = &adv7511_video_ops, | ||
4810 | + .audio = &adv7511_audio_ops, | ||
4811 | +}; | ||
4812 | + | ||
4813 | +/* ----------------------------------------------------------------------- */ | ||
4814 | +static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf) | ||
4815 | +{ | ||
4816 | + if (debug >= lvl) { | ||
4817 | + int i, j; | ||
4818 | + v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment); | ||
4819 | + for (i = 0; i < 256; i += 16) { | ||
4820 | + u8 b[128]; | ||
4821 | + u8 *bp = b; | ||
4822 | + if (i == 128) | ||
4823 | + v4l2_dbg(lvl, debug, sd, "\n"); | ||
4824 | + for (j = i; j < i + 16; j++) { | ||
4825 | + sprintf(bp, "0x%02x, ", buf[j]); | ||
4826 | + bp += 6; | ||
4827 | + } | ||
4828 | + bp[0] = '\0'; | ||
4829 | + v4l2_dbg(lvl, debug, sd, "%s\n", b); | ||
4830 | + } | ||
4831 | + } | ||
4832 | +} | ||
4833 | + | ||
4834 | +static void adv7511_notify_no_edid(struct v4l2_subdev *sd) | ||
4835 | +{ | ||
4836 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4837 | + struct adv7511_edid_detect ed; | ||
4838 | + | ||
4839 | + /* We failed to read the EDID, so send an event for this. */ | ||
4840 | + ed.present = false; | ||
4841 | + ed.segment = adv7511_rd(sd, 0xc4); | ||
4842 | + ed.phys_addr = CEC_PHYS_ADDR_INVALID; | ||
4843 | + cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); | ||
4844 | + v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); | ||
4845 | + v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x0); | ||
4846 | +} | ||
4847 | + | ||
4848 | +static void adv7511_edid_handler(struct work_struct *work) | ||
4849 | +{ | ||
4850 | + struct delayed_work *dwork = to_delayed_work(work); | ||
4851 | + struct adv7511_state *state = container_of(dwork, struct adv7511_state, edid_handler); | ||
4852 | + struct v4l2_subdev *sd = &state->sd; | ||
4853 | + | ||
4854 | + v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
4855 | + | ||
4856 | + if (adv7511_check_edid_status(sd)) { | ||
4857 | + /* Return if we received the EDID. */ | ||
4858 | + return; | ||
4859 | + } | ||
4860 | + | ||
4861 | + if (adv7511_have_hotplug(sd)) { | ||
4862 | + /* We must retry reading the EDID several times, it is possible | ||
4863 | + * that initially the EDID couldn't be read due to i2c errors | ||
4864 | + * (DVI connectors are particularly prone to this problem). */ | ||
4865 | + if (state->edid.read_retries) { | ||
4866 | + state->edid.read_retries--; | ||
4867 | + v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__); | ||
4868 | + state->have_monitor = false; | ||
4869 | + adv7511_s_power(sd, false); | ||
4870 | + adv7511_s_power(sd, true); | ||
4871 | + queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
4872 | + return; | ||
4873 | + } | ||
4874 | + } | ||
4875 | + | ||
4876 | + /* We failed to read the EDID, so send an event for this. */ | ||
4877 | + adv7511_notify_no_edid(sd); | ||
4878 | + v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__); | ||
4879 | +} | ||
4880 | + | ||
4881 | +static void adv7511_audio_setup(struct v4l2_subdev *sd) | ||
4882 | +{ | ||
4883 | + v4l2_dbg(1, debug, sd, "%s\n", __func__); | ||
4884 | + | ||
4885 | + adv7511_s_i2s_clock_freq(sd, 48000); | ||
4886 | + adv7511_s_clock_freq(sd, 48000); | ||
4887 | + adv7511_s_routing(sd, 0, 0, 0); | ||
4888 | +} | ||
4889 | + | ||
4890 | +/* Configure hdmi transmitter. */ | ||
4891 | +static void adv7511_setup(struct v4l2_subdev *sd) | ||
4892 | +{ | ||
4893 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4894 | + v4l2_dbg(1, debug, sd, "%s\n", __func__); | ||
4895 | + | ||
4896 | + /* Input format: RGB 4:4:4 */ | ||
4897 | + adv7511_wr_and_or(sd, 0x15, 0xf0, 0x0); | ||
4898 | + /* Output format: RGB 4:4:4 */ | ||
4899 | + adv7511_wr_and_or(sd, 0x16, 0x7f, 0x0); | ||
4900 | + /* 1st order interpolation 4:2:2 -> 4:4:4 up conversion, Aspect ratio: 16:9 */ | ||
4901 | + adv7511_wr_and_or(sd, 0x17, 0xf9, 0x06); | ||
4902 | + /* Disable pixel repetition */ | ||
4903 | + adv7511_wr_and_or(sd, 0x3b, 0x9f, 0x0); | ||
4904 | + /* Disable CSC */ | ||
4905 | + adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); | ||
4906 | + /* Output format: RGB 4:4:4, Active Format Information is valid, | ||
4907 | + * underscanned */ | ||
4908 | + adv7511_wr_and_or(sd, 0x55, 0x9c, 0x12); | ||
4909 | + /* AVI Info frame packet enable, Audio Info frame disable */ | ||
4910 | + adv7511_wr_and_or(sd, 0x44, 0xe7, 0x10); | ||
4911 | + /* Colorimetry, Active format aspect ratio: same as picure. */ | ||
4912 | + adv7511_wr(sd, 0x56, 0xa8); | ||
4913 | + /* No encryption */ | ||
4914 | + adv7511_wr_and_or(sd, 0xaf, 0xed, 0x0); | ||
4915 | + | ||
4916 | + /* Positive clk edge capture for input video clock */ | ||
4917 | + adv7511_wr_and_or(sd, 0xba, 0x1f, 0x60); | ||
4918 | + | ||
4919 | + adv7511_audio_setup(sd); | ||
4920 | + | ||
4921 | + v4l2_ctrl_handler_setup(&state->hdl); | ||
4922 | +} | ||
4923 | + | ||
4924 | +static void adv7511_notify_monitor_detect(struct v4l2_subdev *sd) | ||
4925 | +{ | ||
4926 | + struct adv7511_monitor_detect mdt; | ||
4927 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4928 | + | ||
4929 | + mdt.present = state->have_monitor; | ||
4930 | + v4l2_subdev_notify(sd, ADV7511_MONITOR_DETECT, (void *)&mdt); | ||
4931 | +} | ||
4932 | + | ||
4933 | +static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd) | ||
4934 | +{ | ||
4935 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4936 | + /* read hotplug and rx-sense state */ | ||
4937 | + u8 status = adv7511_rd(sd, 0x42); | ||
4938 | + | ||
4939 | + v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n", | ||
4940 | + __func__, | ||
4941 | + status, | ||
4942 | + status & MASK_ADV7511_HPD_DETECT ? ", hotplug" : "", | ||
4943 | + status & MASK_ADV7511_MSEN_DETECT ? ", rx-sense" : ""); | ||
4944 | + | ||
4945 | + /* update read only ctrls */ | ||
4946 | + v4l2_ctrl_s_ctrl(state->hotplug_ctrl, adv7511_have_hotplug(sd) ? 0x1 : 0x0); | ||
4947 | + v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, adv7511_have_rx_sense(sd) ? 0x1 : 0x0); | ||
4948 | + | ||
4949 | + if ((status & MASK_ADV7511_HPD_DETECT) && ((status & MASK_ADV7511_MSEN_DETECT) || state->edid.segments)) { | ||
4950 | + v4l2_dbg(1, debug, sd, "%s: hotplug and (rx-sense or edid)\n", __func__); | ||
4951 | + if (!state->have_monitor) { | ||
4952 | + v4l2_dbg(1, debug, sd, "%s: monitor detected\n", __func__); | ||
4953 | + state->have_monitor = true; | ||
4954 | + adv7511_set_isr(sd, true); | ||
4955 | + if (!adv7511_s_power(sd, true)) { | ||
4956 | + v4l2_dbg(1, debug, sd, "%s: monitor detected, powerup failed\n", __func__); | ||
4957 | + return; | ||
4958 | + } | ||
4959 | + adv7511_setup(sd); | ||
4960 | + adv7511_notify_monitor_detect(sd); | ||
4961 | + state->edid.read_retries = EDID_MAX_RETRIES; | ||
4962 | + queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
4963 | + } | ||
4964 | + } else if (status & MASK_ADV7511_HPD_DETECT) { | ||
4965 | + v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__); | ||
4966 | + state->edid.read_retries = EDID_MAX_RETRIES; | ||
4967 | + queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
4968 | + } else if (!(status & MASK_ADV7511_HPD_DETECT)) { | ||
4969 | + v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__); | ||
4970 | + if (state->have_monitor) { | ||
4971 | + v4l2_dbg(1, debug, sd, "%s: monitor not detected\n", __func__); | ||
4972 | + state->have_monitor = false; | ||
4973 | + adv7511_notify_monitor_detect(sd); | ||
4974 | + } | ||
4975 | + adv7511_s_power(sd, false); | ||
4976 | + memset(&state->edid, 0, sizeof(struct adv7511_state_edid)); | ||
4977 | + adv7511_notify_no_edid(sd); | ||
4978 | + } | ||
4979 | +} | ||
4980 | + | ||
4981 | +static bool edid_block_verify_crc(u8 *edid_block) | ||
4982 | +{ | ||
4983 | + u8 sum = 0; | ||
4984 | + int i; | ||
4985 | + | ||
4986 | + for (i = 0; i < 128; i++) | ||
4987 | + sum += edid_block[i]; | ||
4988 | + return sum == 0; | ||
4989 | +} | ||
4990 | + | ||
4991 | +static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment) | ||
4992 | +{ | ||
4993 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
4994 | + u32 blocks = state->edid.blocks; | ||
4995 | + u8 *data = state->edid.data; | ||
4996 | + | ||
4997 | + if (!edid_block_verify_crc(&data[segment * 256])) | ||
4998 | + return false; | ||
4999 | + if ((segment + 1) * 2 <= blocks) | ||
5000 | + return edid_block_verify_crc(&data[segment * 256 + 128]); | ||
5001 | + return true; | ||
5002 | +} | ||
5003 | + | ||
5004 | +static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment) | ||
5005 | +{ | ||
5006 | + static const u8 hdmi_header[] = { | ||
5007 | + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 | ||
5008 | + }; | ||
5009 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
5010 | + u8 *data = state->edid.data; | ||
5011 | + | ||
5012 | + if (segment != 0) | ||
5013 | + return true; | ||
5014 | + return !memcmp(data, hdmi_header, sizeof(hdmi_header)); | ||
5015 | +} | ||
5016 | + | ||
5017 | +static bool adv7511_check_edid_status(struct v4l2_subdev *sd) | ||
5018 | +{ | ||
5019 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
5020 | + u8 edidRdy = adv7511_rd(sd, 0xc5); | ||
5021 | + | ||
5022 | + v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n", | ||
5023 | + __func__, EDID_MAX_RETRIES - state->edid.read_retries); | ||
5024 | + | ||
5025 | + if (state->edid.complete) | ||
5026 | + return true; | ||
5027 | + | ||
5028 | + if (edidRdy & MASK_ADV7511_EDID_RDY) { | ||
5029 | + int segment = adv7511_rd(sd, 0xc4); | ||
5030 | + struct adv7511_edid_detect ed; | ||
5031 | + | ||
5032 | + if (segment >= EDID_MAX_SEGM) { | ||
5033 | + v4l2_err(sd, "edid segment number too big\n"); | ||
5034 | + return false; | ||
5035 | + } | ||
5036 | + v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment); | ||
5037 | + adv7511_edid_rd(sd, 256, &state->edid.data[segment * 256]); | ||
5038 | + adv7511_dbg_dump_edid(2, debug, sd, segment, &state->edid.data[segment * 256]); | ||
5039 | + if (segment == 0) { | ||
5040 | + state->edid.blocks = state->edid.data[0x7e] + 1; | ||
5041 | + v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n", __func__, state->edid.blocks); | ||
5042 | + } | ||
5043 | + if (!edid_verify_crc(sd, segment) || | ||
5044 | + !edid_verify_header(sd, segment)) { | ||
5045 | + /* edid crc error, force reread of edid segment */ | ||
5046 | + v4l2_err(sd, "%s: edid crc or header error\n", __func__); | ||
5047 | + state->have_monitor = false; | ||
5048 | + adv7511_s_power(sd, false); | ||
5049 | + adv7511_s_power(sd, true); | ||
5050 | + return false; | ||
5051 | + } | ||
5052 | + /* one more segment read ok */ | ||
5053 | + state->edid.segments = segment + 1; | ||
5054 | + v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x1); | ||
5055 | + if (((state->edid.data[0x7e] >> 1) + 1) > state->edid.segments) { | ||
5056 | + /* Request next EDID segment */ | ||
5057 | + v4l2_dbg(1, debug, sd, "%s: request segment %d\n", __func__, state->edid.segments); | ||
5058 | + adv7511_wr(sd, 0xc9, 0xf); | ||
5059 | + adv7511_wr(sd, 0xc4, state->edid.segments); | ||
5060 | + state->edid.read_retries = EDID_MAX_RETRIES; | ||
5061 | + queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
5062 | + return false; | ||
5063 | + } | ||
5064 | + | ||
5065 | + v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments); | ||
5066 | + state->edid.complete = true; | ||
5067 | + ed.phys_addr = cec_get_edid_phys_addr(state->edid.data, | ||
5068 | + state->edid.segments * 256, | ||
5069 | + NULL); | ||
5070 | + /* report when we have all segments | ||
5071 | + but report only for segment 0 | ||
5072 | + */ | ||
5073 | + ed.present = true; | ||
5074 | + ed.segment = 0; | ||
5075 | + state->edid_detect_counter++; | ||
5076 | + cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); | ||
5077 | + v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); | ||
5078 | + return ed.present; | ||
5079 | + } | ||
5080 | + | ||
5081 | + return false; | ||
5082 | +} | ||
5083 | + | ||
5084 | +static int adv7511_registered(struct v4l2_subdev *sd) | ||
5085 | +{ | ||
5086 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
5087 | + int err; | ||
5088 | + | ||
5089 | + err = cec_register_adapter(state->cec_adap); | ||
5090 | + if (err) | ||
5091 | + cec_delete_adapter(state->cec_adap); | ||
5092 | + return err; | ||
5093 | +} | ||
5094 | + | ||
5095 | +static void adv7511_unregistered(struct v4l2_subdev *sd) | ||
5096 | +{ | ||
5097 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
5098 | + | ||
5099 | + cec_unregister_adapter(state->cec_adap); | ||
5100 | +} | ||
5101 | + | ||
5102 | +static const struct v4l2_subdev_internal_ops adv7511_int_ops = { | ||
5103 | + .registered = adv7511_registered, | ||
5104 | + .unregistered = adv7511_unregistered, | ||
5105 | +}; | ||
5106 | + | ||
5107 | +/* ----------------------------------------------------------------------- */ | ||
5108 | +/* Setup ADV7511 */ | ||
5109 | +static void adv7511_init_setup(struct v4l2_subdev *sd) | ||
5110 | +{ | ||
5111 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
5112 | + struct adv7511_state_edid *edid = &state->edid; | ||
5113 | + u32 cec_clk = state->pdata.cec_clk; | ||
5114 | + u8 ratio; | ||
5115 | + | ||
5116 | + v4l2_dbg(1, debug, sd, "%s\n", __func__); | ||
5117 | + | ||
5118 | + /* clear all interrupts */ | ||
5119 | + adv7511_wr(sd, 0x96, 0xff); | ||
5120 | + adv7511_wr(sd, 0x97, 0xff); | ||
5121 | + /* | ||
5122 | + * Stop HPD from resetting a lot of registers. | ||
5123 | + * It might leave the chip in a partly un-initialized state, | ||
5124 | + * in particular with regards to hotplug bounces. | ||
5125 | + */ | ||
5126 | + adv7511_wr_and_or(sd, 0xd6, 0x3f, 0xc0); | ||
5127 | + memset(edid, 0, sizeof(struct adv7511_state_edid)); | ||
5128 | + state->have_monitor = false; | ||
5129 | + adv7511_set_isr(sd, false); | ||
5130 | + adv7511_s_stream(sd, false); | ||
5131 | + adv7511_s_audio_stream(sd, false); | ||
5132 | + | ||
5133 | + if (state->i2c_cec == NULL) | ||
5134 | + return; | ||
5135 | + | ||
5136 | + v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk); | ||
5137 | + | ||
5138 | + /* cec soft reset */ | ||
5139 | + adv7511_cec_write(sd, 0x50, 0x01); | ||
5140 | + adv7511_cec_write(sd, 0x50, 0x00); | ||
5141 | + | ||
5142 | + /* legacy mode */ | ||
5143 | + adv7511_cec_write(sd, 0x4a, 0x00); | ||
5144 | + | ||
5145 | + if (cec_clk % 750000 != 0) | ||
5146 | + v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n", | ||
5147 | + __func__, cec_clk); | ||
5148 | + | ||
5149 | + ratio = (cec_clk / 750000) - 1; | ||
5150 | + adv7511_cec_write(sd, 0x4e, ratio << 2); | ||
5151 | +} | ||
5152 | + | ||
5153 | +static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
5154 | +{ | ||
5155 | + struct adv7511_state *state; | ||
5156 | + struct adv7511_platform_data *pdata = client->dev.platform_data; | ||
5157 | + struct v4l2_ctrl_handler *hdl; | ||
5158 | + struct v4l2_subdev *sd; | ||
5159 | + u8 chip_id[2]; | ||
5160 | + int err = -EIO; | ||
5161 | + | ||
5162 | + /* Check if the adapter supports the needed features */ | ||
5163 | + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
5164 | + return -EIO; | ||
5165 | + | ||
5166 | + state = devm_kzalloc(&client->dev, sizeof(struct adv7511_state), GFP_KERNEL); | ||
5167 | + if (!state) | ||
5168 | + return -ENOMEM; | ||
5169 | + | ||
5170 | + /* Platform data */ | ||
5171 | + if (!pdata) { | ||
5172 | + v4l_err(client, "No platform data!\n"); | ||
5173 | + return -ENODEV; | ||
5174 | + } | ||
5175 | + memcpy(&state->pdata, pdata, sizeof(state->pdata)); | ||
5176 | + state->fmt_code = MEDIA_BUS_FMT_RGB888_1X24; | ||
5177 | + state->colorspace = V4L2_COLORSPACE_SRGB; | ||
5178 | + | ||
5179 | + sd = &state->sd; | ||
5180 | + | ||
5181 | + v4l2_dbg(1, debug, sd, "detecting adv7511 client on address 0x%x\n", | ||
5182 | + client->addr << 1); | ||
5183 | + | ||
5184 | + v4l2_i2c_subdev_init(sd, client, &adv7511_ops); | ||
5185 | + sd->internal_ops = &adv7511_int_ops; | ||
5186 | + | ||
5187 | + hdl = &state->hdl; | ||
5188 | + v4l2_ctrl_handler_init(hdl, 10); | ||
5189 | + /* add in ascending ID order */ | ||
5190 | + state->hdmi_mode_ctrl = v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops, | ||
5191 | + V4L2_CID_DV_TX_MODE, V4L2_DV_TX_MODE_HDMI, | ||
5192 | + 0, V4L2_DV_TX_MODE_DVI_D); | ||
5193 | + state->hotplug_ctrl = v4l2_ctrl_new_std(hdl, NULL, | ||
5194 | + V4L2_CID_DV_TX_HOTPLUG, 0, 1, 0, 0); | ||
5195 | + state->rx_sense_ctrl = v4l2_ctrl_new_std(hdl, NULL, | ||
5196 | + V4L2_CID_DV_TX_RXSENSE, 0, 1, 0, 0); | ||
5197 | + state->have_edid0_ctrl = v4l2_ctrl_new_std(hdl, NULL, | ||
5198 | + V4L2_CID_DV_TX_EDID_PRESENT, 0, 1, 0, 0); | ||
5199 | + state->rgb_quantization_range_ctrl = | ||
5200 | + v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops, | ||
5201 | + V4L2_CID_DV_TX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL, | ||
5202 | + 0, V4L2_DV_RGB_RANGE_AUTO); | ||
5203 | + state->content_type_ctrl = | ||
5204 | + v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops, | ||
5205 | + V4L2_CID_DV_TX_IT_CONTENT_TYPE, V4L2_DV_IT_CONTENT_TYPE_NO_ITC, | ||
5206 | + 0, V4L2_DV_IT_CONTENT_TYPE_NO_ITC); | ||
5207 | + sd->ctrl_handler = hdl; | ||
5208 | + if (hdl->error) { | ||
5209 | + err = hdl->error; | ||
5210 | + goto err_hdl; | ||
5211 | + } | ||
5212 | + state->pad.flags = MEDIA_PAD_FL_SINK; | ||
5213 | + err = media_entity_pads_init(&sd->entity, 1, &state->pad); | ||
5214 | + if (err) | ||
5215 | + goto err_hdl; | ||
5216 | + | ||
5217 | + /* EDID and CEC i2c addr */ | ||
5218 | + state->i2c_edid_addr = state->pdata.i2c_edid << 1; | ||
5219 | + state->i2c_cec_addr = state->pdata.i2c_cec << 1; | ||
5220 | + state->i2c_pktmem_addr = state->pdata.i2c_pktmem << 1; | ||
5221 | + | ||
5222 | + state->chip_revision = adv7511_rd(sd, 0x0); | ||
5223 | + chip_id[0] = adv7511_rd(sd, 0xf5); | ||
5224 | + chip_id[1] = adv7511_rd(sd, 0xf6); | ||
5225 | + if (chip_id[0] != 0x75 || chip_id[1] != 0x11) { | ||
5226 | + v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0], | ||
5227 | + chip_id[1]); | ||
5228 | + err = -EIO; | ||
5229 | + goto err_entity; | ||
5230 | + } | ||
5231 | + | ||
5232 | + state->i2c_edid = i2c_new_dummy(client->adapter, | ||
5233 | + state->i2c_edid_addr >> 1); | ||
5234 | + if (state->i2c_edid == NULL) { | ||
5235 | + v4l2_err(sd, "failed to register edid i2c client\n"); | ||
5236 | + err = -ENOMEM; | ||
5237 | + goto err_entity; | ||
5238 | + } | ||
5239 | + | ||
5240 | + adv7511_wr(sd, 0xe1, state->i2c_cec_addr); | ||
5241 | + if (state->pdata.cec_clk < 3000000 || | ||
5242 | + state->pdata.cec_clk > 100000000) { | ||
5243 | + v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n", | ||
5244 | + __func__, state->pdata.cec_clk); | ||
5245 | + state->pdata.cec_clk = 0; | ||
5246 | + } | ||
5247 | + | ||
5248 | + if (state->pdata.cec_clk) { | ||
5249 | + state->i2c_cec = i2c_new_dummy(client->adapter, | ||
5250 | + state->i2c_cec_addr >> 1); | ||
5251 | + if (state->i2c_cec == NULL) { | ||
5252 | + v4l2_err(sd, "failed to register cec i2c client\n"); | ||
5253 | + err = -ENOMEM; | ||
5254 | + goto err_unreg_edid; | ||
5255 | + } | ||
5256 | + adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */ | ||
5257 | + } else { | ||
5258 | + adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */ | ||
5259 | + } | ||
5260 | + | ||
5261 | + state->i2c_pktmem = i2c_new_dummy(client->adapter, state->i2c_pktmem_addr >> 1); | ||
5262 | + if (state->i2c_pktmem == NULL) { | ||
5263 | + v4l2_err(sd, "failed to register pktmem i2c client\n"); | ||
5264 | + err = -ENOMEM; | ||
5265 | + goto err_unreg_cec; | ||
5266 | + } | ||
5267 | + | ||
5268 | + state->work_queue = create_singlethread_workqueue(sd->name); | ||
5269 | + if (state->work_queue == NULL) { | ||
5270 | + v4l2_err(sd, "could not create workqueue\n"); | ||
5271 | + err = -ENOMEM; | ||
5272 | + goto err_unreg_pktmem; | ||
5273 | + } | ||
5274 | + | ||
5275 | + INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler); | ||
5276 | + | ||
5277 | + adv7511_init_setup(sd); | ||
5278 | + | ||
5279 | +#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) | ||
5280 | + state->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops, | ||
5281 | + state, dev_name(&client->dev), CEC_CAP_TRANSMIT | | ||
5282 | + CEC_CAP_LOG_ADDRS | CEC_CAP_PASSTHROUGH | CEC_CAP_RC, | ||
5283 | + ADV7511_MAX_ADDRS, &client->dev); | ||
5284 | + err = PTR_ERR_OR_ZERO(state->cec_adap); | ||
5285 | + if (err) { | ||
5286 | + destroy_workqueue(state->work_queue); | ||
5287 | + goto err_unreg_pktmem; | ||
5288 | + } | ||
5289 | +#endif | ||
5290 | + | ||
5291 | + adv7511_set_isr(sd, true); | ||
5292 | + adv7511_check_monitor_present_status(sd); | ||
5293 | + | ||
5294 | + v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, | ||
5295 | + client->addr << 1, client->adapter->name); | ||
5296 | + return 0; | ||
5297 | + | ||
5298 | +err_unreg_pktmem: | ||
5299 | + i2c_unregister_device(state->i2c_pktmem); | ||
5300 | +err_unreg_cec: | ||
5301 | + if (state->i2c_cec) | ||
5302 | + i2c_unregister_device(state->i2c_cec); | ||
5303 | +err_unreg_edid: | ||
5304 | + i2c_unregister_device(state->i2c_edid); | ||
5305 | +err_entity: | ||
5306 | + media_entity_cleanup(&sd->entity); | ||
5307 | +err_hdl: | ||
5308 | + v4l2_ctrl_handler_free(&state->hdl); | ||
5309 | + return err; | ||
5310 | +} | ||
5311 | + | ||
5312 | +/* ----------------------------------------------------------------------- */ | ||
5313 | + | ||
5314 | +static int adv7511_remove(struct i2c_client *client) | ||
5315 | +{ | ||
5316 | + struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
5317 | + struct adv7511_state *state = get_adv7511_state(sd); | ||
5318 | + | ||
5319 | + state->chip_revision = -1; | ||
5320 | + | ||
5321 | + v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name, | ||
5322 | + client->addr << 1, client->adapter->name); | ||
5323 | + | ||
5324 | + adv7511_set_isr(sd, false); | ||
5325 | + adv7511_init_setup(sd); | ||
5326 | + cancel_delayed_work(&state->edid_handler); | ||
5327 | + i2c_unregister_device(state->i2c_edid); | ||
5328 | + if (state->i2c_cec) | ||
5329 | + i2c_unregister_device(state->i2c_cec); | ||
5330 | + i2c_unregister_device(state->i2c_pktmem); | ||
5331 | + destroy_workqueue(state->work_queue); | ||
5332 | + v4l2_device_unregister_subdev(sd); | ||
5333 | + media_entity_cleanup(&sd->entity); | ||
5334 | + v4l2_ctrl_handler_free(sd->ctrl_handler); | ||
5335 | + return 0; | ||
5336 | +} | ||
5337 | + | ||
5338 | +/* ----------------------------------------------------------------------- */ | ||
5339 | + | ||
5340 | +static struct i2c_device_id adv7511_id[] = { | ||
5341 | + { "adv7511", 0 }, | ||
5342 | + { } | ||
5343 | +}; | ||
5344 | +MODULE_DEVICE_TABLE(i2c, adv7511_id); | ||
5345 | + | ||
5346 | +static struct i2c_driver adv7511_driver = { | ||
5347 | + .driver = { | ||
5348 | + .name = "adv7511", | ||
5349 | + }, | ||
5350 | + .probe = adv7511_probe, | ||
5351 | + .remove = adv7511_remove, | ||
5352 | + .id_table = adv7511_id, | ||
5353 | +}; | ||
5354 | + | ||
5355 | +module_i2c_driver(adv7511_driver); | ||
5356 | diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c | ||
5357 | deleted file mode 100644 | ||
5358 | index 5f1c8ee8a50e..000000000000 | ||
5359 | --- a/drivers/media/i2c/adv7511.c | ||
5360 | +++ /dev/null | ||
5361 | @@ -1,2003 +0,0 @@ | ||
5362 | -/* | ||
5363 | - * Analog Devices ADV7511 HDMI Transmitter Device Driver | ||
5364 | - * | ||
5365 | - * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | ||
5366 | - * | ||
5367 | - * This program is free software; you may redistribute it and/or modify | ||
5368 | - * it under the terms of the GNU General Public License as published by | ||
5369 | - * the Free Software Foundation; version 2 of the License. | ||
5370 | - * | ||
5371 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
5372 | - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
5373 | - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
5374 | - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
5375 | - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
5376 | - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
5377 | - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
5378 | - * SOFTWARE. | ||
5379 | - */ | ||
5380 | - | ||
5381 | - | ||
5382 | -#include <linux/kernel.h> | ||
5383 | -#include <linux/module.h> | ||
5384 | -#include <linux/slab.h> | ||
5385 | -#include <linux/i2c.h> | ||
5386 | -#include <linux/delay.h> | ||
5387 | -#include <linux/videodev2.h> | ||
5388 | -#include <linux/gpio.h> | ||
5389 | -#include <linux/workqueue.h> | ||
5390 | -#include <linux/hdmi.h> | ||
5391 | -#include <linux/v4l2-dv-timings.h> | ||
5392 | -#include <media/v4l2-device.h> | ||
5393 | -#include <media/v4l2-common.h> | ||
5394 | -#include <media/v4l2-ctrls.h> | ||
5395 | -#include <media/v4l2-dv-timings.h> | ||
5396 | -#include <media/i2c/adv7511.h> | ||
5397 | -#include <media/cec.h> | ||
5398 | - | ||
5399 | -static int debug; | ||
5400 | -module_param(debug, int, 0644); | ||
5401 | -MODULE_PARM_DESC(debug, "debug level (0-2)"); | ||
5402 | - | ||
5403 | -MODULE_DESCRIPTION("Analog Devices ADV7511 HDMI Transmitter Device Driver"); | ||
5404 | -MODULE_AUTHOR("Hans Verkuil"); | ||
5405 | -MODULE_LICENSE("GPL v2"); | ||
5406 | - | ||
5407 | -#define MASK_ADV7511_EDID_RDY_INT 0x04 | ||
5408 | -#define MASK_ADV7511_MSEN_INT 0x40 | ||
5409 | -#define MASK_ADV7511_HPD_INT 0x80 | ||
5410 | - | ||
5411 | -#define MASK_ADV7511_HPD_DETECT 0x40 | ||
5412 | -#define MASK_ADV7511_MSEN_DETECT 0x20 | ||
5413 | -#define MASK_ADV7511_EDID_RDY 0x10 | ||
5414 | - | ||
5415 | -#define EDID_MAX_RETRIES (8) | ||
5416 | -#define EDID_DELAY 250 | ||
5417 | -#define EDID_MAX_SEGM 8 | ||
5418 | - | ||
5419 | -#define ADV7511_MAX_WIDTH 1920 | ||
5420 | -#define ADV7511_MAX_HEIGHT 1200 | ||
5421 | -#define ADV7511_MIN_PIXELCLOCK 20000000 | ||
5422 | -#define ADV7511_MAX_PIXELCLOCK 225000000 | ||
5423 | - | ||
5424 | -#define ADV7511_MAX_ADDRS (3) | ||
5425 | - | ||
5426 | -/* | ||
5427 | -********************************************************************** | ||
5428 | -* | ||
5429 | -* Arrays with configuration parameters for the ADV7511 | ||
5430 | -* | ||
5431 | -********************************************************************** | ||
5432 | -*/ | ||
5433 | - | ||
5434 | -struct i2c_reg_value { | ||
5435 | - unsigned char reg; | ||
5436 | - unsigned char value; | ||
5437 | -}; | ||
5438 | - | ||
5439 | -struct adv7511_state_edid { | ||
5440 | - /* total number of blocks */ | ||
5441 | - u32 blocks; | ||
5442 | - /* Number of segments read */ | ||
5443 | - u32 segments; | ||
5444 | - u8 data[EDID_MAX_SEGM * 256]; | ||
5445 | - /* Number of EDID read retries left */ | ||
5446 | - unsigned read_retries; | ||
5447 | - bool complete; | ||
5448 | -}; | ||
5449 | - | ||
5450 | -struct adv7511_state { | ||
5451 | - struct adv7511_platform_data pdata; | ||
5452 | - struct v4l2_subdev sd; | ||
5453 | - struct media_pad pad; | ||
5454 | - struct v4l2_ctrl_handler hdl; | ||
5455 | - int chip_revision; | ||
5456 | - u8 i2c_edid_addr; | ||
5457 | - u8 i2c_pktmem_addr; | ||
5458 | - u8 i2c_cec_addr; | ||
5459 | - | ||
5460 | - struct i2c_client *i2c_cec; | ||
5461 | - struct cec_adapter *cec_adap; | ||
5462 | - u8 cec_addr[ADV7511_MAX_ADDRS]; | ||
5463 | - u8 cec_valid_addrs; | ||
5464 | - bool cec_enabled_adap; | ||
5465 | - | ||
5466 | - /* Is the adv7511 powered on? */ | ||
5467 | - bool power_on; | ||
5468 | - /* Did we receive hotplug and rx-sense signals? */ | ||
5469 | - bool have_monitor; | ||
5470 | - bool enabled_irq; | ||
5471 | - /* timings from s_dv_timings */ | ||
5472 | - struct v4l2_dv_timings dv_timings; | ||
5473 | - u32 fmt_code; | ||
5474 | - u32 colorspace; | ||
5475 | - u32 ycbcr_enc; | ||
5476 | - u32 quantization; | ||
5477 | - u32 xfer_func; | ||
5478 | - u32 content_type; | ||
5479 | - /* controls */ | ||
5480 | - struct v4l2_ctrl *hdmi_mode_ctrl; | ||
5481 | - struct v4l2_ctrl *hotplug_ctrl; | ||
5482 | - struct v4l2_ctrl *rx_sense_ctrl; | ||
5483 | - struct v4l2_ctrl *have_edid0_ctrl; | ||
5484 | - struct v4l2_ctrl *rgb_quantization_range_ctrl; | ||
5485 | - struct v4l2_ctrl *content_type_ctrl; | ||
5486 | - struct i2c_client *i2c_edid; | ||
5487 | - struct i2c_client *i2c_pktmem; | ||
5488 | - struct adv7511_state_edid edid; | ||
5489 | - /* Running counter of the number of detected EDIDs (for debugging) */ | ||
5490 | - unsigned edid_detect_counter; | ||
5491 | - struct workqueue_struct *work_queue; | ||
5492 | - struct delayed_work edid_handler; /* work entry */ | ||
5493 | -}; | ||
5494 | - | ||
5495 | -static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd); | ||
5496 | -static bool adv7511_check_edid_status(struct v4l2_subdev *sd); | ||
5497 | -static void adv7511_setup(struct v4l2_subdev *sd); | ||
5498 | -static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq); | ||
5499 | -static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq); | ||
5500 | - | ||
5501 | - | ||
5502 | -static const struct v4l2_dv_timings_cap adv7511_timings_cap = { | ||
5503 | - .type = V4L2_DV_BT_656_1120, | ||
5504 | - /* keep this initialization for compatibility with GCC < 4.4.6 */ | ||
5505 | - .reserved = { 0 }, | ||
5506 | - V4L2_INIT_BT_TIMINGS(640, ADV7511_MAX_WIDTH, 350, ADV7511_MAX_HEIGHT, | ||
5507 | - ADV7511_MIN_PIXELCLOCK, ADV7511_MAX_PIXELCLOCK, | ||
5508 | - V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT | | ||
5509 | - V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT, | ||
5510 | - V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING | | ||
5511 | - V4L2_DV_BT_CAP_CUSTOM) | ||
5512 | -}; | ||
5513 | - | ||
5514 | -static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd) | ||
5515 | -{ | ||
5516 | - return container_of(sd, struct adv7511_state, sd); | ||
5517 | -} | ||
5518 | - | ||
5519 | -static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) | ||
5520 | -{ | ||
5521 | - return &container_of(ctrl->handler, struct adv7511_state, hdl)->sd; | ||
5522 | -} | ||
5523 | - | ||
5524 | -/* ------------------------ I2C ----------------------------------------------- */ | ||
5525 | - | ||
5526 | -static s32 adv_smbus_read_byte_data_check(struct i2c_client *client, | ||
5527 | - u8 command, bool check) | ||
5528 | -{ | ||
5529 | - union i2c_smbus_data data; | ||
5530 | - | ||
5531 | - if (!i2c_smbus_xfer(client->adapter, client->addr, client->flags, | ||
5532 | - I2C_SMBUS_READ, command, | ||
5533 | - I2C_SMBUS_BYTE_DATA, &data)) | ||
5534 | - return data.byte; | ||
5535 | - if (check) | ||
5536 | - v4l_err(client, "error reading %02x, %02x\n", | ||
5537 | - client->addr, command); | ||
5538 | - return -1; | ||
5539 | -} | ||
5540 | - | ||
5541 | -static s32 adv_smbus_read_byte_data(struct i2c_client *client, u8 command) | ||
5542 | -{ | ||
5543 | - int i; | ||
5544 | - for (i = 0; i < 3; i++) { | ||
5545 | - int ret = adv_smbus_read_byte_data_check(client, command, true); | ||
5546 | - if (ret >= 0) { | ||
5547 | - if (i) | ||
5548 | - v4l_err(client, "read ok after %d retries\n", i); | ||
5549 | - return ret; | ||
5550 | - } | ||
5551 | - } | ||
5552 | - v4l_err(client, "read failed\n"); | ||
5553 | - return -1; | ||
5554 | -} | ||
5555 | - | ||
5556 | -static int adv7511_rd(struct v4l2_subdev *sd, u8 reg) | ||
5557 | -{ | ||
5558 | - struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
5559 | - | ||
5560 | - return adv_smbus_read_byte_data(client, reg); | ||
5561 | -} | ||
5562 | - | ||
5563 | -static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val) | ||
5564 | -{ | ||
5565 | - struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
5566 | - int ret; | ||
5567 | - int i; | ||
5568 | - | ||
5569 | - for (i = 0; i < 3; i++) { | ||
5570 | - ret = i2c_smbus_write_byte_data(client, reg, val); | ||
5571 | - if (ret == 0) | ||
5572 | - return 0; | ||
5573 | - } | ||
5574 | - v4l2_err(sd, "%s: i2c write error\n", __func__); | ||
5575 | - return ret; | ||
5576 | -} | ||
5577 | - | ||
5578 | -/* To set specific bits in the register, a clear-mask is given (to be AND-ed), | ||
5579 | - and then the value-mask (to be OR-ed). */ | ||
5580 | -static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask) | ||
5581 | -{ | ||
5582 | - adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask); | ||
5583 | -} | ||
5584 | - | ||
5585 | -static int adv_smbus_read_i2c_block_data(struct i2c_client *client, | ||
5586 | - u8 command, unsigned length, u8 *values) | ||
5587 | -{ | ||
5588 | - union i2c_smbus_data data; | ||
5589 | - int ret; | ||
5590 | - | ||
5591 | - if (length > I2C_SMBUS_BLOCK_MAX) | ||
5592 | - length = I2C_SMBUS_BLOCK_MAX; | ||
5593 | - data.block[0] = length; | ||
5594 | - | ||
5595 | - ret = i2c_smbus_xfer(client->adapter, client->addr, client->flags, | ||
5596 | - I2C_SMBUS_READ, command, | ||
5597 | - I2C_SMBUS_I2C_BLOCK_DATA, &data); | ||
5598 | - memcpy(values, data.block + 1, length); | ||
5599 | - return ret; | ||
5600 | -} | ||
5601 | - | ||
5602 | -static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf) | ||
5603 | -{ | ||
5604 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5605 | - int i; | ||
5606 | - int err = 0; | ||
5607 | - | ||
5608 | - v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
5609 | - | ||
5610 | - for (i = 0; !err && i < len; i += I2C_SMBUS_BLOCK_MAX) | ||
5611 | - err = adv_smbus_read_i2c_block_data(state->i2c_edid, i, | ||
5612 | - I2C_SMBUS_BLOCK_MAX, buf + i); | ||
5613 | - if (err) | ||
5614 | - v4l2_err(sd, "%s: i2c read error\n", __func__); | ||
5615 | -} | ||
5616 | - | ||
5617 | -static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg) | ||
5618 | -{ | ||
5619 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5620 | - | ||
5621 | - return i2c_smbus_read_byte_data(state->i2c_cec, reg); | ||
5622 | -} | ||
5623 | - | ||
5624 | -static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) | ||
5625 | -{ | ||
5626 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5627 | - int ret; | ||
5628 | - int i; | ||
5629 | - | ||
5630 | - for (i = 0; i < 3; i++) { | ||
5631 | - ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val); | ||
5632 | - if (ret == 0) | ||
5633 | - return 0; | ||
5634 | - } | ||
5635 | - v4l2_err(sd, "%s: I2C Write Problem\n", __func__); | ||
5636 | - return ret; | ||
5637 | -} | ||
5638 | - | ||
5639 | -static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, | ||
5640 | - u8 val) | ||
5641 | -{ | ||
5642 | - return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val); | ||
5643 | -} | ||
5644 | - | ||
5645 | -static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg) | ||
5646 | -{ | ||
5647 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5648 | - | ||
5649 | - return adv_smbus_read_byte_data(state->i2c_pktmem, reg); | ||
5650 | -} | ||
5651 | - | ||
5652 | -static int adv7511_pktmem_wr(struct v4l2_subdev *sd, u8 reg, u8 val) | ||
5653 | -{ | ||
5654 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5655 | - int ret; | ||
5656 | - int i; | ||
5657 | - | ||
5658 | - for (i = 0; i < 3; i++) { | ||
5659 | - ret = i2c_smbus_write_byte_data(state->i2c_pktmem, reg, val); | ||
5660 | - if (ret == 0) | ||
5661 | - return 0; | ||
5662 | - } | ||
5663 | - v4l2_err(sd, "%s: i2c write error\n", __func__); | ||
5664 | - return ret; | ||
5665 | -} | ||
5666 | - | ||
5667 | -/* To set specific bits in the register, a clear-mask is given (to be AND-ed), | ||
5668 | - and then the value-mask (to be OR-ed). */ | ||
5669 | -static inline void adv7511_pktmem_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask) | ||
5670 | -{ | ||
5671 | - adv7511_pktmem_wr(sd, reg, (adv7511_pktmem_rd(sd, reg) & clr_mask) | val_mask); | ||
5672 | -} | ||
5673 | - | ||
5674 | -static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd) | ||
5675 | -{ | ||
5676 | - return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT; | ||
5677 | -} | ||
5678 | - | ||
5679 | -static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd) | ||
5680 | -{ | ||
5681 | - return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT; | ||
5682 | -} | ||
5683 | - | ||
5684 | -static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode) | ||
5685 | -{ | ||
5686 | - adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5); | ||
5687 | -} | ||
5688 | - | ||
5689 | -static void adv7511_csc_coeff(struct v4l2_subdev *sd, | ||
5690 | - u16 A1, u16 A2, u16 A3, u16 A4, | ||
5691 | - u16 B1, u16 B2, u16 B3, u16 B4, | ||
5692 | - u16 C1, u16 C2, u16 C3, u16 C4) | ||
5693 | -{ | ||
5694 | - /* A */ | ||
5695 | - adv7511_wr_and_or(sd, 0x18, 0xe0, A1>>8); | ||
5696 | - adv7511_wr(sd, 0x19, A1); | ||
5697 | - adv7511_wr_and_or(sd, 0x1A, 0xe0, A2>>8); | ||
5698 | - adv7511_wr(sd, 0x1B, A2); | ||
5699 | - adv7511_wr_and_or(sd, 0x1c, 0xe0, A3>>8); | ||
5700 | - adv7511_wr(sd, 0x1d, A3); | ||
5701 | - adv7511_wr_and_or(sd, 0x1e, 0xe0, A4>>8); | ||
5702 | - adv7511_wr(sd, 0x1f, A4); | ||
5703 | - | ||
5704 | - /* B */ | ||
5705 | - adv7511_wr_and_or(sd, 0x20, 0xe0, B1>>8); | ||
5706 | - adv7511_wr(sd, 0x21, B1); | ||
5707 | - adv7511_wr_and_or(sd, 0x22, 0xe0, B2>>8); | ||
5708 | - adv7511_wr(sd, 0x23, B2); | ||
5709 | - adv7511_wr_and_or(sd, 0x24, 0xe0, B3>>8); | ||
5710 | - adv7511_wr(sd, 0x25, B3); | ||
5711 | - adv7511_wr_and_or(sd, 0x26, 0xe0, B4>>8); | ||
5712 | - adv7511_wr(sd, 0x27, B4); | ||
5713 | - | ||
5714 | - /* C */ | ||
5715 | - adv7511_wr_and_or(sd, 0x28, 0xe0, C1>>8); | ||
5716 | - adv7511_wr(sd, 0x29, C1); | ||
5717 | - adv7511_wr_and_or(sd, 0x2A, 0xe0, C2>>8); | ||
5718 | - adv7511_wr(sd, 0x2B, C2); | ||
5719 | - adv7511_wr_and_or(sd, 0x2C, 0xe0, C3>>8); | ||
5720 | - adv7511_wr(sd, 0x2D, C3); | ||
5721 | - adv7511_wr_and_or(sd, 0x2E, 0xe0, C4>>8); | ||
5722 | - adv7511_wr(sd, 0x2F, C4); | ||
5723 | -} | ||
5724 | - | ||
5725 | -static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable) | ||
5726 | -{ | ||
5727 | - if (enable) { | ||
5728 | - u8 csc_mode = 0; | ||
5729 | - adv7511_csc_conversion_mode(sd, csc_mode); | ||
5730 | - adv7511_csc_coeff(sd, | ||
5731 | - 4096-564, 0, 0, 256, | ||
5732 | - 0, 4096-564, 0, 256, | ||
5733 | - 0, 0, 4096-564, 256); | ||
5734 | - /* enable CSC */ | ||
5735 | - adv7511_wr_and_or(sd, 0x18, 0x7f, 0x80); | ||
5736 | - /* AVI infoframe: Limited range RGB (16-235) */ | ||
5737 | - adv7511_wr_and_or(sd, 0x57, 0xf3, 0x04); | ||
5738 | - } else { | ||
5739 | - /* disable CSC */ | ||
5740 | - adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); | ||
5741 | - /* AVI infoframe: Full range RGB (0-255) */ | ||
5742 | - adv7511_wr_and_or(sd, 0x57, 0xf3, 0x08); | ||
5743 | - } | ||
5744 | -} | ||
5745 | - | ||
5746 | -static void adv7511_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl) | ||
5747 | -{ | ||
5748 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5749 | - | ||
5750 | - /* Only makes sense for RGB formats */ | ||
5751 | - if (state->fmt_code != MEDIA_BUS_FMT_RGB888_1X24) { | ||
5752 | - /* so just keep quantization */ | ||
5753 | - adv7511_csc_rgb_full2limit(sd, false); | ||
5754 | - return; | ||
5755 | - } | ||
5756 | - | ||
5757 | - switch (ctrl->val) { | ||
5758 | - case V4L2_DV_RGB_RANGE_AUTO: | ||
5759 | - /* automatic */ | ||
5760 | - if (state->dv_timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) { | ||
5761 | - /* CE format, RGB limited range (16-235) */ | ||
5762 | - adv7511_csc_rgb_full2limit(sd, true); | ||
5763 | - } else { | ||
5764 | - /* not CE format, RGB full range (0-255) */ | ||
5765 | - adv7511_csc_rgb_full2limit(sd, false); | ||
5766 | - } | ||
5767 | - break; | ||
5768 | - case V4L2_DV_RGB_RANGE_LIMITED: | ||
5769 | - /* RGB limited range (16-235) */ | ||
5770 | - adv7511_csc_rgb_full2limit(sd, true); | ||
5771 | - break; | ||
5772 | - case V4L2_DV_RGB_RANGE_FULL: | ||
5773 | - /* RGB full range (0-255) */ | ||
5774 | - adv7511_csc_rgb_full2limit(sd, false); | ||
5775 | - break; | ||
5776 | - } | ||
5777 | -} | ||
5778 | - | ||
5779 | -/* ------------------------------ CTRL OPS ------------------------------ */ | ||
5780 | - | ||
5781 | -static int adv7511_s_ctrl(struct v4l2_ctrl *ctrl) | ||
5782 | -{ | ||
5783 | - struct v4l2_subdev *sd = to_sd(ctrl); | ||
5784 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5785 | - | ||
5786 | - v4l2_dbg(1, debug, sd, "%s: ctrl id: %d, ctrl->val %d\n", __func__, ctrl->id, ctrl->val); | ||
5787 | - | ||
5788 | - if (state->hdmi_mode_ctrl == ctrl) { | ||
5789 | - /* Set HDMI or DVI-D */ | ||
5790 | - adv7511_wr_and_or(sd, 0xaf, 0xfd, ctrl->val == V4L2_DV_TX_MODE_HDMI ? 0x02 : 0x00); | ||
5791 | - return 0; | ||
5792 | - } | ||
5793 | - if (state->rgb_quantization_range_ctrl == ctrl) { | ||
5794 | - adv7511_set_rgb_quantization_mode(sd, ctrl); | ||
5795 | - return 0; | ||
5796 | - } | ||
5797 | - if (state->content_type_ctrl == ctrl) { | ||
5798 | - u8 itc, cn; | ||
5799 | - | ||
5800 | - state->content_type = ctrl->val; | ||
5801 | - itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC; | ||
5802 | - cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS; | ||
5803 | - adv7511_wr_and_or(sd, 0x57, 0x7f, itc << 7); | ||
5804 | - adv7511_wr_and_or(sd, 0x59, 0xcf, cn << 4); | ||
5805 | - return 0; | ||
5806 | - } | ||
5807 | - | ||
5808 | - return -EINVAL; | ||
5809 | -} | ||
5810 | - | ||
5811 | -static const struct v4l2_ctrl_ops adv7511_ctrl_ops = { | ||
5812 | - .s_ctrl = adv7511_s_ctrl, | ||
5813 | -}; | ||
5814 | - | ||
5815 | -/* ---------------------------- CORE OPS ------------------------------------------- */ | ||
5816 | - | ||
5817 | -#ifdef CONFIG_VIDEO_ADV_DEBUG | ||
5818 | -static void adv7511_inv_register(struct v4l2_subdev *sd) | ||
5819 | -{ | ||
5820 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5821 | - | ||
5822 | - v4l2_info(sd, "0x000-0x0ff: Main Map\n"); | ||
5823 | - if (state->i2c_cec) | ||
5824 | - v4l2_info(sd, "0x100-0x1ff: CEC Map\n"); | ||
5825 | -} | ||
5826 | - | ||
5827 | -static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) | ||
5828 | -{ | ||
5829 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5830 | - | ||
5831 | - reg->size = 1; | ||
5832 | - switch (reg->reg >> 8) { | ||
5833 | - case 0: | ||
5834 | - reg->val = adv7511_rd(sd, reg->reg & 0xff); | ||
5835 | - break; | ||
5836 | - case 1: | ||
5837 | - if (state->i2c_cec) { | ||
5838 | - reg->val = adv7511_cec_read(sd, reg->reg & 0xff); | ||
5839 | - break; | ||
5840 | - } | ||
5841 | - /* fall through */ | ||
5842 | - default: | ||
5843 | - v4l2_info(sd, "Register %03llx not supported\n", reg->reg); | ||
5844 | - adv7511_inv_register(sd); | ||
5845 | - break; | ||
5846 | - } | ||
5847 | - return 0; | ||
5848 | -} | ||
5849 | - | ||
5850 | -static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) | ||
5851 | -{ | ||
5852 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5853 | - | ||
5854 | - switch (reg->reg >> 8) { | ||
5855 | - case 0: | ||
5856 | - adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff); | ||
5857 | - break; | ||
5858 | - case 1: | ||
5859 | - if (state->i2c_cec) { | ||
5860 | - adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff); | ||
5861 | - break; | ||
5862 | - } | ||
5863 | - /* fall through */ | ||
5864 | - default: | ||
5865 | - v4l2_info(sd, "Register %03llx not supported\n", reg->reg); | ||
5866 | - adv7511_inv_register(sd); | ||
5867 | - break; | ||
5868 | - } | ||
5869 | - return 0; | ||
5870 | -} | ||
5871 | -#endif | ||
5872 | - | ||
5873 | -struct adv7511_cfg_read_infoframe { | ||
5874 | - const char *desc; | ||
5875 | - u8 present_reg; | ||
5876 | - u8 present_mask; | ||
5877 | - u8 header[3]; | ||
5878 | - u16 payload_addr; | ||
5879 | -}; | ||
5880 | - | ||
5881 | -static u8 hdmi_infoframe_checksum(u8 *ptr, size_t size) | ||
5882 | -{ | ||
5883 | - u8 csum = 0; | ||
5884 | - size_t i; | ||
5885 | - | ||
5886 | - /* compute checksum */ | ||
5887 | - for (i = 0; i < size; i++) | ||
5888 | - csum += ptr[i]; | ||
5889 | - | ||
5890 | - return 256 - csum; | ||
5891 | -} | ||
5892 | - | ||
5893 | -static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri) | ||
5894 | -{ | ||
5895 | - struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
5896 | - struct device *dev = &client->dev; | ||
5897 | - union hdmi_infoframe frame; | ||
5898 | - u8 buffer[32]; | ||
5899 | - u8 len; | ||
5900 | - int i; | ||
5901 | - | ||
5902 | - if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) { | ||
5903 | - v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc); | ||
5904 | - return; | ||
5905 | - } | ||
5906 | - | ||
5907 | - memcpy(buffer, cri->header, sizeof(cri->header)); | ||
5908 | - | ||
5909 | - len = buffer[2]; | ||
5910 | - | ||
5911 | - if (len + 4 > sizeof(buffer)) { | ||
5912 | - v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len); | ||
5913 | - return; | ||
5914 | - } | ||
5915 | - | ||
5916 | - if (cri->payload_addr >= 0x100) { | ||
5917 | - for (i = 0; i < len; i++) | ||
5918 | - buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100); | ||
5919 | - } else { | ||
5920 | - for (i = 0; i < len; i++) | ||
5921 | - buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i); | ||
5922 | - } | ||
5923 | - buffer[3] = 0; | ||
5924 | - buffer[3] = hdmi_infoframe_checksum(buffer, len + 4); | ||
5925 | - | ||
5926 | - if (hdmi_infoframe_unpack(&frame, buffer) < 0) { | ||
5927 | - v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc); | ||
5928 | - return; | ||
5929 | - } | ||
5930 | - | ||
5931 | - hdmi_infoframe_log(KERN_INFO, dev, &frame); | ||
5932 | -} | ||
5933 | - | ||
5934 | -static void adv7511_log_infoframes(struct v4l2_subdev *sd) | ||
5935 | -{ | ||
5936 | - static const struct adv7511_cfg_read_infoframe cri[] = { | ||
5937 | - { "AVI", 0x44, 0x10, { 0x82, 2, 13 }, 0x55 }, | ||
5938 | - { "Audio", 0x44, 0x08, { 0x84, 1, 10 }, 0x73 }, | ||
5939 | - { "SDP", 0x40, 0x40, { 0x83, 1, 25 }, 0x103 }, | ||
5940 | - }; | ||
5941 | - int i; | ||
5942 | - | ||
5943 | - for (i = 0; i < ARRAY_SIZE(cri); i++) | ||
5944 | - log_infoframe(sd, &cri[i]); | ||
5945 | -} | ||
5946 | - | ||
5947 | -static int adv7511_log_status(struct v4l2_subdev *sd) | ||
5948 | -{ | ||
5949 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
5950 | - struct adv7511_state_edid *edid = &state->edid; | ||
5951 | - int i; | ||
5952 | - | ||
5953 | - static const char * const states[] = { | ||
5954 | - "in reset", | ||
5955 | - "reading EDID", | ||
5956 | - "idle", | ||
5957 | - "initializing HDCP", | ||
5958 | - "HDCP enabled", | ||
5959 | - "initializing HDCP repeater", | ||
5960 | - "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" | ||
5961 | - }; | ||
5962 | - static const char * const errors[] = { | ||
5963 | - "no error", | ||
5964 | - "bad receiver BKSV", | ||
5965 | - "Ri mismatch", | ||
5966 | - "Pj mismatch", | ||
5967 | - "i2c error", | ||
5968 | - "timed out", | ||
5969 | - "max repeater cascade exceeded", | ||
5970 | - "hash check failed", | ||
5971 | - "too many devices", | ||
5972 | - "9", "A", "B", "C", "D", "E", "F" | ||
5973 | - }; | ||
5974 | - | ||
5975 | - v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off"); | ||
5976 | - v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n", | ||
5977 | - (adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT) ? "detected" : "no", | ||
5978 | - (adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT) ? "detected" : "no", | ||
5979 | - edid->segments ? "found" : "no", | ||
5980 | - edid->blocks); | ||
5981 | - v4l2_info(sd, "%s output %s\n", | ||
5982 | - (adv7511_rd(sd, 0xaf) & 0x02) ? | ||
5983 | - "HDMI" : "DVI-D", | ||
5984 | - (adv7511_rd(sd, 0xa1) & 0x3c) ? | ||
5985 | - "disabled" : "enabled"); | ||
5986 | - v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n", | ||
5987 | - states[adv7511_rd(sd, 0xc8) & 0xf], | ||
5988 | - errors[adv7511_rd(sd, 0xc8) >> 4], state->edid_detect_counter, | ||
5989 | - adv7511_rd(sd, 0x94), adv7511_rd(sd, 0x96)); | ||
5990 | - v4l2_info(sd, "RGB quantization: %s range\n", adv7511_rd(sd, 0x18) & 0x80 ? "limited" : "full"); | ||
5991 | - if (adv7511_rd(sd, 0xaf) & 0x02) { | ||
5992 | - /* HDMI only */ | ||
5993 | - u8 manual_cts = adv7511_rd(sd, 0x0a) & 0x80; | ||
5994 | - u32 N = (adv7511_rd(sd, 0x01) & 0xf) << 16 | | ||
5995 | - adv7511_rd(sd, 0x02) << 8 | | ||
5996 | - adv7511_rd(sd, 0x03); | ||
5997 | - u8 vic_detect = adv7511_rd(sd, 0x3e) >> 2; | ||
5998 | - u8 vic_sent = adv7511_rd(sd, 0x3d) & 0x3f; | ||
5999 | - u32 CTS; | ||
6000 | - | ||
6001 | - if (manual_cts) | ||
6002 | - CTS = (adv7511_rd(sd, 0x07) & 0xf) << 16 | | ||
6003 | - adv7511_rd(sd, 0x08) << 8 | | ||
6004 | - adv7511_rd(sd, 0x09); | ||
6005 | - else | ||
6006 | - CTS = (adv7511_rd(sd, 0x04) & 0xf) << 16 | | ||
6007 | - adv7511_rd(sd, 0x05) << 8 | | ||
6008 | - adv7511_rd(sd, 0x06); | ||
6009 | - v4l2_info(sd, "CTS %s mode: N %d, CTS %d\n", | ||
6010 | - manual_cts ? "manual" : "automatic", N, CTS); | ||
6011 | - v4l2_info(sd, "VIC: detected %d, sent %d\n", | ||
6012 | - vic_detect, vic_sent); | ||
6013 | - adv7511_log_infoframes(sd); | ||
6014 | - } | ||
6015 | - if (state->dv_timings.type == V4L2_DV_BT_656_1120) | ||
6016 | - v4l2_print_dv_timings(sd->name, "timings: ", | ||
6017 | - &state->dv_timings, false); | ||
6018 | - else | ||
6019 | - v4l2_info(sd, "no timings set\n"); | ||
6020 | - v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr); | ||
6021 | - | ||
6022 | - if (state->i2c_cec == NULL) | ||
6023 | - return 0; | ||
6024 | - | ||
6025 | - v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr); | ||
6026 | - | ||
6027 | - v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ? | ||
6028 | - "enabled" : "disabled"); | ||
6029 | - if (state->cec_enabled_adap) { | ||
6030 | - for (i = 0; i < ADV7511_MAX_ADDRS; i++) { | ||
6031 | - bool is_valid = state->cec_valid_addrs & (1 << i); | ||
6032 | - | ||
6033 | - if (is_valid) | ||
6034 | - v4l2_info(sd, "CEC Logical Address: 0x%x\n", | ||
6035 | - state->cec_addr[i]); | ||
6036 | - } | ||
6037 | - } | ||
6038 | - v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr); | ||
6039 | - return 0; | ||
6040 | -} | ||
6041 | - | ||
6042 | -/* Power up/down adv7511 */ | ||
6043 | -static int adv7511_s_power(struct v4l2_subdev *sd, int on) | ||
6044 | -{ | ||
6045 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6046 | - const int retries = 20; | ||
6047 | - int i; | ||
6048 | - | ||
6049 | - v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off"); | ||
6050 | - | ||
6051 | - state->power_on = on; | ||
6052 | - | ||
6053 | - if (!on) { | ||
6054 | - /* Power down */ | ||
6055 | - adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); | ||
6056 | - return true; | ||
6057 | - } | ||
6058 | - | ||
6059 | - /* Power up */ | ||
6060 | - /* The adv7511 does not always come up immediately. | ||
6061 | - Retry multiple times. */ | ||
6062 | - for (i = 0; i < retries; i++) { | ||
6063 | - adv7511_wr_and_or(sd, 0x41, 0xbf, 0x0); | ||
6064 | - if ((adv7511_rd(sd, 0x41) & 0x40) == 0) | ||
6065 | - break; | ||
6066 | - adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); | ||
6067 | - msleep(10); | ||
6068 | - } | ||
6069 | - if (i == retries) { | ||
6070 | - v4l2_dbg(1, debug, sd, "%s: failed to powerup the adv7511!\n", __func__); | ||
6071 | - adv7511_s_power(sd, 0); | ||
6072 | - return false; | ||
6073 | - } | ||
6074 | - if (i > 1) | ||
6075 | - v4l2_dbg(1, debug, sd, "%s: needed %d retries to powerup the adv7511\n", __func__, i); | ||
6076 | - | ||
6077 | - /* Reserved registers that must be set */ | ||
6078 | - adv7511_wr(sd, 0x98, 0x03); | ||
6079 | - adv7511_wr_and_or(sd, 0x9a, 0xfe, 0x70); | ||
6080 | - adv7511_wr(sd, 0x9c, 0x30); | ||
6081 | - adv7511_wr_and_or(sd, 0x9d, 0xfc, 0x01); | ||
6082 | - adv7511_wr(sd, 0xa2, 0xa4); | ||
6083 | - adv7511_wr(sd, 0xa3, 0xa4); | ||
6084 | - adv7511_wr(sd, 0xe0, 0xd0); | ||
6085 | - adv7511_wr(sd, 0xf9, 0x00); | ||
6086 | - | ||
6087 | - adv7511_wr(sd, 0x43, state->i2c_edid_addr); | ||
6088 | - adv7511_wr(sd, 0x45, state->i2c_pktmem_addr); | ||
6089 | - | ||
6090 | - /* Set number of attempts to read the EDID */ | ||
6091 | - adv7511_wr(sd, 0xc9, 0xf); | ||
6092 | - return true; | ||
6093 | -} | ||
6094 | - | ||
6095 | -#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) | ||
6096 | -static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) | ||
6097 | -{ | ||
6098 | - struct adv7511_state *state = adap->priv; | ||
6099 | - struct v4l2_subdev *sd = &state->sd; | ||
6100 | - | ||
6101 | - if (state->i2c_cec == NULL) | ||
6102 | - return -EIO; | ||
6103 | - | ||
6104 | - if (!state->cec_enabled_adap && enable) { | ||
6105 | - /* power up cec section */ | ||
6106 | - adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01); | ||
6107 | - /* legacy mode and clear all rx buffers */ | ||
6108 | - adv7511_cec_write(sd, 0x4a, 0x07); | ||
6109 | - adv7511_cec_write(sd, 0x4a, 0); | ||
6110 | - adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */ | ||
6111 | - /* enabled irqs: */ | ||
6112 | - /* tx: ready */ | ||
6113 | - /* tx: arbitration lost */ | ||
6114 | - /* tx: retry timeout */ | ||
6115 | - /* rx: ready 1 */ | ||
6116 | - if (state->enabled_irq) | ||
6117 | - adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39); | ||
6118 | - } else if (state->cec_enabled_adap && !enable) { | ||
6119 | - if (state->enabled_irq) | ||
6120 | - adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00); | ||
6121 | - /* disable address mask 1-3 */ | ||
6122 | - adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00); | ||
6123 | - /* power down cec section */ | ||
6124 | - adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00); | ||
6125 | - state->cec_valid_addrs = 0; | ||
6126 | - } | ||
6127 | - state->cec_enabled_adap = enable; | ||
6128 | - return 0; | ||
6129 | -} | ||
6130 | - | ||
6131 | -static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr) | ||
6132 | -{ | ||
6133 | - struct adv7511_state *state = adap->priv; | ||
6134 | - struct v4l2_subdev *sd = &state->sd; | ||
6135 | - unsigned int i, free_idx = ADV7511_MAX_ADDRS; | ||
6136 | - | ||
6137 | - if (!state->cec_enabled_adap) | ||
6138 | - return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO; | ||
6139 | - | ||
6140 | - if (addr == CEC_LOG_ADDR_INVALID) { | ||
6141 | - adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0); | ||
6142 | - state->cec_valid_addrs = 0; | ||
6143 | - return 0; | ||
6144 | - } | ||
6145 | - | ||
6146 | - for (i = 0; i < ADV7511_MAX_ADDRS; i++) { | ||
6147 | - bool is_valid = state->cec_valid_addrs & (1 << i); | ||
6148 | - | ||
6149 | - if (free_idx == ADV7511_MAX_ADDRS && !is_valid) | ||
6150 | - free_idx = i; | ||
6151 | - if (is_valid && state->cec_addr[i] == addr) | ||
6152 | - return 0; | ||
6153 | - } | ||
6154 | - if (i == ADV7511_MAX_ADDRS) { | ||
6155 | - i = free_idx; | ||
6156 | - if (i == ADV7511_MAX_ADDRS) | ||
6157 | - return -ENXIO; | ||
6158 | - } | ||
6159 | - state->cec_addr[i] = addr; | ||
6160 | - state->cec_valid_addrs |= 1 << i; | ||
6161 | - | ||
6162 | - switch (i) { | ||
6163 | - case 0: | ||
6164 | - /* enable address mask 0 */ | ||
6165 | - adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10); | ||
6166 | - /* set address for mask 0 */ | ||
6167 | - adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr); | ||
6168 | - break; | ||
6169 | - case 1: | ||
6170 | - /* enable address mask 1 */ | ||
6171 | - adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20); | ||
6172 | - /* set address for mask 1 */ | ||
6173 | - adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4); | ||
6174 | - break; | ||
6175 | - case 2: | ||
6176 | - /* enable address mask 2 */ | ||
6177 | - adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40); | ||
6178 | - /* set address for mask 1 */ | ||
6179 | - adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr); | ||
6180 | - break; | ||
6181 | - } | ||
6182 | - return 0; | ||
6183 | -} | ||
6184 | - | ||
6185 | -static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, | ||
6186 | - u32 signal_free_time, struct cec_msg *msg) | ||
6187 | -{ | ||
6188 | - struct adv7511_state *state = adap->priv; | ||
6189 | - struct v4l2_subdev *sd = &state->sd; | ||
6190 | - u8 len = msg->len; | ||
6191 | - unsigned int i; | ||
6192 | - | ||
6193 | - v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len); | ||
6194 | - | ||
6195 | - if (len > 16) { | ||
6196 | - v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len); | ||
6197 | - return -EINVAL; | ||
6198 | - } | ||
6199 | - | ||
6200 | - /* | ||
6201 | - * The number of retries is the number of attempts - 1, but retry | ||
6202 | - * at least once. It's not clear if a value of 0 is allowed, so | ||
6203 | - * let's do at least one retry. | ||
6204 | - */ | ||
6205 | - adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4); | ||
6206 | - | ||
6207 | - /* blocking, clear cec tx irq status */ | ||
6208 | - adv7511_wr_and_or(sd, 0x97, 0xc7, 0x38); | ||
6209 | - | ||
6210 | - /* write data */ | ||
6211 | - for (i = 0; i < len; i++) | ||
6212 | - adv7511_cec_write(sd, i, msg->msg[i]); | ||
6213 | - | ||
6214 | - /* set length (data + header) */ | ||
6215 | - adv7511_cec_write(sd, 0x10, len); | ||
6216 | - /* start transmit, enable tx */ | ||
6217 | - adv7511_cec_write(sd, 0x11, 0x01); | ||
6218 | - return 0; | ||
6219 | -} | ||
6220 | - | ||
6221 | -static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status) | ||
6222 | -{ | ||
6223 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6224 | - | ||
6225 | - if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) { | ||
6226 | - v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__); | ||
6227 | - return; | ||
6228 | - } | ||
6229 | - | ||
6230 | - if (tx_raw_status & 0x10) { | ||
6231 | - v4l2_dbg(1, debug, sd, | ||
6232 | - "%s: tx raw: arbitration lost\n", __func__); | ||
6233 | - cec_transmit_done(state->cec_adap, CEC_TX_STATUS_ARB_LOST, | ||
6234 | - 1, 0, 0, 0); | ||
6235 | - return; | ||
6236 | - } | ||
6237 | - if (tx_raw_status & 0x08) { | ||
6238 | - u8 status; | ||
6239 | - u8 nack_cnt; | ||
6240 | - u8 low_drive_cnt; | ||
6241 | - | ||
6242 | - v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__); | ||
6243 | - /* | ||
6244 | - * We set this status bit since this hardware performs | ||
6245 | - * retransmissions. | ||
6246 | - */ | ||
6247 | - status = CEC_TX_STATUS_MAX_RETRIES; | ||
6248 | - nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf; | ||
6249 | - if (nack_cnt) | ||
6250 | - status |= CEC_TX_STATUS_NACK; | ||
6251 | - low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4; | ||
6252 | - if (low_drive_cnt) | ||
6253 | - status |= CEC_TX_STATUS_LOW_DRIVE; | ||
6254 | - cec_transmit_done(state->cec_adap, status, | ||
6255 | - 0, nack_cnt, low_drive_cnt, 0); | ||
6256 | - return; | ||
6257 | - } | ||
6258 | - if (tx_raw_status & 0x20) { | ||
6259 | - v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__); | ||
6260 | - cec_transmit_done(state->cec_adap, CEC_TX_STATUS_OK, 0, 0, 0, 0); | ||
6261 | - return; | ||
6262 | - } | ||
6263 | -} | ||
6264 | - | ||
6265 | -static const struct cec_adap_ops adv7511_cec_adap_ops = { | ||
6266 | - .adap_enable = adv7511_cec_adap_enable, | ||
6267 | - .adap_log_addr = adv7511_cec_adap_log_addr, | ||
6268 | - .adap_transmit = adv7511_cec_adap_transmit, | ||
6269 | -}; | ||
6270 | -#endif | ||
6271 | - | ||
6272 | -/* Enable interrupts */ | ||
6273 | -static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable) | ||
6274 | -{ | ||
6275 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6276 | - u8 irqs = MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT; | ||
6277 | - u8 irqs_rd; | ||
6278 | - int retries = 100; | ||
6279 | - | ||
6280 | - v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable"); | ||
6281 | - | ||
6282 | - if (state->enabled_irq == enable) | ||
6283 | - return; | ||
6284 | - state->enabled_irq = enable; | ||
6285 | - | ||
6286 | - /* The datasheet says that the EDID ready interrupt should be | ||
6287 | - disabled if there is no hotplug. */ | ||
6288 | - if (!enable) | ||
6289 | - irqs = 0; | ||
6290 | - else if (adv7511_have_hotplug(sd)) | ||
6291 | - irqs |= MASK_ADV7511_EDID_RDY_INT; | ||
6292 | - | ||
6293 | - adv7511_wr_and_or(sd, 0x95, 0xc0, | ||
6294 | - (state->cec_enabled_adap && enable) ? 0x39 : 0x00); | ||
6295 | - | ||
6296 | - /* | ||
6297 | - * This i2c write can fail (approx. 1 in 1000 writes). But it | ||
6298 | - * is essential that this register is correct, so retry it | ||
6299 | - * multiple times. | ||
6300 | - * | ||
6301 | - * Note that the i2c write does not report an error, but the readback | ||
6302 | - * clearly shows the wrong value. | ||
6303 | - */ | ||
6304 | - do { | ||
6305 | - adv7511_wr(sd, 0x94, irqs); | ||
6306 | - irqs_rd = adv7511_rd(sd, 0x94); | ||
6307 | - } while (retries-- && irqs_rd != irqs); | ||
6308 | - | ||
6309 | - if (irqs_rd == irqs) | ||
6310 | - return; | ||
6311 | - v4l2_err(sd, "Could not set interrupts: hw failure?\n"); | ||
6312 | -} | ||
6313 | - | ||
6314 | -/* Interrupt handler */ | ||
6315 | -static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled) | ||
6316 | -{ | ||
6317 | - u8 irq_status; | ||
6318 | - u8 cec_irq; | ||
6319 | - | ||
6320 | - /* disable interrupts to prevent a race condition */ | ||
6321 | - adv7511_set_isr(sd, false); | ||
6322 | - irq_status = adv7511_rd(sd, 0x96); | ||
6323 | - cec_irq = adv7511_rd(sd, 0x97); | ||
6324 | - /* clear detected interrupts */ | ||
6325 | - adv7511_wr(sd, 0x96, irq_status); | ||
6326 | - adv7511_wr(sd, 0x97, cec_irq); | ||
6327 | - | ||
6328 | - v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__, | ||
6329 | - irq_status, cec_irq); | ||
6330 | - | ||
6331 | - if (irq_status & (MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT)) | ||
6332 | - adv7511_check_monitor_present_status(sd); | ||
6333 | - if (irq_status & MASK_ADV7511_EDID_RDY_INT) | ||
6334 | - adv7511_check_edid_status(sd); | ||
6335 | - | ||
6336 | -#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) | ||
6337 | - if (cec_irq & 0x38) | ||
6338 | - adv_cec_tx_raw_status(sd, cec_irq); | ||
6339 | - | ||
6340 | - if (cec_irq & 1) { | ||
6341 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6342 | - struct cec_msg msg; | ||
6343 | - | ||
6344 | - msg.len = adv7511_cec_read(sd, 0x25) & 0x1f; | ||
6345 | - | ||
6346 | - v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__, | ||
6347 | - msg.len); | ||
6348 | - | ||
6349 | - if (msg.len > 16) | ||
6350 | - msg.len = 16; | ||
6351 | - | ||
6352 | - if (msg.len) { | ||
6353 | - u8 i; | ||
6354 | - | ||
6355 | - for (i = 0; i < msg.len; i++) | ||
6356 | - msg.msg[i] = adv7511_cec_read(sd, i + 0x15); | ||
6357 | - | ||
6358 | - adv7511_cec_write(sd, 0x4a, 1); /* toggle to re-enable rx 1 */ | ||
6359 | - adv7511_cec_write(sd, 0x4a, 0); | ||
6360 | - cec_received_msg(state->cec_adap, &msg); | ||
6361 | - } | ||
6362 | - } | ||
6363 | -#endif | ||
6364 | - | ||
6365 | - /* enable interrupts */ | ||
6366 | - adv7511_set_isr(sd, true); | ||
6367 | - | ||
6368 | - if (handled) | ||
6369 | - *handled = true; | ||
6370 | - return 0; | ||
6371 | -} | ||
6372 | - | ||
6373 | -static const struct v4l2_subdev_core_ops adv7511_core_ops = { | ||
6374 | - .log_status = adv7511_log_status, | ||
6375 | -#ifdef CONFIG_VIDEO_ADV_DEBUG | ||
6376 | - .g_register = adv7511_g_register, | ||
6377 | - .s_register = adv7511_s_register, | ||
6378 | -#endif | ||
6379 | - .s_power = adv7511_s_power, | ||
6380 | - .interrupt_service_routine = adv7511_isr, | ||
6381 | -}; | ||
6382 | - | ||
6383 | -/* ------------------------------ VIDEO OPS ------------------------------ */ | ||
6384 | - | ||
6385 | -/* Enable/disable adv7511 output */ | ||
6386 | -static int adv7511_s_stream(struct v4l2_subdev *sd, int enable) | ||
6387 | -{ | ||
6388 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6389 | - | ||
6390 | - v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); | ||
6391 | - adv7511_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c)); | ||
6392 | - if (enable) { | ||
6393 | - adv7511_check_monitor_present_status(sd); | ||
6394 | - } else { | ||
6395 | - adv7511_s_power(sd, 0); | ||
6396 | - state->have_monitor = false; | ||
6397 | - } | ||
6398 | - return 0; | ||
6399 | -} | ||
6400 | - | ||
6401 | -static int adv7511_s_dv_timings(struct v4l2_subdev *sd, | ||
6402 | - struct v4l2_dv_timings *timings) | ||
6403 | -{ | ||
6404 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6405 | - struct v4l2_bt_timings *bt = &timings->bt; | ||
6406 | - u32 fps; | ||
6407 | - | ||
6408 | - v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
6409 | - | ||
6410 | - /* quick sanity check */ | ||
6411 | - if (!v4l2_valid_dv_timings(timings, &adv7511_timings_cap, NULL, NULL)) | ||
6412 | - return -EINVAL; | ||
6413 | - | ||
6414 | - /* Fill the optional fields .standards and .flags in struct v4l2_dv_timings | ||
6415 | - if the format is one of the CEA or DMT timings. */ | ||
6416 | - v4l2_find_dv_timings_cap(timings, &adv7511_timings_cap, 0, NULL, NULL); | ||
6417 | - | ||
6418 | - /* save timings */ | ||
6419 | - state->dv_timings = *timings; | ||
6420 | - | ||
6421 | - /* set h/vsync polarities */ | ||
6422 | - adv7511_wr_and_or(sd, 0x17, 0x9f, | ||
6423 | - ((bt->polarities & V4L2_DV_VSYNC_POS_POL) ? 0 : 0x40) | | ||
6424 | - ((bt->polarities & V4L2_DV_HSYNC_POS_POL) ? 0 : 0x20)); | ||
6425 | - | ||
6426 | - fps = (u32)bt->pixelclock / (V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt)); | ||
6427 | - switch (fps) { | ||
6428 | - case 24: | ||
6429 | - adv7511_wr_and_or(sd, 0xfb, 0xf9, 1 << 1); | ||
6430 | - break; | ||
6431 | - case 25: | ||
6432 | - adv7511_wr_and_or(sd, 0xfb, 0xf9, 2 << 1); | ||
6433 | - break; | ||
6434 | - case 30: | ||
6435 | - adv7511_wr_and_or(sd, 0xfb, 0xf9, 3 << 1); | ||
6436 | - break; | ||
6437 | - default: | ||
6438 | - adv7511_wr_and_or(sd, 0xfb, 0xf9, 0); | ||
6439 | - break; | ||
6440 | - } | ||
6441 | - | ||
6442 | - /* update quantization range based on new dv_timings */ | ||
6443 | - adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); | ||
6444 | - | ||
6445 | - return 0; | ||
6446 | -} | ||
6447 | - | ||
6448 | -static int adv7511_g_dv_timings(struct v4l2_subdev *sd, | ||
6449 | - struct v4l2_dv_timings *timings) | ||
6450 | -{ | ||
6451 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6452 | - | ||
6453 | - v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
6454 | - | ||
6455 | - if (!timings) | ||
6456 | - return -EINVAL; | ||
6457 | - | ||
6458 | - *timings = state->dv_timings; | ||
6459 | - | ||
6460 | - return 0; | ||
6461 | -} | ||
6462 | - | ||
6463 | -static int adv7511_enum_dv_timings(struct v4l2_subdev *sd, | ||
6464 | - struct v4l2_enum_dv_timings *timings) | ||
6465 | -{ | ||
6466 | - if (timings->pad != 0) | ||
6467 | - return -EINVAL; | ||
6468 | - | ||
6469 | - return v4l2_enum_dv_timings_cap(timings, &adv7511_timings_cap, NULL, NULL); | ||
6470 | -} | ||
6471 | - | ||
6472 | -static int adv7511_dv_timings_cap(struct v4l2_subdev *sd, | ||
6473 | - struct v4l2_dv_timings_cap *cap) | ||
6474 | -{ | ||
6475 | - if (cap->pad != 0) | ||
6476 | - return -EINVAL; | ||
6477 | - | ||
6478 | - *cap = adv7511_timings_cap; | ||
6479 | - return 0; | ||
6480 | -} | ||
6481 | - | ||
6482 | -static const struct v4l2_subdev_video_ops adv7511_video_ops = { | ||
6483 | - .s_stream = adv7511_s_stream, | ||
6484 | - .s_dv_timings = adv7511_s_dv_timings, | ||
6485 | - .g_dv_timings = adv7511_g_dv_timings, | ||
6486 | -}; | ||
6487 | - | ||
6488 | -/* ------------------------------ AUDIO OPS ------------------------------ */ | ||
6489 | -static int adv7511_s_audio_stream(struct v4l2_subdev *sd, int enable) | ||
6490 | -{ | ||
6491 | - v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); | ||
6492 | - | ||
6493 | - if (enable) | ||
6494 | - adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x80); | ||
6495 | - else | ||
6496 | - adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x40); | ||
6497 | - | ||
6498 | - return 0; | ||
6499 | -} | ||
6500 | - | ||
6501 | -static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq) | ||
6502 | -{ | ||
6503 | - u32 N; | ||
6504 | - | ||
6505 | - switch (freq) { | ||
6506 | - case 32000: N = 4096; break; | ||
6507 | - case 44100: N = 6272; break; | ||
6508 | - case 48000: N = 6144; break; | ||
6509 | - case 88200: N = 12544; break; | ||
6510 | - case 96000: N = 12288; break; | ||
6511 | - case 176400: N = 25088; break; | ||
6512 | - case 192000: N = 24576; break; | ||
6513 | - default: | ||
6514 | - return -EINVAL; | ||
6515 | - } | ||
6516 | - | ||
6517 | - /* Set N (used with CTS to regenerate the audio clock) */ | ||
6518 | - adv7511_wr(sd, 0x01, (N >> 16) & 0xf); | ||
6519 | - adv7511_wr(sd, 0x02, (N >> 8) & 0xff); | ||
6520 | - adv7511_wr(sd, 0x03, N & 0xff); | ||
6521 | - | ||
6522 | - return 0; | ||
6523 | -} | ||
6524 | - | ||
6525 | -static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq) | ||
6526 | -{ | ||
6527 | - u32 i2s_sf; | ||
6528 | - | ||
6529 | - switch (freq) { | ||
6530 | - case 32000: i2s_sf = 0x30; break; | ||
6531 | - case 44100: i2s_sf = 0x00; break; | ||
6532 | - case 48000: i2s_sf = 0x20; break; | ||
6533 | - case 88200: i2s_sf = 0x80; break; | ||
6534 | - case 96000: i2s_sf = 0xa0; break; | ||
6535 | - case 176400: i2s_sf = 0xc0; break; | ||
6536 | - case 192000: i2s_sf = 0xe0; break; | ||
6537 | - default: | ||
6538 | - return -EINVAL; | ||
6539 | - } | ||
6540 | - | ||
6541 | - /* Set sampling frequency for I2S audio to 48 kHz */ | ||
6542 | - adv7511_wr_and_or(sd, 0x15, 0xf, i2s_sf); | ||
6543 | - | ||
6544 | - return 0; | ||
6545 | -} | ||
6546 | - | ||
6547 | -static int adv7511_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config) | ||
6548 | -{ | ||
6549 | - /* Only 2 channels in use for application */ | ||
6550 | - adv7511_wr_and_or(sd, 0x73, 0xf8, 0x1); | ||
6551 | - /* Speaker mapping */ | ||
6552 | - adv7511_wr(sd, 0x76, 0x00); | ||
6553 | - | ||
6554 | - /* 16 bit audio word length */ | ||
6555 | - adv7511_wr_and_or(sd, 0x14, 0xf0, 0x02); | ||
6556 | - | ||
6557 | - return 0; | ||
6558 | -} | ||
6559 | - | ||
6560 | -static const struct v4l2_subdev_audio_ops adv7511_audio_ops = { | ||
6561 | - .s_stream = adv7511_s_audio_stream, | ||
6562 | - .s_clock_freq = adv7511_s_clock_freq, | ||
6563 | - .s_i2s_clock_freq = adv7511_s_i2s_clock_freq, | ||
6564 | - .s_routing = adv7511_s_routing, | ||
6565 | -}; | ||
6566 | - | ||
6567 | -/* ---------------------------- PAD OPS ------------------------------------- */ | ||
6568 | - | ||
6569 | -static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid) | ||
6570 | -{ | ||
6571 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6572 | - | ||
6573 | - memset(edid->reserved, 0, sizeof(edid->reserved)); | ||
6574 | - | ||
6575 | - if (edid->pad != 0) | ||
6576 | - return -EINVAL; | ||
6577 | - | ||
6578 | - if (edid->start_block == 0 && edid->blocks == 0) { | ||
6579 | - edid->blocks = state->edid.segments * 2; | ||
6580 | - return 0; | ||
6581 | - } | ||
6582 | - | ||
6583 | - if (state->edid.segments == 0) | ||
6584 | - return -ENODATA; | ||
6585 | - | ||
6586 | - if (edid->start_block >= state->edid.segments * 2) | ||
6587 | - return -EINVAL; | ||
6588 | - | ||
6589 | - if (edid->start_block + edid->blocks > state->edid.segments * 2) | ||
6590 | - edid->blocks = state->edid.segments * 2 - edid->start_block; | ||
6591 | - | ||
6592 | - memcpy(edid->edid, &state->edid.data[edid->start_block * 128], | ||
6593 | - 128 * edid->blocks); | ||
6594 | - | ||
6595 | - return 0; | ||
6596 | -} | ||
6597 | - | ||
6598 | -static int adv7511_enum_mbus_code(struct v4l2_subdev *sd, | ||
6599 | - struct v4l2_subdev_pad_config *cfg, | ||
6600 | - struct v4l2_subdev_mbus_code_enum *code) | ||
6601 | -{ | ||
6602 | - if (code->pad != 0) | ||
6603 | - return -EINVAL; | ||
6604 | - | ||
6605 | - switch (code->index) { | ||
6606 | - case 0: | ||
6607 | - code->code = MEDIA_BUS_FMT_RGB888_1X24; | ||
6608 | - break; | ||
6609 | - case 1: | ||
6610 | - code->code = MEDIA_BUS_FMT_YUYV8_1X16; | ||
6611 | - break; | ||
6612 | - case 2: | ||
6613 | - code->code = MEDIA_BUS_FMT_UYVY8_1X16; | ||
6614 | - break; | ||
6615 | - default: | ||
6616 | - return -EINVAL; | ||
6617 | - } | ||
6618 | - return 0; | ||
6619 | -} | ||
6620 | - | ||
6621 | -static void adv7511_fill_format(struct adv7511_state *state, | ||
6622 | - struct v4l2_mbus_framefmt *format) | ||
6623 | -{ | ||
6624 | - format->width = state->dv_timings.bt.width; | ||
6625 | - format->height = state->dv_timings.bt.height; | ||
6626 | - format->field = V4L2_FIELD_NONE; | ||
6627 | -} | ||
6628 | - | ||
6629 | -static int adv7511_get_fmt(struct v4l2_subdev *sd, | ||
6630 | - struct v4l2_subdev_pad_config *cfg, | ||
6631 | - struct v4l2_subdev_format *format) | ||
6632 | -{ | ||
6633 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6634 | - | ||
6635 | - if (format->pad != 0) | ||
6636 | - return -EINVAL; | ||
6637 | - | ||
6638 | - memset(&format->format, 0, sizeof(format->format)); | ||
6639 | - adv7511_fill_format(state, &format->format); | ||
6640 | - | ||
6641 | - if (format->which == V4L2_SUBDEV_FORMAT_TRY) { | ||
6642 | - struct v4l2_mbus_framefmt *fmt; | ||
6643 | - | ||
6644 | - fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); | ||
6645 | - format->format.code = fmt->code; | ||
6646 | - format->format.colorspace = fmt->colorspace; | ||
6647 | - format->format.ycbcr_enc = fmt->ycbcr_enc; | ||
6648 | - format->format.quantization = fmt->quantization; | ||
6649 | - format->format.xfer_func = fmt->xfer_func; | ||
6650 | - } else { | ||
6651 | - format->format.code = state->fmt_code; | ||
6652 | - format->format.colorspace = state->colorspace; | ||
6653 | - format->format.ycbcr_enc = state->ycbcr_enc; | ||
6654 | - format->format.quantization = state->quantization; | ||
6655 | - format->format.xfer_func = state->xfer_func; | ||
6656 | - } | ||
6657 | - | ||
6658 | - return 0; | ||
6659 | -} | ||
6660 | - | ||
6661 | -static int adv7511_set_fmt(struct v4l2_subdev *sd, | ||
6662 | - struct v4l2_subdev_pad_config *cfg, | ||
6663 | - struct v4l2_subdev_format *format) | ||
6664 | -{ | ||
6665 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6666 | - /* | ||
6667 | - * Bitfield namings come the CEA-861-F standard, table 8 "Auxiliary | ||
6668 | - * Video Information (AVI) InfoFrame Format" | ||
6669 | - * | ||
6670 | - * c = Colorimetry | ||
6671 | - * ec = Extended Colorimetry | ||
6672 | - * y = RGB or YCbCr | ||
6673 | - * q = RGB Quantization Range | ||
6674 | - * yq = YCC Quantization Range | ||
6675 | - */ | ||
6676 | - u8 c = HDMI_COLORIMETRY_NONE; | ||
6677 | - u8 ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; | ||
6678 | - u8 y = HDMI_COLORSPACE_RGB; | ||
6679 | - u8 q = HDMI_QUANTIZATION_RANGE_DEFAULT; | ||
6680 | - u8 yq = HDMI_YCC_QUANTIZATION_RANGE_LIMITED; | ||
6681 | - u8 itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC; | ||
6682 | - u8 cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS; | ||
6683 | - | ||
6684 | - if (format->pad != 0) | ||
6685 | - return -EINVAL; | ||
6686 | - switch (format->format.code) { | ||
6687 | - case MEDIA_BUS_FMT_UYVY8_1X16: | ||
6688 | - case MEDIA_BUS_FMT_YUYV8_1X16: | ||
6689 | - case MEDIA_BUS_FMT_RGB888_1X24: | ||
6690 | - break; | ||
6691 | - default: | ||
6692 | - return -EINVAL; | ||
6693 | - } | ||
6694 | - | ||
6695 | - adv7511_fill_format(state, &format->format); | ||
6696 | - if (format->which == V4L2_SUBDEV_FORMAT_TRY) { | ||
6697 | - struct v4l2_mbus_framefmt *fmt; | ||
6698 | - | ||
6699 | - fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); | ||
6700 | - fmt->code = format->format.code; | ||
6701 | - fmt->colorspace = format->format.colorspace; | ||
6702 | - fmt->ycbcr_enc = format->format.ycbcr_enc; | ||
6703 | - fmt->quantization = format->format.quantization; | ||
6704 | - fmt->xfer_func = format->format.xfer_func; | ||
6705 | - return 0; | ||
6706 | - } | ||
6707 | - | ||
6708 | - switch (format->format.code) { | ||
6709 | - case MEDIA_BUS_FMT_UYVY8_1X16: | ||
6710 | - adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); | ||
6711 | - adv7511_wr_and_or(sd, 0x16, 0x03, 0xb8); | ||
6712 | - y = HDMI_COLORSPACE_YUV422; | ||
6713 | - break; | ||
6714 | - case MEDIA_BUS_FMT_YUYV8_1X16: | ||
6715 | - adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); | ||
6716 | - adv7511_wr_and_or(sd, 0x16, 0x03, 0xbc); | ||
6717 | - y = HDMI_COLORSPACE_YUV422; | ||
6718 | - break; | ||
6719 | - case MEDIA_BUS_FMT_RGB888_1X24: | ||
6720 | - default: | ||
6721 | - adv7511_wr_and_or(sd, 0x15, 0xf0, 0x00); | ||
6722 | - adv7511_wr_and_or(sd, 0x16, 0x03, 0x00); | ||
6723 | - break; | ||
6724 | - } | ||
6725 | - state->fmt_code = format->format.code; | ||
6726 | - state->colorspace = format->format.colorspace; | ||
6727 | - state->ycbcr_enc = format->format.ycbcr_enc; | ||
6728 | - state->quantization = format->format.quantization; | ||
6729 | - state->xfer_func = format->format.xfer_func; | ||
6730 | - | ||
6731 | - switch (format->format.colorspace) { | ||
6732 | - case V4L2_COLORSPACE_ADOBERGB: | ||
6733 | - c = HDMI_COLORIMETRY_EXTENDED; | ||
6734 | - ec = y ? HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601 : | ||
6735 | - HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB; | ||
6736 | - break; | ||
6737 | - case V4L2_COLORSPACE_SMPTE170M: | ||
6738 | - c = y ? HDMI_COLORIMETRY_ITU_601 : HDMI_COLORIMETRY_NONE; | ||
6739 | - if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV601) { | ||
6740 | - c = HDMI_COLORIMETRY_EXTENDED; | ||
6741 | - ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; | ||
6742 | - } | ||
6743 | - break; | ||
6744 | - case V4L2_COLORSPACE_REC709: | ||
6745 | - c = y ? HDMI_COLORIMETRY_ITU_709 : HDMI_COLORIMETRY_NONE; | ||
6746 | - if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV709) { | ||
6747 | - c = HDMI_COLORIMETRY_EXTENDED; | ||
6748 | - ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_709; | ||
6749 | - } | ||
6750 | - break; | ||
6751 | - case V4L2_COLORSPACE_SRGB: | ||
6752 | - c = y ? HDMI_COLORIMETRY_EXTENDED : HDMI_COLORIMETRY_NONE; | ||
6753 | - ec = y ? HDMI_EXTENDED_COLORIMETRY_S_YCC_601 : | ||
6754 | - HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; | ||
6755 | - break; | ||
6756 | - case V4L2_COLORSPACE_BT2020: | ||
6757 | - c = HDMI_COLORIMETRY_EXTENDED; | ||
6758 | - if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_BT2020_CONST_LUM) | ||
6759 | - ec = 5; /* Not yet available in hdmi.h */ | ||
6760 | - else | ||
6761 | - ec = 6; /* Not yet available in hdmi.h */ | ||
6762 | - break; | ||
6763 | - default: | ||
6764 | - break; | ||
6765 | - } | ||
6766 | - | ||
6767 | - /* | ||
6768 | - * CEA-861-F says that for RGB formats the YCC range must match the | ||
6769 | - * RGB range, although sources should ignore the YCC range. | ||
6770 | - * | ||
6771 | - * The RGB quantization range shouldn't be non-zero if the EDID doesn't | ||
6772 | - * have the Q bit set in the Video Capabilities Data Block, however this | ||
6773 | - * isn't checked at the moment. The assumption is that the application | ||
6774 | - * knows the EDID and can detect this. | ||
6775 | - * | ||
6776 | - * The same is true for the YCC quantization range: non-standard YCC | ||
6777 | - * quantization ranges should only be sent if the EDID has the YQ bit | ||
6778 | - * set in the Video Capabilities Data Block. | ||
6779 | - */ | ||
6780 | - switch (format->format.quantization) { | ||
6781 | - case V4L2_QUANTIZATION_FULL_RANGE: | ||
6782 | - q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT : | ||
6783 | - HDMI_QUANTIZATION_RANGE_FULL; | ||
6784 | - yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_FULL; | ||
6785 | - break; | ||
6786 | - case V4L2_QUANTIZATION_LIM_RANGE: | ||
6787 | - q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT : | ||
6788 | - HDMI_QUANTIZATION_RANGE_LIMITED; | ||
6789 | - yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_LIMITED; | ||
6790 | - break; | ||
6791 | - } | ||
6792 | - | ||
6793 | - adv7511_wr_and_or(sd, 0x4a, 0xbf, 0); | ||
6794 | - adv7511_wr_and_or(sd, 0x55, 0x9f, y << 5); | ||
6795 | - adv7511_wr_and_or(sd, 0x56, 0x3f, c << 6); | ||
6796 | - adv7511_wr_and_or(sd, 0x57, 0x83, (ec << 4) | (q << 2) | (itc << 7)); | ||
6797 | - adv7511_wr_and_or(sd, 0x59, 0x0f, (yq << 6) | (cn << 4)); | ||
6798 | - adv7511_wr_and_or(sd, 0x4a, 0xff, 1); | ||
6799 | - adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); | ||
6800 | - | ||
6801 | - return 0; | ||
6802 | -} | ||
6803 | - | ||
6804 | -static const struct v4l2_subdev_pad_ops adv7511_pad_ops = { | ||
6805 | - .get_edid = adv7511_get_edid, | ||
6806 | - .enum_mbus_code = adv7511_enum_mbus_code, | ||
6807 | - .get_fmt = adv7511_get_fmt, | ||
6808 | - .set_fmt = adv7511_set_fmt, | ||
6809 | - .enum_dv_timings = adv7511_enum_dv_timings, | ||
6810 | - .dv_timings_cap = adv7511_dv_timings_cap, | ||
6811 | -}; | ||
6812 | - | ||
6813 | -/* --------------------- SUBDEV OPS --------------------------------------- */ | ||
6814 | - | ||
6815 | -static const struct v4l2_subdev_ops adv7511_ops = { | ||
6816 | - .core = &adv7511_core_ops, | ||
6817 | - .pad = &adv7511_pad_ops, | ||
6818 | - .video = &adv7511_video_ops, | ||
6819 | - .audio = &adv7511_audio_ops, | ||
6820 | -}; | ||
6821 | - | ||
6822 | -/* ----------------------------------------------------------------------- */ | ||
6823 | -static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf) | ||
6824 | -{ | ||
6825 | - if (debug >= lvl) { | ||
6826 | - int i, j; | ||
6827 | - v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment); | ||
6828 | - for (i = 0; i < 256; i += 16) { | ||
6829 | - u8 b[128]; | ||
6830 | - u8 *bp = b; | ||
6831 | - if (i == 128) | ||
6832 | - v4l2_dbg(lvl, debug, sd, "\n"); | ||
6833 | - for (j = i; j < i + 16; j++) { | ||
6834 | - sprintf(bp, "0x%02x, ", buf[j]); | ||
6835 | - bp += 6; | ||
6836 | - } | ||
6837 | - bp[0] = '\0'; | ||
6838 | - v4l2_dbg(lvl, debug, sd, "%s\n", b); | ||
6839 | - } | ||
6840 | - } | ||
6841 | -} | ||
6842 | - | ||
6843 | -static void adv7511_notify_no_edid(struct v4l2_subdev *sd) | ||
6844 | -{ | ||
6845 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6846 | - struct adv7511_edid_detect ed; | ||
6847 | - | ||
6848 | - /* We failed to read the EDID, so send an event for this. */ | ||
6849 | - ed.present = false; | ||
6850 | - ed.segment = adv7511_rd(sd, 0xc4); | ||
6851 | - ed.phys_addr = CEC_PHYS_ADDR_INVALID; | ||
6852 | - cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); | ||
6853 | - v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); | ||
6854 | - v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x0); | ||
6855 | -} | ||
6856 | - | ||
6857 | -static void adv7511_edid_handler(struct work_struct *work) | ||
6858 | -{ | ||
6859 | - struct delayed_work *dwork = to_delayed_work(work); | ||
6860 | - struct adv7511_state *state = container_of(dwork, struct adv7511_state, edid_handler); | ||
6861 | - struct v4l2_subdev *sd = &state->sd; | ||
6862 | - | ||
6863 | - v4l2_dbg(1, debug, sd, "%s:\n", __func__); | ||
6864 | - | ||
6865 | - if (adv7511_check_edid_status(sd)) { | ||
6866 | - /* Return if we received the EDID. */ | ||
6867 | - return; | ||
6868 | - } | ||
6869 | - | ||
6870 | - if (adv7511_have_hotplug(sd)) { | ||
6871 | - /* We must retry reading the EDID several times, it is possible | ||
6872 | - * that initially the EDID couldn't be read due to i2c errors | ||
6873 | - * (DVI connectors are particularly prone to this problem). */ | ||
6874 | - if (state->edid.read_retries) { | ||
6875 | - state->edid.read_retries--; | ||
6876 | - v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__); | ||
6877 | - state->have_monitor = false; | ||
6878 | - adv7511_s_power(sd, false); | ||
6879 | - adv7511_s_power(sd, true); | ||
6880 | - queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
6881 | - return; | ||
6882 | - } | ||
6883 | - } | ||
6884 | - | ||
6885 | - /* We failed to read the EDID, so send an event for this. */ | ||
6886 | - adv7511_notify_no_edid(sd); | ||
6887 | - v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__); | ||
6888 | -} | ||
6889 | - | ||
6890 | -static void adv7511_audio_setup(struct v4l2_subdev *sd) | ||
6891 | -{ | ||
6892 | - v4l2_dbg(1, debug, sd, "%s\n", __func__); | ||
6893 | - | ||
6894 | - adv7511_s_i2s_clock_freq(sd, 48000); | ||
6895 | - adv7511_s_clock_freq(sd, 48000); | ||
6896 | - adv7511_s_routing(sd, 0, 0, 0); | ||
6897 | -} | ||
6898 | - | ||
6899 | -/* Configure hdmi transmitter. */ | ||
6900 | -static void adv7511_setup(struct v4l2_subdev *sd) | ||
6901 | -{ | ||
6902 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6903 | - v4l2_dbg(1, debug, sd, "%s\n", __func__); | ||
6904 | - | ||
6905 | - /* Input format: RGB 4:4:4 */ | ||
6906 | - adv7511_wr_and_or(sd, 0x15, 0xf0, 0x0); | ||
6907 | - /* Output format: RGB 4:4:4 */ | ||
6908 | - adv7511_wr_and_or(sd, 0x16, 0x7f, 0x0); | ||
6909 | - /* 1st order interpolation 4:2:2 -> 4:4:4 up conversion, Aspect ratio: 16:9 */ | ||
6910 | - adv7511_wr_and_or(sd, 0x17, 0xf9, 0x06); | ||
6911 | - /* Disable pixel repetition */ | ||
6912 | - adv7511_wr_and_or(sd, 0x3b, 0x9f, 0x0); | ||
6913 | - /* Disable CSC */ | ||
6914 | - adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); | ||
6915 | - /* Output format: RGB 4:4:4, Active Format Information is valid, | ||
6916 | - * underscanned */ | ||
6917 | - adv7511_wr_and_or(sd, 0x55, 0x9c, 0x12); | ||
6918 | - /* AVI Info frame packet enable, Audio Info frame disable */ | ||
6919 | - adv7511_wr_and_or(sd, 0x44, 0xe7, 0x10); | ||
6920 | - /* Colorimetry, Active format aspect ratio: same as picure. */ | ||
6921 | - adv7511_wr(sd, 0x56, 0xa8); | ||
6922 | - /* No encryption */ | ||
6923 | - adv7511_wr_and_or(sd, 0xaf, 0xed, 0x0); | ||
6924 | - | ||
6925 | - /* Positive clk edge capture for input video clock */ | ||
6926 | - adv7511_wr_and_or(sd, 0xba, 0x1f, 0x60); | ||
6927 | - | ||
6928 | - adv7511_audio_setup(sd); | ||
6929 | - | ||
6930 | - v4l2_ctrl_handler_setup(&state->hdl); | ||
6931 | -} | ||
6932 | - | ||
6933 | -static void adv7511_notify_monitor_detect(struct v4l2_subdev *sd) | ||
6934 | -{ | ||
6935 | - struct adv7511_monitor_detect mdt; | ||
6936 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6937 | - | ||
6938 | - mdt.present = state->have_monitor; | ||
6939 | - v4l2_subdev_notify(sd, ADV7511_MONITOR_DETECT, (void *)&mdt); | ||
6940 | -} | ||
6941 | - | ||
6942 | -static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd) | ||
6943 | -{ | ||
6944 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
6945 | - /* read hotplug and rx-sense state */ | ||
6946 | - u8 status = adv7511_rd(sd, 0x42); | ||
6947 | - | ||
6948 | - v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n", | ||
6949 | - __func__, | ||
6950 | - status, | ||
6951 | - status & MASK_ADV7511_HPD_DETECT ? ", hotplug" : "", | ||
6952 | - status & MASK_ADV7511_MSEN_DETECT ? ", rx-sense" : ""); | ||
6953 | - | ||
6954 | - /* update read only ctrls */ | ||
6955 | - v4l2_ctrl_s_ctrl(state->hotplug_ctrl, adv7511_have_hotplug(sd) ? 0x1 : 0x0); | ||
6956 | - v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, adv7511_have_rx_sense(sd) ? 0x1 : 0x0); | ||
6957 | - | ||
6958 | - if ((status & MASK_ADV7511_HPD_DETECT) && ((status & MASK_ADV7511_MSEN_DETECT) || state->edid.segments)) { | ||
6959 | - v4l2_dbg(1, debug, sd, "%s: hotplug and (rx-sense or edid)\n", __func__); | ||
6960 | - if (!state->have_monitor) { | ||
6961 | - v4l2_dbg(1, debug, sd, "%s: monitor detected\n", __func__); | ||
6962 | - state->have_monitor = true; | ||
6963 | - adv7511_set_isr(sd, true); | ||
6964 | - if (!adv7511_s_power(sd, true)) { | ||
6965 | - v4l2_dbg(1, debug, sd, "%s: monitor detected, powerup failed\n", __func__); | ||
6966 | - return; | ||
6967 | - } | ||
6968 | - adv7511_setup(sd); | ||
6969 | - adv7511_notify_monitor_detect(sd); | ||
6970 | - state->edid.read_retries = EDID_MAX_RETRIES; | ||
6971 | - queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
6972 | - } | ||
6973 | - } else if (status & MASK_ADV7511_HPD_DETECT) { | ||
6974 | - v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__); | ||
6975 | - state->edid.read_retries = EDID_MAX_RETRIES; | ||
6976 | - queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
6977 | - } else if (!(status & MASK_ADV7511_HPD_DETECT)) { | ||
6978 | - v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__); | ||
6979 | - if (state->have_monitor) { | ||
6980 | - v4l2_dbg(1, debug, sd, "%s: monitor not detected\n", __func__); | ||
6981 | - state->have_monitor = false; | ||
6982 | - adv7511_notify_monitor_detect(sd); | ||
6983 | - } | ||
6984 | - adv7511_s_power(sd, false); | ||
6985 | - memset(&state->edid, 0, sizeof(struct adv7511_state_edid)); | ||
6986 | - adv7511_notify_no_edid(sd); | ||
6987 | - } | ||
6988 | -} | ||
6989 | - | ||
6990 | -static bool edid_block_verify_crc(u8 *edid_block) | ||
6991 | -{ | ||
6992 | - u8 sum = 0; | ||
6993 | - int i; | ||
6994 | - | ||
6995 | - for (i = 0; i < 128; i++) | ||
6996 | - sum += edid_block[i]; | ||
6997 | - return sum == 0; | ||
6998 | -} | ||
6999 | - | ||
7000 | -static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment) | ||
7001 | -{ | ||
7002 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
7003 | - u32 blocks = state->edid.blocks; | ||
7004 | - u8 *data = state->edid.data; | ||
7005 | - | ||
7006 | - if (!edid_block_verify_crc(&data[segment * 256])) | ||
7007 | - return false; | ||
7008 | - if ((segment + 1) * 2 <= blocks) | ||
7009 | - return edid_block_verify_crc(&data[segment * 256 + 128]); | ||
7010 | - return true; | ||
7011 | -} | ||
7012 | - | ||
7013 | -static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment) | ||
7014 | -{ | ||
7015 | - static const u8 hdmi_header[] = { | ||
7016 | - 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 | ||
7017 | - }; | ||
7018 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
7019 | - u8 *data = state->edid.data; | ||
7020 | - | ||
7021 | - if (segment != 0) | ||
7022 | - return true; | ||
7023 | - return !memcmp(data, hdmi_header, sizeof(hdmi_header)); | ||
7024 | -} | ||
7025 | - | ||
7026 | -static bool adv7511_check_edid_status(struct v4l2_subdev *sd) | ||
7027 | -{ | ||
7028 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
7029 | - u8 edidRdy = adv7511_rd(sd, 0xc5); | ||
7030 | - | ||
7031 | - v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n", | ||
7032 | - __func__, EDID_MAX_RETRIES - state->edid.read_retries); | ||
7033 | - | ||
7034 | - if (state->edid.complete) | ||
7035 | - return true; | ||
7036 | - | ||
7037 | - if (edidRdy & MASK_ADV7511_EDID_RDY) { | ||
7038 | - int segment = adv7511_rd(sd, 0xc4); | ||
7039 | - struct adv7511_edid_detect ed; | ||
7040 | - | ||
7041 | - if (segment >= EDID_MAX_SEGM) { | ||
7042 | - v4l2_err(sd, "edid segment number too big\n"); | ||
7043 | - return false; | ||
7044 | - } | ||
7045 | - v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment); | ||
7046 | - adv7511_edid_rd(sd, 256, &state->edid.data[segment * 256]); | ||
7047 | - adv7511_dbg_dump_edid(2, debug, sd, segment, &state->edid.data[segment * 256]); | ||
7048 | - if (segment == 0) { | ||
7049 | - state->edid.blocks = state->edid.data[0x7e] + 1; | ||
7050 | - v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n", __func__, state->edid.blocks); | ||
7051 | - } | ||
7052 | - if (!edid_verify_crc(sd, segment) || | ||
7053 | - !edid_verify_header(sd, segment)) { | ||
7054 | - /* edid crc error, force reread of edid segment */ | ||
7055 | - v4l2_err(sd, "%s: edid crc or header error\n", __func__); | ||
7056 | - state->have_monitor = false; | ||
7057 | - adv7511_s_power(sd, false); | ||
7058 | - adv7511_s_power(sd, true); | ||
7059 | - return false; | ||
7060 | - } | ||
7061 | - /* one more segment read ok */ | ||
7062 | - state->edid.segments = segment + 1; | ||
7063 | - v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x1); | ||
7064 | - if (((state->edid.data[0x7e] >> 1) + 1) > state->edid.segments) { | ||
7065 | - /* Request next EDID segment */ | ||
7066 | - v4l2_dbg(1, debug, sd, "%s: request segment %d\n", __func__, state->edid.segments); | ||
7067 | - adv7511_wr(sd, 0xc9, 0xf); | ||
7068 | - adv7511_wr(sd, 0xc4, state->edid.segments); | ||
7069 | - state->edid.read_retries = EDID_MAX_RETRIES; | ||
7070 | - queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); | ||
7071 | - return false; | ||
7072 | - } | ||
7073 | - | ||
7074 | - v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments); | ||
7075 | - state->edid.complete = true; | ||
7076 | - ed.phys_addr = cec_get_edid_phys_addr(state->edid.data, | ||
7077 | - state->edid.segments * 256, | ||
7078 | - NULL); | ||
7079 | - /* report when we have all segments | ||
7080 | - but report only for segment 0 | ||
7081 | - */ | ||
7082 | - ed.present = true; | ||
7083 | - ed.segment = 0; | ||
7084 | - state->edid_detect_counter++; | ||
7085 | - cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); | ||
7086 | - v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); | ||
7087 | - return ed.present; | ||
7088 | - } | ||
7089 | - | ||
7090 | - return false; | ||
7091 | -} | ||
7092 | - | ||
7093 | -static int adv7511_registered(struct v4l2_subdev *sd) | ||
7094 | -{ | ||
7095 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
7096 | - int err; | ||
7097 | - | ||
7098 | - err = cec_register_adapter(state->cec_adap); | ||
7099 | - if (err) | ||
7100 | - cec_delete_adapter(state->cec_adap); | ||
7101 | - return err; | ||
7102 | -} | ||
7103 | - | ||
7104 | -static void adv7511_unregistered(struct v4l2_subdev *sd) | ||
7105 | -{ | ||
7106 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
7107 | - | ||
7108 | - cec_unregister_adapter(state->cec_adap); | ||
7109 | -} | ||
7110 | - | ||
7111 | -static const struct v4l2_subdev_internal_ops adv7511_int_ops = { | ||
7112 | - .registered = adv7511_registered, | ||
7113 | - .unregistered = adv7511_unregistered, | ||
7114 | -}; | ||
7115 | - | ||
7116 | -/* ----------------------------------------------------------------------- */ | ||
7117 | -/* Setup ADV7511 */ | ||
7118 | -static void adv7511_init_setup(struct v4l2_subdev *sd) | ||
7119 | -{ | ||
7120 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
7121 | - struct adv7511_state_edid *edid = &state->edid; | ||
7122 | - u32 cec_clk = state->pdata.cec_clk; | ||
7123 | - u8 ratio; | ||
7124 | - | ||
7125 | - v4l2_dbg(1, debug, sd, "%s\n", __func__); | ||
7126 | - | ||
7127 | - /* clear all interrupts */ | ||
7128 | - adv7511_wr(sd, 0x96, 0xff); | ||
7129 | - adv7511_wr(sd, 0x97, 0xff); | ||
7130 | - /* | ||
7131 | - * Stop HPD from resetting a lot of registers. | ||
7132 | - * It might leave the chip in a partly un-initialized state, | ||
7133 | - * in particular with regards to hotplug bounces. | ||
7134 | - */ | ||
7135 | - adv7511_wr_and_or(sd, 0xd6, 0x3f, 0xc0); | ||
7136 | - memset(edid, 0, sizeof(struct adv7511_state_edid)); | ||
7137 | - state->have_monitor = false; | ||
7138 | - adv7511_set_isr(sd, false); | ||
7139 | - adv7511_s_stream(sd, false); | ||
7140 | - adv7511_s_audio_stream(sd, false); | ||
7141 | - | ||
7142 | - if (state->i2c_cec == NULL) | ||
7143 | - return; | ||
7144 | - | ||
7145 | - v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk); | ||
7146 | - | ||
7147 | - /* cec soft reset */ | ||
7148 | - adv7511_cec_write(sd, 0x50, 0x01); | ||
7149 | - adv7511_cec_write(sd, 0x50, 0x00); | ||
7150 | - | ||
7151 | - /* legacy mode */ | ||
7152 | - adv7511_cec_write(sd, 0x4a, 0x00); | ||
7153 | - | ||
7154 | - if (cec_clk % 750000 != 0) | ||
7155 | - v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n", | ||
7156 | - __func__, cec_clk); | ||
7157 | - | ||
7158 | - ratio = (cec_clk / 750000) - 1; | ||
7159 | - adv7511_cec_write(sd, 0x4e, ratio << 2); | ||
7160 | -} | ||
7161 | - | ||
7162 | -static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
7163 | -{ | ||
7164 | - struct adv7511_state *state; | ||
7165 | - struct adv7511_platform_data *pdata = client->dev.platform_data; | ||
7166 | - struct v4l2_ctrl_handler *hdl; | ||
7167 | - struct v4l2_subdev *sd; | ||
7168 | - u8 chip_id[2]; | ||
7169 | - int err = -EIO; | ||
7170 | - | ||
7171 | - /* Check if the adapter supports the needed features */ | ||
7172 | - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
7173 | - return -EIO; | ||
7174 | - | ||
7175 | - state = devm_kzalloc(&client->dev, sizeof(struct adv7511_state), GFP_KERNEL); | ||
7176 | - if (!state) | ||
7177 | - return -ENOMEM; | ||
7178 | - | ||
7179 | - /* Platform data */ | ||
7180 | - if (!pdata) { | ||
7181 | - v4l_err(client, "No platform data!\n"); | ||
7182 | - return -ENODEV; | ||
7183 | - } | ||
7184 | - memcpy(&state->pdata, pdata, sizeof(state->pdata)); | ||
7185 | - state->fmt_code = MEDIA_BUS_FMT_RGB888_1X24; | ||
7186 | - state->colorspace = V4L2_COLORSPACE_SRGB; | ||
7187 | - | ||
7188 | - sd = &state->sd; | ||
7189 | - | ||
7190 | - v4l2_dbg(1, debug, sd, "detecting adv7511 client on address 0x%x\n", | ||
7191 | - client->addr << 1); | ||
7192 | - | ||
7193 | - v4l2_i2c_subdev_init(sd, client, &adv7511_ops); | ||
7194 | - sd->internal_ops = &adv7511_int_ops; | ||
7195 | - | ||
7196 | - hdl = &state->hdl; | ||
7197 | - v4l2_ctrl_handler_init(hdl, 10); | ||
7198 | - /* add in ascending ID order */ | ||
7199 | - state->hdmi_mode_ctrl = v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops, | ||
7200 | - V4L2_CID_DV_TX_MODE, V4L2_DV_TX_MODE_HDMI, | ||
7201 | - 0, V4L2_DV_TX_MODE_DVI_D); | ||
7202 | - state->hotplug_ctrl = v4l2_ctrl_new_std(hdl, NULL, | ||
7203 | - V4L2_CID_DV_TX_HOTPLUG, 0, 1, 0, 0); | ||
7204 | - state->rx_sense_ctrl = v4l2_ctrl_new_std(hdl, NULL, | ||
7205 | - V4L2_CID_DV_TX_RXSENSE, 0, 1, 0, 0); | ||
7206 | - state->have_edid0_ctrl = v4l2_ctrl_new_std(hdl, NULL, | ||
7207 | - V4L2_CID_DV_TX_EDID_PRESENT, 0, 1, 0, 0); | ||
7208 | - state->rgb_quantization_range_ctrl = | ||
7209 | - v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops, | ||
7210 | - V4L2_CID_DV_TX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL, | ||
7211 | - 0, V4L2_DV_RGB_RANGE_AUTO); | ||
7212 | - state->content_type_ctrl = | ||
7213 | - v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops, | ||
7214 | - V4L2_CID_DV_TX_IT_CONTENT_TYPE, V4L2_DV_IT_CONTENT_TYPE_NO_ITC, | ||
7215 | - 0, V4L2_DV_IT_CONTENT_TYPE_NO_ITC); | ||
7216 | - sd->ctrl_handler = hdl; | ||
7217 | - if (hdl->error) { | ||
7218 | - err = hdl->error; | ||
7219 | - goto err_hdl; | ||
7220 | - } | ||
7221 | - state->pad.flags = MEDIA_PAD_FL_SINK; | ||
7222 | - err = media_entity_pads_init(&sd->entity, 1, &state->pad); | ||
7223 | - if (err) | ||
7224 | - goto err_hdl; | ||
7225 | - | ||
7226 | - /* EDID and CEC i2c addr */ | ||
7227 | - state->i2c_edid_addr = state->pdata.i2c_edid << 1; | ||
7228 | - state->i2c_cec_addr = state->pdata.i2c_cec << 1; | ||
7229 | - state->i2c_pktmem_addr = state->pdata.i2c_pktmem << 1; | ||
7230 | - | ||
7231 | - state->chip_revision = adv7511_rd(sd, 0x0); | ||
7232 | - chip_id[0] = adv7511_rd(sd, 0xf5); | ||
7233 | - chip_id[1] = adv7511_rd(sd, 0xf6); | ||
7234 | - if (chip_id[0] != 0x75 || chip_id[1] != 0x11) { | ||
7235 | - v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0], | ||
7236 | - chip_id[1]); | ||
7237 | - err = -EIO; | ||
7238 | - goto err_entity; | ||
7239 | - } | ||
7240 | - | ||
7241 | - state->i2c_edid = i2c_new_dummy(client->adapter, | ||
7242 | - state->i2c_edid_addr >> 1); | ||
7243 | - if (state->i2c_edid == NULL) { | ||
7244 | - v4l2_err(sd, "failed to register edid i2c client\n"); | ||
7245 | - err = -ENOMEM; | ||
7246 | - goto err_entity; | ||
7247 | - } | ||
7248 | - | ||
7249 | - adv7511_wr(sd, 0xe1, state->i2c_cec_addr); | ||
7250 | - if (state->pdata.cec_clk < 3000000 || | ||
7251 | - state->pdata.cec_clk > 100000000) { | ||
7252 | - v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n", | ||
7253 | - __func__, state->pdata.cec_clk); | ||
7254 | - state->pdata.cec_clk = 0; | ||
7255 | - } | ||
7256 | - | ||
7257 | - if (state->pdata.cec_clk) { | ||
7258 | - state->i2c_cec = i2c_new_dummy(client->adapter, | ||
7259 | - state->i2c_cec_addr >> 1); | ||
7260 | - if (state->i2c_cec == NULL) { | ||
7261 | - v4l2_err(sd, "failed to register cec i2c client\n"); | ||
7262 | - err = -ENOMEM; | ||
7263 | - goto err_unreg_edid; | ||
7264 | - } | ||
7265 | - adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */ | ||
7266 | - } else { | ||
7267 | - adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */ | ||
7268 | - } | ||
7269 | - | ||
7270 | - state->i2c_pktmem = i2c_new_dummy(client->adapter, state->i2c_pktmem_addr >> 1); | ||
7271 | - if (state->i2c_pktmem == NULL) { | ||
7272 | - v4l2_err(sd, "failed to register pktmem i2c client\n"); | ||
7273 | - err = -ENOMEM; | ||
7274 | - goto err_unreg_cec; | ||
7275 | - } | ||
7276 | - | ||
7277 | - state->work_queue = create_singlethread_workqueue(sd->name); | ||
7278 | - if (state->work_queue == NULL) { | ||
7279 | - v4l2_err(sd, "could not create workqueue\n"); | ||
7280 | - err = -ENOMEM; | ||
7281 | - goto err_unreg_pktmem; | ||
7282 | - } | ||
7283 | - | ||
7284 | - INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler); | ||
7285 | - | ||
7286 | - adv7511_init_setup(sd); | ||
7287 | - | ||
7288 | -#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) | ||
7289 | - state->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops, | ||
7290 | - state, dev_name(&client->dev), CEC_CAP_TRANSMIT | | ||
7291 | - CEC_CAP_LOG_ADDRS | CEC_CAP_PASSTHROUGH | CEC_CAP_RC, | ||
7292 | - ADV7511_MAX_ADDRS, &client->dev); | ||
7293 | - err = PTR_ERR_OR_ZERO(state->cec_adap); | ||
7294 | - if (err) { | ||
7295 | - destroy_workqueue(state->work_queue); | ||
7296 | - goto err_unreg_pktmem; | ||
7297 | - } | ||
7298 | -#endif | ||
7299 | - | ||
7300 | - adv7511_set_isr(sd, true); | ||
7301 | - adv7511_check_monitor_present_status(sd); | ||
7302 | - | ||
7303 | - v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, | ||
7304 | - client->addr << 1, client->adapter->name); | ||
7305 | - return 0; | ||
7306 | - | ||
7307 | -err_unreg_pktmem: | ||
7308 | - i2c_unregister_device(state->i2c_pktmem); | ||
7309 | -err_unreg_cec: | ||
7310 | - if (state->i2c_cec) | ||
7311 | - i2c_unregister_device(state->i2c_cec); | ||
7312 | -err_unreg_edid: | ||
7313 | - i2c_unregister_device(state->i2c_edid); | ||
7314 | -err_entity: | ||
7315 | - media_entity_cleanup(&sd->entity); | ||
7316 | -err_hdl: | ||
7317 | - v4l2_ctrl_handler_free(&state->hdl); | ||
7318 | - return err; | ||
7319 | -} | ||
7320 | - | ||
7321 | -/* ----------------------------------------------------------------------- */ | ||
7322 | - | ||
7323 | -static int adv7511_remove(struct i2c_client *client) | ||
7324 | -{ | ||
7325 | - struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
7326 | - struct adv7511_state *state = get_adv7511_state(sd); | ||
7327 | - | ||
7328 | - state->chip_revision = -1; | ||
7329 | - | ||
7330 | - v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name, | ||
7331 | - client->addr << 1, client->adapter->name); | ||
7332 | - | ||
7333 | - adv7511_set_isr(sd, false); | ||
7334 | - adv7511_init_setup(sd); | ||
7335 | - cancel_delayed_work(&state->edid_handler); | ||
7336 | - i2c_unregister_device(state->i2c_edid); | ||
7337 | - if (state->i2c_cec) | ||
7338 | - i2c_unregister_device(state->i2c_cec); | ||
7339 | - i2c_unregister_device(state->i2c_pktmem); | ||
7340 | - destroy_workqueue(state->work_queue); | ||
7341 | - v4l2_device_unregister_subdev(sd); | ||
7342 | - media_entity_cleanup(&sd->entity); | ||
7343 | - v4l2_ctrl_handler_free(sd->ctrl_handler); | ||
7344 | - return 0; | ||
7345 | -} | ||
7346 | - | ||
7347 | -/* ----------------------------------------------------------------------- */ | ||
7348 | - | ||
7349 | -static struct i2c_device_id adv7511_id[] = { | ||
7350 | - { "adv7511", 0 }, | ||
7351 | - { } | ||
7352 | -}; | ||
7353 | -MODULE_DEVICE_TABLE(i2c, adv7511_id); | ||
7354 | - | ||
7355 | -static struct i2c_driver adv7511_driver = { | ||
7356 | - .driver = { | ||
7357 | - .name = "adv7511", | ||
7358 | - }, | ||
7359 | - .probe = adv7511_probe, | ||
7360 | - .remove = adv7511_remove, | ||
7361 | - .id_table = adv7511_id, | ||
7362 | -}; | ||
7363 | - | ||
7364 | -module_i2c_driver(adv7511_driver); | ||
7365 | diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c | ||
7366 | index 6f46c59415fe..73a2dba475d0 100644 | ||
7367 | --- a/drivers/media/media-device.c | ||
7368 | +++ b/drivers/media/media-device.c | ||
7369 | @@ -474,6 +474,7 @@ static long media_device_enum_links32(struct media_device *mdev, | ||
7370 | { | ||
7371 | struct media_links_enum links; | ||
7372 | compat_uptr_t pads_ptr, links_ptr; | ||
7373 | + int ret; | ||
7374 | |||
7375 | memset(&links, 0, sizeof(links)); | ||
7376 | |||
7377 | @@ -485,7 +486,14 @@ static long media_device_enum_links32(struct media_device *mdev, | ||
7378 | links.pads = compat_ptr(pads_ptr); | ||
7379 | links.links = compat_ptr(links_ptr); | ||
7380 | |||
7381 | - return media_device_enum_links(mdev, &links); | ||
7382 | + ret = media_device_enum_links(mdev, &links); | ||
7383 | + if (ret) | ||
7384 | + return ret; | ||
7385 | + | ||
7386 | + if (copy_to_user(ulinks->reserved, links.reserved, | ||
7387 | + sizeof(ulinks->reserved))) | ||
7388 | + return -EFAULT; | ||
7389 | + return 0; | ||
7390 | } | ||
7391 | |||
7392 | #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct media_links_enum32) | ||
7393 | diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c | ||
7394 | index 717ee9a6a80e..7b4c93619c3d 100644 | ||
7395 | --- a/drivers/media/platform/coda/coda-bit.c | ||
7396 | +++ b/drivers/media/platform/coda/coda-bit.c | ||
7397 | @@ -1581,6 +1581,7 @@ static int __coda_start_decoding(struct coda_ctx *ctx) | ||
7398 | coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM); | ||
7399 | return -ETIMEDOUT; | ||
7400 | } | ||
7401 | + ctx->sequence_offset = ~0U; | ||
7402 | ctx->initialized = 1; | ||
7403 | |||
7404 | /* Update kfifo out pointer from coda bitstream read pointer */ | ||
7405 | @@ -1966,12 +1967,17 @@ static void coda_finish_decode(struct coda_ctx *ctx) | ||
7406 | else if (ctx->display_idx < 0) | ||
7407 | ctx->hold = true; | ||
7408 | } else if (decoded_idx == -2) { | ||
7409 | + if (ctx->display_idx >= 0 && | ||
7410 | + ctx->display_idx < ctx->num_internal_frames) | ||
7411 | + ctx->sequence_offset++; | ||
7412 | /* no frame was decoded, we still return remaining buffers */ | ||
7413 | } else if (decoded_idx < 0 || decoded_idx >= ctx->num_internal_frames) { | ||
7414 | v4l2_err(&dev->v4l2_dev, | ||
7415 | "decoded frame index out of range: %d\n", decoded_idx); | ||
7416 | } else { | ||
7417 | - val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM) - 1; | ||
7418 | + val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM); | ||
7419 | + if (ctx->sequence_offset == -1) | ||
7420 | + ctx->sequence_offset = val; | ||
7421 | val -= ctx->sequence_offset; | ||
7422 | spin_lock_irqsave(&ctx->buffer_meta_lock, flags); | ||
7423 | if (!list_empty(&ctx->buffer_meta_list)) { | ||
7424 | @@ -2101,7 +2107,6 @@ irqreturn_t coda_irq_handler(int irq, void *data) | ||
7425 | if (ctx == NULL) { | ||
7426 | v4l2_err(&dev->v4l2_dev, | ||
7427 | "Instance released before the end of transaction\n"); | ||
7428 | - mutex_unlock(&dev->coda_mutex); | ||
7429 | return IRQ_HANDLED; | ||
7430 | } | ||
7431 | |||
7432 | diff --git a/drivers/media/platform/davinci/vpss.c b/drivers/media/platform/davinci/vpss.c | ||
7433 | index fce86f17dffc..c2c68988e38a 100644 | ||
7434 | --- a/drivers/media/platform/davinci/vpss.c | ||
7435 | +++ b/drivers/media/platform/davinci/vpss.c | ||
7436 | @@ -523,6 +523,11 @@ static int __init vpss_init(void) | ||
7437 | return -EBUSY; | ||
7438 | |||
7439 | oper_cfg.vpss_regs_base2 = ioremap(VPSS_CLK_CTRL, 4); | ||
7440 | + if (unlikely(!oper_cfg.vpss_regs_base2)) { | ||
7441 | + release_mem_region(VPSS_CLK_CTRL, 4); | ||
7442 | + return -ENOMEM; | ||
7443 | + } | ||
7444 | + | ||
7445 | writel(VPSS_CLK_CTRL_VENCCLKEN | | ||
7446 | VPSS_CLK_CTRL_DACCLKEN, oper_cfg.vpss_regs_base2); | ||
7447 | |||
7448 | diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c | ||
7449 | index af59bf4dca2d..a74bfb9afc8d 100644 | ||
7450 | --- a/drivers/media/platform/marvell-ccic/mcam-core.c | ||
7451 | +++ b/drivers/media/platform/marvell-ccic/mcam-core.c | ||
7452 | @@ -209,7 +209,6 @@ struct mcam_vb_buffer { | ||
7453 | struct list_head queue; | ||
7454 | struct mcam_dma_desc *dma_desc; /* Descriptor virtual address */ | ||
7455 | dma_addr_t dma_desc_pa; /* Descriptor physical address */ | ||
7456 | - int dma_desc_nent; /* Number of mapped descriptors */ | ||
7457 | }; | ||
7458 | |||
7459 | static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_v4l2_buffer *vb) | ||
7460 | @@ -616,9 +615,11 @@ static void mcam_dma_contig_done(struct mcam_camera *cam, int frame) | ||
7461 | static void mcam_sg_next_buffer(struct mcam_camera *cam) | ||
7462 | { | ||
7463 | struct mcam_vb_buffer *buf; | ||
7464 | + struct sg_table *sg_table; | ||
7465 | |||
7466 | buf = list_first_entry(&cam->buffers, struct mcam_vb_buffer, queue); | ||
7467 | list_del_init(&buf->queue); | ||
7468 | + sg_table = vb2_dma_sg_plane_desc(&buf->vb_buf.vb2_buf, 0); | ||
7469 | /* | ||
7470 | * Very Bad Not Good Things happen if you don't clear | ||
7471 | * C1_DESC_ENA before making any descriptor changes. | ||
7472 | @@ -626,7 +627,7 @@ static void mcam_sg_next_buffer(struct mcam_camera *cam) | ||
7473 | mcam_reg_clear_bit(cam, REG_CTRL1, C1_DESC_ENA); | ||
7474 | mcam_reg_write(cam, REG_DMA_DESC_Y, buf->dma_desc_pa); | ||
7475 | mcam_reg_write(cam, REG_DESC_LEN_Y, | ||
7476 | - buf->dma_desc_nent*sizeof(struct mcam_dma_desc)); | ||
7477 | + sg_table->nents * sizeof(struct mcam_dma_desc)); | ||
7478 | mcam_reg_write(cam, REG_DESC_LEN_U, 0); | ||
7479 | mcam_reg_write(cam, REG_DESC_LEN_V, 0); | ||
7480 | mcam_reg_set_bit(cam, REG_CTRL1, C1_DESC_ENA); | ||
7481 | diff --git a/drivers/media/radio/radio-raremono.c b/drivers/media/radio/radio-raremono.c | ||
7482 | index bfb3a6d051ba..10958bac0ad9 100644 | ||
7483 | --- a/drivers/media/radio/radio-raremono.c | ||
7484 | +++ b/drivers/media/radio/radio-raremono.c | ||
7485 | @@ -283,6 +283,14 @@ static int vidioc_g_frequency(struct file *file, void *priv, | ||
7486 | return 0; | ||
7487 | } | ||
7488 | |||
7489 | +static void raremono_device_release(struct v4l2_device *v4l2_dev) | ||
7490 | +{ | ||
7491 | + struct raremono_device *radio = to_raremono_dev(v4l2_dev); | ||
7492 | + | ||
7493 | + kfree(radio->buffer); | ||
7494 | + kfree(radio); | ||
7495 | +} | ||
7496 | + | ||
7497 | /* File system interface */ | ||
7498 | static const struct v4l2_file_operations usb_raremono_fops = { | ||
7499 | .owner = THIS_MODULE, | ||
7500 | @@ -307,12 +315,14 @@ static int usb_raremono_probe(struct usb_interface *intf, | ||
7501 | struct raremono_device *radio; | ||
7502 | int retval = 0; | ||
7503 | |||
7504 | - radio = devm_kzalloc(&intf->dev, sizeof(struct raremono_device), GFP_KERNEL); | ||
7505 | - if (radio) | ||
7506 | - radio->buffer = devm_kmalloc(&intf->dev, BUFFER_LENGTH, GFP_KERNEL); | ||
7507 | - | ||
7508 | - if (!radio || !radio->buffer) | ||
7509 | + radio = kzalloc(sizeof(*radio), GFP_KERNEL); | ||
7510 | + if (!radio) | ||
7511 | + return -ENOMEM; | ||
7512 | + radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL); | ||
7513 | + if (!radio->buffer) { | ||
7514 | + kfree(radio); | ||
7515 | return -ENOMEM; | ||
7516 | + } | ||
7517 | |||
7518 | radio->usbdev = interface_to_usbdev(intf); | ||
7519 | radio->intf = intf; | ||
7520 | @@ -336,7 +346,8 @@ static int usb_raremono_probe(struct usb_interface *intf, | ||
7521 | if (retval != 3 || | ||
7522 | (get_unaligned_be16(&radio->buffer[1]) & 0xfff) == 0x0242) { | ||
7523 | dev_info(&intf->dev, "this is not Thanko's Raremono.\n"); | ||
7524 | - return -ENODEV; | ||
7525 | + retval = -ENODEV; | ||
7526 | + goto free_mem; | ||
7527 | } | ||
7528 | |||
7529 | dev_info(&intf->dev, "Thanko's Raremono connected: (%04X:%04X)\n", | ||
7530 | @@ -345,7 +356,7 @@ static int usb_raremono_probe(struct usb_interface *intf, | ||
7531 | retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev); | ||
7532 | if (retval < 0) { | ||
7533 | dev_err(&intf->dev, "couldn't register v4l2_device\n"); | ||
7534 | - return retval; | ||
7535 | + goto free_mem; | ||
7536 | } | ||
7537 | |||
7538 | mutex_init(&radio->lock); | ||
7539 | @@ -357,6 +368,7 @@ static int usb_raremono_probe(struct usb_interface *intf, | ||
7540 | radio->vdev.ioctl_ops = &usb_raremono_ioctl_ops; | ||
7541 | radio->vdev.lock = &radio->lock; | ||
7542 | radio->vdev.release = video_device_release_empty; | ||
7543 | + radio->v4l2_dev.release = raremono_device_release; | ||
7544 | |||
7545 | usb_set_intfdata(intf, &radio->v4l2_dev); | ||
7546 | |||
7547 | @@ -372,6 +384,10 @@ static int usb_raremono_probe(struct usb_interface *intf, | ||
7548 | } | ||
7549 | dev_err(&intf->dev, "could not register video device\n"); | ||
7550 | v4l2_device_unregister(&radio->v4l2_dev); | ||
7551 | + | ||
7552 | +free_mem: | ||
7553 | + kfree(radio->buffer); | ||
7554 | + kfree(radio); | ||
7555 | return retval; | ||
7556 | } | ||
7557 | |||
7558 | diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.c b/drivers/media/radio/wl128x/fmdrv_v4l2.c | ||
7559 | index fb42f0fd0c1f..add26eac1677 100644 | ||
7560 | --- a/drivers/media/radio/wl128x/fmdrv_v4l2.c | ||
7561 | +++ b/drivers/media/radio/wl128x/fmdrv_v4l2.c | ||
7562 | @@ -553,6 +553,7 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr) | ||
7563 | |||
7564 | /* Register with V4L2 subsystem as RADIO device */ | ||
7565 | if (video_register_device(&gradio_dev, VFL_TYPE_RADIO, radio_nr)) { | ||
7566 | + v4l2_device_unregister(&fmdev->v4l2_dev); | ||
7567 | fmerr("Could not register video device\n"); | ||
7568 | return -ENOMEM; | ||
7569 | } | ||
7570 | @@ -566,6 +567,8 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr) | ||
7571 | if (ret < 0) { | ||
7572 | fmerr("(fmdev): Can't init ctrl handler\n"); | ||
7573 | v4l2_ctrl_handler_free(&fmdev->ctrl_handler); | ||
7574 | + video_unregister_device(fmdev->radio_dev); | ||
7575 | + v4l2_device_unregister(&fmdev->v4l2_dev); | ||
7576 | return -EBUSY; | ||
7577 | } | ||
7578 | |||
7579 | diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c | ||
7580 | index bf53553d2624..38e73ee5c8fb 100644 | ||
7581 | --- a/drivers/media/usb/au0828/au0828-core.c | ||
7582 | +++ b/drivers/media/usb/au0828/au0828-core.c | ||
7583 | @@ -630,6 +630,12 @@ static int au0828_usb_probe(struct usb_interface *interface, | ||
7584 | /* Setup */ | ||
7585 | au0828_card_setup(dev); | ||
7586 | |||
7587 | + /* | ||
7588 | + * Store the pointer to the au0828_dev so it can be accessed in | ||
7589 | + * au0828_usb_disconnect | ||
7590 | + */ | ||
7591 | + usb_set_intfdata(interface, dev); | ||
7592 | + | ||
7593 | /* Analog TV */ | ||
7594 | retval = au0828_analog_register(dev, interface); | ||
7595 | if (retval) { | ||
7596 | @@ -647,12 +653,6 @@ static int au0828_usb_probe(struct usb_interface *interface, | ||
7597 | /* Remote controller */ | ||
7598 | au0828_rc_register(dev); | ||
7599 | |||
7600 | - /* | ||
7601 | - * Store the pointer to the au0828_dev so it can be accessed in | ||
7602 | - * au0828_usb_disconnect | ||
7603 | - */ | ||
7604 | - usb_set_intfdata(interface, dev); | ||
7605 | - | ||
7606 | pr_info("Registered device AU0828 [%s]\n", | ||
7607 | dev->board.name == NULL ? "Unset" : dev->board.name); | ||
7608 | |||
7609 | diff --git a/drivers/media/usb/cpia2/cpia2_usb.c b/drivers/media/usb/cpia2/cpia2_usb.c | ||
7610 | index e9100a235831..21e5454d260a 100644 | ||
7611 | --- a/drivers/media/usb/cpia2/cpia2_usb.c | ||
7612 | +++ b/drivers/media/usb/cpia2/cpia2_usb.c | ||
7613 | @@ -909,7 +909,6 @@ static void cpia2_usb_disconnect(struct usb_interface *intf) | ||
7614 | cpia2_unregister_camera(cam); | ||
7615 | v4l2_device_disconnect(&cam->v4l2_dev); | ||
7616 | mutex_unlock(&cam->v4l2_lock); | ||
7617 | - v4l2_device_put(&cam->v4l2_dev); | ||
7618 | |||
7619 | if(cam->buffers) { | ||
7620 | DBG("Wakeup waiting processes\n"); | ||
7621 | @@ -921,6 +920,8 @@ static void cpia2_usb_disconnect(struct usb_interface *intf) | ||
7622 | DBG("Releasing interface\n"); | ||
7623 | usb_driver_release_interface(&cpia2_driver, intf); | ||
7624 | |||
7625 | + v4l2_device_put(&cam->v4l2_dev); | ||
7626 | + | ||
7627 | LOG("CPiA2 camera disconnected.\n"); | ||
7628 | } | ||
7629 | |||
7630 | diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c | ||
7631 | index 84308569e7dc..b3413404f91a 100644 | ||
7632 | --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c | ||
7633 | +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c | ||
7634 | @@ -287,12 +287,15 @@ EXPORT_SYMBOL(dvb_usb_device_init); | ||
7635 | void dvb_usb_device_exit(struct usb_interface *intf) | ||
7636 | { | ||
7637 | struct dvb_usb_device *d = usb_get_intfdata(intf); | ||
7638 | - const char *name = "generic DVB-USB module"; | ||
7639 | + const char *default_name = "generic DVB-USB module"; | ||
7640 | + char name[40]; | ||
7641 | |||
7642 | usb_set_intfdata(intf, NULL); | ||
7643 | if (d != NULL && d->desc != NULL) { | ||
7644 | - name = d->desc->name; | ||
7645 | + strscpy(name, d->desc->name, sizeof(name)); | ||
7646 | dvb_usb_exit(d); | ||
7647 | + } else { | ||
7648 | + strscpy(name, default_name, sizeof(name)); | ||
7649 | } | ||
7650 | info("%s successfully deinitialized and disconnected.", name); | ||
7651 | |||
7652 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c | ||
7653 | index c56d649fa7da..b3d8b9592f8a 100644 | ||
7654 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c | ||
7655 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c | ||
7656 | @@ -2103,16 +2103,15 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, | ||
7657 | v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step, | ||
7658 | &def, &flags); | ||
7659 | |||
7660 | - is_menu = (cfg->type == V4L2_CTRL_TYPE_MENU || | ||
7661 | - cfg->type == V4L2_CTRL_TYPE_INTEGER_MENU); | ||
7662 | + is_menu = (type == V4L2_CTRL_TYPE_MENU || | ||
7663 | + type == V4L2_CTRL_TYPE_INTEGER_MENU); | ||
7664 | if (is_menu) | ||
7665 | WARN_ON(step); | ||
7666 | else | ||
7667 | WARN_ON(cfg->menu_skip_mask); | ||
7668 | - if (cfg->type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) | ||
7669 | + if (type == V4L2_CTRL_TYPE_MENU && !qmenu) { | ||
7670 | qmenu = v4l2_ctrl_get_menu(cfg->id); | ||
7671 | - else if (cfg->type == V4L2_CTRL_TYPE_INTEGER_MENU && | ||
7672 | - qmenu_int == NULL) { | ||
7673 | + } else if (type == V4L2_CTRL_TYPE_INTEGER_MENU && !qmenu_int) { | ||
7674 | handler_set_err(hdl, -EINVAL); | ||
7675 | return NULL; | ||
7676 | } | ||
7677 | diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c | ||
7678 | index 4d673a626db4..1041eb7a6167 100644 | ||
7679 | --- a/drivers/memstick/core/memstick.c | ||
7680 | +++ b/drivers/memstick/core/memstick.c | ||
7681 | @@ -629,13 +629,18 @@ static int __init memstick_init(void) | ||
7682 | return -ENOMEM; | ||
7683 | |||
7684 | rc = bus_register(&memstick_bus_type); | ||
7685 | - if (!rc) | ||
7686 | - rc = class_register(&memstick_host_class); | ||
7687 | + if (rc) | ||
7688 | + goto error_destroy_workqueue; | ||
7689 | |||
7690 | - if (!rc) | ||
7691 | - return 0; | ||
7692 | + rc = class_register(&memstick_host_class); | ||
7693 | + if (rc) | ||
7694 | + goto error_bus_unregister; | ||
7695 | + | ||
7696 | + return 0; | ||
7697 | |||
7698 | +error_bus_unregister: | ||
7699 | bus_unregister(&memstick_bus_type); | ||
7700 | +error_destroy_workqueue: | ||
7701 | destroy_workqueue(workqueue); | ||
7702 | |||
7703 | return rc; | ||
7704 | diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c | ||
7705 | index 41767f7239bb..0556a9749dbe 100644 | ||
7706 | --- a/drivers/mfd/arizona-core.c | ||
7707 | +++ b/drivers/mfd/arizona-core.c | ||
7708 | @@ -1038,7 +1038,7 @@ int arizona_dev_init(struct arizona *arizona) | ||
7709 | unsigned int reg, val, mask; | ||
7710 | int (*apply_patch)(struct arizona *) = NULL; | ||
7711 | const struct mfd_cell *subdevs = NULL; | ||
7712 | - int n_subdevs, ret, i; | ||
7713 | + int n_subdevs = 0, ret, i; | ||
7714 | |||
7715 | dev_set_drvdata(arizona->dev, arizona); | ||
7716 | mutex_init(&arizona->clk_lock); | ||
7717 | diff --git a/drivers/mfd/hi655x-pmic.c b/drivers/mfd/hi655x-pmic.c | ||
7718 | index 11347a3e6d40..c311b869be38 100644 | ||
7719 | --- a/drivers/mfd/hi655x-pmic.c | ||
7720 | +++ b/drivers/mfd/hi655x-pmic.c | ||
7721 | @@ -111,6 +111,8 @@ static int hi655x_pmic_probe(struct platform_device *pdev) | ||
7722 | |||
7723 | pmic->regmap = devm_regmap_init_mmio_clk(dev, NULL, base, | ||
7724 | &hi655x_regmap_config); | ||
7725 | + if (IS_ERR(pmic->regmap)) | ||
7726 | + return PTR_ERR(pmic->regmap); | ||
7727 | |||
7728 | regmap_read(pmic->regmap, HI655X_BUS_ADDR(HI655X_VER_REG), &pmic->ver); | ||
7729 | if ((pmic->ver < PMU_VER_START) || (pmic->ver > PMU_VER_END)) { | ||
7730 | diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c | ||
7731 | index c57e407020f1..5c8ed2150c8b 100644 | ||
7732 | --- a/drivers/mfd/mfd-core.c | ||
7733 | +++ b/drivers/mfd/mfd-core.c | ||
7734 | @@ -179,6 +179,7 @@ static int mfd_add_device(struct device *parent, int id, | ||
7735 | for_each_child_of_node(parent->of_node, np) { | ||
7736 | if (of_device_is_compatible(np, cell->of_compatible)) { | ||
7737 | pdev->dev.of_node = np; | ||
7738 | + pdev->dev.fwnode = &np->fwnode; | ||
7739 | break; | ||
7740 | } | ||
7741 | } | ||
7742 | diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c | ||
7743 | index fd01138c411e..5b116ec756b4 100644 | ||
7744 | --- a/drivers/net/bonding/bond_main.c | ||
7745 | +++ b/drivers/net/bonding/bond_main.c | ||
7746 | @@ -3788,8 +3788,8 @@ static u32 bond_rr_gen_slave_id(struct bonding *bond) | ||
7747 | static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev) | ||
7748 | { | ||
7749 | struct bonding *bond = netdev_priv(bond_dev); | ||
7750 | - struct iphdr *iph = ip_hdr(skb); | ||
7751 | struct slave *slave; | ||
7752 | + int slave_cnt; | ||
7753 | u32 slave_id; | ||
7754 | |||
7755 | /* Start with the curr_active_slave that joined the bond as the | ||
7756 | @@ -3798,23 +3798,32 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev | ||
7757 | * send the join/membership reports. The curr_active_slave found | ||
7758 | * will send all of this type of traffic. | ||
7759 | */ | ||
7760 | - if (iph->protocol == IPPROTO_IGMP && skb->protocol == htons(ETH_P_IP)) { | ||
7761 | - slave = rcu_dereference(bond->curr_active_slave); | ||
7762 | - if (slave) | ||
7763 | - bond_dev_queue_xmit(bond, skb, slave->dev); | ||
7764 | - else | ||
7765 | - bond_xmit_slave_id(bond, skb, 0); | ||
7766 | - } else { | ||
7767 | - int slave_cnt = ACCESS_ONCE(bond->slave_cnt); | ||
7768 | + if (skb->protocol == htons(ETH_P_IP)) { | ||
7769 | + int noff = skb_network_offset(skb); | ||
7770 | + struct iphdr *iph; | ||
7771 | |||
7772 | - if (likely(slave_cnt)) { | ||
7773 | - slave_id = bond_rr_gen_slave_id(bond); | ||
7774 | - bond_xmit_slave_id(bond, skb, slave_id % slave_cnt); | ||
7775 | - } else { | ||
7776 | - bond_tx_drop(bond_dev, skb); | ||
7777 | + if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph)))) | ||
7778 | + goto non_igmp; | ||
7779 | + | ||
7780 | + iph = ip_hdr(skb); | ||
7781 | + if (iph->protocol == IPPROTO_IGMP) { | ||
7782 | + slave = rcu_dereference(bond->curr_active_slave); | ||
7783 | + if (slave) | ||
7784 | + bond_dev_queue_xmit(bond, skb, slave->dev); | ||
7785 | + else | ||
7786 | + bond_xmit_slave_id(bond, skb, 0); | ||
7787 | + return NETDEV_TX_OK; | ||
7788 | } | ||
7789 | } | ||
7790 | |||
7791 | +non_igmp: | ||
7792 | + slave_cnt = ACCESS_ONCE(bond->slave_cnt); | ||
7793 | + if (likely(slave_cnt)) { | ||
7794 | + slave_id = bond_rr_gen_slave_id(bond); | ||
7795 | + bond_xmit_slave_id(bond, skb, slave_id % slave_cnt); | ||
7796 | + } else { | ||
7797 | + bond_tx_drop(bond_dev, skb); | ||
7798 | + } | ||
7799 | return NETDEV_TX_OK; | ||
7800 | } | ||
7801 | |||
7802 | diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c | ||
7803 | index ddabce759456..7f79a6cf5665 100644 | ||
7804 | --- a/drivers/net/caif/caif_hsi.c | ||
7805 | +++ b/drivers/net/caif/caif_hsi.c | ||
7806 | @@ -1464,7 +1464,7 @@ static void __exit cfhsi_exit_module(void) | ||
7807 | rtnl_lock(); | ||
7808 | list_for_each_safe(list_node, n, &cfhsi_list) { | ||
7809 | cfhsi = list_entry(list_node, struct cfhsi, list); | ||
7810 | - unregister_netdev(cfhsi->ndev); | ||
7811 | + unregister_netdevice(cfhsi->ndev); | ||
7812 | } | ||
7813 | rtnl_unlock(); | ||
7814 | } | ||
7815 | diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c | ||
7816 | index 2edd193c96ab..f157b81551b7 100644 | ||
7817 | --- a/drivers/net/dsa/mv88e6xxx/chip.c | ||
7818 | +++ b/drivers/net/dsa/mv88e6xxx/chip.c | ||
7819 | @@ -3846,6 +3846,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) | ||
7820 | mv88e6xxx_mdio_unregister(chip); | ||
7821 | return err; | ||
7822 | } | ||
7823 | + if (chip->reset) | ||
7824 | + usleep_range(1000, 2000); | ||
7825 | |||
7826 | return 0; | ||
7827 | } | ||
7828 | diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | ||
7829 | index 2cd1dcd77559..6167bb0c71ed 100644 | ||
7830 | --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | ||
7831 | +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | ||
7832 | @@ -286,6 +286,9 @@ int bnx2x_tx_int(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata) | ||
7833 | hw_cons = le16_to_cpu(*txdata->tx_cons_sb); | ||
7834 | sw_cons = txdata->tx_pkt_cons; | ||
7835 | |||
7836 | + /* Ensure subsequent loads occur after hw_cons */ | ||
7837 | + smp_rmb(); | ||
7838 | + | ||
7839 | while (sw_cons != hw_cons) { | ||
7840 | u16 pkt_cons; | ||
7841 | |||
7842 | @@ -3860,9 +3863,12 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev) | ||
7843 | |||
7844 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { | ||
7845 | if (!(bp->flags & TX_TIMESTAMPING_EN)) { | ||
7846 | + bp->eth_stats.ptp_skip_tx_ts++; | ||
7847 | BNX2X_ERR("Tx timestamping was not enabled, this packet will not be timestamped\n"); | ||
7848 | } else if (bp->ptp_tx_skb) { | ||
7849 | - BNX2X_ERR("The device supports only a single outstanding packet to timestamp, this packet will not be timestamped\n"); | ||
7850 | + bp->eth_stats.ptp_skip_tx_ts++; | ||
7851 | + dev_err_once(&bp->dev->dev, | ||
7852 | + "Device supports only a single outstanding packet to timestamp, this packet won't be timestamped\n"); | ||
7853 | } else { | ||
7854 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; | ||
7855 | /* schedule check for Tx timestamp */ | ||
7856 | diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | ||
7857 | index 15a0850e6bde..b1992f464b3d 100644 | ||
7858 | --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | ||
7859 | +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | ||
7860 | @@ -182,7 +182,9 @@ static const struct { | ||
7861 | { STATS_OFFSET32(driver_filtered_tx_pkt), | ||
7862 | 4, false, "driver_filtered_tx_pkt" }, | ||
7863 | { STATS_OFFSET32(eee_tx_lpi), | ||
7864 | - 4, true, "Tx LPI entry count"} | ||
7865 | + 4, true, "Tx LPI entry count"}, | ||
7866 | + { STATS_OFFSET32(ptp_skip_tx_ts), | ||
7867 | + 4, false, "ptp_skipped_tx_tstamp" }, | ||
7868 | }; | ||
7869 | |||
7870 | #define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr) | ||
7871 | diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | ||
7872 | index eeeb4c5740bf..2ef6012c3dc5 100644 | ||
7873 | --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | ||
7874 | +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | ||
7875 | @@ -15261,11 +15261,24 @@ static void bnx2x_ptp_task(struct work_struct *work) | ||
7876 | u32 val_seq; | ||
7877 | u64 timestamp, ns; | ||
7878 | struct skb_shared_hwtstamps shhwtstamps; | ||
7879 | + bool bail = true; | ||
7880 | + int i; | ||
7881 | + | ||
7882 | + /* FW may take a while to complete timestamping; try a bit and if it's | ||
7883 | + * still not complete, may indicate an error state - bail out then. | ||
7884 | + */ | ||
7885 | + for (i = 0; i < 10; i++) { | ||
7886 | + /* Read Tx timestamp registers */ | ||
7887 | + val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID : | ||
7888 | + NIG_REG_P0_TLLH_PTP_BUF_SEQID); | ||
7889 | + if (val_seq & 0x10000) { | ||
7890 | + bail = false; | ||
7891 | + break; | ||
7892 | + } | ||
7893 | + msleep(1 << i); | ||
7894 | + } | ||
7895 | |||
7896 | - /* Read Tx timestamp registers */ | ||
7897 | - val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID : | ||
7898 | - NIG_REG_P0_TLLH_PTP_BUF_SEQID); | ||
7899 | - if (val_seq & 0x10000) { | ||
7900 | + if (!bail) { | ||
7901 | /* There is a valid timestamp value */ | ||
7902 | timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB : | ||
7903 | NIG_REG_P0_TLLH_PTP_BUF_TS_MSB); | ||
7904 | @@ -15280,16 +15293,18 @@ static void bnx2x_ptp_task(struct work_struct *work) | ||
7905 | memset(&shhwtstamps, 0, sizeof(shhwtstamps)); | ||
7906 | shhwtstamps.hwtstamp = ns_to_ktime(ns); | ||
7907 | skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps); | ||
7908 | - dev_kfree_skb_any(bp->ptp_tx_skb); | ||
7909 | - bp->ptp_tx_skb = NULL; | ||
7910 | |||
7911 | DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n", | ||
7912 | timestamp, ns); | ||
7913 | } else { | ||
7914 | - DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n"); | ||
7915 | - /* Reschedule to keep checking for a valid timestamp value */ | ||
7916 | - schedule_work(&bp->ptp_task); | ||
7917 | + DP(BNX2X_MSG_PTP, | ||
7918 | + "Tx timestamp is not recorded (register read=%u)\n", | ||
7919 | + val_seq); | ||
7920 | + bp->eth_stats.ptp_skip_tx_ts++; | ||
7921 | } | ||
7922 | + | ||
7923 | + dev_kfree_skb_any(bp->ptp_tx_skb); | ||
7924 | + bp->ptp_tx_skb = NULL; | ||
7925 | } | ||
7926 | |||
7927 | void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb) | ||
7928 | diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h | ||
7929 | index b2644ed13d06..d55e63692cf3 100644 | ||
7930 | --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h | ||
7931 | +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h | ||
7932 | @@ -207,6 +207,9 @@ struct bnx2x_eth_stats { | ||
7933 | u32 driver_filtered_tx_pkt; | ||
7934 | /* src: Clear-on-Read register; Will not survive PMF Migration */ | ||
7935 | u32 eee_tx_lpi; | ||
7936 | + | ||
7937 | + /* PTP */ | ||
7938 | + u32 ptp_skip_tx_ts; | ||
7939 | }; | ||
7940 | |||
7941 | struct bnx2x_eth_q_stats { | ||
7942 | diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c | ||
7943 | index 3480b3078775..1bb923e3a2bc 100644 | ||
7944 | --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c | ||
7945 | +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c | ||
7946 | @@ -3002,39 +3002,42 @@ static void bcmgenet_timeout(struct net_device *dev) | ||
7947 | netif_tx_wake_all_queues(dev); | ||
7948 | } | ||
7949 | |||
7950 | -#define MAX_MC_COUNT 16 | ||
7951 | +#define MAX_MDF_FILTER 17 | ||
7952 | |||
7953 | static inline void bcmgenet_set_mdf_addr(struct bcmgenet_priv *priv, | ||
7954 | unsigned char *addr, | ||
7955 | - int *i, | ||
7956 | - int *mc) | ||
7957 | + int *i) | ||
7958 | { | ||
7959 | - u32 reg; | ||
7960 | - | ||
7961 | bcmgenet_umac_writel(priv, addr[0] << 8 | addr[1], | ||
7962 | UMAC_MDF_ADDR + (*i * 4)); | ||
7963 | bcmgenet_umac_writel(priv, addr[2] << 24 | addr[3] << 16 | | ||
7964 | addr[4] << 8 | addr[5], | ||
7965 | UMAC_MDF_ADDR + ((*i + 1) * 4)); | ||
7966 | - reg = bcmgenet_umac_readl(priv, UMAC_MDF_CTRL); | ||
7967 | - reg |= (1 << (MAX_MC_COUNT - *mc)); | ||
7968 | - bcmgenet_umac_writel(priv, reg, UMAC_MDF_CTRL); | ||
7969 | *i += 2; | ||
7970 | - (*mc)++; | ||
7971 | } | ||
7972 | |||
7973 | static void bcmgenet_set_rx_mode(struct net_device *dev) | ||
7974 | { | ||
7975 | struct bcmgenet_priv *priv = netdev_priv(dev); | ||
7976 | struct netdev_hw_addr *ha; | ||
7977 | - int i, mc; | ||
7978 | + int i, nfilter; | ||
7979 | u32 reg; | ||
7980 | |||
7981 | netif_dbg(priv, hw, dev, "%s: %08X\n", __func__, dev->flags); | ||
7982 | |||
7983 | - /* Promiscuous mode */ | ||
7984 | + /* Number of filters needed */ | ||
7985 | + nfilter = netdev_uc_count(dev) + netdev_mc_count(dev) + 2; | ||
7986 | + | ||
7987 | + /* | ||
7988 | + * Turn on promicuous mode for three scenarios | ||
7989 | + * 1. IFF_PROMISC flag is set | ||
7990 | + * 2. IFF_ALLMULTI flag is set | ||
7991 | + * 3. The number of filters needed exceeds the number filters | ||
7992 | + * supported by the hardware. | ||
7993 | + */ | ||
7994 | reg = bcmgenet_umac_readl(priv, UMAC_CMD); | ||
7995 | - if (dev->flags & IFF_PROMISC) { | ||
7996 | + if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) || | ||
7997 | + (nfilter > MAX_MDF_FILTER)) { | ||
7998 | reg |= CMD_PROMISC; | ||
7999 | bcmgenet_umac_writel(priv, reg, UMAC_CMD); | ||
8000 | bcmgenet_umac_writel(priv, 0, UMAC_MDF_CTRL); | ||
8001 | @@ -3044,32 +3047,24 @@ static void bcmgenet_set_rx_mode(struct net_device *dev) | ||
8002 | bcmgenet_umac_writel(priv, reg, UMAC_CMD); | ||
8003 | } | ||
8004 | |||
8005 | - /* UniMac doesn't support ALLMULTI */ | ||
8006 | - if (dev->flags & IFF_ALLMULTI) { | ||
8007 | - netdev_warn(dev, "ALLMULTI is not supported\n"); | ||
8008 | - return; | ||
8009 | - } | ||
8010 | - | ||
8011 | /* update MDF filter */ | ||
8012 | i = 0; | ||
8013 | - mc = 0; | ||
8014 | /* Broadcast */ | ||
8015 | - bcmgenet_set_mdf_addr(priv, dev->broadcast, &i, &mc); | ||
8016 | + bcmgenet_set_mdf_addr(priv, dev->broadcast, &i); | ||
8017 | /* my own address.*/ | ||
8018 | - bcmgenet_set_mdf_addr(priv, dev->dev_addr, &i, &mc); | ||
8019 | - /* Unicast list*/ | ||
8020 | - if (netdev_uc_count(dev) > (MAX_MC_COUNT - mc)) | ||
8021 | - return; | ||
8022 | + bcmgenet_set_mdf_addr(priv, dev->dev_addr, &i); | ||
8023 | |||
8024 | - if (!netdev_uc_empty(dev)) | ||
8025 | - netdev_for_each_uc_addr(ha, dev) | ||
8026 | - bcmgenet_set_mdf_addr(priv, ha->addr, &i, &mc); | ||
8027 | - /* Multicast */ | ||
8028 | - if (netdev_mc_empty(dev) || netdev_mc_count(dev) >= (MAX_MC_COUNT - mc)) | ||
8029 | - return; | ||
8030 | + /* Unicast */ | ||
8031 | + netdev_for_each_uc_addr(ha, dev) | ||
8032 | + bcmgenet_set_mdf_addr(priv, ha->addr, &i); | ||
8033 | |||
8034 | + /* Multicast */ | ||
8035 | netdev_for_each_mc_addr(ha, dev) | ||
8036 | - bcmgenet_set_mdf_addr(priv, ha->addr, &i, &mc); | ||
8037 | + bcmgenet_set_mdf_addr(priv, ha->addr, &i); | ||
8038 | + | ||
8039 | + /* Enable filters */ | ||
8040 | + reg = GENMASK(MAX_MDF_FILTER - 1, MAX_MDF_FILTER - nfilter); | ||
8041 | + bcmgenet_umac_writel(priv, reg, UMAC_MDF_CTRL); | ||
8042 | } | ||
8043 | |||
8044 | /* Set the hardware MAC address. */ | ||
8045 | diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c | ||
8046 | index 1eb34109b207..92ea760c4822 100644 | ||
8047 | --- a/drivers/net/ethernet/freescale/fec_main.c | ||
8048 | +++ b/drivers/net/ethernet/freescale/fec_main.c | ||
8049 | @@ -1685,10 +1685,10 @@ static void fec_get_mac(struct net_device *ndev) | ||
8050 | */ | ||
8051 | if (!is_valid_ether_addr(iap)) { | ||
8052 | /* Report it and use a random ethernet address instead */ | ||
8053 | - netdev_err(ndev, "Invalid MAC address: %pM\n", iap); | ||
8054 | + dev_err(&fep->pdev->dev, "Invalid MAC address: %pM\n", iap); | ||
8055 | eth_hw_addr_random(ndev); | ||
8056 | - netdev_info(ndev, "Using random MAC address: %pM\n", | ||
8057 | - ndev->dev_addr); | ||
8058 | + dev_info(&fep->pdev->dev, "Using random MAC address: %pM\n", | ||
8059 | + ndev->dev_addr); | ||
8060 | return; | ||
8061 | } | ||
8062 | |||
8063 | diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | ||
8064 | index a137e060c185..bbc23e88de89 100644 | ||
8065 | --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | ||
8066 | +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | ||
8067 | @@ -3192,7 +3192,8 @@ static int ixgbe_get_module_info(struct net_device *dev, | ||
8068 | page_swap = true; | ||
8069 | } | ||
8070 | |||
8071 | - if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap) { | ||
8072 | + if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap || | ||
8073 | + !(addr_mode & IXGBE_SFF_DDM_IMPLEMENTED)) { | ||
8074 | /* We have a SFP, but it does not support SFF-8472 */ | ||
8075 | modinfo->type = ETH_MODULE_SFF_8079; | ||
8076 | modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; | ||
8077 | diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h | ||
8078 | index cc735ec3e045..25090b4880b3 100644 | ||
8079 | --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h | ||
8080 | +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h | ||
8081 | @@ -70,6 +70,7 @@ | ||
8082 | #define IXGBE_SFF_SOFT_RS_SELECT_10G 0x8 | ||
8083 | #define IXGBE_SFF_SOFT_RS_SELECT_1G 0x0 | ||
8084 | #define IXGBE_SFF_ADDRESSING_MODE 0x4 | ||
8085 | +#define IXGBE_SFF_DDM_IMPLEMENTED 0x40 | ||
8086 | #define IXGBE_SFF_QSFP_DA_ACTIVE_CABLE 0x1 | ||
8087 | #define IXGBE_SFF_QSFP_DA_PASSIVE_CABLE 0x8 | ||
8088 | #define IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE 0x23 | ||
8089 | diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c | ||
8090 | index 4ac023a37936..59dbecd19c93 100644 | ||
8091 | --- a/drivers/net/ethernet/marvell/sky2.c | ||
8092 | +++ b/drivers/net/ethernet/marvell/sky2.c | ||
8093 | @@ -4939,6 +4939,13 @@ static const struct dmi_system_id msi_blacklist[] = { | ||
8094 | DMI_MATCH(DMI_PRODUCT_NAME, "P-79"), | ||
8095 | }, | ||
8096 | }, | ||
8097 | + { | ||
8098 | + .ident = "ASUS P6T", | ||
8099 | + .matches = { | ||
8100 | + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), | ||
8101 | + DMI_MATCH(DMI_BOARD_NAME, "P6T"), | ||
8102 | + }, | ||
8103 | + }, | ||
8104 | {} | ||
8105 | }; | ||
8106 | |||
8107 | diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | ||
8108 | index 7d19029e2564..093e58e94075 100644 | ||
8109 | --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | ||
8110 | +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | ||
8111 | @@ -213,6 +213,12 @@ static void dwmac1000_set_filter(struct mac_device_info *hw, | ||
8112 | GMAC_ADDR_LOW(reg)); | ||
8113 | reg++; | ||
8114 | } | ||
8115 | + | ||
8116 | + while (reg <= perfect_addr_number) { | ||
8117 | + writel(0, ioaddr + GMAC_ADDR_HIGH(reg)); | ||
8118 | + writel(0, ioaddr + GMAC_ADDR_LOW(reg)); | ||
8119 | + reg++; | ||
8120 | + } | ||
8121 | } | ||
8122 | |||
8123 | #ifdef FRAME_FILTER_DEBUG | ||
8124 | diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | ||
8125 | index 51019b794be5..f46f2bfc2cc0 100644 | ||
8126 | --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | ||
8127 | +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | ||
8128 | @@ -173,14 +173,20 @@ static void dwmac4_set_filter(struct mac_device_info *hw, | ||
8129 | * are required | ||
8130 | */ | ||
8131 | value |= GMAC_PACKET_FILTER_PR; | ||
8132 | - } else if (!netdev_uc_empty(dev)) { | ||
8133 | - int reg = 1; | ||
8134 | + } else { | ||
8135 | struct netdev_hw_addr *ha; | ||
8136 | + int reg = 1; | ||
8137 | |||
8138 | netdev_for_each_uc_addr(ha, dev) { | ||
8139 | dwmac4_set_umac_addr(hw, ha->addr, reg); | ||
8140 | reg++; | ||
8141 | } | ||
8142 | + | ||
8143 | + while (reg <= GMAC_MAX_PERFECT_ADDRESSES) { | ||
8144 | + writel(0, ioaddr + GMAC_ADDR_HIGH(reg)); | ||
8145 | + writel(0, ioaddr + GMAC_ADDR_LOW(reg)); | ||
8146 | + reg++; | ||
8147 | + } | ||
8148 | } | ||
8149 | |||
8150 | writel(value, ioaddr + GMAC_PACKET_FILTER); | ||
8151 | diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c | ||
8152 | index a8afc92cbfca..5f21ddff9e0f 100644 | ||
8153 | --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c | ||
8154 | +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c | ||
8155 | @@ -612,6 +612,10 @@ static void axienet_start_xmit_done(struct net_device *ndev) | ||
8156 | |||
8157 | ndev->stats.tx_packets += packets; | ||
8158 | ndev->stats.tx_bytes += size; | ||
8159 | + | ||
8160 | + /* Matches barrier in axienet_start_xmit */ | ||
8161 | + smp_mb(); | ||
8162 | + | ||
8163 | netif_wake_queue(ndev); | ||
8164 | } | ||
8165 | |||
8166 | @@ -666,9 +670,19 @@ static int axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev) | ||
8167 | cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; | ||
8168 | |||
8169 | if (axienet_check_tx_bd_space(lp, num_frag)) { | ||
8170 | - if (!netif_queue_stopped(ndev)) | ||
8171 | - netif_stop_queue(ndev); | ||
8172 | - return NETDEV_TX_BUSY; | ||
8173 | + if (netif_queue_stopped(ndev)) | ||
8174 | + return NETDEV_TX_BUSY; | ||
8175 | + | ||
8176 | + netif_stop_queue(ndev); | ||
8177 | + | ||
8178 | + /* Matches barrier in axienet_start_xmit_done */ | ||
8179 | + smp_mb(); | ||
8180 | + | ||
8181 | + /* Space might have just been freed - check again */ | ||
8182 | + if (axienet_check_tx_bd_space(lp, num_frag)) | ||
8183 | + return NETDEV_TX_BUSY; | ||
8184 | + | ||
8185 | + netif_wake_queue(ndev); | ||
8186 | } | ||
8187 | |||
8188 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | ||
8189 | diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c | ||
8190 | index cb206e5526c4..7e1df403a37d 100644 | ||
8191 | --- a/drivers/net/gtp.c | ||
8192 | +++ b/drivers/net/gtp.c | ||
8193 | @@ -952,7 +952,7 @@ static int ipv4_pdp_add(struct net_device *dev, struct genl_info *info) | ||
8194 | |||
8195 | } | ||
8196 | |||
8197 | - pctx = kmalloc(sizeof(struct pdp_ctx), GFP_KERNEL); | ||
8198 | + pctx = kmalloc(sizeof(*pctx), GFP_ATOMIC); | ||
8199 | if (pctx == NULL) | ||
8200 | return -ENOMEM; | ||
8201 | |||
8202 | @@ -1358,9 +1358,9 @@ late_initcall(gtp_init); | ||
8203 | |||
8204 | static void __exit gtp_fini(void) | ||
8205 | { | ||
8206 | - unregister_pernet_subsys(>p_net_ops); | ||
8207 | genl_unregister_family(>p_genl_family); | ||
8208 | rtnl_link_unregister(>p_link_ops); | ||
8209 | + unregister_pernet_subsys(>p_net_ops); | ||
8210 | |||
8211 | pr_info("GTP module unloaded\n"); | ||
8212 | } | ||
8213 | diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c | ||
8214 | index 653f0b185a68..d91f020a8491 100644 | ||
8215 | --- a/drivers/net/macsec.c | ||
8216 | +++ b/drivers/net/macsec.c | ||
8217 | @@ -867,6 +867,7 @@ static void macsec_reset_skb(struct sk_buff *skb, struct net_device *dev) | ||
8218 | |||
8219 | static void macsec_finalize_skb(struct sk_buff *skb, u8 icv_len, u8 hdr_len) | ||
8220 | { | ||
8221 | + skb->ip_summed = CHECKSUM_NONE; | ||
8222 | memmove(skb->data + hdr_len, skb->data, 2 * ETH_ALEN); | ||
8223 | skb_pull(skb, hdr_len); | ||
8224 | pskb_trim_unique(skb, skb->len - icv_len); | ||
8225 | @@ -1105,10 +1106,9 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb) | ||
8226 | } | ||
8227 | |||
8228 | skb = skb_unshare(skb, GFP_ATOMIC); | ||
8229 | - if (!skb) { | ||
8230 | - *pskb = NULL; | ||
8231 | + *pskb = skb; | ||
8232 | + if (!skb) | ||
8233 | return RX_HANDLER_CONSUMED; | ||
8234 | - } | ||
8235 | |||
8236 | pulled_sci = pskb_may_pull(skb, macsec_extra_len(true)); | ||
8237 | if (!pulled_sci) { | ||
8238 | diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c | ||
8239 | index 5048a6df6a8e..5c2c72b1ef8b 100644 | ||
8240 | --- a/drivers/net/phy/phy_device.c | ||
8241 | +++ b/drivers/net/phy/phy_device.c | ||
8242 | @@ -673,6 +673,9 @@ int phy_connect_direct(struct net_device *dev, struct phy_device *phydev, | ||
8243 | { | ||
8244 | int rc; | ||
8245 | |||
8246 | + if (!dev) | ||
8247 | + return -EINVAL; | ||
8248 | + | ||
8249 | rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); | ||
8250 | if (rc) | ||
8251 | return rc; | ||
8252 | @@ -965,6 +968,9 @@ struct phy_device *phy_attach(struct net_device *dev, const char *bus_id, | ||
8253 | struct device *d; | ||
8254 | int rc; | ||
8255 | |||
8256 | + if (!dev) | ||
8257 | + return ERR_PTR(-EINVAL); | ||
8258 | + | ||
8259 | /* Search the list of PHY devices on the mdio bus for the | ||
8260 | * PHY with the requested name | ||
8261 | */ | ||
8262 | diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c | ||
8263 | index 393fd3ed6b94..4b12b6da3fab 100644 | ||
8264 | --- a/drivers/net/usb/asix_devices.c | ||
8265 | +++ b/drivers/net/usb/asix_devices.c | ||
8266 | @@ -237,7 +237,7 @@ static void asix_phy_reset(struct usbnet *dev, unsigned int reset_bits) | ||
8267 | static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf) | ||
8268 | { | ||
8269 | int ret = 0; | ||
8270 | - u8 buf[ETH_ALEN]; | ||
8271 | + u8 buf[ETH_ALEN] = {0}; | ||
8272 | int i; | ||
8273 | unsigned long gpio_bits = dev->driver_info->data; | ||
8274 | |||
8275 | @@ -687,7 +687,7 @@ static int asix_resume(struct usb_interface *intf) | ||
8276 | static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) | ||
8277 | { | ||
8278 | int ret, i; | ||
8279 | - u8 buf[ETH_ALEN], chipcode = 0; | ||
8280 | + u8 buf[ETH_ALEN] = {0}, chipcode = 0; | ||
8281 | u32 phyid; | ||
8282 | struct asix_common_private *priv; | ||
8283 | |||
8284 | @@ -1064,7 +1064,7 @@ static const struct net_device_ops ax88178_netdev_ops = { | ||
8285 | static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf) | ||
8286 | { | ||
8287 | int ret; | ||
8288 | - u8 buf[ETH_ALEN]; | ||
8289 | + u8 buf[ETH_ALEN] = {0}; | ||
8290 | |||
8291 | usbnet_get_endpoints(dev,intf); | ||
8292 | |||
8293 | diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c | ||
8294 | index 42c9480acdc7..3b6e908d3164 100644 | ||
8295 | --- a/drivers/net/vrf.c | ||
8296 | +++ b/drivers/net/vrf.c | ||
8297 | @@ -153,23 +153,29 @@ static int vrf_ip6_local_out(struct net *net, struct sock *sk, | ||
8298 | static netdev_tx_t vrf_process_v6_outbound(struct sk_buff *skb, | ||
8299 | struct net_device *dev) | ||
8300 | { | ||
8301 | - const struct ipv6hdr *iph = ipv6_hdr(skb); | ||
8302 | + const struct ipv6hdr *iph; | ||
8303 | struct net *net = dev_net(skb->dev); | ||
8304 | - struct flowi6 fl6 = { | ||
8305 | - /* needed to match OIF rule */ | ||
8306 | - .flowi6_oif = dev->ifindex, | ||
8307 | - .flowi6_iif = LOOPBACK_IFINDEX, | ||
8308 | - .daddr = iph->daddr, | ||
8309 | - .saddr = iph->saddr, | ||
8310 | - .flowlabel = ip6_flowinfo(iph), | ||
8311 | - .flowi6_mark = skb->mark, | ||
8312 | - .flowi6_proto = iph->nexthdr, | ||
8313 | - .flowi6_flags = FLOWI_FLAG_SKIP_NH_OIF, | ||
8314 | - }; | ||
8315 | + struct flowi6 fl6; | ||
8316 | int ret = NET_XMIT_DROP; | ||
8317 | struct dst_entry *dst; | ||
8318 | struct dst_entry *dst_null = &net->ipv6.ip6_null_entry->dst; | ||
8319 | |||
8320 | + if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct ipv6hdr))) | ||
8321 | + goto err; | ||
8322 | + | ||
8323 | + iph = ipv6_hdr(skb); | ||
8324 | + | ||
8325 | + memset(&fl6, 0, sizeof(fl6)); | ||
8326 | + /* needed to match OIF rule */ | ||
8327 | + fl6.flowi6_oif = dev->ifindex; | ||
8328 | + fl6.flowi6_iif = LOOPBACK_IFINDEX; | ||
8329 | + fl6.daddr = iph->daddr; | ||
8330 | + fl6.saddr = iph->saddr; | ||
8331 | + fl6.flowlabel = ip6_flowinfo(iph); | ||
8332 | + fl6.flowi6_mark = skb->mark; | ||
8333 | + fl6.flowi6_proto = iph->nexthdr; | ||
8334 | + fl6.flowi6_flags = FLOWI_FLAG_SKIP_NH_OIF; | ||
8335 | + | ||
8336 | dst = ip6_route_output(net, NULL, &fl6); | ||
8337 | if (dst == dst_null) | ||
8338 | goto err; | ||
8339 | @@ -257,21 +263,27 @@ static int vrf_ip_local_out(struct net *net, struct sock *sk, | ||
8340 | static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb, | ||
8341 | struct net_device *vrf_dev) | ||
8342 | { | ||
8343 | - struct iphdr *ip4h = ip_hdr(skb); | ||
8344 | + struct iphdr *ip4h; | ||
8345 | int ret = NET_XMIT_DROP; | ||
8346 | - struct flowi4 fl4 = { | ||
8347 | - /* needed to match OIF rule */ | ||
8348 | - .flowi4_oif = vrf_dev->ifindex, | ||
8349 | - .flowi4_iif = LOOPBACK_IFINDEX, | ||
8350 | - .flowi4_tos = RT_TOS(ip4h->tos), | ||
8351 | - .flowi4_flags = FLOWI_FLAG_ANYSRC | FLOWI_FLAG_SKIP_NH_OIF, | ||
8352 | - .flowi4_proto = ip4h->protocol, | ||
8353 | - .daddr = ip4h->daddr, | ||
8354 | - .saddr = ip4h->saddr, | ||
8355 | - }; | ||
8356 | + struct flowi4 fl4; | ||
8357 | struct net *net = dev_net(vrf_dev); | ||
8358 | struct rtable *rt; | ||
8359 | |||
8360 | + if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr))) | ||
8361 | + goto err; | ||
8362 | + | ||
8363 | + ip4h = ip_hdr(skb); | ||
8364 | + | ||
8365 | + memset(&fl4, 0, sizeof(fl4)); | ||
8366 | + /* needed to match OIF rule */ | ||
8367 | + fl4.flowi4_oif = vrf_dev->ifindex; | ||
8368 | + fl4.flowi4_iif = LOOPBACK_IFINDEX; | ||
8369 | + fl4.flowi4_tos = RT_TOS(ip4h->tos); | ||
8370 | + fl4.flowi4_flags = FLOWI_FLAG_ANYSRC | FLOWI_FLAG_SKIP_NH_OIF; | ||
8371 | + fl4.flowi4_proto = ip4h->protocol; | ||
8372 | + fl4.daddr = ip4h->daddr; | ||
8373 | + fl4.saddr = ip4h->saddr; | ||
8374 | + | ||
8375 | rt = ip_route_output_flow(net, &fl4, NULL); | ||
8376 | if (IS_ERR(rt)) | ||
8377 | goto err; | ||
8378 | diff --git a/drivers/net/wireless/ath/ath10k/hw.c b/drivers/net/wireless/ath/ath10k/hw.c | ||
8379 | index 675e75d66db2..14dc6548701c 100644 | ||
8380 | --- a/drivers/net/wireless/ath/ath10k/hw.c | ||
8381 | +++ b/drivers/net/wireless/ath/ath10k/hw.c | ||
8382 | @@ -157,7 +157,7 @@ const struct ath10k_hw_values qca6174_values = { | ||
8383 | }; | ||
8384 | |||
8385 | const struct ath10k_hw_values qca99x0_values = { | ||
8386 | - .rtc_state_val_on = 5, | ||
8387 | + .rtc_state_val_on = 7, | ||
8388 | .ce_count = 12, | ||
8389 | .msi_assign_ce_max = 12, | ||
8390 | .num_target_ce_config_wlan = 10, | ||
8391 | diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c | ||
8392 | index fb632a454fc2..1588fe8110d0 100644 | ||
8393 | --- a/drivers/net/wireless/ath/ath10k/mac.c | ||
8394 | +++ b/drivers/net/wireless/ath/ath10k/mac.c | ||
8395 | @@ -1596,6 +1596,10 @@ static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif) | ||
8396 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) | ||
8397 | return 0; | ||
8398 | |||
8399 | + /* For mesh, probe response and beacon share the same template */ | ||
8400 | + if (ieee80211_vif_is_mesh(vif)) | ||
8401 | + return 0; | ||
8402 | + | ||
8403 | prb = ieee80211_proberesp_get(hw, vif); | ||
8404 | if (!prb) { | ||
8405 | ath10k_warn(ar, "failed to get probe resp template from mac80211\n"); | ||
8406 | diff --git a/drivers/net/wireless/ath/ath6kl/wmi.c b/drivers/net/wireless/ath/ath6kl/wmi.c | ||
8407 | index 3fd1cc98fd2f..55609fc4e50e 100644 | ||
8408 | --- a/drivers/net/wireless/ath/ath6kl/wmi.c | ||
8409 | +++ b/drivers/net/wireless/ath/ath6kl/wmi.c | ||
8410 | @@ -1178,6 +1178,10 @@ static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap, | ||
8411 | return -EINVAL; | ||
8412 | |||
8413 | ev = (struct wmi_pstream_timeout_event *) datap; | ||
8414 | + if (ev->traffic_class >= WMM_NUM_AC) { | ||
8415 | + ath6kl_err("invalid traffic class: %d\n", ev->traffic_class); | ||
8416 | + return -EINVAL; | ||
8417 | + } | ||
8418 | |||
8419 | /* | ||
8420 | * When the pstream (fat pipe == AC) timesout, it means there were | ||
8421 | @@ -1519,6 +1523,10 @@ static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len, | ||
8422 | return -EINVAL; | ||
8423 | |||
8424 | reply = (struct wmi_cac_event *) datap; | ||
8425 | + if (reply->ac >= WMM_NUM_AC) { | ||
8426 | + ath6kl_err("invalid AC: %d\n", reply->ac); | ||
8427 | + return -EINVAL; | ||
8428 | + } | ||
8429 | |||
8430 | if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) && | ||
8431 | (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) { | ||
8432 | @@ -2635,7 +2643,7 @@ int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class, | ||
8433 | u16 active_tsids = 0; | ||
8434 | int ret; | ||
8435 | |||
8436 | - if (traffic_class > 3) { | ||
8437 | + if (traffic_class >= WMM_NUM_AC) { | ||
8438 | ath6kl_err("invalid traffic class: %d\n", traffic_class); | ||
8439 | return -EINVAL; | ||
8440 | } | ||
8441 | diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c | ||
8442 | index 951bac2caf12..e7fca78cdd96 100644 | ||
8443 | --- a/drivers/net/wireless/ath/ath9k/hw.c | ||
8444 | +++ b/drivers/net/wireless/ath/ath9k/hw.c | ||
8445 | @@ -250,8 +250,9 @@ void ath9k_hw_get_channel_centers(struct ath_hw *ah, | ||
8446 | /* Chip Revisions */ | ||
8447 | /******************/ | ||
8448 | |||
8449 | -static void ath9k_hw_read_revisions(struct ath_hw *ah) | ||
8450 | +static bool ath9k_hw_read_revisions(struct ath_hw *ah) | ||
8451 | { | ||
8452 | + u32 srev; | ||
8453 | u32 val; | ||
8454 | |||
8455 | if (ah->get_mac_revision) | ||
8456 | @@ -267,25 +268,33 @@ static void ath9k_hw_read_revisions(struct ath_hw *ah) | ||
8457 | val = REG_READ(ah, AR_SREV); | ||
8458 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); | ||
8459 | } | ||
8460 | - return; | ||
8461 | + return true; | ||
8462 | case AR9300_DEVID_AR9340: | ||
8463 | ah->hw_version.macVersion = AR_SREV_VERSION_9340; | ||
8464 | - return; | ||
8465 | + return true; | ||
8466 | case AR9300_DEVID_QCA955X: | ||
8467 | ah->hw_version.macVersion = AR_SREV_VERSION_9550; | ||
8468 | - return; | ||
8469 | + return true; | ||
8470 | case AR9300_DEVID_AR953X: | ||
8471 | ah->hw_version.macVersion = AR_SREV_VERSION_9531; | ||
8472 | - return; | ||
8473 | + return true; | ||
8474 | case AR9300_DEVID_QCA956X: | ||
8475 | ah->hw_version.macVersion = AR_SREV_VERSION_9561; | ||
8476 | - return; | ||
8477 | + return true; | ||
8478 | } | ||
8479 | |||
8480 | - val = REG_READ(ah, AR_SREV) & AR_SREV_ID; | ||
8481 | + srev = REG_READ(ah, AR_SREV); | ||
8482 | + | ||
8483 | + if (srev == -EIO) { | ||
8484 | + ath_err(ath9k_hw_common(ah), | ||
8485 | + "Failed to read SREV register"); | ||
8486 | + return false; | ||
8487 | + } | ||
8488 | + | ||
8489 | + val = srev & AR_SREV_ID; | ||
8490 | |||
8491 | if (val == 0xFF) { | ||
8492 | - val = REG_READ(ah, AR_SREV); | ||
8493 | + val = srev; | ||
8494 | ah->hw_version.macVersion = | ||
8495 | (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S; | ||
8496 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); | ||
8497 | @@ -304,6 +313,8 @@ static void ath9k_hw_read_revisions(struct ath_hw *ah) | ||
8498 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) | ||
8499 | ah->is_pciexpress = true; | ||
8500 | } | ||
8501 | + | ||
8502 | + return true; | ||
8503 | } | ||
8504 | |||
8505 | /************************************/ | ||
8506 | @@ -557,7 +568,10 @@ static int __ath9k_hw_init(struct ath_hw *ah) | ||
8507 | struct ath_common *common = ath9k_hw_common(ah); | ||
8508 | int r = 0; | ||
8509 | |||
8510 | - ath9k_hw_read_revisions(ah); | ||
8511 | + if (!ath9k_hw_read_revisions(ah)) { | ||
8512 | + ath_err(common, "Could not read hardware revisions"); | ||
8513 | + return -EOPNOTSUPP; | ||
8514 | + } | ||
8515 | |||
8516 | switch (ah->hw_version.macVersion) { | ||
8517 | case AR_SREV_VERSION_5416_PCI: | ||
8518 | diff --git a/drivers/net/wireless/ath/dfs_pattern_detector.c b/drivers/net/wireless/ath/dfs_pattern_detector.c | ||
8519 | index 4100ffd42a43..78146607f16e 100644 | ||
8520 | --- a/drivers/net/wireless/ath/dfs_pattern_detector.c | ||
8521 | +++ b/drivers/net/wireless/ath/dfs_pattern_detector.c | ||
8522 | @@ -111,7 +111,7 @@ static const struct radar_detector_specs jp_radar_ref_types[] = { | ||
8523 | JP_PATTERN(0, 0, 1, 1428, 1428, 1, 18, 29, false), | ||
8524 | JP_PATTERN(1, 2, 3, 3846, 3846, 1, 18, 29, false), | ||
8525 | JP_PATTERN(2, 0, 1, 1388, 1388, 1, 18, 50, false), | ||
8526 | - JP_PATTERN(3, 1, 2, 4000, 4000, 1, 18, 50, false), | ||
8527 | + JP_PATTERN(3, 0, 4, 4000, 4000, 1, 18, 50, false), | ||
8528 | JP_PATTERN(4, 0, 5, 150, 230, 1, 23, 50, false), | ||
8529 | JP_PATTERN(5, 6, 10, 200, 500, 1, 16, 50, false), | ||
8530 | JP_PATTERN(6, 11, 20, 200, 500, 1, 12, 50, false), | ||
8531 | diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c | ||
8532 | index bd7ff562d82d..1aa74b87599f 100644 | ||
8533 | --- a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c | ||
8534 | +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c | ||
8535 | @@ -551,6 +551,9 @@ int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb) | ||
8536 | |||
8537 | memcpy(&info, skb->cb, sizeof(info)); | ||
8538 | |||
8539 | + if (WARN_ON_ONCE(skb->len > IEEE80211_MAX_DATA_LEN + hdrlen)) | ||
8540 | + return -1; | ||
8541 | + | ||
8542 | if (WARN_ON_ONCE(info.flags & IEEE80211_TX_CTL_AMPDU)) | ||
8543 | return -1; | ||
8544 | |||
8545 | diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c | ||
8546 | index 25f2a0aceaa2..a2ebe46bcfc5 100644 | ||
8547 | --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c | ||
8548 | +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c | ||
8549 | @@ -1901,10 +1901,18 @@ irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id) | ||
8550 | return IRQ_NONE; | ||
8551 | } | ||
8552 | |||
8553 | - if (iwl_have_debug_level(IWL_DL_ISR)) | ||
8554 | - IWL_DEBUG_ISR(trans, "ISR inta_fh 0x%08x, enabled 0x%08x\n", | ||
8555 | - inta_fh, | ||
8556 | + if (iwl_have_debug_level(IWL_DL_ISR)) { | ||
8557 | + IWL_DEBUG_ISR(trans, | ||
8558 | + "ISR inta_fh 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n", | ||
8559 | + inta_fh, trans_pcie->fh_mask, | ||
8560 | iwl_read32(trans, CSR_MSIX_FH_INT_MASK_AD)); | ||
8561 | + if (inta_fh & ~trans_pcie->fh_mask) | ||
8562 | + IWL_DEBUG_ISR(trans, | ||
8563 | + "We got a masked interrupt (0x%08x)\n", | ||
8564 | + inta_fh & ~trans_pcie->fh_mask); | ||
8565 | + } | ||
8566 | + | ||
8567 | + inta_fh &= trans_pcie->fh_mask; | ||
8568 | |||
8569 | if ((trans_pcie->shared_vec_mask & IWL_SHARED_IRQ_NON_RX) && | ||
8570 | inta_fh & MSIX_FH_INT_CAUSES_Q0) { | ||
8571 | @@ -1943,11 +1951,18 @@ irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id) | ||
8572 | } | ||
8573 | |||
8574 | /* After checking FH register check HW register */ | ||
8575 | - if (iwl_have_debug_level(IWL_DL_ISR)) | ||
8576 | + if (iwl_have_debug_level(IWL_DL_ISR)) { | ||
8577 | IWL_DEBUG_ISR(trans, | ||
8578 | - "ISR inta_hw 0x%08x, enabled 0x%08x\n", | ||
8579 | - inta_hw, | ||
8580 | + "ISR inta_hw 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n", | ||
8581 | + inta_hw, trans_pcie->hw_mask, | ||
8582 | iwl_read32(trans, CSR_MSIX_HW_INT_MASK_AD)); | ||
8583 | + if (inta_hw & ~trans_pcie->hw_mask) | ||
8584 | + IWL_DEBUG_ISR(trans, | ||
8585 | + "We got a masked interrupt 0x%08x\n", | ||
8586 | + inta_hw & ~trans_pcie->hw_mask); | ||
8587 | + } | ||
8588 | + | ||
8589 | + inta_hw &= trans_pcie->hw_mask; | ||
8590 | |||
8591 | /* Alive notification via Rx interrupt will do the real work */ | ||
8592 | if (inta_hw & MSIX_HW_INT_CAUSES_REG_ALIVE) { | ||
8593 | diff --git a/drivers/net/wireless/mediatek/mt7601u/dma.c b/drivers/net/wireless/mediatek/mt7601u/dma.c | ||
8594 | index a8bc064bc14f..56cad16e70ca 100644 | ||
8595 | --- a/drivers/net/wireless/mediatek/mt7601u/dma.c | ||
8596 | +++ b/drivers/net/wireless/mediatek/mt7601u/dma.c | ||
8597 | @@ -193,10 +193,23 @@ static void mt7601u_complete_rx(struct urb *urb) | ||
8598 | struct mt7601u_rx_queue *q = &dev->rx_q; | ||
8599 | unsigned long flags; | ||
8600 | |||
8601 | - spin_lock_irqsave(&dev->rx_lock, flags); | ||
8602 | + /* do no schedule rx tasklet if urb has been unlinked | ||
8603 | + * or the device has been removed | ||
8604 | + */ | ||
8605 | + switch (urb->status) { | ||
8606 | + case -ECONNRESET: | ||
8607 | + case -ESHUTDOWN: | ||
8608 | + case -ENOENT: | ||
8609 | + return; | ||
8610 | + default: | ||
8611 | + dev_err_ratelimited(dev->dev, "rx urb failed: %d\n", | ||
8612 | + urb->status); | ||
8613 | + /* fall through */ | ||
8614 | + case 0: | ||
8615 | + break; | ||
8616 | + } | ||
8617 | |||
8618 | - if (mt7601u_urb_has_error(urb)) | ||
8619 | - dev_err(dev->dev, "Error: RX urb failed:%d\n", urb->status); | ||
8620 | + spin_lock_irqsave(&dev->rx_lock, flags); | ||
8621 | if (WARN_ONCE(q->e[q->end].urb != urb, "RX urb mismatch")) | ||
8622 | goto out; | ||
8623 | |||
8624 | @@ -228,14 +241,25 @@ static void mt7601u_complete_tx(struct urb *urb) | ||
8625 | struct sk_buff *skb; | ||
8626 | unsigned long flags; | ||
8627 | |||
8628 | - spin_lock_irqsave(&dev->tx_lock, flags); | ||
8629 | + switch (urb->status) { | ||
8630 | + case -ECONNRESET: | ||
8631 | + case -ESHUTDOWN: | ||
8632 | + case -ENOENT: | ||
8633 | + return; | ||
8634 | + default: | ||
8635 | + dev_err_ratelimited(dev->dev, "tx urb failed: %d\n", | ||
8636 | + urb->status); | ||
8637 | + /* fall through */ | ||
8638 | + case 0: | ||
8639 | + break; | ||
8640 | + } | ||
8641 | |||
8642 | - if (mt7601u_urb_has_error(urb)) | ||
8643 | - dev_err(dev->dev, "Error: TX urb failed:%d\n", urb->status); | ||
8644 | + spin_lock_irqsave(&dev->tx_lock, flags); | ||
8645 | if (WARN_ONCE(q->e[q->start].urb != urb, "TX urb mismatch")) | ||
8646 | goto out; | ||
8647 | |||
8648 | skb = q->e[q->start].skb; | ||
8649 | + q->e[q->start].skb = NULL; | ||
8650 | trace_mt_tx_dma_done(dev, skb); | ||
8651 | |||
8652 | __skb_queue_tail(&dev->tx_skb_done, skb); | ||
8653 | @@ -363,19 +387,9 @@ int mt7601u_dma_enqueue_tx(struct mt7601u_dev *dev, struct sk_buff *skb, | ||
8654 | static void mt7601u_kill_rx(struct mt7601u_dev *dev) | ||
8655 | { | ||
8656 | int i; | ||
8657 | - unsigned long flags; | ||
8658 | - | ||
8659 | - spin_lock_irqsave(&dev->rx_lock, flags); | ||
8660 | - | ||
8661 | - for (i = 0; i < dev->rx_q.entries; i++) { | ||
8662 | - int next = dev->rx_q.end; | ||
8663 | |||
8664 | - spin_unlock_irqrestore(&dev->rx_lock, flags); | ||
8665 | - usb_poison_urb(dev->rx_q.e[next].urb); | ||
8666 | - spin_lock_irqsave(&dev->rx_lock, flags); | ||
8667 | - } | ||
8668 | - | ||
8669 | - spin_unlock_irqrestore(&dev->rx_lock, flags); | ||
8670 | + for (i = 0; i < dev->rx_q.entries; i++) | ||
8671 | + usb_poison_urb(dev->rx_q.e[i].urb); | ||
8672 | } | ||
8673 | |||
8674 | static int mt7601u_submit_rx_buf(struct mt7601u_dev *dev, | ||
8675 | @@ -445,10 +459,10 @@ static void mt7601u_free_tx_queue(struct mt7601u_tx_queue *q) | ||
8676 | { | ||
8677 | int i; | ||
8678 | |||
8679 | - WARN_ON(q->used); | ||
8680 | - | ||
8681 | for (i = 0; i < q->entries; i++) { | ||
8682 | usb_poison_urb(q->e[i].urb); | ||
8683 | + if (q->e[i].skb) | ||
8684 | + mt7601u_tx_status(q->dev, q->e[i].skb); | ||
8685 | usb_free_urb(q->e[i].urb); | ||
8686 | } | ||
8687 | } | ||
8688 | diff --git a/drivers/net/wireless/mediatek/mt7601u/tx.c b/drivers/net/wireless/mediatek/mt7601u/tx.c | ||
8689 | index ad77bec1ba0f..2cb1883c0d33 100644 | ||
8690 | --- a/drivers/net/wireless/mediatek/mt7601u/tx.c | ||
8691 | +++ b/drivers/net/wireless/mediatek/mt7601u/tx.c | ||
8692 | @@ -117,9 +117,9 @@ void mt7601u_tx_status(struct mt7601u_dev *dev, struct sk_buff *skb) | ||
8693 | info->status.rates[0].idx = -1; | ||
8694 | info->flags |= IEEE80211_TX_STAT_ACK; | ||
8695 | |||
8696 | - spin_lock(&dev->mac_lock); | ||
8697 | + spin_lock_bh(&dev->mac_lock); | ||
8698 | ieee80211_tx_status(dev->hw, skb); | ||
8699 | - spin_unlock(&dev->mac_lock); | ||
8700 | + spin_unlock_bh(&dev->mac_lock); | ||
8701 | } | ||
8702 | |||
8703 | static int mt7601u_skb_rooms(struct mt7601u_dev *dev, struct sk_buff *skb) | ||
8704 | diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c | ||
8705 | index 45fa82cae87c..da504665b1c7 100644 | ||
8706 | --- a/drivers/nvdimm/dax_devs.c | ||
8707 | +++ b/drivers/nvdimm/dax_devs.c | ||
8708 | @@ -118,7 +118,7 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) | ||
8709 | nvdimm_bus_unlock(&ndns->dev); | ||
8710 | if (!dax_dev) | ||
8711 | return -ENOMEM; | ||
8712 | - pfn_sb = devm_kzalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); | ||
8713 | + pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); | ||
8714 | nd_pfn->pfn_sb = pfn_sb; | ||
8715 | rc = nd_pfn_validate(nd_pfn, DAX_SIG); | ||
8716 | dev_dbg(dev, "%s: dax: %s\n", __func__, | ||
8717 | diff --git a/drivers/nvdimm/pfn.h b/drivers/nvdimm/pfn.h | ||
8718 | index dde9853453d3..e901e3a3b04c 100644 | ||
8719 | --- a/drivers/nvdimm/pfn.h | ||
8720 | +++ b/drivers/nvdimm/pfn.h | ||
8721 | @@ -36,6 +36,7 @@ struct nd_pfn_sb { | ||
8722 | __le32 end_trunc; | ||
8723 | /* minor-version-2 record the base alignment of the mapping */ | ||
8724 | __le32 align; | ||
8725 | + /* minor-version-3 guarantee the padding and flags are zero */ | ||
8726 | u8 padding[4000]; | ||
8727 | __le64 checksum; | ||
8728 | }; | ||
8729 | diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c | ||
8730 | index ba9aa8475e6d..f40c9c626861 100644 | ||
8731 | --- a/drivers/nvdimm/pfn_devs.c | ||
8732 | +++ b/drivers/nvdimm/pfn_devs.c | ||
8733 | @@ -349,6 +349,15 @@ struct device *nd_pfn_create(struct nd_region *nd_region) | ||
8734 | return dev; | ||
8735 | } | ||
8736 | |||
8737 | +/** | ||
8738 | + * nd_pfn_validate - read and validate info-block | ||
8739 | + * @nd_pfn: fsdax namespace runtime state / properties | ||
8740 | + * @sig: 'devdax' or 'fsdax' signature | ||
8741 | + * | ||
8742 | + * Upon return the info-block buffer contents (->pfn_sb) are | ||
8743 | + * indeterminate when validation fails, and a coherent info-block | ||
8744 | + * otherwise. | ||
8745 | + */ | ||
8746 | int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) | ||
8747 | { | ||
8748 | u64 checksum, offset; | ||
8749 | @@ -486,7 +495,7 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns) | ||
8750 | nvdimm_bus_unlock(&ndns->dev); | ||
8751 | if (!pfn_dev) | ||
8752 | return -ENOMEM; | ||
8753 | - pfn_sb = devm_kzalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); | ||
8754 | + pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); | ||
8755 | nd_pfn = to_nd_pfn(pfn_dev); | ||
8756 | nd_pfn->pfn_sb = pfn_sb; | ||
8757 | rc = nd_pfn_validate(nd_pfn, PFN_SIG); | ||
8758 | @@ -584,7 +593,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn) | ||
8759 | u64 checksum; | ||
8760 | int rc; | ||
8761 | |||
8762 | - pfn_sb = devm_kzalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL); | ||
8763 | + pfn_sb = devm_kmalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL); | ||
8764 | if (!pfn_sb) | ||
8765 | return -ENOMEM; | ||
8766 | |||
8767 | @@ -593,11 +602,14 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn) | ||
8768 | sig = DAX_SIG; | ||
8769 | else | ||
8770 | sig = PFN_SIG; | ||
8771 | + | ||
8772 | rc = nd_pfn_validate(nd_pfn, sig); | ||
8773 | if (rc != -ENODEV) | ||
8774 | return rc; | ||
8775 | |||
8776 | /* no info block, do init */; | ||
8777 | + memset(pfn_sb, 0, sizeof(*pfn_sb)); | ||
8778 | + | ||
8779 | nd_region = to_nd_region(nd_pfn->dev.parent); | ||
8780 | if (nd_region->ro) { | ||
8781 | dev_info(&nd_pfn->dev, | ||
8782 | @@ -673,7 +685,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn) | ||
8783 | memcpy(pfn_sb->uuid, nd_pfn->uuid, 16); | ||
8784 | memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16); | ||
8785 | pfn_sb->version_major = cpu_to_le16(1); | ||
8786 | - pfn_sb->version_minor = cpu_to_le16(2); | ||
8787 | + pfn_sb->version_minor = cpu_to_le16(3); | ||
8788 | pfn_sb->start_pad = cpu_to_le32(start_pad); | ||
8789 | pfn_sb->end_trunc = cpu_to_le32(end_trunc); | ||
8790 | pfn_sb->align = cpu_to_le32(nd_pfn->align); | ||
8791 | diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c | ||
8792 | index 200b41576526..a597619f25d6 100644 | ||
8793 | --- a/drivers/pci/host/pci-hyperv.c | ||
8794 | +++ b/drivers/pci/host/pci-hyperv.c | ||
8795 | @@ -1575,6 +1575,7 @@ static void hv_pci_devices_present(struct hv_pcibus_device *hbus, | ||
8796 | static void hv_eject_device_work(struct work_struct *work) | ||
8797 | { | ||
8798 | struct pci_eject_response *ejct_pkt; | ||
8799 | + struct hv_pcibus_device *hbus; | ||
8800 | struct hv_pci_dev *hpdev; | ||
8801 | struct pci_dev *pdev; | ||
8802 | unsigned long flags; | ||
8803 | @@ -1585,6 +1586,7 @@ static void hv_eject_device_work(struct work_struct *work) | ||
8804 | } ctxt; | ||
8805 | |||
8806 | hpdev = container_of(work, struct hv_pci_dev, wrk); | ||
8807 | + hbus = hpdev->hbus; | ||
8808 | |||
8809 | if (hpdev->state != hv_pcichild_ejecting) { | ||
8810 | put_pcichild(hpdev, hv_pcidev_ref_pnp); | ||
8811 | @@ -1598,8 +1600,7 @@ static void hv_eject_device_work(struct work_struct *work) | ||
8812 | * because hbus->pci_bus may not exist yet. | ||
8813 | */ | ||
8814 | wslot = wslot_to_devfn(hpdev->desc.win_slot.slot); | ||
8815 | - pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, | ||
8816 | - wslot); | ||
8817 | + pdev = pci_get_domain_bus_and_slot(hbus->sysdata.domain, 0, wslot); | ||
8818 | if (pdev) { | ||
8819 | pci_lock_rescan_remove(); | ||
8820 | pci_stop_and_remove_bus_device(pdev); | ||
8821 | @@ -1607,22 +1608,24 @@ static void hv_eject_device_work(struct work_struct *work) | ||
8822 | pci_unlock_rescan_remove(); | ||
8823 | } | ||
8824 | |||
8825 | + spin_lock_irqsave(&hbus->device_list_lock, flags); | ||
8826 | + list_del(&hpdev->list_entry); | ||
8827 | + spin_unlock_irqrestore(&hbus->device_list_lock, flags); | ||
8828 | + | ||
8829 | memset(&ctxt, 0, sizeof(ctxt)); | ||
8830 | ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message; | ||
8831 | ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE; | ||
8832 | ejct_pkt->wslot.slot = hpdev->desc.win_slot.slot; | ||
8833 | - vmbus_sendpacket(hpdev->hbus->hdev->channel, ejct_pkt, | ||
8834 | + vmbus_sendpacket(hbus->hdev->channel, ejct_pkt, | ||
8835 | sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt, | ||
8836 | VM_PKT_DATA_INBAND, 0); | ||
8837 | |||
8838 | - spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); | ||
8839 | - list_del(&hpdev->list_entry); | ||
8840 | - spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); | ||
8841 | - | ||
8842 | put_pcichild(hpdev, hv_pcidev_ref_childlist); | ||
8843 | put_pcichild(hpdev, hv_pcidev_ref_initial); | ||
8844 | put_pcichild(hpdev, hv_pcidev_ref_pnp); | ||
8845 | - put_hvpcibus(hpdev->hbus); | ||
8846 | + | ||
8847 | + /* hpdev has been freed. Do not use it any more. */ | ||
8848 | + put_hvpcibus(hbus); | ||
8849 | } | ||
8850 | |||
8851 | /** | ||
8852 | diff --git a/drivers/pci/host/pcie-xilinx-nwl.c b/drivers/pci/host/pcie-xilinx-nwl.c | ||
8853 | index 94fdd295aae2..3bba87af0b6b 100644 | ||
8854 | --- a/drivers/pci/host/pcie-xilinx-nwl.c | ||
8855 | +++ b/drivers/pci/host/pcie-xilinx-nwl.c | ||
8856 | @@ -456,15 +456,13 @@ static int nwl_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, | ||
8857 | int i; | ||
8858 | |||
8859 | mutex_lock(&msi->lock); | ||
8860 | - bit = bitmap_find_next_zero_area(msi->bitmap, INT_PCI_MSI_NR, 0, | ||
8861 | - nr_irqs, 0); | ||
8862 | - if (bit >= INT_PCI_MSI_NR) { | ||
8863 | + bit = bitmap_find_free_region(msi->bitmap, INT_PCI_MSI_NR, | ||
8864 | + get_count_order(nr_irqs)); | ||
8865 | + if (bit < 0) { | ||
8866 | mutex_unlock(&msi->lock); | ||
8867 | return -ENOSPC; | ||
8868 | } | ||
8869 | |||
8870 | - bitmap_set(msi->bitmap, bit, nr_irqs); | ||
8871 | - | ||
8872 | for (i = 0; i < nr_irqs; i++) { | ||
8873 | irq_domain_set_info(domain, virq + i, bit + i, &nwl_irq_chip, | ||
8874 | domain->host_data, handle_simple_irq, | ||
8875 | @@ -482,7 +480,8 @@ static void nwl_irq_domain_free(struct irq_domain *domain, unsigned int virq, | ||
8876 | struct nwl_msi *msi = &pcie->msi; | ||
8877 | |||
8878 | mutex_lock(&msi->lock); | ||
8879 | - bitmap_clear(msi->bitmap, data->hwirq, nr_irqs); | ||
8880 | + bitmap_release_region(msi->bitmap, data->hwirq, | ||
8881 | + get_count_order(nr_irqs)); | ||
8882 | mutex_unlock(&msi->lock); | ||
8883 | } | ||
8884 | |||
8885 | diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c | ||
8886 | index e5d8e2e2bd30..717540161223 100644 | ||
8887 | --- a/drivers/pci/pci-sysfs.c | ||
8888 | +++ b/drivers/pci/pci-sysfs.c | ||
8889 | @@ -371,7 +371,7 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr, | ||
8890 | pci_stop_and_remove_bus_device_locked(to_pci_dev(dev)); | ||
8891 | return count; | ||
8892 | } | ||
8893 | -static struct device_attribute dev_remove_attr = __ATTR(remove, | ||
8894 | +static struct device_attribute dev_remove_attr = __ATTR_IGNORE_LOCKDEP(remove, | ||
8895 | (S_IWUSR|S_IWGRP), | ||
8896 | NULL, remove_store); | ||
8897 | |||
8898 | diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c | ||
8899 | index ccbbd4cde0f1..a07533702d26 100644 | ||
8900 | --- a/drivers/pci/pci.c | ||
8901 | +++ b/drivers/pci/pci.c | ||
8902 | @@ -1786,6 +1786,13 @@ static void pci_pme_list_scan(struct work_struct *work) | ||
8903 | */ | ||
8904 | if (bridge && bridge->current_state != PCI_D0) | ||
8905 | continue; | ||
8906 | + /* | ||
8907 | + * If the device is in D3cold it should not be | ||
8908 | + * polled either. | ||
8909 | + */ | ||
8910 | + if (pme_dev->dev->current_state == PCI_D3cold) | ||
8911 | + continue; | ||
8912 | + | ||
8913 | pci_pme_wakeup(pme_dev->dev, NULL); | ||
8914 | } else { | ||
8915 | list_del(&pme_dev->list); | ||
8916 | diff --git a/drivers/phy/phy-rcar-gen2.c b/drivers/phy/phy-rcar-gen2.c | ||
8917 | index 97d4dd6ea924..aa02b19b7e0e 100644 | ||
8918 | --- a/drivers/phy/phy-rcar-gen2.c | ||
8919 | +++ b/drivers/phy/phy-rcar-gen2.c | ||
8920 | @@ -288,6 +288,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) | ||
8921 | error = of_property_read_u32(np, "reg", &channel_num); | ||
8922 | if (error || channel_num > 2) { | ||
8923 | dev_err(dev, "Invalid \"reg\" property\n"); | ||
8924 | + of_node_put(np); | ||
8925 | return error; | ||
8926 | } | ||
8927 | channel->select_mask = select_mask[channel_num]; | ||
8928 | @@ -303,6 +304,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) | ||
8929 | &rcar_gen2_phy_ops); | ||
8930 | if (IS_ERR(phy->phy)) { | ||
8931 | dev_err(dev, "Failed to create PHY\n"); | ||
8932 | + of_node_put(np); | ||
8933 | return PTR_ERR(phy->phy); | ||
8934 | } | ||
8935 | phy_set_drvdata(phy->phy, phy); | ||
8936 | diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c | ||
8937 | index f826793e972c..417cd3bd7e0c 100644 | ||
8938 | --- a/drivers/pinctrl/pinctrl-rockchip.c | ||
8939 | +++ b/drivers/pinctrl/pinctrl-rockchip.c | ||
8940 | @@ -2208,6 +2208,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank, | ||
8941 | base, | ||
8942 | &rockchip_regmap_config); | ||
8943 | } | ||
8944 | + of_node_put(node); | ||
8945 | } | ||
8946 | |||
8947 | bank->irq = irq_of_parse_and_map(bank->of_node, 0); | ||
8948 | diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c | ||
8949 | index 2f07cd615665..76ae38450aea 100644 | ||
8950 | --- a/drivers/pps/pps.c | ||
8951 | +++ b/drivers/pps/pps.c | ||
8952 | @@ -129,6 +129,14 @@ static long pps_cdev_ioctl(struct file *file, | ||
8953 | pps->params.mode |= PPS_CANWAIT; | ||
8954 | pps->params.api_version = PPS_API_VERS; | ||
8955 | |||
8956 | + /* | ||
8957 | + * Clear unused fields of pps_kparams to avoid leaking | ||
8958 | + * uninitialized data of the PPS_SETPARAMS caller via | ||
8959 | + * PPS_GETPARAMS | ||
8960 | + */ | ||
8961 | + pps->params.assert_off_tu.flags = 0; | ||
8962 | + pps->params.clear_off_tu.flags = 0; | ||
8963 | + | ||
8964 | spin_unlock_irq(&pps->lock); | ||
8965 | |||
8966 | break; | ||
8967 | diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c | ||
8968 | index 1fe1c18cc27b..179f3c61a321 100644 | ||
8969 | --- a/drivers/regulator/s2mps11.c | ||
8970 | +++ b/drivers/regulator/s2mps11.c | ||
8971 | @@ -386,8 +386,8 @@ static const struct regulator_desc s2mps11_regulators[] = { | ||
8972 | regulator_desc_s2mps11_buck1_4(4), | ||
8973 | regulator_desc_s2mps11_buck5, | ||
8974 | regulator_desc_s2mps11_buck67810(6, MIN_600_MV, STEP_6_25_MV), | ||
8975 | - regulator_desc_s2mps11_buck67810(7, MIN_600_MV, STEP_12_5_MV), | ||
8976 | - regulator_desc_s2mps11_buck67810(8, MIN_600_MV, STEP_12_5_MV), | ||
8977 | + regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV), | ||
8978 | + regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV), | ||
8979 | regulator_desc_s2mps11_buck9, | ||
8980 | regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV), | ||
8981 | }; | ||
8982 | diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c | ||
8983 | index 18ab84e9c6b2..58cd0e0c9680 100644 | ||
8984 | --- a/drivers/s390/cio/qdio_main.c | ||
8985 | +++ b/drivers/s390/cio/qdio_main.c | ||
8986 | @@ -758,6 +758,7 @@ static int get_outbound_buffer_frontier(struct qdio_q *q) | ||
8987 | |||
8988 | switch (state) { | ||
8989 | case SLSB_P_OUTPUT_EMPTY: | ||
8990 | + case SLSB_P_OUTPUT_PENDING: | ||
8991 | /* the adapter got it */ | ||
8992 | DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, | ||
8993 | "out empty:%1d %02x", q->nr, count); | ||
8994 | diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c | ||
8995 | index 790babc5ef66..3cfab8868c98 100644 | ||
8996 | --- a/drivers/scsi/NCR5380.c | ||
8997 | +++ b/drivers/scsi/NCR5380.c | ||
8998 | @@ -813,6 +813,8 @@ static void NCR5380_main(struct work_struct *work) | ||
8999 | NCR5380_information_transfer(instance); | ||
9000 | done = 0; | ||
9001 | } | ||
9002 | + if (!hostdata->connected) | ||
9003 | + NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); | ||
9004 | spin_unlock_irq(&hostdata->lock); | ||
9005 | if (!done) | ||
9006 | cond_resched(); | ||
9007 | @@ -1086,7 +1088,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance, | ||
9008 | if (!hostdata->selecting) { | ||
9009 | /* Command was aborted */ | ||
9010 | NCR5380_write(MODE_REG, MR_BASE); | ||
9011 | - goto out; | ||
9012 | + return NULL; | ||
9013 | } | ||
9014 | if (err < 0) { | ||
9015 | NCR5380_write(MODE_REG, MR_BASE); | ||
9016 | @@ -1135,7 +1137,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance, | ||
9017 | if (!hostdata->selecting) { | ||
9018 | NCR5380_write(MODE_REG, MR_BASE); | ||
9019 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); | ||
9020 | - goto out; | ||
9021 | + return NULL; | ||
9022 | } | ||
9023 | |||
9024 | dsprintk(NDEBUG_ARBITRATION, instance, "won arbitration\n"); | ||
9025 | @@ -1208,8 +1210,6 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance, | ||
9026 | spin_lock_irq(&hostdata->lock); | ||
9027 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); | ||
9028 | NCR5380_reselect(instance); | ||
9029 | - if (!hostdata->connected) | ||
9030 | - NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); | ||
9031 | shost_printk(KERN_ERR, instance, "reselection after won arbitration?\n"); | ||
9032 | goto out; | ||
9033 | } | ||
9034 | @@ -1217,14 +1217,16 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance, | ||
9035 | if (err < 0) { | ||
9036 | spin_lock_irq(&hostdata->lock); | ||
9037 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); | ||
9038 | - NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); | ||
9039 | + | ||
9040 | /* Can't touch cmd if it has been reclaimed by the scsi ML */ | ||
9041 | - if (hostdata->selecting) { | ||
9042 | - cmd->result = DID_BAD_TARGET << 16; | ||
9043 | - complete_cmd(instance, cmd); | ||
9044 | - dsprintk(NDEBUG_SELECTION, instance, "target did not respond within 250ms\n"); | ||
9045 | - cmd = NULL; | ||
9046 | - } | ||
9047 | + if (!hostdata->selecting) | ||
9048 | + return NULL; | ||
9049 | + | ||
9050 | + cmd->result = DID_BAD_TARGET << 16; | ||
9051 | + complete_cmd(instance, cmd); | ||
9052 | + dsprintk(NDEBUG_SELECTION, instance, | ||
9053 | + "target did not respond within 250ms\n"); | ||
9054 | + cmd = NULL; | ||
9055 | goto out; | ||
9056 | } | ||
9057 | |||
9058 | @@ -1252,12 +1254,11 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance, | ||
9059 | if (err < 0) { | ||
9060 | shost_printk(KERN_ERR, instance, "select: REQ timeout\n"); | ||
9061 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); | ||
9062 | - NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); | ||
9063 | goto out; | ||
9064 | } | ||
9065 | if (!hostdata->selecting) { | ||
9066 | do_abort(instance); | ||
9067 | - goto out; | ||
9068 | + return NULL; | ||
9069 | } | ||
9070 | |||
9071 | dsprintk(NDEBUG_SELECTION, instance, "target %d selected, going into MESSAGE OUT phase.\n", | ||
9072 | @@ -1903,9 +1904,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) | ||
9073 | */ | ||
9074 | NCR5380_write(TARGET_COMMAND_REG, 0); | ||
9075 | |||
9076 | - /* Enable reselect interrupts */ | ||
9077 | - NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); | ||
9078 | - | ||
9079 | maybe_release_dma_irq(instance); | ||
9080 | return; | ||
9081 | case MESSAGE_REJECT: | ||
9082 | @@ -1937,8 +1935,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) | ||
9083 | */ | ||
9084 | NCR5380_write(TARGET_COMMAND_REG, 0); | ||
9085 | |||
9086 | - /* Enable reselect interrupts */ | ||
9087 | - NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); | ||
9088 | #ifdef SUN3_SCSI_VME | ||
9089 | dregs->csr |= CSR_DMA_ENABLE; | ||
9090 | #endif | ||
9091 | @@ -2046,7 +2042,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) | ||
9092 | cmd->result = DID_ERROR << 16; | ||
9093 | complete_cmd(instance, cmd); | ||
9094 | maybe_release_dma_irq(instance); | ||
9095 | - NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); | ||
9096 | return; | ||
9097 | } | ||
9098 | msgout = NOP; | ||
9099 | diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c | ||
9100 | index a590089b9397..5648d30c7376 100644 | ||
9101 | --- a/drivers/scsi/mac_scsi.c | ||
9102 | +++ b/drivers/scsi/mac_scsi.c | ||
9103 | @@ -54,7 +54,7 @@ static int setup_cmd_per_lun = -1; | ||
9104 | module_param(setup_cmd_per_lun, int, 0); | ||
9105 | static int setup_sg_tablesize = -1; | ||
9106 | module_param(setup_sg_tablesize, int, 0); | ||
9107 | -static int setup_use_pdma = -1; | ||
9108 | +static int setup_use_pdma = 512; | ||
9109 | module_param(setup_use_pdma, int, 0); | ||
9110 | static int setup_hostid = -1; | ||
9111 | module_param(setup_hostid, int, 0); | ||
9112 | @@ -325,7 +325,7 @@ static int macscsi_dma_xfer_len(struct Scsi_Host *instance, | ||
9113 | struct NCR5380_hostdata *hostdata = shost_priv(instance); | ||
9114 | |||
9115 | if (hostdata->flags & FLAG_NO_PSEUDO_DMA || | ||
9116 | - cmd->SCp.this_residual < 16) | ||
9117 | + cmd->SCp.this_residual < setup_use_pdma) | ||
9118 | return 0; | ||
9119 | |||
9120 | return cmd->SCp.this_residual; | ||
9121 | diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c | ||
9122 | index 89dd6b989254..e0440807b4ed 100644 | ||
9123 | --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c | ||
9124 | +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c | ||
9125 | @@ -423,6 +423,9 @@ static int vpfe_open(struct file *file) | ||
9126 | /* If decoder is not initialized. initialize it */ | ||
9127 | if (!video->initialized && vpfe_update_pipe_state(video)) { | ||
9128 | mutex_unlock(&video->lock); | ||
9129 | + v4l2_fh_del(&handle->vfh); | ||
9130 | + v4l2_fh_exit(&handle->vfh); | ||
9131 | + kfree(handle); | ||
9132 | return -ENODEV; | ||
9133 | } | ||
9134 | /* Increment device users counter */ | ||
9135 | diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c | ||
9136 | index 84474f06dbcf..8f1233324586 100644 | ||
9137 | --- a/drivers/tty/serial/8250/8250_port.c | ||
9138 | +++ b/drivers/tty/serial/8250/8250_port.c | ||
9139 | @@ -1819,7 +1819,8 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir) | ||
9140 | status = serial8250_rx_chars(up, status); | ||
9141 | } | ||
9142 | serial8250_modem_status(up); | ||
9143 | - if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE)) | ||
9144 | + if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE) && | ||
9145 | + (up->ier & UART_IER_THRI)) | ||
9146 | serial8250_tx_chars(up); | ||
9147 | |||
9148 | spin_unlock_irqrestore(&port->lock, flags); | ||
9149 | diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c | ||
9150 | index 0040c29f651a..b9e137c03fe3 100644 | ||
9151 | --- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c | ||
9152 | +++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c | ||
9153 | @@ -421,7 +421,16 @@ static int cpm_uart_startup(struct uart_port *port) | ||
9154 | clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX); | ||
9155 | } | ||
9156 | cpm_uart_initbd(pinfo); | ||
9157 | - cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); | ||
9158 | + if (IS_SMC(pinfo)) { | ||
9159 | + out_be32(&pinfo->smcup->smc_rstate, 0); | ||
9160 | + out_be32(&pinfo->smcup->smc_tstate, 0); | ||
9161 | + out_be16(&pinfo->smcup->smc_rbptr, | ||
9162 | + in_be16(&pinfo->smcup->smc_rbase)); | ||
9163 | + out_be16(&pinfo->smcup->smc_tbptr, | ||
9164 | + in_be16(&pinfo->smcup->smc_tbase)); | ||
9165 | + } else { | ||
9166 | + cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); | ||
9167 | + } | ||
9168 | } | ||
9169 | /* Install interrupt handler. */ | ||
9170 | retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port); | ||
9171 | @@ -875,16 +884,14 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo) | ||
9172 | (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE); | ||
9173 | |||
9174 | /* | ||
9175 | - * In case SMC1 is being relocated... | ||
9176 | + * In case SMC is being relocated... | ||
9177 | */ | ||
9178 | -#if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH) | ||
9179 | out_be16(&up->smc_rbptr, in_be16(&pinfo->smcup->smc_rbase)); | ||
9180 | out_be16(&up->smc_tbptr, in_be16(&pinfo->smcup->smc_tbase)); | ||
9181 | out_be32(&up->smc_rstate, 0); | ||
9182 | out_be32(&up->smc_tstate, 0); | ||
9183 | out_be16(&up->smc_brkcr, 1); /* number of break chars */ | ||
9184 | out_be16(&up->smc_brkec, 0); | ||
9185 | -#endif | ||
9186 | |||
9187 | /* Set up the uart parameters in the | ||
9188 | * parameter ram. | ||
9189 | @@ -898,8 +905,6 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo) | ||
9190 | out_be16(&up->smc_brkec, 0); | ||
9191 | out_be16(&up->smc_brkcr, 1); | ||
9192 | |||
9193 | - cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); | ||
9194 | - | ||
9195 | /* Set UART mode, 8 bit, no parity, one stop. | ||
9196 | * Enable receive and transmit. | ||
9197 | */ | ||
9198 | diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digicolor-usart.c | ||
9199 | index 02ad6953b167..50ec5f1ac77f 100644 | ||
9200 | --- a/drivers/tty/serial/digicolor-usart.c | ||
9201 | +++ b/drivers/tty/serial/digicolor-usart.c | ||
9202 | @@ -545,7 +545,11 @@ static int __init digicolor_uart_init(void) | ||
9203 | if (ret) | ||
9204 | return ret; | ||
9205 | |||
9206 | - return platform_driver_register(&digicolor_uart_platform); | ||
9207 | + ret = platform_driver_register(&digicolor_uart_platform); | ||
9208 | + if (ret) | ||
9209 | + uart_unregister_driver(&digicolor_uart); | ||
9210 | + | ||
9211 | + return ret; | ||
9212 | } | ||
9213 | module_init(digicolor_uart_init); | ||
9214 | |||
9215 | diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c | ||
9216 | index ec3db8d8306c..bacc7e284c0c 100644 | ||
9217 | --- a/drivers/tty/serial/max310x.c | ||
9218 | +++ b/drivers/tty/serial/max310x.c | ||
9219 | @@ -494,37 +494,48 @@ static bool max310x_reg_precious(struct device *dev, unsigned int reg) | ||
9220 | |||
9221 | static int max310x_set_baud(struct uart_port *port, int baud) | ||
9222 | { | ||
9223 | - unsigned int mode = 0, clk = port->uartclk, div = clk / baud; | ||
9224 | + unsigned int mode = 0, div = 0, frac = 0, c = 0, F = 0; | ||
9225 | |||
9226 | - /* Check for minimal value for divider */ | ||
9227 | - if (div < 16) | ||
9228 | - div = 16; | ||
9229 | - | ||
9230 | - if (clk % baud && (div / 16) < 0x8000) { | ||
9231 | + /* | ||
9232 | + * Calculate the integer divisor first. Select a proper mode | ||
9233 | + * in case if the requested baud is too high for the pre-defined | ||
9234 | + * clocks frequency. | ||
9235 | + */ | ||
9236 | + div = port->uartclk / baud; | ||
9237 | + if (div < 8) { | ||
9238 | + /* Mode x4 */ | ||
9239 | + c = 4; | ||
9240 | + mode = MAX310X_BRGCFG_4XMODE_BIT; | ||
9241 | + } else if (div < 16) { | ||
9242 | /* Mode x2 */ | ||
9243 | + c = 8; | ||
9244 | mode = MAX310X_BRGCFG_2XMODE_BIT; | ||
9245 | - clk = port->uartclk * 2; | ||
9246 | - div = clk / baud; | ||
9247 | - | ||
9248 | - if (clk % baud && (div / 16) < 0x8000) { | ||
9249 | - /* Mode x4 */ | ||
9250 | - mode = MAX310X_BRGCFG_4XMODE_BIT; | ||
9251 | - clk = port->uartclk * 4; | ||
9252 | - div = clk / baud; | ||
9253 | - } | ||
9254 | + } else { | ||
9255 | + c = 16; | ||
9256 | } | ||
9257 | |||
9258 | - max310x_port_write(port, MAX310X_BRGDIVMSB_REG, (div / 16) >> 8); | ||
9259 | - max310x_port_write(port, MAX310X_BRGDIVLSB_REG, div / 16); | ||
9260 | - max310x_port_write(port, MAX310X_BRGCFG_REG, (div % 16) | mode); | ||
9261 | + /* Calculate the divisor in accordance with the fraction coefficient */ | ||
9262 | + div /= c; | ||
9263 | + F = c*baud; | ||
9264 | + | ||
9265 | + /* Calculate the baud rate fraction */ | ||
9266 | + if (div > 0) | ||
9267 | + frac = (16*(port->uartclk % F)) / F; | ||
9268 | + else | ||
9269 | + div = 1; | ||
9270 | + | ||
9271 | + max310x_port_write(port, MAX310X_BRGDIVMSB_REG, div >> 8); | ||
9272 | + max310x_port_write(port, MAX310X_BRGDIVLSB_REG, div); | ||
9273 | + max310x_port_write(port, MAX310X_BRGCFG_REG, frac | mode); | ||
9274 | |||
9275 | - return DIV_ROUND_CLOSEST(clk, div); | ||
9276 | + /* Return the actual baud rate we just programmed */ | ||
9277 | + return (16*port->uartclk) / (c*(16*div + frac)); | ||
9278 | } | ||
9279 | |||
9280 | static int max310x_update_best_err(unsigned long f, long *besterr) | ||
9281 | { | ||
9282 | /* Use baudrate 115200 for calculate error */ | ||
9283 | - long err = f % (115200 * 16); | ||
9284 | + long err = f % (460800 * 16); | ||
9285 | |||
9286 | if ((*besterr < 0) || (*besterr > err)) { | ||
9287 | *besterr = err; | ||
9288 | diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c | ||
9289 | index 7dc8272c6b15..9027455c6be1 100644 | ||
9290 | --- a/drivers/tty/serial/msm_serial.c | ||
9291 | +++ b/drivers/tty/serial/msm_serial.c | ||
9292 | @@ -391,10 +391,14 @@ no_rx: | ||
9293 | |||
9294 | static inline void msm_wait_for_xmitr(struct uart_port *port) | ||
9295 | { | ||
9296 | + unsigned int timeout = 500000; | ||
9297 | + | ||
9298 | while (!(msm_read(port, UART_SR) & UART_SR_TX_EMPTY)) { | ||
9299 | if (msm_read(port, UART_ISR) & UART_ISR_TX_READY) | ||
9300 | break; | ||
9301 | udelay(1); | ||
9302 | + if (!timeout--) | ||
9303 | + break; | ||
9304 | } | ||
9305 | msm_write(port, UART_CR_CMD_RESET_TX_READY, UART_CR); | ||
9306 | } | ||
9307 | diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c | ||
9308 | index 680fb3f9be2d..04c023f7f633 100644 | ||
9309 | --- a/drivers/tty/serial/serial_core.c | ||
9310 | +++ b/drivers/tty/serial/serial_core.c | ||
9311 | @@ -1725,6 +1725,7 @@ static int uart_port_activate(struct tty_port *port, struct tty_struct *tty) | ||
9312 | { | ||
9313 | struct uart_state *state = container_of(port, struct uart_state, port); | ||
9314 | struct uart_port *uport; | ||
9315 | + int ret; | ||
9316 | |||
9317 | uport = uart_port_check(state); | ||
9318 | if (!uport || uport->flags & UPF_DEAD) | ||
9319 | @@ -1735,7 +1736,11 @@ static int uart_port_activate(struct tty_port *port, struct tty_struct *tty) | ||
9320 | /* | ||
9321 | * Start up the serial port. | ||
9322 | */ | ||
9323 | - return uart_startup(tty, state, 0); | ||
9324 | + ret = uart_startup(tty, state, 0); | ||
9325 | + if (ret > 0) | ||
9326 | + tty_port_set_active(port, 1); | ||
9327 | + | ||
9328 | + return ret; | ||
9329 | } | ||
9330 | |||
9331 | static const char *uart_type(struct uart_port *port) | ||
9332 | diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c | ||
9333 | index bcb997935c5e..ea35f5144237 100644 | ||
9334 | --- a/drivers/tty/serial/sh-sci.c | ||
9335 | +++ b/drivers/tty/serial/sh-sci.c | ||
9336 | @@ -1291,6 +1291,7 @@ static void work_fn_tx(struct work_struct *work) | ||
9337 | struct uart_port *port = &s->port; | ||
9338 | struct circ_buf *xmit = &port->state->xmit; | ||
9339 | dma_addr_t buf; | ||
9340 | + int head, tail; | ||
9341 | |||
9342 | /* | ||
9343 | * DMA is idle now. | ||
9344 | @@ -1300,16 +1301,23 @@ static void work_fn_tx(struct work_struct *work) | ||
9345 | * consistent xmit buffer state. | ||
9346 | */ | ||
9347 | spin_lock_irq(&port->lock); | ||
9348 | - buf = s->tx_dma_addr + (xmit->tail & (UART_XMIT_SIZE - 1)); | ||
9349 | + head = xmit->head; | ||
9350 | + tail = xmit->tail; | ||
9351 | + buf = s->tx_dma_addr + (tail & (UART_XMIT_SIZE - 1)); | ||
9352 | s->tx_dma_len = min_t(unsigned int, | ||
9353 | - CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE), | ||
9354 | - CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE)); | ||
9355 | - spin_unlock_irq(&port->lock); | ||
9356 | + CIRC_CNT(head, tail, UART_XMIT_SIZE), | ||
9357 | + CIRC_CNT_TO_END(head, tail, UART_XMIT_SIZE)); | ||
9358 | + if (!s->tx_dma_len) { | ||
9359 | + /* Transmit buffer has been flushed */ | ||
9360 | + spin_unlock_irq(&port->lock); | ||
9361 | + return; | ||
9362 | + } | ||
9363 | |||
9364 | desc = dmaengine_prep_slave_single(chan, buf, s->tx_dma_len, | ||
9365 | DMA_MEM_TO_DEV, | ||
9366 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | ||
9367 | if (!desc) { | ||
9368 | + spin_unlock_irq(&port->lock); | ||
9369 | dev_warn(port->dev, "Failed preparing Tx DMA descriptor\n"); | ||
9370 | /* switch to PIO */ | ||
9371 | sci_tx_dma_release(s, true); | ||
9372 | @@ -1319,20 +1327,20 @@ static void work_fn_tx(struct work_struct *work) | ||
9373 | dma_sync_single_for_device(chan->device->dev, buf, s->tx_dma_len, | ||
9374 | DMA_TO_DEVICE); | ||
9375 | |||
9376 | - spin_lock_irq(&port->lock); | ||
9377 | desc->callback = sci_dma_tx_complete; | ||
9378 | desc->callback_param = s; | ||
9379 | - spin_unlock_irq(&port->lock); | ||
9380 | s->cookie_tx = dmaengine_submit(desc); | ||
9381 | if (dma_submit_error(s->cookie_tx)) { | ||
9382 | + spin_unlock_irq(&port->lock); | ||
9383 | dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n"); | ||
9384 | /* switch to PIO */ | ||
9385 | sci_tx_dma_release(s, true); | ||
9386 | return; | ||
9387 | } | ||
9388 | |||
9389 | + spin_unlock_irq(&port->lock); | ||
9390 | dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n", | ||
9391 | - __func__, xmit->buf, xmit->tail, xmit->head, s->cookie_tx); | ||
9392 | + __func__, xmit->buf, tail, head, s->cookie_tx); | ||
9393 | |||
9394 | dma_async_issue_pending(chan); | ||
9395 | } | ||
9396 | @@ -1538,11 +1546,18 @@ static void sci_free_dma(struct uart_port *port) | ||
9397 | |||
9398 | static void sci_flush_buffer(struct uart_port *port) | ||
9399 | { | ||
9400 | + struct sci_port *s = to_sci_port(port); | ||
9401 | + | ||
9402 | /* | ||
9403 | * In uart_flush_buffer(), the xmit circular buffer has just been | ||
9404 | - * cleared, so we have to reset tx_dma_len accordingly. | ||
9405 | + * cleared, so we have to reset tx_dma_len accordingly, and stop any | ||
9406 | + * pending transfers | ||
9407 | */ | ||
9408 | - to_sci_port(port)->tx_dma_len = 0; | ||
9409 | + s->tx_dma_len = 0; | ||
9410 | + if (s->chan_tx) { | ||
9411 | + dmaengine_terminate_async(s->chan_tx); | ||
9412 | + s->cookie_tx = -EINVAL; | ||
9413 | + } | ||
9414 | } | ||
9415 | #else /* !CONFIG_SERIAL_SH_SCI_DMA */ | ||
9416 | static inline void sci_request_dma(struct uart_port *port) | ||
9417 | diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c | ||
9418 | index 3941df076cca..63646dc3ca27 100644 | ||
9419 | --- a/drivers/usb/core/hub.c | ||
9420 | +++ b/drivers/usb/core/hub.c | ||
9421 | @@ -3535,6 +3535,7 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | ||
9422 | struct usb_device *hdev; | ||
9423 | struct usb_device *udev; | ||
9424 | int connect_change = 0; | ||
9425 | + u16 link_state; | ||
9426 | int ret; | ||
9427 | |||
9428 | hdev = hub->hdev; | ||
9429 | @@ -3544,9 +3545,11 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | ||
9430 | return 0; | ||
9431 | usb_clear_port_feature(hdev, port, USB_PORT_FEAT_C_SUSPEND); | ||
9432 | } else { | ||
9433 | + link_state = portstatus & USB_PORT_STAT_LINK_STATE; | ||
9434 | if (!udev || udev->state != USB_STATE_SUSPENDED || | ||
9435 | - (portstatus & USB_PORT_STAT_LINK_STATE) != | ||
9436 | - USB_SS_PORT_LS_U0) | ||
9437 | + (link_state != USB_SS_PORT_LS_U0 && | ||
9438 | + link_state != USB_SS_PORT_LS_U1 && | ||
9439 | + link_state != USB_SS_PORT_LS_U2)) | ||
9440 | return 0; | ||
9441 | } | ||
9442 | |||
9443 | @@ -3876,6 +3879,9 @@ static int usb_set_lpm_timeout(struct usb_device *udev, | ||
9444 | * control transfers to set the hub timeout or enable device-initiated U1/U2 | ||
9445 | * will be successful. | ||
9446 | * | ||
9447 | + * If the control transfer to enable device-initiated U1/U2 entry fails, then | ||
9448 | + * hub-initiated U1/U2 will be disabled. | ||
9449 | + * | ||
9450 | * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI | ||
9451 | * driver know about it. If that call fails, it should be harmless, and just | ||
9452 | * take up more slightly more bus bandwidth for unnecessary U1/U2 exit latency. | ||
9453 | @@ -3930,23 +3936,24 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, | ||
9454 | * host know that this link state won't be enabled. | ||
9455 | */ | ||
9456 | hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); | ||
9457 | - } else { | ||
9458 | - /* Only a configured device will accept the Set Feature | ||
9459 | - * U1/U2_ENABLE | ||
9460 | - */ | ||
9461 | - if (udev->actconfig) | ||
9462 | - usb_set_device_initiated_lpm(udev, state, true); | ||
9463 | + return; | ||
9464 | + } | ||
9465 | |||
9466 | - /* As soon as usb_set_lpm_timeout(timeout) returns 0, the | ||
9467 | - * hub-initiated LPM is enabled. Thus, LPM is enabled no | ||
9468 | - * matter the result of usb_set_device_initiated_lpm(). | ||
9469 | - * The only difference is whether device is able to initiate | ||
9470 | - * LPM. | ||
9471 | - */ | ||
9472 | + /* Only a configured device will accept the Set Feature | ||
9473 | + * U1/U2_ENABLE | ||
9474 | + */ | ||
9475 | + if (udev->actconfig && | ||
9476 | + usb_set_device_initiated_lpm(udev, state, true) == 0) { | ||
9477 | if (state == USB3_LPM_U1) | ||
9478 | udev->usb3_lpm_u1_enabled = 1; | ||
9479 | else if (state == USB3_LPM_U2) | ||
9480 | udev->usb3_lpm_u2_enabled = 1; | ||
9481 | + } else { | ||
9482 | + /* Don't request U1/U2 entry if the device | ||
9483 | + * cannot transition to U1/U2. | ||
9484 | + */ | ||
9485 | + usb_set_lpm_timeout(udev, state, 0); | ||
9486 | + hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); | ||
9487 | } | ||
9488 | } | ||
9489 | |||
9490 | diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c | ||
9491 | index 927ac0ee09b7..d1278d2d544b 100644 | ||
9492 | --- a/drivers/usb/gadget/function/f_fs.c | ||
9493 | +++ b/drivers/usb/gadget/function/f_fs.c | ||
9494 | @@ -1101,11 +1101,12 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from) | ||
9495 | ENTER(); | ||
9496 | |||
9497 | if (!is_sync_kiocb(kiocb)) { | ||
9498 | - p = kmalloc(sizeof(io_data), GFP_KERNEL); | ||
9499 | + p = kzalloc(sizeof(io_data), GFP_KERNEL); | ||
9500 | if (unlikely(!p)) | ||
9501 | return -ENOMEM; | ||
9502 | p->aio = true; | ||
9503 | } else { | ||
9504 | + memset(p, 0, sizeof(*p)); | ||
9505 | p->aio = false; | ||
9506 | } | ||
9507 | |||
9508 | @@ -1137,11 +1138,12 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to) | ||
9509 | ENTER(); | ||
9510 | |||
9511 | if (!is_sync_kiocb(kiocb)) { | ||
9512 | - p = kmalloc(sizeof(io_data), GFP_KERNEL); | ||
9513 | + p = kzalloc(sizeof(io_data), GFP_KERNEL); | ||
9514 | if (unlikely(!p)) | ||
9515 | return -ENOMEM; | ||
9516 | p->aio = true; | ||
9517 | } else { | ||
9518 | + memset(p, 0, sizeof(*p)); | ||
9519 | p->aio = false; | ||
9520 | } | ||
9521 | |||
9522 | diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c | ||
9523 | index 97750f162f01..c14e4a64b0e8 100644 | ||
9524 | --- a/drivers/usb/host/hwa-hc.c | ||
9525 | +++ b/drivers/usb/host/hwa-hc.c | ||
9526 | @@ -173,7 +173,7 @@ out: | ||
9527 | return result; | ||
9528 | |||
9529 | error_set_cluster_id: | ||
9530 | - wusb_cluster_id_put(wusbhc->cluster_id); | ||
9531 | + wusb_cluster_id_put(addr); | ||
9532 | error_cluster_id_get: | ||
9533 | goto out; | ||
9534 | |||
9535 | diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c | ||
9536 | index ee213c5f4107..11b0767ca1ba 100644 | ||
9537 | --- a/drivers/usb/host/pci-quirks.c | ||
9538 | +++ b/drivers/usb/host/pci-quirks.c | ||
9539 | @@ -187,7 +187,7 @@ int usb_amd_find_chipset_info(void) | ||
9540 | { | ||
9541 | unsigned long flags; | ||
9542 | struct amd_chipset_info info; | ||
9543 | - int ret; | ||
9544 | + int need_pll_quirk = 0; | ||
9545 | |||
9546 | spin_lock_irqsave(&amd_lock, flags); | ||
9547 | |||
9548 | @@ -201,21 +201,28 @@ int usb_amd_find_chipset_info(void) | ||
9549 | spin_unlock_irqrestore(&amd_lock, flags); | ||
9550 | |||
9551 | if (!amd_chipset_sb_type_init(&info)) { | ||
9552 | - ret = 0; | ||
9553 | goto commit; | ||
9554 | } | ||
9555 | |||
9556 | - /* Below chipset generations needn't enable AMD PLL quirk */ | ||
9557 | - if (info.sb_type.gen == AMD_CHIPSET_UNKNOWN || | ||
9558 | - info.sb_type.gen == AMD_CHIPSET_SB600 || | ||
9559 | - info.sb_type.gen == AMD_CHIPSET_YANGTZE || | ||
9560 | - (info.sb_type.gen == AMD_CHIPSET_SB700 && | ||
9561 | - info.sb_type.rev > 0x3b)) { | ||
9562 | + switch (info.sb_type.gen) { | ||
9563 | + case AMD_CHIPSET_SB700: | ||
9564 | + need_pll_quirk = info.sb_type.rev <= 0x3B; | ||
9565 | + break; | ||
9566 | + case AMD_CHIPSET_SB800: | ||
9567 | + case AMD_CHIPSET_HUDSON2: | ||
9568 | + case AMD_CHIPSET_BOLTON: | ||
9569 | + need_pll_quirk = 1; | ||
9570 | + break; | ||
9571 | + default: | ||
9572 | + need_pll_quirk = 0; | ||
9573 | + break; | ||
9574 | + } | ||
9575 | + | ||
9576 | + if (!need_pll_quirk) { | ||
9577 | if (info.smbus_dev) { | ||
9578 | pci_dev_put(info.smbus_dev); | ||
9579 | info.smbus_dev = NULL; | ||
9580 | } | ||
9581 | - ret = 0; | ||
9582 | goto commit; | ||
9583 | } | ||
9584 | |||
9585 | @@ -234,7 +241,7 @@ int usb_amd_find_chipset_info(void) | ||
9586 | } | ||
9587 | } | ||
9588 | |||
9589 | - ret = info.probe_result = 1; | ||
9590 | + need_pll_quirk = info.probe_result = 1; | ||
9591 | printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n"); | ||
9592 | |||
9593 | commit: | ||
9594 | @@ -245,7 +252,7 @@ commit: | ||
9595 | |||
9596 | /* Mark that we where here */ | ||
9597 | amd_chipset.probe_count++; | ||
9598 | - ret = amd_chipset.probe_result; | ||
9599 | + need_pll_quirk = amd_chipset.probe_result; | ||
9600 | |||
9601 | spin_unlock_irqrestore(&amd_lock, flags); | ||
9602 | |||
9603 | @@ -259,7 +266,7 @@ commit: | ||
9604 | spin_unlock_irqrestore(&amd_lock, flags); | ||
9605 | } | ||
9606 | |||
9607 | - return ret; | ||
9608 | + return need_pll_quirk; | ||
9609 | } | ||
9610 | EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info); | ||
9611 | |||
9612 | diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c | ||
9613 | index 681d0eade82f..75e1089dfb01 100644 | ||
9614 | --- a/drivers/vhost/net.c | ||
9615 | +++ b/drivers/vhost/net.c | ||
9616 | @@ -30,7 +30,7 @@ | ||
9617 | |||
9618 | #include "vhost.h" | ||
9619 | |||
9620 | -static int experimental_zcopytx = 1; | ||
9621 | +static int experimental_zcopytx = 0; | ||
9622 | module_param(experimental_zcopytx, int, 0444); | ||
9623 | MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;" | ||
9624 | " 1 -Enable; 0 - Disable"); | ||
9625 | diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c | ||
9626 | index e4db19e88ab1..6af117af9780 100644 | ||
9627 | --- a/drivers/xen/balloon.c | ||
9628 | +++ b/drivers/xen/balloon.c | ||
9629 | @@ -591,8 +591,15 @@ static void balloon_process(struct work_struct *work) | ||
9630 | state = reserve_additional_memory(); | ||
9631 | } | ||
9632 | |||
9633 | - if (credit < 0) | ||
9634 | - state = decrease_reservation(-credit, GFP_BALLOON); | ||
9635 | + if (credit < 0) { | ||
9636 | + long n_pages; | ||
9637 | + | ||
9638 | + n_pages = min(-credit, si_mem_available()); | ||
9639 | + state = decrease_reservation(n_pages, GFP_BALLOON); | ||
9640 | + if (state == BP_DONE && n_pages != -credit && | ||
9641 | + n_pages < totalreserve_pages) | ||
9642 | + state = BP_EAGAIN; | ||
9643 | + } | ||
9644 | |||
9645 | state = update_schedule(state); | ||
9646 | |||
9647 | @@ -631,6 +638,9 @@ static int add_ballooned_pages(int nr_pages) | ||
9648 | } | ||
9649 | } | ||
9650 | |||
9651 | + if (si_mem_available() < nr_pages) | ||
9652 | + return -ENOMEM; | ||
9653 | + | ||
9654 | st = decrease_reservation(nr_pages, GFP_USER); | ||
9655 | if (st != BP_DONE) | ||
9656 | return -ENOMEM; | ||
9657 | @@ -754,7 +764,7 @@ static int __init balloon_init(void) | ||
9658 | balloon_stats.schedule_delay = 1; | ||
9659 | balloon_stats.max_schedule_delay = 32; | ||
9660 | balloon_stats.retry_count = 1; | ||
9661 | - balloon_stats.max_retry_count = RETRY_UNLIMITED; | ||
9662 | + balloon_stats.max_retry_count = 4; | ||
9663 | |||
9664 | #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG | ||
9665 | set_online_page_callback(&xen_online_page); | ||
9666 | diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c | ||
9667 | index 6181ad79e1a5..e45b1a0dd513 100644 | ||
9668 | --- a/fs/9p/vfs_addr.c | ||
9669 | +++ b/fs/9p/vfs_addr.c | ||
9670 | @@ -49,8 +49,9 @@ | ||
9671 | * @page: structure to page | ||
9672 | * | ||
9673 | */ | ||
9674 | -static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page) | ||
9675 | +static int v9fs_fid_readpage(void *data, struct page *page) | ||
9676 | { | ||
9677 | + struct p9_fid *fid = data; | ||
9678 | struct inode *inode = page->mapping->host; | ||
9679 | struct bio_vec bvec = {.bv_page = page, .bv_len = PAGE_SIZE}; | ||
9680 | struct iov_iter to; | ||
9681 | @@ -121,7 +122,8 @@ static int v9fs_vfs_readpages(struct file *filp, struct address_space *mapping, | ||
9682 | if (ret == 0) | ||
9683 | return ret; | ||
9684 | |||
9685 | - ret = read_cache_pages(mapping, pages, (void *)v9fs_vfs_readpage, filp); | ||
9686 | + ret = read_cache_pages(mapping, pages, v9fs_fid_readpage, | ||
9687 | + filp->private_data); | ||
9688 | p9_debug(P9_DEBUG_VFS, " = %d\n", ret); | ||
9689 | return ret; | ||
9690 | } | ||
9691 | diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c | ||
9692 | index c77114ce884b..6cdf27325576 100644 | ||
9693 | --- a/fs/btrfs/file.c | ||
9694 | +++ b/fs/btrfs/file.c | ||
9695 | @@ -2646,6 +2646,11 @@ out_only_mutex: | ||
9696 | * for detecting, at fsync time, if the inode isn't yet in the | ||
9697 | * log tree or it's there but not up to date. | ||
9698 | */ | ||
9699 | + struct timespec now = current_time(inode); | ||
9700 | + | ||
9701 | + inode_inc_iversion(inode); | ||
9702 | + inode->i_mtime = now; | ||
9703 | + inode->i_ctime = now; | ||
9704 | trans = btrfs_start_transaction(root, 1); | ||
9705 | if (IS_ERR(trans)) { | ||
9706 | err = PTR_ERR(trans); | ||
9707 | diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c | ||
9708 | index f916cd7b1918..82df349b84f7 100644 | ||
9709 | --- a/fs/ceph/caps.c | ||
9710 | +++ b/fs/ceph/caps.c | ||
9711 | @@ -1081,20 +1081,23 @@ static int send_cap_msg(struct ceph_mds_session *session, | ||
9712 | } | ||
9713 | |||
9714 | /* | ||
9715 | - * Queue cap releases when an inode is dropped from our cache. Since | ||
9716 | - * inode is about to be destroyed, there is no need for i_ceph_lock. | ||
9717 | + * Queue cap releases when an inode is dropped from our cache. | ||
9718 | */ | ||
9719 | void ceph_queue_caps_release(struct inode *inode) | ||
9720 | { | ||
9721 | struct ceph_inode_info *ci = ceph_inode(inode); | ||
9722 | struct rb_node *p; | ||
9723 | |||
9724 | + /* lock i_ceph_lock, because ceph_d_revalidate(..., LOOKUP_RCU) | ||
9725 | + * may call __ceph_caps_issued_mask() on a freeing inode. */ | ||
9726 | + spin_lock(&ci->i_ceph_lock); | ||
9727 | p = rb_first(&ci->i_caps); | ||
9728 | while (p) { | ||
9729 | struct ceph_cap *cap = rb_entry(p, struct ceph_cap, ci_node); | ||
9730 | p = rb_next(p); | ||
9731 | __ceph_remove_cap(cap, true); | ||
9732 | } | ||
9733 | + spin_unlock(&ci->i_ceph_lock); | ||
9734 | } | ||
9735 | |||
9736 | /* | ||
9737 | diff --git a/fs/coda/file.c b/fs/coda/file.c | ||
9738 | index 6e0154eb6fcc..649d17edc071 100644 | ||
9739 | --- a/fs/coda/file.c | ||
9740 | +++ b/fs/coda/file.c | ||
9741 | @@ -60,6 +60,41 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to) | ||
9742 | return ret; | ||
9743 | } | ||
9744 | |||
9745 | +struct coda_vm_ops { | ||
9746 | + atomic_t refcnt; | ||
9747 | + struct file *coda_file; | ||
9748 | + const struct vm_operations_struct *host_vm_ops; | ||
9749 | + struct vm_operations_struct vm_ops; | ||
9750 | +}; | ||
9751 | + | ||
9752 | +static void | ||
9753 | +coda_vm_open(struct vm_area_struct *vma) | ||
9754 | +{ | ||
9755 | + struct coda_vm_ops *cvm_ops = | ||
9756 | + container_of(vma->vm_ops, struct coda_vm_ops, vm_ops); | ||
9757 | + | ||
9758 | + atomic_inc(&cvm_ops->refcnt); | ||
9759 | + | ||
9760 | + if (cvm_ops->host_vm_ops && cvm_ops->host_vm_ops->open) | ||
9761 | + cvm_ops->host_vm_ops->open(vma); | ||
9762 | +} | ||
9763 | + | ||
9764 | +static void | ||
9765 | +coda_vm_close(struct vm_area_struct *vma) | ||
9766 | +{ | ||
9767 | + struct coda_vm_ops *cvm_ops = | ||
9768 | + container_of(vma->vm_ops, struct coda_vm_ops, vm_ops); | ||
9769 | + | ||
9770 | + if (cvm_ops->host_vm_ops && cvm_ops->host_vm_ops->close) | ||
9771 | + cvm_ops->host_vm_ops->close(vma); | ||
9772 | + | ||
9773 | + if (atomic_dec_and_test(&cvm_ops->refcnt)) { | ||
9774 | + vma->vm_ops = cvm_ops->host_vm_ops; | ||
9775 | + fput(cvm_ops->coda_file); | ||
9776 | + kfree(cvm_ops); | ||
9777 | + } | ||
9778 | +} | ||
9779 | + | ||
9780 | static int | ||
9781 | coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma) | ||
9782 | { | ||
9783 | @@ -67,6 +102,8 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma) | ||
9784 | struct coda_inode_info *cii; | ||
9785 | struct file *host_file; | ||
9786 | struct inode *coda_inode, *host_inode; | ||
9787 | + struct coda_vm_ops *cvm_ops; | ||
9788 | + int ret; | ||
9789 | |||
9790 | cfi = CODA_FTOC(coda_file); | ||
9791 | BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); | ||
9792 | @@ -75,6 +112,13 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma) | ||
9793 | if (!host_file->f_op->mmap) | ||
9794 | return -ENODEV; | ||
9795 | |||
9796 | + if (WARN_ON(coda_file != vma->vm_file)) | ||
9797 | + return -EIO; | ||
9798 | + | ||
9799 | + cvm_ops = kmalloc(sizeof(struct coda_vm_ops), GFP_KERNEL); | ||
9800 | + if (!cvm_ops) | ||
9801 | + return -ENOMEM; | ||
9802 | + | ||
9803 | coda_inode = file_inode(coda_file); | ||
9804 | host_inode = file_inode(host_file); | ||
9805 | |||
9806 | @@ -88,6 +132,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma) | ||
9807 | * the container file on us! */ | ||
9808 | else if (coda_inode->i_mapping != host_inode->i_mapping) { | ||
9809 | spin_unlock(&cii->c_lock); | ||
9810 | + kfree(cvm_ops); | ||
9811 | return -EBUSY; | ||
9812 | } | ||
9813 | |||
9814 | @@ -96,7 +141,29 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma) | ||
9815 | cfi->cfi_mapcount++; | ||
9816 | spin_unlock(&cii->c_lock); | ||
9817 | |||
9818 | - return host_file->f_op->mmap(host_file, vma); | ||
9819 | + vma->vm_file = get_file(host_file); | ||
9820 | + ret = host_file->f_op->mmap(host_file, vma); | ||
9821 | + | ||
9822 | + if (ret) { | ||
9823 | + /* if call_mmap fails, our caller will put coda_file so we | ||
9824 | + * should drop the reference to the host_file that we got. | ||
9825 | + */ | ||
9826 | + fput(host_file); | ||
9827 | + kfree(cvm_ops); | ||
9828 | + } else { | ||
9829 | + /* here we add redirects for the open/close vm_operations */ | ||
9830 | + cvm_ops->host_vm_ops = vma->vm_ops; | ||
9831 | + if (vma->vm_ops) | ||
9832 | + cvm_ops->vm_ops = *vma->vm_ops; | ||
9833 | + | ||
9834 | + cvm_ops->vm_ops.open = coda_vm_open; | ||
9835 | + cvm_ops->vm_ops.close = coda_vm_close; | ||
9836 | + cvm_ops->coda_file = coda_file; | ||
9837 | + atomic_set(&cvm_ops->refcnt, 1); | ||
9838 | + | ||
9839 | + vma->vm_ops = &cvm_ops->vm_ops; | ||
9840 | + } | ||
9841 | + return ret; | ||
9842 | } | ||
9843 | |||
9844 | int coda_open(struct inode *coda_inode, struct file *coda_file) | ||
9845 | diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c | ||
9846 | index e5e29f8c920b..cb77e7ee2c9f 100644 | ||
9847 | --- a/fs/ecryptfs/crypto.c | ||
9848 | +++ b/fs/ecryptfs/crypto.c | ||
9849 | @@ -1034,8 +1034,10 @@ int ecryptfs_read_and_validate_header_region(struct inode *inode) | ||
9850 | |||
9851 | rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES, | ||
9852 | inode); | ||
9853 | - if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
9854 | - return rc >= 0 ? -EINVAL : rc; | ||
9855 | + if (rc < 0) | ||
9856 | + return rc; | ||
9857 | + else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
9858 | + return -EINVAL; | ||
9859 | rc = ecryptfs_validate_marker(marker); | ||
9860 | if (!rc) | ||
9861 | ecryptfs_i_size_init(file_size, inode); | ||
9862 | @@ -1397,8 +1399,10 @@ int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry, | ||
9863 | ecryptfs_inode_to_lower(inode), | ||
9864 | ECRYPTFS_XATTR_NAME, file_size, | ||
9865 | ECRYPTFS_SIZE_AND_MARKER_BYTES); | ||
9866 | - if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
9867 | - return rc >= 0 ? -EINVAL : rc; | ||
9868 | + if (rc < 0) | ||
9869 | + return rc; | ||
9870 | + else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
9871 | + return -EINVAL; | ||
9872 | rc = ecryptfs_validate_marker(marker); | ||
9873 | if (!rc) | ||
9874 | ecryptfs_i_size_init(file_size, inode); | ||
9875 | diff --git a/fs/exec.c b/fs/exec.c | ||
9876 | index 81477116035d..820d7f3b25e8 100644 | ||
9877 | --- a/fs/exec.c | ||
9878 | +++ b/fs/exec.c | ||
9879 | @@ -1790,7 +1790,7 @@ static int do_execveat_common(int fd, struct filename *filename, | ||
9880 | current->fs->in_exec = 0; | ||
9881 | current->in_execve = 0; | ||
9882 | acct_update_integrals(current); | ||
9883 | - task_numa_free(current); | ||
9884 | + task_numa_free(current, false); | ||
9885 | free_bprm(bprm); | ||
9886 | kfree(pathbuf); | ||
9887 | putname(filename); | ||
9888 | diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c | ||
9889 | index e16bc4cec62e..0c83bffa7927 100644 | ||
9890 | --- a/fs/ext4/dir.c | ||
9891 | +++ b/fs/ext4/dir.c | ||
9892 | @@ -106,7 +106,6 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | ||
9893 | struct inode *inode = file_inode(file); | ||
9894 | struct super_block *sb = inode->i_sb; | ||
9895 | struct buffer_head *bh = NULL; | ||
9896 | - int dir_has_error = 0; | ||
9897 | struct fscrypt_str fstr = FSTR_INIT(NULL, 0); | ||
9898 | |||
9899 | if (ext4_encrypted_inode(inode)) { | ||
9900 | @@ -142,8 +141,6 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | ||
9901 | return err; | ||
9902 | } | ||
9903 | |||
9904 | - offset = ctx->pos & (sb->s_blocksize - 1); | ||
9905 | - | ||
9906 | while (ctx->pos < inode->i_size) { | ||
9907 | struct ext4_map_blocks map; | ||
9908 | |||
9909 | @@ -152,9 +149,18 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | ||
9910 | goto errout; | ||
9911 | } | ||
9912 | cond_resched(); | ||
9913 | + offset = ctx->pos & (sb->s_blocksize - 1); | ||
9914 | map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb); | ||
9915 | map.m_len = 1; | ||
9916 | err = ext4_map_blocks(NULL, inode, &map, 0); | ||
9917 | + if (err == 0) { | ||
9918 | + /* m_len should never be zero but let's avoid | ||
9919 | + * an infinite loop if it somehow is */ | ||
9920 | + if (map.m_len == 0) | ||
9921 | + map.m_len = 1; | ||
9922 | + ctx->pos += map.m_len * sb->s_blocksize; | ||
9923 | + continue; | ||
9924 | + } | ||
9925 | if (err > 0) { | ||
9926 | pgoff_t index = map.m_pblk >> | ||
9927 | (PAGE_SHIFT - inode->i_blkbits); | ||
9928 | @@ -173,13 +179,6 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | ||
9929 | } | ||
9930 | |||
9931 | if (!bh) { | ||
9932 | - if (!dir_has_error) { | ||
9933 | - EXT4_ERROR_FILE(file, 0, | ||
9934 | - "directory contains a " | ||
9935 | - "hole at offset %llu", | ||
9936 | - (unsigned long long) ctx->pos); | ||
9937 | - dir_has_error = 1; | ||
9938 | - } | ||
9939 | /* corrupt size? Maybe no more blocks to read */ | ||
9940 | if (ctx->pos > inode->i_blocks << 9) | ||
9941 | break; | ||
9942 | diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c | ||
9943 | index 3c3757ee11f0..29dc02758a52 100644 | ||
9944 | --- a/fs/ext4/namei.c | ||
9945 | +++ b/fs/ext4/namei.c | ||
9946 | @@ -79,8 +79,18 @@ static struct buffer_head *ext4_append(handle_t *handle, | ||
9947 | static int ext4_dx_csum_verify(struct inode *inode, | ||
9948 | struct ext4_dir_entry *dirent); | ||
9949 | |||
9950 | +/* | ||
9951 | + * Hints to ext4_read_dirblock regarding whether we expect a directory | ||
9952 | + * block being read to be an index block, or a block containing | ||
9953 | + * directory entries (and if the latter, whether it was found via a | ||
9954 | + * logical block in an htree index block). This is used to control | ||
9955 | + * what sort of sanity checkinig ext4_read_dirblock() will do on the | ||
9956 | + * directory block read from the storage device. EITHER will means | ||
9957 | + * the caller doesn't know what kind of directory block will be read, | ||
9958 | + * so no specific verification will be done. | ||
9959 | + */ | ||
9960 | typedef enum { | ||
9961 | - EITHER, INDEX, DIRENT | ||
9962 | + EITHER, INDEX, DIRENT, DIRENT_HTREE | ||
9963 | } dirblock_type_t; | ||
9964 | |||
9965 | #define ext4_read_dirblock(inode, block, type) \ | ||
9966 | @@ -106,11 +116,14 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode, | ||
9967 | |||
9968 | return bh; | ||
9969 | } | ||
9970 | - if (!bh) { | ||
9971 | + if (!bh && (type == INDEX || type == DIRENT_HTREE)) { | ||
9972 | ext4_error_inode(inode, func, line, block, | ||
9973 | - "Directory hole found"); | ||
9974 | + "Directory hole found for htree %s block", | ||
9975 | + (type == INDEX) ? "index" : "leaf"); | ||
9976 | return ERR_PTR(-EFSCORRUPTED); | ||
9977 | } | ||
9978 | + if (!bh) | ||
9979 | + return NULL; | ||
9980 | dirent = (struct ext4_dir_entry *) bh->b_data; | ||
9981 | /* Determine whether or not we have an index block */ | ||
9982 | if (is_dx(inode)) { | ||
9983 | @@ -960,7 +973,7 @@ static int htree_dirblock_to_tree(struct file *dir_file, | ||
9984 | |||
9985 | dxtrace(printk(KERN_INFO "In htree dirblock_to_tree: block %lu\n", | ||
9986 | (unsigned long)block)); | ||
9987 | - bh = ext4_read_dirblock(dir, block, DIRENT); | ||
9988 | + bh = ext4_read_dirblock(dir, block, DIRENT_HTREE); | ||
9989 | if (IS_ERR(bh)) | ||
9990 | return PTR_ERR(bh); | ||
9991 | |||
9992 | @@ -1537,7 +1550,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir, | ||
9993 | return (struct buffer_head *) frame; | ||
9994 | do { | ||
9995 | block = dx_get_block(frame->at); | ||
9996 | - bh = ext4_read_dirblock(dir, block, DIRENT); | ||
9997 | + bh = ext4_read_dirblock(dir, block, DIRENT_HTREE); | ||
9998 | if (IS_ERR(bh)) | ||
9999 | goto errout; | ||
10000 | |||
10001 | @@ -2142,6 +2155,11 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, | ||
10002 | blocks = dir->i_size >> sb->s_blocksize_bits; | ||
10003 | for (block = 0; block < blocks; block++) { | ||
10004 | bh = ext4_read_dirblock(dir, block, DIRENT); | ||
10005 | + if (bh == NULL) { | ||
10006 | + bh = ext4_bread(handle, dir, block, | ||
10007 | + EXT4_GET_BLOCKS_CREATE); | ||
10008 | + goto add_to_new_block; | ||
10009 | + } | ||
10010 | if (IS_ERR(bh)) { | ||
10011 | retval = PTR_ERR(bh); | ||
10012 | bh = NULL; | ||
10013 | @@ -2162,6 +2180,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, | ||
10014 | brelse(bh); | ||
10015 | } | ||
10016 | bh = ext4_append(handle, dir, &block); | ||
10017 | +add_to_new_block: | ||
10018 | if (IS_ERR(bh)) { | ||
10019 | retval = PTR_ERR(bh); | ||
10020 | bh = NULL; | ||
10021 | @@ -2203,7 +2222,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname, | ||
10022 | return PTR_ERR(frame); | ||
10023 | entries = frame->entries; | ||
10024 | at = frame->at; | ||
10025 | - bh = ext4_read_dirblock(dir, dx_get_block(frame->at), DIRENT); | ||
10026 | + bh = ext4_read_dirblock(dir, dx_get_block(frame->at), DIRENT_HTREE); | ||
10027 | if (IS_ERR(bh)) { | ||
10028 | err = PTR_ERR(bh); | ||
10029 | bh = NULL; | ||
10030 | @@ -2719,7 +2738,10 @@ bool ext4_empty_dir(struct inode *inode) | ||
10031 | EXT4_ERROR_INODE(inode, "invalid size"); | ||
10032 | return true; | ||
10033 | } | ||
10034 | - bh = ext4_read_dirblock(inode, 0, EITHER); | ||
10035 | + /* The first directory block must not be a hole, | ||
10036 | + * so treat it as DIRENT_HTREE | ||
10037 | + */ | ||
10038 | + bh = ext4_read_dirblock(inode, 0, DIRENT_HTREE); | ||
10039 | if (IS_ERR(bh)) | ||
10040 | return true; | ||
10041 | |||
10042 | @@ -2741,6 +2763,10 @@ bool ext4_empty_dir(struct inode *inode) | ||
10043 | brelse(bh); | ||
10044 | lblock = offset >> EXT4_BLOCK_SIZE_BITS(sb); | ||
10045 | bh = ext4_read_dirblock(inode, lblock, EITHER); | ||
10046 | + if (bh == NULL) { | ||
10047 | + offset += sb->s_blocksize; | ||
10048 | + continue; | ||
10049 | + } | ||
10050 | if (IS_ERR(bh)) | ||
10051 | return true; | ||
10052 | de = (struct ext4_dir_entry_2 *) bh->b_data; | ||
10053 | @@ -3302,7 +3328,10 @@ static struct buffer_head *ext4_get_first_dir_block(handle_t *handle, | ||
10054 | struct buffer_head *bh; | ||
10055 | |||
10056 | if (!ext4_has_inline_data(inode)) { | ||
10057 | - bh = ext4_read_dirblock(inode, 0, EITHER); | ||
10058 | + /* The first directory block must not be a hole, so | ||
10059 | + * treat it as DIRENT_HTREE | ||
10060 | + */ | ||
10061 | + bh = ext4_read_dirblock(inode, 0, DIRENT_HTREE); | ||
10062 | if (IS_ERR(bh)) { | ||
10063 | *retval = PTR_ERR(bh); | ||
10064 | return NULL; | ||
10065 | diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c | ||
10066 | index 2fb99a081de8..c983f7d28f03 100644 | ||
10067 | --- a/fs/f2fs/segment.c | ||
10068 | +++ b/fs/f2fs/segment.c | ||
10069 | @@ -1709,6 +1709,11 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) | ||
10070 | seg_i = CURSEG_I(sbi, i); | ||
10071 | segno = le32_to_cpu(ckpt->cur_data_segno[i]); | ||
10072 | blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]); | ||
10073 | + if (blk_off > ENTRIES_IN_SUM) { | ||
10074 | + f2fs_bug_on(sbi, 1); | ||
10075 | + f2fs_put_page(page, 1); | ||
10076 | + return -EFAULT; | ||
10077 | + } | ||
10078 | seg_i->next_segno = segno; | ||
10079 | reset_curseg(sbi, i, 0); | ||
10080 | seg_i->alloc_type = ckpt->alloc_type[i]; | ||
10081 | diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c | ||
10082 | index 8b93d4b98428..baaed9369ab4 100644 | ||
10083 | --- a/fs/fs-writeback.c | ||
10084 | +++ b/fs/fs-writeback.c | ||
10085 | @@ -721,6 +721,7 @@ void wbc_detach_inode(struct writeback_control *wbc) | ||
10086 | void wbc_account_io(struct writeback_control *wbc, struct page *page, | ||
10087 | size_t bytes) | ||
10088 | { | ||
10089 | + struct cgroup_subsys_state *css; | ||
10090 | int id; | ||
10091 | |||
10092 | /* | ||
10093 | @@ -732,7 +733,12 @@ void wbc_account_io(struct writeback_control *wbc, struct page *page, | ||
10094 | if (!wbc->wb) | ||
10095 | return; | ||
10096 | |||
10097 | - id = mem_cgroup_css_from_page(page)->id; | ||
10098 | + css = mem_cgroup_css_from_page(page); | ||
10099 | + /* dead cgroups shouldn't contribute to inode ownership arbitration */ | ||
10100 | + if (!(css->flags & CSS_ONLINE)) | ||
10101 | + return; | ||
10102 | + | ||
10103 | + id = css->id; | ||
10104 | |||
10105 | if (id == wbc->wb_id) { | ||
10106 | wbc->wb_bytes += bytes; | ||
10107 | diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c | ||
10108 | index 76ae25661d3f..851274b25d39 100644 | ||
10109 | --- a/fs/nfs/inode.c | ||
10110 | +++ b/fs/nfs/inode.c | ||
10111 | @@ -950,6 +950,7 @@ int nfs_open(struct inode *inode, struct file *filp) | ||
10112 | nfs_fscache_open_file(inode, filp); | ||
10113 | return 0; | ||
10114 | } | ||
10115 | +EXPORT_SYMBOL_GPL(nfs_open); | ||
10116 | |||
10117 | /* | ||
10118 | * This function is called whenever some part of NFS notices that | ||
10119 | diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c | ||
10120 | index 89a77950e0b0..8a0c301b0c69 100644 | ||
10121 | --- a/fs/nfs/nfs4file.c | ||
10122 | +++ b/fs/nfs/nfs4file.c | ||
10123 | @@ -49,7 +49,7 @@ nfs4_file_open(struct inode *inode, struct file *filp) | ||
10124 | return err; | ||
10125 | |||
10126 | if ((openflags & O_ACCMODE) == 3) | ||
10127 | - openflags--; | ||
10128 | + return nfs_open(inode, filp); | ||
10129 | |||
10130 | /* We can't create new files here */ | ||
10131 | openflags &= ~(O_CREAT|O_EXCL); | ||
10132 | diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c | ||
10133 | index 6d0d94fc243d..ea29c608be89 100644 | ||
10134 | --- a/fs/nfs/nfs4proc.c | ||
10135 | +++ b/fs/nfs/nfs4proc.c | ||
10136 | @@ -1121,6 +1121,12 @@ struct nfs4_opendata { | ||
10137 | int cancelled; | ||
10138 | }; | ||
10139 | |||
10140 | +struct nfs4_open_createattrs { | ||
10141 | + struct nfs4_label *label; | ||
10142 | + struct iattr *sattr; | ||
10143 | + const __u32 verf[2]; | ||
10144 | +}; | ||
10145 | + | ||
10146 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, | ||
10147 | int err, struct nfs4_exception *exception) | ||
10148 | { | ||
10149 | @@ -1190,8 +1196,7 @@ static void nfs4_init_opendata_res(struct nfs4_opendata *p) | ||
10150 | |||
10151 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | ||
10152 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, | ||
10153 | - const struct iattr *attrs, | ||
10154 | - struct nfs4_label *label, | ||
10155 | + const struct nfs4_open_createattrs *c, | ||
10156 | enum open_claim_type4 claim, | ||
10157 | gfp_t gfp_mask) | ||
10158 | { | ||
10159 | @@ -1199,6 +1204,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | ||
10160 | struct inode *dir = d_inode(parent); | ||
10161 | struct nfs_server *server = NFS_SERVER(dir); | ||
10162 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | ||
10163 | + struct nfs4_label *label = (c != NULL) ? c->label : NULL; | ||
10164 | struct nfs4_opendata *p; | ||
10165 | |||
10166 | p = kzalloc(sizeof(*p), gfp_mask); | ||
10167 | @@ -1255,15 +1261,11 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | ||
10168 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | ||
10169 | p->o_arg.fh = NFS_FH(d_inode(dentry)); | ||
10170 | } | ||
10171 | - if (attrs != NULL && attrs->ia_valid != 0) { | ||
10172 | - __u32 verf[2]; | ||
10173 | - | ||
10174 | + if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { | ||
10175 | p->o_arg.u.attrs = &p->attrs; | ||
10176 | - memcpy(&p->attrs, attrs, sizeof(p->attrs)); | ||
10177 | + memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); | ||
10178 | |||
10179 | - verf[0] = jiffies; | ||
10180 | - verf[1] = current->pid; | ||
10181 | - memcpy(p->o_arg.u.verifier.data, verf, | ||
10182 | + memcpy(p->o_arg.u.verifier.data, c->verf, | ||
10183 | sizeof(p->o_arg.u.verifier.data)); | ||
10184 | } | ||
10185 | p->c_arg.fh = &p->o_res.fh; | ||
10186 | @@ -1814,7 +1816,7 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context | ||
10187 | struct nfs4_opendata *opendata; | ||
10188 | |||
10189 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, | ||
10190 | - NULL, NULL, claim, GFP_NOFS); | ||
10191 | + NULL, claim, GFP_NOFS); | ||
10192 | if (opendata == NULL) | ||
10193 | return ERR_PTR(-ENOMEM); | ||
10194 | opendata->state = state; | ||
10195 | @@ -2759,8 +2761,7 @@ out: | ||
10196 | static int _nfs4_do_open(struct inode *dir, | ||
10197 | struct nfs_open_context *ctx, | ||
10198 | int flags, | ||
10199 | - struct iattr *sattr, | ||
10200 | - struct nfs4_label *label, | ||
10201 | + const struct nfs4_open_createattrs *c, | ||
10202 | int *opened) | ||
10203 | { | ||
10204 | struct nfs4_state_owner *sp; | ||
10205 | @@ -2772,6 +2773,8 @@ static int _nfs4_do_open(struct inode *dir, | ||
10206 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; | ||
10207 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); | ||
10208 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; | ||
10209 | + struct iattr *sattr = c->sattr; | ||
10210 | + struct nfs4_label *label = c->label; | ||
10211 | struct nfs4_label *olabel = NULL; | ||
10212 | int status; | ||
10213 | |||
10214 | @@ -2790,8 +2793,8 @@ static int _nfs4_do_open(struct inode *dir, | ||
10215 | status = -ENOMEM; | ||
10216 | if (d_really_is_positive(dentry)) | ||
10217 | claim = NFS4_OPEN_CLAIM_FH; | ||
10218 | - opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, | ||
10219 | - label, claim, GFP_KERNEL); | ||
10220 | + opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, | ||
10221 | + c, claim, GFP_KERNEL); | ||
10222 | if (opendata == NULL) | ||
10223 | goto err_put_state_owner; | ||
10224 | |||
10225 | @@ -2872,10 +2875,18 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, | ||
10226 | struct nfs_server *server = NFS_SERVER(dir); | ||
10227 | struct nfs4_exception exception = { }; | ||
10228 | struct nfs4_state *res; | ||
10229 | + struct nfs4_open_createattrs c = { | ||
10230 | + .label = label, | ||
10231 | + .sattr = sattr, | ||
10232 | + .verf = { | ||
10233 | + [0] = (__u32)jiffies, | ||
10234 | + [1] = (__u32)current->pid, | ||
10235 | + }, | ||
10236 | + }; | ||
10237 | int status; | ||
10238 | |||
10239 | do { | ||
10240 | - status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); | ||
10241 | + status = _nfs4_do_open(dir, ctx, flags, &c, opened); | ||
10242 | res = ctx->state; | ||
10243 | trace_nfs4_open_file(ctx, flags, status); | ||
10244 | if (status == 0) | ||
10245 | diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c | ||
10246 | index 3656f87d11e3..032fcae3a94f 100644 | ||
10247 | --- a/fs/nfsd/nfs4state.c | ||
10248 | +++ b/fs/nfsd/nfs4state.c | ||
10249 | @@ -1502,11 +1502,16 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca) | ||
10250 | { | ||
10251 | u32 slotsize = slot_bytes(ca); | ||
10252 | u32 num = ca->maxreqs; | ||
10253 | - int avail; | ||
10254 | + unsigned long avail, total_avail; | ||
10255 | |||
10256 | spin_lock(&nfsd_drc_lock); | ||
10257 | - avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION, | ||
10258 | - nfsd_drc_max_mem - nfsd_drc_mem_used); | ||
10259 | + total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used; | ||
10260 | + avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION, total_avail); | ||
10261 | + /* | ||
10262 | + * Never use more than a third of the remaining memory, | ||
10263 | + * unless it's the only way to give this client a slot: | ||
10264 | + */ | ||
10265 | + avail = clamp_t(unsigned long, avail, slotsize, total_avail/3); | ||
10266 | num = min_t(int, num, avail / slotsize); | ||
10267 | nfsd_drc_mem_used += num * slotsize; | ||
10268 | spin_unlock(&nfsd_drc_lock); | ||
10269 | diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c | ||
10270 | index 5c4800626f13..60291d10f8e4 100644 | ||
10271 | --- a/fs/nfsd/nfssvc.c | ||
10272 | +++ b/fs/nfsd/nfssvc.c | ||
10273 | @@ -430,7 +430,7 @@ void nfsd_reset_versions(void) | ||
10274 | */ | ||
10275 | static void set_max_drc(void) | ||
10276 | { | ||
10277 | - #define NFSD_DRC_SIZE_SHIFT 10 | ||
10278 | + #define NFSD_DRC_SIZE_SHIFT 7 | ||
10279 | nfsd_drc_max_mem = (nr_free_buffer_pages() | ||
10280 | >> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE; | ||
10281 | nfsd_drc_mem_used = 0; | ||
10282 | diff --git a/fs/open.c b/fs/open.c | ||
10283 | index 6ad9a21f2459..8db6e3a5fc10 100644 | ||
10284 | --- a/fs/open.c | ||
10285 | +++ b/fs/open.c | ||
10286 | @@ -380,6 +380,25 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode) | ||
10287 | override_cred->cap_permitted; | ||
10288 | } | ||
10289 | |||
10290 | + /* | ||
10291 | + * The new set of credentials can *only* be used in | ||
10292 | + * task-synchronous circumstances, and does not need | ||
10293 | + * RCU freeing, unless somebody then takes a separate | ||
10294 | + * reference to it. | ||
10295 | + * | ||
10296 | + * NOTE! This is _only_ true because this credential | ||
10297 | + * is used purely for override_creds() that installs | ||
10298 | + * it as the subjective cred. Other threads will be | ||
10299 | + * accessing ->real_cred, not the subjective cred. | ||
10300 | + * | ||
10301 | + * If somebody _does_ make a copy of this (using the | ||
10302 | + * 'get_current_cred()' function), that will clear the | ||
10303 | + * non_rcu field, because now that other user may be | ||
10304 | + * expecting RCU freeing. But normal thread-synchronous | ||
10305 | + * cred accesses will keep things non-RCY. | ||
10306 | + */ | ||
10307 | + override_cred->non_rcu = 1; | ||
10308 | + | ||
10309 | old_cred = override_creds(override_cred); | ||
10310 | retry: | ||
10311 | res = user_path_at(dfd, filename, lookup_flags, &path); | ||
10312 | diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c | ||
10313 | index 5b32c054df71..191573a625f2 100644 | ||
10314 | --- a/fs/proc/proc_sysctl.c | ||
10315 | +++ b/fs/proc/proc_sysctl.c | ||
10316 | @@ -500,6 +500,10 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, | ||
10317 | |||
10318 | if (root->set_ownership) | ||
10319 | root->set_ownership(head, table, &inode->i_uid, &inode->i_gid); | ||
10320 | + else { | ||
10321 | + inode->i_uid = GLOBAL_ROOT_UID; | ||
10322 | + inode->i_gid = GLOBAL_ROOT_GID; | ||
10323 | + } | ||
10324 | |||
10325 | return inode; | ||
10326 | } | ||
10327 | diff --git a/include/linux/compiler.h b/include/linux/compiler.h | ||
10328 | index 80a5bc623c47..3050de0dac96 100644 | ||
10329 | --- a/include/linux/compiler.h | ||
10330 | +++ b/include/linux/compiler.h | ||
10331 | @@ -250,23 +250,21 @@ void __read_once_size(const volatile void *p, void *res, int size) | ||
10332 | |||
10333 | #ifdef CONFIG_KASAN | ||
10334 | /* | ||
10335 | - * This function is not 'inline' because __no_sanitize_address confilcts | ||
10336 | + * We can't declare function 'inline' because __no_sanitize_address confilcts | ||
10337 | * with inlining. Attempt to inline it may cause a build failure. | ||
10338 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 | ||
10339 | * '__maybe_unused' allows us to avoid defined-but-not-used warnings. | ||
10340 | */ | ||
10341 | -static __no_sanitize_address __maybe_unused | ||
10342 | -void __read_once_size_nocheck(const volatile void *p, void *res, int size) | ||
10343 | -{ | ||
10344 | - __READ_ONCE_SIZE; | ||
10345 | -} | ||
10346 | +# define __no_kasan_or_inline __no_sanitize_address __maybe_unused | ||
10347 | #else | ||
10348 | -static __always_inline | ||
10349 | +# define __no_kasan_or_inline __always_inline | ||
10350 | +#endif | ||
10351 | + | ||
10352 | +static __no_kasan_or_inline | ||
10353 | void __read_once_size_nocheck(const volatile void *p, void *res, int size) | ||
10354 | { | ||
10355 | __READ_ONCE_SIZE; | ||
10356 | } | ||
10357 | -#endif | ||
10358 | |||
10359 | static __always_inline void __write_once_size(volatile void *p, void *res, int size) | ||
10360 | { | ||
10361 | @@ -304,6 +302,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s | ||
10362 | * with an explicit memory barrier or atomic instruction that provides the | ||
10363 | * required ordering. | ||
10364 | */ | ||
10365 | +#include <linux/kasan-checks.h> | ||
10366 | |||
10367 | #define __READ_ONCE(x, check) \ | ||
10368 | ({ \ | ||
10369 | @@ -322,6 +321,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s | ||
10370 | */ | ||
10371 | #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0) | ||
10372 | |||
10373 | +static __no_kasan_or_inline | ||
10374 | +unsigned long read_word_at_a_time(const void *addr) | ||
10375 | +{ | ||
10376 | + kasan_check_read(addr, 1); | ||
10377 | + return *(unsigned long *)addr; | ||
10378 | +} | ||
10379 | + | ||
10380 | #define WRITE_ONCE(x, val) \ | ||
10381 | ({ \ | ||
10382 | union { typeof(x) __val; char __c[1]; } __u = \ | ||
10383 | diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h | ||
10384 | index c9447a689522..1ab0273560ae 100644 | ||
10385 | --- a/include/linux/cpuhotplug.h | ||
10386 | +++ b/include/linux/cpuhotplug.h | ||
10387 | @@ -77,10 +77,10 @@ enum cpuhp_state { | ||
10388 | CPUHP_AP_PERF_ARM_HW_BREAKPOINT_STARTING, | ||
10389 | CPUHP_AP_PERF_ARM_STARTING, | ||
10390 | CPUHP_AP_ARM_L2X0_STARTING, | ||
10391 | + CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING, | ||
10392 | CPUHP_AP_ARM_ARCH_TIMER_STARTING, | ||
10393 | CPUHP_AP_ARM_GLOBAL_TIMER_STARTING, | ||
10394 | CPUHP_AP_JCORE_TIMER_STARTING, | ||
10395 | - CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING, | ||
10396 | CPUHP_AP_ARM_TWD_STARTING, | ||
10397 | CPUHP_AP_METAG_TIMER_STARTING, | ||
10398 | CPUHP_AP_QCOM_TIMER_STARTING, | ||
10399 | diff --git a/include/linux/cred.h b/include/linux/cred.h | ||
10400 | index cf1a5d0c4eb4..4f614042214b 100644 | ||
10401 | --- a/include/linux/cred.h | ||
10402 | +++ b/include/linux/cred.h | ||
10403 | @@ -144,7 +144,11 @@ struct cred { | ||
10404 | struct user_struct *user; /* real user ID subscription */ | ||
10405 | struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */ | ||
10406 | struct group_info *group_info; /* supplementary groups for euid/fsgid */ | ||
10407 | - struct rcu_head rcu; /* RCU deletion hook */ | ||
10408 | + /* RCU deletion */ | ||
10409 | + union { | ||
10410 | + int non_rcu; /* Can we skip RCU deletion? */ | ||
10411 | + struct rcu_head rcu; /* RCU deletion hook */ | ||
10412 | + }; | ||
10413 | }; | ||
10414 | |||
10415 | extern void __put_cred(struct cred *); | ||
10416 | @@ -242,6 +246,7 @@ static inline const struct cred *get_cred(const struct cred *cred) | ||
10417 | { | ||
10418 | struct cred *nonconst_cred = (struct cred *) cred; | ||
10419 | validate_creds(cred); | ||
10420 | + nonconst_cred->non_rcu = 0; | ||
10421 | return get_new_cred(nonconst_cred); | ||
10422 | } | ||
10423 | |||
10424 | diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h | ||
10425 | index aa2935779e43..96037ba940ee 100644 | ||
10426 | --- a/include/linux/rcupdate.h | ||
10427 | +++ b/include/linux/rcupdate.h | ||
10428 | @@ -866,7 +866,7 @@ static inline void rcu_preempt_sleep_check(void) | ||
10429 | * read-side critical sections may be preempted and they may also block, but | ||
10430 | * only when acquiring spinlocks that are subject to priority inheritance. | ||
10431 | */ | ||
10432 | -static inline void rcu_read_lock(void) | ||
10433 | +static __always_inline void rcu_read_lock(void) | ||
10434 | { | ||
10435 | __rcu_read_lock(); | ||
10436 | __acquire(RCU); | ||
10437 | diff --git a/include/linux/sched.h b/include/linux/sched.h | ||
10438 | index 1c487a3abd84..275511b60978 100644 | ||
10439 | --- a/include/linux/sched.h | ||
10440 | +++ b/include/linux/sched.h | ||
10441 | @@ -2044,7 +2044,7 @@ static inline bool in_vfork(struct task_struct *tsk) | ||
10442 | extern void task_numa_fault(int last_node, int node, int pages, int flags); | ||
10443 | extern pid_t task_numa_group_id(struct task_struct *p); | ||
10444 | extern void set_numabalancing_state(bool enabled); | ||
10445 | -extern void task_numa_free(struct task_struct *p); | ||
10446 | +extern void task_numa_free(struct task_struct *p, bool final); | ||
10447 | extern bool should_numa_migrate_memory(struct task_struct *p, struct page *page, | ||
10448 | int src_nid, int dst_cpu); | ||
10449 | #else | ||
10450 | @@ -2059,7 +2059,7 @@ static inline pid_t task_numa_group_id(struct task_struct *p) | ||
10451 | static inline void set_numabalancing_state(bool enabled) | ||
10452 | { | ||
10453 | } | ||
10454 | -static inline void task_numa_free(struct task_struct *p) | ||
10455 | +static inline void task_numa_free(struct task_struct *p, bool final) | ||
10456 | { | ||
10457 | } | ||
10458 | static inline bool should_numa_migrate_memory(struct task_struct *p, | ||
10459 | diff --git a/include/net/tcp.h b/include/net/tcp.h | ||
10460 | index d7047de952f0..1eda31f7f013 100644 | ||
10461 | --- a/include/net/tcp.h | ||
10462 | +++ b/include/net/tcp.h | ||
10463 | @@ -1512,6 +1512,11 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, | ||
10464 | void tcp_fastopen_init_key_once(bool publish); | ||
10465 | #define TCP_FASTOPEN_KEY_LENGTH 16 | ||
10466 | |||
10467 | +static inline void tcp_init_send_head(struct sock *sk) | ||
10468 | +{ | ||
10469 | + sk->sk_send_head = NULL; | ||
10470 | +} | ||
10471 | + | ||
10472 | /* Fastopen key context */ | ||
10473 | struct tcp_fastopen_context { | ||
10474 | struct crypto_cipher *tfm; | ||
10475 | @@ -1528,6 +1533,7 @@ static inline void tcp_write_queue_purge(struct sock *sk) | ||
10476 | sk_wmem_free_skb(sk, skb); | ||
10477 | sk_mem_reclaim(sk); | ||
10478 | tcp_clear_all_retrans_hints(tcp_sk(sk)); | ||
10479 | + tcp_init_send_head(sk); | ||
10480 | inet_csk(sk)->icsk_backoff = 0; | ||
10481 | } | ||
10482 | |||
10483 | @@ -1589,11 +1595,6 @@ static inline void tcp_check_send_head(struct sock *sk, struct sk_buff *skb_unli | ||
10484 | tcp_sk(sk)->highest_sack = NULL; | ||
10485 | } | ||
10486 | |||
10487 | -static inline void tcp_init_send_head(struct sock *sk) | ||
10488 | -{ | ||
10489 | - sk->sk_send_head = NULL; | ||
10490 | -} | ||
10491 | - | ||
10492 | static inline void __tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) | ||
10493 | { | ||
10494 | __skb_queue_tail(&sk->sk_write_queue, skb); | ||
10495 | diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile | ||
10496 | index eed911d091da..5a590f22b4d4 100644 | ||
10497 | --- a/kernel/bpf/Makefile | ||
10498 | +++ b/kernel/bpf/Makefile | ||
10499 | @@ -1,4 +1,5 @@ | ||
10500 | obj-y := core.o | ||
10501 | +CFLAGS_core.o += $(call cc-disable-warning, override-init) | ||
10502 | |||
10503 | obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o | ||
10504 | obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o | ||
10505 | diff --git a/kernel/cred.c b/kernel/cred.c | ||
10506 | index 7b925925be95..0966fab0f48b 100644 | ||
10507 | --- a/kernel/cred.c | ||
10508 | +++ b/kernel/cred.c | ||
10509 | @@ -146,7 +146,10 @@ void __put_cred(struct cred *cred) | ||
10510 | BUG_ON(cred == current->cred); | ||
10511 | BUG_ON(cred == current->real_cred); | ||
10512 | |||
10513 | - call_rcu(&cred->rcu, put_cred_rcu); | ||
10514 | + if (cred->non_rcu) | ||
10515 | + put_cred_rcu(&cred->rcu); | ||
10516 | + else | ||
10517 | + call_rcu(&cred->rcu, put_cred_rcu); | ||
10518 | } | ||
10519 | EXPORT_SYMBOL(__put_cred); | ||
10520 | |||
10521 | @@ -257,6 +260,7 @@ struct cred *prepare_creds(void) | ||
10522 | old = task->cred; | ||
10523 | memcpy(new, old, sizeof(struct cred)); | ||
10524 | |||
10525 | + new->non_rcu = 0; | ||
10526 | atomic_set(&new->usage, 1); | ||
10527 | set_cred_subscribers(new, 0); | ||
10528 | get_group_info(new->group_info); | ||
10529 | @@ -536,7 +540,19 @@ const struct cred *override_creds(const struct cred *new) | ||
10530 | |||
10531 | validate_creds(old); | ||
10532 | validate_creds(new); | ||
10533 | - get_cred(new); | ||
10534 | + | ||
10535 | + /* | ||
10536 | + * NOTE! This uses 'get_new_cred()' rather than 'get_cred()'. | ||
10537 | + * | ||
10538 | + * That means that we do not clear the 'non_rcu' flag, since | ||
10539 | + * we are only installing the cred into the thread-synchronous | ||
10540 | + * '->cred' pointer, not the '->real_cred' pointer that is | ||
10541 | + * visible to other threads under RCU. | ||
10542 | + * | ||
10543 | + * Also note that we did validate_creds() manually, not depending | ||
10544 | + * on the validation in 'get_cred()'. | ||
10545 | + */ | ||
10546 | + get_new_cred((struct cred *)new); | ||
10547 | alter_cred_subscribers(new, 1); | ||
10548 | rcu_assign_pointer(current->cred, new); | ||
10549 | alter_cred_subscribers(old, -1); | ||
10550 | @@ -619,6 +635,7 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) | ||
10551 | validate_creds(old); | ||
10552 | |||
10553 | *new = *old; | ||
10554 | + new->non_rcu = 0; | ||
10555 | atomic_set(&new->usage, 1); | ||
10556 | set_cred_subscribers(new, 0); | ||
10557 | get_uid(new->user); | ||
10558 | diff --git a/kernel/fork.c b/kernel/fork.c | ||
10559 | index e92b06351dec..1c21d13a3874 100644 | ||
10560 | --- a/kernel/fork.c | ||
10561 | +++ b/kernel/fork.c | ||
10562 | @@ -389,7 +389,7 @@ void __put_task_struct(struct task_struct *tsk) | ||
10563 | WARN_ON(tsk == current); | ||
10564 | |||
10565 | cgroup_free(tsk); | ||
10566 | - task_numa_free(tsk); | ||
10567 | + task_numa_free(tsk, true); | ||
10568 | security_task_free(tsk); | ||
10569 | exit_creds(tsk); | ||
10570 | delayacct_tsk_free(tsk); | ||
10571 | diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c | ||
10572 | index 26fc428476b9..4b27aaffdf35 100644 | ||
10573 | --- a/kernel/locking/lockdep.c | ||
10574 | +++ b/kernel/locking/lockdep.c | ||
10575 | @@ -3260,17 +3260,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | ||
10576 | if (depth) { | ||
10577 | hlock = curr->held_locks + depth - 1; | ||
10578 | if (hlock->class_idx == class_idx && nest_lock) { | ||
10579 | - if (hlock->references) { | ||
10580 | - /* | ||
10581 | - * Check: unsigned int references:12, overflow. | ||
10582 | - */ | ||
10583 | - if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1)) | ||
10584 | - return 0; | ||
10585 | + if (!references) | ||
10586 | + references++; | ||
10587 | |||
10588 | + if (!hlock->references) | ||
10589 | hlock->references++; | ||
10590 | - } else { | ||
10591 | - hlock->references = 2; | ||
10592 | - } | ||
10593 | + | ||
10594 | + hlock->references += references; | ||
10595 | + | ||
10596 | + /* Overflow */ | ||
10597 | + if (DEBUG_LOCKS_WARN_ON(hlock->references < references)) | ||
10598 | + return 0; | ||
10599 | |||
10600 | return 1; | ||
10601 | } | ||
10602 | diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c | ||
10603 | index a0f61effad25..75d80809c48c 100644 | ||
10604 | --- a/kernel/locking/lockdep_proc.c | ||
10605 | +++ b/kernel/locking/lockdep_proc.c | ||
10606 | @@ -219,7 +219,6 @@ static void lockdep_stats_debug_show(struct seq_file *m) | ||
10607 | |||
10608 | static int lockdep_stats_show(struct seq_file *m, void *v) | ||
10609 | { | ||
10610 | - struct lock_class *class; | ||
10611 | unsigned long nr_unused = 0, nr_uncategorized = 0, | ||
10612 | nr_irq_safe = 0, nr_irq_unsafe = 0, | ||
10613 | nr_softirq_safe = 0, nr_softirq_unsafe = 0, | ||
10614 | @@ -229,6 +228,9 @@ static int lockdep_stats_show(struct seq_file *m, void *v) | ||
10615 | nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0, | ||
10616 | sum_forward_deps = 0; | ||
10617 | |||
10618 | +#ifdef CONFIG_PROVE_LOCKING | ||
10619 | + struct lock_class *class; | ||
10620 | + | ||
10621 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | ||
10622 | |||
10623 | if (class->usage_mask == 0) | ||
10624 | @@ -260,12 +262,12 @@ static int lockdep_stats_show(struct seq_file *m, void *v) | ||
10625 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ) | ||
10626 | nr_hardirq_read_unsafe++; | ||
10627 | |||
10628 | -#ifdef CONFIG_PROVE_LOCKING | ||
10629 | sum_forward_deps += lockdep_count_forward_deps(class); | ||
10630 | -#endif | ||
10631 | } | ||
10632 | #ifdef CONFIG_DEBUG_LOCKDEP | ||
10633 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused); | ||
10634 | +#endif | ||
10635 | + | ||
10636 | #endif | ||
10637 | seq_printf(m, " lock-classes: %11lu [max: %lu]\n", | ||
10638 | nr_lock_classes, MAX_LOCKDEP_KEYS); | ||
10639 | diff --git a/kernel/padata.c b/kernel/padata.c | ||
10640 | index e4a8f8d9b31a..63449fc584da 100644 | ||
10641 | --- a/kernel/padata.c | ||
10642 | +++ b/kernel/padata.c | ||
10643 | @@ -274,7 +274,12 @@ static void padata_reorder(struct parallel_data *pd) | ||
10644 | * The next object that needs serialization might have arrived to | ||
10645 | * the reorder queues in the meantime, we will be called again | ||
10646 | * from the timer function if no one else cares for it. | ||
10647 | + * | ||
10648 | + * Ensure reorder_objects is read after pd->lock is dropped so we see | ||
10649 | + * an increment from another task in padata_do_serial. Pairs with | ||
10650 | + * smp_mb__after_atomic in padata_do_serial. | ||
10651 | */ | ||
10652 | + smp_mb(); | ||
10653 | if (atomic_read(&pd->reorder_objects) | ||
10654 | && !(pinst->flags & PADATA_RESET)) | ||
10655 | mod_timer(&pd->timer, jiffies + HZ); | ||
10656 | @@ -343,6 +348,13 @@ void padata_do_serial(struct padata_priv *padata) | ||
10657 | list_add_tail(&padata->list, &pqueue->reorder.list); | ||
10658 | spin_unlock(&pqueue->reorder.lock); | ||
10659 | |||
10660 | + /* | ||
10661 | + * Ensure the atomic_inc of reorder_objects above is ordered correctly | ||
10662 | + * with the trylock of pd->lock in padata_reorder. Pairs with smp_mb | ||
10663 | + * in padata_reorder. | ||
10664 | + */ | ||
10665 | + smp_mb__after_atomic(); | ||
10666 | + | ||
10667 | put_cpu(); | ||
10668 | |||
10669 | padata_reorder(pd); | ||
10670 | diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c | ||
10671 | index 3976dd57db78..0eab538841fd 100644 | ||
10672 | --- a/kernel/pid_namespace.c | ||
10673 | +++ b/kernel/pid_namespace.c | ||
10674 | @@ -344,7 +344,7 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) | ||
10675 | } | ||
10676 | |||
10677 | read_lock(&tasklist_lock); | ||
10678 | - force_sig(SIGKILL, pid_ns->child_reaper); | ||
10679 | + send_sig(SIGKILL, pid_ns->child_reaper, 1); | ||
10680 | read_unlock(&tasklist_lock); | ||
10681 | |||
10682 | do_exit(0); | ||
10683 | diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c | ||
10684 | index f0c9b6925687..924bb307c0fa 100644 | ||
10685 | --- a/kernel/sched/fair.c | ||
10686 | +++ b/kernel/sched/fair.c | ||
10687 | @@ -2257,13 +2257,23 @@ no_join: | ||
10688 | return; | ||
10689 | } | ||
10690 | |||
10691 | -void task_numa_free(struct task_struct *p) | ||
10692 | +/* | ||
10693 | + * Get rid of NUMA staticstics associated with a task (either current or dead). | ||
10694 | + * If @final is set, the task is dead and has reached refcount zero, so we can | ||
10695 | + * safely free all relevant data structures. Otherwise, there might be | ||
10696 | + * concurrent reads from places like load balancing and procfs, and we should | ||
10697 | + * reset the data back to default state without freeing ->numa_faults. | ||
10698 | + */ | ||
10699 | +void task_numa_free(struct task_struct *p, bool final) | ||
10700 | { | ||
10701 | struct numa_group *grp = p->numa_group; | ||
10702 | - void *numa_faults = p->numa_faults; | ||
10703 | + unsigned long *numa_faults = p->numa_faults; | ||
10704 | unsigned long flags; | ||
10705 | int i; | ||
10706 | |||
10707 | + if (!numa_faults) | ||
10708 | + return; | ||
10709 | + | ||
10710 | if (grp) { | ||
10711 | spin_lock_irqsave(&grp->lock, flags); | ||
10712 | for (i = 0; i < NR_NUMA_HINT_FAULT_STATS * nr_node_ids; i++) | ||
10713 | @@ -2276,8 +2286,14 @@ void task_numa_free(struct task_struct *p) | ||
10714 | put_numa_group(grp); | ||
10715 | } | ||
10716 | |||
10717 | - p->numa_faults = NULL; | ||
10718 | - kfree(numa_faults); | ||
10719 | + if (final) { | ||
10720 | + p->numa_faults = NULL; | ||
10721 | + kfree(numa_faults); | ||
10722 | + } else { | ||
10723 | + p->total_numa_faults = 0; | ||
10724 | + for (i = 0; i < NR_NUMA_HINT_FAULT_STATS * nr_node_ids; i++) | ||
10725 | + numa_faults[i] = 0; | ||
10726 | + } | ||
10727 | } | ||
10728 | |||
10729 | /* | ||
10730 | diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c | ||
10731 | index 0a16419006f3..4bdb59604526 100644 | ||
10732 | --- a/kernel/time/ntp.c | ||
10733 | +++ b/kernel/time/ntp.c | ||
10734 | @@ -42,6 +42,7 @@ static u64 tick_length_base; | ||
10735 | #define MAX_TICKADJ 500LL /* usecs */ | ||
10736 | #define MAX_TICKADJ_SCALED \ | ||
10737 | (((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) | ||
10738 | +#define MAX_TAI_OFFSET 100000 | ||
10739 | |||
10740 | /* | ||
10741 | * phase-lock loop variables | ||
10742 | @@ -639,7 +640,8 @@ static inline void process_adjtimex_modes(struct timex *txc, | ||
10743 | time_constant = max(time_constant, 0l); | ||
10744 | } | ||
10745 | |||
10746 | - if (txc->modes & ADJ_TAI && txc->constant >= 0) | ||
10747 | + if (txc->modes & ADJ_TAI && | ||
10748 | + txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET) | ||
10749 | *time_tai = txc->constant; | ||
10750 | |||
10751 | if (txc->modes & ADJ_OFFSET) | ||
10752 | diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c | ||
10753 | index 1407ed20ea93..b7c5d230b4b2 100644 | ||
10754 | --- a/kernel/time/timer_list.c | ||
10755 | +++ b/kernel/time/timer_list.c | ||
10756 | @@ -299,23 +299,6 @@ static inline void timer_list_header(struct seq_file *m, u64 now) | ||
10757 | SEQ_printf(m, "\n"); | ||
10758 | } | ||
10759 | |||
10760 | -static int timer_list_show(struct seq_file *m, void *v) | ||
10761 | -{ | ||
10762 | - struct timer_list_iter *iter = v; | ||
10763 | - | ||
10764 | - if (iter->cpu == -1 && !iter->second_pass) | ||
10765 | - timer_list_header(m, iter->now); | ||
10766 | - else if (!iter->second_pass) | ||
10767 | - print_cpu(m, iter->cpu, iter->now); | ||
10768 | -#ifdef CONFIG_GENERIC_CLOCKEVENTS | ||
10769 | - else if (iter->cpu == -1 && iter->second_pass) | ||
10770 | - timer_list_show_tickdevices_header(m); | ||
10771 | - else | ||
10772 | - print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu); | ||
10773 | -#endif | ||
10774 | - return 0; | ||
10775 | -} | ||
10776 | - | ||
10777 | void sysrq_timer_list_show(void) | ||
10778 | { | ||
10779 | u64 now = ktime_to_ns(ktime_get()); | ||
10780 | @@ -334,6 +317,24 @@ void sysrq_timer_list_show(void) | ||
10781 | return; | ||
10782 | } | ||
10783 | |||
10784 | +#ifdef CONFIG_PROC_FS | ||
10785 | +static int timer_list_show(struct seq_file *m, void *v) | ||
10786 | +{ | ||
10787 | + struct timer_list_iter *iter = v; | ||
10788 | + | ||
10789 | + if (iter->cpu == -1 && !iter->second_pass) | ||
10790 | + timer_list_header(m, iter->now); | ||
10791 | + else if (!iter->second_pass) | ||
10792 | + print_cpu(m, iter->cpu, iter->now); | ||
10793 | +#ifdef CONFIG_GENERIC_CLOCKEVENTS | ||
10794 | + else if (iter->cpu == -1 && iter->second_pass) | ||
10795 | + timer_list_show_tickdevices_header(m); | ||
10796 | + else | ||
10797 | + print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu); | ||
10798 | +#endif | ||
10799 | + return 0; | ||
10800 | +} | ||
10801 | + | ||
10802 | static void *move_iter(struct timer_list_iter *iter, loff_t offset) | ||
10803 | { | ||
10804 | for (; offset; offset--) { | ||
10805 | @@ -405,3 +406,4 @@ static int __init init_timer_list_procfs(void) | ||
10806 | return 0; | ||
10807 | } | ||
10808 | __initcall(init_timer_list_procfs); | ||
10809 | +#endif | ||
10810 | diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c | ||
10811 | index ea8a2760de24..70b82f4fd417 100644 | ||
10812 | --- a/kernel/trace/trace.c | ||
10813 | +++ b/kernel/trace/trace.c | ||
10814 | @@ -5820,11 +5820,15 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, | ||
10815 | break; | ||
10816 | } | ||
10817 | #endif | ||
10818 | - if (!tr->allocated_snapshot) { | ||
10819 | + if (!tr->allocated_snapshot) | ||
10820 | + ret = resize_buffer_duplicate_size(&tr->max_buffer, | ||
10821 | + &tr->trace_buffer, iter->cpu_file); | ||
10822 | + else | ||
10823 | ret = alloc_snapshot(tr); | ||
10824 | - if (ret < 0) | ||
10825 | - break; | ||
10826 | - } | ||
10827 | + | ||
10828 | + if (ret < 0) | ||
10829 | + break; | ||
10830 | + | ||
10831 | local_irq_disable(); | ||
10832 | /* Now, we're going to swap */ | ||
10833 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) | ||
10834 | diff --git a/lib/reed_solomon/decode_rs.c b/lib/reed_solomon/decode_rs.c | ||
10835 | index 0ec3f257ffdf..a5d313381539 100644 | ||
10836 | --- a/lib/reed_solomon/decode_rs.c | ||
10837 | +++ b/lib/reed_solomon/decode_rs.c | ||
10838 | @@ -42,8 +42,18 @@ | ||
10839 | BUG_ON(pad < 0 || pad >= nn); | ||
10840 | |||
10841 | /* Does the caller provide the syndrome ? */ | ||
10842 | - if (s != NULL) | ||
10843 | - goto decode; | ||
10844 | + if (s != NULL) { | ||
10845 | + for (i = 0; i < nroots; i++) { | ||
10846 | + /* The syndrome is in index form, | ||
10847 | + * so nn represents zero | ||
10848 | + */ | ||
10849 | + if (s[i] != nn) | ||
10850 | + goto decode; | ||
10851 | + } | ||
10852 | + | ||
10853 | + /* syndrome is zero, no errors to correct */ | ||
10854 | + return 0; | ||
10855 | + } | ||
10856 | |||
10857 | /* form the syndromes; i.e., evaluate data(x) at roots of | ||
10858 | * g(x) */ | ||
10859 | @@ -99,9 +109,9 @@ | ||
10860 | if (no_eras > 0) { | ||
10861 | /* Init lambda to be the erasure locator polynomial */ | ||
10862 | lambda[1] = alpha_to[rs_modnn(rs, | ||
10863 | - prim * (nn - 1 - eras_pos[0]))]; | ||
10864 | + prim * (nn - 1 - (eras_pos[0] + pad)))]; | ||
10865 | for (i = 1; i < no_eras; i++) { | ||
10866 | - u = rs_modnn(rs, prim * (nn - 1 - eras_pos[i])); | ||
10867 | + u = rs_modnn(rs, prim * (nn - 1 - (eras_pos[i] + pad))); | ||
10868 | for (j = i + 1; j > 0; j--) { | ||
10869 | tmp = index_of[lambda[j - 1]]; | ||
10870 | if (tmp != nn) { | ||
10871 | diff --git a/lib/scatterlist.c b/lib/scatterlist.c | ||
10872 | index 004fc70fc56a..a854cc39f084 100644 | ||
10873 | --- a/lib/scatterlist.c | ||
10874 | +++ b/lib/scatterlist.c | ||
10875 | @@ -496,17 +496,18 @@ static bool sg_miter_get_next_page(struct sg_mapping_iter *miter) | ||
10876 | { | ||
10877 | if (!miter->__remaining) { | ||
10878 | struct scatterlist *sg; | ||
10879 | - unsigned long pgoffset; | ||
10880 | |||
10881 | if (!__sg_page_iter_next(&miter->piter)) | ||
10882 | return false; | ||
10883 | |||
10884 | sg = miter->piter.sg; | ||
10885 | - pgoffset = miter->piter.sg_pgoffset; | ||
10886 | |||
10887 | - miter->__offset = pgoffset ? 0 : sg->offset; | ||
10888 | + miter->__offset = miter->piter.sg_pgoffset ? 0 : sg->offset; | ||
10889 | + miter->piter.sg_pgoffset += miter->__offset >> PAGE_SHIFT; | ||
10890 | + miter->__offset &= PAGE_SIZE - 1; | ||
10891 | miter->__remaining = sg->offset + sg->length - | ||
10892 | - (pgoffset << PAGE_SHIFT) - miter->__offset; | ||
10893 | + (miter->piter.sg_pgoffset << PAGE_SHIFT) - | ||
10894 | + miter->__offset; | ||
10895 | miter->__remaining = min_t(unsigned long, miter->__remaining, | ||
10896 | PAGE_SIZE - miter->__offset); | ||
10897 | } | ||
10898 | diff --git a/lib/string.c b/lib/string.c | ||
10899 | index 1cd9757291b1..8f1a2a04e22f 100644 | ||
10900 | --- a/lib/string.c | ||
10901 | +++ b/lib/string.c | ||
10902 | @@ -202,7 +202,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count) | ||
10903 | while (max >= sizeof(unsigned long)) { | ||
10904 | unsigned long c, data; | ||
10905 | |||
10906 | - c = *(unsigned long *)(src+res); | ||
10907 | + c = read_word_at_a_time(src+res); | ||
10908 | if (has_zero(c, &data, &constants)) { | ||
10909 | data = prep_zero_mask(c, data, &constants); | ||
10910 | data = create_zero_mask(data); | ||
10911 | diff --git a/mm/kmemleak.c b/mm/kmemleak.c | ||
10912 | index 9e66449ed91f..d05133b37b17 100644 | ||
10913 | --- a/mm/kmemleak.c | ||
10914 | +++ b/mm/kmemleak.c | ||
10915 | @@ -569,7 +569,7 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size, | ||
10916 | if (in_irq()) { | ||
10917 | object->pid = 0; | ||
10918 | strncpy(object->comm, "hardirq", sizeof(object->comm)); | ||
10919 | - } else if (in_softirq()) { | ||
10920 | + } else if (in_serving_softirq()) { | ||
10921 | object->pid = 0; | ||
10922 | strncpy(object->comm, "softirq", sizeof(object->comm)); | ||
10923 | } else { | ||
10924 | diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c | ||
10925 | index f4259e496f83..7a66e37efb4d 100644 | ||
10926 | --- a/mm/mmu_notifier.c | ||
10927 | +++ b/mm/mmu_notifier.c | ||
10928 | @@ -286,7 +286,7 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn, | ||
10929 | * thanks to mm_take_all_locks(). | ||
10930 | */ | ||
10931 | spin_lock(&mm->mmu_notifier_mm->lock); | ||
10932 | - hlist_add_head(&mn->hlist, &mm->mmu_notifier_mm->list); | ||
10933 | + hlist_add_head_rcu(&mn->hlist, &mm->mmu_notifier_mm->list); | ||
10934 | spin_unlock(&mm->mmu_notifier_mm->lock); | ||
10935 | |||
10936 | mm_drop_all_locks(mm); | ||
10937 | diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c | ||
10938 | index e73fd647065a..f88911cffa1a 100644 | ||
10939 | --- a/net/9p/trans_virtio.c | ||
10940 | +++ b/net/9p/trans_virtio.c | ||
10941 | @@ -764,10 +764,16 @@ static struct p9_trans_module p9_virtio_trans = { | ||
10942 | /* The standard init function */ | ||
10943 | static int __init p9_virtio_init(void) | ||
10944 | { | ||
10945 | + int rc; | ||
10946 | + | ||
10947 | INIT_LIST_HEAD(&virtio_chan_list); | ||
10948 | |||
10949 | v9fs_register_trans(&p9_virtio_trans); | ||
10950 | - return register_virtio_driver(&p9_virtio_drv); | ||
10951 | + rc = register_virtio_driver(&p9_virtio_drv); | ||
10952 | + if (rc) | ||
10953 | + v9fs_unregister_trans(&p9_virtio_trans); | ||
10954 | + | ||
10955 | + return rc; | ||
10956 | } | ||
10957 | |||
10958 | static void __exit p9_virtio_cleanup(void) | ||
10959 | diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c | ||
10960 | index af4a02ad8503..1fab9bcf535d 100644 | ||
10961 | --- a/net/batman-adv/translation-table.c | ||
10962 | +++ b/net/batman-adv/translation-table.c | ||
10963 | @@ -3700,6 +3700,8 @@ static void batadv_tt_purge(struct work_struct *work) | ||
10964 | |||
10965 | void batadv_tt_free(struct batadv_priv *bat_priv) | ||
10966 | { | ||
10967 | + batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_ROAM, 1); | ||
10968 | + | ||
10969 | batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_TT, 1); | ||
10970 | batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_TT, 1); | ||
10971 | |||
10972 | diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c | ||
10973 | index de7b82ece499..21096c882223 100644 | ||
10974 | --- a/net/bluetooth/6lowpan.c | ||
10975 | +++ b/net/bluetooth/6lowpan.c | ||
10976 | @@ -187,10 +187,16 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_btle_dev *dev, | ||
10977 | } | ||
10978 | |||
10979 | if (!rt) { | ||
10980 | - nexthop = &lowpan_cb(skb)->gw; | ||
10981 | - | ||
10982 | - if (ipv6_addr_any(nexthop)) | ||
10983 | - return NULL; | ||
10984 | + if (ipv6_addr_any(&lowpan_cb(skb)->gw)) { | ||
10985 | + /* There is neither route nor gateway, | ||
10986 | + * probably the destination is a direct peer. | ||
10987 | + */ | ||
10988 | + nexthop = daddr; | ||
10989 | + } else { | ||
10990 | + /* There is a known gateway | ||
10991 | + */ | ||
10992 | + nexthop = &lowpan_cb(skb)->gw; | ||
10993 | + } | ||
10994 | } else { | ||
10995 | nexthop = rt6_nexthop(rt, daddr); | ||
10996 | |||
10997 | diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c | ||
10998 | index 6f78489fdb13..163a239bda91 100644 | ||
10999 | --- a/net/bluetooth/hci_event.c | ||
11000 | +++ b/net/bluetooth/hci_event.c | ||
11001 | @@ -5089,6 +5089,11 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, | ||
11002 | return send_conn_param_neg_reply(hdev, handle, | ||
11003 | HCI_ERROR_UNKNOWN_CONN_ID); | ||
11004 | |||
11005 | + if (min < hcon->le_conn_min_interval || | ||
11006 | + max > hcon->le_conn_max_interval) | ||
11007 | + return send_conn_param_neg_reply(hdev, handle, | ||
11008 | + HCI_ERROR_INVALID_LL_PARAMS); | ||
11009 | + | ||
11010 | if (hci_check_conn_params(min, max, latency, timeout)) | ||
11011 | return send_conn_param_neg_reply(hdev, handle, | ||
11012 | HCI_ERROR_INVALID_LL_PARAMS); | ||
11013 | diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c | ||
11014 | index ec9b5d159591..4912e80dacef 100644 | ||
11015 | --- a/net/bluetooth/l2cap_core.c | ||
11016 | +++ b/net/bluetooth/l2cap_core.c | ||
11017 | @@ -4374,6 +4374,12 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, | ||
11018 | |||
11019 | l2cap_chan_lock(chan); | ||
11020 | |||
11021 | + if (chan->state != BT_DISCONN) { | ||
11022 | + l2cap_chan_unlock(chan); | ||
11023 | + mutex_unlock(&conn->chan_lock); | ||
11024 | + return 0; | ||
11025 | + } | ||
11026 | + | ||
11027 | l2cap_chan_hold(chan); | ||
11028 | l2cap_chan_del(chan, 0); | ||
11029 | |||
11030 | @@ -5271,7 +5277,14 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn, | ||
11031 | |||
11032 | memset(&rsp, 0, sizeof(rsp)); | ||
11033 | |||
11034 | - err = hci_check_conn_params(min, max, latency, to_multiplier); | ||
11035 | + if (min < hcon->le_conn_min_interval || | ||
11036 | + max > hcon->le_conn_max_interval) { | ||
11037 | + BT_DBG("requested connection interval exceeds current bounds."); | ||
11038 | + err = -EINVAL; | ||
11039 | + } else { | ||
11040 | + err = hci_check_conn_params(min, max, latency, to_multiplier); | ||
11041 | + } | ||
11042 | + | ||
11043 | if (err) | ||
11044 | rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED); | ||
11045 | else | ||
11046 | diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c | ||
11047 | index 1abfbcd8090a..6670b7ffc200 100644 | ||
11048 | --- a/net/bluetooth/smp.c | ||
11049 | +++ b/net/bluetooth/smp.c | ||
11050 | @@ -2514,6 +2514,19 @@ static int smp_cmd_ident_addr_info(struct l2cap_conn *conn, | ||
11051 | goto distribute; | ||
11052 | } | ||
11053 | |||
11054 | + /* Drop IRK if peer is using identity address during pairing but is | ||
11055 | + * providing different address as identity information. | ||
11056 | + * | ||
11057 | + * Microsoft Surface Precision Mouse is known to have this bug. | ||
11058 | + */ | ||
11059 | + if (hci_is_identity_address(&hcon->dst, hcon->dst_type) && | ||
11060 | + (bacmp(&info->bdaddr, &hcon->dst) || | ||
11061 | + info->addr_type != hcon->dst_type)) { | ||
11062 | + bt_dev_err(hcon->hdev, | ||
11063 | + "ignoring IRK with invalid identity address"); | ||
11064 | + goto distribute; | ||
11065 | + } | ||
11066 | + | ||
11067 | bacpy(&smp->id_addr, &info->bdaddr); | ||
11068 | smp->id_addr_type = info->addr_type; | ||
11069 | |||
11070 | diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c | ||
11071 | index 964ffff90432..3626174456b7 100644 | ||
11072 | --- a/net/bridge/br_multicast.c | ||
11073 | +++ b/net/bridge/br_multicast.c | ||
11074 | @@ -1036,6 +1036,7 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br, | ||
11075 | int type; | ||
11076 | int err = 0; | ||
11077 | __be32 group; | ||
11078 | + u16 nsrcs; | ||
11079 | |||
11080 | ih = igmpv3_report_hdr(skb); | ||
11081 | num = ntohs(ih->ngrec); | ||
11082 | @@ -1049,8 +1050,9 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br, | ||
11083 | grec = (void *)(skb->data + len - sizeof(*grec)); | ||
11084 | group = grec->grec_mca; | ||
11085 | type = grec->grec_type; | ||
11086 | + nsrcs = ntohs(grec->grec_nsrcs); | ||
11087 | |||
11088 | - len += ntohs(grec->grec_nsrcs) * 4; | ||
11089 | + len += nsrcs * 4; | ||
11090 | if (!pskb_may_pull(skb, len)) | ||
11091 | return -EINVAL; | ||
11092 | |||
11093 | @@ -1070,7 +1072,7 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br, | ||
11094 | |||
11095 | if ((type == IGMPV3_CHANGE_TO_INCLUDE || | ||
11096 | type == IGMPV3_MODE_IS_INCLUDE) && | ||
11097 | - ntohs(grec->grec_nsrcs) == 0) { | ||
11098 | + nsrcs == 0) { | ||
11099 | br_ip4_multicast_leave_group(br, port, group, vid); | ||
11100 | } else { | ||
11101 | err = br_ip4_multicast_add_group(br, port, group, vid); | ||
11102 | @@ -1103,23 +1105,26 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br, | ||
11103 | len = skb_transport_offset(skb) + sizeof(*icmp6h); | ||
11104 | |||
11105 | for (i = 0; i < num; i++) { | ||
11106 | - __be16 *nsrcs, _nsrcs; | ||
11107 | - | ||
11108 | - nsrcs = skb_header_pointer(skb, | ||
11109 | - len + offsetof(struct mld2_grec, | ||
11110 | - grec_nsrcs), | ||
11111 | - sizeof(_nsrcs), &_nsrcs); | ||
11112 | - if (!nsrcs) | ||
11113 | + __be16 *_nsrcs, __nsrcs; | ||
11114 | + u16 nsrcs; | ||
11115 | + | ||
11116 | + _nsrcs = skb_header_pointer(skb, | ||
11117 | + len + offsetof(struct mld2_grec, | ||
11118 | + grec_nsrcs), | ||
11119 | + sizeof(__nsrcs), &__nsrcs); | ||
11120 | + if (!_nsrcs) | ||
11121 | return -EINVAL; | ||
11122 | |||
11123 | + nsrcs = ntohs(*_nsrcs); | ||
11124 | + | ||
11125 | if (!pskb_may_pull(skb, | ||
11126 | len + sizeof(*grec) + | ||
11127 | - sizeof(struct in6_addr) * ntohs(*nsrcs))) | ||
11128 | + sizeof(struct in6_addr) * nsrcs)) | ||
11129 | return -EINVAL; | ||
11130 | |||
11131 | grec = (struct mld2_grec *)(skb->data + len); | ||
11132 | len += sizeof(*grec) + | ||
11133 | - sizeof(struct in6_addr) * ntohs(*nsrcs); | ||
11134 | + sizeof(struct in6_addr) * nsrcs; | ||
11135 | |||
11136 | /* We treat these as MLDv1 reports for now. */ | ||
11137 | switch (grec->grec_type) { | ||
11138 | @@ -1137,7 +1142,7 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br, | ||
11139 | |||
11140 | if ((grec->grec_type == MLD2_CHANGE_TO_INCLUDE || | ||
11141 | grec->grec_type == MLD2_MODE_IS_INCLUDE) && | ||
11142 | - ntohs(*nsrcs) == 0) { | ||
11143 | + nsrcs == 0) { | ||
11144 | br_ip6_multicast_leave_group(br, port, &grec->grec_mca, | ||
11145 | vid); | ||
11146 | } else { | ||
11147 | @@ -1374,7 +1379,6 @@ static int br_ip6_multicast_query(struct net_bridge *br, | ||
11148 | struct sk_buff *skb, | ||
11149 | u16 vid) | ||
11150 | { | ||
11151 | - const struct ipv6hdr *ip6h = ipv6_hdr(skb); | ||
11152 | struct mld_msg *mld; | ||
11153 | struct net_bridge_mdb_entry *mp; | ||
11154 | struct mld2_query *mld2q; | ||
11155 | @@ -1418,7 +1422,7 @@ static int br_ip6_multicast_query(struct net_bridge *br, | ||
11156 | |||
11157 | if (is_general_query) { | ||
11158 | saddr.proto = htons(ETH_P_IPV6); | ||
11159 | - saddr.u.ip6 = ip6h->saddr; | ||
11160 | + saddr.u.ip6 = ipv6_hdr(skb)->saddr; | ||
11161 | |||
11162 | br_multicast_query_received(br, port, &br->ip6_other_query, | ||
11163 | &saddr, max_delay); | ||
11164 | diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c | ||
11165 | index 5881fbc114a9..36282eb3492d 100644 | ||
11166 | --- a/net/bridge/br_stp_bpdu.c | ||
11167 | +++ b/net/bridge/br_stp_bpdu.c | ||
11168 | @@ -147,7 +147,6 @@ void br_send_tcn_bpdu(struct net_bridge_port *p) | ||
11169 | void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, | ||
11170 | struct net_device *dev) | ||
11171 | { | ||
11172 | - const unsigned char *dest = eth_hdr(skb)->h_dest; | ||
11173 | struct net_bridge_port *p; | ||
11174 | struct net_bridge *br; | ||
11175 | const unsigned char *buf; | ||
11176 | @@ -176,7 +175,7 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, | ||
11177 | if (p->state == BR_STATE_DISABLED) | ||
11178 | goto out; | ||
11179 | |||
11180 | - if (!ether_addr_equal(dest, br->group_addr)) | ||
11181 | + if (!ether_addr_equal(eth_hdr(skb)->h_dest, br->group_addr)) | ||
11182 | goto out; | ||
11183 | |||
11184 | if (p->flags & BR_BPDU_GUARD) { | ||
11185 | diff --git a/net/core/neighbour.c b/net/core/neighbour.c | ||
11186 | index 01cdfe85bb09..6e964fec45cf 100644 | ||
11187 | --- a/net/core/neighbour.c | ||
11188 | +++ b/net/core/neighbour.c | ||
11189 | @@ -982,6 +982,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb) | ||
11190 | |||
11191 | atomic_set(&neigh->probes, | ||
11192 | NEIGH_VAR(neigh->parms, UCAST_PROBES)); | ||
11193 | + neigh_del_timer(neigh); | ||
11194 | neigh->nud_state = NUD_INCOMPLETE; | ||
11195 | neigh->updated = now; | ||
11196 | next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), | ||
11197 | @@ -998,6 +999,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb) | ||
11198 | } | ||
11199 | } else if (neigh->nud_state & NUD_STALE) { | ||
11200 | neigh_dbg(2, "neigh %p is delayed\n", neigh); | ||
11201 | + neigh_del_timer(neigh); | ||
11202 | neigh->nud_state = NUD_DELAY; | ||
11203 | neigh->updated = jiffies; | ||
11204 | neigh_add_timer(neigh, jiffies + | ||
11205 | diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c | ||
11206 | index f08f984ebc56..93438113d136 100644 | ||
11207 | --- a/net/ipv4/devinet.c | ||
11208 | +++ b/net/ipv4/devinet.c | ||
11209 | @@ -67,6 +67,11 @@ | ||
11210 | |||
11211 | #include "fib_lookup.h" | ||
11212 | |||
11213 | +#define IPV6ONLY_FLAGS \ | ||
11214 | + (IFA_F_NODAD | IFA_F_OPTIMISTIC | IFA_F_DADFAILED | \ | ||
11215 | + IFA_F_HOMEADDRESS | IFA_F_TENTATIVE | \ | ||
11216 | + IFA_F_MANAGETEMPADDR | IFA_F_STABLE_PRIVACY) | ||
11217 | + | ||
11218 | static struct ipv4_devconf ipv4_devconf = { | ||
11219 | .data = { | ||
11220 | [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1, | ||
11221 | @@ -453,6 +458,9 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh, | ||
11222 | ifa->ifa_flags &= ~IFA_F_SECONDARY; | ||
11223 | last_primary = &in_dev->ifa_list; | ||
11224 | |||
11225 | + /* Don't set IPv6 only flags to IPv4 addresses */ | ||
11226 | + ifa->ifa_flags &= ~IPV6ONLY_FLAGS; | ||
11227 | + | ||
11228 | for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL; | ||
11229 | ifap = &ifa1->ifa_next) { | ||
11230 | if (!(ifa1->ifa_flags & IFA_F_SECONDARY) && | ||
11231 | diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c | ||
11232 | index 780dc6fe899d..02c1736c0b89 100644 | ||
11233 | --- a/net/ipv4/igmp.c | ||
11234 | +++ b/net/ipv4/igmp.c | ||
11235 | @@ -1212,12 +1212,8 @@ static void igmpv3_del_delrec(struct in_device *in_dev, struct ip_mc_list *im) | ||
11236 | im->interface = pmc->interface; | ||
11237 | im->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; | ||
11238 | if (im->sfmode == MCAST_INCLUDE) { | ||
11239 | - im->tomb = pmc->tomb; | ||
11240 | - pmc->tomb = NULL; | ||
11241 | - | ||
11242 | - im->sources = pmc->sources; | ||
11243 | - pmc->sources = NULL; | ||
11244 | - | ||
11245 | + swap(im->tomb, pmc->tomb); | ||
11246 | + swap(im->sources, pmc->sources); | ||
11247 | for (psf = im->sources; psf; psf = psf->sf_next) | ||
11248 | psf->sf_crcount = im->crcount; | ||
11249 | } | ||
11250 | diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c | ||
11251 | index ee2822a411f9..6e25524c6a74 100644 | ||
11252 | --- a/net/ipv4/tcp.c | ||
11253 | +++ b/net/ipv4/tcp.c | ||
11254 | @@ -2312,6 +2312,8 @@ int tcp_disconnect(struct sock *sk, int flags) | ||
11255 | dst_release(sk->sk_rx_dst); | ||
11256 | sk->sk_rx_dst = NULL; | ||
11257 | tcp_saved_syn_free(tp); | ||
11258 | + tp->bytes_acked = 0; | ||
11259 | + tp->bytes_received = 0; | ||
11260 | |||
11261 | WARN_ON(inet->inet_num && !icsk->icsk_bind_hash); | ||
11262 | |||
11263 | diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c | ||
11264 | index 41f67629ae59..f38b22f54c09 100644 | ||
11265 | --- a/net/ipv6/ip6mr.c | ||
11266 | +++ b/net/ipv6/ip6mr.c | ||
11267 | @@ -1668,6 +1668,10 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns | ||
11268 | struct net *net = sock_net(sk); | ||
11269 | struct mr6_table *mrt; | ||
11270 | |||
11271 | + if (sk->sk_type != SOCK_RAW || | ||
11272 | + inet_sk(sk)->inet_num != IPPROTO_ICMPV6) | ||
11273 | + return -EOPNOTSUPP; | ||
11274 | + | ||
11275 | mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); | ||
11276 | if (!mrt) | ||
11277 | return -ENOENT; | ||
11278 | @@ -1679,9 +1683,6 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns | ||
11279 | |||
11280 | switch (optname) { | ||
11281 | case MRT6_INIT: | ||
11282 | - if (sk->sk_type != SOCK_RAW || | ||
11283 | - inet_sk(sk)->inet_num != IPPROTO_ICMPV6) | ||
11284 | - return -EOPNOTSUPP; | ||
11285 | if (optlen < sizeof(int)) | ||
11286 | return -EINVAL; | ||
11287 | |||
11288 | @@ -1818,6 +1819,10 @@ int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, | ||
11289 | struct net *net = sock_net(sk); | ||
11290 | struct mr6_table *mrt; | ||
11291 | |||
11292 | + if (sk->sk_type != SOCK_RAW || | ||
11293 | + inet_sk(sk)->inet_num != IPPROTO_ICMPV6) | ||
11294 | + return -EOPNOTSUPP; | ||
11295 | + | ||
11296 | mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); | ||
11297 | if (!mrt) | ||
11298 | return -ENOENT; | ||
11299 | diff --git a/net/key/af_key.c b/net/key/af_key.c | ||
11300 | index 3ba903ff2bb0..36db179d848e 100644 | ||
11301 | --- a/net/key/af_key.c | ||
11302 | +++ b/net/key/af_key.c | ||
11303 | @@ -2463,8 +2463,10 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc | ||
11304 | goto out; | ||
11305 | } | ||
11306 | err = pfkey_xfrm_policy2msg(out_skb, xp, dir); | ||
11307 | - if (err < 0) | ||
11308 | + if (err < 0) { | ||
11309 | + kfree_skb(out_skb); | ||
11310 | goto out; | ||
11311 | + } | ||
11312 | |||
11313 | out_hdr = (struct sadb_msg *) out_skb->data; | ||
11314 | out_hdr->sadb_msg_version = hdr->sadb_msg_version; | ||
11315 | @@ -2717,8 +2719,10 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr) | ||
11316 | return PTR_ERR(out_skb); | ||
11317 | |||
11318 | err = pfkey_xfrm_policy2msg(out_skb, xp, dir); | ||
11319 | - if (err < 0) | ||
11320 | + if (err < 0) { | ||
11321 | + kfree_skb(out_skb); | ||
11322 | return err; | ||
11323 | + } | ||
11324 | |||
11325 | out_hdr = (struct sadb_msg *) out_skb->data; | ||
11326 | out_hdr->sadb_msg_version = pfk->dump.msg_version; | ||
11327 | diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c | ||
11328 | index 046ae1caecea..e5888983bec4 100644 | ||
11329 | --- a/net/netrom/af_netrom.c | ||
11330 | +++ b/net/netrom/af_netrom.c | ||
11331 | @@ -870,7 +870,7 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev) | ||
11332 | unsigned short frametype, flags, window, timeout; | ||
11333 | int ret; | ||
11334 | |||
11335 | - skb->sk = NULL; /* Initially we don't know who it's for */ | ||
11336 | + skb_orphan(skb); | ||
11337 | |||
11338 | /* | ||
11339 | * skb->data points to the netrom frame start | ||
11340 | @@ -968,7 +968,9 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev) | ||
11341 | |||
11342 | window = skb->data[20]; | ||
11343 | |||
11344 | + sock_hold(make); | ||
11345 | skb->sk = make; | ||
11346 | + skb->destructor = sock_efree; | ||
11347 | make->sk_state = TCP_ESTABLISHED; | ||
11348 | |||
11349 | /* Fill in his circuit details */ | ||
11350 | diff --git a/net/nfc/nci/data.c b/net/nfc/nci/data.c | ||
11351 | index dbd24254412a..d20383779710 100644 | ||
11352 | --- a/net/nfc/nci/data.c | ||
11353 | +++ b/net/nfc/nci/data.c | ||
11354 | @@ -119,7 +119,7 @@ static int nci_queue_tx_data_frags(struct nci_dev *ndev, | ||
11355 | conn_info = nci_get_conn_info_by_conn_id(ndev, conn_id); | ||
11356 | if (!conn_info) { | ||
11357 | rc = -EPROTO; | ||
11358 | - goto free_exit; | ||
11359 | + goto exit; | ||
11360 | } | ||
11361 | |||
11362 | __skb_queue_head_init(&frags_q); | ||
11363 | diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c | ||
11364 | index 05d9f42fc309..7135aff3946d 100644 | ||
11365 | --- a/net/openvswitch/actions.c | ||
11366 | +++ b/net/openvswitch/actions.c | ||
11367 | @@ -150,8 +150,7 @@ static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr, | ||
11368 | if (skb->ip_summed == CHECKSUM_COMPLETE) { | ||
11369 | __be16 diff[] = { ~(hdr->h_proto), ethertype }; | ||
11370 | |||
11371 | - skb->csum = ~csum_partial((char *)diff, sizeof(diff), | ||
11372 | - ~skb->csum); | ||
11373 | + skb->csum = csum_partial((char *)diff, sizeof(diff), skb->csum); | ||
11374 | } | ||
11375 | |||
11376 | hdr->h_proto = ethertype; | ||
11377 | @@ -239,8 +238,7 @@ static int set_mpls(struct sk_buff *skb, struct sw_flow_key *flow_key, | ||
11378 | if (skb->ip_summed == CHECKSUM_COMPLETE) { | ||
11379 | __be32 diff[] = { ~(stack->label_stack_entry), lse }; | ||
11380 | |||
11381 | - skb->csum = ~csum_partial((char *)diff, sizeof(diff), | ||
11382 | - ~skb->csum); | ||
11383 | + skb->csum = csum_partial((char *)diff, sizeof(diff), skb->csum); | ||
11384 | } | ||
11385 | |||
11386 | stack->label_stack_entry = lse; | ||
11387 | diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c | ||
11388 | index 2d59c9be40e1..222c566cf25d 100644 | ||
11389 | --- a/net/rxrpc/af_rxrpc.c | ||
11390 | +++ b/net/rxrpc/af_rxrpc.c | ||
11391 | @@ -405,6 +405,7 @@ static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len) | ||
11392 | |||
11393 | switch (rx->sk.sk_state) { | ||
11394 | case RXRPC_UNBOUND: | ||
11395 | + case RXRPC_CLIENT_UNBOUND: | ||
11396 | rx->srx.srx_family = AF_RXRPC; | ||
11397 | rx->srx.srx_service = 0; | ||
11398 | rx->srx.transport_type = SOCK_DGRAM; | ||
11399 | @@ -429,10 +430,9 @@ static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len) | ||
11400 | } | ||
11401 | |||
11402 | rx->local = local; | ||
11403 | - rx->sk.sk_state = RXRPC_CLIENT_UNBOUND; | ||
11404 | + rx->sk.sk_state = RXRPC_CLIENT_BOUND; | ||
11405 | /* Fall through */ | ||
11406 | |||
11407 | - case RXRPC_CLIENT_UNBOUND: | ||
11408 | case RXRPC_CLIENT_BOUND: | ||
11409 | if (!m->msg_name && | ||
11410 | test_bit(RXRPC_SOCK_CONNECTED, &rx->flags)) { | ||
11411 | diff --git a/net/xfrm/Kconfig b/net/xfrm/Kconfig | ||
11412 | index bda1a13628a8..c09336b5a028 100644 | ||
11413 | --- a/net/xfrm/Kconfig | ||
11414 | +++ b/net/xfrm/Kconfig | ||
11415 | @@ -9,6 +9,8 @@ config XFRM_ALGO | ||
11416 | tristate | ||
11417 | select XFRM | ||
11418 | select CRYPTO | ||
11419 | + select CRYPTO_HASH | ||
11420 | + select CRYPTO_BLKCIPHER | ||
11421 | |||
11422 | config XFRM_USER | ||
11423 | tristate "Transformation user configuration interface" | ||
11424 | diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c | ||
11425 | index ca5c79bfd9a5..f3e9d500fa5a 100644 | ||
11426 | --- a/net/xfrm/xfrm_user.c | ||
11427 | +++ b/net/xfrm/xfrm_user.c | ||
11428 | @@ -150,6 +150,25 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, | ||
11429 | |||
11430 | err = -EINVAL; | ||
11431 | switch (p->family) { | ||
11432 | + case AF_INET: | ||
11433 | + break; | ||
11434 | + | ||
11435 | + case AF_INET6: | ||
11436 | +#if IS_ENABLED(CONFIG_IPV6) | ||
11437 | + break; | ||
11438 | +#else | ||
11439 | + err = -EAFNOSUPPORT; | ||
11440 | + goto out; | ||
11441 | +#endif | ||
11442 | + | ||
11443 | + default: | ||
11444 | + goto out; | ||
11445 | + } | ||
11446 | + | ||
11447 | + switch (p->sel.family) { | ||
11448 | + case AF_UNSPEC: | ||
11449 | + break; | ||
11450 | + | ||
11451 | case AF_INET: | ||
11452 | if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32) | ||
11453 | goto out; | ||
11454 | diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c | ||
11455 | index 1f22a186c18c..2c8b8c662da5 100644 | ||
11456 | --- a/scripts/kallsyms.c | ||
11457 | +++ b/scripts/kallsyms.c | ||
11458 | @@ -161,6 +161,9 @@ static int read_symbol(FILE *in, struct sym_entry *s) | ||
11459 | /* exclude debugging symbols */ | ||
11460 | else if (stype == 'N') | ||
11461 | return -1; | ||
11462 | + /* exclude s390 kasan local symbols */ | ||
11463 | + else if (!strncmp(sym, ".LASANPC", 8)) | ||
11464 | + return -1; | ||
11465 | |||
11466 | /* include the type field in the symbol name, so that it gets | ||
11467 | * compressed together */ | ||
11468 | diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h | ||
11469 | index b9897e2be404..04151ede8043 100644 | ||
11470 | --- a/scripts/recordmcount.h | ||
11471 | +++ b/scripts/recordmcount.h | ||
11472 | @@ -326,7 +326,8 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, | ||
11473 | if (!mcountsym) | ||
11474 | mcountsym = get_mcountsym(sym0, relp, str0); | ||
11475 | |||
11476 | - if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) { | ||
11477 | + if (mcountsym && mcountsym == Elf_r_sym(relp) && | ||
11478 | + !is_fake_mcount(relp)) { | ||
11479 | uint_t const addend = | ||
11480 | _w(_w(relp->r_offset) - recval + mcount_adjust); | ||
11481 | mrelp->r_offset = _w(offbase | ||
11482 | diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c | ||
11483 | index bc6d371031fc..130e22742137 100644 | ||
11484 | --- a/sound/core/seq/seq_clientmgr.c | ||
11485 | +++ b/sound/core/seq/seq_clientmgr.c | ||
11486 | @@ -1001,7 +1001,7 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf, | ||
11487 | { | ||
11488 | struct snd_seq_client *client = file->private_data; | ||
11489 | int written = 0, len; | ||
11490 | - int err; | ||
11491 | + int err, handled; | ||
11492 | struct snd_seq_event event; | ||
11493 | |||
11494 | if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT)) | ||
11495 | @@ -1014,6 +1014,8 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf, | ||
11496 | if (!client->accept_output || client->pool == NULL) | ||
11497 | return -ENXIO; | ||
11498 | |||
11499 | + repeat: | ||
11500 | + handled = 0; | ||
11501 | /* allocate the pool now if the pool is not allocated yet */ | ||
11502 | mutex_lock(&client->ioctl_mutex); | ||
11503 | if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) { | ||
11504 | @@ -1073,12 +1075,19 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf, | ||
11505 | 0, 0, &client->ioctl_mutex); | ||
11506 | if (err < 0) | ||
11507 | break; | ||
11508 | + handled++; | ||
11509 | |||
11510 | __skip_event: | ||
11511 | /* Update pointers and counts */ | ||
11512 | count -= len; | ||
11513 | buf += len; | ||
11514 | written += len; | ||
11515 | + | ||
11516 | + /* let's have a coffee break if too many events are queued */ | ||
11517 | + if (++handled >= 200) { | ||
11518 | + mutex_unlock(&client->ioctl_mutex); | ||
11519 | + goto repeat; | ||
11520 | + } | ||
11521 | } | ||
11522 | |||
11523 | out: | ||
11524 | diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c | ||
11525 | index 447b3a8a83c3..df66969b124d 100644 | ||
11526 | --- a/sound/pci/hda/patch_conexant.c | ||
11527 | +++ b/sound/pci/hda/patch_conexant.c | ||
11528 | @@ -1011,6 +1011,7 @@ static int patch_conexant_auto(struct hda_codec *codec) | ||
11529 | */ | ||
11530 | |||
11531 | static const struct hda_device_id snd_hda_id_conexant[] = { | ||
11532 | + HDA_CODEC_ENTRY(0x14f11f86, "CX8070", patch_conexant_auto), | ||
11533 | HDA_CODEC_ENTRY(0x14f12008, "CX8200", patch_conexant_auto), | ||
11534 | HDA_CODEC_ENTRY(0x14f15045, "CX20549 (Venice)", patch_conexant_auto), | ||
11535 | HDA_CODEC_ENTRY(0x14f15047, "CX20551 (Waikiki)", patch_conexant_auto), | ||
11536 | diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c | ||
11537 | index 95fb213cf94b..04d2dc7097a1 100644 | ||
11538 | --- a/sound/pci/hda/patch_realtek.c | ||
11539 | +++ b/sound/pci/hda/patch_realtek.c | ||
11540 | @@ -7272,6 +7272,11 @@ static const struct snd_hda_pin_quirk alc662_pin_fixup_tbl[] = { | ||
11541 | {0x18, 0x01a19030}, | ||
11542 | {0x1a, 0x01813040}, | ||
11543 | {0x21, 0x01014020}), | ||
11544 | + SND_HDA_PIN_QUIRK(0x10ec0867, 0x1028, "Dell", ALC891_FIXUP_DELL_MIC_NO_PRESENCE, | ||
11545 | + {0x16, 0x01813030}, | ||
11546 | + {0x17, 0x02211010}, | ||
11547 | + {0x18, 0x01a19040}, | ||
11548 | + {0x21, 0x01014020}), | ||
11549 | SND_HDA_PIN_QUIRK(0x10ec0662, 0x1028, "Dell", ALC662_FIXUP_DELL_MIC_NO_PRESENCE, | ||
11550 | {0x14, 0x01014010}, | ||
11551 | {0x18, 0x01a19020}, | ||
11552 | diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c | ||
11553 | index c0b6733c0623..8c4375bf34ab 100644 | ||
11554 | --- a/sound/usb/line6/podhd.c | ||
11555 | +++ b/sound/usb/line6/podhd.c | ||
11556 | @@ -385,7 +385,7 @@ static const struct line6_properties podhd_properties_table[] = { | ||
11557 | .name = "POD HD500", | ||
11558 | .capabilities = LINE6_CAP_PCM | ||
11559 | | LINE6_CAP_HWMON, | ||
11560 | - .altsetting = 1, | ||
11561 | + .altsetting = 0, | ||
11562 | .ep_ctrl_r = 0x81, | ||
11563 | .ep_ctrl_w = 0x01, | ||
11564 | .ep_audio_r = 0x86, | ||
11565 | diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c | ||
11566 | index 7a6d61c6c012..55272fef3b50 100644 | ||
11567 | --- a/tools/iio/iio_utils.c | ||
11568 | +++ b/tools/iio/iio_utils.c | ||
11569 | @@ -159,9 +159,9 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, | ||
11570 | *be = (endianchar == 'b'); | ||
11571 | *bytes = padint / 8; | ||
11572 | if (*bits_used == 64) | ||
11573 | - *mask = ~0; | ||
11574 | + *mask = ~(0ULL); | ||
11575 | else | ||
11576 | - *mask = (1ULL << *bits_used) - 1; | ||
11577 | + *mask = (1ULL << *bits_used) - 1ULL; | ||
11578 | |||
11579 | *is_signed = (signchar == 's'); | ||
11580 | if (fclose(sysfsfp)) { | ||
11581 | diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c | ||
11582 | index 47d584da5819..f6cff278aa5d 100644 | ||
11583 | --- a/tools/perf/arch/arm/util/cs-etm.c | ||
11584 | +++ b/tools/perf/arch/arm/util/cs-etm.c | ||
11585 | @@ -41,6 +41,8 @@ struct cs_etm_recording { | ||
11586 | struct auxtrace_record itr; | ||
11587 | struct perf_pmu *cs_etm_pmu; | ||
11588 | struct perf_evlist *evlist; | ||
11589 | + int wrapped_cnt; | ||
11590 | + bool *wrapped; | ||
11591 | bool snapshot_mode; | ||
11592 | size_t snapshot_size; | ||
11593 | }; | ||
11594 | @@ -458,16 +460,131 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, | ||
11595 | return 0; | ||
11596 | } | ||
11597 | |||
11598 | -static int cs_etm_find_snapshot(struct auxtrace_record *itr __maybe_unused, | ||
11599 | +static int cs_etm_alloc_wrapped_array(struct cs_etm_recording *ptr, int idx) | ||
11600 | +{ | ||
11601 | + bool *wrapped; | ||
11602 | + int cnt = ptr->wrapped_cnt; | ||
11603 | + | ||
11604 | + /* Make @ptr->wrapped as big as @idx */ | ||
11605 | + while (cnt <= idx) | ||
11606 | + cnt++; | ||
11607 | + | ||
11608 | + /* | ||
11609 | + * Free'ed in cs_etm_recording_free(). Using realloc() to avoid | ||
11610 | + * cross compilation problems where the host's system supports | ||
11611 | + * reallocarray() but not the target. | ||
11612 | + */ | ||
11613 | + wrapped = realloc(ptr->wrapped, cnt * sizeof(bool)); | ||
11614 | + if (!wrapped) | ||
11615 | + return -ENOMEM; | ||
11616 | + | ||
11617 | + wrapped[cnt - 1] = false; | ||
11618 | + ptr->wrapped_cnt = cnt; | ||
11619 | + ptr->wrapped = wrapped; | ||
11620 | + | ||
11621 | + return 0; | ||
11622 | +} | ||
11623 | + | ||
11624 | +static bool cs_etm_buffer_has_wrapped(unsigned char *buffer, | ||
11625 | + size_t buffer_size, u64 head) | ||
11626 | +{ | ||
11627 | + u64 i, watermark; | ||
11628 | + u64 *buf = (u64 *)buffer; | ||
11629 | + size_t buf_size = buffer_size; | ||
11630 | + | ||
11631 | + /* | ||
11632 | + * We want to look the very last 512 byte (chosen arbitrarily) in | ||
11633 | + * the ring buffer. | ||
11634 | + */ | ||
11635 | + watermark = buf_size - 512; | ||
11636 | + | ||
11637 | + /* | ||
11638 | + * @head is continuously increasing - if its value is equal or greater | ||
11639 | + * than the size of the ring buffer, it has wrapped around. | ||
11640 | + */ | ||
11641 | + if (head >= buffer_size) | ||
11642 | + return true; | ||
11643 | + | ||
11644 | + /* | ||
11645 | + * The value of @head is somewhere within the size of the ring buffer. | ||
11646 | + * This can be that there hasn't been enough data to fill the ring | ||
11647 | + * buffer yet or the trace time was so long that @head has numerically | ||
11648 | + * wrapped around. To find we need to check if we have data at the very | ||
11649 | + * end of the ring buffer. We can reliably do this because mmap'ed | ||
11650 | + * pages are zeroed out and there is a fresh mapping with every new | ||
11651 | + * session. | ||
11652 | + */ | ||
11653 | + | ||
11654 | + /* @head is less than 512 byte from the end of the ring buffer */ | ||
11655 | + if (head > watermark) | ||
11656 | + watermark = head; | ||
11657 | + | ||
11658 | + /* | ||
11659 | + * Speed things up by using 64 bit transactions (see "u64 *buf" above) | ||
11660 | + */ | ||
11661 | + watermark >>= 3; | ||
11662 | + buf_size >>= 3; | ||
11663 | + | ||
11664 | + /* | ||
11665 | + * If we find trace data at the end of the ring buffer, @head has | ||
11666 | + * been there and has numerically wrapped around at least once. | ||
11667 | + */ | ||
11668 | + for (i = watermark; i < buf_size; i++) | ||
11669 | + if (buf[i]) | ||
11670 | + return true; | ||
11671 | + | ||
11672 | + return false; | ||
11673 | +} | ||
11674 | + | ||
11675 | +static int cs_etm_find_snapshot(struct auxtrace_record *itr, | ||
11676 | int idx, struct auxtrace_mmap *mm, | ||
11677 | - unsigned char *data __maybe_unused, | ||
11678 | + unsigned char *data, | ||
11679 | u64 *head, u64 *old) | ||
11680 | { | ||
11681 | + int err; | ||
11682 | + bool wrapped; | ||
11683 | + struct cs_etm_recording *ptr = | ||
11684 | + container_of(itr, struct cs_etm_recording, itr); | ||
11685 | + | ||
11686 | + /* | ||
11687 | + * Allocate memory to keep track of wrapping if this is the first | ||
11688 | + * time we deal with this *mm. | ||
11689 | + */ | ||
11690 | + if (idx >= ptr->wrapped_cnt) { | ||
11691 | + err = cs_etm_alloc_wrapped_array(ptr, idx); | ||
11692 | + if (err) | ||
11693 | + return err; | ||
11694 | + } | ||
11695 | + | ||
11696 | + /* | ||
11697 | + * Check to see if *head has wrapped around. If it hasn't only the | ||
11698 | + * amount of data between *head and *old is snapshot'ed to avoid | ||
11699 | + * bloating the perf.data file with zeros. But as soon as *head has | ||
11700 | + * wrapped around the entire size of the AUX ring buffer it taken. | ||
11701 | + */ | ||
11702 | + wrapped = ptr->wrapped[idx]; | ||
11703 | + if (!wrapped && cs_etm_buffer_has_wrapped(data, mm->len, *head)) { | ||
11704 | + wrapped = true; | ||
11705 | + ptr->wrapped[idx] = true; | ||
11706 | + } | ||
11707 | + | ||
11708 | pr_debug3("%s: mmap index %d old head %zu new head %zu size %zu\n", | ||
11709 | __func__, idx, (size_t)*old, (size_t)*head, mm->len); | ||
11710 | |||
11711 | - *old = *head; | ||
11712 | - *head += mm->len; | ||
11713 | + /* No wrap has occurred, we can just use *head and *old. */ | ||
11714 | + if (!wrapped) | ||
11715 | + return 0; | ||
11716 | + | ||
11717 | + /* | ||
11718 | + * *head has wrapped around - adjust *head and *old to pickup the | ||
11719 | + * entire content of the AUX buffer. | ||
11720 | + */ | ||
11721 | + if (*head >= mm->len) { | ||
11722 | + *old = *head - mm->len; | ||
11723 | + } else { | ||
11724 | + *head += mm->len; | ||
11725 | + *old = *head - mm->len; | ||
11726 | + } | ||
11727 | |||
11728 | return 0; | ||
11729 | } | ||
11730 | @@ -508,6 +625,8 @@ static void cs_etm_recording_free(struct auxtrace_record *itr) | ||
11731 | { | ||
11732 | struct cs_etm_recording *ptr = | ||
11733 | container_of(itr, struct cs_etm_recording, itr); | ||
11734 | + | ||
11735 | + zfree(&ptr->wrapped); | ||
11736 | free(ptr); | ||
11737 | } | ||
11738 | |||
11739 | diff --git a/tools/perf/perf.h b/tools/perf/perf.h | ||
11740 | index 8f8d895d5b74..3b9d56125ee2 100644 | ||
11741 | --- a/tools/perf/perf.h | ||
11742 | +++ b/tools/perf/perf.h | ||
11743 | @@ -23,7 +23,7 @@ static inline unsigned long long rdclock(void) | ||
11744 | } | ||
11745 | |||
11746 | #ifndef MAX_NR_CPUS | ||
11747 | -#define MAX_NR_CPUS 1024 | ||
11748 | +#define MAX_NR_CPUS 2048 | ||
11749 | #endif | ||
11750 | |||
11751 | extern const char *input_name; | ||
11752 | diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c | ||
11753 | index 0c5ce44f723f..e5d6e6584001 100644 | ||
11754 | --- a/tools/perf/tests/mmap-thread-lookup.c | ||
11755 | +++ b/tools/perf/tests/mmap-thread-lookup.c | ||
11756 | @@ -49,7 +49,7 @@ static void *thread_fn(void *arg) | ||
11757 | { | ||
11758 | struct thread_data *td = arg; | ||
11759 | ssize_t ret; | ||
11760 | - int go; | ||
11761 | + int go = 0; | ||
11762 | |||
11763 | if (thread_init(td)) | ||
11764 | return NULL; | ||
11765 | diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c | ||
11766 | index aa9276bfe3e9..9134a0c3e99d 100644 | ||
11767 | --- a/tools/perf/tests/parse-events.c | ||
11768 | +++ b/tools/perf/tests/parse-events.c | ||
11769 | @@ -12,6 +12,32 @@ | ||
11770 | #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ | ||
11771 | PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) | ||
11772 | |||
11773 | +#if defined(__s390x__) | ||
11774 | +/* Return true if kvm module is available and loaded. Test this | ||
11775 | + * and retun success when trace point kvm_s390_create_vm | ||
11776 | + * exists. Otherwise this test always fails. | ||
11777 | + */ | ||
11778 | +static bool kvm_s390_create_vm_valid(void) | ||
11779 | +{ | ||
11780 | + char *eventfile; | ||
11781 | + bool rc = false; | ||
11782 | + | ||
11783 | + eventfile = get_events_file("kvm-s390"); | ||
11784 | + | ||
11785 | + if (eventfile) { | ||
11786 | + DIR *mydir = opendir(eventfile); | ||
11787 | + | ||
11788 | + if (mydir) { | ||
11789 | + rc = true; | ||
11790 | + closedir(mydir); | ||
11791 | + } | ||
11792 | + put_events_file(eventfile); | ||
11793 | + } | ||
11794 | + | ||
11795 | + return rc; | ||
11796 | +} | ||
11797 | +#endif | ||
11798 | + | ||
11799 | static int test__checkevent_tracepoint(struct perf_evlist *evlist) | ||
11800 | { | ||
11801 | struct perf_evsel *evsel = perf_evlist__first(evlist); | ||
11802 | @@ -1593,6 +1619,7 @@ static struct evlist_test test__events[] = { | ||
11803 | { | ||
11804 | .name = "kvm-s390:kvm_s390_create_vm", | ||
11805 | .check = test__checkevent_tracepoint, | ||
11806 | + .valid = kvm_s390_create_vm_valid, | ||
11807 | .id = 100, | ||
11808 | }, | ||
11809 | #endif | ||
11810 | diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c | ||
11811 | index a62f79558146..758d0108c5a5 100644 | ||
11812 | --- a/tools/perf/util/evsel.c | ||
11813 | +++ b/tools/perf/util/evsel.c | ||
11814 | @@ -558,6 +558,9 @@ const char *perf_evsel__name(struct perf_evsel *evsel) | ||
11815 | { | ||
11816 | char bf[128]; | ||
11817 | |||
11818 | + if (!evsel) | ||
11819 | + goto out_unknown; | ||
11820 | + | ||
11821 | if (evsel->name) | ||
11822 | return evsel->name; | ||
11823 | |||
11824 | @@ -594,7 +597,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel) | ||
11825 | |||
11826 | evsel->name = strdup(bf); | ||
11827 | |||
11828 | - return evsel->name ?: "unknown"; | ||
11829 | + if (evsel->name) | ||
11830 | + return evsel->name; | ||
11831 | +out_unknown: | ||
11832 | + return "unknown"; | ||
11833 | } | ||
11834 | |||
11835 | const char *perf_evsel__group_name(struct perf_evsel *evsel) | ||
11836 | diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c | ||
11837 | index de9b369d2d2e..283148104ffb 100644 | ||
11838 | --- a/tools/perf/util/header.c | ||
11839 | +++ b/tools/perf/util/header.c | ||
11840 | @@ -1008,7 +1008,7 @@ static int build_caches(struct cpu_cache_level caches[], u32 size, u32 *cntp) | ||
11841 | return 0; | ||
11842 | } | ||
11843 | |||
11844 | -#define MAX_CACHES 2000 | ||
11845 | +#define MAX_CACHES (MAX_NR_CPUS * 4) | ||
11846 | |||
11847 | static int write_cache(int fd, struct perf_header *h __maybe_unused, | ||
11848 | struct perf_evlist *evlist __maybe_unused) | ||
11849 | diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c | ||
11850 | index 1eef0aed6423..08a405593a79 100644 | ||
11851 | --- a/tools/power/cpupower/utils/cpufreq-set.c | ||
11852 | +++ b/tools/power/cpupower/utils/cpufreq-set.c | ||
11853 | @@ -306,6 +306,8 @@ int cmd_freq_set(int argc, char **argv) | ||
11854 | bitmask_setbit(cpus_chosen, cpus->cpu); | ||
11855 | cpus = cpus->next; | ||
11856 | } | ||
11857 | + /* Set the last cpu in related cpus list */ | ||
11858 | + bitmask_setbit(cpus_chosen, cpus->cpu); | ||
11859 | cpufreq_put_related_cpus(cpus); | ||
11860 | } | ||
11861 | } |