Gentoo Archives: gentoo-commits

From: "Mike Pagano (mpagano)" <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] linux-patches r1616 - genpatches-2.6/trunk/2.6.31
Date: Mon, 05 Oct 2009 21:46:52
Message-Id: E1MuvO8-0007rw-9z@stork.gentoo.org
1 Author: mpagano
2 Date: 2009-10-05 21:46:35 +0000 (Mon, 05 Oct 2009)
3 New Revision: 1616
4
5 Added:
6 genpatches-2.6/trunk/2.6.31/1001_linux-2.6.31.2.patch
7 Removed:
8 genpatches-2.6/trunk/2.6.31/2300_cdc-acm-set-open-flag.patch
9 genpatches-2.6/trunk/2.6.31/2900_cc1-option-fPIC-check.patch
10 Modified:
11 genpatches-2.6/trunk/2.6.31/0000_README
12 genpatches-2.6/trunk/2.6.31/4202_fbcondecor-0.9.6.patch
13 Log:
14 Linux version 2.6.31.2. Removal of redundant patches.
15
16 Modified: genpatches-2.6/trunk/2.6.31/0000_README
17 ===================================================================
18 --- genpatches-2.6/trunk/2.6.31/0000_README 2009-09-28 15:44:45 UTC (rev 1615)
19 +++ genpatches-2.6/trunk/2.6.31/0000_README 2009-10-05 21:46:35 UTC (rev 1616)
20 @@ -43,14 +43,10 @@
21 From: http://www.kernel.org
22 Desc: Linux 2.6.31.1
23
24 -Patch: 2300_cdc-acm-set-open-flag.patch
25 -From: http://bugs.gentoo.org/show_bug.cgi?id=286761
26 -Desc: fix cdc-acm regression in open
27 +Patch: 1001_linux-2.6.31.2.patch
28 +From: http://www.kernel.org
29 +Desc: Linux 2.6.31.2
30
31 -Patch: 2900_cc1-option-fPIC-check.patch
32 -From: http://bugs.gentoo.org/show_bug.cgi?id=282201
33 -Desc: fix cc1 options check to ensure we do not use -fPIC when compiling
34 -
35 Patch: 4100_dm-bbr.patch
36 From: EVMS 2.5.2
37 Desc: Bad block relocation support for LiveCD users
38
39 Added: genpatches-2.6/trunk/2.6.31/1001_linux-2.6.31.2.patch
40 ===================================================================
41 --- genpatches-2.6/trunk/2.6.31/1001_linux-2.6.31.2.patch (rev 0)
42 +++ genpatches-2.6/trunk/2.6.31/1001_linux-2.6.31.2.patch 2009-10-05 21:46:35 UTC (rev 1616)
43 @@ -0,0 +1,7459 @@
44 +diff --git a/MAINTAINERS b/MAINTAINERS
45 +index 8dca9d8..2ccc21c 100644
46 +--- a/MAINTAINERS
47 ++++ b/MAINTAINERS
48 +@@ -897,6 +897,12 @@ W: http://wireless.kernel.org/en/users/Drivers/ar9170
49 + S: Maintained
50 + F: drivers/net/wireless/ath/ar9170/
51 +
52 ++ATK0110 HWMON DRIVER
53 ++M: Luca Tettamanti <kronos.it@×××××.com>
54 ++L: lm-sensors@××××××××××.org
55 ++S: Maintained
56 ++F: drivers/hwmon/asus_atk0110.c
57 ++
58 + ATI_REMOTE2 DRIVER
59 + M: Ville Syrjala <syrjala@×××.fi>
60 + S: Maintained
61 +diff --git a/arch/alpha/kernel/core_marvel.c b/arch/alpha/kernel/core_marvel.c
62 +index e302dae..8e059e5 100644
63 +--- a/arch/alpha/kernel/core_marvel.c
64 ++++ b/arch/alpha/kernel/core_marvel.c
65 +@@ -1016,7 +1016,7 @@ marvel_agp_bind_memory(alpha_agp_info *agp, off_t pg_start, struct agp_memory *m
66 + {
67 + struct marvel_agp_aperture *aper = agp->aperture.sysdata;
68 + return iommu_bind(aper->arena, aper->pg_start + pg_start,
69 +- mem->page_count, mem->memory);
70 ++ mem->page_count, mem->pages);
71 + }
72 +
73 + static int
74 +diff --git a/arch/alpha/kernel/core_titan.c b/arch/alpha/kernel/core_titan.c
75 +index 319fcb7..7668649 100644
76 +--- a/arch/alpha/kernel/core_titan.c
77 ++++ b/arch/alpha/kernel/core_titan.c
78 +@@ -680,7 +680,7 @@ titan_agp_bind_memory(alpha_agp_info *agp, off_t pg_start, struct agp_memory *me
79 + {
80 + struct titan_agp_aperture *aper = agp->aperture.sysdata;
81 + return iommu_bind(aper->arena, aper->pg_start + pg_start,
82 +- mem->page_count, mem->memory);
83 ++ mem->page_count, mem->pages);
84 + }
85 +
86 + static int
87 +diff --git a/arch/alpha/kernel/pci_impl.h b/arch/alpha/kernel/pci_impl.h
88 +index 00edd04..85457b2 100644
89 +--- a/arch/alpha/kernel/pci_impl.h
90 ++++ b/arch/alpha/kernel/pci_impl.h
91 +@@ -198,7 +198,7 @@ extern unsigned long size_for_memory(unsigned long max);
92 +
93 + extern int iommu_reserve(struct pci_iommu_arena *, long, long);
94 + extern int iommu_release(struct pci_iommu_arena *, long, long);
95 +-extern int iommu_bind(struct pci_iommu_arena *, long, long, unsigned long *);
96 ++extern int iommu_bind(struct pci_iommu_arena *, long, long, struct page **);
97 + extern int iommu_unbind(struct pci_iommu_arena *, long, long);
98 +
99 +
100 +diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
101 +index bfb880a..eadd63b 100644
102 +--- a/arch/alpha/kernel/pci_iommu.c
103 ++++ b/arch/alpha/kernel/pci_iommu.c
104 +@@ -880,7 +880,7 @@ iommu_release(struct pci_iommu_arena *arena, long pg_start, long pg_count)
105 +
106 + int
107 + iommu_bind(struct pci_iommu_arena *arena, long pg_start, long pg_count,
108 +- unsigned long *physaddrs)
109 ++ struct page **pages)
110 + {
111 + unsigned long flags;
112 + unsigned long *ptes;
113 +@@ -900,7 +900,7 @@ iommu_bind(struct pci_iommu_arena *arena, long pg_start, long pg_count,
114 + }
115 +
116 + for(i = 0, j = pg_start; i < pg_count; i++, j++)
117 +- ptes[j] = mk_iommu_pte(physaddrs[i]);
118 ++ ptes[j] = mk_iommu_pte(page_to_phys(pages[i]));
119 +
120 + spin_unlock_irqrestore(&arena->lock, flags);
121 +
122 +diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
123 +index 2546c06..629e05d 100644
124 +--- a/arch/arm/mach-pxa/sharpsl_pm.c
125 ++++ b/arch/arm/mach-pxa/sharpsl_pm.c
126 +@@ -678,8 +678,8 @@ static int corgi_enter_suspend(unsigned long alarm_time, unsigned int alarm_enab
127 + dev_dbg(sharpsl_pm.dev, "User triggered wakeup in offline charger.\n");
128 + }
129 +
130 +- if ((!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_LOCK)) || (sharpsl_fatal_check() < 0) )
131 +- {
132 ++ if ((!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_LOCK)) ||
133 ++ (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_FATAL))) {
134 + dev_err(sharpsl_pm.dev, "Fatal condition. Suspend.\n");
135 + corgi_goto_sleep(alarm_time, alarm_enable, state);
136 + return 1;
137 +diff --git a/arch/powerpc/include/asm/pte-common.h b/arch/powerpc/include/asm/pte-common.h
138 +index a7e210b..0cd2e34 100644
139 +--- a/arch/powerpc/include/asm/pte-common.h
140 ++++ b/arch/powerpc/include/asm/pte-common.h
141 +@@ -176,7 +176,7 @@ extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);
142 + #define HAVE_PAGE_AGP
143 +
144 + /* Advertise support for _PAGE_SPECIAL */
145 +-#ifdef _PAGE_SPECIAL
146 ++#if _PAGE_SPECIAL != 0
147 + #define __HAVE_ARCH_PTE_SPECIAL
148 + #endif
149 +
150 +diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c
151 +index 627767d..d8e6725 100644
152 +--- a/arch/powerpc/mm/pgtable.c
153 ++++ b/arch/powerpc/mm/pgtable.c
154 +@@ -30,6 +30,8 @@
155 + #include <asm/tlbflush.h>
156 + #include <asm/tlb.h>
157 +
158 ++#include "mmu_decl.h"
159 ++
160 + static DEFINE_PER_CPU(struct pte_freelist_batch *, pte_freelist_cur);
161 + static unsigned long pte_freelist_forced_free;
162 +
163 +@@ -119,7 +121,7 @@ void pte_free_finish(void)
164 + /*
165 + * Handle i/d cache flushing, called from set_pte_at() or ptep_set_access_flags()
166 + */
167 +-static pte_t do_dcache_icache_coherency(pte_t pte)
168 ++static pte_t do_dcache_icache_coherency(pte_t pte, unsigned long addr)
169 + {
170 + unsigned long pfn = pte_pfn(pte);
171 + struct page *page;
172 +@@ -128,6 +130,17 @@ static pte_t do_dcache_icache_coherency(pte_t pte)
173 + return pte;
174 + page = pfn_to_page(pfn);
175 +
176 ++#ifdef CONFIG_8xx
177 ++ /* On 8xx, cache control instructions (particularly
178 ++ * "dcbst" from flush_dcache_icache) fault as write
179 ++ * operation if there is an unpopulated TLB entry
180 ++ * for the address in question. To workaround that,
181 ++ * we invalidate the TLB here, thus avoiding dcbst
182 ++ * misbehaviour.
183 ++ */
184 ++ _tlbil_va(addr, 0 /* 8xx doesn't care about PID */);
185 ++#endif
186 ++
187 + if (!PageReserved(page) && !test_bit(PG_arch_1, &page->flags)) {
188 + pr_devel("do_dcache_icache_coherency... flushing\n");
189 + flush_dcache_icache_page(page);
190 +@@ -198,7 +211,7 @@ void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte
191 + */
192 + pte = __pte(pte_val(pte) & ~_PAGE_HPTEFLAGS);
193 + if (pte_need_exec_flush(pte, 1))
194 +- pte = do_dcache_icache_coherency(pte);
195 ++ pte = do_dcache_icache_coherency(pte, addr);
196 +
197 + /* Perform the setting of the PTE */
198 + __set_pte_at(mm, addr, ptep, pte, 0);
199 +@@ -216,7 +229,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
200 + {
201 + int changed;
202 + if (!dirty && pte_need_exec_flush(entry, 0))
203 +- entry = do_dcache_icache_coherency(entry);
204 ++ entry = do_dcache_icache_coherency(entry, address);
205 + changed = !pte_same(*(ptep), entry);
206 + if (changed) {
207 + if (!(vma->vm_flags & VM_HUGETLB))
208 +diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
209 +index 83c1bc8..456a304 100644
210 +--- a/arch/x86/include/asm/elf.h
211 ++++ b/arch/x86/include/asm/elf.h
212 +@@ -299,6 +299,8 @@ do { \
213 +
214 + #ifdef CONFIG_X86_32
215 +
216 ++#define STACK_RND_MASK (0x7ff)
217 ++
218 + #define VDSO_HIGH_BASE (__fix_to_virt(FIX_VDSO))
219 +
220 + #define ARCH_DLINFO ARCH_DLINFO_IA32(vdso_enabled)
221 +diff --git a/arch/x86/include/asm/uv/uv_hub.h b/arch/x86/include/asm/uv/uv_hub.h
222 +index 77a6850..03a0cbd 100644
223 +--- a/arch/x86/include/asm/uv/uv_hub.h
224 ++++ b/arch/x86/include/asm/uv/uv_hub.h
225 +@@ -422,7 +422,7 @@ static inline void uv_hub_send_ipi(int pnode, int apicid, int vector)
226 + unsigned long val;
227 +
228 + val = (1UL << UVH_IPI_INT_SEND_SHFT) |
229 +- ((apicid & 0x3f) << UVH_IPI_INT_APIC_ID_SHFT) |
230 ++ ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) |
231 + (vector << UVH_IPI_INT_VECTOR_SHFT);
232 + uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
233 + }
234 +diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
235 +index 2a50ef8..fde0cd3 100644
236 +--- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
237 ++++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
238 +@@ -605,9 +605,10 @@ static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst,
239 + return 0;
240 + }
241 +
242 +-static void invalidate_entry(struct powernow_k8_data *data, unsigned int entry)
243 ++static void invalidate_entry(struct cpufreq_frequency_table *powernow_table,
244 ++ unsigned int entry)
245 + {
246 +- data->powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
247 ++ powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
248 + }
249 +
250 + static void print_basics(struct powernow_k8_data *data)
251 +@@ -914,13 +915,13 @@ static int fill_powernow_table_pstate(struct powernow_k8_data *data,
252 + "bad value %d.\n", i, index);
253 + printk(KERN_ERR PFX "Please report to BIOS "
254 + "manufacturer\n");
255 +- invalidate_entry(data, i);
256 ++ invalidate_entry(powernow_table, i);
257 + continue;
258 + }
259 + rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi);
260 + if (!(hi & HW_PSTATE_VALID_MASK)) {
261 + dprintk("invalid pstate %d, ignoring\n", index);
262 +- invalidate_entry(data, i);
263 ++ invalidate_entry(powernow_table, i);
264 + continue;
265 + }
266 +
267 +@@ -970,7 +971,7 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
268 + /* verify frequency is OK */
269 + if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) {
270 + dprintk("invalid freq %u kHz, ignoring\n", freq);
271 +- invalidate_entry(data, i);
272 ++ invalidate_entry(powernow_table, i);
273 + continue;
274 + }
275 +
276 +@@ -978,7 +979,7 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
277 + * BIOSs are using "off" to indicate invalid */
278 + if (vid == VID_OFF) {
279 + dprintk("invalid vid %u, ignoring\n", vid);
280 +- invalidate_entry(data, i);
281 ++ invalidate_entry(powernow_table, i);
282 + continue;
283 + }
284 +
285 +@@ -997,7 +998,7 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
286 +
287 + dprintk("double low frequency table entry, "
288 + "ignoring it.\n");
289 +- invalidate_entry(data, i);
290 ++ invalidate_entry(powernow_table, i);
291 + continue;
292 + } else
293 + cntlofreq = i;
294 +@@ -1009,7 +1010,7 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
295 + (unsigned int)
296 + (data->acpi_data.states[i].core_frequency
297 + * 1000));
298 +- invalidate_entry(data, i);
299 ++ invalidate_entry(powernow_table, i);
300 + continue;
301 + }
302 + }
303 +diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
304 +index a5cdb35..4712293 100644
305 +--- a/arch/x86/kvm/mmu.c
306 ++++ b/arch/x86/kvm/mmu.c
307 +@@ -2713,12 +2713,6 @@ static int alloc_mmu_pages(struct kvm_vcpu *vcpu)
308 +
309 + ASSERT(vcpu);
310 +
311 +- if (vcpu->kvm->arch.n_requested_mmu_pages)
312 +- vcpu->kvm->arch.n_free_mmu_pages =
313 +- vcpu->kvm->arch.n_requested_mmu_pages;
314 +- else
315 +- vcpu->kvm->arch.n_free_mmu_pages =
316 +- vcpu->kvm->arch.n_alloc_mmu_pages;
317 + /*
318 + * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64.
319 + * Therefore we need to allocate shadow page tables in the first
320 +diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
321 +index b5fa966..6a768ff 100644
322 +--- a/arch/x86/kvm/vmx.c
323 ++++ b/arch/x86/kvm/vmx.c
324 +@@ -1569,7 +1569,6 @@ static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
325 + vcpu->arch.cr0 = cr0;
326 + vmx_set_cr4(vcpu, vcpu->arch.cr4);
327 + *hw_cr0 |= X86_CR0_PE | X86_CR0_PG;
328 +- *hw_cr0 &= ~X86_CR0_WP;
329 + } else if (!is_paging(vcpu)) {
330 + /* From nonpaging to paging */
331 + vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
332 +@@ -1578,9 +1577,10 @@ static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
333 + CPU_BASED_CR3_STORE_EXITING));
334 + vcpu->arch.cr0 = cr0;
335 + vmx_set_cr4(vcpu, vcpu->arch.cr4);
336 +- if (!(vcpu->arch.cr0 & X86_CR0_WP))
337 +- *hw_cr0 &= ~X86_CR0_WP;
338 + }
339 ++
340 ++ if (!(cr0 & X86_CR0_WP))
341 ++ *hw_cr0 &= ~X86_CR0_WP;
342 + }
343 +
344 + static void ept_update_paging_mode_cr4(unsigned long *hw_cr4,
345 +diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
346 +index 3d36045..91a077f 100644
347 +--- a/arch/x86/kvm/x86.c
348 ++++ b/arch/x86/kvm/x86.c
349 +@@ -1448,6 +1448,10 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
350 + for (func = 0x80000001; func <= limit && nent < cpuid->nent; ++func)
351 + do_cpuid_ent(&cpuid_entries[nent], func, 0,
352 + &nent, cpuid->nent);
353 ++ r = -E2BIG;
354 ++ if (nent >= cpuid->nent)
355 ++ goto out_free;
356 ++
357 + r = -EFAULT;
358 + if (copy_to_user(entries, cpuid_entries,
359 + nent * sizeof(struct kvm_cpuid_entry2)))
360 +@@ -3198,6 +3202,9 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu)
361 + if (!kvm_x86_ops->update_cr8_intercept)
362 + return;
363 +
364 ++ if (!vcpu->arch.apic)
365 ++ return;
366 ++
367 + if (!vcpu->arch.apic->vapic_addr)
368 + max_irr = kvm_lapic_find_highest_irr(vcpu);
369 + else
370 +@@ -4118,13 +4125,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
371 +
372 + vcpu->arch.cr2 = sregs->cr2;
373 + mmu_reset_needed |= vcpu->arch.cr3 != sregs->cr3;
374 +-
375 +- down_read(&vcpu->kvm->slots_lock);
376 +- if (gfn_to_memslot(vcpu->kvm, sregs->cr3 >> PAGE_SHIFT))
377 +- vcpu->arch.cr3 = sregs->cr3;
378 +- else
379 +- set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests);
380 +- up_read(&vcpu->kvm->slots_lock);
381 ++ vcpu->arch.cr3 = sregs->cr3;
382 +
383 + kvm_set_cr8(vcpu, sregs->cr8);
384 +
385 +diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
386 +index eefdeee..0088329 100644
387 +--- a/arch/x86/mm/Makefile
388 ++++ b/arch/x86/mm/Makefile
389 +@@ -1,6 +1,11 @@
390 + obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \
391 + pat.o pgtable.o gup.o
392 +
393 ++# Make sure __phys_addr has no stackprotector
394 ++nostackp := $(call cc-option, -fno-stack-protector)
395 ++CFLAGS_ioremap.o := $(nostackp)
396 ++CFLAGS_init.o := $(nostackp)
397 ++
398 + obj-$(CONFIG_SMP) += tlb.o
399 +
400 + obj-$(CONFIG_X86_32) += pgtable_32.o iomap_32.o
401 +diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
402 +index 1658296..c8191de 100644
403 +--- a/arch/x86/mm/mmap.c
404 ++++ b/arch/x86/mm/mmap.c
405 +@@ -29,13 +29,26 @@
406 + #include <linux/random.h>
407 + #include <linux/limits.h>
408 + #include <linux/sched.h>
409 ++#include <asm/elf.h>
410 ++
411 ++static unsigned int stack_maxrandom_size(void)
412 ++{
413 ++ unsigned int max = 0;
414 ++ if ((current->flags & PF_RANDOMIZE) &&
415 ++ !(current->personality & ADDR_NO_RANDOMIZE)) {
416 ++ max = ((-1U) & STACK_RND_MASK) << PAGE_SHIFT;
417 ++ }
418 ++
419 ++ return max;
420 ++}
421 ++
422 +
423 + /*
424 + * Top of mmap area (just below the process stack).
425 + *
426 +- * Leave an at least ~128 MB hole.
427 ++ * Leave an at least ~128 MB hole with possible stack randomization.
428 + */
429 +-#define MIN_GAP (128*1024*1024)
430 ++#define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
431 + #define MAX_GAP (TASK_SIZE/6*5)
432 +
433 + /*
434 +diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
435 +index e245775..fbb46d6 100644
436 +--- a/arch/x86/mm/pageattr.c
437 ++++ b/arch/x86/mm/pageattr.c
438 +@@ -143,6 +143,7 @@ void clflush_cache_range(void *vaddr, unsigned int size)
439 +
440 + mb();
441 + }
442 ++EXPORT_SYMBOL_GPL(clflush_cache_range);
443 +
444 + static void __cpa_flush_all(void *arg)
445 + {
446 +diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
447 +index 7410640..3bb4fc2 100644
448 +--- a/arch/x86/xen/Makefile
449 ++++ b/arch/x86/xen/Makefile
450 +@@ -8,6 +8,7 @@ endif
451 + # Make sure early boot has no stackprotector
452 + nostackp := $(call cc-option, -fno-stack-protector)
453 + CFLAGS_enlighten.o := $(nostackp)
454 ++CFLAGS_mmu.o := $(nostackp)
455 +
456 + obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \
457 + time.o xen-asm.o xen-asm_$(BITS).o \
458 +@@ -16,3 +17,4 @@ obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \
459 + obj-$(CONFIG_SMP) += smp.o
460 + obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o
461 + obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o
462 ++
463 +diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
464 +index eb33aaa..3839a0f 100644
465 +--- a/arch/x86/xen/enlighten.c
466 ++++ b/arch/x86/xen/enlighten.c
467 +@@ -51,6 +51,7 @@
468 + #include <asm/pgtable.h>
469 + #include <asm/tlbflush.h>
470 + #include <asm/reboot.h>
471 ++#include <asm/stackprotector.h>
472 +
473 + #include "xen-ops.h"
474 + #include "mmu.h"
475 +@@ -330,18 +331,28 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
476 + unsigned long frames[pages];
477 + int f;
478 +
479 +- /* A GDT can be up to 64k in size, which corresponds to 8192
480 +- 8-byte entries, or 16 4k pages.. */
481 ++ /*
482 ++ * A GDT can be up to 64k in size, which corresponds to 8192
483 ++ * 8-byte entries, or 16 4k pages..
484 ++ */
485 +
486 + BUG_ON(size > 65536);
487 + BUG_ON(va & ~PAGE_MASK);
488 +
489 + for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
490 + int level;
491 +- pte_t *ptep = lookup_address(va, &level);
492 ++ pte_t *ptep;
493 + unsigned long pfn, mfn;
494 + void *virt;
495 +
496 ++ /*
497 ++ * The GDT is per-cpu and is in the percpu data area.
498 ++ * That can be virtually mapped, so we need to do a
499 ++ * page-walk to get the underlying MFN for the
500 ++ * hypercall. The page can also be in the kernel's
501 ++ * linear range, so we need to RO that mapping too.
502 ++ */
503 ++ ptep = lookup_address(va, &level);
504 + BUG_ON(ptep == NULL);
505 +
506 + pfn = pte_pfn(*ptep);
507 +@@ -358,6 +369,44 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
508 + BUG();
509 + }
510 +
511 ++/*
512 ++ * load_gdt for early boot, when the gdt is only mapped once
513 ++ */
514 ++static __init void xen_load_gdt_boot(const struct desc_ptr *dtr)
515 ++{
516 ++ unsigned long va = dtr->address;
517 ++ unsigned int size = dtr->size + 1;
518 ++ unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
519 ++ unsigned long frames[pages];
520 ++ int f;
521 ++
522 ++ /*
523 ++ * A GDT can be up to 64k in size, which corresponds to 8192
524 ++ * 8-byte entries, or 16 4k pages..
525 ++ */
526 ++
527 ++ BUG_ON(size > 65536);
528 ++ BUG_ON(va & ~PAGE_MASK);
529 ++
530 ++ for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
531 ++ pte_t pte;
532 ++ unsigned long pfn, mfn;
533 ++
534 ++ pfn = virt_to_pfn(va);
535 ++ mfn = pfn_to_mfn(pfn);
536 ++
537 ++ pte = pfn_pte(pfn, PAGE_KERNEL_RO);
538 ++
539 ++ if (HYPERVISOR_update_va_mapping((unsigned long)va, pte, 0))
540 ++ BUG();
541 ++
542 ++ frames[f] = mfn;
543 ++ }
544 ++
545 ++ if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct)))
546 ++ BUG();
547 ++}
548 ++
549 + static void load_TLS_descriptor(struct thread_struct *t,
550 + unsigned int cpu, unsigned int i)
551 + {
552 +@@ -581,6 +630,29 @@ static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
553 + preempt_enable();
554 + }
555 +
556 ++/*
557 ++ * Version of write_gdt_entry for use at early boot-time needed to
558 ++ * update an entry as simply as possible.
559 ++ */
560 ++static __init void xen_write_gdt_entry_boot(struct desc_struct *dt, int entry,
561 ++ const void *desc, int type)
562 ++{
563 ++ switch (type) {
564 ++ case DESC_LDT:
565 ++ case DESC_TSS:
566 ++ /* ignore */
567 ++ break;
568 ++
569 ++ default: {
570 ++ xmaddr_t maddr = virt_to_machine(&dt[entry]);
571 ++
572 ++ if (HYPERVISOR_update_descriptor(maddr.maddr, *(u64 *)desc))
573 ++ dt[entry] = *(struct desc_struct *)desc;
574 ++ }
575 ++
576 ++ }
577 ++}
578 ++
579 + static void xen_load_sp0(struct tss_struct *tss,
580 + struct thread_struct *thread)
581 + {
582 +@@ -965,6 +1037,23 @@ static const struct machine_ops __initdata xen_machine_ops = {
583 + .emergency_restart = xen_emergency_restart,
584 + };
585 +
586 ++/*
587 ++ * Set up the GDT and segment registers for -fstack-protector. Until
588 ++ * we do this, we have to be careful not to call any stack-protected
589 ++ * function, which is most of the kernel.
590 ++ */
591 ++static void __init xen_setup_stackprotector(void)
592 ++{
593 ++ pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
594 ++ pv_cpu_ops.load_gdt = xen_load_gdt_boot;
595 ++
596 ++ setup_stack_canary_segment(0);
597 ++ switch_to_new_gdt(0);
598 ++
599 ++ pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
600 ++ pv_cpu_ops.load_gdt = xen_load_gdt;
601 ++}
602 ++
603 + /* First C function to be called on Xen boot */
604 + asmlinkage void __init xen_start_kernel(void)
605 + {
606 +@@ -983,14 +1072,34 @@ asmlinkage void __init xen_start_kernel(void)
607 + pv_apic_ops = xen_apic_ops;
608 + pv_mmu_ops = xen_mmu_ops;
609 +
610 +-#ifdef CONFIG_X86_64
611 + /*
612 +- * Setup percpu state. We only need to do this for 64-bit
613 +- * because 32-bit already has %fs set properly.
614 ++ * Set up some pagetable state before starting to set any ptes.
615 + */
616 +- load_percpu_segment(0);
617 ++
618 ++ /* Prevent unwanted bits from being set in PTEs. */
619 ++ __supported_pte_mask &= ~_PAGE_GLOBAL;
620 ++ if (!xen_initial_domain())
621 ++ __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD);
622 ++
623 ++ __supported_pte_mask |= _PAGE_IOMAP;
624 ++
625 ++#ifdef CONFIG_X86_64
626 ++ /* Work out if we support NX */
627 ++ check_efer();
628 + #endif
629 +
630 ++ xen_setup_features();
631 ++
632 ++ /* Get mfn list */
633 ++ if (!xen_feature(XENFEAT_auto_translated_physmap))
634 ++ xen_build_dynamic_phys_to_machine();
635 ++
636 ++ /*
637 ++ * Set up kernel GDT and segment registers, mainly so that
638 ++ * -fstack-protector code can be executed.
639 ++ */
640 ++ xen_setup_stackprotector();
641 ++
642 + xen_init_irq_ops();
643 + xen_init_cpuid_mask();
644 +
645 +@@ -1001,8 +1110,6 @@ asmlinkage void __init xen_start_kernel(void)
646 + set_xen_basic_apic_ops();
647 + #endif
648 +
649 +- xen_setup_features();
650 +-
651 + if (xen_feature(XENFEAT_mmu_pt_update_preserve_ad)) {
652 + pv_mmu_ops.ptep_modify_prot_start = xen_ptep_modify_prot_start;
653 + pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
654 +@@ -1019,22 +1126,8 @@ asmlinkage void __init xen_start_kernel(void)
655 +
656 + xen_smp_init();
657 +
658 +- /* Get mfn list */
659 +- if (!xen_feature(XENFEAT_auto_translated_physmap))
660 +- xen_build_dynamic_phys_to_machine();
661 +-
662 + pgd = (pgd_t *)xen_start_info->pt_base;
663 +
664 +- /* Prevent unwanted bits from being set in PTEs. */
665 +- __supported_pte_mask &= ~_PAGE_GLOBAL;
666 +- if (!xen_initial_domain())
667 +- __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD);
668 +-
669 +-#ifdef CONFIG_X86_64
670 +- /* Work out if we support NX */
671 +- check_efer();
672 +-#endif
673 +-
674 + /* Don't do the full vcpu_info placement stuff until we have a
675 + possible map and a non-dummy shared_info. */
676 + per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
677 +diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
678 +index 429834e..fe03eee 100644
679 +--- a/arch/x86/xen/smp.c
680 ++++ b/arch/x86/xen/smp.c
681 +@@ -236,6 +236,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
682 + ctxt->user_regs.ss = __KERNEL_DS;
683 + #ifdef CONFIG_X86_32
684 + ctxt->user_regs.fs = __KERNEL_PERCPU;
685 ++ ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
686 + #else
687 + ctxt->gs_base_kernel = per_cpu_offset(cpu);
688 + #endif
689 +diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
690 +index 5601506..36a5141 100644
691 +--- a/arch/x86/xen/spinlock.c
692 ++++ b/arch/x86/xen/spinlock.c
693 +@@ -187,7 +187,6 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enabl
694 + struct xen_spinlock *prev;
695 + int irq = __get_cpu_var(lock_kicker_irq);
696 + int ret;
697 +- unsigned long flags;
698 + u64 start;
699 +
700 + /* If kicker interrupts not initialized yet, just spin */
701 +@@ -199,16 +198,12 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enabl
702 + /* announce we're spinning */
703 + prev = spinning_lock(xl);
704 +
705 +- flags = __raw_local_save_flags();
706 +- if (irq_enable) {
707 +- ADD_STATS(taken_slow_irqenable, 1);
708 +- raw_local_irq_enable();
709 +- }
710 +-
711 + ADD_STATS(taken_slow, 1);
712 + ADD_STATS(taken_slow_nested, prev != NULL);
713 +
714 + do {
715 ++ unsigned long flags;
716 ++
717 + /* clear pending */
718 + xen_clear_irq_pending(irq);
719 +
720 +@@ -228,6 +223,12 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enabl
721 + goto out;
722 + }
723 +
724 ++ flags = __raw_local_save_flags();
725 ++ if (irq_enable) {
726 ++ ADD_STATS(taken_slow_irqenable, 1);
727 ++ raw_local_irq_enable();
728 ++ }
729 ++
730 + /*
731 + * Block until irq becomes pending. If we're
732 + * interrupted at this point (after the trylock but
733 +@@ -238,13 +239,15 @@ static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enabl
734 + * pending.
735 + */
736 + xen_poll_irq(irq);
737 ++
738 ++ raw_local_irq_restore(flags);
739 ++
740 + ADD_STATS(taken_slow_spurious, !xen_test_irq_pending(irq));
741 + } while (!xen_test_irq_pending(irq)); /* check for spurious wakeups */
742 +
743 + kstat_incr_irqs_this_cpu(irq, irq_to_desc(irq));
744 +
745 + out:
746 +- raw_local_irq_restore(flags);
747 + unspinning_lock(xl, prev);
748 + spin_time_accum_blocked(start);
749 +
750 +@@ -323,8 +326,13 @@ static void xen_spin_unlock(struct raw_spinlock *lock)
751 + smp_wmb(); /* make sure no writes get moved after unlock */
752 + xl->lock = 0; /* release lock */
753 +
754 +- /* make sure unlock happens before kick */
755 +- barrier();
756 ++ /*
757 ++ * Make sure unlock happens before checking for waiting
758 ++ * spinners. We need a strong barrier to enforce the
759 ++ * write-read ordering to different memory locations, as the
760 ++ * CPU makes no implied guarantees about their ordering.
761 ++ */
762 ++ mb();
763 +
764 + if (unlikely(xl->spinners))
765 + xen_spin_unlock_slow(xl);
766 +diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c
767 +index 12158e0..da9d6d2 100644
768 +--- a/drivers/acpi/pci_slot.c
769 ++++ b/drivers/acpi/pci_slot.c
770 +@@ -57,7 +57,7 @@ ACPI_MODULE_NAME("pci_slot");
771 + MY_NAME , ## arg); \
772 + } while (0)
773 +
774 +-#define SLOT_NAME_SIZE 20 /* Inspired by #define in acpiphp.h */
775 ++#define SLOT_NAME_SIZE 21 /* Inspired by #define in acpiphp.h */
776 +
777 + struct acpi_pci_slot {
778 + acpi_handle root_handle; /* handle of the root bridge */
779 +@@ -149,7 +149,7 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
780 + return AE_OK;
781 + }
782 +
783 +- snprintf(name, sizeof(name), "%u", (u32)sun);
784 ++ snprintf(name, sizeof(name), "%llu", sun);
785 + pci_slot = pci_create_slot(pci_bus, device, name, NULL);
786 + if (IS_ERR(pci_slot)) {
787 + err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot));
788 +diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
789 +index fe3eba5..289c4f8 100644
790 +--- a/drivers/ata/ahci.c
791 ++++ b/drivers/ata/ahci.c
792 +@@ -2861,8 +2861,8 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
793 + if (ahci_asus_m2a_vm_32bit_only(pdev))
794 + hpriv->flags |= AHCI_HFLAG_32BIT_ONLY;
795 +
796 +- if (!(hpriv->flags & AHCI_HFLAG_NO_MSI))
797 +- pci_enable_msi(pdev);
798 ++ if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev))
799 ++ pci_intx(pdev, 1);
800 +
801 + /* save initial config */
802 + ahci_save_initial_config(pdev, hpriv);
803 +diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
804 +index 33a74f1..567f3f7 100644
805 +--- a/drivers/ata/pata_amd.c
806 ++++ b/drivers/ata/pata_amd.c
807 +@@ -307,6 +307,9 @@ static unsigned long nv_mode_filter(struct ata_device *dev,
808 + limit |= ATA_MASK_PIO;
809 + if (!(limit & (ATA_MASK_MWDMA | ATA_MASK_UDMA)))
810 + limit |= ATA_MASK_MWDMA | ATA_MASK_UDMA;
811 ++ /* PIO4, MWDMA2, UDMA2 should always be supported regardless of
812 ++ cable detection result */
813 ++ limit |= ata_pack_xfermask(ATA_PIO4, ATA_MWDMA2, ATA_UDMA2);
814 +
815 + ata_port_printk(ap, KERN_DEBUG, "nv_mode_filter: 0x%lx&0x%lx->0x%lx, "
816 + "BIOS=0x%lx (0x%x) ACPI=0x%lx%s\n",
817 +diff --git a/drivers/base/base.h b/drivers/base/base.h
818 +index b528145..1e52c12 100644
819 +--- a/drivers/base/base.h
820 ++++ b/drivers/base/base.h
821 +@@ -104,7 +104,7 @@ extern int system_bus_init(void);
822 + extern int cpu_dev_init(void);
823 +
824 + extern int bus_add_device(struct device *dev);
825 +-extern void bus_attach_device(struct device *dev);
826 ++extern void bus_probe_device(struct device *dev);
827 + extern void bus_remove_device(struct device *dev);
828 +
829 + extern int bus_add_driver(struct device_driver *drv);
830 +diff --git a/drivers/base/bus.c b/drivers/base/bus.c
831 +index 4b04a15..973bf2a 100644
832 +--- a/drivers/base/bus.c
833 ++++ b/drivers/base/bus.c
834 +@@ -459,8 +459,9 @@ static inline void remove_deprecated_bus_links(struct device *dev) { }
835 + * bus_add_device - add device to bus
836 + * @dev: device being added
837 + *
838 ++ * - Add device's bus attributes.
839 ++ * - Create links to device's bus.
840 + * - Add the device to its bus's list of devices.
841 +- * - Create link to device's bus.
842 + */
843 + int bus_add_device(struct device *dev)
844 + {
845 +@@ -483,6 +484,7 @@ int bus_add_device(struct device *dev)
846 + error = make_deprecated_bus_links(dev);
847 + if (error)
848 + goto out_deprecated;
849 ++ klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices);
850 + }
851 + return 0;
852 +
853 +@@ -498,24 +500,19 @@ out_put:
854 + }
855 +
856 + /**
857 +- * bus_attach_device - add device to bus
858 +- * @dev: device tried to attach to a driver
859 ++ * bus_probe_device - probe drivers for a new device
860 ++ * @dev: device to probe
861 + *
862 +- * - Add device to bus's list of devices.
863 +- * - Try to attach to driver.
864 ++ * - Automatically probe for a driver if the bus allows it.
865 + */
866 +-void bus_attach_device(struct device *dev)
867 ++void bus_probe_device(struct device *dev)
868 + {
869 + struct bus_type *bus = dev->bus;
870 +- int ret = 0;
871 ++ int ret;
872 +
873 +- if (bus) {
874 +- if (bus->p->drivers_autoprobe)
875 +- ret = device_attach(dev);
876 ++ if (bus && bus->p->drivers_autoprobe) {
877 ++ ret = device_attach(dev);
878 + WARN_ON(ret < 0);
879 +- if (ret >= 0)
880 +- klist_add_tail(&dev->p->knode_bus,
881 +- &bus->p->klist_devices);
882 + }
883 + }
884 +
885 +diff --git a/drivers/base/core.c b/drivers/base/core.c
886 +index 7ecb193..c34774d 100644
887 +--- a/drivers/base/core.c
888 ++++ b/drivers/base/core.c
889 +@@ -945,7 +945,7 @@ int device_add(struct device *dev)
890 + BUS_NOTIFY_ADD_DEVICE, dev);
891 +
892 + kobject_uevent(&dev->kobj, KOBJ_ADD);
893 +- bus_attach_device(dev);
894 ++ bus_probe_device(dev);
895 + if (parent)
896 + klist_add_tail(&dev->p->knode_parent,
897 + &parent->p->klist_children);
898 +diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
899 +index dee0f1f..6cf88b6 100644
900 +--- a/drivers/char/agp/intel-agp.c
901 ++++ b/drivers/char/agp/intel-agp.c
902 +@@ -679,23 +679,39 @@ static void intel_i830_setup_flush(void)
903 + if (!intel_private.i8xx_page)
904 + return;
905 +
906 +- /* make page uncached */
907 +- map_page_into_agp(intel_private.i8xx_page);
908 +-
909 + intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
910 + if (!intel_private.i8xx_flush_page)
911 + intel_i830_fini_flush();
912 + }
913 +
914 ++static void
915 ++do_wbinvd(void *null)
916 ++{
917 ++ wbinvd();
918 ++}
919 ++
920 ++/* The chipset_flush interface needs to get data that has already been
921 ++ * flushed out of the CPU all the way out to main memory, because the GPU
922 ++ * doesn't snoop those buffers.
923 ++ *
924 ++ * The 8xx series doesn't have the same lovely interface for flushing the
925 ++ * chipset write buffers that the later chips do. According to the 865
926 ++ * specs, it's 64 octwords, or 1KB. So, to get those previous things in
927 ++ * that buffer out, we just fill 1KB and clflush it out, on the assumption
928 ++ * that it'll push whatever was in there out. It appears to work.
929 ++ */
930 + static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
931 + {
932 + unsigned int *pg = intel_private.i8xx_flush_page;
933 +- int i;
934 +
935 +- for (i = 0; i < 256; i += 2)
936 +- *(pg + i) = i;
937 ++ memset(pg, 0, 1024);
938 +
939 +- wmb();
940 ++ if (cpu_has_clflush) {
941 ++ clflush_cache_range(pg, 1024);
942 ++ } else {
943 ++ if (on_each_cpu(do_wbinvd, NULL, 1) != 0)
944 ++ printk(KERN_ERR "Timed out waiting for cache flush.\n");
945 ++ }
946 + }
947 +
948 + /* The intel i830 automatically initializes the agp aperture during POST.
949 +diff --git a/drivers/char/pty.c b/drivers/char/pty.c
950 +index b33d668..53761ce 100644
951 +--- a/drivers/char/pty.c
952 ++++ b/drivers/char/pty.c
953 +@@ -120,8 +120,10 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
954 + /* Stuff the data into the input queue of the other end */
955 + c = tty_insert_flip_string(to, buf, c);
956 + /* And shovel */
957 +- tty_flip_buffer_push(to);
958 +- tty_wakeup(tty);
959 ++ if (c) {
960 ++ tty_flip_buffer_push(to);
961 ++ tty_wakeup(tty);
962 ++ }
963 + }
964 + return c;
965 + }
966 +diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
967 +index a3afa0c..9fc9517 100644
968 +--- a/drivers/char/tty_io.c
969 ++++ b/drivers/char/tty_io.c
970 +@@ -1184,6 +1184,7 @@ int tty_init_termios(struct tty_struct *tty)
971 + tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
972 + return 0;
973 + }
974 ++EXPORT_SYMBOL_GPL(tty_init_termios);
975 +
976 + /**
977 + * tty_driver_install_tty() - install a tty entry in the driver
978 +diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
979 +index 9769b11..549bd0f 100644
980 +--- a/drivers/char/tty_port.c
981 ++++ b/drivers/char/tty_port.c
982 +@@ -96,6 +96,14 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
983 + }
984 + EXPORT_SYMBOL(tty_port_tty_set);
985 +
986 ++static void tty_port_shutdown(struct tty_port *port)
987 ++{
988 ++ if (port->ops->shutdown &&
989 ++ test_and_clear_bit(ASYNC_INITIALIZED, &port->flags))
990 ++ port->ops->shutdown(port);
991 ++
992 ++}
993 ++
994 + /**
995 + * tty_port_hangup - hangup helper
996 + * @port: tty port
997 +@@ -116,6 +124,7 @@ void tty_port_hangup(struct tty_port *port)
998 + port->tty = NULL;
999 + spin_unlock_irqrestore(&port->lock, flags);
1000 + wake_up_interruptible(&port->open_wait);
1001 ++ tty_port_shutdown(port);
1002 + }
1003 + EXPORT_SYMBOL(tty_port_hangup);
1004 +
1005 +@@ -296,15 +305,17 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
1006 +
1007 + if (port->count) {
1008 + spin_unlock_irqrestore(&port->lock, flags);
1009 ++ if (port->ops->drop)
1010 ++ port->ops->drop(port);
1011 + return 0;
1012 + }
1013 +- port->flags |= ASYNC_CLOSING;
1014 ++ set_bit(ASYNC_CLOSING, &port->flags);
1015 + tty->closing = 1;
1016 + spin_unlock_irqrestore(&port->lock, flags);
1017 + /* Don't block on a stalled port, just pull the chain */
1018 + if (tty->flow_stopped)
1019 + tty_driver_flush_buffer(tty);
1020 +- if (port->flags & ASYNC_INITIALIZED &&
1021 ++ if (test_bit(ASYNCB_INITIALIZED, &port->flags) &&
1022 + port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1023 + tty_wait_until_sent(tty, port->closing_wait);
1024 + if (port->drain_delay) {
1025 +@@ -318,6 +329,9 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
1026 + timeout = 2 * HZ;
1027 + schedule_timeout_interruptible(timeout);
1028 + }
1029 ++ /* Don't call port->drop for the last reference. Callers will want
1030 ++ to drop the last active reference in ->shutdown() or the tty
1031 ++ shutdown path */
1032 + return 1;
1033 + }
1034 + EXPORT_SYMBOL(tty_port_close_start);
1035 +@@ -348,3 +362,14 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
1036 + spin_unlock_irqrestore(&port->lock, flags);
1037 + }
1038 + EXPORT_SYMBOL(tty_port_close_end);
1039 ++
1040 ++void tty_port_close(struct tty_port *port, struct tty_struct *tty,
1041 ++ struct file *filp)
1042 ++{
1043 ++ if (tty_port_close_start(port, tty, filp) == 0)
1044 ++ return;
1045 ++ tty_port_shutdown(port);
1046 ++ tty_port_close_end(port, tty);
1047 ++ tty_port_tty_set(port, NULL);
1048 ++}
1049 ++EXPORT_SYMBOL(tty_port_close);
1050 +diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
1051 +index fc4b68a..c078d99 100644
1052 +--- a/drivers/gpu/drm/i915/i915_drv.c
1053 ++++ b/drivers/gpu/drm/i915/i915_drv.c
1054 +@@ -94,8 +94,6 @@ static int i915_resume(struct drm_device *dev)
1055 + struct drm_i915_private *dev_priv = dev->dev_private;
1056 + int ret = 0;
1057 +
1058 +- pci_set_power_state(dev->pdev, PCI_D0);
1059 +- pci_restore_state(dev->pdev);
1060 + if (pci_enable_device(dev->pdev))
1061 + return -1;
1062 + pci_set_master(dev->pdev);
1063 +diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
1064 +index 80e5ba4..2b7aeee 100644
1065 +--- a/drivers/gpu/drm/i915/i915_gem.c
1066 ++++ b/drivers/gpu/drm/i915/i915_gem.c
1067 +@@ -1151,27 +1151,21 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1068 + mutex_lock(&dev->struct_mutex);
1069 + if (!obj_priv->gtt_space) {
1070 + ret = i915_gem_object_bind_to_gtt(obj, obj_priv->gtt_alignment);
1071 +- if (ret) {
1072 +- mutex_unlock(&dev->struct_mutex);
1073 +- return VM_FAULT_SIGBUS;
1074 +- }
1075 +-
1076 +- ret = i915_gem_object_set_to_gtt_domain(obj, write);
1077 +- if (ret) {
1078 +- mutex_unlock(&dev->struct_mutex);
1079 +- return VM_FAULT_SIGBUS;
1080 +- }
1081 ++ if (ret)
1082 ++ goto unlock;
1083 +
1084 + list_add_tail(&obj_priv->list, &dev_priv->mm.inactive_list);
1085 ++
1086 ++ ret = i915_gem_object_set_to_gtt_domain(obj, write);
1087 ++ if (ret)
1088 ++ goto unlock;
1089 + }
1090 +
1091 + /* Need a new fence register? */
1092 + if (obj_priv->tiling_mode != I915_TILING_NONE) {
1093 + ret = i915_gem_object_get_fence_reg(obj);
1094 +- if (ret) {
1095 +- mutex_unlock(&dev->struct_mutex);
1096 +- return VM_FAULT_SIGBUS;
1097 +- }
1098 ++ if (ret)
1099 ++ goto unlock;
1100 + }
1101 +
1102 + pfn = ((dev->agp->base + obj_priv->gtt_offset) >> PAGE_SHIFT) +
1103 +@@ -1179,18 +1173,18 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1104 +
1105 + /* Finally, remap it using the new GTT offset */
1106 + ret = vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
1107 +-
1108 ++unlock:
1109 + mutex_unlock(&dev->struct_mutex);
1110 +
1111 + switch (ret) {
1112 ++ case 0:
1113 ++ case -ERESTARTSYS:
1114 ++ return VM_FAULT_NOPAGE;
1115 + case -ENOMEM:
1116 + case -EAGAIN:
1117 + return VM_FAULT_OOM;
1118 +- case -EFAULT:
1119 +- case -EINVAL:
1120 +- return VM_FAULT_SIGBUS;
1121 + default:
1122 +- return VM_FAULT_NOPAGE;
1123 ++ return VM_FAULT_SIGBUS;
1124 + }
1125 + }
1126 +
1127 +@@ -2506,16 +2500,6 @@ i915_gem_clflush_object(struct drm_gem_object *obj)
1128 + if (obj_priv->pages == NULL)
1129 + return;
1130 +
1131 +- /* XXX: The 865 in particular appears to be weird in how it handles
1132 +- * cache flushing. We haven't figured it out, but the
1133 +- * clflush+agp_chipset_flush doesn't appear to successfully get the
1134 +- * data visible to the PGU, while wbinvd + agp_chipset_flush does.
1135 +- */
1136 +- if (IS_I865G(obj->dev)) {
1137 +- wbinvd();
1138 +- return;
1139 +- }
1140 +-
1141 + drm_clflush_pages(obj_priv->pages, obj->size / PAGE_SIZE);
1142 + }
1143 +
1144 +@@ -3007,6 +2991,16 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj,
1145 + return -EINVAL;
1146 + }
1147 +
1148 ++ if (reloc->delta >= target_obj->size) {
1149 ++ DRM_ERROR("Relocation beyond target object bounds: "
1150 ++ "obj %p target %d delta %d size %d.\n",
1151 ++ obj, reloc->target_handle,
1152 ++ (int) reloc->delta, (int) target_obj->size);
1153 ++ drm_gem_object_unreference(target_obj);
1154 ++ i915_gem_object_unpin(obj);
1155 ++ return -EINVAL;
1156 ++ }
1157 ++
1158 + if (reloc->write_domain & I915_GEM_DOMAIN_CPU ||
1159 + reloc->read_domains & I915_GEM_DOMAIN_CPU) {
1160 + DRM_ERROR("reloc with read/write CPU domains: "
1161 +@@ -3837,7 +3831,8 @@ void i915_gem_free_object(struct drm_gem_object *obj)
1162 +
1163 + i915_gem_object_unbind(obj);
1164 +
1165 +- i915_gem_free_mmap_offset(obj);
1166 ++ if (obj_priv->mmap_offset)
1167 ++ i915_gem_free_mmap_offset(obj);
1168 +
1169 + kfree(obj_priv->page_cpu_valid);
1170 + kfree(obj_priv->bit_17);
1171 +diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
1172 +index a2d527b..e774a4a 100644
1173 +--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
1174 ++++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
1175 +@@ -234,7 +234,13 @@ i915_gem_detect_bit_6_swizzle(struct drm_device *dev)
1176 + uint32_t swizzle_y = I915_BIT_6_SWIZZLE_UNKNOWN;
1177 + bool need_disable;
1178 +
1179 +- if (!IS_I9XX(dev)) {
1180 ++ if (IS_IGDNG(dev)) {
1181 ++ /* On IGDNG whatever DRAM config, GPU always do
1182 ++ * same swizzling setup.
1183 ++ */
1184 ++ swizzle_x = I915_BIT_6_SWIZZLE_9_10;
1185 ++ swizzle_y = I915_BIT_6_SWIZZLE_9;
1186 ++ } else if (!IS_I9XX(dev)) {
1187 + /* As far as we know, the 865 doesn't have these bit 6
1188 + * swizzling issues.
1189 + */
1190 +@@ -317,13 +323,6 @@ i915_gem_detect_bit_6_swizzle(struct drm_device *dev)
1191 + }
1192 + }
1193 +
1194 +- /* FIXME: check with memory config on IGDNG */
1195 +- if (IS_IGDNG(dev)) {
1196 +- DRM_ERROR("disable tiling on IGDNG...\n");
1197 +- swizzle_x = I915_BIT_6_SWIZZLE_UNKNOWN;
1198 +- swizzle_y = I915_BIT_6_SWIZZLE_UNKNOWN;
1199 +- }
1200 +-
1201 + dev_priv->mm.bit_6_swizzle_x = swizzle_x;
1202 + dev_priv->mm.bit_6_swizzle_y = swizzle_y;
1203 + }
1204 +diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
1205 +index 2955083..106a1ae 100644
1206 +--- a/drivers/gpu/drm/i915/i915_reg.h
1207 ++++ b/drivers/gpu/drm/i915/i915_reg.h
1208 +@@ -1733,6 +1733,7 @@
1209 + #define DISPPLANE_NO_LINE_DOUBLE 0
1210 + #define DISPPLANE_STEREO_POLARITY_FIRST 0
1211 + #define DISPPLANE_STEREO_POLARITY_SECOND (1<<18)
1212 ++#define DISPPLANE_TRICKLE_FEED_DISABLE (1<<14) /* IGDNG */
1213 + #define DISPPLANE_TILED (1<<10)
1214 + #define DSPAADDR 0x70184
1215 + #define DSPASTRIDE 0x70188
1216 +@@ -1867,6 +1868,8 @@
1217 + #define PF_ENABLE (1<<31)
1218 + #define PFA_WIN_SZ 0x68074
1219 + #define PFB_WIN_SZ 0x68874
1220 ++#define PFA_WIN_POS 0x68070
1221 ++#define PFB_WIN_POS 0x68870
1222 +
1223 + /* legacy palette */
1224 + #define LGC_PALETTE_A 0x4a000
1225 +@@ -1913,6 +1916,9 @@
1226 + #define GTIIR 0x44018
1227 + #define GTIER 0x4401c
1228 +
1229 ++#define DISP_ARB_CTL 0x45000
1230 ++#define DISP_TILE_SURFACE_SWIZZLING (1<<13)
1231 ++
1232 + /* PCH */
1233 +
1234 + /* south display engine interrupt */
1235 +diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
1236 +index f806fcc..698a0ed 100644
1237 +--- a/drivers/gpu/drm/i915/intel_bios.c
1238 ++++ b/drivers/gpu/drm/i915/intel_bios.c
1239 +@@ -217,6 +217,9 @@ parse_general_features(struct drm_i915_private *dev_priv,
1240 + if (IS_I85X(dev_priv->dev))
1241 + dev_priv->lvds_ssc_freq =
1242 + general->ssc_freq ? 66 : 48;
1243 ++ else if (IS_IGDNG(dev_priv->dev))
1244 ++ dev_priv->lvds_ssc_freq =
1245 ++ general->ssc_freq ? 100 : 120;
1246 + else
1247 + dev_priv->lvds_ssc_freq =
1248 + general->ssc_freq ? 100 : 96;
1249 +diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
1250 +index 590f81c..5ae4c1a 100644
1251 +--- a/drivers/gpu/drm/i915/intel_crt.c
1252 ++++ b/drivers/gpu/drm/i915/intel_crt.c
1253 +@@ -151,13 +151,10 @@ static bool intel_igdng_crt_detect_hotplug(struct drm_connector *connector)
1254 + {
1255 + struct drm_device *dev = connector->dev;
1256 + struct drm_i915_private *dev_priv = dev->dev_private;
1257 +- u32 adpa, temp;
1258 ++ u32 adpa;
1259 + bool ret;
1260 +
1261 +- temp = adpa = I915_READ(PCH_ADPA);
1262 +-
1263 +- adpa &= ~ADPA_DAC_ENABLE;
1264 +- I915_WRITE(PCH_ADPA, adpa);
1265 ++ adpa = I915_READ(PCH_ADPA);
1266 +
1267 + adpa &= ~ADPA_CRT_HOTPLUG_MASK;
1268 +
1269 +@@ -184,8 +181,6 @@ static bool intel_igdng_crt_detect_hotplug(struct drm_connector *connector)
1270 + else
1271 + ret = false;
1272 +
1273 +- /* restore origin register */
1274 +- I915_WRITE(PCH_ADPA, temp);
1275 + return ret;
1276 + }
1277 +
1278 +diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
1279 +index 748ed50..8b5af29 100644
1280 +--- a/drivers/gpu/drm/i915/intel_display.c
1281 ++++ b/drivers/gpu/drm/i915/intel_display.c
1282 +@@ -818,7 +818,7 @@ intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
1283 + refclk, best_clock);
1284 +
1285 + if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
1286 +- if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
1287 ++ if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) ==
1288 + LVDS_CLKB_POWER_UP)
1289 + clock.p2 = limit->p2.p2_fast;
1290 + else
1291 +@@ -1008,6 +1008,10 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
1292 + dspcntr &= ~DISPPLANE_TILED;
1293 + }
1294 +
1295 ++ if (IS_IGDNG(dev))
1296 ++ /* must disable */
1297 ++ dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
1298 ++
1299 + I915_WRITE(dspcntr_reg, dspcntr);
1300 +
1301 + Start = obj_priv->gtt_offset;
1302 +@@ -1154,6 +1158,7 @@ static void igdng_crtc_dpms(struct drm_crtc *crtc, int mode)
1303 + int transconf_reg = (pipe == 0) ? TRANSACONF : TRANSBCONF;
1304 + int pf_ctl_reg = (pipe == 0) ? PFA_CTL_1 : PFB_CTL_1;
1305 + int pf_win_size = (pipe == 0) ? PFA_WIN_SZ : PFB_WIN_SZ;
1306 ++ int pf_win_pos = (pipe == 0) ? PFA_WIN_POS : PFB_WIN_POS;
1307 + int cpu_htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
1308 + int cpu_hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
1309 + int cpu_hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
1310 +@@ -1205,6 +1210,19 @@ static void igdng_crtc_dpms(struct drm_crtc *crtc, int mode)
1311 + }
1312 + }
1313 +
1314 ++ /* Enable panel fitting for LVDS */
1315 ++ if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
1316 ++ temp = I915_READ(pf_ctl_reg);
1317 ++ I915_WRITE(pf_ctl_reg, temp | PF_ENABLE);
1318 ++
1319 ++ /* currently full aspect */
1320 ++ I915_WRITE(pf_win_pos, 0);
1321 ++
1322 ++ I915_WRITE(pf_win_size,
1323 ++ (dev_priv->panel_fixed_mode->hdisplay << 16) |
1324 ++ (dev_priv->panel_fixed_mode->vdisplay));
1325 ++ }
1326 ++
1327 + /* Enable CPU pipe */
1328 + temp = I915_READ(pipeconf_reg);
1329 + if ((temp & PIPEACONF_ENABLE) == 0) {
1330 +@@ -1858,7 +1876,14 @@ static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
1331 + {
1332 + long entries_required, wm_size;
1333 +
1334 +- entries_required = (clock_in_khz * pixel_size * latency_ns) / 1000000;
1335 ++ /*
1336 ++ * Note: we need to make sure we don't overflow for various clock &
1337 ++ * latency values.
1338 ++ * clocks go from a few thousand to several hundred thousand.
1339 ++ * latency is usually a few thousand
1340 ++ */
1341 ++ entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
1342 ++ 1000;
1343 + entries_required /= wm->cacheline_size;
1344 +
1345 + DRM_DEBUG("FIFO entries required for mode: %d\n", entries_required);
1346 +@@ -2616,6 +2641,12 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1347 +
1348 + intel_wait_for_vblank(dev);
1349 +
1350 ++ if (IS_IGDNG(dev)) {
1351 ++ /* enable address swizzle for tiling buffer */
1352 ++ temp = I915_READ(DISP_ARB_CTL);
1353 ++ I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
1354 ++ }
1355 ++
1356 + I915_WRITE(dspcntr_reg, dspcntr);
1357 +
1358 + /* Flush the plane changes */
1359 +diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
1360 +index 8df02ef..b7d091b 100644
1361 +--- a/drivers/gpu/drm/i915/intel_lvds.c
1362 ++++ b/drivers/gpu/drm/i915/intel_lvds.c
1363 +@@ -305,6 +305,10 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
1364 + goto out;
1365 + }
1366 +
1367 ++ /* full screen scale for now */
1368 ++ if (IS_IGDNG(dev))
1369 ++ goto out;
1370 ++
1371 + /* 965+ wants fuzzy fitting */
1372 + if (IS_I965G(dev))
1373 + pfit_control |= (intel_crtc->pipe << PFIT_PIPE_SHIFT) |
1374 +@@ -332,8 +336,10 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
1375 + * to register description and PRM.
1376 + * Change the value here to see the borders for debugging
1377 + */
1378 +- I915_WRITE(BCLRPAT_A, 0);
1379 +- I915_WRITE(BCLRPAT_B, 0);
1380 ++ if (!IS_IGDNG(dev)) {
1381 ++ I915_WRITE(BCLRPAT_A, 0);
1382 ++ I915_WRITE(BCLRPAT_B, 0);
1383 ++ }
1384 +
1385 + switch (lvds_priv->fitting_mode) {
1386 + case DRM_MODE_SCALE_NO_SCALE:
1387 +@@ -582,7 +588,6 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder,
1388 + * settings.
1389 + */
1390 +
1391 +- /* No panel fitting yet, fixme */
1392 + if (IS_IGDNG(dev))
1393 + return;
1394 +
1395 +diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
1396 +index d3b74ba..66dc1a5 100644
1397 +--- a/drivers/gpu/drm/i915/intel_sdvo.c
1398 ++++ b/drivers/gpu/drm/i915/intel_sdvo.c
1399 +@@ -114,6 +114,9 @@ struct intel_sdvo_priv {
1400 + /* DDC bus used by this SDVO output */
1401 + uint8_t ddc_bus;
1402 +
1403 ++ /* Mac mini hack -- use the same DDC as the analog connector */
1404 ++ struct i2c_adapter *analog_ddc_bus;
1405 ++
1406 + int save_sdvo_mult;
1407 + u16 save_active_outputs;
1408 + struct intel_sdvo_dtd save_input_dtd_1, save_input_dtd_2;
1409 +@@ -1478,6 +1481,36 @@ intel_sdvo_multifunc_encoder(struct intel_output *intel_output)
1410 + return (caps > 1);
1411 + }
1412 +
1413 ++static struct drm_connector *
1414 ++intel_find_analog_connector(struct drm_device *dev)
1415 ++{
1416 ++ struct drm_connector *connector;
1417 ++ struct intel_output *intel_output;
1418 ++
1419 ++ list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1420 ++ intel_output = to_intel_output(connector);
1421 ++ if (intel_output->type == INTEL_OUTPUT_ANALOG)
1422 ++ return connector;
1423 ++ }
1424 ++ return NULL;
1425 ++}
1426 ++
1427 ++static int
1428 ++intel_analog_is_connected(struct drm_device *dev)
1429 ++{
1430 ++ struct drm_connector *analog_connector;
1431 ++ analog_connector = intel_find_analog_connector(dev);
1432 ++
1433 ++ if (!analog_connector)
1434 ++ return false;
1435 ++
1436 ++ if (analog_connector->funcs->detect(analog_connector) ==
1437 ++ connector_status_disconnected)
1438 ++ return false;
1439 ++
1440 ++ return true;
1441 ++}
1442 ++
1443 + enum drm_connector_status
1444 + intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
1445 + {
1446 +@@ -1488,6 +1521,15 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
1447 +
1448 + edid = drm_get_edid(&intel_output->base,
1449 + intel_output->ddc_bus);
1450 ++
1451 ++ /* when there is no edid and no monitor is connected with VGA
1452 ++ * port, try to use the CRT ddc to read the EDID for DVI-connector
1453 ++ */
1454 ++ if (edid == NULL &&
1455 ++ sdvo_priv->analog_ddc_bus &&
1456 ++ !intel_analog_is_connected(intel_output->base.dev))
1457 ++ edid = drm_get_edid(&intel_output->base,
1458 ++ sdvo_priv->analog_ddc_bus);
1459 + if (edid != NULL) {
1460 + /* Don't report the output as connected if it's a DVI-I
1461 + * connector with a non-digital EDID coming out.
1462 +@@ -1540,31 +1582,32 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect
1463 + static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
1464 + {
1465 + struct intel_output *intel_output = to_intel_output(connector);
1466 ++ struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1467 ++ int num_modes;
1468 +
1469 + /* set the bus switch and get the modes */
1470 +- intel_ddc_get_modes(intel_output);
1471 ++ num_modes = intel_ddc_get_modes(intel_output);
1472 +
1473 +-#if 0
1474 +- struct drm_device *dev = encoder->dev;
1475 +- struct drm_i915_private *dev_priv = dev->dev_private;
1476 +- /* Mac mini hack. On this device, I get DDC through the analog, which
1477 +- * load-detects as disconnected. I fail to DDC through the SDVO DDC,
1478 +- * but it does load-detect as connected. So, just steal the DDC bits
1479 +- * from analog when we fail at finding it the right way.
1480 ++ /*
1481 ++ * Mac mini hack. On this device, the DVI-I connector shares one DDC
1482 ++ * link between analog and digital outputs. So, if the regular SDVO
1483 ++ * DDC fails, check to see if the analog output is disconnected, in
1484 ++ * which case we'll look there for the digital DDC data.
1485 + */
1486 +- crt = xf86_config->output[0];
1487 +- intel_output = crt->driver_private;
1488 +- if (intel_output->type == I830_OUTPUT_ANALOG &&
1489 +- crt->funcs->detect(crt) == XF86OutputStatusDisconnected) {
1490 +- I830I2CInit(pScrn, &intel_output->pDDCBus, GPIOA, "CRTDDC_A");
1491 +- edid_mon = xf86OutputGetEDID(crt, intel_output->pDDCBus);
1492 +- xf86DestroyI2CBusRec(intel_output->pDDCBus, true, true);
1493 +- }
1494 +- if (edid_mon) {
1495 +- xf86OutputSetEDID(output, edid_mon);
1496 +- modes = xf86OutputGetEDIDModes(output);
1497 ++ if (num_modes == 0 &&
1498 ++ sdvo_priv->analog_ddc_bus &&
1499 ++ !intel_analog_is_connected(intel_output->base.dev)) {
1500 ++ struct i2c_adapter *digital_ddc_bus;
1501 ++
1502 ++ /* Switch to the analog ddc bus and try that
1503 ++ */
1504 ++ digital_ddc_bus = intel_output->ddc_bus;
1505 ++ intel_output->ddc_bus = sdvo_priv->analog_ddc_bus;
1506 ++
1507 ++ (void) intel_ddc_get_modes(intel_output);
1508 ++
1509 ++ intel_output->ddc_bus = digital_ddc_bus;
1510 + }
1511 +-#endif
1512 + }
1513 +
1514 + /**
1515 +@@ -1748,6 +1791,8 @@ static void intel_sdvo_destroy(struct drm_connector *connector)
1516 + intel_i2c_destroy(intel_output->i2c_bus);
1517 + if (intel_output->ddc_bus)
1518 + intel_i2c_destroy(intel_output->ddc_bus);
1519 ++ if (sdvo_priv->analog_ddc_bus)
1520 ++ intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
1521 +
1522 + if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
1523 + drm_mode_destroy(connector->dev,
1524 +@@ -2074,10 +2119,15 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1525 + }
1526 +
1527 + /* setup the DDC bus. */
1528 +- if (output_device == SDVOB)
1529 ++ if (output_device == SDVOB) {
1530 + intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
1531 +- else
1532 ++ sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
1533 ++ "SDVOB/VGA DDC BUS");
1534 ++ } else {
1535 + intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
1536 ++ sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
1537 ++ "SDVOC/VGA DDC BUS");
1538 ++ }
1539 +
1540 + if (intel_output->ddc_bus == NULL)
1541 + goto err_i2c;
1542 +@@ -2143,6 +2193,8 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1543 + return true;
1544 +
1545 + err_i2c:
1546 ++ if (sdvo_priv->analog_ddc_bus != NULL)
1547 ++ intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
1548 + if (intel_output->ddc_bus != NULL)
1549 + intel_i2c_destroy(intel_output->ddc_bus);
1550 + if (intel_output->i2c_bus != NULL)
1551 +diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
1552 +index 5eb10c2..047844d 100644
1553 +--- a/drivers/hid/hid-core.c
1554 ++++ b/drivers/hid/hid-core.c
1555 +@@ -1319,7 +1319,6 @@ static const struct hid_device_id hid_blacklist[] = {
1556 + { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1557 + { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1558 +
1559 +- { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 0x030c) },
1560 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
1561 + { }
1562 + };
1563 +diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
1564 +index 8ff7e35..f33ac27 100644
1565 +--- a/drivers/isdn/gigaset/interface.c
1566 ++++ b/drivers/isdn/gigaset/interface.c
1567 +@@ -408,33 +408,28 @@ static int if_write_room(struct tty_struct *tty)
1568 + return retval;
1569 + }
1570 +
1571 +-/* FIXME: This function does not have error returns */
1572 +-
1573 + static int if_chars_in_buffer(struct tty_struct *tty)
1574 + {
1575 + struct cardstate *cs;
1576 +- int retval = -ENODEV;
1577 ++ int retval = 0;
1578 +
1579 + cs = (struct cardstate *) tty->driver_data;
1580 + if (!cs) {
1581 + pr_err("%s: no cardstate\n", __func__);
1582 +- return -ENODEV;
1583 ++ return 0;
1584 + }
1585 +
1586 + gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
1587 +
1588 +- if (mutex_lock_interruptible(&cs->mutex))
1589 +- return -ERESTARTSYS; // FIXME -EINTR?
1590 ++ mutex_lock(&cs->mutex);
1591 +
1592 +- if (!cs->connected) {
1593 ++ if (!cs->connected)
1594 + gig_dbg(DEBUG_IF, "not connected");
1595 +- retval = -ENODEV;
1596 +- } else if (!cs->open_count)
1597 ++ else if (!cs->open_count)
1598 + dev_warn(cs->dev, "%s: device not opened\n", __func__);
1599 +- else if (cs->mstate != MS_LOCKED) {
1600 ++ else if (cs->mstate != MS_LOCKED)
1601 + dev_warn(cs->dev, "can't write to unlocked device\n");
1602 +- retval = -EBUSY;
1603 +- } else
1604 ++ else
1605 + retval = cs->ops->chars_in_buffer(cs);
1606 +
1607 + mutex_unlock(&cs->mutex);
1608 +diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
1609 +index 1c2e544..ffe9306 100644
1610 +--- a/drivers/media/video/em28xx/em28xx-cards.c
1611 ++++ b/drivers/media/video/em28xx/em28xx-cards.c
1612 +@@ -2170,8 +2170,6 @@ static int em28xx_hint_board(struct em28xx *dev)
1613 + /* ----------------------------------------------------------------------- */
1614 + void em28xx_register_i2c_ir(struct em28xx *dev)
1615 + {
1616 +- struct i2c_board_info info;
1617 +- struct IR_i2c_init_data init_data;
1618 + const unsigned short addr_list[] = {
1619 + 0x30, 0x47, I2C_CLIENT_END
1620 + };
1621 +@@ -2179,9 +2177,9 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
1622 + if (disable_ir)
1623 + return;
1624 +
1625 +- memset(&info, 0, sizeof(struct i2c_board_info));
1626 +- memset(&init_data, 0, sizeof(struct IR_i2c_init_data));
1627 +- strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
1628 ++ memset(&dev->info, 0, sizeof(&dev->info));
1629 ++ memset(&dev->init_data, 0, sizeof(dev->init_data));
1630 ++ strlcpy(dev->info.type, "ir_video", I2C_NAME_SIZE);
1631 +
1632 + /* detect & configure */
1633 + switch (dev->model) {
1634 +@@ -2191,19 +2189,19 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
1635 + break;
1636 + case (EM2800_BOARD_TERRATEC_CINERGY_200):
1637 + case (EM2820_BOARD_TERRATEC_CINERGY_250):
1638 +- init_data.ir_codes = ir_codes_em_terratec;
1639 +- init_data.get_key = em28xx_get_key_terratec;
1640 +- init_data.name = "i2c IR (EM28XX Terratec)";
1641 ++ dev->init_data.ir_codes = ir_codes_em_terratec;
1642 ++ dev->init_data.get_key = em28xx_get_key_terratec;
1643 ++ dev->init_data.name = "i2c IR (EM28XX Terratec)";
1644 + break;
1645 + case (EM2820_BOARD_PINNACLE_USB_2):
1646 +- init_data.ir_codes = ir_codes_pinnacle_grey;
1647 +- init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
1648 +- init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
1649 ++ dev->init_data.ir_codes = ir_codes_pinnacle_grey;
1650 ++ dev->init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
1651 ++ dev->init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
1652 + break;
1653 + case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
1654 +- init_data.ir_codes = ir_codes_hauppauge_new;
1655 +- init_data.get_key = em28xx_get_key_em_haup;
1656 +- init_data.name = "i2c IR (EM2840 Hauppauge)";
1657 ++ dev->init_data.ir_codes = ir_codes_hauppauge_new;
1658 ++ dev->init_data.get_key = em28xx_get_key_em_haup;
1659 ++ dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
1660 + break;
1661 + case (EM2820_BOARD_MSI_VOX_USB_2):
1662 + break;
1663 +@@ -2215,9 +2213,9 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
1664 + break;
1665 + }
1666 +
1667 +- if (init_data.name)
1668 +- info.platform_data = &init_data;
1669 +- i2c_new_probed_device(&dev->i2c_adap, &info, addr_list);
1670 ++ if (dev->init_data.name)
1671 ++ dev->info.platform_data = &dev->init_data;
1672 ++ i2c_new_probed_device(&dev->i2c_adap, &dev->info, addr_list);
1673 + }
1674 +
1675 + void em28xx_card_setup(struct em28xx *dev)
1676 +diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
1677 +index a2add61..cb2a70a 100644
1678 +--- a/drivers/media/video/em28xx/em28xx.h
1679 ++++ b/drivers/media/video/em28xx/em28xx.h
1680 +@@ -595,6 +595,10 @@ struct em28xx {
1681 + struct delayed_work sbutton_query_work;
1682 +
1683 + struct em28xx_dvb *dvb;
1684 ++
1685 ++ /* I2C keyboard data */
1686 ++ struct i2c_board_info info;
1687 ++ struct IR_i2c_init_data init_data;
1688 + };
1689 +
1690 + struct em28xx_ops {
1691 +diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
1692 +index 6e219c2..69e48ce 100644
1693 +--- a/drivers/media/video/saa7134/saa7134-input.c
1694 ++++ b/drivers/media/video/saa7134/saa7134-input.c
1695 +@@ -684,8 +684,6 @@ void saa7134_input_fini(struct saa7134_dev *dev)
1696 +
1697 + void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
1698 + {
1699 +- struct i2c_board_info info;
1700 +- struct IR_i2c_init_data init_data;
1701 + const unsigned short addr_list[] = {
1702 + 0x7a, 0x47, 0x71, 0x2d,
1703 + I2C_CLIENT_END
1704 +@@ -705,32 +703,32 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
1705 + return;
1706 + }
1707 +
1708 +- memset(&info, 0, sizeof(struct i2c_board_info));
1709 +- memset(&init_data, 0, sizeof(struct IR_i2c_init_data));
1710 +- strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
1711 ++ memset(&dev->info, 0, sizeof(dev->info));
1712 ++ memset(&dev->init_data, 0, sizeof(dev->init_data));
1713 ++ strlcpy(dev->info.type, "ir_video", I2C_NAME_SIZE);
1714 +
1715 + switch (dev->board) {
1716 + case SAA7134_BOARD_PINNACLE_PCTV_110i:
1717 + case SAA7134_BOARD_PINNACLE_PCTV_310i:
1718 +- init_data.name = "Pinnacle PCTV";
1719 ++ dev->init_data.name = "Pinnacle PCTV";
1720 + if (pinnacle_remote == 0) {
1721 +- init_data.get_key = get_key_pinnacle_color;
1722 +- init_data.ir_codes = ir_codes_pinnacle_color;
1723 ++ dev->init_data.get_key = get_key_pinnacle_color;
1724 ++ dev->init_data.ir_codes = ir_codes_pinnacle_color;
1725 + } else {
1726 +- init_data.get_key = get_key_pinnacle_grey;
1727 +- init_data.ir_codes = ir_codes_pinnacle_grey;
1728 ++ dev->init_data.get_key = get_key_pinnacle_grey;
1729 ++ dev->init_data.ir_codes = ir_codes_pinnacle_grey;
1730 + }
1731 + break;
1732 + case SAA7134_BOARD_UPMOST_PURPLE_TV:
1733 +- init_data.name = "Purple TV";
1734 +- init_data.get_key = get_key_purpletv;
1735 +- init_data.ir_codes = ir_codes_purpletv;
1736 ++ dev->init_data.name = "Purple TV";
1737 ++ dev->init_data.get_key = get_key_purpletv;
1738 ++ dev->init_data.ir_codes = ir_codes_purpletv;
1739 + break;
1740 + case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
1741 +- init_data.name = "MSI TV@nywhere Plus";
1742 +- init_data.get_key = get_key_msi_tvanywhere_plus;
1743 +- init_data.ir_codes = ir_codes_msi_tvanywhere_plus;
1744 +- info.addr = 0x30;
1745 ++ dev->init_data.name = "MSI TV@nywhere Plus";
1746 ++ dev->init_data.get_key = get_key_msi_tvanywhere_plus;
1747 ++ dev->init_data.ir_codes = ir_codes_msi_tvanywhere_plus;
1748 ++ dev->info.addr = 0x30;
1749 + /* MSI TV@nywhere Plus controller doesn't seem to
1750 + respond to probes unless we read something from
1751 + an existing device. Weird...
1752 +@@ -741,9 +739,9 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
1753 + (1 == rc) ? "yes" : "no");
1754 + break;
1755 + case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1756 +- init_data.name = "HVR 1110";
1757 +- init_data.get_key = get_key_hvr1110;
1758 +- init_data.ir_codes = ir_codes_hauppauge_new;
1759 ++ dev->init_data.name = "HVR 1110";
1760 ++ dev->init_data.get_key = get_key_hvr1110;
1761 ++ dev->init_data.ir_codes = ir_codes_hauppauge_new;
1762 + break;
1763 + case SAA7134_BOARD_BEHOLD_607FM_MK3:
1764 + case SAA7134_BOARD_BEHOLD_607FM_MK5:
1765 +@@ -757,26 +755,26 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
1766 + case SAA7134_BOARD_BEHOLD_M63:
1767 + case SAA7134_BOARD_BEHOLD_M6_EXTRA:
1768 + case SAA7134_BOARD_BEHOLD_H6:
1769 +- init_data.name = "BeholdTV";
1770 +- init_data.get_key = get_key_beholdm6xx;
1771 +- init_data.ir_codes = ir_codes_behold;
1772 ++ dev->init_data.name = "BeholdTV";
1773 ++ dev->init_data.get_key = get_key_beholdm6xx;
1774 ++ dev->init_data.ir_codes = ir_codes_behold;
1775 + break;
1776 + case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
1777 + case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1778 +- info.addr = 0x40;
1779 ++ dev->info.addr = 0x40;
1780 + break;
1781 + }
1782 +
1783 +- if (init_data.name)
1784 +- info.platform_data = &init_data;
1785 ++ if (dev->init_data.name)
1786 ++ dev->info.platform_data = &dev->init_data;
1787 + /* No need to probe if address is known */
1788 +- if (info.addr) {
1789 +- i2c_new_device(&dev->i2c_adap, &info);
1790 ++ if (dev->info.addr) {
1791 ++ i2c_new_device(&dev->i2c_adap, &dev->info);
1792 + return;
1793 + }
1794 +
1795 + /* Address not known, fallback to probing */
1796 +- i2c_new_probed_device(&dev->i2c_adap, &info, addr_list);
1797 ++ i2c_new_probed_device(&dev->i2c_adap, &dev->info, addr_list);
1798 + }
1799 +
1800 + static int saa7134_rc5_irq(struct saa7134_dev *dev)
1801 +diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
1802 +index fb564f1..4d85f5c 100644
1803 +--- a/drivers/media/video/saa7134/saa7134.h
1804 ++++ b/drivers/media/video/saa7134/saa7134.h
1805 +@@ -584,6 +584,10 @@ struct saa7134_dev {
1806 + int nosignal;
1807 + unsigned int insuspend;
1808 +
1809 ++ /* I2C keyboard data */
1810 ++ struct i2c_board_info info;
1811 ++ struct IR_i2c_init_data init_data;
1812 ++
1813 + /* SAA7134_MPEG_* */
1814 + struct saa7134_ts ts;
1815 + struct saa7134_dmaqueue ts_q;
1816 +diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
1817 +index 5d0ba4f..9ad7bb4 100644
1818 +--- a/drivers/message/fusion/mptbase.c
1819 ++++ b/drivers/message/fusion/mptbase.c
1820 +@@ -1015,9 +1015,9 @@ mpt_add_sge_64bit(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
1821 + {
1822 + SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
1823 + pSge->Address.Low = cpu_to_le32
1824 +- (lower_32_bits((unsigned long)(dma_addr)));
1825 ++ (lower_32_bits(dma_addr));
1826 + pSge->Address.High = cpu_to_le32
1827 +- (upper_32_bits((unsigned long)dma_addr));
1828 ++ (upper_32_bits(dma_addr));
1829 + pSge->FlagsLength = cpu_to_le32
1830 + ((flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
1831 + }
1832 +@@ -1038,8 +1038,8 @@ mpt_add_sge_64bit_1078(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
1833 + u32 tmp;
1834 +
1835 + pSge->Address.Low = cpu_to_le32
1836 +- (lower_32_bits((unsigned long)(dma_addr)));
1837 +- tmp = (u32)(upper_32_bits((unsigned long)dma_addr));
1838 ++ (lower_32_bits(dma_addr));
1839 ++ tmp = (u32)(upper_32_bits(dma_addr));
1840 +
1841 + /*
1842 + * 1078 errata workaround for the 36GB limitation
1843 +@@ -1101,7 +1101,7 @@ mpt_add_chain_64bit(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
1844 + pChain->NextChainOffset = next;
1845 +
1846 + pChain->Address.Low = cpu_to_le32(tmp);
1847 +- tmp = (u32)(upper_32_bits((unsigned long)dma_addr));
1848 ++ tmp = (u32)(upper_32_bits(dma_addr));
1849 + pChain->Address.High = cpu_to_le32(tmp);
1850 + }
1851 +
1852 +diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
1853 +index 13e7d7b..dd8b6b3 100644
1854 +--- a/drivers/mfd/ab3100-core.c
1855 ++++ b/drivers/mfd/ab3100-core.c
1856 +@@ -643,7 +643,7 @@ struct ab3100_init_setting {
1857 + u8 setting;
1858 + };
1859 +
1860 +-static const struct ab3100_init_setting __initdata
1861 ++static const struct ab3100_init_setting __initconst
1862 + ab3100_init_settings[] = {
1863 + {
1864 + .abreg = AB3100_MCA,
1865 +diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
1866 +index 06084db..72f2df1 100644
1867 +--- a/drivers/mmc/core/mmc.c
1868 ++++ b/drivers/mmc/core/mmc.c
1869 +@@ -180,11 +180,11 @@ static int mmc_read_ext_csd(struct mmc_card *card)
1870 +
1871 + err = mmc_send_ext_csd(card, ext_csd);
1872 + if (err) {
1873 +- /*
1874 +- * We all hosts that cannot perform the command
1875 +- * to fail more gracefully
1876 +- */
1877 +- if (err != -EINVAL)
1878 ++ /* If the host or the card can't do the switch,
1879 ++ * fail more gracefully. */
1880 ++ if ((err != -EINVAL)
1881 ++ && (err != -ENOSYS)
1882 ++ && (err != -EFAULT))
1883 + goto out;
1884 +
1885 + /*
1886 +diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
1887 +index cd81c39..65c32bf 100644
1888 +--- a/drivers/mmc/core/sd.c
1889 ++++ b/drivers/mmc/core/sd.c
1890 +@@ -210,11 +210,11 @@ static int mmc_read_switch(struct mmc_card *card)
1891 +
1892 + err = mmc_sd_switch(card, 0, 0, 1, status);
1893 + if (err) {
1894 +- /*
1895 +- * We all hosts that cannot perform the command
1896 +- * to fail more gracefully
1897 +- */
1898 +- if (err != -EINVAL)
1899 ++ /* If the host or the card can't do the switch,
1900 ++ * fail more gracefully. */
1901 ++ if ((err != -EINVAL)
1902 ++ && (err != -ENOSYS)
1903 ++ && (err != -EFAULT))
1904 + goto out;
1905 +
1906 + printk(KERN_WARNING "%s: problem reading switch "
1907 +diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
1908 +index 61ea833..94bb61e 100644
1909 +--- a/drivers/mtd/chips/cfi_cmdset_0002.c
1910 ++++ b/drivers/mtd/chips/cfi_cmdset_0002.c
1911 +@@ -282,16 +282,6 @@ static void fixup_s29gl032n_sectors(struct mtd_info *mtd, void *param)
1912 + }
1913 + }
1914 +
1915 +-static void fixup_M29W128G_write_buffer(struct mtd_info *mtd, void *param)
1916 +-{
1917 +- struct map_info *map = mtd->priv;
1918 +- struct cfi_private *cfi = map->fldrv_priv;
1919 +- if (cfi->cfiq->BufWriteTimeoutTyp) {
1920 +- pr_warning("Don't use write buffer on ST flash M29W128G\n");
1921 +- cfi->cfiq->BufWriteTimeoutTyp = 0;
1922 +- }
1923 +-}
1924 +-
1925 + static struct cfi_fixup cfi_fixup_table[] = {
1926 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
1927 + #ifdef AMD_BOOTLOC_BUG
1928 +@@ -308,7 +298,6 @@ static struct cfi_fixup cfi_fixup_table[] = {
1929 + { CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors, NULL, },
1930 + { CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors, NULL, },
1931 + { CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors, NULL, },
1932 +- { CFI_MFR_ST, 0x227E, fixup_M29W128G_write_buffer, NULL, },
1933 + #if !FORCE_WORD_WRITE
1934 + { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
1935 + #endif
1936 +diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c
1937 +index 34d40e2..c5a84fd 100644
1938 +--- a/drivers/mtd/chips/cfi_util.c
1939 ++++ b/drivers/mtd/chips/cfi_util.c
1940 +@@ -81,6 +81,10 @@ void __xipram cfi_qry_mode_off(uint32_t base, struct map_info *map,
1941 + {
1942 + cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
1943 + cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL);
1944 ++ /* M29W128G flashes require an additional reset command
1945 ++ when exit qry mode */
1946 ++ if ((cfi->mfr == CFI_MFR_ST) && (cfi->id == 0x227E || cfi->id == 0x7E))
1947 ++ cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
1948 + }
1949 + EXPORT_SYMBOL_GPL(cfi_qry_mode_off);
1950 +
1951 +diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
1952 +index 89bf85a..40b5658 100644
1953 +--- a/drivers/mtd/nand/ndfc.c
1954 ++++ b/drivers/mtd/nand/ndfc.c
1955 +@@ -102,8 +102,8 @@ static int ndfc_calculate_ecc(struct mtd_info *mtd,
1956 + wmb();
1957 + ecc = in_be32(ndfc->ndfcbase + NDFC_ECC);
1958 + /* The NDFC uses Smart Media (SMC) bytes order */
1959 +- ecc_code[0] = p[2];
1960 +- ecc_code[1] = p[1];
1961 ++ ecc_code[0] = p[1];
1962 ++ ecc_code[1] = p[2];
1963 + ecc_code[2] = p[3];
1964 +
1965 + return 0;
1966 +diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
1967 +index 3e164f0..62d6a78 100644
1968 +--- a/drivers/mtd/ofpart.c
1969 ++++ b/drivers/mtd/ofpart.c
1970 +@@ -46,21 +46,12 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
1971 + const u32 *reg;
1972 + int len;
1973 +
1974 +- /* check if this is a partition node */
1975 +- partname = of_get_property(pp, "name", &len);
1976 +- if (strcmp(partname, "partition") != 0) {
1977 ++ reg = of_get_property(pp, "reg", &len);
1978 ++ if (!reg) {
1979 + nr_parts--;
1980 + continue;
1981 + }
1982 +
1983 +- reg = of_get_property(pp, "reg", &len);
1984 +- if (!reg || (len != 2 * sizeof(u32))) {
1985 +- of_node_put(pp);
1986 +- dev_err(dev, "Invalid 'reg' on %s\n", node->full_name);
1987 +- kfree(*pparts);
1988 +- *pparts = NULL;
1989 +- return -EINVAL;
1990 +- }
1991 + (*pparts)[i].offset = reg[0];
1992 + (*pparts)[i].size = reg[1];
1993 +
1994 +@@ -75,6 +66,14 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
1995 + i++;
1996 + }
1997 +
1998 ++ if (!i) {
1999 ++ of_node_put(pp);
2000 ++ dev_err(dev, "No valid partition found on %s\n", node->full_name);
2001 ++ kfree(*pparts);
2002 ++ *pparts = NULL;
2003 ++ return -EINVAL;
2004 ++ }
2005 ++
2006 + return nr_parts;
2007 + }
2008 + EXPORT_SYMBOL(of_mtd_parse_partitions);
2009 +diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
2010 +index a10c1d7..460bb88 100644
2011 +--- a/drivers/net/can/vcan.c
2012 ++++ b/drivers/net/can/vcan.c
2013 +@@ -80,7 +80,7 @@ static void vcan_rx(struct sk_buff *skb, struct net_device *dev)
2014 + skb->dev = dev;
2015 + skb->ip_summed = CHECKSUM_UNNECESSARY;
2016 +
2017 +- netif_rx(skb);
2018 ++ netif_rx_ni(skb);
2019 + }
2020 +
2021 + static int vcan_tx(struct sk_buff *skb, struct net_device *dev)
2022 +diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
2023 +index 1f9ec29..65a43c8 100644
2024 +--- a/drivers/net/usb/kaweth.c
2025 ++++ b/drivers/net/usb/kaweth.c
2026 +@@ -263,6 +263,7 @@ static int kaweth_control(struct kaweth_device *kaweth,
2027 + int timeout)
2028 + {
2029 + struct usb_ctrlrequest *dr;
2030 ++ int retval;
2031 +
2032 + dbg("kaweth_control()");
2033 +
2034 +@@ -278,18 +279,21 @@ static int kaweth_control(struct kaweth_device *kaweth,
2035 + return -ENOMEM;
2036 + }
2037 +
2038 +- dr->bRequestType= requesttype;
2039 ++ dr->bRequestType = requesttype;
2040 + dr->bRequest = request;
2041 + dr->wValue = cpu_to_le16(value);
2042 + dr->wIndex = cpu_to_le16(index);
2043 + dr->wLength = cpu_to_le16(size);
2044 +
2045 +- return kaweth_internal_control_msg(kaweth->dev,
2046 +- pipe,
2047 +- dr,
2048 +- data,
2049 +- size,
2050 +- timeout);
2051 ++ retval = kaweth_internal_control_msg(kaweth->dev,
2052 ++ pipe,
2053 ++ dr,
2054 ++ data,
2055 ++ size,
2056 ++ timeout);
2057 ++
2058 ++ kfree(dr);
2059 ++ return retval;
2060 + }
2061 +
2062 + /****************************************************************
2063 +diff --git a/drivers/net/wireless/ath/ar9170/usb.c b/drivers/net/wireless/ath/ar9170/usb.c
2064 +index 007eb85..1084ca6 100644
2065 +--- a/drivers/net/wireless/ath/ar9170/usb.c
2066 ++++ b/drivers/net/wireless/ath/ar9170/usb.c
2067 +@@ -64,6 +64,8 @@ static struct usb_device_id ar9170_usb_ids[] = {
2068 + { USB_DEVICE(0x0cf3, 0x9170) },
2069 + /* Atheros TG121N */
2070 + { USB_DEVICE(0x0cf3, 0x1001) },
2071 ++ /* TP-Link TL-WN821N v2 */
2072 ++ { USB_DEVICE(0x0cf3, 0x1002) },
2073 + /* Cace Airpcap NX */
2074 + { USB_DEVICE(0xcace, 0x0300) },
2075 + /* D-Link DWA 160A */
2076 +diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h
2077 +index 6358233..778baf7 100644
2078 +--- a/drivers/net/wireless/ath/ath5k/ath5k.h
2079 ++++ b/drivers/net/wireless/ath/ath5k/ath5k.h
2080 +@@ -1164,6 +1164,7 @@ extern void ath5k_unregister_leds(struct ath5k_softc *sc);
2081 +
2082 + /* Reset Functions */
2083 + extern int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial);
2084 ++extern int ath5k_hw_on_hold(struct ath5k_hw *ah);
2085 + extern int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode, struct ieee80211_channel *channel, bool change_channel);
2086 + /* Power management functions */
2087 + extern int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode, bool set_chip, u16 sleep_duration);
2088 +diff --git a/drivers/net/wireless/ath/ath5k/attach.c b/drivers/net/wireless/ath/ath5k/attach.c
2089 +index c41ef58..605b8f6 100644
2090 +--- a/drivers/net/wireless/ath/ath5k/attach.c
2091 ++++ b/drivers/net/wireless/ath/ath5k/attach.c
2092 +@@ -145,7 +145,7 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
2093 + goto err_free;
2094 +
2095 + /* Bring device out of sleep and reset it's units */
2096 +- ret = ath5k_hw_nic_wakeup(ah, CHANNEL_B, true);
2097 ++ ret = ath5k_hw_nic_wakeup(ah, 0, true);
2098 + if (ret)
2099 + goto err_free;
2100 +
2101 +diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
2102 +index ba6d225..753f50e 100644
2103 +--- a/drivers/net/wireless/ath/ath5k/base.c
2104 ++++ b/drivers/net/wireless/ath/ath5k/base.c
2105 +@@ -666,7 +666,6 @@ ath5k_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2106 +
2107 + ath5k_led_off(sc);
2108 +
2109 +- free_irq(pdev->irq, sc);
2110 + pci_save_state(pdev);
2111 + pci_disable_device(pdev);
2112 + pci_set_power_state(pdev, PCI_D3hot);
2113 +@@ -694,18 +693,8 @@ ath5k_pci_resume(struct pci_dev *pdev)
2114 + */
2115 + pci_write_config_byte(pdev, 0x41, 0);
2116 +
2117 +- err = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc);
2118 +- if (err) {
2119 +- ATH5K_ERR(sc, "request_irq failed\n");
2120 +- goto err_no_irq;
2121 +- }
2122 +-
2123 + ath5k_led_enable(sc);
2124 + return 0;
2125 +-
2126 +-err_no_irq:
2127 +- pci_disable_device(pdev);
2128 +- return err;
2129 + }
2130 + #endif /* CONFIG_PM */
2131 +
2132 +@@ -2445,27 +2434,29 @@ ath5k_stop_hw(struct ath5k_softc *sc)
2133 + ret = ath5k_stop_locked(sc);
2134 + if (ret == 0 && !test_bit(ATH_STAT_INVALID, sc->status)) {
2135 + /*
2136 +- * Set the chip in full sleep mode. Note that we are
2137 +- * careful to do this only when bringing the interface
2138 +- * completely to a stop. When the chip is in this state
2139 +- * it must be carefully woken up or references to
2140 +- * registers in the PCI clock domain may freeze the bus
2141 +- * (and system). This varies by chip and is mostly an
2142 +- * issue with newer parts that go to sleep more quickly.
2143 +- */
2144 +- if (sc->ah->ah_mac_srev >= 0x78) {
2145 +- /*
2146 +- * XXX
2147 +- * don't put newer MAC revisions > 7.8 to sleep because
2148 +- * of the above mentioned problems
2149 +- */
2150 +- ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "mac version > 7.8, "
2151 +- "not putting device to sleep\n");
2152 +- } else {
2153 +- ATH5K_DBG(sc, ATH5K_DEBUG_RESET,
2154 +- "putting device to full sleep\n");
2155 +- ath5k_hw_set_power(sc->ah, AR5K_PM_FULL_SLEEP, true, 0);
2156 +- }
2157 ++ * Don't set the card in full sleep mode!
2158 ++ *
2159 ++ * a) When the device is in this state it must be carefully
2160 ++ * woken up or references to registers in the PCI clock
2161 ++ * domain may freeze the bus (and system). This varies
2162 ++ * by chip and is mostly an issue with newer parts
2163 ++ * (madwifi sources mentioned srev >= 0x78) that go to
2164 ++ * sleep more quickly.
2165 ++ *
2166 ++ * b) On older chips full sleep results a weird behaviour
2167 ++ * during wakeup. I tested various cards with srev < 0x78
2168 ++ * and they don't wake up after module reload, a second
2169 ++ * module reload is needed to bring the card up again.
2170 ++ *
2171 ++ * Until we figure out what's going on don't enable
2172 ++ * full chip reset on any chip (this is what Legacy HAL
2173 ++ * and Sam's HAL do anyway). Instead Perform a full reset
2174 ++ * on the device (same as initial state after attach) and
2175 ++ * leave it idle (keep MAC/BB on warm reset) */
2176 ++ ret = ath5k_hw_on_hold(sc->ah);
2177 ++
2178 ++ ATH5K_DBG(sc, ATH5K_DEBUG_RESET,
2179 ++ "putting device to sleep\n");
2180 + }
2181 + ath5k_txbuf_free(sc, sc->bbuf);
2182 +
2183 +diff --git a/drivers/net/wireless/ath/ath5k/reset.c b/drivers/net/wireless/ath/ath5k/reset.c
2184 +index bd0a97a..4980621 100644
2185 +--- a/drivers/net/wireless/ath/ath5k/reset.c
2186 ++++ b/drivers/net/wireless/ath/ath5k/reset.c
2187 +@@ -258,29 +258,35 @@ int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
2188 + if (!set_chip)
2189 + goto commit;
2190 +
2191 +- /* Preserve sleep duration */
2192 + data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
2193 ++
2194 ++ /* If card is down we 'll get 0xffff... so we
2195 ++ * need to clean this up before we write the register
2196 ++ */
2197 + if (data & 0xffc00000)
2198 + data = 0;
2199 + else
2200 +- data = data & 0xfffcffff;
2201 ++ /* Preserve sleep duration etc */
2202 ++ data = data & ~AR5K_SLEEP_CTL_SLE;
2203 +
2204 +- ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
2205 ++ ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
2206 ++ AR5K_SLEEP_CTL);
2207 + udelay(15);
2208 +
2209 +- for (i = 50; i > 0; i--) {
2210 ++ for (i = 200; i > 0; i--) {
2211 + /* Check if the chip did wake up */
2212 + if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
2213 + AR5K_PCICFG_SPWR_DN) == 0)
2214 + break;
2215 +
2216 + /* Wait a bit and retry */
2217 +- udelay(200);
2218 +- ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
2219 ++ udelay(50);
2220 ++ ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
2221 ++ AR5K_SLEEP_CTL);
2222 + }
2223 +
2224 + /* Fail if the chip didn't wake up */
2225 +- if (i <= 0)
2226 ++ if (i == 0)
2227 + return -EIO;
2228 +
2229 + break;
2230 +@@ -297,6 +303,64 @@ commit:
2231 + }
2232 +
2233 + /*
2234 ++ * Put device on hold
2235 ++ *
2236 ++ * Put MAC and Baseband on warm reset and
2237 ++ * keep that state (don't clean sleep control
2238 ++ * register). After this MAC and Baseband are
2239 ++ * disabled and a full reset is needed to come
2240 ++ * back. This way we save as much power as possible
2241 ++ * without puting the card on full sleep.
2242 ++ */
2243 ++int ath5k_hw_on_hold(struct ath5k_hw *ah)
2244 ++{
2245 ++ struct pci_dev *pdev = ah->ah_sc->pdev;
2246 ++ u32 bus_flags;
2247 ++ int ret;
2248 ++
2249 ++ /* Make sure device is awake */
2250 ++ ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
2251 ++ if (ret) {
2252 ++ ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
2253 ++ return ret;
2254 ++ }
2255 ++
2256 ++ /*
2257 ++ * Put chipset on warm reset...
2258 ++ *
2259 ++ * Note: puting PCI core on warm reset on PCI-E cards
2260 ++ * results card to hang and always return 0xffff... so
2261 ++ * we ingore that flag for PCI-E cards. On PCI cards
2262 ++ * this flag gets cleared after 64 PCI clocks.
2263 ++ */
2264 ++ bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
2265 ++
2266 ++ if (ah->ah_version == AR5K_AR5210) {
2267 ++ ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
2268 ++ AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
2269 ++ AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
2270 ++ mdelay(2);
2271 ++ } else {
2272 ++ ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
2273 ++ AR5K_RESET_CTL_BASEBAND | bus_flags);
2274 ++ }
2275 ++
2276 ++ if (ret) {
2277 ++ ATH5K_ERR(ah->ah_sc, "failed to put device on warm reset\n");
2278 ++ return -EIO;
2279 ++ }
2280 ++
2281 ++ /* ...wakeup again!*/
2282 ++ ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
2283 ++ if (ret) {
2284 ++ ATH5K_ERR(ah->ah_sc, "failed to put device on hold\n");
2285 ++ return ret;
2286 ++ }
2287 ++
2288 ++ return ret;
2289 ++}
2290 ++
2291 ++/*
2292 + * Bring up MAC + PHY Chips and program PLL
2293 + * TODO: Half/Quarter rate support
2294 + */
2295 +@@ -319,6 +383,50 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
2296 + return ret;
2297 + }
2298 +
2299 ++ /*
2300 ++ * Put chipset on warm reset...
2301 ++ *
2302 ++ * Note: puting PCI core on warm reset on PCI-E cards
2303 ++ * results card to hang and always return 0xffff... so
2304 ++ * we ingore that flag for PCI-E cards. On PCI cards
2305 ++ * this flag gets cleared after 64 PCI clocks.
2306 ++ */
2307 ++ bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
2308 ++
2309 ++ if (ah->ah_version == AR5K_AR5210) {
2310 ++ ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
2311 ++ AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
2312 ++ AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
2313 ++ mdelay(2);
2314 ++ } else {
2315 ++ ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
2316 ++ AR5K_RESET_CTL_BASEBAND | bus_flags);
2317 ++ }
2318 ++
2319 ++ if (ret) {
2320 ++ ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
2321 ++ return -EIO;
2322 ++ }
2323 ++
2324 ++ /* ...wakeup again!...*/
2325 ++ ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
2326 ++ if (ret) {
2327 ++ ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
2328 ++ return ret;
2329 ++ }
2330 ++
2331 ++ /* ...clear reset control register and pull device out of
2332 ++ * warm reset */
2333 ++ if (ath5k_hw_nic_reset(ah, 0)) {
2334 ++ ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
2335 ++ return -EIO;
2336 ++ }
2337 ++
2338 ++ /* On initialization skip PLL programming since we don't have
2339 ++ * a channel / mode set yet */
2340 ++ if (initial)
2341 ++ return 0;
2342 ++
2343 + if (ah->ah_version != AR5K_AR5210) {
2344 + /*
2345 + * Get channel mode flags
2346 +@@ -384,39 +492,6 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
2347 + AR5K_PHY_TURBO);
2348 + }
2349 +
2350 +- /* reseting PCI on PCI-E cards results card to hang
2351 +- * and always return 0xffff... so we ingore that flag
2352 +- * for PCI-E cards */
2353 +- bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
2354 +-
2355 +- /* Reset chipset */
2356 +- if (ah->ah_version == AR5K_AR5210) {
2357 +- ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
2358 +- AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
2359 +- AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
2360 +- mdelay(2);
2361 +- } else {
2362 +- ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
2363 +- AR5K_RESET_CTL_BASEBAND | bus_flags);
2364 +- }
2365 +- if (ret) {
2366 +- ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
2367 +- return -EIO;
2368 +- }
2369 +-
2370 +- /* ...wakeup again!*/
2371 +- ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
2372 +- if (ret) {
2373 +- ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
2374 +- return ret;
2375 +- }
2376 +-
2377 +- /* ...final warm reset */
2378 +- if (ath5k_hw_nic_reset(ah, 0)) {
2379 +- ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
2380 +- return -EIO;
2381 +- }
2382 +-
2383 + if (ah->ah_version != AR5K_AR5210) {
2384 +
2385 + /* ...update PLL if needed */
2386 +diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
2387 +index 7da52f1..d83d430 100644
2388 +--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
2389 ++++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
2390 +@@ -46,7 +46,7 @@
2391 + #include "iwl-5000-hw.h"
2392 +
2393 + /* Highest firmware API version supported */
2394 +-#define IWL1000_UCODE_API_MAX 2
2395 ++#define IWL1000_UCODE_API_MAX 3
2396 +
2397 + /* Lowest firmware API version supported */
2398 + #define IWL1000_UCODE_API_MIN 1
2399 +@@ -62,12 +62,14 @@ struct iwl_cfg iwl1000_bgn_cfg = {
2400 + .ucode_api_min = IWL1000_UCODE_API_MIN,
2401 + .sku = IWL_SKU_G|IWL_SKU_N,
2402 + .ops = &iwl5000_ops,
2403 +- .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
2404 ++ .eeprom_size = OTP_LOW_IMAGE_SIZE,
2405 + .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
2406 + .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
2407 + .mod_params = &iwl50_mod_params,
2408 + .valid_tx_ant = ANT_A,
2409 + .valid_rx_ant = ANT_AB,
2410 + .need_pll_cfg = true,
2411 ++ .max_ll_items = OTP_MAX_LL_ITEMS_1000,
2412 ++ .shadow_ram_support = false,
2413 + };
2414 +
2415 +diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
2416 +index 46288e7..b73ab6c 100644
2417 +--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
2418 ++++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
2419 +@@ -2784,11 +2784,50 @@ static int iwl3945_load_bsm(struct iwl_priv *priv)
2420 + return 0;
2421 + }
2422 +
2423 ++#define IWL3945_UCODE_GET(item) \
2424 ++static u32 iwl3945_ucode_get_##item(const struct iwl_ucode_header *ucode,\
2425 ++ u32 api_ver) \
2426 ++{ \
2427 ++ return le32_to_cpu(ucode->u.v1.item); \
2428 ++}
2429 ++
2430 ++static u32 iwl3945_ucode_get_header_size(u32 api_ver)
2431 ++{
2432 ++ return UCODE_HEADER_SIZE(1);
2433 ++}
2434 ++static u32 iwl3945_ucode_get_build(const struct iwl_ucode_header *ucode,
2435 ++ u32 api_ver)
2436 ++{
2437 ++ return 0;
2438 ++}
2439 ++static u8 *iwl3945_ucode_get_data(const struct iwl_ucode_header *ucode,
2440 ++ u32 api_ver)
2441 ++{
2442 ++ return (u8 *) ucode->u.v1.data;
2443 ++}
2444 ++
2445 ++IWL3945_UCODE_GET(inst_size);
2446 ++IWL3945_UCODE_GET(data_size);
2447 ++IWL3945_UCODE_GET(init_size);
2448 ++IWL3945_UCODE_GET(init_data_size);
2449 ++IWL3945_UCODE_GET(boot_size);
2450 ++
2451 + static struct iwl_hcmd_ops iwl3945_hcmd = {
2452 + .rxon_assoc = iwl3945_send_rxon_assoc,
2453 + .commit_rxon = iwl3945_commit_rxon,
2454 + };
2455 +
2456 ++static struct iwl_ucode_ops iwl3945_ucode = {
2457 ++ .get_header_size = iwl3945_ucode_get_header_size,
2458 ++ .get_build = iwl3945_ucode_get_build,
2459 ++ .get_inst_size = iwl3945_ucode_get_inst_size,
2460 ++ .get_data_size = iwl3945_ucode_get_data_size,
2461 ++ .get_init_size = iwl3945_ucode_get_init_size,
2462 ++ .get_init_data_size = iwl3945_ucode_get_init_data_size,
2463 ++ .get_boot_size = iwl3945_ucode_get_boot_size,
2464 ++ .get_data = iwl3945_ucode_get_data,
2465 ++};
2466 ++
2467 + static struct iwl_lib_ops iwl3945_lib = {
2468 + .txq_attach_buf_to_tfd = iwl3945_hw_txq_attach_buf_to_tfd,
2469 + .txq_free_tfd = iwl3945_hw_txq_free_tfd,
2470 +@@ -2829,6 +2868,7 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
2471 + };
2472 +
2473 + static struct iwl_ops iwl3945_ops = {
2474 ++ .ucode = &iwl3945_ucode,
2475 + .lib = &iwl3945_lib,
2476 + .hcmd = &iwl3945_hcmd,
2477 + .utils = &iwl3945_hcmd_utils,
2478 +diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
2479 +index 8f3d4bc..157ee15 100644
2480 +--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
2481 ++++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
2482 +@@ -2221,12 +2221,50 @@ static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
2483 + cancel_work_sync(&priv->txpower_work);
2484 + }
2485 +
2486 ++#define IWL4965_UCODE_GET(item) \
2487 ++static u32 iwl4965_ucode_get_##item(const struct iwl_ucode_header *ucode,\
2488 ++ u32 api_ver) \
2489 ++{ \
2490 ++ return le32_to_cpu(ucode->u.v1.item); \
2491 ++}
2492 ++
2493 ++static u32 iwl4965_ucode_get_header_size(u32 api_ver)
2494 ++{
2495 ++ return UCODE_HEADER_SIZE(1);
2496 ++}
2497 ++static u32 iwl4965_ucode_get_build(const struct iwl_ucode_header *ucode,
2498 ++ u32 api_ver)
2499 ++{
2500 ++ return 0;
2501 ++}
2502 ++static u8 *iwl4965_ucode_get_data(const struct iwl_ucode_header *ucode,
2503 ++ u32 api_ver)
2504 ++{
2505 ++ return (u8 *) ucode->u.v1.data;
2506 ++}
2507 ++
2508 ++IWL4965_UCODE_GET(inst_size);
2509 ++IWL4965_UCODE_GET(data_size);
2510 ++IWL4965_UCODE_GET(init_size);
2511 ++IWL4965_UCODE_GET(init_data_size);
2512 ++IWL4965_UCODE_GET(boot_size);
2513 ++
2514 + static struct iwl_hcmd_ops iwl4965_hcmd = {
2515 + .rxon_assoc = iwl4965_send_rxon_assoc,
2516 + .commit_rxon = iwl_commit_rxon,
2517 + .set_rxon_chain = iwl_set_rxon_chain,
2518 + };
2519 +
2520 ++static struct iwl_ucode_ops iwl4965_ucode = {
2521 ++ .get_header_size = iwl4965_ucode_get_header_size,
2522 ++ .get_build = iwl4965_ucode_get_build,
2523 ++ .get_inst_size = iwl4965_ucode_get_inst_size,
2524 ++ .get_data_size = iwl4965_ucode_get_data_size,
2525 ++ .get_init_size = iwl4965_ucode_get_init_size,
2526 ++ .get_init_data_size = iwl4965_ucode_get_init_data_size,
2527 ++ .get_boot_size = iwl4965_ucode_get_boot_size,
2528 ++ .get_data = iwl4965_ucode_get_data,
2529 ++};
2530 + static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
2531 + .get_hcmd_size = iwl4965_get_hcmd_size,
2532 + .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
2533 +@@ -2287,6 +2325,7 @@ static struct iwl_lib_ops iwl4965_lib = {
2534 + };
2535 +
2536 + static struct iwl_ops iwl4965_ops = {
2537 ++ .ucode = &iwl4965_ucode,
2538 + .lib = &iwl4965_lib,
2539 + .hcmd = &iwl4965_hcmd,
2540 + .utils = &iwl4965_hcmd_utils,
2541 +diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
2542 +index b3c648c..a9ea3b5 100644
2543 +--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
2544 ++++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
2545 +@@ -239,6 +239,13 @@ static void iwl5000_nic_config(struct iwl_priv *priv)
2546 + APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
2547 + ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
2548 +
2549 ++ if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_1000) {
2550 ++ /* Setting digital SVR for 1000 card to 1.32V */
2551 ++ iwl_set_bits_mask_prph(priv, APMG_DIGITAL_SVR_REG,
2552 ++ APMG_SVR_DIGITAL_VOLTAGE_1_32,
2553 ++ ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK);
2554 ++ }
2555 ++
2556 + spin_unlock_irqrestore(&priv->lock, flags);
2557 + }
2558 +
2559 +@@ -1426,6 +1433,44 @@ int iwl5000_calc_rssi(struct iwl_priv *priv,
2560 + return max_rssi - agc - IWL49_RSSI_OFFSET;
2561 + }
2562 +
2563 ++#define IWL5000_UCODE_GET(item) \
2564 ++static u32 iwl5000_ucode_get_##item(const struct iwl_ucode_header *ucode,\
2565 ++ u32 api_ver) \
2566 ++{ \
2567 ++ if (api_ver <= 2) \
2568 ++ return le32_to_cpu(ucode->u.v1.item); \
2569 ++ return le32_to_cpu(ucode->u.v2.item); \
2570 ++}
2571 ++
2572 ++static u32 iwl5000_ucode_get_header_size(u32 api_ver)
2573 ++{
2574 ++ if (api_ver <= 2)
2575 ++ return UCODE_HEADER_SIZE(1);
2576 ++ return UCODE_HEADER_SIZE(2);
2577 ++}
2578 ++
2579 ++static u32 iwl5000_ucode_get_build(const struct iwl_ucode_header *ucode,
2580 ++ u32 api_ver)
2581 ++{
2582 ++ if (api_ver <= 2)
2583 ++ return 0;
2584 ++ return le32_to_cpu(ucode->u.v2.build);
2585 ++}
2586 ++
2587 ++static u8 *iwl5000_ucode_get_data(const struct iwl_ucode_header *ucode,
2588 ++ u32 api_ver)
2589 ++{
2590 ++ if (api_ver <= 2)
2591 ++ return (u8 *) ucode->u.v1.data;
2592 ++ return (u8 *) ucode->u.v2.data;
2593 ++}
2594 ++
2595 ++IWL5000_UCODE_GET(inst_size);
2596 ++IWL5000_UCODE_GET(data_size);
2597 ++IWL5000_UCODE_GET(init_size);
2598 ++IWL5000_UCODE_GET(init_data_size);
2599 ++IWL5000_UCODE_GET(boot_size);
2600 ++
2601 + struct iwl_hcmd_ops iwl5000_hcmd = {
2602 + .rxon_assoc = iwl5000_send_rxon_assoc,
2603 + .commit_rxon = iwl_commit_rxon,
2604 +@@ -1441,6 +1486,17 @@ struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
2605 + .calc_rssi = iwl5000_calc_rssi,
2606 + };
2607 +
2608 ++struct iwl_ucode_ops iwl5000_ucode = {
2609 ++ .get_header_size = iwl5000_ucode_get_header_size,
2610 ++ .get_build = iwl5000_ucode_get_build,
2611 ++ .get_inst_size = iwl5000_ucode_get_inst_size,
2612 ++ .get_data_size = iwl5000_ucode_get_data_size,
2613 ++ .get_init_size = iwl5000_ucode_get_init_size,
2614 ++ .get_init_data_size = iwl5000_ucode_get_init_data_size,
2615 ++ .get_boot_size = iwl5000_ucode_get_boot_size,
2616 ++ .get_data = iwl5000_ucode_get_data,
2617 ++};
2618 ++
2619 + struct iwl_lib_ops iwl5000_lib = {
2620 + .set_hw_params = iwl5000_hw_set_hw_params,
2621 + .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
2622 +@@ -1542,12 +1598,14 @@ static struct iwl_lib_ops iwl5150_lib = {
2623 + };
2624 +
2625 + struct iwl_ops iwl5000_ops = {
2626 ++ .ucode = &iwl5000_ucode,
2627 + .lib = &iwl5000_lib,
2628 + .hcmd = &iwl5000_hcmd,
2629 + .utils = &iwl5000_hcmd_utils,
2630 + };
2631 +
2632 + static struct iwl_ops iwl5150_ops = {
2633 ++ .ucode = &iwl5000_ucode,
2634 + .lib = &iwl5150_lib,
2635 + .hcmd = &iwl5000_hcmd,
2636 + .utils = &iwl5000_hcmd_utils,
2637 +diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
2638 +index bd438d8..e4a405f 100644
2639 +--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
2640 ++++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
2641 +@@ -46,8 +46,8 @@
2642 + #include "iwl-5000-hw.h"
2643 +
2644 + /* Highest firmware API version supported */
2645 +-#define IWL6000_UCODE_API_MAX 2
2646 +-#define IWL6050_UCODE_API_MAX 2
2647 ++#define IWL6000_UCODE_API_MAX 3
2648 ++#define IWL6050_UCODE_API_MAX 3
2649 +
2650 + /* Lowest firmware API version supported */
2651 + #define IWL6000_UCODE_API_MIN 1
2652 +@@ -69,6 +69,7 @@ static struct iwl_hcmd_utils_ops iwl6000_hcmd_utils = {
2653 + };
2654 +
2655 + static struct iwl_ops iwl6000_ops = {
2656 ++ .ucode = &iwl5000_ucode,
2657 + .lib = &iwl5000_lib,
2658 + .hcmd = &iwl5000_hcmd,
2659 + .utils = &iwl6000_hcmd_utils,
2660 +@@ -81,13 +82,15 @@ struct iwl_cfg iwl6000_2ag_cfg = {
2661 + .ucode_api_min = IWL6000_UCODE_API_MIN,
2662 + .sku = IWL_SKU_A|IWL_SKU_G,
2663 + .ops = &iwl6000_ops,
2664 +- .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
2665 ++ .eeprom_size = OTP_LOW_IMAGE_SIZE,
2666 + .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
2667 + .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
2668 + .mod_params = &iwl50_mod_params,
2669 + .valid_tx_ant = ANT_BC,
2670 + .valid_rx_ant = ANT_BC,
2671 + .need_pll_cfg = false,
2672 ++ .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
2673 ++ .shadow_ram_support = true,
2674 + };
2675 +
2676 + struct iwl_cfg iwl6000_2agn_cfg = {
2677 +@@ -97,13 +100,15 @@ struct iwl_cfg iwl6000_2agn_cfg = {
2678 + .ucode_api_min = IWL6000_UCODE_API_MIN,
2679 + .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
2680 + .ops = &iwl6000_ops,
2681 +- .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
2682 ++ .eeprom_size = OTP_LOW_IMAGE_SIZE,
2683 + .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
2684 + .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
2685 + .mod_params = &iwl50_mod_params,
2686 + .valid_tx_ant = ANT_AB,
2687 + .valid_rx_ant = ANT_AB,
2688 + .need_pll_cfg = false,
2689 ++ .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
2690 ++ .shadow_ram_support = true,
2691 + };
2692 +
2693 + struct iwl_cfg iwl6050_2agn_cfg = {
2694 +@@ -113,13 +118,15 @@ struct iwl_cfg iwl6050_2agn_cfg = {
2695 + .ucode_api_min = IWL6050_UCODE_API_MIN,
2696 + .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
2697 + .ops = &iwl6000_ops,
2698 +- .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
2699 ++ .eeprom_size = OTP_LOW_IMAGE_SIZE,
2700 + .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
2701 + .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
2702 + .mod_params = &iwl50_mod_params,
2703 + .valid_tx_ant = ANT_AB,
2704 + .valid_rx_ant = ANT_AB,
2705 + .need_pll_cfg = false,
2706 ++ .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
2707 ++ .shadow_ram_support = true,
2708 + };
2709 +
2710 + struct iwl_cfg iwl6000_3agn_cfg = {
2711 +@@ -129,13 +136,15 @@ struct iwl_cfg iwl6000_3agn_cfg = {
2712 + .ucode_api_min = IWL6000_UCODE_API_MIN,
2713 + .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
2714 + .ops = &iwl6000_ops,
2715 +- .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
2716 ++ .eeprom_size = OTP_LOW_IMAGE_SIZE,
2717 + .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
2718 + .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
2719 + .mod_params = &iwl50_mod_params,
2720 + .valid_tx_ant = ANT_ABC,
2721 + .valid_rx_ant = ANT_ABC,
2722 + .need_pll_cfg = false,
2723 ++ .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
2724 ++ .shadow_ram_support = true,
2725 + };
2726 +
2727 + struct iwl_cfg iwl6050_3agn_cfg = {
2728 +@@ -145,13 +154,15 @@ struct iwl_cfg iwl6050_3agn_cfg = {
2729 + .ucode_api_min = IWL6050_UCODE_API_MIN,
2730 + .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
2731 + .ops = &iwl6000_ops,
2732 +- .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
2733 ++ .eeprom_size = OTP_LOW_IMAGE_SIZE,
2734 + .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
2735 + .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
2736 + .mod_params = &iwl50_mod_params,
2737 + .valid_tx_ant = ANT_ABC,
2738 + .valid_rx_ant = ANT_ABC,
2739 + .need_pll_cfg = false,
2740 ++ .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
2741 ++ .shadow_ram_support = true,
2742 + };
2743 +
2744 + MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX));
2745 +diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
2746 +index 355f50e..2a577ae 100644
2747 +--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
2748 ++++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
2749 +@@ -1348,7 +1348,7 @@ static void iwl_nic_start(struct iwl_priv *priv)
2750 + */
2751 + static int iwl_read_ucode(struct iwl_priv *priv)
2752 + {
2753 +- struct iwl_ucode *ucode;
2754 ++ struct iwl_ucode_header *ucode;
2755 + int ret = -EINVAL, index;
2756 + const struct firmware *ucode_raw;
2757 + const char *name_pre = priv->cfg->fw_name_pre;
2758 +@@ -1357,7 +1357,8 @@ static int iwl_read_ucode(struct iwl_priv *priv)
2759 + char buf[25];
2760 + u8 *src;
2761 + size_t len;
2762 +- u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
2763 ++ u32 api_ver, build;
2764 ++ u32 inst_size, data_size, init_size, init_data_size, boot_size;
2765 +
2766 + /* Ask kernel firmware_class module to get the boot firmware off disk.
2767 + * request_firmware() is synchronous, file is in memory on return. */
2768 +@@ -1387,23 +1388,26 @@ static int iwl_read_ucode(struct iwl_priv *priv)
2769 + if (ret < 0)
2770 + goto error;
2771 +
2772 +- /* Make sure that we got at least our header! */
2773 +- if (ucode_raw->size < sizeof(*ucode)) {
2774 ++ /* Make sure that we got at least the v1 header! */
2775 ++ if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
2776 + IWL_ERR(priv, "File size way too small!\n");
2777 + ret = -EINVAL;
2778 + goto err_release;
2779 + }
2780 +
2781 + /* Data from ucode file: header followed by uCode images */
2782 +- ucode = (void *)ucode_raw->data;
2783 ++ ucode = (struct iwl_ucode_header *)ucode_raw->data;
2784 +
2785 + priv->ucode_ver = le32_to_cpu(ucode->ver);
2786 + api_ver = IWL_UCODE_API(priv->ucode_ver);
2787 +- inst_size = le32_to_cpu(ucode->inst_size);
2788 +- data_size = le32_to_cpu(ucode->data_size);
2789 +- init_size = le32_to_cpu(ucode->init_size);
2790 +- init_data_size = le32_to_cpu(ucode->init_data_size);
2791 +- boot_size = le32_to_cpu(ucode->boot_size);
2792 ++ build = priv->cfg->ops->ucode->get_build(ucode, api_ver);
2793 ++ inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
2794 ++ data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
2795 ++ init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
2796 ++ init_data_size =
2797 ++ priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
2798 ++ boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
2799 ++ src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
2800 +
2801 + /* api_ver should match the api version forming part of the
2802 + * firmware filename ... but we don't check for that and only rely
2803 +@@ -1429,6 +1433,9 @@ static int iwl_read_ucode(struct iwl_priv *priv)
2804 + IWL_UCODE_API(priv->ucode_ver),
2805 + IWL_UCODE_SERIAL(priv->ucode_ver));
2806 +
2807 ++ if (build)
2808 ++ IWL_DEBUG_INFO(priv, "Build %u\n", build);
2809 ++
2810 + IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
2811 + priv->ucode_ver);
2812 + IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2813 +@@ -1443,12 +1450,14 @@ static int iwl_read_ucode(struct iwl_priv *priv)
2814 + boot_size);
2815 +
2816 + /* Verify size of file vs. image size info in file's header */
2817 +- if (ucode_raw->size < sizeof(*ucode) +
2818 ++ if (ucode_raw->size !=
2819 ++ priv->cfg->ops->ucode->get_header_size(api_ver) +
2820 + inst_size + data_size + init_size +
2821 + init_data_size + boot_size) {
2822 +
2823 +- IWL_DEBUG_INFO(priv, "uCode file size %d too small\n",
2824 +- (int)ucode_raw->size);
2825 ++ IWL_DEBUG_INFO(priv,
2826 ++ "uCode file size %d does not match expected size\n",
2827 ++ (int)ucode_raw->size);
2828 + ret = -EINVAL;
2829 + goto err_release;
2830 + }
2831 +@@ -1528,42 +1537,42 @@ static int iwl_read_ucode(struct iwl_priv *priv)
2832 + /* Copy images into buffers for card's bus-master reads ... */
2833 +
2834 + /* Runtime instructions (first block of data in file) */
2835 +- src = &ucode->data[0];
2836 +- len = priv->ucode_code.len;
2837 ++ len = inst_size;
2838 + IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", len);
2839 + memcpy(priv->ucode_code.v_addr, src, len);
2840 ++ src += len;
2841 ++
2842 + IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2843 + priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2844 +
2845 + /* Runtime data (2nd block)
2846 + * NOTE: Copy into backup buffer will be done in iwl_up() */
2847 +- src = &ucode->data[inst_size];
2848 +- len = priv->ucode_data.len;
2849 ++ len = data_size;
2850 + IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", len);
2851 + memcpy(priv->ucode_data.v_addr, src, len);
2852 + memcpy(priv->ucode_data_backup.v_addr, src, len);
2853 ++ src += len;
2854 +
2855 + /* Initialization instructions (3rd block) */
2856 + if (init_size) {
2857 +- src = &ucode->data[inst_size + data_size];
2858 +- len = priv->ucode_init.len;
2859 ++ len = init_size;
2860 + IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
2861 + len);
2862 + memcpy(priv->ucode_init.v_addr, src, len);
2863 ++ src += len;
2864 + }
2865 +
2866 + /* Initialization data (4th block) */
2867 + if (init_data_size) {
2868 +- src = &ucode->data[inst_size + data_size + init_size];
2869 +- len = priv->ucode_init_data.len;
2870 ++ len = init_data_size;
2871 + IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
2872 + len);
2873 + memcpy(priv->ucode_init_data.v_addr, src, len);
2874 ++ src += len;
2875 + }
2876 +
2877 + /* Bootstrap instructions (5th block) */
2878 +- src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2879 +- len = priv->ucode_boot.len;
2880 ++ len = boot_size;
2881 + IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", len);
2882 + memcpy(priv->ucode_boot.v_addr, src, len);
2883 +
2884 +@@ -2206,7 +2215,7 @@ static void iwl_mac_stop(struct ieee80211_hw *hw)
2885 +
2886 + priv->is_open = 0;
2887 +
2888 +- if (iwl_is_ready_rf(priv)) {
2889 ++ if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
2890 + /* stop mac, cancel any scan request and clear
2891 + * RXON_FILTER_ASSOC_MSK BIT
2892 + */
2893 +diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
2894 +index dabf663..1e51891 100644
2895 +--- a/drivers/net/wireless/iwlwifi/iwl-core.h
2896 ++++ b/drivers/net/wireless/iwlwifi/iwl-core.h
2897 +@@ -116,6 +116,17 @@ struct iwl_temp_ops {
2898 + void (*set_ct_kill)(struct iwl_priv *priv);
2899 + };
2900 +
2901 ++struct iwl_ucode_ops {
2902 ++ u32 (*get_header_size)(u32);
2903 ++ u32 (*get_build)(const struct iwl_ucode_header *, u32);
2904 ++ u32 (*get_inst_size)(const struct iwl_ucode_header *, u32);
2905 ++ u32 (*get_data_size)(const struct iwl_ucode_header *, u32);
2906 ++ u32 (*get_init_size)(const struct iwl_ucode_header *, u32);
2907 ++ u32 (*get_init_data_size)(const struct iwl_ucode_header *, u32);
2908 ++ u32 (*get_boot_size)(const struct iwl_ucode_header *, u32);
2909 ++ u8 * (*get_data)(const struct iwl_ucode_header *, u32);
2910 ++};
2911 ++
2912 + struct iwl_lib_ops {
2913 + /* set hw dependent parameters */
2914 + int (*set_hw_params)(struct iwl_priv *priv);
2915 +@@ -171,6 +182,7 @@ struct iwl_lib_ops {
2916 + };
2917 +
2918 + struct iwl_ops {
2919 ++ const struct iwl_ucode_ops *ucode;
2920 + const struct iwl_lib_ops *lib;
2921 + const struct iwl_hcmd_ops *hcmd;
2922 + const struct iwl_hcmd_utils_ops *utils;
2923 +@@ -195,6 +207,8 @@ struct iwl_mod_params {
2924 + * filename is constructed as fw_name_pre<api>.ucode.
2925 + * @ucode_api_max: Highest version of uCode API supported by driver.
2926 + * @ucode_api_min: Lowest version of uCode API supported by driver.
2927 ++ * @max_ll_items: max number of OTP blocks
2928 ++ * @shadow_ram_support: shadow support for OTP memory
2929 + *
2930 + * We enable the driver to be backward compatible wrt API version. The
2931 + * driver specifies which APIs it supports (with @ucode_api_max being the
2932 +@@ -231,6 +245,8 @@ struct iwl_cfg {
2933 + u8 valid_rx_ant;
2934 + bool need_pll_cfg;
2935 + bool use_isr_legacy;
2936 ++ const u16 max_ll_items;
2937 ++ const bool shadow_ram_support;
2938 + };
2939 +
2940 + /***************************
2941 +diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
2942 +index 650e20a..e8c8607 100644
2943 +--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
2944 ++++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
2945 +@@ -66,6 +66,7 @@ extern struct iwl_cfg iwl1000_bgn_cfg;
2946 + /* shared structures from iwl-5000.c */
2947 + extern struct iwl_mod_params iwl50_mod_params;
2948 + extern struct iwl_ops iwl5000_ops;
2949 ++extern struct iwl_ucode_ops iwl5000_ucode;
2950 + extern struct iwl_lib_ops iwl5000_lib;
2951 + extern struct iwl_hcmd_ops iwl5000_hcmd;
2952 + extern struct iwl_hcmd_utils_ops iwl5000_hcmd_utils;
2953 +@@ -525,15 +526,29 @@ struct fw_desc {
2954 + };
2955 +
2956 + /* uCode file layout */
2957 +-struct iwl_ucode {
2958 +- __le32 ver; /* major/minor/API/serial */
2959 +- __le32 inst_size; /* bytes of runtime instructions */
2960 +- __le32 data_size; /* bytes of runtime data */
2961 +- __le32 init_size; /* bytes of initialization instructions */
2962 +- __le32 init_data_size; /* bytes of initialization data */
2963 +- __le32 boot_size; /* bytes of bootstrap instructions */
2964 +- u8 data[0]; /* data in same order as "size" elements */
2965 ++struct iwl_ucode_header {
2966 ++ __le32 ver; /* major/minor/API/serial */
2967 ++ union {
2968 ++ struct {
2969 ++ __le32 inst_size; /* bytes of runtime code */
2970 ++ __le32 data_size; /* bytes of runtime data */
2971 ++ __le32 init_size; /* bytes of init code */
2972 ++ __le32 init_data_size; /* bytes of init data */
2973 ++ __le32 boot_size; /* bytes of bootstrap code */
2974 ++ u8 data[0]; /* in same order as sizes */
2975 ++ } v1;
2976 ++ struct {
2977 ++ __le32 build; /* build number */
2978 ++ __le32 inst_size; /* bytes of runtime code */
2979 ++ __le32 data_size; /* bytes of runtime data */
2980 ++ __le32 init_size; /* bytes of init code */
2981 ++ __le32 init_data_size; /* bytes of init data */
2982 ++ __le32 boot_size; /* bytes of bootstrap code */
2983 ++ u8 data[0]; /* in same order as sizes */
2984 ++ } v2;
2985 ++ } u;
2986 + };
2987 ++#define UCODE_HEADER_SIZE(ver) ((ver) == 1 ? 24 : 28)
2988 +
2989 + struct iwl4965_ibss_seq {
2990 + u8 mac[ETH_ALEN];
2991 +@@ -820,6 +835,18 @@ enum iwl_nvm_type {
2992 + NVM_DEVICE_TYPE_OTP,
2993 + };
2994 +
2995 ++/*
2996 ++ * Two types of OTP memory access modes
2997 ++ * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
2998 ++ * based on physical memory addressing
2999 ++ * IWL_OTP_ACCESS_RELATIVE - relative address mode,
3000 ++ * based on logical memory addressing
3001 ++ */
3002 ++enum iwl_access_mode {
3003 ++ IWL_OTP_ACCESS_ABSOLUTE,
3004 ++ IWL_OTP_ACCESS_RELATIVE,
3005 ++};
3006 ++
3007 + /* interrupt statistics */
3008 + struct isr_statistics {
3009 + u32 hw;
3010 +diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
3011 +index 7d7554a..e8c0e82 100644
3012 +--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
3013 ++++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
3014 +@@ -152,6 +152,19 @@ int iwlcore_eeprom_verify_signature(struct iwl_priv *priv)
3015 + }
3016 + EXPORT_SYMBOL(iwlcore_eeprom_verify_signature);
3017 +
3018 ++static void iwl_set_otp_access(struct iwl_priv *priv, enum iwl_access_mode mode)
3019 ++{
3020 ++ u32 otpgp;
3021 ++
3022 ++ otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
3023 ++ if (mode == IWL_OTP_ACCESS_ABSOLUTE)
3024 ++ iwl_clear_bit(priv, CSR_OTP_GP_REG,
3025 ++ CSR_OTP_GP_REG_OTP_ACCESS_MODE);
3026 ++ else
3027 ++ iwl_set_bit(priv, CSR_OTP_GP_REG,
3028 ++ CSR_OTP_GP_REG_OTP_ACCESS_MODE);
3029 ++}
3030 ++
3031 + static int iwlcore_get_nvm_type(struct iwl_priv *priv)
3032 + {
3033 + u32 otpgp;
3034 +@@ -249,6 +262,124 @@ static int iwl_init_otp_access(struct iwl_priv *priv)
3035 + return ret;
3036 + }
3037 +
3038 ++static int iwl_read_otp_word(struct iwl_priv *priv, u16 addr, u16 *eeprom_data)
3039 ++{
3040 ++ int ret = 0;
3041 ++ u32 r;
3042 ++ u32 otpgp;
3043 ++
3044 ++ _iwl_write32(priv, CSR_EEPROM_REG,
3045 ++ CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
3046 ++ ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
3047 ++ CSR_EEPROM_REG_READ_VALID_MSK,
3048 ++ IWL_EEPROM_ACCESS_TIMEOUT);
3049 ++ if (ret < 0) {
3050 ++ IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
3051 ++ return ret;
3052 ++ }
3053 ++ r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
3054 ++ /* check for ECC errors: */
3055 ++ otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
3056 ++ if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
3057 ++ /* stop in this case */
3058 ++ /* set the uncorrectable OTP ECC bit for acknowledgement */
3059 ++ iwl_set_bit(priv, CSR_OTP_GP_REG,
3060 ++ CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
3061 ++ IWL_ERR(priv, "Uncorrectable OTP ECC error, abort OTP read\n");
3062 ++ return -EINVAL;
3063 ++ }
3064 ++ if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
3065 ++ /* continue in this case */
3066 ++ /* set the correctable OTP ECC bit for acknowledgement */
3067 ++ iwl_set_bit(priv, CSR_OTP_GP_REG,
3068 ++ CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
3069 ++ IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
3070 ++ }
3071 ++ *eeprom_data = le16_to_cpu((__force __le16)(r >> 16));
3072 ++ return 0;
3073 ++}
3074 ++
3075 ++/*
3076 ++ * iwl_is_otp_empty: check for empty OTP
3077 ++ */
3078 ++static bool iwl_is_otp_empty(struct iwl_priv *priv)
3079 ++{
3080 ++ u16 next_link_addr = 0, link_value;
3081 ++ bool is_empty = false;
3082 ++
3083 ++ /* locate the beginning of OTP link list */
3084 ++ if (!iwl_read_otp_word(priv, next_link_addr, &link_value)) {
3085 ++ if (!link_value) {
3086 ++ IWL_ERR(priv, "OTP is empty\n");
3087 ++ is_empty = true;
3088 ++ }
3089 ++ } else {
3090 ++ IWL_ERR(priv, "Unable to read first block of OTP list.\n");
3091 ++ is_empty = true;
3092 ++ }
3093 ++
3094 ++ return is_empty;
3095 ++}
3096 ++
3097 ++
3098 ++/*
3099 ++ * iwl_find_otp_image: find EEPROM image in OTP
3100 ++ * finding the OTP block that contains the EEPROM image.
3101 ++ * the last valid block on the link list (the block _before_ the last block)
3102 ++ * is the block we should read and used to configure the device.
3103 ++ * If all the available OTP blocks are full, the last block will be the block
3104 ++ * we should read and used to configure the device.
3105 ++ * only perform this operation if shadow RAM is disabled
3106 ++ */
3107 ++static int iwl_find_otp_image(struct iwl_priv *priv,
3108 ++ u16 *validblockaddr)
3109 ++{
3110 ++ u16 next_link_addr = 0, link_value = 0, valid_addr;
3111 ++ int ret = 0;
3112 ++ int usedblocks = 0;
3113 ++
3114 ++ /* set addressing mode to absolute to traverse the link list */
3115 ++ iwl_set_otp_access(priv, IWL_OTP_ACCESS_ABSOLUTE);
3116 ++
3117 ++ /* checking for empty OTP or error */
3118 ++ if (iwl_is_otp_empty(priv))
3119 ++ return -EINVAL;
3120 ++
3121 ++ /*
3122 ++ * start traverse link list
3123 ++ * until reach the max number of OTP blocks
3124 ++ * different devices have different number of OTP blocks
3125 ++ */
3126 ++ do {
3127 ++ /* save current valid block address
3128 ++ * check for more block on the link list
3129 ++ */
3130 ++ valid_addr = next_link_addr;
3131 ++ next_link_addr = link_value;
3132 ++ IWL_DEBUG_INFO(priv, "OTP blocks %d addr 0x%x\n",
3133 ++ usedblocks, next_link_addr);
3134 ++ if (iwl_read_otp_word(priv, next_link_addr, &link_value))
3135 ++ return -EINVAL;
3136 ++ if (!link_value) {
3137 ++ /*
3138 ++ * reach the end of link list,
3139 ++ * set address point to the starting address
3140 ++ * of the image
3141 ++ */
3142 ++ goto done;
3143 ++ }
3144 ++ /* more in the link list, continue */
3145 ++ usedblocks++;
3146 ++ } while (usedblocks < priv->cfg->max_ll_items);
3147 ++ /* OTP full, use last block */
3148 ++ IWL_DEBUG_INFO(priv, "OTP is full, use last block\n");
3149 ++done:
3150 ++ *validblockaddr = valid_addr;
3151 ++ /* skip first 2 bytes (link list pointer) */
3152 ++ *validblockaddr += 2;
3153 ++ return ret;
3154 ++}
3155 ++
3156 + /**
3157 + * iwl_eeprom_init - read EEPROM contents
3158 + *
3159 +@@ -263,14 +394,13 @@ int iwl_eeprom_init(struct iwl_priv *priv)
3160 + int sz;
3161 + int ret;
3162 + u16 addr;
3163 +- u32 otpgp;
3164 ++ u16 validblockaddr = 0;
3165 ++ u16 cache_addr = 0;
3166 +
3167 + priv->nvm_device_type = iwlcore_get_nvm_type(priv);
3168 +
3169 + /* allocate eeprom */
3170 +- if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
3171 +- priv->cfg->eeprom_size =
3172 +- OTP_BLOCK_SIZE * OTP_LOWER_BLOCKS_TOTAL;
3173 ++ IWL_DEBUG_INFO(priv, "NVM size = %d\n", priv->cfg->eeprom_size);
3174 + sz = priv->cfg->eeprom_size;
3175 + priv->eeprom = kzalloc(sz, GFP_KERNEL);
3176 + if (!priv->eeprom) {
3177 +@@ -298,46 +428,31 @@ int iwl_eeprom_init(struct iwl_priv *priv)
3178 + if (ret) {
3179 + IWL_ERR(priv, "Failed to initialize OTP access.\n");
3180 + ret = -ENOENT;
3181 +- goto err;
3182 ++ goto done;
3183 + }
3184 + _iwl_write32(priv, CSR_EEPROM_GP,
3185 + iwl_read32(priv, CSR_EEPROM_GP) &
3186 + ~CSR_EEPROM_GP_IF_OWNER_MSK);
3187 +- /* clear */
3188 +- _iwl_write32(priv, CSR_OTP_GP_REG,
3189 +- iwl_read32(priv, CSR_OTP_GP_REG) |
3190 ++
3191 ++ iwl_set_bit(priv, CSR_OTP_GP_REG,
3192 + CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
3193 + CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
3194 +-
3195 +- for (addr = 0; addr < sz; addr += sizeof(u16)) {
3196 +- u32 r;
3197 +-
3198 +- _iwl_write32(priv, CSR_EEPROM_REG,
3199 +- CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
3200 +-
3201 +- ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
3202 +- CSR_EEPROM_REG_READ_VALID_MSK,
3203 +- IWL_EEPROM_ACCESS_TIMEOUT);
3204 +- if (ret < 0) {
3205 +- IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
3206 ++ /* traversing the linked list if no shadow ram supported */
3207 ++ if (!priv->cfg->shadow_ram_support) {
3208 ++ if (iwl_find_otp_image(priv, &validblockaddr)) {
3209 ++ ret = -ENOENT;
3210 + goto done;
3211 + }
3212 +- r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
3213 +- /* check for ECC errors: */
3214 +- otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
3215 +- if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
3216 +- /* stop in this case */
3217 +- IWL_ERR(priv, "Uncorrectable OTP ECC error, Abort OTP read\n");
3218 ++ }
3219 ++ for (addr = validblockaddr; addr < validblockaddr + sz;
3220 ++ addr += sizeof(u16)) {
3221 ++ u16 eeprom_data;
3222 ++
3223 ++ ret = iwl_read_otp_word(priv, addr, &eeprom_data);
3224 ++ if (ret)
3225 + goto done;
3226 +- }
3227 +- if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
3228 +- /* continue in this case */
3229 +- _iwl_write32(priv, CSR_OTP_GP_REG,
3230 +- iwl_read32(priv, CSR_OTP_GP_REG) |
3231 +- CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
3232 +- IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
3233 +- }
3234 +- e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
3235 ++ e[cache_addr / 2] = eeprom_data;
3236 ++ cache_addr += sizeof(u16);
3237 + }
3238 + } else {
3239 + /* eeprom is an array of 16bit values */
3240 +diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
3241 +index 195b4ef..7899885 100644
3242 +--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
3243 ++++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
3244 +@@ -180,8 +180,14 @@ struct iwl_eeprom_channel {
3245 + #define EEPROM_5050_EEPROM_VERSION (0x21E)
3246 +
3247 + /* OTP */
3248 +-#define OTP_LOWER_BLOCKS_TOTAL (3)
3249 +-#define OTP_BLOCK_SIZE (0x400)
3250 ++/* lower blocks contain EEPROM image and calibration data */
3251 ++#define OTP_LOW_IMAGE_SIZE (2 * 512 * sizeof(u16)) /* 2 KB */
3252 ++/* high blocks contain PAPD data */
3253 ++#define OTP_HIGH_IMAGE_SIZE_6x00 (6 * 512 * sizeof(u16)) /* 6 KB */
3254 ++#define OTP_HIGH_IMAGE_SIZE_1000 (0x200 * sizeof(u16)) /* 1024 bytes */
3255 ++#define OTP_MAX_LL_ITEMS_1000 (3) /* OTP blocks for 1000 */
3256 ++#define OTP_MAX_LL_ITEMS_6x00 (4) /* OTP blocks for 6x00 */
3257 ++#define OTP_MAX_LL_ITEMS_6x50 (7) /* OTP blocks for 6x50 */
3258 +
3259 + /* 2.4 GHz */
3260 + extern const u8 iwl_eeprom_band_1[14];
3261 +diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
3262 +index 3b9cac3..d393e8f 100644
3263 +--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
3264 ++++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
3265 +@@ -80,6 +80,8 @@
3266 + #define APMG_RFKILL_REG (APMG_BASE + 0x0014)
3267 + #define APMG_RTC_INT_STT_REG (APMG_BASE + 0x001c)
3268 + #define APMG_RTC_INT_MSK_REG (APMG_BASE + 0x0020)
3269 ++#define APMG_DIGITAL_SVR_REG (APMG_BASE + 0x0058)
3270 ++#define APMG_ANALOG_SVR_REG (APMG_BASE + 0x006C)
3271 +
3272 + #define APMG_CLK_VAL_DMA_CLK_RQT (0x00000200)
3273 + #define APMG_CLK_VAL_BSM_CLK_RQT (0x00000800)
3274 +@@ -91,7 +93,8 @@
3275 + #define APMG_PS_CTRL_VAL_PWR_SRC_VMAIN (0x00000000)
3276 + #define APMG_PS_CTRL_VAL_PWR_SRC_MAX (0x01000000) /* 3945 only */
3277 + #define APMG_PS_CTRL_VAL_PWR_SRC_VAUX (0x02000000)
3278 +-
3279 ++#define APMG_SVR_VOLTAGE_CONFIG_BIT_MSK (0x000001E0) /* bit 8:5 */
3280 ++#define APMG_SVR_DIGITAL_VOLTAGE_1_32 (0x00000060)
3281 +
3282 + #define APMG_PCIDEV_STT_VAL_L1_ACT_DIS (0x00000800)
3283 +
3284 +diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
3285 +index e26875d..474fd49 100644
3286 +--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
3287 ++++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
3288 +@@ -799,7 +799,8 @@ void iwl_bg_abort_scan(struct work_struct *work)
3289 + {
3290 + struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
3291 +
3292 +- if (!iwl_is_ready(priv))
3293 ++ if (!test_bit(STATUS_READY, &priv->status) ||
3294 ++ !test_bit(STATUS_GEO_CONFIGURED, &priv->status))
3295 + return;
3296 +
3297 + mutex_lock(&priv->mutex);
3298 +diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
3299 +index 5238433..054d6c7 100644
3300 +--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
3301 ++++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
3302 +@@ -2111,7 +2111,7 @@ static void iwl3945_nic_start(struct iwl_priv *priv)
3303 + */
3304 + static int iwl3945_read_ucode(struct iwl_priv *priv)
3305 + {
3306 +- struct iwl_ucode *ucode;
3307 ++ const struct iwl_ucode_header *ucode;
3308 + int ret = -EINVAL, index;
3309 + const struct firmware *ucode_raw;
3310 + /* firmware file name contains uCode/driver compatibility version */
3311 +@@ -2152,22 +2152,24 @@ static int iwl3945_read_ucode(struct iwl_priv *priv)
3312 + goto error;
3313 +
3314 + /* Make sure that we got at least our header! */
3315 +- if (ucode_raw->size < sizeof(*ucode)) {
3316 ++ if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
3317 + IWL_ERR(priv, "File size way too small!\n");
3318 + ret = -EINVAL;
3319 + goto err_release;
3320 + }
3321 +
3322 + /* Data from ucode file: header followed by uCode images */
3323 +- ucode = (void *)ucode_raw->data;
3324 ++ ucode = (struct iwl_ucode_header *)ucode_raw->data;
3325 +
3326 + priv->ucode_ver = le32_to_cpu(ucode->ver);
3327 + api_ver = IWL_UCODE_API(priv->ucode_ver);
3328 +- inst_size = le32_to_cpu(ucode->inst_size);
3329 +- data_size = le32_to_cpu(ucode->data_size);
3330 +- init_size = le32_to_cpu(ucode->init_size);
3331 +- init_data_size = le32_to_cpu(ucode->init_data_size);
3332 +- boot_size = le32_to_cpu(ucode->boot_size);
3333 ++ inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
3334 ++ data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
3335 ++ init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
3336 ++ init_data_size =
3337 ++ priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
3338 ++ boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
3339 ++ src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
3340 +
3341 + /* api_ver should match the api version forming part of the
3342 + * firmware filename ... but we don't check for that and only rely
3343 +@@ -2208,12 +2210,13 @@ static int iwl3945_read_ucode(struct iwl_priv *priv)
3344 +
3345 +
3346 + /* Verify size of file vs. image size info in file's header */
3347 +- if (ucode_raw->size < sizeof(*ucode) +
3348 ++ if (ucode_raw->size != priv->cfg->ops->ucode->get_header_size(api_ver) +
3349 + inst_size + data_size + init_size +
3350 + init_data_size + boot_size) {
3351 +
3352 +- IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
3353 +- ucode_raw->size);
3354 ++ IWL_DEBUG_INFO(priv,
3355 ++ "uCode file size %zd does not match expected size\n",
3356 ++ ucode_raw->size);
3357 + ret = -EINVAL;
3358 + goto err_release;
3359 + }
3360 +@@ -2296,44 +2299,44 @@ static int iwl3945_read_ucode(struct iwl_priv *priv)
3361 + /* Copy images into buffers for card's bus-master reads ... */
3362 +
3363 + /* Runtime instructions (first block of data in file) */
3364 +- src = &ucode->data[0];
3365 +- len = priv->ucode_code.len;
3366 ++ len = inst_size;
3367 + IWL_DEBUG_INFO(priv,
3368 + "Copying (but not loading) uCode instr len %zd\n", len);
3369 + memcpy(priv->ucode_code.v_addr, src, len);
3370 ++ src += len;
3371 ++
3372 + IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
3373 + priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
3374 +
3375 + /* Runtime data (2nd block)
3376 + * NOTE: Copy into backup buffer will be done in iwl3945_up() */
3377 +- src = &ucode->data[inst_size];
3378 +- len = priv->ucode_data.len;
3379 ++ len = data_size;
3380 + IWL_DEBUG_INFO(priv,
3381 + "Copying (but not loading) uCode data len %zd\n", len);
3382 + memcpy(priv->ucode_data.v_addr, src, len);
3383 + memcpy(priv->ucode_data_backup.v_addr, src, len);
3384 ++ src += len;
3385 +
3386 + /* Initialization instructions (3rd block) */
3387 + if (init_size) {
3388 +- src = &ucode->data[inst_size + data_size];
3389 +- len = priv->ucode_init.len;
3390 ++ len = init_size;
3391 + IWL_DEBUG_INFO(priv,
3392 + "Copying (but not loading) init instr len %zd\n", len);
3393 + memcpy(priv->ucode_init.v_addr, src, len);
3394 ++ src += len;
3395 + }
3396 +
3397 + /* Initialization data (4th block) */
3398 + if (init_data_size) {
3399 +- src = &ucode->data[inst_size + data_size + init_size];
3400 +- len = priv->ucode_init_data.len;
3401 ++ len = init_data_size;
3402 + IWL_DEBUG_INFO(priv,
3403 + "Copying (but not loading) init data len %zd\n", len);
3404 + memcpy(priv->ucode_init_data.v_addr, src, len);
3405 ++ src += len;
3406 + }
3407 +
3408 + /* Bootstrap instructions (5th block) */
3409 +- src = &ucode->data[inst_size + data_size + init_size + init_data_size];
3410 +- len = priv->ucode_boot.len;
3411 ++ len = boot_size;
3412 + IWL_DEBUG_INFO(priv,
3413 + "Copying (but not loading) boot instr len %zd\n", len);
3414 + memcpy(priv->ucode_boot.v_addr, src, len);
3415 +diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
3416 +index 0e877a1..6e1b889 100644
3417 +--- a/drivers/net/wireless/p54/p54usb.c
3418 ++++ b/drivers/net/wireless/p54/p54usb.c
3419 +@@ -66,6 +66,7 @@ static struct usb_device_id p54u_table[] __devinitdata = {
3420 + {USB_DEVICE(0x0bf8, 0x1009)}, /* FUJITSU E-5400 USB D1700*/
3421 + {USB_DEVICE(0x0cde, 0x0006)}, /* Medion MD40900 */
3422 + {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */
3423 ++ {USB_DEVICE(0x0cde, 0x0015)}, /* Zcomax XG-705A */
3424 + {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */
3425 + {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */
3426 + {USB_DEVICE(0x1260, 0xee22)}, /* SMC 2862W-G version 2 */
3427 +diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
3428 +index 9e1140f..e1dcced 100644
3429 +--- a/drivers/pcmcia/at91_cf.c
3430 ++++ b/drivers/pcmcia/at91_cf.c
3431 +@@ -363,7 +363,7 @@ static int at91_cf_suspend(struct platform_device *pdev, pm_message_t mesg)
3432 + struct at91_cf_socket *cf = platform_get_drvdata(pdev);
3433 + struct at91_cf_data *board = cf->board;
3434 +
3435 +- pcmcia_socket_dev_suspend(&pdev->dev, mesg);
3436 ++ pcmcia_socket_dev_suspend(&pdev->dev);
3437 + if (device_may_wakeup(&pdev->dev)) {
3438 + enable_irq_wake(board->det_pin);
3439 + if (board->irq_pin)
3440 +diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
3441 +index 9001334..0208870 100644
3442 +--- a/drivers/pcmcia/au1000_generic.c
3443 ++++ b/drivers/pcmcia/au1000_generic.c
3444 +@@ -515,7 +515,7 @@ static int au1x00_drv_pcmcia_probe(struct platform_device *dev)
3445 + static int au1x00_drv_pcmcia_suspend(struct platform_device *dev,
3446 + pm_message_t state)
3447 + {
3448 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3449 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3450 + }
3451 +
3452 + static int au1x00_drv_pcmcia_resume(struct platform_device *dev)
3453 +diff --git a/drivers/pcmcia/bfin_cf_pcmcia.c b/drivers/pcmcia/bfin_cf_pcmcia.c
3454 +index b59d411..300b368 100644
3455 +--- a/drivers/pcmcia/bfin_cf_pcmcia.c
3456 ++++ b/drivers/pcmcia/bfin_cf_pcmcia.c
3457 +@@ -302,7 +302,7 @@ static int __devexit bfin_cf_remove(struct platform_device *pdev)
3458 +
3459 + static int bfin_cf_suspend(struct platform_device *pdev, pm_message_t mesg)
3460 + {
3461 +- return pcmcia_socket_dev_suspend(&pdev->dev, mesg);
3462 ++ return pcmcia_socket_dev_suspend(&pdev->dev);
3463 + }
3464 +
3465 + static int bfin_cf_resume(struct platform_device *pdev)
3466 +diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
3467 +index 0660ad1..934d4be 100644
3468 +--- a/drivers/pcmcia/cs.c
3469 ++++ b/drivers/pcmcia/cs.c
3470 +@@ -101,7 +101,7 @@ EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
3471 + static int socket_resume(struct pcmcia_socket *skt);
3472 + static int socket_suspend(struct pcmcia_socket *skt);
3473 +
3474 +-int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state)
3475 ++int pcmcia_socket_dev_suspend(struct device *dev)
3476 + {
3477 + struct pcmcia_socket *socket;
3478 +
3479 +diff --git a/drivers/pcmcia/i82092.c b/drivers/pcmcia/i82092.c
3480 +index 46561fa..a04f21c 100644
3481 +--- a/drivers/pcmcia/i82092.c
3482 ++++ b/drivers/pcmcia/i82092.c
3483 +@@ -42,7 +42,7 @@ MODULE_DEVICE_TABLE(pci, i82092aa_pci_ids);
3484 + #ifdef CONFIG_PM
3485 + static int i82092aa_socket_suspend (struct pci_dev *dev, pm_message_t state)
3486 + {
3487 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3488 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3489 + }
3490 +
3491 + static int i82092aa_socket_resume (struct pci_dev *dev)
3492 +diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
3493 +index 40d4953..b906abe 100644
3494 +--- a/drivers/pcmcia/i82365.c
3495 ++++ b/drivers/pcmcia/i82365.c
3496 +@@ -1241,7 +1241,7 @@ static int pcic_init(struct pcmcia_socket *s)
3497 + static int i82365_drv_pcmcia_suspend(struct platform_device *dev,
3498 + pm_message_t state)
3499 + {
3500 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3501 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3502 + }
3503 +
3504 + static int i82365_drv_pcmcia_resume(struct platform_device *dev)
3505 +diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
3506 +index 62b4ecc..d1d89c4 100644
3507 +--- a/drivers/pcmcia/m32r_cfc.c
3508 ++++ b/drivers/pcmcia/m32r_cfc.c
3509 +@@ -699,7 +699,7 @@ static struct pccard_operations pcc_operations = {
3510 + static int cfc_drv_pcmcia_suspend(struct platform_device *dev,
3511 + pm_message_t state)
3512 + {
3513 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3514 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3515 + }
3516 +
3517 + static int cfc_drv_pcmcia_resume(struct platform_device *dev)
3518 +diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c
3519 +index 12034b4..a065583 100644
3520 +--- a/drivers/pcmcia/m32r_pcc.c
3521 ++++ b/drivers/pcmcia/m32r_pcc.c
3522 +@@ -675,7 +675,7 @@ static struct pccard_operations pcc_operations = {
3523 + static int pcc_drv_pcmcia_suspend(struct platform_device *dev,
3524 + pm_message_t state)
3525 + {
3526 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3527 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3528 + }
3529 +
3530 + static int pcc_drv_pcmcia_resume(struct platform_device *dev)
3531 +diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
3532 +index d1ad096..c69f2c4 100644
3533 +--- a/drivers/pcmcia/m8xx_pcmcia.c
3534 ++++ b/drivers/pcmcia/m8xx_pcmcia.c
3535 +@@ -1296,7 +1296,7 @@ static int m8xx_remove(struct of_device *ofdev)
3536 + #ifdef CONFIG_PM
3537 + static int m8xx_suspend(struct platform_device *pdev, pm_message_t state)
3538 + {
3539 +- return pcmcia_socket_dev_suspend(&pdev->dev, state);
3540 ++ return pcmcia_socket_dev_suspend(&pdev->dev);
3541 + }
3542 +
3543 + static int m8xx_resume(struct platform_device *pdev)
3544 +diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
3545 +index f373639..68570bc 100644
3546 +--- a/drivers/pcmcia/omap_cf.c
3547 ++++ b/drivers/pcmcia/omap_cf.c
3548 +@@ -334,7 +334,7 @@ static int __exit omap_cf_remove(struct platform_device *pdev)
3549 +
3550 + static int omap_cf_suspend(struct platform_device *pdev, pm_message_t mesg)
3551 + {
3552 +- return pcmcia_socket_dev_suspend(&pdev->dev, mesg);
3553 ++ return pcmcia_socket_dev_suspend(&pdev->dev);
3554 + }
3555 +
3556 + static int omap_cf_resume(struct platform_device *pdev)
3557 +diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c
3558 +index 8bed1da..1c39d34 100644
3559 +--- a/drivers/pcmcia/pd6729.c
3560 ++++ b/drivers/pcmcia/pd6729.c
3561 +@@ -758,7 +758,7 @@ static void __devexit pd6729_pci_remove(struct pci_dev *dev)
3562 + #ifdef CONFIG_PM
3563 + static int pd6729_socket_suspend(struct pci_dev *dev, pm_message_t state)
3564 + {
3565 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3566 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3567 + }
3568 +
3569 + static int pd6729_socket_resume(struct pci_dev *dev)
3570 +diff --git a/drivers/pcmcia/pxa2xx_base.c b/drivers/pcmcia/pxa2xx_base.c
3571 +index c49a726..86ad876 100644
3572 +--- a/drivers/pcmcia/pxa2xx_base.c
3573 ++++ b/drivers/pcmcia/pxa2xx_base.c
3574 +@@ -302,7 +302,7 @@ static int pxa2xx_drv_pcmcia_remove(struct platform_device *dev)
3575 +
3576 + static int pxa2xx_drv_pcmcia_suspend(struct platform_device *dev, pm_message_t state)
3577 + {
3578 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3579 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3580 + }
3581 +
3582 + static int pxa2xx_drv_pcmcia_resume(struct platform_device *dev)
3583 +diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c
3584 +index d8da5ac..2d0e997 100644
3585 +--- a/drivers/pcmcia/sa1100_generic.c
3586 ++++ b/drivers/pcmcia/sa1100_generic.c
3587 +@@ -89,7 +89,7 @@ static int sa11x0_drv_pcmcia_remove(struct platform_device *dev)
3588 + static int sa11x0_drv_pcmcia_suspend(struct platform_device *dev,
3589 + pm_message_t state)
3590 + {
3591 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3592 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3593 + }
3594 +
3595 + static int sa11x0_drv_pcmcia_resume(struct platform_device *dev)
3596 +diff --git a/drivers/pcmcia/sa1111_generic.c b/drivers/pcmcia/sa1111_generic.c
3597 +index 401052a..4be4e17 100644
3598 +--- a/drivers/pcmcia/sa1111_generic.c
3599 ++++ b/drivers/pcmcia/sa1111_generic.c
3600 +@@ -159,7 +159,7 @@ static int __devexit pcmcia_remove(struct sa1111_dev *dev)
3601 +
3602 + static int pcmcia_suspend(struct sa1111_dev *dev, pm_message_t state)
3603 + {
3604 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3605 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3606 + }
3607 +
3608 + static int pcmcia_resume(struct sa1111_dev *dev)
3609 +diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c
3610 +index 8eb0423..582413f 100644
3611 +--- a/drivers/pcmcia/tcic.c
3612 ++++ b/drivers/pcmcia/tcic.c
3613 +@@ -366,7 +366,7 @@ static int __init get_tcic_id(void)
3614 + static int tcic_drv_pcmcia_suspend(struct platform_device *dev,
3615 + pm_message_t state)
3616 + {
3617 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3618 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3619 + }
3620 +
3621 + static int tcic_drv_pcmcia_resume(struct platform_device *dev)
3622 +diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c
3623 +index d4ad50d..c9fcbdc 100644
3624 +--- a/drivers/pcmcia/vrc4171_card.c
3625 ++++ b/drivers/pcmcia/vrc4171_card.c
3626 +@@ -707,7 +707,7 @@ __setup("vrc4171_card=", vrc4171_card_setup);
3627 + static int vrc4171_card_suspend(struct platform_device *dev,
3628 + pm_message_t state)
3629 + {
3630 +- return pcmcia_socket_dev_suspend(&dev->dev, state);
3631 ++ return pcmcia_socket_dev_suspend(&dev->dev);
3632 + }
3633 +
3634 + static int vrc4171_card_resume(struct platform_device *dev)
3635 +diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
3636 +index 3ecd7c9..f728a45 100644
3637 +--- a/drivers/pcmcia/yenta_socket.c
3638 ++++ b/drivers/pcmcia/yenta_socket.c
3639 +@@ -1225,60 +1225,71 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
3640 + }
3641 +
3642 + #ifdef CONFIG_PM
3643 +-static int yenta_dev_suspend (struct pci_dev *dev, pm_message_t state)
3644 ++static int yenta_dev_suspend_noirq(struct device *dev)
3645 + {
3646 +- struct yenta_socket *socket = pci_get_drvdata(dev);
3647 ++ struct pci_dev *pdev = to_pci_dev(dev);
3648 ++ struct yenta_socket *socket = pci_get_drvdata(pdev);
3649 + int ret;
3650 +
3651 +- ret = pcmcia_socket_dev_suspend(&dev->dev, state);
3652 ++ ret = pcmcia_socket_dev_suspend(dev);
3653 +
3654 +- if (socket) {
3655 +- if (socket->type && socket->type->save_state)
3656 +- socket->type->save_state(socket);
3657 ++ if (!socket)
3658 ++ return ret;
3659 +
3660 +- /* FIXME: pci_save_state needs to have a better interface */
3661 +- pci_save_state(dev);
3662 +- pci_read_config_dword(dev, 16*4, &socket->saved_state[0]);
3663 +- pci_read_config_dword(dev, 17*4, &socket->saved_state[1]);
3664 +- pci_disable_device(dev);
3665 ++ if (socket->type && socket->type->save_state)
3666 ++ socket->type->save_state(socket);
3667 +
3668 +- /*
3669 +- * Some laptops (IBM T22) do not like us putting the Cardbus
3670 +- * bridge into D3. At a guess, some other laptop will
3671 +- * probably require this, so leave it commented out for now.
3672 +- */
3673 +- /* pci_set_power_state(dev, 3); */
3674 +- }
3675 ++ pci_save_state(pdev);
3676 ++ pci_read_config_dword(pdev, 16*4, &socket->saved_state[0]);
3677 ++ pci_read_config_dword(pdev, 17*4, &socket->saved_state[1]);
3678 ++ pci_disable_device(pdev);
3679 ++
3680 ++ /*
3681 ++ * Some laptops (IBM T22) do not like us putting the Cardbus
3682 ++ * bridge into D3. At a guess, some other laptop will
3683 ++ * probably require this, so leave it commented out for now.
3684 ++ */
3685 ++ /* pci_set_power_state(dev, 3); */
3686 +
3687 + return ret;
3688 + }
3689 +
3690 +-
3691 +-static int yenta_dev_resume (struct pci_dev *dev)
3692 ++static int yenta_dev_resume_noirq(struct device *dev)
3693 + {
3694 +- struct yenta_socket *socket = pci_get_drvdata(dev);
3695 ++ struct pci_dev *pdev = to_pci_dev(dev);
3696 ++ struct yenta_socket *socket = pci_get_drvdata(pdev);
3697 ++ int ret;
3698 +
3699 +- if (socket) {
3700 +- int rc;
3701 ++ if (!socket)
3702 ++ return 0;
3703 +
3704 +- pci_set_power_state(dev, 0);
3705 +- /* FIXME: pci_restore_state needs to have a better interface */
3706 +- pci_restore_state(dev);
3707 +- pci_write_config_dword(dev, 16*4, socket->saved_state[0]);
3708 +- pci_write_config_dword(dev, 17*4, socket->saved_state[1]);
3709 ++ pci_write_config_dword(pdev, 16*4, socket->saved_state[0]);
3710 ++ pci_write_config_dword(pdev, 17*4, socket->saved_state[1]);
3711 +
3712 +- rc = pci_enable_device(dev);
3713 +- if (rc)
3714 +- return rc;
3715 ++ ret = pci_enable_device(pdev);
3716 ++ if (ret)
3717 ++ return ret;
3718 +
3719 +- pci_set_master(dev);
3720 ++ pci_set_master(pdev);
3721 +
3722 +- if (socket->type && socket->type->restore_state)
3723 +- socket->type->restore_state(socket);
3724 +- }
3725 ++ if (socket->type && socket->type->restore_state)
3726 ++ socket->type->restore_state(socket);
3727 +
3728 +- return pcmcia_socket_dev_resume(&dev->dev);
3729 ++ return pcmcia_socket_dev_resume(dev);
3730 + }
3731 ++
3732 ++static struct dev_pm_ops yenta_pm_ops = {
3733 ++ .suspend_noirq = yenta_dev_suspend_noirq,
3734 ++ .resume_noirq = yenta_dev_resume_noirq,
3735 ++ .freeze_noirq = yenta_dev_suspend_noirq,
3736 ++ .thaw_noirq = yenta_dev_resume_noirq,
3737 ++ .poweroff_noirq = yenta_dev_suspend_noirq,
3738 ++ .restore_noirq = yenta_dev_resume_noirq,
3739 ++};
3740 ++
3741 ++#define YENTA_PM_OPS (&yenta_pm_ops)
3742 ++#else
3743 ++#define YENTA_PM_OPS NULL
3744 + #endif
3745 +
3746 + #define CB_ID(vend,dev,type) \
3747 +@@ -1376,10 +1387,7 @@ static struct pci_driver yenta_cardbus_driver = {
3748 + .id_table = yenta_table,
3749 + .probe = yenta_probe,
3750 + .remove = __devexit_p(yenta_close),
3751 +-#ifdef CONFIG_PM
3752 +- .suspend = yenta_dev_suspend,
3753 +- .resume = yenta_dev_resume,
3754 +-#endif
3755 ++ .driver.pm = YENTA_PM_OPS,
3756 + };
3757 +
3758 +
3759 +diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
3760 +index dafaa4a..a234a9d 100644
3761 +--- a/drivers/platform/x86/sony-laptop.c
3762 ++++ b/drivers/platform/x86/sony-laptop.c
3763 +@@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
3764 + struct rfkill *rfk;
3765 + enum rfkill_type type;
3766 + const char *name;
3767 ++ int result;
3768 ++ bool hwblock;
3769 +
3770 + switch (nc_type) {
3771 + case SONY_WIFI:
3772 +@@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
3773 + if (!rfk)
3774 + return -ENOMEM;
3775 +
3776 ++ sony_call_snc_handle(0x124, 0x200, &result);
3777 ++ hwblock = !(result & 0x1);
3778 ++ rfkill_set_hw_state(rfk, hwblock);
3779 ++
3780 + err = rfkill_register(rfk);
3781 + if (err) {
3782 + rfkill_destroy(rfk);
3783 +diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
3784 +index e856008..d287283 100644
3785 +--- a/drivers/platform/x86/thinkpad_acpi.c
3786 ++++ b/drivers/platform/x86/thinkpad_acpi.c
3787 +@@ -5655,16 +5655,16 @@ static const struct tpacpi_quirk brightness_quirk_table[] __initconst = {
3788 + /* Models with ATI GPUs known to require ECNVRAM mode */
3789 + TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */
3790 +
3791 +- /* Models with ATI GPUs (waiting confirmation) */
3792 +- TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
3793 ++ /* Models with ATI GPUs that can use ECNVRAM */
3794 ++ TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC),
3795 + TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
3796 + TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
3797 + TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
3798 +
3799 +- /* Models with Intel Extreme Graphics 2 (waiting confirmation) */
3800 ++ /* Models with Intel Extreme Graphics 2 */
3801 ++ TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC),
3802 + TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_NOEC),
3803 + TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_NOEC),
3804 +- TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_NOEC),
3805 +
3806 + /* Models with Intel GMA900 */
3807 + TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */
3808 +diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
3809 +index b4a7650..4fff4e5 100644
3810 +--- a/drivers/serial/bfin_5xx.c
3811 ++++ b/drivers/serial/bfin_5xx.c
3812 +@@ -42,6 +42,10 @@
3813 + # undef CONFIG_EARLY_PRINTK
3814 + #endif
3815 +
3816 ++#ifdef CONFIG_SERIAL_BFIN_MODULE
3817 ++# undef CONFIG_EARLY_PRINTK
3818 ++#endif
3819 ++
3820 + /* UART name and device definitions */
3821 + #define BFIN_SERIAL_NAME "ttyBF"
3822 + #define BFIN_SERIAL_MAJOR 204
3823 +diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
3824 +index 79c9c5f..6ecb51b 100644
3825 +--- a/drivers/serial/serial_cs.c
3826 ++++ b/drivers/serial/serial_cs.c
3827 +@@ -884,6 +884,7 @@ static struct pcmcia_device_id serial_ids[] = {
3828 + PCMCIA_DEVICE_CIS_MANF_CARD(0x0192, 0xa555, "SW_555_SER.cis"), /* Sierra Aircard 555 CDMA 1xrtt Modem -- pre update */
3829 + PCMCIA_DEVICE_CIS_MANF_CARD(0x013f, 0xa555, "SW_555_SER.cis"), /* Sierra Aircard 555 CDMA 1xrtt Modem -- post update */
3830 + PCMCIA_DEVICE_CIS_PROD_ID12("MultiTech", "PCMCIA 56K DataFax", 0x842047ee, 0xc2efcf03, "MT5634ZLX.cis"),
3831 ++ PCMCIA_DEVICE_CIS_PROD_ID12("ADVANTECH", "COMpad-32/85B-2", 0x96913a85, 0x27ab5437, "COMpad2.cis"),
3832 + PCMCIA_DEVICE_CIS_PROD_ID12("ADVANTECH", "COMpad-32/85B-4", 0x96913a85, 0xcec8f102, "COMpad4.cis"),
3833 + PCMCIA_DEVICE_CIS_PROD_ID123("ADVANTECH", "COMpad-32/85", "1.0", 0x96913a85, 0x8fbe92ae, 0x0877b627, "COMpad2.cis"),
3834 + PCMCIA_DEVICE_CIS_PROD_ID2("RS-COM 2P", 0xad20b156, "RS-COM-2P.cis"),
3835 +diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
3836 +index 2bfc41e..e3861b2 100644
3837 +--- a/drivers/usb/class/cdc-acm.c
3838 ++++ b/drivers/usb/class/cdc-acm.c
3839 +@@ -59,6 +59,7 @@
3840 + #include <linux/init.h>
3841 + #include <linux/slab.h>
3842 + #include <linux/tty.h>
3843 ++#include <linux/serial.h>
3844 + #include <linux/tty_driver.h>
3845 + #include <linux/tty_flip.h>
3846 + #include <linux/module.h>
3847 +@@ -609,6 +610,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
3848 + acm->throttle = 0;
3849 +
3850 + tasklet_schedule(&acm->urb_task);
3851 ++ set_bit(ASYNCB_INITIALIZED, &acm->port.flags);
3852 + rv = tty_port_block_til_ready(&acm->port, tty, filp);
3853 + done:
3854 + mutex_unlock(&acm->mutex);
3855 +@@ -858,10 +860,7 @@ static void acm_tty_set_termios(struct tty_struct *tty,
3856 + if (!ACM_READY(acm))
3857 + return;
3858 +
3859 +- /* FIXME: Needs to support the tty_baud interface */
3860 +- /* FIXME: Broken on sparc */
3861 +- newline.dwDTERate = cpu_to_le32p(acm_tty_speed +
3862 +- (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0));
3863 ++ newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty));
3864 + newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
3865 + newline.bParityType = termios->c_cflag & PARENB ?
3866 + (termios->c_cflag & PARODD ? 1 : 2) +
3867 +diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
3868 +index ba589d4..a9c3399 100644
3869 +--- a/drivers/usb/class/cdc-wdm.c
3870 ++++ b/drivers/usb/class/cdc-wdm.c
3871 +@@ -313,8 +313,13 @@ static ssize_t wdm_write
3872 + r = usb_autopm_get_interface(desc->intf);
3873 + if (r < 0)
3874 + goto outnp;
3875 +- r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
3876 +- &desc->flags));
3877 ++
3878 ++ if (!file->f_flags && O_NONBLOCK)
3879 ++ r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
3880 ++ &desc->flags));
3881 ++ else
3882 ++ if (test_bit(WDM_IN_USE, &desc->flags))
3883 ++ r = -EAGAIN;
3884 + if (r < 0)
3885 + goto out;
3886 +
3887 +@@ -377,7 +382,7 @@ outnl:
3888 + static ssize_t wdm_read
3889 + (struct file *file, char __user *buffer, size_t count, loff_t *ppos)
3890 + {
3891 +- int rv, cntr;
3892 ++ int rv, cntr = 0;
3893 + int i = 0;
3894 + struct wdm_device *desc = file->private_data;
3895 +
3896 +@@ -389,10 +394,23 @@ static ssize_t wdm_read
3897 + if (desc->length == 0) {
3898 + desc->read = 0;
3899 + retry:
3900 ++ if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
3901 ++ rv = -ENODEV;
3902 ++ goto err;
3903 ++ }
3904 + i++;
3905 +- rv = wait_event_interruptible(desc->wait,
3906 +- test_bit(WDM_READ, &desc->flags));
3907 ++ if (file->f_flags & O_NONBLOCK) {
3908 ++ if (!test_bit(WDM_READ, &desc->flags)) {
3909 ++ rv = cntr ? cntr : -EAGAIN;
3910 ++ goto err;
3911 ++ }
3912 ++ rv = 0;
3913 ++ } else {
3914 ++ rv = wait_event_interruptible(desc->wait,
3915 ++ test_bit(WDM_READ, &desc->flags));
3916 ++ }
3917 +
3918 ++ /* may have happened while we slept */
3919 + if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
3920 + rv = -ENODEV;
3921 + goto err;
3922 +@@ -448,7 +466,7 @@ retry:
3923 +
3924 + err:
3925 + mutex_unlock(&desc->rlock);
3926 +- if (rv < 0)
3927 ++ if (rv < 0 && rv != -EAGAIN)
3928 + dev_err(&desc->intf->dev, "wdm_read: exit error\n");
3929 + return rv;
3930 + }
3931 +diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
3932 +index b09a527..21b3719 100644
3933 +--- a/drivers/usb/class/usbtmc.c
3934 ++++ b/drivers/usb/class/usbtmc.c
3935 +@@ -367,13 +367,13 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
3936 + {
3937 + struct usbtmc_device_data *data;
3938 + struct device *dev;
3939 +- unsigned long int n_characters;
3940 ++ u32 n_characters;
3941 + u8 *buffer;
3942 + int actual;
3943 +- int done;
3944 +- int remaining;
3945 ++ size_t done;
3946 ++ size_t remaining;
3947 + int retval;
3948 +- int this_part;
3949 ++ size_t this_part;
3950 +
3951 + /* Get pointer to private data structure */
3952 + data = filp->private_data;
3953 +@@ -455,6 +455,18 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
3954 + (buffer[6] << 16) +
3955 + (buffer[7] << 24);
3956 +
3957 ++ /* Ensure the instrument doesn't lie about it */
3958 ++ if(n_characters > actual - 12) {
3959 ++ dev_err(dev, "Device lies about message size: %zu > %zu\n", n_characters, actual - 12);
3960 ++ n_characters = actual - 12;
3961 ++ }
3962 ++
3963 ++ /* Ensure the instrument doesn't send more back than requested */
3964 ++ if(n_characters > this_part) {
3965 ++ dev_err(dev, "Device returns more than requested: %zu > %zu\n", done + n_characters, done + this_part);
3966 ++ n_characters = this_part;
3967 ++ }
3968 ++
3969 + /* Copy buffer to user space */
3970 + if (copy_to_user(buf + done, &buffer[12], n_characters)) {
3971 + /* There must have been an addressing problem */
3972 +@@ -465,6 +477,8 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
3973 + done += n_characters;
3974 + if (n_characters < USBTMC_SIZE_IOBUFFER)
3975 + remaining = 0;
3976 ++ else
3977 ++ remaining -= n_characters;
3978 + }
3979 +
3980 + /* Update file position value */
3981 +diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
3982 +index a16c538..0d3af6a 100644
3983 +--- a/drivers/usb/core/config.c
3984 ++++ b/drivers/usb/core/config.c
3985 +@@ -105,7 +105,7 @@ static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
3986 + ep->ss_ep_comp->extralen = i;
3987 + buffer += i;
3988 + size -= i;
3989 +- retval = buffer - buffer_start + i;
3990 ++ retval = buffer - buffer_start;
3991 + if (num_skipped > 0)
3992 + dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
3993 + num_skipped, plural(num_skipped),
3994 +diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
3995 +index a949259..5b22a4d 100644
3996 +--- a/drivers/usb/host/sl811-hcd.c
3997 ++++ b/drivers/usb/host/sl811-hcd.c
3998 +@@ -719,8 +719,12 @@ retry:
3999 + /* port status seems weird until after reset, so
4000 + * force the reset and make khubd clean up later.
4001 + */
4002 +- sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
4003 +- | (1 << USB_PORT_FEAT_CONNECTION);
4004 ++ if (sl811->stat_insrmv & 1)
4005 ++ sl811->port1 |= 1 << USB_PORT_FEAT_CONNECTION;
4006 ++ else
4007 ++ sl811->port1 &= ~(1 << USB_PORT_FEAT_CONNECTION);
4008 ++
4009 ++ sl811->port1 |= 1 << USB_PORT_FEAT_C_CONNECTION;
4010 +
4011 + } else if (irqstat & SL11H_INTMASK_RD) {
4012 + if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) {
4013 +diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
4014 +index 705e343..33128d5 100644
4015 +--- a/drivers/usb/host/xhci-dbg.c
4016 ++++ b/drivers/usb/host/xhci-dbg.c
4017 +@@ -413,7 +413,8 @@ void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx)
4018 + int i;
4019 +
4020 + struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx);
4021 +- dma_addr_t dma = ctx->dma + ((unsigned long)slot_ctx - (unsigned long)ctx);
4022 ++ dma_addr_t dma = ctx->dma +
4023 ++ ((unsigned long)slot_ctx - (unsigned long)ctx->bytes);
4024 + int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params);
4025 +
4026 + xhci_dbg(xhci, "Slot Context:\n");
4027 +@@ -459,7 +460,7 @@ void xhci_dbg_ep_ctx(struct xhci_hcd *xhci,
4028 + for (i = 0; i < last_ep_ctx; ++i) {
4029 + struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, ctx, i);
4030 + dma_addr_t dma = ctx->dma +
4031 +- ((unsigned long)ep_ctx - (unsigned long)ctx);
4032 ++ ((unsigned long)ep_ctx - (unsigned long)ctx->bytes);
4033 +
4034 + xhci_dbg(xhci, "Endpoint %02d Context:\n", i);
4035 + xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n",
4036 +diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c
4037 +index 816c39c..e478a63 100644
4038 +--- a/drivers/usb/host/xhci-hcd.c
4039 ++++ b/drivers/usb/host/xhci-hcd.c
4040 +@@ -22,12 +22,18 @@
4041 +
4042 + #include <linux/irq.h>
4043 + #include <linux/module.h>
4044 ++#include <linux/moduleparam.h>
4045 +
4046 + #include "xhci.h"
4047 +
4048 + #define DRIVER_AUTHOR "Sarah Sharp"
4049 + #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
4050 +
4051 ++/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */
4052 ++static int link_quirk;
4053 ++module_param(link_quirk, int, S_IRUGO | S_IWUSR);
4054 ++MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB");
4055 ++
4056 + /* TODO: copied from ehci-hcd.c - can this be refactored? */
4057 + /*
4058 + * handshake - spin reading hc until handshake completes or fails
4059 +@@ -214,6 +220,12 @@ int xhci_init(struct usb_hcd *hcd)
4060 +
4061 + xhci_dbg(xhci, "xhci_init\n");
4062 + spin_lock_init(&xhci->lock);
4063 ++ if (link_quirk) {
4064 ++ xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n");
4065 ++ xhci->quirks |= XHCI_LINK_TRB_QUIRK;
4066 ++ } else {
4067 ++ xhci_dbg(xhci, "xHCI doesn't need link TRB QUIRK\n");
4068 ++ }
4069 + retval = xhci_mem_init(xhci, GFP_KERNEL);
4070 + xhci_dbg(xhci, "Finished xhci_init\n");
4071 +
4072 +@@ -555,13 +567,22 @@ unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc)
4073 + return 1 << (xhci_get_endpoint_index(desc) + 1);
4074 + }
4075 +
4076 ++/* Find the flag for this endpoint (for use in the control context). Use the
4077 ++ * endpoint index to create a bitmask. The slot context is bit 0, endpoint 0 is
4078 ++ * bit 1, etc.
4079 ++ */
4080 ++unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index)
4081 ++{
4082 ++ return 1 << (ep_index + 1);
4083 ++}
4084 ++
4085 + /* Compute the last valid endpoint context index. Basically, this is the
4086 + * endpoint index plus one. For slot contexts with more than valid endpoint,
4087 + * we find the most significant bit set in the added contexts flags.
4088 + * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000
4089 + * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one.
4090 + */
4091 +-static inline unsigned int xhci_last_valid_endpoint(u32 added_ctxs)
4092 ++unsigned int xhci_last_valid_endpoint(u32 added_ctxs)
4093 + {
4094 + return fls(added_ctxs) - 1;
4095 + }
4096 +@@ -589,6 +610,70 @@ int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev,
4097 + return 1;
4098 + }
4099 +
4100 ++static int xhci_configure_endpoint(struct xhci_hcd *xhci,
4101 ++ struct usb_device *udev, struct xhci_virt_device *virt_dev,
4102 ++ bool ctx_change);
4103 ++
4104 ++/*
4105 ++ * Full speed devices may have a max packet size greater than 8 bytes, but the
4106 ++ * USB core doesn't know that until it reads the first 8 bytes of the
4107 ++ * descriptor. If the usb_device's max packet size changes after that point,
4108 ++ * we need to issue an evaluate context command and wait on it.
4109 ++ */
4110 ++static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
4111 ++ unsigned int ep_index, struct urb *urb)
4112 ++{
4113 ++ struct xhci_container_ctx *in_ctx;
4114 ++ struct xhci_container_ctx *out_ctx;
4115 ++ struct xhci_input_control_ctx *ctrl_ctx;
4116 ++ struct xhci_ep_ctx *ep_ctx;
4117 ++ int max_packet_size;
4118 ++ int hw_max_packet_size;
4119 ++ int ret = 0;
4120 ++
4121 ++ out_ctx = xhci->devs[slot_id]->out_ctx;
4122 ++ ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
4123 ++ hw_max_packet_size = MAX_PACKET_DECODED(ep_ctx->ep_info2);
4124 ++ max_packet_size = urb->dev->ep0.desc.wMaxPacketSize;
4125 ++ if (hw_max_packet_size != max_packet_size) {
4126 ++ xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n");
4127 ++ xhci_dbg(xhci, "Max packet size in usb_device = %d\n",
4128 ++ max_packet_size);
4129 ++ xhci_dbg(xhci, "Max packet size in xHCI HW = %d\n",
4130 ++ hw_max_packet_size);
4131 ++ xhci_dbg(xhci, "Issuing evaluate context command.\n");
4132 ++
4133 ++ /* Set up the modified control endpoint 0 */
4134 ++ xhci_endpoint_copy(xhci, xhci->devs[slot_id], ep_index);
4135 ++ in_ctx = xhci->devs[slot_id]->in_ctx;
4136 ++ ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
4137 ++ ep_ctx->ep_info2 &= ~MAX_PACKET_MASK;
4138 ++ ep_ctx->ep_info2 |= MAX_PACKET(max_packet_size);
4139 ++
4140 ++ /* Set up the input context flags for the command */
4141 ++ /* FIXME: This won't work if a non-default control endpoint
4142 ++ * changes max packet sizes.
4143 ++ */
4144 ++ ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
4145 ++ ctrl_ctx->add_flags = EP0_FLAG;
4146 ++ ctrl_ctx->drop_flags = 0;
4147 ++
4148 ++ xhci_dbg(xhci, "Slot %d input context\n", slot_id);
4149 ++ xhci_dbg_ctx(xhci, in_ctx, ep_index);
4150 ++ xhci_dbg(xhci, "Slot %d output context\n", slot_id);
4151 ++ xhci_dbg_ctx(xhci, out_ctx, ep_index);
4152 ++
4153 ++ ret = xhci_configure_endpoint(xhci, urb->dev,
4154 ++ xhci->devs[slot_id], true);
4155 ++
4156 ++ /* Clean up the input context for later use by bandwidth
4157 ++ * functions.
4158 ++ */
4159 ++ ctrl_ctx->add_flags = SLOT_FLAG;
4160 ++ }
4161 ++ return ret;
4162 ++}
4163 ++
4164 + /*
4165 + * non-error returns are a promise to giveback() the urb later
4166 + * we drop ownership so next owner (or urb unlink) can get it
4167 +@@ -600,13 +685,13 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
4168 + int ret = 0;
4169 + unsigned int slot_id, ep_index;
4170 +
4171 ++
4172 + if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0)
4173 + return -EINVAL;
4174 +
4175 + slot_id = urb->dev->slot_id;
4176 + ep_index = xhci_get_endpoint_index(&urb->ep->desc);
4177 +
4178 +- spin_lock_irqsave(&xhci->lock, flags);
4179 + if (!xhci->devs || !xhci->devs[slot_id]) {
4180 + if (!in_interrupt())
4181 + dev_warn(&urb->dev->dev, "WARN: urb submitted for dev with no Slot ID\n");
4182 +@@ -619,19 +704,38 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
4183 + ret = -ESHUTDOWN;
4184 + goto exit;
4185 + }
4186 +- if (usb_endpoint_xfer_control(&urb->ep->desc))
4187 ++ if (usb_endpoint_xfer_control(&urb->ep->desc)) {
4188 ++ /* Check to see if the max packet size for the default control
4189 ++ * endpoint changed during FS device enumeration
4190 ++ */
4191 ++ if (urb->dev->speed == USB_SPEED_FULL) {
4192 ++ ret = xhci_check_maxpacket(xhci, slot_id,
4193 ++ ep_index, urb);
4194 ++ if (ret < 0)
4195 ++ return ret;
4196 ++ }
4197 ++
4198 + /* We have a spinlock and interrupts disabled, so we must pass
4199 + * atomic context to this function, which may allocate memory.
4200 + */
4201 ++ spin_lock_irqsave(&xhci->lock, flags);
4202 + ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
4203 + slot_id, ep_index);
4204 +- else if (usb_endpoint_xfer_bulk(&urb->ep->desc))
4205 ++ spin_unlock_irqrestore(&xhci->lock, flags);
4206 ++ } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) {
4207 ++ spin_lock_irqsave(&xhci->lock, flags);
4208 + ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb,
4209 + slot_id, ep_index);
4210 +- else
4211 ++ spin_unlock_irqrestore(&xhci->lock, flags);
4212 ++ } else if (usb_endpoint_xfer_int(&urb->ep->desc)) {
4213 ++ spin_lock_irqsave(&xhci->lock, flags);
4214 ++ ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb,
4215 ++ slot_id, ep_index);
4216 ++ spin_unlock_irqrestore(&xhci->lock, flags);
4217 ++ } else {
4218 + ret = -EINVAL;
4219 ++ }
4220 + exit:
4221 +- spin_unlock_irqrestore(&xhci->lock, flags);
4222 + return ret;
4223 + }
4224 +
4225 +@@ -930,6 +1034,122 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir
4226 + }
4227 + }
4228 +
4229 ++static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
4230 ++ struct usb_device *udev, struct xhci_virt_device *virt_dev)
4231 ++{
4232 ++ int ret;
4233 ++
4234 ++ switch (virt_dev->cmd_status) {
4235 ++ case COMP_ENOMEM:
4236 ++ dev_warn(&udev->dev, "Not enough host controller resources "
4237 ++ "for new device state.\n");
4238 ++ ret = -ENOMEM;
4239 ++ /* FIXME: can we allocate more resources for the HC? */
4240 ++ break;
4241 ++ case COMP_BW_ERR:
4242 ++ dev_warn(&udev->dev, "Not enough bandwidth "
4243 ++ "for new device state.\n");
4244 ++ ret = -ENOSPC;
4245 ++ /* FIXME: can we go back to the old state? */
4246 ++ break;
4247 ++ case COMP_TRB_ERR:
4248 ++ /* the HCD set up something wrong */
4249 ++ dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, "
4250 ++ "add flag = 1, "
4251 ++ "and endpoint is not disabled.\n");
4252 ++ ret = -EINVAL;
4253 ++ break;
4254 ++ case COMP_SUCCESS:
4255 ++ dev_dbg(&udev->dev, "Successful Endpoint Configure command\n");
4256 ++ ret = 0;
4257 ++ break;
4258 ++ default:
4259 ++ xhci_err(xhci, "ERROR: unexpected command completion "
4260 ++ "code 0x%x.\n", virt_dev->cmd_status);
4261 ++ ret = -EINVAL;
4262 ++ break;
4263 ++ }
4264 ++ return ret;
4265 ++}
4266 ++
4267 ++static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
4268 ++ struct usb_device *udev, struct xhci_virt_device *virt_dev)
4269 ++{
4270 ++ int ret;
4271 ++
4272 ++ switch (virt_dev->cmd_status) {
4273 ++ case COMP_EINVAL:
4274 ++ dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate "
4275 ++ "context command.\n");
4276 ++ ret = -EINVAL;
4277 ++ break;
4278 ++ case COMP_EBADSLT:
4279 ++ dev_warn(&udev->dev, "WARN: slot not enabled for"
4280 ++ "evaluate context command.\n");
4281 ++ case COMP_CTX_STATE:
4282 ++ dev_warn(&udev->dev, "WARN: invalid context state for "
4283 ++ "evaluate context command.\n");
4284 ++ xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1);
4285 ++ ret = -EINVAL;
4286 ++ break;
4287 ++ case COMP_SUCCESS:
4288 ++ dev_dbg(&udev->dev, "Successful evaluate context command\n");
4289 ++ ret = 0;
4290 ++ break;
4291 ++ default:
4292 ++ xhci_err(xhci, "ERROR: unexpected command completion "
4293 ++ "code 0x%x.\n", virt_dev->cmd_status);
4294 ++ ret = -EINVAL;
4295 ++ break;
4296 ++ }
4297 ++ return ret;
4298 ++}
4299 ++
4300 ++/* Issue a configure endpoint command or evaluate context command
4301 ++ * and wait for it to finish.
4302 ++ */
4303 ++static int xhci_configure_endpoint(struct xhci_hcd *xhci,
4304 ++ struct usb_device *udev, struct xhci_virt_device *virt_dev,
4305 ++ bool ctx_change)
4306 ++{
4307 ++ int ret;
4308 ++ int timeleft;
4309 ++ unsigned long flags;
4310 ++
4311 ++ spin_lock_irqsave(&xhci->lock, flags);
4312 ++ if (!ctx_change)
4313 ++ ret = xhci_queue_configure_endpoint(xhci, virt_dev->in_ctx->dma,
4314 ++ udev->slot_id);
4315 ++ else
4316 ++ ret = xhci_queue_evaluate_context(xhci, virt_dev->in_ctx->dma,
4317 ++ udev->slot_id);
4318 ++ if (ret < 0) {
4319 ++ spin_unlock_irqrestore(&xhci->lock, flags);
4320 ++ xhci_dbg(xhci, "FIXME allocate a new ring segment\n");
4321 ++ return -ENOMEM;
4322 ++ }
4323 ++ xhci_ring_cmd_db(xhci);
4324 ++ spin_unlock_irqrestore(&xhci->lock, flags);
4325 ++
4326 ++ /* Wait for the configure endpoint command to complete */
4327 ++ timeleft = wait_for_completion_interruptible_timeout(
4328 ++ &virt_dev->cmd_completion,
4329 ++ USB_CTRL_SET_TIMEOUT);
4330 ++ if (timeleft <= 0) {
4331 ++ xhci_warn(xhci, "%s while waiting for %s command\n",
4332 ++ timeleft == 0 ? "Timeout" : "Signal",
4333 ++ ctx_change == 0 ?
4334 ++ "configure endpoint" :
4335 ++ "evaluate context");
4336 ++ /* FIXME cancel the configure endpoint command */
4337 ++ return -ETIME;
4338 ++ }
4339 ++
4340 ++ if (!ctx_change)
4341 ++ return xhci_configure_endpoint_result(xhci, udev, virt_dev);
4342 ++ return xhci_evaluate_context_result(xhci, udev, virt_dev);
4343 ++}
4344 ++
4345 + /* Called after one or more calls to xhci_add_endpoint() or
4346 + * xhci_drop_endpoint(). If this call fails, the USB core is expected
4347 + * to call xhci_reset_bandwidth().
4348 +@@ -944,8 +1164,6 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
4349 + {
4350 + int i;
4351 + int ret = 0;
4352 +- int timeleft;
4353 +- unsigned long flags;
4354 + struct xhci_hcd *xhci;
4355 + struct xhci_virt_device *virt_dev;
4356 + struct xhci_input_control_ctx *ctrl_ctx;
4357 +@@ -975,56 +1193,7 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
4358 + xhci_dbg_ctx(xhci, virt_dev->in_ctx,
4359 + LAST_CTX_TO_EP_NUM(slot_ctx->dev_info));
4360 +
4361 +- spin_lock_irqsave(&xhci->lock, flags);
4362 +- ret = xhci_queue_configure_endpoint(xhci, virt_dev->in_ctx->dma,
4363 +- udev->slot_id);
4364 +- if (ret < 0) {
4365 +- spin_unlock_irqrestore(&xhci->lock, flags);
4366 +- xhci_dbg(xhci, "FIXME allocate a new ring segment\n");
4367 +- return -ENOMEM;
4368 +- }
4369 +- xhci_ring_cmd_db(xhci);
4370 +- spin_unlock_irqrestore(&xhci->lock, flags);
4371 +-
4372 +- /* Wait for the configure endpoint command to complete */
4373 +- timeleft = wait_for_completion_interruptible_timeout(
4374 +- &virt_dev->cmd_completion,
4375 +- USB_CTRL_SET_TIMEOUT);
4376 +- if (timeleft <= 0) {
4377 +- xhci_warn(xhci, "%s while waiting for configure endpoint command\n",
4378 +- timeleft == 0 ? "Timeout" : "Signal");
4379 +- /* FIXME cancel the configure endpoint command */
4380 +- return -ETIME;
4381 +- }
4382 +-
4383 +- switch (virt_dev->cmd_status) {
4384 +- case COMP_ENOMEM:
4385 +- dev_warn(&udev->dev, "Not enough host controller resources "
4386 +- "for new device state.\n");
4387 +- ret = -ENOMEM;
4388 +- /* FIXME: can we allocate more resources for the HC? */
4389 +- break;
4390 +- case COMP_BW_ERR:
4391 +- dev_warn(&udev->dev, "Not enough bandwidth "
4392 +- "for new device state.\n");
4393 +- ret = -ENOSPC;
4394 +- /* FIXME: can we go back to the old state? */
4395 +- break;
4396 +- case COMP_TRB_ERR:
4397 +- /* the HCD set up something wrong */
4398 +- dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, add flag = 1, "
4399 +- "and endpoint is not disabled.\n");
4400 +- ret = -EINVAL;
4401 +- break;
4402 +- case COMP_SUCCESS:
4403 +- dev_dbg(&udev->dev, "Successful Endpoint Configure command\n");
4404 +- break;
4405 +- default:
4406 +- xhci_err(xhci, "ERROR: unexpected command completion "
4407 +- "code 0x%x.\n", virt_dev->cmd_status);
4408 +- ret = -EINVAL;
4409 +- break;
4410 +- }
4411 ++ ret = xhci_configure_endpoint(xhci, udev, virt_dev, false);
4412 + if (ret) {
4413 + /* Callee should call reset_bandwidth() */
4414 + return ret;
4415 +@@ -1075,6 +1244,75 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
4416 + xhci_zero_in_ctx(xhci, virt_dev);
4417 + }
4418 +
4419 ++void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
4420 ++ unsigned int slot_id, unsigned int ep_index,
4421 ++ struct xhci_dequeue_state *deq_state)
4422 ++{
4423 ++ struct xhci_container_ctx *in_ctx;
4424 ++ struct xhci_input_control_ctx *ctrl_ctx;
4425 ++ struct xhci_ep_ctx *ep_ctx;
4426 ++ u32 added_ctxs;
4427 ++ dma_addr_t addr;
4428 ++
4429 ++ xhci_endpoint_copy(xhci, xhci->devs[slot_id], ep_index);
4430 ++ in_ctx = xhci->devs[slot_id]->in_ctx;
4431 ++ ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
4432 ++ addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg,
4433 ++ deq_state->new_deq_ptr);
4434 ++ if (addr == 0) {
4435 ++ xhci_warn(xhci, "WARN Cannot submit config ep after "
4436 ++ "reset ep command\n");
4437 ++ xhci_warn(xhci, "WARN deq seg = %p, deq ptr = %p\n",
4438 ++ deq_state->new_deq_seg,
4439 ++ deq_state->new_deq_ptr);
4440 ++ return;
4441 ++ }
4442 ++ ep_ctx->deq = addr | deq_state->new_cycle_state;
4443 ++
4444 ++ xhci_slot_copy(xhci, xhci->devs[slot_id]);
4445 ++
4446 ++ ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
4447 ++ added_ctxs = xhci_get_endpoint_flag_from_index(ep_index);
4448 ++ ctrl_ctx->add_flags = added_ctxs | SLOT_FLAG;
4449 ++ ctrl_ctx->drop_flags = added_ctxs;
4450 ++
4451 ++ xhci_dbg(xhci, "Slot ID %d Input Context:\n", slot_id);
4452 ++ xhci_dbg_ctx(xhci, in_ctx, ep_index);
4453 ++}
4454 ++
4455 ++void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
4456 ++ struct usb_device *udev,
4457 ++ unsigned int ep_index, struct xhci_ring *ep_ring)
4458 ++{
4459 ++ struct xhci_dequeue_state deq_state;
4460 ++
4461 ++ xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n");
4462 ++ /* We need to move the HW's dequeue pointer past this TD,
4463 ++ * or it will attempt to resend it on the next doorbell ring.
4464 ++ */
4465 ++ xhci_find_new_dequeue_state(xhci, udev->slot_id,
4466 ++ ep_index, ep_ring->stopped_td,
4467 ++ &deq_state);
4468 ++
4469 ++ /* HW with the reset endpoint quirk will use the saved dequeue state to
4470 ++ * issue a configure endpoint command later.
4471 ++ */
4472 ++ if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) {
4473 ++ xhci_dbg(xhci, "Queueing new dequeue state\n");
4474 ++ xhci_queue_new_dequeue_state(xhci, ep_ring,
4475 ++ udev->slot_id,
4476 ++ ep_index, &deq_state);
4477 ++ } else {
4478 ++ /* Better hope no one uses the input context between now and the
4479 ++ * reset endpoint completion!
4480 ++ */
4481 ++ xhci_dbg(xhci, "Setting up input context for "
4482 ++ "configure endpoint command\n");
4483 ++ xhci_setup_input_ctx_for_quirk(xhci, udev->slot_id,
4484 ++ ep_index, &deq_state);
4485 ++ }
4486 ++}
4487 ++
4488 + /* Deal with stalled endpoints. The core should have sent the control message
4489 + * to clear the halt condition. However, we need to make the xHCI hardware
4490 + * reset its sequence number, since a device will expect a sequence number of
4491 +@@ -1089,7 +1327,6 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
4492 + unsigned int ep_index;
4493 + unsigned long flags;
4494 + int ret;
4495 +- struct xhci_dequeue_state deq_state;
4496 + struct xhci_ring *ep_ring;
4497 +
4498 + xhci = hcd_to_xhci(hcd);
4499 +@@ -1106,6 +1343,10 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
4500 + ep->desc.bEndpointAddress);
4501 + return;
4502 + }
4503 ++ if (usb_endpoint_xfer_control(&ep->desc)) {
4504 ++ xhci_dbg(xhci, "Control endpoint stall already handled.\n");
4505 ++ return;
4506 ++ }
4507 +
4508 + xhci_dbg(xhci, "Queueing reset endpoint command\n");
4509 + spin_lock_irqsave(&xhci->lock, flags);
4510 +@@ -1116,16 +1357,7 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
4511 + * command. Better hope that last command worked!
4512 + */
4513 + if (!ret) {
4514 +- xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n");
4515 +- /* We need to move the HW's dequeue pointer past this TD,
4516 +- * or it will attempt to resend it on the next doorbell ring.
4517 +- */
4518 +- xhci_find_new_dequeue_state(xhci, udev->slot_id,
4519 +- ep_index, ep_ring->stopped_td, &deq_state);
4520 +- xhci_dbg(xhci, "Queueing new dequeue state\n");
4521 +- xhci_queue_new_dequeue_state(xhci, ep_ring,
4522 +- udev->slot_id,
4523 +- ep_index, &deq_state);
4524 ++ xhci_cleanup_stalled_ring(xhci, udev, ep_index, ep_ring);
4525 + kfree(ep_ring->stopped_td);
4526 + xhci_ring_cmd_db(xhci);
4527 + }
4528 +diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
4529 +index e6b9a1c..55920b3 100644
4530 +--- a/drivers/usb/host/xhci-mem.c
4531 ++++ b/drivers/usb/host/xhci-mem.c
4532 +@@ -94,6 +94,9 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev,
4533 + val = prev->trbs[TRBS_PER_SEGMENT-1].link.control;
4534 + val &= ~TRB_TYPE_BITMASK;
4535 + val |= TRB_TYPE(TRB_LINK);
4536 ++ /* Always set the chain bit with 0.95 hardware */
4537 ++ if (xhci_link_trb_quirk(xhci))
4538 ++ val |= TRB_CHAIN;
4539 + prev->trbs[TRBS_PER_SEGMENT-1].link.control = val;
4540 + }
4541 + xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n",
4542 +@@ -398,15 +401,28 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
4543 + /* Step 5 */
4544 + ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP);
4545 + /*
4546 +- * See section 4.3 bullet 6:
4547 +- * The default Max Packet size for ep0 is "8 bytes for a USB2
4548 +- * LS/FS/HS device or 512 bytes for a USB3 SS device"
4549 + * XXX: Not sure about wireless USB devices.
4550 + */
4551 +- if (udev->speed == USB_SPEED_SUPER)
4552 ++ switch (udev->speed) {
4553 ++ case USB_SPEED_SUPER:
4554 + ep0_ctx->ep_info2 |= MAX_PACKET(512);
4555 +- else
4556 ++ break;
4557 ++ case USB_SPEED_HIGH:
4558 ++ /* USB core guesses at a 64-byte max packet first for FS devices */
4559 ++ case USB_SPEED_FULL:
4560 ++ ep0_ctx->ep_info2 |= MAX_PACKET(64);
4561 ++ break;
4562 ++ case USB_SPEED_LOW:
4563 + ep0_ctx->ep_info2 |= MAX_PACKET(8);
4564 ++ break;
4565 ++ case USB_SPEED_VARIABLE:
4566 ++ xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
4567 ++ return -EINVAL;
4568 ++ break;
4569 ++ default:
4570 ++ /* New speed? */
4571 ++ BUG();
4572 ++ }
4573 + /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */
4574 + ep0_ctx->ep_info2 |= MAX_BURST(0);
4575 + ep0_ctx->ep_info2 |= ERROR_COUNT(3);
4576 +@@ -598,6 +614,44 @@ void xhci_endpoint_zero(struct xhci_hcd *xhci,
4577 + */
4578 + }
4579 +
4580 ++/* Copy output xhci_ep_ctx to the input xhci_ep_ctx copy.
4581 ++ * Useful when you want to change one particular aspect of the endpoint and then
4582 ++ * issue a configure endpoint command.
4583 ++ */
4584 ++void xhci_endpoint_copy(struct xhci_hcd *xhci,
4585 ++ struct xhci_virt_device *vdev, unsigned int ep_index)
4586 ++{
4587 ++ struct xhci_ep_ctx *out_ep_ctx;
4588 ++ struct xhci_ep_ctx *in_ep_ctx;
4589 ++
4590 ++ out_ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index);
4591 ++ in_ep_ctx = xhci_get_ep_ctx(xhci, vdev->in_ctx, ep_index);
4592 ++
4593 ++ in_ep_ctx->ep_info = out_ep_ctx->ep_info;
4594 ++ in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2;
4595 ++ in_ep_ctx->deq = out_ep_ctx->deq;
4596 ++ in_ep_ctx->tx_info = out_ep_ctx->tx_info;
4597 ++}
4598 ++
4599 ++/* Copy output xhci_slot_ctx to the input xhci_slot_ctx.
4600 ++ * Useful when you want to change one particular aspect of the endpoint and then
4601 ++ * issue a configure endpoint command. Only the context entries field matters,
4602 ++ * but we'll copy the whole thing anyway.
4603 ++ */
4604 ++void xhci_slot_copy(struct xhci_hcd *xhci, struct xhci_virt_device *vdev)
4605 ++{
4606 ++ struct xhci_slot_ctx *in_slot_ctx;
4607 ++ struct xhci_slot_ctx *out_slot_ctx;
4608 ++
4609 ++ in_slot_ctx = xhci_get_slot_ctx(xhci, vdev->in_ctx);
4610 ++ out_slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx);
4611 ++
4612 ++ in_slot_ctx->dev_info = out_slot_ctx->dev_info;
4613 ++ in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2;
4614 ++ in_slot_ctx->tt_info = out_slot_ctx->tt_info;
4615 ++ in_slot_ctx->dev_state = out_slot_ctx->dev_state;
4616 ++}
4617 ++
4618 + /* Set up the scratchpad buffer array and scratchpad buffers, if needed. */
4619 + static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
4620 + {
4621 +diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
4622 +index 592fe7e..8fb308d 100644
4623 +--- a/drivers/usb/host/xhci-pci.c
4624 ++++ b/drivers/usb/host/xhci-pci.c
4625 +@@ -24,6 +24,10 @@
4626 +
4627 + #include "xhci.h"
4628 +
4629 ++/* Device for a quirk */
4630 ++#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
4631 ++#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
4632 ++
4633 + static const char hcd_name[] = "xhci_hcd";
4634 +
4635 + /* called after powerup, by probe or system-pm "wakeup" */
4636 +@@ -62,6 +66,15 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
4637 + xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
4638 + xhci_print_registers(xhci);
4639 +
4640 ++ /* Look for vendor-specific quirks */
4641 ++ if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
4642 ++ pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
4643 ++ pdev->revision == 0x0) {
4644 ++ xhci->quirks |= XHCI_RESET_EP_QUIRK;
4645 ++ xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure"
4646 ++ " endpoint cmd after reset endpoint\n");
4647 ++ }
4648 ++
4649 + /* Make sure the HC is halted. */
4650 + retval = xhci_halt(xhci);
4651 + if (retval)
4652 +diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
4653 +index aa88a06..ff5e6bc 100644
4654 +--- a/drivers/usb/host/xhci-ring.c
4655 ++++ b/drivers/usb/host/xhci-ring.c
4656 +@@ -172,8 +172,9 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer
4657 + * have their chain bit cleared (so that each Link TRB is a separate TD).
4658 + *
4659 + * Section 6.4.4.1 of the 0.95 spec says link TRBs cannot have the chain bit
4660 +- * set, but other sections talk about dealing with the chain bit set.
4661 +- * Assume section 6.4.4.1 is wrong, and the chain bit can be set in a Link TRB.
4662 ++ * set, but other sections talk about dealing with the chain bit set. This was
4663 ++ * fixed in the 0.96 specification errata, but we have to assume that all 0.95
4664 ++ * xHCI hardware can't handle the chain bit being cleared on a link TRB.
4665 + */
4666 + static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer)
4667 + {
4668 +@@ -191,8 +192,14 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer
4669 + while (last_trb(xhci, ring, ring->enq_seg, next)) {
4670 + if (!consumer) {
4671 + if (ring != xhci->event_ring) {
4672 +- next->link.control &= ~TRB_CHAIN;
4673 +- next->link.control |= chain;
4674 ++ /* If we're not dealing with 0.95 hardware,
4675 ++ * carry over the chain bit of the previous TRB
4676 ++ * (which may mean the chain bit is cleared).
4677 ++ */
4678 ++ if (!xhci_link_trb_quirk(xhci)) {
4679 ++ next->link.control &= ~TRB_CHAIN;
4680 ++ next->link.control |= chain;
4681 ++ }
4682 + /* Give this link TRB to the hardware */
4683 + wmb();
4684 + if (next->link.control & TRB_CYCLE)
4685 +@@ -462,7 +469,6 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
4686 + * ring running.
4687 + */
4688 + ep_ring->state |= SET_DEQ_PENDING;
4689 +- xhci_ring_cmd_db(xhci);
4690 + }
4691 +
4692 + /*
4693 +@@ -531,6 +537,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
4694 + if (deq_state.new_deq_ptr && deq_state.new_deq_seg) {
4695 + xhci_queue_new_dequeue_state(xhci, ep_ring,
4696 + slot_id, ep_index, &deq_state);
4697 ++ xhci_ring_cmd_db(xhci);
4698 + } else {
4699 + /* Otherwise just ring the doorbell to restart the ring */
4700 + ring_ep_doorbell(xhci, slot_id, ep_index);
4701 +@@ -644,18 +651,31 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
4702 + {
4703 + int slot_id;
4704 + unsigned int ep_index;
4705 ++ struct xhci_ring *ep_ring;
4706 +
4707 + slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
4708 + ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
4709 ++ ep_ring = xhci->devs[slot_id]->ep_rings[ep_index];
4710 + /* This command will only fail if the endpoint wasn't halted,
4711 + * but we don't care.
4712 + */
4713 + xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n",
4714 + (unsigned int) GET_COMP_CODE(event->status));
4715 +
4716 +- /* Clear our internal halted state and restart the ring */
4717 +- xhci->devs[slot_id]->ep_rings[ep_index]->state &= ~EP_HALTED;
4718 +- ring_ep_doorbell(xhci, slot_id, ep_index);
4719 ++ /* HW with the reset endpoint quirk needs to have a configure endpoint
4720 ++ * command complete before the endpoint can be used. Queue that here
4721 ++ * because the HW can't handle two commands being queued in a row.
4722 ++ */
4723 ++ if (xhci->quirks & XHCI_RESET_EP_QUIRK) {
4724 ++ xhci_dbg(xhci, "Queueing configure endpoint command\n");
4725 ++ xhci_queue_configure_endpoint(xhci,
4726 ++ xhci->devs[slot_id]->in_ctx->dma, slot_id);
4727 ++ xhci_ring_cmd_db(xhci);
4728 ++ } else {
4729 ++ /* Clear our internal halted state and restart the ring */
4730 ++ ep_ring->state &= ~EP_HALTED;
4731 ++ ring_ep_doorbell(xhci, slot_id, ep_index);
4732 ++ }
4733 + }
4734 +
4735 + static void handle_cmd_completion(struct xhci_hcd *xhci,
4736 +@@ -664,6 +684,10 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
4737 + int slot_id = TRB_TO_SLOT_ID(event->flags);
4738 + u64 cmd_dma;
4739 + dma_addr_t cmd_dequeue_dma;
4740 ++ struct xhci_input_control_ctx *ctrl_ctx;
4741 ++ unsigned int ep_index;
4742 ++ struct xhci_ring *ep_ring;
4743 ++ unsigned int ep_state;
4744 +
4745 + cmd_dma = event->cmd_trb;
4746 + cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
4747 +@@ -691,6 +715,41 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
4748 + xhci_free_virt_device(xhci, slot_id);
4749 + break;
4750 + case TRB_TYPE(TRB_CONFIG_EP):
4751 ++ /*
4752 ++ * Configure endpoint commands can come from the USB core
4753 ++ * configuration or alt setting changes, or because the HW
4754 ++ * needed an extra configure endpoint command after a reset
4755 ++ * endpoint command. In the latter case, the xHCI driver is
4756 ++ * not waiting on the configure endpoint command.
4757 ++ */
4758 ++ ctrl_ctx = xhci_get_input_control_ctx(xhci,
4759 ++ xhci->devs[slot_id]->in_ctx);
4760 ++ /* Input ctx add_flags are the endpoint index plus one */
4761 ++ ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1;
4762 ++ ep_ring = xhci->devs[slot_id]->ep_rings[ep_index];
4763 ++ if (!ep_ring) {
4764 ++ /* This must have been an initial configure endpoint */
4765 ++ xhci->devs[slot_id]->cmd_status =
4766 ++ GET_COMP_CODE(event->status);
4767 ++ complete(&xhci->devs[slot_id]->cmd_completion);
4768 ++ break;
4769 ++ }
4770 ++ ep_state = ep_ring->state;
4771 ++ xhci_dbg(xhci, "Completed config ep cmd - last ep index = %d, "
4772 ++ "state = %d\n", ep_index, ep_state);
4773 ++ if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
4774 ++ ep_state & EP_HALTED) {
4775 ++ /* Clear our internal halted state and restart ring */
4776 ++ xhci->devs[slot_id]->ep_rings[ep_index]->state &=
4777 ++ ~EP_HALTED;
4778 ++ ring_ep_doorbell(xhci, slot_id, ep_index);
4779 ++ } else {
4780 ++ xhci->devs[slot_id]->cmd_status =
4781 ++ GET_COMP_CODE(event->status);
4782 ++ complete(&xhci->devs[slot_id]->cmd_completion);
4783 ++ }
4784 ++ break;
4785 ++ case TRB_TYPE(TRB_EVAL_CONTEXT):
4786 + xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status);
4787 + complete(&xhci->devs[slot_id]->cmd_completion);
4788 + break;
4789 +@@ -806,6 +865,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4790 + {
4791 + struct xhci_virt_device *xdev;
4792 + struct xhci_ring *ep_ring;
4793 ++ unsigned int slot_id;
4794 + int ep_index;
4795 + struct xhci_td *td = 0;
4796 + dma_addr_t event_dma;
4797 +@@ -814,9 +874,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4798 + struct urb *urb = 0;
4799 + int status = -EINPROGRESS;
4800 + struct xhci_ep_ctx *ep_ctx;
4801 ++ u32 trb_comp_code;
4802 +
4803 + xhci_dbg(xhci, "In %s\n", __func__);
4804 +- xdev = xhci->devs[TRB_TO_SLOT_ID(event->flags)];
4805 ++ slot_id = TRB_TO_SLOT_ID(event->flags);
4806 ++ xdev = xhci->devs[slot_id];
4807 + if (!xdev) {
4808 + xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n");
4809 + return -ENODEV;
4810 +@@ -870,7 +932,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4811 + (unsigned int) event->flags);
4812 +
4813 + /* Look for common error cases */
4814 +- switch (GET_COMP_CODE(event->transfer_len)) {
4815 ++ trb_comp_code = GET_COMP_CODE(event->transfer_len);
4816 ++ switch (trb_comp_code) {
4817 + /* Skip codes that require special handling depending on
4818 + * transfer type
4819 + */
4820 +@@ -913,7 +976,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4821 + /* Was this a control transfer? */
4822 + if (usb_endpoint_xfer_control(&td->urb->ep->desc)) {
4823 + xhci_debug_trb(xhci, xhci->event_ring->dequeue);
4824 +- switch (GET_COMP_CODE(event->transfer_len)) {
4825 ++ switch (trb_comp_code) {
4826 + case COMP_SUCCESS:
4827 + if (event_trb == ep_ring->dequeue) {
4828 + xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n");
4829 +@@ -928,8 +991,39 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4830 + break;
4831 + case COMP_SHORT_TX:
4832 + xhci_warn(xhci, "WARN: short transfer on control ep\n");
4833 +- status = -EREMOTEIO;
4834 ++ if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
4835 ++ status = -EREMOTEIO;
4836 ++ else
4837 ++ status = 0;
4838 + break;
4839 ++ case COMP_BABBLE:
4840 ++ /* The 0.96 spec says a babbling control endpoint
4841 ++ * is not halted. The 0.96 spec says it is. Some HW
4842 ++ * claims to be 0.95 compliant, but it halts the control
4843 ++ * endpoint anyway. Check if a babble halted the
4844 ++ * endpoint.
4845 ++ */
4846 ++ if (ep_ctx->ep_info != EP_STATE_HALTED)
4847 ++ break;
4848 ++ /* else fall through */
4849 ++ case COMP_STALL:
4850 ++ /* Did we transfer part of the data (middle) phase? */
4851 ++ if (event_trb != ep_ring->dequeue &&
4852 ++ event_trb != td->last_trb)
4853 ++ td->urb->actual_length =
4854 ++ td->urb->transfer_buffer_length
4855 ++ - TRB_LEN(event->transfer_len);
4856 ++ else
4857 ++ td->urb->actual_length = 0;
4858 ++
4859 ++ ep_ring->stopped_td = td;
4860 ++ ep_ring->stopped_trb = event_trb;
4861 ++ xhci_queue_reset_ep(xhci, slot_id, ep_index);
4862 ++ xhci_cleanup_stalled_ring(xhci,
4863 ++ td->urb->dev,
4864 ++ ep_index, ep_ring);
4865 ++ xhci_ring_cmd_db(xhci);
4866 ++ goto td_cleanup;
4867 + default:
4868 + /* Others already handled above */
4869 + break;
4870 +@@ -943,7 +1037,10 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4871 + if (event_trb == td->last_trb) {
4872 + if (td->urb->actual_length != 0) {
4873 + /* Don't overwrite a previously set error code */
4874 +- if (status == -EINPROGRESS || status == 0)
4875 ++ if ((status == -EINPROGRESS ||
4876 ++ status == 0) &&
4877 ++ (td->urb->transfer_flags
4878 ++ & URB_SHORT_NOT_OK))
4879 + /* Did we already see a short data stage? */
4880 + status = -EREMOTEIO;
4881 + } else {
4882 +@@ -952,7 +1049,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4883 + }
4884 + } else {
4885 + /* Maybe the event was for the data stage? */
4886 +- if (GET_COMP_CODE(event->transfer_len) != COMP_STOP_INVAL) {
4887 ++ if (trb_comp_code != COMP_STOP_INVAL) {
4888 + /* We didn't stop on a link TRB in the middle */
4889 + td->urb->actual_length =
4890 + td->urb->transfer_buffer_length -
4891 +@@ -964,7 +1061,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4892 + }
4893 + }
4894 + } else {
4895 +- switch (GET_COMP_CODE(event->transfer_len)) {
4896 ++ switch (trb_comp_code) {
4897 + case COMP_SUCCESS:
4898 + /* Double check that the HW transferred everything. */
4899 + if (event_trb != td->last_trb) {
4900 +@@ -975,7 +1072,12 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4901 + else
4902 + status = 0;
4903 + } else {
4904 +- xhci_dbg(xhci, "Successful bulk transfer!\n");
4905 ++ if (usb_endpoint_xfer_bulk(&td->urb->ep->desc))
4906 ++ xhci_dbg(xhci, "Successful bulk "
4907 ++ "transfer!\n");
4908 ++ else
4909 ++ xhci_dbg(xhci, "Successful interrupt "
4910 ++ "transfer!\n");
4911 + status = 0;
4912 + }
4913 + break;
4914 +@@ -1001,11 +1103,17 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4915 + td->urb->actual_length =
4916 + td->urb->transfer_buffer_length -
4917 + TRB_LEN(event->transfer_len);
4918 +- if (td->urb->actual_length < 0) {
4919 ++ if (td->urb->transfer_buffer_length <
4920 ++ td->urb->actual_length) {
4921 + xhci_warn(xhci, "HC gave bad length "
4922 + "of %d bytes left\n",
4923 + TRB_LEN(event->transfer_len));
4924 + td->urb->actual_length = 0;
4925 ++ if (td->urb->transfer_flags &
4926 ++ URB_SHORT_NOT_OK)
4927 ++ status = -EREMOTEIO;
4928 ++ else
4929 ++ status = 0;
4930 + }
4931 + /* Don't overwrite a previously set error code */
4932 + if (status == -EINPROGRESS) {
4933 +@@ -1041,14 +1149,14 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4934 + /* If the ring didn't stop on a Link or No-op TRB, add
4935 + * in the actual bytes transferred from the Normal TRB
4936 + */
4937 +- if (GET_COMP_CODE(event->transfer_len) != COMP_STOP_INVAL)
4938 ++ if (trb_comp_code != COMP_STOP_INVAL)
4939 + td->urb->actual_length +=
4940 + TRB_LEN(cur_trb->generic.field[2]) -
4941 + TRB_LEN(event->transfer_len);
4942 + }
4943 + }
4944 +- if (GET_COMP_CODE(event->transfer_len) == COMP_STOP_INVAL ||
4945 +- GET_COMP_CODE(event->transfer_len) == COMP_STOP) {
4946 ++ if (trb_comp_code == COMP_STOP_INVAL ||
4947 ++ trb_comp_code == COMP_STOP) {
4948 + /* The Endpoint Stop Command completion will take care of any
4949 + * stopped TDs. A stopped TD may be restarted, so don't update
4950 + * the ring dequeue pointer or take this TD off any lists yet.
4951 +@@ -1056,7 +1164,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4952 + ep_ring->stopped_td = td;
4953 + ep_ring->stopped_trb = event_trb;
4954 + } else {
4955 +- if (GET_COMP_CODE(event->transfer_len) == COMP_STALL) {
4956 ++ if (trb_comp_code == COMP_STALL ||
4957 ++ trb_comp_code == COMP_BABBLE) {
4958 + /* The transfer is completed from the driver's
4959 + * perspective, but we need to issue a set dequeue
4960 + * command for this stalled endpoint to move the dequeue
4961 +@@ -1072,16 +1181,41 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4962 + inc_deq(xhci, ep_ring, false);
4963 + }
4964 +
4965 ++td_cleanup:
4966 + /* Clean up the endpoint's TD list */
4967 + urb = td->urb;
4968 ++ /* Do one last check of the actual transfer length.
4969 ++ * If the host controller said we transferred more data than
4970 ++ * the buffer length, urb->actual_length will be a very big
4971 ++ * number (since it's unsigned). Play it safe and say we didn't
4972 ++ * transfer anything.
4973 ++ */
4974 ++ if (urb->actual_length > urb->transfer_buffer_length) {
4975 ++ xhci_warn(xhci, "URB transfer length is wrong, "
4976 ++ "xHC issue? req. len = %u, "
4977 ++ "act. len = %u\n",
4978 ++ urb->transfer_buffer_length,
4979 ++ urb->actual_length);
4980 ++ urb->actual_length = 0;
4981 ++ if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
4982 ++ status = -EREMOTEIO;
4983 ++ else
4984 ++ status = 0;
4985 ++ }
4986 + list_del(&td->td_list);
4987 + /* Was this TD slated to be cancelled but completed anyway? */
4988 + if (!list_empty(&td->cancelled_td_list)) {
4989 + list_del(&td->cancelled_td_list);
4990 + ep_ring->cancels_pending--;
4991 + }
4992 +- /* Leave the TD around for the reset endpoint function to use */
4993 +- if (GET_COMP_CODE(event->transfer_len) != COMP_STALL) {
4994 ++ /* Leave the TD around for the reset endpoint function to use
4995 ++ * (but only if it's not a control endpoint, since we already
4996 ++ * queued the Set TR dequeue pointer command for stalled
4997 ++ * control endpoints).
4998 ++ */
4999 ++ if (usb_endpoint_xfer_control(&urb->ep->desc) ||
5000 ++ (trb_comp_code != COMP_STALL &&
5001 ++ trb_comp_code != COMP_BABBLE)) {
5002 + kfree(td);
5003 + }
5004 + urb->hcpriv = NULL;
5005 +@@ -1094,7 +1228,7 @@ cleanup:
5006 + if (urb) {
5007 + usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb);
5008 + xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n",
5009 +- urb, td->urb->actual_length, status);
5010 ++ urb, urb->actual_length, status);
5011 + spin_unlock(&xhci->lock);
5012 + usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status);
5013 + spin_lock(&xhci->lock);
5014 +@@ -1335,6 +1469,47 @@ static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id,
5015 + ring_ep_doorbell(xhci, slot_id, ep_index);
5016 + }
5017 +
5018 ++/*
5019 ++ * xHCI uses normal TRBs for both bulk and interrupt. When the interrupt
5020 ++ * endpoint is to be serviced, the xHC will consume (at most) one TD. A TD
5021 ++ * (comprised of sg list entries) can take several service intervals to
5022 ++ * transmit.
5023 ++ */
5024 ++int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
5025 ++ struct urb *urb, int slot_id, unsigned int ep_index)
5026 ++{
5027 ++ struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci,
5028 ++ xhci->devs[slot_id]->out_ctx, ep_index);
5029 ++ int xhci_interval;
5030 ++ int ep_interval;
5031 ++
5032 ++ xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info);
5033 ++ ep_interval = urb->interval;
5034 ++ /* Convert to microframes */
5035 ++ if (urb->dev->speed == USB_SPEED_LOW ||
5036 ++ urb->dev->speed == USB_SPEED_FULL)
5037 ++ ep_interval *= 8;
5038 ++ /* FIXME change this to a warning and a suggestion to use the new API
5039 ++ * to set the polling interval (once the API is added).
5040 ++ */
5041 ++ if (xhci_interval != ep_interval) {
5042 ++ if (!printk_ratelimit())
5043 ++ dev_dbg(&urb->dev->dev, "Driver uses different interval"
5044 ++ " (%d microframe%s) than xHCI "
5045 ++ "(%d microframe%s)\n",
5046 ++ ep_interval,
5047 ++ ep_interval == 1 ? "" : "s",
5048 ++ xhci_interval,
5049 ++ xhci_interval == 1 ? "" : "s");
5050 ++ urb->interval = xhci_interval;
5051 ++ /* Convert back to frames for LS/FS devices */
5052 ++ if (urb->dev->speed == USB_SPEED_LOW ||
5053 ++ urb->dev->speed == USB_SPEED_FULL)
5054 ++ urb->interval /= 8;
5055 ++ }
5056 ++ return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index);
5057 ++}
5058 ++
5059 + static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
5060 + struct urb *urb, int slot_id, unsigned int ep_index)
5061 + {
5062 +@@ -1733,6 +1908,15 @@ int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
5063 + TRB_TYPE(TRB_CONFIG_EP) | SLOT_ID_FOR_TRB(slot_id));
5064 + }
5065 +
5066 ++/* Queue an evaluate context command TRB */
5067 ++int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
5068 ++ u32 slot_id)
5069 ++{
5070 ++ return queue_command(xhci, lower_32_bits(in_ctx_ptr),
5071 ++ upper_32_bits(in_ctx_ptr), 0,
5072 ++ TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id));
5073 ++}
5074 ++
5075 + int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
5076 + unsigned int ep_index)
5077 + {
5078 +diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
5079 +index d31d322..8085841 100644
5080 +--- a/drivers/usb/host/xhci.h
5081 ++++ b/drivers/usb/host/xhci.h
5082 +@@ -581,6 +581,7 @@ struct xhci_ep_ctx {
5083 + /* bit 15 is Linear Stream Array */
5084 + /* Interval - period between requests to an endpoint - 125u increments. */
5085 + #define EP_INTERVAL(p) ((p & 0xff) << 16)
5086 ++#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
5087 +
5088 + /* ep_info2 bitmasks */
5089 + /*
5090 +@@ -589,6 +590,7 @@ struct xhci_ep_ctx {
5091 + */
5092 + #define FORCE_EVENT (0x1)
5093 + #define ERROR_COUNT(p) (((p) & 0x3) << 1)
5094 ++#define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
5095 + #define EP_TYPE(p) ((p) << 3)
5096 + #define ISOC_OUT_EP 1
5097 + #define BULK_OUT_EP 2
5098 +@@ -601,6 +603,8 @@ struct xhci_ep_ctx {
5099 + /* bit 7 is Host Initiate Disable - for disabling stream selection */
5100 + #define MAX_BURST(p) (((p)&0xff) << 8)
5101 + #define MAX_PACKET(p) (((p)&0xffff) << 16)
5102 ++#define MAX_PACKET_MASK (0xffff << 16)
5103 ++#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
5104 +
5105 +
5106 + /**
5107 +@@ -926,6 +930,12 @@ struct xhci_td {
5108 + union xhci_trb *last_trb;
5109 + };
5110 +
5111 ++struct xhci_dequeue_state {
5112 ++ struct xhci_segment *new_deq_seg;
5113 ++ union xhci_trb *new_deq_ptr;
5114 ++ int new_cycle_state;
5115 ++};
5116 ++
5117 + struct xhci_ring {
5118 + struct xhci_segment *first_seg;
5119 + union xhci_trb *enqueue;
5120 +@@ -952,12 +962,6 @@ struct xhci_ring {
5121 + u32 cycle_state;
5122 + };
5123 +
5124 +-struct xhci_dequeue_state {
5125 +- struct xhci_segment *new_deq_seg;
5126 +- union xhci_trb *new_deq_ptr;
5127 +- int new_cycle_state;
5128 +-};
5129 +-
5130 + struct xhci_erst_entry {
5131 + /* 64-bit event ring segment address */
5132 + u64 seg_addr;
5133 +@@ -1058,6 +1062,9 @@ struct xhci_hcd {
5134 + int noops_submitted;
5135 + int noops_handled;
5136 + int error_bitmask;
5137 ++ unsigned int quirks;
5138 ++#define XHCI_LINK_TRB_QUIRK (1 << 0)
5139 ++#define XHCI_RESET_EP_QUIRK (1 << 1)
5140 + };
5141 +
5142 + /* For testing purposes */
5143 +@@ -1136,6 +1143,13 @@ static inline void xhci_write_64(struct xhci_hcd *xhci,
5144 + writel(val_hi, ptr + 1);
5145 + }
5146 +
5147 ++static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
5148 ++{
5149 ++ u32 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
5150 ++ return ((HC_VERSION(temp) == 0x95) &&
5151 ++ (xhci->quirks & XHCI_LINK_TRB_QUIRK));
5152 ++}
5153 ++
5154 + /* xHCI debugging */
5155 + void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num);
5156 + void xhci_print_registers(struct xhci_hcd *xhci);
5157 +@@ -1158,7 +1172,12 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device
5158 + int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
5159 + unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
5160 + unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
5161 ++unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index);
5162 ++unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
5163 + void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
5164 ++void xhci_endpoint_copy(struct xhci_hcd *xhci,
5165 ++ struct xhci_virt_device *vdev, unsigned int ep_index);
5166 ++void xhci_slot_copy(struct xhci_hcd *xhci, struct xhci_virt_device *vdev);
5167 + int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
5168 + struct usb_device *udev, struct usb_host_endpoint *ep,
5169 + gfp_t mem_flags);
5170 +@@ -1205,8 +1224,12 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
5171 + int slot_id, unsigned int ep_index);
5172 + int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
5173 + int slot_id, unsigned int ep_index);
5174 ++int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
5175 ++ int slot_id, unsigned int ep_index);
5176 + int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
5177 + u32 slot_id);
5178 ++int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
5179 ++ u32 slot_id);
5180 + int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
5181 + unsigned int ep_index);
5182 + void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
5183 +@@ -1215,6 +1238,12 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
5184 + void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
5185 + struct xhci_ring *ep_ring, unsigned int slot_id,
5186 + unsigned int ep_index, struct xhci_dequeue_state *deq_state);
5187 ++void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
5188 ++ struct usb_device *udev,
5189 ++ unsigned int ep_index, struct xhci_ring *ep_ring);
5190 ++void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
5191 ++ unsigned int slot_id, unsigned int ep_index,
5192 ++ struct xhci_dequeue_state *deq_state);
5193 +
5194 + /* xHCI roothub code */
5195 + int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
5196 +diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
5197 +index aec6188..1a50beb 100644
5198 +--- a/drivers/usb/serial/ark3116.c
5199 ++++ b/drivers/usb/serial/ark3116.c
5200 +@@ -35,11 +35,6 @@ static struct usb_device_id id_table [] = {
5201 + };
5202 + MODULE_DEVICE_TABLE(usb, id_table);
5203 +
5204 +-struct ark3116_private {
5205 +- spinlock_t lock;
5206 +- u8 termios_initialized;
5207 +-};
5208 +-
5209 + static inline void ARK3116_SND(struct usb_serial *serial, int seq,
5210 + __u8 request, __u8 requesttype,
5211 + __u16 value, __u16 index)
5212 +@@ -82,22 +77,11 @@ static inline void ARK3116_RCV_QUIET(struct usb_serial *serial,
5213 + static int ark3116_attach(struct usb_serial *serial)
5214 + {
5215 + char *buf;
5216 +- struct ark3116_private *priv;
5217 +- int i;
5218 +-
5219 +- for (i = 0; i < serial->num_ports; ++i) {
5220 +- priv = kzalloc(sizeof(struct ark3116_private), GFP_KERNEL);
5221 +- if (!priv)
5222 +- goto cleanup;
5223 +- spin_lock_init(&priv->lock);
5224 +-
5225 +- usb_set_serial_port_data(serial->port[i], priv);
5226 +- }
5227 +
5228 + buf = kmalloc(1, GFP_KERNEL);
5229 + if (!buf) {
5230 + dbg("error kmalloc -> out of mem?");
5231 +- goto cleanup;
5232 ++ return -ENOMEM;
5233 + }
5234 +
5235 + /* 3 */
5236 +@@ -149,13 +133,16 @@ static int ark3116_attach(struct usb_serial *serial)
5237 +
5238 + kfree(buf);
5239 + return 0;
5240 ++}
5241 +
5242 +-cleanup:
5243 +- for (--i; i >= 0; --i) {
5244 +- kfree(usb_get_serial_port_data(serial->port[i]));
5245 +- usb_set_serial_port_data(serial->port[i], NULL);
5246 +- }
5247 +- return -ENOMEM;
5248 ++static void ark3116_init_termios(struct tty_struct *tty)
5249 ++{
5250 ++ struct ktermios *termios = tty->termios;
5251 ++ *termios = tty_std_termios;
5252 ++ termios->c_cflag = B9600 | CS8
5253 ++ | CREAD | HUPCL | CLOCAL;
5254 ++ termios->c_ispeed = 9600;
5255 ++ termios->c_ospeed = 9600;
5256 + }
5257 +
5258 + static void ark3116_set_termios(struct tty_struct *tty,
5259 +@@ -163,10 +150,8 @@ static void ark3116_set_termios(struct tty_struct *tty,
5260 + struct ktermios *old_termios)
5261 + {
5262 + struct usb_serial *serial = port->serial;
5263 +- struct ark3116_private *priv = usb_get_serial_port_data(port);
5264 + struct ktermios *termios = tty->termios;
5265 + unsigned int cflag = termios->c_cflag;
5266 +- unsigned long flags;
5267 + int baud;
5268 + int ark3116_baud;
5269 + char *buf;
5270 +@@ -176,16 +161,6 @@ static void ark3116_set_termios(struct tty_struct *tty,
5271 +
5272 + dbg("%s - port %d", __func__, port->number);
5273 +
5274 +- spin_lock_irqsave(&priv->lock, flags);
5275 +- if (!priv->termios_initialized) {
5276 +- *termios = tty_std_termios;
5277 +- termios->c_cflag = B9600 | CS8
5278 +- | CREAD | HUPCL | CLOCAL;
5279 +- termios->c_ispeed = 9600;
5280 +- termios->c_ospeed = 9600;
5281 +- priv->termios_initialized = 1;
5282 +- }
5283 +- spin_unlock_irqrestore(&priv->lock, flags);
5284 +
5285 + cflag = termios->c_cflag;
5286 + termios->c_cflag &= ~(CMSPAR|CRTSCTS);
5287 +@@ -455,6 +430,7 @@ static struct usb_serial_driver ark3116_device = {
5288 + .num_ports = 1,
5289 + .attach = ark3116_attach,
5290 + .set_termios = ark3116_set_termios,
5291 ++ .init_termios = ark3116_init_termios,
5292 + .ioctl = ark3116_ioctl,
5293 + .tiocmget = ark3116_tiocmget,
5294 + .open = ark3116_open,
5295 +diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
5296 +index 0e4f2e4..3e49b2e 100644
5297 +--- a/drivers/usb/serial/console.c
5298 ++++ b/drivers/usb/serial/console.c
5299 +@@ -16,6 +16,7 @@
5300 + #include <linux/slab.h>
5301 + #include <linux/tty.h>
5302 + #include <linux/console.h>
5303 ++#include <linux/serial.h>
5304 + #include <linux/usb.h>
5305 + #include <linux/usb/serial.h>
5306 +
5307 +@@ -63,7 +64,7 @@ static int usb_console_setup(struct console *co, char *options)
5308 + char *s;
5309 + struct usb_serial *serial;
5310 + struct usb_serial_port *port;
5311 +- int retval = 0;
5312 ++ int retval;
5313 + struct tty_struct *tty = NULL;
5314 + struct ktermios *termios = NULL, dummy;
5315 +
5316 +@@ -116,13 +117,17 @@ static int usb_console_setup(struct console *co, char *options)
5317 + return -ENODEV;
5318 + }
5319 +
5320 +- port = serial->port[0];
5321 ++ retval = usb_autopm_get_interface(serial->interface);
5322 ++ if (retval)
5323 ++ goto error_get_interface;
5324 ++
5325 ++ port = serial->port[co->index - serial->minor];
5326 + tty_port_tty_set(&port->port, NULL);
5327 +
5328 + info->port = port;
5329 +
5330 + ++port->port.count;
5331 +- if (port->port.count == 1) {
5332 ++ if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
5333 + if (serial->type->set_termios) {
5334 + /*
5335 + * allocate a fake tty so the driver can initialize
5336 +@@ -168,6 +173,7 @@ static int usb_console_setup(struct console *co, char *options)
5337 + kfree(termios);
5338 + kfree(tty);
5339 + }
5340 ++ set_bit(ASYNCB_INITIALIZED, &port->port.flags);
5341 + }
5342 + /* Now that any required fake tty operations are completed restore
5343 + * the tty port count */
5344 +@@ -175,18 +181,22 @@ static int usb_console_setup(struct console *co, char *options)
5345 + /* The console is special in terms of closing the device so
5346 + * indicate this port is now acting as a system console. */
5347 + port->console = 1;
5348 +- retval = 0;
5349 +
5350 +-out:
5351 ++ mutex_unlock(&serial->disc_mutex);
5352 + return retval;
5353 +-free_termios:
5354 ++
5355 ++ free_termios:
5356 + kfree(termios);
5357 + tty_port_tty_set(&port->port, NULL);
5358 +-free_tty:
5359 ++ free_tty:
5360 + kfree(tty);
5361 +-reset_open_count:
5362 ++ reset_open_count:
5363 + port->port.count = 0;
5364 +- goto out;
5365 ++ usb_autopm_put_interface(serial->interface);
5366 ++ error_get_interface:
5367 ++ usb_serial_put(serial);
5368 ++ mutex_unlock(&serial->disc_mutex);
5369 ++ return retval;
5370 + }
5371 +
5372 + static void usb_console_write(struct console *co,
5373 +diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
5374 +index 985cbcf..b5275c4 100644
5375 +--- a/drivers/usb/serial/cp210x.c
5376 ++++ b/drivers/usb/serial/cp210x.c
5377 +@@ -399,12 +399,6 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port,
5378 +
5379 + /* Configure the termios structure */
5380 + cp210x_get_termios(tty, port);
5381 +-
5382 +- /* Set the DTR and RTS pins low */
5383 +- cp210x_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data
5384 +- : port,
5385 +- NULL, TIOCM_DTR | TIOCM_RTS, 0);
5386 +-
5387 + return 0;
5388 + }
5389 +
5390 +diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
5391 +index 59adfe1..27b5a27 100644
5392 +--- a/drivers/usb/serial/cypress_m8.c
5393 ++++ b/drivers/usb/serial/cypress_m8.c
5394 +@@ -659,15 +659,7 @@ static int cypress_open(struct tty_struct *tty,
5395 + spin_unlock_irqrestore(&priv->lock, flags);
5396 +
5397 + /* Set termios */
5398 +- result = cypress_write(tty, port, NULL, 0);
5399 +-
5400 +- if (result) {
5401 +- dev_err(&port->dev,
5402 +- "%s - failed setting the control lines - error %d\n",
5403 +- __func__, result);
5404 +- return result;
5405 +- } else
5406 +- dbg("%s - success setting the control lines", __func__);
5407 ++ cypress_send(port);
5408 +
5409 + if (tty)
5410 + cypress_set_termios(tty, port, &priv->tmp_termios);
5411 +@@ -1005,6 +997,8 @@ static void cypress_set_termios(struct tty_struct *tty,
5412 + dbg("%s - port %d", __func__, port->number);
5413 +
5414 + spin_lock_irqsave(&priv->lock, flags);
5415 ++ /* We can't clean this one up as we don't know the device type
5416 ++ early enough */
5417 + if (!priv->termios_initialized) {
5418 + if (priv->chiptype == CT_EARTHMATE) {
5419 + *(tty->termios) = tty_std_termios;
5420 +diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
5421 +index 80cb347..3433f9d 100644
5422 +--- a/drivers/usb/serial/empeg.c
5423 ++++ b/drivers/usb/serial/empeg.c
5424 +@@ -90,8 +90,7 @@ static int empeg_chars_in_buffer(struct tty_struct *tty);
5425 + static void empeg_throttle(struct tty_struct *tty);
5426 + static void empeg_unthrottle(struct tty_struct *tty);
5427 + static int empeg_startup(struct usb_serial *serial);
5428 +-static void empeg_set_termios(struct tty_struct *tty,
5429 +- struct usb_serial_port *port, struct ktermios *old_termios);
5430 ++static void empeg_init_termios(struct tty_struct *tty);
5431 + static void empeg_write_bulk_callback(struct urb *urb);
5432 + static void empeg_read_bulk_callback(struct urb *urb);
5433 +
5434 +@@ -123,7 +122,7 @@ static struct usb_serial_driver empeg_device = {
5435 + .throttle = empeg_throttle,
5436 + .unthrottle = empeg_unthrottle,
5437 + .attach = empeg_startup,
5438 +- .set_termios = empeg_set_termios,
5439 ++ .init_termios = empeg_init_termios,
5440 + .write = empeg_write,
5441 + .write_room = empeg_write_room,
5442 + .chars_in_buffer = empeg_chars_in_buffer,
5443 +@@ -150,9 +149,6 @@ static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
5444 +
5445 + dbg("%s - port %d", __func__, port->number);
5446 +
5447 +- /* Force default termio settings */
5448 +- empeg_set_termios(tty, port, NULL) ;
5449 +-
5450 + bytes_in = 0;
5451 + bytes_out = 0;
5452 +
5453 +@@ -425,11 +421,9 @@ static int empeg_startup(struct usb_serial *serial)
5454 + }
5455 +
5456 +
5457 +-static void empeg_set_termios(struct tty_struct *tty,
5458 +- struct usb_serial_port *port, struct ktermios *old_termios)
5459 ++static void empeg_init_termios(struct tty_struct *tty)
5460 + {
5461 + struct ktermios *termios = tty->termios;
5462 +- dbg("%s - port %d", __func__, port->number);
5463 +
5464 + /*
5465 + * The empeg-car player wants these particular tty settings.
5466 +diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
5467 +index 8fec5d4..0cc78f9 100644
5468 +--- a/drivers/usb/serial/ftdi_sio.c
5469 ++++ b/drivers/usb/serial/ftdi_sio.c
5470 +@@ -176,6 +176,9 @@ static struct usb_device_id id_table_combined [] = {
5471 + { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
5472 + { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
5473 + { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) },
5474 ++ { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_SNIFFER_PID) },
5475 ++ { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) },
5476 ++ { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) },
5477 + { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
5478 + { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
5479 + { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) },
5480 +@@ -694,6 +697,8 @@ static struct usb_device_id id_table_combined [] = {
5481 + { USB_DEVICE(DE_VID, WHT_PID) },
5482 + { USB_DEVICE(ADI_VID, ADI_GNICE_PID),
5483 + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
5484 ++ { USB_DEVICE(ADI_VID, ADI_GNICEPLUS_PID),
5485 ++ .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
5486 + { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) },
5487 + { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID),
5488 + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
5489 +@@ -702,6 +707,8 @@ static struct usb_device_id id_table_combined [] = {
5490 + { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) },
5491 + { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID),
5492 + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
5493 ++ { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) },
5494 ++ { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) },
5495 + { }, /* Optional parameter entry */
5496 + { } /* Terminating entry */
5497 + };
5498 +diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
5499 +index 8c92b88..6f31e0d 100644
5500 +--- a/drivers/usb/serial/ftdi_sio.h
5501 ++++ b/drivers/usb/serial/ftdi_sio.h
5502 +@@ -81,6 +81,9 @@
5503 +
5504 + /* OpenDCC (www.opendcc.de) product id */
5505 + #define FTDI_OPENDCC_PID 0xBFD8
5506 ++#define FTDI_OPENDCC_SNIFFER_PID 0xBFD9
5507 ++#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA
5508 ++#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB
5509 +
5510 + /* Sprog II (Andrew Crosland's SprogII DCC interface) */
5511 + #define FTDI_SPROG_II 0xF0C8
5512 +@@ -930,6 +933,7 @@
5513 + */
5514 + #define ADI_VID 0x0456
5515 + #define ADI_GNICE_PID 0xF000
5516 ++#define ADI_GNICEPLUS_PID 0xF001
5517 +
5518 + /*
5519 + * JETI SPECTROMETER SPECBOS 1201
5520 +@@ -968,6 +972,12 @@
5521 + #define MARVELL_OPENRD_PID 0x9e90
5522 +
5523 + /*
5524 ++ * Hameg HO820 and HO870 interface (using VID 0x0403)
5525 ++ */
5526 ++#define HAMEG_HO820_PID 0xed74
5527 ++#define HAMEG_HO870_PID 0xed71
5528 ++
5529 ++/*
5530 + * BmRequestType: 1100 0000b
5531 + * bRequest: FTDI_E2_READ
5532 + * wValue: 0
5533 +diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
5534 +index 96873a7..af6df6c 100644
5535 +--- a/drivers/usb/serial/iuu_phoenix.c
5536 ++++ b/drivers/usb/serial/iuu_phoenix.c
5537 +@@ -71,7 +71,6 @@ struct iuu_private {
5538 + spinlock_t lock; /* store irq state */
5539 + wait_queue_head_t delta_msr_wait;
5540 + u8 line_status;
5541 +- u8 termios_initialized;
5542 + int tiostatus; /* store IUART SIGNAL for tiocmget call */
5543 + u8 reset; /* if 1 reset is needed */
5544 + int poll; /* number of poll */
5545 +@@ -1018,6 +1017,18 @@ static void iuu_close(struct usb_serial_port *port)
5546 + }
5547 + }
5548 +
5549 ++static void iuu_init_termios(struct tty_struct *tty)
5550 ++{
5551 ++ *(tty->termios) = tty_std_termios;
5552 ++ tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
5553 ++ | TIOCM_CTS | CSTOPB | PARENB;
5554 ++ tty->termios->c_ispeed = 9600;
5555 ++ tty->termios->c_ospeed = 9600;
5556 ++ tty->termios->c_lflag = 0;
5557 ++ tty->termios->c_oflag = 0;
5558 ++ tty->termios->c_iflag = 0;
5559 ++}
5560 ++
5561 + static int iuu_open(struct tty_struct *tty,
5562 + struct usb_serial_port *port, struct file *filp)
5563 + {
5564 +@@ -1025,7 +1036,6 @@ static int iuu_open(struct tty_struct *tty,
5565 + u8 *buf;
5566 + int result;
5567 + u32 actual;
5568 +- unsigned long flags;
5569 + struct iuu_private *priv = usb_get_serial_port_data(port);
5570 +
5571 + dbg("%s - port %d", __func__, port->number);
5572 +@@ -1064,21 +1074,7 @@ static int iuu_open(struct tty_struct *tty,
5573 + port->bulk_in_buffer, 512,
5574 + NULL, NULL);
5575 +
5576 +- /* set the termios structure */
5577 +- spin_lock_irqsave(&priv->lock, flags);
5578 +- if (tty && !priv->termios_initialized) {
5579 +- *(tty->termios) = tty_std_termios;
5580 +- tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
5581 +- | TIOCM_CTS | CSTOPB | PARENB;
5582 +- tty->termios->c_ispeed = 9600;
5583 +- tty->termios->c_ospeed = 9600;
5584 +- tty->termios->c_lflag = 0;
5585 +- tty->termios->c_oflag = 0;
5586 +- tty->termios->c_iflag = 0;
5587 +- priv->termios_initialized = 1;
5588 +- priv->poll = 0;
5589 +- }
5590 +- spin_unlock_irqrestore(&priv->lock, flags);
5591 ++ priv->poll = 0;
5592 +
5593 + /* initialize writebuf */
5594 + #define FISH(a, b, c, d) do { \
5595 +@@ -1201,6 +1197,7 @@ static struct usb_serial_driver iuu_device = {
5596 + .tiocmget = iuu_tiocmget,
5597 + .tiocmset = iuu_tiocmset,
5598 + .set_termios = iuu_set_termios,
5599 ++ .init_termios = iuu_init_termios,
5600 + .attach = iuu_startup,
5601 + .release = iuu_release,
5602 + };
5603 +diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
5604 +index 6db0e56..46d47d1 100644
5605 +--- a/drivers/usb/serial/kobil_sct.c
5606 ++++ b/drivers/usb/serial/kobil_sct.c
5607 +@@ -85,7 +85,7 @@ static void kobil_read_int_callback(struct urb *urb);
5608 + static void kobil_write_callback(struct urb *purb);
5609 + static void kobil_set_termios(struct tty_struct *tty,
5610 + struct usb_serial_port *port, struct ktermios *old);
5611 +-
5612 ++static void kobil_init_termios(struct tty_struct *tty);
5613 +
5614 + static struct usb_device_id id_table [] = {
5615 + { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_B_PRODUCT_ID) },
5616 +@@ -120,6 +120,7 @@ static struct usb_serial_driver kobil_device = {
5617 + .release = kobil_release,
5618 + .ioctl = kobil_ioctl,
5619 + .set_termios = kobil_set_termios,
5620 ++ .init_termios = kobil_init_termios,
5621 + .tiocmget = kobil_tiocmget,
5622 + .tiocmset = kobil_tiocmset,
5623 + .open = kobil_open,
5624 +@@ -210,6 +211,15 @@ static void kobil_release(struct usb_serial *serial)
5625 + kfree(usb_get_serial_port_data(serial->port[i]));
5626 + }
5627 +
5628 ++static void kobil_init_termios(struct tty_struct *tty)
5629 ++{
5630 ++ /* Default to echo off and other sane device settings */
5631 ++ tty->termios->c_lflag = 0;
5632 ++ tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN | XCASE);
5633 ++ tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF;
5634 ++ /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */
5635 ++ tty->termios->c_oflag &= ~ONLCR;
5636 ++}
5637 +
5638 + static int kobil_open(struct tty_struct *tty,
5639 + struct usb_serial_port *port, struct file *filp)
5640 +@@ -226,16 +236,6 @@ static int kobil_open(struct tty_struct *tty,
5641 + /* someone sets the dev to 0 if the close method has been called */
5642 + port->interrupt_in_urb->dev = port->serial->dev;
5643 +
5644 +- if (tty) {
5645 +-
5646 +- /* Default to echo off and other sane device settings */
5647 +- tty->termios->c_lflag = 0;
5648 +- tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN |
5649 +- XCASE);
5650 +- tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF;
5651 +- /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */
5652 +- tty->termios->c_oflag &= ~ONLCR;
5653 +- }
5654 + /* allocate memory for transfer buffer */
5655 + transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
5656 + if (!transfer_buffer)
5657 +diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
5658 +index c784ddb..0101548 100644
5659 +--- a/drivers/usb/serial/option.c
5660 ++++ b/drivers/usb/serial/option.c
5661 +@@ -292,6 +292,7 @@ static int option_resume(struct usb_serial *serial);
5662 +
5663 + #define TELIT_VENDOR_ID 0x1bc7
5664 + #define TELIT_PRODUCT_UC864E 0x1003
5665 ++#define TELIT_PRODUCT_UC864G 0x1004
5666 +
5667 + /* ZTE PRODUCTS */
5668 + #define ZTE_VENDOR_ID 0x19d2
5669 +@@ -300,6 +301,7 @@ static int option_resume(struct usb_serial *serial);
5670 + #define ZTE_PRODUCT_MF626 0x0031
5671 + #define ZTE_PRODUCT_CDMA_TECH 0xfffe
5672 + #define ZTE_PRODUCT_AC8710 0xfff1
5673 ++#define ZTE_PRODUCT_AC2726 0xfff5
5674 +
5675 + #define BENQ_VENDOR_ID 0x04a5
5676 + #define BENQ_PRODUCT_H10 0x4068
5677 +@@ -503,6 +505,7 @@ static struct usb_device_id option_ids[] = {
5678 + { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
5679 + { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */
5680 + { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) },
5681 ++ { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864G) },
5682 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */
5683 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff) },
5684 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0003, 0xff, 0xff, 0xff) },
5685 +@@ -572,6 +575,7 @@ static struct usb_device_id option_ids[] = {
5686 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) },
5687 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) },
5688 + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) },
5689 ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) },
5690 + { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) },
5691 + { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) },
5692 + { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) },
5693 +diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
5694 +index 3cece27..ef34cff 100644
5695 +--- a/drivers/usb/serial/oti6858.c
5696 ++++ b/drivers/usb/serial/oti6858.c
5697 +@@ -146,6 +146,7 @@ static int oti6858_open(struct tty_struct *tty,
5698 + static void oti6858_close(struct usb_serial_port *port);
5699 + static void oti6858_set_termios(struct tty_struct *tty,
5700 + struct usb_serial_port *port, struct ktermios *old);
5701 ++static void oti6858_init_termios(struct tty_struct *tty);
5702 + static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
5703 + unsigned int cmd, unsigned long arg);
5704 + static void oti6858_read_int_callback(struct urb *urb);
5705 +@@ -186,6 +187,7 @@ static struct usb_serial_driver oti6858_device = {
5706 + .write = oti6858_write,
5707 + .ioctl = oti6858_ioctl,
5708 + .set_termios = oti6858_set_termios,
5709 ++ .init_termios = oti6858_init_termios,
5710 + .tiocmget = oti6858_tiocmget,
5711 + .tiocmset = oti6858_tiocmset,
5712 + .read_bulk_callback = oti6858_read_bulk_callback,
5713 +@@ -206,7 +208,6 @@ struct oti6858_private {
5714 + struct {
5715 + u8 read_urb_in_use;
5716 + u8 write_urb_in_use;
5717 +- u8 termios_initialized;
5718 + } flags;
5719 + struct delayed_work delayed_write_work;
5720 +
5721 +@@ -447,6 +448,14 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty)
5722 + return chars;
5723 + }
5724 +
5725 ++static void oti6858_init_termios(struct tty_struct *tty)
5726 ++{
5727 ++ *(tty->termios) = tty_std_termios;
5728 ++ tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL;
5729 ++ tty->termios->c_ispeed = 38400;
5730 ++ tty->termios->c_ospeed = 38400;
5731 ++}
5732 ++
5733 + static void oti6858_set_termios(struct tty_struct *tty,
5734 + struct usb_serial_port *port, struct ktermios *old_termios)
5735 + {
5736 +@@ -464,16 +473,6 @@ static void oti6858_set_termios(struct tty_struct *tty,
5737 + return;
5738 + }
5739 +
5740 +- spin_lock_irqsave(&priv->lock, flags);
5741 +- if (!priv->flags.termios_initialized) {
5742 +- *(tty->termios) = tty_std_termios;
5743 +- tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL;
5744 +- tty->termios->c_ispeed = 38400;
5745 +- tty->termios->c_ospeed = 38400;
5746 +- priv->flags.termios_initialized = 1;
5747 +- }
5748 +- spin_unlock_irqrestore(&priv->lock, flags);
5749 +-
5750 + cflag = tty->termios->c_cflag;
5751 +
5752 + spin_lock_irqsave(&priv->lock, flags);
5753 +diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
5754 +index 3e86815..124d5ae 100644
5755 +--- a/drivers/usb/serial/pl2303.c
5756 ++++ b/drivers/usb/serial/pl2303.c
5757 +@@ -96,6 +96,7 @@ static struct usb_device_id id_table [] = {
5758 + { USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) },
5759 + { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) },
5760 + { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
5761 ++ { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) },
5762 + { } /* Terminating entry */
5763 + };
5764 +
5765 +diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
5766 +index ee9505e..d640dc9 100644
5767 +--- a/drivers/usb/serial/pl2303.h
5768 ++++ b/drivers/usb/serial/pl2303.h
5769 +@@ -130,3 +130,7 @@
5770 + /* Sony, USB data cable for CMD-Jxx mobile phones */
5771 + #define SONY_VENDOR_ID 0x054c
5772 + #define SONY_QN3USB_PRODUCT_ID 0x0437
5773 ++
5774 ++/* Sanwa KB-USB2 multimeter cable (ID: 11ad:0001) */
5775 ++#define SANWA_VENDOR_ID 0x11ad
5776 ++#define SANWA_PRODUCT_ID 0x0001
5777 +diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
5778 +index 3c249d8..993a6d5 100644
5779 +--- a/drivers/usb/serial/spcp8x5.c
5780 ++++ b/drivers/usb/serial/spcp8x5.c
5781 +@@ -299,7 +299,6 @@ struct spcp8x5_private {
5782 + wait_queue_head_t delta_msr_wait;
5783 + u8 line_control;
5784 + u8 line_status;
5785 +- u8 termios_initialized;
5786 + };
5787 +
5788 + /* desc : when device plug in,this function would be called.
5789 +@@ -498,6 +497,15 @@ static void spcp8x5_close(struct usb_serial_port *port)
5790 + dev_dbg(&port->dev, "usb_unlink_urb(read_urb) = %d\n", result);
5791 + }
5792 +
5793 ++static void spcp8x5_init_termios(struct tty_struct *tty)
5794 ++{
5795 ++ /* for the 1st time call this function */
5796 ++ *(tty->termios) = tty_std_termios;
5797 ++ tty->termios->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
5798 ++ tty->termios->c_ispeed = 115200;
5799 ++ tty->termios->c_ospeed = 115200;
5800 ++}
5801 ++
5802 + /* set the serial param for transfer. we should check if we really need to
5803 + * transfer. if we set flow control we should do this too. */
5804 + static void spcp8x5_set_termios(struct tty_struct *tty,
5805 +@@ -514,16 +522,6 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
5806 + int i;
5807 + u8 control;
5808 +
5809 +- /* for the 1st time call this function */
5810 +- spin_lock_irqsave(&priv->lock, flags);
5811 +- if (!priv->termios_initialized) {
5812 +- *(tty->termios) = tty_std_termios;
5813 +- tty->termios->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
5814 +- tty->termios->c_ispeed = 115200;
5815 +- tty->termios->c_ospeed = 115200;
5816 +- priv->termios_initialized = 1;
5817 +- }
5818 +- spin_unlock_irqrestore(&priv->lock, flags);
5819 +
5820 + /* check that they really want us to change something */
5821 + if (!tty_termios_hw_change(tty->termios, old_termios))
5822 +@@ -1011,6 +1009,7 @@ static struct usb_serial_driver spcp8x5_device = {
5823 + .carrier_raised = spcp8x5_carrier_raised,
5824 + .write = spcp8x5_write,
5825 + .set_termios = spcp8x5_set_termios,
5826 ++ .init_termios = spcp8x5_init_termios,
5827 + .ioctl = spcp8x5_ioctl,
5828 + .tiocmget = spcp8x5_tiocmget,
5829 + .tiocmset = spcp8x5_tiocmset,
5830 +diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
5831 +index 99188c9..a0702db 100644
5832 +--- a/drivers/usb/serial/usb-serial.c
5833 ++++ b/drivers/usb/serial/usb-serial.c
5834 +@@ -43,8 +43,6 @@
5835 + #define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@×××××.com, http://www.kroah.com/linux/"
5836 + #define DRIVER_DESC "USB Serial Driver core"
5837 +
5838 +-static void port_free(struct usb_serial_port *port);
5839 +-
5840 + /* Driver structure we register with the USB core */
5841 + static struct usb_driver usb_serial_driver = {
5842 + .name = "usbserial",
5843 +@@ -68,6 +66,11 @@ static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
5844 + static DEFINE_MUTEX(table_lock);
5845 + static LIST_HEAD(usb_serial_driver_list);
5846 +
5847 ++/*
5848 ++ * Look up the serial structure. If it is found and it hasn't been
5849 ++ * disconnected, return with its disc_mutex held and its refcount
5850 ++ * incremented. Otherwise return NULL.
5851 ++ */
5852 + struct usb_serial *usb_serial_get_by_index(unsigned index)
5853 + {
5854 + struct usb_serial *serial;
5855 +@@ -75,8 +78,15 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
5856 + mutex_lock(&table_lock);
5857 + serial = serial_table[index];
5858 +
5859 +- if (serial)
5860 +- kref_get(&serial->kref);
5861 ++ if (serial) {
5862 ++ mutex_lock(&serial->disc_mutex);
5863 ++ if (serial->disconnected) {
5864 ++ mutex_unlock(&serial->disc_mutex);
5865 ++ serial = NULL;
5866 ++ } else {
5867 ++ kref_get(&serial->kref);
5868 ++ }
5869 ++ }
5870 + mutex_unlock(&table_lock);
5871 + return serial;
5872 + }
5873 +@@ -125,8 +135,10 @@ static void return_serial(struct usb_serial *serial)
5874 +
5875 + dbg("%s", __func__);
5876 +
5877 ++ mutex_lock(&table_lock);
5878 + for (i = 0; i < serial->num_ports; ++i)
5879 + serial_table[serial->minor + i] = NULL;
5880 ++ mutex_unlock(&table_lock);
5881 + }
5882 +
5883 + static void destroy_serial(struct kref *kref)
5884 +@@ -145,161 +157,157 @@ static void destroy_serial(struct kref *kref)
5885 +
5886 + serial->type->release(serial);
5887 +
5888 +- for (i = 0; i < serial->num_ports; ++i) {
5889 ++ /* Now that nothing is using the ports, they can be freed */
5890 ++ for (i = 0; i < serial->num_port_pointers; ++i) {
5891 + port = serial->port[i];
5892 +- if (port)
5893 ++ if (port) {
5894 ++ port->serial = NULL;
5895 + put_device(&port->dev);
5896 +- }
5897 +-
5898 +- /* If this is a "fake" port, we have to clean it up here, as it will
5899 +- * not get cleaned up in port_release() as it was never registered with
5900 +- * the driver core */
5901 +- if (serial->num_ports < serial->num_port_pointers) {
5902 +- for (i = serial->num_ports;
5903 +- i < serial->num_port_pointers; ++i) {
5904 +- port = serial->port[i];
5905 +- if (port)
5906 +- port_free(port);
5907 + }
5908 + }
5909 +
5910 + usb_put_dev(serial->dev);
5911 +-
5912 +- /* free up any memory that we allocated */
5913 + kfree(serial);
5914 + }
5915 +
5916 + void usb_serial_put(struct usb_serial *serial)
5917 + {
5918 +- mutex_lock(&table_lock);
5919 + kref_put(&serial->kref, destroy_serial);
5920 +- mutex_unlock(&table_lock);
5921 + }
5922 +
5923 + /*****************************************************************************
5924 + * Driver tty interface functions
5925 + *****************************************************************************/
5926 +-static int serial_open (struct tty_struct *tty, struct file *filp)
5927 ++
5928 ++/**
5929 ++ * serial_install - install tty
5930 ++ * @driver: the driver (USB in our case)
5931 ++ * @tty: the tty being created
5932 ++ *
5933 ++ * Create the termios objects for this tty. We use the default
5934 ++ * USB serial settings but permit them to be overridden by
5935 ++ * serial->type->init_termios.
5936 ++ *
5937 ++ * This is the first place a new tty gets used. Hence this is where we
5938 ++ * acquire references to the usb_serial structure and the driver module,
5939 ++ * where we store a pointer to the port, and where we do an autoresume.
5940 ++ * All these actions are reversed in serial_release().
5941 ++ */
5942 ++static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
5943 + {
5944 ++ int idx = tty->index;
5945 + struct usb_serial *serial;
5946 + struct usb_serial_port *port;
5947 +- unsigned int portNumber;
5948 +- int retval = 0;
5949 +- int first = 0;
5950 ++ int retval = -ENODEV;
5951 +
5952 + dbg("%s", __func__);
5953 +
5954 +- /* get the serial object associated with this tty pointer */
5955 +- serial = usb_serial_get_by_index(tty->index);
5956 +- if (!serial) {
5957 +- tty->driver_data = NULL;
5958 +- return -ENODEV;
5959 +- }
5960 ++ serial = usb_serial_get_by_index(idx);
5961 ++ if (!serial)
5962 ++ return retval;
5963 +
5964 +- mutex_lock(&serial->disc_mutex);
5965 +- portNumber = tty->index - serial->minor;
5966 +- port = serial->port[portNumber];
5967 +- if (!port || serial->disconnected)
5968 +- retval = -ENODEV;
5969 +- else
5970 +- get_device(&port->dev);
5971 +- /*
5972 +- * Note: Our locking order requirement does not allow port->mutex
5973 +- * to be acquired while serial->disc_mutex is held.
5974 +- */
5975 +- mutex_unlock(&serial->disc_mutex);
5976 ++ port = serial->port[idx - serial->minor];
5977 ++ if (!port)
5978 ++ goto error_no_port;
5979 ++ if (!try_module_get(serial->type->driver.owner))
5980 ++ goto error_module_get;
5981 ++
5982 ++ /* perform the standard setup */
5983 ++ retval = tty_init_termios(tty);
5984 + if (retval)
5985 +- goto bailout_serial_put;
5986 ++ goto error_init_termios;
5987 +
5988 +- if (mutex_lock_interruptible(&port->mutex)) {
5989 +- retval = -ERESTARTSYS;
5990 +- goto bailout_port_put;
5991 +- }
5992 ++ retval = usb_autopm_get_interface(serial->interface);
5993 ++ if (retval)
5994 ++ goto error_get_interface;
5995 ++
5996 ++ mutex_unlock(&serial->disc_mutex);
5997 +
5998 +- ++port->port.count;
5999 ++ /* allow the driver to update the settings */
6000 ++ if (serial->type->init_termios)
6001 ++ serial->type->init_termios(tty);
6002 +
6003 +- /* set up our port structure making the tty driver
6004 +- * remember our port object, and us it */
6005 + tty->driver_data = port;
6006 +- tty_port_tty_set(&port->port, tty);
6007 +
6008 +- /* If the console is attached, the device is already open */
6009 +- if (port->port.count == 1 && !port->console) {
6010 +- first = 1;
6011 +- /* lock this module before we call it
6012 +- * this may fail, which means we must bail out,
6013 +- * safe because we are called with BKL held */
6014 +- if (!try_module_get(serial->type->driver.owner)) {
6015 +- retval = -ENODEV;
6016 +- goto bailout_mutex_unlock;
6017 +- }
6018 ++ /* Final install (we use the default method) */
6019 ++ tty_driver_kref_get(driver);
6020 ++ tty->count++;
6021 ++ driver->ttys[idx] = tty;
6022 ++ return retval;
6023 +
6024 ++ error_get_interface:
6025 ++ error_init_termios:
6026 ++ module_put(serial->type->driver.owner);
6027 ++ error_module_get:
6028 ++ error_no_port:
6029 ++ usb_serial_put(serial);
6030 ++ mutex_unlock(&serial->disc_mutex);
6031 ++ return retval;
6032 ++}
6033 ++
6034 ++static int serial_open(struct tty_struct *tty, struct file *filp)
6035 ++{
6036 ++ struct usb_serial_port *port = tty->driver_data;
6037 ++ struct usb_serial *serial = port->serial;
6038 ++ int retval;
6039 ++
6040 ++ dbg("%s - port %d", __func__, port->number);
6041 ++
6042 ++ spin_lock_irq(&port->port.lock);
6043 ++ if (!tty_hung_up_p(filp))
6044 ++ ++port->port.count;
6045 ++ spin_unlock_irq(&port->port.lock);
6046 ++ tty_port_tty_set(&port->port, tty);
6047 ++
6048 ++ /* Do the device-specific open only if the hardware isn't
6049 ++ * already initialized.
6050 ++ */
6051 ++ if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
6052 ++ if (mutex_lock_interruptible(&port->mutex))
6053 ++ return -ERESTARTSYS;
6054 + mutex_lock(&serial->disc_mutex);
6055 + if (serial->disconnected)
6056 + retval = -ENODEV;
6057 + else
6058 +- retval = usb_autopm_get_interface(serial->interface);
6059 +- if (retval)
6060 +- goto bailout_module_put;
6061 +-
6062 +- /* only call the device specific open if this
6063 +- * is the first time the port is opened */
6064 +- retval = serial->type->open(tty, port, filp);
6065 +- if (retval)
6066 +- goto bailout_interface_put;
6067 ++ retval = port->serial->type->open(tty, port, filp);
6068 + mutex_unlock(&serial->disc_mutex);
6069 ++ mutex_unlock(&port->mutex);
6070 ++ if (retval)
6071 ++ return retval;
6072 + set_bit(ASYNCB_INITIALIZED, &port->port.flags);
6073 + }
6074 +- mutex_unlock(&port->mutex);
6075 ++
6076 + /* Now do the correct tty layer semantics */
6077 + retval = tty_port_block_til_ready(&port->port, tty, filp);
6078 +- if (retval == 0) {
6079 +- if (!first)
6080 +- usb_serial_put(serial);
6081 +- return 0;
6082 +- }
6083 +- mutex_lock(&port->mutex);
6084 +- if (first == 0)
6085 +- goto bailout_mutex_unlock;
6086 +- /* Undo the initial port actions */
6087 +- mutex_lock(&serial->disc_mutex);
6088 +-bailout_interface_put:
6089 +- usb_autopm_put_interface(serial->interface);
6090 +-bailout_module_put:
6091 +- mutex_unlock(&serial->disc_mutex);
6092 +- module_put(serial->type->driver.owner);
6093 +-bailout_mutex_unlock:
6094 +- port->port.count = 0;
6095 +- tty->driver_data = NULL;
6096 +- tty_port_tty_set(&port->port, NULL);
6097 +- mutex_unlock(&port->mutex);
6098 +-bailout_port_put:
6099 +- put_device(&port->dev);
6100 +-bailout_serial_put:
6101 +- usb_serial_put(serial);
6102 + return retval;
6103 + }
6104 +
6105 + /**
6106 +- * serial_do_down - shut down hardware
6107 +- * @port: port to shut down
6108 +- *
6109 +- * Shut down a USB port unless it is the console. We never shut down the
6110 +- * console hardware as it will always be in use.
6111 ++ * serial_down - shut down hardware
6112 ++ * @port: port to shut down
6113 + *
6114 +- * Don't free any resources at this point
6115 ++ * Shut down a USB serial port unless it is the console. We never
6116 ++ * shut down the console hardware as it will always be in use.
6117 + */
6118 +-static void serial_do_down(struct usb_serial_port *port)
6119 ++static void serial_down(struct usb_serial_port *port)
6120 + {
6121 + struct usb_serial_driver *drv = port->serial->type;
6122 + struct usb_serial *serial;
6123 + struct module *owner;
6124 +
6125 +- /* The console is magical, do not hang up the console hardware
6126 +- or there will be tears */
6127 ++ /*
6128 ++ * The console is magical. Do not hang up the console hardware
6129 ++ * or there will be tears.
6130 ++ */
6131 + if (port->console)
6132 + return;
6133 +
6134 ++ /* Don't call the close method if the hardware hasn't been
6135 ++ * initialized.
6136 ++ */
6137 ++ if (!test_and_clear_bit(ASYNCB_INITIALIZED, &port->port.flags))
6138 ++ return;
6139 ++
6140 + mutex_lock(&port->mutex);
6141 + serial = port->serial;
6142 + owner = serial->type->driver.owner;
6143 +@@ -310,79 +318,69 @@ static void serial_do_down(struct usb_serial_port *port)
6144 + mutex_unlock(&port->mutex);
6145 + }
6146 +
6147 +-/**
6148 +- * serial_do_free - free resources post close/hangup
6149 +- * @port: port to free up
6150 +- *
6151 +- * Do the resource freeing and refcount dropping for the port. We must
6152 +- * be careful about ordering and we must avoid freeing up the console.
6153 +- */
6154 +-
6155 +-static void serial_do_free(struct usb_serial_port *port)
6156 ++static void serial_hangup(struct tty_struct *tty)
6157 + {
6158 +- struct usb_serial *serial;
6159 +- struct module *owner;
6160 ++ struct usb_serial_port *port = tty->driver_data;
6161 +
6162 +- /* The console is magical, do not hang up the console hardware
6163 +- or there will be tears */
6164 +- if (port->console)
6165 +- return;
6166 ++ dbg("%s - port %d", __func__, port->number);
6167 +
6168 +- serial = port->serial;
6169 +- owner = serial->type->driver.owner;
6170 +- put_device(&port->dev);
6171 +- /* Mustn't dereference port any more */
6172 +- mutex_lock(&serial->disc_mutex);
6173 +- if (!serial->disconnected)
6174 +- usb_autopm_put_interface(serial->interface);
6175 +- mutex_unlock(&serial->disc_mutex);
6176 +- usb_serial_put(serial);
6177 +- /* Mustn't dereference serial any more */
6178 +- module_put(owner);
6179 ++ serial_down(port);
6180 ++ tty_port_hangup(&port->port);
6181 + }
6182 +
6183 + static void serial_close(struct tty_struct *tty, struct file *filp)
6184 + {
6185 + struct usb_serial_port *port = tty->driver_data;
6186 +
6187 +- if (!port)
6188 +- return;
6189 +-
6190 + dbg("%s - port %d", __func__, port->number);
6191 +
6192 +- /* FIXME:
6193 +- This leaves a very narrow race. Really we should do the
6194 +- serial_do_free() on tty->shutdown(), but tty->shutdown can
6195 +- be called from IRQ context and serial_do_free can sleep.
6196 +-
6197 +- The right fix is probably to make the tty free (which is rare)
6198 +- and thus tty->shutdown() occur via a work queue and simplify all
6199 +- the drivers that use it.
6200 +- */
6201 +- if (tty_hung_up_p(filp)) {
6202 +- /* serial_hangup already called serial_down at this point.
6203 +- Another user may have already reopened the port but
6204 +- serial_do_free is refcounted */
6205 +- serial_do_free(port);
6206 ++ if (tty_hung_up_p(filp))
6207 + return;
6208 +- }
6209 +-
6210 + if (tty_port_close_start(&port->port, tty, filp) == 0)
6211 + return;
6212 +-
6213 +- serial_do_down(port);
6214 ++ serial_down(port);
6215 + tty_port_close_end(&port->port, tty);
6216 + tty_port_tty_set(&port->port, NULL);
6217 +- serial_do_free(port);
6218 + }
6219 +
6220 +-static void serial_hangup(struct tty_struct *tty)
6221 ++/**
6222 ++ * serial_release - free resources post close/hangup
6223 ++ * @port: port to free up
6224 ++ *
6225 ++ * Do the resource freeing and refcount dropping for the port.
6226 ++ * Avoid freeing the console.
6227 ++ *
6228 ++ * Called when the last tty kref is dropped.
6229 ++ */
6230 ++static void serial_release(struct tty_struct *tty)
6231 + {
6232 + struct usb_serial_port *port = tty->driver_data;
6233 +- serial_do_down(port);
6234 +- tty_port_hangup(&port->port);
6235 +- /* We must not free port yet - the USB serial layer depends on it's
6236 +- continued existence */
6237 ++ struct usb_serial *serial;
6238 ++ struct module *owner;
6239 ++
6240 ++ /* The console is magical. Do not hang up the console hardware
6241 ++ * or there will be tears.
6242 ++ */
6243 ++ if (port->console)
6244 ++ return;
6245 ++
6246 ++ dbg("%s - port %d", __func__, port->number);
6247 ++
6248 ++ /* Standard shutdown processing */
6249 ++ tty_shutdown(tty);
6250 ++
6251 ++ tty->driver_data = NULL;
6252 ++
6253 ++ serial = port->serial;
6254 ++ owner = serial->type->driver.owner;
6255 ++
6256 ++ mutex_lock(&serial->disc_mutex);
6257 ++ if (!serial->disconnected)
6258 ++ usb_autopm_put_interface(serial->interface);
6259 ++ mutex_unlock(&serial->disc_mutex);
6260 ++
6261 ++ usb_serial_put(serial);
6262 ++ module_put(owner);
6263 + }
6264 +
6265 + static int serial_write(struct tty_struct *tty, const unsigned char *buf,
6266 +@@ -527,6 +525,7 @@ static int serial_proc_show(struct seq_file *m, void *v)
6267 +
6268 + seq_putc(m, '\n');
6269 + usb_serial_put(serial);
6270 ++ mutex_unlock(&serial->disc_mutex);
6271 + }
6272 + return 0;
6273 + }
6274 +@@ -596,14 +595,6 @@ static void usb_serial_port_work(struct work_struct *work)
6275 + tty_kref_put(tty);
6276 + }
6277 +
6278 +-static void port_release(struct device *dev)
6279 +-{
6280 +- struct usb_serial_port *port = to_usb_serial_port(dev);
6281 +-
6282 +- dbg ("%s - %s", __func__, dev_name(dev));
6283 +- port_free(port);
6284 +-}
6285 +-
6286 + static void kill_traffic(struct usb_serial_port *port)
6287 + {
6288 + usb_kill_urb(port->read_urb);
6289 +@@ -623,8 +614,12 @@ static void kill_traffic(struct usb_serial_port *port)
6290 + usb_kill_urb(port->interrupt_out_urb);
6291 + }
6292 +
6293 +-static void port_free(struct usb_serial_port *port)
6294 ++static void port_release(struct device *dev)
6295 + {
6296 ++ struct usb_serial_port *port = to_usb_serial_port(dev);
6297 ++
6298 ++ dbg ("%s - %s", __func__, dev_name(dev));
6299 ++
6300 + /*
6301 + * Stop all the traffic before cancelling the work, so that
6302 + * nobody will restart it by calling usb_serial_port_softint.
6303 +@@ -935,6 +930,11 @@ int usb_serial_probe(struct usb_interface *interface,
6304 + mutex_init(&port->mutex);
6305 + INIT_WORK(&port->work, usb_serial_port_work);
6306 + serial->port[i] = port;
6307 ++ port->dev.parent = &interface->dev;
6308 ++ port->dev.driver = NULL;
6309 ++ port->dev.bus = &usb_serial_bus_type;
6310 ++ port->dev.release = &port_release;
6311 ++ device_initialize(&port->dev);
6312 + }
6313 +
6314 + /* set up the endpoint information */
6315 +@@ -1077,15 +1077,10 @@ int usb_serial_probe(struct usb_interface *interface,
6316 + /* register all of the individual ports with the driver core */
6317 + for (i = 0; i < num_ports; ++i) {
6318 + port = serial->port[i];
6319 +- port->dev.parent = &interface->dev;
6320 +- port->dev.driver = NULL;
6321 +- port->dev.bus = &usb_serial_bus_type;
6322 +- port->dev.release = &port_release;
6323 +-
6324 + dev_set_name(&port->dev, "ttyUSB%d", port->number);
6325 + dbg ("%s - registering %s", __func__, dev_name(&port->dev));
6326 + port->dev_state = PORT_REGISTERING;
6327 +- retval = device_register(&port->dev);
6328 ++ retval = device_add(&port->dev);
6329 + if (retval) {
6330 + dev_err(&port->dev, "Error registering port device, "
6331 + "continuing\n");
6332 +@@ -1103,39 +1098,7 @@ exit:
6333 + return 0;
6334 +
6335 + probe_error:
6336 +- for (i = 0; i < num_bulk_in; ++i) {
6337 +- port = serial->port[i];
6338 +- if (!port)
6339 +- continue;
6340 +- usb_free_urb(port->read_urb);
6341 +- kfree(port->bulk_in_buffer);
6342 +- }
6343 +- for (i = 0; i < num_bulk_out; ++i) {
6344 +- port = serial->port[i];
6345 +- if (!port)
6346 +- continue;
6347 +- usb_free_urb(port->write_urb);
6348 +- kfree(port->bulk_out_buffer);
6349 +- }
6350 +- for (i = 0; i < num_interrupt_in; ++i) {
6351 +- port = serial->port[i];
6352 +- if (!port)
6353 +- continue;
6354 +- usb_free_urb(port->interrupt_in_urb);
6355 +- kfree(port->interrupt_in_buffer);
6356 +- }
6357 +- for (i = 0; i < num_interrupt_out; ++i) {
6358 +- port = serial->port[i];
6359 +- if (!port)
6360 +- continue;
6361 +- usb_free_urb(port->interrupt_out_urb);
6362 +- kfree(port->interrupt_out_buffer);
6363 +- }
6364 +-
6365 +- /* free up any memory that we allocated */
6366 +- for (i = 0; i < serial->num_port_pointers; ++i)
6367 +- kfree(serial->port[i]);
6368 +- kfree(serial);
6369 ++ usb_serial_put(serial);
6370 + return -EIO;
6371 + }
6372 + EXPORT_SYMBOL_GPL(usb_serial_probe);
6373 +@@ -1161,10 +1124,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
6374 + if (port) {
6375 + struct tty_struct *tty = tty_port_tty_get(&port->port);
6376 + if (tty) {
6377 +- /* The hangup will occur asynchronously but
6378 +- the object refcounts will sort out all the
6379 +- cleanup */
6380 +- tty_hangup(tty);
6381 ++ tty_vhangup(tty);
6382 + tty_kref_put(tty);
6383 + }
6384 + kill_traffic(port);
6385 +@@ -1189,8 +1149,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
6386 + }
6387 + serial->type->disconnect(serial);
6388 +
6389 +- /* let the last holder of this object
6390 +- * cause it to be cleaned up */
6391 ++ /* let the last holder of this object cause it to be cleaned up */
6392 + usb_serial_put(serial);
6393 + dev_info(dev, "device disconnected\n");
6394 + }
6395 +@@ -1246,6 +1205,8 @@ static const struct tty_operations serial_ops = {
6396 + .chars_in_buffer = serial_chars_in_buffer,
6397 + .tiocmget = serial_tiocmget,
6398 + .tiocmset = serial_tiocmset,
6399 ++ .shutdown = serial_release,
6400 ++ .install = serial_install,
6401 + .proc_fops = &serial_proc_fops,
6402 + };
6403 +
6404 +diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
6405 +index 8d126dd..f7232b1 100644
6406 +--- a/drivers/usb/serial/whiteheat.c
6407 ++++ b/drivers/usb/serial/whiteheat.c
6408 +@@ -259,7 +259,7 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command,
6409 + __u8 *data, __u8 datasize);
6410 + static int firm_open(struct usb_serial_port *port);
6411 + static int firm_close(struct usb_serial_port *port);
6412 +-static int firm_setup_port(struct tty_struct *tty);
6413 ++static void firm_setup_port(struct tty_struct *tty);
6414 + static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
6415 + static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
6416 + static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
6417 +@@ -1211,7 +1211,7 @@ static int firm_close(struct usb_serial_port *port)
6418 + }
6419 +
6420 +
6421 +-static int firm_setup_port(struct tty_struct *tty)
6422 ++static void firm_setup_port(struct tty_struct *tty)
6423 + {
6424 + struct usb_serial_port *port = tty->driver_data;
6425 + struct whiteheat_port_settings port_settings;
6426 +@@ -1286,7 +1286,7 @@ static int firm_setup_port(struct tty_struct *tty)
6427 + port_settings.lloop = 0;
6428 +
6429 + /* now send the message to the device */
6430 +- return firm_send_command(port, WHITEHEAT_SETUP_PORT,
6431 ++ firm_send_command(port, WHITEHEAT_SETUP_PORT,
6432 + (__u8 *)&port_settings, sizeof(port_settings));
6433 + }
6434 +
6435 +diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c
6436 +index ec17c96..105d900 100644
6437 +--- a/drivers/usb/storage/initializers.c
6438 ++++ b/drivers/usb/storage/initializers.c
6439 +@@ -102,5 +102,5 @@ int usb_stor_huawei_e220_init(struct us_data *us)
6440 + USB_TYPE_STANDARD | USB_RECIP_DEVICE,
6441 + 0x01, 0x0, NULL, 0x0, 1000);
6442 + US_DEBUGP("Huawei mode set result is %d\n", result);
6443 +- return (result ? 0 : -ENODEV);
6444 ++ return 0;
6445 + }
6446 +diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
6447 +index 380233b..80e65f2 100644
6448 +--- a/drivers/usb/storage/onetouch.c
6449 ++++ b/drivers/usb/storage/onetouch.c
6450 +@@ -163,7 +163,7 @@ static void usb_onetouch_pm_hook(struct us_data *us, int action)
6451 + usb_kill_urb(onetouch->irq);
6452 + break;
6453 + case US_RESUME:
6454 +- if (usb_submit_urb(onetouch->irq, GFP_KERNEL) != 0)
6455 ++ if (usb_submit_urb(onetouch->irq, GFP_NOIO) != 0)
6456 + dev_err(&onetouch->irq->dev->dev,
6457 + "usb_submit_urb failed\n");
6458 + break;
6459 +diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
6460 +index 3a44695..29ff5ea 100644
6461 +--- a/drivers/video/console/fbcon.c
6462 ++++ b/drivers/video/console/fbcon.c
6463 +@@ -114,6 +114,7 @@ static int last_fb_vc = MAX_NR_CONSOLES - 1;
6464 + static int fbcon_is_default = 1;
6465 + static int fbcon_has_exited;
6466 + static int primary_device = -1;
6467 ++static int fbcon_has_console_bind;
6468 +
6469 + #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
6470 + static int map_override;
6471 +@@ -544,6 +545,8 @@ static int fbcon_takeover(int show_logo)
6472 + con2fb_map[i] = -1;
6473 + }
6474 + info_idx = -1;
6475 ++ } else {
6476 ++ fbcon_has_console_bind = 1;
6477 + }
6478 +
6479 + return err;
6480 +@@ -2923,6 +2926,10 @@ static int fbcon_unbind(void)
6481 +
6482 + ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
6483 + fbcon_is_default);
6484 ++
6485 ++ if (!ret)
6486 ++ fbcon_has_console_bind = 0;
6487 ++
6488 + return ret;
6489 + }
6490 + #else
6491 +@@ -2936,6 +2943,9 @@ static int fbcon_fb_unbind(int idx)
6492 + {
6493 + int i, new_idx = -1, ret = 0;
6494 +
6495 ++ if (!fbcon_has_console_bind)
6496 ++ return 0;
6497 ++
6498 + for (i = first_fb_vc; i <= last_fb_vc; i++) {
6499 + if (con2fb_map[i] != idx &&
6500 + con2fb_map[i] != -1) {
6501 +diff --git a/drivers/video/s3c-fb.c b/drivers/video/s3c-fb.c
6502 +index 5a72083..adf9632 100644
6503 +--- a/drivers/video/s3c-fb.c
6504 ++++ b/drivers/video/s3c-fb.c
6505 +@@ -1036,7 +1036,7 @@ static int s3c_fb_resume(struct platform_device *pdev)
6506 +
6507 + static struct platform_driver s3c_fb_driver = {
6508 + .probe = s3c_fb_probe,
6509 +- .remove = s3c_fb_remove,
6510 ++ .remove = __devexit_p(s3c_fb_remove),
6511 + .suspend = s3c_fb_suspend,
6512 + .resume = s3c_fb_resume,
6513 + .driver = {
6514 +diff --git a/drivers/video/sis/vstruct.h b/drivers/video/sis/vstruct.h
6515 +index 705c853..bef4aae 100644
6516 +--- a/drivers/video/sis/vstruct.h
6517 ++++ b/drivers/video/sis/vstruct.h
6518 +@@ -342,7 +342,7 @@ struct SiS_Private
6519 + unsigned short SiS_RY4COE;
6520 + unsigned short SiS_LCDHDES;
6521 + unsigned short SiS_LCDVDES;
6522 +- unsigned short SiS_DDC_Port;
6523 ++ SISIOADDRESS SiS_DDC_Port;
6524 + unsigned short SiS_DDC_Index;
6525 + unsigned short SiS_DDC_Data;
6526 + unsigned short SiS_DDC_NData;
6527 +diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
6528 +index ec2a39b..7c28434 100644
6529 +--- a/drivers/xen/Makefile
6530 ++++ b/drivers/xen/Makefile
6531 +@@ -1,6 +1,9 @@
6532 + obj-y += grant-table.o features.o events.o manage.o
6533 + obj-y += xenbus/
6534 +
6535 ++nostackp := $(call cc-option, -fno-stack-protector)
6536 ++CFLAGS_features.o := $(nostackp)
6537 ++
6538 + obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o
6539 + obj-$(CONFIG_XEN_XENCOMM) += xencomm.o
6540 + obj-$(CONFIG_XEN_BALLOON) += balloon.o
6541 +diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
6542 +index 6084d63..3cfec69 100644
6543 +--- a/fs/cifs/cifsglob.h
6544 ++++ b/fs/cifs/cifsglob.h
6545 +@@ -572,9 +572,9 @@ require use of the stronger protocol */
6546 + #define CIFSSEC_MUST_LANMAN 0x10010
6547 + #define CIFSSEC_MUST_PLNTXT 0x20020
6548 + #ifdef CONFIG_CIFS_UPCALL
6549 +-#define CIFSSEC_MASK 0xAF0AF /* allows weak security but also krb5 */
6550 ++#define CIFSSEC_MASK 0xBF0BF /* allows weak security but also krb5 */
6551 + #else
6552 +-#define CIFSSEC_MASK 0xA70A7 /* current flags supported if weak */
6553 ++#define CIFSSEC_MASK 0xB70B7 /* current flags supported if weak */
6554 + #endif /* UPCALL */
6555 + #else /* do not allow weak pw hash */
6556 + #ifdef CONFIG_CIFS_UPCALL
6557 +diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
6558 +index b91851f..f0b53df 100644
6559 +--- a/fs/ecryptfs/crypto.c
6560 ++++ b/fs/ecryptfs/crypto.c
6561 +@@ -797,6 +797,7 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat)
6562 + kfree(full_alg_name);
6563 + if (IS_ERR(crypt_stat->tfm)) {
6564 + rc = PTR_ERR(crypt_stat->tfm);
6565 ++ crypt_stat->tfm = NULL;
6566 + ecryptfs_printk(KERN_ERR, "cryptfs: init_crypt_ctx(): "
6567 + "Error initializing cipher [%s]\n",
6568 + crypt_stat->cipher);
6569 +@@ -1702,7 +1703,7 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename *filename,
6570 + } else {
6571 + printk(KERN_ERR "%s: No support for requested filename "
6572 + "encryption method in this release\n", __func__);
6573 +- rc = -ENOTSUPP;
6574 ++ rc = -EOPNOTSUPP;
6575 + goto out;
6576 + }
6577 + out:
6578 +@@ -2166,7 +2167,7 @@ int ecryptfs_encrypt_and_encode_filename(
6579 + (*encoded_name)[(*encoded_name_size)] = '\0';
6580 + (*encoded_name_size)++;
6581 + } else {
6582 +- rc = -ENOTSUPP;
6583 ++ rc = -EOPNOTSUPP;
6584 + }
6585 + if (rc) {
6586 + printk(KERN_ERR "%s: Error attempting to encode "
6587 +diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
6588 +index 2f0945d..056fed6 100644
6589 +--- a/fs/ecryptfs/inode.c
6590 ++++ b/fs/ecryptfs/inode.c
6591 +@@ -476,6 +476,7 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
6592 + struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
6593 + struct dentry *lower_dir_dentry;
6594 +
6595 ++ dget(lower_dentry);
6596 + lower_dir_dentry = lock_parent(lower_dentry);
6597 + rc = vfs_unlink(lower_dir_inode, lower_dentry);
6598 + if (rc) {
6599 +@@ -489,6 +490,7 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
6600 + d_drop(dentry);
6601 + out_unlock:
6602 + unlock_dir(lower_dir_dentry);
6603 ++ dput(lower_dentry);
6604 + return rc;
6605 + }
6606 +
6607 +diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
6608 +index 259525c..c77438f 100644
6609 +--- a/fs/ecryptfs/keystore.c
6610 ++++ b/fs/ecryptfs/keystore.c
6611 +@@ -416,7 +416,9 @@ ecryptfs_find_global_auth_tok_for_sig(
6612 + &mount_crypt_stat->global_auth_tok_list,
6613 + mount_crypt_stat_list) {
6614 + if (memcmp(walker->sig, sig, ECRYPTFS_SIG_SIZE_HEX) == 0) {
6615 +- (*global_auth_tok) = walker;
6616 ++ rc = key_validate(walker->global_auth_tok_key);
6617 ++ if (!rc)
6618 ++ (*global_auth_tok) = walker;
6619 + goto out;
6620 + }
6621 + }
6622 +@@ -612,7 +614,12 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
6623 + }
6624 + /* TODO: Support other key modules than passphrase for
6625 + * filename encryption */
6626 +- BUG_ON(s->auth_tok->token_type != ECRYPTFS_PASSWORD);
6627 ++ if (s->auth_tok->token_type != ECRYPTFS_PASSWORD) {
6628 ++ rc = -EOPNOTSUPP;
6629 ++ printk(KERN_INFO "%s: Filename encryption only supports "
6630 ++ "password tokens\n", __func__);
6631 ++ goto out_free_unlock;
6632 ++ }
6633 + sg_init_one(
6634 + &s->hash_sg,
6635 + (u8 *)s->auth_tok->token.password.session_key_encryption_key,
6636 +@@ -910,7 +917,12 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
6637 + }
6638 + /* TODO: Support other key modules than passphrase for
6639 + * filename encryption */
6640 +- BUG_ON(s->auth_tok->token_type != ECRYPTFS_PASSWORD);
6641 ++ if (s->auth_tok->token_type != ECRYPTFS_PASSWORD) {
6642 ++ rc = -EOPNOTSUPP;
6643 ++ printk(KERN_INFO "%s: Filename encryption only supports "
6644 ++ "password tokens\n", __func__);
6645 ++ goto out_free_unlock;
6646 ++ }
6647 + rc = crypto_blkcipher_setkey(
6648 + s->desc.tfm,
6649 + s->auth_tok->token.password.session_key_encryption_key,
6650 +@@ -1316,8 +1328,10 @@ parse_tag_3_packet(struct ecryptfs_crypt_stat *crypt_stat,
6651 + rc = -EINVAL;
6652 + goto out_free;
6653 + }
6654 +- ecryptfs_cipher_code_to_string(crypt_stat->cipher,
6655 +- (u16)data[(*packet_size)]);
6656 ++ rc = ecryptfs_cipher_code_to_string(crypt_stat->cipher,
6657 ++ (u16)data[(*packet_size)]);
6658 ++ if (rc)
6659 ++ goto out_free;
6660 + /* A little extra work to differentiate among the AES key
6661 + * sizes; see RFC2440 */
6662 + switch(data[(*packet_size)++]) {
6663 +@@ -1328,7 +1342,9 @@ parse_tag_3_packet(struct ecryptfs_crypt_stat *crypt_stat,
6664 + crypt_stat->key_size =
6665 + (*new_auth_tok)->session_key.encrypted_key_size;
6666 + }
6667 +- ecryptfs_init_crypt_ctx(crypt_stat);
6668 ++ rc = ecryptfs_init_crypt_ctx(crypt_stat);
6669 ++ if (rc)
6670 ++ goto out_free;
6671 + if (unlikely(data[(*packet_size)++] != 0x03)) {
6672 + printk(KERN_WARNING "Only S2K ID 3 is currently supported\n");
6673 + rc = -ENOSYS;
6674 +diff --git a/fs/ecryptfs/kthread.c b/fs/ecryptfs/kthread.c
6675 +index c6d7a4d..e14cf7e 100644
6676 +--- a/fs/ecryptfs/kthread.c
6677 ++++ b/fs/ecryptfs/kthread.c
6678 +@@ -136,6 +136,7 @@ int ecryptfs_privileged_open(struct file **lower_file,
6679 + const struct cred *cred)
6680 + {
6681 + struct ecryptfs_open_req *req;
6682 ++ int flags = O_LARGEFILE;
6683 + int rc = 0;
6684 +
6685 + /* Corresponding dput() and mntput() are done when the
6686 +@@ -143,10 +144,14 @@ int ecryptfs_privileged_open(struct file **lower_file,
6687 + * destroyed. */
6688 + dget(lower_dentry);
6689 + mntget(lower_mnt);
6690 +- (*lower_file) = dentry_open(lower_dentry, lower_mnt,
6691 +- (O_RDWR | O_LARGEFILE), cred);
6692 ++ flags |= IS_RDONLY(lower_dentry->d_inode) ? O_RDONLY : O_RDWR;
6693 ++ (*lower_file) = dentry_open(lower_dentry, lower_mnt, flags, cred);
6694 + if (!IS_ERR(*lower_file))
6695 + goto out;
6696 ++ if (flags & O_RDONLY) {
6697 ++ rc = PTR_ERR((*lower_file));
6698 ++ goto out;
6699 ++ }
6700 + req = kmem_cache_alloc(ecryptfs_open_req_cache, GFP_KERNEL);
6701 + if (!req) {
6702 + rc = -ENOMEM;
6703 +@@ -180,21 +185,8 @@ int ecryptfs_privileged_open(struct file **lower_file,
6704 + __func__);
6705 + goto out_unlock;
6706 + }
6707 +- if (IS_ERR(*req->lower_file)) {
6708 ++ if (IS_ERR(*req->lower_file))
6709 + rc = PTR_ERR(*req->lower_file);
6710 +- dget(lower_dentry);
6711 +- mntget(lower_mnt);
6712 +- (*lower_file) = dentry_open(lower_dentry, lower_mnt,
6713 +- (O_RDONLY | O_LARGEFILE), cred);
6714 +- if (IS_ERR(*lower_file)) {
6715 +- rc = PTR_ERR(*req->lower_file);
6716 +- (*lower_file) = NULL;
6717 +- printk(KERN_WARNING "%s: Error attempting privileged "
6718 +- "open of lower file with either RW or RO "
6719 +- "perms; rc = [%d]. Giving up.\n",
6720 +- __func__, rc);
6721 +- }
6722 +- }
6723 + out_unlock:
6724 + mutex_unlock(&req->mux);
6725 + out_free:
6726 +diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
6727 +index 9f0aa98..101fe4c 100644
6728 +--- a/fs/ecryptfs/main.c
6729 ++++ b/fs/ecryptfs/main.c
6730 +@@ -129,11 +129,10 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
6731 + lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
6732 + rc = ecryptfs_privileged_open(&inode_info->lower_file,
6733 + lower_dentry, lower_mnt, cred);
6734 +- if (rc || IS_ERR(inode_info->lower_file)) {
6735 ++ if (rc) {
6736 + printk(KERN_ERR "Error opening lower persistent file "
6737 + "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
6738 + "rc = [%d]\n", lower_dentry, lower_mnt, rc);
6739 +- rc = PTR_ERR(inode_info->lower_file);
6740 + inode_info->lower_file = NULL;
6741 + }
6742 + }
6743 +diff --git a/fs/inode.c b/fs/inode.c
6744 +index ae7b67e..1a959c0 100644
6745 +--- a/fs/inode.c
6746 ++++ b/fs/inode.c
6747 +@@ -697,13 +697,15 @@ void unlock_new_inode(struct inode *inode)
6748 + }
6749 + #endif
6750 + /*
6751 +- * This is special! We do not need the spinlock
6752 +- * when clearing I_LOCK, because we're guaranteed
6753 +- * that nobody else tries to do anything about the
6754 +- * state of the inode when it is locked, as we
6755 +- * just created it (so there can be no old holders
6756 +- * that haven't tested I_LOCK).
6757 ++ * This is special! We do not need the spinlock when clearing I_LOCK,
6758 ++ * because we're guaranteed that nobody else tries to do anything about
6759 ++ * the state of the inode when it is locked, as we just created it (so
6760 ++ * there can be no old holders that haven't tested I_LOCK).
6761 ++ * However we must emit the memory barrier so that other CPUs reliably
6762 ++ * see the clearing of I_LOCK after the other inode initialisation has
6763 ++ * completed.
6764 + */
6765 ++ smp_mb();
6766 + WARN_ON((inode->i_state & (I_LOCK|I_NEW)) != (I_LOCK|I_NEW));
6767 + inode->i_state &= ~(I_LOCK|I_NEW);
6768 + wake_up_inode(inode);
6769 +diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
6770 +index 3fd23f7..bf9b470 100644
6771 +--- a/fs/nfsd/nfs4callback.c
6772 ++++ b/fs/nfsd/nfs4callback.c
6773 +@@ -444,6 +444,7 @@ static struct rpc_cred *lookup_cb_cred(struct nfs4_cb_conn *cb)
6774 + struct auth_cred acred = {
6775 + .machine_cred = 1
6776 + };
6777 ++ struct rpc_auth *auth = cb->cb_client->cl_auth;
6778 +
6779 + /*
6780 + * Note in the gss case this doesn't actually have to wait for a
6781 +@@ -451,8 +452,7 @@ static struct rpc_cred *lookup_cb_cred(struct nfs4_cb_conn *cb)
6782 + * non-uptodate cred which the rpc state machine will fill in with
6783 + * a refresh_upcall later.
6784 + */
6785 +- return rpcauth_lookup_credcache(cb->cb_client->cl_auth, &acred,
6786 +- RPCAUTH_LOOKUP_NEW);
6787 ++ return auth->au_ops->lookup_cred(auth, &acred, RPCAUTH_LOOKUP_NEW);
6788 + }
6789 +
6790 + void do_probe_callback(struct nfs4_client *clp)
6791 +diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c
6792 +index c668bca..5be2c8b 100644
6793 +--- a/fs/nilfs2/btnode.c
6794 ++++ b/fs/nilfs2/btnode.c
6795 +@@ -36,6 +36,7 @@
6796 +
6797 + void nilfs_btnode_cache_init_once(struct address_space *btnc)
6798 + {
6799 ++ memset(btnc, 0, sizeof(*btnc));
6800 + INIT_RADIX_TREE(&btnc->page_tree, GFP_ATOMIC);
6801 + spin_lock_init(&btnc->tree_lock);
6802 + INIT_LIST_HEAD(&btnc->private_list);
6803 +diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
6804 +index 59b43a0..5fd7d2b 100644
6805 +--- a/fs/proc/kcore.c
6806 ++++ b/fs/proc/kcore.c
6807 +@@ -361,7 +361,13 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
6808 + /* don't dump ioremap'd stuff! (TA) */
6809 + if (m->flags & VM_IOREMAP)
6810 + continue;
6811 +- memcpy(elf_buf + (vmstart - start),
6812 ++ /*
6813 ++ * we may access memory holes, then use
6814 ++ * ex_table. checking return value just for
6815 ++ * avoid warnings.
6816 ++ */
6817 ++ vmsize = __copy_from_user_inatomic(
6818 ++ elf_buf + (vmstart - start),
6819 + (char *)vmstart, vmsize);
6820 + }
6821 + read_unlock(&vmlist_lock);
6822 +diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c
6823 +index 0c10a0b..766b1d4 100644
6824 +--- a/fs/proc/uptime.c
6825 ++++ b/fs/proc/uptime.c
6826 +@@ -4,13 +4,18 @@
6827 + #include <linux/sched.h>
6828 + #include <linux/seq_file.h>
6829 + #include <linux/time.h>
6830 ++#include <linux/kernel_stat.h>
6831 + #include <asm/cputime.h>
6832 +
6833 + static int uptime_proc_show(struct seq_file *m, void *v)
6834 + {
6835 + struct timespec uptime;
6836 + struct timespec idle;
6837 +- cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
6838 ++ int i;
6839 ++ cputime_t idletime = cputime_zero;
6840 ++
6841 ++ for_each_possible_cpu(i)
6842 ++ idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
6843 +
6844 + do_posix_clock_monotonic_gettime(&uptime);
6845 + monotonic_to_bootbased(&uptime);
6846 +diff --git a/include/linux/tty.h b/include/linux/tty.h
6847 +index e8c6c91..b982a17 100644
6848 +--- a/include/linux/tty.h
6849 ++++ b/include/linux/tty.h
6850 +@@ -185,7 +185,12 @@ struct tty_port;
6851 + struct tty_port_operations {
6852 + /* Return 1 if the carrier is raised */
6853 + int (*carrier_raised)(struct tty_port *port);
6854 ++ /* Control the DTR line */
6855 + void (*dtr_rts)(struct tty_port *port, int raise);
6856 ++ /* Called when the last close completes or a hangup finishes
6857 ++ IFF the port was initialized. Do not use to free resources */
6858 ++ void (*shutdown)(struct tty_port *port);
6859 ++ void (*drop)(struct tty_port *port);
6860 + };
6861 +
6862 + struct tty_port {
6863 +@@ -457,7 +462,8 @@ extern int tty_port_block_til_ready(struct tty_port *port,
6864 + extern int tty_port_close_start(struct tty_port *port,
6865 + struct tty_struct *tty, struct file *filp);
6866 + extern void tty_port_close_end(struct tty_port *port, struct tty_struct *tty);
6867 +-
6868 ++extern void tty_port_close(struct tty_port *port,
6869 ++ struct tty_struct *tty, struct file *filp);
6870 + extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
6871 + extern int tty_unregister_ldisc(int disc);
6872 + extern int tty_set_ldisc(struct tty_struct *tty, int ldisc);
6873 +diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
6874 +index 0ec50ba..73f121e 100644
6875 +--- a/include/linux/usb/serial.h
6876 ++++ b/include/linux/usb/serial.h
6877 +@@ -261,6 +261,9 @@ struct usb_serial_driver {
6878 + be an attached tty at this point */
6879 + void (*dtr_rts)(struct usb_serial_port *port, int on);
6880 + int (*carrier_raised)(struct usb_serial_port *port);
6881 ++ /* Called by the usb serial hooks to allow the user to rework the
6882 ++ termios state */
6883 ++ void (*init_termios)(struct tty_struct *tty);
6884 + /* USB events */
6885 + void (*read_int_callback)(struct urb *urb);
6886 + void (*write_int_callback)(struct urb *urb);
6887 +diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h
6888 +index 9b4ac93..56677eb 100644
6889 +--- a/include/pcmcia/ss.h
6890 ++++ b/include/pcmcia/ss.h
6891 +@@ -279,7 +279,7 @@ extern struct pccard_resource_ops pccard_iodyn_ops;
6892 + extern struct pccard_resource_ops pccard_nonstatic_ops;
6893 +
6894 + /* socket drivers are expected to use these callbacks in their .drv struct */
6895 +-extern int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state);
6896 ++extern int pcmcia_socket_dev_suspend(struct device *dev);
6897 + extern int pcmcia_socket_dev_resume(struct device *dev);
6898 +
6899 + /* socket drivers use this callback in their IRQ handler */
6900 +diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
6901 +index 3f49f53..b1dc468 100644
6902 +--- a/kernel/perf_counter.c
6903 ++++ b/kernel/perf_counter.c
6904 +@@ -4143,8 +4143,8 @@ done:
6905 + static int perf_copy_attr(struct perf_counter_attr __user *uattr,
6906 + struct perf_counter_attr *attr)
6907 + {
6908 +- int ret;
6909 + u32 size;
6910 ++ int ret;
6911 +
6912 + if (!access_ok(VERIFY_WRITE, uattr, PERF_ATTR_SIZE_VER0))
6913 + return -EFAULT;
6914 +@@ -4169,19 +4169,19 @@ static int perf_copy_attr(struct perf_counter_attr __user *uattr,
6915 +
6916 + /*
6917 + * If we're handed a bigger struct than we know of,
6918 +- * ensure all the unknown bits are 0.
6919 ++ * ensure all the unknown bits are 0 - i.e. new
6920 ++ * user-space does not rely on any kernel feature
6921 ++ * extensions we dont know about yet.
6922 + */
6923 + if (size > sizeof(*attr)) {
6924 +- unsigned long val;
6925 +- unsigned long __user *addr;
6926 +- unsigned long __user *end;
6927 ++ unsigned char __user *addr;
6928 ++ unsigned char __user *end;
6929 ++ unsigned char val;
6930 +
6931 +- addr = PTR_ALIGN((void __user *)uattr + sizeof(*attr),
6932 +- sizeof(unsigned long));
6933 +- end = PTR_ALIGN((void __user *)uattr + size,
6934 +- sizeof(unsigned long));
6935 ++ addr = (void __user *)uattr + sizeof(*attr);
6936 ++ end = (void __user *)uattr + size;
6937 +
6938 +- for (; addr < end; addr += sizeof(unsigned long)) {
6939 ++ for (; addr < end; addr++) {
6940 + ret = get_user(val, addr);
6941 + if (ret)
6942 + return ret;
6943 +diff --git a/mm/hugetlb.c b/mm/hugetlb.c
6944 +index cafdcee..cae0337 100644
6945 +--- a/mm/hugetlb.c
6946 ++++ b/mm/hugetlb.c
6947 +@@ -1010,6 +1010,7 @@ int __weak alloc_bootmem_huge_page(struct hstate *h)
6948 + NODE_DATA(h->hugetlb_next_nid),
6949 + huge_page_size(h), huge_page_size(h), 0);
6950 +
6951 ++ hstate_next_node(h);
6952 + if (addr) {
6953 + /*
6954 + * Use the beginning of the huge page to store the
6955 +@@ -1019,7 +1020,6 @@ int __weak alloc_bootmem_huge_page(struct hstate *h)
6956 + m = addr;
6957 + goto found;
6958 + }
6959 +- hstate_next_node(h);
6960 + nr_nodes--;
6961 + }
6962 + return 0;
6963 +diff --git a/mm/memory.c b/mm/memory.c
6964 +index aede2ce..753b2e6 100644
6965 +--- a/mm/memory.c
6966 ++++ b/mm/memory.c
6967 +@@ -2638,7 +2638,8 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
6968 + goto oom_free_page;
6969 +
6970 + entry = mk_pte(page, vma->vm_page_prot);
6971 +- entry = maybe_mkwrite(pte_mkdirty(entry), vma);
6972 ++ if (vma->vm_flags & VM_WRITE)
6973 ++ entry = pte_mkwrite(pte_mkdirty(entry));
6974 +
6975 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
6976 + if (!pte_none(*page_table))
6977 +diff --git a/mm/mlock.c b/mm/mlock.c
6978 +index 45eb650..e13918d 100644
6979 +--- a/mm/mlock.c
6980 ++++ b/mm/mlock.c
6981 +@@ -139,49 +139,36 @@ static void munlock_vma_page(struct page *page)
6982 + }
6983 +
6984 + /**
6985 +- * __mlock_vma_pages_range() - mlock/munlock a range of pages in the vma.
6986 ++ * __mlock_vma_pages_range() - mlock a range of pages in the vma.
6987 + * @vma: target vma
6988 + * @start: start address
6989 + * @end: end address
6990 +- * @mlock: 0 indicate munlock, otherwise mlock.
6991 + *
6992 +- * If @mlock == 0, unlock an mlocked range;
6993 +- * else mlock the range of pages. This takes care of making the pages present ,
6994 +- * too.
6995 ++ * This takes care of making the pages present too.
6996 + *
6997 + * return 0 on success, negative error code on error.
6998 + *
6999 + * vma->vm_mm->mmap_sem must be held for at least read.
7000 + */
7001 + static long __mlock_vma_pages_range(struct vm_area_struct *vma,
7002 +- unsigned long start, unsigned long end,
7003 +- int mlock)
7004 ++ unsigned long start, unsigned long end)
7005 + {
7006 + struct mm_struct *mm = vma->vm_mm;
7007 + unsigned long addr = start;
7008 + struct page *pages[16]; /* 16 gives a reasonable batch */
7009 + int nr_pages = (end - start) / PAGE_SIZE;
7010 + int ret = 0;
7011 +- int gup_flags = 0;
7012 ++ int gup_flags;
7013 +
7014 + VM_BUG_ON(start & ~PAGE_MASK);
7015 + VM_BUG_ON(end & ~PAGE_MASK);
7016 + VM_BUG_ON(start < vma->vm_start);
7017 + VM_BUG_ON(end > vma->vm_end);
7018 +- VM_BUG_ON((!rwsem_is_locked(&mm->mmap_sem)) &&
7019 +- (atomic_read(&mm->mm_users) != 0));
7020 +-
7021 +- /*
7022 +- * mlock: don't page populate if vma has PROT_NONE permission.
7023 +- * munlock: always do munlock although the vma has PROT_NONE
7024 +- * permission, or SIGKILL is pending.
7025 +- */
7026 +- if (!mlock)
7027 +- gup_flags |= GUP_FLAGS_IGNORE_VMA_PERMISSIONS |
7028 +- GUP_FLAGS_IGNORE_SIGKILL;
7029 ++ VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
7030 +
7031 ++ gup_flags = 0;
7032 + if (vma->vm_flags & VM_WRITE)
7033 +- gup_flags |= GUP_FLAGS_WRITE;
7034 ++ gup_flags = GUP_FLAGS_WRITE;
7035 +
7036 + while (nr_pages > 0) {
7037 + int i;
7038 +@@ -201,19 +188,10 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
7039 + * This can happen for, e.g., VM_NONLINEAR regions before
7040 + * a page has been allocated and mapped at a given offset,
7041 + * or for addresses that map beyond end of a file.
7042 +- * We'll mlock the the pages if/when they get faulted in.
7043 ++ * We'll mlock the pages if/when they get faulted in.
7044 + */
7045 + if (ret < 0)
7046 + break;
7047 +- if (ret == 0) {
7048 +- /*
7049 +- * We know the vma is there, so the only time
7050 +- * we cannot get a single page should be an
7051 +- * error (ret < 0) case.
7052 +- */
7053 +- WARN_ON(1);
7054 +- break;
7055 +- }
7056 +
7057 + lru_add_drain(); /* push cached pages to LRU */
7058 +
7059 +@@ -224,28 +202,22 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
7060 + /*
7061 + * Because we lock page here and migration is blocked
7062 + * by the elevated reference, we need only check for
7063 +- * page truncation (file-cache only).
7064 ++ * file-cache page truncation. This page->mapping
7065 ++ * check also neatly skips over the ZERO_PAGE(),
7066 ++ * though if that's common we'd prefer not to lock it.
7067 + */
7068 +- if (page->mapping) {
7069 +- if (mlock)
7070 +- mlock_vma_page(page);
7071 +- else
7072 +- munlock_vma_page(page);
7073 +- }
7074 ++ if (page->mapping)
7075 ++ mlock_vma_page(page);
7076 + unlock_page(page);
7077 +- put_page(page); /* ref from get_user_pages() */
7078 +-
7079 +- /*
7080 +- * here we assume that get_user_pages() has given us
7081 +- * a list of virtually contiguous pages.
7082 +- */
7083 +- addr += PAGE_SIZE; /* for next get_user_pages() */
7084 +- nr_pages--;
7085 ++ put_page(page); /* ref from get_user_pages() */
7086 + }
7087 ++
7088 ++ addr += ret * PAGE_SIZE;
7089 ++ nr_pages -= ret;
7090 + ret = 0;
7091 + }
7092 +
7093 +- return ret; /* count entire vma as locked_vm */
7094 ++ return ret; /* 0 or negative error code */
7095 + }
7096 +
7097 + /*
7098 +@@ -289,7 +261,7 @@ long mlock_vma_pages_range(struct vm_area_struct *vma,
7099 + is_vm_hugetlb_page(vma) ||
7100 + vma == get_gate_vma(current))) {
7101 +
7102 +- __mlock_vma_pages_range(vma, start, end, 1);
7103 ++ __mlock_vma_pages_range(vma, start, end);
7104 +
7105 + /* Hide errors from mmap() and other callers */
7106 + return 0;
7107 +@@ -310,7 +282,6 @@ no_mlock:
7108 + return nr_pages; /* error or pages NOT mlocked */
7109 + }
7110 +
7111 +-
7112 + /*
7113 + * munlock_vma_pages_range() - munlock all pages in the vma range.'
7114 + * @vma - vma containing range to be munlock()ed.
7115 +@@ -330,10 +301,24 @@ no_mlock:
7116 + * free them. This will result in freeing mlocked pages.
7117 + */
7118 + void munlock_vma_pages_range(struct vm_area_struct *vma,
7119 +- unsigned long start, unsigned long end)
7120 ++ unsigned long start, unsigned long end)
7121 + {
7122 ++ unsigned long addr;
7123 ++
7124 ++ lru_add_drain();
7125 + vma->vm_flags &= ~VM_LOCKED;
7126 +- __mlock_vma_pages_range(vma, start, end, 0);
7127 ++
7128 ++ for (addr = start; addr < end; addr += PAGE_SIZE) {
7129 ++ struct page *page = follow_page(vma, addr, FOLL_GET);
7130 ++ if (page) {
7131 ++ lock_page(page);
7132 ++ if (page->mapping)
7133 ++ munlock_vma_page(page);
7134 ++ unlock_page(page);
7135 ++ put_page(page);
7136 ++ }
7137 ++ cond_resched();
7138 ++ }
7139 + }
7140 +
7141 + /*
7142 +@@ -400,18 +385,14 @@ success:
7143 + * It's okay if try_to_unmap_one unmaps a page just after we
7144 + * set VM_LOCKED, __mlock_vma_pages_range will bring it back.
7145 + */
7146 +- vma->vm_flags = newflags;
7147 +
7148 + if (lock) {
7149 +- ret = __mlock_vma_pages_range(vma, start, end, 1);
7150 +-
7151 +- if (ret > 0) {
7152 +- mm->locked_vm -= ret;
7153 +- ret = 0;
7154 +- } else
7155 +- ret = __mlock_posix_error_return(ret); /* translate if needed */
7156 ++ vma->vm_flags = newflags;
7157 ++ ret = __mlock_vma_pages_range(vma, start, end);
7158 ++ if (ret < 0)
7159 ++ ret = __mlock_posix_error_return(ret);
7160 + } else {
7161 +- __mlock_vma_pages_range(vma, start, end, 0);
7162 ++ munlock_vma_pages_range(vma, start, end);
7163 + }
7164 +
7165 + out:
7166 +diff --git a/mm/mmap.c b/mm/mmap.c
7167 +index 8101de4..cbb7cb3 100644
7168 +--- a/mm/mmap.c
7169 ++++ b/mm/mmap.c
7170 +@@ -570,9 +570,9 @@ again: remove_next = 1 + (end > next->vm_end);
7171 +
7172 + /*
7173 + * When changing only vma->vm_end, we don't really need
7174 +- * anon_vma lock: but is that case worth optimizing out?
7175 ++ * anon_vma lock.
7176 + */
7177 +- if (vma->anon_vma)
7178 ++ if (vma->anon_vma && (insert || importer || start != vma->vm_start))
7179 + anon_vma = vma->anon_vma;
7180 + if (anon_vma) {
7181 + spin_lock(&anon_vma->lock);
7182 +diff --git a/mm/nommu.c b/mm/nommu.c
7183 +index 66e81e7..82fedca 100644
7184 +--- a/mm/nommu.c
7185 ++++ b/mm/nommu.c
7186 +@@ -1056,7 +1056,7 @@ static int do_mmap_shared_file(struct vm_area_struct *vma)
7187 + ret = vma->vm_file->f_op->mmap(vma->vm_file, vma);
7188 + if (ret == 0) {
7189 + vma->vm_region->vm_top = vma->vm_region->vm_end;
7190 +- return ret;
7191 ++ return 0;
7192 + }
7193 + if (ret != -ENOSYS)
7194 + return ret;
7195 +@@ -1073,7 +1073,8 @@ static int do_mmap_shared_file(struct vm_area_struct *vma)
7196 + */
7197 + static int do_mmap_private(struct vm_area_struct *vma,
7198 + struct vm_region *region,
7199 +- unsigned long len)
7200 ++ unsigned long len,
7201 ++ unsigned long capabilities)
7202 + {
7203 + struct page *pages;
7204 + unsigned long total, point, n, rlen;
7205 +@@ -1084,13 +1085,13 @@ static int do_mmap_private(struct vm_area_struct *vma,
7206 + * shared mappings on devices or memory
7207 + * - VM_MAYSHARE will be set if it may attempt to share
7208 + */
7209 +- if (vma->vm_file) {
7210 ++ if (capabilities & BDI_CAP_MAP_DIRECT) {
7211 + ret = vma->vm_file->f_op->mmap(vma->vm_file, vma);
7212 + if (ret == 0) {
7213 + /* shouldn't return success if we're not sharing */
7214 + BUG_ON(!(vma->vm_flags & VM_MAYSHARE));
7215 + vma->vm_region->vm_top = vma->vm_region->vm_end;
7216 +- return ret;
7217 ++ return 0;
7218 + }
7219 + if (ret != -ENOSYS)
7220 + return ret;
7221 +@@ -1328,7 +1329,7 @@ unsigned long do_mmap_pgoff(struct file *file,
7222 + * - this is the hook for quasi-memory character devices to
7223 + * tell us the location of a shared mapping
7224 + */
7225 +- if (file && file->f_op->get_unmapped_area) {
7226 ++ if (capabilities & BDI_CAP_MAP_DIRECT) {
7227 + addr = file->f_op->get_unmapped_area(file, addr, len,
7228 + pgoff, flags);
7229 + if (IS_ERR((void *) addr)) {
7230 +@@ -1352,15 +1353,17 @@ unsigned long do_mmap_pgoff(struct file *file,
7231 + }
7232 +
7233 + vma->vm_region = region;
7234 +- add_nommu_region(region);
7235 +
7236 +- /* set up the mapping */
7237 ++ /* set up the mapping
7238 ++ * - the region is filled in if BDI_CAP_MAP_DIRECT is still set
7239 ++ */
7240 + if (file && vma->vm_flags & VM_SHARED)
7241 + ret = do_mmap_shared_file(vma);
7242 + else
7243 +- ret = do_mmap_private(vma, region, len);
7244 ++ ret = do_mmap_private(vma, region, len, capabilities);
7245 + if (ret < 0)
7246 +- goto error_put_region;
7247 ++ goto error_just_free;
7248 ++ add_nommu_region(region);
7249 +
7250 + /* okay... we have a mapping; now we have to register it */
7251 + result = vma->vm_start;
7252 +@@ -1378,19 +1381,6 @@ share:
7253 + kleave(" = %lx", result);
7254 + return result;
7255 +
7256 +-error_put_region:
7257 +- __put_nommu_region(region);
7258 +- if (vma) {
7259 +- if (vma->vm_file) {
7260 +- fput(vma->vm_file);
7261 +- if (vma->vm_flags & VM_EXECUTABLE)
7262 +- removed_exe_file_vma(vma->vm_mm);
7263 +- }
7264 +- kmem_cache_free(vm_area_cachep, vma);
7265 +- }
7266 +- kleave(" = %d [pr]", ret);
7267 +- return ret;
7268 +-
7269 + error_just_free:
7270 + up_write(&nommu_region_sem);
7271 + error:
7272 +diff --git a/mm/page_alloc.c b/mm/page_alloc.c
7273 +index a0de15f..0b3c6cb 100644
7274 +--- a/mm/page_alloc.c
7275 ++++ b/mm/page_alloc.c
7276 +@@ -2783,7 +2783,8 @@ static void setup_zone_migrate_reserve(struct zone *zone)
7277 + {
7278 + unsigned long start_pfn, pfn, end_pfn;
7279 + struct page *page;
7280 +- unsigned long reserve, block_migratetype;
7281 ++ unsigned long block_migratetype;
7282 ++ int reserve;
7283 +
7284 + /* Get the start pfn, end pfn and the number of blocks to reserve */
7285 + start_pfn = zone->zone_start_pfn;
7286 +@@ -2791,6 +2792,15 @@ static void setup_zone_migrate_reserve(struct zone *zone)
7287 + reserve = roundup(min_wmark_pages(zone), pageblock_nr_pages) >>
7288 + pageblock_order;
7289 +
7290 ++ /*
7291 ++ * Reserve blocks are generally in place to help high-order atomic
7292 ++ * allocations that are short-lived. A min_free_kbytes value that
7293 ++ * would result in more than 2 reserve blocks for atomic allocations
7294 ++ * is assumed to be in place to help anti-fragmentation for the
7295 ++ * future allocation of hugepages at runtime.
7296 ++ */
7297 ++ reserve = min(2, reserve);
7298 ++
7299 + for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {
7300 + if (!pfn_valid(pfn))
7301 + continue;
7302 +diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
7303 +index da0f64f..f03529c 100644
7304 +--- a/net/ax25/af_ax25.c
7305 ++++ b/net/ax25/af_ax25.c
7306 +@@ -538,7 +538,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
7307 + if (level != SOL_AX25)
7308 + return -ENOPROTOOPT;
7309 +
7310 +- if (optlen < sizeof(int))
7311 ++ if (optlen < (int)sizeof(int))
7312 + return -EINVAL;
7313 +
7314 + if (get_user(opt, (int __user *)optval))
7315 +diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
7316 +index d22f611..991fe40 100644
7317 +--- a/net/bridge/br_netfilter.c
7318 ++++ b/net/bridge/br_netfilter.c
7319 +@@ -359,7 +359,7 @@ static int br_nf_pre_routing_finish(struct sk_buff *skb)
7320 + },
7321 + .proto = 0,
7322 + };
7323 +- struct in_device *in_dev = in_dev_get(dev);
7324 ++ struct in_device *in_dev = __in_dev_get_rcu(dev);
7325 +
7326 + /* If err equals -EHOSTUNREACH the error is due to a
7327 + * martian destination or due to the fact that
7328 +diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
7329 +index 133eeae..ce50688 100644
7330 +--- a/net/bridge/netfilter/ebt_ulog.c
7331 ++++ b/net/bridge/netfilter/ebt_ulog.c
7332 +@@ -266,7 +266,7 @@ static bool ebt_ulog_tg_check(const struct xt_tgchk_param *par)
7333 + if (uloginfo->qthreshold > EBT_ULOG_MAX_QLEN)
7334 + uloginfo->qthreshold = EBT_ULOG_MAX_QLEN;
7335 +
7336 +- return 0;
7337 ++ return true;
7338 + }
7339 +
7340 + static struct xt_target ebt_ulog_tg_reg __read_mostly = {
7341 +diff --git a/net/can/af_can.c b/net/can/af_can.c
7342 +index e733725..264c968 100644
7343 +--- a/net/can/af_can.c
7344 ++++ b/net/can/af_can.c
7345 +@@ -199,6 +199,8 @@ static int can_create(struct net *net, struct socket *sock, int protocol)
7346 + * @skb: pointer to socket buffer with CAN frame in data section
7347 + * @loop: loopback for listeners on local CAN sockets (recommended default!)
7348 + *
7349 ++ * Due to the loopback this routine must not be called from hardirq context.
7350 ++ *
7351 + * Return:
7352 + * 0 on success
7353 + * -ENETDOWN when the selected interface is down
7354 +@@ -278,7 +280,7 @@ int can_send(struct sk_buff *skb, int loop)
7355 + }
7356 +
7357 + if (newskb)
7358 +- netif_rx(newskb);
7359 ++ netif_rx_ni(newskb);
7360 +
7361 + /* update statistics */
7362 + can_stats.tx_frames++;
7363 +diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
7364 +index 3229e0a..b6ddd56 100644
7365 +--- a/net/ipv4/netfilter/nf_nat_core.c
7366 ++++ b/net/ipv4/netfilter/nf_nat_core.c
7367 +@@ -212,7 +212,7 @@ find_best_ips_proto(struct nf_conntrack_tuple *tuple,
7368 + maxip = ntohl(range->max_ip);
7369 + j = jhash_2words((__force u32)tuple->src.u3.ip,
7370 + range->flags & IP_NAT_RANGE_PERSISTENT ?
7371 +- (__force u32)tuple->dst.u3.ip : 0, 0);
7372 ++ 0 : (__force u32)tuple->dst.u3.ip, 0);
7373 + j = ((u64)j * (maxip - minip + 1)) >> 32;
7374 + *var_ipp = htonl(minip + j);
7375 + }
7376 +diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
7377 +index b5869b9..b8614c6 100644
7378 +--- a/net/netfilter/nf_conntrack_core.c
7379 ++++ b/net/netfilter/nf_conntrack_core.c
7380 +@@ -1089,14 +1089,14 @@ void nf_conntrack_flush_report(struct net *net, u32 pid, int report)
7381 + }
7382 + EXPORT_SYMBOL_GPL(nf_conntrack_flush_report);
7383 +
7384 +-static void nf_ct_release_dying_list(void)
7385 ++static void nf_ct_release_dying_list(struct net *net)
7386 + {
7387 + struct nf_conntrack_tuple_hash *h;
7388 + struct nf_conn *ct;
7389 + struct hlist_nulls_node *n;
7390 +
7391 + spin_lock_bh(&nf_conntrack_lock);
7392 +- hlist_nulls_for_each_entry(h, n, &init_net.ct.dying, hnnode) {
7393 ++ hlist_nulls_for_each_entry(h, n, &net->ct.dying, hnnode) {
7394 + ct = nf_ct_tuplehash_to_ctrack(h);
7395 + /* never fails to remove them, no listeners at this point */
7396 + nf_ct_kill(ct);
7397 +@@ -1115,7 +1115,7 @@ static void nf_conntrack_cleanup_net(struct net *net)
7398 + {
7399 + i_see_dead_people:
7400 + nf_ct_iterate_cleanup(net, kill_all, NULL);
7401 +- nf_ct_release_dying_list();
7402 ++ nf_ct_release_dying_list(net);
7403 + if (atomic_read(&net->ct.count) != 0) {
7404 + schedule();
7405 + goto i_see_dead_people;
7406 +diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
7407 +index ebe5718..f9f7177 100644
7408 +--- a/net/packet/af_packet.c
7409 ++++ b/net/packet/af_packet.c
7410 +@@ -1836,7 +1836,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
7411 + static int packet_getsockopt(struct socket *sock, int level, int optname,
7412 + char __user *optval, int __user *optlen)
7413 + {
7414 +- int len;
7415 ++ unsigned int len;
7416 + int val;
7417 + struct sock *sk = sock->sk;
7418 + struct packet_sock *po = pkt_sk(sk);
7419 +@@ -1849,7 +1849,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
7420 + if (get_user(len, optlen))
7421 + return -EFAULT;
7422 +
7423 +- if (len < 0)
7424 ++ if ((int)len < 0)
7425 + return -EINVAL;
7426 +
7427 + switch (optname) {
7428 +diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
7429 +index c29be8f..43300b3 100644
7430 +--- a/scripts/Kbuild.include
7431 ++++ b/scripts/Kbuild.include
7432 +@@ -105,12 +105,12 @@ as-instr = $(call try-run,\
7433 + # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
7434 +
7435 + cc-option = $(call try-run,\
7436 +- $(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
7437 ++ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
7438 +
7439 + # cc-option-yn
7440 + # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
7441 + cc-option-yn = $(call try-run,\
7442 +- $(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n)
7443 ++ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n)
7444 +
7445 + # cc-option-align
7446 + # Prefix align with either -falign or -malign
7447 +diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
7448 +index 64343cc..86c3896 100644
7449 +--- a/scripts/kallsyms.c
7450 ++++ b/scripts/kallsyms.c
7451 +@@ -585,7 +585,7 @@ static int prefix_underscores_count(const char *str)
7452 + {
7453 + const char *tail = str;
7454 +
7455 +- while (*tail != '_')
7456 ++ while (*tail == '_')
7457 + tail++;
7458 +
7459 + return tail - str;
7460 +diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
7461 +index 5e17de9..5010952 100644
7462 +--- a/tools/perf/builtin-annotate.c
7463 ++++ b/tools/perf/builtin-annotate.c
7464 +@@ -1335,8 +1335,8 @@ static int __cmd_annotate(void)
7465 + exit(-1);
7466 + }
7467 +
7468 +- if (!force && (stat.st_uid != geteuid())) {
7469 +- fprintf(stderr, "file: %s not owned by current user\n", input_name);
7470 ++ if (!force && stat.st_uid && (stat.st_uid != geteuid())) {
7471 ++ fprintf(stderr, "file: %s not owned by current user or root\n", input_name);
7472 + exit(-1);
7473 + }
7474 +
7475 +diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
7476 +index 8b2ec88..b8a75f6 100644
7477 +--- a/tools/perf/builtin-report.c
7478 ++++ b/tools/perf/builtin-report.c
7479 +@@ -1857,8 +1857,8 @@ static int __cmd_report(void)
7480 + exit(-1);
7481 + }
7482 +
7483 +- if (!force && (stat.st_uid != geteuid())) {
7484 +- fprintf(stderr, "file: %s not owned by current user\n", input_name);
7485 ++ if (!force && stat.st_uid && (stat.st_uid != geteuid())) {
7486 ++ fprintf(stderr, "file: %s not owned by current user or root\n", input_name);
7487 + exit(-1);
7488 + }
7489 +
7490 +diff --git a/tools/perf/util/module.c b/tools/perf/util/module.c
7491 +index ddabe92..702083d 100644
7492 +--- a/tools/perf/util/module.c
7493 ++++ b/tools/perf/util/module.c
7494 +@@ -422,7 +422,7 @@ static int mod_dso__load_module_paths(struct mod_dso *self)
7495 + len += strlen(uts.release);
7496 + len += strlen("/modules.dep");
7497 +
7498 +- path = calloc(1, len);
7499 ++ path = calloc(1, len + 1);
7500 + if (path == NULL)
7501 + goto out_failure;
7502 +
7503
7504 Deleted: genpatches-2.6/trunk/2.6.31/2300_cdc-acm-set-open-flag.patch
7505 ===================================================================
7506 --- genpatches-2.6/trunk/2.6.31/2300_cdc-acm-set-open-flag.patch 2009-09-28 15:44:45 UTC (rev 1615)
7507 +++ genpatches-2.6/trunk/2.6.31/2300_cdc-acm-set-open-flag.patch 2009-10-05 21:46:35 UTC (rev 1616)
7508 @@ -1,39 +0,0 @@
7509 -From: Oliver Neukum <oliver@××××××.org>
7510 -Date: Tue, 8 Sep 2009 21:51:28 +0000 (+0200)
7511 -Subject: USB: fix cdc-acm regression in open
7512 -X-Git-Tag: v2.6.32-rc1~174^2~135
7513 -X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=7af25b4b34a2439020d78da765a3bed0ff73f25c
7514 -
7515 -USB: fix cdc-acm regression in open
7516 -
7517 -cdc-acm needs to set a flag during open to tell the
7518 -tty layer that the device is initialized
7519 -
7520 -Signed-off-by: Oliver Neukum <oliver@××××××.org>
7521 -Cc: Marcel Holtmann <marcel@××××××××.org>
7522 -Cc: Paul Martin <pm@××××××.org>
7523 -Cc: stable <stable@××××××.org>
7524 -Signed-off-by: Greg Kroah-Hartman <gregkh@××××.de>
7525 ----
7526 -
7527 -diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
7528 -index 85a1a55..e3861b2 100644
7529 ---- a/drivers/usb/class/cdc-acm.c
7530 -+++ b/drivers/usb/class/cdc-acm.c
7531 -@@ -59,6 +59,7 @@
7532 - #include <linux/init.h>
7533 - #include <linux/slab.h>
7534 - #include <linux/tty.h>
7535 -+#include <linux/serial.h>
7536 - #include <linux/tty_driver.h>
7537 - #include <linux/tty_flip.h>
7538 - #include <linux/module.h>
7539 -@@ -609,6 +610,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
7540 - acm->throttle = 0;
7541 -
7542 - tasklet_schedule(&acm->urb_task);
7543 -+ set_bit(ASYNCB_INITIALIZED, &acm->port.flags);
7544 - rv = tty_port_block_til_ready(&acm->port, tty, filp);
7545 - done:
7546 - mutex_unlock(&acm->mutex);
7547 -
7548
7549 Deleted: genpatches-2.6/trunk/2.6.31/2900_cc1-option-fPIC-check.patch
7550 ===================================================================
7551 --- genpatches-2.6/trunk/2.6.31/2900_cc1-option-fPIC-check.patch 2009-09-28 15:44:45 UTC (rev 1615)
7552 +++ genpatches-2.6/trunk/2.6.31/2900_cc1-option-fPIC-check.patch 2009-10-05 21:46:35 UTC (rev 1616)
7553 @@ -1,45 +0,0 @@
7554 -From: Jory A. Pratt <anarchy@g.o>
7555 -Date: Fri, 18 Sep 2009 19:49:31 +0000 (-0700)
7556 -Subject: kbuild: fix cc1 options check to ensure we do not use -fPIC when compiling
7557 -X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=c47efe5548abbf53c2f66e06dcb46183b11d6b22
7558 -
7559 -kbuild: fix cc1 options check to ensure we do not use -fPIC when compiling
7560 -
7561 -The arch/*/boot/Makefile use cc-options to check for GCC command options
7562 -and cc-options use the hardened specs when checking for GCC command
7563 -options. When -fPIE is pass to cc1 it can't use -ffreestanding or
7564 --fno-toplevel-reorder. Then it fail to build stuff with -ffreestanding
7565 -and -fno-toplevel-reorder.
7566 -
7567 -Thanks to Fredric Johansson for finding the main problem behind a failed
7568 -build using a hardened toolchain.
7569 -
7570 -Signed-off-by: Magnus Granberg <zorry@×××.nu>
7571 -Signed-off-by: Jory A. Pratt <anarchy@g.o>
7572 -Cc: Fredric Johansson <johansson_fredric@×××××××.com>
7573 -Cc: "H. Peter Anvin" <hpa@×××××.com>
7574 -Signed-off-by: Andrew Morton <akpm@××××××××××××××××.org>
7575 -Cc: <stable@××××××.org>
7576 -Signed-off-by: Sam Ravnborg <sam@××××××××.org>
7577 ----
7578 -
7579 -diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
7580 -index b345260..4f9c190 100644
7581 ---- a/scripts/Kbuild.include
7582 -+++ b/scripts/Kbuild.include
7583 -@@ -106,12 +106,12 @@ as-instr = $(call try-run,\
7584 - # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
7585 -
7586 - cc-option = $(call try-run,\
7587 -- $(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
7588 -+ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
7589 -
7590 - # cc-option-yn
7591 - # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
7592 - cc-option-yn = $(call try-run,\
7593 -- $(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n)
7594 -+ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n)
7595 -
7596 - # cc-option-align
7597 - # Prefix align with either -falign or -malign
7598 -
7599
7600 Modified: genpatches-2.6/trunk/2.6.31/4202_fbcondecor-0.9.6.patch
7601 ===================================================================
7602 --- genpatches-2.6/trunk/2.6.31/4202_fbcondecor-0.9.6.patch 2009-09-28 15:44:45 UTC (rev 1615)
7603 +++ genpatches-2.6/trunk/2.6.31/4202_fbcondecor-0.9.6.patch 2009-10-05 21:46:35 UTC (rev 1616)
7604 @@ -866,7 +866,7 @@
7605
7606 if (!num_registered_fb)
7607 return -ENODEV;
7608 -@@ -539,11 +542,17 @@ static int fbcon_takeover(int show_logo)
7609 +@@ -542,11 +545,17 @@ static int fbcon_takeover(int show_logo)
7610 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
7611 fbcon_is_default);