Merge branch 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6 into for-linus
diff --git a/MAINTAINERS b/MAINTAINERS
index 8fa3005..303ef7d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -723,42 +723,52 @@
 S:	Maintained
 
 BLACKFIN ARCHITECTURE
-P:     Aubrey Li
-M:     aubrey.li@analog.com
-P:     Bernd Schmidt
-M:     bernd.schmidt@analog.com
-P:     Bryan Wu
-M:     bryan.wu@analog.com
-P:     Grace Pan
-M:     grace.pan@analog.com
-P:     Michael Hennerich
-M:     michael.hennerich@analog.com
-P:     Mike Frysinger
-M:     michael.frysinger@analog.com
-P:     Jane Lv
-M:     jane.lv@analog.com
-P:     Jerry Zeng
-M:     jerry.zeng@analog.com
-P:     Jie Zhang
-M:     jie.zhang@analog.com
-P:     Robin Getz
-M:     robin.getz@analog.com
-P:     Roy Huang
-M:     roy.huang@analog.com
-P:     Sonic Zhang
-M:     sonic.zhang@analog.com
-P:     Yi Li
-M:     yi.li@analog.com
-L:     uclinux-dist-devel@blackfin.uclinux.org
-W:     http://blackfin.uclinux.org
-S:     Supported
+P:	Aubrey Li
+M:	aubrey.li@analog.com
+P:	Bernd Schmidt
+M:	bernd.schmidt@analog.com
+P:	Bryan Wu
+M:	bryan.wu@analog.com
+P:	Grace Pan
+M:	grace.pan@analog.com
+P:	Marc Hoffman
+M:	marc.hoffman@analog.com
+P:	Michael Hennerich
+M:	michael.hennerich@analog.com
+P:	Mike Frysinger
+M:	michael.frysinger@analog.com
+P:	Jerry Zeng
+M:	jerry.zeng@analog.com
+P:	Jie Zhang
+M:	jie.zhang@analog.com
+P:	Robin Getz
+M:	robin.getz@analog.com
+P:	Roy Huang
+M:	roy.huang@analog.com
+P:	Sonic Zhang
+M:	sonic.zhang@analog.com
+P:	Vivi Li
+M:	vivi.li@analog.com
+P:	Yi Li
+M:	yi.li@analog.com
+L:	uclinux-dist-devel@blackfin.uclinux.org (subscribers-only)
+W:	http://blackfin.uclinux.org
+S:	Supported
+
+BLACKFIN RTC DRIVER
+P:	Mike Frysinger
+M:	michael.frysinger@analog.com
+M:	vapier.adi@gmail.com
+L:	uclinux-dist-devel@blackfin.uclinux.org (subscribers-only)
+W:	http://blackfin.uclinux.org
+S:	Supported
 
 BLACKFIN SERIAL DRIVER
-P:     Aubrey Li
-M:     aubrey.li@analog.com
-L:     uclinux-dist-devel@blackfin.uclinux.org
-W:     http://blackfin.uclinux.org
-S:     Supported
+P:	Aubrey Li
+M:	aubrey.li@analog.com
+L:	uclinux-dist-devel@blackfin.uclinux.org (subscribers-only)
+W:	http://blackfin.uclinux.org
+S:	Supported
 
 BAYCOM/HDLCDRV DRIVERS FOR AX.25
 P:	Thomas Sailer
diff --git a/Makefile b/Makefile
index 30d685b..b76ee94 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 22
-EXTRAVERSION = -rc4
-NAME = Jeff Thinks I Should Change This, But To What?
+EXTRAVERSION = -rc5
+NAME = Holy Dancing Manatees, Batman!
 
 # *DOCUMENTATION*
 # To see a list of typical targets execute "make help"
diff --git a/arch/arm/mach-s3c2440/mach-anubis.c b/arch/arm/mach-s3c2440/mach-anubis.c
index b5d387e..bff7ddd 100644
--- a/arch/arm/mach-s3c2440/mach-anubis.c
+++ b/arch/arm/mach-s3c2440/mach-anubis.c
@@ -76,8 +76,8 @@
 	.length		= SZ_4K,
 	.type		= MT_DEVICE,
   }, {
-	.virtual	= (u32)ANUBIS_VA_CTRL2,
-	.pfn		= __phys_to_pfn(ANUBIS_PA_CTRL2),
+	.virtual	= (u32)ANUBIS_VA_IDREG,
+	.pfn		= __phys_to_pfn(ANUBIS_PA_IDREG),
 	.length		= SZ_4K,
 	.type		= MT_DEVICE,
   },
diff --git a/arch/arm/mach-s3c2440/mach-osiris.c b/arch/arm/mach-s3c2440/mach-osiris.c
index 4d6c7a5..1581160 100644
--- a/arch/arm/mach-s3c2440/mach-osiris.c
+++ b/arch/arm/mach-s3c2440/mach-osiris.c
@@ -16,6 +16,7 @@
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/sysdev.h>
 #include <linux/serial_core.h>
 
 #include <asm/mach/arch.h>
@@ -65,6 +66,11 @@
   /* CPLD control registers */
 
   {
+	  .virtual	= (u32)OSIRIS_VA_CTRL0,
+	  .pfn		= __phys_to_pfn(OSIRIS_PA_CTRL0),
+	  .length	= SZ_16K,
+	  .type		= MT_DEVICE,
+  }, {
 	  .virtual	= (u32)OSIRIS_VA_CTRL1,
 	  .pfn		= __phys_to_pfn(OSIRIS_PA_CTRL1),
 	  .length	= SZ_16K,
@@ -74,6 +80,11 @@
 	  .pfn		= __phys_to_pfn(OSIRIS_PA_CTRL2),
 	  .length	= SZ_16K,
 	  .type		= MT_DEVICE,
+  }, {
+	  .virtual	= (u32)OSIRIS_VA_IDREG,
+	  .pfn		= __phys_to_pfn(OSIRIS_PA_IDREG),
+	  .length	= SZ_16K,
+	  .type		= MT_DEVICE,
   },
 };
 
@@ -195,13 +206,13 @@
 	pr_debug("osiris_nand: selecting slot %d (set %p,%p)\n",
 		 slot, set, set->nr_map);
 
-	tmp = __raw_readb(OSIRIS_VA_CTRL1);
-	tmp &= ~OSIRIS_CTRL1_NANDSEL;
+	tmp = __raw_readb(OSIRIS_VA_CTRL0);
+	tmp &= ~OSIRIS_CTRL0_NANDSEL;
 	tmp |= slot;
 
-	pr_debug("osiris_nand: ctrl1 now %02x\n", tmp);
+	pr_debug("osiris_nand: ctrl0 now %02x\n", tmp);
 
-	__raw_writeb(tmp, OSIRIS_VA_CTRL1);
+	__raw_writeb(tmp, OSIRIS_VA_CTRL0);
 }
 
 static struct s3c2410_platform_nand osiris_nand_info = {
@@ -235,10 +246,45 @@
 	.resource	= osiris_pcmcia_resource,
 };
 
+/* Osiris power management device */
+
+#ifdef CONFIG_PM
+static unsigned char pm_osiris_ctrl0;
+
+static int osiris_pm_suspend(struct sys_device *sd, pm_message_t state)
+{
+	pm_osiris_ctrl0 = __raw_readb(OSIRIS_VA_CTRL0);
+	return 0;
+}
+
+static int osiris_pm_resume(struct sys_device *sd)
+{
+	if (pm_osiris_ctrl0 & OSIRIS_CTRL0_FIX8)
+		__raw_writeb(OSIRIS_CTRL1_FIX8, OSIRIS_VA_CTRL1);
+
+	return 0;
+}
+
+#else
+#define osiris_pm_suspend NULL
+#define osiris_pm_resume NULL
+#endif
+
+static struct sysdev_class osiris_pm_sysclass = {
+	set_kset_name("mach-osiris"),
+	.suspend	= osiris_pm_suspend,
+	.resume		= osiris_pm_resume,
+};
+
+static struct sys_device osiris_pm_sysdev = {
+	.cls		= &osiris_pm_sysclass,
+};
+
 /* Standard Osiris devices */
 
 static struct platform_device *osiris_devices[] __initdata = {
 	&s3c_device_i2c,
+	&s3c_device_wdt,
 	&s3c_device_nand,
 	&osiris_pcmcia,
 };
@@ -288,6 +334,9 @@
 
 static void __init osiris_init(void)
 {
+	sysdev_class_register(&osiris_pm_sysclass);
+	sysdev_register(&osiris_pm_sysdev);
+
 	platform_add_devices(osiris_devices, ARRAY_SIZE(osiris_devices));
 };
 
@@ -299,5 +348,6 @@
 	.map_io		= osiris_map_io,
 	.init_machine	= osiris_init,
 	.init_irq	= s3c24xx_init_irq,
+	.init_machine	= osiris_init,
 	.timer		= &s3c24xx_timer,
 MACHINE_END
diff --git a/arch/arm/vfp/entry.S b/arch/arm/vfp/entry.S
index ca2a5ad..806ce26 100644
--- a/arch/arm/vfp/entry.S
+++ b/arch/arm/vfp/entry.S
@@ -29,6 +29,10 @@
 	add	r10, r10, #TI_VFPSTATE	@ r10 = workspace
 	ldr	pc, [r4]		@ call VFP entry point
 
+ENTRY(vfp_null_entry)
+	mov	pc, lr
+ENDPROC(vfp_null_entry)
+
 .LCvfp:
 	.word	vfp_vector
 
diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
index f1e5951..1106b5f 100644
--- a/arch/arm/vfp/vfpmodule.c
+++ b/arch/arm/vfp/vfpmodule.c
@@ -26,8 +26,9 @@
  */
 void vfp_testing_entry(void);
 void vfp_support_entry(void);
+void vfp_null_entry(void);
 
-void (*vfp_vector)(void) = vfp_testing_entry;
+void (*vfp_vector)(void) = vfp_null_entry;
 union vfp_state *last_VFP_context[NR_CPUS];
 
 /*
@@ -321,8 +322,10 @@
 	 * The handler is already setup to just log calls, so
 	 * we just need to read the VFPSID register.
 	 */
+	vfp_vector = vfp_testing_entry;
 	vfpsid = fmrx(FPSID);
 	barrier();
+	vfp_vector = vfp_null_entry;
 
 	printk(KERN_INFO "VFP support v0.3: ");
 	if (VFP_arch) {
diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
index fe1dbe2..e253e86 100644
--- a/arch/avr32/boards/atstk1000/atstk1002.c
+++ b/arch/avr32/boards/atstk1000/atstk1002.c
@@ -42,6 +42,7 @@
 		.modalias	= "ltv350qv",
 		.max_speed_hz	= 16000000,
 		.chip_select	= 1,
+		.mode		= SPI_MODE_3,
 	},
 };
 
diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
index e011f1c..4b24952 100644
--- a/arch/avr32/mm/fault.c
+++ b/arch/avr32/mm/fault.c
@@ -158,7 +158,7 @@
 	up_read(&mm->mmap_sem);
 
 	if (user_mode(regs)) {
-		if (exception_trace)
+		if (exception_trace && printk_ratelimit())
 			printk("%s%s[%d]: segfault at %08lx pc %08lx "
 			       "sp %08lx ecr %lu\n",
 			       is_init(tsk) ? KERN_EMERG : KERN_INFO,
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index b1b111b..1fad856 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -394,41 +394,6 @@
 	default 0x08 if (BFIN533_STAMP && BFIN_IDLE_LED_NUM = 2)
 	default 0x10 if (BFIN533_STAMP && BFIN_IDLE_LED_NUM = 3)
 
-comment "Console UART Setup"
-
-choice
-	prompt "Baud Rate"
-	default BAUD_57600
-config BAUD_9600
-	bool "9600"
-config BAUD_19200
-	bool "19200"
-config BAUD_38400
-	bool "38400"
-config BAUD_57600
-	bool "57600"
-config BAUD_115200
-	bool "115200"
-endchoice
-
-choice
-	prompt "Parity"
-	default BAUD_NO_PARITY
-config  BAUD_NO_PARITY
-	bool "No Parity"
-config  BAUD_PARITY
-	bool "Parity"
-endchoice
-
-choice
-	prompt "Stop Bits"
-	default BAUD_1_STOPBIT
-config  BAUD_1_STOPBIT
-	bool "1"
-config  BAUD_2_STOPBIT
-	bool "2"
-endchoice
-
 endmenu
 
 
diff --git a/arch/blackfin/configs/BF533-EZKIT_defconfig b/arch/blackfin/configs/BF533-EZKIT_defconfig
index 377c8e0..90d58aa 100644
--- a/arch/blackfin/configs/BF533-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF533-EZKIT_defconfig
@@ -1,20 +1,21 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.19.3
+# Linux kernel version: 2.6.21.3
 #
 # CONFIG_MMU is not set
 # CONFIG_FPU is not set
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
 # CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
 CONFIG_BLACKFIN=y
+CONFIG_ZONE_DMA=y
 CONFIG_BFIN=y
 CONFIG_SEMAPHORE_SLEEPERS=y
 CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
+# CONFIG_GENERIC_TIME is not set
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_UCLINUX=y
 CONFIG_FORCE_MAX_ZONEORDER=14
 CONFIG_IRQCHIP_DEMUX_GPIO=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
@@ -33,13 +34,16 @@
 CONFIG_LOCALVERSION_AUTO=y
 CONFIG_SYSVIPC=y
 # CONFIG_IPC_NS is not set
+CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 # CONFIG_TASKSTATS is not set
 # CONFIG_UTS_NS is not set
 # CONFIG_AUDIT is not set
 # CONFIG_IKCONFIG is not set
+CONFIG_SYSFS_DEPRECATED=y
 # CONFIG_RELAY is not set
+CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
@@ -54,9 +58,7 @@
 CONFIG_ELF_CORE=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
-CONFIG_EPOLL=y
 CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
-# CONFIG_LIMIT_PAGECACHE is not set
 CONFIG_BUDDY=y
 # CONFIG_NP2 is not set
 CONFIG_SLAB=y
@@ -80,7 +82,9 @@
 # Block layer
 #
 CONFIG_BLOCK=y
+# CONFIG_LBD is not set
 # CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
 
 #
 # IO Schedulers
@@ -109,7 +113,6 @@
 # CONFIG_BF532 is not set
 CONFIG_BF533=y
 # CONFIG_BF534 is not set
-# CONFIG_BF535 is not set
 # CONFIG_BF536 is not set
 # CONFIG_BF537 is not set
 # CONFIG_BF561 is not set
@@ -125,6 +128,7 @@
 # CONFIG_BFIN537_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_EZKIT is not set
+# CONFIG_BFIN561_TEPLA is not set
 # CONFIG_PNAV10 is not set
 # CONFIG_GENERIC_BOARD is not set
 CONFIG_MEM_MT48LC16M16A2TG_75=y
@@ -168,6 +172,7 @@
 #
 # Board customizations
 #
+# CONFIG_CMDLINE_BOOL is not set
 
 #
 # Board Setup
@@ -178,19 +183,6 @@
 CONFIG_BOOT_LOAD=0x1000
 
 #
-# Console UART Setup
-#
-# CONFIG_BAUD_9600 is not set
-# CONFIG_BAUD_19200 is not set
-# CONFIG_BAUD_38400 is not set
-CONFIG_BAUD_57600=y
-# CONFIG_BAUD_115200 is not set
-CONFIG_BAUD_NO_PARITY=y
-# CONFIG_BAUD_PARITY is not set
-CONFIG_BAUD_1_STOPBIT=y
-# CONFIG_BAUD_2_STOPBIT is not set
-
-#
 # Blackfin Kernel Optimizations
 #
 
@@ -199,6 +191,7 @@
 #
 # CONFIG_HZ_100 is not set
 CONFIG_HZ_250=y
+# CONFIG_HZ_300 is not set
 # CONFIG_HZ_1000 is not set
 CONFIG_HZ=250
 
@@ -217,6 +210,7 @@
 CONFIG_MEMCPY_L1=y
 CONFIG_SYS_BFIN_SPINLOCK_L1=y
 # CONFIG_IP_CHECKSUM_L1 is not set
+CONFIG_CACHELINE_ALIGNED_L1=y
 # CONFIG_SYSCALL_TAB_L1 is not set
 # CONFIG_CPLB_SWITCH_TAB_L1 is not set
 CONFIG_RAMKERNEL=y
@@ -230,6 +224,7 @@
 # CONFIG_SPARSEMEM_STATIC is not set
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
 CONFIG_LARGE_ALLOCS=y
 CONFIG_BFIN_DMA_5XX=y
 # CONFIG_DMA_UNCACHED_2M is not set
@@ -302,7 +297,7 @@
 # Power management options
 #
 CONFIG_PM=y
-CONFIG_PM_LEGACY=y
+# CONFIG_PM_LEGACY is not set
 # CONFIG_PM_DEBUG is not set
 # CONFIG_PM_SYSFS_DEPRECATED is not set
 CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR=y
@@ -330,6 +325,7 @@
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
 # CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 # CONFIG_IP_MULTICAST is not set
@@ -356,6 +352,7 @@
 # CONFIG_TCP_CONG_ADVANCED is not set
 CONFIG_TCP_CONG_CUBIC=y
 CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
 # CONFIG_IPV6 is not set
 # CONFIG_INET6_XFRM_TUNNEL is not set
 # CONFIG_INET6_TUNNEL is not set
@@ -399,7 +396,48 @@
 #
 # CONFIG_NET_PKTGEN is not set
 # CONFIG_HAMRADIO is not set
-# CONFIG_IRDA is not set
+CONFIG_IRDA=m
+
+#
+# IrDA protocols
+#
+CONFIG_IRLAN=m
+CONFIG_IRCOMM=m
+# CONFIG_IRDA_ULTRA is not set
+
+#
+# IrDA options
+#
+CONFIG_IRDA_CACHE_LAST_LSAP=y
+# CONFIG_IRDA_FAST_RR is not set
+# CONFIG_IRDA_DEBUG is not set
+
+#
+# Infrared-port device drivers
+#
+
+#
+# SIR device drivers
+#
+CONFIG_IRTTY_SIR=m
+
+#
+# Dongle support
+#
+# CONFIG_DONGLE is not set
+
+#
+# Old SIR device drivers
+#
+# CONFIG_IRPORT_SIR is not set
+
+#
+# Old Serial dongle support
+#
+
+#
+# FIR device drivers
+#
 # CONFIG_BT is not set
 # CONFIG_IEEE80211 is not set
 
@@ -434,6 +472,7 @@
 # User Modules And Translation Layers
 #
 CONFIG_MTD_CHAR=m
+CONFIG_MTD_BLKDEVS=y
 CONFIG_MTD_BLOCK=y
 # CONFIG_FTL is not set
 # CONFIG_NFTL is not set
@@ -489,6 +528,8 @@
 #
 # Self-contained MTD device drivers
 #
+# CONFIG_MTD_DATAFLASH is not set
+# CONFIG_MTD_M25P80 is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_PHRAM is not set
 # CONFIG_MTD_MTDRAM is not set
@@ -519,6 +560,7 @@
 #
 # Plug and Play support
 #
+# CONFIG_PNPACPI is not set
 
 #
 # Block devices
@@ -530,14 +572,12 @@
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=4096
 CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_BLK_DEV_INITRD is not set
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 
 #
 # Misc devices
 #
-# CONFIG_TIFM_CORE is not set
 
 #
 # ATA/ATAPI/MFM/RLL support
@@ -636,7 +676,26 @@
 #
 # Input device support
 #
-# CONFIG_INPUT is not set
+CONFIG_INPUT=m
+# CONFIG_INPUT_FF_MEMLESS is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_TSDEV is not set
+CONFIG_INPUT_EVDEV=m
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
 
 #
 # Hardware I/O ports
@@ -649,12 +708,14 @@
 #
 # CONFIG_AD9960 is not set
 # CONFIG_SPI_ADC_BF533 is not set
-# CONFIG_BF533_PFLAGS is not set
+# CONFIG_BF5xx_PFLAGS is not set
 # CONFIG_BF5xx_PPIFCD is not set
 # CONFIG_BF5xx_TIMERS is not set
 # CONFIG_BF5xx_PPI is not set
-# CONFIG_BFIN_SPORT is not set
+CONFIG_BFIN_SPORT=y
 # CONFIG_BFIN_TIMER_LATENCY is not set
+# CONFIG_AD5304 is not set
+# CONFIG_BF5xx_FBDMA is not set
 # CONFIG_VT is not set
 # CONFIG_SERIAL_NONSTANDARD is not set
 
@@ -691,16 +752,19 @@
 #
 # Watchdog Cards
 #
-# CONFIG_WATCHDOG is not set
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+CONFIG_BFIN_WDT=y
 CONFIG_HW_RANDOM=y
 # CONFIG_GEN_RTC is not set
 CONFIG_BLACKFIN_DPMC=y
 # CONFIG_DTLK is not set
 # CONFIG_R3964 is not set
-
-#
-# Ftape, the floppy tape device driver
-#
 # CONFIG_RAW_DRIVER is not set
 
 #
@@ -716,8 +780,19 @@
 #
 # SPI support
 #
-# CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
+CONFIG_SPI=y
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_BFIN=y
+# CONFIG_SPI_BITBANG is not set
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
 
 #
 # Dallas's 1-wire bus
@@ -731,10 +806,17 @@
 # CONFIG_HWMON_VID is not set
 # CONFIG_SENSORS_ABITUGURU is not set
 # CONFIG_SENSORS_F71805F is not set
+# CONFIG_SENSORS_LM70 is not set
+# CONFIG_SENSORS_PC87427 is not set
 # CONFIG_SENSORS_VT1211 is not set
 # CONFIG_HWMON_DEBUG_CHIP is not set
 
 #
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
 # Multimedia devices
 #
 # CONFIG_VIDEO_DEV is not set
@@ -747,9 +829,8 @@
 #
 # Graphics support
 #
-CONFIG_FIRMWARE_EDID=y
-# CONFIG_FB is not set
 # CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+# CONFIG_FB is not set
 
 #
 # Sound
@@ -757,6 +838,12 @@
 # CONFIG_SOUND is not set
 
 #
+# HID Devices
+#
+CONFIG_HID=m
+# CONFIG_HID_DEBUG is not set
+
+#
 # USB support
 #
 CONFIG_USB_ARCH_HAS_HCD=y
@@ -776,6 +863,7 @@
 #
 # MMC/SD Card support
 #
+# CONFIG_SPI_MMC is not set
 # CONFIG_MMC is not set
 
 #
@@ -821,8 +909,10 @@
 #
 # CONFIG_RTC_DRV_DS1553 is not set
 # CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_RS5C348 is not set
 # CONFIG_RTC_DRV_M48T86 is not set
 # CONFIG_RTC_DRV_TEST is not set
+# CONFIG_RTC_DRV_MAX6902 is not set
 # CONFIG_RTC_DRV_V3020 is not set
 CONFIG_RTC_DRV_BFIN=y
 
@@ -840,6 +930,14 @@
 #
 
 #
+# Auxiliary Display support
+#
+
+#
+# Virtualization
+#
+
+#
 # PBX support
 #
 # CONFIG_PBX is not set
@@ -847,13 +945,9 @@
 #
 # File systems
 #
-CONFIG_EXT2_FS=y
-CONFIG_EXT2_FS_XATTR=y
-# CONFIG_EXT2_FS_POSIX_ACL is not set
-# CONFIG_EXT2_FS_SECURITY is not set
+# CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4DEV_FS is not set
-CONFIG_FS_MBCACHE=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -862,7 +956,8 @@
 # CONFIG_OCFS2_FS is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_ROMFS_FS is not set
-# CONFIG_INOTIFY is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
 # CONFIG_DNOTIFY is not set
 # CONFIG_AUTOFS_FS is not set
@@ -913,7 +1008,6 @@
 # CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
 # CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
 CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
-# CONFIG_JFFS_FS is not set
 CONFIG_JFFS2_FS=m
 CONFIG_JFFS2_FS_DEBUG=0
 CONFIG_JFFS2_FS_WRITEBUFFER=y
@@ -945,7 +1039,8 @@
 CONFIG_SUNRPC=m
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
-# CONFIG_SMB_FS is not set
+CONFIG_SMB_FS=m
+# CONFIG_SMB_NLS_DEFAULT is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -961,7 +1056,51 @@
 #
 # Native Language Support
 #
-# CONFIG_NLS is not set
+CONFIG_NLS=m
+CONFIG_NLS_DEFAULT="iso8859-1"
+# CONFIG_NLS_CODEPAGE_437 is not set
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+# CONFIG_NLS_ISO8859_1 is not set
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+
+#
+# Distributed Lock Manager
+#
+# CONFIG_DLM is not set
 
 #
 # Profiling support
@@ -975,19 +1114,16 @@
 CONFIG_ENABLE_MUST_CHECK=y
 # CONFIG_MAGIC_SYSRQ is not set
 # CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
 CONFIG_LOG_BUF_SHIFT=14
 # CONFIG_DEBUG_BUGVERBOSE is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_UNWIND_INFO is not set
-# CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_SERIAL_EARLY_INIT is not set
 CONFIG_DEBUG_HUNT_FOR_ZERO=y
 # CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
-# CONFIG_BOOTPARAM is not set
-# CONFIG_NO_KERNEL_MSG is not set
 CONFIG_CPLB_INFO=y
-# CONFIG_NO_ACCESS_CHECK is not set
+CONFIG_ACCESS_CHECK=y
 
 #
 # Security options
@@ -995,7 +1131,7 @@
 # CONFIG_KEYS is not set
 CONFIG_SECURITY=y
 # CONFIG_SECURITY_NETWORK is not set
-CONFIG_SECURITY_CAPABILITIES=y
+CONFIG_SECURITY_CAPABILITIES=m
 
 #
 # Cryptographic options
@@ -1005,10 +1141,13 @@
 #
 # Library routines
 #
-# CONFIG_CRC_CCITT is not set
+CONFIG_BITREVERSE=y
+CONFIG_CRC_CCITT=m
 # CONFIG_CRC16 is not set
 CONFIG_CRC32=y
 # CONFIG_LIBCRC32C is not set
 CONFIG_ZLIB_INFLATE=y
 CONFIG_ZLIB_DEFLATE=m
 CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
diff --git a/arch/blackfin/configs/BF533-STAMP_defconfig b/arch/blackfin/configs/BF533-STAMP_defconfig
index 14a948c..fee9189 100644
--- a/arch/blackfin/configs/BF533-STAMP_defconfig
+++ b/arch/blackfin/configs/BF533-STAMP_defconfig
@@ -1,12 +1,13 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.20.4
+# Linux kernel version: 2.6.21.3
 #
 # CONFIG_MMU is not set
 # CONFIG_FPU is not set
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
 # CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
 CONFIG_BLACKFIN=y
+CONFIG_ZONE_DMA=y
 CONFIG_BFIN=y
 CONFIG_SEMAPHORE_SLEEPERS=y
 CONFIG_GENERIC_FIND_NEXT_BIT=y
@@ -33,6 +34,7 @@
 CONFIG_LOCALVERSION_AUTO=y
 CONFIG_SYSVIPC=y
 # CONFIG_IPC_NS is not set
+CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 # CONFIG_TASKSTATS is not set
@@ -41,6 +43,7 @@
 # CONFIG_IKCONFIG is not set
 CONFIG_SYSFS_DEPRECATED=y
 # CONFIG_RELAY is not set
+CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
@@ -55,9 +58,7 @@
 CONFIG_ELF_CORE=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
-CONFIG_EPOLL=y
 CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
-# CONFIG_LIMIT_PAGECACHE is not set
 CONFIG_BUDDY=y
 # CONFIG_NP2 is not set
 CONFIG_SLAB=y
@@ -127,6 +128,7 @@
 # CONFIG_BFIN537_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_EZKIT is not set
+# CONFIG_BFIN561_TEPLA is not set
 # CONFIG_PNAV10 is not set
 # CONFIG_GENERIC_BOARD is not set
 CONFIG_MEM_MT48LC64M4A2FB_7E=y
@@ -193,19 +195,6 @@
 CONFIG_BFIN_IDLE_LED_DPORT=0xFFC00730
 
 #
-# Console UART Setup
-#
-# CONFIG_BAUD_9600 is not set
-# CONFIG_BAUD_19200 is not set
-# CONFIG_BAUD_38400 is not set
-CONFIG_BAUD_57600=y
-# CONFIG_BAUD_115200 is not set
-CONFIG_BAUD_NO_PARITY=y
-# CONFIG_BAUD_PARITY is not set
-CONFIG_BAUD_1_STOPBIT=y
-# CONFIG_BAUD_2_STOPBIT is not set
-
-#
 # Blackfin Kernel Optimizations
 #
 
@@ -233,6 +222,7 @@
 CONFIG_MEMCPY_L1=y
 CONFIG_SYS_BFIN_SPINLOCK_L1=y
 # CONFIG_IP_CHECKSUM_L1 is not set
+CONFIG_CACHELINE_ALIGNED_L1=y
 # CONFIG_SYSCALL_TAB_L1 is not set
 # CONFIG_CPLB_SWITCH_TAB_L1 is not set
 CONFIG_RAMKERNEL=y
@@ -246,6 +236,7 @@
 # CONFIG_SPARSEMEM_STATIC is not set
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
 CONFIG_LARGE_ALLOCS=y
 CONFIG_BFIN_DMA_5XX=y
 # CONFIG_DMA_UNCACHED_2M is not set
@@ -318,7 +309,7 @@
 # Power management options
 #
 CONFIG_PM=y
-CONFIG_PM_LEGACY=y
+# CONFIG_PM_LEGACY is not set
 # CONFIG_PM_DEBUG is not set
 # CONFIG_PM_SYSFS_DEPRECATED is not set
 CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR=y
@@ -346,6 +337,7 @@
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
 # CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 # CONFIG_IP_MULTICAST is not set
@@ -580,6 +572,7 @@
 #
 # Plug and Play support
 #
+# CONFIG_PNPACPI is not set
 
 #
 # Block devices
@@ -591,14 +584,12 @@
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=4096
 CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_BLK_DEV_INITRD is not set
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 
 #
 # Misc devices
 #
-# CONFIG_TIFM_CORE is not set
 
 #
 # ATA/ATAPI/MFM/RLL support
@@ -733,7 +724,7 @@
 #
 # CONFIG_AD9960 is not set
 # CONFIG_SPI_ADC_BF533 is not set
-# CONFIG_BF533_PFLAGS is not set
+# CONFIG_BF5xx_PFLAGS is not set
 # CONFIG_BF5xx_PPIFCD is not set
 # CONFIG_BF5xx_TIMERS is not set
 # CONFIG_BF5xx_PPI is not set
@@ -742,6 +733,8 @@
 CONFIG_TWI_LCD=m
 CONFIG_TWI_LCD_SLAVE_ADDR=34
 # CONFIG_AD5304 is not set
+# CONFIG_BF5xx_TEA5764 is not set
+# CONFIG_BF5xx_FBDMA is not set
 # CONFIG_VT is not set
 # CONFIG_SERIAL_NONSTANDARD is not set
 
@@ -778,7 +771,14 @@
 #
 # Watchdog Cards
 #
-# CONFIG_WATCHDOG is not set
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+CONFIG_BFIN_WDT=y
 CONFIG_HW_RANDOM=y
 # CONFIG_GEN_RTC is not set
 CONFIG_BLACKFIN_DPMC=y
@@ -840,12 +840,13 @@
 #
 # SPI Master Controller Drivers
 #
+CONFIG_SPI_BFIN=y
 # CONFIG_SPI_BITBANG is not set
 
 #
 # SPI Protocol Masters
 #
-CONFIG_SPI_BFIN=y
+# CONFIG_SPI_AT25 is not set
 
 #
 # Dallas's 1-wire bus
@@ -861,6 +862,7 @@
 # CONFIG_SENSORS_ADM1021 is not set
 # CONFIG_SENSORS_ADM1025 is not set
 # CONFIG_SENSORS_ADM1026 is not set
+# CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
 # CONFIG_SENSORS_ASB100 is not set
@@ -900,6 +902,11 @@
 # CONFIG_HWMON_DEBUG_CHIP is not set
 
 #
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
 # Multimedia devices
 #
 # CONFIG_VIDEO_DEV is not set
@@ -912,15 +919,22 @@
 #
 # Graphics support
 #
-CONFIG_FIRMWARE_EDID=y
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
 CONFIG_FB=m
+CONFIG_FIRMWARE_EDID=y
+# CONFIG_FB_DDC is not set
 CONFIG_FB_CFB_FILLRECT=m
 CONFIG_FB_CFB_COPYAREA=m
 CONFIG_FB_CFB_IMAGEBLIT=m
+# CONFIG_FB_SVGALIB is not set
 # CONFIG_FB_MACMODES is not set
 # CONFIG_FB_BACKLIGHT is not set
 # CONFIG_FB_MODE_HELPERS is not set
 # CONFIG_FB_TILEBLITTING is not set
+
+#
+# Frame buffer hardware drivers
+#
 CONFIG_FB_BFIN_7171=m
 CONFIG_FB_BFIN_7393=m
 CONFIG_NTSC=y
@@ -938,7 +952,6 @@
 # Logo configuration
 #
 # CONFIG_LOGO is not set
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
 
 #
 # Sound
@@ -971,6 +984,18 @@
 # CONFIG_SND_MPU401 is not set
 
 #
+# ALSA Blackfin devices
+#
+# CONFIG_SND_BLACKFIN_AD1836 is not set
+# CONFIG_SND_BLACKFIN_AD1981B is not set
+# CONFIG_SND_BFIN_AD73311 is not set
+
+#
+# SoC audio support
+#
+# CONFIG_SND_SOC is not set
+
+#
 # Open Sound System
 #
 # CONFIG_SOUND_PRIME is not set
@@ -979,6 +1004,7 @@
 # HID Devices
 #
 CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
 
 #
 # USB support
@@ -1051,7 +1077,6 @@
 # CONFIG_RTC_DRV_DS1672 is not set
 # CONFIG_RTC_DRV_DS1742 is not set
 # CONFIG_RTC_DRV_PCF8563 is not set
-# CONFIG_RTC_DRV_PCF8583 is not set
 # CONFIG_RTC_DRV_RS5C348 is not set
 # CONFIG_RTC_DRV_RS5C372 is not set
 # CONFIG_RTC_DRV_M48T86 is not set
@@ -1074,6 +1099,10 @@
 #
 
 #
+# Auxiliary Display support
+#
+
+#
 # Virtualization
 #
 
@@ -1085,13 +1114,9 @@
 #
 # File systems
 #
-CONFIG_EXT2_FS=y
-CONFIG_EXT2_FS_XATTR=y
-# CONFIG_EXT2_FS_POSIX_ACL is not set
-# CONFIG_EXT2_FS_SECURITY is not set
+# CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4DEV_FS is not set
-CONFIG_FS_MBCACHE=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1103,7 +1128,7 @@
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
+# CONFIG_DNOTIFY is not set
 # CONFIG_AUTOFS_FS is not set
 # CONFIG_AUTOFS4_FS is not set
 # CONFIG_FUSE_FS is not set
@@ -1275,7 +1300,7 @@
 # CONFIG_KEYS is not set
 CONFIG_SECURITY=y
 # CONFIG_SECURITY_NETWORK is not set
-CONFIG_SECURITY_CAPABILITIES=y
+CONFIG_SECURITY_CAPABILITIES=m
 
 #
 # Cryptographic options
@@ -1293,4 +1318,5 @@
 CONFIG_ZLIB_INFLATE=y
 CONFIG_ZLIB_DEFLATE=m
 CONFIG_PLIST=y
-CONFIG_IOMAP_COPY=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
diff --git a/arch/blackfin/configs/BF537-STAMP_defconfig b/arch/blackfin/configs/BF537-STAMP_defconfig
index 8ed67dc4..37688bb 100644
--- a/arch/blackfin/configs/BF537-STAMP_defconfig
+++ b/arch/blackfin/configs/BF537-STAMP_defconfig
@@ -1,12 +1,13 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.20.4
+# Linux kernel version: 2.6.21.3
 #
 # CONFIG_MMU is not set
 # CONFIG_FPU is not set
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
 # CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
 CONFIG_BLACKFIN=y
+CONFIG_ZONE_DMA=y
 CONFIG_BFIN=y
 CONFIG_SEMAPHORE_SLEEPERS=y
 CONFIG_GENERIC_FIND_NEXT_BIT=y
@@ -33,6 +34,7 @@
 CONFIG_LOCALVERSION_AUTO=y
 CONFIG_SYSVIPC=y
 # CONFIG_IPC_NS is not set
+CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 # CONFIG_TASKSTATS is not set
@@ -41,6 +43,7 @@
 # CONFIG_IKCONFIG is not set
 CONFIG_SYSFS_DEPRECATED=y
 # CONFIG_RELAY is not set
+CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
@@ -55,9 +58,7 @@
 CONFIG_ELF_CORE=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
-CONFIG_EPOLL=y
 CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
-# CONFIG_LIMIT_PAGECACHE is not set
 CONFIG_BUDDY=y
 # CONFIG_NP2 is not set
 CONFIG_SLAB=y
@@ -127,6 +128,7 @@
 # CONFIG_BFIN537_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_EZKIT is not set
+# CONFIG_BFIN561_TEPLA is not set
 # CONFIG_PNAV10 is not set
 # CONFIG_GENERIC_BOARD is not set
 CONFIG_MEM_MT48LC32M8A2_75=y
@@ -196,19 +198,6 @@
 CONFIG_BOOT_LOAD=0x1000
 
 #
-# Console UART Setup
-#
-# CONFIG_BAUD_9600 is not set
-# CONFIG_BAUD_19200 is not set
-# CONFIG_BAUD_38400 is not set
-CONFIG_BAUD_57600=y
-# CONFIG_BAUD_115200 is not set
-CONFIG_BAUD_NO_PARITY=y
-# CONFIG_BAUD_PARITY is not set
-CONFIG_BAUD_1_STOPBIT=y
-# CONFIG_BAUD_2_STOPBIT is not set
-
-#
 # Blackfin Kernel Optimizations
 #
 
@@ -236,6 +225,7 @@
 CONFIG_MEMCPY_L1=y
 CONFIG_SYS_BFIN_SPINLOCK_L1=y
 # CONFIG_IP_CHECKSUM_L1 is not set
+CONFIG_CACHELINE_ALIGNED_L1=y
 # CONFIG_SYSCALL_TAB_L1 is not set
 # CONFIG_CPLB_SWITCH_TAB_L1 is not set
 CONFIG_RAMKERNEL=y
@@ -249,6 +239,7 @@
 # CONFIG_SPARSEMEM_STATIC is not set
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
 CONFIG_LARGE_ALLOCS=y
 CONFIG_BFIN_DMA_5XX=y
 # CONFIG_DMA_UNCACHED_2M is not set
@@ -321,7 +312,7 @@
 # Power management options
 #
 CONFIG_PM=y
-CONFIG_PM_LEGACY=y
+# CONFIG_PM_LEGACY is not set
 # CONFIG_PM_DEBUG is not set
 # CONFIG_PM_SYSFS_DEPRECATED is not set
 CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR=y
@@ -349,6 +340,7 @@
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
 # CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 # CONFIG_IP_MULTICAST is not set
@@ -593,6 +585,7 @@
 #
 # Plug and Play support
 #
+# CONFIG_PNPACPI is not set
 
 #
 # Block devices
@@ -604,14 +597,12 @@
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=4096
 CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_BLK_DEV_INITRD is not set
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 
 #
 # Misc devices
 #
-# CONFIG_TIFM_CORE is not set
 
 #
 # ATA/ATAPI/MFM/RLL support
@@ -751,7 +742,7 @@
 #
 # CONFIG_AD9960 is not set
 # CONFIG_SPI_ADC_BF533 is not set
-# CONFIG_BF533_PFLAGS is not set
+# CONFIG_BF5xx_PFLAGS is not set
 # CONFIG_BF5xx_PPIFCD is not set
 # CONFIG_BF5xx_TIMERS is not set
 # CONFIG_BF5xx_PPI is not set
@@ -760,6 +751,8 @@
 CONFIG_TWI_LCD=m
 CONFIG_TWI_LCD_SLAVE_ADDR=34
 # CONFIG_AD5304 is not set
+# CONFIG_BF5xx_TEA5764 is not set
+# CONFIG_BF5xx_FBDMA is not set
 # CONFIG_VT is not set
 # CONFIG_SERIAL_NONSTANDARD is not set
 
@@ -804,7 +797,14 @@
 #
 # Watchdog Cards
 #
-# CONFIG_WATCHDOG is not set
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+CONFIG_BFIN_WDT=y
 CONFIG_HW_RANDOM=y
 # CONFIG_GEN_RTC is not set
 CONFIG_BLACKFIN_DPMC=y
@@ -868,12 +868,13 @@
 #
 # SPI Master Controller Drivers
 #
+CONFIG_SPI_BFIN=y
 # CONFIG_SPI_BITBANG is not set
 
 #
 # SPI Protocol Masters
 #
-CONFIG_SPI_BFIN=y
+# CONFIG_SPI_AT25 is not set
 
 #
 # Dallas's 1-wire bus
@@ -889,6 +890,7 @@
 # CONFIG_SENSORS_ADM1021 is not set
 # CONFIG_SENSORS_ADM1025 is not set
 # CONFIG_SENSORS_ADM1026 is not set
+# CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
 # CONFIG_SENSORS_ASB100 is not set
@@ -928,6 +930,11 @@
 # CONFIG_HWMON_DEBUG_CHIP is not set
 
 #
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
 # Multimedia devices
 #
 # CONFIG_VIDEO_DEV is not set
@@ -940,15 +947,24 @@
 #
 # Graphics support
 #
-CONFIG_FIRMWARE_EDID=y
+CONFIG_BACKLIGHT_LCD_SUPPORT=y
+CONFIG_BACKLIGHT_CLASS_DEVICE=m
+CONFIG_LCD_CLASS_DEVICE=m
 CONFIG_FB=m
+CONFIG_FIRMWARE_EDID=y
+# CONFIG_FB_DDC is not set
 CONFIG_FB_CFB_FILLRECT=m
 CONFIG_FB_CFB_COPYAREA=m
 CONFIG_FB_CFB_IMAGEBLIT=m
+# CONFIG_FB_SVGALIB is not set
 # CONFIG_FB_MACMODES is not set
 # CONFIG_FB_BACKLIGHT is not set
 # CONFIG_FB_MODE_HELPERS is not set
 # CONFIG_FB_TILEBLITTING is not set
+
+#
+# Frame buffer hardware drivers
+#
 CONFIG_FB_BFIN_7171=m
 CONFIG_FB_BFIN_7393=m
 CONFIG_NTSC=y
@@ -970,11 +986,6 @@
 # Logo configuration
 #
 # CONFIG_LOGO is not set
-CONFIG_BACKLIGHT_LCD_SUPPORT=y
-CONFIG_BACKLIGHT_CLASS_DEVICE=m
-CONFIG_BACKLIGHT_DEVICE=y
-CONFIG_LCD_CLASS_DEVICE=m
-CONFIG_LCD_DEVICE=y
 
 #
 # Sound
@@ -1007,6 +1018,18 @@
 # CONFIG_SND_MPU401 is not set
 
 #
+# ALSA Blackfin devices
+#
+# CONFIG_SND_BLACKFIN_AD1836 is not set
+# CONFIG_SND_BLACKFIN_AD1981B is not set
+# CONFIG_SND_BFIN_AD73311 is not set
+
+#
+# SoC audio support
+#
+# CONFIG_SND_SOC is not set
+
+#
 # Open Sound System
 #
 # CONFIG_SOUND_PRIME is not set
@@ -1015,6 +1038,7 @@
 # HID Devices
 #
 CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
 
 #
 # USB support
@@ -1087,7 +1111,6 @@
 # CONFIG_RTC_DRV_DS1672 is not set
 # CONFIG_RTC_DRV_DS1742 is not set
 # CONFIG_RTC_DRV_PCF8563 is not set
-# CONFIG_RTC_DRV_PCF8583 is not set
 # CONFIG_RTC_DRV_RS5C348 is not set
 # CONFIG_RTC_DRV_RS5C372 is not set
 # CONFIG_RTC_DRV_M48T86 is not set
@@ -1110,6 +1133,10 @@
 #
 
 #
+# Auxiliary Display support
+#
+
+#
 # Virtualization
 #
 
@@ -1121,13 +1148,9 @@
 #
 # File systems
 #
-CONFIG_EXT2_FS=y
-CONFIG_EXT2_FS_XATTR=y
-# CONFIG_EXT2_FS_POSIX_ACL is not set
-# CONFIG_EXT2_FS_SECURITY is not set
+# CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4DEV_FS is not set
-CONFIG_FS_MBCACHE=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1139,7 +1162,7 @@
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
+# CONFIG_DNOTIFY is not set
 # CONFIG_AUTOFS_FS is not set
 # CONFIG_AUTOFS4_FS is not set
 # CONFIG_FUSE_FS is not set
@@ -1311,7 +1334,7 @@
 # CONFIG_KEYS is not set
 CONFIG_SECURITY=y
 # CONFIG_SECURITY_NETWORK is not set
-CONFIG_SECURITY_CAPABILITIES=y
+CONFIG_SECURITY_CAPABILITIES=m
 
 #
 # Cryptographic options
@@ -1329,4 +1352,5 @@
 CONFIG_ZLIB_INFLATE=y
 CONFIG_ZLIB_DEFLATE=m
 CONFIG_PLIST=y
-CONFIG_IOMAP_COPY=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
diff --git a/arch/blackfin/configs/BF561-EZKIT_defconfig b/arch/blackfin/configs/BF561-EZKIT_defconfig
index e32ca20..fe4e67d 100644
--- a/arch/blackfin/configs/BF561-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF561-EZKIT_defconfig
@@ -1,20 +1,21 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.19.3
+# Linux kernel version: 2.6.21.3
 #
 # CONFIG_MMU is not set
 # CONFIG_FPU is not set
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
 # CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
 CONFIG_BLACKFIN=y
+CONFIG_ZONE_DMA=y
 CONFIG_BFIN=y
 CONFIG_SEMAPHORE_SLEEPERS=y
 CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
+# CONFIG_GENERIC_TIME is not set
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_UCLINUX=y
 CONFIG_FORCE_MAX_ZONEORDER=14
 CONFIG_IRQCHIP_DEMUX_GPIO=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
@@ -33,18 +34,21 @@
 CONFIG_LOCALVERSION_AUTO=y
 CONFIG_SYSVIPC=y
 # CONFIG_IPC_NS is not set
+CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 # CONFIG_TASKSTATS is not set
 # CONFIG_UTS_NS is not set
 # CONFIG_AUDIT is not set
 # CONFIG_IKCONFIG is not set
+CONFIG_SYSFS_DEPRECATED=y
 # CONFIG_RELAY is not set
+CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_EMBEDDED=y
-# CONFIG_UID16 is not set
+CONFIG_UID16=y
 CONFIG_SYSCTL_SYSCALL=y
 CONFIG_KALLSYMS=y
 # CONFIG_KALLSYMS_EXTRA_PASS is not set
@@ -54,9 +58,7 @@
 CONFIG_ELF_CORE=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
-CONFIG_EPOLL=y
 CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
-# CONFIG_LIMIT_PAGECACHE is not set
 CONFIG_BUDDY=y
 # CONFIG_NP2 is not set
 CONFIG_SLAB=y
@@ -80,7 +82,9 @@
 # Block layer
 #
 CONFIG_BLOCK=y
+# CONFIG_LBD is not set
 # CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
 
 #
 # IO Schedulers
@@ -109,7 +113,6 @@
 # CONFIG_BF532 is not set
 # CONFIG_BF533 is not set
 # CONFIG_BF534 is not set
-# CONFIG_BF535 is not set
 # CONFIG_BF536 is not set
 # CONFIG_BF537 is not set
 CONFIG_BF561=y
@@ -125,6 +128,7 @@
 # CONFIG_BFIN537_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_BLUETECHNIX_CM is not set
 CONFIG_BFIN561_EZKIT=y
+# CONFIG_BFIN561_TEPLA is not set
 # CONFIG_PNAV10 is not set
 # CONFIG_GENERIC_BOARD is not set
 CONFIG_MEM_MT48LC16M16A2TG_75=y
@@ -214,6 +218,7 @@
 #
 # Board customizations
 #
+# CONFIG_CMDLINE_BOOL is not set
 
 #
 # Board Setup
@@ -224,19 +229,6 @@
 CONFIG_BOOT_LOAD=0x1000
 
 #
-# Console UART Setup
-#
-# CONFIG_BAUD_9600 is not set
-# CONFIG_BAUD_19200 is not set
-# CONFIG_BAUD_38400 is not set
-CONFIG_BAUD_57600=y
-# CONFIG_BAUD_115200 is not set
-CONFIG_BAUD_NO_PARITY=y
-# CONFIG_BAUD_PARITY is not set
-CONFIG_BAUD_1_STOPBIT=y
-# CONFIG_BAUD_2_STOPBIT is not set
-
-#
 # Blackfin Kernel Optimizations
 #
 
@@ -245,6 +237,7 @@
 #
 # CONFIG_HZ_100 is not set
 CONFIG_HZ_250=y
+# CONFIG_HZ_300 is not set
 # CONFIG_HZ_1000 is not set
 CONFIG_HZ=250
 
@@ -263,6 +256,7 @@
 CONFIG_MEMCPY_L1=y
 CONFIG_SYS_BFIN_SPINLOCK_L1=y
 # CONFIG_IP_CHECKSUM_L1 is not set
+CONFIG_CACHELINE_ALIGNED_L1=y
 # CONFIG_SYSCALL_TAB_L1 is not set
 # CONFIG_CPLB_SWITCH_TAB_L1 is not set
 CONFIG_RAMKERNEL=y
@@ -276,6 +270,7 @@
 # CONFIG_SPARSEMEM_STATIC is not set
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
 CONFIG_LARGE_ALLOCS=y
 CONFIG_BFIN_DMA_5XX=y
 # CONFIG_DMA_UNCACHED_2M is not set
@@ -368,6 +363,7 @@
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
 # CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 # CONFIG_IP_MULTICAST is not set
@@ -394,6 +390,7 @@
 # CONFIG_TCP_CONG_ADVANCED is not set
 CONFIG_TCP_CONG_CUBIC=y
 CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
 # CONFIG_IPV6 is not set
 # CONFIG_INET6_XFRM_TUNNEL is not set
 # CONFIG_INET6_TUNNEL is not set
@@ -437,7 +434,48 @@
 #
 # CONFIG_NET_PKTGEN is not set
 # CONFIG_HAMRADIO is not set
-# CONFIG_IRDA is not set
+CONFIG_IRDA=m
+
+#
+# IrDA protocols
+#
+CONFIG_IRLAN=m
+CONFIG_IRCOMM=m
+# CONFIG_IRDA_ULTRA is not set
+
+#
+# IrDA options
+#
+CONFIG_IRDA_CACHE_LAST_LSAP=y
+# CONFIG_IRDA_FAST_RR is not set
+# CONFIG_IRDA_DEBUG is not set
+
+#
+# Infrared-port device drivers
+#
+
+#
+# SIR device drivers
+#
+CONFIG_IRTTY_SIR=m
+
+#
+# Dongle support
+#
+# CONFIG_DONGLE is not set
+
+#
+# Old SIR device drivers
+#
+# CONFIG_IRPORT_SIR is not set
+
+#
+# Old Serial dongle support
+#
+
+#
+# FIR device drivers
+#
 # CONFIG_BT is not set
 # CONFIG_IEEE80211 is not set
 
@@ -472,6 +510,7 @@
 # User Modules And Translation Layers
 #
 CONFIG_MTD_CHAR=m
+CONFIG_MTD_BLKDEVS=y
 CONFIG_MTD_BLOCK=y
 # CONFIG_FTL is not set
 # CONFIG_NFTL is not set
@@ -528,6 +567,8 @@
 #
 # Self-contained MTD device drivers
 #
+# CONFIG_MTD_DATAFLASH is not set
+# CONFIG_MTD_M25P80 is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_PHRAM is not set
 # CONFIG_MTD_MTDRAM is not set
@@ -558,6 +599,7 @@
 #
 # Plug and Play support
 #
+# CONFIG_PNPACPI is not set
 
 #
 # Block devices
@@ -569,14 +611,12 @@
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=4096
 CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_BLK_DEV_INITRD is not set
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 
 #
 # Misc devices
 #
-# CONFIG_TIFM_CORE is not set
 
 #
 # ATA/ATAPI/MFM/RLL support
@@ -675,7 +715,26 @@
 #
 # Input device support
 #
-# CONFIG_INPUT is not set
+CONFIG_INPUT=m
+# CONFIG_INPUT_FF_MEMLESS is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_TSDEV is not set
+CONFIG_INPUT_EVDEV=m
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
 
 #
 # Hardware I/O ports
@@ -688,12 +747,14 @@
 #
 # CONFIG_AD9960 is not set
 # CONFIG_SPI_ADC_BF533 is not set
-# CONFIG_BF533_PFLAGS is not set
+# CONFIG_BF5xx_PFLAGS is not set
 # CONFIG_BF5xx_PPIFCD is not set
 # CONFIG_BF5xx_TIMERS is not set
 # CONFIG_BF5xx_PPI is not set
 # CONFIG_BFIN_SPORT is not set
 # CONFIG_BFIN_TIMER_LATENCY is not set
+# CONFIG_AD5304 is not set
+# CONFIG_BF5xx_FBDMA is not set
 # CONFIG_VT is not set
 # CONFIG_SERIAL_NONSTANDARD is not set
 
@@ -730,16 +791,19 @@
 #
 # Watchdog Cards
 #
-# CONFIG_WATCHDOG is not set
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+CONFIG_BFIN_WDT=y
 CONFIG_HW_RANDOM=y
 # CONFIG_GEN_RTC is not set
 # CONFIG_BLACKFIN_DPMC is not set
 # CONFIG_DTLK is not set
 # CONFIG_R3964 is not set
-
-#
-# Ftape, the floppy tape device driver
-#
 # CONFIG_RAW_DRIVER is not set
 
 #
@@ -755,8 +819,19 @@
 #
 # SPI support
 #
-# CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
+CONFIG_SPI=y
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_BFIN=y
+# CONFIG_SPI_BITBANG is not set
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
 
 #
 # Dallas's 1-wire bus
@@ -770,10 +845,17 @@
 # CONFIG_HWMON_VID is not set
 # CONFIG_SENSORS_ABITUGURU is not set
 # CONFIG_SENSORS_F71805F is not set
+# CONFIG_SENSORS_LM70 is not set
+# CONFIG_SENSORS_PC87427 is not set
 # CONFIG_SENSORS_VT1211 is not set
 # CONFIG_HWMON_DEBUG_CHIP is not set
 
 #
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
 # Multimedia devices
 #
 # CONFIG_VIDEO_DEV is not set
@@ -786,9 +868,8 @@
 #
 # Graphics support
 #
-CONFIG_FIRMWARE_EDID=y
-# CONFIG_FB is not set
 # CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+# CONFIG_FB is not set
 
 #
 # Sound
@@ -796,6 +877,12 @@
 # CONFIG_SOUND is not set
 
 #
+# HID Devices
+#
+CONFIG_HID=m
+# CONFIG_HID_DEBUG is not set
+
+#
 # USB support
 #
 CONFIG_USB_ARCH_HAS_HCD=y
@@ -815,6 +902,7 @@
 #
 # MMC/SD Card support
 #
+# CONFIG_SPI_MMC is not set
 # CONFIG_MMC is not set
 
 #
@@ -857,6 +945,14 @@
 #
 
 #
+# Auxiliary Display support
+#
+
+#
+# Virtualization
+#
+
+#
 # PBX support
 #
 # CONFIG_PBX is not set
@@ -864,13 +960,9 @@
 #
 # File systems
 #
-CONFIG_EXT2_FS=y
-CONFIG_EXT2_FS_XATTR=y
-# CONFIG_EXT2_FS_POSIX_ACL is not set
-# CONFIG_EXT2_FS_SECURITY is not set
+# CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4DEV_FS is not set
-CONFIG_FS_MBCACHE=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -882,7 +974,7 @@
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
+# CONFIG_DNOTIFY is not set
 # CONFIG_AUTOFS_FS is not set
 # CONFIG_AUTOFS4_FS is not set
 # CONFIG_FUSE_FS is not set
@@ -931,7 +1023,6 @@
 # CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
 # CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
 CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
-# CONFIG_JFFS_FS is not set
 CONFIG_JFFS2_FS=m
 CONFIG_JFFS2_FS_DEBUG=0
 CONFIG_JFFS2_FS_WRITEBUFFER=y
@@ -1022,6 +1113,11 @@
 # CONFIG_NLS_UTF8 is not set
 
 #
+# Distributed Lock Manager
+#
+# CONFIG_DLM is not set
+
+#
 # Profiling support
 #
 # CONFIG_PROFILING is not set
@@ -1033,20 +1129,17 @@
 CONFIG_ENABLE_MUST_CHECK=y
 # CONFIG_MAGIC_SYSRQ is not set
 # CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
 CONFIG_LOG_BUF_SHIFT=14
 # CONFIG_DEBUG_BUGVERBOSE is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_UNWIND_INFO is not set
-# CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_SERIAL_EARLY_INIT is not set
 CONFIG_DEBUG_HUNT_FOR_ZERO=y
 # CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
 # CONFIG_DUAL_CORE_TEST_MODULE is not set
-# CONFIG_BOOTPARAM is not set
-# CONFIG_NO_KERNEL_MSG is not set
 CONFIG_CPLB_INFO=y
-# CONFIG_NO_ACCESS_CHECK is not set
+CONFIG_ACCESS_CHECK=y
 
 #
 # Security options
@@ -1054,7 +1147,7 @@
 # CONFIG_KEYS is not set
 CONFIG_SECURITY=y
 # CONFIG_SECURITY_NETWORK is not set
-CONFIG_SECURITY_CAPABILITIES=y
+CONFIG_SECURITY_CAPABILITIES=m
 
 #
 # Cryptographic options
@@ -1064,10 +1157,13 @@
 #
 # Library routines
 #
-# CONFIG_CRC_CCITT is not set
+CONFIG_BITREVERSE=y
+CONFIG_CRC_CCITT=m
 # CONFIG_CRC16 is not set
 CONFIG_CRC32=y
 # CONFIG_LIBCRC32C is not set
 CONFIG_ZLIB_INFLATE=y
 CONFIG_ZLIB_DEFLATE=m
 CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
diff --git a/arch/blackfin/configs/PNAV-10_defconfig b/arch/blackfin/configs/PNAV-10_defconfig
index 97b4ffa..a783ff6 100644
--- a/arch/blackfin/configs/PNAV-10_defconfig
+++ b/arch/blackfin/configs/PNAV-10_defconfig
@@ -1,20 +1,21 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.19.3
+# Linux kernel version: 2.6.21.3
 #
 # CONFIG_MMU is not set
 # CONFIG_FPU is not set
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
 # CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
 CONFIG_BLACKFIN=y
+CONFIG_ZONE_DMA=y
 CONFIG_BFIN=y
 CONFIG_SEMAPHORE_SLEEPERS=y
 CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
+# CONFIG_GENERIC_TIME is not set
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_UCLINUX=y
 CONFIG_FORCE_MAX_ZONEORDER=14
 CONFIG_IRQCHIP_DEMUX_GPIO=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
@@ -33,14 +34,16 @@
 CONFIG_LOCALVERSION_AUTO=y
 CONFIG_SYSVIPC=y
 # CONFIG_IPC_NS is not set
+CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 # CONFIG_TASKSTATS is not set
 # CONFIG_UTS_NS is not set
 # CONFIG_AUDIT is not set
 # CONFIG_IKCONFIG is not set
+CONFIG_SYSFS_DEPRECATED=y
 # CONFIG_RELAY is not set
-CONFIG_INITRAMFS_SOURCE=""
+# CONFIG_BLK_DEV_INITRD is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_EMBEDDED=y
@@ -54,9 +57,7 @@
 CONFIG_ELF_CORE=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
-CONFIG_EPOLL=y
 CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=9
-# CONFIG_LIMIT_PAGECACHE is not set
 CONFIG_BUDDY=y
 # CONFIG_NP2 is not set
 CONFIG_SLAB=y
@@ -80,7 +81,9 @@
 # Block layer
 #
 CONFIG_BLOCK=y
+# CONFIG_LBD is not set
 # CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
 
 #
 # IO Schedulers
@@ -109,7 +112,6 @@
 # CONFIG_BF532 is not set
 # CONFIG_BF533 is not set
 # CONFIG_BF534 is not set
-# CONFIG_BF535 is not set
 # CONFIG_BF536 is not set
 CONFIG_BF537=y
 # CONFIG_BF561 is not set
@@ -125,6 +127,7 @@
 # CONFIG_BFIN537_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_BLUETECHNIX_CM is not set
 # CONFIG_BFIN561_EZKIT is not set
+# CONFIG_BFIN561_TEPLA is not set
 CONFIG_PNAV10=y
 # CONFIG_GENERIC_BOARD is not set
 CONFIG_MEM_MT48LC32M8A2_75=y
@@ -183,6 +186,7 @@
 #
 # Board customizations
 #
+# CONFIG_CMDLINE_BOOL is not set
 
 #
 # Board Setup
@@ -193,19 +197,6 @@
 CONFIG_BOOT_LOAD=0x1000
 
 #
-# Console UART Setup
-#
-# CONFIG_BAUD_9600 is not set
-# CONFIG_BAUD_19200 is not set
-# CONFIG_BAUD_38400 is not set
-# CONFIG_BAUD_57600 is not set
-CONFIG_BAUD_115200=y
-CONFIG_BAUD_NO_PARITY=y
-# CONFIG_BAUD_PARITY is not set
-CONFIG_BAUD_1_STOPBIT=y
-# CONFIG_BAUD_2_STOPBIT is not set
-
-#
 # Blackfin Kernel Optimizations
 #
 
@@ -214,6 +205,7 @@
 #
 # CONFIG_HZ_100 is not set
 CONFIG_HZ_250=y
+# CONFIG_HZ_300 is not set
 # CONFIG_HZ_1000 is not set
 CONFIG_HZ=250
 
@@ -232,6 +224,7 @@
 CONFIG_MEMCPY_L1=y
 CONFIG_SYS_BFIN_SPINLOCK_L1=y
 CONFIG_IP_CHECKSUM_L1=y
+CONFIG_CACHELINE_ALIGNED_L1=y
 CONFIG_SYSCALL_TAB_L1=y
 CONFIG_CPLB_SWITCH_TAB_L1=y
 CONFIG_RAMKERNEL=y
@@ -245,6 +238,7 @@
 # CONFIG_SPARSEMEM_STATIC is not set
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
 CONFIG_LARGE_ALLOCS=y
 CONFIG_BFIN_DMA_5XX=y
 # CONFIG_DMA_UNCACHED_2M is not set
@@ -338,6 +332,7 @@
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
 # CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 # CONFIG_IP_MULTICAST is not set
@@ -364,6 +359,7 @@
 # CONFIG_TCP_CONG_ADVANCED is not set
 CONFIG_TCP_CONG_CUBIC=y
 CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
 # CONFIG_IPV6 is not set
 # CONFIG_INET6_XFRM_TUNNEL is not set
 # CONFIG_INET6_TUNNEL is not set
@@ -442,6 +438,7 @@
 # User Modules And Translation Layers
 #
 CONFIG_MTD_CHAR=m
+CONFIG_MTD_BLKDEVS=y
 CONFIG_MTD_BLOCK=y
 # CONFIG_FTL is not set
 # CONFIG_NFTL is not set
@@ -522,6 +519,7 @@
 #
 # Plug and Play support
 #
+# CONFIG_PNPACPI is not set
 
 #
 # Block devices
@@ -533,14 +531,12 @@
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=4096
 CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_BLK_DEV_INITRD is not set
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 
 #
 # Misc devices
 #
-# CONFIG_TIFM_CORE is not set
 
 #
 # ATA/ATAPI/MFM/RLL support
@@ -674,6 +670,7 @@
 # CONFIG_TOUCHSCREEN_PENMOUNT is not set
 # CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
 # CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+# CONFIG_TOUCHSCREEN_UCB1400 is not set
 CONFIG_INPUT_MISC=y
 CONFIG_INPUT_UINPUT=y
 # CONFIG_BF53X_PFBUTTONS is not set
@@ -690,7 +687,7 @@
 #
 # CONFIG_AD9960 is not set
 # CONFIG_SPI_ADC_BF533 is not set
-# CONFIG_BF533_PFLAGS is not set
+# CONFIG_BF5xx_PFLAGS is not set
 # CONFIG_BF5xx_PPIFCD is not set
 # CONFIG_BF5xx_TIMERS is not set
 # CONFIG_BF5xx_PPI is not set
@@ -699,6 +696,8 @@
 CONFIG_TWI_LCD=m
 CONFIG_TWI_LCD_SLAVE_ADDR=34
 # CONFIG_AD5304 is not set
+# CONFIG_BF5xx_TEA5764 is not set
+# CONFIG_BF5xx_FBDMA is not set
 # CONFIG_VT is not set
 # CONFIG_SERIAL_NONSTANDARD is not set
 
@@ -750,10 +749,6 @@
 CONFIG_BLACKFIN_DPMC=y
 # CONFIG_DTLK is not set
 # CONFIG_R3964 is not set
-
-#
-# Ftape, the floppy tape device driver
-#
 # CONFIG_RAW_DRIVER is not set
 
 #
@@ -777,9 +772,9 @@
 #
 # I2C Hardware Bus support
 #
-# CONFIG_I2C_BFIN_GPIO is not set
-CONFIG_I2C_BFIN_TWI=y
-CONFIG_TWICLK_KHZ=50
+# CONFIG_I2C_BLACKFIN_GPIO is not set
+CONFIG_I2C_BLACKFIN_TWI=y
+CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_PARPORT_LIGHT is not set
 # CONFIG_I2C_STUB is not set
@@ -812,12 +807,13 @@
 #
 # SPI Master Controller Drivers
 #
-# CONFIG_SPI_BITBANG is not set
 CONFIG_SPI_BFIN=y
+# CONFIG_SPI_BITBANG is not set
 
 #
 # SPI Protocol Masters
 #
+# CONFIG_SPI_AT25 is not set
 
 #
 # Dallas's 1-wire bus
@@ -833,6 +829,7 @@
 # CONFIG_SENSORS_ADM1021 is not set
 # CONFIG_SENSORS_ADM1025 is not set
 # CONFIG_SENSORS_ADM1026 is not set
+# CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
 # CONFIG_SENSORS_ASB100 is not set
@@ -857,6 +854,7 @@
 # CONFIG_SENSORS_LM92 is not set
 # CONFIG_SENSORS_MAX1619 is not set
 # CONFIG_SENSORS_PC87360 is not set
+# CONFIG_SENSORS_PC87427 is not set
 # CONFIG_SENSORS_SMSC47M1 is not set
 # CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
@@ -864,12 +862,18 @@
 # CONFIG_SENSORS_W83781D is not set
 # CONFIG_SENSORS_W83791D is not set
 # CONFIG_SENSORS_W83792D is not set
+# CONFIG_SENSORS_W83793 is not set
 # CONFIG_SENSORS_W83L785TS is not set
 # CONFIG_SENSORS_W83627HF is not set
 # CONFIG_SENSORS_W83627EHF is not set
 # CONFIG_HWMON_DEBUG_CHIP is not set
 
 #
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
 # Multimedia devices
 #
 # CONFIG_VIDEO_DEV is not set
@@ -882,15 +886,24 @@
 #
 # Graphics support
 #
-CONFIG_FIRMWARE_EDID=y
+CONFIG_BACKLIGHT_LCD_SUPPORT=y
+CONFIG_BACKLIGHT_CLASS_DEVICE=y
+CONFIG_LCD_CLASS_DEVICE=y
 CONFIG_FB=y
+CONFIG_FIRMWARE_EDID=y
+# CONFIG_FB_DDC is not set
 CONFIG_FB_CFB_FILLRECT=y
 CONFIG_FB_CFB_COPYAREA=y
 CONFIG_FB_CFB_IMAGEBLIT=y
+# CONFIG_FB_SVGALIB is not set
 # CONFIG_FB_MACMODES is not set
 # CONFIG_FB_BACKLIGHT is not set
 # CONFIG_FB_MODE_HELPERS is not set
 # CONFIG_FB_TILEBLITTING is not set
+
+#
+# Frame buffer hardware drivers
+#
 # CONFIG_FB_BFIN_7171 is not set
 # CONFIG_FB_BFIN_7393 is not set
 CONFIG_FB_BF537_LQ035=y
@@ -904,11 +917,6 @@
 # Logo configuration
 #
 # CONFIG_LOGO is not set
-CONFIG_BACKLIGHT_LCD_SUPPORT=y
-CONFIG_BACKLIGHT_CLASS_DEVICE=y
-CONFIG_BACKLIGHT_DEVICE=y
-CONFIG_LCD_CLASS_DEVICE=y
-CONFIG_LCD_DEVICE=y
 
 #
 # Sound
@@ -946,14 +954,24 @@
 # CONFIG_SND_BFIN_AD73311 is not set
 
 #
+# SoC audio support
+#
+# CONFIG_SND_SOC is not set
+
+#
 # Open Sound System
 #
 CONFIG_SOUND_PRIME=y
-CONFIG_OSS_OBSOLETE_DRIVER=y
+# CONFIG_OBSOLETE_OSS is not set
 # CONFIG_SOUND_MSNDCLAS is not set
 # CONFIG_SOUND_MSNDPIN is not set
 
 #
+# HID Devices
+#
+# CONFIG_HID is not set
+
+#
 # USB support
 #
 CONFIG_USB_ARCH_HAS_HCD=y
@@ -1024,7 +1042,6 @@
 # CONFIG_RTC_DRV_DS1672 is not set
 # CONFIG_RTC_DRV_DS1742 is not set
 # CONFIG_RTC_DRV_PCF8563 is not set
-# CONFIG_RTC_DRV_PCF8583 is not set
 # CONFIG_RTC_DRV_RS5C348 is not set
 # CONFIG_RTC_DRV_RS5C372 is not set
 # CONFIG_RTC_DRV_M48T86 is not set
@@ -1047,6 +1064,14 @@
 #
 
 #
+# Auxiliary Display support
+#
+
+#
+# Virtualization
+#
+
+#
 # PBX support
 #
 # CONFIG_PBX is not set
@@ -1121,7 +1146,6 @@
 # CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
 # CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
 CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
-# CONFIG_JFFS_FS is not set
 # CONFIG_JFFS2_FS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1204,6 +1228,11 @@
 # CONFIG_NLS_UTF8 is not set
 
 #
+# Distributed Lock Manager
+#
+# CONFIG_DLM is not set
+
+#
 # Profiling support
 #
 # CONFIG_PROFILING is not set
@@ -1215,19 +1244,16 @@
 CONFIG_ENABLE_MUST_CHECK=y
 # CONFIG_MAGIC_SYSRQ is not set
 # CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
 CONFIG_LOG_BUF_SHIFT=14
 # CONFIG_DEBUG_BUGVERBOSE is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_UNWIND_INFO is not set
-# CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_SERIAL_EARLY_INIT is not set
 # CONFIG_DEBUG_HUNT_FOR_ZERO is not set
 # CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
-# CONFIG_BOOTPARAM is not set
-# CONFIG_NO_KERNEL_MSG is not set
 # CONFIG_CPLB_INFO is not set
-# CONFIG_NO_ACCESS_CHECK is not set
+# CONFIG_ACCESS_CHECK is not set
 
 #
 # Security options
@@ -1245,9 +1271,12 @@
 #
 # Library routines
 #
+CONFIG_BITREVERSE=y
 CONFIG_CRC_CCITT=m
 # CONFIG_CRC16 is not set
 CONFIG_CRC32=y
 # CONFIG_LIBCRC32C is not set
 CONFIG_ZLIB_INFLATE=y
 CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
diff --git a/arch/blackfin/defconfig b/arch/blackfin/defconfig
deleted file mode 100644
index a513fbe..0000000
--- a/arch/blackfin/defconfig
+++ /dev/null
@@ -1,1327 +0,0 @@
-#
-# Automatically generated make config: don't edit
-# Linux kernel version: 2.6.20.4
-#
-# CONFIG_MMU is not set
-# CONFIG_FPU is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_BLACKFIN=y
-CONFIG_BFIN=y
-CONFIG_SEMAPHORE_SLEEPERS=y
-CONFIG_GENERIC_FIND_NEXT_BIT=y
-CONFIG_GENERIC_HWEIGHT=y
-CONFIG_GENERIC_HARDIRQS=y
-CONFIG_GENERIC_IRQ_PROBE=y
-# CONFIG_GENERIC_TIME is not set
-CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_FORCE_MAX_ZONEORDER=14
-CONFIG_IRQCHIP_DEMUX_GPIO=y
-CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-CONFIG_BROKEN_ON_SMP=y
-CONFIG_INIT_ENV_ARG_LIMIT=32
-
-#
-# General setup
-#
-CONFIG_LOCALVERSION=""
-CONFIG_LOCALVERSION_AUTO=y
-CONFIG_SYSVIPC=y
-# CONFIG_IPC_NS is not set
-# CONFIG_POSIX_MQUEUE is not set
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_UTS_NS is not set
-# CONFIG_AUDIT is not set
-# CONFIG_IKCONFIG is not set
-CONFIG_SYSFS_DEPRECATED=y
-# CONFIG_RELAY is not set
-CONFIG_INITRAMFS_SOURCE=""
-# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
-CONFIG_SYSCTL=y
-CONFIG_EMBEDDED=y
-CONFIG_UID16=y
-CONFIG_SYSCTL_SYSCALL=y
-CONFIG_KALLSYMS=y
-# CONFIG_KALLSYMS_EXTRA_PASS is not set
-CONFIG_HOTPLUG=y
-CONFIG_PRINTK=y
-CONFIG_BUG=y
-CONFIG_ELF_CORE=y
-CONFIG_BASE_FULL=y
-CONFIG_FUTEX=y
-CONFIG_EPOLL=y
-CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
-# CONFIG_LIMIT_PAGECACHE is not set
-CONFIG_BUDDY=y
-# CONFIG_NP2 is not set
-CONFIG_SLAB=y
-CONFIG_VM_EVENT_COUNTERS=y
-CONFIG_RT_MUTEXES=y
-CONFIG_TINY_SHMEM=y
-CONFIG_BASE_SMALL=0
-# CONFIG_SLOB is not set
-
-#
-# Loadable module support
-#
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_MODULE_FORCE_UNLOAD is not set
-# CONFIG_MODVERSIONS is not set
-# CONFIG_MODULE_SRCVERSION_ALL is not set
-CONFIG_KMOD=y
-
-#
-# Block layer
-#
-CONFIG_BLOCK=y
-# CONFIG_LBD is not set
-# CONFIG_BLK_DEV_IO_TRACE is not set
-# CONFIG_LSF is not set
-
-#
-# IO Schedulers
-#
-CONFIG_IOSCHED_NOOP=y
-CONFIG_IOSCHED_AS=y
-# CONFIG_IOSCHED_DEADLINE is not set
-CONFIG_IOSCHED_CFQ=y
-CONFIG_DEFAULT_AS=y
-# CONFIG_DEFAULT_DEADLINE is not set
-# CONFIG_DEFAULT_CFQ is not set
-# CONFIG_DEFAULT_NOOP is not set
-CONFIG_DEFAULT_IOSCHED="anticipatory"
-# CONFIG_PREEMPT_NONE is not set
-CONFIG_PREEMPT_VOLUNTARY=y
-# CONFIG_PREEMPT is not set
-
-#
-# Blackfin Processor Options
-#
-
-#
-# Processor and Board Settings
-#
-# CONFIG_BF531 is not set
-# CONFIG_BF532 is not set
-# CONFIG_BF533 is not set
-# CONFIG_BF534 is not set
-# CONFIG_BF536 is not set
-CONFIG_BF537=y
-# CONFIG_BF561 is not set
-CONFIG_BF_REV_0_2=y
-# CONFIG_BF_REV_0_3 is not set
-# CONFIG_BF_REV_0_4 is not set
-# CONFIG_BF_REV_0_5 is not set
-CONFIG_BFIN_SINGLE_CORE=y
-# CONFIG_BFIN533_EZKIT is not set
-# CONFIG_BFIN533_STAMP is not set
-CONFIG_BFIN537_STAMP=y
-# CONFIG_BFIN533_BLUETECHNIX_CM is not set
-# CONFIG_BFIN537_BLUETECHNIX_CM is not set
-# CONFIG_BFIN561_BLUETECHNIX_CM is not set
-# CONFIG_BFIN561_EZKIT is not set
-# CONFIG_PNAV10 is not set
-# CONFIG_GENERIC_BOARD is not set
-CONFIG_MEM_MT48LC32M8A2_75=y
-CONFIG_IRQ_PLL_WAKEUP=7
-
-#
-# BF537 Specific Configuration
-#
-
-#
-# PORT F/G Selection
-#
-CONFIG_BF537_PORT_F=y
-# CONFIG_BF537_PORT_G is not set
-# CONFIG_BF537_PORT_H is not set
-
-#
-# Interrupt Priority Assignment
-#
-
-#
-# Priority
-#
-CONFIG_IRQ_DMA_ERROR=7
-CONFIG_IRQ_ERROR=7
-CONFIG_IRQ_RTC=8
-CONFIG_IRQ_PPI=8
-CONFIG_IRQ_SPORT0_RX=9
-CONFIG_IRQ_SPORT0_TX=9
-CONFIG_IRQ_SPORT1_RX=9
-CONFIG_IRQ_SPORT1_TX=9
-CONFIG_IRQ_TWI=10
-CONFIG_IRQ_SPI=10
-CONFIG_IRQ_UART0_RX=10
-CONFIG_IRQ_UART0_TX=10
-CONFIG_IRQ_UART1_RX=10
-CONFIG_IRQ_UART1_TX=10
-CONFIG_IRQ_CAN_RX=11
-CONFIG_IRQ_CAN_TX=11
-CONFIG_IRQ_MAC_RX=11
-CONFIG_IRQ_MAC_TX=11
-CONFIG_IRQ_TMR0=12
-CONFIG_IRQ_TMR1=12
-CONFIG_IRQ_TMR2=12
-CONFIG_IRQ_TMR3=12
-CONFIG_IRQ_TMR4=12
-CONFIG_IRQ_TMR5=12
-CONFIG_IRQ_TMR6=12
-CONFIG_IRQ_TMR7=12
-CONFIG_IRQ_PROG_INTA=12
-CONFIG_IRQ_PORTG_INTB=12
-CONFIG_IRQ_MEM_DMA0=13
-CONFIG_IRQ_MEM_DMA1=13
-CONFIG_IRQ_WATCH=13
-
-#
-# Board customizations
-#
-# CONFIG_CMDLINE_BOOL is not set
-
-#
-# Board Setup
-#
-CONFIG_CLKIN_HZ=25000000
-CONFIG_MEM_SIZE=64
-CONFIG_MEM_ADD_WIDTH=10
-CONFIG_BOOT_LOAD=0x1000
-
-#
-# Console UART Setup
-#
-# CONFIG_BAUD_9600 is not set
-# CONFIG_BAUD_19200 is not set
-# CONFIG_BAUD_38400 is not set
-CONFIG_BAUD_57600=y
-# CONFIG_BAUD_115200 is not set
-CONFIG_BAUD_NO_PARITY=y
-# CONFIG_BAUD_PARITY is not set
-CONFIG_BAUD_1_STOPBIT=y
-# CONFIG_BAUD_2_STOPBIT is not set
-
-#
-# Blackfin Kernel Optimizations
-#
-
-#
-# Timer Tick
-#
-# CONFIG_HZ_100 is not set
-CONFIG_HZ_250=y
-# CONFIG_HZ_300 is not set
-# CONFIG_HZ_1000 is not set
-CONFIG_HZ=250
-
-#
-# Memory Optimizations
-#
-CONFIG_I_ENTRY_L1=y
-CONFIG_EXCPT_IRQ_SYSC_L1=y
-CONFIG_DO_IRQ_L1=y
-CONFIG_CORE_TIMER_IRQ_L1=y
-CONFIG_IDLE_L1=y
-CONFIG_SCHEDULE_L1=y
-CONFIG_ARITHMETIC_OPS_L1=y
-CONFIG_ACCESS_OK_L1=y
-CONFIG_MEMSET_L1=y
-CONFIG_MEMCPY_L1=y
-CONFIG_SYS_BFIN_SPINLOCK_L1=y
-# CONFIG_IP_CHECKSUM_L1 is not set
-# CONFIG_SYSCALL_TAB_L1 is not set
-# CONFIG_CPLB_SWITCH_TAB_L1 is not set
-CONFIG_RAMKERNEL=y
-# CONFIG_ROMKERNEL is not set
-CONFIG_SELECT_MEMORY_MODEL=y
-CONFIG_FLATMEM_MANUAL=y
-# CONFIG_DISCONTIGMEM_MANUAL is not set
-# CONFIG_SPARSEMEM_MANUAL is not set
-CONFIG_FLATMEM=y
-CONFIG_FLAT_NODE_MEM_MAP=y
-# CONFIG_SPARSEMEM_STATIC is not set
-CONFIG_SPLIT_PTLOCK_CPUS=4
-# CONFIG_RESOURCES_64BIT is not set
-CONFIG_LARGE_ALLOCS=y
-CONFIG_BFIN_DMA_5XX=y
-# CONFIG_DMA_UNCACHED_2M is not set
-CONFIG_DMA_UNCACHED_1M=y
-# CONFIG_DMA_UNCACHED_NONE is not set
-
-#
-# Cache Support
-#
-CONFIG_BLKFIN_CACHE=y
-CONFIG_BLKFIN_DCACHE=y
-# CONFIG_BLKFIN_DCACHE_BANKA is not set
-# CONFIG_BLKFIN_CACHE_LOCK is not set
-# CONFIG_BLKFIN_WB is not set
-CONFIG_BLKFIN_WT=y
-CONFIG_L1_MAX_PIECE=16
-
-#
-# Clock Settings
-#
-# CONFIG_BFIN_KERNEL_CLOCK is not set
-
-#
-# Asynchonous Memory Configuration
-#
-
-#
-# EBIU_AMBCTL Global Control
-#
-CONFIG_C_AMCKEN=y
-CONFIG_C_CDPRIO=y
-# CONFIG_C_AMBEN is not set
-# CONFIG_C_AMBEN_B0 is not set
-# CONFIG_C_AMBEN_B0_B1 is not set
-# CONFIG_C_AMBEN_B0_B1_B2 is not set
-CONFIG_C_AMBEN_ALL=y
-
-#
-# EBIU_AMBCTL Control
-#
-CONFIG_BANK_0=0x7BB0
-CONFIG_BANK_1=0x7BB0
-CONFIG_BANK_2=0x7BB0
-CONFIG_BANK_3=0x99B3
-
-#
-# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
-#
-# CONFIG_PCI is not set
-
-#
-# PCCARD (PCMCIA/CardBus) support
-#
-# CONFIG_PCCARD is not set
-
-#
-# PCI Hotplug Support
-#
-
-#
-# Executable file formats
-#
-CONFIG_BINFMT_ELF_FDPIC=y
-CONFIG_BINFMT_FLAT=y
-CONFIG_BINFMT_ZFLAT=y
-# CONFIG_BINFMT_SHARED_FLAT is not set
-# CONFIG_BINFMT_MISC is not set
-
-#
-# Power management options
-#
-CONFIG_PM=y
-CONFIG_PM_LEGACY=y
-# CONFIG_PM_DEBUG is not set
-# CONFIG_PM_SYSFS_DEPRECATED is not set
-CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR=y
-# CONFIG_PM_WAKEUP_BY_GPIO is not set
-# CONFIG_PM_WAKEUP_GPIO_API is not set
-CONFIG_PM_WAKEUP_SIC_IWR=0x80000000
-
-#
-# CPU Frequency scaling
-#
-# CONFIG_CPU_FREQ is not set
-
-#
-# Networking
-#
-CONFIG_NET=y
-
-#
-# Networking options
-#
-# CONFIG_NETDEBUG is not set
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_UNIX=y
-CONFIG_XFRM=y
-# CONFIG_XFRM_USER is not set
-# CONFIG_XFRM_SUB_POLICY is not set
-# CONFIG_NET_KEY is not set
-CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
-# CONFIG_IP_ADVANCED_ROUTER is not set
-CONFIG_IP_FIB_HASH=y
-CONFIG_IP_PNP=y
-# CONFIG_IP_PNP_DHCP is not set
-# CONFIG_IP_PNP_BOOTP is not set
-# CONFIG_IP_PNP_RARP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_ARPD is not set
-CONFIG_SYN_COOKIES=y
-# CONFIG_INET_AH is not set
-# CONFIG_INET_ESP is not set
-# CONFIG_INET_IPCOMP is not set
-# CONFIG_INET_XFRM_TUNNEL is not set
-# CONFIG_INET_TUNNEL is not set
-CONFIG_INET_XFRM_MODE_TRANSPORT=y
-CONFIG_INET_XFRM_MODE_TUNNEL=y
-CONFIG_INET_XFRM_MODE_BEET=y
-CONFIG_INET_DIAG=y
-CONFIG_INET_TCP_DIAG=y
-# CONFIG_TCP_CONG_ADVANCED is not set
-CONFIG_TCP_CONG_CUBIC=y
-CONFIG_DEFAULT_TCP_CONG="cubic"
-# CONFIG_TCP_MD5SIG is not set
-# CONFIG_IPV6 is not set
-# CONFIG_INET6_XFRM_TUNNEL is not set
-# CONFIG_INET6_TUNNEL is not set
-# CONFIG_NETLABEL is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETFILTER is not set
-
-#
-# DCCP Configuration (EXPERIMENTAL)
-#
-# CONFIG_IP_DCCP is not set
-
-#
-# SCTP Configuration (EXPERIMENTAL)
-#
-# CONFIG_IP_SCTP is not set
-
-#
-# TIPC Configuration (EXPERIMENTAL)
-#
-# CONFIG_TIPC is not set
-# CONFIG_ATM is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_VLAN_8021Q is not set
-# CONFIG_DECNET is not set
-# CONFIG_LLC2 is not set
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Network testing
-#
-# CONFIG_NET_PKTGEN is not set
-# CONFIG_HAMRADIO is not set
-CONFIG_IRDA=m
-
-#
-# IrDA protocols
-#
-CONFIG_IRLAN=m
-CONFIG_IRCOMM=m
-# CONFIG_IRDA_ULTRA is not set
-
-#
-# IrDA options
-#
-CONFIG_IRDA_CACHE_LAST_LSAP=y
-# CONFIG_IRDA_FAST_RR is not set
-# CONFIG_IRDA_DEBUG is not set
-
-#
-# Infrared-port device drivers
-#
-
-#
-# SIR device drivers
-#
-CONFIG_IRTTY_SIR=m
-
-#
-# Dongle support
-#
-# CONFIG_DONGLE is not set
-
-#
-# Old SIR device drivers
-#
-# CONFIG_IRPORT_SIR is not set
-
-#
-# Old Serial dongle support
-#
-
-#
-# FIR device drivers
-#
-# CONFIG_BT is not set
-# CONFIG_IEEE80211 is not set
-
-#
-# Device Drivers
-#
-
-#
-# Generic Driver Options
-#
-CONFIG_STANDALONE=y
-CONFIG_PREVENT_FIRMWARE_BUILD=y
-# CONFIG_FW_LOADER is not set
-# CONFIG_SYS_HYPERVISOR is not set
-
-#
-# Connector - unified userspace <-> kernelspace linker
-#
-# CONFIG_CONNECTOR is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-CONFIG_MTD=y
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_CONCAT is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_CMDLINE_PARTS is not set
-
-#
-# User Modules And Translation Layers
-#
-CONFIG_MTD_CHAR=m
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_FTL is not set
-# CONFIG_NFTL is not set
-# CONFIG_INFTL is not set
-# CONFIG_RFD_FTL is not set
-# CONFIG_SSFDC is not set
-
-#
-# RAM/ROM/Flash chip drivers
-#
-# CONFIG_MTD_CFI is not set
-CONFIG_MTD_JEDECPROBE=m
-CONFIG_MTD_GEN_PROBE=m
-# CONFIG_MTD_CFI_ADV_OPTIONS is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-# CONFIG_MTD_CFI_INTELEXT is not set
-# CONFIG_MTD_CFI_AMDSTD is not set
-# CONFIG_MTD_CFI_STAA is not set
-CONFIG_MTD_MW320D=m
-CONFIG_MTD_RAM=y
-CONFIG_MTD_ROM=m
-# CONFIG_MTD_ABSENT is not set
-# CONFIG_MTD_OBSOLETE_CHIPS is not set
-
-#
-# Mapping drivers for chip access
-#
-CONFIG_MTD_COMPLEX_MAPPINGS=y
-# CONFIG_MTD_PHYSMAP is not set
-CONFIG_MTD_BF5xx=m
-CONFIG_BFIN_FLASH_SIZE=0x400000
-CONFIG_EBIU_FLASH_BASE=0x20000000
-
-#
-# FLASH_EBIU_AMBCTL Control
-#
-CONFIG_BFIN_FLASH_BANK_0=0x7BB0
-CONFIG_BFIN_FLASH_BANK_1=0x7BB0
-CONFIG_BFIN_FLASH_BANK_2=0x7BB0
-CONFIG_BFIN_FLASH_BANK_3=0x7BB0
-CONFIG_MTD_UCLINUX=y
-# CONFIG_MTD_PLATRAM is not set
-
-#
-# Self-contained MTD device drivers
-#
-# CONFIG_MTD_DATAFLASH is not set
-# CONFIG_MTD_M25P80 is not set
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_MTD_PHRAM is not set
-# CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_BLOCK2MTD is not set
-
-#
-# Disk-On-Chip Device Drivers
-#
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-
-#
-# NAND Flash Device Drivers
-#
-CONFIG_MTD_NAND=m
-# CONFIG_MTD_NAND_VERIFY_WRITE is not set
-# CONFIG_MTD_NAND_ECC_SMC is not set
-CONFIG_MTD_NAND_BFIN=m
-CONFIG_BFIN_NAND_BASE=0x20212000
-CONFIG_BFIN_NAND_CLE=2
-CONFIG_BFIN_NAND_ALE=1
-CONFIG_BFIN_NAND_READY=3
-CONFIG_MTD_NAND_IDS=m
-# CONFIG_MTD_NAND_DISKONCHIP is not set
-# CONFIG_MTD_NAND_NANDSIM is not set
-
-#
-# OneNAND Flash Device Drivers
-#
-# CONFIG_MTD_ONENAND is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Plug and Play support
-#
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_COW_COMMON is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-CONFIG_BLK_DEV_RAM=y
-CONFIG_BLK_DEV_RAM_COUNT=16
-CONFIG_BLK_DEV_RAM_SIZE=4096
-CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_BLK_DEV_INITRD is not set
-# CONFIG_CDROM_PKTCDVD is not set
-# CONFIG_ATA_OVER_ETH is not set
-
-#
-# Misc devices
-#
-# CONFIG_TIFM_CORE is not set
-
-#
-# ATA/ATAPI/MFM/RLL support
-#
-# CONFIG_IDE is not set
-
-#
-# SCSI device support
-#
-# CONFIG_RAID_ATTRS is not set
-# CONFIG_SCSI is not set
-# CONFIG_SCSI_NETLINK is not set
-
-#
-# Serial ATA (prod) and Parallel ATA (experimental) drivers
-#
-# CONFIG_ATA is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-
-#
-# Fusion MPT device support
-#
-# CONFIG_FUSION is not set
-
-#
-# IEEE 1394 (FireWire) support
-#
-
-#
-# I2O device support
-#
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-
-#
-# PHY device support
-#
-# CONFIG_PHYLIB is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-CONFIG_MII=y
-# CONFIG_SMC91X is not set
-CONFIG_BFIN_MAC=y
-CONFIG_BFIN_MAC_USE_L1=y
-CONFIG_BFIN_TX_DESC_NUM=10
-CONFIG_BFIN_RX_DESC_NUM=20
-# CONFIG_BFIN_MAC_RMII is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-
-#
-# Ethernet (10000 Mbit)
-#
-
-#
-# Token Ring devices
-#
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-# CONFIG_SHAPER is not set
-# CONFIG_NETCONSOLE is not set
-# CONFIG_NETPOLL is not set
-# CONFIG_NET_POLL_CONTROLLER is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# Telephony Support
-#
-# CONFIG_PHONE is not set
-
-#
-# Input device support
-#
-CONFIG_INPUT=y
-# CONFIG_INPUT_FF_MEMLESS is not set
-
-#
-# Userland interfaces
-#
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_TSDEV is not set
-CONFIG_INPUT_EVDEV=m
-# CONFIG_INPUT_EVBUG is not set
-
-#
-# Input Device Drivers
-#
-# CONFIG_INPUT_KEYBOARD is not set
-# CONFIG_INPUT_MOUSE is not set
-# CONFIG_INPUT_JOYSTICK is not set
-# CONFIG_INPUT_TOUCHSCREEN is not set
-CONFIG_INPUT_MISC=y
-# CONFIG_INPUT_UINPUT is not set
-# CONFIG_BF53X_PFBUTTONS is not set
-CONFIG_TWI_KEYPAD=m
-CONFIG_BFIN_TWIKEYPAD_IRQ_PFX=72
-
-#
-# Hardware I/O ports
-#
-# CONFIG_SERIO is not set
-# CONFIG_GAMEPORT is not set
-
-#
-# Character devices
-#
-# CONFIG_AD9960 is not set
-# CONFIG_SPI_ADC_BF533 is not set
-# CONFIG_BF533_PFLAGS is not set
-# CONFIG_BF5xx_PPIFCD is not set
-# CONFIG_BF5xx_TIMERS is not set
-# CONFIG_BF5xx_PPI is not set
-CONFIG_BFIN_SPORT=y
-# CONFIG_BFIN_TIMER_LATENCY is not set
-CONFIG_TWI_LCD=m
-CONFIG_TWI_LCD_SLAVE_ADDR=34
-# CONFIG_AD5304 is not set
-# CONFIG_VT is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-
-#
-# Serial drivers
-#
-# CONFIG_SERIAL_8250 is not set
-
-#
-# Non-8250 serial port support
-#
-CONFIG_SERIAL_BFIN=y
-CONFIG_SERIAL_BFIN_CONSOLE=y
-CONFIG_SERIAL_BFIN_DMA=y
-# CONFIG_SERIAL_BFIN_PIO is not set
-CONFIG_SERIAL_BFIN_UART0=y
-# CONFIG_BFIN_UART0_CTSRTS is not set
-# CONFIG_SERIAL_BFIN_UART1 is not set
-CONFIG_SERIAL_CORE=y
-CONFIG_SERIAL_CORE_CONSOLE=y
-# CONFIG_SERIAL_BFIN_SPORT is not set
-CONFIG_UNIX98_PTYS=y
-# CONFIG_LEGACY_PTYS is not set
-
-#
-# CAN, the car bus and industrial fieldbus
-#
-CONFIG_CAN4LINUX=y
-
-#
-# linux embedded drivers
-#
-# CONFIG_CAN_MCF5282 is not set
-# CONFIG_CAN_UNCTWINCAN is not set
-CONFIG_CAN_BLACKFIN=m
-
-#
-# IPMI
-#
-# CONFIG_IPMI_HANDLER is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-CONFIG_HW_RANDOM=y
-# CONFIG_GEN_RTC is not set
-CONFIG_BLACKFIN_DPMC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_RAW_DRIVER is not set
-
-#
-# TPM devices
-#
-# CONFIG_TCG_TPM is not set
-
-#
-# I2C support
-#
-CONFIG_I2C=m
-CONFIG_I2C_CHARDEV=m
-
-#
-# I2C Algorithms
-#
-# CONFIG_I2C_ALGOBIT is not set
-# CONFIG_I2C_ALGOPCF is not set
-# CONFIG_I2C_ALGOPCA is not set
-
-#
-# I2C Hardware Bus support
-#
-# CONFIG_I2C_BLACKFIN_GPIO is not set
-# CONFIG_I2C_BLACKFIN_TWI is not set
-# CONFIG_I2C_OCORES is not set
-# CONFIG_I2C_PARPORT_LIGHT is not set
-# CONFIG_I2C_STUB is not set
-# CONFIG_I2C_PCA_ISA is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_DS1337 is not set
-# CONFIG_SENSORS_DS1374 is not set
-CONFIG_SENSORS_AD5252=m
-# CONFIG_SENSORS_EEPROM is not set
-# CONFIG_SENSORS_PCF8574 is not set
-# CONFIG_SENSORS_PCF8575 is not set
-# CONFIG_SENSORS_PCA9543 is not set
-# CONFIG_SENSORS_PCA9539 is not set
-# CONFIG_SENSORS_PCF8591 is not set
-# CONFIG_SENSORS_MAX6875 is not set
-# CONFIG_I2C_DEBUG_CORE is not set
-# CONFIG_I2C_DEBUG_ALGO is not set
-# CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
-
-#
-# SPI support
-#
-CONFIG_SPI=y
-CONFIG_SPI_MASTER=y
-
-#
-# SPI Master Controller Drivers
-#
-# CONFIG_SPI_BITBANG is not set
-
-#
-# SPI Protocol Masters
-#
-CONFIG_SPI_BFIN=y
-
-#
-# Dallas's 1-wire bus
-#
-# CONFIG_W1 is not set
-
-#
-# Hardware Monitoring support
-#
-CONFIG_HWMON=y
-# CONFIG_HWMON_VID is not set
-# CONFIG_SENSORS_ABITUGURU is not set
-# CONFIG_SENSORS_ADM1021 is not set
-# CONFIG_SENSORS_ADM1025 is not set
-# CONFIG_SENSORS_ADM1026 is not set
-# CONFIG_SENSORS_ADM1031 is not set
-# CONFIG_SENSORS_ADM9240 is not set
-# CONFIG_SENSORS_ASB100 is not set
-# CONFIG_SENSORS_ATXP1 is not set
-# CONFIG_SENSORS_DS1621 is not set
-# CONFIG_SENSORS_F71805F is not set
-# CONFIG_SENSORS_FSCHER is not set
-# CONFIG_SENSORS_FSCPOS is not set
-# CONFIG_SENSORS_GL518SM is not set
-# CONFIG_SENSORS_GL520SM is not set
-# CONFIG_SENSORS_IT87 is not set
-# CONFIG_SENSORS_LM63 is not set
-# CONFIG_SENSORS_LM70 is not set
-# CONFIG_SENSORS_LM75 is not set
-# CONFIG_SENSORS_LM77 is not set
-# CONFIG_SENSORS_LM78 is not set
-# CONFIG_SENSORS_LM80 is not set
-# CONFIG_SENSORS_LM83 is not set
-# CONFIG_SENSORS_LM85 is not set
-# CONFIG_SENSORS_LM87 is not set
-# CONFIG_SENSORS_LM90 is not set
-# CONFIG_SENSORS_LM92 is not set
-# CONFIG_SENSORS_MAX1619 is not set
-# CONFIG_SENSORS_PC87360 is not set
-# CONFIG_SENSORS_PC87427 is not set
-# CONFIG_SENSORS_SMSC47M1 is not set
-# CONFIG_SENSORS_SMSC47M192 is not set
-# CONFIG_SENSORS_SMSC47B397 is not set
-# CONFIG_SENSORS_VT1211 is not set
-# CONFIG_SENSORS_W83781D is not set
-# CONFIG_SENSORS_W83791D is not set
-# CONFIG_SENSORS_W83792D is not set
-# CONFIG_SENSORS_W83793 is not set
-# CONFIG_SENSORS_W83L785TS is not set
-# CONFIG_SENSORS_W83627HF is not set
-# CONFIG_SENSORS_W83627EHF is not set
-# CONFIG_HWMON_DEBUG_CHIP is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# Digital Video Broadcasting Devices
-#
-# CONFIG_DVB is not set
-
-#
-# Graphics support
-#
-CONFIG_FIRMWARE_EDID=y
-CONFIG_FB=m
-CONFIG_FB_CFB_FILLRECT=m
-CONFIG_FB_CFB_COPYAREA=m
-CONFIG_FB_CFB_IMAGEBLIT=m
-# CONFIG_FB_MACMODES is not set
-# CONFIG_FB_BACKLIGHT is not set
-# CONFIG_FB_MODE_HELPERS is not set
-# CONFIG_FB_TILEBLITTING is not set
-CONFIG_FB_BFIN_7171=m
-CONFIG_FB_BFIN_7393=m
-CONFIG_NTSC=y
-# CONFIG_PAL is not set
-# CONFIG_NTSC_640x480 is not set
-# CONFIG_PAL_640x480 is not set
-# CONFIG_NTSC_YCBCR is not set
-# CONFIG_PAL_YCBCR is not set
-CONFIG_ADV7393_1XMEM=y
-# CONFIG_ADV7393_2XMEM is not set
-# CONFIG_FB_S1D13XXX is not set
-# CONFIG_FB_VIRTUAL is not set
-
-#
-# Logo configuration
-#
-# CONFIG_LOGO is not set
-CONFIG_BACKLIGHT_LCD_SUPPORT=y
-CONFIG_BACKLIGHT_CLASS_DEVICE=m
-CONFIG_BACKLIGHT_DEVICE=y
-CONFIG_LCD_CLASS_DEVICE=m
-CONFIG_LCD_DEVICE=y
-
-#
-# Sound
-#
-CONFIG_SOUND=m
-
-#
-# Advanced Linux Sound Architecture
-#
-CONFIG_SND=m
-CONFIG_SND_TIMER=m
-CONFIG_SND_PCM=m
-# CONFIG_SND_SEQUENCER is not set
-CONFIG_SND_OSSEMUL=y
-CONFIG_SND_MIXER_OSS=m
-CONFIG_SND_PCM_OSS=m
-CONFIG_SND_PCM_OSS_PLUGINS=y
-# CONFIG_SND_DYNAMIC_MINORS is not set
-CONFIG_SND_SUPPORT_OLD_API=y
-CONFIG_SND_VERBOSE_PROCFS=y
-# CONFIG_SND_VERBOSE_PRINTK is not set
-# CONFIG_SND_DEBUG is not set
-
-#
-# Generic devices
-#
-# CONFIG_SND_DUMMY is not set
-# CONFIG_SND_MTPAV is not set
-# CONFIG_SND_SERIAL_U16550 is not set
-# CONFIG_SND_MPU401 is not set
-
-#
-# Open Sound System
-#
-# CONFIG_SOUND_PRIME is not set
-
-#
-# HID Devices
-#
-CONFIG_HID=y
-
-#
-# USB support
-#
-CONFIG_USB_ARCH_HAS_HCD=y
-# CONFIG_USB_ARCH_HAS_OHCI is not set
-# CONFIG_USB_ARCH_HAS_EHCI is not set
-# CONFIG_USB is not set
-
-#
-# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
-#
-
-#
-# USB Gadget Support
-#
-# CONFIG_USB_GADGET is not set
-
-#
-# MMC/SD Card support
-#
-# CONFIG_SPI_MMC is not set
-# CONFIG_MMC is not set
-
-#
-# LED devices
-#
-# CONFIG_NEW_LEDS is not set
-
-#
-# LED drivers
-#
-
-#
-# LED Triggers
-#
-
-#
-# InfiniBand support
-#
-
-#
-# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
-#
-
-#
-# Real Time Clock
-#
-CONFIG_RTC_LIB=y
-CONFIG_RTC_CLASS=y
-CONFIG_RTC_HCTOSYS=y
-CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
-# CONFIG_RTC_DEBUG is not set
-
-#
-# RTC interfaces
-#
-CONFIG_RTC_INTF_SYSFS=y
-CONFIG_RTC_INTF_PROC=y
-CONFIG_RTC_INTF_DEV=y
-# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
-
-#
-# RTC drivers
-#
-# CONFIG_RTC_DRV_X1205 is not set
-# CONFIG_RTC_DRV_DS1307 is not set
-# CONFIG_RTC_DRV_DS1553 is not set
-# CONFIG_RTC_DRV_ISL1208 is not set
-# CONFIG_RTC_DRV_DS1672 is not set
-# CONFIG_RTC_DRV_DS1742 is not set
-# CONFIG_RTC_DRV_PCF8563 is not set
-# CONFIG_RTC_DRV_PCF8583 is not set
-# CONFIG_RTC_DRV_RS5C348 is not set
-# CONFIG_RTC_DRV_RS5C372 is not set
-# CONFIG_RTC_DRV_M48T86 is not set
-# CONFIG_RTC_DRV_TEST is not set
-# CONFIG_RTC_DRV_MAX6902 is not set
-# CONFIG_RTC_DRV_V3020 is not set
-CONFIG_RTC_DRV_BFIN=y
-
-#
-# DMA Engine support
-#
-# CONFIG_DMA_ENGINE is not set
-
-#
-# DMA Clients
-#
-
-#
-# DMA Devices
-#
-
-#
-# Virtualization
-#
-
-#
-# PBX support
-#
-# CONFIG_PBX is not set
-
-#
-# File systems
-#
-CONFIG_EXT2_FS=y
-CONFIG_EXT2_FS_XATTR=y
-# CONFIG_EXT2_FS_POSIX_ACL is not set
-# CONFIG_EXT2_FS_SECURITY is not set
-# CONFIG_EXT3_FS is not set
-# CONFIG_EXT4DEV_FS is not set
-CONFIG_FS_MBCACHE=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_JFS_FS is not set
-# CONFIG_FS_POSIX_ACL is not set
-# CONFIG_XFS_FS is not set
-# CONFIG_GFS2_FS is not set
-# CONFIG_OCFS2_FS is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_INOTIFY=y
-CONFIG_INOTIFY_USER=y
-# CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_FUSE_FS is not set
-
-#
-# CD-ROM/DVD Filesystems
-#
-# CONFIG_ISO9660_FS is not set
-# CONFIG_UDF_FS is not set
-
-#
-# DOS/FAT/NT Filesystems
-#
-# CONFIG_MSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_NTFS_FS is not set
-
-#
-# Pseudo filesystems
-#
-CONFIG_PROC_FS=y
-CONFIG_PROC_SYSCTL=y
-CONFIG_SYSFS=y
-# CONFIG_TMPFS is not set
-# CONFIG_HUGETLB_PAGE is not set
-CONFIG_RAMFS=y
-# CONFIG_CONFIGFS_FS is not set
-
-#
-# Miscellaneous filesystems
-#
-# CONFIG_ADFS_FS is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_HFSPLUS_FS is not set
-# CONFIG_BEFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_EFS_FS is not set
-CONFIG_YAFFS_FS=m
-CONFIG_YAFFS_YAFFS1=y
-# CONFIG_YAFFS_DOES_ECC is not set
-CONFIG_YAFFS_YAFFS2=y
-CONFIG_YAFFS_AUTO_YAFFS2=y
-# CONFIG_YAFFS_DISABLE_LAZY_LOAD is not set
-CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS=10
-# CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
-# CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
-CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
-CONFIG_JFFS2_FS=m
-CONFIG_JFFS2_FS_DEBUG=0
-CONFIG_JFFS2_FS_WRITEBUFFER=y
-# CONFIG_JFFS2_SUMMARY is not set
-# CONFIG_JFFS2_FS_XATTR is not set
-# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
-CONFIG_JFFS2_ZLIB=y
-CONFIG_JFFS2_RTIME=y
-# CONFIG_JFFS2_RUBIN is not set
-# CONFIG_CRAMFS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_HPFS_FS is not set
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_SYSV_FS is not set
-# CONFIG_UFS_FS is not set
-
-#
-# Network File Systems
-#
-CONFIG_NFS_FS=m
-CONFIG_NFS_V3=y
-# CONFIG_NFS_V3_ACL is not set
-# CONFIG_NFS_V4 is not set
-# CONFIG_NFS_DIRECTIO is not set
-# CONFIG_NFSD is not set
-CONFIG_LOCKD=m
-CONFIG_LOCKD_V4=y
-CONFIG_NFS_COMMON=y
-CONFIG_SUNRPC=m
-# CONFIG_RPCSEC_GSS_KRB5 is not set
-# CONFIG_RPCSEC_GSS_SPKM3 is not set
-CONFIG_SMB_FS=m
-# CONFIG_SMB_NLS_DEFAULT is not set
-# CONFIG_CIFS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_CODA_FS is not set
-# CONFIG_AFS_FS is not set
-# CONFIG_9P_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS=m
-CONFIG_NLS_DEFAULT="iso8859-1"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1250 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ASCII is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Distributed Lock Manager
-#
-# CONFIG_DLM is not set
-
-#
-# Profiling support
-#
-# CONFIG_PROFILING is not set
-
-#
-# Kernel hacking
-#
-# CONFIG_PRINTK_TIME is not set
-CONFIG_ENABLE_MUST_CHECK=y
-# CONFIG_MAGIC_SYSRQ is not set
-# CONFIG_UNUSED_SYMBOLS is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_HEADERS_CHECK is not set
-# CONFIG_DEBUG_KERNEL is not set
-CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_DEBUG_BUGVERBOSE is not set
-# CONFIG_DEBUG_SERIAL_EARLY_INIT is not set
-CONFIG_DEBUG_HUNT_FOR_ZERO=y
-# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
-CONFIG_CPLB_INFO=y
-CONFIG_ACCESS_CHECK=y
-
-#
-# Security options
-#
-# CONFIG_KEYS is not set
-CONFIG_SECURITY=y
-# CONFIG_SECURITY_NETWORK is not set
-CONFIG_SECURITY_CAPABILITIES=y
-
-#
-# Cryptographic options
-#
-# CONFIG_CRYPTO is not set
-
-#
-# Library routines
-#
-CONFIG_BITREVERSE=y
-CONFIG_CRC_CCITT=m
-# CONFIG_CRC16 is not set
-CONFIG_CRC32=y
-# CONFIG_LIBCRC32C is not set
-CONFIG_ZLIB_INFLATE=y
-CONFIG_ZLIB_DEFLATE=m
-CONFIG_PLIST=y
-CONFIG_IOMAP_COPY=y
diff --git a/arch/blackfin/kernel/bfin_dma_5xx.c b/arch/blackfin/kernel/bfin_dma_5xx.c
index 0ccb0dc..069a896 100644
--- a/arch/blackfin/kernel/bfin_dma_5xx.c
+++ b/arch/blackfin/kernel/bfin_dma_5xx.c
@@ -595,7 +595,7 @@
 }
 EXPORT_SYMBOL(get_dma_curr_ycount);
 
-void *_dma_memcpy(void *dest, const void *src, size_t size)
+static void *__dma_memcpy(void *dest, const void *src, size_t size)
 {
 	int direction;	/* 1 - address decrease, 0 - address increase */
 	int flag_align;	/* 1 - address aligned,  0 - address unaligned */
@@ -744,8 +744,8 @@
 	bulk = (size >> 16) << 16;
 	rest = size - bulk;
 	if (bulk)
-		_dma_memcpy(dest, src, bulk);
-	addr = _dma_memcpy(dest+bulk, src+bulk, rest);
+		__dma_memcpy(dest, src, bulk);
+	addr = __dma_memcpy(dest+bulk, src+bulk, rest);
 	return addr;
 }
 
diff --git a/arch/blackfin/kernel/bfin_gpio.c b/arch/blackfin/kernel/bfin_gpio.c
index 3f49fae..bb1f4fb 100644
--- a/arch/blackfin/kernel/bfin_gpio.c
+++ b/arch/blackfin/kernel/bfin_gpio.c
@@ -138,7 +138,7 @@
 
 inline int check_gpio(unsigned short gpio)
 {
-	if (gpio > MAX_BLACKFIN_GPIOS)
+	if (gpio >= MAX_BLACKFIN_GPIOS)
 		return -EINVAL;
 	return 0;
 }
@@ -494,19 +494,24 @@
 			gpio_bank_saved[bank].dir   = gpio_bankb[bank]->dir;
 			gpio_bank_saved[bank].edge  = gpio_bankb[bank]->edge;
 			gpio_bank_saved[bank].both  = gpio_bankb[bank]->both;
+			gpio_bank_saved[bank].reserved = reserved_map[bank];
 
 			gpio = i;
 
 			while (mask) {
 				if (mask & 1) {
-					bfin_gpio_wakeup_type(gpio, wakeup_flags_map[gpio]);
+					reserved_map[gpio_bank(gpio)] |=
+							gpio_bit(gpio);
+					bfin_gpio_wakeup_type(gpio,
+						wakeup_flags_map[gpio]);
 					set_gpio_data(gpio, 0); /*Clear*/
 				}
 				gpio++;
 				mask >>= 1;
 			}
 
-			sic_iwr |= 1 << (sic_iwr_irqs[bank] - (IRQ_CORETMR + 1));
+			sic_iwr |= 1 <<
+				(sic_iwr_irqs[bank] - (IRQ_CORETMR + 1));
 			gpio_bankb[bank]->maskb_set = wakeup_map[gpio_bank(i)];
 		}
 	}
@@ -535,6 +540,9 @@
 			gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar;
 			gpio_bankb[bank]->edge  = gpio_bank_saved[bank].edge;
 			gpio_bankb[bank]->both  = gpio_bank_saved[bank].both;
+
+			reserved_map[bank] = gpio_bank_saved[bank].reserved;
+
 		}
 
 		gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb;
diff --git a/arch/blackfin/kernel/entry.S b/arch/blackfin/kernel/entry.S
index 5880b27..65c5ba4 100644
--- a/arch/blackfin/kernel/entry.S
+++ b/arch/blackfin/kernel/entry.S
@@ -58,10 +58,12 @@
 	RESTORE_ALL_SYS
 	p0 = reti;
 	jump (p0);
+ENDPROC(_ret_from_fork)
 
 ENTRY(_sys_fork)
 	r0 = -EINVAL;
 	rts;
+ENDPROC(_sys_fork)
 
 ENTRY(_sys_vfork)
 	r0 = sp;
@@ -72,6 +74,7 @@
 	SP += 12;
 	rets = [sp++];
 	rts;
+ENDPROC(_sys_vfork)
 
 ENTRY(_sys_clone)
 	r0 = sp;
@@ -82,6 +85,7 @@
 	SP += 12;
 	rets = [sp++];
 	rts;
+ENDPROC(_sys_clone)
 
 ENTRY(_sys_rt_sigreturn)
 	r0 = sp;
@@ -92,3 +96,4 @@
 	SP += 12;
 	rets = [sp++];
 	rts;
+ENDPROC(_sys_rt_sigreturn)
diff --git a/arch/blackfin/kernel/irqchip.c b/arch/blackfin/kernel/irqchip.c
index df5bf02..80996a1 100644
--- a/arch/blackfin/kernel/irqchip.c
+++ b/arch/blackfin/kernel/irqchip.c
@@ -91,7 +91,7 @@
 }
 
 /*
- * do_IRQ handles all hardware IRQ's.  Decoded IRQs should not
+ * do_IRQ handles all hardware IRQs.  Decoded IRQs should not
  * come via this function.  Instead, they should provide their
  * own 'handler'
  */
diff --git a/arch/blackfin/kernel/setup.c b/arch/blackfin/kernel/setup.c
index 02dc743..a24fa1a 100644
--- a/arch/blackfin/kernel/setup.c
+++ b/arch/blackfin/kernel/setup.c
@@ -61,7 +61,7 @@
 EXPORT_SYMBOL(mtd_size);
 #endif
 
-char command_line[COMMAND_LINE_SIZE];
+char __initdata command_line[COMMAND_LINE_SIZE];
 
 #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
 static void generate_cpl_tables(void);
@@ -90,7 +90,7 @@
 #endif
 }
 
-void bf53x_relocate_l1_mem(void)
+void __init bf53x_relocate_l1_mem(void)
 {
 	unsigned long l1_code_length;
 	unsigned long l1_data_a_length;
@@ -205,7 +205,6 @@
 #endif
 
 #if defined(CONFIG_CMDLINE_BOOL)
-	memset(command_line, 0, sizeof(command_line));
 	strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
 	command_line[sizeof(command_line) - 1] = 0;
 #endif
@@ -213,7 +212,7 @@
 	/* Keep a copy of command line */
 	*cmdline_p = &command_line[0];
 	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
-	boot_command_line[COMMAND_LINE_SIZE - 1] = 0;
+	boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
 
 	/* setup memory defaults from the user config */
 	physical_mem_end = 0;
@@ -411,7 +410,7 @@
 subsys_initcall(topology_init);
 
 #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
-u16 lock_kernel_check(u32 start, u32 end)
+static u16 __init lock_kernel_check(u32 start, u32 end)
 {
 	if ((start <= (u32) _stext && end >= (u32) _end)
 	    || (start >= (u32) _stext && end <= (u32) _end))
@@ -471,6 +470,67 @@
 	return 0;
 }
 
+/* helper function */
+static void __fill_code_cplbtab(struct cplb_tab *t, int i,
+				u32 a_start, u32 a_end)
+{
+	if (cplb_data[i].psize) {
+		fill_cplbtab(t,
+				cplb_data[i].start,
+				cplb_data[i].end,
+				cplb_data[i].psize,
+				cplb_data[i].i_conf);
+	} else {
+#if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
+		if (i == SDRAM_KERN) {
+			fill_cplbtab(t,
+					cplb_data[i].start,
+					cplb_data[i].end,
+					SIZE_4M,
+					cplb_data[i].i_conf);
+		} else {
+#endif
+			fill_cplbtab(t,
+					cplb_data[i].start,
+					a_start,
+					SIZE_1M,
+					cplb_data[i].i_conf);
+			fill_cplbtab(t,
+					a_start,
+					a_end,
+					SIZE_4M,
+					cplb_data[i].i_conf);
+			fill_cplbtab(t, a_end,
+					cplb_data[i].end,
+					SIZE_1M,
+					cplb_data[i].i_conf);
+		}
+	}
+}
+
+static void __fill_data_cplbtab(struct cplb_tab *t, int i,
+				u32 a_start, u32 a_end)
+{
+	if (cplb_data[i].psize) {
+		fill_cplbtab(t,
+				cplb_data[i].start,
+				cplb_data[i].end,
+				cplb_data[i].psize,
+				cplb_data[i].d_conf);
+	} else {
+		fill_cplbtab(t,
+				cplb_data[i].start,
+				a_start, SIZE_1M,
+				cplb_data[i].d_conf);
+		fill_cplbtab(t, a_start,
+				a_end, SIZE_4M,
+				cplb_data[i].d_conf);
+		fill_cplbtab(t, a_end,
+				cplb_data[i].end,
+				SIZE_1M,
+				cplb_data[i].d_conf);
+	}
+}
 static void __init generate_cpl_tables(void)
 {
 
@@ -540,130 +600,78 @@
 		cplb_data[RES_MEM].i_conf = SDRAM_INON_CHBL;
 
 	for (i = ZERO_P; i <= L2_MEM; i++) {
+		if (!cplb_data[i].valid)
+			continue;
 
-		if (cplb_data[i].valid) {
+		as_1m = cplb_data[i].start % SIZE_1M;
 
-			as_1m = cplb_data[i].start % SIZE_1M;
+		/*
+		 * We need to make sure all sections are properly 1M aligned
+		 * However between Kernel Memory and the Kernel mtd section,
+		 * depending on the rootfs size, there can be overlapping
+		 * memory areas.
+		 */
 
-			/* We need to make sure all sections are properly 1M aligned
-			 * However between Kernel Memory and the Kernel mtd section, depending on the
-			 * rootfs size, there can be overlapping memory areas.
-			 */
-
-			if (as_1m &&  i!=L1I_MEM && i!=L1D_MEM) {
+		if (as_1m && i != L1I_MEM && i != L1D_MEM) {
 #ifdef CONFIG_MTD_UCLINUX
-				if (i == SDRAM_RAM_MTD) {
-					if ((cplb_data[SDRAM_KERN].end + 1) > cplb_data[SDRAM_RAM_MTD].start)
-						cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M)) + SIZE_1M;
-					else
-						cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M));
+			if (i == SDRAM_RAM_MTD) {
+				if ((cplb_data[SDRAM_KERN].end + 1) >
+						cplb_data[SDRAM_RAM_MTD].start)
+					cplb_data[SDRAM_RAM_MTD].start =
+						(cplb_data[i].start &
+						 (-2*SIZE_1M)) + SIZE_1M;
+				else
+					cplb_data[SDRAM_RAM_MTD].start =
+						(cplb_data[i].start &
+						 (-2*SIZE_1M));
+			} else
+#endif
+				printk(KERN_WARNING
+					"Unaligned Start of %s at 0x%X\n",
+					cplb_data[i].name, cplb_data[i].start);
+		}
+
+		as = cplb_data[i].start % SIZE_4M;
+		ae = cplb_data[i].end % SIZE_4M;
+
+		if (as)
+			a_start = cplb_data[i].start + (SIZE_4M - (as));
+		else
+			a_start = cplb_data[i].start;
+
+		a_end = cplb_data[i].end - ae;
+
+		for (j = INITIAL_T; j <= SWITCH_T; j++) {
+
+			switch (j) {
+			case INITIAL_T:
+				if (cplb_data[i].attr & INITIAL_T) {
+					t_i = &cplb.init_i;
+					t_d = &cplb.init_d;
+					process = 1;
 				} else
-#endif
-					printk(KERN_WARNING "Unaligned Start of %s at 0x%X\n",
-					       cplb_data[i].name, cplb_data[i].start);
+					process = 0;
+				break;
+			case SWITCH_T:
+				if (cplb_data[i].attr & SWITCH_T) {
+					t_i = &cplb.switch_i;
+					t_d = &cplb.switch_d;
+					process = 1;
+				} else
+					process = 0;
+				break;
+			default:
+					process = 0;
+				break;
 			}
 
-			as = cplb_data[i].start % SIZE_4M;
-			ae = cplb_data[i].end % SIZE_4M;
+			if (!process)
+				continue;
+			if (cplb_data[i].attr & I_CPLB)
+				__fill_code_cplbtab(t_i, i, a_start, a_end);
 
-			if (as)
-				a_start = cplb_data[i].start + (SIZE_4M - (as));
-			else
-				a_start = cplb_data[i].start;
-
-			a_end = cplb_data[i].end - ae;
-
-			for (j = INITIAL_T; j <= SWITCH_T; j++) {
-
-				switch (j) {
-				case INITIAL_T:
-					if (cplb_data[i].attr & INITIAL_T) {
-						t_i = &cplb.init_i;
-						t_d = &cplb.init_d;
-						process = 1;
-					} else
-						process = 0;
-					break;
-				case SWITCH_T:
-					if (cplb_data[i].attr & SWITCH_T) {
-						t_i = &cplb.switch_i;
-						t_d = &cplb.switch_d;
-						process = 1;
-					} else
-						process = 0;
-					break;
-				default:
-						process = 0;
-					break;
-				}
-
-	if (process) {
-				if (cplb_data[i].attr & I_CPLB) {
-
-					if (cplb_data[i].psize) {
-						fill_cplbtab(t_i,
-							     cplb_data[i].start,
-							     cplb_data[i].end,
-							     cplb_data[i].psize,
-							     cplb_data[i].i_conf);
-					} else {
-						/*icplb_table */
-#if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
-						if (i == SDRAM_KERN) {
-							fill_cplbtab(t_i,
-								     cplb_data[i].start,
-								     cplb_data[i].end,
-								     SIZE_4M,
-								     cplb_data[i].i_conf);
-						} else
-#endif
-						{
-							fill_cplbtab(t_i,
-								     cplb_data[i].start,
-								     a_start,
-								     SIZE_1M,
-								     cplb_data[i].i_conf);
-							fill_cplbtab(t_i,
-								     a_start,
-								     a_end,
-								     SIZE_4M,
-								     cplb_data[i].i_conf);
-							fill_cplbtab(t_i, a_end,
-								     cplb_data[i].end,
-								     SIZE_1M,
-								     cplb_data[i].i_conf);
-						}
-					}
-
-				}
-				if (cplb_data[i].attr & D_CPLB) {
-
-					if (cplb_data[i].psize) {
-						fill_cplbtab(t_d,
-							     cplb_data[i].start,
-							     cplb_data[i].end,
-							     cplb_data[i].psize,
-							     cplb_data[i].d_conf);
-					} else {
-/*dcplb_table*/
-						fill_cplbtab(t_d,
-							     cplb_data[i].start,
-							     a_start, SIZE_1M,
-							     cplb_data[i].d_conf);
-						fill_cplbtab(t_d, a_start,
-							     a_end, SIZE_4M,
-							     cplb_data[i].d_conf);
-						fill_cplbtab(t_d, a_end,
-							     cplb_data[i].end,
-							     SIZE_1M,
-							     cplb_data[i].d_conf);
-
-					}
-
-				}
-			}
-			}
-
+			if (cplb_data[i].attr & D_CPLB)
+				__fill_data_cplbtab(t_d, i, a_start, a_end);
 		}
 	}
 
@@ -681,7 +689,7 @@
 
 #endif
 
-static inline u_long get_vco(void)
+static u_long get_vco(void)
 {
 	u_long msel;
 	u_long vco;
@@ -889,8 +897,8 @@
 	.show = show_cpuinfo,
 };
 
-void cmdline_init(unsigned long r0)
+void __init cmdline_init(const char *r0)
 {
 	if (r0)
-		strncpy(command_line, (char *)r0, COMMAND_LINE_SIZE);
+		strncpy(command_line, r0, COMMAND_LINE_SIZE);
 }
diff --git a/arch/blackfin/kernel/traps.c b/arch/blackfin/kernel/traps.c
index 9932ede..5ab87b0 100644
--- a/arch/blackfin/kernel/traps.c
+++ b/arch/blackfin/kernel/traps.c
@@ -557,7 +557,7 @@
 				break;
 #ifndef CONFIG_DEBUG_HWERR
 			/* If one of the last few instructions was a STI
-			 * it is likily that the error occured awhile ago
+			 * it is likely that the error occured awhile ago
 			 * and we just noticed
 			 */
 			if (x >= 0x0040 && x <= 0x0047 && i <= 0)
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index 86fe679..1ef1e36 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -7,7 +7,7 @@
  * Description:  Master linker script for blackfin architecture
  *
  * Modified:
- *               Copyright 2004-2006 Analog Devices Inc.
+ *               Copyright 2004-2007 Analog Devices Inc.
  *
  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
  *
@@ -32,97 +32,54 @@
 #include <asm-generic/vmlinux.lds.h>
 #include <asm/mem_map.h>
 
-
 OUTPUT_FORMAT("elf32-bfin")
 ENTRY(__start)
 _jiffies = _jiffies_64;
 
-MEMORY
-{
-	ram         : ORIGIN = CONFIG_BOOT_LOAD, LENGTH = (CONFIG_MEM_SIZE * 1024 * 1024) - (CONFIG_BOOT_LOAD)
-	l1_data_a   : ORIGIN = L1_DATA_A_START,  LENGTH = L1_DATA_A_LENGTH
-	l1_data_b   : ORIGIN = L1_DATA_B_START,  LENGTH = L1_DATA_B_LENGTH
-	l1_code     : ORIGIN = L1_CODE_START,    LENGTH = L1_CODE_LENGTH
-	l1_scratch  : ORIGIN = L1_SCRATCH_START, LENGTH = L1_SCRATCH_LENGTH
-}
-
 SECTIONS
 {
 	. = CONFIG_BOOT_LOAD;
-
 	.text :
 	{
-		 _text = .;
-		 __stext = .;
+		__text = .;
+		_text = .;
+		__stext = .;
 		TEXT_TEXT
 		SCHED_TEXT
+		LOCK_TEXT
 		*(.text.lock)
-		. = ALIGN(16);
-		  ___start___ex_table = .;
-		*(__ex_table)
-		 ___stop___ex_table = .;
-
-		*($code)
-		*(.rodata)
-		*(.rodata.*)
-		*(__vermagic)		/* Kernel version magic */
-		*(.rodata1)
 		*(.fixup)
-		*(.spinlock.text)
 
-		/* Kernel symbol table: Normal symbols */
+		. = ALIGN(16);
+		___start___ex_table = .;
+		*(__ex_table)
+		___stop___ex_table = .;
+
 		. = ALIGN(4);
-		___start___ksymtab = .;
-		*(__ksymtab)
-		___stop___ksymtab = .;
-
-		/* Kernel symbol table: GPL-only symbols */
-		___start___ksymtab_gpl = .;
-		*(__ksymtab_gpl)
-		___stop___ksymtab_gpl = .;
-
-		/* Kernel symbol table: Normal unused symbols */		\
-		___start___ksymtab_unused = .;
-		*(__ksymtab_unused)
-		___stop___ksymtab_unused = .;
-
-		/* Kernel symbol table: GPL-only unused symbols */
-		___start___ksymtab_unused_gpl = .;
-		*(__ksymtab_unused_gpl)
-		___stop___ksymtab_unused_gpl = .;
-
-
-		/* Kernel symbol table: GPL-future symbols */
-		___start___ksymtab_gpl_future = .;
-		*(__ksymtab_gpl_future)
-		___stop___ksymtab_gpl_future = .;
-
-		/* Kernel symbol table: Normal symbols */
-		___start___kcrctab = .;
-		*(__kcrctab)
-		___stop___kcrctab = .;
-
-		/* Kernel symbol table: GPL-only symbols */
-		___start___kcrctab_gpl = .;
-		*(__kcrctab_gpl)
-		___stop___kcrctab_gpl = .;
-
-		/* Kernel symbol table: GPL-future symbols */
-		___start___kcrctab_gpl_future = .;
-		*(__kcrctab_gpl_future)
-		___stop___kcrctab_gpl_future = .;
-
-		/* Kernel symbol table: strings */
-		*(__ksymtab_strings)
-
-		 . = ALIGN(4);
 		__etext = .;
-	} > ram
+	}
 
+	RODATA
+
+	.data :
+	{
+		__sdata = .;
+		. = ALIGN(0x2000);
+		*(.data.init_task)
+		DATA_DATA
+		CONSTRUCTORS
+
+		. = ALIGN(32);
+		*(.data.cacheline_aligned)
+
+		. = ALIGN(0x2000);
+		__edata = .;
+	}
+
+	___init_begin = .;
 	.init :
 	{
 		. = ALIGN(4096);
-		___init_begin = .;
 		__sinittext = .;
 		*(.init.text)
 		__einittext = .;
@@ -148,39 +105,39 @@
 		*(.init.ramfs)
 		___initramfs_end = .;
 		. = ALIGN(4);
-		___init_end = .;
-	} > ram
+	}
 
-	 __l1_lma_start = .;
+	__l1_lma_start = .;
 
-	.text_l1 :
+	.text_l1 L1_CODE_START : AT(LOADADDR(.init) + SIZEOF(.init))
 	{
 		. = ALIGN(4);
-		 __stext_l1 = .;
+		__stext_l1 = .;
 		*(.l1.text)
 
 		. = ALIGN(4);
-		 __etext_l1 = .;
-	} > l1_code AT > ram
+		__etext_l1 = .;
+	}
 
-	.data_l1 :
+	.data_l1 L1_DATA_A_START : AT(LOADADDR(.text_l1) + SIZEOF(.text_l1))
 	{
 		. = ALIGN(4);
-		 __sdata_l1 = .;
+		__sdata_l1 = .;
 		*(.l1.data)
-		 __edata_l1 = .;
+		__edata_l1 = .;
 
 		. = ALIGN(4);
-		 __sbss_l1 = .;
+		__sbss_l1 = .;
 		*(.l1.bss)
 
 		. = ALIGN(32);
 		*(.data_l1.cacheline_aligned)
 
 		. = ALIGN(4);
-		 __ebss_l1 = .;
-	} > l1_data_a AT > ram
-	.data_b_l1 :
+		__ebss_l1 = .;
+	}
+
+	.data_b_l1 L1_DATA_B_START : AT(LOADADDR(.data_l1) + SIZEOF(.data_l1))
 	{
 		. = ALIGN(4);
 		__sdata_b_l1 = .;
@@ -193,36 +150,25 @@
 
 		. = ALIGN(4);
 		__ebss_b_l1 = .;
-	} > l1_data_b AT > ram
+	}
 
-	.data :
-	{
-		 __sdata = .;
-		. = ALIGN(0x2000);
-		*(.data.init_task)
-		DATA_DATA
+	___init_end = LOADADDR(.data_b_l1) + SIZEOF(.data_b_l1);
 
-		. = ALIGN(32);
-		*(.data.cacheline_aligned)
-
-		. = ALIGN(0x2000);
-		__edata = .;
-	} > ram
-
-	/DISCARD/ : {			/* Exit code and data*/
-		*(.exit.text)
-		*(.exit.data)
-		*(.exitcall.exit)
-	} > ram
-
-	.bss :
+	.bss LOADADDR(.data_b_l1) + SIZEOF(.data_b_l1) :
 	{
 		. = ALIGN(4);
-		 ___bss_start = .;
+		___bss_start = .;
 		*(.bss)
 		*(COMMON)
 		. = ALIGN(4);
-		 ___bss_stop = .;
-		 __end = .	;
-	} > ram
+		___bss_stop = .;
+		__end = .;
+	}
+
+	/DISCARD/ :
+	{
+		*(.exit.text)
+		*(.exit.data)
+		*(.exitcall.exit)
+	}
 }
diff --git a/arch/blackfin/lib/divsi3.S b/arch/blackfin/lib/divsi3.S
index 3e29861..2ac59c7 100644
--- a/arch/blackfin/lib/divsi3.S
+++ b/arch/blackfin/lib/divsi3.S
@@ -44,6 +44,7 @@
  */
 
 .global   ___divsi3;
+.type ___divsi3, STT_FUNC;
 
 #ifdef CONFIG_ARITHMETIC_OPS_L1
 .section .l1.text
@@ -214,3 +215,5 @@
 .Lret_zero:
   R0 = 0;
   RTS;
+
+.size ___divsi3, .-___divsi3
diff --git a/arch/blackfin/lib/ins.S b/arch/blackfin/lib/ins.S
index 7d5e984..a17cc77 100644
--- a/arch/blackfin/lib/ins.S
+++ b/arch/blackfin/lib/ins.S
@@ -46,7 +46,7 @@
 .Llong_loop_e: 	NOP;
 	sti R3;
 	RTS;
-
+ENDPROC(_insl)
 
 ENTRY(_insw)
 	P0 = R0;	/* P0 = port */
@@ -61,6 +61,7 @@
 .Lword_loop_e: 	NOP;
 	sti R3;
 	RTS;
+ENDPROC(_insw)
 
 ENTRY(_insb)
 	P0 = R0;	/* P0 = port */
@@ -75,3 +76,4 @@
 .Lbyte_loop_e:  NOP;
 	sti R3;
 	RTS;
+ENDPROC(_insb)
diff --git a/arch/blackfin/lib/memchr.S b/arch/blackfin/lib/memchr.S
index 4981222..5da4281 100644
--- a/arch/blackfin/lib/memchr.S
+++ b/arch/blackfin/lib/memchr.S
@@ -67,4 +67,4 @@
 	R0 += -1;
 	RTS;
 
-.size _memchr,.-_memchr
+ENDPROC(_memchr)
diff --git a/arch/blackfin/lib/memcmp.S b/arch/blackfin/lib/memcmp.S
index 5b95023..a6b8ee6 100644
--- a/arch/blackfin/lib/memcmp.S
+++ b/arch/blackfin/lib/memcmp.S
@@ -107,4 +107,4 @@
 	P3 = I1;
 	RTS;
 
-.size _memcmp,.-_memcmp
+ENDPROC(_memcmp)
diff --git a/arch/blackfin/lib/memcpy.S b/arch/blackfin/lib/memcpy.S
index c1e00ef..34b5a91 100644
--- a/arch/blackfin/lib/memcpy.S
+++ b/arch/blackfin/lib/memcpy.S
@@ -140,3 +140,5 @@
 	B[P0--] = R1;
 
 	RTS;
+
+ENDPROC(_memcpy)
diff --git a/arch/blackfin/lib/memmove.S b/arch/blackfin/lib/memmove.S
index 2e5fb7f..c371585 100644
--- a/arch/blackfin/lib/memmove.S
+++ b/arch/blackfin/lib/memmove.S
@@ -100,4 +100,4 @@
 	P3 = I1;
 	RTS;
 
-.size _memmove,.-_memmove
+ENDPROC(_memmove)
diff --git a/arch/blackfin/lib/memset.S b/arch/blackfin/lib/memset.S
index ba6d047..8159136 100644
--- a/arch/blackfin/lib/memset.S
+++ b/arch/blackfin/lib/memset.S
@@ -106,4 +106,4 @@
 	B[P0++] = R1;
 	JUMP .Laligned;
 
-.size _memset,.-_memset
+ENDPROC(_memset)
diff --git a/arch/blackfin/lib/modsi3.S b/arch/blackfin/lib/modsi3.S
index 528b8b1..ca1dd39 100644
--- a/arch/blackfin/lib/modsi3.S
+++ b/arch/blackfin/lib/modsi3.S
@@ -77,3 +77,5 @@
 	R0 = 0;
 .LRETURN_R0:
 	RTS;
+
+.size ___modsi3, .-___modsi3
diff --git a/arch/blackfin/lib/outs.S b/arch/blackfin/lib/outs.S
index f8c876f..4c3da8a 100644
--- a/arch/blackfin/lib/outs.S
+++ b/arch/blackfin/lib/outs.S
@@ -40,6 +40,7 @@
 .Llong_loop_s: R0 = [P1++];
 .Llong_loop_e: [P0] = R0;
 	RTS;
+ENDPROC(_outsl)
 
 ENTRY(_outsw)
 	P0 = R0;	/* P0 = port */
@@ -50,6 +51,7 @@
 .Lword_loop_s: R0 = W[P1++];
 .Lword_loop_e: W[P0] = R0;
 	RTS;
+ENDPROC(_outsw)
 
 ENTRY(_outsb)
 	P0 = R0;	/* P0 = port */
@@ -60,3 +62,4 @@
 .Lbyte_loop_s: R0 = B[P1++];
 .Lbyte_loop_e: B[P0] = R0;
 	RTS;
+ENDPROC(_outsb)
diff --git a/arch/blackfin/lib/smulsi3_highpart.S b/arch/blackfin/lib/smulsi3_highpart.S
index 10b8f8d..e383cd3 100644
--- a/arch/blackfin/lib/smulsi3_highpart.S
+++ b/arch/blackfin/lib/smulsi3_highpart.S
@@ -28,3 +28,5 @@
 
 	R0 = R0 + R1;
 	RTS;
+
+.size ___smulsi3_highpart, .-___smulsi3_highpart
diff --git a/arch/blackfin/lib/udivsi3.S b/arch/blackfin/lib/udivsi3.S
index d39a129..58fd96d 100644
--- a/arch/blackfin/lib/udivsi3.S
+++ b/arch/blackfin/lib/udivsi3.S
@@ -296,3 +296,5 @@
   R1 = R0 - R3;
   IF CC R0 = R1;
   RTS;
+
+ENDPROC(___udivsi3)
diff --git a/arch/blackfin/lib/umodsi3.S b/arch/blackfin/lib/umodsi3.S
index b55ce96..4f2b76e 100644
--- a/arch/blackfin/lib/umodsi3.S
+++ b/arch/blackfin/lib/umodsi3.S
@@ -34,7 +34,9 @@
 #endif
 
 .extern ___udivsi3;
+.type ___udivsi3, STT_FUNC;
 .globl	___umodsi3
+.type ___umodsi3, STT_FUNC;
 ___umodsi3:
 
 	CC=R0==0;
@@ -64,3 +66,5 @@
 	R0 = 0;
 .LRETURN_R0:
 	RTS;
+
+.size ___umodsi3, .-___umodsi3
diff --git a/arch/blackfin/lib/umulsi3_highpart.S b/arch/blackfin/lib/umulsi3_highpart.S
index aac8218..67b7993 100644
--- a/arch/blackfin/lib/umulsi3_highpart.S
+++ b/arch/blackfin/lib/umulsi3_highpart.S
@@ -21,3 +21,5 @@
 	R1 = PACK(R1.l,R0.h);
 	R0 = R1 + R2;
 	RTS;
+
+.size ___umulsi3_highpart, .-___umulsi3_highpart
diff --git a/arch/blackfin/mach-bf533/boards/cm_bf533.c b/arch/blackfin/mach-bf533/boards/cm_bf533.c
index 23a7f60..edd31ce 100644
--- a/arch/blackfin/mach-bf533/boards/cm_bf533.c
+++ b/arch/blackfin/mach-bf533/boards/cm_bf533.c
@@ -1,7 +1,7 @@
 /*
  * File:         arch/blackfin/mach-bf533/boards/cm_bf533.c
  * Based on:     arch/blackfin/mach-bf533/boards/ezkit.c
- * Author:       Aidan Williams <aidan@nicta.com.au> Copright 2005
+ * Author:       Aidan Williams <aidan@nicta.com.au> Copyright 2005
  *
  * Created:      2005
  * Description:  Board description file
diff --git a/arch/blackfin/mach-bf533/boards/ezkit.c b/arch/blackfin/mach-bf533/boards/ezkit.c
index 747298e..0b522d9 100644
--- a/arch/blackfin/mach-bf533/boards/ezkit.c
+++ b/arch/blackfin/mach-bf533/boards/ezkit.c
@@ -1,6 +1,6 @@
 /*
  * File:         arch/blackfin/mach-bf533/ezkit.c
- * Based on:     Orginal Work
+ * Based on:     Original Work
  * Author:       Aidan Williams <aidan@nicta.com.au>
  *
  * Created:      2005
diff --git a/arch/blackfin/mach-bf533/head.S b/arch/blackfin/mach-bf533/head.S
index 4db9e62..7e2aa8d 100644
--- a/arch/blackfin/mach-bf533/head.S
+++ b/arch/blackfin/mach-bf533/head.S
@@ -28,6 +28,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/init.h>
 #include <asm/blackfin.h>
 #if CONFIG_BFIN_KERNEL_CLOCK
 #include <asm/mach/mem_init.h>
@@ -45,19 +46,19 @@
 
 #define INITIAL_STACK	0xFFB01000
 
-.text
+__INIT
 
 ENTRY(__start)
-ENTRY(__stext)
 	/* R0: argument of command line string, passed from uboot, save it */
 	R7 = R0;
-	/* Set the SYSCFG register */
+	/* Set the SYSCFG register:
+	 * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
+	 */
 	R0 = 0x36;
-	/*Enable Cycle Counter and Nesting Of Interrupts(3rd Bit)*/
 	SYSCFG = R0;
 	R0 = 0;
 
-	/*Clear Out All the data and pointer  Registers*/
+	/* Clear Out All the data and pointer Registers */
 	R1 = R0;
 	R2 = R0;
 	R3 = R0;
@@ -79,7 +80,7 @@
 	L2 = r0;
 	L3 = r0;
 
-	/* Clear Out All the DAG Registers*/
+	/* Clear Out All the DAG Registers */
 	B0 = r0;
 	B1 = r0;
 	B2 = r0;
@@ -265,6 +266,7 @@
 
 .LWAIT_HERE:
 	jump .LWAIT_HERE;
+ENDPROC(__start)
 
 ENTRY(_real_start)
 	[ -- sp ] = reti;
@@ -303,7 +305,7 @@
 .L_clear_zero:
 	W[p1++] = r0;
 
-/* pass the uboot arguments to the global value command line */
+	/* pass the uboot arguments to the global value command line */
 	R0 = R7;
 	call _cmdline_init;
 
@@ -322,7 +324,7 @@
 	[p1] = r1;
 
 	/*
-	 *  load the current thread pointer and stack
+	 * load the current thread pointer and stack
 	 */
 	r1.l = _init_thread_union;
 	r1.h = _init_thread_union;
@@ -333,9 +335,10 @@
 	sp = r1;
 	usp = sp;
 	fp = sp;
-	call _start_kernel;
-.L_exit:
-	jump.s	.L_exit;
+	jump.l _start_kernel;
+ENDPROC(_real_start)
+
+__FINIT
 
 .section .l1.text
 #if CONFIG_BFIN_KERNEL_CLOCK
@@ -439,12 +442,13 @@
 
 	p0.h = hi(SIC_IWR);
 	p0.l = lo(SIC_IWR);
-	r0.l = lo(IWR_ENABLE_ALL)
-	r0.h = hi(IWR_ENABLE_ALL)
+	r0.l = lo(IWR_ENABLE_ALL);
+	r0.h = hi(IWR_ENABLE_ALL);
 	[p0] = r0;
 	SSYNC;
 
 	RTS;
+ENDPROC(_start_dma_code)
 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
 
 ENTRY(_bfin_reset)
diff --git a/arch/blackfin/mach-bf533/ints-priority.c b/arch/blackfin/mach-bf533/ints-priority.c
index 36a6933..a3e1789 100644
--- a/arch/blackfin/mach-bf533/ints-priority.c
+++ b/arch/blackfin/mach-bf533/ints-priority.c
@@ -4,7 +4,7 @@
  * Author:       Michael Hennerich
  *
  * Created:      ?
- * Description:  Set up the interupt priorities
+ * Description:  Set up the interrupt priorities
  *
  * Modified:
  *               Copyright 2004-2006 Analog Devices Inc.
diff --git a/arch/blackfin/mach-bf537/boards/generic_board.c b/arch/blackfin/mach-bf537/boards/generic_board.c
index 9019c0e..fd57e74 100644
--- a/arch/blackfin/mach-bf537/boards/generic_board.c
+++ b/arch/blackfin/mach-bf537/boards/generic_board.c
@@ -55,7 +55,7 @@
 		.end = 0x20312000,
 		.flags = IORESOURCE_MEM,
 	},{
-		.start = 0x20311000, /* Attribute Memeory */
+		.start = 0x20311000, /* Attribute Memory */
 		.end = 0x20311FFF,
 		.flags = IORESOURCE_MEM,
 	},{
diff --git a/arch/blackfin/mach-bf537/boards/pnav10.c b/arch/blackfin/mach-bf537/boards/pnav10.c
index 40d3a1b..8aaf76d 100644
--- a/arch/blackfin/mach-bf537/boards/pnav10.c
+++ b/arch/blackfin/mach-bf537/boards/pnav10.c
@@ -59,7 +59,7 @@
 		.end = 0x20312000,
 		.flags = IORESOURCE_MEM,
 	},{
-		.start = 0x20311000, /* Attribute Memeory */
+		.start = 0x20311000, /* Attribute Memory */
 		.end = 0x20311FFF,
 		.flags = IORESOURCE_MEM,
 	},{
diff --git a/arch/blackfin/mach-bf537/boards/stamp.c b/arch/blackfin/mach-bf537/boards/stamp.c
index ba2f875..3a29b4d1 100644
--- a/arch/blackfin/mach-bf537/boards/stamp.c
+++ b/arch/blackfin/mach-bf537/boards/stamp.c
@@ -108,7 +108,7 @@
 		.end = 0x20312000,
 		.flags = IORESOURCE_MEM,
 	},{
-		.start = 0x20311000, /* Attribute Memeory */
+		.start = 0x20311000, /* Attribute Memory */
 		.end = 0x20311FFF,
 		.flags = IORESOURCE_MEM,
 	},{
diff --git a/arch/blackfin/mach-bf537/head.S b/arch/blackfin/mach-bf537/head.S
index 2c2652b..7d902bb 100644
--- a/arch/blackfin/mach-bf537/head.S
+++ b/arch/blackfin/mach-bf537/head.S
@@ -28,6 +28,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/init.h>
 #include <asm/blackfin.h>
 #if CONFIG_BFIN_KERNEL_CLOCK
 #include <asm/mach/mem_init.h>
@@ -40,20 +41,21 @@
 .extern ___bss_start
 .extern _bf53x_relocate_l1_mem
 
-#define INITIAL_STACK   0xFFB01000
+#define INITIAL_STACK	0xFFB01000
 
-.text
+__INIT
 
 ENTRY(__start)
-ENTRY(__stext)
 	/* R0: argument of command line string, passed from uboot, save it */
 	R7 = R0;
-	/* Set the SYSCFG register */
+	/* Set the SYSCFG register:
+	 * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
+	 */
 	R0 = 0x36;
-	SYSCFG = R0;   /*Enable Cycle Counter and Nesting Of Interrupts(3rd Bit)*/
+	SYSCFG = R0;
 	R0 = 0;
 
-	/* Clear Out All the data and pointer  Registers*/
+	/* Clear Out All the data and pointer Registers */
 	R1 = R0;
 	R2 = R0;
 	R3 = R0;
@@ -75,7 +77,7 @@
 	L2 = r0;
 	L3 = r0;
 
-	/* Clear Out All the DAG Registers*/
+	/* Clear Out All the DAG Registers */
 	B0 = r0;
 	B1 = r0;
 	B2 = r0;
@@ -191,7 +193,7 @@
 
 	p0.h = hi(UART_DLL);
 	p0.l = lo(UART_DLL);
-	r0 = 0x00(Z);
+	r0 = 0x0(Z);
 	w[p0] = r0.L;
 	ssync;
 
@@ -218,6 +220,7 @@
 #if CONFIG_BFIN_KERNEL_CLOCK
 	call _start_dma_code;
 #endif
+
 	/* Code for initializing Async memory banks */
 
 	p2.h = hi(EBIU_AMBCTL1);
@@ -272,6 +275,7 @@
 
 .LWAIT_HERE:
 	jump .LWAIT_HERE;
+ENDPROC(__start)
 
 ENTRY(_real_start)
 	[ -- sp ] = reti;
@@ -291,7 +295,7 @@
 	p2.h = ___bss_stop;
 	r0 = 0;
 	p2 -= p1;
-	lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
+	lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
 .L_clear_bss:
 	B[p1++] = r0;
 
@@ -306,7 +310,7 @@
 	r0 = r0 >> 1;
 	p2 = r0;
 	r0 = 0;
-	lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
+	lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
 .L_clear_zero:
 	W[p1++] = r0;
 
@@ -328,9 +332,8 @@
 	r1 = p3;
 	[p1] = r1;
 
-
 	/*
-	 *  load the current thread pointer and stack
+	 * load the current thread pointer and stack
 	 */
 	r1.l = _init_thread_union;
 	r1.h = _init_thread_union;
@@ -341,9 +344,10 @@
 	sp = r1;
 	usp = sp;
 	fp = sp;
-	call _start_kernel;
-.L_exit:
-	jump.s	.L_exit;
+	jump.l _start_kernel;
+ENDPROC(_real_start)
+
+__FINIT
 
 .section .l1.text
 #if CONFIG_BFIN_KERNEL_CLOCK
@@ -462,6 +466,7 @@
 	SSYNC;
 
 	RTS;
+ENDPROC(_start_dma_code)
 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
 
 ENTRY(_bfin_reset)
diff --git a/arch/blackfin/mach-bf537/ints-priority.c b/arch/blackfin/mach-bf537/ints-priority.c
index fd6308e..2dbf3df 100644
--- a/arch/blackfin/mach-bf537/ints-priority.c
+++ b/arch/blackfin/mach-bf537/ints-priority.c
@@ -4,7 +4,7 @@
  * Author:       Michael Hennerich
  *
  * Created:
- * Description:  Set up the interupt priorities
+ * Description:  Set up the interrupt priorities
  *
  * Modified:
  *               Copyright 2004-2006 Analog Devices Inc.
diff --git a/arch/blackfin/mach-bf561/boards/cm_bf561.c b/arch/blackfin/mach-bf561/boards/cm_bf561.c
index 6824e95..3dc5c04 100644
--- a/arch/blackfin/mach-bf561/boards/cm_bf561.c
+++ b/arch/blackfin/mach-bf561/boards/cm_bf561.c
@@ -1,7 +1,7 @@
 /*
  * File:         arch/blackfin/mach-bf533/boards/cm_bf561.c
  * Based on:     arch/blackfin/mach-bf533/boards/ezkit.c
- * Author:       Aidan Williams <aidan@nicta.com.au> Copright 2005
+ * Author:       Aidan Williams <aidan@nicta.com.au> Copyright 2005
  *
  * Created:      2006
  * Description:  Board description file
@@ -43,7 +43,7 @@
 char *bfin_board_name = "Bluetechnix CM BF561";
 
 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
-/* all SPI perpherals info goes here */
+/* all SPI peripherals info goes here */
 
 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
 static struct mtd_partition bfin_spi_flash_partitions[] = {
diff --git a/arch/blackfin/mach-bf561/head.S b/arch/blackfin/mach-bf561/head.S
index ad9187a..31cbc75 100644
--- a/arch/blackfin/mach-bf561/head.S
+++ b/arch/blackfin/mach-bf561/head.S
@@ -28,6 +28,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/init.h>
 #include <asm/blackfin.h>
 #if CONFIG_BFIN_KERNEL_CLOCK
 #include <asm/mach/mem_init.h>
@@ -42,18 +43,19 @@
 
 #define INITIAL_STACK	0xFFB01000
 
-.text
+__INIT
 
 ENTRY(__start)
-ENTRY(__stext)
-	/*  R0: argument of command line string, passed from uboot, save it */
+	/* R0: argument of command line string, passed from uboot, save it */
 	R7 = R0;
-	/* Set the SYSCFG register */
+	/* Set the SYSCFG register:
+	 * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
+	 */
 	R0 = 0x36;
-	SYSCFG = R0; /*Enable Cycle Counter and Nesting Of Interrupts(3rd Bit)*/
+	SYSCFG = R0;
 	R0 = 0;
 
-	/*Clear Out All the data and pointer  Registers*/
+	/* Clear Out All the data and pointer Registers */
 	R1 = R0;
 	R2 = R0;
 	R3 = R0;
@@ -75,7 +77,7 @@
 	L2 = r0;
 	L3 = r0;
 
-	/* Clear Out All the DAG Registers*/
+	/* Clear Out All the DAG Registers */
 	B0 = r0;
 	B1 = r0;
 	B2 = r0;
@@ -219,6 +221,7 @@
 
 .LWAIT_HERE:
 	jump .LWAIT_HERE;
+ENDPROC(__start)
 
 ENTRY(_real_start)
 	[ -- sp ] = reti;
@@ -238,7 +241,7 @@
 	p2.h = ___bss_stop;
 	r0 = 0;
 	p2 -= p1;
-	lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
+	lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
 .L_clear_bss:
 	B[p1++] = r0;
 
@@ -253,11 +256,11 @@
 	r0 = r0 >> 1;
 	p2 = r0;
 	r0 = 0;
-	lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
+	lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
 .L_clear_zero:
 	W[p1++] = r0;
 
-/* pass the uboot arguments to the global value command line */
+	/* pass the uboot arguments to the global value command line */
 	R0 = R7;
 	call _cmdline_init;
 
@@ -287,9 +290,10 @@
 	sp = r1;
 	usp = sp;
 	fp = sp;
-	call _start_kernel;
-.L_exit:
-	jump.s	.L_exit;
+	jump.l _start_kernel;
+ENDPROC(_real_start)
+
+__FINIT
 
 .section .l1.text
 #if CONFIG_BFIN_KERNEL_CLOCK
@@ -350,7 +354,7 @@
 	if ! CC jump .Lcheck_again;
 
 	/* Configure SCLK & CCLK Dividers */
-	   	r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
+	r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
 	p0.h = hi(PLL_DIV);
 	p0.l = lo(PLL_DIV);
 	w[p0] = r0.l;
@@ -391,6 +395,7 @@
 	SSYNC;
 
 	RTS;
+ENDPROC(_start_dma_code)
 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
 
 ENTRY(_bfin_reset)
diff --git a/arch/blackfin/mach-bf561/ints-priority.c b/arch/blackfin/mach-bf561/ints-priority.c
index 89c52ff..86e3b0e 100644
--- a/arch/blackfin/mach-bf561/ints-priority.c
+++ b/arch/blackfin/mach-bf561/ints-priority.c
@@ -4,7 +4,7 @@
  * Author:       Michael Hennerich
  *
  * Created:
- * Description:  Set up the interupt priorities
+ * Description:  Set up the interrupt priorities
  *
  * Modified:
  *               Copyright 2004-2006 Analog Devices Inc.
diff --git a/arch/blackfin/mach-common/cache.S b/arch/blackfin/mach-common/cache.S
index bb9446e..8bd2af1 100644
--- a/arch/blackfin/mach-common/cache.S
+++ b/arch/blackfin/mach-common/cache.S
@@ -70,6 +70,7 @@
 .Lno_dcache_b:
 	R7 = [SP++];
 	RTS;
+ENDPROC(_cache_invalidate)
 
 /* Invalidate the Entire Instruction cache by
  * disabling IMC bit
@@ -106,6 +107,8 @@
 
 	( R7:5) = [SP++];
 	RTS;
+ENDPROC(_invalidate_entire_icache)
+ENDPROC(_icache_invalidate)
 
 /*
  * blackfin_cache_flush_range(start, end)
@@ -129,6 +132,7 @@
 	IFLUSH [P0];
 	SSYNC;
 	RTS;
+ENDPROC(_blackfin_icache_flush_range)
 
 /*
  * blackfin_icache_dcache_flush_range(start, end)
@@ -155,6 +159,7 @@
 	FLUSH [P0];
 	SSYNC;
 	RTS;
+ENDPROC(_blackfin_icache_dcache_flush_range)
 
 /* Throw away all D-cached data in specified region without any obligation to
  * write them back. However, we must clean the D-cached entries around the
@@ -183,6 +188,7 @@
 	FLUSHINV[P0];
 	SSYNC;
 	RTS;
+ENDPROC(_blackfin_dcache_invalidate_range)
 
 /* Invalidate the Entire Data cache by
  * clearing DMC[1:0] bits
@@ -221,6 +227,8 @@
 
 	( R7:6) = [SP++];
 	RTS;
+ENDPROC(_dcache_invalidate)
+ENDPROC(_invalidate_entire_dcache)
 
 ENTRY(_blackfin_dcache_flush_range)
 	R2 = -L1_CACHE_BYTES;
@@ -241,6 +249,7 @@
 	FLUSH[P0];
 	SSYNC;
 	RTS;
+ENDPROC(_blackfin_dcache_flush_range)
 
 ENTRY(_blackfin_dflush_page)
 	P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
@@ -251,3 +260,4 @@
 .Lfl1:	FLUSH [P0++];
 	SSYNC;
 	RTS;
+ENDPROC(_blackfin_dflush_page)
diff --git a/arch/blackfin/mach-common/cacheinit.S b/arch/blackfin/mach-common/cacheinit.S
index 8c17f09..7924a90 100644
--- a/arch/blackfin/mach-common/cacheinit.S
+++ b/arch/blackfin/mach-common/cacheinit.S
@@ -86,6 +86,8 @@
 	SSYNC;
 	STI R2;
 	RTS;
+
+ENDPROC(_bfin_icache_init)
 #endif
 
 #if defined(CONFIG_BLKFIN_DCACHE)
@@ -134,4 +136,6 @@
 	SSYNC;
 	STI R2;
 	RTS;
+
+ENDPROC(_bfin_dcache_init)
 #endif
diff --git a/arch/blackfin/mach-common/cplbhdlr.S b/arch/blackfin/mach-common/cplbhdlr.S
index b979067..2f3c72c 100644
--- a/arch/blackfin/mach-common/cplbhdlr.S
+++ b/arch/blackfin/mach-common/cplbhdlr.S
@@ -42,8 +42,6 @@
 
 .align 2
 
-.global __cplb_hdr;
-.type __cplb_hdr, STT_FUNC;
 ENTRY(__cplb_hdr)
 	R2 = SEQSTAT;
 
@@ -128,3 +126,5 @@
 	call _panic_cplb_error;
 	SP += 12;
 	JUMP _handle_bad_cplb;
+
+ENDPROC(__cplb_hdr)
diff --git a/arch/blackfin/mach-common/cplbinfo.c b/arch/blackfin/mach-common/cplbinfo.c
index d65fac3..caa9623 100644
--- a/arch/blackfin/mach-common/cplbinfo.c
+++ b/arch/blackfin/mach-common/cplbinfo.c
@@ -82,7 +82,7 @@
 	int entry = 0, used_cplb = 0;
 
 	if (type == CPLB_I) {
-		buf += sprintf(buf, "Instrction CPLB entry:\n");
+		buf += sprintf(buf, "Instruction CPLB entry:\n");
 		p_addr = ipdt_table;
 		p_data = ipdt_table + 1;
 		p_icount = ipdt_swapcount_table;
diff --git a/arch/blackfin/mach-common/cplbmgr.S b/arch/blackfin/mach-common/cplbmgr.S
index f5efc4b..e4b47e0 100644
--- a/arch/blackfin/mach-common/cplbmgr.S
+++ b/arch/blackfin/mach-common/cplbmgr.S
@@ -592,6 +592,7 @@
 	( R7:4,P5:3 ) = [SP++];
 	R0 = CPLB_RELOADED;
 	RTS;
+ENDPROC(_cplb_mgr)
 
 .data
 .align 4;
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S
index 7d03687..40045b1 100644
--- a/arch/blackfin/mach-common/entry.S
+++ b/arch/blackfin/mach-common/entry.S
@@ -103,6 +103,7 @@
 	if !cc jump _return_from_exception;
 	/* fall through */
 #endif
+ENDPROC(_ex_dcplb)
 
 ENTRY(_ex_icplb)
 	(R7:6,P5:4) = [sp++];
@@ -113,6 +114,7 @@
 	RESTORE_ALL_SYS
 	SP = RETN;
 	rtx;
+ENDPROC(_ex_icplb)
 
 ENTRY(_ex_spinlock)
 	/* Transform this into a syscall - twiddle the syscall vector.  */
@@ -123,6 +125,7 @@
 	[p5] = r7;
 	csync;
 	/* Fall through.  */
+ENDPROC(_ex_spinlock)
 
 ENTRY(_ex_syscall)
 	DEBUG_START_HWTRACE
@@ -131,6 +134,7 @@
 	raise 15;		/* invoked by TRAP #0, for sys call */
 	sp = retn;
 	rtx
+ENDPROC(_ex_syscall)
 
 ENTRY(_spinlock_bh)
 	SAVE_ALL_SYS
@@ -150,12 +154,14 @@
 	[SP + PT_R0] = R0;
 	RESTORE_ALL_SYS
 	rti;
+ENDPROC(_spinlock_bh)
 
 ENTRY(_ex_soft_bp)
 	r7 = retx;
 	r7 += -2;
 	retx = r7;
 	jump.s _ex_trap_c;
+ENDPROC(_ex_soft_bp)
 
 ENTRY(_ex_single_step)
 	r7 = retx;
@@ -191,6 +197,7 @@
 	ASTAT = [sp++];
 	sp = retn;
 	rtx;
+ENDPROC(_ex_soft_bp)
 
 ENTRY(_handle_bad_cplb)
 	/* To get here, we just tried and failed to change a CPLB
@@ -250,6 +257,7 @@
 	SP = RETN;
 	raise 5;
 	rtx;
+ENDPROC(_ex_trap_c)
 
 ENTRY(_exception_to_level5)
 	SAVE_ALL_SYS
@@ -314,6 +322,7 @@
 	call _ret_from_exception;
 	RESTORE_ALL_SYS
 	rti;
+ENDPROC(_exception_to_level5)
 
 ENTRY(_trap) /* Exception: 4th entry into system event table(supervisor mode)*/
 	/* Since the kernel stack can be anywhere, it's not guaranteed to be
@@ -342,6 +351,7 @@
 	r7 = -ENOSYS; 		/* signextending enough */
 	[sp + PT_R0] = r7;	/* return value from system call */
 	jump .Lsyscall_really_exit;
+ENDPROC(_trap)
 
 ENTRY(_kernel_execve)
 	link SIZEOF_PTREGS;
@@ -396,6 +406,7 @@
 1:
 	unlink;
 	rts;
+ENDPROC(_kernel_execve)
 
 ENTRY(_system_call)
 	/* Store IPEND */
@@ -503,6 +514,7 @@
 	r5 = [sp + PT_RESERVED];
 	rets = r5;
 	rts;
+ENDPROC(_system_call)
 
 _sys_trace:
 	call _syscall_trace;
@@ -531,6 +543,7 @@
 
 	call _syscall_trace;
 	jump .Lresume_userspace;
+ENDPROC(_sys_trace)
 
 ENTRY(_resume)
 	/*
@@ -580,6 +593,7 @@
 	 * in "new" task.
 	 */
 	rts;
+ENDPROC(_resume)
 
 ENTRY(_ret_from_exception)
 	p2.l = lo(IPEND);
@@ -638,6 +652,7 @@
 	syscfg = r0;
 5:
 	rts;
+ENDPROC(_ret_from_exception)
 
 ENTRY(_return_from_int)
 	/* If someone else already raised IRQ 15, do nothing.  */
@@ -680,6 +695,7 @@
 	rti;
 2:
 	rts;
+ENDPROC(_return_from_int)
 
 ENTRY(_lower_to_irq14)
 #if defined(ANOMALY_05000281)
@@ -745,6 +761,7 @@
 1:
 	RESTORE_CONTEXT
 	rti;
+ENDPROC(_lower_to_irq14)
 
 /* Make sure when we start, that the circular buffer is initialized properly
  * R0 and P0 are call clobbered, so we can use them here.
@@ -758,6 +775,7 @@
 	p0.l = _out_ptr_excause;
 	[p0] = r0;
 	rts;
+ENDPROC(_init_exception_buff)
 
 /*
  * Put these in the kernel data section - that should always be covered by
diff --git a/arch/blackfin/mach-common/interrupt.S b/arch/blackfin/mach-common/interrupt.S
index dd45664..b69f517 100644
--- a/arch/blackfin/mach-common/interrupt.S
+++ b/arch/blackfin/mach-common/interrupt.S
@@ -66,6 +66,7 @@
 	SP += 12;
 	/* - GDB stub fills this in by itself (if defined) */
 	rte;
+ENDPROC(_evt_emulation)
 #endif
 
 /* Common interrupt entry code.	 First we do CLI, then push
@@ -251,3 +252,4 @@
 #endif
 	call _system_call;
 	jump .Lcommon_restore_context;
+ENDPROC(_evt_system_call)
diff --git a/arch/blackfin/mach-common/ints-priority-dc.c b/arch/blackfin/mach-common/ints-priority-dc.c
index f3cf070..80943bb 100644
--- a/arch/blackfin/mach-common/ints-priority-dc.c
+++ b/arch/blackfin/mach-common/ints-priority-dc.c
@@ -4,7 +4,7 @@
  * Author:
  *
  * Created:      ?
- * Description:  Set up the interupt priorities
+ * Description:  Set up the interrupt priorities
  *
  * Modified:
  *               1996 Roman Zippel
diff --git a/arch/blackfin/mach-common/ints-priority-sc.c b/arch/blackfin/mach-common/ints-priority-sc.c
index 34b6228..2cfc7d5 100644
--- a/arch/blackfin/mach-common/ints-priority-sc.c
+++ b/arch/blackfin/mach-common/ints-priority-sc.c
@@ -4,7 +4,7 @@
  * Author:
  *
  * Created:      ?
- * Description:  Set up the interupt priorities
+ * Description:  Set up the interrupt priorities
  *
  * Modified:
  *               1996 Roman Zippel
diff --git a/arch/blackfin/mach-common/lock.S b/arch/blackfin/mach-common/lock.S
index 2cbb15b..386ac8d 100644
--- a/arch/blackfin/mach-common/lock.S
+++ b/arch/blackfin/mach-common/lock.S
@@ -155,6 +155,7 @@
 	( R7:0,P5:0 ) = [SP++];
 
 	RTS;
+ENDPROC(_cache_grab_lock)
 
 /* After the execution of critical code, the code is now locked into
  * the cache way. Now we need to set ILOC.
@@ -186,6 +187,7 @@
 
 	( R7:0,P5:0 ) = [SP++];
 	RTS;
+ENDPROC(_cache_lock)
 
 #endif	/* BLKFIN_CACHE_LOCK */
 
@@ -193,7 +195,6 @@
  */
 
 ENTRY(_read_iloc)
-
 	P1.H = (IMEM_CONTROL >> 16);
 	P1.L = (IMEM_CONTROL & 0xFFFF);
 	R1 = 0xF;
@@ -202,3 +203,4 @@
 	R0 = R0 & R1;
 
 	RTS;
+ENDPROC(_read_iloc)
diff --git a/arch/blackfin/mach-common/pm.c b/arch/blackfin/mach-common/pm.c
index afed524..150ef5d 100644
--- a/arch/blackfin/mach-common/pm.c
+++ b/arch/blackfin/mach-common/pm.c
@@ -39,7 +39,7 @@
 #include <asm/io.h>
 #include <asm/dpmc.h>
 #include <asm/irq.h>
-
+#include <asm/gpio.h>
 
 #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_H
 #define WAKEUP_TYPE	PM_WAKE_HIGH
diff --git a/arch/blackfin/mm/blackfin_sram.c b/arch/blackfin/mm/blackfin_sram.c
index dd0c650..6810792 100644
--- a/arch/blackfin/mm/blackfin_sram.c
+++ b/arch/blackfin/mm/blackfin_sram.c
@@ -7,7 +7,7 @@
  * Description:  SRAM driver for Blackfin ADSP-BF5xx
  *
  * Modified:
- *               Copyright 2004-2006 Analog Devices Inc.
+ *               Copyright 2004-2007 Analog Devices Inc.
  *
  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
  *
@@ -63,6 +63,7 @@
 	void *paddr;
 	int size;
 	int flag;
+	pid_t pid;
 };
 
 static struct l1_sram_piece l1_ssram[CONFIG_L1_MAX_PIECE];
@@ -80,7 +81,7 @@
 #endif
 
 /* L1 Scratchpad SRAM initialization function */
-void l1sram_init(void)
+void __init l1sram_init(void)
 {
 	printk(KERN_INFO "Blackfin Scratchpad data SRAM: %d KB\n",
 	       L1_SCRATCH_LENGTH >> 10);
@@ -94,42 +95,43 @@
 	spin_lock_init(&l1sram_lock);
 }
 
-void l1_data_sram_init(void)
+void __init l1_data_sram_init(void)
 {
 #if L1_DATA_A_LENGTH != 0
-	printk(KERN_INFO "Blackfin DATA_A SRAM: %d KB\n",
-	       L1_DATA_A_LENGTH >> 10);
-
 	memset(&l1_data_A_sram, 0x00, sizeof(l1_data_A_sram));
-	l1_data_A_sram[0].paddr = (void*)L1_DATA_A_START +
-		(_ebss_l1 - _sdata_l1);
+	l1_data_A_sram[0].paddr = (void *)L1_DATA_A_START +
+					(_ebss_l1 - _sdata_l1);
 	l1_data_A_sram[0].size = L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1);
 	l1_data_A_sram[0].flag = SRAM_SLT_FREE;
+
+	printk(KERN_INFO "Blackfin Data A SRAM: %d KB (%d KB free)\n",
+	       L1_DATA_A_LENGTH >> 10, l1_data_A_sram[0].size >> 10);
 #endif
 #if L1_DATA_B_LENGTH != 0
-	printk(KERN_INFO "Blackfin DATA_B SRAM: %d KB\n",
-	       L1_DATA_B_LENGTH >> 10);
-
 	memset(&l1_data_B_sram, 0x00, sizeof(l1_data_B_sram));
-	l1_data_B_sram[0].paddr = (void*)L1_DATA_B_START;
-	l1_data_B_sram[0].size = L1_DATA_B_LENGTH;
+	l1_data_B_sram[0].paddr = (void *)L1_DATA_B_START +
+				(_ebss_b_l1 - _sdata_b_l1);
+	l1_data_B_sram[0].size = L1_DATA_B_LENGTH - (_ebss_b_l1 - _sdata_b_l1);
 	l1_data_B_sram[0].flag = SRAM_SLT_FREE;
+
+	printk(KERN_INFO "Blackfin Data B SRAM: %d KB (%d KB free)\n",
+	       L1_DATA_B_LENGTH >> 10, l1_data_B_sram[0].size >> 10);
 #endif
 
 	/* mutex initialize */
 	spin_lock_init(&l1_data_sram_lock);
 }
 
-void l1_inst_sram_init(void)
+void __init l1_inst_sram_init(void)
 {
 #if L1_CODE_LENGTH != 0
-	printk(KERN_INFO "Blackfin Instruction SRAM: %d KB\n",
-	       L1_CODE_LENGTH >> 10);
-
 	memset(&l1_inst_sram, 0x00, sizeof(l1_inst_sram));
 	l1_inst_sram[0].paddr = (void*)L1_CODE_START + (_etext_l1 - _stext_l1);
 	l1_inst_sram[0].size = L1_CODE_LENGTH - (_etext_l1 - _stext_l1);
 	l1_inst_sram[0].flag = SRAM_SLT_FREE;
+
+	printk(KERN_INFO "Blackfin Instruction SRAM: %d KB (%d KB free)\n",
+	       L1_CODE_LENGTH >> 10, l1_inst_sram[0].size >> 10);
 #endif
 
 	/* mutex initialize */
@@ -149,12 +151,13 @@
 	size = (size + 3) & ~3;
 
 	/* not use the good method to match the best slot !!! */
-	/* search an available memeory slot */
+	/* search an available memory slot */
 	for (i = 0; i < count; i++) {
 		if ((pfree[i].flag == SRAM_SLT_FREE)
 		    && (pfree[i].size >= size)) {
 			addr = pfree[i].paddr;
 			pfree[i].flag = SRAM_SLT_ALLOCATED;
+			pfree[i].pid = current->pid;
 			index = i;
 			break;
 		}
@@ -162,10 +165,11 @@
 	if (i >= count)
 		return NULL;
 
-	/* updated the NULL memeory slot !!! */
+	/* updated the NULL memory slot !!! */
 	if (pfree[i].size > size) {
 		for (i = 0; i < count; i++) {
 			if (pfree[i].flag == SRAM_SLT_NULL) {
+				pfree[i].pid = 0;
 				pfree[i].flag = SRAM_SLT_FREE;
 				pfree[i].paddr = addr + size;
 				pfree[i].size = pfree[index].size - size;
@@ -186,7 +190,7 @@
 	int i, index = -1;
 	void *addr = NULL;
 
-	/* search an available memeory slot */
+	/* search an available memory slot */
 	for (i = 0; i < count; i++) {
 		if (pfree[i].flag == SRAM_SLT_FREE && pfree[i].size > best) {
 			addr = pfree[i].paddr;
@@ -198,13 +202,15 @@
 		return NULL;
 	*psize = best;
 
+	pfree[index].pid = current->pid;
 	pfree[index].flag = SRAM_SLT_ALLOCATED;
 	return addr;
 }
 
 /* L1 memory free function */
 static int _l1_sram_free(const void *addr,
-			 struct l1_sram_piece *pfree, int count)
+			struct l1_sram_piece *pfree,
+			int count)
 {
 	int i, index = 0;
 
@@ -222,12 +228,14 @@
 	if (i >= count)
 		return -1;
 
+	pfree[index].pid = 0;
 	pfree[index].flag = SRAM_SLT_FREE;
 
 	/* link the next address slot */
 	for (i = 0; i < count; i++) {
 		if (((pfree[index].paddr + pfree[index].size) == pfree[i].paddr)
 		    && (pfree[i].flag == SRAM_SLT_FREE)) {
+			pfree[i].pid = 0;
 			pfree[i].flag = SRAM_SLT_NULL;
 			pfree[index].size += pfree[i].size;
 			pfree[index].flag = SRAM_SLT_FREE;
@@ -538,3 +546,64 @@
 	return addr;
 }
 EXPORT_SYMBOL(sram_alloc_with_lsl);
+
+#ifdef CONFIG_PROC_FS
+/* Once we get a real allocator, we'll throw all of this away.
+ * Until then, we need some sort of visibility into the L1 alloc.
+ */
+static void _l1sram_proc_read(char *buf, int *len, const char *desc,
+		struct l1_sram_piece *pfree, const int array_size)
+{
+	int i;
+
+	*len += sprintf(&buf[*len], "--- L1 %-14s Size  PID State\n", desc);
+	for (i = 0; i < array_size; ++i) {
+		const char *alloc_type;
+		switch (pfree[i].flag) {
+		case SRAM_SLT_NULL:      alloc_type = "NULL"; break;
+		case SRAM_SLT_FREE:      alloc_type = "FREE"; break;
+		case SRAM_SLT_ALLOCATED: alloc_type = "ALLOCATED"; break;
+		default:                 alloc_type = "????"; break;
+		}
+		*len += sprintf(&buf[*len], "%p-%p %8i %4i %s\n",
+			pfree[i].paddr, pfree[i].paddr + pfree[i].size,
+			pfree[i].size, pfree[i].pid, alloc_type);
+	}
+}
+static int l1sram_proc_read(char *buf, char **start, off_t offset, int count,
+		int *eof, void *data)
+{
+	int len = 0;
+
+	_l1sram_proc_read(buf, &len, "Scratchpad",
+			l1_ssram, ARRAY_SIZE(l1_ssram));
+#if L1_DATA_A_LENGTH != 0
+	_l1sram_proc_read(buf, &len, "Data A",
+			l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram));
+#endif
+#if L1_DATA_B_LENGTH != 0
+	_l1sram_proc_read(buf, &len, "Data B",
+			l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram));
+#endif
+#if L1_CODE_LENGTH != 0
+	_l1sram_proc_read(buf, &len, "Instruction",
+			l1_inst_sram, ARRAY_SIZE(l1_inst_sram));
+#endif
+
+	return len;
+}
+
+static int __init l1sram_proc_init(void)
+{
+	struct proc_dir_entry *ptr;
+	ptr = create_proc_entry("sram", S_IFREG | S_IRUGO, NULL);
+	if (!ptr) {
+		printk(KERN_WARNING "unable to create /proc/sram\n");
+		return -1;
+	}
+	ptr->owner = THIS_MODULE;
+	ptr->read_proc = l1sram_proc_read;
+	return 0;
+}
+late_initcall(l1sram_proc_init);
+#endif
diff --git a/arch/blackfin/mm/init.c b/arch/blackfin/mm/init.c
index d6cf105..570356d 100644
--- a/arch/blackfin/mm/init.c
+++ b/arch/blackfin/mm/init.c
@@ -7,7 +7,7 @@
  * Description:
  *
  * Modified:
- *               Copyright 2004-2006 Analog Devices Inc.
+ *               Copyright 2004-2007 Analog Devices Inc.
  *
  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
  *
@@ -53,7 +53,7 @@
 
 unsigned long empty_zero_page;
 
-void show_mem(void)
+void __init show_mem(void)
 {
 	unsigned long i;
 	int free = 0, total = 0, reserved = 0, shared = 0;
@@ -86,7 +86,7 @@
  * The parameters are pointers to where to stick the starting and ending
  * addresses  of available kernel virtual memory.
  */
-void paging_init(void)
+void __init paging_init(void)
 {
 	/*
 	 * make sure start_mem is page aligned,  otherwise bootmem and
@@ -125,7 +125,7 @@
 	}
 }
 
-void mem_init(void)
+void __init mem_init(void)
 {
 	unsigned int codek = 0, datak = 0, initk = 0;
 	unsigned long tmp;
@@ -169,7 +169,7 @@
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
-void free_initrd_mem(unsigned long start, unsigned long end)
+void __init free_initrd_mem(unsigned long start, unsigned long end)
 {
 	int pages = 0;
 	for (; start < end; start += PAGE_SIZE) {
@@ -183,14 +183,14 @@
 }
 #endif
 
-void free_initmem(void)
+void __init free_initmem(void)
 {
 #ifdef CONFIG_RAMKERNEL
 	unsigned long addr;
-/*
- *	the following code should be cool even if these sections
- *	are not page aligned.
- */
+	/*
+	 *	the following code should be cool even if these sections
+	 *	are not page aligned.
+	 */
 	addr = PAGE_ALIGN((unsigned long)(__init_begin));
 	/* next to check that the page we free is not a partial page */
 	for (; addr + PAGE_SIZE < (unsigned long)(__init_end);
diff --git a/arch/i386/kernel/cpu/perfctr-watchdog.c b/arch/i386/kernel/cpu/perfctr-watchdog.c
index 2b04c8f..f0b6763 100644
--- a/arch/i386/kernel/cpu/perfctr-watchdog.c
+++ b/arch/i386/kernel/cpu/perfctr-watchdog.c
@@ -28,7 +28,7 @@
 	void (*unreserve)(void);
 	int (*setup)(unsigned nmi_hz);
 	void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
-	void (*stop)(void *);
+	void (*stop)(void);
 	unsigned perfctr;
 	unsigned evntsel;
 	u64 checkbit;
@@ -142,7 +142,7 @@
 	if (atomic_read(&nmi_active) <= 0)
 		return;
 
-	on_each_cpu(wd_ops->stop, NULL, 0, 1);
+	on_each_cpu(stop_apic_nmi_watchdog, NULL, 0, 1);
 	wd_ops->unreserve();
 
 	BUG_ON(atomic_read(&nmi_active) != 0);
@@ -255,7 +255,7 @@
 	return 1;
 }
 
-static void single_msr_stop_watchdog(void *arg)
+static void single_msr_stop_watchdog(void)
 {
 	struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
 
@@ -276,8 +276,8 @@
 
 static void single_msr_unreserve(void)
 {
-	release_evntsel_nmi(wd_ops->perfctr);
-	release_perfctr_nmi(wd_ops->evntsel);
+	release_evntsel_nmi(wd_ops->evntsel);
+	release_perfctr_nmi(wd_ops->perfctr);
 }
 
 static void single_msr_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz)
@@ -442,7 +442,7 @@
 	return 1;
 }
 
-static void stop_p4_watchdog(void *arg)
+static void stop_p4_watchdog(void)
 {
 	struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
 	wrmsr(wd->cccr_msr, 0, 0);
@@ -475,10 +475,10 @@
 {
 #ifdef CONFIG_SMP
 	if (smp_num_siblings > 1)
-		release_evntsel_nmi(MSR_P4_IQ_PERFCTR1);
+		release_perfctr_nmi(MSR_P4_IQ_PERFCTR1);
 #endif
-	release_evntsel_nmi(MSR_P4_IQ_PERFCTR0);
-	release_perfctr_nmi(MSR_P4_CRU_ESCR0);
+	release_evntsel_nmi(MSR_P4_CRU_ESCR0);
+	release_perfctr_nmi(MSR_P4_IQ_PERFCTR0);
 }
 
 static void p4_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz)
@@ -614,6 +614,12 @@
 		probe_nmi_watchdog();
 		if (!wd_ops)
 			return -1;
+
+		if (!wd_ops->reserve()) {
+			printk(KERN_ERR
+				"NMI watchdog: cannot reserve perfctrs\n");
+			return -1;
+		}
 	}
 
 	if (!(wd_ops->setup(nmi_hz))) {
@@ -628,7 +634,7 @@
 void lapic_watchdog_stop(void)
 {
 	if (wd_ops)
-		wd_ops->stop(NULL);
+		wd_ops->stop();
 }
 
 unsigned lapic_adjust_nmi_hz(unsigned hz)
diff --git a/arch/mips/kernel/smp-mt.c b/arch/mips/kernel/smp-mt.c
index 64b62bd..b8fa7dd 100644
--- a/arch/mips/kernel/smp-mt.c
+++ b/arch/mips/kernel/smp-mt.c
@@ -129,13 +129,13 @@
 
 static struct irqaction irq_resched = {
 	.handler	= ipi_resched_interrupt,
-	.flags		= IRQF_DISABLED,
+	.flags		= IRQF_DISABLED|IRQF_PERCPU,
 	.name		= "IPI_resched"
 };
 
 static struct irqaction irq_call = {
 	.handler	= ipi_call_interrupt,
-	.flags		= IRQF_DISABLED,
+	.flags		= IRQF_DISABLED|IRQF_PERCPU,
 	.name		= "IPI_call"
 };
 
@@ -275,10 +275,7 @@
 	setup_irq(cpu_ipi_resched_irq, &irq_resched);
 	setup_irq(cpu_ipi_call_irq, &irq_call);
 
-	/* need to mark IPI's as IRQ_PER_CPU */
-	irq_desc[cpu_ipi_resched_irq].status |= IRQ_PER_CPU;
 	set_irq_handler(cpu_ipi_resched_irq, handle_percpu_irq);
-	irq_desc[cpu_ipi_call_irq].status |= IRQ_PER_CPU;
 	set_irq_handler(cpu_ipi_call_irq, handle_percpu_irq);
 }
 
@@ -326,8 +323,11 @@
 
 void prom_init_secondary(void)
 {
+	/* Enable per-cpu interrupts */
+
+	/* This is Malta specific: IPI,performance and timer inetrrupts */
 	write_c0_status((read_c0_status() & ~ST0_IM ) |
-	                (STATUSF_IP0 | STATUSF_IP1 | STATUSF_IP7));
+	                (STATUSF_IP0 | STATUSF_IP1 | STATUSF_IP6 | STATUSF_IP7));
 }
 
 void prom_smp_finish(void)
diff --git a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c
index 751b4a1..7def1ff 100644
--- a/arch/mips/kernel/time.c
+++ b/arch/mips/kernel/time.c
@@ -199,6 +199,30 @@
 EXPORT_SYMBOL(null_perf_irq);
 EXPORT_SYMBOL(perf_irq);
 
+/*
+ * Performance counter IRQ or -1 if shared with timer
+ */
+int mipsxx_perfcount_irq;
+EXPORT_SYMBOL(mipsxx_perfcount_irq);
+
+/*
+ * Possibly handle a performance counter interrupt.
+ * Return true if the timer interrupt should not be checked
+ */
+static inline int handle_perf_irq (int r2)
+{
+	/*
+	 * The performance counter overflow interrupt may be shared with the
+	 * timer interrupt (mipsxx_perfcount_irq < 0). If it is and a
+	 * performance counter has overflowed (perf_irq() == IRQ_HANDLED)
+	 * and we can't reliably determine if a counter interrupt has also
+	 * happened (!r2) then don't check for a timer interrupt.
+	 */
+	return (mipsxx_perfcount_irq < 0) &&
+		perf_irq() == IRQ_HANDLED &&
+		!r2;
+}
+
 asmlinkage void ll_timer_interrupt(int irq)
 {
 	int r2 = cpu_has_mips_r2;
@@ -206,19 +230,13 @@
 	irq_enter();
 	kstat_this_cpu.irqs[irq]++;
 
-	/*
-	 * Suckage alert:
-	 * Before R2 of the architecture there was no way to see if a
-	 * performance counter interrupt was pending, so we have to run the
-	 * performance counter interrupt handler anyway.
-	 */
-	if (!r2 || (read_c0_cause() & (1 << 26)))
-		if (perf_irq())
-			goto out;
+	if (handle_perf_irq(r2))
+		goto out;
 
-	/* we keep interrupt disabled all the time */
-	if (!r2 || (read_c0_cause() & (1 << 30)))
-		timer_interrupt(irq, NULL);
+	if (r2 && ((read_c0_cause() & (1 << 30)) == 0))
+		goto out;
+
+	timer_interrupt(irq, NULL);
 
 out:
 	irq_exit();
@@ -258,7 +276,7 @@
 
 static struct irqaction timer_irqaction = {
 	.handler = timer_interrupt,
-	.flags = IRQF_DISABLED,
+	.flags = IRQF_DISABLED | IRQF_PERCPU,
 	.name = "timer",
 };
 
diff --git a/arch/mips/mips-boards/generic/init.c b/arch/mips/mips-boards/generic/init.c
index 88e9c2a..4eabc1e 100644
--- a/arch/mips/mips-boards/generic/init.c
+++ b/arch/mips/mips-boards/generic/init.c
@@ -57,7 +57,8 @@
 
 int init_debug = 0;
 
-unsigned int mips_revision_corid;
+int mips_revision_corid;
+int mips_revision_sconid;
 
 /* Bonito64 system controller register base. */
 unsigned long _pcictrl_bonito;
@@ -275,13 +276,38 @@
 		else
 			mips_revision_corid = MIPS_REVISION_CORID_CORE_EMUL_MSC;
 	}
-	switch(mips_revision_corid) {
+
+	mips_revision_sconid = MIPS_REVISION_SCONID;
+	if (mips_revision_sconid == MIPS_REVISION_SCON_OTHER) {
+		switch (mips_revision_corid) {
+		case MIPS_REVISION_CORID_QED_RM5261:
+		case MIPS_REVISION_CORID_CORE_LV:
+		case MIPS_REVISION_CORID_CORE_FPGA:
+		case MIPS_REVISION_CORID_CORE_FPGAR2:
+			mips_revision_sconid = MIPS_REVISION_SCON_GT64120;
+			break;
+		case MIPS_REVISION_CORID_CORE_EMUL_BON:
+		case MIPS_REVISION_CORID_BONITO64:
+		case MIPS_REVISION_CORID_CORE_20K:
+			mips_revision_sconid = MIPS_REVISION_SCON_BONITO;
+			break;
+		case MIPS_REVISION_CORID_CORE_MSC:
+		case MIPS_REVISION_CORID_CORE_FPGA2:
+		case MIPS_REVISION_CORID_CORE_FPGA3:
+		case MIPS_REVISION_CORID_CORE_24K:
+		case MIPS_REVISION_CORID_CORE_EMUL_MSC:
+			mips_revision_sconid = MIPS_REVISION_SCON_SOCIT;
+			break;
+		default:
+			mips_display_message("CC Error");
+			while (1);   /* We die here... */
+		}
+	}
+
+	switch (mips_revision_sconid) {
 		u32 start, map, mask, data;
 
-	case MIPS_REVISION_CORID_QED_RM5261:
-	case MIPS_REVISION_CORID_CORE_LV:
-	case MIPS_REVISION_CORID_CORE_FPGA:
-	case MIPS_REVISION_CORID_CORE_FPGAR2:
+	case MIPS_REVISION_SCON_GT64120:
 		/*
 		 * Setup the North bridge to do Master byte-lane swapping
 		 * when running in bigendian.
@@ -305,9 +331,7 @@
 		set_io_port_base(MALTA_GT_PORT_BASE);
 		break;
 
-	case MIPS_REVISION_CORID_CORE_EMUL_BON:
-	case MIPS_REVISION_CORID_BONITO64:
-	case MIPS_REVISION_CORID_CORE_20K:
+	case MIPS_REVISION_SCON_BONITO:
 		_pcictrl_bonito_pcicfg = (unsigned long)ioremap(BONITO_PCICFG_BASE, BONITO_PCICFG_SIZE);
 
 		/*
@@ -334,13 +358,10 @@
 		set_io_port_base(MALTA_BONITO_PORT_BASE);
 		break;
 
-	case MIPS_REVISION_CORID_CORE_MSC:
-	case MIPS_REVISION_CORID_CORE_FPGA2:
-	case MIPS_REVISION_CORID_CORE_FPGA3:
-	case MIPS_REVISION_CORID_CORE_24K:
-	case MIPS_REVISION_CORID_CORE_EMUL_MSC:
+	case MIPS_REVISION_SCON_SOCIT:
+	case MIPS_REVISION_SCON_ROCIT:
 		_pcictrl_msc = (unsigned long)ioremap(MIPS_MSC01_PCI_REG_BASE, 0x2000);
-
+	mips_pci_controller:
 		mb();
 		MSC_READ(MSC01_PCI_CFG, data);
 		MSC_WRITE(MSC01_PCI_CFG, data & ~MSC01_PCI_CFG_EN_BIT);
@@ -374,10 +395,15 @@
 		set_io_port_base(MALTA_MSC_PORT_BASE);
 		break;
 
+	case MIPS_REVISION_SCON_SOCITSC:
+	case MIPS_REVISION_SCON_SOCITSCP:
+		_pcictrl_msc = (unsigned long)ioremap(MIPS_SOCITSC_PCI_REG_BASE, 0x2000);
+		goto mips_pci_controller;
+
 	default:
-		/* Unknown Core card */
-		mips_display_message("CC Error");
-		while(1);   /* We die here... */
+		/* Unknown system controller */
+		mips_display_message("SC Error");
+		while (1);   /* We die here... */
 	}
 #endif
 	board_nmi_handler_setup = mips_nmi_setup;
diff --git a/arch/mips/mips-boards/generic/pci.c b/arch/mips/mips-boards/generic/pci.c
index f98d60f..c985220 100644
--- a/arch/mips/mips-boards/generic/pci.c
+++ b/arch/mips/mips-boards/generic/pci.c
@@ -92,11 +92,8 @@
 	struct pci_controller *controller;
 	resource_size_t start, end, map, start1, end1, map1, map2, map3, mask;
 
-	switch (mips_revision_corid) {
-	case MIPS_REVISION_CORID_QED_RM5261:
-	case MIPS_REVISION_CORID_CORE_LV:
-	case MIPS_REVISION_CORID_CORE_FPGA:
-	case MIPS_REVISION_CORID_CORE_FPGAR2:
+	switch (mips_revision_sconid) {
+	case MIPS_REVISION_SCON_GT64120:
 		/*
 		 * Due to a bug in the Galileo system controller, we need
 		 * to setup the PCI BAR for the Galileo internal registers.
@@ -161,9 +158,7 @@
 		controller = &gt64120_controller;
 		break;
 
-	case MIPS_REVISION_CORID_BONITO64:
-	case MIPS_REVISION_CORID_CORE_20K:
-	case MIPS_REVISION_CORID_CORE_EMUL_BON:
+	case MIPS_REVISION_SCON_BONITO:
 		/* Set up resource ranges from the controller's registers.  */
 		map = BONITO_PCIMAP;
 		map1 = (BONITO_PCIMAP & BONITO_PCIMAP_PCIMAP_LO0) >>
@@ -195,11 +190,10 @@
 		controller = &bonito64_controller;
 		break;
 
-	case MIPS_REVISION_CORID_CORE_MSC:
-	case MIPS_REVISION_CORID_CORE_FPGA2:
-	case MIPS_REVISION_CORID_CORE_FPGA3:
-	case MIPS_REVISION_CORID_CORE_24K:
-	case MIPS_REVISION_CORID_CORE_EMUL_MSC:
+	case MIPS_REVISION_SCON_SOCIT:
+	case MIPS_REVISION_SCON_ROCIT:
+	case MIPS_REVISION_SCON_SOCITSC:
+	case MIPS_REVISION_SCON_SOCITSCP:
 		/* Set up resource ranges from the controller's registers.  */
 		MSC_READ(MSC01_PCI_SC2PMBASL, start);
 		MSC_READ(MSC01_PCI_SC2PMMSKL, mask);
diff --git a/arch/mips/mips-boards/generic/time.c b/arch/mips/mips-boards/generic/time.c
index b41db9e..8f1000f 100644
--- a/arch/mips/mips-boards/generic/time.c
+++ b/arch/mips/mips-boards/generic/time.c
@@ -53,9 +53,8 @@
 
 unsigned long cpu_khz;
 
-#define CPUCTR_IMASKBIT (0x100 << MIPSCPU_INT_CPUCTR)
-
 static int mips_cpu_timer_irq;
+extern int mipsxx_perfcount_irq;
 extern void smtc_timer_broadcast(int);
 
 static void mips_timer_dispatch(void)
@@ -63,6 +62,11 @@
 	do_IRQ(mips_cpu_timer_irq);
 }
 
+static void mips_perf_dispatch(void)
+{
+	do_IRQ(mipsxx_perfcount_irq);
+}
+
 /*
  * Redeclare until I get around mopping the timer code insanity on MIPS.
  */
@@ -70,6 +74,24 @@
 
 extern int (*perf_irq)(void);
 
+/*
+ * Possibly handle a performance counter interrupt.
+ * Return true if the timer interrupt should not be checked
+ */
+static inline int handle_perf_irq (int r2)
+{
+	/*
+	 * The performance counter overflow interrupt may be shared with the
+	 * timer interrupt (mipsxx_perfcount_irq < 0). If it is and a
+	 * performance counter has overflowed (perf_irq() == IRQ_HANDLED)
+	 * and we can't reliably determine if a counter interrupt has also
+	 * happened (!r2) then don't check for a timer interrupt.
+	 */
+	return (mipsxx_perfcount_irq < 0) &&
+		perf_irq() == IRQ_HANDLED &&
+		!r2;
+}
+
 irqreturn_t mips_timer_interrupt(int irq, void *dev_id)
 {
 	int cpu = smp_processor_id();
@@ -92,8 +114,7 @@
 	 * We could be here due to timer interrupt,
 	 * perf counter overflow, or both.
 	 */
-	if (read_c0_cause() & (1 << 26))
-		perf_irq();
+	(void) handle_perf_irq(1);
 
 	if (read_c0_cause() & (1 << 30)) {
 		/*
@@ -115,19 +136,19 @@
 #else /* CONFIG_MIPS_MT_SMTC */
 	int r2 = cpu_has_mips_r2;
 
+	if (handle_perf_irq(r2))
+		goto out;
+
+	if (r2 && ((read_c0_cause() & (1 << 30)) == 0))
+		goto out;
+
 	if (cpu == 0) {
 		/*
 		 * CPU 0 handles the global timer interrupt job and process
 		 * accounting resets count/compare registers to trigger next
 		 * timer int.
 		 */
-		if (!r2 || (read_c0_cause() & (1 << 26)))
-			if (perf_irq())
-				goto out;
-
-		/* we keep interrupt disabled all the time */
-		if (!r2 || (read_c0_cause() & (1 << 30)))
-			timer_interrupt(irq, NULL);
+		timer_interrupt(irq, NULL);
 	} else {
 		/* Everyone else needs to reset the timer int here as
 		   ll_local_timer_interrupt doesn't */
@@ -225,35 +246,85 @@
 	mips_scroll_message();
 }
 
+irqreturn_t mips_perf_interrupt(int irq, void *dev_id)
+{
+	return perf_irq();
+}
+
+static struct irqaction perf_irqaction = {
+	.handler = mips_perf_interrupt,
+	.flags = IRQF_DISABLED | IRQF_PERCPU,
+	.name = "performance",
+};
+
+void __init plat_perf_setup(struct irqaction *irq)
+{
+	int hwint = 0;
+	mipsxx_perfcount_irq = -1;
+
+#ifdef MSC01E_INT_BASE
+	if (cpu_has_veic) {
+		set_vi_handler (MSC01E_INT_PERFCTR, mips_perf_dispatch);
+		mipsxx_perfcount_irq = MSC01E_INT_BASE + MSC01E_INT_PERFCTR;
+	} else
+#endif
+	if (cpu_has_mips_r2) {
+		/*
+		 * Read IntCtl.IPPCI to determine the performance
+		 * counter interrupt
+		 */
+		hwint = (read_c0_intctl () >> 26) & 7;
+		if (hwint != MIPSCPU_INT_CPUCTR) {
+			if (cpu_has_vint)
+				set_vi_handler (hwint, mips_perf_dispatch);
+			mipsxx_perfcount_irq = MIPSCPU_INT_BASE + hwint;
+		}
+	}
+	if (mipsxx_perfcount_irq >= 0) {
+#ifdef CONFIG_MIPS_MT_SMTC
+		setup_irq_smtc(mipsxx_perfcount_irq, irq, 0x100 << hwint);
+#else
+		setup_irq(mipsxx_perfcount_irq, irq);
+#endif /* CONFIG_MIPS_MT_SMTC */
+#ifdef CONFIG_SMP
+		set_irq_handler(mipsxx_perfcount_irq, handle_percpu_irq);
+#endif
+	}
+}
+
 void __init plat_timer_setup(struct irqaction *irq)
 {
+	int hwint = 0;
 #ifdef MSC01E_INT_BASE
 	if (cpu_has_veic) {
 		set_vi_handler (MSC01E_INT_CPUCTR, mips_timer_dispatch);
 		mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
-	} else
+	}
+	else
 #endif
 	{
+		if (cpu_has_mips_r2)
+			/*
+			 * Read IntCtl.IPTI to determine the timer interrupt
+			 */
+			hwint = (read_c0_intctl () >> 29) & 7;
+		else
+			hwint = MIPSCPU_INT_CPUCTR;
 		if (cpu_has_vint)
-			set_vi_handler (MIPSCPU_INT_CPUCTR, mips_timer_dispatch);
-		mips_cpu_timer_irq = MIPSCPU_INT_BASE + MIPSCPU_INT_CPUCTR;
+			set_vi_handler (hwint, mips_timer_dispatch);
+		mips_cpu_timer_irq = MIPSCPU_INT_BASE + hwint;
 	}
 
-
 	/* we are using the cpu counter for timer interrupts */
 	irq->handler = mips_timer_interrupt;	/* we use our own handler */
 #ifdef CONFIG_MIPS_MT_SMTC
-	setup_irq_smtc(mips_cpu_timer_irq, irq, CPUCTR_IMASKBIT);
+	setup_irq_smtc(mips_cpu_timer_irq, irq, 0x100 << hwint);
 #else
 	setup_irq(mips_cpu_timer_irq, irq);
 #endif /* CONFIG_MIPS_MT_SMTC */
-
 #ifdef CONFIG_SMP
-	/* irq_desc(riptor) is a global resource, when the interrupt overlaps
-	   on seperate cpu's the first one tries to handle the second interrupt.
-	   The effect is that the int remains disabled on the second cpu.
-	   Mark the interrupt with IRQ_PER_CPU to avoid any confusion */
-	irq_desc[mips_cpu_timer_irq].status |= IRQ_PER_CPU;
 	set_irq_handler(mips_cpu_timer_irq, handle_percpu_irq);
 #endif
+
+	plat_perf_setup(&perf_irqaction);
 }
diff --git a/arch/mips/mips-boards/malta/malta_int.c b/arch/mips/mips-boards/malta/malta_int.c
index 1cd830e..1668cc2 100644
--- a/arch/mips/mips-boards/malta/malta_int.c
+++ b/arch/mips/mips-boards/malta/malta_int.c
@@ -53,25 +53,19 @@
 	 * Determine highest priority pending interrupt by performing
 	 * a PCI Interrupt Acknowledge cycle.
 	 */
-	switch(mips_revision_corid) {
-	case MIPS_REVISION_CORID_CORE_MSC:
-	case MIPS_REVISION_CORID_CORE_FPGA2:
-	case MIPS_REVISION_CORID_CORE_FPGA3:
-	case MIPS_REVISION_CORID_CORE_24K:
-	case MIPS_REVISION_CORID_CORE_EMUL_MSC:
+	switch (mips_revision_sconid) {
+	case MIPS_REVISION_SCON_SOCIT:
+	case MIPS_REVISION_SCON_ROCIT:
+	case MIPS_REVISION_SCON_SOCITSC:
+	case MIPS_REVISION_SCON_SOCITSCP:
 	        MSC_READ(MSC01_PCI_IACK, irq);
 		irq &= 0xff;
 		break;
-	case MIPS_REVISION_CORID_QED_RM5261:
-	case MIPS_REVISION_CORID_CORE_LV:
-	case MIPS_REVISION_CORID_CORE_FPGA:
-	case MIPS_REVISION_CORID_CORE_FPGAR2:
+	case MIPS_REVISION_SCON_GT64120:
 		irq = GT_READ(GT_PCI0_IACK_OFS);
 		irq &= 0xff;
 		break;
-	case MIPS_REVISION_CORID_BONITO64:
-	case MIPS_REVISION_CORID_CORE_20K:
-	case MIPS_REVISION_CORID_CORE_EMUL_BON:
+	case MIPS_REVISION_SCON_BONITO:
 		/* The following will generate a PCI IACK cycle on the
 		 * Bonito controller. It's a little bit kludgy, but it
 		 * was the easiest way to implement it in hardware at
@@ -89,7 +83,7 @@
 		BONITO_PCIMAP_CFG = 0;
 		break;
 	default:
-	        printk("Unknown Core card, don't know the system controller.\n");
+	        printk("Unknown system controller.\n");
 		return -1;
 	}
 	return irq;
@@ -144,27 +138,21 @@
 	   Do it for the others too.
 	*/
 
-        switch(mips_revision_corid) {
-        case MIPS_REVISION_CORID_CORE_MSC:
-        case MIPS_REVISION_CORID_CORE_FPGA2:
-        case MIPS_REVISION_CORID_CORE_FPGA3:
-        case MIPS_REVISION_CORID_CORE_24K:
-        case MIPS_REVISION_CORID_CORE_EMUL_MSC:
+	switch (mips_revision_sconid) {
+        case MIPS_REVISION_SCON_SOCIT:
+	case MIPS_REVISION_SCON_ROCIT:
+	case MIPS_REVISION_SCON_SOCITSC:
+	case MIPS_REVISION_SCON_SOCITSCP:
                 ll_msc_irq();
                 break;
-        case MIPS_REVISION_CORID_QED_RM5261:
-        case MIPS_REVISION_CORID_CORE_LV:
-        case MIPS_REVISION_CORID_CORE_FPGA:
-        case MIPS_REVISION_CORID_CORE_FPGAR2:
+        case MIPS_REVISION_SCON_GT64120:
                 intrcause = GT_READ(GT_INTRCAUSE_OFS);
                 datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
                 datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
                 printk("GT_INTRCAUSE = %08x\n", intrcause);
                 printk("GT_CPUERR_ADDR = %02x%08x\n", datahi, datalo);
                 break;
-        case MIPS_REVISION_CORID_BONITO64:
-        case MIPS_REVISION_CORID_CORE_20K:
-        case MIPS_REVISION_CORID_CORE_EMUL_BON:
+        case MIPS_REVISION_SCON_BONITO:
                 pcibadaddr = BONITO_PCIBADADDR;
                 pcimstat = BONITO_PCIMSTAT;
                 intisr = BONITO_INTISR;
diff --git a/arch/mips/mips-boards/malta/malta_setup.c b/arch/mips/mips-boards/malta/malta_setup.c
index c14b7bf..8f1b78d 100644
--- a/arch/mips/mips-boards/malta/malta_setup.c
+++ b/arch/mips/mips-boards/malta/malta_setup.c
@@ -103,9 +103,7 @@
 	kgdb_config ();
 #endif
 
-	if ((mips_revision_corid == MIPS_REVISION_CORID_BONITO64) ||
-	    (mips_revision_corid == MIPS_REVISION_CORID_CORE_20K) ||
-	    (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL_BON)) {
+	if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) {
 		char *argptr;
 
 		argptr = prom_getcmdline();
diff --git a/arch/mips/oprofile/op_model_mipsxx.c b/arch/mips/oprofile/op_model_mipsxx.c
index 4f94fa2..1ea5c9c 100644
--- a/arch/mips/oprofile/op_model_mipsxx.c
+++ b/arch/mips/oprofile/op_model_mipsxx.c
@@ -177,7 +177,10 @@
 	unsigned int counters = op_model_mipsxx_ops.num_counters;
 	unsigned int control;
 	unsigned int counter;
-	int handled = 0;
+	int handled = IRQ_NONE;
+
+	if (cpu_has_mips_r2 && !(read_c0_cause() & (1 << 26)))
+		return handled;
 
 	switch (counters) {
 #define HANDLE_COUNTER(n)						\
@@ -188,7 +191,7 @@
 		    (counter & M_COUNTER_OVERFLOW)) {			\
 			oprofile_add_sample(get_irq_regs(), n);		\
 			w_c0_perfcntr ## n(reg.counter[n]);		\
-			handled = 1;					\
+			handled = IRQ_HANDLED;				\
 		}
 	HANDLE_COUNTER(3)
 	HANDLE_COUNTER(2)
diff --git a/arch/parisc/hpux/fs.c b/arch/parisc/hpux/fs.c
index d86e157..f2042e6 100644
--- a/arch/parisc/hpux/fs.c
+++ b/arch/parisc/hpux/fs.c
@@ -21,6 +21,7 @@
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/sched.h>
 #include <linux/file.h>
@@ -69,7 +70,6 @@
 };
 
 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
-#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
 
 static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
 		u64 ino, unsigned d_type)
@@ -77,7 +77,7 @@
 	struct hpux_dirent __user * dirent;
 	struct getdents_callback * buf = (struct getdents_callback *) __buf;
 	ino_t d_ino;
-	int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
+	int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 1, sizeof(long));
 
 	buf->error = -EINVAL;	/* only used if we fail.. */
 	if (reclen > buf->count)
@@ -102,7 +102,6 @@
 }
 
 #undef NAME_OFFSET
-#undef ROUND_UP
 
 int hpux_getdents(unsigned int fd, struct hpux_dirent __user *dirent, unsigned int count)
 {
diff --git a/arch/parisc/kernel/entry.S b/arch/parisc/kernel/entry.S
index 8474f9e..42598ab 100644
--- a/arch/parisc/kernel/entry.S
+++ b/arch/parisc/kernel/entry.S
@@ -954,21 +954,6 @@
 	/* NOTE: Need to enable interrupts incase we schedule. */
 	ssm     PSW_SM_I, %r0
 
-	/* Check for software interrupts */
-
-	.import irq_stat,data
-
-	load32	irq_stat,%r19
-#ifdef CONFIG_SMP
-	mfctl   %cr30,%r1
-	ldw	TI_CPU(%r1),%r1 /* get cpu # - int */
-	/* shift left ____cacheline_aligned (aka L1_CACHE_BYTES) amount
-	** irq_stat[] is defined using ____cacheline_aligned.
-	*/
-	SHLREG	%r1,L1_CACHE_SHIFT,%r20
-	add     %r19,%r20,%r19	/* now have &irq_stat[smp_processor_id()] */
-#endif /* CONFIG_SMP */
-
 intr_check_resched:
 
 	/* check for reschedule */
@@ -2034,10 +2019,9 @@
 	STREG     %r28,TASK_PT_GR28(%r1)
 
 #ifdef CONFIG_HPUX
-
 /* <linux/personality.h> cannot be easily included */
 #define PER_HPUX 0x10
-	LDREG     TASK_PERSONALITY(%r1),%r19
+	ldw	TASK_PERSONALITY(%r1),%r19
 
 	/* We can't use "CMPIB<> PER_HPUX" since "im5" field is sign extended */
 	ldo	  -PER_HPUX(%r19), %r19
@@ -2055,24 +2039,6 @@
 	 */
 	loadgp
 
-syscall_check_bh:
-
-	/* Check for software interrupts */
-
-	.import irq_stat,data
-
-	load32	irq_stat,%r19
-
-#ifdef CONFIG_SMP
-	/* sched.h: int processor */
-	/* %r26 is used as scratch register to index into irq_stat[] */
-	ldw     TI_CPU-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r26 /* cpu # */
-
-	/* shift left ____cacheline_aligned (aka L1_CACHE_BYTES) bits */
-	SHLREG	%r26,L1_CACHE_SHIFT,%r20
-	add     %r19,%r20,%r19	/* now have &irq_stat[smp_processor_id()] */
-#endif /* CONFIG_SMP */
-
 syscall_check_resched:
 
 	/* check for reschedule */
@@ -2114,7 +2080,7 @@
 	/* Are we being ptraced? */
 	LDREG	TI_TASK-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1
 
-	LDREG	TASK_PTRACE(%r1), %r19
+	ldw	TASK_PTRACE(%r1), %r19
 	bb,<	%r19,31,syscall_restore_rfi
 	nop
 
@@ -2244,7 +2210,7 @@
 #else
 	nop
 #endif
-	b       syscall_check_bh  /* if resched, we start over again */
+	b	syscall_check_resched	/* if resched, we start over again */
 	nop
 ENDPROC(syscall_exit)
 
diff --git a/arch/parisc/kernel/firmware.c b/arch/parisc/kernel/firmware.c
index 39dc835..fd6552c 100644
--- a/arch/parisc/kernel/firmware.c
+++ b/arch/parisc/kernel/firmware.c
@@ -634,7 +634,7 @@
  * pdc_stable_read - Read data from Stable Storage.
  * @staddr: Stable Storage address to access.
  * @memaddr: The memory address where Stable Storage data shall be copied.
- * @count: number of bytes to transfert. count is multiple of 4.
+ * @count: number of bytes to transfer. count is multiple of 4.
  *
  * This PDC call reads from the Stable Storage address supplied in staddr
  * and copies count bytes to the memory address memaddr.
@@ -660,7 +660,7 @@
  * pdc_stable_write - Write data to Stable Storage.
  * @staddr: Stable Storage address to access.
  * @memaddr: The memory address where Stable Storage data shall be read from.
- * @count: number of bytes to transfert. count is multiple of 4.
+ * @count: number of bytes to transfer. count is multiple of 4.
  *
  * This PDC call reads count bytes from the supplied memaddr address,
  * and copies count bytes to the Stable Storage address staddr.
diff --git a/arch/parisc/kernel/hardware.c b/arch/parisc/kernel/hardware.c
index 18ba4cb..04848b2 100644
--- a/arch/parisc/kernel/hardware.c
+++ b/arch/parisc/kernel/hardware.c
@@ -38,7 +38,7 @@
  *	so don't reference this table after starting the init process
  */
  
-static struct hp_hardware hp_hardware_list[] __initdata = {
+static struct hp_hardware hp_hardware_list[] __devinitdata = {
 	{HPHW_NPROC,0x01,0x4,0x0,"Indigo (840, 930)"},
 	{HPHW_NPROC,0x8,0x4,0x01,"Firefox(825,925)"},
 	{HPHW_NPROC,0xA,0x4,0x01,"Top Gun (835,834,935,635)"},
@@ -1219,7 +1219,7 @@
 	unsigned short model;
 	unsigned short mask;
 	enum cpu_type cpu;
-} hp_cpu_type_mask_list[] __initdata = {
+} hp_cpu_type_mask_list[] __devinitdata = {
 
 	{ 0x0000, 0x0ff0, pcx    },  /* 0x0000 - 0x000f */
 	{ 0x0048, 0x0ff0, pcxl   },  /* 0x0040 - 0x004f */
@@ -1296,10 +1296,11 @@
 	{ 0x05f0, 0x0ff0, pcxw2  },  /* 0x05f0 - 0x05ff */
 	{ 0x0600, 0x0fe0, pcxl   },  /* 0x0600 - 0x061f */
 	{ 0x0880, 0x0ff0, mako   },  /* 0x0880 - 0x088f */
+	{ 0x0890, 0x0ff0, mako2  },  /* 0x0890 - 0x089f */
 	{ 0x0000, 0x0000, pcx    }	/* terminate table */
 };
 
-char *cpu_name_version[][2] = {
+const char * const cpu_name_version[][2] = {
 	[pcx]	= { "PA7000 (PCX)",	"1.0" },
 	[pcxs]	= { "PA7000 (PCX-S)",	"1.1a" },
 	[pcxt]	= { "PA7100 (PCX-T)",	"1.1b" },
@@ -1311,10 +1312,11 @@
 	[pcxw]	= { "PA8500 (PCX-W)",	"2.0" },
 	[pcxw_]	= { "PA8600 (PCX-W+)",	"2.0" },
 	[pcxw2]	= { "PA8700 (PCX-W2)",	"2.0" },
-	[mako]	= { "PA8800 (Mako)",	"2.0" }
+	[mako]	= { "PA8800 (Mako)",	"2.0" },
+	[mako2] = { "PA8900 (Shortfin)",	"2.0" }
 };
 
-const char * __init
+const char * __devinit
 parisc_hardware_description(struct parisc_device_id *id)
 {
 	struct hp_hardware *listptr;
@@ -1353,7 +1355,7 @@
 
 
 /* Interpret hversion (ret[0]) from PDC_MODEL(4)/PDC_MODEL_INFO(0) */
-enum cpu_type __init
+enum cpu_type __cpuinit
 parisc_get_cpu_type(unsigned long hversion)
 {
 	struct hp_cpu_type_mask *ptr;
diff --git a/arch/parisc/kernel/hpmc.S b/arch/parisc/kernel/hpmc.S
index d8baa15..43b41df 100644
--- a/arch/parisc/kernel/hpmc.S
+++ b/arch/parisc/kernel/hpmc.S
@@ -295,8 +295,5 @@
 	b .
 	nop
 ENDPROC(os_hpmc)
-
-	/* this label used to compute os_hpmc checksum */
-ENTRY(os_hpmc_end)
-
+ENTRY(os_hpmc_end)	/* this label used to compute os_hpmc checksum */
 	nop
diff --git a/arch/parisc/kernel/irq.c b/arch/parisc/kernel/irq.c
index c5c9125..76ce5e3 100644
--- a/arch/parisc/kernel/irq.c
+++ b/arch/parisc/kernel/irq.c
@@ -46,14 +46,10 @@
 static volatile unsigned long cpu_eiem = 0;
 
 /*
-** ack bitmap ... habitually set to 1, but reset to zero
+** local ACK bitmap ... habitually set to 1, but reset to zero
 ** between ->ack() and ->end() of the interrupt to prevent
 ** re-interruption of a processing interrupt.
 */
-static volatile unsigned long global_ack_eiem = ~0UL;
-/*
-** Local bitmap, same as above but for per-cpu interrupts
-*/
 static DEFINE_PER_CPU(unsigned long, local_ack_eiem) = ~0UL;
 
 static void cpu_disable_irq(unsigned int irq)
@@ -94,13 +90,11 @@
 	int cpu = smp_processor_id();
 
 	/* Clear in EIEM so we can no longer process */
-	if (CHECK_IRQ_PER_CPU(irq_desc[irq].status))
-		per_cpu(local_ack_eiem, cpu) &= ~mask;
-	else
-		global_ack_eiem &= ~mask;
+	per_cpu(local_ack_eiem, cpu) &= ~mask;
 
 	/* disable the interrupt */
-	set_eiem(cpu_eiem & global_ack_eiem & per_cpu(local_ack_eiem, cpu));
+	set_eiem(cpu_eiem & per_cpu(local_ack_eiem, cpu));
+
 	/* and now ack it */
 	mtctl(mask, 23);
 }
@@ -111,13 +105,10 @@
 	int cpu = smp_processor_id();
 
 	/* set it in the eiems---it's no longer in process */
-	if (CHECK_IRQ_PER_CPU(irq_desc[irq].status))
-		per_cpu(local_ack_eiem, cpu) |= mask;
-	else
-		global_ack_eiem |= mask;
+	per_cpu(local_ack_eiem, cpu) |= mask;
 
 	/* enable the interrupt */
-	set_eiem(cpu_eiem & global_ack_eiem & per_cpu(local_ack_eiem, cpu));
+	set_eiem(cpu_eiem & per_cpu(local_ack_eiem, cpu));
 }
 
 #ifdef CONFIG_SMP
@@ -354,8 +345,7 @@
 	local_irq_disable();
 	irq_enter();
 
-	eirr_val = mfctl(23) & cpu_eiem & global_ack_eiem &
-		per_cpu(local_ack_eiem, cpu);
+	eirr_val = mfctl(23) & cpu_eiem & per_cpu(local_ack_eiem, cpu);
 	if (!eirr_val)
 		goto set_out;
 	irq = eirr_to_irq(eirr_val);
@@ -381,7 +371,7 @@
 	return;
 
  set_out:
-	set_eiem(cpu_eiem & global_ack_eiem & per_cpu(local_ack_eiem, cpu));
+	set_eiem(cpu_eiem & per_cpu(local_ack_eiem, cpu));
 	goto out;
 }
 
diff --git a/arch/parisc/kernel/pci-dma.c b/arch/parisc/kernel/pci-dma.c
index 0c3aecb..23c1388 100644
--- a/arch/parisc/kernel/pci-dma.c
+++ b/arch/parisc/kernel/pci-dma.c
@@ -21,6 +21,7 @@
 #include <linux/mm.h>
 #include <linux/pci.h>
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/types.h>
@@ -34,7 +35,6 @@
 #include <asm/tlbflush.h>	/* for purge_tlb_*() macros */
 
 static struct proc_dir_entry * proc_gsc_root __read_mostly = NULL;
-static int pcxl_proc_info(char *buffer, char **start, off_t offset, int length);
 static unsigned long pcxl_used_bytes __read_mostly = 0;
 static unsigned long pcxl_used_pages __read_mostly = 0;
 
@@ -330,6 +330,54 @@
 	dump_resmap();
 }
 
+static int proc_pcxl_dma_show(struct seq_file *m, void *v)
+{
+#if 0
+	u_long i = 0;
+	unsigned long *res_ptr = (u_long *)pcxl_res_map;
+#endif
+	unsigned long total_pages = pcxl_res_size << 3;   /* 8 bits per byte */
+
+	seq_printf(m, "\nDMA Mapping Area size    : %d bytes (%ld pages)\n",
+		PCXL_DMA_MAP_SIZE, total_pages);
+
+	seq_printf(m, "Resource bitmap : %d bytes\n", pcxl_res_size);
+
+	seq_puts(m,  "     	  total:    free:    used:   % used:\n");
+	seq_printf(m, "blocks  %8d %8ld %8ld %8ld%%\n", pcxl_res_size,
+		pcxl_res_size - pcxl_used_bytes, pcxl_used_bytes,
+		(pcxl_used_bytes * 100) / pcxl_res_size);
+
+	seq_printf(m, "pages   %8ld %8ld %8ld %8ld%%\n", total_pages,
+		total_pages - pcxl_used_pages, pcxl_used_pages,
+		(pcxl_used_pages * 100 / total_pages));
+
+#if 0
+	seq_puts(m, "\nResource bitmap:");
+
+	for(; i < (pcxl_res_size / sizeof(u_long)); ++i, ++res_ptr) {
+		if ((i & 7) == 0)
+		    seq_puts(m,"\n   ");
+		seq_printf(m, "%s %08lx", buf, *res_ptr);
+	}
+#endif
+	seq_putc(m, '\n');
+	return 0;
+}
+
+static int proc_pcxl_dma_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, proc_pcxl_dma_show, NULL);
+}
+
+static const struct file_operations proc_pcxl_dma_ops = {
+	.owner		= THIS_MODULE,
+	.open		= proc_pcxl_dma_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
 static int __init
 pcxl_dma_init(void)
 {
@@ -348,9 +396,10 @@
 			"pcxl_dma_init: Unable to create gsc /proc dir entry\n");
 	else {
 		struct proc_dir_entry* ent;
-		ent = create_proc_info_entry("pcxl_dma", 0,
-				proc_gsc_root, pcxl_proc_info);
-		if (!ent)
+		ent = create_proc_entry("pcxl_dma", 0, proc_gsc_root);
+		if (ent)
+			ent->proc_fops = &proc_pcxl_dma_ops;
+		else
 			printk(KERN_WARNING
 				"pci-dma.c: Unable to create pcxl_dma /proc entry.\n");
 	}
@@ -551,40 +600,3 @@
 	.dma_sync_sg_for_cpu =		pa11_dma_sync_sg_for_cpu,
 	.dma_sync_sg_for_device =	pa11_dma_sync_sg_for_device,
 };
-
-
-static int pcxl_proc_info(char *buf, char **start, off_t offset, int len)
-{
-#if 0
-	u_long i = 0;
-	unsigned long *res_ptr = (u_long *)pcxl_res_map;
-#endif
-	unsigned long total_pages = pcxl_res_size << 3;   /* 8 bits per byte */
-
-	sprintf(buf, "\nDMA Mapping Area size    : %d bytes (%ld pages)\n",
-		PCXL_DMA_MAP_SIZE, total_pages);
-	
-	sprintf(buf, "%sResource bitmap : %d bytes\n", buf, pcxl_res_size);
-
-	strcat(buf,  "     	  total:    free:    used:   % used:\n");
-	sprintf(buf, "%sblocks  %8d %8ld %8ld %8ld%%\n", buf, pcxl_res_size,
-		pcxl_res_size - pcxl_used_bytes, pcxl_used_bytes,
-		(pcxl_used_bytes * 100) / pcxl_res_size);
-
-	sprintf(buf, "%spages   %8ld %8ld %8ld %8ld%%\n", buf, total_pages,
-		total_pages - pcxl_used_pages, pcxl_used_pages,
-		(pcxl_used_pages * 100 / total_pages));
-
-#if 0
-	strcat(buf, "\nResource bitmap:");
-
-	for(; i < (pcxl_res_size / sizeof(u_long)); ++i, ++res_ptr) {
-		if ((i & 7) == 0)
-		    strcat(buf,"\n   ");
-		sprintf(buf, "%s %08lx", buf, *res_ptr);
-	}
-#endif
-	strcat(buf, "\n");
-	return strlen(buf);
-}
-
diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
index a46bc62..89d6d5a 100644
--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -171,7 +171,7 @@
 
 /*
  * Write control bitmasks for Pa-8700 processor given
- * somethings have changed slightly.
+ * some things have changed slightly.
  */
 static const uint64_t perf_bitmasks_piranha[] = {
 	0x0000000000000000ul,     /* first dbl word must be zero */
@@ -511,10 +511,12 @@
 	} else if (boot_cpu_data.cpu_type == pcxw ||
 		 boot_cpu_data.cpu_type == pcxw_ ||
 		 boot_cpu_data.cpu_type == pcxw2 ||
-		 boot_cpu_data.cpu_type == mako) {
+		 boot_cpu_data.cpu_type == mako ||
+		 boot_cpu_data.cpu_type == mako2) {
 		perf_processor_interface = CUDA_INTF;
 		if (boot_cpu_data.cpu_type == pcxw2 ||
-		    boot_cpu_data.cpu_type == mako) 
+		    boot_cpu_data.cpu_type == mako ||
+		    boot_cpu_data.cpu_type == mako2)
 			bitmask_array = perf_bitmasks_piranha;
 	} else {
 		perf_processor_interface = UNKNOWN_INTF;
@@ -574,27 +576,27 @@
 		if (!perf_rdr_read_ubuf(16, userbuf))
 			return -13;
 
-		/* Counter0 is bits 1398 thru 1429 */
+		/* Counter0 is bits 1398 to 1429 */
 		tmp64 =  (userbuf[21] << 22) & 0x00000000ffc00000;
 		tmp64 |= (userbuf[22] >> 42) & 0x00000000003fffff;
 		/* OR sticky0 (bit 1430) to counter0 bit 32 */
 		tmp64 |= (userbuf[22] >> 10) & 0x0000000080000000;
 		raddr[0] = (uint32_t)tmp64;
 
-		/* Counter1 is bits 1431 thru 1462 */
+		/* Counter1 is bits 1431 to 1462 */
 		tmp64 =  (userbuf[22] >> 9) & 0x00000000ffffffff;
 		/* OR sticky1 (bit 1463) to counter1 bit 32 */
 		tmp64 |= (userbuf[22] << 23) & 0x0000000080000000;
 		raddr[1] = (uint32_t)tmp64;
 
-		/* Counter2 is bits 1464 thru 1495 */
+		/* Counter2 is bits 1464 to 1495 */
 		tmp64 =  (userbuf[22] << 24) & 0x00000000ff000000;
 		tmp64 |= (userbuf[23] >> 40) & 0x0000000000ffffff;
 		/* OR sticky2 (bit 1496) to counter2 bit 32 */
 		tmp64 |= (userbuf[23] >> 8) & 0x0000000080000000;
 		raddr[2] = (uint32_t)tmp64;
 		
-		/* Counter3 is bits 1497 thru 1528 */
+		/* Counter3 is bits 1497 to 1528 */
 		tmp64 =  (userbuf[23] >> 7) & 0x00000000ffffffff;
 		/* OR sticky3 (bit 1529) to counter3 bit 32 */
 		tmp64 |= (userbuf[23] << 25) & 0x0000000080000000;
@@ -616,7 +618,7 @@
 		userbuf[23] = 0;
 
 		/* 
-		 * Write back the zero'ed bytes + the image given
+		 * Write back the zeroed bytes + the image given
 		 * the read was destructive.
 		 */
 		perf_rdr_write(16, userbuf);
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 0dd3847..3556648 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -381,6 +381,10 @@
 	struct unwind_frame_info info;
 	unsigned long ip;
 	int count = 0;
+
+	if (!p || p == current || p->state == TASK_RUNNING)
+		return 0;
+
 	/*
 	 * These bracket the sleeping functions..
 	 */
diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c
index 566226d..549f548 100644
--- a/arch/parisc/kernel/processor.c
+++ b/arch/parisc/kernel/processor.c
@@ -63,7 +63,7 @@
 ** will call register_parisc_driver(&cpu_driver) before calling do_inventory().
 **
 ** The goal of consolidating CPU initialization into one place is
-** to make sure all CPU's get initialized the same way.
+** to make sure all CPUs get initialized the same way.
 ** The code path not shared is how PDC hands control of the CPU to the OS.
 ** The initialization of OS data structures is the same (done below).
 */
@@ -76,7 +76,7 @@
  * (return 1).  If so, initialize the chip and tell other partners in crime 
  * they have work to do.
  */
-static int __init processor_probe(struct parisc_device *dev)
+static int __cpuinit processor_probe(struct parisc_device *dev)
 {
 	unsigned long txn_addr;
 	unsigned long cpuid;
@@ -166,7 +166,7 @@
 #endif
 
 	/*
-	** CONFIG_SMP: init_smp_config() will attempt to get CPU's into
+	** CONFIG_SMP: init_smp_config() will attempt to get CPUs into
 	** OS control. RENDEZVOUS is the default state - see mem_set above.
 	**	p->state = STATE_RENDEZVOUS;
 	*/
@@ -334,7 +334,7 @@
 }
 
 /*
- * Display cpu info for all cpu's.
+ * Display CPU info for all CPUs.
  */
 int
 show_cpuinfo (struct seq_file *m, void *v)
@@ -381,19 +381,19 @@
 	return 0;
 }
 
-static struct parisc_device_id processor_tbl[] __read_mostly = {
+static const struct parisc_device_id processor_tbl[] = {
 	{ HPHW_NPROC, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, SVERSION_ANY_ID },
 	{ 0, }
 };
 
-static struct parisc_driver cpu_driver __read_mostly = {
+static struct parisc_driver cpu_driver = {
 	.name		= "CPU",
 	.id_table	= processor_tbl,
 	.probe		= processor_probe
 };
 
 /**
- * processor_init - Processor initalization procedure.
+ * processor_init - Processor initialization procedure.
  *
  * Register this driver.
  */
diff --git a/arch/parisc/kernel/setup.c b/arch/parisc/kernel/setup.c
index 9818919..c44b8c5 100644
--- a/arch/parisc/kernel/setup.c
+++ b/arch/parisc/kernel/setup.c
@@ -45,7 +45,7 @@
 #include <asm/io.h>
 #include <asm/setup.h>
 
-char	__initdata command_line[COMMAND_LINE_SIZE];
+static char __initdata command_line[COMMAND_LINE_SIZE];
 
 /* Intended for ccio/sba/cpu statistics under /proc/bus/{runway|gsc} */
 struct proc_dir_entry * proc_runway_root __read_mostly = NULL;
@@ -162,7 +162,7 @@
 }
 
 /*
- * Display cpu info for all cpu's.
+ * Display CPU info for all CPUs.
  * for parisc this is in processor.c
  */
 extern int show_cpuinfo (struct seq_file *m, void *v);
@@ -225,6 +225,7 @@
                 }
                 break;
 	case mako:
+	case mako2:
                 if (NULL == proc_mckinley_root)
                 {
                         proc_mckinley_root = proc_mkdir("bus/mckinley", NULL);
diff --git a/arch/parisc/kernel/signal32.h b/arch/parisc/kernel/signal32.h
index e39b38a..c780084 100644
--- a/arch/parisc/kernel/signal32.h
+++ b/arch/parisc/kernel/signal32.h
@@ -113,7 +113,7 @@
 /* In a deft move of uber-hackery, we decide to carry the top half of all
  * 64-bit registers in a non-portable, non-ABI, hidden structure.
  * Userspace can read the hidden structure if it *wants* but is never
- * guaranteed to be in the same place. Infact the uc_sigmask from the
+ * guaranteed to be in the same place. In fact the uc_sigmask from the
  * ucontext_t structure may push the hidden register file downards
  */
 struct compat_regfile {
diff --git a/arch/parisc/kernel/smp.c b/arch/parisc/kernel/smp.c
index 6ba9257..04c7e1d 100644
--- a/arch/parisc/kernel/smp.c
+++ b/arch/parisc/kernel/smp.c
@@ -8,7 +8,7 @@
 ** Lots of stuff stolen from arch/alpha/kernel/smp.c
 ** ...and then parisc stole from arch/ia64/kernel/smp.c. Thanks David! :^)
 **
-** Thanks to John Curry and Ullas Ponnadi. I learned alot from their work.
+** Thanks to John Curry and Ullas Ponnadi. I learned a lot from their work.
 ** -grant (1/12/2001)
 **
 **	This program is free software; you can redistribute it and/or modify
@@ -419,7 +419,7 @@
 		BUG();
 	enter_lazy_tlb(&init_mm, current);
 
-	init_IRQ();   /* make sure no IRQ's are enabled or pending */
+	init_IRQ();   /* make sure no IRQs are enabled or pending */
 	start_cpu_itimer();
 }
 
@@ -461,7 +461,7 @@
 /*
  * Bring one cpu online.
  */
-int __init smp_boot_one_cpu(int cpuid)
+int __cpuinit smp_boot_one_cpu(int cpuid)
 {
 	struct task_struct *idle;
 	long timeout;
@@ -552,7 +552,7 @@
 
 /*
 ** inventory.c:do_inventory() hasn't yet been run and thus we
-** don't 'discover' the additional CPU's until later.
+** don't 'discover' the additional CPUs until later.
 */
 void __init smp_prepare_cpus(unsigned int max_cpus)
 {
diff --git a/arch/parisc/kernel/sys_parisc32.c b/arch/parisc/kernel/sys_parisc32.c
index ce3245f..bb23ff7 100644
--- a/arch/parisc/kernel/sys_parisc32.c
+++ b/arch/parisc/kernel/sys_parisc32.c
@@ -311,14 +311,13 @@
 	int count;
 };
 
-#define ROUND_UP(x,a)	((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
 static int filldir32 (void *__buf, const char *name, int namlen,
 			loff_t offset, u64 ino, unsigned int d_type)
 {
 	struct linux32_dirent __user * dirent;
 	struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
-	int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1, 4);
+	int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 1, 4);
 	u32 d_ino;
 
 	buf->error = -EINVAL;	/* only used if we fail.. */
@@ -350,6 +349,10 @@
 	struct getdents32_callback buf;
 	int error;
 
+	error = -EFAULT;
+	if (!access_ok(VERIFY_WRITE, dirent, count))
+		goto out;
+
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -366,8 +369,10 @@
 	error = buf.error;
 	lastdirent = buf.previous;
 	if (lastdirent) {
-		put_user(file->f_pos, &lastdirent->d_off);
-		error = count - buf.count;
+		if (put_user(file->f_pos, &lastdirent->d_off))
+			error = -EFAULT;
+		else
+			error = count - buf.count;
 	}
 
 out_putf:
diff --git a/arch/parisc/kernel/syscall.S b/arch/parisc/kernel/syscall.S
index 10859f5..56f6231 100644
--- a/arch/parisc/kernel/syscall.S
+++ b/arch/parisc/kernel/syscall.S
@@ -181,7 +181,7 @@
 	/* Are we being ptraced? */
 	mfctl	%cr30, %r1
 	LDREG	TI_TASK(%r1),%r1
-	LDREG	TASK_PTRACE(%r1), %r1
+	ldw	TASK_PTRACE(%r1), %r1
 	bb,<,n	%r1,31,.Ltracesys
 	
 	/* Note!  We cannot use the syscall table that is mapped
@@ -198,7 +198,7 @@
 	ldil	L%sys_call_table, %r1
 	ldo     R%sys_call_table(%r1), %r19
 #endif	
-	comiclr,>>=	__NR_Linux_syscalls, %r20, %r0
+	comiclr,>>	__NR_Linux_syscalls, %r20, %r0
 	b,n	.Lsyscall_nosys
 	
 	LDREGX  %r20(%r19), %r19
@@ -501,7 +501,7 @@
 	shlw	%r20, 4, %r20
 	add	%r20, %r28, %r20
 
-# ifdef ENABLE_LWS_DEBUG
+# if ENABLE_LWS_DEBUG
 	/*	
 		DEBUG, check for deadlock! 
 		If the thread register values are the same
@@ -550,7 +550,7 @@
 		perspective
 	*/
 cas_action:
-#if defined CONFIG_SMP && defined ENABLE_LWS_DEBUG
+#if defined CONFIG_SMP && ENABLE_LWS_DEBUG
 	/* DEBUG */
 	mfctl	%cr27, %r1
 	stw	%r1, 4(%sr2,%r20)
@@ -562,7 +562,7 @@
 #ifdef CONFIG_SMP
 	/* Free lock */
 	stw	%r20, 0(%sr2,%r20)
-# ifdef ENABLE_LWS_DEBUG
+# if ENABLE_LWS_DEBUG
 	/* Clear thread register indicator */
 	stw	%r0, 4(%sr2,%r20)
 # endif
@@ -576,7 +576,7 @@
 #ifdef CONFIG_SMP
 	/* Free lock */
 	stw	%r20, 0(%sr2,%r20)
-# ifdef ENABLE_LWS_DEBUG
+# if ENABLE_LWS_DEBUG
 	stw	%r0, 4(%sr2,%r20)
 # endif
 #endif
diff --git a/arch/parisc/kernel/syscall_table.S b/arch/parisc/kernel/syscall_table.S
index 8bf87e5..627f3c2 100644
--- a/arch/parisc/kernel/syscall_table.S
+++ b/arch/parisc/kernel/syscall_table.S
@@ -30,11 +30,6 @@
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#undef ENTRY_SAME
-#undef ENTRY_DIFF
-#undef ENTRY_UHOH
-#undef ENTRY_COMP
-#undef ENTRY_OURS
 #if defined(CONFIG_64BIT) && !defined(SYSCALL_TABLE_64BIT)
 /* Use ENTRY_SAME for 32-bit syscalls which are the same on wide and
  * narrow palinux.  Use ENTRY_DIFF for those where a 32-bit specific
@@ -405,5 +400,16 @@
 	ENTRY_SAME(epoll_pwait)
 	ENTRY_COMP(statfs64)
 	ENTRY_COMP(fstatfs64)
+	ENTRY_COMP(kexec_load)		/* 300 */
+	ENTRY_COMP(utimensat)
+	ENTRY_COMP(signalfd)
+	ENTRY_COMP(timerfd)
+	ENTRY_SAME(eventfd)
+
 	/* Nothing yet */
 
+#undef ENTRY_SAME
+#undef ENTRY_DIFF
+#undef ENTRY_UHOH
+#undef ENTRY_COMP
+#undef ENTRY_OURS
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
index 07a991a..8b3062a 100644
--- a/arch/parisc/kernel/time.c
+++ b/arch/parisc/kernel/time.c
@@ -191,7 +191,7 @@
 {
 	int change = 0;
 
-	/* since the cr16 cycle counters are not syncronized across CPUs,
+	/* since the cr16 cycle counters are not synchronized across CPUs,
 	   we'll check if we should switch to a safe clocksource: */
 	if (clocksource_cr16.rating != 0 && num_online_cpus() > 1) {
 		clocksource_change_rating(&clocksource_cr16, 0);
diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
index 745ff74..c3ec9f1 100644
--- a/arch/parisc/kernel/traps.c
+++ b/arch/parisc/kernel/traps.c
@@ -615,7 +615,7 @@
 		
 	case 13:
 		/* Conditional Trap
-		   The condition succees in an instruction which traps 
+		   The condition succeeds in an instruction which traps
 		   on condition  */
 		if(user_mode(regs)){
 			si.si_signo = SIGFPE;
@@ -802,13 +802,14 @@
 
 int __init check_ivt(void *iva)
 {
+	extern const u32 os_hpmc[];
+	extern const u32 os_hpmc_end[];
+
 	int i;
 	u32 check = 0;
 	u32 *ivap;
 	u32 *hpmcp;
 	u32 length;
-	extern void os_hpmc(void);
-	extern void os_hpmc_end(void);
 
 	if (strcmp((char *)iva, "cows can fly"))
 		return -1;
@@ -820,7 +821,7 @@
 
 	/* Compute Checksum for HPMC handler */
 
-	length = (u32)((unsigned long)os_hpmc_end - (unsigned long)os_hpmc);
+	length = os_hpmc_end - os_hpmc;
 	ivap[7] = length;
 
 	hpmcp = (u32 *)os_hpmc;
diff --git a/arch/parisc/kernel/unwind.c b/arch/parisc/kernel/unwind.c
index 89c0370..e70f57e 100644
--- a/arch/parisc/kernel/unwind.c
+++ b/arch/parisc/kernel/unwind.c
@@ -216,8 +216,10 @@
 		/* Handle some frequent special cases.... */
 		{
 			char symname[KSYM_NAME_LEN+1];
+			char *modname;
 
-			kallsyms_lookup(info->ip, NULL, NULL, NULL, symname);
+			kallsyms_lookup(info->ip, NULL, NULL, &modname,
+				symname);
 
 			dbg("info->ip = 0x%lx, name = %s\n", info->ip, symname);
 
diff --git a/arch/parisc/math-emu/dbl_float.h b/arch/parisc/math-emu/dbl_float.h
index 1570e2e..0c2fa9a 100644
--- a/arch/parisc/math-emu/dbl_float.h
+++ b/arch/parisc/math-emu/dbl_float.h
@@ -22,7 +22,7 @@
     PA header file -- do not include this header file for non-PA builds.
 #endif
 
-/* 32-bit word grabing functions */
+/* 32-bit word grabbing functions */
 #define Dbl_firstword(value) Dallp1(value)
 #define Dbl_secondword(value) Dallp2(value)
 #define Dbl_thirdword(value) dummy_location
@@ -37,7 +37,7 @@
 #define Dbl_allp1(object) Dallp1(object)
 #define Dbl_allp2(object) Dallp2(object)
 
-/* dbl_and_signs ands the sign bits of each argument and puts the result
+/* dbl_and_signs ANDs the sign bits of each argument and puts the result
  * into the first argument. dbl_or_signs ors those same sign bits */
 #define Dbl_and_signs( src1dst, src2)		\
     Dallp1(src1dst) = (Dallp1(src2)|~((unsigned int)1<<31)) & Dallp1(src1dst)
diff --git a/arch/parisc/math-emu/dfsqrt.c b/arch/parisc/math-emu/dfsqrt.c
index b6ed106..9542c6d 100644
--- a/arch/parisc/math-emu/dfsqrt.c
+++ b/arch/parisc/math-emu/dfsqrt.c
@@ -76,7 +76,7 @@
                 }
                 /*
                  * Return quiet NaN or positive infinity.
-		 *  Fall thru to negative test if negative infinity.
+		 *  Fall through to negative test if negative infinity.
                  */
 		if (Dbl_iszero_sign(srcp1) || 
 		    Dbl_isnotzero_mantissa(srcp1,srcp2)) {
diff --git a/arch/parisc/math-emu/sfsqrt.c b/arch/parisc/math-emu/sfsqrt.c
index cd3f6db..4657a12 100644
--- a/arch/parisc/math-emu/sfsqrt.c
+++ b/arch/parisc/math-emu/sfsqrt.c
@@ -76,7 +76,7 @@
                 }
                 /*
                  * Return quiet NaN or positive infinity.
-		 *  Fall thru to negative test if negative infinity.
+		 *  Fall through to negative test if negative infinity.
                  */
 		if (Sgl_iszero_sign(src) || Sgl_isnotzero_mantissa(src)) {
                 	*dstptr = src;
diff --git a/arch/parisc/math-emu/sgl_float.h b/arch/parisc/math-emu/sgl_float.h
index 82519a5..4ee4cc9 100644
--- a/arch/parisc/math-emu/sgl_float.h
+++ b/arch/parisc/math-emu/sgl_float.h
@@ -23,7 +23,7 @@
     PA header file -- do not include this header file for non-PA builds.
 #endif
 
-/* 32-bit word grabing functions */
+/* 32-bit word grabbing functions */
 #define Sgl_firstword(value) Sall(value)
 #define Sgl_secondword(value) dummy_location
 #define Sgl_thirdword(value) dummy_location
@@ -36,7 +36,7 @@
 #define Sgl_exponentmantissa(object) Sexponentmantissa(object)
 #define Sgl_all(object) Sall(object)
 
-/* sgl_and_signs ands the sign bits of each argument and puts the result
+/* sgl_and_signs ANDs the sign bits of each argument and puts the result
  * into the first argument. sgl_or_signs ors those same sign bits */
 #define Sgl_and_signs( src1dst, src2)		\
     Sall(src1dst) = (Sall(src2)|~((unsigned int)1<<31)) & Sall(src1dst)
diff --git a/arch/parisc/mm/init.c b/arch/parisc/mm/init.c
index 75ea9f2..e724b36 100644
--- a/arch/parisc/mm/init.c
+++ b/arch/parisc/mm/init.c
@@ -890,7 +890,7 @@
 #ifdef CONFIG_PA20
 
 /*
- * Currently, all PA20 chips have 18 bit protection id's, which is the
+ * Currently, all PA20 chips have 18 bit protection IDs, which is the
  * limiting factor (space ids are 32 bits).
  */
 
@@ -899,10 +899,10 @@
 #else
 
 /*
- * Currently we have a one-to-one relationship between space id's and
- * protection id's. Older parisc chips (PCXS, PCXT, PCXL, PCXL2) only
- * support 15 bit protection id's, so that is the limiting factor.
- * PCXT' has 18 bit protection id's, but only 16 bit spaceids, so it's
+ * Currently we have a one-to-one relationship between space IDs and
+ * protection IDs. Older parisc chips (PCXS, PCXT, PCXL, PCXL2) only
+ * support 15 bit protection IDs, so that is the limiting factor.
+ * PCXT' has 18 bit protection IDs, but only 16 bit spaceids, so it's
  * probably not worth the effort for a special case here.
  */
 
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index 87703df..cbca1df 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -151,12 +151,18 @@
 
 static int early_console_initialized;
 
-/* called by setup_system */
+/*
+ * Called by setup_system after ppc_md->probe and ppc_md->early_init.
+ * Call it again after setting udbg_putc in ppc_md->setup_arch.
+ */
 void register_early_udbg_console(void)
 {
 	if (early_console_initialized)
 		return;
 
+	if (!udbg_putc)
+		return;
+
 	if (strstr(boot_command_line, "udbg-immortal")) {
 		printk(KERN_INFO "early console immortal !\n");
 		udbg_console.flags &= ~CON_BOOT;
diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
index 07b1c4e..9565715 100644
--- a/arch/powerpc/platforms/powermac/setup.c
+++ b/arch/powerpc/platforms/powermac/setup.c
@@ -363,8 +363,19 @@
 		smp_ops = &core99_smp_ops;
 	}
 #ifdef CONFIG_PPC32
-	else
+	else {
+		/*
+		 * We have to set bits in cpu_possible_map here since the
+		 * secondary CPU(s) aren't in the device tree, and
+		 * setup_per_cpu_areas only allocates per-cpu data for
+		 * CPUs in the cpu_possible_map.
+		 */
+		int cpu;
+
+		for (cpu = 1; cpu < 4 && cpu < NR_CPUS; ++cpu)
+			cpu_set(cpu, cpu_possible_map);
 		smp_ops = &psurge_smp_ops;
+	}
 #endif
 #endif /* CONFIG_SMP */
 
diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
index 686ed82..cb2d8945 100644
--- a/arch/powerpc/platforms/powermac/smp.c
+++ b/arch/powerpc/platforms/powermac/smp.c
@@ -317,7 +317,6 @@
 		ncpus = NR_CPUS;
 	for (i = 1; i < ncpus ; ++i) {
 		cpu_set(i, cpu_present_map);
-		cpu_set(i, cpu_possible_map);
 		set_hard_smp_processor_id(i, i);
 	}
 
diff --git a/arch/sparc64/kernel/entry.S b/arch/sparc64/kernel/entry.S
index 7d1a118..8059531 100644
--- a/arch/sparc64/kernel/entry.S
+++ b/arch/sparc64/kernel/entry.S
@@ -2357,8 +2357,9 @@
 	 nop
 	.size	sun4v_ldc_unmap, .-sun4v_ldc_unmap
 
-	/* %o0:	cookie
-	 * %o1:	mte_cookie
+	/* %o0: channel
+	 * %o1:	cookie
+	 * %o2:	mte_cookie
 	 *
 	 * returns %o0:	status
 	 */
diff --git a/arch/sparc64/kernel/irq.c b/arch/sparc64/kernel/irq.c
index a36f8dd..e60d283 100644
--- a/arch/sparc64/kernel/irq.c
+++ b/arch/sparc64/kernel/irq.c
@@ -1,7 +1,6 @@
-/* $Id: irq.c,v 1.114 2002/01/11 08:45:38 davem Exp $
- * irq.c: UltraSparc IRQ handling/init/registry.
+/* irq.c: UltraSparc IRQ handling/init/registry.
  *
- * Copyright (C) 1997  David S. Miller  (davem@caip.rutgers.edu)
+ * Copyright (C) 1997, 2007  David S. Miller  (davem@davemloft.net)
  * Copyright (C) 1998  Eddie C. Dost    (ecd@skynet.be)
  * Copyright (C) 1998  Jakub Jelinek    (jj@ultra.linux.cz)
  */
@@ -43,6 +42,7 @@
 #include <asm/cpudata.h>
 #include <asm/auxio.h>
 #include <asm/head.h>
+#include <asm/hypervisor.h>
 
 /* UPA nodes send interrupt packet to UltraSparc with first data reg
  * value low 5 (7 on Starfire) bits holding the IRQ identifier being
@@ -380,6 +380,76 @@
 	}
 }
 
+static void sun4v_virq_enable(unsigned int virt_irq)
+{
+	struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
+	unsigned int ino = bucket - &ivector_table[0];
+
+	if (likely(bucket)) {
+		unsigned long cpuid, dev_handle, dev_ino;
+		int err;
+
+		cpuid = irq_choose_cpu(virt_irq);
+
+		dev_handle = ino & IMAP_IGN;
+		dev_ino = ino & IMAP_INO;
+
+		err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
+		if (err != HV_EOK)
+			printk("sun4v_vintr_set_target(%lx,%lx,%lu): "
+			       "err(%d)\n",
+			       dev_handle, dev_ino, cpuid, err);
+		err = sun4v_vintr_set_state(dev_handle, dev_ino,
+					    HV_INTR_ENABLED);
+		if (err != HV_EOK)
+			printk("sun4v_vintr_set_state(%lx,%lx,"
+			       "HV_INTR_ENABLED): err(%d)\n",
+			       dev_handle, dev_ino, err);
+	}
+}
+
+static void sun4v_virq_disable(unsigned int virt_irq)
+{
+	struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
+	unsigned int ino = bucket - &ivector_table[0];
+
+	if (likely(bucket)) {
+		unsigned long dev_handle, dev_ino;
+		int err;
+
+		dev_handle = ino & IMAP_IGN;
+		dev_ino = ino & IMAP_INO;
+
+		err = sun4v_vintr_set_state(dev_handle, dev_ino,
+					    HV_INTR_DISABLED);
+		if (err != HV_EOK)
+			printk("sun4v_vintr_set_state(%lx,%lx,"
+			       "HV_INTR_DISABLED): err(%d)\n",
+			       dev_handle, dev_ino, err);
+	}
+}
+
+static void sun4v_virq_end(unsigned int virt_irq)
+{
+	struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
+	unsigned int ino = bucket - &ivector_table[0];
+
+	if (likely(bucket)) {
+		unsigned long dev_handle, dev_ino;
+		int err;
+
+		dev_handle = ino & IMAP_IGN;
+		dev_ino = ino & IMAP_INO;
+
+		err = sun4v_vintr_set_state(dev_handle, dev_ino,
+					    HV_INTR_STATE_IDLE);
+		if (err != HV_EOK)
+			printk("sun4v_vintr_set_state(%lx,%lx,"
+				"HV_INTR_STATE_IDLE): err(%d)\n",
+			       dev_handle, dev_ino, err);
+	}
+}
+
 static void run_pre_handler(unsigned int virt_irq)
 {
 	struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
@@ -434,6 +504,21 @@
 };
 #endif
 
+static struct irq_chip sun4v_virq = {
+	.typename	= "vsun4v",
+	.enable		= sun4v_virq_enable,
+	.disable	= sun4v_virq_disable,
+	.end		= sun4v_virq_end,
+};
+
+static struct irq_chip sun4v_virq_ack = {
+	.typename	= "vsun4v+ack",
+	.enable		= sun4v_virq_enable,
+	.disable	= sun4v_virq_disable,
+	.ack		= run_pre_handler,
+	.end		= sun4v_virq_end,
+};
+
 void irq_install_pre_handler(int virt_irq,
 			     void (*func)(unsigned int, void *, void *),
 			     void *arg1, void *arg2)
@@ -447,7 +532,8 @@
 
 	chip = get_irq_chip(virt_irq);
 	if (chip == &sun4u_irq_ack ||
-	    chip == &sun4v_irq_ack
+	    chip == &sun4v_irq_ack ||
+	    chip == &sun4v_virq_ack
 #ifdef CONFIG_PCI_MSI
 	    || chip == &sun4v_msi
 #endif
@@ -455,7 +541,9 @@
 		return;
 
 	chip = (chip == &sun4u_irq ?
-		&sun4u_irq_ack : &sun4v_irq_ack);
+		&sun4u_irq_ack :
+		(chip == &sun4v_irq ?
+		 &sun4v_irq_ack : &sun4v_virq_ack));
 	set_irq_chip(virt_irq, chip);
 }
 
@@ -492,19 +580,18 @@
 	return bucket->virt_irq;
 }
 
-unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
+static unsigned int sun4v_build_common(unsigned long sysino,
+				       struct irq_chip *chip)
 {
 	struct ino_bucket *bucket;
 	struct irq_handler_data *data;
-	unsigned long sysino;
 
 	BUG_ON(tlb_type != hypervisor);
 
-	sysino = sun4v_devino_to_sysino(devhandle, devino);
 	bucket = &ivector_table[sysino];
 	if (!bucket->virt_irq) {
 		bucket->virt_irq = virt_irq_alloc(__irq(bucket));
-		set_irq_chip(bucket->virt_irq, &sun4v_irq);
+		set_irq_chip(bucket->virt_irq, chip);
 	}
 
 	data = get_irq_chip_data(bucket->virt_irq);
@@ -529,6 +616,32 @@
 	return bucket->virt_irq;
 }
 
+unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
+{
+	unsigned long sysino = sun4v_devino_to_sysino(devhandle, devino);
+
+	return sun4v_build_common(sysino, &sun4v_irq);
+}
+
+unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino)
+{
+	unsigned long sysino, hv_err;
+
+	BUG_ON(devhandle & ~IMAP_IGN);
+	BUG_ON(devino & ~IMAP_INO);
+
+	sysino = devhandle | devino;
+
+	hv_err = sun4v_vintr_set_cookie(devhandle, devino, sysino);
+	if (hv_err) {
+		prom_printf("IRQ: Fatal, cannot set cookie for [%x:%x] "
+			    "err=%lu\n", devhandle, devino, hv_err);
+		prom_halt();
+	}
+
+	return sun4v_build_common(sysino, &sun4v_virq);
+}
+
 #ifdef CONFIG_PCI_MSI
 unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
 			     unsigned int msi_start, unsigned int msi_end)
diff --git a/arch/sparc64/kernel/pci_common.c b/arch/sparc64/kernel/pci_common.c
index f974fef..4249214 100644
--- a/arch/sparc64/kernel/pci_common.c
+++ b/arch/sparc64/kernel/pci_common.c
@@ -291,8 +291,9 @@
 
 	for (i = 0; i < num_pbm_ranges; i++) {
 		const struct linux_prom_pci_ranges *pr = &pbm_ranges[i];
-		unsigned long a;
+		unsigned long a, size;
 		u32 parent_phys_hi, parent_phys_lo;
+		u32 size_hi, size_lo;
 		int type;
 
 		parent_phys_hi = pr->parent_phys_hi;
@@ -300,9 +301,14 @@
 		if (tlb_type == hypervisor)
 			parent_phys_hi &= 0x0fffffff;
 
+		size_hi = pr->size_hi;
+		size_lo = pr->size_lo;
+
 		type = (pr->child_phys_hi >> 24) & 0x3;
 		a = (((unsigned long)parent_phys_hi << 32UL) |
 		     ((unsigned long)parent_phys_lo  <<  0UL));
+		size = (((unsigned long)size_hi << 32UL) |
+			((unsigned long)size_lo  <<  0UL));
 
 		switch (type) {
 		case 0:
@@ -313,7 +319,7 @@
 		case 1:
 			/* 16-bit IO space, 16MB */
 			pbm->io_space.start = a;
-			pbm->io_space.end = a + ((16UL*1024UL*1024UL) - 1UL);
+			pbm->io_space.end = a + size - 1UL;
 			pbm->io_space.flags = IORESOURCE_IO;
 			saw_io = 1;
 			break;
@@ -321,7 +327,7 @@
 		case 2:
 			/* 32-bit MEM space, 2GB */
 			pbm->mem_space.start = a;
-			pbm->mem_space.end = a + (0x80000000UL - 1UL);
+			pbm->mem_space.end = a + size - 1UL;
 			pbm->mem_space.flags = IORESOURCE_MEM;
 			saw_mem = 1;
 			break;
diff --git a/arch/um/include/common-offsets.h b/arch/um/include/common-offsets.h
index 541f4a8..7376ee4 100644
--- a/arch/um/include/common-offsets.h
+++ b/arch/um/include/common-offsets.h
@@ -9,6 +9,7 @@
 OFFSET(HOST_TASK_PID, task_struct, pid);
 
 DEFINE(UM_KERN_PAGE_SIZE, PAGE_SIZE);
+DEFINE(UM_KERN_PAGE_MASK, PAGE_MASK);
 DEFINE(UM_NSEC_PER_SEC, NSEC_PER_SEC);
 
 DEFINE_STR(UM_KERN_EMERG, KERN_EMERG);
diff --git a/arch/um/os-Linux/main.c b/arch/um/os-Linux/main.c
index ea9a236..fb510d4 100644
--- a/arch/um/os-Linux/main.c
+++ b/arch/um/os-Linux/main.c
@@ -24,6 +24,7 @@
 #include "uml-config.h"
 #include "os.h"
 #include "um_malloc.h"
+#include "kern_constants.h"
 
 /* Set in main, unchanged thereafter */
 char *linux_prog;
@@ -232,7 +233,8 @@
 
 	if(!CAN_KMALLOC())
 		return __real_malloc(size);
-	else if(size <= PAGE_SIZE) /* finding contiguos pages can be hard*/
+	else if(size <= UM_KERN_PAGE_SIZE)
+		/* finding contiguous pages can be hard*/
 		ret = um_kmalloc(size);
 	else ret = um_vmalloc(size);
 
diff --git a/arch/um/os-Linux/skas/mem.c b/arch/um/os-Linux/skas/mem.c
index 5c89463..0f7df4e 100644
--- a/arch/um/os-Linux/skas/mem.c
+++ b/arch/um/os-Linux/skas/mem.c
@@ -25,6 +25,7 @@
 #include "sysdep/ptrace.h"
 #include "sysdep/stub.h"
 #include "init.h"
+#include "kern_constants.h"
 
 extern unsigned long batch_syscall_stub, __syscall_stub_start;
 
@@ -149,8 +150,8 @@
 	*stack = 0;
 	multi_op_count++;
 
-	if(!done && ((((unsigned long) stack) & ~PAGE_MASK) <
-		     PAGE_SIZE - 10 * sizeof(long))){
+	if(!done && ((((unsigned long) stack) & ~UM_KERN_PAGE_MASK) <
+		     UM_KERN_PAGE_SIZE - 10 * sizeof(long))){
 		*addr = stack;
 		return 0;
 	}
@@ -168,8 +169,8 @@
 	/* If *addr still is uninitialized, it *must* contain NULL.
 	 * Thus in this case do_syscall_stub correctly won't be called.
 	 */
-	if((((unsigned long) *addr) & ~PAGE_MASK) >=
-	   PAGE_SIZE - (10 + data_count) * sizeof(long)) {
+	if((((unsigned long) *addr) & ~UM_KERN_PAGE_MASK) >=
+	   UM_KERN_PAGE_SIZE - (10 + data_count) * sizeof(long)) {
 		ret = do_syscall_stub(mm_idp, addr);
 		/* in case of error, don't overwrite data on stack */
 		if(ret)
@@ -183,8 +184,8 @@
 
 	memcpy(stack + 1, data, data_count * sizeof(long));
 
-	*stub_addr = (void *)(((unsigned long)(stack + 1) & ~PAGE_MASK) +
-			      UML_CONFIG_STUB_DATA);
+	*stub_addr = (void *)(((unsigned long)(stack + 1) &
+			       ~UM_KERN_PAGE_MASK) + UML_CONFIG_STUB_DATA);
 
 	return 0;
 }
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index f9d2f85..46c00cc 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -252,11 +252,12 @@
 	unsigned long sp;
 	int pid, status, n, flags;
 
-	stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
+	stack = mmap(NULL, UM_KERN_PAGE_SIZE,
+		     PROT_READ | PROT_WRITE | PROT_EXEC,
 		     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 	if(stack == MAP_FAILED)
 		panic("start_userspace : mmap failed, errno = %d", errno);
-	sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
+	sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *);
 
 	flags = CLONE_FILES | SIGCHLD;
 	if(proc_mm) flags |= CLONE_VM;
@@ -279,7 +280,7 @@
 		panic("start_userspace : PTRACE_OLDSETOPTIONS failed, errno=%d\n",
 		      errno);
 
-	if(munmap(stack, PAGE_SIZE) < 0)
+	if(munmap(stack, UM_KERN_PAGE_SIZE) < 0)
 		panic("start_userspace : munmap failed, errno = %d\n", errno);
 
 	return(pid);
@@ -365,7 +366,7 @@
 	thread_regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE +
 				(unsigned long) stub_clone_handler -
 				(unsigned long) &__syscall_stub_start;
-	thread_regs[REGS_SP_INDEX] = UML_CONFIG_STUB_DATA + PAGE_SIZE -
+	thread_regs[REGS_SP_INDEX] = UML_CONFIG_STUB_DATA + UM_KERN_PAGE_SIZE -
 		sizeof(void *);
 #ifdef __SIGNAL_FRAMESIZE
 	thread_regs[REGS_SP_INDEX] -= __SIGNAL_FRAMESIZE;
@@ -453,7 +454,7 @@
 				      .u         =
 				      { .mmap    =
 					{ .addr    = code,
-					  .len     = PAGE_SIZE,
+					  .len     = UM_KERN_PAGE_SIZE,
 					  .prot    = PROT_EXEC,
 					  .flags   = MAP_FIXED | MAP_PRIVATE,
 					  .fd      = code_fd,
@@ -476,7 +477,7 @@
 				  .u         =
 				  { .mmap    =
 				    { .addr    = data,
-				      .len     = PAGE_SIZE,
+				      .len     = UM_KERN_PAGE_SIZE,
 				      .prot    = PROT_READ | PROT_WRITE,
 				      .flags   = MAP_FIXED | MAP_SHARED,
 				      .fd      = map_fd,
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c
index 3fc13fa..46f6139 100644
--- a/arch/um/os-Linux/start_up.c
+++ b/arch/um/os-Linux/start_up.c
@@ -107,11 +107,12 @@
 	unsigned long sp;
 	int pid, n, status;
 
-	stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
+	stack = mmap(NULL, UM_KERN_PAGE_SIZE,
+		     PROT_READ | PROT_WRITE | PROT_EXEC,
 		     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 	if(stack == MAP_FAILED)
 		fatal_perror("check_ptrace : mmap failed");
-	sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
+	sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *);
 	pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
 	if(pid < 0)
 		fatal_perror("start_ptraced_child : clone failed");
@@ -153,7 +154,7 @@
 		ret = -1;
 	}
 
-	if(munmap(stack, PAGE_SIZE) < 0)
+	if(munmap(stack, UM_KERN_PAGE_SIZE) < 0)
 		fatal_perror("check_ptrace : munmap failed");
 	return ret;
 }
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 6b5173a..c99b463 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -340,6 +340,15 @@
 	if (rq == &q->post_flush_rq)
 		return QUEUE_ORDSEQ_POSTFLUSH;
 
+	/*
+	 * !fs requests don't need to follow barrier ordering.  Always
+	 * put them at the front.  This fixes the following deadlock.
+	 *
+	 * http://thread.gmane.org/gmane.linux.kernel/537473
+	 */
+	if (!blk_fs_request(rq))
+		return QUEUE_ORDSEQ_DRAIN;
+
 	if ((rq->cmd_flags & REQ_ORDERED_COLOR) ==
 	    (q->orig_bar_rq->cmd_flags & REQ_ORDERED_COLOR))
 		return QUEUE_ORDSEQ_DRAIN;
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index 1cfbecb..13369b4 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -524,7 +524,7 @@
 	return AE_OK;
 }
 
-static acpi_status __exit remove_device(void)
+static acpi_status remove_device(void)
 {
 	ProcItem *item;
 
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index d383168..0439ee9 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -1810,68 +1810,69 @@
 static const struct intel_driver_description {
 	unsigned int chip_id;
 	unsigned int gmch_chip_id;
+	unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
 	char *name;
 	const struct agp_bridge_driver *driver;
 	const struct agp_bridge_driver *gmch_driver;
 } intel_agp_chipsets[] = {
-	{ PCI_DEVICE_ID_INTEL_82443LX_0, 0, "440LX", &intel_generic_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82443BX_0, 0, "440BX", &intel_generic_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82443GX_0, 0, "440GX", &intel_generic_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, "i810",
+	{ PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
 		NULL, &intel_810_driver },
-	{ PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, "i810",
+	{ PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
 		NULL, &intel_810_driver },
-	{ PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, "i810",
+	{ PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
 		NULL, &intel_810_driver },
-	{ PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, "i815",
-		&intel_810_driver, &intel_815_driver },
-	{ PCI_DEVICE_ID_INTEL_82820_HB, 0, "i820", &intel_820_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, "i820", &intel_820_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, "830M",
+	{ PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
+		&intel_815_driver, &intel_810_driver },
+	{ PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
 		&intel_830mp_driver, &intel_830_driver },
-	{ PCI_DEVICE_ID_INTEL_82840_HB, 0, "i840", &intel_840_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82845_HB, 0, "845G", &intel_845_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, "830M",
+	{ PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
 		&intel_845_driver, &intel_830_driver },
-	{ PCI_DEVICE_ID_INTEL_82850_HB, 0, "i850", &intel_850_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82855PM_HB, 0, "855PM", &intel_845_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, "855GM",
+	{ PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
 		&intel_845_driver, &intel_830_driver },
-	{ PCI_DEVICE_ID_INTEL_82860_HB, 0, "i860", &intel_860_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, "865",
+	{ PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
 		&intel_845_driver, &intel_830_driver },
-	{ PCI_DEVICE_ID_INTEL_82875_HB, 0, "i875", &intel_845_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, "915G",
+	{ PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
 		&intel_845_driver, &intel_915_driver },
-	{ PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, "915GM",
+	{ PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
 		&intel_845_driver, &intel_915_driver },
-	{ PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, "945G",
+	{ PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
 		&intel_845_driver, &intel_915_driver },
-	{ PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, "945GM",
+	{ PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 1, "945GM",
 		&intel_845_driver, &intel_915_driver },
-	{ PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, "945GME",
+	{ PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
 		&intel_845_driver, &intel_915_driver },
-	{ PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, "946GZ",
+	{ PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
 		&intel_845_driver, &intel_i965_driver },
-	{ PCI_DEVICE_ID_INTEL_82965G_1_HB, PCI_DEVICE_ID_INTEL_82965G_1_IG, "965G",
+	{ PCI_DEVICE_ID_INTEL_82965G_1_HB, PCI_DEVICE_ID_INTEL_82965G_1_IG, 0, "965G",
 		&intel_845_driver, &intel_i965_driver },
-	{ PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, "965Q",
+	{ PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
 		&intel_845_driver, &intel_i965_driver },
-	{ PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, "965G",
+	{ PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
 		&intel_845_driver, &intel_i965_driver },
-	{ PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, "965GM",
+	{ PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 1, "965GM",
 		&intel_845_driver, &intel_i965_driver },
-	{ PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, "965GME/GLE",
+	{ PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
 		&intel_845_driver, &intel_i965_driver },
-	{ PCI_DEVICE_ID_INTEL_7505_0, 0, "E7505", &intel_7505_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_7205_0, 0, "E7205", &intel_7505_driver, NULL },
-	{ PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, "G33",
+	{ PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
+	{ PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
 		&intel_845_driver, &intel_g33_driver },
-	{ PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, "Q35",
+	{ PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
 		&intel_845_driver, &intel_g33_driver },
-	{ PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, "Q33",
+	{ PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
 		&intel_845_driver, &intel_g33_driver },
-	{ 0, 0, NULL, NULL, NULL }
+	{ 0, 0, 0, NULL, NULL, NULL }
 };
 
 static int __devinit agp_intel_probe(struct pci_dev *pdev,
@@ -1892,10 +1893,19 @@
 		/* In case that multiple models of gfx chip may
 		   stand on same host bridge type, this can be
 		   sure we detect the right IGD. */
-		if ((pdev->device == intel_agp_chipsets[i].chip_id) &&
-			((intel_agp_chipsets[i].gmch_chip_id == 0) ||
-				find_gmch(intel_agp_chipsets[i].gmch_chip_id)))
-			break;
+		if (pdev->device == intel_agp_chipsets[i].chip_id) {
+			if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
+				find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
+				bridge->driver =
+					intel_agp_chipsets[i].gmch_driver;
+				break;
+			} else if (intel_agp_chipsets[i].multi_gmch_chip) {
+				continue;
+			} else {
+				bridge->driver = intel_agp_chipsets[i].driver;
+				break;
+			}
+		}
 	}
 
 	if (intel_agp_chipsets[i].name == NULL) {
@@ -1906,11 +1916,6 @@
 		return -ENODEV;
 	}
 
-	if (intel_agp_chipsets[i].gmch_chip_id != 0)
-	    bridge->driver = intel_agp_chipsets[i].gmch_driver;
-	else
-	    bridge->driver = intel_agp_chipsets[i].driver;
-
 	if (bridge->driver == NULL) {
 		printk(KERN_WARNING PFX "Failed to find bridge device "
 			"(chip_id: %04x)\n", intel_agp_chipsets[i].gmch_chip_id);
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
index 177ccc0..aa63350 100644
--- a/drivers/char/drm/drm_pciids.h
+++ b/drivers/char/drm/drm_pciids.h
@@ -300,10 +300,15 @@
 	{0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x27a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+	{0x8086, 0x27ae, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2972, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2982, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2992, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x29a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+	{0x8086, 0x29b2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+	{0x8086, 0x29c2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+	{0x8086, 0x29d2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2a02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+	{0x8086, 0x2a12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0, 0, 0}
 
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
index 1ba15d9..ea52740a 100644
--- a/drivers/char/drm/i915_dma.c
+++ b/drivers/char/drm/i915_dma.c
@@ -35,7 +35,12 @@
 		       dev->pci_device == 0x2982 || \
 		       dev->pci_device == 0x2992 || \
 		       dev->pci_device == 0x29A2 || \
-		       dev->pci_device == 0x2A02)
+		       dev->pci_device == 0x2A02 || \
+		       dev->pci_device == 0x2A12)
+
+#define IS_G33(dev) (dev->pci_device == 0x29b2 || \
+		     dev->pci_device == 0x29c2 || \
+		     dev->pci_device == 0x29d2)
 
 /* Really want an OS-independent resettable timer.  Would like to have
  * this loop run for (eg) 3 sec, but have the timer reset every time
@@ -106,6 +111,12 @@
 			I915_WRITE(0x02080, 0x1ffff000);
 		}
 
+		if (dev_priv->status_gfx_addr) {
+			dev_priv->status_gfx_addr = 0;
+			drm_core_ioremapfree(&dev_priv->hws_map, dev);
+			I915_WRITE(0x2080, 0x1ffff000);
+		}
+
 		drm_free(dev->dev_private, sizeof(drm_i915_private_t),
 			 DRM_MEM_DRIVER);
 
@@ -179,26 +190,24 @@
 	dev_priv->allow_batchbuffer = 1;
 
 	/* Program Hardware Status Page */
-	dev_priv->status_page_dmah = drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE,
-						   0xffffffff);
+	if (!IS_G33(dev)) {
+		dev_priv->status_page_dmah =
+			drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
 
-	if (!dev_priv->status_page_dmah) {
-		dev->dev_private = (void *)dev_priv;
-		i915_dma_cleanup(dev);
-		DRM_ERROR("Can not allocate hardware status page\n");
-		return DRM_ERR(ENOMEM);
+		if (!dev_priv->status_page_dmah) {
+			dev->dev_private = (void *)dev_priv;
+			i915_dma_cleanup(dev);
+			DRM_ERROR("Can not allocate hardware status page\n");
+			return DRM_ERR(ENOMEM);
+		}
+		dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
+		dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
+
+		memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+		I915_WRITE(0x02080, dev_priv->dma_status_page);
 	}
-	dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
-	dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
-
-	memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
-	DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
-
-	I915_WRITE(0x02080, dev_priv->dma_status_page);
 	DRM_DEBUG("Enabled hardware status page\n");
-
 	dev->dev_private = (void *)dev_priv;
-
 	return 0;
 }
 
@@ -231,7 +240,10 @@
 	}
 	DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
 
-	I915_WRITE(0x02080, dev_priv->dma_status_page);
+	if (dev_priv->status_gfx_addr != 0)
+		I915_WRITE(0x02080, dev_priv->status_gfx_addr);
+	else
+		I915_WRITE(0x02080, dev_priv->dma_status_page);
 	DRM_DEBUG("Enabled hardware status page\n");
 
 	return 0;
@@ -739,6 +751,47 @@
 	return 0;
 }
 
+static int i915_set_status_page(DRM_IOCTL_ARGS)
+{
+	DRM_DEVICE;
+	drm_i915_private_t *dev_priv = dev->dev_private;
+	drm_i915_hws_addr_t hws;
+
+	if (!dev_priv) {
+		DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
+		return DRM_ERR(EINVAL);
+	}
+	DRM_COPY_FROM_USER_IOCTL(hws, (drm_i915_hws_addr_t __user *) data,
+			sizeof(hws));
+	printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws.addr);
+
+	dev_priv->status_gfx_addr = hws.addr & (0x1ffff<<12);
+
+	dev_priv->hws_map.offset = dev->agp->agp_info.aper_base + hws.addr;
+	dev_priv->hws_map.size = 4*1024;
+	dev_priv->hws_map.type = 0;
+	dev_priv->hws_map.flags = 0;
+	dev_priv->hws_map.mtrr = 0;
+
+	drm_core_ioremap(&dev_priv->hws_map, dev);
+	if (dev_priv->hws_map.handle == NULL) {
+		dev->dev_private = (void *)dev_priv;
+		i915_dma_cleanup(dev);
+		dev_priv->status_gfx_addr = 0;
+		DRM_ERROR("can not ioremap virtual address for"
+				" G33 hw status page\n");
+		return DRM_ERR(ENOMEM);
+	}
+	dev_priv->hw_status_page = dev_priv->hws_map.handle;
+
+	memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+	I915_WRITE(0x02080, dev_priv->status_gfx_addr);
+	DRM_DEBUG("load hws 0x2080 with gfx mem 0x%x\n",
+			dev_priv->status_gfx_addr);
+	DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page);
+	return 0;
+}
+
 int i915_driver_load(drm_device_t *dev, unsigned long flags)
 {
 	/* i915 has 4 more counters */
@@ -785,6 +838,7 @@
 	[DRM_IOCTL_NR(DRM_I915_SET_VBLANK_PIPE)] = { i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY },
 	[DRM_IOCTL_NR(DRM_I915_GET_VBLANK_PIPE)] = { i915_vblank_pipe_get, DRM_AUTH },
 	[DRM_IOCTL_NR(DRM_I915_VBLANK_SWAP)] = {i915_vblank_swap, DRM_AUTH},
+	[DRM_IOCTL_NR(DRM_I915_HWS_ADDR)] = {i915_set_status_page, DRM_AUTH},
 };
 
 int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
diff --git a/drivers/char/drm/i915_drm.h b/drivers/char/drm/i915_drm.h
index 96a4688..7b7b68b 100644
--- a/drivers/char/drm/i915_drm.h
+++ b/drivers/char/drm/i915_drm.h
@@ -142,6 +142,7 @@
 #define DRM_I915_SET_VBLANK_PIPE	0x0d
 #define DRM_I915_GET_VBLANK_PIPE	0x0e
 #define DRM_I915_VBLANK_SWAP	0x0f
+#define DRM_I915_HWS_ADDR	0x11
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -262,4 +263,8 @@
 	unsigned int sequence;
 } drm_i915_vblank_swap_t;
 
+typedef struct drm_i915_hws_addr {
+	uint64_t addr;
+} drm_i915_hws_addr_t;
+
 #endif				/* _I915_DRM_H_ */
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h
index 93cdcfe..85e323a 100644
--- a/drivers/char/drm/i915_drv.h
+++ b/drivers/char/drm/i915_drv.h
@@ -91,6 +91,8 @@
 	void *hw_status_page;
 	dma_addr_t dma_status_page;
 	unsigned long counter;
+	unsigned int status_gfx_addr;
+	drm_local_map_t hws_map;
 
 	unsigned int cpp;
 	int back_offset;
diff --git a/drivers/char/drm/radeon_ioc32.c b/drivers/char/drm/radeon_ioc32.c
index 1f1f9cc..56decda 100644
--- a/drivers/char/drm/radeon_ioc32.c
+++ b/drivers/char/drm/radeon_ioc32.c
@@ -349,6 +349,36 @@
 			 DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request);
 }
 
+/* The two 64-bit arches where alignof(u64)==4 in 32-bit code */
+#if defined (CONFIG_X86_64) || defined(CONFIG_IA64)
+typedef struct drm_radeon_setparam32 {
+	int param;
+	u64 value;
+} __attribute__((packed)) drm_radeon_setparam32_t;
+
+static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
+				     unsigned long arg)
+{
+	drm_radeon_setparam32_t req32;
+	drm_radeon_setparam_t __user *request;
+
+	if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
+		return -EFAULT;
+
+	request = compat_alloc_user_space(sizeof(*request));
+	if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+	    || __put_user(req32.param, &request->param)
+	    || __put_user((void __user *)(unsigned long)req32.value,
+			  &request->value))
+		return -EFAULT;
+
+	return drm_ioctl(file->f_dentry->d_inode, file,
+			 DRM_IOCTL_RADEON_SETPARAM, (unsigned long) request);
+}
+#else
+#define compat_radeon_cp_setparam NULL
+#endif /* X86_64 || IA64 */
+
 drm_ioctl_compat_t *radeon_compat_ioctls[] = {
 	[DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
 	[DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
@@ -357,6 +387,7 @@
 	[DRM_RADEON_VERTEX2] = compat_radeon_cp_vertex2,
 	[DRM_RADEON_CMDBUF] = compat_radeon_cp_cmdbuf,
 	[DRM_RADEON_GETPARAM] = compat_radeon_cp_getparam,
+	[DRM_RADEON_SETPARAM] = compat_radeon_cp_setparam,
 	[DRM_RADEON_ALLOC] = compat_radeon_mem_alloc,
 	[DRM_RADEON_IRQ_EMIT] = compat_radeon_irq_emit,
 };
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 0474cac..7f52712 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -794,7 +794,7 @@
 
 	buf[0] ^= buf[3];
 	buf[1] ^= buf[4];
-	buf[0] ^= rol32(buf[3], 16);
+	buf[2] ^= rol32(buf[2], 16);
 	memcpy(out, buf, EXTRACT_SIZE);
 	memset(buf, 0, sizeof(buf));
 }
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 3752edc..a96f26a 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1173,8 +1173,14 @@
 	return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
 }
 
-static long hung_up_tty_ioctl(struct file * file,
-			      unsigned int cmd, unsigned long arg)
+static int hung_up_tty_ioctl(struct inode * inode, struct file * file,
+			     unsigned int cmd, unsigned long arg)
+{
+	return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
+}
+
+static long hung_up_tty_compat_ioctl(struct file * file,
+				     unsigned int cmd, unsigned long arg)
 {
 	return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
 }
@@ -1222,8 +1228,8 @@
 	.read		= hung_up_tty_read,
 	.write		= hung_up_tty_write,
 	.poll		= hung_up_tty_poll,
-	.unlocked_ioctl = hung_up_tty_ioctl,
-	.compat_ioctl	= hung_up_tty_ioctl,
+	.ioctl		= hung_up_tty_ioctl,
+	.compat_ioctl	= hung_up_tty_compat_ioctl,
 	.release	= tty_release,
 };
 
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 0af0d16..0cd76bf 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -1010,7 +1010,6 @@
 {
 	ide_drive_t *drive = dev->driver_data;
 	ide_hwif_t *hwif = HWIF(drive);
-	ide_driver_t *drv = to_ide_driver(dev->driver);
 	struct request rq;
 	struct request_pm_state rqpm;
 	ide_task_t args;
@@ -1033,8 +1032,12 @@
 
 	err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
 
-	if (err == 0 && drv && drv->resume)
-		drv->resume(drive);
+	if (err == 0 && dev->driver) {
+		ide_driver_t *drv = to_ide_driver(dev->driver);
+
+		if (drv->resume)
+			drv->resume(drive);
+	}
 
 	return err;
 }
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index f814fb3..2d87357 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -39,6 +39,19 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called ff-memless.
 
+config INPUT_POLLDEV
+	tristate "Polled input device skeleton"
+	help
+	  Say Y here if you are using a driver for an input
+	  device that periodically polls hardware state. This
+	  option is only useful for out-of-tree drivers since
+	  in-tree drivers select it automatically.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called input-polldev.
+
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 8a2dd98..15eb752 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -8,6 +8,7 @@
 input-core-objs := input.o ff-core.o
 
 obj-$(CONFIG_INPUT_FF_MEMLESS)	+= ff-memless.o
+obj-$(CONFIG_INPUT_POLLDEV)	+= input-polldev.o
 
 obj-$(CONFIG_INPUT_MOUSEDEV)	+= mousedev.o
 obj-$(CONFIG_INPUT_JOYDEV)	+= joydev.o
diff --git a/drivers/input/misc/input-polldev.c b/drivers/input/input-polldev.c
similarity index 100%
rename from drivers/input/misc/input-polldev.c
rename to drivers/input/input-polldev.c
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 842a7b4..88e2907 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -170,17 +170,6 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called uinput.
 
-config INPUT_POLLDEV
-	tristate "Polled input device skeleton"
-	help
-	  Say Y here if you are using a driver for an input
-	  device that periodically polls hardware state. This
-	  option is only useful for out-of-tree drivers since
-	  in-tree drivers select it automatically.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called input-polldev.
-
 config HP_SDC_RTC
 	tristate "HP SDC Real Time Clock"
 	depends on GSC || HP300
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 8b2f779..3585b50 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -4,7 +4,6 @@
 
 # Each configuration option enables a list of files.
 
-obj-$(CONFIG_INPUT_POLLDEV)		+= input-polldev.o
 obj-$(CONFIG_INPUT_SPARCSPKR)		+= sparcspkr.o
 obj-$(CONFIG_INPUT_PCSPKR)		+= pcspkr.o
 obj-$(CONFIG_INPUT_M68K_BEEP)		+= m68kspkr.o
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 6858bc5..f4a2517 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -69,6 +69,15 @@
 
 static struct dmi_system_id __initdata i8042_dmi_noloop_table[] = {
 	{
+		/* AUX LOOP command does not raise AUX IRQ */
+		.ident = "ASUS P65UP5",
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
+			DMI_MATCH(DMI_BOARD_NAME, "P/I-P65UP5"),
+			DMI_MATCH(DMI_BOARD_VERSION, "REV 2.X"),
+		},
+	},
+	{
 		.ident = "Compaq Proliant 8500",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
@@ -92,6 +101,15 @@
 			DMI_MATCH(DMI_PRODUCT_VERSION, "00"),
 		},
 	},
+	{
+		/* AUX LOOP does not work properly */
+		.ident = "ULI EV4873",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ULI"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "EV4873"),
+			DMI_MATCH(DMI_PRODUCT_VERSION, "5a"),
+		},
+	},
 	{ }
 };
 
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 8e18e6c..e3f2285 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -91,7 +91,7 @@
 };
 
 
-#if defined(CONFIG_USB_TOUCHSCREEN_EGALAX) || defined(CONFIG_USB_TOUCHSCREEN_ETURBO)
+#if defined(CONFIG_TOUCHSCREEN_USB_EGALAX) || defined(CONFIG_TOUCHSCREEN_USB_ETURBO)
 #define MULTI_PACKET
 #endif
 
@@ -113,7 +113,7 @@
 };
 
 static struct usb_device_id usbtouch_devices[] = {
-#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
+#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
 	{USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
 	{USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
 	{USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
@@ -123,30 +123,30 @@
 	{USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
+#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
 	{USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
 	{USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
 	{USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
 	{USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_3M
+#ifdef CONFIG_TOUCHSCREEN_USB_3M
 	{USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_ITM
+#ifdef CONFIG_TOUCHSCREEN_USB_ITM
 	{USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
+#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
 	{USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
+#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
 	{USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_DMC_TSC10
+#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
 	{USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
 #endif
 
@@ -158,7 +158,7 @@
  * eGalax part
  */
 
-#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
+#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
 
 #define EGALAX_PKT_TYPE_MASK		0xFE
 #define EGALAX_PKT_TYPE_REPT		0x80
@@ -197,7 +197,7 @@
 /*****************************************************************************
  * PanJit Part
  */
-#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
+#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
 static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
 {
 	dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
@@ -212,7 +212,7 @@
 /*****************************************************************************
  * 3M/Microtouch Part
  */
-#ifdef CONFIG_USB_TOUCHSCREEN_3M
+#ifdef CONFIG_TOUCHSCREEN_USB_3M
 
 #define MTOUCHUSB_ASYNC_REPORT          1
 #define MTOUCHUSB_RESET                 7
@@ -262,7 +262,7 @@
 /*****************************************************************************
  * ITM Part
  */
-#ifdef CONFIG_USB_TOUCHSCREEN_ITM
+#ifdef CONFIG_TOUCHSCREEN_USB_ITM
 static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
 {
 	int touch;
@@ -296,7 +296,7 @@
 /*****************************************************************************
  * eTurboTouch part
  */
-#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
+#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
 static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
 {
 	unsigned int shift;
@@ -327,7 +327,7 @@
 /*****************************************************************************
  * Gunze part
  */
-#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
+#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
 static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
 {
 	if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
@@ -348,7 +348,7 @@
  *   http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
  *   http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
  */
-#ifdef CONFIG_USB_TOUCHSCREEN_DMC_TSC10
+#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
 
 /* supported data rates. currently using 130 */
 #define TSC10_RATE_POINT	0x50
@@ -419,7 +419,7 @@
  * the different device descriptors
  */
 static struct usbtouch_device_info usbtouch_dev_info[] = {
-#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
+#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
 	[DEVTYPE_EGALAX] = {
 		.min_xc		= 0x0,
 		.max_xc		= 0x07ff,
@@ -433,7 +433,7 @@
 	},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
+#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
 	[DEVTYPE_PANJIT] = {
 		.min_xc		= 0x0,
 		.max_xc		= 0x0fff,
@@ -444,7 +444,7 @@
 	},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_3M
+#ifdef CONFIG_TOUCHSCREEN_USB_3M
 	[DEVTYPE_3M] = {
 		.min_xc		= 0x0,
 		.max_xc		= 0x4000,
@@ -456,7 +456,7 @@
 	},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_ITM
+#ifdef CONFIG_TOUCHSCREEN_USB_ITM
 	[DEVTYPE_ITM] = {
 		.min_xc		= 0x0,
 		.max_xc		= 0x0fff,
@@ -468,7 +468,7 @@
 	},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
+#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
 	[DEVTYPE_ETURBO] = {
 		.min_xc		= 0x0,
 		.max_xc		= 0x07ff,
@@ -482,7 +482,7 @@
 	},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
+#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
 	[DEVTYPE_GUNZE] = {
 		.min_xc		= 0x0,
 		.max_xc		= 0x0fff,
@@ -493,7 +493,7 @@
 	},
 #endif
 
-#ifdef CONFIG_USB_TOUCHSCREEN_DMC_TSC10
+#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
 	[DEVTYPE_DMC_TSC10] = {
 		.min_xc		= 0x0,
 		.max_xc		= 0x03ff,
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 1c040d8..152312c 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -304,6 +304,7 @@
 	char *host_fx_image;
 	char *guest_fx_image;
 	int fpu_active;
+	int guest_fpu_loaded;
 
 	int mmio_needed;
 	int mmio_read_completed;
@@ -508,6 +509,8 @@
 void load_msrs(struct vmx_msr_entry *e, int n);
 void save_msrs(struct vmx_msr_entry *e, int n);
 void kvm_resched(struct kvm_vcpu *vcpu);
+void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
+void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
 
 int kvm_read_guest(struct kvm_vcpu *vcpu,
 	       gva_t addr,
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index da985b3..8f1f07a 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -253,6 +253,28 @@
 }
 EXPORT_SYMBOL_GPL(kvm_write_guest);
 
+void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
+{
+	if (!vcpu->fpu_active || vcpu->guest_fpu_loaded)
+		return;
+
+	vcpu->guest_fpu_loaded = 1;
+	fx_save(vcpu->host_fx_image);
+	fx_restore(vcpu->guest_fx_image);
+}
+EXPORT_SYMBOL_GPL(kvm_load_guest_fpu);
+
+void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
+{
+	if (!vcpu->guest_fpu_loaded)
+		return;
+
+	vcpu->guest_fpu_loaded = 0;
+	fx_save(vcpu->guest_fx_image);
+	fx_restore(vcpu->host_fx_image);
+}
+EXPORT_SYMBOL_GPL(kvm_put_guest_fpu);
+
 /*
  * Switches to specified vcpu, until a matching vcpu_put()
  */
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 184238e..c1ac106 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -280,6 +280,7 @@
 
 static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
 {
+	kvm_put_guest_fpu(vcpu);
 	put_cpu();
 }
 
@@ -1847,10 +1848,8 @@
 	if (vcpu->guest_debug.enabled)
 		kvm_guest_debug_pre(vcpu);
 
-	if (vcpu->fpu_active) {
-		fx_save(vcpu->host_fx_image);
-		fx_restore(vcpu->guest_fx_image);
-	}
+	kvm_load_guest_fpu(vcpu);
+
 	/*
 	 * Loading guest fpu may have cleared host cr0.ts
 	 */
@@ -2012,11 +2011,6 @@
 	}
 #endif
 
-	if (vcpu->fpu_active) {
-		fx_save(vcpu->guest_fx_image);
-		fx_restore(vcpu->host_fx_image);
-	}
-
 	vcpu->interrupt_window_open = (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
 
 	asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 3a95cc5..46677d7 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1240,17 +1240,24 @@
 			}
 		r1_bio->read_disk = primary;
 		for (i=0; i<mddev->raid_disks; i++)
-			if (r1_bio->bios[i]->bi_end_io == end_sync_read &&
-			    test_bit(BIO_UPTODATE, &r1_bio->bios[i]->bi_flags)) {
+			if (r1_bio->bios[i]->bi_end_io == end_sync_read) {
 				int j;
 				int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9);
 				struct bio *pbio = r1_bio->bios[primary];
 				struct bio *sbio = r1_bio->bios[i];
-				for (j = vcnt; j-- ; )
-					if (memcmp(page_address(pbio->bi_io_vec[j].bv_page),
-						   page_address(sbio->bi_io_vec[j].bv_page),
-						   PAGE_SIZE))
-						break;
+
+				if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) {
+					for (j = vcnt; j-- ; ) {
+						struct page *p, *s;
+						p = pbio->bi_io_vec[j].bv_page;
+						s = sbio->bi_io_vec[j].bv_page;
+						if (memcmp(page_address(p),
+							   page_address(s),
+							   PAGE_SIZE))
+							break;
+					}
+				} else
+					j = 0;
 				if (j >= 0)
 					mddev->resync_mismatches += r1_bio->sectors;
 				if (j < 0 || test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) {
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 82249a6..9eb66c1 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1867,6 +1867,7 @@
 			int d = r10_bio->devs[i].devnum;
 			bio = r10_bio->devs[i].bio;
 			bio->bi_end_io = NULL;
+			clear_bit(BIO_UPTODATE, &bio->bi_flags);
 			if (conf->mirrors[d].rdev == NULL ||
 			    test_bit(Faulty, &conf->mirrors[d].rdev->flags))
 				continue;
@@ -2037,6 +2038,11 @@
 	/* 'size' is now the number of chunks in the array */
 	/* calculate "used chunks per device" in 'stride' */
 	stride = size * conf->copies;
+
+	/* We need to round up when dividing by raid_disks to
+	 * get the stride size.
+	 */
+	stride += conf->raid_disks - 1;
 	sector_div(stride, conf->raid_disks);
 	mddev->size = stride  << (conf->chunk_shift-1);
 
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index d75f7ff..37bf653 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -727,13 +727,15 @@
 	struct _MPT_SCSI_HOST *hd =
 		(struct _MPT_SCSI_HOST *)sdev->host->hostdata;
 	VirtTarget *vtarget = scsi_target(sdev)->hostdata;
-	int ret = mptscsih_slave_configure(sdev);
+	int ret;
+
+	mptspi_initTarget(hd, vtarget, sdev);
+
+	ret = mptscsih_slave_configure(sdev);
 
 	if (ret)
 		return ret;
 
-	mptspi_initTarget(hd, vtarget, sdev);
-
 	ddvprintk((MYIOC_s_INFO_FMT "id=%d min_period=0x%02x"
 		" max_offset=0x%02x max_width=%d\n", hd->ioc->name,
 		sdev->id, spi_min_period(scsi_target(sdev)),
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 41bfb5df..918477c 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -427,6 +427,21 @@
 		mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
 	}
 
+	/*
+	 * Check if read-only switch is active.
+	 */
+	if (!oldcard) {
+		if (!host->ops->get_ro) {
+			printk(KERN_WARNING "%s: host does not "
+				"support reading read-only "
+				"switch. assuming write-enable.\n",
+				mmc_hostname(host));
+		} else {
+			if (host->ops->get_ro(host))
+				mmc_card_set_readonly(card);
+		}
+	}
+
 	if (!oldcard)
 		host->card = card;
 
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 1914e65..b0824a3 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -522,28 +522,10 @@
 		}
 
 		if (status & OMAP_MMC_STAT_CARD_ERR) {
-			if (host->cmd && host->cmd->opcode == MMC_STOP_TRANSMISSION) {
-				u32 response = OMAP_MMC_READ(host, RSP6)
-					| (OMAP_MMC_READ(host, RSP7) << 16);
-				/* STOP sometimes sets must-ignore bits */
-				if (!(response & (R1_CC_ERROR
-								| R1_ILLEGAL_COMMAND
-								| R1_COM_CRC_ERROR))) {
-					end_command = 1;
-					continue;
-				}
-			}
-
-			dev_dbg(mmc_dev(host->mmc), "card status error (CMD%d)\n",
+			dev_dbg(mmc_dev(host->mmc),
+				"ignoring card status error (CMD%d)\n",
 				host->cmd->opcode);
-			if (host->cmd) {
-				host->cmd->error = MMC_ERR_FAILED;
-				end_command = 1;
-			}
-			if (host->data) {
-				host->data->error = MMC_ERR_FAILED;
-				transfer_error = 1;
-			}
+			end_command = 1;
 		}
 
 		/*
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 6169663..763810c 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -285,6 +285,12 @@
 	rus_mask         = 0x3C,
 };
 
+enum ru_state  {
+	RU_SUSPENDED = 0,
+	RU_RUNNING	 = 1,
+	RU_UNINITIALIZED = -1,
+};
+
 enum scb_stat_ack {
 	stat_ack_not_ours    = 0x00,
 	stat_ack_sw_gen      = 0x04,
@@ -526,6 +532,7 @@
 	struct rx *rx_to_use;
 	struct rx *rx_to_clean;
 	struct rfd blank_rfd;
+	enum ru_state ru_running;
 
 	spinlock_t cb_lock			____cacheline_aligned;
 	spinlock_t cmd_lock;
@@ -947,7 +954,7 @@
 		((nic->mac >= mac_82558_D101_A4) ? cb_cid : cb_i));
 
 	/* Template for a freshly allocated RFD */
-	nic->blank_rfd.command = cpu_to_le16(cb_el & cb_s);
+	nic->blank_rfd.command = cpu_to_le16(cb_el);
 	nic->blank_rfd.rbd = 0xFFFFFFFF;
 	nic->blank_rfd.size = cpu_to_le16(VLAN_ETH_FRAME_LEN);
 
@@ -1742,11 +1749,19 @@
 	return 0;
 }
 
-static inline void e100_start_receiver(struct nic *nic)
+static inline void e100_start_receiver(struct nic *nic, struct rx *rx)
 {
-	/* Start if RFA is non-NULL */
-	if(nic->rx_to_clean->skb)
-		e100_exec_cmd(nic, ruc_start, nic->rx_to_clean->dma_addr);
+	if(!nic->rxs) return;
+	if(RU_SUSPENDED != nic->ru_running) return;
+
+	/* handle init time starts */
+	if(!rx) rx = nic->rxs;
+
+	/* (Re)start RU if suspended or idle and RFA is non-NULL */
+	if(rx->skb) {
+		e100_exec_cmd(nic, ruc_start, rx->dma_addr);
+		nic->ru_running = RU_RUNNING;
+	}
 }
 
 #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN)
@@ -1775,7 +1790,7 @@
 		put_unaligned(cpu_to_le32(rx->dma_addr),
 			(u32 *)&prev_rfd->link);
 		wmb();
-		prev_rfd->command &= ~cpu_to_le16(cb_el & cb_s);
+		prev_rfd->command &= ~cpu_to_le16(cb_el);
 		pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr,
 			sizeof(struct rfd), PCI_DMA_TODEVICE);
 	}
@@ -1813,6 +1828,10 @@
 	pci_unmap_single(nic->pdev, rx->dma_addr,
 		RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
 
+	/* this allows for a fast restart without re-enabling interrupts */
+	if(le16_to_cpu(rfd->command) & cb_el)
+		nic->ru_running = RU_SUSPENDED;
+
 	/* Pull off the RFD and put the actual data (minus eth hdr) */
 	skb_reserve(skb, sizeof(struct rfd));
 	skb_put(skb, actual_size);
@@ -1843,18 +1862,45 @@
 	unsigned int work_to_do)
 {
 	struct rx *rx;
+	int restart_required = 0;
+	struct rx *rx_to_start = NULL;
+
+	/* are we already rnr? then pay attention!!! this ensures that
+	 * the state machine progression never allows a start with a
+	 * partially cleaned list, avoiding a race between hardware
+	 * and rx_to_clean when in NAPI mode */
+	if(RU_SUSPENDED == nic->ru_running)
+		restart_required = 1;
 
 	/* Indicate newly arrived packets */
 	for(rx = nic->rx_to_clean; rx->skb; rx = nic->rx_to_clean = rx->next) {
-		if(e100_rx_indicate(nic, rx, work_done, work_to_do))
+		int err = e100_rx_indicate(nic, rx, work_done, work_to_do);
+		if(-EAGAIN == err) {
+			/* hit quota so have more work to do, restart once
+			 * cleanup is complete */
+			restart_required = 0;
+			break;
+		} else if(-ENODATA == err)
 			break; /* No more to clean */
 	}
 
+	/* save our starting point as the place we'll restart the receiver */
+	if(restart_required)
+		rx_to_start = nic->rx_to_clean;
+
 	/* Alloc new skbs to refill list */
 	for(rx = nic->rx_to_use; !rx->skb; rx = nic->rx_to_use = rx->next) {
 		if(unlikely(e100_rx_alloc_skb(nic, rx)))
 			break; /* Better luck next time (see watchdog) */
 	}
+
+	if(restart_required) {
+		// ack the rnr?
+		writeb(stat_ack_rnr, &nic->csr->scb.stat_ack);
+		e100_start_receiver(nic, rx_to_start);
+		if(work_done)
+			(*work_done)++;
+	}
 }
 
 static void e100_rx_clean_list(struct nic *nic)
@@ -1862,6 +1908,8 @@
 	struct rx *rx;
 	unsigned int i, count = nic->params.rfds.count;
 
+	nic->ru_running = RU_UNINITIALIZED;
+
 	if(nic->rxs) {
 		for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
 			if(rx->skb) {
@@ -1883,6 +1931,7 @@
 	unsigned int i, count = nic->params.rfds.count;
 
 	nic->rx_to_use = nic->rx_to_clean = NULL;
+	nic->ru_running = RU_UNINITIALIZED;
 
 	if(!(nic->rxs = kcalloc(count, sizeof(struct rx), GFP_ATOMIC)))
 		return -ENOMEM;
@@ -1897,6 +1946,7 @@
 	}
 
 	nic->rx_to_use = nic->rx_to_clean = nic->rxs;
+	nic->ru_running = RU_SUSPENDED;
 
 	return 0;
 }
@@ -1916,6 +1966,10 @@
 	/* Ack interrupt(s) */
 	iowrite8(stat_ack, &nic->csr->scb.stat_ack);
 
+	/* We hit Receive No Resource (RNR); restart RU after cleaning */
+	if(stat_ack & stat_ack_rnr)
+		nic->ru_running = RU_SUSPENDED;
+
 	if(likely(netif_rx_schedule_prep(netdev))) {
 		e100_disable_irq(nic);
 		__netif_rx_schedule(netdev);
@@ -2007,7 +2061,7 @@
 	if((err = e100_hw_init(nic)))
 		goto err_clean_cbs;
 	e100_set_multicast_list(nic->netdev);
-	e100_start_receiver(nic);
+	e100_start_receiver(nic, NULL);
 	mod_timer(&nic->watchdog, jiffies);
 	if((err = request_irq(nic->pdev->irq, e100_intr, IRQF_SHARED,
 		nic->netdev->name, nic->netdev)))
@@ -2088,7 +2142,7 @@
 		mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR,
 			BMCR_LOOPBACK);
 
-	e100_start_receiver(nic);
+	e100_start_receiver(nic, NULL);
 
 	if(!(skb = netdev_alloc_skb(nic->netdev, ETH_DATA_LEN))) {
 		err = -ENOMEM;
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index e85a933..c0f81b5 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -39,7 +39,7 @@
 #include <asm/io.h>
 
 #define DRV_NAME	"ehea"
-#define DRV_VERSION	"EHEA_0061"
+#define DRV_VERSION	"EHEA_0064"
 
 #define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
 	| NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 152bb20..9e13433 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -451,7 +451,8 @@
 				processed_rq3++;
 			}
 
-			if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
+			if ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
+			    && port->vgrp)
 				vlan_hwaccel_receive_skb(skb, port->vgrp,
 							 cqe->vlan_tag);
 			else
@@ -1910,10 +1911,7 @@
 		goto out;
 	}
 
-	if (grp)
-		memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
-	else
-		memset(cb1->vlan_filter, 0xFF, sizeof(cb1->vlan_filter));
+	memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
 
 	hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
 				       H_PORT_CB1, H_PORT_CB1_ALL, cb1);
@@ -1947,7 +1945,7 @@
 	}
 
 	index = (vid / 64);
-	cb1->vlan_filter[index] |= ((u64)(1 << (vid & 0x3F)));
+	cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
 
 	hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
 				       H_PORT_CB1, H_PORT_CB1_ALL, cb1);
@@ -1982,7 +1980,7 @@
 	}
 
 	index = (vid / 64);
-	cb1->vlan_filter[index] &= ~((u64)(1 << (vid & 0x3F)));
+	cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
 
 	hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
 				       H_PORT_CB1, H_PORT_CB1_ALL, cb1);
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 3bec0f7..6ec3d50 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -915,17 +915,36 @@
 {
 	struct ibmveth_adapter *adapter = dev->priv;
 	int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
-	int i;
+	int reinit = 0;
+	int i, rc;
 
 	if (new_mtu < IBMVETH_MAX_MTU)
 		return -EINVAL;
 
+	for (i = 0; i < IbmVethNumBufferPools; i++)
+		if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
+			break;
+
+	if (i == IbmVethNumBufferPools)
+		return -EINVAL;
+
 	/* Look for an active buffer pool that can hold the new MTU */
 	for(i = 0; i<IbmVethNumBufferPools; i++) {
-		if (!adapter->rx_buff_pool[i].active)
-			continue;
+		if (!adapter->rx_buff_pool[i].active) {
+			adapter->rx_buff_pool[i].active = 1;
+			reinit = 1;
+		}
+
 		if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
-			dev->mtu = new_mtu;
+			if (reinit && netif_running(adapter->netdev)) {
+				adapter->pool_config = 1;
+				ibmveth_close(adapter->netdev);
+				adapter->pool_config = 0;
+				dev->mtu = new_mtu;
+				if ((rc = ibmveth_open(adapter->netdev)))
+					return rc;
+			} else
+				dev->mtu = new_mtu;
 			return 0;
 		}
 	}
@@ -1243,16 +1262,19 @@
 
 	if (attr == &veth_active_attr) {
 		if (value && !pool->active) {
-			if(ibmveth_alloc_buffer_pool(pool)) {
-                                ibmveth_error_printk("unable to alloc pool\n");
-                                return -ENOMEM;
-                        }
-			pool->active = 1;
-			adapter->pool_config = 1;
-			ibmveth_close(netdev);
-			adapter->pool_config = 0;
-			if ((rc = ibmveth_open(netdev)))
-				return rc;
+			if (netif_running(netdev)) {
+				if(ibmveth_alloc_buffer_pool(pool)) {
+					ibmveth_error_printk("unable to alloc pool\n");
+					return -ENOMEM;
+				}
+				pool->active = 1;
+				adapter->pool_config = 1;
+				ibmveth_close(netdev);
+				adapter->pool_config = 0;
+				if ((rc = ibmveth_open(netdev)))
+					return rc;
+			} else
+				pool->active = 1;
 		} else if (!value && pool->active) {
 			int mtu = netdev->mtu + IBMVETH_BUFF_OH;
 			int i;
@@ -1281,23 +1303,29 @@
 		if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
 			return -EINVAL;
 		else {
-			adapter->pool_config = 1;
-			ibmveth_close(netdev);
-			adapter->pool_config = 0;
-			pool->size = value;
-			if ((rc = ibmveth_open(netdev)))
-				return rc;
+			if (netif_running(netdev)) {
+				adapter->pool_config = 1;
+				ibmveth_close(netdev);
+				adapter->pool_config = 0;
+				pool->size = value;
+				if ((rc = ibmveth_open(netdev)))
+					return rc;
+			} else
+				pool->size = value;
 		}
 	} else if (attr == &veth_size_attr) {
 		if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE)
 			return -EINVAL;
 		else {
-			adapter->pool_config = 1;
-			ibmveth_close(netdev);
-			adapter->pool_config = 0;
-			pool->buff_size = value;
-			if ((rc = ibmveth_open(netdev)))
-				return rc;
+			if (netif_running(netdev)) {
+				adapter->pool_config = 1;
+				ibmveth_close(netdev);
+				adapter->pool_config = 0;
+				pool->buff_size = value;
+				if ((rc = ibmveth_open(netdev)))
+					return rc;
+			} else
+				pool->buff_size = value;
 		}
 	}
 
diff --git a/drivers/net/lasi_82596.c b/drivers/net/lasi_82596.c
index 6b49fc4..741780e 100644
--- a/drivers/net/lasi_82596.c
+++ b/drivers/net/lasi_82596.c
@@ -83,6 +83,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/bitops.h>
+#include <linux/dma-mapping.h>
 
 #include <asm/io.h>
 #include <asm/pgtable.h>
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index b53b7ad..0f9904f 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -71,7 +71,7 @@
 #include "myri10ge_mcp.h"
 #include "myri10ge_mcp_gen_header.h"
 
-#define MYRI10GE_VERSION_STR "1.3.0-1.233"
+#define MYRI10GE_VERSION_STR "1.3.1-1.248"
 
 MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
 MODULE_AUTHOR("Maintainer: help@myri.com");
@@ -279,6 +279,8 @@
 module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n");
 
+static int myri10ge_reset_recover = 1;
+
 static int myri10ge_wcfifo = 0;
 module_param(myri10ge_wcfifo, int, S_IRUGO);
 MODULE_PARM_DESC(myri10ge_wcfifo, "Enable WC Fifo when WC is enabled\n");
@@ -1154,9 +1156,11 @@
 	struct mcp_irq_data *stats = mgp->fw_stats;
 
 	if (unlikely(stats->stats_updated)) {
-		if (mgp->link_state != stats->link_up) {
-			mgp->link_state = stats->link_up;
-			if (mgp->link_state) {
+		unsigned link_up = ntohl(stats->link_up);
+		if (mgp->link_state != link_up) {
+			mgp->link_state = link_up;
+
+			if (mgp->link_state == MXGEFW_LINK_UP) {
 				if (netif_msg_link(mgp))
 					printk(KERN_INFO
 					       "myri10ge: %s: link up\n",
@@ -1166,8 +1170,11 @@
 			} else {
 				if (netif_msg_link(mgp))
 					printk(KERN_INFO
-					       "myri10ge: %s: link down\n",
-					       mgp->dev->name);
+					       "myri10ge: %s: link %s\n",
+					       mgp->dev->name,
+					       (link_up == MXGEFW_LINK_MYRINET ?
+						"mismatch (Myrinet detected)" :
+						"down"));
 				netif_carrier_off(mgp->dev);
 				mgp->link_changes++;
 			}
@@ -2730,8 +2737,14 @@
 		 * For now, just report it */
 		reboot = myri10ge_read_reboot(mgp);
 		printk(KERN_ERR
-		       "myri10ge: %s: NIC rebooted (0x%x), resetting\n",
-		       mgp->dev->name, reboot);
+		       "myri10ge: %s: NIC rebooted (0x%x),%s resetting\n",
+		       mgp->dev->name, reboot,
+		       myri10ge_reset_recover ? " " : " not");
+		if (myri10ge_reset_recover == 0)
+			return;
+
+		myri10ge_reset_recover--;
+
 		/*
 		 * A rebooted nic will come back with config space as
 		 * it was after power was applied to PCIe bus.
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index ad6688e..91f25e0 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -68,9 +68,10 @@
 #define _NETXEN_NIC_LINUX_SUBVERSION 2
 #define NETXEN_NIC_LINUX_VERSIONID  "3.4.2"
 
-#define NUM_FLASH_SECTORS (64)
-#define FLASH_SECTOR_SIZE (64 * 1024)
-#define FLASH_TOTAL_SIZE  (NUM_FLASH_SECTORS * FLASH_SECTOR_SIZE)
+#define NETXEN_NUM_FLASH_SECTORS (64)
+#define NETXEN_FLASH_SECTOR_SIZE (64 * 1024)
+#define NETXEN_FLASH_TOTAL_SIZE  (NETXEN_NUM_FLASH_SECTORS \
+					* NETXEN_FLASH_SECTOR_SIZE)
 
 #define PHAN_VENDOR_ID 0x4040
 
@@ -677,28 +678,28 @@
 
 /* Flash memory map */
 typedef enum {
-	CRBINIT_START = 0,	/* Crbinit section */
-	BRDCFG_START = 0x4000,	/* board config */
-	INITCODE_START = 0x6000,	/* pegtune code */
-	BOOTLD_START = 0x10000,	/* bootld */
-	IMAGE_START = 0x43000,	/* compressed image */
-	SECONDARY_START = 0x200000,	/* backup images */
-	PXE_START = 0x3E0000,	/* user defined region */
-	USER_START = 0x3E8000,	/* User defined region for new boards */
-	FIXED_START = 0x3F0000	/* backup of crbinit */
+	NETXEN_CRBINIT_START = 0,	/* Crbinit section */
+	NETXEN_BRDCFG_START = 0x4000,	/* board config */
+	NETXEN_INITCODE_START = 0x6000,	/* pegtune code */
+	NETXEN_BOOTLD_START = 0x10000,	/* bootld */
+	NETXEN_IMAGE_START = 0x43000,	/* compressed image */
+	NETXEN_SECONDARY_START = 0x200000,	/* backup images */
+	NETXEN_PXE_START = 0x3E0000,	/* user defined region */
+	NETXEN_USER_START = 0x3E8000,	/* User defined region for new boards */
+	NETXEN_FIXED_START = 0x3F0000	/* backup of crbinit */
 } netxen_flash_map_t;
 
-#define USER_START_OLD PXE_START	/* for backward compatibility */
+#define NETXEN_USER_START_OLD NETXEN_PXE_START	/* for backward compatibility */
 
-#define FLASH_START		(CRBINIT_START)
-#define INIT_SECTOR		(0)
-#define PRIMARY_START 		(BOOTLD_START)
-#define FLASH_CRBINIT_SIZE 	(0x4000)
-#define FLASH_BRDCFG_SIZE 	(sizeof(struct netxen_board_info))
-#define FLASH_USER_SIZE		(sizeof(struct netxen_user_info)/sizeof(u32))
-#define FLASH_SECONDARY_SIZE 	(USER_START-SECONDARY_START)
-#define NUM_PRIMARY_SECTORS	(0x20)
-#define NUM_CONFIG_SECTORS 	(1)
+#define NETXEN_FLASH_START		(NETXEN_CRBINIT_START)
+#define NETXEN_INIT_SECTOR		(0)
+#define NETXEN_PRIMARY_START 		(NETXEN_BOOTLD_START)
+#define NETXEN_FLASH_CRBINIT_SIZE 	(0x4000)
+#define NETXEN_FLASH_BRDCFG_SIZE 	(sizeof(struct netxen_board_info))
+#define NETXEN_FLASH_USER_SIZE		(sizeof(struct netxen_user_info)/sizeof(u32))
+#define NETXEN_FLASH_SECONDARY_SIZE 	(NETXEN_USER_START-NETXEN_SECONDARY_START)
+#define NETXEN_NUM_PRIMARY_SECTORS	(0x20)
+#define NETXEN_NUM_CONFIG_SECTORS 	(1)
 #define PFX "NetXen: "
 extern char netxen_nic_driver_name[];
 
@@ -1048,6 +1049,7 @@
 int netxen_do_rom_se(struct netxen_adapter *adapter, int addr);
 
 /* Functions from netxen_nic_isr.c */
+int netxen_nic_link_ok(struct netxen_adapter *adapter);
 void netxen_nic_isr_other(struct netxen_adapter *adapter);
 void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 link);
 void netxen_handle_port_int(struct netxen_adapter *adapter, u32 enable);
diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c
index 16fabb3..0175f6c 100644
--- a/drivers/net/netxen/netxen_nic_ethtool.c
+++ b/drivers/net/netxen/netxen_nic_ethtool.c
@@ -94,7 +94,7 @@
 
 static int netxen_nic_get_eeprom_len(struct net_device *dev)
 {
-	return FLASH_TOTAL_SIZE;
+	return NETXEN_FLASH_TOTAL_SIZE;
 }
 
 static void
@@ -470,7 +470,7 @@
 		return 0;
 	}
 
-	if (offset == BOOTLD_START) {
+	if (offset == NETXEN_BOOTLD_START) {
 		ret = netxen_flash_erase_primary(adapter);
 		if (ret != FLASH_SUCCESS) {
 			printk(KERN_ERR "%s: Flash erase failed.\n", 
@@ -478,10 +478,10 @@
 			return ret;
 		}
 
-		ret = netxen_rom_se(adapter, USER_START);
+		ret = netxen_rom_se(adapter, NETXEN_USER_START);
 		if (ret != FLASH_SUCCESS)
 			return ret;
-		ret = netxen_rom_se(adapter, FIXED_START);
+		ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
 		if (ret != FLASH_SUCCESS)
 			return ret;
 
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index baff17a..c012764 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -257,7 +257,7 @@
 #define ADDR_IN_RANGE(addr, low, high)	\
 	(((addr) <= (high)) && ((addr) >= (low)))
 
-#define NETXEN_FLASH_BASE	(BOOTLD_START)
+#define NETXEN_FLASH_BASE	(NETXEN_BOOTLD_START)
 #define NETXEN_PHANTOM_MEM_BASE	(NETXEN_FLASH_BASE)
 #define NETXEN_MAX_MTU		8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE
 #define NETXEN_MIN_MTU		64
@@ -611,7 +611,7 @@
 	u32 *pmac = (u32 *) & mac[0];
 
 	if (netxen_get_flash_block(adapter,
-				   USER_START +
+				   NETXEN_USER_START +
 				   offsetof(struct netxen_new_user_info,
 					    mac_addr),
 				   FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
@@ -619,7 +619,7 @@
 	}
 	if (*mac == ~0ULL) {
 		if (netxen_get_flash_block(adapter,
-					   USER_START_OLD +
+					   NETXEN_USER_START_OLD +
 					   offsetof(struct netxen_user_old_info,
 						    mac_addr),
 					   FLASH_NUM_PORTS * sizeof(u64),
@@ -942,7 +942,7 @@
 int
 netxen_nic_erase_pxe(struct netxen_adapter *adapter)
 {
-	if (netxen_rom_fast_write(adapter, PXE_START, 0) == -1) {
+	if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
 		printk(KERN_ERR "%s: erase pxe failed\n", 
 			netxen_nic_driver_name);
 		return -1;
@@ -953,7 +953,7 @@
 int netxen_nic_get_board_info(struct netxen_adapter *adapter)
 {
 	int rv = 0;
-	int addr = BRDCFG_START;
+	int addr = NETXEN_BRDCFG_START;
 	struct netxen_board_info *boardinfo;
 	int index;
 	u32 *ptr32;
@@ -1115,7 +1115,7 @@
 	u32 fw_build = 0;
 	char brd_name[NETXEN_MAX_SHORT_NAME];
 	struct netxen_new_user_info user_info;
-	int i, addr = USER_START;
+	int i, addr = NETXEN_USER_START;
 	__le32 *ptr32;
 
 	struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index a368924..bb23f4c 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -585,7 +585,7 @@
 {
 	int ret = FLASH_SUCCESS;
 	int val;
-	char *buffer = kmalloc(FLASH_SECTOR_SIZE, GFP_KERNEL);
+	char *buffer = kmalloc(NETXEN_FLASH_SECTOR_SIZE, GFP_KERNEL);
 
 	if (!buffer)
 		return -ENOMEM;	
@@ -601,13 +601,13 @@
 		goto out_kfree;
 
 	/* copy  sector 0 to sector 63 */
-	ret = netxen_rom_fast_read_words(adapter, CRBINIT_START, 
-						buffer, FLASH_SECTOR_SIZE);
+	ret = netxen_rom_fast_read_words(adapter, NETXEN_CRBINIT_START, 
+					buffer, NETXEN_FLASH_SECTOR_SIZE);
 	if (ret != FLASH_SUCCESS)
 		goto out_kfree;
 
-	ret = netxen_rom_fast_write_words(adapter, FIXED_START, 
-						buffer, FLASH_SECTOR_SIZE);
+	ret = netxen_rom_fast_write_words(adapter, NETXEN_FIXED_START, 
+					buffer, NETXEN_FLASH_SECTOR_SIZE);
 	if (ret != FLASH_SUCCESS)
 		goto out_kfree;
 
@@ -654,7 +654,8 @@
 	int count = 0, erased_errors = 0;
 	int range;
 
-	range = (addr == USER_START) ? FIXED_START : addr + FLASH_SECTOR_SIZE;
+	range = (addr == NETXEN_USER_START) ? 
+		NETXEN_FIXED_START : addr + NETXEN_FLASH_SECTOR_SIZE;
 	
 	for (i = addr; i < range; i += 4) {
 		netxen_rom_fast_read(adapter, i, &val);
@@ -689,7 +690,7 @@
 	int i;
 
 	for (i = start; i < end; i++) {
-		ret = netxen_rom_se(adapter, i * FLASH_SECTOR_SIZE);
+		ret = netxen_rom_se(adapter, i * NETXEN_FLASH_SECTOR_SIZE);
 		if (ret)
 			break;
 		ret = netxen_rom_wip_poll(adapter);
@@ -706,8 +707,8 @@
 	int ret = FLASH_SUCCESS;
 	int start, end;
 
-	start = SECONDARY_START / FLASH_SECTOR_SIZE;
-	end   = USER_START / FLASH_SECTOR_SIZE;
+	start = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE;
+	end   = NETXEN_USER_START / NETXEN_FLASH_SECTOR_SIZE;
 	ret = netxen_flash_erase_sections(adapter, start, end);
 
 	return ret;
@@ -719,8 +720,8 @@
 	int ret = FLASH_SUCCESS;
 	int start, end;
 
-	start = PRIMARY_START / FLASH_SECTOR_SIZE;
-	end   = SECONDARY_START / FLASH_SECTOR_SIZE;
+	start = NETXEN_PRIMARY_START / NETXEN_FLASH_SECTOR_SIZE;
+	end   = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE;
 	ret = netxen_flash_erase_sections(adapter, start, end);
 
 	return ret;
@@ -1036,18 +1037,23 @@
 	if ((adapter->portnum  == 0) && netxen_nic_check_temp(adapter))
 		return;
 
-	netdev = adapter->netdev;
-	if ((netif_running(netdev)) && !netif_carrier_ok(netdev)) {
-		printk(KERN_INFO "%s port %d, %s carrier is now ok\n",
-		       netxen_nic_driver_name, adapter->portnum, netdev->name);
-		netif_carrier_on(netdev);
-	}
-
-	if (netif_queue_stopped(netdev))
-		netif_wake_queue(netdev);
-
 	if (adapter->handle_phy_intr)
 		adapter->handle_phy_intr(adapter);
+
+	netdev = adapter->netdev;
+	if ((netif_running(netdev)) && !netif_carrier_ok(netdev) &&
+			netxen_nic_link_ok(adapter) ) {
+		printk(KERN_INFO "%s %s (port %d), Link is up\n",
+			       netxen_nic_driver_name, netdev->name, adapter->portnum);
+		netif_carrier_on(netdev);
+		netif_wake_queue(netdev);
+	} else if(!(netif_running(netdev)) && netif_carrier_ok(netdev)) {
+		printk(KERN_ERR "%s %s Link is Down\n",
+				netxen_nic_driver_name, netdev->name);
+		netif_carrier_off(netdev);
+		netif_stop_queue(netdev);
+	}
+
 	mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
 }
 
diff --git a/drivers/net/netxen/netxen_nic_isr.c b/drivers/net/netxen/netxen_nic_isr.c
index b213b06..b2de6b6 100644
--- a/drivers/net/netxen/netxen_nic_isr.c
+++ b/drivers/net/netxen/netxen_nic_isr.c
@@ -169,6 +169,24 @@
 	netxen_nic_isr_other(adapter);
 }
 
+int netxen_nic_link_ok(struct netxen_adapter *adapter)
+{
+	switch (adapter->ahw.board_type) {
+	case NETXEN_NIC_GBE:
+		return ((adapter->ahw.qg_linksup) & 1);
+
+	case NETXEN_NIC_XGBE:
+		return ((adapter->ahw.xg_linkup) & 1);
+
+	default:
+		printk(KERN_ERR"%s: Function: %s, Unknown board type\n",
+			netxen_nic_driver_name, __FUNCTION__);
+		break;
+	}
+
+	return 0;
+}
+
 void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
 {
 	struct net_device *netdev = adapter->netdev;
@@ -183,6 +201,10 @@
 		printk(KERN_INFO "%s: %s NIC Link is down\n",
 		       netxen_nic_driver_name, netdev->name);
 		adapter->ahw.xg_linkup = 0;
+		if (netif_running(netdev)) {
+			netif_carrier_off(netdev);
+			netif_stop_queue(netdev);
+		}
 		/* read twice to clear sticky bits */
 		/* WINDOW = 0 */
 		netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1);
@@ -196,5 +218,7 @@
 		printk(KERN_INFO "%s: %s NIC Link is up\n",
 		       netxen_nic_driver_name, netdev->name);
 		adapter->ahw.xg_linkup = 1;
+		netif_carrier_on(netdev);
+		netif_wake_queue(netdev);
 	}
 }
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index c61181f..6167b58 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -542,6 +542,13 @@
 				NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
 		/* Handshake with the card before we register the devices. */
 		netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
+
+	       /* leave the hw in the same state as reboot */
+	       writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
+	       netxen_pinit_from_rom(adapter, 0);
+	       udelay(500);
+	       netxen_load_firmware(adapter);
+	       netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
 	}
 
 	/*
diff --git a/drivers/net/netxen/netxen_nic_niu.c b/drivers/net/netxen/netxen_nic_niu.c
index cef90a7..75102d3 100644
--- a/drivers/net/netxen/netxen_nic_niu.c
+++ b/drivers/net/netxen/netxen_nic_niu.c
@@ -454,16 +454,12 @@
 
 int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
 {
-	u32 reg;
 	u32 portnum = physical_port[adapter->portnum];
 
 	netxen_crb_writelit_adapter(adapter,
-		NETXEN_NIU_XGE_CONFIG_0+(0x10000*portnum), 0x5);
-	netxen_nic_hw_read_wx(adapter,
-		NETXEN_NIU_XGE_CONFIG_1+(0x10000*portnum), &reg, 4);
-	reg = (reg & ~0x2000UL);
+		NETXEN_NIU_XGE_CONFIG_1+(0x10000*portnum), 0x1447);
 	netxen_crb_writelit_adapter(adapter,
-		NETXEN_NIU_XGE_CONFIG_1+(0x10000*portnum), reg);
+		NETXEN_NIU_XGE_CONFIG_0+(0x10000*portnum), 0x5);
 
 	return 0;
 }
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 22aec5c..b87f8d2 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -54,6 +54,12 @@
 #define MII_M1111_PHY_LED_CONTROL	0x18
 #define MII_M1111_PHY_LED_DIRECT	0x4100
 #define MII_M1111_PHY_LED_COMBINE	0x411c
+#define MII_M1111_PHY_EXT_CR		0x14
+#define MII_M1111_RX_DELAY		0x80
+#define MII_M1111_TX_DELAY		0x2
+#define MII_M1111_PHY_EXT_SR		0x1b
+#define MII_M1111_HWCFG_MODE_MASK	0xf
+#define MII_M1111_HWCFG_MODE_RGMII	0xb
 
 MODULE_DESCRIPTION("Marvell PHY driver");
 MODULE_AUTHOR("Andy Fleming");
@@ -131,6 +137,45 @@
 	return err;
 }
 
+static int m88e1111_config_init(struct phy_device *phydev)
+{
+	int err;
+
+	if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
+	    (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) {
+		int temp;
+
+		if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
+			temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
+			if (temp < 0)
+				return temp;
+
+			temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
+
+			err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
+			if (err < 0)
+				return err;
+		}
+
+		temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
+		if (temp < 0)
+			return temp;
+
+		temp &= ~(MII_M1111_HWCFG_MODE_MASK);
+		temp |= MII_M1111_HWCFG_MODE_RGMII;
+
+		err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
+		if (err < 0)
+			return err;
+	}
+
+	err = phy_write(phydev, MII_BMCR, BMCR_RESET);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
 static int m88e1145_config_init(struct phy_device *phydev)
 {
 	int err;
@@ -152,7 +197,7 @@
 	if (err < 0)
 		return err;
 
-	if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
+	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
 		int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
 		if (temp < 0)
 			return temp;
@@ -206,7 +251,7 @@
 	.driver = {.owner = THIS_MODULE,},
 };
 
-static struct phy_driver m88e1111s_driver = {
+static struct phy_driver m88e1111_driver = {
 	.phy_id = 0x01410cc0,
 	.phy_id_mask = 0xfffffff0,
 	.name = "Marvell 88E1111",
@@ -216,6 +261,7 @@
 	.read_status = &genphy_read_status,
 	.ack_interrupt = &marvell_ack_interrupt,
 	.config_intr = &marvell_config_intr,
+	.config_init = &m88e1111_config_init,
 	.driver = {.owner = THIS_MODULE,},
 };
 
@@ -241,9 +287,9 @@
 	if (ret)
 		return ret;
 
-	ret = phy_driver_register(&m88e1111s_driver);
+	ret = phy_driver_register(&m88e1111_driver);
 	if (ret)
-		goto err1111s;
+		goto err1111;
 
 	ret = phy_driver_register(&m88e1145_driver);
 	if (ret)
@@ -251,9 +297,9 @@
 
 	return 0;
 
-      err1145:
-	phy_driver_unregister(&m88e1111s_driver);
-      err1111s:
+err1145:
+	phy_driver_unregister(&m88e1111_driver);
+err1111:
 	phy_driver_unregister(&m88e1101_driver);
 	return ret;
 }
@@ -261,7 +307,7 @@
 static void __exit marvell_exit(void)
 {
 	phy_driver_unregister(&m88e1101_driver);
-	phy_driver_unregister(&m88e1111s_driver);
+	phy_driver_unregister(&m88e1111_driver);
 	phy_driver_unregister(&m88e1145_driver);
 }
 
diff --git a/drivers/net/ppp_mppe.c b/drivers/net/ppp_mppe.c
index d5bdd25..5ae80bb 100644
--- a/drivers/net/ppp_mppe.c
+++ b/drivers/net/ppp_mppe.c
@@ -493,14 +493,14 @@
 
 	/*
 	 * Make sure we have enough room to decrypt the packet.
-	 * Note that for our test we only subtract 1 byte whereas in
-	 * mppe_compress() we added 2 bytes (+MPPE_OVHD);
-	 * this is to account for possible PFC.
+	 * To account for possible PFC we should only subtract 1
+	 * byte whereas in mppe_compress() we added 2 bytes (+MPPE_OVHD);
+	 * However, we assume no PFC, thus subtracting 2 bytes.
 	 */
-	if (osize < isize - MPPE_OVHD - 1) {
+	if (osize < isize - MPPE_OVHD - 2) {
 		printk(KERN_DEBUG "mppe_decompress[%d]: osize too small! "
 		       "(have: %d need: %d)\n", state->unit,
-		       osize, isize - MPPE_OVHD - 1);
+		       osize, isize - MPPE_OVHD - 2);
 		return DECOMP_ERROR;
 	}
 	osize = isize - MPPE_OVHD - 2;	/* assume no PFC */
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 506bffc..f842944 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -58,6 +58,8 @@
 #elif defined(CONFIG_BFIN)
 
 #define SMC_IRQ_FLAGS		IRQF_TRIGGER_HIGH
+#define RPC_LSA_DEFAULT		RPC_LED_100_10
+#define RPC_LSB_DEFAULT		RPC_LED_TX_RX
 
 # if defined (CONFIG_BFIN561_EZKIT)
 #define SMC_CAN_USE_8BIT	0
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 3de564b..8dc09a3 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -313,8 +313,8 @@
 	boolean "KT Technology KC2190 based cables (InstaNet)"
 	depends on USB_NET_CDC_SUBSET && EXPERIMENTAL
 	help
-	  Choose this option if you're using a host-to-host cable
-	  with one of these chips.
+	  Choose this option if you're using a host-to-host cable
+	  with one of these chips.
 
 config USB_NET_ZAURUS
 	tristate "Sharp Zaurus (stock ROMs) and compatible"
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 25b75b6..b670b97 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -1562,7 +1562,7 @@
 	if (vptr->mii_status & VELOCITY_LINK_FAIL) {
 		VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: failed to detect cable link\n", vptr->dev->name);
 	} else if (vptr->options.spd_dpx == SPD_DPX_AUTO) {
-		VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: Link autonegation", vptr->dev->name);
+		VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: Link auto-negotiation", vptr->dev->name);
 
 		if (vptr->mii_status & VELOCITY_SPEED_1000)
 			VELOCITY_PRT(MSG_LEVEL_INFO, " speed 1000M bps");
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index e3f5bb0..fa2399c 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -266,16 +266,23 @@
 
 	  If you are not sure, say N here.
 
-config LIBERTAS_USB
-	tristate "Marvell Libertas 8388 802.11a/b/g cards"
-	depends on USB && WLAN_80211
+config LIBERTAS
+	tristate "Marvell 8xxx Libertas WLAN driver support"
+	depends on WLAN_80211
+	select IEEE80211
 	select FW_LOADER
 	---help---
+	  A library for Marvell Libertas 8xxx devices.
+
+config LIBERTAS_USB
+	tristate "Marvell Libertas 8388 USB 802.11b/g cards"
+	depends on LIBERTAS && USB
+	---help---
 	  A driver for Marvell Libertas 8388 USB devices.
 
-config LIBERTAS_USB_DEBUG
-	bool "Enable full debugging output in the Libertas USB module."
-	depends on LIBERTAS_USB
+config LIBERTAS_DEBUG
+	bool "Enable full debugging output in the Libertas module."
+	depends on LIBERTAS
 	---help---
 	  Debugging support.
 
diff --git a/drivers/net/wireless/libertas/11d.c b/drivers/net/wireless/libertas/11d.c
index e0ecc4d..4cf0ff7 100644
--- a/drivers/net/wireless/libertas/11d.c
+++ b/drivers/net/wireless/libertas/11d.c
@@ -95,7 +95,7 @@
 
 	for (i = 0; i < cfp_no; i++) {
 		if ((cfp + i)->channel == firstchan) {
-			lbs_pr_debug(1, "firstchan found\n");
+			lbs_deb_11d("firstchan found\n");
 			break;
 		}
 	}
@@ -129,12 +129,12 @@
 
 	for (i = 0; i < nr_chan; i++) {
 		if (chan == chanpwr[i].chan) {
-			lbs_pr_debug(1, "11D: Found Chan:%d\n", chan);
+			lbs_deb_11d("11D: Found Chan:%d\n", chan);
 			return 1;
 		}
 	}
 
-	lbs_pr_debug(1, "11D: Not Find Chan:%d\n", chan);
+	lbs_deb_11d("11D: Not Find Chan:%d\n", chan);
 	return 0;
 }
 
@@ -174,7 +174,7 @@
 	memcpy(domaininfo->countrycode, parsed_region_chan->countrycode,
 	       COUNTRY_CODE_LEN);
 
-	lbs_pr_debug(1, "11D:nrchan=%d\n", nr_chan);
+	lbs_deb_11d("11D:nrchan=%d\n", nr_chan);
 	lbs_dbg_hex("11D:parsed_region_chan:", (char *)parsed_region_chan,
 		sizeof(struct parsed_region_chan_11d));
 
@@ -212,7 +212,7 @@
 	}
 	domaininfo->nr_subband = nr_subband;
 
-	lbs_pr_debug(1, "nr_subband=%x\n", domaininfo->nr_subband);
+	lbs_deb_11d("nr_subband=%x\n", domaininfo->nr_subband);
 	lbs_dbg_hex("11D:domaininfo:", (char *)domaininfo,
 		COUNTRY_CODE_LEN + 1 +
 		sizeof(struct ieeetypes_subbandset) * nr_subband);
@@ -233,13 +233,13 @@
 	struct chan_freq_power *cfp;
 
 	if (region_chan == NULL) {
-		lbs_pr_debug(1, "11D: region_chan is NULL\n");
+		lbs_deb_11d("11D: region_chan is NULL\n");
 		return;
 	}
 
 	cfp = region_chan->CFP;
 	if (cfp == NULL) {
-		lbs_pr_debug(1, "11D: cfp equal NULL \n");
+		lbs_deb_11d("11D: cfp equal NULL \n");
 		return;
 	}
 
@@ -248,19 +248,19 @@
 	memcpy(parsed_region_chan->countrycode,
 	       wlan_code_2_region(region_chan->region), COUNTRY_CODE_LEN);
 
-	lbs_pr_debug(1, "11D: region[0x%x] band[%d]\n", parsed_region_chan->region,
+	lbs_deb_11d("11D: region[0x%x] band[%d]\n", parsed_region_chan->region,
 	       parsed_region_chan->band);
 
 	for (i = 0; i < region_chan->nrcfp; i++, cfp++) {
 		parsed_region_chan->chanpwr[i].chan = cfp->channel;
 		parsed_region_chan->chanpwr[i].pwr = cfp->maxtxpower;
-		lbs_pr_debug(1, "11D: Chan[%d] Pwr[%d]\n",
+		lbs_deb_11d("11D: Chan[%d] Pwr[%d]\n",
 		       parsed_region_chan->chanpwr[i].chan,
 		       parsed_region_chan->chanpwr[i].pwr);
 	}
 	parsed_region_chan->nr_chan = region_chan->nrcfp;
 
-	lbs_pr_debug(1, "11D: nrchan[%d]\n", parsed_region_chan->nr_chan);
+	lbs_deb_11d("11D: nrchan[%d]\n", parsed_region_chan->nr_chan);
 
 	return;
 }
@@ -277,8 +277,9 @@
 	struct chan_freq_power *cfp;
 	int cfp_no;
 	u8 idx;
+	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_11D);
 
 	cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
 	if (cfp == NULL)
@@ -288,16 +289,19 @@
 		if (chan == (cfp + idx)->channel) {
 			/* If Mrvl Chip Supported? */
 			if ((cfp + idx)->unsupported) {
-				return 0;
+				ret = 0;
 			} else {
-				return 1;
+				ret = 1;
 			}
+			goto done;
 		}
 	}
 
 	/*chan is not in the region table */
-	LEAVE();
-	return 0;
+
+done:
+	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
+	return ret;
 }
 
 /**
@@ -321,7 +325,7 @@
 
 	u8 j, i;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_11D);
 
 	/*validation Rules:
 	   1. valid region Code
@@ -337,15 +341,14 @@
 	if ((*(countryinfo->countrycode)) == 0
 	    || (countryinfo->len <= COUNTRY_CODE_LEN)) {
 		/* No region Info or Wrong region info: treat as No 11D info */
-		LEAVE();
-		return 0;
+		goto done;
 	}
 
 	/*Step1: check region_code */
 	parsed_region_chan->region = region =
 	    wlan_region_2_code(countryinfo->countrycode);
 
-	lbs_pr_debug(1, "regioncode=%x\n", (u8) parsed_region_chan->region);
+	lbs_deb_11d("regioncode=%x\n", (u8) parsed_region_chan->region);
 	lbs_dbg_hex("CountryCode:", (char *)countryinfo->countrycode,
 		COUNTRY_CODE_LEN);
 
@@ -361,7 +364,7 @@
 
 		if (countryinfo->subband[j].firstchan <= lastchan) {
 			/*Step2&3. Check First Chan Num increment and no overlap */
-			lbs_pr_debug(1, "11D: Chan[%d>%d] Overlap\n",
+			lbs_deb_11d("11D: Chan[%d>%d] Overlap\n",
 			       countryinfo->subband[j].firstchan, lastchan);
 			continue;
 		}
@@ -374,7 +377,7 @@
 
 			if (!wlan_get_chan_11d(band, firstchan, i, &curchan)) {
 				/* Chan is not found in UN table */
-				lbs_pr_debug(1, "chan is not supported: %d \n", i);
+				lbs_deb_11d("chan is not supported: %d \n", i);
 				break;
 			}
 
@@ -389,7 +392,7 @@
 				idx++;
 			} else {
 				/*not supported and ignore the chan */
-				lbs_pr_debug(1,
+				lbs_deb_11d(
 				       "11D:i[%d] chan[%d] unsupported in region[%x] band[%d]\n",
 				       i, curchan, region, band);
 			}
@@ -401,11 +404,12 @@
 
 	parsed_region_chan->nr_chan = idx;
 
-	lbs_pr_debug(1, "nrchan=%x\n", parsed_region_chan->nr_chan);
+	lbs_deb_11d("nrchan=%x\n", parsed_region_chan->nr_chan);
 	lbs_dbg_hex("11D:parsed_region_chan:", (u8 *) parsed_region_chan,
 		2 + COUNTRY_CODE_LEN + sizeof(struct parsed_region_chan_11d) * idx);
 
-	LEAVE();
+done:
+	lbs_deb_enter(LBS_DEB_11D);
 	return 0;
 }
 
@@ -420,16 +424,16 @@
 {
 	u8 scan_type = cmd_scan_type_passive;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_11D);
 
 	if (wlan_channel_known_11d(chan, parsed_region_chan)) {
-		lbs_pr_debug(1, "11D: Found and do Active Scan\n");
+		lbs_deb_11d("11D: Found and do Active Scan\n");
 		scan_type = cmd_scan_type_active;
 	} else {
-		lbs_pr_debug(1, "11D: Not Find and do Passive Scan\n");
+		lbs_deb_11d("11D: Not Find and do Passive Scan\n");
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_11D, "ret scan_type %d", scan_type);
 	return scan_type;
 
 }
@@ -456,7 +460,7 @@
 				    OID_802_11D_ENABLE,
 				    &priv->adapter->enable11d);
 	if (ret)
-		lbs_pr_debug(1, "11D: Fail to enable 11D \n");
+		lbs_deb_11d("11D: Fail to enable 11D \n");
 
 	return 0;
 }
@@ -471,7 +475,7 @@
 	int ret;
 
 	if (!priv->adapter->enable11d) {
-		lbs_pr_debug(1, "11D: dnld domain Info with 11d disabled\n");
+		lbs_deb_11d("11D: dnld domain Info with 11d disabled\n");
 		return 0;
 	}
 
@@ -479,7 +483,7 @@
 				    cmd_act_set,
 				    cmd_option_waitforrsp, 0, NULL);
 	if (ret)
-		lbs_pr_debug(1, "11D: Fail to dnld domain Info\n");
+		lbs_deb_11d("11D: Fail to dnld domain Info\n");
 
 	return ret;
 }
@@ -501,7 +505,7 @@
 
 	adapter->universal_channel[i].nrcfp =
 	    sizeof(channel_freq_power_UN_BG) / size;
-	lbs_pr_debug(1, "11D: BG-band nrcfp=%d\n",
+	lbs_deb_11d("11D: BG-band nrcfp=%d\n",
 	       adapter->universal_channel[i].nrcfp);
 
 	adapter->universal_channel[i].CFP = channel_freq_power_UN_BG;
@@ -531,9 +535,9 @@
 	wlan_adapter *adapter = priv->adapter;
 	u8 nr_subband = adapter->domainreg.nr_subband;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_11D);
 
-	lbs_pr_debug(1, "nr_subband=%x\n", nr_subband);
+	lbs_deb_11d("nr_subband=%x\n", nr_subband);
 
 	cmd->command = cpu_to_le16(cmdno);
 	pdomaininfo->action = cpu_to_le16(cmdoption);
@@ -542,8 +546,7 @@
 		    cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
 		lbs_dbg_hex("11D: 802_11D_DOMAIN_INFO:", (u8 *) cmd,
 			(int)(cmd->size));
-		LEAVE();
-		return 0;
+		goto done;
 	}
 
 	domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
@@ -567,10 +570,10 @@
 		    cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
 	}
 
-	lbs_dbg_hex("11D:802_11D_DOMAIN_INFO:", (u8 *) cmd, (int)(cmd->size));
+	lbs_dbg_hex("11D:802_11D_DOMAIN_INFO:", (u8 *) cmd, le16_to_cpu(cmd->size));
 
-	LEAVE();
-
+done:
+	lbs_deb_enter(LBS_DEB_11D);
 	return 0;
 }
 
@@ -585,17 +588,17 @@
 	int data = 0;
 	int *val;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_11D);
 	data = SUBCMD_DATA(wrq);
 
-	lbs_pr_debug(1, "enable 11D: %s\n",
+	lbs_deb_11d("enable 11D: %s\n",
 	       (data == 1) ? "enable" : "Disable");
 
 	wlan_enable_11d(priv, data);
 	val = (int *)wrq->u.name;
 	*val = priv->adapter->enable11d;
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_11D);
 	return 0;
 }
 
@@ -608,25 +611,24 @@
 int libertas_ret_802_11d_domain_info(wlan_private * priv,
 				 struct cmd_ds_command *resp)
 {
-	struct cmd_ds_802_11d_domain_info
-	*domaininfo = &resp->params.domaininforesp;
+	struct cmd_ds_802_11d_domain_info *domaininfo = &resp->params.domaininforesp;
 	struct mrvlietypes_domainparamset *domain = &domaininfo->domain;
 	u16 action = le16_to_cpu(domaininfo->action);
 	s16 ret = 0;
 	u8 nr_subband = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_11D);
 
 	lbs_dbg_hex("11D DOMAIN Info Rsp Data:", (u8 *) resp,
 		(int)le16_to_cpu(resp->size));
 
-	nr_subband = (domain->header.len - 3) / sizeof(struct ieeetypes_subbandset);
-	/* countrycode 3 bytes */
+	nr_subband = (le16_to_cpu(domain->header.len) - COUNTRY_CODE_LEN) /
+		      sizeof(struct ieeetypes_subbandset);
 
-	lbs_pr_debug(1, "11D Domain Info Resp: nr_subband=%d\n", nr_subband);
+	lbs_deb_11d("11D Domain Info Resp: nr_subband=%d\n", nr_subband);
 
 	if (nr_subband > MRVDRV_MAX_SUBBAND_802_11D) {
-		lbs_pr_debug(1, "Invalid Numrer of Subband returned!!\n");
+		lbs_deb_11d("Invalid Numrer of Subband returned!!\n");
 		return -1;
 	}
 
@@ -637,12 +639,12 @@
 	case cmd_act_get:
 		break;
 	default:
-		lbs_pr_debug(1, "Invalid action:%d\n", domaininfo->action);
+		lbs_deb_11d("Invalid action:%d\n", domaininfo->action);
 		ret = -1;
 		break;
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
 	return ret;
 }
 
@@ -651,23 +653,22 @@
  *  @param priv    pointer to wlan_private
  *  @return 	   0; -1
  */
-int libertas_parse_dnld_countryinfo_11d(wlan_private * priv)
+int libertas_parse_dnld_countryinfo_11d(wlan_private * priv,
+                                        struct bss_descriptor * bss)
 {
 	int ret;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_11D);
 	if (priv->adapter->enable11d) {
 		memset(&adapter->parsed_region_chan, 0,
 		       sizeof(struct parsed_region_chan_11d));
-		ret = parse_domain_info_11d(&adapter->pattemptedbssdesc->
-					       countryinfo, 0,
+		ret = parse_domain_info_11d(&bss->countryinfo, 0,
 					       &adapter->parsed_region_chan);
 
 		if (ret == -1) {
-			lbs_pr_debug(1, "11D: Err Parse domain_info from AP..\n");
-			LEAVE();
-			return ret;
+			lbs_deb_11d("11D: Err Parse domain_info from AP..\n");
+			goto done;
 		}
 
 		memset(&adapter->domainreg, 0,
@@ -678,13 +679,15 @@
 		ret = set_domain_info_11d(priv);
 
 		if (ret) {
-			lbs_pr_debug(1, "11D: Err set domainInfo to FW\n");
-			LEAVE();
-			return ret;
+			lbs_deb_11d("11D: Err set domainInfo to FW\n");
+			goto done;
 		}
 	}
-	LEAVE();
-	return 0;
+	ret = 0;
+
+done:
+	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
+	return ret;
 }
 
 /**
@@ -699,8 +702,8 @@
 	struct region_channel *region_chan;
 	u8 j;
 
-	ENTER();
-	lbs_pr_debug(1, "11D:curbssparams.band[%d]\n", adapter->curbssparams.band);
+	lbs_deb_enter(LBS_DEB_11D);
+	lbs_deb_11d("11D:curbssparams.band[%d]\n", adapter->curbssparams.band);
 
 	if (priv->adapter->enable11d) {
 		/* update parsed_region_chan_11; dnld domaininf to FW */
@@ -709,7 +712,7 @@
 		     sizeof(adapter->region_channel[0]); j++) {
 			region_chan = &adapter->region_channel[j];
 
-			lbs_pr_debug(1, "11D:[%d] region_chan->band[%d]\n", j,
+			lbs_deb_11d("11D:[%d] region_chan->band[%d]\n", j,
 			       region_chan->band);
 
 			if (!region_chan || !region_chan->valid
@@ -722,10 +725,10 @@
 
 		if (j >= sizeof(adapter->region_channel) /
 		    sizeof(adapter->region_channel[0])) {
-			lbs_pr_debug(1, "11D:region_chan not found. band[%d]\n",
+			lbs_deb_11d("11D:region_chan not found. band[%d]\n",
 			       adapter->curbssparams.band);
-			LEAVE();
-			return -1;
+			ret = -1;
+			goto done;
 		}
 
 		memset(&adapter->parsed_region_chan, 0,
@@ -742,13 +745,14 @@
 		ret = set_domain_info_11d(priv);
 
 		if (ret) {
-			lbs_pr_debug(1, "11D: Err set domainInfo to FW\n");
-			LEAVE();
-			return ret;
+			lbs_deb_11d("11D: Err set domainInfo to FW\n");
+			goto done;
 		}
 
 	}
+	ret = 0;
 
-	LEAVE();
-	return 0;
+done:
+	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
+	return ret;
 }
diff --git a/drivers/net/wireless/libertas/11d.h b/drivers/net/wireless/libertas/11d.h
index db2ebea..73e42e7 100644
--- a/drivers/net/wireless/libertas/11d.h
+++ b/drivers/net/wireless/libertas/11d.h
@@ -47,7 +47,7 @@
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11d_domain_info {
-	u16 action;
+	__le16 action;
 	struct mrvlietypes_domainparamset domain;
 } __attribute__ ((packed));
 
@@ -98,7 +98,9 @@
 int libertas_ret_802_11d_domain_info(wlan_private * priv,
 				 struct cmd_ds_command *resp);
 
-int libertas_parse_dnld_countryinfo_11d(wlan_private * priv);
+struct bss_descriptor;
+int libertas_parse_dnld_countryinfo_11d(wlan_private * priv,
+                                        struct bss_descriptor * bss);
 
 int libertas_create_dnld_countryinfo_11d(wlan_private * priv);
 
diff --git a/drivers/net/wireless/libertas/Makefile b/drivers/net/wireless/libertas/Makefile
index 56a8ea1..a1097f5 100644
--- a/drivers/net/wireless/libertas/Makefile
+++ b/drivers/net/wireless/libertas/Makefile
@@ -1,4 +1,4 @@
-usb8xxx-objs := main.o fw.o wext.o \
+libertas-objs := main.o fw.o wext.o \
 		rx.o tx.o cmd.o 	  \
 		cmdresp.o scan.o	  \
 		join.o 11d.o 		  \
@@ -8,5 +8,5 @@
 usb8xxx-objs += if_bootcmd.o
 usb8xxx-objs += if_usb.o
 
+obj-$(CONFIG_LIBERTAS)     += libertas.o
 obj-$(CONFIG_LIBERTAS_USB) += usb8xxx.o
-
diff --git a/drivers/net/wireless/libertas/README b/drivers/net/wireless/libertas/README
index 3785772..1f92f50 100644
--- a/drivers/net/wireless/libertas/README
+++ b/drivers/net/wireless/libertas/README
@@ -1,7 +1,7 @@
 ================================================================================
 			README for USB8388
 
- (c) Copyright © 2003-2006, Marvell International Ltd.
+ (c) Copyright © 2003-2006, Marvell International Ltd.
  All Rights Reserved
 
  This software file (the "File") is distributed by Marvell International
@@ -47,15 +47,19 @@
 	iwpriv ethX ledgpio <n>
 
 BT Commands:
-	The blinding table (BT) contains a list of mac addresses that should be
-	ignored by the firmware.  It is primarily used for debugging and
-	testing networks.  It can be edited and inspected with the following
-	commands:
+	The blinding table (BT) contains a list of mac addresses that will be,
+	by default, ignored by the firmware. It is also possible to invert this
+	behavior so that we will ignore all traffic except for the portion
+	coming from mac addresess in the list. It is primarily used for
+	debugging and testing networks.  It can be edited and inspected with
+	the following commands:
 
 	iwpriv ethX bt_reset
 	iwpriv ethX bt_add <mac_address>
 	iwpriv ethX bt_del <mac_address>
 	iwpriv ethX bt_list <id>
+	iwpriv ethX bt_get_invert <n>
+	iwpriv ethX bt_set_invert <n>
 
 FWT Commands:
 	The forwarding table (FWT) is a feature used to manage mesh network
@@ -135,7 +139,7 @@
 	This command is used to insert an entry into the FWT table. The list of
 	parameters must follow the following structure:
 
-	iwpriv ethX fwt_add da ra [metric dir ssn dsn hopcount ttl expiration sleepmode snr]
+	iwpriv ethX fwt_add da ra [metric dir rate ssn dsn hopcount ttl expiration sleepmode snr]
 
 	The parameters between brackets are optional, but they must appear in
 	the order specified.  For example, if you want to specify the metric,
@@ -150,6 +154,9 @@
 				   preferred, default is 0)
 		dir		-- direction (1 for direct, 0 for reverse,
 				   default is 1)
+		rate		-- data rate used for transmission to the RA,
+				   as specified for the rateadapt command,
+				   default is 3 (11Mbps)
 		ssn		-- Source Sequence Number (time at the RA for
 				   reverse routes.  Default is 0)
 		dsn		-- Destination Sequence Number (time at the DA
@@ -207,13 +214,17 @@
 
 	The output is a string of the following form:
 
-		da ra metric dir ssn dsn hopcount ttl expiration sleepmode snr
+		da ra valid metric dir rate ssn dsn hopcount ttl expiration
+		sleepmode snr precursor
 
 	where the different fields are:-
 		da		-- DA MAC address (in the form "00:11:22:33:44:55")
 		ra		-- RA MAC address (in the form "00:11:22:33:44:55")
+		valid		-- whether the route is valid (0 if not valid)
 		metric		-- route metric (cost: smaller-metric routes are preferred)
 		dir		-- direction (1 for direct, 0 for reverse)
+		rate		-- data rate used for transmission to the RA,
+				   as specified for the rateadapt command
 		ssn		-- Source Sequence Number (time at the RA for reverse routes)
 		dsn		-- Destination Sequence Number (time at the DA for direct routes)
 		hopcount	-- hop count (currently unused)
@@ -221,33 +232,10 @@
 		expiration	-- entry expiration (in ticks, where a tick is 1024us, or ~ 1ms. Use 0 for an indefinite entry)
 		sleepmode	-- RA's sleep mode (currently unused)
 		snr		-- SNR in the link to RA (currently unused)
+		precursor	-- predecessor in direct routes
 
 fwt_list_route
-	This command is used to list a route from the FWT table. The only
-	parameter is the route ID. If you want to list all the routes in a
-	table, start with rid=0, and keep incrementing rid until you get a
-	"(null)" string. This function is similar to fwt_list. The only
-	difference is the output format.  Also note that this command is meant
-	for debugging.  It is expected that users will use fwt_lookup and
-	fwt_list.  One important reason for this is that the route id may change
-	as the route table is altered.
-
-		iwpriv ethX fwt_list_route rid
-
-	The output is a string of the following form:
-
-		da metric dir nid ssn dsn hopcount ttl expiration
-
-	where the different fields are:-
-		da		-- DA MAC address (in the form "00:11:22:33:44:55")
-		metric		-- route metric (cost: smaller-metric routes are preferred)
-		dir		-- direction (1 for direct, 0 for reverse)
-		nid		-- Next-hop (neighbor) host ID (nid)
-		ssn		-- Source Sequence Number (time at the RA for reverse routes)
-		dsn		-- Destination Sequence Number (time at the DA for direct routes)
-		hopcount	-- hop count (currently unused)
-		ttl		-- TTL count (only used in reverse entries)
-		expiration	-- entry expiration (in ticks, where a tick is 1024us, or ~ 1ms. Use 0 for an indefinite entry)
+	This command is equivalent to fwt_list.
 
 fwt_list_neigh
 	This command is used to list a neighbor from the FWT table. The only
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
index c260bd1..f67efa0 100644
--- a/drivers/net/wireless/libertas/assoc.c
+++ b/drivers/net/wireless/libertas/assoc.c
@@ -2,6 +2,7 @@
 
 #include <linux/bitops.h>
 #include <net/ieee80211.h>
+#include <linux/etherdevice.h>
 
 #include "assoc.h"
 #include "join.h"
@@ -13,59 +14,88 @@
 static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
+static void print_assoc_req(const char * extra, struct assoc_request * assoc_req)
+{
+	lbs_deb_assoc(
+	       "#### Association Request: %s\n"
+	       "       flags:      0x%08lX\n"
+	       "       SSID:       '%s'\n"
+	       "       channel:    %d\n"
+	       "       band:       %d\n"
+	       "       mode:       %d\n"
+	       "       BSSID:      " MAC_FMT "\n"
+	       "       Encryption:%s%s%s\n"
+	       "       auth:       %d\n",
+	       extra, assoc_req->flags,
+	       escape_essid(assoc_req->ssid, assoc_req->ssid_len),
+	       assoc_req->channel, assoc_req->band, assoc_req->mode,
+	       MAC_ARG(assoc_req->bssid),
+	       assoc_req->secinfo.WPAenabled ? " WPA" : "",
+	       assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
+	       assoc_req->secinfo.wep_enabled ? " WEP" : "",
+	       assoc_req->secinfo.auth_mode);
+}
+
+
 static int assoc_helper_essid(wlan_private *priv,
                               struct assoc_request * assoc_req)
 {
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
-	int i;
+	struct bss_descriptor * bss;
+	int channel = -1;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
-	lbs_pr_debug(1, "New SSID requested: %s\n", assoc_req->ssid.ssid);
+	/* FIXME: take channel into account when picking SSIDs if a channel
+	 * is set.
+	 */
+
+	if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
+		channel = assoc_req->channel;
+
+	lbs_deb_assoc("New SSID requested: '%s'\n",
+	              escape_essid(assoc_req->ssid, assoc_req->ssid_len));
 	if (assoc_req->mode == IW_MODE_INFRA) {
 		if (adapter->prescan) {
-			libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1);
+			libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
+				assoc_req->ssid_len, 0);
 		}
 
-		i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
-				NULL, IW_MODE_INFRA);
-		if (i >= 0) {
-			lbs_pr_debug(1,
-			       "SSID found in scan list ... associating...\n");
-
-			ret = wlan_associate(priv, &adapter->scantable[i]);
-			if (ret == 0) {
-				memcpy(&assoc_req->bssid,
-				       &adapter->scantable[i].macaddress,
-				       ETH_ALEN);
-			}
+		bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
+				assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
+		if (bss != NULL) {
+			lbs_deb_assoc("SSID found in scan list, associating\n");
+			memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
+			ret = wlan_associate(priv, assoc_req);
 		} else {
-			lbs_pr_debug(1, "SSID '%s' not found; cannot associate\n",
-				assoc_req->ssid.ssid);
+			lbs_deb_assoc("SSID not found; cannot associate\n");
 		}
 	} else if (assoc_req->mode == IW_MODE_ADHOC) {
 		/* Scan for the network, do not save previous results.  Stale
 		 *   scan data will cause us to join a non-existant adhoc network
 		 */
-		libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0);
+		libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
+			assoc_req->ssid_len, 1);
 
 		/* Search for the requested SSID in the scan table */
-		i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
-				IW_MODE_ADHOC);
-		if (i >= 0) {
-			lbs_pr_debug(1, "SSID found at %d in List, so join\n", ret);
-			libertas_join_adhoc_network(priv, &adapter->scantable[i]);
+		bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
+				assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
+		if (bss != NULL) {
+			lbs_deb_assoc("SSID found, will join\n");
+			memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
+			libertas_join_adhoc_network(priv, assoc_req);
 		} else {
 			/* else send START command */
-			lbs_pr_debug(1, "SSID not found in list, so creating adhoc"
-				" with SSID '%s'\n", assoc_req->ssid.ssid);
-			libertas_start_adhoc_network(priv, &assoc_req->ssid);
+			lbs_deb_assoc("SSID not found, creating adhoc network\n");
+			memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
+				IW_ESSID_MAX_SIZE);
+			assoc_req->bss.ssid_len = assoc_req->ssid_len;
+			libertas_start_adhoc_network(priv, assoc_req);
 		}
-		memcpy(&assoc_req->bssid, &adapter->current_addr, ETH_ALEN);
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
 	return ret;
 }
 
@@ -74,33 +104,31 @@
                               struct assoc_request * assoc_req)
 {
 	wlan_adapter *adapter = priv->adapter;
-	int i, ret = 0;
+	int ret = 0;
+	struct bss_descriptor * bss;
 
-	ENTER();
-
-	lbs_pr_debug(1, "ASSOC: WAP: BSSID = " MAC_FMT "\n",
+	lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID " MAC_FMT,
 		MAC_ARG(assoc_req->bssid));
 
 	/* Search for index position in list for requested MAC */
-	i = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
+	bss = libertas_find_bssid_in_list(adapter, assoc_req->bssid,
 			    assoc_req->mode);
-	if (i < 0) {
-		lbs_pr_debug(1, "ASSOC: WAP: BSSID " MAC_FMT " not found, "
+	if (bss == NULL) {
+		lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, "
 			"cannot associate.\n", MAC_ARG(assoc_req->bssid));
 		goto out;
 	}
 
+	memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
 	if (assoc_req->mode == IW_MODE_INFRA) {
-		ret = wlan_associate(priv, &adapter->scantable[i]);
-		lbs_pr_debug(1, "ASSOC: return from wlan_associate(bssd) was %d\n", ret);
+		ret = wlan_associate(priv, assoc_req);
+		lbs_deb_assoc("ASSOC: wlan_associate(bssid) returned %d\n", ret);
 	} else if (assoc_req->mode == IW_MODE_ADHOC) {
-		libertas_join_adhoc_network(priv, &adapter->scantable[i]);
+		libertas_join_adhoc_network(priv, assoc_req);
 	}
-	memcpy(&assoc_req->ssid, &adapter->scantable[i].ssid,
-		sizeof(struct WLAN_802_11_SSID));
 
 out:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
 	return ret;
 }
 
@@ -113,12 +141,12 @@
 	/* If we're given and 'any' BSSID, try associating based on SSID */
 
 	if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-		if (memcmp(bssid_any, assoc_req->bssid, ETH_ALEN)
-		    && memcmp(bssid_off, assoc_req->bssid, ETH_ALEN)) {
+		if (compare_ether_addr(bssid_any, assoc_req->bssid)
+		    && compare_ether_addr(bssid_off, assoc_req->bssid)) {
 			ret = assoc_helper_bssid(priv, assoc_req);
 			done = 1;
 			if (ret) {
-				lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+				lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
 			}
 		}
 	}
@@ -126,7 +154,7 @@
 	if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
 		ret = assoc_helper_essid(priv, assoc_req);
 		if (ret) {
-			lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+			lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
 		}
 	}
 
@@ -140,12 +168,10 @@
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
-	if (assoc_req->mode == adapter->mode) {
-		LEAVE();
-		return 0;
-	}
+	if (assoc_req->mode == adapter->mode)
+		goto done;
 
 	if (assoc_req->mode == IW_MODE_INFRA) {
 		if (adapter->psstate != PS_STATE_FULL_POWER)
@@ -158,9 +184,81 @@
 				    cmd_802_11_snmp_mib,
 				    0, cmd_option_waitforrsp,
 				    OID_802_11_INFRASTRUCTURE_MODE,
-				    (void *) (size_t) assoc_req->mode);
+		/* Shoot me now */  (void *) (size_t) assoc_req->mode);
 
-	LEAVE();
+done:
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
+	return ret;
+}
+
+
+static int update_channel(wlan_private * priv)
+{
+	/* the channel in f/w could be out of sync, get the current channel */
+	return libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
+				    cmd_opt_802_11_rf_channel_get,
+				    cmd_option_waitforrsp, 0, NULL);
+}
+
+void libertas_sync_channel(struct work_struct *work)
+{
+	wlan_private *priv = container_of(work, wlan_private, sync_channel);
+
+	if (update_channel(priv) != 0)
+		lbs_pr_info("Channel synchronization failed.");
+}
+
+static int assoc_helper_channel(wlan_private *priv,
+                                struct assoc_request * assoc_req)
+{
+	wlan_adapter *adapter = priv->adapter;
+	int ret = 0;
+
+	lbs_deb_enter(LBS_DEB_ASSOC);
+
+	ret = update_channel(priv);
+	if (ret < 0) {
+		lbs_deb_assoc("ASSOC: channel: error getting channel.");
+	}
+
+	if (assoc_req->channel == adapter->curbssparams.channel)
+		goto done;
+
+	lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
+	       adapter->curbssparams.channel, assoc_req->channel);
+
+	ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
+				cmd_opt_802_11_rf_channel_set,
+				cmd_option_waitforrsp, 0, &assoc_req->channel);
+	if (ret < 0) {
+		lbs_deb_assoc("ASSOC: channel: error setting channel.");
+	}
+
+	ret = update_channel(priv);
+	if (ret < 0) {
+		lbs_deb_assoc("ASSOC: channel: error getting channel.");
+	}
+
+	if (assoc_req->channel != adapter->curbssparams.channel) {
+		lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
+		              assoc_req->channel);
+		goto done;
+	}
+
+	if (   assoc_req->secinfo.wep_enabled
+	    &&   (assoc_req->wep_keys[0].len
+	       || assoc_req->wep_keys[1].len
+	       || assoc_req->wep_keys[2].len
+	       || assoc_req->wep_keys[3].len)) {
+		/* Make sure WEP keys are re-sent to firmware */
+		set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
+	}
+
+	/* Must restart/rejoin adhoc networks after channel change */
+	set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
+
+done:
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
 	return ret;
 }
 
@@ -172,7 +270,7 @@
 	int i;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	/* Set or remove WEP keys */
 	if (   assoc_req->wep_keys[0].len
@@ -216,7 +314,7 @@
 	mutex_unlock(&adapter->lock);
 
 out:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
 	return ret;
 }
 
@@ -226,14 +324,24 @@
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	memcpy(&adapter->secinfo, &assoc_req->secinfo,
 		sizeof(struct wlan_802_11_security));
 
 	ret = libertas_set_mac_packet_filter(priv);
+	if (ret)
+		goto out;
 
-	LEAVE();
+	/* enable/disable RSN */
+	ret = libertas_prepare_and_send_command(priv,
+				    cmd_802_11_enable_rsn,
+				    cmd_act_set,
+				    cmd_option_waitforrsp,
+				    0, assoc_req);
+
+out:
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
 	return ret;
 }
 
@@ -243,16 +351,7 @@
 {
 	int ret = 0;
 
-	ENTER();
-
-	/* enable/Disable RSN */
-	ret = libertas_prepare_and_send_command(priv,
-				    cmd_802_11_enable_rsn,
-				    cmd_act_set,
-				    cmd_option_waitforrsp,
-				    0, assoc_req);
-	if (ret)
-		goto out;
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	ret = libertas_prepare_and_send_command(priv,
 				    cmd_802_11_key_material,
@@ -260,8 +359,7 @@
 				    cmd_option_waitforrsp,
 				    0, assoc_req);
 
-out:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
 	return ret;
 }
 
@@ -272,7 +370,7 @@
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
 		memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
@@ -282,7 +380,7 @@
 		adapter->wpa_ie_len = 0;
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
 	return ret;
 }
 
@@ -294,25 +392,30 @@
 		return 0;
 
 	if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
-		lbs_pr_debug(1, "Deauthenticating due to new SSID in "
+		lbs_deb_assoc("Deauthenticating due to new SSID in "
 			" configuration request.\n");
 		return 1;
 	}
 
 	if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
 		if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
-			lbs_pr_debug(1, "Deauthenticating due to updated security "
+			lbs_deb_assoc("Deauthenticating due to updated security "
 				"info in configuration request.\n");
 			return 1;
 		}
 	}
 
 	if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-		lbs_pr_debug(1, "Deauthenticating due to new BSSID in "
+		lbs_deb_assoc("Deauthenticating due to new BSSID in "
 			" configuration request.\n");
 		return 1;
 	}
 
+	if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+		lbs_deb_assoc("Deauthenticating due to channel switch.\n");
+		return 1;
+	}
+
 	/* FIXME: deal with 'auto' mode somehow */
 	if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
 		if (assoc_req->mode != IW_MODE_INFRA)
@@ -329,10 +432,9 @@
 	if (adapter->connect_status != libertas_connected)
 		return 0;
 
-	if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength)
-		return 1;
-	if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid,
-			adapter->curbssparams.ssid.ssidlength))
+	if (libertas_ssid_cmp(adapter->curbssparams.ssid,
+	                      adapter->curbssparams.ssid_len,
+	                      assoc_req->ssid, assoc_req->ssid_len) != 0)
 		return 1;
 
 	/* FIXME: deal with 'auto' mode somehow */
@@ -341,11 +443,16 @@
 			return 1;
 	}
 
+	if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+		if (assoc_req->channel != adapter->curbssparams.channel)
+			return 1;
+	}
+
 	return 0;
 }
 
 
-void wlan_association_worker(struct work_struct *work)
+void libertas_association_worker(struct work_struct *work)
 {
 	wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
 	wlan_adapter *adapter = priv->adapter;
@@ -353,40 +460,38 @@
 	int ret = 0;
 	int find_any_ssid = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	mutex_lock(&adapter->lock);
-	assoc_req = adapter->assoc_req;
-	adapter->assoc_req = NULL;
+	assoc_req = adapter->pending_assoc_req;
+	adapter->pending_assoc_req = NULL;
+	adapter->in_progress_assoc_req = assoc_req;
 	mutex_unlock(&adapter->lock);
 
-	if (!assoc_req) {
-		LEAVE();
-		return;
-	}
+	if (!assoc_req)
+		goto done;
 
-	lbs_pr_debug(1, "ASSOC: starting new association request: flags = 0x%lX\n",
-		assoc_req->flags);
+	print_assoc_req(__func__, assoc_req);
 
 	/* If 'any' SSID was specified, find an SSID to associate with */
 	if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
-	    && !assoc_req->ssid.ssidlength)
+	    && !assoc_req->ssid_len)
 		find_any_ssid = 1;
 
 	/* But don't use 'any' SSID if there's a valid locked BSSID to use */
 	if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-		if (memcmp(&assoc_req->bssid, bssid_any, ETH_ALEN)
-		    && memcmp(&assoc_req->bssid, bssid_off, ETH_ALEN))
+		if (compare_ether_addr(assoc_req->bssid, bssid_any)
+		    && compare_ether_addr(assoc_req->bssid, bssid_off))
 			find_any_ssid = 0;
 	}
 
 	if (find_any_ssid) {
 		u8 new_mode;
 
-		ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid,
-				assoc_req->mode, &new_mode);
+		ret = libertas_find_best_network_ssid(priv, assoc_req->ssid,
+				&assoc_req->ssid_len, assoc_req->mode, &new_mode);
 		if (ret) {
-			lbs_pr_debug(1, "Could not find best network\n");
+			lbs_deb_assoc("Could not find best network\n");
 			ret = -ENETUNREACH;
 			goto out;
 		}
@@ -406,7 +511,7 @@
 		if (should_deauth_infrastructure(adapter, assoc_req)) {
 			ret = libertas_send_deauthentication(priv);
 			if (ret) {
-				lbs_pr_debug(1, "Deauthentication due to new "
+				lbs_deb_assoc("Deauthentication due to new "
 					"configuration request failed: %d\n",
 					ret);
 			}
@@ -415,7 +520,7 @@
 		if (should_stop_adhoc(adapter, assoc_req)) {
 			ret = libertas_stop_adhoc_network(priv);
 			if (ret) {
-				lbs_pr_debug(1, "Teardown of AdHoc network due to "
+				lbs_deb_assoc("Teardown of AdHoc network due to "
 					"new configuration request failed: %d\n",
 					ret);
 			}
@@ -427,7 +532,16 @@
 	if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
 		ret = assoc_helper_mode(priv, assoc_req);
 		if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
+			goto out;
+		}
+	}
+
+	if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+		ret = assoc_helper_channel(priv, assoc_req);
+		if (ret) {
+			lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n",
+			              __LINE__, ret);
 			goto out;
 		}
 	}
@@ -436,7 +550,7 @@
 	    || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
 		ret = assoc_helper_wep_keys(priv, assoc_req);
 		if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
 			goto out;
 		}
 	}
@@ -444,7 +558,7 @@
 	if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
 		ret = assoc_helper_secinfo(priv, assoc_req);
 		if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
 			goto out;
 		}
 	}
@@ -452,7 +566,7 @@
 	if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
 		ret = assoc_helper_wpa_ie(priv, assoc_req);
 		if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
 			goto out;
 		}
 	}
@@ -461,7 +575,7 @@
 	    || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
 		ret = assoc_helper_wpa_keys(priv, assoc_req);
 		if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
 			goto out;
 		}
 	}
@@ -475,21 +589,23 @@
 
 		ret = assoc_helper_associate(priv, assoc_req);
 		if (ret) {
-			lbs_pr_debug(1, "ASSOC: association attempt unsuccessful: %d\n",
+			lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
 				ret);
 			success = 0;
 		}
 
 		if (adapter->connect_status != libertas_connected) {
-			lbs_pr_debug(1, "ASSOC: assoication attempt unsuccessful, "
+			lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, "
 				"not connected.\n");
 			success = 0;
 		}
 
 		if (success) {
-			lbs_pr_debug(1, "ASSOC: association attempt successful. "
+			lbs_deb_assoc("ASSOC: association attempt successful. "
 				"Associated to '%s' (" MAC_FMT ")\n",
-				assoc_req->ssid.ssid, MAC_ARG(assoc_req->bssid));
+				escape_essid(adapter->curbssparams.ssid,
+				             adapter->curbssparams.ssid_len),
+				MAC_ARG(adapter->curbssparams.bssid));
 			libertas_prepare_and_send_command(priv,
 				cmd_802_11_rssi,
 				0, cmd_option_waitforrsp, 0, NULL);
@@ -498,18 +614,23 @@
 				cmd_802_11_get_log,
 				0, cmd_option_waitforrsp, 0, NULL);
 		} else {
-
 			ret = -1;
 		}
 	}
 
 out:
 	if (ret) {
-		lbs_pr_debug(1, "ASSOC: reconfiguration attempt unsuccessful: %d\n",
+		lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
 			ret);
 	}
+
+	mutex_lock(&adapter->lock);
+	adapter->in_progress_assoc_req = NULL;
+	mutex_unlock(&adapter->lock);
 	kfree(assoc_req);
-	LEAVE();
+
+done:
+	lbs_deb_leave(LBS_DEB_ASSOC);
 }
 
 
@@ -520,9 +641,10 @@
 {
 	struct assoc_request * assoc_req;
 
-	if (!adapter->assoc_req) {
-		adapter->assoc_req = kzalloc(sizeof(struct assoc_request), GFP_KERNEL);
-		if (!adapter->assoc_req) {
+	if (!adapter->pending_assoc_req) {
+		adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
+		                                     GFP_KERNEL);
+		if (!adapter->pending_assoc_req) {
 			lbs_pr_info("Not enough memory to allocate association"
 				" request!\n");
 			return NULL;
@@ -532,15 +654,19 @@
 	/* Copy current configuration attributes to the association request,
 	 * but don't overwrite any that are already set.
 	 */
-	assoc_req = adapter->assoc_req;
+	assoc_req = adapter->pending_assoc_req;
 	if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
-		memcpy(&assoc_req->ssid, adapter->curbssparams.ssid.ssid,
-			adapter->curbssparams.ssid.ssidlength);
+		memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
+		       IW_ESSID_MAX_SIZE);
+		assoc_req->ssid_len = adapter->curbssparams.ssid_len;
 	}
 
 	if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
 		assoc_req->channel = adapter->curbssparams.channel;
 
+	if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
+		assoc_req->band = adapter->curbssparams.band;
+
 	if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
 		assoc_req->mode = adapter->mode;
 
@@ -581,7 +707,7 @@
 		assoc_req->wpa_ie_len = adapter->wpa_ie_len;
 	}
 
+	print_assoc_req(__func__, assoc_req);
+
 	return assoc_req;
 }
-
-
diff --git a/drivers/net/wireless/libertas/assoc.h b/drivers/net/wireless/libertas/assoc.h
index 2ffd82d..5e9c31f 100644
--- a/drivers/net/wireless/libertas/assoc.h
+++ b/drivers/net/wireless/libertas/assoc.h
@@ -5,10 +5,12 @@
 
 #include "dev.h"
 
-void wlan_association_worker(struct work_struct *work);
+void libertas_association_worker(struct work_struct *work);
 
 struct assoc_request * wlan_get_association_request(wlan_adapter *adapter);
 
+void libertas_sync_channel(struct work_struct *work);
+
 #define ASSOC_DELAY (HZ / 2)
 static inline void wlan_postpone_association_work(wlan_private *priv)
 {
@@ -21,9 +23,9 @@
 static inline void wlan_cancel_association_work(wlan_private *priv)
 {
 	cancel_delayed_work(&priv->assoc_work);
-	if (priv->adapter->assoc_req) {
-		kfree(priv->adapter->assoc_req);
-		priv->adapter->assoc_req = NULL;
+	if (priv->adapter->pending_assoc_req) {
+		kfree(priv->adapter->pending_assoc_req);
+		priv->adapter->pending_assoc_req = NULL;
 	}
 }
 
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index de9cb46..124e029 100644
--- a/drivers/net/wireless/libertas/cmd.c
+++ b/drivers/net/wireless/libertas/cmd.c
@@ -6,7 +6,6 @@
 #include <net/iw_handler.h>
 #include "host.h"
 #include "hostcmd.h"
-#include "sbi.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
@@ -26,13 +25,11 @@
  *  @param command the command ID
  *  @return 	   TRUE or FALSE
  */
-static u8 is_command_allowed_in_ps(u16 command)
+static u8 is_command_allowed_in_ps(__le16 command)
 {
-	int count = sizeof(commands_allowed_in_ps)
-	    / sizeof(commands_allowed_in_ps[0]);
 	int i;
 
-	for (i = 0; i < count; i++) {
+	for (i = 0; i < ARRAY_SIZE(commands_allowed_in_ps); i++) {
 		if (command == cpu_to_le16(commands_allowed_in_ps[i]))
 			return 1;
 	}
@@ -44,14 +41,13 @@
 {
 	struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->command = cpu_to_le16(cmd_get_hw_spec);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
 	memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -60,21 +56,19 @@
 				   u16 cmd_action)
 {
 	struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
-	u16 action = cmd_action;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->command = cpu_to_le16(cmd_802_11_ps_mode);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
-			     S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
+				S_DS_GEN);
 	psm->action = cpu_to_le16(cmd_action);
 	psm->multipledtim = 0;
-	switch (action) {
+	switch (cmd_action) {
 	case cmd_subcmd_enter_ps:
-		lbs_pr_debug(1, "PS command:" "SubCode- Enter PS\n");
-		lbs_pr_debug(1, "locallisteninterval = %d\n",
+		lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
+		lbs_deb_cmd("locallisteninterval = %d\n",
 		       adapter->locallisteninterval);
 
 		psm->locallisteninterval =
@@ -86,18 +80,18 @@
 		break;
 
 	case cmd_subcmd_exit_ps:
-		lbs_pr_debug(1, "PS command:" "SubCode- Exit PS\n");
+		lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
 		break;
 
 	case cmd_subcmd_sleep_confirmed:
-		lbs_pr_debug(1, "PS command: SubCode- sleep confirm\n");
+		lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
 		break;
 
 	default:
 		break;
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -115,8 +109,7 @@
 	cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
 
 	if (cmd_action)
-		cmd->params.inactivity_timeout.timeout =
-		    cpu_to_le16(*timeout);
+		cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
 	else
 		cmd->params.inactivity_timeout.timeout = 0;
 
@@ -130,11 +123,10 @@
 	wlan_adapter *adapter = priv->adapter;
 	struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	cmd->size =
-	    cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
-			     S_DS_GEN);
+	cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
+				S_DS_GEN);
 	cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
 
 	if (cmd_action == cmd_act_get) {
@@ -151,7 +143,7 @@
 		sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -165,17 +157,16 @@
 	int ret = 0;
 	struct assoc_request * assoc_req = pdata_buf;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->command = cpu_to_le16(cmd_802_11_set_wep);
-	cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_set_wep))
-	                             + S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
 
 	if (cmd_act == cmd_act_add) {
 		int i;
 
 		if (!assoc_req) {
-			lbs_pr_debug(1, "Invalid association request!");
+			lbs_deb_cmd("Invalid association request!");
 			ret = -1;
 			goto done;
 		}
@@ -183,11 +174,10 @@
 		wep->action = cpu_to_le16(cmd_act_add);
 
 		/* default tx key index */
-		wep->keyindex = cpu_to_le16((u16)
-				                 (assoc_req->wep_tx_keyidx &
-				                 (u32)cmd_WEP_KEY_INDEX_MASK));
+		wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
+						  (u32)cmd_WEP_KEY_INDEX_MASK));
 
-		lbs_pr_debug(1, "Tx key Index: %u\n", wep->keyindex);
+		lbs_deb_cmd("Tx key Index: %u\n", le16_to_cpu(wep->keyindex));
 
 		/* Copy key types and material to host command structure */
 		for (i = 0; i < 4; i++) {
@@ -195,19 +185,21 @@
 
 			switch (pkey->len) {
 			case KEY_LEN_WEP_40:
-				wep->keytype[i] = cmd_type_wep_40_bit;
+				wep->keytype[i] =
+					cpu_to_le16(cmd_type_wep_40_bit);
 				memmove(&wep->keymaterial[i], pkey->key,
 				        pkey->len);
 				break;
 			case KEY_LEN_WEP_104:
-				wep->keytype[i] = cmd_type_wep_104_bit;
+				wep->keytype[i] =
+					cpu_to_le16(cmd_type_wep_104_bit);
 				memmove(&wep->keymaterial[i], pkey->key,
 				        pkey->len);
 				break;
 			case 0:
 				break;
 			default:
-				lbs_pr_debug(1, "Invalid WEP key %d length of %d\n",
+				lbs_deb_cmd("Invalid WEP key %d length of %d\n",
 				       i, pkey->len);
 				ret = -1;
 				goto done;
@@ -219,36 +211,37 @@
 		wep->action = cpu_to_le16(cmd_act_remove);
 
 		/* default tx key index */
-		wep->keyindex = cpu_to_le16((u16)
-				                 (adapter->wep_tx_keyidx &
-				                 (u32)cmd_WEP_KEY_INDEX_MASK));
+		wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx &
+						  (u32)cmd_WEP_KEY_INDEX_MASK));
 	}
 
 	ret = 0;
 
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
 static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
 				      struct cmd_ds_command *cmd,
-				      u16 cmd_action)
+				      u16 cmd_action,
+				      void * pdata_buf)
 {
 	struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
-	wlan_adapter *adapter = priv->adapter;
+	struct assoc_request * assoc_req = pdata_buf;
+
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_enable_rsn) +
-			     S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
 	penableRSN->action = cpu_to_le16(cmd_action);
-	if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
+	if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
 		penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
 	} else {
 		penableRSN->enable = cpu_to_le16(cmd_disable_rsn);
 	}
 
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -259,14 +252,12 @@
 	pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
 
 	if (pkey->flags & KEY_INFO_WPA_ENABLED) {
-		pkeyparamset->keyinfo = cpu_to_le16(KEY_INFO_WPA_ENABLED);
-	} else {
-		pkeyparamset->keyinfo = cpu_to_le16(!KEY_INFO_WPA_ENABLED);
+		pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
 	}
-
 	if (pkey->flags & KEY_INFO_WPA_UNICAST) {
 		pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
-	} else if (pkey->flags & KEY_INFO_WPA_MCAST) {
+	}
+	if (pkey->flags & KEY_INFO_WPA_MCAST) {
 		pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
 	}
 
@@ -284,46 +275,45 @@
 					u16 cmd_action,
 					u32 cmd_oid, void *pdata_buf)
 {
-	wlan_adapter *adapter = priv->adapter;
 	struct cmd_ds_802_11_key_material *pkeymaterial =
 	    &cmd->params.keymaterial;
+	struct assoc_request * assoc_req = pdata_buf;
 	int ret = 0;
 	int index = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->command = cpu_to_le16(cmd_802_11_key_material);
 	pkeymaterial->action = cpu_to_le16(cmd_action);
 
 	if (cmd_action == cmd_act_get) {
-		cmd->size = cpu_to_le16(  S_DS_GEN
-		                             + sizeof (pkeymaterial->action));
+		cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
 		ret = 0;
 		goto done;
 	}
 
 	memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
 
-	if (adapter->wpa_unicast_key.len) {
+	if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
 		set_one_wpa_key(&pkeymaterial->keyParamSet[index],
-		                &adapter->wpa_unicast_key);
+		                &assoc_req->wpa_unicast_key);
 		index++;
 	}
 
-	if (adapter->wpa_mcast_key.len) {
+	if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
 		set_one_wpa_key(&pkeymaterial->keyParamSet[index],
-		                &adapter->wpa_mcast_key);
+		                &assoc_req->wpa_mcast_key);
 		index++;
 	}
 
 	cmd->size = cpu_to_le16(  S_DS_GEN
-	                             + sizeof (pkeymaterial->action)
-	                             + index * sizeof(struct MrvlIEtype_keyParamSet));
+	                        + sizeof (pkeymaterial->action)
+	                        + (index * sizeof(struct MrvlIEtype_keyParamSet)));
 
 	ret = 0;
 
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
@@ -354,8 +344,7 @@
 {
 	cmd->command = cpu_to_le16(cmd_802_11_get_stat);
 	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) +
-			     S_DS_GEN);
+	    cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
 
 	return 0;
 }
@@ -369,14 +358,12 @@
 	wlan_adapter *adapter = priv->adapter;
 	u8 ucTemp;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	lbs_pr_debug(1, "SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
+	lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
 
 	cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_snmp_mib) +
-			     S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
 
 	switch (cmd_oid) {
 	case OID_802_11_INFRASTRUCTURE_MODE:
@@ -407,7 +394,7 @@
 				pSNMPMIB->querytype = cmd_act_set;
 				pSNMPMIB->bufsize = sizeof(u16);
 				ulTemp = *(u32 *)pdata_buf;
-				*((unsigned short *)(pSNMPMIB->value)) =
+				*((__le16 *)(pSNMPMIB->value)) =
 				    cpu_to_le16((u16) ulTemp);
 			}
 			break;
@@ -420,15 +407,12 @@
 			pSNMPMIB->oid = cpu_to_le16((u16) fragthresh_i);
 
 			if (cmd_action == cmd_act_get) {
-				pSNMPMIB->querytype =
-				    cpu_to_le16(cmd_act_get);
+				pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
 			} else if (cmd_action == cmd_act_set) {
-				pSNMPMIB->querytype =
-				    cpu_to_le16(cmd_act_set);
-				pSNMPMIB->bufsize =
-				    cpu_to_le16(sizeof(u16));
+				pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
+				pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
 				ulTemp = *((u32 *) pdata_buf);
-				*((unsigned short *)(pSNMPMIB->value)) =
+				*((__le16 *)(pSNMPMIB->value)) =
 				    cpu_to_le16((u16) ulTemp);
 
 			}
@@ -443,16 +427,12 @@
 			pSNMPMIB->oid = le16_to_cpu((u16) rtsthresh_i);
 
 			if (cmd_action == cmd_act_get) {
-				pSNMPMIB->querytype =
-				    cpu_to_le16(cmd_act_get);
+				pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
 			} else if (cmd_action == cmd_act_set) {
-				pSNMPMIB->querytype =
-				    cpu_to_le16(cmd_act_set);
-				pSNMPMIB->bufsize =
-				    cpu_to_le16(sizeof(u16));
-				ulTemp = *((u32 *)
-					   pdata_buf);
-				*(unsigned short *)(pSNMPMIB->value) =
+				pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
+				pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
+				ulTemp = *((u32 *)pdata_buf);
+				*(__le16 *)(pSNMPMIB->value) =
 				    cpu_to_le16((u16) ulTemp);
 
 			}
@@ -462,13 +442,11 @@
 		pSNMPMIB->oid = cpu_to_le16((u16) short_retrylim_i);
 
 		if (cmd_action == cmd_act_get) {
-			pSNMPMIB->querytype =
-			    cpu_to_le16(cmd_act_get);
+			pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
 		} else if (cmd_action == cmd_act_set) {
-			pSNMPMIB->querytype =
-			    cpu_to_le16(cmd_act_set);
+			pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
 			pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
-			*((unsigned short *)(pSNMPMIB->value)) =
+			*((__le16 *)(pSNMPMIB->value)) =
 			    cpu_to_le16((u16) adapter->txretrycount);
 		}
 
@@ -477,16 +455,18 @@
 		break;
 	}
 
-	lbs_pr_debug(1,
+	lbs_deb_cmd(
 	       "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
-	       cmd->command, cmd->size, cmd->seqnum, cmd->result);
+	       le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
+	       le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
 
-	lbs_pr_debug(1,
+	lbs_deb_cmd(
 	       "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
-	       pSNMPMIB->querytype, pSNMPMIB->oid, pSNMPMIB->bufsize,
-	       *(u16 *) pSNMPMIB->value);
+	       le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
+	       le16_to_cpu(pSNMPMIB->bufsize),
+	       le16_to_cpu(*(__le16 *) pSNMPMIB->value));
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -495,10 +475,9 @@
 					 int cmd_action)
 {
 	wlan_adapter *adapter = priv->adapter;
-	struct cmd_ds_802_11_radio_control *pradiocontrol =
-	    &cmd->params.radio;
+	struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->size =
 	    cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
@@ -527,7 +506,7 @@
 	else
 		pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -538,16 +517,16 @@
 
 	struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->size =
-	    cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) +
-			     S_DS_GEN);
+	    cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
 	cmd->command = cpu_to_le16(cmd_802_11_rf_tx_power);
-	prtp->action = cmd_action;
+	prtp->action = cpu_to_le16(cmd_action);
 
-	lbs_pr_debug(1, "RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", cmd->size,
-	       cmd->command, prtp->action);
+	lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
+		    le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
+		    le16_to_cpu(prtp->action));
 
 	switch (cmd_action) {
 	case cmd_act_tx_power_opt_get:
@@ -557,14 +536,12 @@
 
 	case cmd_act_tx_power_opt_set_high:
 		prtp->action = cpu_to_le16(cmd_act_set);
-		prtp->currentlevel =
-		    cpu_to_le16(cmd_act_tx_power_index_high);
+		prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_high);
 		break;
 
 	case cmd_act_tx_power_opt_set_mid:
 		prtp->action = cpu_to_le16(cmd_act_set);
-		prtp->currentlevel =
-		    cpu_to_le16(cmd_act_tx_power_index_mid);
+		prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_mid);
 		break;
 
 	case cmd_act_tx_power_opt_set_low:
@@ -572,7 +549,8 @@
 		prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
 		break;
 	}
-	LEAVE();
+
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -583,15 +561,12 @@
 	struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
 
 	cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
-			     S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
+				S_DS_GEN);
 
 	rant->action = cpu_to_le16(cmd_action);
-	if ((cmd_action == cmd_act_set_rx) ||
-	    (cmd_action == cmd_act_set_tx)) {
-		rant->antennamode =
-		    cpu_to_le16((u16) (*(u32 *) pdata_buf));
+	if ((cmd_action == cmd_act_set_rx) || (cmd_action == cmd_act_set_tx)) {
+		rant->antennamode = cpu_to_le16((u16) (*(u32 *) pdata_buf));
 	}
 
 	return 0;
@@ -610,13 +585,13 @@
 			     + S_DS_GEN);
 	cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	rateadapt->action = cmd_action;
-	rateadapt->enablehwauto = adapter->enablehwauto;
-	rateadapt->bitmap = adapter->ratebitmap;
+	rateadapt->action = cpu_to_le16(cmd_action);
+	rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
+	rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -626,12 +601,10 @@
 {
 	struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
 	wlan_adapter *adapter = priv->adapter;
-	u16 action = cmd_action;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
 			     S_DS_GEN);
 
 	cmd->command = cpu_to_le16(cmd_802_11_data_rate);
@@ -640,15 +613,15 @@
 
 	pdatarate->action = cpu_to_le16(cmd_action);
 
-	if (action == cmd_act_set_tx_fix_rate) {
+	if (cmd_action == cmd_act_set_tx_fix_rate) {
 		pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
-		lbs_pr_debug(1, "Setting FW for fixed rate 0x%02X\n",
+		lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
 		       adapter->datarate);
-	} else if (action == cmd_act_set_tx_auto) {
-		lbs_pr_debug(1, "Setting FW for AUTO rate\n");
+	} else if (cmd_action == cmd_act_set_tx_auto) {
+		lbs_deb_cmd("Setting FW for AUTO rate\n");
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -659,8 +632,7 @@
 	struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
 	wlan_adapter *adapter = priv->adapter;
 
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
 			     S_DS_GEN);
 	cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
 
@@ -680,8 +652,8 @@
 	struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
 
 	cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
-	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel)
-				     + S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
+				S_DS_GEN);
 
 	if (option == cmd_opt_802_11_rf_channel_set) {
 		rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
@@ -698,9 +670,8 @@
 	wlan_adapter *adapter = priv->adapter;
 
 	cmd->command = cpu_to_le16(cmd_802_11_rssi);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
-	cmd->params.rssi.N = priv->adapter->bcn_avg_factor;
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
+	cmd->params.rssi.N = cpu_to_le16(priv->adapter->bcn_avg_factor);
 
 	/* reset Beacon SNR/NF/RSSI values */
 	adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
@@ -719,7 +690,7 @@
 {
 	struct wlan_offset_value *offval;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	offval = (struct wlan_offset_value *)pdata_buf;
 
@@ -729,9 +700,8 @@
 			struct cmd_ds_mac_reg_access *macreg;
 
 			cmdptr->size =
-			    cpu_to_le16(sizeof
-					     (struct cmd_ds_mac_reg_access)
-					     + S_DS_GEN);
+			    cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
+					+ S_DS_GEN);
 			macreg =
 			    (struct cmd_ds_mac_reg_access *)&cmdptr->params.
 			    macreg;
@@ -785,7 +755,7 @@
 		break;
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -796,8 +766,7 @@
 	wlan_adapter *adapter = priv->adapter;
 
 	cmd->command = cpu_to_le16(cmd_802_11_mac_address);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
 			     S_DS_GEN);
 	cmd->result = 0;
 
@@ -818,12 +787,11 @@
 {
 	struct wlan_ioctl_regrdwr *ea = pdata_buf;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
-			     S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
+				S_DS_GEN);
 	cmd->result = 0;
 
 	cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
@@ -839,11 +807,10 @@
 			       u16 cmd_action, void *pdata_buf)
 {
 	struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
-	lbs_pr_debug(1, "BT CMD(%d)\n", cmd_action);
+	lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
 
 	cmd->command = cpu_to_le16(cmd_bt_access);
-	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access)
-				     + S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
 	cmd->result = 0;
 	bt_access->action = cpu_to_le16(cmd_action);
 
@@ -861,6 +828,11 @@
 		break;
 	case cmd_act_bt_access_reset:
 		break;
+	case cmd_act_bt_access_set_invert:
+		bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
+		break;
+	case cmd_act_bt_access_get_invert:
+		break;
 	default:
 		break;
 	}
@@ -872,11 +844,10 @@
 			       u16 cmd_action, void *pdata_buf)
 {
 	struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
-	lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
+	lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
 
 	cmd->command = cpu_to_le16(cmd_fwt_access);
-	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access)
-				     + S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
 	cmd->result = 0;
 
 	if (pdata_buf)
@@ -894,11 +865,10 @@
 				u16 cmd_action, void *pdata_buf)
 {
 	struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
-	lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
+	lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
 
 	cmd->command = cpu_to_le16(cmd_mesh_access);
-	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access)
-				     + S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
 	cmd->result = 0;
 
 	if (pdata_buf)
@@ -916,23 +886,23 @@
 	unsigned long flags;
 	struct cmd_ds_command *cmdptr;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	if (!cmdnode) {
-		lbs_pr_debug(1, "QUEUE_CMD: cmdnode is NULL\n");
+		lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
 		goto done;
 	}
 
 	cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
 	if (!cmdptr) {
-		lbs_pr_debug(1, "QUEUE_CMD: cmdptr is NULL\n");
+		lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
 		goto done;
 	}
 
 	/* Exit_PS command needs to be queued in the header always. */
 	if (cmdptr->command == cmd_802_11_ps_mode) {
 		struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
-		if (psm->action == cmd_subcmd_exit_ps) {
+		if (psm->action == cpu_to_le16(cmd_subcmd_exit_ps)) {
 			if (adapter->psstate != PS_STATE_FULL_POWER)
 				addtail = 0;
 		}
@@ -948,13 +918,12 @@
 
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
-	lbs_pr_debug(1, "QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
+	lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
 	       cmdnode,
-	       ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
+	       le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
 
 done:
-	LEAVE();
-	return;
+	lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /*
@@ -974,10 +943,10 @@
 	u16 cmdsize;
 	u16 command;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	if (!adapter || !cmdnode) {
-		lbs_pr_debug(1, "DNLD_CMD: adapter = %p, cmdnode = %p\n",
+		lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
 		       adapter, cmdnode);
 		if (cmdnode) {
 			spin_lock_irqsave(&adapter->driver_lock, flags);
@@ -993,7 +962,7 @@
 
 	spin_lock_irqsave(&adapter->driver_lock, flags);
 	if (!cmdptr || !cmdptr->size) {
-		lbs_pr_debug(1, "DNLD_CMD: cmdptr is Null or cmd size is Zero, "
+		lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
 		       "Not sending\n");
 		__libertas_cleanup_and_insert_cmd(priv, cmdnode);
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
@@ -1004,8 +973,8 @@
 	adapter->cur_cmd = cmdnode;
 	adapter->cur_cmd_retcode = 0;
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
-	lbs_pr_debug(1, "DNLD_CMD:: Before download, size of cmd = %d\n",
-	       cmdptr->size);
+	lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
+		    le16_to_cpu(cmdptr->size));
 
 	cmdsize = cmdptr->size;
 
@@ -1014,10 +983,10 @@
 	cmdnode->cmdwaitqwoken = 0;
 	cmdsize = cpu_to_le16(cmdsize);
 
-	ret = libertas_sbi_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
+	ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
 
 	if (ret != 0) {
-		lbs_pr_debug(1, "DNLD_CMD: Host to Card failed\n");
+		lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
 		spin_lock_irqsave(&adapter->driver_lock, flags);
 		__libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
 		adapter->cur_cmd = NULL;
@@ -1026,12 +995,11 @@
 		goto done;
 	}
 
-	lbs_pr_debug(1, "DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
+	lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
 	lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
 
 	/* Setup the timer after transmit command */
-	if (command == cmd_802_11_scan
-	    || command == cmd_802_11_authenticate
+	if (command == cmd_802_11_scan || command == cmd_802_11_authenticate
 	    || command == cmd_802_11_associate)
 		mod_timer(&adapter->command_timer, jiffies + (10*HZ));
 	else
@@ -1039,8 +1007,8 @@
 
 	ret = 0;
 
-      done:
-	LEAVE();
+done:
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
@@ -1049,17 +1017,16 @@
 {
 	struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	cmd->command = cpu_to_le16(cmd_mac_control);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
 	mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
 
-	lbs_pr_debug(1, "wlan_cmd_mac_control(): action=0x%X size=%d\n",
-	       mac->action, cmd->size);
+	lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
+		    le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -1093,17 +1060,17 @@
 {
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	ret = libertas_prepare_and_send_command(priv,
 				    cmd_802_11_radio_control,
 				    cmd_act_set,
 				    cmd_option_waitforrsp, 0, NULL);
 
-	lbs_pr_debug(1, "RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
+	lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
 	       priv->adapter->radioon, priv->adapter->preamble);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
@@ -1111,16 +1078,16 @@
 {
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	lbs_pr_debug(1, "libertas_set_mac_packet_filter value = %x\n",
+	lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
 	       priv->adapter->currentpacketfilter);
 
 	/* Send MAC control command to station */
 	ret = libertas_prepare_and_send_command(priv,
 				    cmd_mac_control, 0, 0, 0, NULL);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
@@ -1146,16 +1113,16 @@
 	struct cmd_ds_command *cmdptr;
 	unsigned long flags;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	if (!adapter) {
-		lbs_pr_debug(1, "PREP_CMD: adapter is Null\n");
+		lbs_deb_cmd("PREP_CMD: adapter is Null\n");
 		ret = -1;
 		goto done;
 	}
 
 	if (adapter->surpriseremoved) {
-		lbs_pr_debug(1, "PREP_CMD: Card is Removed\n");
+		lbs_deb_cmd("PREP_CMD: Card is Removed\n");
 		ret = -1;
 		goto done;
 	}
@@ -1163,7 +1130,7 @@
 	cmdnode = libertas_get_free_cmd_ctrl_node(priv);
 
 	if (cmdnode == NULL) {
-		lbs_pr_debug(1, "PREP_CMD: No free cmdnode\n");
+		lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
 
 		/* Wake up main thread to execute next command */
 		wake_up_interruptible(&priv->mainthread.waitq);
@@ -1175,11 +1142,11 @@
 
 	cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
 
-	lbs_pr_debug(1, "PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
+	lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
 	       cmdptr, cmd_no);
 
 	if (!cmdptr) {
-		lbs_pr_debug(1, "PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
+		lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
 		libertas_cleanup_and_insert_cmd(priv, cmdnode);
 		ret = -1;
 		goto done;
@@ -1189,7 +1156,7 @@
 	adapter->seqnum++;
 	cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
 
-	cmdptr->command = cmd_no;
+	cmdptr->command = cpu_to_le16(cmd_no);
 	cmdptr->result = 0;
 
 	switch (cmd_no) {
@@ -1298,13 +1265,13 @@
 		break;
 
 	case cmd_802_11_enable_rsn:
-		ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action);
+		ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
+				pdata_buf);
 		break;
 
 	case cmd_802_11_key_material:
-		ret = wlan_cmd_802_11_key_material(priv, cmdptr,
-						   cmd_action, cmd_oid,
-						   pdata_buf);
+		ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
+				cmd_oid, pdata_buf);
 		break;
 
 	case cmd_802_11_pairwise_tsc:
@@ -1325,9 +1292,8 @@
 	case cmd_802_11_get_afc:
 
 		cmdptr->command = cpu_to_le16(cmd_no);
-		cmdptr->size =
-		    cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
-				     S_DS_GEN);
+		cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
+					   S_DS_GEN);
 
 		memmove(&cmdptr->params.afc,
 			pdata_buf, sizeof(struct cmd_ds_802_11_afc));
@@ -1406,29 +1372,26 @@
 
 	case cmd_get_tsf:
 		cmdptr->command = cpu_to_le16(cmd_get_tsf);
-		cmdptr->size =
-		    cpu_to_le16(sizeof(struct cmd_ds_get_tsf)
-				     + S_DS_GEN);
+		cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
+					   S_DS_GEN);
 		ret = 0;
 		break;
 	case cmd_802_11_tx_rate_query:
-		cmdptr->command =
-		    cpu_to_le16(cmd_802_11_tx_rate_query);
-		cmdptr->size =
-		    cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
-				     S_DS_GEN);
+		cmdptr->command = cpu_to_le16(cmd_802_11_tx_rate_query);
+		cmdptr->size = cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
+					   S_DS_GEN);
 		adapter->txrate = 0;
 		ret = 0;
 		break;
 	default:
-		lbs_pr_debug(1, "PREP_CMD: unknown command- %#x\n", cmd_no);
+		lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
 		ret = -1;
 		break;
 	}
 
 	/* return error, since the command preparation failed */
 	if (ret != 0) {
-		lbs_pr_debug(1, "PREP_CMD: command preparation failed\n");
+		lbs_deb_cmd("PREP_CMD: command preparation failed\n");
 		libertas_cleanup_and_insert_cmd(priv, cmdnode);
 		ret = -1;
 		goto done;
@@ -1441,7 +1404,7 @@
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	if (wait_option & cmd_option_waitforrsp) {
-		lbs_pr_debug(1, "PREP_CMD: Wait for CMD response\n");
+		lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
 		might_sleep();
 		wait_event_interruptible(cmdnode->cmdwait_q,
 					 cmdnode->cmdwaitqwoken);
@@ -1449,7 +1412,7 @@
 
 	spin_lock_irqsave(&adapter->driver_lock, flags);
 	if (adapter->cur_cmd_retcode) {
-		lbs_pr_debug(1, "PREP_CMD: command failed with return code=%d\n",
+		lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
 		       adapter->cur_cmd_retcode);
 		adapter->cur_cmd_retcode = 0;
 		ret = -1;
@@ -1457,9 +1420,10 @@
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
 
 /**
  *  @brief This function allocates the command buffer and link
@@ -1477,33 +1441,29 @@
 	u8 *ptempvirtualaddr;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	/* Allocate and initialize cmdCtrlNode */
 	ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
 
-	if (!(tempcmd_array = kmalloc(ulbufsize, GFP_KERNEL))) {
-		lbs_pr_debug(1,
+	if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
+		lbs_deb_cmd(
 		       "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
 		ret = -1;
 		goto done;
 	}
-
 	adapter->cmd_array = tempcmd_array;
-	memset(adapter->cmd_array, 0, ulbufsize);
 
 	/* Allocate and initialize command buffers */
 	ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
 	for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
-		if (!(ptempvirtualaddr = kmalloc(ulbufsize, GFP_KERNEL))) {
-			lbs_pr_debug(1,
+		if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
+			lbs_deb_cmd(
 			       "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
 			ret = -1;
 			goto done;
 		}
 
-		memset(ptempvirtualaddr, 0, ulbufsize);
-
 		/* Update command buffer virtual */
 		tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
 	}
@@ -1514,8 +1474,9 @@
 	}
 
 	ret = 0;
-      done:
-	LEAVE();
+
+done:
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
@@ -1527,16 +1488,16 @@
  */
 int libertas_free_cmd_buffer(wlan_private * priv)
 {
-	u32 ulbufsize;
+	u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
 	unsigned int i;
 	struct cmd_ctrl_node *tempcmd_array;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	/* need to check if cmd array is allocated or not */
 	if (adapter->cmd_array == NULL) {
-		lbs_pr_debug(1, "FREE_CMD_BUF: cmd_array is Null\n");
+		lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
 		goto done;
 	}
 
@@ -1546,7 +1507,7 @@
 	ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
 	for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
 		if (tempcmd_array[i].bufvirtualaddr) {
-			lbs_pr_debug(1, "Free all the array\n");
+			lbs_deb_cmd("Free all the array\n");
 			kfree(tempcmd_array[i].bufvirtualaddr);
 			tempcmd_array[i].bufvirtualaddr = NULL;
 		}
@@ -1554,13 +1515,13 @@
 
 	/* Release cmd_ctrl_node */
 	if (adapter->cmd_array) {
-		lbs_pr_debug(1, "Free cmd_array\n");
+		lbs_deb_cmd("Free cmd_array\n");
 		kfree(adapter->cmd_array);
 		adapter->cmd_array = NULL;
 	}
 
 done:
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -1586,16 +1547,18 @@
 		tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
 		list_del((struct list_head *)tempnode);
 	} else {
-		lbs_pr_debug(1, "GET_CMD_NODE: cmd_ctrl_node is not available\n");
+		lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
 		tempnode = NULL;
 	}
 
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
 	if (tempnode) {
+		/*
 		lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
 		lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
 		       tempnode);
+		*/
 		cleanup_cmdnode(tempnode);
 	}
 
@@ -1638,7 +1601,7 @@
 		    struct cmd_ctrl_node *ptempnode,
 		    u32 cmd_oid, u16 wait_option, void *pdata_buf)
 {
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	if (!ptempnode)
 		return;
@@ -1647,7 +1610,7 @@
 	ptempnode->wait_option = wait_option;
 	ptempnode->pdata_buf = pdata_buf;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /**
@@ -1666,7 +1629,7 @@
 	unsigned long flags;
 	int ret = 0;
 
-	lbs_pr_debug(1, "libertas_execute_next_command\n");
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	spin_lock_irqsave(&adapter->driver_lock, flags);
 
@@ -1685,23 +1648,24 @@
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
 	if (cmdnode) {
-		lbs_pr_debug(1,
+		lbs_deb_cmd(
 		       "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
 		cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
 
 		if (is_command_allowed_in_ps(cmdptr->command)) {
-			if ((adapter->psstate == PS_STATE_SLEEP)
-			    || (adapter->psstate == PS_STATE_PRE_SLEEP)
-			    ) {
-				lbs_pr_debug(1,
+			if ((adapter->psstate == PS_STATE_SLEEP) ||
+			    (adapter->psstate == PS_STATE_PRE_SLEEP)) {
+				lbs_deb_cmd(
 				       "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
-				       cmdptr->command, adapter->psstate);
+				       le16_to_cpu(cmdptr->command),
+				       adapter->psstate);
 				ret = -1;
 				goto done;
 			}
-			lbs_pr_debug(1, "EXEC_NEXT_CMD: OK to send command "
+			lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
 			       "0x%x in psstate %d\n",
-			       cmdptr->command, adapter->psstate);
+				    le16_to_cpu(cmdptr->command),
+				    adapter->psstate);
 		} else if (adapter->psstate != PS_STATE_FULL_POWER) {
 			/*
 			 * 1. Non-PS command:
@@ -1737,12 +1701,12 @@
 				struct cmd_ds_802_11_ps_mode *psm =
 				    &cmdptr->params.psmode;
 
-				lbs_pr_debug(1,
+				lbs_deb_cmd(
 				       "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
 				       psm->action);
 				if (psm->action !=
 				    cpu_to_le16(cmd_subcmd_exit_ps)) {
-					lbs_pr_debug(1,
+					lbs_deb_cmd(
 					       "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
 					list_del((struct list_head *)cmdnode);
 					libertas_cleanup_and_insert_cmd(priv, cmdnode);
@@ -1751,10 +1715,9 @@
 					goto done;
 				}
 
-				if ((adapter->psstate == PS_STATE_SLEEP)
-				    || (adapter->psstate == PS_STATE_PRE_SLEEP)
-				    ) {
-					lbs_pr_debug(1,
+				if ((adapter->psstate == PS_STATE_SLEEP) ||
+				    (adapter->psstate == PS_STATE_PRE_SLEEP)) {
+					lbs_deb_cmd(
 					       "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
 					list_del((struct list_head *)cmdnode);
 					libertas_cleanup_and_insert_cmd(priv, cmdnode);
@@ -1764,13 +1727,13 @@
 					goto done;
 				}
 
-				lbs_pr_debug(1,
+				lbs_deb_cmd(
 				       "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
 			}
 		}
 		list_del((struct list_head *)cmdnode);
-		lbs_pr_debug(1, "EXEC_NEXT_CMD: Sending 0x%04X command\n",
-		       cmdptr->command);
+		lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
+			    le16_to_cpu(cmdptr->command));
 		DownloadcommandToStation(priv, cmdnode);
 	} else {
 		/*
@@ -1780,18 +1743,18 @@
 		if ((adapter->psmode != wlan802_11powermodecam) &&
 		    (adapter->psstate == PS_STATE_FULL_POWER) &&
 		    (adapter->connect_status == libertas_connected)) {
-			if (adapter->secinfo.WPAenabled
-			    || adapter->secinfo.WPA2enabled) {
+			if (adapter->secinfo.WPAenabled ||
+			    adapter->secinfo.WPA2enabled) {
 				/* check for valid WPA group keys */
-				if (adapter->wpa_mcast_key.len
-				    || adapter->wpa_unicast_key.len) {
-					lbs_pr_debug(1,
+				if (adapter->wpa_mcast_key.len ||
+				    adapter->wpa_unicast_key.len) {
+					lbs_deb_cmd(
 					       "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
 					       " go back to PS_SLEEP");
 					libertas_ps_sleep(priv, 0);
 				}
 			} else {
-				lbs_pr_debug(1,
+				lbs_deb_cmd(
 				       "EXEC_NEXT_CMD: command PendQ is empty,"
 				       " go back to PS_SLEEP");
 				libertas_ps_sleep(priv, 0);
@@ -1801,6 +1764,7 @@
 
 	ret = 0;
 done:
+	lbs_deb_leave(LBS_DEB_CMD);
 	return ret;
 }
 
@@ -1809,7 +1773,7 @@
 	union iwreq_data iwrq;
 	u8 buf[50];
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	memset(&iwrq, 0, sizeof(union iwreq_data));
 	memset(buf, 0, sizeof(buf));
@@ -1819,15 +1783,13 @@
 	iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
 
 	/* Send Event to upper layer */
-	lbs_pr_debug(1, "Event Indication string = %s\n",
-	       (char *)buf);
-	lbs_pr_debug(1, "Event Indication String length = %d\n", iwrq.data.length);
+	lbs_deb_cmd("Event Indication string = %s\n", (char *)buf);
+	lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
 
-	lbs_pr_debug(1, "Sending wireless event IWEVCUSTOM for %s\n", str);
-	wireless_send_event(priv->wlan_dev.netdev, IWEVCUSTOM, &iwrq, buf);
+	lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
+	wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
 
-	LEAVE();
-	return;
+	lbs_deb_leave(LBS_DEB_CMD);
 }
 
 static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
@@ -1836,19 +1798,19 @@
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	lbs_pr_debug(1, "SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
+	lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
 	       size);
 
 	lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
 
-	ret = libertas_sbi_host_to_card(priv, MVMS_CMD, cmdptr, size);
-	priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
+	ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
+	priv->dnld_sent = DNLD_RES_RECEIVED;
 
 	spin_lock_irqsave(&adapter->driver_lock, flags);
 	if (adapter->intcounter || adapter->currenttxskb)
-		lbs_pr_debug(1, "SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
+		lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
 		       adapter->intcounter, adapter->currenttxskb);
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
@@ -1860,23 +1822,22 @@
 		if (!adapter->intcounter) {
 			adapter->psstate = PS_STATE_SLEEP;
 		} else {
-			lbs_pr_debug(1, "SEND_SLEEPC_CMD: After sent,IntC=%d\n",
+			lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
 			       adapter->intcounter);
 		}
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
-		lbs_pr_debug(1, "SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
-		lbs_pr_debug(1, "+");
+		lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
+		lbs_deb_cmd("+");
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
 void libertas_ps_sleep(wlan_private * priv, int wait_option)
 {
-
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	/*
 	 * PS is currently supported only in Infrastructure mode
@@ -1886,8 +1847,7 @@
 	libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
 			      cmd_subcmd_enter_ps, wait_option, 0, NULL);
 
-	LEAVE();
-	return;
+	lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /**
@@ -1899,20 +1859,19 @@
  */
 void libertas_ps_wakeup(wlan_private * priv, int wait_option)
 {
-	enum WLAN_802_11_POWER_MODE Localpsmode;
+	__le32 Localpsmode;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	Localpsmode = wlan802_11powermodecam;
+	Localpsmode = cpu_to_le32(wlan802_11powermodecam);
 
-	lbs_pr_debug(1, "Exit_PS: Localpsmode = %d\n", Localpsmode);
+	lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", wlan802_11powermodecam);
 
 	libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
 			      cmd_subcmd_exit_ps,
 			      wait_option, 0, &Localpsmode);
 
-	LEAVE();
-	return;
+	lbs_deb_leave(LBS_DEB_CMD);
 }
 
 /**
@@ -1929,31 +1888,31 @@
 	wlan_adapter *adapter = priv->adapter;
 	u8 allowed = 1;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	if (priv->wlan_dev.dnld_sent) {
+	if (priv->dnld_sent) {
 		allowed = 0;
-		lbs_pr_debug(1, "D");
+		lbs_deb_cmd("D");
 	}
 
 	spin_lock_irqsave(&adapter->driver_lock, flags);
 	if (adapter->cur_cmd) {
 		allowed = 0;
-		lbs_pr_debug(1, "C");
+		lbs_deb_cmd("C");
 	}
 	if (adapter->intcounter > 0) {
 		allowed = 0;
-		lbs_pr_debug(1, "I%d", adapter->intcounter);
+		lbs_deb_cmd("I%d", adapter->intcounter);
 	}
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
 	if (allowed) {
-		lbs_pr_debug(1, "Sending libertas_ps_confirm_sleep\n");
+		lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
 		sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
 				 sizeof(struct PS_CMD_ConfirmSleep));
 	} else {
-		lbs_pr_debug(1, "Sleep Confirm has been delayed\n");
+		lbs_deb_cmd("Sleep Confirm has been delayed\n");
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_CMD);
 }
diff --git a/drivers/net/wireless/libertas/cmdresp.c b/drivers/net/wireless/libertas/cmdresp.c
index c864540..0c3b9a5 100644
--- a/drivers/net/wireless/libertas/cmdresp.c
+++ b/drivers/net/wireless/libertas/cmdresp.c
@@ -9,7 +9,6 @@
 #include <net/iw_handler.h>
 
 #include "host.h"
-#include "sbi.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
@@ -32,7 +31,7 @@
 	if (adapter->connect_status != libertas_connected)
 		return;
 
-	lbs_pr_debug(1, "Handles disconnect event.\n");
+	lbs_deb_cmd("Handles disconnect event.\n");
 
 	memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
 	wrqu.ap_addr.sa_family = ARPHRD_ETHER;
@@ -43,15 +42,15 @@
 	 */
 
 	msleep_interruptible(1000);
-	wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
+	wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
 
 	/* Free Tx and Rx packets */
 	kfree_skb(priv->adapter->currenttxskb);
 	priv->adapter->currenttxskb = NULL;
 
 	/* report disconnect to upper layer */
-	netif_stop_queue(priv->wlan_dev.netdev);
-	netif_carrier_off(priv->wlan_dev.netdev);
+	netif_stop_queue(priv->dev);
+	netif_carrier_off(priv->dev);
 
 	/* reset SNR/NF/RSSI values */
 	memset(adapter->SNR, 0x00, sizeof(adapter->SNR));
@@ -62,35 +61,32 @@
 	adapter->nextSNRNF = 0;
 	adapter->numSNRNF = 0;
 	adapter->rxpd_rate = 0;
-	lbs_pr_debug(1, "Current SSID=%s, ssid length=%u\n",
-	       adapter->curbssparams.ssid.ssid,
-	       adapter->curbssparams.ssid.ssidlength);
-	lbs_pr_debug(1, "Previous SSID=%s, ssid length=%u\n",
-	       adapter->previousssid.ssid, adapter->previousssid.ssidlength);
-
-	/* reset internal flags */
-	adapter->secinfo.WPAenabled = 0;
-	adapter->secinfo.WPA2enabled = 0;
-	adapter->wpa_ie_len = 0;
+	lbs_deb_cmd("Current SSID='%s', ssid length=%u\n",
+	            escape_essid(adapter->curbssparams.ssid,
+	                         adapter->curbssparams.ssid_len),
+	            adapter->curbssparams.ssid_len);
+	lbs_deb_cmd("Previous SSID='%s', ssid length=%u\n",
+	            escape_essid(adapter->prev_ssid, adapter->prev_ssid_len),
+	            adapter->prev_ssid_len);
 
 	adapter->connect_status = libertas_disconnected;
 
-	/*
-	 * memorize the previous SSID and BSSID
-	 * it could be used for re-assoc
-	 */
-	memcpy(&adapter->previousssid,
-	       &adapter->curbssparams.ssid, sizeof(struct WLAN_802_11_SSID));
-	memcpy(adapter->previousbssid,
-	       adapter->curbssparams.bssid, ETH_ALEN);
+	/* Save previous SSID and BSSID for possible reassociation */
+	memcpy(&adapter->prev_ssid, &adapter->curbssparams.ssid,
+	       IW_ESSID_MAX_SIZE);
+	adapter->prev_ssid_len = adapter->curbssparams.ssid_len;
+	memcpy(adapter->prev_bssid, adapter->curbssparams.bssid, ETH_ALEN);
 
-	/* need to erase the current SSID and BSSID info */
-	adapter->pattemptedbssdesc = NULL;
-	memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
+	/* Clear out associated SSID and BSSID since connection is
+	 * no longer valid.
+	 */
+	memset(&adapter->curbssparams.bssid, 0, ETH_ALEN);
+	memset(&adapter->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE);
+	adapter->curbssparams.ssid_len = 0;
 
 	if (adapter->psstate != PS_STATE_FULL_POWER) {
 		/* make firmware to exit PS mode */
-		lbs_pr_debug(1, "Disconnected, so exit PS mode.\n");
+		lbs_deb_cmd("Disconnected, so exit PS mode.\n");
 		libertas_ps_wakeup(priv, 0);
 	}
 }
@@ -122,55 +118,45 @@
 static int wlan_ret_reg_access(wlan_private * priv,
 			       u16 type, struct cmd_ds_command *resp)
 {
+	int ret = 0;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	switch (type) {
 	case cmd_ret_mac_reg_access:
 		{
-			struct cmd_ds_mac_reg_access *reg;
+			struct cmd_ds_mac_reg_access *reg = &resp->params.macreg;
 
-			reg =
-			    (struct cmd_ds_mac_reg_access *)&resp->params.
-			    macreg;
-
-			adapter->offsetvalue.offset = reg->offset;
-			adapter->offsetvalue.value = reg->value;
+			adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
+			adapter->offsetvalue.value = le32_to_cpu(reg->value);
 			break;
 		}
 
 	case cmd_ret_bbp_reg_access:
 		{
-			struct cmd_ds_bbp_reg_access *reg;
-			reg =
-			    (struct cmd_ds_bbp_reg_access *)&resp->params.
-			    bbpreg;
+			struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg;
 
-			adapter->offsetvalue.offset = reg->offset;
+			adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
 			adapter->offsetvalue.value = reg->value;
 			break;
 		}
 
 	case cmd_ret_rf_reg_access:
 		{
-			struct cmd_ds_rf_reg_access *reg;
-			reg =
-			    (struct cmd_ds_rf_reg_access *)&resp->params.
-			    rfreg;
+			struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg;
 
-			adapter->offsetvalue.offset = reg->offset;
+			adapter->offsetvalue.offset = (u32)le16_to_cpu(reg->offset);
 			adapter->offsetvalue.value = reg->value;
 			break;
 		}
 
 	default:
-		LEAVE();
-		return -1;
+		ret = -1;
 	}
 
-	LEAVE();
-	return 0;
+	lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
+	return ret;
 }
 
 static int wlan_ret_get_hw_spec(wlan_private * priv,
@@ -181,19 +167,20 @@
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	adapter->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo);
 
-	adapter->fwreleasenumber = hwspec->fwreleasenumber;
+	memcpy(adapter->fwreleasenumber, hwspec->fwreleasenumber, 4);
 
-	lbs_pr_debug(1, "GET_HW_SPEC: FWReleaseVersion- 0x%X\n",
-	       adapter->fwreleasenumber);
-	lbs_pr_debug(1, "GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
+	lbs_deb_cmd("GET_HW_SPEC: FWReleaseVersion- %u.%u.%u.p%u\n",
+		    adapter->fwreleasenumber[2], adapter->fwreleasenumber[1],
+		    adapter->fwreleasenumber[0], adapter->fwreleasenumber[3]);
+	lbs_deb_cmd("GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
 	       hwspec->permanentaddr[0], hwspec->permanentaddr[1],
 	       hwspec->permanentaddr[2], hwspec->permanentaddr[3],
 	       hwspec->permanentaddr[4], hwspec->permanentaddr[5]);
-	lbs_pr_debug(1, "GET_HW_SPEC: hwifversion=0x%X  version=0x%X\n",
+	lbs_deb_cmd("GET_HW_SPEC: hwifversion=0x%X  version=0x%X\n",
 	       hwspec->hwifversion, hwspec->version);
 
 	adapter->regioncode = le16_to_cpu(hwspec->regioncode);
@@ -210,17 +197,15 @@
 	if (i >= MRVDRV_MAX_REGION_CODE) {
 		adapter->regioncode = 0x10;
 		adapter->regiontableindex = 0;
-		lbs_pr_info(
-		       "unidentified region code, use the default (USA)\n");
+		lbs_pr_info("unidentified region code; using the default (USA)\n");
 	}
 
-	if (adapter->current_addr[0] == 0xff) {
-		memmove(adapter->current_addr, hwspec->permanentaddr,
-			ETH_ALEN);
-	}
+	if (adapter->current_addr[0] == 0xff)
+		memmove(adapter->current_addr, hwspec->permanentaddr, ETH_ALEN);
 
-	memcpy(priv->wlan_dev.netdev->dev_addr, adapter->current_addr, ETH_ALEN);
-	memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
+	memcpy(priv->dev->dev_addr, adapter->current_addr, ETH_ALEN);
+	if (priv->mesh_dev)
+		memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
 
 	if (libertas_set_regiontable(priv, adapter->regioncode, 0)) {
 		ret = -1;
@@ -232,8 +217,8 @@
 		goto done;
 	}
 
-      done:
-	LEAVE();
+done:
+	lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
@@ -243,19 +228,21 @@
 	struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	lbs_pr_debug(1, "error=%x offset=%x stabletime=%x calcontrol=%x\n"
-	       " extsleepclk=%x\n", sp->error, sp->offset,
-	       sp->stabletime, sp->calcontrol, sp->externalsleepclk);
+	lbs_deb_cmd("error=%x offset=%x stabletime=%x calcontrol=%x\n"
+		    " extsleepclk=%x\n", le16_to_cpu(sp->error),
+		    le16_to_cpu(sp->offset), le16_to_cpu(sp->stabletime),
+		    sp->calcontrol, sp->externalsleepclk);
+
 	adapter->sp.sp_error = le16_to_cpu(sp->error);
 	adapter->sp.sp_offset = le16_to_cpu(sp->offset);
 	adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
-	adapter->sp.sp_calcontrol = le16_to_cpu(sp->calcontrol);
-	adapter->sp.sp_extsleepclk = le16_to_cpu(sp->externalsleepclk);
+	adapter->sp.sp_calcontrol = sp->calcontrol;
+	adapter->sp.sp_extsleepclk = sp->externalsleepclk;
 	adapter->sp.sp_reserved = le16_to_cpu(sp->reserved);
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -281,42 +268,38 @@
 	u16 oid = le16_to_cpu(smib->oid);
 	u16 querytype = le16_to_cpu(smib->querytype);
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	lbs_pr_debug(1, "SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
+	lbs_deb_cmd("SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
 	       querytype);
-	lbs_pr_debug(1, "SNMP_RESP: Buf size  = %x\n",
-	       le16_to_cpu(smib->bufsize));
+	lbs_deb_cmd("SNMP_RESP: Buf size  = %x\n", le16_to_cpu(smib->bufsize));
 
 	if (querytype == cmd_act_get) {
 		switch (oid) {
 		case fragthresh_i:
 			priv->adapter->fragthsd =
-			    le16_to_cpu(*
-					     ((unsigned short *)(smib->value)));
-			lbs_pr_debug(1, "SNMP_RESP: fragthsd =%u\n",
-			       priv->adapter->fragthsd);
+				le16_to_cpu(*((__le16 *)(smib->value)));
+			lbs_deb_cmd("SNMP_RESP: fragthsd =%u\n",
+				    priv->adapter->fragthsd);
 			break;
 		case rtsthresh_i:
 			priv->adapter->rtsthsd =
-			    le16_to_cpu(*
-					     ((unsigned short *)(smib->value)));
-			lbs_pr_debug(1, "SNMP_RESP: rtsthsd =%u\n",
-			       priv->adapter->rtsthsd);
+				le16_to_cpu(*((__le16 *)(smib->value)));
+			lbs_deb_cmd("SNMP_RESP: rtsthsd =%u\n",
+				    priv->adapter->rtsthsd);
 			break;
 		case short_retrylim_i:
 			priv->adapter->txretrycount =
-			    le16_to_cpu(*
-					     ((unsigned short *)(smib->value)));
-			lbs_pr_debug(1, "SNMP_RESP: txretrycount =%u\n",
-			       priv->adapter->rtsthsd);
+				le16_to_cpu(*((__le16 *)(smib->value)));
+			lbs_deb_cmd("SNMP_RESP: txretrycount =%u\n",
+				    priv->adapter->rtsthsd);
 			break;
 		default:
 			break;
 		}
 	}
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -328,7 +311,7 @@
 	wlan_adapter *adapter = priv->adapter;
 	u16 action = le16_to_cpu(pkeymaterial->action);
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	/* Copy the returned key to driver private data */
 	if (action == cmd_act_get) {
@@ -371,7 +354,7 @@
 		}
 	}
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -381,11 +364,11 @@
 	struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN);
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -395,13 +378,13 @@
 	struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel);
 
-	lbs_pr_debug(1, "Current TxPower Level = %d\n", adapter->txpowerlevel);
+	lbs_deb_cmd("Current TxPower Level = %d\n", adapter->txpowerlevel);
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -413,14 +396,12 @@
 	u16 action = le16_to_cpu(pAntenna->action);
 
 	if (action == cmd_act_get_rx)
-		adapter->rxantennamode =
-		    le16_to_cpu(pAntenna->antennamode);
+		adapter->rxantennamode = le16_to_cpu(pAntenna->antennamode);
 
 	if (action == cmd_act_get_tx)
-		adapter->txantennamode =
-		    le16_to_cpu(pAntenna->antennamode);
+		adapter->txantennamode = le16_to_cpu(pAntenna->antennamode);
 
-	lbs_pr_debug(1, "RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
+	lbs_deb_cmd("RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
 	       action, le16_to_cpu(pAntenna->antennamode));
 
 	return 0;
@@ -429,19 +410,17 @@
 static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv,
 					      struct cmd_ds_command *resp)
 {
-	struct cmd_ds_802_11_rate_adapt_rateset *rates =
-	    &resp->params.rateset;
+	struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	if (rates->action == cmd_act_get) {
-		adapter->enablehwauto = rates->enablehwauto;
-		adapter->ratebitmap = rates->bitmap;
+		adapter->enablehwauto = le16_to_cpu(rates->enablehwauto);
+		adapter->ratebitmap = le16_to_cpu(rates->bitmap);
 	}
 
-	LEAVE();
-
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -452,43 +431,42 @@
 	wlan_adapter *adapter = priv->adapter;
 	u8 dot11datarate;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	lbs_dbg_hex("DATA_RATE_RESP: data_rate- ",
 		(u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate));
 
 	dot11datarate = pdatarate->datarate[0];
-	if (pdatarate->action == cmd_act_get_tx_rate) {
+	if (pdatarate->action == cpu_to_le16(cmd_act_get_tx_rate)) {
 		memcpy(adapter->libertas_supported_rates, pdatarate->datarate,
 		       sizeof(adapter->libertas_supported_rates));
 	}
 	adapter->datarate = libertas_index_to_data_rate(dot11datarate);
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
 static int wlan_ret_802_11_rf_channel(wlan_private * priv,
 				      struct cmd_ds_command *resp)
 {
-	struct cmd_ds_802_11_rf_channel *rfchannel =
-	    &resp->params.rfchannel;
+	struct cmd_ds_802_11_rf_channel *rfchannel = &resp->params.rfchannel;
 	wlan_adapter *adapter = priv->adapter;
 	u16 action = le16_to_cpu(rfchannel->action);
 	u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
 	if (action == cmd_opt_802_11_rf_channel_get
 	    && adapter->curbssparams.channel != newchannel) {
-		lbs_pr_debug(1, "channel Switch: %d to %d\n",
+		lbs_deb_cmd("channel Switch: %d to %d\n",
 		       adapter->curbssparams.channel, newchannel);
 
 		/* Update the channel again */
 		adapter->curbssparams.channel = newchannel;
 	}
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -500,12 +478,10 @@
 
 	/* store the non average value */
 	adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
-	adapter->NF[TYPE_BEACON][TYPE_NOAVG] =
-	    le16_to_cpu(rssirsp->noisefloor);
+	adapter->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor);
 
 	adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
-	adapter->NF[TYPE_BEACON][TYPE_AVG] =
-	    le16_to_cpu(rssirsp->avgnoisefloor);
+	adapter->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor);
 
 	adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] =
 	    CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
@@ -515,7 +491,7 @@
 	    CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
 		     adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
 
-	lbs_pr_debug(1, "Beacon RSSI value = 0x%x\n",
+	lbs_deb_cmd("Beacon RSSI value = 0x%x\n",
 	       adapter->RSSI[TYPE_BEACON][TYPE_AVG]);
 
 	return 0;
@@ -528,11 +504,11 @@
 	struct wlan_ioctl_regrdwr *pbuf;
 	pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom;
 
-	lbs_pr_debug(1, "eeprom read len=%x\n",
+	lbs_deb_cmd("eeprom read len=%x\n",
 	       le16_to_cpu(resp->params.rdeeprom.bytecount));
 	if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
 		pbuf->NOB = 0;
-		lbs_pr_debug(1, "eeprom read return length is too big\n");
+		lbs_deb_cmd("eeprom read return length is too big\n");
 		return -1;
 	}
 	pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
@@ -549,17 +525,15 @@
 static int wlan_ret_get_log(wlan_private * priv,
 			    struct cmd_ds_command *resp)
 {
-	struct cmd_ds_802_11_get_log *logmessage =
-	    (struct cmd_ds_802_11_get_log *)&resp->params.glog;
+	struct cmd_ds_802_11_get_log *logmessage = &resp->params.glog;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	/* TODO Convert it to Big Endian before copy */
-	memcpy(&adapter->logmsg, logmessage,
-	       sizeof(struct cmd_ds_802_11_get_log));
+	/* Stored little-endian */
+	memcpy(&adapter->logmsg, logmessage, sizeof(struct cmd_ds_802_11_get_log));
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_CMD);
 	return 0;
 }
 
@@ -620,8 +594,7 @@
 	case cmd_ret_802_11_set_afc:
 	case cmd_ret_802_11_get_afc:
 		spin_lock_irqsave(&adapter->driver_lock, flags);
-		memmove(adapter->cur_cmd->pdata_buf,
-			&resp->params.afc,
+		memmove(adapter->cur_cmd->pdata_buf, &resp->params.afc,
 			sizeof(struct cmd_ds_802_11_afc));
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
@@ -663,7 +636,7 @@
 		break;
 
 	case cmd_ret_802_11_key_material:
-		lbs_pr_debug(1, "CMD_RESP: KEY_MATERIAL command response\n");
+		lbs_deb_cmd("CMD_RESP: KEY_MATERIAL command response\n");
 		ret = wlan_ret_802_11_key_material(priv, resp);
 		break;
 
@@ -687,22 +660,19 @@
 
 	case cmd_ret_802_11_tpc_cfg:
 		spin_lock_irqsave(&adapter->driver_lock, flags);
-		memmove(adapter->cur_cmd->pdata_buf,
-			&resp->params.tpccfg,
+		memmove(adapter->cur_cmd->pdata_buf, &resp->params.tpccfg,
 			sizeof(struct cmd_ds_802_11_tpc_cfg));
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
 		break;
 	case cmd_ret_802_11_led_gpio_ctrl:
 		spin_lock_irqsave(&adapter->driver_lock, flags);
-		memmove(adapter->cur_cmd->pdata_buf,
-			&resp->params.ledgpio,
+		memmove(adapter->cur_cmd->pdata_buf, &resp->params.ledgpio,
 			sizeof(struct cmd_ds_802_11_led_ctrl));
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
 		break;
 	case cmd_ret_802_11_pwr_cfg:
 		spin_lock_irqsave(&adapter->driver_lock, flags);
-		memmove(adapter->cur_cmd->pdata_buf,
-			&resp->params.pwrcfg,
+		memmove(adapter->cur_cmd->pdata_buf, &resp->params.pwrcfg,
 			sizeof(struct cmd_ds_802_11_pwr_cfg));
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
@@ -724,23 +694,21 @@
 	case cmd_ret_fwt_access:
 		spin_lock_irqsave(&adapter->driver_lock, flags);
 		if (adapter->cur_cmd->pdata_buf)
-			memcpy(adapter->cur_cmd->pdata_buf,
-			       &resp->params.fwt,
-				sizeof(resp->params.fwt));
+			memcpy(adapter->cur_cmd->pdata_buf, &resp->params.fwt,
+			       sizeof(resp->params.fwt));
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
 		break;
 	case cmd_ret_mesh_access:
 		if (adapter->cur_cmd->pdata_buf)
-			memcpy(adapter->cur_cmd->pdata_buf,
-			       &resp->params.mesh,
+			memcpy(adapter->cur_cmd->pdata_buf, &resp->params.mesh,
 			       sizeof(resp->params.mesh));
 		break;
 	case cmd_rte_802_11_tx_rate_query:
 		priv->adapter->txrate = resp->params.txrate.txrate;
 		break;
 	default:
-		lbs_pr_debug(1, "CMD_RESP: Unknown command response %#x\n",
-		       resp->command);
+		lbs_deb_cmd("CMD_RESP: Unknown command response %#x\n",
+			    resp->command);
 		break;
 	}
 	return ret;
@@ -755,9 +723,9 @@
 	ulong flags;
 	u16 result;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	lbs_pr_debug(1, "CMD_RESP: @ %lu\n", jiffies);
+	lbs_deb_cmd("CMD_RESP: @ %lu\n", jiffies);
 
 	/* Now we got response from FW, cancel the command timer */
 	del_timer(&adapter->command_timer);
@@ -766,7 +734,7 @@
 	spin_lock_irqsave(&adapter->driver_lock, flags);
 
 	if (!adapter->cur_cmd) {
-		lbs_pr_debug(1, "CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
+		lbs_deb_cmd("CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
 		ret = -1;
 		spin_unlock_irqrestore(&adapter->driver_lock, flags);
 		goto done;
@@ -774,17 +742,17 @@
 	resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr);
 
 	lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr,
-		priv->wlan_dev.upld_len);
+		    priv->upld_len);
 
 	respcmd = le16_to_cpu(resp->command);
 
 	result = le16_to_cpu(resp->result);
 
-	lbs_pr_debug(1, "CMD_RESP: %x result: %d length: %d\n", respcmd,
-	       result, priv->wlan_dev.upld_len);
+	lbs_deb_cmd("CMD_RESP: %x result: %d length: %d\n", respcmd,
+		    result, priv->upld_len);
 
 	if (!(respcmd & 0x8000)) {
-		lbs_pr_debug(1, "Invalid response to command!");
+		lbs_deb_cmd("Invalid response to command!");
 		adapter->cur_cmd_retcode = -1;
 		__libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
 		adapter->nr_cmd_pending--;
@@ -795,56 +763,52 @@
 	}
 
 	/* Store the response code to cur_cmd_retcode. */
-	adapter->cur_cmd_retcode = le16_to_cpu(resp->result);
+	adapter->cur_cmd_retcode = result;;
 
 	if (respcmd == cmd_ret_802_11_ps_mode) {
-		struct cmd_ds_802_11_ps_mode *psmode;
+		struct cmd_ds_802_11_ps_mode *psmode = &resp->params.psmode;
+		u16 action = le16_to_cpu(psmode->action);
 
-		psmode = &resp->params.psmode;
-		lbs_pr_debug(1,
+		lbs_deb_cmd(
 		       "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n",
-		       resp->result, psmode->action);
-		psmode->action = cpu_to_le16(psmode->action);
+		       result, action);
 
 		if (result) {
-			lbs_pr_debug(1, "CMD_RESP: PS command failed- %#x \n",
-			       resp->result);
-			if (adapter->mode == IW_MODE_ADHOC) {
-				/*
-				 * We should not re-try enter-ps command in
-				 * ad-hoc mode. It takes place in
-				 * libertas_execute_next_command().
-				 */
-				if (psmode->action == cmd_subcmd_enter_ps)
-					adapter->psmode =
-					    wlan802_11powermodecam;
-			}
-		} else if (psmode->action == cmd_subcmd_enter_ps) {
+			lbs_deb_cmd("CMD_RESP: PS command failed- %#x \n",
+				    result);
+			/*
+			 * We should not re-try enter-ps command in
+			 * ad-hoc mode. It takes place in
+			 * libertas_execute_next_command().
+			 */
+			if (adapter->mode == IW_MODE_ADHOC &&
+			    action == cmd_subcmd_enter_ps)
+				adapter->psmode = wlan802_11powermodecam;
+		} else if (action == cmd_subcmd_enter_ps) {
 			adapter->needtowakeup = 0;
 			adapter->psstate = PS_STATE_AWAKE;
 
-			lbs_pr_debug(1, "CMD_RESP: Enter_PS command response\n");
+			lbs_deb_cmd("CMD_RESP: Enter_PS command response\n");
 			if (adapter->connect_status != libertas_connected) {
 				/*
 				 * When Deauth Event received before Enter_PS command
 				 * response, We need to wake up the firmware.
 				 */
-				lbs_pr_debug(1,
+				lbs_deb_cmd(
 				       "Disconnected, Going to invoke libertas_ps_wakeup\n");
 
-				mutex_unlock(&adapter->lock);
 				spin_unlock_irqrestore(&adapter->driver_lock, flags);
+				mutex_unlock(&adapter->lock);
 				libertas_ps_wakeup(priv, 0);
 				mutex_lock(&adapter->lock);
 				spin_lock_irqsave(&adapter->driver_lock, flags);
 			}
-		} else if (psmode->action == cmd_subcmd_exit_ps) {
+		} else if (action == cmd_subcmd_exit_ps) {
 			adapter->needtowakeup = 0;
 			adapter->psstate = PS_STATE_FULL_POWER;
-			lbs_pr_debug(1, "CMD_RESP: Exit_PS command response\n");
+			lbs_deb_cmd("CMD_RESP: Exit_PS command response\n");
 		} else {
-			lbs_pr_debug(1, "CMD_RESP: PS- action=0x%X\n",
-			       psmode->action);
+			lbs_deb_cmd("CMD_RESP: PS- action=0x%X\n", action);
 		}
 
 		__libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
@@ -865,15 +829,15 @@
 
 	/* If the command is not successful, cleanup and return failure */
 	if ((result != 0 || !(respcmd & 0x8000))) {
-		lbs_pr_debug(1, "CMD_RESP: command reply %#x result=%#x\n",
-		       resp->command, resp->result);
+		lbs_deb_cmd("CMD_RESP: command reply %#x result=%#x\n",
+		       respcmd, result);
 		/*
 		 * Handling errors here
 		 */
 		switch (respcmd) {
 		case cmd_ret_hw_spec_info:
 		case cmd_ret_802_11_reset:
-			lbs_pr_debug(1, "CMD_RESP: Reset command failed\n");
+			lbs_deb_cmd("CMD_RESP: Reset command failed\n");
 			break;
 
 		}
@@ -903,7 +867,7 @@
 
 done:
 	mutex_unlock(&adapter->lock);
-	LEAVE();
+	lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
 
@@ -917,37 +881,37 @@
 	eventcause = adapter->eventcause;
 	spin_unlock_irq(&adapter->driver_lock);
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_CMD);
 
-	lbs_pr_debug(1, "EVENT Cause %x\n", eventcause);
+	lbs_deb_cmd("EVENT Cause %x\n", eventcause);
 
 	switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) {
 	case MACREG_INT_CODE_LINK_SENSED:
-		lbs_pr_debug(1, "EVENT: MACREG_INT_CODE_LINK_SENSED\n");
+		lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
 		break;
 
 	case MACREG_INT_CODE_DEAUTHENTICATED:
-		lbs_pr_debug(1, "EVENT: Deauthenticated\n");
+		lbs_deb_cmd("EVENT: Deauthenticated\n");
 		libertas_mac_event_disconnected(priv);
 		break;
 
 	case MACREG_INT_CODE_DISASSOCIATED:
-		lbs_pr_debug(1, "EVENT: Disassociated\n");
+		lbs_deb_cmd("EVENT: Disassociated\n");
 		libertas_mac_event_disconnected(priv);
 		break;
 
 	case MACREG_INT_CODE_LINK_LOSE_NO_SCAN:
-		lbs_pr_debug(1, "EVENT: Link lost\n");
+		lbs_deb_cmd("EVENT: Link lost\n");
 		libertas_mac_event_disconnected(priv);
 		break;
 
 	case MACREG_INT_CODE_PS_SLEEP:
-		lbs_pr_debug(1, "EVENT: SLEEP\n");
-		lbs_pr_debug(1, "_");
+		lbs_deb_cmd("EVENT: SLEEP\n");
+		lbs_deb_cmd("_");
 
 		/* handle unexpected PS SLEEP event */
 		if (adapter->psstate == PS_STATE_FULL_POWER) {
-			lbs_pr_debug(1,
+			lbs_deb_cmd(
 			       "EVENT: In FULL POWER mode - ignore PS SLEEP\n");
 			break;
 		}
@@ -958,12 +922,12 @@
 		break;
 
 	case MACREG_INT_CODE_PS_AWAKE:
-		lbs_pr_debug(1, "EVENT: AWAKE \n");
-		lbs_pr_debug(1, "|");
+		lbs_deb_cmd("EVENT: AWAKE \n");
+		lbs_deb_cmd("|");
 
 		/* handle unexpected PS AWAKE event */
 		if (adapter->psstate == PS_STATE_FULL_POWER) {
-			lbs_pr_debug(1,
+			lbs_deb_cmd(
 			       "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
 			break;
 		}
@@ -977,18 +941,18 @@
 			 * adapter->needtowakeup will be set to FALSE
 			 * in libertas_ps_wakeup()
 			 */
-			lbs_pr_debug(1, "Waking up...\n");
+			lbs_deb_cmd("Waking up...\n");
 			libertas_ps_wakeup(priv, 0);
 		}
 		break;
 
 	case MACREG_INT_CODE_MIC_ERR_UNICAST:
-		lbs_pr_debug(1, "EVENT: UNICAST MIC ERROR\n");
+		lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
 		handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
 		break;
 
 	case MACREG_INT_CODE_MIC_ERR_MULTICAST:
-		lbs_pr_debug(1, "EVENT: MULTICAST MIC ERROR\n");
+		lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
 		handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
 		break;
 	case MACREG_INT_CODE_MIB_CHANGED:
@@ -996,7 +960,7 @@
 		break;
 
 	case MACREG_INT_CODE_ADHOC_BCN_LOST:
-		lbs_pr_debug(1, "EVENT: HWAC - ADHOC BCN LOST\n");
+		lbs_deb_cmd("EVENT: HWAC - ADHOC BCN LOST\n");
 		break;
 
 	case MACREG_INT_CODE_RSSI_LOW:
@@ -1015,6 +979,17 @@
 		lbs_pr_alert( "EVENT: SNR_HIGH\n");
 		break;
 
+	case MACREG_INT_CODE_MESH_AUTO_STARTED:
+		lbs_pr_alert( "EVENT: MESH_AUTO_STARTED\n");
+		adapter->connect_status = libertas_connected ;
+		if (priv->mesh_open == 1) {
+			netif_wake_queue(priv->mesh_dev) ;
+			netif_carrier_on(priv->mesh_dev) ;
+		}
+		adapter->mode = IW_MODE_ADHOC ;
+		schedule_work(&priv->sync_channel);
+		break;
+
 	default:
 		lbs_pr_alert( "EVENT: unknown event id: %#x\n",
 		       eventcause >> SBI_EVENT_CAUSE_SHIFT);
@@ -1024,6 +999,7 @@
 	spin_lock_irq(&adapter->driver_lock);
 	adapter->eventcause = 0;
 	spin_unlock_irq(&adapter->driver_lock);
-	LEAVE();
+
+	lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret);
 	return ret;
 }
diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
index 7d7bc5e..715cbda 100644
--- a/drivers/net/wireless/libertas/debugfs.c
+++ b/drivers/net/wireless/libertas/debugfs.c
@@ -4,6 +4,7 @@
 #include <linux/delay.h>
 #include <linux/mm.h>
 #include <net/iw_handler.h>
+
 #include "dev.h"
 #include "decl.h"
 #include "host.h"
@@ -15,7 +16,9 @@
 	"Disconnected"
 };
 
-void libertas_debug_init(wlan_private * priv, struct net_device *dev);
+#ifdef PROC_DEBUG
+static void libertas_debug_init(wlan_private * priv, struct net_device *dev);
+#endif
 
 static int open_file_generic(struct inode *inode, struct file *file)
 {
@@ -60,43 +63,33 @@
 	int numscansdone = 0, res;
 	unsigned long addr = get_zeroed_page(GFP_KERNEL);
 	char *buf = (char *)addr;
+	struct bss_descriptor * iter_bss;
 
 	pos += snprintf(buf+pos, len-pos,
-			"---------------------------------------");
-	pos += snprintf(buf+pos, len-pos,
-			"---------------------------------------\n");
-	pos += snprintf(buf+pos, len-pos,
 		"# | ch  | ss  |       bssid       |   cap    |    TSF   | Qual | SSID \n");
-	pos += snprintf(buf+pos, len-pos,
-		"---------------------------------------");
-	pos += snprintf(buf+pos, len-pos,
-		"---------------------------------------\n");
 
-	while (numscansdone < priv->adapter->numinscantable) {
-		struct bss_descriptor *pbssinfo;
+	mutex_lock(&priv->adapter->lock);
+	list_for_each_entry (iter_bss, &priv->adapter->network_list, list) {
 		u16 cap;
 
-		pbssinfo = &priv->adapter->scantable[numscansdone];
-		memcpy(&cap, &pbssinfo->cap, sizeof(cap));
+		memcpy(&cap, &iter_bss->cap, sizeof(cap));
 		pos += snprintf(buf+pos, len-pos,
-			"%02u| %03d | %03ld | %02x:%02x:%02x:%02x:%02x:%02x |",
-			numscansdone, pbssinfo->channel, pbssinfo->rssi,
-			pbssinfo->macaddress[0], pbssinfo->macaddress[1],
-			pbssinfo->macaddress[2], pbssinfo->macaddress[3],
-			pbssinfo->macaddress[4], pbssinfo->macaddress[5]);
+			"%02u| %03d | %03ld | " MAC_FMT " |",
+			numscansdone, iter_bss->channel, iter_bss->rssi,
+			MAC_ARG(iter_bss->bssid));
 		pos += snprintf(buf+pos, len-pos, " %04x-", cap);
 		pos += snprintf(buf+pos, len-pos, "%c%c%c |",
-				pbssinfo->cap.ibss ? 'A' : 'I',
-				pbssinfo->cap.privacy ? 'P' : ' ',
-				pbssinfo->cap.spectrummgmt ? 'S' : ' ');
-		pos += snprintf(buf+pos, len-pos, " %08llx |", pbssinfo->networktsf);
-		pos += snprintf(buf+pos, len-pos, " %d |",
-			SCAN_RSSI(priv->adapter->scantable[numscansdone].rssi));
-
-		pos += snprintf(buf+pos, len-pos, " %s\n", pbssinfo->ssid.ssid);
+				iter_bss->cap.ibss ? 'A' : 'I',
+				iter_bss->cap.privacy ? 'P' : ' ',
+				iter_bss->cap.spectrummgmt ? 'S' : ' ');
+		pos += snprintf(buf+pos, len-pos, " %08llx |", iter_bss->networktsf);
+		pos += snprintf(buf+pos, len-pos, " %d |", SCAN_RSSI(iter_bss->rssi));
+		pos += snprintf(buf+pos, len-pos, " %s\n",
+		                escape_essid(iter_bss->ssid, iter_bss->ssid_len));
 
 		numscansdone++;
 	}
+	mutex_unlock(&priv->adapter->lock);
 
 	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
 
@@ -111,7 +104,6 @@
 	wlan_private *priv = file->private_data;
 	ssize_t buf_size, res;
 	int p1, p2, p3, p4, p5, p6;
-	struct sleep_params sp;
 	unsigned long addr = get_zeroed_page(GFP_KERNEL);
 	char *buf = (char *)addr;
 
@@ -125,14 +117,12 @@
 		res = -EFAULT;
 		goto out_unlock;
 	}
-	sp.sp_error = p1;
-	sp.sp_offset = p2;
-	sp.sp_stabletime = p3;
-	sp.sp_calcontrol = p4;
-	sp.sp_extsleepclk = p5;
-	sp.sp_reserved = p6;
-
-	memcpy(&priv->adapter->sp, &sp, sizeof(struct sleep_params));
+	priv->adapter->sp.sp_error = p1;
+	priv->adapter->sp.sp_offset = p2;
+	priv->adapter->sp.sp_stabletime = p3;
+	priv->adapter->sp.sp_calcontrol = p4;
+	priv->adapter->sp.sp_extsleepclk = p5;
+	priv->adapter->sp.sp_reserved = p6;
 
         res = libertas_prepare_and_send_command(priv,
 				cmd_802_11_sleep_params,
@@ -185,7 +175,6 @@
 {
 	wlan_private *priv = file->private_data;
 	ssize_t res, buf_size;
-	struct WLAN_802_11_SSID extscan_ssid;
 	union iwreq_data wrqu;
 	unsigned long addr = get_zeroed_page(GFP_KERNEL);
 	char *buf = (char *)addr;
@@ -196,13 +185,10 @@
 		goto out_unlock;
 	}
 
-	memcpy(&extscan_ssid.ssid, buf, strlen(buf)-1);
-	extscan_ssid.ssidlength = strlen(buf)-1;
-
-	libertas_send_specific_SSID_scan(priv, &extscan_ssid, 1);
+	libertas_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
 
 	memset(&wrqu, 0, sizeof(union iwreq_data));
-	wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
+	wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
 
 out_unlock:
 	free_page(addr);
@@ -251,16 +237,13 @@
 {
 	char *hold;
 	unsigned int mac[ETH_ALEN];
-	int i;
 
 	hold = strstr(buf, "bssid=");
 	if (!hold)
 		return;
 	hold += 6;
-	sscanf(hold, "%2x:%2x:%2x:%2x:%2x:%2x", mac, mac+1, mac+2, mac+3,
-			mac+4, mac+5);
-	for(i=0;i<ETH_ALEN;i++)
-		scan_cfg->specificBSSID[i] = mac[i];
+	sscanf(hold, MAC_FMT, mac, mac+1, mac+2, mac+3, mac+4, mac+5);
+	memcpy(scan_cfg->bssid, mac, ETH_ALEN);
 }
 
 static void libertas_parse_ssid(char *buf, size_t count,
@@ -278,28 +261,26 @@
 		end = buf + count - 1;
 
 	size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
-	strncpy(scan_cfg->specificSSID, hold, size);
+	strncpy(scan_cfg->ssid, hold, size);
 
 	return;
 }
 
-static void libertas_parse_keep(char *buf, size_t count,
-                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+static int libertas_parse_clear(char *buf, size_t count, const char *tag)
 {
 	char *hold;
 	int val;
 
-	hold = strstr(buf, "keep=");
+	hold = strstr(buf, tag);
 	if (!hold)
-		return;
-	hold += 5;
+		return 0;
+	hold += strlen(tag);
 	sscanf(hold, "%d", &val);
 
 	if (val != 0)
 		val = 1;
 
-	scan_cfg->keeppreviousscan = val;
-	return;
+	return val;
 }
 
 static int libertas_parse_dur(char *buf, size_t count,
@@ -382,17 +363,18 @@
 	dur = libertas_parse_dur(buf, count, scan_cfg);
 	libertas_parse_chan(buf, count, scan_cfg, dur);
 	libertas_parse_bssid(buf, count, scan_cfg);
+	scan_cfg->clear_bssid = libertas_parse_clear(buf, count, "clear_bssid=");
 	libertas_parse_ssid(buf, count, scan_cfg);
-	libertas_parse_keep(buf, count, scan_cfg);
+	scan_cfg->clear_ssid = libertas_parse_clear(buf, count, "clear_ssid=");
 	libertas_parse_probes(buf, count, scan_cfg);
 	libertas_parse_type(buf, count, scan_cfg);
 
-	wlan_scan_networks(priv, scan_cfg);
+	wlan_scan_networks(priv, scan_cfg, 1);
 	wait_event_interruptible(priv->adapter->cmd_pending,
 				 !priv->adapter->nr_cmd_pending);
 
 	memset(&wrqu, 0x00, sizeof(union iwreq_data));
-	wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
+	wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
 
 out_unlock:
 	free_page(addr);
@@ -407,11 +389,11 @@
 	u16 wait_option = cmd_option_waitforrsp;
 
 	if (!(*cmdnode = libertas_get_free_cmd_ctrl_node(priv))) {
-		lbs_pr_debug(1, "failed libertas_get_free_cmd_ctrl_node\n");
+		lbs_deb_debugfs("failed libertas_get_free_cmd_ctrl_node\n");
 		return -ENOMEM;
 	}
 	if (!(*response_buf = kmalloc(3000, GFP_KERNEL))) {
-		lbs_pr_debug(1, "failed to allocate response buffer!\n");
+		lbs_deb_debugfs("failed to allocate response buffer!\n");
 		return -ENOMEM;
 	}
 	libertas_set_cmd_ctrl_node(priv, *cmdnode, 0, wait_option, NULL);
@@ -420,8 +402,8 @@
 	(*cmdnode)->cmdflags |= CMD_F_HOSTCMD;
 	(*cmdnode)->cmdwaitqwoken = 0;
 	*cmd = (struct cmd_ds_command *)(*cmdnode)->bufvirtualaddr;
-	(*cmd)->command = cmd_802_11_subscribe_event;
-	(*cmd)->seqnum = ++priv->adapter->seqnum;
+	(*cmd)->command = cpu_to_le16(cmd_802_11_subscribe_event);
+	(*cmd)->seqnum = cpu_to_le16(++priv->adapter->seqnum);
 	(*cmd)->result = 0;
 	return 0;
 }
@@ -447,26 +429,25 @@
 	}
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_get;
-	pcmdptr->size =
-	cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+	event->action = cpu_to_le16(cmd_act_get);
+	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -474,17 +455,17 @@
 	}
 
 	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-	while (cmd_len < pcmdptr->size) {
-		struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-		switch(header->type) {
+	event = (void *)(response_buf + S_DS_GEN);
+	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+		switch (header->type) {
 		struct mrvlietypes_rssithreshold  *Lowrssi;
-		case TLV_TYPE_RSSI_LOW:
-		Lowrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
-		pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-				Lowrssi->rssivalue,
-				Lowrssi->rssifreq,
-				(event->events & 0x0001)?1:0);
+		case __constant_cpu_to_le16(TLV_TYPE_RSSI_LOW):
+			Lowrssi = (void *)(response_buf + cmd_len);
+			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+					Lowrssi->rssivalue,
+					Lowrssi->rssifreq,
+					(event->events & cpu_to_le16(0x0001))?1:0);
 		default:
 			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
 			break;
@@ -512,21 +493,20 @@
 		return res;
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_get;
-	pcmdptr->size =
-	cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+	event->action = cpu_to_le16(cmd_act_get);
+	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		return 0;
 	}
@@ -538,7 +518,7 @@
 	}
 
 	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-	event_bitmap = event->events;
+	event_bitmap = le16_to_cpu(event->events);
 	kfree(response_buf);
 	return event_bitmap;
 }
@@ -579,7 +559,7 @@
 		goto out_unlock;
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_set;
+	event->action = cpu_to_le16(cmd_act_set);
 	pcmdptr->size = cpu_to_le16(S_DS_GEN +
 		sizeof(struct cmd_ds_802_11_subscribe_event) +
 		sizeof(struct mrvlietypes_rssithreshold));
@@ -588,30 +568,30 @@
 	ptr = (u8*) pcmdptr+cmd_len;
 	rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
 	rssi_threshold->header.type = cpu_to_le16(0x0104);
-	rssi_threshold->header.len = 2;
-	rssi_threshold->rssivalue = cpu_to_le16(value);
-	rssi_threshold->rssifreq = cpu_to_le16(freq);
+	rssi_threshold->header.len = cpu_to_le16(2);
+	rssi_threshold->rssivalue = value;
+	rssi_threshold->rssifreq = freq;
 	event_bitmap |= subscribed ? 0x0001 : 0x0;
-	event->events = event_bitmap;
+	event->events = cpu_to_le16(event_bitmap);
 
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -645,27 +625,26 @@
 	}
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_get;
-	pcmdptr->size =
-	cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+	event->action = cpu_to_le16(cmd_act_get);
+	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -673,17 +652,17 @@
 	}
 
 	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-	while (cmd_len < pcmdptr->size) {
-		struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-		switch(header->type) {
+	event = (void *)(response_buf + S_DS_GEN);
+	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+		switch (header->type) {
 		struct mrvlietypes_snrthreshold *LowSnr;
-		case TLV_TYPE_SNR_LOW:
-		LowSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
-		pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-				LowSnr->snrvalue,
-				LowSnr->snrfreq,
-				(event->events & 0x0002)?1:0);
+		case __constant_cpu_to_le16(TLV_TYPE_SNR_LOW):
+			LowSnr = (void *)(response_buf + cmd_len);
+			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+					LowSnr->snrvalue,
+					LowSnr->snrfreq,
+					(event->events & cpu_to_le16(0x0002))?1:0);
 		default:
 			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
 			break;
@@ -733,7 +712,7 @@
 		goto out_unlock;
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_set;
+	event->action = cpu_to_le16(cmd_act_set);
 	pcmdptr->size = cpu_to_le16(S_DS_GEN +
 		sizeof(struct cmd_ds_802_11_subscribe_event) +
 		sizeof(struct mrvlietypes_snrthreshold));
@@ -741,30 +720,30 @@
 	ptr = (u8*) pcmdptr+cmd_len;
 	snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
 	snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_LOW);
-	snr_threshold->header.len = 2;
-	snr_threshold->snrvalue = cpu_to_le16(value);
-	snr_threshold->snrfreq = cpu_to_le16(freq);
+	snr_threshold->header.len = cpu_to_le16(2);
+	snr_threshold->snrvalue = value;
+	snr_threshold->snrfreq = freq;
 	event_bitmap |= subscribed ? 0x0002 : 0x0;
-	event->events = event_bitmap;
+	event->events = cpu_to_le16(event_bitmap);
 
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -799,27 +778,26 @@
 	}
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_get;
-	pcmdptr->size =
-	cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+	event->action = cpu_to_le16(cmd_act_get);
+	pcmdptr->size =	cpu_to_le16(sizeof(*event) + S_DS_GEN);
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -827,17 +805,17 @@
 	}
 
 	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-	while (cmd_len < pcmdptr->size) {
-		struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-		switch(header->type) {
+	event = (void *)(response_buf + S_DS_GEN);
+	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+		switch (header->type) {
 		struct mrvlietypes_failurecount *failcount;
-		case TLV_TYPE_FAILCOUNT:
-		failcount = (struct mrvlietypes_failurecount *)(response_buf + cmd_len);
-		pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-				failcount->failvalue,
-				failcount->Failfreq,
-				(event->events & 0x0004)?1:0);
+		case __constant_cpu_to_le16(TLV_TYPE_FAILCOUNT):
+			failcount = (void *)(response_buf + cmd_len);
+			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+					failcount->failvalue,
+					failcount->Failfreq,
+					(event->events & cpu_to_le16(0x0004))?1:0);
 		default:
 			cmd_len += sizeof(struct mrvlietypes_failurecount);
 			break;
@@ -886,7 +864,7 @@
 		goto out_unlock;
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_set;
+	event->action = cpu_to_le16(cmd_act_set);
 	pcmdptr->size = cpu_to_le16(S_DS_GEN +
 		sizeof(struct cmd_ds_802_11_subscribe_event) +
 		sizeof(struct mrvlietypes_failurecount));
@@ -894,30 +872,30 @@
 	ptr = (u8*) pcmdptr+cmd_len;
 	failcount = (struct mrvlietypes_failurecount *)(ptr);
 	failcount->header.type = cpu_to_le16(TLV_TYPE_FAILCOUNT);
-	failcount->header.len = 2;
-	failcount->failvalue = cpu_to_le16(value);
-	failcount->Failfreq = cpu_to_le16(freq);
+	failcount->header.len = cpu_to_le16(2);
+	failcount->failvalue = value;
+	failcount->Failfreq = freq;
 	event_bitmap |= subscribed ? 0x0004 : 0x0;
-	event->events = event_bitmap;
+	event->events = cpu_to_le16(event_bitmap);
 
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = (struct cmd_ds_command *)response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -951,27 +929,26 @@
 	}
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_get;
-	pcmdptr->size =
-	cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+	event->action = cpu_to_le16(cmd_act_get);
+	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		free_page(addr);
 		kfree(response_buf);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		free_page(addr);
 		kfree(response_buf);
@@ -979,16 +956,16 @@
 	}
 
 	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-	while (cmd_len < pcmdptr->size) {
-		struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-		switch(header->type) {
+	event = (void *)(response_buf + S_DS_GEN);
+	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+		switch (header->type) {
 		struct mrvlietypes_beaconsmissed *bcnmiss;
-		case TLV_TYPE_BCNMISS:
-		bcnmiss = (struct mrvlietypes_beaconsmissed *)(response_buf + cmd_len);
-		pos += snprintf(buf+pos, len-pos, "%d N/A %d\n",
-				bcnmiss->beaconmissed,
-				(event->events & 0x0008)?1:0);
+		case __constant_cpu_to_le16(TLV_TYPE_BCNMISS):
+			bcnmiss = (void *)(response_buf + cmd_len);
+			pos += snprintf(buf+pos, len-pos, "%d N/A %d\n",
+					bcnmiss->beaconmissed,
+					(event->events & cpu_to_le16(0x0008))?1:0);
 		default:
 			cmd_len += sizeof(struct mrvlietypes_beaconsmissed);
 			break;
@@ -1038,7 +1015,7 @@
 		goto out_unlock;
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_set;
+	event->action = cpu_to_le16(cmd_act_set);
 	pcmdptr->size = cpu_to_le16(S_DS_GEN +
 		sizeof(struct cmd_ds_802_11_subscribe_event) +
 		sizeof(struct mrvlietypes_beaconsmissed));
@@ -1046,29 +1023,29 @@
 	ptr = (u8*) pcmdptr+cmd_len;
 	bcnmiss = (struct mrvlietypes_beaconsmissed *)(ptr);
 	bcnmiss->header.type = cpu_to_le16(TLV_TYPE_BCNMISS);
-	bcnmiss->header.len = 2;
-	bcnmiss->beaconmissed = cpu_to_le16(value);
+	bcnmiss->header.len = cpu_to_le16(2);
+	bcnmiss->beaconmissed = value;
 	event_bitmap |= subscribed ? 0x0008 : 0x0;
-	event->events = event_bitmap;
+	event->events = cpu_to_le16(event_bitmap);
 
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		free_page(addr);
 		kfree(response_buf);
@@ -1102,27 +1079,26 @@
 	}
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_get;
-	pcmdptr->size =
-	cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+	event->action = cpu_to_le16(cmd_act_get);
+	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -1130,17 +1106,17 @@
 	}
 
 	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-	while (cmd_len < pcmdptr->size) {
-		struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-		switch(header->type) {
+	event = (void *)(response_buf + S_DS_GEN);
+	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+		switch (header->type) {
 		struct mrvlietypes_rssithreshold  *Highrssi;
-		case TLV_TYPE_RSSI_HIGH:
-		Highrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
-		pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-				Highrssi->rssivalue,
-				Highrssi->rssifreq,
-				(event->events & 0x0010)?1:0);
+		case __constant_cpu_to_le16(TLV_TYPE_RSSI_HIGH):
+			Highrssi = (void *)(response_buf + cmd_len);
+			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+					Highrssi->rssivalue,
+					Highrssi->rssifreq,
+					(event->events & cpu_to_le16(0x0010))?1:0);
 		default:
 			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
 			break;
@@ -1190,7 +1166,7 @@
 		goto out_unlock;
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_set;
+	event->action = cpu_to_le16(cmd_act_set);
 	pcmdptr->size = cpu_to_le16(S_DS_GEN +
 		sizeof(struct cmd_ds_802_11_subscribe_event) +
 		sizeof(struct mrvlietypes_rssithreshold));
@@ -1198,29 +1174,29 @@
 	ptr = (u8*) pcmdptr+cmd_len;
 	rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
 	rssi_threshold->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
-	rssi_threshold->header.len = 2;
-	rssi_threshold->rssivalue = cpu_to_le16(value);
-	rssi_threshold->rssifreq = cpu_to_le16(freq);
+	rssi_threshold->header.len = cpu_to_le16(2);
+	rssi_threshold->rssivalue = value;
+	rssi_threshold->rssifreq = freq;
 	event_bitmap |= subscribed ? 0x0010 : 0x0;
-	event->events = event_bitmap;
+	event->events = cpu_to_le16(event_bitmap);
 
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		return 0;
@@ -1253,27 +1229,26 @@
 	}
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_get;
-	pcmdptr->size =
-	cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+	event->action = cpu_to_le16(cmd_act_get);
+	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -1281,17 +1256,17 @@
 	}
 
 	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
-	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
-	while (cmd_len < pcmdptr->size) {
-		struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
-		switch(header->type) {
+	event = (void *)(response_buf + S_DS_GEN);
+	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
+		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
+		switch (header->type) {
 		struct mrvlietypes_snrthreshold *HighSnr;
-		case TLV_TYPE_SNR_HIGH:
-		HighSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
-		pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
-				HighSnr->snrvalue,
-				HighSnr->snrfreq,
-				(event->events & 0x0020)?1:0);
+		case __constant_cpu_to_le16(TLV_TYPE_SNR_HIGH):
+			HighSnr = (void *)(response_buf + cmd_len);
+			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+					HighSnr->snrvalue,
+					HighSnr->snrfreq,
+					(event->events & cpu_to_le16(0x0020))?1:0);
 		default:
 			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
 			break;
@@ -1341,7 +1316,7 @@
 		goto out_unlock;
 
 	event = &pcmdptr->params.subscribe_event;
-	event->action = cmd_act_set;
+	event->action = cpu_to_le16(cmd_act_set);
 	pcmdptr->size = cpu_to_le16(S_DS_GEN +
 		sizeof(struct cmd_ds_802_11_subscribe_event) +
 		sizeof(struct mrvlietypes_snrthreshold));
@@ -1349,30 +1324,30 @@
 	ptr = (u8*) pcmdptr+cmd_len;
 	snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
 	snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_HIGH);
-	snr_threshold->header.len = 2;
-	snr_threshold->snrvalue = cpu_to_le16(value);
-	snr_threshold->snrfreq = cpu_to_le16(freq);
+	snr_threshold->header.len = cpu_to_le16(2);
+	snr_threshold->snrvalue = value;
+	snr_threshold->snrfreq = freq;
 	event_bitmap |= subscribed ? 0x0020 : 0x0;
-	event->events = event_bitmap;
+	event->events = cpu_to_le16(event_bitmap);
 
 	libertas_queue_cmd(adapter, pcmdnode, 1);
 	wake_up_interruptible(&priv->mainthread.waitq);
 
 	/* Sleep until response is generated by FW */
 	wait_event_interruptible(pcmdnode->cmdwait_q,
-				pcmdnode->cmdwaitqwoken);
+				 pcmdnode->cmdwaitqwoken);
 
 	pcmdptr = response_buf;
 
 	if (pcmdptr->result) {
-		lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
-			pcmdptr->result);
+		lbs_pr_err("%s: fail, result=%d\n", __func__,
+			   le16_to_cpu(pcmdptr->result));
 		kfree(response_buf);
 		free_page(addr);
 		return 0;
 	}
 
-	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
 		lbs_pr_err("command response incorrect!\n");
 		kfree(response_buf);
 		free_page(addr);
@@ -1760,7 +1735,7 @@
 
 	debugfs_remove(priv->regs_dir);
 
-	for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
+	for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
 		debugfs_remove(priv->debugfs_events_files[i]);
 
 	debugfs_remove(priv->events_dir);
@@ -1769,13 +1744,19 @@
 #endif
 	for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
 		debugfs_remove(priv->debugfs_files[i]);
+	debugfs_remove(priv->debugfs_dir);
 }
 
+
+
 /* debug entry */
 
+#ifdef PROC_DEBUG
+
 #define item_size(n)	(FIELD_SIZEOF(wlan_adapter, n))
 #define item_addr(n)	(offsetof(wlan_adapter, n))
 
+
 struct debug_data {
 	char name[32];
 	u32 size;
@@ -1863,7 +1844,7 @@
 		return 0;
 
 	if (copy_from_user(pdata, buf, cnt)) {
-		lbs_pr_debug(1, "Copy from user failed\n");
+		lbs_deb_debugfs("Copy from user failed\n");
 		kfree(pdata);
 		return 0;
 	}
@@ -1913,7 +1894,7 @@
  *  @param dev     pointer net_device
  *  @return 	   N/A
  */
-void libertas_debug_init(wlan_private * priv, struct net_device *dev)
+static void libertas_debug_init(wlan_private * priv, struct net_device *dev)
 {
 	int i;
 
@@ -1927,4 +1908,5 @@
 						  priv->debugfs_dir, &items[0],
 						  &libertas_debug_fops);
 }
+#endif
 
diff --git a/drivers/net/wireless/libertas/decl.h b/drivers/net/wireless/libertas/decl.h
index dfe2764..40f56bb 100644
--- a/drivers/net/wireless/libertas/decl.h
+++ b/drivers/net/wireless/libertas/decl.h
@@ -6,6 +6,8 @@
 #ifndef _WLAN_DECL_H_
 #define _WLAN_DECL_H_
 
+#include <linux/device.h>
+
 #include "defs.h"
 
 /** Function Prototype Declaration */
@@ -66,18 +68,24 @@
 
 void libertas_tx_runqueue(wlan_private *priv);
 
-extern struct chan_freq_power *libertas_find_cfp_by_band_and_channel(
+struct chan_freq_power *libertas_find_cfp_by_band_and_channel(
 				wlan_adapter * adapter, u8 band, u16 channel);
 
-extern void libertas_mac_event_disconnected(wlan_private * priv);
+void libertas_mac_event_disconnected(wlan_private * priv);
 
 void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str);
 
-int reset_device(wlan_private *priv);
+/* fw.c */
+int libertas_init_fw(wlan_private * priv, char *fw_name);
+
 /* main.c */
-extern struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band,
+struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band,
 						             int *cfp_no);
-wlan_private *wlan_add_card(void *card);
-int wlan_remove_card(void *card);
+wlan_private *libertas_add_card(void *card, struct device *dmdev);
+int libertas_activate_card(wlan_private *priv, char *fw_name);
+int libertas_remove_card(wlan_private *priv);
+int libertas_add_mesh(wlan_private *priv, struct device *dev);
+void libertas_remove_mesh(wlan_private *priv);
+
 
 #endif				/* _WLAN_DECL_H_ */
diff --git a/drivers/net/wireless/libertas/defs.h b/drivers/net/wireless/libertas/defs.h
index 80dd9ea..4dd43e5 100644
--- a/drivers/net/wireless/libertas/defs.h
+++ b/drivers/net/wireless/libertas/defs.h
@@ -7,14 +7,79 @@
 
 #include <linux/spinlock.h>
 
-extern unsigned int libertas_debug;
-
 #ifdef CONFIG_LIBERTAS_DEBUG
 #define DEBUG
 #define PROC_DEBUG
 #endif
 
-#define DRV_NAME		"usb8xxx"
+#ifndef DRV_NAME
+#define DRV_NAME "libertas"
+#endif
+
+
+#define LBS_DEB_ENTER	0x00000001
+#define LBS_DEB_LEAVE	0x00000002
+#define LBS_DEB_MAIN	0x00000004
+#define LBS_DEB_NET	0x00000008
+#define LBS_DEB_MESH	0x00000010
+#define LBS_DEB_WEXT	0x00000020
+#define LBS_DEB_IOCTL	0x00000040
+#define LBS_DEB_SCAN	0x00000080
+#define LBS_DEB_ASSOC	0x00000100
+#define LBS_DEB_JOIN	0x00000200
+#define LBS_DEB_11D	0x00000400
+#define LBS_DEB_DEBUGFS	0x00000800
+#define LBS_DEB_ETHTOOL	0x00001000
+#define LBS_DEB_HOST	0x00002000
+#define LBS_DEB_CMD	0x00004000
+#define LBS_DEB_RX	0x00008000
+#define LBS_DEB_TX	0x00010000
+#define LBS_DEB_USB	0x00020000
+#define LBS_DEB_CS	0x00040000
+#define LBS_DEB_FW	0x00080000
+#define LBS_DEB_THREAD	0x00100000
+#define LBS_DEB_HEX	0x00200000
+
+extern unsigned int libertas_debug;
+
+#ifdef DEBUG
+#define LBS_DEB_LL(grp, fmt, args...) \
+do { if ((libertas_debug & (grp)) == (grp)) \
+  printk(KERN_DEBUG DRV_NAME "%s: " fmt, \
+         in_interrupt() ? " (INT)" : "", ## args); } while (0)
+#else
+#define LBS_DEB_LL(grp, fmt, args...) do {} while (0)
+#endif
+
+#define lbs_deb_enter(grp) \
+  LBS_DEB_LL(grp | LBS_DEB_ENTER, "%s():%d enter\n", __FUNCTION__, __LINE__);
+#define lbs_deb_enter_args(grp, fmt, args...) \
+  LBS_DEB_LL(grp | LBS_DEB_ENTER, "%s(" fmt "):%d\n", __FUNCTION__, ## args, __LINE__);
+#define lbs_deb_leave(grp) \
+  LBS_DEB_LL(grp | LBS_DEB_LEAVE, "%s():%d leave\n", __FUNCTION__, __LINE__);
+#define lbs_deb_leave_args(grp, fmt, args...) \
+  LBS_DEB_LL(grp | LBS_DEB_LEAVE, "%s():%d leave, " fmt "\n", \
+  __FUNCTION__, __LINE__, ##args);
+#define lbs_deb_main(fmt, args...)      LBS_DEB_LL(LBS_DEB_MAIN, fmt, ##args)
+#define lbs_deb_net(fmt, args...)       LBS_DEB_LL(LBS_DEB_NET, fmt, ##args)
+#define lbs_deb_mesh(fmt, args...)      LBS_DEB_LL(LBS_DEB_MESH, fmt, ##args)
+#define lbs_deb_wext(fmt, args...)      LBS_DEB_LL(LBS_DEB_WEXT, fmt, ##args)
+#define lbs_deb_ioctl(fmt, args...)     LBS_DEB_LL(LBS_DEB_IOCTL, fmt, ##args)
+#define lbs_deb_scan(fmt, args...)      LBS_DEB_LL(LBS_DEB_SCAN, fmt, ##args)
+#define lbs_deb_assoc(fmt, args...)     LBS_DEB_LL(LBS_DEB_ASSOC, fmt, ##args)
+#define lbs_deb_join(fmt, args...)      LBS_DEB_LL(LBS_DEB_JOIN, fmt, ##args)
+#define lbs_deb_11d(fmt, args...)       LBS_DEB_LL(LBS_DEB_11D, fmt, ##args)
+#define lbs_deb_debugfs(fmt, args...)   LBS_DEB_LL(LBS_DEB_DEBUGFS, fmt, ##args)
+#define lbs_deb_ethtool(fmt, args...)   LBS_DEB_LL(LBS_DEB_ETHTOOL, fmt, ##args)
+#define lbs_deb_host(fmt, args...)      LBS_DEB_LL(LBS_DEB_HOST, fmt, ##args)
+#define lbs_deb_cmd(fmt, args...)       LBS_DEB_LL(LBS_DEB_CMD, fmt, ##args)
+#define lbs_deb_rx(fmt, args...)        LBS_DEB_LL(LBS_DEB_RX, fmt, ##args)
+#define lbs_deb_tx(fmt, args...)        LBS_DEB_LL(LBS_DEB_TX, fmt, ##args)
+#define lbs_deb_fw(fmt, args...)        LBS_DEB_LL(LBS_DEB_FW, fmt, ##args)
+#define lbs_deb_usb(fmt, args...)       LBS_DEB_LL(LBS_DEB_USB, fmt, ##args)
+#define lbs_deb_usbd(dev, fmt, args...) LBS_DEB_LL(LBS_DEB_USB, "%s:" fmt, (dev)->bus_id, ##args)
+#define lbs_deb_cs(fmt, args...)        LBS_DEB_LL(LBS_DEB_CS, fmt, ##args)
+#define lbs_deb_thread(fmt, args...)    LBS_DEB_LL(LBS_DEB_THREAD, fmt, ##args)
 
 #define lbs_pr_info(format, args...) \
 	printk(KERN_INFO DRV_NAME": " format, ## args)
@@ -24,37 +89,25 @@
 	printk(KERN_ALERT DRV_NAME": " format, ## args)
 
 #ifdef DEBUG
-#define lbs_pr_debug(level, format, args...) \
-	do { if (libertas_debug >= level) \
-	printk(KERN_INFO DRV_NAME": " format, ##args); } while (0)
-#define lbs_dev_dbg(level, device, format, args...) \
-        lbs_pr_debug(level, "%s: " format, \
-        (device)->bus_id , ## args)
-
 static inline void lbs_dbg_hex(char *prompt, u8 * buf, int len)
 {
 	int i = 0;
 
-	if (!libertas_debug)
+	if (!(libertas_debug & LBS_DEB_HEX))
 		return;
 
 	printk(KERN_DEBUG "%s: ", prompt);
 	for (i = 1; i <= len; i++) {
-		printk(KERN_DEBUG "%02x ", (u8) * buf);
+		printk("%02x ", (u8) * buf);
 		buf++;
 	}
 	printk("\n");
 }
 #else
-#define lbs_pr_debug(level, format, args...)		do {} while (0)
-#define lbs_dev_dbg(level, device, format, args...)	do {} while (0)
 #define lbs_dbg_hex(x,y,z)				do {} while (0)
 #endif
 
-#define	ENTER()			lbs_pr_debug(1, "Enter: %s, %s:%i\n", \
-					__FUNCTION__, __FILE__, __LINE__)
-#define	LEAVE()			lbs_pr_debug(1, "Leave: %s, %s:%i\n", \
-					__FUNCTION__, __FILE__, __LINE__)
+
 
 /** Buffer Constants */
 
@@ -74,7 +127,6 @@
 #define MRVDRV_NUM_OF_CMD_BUFFER        10
 #define MRVDRV_SIZE_OF_CMD_BUFFER       (2 * 1024)
 #define MRVDRV_MAX_CHANNEL_SIZE		14
-#define MRVDRV_MAX_BSSID_LIST		64
 #define MRVDRV_ASSOCIATION_TIME_OUT	255
 #define MRVDRV_SNAP_HEADER_LEN          8
 
@@ -104,6 +156,13 @@
 #define MRVDRV_MAX_BEACON_INTERVAL		1000
 #define MRVDRV_BEACON_INTERVAL			100
 
+/** INT status Bit Definition*/
+#define his_cmddnldrdy			0x01
+#define his_cardevent			0x02
+#define his_cmdupldrdy			0x04
+
+#define SBI_EVENT_CAUSE_SHIFT		3
+
 /** TxPD status */
 
 /*	Station firmware use TxPD status field to report final Tx transmit
@@ -205,8 +264,6 @@
 extern const char libertas_driver_version[];
 extern u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE];
 
-extern u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES];
-
 extern u8 libertas_supported_rates[G_SUPPORTED_RATES];
 
 extern u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES];
@@ -316,6 +373,8 @@
 /* Default values for fwt commands. */
 #define FWT_DEFAULT_METRIC 0
 #define FWT_DEFAULT_DIR 1
+/* Default Rate, 11Mbps */
+#define FWT_DEFAULT_RATE 3
 #define FWT_DEFAULT_SSN 0xffffffff
 #define FWT_DEFAULT_DSN 0
 #define FWT_DEFAULT_HOPCOUNT 0
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index e8b9020..785192b 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -63,11 +63,11 @@
 
 /** Current Basic Service Set State Structure */
 struct current_bss_params {
-	struct bss_descriptor bssdescriptor;
 	/** bssid */
 	u8 bssid[ETH_ALEN];
 	/** ssid */
-	struct WLAN_802_11_SSID ssid;
+	u8 ssid[IW_ESSID_MAX_SIZE + 1];
+	u8 ssid_len;
 
 	/** band */
 	u8 band;
@@ -89,31 +89,6 @@
 	u16 sp_reserved;
 };
 
-/** Data structure for the Marvell WLAN device */
-typedef struct _wlan_dev {
-	/** device name */
-	char name[DEV_NAME_LEN];
-	/** card pointer */
-	void *card;
-	/** IO port */
-	u32 ioport;
-	/** Upload received */
-	u32 upld_rcv;
-	/** Upload type */
-	u32 upld_typ;
-	/** Upload length */
-	u32 upld_len;
-	/** netdev pointer */
-	struct net_device *netdev;
-	/* Upload buffer */
-	u8 upld_buf[WLAN_UPLD_SIZE];
-	/* Download sent:
-	   bit0 1/0=data_sent/data_tx_done,
-	   bit1 1/0=cmd_sent/cmd_tx_done,
-	   all other bits reserved 0 */
-	u8 dnld_sent;
-} wlan_dev_t, *pwlan_dev_t;
-
 /* Mesh statistics */
 struct wlan_mesh_stats {
 	u32	fwd_bcast_cnt;		/* Fwd: Broadcast counter */
@@ -123,6 +98,7 @@
 	u32	fwd_drop_noroute; 	/* Fwd: No route to Destination */
 	u32	fwd_drop_nobuf;		/* Fwd: Run out of internal buffers */
 	u32	drop_blind;		/* Rx:  Dropped by blinding table */
+	u32	tx_failed_cnt;		/* Tx:  Failed transmissions */
 };
 
 /** Private structure for the MV device */
@@ -131,8 +107,11 @@
 	int mesh_open;
 	int infra_open;
 
+	char name[DEV_NAME_LEN];
+
+	void *card;
 	wlan_adapter *adapter;
-	wlan_dev_t wlan_dev;
+	struct net_device *dev;
 
 	struct net_device_stats stats;
 	struct net_device *mesh_dev ; /* Virtual device */
@@ -153,6 +132,16 @@
 	u32 bbp_offset;
 	u32 rf_offset;
 
+	/** Upload length */
+	u32 upld_len;
+	/* Upload buffer */
+	u8 upld_buf[WLAN_UPLD_SIZE];
+	/* Download sent:
+	   bit0 1/0=data_sent/data_tx_done,
+	   bit1 1/0=cmd_sent/cmd_tx_done,
+	   all other bits reserved 0 */
+	u8 dnld_sent;
+
 	const struct firmware *firmware;
 	struct device *hotplug_device;
 
@@ -161,6 +150,15 @@
 
 	struct delayed_work assoc_work;
 	struct workqueue_struct *assoc_thread;
+	struct work_struct sync_channel;
+
+	/** Hardware access */
+	int (*hw_register_dev) (wlan_private * priv);
+	int (*hw_unregister_dev) (wlan_private *);
+	int (*hw_prog_firmware) (wlan_private *);
+	int (*hw_host_to_card) (wlan_private * priv, u8 type, u8 * payload, u16 nb);
+	int (*hw_get_int_status) (wlan_private * priv, u8 *);
+	int (*hw_read_event_cause) (wlan_private *);
 };
 
 /** Association request
@@ -171,18 +169,21 @@
 struct assoc_request {
 #define ASSOC_FLAG_SSID			1
 #define ASSOC_FLAG_CHANNEL		2
-#define ASSOC_FLAG_MODE			3
-#define ASSOC_FLAG_BSSID		4
-#define ASSOC_FLAG_WEP_KEYS		5
-#define ASSOC_FLAG_WEP_TX_KEYIDX	6
-#define ASSOC_FLAG_WPA_MCAST_KEY	7
-#define ASSOC_FLAG_WPA_UCAST_KEY	8
-#define ASSOC_FLAG_SECINFO		9
-#define ASSOC_FLAG_WPA_IE		10
+#define ASSOC_FLAG_BAND			3
+#define ASSOC_FLAG_MODE			4
+#define ASSOC_FLAG_BSSID		5
+#define ASSOC_FLAG_WEP_KEYS		6
+#define ASSOC_FLAG_WEP_TX_KEYIDX	7
+#define ASSOC_FLAG_WPA_MCAST_KEY	8
+#define ASSOC_FLAG_WPA_UCAST_KEY	9
+#define ASSOC_FLAG_SECINFO		10
+#define ASSOC_FLAG_WPA_IE		11
 	unsigned long flags;
 
-	struct WLAN_802_11_SSID ssid;
+	u8 ssid[IW_ESSID_MAX_SIZE + 1];
+	u8 ssid_len;
 	u8 channel;
+	u8 band;
 	u8 mode;
 	u8 bssid[ETH_ALEN];
 
@@ -199,12 +200,15 @@
 	/** WPA Information Elements*/
 	u8 wpa_ie[MAX_WPA_IE_LEN];
 	u8 wpa_ie_len;
+
+	/* BSS to associate with for infrastructure of Ad-Hoc join */
+	struct bss_descriptor bss;
 };
 
 /** Wlan adapter data structure*/
 struct _wlan_adapter {
 	/** STATUS variables */
-	u32 fwreleasenumber;
+	u8 fwreleasenumber[4];
 	u32 fwcapinfo;
 	/* protected with big lock */
 
@@ -255,13 +259,14 @@
 	/* IW_MODE_* */
 	u8 mode;
 
-	struct bss_descriptor *pattemptedbssdesc;
+	u8 prev_ssid[IW_ESSID_MAX_SIZE + 1];
+	u8 prev_ssid_len;
+	u8 prev_bssid[ETH_ALEN];
 
-	struct WLAN_802_11_SSID previousssid;
-	u8 previousbssid[ETH_ALEN];
-
-	struct bss_descriptor *scantable;
-	u32 numinscantable;
+	/* Scan results list */
+	struct list_head network_list;
+	struct list_head network_free_list;
+	struct bss_descriptor *networks;
 
 	u8 scantype;
 	u32 scanmode;
@@ -288,7 +293,6 @@
 	u32 txantenna;
 	u32 rxantenna;
 
-	u8 adhocchannel;
 	u32 fragthsd;
 	u32 rtsthsd;
 
@@ -324,7 +328,8 @@
 	u16 locallisteninterval;
 	u16 nullpktinterval;
 
-	struct assoc_request * assoc_req;
+	struct assoc_request * pending_assoc_req;
+	struct assoc_request * in_progress_assoc_req;
 
 	/** Encryption parameter */
 	struct wlan_802_11_security secinfo;
@@ -396,6 +401,8 @@
 	u32 radiomode;
 	u32 debugmode;
 	u8 fw_ready;
+
+	u8 last_scanned_channel;
 };
 
 #endif				/* _WLAN_DEV_H_ */
diff --git a/drivers/net/wireless/libertas/ethtool.c b/drivers/net/wireless/libertas/ethtool.c
index 0064de5..96f1974 100644
--- a/drivers/net/wireless/libertas/ethtool.c
+++ b/drivers/net/wireless/libertas/ethtool.c
@@ -1,10 +1,8 @@
-
 #include <linux/netdevice.h>
 #include <linux/ethtool.h>
 #include <linux/delay.h>
 
 #include "host.h"
-#include "sbi.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
@@ -17,7 +15,8 @@
 			"drop_no_buffers",
 			"fwded_unicast_cnt",
 			"fwded_bcast_cnt",
-			"drop_blind_table"
+			"drop_blind_table",
+			"tx_failed_cnt"
 };
 
 static void libertas_ethtool_get_drvinfo(struct net_device *dev,
@@ -69,7 +68,7 @@
 
 	/* +14 is for action, offset, and NOB in
 	 * response */
-	lbs_pr_debug(1, "action:%d offset: %x NOB: %02x\n",
+	lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
 	       regctrl.action, regctrl.offset, regctrl.NOB);
 
 	ret = libertas_prepare_and_send_command(priv,
@@ -81,8 +80,7 @@
 	if (ret) {
 		if (adapter->prdeeprom)
 			kfree(adapter->prdeeprom);
-		LEAVE();
-			return ret;
+		goto done;
 	}
 
 	mdelay(10);
@@ -101,7 +99,11 @@
 		kfree(adapter->prdeeprom);
 //	mutex_unlock(&priv->mutex);
 
-        return 0;
+	ret = 0;
+
+done:
+	lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
+        return ret;
 }
 
 static void libertas_ethtool_get_stats(struct net_device * dev,
@@ -109,7 +111,7 @@
 {
 	wlan_private *priv = dev->priv;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ETHTOOL);
 
 	stats->cmd = ETHTOOL_GSTATS;
 	BUG_ON(stats->n_stats != MESH_STATS_NUM);
@@ -121,8 +123,9 @@
         data[4] = priv->mstats.fwd_unicast_cnt;
         data[5] = priv->mstats.fwd_bcast_cnt;
         data[6] = priv->mstats.drop_blind;
+        data[7] = priv->mstats.tx_failed_cnt;
 
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_ETHTOOL);
 }
 
 static int libertas_ethtool_get_stats_count(struct net_device * dev)
@@ -131,27 +134,32 @@
 	wlan_private *priv = dev->priv;
 	struct cmd_ds_mesh_access mesh_access;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ETHTOOL);
+
 	/* Get Mesh Statistics */
 	ret = libertas_prepare_and_send_command(priv,
 			cmd_mesh_access, cmd_act_mesh_get_stats,
 			cmd_option_waitforrsp, 0, &mesh_access);
 
 	if (ret) {
-		LEAVE();
-		return 0;
+		ret = 0;
+		goto done;
 	}
 
-        priv->mstats.fwd_drop_rbt = mesh_access.data[0];
-        priv->mstats.fwd_drop_ttl = mesh_access.data[1];
-        priv->mstats.fwd_drop_noroute = mesh_access.data[2];
-        priv->mstats.fwd_drop_nobuf = mesh_access.data[3];
-        priv->mstats.fwd_unicast_cnt = mesh_access.data[4];
-        priv->mstats.fwd_bcast_cnt = mesh_access.data[5];
-        priv->mstats.drop_blind = mesh_access.data[6];
+        priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
+        priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
+        priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
+        priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
+        priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
+        priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
+        priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
+        priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
 
-	LEAVE();
-	return MESH_STATS_NUM;
+	ret = MESH_STATS_NUM;
+
+done:
+	lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
+	return ret;
 }
 
 static void libertas_ethtool_get_strings (struct net_device * dev,
@@ -160,7 +168,8 @@
 {
 	int i;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ETHTOOL);
+
 	switch (stringset) {
         case ETH_SS_STATS:
 		for (i=0; i < MESH_STATS_NUM; i++) {
@@ -170,7 +179,7 @@
 		}
 		break;
         }
-	LEAVE();
+	lbs_deb_enter(LBS_DEB_ETHTOOL);
 }
 
 struct ethtool_ops libertas_ethtool_ops = {
diff --git a/drivers/net/wireless/libertas/fw.c b/drivers/net/wireless/libertas/fw.c
index 5c63c9b..2dc84ff 100644
--- a/drivers/net/wireless/libertas/fw.c
+++ b/drivers/net/wireless/libertas/fw.c
@@ -1,28 +1,15 @@
 /**
   * This file contains the initialization for FW and HW
   */
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-
-#include <linux/vmalloc.h>
 #include <linux/firmware.h>
-#include <linux/version.h>
 
 #include "host.h"
-#include "sbi.h"
 #include "defs.h"
 #include "decl.h"
 #include "dev.h"
-#include "fw.h"
 #include "wext.h"
 #include "if_usb.h"
 
-char *libertas_fw_name = NULL;
-module_param_named(fw_name, libertas_fw_name, charp, 0644);
-
-unsigned int libertas_debug = 0;
-module_param(libertas_debug, int, 0);
-
 /**
  *  @brief This function checks the validity of Boot2/FW image.
  *
@@ -32,7 +19,7 @@
  */
 static int check_fwfile_format(u8 *data, u32 totlen)
 {
-	u8  bincmd, exit;
+	u32 bincmd, exit;
 	u32 blksize, offset, len;
 	int ret;
 
@@ -40,8 +27,10 @@
 	exit = len = 0;
 
 	do {
-		bincmd = *data;
-		blksize = *(u32*)(data + offsetof(struct fwheader, datalength));
+		struct fwheader *fwh = (void *)data;
+
+		bincmd = le32_to_cpu(fwh->dnldcmd);
+		blksize = le32_to_cpu(fwh->datalength);
 		switch (bincmd) {
 		case FW_HAS_DATA_TO_RECV:
 			offset = sizeof(struct fwheader) + blksize;
@@ -61,9 +50,9 @@
 	} while (!exit);
 
 	if (ret)
-		lbs_pr_err("bin file format check FAIL...\n");
+		lbs_pr_err("firmware file format check FAIL\n");
 	else
-		lbs_pr_debug(1, "bin file format check PASS...\n");
+		lbs_deb_fw("firmware file format check PASS\n");
 
 	return ret;
 }
@@ -76,32 +65,31 @@
  *  @param priv    A pointer to wlan_private structure
  *  @return 	   0 or -1
  */
-static int wlan_setup_station_hw(wlan_private * priv)
+static int wlan_setup_station_hw(wlan_private * priv, char *fw_name)
 {
 	int ret = -1;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_FW);
 
-	if ((ret = request_firmware(&priv->firmware, libertas_fw_name,
+	if ((ret = request_firmware(&priv->firmware, fw_name,
 				    priv->hotplug_device)) < 0) {
-		lbs_pr_err("request_firmware() failed, error code = %#x\n",
-		       ret);
-		lbs_pr_err("%s not found in /lib/firmware\n", libertas_fw_name);
+		lbs_pr_err("request_firmware() failed with %#x\n", ret);
+		lbs_pr_err("firmware %s not found\n", fw_name);
 		goto done;
 	}
 
-	if(check_fwfile_format(priv->firmware->data, priv->firmware->size)) {
+	if (check_fwfile_format(priv->firmware->data, priv->firmware->size)) {
 		release_firmware(priv->firmware);
 		goto done;
 	}
 
-	ret = libertas_sbi_prog_firmware(priv);
+	ret = priv->hw_prog_firmware(priv);
 
 	release_firmware(priv->firmware);
 
 	if (ret) {
-		lbs_pr_debug(1, "Bootloader in invalid state!\n");
+		lbs_deb_fw("bootloader in invalid state\n");
 		ret = -1;
 		goto done;
 	}
@@ -133,28 +121,24 @@
 
 	ret = 0;
 done:
-	LEAVE();
-
-	return (ret);
+	lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
+	return ret;
 }
 
 static int wlan_allocate_adapter(wlan_private * priv)
 {
-	u32 ulbufsize;
+	size_t bufsize;
 	wlan_adapter *adapter = priv->adapter;
 
-	struct bss_descriptor *ptempscantable;
-
 	/* Allocate buffer to store the BSSID list */
-	ulbufsize = sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST;
-	if (!(ptempscantable = kmalloc(ulbufsize, GFP_KERNEL))) {
+	bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
+	adapter->networks = kzalloc(bufsize, GFP_KERNEL);
+	if (!adapter->networks) {
+		lbs_pr_err("Out of memory allocating beacons\n");
 		libertas_free_adapter(priv);
-		return -1;
+		return -ENOMEM;
 	}
 
-	adapter->scantable = ptempscantable;
-	memset(adapter->scantable, 0, ulbufsize);
-
 	/* Allocate the command buffers */
 	libertas_allocate_cmd_buffer(priv);
 
@@ -202,15 +186,23 @@
 	adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
 	adapter->mode = IW_MODE_INFRA;
 
-	adapter->assoc_req = NULL;
+	adapter->pending_assoc_req = NULL;
+	adapter->in_progress_assoc_req = NULL;
 
-	adapter->numinscantable = 0;
-	adapter->pattemptedbssdesc = NULL;
+	/* Initialize scan result lists */
+	INIT_LIST_HEAD(&adapter->network_free_list);
+	INIT_LIST_HEAD(&adapter->network_list);
+	for (i = 0; i < MAX_NETWORK_COUNT; i++) {
+		list_add_tail(&adapter->networks[i].list,
+			      &adapter->network_free_list);
+	}
+
 	mutex_init(&adapter->lock);
 
 	adapter->prescan = 1;
 
 	memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
+	adapter->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
 
 	/* PnP and power profile */
 	adapter->surpriseremoved = 0;
@@ -230,8 +222,6 @@
 	memset(&adapter->capinfo, 0, sizeof(adapter->capinfo));
 	adapter->capinfo.shortpreamble = SHORT_PREAMBLE_ALLOWED;
 
-	adapter->adhocchannel = DEFAULT_AD_HOC_CHANNEL;
-
 	adapter->psmode = wlan802_11powermodecam;
 	adapter->multipledtim = MRVDRV_DEFAULT_MULTIPLE_DTIM;
 
@@ -259,12 +249,12 @@
 
 static void command_timer_fn(unsigned long data);
 
-int libertas_init_fw(wlan_private * priv)
+int libertas_init_fw(wlan_private * priv, char *fw_name)
 {
 	int ret = -1;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_FW);
 
 	/* Allocate adapter structure */
 	if ((ret = wlan_allocate_adapter(priv)) != 0)
@@ -278,7 +268,7 @@
 			(unsigned long)priv);
 
 	/* download fimrware etc. */
-	if ((ret = wlan_setup_station_hw(priv)) != 0) {
+	if ((ret = wlan_setup_station_hw(priv, fw_name)) != 0) {
 		del_timer_sync(&adapter->command_timer);
 		goto done;
 	}
@@ -288,7 +278,7 @@
 
 	ret = 0;
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
 	return ret;
 }
 
@@ -297,25 +287,22 @@
 	wlan_adapter *adapter = priv->adapter;
 
 	if (!adapter) {
-		lbs_pr_debug(1, "Why double free adapter?:)\n");
+		lbs_deb_fw("why double free adapter?\n");
 		return;
 	}
 
-	lbs_pr_debug(1, "Free command buffer\n");
+	lbs_deb_fw("free command buffer\n");
 	libertas_free_cmd_buffer(priv);
 
-	lbs_pr_debug(1, "Free commandTimer\n");
+	lbs_deb_fw("free command_timer\n");
 	del_timer(&adapter->command_timer);
 
-	lbs_pr_debug(1, "Free scantable\n");
-	if (adapter->scantable) {
-		kfree(adapter->scantable);
-		adapter->scantable = NULL;
-	}
-
-	lbs_pr_debug(1, "Free adapter\n");
+	lbs_deb_fw("free scan results table\n");
+	kfree(adapter->networks);
+	adapter->networks = NULL;
 
 	/* Free the adapter object itself */
+	lbs_deb_fw("free adapter\n");
 	kfree(adapter);
 	priv->adapter = NULL;
 }
@@ -334,17 +321,17 @@
 
 	ptempnode = adapter->cur_cmd;
 	if (ptempnode == NULL) {
-		lbs_pr_debug(1, "PTempnode Empty\n");
+		lbs_deb_fw("ptempnode empty\n");
 		return;
 	}
 
 	cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
 	if (!cmd) {
-		lbs_pr_debug(1, "cmd is NULL\n");
+		lbs_deb_fw("cmd is NULL\n");
 		return;
 	}
 
-	lbs_pr_info("command_timer_fn fired (%x)\n", cmd->command);
+	lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
 
 	if (!adapter->fw_ready)
 		return;
@@ -353,7 +340,7 @@
 	adapter->cur_cmd = NULL;
 	spin_unlock_irqrestore(&adapter->driver_lock, flags);
 
-	lbs_pr_debug(1, "Re-sending same command as it timeout...!\n");
+	lbs_deb_fw("re-sending same command because of timeout\n");
 	libertas_queue_cmd(adapter, ptempnode, 0);
 
 	wake_up_interruptible(&priv->mainthread.waitq);
diff --git a/drivers/net/wireless/libertas/fw.h b/drivers/net/wireless/libertas/fw.h
deleted file mode 100644
index 1f9ae26..0000000
--- a/drivers/net/wireless/libertas/fw.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
-  * This header file contains FW interface related definitions.
-  */
-#ifndef _WLAN_FW_H_
-#define _WLAN_FW_H_
-
-#ifndef DEV_NAME_LEN
-#define DEV_NAME_LEN            32
-#endif
-
-int libertas_init_fw(wlan_private * priv);
-
-#endif				/* _WLAN_FW_H_ */
diff --git a/drivers/net/wireless/libertas/host.h b/drivers/net/wireless/libertas/host.h
index c0faaec..7509cc1 100644
--- a/drivers/net/wireless/libertas/host.h
+++ b/drivers/net/wireless/libertas/host.h
@@ -99,11 +99,11 @@
 #define cmd_bt_access                 0x0087
 #define cmd_ret_bt_access                 0x8087
 
-#define cmd_fwt_access                0x0088
-#define cmd_ret_fwt_access                0x8088
+#define cmd_fwt_access                0x0095
+#define cmd_ret_fwt_access                0x8095
 
-#define cmd_mesh_access               0x0090
-#define cmd_ret_mesh_access               0x8090
+#define cmd_mesh_access               0x009b
+#define cmd_ret_mesh_access               0x809b
 
 /* For the IEEE Power Save */
 #define cmd_subcmd_enter_ps               0x0030
@@ -287,7 +287,9 @@
 	cmd_act_bt_access_add = 5,
 	cmd_act_bt_access_del,
 	cmd_act_bt_access_list,
-	cmd_act_bt_access_reset
+	cmd_act_bt_access_reset,
+	cmd_act_bt_access_set_invert,
+	cmd_act_bt_access_get_invert
 };
 
 /* Define action or option for cmd_fwt_access */
@@ -308,8 +310,8 @@
 	cmd_act_mesh_get_ttl = 1,
 	cmd_act_mesh_set_ttl,
 	cmd_act_mesh_get_stats,
-	cmd_act_mesh_get_mpp,
-	cmd_act_mesh_set_mpp,
+	cmd_act_mesh_get_anycast,
+	cmd_act_mesh_set_anycast,
 };
 
 /** Card Event definition */
@@ -334,5 +336,6 @@
 #define MACREG_INT_CODE_MAX_FAIL		0x0000001b
 #define MACREG_INT_CODE_RSSI_HIGH		0x0000001c
 #define MACREG_INT_CODE_SNR_HIGH		0x0000001d
+#define MACREG_INT_CODE_MESH_AUTO_STARTED	0x00000023
 
 #endif				/* _HOST_H_ */
diff --git a/drivers/net/wireless/libertas/hostcmd.h b/drivers/net/wireless/libertas/hostcmd.h
index f239e5d..3acf939 100644
--- a/drivers/net/wireless/libertas/hostcmd.h
+++ b/drivers/net/wireless/libertas/hostcmd.h
@@ -14,12 +14,12 @@
 /* TxPD descriptor */
 struct txpd {
 	/* Current Tx packet status */
-	u32 tx_status;
+	__le32 tx_status;
 	/* Tx control */
-	u32 tx_control;
-	u32 tx_packet_location;
+	__le32 tx_control;
+	__le32 tx_packet_location;
 	/* Tx packet length */
-	u16 tx_packet_length;
+	__le16 tx_packet_length;
 	/* First 2 byte of destination MAC address */
 	u8 tx_dest_addr_high[2];
 	/* Last 4 byte of destination MAC address */
@@ -37,7 +37,7 @@
 /* RxPD Descriptor */
 struct rxpd {
 	/* Current Rx packet status */
-	u16 status;
+	__le16 status;
 
 	/* SNR */
 	u8 snr;
@@ -46,7 +46,7 @@
 	u8 rx_control;
 
 	/* Pkt length */
-	u16 pkt_len;
+	__le16 pkt_len;
 
 	/* Noise Floor */
 	u8 nf;
@@ -55,10 +55,10 @@
 	u8 rx_rate;
 
 	/* Pkt addr */
-	u32 pkt_ptr;
+	__le32 pkt_ptr;
 
 	/* Next Rx RxPD addr */
-	u32 next_rxpd_ptr;
+	__le32 next_rxpd_ptr;
 
 	/* Pkt Priority */
 	u8 priority;
@@ -89,30 +89,17 @@
  * is determined from the keylength field.
  */
 struct WLAN_802_11_KEY {
-	u32 len;
-	u32 flags;  /* KEY_INFO_* from wlan_defs.h */
+	__le32 len;
+	__le32 flags;  /* KEY_INFO_* from wlan_defs.h */
 	u8 key[MRVL_MAX_KEY_WPA_KEY_LENGTH];
-	u16 type; /* KEY_TYPE_* from wlan_defs.h */
+	__le16 type; /* KEY_TYPE_* from wlan_defs.h */
 };
 
 struct IE_WPA {
 	u8 elementid;
 	u8 len;
 	u8 oui[4];
-	u16 version;
-};
-
-struct WLAN_802_11_SSID {
-	/* SSID length */
-	u32 ssidlength;
-
-	/* SSID information field */
-	u8 ssid[IW_ESSID_MAX_SIZE];
-};
-
-struct WPA_SUPPLICANT {
-	u8 wpa_ie[256];
-	u8 wpa_ie_len;
+	__le16 version;
 };
 
 /* wlan_offset_value */
@@ -122,9 +109,9 @@
 };
 
 struct WLAN_802_11_FIXED_IEs {
-	u8 timestamp[8];
-	u16 beaconinterval;
-	u16 capabilities;
+	__le64 timestamp;
+	__le16 beaconinterval;
+	u16 capabilities; /* Actually struct ieeetypes_capinfo */
 };
 
 struct WLAN_802_11_VARIABLE_IEs {
@@ -136,10 +123,10 @@
 /* Define general data structure */
 /* cmd_DS_GEN */
 struct cmd_ds_gen {
-	u16 command;
-	u16 size;
-	u16 seqnum;
-	u16 result;
+	__le16 command;
+	__le16 size;
+	__le16 seqnum;
+	__le16 result;
 };
 
 #define S_DS_GEN sizeof(struct cmd_ds_gen)
@@ -149,44 +136,44 @@
  */
 struct cmd_ds_get_hw_spec {
 	/* HW Interface version number */
-	u16 hwifversion;
+	__le16 hwifversion;
 	/* HW version number */
-	u16 version;
+	__le16 version;
 	/* Max number of TxPD FW can handle */
-	u16 nr_txpd;
+	__le16 nr_txpd;
 	/* Max no of Multicast address */
-	u16 nr_mcast_adr;
+	__le16 nr_mcast_adr;
 	/* MAC address */
 	u8 permanentaddr[6];
 
 	/* region Code */
-	u16 regioncode;
+	__le16 regioncode;
 
 	/* Number of antenna used */
-	u16 nr_antenna;
+	__le16 nr_antenna;
 
-	/* FW release number, example 0x1234=1.2.3.4 */
-	u32 fwreleasenumber;
+	/* FW release number, example 1,2,3,4 = 3.2.1p4 */
+	u8 fwreleasenumber[4];
 
 	/* Base Address of TxPD queue */
-	u32 wcb_base;
+	__le32 wcb_base;
 	/* Read Pointer of RxPd queue */
-	u32 rxpd_rdptr;
+	__le32 rxpd_rdptr;
 
 	/* Write Pointer of RxPd queue */
-	u32 rxpd_wrptr;
+	__le32 rxpd_wrptr;
 
 	/*FW/HW capability */
-	u32 fwcapinfo;
+	__le32 fwcapinfo;
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11_reset {
-	u16 action;
+	__le16 action;
 };
 
 struct cmd_ds_802_11_subscribe_event {
-	u16 action;
-	u16 events;
+	__le16 action;
+	__le16 events;
 };
 
 /*
@@ -205,35 +192,35 @@
 };
 
 struct cmd_ds_802_11_scan_rsp {
-	u16 bssdescriptsize;
+	__le16 bssdescriptsize;
 	u8 nr_sets;
 	u8 bssdesc_and_tlvbuffer[1];
 };
 
 struct cmd_ds_802_11_get_log {
-	u32 mcasttxframe;
-	u32 failed;
-	u32 retry;
-	u32 multiretry;
-	u32 framedup;
-	u32 rtssuccess;
-	u32 rtsfailure;
-	u32 ackfailure;
-	u32 rxfrag;
-	u32 mcastrxframe;
-	u32 fcserror;
-	u32 txframe;
-	u32 wepundecryptable;
+	__le32 mcasttxframe;
+	__le32 failed;
+	__le32 retry;
+	__le32 multiretry;
+	__le32 framedup;
+	__le32 rtssuccess;
+	__le32 rtsfailure;
+	__le32 ackfailure;
+	__le32 rxfrag;
+	__le32 mcastrxframe;
+	__le32 fcserror;
+	__le32 txframe;
+	__le32 wepundecryptable;
 };
 
 struct cmd_ds_mac_control {
-	u16 action;
-	u16 reserved;
+	__le16 action;
+	__le16 reserved;
 };
 
 struct cmd_ds_mac_multicast_adr {
-	u16 action;
-	u16 nr_of_adrs;
+	__le16 action;
+	__le16 nr_of_adrs;
 	u8 maclist[ETH_ALEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
 };
 
@@ -245,14 +232,14 @@
 
 struct cmd_ds_802_11_deauthenticate {
 	u8 macaddr[6];
-	u16 reasoncode;
+	__le16 reasoncode;
 };
 
 struct cmd_ds_802_11_associate {
 	u8 peerstaaddr[6];
 	struct ieeetypes_capinfo capinfo;
-	u16 listeninterval;
-	u16 bcnperiod;
+	__le16 listeninterval;
+	__le16 bcnperiod;
 	u8 dtimperiod;
 
 #if 0
@@ -265,7 +252,7 @@
 
 struct cmd_ds_802_11_disassociate {
 	u8 destmacaddr[6];
-	u16 reasoncode;
+	__le16 reasoncode;
 };
 
 struct cmd_ds_802_11_associate_rsp {
@@ -279,10 +266,10 @@
 
 struct cmd_ds_802_11_set_wep {
 	/* ACT_ADD, ACT_REMOVE or ACT_ENABLE */
-	u16 action;
+	__le16 action;
 
 	/* key Index selected for Tx */
-	u16 keyindex;
+	__le16 keyindex;
 
 	/* 40, 128bit or TXWEP */
 	u8 keytype[4];
@@ -290,96 +277,96 @@
 };
 
 struct cmd_ds_802_3_get_stat {
-	u32 xmitok;
-	u32 rcvok;
-	u32 xmiterror;
-	u32 rcverror;
-	u32 rcvnobuffer;
-	u32 rcvcrcerror;
+	__le32 xmitok;
+	__le32 rcvok;
+	__le32 xmiterror;
+	__le32 rcverror;
+	__le32 rcvnobuffer;
+	__le32 rcvcrcerror;
 };
 
 struct cmd_ds_802_11_get_stat {
-	u32 txfragmentcnt;
-	u32 mcasttxframecnt;
-	u32 failedcnt;
-	u32 retrycnt;
-	u32 Multipleretrycnt;
-	u32 rtssuccesscnt;
-	u32 rtsfailurecnt;
-	u32 ackfailurecnt;
-	u32 frameduplicatecnt;
-	u32 rxfragmentcnt;
-	u32 mcastrxframecnt;
-	u32 fcserrorcnt;
-	u32 bcasttxframecnt;
-	u32 bcastrxframecnt;
-	u32 txbeacon;
-	u32 rxbeacon;
-	u32 wepundecryptable;
+	__le32 txfragmentcnt;
+	__le32 mcasttxframecnt;
+	__le32 failedcnt;
+	__le32 retrycnt;
+	__le32 Multipleretrycnt;
+	__le32 rtssuccesscnt;
+	__le32 rtsfailurecnt;
+	__le32 ackfailurecnt;
+	__le32 frameduplicatecnt;
+	__le32 rxfragmentcnt;
+	__le32 mcastrxframecnt;
+	__le32 fcserrorcnt;
+	__le32 bcasttxframecnt;
+	__le32 bcastrxframecnt;
+	__le32 txbeacon;
+	__le32 rxbeacon;
+	__le32 wepundecryptable;
 };
 
 struct cmd_ds_802_11_snmp_mib {
-	u16 querytype;
-	u16 oid;
-	u16 bufsize;
+	__le16 querytype;
+	__le16 oid;
+	__le16 bufsize;
 	u8 value[128];
 };
 
 struct cmd_ds_mac_reg_map {
-	u16 buffersize;
+	__le16 buffersize;
 	u8 regmap[128];
-	u16 reserved;
+	__le16 reserved;
 };
 
 struct cmd_ds_bbp_reg_map {
-	u16 buffersize;
+	__le16 buffersize;
 	u8 regmap[128];
-	u16 reserved;
+	__le16 reserved;
 };
 
 struct cmd_ds_rf_reg_map {
-	u16 buffersize;
+	__le16 buffersize;
 	u8 regmap[64];
-	u16 reserved;
+	__le16 reserved;
 };
 
 struct cmd_ds_mac_reg_access {
-	u16 action;
-	u16 offset;
-	u32 value;
+	__le16 action;
+	__le16 offset;
+	__le32 value;
 };
 
 struct cmd_ds_bbp_reg_access {
-	u16 action;
-	u16 offset;
+	__le16 action;
+	__le16 offset;
 	u8 value;
 	u8 reserved[3];
 };
 
 struct cmd_ds_rf_reg_access {
-	u16 action;
-	u16 offset;
+	__le16 action;
+	__le16 offset;
 	u8 value;
 	u8 reserved[3];
 };
 
 struct cmd_ds_802_11_radio_control {
-	u16 action;
-	u16 control;
+	__le16 action;
+	__le16 control;
 };
 
 struct cmd_ds_802_11_sleep_params {
 	/* ACT_GET/ACT_SET */
-	u16 action;
+	__le16 action;
 
 	/* Sleep clock error in ppm */
-	u16 error;
+	__le16 error;
 
 	/* Wakeup offset in usec */
-	u16 offset;
+	__le16 offset;
 
 	/* Clock stabilization time in usec */
-	u16 stabletime;
+	__le16 stabletime;
 
 	/* control periodic calibration */
 	u8 calcontrol;
@@ -388,100 +375,100 @@
 	u8 externalsleepclk;
 
 	/* reserved field, should be set to zero */
-	u16 reserved;
+	__le16 reserved;
 };
 
 struct cmd_ds_802_11_inactivity_timeout {
 	/* ACT_GET/ACT_SET */
-	u16 action;
+	__le16 action;
 
 	/* Inactivity timeout in msec */
-	u16 timeout;
+	__le16 timeout;
 };
 
 struct cmd_ds_802_11_rf_channel {
-	u16 action;
-	u16 currentchannel;
-	u16 rftype;
-	u16 reserved;
+	__le16 action;
+	__le16 currentchannel;
+	__le16 rftype;
+	__le16 reserved;
 	u8 channellist[32];
 };
 
 struct cmd_ds_802_11_rssi {
 	/* weighting factor */
-	u16 N;
+	__le16 N;
 
-	u16 reserved_0;
-	u16 reserved_1;
-	u16 reserved_2;
+	__le16 reserved_0;
+	__le16 reserved_1;
+	__le16 reserved_2;
 };
 
 struct cmd_ds_802_11_rssi_rsp {
-	u16 SNR;
-	u16 noisefloor;
-	u16 avgSNR;
-	u16 avgnoisefloor;
+	__le16 SNR;
+	__le16 noisefloor;
+	__le16 avgSNR;
+	__le16 avgnoisefloor;
 };
 
 struct cmd_ds_802_11_mac_address {
-	u16 action;
+	__le16 action;
 	u8 macadd[ETH_ALEN];
 };
 
 struct cmd_ds_802_11_rf_tx_power {
-	u16 action;
-	u16 currentlevel;
+	__le16 action;
+	__le16 currentlevel;
 };
 
 struct cmd_ds_802_11_rf_antenna {
-	u16 action;
+	__le16 action;
 
 	/* Number of antennas or 0xffff(diversity) */
-	u16 antennamode;
+	__le16 antennamode;
 
 };
 
 struct cmd_ds_802_11_ps_mode {
-	u16 action;
-	u16 nullpktinterval;
-	u16 multipledtim;
-	u16 reserved;
-	u16 locallisteninterval;
+	__le16 action;
+	__le16 nullpktinterval;
+	__le16 multipledtim;
+	__le16 reserved;
+	__le16 locallisteninterval;
 };
 
 struct PS_CMD_ConfirmSleep {
-	u16 command;
-	u16 size;
-	u16 seqnum;
-	u16 result;
+	__le16 command;
+	__le16 size;
+	__le16 seqnum;
+	__le16 result;
 
-	u16 action;
-	u16 reserved1;
-	u16 multipledtim;
-	u16 reserved;
-	u16 locallisteninterval;
+	__le16 action;
+	__le16 reserved1;
+	__le16 multipledtim;
+	__le16 reserved;
+	__le16 locallisteninterval;
 };
 
 struct cmd_ds_802_11_data_rate {
-	u16 action;
-	u16 reserverd;
+	__le16 action;
+	__le16 reserverd;
 	u8 datarate[G_SUPPORTED_RATES];
 };
 
 struct cmd_ds_802_11_rate_adapt_rateset {
-	u16 action;
-	u16 enablehwauto;
-	u16 bitmap;
+	__le16 action;
+	__le16 enablehwauto;
+	__le16 bitmap;
 };
 
 struct cmd_ds_802_11_ad_hoc_start {
 	u8 SSID[IW_ESSID_MAX_SIZE];
 	u8 bsstype;
-	u16 beaconperiod;
+	__le16 beaconperiod;
 	u8 dtimperiod;
 	union IEEEtypes_ssparamset ssparamset;
 	union ieeetypes_phyparamset phyparamset;
-	u16 probedelay;
+	__le16 probedelay;
 	struct ieeetypes_capinfo cap;
 	u8 datarate[G_SUPPORTED_RATES];
 	u8 tlv_memory_size_pad[100];
@@ -491,10 +478,10 @@
 	u8 BSSID[6];
 	u8 SSID[32];
 	u8 bsstype;
-	u16 beaconperiod;
+	__le16 beaconperiod;
 	u8 dtimperiod;
-	u8 timestamp[8];
-	u8 localtime[8];
+	__le64 timestamp;
+	__le64 localtime;
 	union ieeetypes_phyparamset phyparamset;
 	union IEEEtypes_ssparamset ssparamset;
 	struct ieeetypes_capinfo cap;
@@ -508,52 +495,52 @@
 
 struct cmd_ds_802_11_ad_hoc_join {
 	struct adhoc_bssdesc bssdescriptor;
-	u16 failtimeout;
-	u16 probedelay;
+	__le16 failtimeout;
+	__le16 probedelay;
 
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11_enable_rsn {
-	u16 action;
-	u16 enable;
+	__le16 action;
+	__le16 enable;
 };
 
 struct MrvlIEtype_keyParamSet {
 	/* type ID */
-	u16 type;
+	__le16 type;
 
 	/* length of Payload */
-	u16 length;
+	__le16 length;
 
 	/* type of key: WEP=0, TKIP=1, AES=2 */
-	u16 keytypeid;
+	__le16 keytypeid;
 
 	/* key control Info specific to a keytypeid */
-	u16 keyinfo;
+	__le16 keyinfo;
 
 	/* length of key */
-	u16 keylen;
+	__le16 keylen;
 
 	/* key material of size keylen */
 	u8 key[32];
 };
 
 struct cmd_ds_802_11_key_material {
-	u16 action;
+	__le16 action;
 	struct MrvlIEtype_keyParamSet keyParamSet[2];
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11_eeprom_access {
-	u16 action;
+	__le16 action;
 
 	/* multiple 4 */
-	u16 offset;
-	u16 bytecount;
+	__le16 offset;
+	__le16 bytecount;
 	u8 value;
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11_tpc_cfg {
-	u16 action;
+	__le16 action;
 	u8 enable;
 	s8 P0;
 	s8 P1;
@@ -562,13 +549,13 @@
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11_led_ctrl {
-	u16 action;
-	u16 numled;
+	__le16 action;
+	__le16 numled;
 	u8 data[256];
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11_pwr_cfg {
-	u16 action;
+	__le16 action;
 	u8 enable;
 	s8 PA_P0;
 	s8 PA_P1;
@@ -576,21 +563,21 @@
 } __attribute__ ((packed));
 
 struct cmd_ds_802_11_afc {
-	u16 afc_auto;
+	__le16 afc_auto;
 	union {
 		struct {
-			u16 threshold;
-			u16 period;
+			__le16 threshold;
+			__le16 period;
 		};
 		struct {
-			s16 timing_offset;
-			s16 carrier_offset;
+			__le16 timing_offset; /* signed */
+			__le16 carrier_offset; /* signed */
 		};
 	};
 } __attribute__ ((packed));
 
 struct cmd_tx_rate_query {
-	u16 txrate;
+	__le16 txrate;
 } __attribute__ ((packed));
 
 struct cmd_ds_get_tsf {
@@ -598,41 +585,46 @@
 } __attribute__ ((packed));
 
 struct cmd_ds_bt_access {
-	u16 action;
-	u32 id;
+	__le16 action;
+	__le32 id;
 	u8 addr1[ETH_ALEN];
 	u8 addr2[ETH_ALEN];
 } __attribute__ ((packed));
 
 struct cmd_ds_fwt_access {
-	u16 action;
-	u32 id;
+	__le16 action;
+	__le32 id;
+	u8 valid;
 	u8 da[ETH_ALEN];
 	u8 dir;
 	u8 ra[ETH_ALEN];
-	u32 ssn;
-	u32 dsn;
-	u32 metric;
+	__le32 ssn;
+	__le32 dsn;
+	__le32 metric;
+	u8 rate;
 	u8 hopcount;
 	u8 ttl;
-	u32 expiration;
+	__le32 expiration;
 	u8 sleepmode;
-	u32 snr;
-	u32 references;
+	__le32 snr;
+	__le32 references;
+	u8 prec[ETH_ALEN];
 } __attribute__ ((packed));
 
-#define MESH_STATS_NUM 7
 struct cmd_ds_mesh_access {
-	u16 action;
-	u32 data[MESH_STATS_NUM + 1];	/* last position reserved */
+	__le16 action;
+	__le32 data[32];	/* last position reserved */
 } __attribute__ ((packed));
 
+/* Number of stats counters returned by the firmware */
+#define MESH_STATS_NUM 8
+
 struct cmd_ds_command {
 	/* command header */
-	u16 command;
-	u16 size;
-	u16 seqnum;
-	u16 result;
+	__le16 command;
+	__le16 size;
+	__le16 seqnum;
+	__le16 result;
 
 	/* command Body */
 	union {
diff --git a/drivers/net/wireless/libertas/if_bootcmd.c b/drivers/net/wireless/libertas/if_bootcmd.c
index 567000c..8bca306 100644
--- a/drivers/net/wireless/libertas/if_bootcmd.c
+++ b/drivers/net/wireless/libertas/if_bootcmd.c
@@ -8,6 +8,8 @@
 #include <linux/netdevice.h>
 #include <linux/usb.h>
 
+#define DRV_NAME "usb8xxx"
+
 #include "defs.h"
 #include "dev.h"
 #include "if_usb.h"
@@ -20,12 +22,12 @@
  */
 int if_usb_issue_boot_command(wlan_private *priv, int ivalue)
 {
-	struct usb_card_rec	*cardp = priv->wlan_dev.card;
+	struct usb_card_rec	*cardp = priv->card;
 	struct bootcmdstr	sbootcmd;
 	int i;
 
 	/* Prepare command */
-	sbootcmd.u32magicnumber = BOOT_CMD_MAGIC_NUMBER;
+	sbootcmd.u32magicnumber = cpu_to_le32(BOOT_CMD_MAGIC_NUMBER);
 	sbootcmd.u8cmd_tag = ivalue;
 	for (i=0; i<11; i++)
 		sbootcmd.au8dumy[i]=0x00;
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index ae6f72a..9983175 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -2,12 +2,15 @@
   * This file contains functions used in USB interface module.
   */
 #include <linux/delay.h>
+#include <linux/moduleparam.h>
 #include <linux/firmware.h>
 #include <linux/netdevice.h>
+#include <linux/list.h>
 #include <linux/usb.h>
 
+#define DRV_NAME "usb8xxx"
+
 #include "host.h"
-#include "sbi.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
@@ -16,15 +19,24 @@
 #define MESSAGE_HEADER_LEN	4
 
 static const char usbdriver_name[] = "usb8xxx";
+static u8 *default_fw_name = "usb8388.bin";
+
+char *libertas_fw_name = NULL;
+module_param_named(fw_name, libertas_fw_name, charp, 0644);
+
+/*
+ * We need to send a RESET command to all USB devices before
+ * we tear down the USB connection. Otherwise we would not
+ * be able to re-init device the device if the module gets
+ * loaded again. This is a list of all initialized USB devices,
+ * for the reset code see if_usb_reset_device()
+*/
+static LIST_HEAD(usb_devices);
 
 static struct usb_device_id if_usb_table[] = {
 	/* Enter the device signature inside */
-	{
-		USB_DEVICE(USB8388_VID_1, USB8388_PID_1),
-	},
-	{
-		USB_DEVICE(USB8388_VID_2, USB8388_PID_2),
-	},
+	{ USB_DEVICE(0x1286, 0x2001) },
+	{ USB_DEVICE(0x05a3, 0x8388) },
 	{}	/* Terminating entry */
 };
 
@@ -32,6 +44,13 @@
 
 static void if_usb_receive(struct urb *urb);
 static void if_usb_receive_fwload(struct urb *urb);
+static int if_usb_reset_device(wlan_private *priv);
+static int if_usb_register_dev(wlan_private * priv);
+static int if_usb_unregister_dev(wlan_private *);
+static int if_usb_prog_firmware(wlan_private *);
+static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb);
+static int if_usb_get_int_status(wlan_private * priv, u8 *);
+static int if_usb_read_event_cause(wlan_private *);
 
 /**
  *  @brief  call back function to handle the status of the URB
@@ -42,23 +61,27 @@
 {
 	wlan_private *priv = (wlan_private *) (urb->context);
 	wlan_adapter *adapter = priv->adapter;
-	struct net_device *dev = priv->wlan_dev.netdev;
+	struct net_device *dev = priv->dev;
 
 	/* handle the transmission complete validations */
 
 	if (urb->status != 0) {
 		/* print the failure status number for debug */
-		lbs_pr_info("URB in failure status\n");
+		lbs_pr_info("URB in failure status: %d\n", urb->status);
 	} else {
-		lbs_dev_dbg(2, &urb->dev->dev, "URB status is successfull\n");
-		lbs_dev_dbg(2, &urb->dev->dev, "Actual length transmitted %d\n",
+		/*
+		lbs_deb_usbd(&urb->dev->dev, "URB status is successfull\n");
+		lbs_deb_usbd(&urb->dev->dev, "Actual length transmitted %d\n",
 		       urb->actual_length);
-		priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
+		*/
+		priv->dnld_sent = DNLD_RES_RECEIVED;
 		/* Wake main thread if commands are pending */
 		if (!adapter->cur_cmd)
 			wake_up_interruptible(&priv->mainthread.waitq);
-		if ((adapter->connect_status == libertas_connected))
+		if ((adapter->connect_status == libertas_connected)) {
 			netif_wake_queue(dev);
+			netif_wake_queue(priv->mesh_dev);
+		}
 	}
 
 	return;
@@ -71,7 +94,7 @@
  */
 void if_usb_free(struct usb_card_rec *cardp)
 {
-	ENTER();
+	lbs_deb_enter(LBS_DEB_USB);
 
 	/* Unlink tx & rx urb */
 	usb_kill_urb(cardp->tx_urb);
@@ -86,8 +109,7 @@
 	kfree(cardp->bulk_out_buffer);
 	cardp->bulk_out_buffer = NULL;
 
-	LEAVE();
-	return;
+	lbs_deb_leave(LBS_DEB_USB);
 }
 
 /**
@@ -102,27 +124,27 @@
 	struct usb_device *udev;
 	struct usb_host_interface *iface_desc;
 	struct usb_endpoint_descriptor *endpoint;
-	wlan_private *pwlanpriv;
-	struct usb_card_rec *usb_cardp;
+	wlan_private *priv;
+	struct usb_card_rec *cardp;
 	int i;
 
 	udev = interface_to_usbdev(intf);
 
-	usb_cardp = kzalloc(sizeof(struct usb_card_rec), GFP_KERNEL);
-	if (!usb_cardp) {
+	cardp = kzalloc(sizeof(struct usb_card_rec), GFP_KERNEL);
+	if (!cardp) {
 		lbs_pr_err("Out of memory allocating private data.\n");
 		goto error;
 	}
 
-	usb_cardp->udev = udev;
+	cardp->udev = udev;
 	iface_desc = intf->cur_altsetting;
 
-	lbs_dev_dbg(1, &udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
+	lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
 	       " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n",
-	       udev->descriptor.bcdUSB,
-	       udev->descriptor.bDeviceClass,
-	       udev->descriptor.bDeviceSubClass,
-	       udev->descriptor.bDeviceProtocol);
+		     le16_to_cpu(udev->descriptor.bcdUSB),
+		     udev->descriptor.bDeviceClass,
+		     udev->descriptor.bDeviceSubClass,
+		     udev->descriptor.bDeviceProtocol);
 
 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
 		endpoint = &iface_desc->endpoint[i].desc;
@@ -130,23 +152,21 @@
 		    && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
 			USB_ENDPOINT_XFER_BULK)) {
 			/* we found a bulk in endpoint */
-			lbs_dev_dbg(1, &udev->dev, "Bulk in size is %d\n",
-			       endpoint->wMaxPacketSize);
-			if (!
-			    (usb_cardp->rx_urb =
-			     usb_alloc_urb(0, GFP_KERNEL))) {
-				lbs_dev_dbg(1, &udev->dev,
+			lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n",
+				     le16_to_cpu(endpoint->wMaxPacketSize));
+			if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
+				lbs_deb_usbd(&udev->dev,
 				       "Rx URB allocation failed\n");
 				goto dealloc;
 			}
-			usb_cardp->rx_urb_recall = 0;
+			cardp->rx_urb_recall = 0;
 
-			usb_cardp->bulk_in_size =
-			    endpoint->wMaxPacketSize;
-			usb_cardp->bulk_in_endpointAddr =
+			cardp->bulk_in_size =
+				le16_to_cpu(endpoint->wMaxPacketSize);
+			cardp->bulk_in_endpointAddr =
 			    (endpoint->
 			     bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
-			lbs_dev_dbg(1, &udev->dev, "in_endpoint = %d\n",
+			lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n",
 			       endpoint->bEndpointAddress);
 		}
 
@@ -156,55 +176,63 @@
 		    && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
 			USB_ENDPOINT_XFER_BULK)) {
 			/* We found bulk out endpoint */
-			if (!
-			    (usb_cardp->tx_urb =
-			     usb_alloc_urb(0, GFP_KERNEL))) {
-				lbs_dev_dbg(1,&udev->dev,
+			if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
+				lbs_deb_usbd(&udev->dev,
 				       "Tx URB allocation failed\n");
 				goto dealloc;
 			}
 
-			usb_cardp->bulk_out_size =
-			    endpoint->wMaxPacketSize;
-			lbs_dev_dbg(1, &udev->dev,
-				    "Bulk out size is %d\n",
-				    endpoint->wMaxPacketSize);
-			usb_cardp->bulk_out_endpointAddr =
+			cardp->bulk_out_size =
+				le16_to_cpu(endpoint->wMaxPacketSize);
+			lbs_deb_usbd(&udev->dev,
+				     "Bulk out size is %d\n",
+				     le16_to_cpu(endpoint->wMaxPacketSize));
+			cardp->bulk_out_endpointAddr =
 			    endpoint->bEndpointAddress;
-			lbs_dev_dbg(1, &udev->dev, "out_endpoint = %d\n",
+			lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n",
 				    endpoint->bEndpointAddress);
-			usb_cardp->bulk_out_buffer =
+			cardp->bulk_out_buffer =
 			    kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE,
 				    GFP_KERNEL);
 
-			if (!usb_cardp->bulk_out_buffer) {
-				lbs_dev_dbg(1, &udev->dev,
+			if (!cardp->bulk_out_buffer) {
+				lbs_deb_usbd(&udev->dev,
 				       "Could not allocate buffer\n");
 				goto dealloc;
 			}
 		}
 	}
 
-
-	/* At this point wlan_add_card() will be called.  Don't worry
-	 * about keeping pwlanpriv around since it will be set on our
-	 * usb device data in -> add() -> libertas_sbi_register_dev().
-	 */
-	if (!(pwlanpriv = wlan_add_card(usb_cardp)))
+	if (!(priv = libertas_add_card(cardp, &udev->dev)))
 		goto dealloc;
 
-	usb_get_dev(udev);
-	usb_set_intfdata(intf, usb_cardp);
+	if (libertas_add_mesh(priv, &udev->dev))
+		goto err_add_mesh;
 
-	/*
-	 * return card structure, which can be got back in the
-	 * diconnect function as the ptr
-	 * argument.
-	 */
+	priv->hw_register_dev = if_usb_register_dev;
+	priv->hw_unregister_dev = if_usb_unregister_dev;
+	priv->hw_prog_firmware = if_usb_prog_firmware;
+	priv->hw_host_to_card = if_usb_host_to_card;
+	priv->hw_get_int_status = if_usb_get_int_status;
+	priv->hw_read_event_cause = if_usb_read_event_cause;
+
+	if (libertas_activate_card(priv, libertas_fw_name))
+		goto err_activate_card;
+
+	list_add_tail(&cardp->list, &usb_devices);
+
+	usb_get_dev(udev);
+	usb_set_intfdata(intf, cardp);
+
 	return 0;
 
+err_activate_card:
+	libertas_remove_mesh(priv);
+err_add_mesh:
+	free_netdev(priv->dev);
+	kfree(priv->adapter);
 dealloc:
-	if_usb_free(usb_cardp);
+	if_usb_free(cardp);
 
 error:
 	return -ENOMEM;
@@ -212,8 +240,7 @@
 
 /**
  *  @brief free resource and cleanup
- *  @param udev		pointer to usb_device
- *  @param ptr		pointer to usb_cardp
+ *  @param intf		USB interface structure
  *  @return 	   	N/A
  */
 static void if_usb_disconnect(struct usb_interface *intf)
@@ -229,9 +256,12 @@
 	 */
 	adapter->surpriseremoved = 1;
 
+	list_del(&cardp->list);
+
 	/* card is removed and we can call wlan_remove_card */
-	lbs_dev_dbg(1, &cardp->udev->dev, "call remove card\n");
-	wlan_remove_card(cardp);
+	lbs_deb_usbd(&cardp->udev->dev, "call remove card\n");
+	libertas_remove_mesh(priv);
+	libertas_remove_card(priv);
 
 	/* Unlink and free urb */
 	if_usb_free(cardp);
@@ -249,7 +279,7 @@
  */
 static int if_prog_firmware(wlan_private * priv)
 {
-	struct usb_card_rec *cardp = priv->wlan_dev.card;
+	struct usb_card_rec *cardp = priv->card;
 	struct FWData *fwdata;
 	struct fwheader *fwheader;
 	u8 *firmware = priv->firmware->data;
@@ -266,8 +296,10 @@
 		cardp->fwseqnum = cardp->lastseqnum - 1;
 	}
 
-	lbs_dev_dbg(2, &cardp->udev->dev, "totalbytes = %d\n",
+	/*
+	lbs_deb_usbd(&cardp->udev->dev, "totalbytes = %d\n",
 		    cardp->totalbytes);
+	*/
 
 	memcpy(fwheader, &firmware[cardp->totalbytes],
 	       sizeof(struct fwheader));
@@ -275,40 +307,48 @@
 	cardp->fwlastblksent = cardp->totalbytes;
 	cardp->totalbytes += sizeof(struct fwheader);
 
-	lbs_dev_dbg(2, &cardp->udev->dev,"Copy Data\n");
+	/* lbs_deb_usbd(&cardp->udev->dev,"Copy Data\n"); */
 	memcpy(fwdata->data, &firmware[cardp->totalbytes],
-	       fwdata->fwheader.datalength);
+	       le32_to_cpu(fwdata->fwheader.datalength));
 
-	lbs_dev_dbg(2, &cardp->udev->dev,
-		    "Data length = %d\n", fwdata->fwheader.datalength);
+	/*
+	lbs_deb_usbd(&cardp->udev->dev,
+		    "Data length = %d\n", le32_to_cpu(fwdata->fwheader.datalength));
+	*/
 
 	cardp->fwseqnum = cardp->fwseqnum + 1;
 
-	fwdata->seqnum = cardp->fwseqnum;
-	cardp->lastseqnum = fwdata->seqnum;
-	cardp->totalbytes += fwdata->fwheader.datalength;
+	fwdata->seqnum = cpu_to_le32(cardp->fwseqnum);
+	cardp->lastseqnum = cardp->fwseqnum;
+	cardp->totalbytes += le32_to_cpu(fwdata->fwheader.datalength);
 
-	if (fwheader->dnldcmd == FW_HAS_DATA_TO_RECV) {
-		lbs_dev_dbg(2, &cardp->udev->dev, "There is data to follow\n");
-		lbs_dev_dbg(2, &cardp->udev->dev,
+	if (fwheader->dnldcmd == cpu_to_le32(FW_HAS_DATA_TO_RECV)) {
+		/*
+		lbs_deb_usbd(&cardp->udev->dev, "There are data to follow\n");
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "seqnum = %d totalbytes = %d\n", cardp->fwseqnum,
 			    cardp->totalbytes);
+		*/
 		memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
 		usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
 
-	} else if (fwdata->fwheader.dnldcmd == FW_HAS_LAST_BLOCK) {
-		lbs_dev_dbg(2, &cardp->udev->dev,
+	} else if (fwdata->fwheader.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) {
+		/*
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "Host has finished FW downloading\n");
-		lbs_dev_dbg(2, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "Donwloading FW JUMP BLOCK\n");
+		*/
 		memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
 		usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
 		cardp->fwfinalblk = 1;
 	}
 
-	lbs_dev_dbg(2, &cardp->udev->dev,
+	/*
+	lbs_deb_usbd(&cardp->udev->dev,
 		    "The firmware download is done size is %d\n",
 		    cardp->totalbytes);
+	*/
 
 	kfree(fwdata);
 
@@ -318,14 +358,19 @@
 static int libertas_do_reset(wlan_private *priv)
 {
 	int ret;
-	struct usb_card_rec *cardp = priv->wlan_dev.card;
+	struct usb_card_rec *cardp = priv->card;
+
+	lbs_deb_enter(LBS_DEB_USB);
 
 	ret = usb_reset_device(cardp->udev);
 	if (!ret) {
 		msleep(10);
-		reset_device(priv);
+		if_usb_reset_device(priv);
 		msleep(10);
 	}
+
+	lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
+
 	return ret;
 }
 
@@ -339,12 +384,12 @@
 int usb_tx_block(wlan_private * priv, u8 * payload, u16 nb)
 {
 	/* pointer to card structure */
-	struct usb_card_rec *cardp = priv->wlan_dev.card;
+	struct usb_card_rec *cardp = priv->card;
 	int ret = -1;
 
 	/* check if device is removed */
 	if (priv->adapter->surpriseremoved) {
-		lbs_dev_dbg(1, &cardp->udev->dev, "Device removed\n");
+		lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
 		goto tx_ret;
 	}
 
@@ -357,10 +402,10 @@
 
 	if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
 		/*  transfer failed */
-		lbs_dev_dbg(1, &cardp->udev->dev, "usb_submit_urb failed\n");
+		lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed\n");
 		ret = -1;
 	} else {
-		lbs_dev_dbg(2, &cardp->udev->dev, "usb_submit_urb success\n");
+		/* lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb success\n"); */
 		ret = 0;
 	}
 
@@ -372,7 +417,7 @@
 				  void (*callbackfn)
 				  (struct urb *urb))
 {
-	struct usb_card_rec *cardp = priv->wlan_dev.card;
+	struct usb_card_rec *cardp = priv->card;
 	struct sk_buff *skb;
 	struct read_cb_info *rinfo = &cardp->rinfo;
 	int ret = -1;
@@ -394,13 +439,13 @@
 
 	cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
 
-	lbs_dev_dbg(2, &cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb);
+	/* lbs_deb_usbd(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb); */
 	if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
 		/* handle failure conditions */
-		lbs_dev_dbg(1, &cardp->udev->dev, "Submit Rx URB failed\n");
+		lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed\n");
 		ret = -1;
 	} else {
-		lbs_dev_dbg(2, &cardp->udev->dev, "Submit Rx URB success\n");
+		/* lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB success\n"); */
 		ret = 0;
 	}
 
@@ -423,12 +468,12 @@
 	struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
 	wlan_private *priv = rinfo->priv;
 	struct sk_buff *skb = rinfo->skb;
-	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->wlan_dev.card;
+	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
 	struct fwsyncheader *syncfwheader;
 	struct bootcmdrespStr bootcmdresp;
 
 	if (urb->status) {
-		lbs_dev_dbg(1, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "URB status is failed during fw load\n");
 		kfree_skb(skb);
 		return;
@@ -437,18 +482,18 @@
 	if (cardp->bootcmdresp == 0) {
 		memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET,
 			sizeof(bootcmdresp));
-		if (cardp->udev->descriptor.bcdDevice < 0x3106) {
+		if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) {
 			kfree_skb(skb);
 			if_usb_submit_rx_urb_fwload(priv);
 			cardp->bootcmdresp = 1;
-			lbs_dev_dbg(1, &cardp->udev->dev,
+			lbs_deb_usbd(&cardp->udev->dev,
 				    "Received valid boot command response\n");
 			return;
 		}
-		if (bootcmdresp.u32magicnumber != BOOT_CMD_MAGIC_NUMBER) {
+		if (bootcmdresp.u32magicnumber != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) {
 			lbs_pr_info(
 				"boot cmd response wrong magic number (0x%x)\n",
-				bootcmdresp.u32magicnumber);
+				le32_to_cpu(bootcmdresp.u32magicnumber));
 		} else if (bootcmdresp.u8cmd_tag != BOOT_CMD_FW_BY_USB) {
 			lbs_pr_info(
 				"boot cmd response cmd_tag error (%d)\n",
@@ -459,7 +504,7 @@
 				bootcmdresp.u8result);
 		} else {
 			cardp->bootcmdresp = 1;
-			lbs_dev_dbg(1, &cardp->udev->dev,
+			lbs_deb_usbd(&cardp->udev->dev,
 				    "Received valid boot command response\n");
 		}
 		kfree_skb(skb);
@@ -469,7 +514,7 @@
 
 	syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
 	if (!syncfwheader) {
-		lbs_dev_dbg(1, &cardp->udev->dev, "Failure to allocate syncfwheader\n");
+		lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
 		kfree_skb(skb);
 		return;
 	}
@@ -478,14 +523,16 @@
 			sizeof(struct fwsyncheader));
 
 	if (!syncfwheader->cmd) {
-		lbs_dev_dbg(2, &cardp->udev->dev,
+		/*
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "FW received Blk with correct CRC\n");
-		lbs_dev_dbg(2, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "FW received Blk seqnum = %d\n",
 		       syncfwheader->seqnum);
+		*/
 		cardp->CRC_OK = 1;
 	} else {
-		lbs_dev_dbg(1, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "FW received Blk with CRC error\n");
 		cardp->CRC_OK = 0;
 	}
@@ -515,7 +562,7 @@
 {
 	if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE +
 	    MESSAGE_HEADER_LEN || recvlength < MRVDRV_MIN_PKT_LEN) {
-		lbs_dev_dbg(1, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "Packet length is Invalid\n");
 		kfree_skb(skb);
 		return;
@@ -525,7 +572,7 @@
 	skb_put(skb, recvlength);
 	skb_pull(skb, MESSAGE_HEADER_LEN);
 	libertas_process_rxed_packet(priv, skb);
-	priv->wlan_dev.upld_len = (recvlength - MESSAGE_HEADER_LEN);
+	priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
 }
 
 static inline void process_cmdrequest(int recvlength, u8 *recvbuff,
@@ -535,7 +582,7 @@
 {
 	u8 *cmdbuf;
 	if (recvlength > MRVDRV_SIZE_OF_CMD_BUFFER) {
-		lbs_dev_dbg(1, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "The receive buffer is too large\n");
 		kfree_skb(skb);
 		return;
@@ -548,21 +595,21 @@
 	/* take care of cur_cmd = NULL case by reading the
 	 * data to clear the interrupt */
 	if (!priv->adapter->cur_cmd) {
-		cmdbuf = priv->wlan_dev.upld_buf;
+		cmdbuf = priv->upld_buf;
 		priv->adapter->hisregcpy &= ~his_cmdupldrdy;
 	} else
 		cmdbuf = priv->adapter->cur_cmd->bufvirtualaddr;
 
 	cardp->usb_int_cause |= his_cmdupldrdy;
-	priv->wlan_dev.upld_len = (recvlength - MESSAGE_HEADER_LEN);
+	priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
 	memcpy(cmdbuf, recvbuff + MESSAGE_HEADER_LEN,
-	       priv->wlan_dev.upld_len);
+	       priv->upld_len);
 
 	kfree_skb(skb);
-	libertas_interrupt(priv->wlan_dev.netdev);
+	libertas_interrupt(priv->dev);
 	spin_unlock(&priv->adapter->driver_lock);
 
-	lbs_dev_dbg(1, &cardp->udev->dev,
+	lbs_deb_usbd(&cardp->udev->dev,
 		    "Wake up main thread to handle cmd response\n");
 
 	return;
@@ -580,17 +627,17 @@
 	struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
 	wlan_private *priv = rinfo->priv;
 	struct sk_buff *skb = rinfo->skb;
-	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->wlan_dev.card;
+	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
 
 	int recvlength = urb->actual_length;
 	u8 *recvbuff = NULL;
 	u32 recvtype;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_USB);
 
 	if (recvlength) {
 		if (urb->status) {
-			lbs_dev_dbg(1, &cardp->udev->dev,
+			lbs_deb_usbd(&cardp->udev->dev,
 				    "URB status is failed\n");
 			kfree_skb(skb);
 			goto setup_for_next;
@@ -598,12 +645,12 @@
 
 		recvbuff = skb->data + IPFIELD_ALIGN_OFFSET;
 		memcpy(&recvtype, recvbuff, sizeof(u32));
-		lbs_dev_dbg(1, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "Recv length = 0x%x\n", recvlength);
-		lbs_dev_dbg(1, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "Receive type = 0x%X\n", recvtype);
 		recvtype = le32_to_cpu(recvtype);
-		lbs_dev_dbg(1, &cardp->udev->dev,
+		lbs_deb_usbd(&cardp->udev->dev,
 			    "Receive type after = 0x%X\n", recvtype);
 	} else if (urb->status)
 		goto rx_exit;
@@ -621,18 +668,18 @@
 	case CMD_TYPE_INDICATION:
 		/* Event cause handling */
 		spin_lock(&priv->adapter->driver_lock);
-		cardp->usb_event_cause = *(u32 *) (recvbuff + MESSAGE_HEADER_LEN);
-		lbs_dev_dbg(1, &cardp->udev->dev,"**EVENT** 0x%X\n",
+		cardp->usb_event_cause = le32_to_cpu(*(__le32 *) (recvbuff + MESSAGE_HEADER_LEN));
+		lbs_deb_usbd(&cardp->udev->dev,"**EVENT** 0x%X\n",
 			    cardp->usb_event_cause);
 		if (cardp->usb_event_cause & 0xffff0000) {
 			libertas_send_tx_feedback(priv);
 			spin_unlock(&priv->adapter->driver_lock);
 			break;
 		}
-		cardp->usb_event_cause = le32_to_cpu(cardp->usb_event_cause) << 3;
+		cardp->usb_event_cause <<= 3;
 		cardp->usb_int_cause |= his_cardevent;
 		kfree_skb(skb);
-		libertas_interrupt(priv->wlan_dev.netdev);
+		libertas_interrupt(priv->dev);
 		spin_unlock(&priv->adapter->driver_lock);
 		goto rx_exit;
 	default:
@@ -643,8 +690,7 @@
 setup_for_next:
 	if_usb_submit_rx_urb(priv);
 rx_exit:
-	LEAVE();
-	return;
+	lbs_deb_leave(LBS_DEB_USB);
 }
 
 /**
@@ -655,24 +701,24 @@
  *  @param len		number of bytes
  *  @return 	   	0 or -1
  */
-int libertas_sbi_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb)
+static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb)
 {
 	int ret = -1;
 	u32 tmp;
-	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->wlan_dev.card;
+	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
 
-	lbs_dev_dbg(1, &cardp->udev->dev,"*** type = %u\n", type);
-	lbs_dev_dbg(1, &cardp->udev->dev,"size after = %d\n", nb);
+	lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type);
+	lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb);
 
 	if (type == MVMS_CMD) {
 		tmp = cpu_to_le32(CMD_TYPE_REQUEST);
-		priv->wlan_dev.dnld_sent = DNLD_CMD_SENT;
+		priv->dnld_sent = DNLD_CMD_SENT;
 		memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
 		       MESSAGE_HEADER_LEN);
 
 	} else {
 		tmp = cpu_to_le32(CMD_TYPE_DATA);
-		priv->wlan_dev.dnld_sent = DNLD_DATA_SENT;
+		priv->dnld_sent = DNLD_DATA_SENT;
 		memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
 		       MESSAGE_HEADER_LEN);
 	}
@@ -686,39 +732,41 @@
 }
 
 /* called with adapter->driver_lock held */
-int libertas_sbi_get_int_status(wlan_private * priv, u8 * ireg)
+static int if_usb_get_int_status(wlan_private * priv, u8 * ireg)
 {
-	struct usb_card_rec *cardp = priv->wlan_dev.card;
+	struct usb_card_rec *cardp = priv->card;
 
 	*ireg = cardp->usb_int_cause;
 	cardp->usb_int_cause = 0;
 
-	lbs_dev_dbg(1, &cardp->udev->dev,"Int cause is 0x%X\n", *ireg);
+	lbs_deb_usbd(&cardp->udev->dev,"Int cause is 0x%X\n", *ireg);
 
 	return 0;
 }
 
-int libertas_sbi_read_event_cause(wlan_private * priv)
+static int if_usb_read_event_cause(wlan_private * priv)
 {
-	struct usb_card_rec *cardp = priv->wlan_dev.card;
+	struct usb_card_rec *cardp = priv->card;
 	priv->adapter->eventcause = cardp->usb_event_cause;
 	/* Re-submit rx urb here to avoid event lost issue */
 	if_usb_submit_rx_urb(priv);
 	return 0;
 }
 
-int reset_device(wlan_private *priv)
+static int if_usb_reset_device(wlan_private *priv)
 {
 	int ret;
 
+	lbs_deb_enter(LBS_DEB_USB);
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_reset,
 				    cmd_act_halt, 0, 0, NULL);
 	msleep_interruptible(10);
 
+	lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
 	return ret;
 }
 
-int libertas_sbi_unregister_dev(wlan_private * priv)
+static int if_usb_unregister_dev(wlan_private * priv)
 {
 	int ret = 0;
 
@@ -727,7 +775,7 @@
 	 * again.
 	 */
 	if (priv)
-		reset_device(priv);
+		if_usb_reset_device(priv);
 
 	return ret;
 }
@@ -738,42 +786,41 @@
  *  @param		priv pointer to wlan_private
  *  @return		0 or -1
  */
-int libertas_sbi_register_dev(wlan_private * priv)
+static int if_usb_register_dev(wlan_private * priv)
 {
+	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
 
-	struct usb_card_rec *cardp = (struct usb_card_rec *)priv->wlan_dev.card;
-	ENTER();
+	lbs_deb_enter(LBS_DEB_USB);
 
 	cardp->priv = priv;
-	cardp->eth_dev = priv->wlan_dev.netdev;
+	cardp->eth_dev = priv->dev;
 	priv->hotplug_device = &(cardp->udev->dev);
 
-	SET_NETDEV_DEV(cardp->eth_dev, &(cardp->udev->dev));
-
-	lbs_dev_dbg(1, &cardp->udev->dev, "udev pointer is at %p\n",
+	lbs_deb_usbd(&cardp->udev->dev, "udev pointer is at %p\n",
 		    cardp->udev);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_USB);
 	return 0;
 }
 
 
 
-int libertas_sbi_prog_firmware(wlan_private * priv)
+static int if_usb_prog_firmware(wlan_private * priv)
 {
-	struct usb_card_rec *cardp = priv->wlan_dev.card;
+	struct usb_card_rec *cardp = priv->card;
 	int i = 0;
 	static int reset_count = 10;
+	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_USB);
 
 	cardp->rinfo.priv = priv;
 
 restart:
 	if (if_usb_submit_rx_urb_fwload(priv) < 0) {
-		lbs_dev_dbg(1, &cardp->udev->dev, "URB submission is failed\n");
-		LEAVE();
-		return -1;
+		lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n");
+		ret = -1;
+		goto done;
 	}
 
 	cardp->bootcmdresp = 0;
@@ -811,7 +858,7 @@
 	if_prog_firmware(priv);
 
 	do {
-		lbs_dev_dbg(1, &cardp->udev->dev,"Wlan sched timeout\n");
+		lbs_deb_usbd(&cardp->udev->dev,"Wlan sched timeout\n");
 		i++;
 		msleep_interruptible(100);
 		if (priv->adapter->surpriseremoved || i >= 20)
@@ -826,8 +873,8 @@
 		}
 
 		lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
-		LEAVE();
-		return -1;
+		ret = -1;
+		goto done;
 	}
 
 	if_usb_submit_rx_urb(priv);
@@ -837,45 +884,24 @@
 
 	priv->adapter->fw_ready = 1;
 
-	LEAVE();
-	return 0;
+done:
+	lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
+	return ret;
 }
 
-/**
- *  @brief Given a usb_card_rec return its wlan_private
- *  @param card		pointer to a usb_card_rec
- *  @return 	   	pointer to wlan_private
- */
-wlan_private *libertas_sbi_get_priv(void *card)
-{
-	struct usb_card_rec *cardp = card;
-	return cardp->priv;
-}
-
-#ifdef ENABLE_PM
-int libertas_sbi_suspend(wlan_private * priv)
-{
-	return 0;
-}
-
-int libertas_sbi_resume(wlan_private * priv)
-{
-	return 0;
-}
-#endif
-
 #ifdef CONFIG_PM
 static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
 {
 	struct usb_card_rec *cardp = usb_get_intfdata(intf);
 	wlan_private *priv = cardp->priv;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_USB);
 
 	if (priv->adapter->psstate != PS_STATE_FULL_POWER)
 		return -1;
 
 	netif_device_detach(cardp->eth_dev);
+	netif_device_detach(priv->mesh_dev);
 
 	/* Unlink tx & rx urb */
 	usb_kill_urb(cardp->tx_urb);
@@ -883,23 +909,25 @@
 
 	cardp->rx_urb_recall = 1;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_USB);
 	return 0;
 }
 
 static int if_usb_resume(struct usb_interface *intf)
 {
 	struct usb_card_rec *cardp = usb_get_intfdata(intf);
+	wlan_private *priv = cardp->priv;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_USB);
 
 	cardp->rx_urb_recall = 0;
 
 	if_usb_submit_rx_urb(cardp->priv);
 
 	netif_device_attach(cardp->eth_dev);
+	netif_device_attach(priv->mesh_dev);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_USB);
 	return 0;
 }
 #else
@@ -920,32 +948,40 @@
 	.resume = if_usb_resume,
 };
 
-/**
- *  @brief This function registers driver.
- *  @param add		pointer to add_card callback function
- *  @param remove	pointer to remove card callback function
- *  @param arg		pointer to call back function parameter
- *  @return 	   	dummy success variable
- */
-int libertas_sbi_register(void)
+static int if_usb_init_module(void)
 {
-	/*
-	 * API registers the Marvell USB driver
-	 * to the USB system
-	 */
-	usb_register(&if_usb_driver);
+	int ret = 0;
 
-	/* Return success to wlan layer */
-	return 0;
+	lbs_deb_enter(LBS_DEB_MAIN);
+
+	if (libertas_fw_name == NULL) {
+		libertas_fw_name = default_fw_name;
+	}
+
+	ret = usb_register(&if_usb_driver);
+
+	lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
+	return ret;
 }
 
-/**
- *  @brief This function removes usb driver.
- *  @return 	   	N/A
- */
-void libertas_sbi_unregister(void)
+static void if_usb_exit_module(void)
 {
+	struct usb_card_rec *cardp, *cardp_temp;
+
+	lbs_deb_enter(LBS_DEB_MAIN);
+
+	list_for_each_entry_safe(cardp, cardp_temp, &usb_devices, list)
+		if_usb_reset_device((wlan_private *) cardp->priv);
+
 	/* API unregisters the driver from USB subsystem */
 	usb_deregister(&if_usb_driver);
-	return;
+
+	lbs_deb_leave(LBS_DEB_MAIN);
 }
+
+module_init(if_usb_init_module);
+module_exit(if_usb_exit_module);
+
+MODULE_DESCRIPTION("8388 USB WLAN Driver");
+MODULE_AUTHOR("Marvell International Ltd.");
+MODULE_LICENSE("GPL");
diff --git a/drivers/net/wireless/libertas/if_usb.h b/drivers/net/wireless/libertas/if_usb.h
index 170dfe6..156bb48 100644
--- a/drivers/net/wireless/libertas/if_usb.h
+++ b/drivers/net/wireless/libertas/if_usb.h
@@ -1,3 +1,8 @@
+#ifndef _LIBERTAS_IF_USB_H
+#define _LIBERTAS_IF_USB_H
+
+#include <linux/list.h>
+
 /**
   * This file contains definition for USB interface.
   */
@@ -7,11 +12,6 @@
 
 #define IPFIELD_ALIGN_OFFSET	2
 
-#define USB8388_VID_1	0x1286
-#define USB8388_PID_1	0x2001
-#define USB8388_VID_2	0x05a3
-#define USB8388_PID_2	0x8388
-
 #define BOOT_CMD_FW_BY_USB     0x01
 #define BOOT_CMD_FW_IN_EEPROM  0x02
 #define BOOT_CMD_UPDATE_BOOT2  0x03
@@ -20,7 +20,7 @@
 
 struct bootcmdstr
 {
-	u32 u32magicnumber;
+	__le32 u32magicnumber;
 	u8  u8cmd_tag;
 	u8  au8dumy[11];
 };
@@ -30,7 +30,7 @@
 
 struct bootcmdrespStr
 {
-	u32 u32magicnumber;
+	__le32 u32magicnumber;
 	u8  u8cmd_tag;
 	u8  u8result;
 	u8  au8dumy[2];
@@ -44,6 +44,7 @@
 
 /** USB card description structure*/
 struct usb_card_rec {
+	struct list_head list;
 	struct net_device *eth_dev;
 	struct usb_device *udev;
 	struct urb *rx_urb, *tx_urb;
@@ -75,33 +76,34 @@
 
 /** fwheader */
 struct fwheader {
-	u32 dnldcmd;
-	u32 baseaddr;
-	u32 datalength;
-	u32 CRC;
+	__le32 dnldcmd;
+	__le32 baseaddr;
+	__le32 datalength;
+	__le32 CRC;
 };
 
 #define FW_MAX_DATA_BLK_SIZE	600
 /** FWData */
 struct FWData {
 	struct fwheader fwheader;
-	u32 seqnum;
+	__le32 seqnum;
 	u8 data[FW_MAX_DATA_BLK_SIZE];
 };
 
 /** fwsyncheader */
 struct fwsyncheader {
-	u32 cmd;
-	u32 seqnum;
+	__le32 cmd;
+	__le32 seqnum;
 };
 
 #define FW_HAS_DATA_TO_RECV		0x00000001
 #define FW_HAS_LAST_BLOCK		0x00000004
 
 #define FW_DATA_XMIT_SIZE \
-	sizeof(struct fwheader) + fwdata->fwheader.datalength + sizeof(u32)
+	sizeof(struct fwheader) + le32_to_cpu(fwdata->fwheader.datalength) + sizeof(u32)
 
 int usb_tx_block(wlan_private *priv, u8 *payload, u16 nb);
 void if_usb_free(struct usb_card_rec *cardp);
 int if_usb_issue_boot_command(wlan_private *priv, int ivalue);
 
+#endif
diff --git a/drivers/net/wireless/libertas/ioctl.c b/drivers/net/wireless/libertas/ioctl.c
index a8f76c3..f410815 100644
--- a/drivers/net/wireless/libertas/ioctl.c
+++ b/drivers/net/wireless/libertas/ioctl.c
@@ -30,6 +30,7 @@
 static int wlan_set_region(wlan_private * priv, u16 region_code)
 {
 	int i;
+	int ret = 0;
 
 	for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
 		// use the region code to search for the index
@@ -42,17 +43,18 @@
 
 	// if it's unidentified region code
 	if (i >= MRVDRV_MAX_REGION_CODE) {
-		lbs_pr_debug(1, "region Code not identified\n");
-		LEAVE();
-		return -1;
+		lbs_deb_ioctl("region Code not identified\n");
+		ret = -1;
+		goto done;
 	}
 
 	if (libertas_set_regiontable(priv, priv->adapter->regioncode, 0)) {
-		LEAVE();
-		return -EINVAL;
+		ret = -EINVAL;
 	}
 
-	return 0;
+done:
+	lbs_deb_leave_args(LBS_DEB_IOCTL, "ret %d", ret);
+	return ret;
 }
 
 static inline int hex2int(char c)
@@ -125,8 +127,10 @@
 	char ethaddrs_str[18];
 	char *pos;
 	u8 ethaddr[ETH_ALEN];
+	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
 	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
 			   sizeof(ethaddrs_str)))
 		return -EFAULT;
@@ -136,11 +140,12 @@
 		return -EINVAL;
 	}
 
-	lbs_pr_debug(1, "BT: adding %s\n", ethaddrs_str);
-	LEAVE();
-	return (libertas_prepare_and_send_command(priv, cmd_bt_access,
+	lbs_deb_ioctl("BT: adding %s\n", ethaddrs_str);
+	ret = libertas_prepare_and_send_command(priv, cmd_bt_access,
 				      cmd_act_bt_access_add,
-				      cmd_option_waitforrsp, 0, ethaddr));
+				      cmd_option_waitforrsp, 0, ethaddr);
+	lbs_deb_leave_args(LBS_DEB_IOCTL, "ret %d", ret);
+	return ret;
 }
 
 /**
@@ -156,7 +161,8 @@
 	u8 ethaddr[ETH_ALEN];
 	char *pos;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
 	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
 			   sizeof(ethaddrs_str)))
 		return -EFAULT;
@@ -166,13 +172,14 @@
 		return -EINVAL;
 	}
 
-	lbs_pr_debug(1, "BT: deleting %s\n", ethaddrs_str);
+	lbs_deb_ioctl("BT: deleting %s\n", ethaddrs_str);
 
 	return (libertas_prepare_and_send_command(priv,
 				      cmd_bt_access,
 				      cmd_act_bt_access_del,
 				      cmd_option_waitforrsp, 0, ethaddr));
-	LEAVE();
+
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -183,7 +190,7 @@
  */
 static int wlan_bt_reset_ioctl(wlan_private * priv)
 {
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
 
 	lbs_pr_alert( "BT: resetting\n");
 
@@ -192,7 +199,7 @@
 				      cmd_act_bt_access_reset,
 				      cmd_option_waitforrsp, 0, NULL));
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -209,17 +216,17 @@
 	struct iwreq *wrq = (struct iwreq *)req;
 	/* used to pass id and store the bt entry returned by the FW */
 	union {
-		int id;
+		u32 id;
 		char addr1addr2[2 * ETH_ALEN];
 	} param;
 	static char outstr[64];
 	char *pbuf = outstr;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
 
 	if (copy_from_user(outstr, wrq->u.data.pointer, sizeof(outstr))) {
-		lbs_pr_debug(1, "Copy from user failed\n");
+		lbs_deb_ioctl("Copy from user failed\n");
 		return -1;
 	}
 	param.id = simple_strtoul(outstr, NULL, 10);
@@ -234,7 +241,7 @@
 	if (ret == 0) {
 		addr1 = param.addr1addr2;
 
-		pos = sprintf(pbuf, "ignoring traffic from ");
+		pos = sprintf(pbuf, "BT includes node ");
 		pbuf += pos;
 		pos = eth_addr2str(addr1, pbuf);
 		pbuf += pos;
@@ -246,11 +253,70 @@
 	wrq->u.data.length = strlen(outstr);
 	if (copy_to_user(wrq->u.data.pointer, (char *)outstr,
 			 wrq->u.data.length)) {
-		lbs_pr_debug(1, "BT_LIST: Copy to user failed!\n");
+		lbs_deb_ioctl("BT_LIST: Copy to user failed!\n");
 		return -EFAULT;
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
+	return 0 ;
+}
+
+/**
+ *  @brief          Sets inverted state of blacklist (non-zero if inverted)
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         0 --success, otherwise fail
+ */
+static int wlan_bt_set_invert_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int ret;
+	struct iwreq *wrq = (struct iwreq *)req;
+	union {
+		u32 id;
+		char addr1addr2[2 * ETH_ALEN];
+	} param;
+
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
+	param.id = SUBCMD_DATA(wrq) ;
+	ret = libertas_prepare_and_send_command(priv, cmd_bt_access,
+				    cmd_act_bt_access_set_invert,
+				    cmd_option_waitforrsp, 0,
+				    (char *)&param);
+	if (ret != 0)
+		return -EFAULT;
+	lbs_deb_leave(LBS_DEB_IOCTL);
+	return 0;
+}
+
+/**
+ *  @brief          Gets inverted state of blacklist (non-zero if inverted)
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         0 --success, otherwise fail
+ */
+static int wlan_bt_get_invert_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	struct iwreq *wrq = (struct iwreq *)req;
+	int ret;
+	union {
+		u32 id;
+		char addr1addr2[2 * ETH_ALEN];
+	} param;
+
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
+	ret = libertas_prepare_and_send_command(priv, cmd_bt_access,
+				    cmd_act_bt_access_get_invert,
+				    cmd_option_waitforrsp, 0,
+				    (char *)&param);
+
+	if (ret == 0)
+		wrq->u.param.value = le32_to_cpu(param.id);
+	else
+		return -EFAULT;
+
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -278,8 +344,10 @@
 	char in_str[128];
 	static struct cmd_ds_fwt_access fwt_access;
 	char *ptr;
+	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
 	if (copy_from_user(in_str, wrq->u.data.pointer, sizeof(in_str)))
 		return -EFAULT;
 
@@ -297,7 +365,7 @@
 		fwt_access.metric =
 			cpu_to_le32(simple_strtoul(ptr, &ptr, 10));
 	else
-		fwt_access.metric = FWT_DEFAULT_METRIC;
+		fwt_access.metric = cpu_to_le32(FWT_DEFAULT_METRIC);
 
 	if ((ptr = next_param(ptr)))
 		fwt_access.dir = (u8)simple_strtoul(ptr, &ptr, 10);
@@ -305,16 +373,21 @@
 		fwt_access.dir = FWT_DEFAULT_DIR;
 
 	if ((ptr = next_param(ptr)))
+		fwt_access.rate = (u8) simple_strtoul(ptr, &ptr, 10);
+	else
+		fwt_access.rate = FWT_DEFAULT_RATE;
+
+	if ((ptr = next_param(ptr)))
 		fwt_access.ssn =
 			cpu_to_le32(simple_strtoul(ptr, &ptr, 10));
 	else
-		fwt_access.ssn = FWT_DEFAULT_SSN;
+		fwt_access.ssn = cpu_to_le32(FWT_DEFAULT_SSN);
 
 	if ((ptr = next_param(ptr)))
 		fwt_access.dsn =
 			cpu_to_le32(simple_strtoul(ptr, &ptr, 10));
 	else
-		fwt_access.dsn = FWT_DEFAULT_DSN;
+		fwt_access.dsn = cpu_to_le32(FWT_DEFAULT_DSN);
 
 	if ((ptr = next_param(ptr)))
 		fwt_access.hopcount = simple_strtoul(ptr, &ptr, 10);
@@ -330,7 +403,7 @@
 		fwt_access.expiration =
 			cpu_to_le32(simple_strtoul(ptr, &ptr, 10));
 	else
-		fwt_access.expiration = FWT_DEFAULT_EXPIRATION;
+		fwt_access.expiration = cpu_to_le32(FWT_DEFAULT_EXPIRATION);
 
 	if ((ptr = next_param(ptr)))
 		fwt_access.sleepmode = (u8)simple_strtoul(ptr, &ptr, 10);
@@ -341,27 +414,29 @@
 		fwt_access.snr =
 			cpu_to_le32(simple_strtoul(ptr, &ptr, 10));
 	else
-		fwt_access.snr = FWT_DEFAULT_SNR;
+		fwt_access.snr = cpu_to_le32(FWT_DEFAULT_SNR);
 
 #ifdef DEBUG
 	{
 		char ethaddr1_str[18], ethaddr2_str[18];
 		eth_addr2str(fwt_access.da, ethaddr1_str);
 		eth_addr2str(fwt_access.ra, ethaddr2_str);
-		lbs_pr_debug(1, "FWT_ADD: adding (da:%s,%i,ra:%s)\n", ethaddr1_str,
+		lbs_deb_ioctl("FWT_ADD: adding (da:%s,%i,ra:%s)\n", ethaddr1_str,
 		       fwt_access.dir, ethaddr2_str);
-		lbs_pr_debug(1, "FWT_ADD: ssn:%u dsn:%u met:%u hop:%u ttl:%u exp:%u slp:%u snr:%u\n",
+		lbs_deb_ioctl("FWT_ADD: ssn:%u dsn:%u met:%u hop:%u ttl:%u exp:%u slp:%u snr:%u\n",
 		       fwt_access.ssn, fwt_access.dsn, fwt_access.metric,
 		       fwt_access.hopcount, fwt_access.ttl, fwt_access.expiration,
 		       fwt_access.sleepmode, fwt_access.snr);
 	}
 #endif
 
-	LEAVE();
-	return (libertas_prepare_and_send_command(priv, cmd_fwt_access,
-						  cmd_act_fwt_access_add,
-						  cmd_option_waitforrsp, 0,
-						  (void *)&fwt_access));
+	ret = libertas_prepare_and_send_command(priv, cmd_fwt_access,
+						cmd_act_fwt_access_add,
+						cmd_option_waitforrsp, 0,
+						(void *)&fwt_access);
+
+	lbs_deb_leave_args(LBS_DEB_IOCTL, "ret %d", ret);
+	return ret;
 }
 
 /**
@@ -376,8 +451,10 @@
 	char in_str[64];
 	static struct cmd_ds_fwt_access fwt_access;
 	char *ptr;
+	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
 	if (copy_from_user(in_str, wrq->u.data.pointer, sizeof(in_str)))
 		return -EFAULT;
 
@@ -399,20 +476,21 @@
 #ifdef DEBUG
 	{
 		char ethaddr1_str[18], ethaddr2_str[18];
-		lbs_pr_debug(1, "FWT_DEL: line is %s\n", in_str);
+		lbs_deb_ioctl("FWT_DEL: line is %s\n", in_str);
 		eth_addr2str(fwt_access.da, ethaddr1_str);
 		eth_addr2str(fwt_access.ra, ethaddr2_str);
-		lbs_pr_debug(1, "FWT_DEL: removing (da:%s,ra:%s,dir:%d)\n", ethaddr1_str,
+		lbs_deb_ioctl("FWT_DEL: removing (da:%s,ra:%s,dir:%d)\n", ethaddr1_str,
 		       ethaddr2_str, fwt_access.dir);
 	}
 #endif
 
-	LEAVE();
-	return (libertas_prepare_and_send_command(priv,
-						  cmd_fwt_access,
-						  cmd_act_fwt_access_del,
-						  cmd_option_waitforrsp, 0,
-						  (void *)&fwt_access));
+	ret = libertas_prepare_and_send_command(priv,
+						cmd_fwt_access,
+						cmd_act_fwt_access_del,
+						cmd_option_waitforrsp, 0,
+						(void *)&fwt_access);
+	lbs_deb_leave_args(LBS_DEB_IOCTL, "ret %d", ret);
+	return ret;
 }
 
 
@@ -427,15 +505,18 @@
 	buf += eth_addr2str(fwt_access.da, buf);
 	buf += sprintf(buf, " ");
 	buf += eth_addr2str(fwt_access.ra, buf);
+	buf += sprintf(buf, " %u", fwt_access.valid);
 	buf += sprintf(buf, " %u", le32_to_cpu(fwt_access.metric));
 	buf += sprintf(buf, " %u", fwt_access.dir);
+	buf += sprintf(buf, " %u", fwt_access.rate);
 	buf += sprintf(buf, " %u", le32_to_cpu(fwt_access.ssn));
 	buf += sprintf(buf, " %u", le32_to_cpu(fwt_access.dsn));
 	buf += sprintf(buf, " %u", fwt_access.hopcount);
 	buf += sprintf(buf, " %u", fwt_access.ttl);
 	buf += sprintf(buf, " %u", le32_to_cpu(fwt_access.expiration));
 	buf += sprintf(buf, " %u", fwt_access.sleepmode);
-	buf += sprintf(buf, " %u", le32_to_cpu(fwt_access.snr));
+	buf += sprintf(buf, " %u ", le32_to_cpu(fwt_access.snr));
+	buf += eth_addr2str(fwt_access.prec, buf);
 }
 
 /**
@@ -453,7 +534,8 @@
 	static char out_str[128];
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
 	if (copy_from_user(in_str, wrq->u.data.pointer, sizeof(in_str)))
 		return -EFAULT;
 
@@ -465,9 +547,9 @@
 #ifdef DEBUG
 	{
 		char ethaddr1_str[18];
-		lbs_pr_debug(1, "FWT_LOOKUP: line is %s\n", in_str);
+		lbs_deb_ioctl("FWT_LOOKUP: line is %s\n", in_str);
 		eth_addr2str(fwt_access.da, ethaddr1_str);
-		lbs_pr_debug(1, "FWT_LOOKUP: looking for (da:%s)\n", ethaddr1_str);
+		lbs_deb_ioctl("FWT_LOOKUP: looking for (da:%s)\n", ethaddr1_str);
 	}
 #endif
 
@@ -485,11 +567,11 @@
 	wrq->u.data.length = strlen(out_str);
 	if (copy_to_user(wrq->u.data.pointer, (char *)out_str,
 			 wrq->u.data.length)) {
-		lbs_pr_debug(1, "FWT_LOOKUP: Copy to user failed!\n");
+		lbs_deb_ioctl("FWT_LOOKUP: Copy to user failed!\n");
 		return -EFAULT;
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -500,7 +582,7 @@
  */
 static int wlan_fwt_reset_ioctl(wlan_private * priv)
 {
-	lbs_pr_debug(1, "FWT: resetting\n");
+	lbs_deb_ioctl("FWT: resetting\n");
 
 	return (libertas_prepare_and_send_command(priv,
 				      cmd_fwt_access,
@@ -522,18 +604,21 @@
 	char *ptr = in_str;
 	static char out_str[128];
 	char *pbuf = out_str;
-	int ret;
+	int ret = 0;
 
-	ENTER();
-	if (copy_from_user(in_str, wrq->u.data.pointer, sizeof(in_str)))
-		return -EFAULT;
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
+	if (copy_from_user(in_str, wrq->u.data.pointer, sizeof(in_str))) {
+		ret = -EFAULT;
+		goto out;
+	}
 
 	fwt_access.id = cpu_to_le32(simple_strtoul(ptr, &ptr, 10));
 
 #ifdef DEBUG
 	{
-		lbs_pr_debug(1, "FWT_LIST: line is %s\n", in_str);
-		lbs_pr_debug(1, "FWT_LIST: listing id:%i\n", le32_to_cpu(fwt_access.id));
+		lbs_deb_ioctl("FWT_LIST: line is %s\n", in_str);
+		lbs_deb_ioctl("FWT_LIST: listing id:%i\n", le32_to_cpu(fwt_access.id));
 	}
 #endif
 
@@ -549,12 +634,16 @@
 	wrq->u.data.length = strlen(out_str);
 	if (copy_to_user(wrq->u.data.pointer, (char *)out_str,
 			 wrq->u.data.length)) {
-		lbs_pr_debug(1, "FWT_LIST: Copy to user failed!\n");
-		return -EFAULT;
+		lbs_deb_ioctl("FWT_LIST: Copy to user failed!\n");
+		ret = -EFAULT;
+		goto out;
 	}
 
-	LEAVE();
-	return 0;
+	ret = 0;
+
+out:
+	lbs_deb_leave(LBS_DEB_IOCTL);
+	return ret;
 }
 
 /**
@@ -573,7 +662,8 @@
 	char *pbuf = out_str;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
 	if (copy_from_user(in_str, wrq->u.data.pointer, sizeof(in_str)))
 		return -EFAULT;
 
@@ -581,8 +671,8 @@
 
 #ifdef DEBUG
 	{
-		lbs_pr_debug(1, "FWT_LIST_ROUTE: line is %s\n", in_str);
-		lbs_pr_debug(1, "FWT_LIST_ROUTE: listing id:%i\n", le32_to_cpu(fwt_access.id));
+		lbs_deb_ioctl("FWT_LIST_ROUTE: line is %s\n", in_str);
+		lbs_deb_ioctl("FWT_LIST_ROUTE: listing id:%i\n", le32_to_cpu(fwt_access.id));
 	}
 #endif
 
@@ -591,28 +681,18 @@
 				    cmd_option_waitforrsp, 0, (void *)&fwt_access);
 
 	if (ret == 0) {
-		pbuf += sprintf(pbuf, " ");
-		pbuf += eth_addr2str(fwt_access.da, pbuf);
-		pbuf += sprintf(pbuf, " %u", le32_to_cpu(fwt_access.metric));
-		pbuf += sprintf(pbuf, " %u", fwt_access.dir);
-		/* note that the firmware returns the nid in the id field */
-		pbuf += sprintf(pbuf, " %u", le32_to_cpu(fwt_access.id));
-		pbuf += sprintf(pbuf, " %u", le32_to_cpu(fwt_access.ssn));
-		pbuf += sprintf(pbuf, " %u", le32_to_cpu(fwt_access.dsn));
-		pbuf += sprintf(pbuf, "  hop %u", fwt_access.hopcount);
-		pbuf += sprintf(pbuf, "  ttl %u", fwt_access.ttl);
-		pbuf += sprintf(pbuf, " %u", le32_to_cpu(fwt_access.expiration));
+		print_route(fwt_access, pbuf);
 	} else
 		pbuf += sprintf(pbuf, " (null)");
 
 	wrq->u.data.length = strlen(out_str);
 	if (copy_to_user(wrq->u.data.pointer, (char *)out_str,
 			 wrq->u.data.length)) {
-		lbs_pr_debug(1, "FWT_LIST_ROUTE: Copy to user failed!\n");
+		lbs_deb_ioctl("FWT_LIST_ROUTE: Copy to user failed!\n");
 		return -EFAULT;
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -632,7 +712,8 @@
 	char *pbuf = out_str;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
+
 	if (copy_from_user(in_str, wrq->u.data.pointer, sizeof(in_str)))
 		return -EFAULT;
 
@@ -641,8 +722,8 @@
 
 #ifdef DEBUG
 	{
-		lbs_pr_debug(1, "FWT_LIST_NEIGHBOR: line is %s\n", in_str);
-		lbs_pr_debug(1, "FWT_LIST_NEIGHBOR: listing id:%i\n", le32_to_cpu(fwt_access.id));
+		lbs_deb_ioctl("FWT_LIST_NEIGHBOR: line is %s\n", in_str);
+		lbs_deb_ioctl("FWT_LIST_NEIGHBOR: listing id:%i\n", le32_to_cpu(fwt_access.id));
 	}
 #endif
 
@@ -663,11 +744,11 @@
 	wrq->u.data.length = strlen(out_str);
 	if (copy_to_user(wrq->u.data.pointer, (char *)out_str,
 			 wrq->u.data.length)) {
-		lbs_pr_debug(1, "FWT_LIST_NEIGHBOR: Copy to user failed!\n");
+		lbs_deb_ioctl("FWT_LIST_NEIGHBOR: Copy to user failed!\n");
 		return -EFAULT;
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -684,9 +765,9 @@
 	static struct cmd_ds_fwt_access fwt_access;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
 
-	lbs_pr_debug(1, "FWT: cleaning up\n");
+	lbs_deb_ioctl("FWT: cleaning up\n");
 
 	memset(&fwt_access, 0, sizeof(fwt_access));
 
@@ -700,7 +781,7 @@
 	else
 		return -EFAULT;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -716,9 +797,9 @@
 	static struct cmd_ds_fwt_access fwt_access;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
 
-	lbs_pr_debug(1, "FWT: getting time\n");
+	lbs_deb_ioctl("FWT: getting time\n");
 
 	memset(&fwt_access, 0, sizeof(fwt_access));
 
@@ -732,7 +813,7 @@
 	else
 		return -EFAULT;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -748,7 +829,7 @@
 	struct cmd_ds_mesh_access mesh_access;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
 
 	memset(&mesh_access, 0, sizeof(mesh_access));
 
@@ -762,7 +843,7 @@
 	else
 		return -EFAULT;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return 0;
 }
 
@@ -777,13 +858,13 @@
 	struct cmd_ds_mesh_access mesh_access;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
 
 	if( (ttl > 0xff) || (ttl < 0) )
 		return -EINVAL;
 
 	memset(&mesh_access, 0, sizeof(mesh_access));
-	mesh_access.data[0] = ttl;
+	mesh_access.data[0] = cpu_to_le32(ttl);
 
 	ret = libertas_prepare_and_send_command(priv, cmd_mesh_access,
 						cmd_act_mesh_set_ttl,
@@ -793,7 +874,7 @@
 	if (ret != 0)
 		ret = -EFAULT;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_IOCTL);
 	return ret;
 }
 
@@ -815,9 +896,9 @@
 	wlan_adapter *adapter = priv->adapter;
 	struct iwreq *wrq = (struct iwreq *)req;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_IOCTL);
 
-	lbs_pr_debug(1, "libertas_do_ioctl: ioctl cmd = 0x%x\n", cmd);
+	lbs_deb_ioctl("libertas_do_ioctl: ioctl cmd = 0x%x\n", cmd);
 	switch (cmd) {
 	case WLAN_SETNONE_GETNONE:	/* set WPA mode on/off ioctl #20 */
 		switch (wrq->u.data.flags) {
@@ -848,6 +929,10 @@
 			ret = wlan_mesh_set_ttl_ioctl(priv, idata);
 			break;
 
+		case WLAN_SUBCMD_BT_SET_INVERT:
+			ret = wlan_bt_set_invert_ioctl(priv, req);
+			break ;
+
 		default:
 			ret = -EOPNOTSUPP;
 			break;
@@ -905,6 +990,10 @@
 			ret = wlan_mesh_get_ttl_ioctl(priv, req);
 			break;
 
+		case WLAN_SUBCMD_BT_GET_INVERT:
+			ret = wlan_bt_get_invert_ioctl(priv, req);
+			break ;
+
 		default:
 			ret = -EOPNOTSUPP;
 
@@ -937,7 +1026,7 @@
 					    (data, wrq->u.data.pointer,
 					     sizeof(int) *
 					     wrq->u.data.length)) {
-						lbs_pr_debug(1,
+						lbs_deb_ioctl(
 						       "Copy from user failed\n");
 						return -EFAULT;
 					}
@@ -970,7 +1059,7 @@
 				if (copy_to_user(wrq->u.data.pointer, data,
 						 sizeof(int) *
 						 gpio->header.len)) {
-					lbs_pr_debug(1, "Copy to user failed\n");
+					lbs_deb_ioctl("Copy to user failed\n");
 					return -EFAULT;
 				}
 
@@ -984,7 +1073,8 @@
 		ret = -EINVAL;
 		break;
 	}
-	LEAVE();
+
+	lbs_deb_leave_args(LBS_DEB_IOCTL, "ret %d", ret);
 	return ret;
 }
 
diff --git a/drivers/net/wireless/libertas/join.c b/drivers/net/wireless/libertas/join.c
index d4926b8..78ac306 100644
--- a/drivers/net/wireless/libertas/join.c
+++ b/drivers/net/wireless/libertas/join.c
@@ -7,6 +7,7 @@
 #include <linux/netdevice.h>
 #include <linux/if_arp.h>
 #include <linux/wireless.h>
+#include <linux/etherdevice.h>
 
 #include <net/iw_handler.h>
 
@@ -14,6 +15,7 @@
 #include "decl.h"
 #include "join.h"
 #include "dev.h"
+#include "assoc.h"
 
 #define AD_HOC_CAP_PRIVACY_ON 1
 
@@ -60,7 +62,7 @@
 	lbs_dbg_hex("rate1 (AP) rates:", tmp, sizeof(tmp));
 	lbs_dbg_hex("rate2 (Card) rates:", rate2, rate2_size);
 	lbs_dbg_hex("Common rates:", ptr, rate1_size);
-	lbs_pr_debug(1, "Tx datarate is set to 0x%X\n", adapter->datarate);
+	lbs_deb_join("Tx datarate is set to 0x%X\n", adapter->datarate);
 
 	if (!adapter->is_datarate_auto) {
 		while (*ptr) {
@@ -104,24 +106,22 @@
  *
  *  @return          0-success, otherwise fail
  */
-int wlan_associate(wlan_private * priv, struct bss_descriptor * pbssdesc)
+int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
 {
 	wlan_adapter *adapter = priv->adapter;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
 
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_authenticate,
 				    0, cmd_option_waitforrsp,
-				    0, pbssdesc->macaddress);
+				    0, assoc_req->bss.bssid);
 
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
+	if (ret)
+		goto done;
 
 	/* set preamble to firmware */
-	if (adapter->capinfo.shortpreamble && pbssdesc->cap.shortpreamble)
+	if (adapter->capinfo.shortpreamble && assoc_req->bss.cap.shortpreamble)
 		adapter->preamble = cmd_type_short_preamble;
 	else
 		adapter->preamble = cmd_type_long_preamble;
@@ -129,9 +129,10 @@
 	libertas_set_radio_control(priv);
 
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_associate,
-				    0, cmd_option_waitforrsp, 0, pbssdesc);
+				    0, cmd_option_waitforrsp, 0, assoc_req);
 
-	LEAVE();
+done:
+	lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
 	return ret;
 }
 
@@ -142,7 +143,7 @@
  *  @param adhocssid    The ssid of the Adhoc Network
  *  @return             0--success, -1--fail
  */
-int libertas_start_adhoc_network(wlan_private * priv, struct WLAN_802_11_SSID *adhocssid)
+int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
 {
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
@@ -150,22 +151,20 @@
 	adapter->adhoccreate = 1;
 
 	if (!adapter->capinfo.shortpreamble) {
-		lbs_pr_debug(1, "AdhocStart: Long preamble\n");
+		lbs_deb_join("AdhocStart: Long preamble\n");
 		adapter->preamble = cmd_type_long_preamble;
 	} else {
-		lbs_pr_debug(1, "AdhocStart: Short preamble\n");
+		lbs_deb_join("AdhocStart: Short preamble\n");
 		adapter->preamble = cmd_type_short_preamble;
 	}
 
 	libertas_set_radio_control(priv);
 
-	lbs_pr_debug(1, "Adhoc channel = %d\n", adapter->adhocchannel);
-	lbs_pr_debug(1, "curbssparams.channel = %d\n",
-	       adapter->curbssparams.channel);
-	lbs_pr_debug(1, "curbssparams.band = %d\n", adapter->curbssparams.band);
+	lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
+	lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
 
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_start,
-				    0, cmd_option_waitforrsp, 0, adhocssid);
+				    0, cmd_option_waitforrsp, 0, assoc_req);
 
 	return ret;
 }
@@ -179,52 +178,53 @@
  *
  *  @return             0--success, -1--fail
  */
-int libertas_join_adhoc_network(wlan_private * priv, struct bss_descriptor * pbssdesc)
+int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
 {
 	wlan_adapter *adapter = priv->adapter;
+	struct bss_descriptor * bss = &assoc_req->bss;
 	int ret = 0;
 
-	lbs_pr_debug(1, "libertas_join_adhoc_network: CurBss.ssid =%s\n",
-	       adapter->curbssparams.ssid.ssid);
-	lbs_pr_debug(1, "libertas_join_adhoc_network: CurBss.ssid_len =%u\n",
-	       adapter->curbssparams.ssid.ssidlength);
-	lbs_pr_debug(1, "libertas_join_adhoc_network: ssid =%s\n", pbssdesc->ssid.ssid);
-	lbs_pr_debug(1, "libertas_join_adhoc_network: ssid len =%u\n",
-	       pbssdesc->ssid.ssidlength);
+	lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
+	             __func__,
+	             escape_essid(adapter->curbssparams.ssid,
+	                          adapter->curbssparams.ssid_len),
+	             adapter->curbssparams.ssid_len);
+	lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
+	             __func__, escape_essid(bss->ssid, bss->ssid_len),
+	             bss->ssid_len);
 
 	/* check if the requested SSID is already joined */
-	if (adapter->curbssparams.ssid.ssidlength
-	    && !libertas_SSID_cmp(&pbssdesc->ssid, &adapter->curbssparams.ssid)
+	if (adapter->curbssparams.ssid_len
+	    && !libertas_ssid_cmp(adapter->curbssparams.ssid,
+	                          adapter->curbssparams.ssid_len,
+	                          bss->ssid, bss->ssid_len)
 	    && (adapter->mode == IW_MODE_ADHOC)) {
-
-        lbs_pr_debug(1,
+		lbs_deb_join(
 		       "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
 		       "not attempting to re-join");
-
 		return -1;
 	}
 
 	/*Use shortpreamble only when both creator and card supports
 	   short preamble */
-	if (!pbssdesc->cap.shortpreamble || !adapter->capinfo.shortpreamble) {
-		lbs_pr_debug(1, "AdhocJoin: Long preamble\n");
+	if (!bss->cap.shortpreamble || !adapter->capinfo.shortpreamble) {
+		lbs_deb_join("AdhocJoin: Long preamble\n");
 		adapter->preamble = cmd_type_long_preamble;
 	} else {
-		lbs_pr_debug(1, "AdhocJoin: Short preamble\n");
+		lbs_deb_join("AdhocJoin: Short preamble\n");
 		adapter->preamble = cmd_type_short_preamble;
 	}
 
 	libertas_set_radio_control(priv);
 
-	lbs_pr_debug(1, "curbssparams.channel = %d\n",
-	       adapter->curbssparams.channel);
-	lbs_pr_debug(1, "curbssparams.band = %c\n", adapter->curbssparams.band);
+	lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
+	lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
 
 	adapter->adhoccreate = 0;
 
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_join,
 				    0, cmd_option_waitforrsp,
-				    OID_802_11_SSID, pbssdesc);
+				    OID_802_11_SSID, assoc_req);
 
 	return ret;
 }
@@ -265,6 +265,8 @@
 	int ret = -1;
 	u8 *bssid = pdata_buf;
 
+	lbs_deb_enter(LBS_DEB_JOIN);
+
 	cmd->command = cpu_to_le16(cmd_802_11_authenticate);
 	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
 	                        + S_DS_GEN);
@@ -281,18 +283,19 @@
 		pauthenticate->authtype = 0x80;
 		break;
 	default:
-		lbs_pr_debug(1, "AUTH_CMD: invalid auth alg 0x%X\n",
+		lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
 		             adapter->secinfo.auth_mode);
 		goto out;
 	}
 
 	memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
 
-	lbs_pr_debug(1, "AUTH_CMD: Bssid is : %x:%x:%x:%x:%x:%x\n",
-	       bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
+	lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
+	             MAC_ARG(bssid), pauthenticate->authtype);
 	ret = 0;
 
 out:
+	lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
 	return ret;
 }
 
@@ -302,22 +305,20 @@
 	wlan_adapter *adapter = priv->adapter;
 	struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
 
 	cmd->command = cpu_to_le16(cmd_802_11_deauthenticate);
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
 			     S_DS_GEN);
 
 	/* set AP MAC address */
-	memmove(dauth->macaddr, adapter->curbssparams.bssid,
-		ETH_ALEN);
+	memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
 
 	/* Reason code 3 = Station is leaving */
 #define REASON_CODE_STA_LEAVING 3
 	dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_JOIN);
 	return 0;
 }
 
@@ -327,20 +328,20 @@
 	wlan_adapter *adapter = priv->adapter;
 	struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
 	int ret = 0;
-	struct bss_descriptor *pbssdesc;
+	struct assoc_request * assoc_req = pdata_buf;
+	struct bss_descriptor * bss = &assoc_req->bss;
 	u8 *card_rates;
 	u8 *pos;
 	int card_rates_size;
-	u16 tmpcap;
+	u16 tmpcap, tmplen;
 	struct mrvlietypes_ssidparamset *ssid;
 	struct mrvlietypes_phyparamset *phy;
 	struct mrvlietypes_ssparamset *ss;
 	struct mrvlietypes_ratesparamset *rates;
 	struct mrvlietypes_rsnparamset *rsn;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
 
-	pbssdesc = pdata_buf;
 	pos = (u8 *) passo;
 
 	if (!adapter) {
@@ -350,15 +351,11 @@
 
 	cmd->command = cpu_to_le16(cmd_802_11_associate);
 
-	/* Save so we know which BSS Desc to use in the response handler */
-	adapter->pattemptedbssdesc = pbssdesc;
-
-	memcpy(passo->peerstaaddr,
-	       pbssdesc->macaddress, sizeof(passo->peerstaaddr));
+	memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
 	pos += sizeof(passo->peerstaaddr);
 
 	/* set the listen interval */
-	passo->listeninterval = adapter->listeninterval;
+	passo->listeninterval = cpu_to_le16(adapter->listeninterval);
 
 	pos += sizeof(passo->capinfo);
 	pos += sizeof(passo->listeninterval);
@@ -367,30 +364,30 @@
 
 	ssid = (struct mrvlietypes_ssidparamset *) pos;
 	ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
-	ssid->header.len = pbssdesc->ssid.ssidlength;
-	memcpy(ssid->ssid, pbssdesc->ssid.ssid, ssid->header.len);
-	pos += sizeof(ssid->header) + ssid->header.len;
-	ssid->header.len = cpu_to_le16(ssid->header.len);
+	tmplen = bss->ssid_len;
+	ssid->header.len = cpu_to_le16(tmplen);
+	memcpy(ssid->ssid, bss->ssid, tmplen);
+	pos += sizeof(ssid->header) + tmplen;
 
 	phy = (struct mrvlietypes_phyparamset *) pos;
 	phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
-	phy->header.len = sizeof(phy->fh_ds.dsparamset);
+	tmplen = sizeof(phy->fh_ds.dsparamset);
+	phy->header.len = cpu_to_le16(tmplen);
 	memcpy(&phy->fh_ds.dsparamset,
-	       &pbssdesc->phyparamset.dsparamset.currentchan,
-	       sizeof(phy->fh_ds.dsparamset));
-	pos += sizeof(phy->header) + phy->header.len;
-	phy->header.len = cpu_to_le16(phy->header.len);
+	       &bss->phyparamset.dsparamset.currentchan,
+	       tmplen);
+	pos += sizeof(phy->header) + tmplen;
 
 	ss = (struct mrvlietypes_ssparamset *) pos;
 	ss->header.type = cpu_to_le16(TLV_TYPE_CF);
-	ss->header.len = sizeof(ss->cf_ibss.cfparamset);
-	pos += sizeof(ss->header) + ss->header.len;
-	ss->header.len = cpu_to_le16(ss->header.len);
+	tmplen = sizeof(ss->cf_ibss.cfparamset);
+	ss->header.len = cpu_to_le16(tmplen);
+	pos += sizeof(ss->header) + tmplen;
 
 	rates = (struct mrvlietypes_ratesparamset *) pos;
 	rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
 
-	memcpy(&rates->rates, &pbssdesc->libertas_supported_rates, WLAN_SUPPORTED_RATES);
+	memcpy(&rates->rates, &bss->libertas_supported_rates, WLAN_SUPPORTED_RATES);
 
 	card_rates = libertas_supported_rates;
 	card_rates_size = sizeof(libertas_supported_rates);
@@ -401,41 +398,42 @@
 		goto done;
 	}
 
-	rates->header.len = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
-	adapter->curbssparams.numofrates = rates->header.len;
+	tmplen = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
+	adapter->curbssparams.numofrates = tmplen;
 
-	pos += sizeof(rates->header) + rates->header.len;
-	rates->header.len = cpu_to_le16(rates->header.len);
+	pos += sizeof(rates->header) + tmplen;
+	rates->header.len = cpu_to_le16(tmplen);
 
-	if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
+	if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
 		rsn = (struct mrvlietypes_rsnparamset *) pos;
-		rsn->header.type = (u16) adapter->wpa_ie[0];	/* WPA_IE or WPA2_IE */
-		rsn->header.type = cpu_to_le16(rsn->header.type);
-		rsn->header.len = (u16) adapter->wpa_ie[1];
-		memcpy(rsn->rsnie, &adapter->wpa_ie[2], rsn->header.len);
+		/* WPA_IE or WPA2_IE */
+		rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
+		tmplen = (u16) assoc_req->wpa_ie[1];
+		rsn->header.len = cpu_to_le16(tmplen);
+		memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
 		lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
-			sizeof(rsn->header) + rsn->header.len);
-		pos += sizeof(rsn->header) + rsn->header.len;
-		rsn->header.len = cpu_to_le16(rsn->header.len);
+			sizeof(rsn->header) + tmplen);
+		pos += sizeof(rsn->header) + tmplen;
 	}
 
 	/* update curbssparams */
-	adapter->curbssparams.channel =
-	    (pbssdesc->phyparamset.dsparamset.currentchan);
+	adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
 
 	/* Copy the infra. association rates into Current BSS state structure */
 	memcpy(&adapter->curbssparams.datarates, &rates->rates,
-	       min_t(size_t, sizeof(adapter->curbssparams.datarates), rates->header.len));
+	       min_t(size_t, sizeof(adapter->curbssparams.datarates),
+		     cpu_to_le16(rates->header.len)));
 
-	lbs_pr_debug(1, "ASSOC_CMD: rates->header.len = %d\n", rates->header.len);
+	lbs_deb_join("ASSOC_CMD: rates->header.len = %d\n",
+		     cpu_to_le16(rates->header.len));
 
 	/* set IBSS field */
-	if (pbssdesc->mode == IW_MODE_INFRA) {
+	if (bss->mode == IW_MODE_INFRA) {
 #define CAPINFO_ESS_MODE 1
 		passo->capinfo.ess = CAPINFO_ESS_MODE;
 	}
 
-	if (libertas_parse_dnld_countryinfo_11d(priv)) {
+	if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
 		ret = -1;
 		goto done;
 	}
@@ -443,31 +441,28 @@
 	cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
 
 	/* set the capability info at last */
-	memcpy(&tmpcap, &pbssdesc->cap, sizeof(passo->capinfo));
+	memcpy(&tmpcap, &bss->cap, sizeof(passo->capinfo));
 	tmpcap &= CAPINFO_MASK;
-	lbs_pr_debug(1, "ASSOC_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
-	       tmpcap, CAPINFO_MASK);
-	tmpcap = cpu_to_le16(tmpcap);
+	lbs_deb_join("ASSOC_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
+		     tmpcap, CAPINFO_MASK);
 	memcpy(&passo->capinfo, &tmpcap, sizeof(passo->capinfo));
 
-      done:
-	LEAVE();
+done:
+	lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
 	return ret;
 }
 
 int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
-				 struct cmd_ds_command *cmd, void *pssid)
+				 struct cmd_ds_command *cmd, void *pdata_buf)
 {
 	wlan_adapter *adapter = priv->adapter;
 	struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
 	int ret = 0;
 	int cmdappendsize = 0;
 	int i;
-	u16 tmpcap;
-	struct bss_descriptor *pbssdesc;
-	struct WLAN_802_11_SSID *ssid = pssid;
+	struct assoc_request * assoc_req = pdata_buf;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
 
 	if (!adapter) {
 		ret = -1;
@@ -476,9 +471,6 @@
 
 	cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_start);
 
-	pbssdesc = &adapter->curbssparams.bssdescriptor;
-	adapter->pattemptedbssdesc = pbssdesc;
-
 	/*
 	 * Fill in the parameters for 2 data structures:
 	 *   1. cmd_ds_802_11_ad_hoc_start command
@@ -492,20 +484,16 @@
 	 */
 
 	memset(adhs->SSID, 0, IW_ESSID_MAX_SIZE);
+	memcpy(adhs->SSID, assoc_req->ssid, assoc_req->ssid_len);
 
-	memcpy(adhs->SSID, ssid->ssid, ssid->ssidlength);
-
-	lbs_pr_debug(1, "ADHOC_S_CMD: SSID = %s\n", adhs->SSID);
-
-	memset(pbssdesc->ssid.ssid, 0, IW_ESSID_MAX_SIZE);
-	memcpy(pbssdesc->ssid.ssid, ssid->ssid, ssid->ssidlength);
-
-	pbssdesc->ssid.ssidlength = ssid->ssidlength;
+	lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
+	             escape_essid(assoc_req->ssid, assoc_req->ssid_len),
+	             assoc_req->ssid_len);
 
 	/* set the BSS type */
 	adhs->bsstype = cmd_bss_type_ibss;
-	pbssdesc->mode = IW_MODE_ADHOC;
-	adhs->beaconperiod = adapter->beaconperiod;
+	adapter->mode = IW_MODE_ADHOC;
+	adhs->beaconperiod = cpu_to_le16(adapter->beaconperiod);
 
 	/* set Physical param set */
 #define DS_PARA_IE_ID   3
@@ -514,18 +502,12 @@
 	adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
 	adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
 
-	WARN_ON(!adapter->adhocchannel);
+	WARN_ON(!assoc_req->channel);
 
-	lbs_pr_debug(1, "ADHOC_S_CMD: Creating ADHOC on channel %d\n",
-	       adapter->adhocchannel);
+	lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
+		     assoc_req->channel);
 
-	adapter->curbssparams.channel = adapter->adhocchannel;
-
-	pbssdesc->channel = adapter->adhocchannel;
-	adhs->phyparamset.dsparamset.currentchan = adapter->adhocchannel;
-
-	memcpy(&pbssdesc->phyparamset,
-	       &adhs->phyparamset, sizeof(union ieeetypes_phyparamset));
+	adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
 
 	/* set IBSS param set */
 #define IBSS_PARA_IE_ID   6
@@ -533,26 +515,21 @@
 
 	adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
 	adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
-	adhs->ssparamset.ibssparamset.atimwindow = adapter->atimwindow;
-	memcpy(&pbssdesc->ssparamset,
-	       &adhs->ssparamset, sizeof(union IEEEtypes_ssparamset));
+	adhs->ssparamset.ibssparamset.atimwindow = cpu_to_le16(adapter->atimwindow);
 
 	/* set capability info */
 	adhs->cap.ess = 0;
 	adhs->cap.ibss = 1;
-	pbssdesc->cap.ibss = 1;
 
 	/* probedelay */
 	adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
 
 	/* set up privacy in adapter->scantable[i] */
-	if (adapter->secinfo.wep_enabled) {
-		lbs_pr_debug(1, "ADHOC_S_CMD: WEP enabled, setting privacy on\n");
-		pbssdesc->privacy = wlan802_11privfilter8021xWEP;
+	if (assoc_req->secinfo.wep_enabled) {
+		lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
 		adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON;
 	} else {
-		lbs_pr_debug(1, "ADHOC_S_CMD: WEP disabled, setting privacy off\n");
-		pbssdesc->privacy = wlan802_11privfilteracceptall;
+		lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
 	}
 
 	memset(adhs->datarate, 0, sizeof(adhs->datarate));
@@ -574,29 +551,24 @@
 	memcpy(&adapter->curbssparams.datarates,
 	       &adhs->datarate, adapter->curbssparams.numofrates);
 
-	lbs_pr_debug(1, "ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
+	lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
 	       adhs->datarate[0], adhs->datarate[1],
 	       adhs->datarate[2], adhs->datarate[3]);
 
-	lbs_pr_debug(1, "ADHOC_S_CMD: AD HOC Start command is ready\n");
+	lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
 
 	if (libertas_create_dnld_countryinfo_11d(priv)) {
-		lbs_pr_debug(1, "ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
+		lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
 		ret = -1;
 		goto done;
 	}
 
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start)
-			     + S_DS_GEN + cmdappendsize);
-
-	memcpy(&tmpcap, &adhs->cap, sizeof(u16));
-	tmpcap = cpu_to_le16(tmpcap);
-	memcpy(&adhs->cap, &tmpcap, sizeof(u16));
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
+				S_DS_GEN + cmdappendsize);
 
 	ret = 0;
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
 	return ret;
 }
 
@@ -614,7 +586,8 @@
 {
 	wlan_adapter *adapter = priv->adapter;
 	struct cmd_ds_802_11_ad_hoc_join *padhocjoin = &cmd->params.adj;
-	struct bss_descriptor *pbssdesc = pdata_buf;
+	struct assoc_request * assoc_req = pdata_buf;
+	struct bss_descriptor *bss = &assoc_req->bss;
 	int cmdappendsize = 0;
 	int ret = 0;
 	u8 *card_rates;
@@ -622,70 +595,59 @@
 	u16 tmpcap;
 	int i;
 
-	ENTER();
-
-	adapter->pattemptedbssdesc = pbssdesc;
+	lbs_deb_enter(LBS_DEB_JOIN);
 
 	cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_join);
 
 	padhocjoin->bssdescriptor.bsstype = cmd_bss_type_ibss;
 
-	padhocjoin->bssdescriptor.beaconperiod = pbssdesc->beaconperiod;
+	padhocjoin->bssdescriptor.beaconperiod = cpu_to_le16(bss->beaconperiod);
 
-	memcpy(&padhocjoin->bssdescriptor.BSSID,
-	       &pbssdesc->macaddress, ETH_ALEN);
-
-	memcpy(&padhocjoin->bssdescriptor.SSID,
-	       &pbssdesc->ssid.ssid, pbssdesc->ssid.ssidlength);
+	memcpy(&padhocjoin->bssdescriptor.BSSID, &bss->bssid, ETH_ALEN);
+	memcpy(&padhocjoin->bssdescriptor.SSID, &bss->ssid, bss->ssid_len);
 
 	memcpy(&padhocjoin->bssdescriptor.phyparamset,
-	       &pbssdesc->phyparamset, sizeof(union ieeetypes_phyparamset));
+	       &bss->phyparamset, sizeof(union ieeetypes_phyparamset));
 
 	memcpy(&padhocjoin->bssdescriptor.ssparamset,
-	       &pbssdesc->ssparamset, sizeof(union IEEEtypes_ssparamset));
+	       &bss->ssparamset, sizeof(union IEEEtypes_ssparamset));
 
-	memcpy(&tmpcap, &pbssdesc->cap, sizeof(struct ieeetypes_capinfo));
+	memcpy(&tmpcap, &bss->cap, sizeof(struct ieeetypes_capinfo));
 	tmpcap &= CAPINFO_MASK;
 
-	lbs_pr_debug(1, "ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
+	lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
 	       tmpcap, CAPINFO_MASK);
 	memcpy(&padhocjoin->bssdescriptor.cap, &tmpcap,
 	       sizeof(struct ieeetypes_capinfo));
 
 	/* information on BSSID descriptor passed to FW */
-    lbs_pr_debug(1,
-	       "ADHOC_J_CMD: BSSID = %2x-%2x-%2x-%2x-%2x-%2x, SSID = %s\n",
-	       padhocjoin->bssdescriptor.BSSID[0],
-	       padhocjoin->bssdescriptor.BSSID[1],
-	       padhocjoin->bssdescriptor.BSSID[2],
-	       padhocjoin->bssdescriptor.BSSID[3],
-	       padhocjoin->bssdescriptor.BSSID[4],
-	       padhocjoin->bssdescriptor.BSSID[5],
+	lbs_deb_join(
+	       "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
+	       MAC_ARG(padhocjoin->bssdescriptor.BSSID),
 	       padhocjoin->bssdescriptor.SSID);
 
 	/* failtimeout */
 	padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
 
 	/* probedelay */
-	padhocjoin->probedelay =
-	    cpu_to_le16(cmd_scan_probe_delay_time);
+	padhocjoin->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
 
 	/* Copy Data rates from the rates recorded in scan response */
 	memset(padhocjoin->bssdescriptor.datarates, 0,
 	       sizeof(padhocjoin->bssdescriptor.datarates));
-	memcpy(padhocjoin->bssdescriptor.datarates, pbssdesc->datarates,
+	memcpy(padhocjoin->bssdescriptor.datarates, bss->datarates,
 	       min(sizeof(padhocjoin->bssdescriptor.datarates),
-		   sizeof(pbssdesc->datarates)));
+		   sizeof(bss->datarates)));
 
 	card_rates = libertas_supported_rates;
 	card_rates_size = sizeof(libertas_supported_rates);
 
-	adapter->curbssparams.channel = pbssdesc->channel;
+	adapter->curbssparams.channel = bss->channel;
 
 	if (get_common_rates(adapter, padhocjoin->bssdescriptor.datarates,
 			     sizeof(padhocjoin->bssdescriptor.datarates),
 			     card_rates, card_rates_size)) {
-		lbs_pr_debug(1, "ADHOC_J_CMD: get_common_rates returns error.\n");
+		lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
 		ret = -1;
 		goto done;
 	}
@@ -704,17 +666,17 @@
 	       adapter->curbssparams.numofrates);
 
 	padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow =
-	    cpu_to_le16(pbssdesc->atimwindow);
+	    cpu_to_le16(bss->atimwindow);
 
-	if (adapter->secinfo.wep_enabled) {
+	if (assoc_req->secinfo.wep_enabled) {
 		padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON;
 	}
 
 	if (adapter->psmode == wlan802_11powermodemax_psp) {
 		/* wake up first */
-		enum WLAN_802_11_POWER_MODE Localpsmode;
+		__le32 Localpsmode;
 
-		Localpsmode = wlan802_11powermodecam;
+		Localpsmode = cpu_to_le32(wlan802_11powermodecam);
 		ret = libertas_prepare_and_send_command(priv,
 					    cmd_802_11_ps_mode,
 					    cmd_act_set,
@@ -726,24 +688,16 @@
 		}
 	}
 
-	if (libertas_parse_dnld_countryinfo_11d(priv)) {
+	if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
 		ret = -1;
 		goto done;
 	}
 
-	cmd->size =
-	    cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join)
-			     + S_DS_GEN + cmdappendsize);
+	cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
+				S_DS_GEN + cmdappendsize);
 
-	memcpy(&tmpcap, &padhocjoin->bssdescriptor.cap,
-	       sizeof(struct ieeetypes_capinfo));
-	tmpcap = cpu_to_le16(tmpcap);
-
-	memcpy(&padhocjoin->bssdescriptor.cap,
-	       &tmpcap, sizeof(struct ieeetypes_capinfo));
-
-      done:
-	LEAVE();
+done:
+	lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
 	return ret;
 }
 
@@ -754,19 +708,24 @@
 	int ret = 0;
 	union iwreq_data wrqu;
 	struct ieeetypes_assocrsp *passocrsp;
-	struct bss_descriptor *pbssdesc;
+	struct bss_descriptor * bss;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
+
+	if (!adapter->in_progress_assoc_req) {
+		lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
+		ret = -1;
+		goto done;
+	}
+	bss = &adapter->in_progress_assoc_req->bss;
 
 	passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
 
-	if (passocrsp->statuscode) {
-
+	if (le16_to_cpu(passocrsp->statuscode)) {
 		libertas_mac_event_disconnected(priv);
 
-        lbs_pr_debug(1,
-		       "ASSOC_RESP: Association failed, status code = %d\n",
-		       passocrsp->statuscode);
+		lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
+			     le16_to_cpu(passocrsp->statuscode));
 
 		ret = -1;
 		goto done;
@@ -778,24 +737,15 @@
 	/* Send a Media Connected event, according to the Spec */
 	adapter->connect_status = libertas_connected;
 
-	/* Set the attempted BSSID Index to current */
-	pbssdesc = adapter->pattemptedbssdesc;
+	lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
+	             escape_essid(bss->ssid, bss->ssid_len));
 
-	lbs_pr_debug(1, "ASSOC_RESP: %s\n", pbssdesc->ssid.ssid);
+	/* Update current SSID and BSSID */
+	memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
+	adapter->curbssparams.ssid_len = bss->ssid_len;
+	memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
 
-	/* Set the new SSID to current SSID */
-	memcpy(&adapter->curbssparams.ssid,
-	       &pbssdesc->ssid, sizeof(struct WLAN_802_11_SSID));
-
-	/* Set the new BSSID (AP's MAC address) to current BSSID */
-	memcpy(adapter->curbssparams.bssid,
-	       pbssdesc->macaddress, ETH_ALEN);
-
-	/* Make a copy of current BSSID descriptor */
-	memcpy(&adapter->curbssparams.bssdescriptor,
-	       pbssdesc, sizeof(struct bss_descriptor));
-
-	lbs_pr_debug(1, "ASSOC_RESP: currentpacketfilter is %x\n",
+	lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
 	       adapter->currentpacketfilter);
 
 	adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
@@ -806,28 +756,31 @@
 	adapter->nextSNRNF = 0;
 	adapter->numSNRNF = 0;
 
-	netif_carrier_on(priv->wlan_dev.netdev);
-	netif_wake_queue(priv->wlan_dev.netdev);
+	netif_carrier_on(priv->dev);
+	netif_wake_queue(priv->dev);
 
-	lbs_pr_debug(1, "ASSOC_RESP: Associated \n");
+	netif_carrier_on(priv->mesh_dev);
+	netif_wake_queue(priv->mesh_dev);
+
+	lbs_deb_join("ASSOC_RESP: Associated \n");
 
 	memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
 	wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-	wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
+	wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
 
-      done:
-	LEAVE();
+done:
+	lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
 	return ret;
 }
 
 int libertas_ret_80211_disassociate(wlan_private * priv,
 				 struct cmd_ds_command *resp)
 {
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
 
 	libertas_mac_event_disconnected(priv);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_JOIN);
 	return 0;
 }
 
@@ -840,90 +793,85 @@
 	u16 result = le16_to_cpu(resp->result);
 	struct cmd_ds_802_11_ad_hoc_result *padhocresult;
 	union iwreq_data wrqu;
-	struct bss_descriptor *pbssdesc;
+	struct bss_descriptor *bss;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
 
 	padhocresult = &resp->params.result;
 
-	lbs_pr_debug(1, "ADHOC_S_RESP: size = %d\n", le16_to_cpu(resp->size));
-	lbs_pr_debug(1, "ADHOC_S_RESP: command = %x\n", command);
-	lbs_pr_debug(1, "ADHOC_S_RESP: result = %x\n", result);
+	lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
+	lbs_deb_join("ADHOC_RESP: command = %x\n", command);
+	lbs_deb_join("ADHOC_RESP: result = %x\n", result);
 
-	pbssdesc = adapter->pattemptedbssdesc;
+	if (!adapter->in_progress_assoc_req) {
+		lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
+		ret = -1;
+		goto done;
+	}
+	bss = &adapter->in_progress_assoc_req->bss;
 
 	/*
 	 * Join result code 0 --> SUCCESS
 	 */
 	if (result) {
-		lbs_pr_debug(1, "ADHOC_RESP failed\n");
+		lbs_deb_join("ADHOC_RESP: failed\n");
 		if (adapter->connect_status == libertas_connected) {
 			libertas_mac_event_disconnected(priv);
 		}
-
-		memset(&adapter->curbssparams.bssdescriptor,
-		       0x00, sizeof(adapter->curbssparams.bssdescriptor));
-
-		LEAVE();
-		return -1;
+		ret = -1;
+		goto done;
 	}
 
 	/*
 	 * Now the join cmd should be successful
 	 * If BSSID has changed use SSID to compare instead of BSSID
 	 */
-	lbs_pr_debug(1, "ADHOC_J_RESP  %s\n", pbssdesc->ssid.ssid);
+	lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
+	             escape_essid(bss->ssid, bss->ssid_len));
 
 	/* Send a Media Connected event, according to the Spec */
 	adapter->connect_status = libertas_connected;
 
 	if (command == cmd_ret_802_11_ad_hoc_start) {
 		/* Update the created network descriptor with the new BSSID */
-		memcpy(pbssdesc->macaddress,
-		       padhocresult->BSSID, ETH_ALEN);
-	} else {
-
-		/* Make a copy of current BSSID descriptor, only needed for join since
-		 *   the current descriptor is already being used for adhoc start
-		 */
-		memmove(&adapter->curbssparams.bssdescriptor,
-			pbssdesc, sizeof(struct bss_descriptor));
+		memcpy(bss->bssid, padhocresult->BSSID, ETH_ALEN);
 	}
 
 	/* Set the BSSID from the joined/started descriptor */
-	memcpy(&adapter->curbssparams.bssid,
-	       pbssdesc->macaddress, ETH_ALEN);
+	memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
 
 	/* Set the new SSID to current SSID */
-	memcpy(&adapter->curbssparams.ssid,
-	       &pbssdesc->ssid, sizeof(struct WLAN_802_11_SSID));
+	memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
+	adapter->curbssparams.ssid_len = bss->ssid_len;
 
-	netif_carrier_on(priv->wlan_dev.netdev);
-	netif_wake_queue(priv->wlan_dev.netdev);
+	netif_carrier_on(priv->dev);
+	netif_wake_queue(priv->dev);
+
+	netif_carrier_on(priv->mesh_dev);
+	netif_wake_queue(priv->mesh_dev);
 
 	memset(&wrqu, 0, sizeof(wrqu));
 	memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
 	wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-	wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
+	wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
 
-	lbs_pr_debug(1, "ADHOC_RESP: - Joined/Started Ad Hoc\n");
-	lbs_pr_debug(1, "ADHOC_RESP: channel = %d\n", adapter->adhocchannel);
-	lbs_pr_debug(1, "ADHOC_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
-	       padhocresult->BSSID[0], padhocresult->BSSID[1],
-	       padhocresult->BSSID[2], padhocresult->BSSID[3],
-	       padhocresult->BSSID[4], padhocresult->BSSID[5]);
+	lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
+	lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
+	lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
+	       MAC_ARG(padhocresult->BSSID));
 
-	LEAVE();
+done:
+	lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
 	return ret;
 }
 
 int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
 				struct cmd_ds_command *resp)
 {
-	ENTER();
+	lbs_deb_enter(LBS_DEB_JOIN);
 
 	libertas_mac_event_disconnected(priv);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_JOIN);
 	return 0;
 }
diff --git a/drivers/net/wireless/libertas/join.h b/drivers/net/wireless/libertas/join.h
index 115f5a8..d522630 100644
--- a/drivers/net/wireless/libertas/join.h
+++ b/drivers/net/wireless/libertas/join.h
@@ -9,6 +9,7 @@
 #define _WLAN_JOIN_H
 
 #include "defs.h"
+#include "dev.h"
 
 struct cmd_ds_command;
 extern int libertas_cmd_80211_authenticate(wlan_private * priv,
@@ -21,7 +22,7 @@
 				       struct cmd_ds_command *cmd);
 extern int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
 					struct cmd_ds_command *cmd,
-					void *pssid);
+					void *pdata_buf);
 extern int libertas_cmd_80211_deauthenticate(wlan_private * priv,
 					  struct cmd_ds_command *cmd);
 extern int libertas_cmd_80211_associate(wlan_private * priv,
@@ -39,12 +40,10 @@
 
 extern int libertas_reassociation_thread(void *data);
 
-struct WLAN_802_11_SSID;
-struct bss_descriptor;
-
 extern int libertas_start_adhoc_network(wlan_private * priv,
-			     struct WLAN_802_11_SSID *adhocssid);
-extern int libertas_join_adhoc_network(wlan_private * priv, struct bss_descriptor *pbssdesc);
+			     struct assoc_request * assoc_req);
+extern int libertas_join_adhoc_network(wlan_private * priv,
+				struct assoc_request * assoc_req);
 extern int libertas_stop_adhoc_network(wlan_private * priv);
 
 extern int libertas_send_deauthentication(wlan_private * priv);
@@ -52,6 +51,6 @@
 
 extern int libertas_do_adhocstop_ioctl(wlan_private * priv);
 
-int wlan_associate(wlan_private * priv, struct bss_descriptor * pbssdesc);
+int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req);
 
 #endif
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index b9b25ce..623ab4b 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -4,6 +4,7 @@
   * thread etc..
   */
 
+#include <linux/moduleparam.h>
 #include <linux/delay.h>
 #include <linux/freezer.h>
 #include <linux/etherdevice.h>
@@ -11,26 +12,28 @@
 #include <linux/if_arp.h>
 
 #include <net/iw_handler.h>
+#include <net/ieee80211.h>
 
 #include "host.h"
-#include "sbi.h"
 #include "decl.h"
 #include "dev.h"
-#include "fw.h"
 #include "wext.h"
 #include "debugfs.h"
 #include "assoc.h"
 
-#define DRIVER_RELEASE_VERSION "320.p0"
+#define DRIVER_RELEASE_VERSION "322.p0"
 const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
 #ifdef  DEBUG
     "-dbg"
 #endif
     "";
 
-#ifdef ENABLE_PM
-static struct pm_dev *wlan_pm_dev = NULL;
-#endif
+
+/* Module parameters */
+unsigned int libertas_debug = 0;
+module_param(libertas_debug, int, 0644);
+EXPORT_SYMBOL_GPL(libertas_debug);
+
 
 #define WLAN_TX_PWR_DEFAULT		20	/*100mW */
 #define WLAN_TX_PWR_US_DEFAULT		20	/*100mW */
@@ -146,14 +149,6 @@
 };
 
 /**
- * the rates supported by the card
- */
-u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
-    { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
-	0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
-};
-
-/**
  * the rates supported
  */
 u8 libertas_supported_rates[G_SUPPORTED_RATES] =
@@ -173,66 +168,55 @@
 u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 };
 
 /**
- * the global variable of a pointer to wlan_private
- * structure variable
- */
-static wlan_private *wlanpriv = NULL;
-
-#define MAX_DEVS 5
-static struct net_device *libertas_devs[MAX_DEVS];
-static int libertas_found = 0;
-
-/**
  * the table to keep region code
  */
 u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
     { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
 
-static u8 *default_fw_name = "usb8388.bin";
-
 /**
  * Attributes exported through sysfs
  */
 
 /**
- * @brief Get function for sysfs attribute libertas_mpp
+ * @brief Get function for sysfs attribute anycast_mask
  */
-static ssize_t libertas_mpp_get(struct device * dev,
+static ssize_t libertas_anycast_get(struct device * dev,
 		struct device_attribute *attr, char * buf) {
 	struct cmd_ds_mesh_access mesh_access;
 
 	memset(&mesh_access, 0, sizeof(mesh_access));
 	libertas_prepare_and_send_command(to_net_dev(dev)->priv,
 			cmd_mesh_access,
-			cmd_act_mesh_get_mpp,
+			cmd_act_mesh_get_anycast,
 			cmd_option_waitforrsp, 0, (void *)&mesh_access);
 
-	return snprintf(buf, 3, "%d\n", mesh_access.data[0]);
+	return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
 }
 
 /**
- * @brief Set function for sysfs attribute libertas_mpp
+ * @brief Set function for sysfs attribute anycast_mask
  */
-static ssize_t libertas_mpp_set(struct device * dev,
+static ssize_t libertas_anycast_set(struct device * dev,
 		struct device_attribute *attr, const char * buf, size_t count) {
 	struct cmd_ds_mesh_access mesh_access;
-
+	uint32_t datum;
 
 	memset(&mesh_access, 0, sizeof(mesh_access));
-	sscanf(buf, "%d", &(mesh_access.data[0]));
+	sscanf(buf, "%x", &datum);
+	mesh_access.data[0] = cpu_to_le32(datum);
+
 	libertas_prepare_and_send_command((to_net_dev(dev))->priv,
 			cmd_mesh_access,
-			cmd_act_mesh_set_mpp,
+			cmd_act_mesh_set_anycast,
 			cmd_option_waitforrsp, 0, (void *)&mesh_access);
 	return strlen(buf);
 }
 
 /**
- * libertas_mpp attribute to be exported per mshX interface
- * through sysfs (/sys/class/net/mshX/libertas-mpp)
+ * anycast_mask attribute to be exported per mshX interface
+ * through sysfs (/sys/class/net/mshX/anycast_mask)
  */
-static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get,
-		libertas_mpp_set );
+static DEVICE_ATTR(anycast_mask, 0644, libertas_anycast_get, libertas_anycast_set);
 
 /**
  *  @brief Check if the device can be open and wait if necessary.
@@ -245,7 +229,8 @@
  * function to work around the issue.
  *
  */
-static int pre_open_check(struct net_device *dev) {
+static int pre_open_check(struct net_device *dev)
+{
 	wlan_private *priv = (wlan_private *) dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 	int i = 0;
@@ -255,8 +240,7 @@
 		msleep_interruptible(100);
 	}
 	if (!adapter->fw_ready) {
-		lbs_pr_info("FW not ready, pre_open_check() return failure\n");
-		LEAVE();
+		lbs_pr_err("firmware not ready\n");
 		return -1;
 	}
 
@@ -274,17 +258,19 @@
 	wlan_private *priv = (wlan_private *) dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
-
+	lbs_deb_enter(LBS_DEB_NET);
 
 	priv->open = 1;
 
 	if (adapter->connect_status == libertas_connected) {
-		netif_carrier_on(priv->wlan_dev.netdev);
-	} else
-		netif_carrier_off(priv->wlan_dev.netdev);
+		netif_carrier_on(priv->dev);
+		netif_carrier_on(priv->mesh_dev);
+	} else {
+		netif_carrier_off(priv->dev);
+		netif_carrier_off(priv->mesh_dev);
+	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_NET);
 	return 0;
 }
 /**
@@ -297,12 +283,12 @@
 {
 	wlan_private *priv = (wlan_private *) dev->priv ;
 
-	if(pre_open_check(dev) == -1)
+	if (pre_open_check(dev) == -1)
 		return -1;
 	priv->mesh_open = 1 ;
-	netif_start_queue(priv->mesh_dev);
+	netif_wake_queue(priv->mesh_dev);
 	if (priv->infra_open == 0)
-		return wlan_dev_open(priv->wlan_dev.netdev) ;
+		return wlan_dev_open(priv->dev) ;
 	return 0;
 }
 
@@ -319,9 +305,9 @@
 	if(pre_open_check(dev) == -1)
 		return -1;
 	priv->infra_open = 1 ;
-	netif_wake_queue(priv->wlan_dev.netdev);
+	netif_wake_queue(priv->dev);
 	if (priv->open == 0)
-		return wlan_dev_open(priv->wlan_dev.netdev) ;
+		return wlan_dev_open(priv->dev) ;
 	return 0;
 }
 
@@ -329,12 +315,12 @@
 {
 	wlan_private *priv = dev->priv;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_NET);
 
-	netif_carrier_off(priv->wlan_dev.netdev);
+	netif_carrier_off(priv->dev);
 	priv->open = 0;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_NET);
 	return 0;
 }
 
@@ -351,7 +337,7 @@
 	priv->mesh_open = 0;
 	netif_stop_queue(priv->mesh_dev);
 	if (priv->infra_open == 0)
-		return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ;
+		return wlan_dev_close(dev);
 	else
 		return 0;
 }
@@ -362,147 +348,38 @@
  *  @param dev     A pointer to net_device structure
  *  @return 	   0
  */
-static int wlan_close(struct net_device *dev) {
+static int wlan_close(struct net_device *dev)
+{
 	wlan_private *priv = (wlan_private *) dev->priv;
 
-	netif_stop_queue(priv->wlan_dev.netdev);
+	netif_stop_queue(dev);
 	priv->infra_open = 0;
 	if (priv->mesh_open == 0)
-		return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ;
+		return wlan_dev_close(dev);
 	else
 		return 0;
 }
 
 
-#ifdef ENABLE_PM
-
-/**
- *  @brief This function is a callback function. it is called by
- *  kernel to enter or exit power saving mode.
- *
- *  @param pmdev   A pointer to pm_dev
- *  @param pmreq   pm_request_t
- *  @param pmdata  A pointer to pmdata
- *  @return 	   0 or -1
- */
-static int wlan_pm_callback(struct pm_dev *pmdev, pm_request_t pmreq,
-			    void *pmdata)
-{
-	wlan_private *priv = wlanpriv;
-	wlan_adapter *adapter = priv->adapter;
-	struct net_device *dev = priv->wlan_dev.netdev;
-
-	lbs_pr_debug(1, "WPRM_PM_CALLBACK: pmreq = %d.\n", pmreq);
-
-	switch (pmreq) {
-	case PM_SUSPEND:
-		lbs_pr_debug(1, "WPRM_PM_CALLBACK: enter PM_SUSPEND.\n");
-
-		/* in associated mode */
-		if (adapter->connect_status == libertas_connected) {
-			if ((adapter->psstate != PS_STATE_SLEEP)
-			    ) {
-				lbs_pr_debug(1,
-				       "wlan_pm_callback: can't enter sleep mode\n");
-				return -1;
-			} else {
-
-				/*
-				 * Detach the network interface
-				 * if the network is running
-				 */
-				if (netif_running(dev)) {
-					netif_device_detach(dev);
-					lbs_pr_debug(1,
-					       "netif_device_detach().\n");
-				}
-				libertas_sbi_suspend(priv);
-			}
-			break;
-		}
-
-		/* in non associated mode */
-
-		/*
-		 * Detach the network interface
-		 * if the network is running
-		 */
-		if (netif_running(dev))
-			netif_device_detach(dev);
-
-		/*
-		 * Storing and restoring of the regs be taken care
-		 * at the driver rest will be done at wlan driver
-		 * this makes driver independent of the card
-		 */
-
-		libertas_sbi_suspend(priv);
-
-		break;
-
-	case PM_RESUME:
-		/* in associated mode */
-		if (adapter->connect_status == libertas_connected) {
-			{
-				/*
-				 * Bring the inteface up first
-				 * This case should not happen still ...
-				 */
-				libertas_sbi_resume(priv);
-
-				/*
-				 * Attach the network interface
-				 * if the network is running
-				 */
-				if (netif_running(dev)) {
-					netif_device_attach(dev);
-					lbs_pr_debug(1,
-					       "after netif_device_attach().\n");
-				}
-				lbs_pr_debug(1,
-				       "After netif attach, in associated mode.\n");
-			}
-			break;
-		}
-
-		/* in non associated mode */
-
-		/*
-		 * Bring the inteface up first
-		 * This case should not happen still ...
-		 */
-
-		libertas_sbi_resume(priv);
-
-		if (netif_running(dev))
-			netif_device_attach(dev);
-
-		lbs_pr_debug(1, "after netif attach, in NON associated mode.\n");
-		break;
-	}
-
-	return 0;
-}
-#endif				/* ENABLE_PM */
-
 static int wlan_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	int ret = 0;
 	wlan_private *priv = dev->priv;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_NET);
 
-	if (priv->wlan_dev.dnld_sent || priv->adapter->TxLockFlag) {
+	if (priv->dnld_sent || priv->adapter->TxLockFlag) {
 		priv->stats.tx_dropped++;
 		goto done;
 	}
 
-	netif_stop_queue(priv->wlan_dev.netdev);
+	netif_stop_queue(priv->dev);
+	netif_stop_queue(priv->mesh_dev);
 
 	if (libertas_process_tx(priv, skb) == 0)
 		dev->trans_start = jiffies;
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
 	return ret;
 }
 
@@ -513,33 +390,43 @@
 static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	wlan_private *priv = dev->priv;
-	ENTER();
-	SET_MESH_FRAME(skb);
-	LEAVE();
+	int ret;
 
-	return wlan_hard_start_xmit(skb, priv->wlan_dev.netdev);
+	lbs_deb_enter(LBS_DEB_MESH);
+
+	SET_MESH_FRAME(skb);
+
+	ret = wlan_hard_start_xmit(skb, priv->dev);
+	lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
+	return ret;
 }
 
 /**
  * @brief Mark non-mesh packets and handover them to wlan_hard_start_xmit
  *
  */
-static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) {
-	ENTER();
+static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	int ret;
+
+	lbs_deb_enter(LBS_DEB_NET);
+
 	UNSET_MESH_FRAME(skb);
-	LEAVE();
-	return wlan_hard_start_xmit(skb, dev);
+
+	ret = wlan_hard_start_xmit(skb, dev);
+	lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
+	return ret;
 }
 
 static void wlan_tx_timeout(struct net_device *dev)
 {
 	wlan_private *priv = (wlan_private *) dev->priv;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_TX);
 
-	lbs_pr_err("tx watch dog timeout!\n");
+	lbs_pr_err("tx watch dog timeout\n");
 
-	priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
+	priv->dnld_sent = DNLD_RES_RECEIVED;
 	dev->trans_start = jiffies;
 
 	if (priv->adapter->currenttxskb) {
@@ -550,10 +437,12 @@
 			libertas_send_tx_feedback(priv);
 		} else
 			wake_up_interruptible(&priv->mainthread.waitq);
-	} else if (priv->adapter->connect_status == libertas_connected)
-		netif_wake_queue(priv->wlan_dev.netdev);
+	} else if (priv->adapter->connect_status == libertas_connected) {
+		netif_wake_queue(priv->dev);
+		netif_wake_queue(priv->mesh_dev);
+	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_TX);
 }
 
 /**
@@ -576,7 +465,10 @@
 	wlan_adapter *adapter = priv->adapter;
 	struct sockaddr *phwaddr = addr;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_NET);
+
+	/* In case it was called from the mesh device */
+	dev = priv->dev ;
 
 	memset(adapter->current_addr, 0, ETH_ALEN);
 
@@ -591,17 +483,18 @@
 				    cmd_option_waitforrsp, 0, NULL);
 
 	if (ret) {
-		lbs_pr_debug(1, "set mac address failed.\n");
+		lbs_deb_net("set MAC address failed\n");
 		ret = -1;
 		goto done;
 	}
 
 	lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN);
 	memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN);
-	memcpy(((wlan_private *) dev->priv)->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
+	if (priv->mesh_dev)
+		memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
 
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
 	return ret;
 }
 
@@ -626,12 +519,12 @@
 	wlan_adapter *adapter = priv->adapter;
 	int oldpacketfilter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_NET);
 
 	oldpacketfilter = adapter->currentpacketfilter;
 
 	if (dev->flags & IFF_PROMISC) {
-		lbs_pr_debug(1, "enable Promiscuous mode\n");
+		lbs_deb_net("enable promiscuous mode\n");
 		adapter->currentpacketfilter |=
 		    cmd_act_mac_promiscuous_enable;
 		adapter->currentpacketfilter &=
@@ -644,7 +537,7 @@
 
 		if (dev->flags & IFF_ALLMULTI || dev->mc_count >
 		    MRVDRV_MAX_MULTICAST_LIST_SIZE) {
-			lbs_pr_debug(1, "Enabling All Multicast!\n");
+			lbs_deb_net( "enabling all multicast\n");
 			adapter->currentpacketfilter |=
 			    cmd_act_mac_all_multicast_enable;
 			adapter->currentpacketfilter &=
@@ -654,8 +547,8 @@
 			    ~cmd_act_mac_all_multicast_enable;
 
 			if (!dev->mc_count) {
-				lbs_pr_debug(1, "No multicast addresses - "
-				       "disabling multicast!\n");
+				lbs_deb_net("no multicast addresses, "
+				       "disabling multicast\n");
 				adapter->currentpacketfilter &=
 				    ~cmd_act_mac_multicast_enable;
 			} else {
@@ -667,12 +560,12 @@
 				adapter->nr_of_multicastmacaddr =
 				    wlan_copy_multicast_address(adapter, dev);
 
-				lbs_pr_debug(1, "Multicast addresses: %d\n",
+				lbs_deb_net("multicast addresses: %d\n",
 				       dev->mc_count);
 
 				for (i = 0; i < dev->mc_count; i++) {
-					lbs_pr_debug(1, "Multicast address %d:"
-					       "%x %x %x %x %x %x\n", i,
+					lbs_deb_net("Multicast address %d:"
+					       MAC_FMT "\n", i,
 					       adapter->multicastlist[i][0],
 					       adapter->multicastlist[i][1],
 					       adapter->multicastlist[i][2],
@@ -680,7 +573,7 @@
 					       adapter->multicastlist[i][4],
 					       adapter->multicastlist[i][5]);
 				}
-				/* set multicast addresses to firmware */
+				/* send multicast addresses to firmware */
 				libertas_prepare_and_send_command(priv,
 						      cmd_mac_multicast_adr,
 						      cmd_act_set, 0, 0,
@@ -693,13 +586,13 @@
 		libertas_set_mac_packet_filter(priv);
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_NET);
 }
 
 /**
- *  @brief This function hanldes the major job in WLAN driver.
- *  it handles the event generated by firmware, rx data received
- *  from firmware and tx data sent from kernel.
+ *  @brief This function handles the major jobs in the WLAN driver.
+ *  It handles all events generated by firmware, RX data received
+ *  from firmware and TX data sent from kernel.
  *
  *  @param data    A pointer to wlan_thread structure
  *  @return 	   0
@@ -712,26 +605,26 @@
 	wait_queue_t wait;
 	u8 ireg = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_THREAD);
 
 	wlan_activate_thread(thread);
 
 	init_waitqueue_entry(&wait, current);
 
 	for (;;) {
-		lbs_pr_debug(1, "main-thread 111: intcounter=%d "
+		lbs_deb_thread( "main-thread 111: intcounter=%d "
 		       "currenttxskb=%p dnld_sent=%d\n",
 		       adapter->intcounter,
-		       adapter->currenttxskb, priv->wlan_dev.dnld_sent);
+		       adapter->currenttxskb, priv->dnld_sent);
 
 		add_wait_queue(&thread->waitq, &wait);
 		set_current_state(TASK_INTERRUPTIBLE);
 		spin_lock_irq(&adapter->driver_lock);
 		if ((adapter->psstate == PS_STATE_SLEEP) ||
 		    (!adapter->intcounter
-		     && (priv->wlan_dev.dnld_sent || adapter->cur_cmd ||
+		     && (priv->dnld_sent || adapter->cur_cmd ||
 			 list_empty(&adapter->cmdpendingq)))) {
-			lbs_pr_debug(1,
+			lbs_deb_thread(
 			       "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
 			       adapter->connect_status, adapter->intcounter,
 			       adapter->psmode, adapter->psstate);
@@ -741,23 +634,23 @@
 			spin_unlock_irq(&adapter->driver_lock);
 
 
-		lbs_pr_debug(1,
+		lbs_deb_thread(
 		       "main-thread 222 (waking up): intcounter=%d currenttxskb=%p "
 		       "dnld_sent=%d\n", adapter->intcounter,
-		       adapter->currenttxskb, priv->wlan_dev.dnld_sent);
+		       adapter->currenttxskb, priv->dnld_sent);
 
 		set_current_state(TASK_RUNNING);
 		remove_wait_queue(&thread->waitq, &wait);
 		try_to_freeze();
 
-		lbs_pr_debug(1, "main-thread 333: intcounter=%d currenttxskb=%p "
+		lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p "
 		       "dnld_sent=%d\n",
 		       adapter->intcounter,
-		       adapter->currenttxskb, priv->wlan_dev.dnld_sent);
+		       adapter->currenttxskb, priv->dnld_sent);
 
 		if (kthread_should_stop()
 		    || adapter->surpriseremoved) {
-			lbs_pr_debug(1,
+			lbs_deb_thread(
 			       "main-thread: break from main thread: surpriseremoved=0x%x\n",
 			       adapter->surpriseremoved);
 			break;
@@ -768,10 +661,10 @@
 		if (adapter->intcounter) {
 			u8 int_status;
 			adapter->intcounter = 0;
-			int_status = libertas_sbi_get_int_status(priv, &ireg);
+			int_status = priv->hw_get_int_status(priv, &ireg);
 
 			if (int_status) {
-				lbs_pr_debug(1,
+				lbs_deb_thread(
 				       "main-thread: reading HOST_INT_STATUS_REG failed\n");
 				spin_unlock_irq(&adapter->driver_lock);
 				continue;
@@ -779,14 +672,14 @@
 			adapter->hisregcpy |= ireg;
 		}
 
-		lbs_pr_debug(1, "main-thread 444: intcounter=%d currenttxskb=%p "
+		lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p "
 		       "dnld_sent=%d\n",
 		       adapter->intcounter,
-		       adapter->currenttxskb, priv->wlan_dev.dnld_sent);
+		       adapter->currenttxskb, priv->dnld_sent);
 
 		/* command response? */
 		if (adapter->hisregcpy & his_cmdupldrdy) {
-			lbs_pr_debug(1, "main-thread: cmd response ready.\n");
+			lbs_deb_thread("main-thread: cmd response ready\n");
 
 			adapter->hisregcpy &= ~his_cmdupldrdy;
 			spin_unlock_irq(&adapter->driver_lock);
@@ -796,13 +689,13 @@
 
 		/* Any Card Event */
 		if (adapter->hisregcpy & his_cardevent) {
-			lbs_pr_debug(1, "main-thread: Card Event Activity.\n");
+			lbs_deb_thread("main-thread: Card Event Activity\n");
 
 			adapter->hisregcpy &= ~his_cardevent;
 
-			if (libertas_sbi_read_event_cause(priv)) {
+			if (priv->hw_read_event_cause(priv)) {
 				lbs_pr_alert(
-				       "main-thread: libertas_sbi_read_event_cause failed.\n");
+				       "main-thread: hw_read_event_cause failed\n");
 				spin_unlock_irq(&adapter->driver_lock);
 				continue;
 			}
@@ -813,15 +706,15 @@
 
 		/* Check if we need to confirm Sleep Request received previously */
 		if (adapter->psstate == PS_STATE_PRE_SLEEP) {
-			if (!priv->wlan_dev.dnld_sent && !adapter->cur_cmd) {
+			if (!priv->dnld_sent && !adapter->cur_cmd) {
 				if (adapter->connect_status ==
 				    libertas_connected) {
-					lbs_pr_debug(1,
+					lbs_deb_thread(
 					       "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p "
 					       "dnld_sent=%d cur_cmd=%p, confirm now\n",
 					       adapter->intcounter,
 					       adapter->currenttxskb,
-					       priv->wlan_dev.dnld_sent,
+					       priv->dnld_sent,
 					       adapter->cur_cmd);
 
 					libertas_ps_confirm_sleep(priv,
@@ -847,7 +740,7 @@
 			continue;
 
 		/* Execute the next command */
-		if (!priv->wlan_dev.dnld_sent && !priv->adapter->cur_cmd)
+		if (!priv->dnld_sent && !priv->adapter->cur_cmd)
 			libertas_execute_next_command(priv);
 
 		/* Wake-up command waiters which can't sleep in
@@ -864,7 +757,7 @@
 	wake_up_all(&adapter->cmd_pending);
 	wlan_deactivate_thread(thread);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_THREAD);
 	return 0;
 }
 
@@ -875,49 +768,32 @@
  *  @param card    A pointer to card
  *  @return 	   A pointer to wlan_private structure
  */
-wlan_private *wlan_add_card(void *card)
+wlan_private *libertas_add_card(void *card, struct device *dmdev)
 {
 	struct net_device *dev = NULL;
-	struct net_device *mesh_dev = NULL;
 	wlan_private *priv = NULL;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_NET);
 
 	/* Allocate an Ethernet device and register it */
 	if (!(dev = alloc_etherdev(sizeof(wlan_private)))) {
-		lbs_pr_alert( "Init ethernet device failed!\n");
+		lbs_pr_err("init ethX device failed\n");
 		return NULL;
 	}
-
 	priv = dev->priv;
 
 	/* allocate buffer for wlan_adapter */
-	if (!(priv->adapter = kmalloc(sizeof(wlan_adapter), GFP_KERNEL))) {
-		lbs_pr_alert( "Allocate buffer for wlan_adapter failed!\n");
-		goto err_kmalloc;
+	if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) {
+		lbs_pr_err("allocate buffer for wlan_adapter failed\n");
+		goto err_kzalloc;
 	}
 
-	/* Allocate a virtual mesh device */
-	if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
-		lbs_pr_debug(1, "Init ethernet device failed!\n");
-		return NULL;
-	}
-
-	/* Both intervaces share the priv structure */
-	mesh_dev->priv = priv;
-
-	/* init wlan_adapter */
-	memset(priv->adapter, 0, sizeof(wlan_adapter));
-
-	priv->wlan_dev.netdev = dev;
-	priv->wlan_dev.card = card;
+	priv->dev = dev;
+	priv->card = card;
 	priv->mesh_open = 0;
 	priv->infra_open = 0;
-	priv->mesh_dev = mesh_dev;
-	wlanpriv = priv;
 
 	SET_MODULE_OWNER(dev);
-	SET_MODULE_OWNER(mesh_dev);
 
 	/* Setup the OS Interface to our functions */
 	dev->open = wlan_open;
@@ -925,116 +801,172 @@
 	dev->stop = wlan_close;
 	dev->do_ioctl = libertas_do_ioctl;
 	dev->set_mac_address = wlan_set_mac_address;
-	mesh_dev->open = mesh_open;
-	mesh_dev->hard_start_xmit = mesh_pre_start_xmit;
-	mesh_dev->stop = mesh_close;
-	mesh_dev->do_ioctl = libertas_do_ioctl;
-	memcpy(mesh_dev->dev_addr, wlanpriv->wlan_dev.netdev->dev_addr,
-			sizeof(wlanpriv->wlan_dev.netdev->dev_addr));
-
-#define	WLAN_WATCHDOG_TIMEOUT	(5 * HZ)
-
 	dev->tx_timeout = wlan_tx_timeout;
 	dev->get_stats = wlan_get_stats;
-	dev->watchdog_timeo = WLAN_WATCHDOG_TIMEOUT;
+	dev->watchdog_timeo = 5 * HZ;
 	dev->ethtool_ops = &libertas_ethtool_ops;
-	mesh_dev->get_stats = wlan_get_stats;
-	mesh_dev->ethtool_ops = &libertas_ethtool_ops;
-
 #ifdef	WIRELESS_EXT
 	dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
-	mesh_dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
 #endif
 #define NETIF_F_DYNALLOC 16
 	dev->features |= NETIF_F_DYNALLOC;
 	dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
 	dev->set_multicast_list = wlan_set_multicast_list;
 
+	SET_NETDEV_DEV(dev, dmdev);
+
 	INIT_LIST_HEAD(&priv->adapter->cmdfreeq);
 	INIT_LIST_HEAD(&priv->adapter->cmdpendingq);
 
 	spin_lock_init(&priv->adapter->driver_lock);
 	init_waitqueue_head(&priv->adapter->cmd_pending);
 	priv->adapter->nr_cmd_pending = 0;
+	goto done;
 
-	lbs_pr_debug(1, "Starting kthread...\n");
+err_kzalloc:
+	free_netdev(dev);
+	priv = NULL;
+done:
+	lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
+	return priv;
+}
+EXPORT_SYMBOL_GPL(libertas_add_card);
+
+int libertas_activate_card(wlan_private *priv, char *fw_name)
+{
+	struct net_device *dev = priv->dev;
+	int ret = -1;
+
+	lbs_deb_enter(LBS_DEB_MAIN);
+
+	lbs_deb_thread("Starting kthread...\n");
 	priv->mainthread.priv = priv;
 	wlan_create_thread(wlan_service_main_thread,
 			   &priv->mainthread, "wlan_main_service");
 
 	priv->assoc_thread =
 		create_singlethread_workqueue("libertas_assoc");
-	INIT_DELAYED_WORK(&priv->assoc_work, wlan_association_worker);
+	INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker);
+	INIT_WORK(&priv->sync_channel, libertas_sync_channel);
 
 	/*
 	 * Register the device. Fillup the private data structure with
 	 * relevant information from the card and request for the required
 	 * IRQ.
 	 */
-	if (libertas_sbi_register_dev(priv) < 0) {
-		lbs_pr_info("failed to register wlan device!\n");
+	if (priv->hw_register_dev(priv) < 0) {
+		lbs_pr_err("failed to register WLAN device\n");
 		goto err_registerdev;
 	}
 
 	/* init FW and HW */
-	if (libertas_init_fw(priv)) {
-		lbs_pr_debug(1, "Firmware Init failed\n");
+	if (fw_name && libertas_init_fw(priv, fw_name)) {
+		lbs_pr_err("firmware init failed\n");
 		goto err_registerdev;
 	}
 
 	if (register_netdev(dev)) {
-		lbs_pr_err("Cannot register network device!\n");
+		lbs_pr_err("cannot register ethX device\n");
 		goto err_init_fw;
 	}
 
-	/* Register virtual mesh interface */
-	if (register_netdev(mesh_dev)) {
-		lbs_pr_info("Cannot register mesh virtual interface!\n");
-		goto err_init_fw;
-	}
-
-	lbs_pr_info("%s: Marvell Wlan 802.11 adapter ", dev->name);
+	lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
 
 	libertas_debugfs_init_one(priv, dev);
 
-	if (libertas_found == MAX_DEVS)
-		goto err_init_fw;
-	libertas_devs[libertas_found] = dev;
-	libertas_found++;
-#ifdef ENABLE_PM
-	if (!(wlan_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, wlan_pm_callback)))
-		lbs_pr_alert( "failed to register PM callback\n");
-#endif
-	if (device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp))
-		goto err_create_file;
+	ret = 0;
+	goto done;
 
-	LEAVE();
-	return priv;
-
-err_create_file:
-	device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
 err_init_fw:
-	libertas_sbi_unregister_dev(priv);
+	priv->hw_unregister_dev(priv);
 err_registerdev:
 	destroy_workqueue(priv->assoc_thread);
 	/* Stop the thread servicing the interrupts */
 	wake_up_interruptible(&priv->mainthread.waitq);
 	wlan_terminate_thread(&priv->mainthread);
-	kfree(priv->adapter);
-err_kmalloc:
-	free_netdev(dev);
-	free_netdev(mesh_dev);
-	wlanpriv = NULL;
-
-	LEAVE();
-	return NULL;
+done:
+	lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
+	return ret;
 }
+EXPORT_SYMBOL_GPL(libertas_activate_card);
+
+
+/**
+ * @brief This function adds mshX interface
+ *
+ *  @param priv    A pointer to the wlan_private structure
+ *  @return 	   0 if successful, -X otherwise
+ */
+int libertas_add_mesh(wlan_private *priv, struct device *dev)
+{
+	struct net_device *mesh_dev = NULL;
+	int ret = 0;
+
+	lbs_deb_enter(LBS_DEB_MESH);
+
+	/* Allocate a virtual mesh device */
+	if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
+		lbs_deb_mesh("init mshX device failed\n");
+		ret = -ENOMEM;
+		goto done;
+	}
+	mesh_dev->priv = priv;
+	priv->mesh_dev = mesh_dev;
+
+	SET_MODULE_OWNER(mesh_dev);
+
+	mesh_dev->open = mesh_open;
+	mesh_dev->hard_start_xmit = mesh_pre_start_xmit;
+	mesh_dev->stop = mesh_close;
+	mesh_dev->do_ioctl = libertas_do_ioctl;
+	mesh_dev->get_stats = wlan_get_stats;
+	mesh_dev->set_mac_address = wlan_set_mac_address;
+	mesh_dev->ethtool_ops = &libertas_ethtool_ops;
+	memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
+			sizeof(priv->dev->dev_addr));
+
+	SET_NETDEV_DEV(priv->mesh_dev, dev);
+
+#ifdef	WIRELESS_EXT
+	mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
+#endif
+#define NETIF_F_DYNALLOC 16
+
+	/* Register virtual mesh interface */
+	ret = register_netdev(mesh_dev);
+	if (ret) {
+		lbs_pr_err("cannot register mshX virtual interface\n");
+		goto err_free;
+	}
+
+	ret = device_create_file(&(mesh_dev->dev), &dev_attr_anycast_mask);
+	if (ret)
+		goto err_unregister;
+
+	/* Everything successful */
+	ret = 0;
+	goto done;
+
+
+err_unregister:
+	unregister_netdev(mesh_dev);
+
+err_free:
+	free_netdev(mesh_dev);
+
+done:
+	lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(libertas_add_mesh);
 
 static void wake_pending_cmdnodes(wlan_private *priv)
 {
 	struct cmd_ctrl_node *cmdnode;
 	unsigned long flags;
 
+	lbs_deb_enter(LBS_DEB_CMD);
+
 	spin_lock_irqsave(&priv->adapter->driver_lock, flags);
 	list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) {
 		cmdnode->cmdwaitqwoken = 1;
@@ -1044,40 +976,29 @@
 }
 
 
-int wlan_remove_card(void *card)
+int libertas_remove_card(wlan_private *priv)
 {
-	wlan_private *priv = libertas_sbi_get_priv(card);
 	wlan_adapter *adapter;
 	struct net_device *dev;
-	struct net_device *mesh_dev;
 	union iwreq_data wrqu;
-	int i;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_NET);
 
-	if (!priv) {
-		LEAVE();
-		return 0;
-	}
+	if (!priv)
+		goto out;
 
 	adapter = priv->adapter;
 
-	if (!adapter) {
-		LEAVE();
-		return 0;
-	}
+	if (!adapter)
+		goto out;
 
-	dev = priv->wlan_dev.netdev;
-	mesh_dev = priv->mesh_dev;
+	dev = priv->dev;
 
-	netif_stop_queue(mesh_dev);
-	netif_stop_queue(priv->wlan_dev.netdev);
-	netif_carrier_off(priv->wlan_dev.netdev);
+	netif_stop_queue(priv->dev);
+	netif_carrier_off(priv->dev);
 
 	wake_pending_cmdnodes(priv);
 
-	device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
-	unregister_netdev(mesh_dev);
 	unregister_netdev(dev);
 
 	cancel_delayed_work(&priv->assoc_work);
@@ -1090,11 +1011,7 @@
 
 	memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
 	wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-	wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
-
-#ifdef ENABLE_PM
-	pm_unregister(wlan_pm_dev);
-#endif
+	wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
 
 	adapter->surpriseremoved = 1;
 
@@ -1103,28 +1020,45 @@
 
 	libertas_debugfs_remove_one(priv);
 
-	lbs_pr_debug(1, "Free adapter\n");
+	lbs_deb_net("free adapter\n");
 	libertas_free_adapter(priv);
 
-	for (i = 0; i<libertas_found; i++) {
-		if (libertas_devs[i]==priv->wlan_dev.netdev) {
-			libertas_devs[i] = libertas_devs[--libertas_found];
-			libertas_devs[libertas_found] = NULL ;
-			break ;
-		}
-	}
+	lbs_deb_net("unregister finish\n");
 
-	lbs_pr_debug(1, "Unregister finish\n");
-
-	priv->wlan_dev.netdev = NULL;
-	priv->mesh_dev = NULL ;
-	free_netdev(mesh_dev);
+	priv->dev = NULL;
 	free_netdev(dev);
-	wlanpriv = NULL;
 
-	LEAVE();
+out:
+	lbs_deb_leave(LBS_DEB_NET);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(libertas_remove_card);
+
+
+void libertas_remove_mesh(wlan_private *priv)
+{
+	struct net_device *mesh_dev;
+
+	lbs_deb_enter(LBS_DEB_NET);
+
+	if (!priv)
+		goto out;
+
+	mesh_dev = priv->mesh_dev;
+
+	netif_stop_queue(mesh_dev);
+	netif_carrier_off(priv->mesh_dev);
+
+	device_remove_file(&(mesh_dev->dev), &dev_attr_anycast_mask);
+	unregister_netdev(mesh_dev);
+
+	priv->mesh_dev = NULL ;
+	free_netdev(mesh_dev);
+
+out:
+	lbs_deb_leave(LBS_DEB_NET);
+}
+EXPORT_SYMBOL_GPL(libertas_remove_mesh);
 
 /**
  *  @brief This function finds the CFP in
@@ -1139,33 +1073,34 @@
 {
 	int i, end;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_MAIN);
 
 	end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table);
 
 	for (i = 0; i < end ; i++) {
-		lbs_pr_debug(1, "region_cfp_table[i].region=%d\n",
+		lbs_deb_main("region_cfp_table[i].region=%d\n",
 			region_cfp_table[i].region);
 		if (region_cfp_table[i].region == region) {
 			*cfp_no = region_cfp_table[i].cfp_no_BG;
-			LEAVE();
+			lbs_deb_leave(LBS_DEB_MAIN);
 			return region_cfp_table[i].cfp_BG;
 		}
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
 	return NULL;
 }
 
 int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band)
 {
 	wlan_adapter *adapter = priv->adapter;
+	int ret = 0;
 	int i = 0;
 
 	struct chan_freq_power *cfp;
 	int cfp_no;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_MAIN);
 
 	memset(adapter->region_channel, 0, sizeof(adapter->region_channel));
 
@@ -1175,17 +1110,19 @@
 			adapter->region_channel[i].nrcfp = cfp_no;
 			adapter->region_channel[i].CFP = cfp;
 		} else {
-			lbs_pr_debug(1, "wrong region code %#x in band B-G\n",
+			lbs_deb_main("wrong region code %#x in band B/G\n",
 			       region);
-			return -1;
+			ret = -1;
+			goto out;
 		}
 		adapter->region_channel[i].valid = 1;
 		adapter->region_channel[i].region = region;
 		adapter->region_channel[i].band = band;
 		i++;
 	}
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
+	return ret;
 }
 
 /**
@@ -1200,9 +1137,9 @@
 {
 	wlan_private *priv = dev->priv;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_THREAD);
 
-	lbs_pr_debug(1, "libertas_interrupt: intcounter=%d\n",
+	lbs_deb_thread("libertas_interrupt: intcounter=%d\n",
 	       priv->adapter->intcounter);
 
 	priv->adapter->intcounter++;
@@ -1210,56 +1147,35 @@
 	if (priv->adapter->psstate == PS_STATE_SLEEP) {
 		priv->adapter->psstate = PS_STATE_AWAKE;
 		netif_wake_queue(dev);
+		netif_wake_queue(priv->mesh_dev);
 	}
 
 	wake_up_interruptible(&priv->mainthread.waitq);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_THREAD);
 }
+EXPORT_SYMBOL_GPL(libertas_interrupt);
 
-static int wlan_init_module(void)
+static int libertas_init_module(void)
 {
-	int ret = 0;
-
-	ENTER();
-
-	if (libertas_fw_name == NULL) {
-		libertas_fw_name = default_fw_name;
-	}
-
+	lbs_deb_enter(LBS_DEB_MAIN);
 	libertas_debugfs_init();
-
-	if (libertas_sbi_register()) {
-		ret = -1;
-		libertas_debugfs_remove();
-		goto done;
-	}
-
-done:
-	LEAVE();
-	return ret;
+	lbs_deb_leave(LBS_DEB_MAIN);
+	return 0;
 }
 
-static void wlan_cleanup_module(void)
+static void libertas_exit_module(void)
 {
-	int i;
+	lbs_deb_enter(LBS_DEB_MAIN);
 
-	ENTER();
-
-	for (i = 0; i<libertas_found; i++) {
-		wlan_private *priv = libertas_devs[i]->priv;
-		reset_device(priv);
-	}
-
-	libertas_sbi_unregister();
 	libertas_debugfs_remove();
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_MAIN);
 }
 
-module_init(wlan_init_module);
-module_exit(wlan_cleanup_module);
+module_init(libertas_init_module);
+module_exit(libertas_exit_module);
 
-MODULE_DESCRIPTION("M-WLAN Driver");
+MODULE_DESCRIPTION("Libertas WLAN Driver Library");
 MODULE_AUTHOR("Marvell International Ltd.");
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/wireless/libertas/rx.c b/drivers/net/wireless/libertas/rx.c
index 96619a32..88d9d2d 100644
--- a/drivers/net/wireless/libertas/rx.c
+++ b/drivers/net/wireless/libertas/rx.c
@@ -106,10 +106,10 @@
 {
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_RX);
 
-	lbs_pr_debug(1, "rxpd: SNR = %d, NF = %d\n", p_rx_pd->snr, p_rx_pd->nf);
-	lbs_pr_debug(1, "Before computing SNR: SNR- avg = %d, NF-avg = %d\n",
+	lbs_deb_rx("rxpd: SNR %d, NF %d\n", p_rx_pd->snr, p_rx_pd->nf);
+	lbs_deb_rx("before computing SNR: SNR-avg = %d, NF-avg = %d\n",
 	       adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
 	       adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
 
@@ -121,7 +121,7 @@
 
 	adapter->SNR[TYPE_RXPD][TYPE_AVG] = wlan_getavgsnr(priv) * AVG_SCALE;
 	adapter->NF[TYPE_RXPD][TYPE_AVG] = wlan_getavgnf(priv) * AVG_SCALE;
-	lbs_pr_debug(1, "After computing SNR: SNR-avg = %d, NF-avg = %d\n",
+	lbs_deb_rx("after computing SNR: SNR-avg = %d, NF-avg = %d\n",
 	       adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
 	       adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
 
@@ -133,18 +133,17 @@
 	    CAL_RSSI(adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
 		     adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_RX);
 }
 
 void libertas_upload_rx_packet(wlan_private * priv, struct sk_buff *skb)
 {
-	lbs_pr_debug(1, "skb->data=%p\n", skb->data);
+	lbs_deb_rx("skb->data %p\n", skb->data);
 
-	if(IS_MESH_FRAME(skb))
-		skb->dev = priv->mesh_dev;
+	if (priv->mesh_dev && IS_MESH_FRAME(skb))
+		skb->protocol = eth_type_trans(skb, priv->mesh_dev);
 	else
-		skb->dev = priv->wlan_dev.netdev;
-	skb->protocol = eth_type_trans(skb, priv->wlan_dev.netdev);
+		skb->protocol = eth_type_trans(skb, priv->dev);
 	skb->ip_summed = CHECKSUM_UNNECESSARY;
 
 	netif_rx(skb);
@@ -171,7 +170,7 @@
 
 	const u8 rfc1042_eth_hdr[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_RX);
 
 	if (priv->adapter->debugmode & MRVDRV_DEBUG_RX_PATH)
 		lbs_dbg_hex("RX packet: ", skb->data,
@@ -191,7 +190,7 @@
 		 min_t(unsigned int, skb->len, 100));
 
 	if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
-		lbs_pr_debug(1, "RX error: FRAME RECEIVED WITH BAD LENGTH\n");
+		lbs_deb_rx("rx err: frame received with bad length\n");
 		priv->stats.rx_length_errors++;
 		ret = 0;
 		goto done;
@@ -200,15 +199,15 @@
 	/*
 	 * Check rxpd status and update 802.3 stat,
 	 */
-	if (!(p_rx_pd->status & MRVDRV_RXPD_STATUS_OK)) {
-		lbs_pr_debug(1, "RX error: frame received with bad status\n");
-		lbs_pr_alert("rxpd Not OK\n");
+	if (!(p_rx_pd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) {
+		lbs_deb_rx("rx err: frame received with bad status\n");
+		lbs_pr_alert("rxpd not ok\n");
 		priv->stats.rx_errors++;
 		ret = 0;
 		goto done;
 	}
 
-	lbs_pr_debug(1, "RX Data: skb->len - sizeof(RxPd) = %d - %zd = %zd\n",
+	lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
 	       skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
 
 	lbs_dbg_hex("RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
@@ -266,7 +265,7 @@
 
 	wlan_compute_rssi(priv, p_rx_pd);
 
-	lbs_pr_debug(1, "RX Data: size of actual packet = %d\n", skb->len);
+	lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
 	priv->stats.rx_bytes += skb->len;
 	priv->stats.rx_packets++;
 
@@ -274,10 +273,10 @@
 
 	ret = 0;
 done:
-	LEAVE();
-
+	lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(libertas_process_rxed_packet);
 
 /**
  *  @brief This function converts Tx/Rx rates from the Marvell WLAN format
@@ -314,7 +313,7 @@
 	case 11:		/*  54 Mbps */
 		return 108;
 	}
-	lbs_pr_alert( "Invalid Marvell WLAN rate (%i)\n", rate);
+	lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate);
 	return 0;
 }
 
@@ -336,7 +335,7 @@
 	struct rx_radiotap_hdr radiotap_hdr;
 	struct rx_radiotap_hdr *pradiotap_hdr;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_RX);
 
 	p_rx_pkt = (struct rx80211packethdr *) skb->data;
 	prxpd = &p_rx_pkt->rx_pd;
@@ -344,7 +343,7 @@
 	// lbs_dbg_hex("RX Data: Before chop rxpd", skb->data, min(skb->len, 100));
 
 	if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
-		lbs_pr_debug(1, "RX error: FRAME RECEIVED WITH BAD LENGTH\n");
+		lbs_deb_rx("rx err: frame received wit bad length\n");
 		priv->stats.rx_length_errors++;
 		ret = 0;
 		goto done;
@@ -353,12 +352,12 @@
 	/*
 	 * Check rxpd status and update 802.3 stat,
 	 */
-	if (!(prxpd->status & MRVDRV_RXPD_STATUS_OK)) {
-		//lbs_pr_debug(1, "RX error: frame received with bad status\n");
+	if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) {
+		//lbs_deb_rx("rx err: frame received with bad status\n");
 		priv->stats.rx_errors++;
 	}
 
-	lbs_pr_debug(1, "RX Data: skb->len - sizeof(RxPd) = %d - %zd = %zd\n",
+	lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
 	       skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
 
 	/* create the exported radio header */
@@ -386,7 +385,7 @@
 		/* XXX must check no carryout */
 		radiotap_hdr.antsignal = prxpd->snr + prxpd->nf;
 		radiotap_hdr.rx_flags = 0;
-		if (!(prxpd->status & MRVDRV_RXPD_STATUS_OK))
+		if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
 			radiotap_hdr.rx_flags |= IEEE80211_RADIOTAP_F_RX_BADFCS;
 		//memset(radiotap_hdr.pad, 0x11, IEEE80211_RADIOTAP_HDRLEN - 18);
 
@@ -399,7 +398,7 @@
 		if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) &&
 		    pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0,
 				     GFP_ATOMIC)) {
-			lbs_pr_alert( "%s: couldn't pskb_expand_head\n",
+			lbs_pr_alert("%s: couldn't pskb_expand_head\n",
 			       __func__);
 		}
 
@@ -414,7 +413,7 @@
 
 	default:
 		/* unknown header */
-		lbs_pr_alert( "Unknown radiomode (%i)\n",
+		lbs_pr_alert("Unknown radiomode %i\n",
 		       priv->adapter->radiomode);
 		/* don't export any header */
 		/* chop the rxpd */
@@ -431,15 +430,16 @@
 
 	wlan_compute_rssi(priv, prxpd);
 
-	lbs_pr_debug(1, "RX Data: size of actual packet = %d\n", skb->len);
+	lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
 	priv->stats.rx_bytes += skb->len;
 	priv->stats.rx_packets++;
 
 	libertas_upload_rx_packet(priv, skb);
 
 	ret = 0;
-done:
-	LEAVE();
 
-	return (ret);
+done:
+	skb->protocol = __constant_htons(0x0019);	/* ETH_P_80211_RAW */
+	lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
+	return ret;
 }
diff --git a/drivers/net/wireless/libertas/sbi.h b/drivers/net/wireless/libertas/sbi.h
deleted file mode 100644
index 59d3a59..0000000
--- a/drivers/net/wireless/libertas/sbi.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
-  * This file contains IF layer definitions.
-  */
-
-#ifndef	_SBI_H_
-#define	_SBI_H_
-
-#include <linux/interrupt.h>
-
-#include "defs.h"
-
-/** INT status Bit Definition*/
-#define his_cmddnldrdy			0x01
-#define his_cardevent			0x02
-#define his_cmdupldrdy			0x04
-
-#ifndef DEV_NAME_LEN
-#define DEV_NAME_LEN			32
-#endif
-
-#define SBI_EVENT_CAUSE_SHIFT		3
-
-/* Probe and Check if the card is present*/
-int libertas_sbi_register_dev(wlan_private * priv);
-int libertas_sbi_unregister_dev(wlan_private *);
-int libertas_sbi_get_int_status(wlan_private * priv, u8 *);
-int libertas_sbi_register(void);
-void libertas_sbi_unregister(void);
-int libertas_sbi_prog_firmware(wlan_private *);
-
-int libertas_sbi_read_event_cause(wlan_private *);
-int libertas_sbi_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb);
-wlan_private *libertas_sbi_get_priv(void *card);
-
-#ifdef ENABLE_PM
-int libertas_sbi_suspend(wlan_private *);
-int libertas_sbi_resume(wlan_private *);
-#endif
-
-#endif				/* _SBI_H */
diff --git a/drivers/net/wireless/libertas/scan.c b/drivers/net/wireless/libertas/scan.c
index 3c0b1a2..606af50 100644
--- a/drivers/net/wireless/libertas/scan.c
+++ b/drivers/net/wireless/libertas/scan.c
@@ -8,6 +8,7 @@
 #include <linux/if.h>
 #include <linux/netdevice.h>
 #include <linux/wireless.h>
+#include <linux/etherdevice.h>
 
 #include <net/ieee80211.h>
 #include <net/iw_handler.h>
@@ -58,12 +59,82 @@
 //! Scan time specified in the channel TLV for each channel for active scans
 #define MRVDRV_ACTIVE_SCAN_CHAN_TIME   100
 
-//! Macro to enable/disable SSID checking before storing a scan table
-#ifdef DISCARD_BAD_SSID
-#define CHECK_SSID_IS_VALID(x) ssid_valid(&bssidEntry.ssid)
-#else
-#define CHECK_SSID_IS_VALID(x) 1
-#endif
+static const u8 zeromac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+static const u8 bcastmac[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+
+static inline void clear_bss_descriptor (struct bss_descriptor * bss)
+{
+	/* Don't blow away ->list, just BSS data */
+	memset(bss, 0, offsetof(struct bss_descriptor, list));
+}
+
+static inline int match_bss_no_security(struct wlan_802_11_security * secinfo,
+			struct bss_descriptor * match_bss)
+{
+	if (   !secinfo->wep_enabled
+	    && !secinfo->WPAenabled
+	    && !secinfo->WPA2enabled
+	    && match_bss->wpa_ie[0] != WPA_IE
+	    && match_bss->rsn_ie[0] != WPA2_IE
+	    && !match_bss->privacy) {
+		return 1;
+	}
+	return 0;
+}
+
+static inline int match_bss_static_wep(struct wlan_802_11_security * secinfo,
+			struct bss_descriptor * match_bss)
+{
+	if ( secinfo->wep_enabled
+	   && !secinfo->WPAenabled
+	   && !secinfo->WPA2enabled
+	   && match_bss->privacy) {
+		return 1;
+	}
+	return 0;
+}
+
+static inline int match_bss_wpa(struct wlan_802_11_security * secinfo,
+			struct bss_descriptor * match_bss)
+{
+	if (  !secinfo->wep_enabled
+	   && secinfo->WPAenabled
+	   && (match_bss->wpa_ie[0] == WPA_IE)
+	   /* privacy bit may NOT be set in some APs like LinkSys WRT54G
+	      && bss->privacy */
+	   ) {
+		return 1;
+	}
+	return 0;
+}
+
+static inline int match_bss_wpa2(struct wlan_802_11_security * secinfo,
+			struct bss_descriptor * match_bss)
+{
+	if (  !secinfo->wep_enabled
+	   && secinfo->WPA2enabled
+	   && (match_bss->rsn_ie[0] == WPA2_IE)
+	   /* privacy bit may NOT be set in some APs like LinkSys WRT54G
+	      && bss->privacy */
+	   ) {
+		return 1;
+	}
+	return 0;
+}
+
+static inline int match_bss_dynamic_wep(struct wlan_802_11_security * secinfo,
+			struct bss_descriptor * match_bss)
+{
+	if (  !secinfo->wep_enabled
+	   && !secinfo->WPAenabled
+	   && !secinfo->WPA2enabled
+	   && (match_bss->wpa_ie[0] != WPA_IE)
+	   && (match_bss->rsn_ie[0] != WPA2_IE)
+	   && match_bss->privacy) {
+		return 1;
+	}
+	return 0;
+}
 
 /**
  *  @brief Check if a scanned network compatible with the driver settings
@@ -84,123 +155,63 @@
  *
  *  @return        Index in scantable, or error code if negative
  */
-static int is_network_compatible(wlan_adapter * adapter, int index, u8 mode)
+static int is_network_compatible(wlan_adapter * adapter,
+		struct bss_descriptor * bss, u8 mode)
 {
-	ENTER();
+	int matched = 0;
 
-	if (adapter->scantable[index].mode == mode) {
-		if (   !adapter->secinfo.wep_enabled
-		    && !adapter->secinfo.WPAenabled
-		    && !adapter->secinfo.WPA2enabled
-		    && adapter->scantable[index].wpa_ie[0] != WPA_IE
-		    && adapter->scantable[index].rsn_ie[0] != WPA2_IE
-		    && !adapter->scantable[index].privacy) {
-			/* no security */
-			LEAVE();
-			return index;
-		} else if (   adapter->secinfo.wep_enabled
-			   && !adapter->secinfo.WPAenabled
-			   && !adapter->secinfo.WPA2enabled
-			   && adapter->scantable[index].privacy) {
-			/* static WEP enabled */
-			LEAVE();
-			return index;
-		} else if (   !adapter->secinfo.wep_enabled
-			   && adapter->secinfo.WPAenabled
-			   && !adapter->secinfo.WPA2enabled
-			   && (adapter->scantable[index].wpa_ie[0] == WPA_IE)
-			   /* privacy bit may NOT be set in some APs like LinkSys WRT54G
-			      && adapter->scantable[index].privacy */
-		    ) {
-			/* WPA enabled */
-			lbs_pr_debug(1,
-			       "is_network_compatible() WPA: index=%d wpa_ie=%#x "
-			       "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
-			       "privacy=%#x\n", index,
-			       adapter->scantable[index].wpa_ie[0],
-			       adapter->scantable[index].rsn_ie[0],
-			       adapter->secinfo.wep_enabled ? "e" : "d",
-			       adapter->secinfo.WPAenabled ? "e" : "d",
-			       adapter->secinfo.WPA2enabled ? "e" : "d",
-			       adapter->scantable[index].privacy);
-			LEAVE();
-			return index;
-		} else if (   !adapter->secinfo.wep_enabled
-			   && !adapter->secinfo.WPAenabled
-			   && adapter->secinfo.WPA2enabled
-			   && (adapter->scantable[index].rsn_ie[0] == WPA2_IE)
-			   /* privacy bit may NOT be set in some APs like LinkSys WRT54G
-			      && adapter->scantable[index].privacy */
-		    ) {
-			/* WPA2 enabled */
-			lbs_pr_debug(1,
-			       "is_network_compatible() WPA2: index=%d wpa_ie=%#x "
-			       "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
-			       "privacy=%#x\n", index,
-			       adapter->scantable[index].wpa_ie[0],
-			       adapter->scantable[index].rsn_ie[0],
-			       adapter->secinfo.wep_enabled ? "e" : "d",
-			       adapter->secinfo.WPAenabled ? "e" : "d",
-			       adapter->secinfo.WPA2enabled ? "e" : "d",
-			       adapter->scantable[index].privacy);
-			LEAVE();
-			return index;
-		} else if (   !adapter->secinfo.wep_enabled
-			   && !adapter->secinfo.WPAenabled
-			   && !adapter->secinfo.WPA2enabled
-			   && (adapter->scantable[index].wpa_ie[0] != WPA_IE)
-			   && (adapter->scantable[index].rsn_ie[0] != WPA2_IE)
-			   && adapter->scantable[index].privacy) {
-			/* dynamic WEP enabled */
-			lbs_pr_debug(1,
-			       "is_network_compatible() dynamic WEP: index=%d "
-			       "wpa_ie=%#x wpa2_ie=%#x privacy=%#x\n",
-			       index,
-			       adapter->scantable[index].wpa_ie[0],
-			       adapter->scantable[index].rsn_ie[0],
-			       adapter->scantable[index].privacy);
-			LEAVE();
-			return index;
-		}
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
-		/* security doesn't match */
-		lbs_pr_debug(1,
-		       "is_network_compatible() FAILED: index=%d wpa_ie=%#x "
-		       "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s privacy=%#x\n",
-		       index,
-		       adapter->scantable[index].wpa_ie[0],
-		       adapter->scantable[index].rsn_ie[0],
+	if (bss->mode != mode)
+		goto done;
+
+	if ((matched = match_bss_no_security(&adapter->secinfo, bss))) {
+		goto done;
+	} else if ((matched = match_bss_static_wep(&adapter->secinfo, bss))) {
+		goto done;
+	} else if ((matched = match_bss_wpa(&adapter->secinfo, bss))) {
+		lbs_deb_scan(
+		       "is_network_compatible() WPA: wpa_ie=%#x "
+		       "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
+		       "privacy=%#x\n", bss->wpa_ie[0], bss->rsn_ie[0],
 		       adapter->secinfo.wep_enabled ? "e" : "d",
 		       adapter->secinfo.WPAenabled ? "e" : "d",
 		       adapter->secinfo.WPA2enabled ? "e" : "d",
-		       adapter->scantable[index].privacy);
-		LEAVE();
-		return -ECONNREFUSED;
+		       bss->privacy);
+		goto done;
+	} else if ((matched = match_bss_wpa2(&adapter->secinfo, bss))) {
+		lbs_deb_scan(
+		       "is_network_compatible() WPA2: wpa_ie=%#x "
+		       "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
+		       "privacy=%#x\n", bss->wpa_ie[0], bss->rsn_ie[0],
+		       adapter->secinfo.wep_enabled ? "e" : "d",
+		       adapter->secinfo.WPAenabled ? "e" : "d",
+		       adapter->secinfo.WPA2enabled ? "e" : "d",
+		       bss->privacy);
+		goto done;
+	} else if ((matched = match_bss_dynamic_wep(&adapter->secinfo, bss))) {
+		lbs_deb_scan(
+		       "is_network_compatible() dynamic WEP: "
+		       "wpa_ie=%#x wpa2_ie=%#x privacy=%#x\n",
+		       bss->wpa_ie[0],
+		       bss->rsn_ie[0],
+		       bss->privacy);
+		goto done;
 	}
 
-	/* mode doesn't match */
-	LEAVE();
-	return -ENETUNREACH;
-}
+	/* bss security settings don't match those configured on card */
+	lbs_deb_scan(
+	       "is_network_compatible() FAILED: wpa_ie=%#x "
+	       "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s privacy=%#x\n",
+	       bss->wpa_ie[0], bss->rsn_ie[0],
+	       adapter->secinfo.wep_enabled ? "e" : "d",
+	       adapter->secinfo.WPAenabled ? "e" : "d",
+	       adapter->secinfo.WPA2enabled ? "e" : "d",
+	       bss->privacy);
 
-/**
- *  @brief This function validates a SSID as being able to be printed
- *
- *  @param pssid   SSID structure to validate
- *
- *  @return        TRUE or FALSE
- */
-static u8 ssid_valid(struct WLAN_802_11_SSID *pssid)
-{
-	int ssididx;
-
-	for (ssididx = 0; ssididx < pssid->ssidlength; ssididx++) {
-		if (!isprint(pssid->ssid[ssididx])) {
-			return 0;
-		}
-	}
-
-	return 1;
+done:
+	lbs_deb_leave(LBS_DEB_SCAN);
+	return matched;
 }
 
 /**
@@ -220,44 +231,19 @@
 static void wlan_scan_process_results(wlan_private * priv)
 {
 	wlan_adapter *adapter = priv->adapter;
-	int foundcurrent;
-	int i;
+	struct bss_descriptor * iter_bss;
+	int i = 0;
 
-	foundcurrent = 0;
+	if (adapter->connect_status == libertas_connected)
+		return;
 
-	if (adapter->connect_status == libertas_connected) {
-		/* try to find the current BSSID in the new scan list */
-		for (i = 0; i < adapter->numinscantable; i++) {
-			if (!libertas_SSID_cmp(&adapter->scantable[i].ssid,
-				     &adapter->curbssparams.ssid) &&
-			    !memcmp(adapter->curbssparams.bssid,
-				    adapter->scantable[i].macaddress,
-				    ETH_ALEN)) {
-				foundcurrent = 1;
-			}
-		}
-
-		if (foundcurrent) {
-			/* Make a copy of current BSSID descriptor */
-			memcpy(&adapter->curbssparams.bssdescriptor,
-			       &adapter->scantable[i],
-			       sizeof(adapter->curbssparams.bssdescriptor));
-		}
+	mutex_lock(&adapter->lock);
+	list_for_each_entry (iter_bss, &adapter->network_list, list) {
+		lbs_deb_scan("Scan:(%02d) " MAC_FMT ", RSSI[%03d], SSID[%s]\n",
+		       i++, MAC_ARG(iter_bss->bssid), (s32) iter_bss->rssi,
+		       escape_essid(iter_bss->ssid, iter_bss->ssid_len));
 	}
-
-	for (i = 0; i < adapter->numinscantable; i++) {
-		lbs_pr_debug(1, "Scan:(%02d) %02x:%02x:%02x:%02x:%02x:%02x, "
-		       "RSSI[%03d], SSID[%s]\n",
-		       i,
-		       adapter->scantable[i].macaddress[0],
-		       adapter->scantable[i].macaddress[1],
-		       adapter->scantable[i].macaddress[2],
-		       adapter->scantable[i].macaddress[3],
-		       adapter->scantable[i].macaddress[4],
-		       adapter->scantable[i].macaddress[5],
-		       (s32) adapter->scantable[i].rssi,
-		       adapter->scantable[i].ssid.ssid);
-	}
+	mutex_unlock(&adapter->lock);
 }
 
 /**
@@ -338,14 +324,12 @@
 
 			if (scantype == cmd_scan_type_passive) {
 				scanchanlist[chanidx].maxscantime =
-				    cpu_to_le16
-				    (MRVDRV_PASSIVE_SCAN_CHAN_TIME);
+				    cpu_to_le16(MRVDRV_PASSIVE_SCAN_CHAN_TIME);
 				scanchanlist[chanidx].chanscanmode.passivescan =
 				    1;
 			} else {
 				scanchanlist[chanidx].maxscantime =
-				    cpu_to_le16
-				    (MRVDRV_ACTIVE_SCAN_CHAN_TIME);
+				    cpu_to_le16(MRVDRV_ACTIVE_SCAN_CHAN_TIME);
 				scanchanlist[chanidx].chanscanmode.passivescan =
 				    0;
 			}
@@ -408,13 +392,11 @@
 			    u8 * pscancurrentonly)
 {
 	wlan_adapter *adapter = priv->adapter;
-	const u8 zeromac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
 	struct mrvlietypes_numprobes *pnumprobestlv;
 	struct mrvlietypes_ssidparamset *pssidtlv;
 	struct wlan_scan_cmd_config * pscancfgout = NULL;
 	u8 *ptlvpos;
 	u16 numprobes;
-	u16 ssidlen;
 	int chanidx;
 	int scantype;
 	int scandur;
@@ -471,21 +453,18 @@
 		 * Set the BSSID filter to the incoming configuration,
 		 *   if non-zero.  If not set, it will remain disabled (all zeros).
 		 */
-		memcpy(pscancfgout->specificBSSID,
-		       puserscanin->specificBSSID,
-		       sizeof(pscancfgout->specificBSSID));
+		memcpy(pscancfgout->bssid, puserscanin->bssid,
+		       sizeof(pscancfgout->bssid));
 
-		ssidlen = strlen(puserscanin->specificSSID);
-
-		if (ssidlen) {
+		if (puserscanin->ssid_len) {
 			pssidtlv =
 			    (struct mrvlietypes_ssidparamset *) pscancfgout->
 			    tlvbuffer;
 			pssidtlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
-			pssidtlv->header.len = cpu_to_le16(ssidlen);
-			memcpy(pssidtlv->ssid, puserscanin->specificSSID,
-			       ssidlen);
-			ptlvpos += sizeof(pssidtlv->header) + ssidlen;
+			pssidtlv->header.len = cpu_to_le16(puserscanin->ssid_len);
+			memcpy(pssidtlv->ssid, puserscanin->ssid,
+			       puserscanin->ssid_len);
+			ptlvpos += sizeof(pssidtlv->header) + puserscanin->ssid_len;
 		}
 
 		/*
@@ -494,8 +473,8 @@
 		 *    scan results.  That is not an issue with an SSID or BSSID
 		 *    filter applied to the scan results in the firmware.
 		 */
-		if (ssidlen || (memcmp(pscancfgout->specificBSSID,
-				       &zeromac, sizeof(zeromac)) != 0)) {
+		if (   puserscanin->ssid_len
+		    || (compare_ether_addr(pscancfgout->bssid, &zeromac[0]) != 0)) {
 			*pmaxchanperscan = MRVDRV_MAX_CHANNELS_PER_SCAN;
 			*pfilteredscan = 1;
 		}
@@ -507,16 +486,11 @@
 	/* If the input config or adapter has the number of Probes set, add tlv */
 	if (numprobes) {
 		pnumprobestlv = (struct mrvlietypes_numprobes *) ptlvpos;
-		pnumprobestlv->header.type =
-		    cpu_to_le16(TLV_TYPE_NUMPROBES);
-		pnumprobestlv->header.len = sizeof(pnumprobestlv->numprobes);
+		pnumprobestlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
+		pnumprobestlv->header.len = cpu_to_le16(2);
 		pnumprobestlv->numprobes = cpu_to_le16(numprobes);
 
-		ptlvpos +=
-		    sizeof(pnumprobestlv->header) + pnumprobestlv->header.len;
-
-		pnumprobestlv->header.len =
-		    cpu_to_le16(pnumprobestlv->header.len);
+		ptlvpos += sizeof(*pnumprobestlv);
 	}
 
 	/*
@@ -529,7 +503,7 @@
 
 	if (puserscanin && puserscanin->chanlist[0].channumber) {
 
-		lbs_pr_debug(1, "Scan: Using supplied channel list\n");
+		lbs_deb_scan("Scan: Using supplied channel list\n");
 
 		for (chanidx = 0;
 		     chanidx < WLAN_IOCTL_USER_SCAN_CHAN_MAX
@@ -573,11 +547,11 @@
 				       ==
 				       priv->adapter->curbssparams.channel)) {
 			*pscancurrentonly = 1;
-			lbs_pr_debug(1, "Scan: Scanning current channel only");
+			lbs_deb_scan("Scan: Scanning current channel only");
 		}
 
 	} else {
-		lbs_pr_debug(1, "Scan: Creating full region channel list\n");
+		lbs_deb_scan("Scan: Creating full region channel list\n");
 		wlan_scan_create_channel_list(priv, pscanchanlist,
 					      *pfilteredscan);
 	}
@@ -613,7 +587,9 @@
 				  u8 filteredscan,
 				  struct wlan_scan_cmd_config * pscancfgout,
 				  struct mrvlietypes_chanlistparamset * pchantlvout,
-				  struct chanscanparamset * pscanchanlist)
+				  struct chanscanparamset * pscanchanlist,
+				  const struct wlan_ioctl_user_scan_cfg * puserscanin,
+				  int full_scan)
 {
 	struct chanscanparamset *ptmpchan;
 	struct chanscanparamset *pstartchan;
@@ -621,11 +597,13 @@
 	int doneearly;
 	int tlvidx;
 	int ret = 0;
+	int scanned = 0;
+	union iwreq_data wrqu;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	if (pscancfgout == 0 || pchantlvout == 0 || pscanchanlist == 0) {
-		lbs_pr_debug(1, "Scan: Null detect: %p, %p, %p\n",
+		lbs_deb_scan("Scan: Null detect: %p, %p, %p\n",
 		       pscancfgout, pchantlvout, pscanchanlist);
 		return -1;
 	}
@@ -635,6 +613,9 @@
 	/* Set the temp channel struct pointer to the start of the desired list */
 	ptmpchan = pscanchanlist;
 
+	if (priv->adapter->last_scanned_channel && !puserscanin)
+		ptmpchan += priv->adapter->last_scanned_channel;
+
 	/* Loop through the desired channel list, sending a new firmware scan
 	 *   commands for each maxchanperscan channels (or for 1,6,11 individually
 	 *   if configured accordingly)
@@ -654,9 +635,9 @@
 		 *    - doneearly is set (controlling individual scanning of 1,6,11)
 		 */
 		while (tlvidx < maxchanperscan && ptmpchan->channumber
-		       && !doneearly) {
+		       && !doneearly && scanned < 2) {
 
-            lbs_pr_debug(1,
+            lbs_deb_scan(
                     "Scan: Chan(%3d), Radio(%d), mode(%d,%d), Dur(%d)\n",
                 ptmpchan->channumber, ptmpchan->radiotype,
                 ptmpchan->chanscanmode.passivescan,
@@ -668,8 +649,11 @@
 			       ptmpchan, sizeof(pchantlvout->chanscanparam));
 
 			/* Increment the TLV header length by the size appended */
-			pchantlvout->header.len +=
-			    sizeof(pchantlvout->chanscanparam);
+			/* Ew, it would be _so_ nice if we could just declare the
+			   variable little-endian and let GCC handle it for us */
+			pchantlvout->header.len =
+				cpu_to_le16(le16_to_cpu(pchantlvout->header.len) +
+					    sizeof(pchantlvout->chanscanparam));
 
 			/*
 			 *  The tlv buffer length is set to the number of bytes of the
@@ -683,7 +667,7 @@
 			/*  Add the size of the channel tlv header and the data length */
 			pscancfgout->tlvbufferlen +=
 			    (sizeof(pchantlvout->header)
-			     + pchantlvout->header.len);
+			     + le16_to_cpu(pchantlvout->header.len));
 
 			/* Increment the index to the channel tlv we are constructing */
 			tlvidx++;
@@ -701,6 +685,7 @@
 
 			/* Increment the tmp pointer to the next channel to be scanned */
 			ptmpchan++;
+			scanned++;
 
 			/* Stop the loop if the *next* channel is in the 1,6,11 set.
 			 *  This will cause it to be the only channel scanned on the next
@@ -716,12 +701,71 @@
 		/* Send the scan command to the firmware with the specified cfg */
 		ret = libertas_prepare_and_send_command(priv, cmd_802_11_scan, 0,
 					    0, 0, pscancfgout);
+		if (scanned >= 2 && !full_scan) {
+			ret = 0;
+			goto done;
+		}
+		scanned = 0;
 	}
 
-	LEAVE();
+done:
+	priv->adapter->last_scanned_channel = ptmpchan->channumber;
+
+	/* Tell userspace the scan table has been updated */
+	memset(&wrqu, 0, sizeof(union iwreq_data));
+	wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
+
+	lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
 	return ret;
 }
 
+static void
+clear_selected_scan_list_entries(wlan_adapter * adapter,
+                                 const struct wlan_ioctl_user_scan_cfg * scan_cfg)
+{
+	struct bss_descriptor * bss;
+	struct bss_descriptor * safe;
+	u32 clear_ssid_flag = 0, clear_bssid_flag = 0;
+
+	if (!scan_cfg)
+		return;
+
+	if (scan_cfg->clear_ssid && scan_cfg->ssid_len)
+		clear_ssid_flag = 1;
+
+	if (scan_cfg->clear_bssid
+	    && (compare_ether_addr(scan_cfg->bssid, &zeromac[0]) != 0)
+	    && (compare_ether_addr(scan_cfg->bssid, &bcastmac[0]) != 0)) {
+		clear_bssid_flag = 1;
+	}
+
+	if (!clear_ssid_flag && !clear_bssid_flag)
+		return;
+
+	mutex_lock(&adapter->lock);
+	list_for_each_entry_safe (bss, safe, &adapter->network_list, list) {
+		u32 clear = 0;
+
+		/* Check for an SSID match */
+		if (   clear_ssid_flag
+		    && (bss->ssid_len == scan_cfg->ssid_len)
+		    && !memcmp(bss->ssid, scan_cfg->ssid, bss->ssid_len))
+			clear = 1;
+
+		/* Check for a BSSID match */
+		if (   clear_bssid_flag
+		    && !compare_ether_addr(bss->bssid, scan_cfg->bssid))
+			clear = 1;
+
+		if (clear) {
+			list_move_tail (&bss->list, &adapter->network_free_list);
+			clear_bss_descriptor(bss);
+		}
+	}
+	mutex_unlock(&adapter->lock);
+}
+
+
 /**
  *  @brief Internal function used to start a scan based on an input config
  *
@@ -736,19 +780,19 @@
  *  @return              0 or < 0 if error
  */
 int wlan_scan_networks(wlan_private * priv,
-			      const struct wlan_ioctl_user_scan_cfg * puserscanin)
+			      const struct wlan_ioctl_user_scan_cfg * puserscanin,
+			      int full_scan)
 {
-	wlan_adapter *adapter = priv->adapter;
+	wlan_adapter * adapter = priv->adapter;
 	struct mrvlietypes_chanlistparamset *pchantlvout;
 	struct chanscanparamset * scan_chan_list = NULL;
 	struct wlan_scan_cmd_config * scan_cfg = NULL;
-	u8 keeppreviousscan;
 	u8 filteredscan;
 	u8 scancurrentchanonly;
 	int maxchanperscan;
 	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	scan_chan_list = kzalloc(sizeof(struct chanscanparamset) *
 				WLAN_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL);
@@ -769,22 +813,14 @@
 		goto out;
 	}
 
-	keeppreviousscan = 0;
-
-	if (puserscanin) {
-		keeppreviousscan = puserscanin->keeppreviousscan;
-	}
-
-	if (!keeppreviousscan) {
-		memset(adapter->scantable, 0x00,
-		       sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST);
-		adapter->numinscantable = 0;
-	}
+	clear_selected_scan_list_entries(adapter, puserscanin);
 
 	/* Keep the data path active if we are only scanning our current channel */
 	if (!scancurrentchanonly) {
-		netif_stop_queue(priv->wlan_dev.netdev);
-		netif_carrier_off(priv->wlan_dev.netdev);
+		netif_stop_queue(priv->dev);
+		netif_carrier_off(priv->dev);
+		netif_stop_queue(priv->mesh_dev);
+		netif_carrier_off(priv->mesh_dev);
 	}
 
 	ret = wlan_scan_channel_list(priv,
@@ -792,7 +828,9 @@
 				     filteredscan,
 				     scan_cfg,
 				     pchantlvout,
-				     scan_chan_list);
+				     scan_chan_list,
+				     puserscanin,
+				     full_scan);
 
 	/*  Process the resulting scan table:
 	 *    - Remove any bad ssids
@@ -801,8 +839,10 @@
 	wlan_scan_process_results(priv);
 
 	if (priv->adapter->connect_status == libertas_connected) {
-		netif_carrier_on(priv->wlan_dev.netdev);
-		netif_wake_queue(priv->wlan_dev.netdev);
+		netif_carrier_on(priv->dev);
+		netif_wake_queue(priv->dev);
+		netif_carrier_on(priv->mesh_dev);
+		netif_wake_queue(priv->mesh_dev);
 	}
 
 out:
@@ -812,7 +852,7 @@
 	if (scan_chan_list)
 		kfree(scan_chan_list);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
 	return ret;
 }
 
@@ -843,7 +883,7 @@
 	tlvbufleft = tlvbufsize;
 	*ptsftlv = NULL;
 
-	lbs_pr_debug(1, "SCAN_RESP: tlvbufsize = %d\n", tlvbufsize);
+	lbs_deb_scan("SCAN_RESP: tlvbufsize = %d\n", tlvbufsize);
 	lbs_dbg_hex("SCAN_RESP: TLV Buf", (u8 *) ptlv, tlvbufsize);
 
 	while (tlvbufleft >= sizeof(struct mrvlietypesheader)) {
@@ -856,7 +896,7 @@
 			break;
 
 		default:
-			lbs_pr_debug(1, "SCAN_RESP: Unhandled TLV = %d\n",
+			lbs_deb_scan("SCAN_RESP: Unhandled TLV = %d\n",
 			       tlvtype);
 			/* Give up, this seems corrupted */
 			return;
@@ -875,12 +915,12 @@
  *   response or beacon from the scan command.  Record information as needed
  *   in the scan table struct bss_descriptor for that entry.
  *
- *  @param pBSSIDEntry  Output parameter: Pointer to the BSS Entry
+ *  @param bss  Output parameter: Pointer to the BSS Entry
  *
  *  @return             0 or -1
  */
-static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
-					 u8 ** pbeaconinfo, int *bytesleft)
+static int libertas_process_bss(struct bss_descriptor * bss,
+				u8 ** pbeaconinfo, int *bytesleft)
 {
 	enum ieeetypes_elementid elemID;
 	struct ieeetypes_fhparamset *pFH;
@@ -897,13 +937,14 @@
 	u16 beaconsize;
 	u8 founddatarateie;
 	int bytesleftforcurrentbeacon;
+	int ret;
 
 	struct IE_WPA *pIe;
 	const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 };
 
 	struct ieeetypes_countryinfoset *pcountryinfo;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	founddatarateie = 0;
 	ratesize = 0;
@@ -911,8 +952,7 @@
 
 	if (*bytesleft >= sizeof(beaconsize)) {
 		/* Extract & convert beacon size from the command buffer */
-		memcpy(&beaconsize, *pbeaconinfo, sizeof(beaconsize));
-		beaconsize = le16_to_cpu(beaconsize);
+		beaconsize = le16_to_cpup((void *)*pbeaconinfo);
 		*bytesleft -= sizeof(beaconsize);
 		*pbeaconinfo += sizeof(beaconsize);
 	}
@@ -934,17 +974,14 @@
 
 	bytesleftforcurrentbeacon = beaconsize;
 
-	memcpy(pBSSEntry->macaddress, pcurrentptr, ETH_ALEN);
-	lbs_pr_debug(1, "InterpretIE: AP MAC Addr-%x:%x:%x:%x:%x:%x\n",
-	       pBSSEntry->macaddress[0], pBSSEntry->macaddress[1],
-	       pBSSEntry->macaddress[2], pBSSEntry->macaddress[3],
-	       pBSSEntry->macaddress[4], pBSSEntry->macaddress[5]);
+	memcpy(bss->bssid, pcurrentptr, ETH_ALEN);
+	lbs_deb_scan("process_bss: AP BSSID " MAC_FMT "\n", MAC_ARG(bss->bssid));
 
 	pcurrentptr += ETH_ALEN;
 	bytesleftforcurrentbeacon -= ETH_ALEN;
 
 	if (bytesleftforcurrentbeacon < 12) {
-		lbs_pr_debug(1, "InterpretIE: Not enough bytes left\n");
+		lbs_deb_scan("process_bss: Not enough bytes left\n");
 		return -1;
 	}
 
@@ -954,51 +991,48 @@
 	 */
 
 	/* RSSI is 1 byte long */
-	pBSSEntry->rssi = le32_to_cpu((long)(*pcurrentptr));
-	lbs_pr_debug(1, "InterpretIE: RSSI=%02X\n", *pcurrentptr);
+	bss->rssi = *pcurrentptr;
+	lbs_deb_scan("process_bss: RSSI=%02X\n", *pcurrentptr);
 	pcurrentptr += 1;
 	bytesleftforcurrentbeacon -= 1;
 
 	/* time stamp is 8 bytes long */
-	memcpy(fixedie.timestamp, pcurrentptr, 8);
-	memcpy(pBSSEntry->timestamp, pcurrentptr, 8);
+	fixedie.timestamp = bss->timestamp = le64_to_cpup((void *)pcurrentptr);
 	pcurrentptr += 8;
 	bytesleftforcurrentbeacon -= 8;
 
 	/* beacon interval is 2 bytes long */
-	memcpy(&fixedie.beaconinterval, pcurrentptr, 2);
-	pBSSEntry->beaconperiod = le16_to_cpu(fixedie.beaconinterval);
+	fixedie.beaconinterval = bss->beaconperiod = le16_to_cpup((void *)pcurrentptr);
 	pcurrentptr += 2;
 	bytesleftforcurrentbeacon -= 2;
 
 	/* capability information is 2 bytes long */
-	memcpy(&fixedie.capabilities, pcurrentptr, 2);
-	lbs_pr_debug(1, "InterpretIE: fixedie.capabilities=0x%X\n",
+        memcpy(&fixedie.capabilities, pcurrentptr, 2);
+	lbs_deb_scan("process_bss: fixedie.capabilities=0x%X\n",
 	       fixedie.capabilities);
-	fixedie.capabilities = le16_to_cpu(fixedie.capabilities);
 	pcap = (struct ieeetypes_capinfo *) & fixedie.capabilities;
-	memcpy(&pBSSEntry->cap, pcap, sizeof(struct ieeetypes_capinfo));
+	memcpy(&bss->cap, pcap, sizeof(struct ieeetypes_capinfo));
 	pcurrentptr += 2;
 	bytesleftforcurrentbeacon -= 2;
 
 	/* rest of the current buffer are IE's */
-	lbs_pr_debug(1, "InterpretIE: IElength for this AP = %d\n",
+	lbs_deb_scan("process_bss: IE length for this AP = %d\n",
 	       bytesleftforcurrentbeacon);
 
-	lbs_dbg_hex("InterpretIE: IE info", (u8 *) pcurrentptr,
+	lbs_dbg_hex("process_bss: IE info", (u8 *) pcurrentptr,
 		bytesleftforcurrentbeacon);
 
 	if (pcap->privacy) {
-		lbs_pr_debug(1, "InterpretIE: AP WEP enabled\n");
-		pBSSEntry->privacy = wlan802_11privfilter8021xWEP;
+		lbs_deb_scan("process_bss: AP WEP enabled\n");
+		bss->privacy = wlan802_11privfilter8021xWEP;
 	} else {
-		pBSSEntry->privacy = wlan802_11privfilteracceptall;
+		bss->privacy = wlan802_11privfilteracceptall;
 	}
 
 	if (pcap->ibss == 1) {
-		pBSSEntry->mode = IW_MODE_ADHOC;
+		bss->mode = IW_MODE_ADHOC;
 	} else {
-		pBSSEntry->mode = IW_MODE_INFRA;
+		bss->mode = IW_MODE_INFRA;
 	}
 
 	/* process variable IE */
@@ -1007,94 +1041,83 @@
 		elemlen = *((u8 *) pcurrentptr + 1);
 
 		if (bytesleftforcurrentbeacon < elemlen) {
-			lbs_pr_debug(1, "InterpretIE: error in processing IE, "
+			lbs_deb_scan("process_bss: error in processing IE, "
 			       "bytes left < IE length\n");
 			bytesleftforcurrentbeacon = 0;
 			continue;
 		}
 
 		switch (elemID) {
-
 		case SSID:
-			pBSSEntry->ssid.ssidlength = elemlen;
-			memcpy(pBSSEntry->ssid.ssid, (pcurrentptr + 2),
-			       elemlen);
-			lbs_pr_debug(1, "ssid: %32s", pBSSEntry->ssid.ssid);
+			bss->ssid_len = elemlen;
+			memcpy(bss->ssid, (pcurrentptr + 2), elemlen);
+			lbs_deb_scan("ssid '%s', ssid length %u\n",
+			             escape_essid(bss->ssid, bss->ssid_len),
+			             bss->ssid_len);
 			break;
 
 		case SUPPORTED_RATES:
-			memcpy(pBSSEntry->datarates, (pcurrentptr + 2),
-			       elemlen);
-			memmove(pBSSEntry->libertas_supported_rates, (pcurrentptr + 2),
+			memcpy(bss->datarates, (pcurrentptr + 2), elemlen);
+			memmove(bss->libertas_supported_rates, (pcurrentptr + 2),
 				elemlen);
 			ratesize = elemlen;
 			founddatarateie = 1;
 			break;
 
 		case EXTRA_IE:
-			lbs_pr_debug(1, "InterpretIE: EXTRA_IE Found!\n");
-			pBSSEntry->extra_ie = 1;
+			lbs_deb_scan("process_bss: EXTRA_IE Found!\n");
 			break;
 
 		case FH_PARAM_SET:
 			pFH = (struct ieeetypes_fhparamset *) pcurrentptr;
-			memmove(&pBSSEntry->phyparamset.fhparamset, pFH,
+			memmove(&bss->phyparamset.fhparamset, pFH,
 				sizeof(struct ieeetypes_fhparamset));
-			pBSSEntry->phyparamset.fhparamset.dwelltime
-			    =
-			    le16_to_cpu(pBSSEntry->phyparamset.fhparamset.
-					     dwelltime);
+#if 0 /* I think we can store these LE */
+			bss->phyparamset.fhparamset.dwelltime
+			    = le16_to_cpu(bss->phyparamset.fhparamset.dwelltime);
+#endif
 			break;
 
 		case DS_PARAM_SET:
 			pDS = (struct ieeetypes_dsparamset *) pcurrentptr;
-
-			pBSSEntry->channel = pDS->currentchan;
-
-			memcpy(&pBSSEntry->phyparamset.dsparamset, pDS,
+			bss->channel = pDS->currentchan;
+			memcpy(&bss->phyparamset.dsparamset, pDS,
 			       sizeof(struct ieeetypes_dsparamset));
 			break;
 
 		case CF_PARAM_SET:
 			pCF = (struct ieeetypes_cfparamset *) pcurrentptr;
-
-			memcpy(&pBSSEntry->ssparamset.cfparamset, pCF,
+			memcpy(&bss->ssparamset.cfparamset, pCF,
 			       sizeof(struct ieeetypes_cfparamset));
 			break;
 
 		case IBSS_PARAM_SET:
 			pibss = (struct ieeetypes_ibssparamset *) pcurrentptr;
-			pBSSEntry->atimwindow =
-			    le32_to_cpu(pibss->atimwindow);
-
-			memmove(&pBSSEntry->ssparamset.ibssparamset, pibss,
+			bss->atimwindow = le32_to_cpu(pibss->atimwindow);
+			memmove(&bss->ssparamset.ibssparamset, pibss,
 				sizeof(struct ieeetypes_ibssparamset));
-
-			pBSSEntry->ssparamset.ibssparamset.atimwindow
-			    =
-			    le16_to_cpu(pBSSEntry->ssparamset.ibssparamset.
-					     atimwindow);
+#if 0
+			bss->ssparamset.ibssparamset.atimwindow
+			    = le16_to_cpu(bss->ssparamset.ibssparamset.atimwindow);
+#endif
 			break;
 
 			/* Handle Country Info IE */
 		case COUNTRY_INFO:
-			pcountryinfo =
-			    (struct ieeetypes_countryinfoset *) pcurrentptr;
-
-			if (pcountryinfo->len <
-			    sizeof(pcountryinfo->countrycode)
+			pcountryinfo = (struct ieeetypes_countryinfoset *) pcurrentptr;
+			if (pcountryinfo->len < sizeof(pcountryinfo->countrycode)
 			    || pcountryinfo->len > 254) {
-				lbs_pr_debug(1, "InterpretIE: 11D- Err "
+				lbs_deb_scan("process_bss: 11D- Err "
 				       "CountryInfo len =%d min=%zd max=254\n",
 				       pcountryinfo->len,
 				       sizeof(pcountryinfo->countrycode));
-				LEAVE();
-				return -1;
+				ret = -1;
+				goto done;
 			}
 
-			memcpy(&pBSSEntry->countryinfo,
+			memcpy(&bss->countryinfo,
 			       pcountryinfo, pcountryinfo->len + 2);
-			lbs_dbg_hex("InterpretIE: 11D- CountryInfo:",
+			lbs_dbg_hex("process_bss: 11D- CountryInfo:",
 				(u8 *) pcountryinfo,
 				(u32) (pcountryinfo->len + 2));
 			break;
@@ -1114,12 +1137,10 @@
 					bytestocopy = elemlen;
 				}
 
-				pRate = (u8 *) pBSSEntry->datarates;
+				pRate = (u8 *) bss->datarates;
 				pRate += ratesize;
 				memmove(pRate, (pcurrentptr + 2), bytestocopy);
-
-				pRate = (u8 *) pBSSEntry->libertas_supported_rates;
-
+				pRate = (u8 *) bss->libertas_supported_rates;
 				pRate += ratesize;
 				memmove(pRate, (pcurrentptr + 2), bytestocopy);
 			}
@@ -1132,24 +1153,17 @@
 			if (memcmp(pIe->oui, oui01, sizeof(oui01)))
 				break;
 
-			pBSSEntry->wpa_ie_len = min_t(size_t,
-				elemlen + IE_ID_LEN_FIELDS_BYTES,
-				sizeof(pBSSEntry->wpa_ie));
-			memcpy(pBSSEntry->wpa_ie, pcurrentptr,
-				pBSSEntry->wpa_ie_len);
-			lbs_dbg_hex("InterpretIE: Resp WPA_IE",
-				pBSSEntry->wpa_ie, elemlen);
+			bss->wpa_ie_len = min(elemlen + IE_ID_LEN_FIELDS_BYTES,
+				MAX_WPA_IE_LEN);
+			memcpy(bss->wpa_ie, pcurrentptr, bss->wpa_ie_len);
+			lbs_dbg_hex("process_bss: WPA IE", bss->wpa_ie, elemlen);
 			break;
 		case WPA2_IE:
 			pIe = (struct IE_WPA *)pcurrentptr;
-
-			pBSSEntry->rsn_ie_len = min_t(size_t,
-				elemlen + IE_ID_LEN_FIELDS_BYTES,
-				sizeof(pBSSEntry->rsn_ie));
-			memcpy(pBSSEntry->rsn_ie, pcurrentptr,
-				pBSSEntry->rsn_ie_len);
-			lbs_dbg_hex("InterpretIE: Resp WPA2_IE",
-				pBSSEntry->rsn_ie, elemlen);
+			bss->rsn_ie_len = min(elemlen + IE_ID_LEN_FIELDS_BYTES,
+				MAX_WPA_IE_LEN);
+			memcpy(bss->rsn_ie, pcurrentptr, bss->rsn_ie_len);
+			lbs_dbg_hex("process_bss: RSN_IE", bss->rsn_ie, elemlen);
 			break;
 		case TIM:
 			break;
@@ -1165,7 +1179,14 @@
 
 	}			/* while (bytesleftforcurrentbeacon > 2) */
 
-	return 0;
+	/* Timestamp */
+	bss->last_scanned = jiffies;
+
+	ret = 0;
+
+done:
+	lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
+	return ret;
 }
 
 /**
@@ -1176,15 +1197,12 @@
  *
  *  @return         0--ssid is same, otherwise is different
  */
-int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1, struct WLAN_802_11_SSID *ssid2)
+int libertas_ssid_cmp(u8 *ssid1, u8 ssid1_len, u8 *ssid2, u8 ssid2_len)
 {
-	if (!ssid1 || !ssid2)
+	if (ssid1_len != ssid2_len)
 		return -1;
 
-	if (ssid1->ssidlength != ssid2->ssidlength)
-		return -1;
-
-	return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssidlength);
+	return memcmp(ssid1, ssid2, ssid1_len);
 }
 
 /**
@@ -1196,38 +1214,41 @@
  *
  *  @return         index in BSSID list, or error return code (< 0)
  */
-int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, u8 mode)
+struct bss_descriptor * libertas_find_bssid_in_list(wlan_adapter * adapter,
+		u8 * bssid, u8 mode)
 {
-	int ret = -ENETUNREACH;
-	int i;
+	struct bss_descriptor * iter_bss;
+	struct bss_descriptor * found_bss = NULL;
 
 	if (!bssid)
-		return -EFAULT;
+		return NULL;
 
-	lbs_pr_debug(1, "FindBSSID: Num of BSSIDs = %d\n",
-	       adapter->numinscantable);
+	lbs_dbg_hex("libertas_find_BSSID_in_list: looking for ",
+		bssid, ETH_ALEN);
 
-	/* Look through the scan table for a compatible match. The ret return
-	 *   variable will be equal to the index in the scan table (greater
-	 *   than zero) if the network is compatible.  The loop will continue
-	 *   past a matched bssid that is not compatible in case there is an
-	 *   AP with multiple SSIDs assigned to the same BSSID
+	/* Look through the scan table for a compatible match.  The loop will
+	 *   continue past a matched bssid that is not compatible in case there
+	 *   is an AP with multiple SSIDs assigned to the same BSSID
 	 */
-	for (i = 0; ret < 0 && i < adapter->numinscantable; i++) {
-		if (!memcmp(adapter->scantable[i].macaddress, bssid, ETH_ALEN)) {
-			switch (mode) {
-			case IW_MODE_INFRA:
-			case IW_MODE_ADHOC:
-				ret = is_network_compatible(adapter, i, mode);
+	mutex_lock(&adapter->lock);
+	list_for_each_entry (iter_bss, &adapter->network_list, list) {
+		if (compare_ether_addr(iter_bss->bssid, bssid))
+			continue; /* bssid doesn't match */
+		switch (mode) {
+		case IW_MODE_INFRA:
+		case IW_MODE_ADHOC:
+			if (!is_network_compatible(adapter, iter_bss, mode))
 				break;
-			default:
-				ret = i;
-				break;
-			}
+			found_bss = iter_bss;
+			break;
+		default:
+			found_bss = iter_bss;
+			break;
 		}
 	}
+	mutex_unlock(&adapter->lock);
 
-	return ret;
+	return found_bss;
 }
 
 /**
@@ -1240,61 +1261,60 @@
  *
  *  @return         index in BSSID list
  */
-int libertas_find_SSID_in_list(wlan_adapter * adapter,
-		   struct WLAN_802_11_SSID *ssid, u8 * bssid, u8 mode)
+struct bss_descriptor * libertas_find_ssid_in_list(wlan_adapter * adapter,
+		   u8 *ssid, u8 ssid_len, u8 * bssid, u8 mode,
+		   int channel)
 {
-	int net = -ENETUNREACH;
 	u8 bestrssi = 0;
-	int i;
-	int j;
+	struct bss_descriptor * iter_bss = NULL;
+	struct bss_descriptor * found_bss = NULL;
+	struct bss_descriptor * tmp_oldest = NULL;
 
-	lbs_pr_debug(1, "Num of Entries in Table = %d\n", adapter->numinscantable);
+	mutex_lock(&adapter->lock);
 
-	for (i = 0; i < adapter->numinscantable; i++) {
-		if (!libertas_SSID_cmp(&adapter->scantable[i].ssid, ssid) &&
-		    (!bssid ||
-		     !memcmp(adapter->scantable[i].
-			     macaddress, bssid, ETH_ALEN))) {
-			switch (mode) {
-			case IW_MODE_INFRA:
-			case IW_MODE_ADHOC:
-				j = is_network_compatible(adapter, i, mode);
+	list_for_each_entry (iter_bss, &adapter->network_list, list) {
+		if (   !tmp_oldest
+		    || (iter_bss->last_scanned < tmp_oldest->last_scanned))
+			tmp_oldest = iter_bss;
 
-				if (j >= 0) {
-					if (bssid) {
-						return i;
-					}
+		if (libertas_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len,
+		                      ssid, ssid_len) != 0)
+			continue; /* ssid doesn't match */
+		if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0)
+			continue; /* bssid doesn't match */
+		if ((channel > 0) && (iter_bss->channel != channel))
+			continue; /* channel doesn't match */
 
-					if (SCAN_RSSI
-					    (adapter->scantable[i].rssi)
-					    > bestrssi) {
-						bestrssi =
-						    SCAN_RSSI(adapter->
-							      scantable[i].
-							      rssi);
-						net = i;
-					}
-				} else {
-					if (net == -ENETUNREACH) {
-						net = j;
-					}
-				}
+		switch (mode) {
+		case IW_MODE_INFRA:
+		case IW_MODE_ADHOC:
+			if (!is_network_compatible(adapter, iter_bss, mode))
 				break;
-			case IW_MODE_AUTO:
-			default:
-				if (SCAN_RSSI(adapter->scantable[i].rssi)
-				    > bestrssi) {
-					bestrssi =
-					    SCAN_RSSI(adapter->scantable[i].
-						      rssi);
-					net = i;
-				}
-				break;
+
+			if (bssid) {
+				/* Found requested BSSID */
+				found_bss = iter_bss;
+				goto out;
 			}
+
+			if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
+				bestrssi = SCAN_RSSI(iter_bss->rssi);
+				found_bss = iter_bss;
+			}
+			break;
+		case IW_MODE_AUTO:
+		default:
+			if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
+				bestrssi = SCAN_RSSI(iter_bss->rssi);
+				found_bss = iter_bss;
+			}
+			break;
 		}
 	}
 
-	return net;
+out:
+	mutex_unlock(&adapter->lock);
+	return found_bss;
 }
 
 /**
@@ -1307,43 +1327,38 @@
  *
  *  @return         index in BSSID list
  */
-int libertas_find_best_SSID_in_list(wlan_adapter * adapter, u8 mode)
+struct bss_descriptor * libertas_find_best_ssid_in_list(wlan_adapter * adapter,
+		u8 mode)
 {
-	int bestnet = -ENETUNREACH;
 	u8 bestrssi = 0;
-	int i;
+	struct bss_descriptor * iter_bss;
+	struct bss_descriptor * best_bss = NULL;
 
-	ENTER();
+	mutex_lock(&adapter->lock);
 
-	lbs_pr_debug(1, "Num of BSSIDs = %d\n", adapter->numinscantable);
-
-	for (i = 0; i < adapter->numinscantable; i++) {
+	list_for_each_entry (iter_bss, &adapter->network_list, list) {
 		switch (mode) {
 		case IW_MODE_INFRA:
 		case IW_MODE_ADHOC:
-			if (is_network_compatible(adapter, i, mode) >= 0) {
-				if (SCAN_RSSI(adapter->scantable[i].rssi) >
-				    bestrssi) {
-					bestrssi =
-					    SCAN_RSSI(adapter->scantable[i].
-						      rssi);
-					bestnet = i;
-				}
-			}
+			if (!is_network_compatible(adapter, iter_bss, mode))
+				break;
+			if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
+				break;
+			bestrssi = SCAN_RSSI(iter_bss->rssi);
+			best_bss = iter_bss;
 			break;
 		case IW_MODE_AUTO:
 		default:
-			if (SCAN_RSSI(adapter->scantable[i].rssi) > bestrssi) {
-				bestrssi =
-				    SCAN_RSSI(adapter->scantable[i].rssi);
-				bestnet = i;
-			}
+			if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
+				break;
+			bestrssi = SCAN_RSSI(iter_bss->rssi);
+			best_bss = iter_bss;
 			break;
 		}
 	}
 
-	LEAVE();
-	return bestnet;
+	mutex_unlock(&adapter->lock);
+	return best_bss;
 }
 
 /**
@@ -1354,41 +1369,30 @@
  *
  *  @return             0--success, otherwise--fail
  */
-int libertas_find_best_network_SSID(wlan_private * priv,
-                                    struct WLAN_802_11_SSID *pSSID,
-                                    u8 preferred_mode, u8 *out_mode)
+int libertas_find_best_network_ssid(wlan_private * priv,
+		u8 *out_ssid, u8 *out_ssid_len, u8 preferred_mode, u8 *out_mode)
 {
 	wlan_adapter *adapter = priv->adapter;
-	int ret = 0;
-	struct bss_descriptor *preqbssid;
-	int i;
+	int ret = -1;
+	struct bss_descriptor * found;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
-	memset(pSSID, 0, sizeof(struct WLAN_802_11_SSID));
-
-	wlan_scan_networks(priv, NULL);
+	wlan_scan_networks(priv, NULL, 1);
 	if (adapter->surpriseremoved)
 		return -1;
+
 	wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
 
-	i = libertas_find_best_SSID_in_list(adapter, preferred_mode);
-	if (i < 0) {
-		ret = -1;
-		goto out;
+	found = libertas_find_best_ssid_in_list(adapter, preferred_mode);
+	if (found && (found->ssid_len > 0)) {
+		memcpy(out_ssid, &found->ssid, IW_ESSID_MAX_SIZE);
+		*out_ssid_len = found->ssid_len;
+		*out_mode = found->mode;
+		ret = 0;
 	}
 
-	preqbssid = &adapter->scantable[i];
-	memcpy(pSSID, &preqbssid->ssid,
-	       sizeof(struct WLAN_802_11_SSID));
-	*out_mode = preqbssid->mode;
-
-	if (!pSSID->ssidlength) {
-		ret = -1;
-	}
-
-out:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
 	return ret;
 }
 
@@ -1407,20 +1411,15 @@
 {
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
-	union iwreq_data wrqu;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_SCAN);
 
-	if (!wlan_scan_networks(priv, NULL)) {
-		memset(&wrqu, 0, sizeof(union iwreq_data));
-		wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu,
-				    NULL);
-	}
+	wlan_scan_networks(priv, NULL, 0);
 
 	if (adapter->surpriseremoved)
 		return -1;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_SCAN);
 	return 0;
 }
 
@@ -1433,32 +1432,31 @@
  *
  *  @return                0-success, otherwise fail
  */
-int libertas_send_specific_SSID_scan(wlan_private * priv,
-			 struct WLAN_802_11_SSID *prequestedssid,
-			 u8 keeppreviousscan)
+int libertas_send_specific_ssid_scan(wlan_private * priv,
+			u8 *ssid, u8 ssid_len, u8 clear_ssid)
 {
 	wlan_adapter *adapter = priv->adapter;
 	struct wlan_ioctl_user_scan_cfg scancfg;
+	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
-	if (prequestedssid == NULL) {
-		return -1;
-	}
+	if (!ssid_len)
+		goto out;
 
 	memset(&scancfg, 0x00, sizeof(scancfg));
+	memcpy(scancfg.ssid, ssid, ssid_len);
+	scancfg.ssid_len = ssid_len;
+	scancfg.clear_ssid = clear_ssid;
 
-	memcpy(scancfg.specificSSID, prequestedssid->ssid,
-	       prequestedssid->ssidlength);
-	scancfg.keeppreviousscan = keeppreviousscan;
-
-	wlan_scan_networks(priv, &scancfg);
+	wlan_scan_networks(priv, &scancfg, 1);
 	if (adapter->surpriseremoved)
 		return -1;
 	wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
 
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave(LBS_DEB_ASSOC);
+	return ret;
 }
 
 /**
@@ -1470,30 +1468,169 @@
  *
  *  @return          0-success, otherwise fail
  */
-int libertas_send_specific_BSSID_scan(wlan_private * priv, u8 * bssid, u8 keeppreviousscan)
+int libertas_send_specific_bssid_scan(wlan_private * priv, u8 * bssid, u8 clear_bssid)
 {
 	struct wlan_ioctl_user_scan_cfg scancfg;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
-	if (bssid == NULL) {
-		return -1;
-	}
+	if (bssid == NULL)
+		goto out;
 
 	memset(&scancfg, 0x00, sizeof(scancfg));
-	memcpy(scancfg.specificBSSID, bssid, sizeof(scancfg.specificBSSID));
-	scancfg.keeppreviousscan = keeppreviousscan;
+	memcpy(scancfg.bssid, bssid, ETH_ALEN);
+	scancfg.clear_bssid = clear_bssid;
 
-	wlan_scan_networks(priv, &scancfg);
+	wlan_scan_networks(priv, &scancfg, 1);
 	if (priv->adapter->surpriseremoved)
 		return -1;
 	wait_event_interruptible(priv->adapter->cmd_pending,
 		!priv->adapter->nr_cmd_pending);
 
-	LEAVE();
+out:
+	lbs_deb_leave(LBS_DEB_ASSOC);
 	return 0;
 }
 
+static inline char *libertas_translate_scan(wlan_private *priv,
+					char *start, char *stop,
+					struct bss_descriptor *bss)
+{
+	wlan_adapter *adapter = priv->adapter;
+	struct chan_freq_power *cfp;
+	char *current_val;	/* For rates */
+	struct iw_event iwe;	/* Temporary buffer */
+	int j;
+#define PERFECT_RSSI ((u8)50)
+#define WORST_RSSI   ((u8)0)
+#define RSSI_DIFF    ((u8)(PERFECT_RSSI - WORST_RSSI))
+	u8 rssi;
+
+	cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, bss->channel);
+	if (!cfp) {
+		lbs_deb_scan("Invalid channel number %d\n", bss->channel);
+		return NULL;
+	}
+
+	/* First entry *MUST* be the AP BSSID */
+	iwe.cmd = SIOCGIWAP;
+	iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
+	memcpy(iwe.u.ap_addr.sa_data, &bss->bssid, ETH_ALEN);
+	start = iwe_stream_add_event(start, stop, &iwe, IW_EV_ADDR_LEN);
+
+	/* SSID */
+	iwe.cmd = SIOCGIWESSID;
+	iwe.u.data.flags = 1;
+	iwe.u.data.length = min((u32) bss->ssid_len, (u32) IW_ESSID_MAX_SIZE);
+	start = iwe_stream_add_point(start, stop, &iwe, bss->ssid);
+
+	/* Mode */
+	iwe.cmd = SIOCGIWMODE;
+	iwe.u.mode = bss->mode;
+	start = iwe_stream_add_event(start, stop, &iwe, IW_EV_UINT_LEN);
+
+	/* Frequency */
+	iwe.cmd = SIOCGIWFREQ;
+	iwe.u.freq.m = (long)cfp->freq * 100000;
+	iwe.u.freq.e = 1;
+	start = iwe_stream_add_event(start, stop, &iwe, IW_EV_FREQ_LEN);
+
+	/* Add quality statistics */
+	iwe.cmd = IWEVQUAL;
+	iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
+	iwe.u.qual.level = SCAN_RSSI(bss->rssi);
+
+	rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
+	iwe.u.qual.qual =
+	    (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
+	     (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
+	    (RSSI_DIFF * RSSI_DIFF);
+	if (iwe.u.qual.qual > 100)
+		iwe.u.qual.qual = 100;
+
+	if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
+		iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
+	} else {
+		iwe.u.qual.noise =
+		    CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
+	}
+
+	/* Locally created ad-hoc BSSs won't have beacons if this is the
+	 * only station in the adhoc network; so get signal strength
+	 * from receive statistics.
+	 */
+	if ((adapter->mode == IW_MODE_ADHOC)
+	    && adapter->adhoccreate
+	    && !libertas_ssid_cmp(adapter->curbssparams.ssid,
+	                          adapter->curbssparams.ssid_len,
+	                          bss->ssid, bss->ssid_len)) {
+		int snr, nf;
+		snr = adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
+		nf = adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
+		iwe.u.qual.level = CAL_RSSI(snr, nf);
+	}
+	start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN);
+
+	/* Add encryption capability */
+	iwe.cmd = SIOCGIWENCODE;
+	if (bss->privacy) {
+		iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
+	} else {
+		iwe.u.data.flags = IW_ENCODE_DISABLED;
+	}
+	iwe.u.data.length = 0;
+	start = iwe_stream_add_point(start, stop, &iwe, bss->ssid);
+
+	current_val = start + IW_EV_LCP_LEN;
+
+	iwe.cmd = SIOCGIWRATE;
+	iwe.u.bitrate.fixed = 0;
+	iwe.u.bitrate.disabled = 0;
+	iwe.u.bitrate.value = 0;
+
+	for (j = 0; j < sizeof(bss->libertas_supported_rates); j++) {
+		u8 rate = bss->libertas_supported_rates[j];
+		if (rate == 0)
+			break; /* no more rates */
+		/* Bit rate given in 500 kb/s units (+ 0x80) */
+		iwe.u.bitrate.value = (rate & 0x7f) * 500000;
+		current_val = iwe_stream_add_value(start, current_val,
+					 stop, &iwe, IW_EV_PARAM_LEN);
+	}
+	if ((bss->mode == IW_MODE_ADHOC)
+	    && !libertas_ssid_cmp(adapter->curbssparams.ssid,
+	                          adapter->curbssparams.ssid_len,
+	                          bss->ssid, bss->ssid_len)
+	    && adapter->adhoccreate) {
+		iwe.u.bitrate.value = 22 * 500000;
+		current_val = iwe_stream_add_value(start, current_val,
+					 stop, &iwe, IW_EV_PARAM_LEN);
+	}
+	/* Check if we added any event */
+	if((current_val - start) > IW_EV_LCP_LEN)
+		start = current_val;
+
+	memset(&iwe, 0, sizeof(iwe));
+	if (bss->wpa_ie_len) {
+		char buf[MAX_WPA_IE_LEN];
+		memcpy(buf, bss->wpa_ie, bss->wpa_ie_len);
+		iwe.cmd = IWEVGENIE;
+		iwe.u.data.length = bss->wpa_ie_len;
+		start = iwe_stream_add_point(start, stop, &iwe, buf);
+	}
+
+	memset(&iwe, 0, sizeof(iwe));
+	if (bss->rsn_ie_len) {
+		char buf[MAX_WPA_IE_LEN];
+		memcpy(buf, bss->rsn_ie, bss->rsn_ie_len);
+		iwe.cmd = IWEVGENIE;
+		iwe.u.data.length = bss->rsn_ie_len;
+		start = iwe_stream_add_point(start, stop, &iwe, buf);
+	}
+
+	return start;
+}
+
 /**
  *  @brief  Retrieve the scan table entries via wireless tools IOCTL call
  *
@@ -1507,267 +1644,59 @@
 int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
 		  struct iw_point *dwrq, char *extra)
 {
+#define SCAN_ITEM_SIZE 128
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
-	int ret = 0;
-	char *current_ev = extra;
-	char *end_buf = extra + IW_SCAN_MAX_DATA;
-	struct chan_freq_power *cfp;
-	struct bss_descriptor *pscantable;
-	char *current_val;	/* For rates */
-	struct iw_event iwe;	/* Temporary buffer */
-	int i;
-	int j;
-	int rate;
-#define PERFECT_RSSI ((u8)50)
-#define WORST_RSSI   ((u8)0)
-#define RSSI_DIFF    ((u8)(PERFECT_RSSI - WORST_RSSI))
-	u8 rssi;
+	int err = 0;
+	char *ev = extra;
+	char *stop = ev + dwrq->length;
+	struct bss_descriptor * iter_bss;
+	struct bss_descriptor * safe;
 
-	u8 buf[16 + 256 * 2];
-	u8 *ptr;
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
-	ENTER();
+	/* If we've got an uncompleted scan, schedule the next part */
+	if (!adapter->nr_cmd_pending && adapter->last_scanned_channel)
+		wlan_scan_networks(priv, NULL, 0);
 
-	/*
-	 * if there's either commands in the queue or one being
-	 * processed return -EAGAIN for iwlist to retry later.
-	 */
-    if (adapter->nr_cmd_pending)
-		return -EAGAIN;
+	/* Update RSSI if current BSS is a locally created ad-hoc BSS */
+	if ((adapter->mode == IW_MODE_ADHOC) && adapter->adhoccreate) {
+		libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
+					cmd_option_waitforrsp, 0, NULL);
+	}
 
-	if (adapter->connect_status == libertas_connected)
-		lbs_pr_debug(1, "Current ssid: %32s\n",
-		       adapter->curbssparams.ssid.ssid);
+	mutex_lock(&adapter->lock);
+	list_for_each_entry_safe (iter_bss, safe, &adapter->network_list, list) {
+		char * next_ev;
+		unsigned long stale_time;
 
-	lbs_pr_debug(1, "Scan: Get: numinscantable = %d\n",
-	       adapter->numinscantable);
-
-	/* The old API using SIOCGIWAPLIST had a hard limit of IW_MAX_AP.
-	 * The new API using SIOCGIWSCAN is only limited by buffer size
-	 * WE-14 -> WE-16 the buffer is limited to IW_SCAN_MAX_DATA bytes
-	 * which is 4096.
-	 */
-	for (i = 0; i < adapter->numinscantable; i++) {
-		if ((current_ev + MAX_SCAN_CELL_SIZE) >= end_buf) {
-			lbs_pr_debug(1, "i=%d break out: current_ev=%p end_buf=%p "
-			       "MAX_SCAN_CELL_SIZE=%zd\n",
-			       i, current_ev, end_buf, MAX_SCAN_CELL_SIZE);
+		if (stop - ev < SCAN_ITEM_SIZE) {
+			err = -E2BIG;
 			break;
 		}
 
-		pscantable = &adapter->scantable[i];
-
-		lbs_pr_debug(1, "i=%d  ssid: %32s\n", i, pscantable->ssid.ssid);
-
-		cfp =
-		    libertas_find_cfp_by_band_and_channel(adapter, 0,
-						 pscantable->channel);
-		if (!cfp) {
-			lbs_pr_debug(1, "Invalid channel number %d\n",
-			       pscantable->channel);
+		/* Prune old an old scan result */
+		stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
+		if (time_after(jiffies, stale_time)) {
+			list_move_tail (&iter_bss->list,
+			                &adapter->network_free_list);
+			clear_bss_descriptor(iter_bss);
 			continue;
 		}
 
-		if (!ssid_valid(&adapter->scantable[i].ssid)) {
+		/* Translate to WE format this entry */
+		next_ev = libertas_translate_scan(priv, ev, stop, iter_bss);
+		if (next_ev == NULL)
 			continue;
-		}
-
-		/* First entry *MUST* be the AP MAC address */
-		iwe.cmd = SIOCGIWAP;
-		iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
-		memcpy(iwe.u.ap_addr.sa_data,
-		       &adapter->scantable[i].macaddress, ETH_ALEN);
-
-		iwe.len = IW_EV_ADDR_LEN;
-		current_ev =
-		    iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
-
-		//Add the ESSID
-		iwe.u.data.length = adapter->scantable[i].ssid.ssidlength;
-
-		if (iwe.u.data.length > 32) {
-			iwe.u.data.length = 32;
-		}
-
-		iwe.cmd = SIOCGIWESSID;
-		iwe.u.data.flags = 1;
-		iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
-		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
-						  adapter->scantable[i].ssid.
-						  ssid);
-
-		//Add mode
-		iwe.cmd = SIOCGIWMODE;
-		iwe.u.mode = adapter->scantable[i].mode;
-		iwe.len = IW_EV_UINT_LEN;
-		current_ev =
-		    iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
-
-		//frequency
-		iwe.cmd = SIOCGIWFREQ;
-		iwe.u.freq.m = (long)cfp->freq * 100000;
-		iwe.u.freq.e = 1;
-		iwe.len = IW_EV_FREQ_LEN;
-		current_ev =
-		    iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
-
-		/* Add quality statistics */
-		iwe.cmd = IWEVQUAL;
-		iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
-		iwe.u.qual.level = SCAN_RSSI(adapter->scantable[i].rssi);
-
-		rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
-		iwe.u.qual.qual =
-		    (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
-		     (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
-		    (RSSI_DIFF * RSSI_DIFF);
-		if (iwe.u.qual.qual > 100)
-			iwe.u.qual.qual = 100;
-		else if (iwe.u.qual.qual < 1)
-			iwe.u.qual.qual = 0;
-
-		if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
-			iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
-		} else {
-			iwe.u.qual.noise =
-			    CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
-		}
-		if ((adapter->mode == IW_MODE_ADHOC) &&
-		    !libertas_SSID_cmp(&adapter->curbssparams.ssid,
-			     &adapter->scantable[i].ssid)
-		    && adapter->adhoccreate) {
-			ret = libertas_prepare_and_send_command(priv,
-						    cmd_802_11_rssi,
-						    0,
-						    cmd_option_waitforrsp,
-						    0, NULL);
-
-			if (!ret) {
-				iwe.u.qual.level =
-				    CAL_RSSI(adapter->SNR[TYPE_RXPD][TYPE_AVG] /
-					     AVG_SCALE,
-					     adapter->NF[TYPE_RXPD][TYPE_AVG] /
-					     AVG_SCALE);
-			}
-		}
-		iwe.len = IW_EV_QUAL_LEN;
-		current_ev =
-		    iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
-
-		/* Add encryption capability */
-		iwe.cmd = SIOCGIWENCODE;
-		if (adapter->scantable[i].privacy) {
-			iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
-		} else {
-			iwe.u.data.flags = IW_ENCODE_DISABLED;
-		}
-		iwe.u.data.length = 0;
-		iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
-		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
-						  adapter->scantable->ssid.
-						  ssid);
-
-		current_val = current_ev + IW_EV_LCP_LEN;
-
-		iwe.cmd = SIOCGIWRATE;
-
-		iwe.u.bitrate.fixed = 0;
-		iwe.u.bitrate.disabled = 0;
-		iwe.u.bitrate.value = 0;
-
-		/* Bit rate given in 500 kb/s units (+ 0x80) */
-		for (j = 0; j < sizeof(adapter->scantable[i].libertas_supported_rates);
-		     j++) {
-			if (adapter->scantable[i].libertas_supported_rates[j] == 0) {
-				break;
-			}
-			rate =
-			    (adapter->scantable[i].libertas_supported_rates[j] & 0x7F) *
-			    500000;
-			if (rate > iwe.u.bitrate.value) {
-				iwe.u.bitrate.value = rate;
-			}
-
-			iwe.u.bitrate.value =
-			    (adapter->scantable[i].libertas_supported_rates[j]
-			     & 0x7f) * 500000;
-			iwe.len = IW_EV_PARAM_LEN;
-			current_ev =
-			    iwe_stream_add_value(current_ev, current_val,
-						 end_buf, &iwe, iwe.len);
-
-		}
-		if ((adapter->scantable[i].mode == IW_MODE_ADHOC)
-		    && !libertas_SSID_cmp(&adapter->curbssparams.ssid,
-				&adapter->scantable[i].ssid)
-		    && adapter->adhoccreate) {
-			iwe.u.bitrate.value = 22 * 500000;
-		}
-		iwe.len = IW_EV_PARAM_LEN;
-		current_ev =
-		    iwe_stream_add_value(current_ev, current_val, end_buf, &iwe,
-					 iwe.len);
-
-		/* Add new value to event */
-		current_val = current_ev + IW_EV_LCP_LEN;
-
-		if (adapter->scantable[i].rsn_ie[0] == WPA2_IE) {
-			memset(&iwe, 0, sizeof(iwe));
-			memset(buf, 0, sizeof(buf));
-			memcpy(buf, adapter->scantable[i].rsn_ie,
-					adapter->scantable[i].rsn_ie_len);
-			iwe.cmd = IWEVGENIE;
-			iwe.u.data.length = adapter->scantable[i].rsn_ie_len;
-			iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
-			current_ev = iwe_stream_add_point(current_ev, end_buf,
-					&iwe, buf);
-		}
-		if (adapter->scantable[i].wpa_ie[0] == WPA_IE) {
-			memset(&iwe, 0, sizeof(iwe));
-			memset(buf, 0, sizeof(buf));
-			memcpy(buf, adapter->scantable[i].wpa_ie,
-					adapter->scantable[i].wpa_ie_len);
-			iwe.cmd = IWEVGENIE;
-			iwe.u.data.length = adapter->scantable[i].wpa_ie_len;
-			iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
-			current_ev = iwe_stream_add_point(current_ev, end_buf,
-					&iwe, buf);
-		}
-
-
-		if (adapter->scantable[i].extra_ie != 0) {
-			memset(&iwe, 0, sizeof(iwe));
-			memset(buf, 0, sizeof(buf));
-			ptr = buf;
-			ptr += sprintf(ptr, "extra_ie");
-			iwe.u.data.length = strlen(buf);
-
-			lbs_pr_debug(1, "iwe.u.data.length %d\n",
-			       iwe.u.data.length);
-			lbs_pr_debug(1, "BUF: %s \n", buf);
-
-			iwe.cmd = IWEVCUSTOM;
-			iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
-			current_ev =
-			    iwe_stream_add_point(current_ev, end_buf, &iwe,
-						 buf);
-		}
-
-		current_val = current_ev + IW_EV_LCP_LEN;
-
-		/*
-		 * Check if we added any event
-		 */
-		if ((current_val - current_ev) > IW_EV_LCP_LEN)
-			current_ev = current_val;
+		ev = next_ev;
 	}
+	mutex_unlock(&adapter->lock);
 
-	dwrq->length = (current_ev - extra);
+	dwrq->length = (ev - extra);
 	dwrq->flags = 0;
 
-	LEAVE();
-	return 0;
+	lbs_deb_leave(LBS_DEB_ASSOC);
+	return err;
 }
 
 /**
@@ -1796,13 +1725,13 @@
 	struct cmd_ds_802_11_scan *pscan = &cmd->params.scan;
 	struct wlan_scan_cmd_config *pscancfg;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
 
 	pscancfg = pdata_buf;
 
 	/* Set fixed field variables in scan command */
 	pscan->bsstype = pscancfg->bsstype;
-	memcpy(pscan->BSSID, pscancfg->specificBSSID, sizeof(pscan->BSSID));
+	memcpy(pscan->BSSID, pscancfg->bssid, sizeof(pscan->BSSID));
 	memcpy(pscan->tlvbuffer, pscancfg->tlvbuffer, pscancfg->tlvbufferlen);
 
 	cmd->command = cpu_to_le16(cmd_802_11_scan);
@@ -1812,12 +1741,26 @@
 				     + sizeof(pscan->BSSID)
 				     + pscancfg->tlvbufferlen + S_DS_GEN);
 
-	lbs_pr_debug(1, "SCAN_CMD: command=%x, size=%x, seqnum=%x\n",
-	       cmd->command, cmd->size, cmd->seqnum);
-	LEAVE();
+	lbs_deb_scan("SCAN_CMD: command=%x, size=%x, seqnum=%x\n",
+		     le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
+		     le16_to_cpu(cmd->seqnum));
+
+	lbs_deb_leave(LBS_DEB_ASSOC);
 	return 0;
 }
 
+static inline int is_same_network(struct bss_descriptor *src,
+				  struct bss_descriptor *dst)
+{
+	/* A network is only a duplicate if the channel, BSSID, and ESSID
+	 * all match.  We treat all <hidden> with the same BSSID and channel
+	 * as one network */
+	return ((src->ssid_len == dst->ssid_len) &&
+		(src->channel == dst->channel) &&
+		!compare_ether_addr(src->bssid, dst->bssid) &&
+		!memcmp(src->ssid, dst->ssid, src->ssid_len));
+}
+
 /**
  *  @brief This function handles the command response of scan
  *
@@ -1846,38 +1789,45 @@
 {
 	wlan_adapter *adapter = priv->adapter;
 	struct cmd_ds_802_11_scan_rsp *pscan;
-	struct bss_descriptor newbssentry;
 	struct mrvlietypes_data *ptlv;
 	struct mrvlietypes_tsftimestamp *ptsftlv;
+	struct bss_descriptor * iter_bss;
+	struct bss_descriptor * safe;
 	u8 *pbssinfo;
 	u16 scanrespsize;
 	int bytesleft;
-	int numintable;
-	int bssIdx;
 	int idx;
 	int tlvbufsize;
-	u64 tsfval;
+	int ret;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_ASSOC);
+
+	/* Prune old entries from scan table */
+	list_for_each_entry_safe (iter_bss, safe, &adapter->network_list, list) {
+		unsigned long stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
+		if (time_before(jiffies, stale_time))
+			continue;
+		list_move_tail (&iter_bss->list, &adapter->network_free_list);
+		clear_bss_descriptor(iter_bss);
+	}
 
 	pscan = &resp->params.scanresp;
 
-	if (pscan->nr_sets > MRVDRV_MAX_BSSID_LIST) {
-        lbs_pr_debug(1,
-		       "SCAN_RESP: Invalid number of AP returned (%d)!!\n",
-		       pscan->nr_sets);
-		LEAVE();
-		return -1;
+	if (pscan->nr_sets > MAX_NETWORK_COUNT) {
+		lbs_deb_scan(
+		       "SCAN_RESP: too many scan results (%d, max %d)!!\n",
+		       pscan->nr_sets, MAX_NETWORK_COUNT);
+		ret = -1;
+		goto done;
 	}
 
 	bytesleft = le16_to_cpu(pscan->bssdescriptsize);
-	lbs_pr_debug(1, "SCAN_RESP: bssdescriptsize %d\n", bytesleft);
+	lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft);
 
 	scanrespsize = le16_to_cpu(resp->size);
-	lbs_pr_debug(1, "SCAN_RESP: returned %d AP before parsing\n",
+	lbs_deb_scan("SCAN_RESP: returned %d AP before parsing\n",
 	       pscan->nr_sets);
 
-	numintable = adapter->numinscantable;
 	pbssinfo = pscan->bssdesc_and_tlvbuffer;
 
 	/* The size of the TLV buffer is equal to the entire command response
@@ -1901,105 +1851,68 @@
 	 *    or as an addition at the end of the table
 	 */
 	for (idx = 0; idx < pscan->nr_sets && bytesleft; idx++) {
-		/* Zero out the newbssentry we are about to store info in */
-		memset(&newbssentry, 0x00, sizeof(newbssentry));
+		struct bss_descriptor new;
+		struct bss_descriptor * found = NULL;
+		struct bss_descriptor * oldest = NULL;
 
 		/* Process the data fields and IEs returned for this BSS */
-		if ((InterpretBSSDescriptionWithIE(&newbssentry,
-						   &pbssinfo,
-						   &bytesleft) ==
-		     0)
-		    && CHECK_SSID_IS_VALID(&newbssentry.ssid)) {
-
-            lbs_pr_debug(1,
-			       "SCAN_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
-			       newbssentry.macaddress[0],
-			       newbssentry.macaddress[1],
-			       newbssentry.macaddress[2],
-			       newbssentry.macaddress[3],
-			       newbssentry.macaddress[4],
-			       newbssentry.macaddress[5]);
-
-			/*
-			 * Search the scan table for the same bssid
-			 */
-			for (bssIdx = 0; bssIdx < numintable; bssIdx++) {
-				if (memcmp(newbssentry.macaddress,
-					   adapter->scantable[bssIdx].
-					   macaddress,
-					   sizeof(newbssentry.macaddress)) ==
-				    0) {
-					/*
-					 * If the SSID matches as well, it is a duplicate of
-					 *   this entry.  Keep the bssIdx set to this
-					 *   entry so we replace the old contents in the table
-					 */
-					if ((newbssentry.ssid.ssidlength ==
-					     adapter->scantable[bssIdx].ssid.
-					     ssidlength)
-					    &&
-					    (memcmp
-					     (newbssentry.ssid.ssid,
-					      adapter->scantable[bssIdx].ssid.
-					      ssid,
-					      newbssentry.ssid.ssidlength) ==
-					     0)) {
-                        lbs_pr_debug(1,
-						       "SCAN_RESP: Duplicate of index: %d\n",
-						       bssIdx);
-						break;
-					}
-				}
-			}
-			/*
-			 * If the bssIdx is equal to the number of entries in the table,
-			 *   the new entry was not a duplicate; append it to the scan
-			 *   table
-			 */
-			if (bssIdx == numintable) {
-				/* Range check the bssIdx, keep it limited to the last entry */
-				if (bssIdx == MRVDRV_MAX_BSSID_LIST) {
-					bssIdx--;
-				} else {
-					numintable++;
-				}
-			}
-
-			/*
-			 * If the TSF TLV was appended to the scan results, save the
-			 *   this entries TSF value in the networktsf field.  The
-			 *   networktsf is the firmware's TSF value at the time the
-			 *   beacon or probe response was received.
-			 */
-			if (ptsftlv) {
-				memcpy(&tsfval, &ptsftlv->tsftable[idx],
-				       sizeof(tsfval));
-				tsfval = le64_to_cpu(tsfval);
-
-				memcpy(&newbssentry.networktsf,
-				       &tsfval, sizeof(newbssentry.networktsf));
-			}
-
-			/* Copy the locally created newbssentry to the scan table */
-			memcpy(&adapter->scantable[bssIdx],
-			       &newbssentry,
-			       sizeof(adapter->scantable[bssIdx]));
-
-		} else {
-
-			/* error parsing/interpreting the scan response, skipped */
-			lbs_pr_debug(1, "SCAN_RESP: "
-			       "InterpretBSSDescriptionWithIE returned ERROR\n");
+		memset(&new, 0, sizeof (struct bss_descriptor));
+		if (libertas_process_bss(&new, &pbssinfo, &bytesleft) != 0) {
+			/* error parsing the scan response, skipped */
+			lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n");
+			continue;
 		}
+
+		/* Try to find this bss in the scan table */
+		list_for_each_entry (iter_bss, &adapter->network_list, list) {
+			if (is_same_network(iter_bss, &new)) {
+				found = iter_bss;
+				break;
+			}
+
+			if ((oldest == NULL) ||
+			    (iter_bss->last_scanned < oldest->last_scanned))
+				oldest = iter_bss;
+		}
+
+		if (found) {
+			/* found, clear it */
+			clear_bss_descriptor(found);
+		} else if (!list_empty(&adapter->network_free_list)) {
+			/* Pull one from the free list */
+			found = list_entry(adapter->network_free_list.next,
+					   struct bss_descriptor, list);
+			list_move_tail(&found->list, &adapter->network_list);
+		} else if (oldest) {
+			/* If there are no more slots, expire the oldest */
+			found = oldest;
+			clear_bss_descriptor(found);
+			list_move_tail(&found->list, &adapter->network_list);
+		} else {
+			continue;
+		}
+
+		lbs_deb_scan("SCAN_RESP: BSSID = " MAC_FMT "\n",
+		       new.bssid[0], new.bssid[1], new.bssid[2],
+		       new.bssid[3], new.bssid[4], new.bssid[5]);
+
+		/*
+		 * If the TSF TLV was appended to the scan results, save the
+		 *   this entries TSF value in the networktsf field.  The
+		 *   networktsf is the firmware's TSF value at the time the
+		 *   beacon or probe response was received.
+		 */
+		if (ptsftlv) {
+			new.networktsf = le64_to_cpup(&ptsftlv->tsftable[idx]);
+		}
+
+		/* Copy the locally created newbssentry to the scan table */
+		memcpy(found, &new, offsetof(struct bss_descriptor, list));
 	}
 
-	lbs_pr_debug(1, "SCAN_RESP: Scanned %2d APs, %d valid, %d total\n",
-	       pscan->nr_sets, numintable - adapter->numinscantable,
-	       numintable);
+	ret = 0;
 
-	/* Update the total number of BSSIDs in the scan table */
-	adapter->numinscantable = numintable;
-
-	LEAVE();
-	return 0;
+done:
+	lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
+	return ret;
 }
diff --git a/drivers/net/wireless/libertas/scan.h b/drivers/net/wireless/libertas/scan.h
index 405f4f0..bd019e5 100644
--- a/drivers/net/wireless/libertas/scan.h
+++ b/drivers/net/wireless/libertas/scan.h
@@ -51,7 +51,7 @@
     /**
      *  @brief Specific BSSID used to filter scan results in the firmware
      */
-	u8 specificBSSID[ETH_ALEN];
+	u8 bssid[ETH_ALEN];
 
     /**
      *  @brief length of TLVs sent in command starting at tlvBuffer
@@ -91,15 +91,6 @@
  *  @sa libertas_set_user_scan_ioctl
  */
 struct wlan_ioctl_user_scan_cfg {
-
-    /**
-     *  @brief Flag set to keep the previous scan table intact
-     *
-     *  If set, the scan results will accumulate, replacing any previous
-     *   matched entries for a BSS with the new scan data
-     */
-	u8 keeppreviousscan;	//!< Do not erase the existing scan results
-
     /**
      *  @brief BSS type to be sent in the firmware command
      *
@@ -117,15 +108,22 @@
      */
 	u8 numprobes;
 
-    /**
-     *  @brief BSSID filter sent in the firmware command to limit the results
-     */
-	u8 specificBSSID[ETH_ALEN];
+	/**
+	 *  @brief BSSID filter sent in the firmware command to limit the results
+	 */
+	u8 bssid[ETH_ALEN];
 
-    /**
-     *  @brief SSID filter sent in the firmware command to limit the results
-     */
-	char specificSSID[IW_ESSID_MAX_SIZE + 1];
+	/* Clear existing scan results matching this BSSID */
+	u8 clear_bssid;
+
+	/**
+	 *  @brief SSID filter sent in the firmware command to limit the results
+	 */
+	char ssid[IW_ESSID_MAX_SIZE];
+	u8 ssid_len;
+
+	/* Clear existing scan results matching this SSID */
+	u8 clear_ssid;
 
     /**
      *  @brief Variable number (fixed maximum) of channels to scan up
@@ -137,9 +135,10 @@
  *  @brief Structure used to store information for each beacon/probe response
  */
 struct bss_descriptor {
-	u8 macaddress[ETH_ALEN];
+	u8 bssid[ETH_ALEN];
 
-	struct WLAN_802_11_SSID ssid;
+	u8 ssid[IW_ESSID_MAX_SIZE + 1];
+	u8 ssid_len;
 
 	/* WEP encryption requirement */
 	u32 privacy;
@@ -156,15 +155,15 @@
 	u8 mode;
 	u8 libertas_supported_rates[WLAN_SUPPORTED_RATES];
 
-	int extra_ie;
+	__le64 timestamp;	//!< TSF value included in the beacon/probe response
+	unsigned long last_scanned;
 
-	u8 timestamp[8];	//!< TSF value included in the beacon/probe response
 	union ieeetypes_phyparamset phyparamset;
 	union IEEEtypes_ssparamset ssparamset;
 	struct ieeetypes_capinfo cap;
 	u8 datarates[WLAN_SUPPORTED_RATES];
 
-	__le64 networktsf;		//!< TSF timestamp from the current firmware TSF
+	u64 networktsf;		//!< TSF timestamp from the current firmware TSF
 
 	struct ieeetypes_countryinfofullset countryinfo;
 
@@ -172,24 +171,29 @@
 	size_t wpa_ie_len;
 	u8 rsn_ie[MAX_WPA_IE_LEN];
 	size_t rsn_ie_len;
+
+	struct list_head list;
 };
 
-extern int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1,
-		   struct WLAN_802_11_SSID *ssid2);
-extern int libertas_find_SSID_in_list(wlan_adapter * adapter, struct WLAN_802_11_SSID *ssid,
-			  u8 * bssid, u8 mode);
-int libertas_find_best_SSID_in_list(wlan_adapter * adapter, u8 mode);
-extern int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, u8 mode);
+extern int libertas_ssid_cmp(u8 *ssid1, u8 ssid1_len, u8 *ssid2, u8 ssid2_len);
 
-int libertas_find_best_network_SSID(wlan_private * priv,
-			struct WLAN_802_11_SSID *pSSID,
-			u8 preferred_mode, u8 *out_mode);
+struct bss_descriptor * libertas_find_ssid_in_list(wlan_adapter * adapter,
+			u8 *ssid, u8 ssid_len, u8 * bssid, u8 mode,
+			int channel);
 
-extern int libertas_send_specific_SSID_scan(wlan_private * priv,
-				struct WLAN_802_11_SSID *prequestedssid,
-				u8 keeppreviousscan);
-extern int libertas_send_specific_BSSID_scan(wlan_private * priv,
-				 u8 * bssid, u8 keeppreviousscan);
+struct bss_descriptor * libertas_find_best_ssid_in_list(wlan_adapter * adapter,
+			u8 mode);
+
+extern struct bss_descriptor * libertas_find_bssid_in_list(wlan_adapter * adapter,
+			u8 * bssid, u8 mode);
+
+int libertas_find_best_network_ssid(wlan_private * priv, u8 *out_ssid,
+			u8 *out_ssid_len, u8 preferred_mode, u8 *out_mode);
+
+extern int libertas_send_specific_ssid_scan(wlan_private * priv, u8 *ssid,
+				u8 ssid_len, u8 clear_ssid);
+extern int libertas_send_specific_bssid_scan(wlan_private * priv,
+				 u8 * bssid, u8 clear_bssid);
 
 extern int libertas_cmd_80211_scan(wlan_private * priv,
 				struct cmd_ds_command *cmd,
@@ -199,7 +203,8 @@
 				struct cmd_ds_command *resp);
 
 int wlan_scan_networks(wlan_private * priv,
-                const struct wlan_ioctl_user_scan_cfg * puserscanin);
+                const struct wlan_ioctl_user_scan_cfg * puserscanin,
+                int full_scan);
 
 struct ifreq;
 
diff --git a/drivers/net/wireless/libertas/thread.h b/drivers/net/wireless/libertas/thread.h
index 207b8a6..b1f34d9 100644
--- a/drivers/net/wireless/libertas/thread.h
+++ b/drivers/net/wireless/libertas/thread.h
@@ -21,11 +21,11 @@
 
 static inline void wlan_deactivate_thread(struct wlan_thread * thr)
 {
-	ENTER();
+	lbs_deb_enter(LBS_DEB_THREAD);
 
 	thr->pid = 0;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_THREAD);
 }
 
 static inline void wlan_create_thread(int (*wlanfunc) (void *),
@@ -36,7 +36,7 @@
 
 static inline int wlan_terminate_thread(struct wlan_thread * thr)
 {
-	ENTER();
+	lbs_deb_enter(LBS_DEB_THREAD);
 
 	/* Check if the thread is active or not */
 	if (!thr->pid) {
@@ -45,7 +45,7 @@
 	}
 	kthread_stop(thr->task);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_THREAD);
 	return 0;
 }
 
diff --git a/drivers/net/wireless/libertas/tx.c b/drivers/net/wireless/libertas/tx.c
index d4b1347..17c4376 100644
--- a/drivers/net/wireless/libertas/tx.c
+++ b/drivers/net/wireless/libertas/tx.c
@@ -5,7 +5,6 @@
 
 #include "hostcmd.h"
 #include "radiotap.h"
-#include "sbi.h"
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
@@ -68,7 +67,7 @@
 	u32 new_rate;
 	u8 *ptr = priv->adapter->tmptxbuf;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_TX);
 
 	if (priv->adapter->surpriseremoved)
 		return -1;
@@ -78,7 +77,7 @@
 			 min_t(unsigned int, skb->len, 100));
 
 	if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
-		lbs_pr_debug(1, "Tx error: Bad skb length %d : %zd\n",
+		lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
 		       skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
 		ret = -1;
 		goto done;
@@ -86,13 +85,13 @@
 
 	memset(plocaltxpd, 0, sizeof(struct txpd));
 
-	plocaltxpd->tx_packet_length = skb->len;
+	plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
 
 	/* offset of actual data */
-	plocaltxpd->tx_packet_location = sizeof(struct txpd);
+	plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
 
 	/* TxCtrl set by user or default */
-	plocaltxpd->tx_control = adapter->pkttxctrl;
+	plocaltxpd->tx_control = cpu_to_le32(adapter->pkttxctrl);
 
 	p802x_hdr = skb->data;
 	if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
@@ -103,15 +102,16 @@
 		/* set txpd fields from the radiotap header */
 		new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
 		if (new_rate != 0) {
-			/* erase tx_control[4:0] */
-			plocaltxpd->tx_control &= ~0x1f;
-			/* write new tx_control[4:0] */
-			plocaltxpd->tx_control |= new_rate;
+			/* use new tx_control[4:0] */
+			new_rate |= (adapter->pkttxctrl & ~0x1f);
+			plocaltxpd->tx_control = cpu_to_le32(new_rate);
 		}
 
 		/* skip the radiotap header */
 		p802x_hdr += sizeof(struct tx_radiotap_hdr);
-		plocaltxpd->tx_packet_length -= sizeof(struct tx_radiotap_hdr);
+		plocaltxpd->tx_packet_length =
+			cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
+				    - sizeof(struct tx_radiotap_hdr));
 
 	}
 	/* copy destination address from 802.3 or 802.11 header */
@@ -123,28 +123,28 @@
 	lbs_dbg_hex("txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
 
 	if (IS_MESH_FRAME(skb)) {
-		plocaltxpd->tx_control |= TxPD_MESH_FRAME;
+		plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
 	}
 
 	memcpy(ptr, plocaltxpd, sizeof(struct txpd));
 
 	ptr += sizeof(struct txpd);
 
-	lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, plocaltxpd->tx_packet_length);
-	memcpy(ptr, p802x_hdr, plocaltxpd->tx_packet_length);
-	ret = libertas_sbi_host_to_card(priv, MVMS_DAT,
-			       priv->adapter->tmptxbuf,
-			       plocaltxpd->tx_packet_length +
-			       sizeof(struct txpd));
+	lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
+	memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
+	ret = priv->hw_host_to_card(priv, MVMS_DAT,
+				    priv->adapter->tmptxbuf,
+				    le16_to_cpu(plocaltxpd->tx_packet_length) +
+				    sizeof(struct txpd));
 
 	if (ret) {
-		lbs_pr_debug(1, "Tx error: libertas_sbi_host_to_card failed: 0x%X\n", ret);
+		lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
 		goto done;
 	}
 
-	lbs_pr_debug(1, "SendSinglePacket succeeds\n");
+	lbs_deb_tx("SendSinglePacket succeeds\n");
 
-      done:
+done:
 	if (!ret) {
 		priv->stats.tx_packets++;
 		priv->stats.tx_bytes += skb->len;
@@ -158,7 +158,8 @@
 		   received from FW */
 		skb_orphan(skb);
 		/* stop processing outgoing pkts */
-		netif_stop_queue(priv->wlan_dev.netdev);
+		netif_stop_queue(priv->dev);
+		netif_stop_queue(priv->mesh_dev);
 		/* freeze any packets already in our queues */
 		priv->adapter->TxLockFlag = 1;
 	} else {
@@ -166,7 +167,7 @@
 		priv->adapter->currenttxskb = NULL;
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
 	return ret;
 }
 
@@ -195,10 +196,13 @@
 
 	WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
 	adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
-	if (adapter->tx_queue_idx == NR_TX_QUEUE)
-		netif_stop_queue(priv->wlan_dev.netdev);
-	else
-		netif_start_queue(priv->wlan_dev.netdev);
+	if (adapter->tx_queue_idx == NR_TX_QUEUE) {
+		netif_stop_queue(priv->dev);
+		netif_stop_queue(priv->mesh_dev);
+	} else {
+		netif_start_queue(priv->dev);
+		netif_start_queue(priv->mesh_dev);
+	}
 
 	spin_unlock(&adapter->txqueue_lock);
 }
@@ -214,13 +218,12 @@
 {
 	int ret = -1;
 
-	ENTER();
-
+	lbs_deb_enter(LBS_DEB_TX);
 	lbs_dbg_hex("TX Data", skb->data, min_t(unsigned int, skb->len, 100));
 
-	if (priv->wlan_dev.dnld_sent) {
+	if (priv->dnld_sent) {
 		lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
-		       priv->wlan_dev.dnld_sent);
+		       priv->dnld_sent);
 		goto done;
 	}
 
@@ -234,7 +237,7 @@
 
 	ret = SendSinglePacket(priv, skb);
 done:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
 	return ret;
 }
 
@@ -280,6 +283,9 @@
 	libertas_upload_rx_packet(priv, adapter->currenttxskb);
 	adapter->currenttxskb = NULL;
 	priv->adapter->TxLockFlag = 0;
-	if (priv->adapter->connect_status == libertas_connected)
-		netif_wake_queue(priv->wlan_dev.netdev);
+	if (priv->adapter->connect_status == libertas_connected) {
+		netif_wake_queue(priv->dev);
+		netif_wake_queue(priv->mesh_dev);
+	}
 }
+EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);
diff --git a/drivers/net/wireless/libertas/types.h b/drivers/net/wireless/libertas/types.h
index 09d62f8..028e2f3 100644
--- a/drivers/net/wireless/libertas/types.h
+++ b/drivers/net/wireless/libertas/types.h
@@ -5,6 +5,7 @@
 #define _WLAN_TYPES_
 
 #include <linux/if_ether.h>
+#include <asm/byteorder.h>
 
 /** IEEE type definitions  */
 enum ieeetypes_elementid {
@@ -29,9 +30,30 @@
 	EXTRA_IE = 133,
 } __attribute__ ((packed));
 
+#ifdef __BIG_ENDIAN
 #define CAPINFO_MASK	(~(0xda00))
+#else
+#define CAPINFO_MASK	(~(0x00da))
+#endif
 
 struct ieeetypes_capinfo {
+#ifdef __BIG_ENDIAN_BITFIELD
+	u8 chanagility:1;
+	u8 pbcc:1;
+	u8 shortpreamble:1;
+	u8 privacy:1;
+	u8 cfpollrqst:1;
+	u8 cfpollable:1;
+	u8 ibss:1;
+	u8 ess:1;
+	u8 rsrvd1:2;
+	u8 dsssofdm:1;
+	u8 rsvrd2:1;
+	u8 apsd:1;
+	u8 shortslottime:1;
+	u8 rsrvd3:1;
+	u8 spectrummgmt:1;
+#else
 	u8 ess:1;
 	u8 ibss:1;
 	u8 cfpollable:1;
@@ -47,6 +69,7 @@
 	u8 rsvrd2:1;
 	u8 dsssofdm:1;
 	u8 rsrvd1:2;
+#endif
 } __attribute__ ((packed));
 
 struct ieeetypes_cfparamset {
@@ -54,15 +77,15 @@
 	u8 len;
 	u8 cfpcnt;
 	u8 cfpperiod;
-	u16 cfpmaxduration;
-	u16 cfpdurationremaining;
+	__le16 cfpmaxduration;
+	__le16 cfpdurationremaining;
 } __attribute__ ((packed));
 
 
 struct ieeetypes_ibssparamset {
 	u8 elementid;
 	u8 len;
-	u16 atimwindow;
+	__le16 atimwindow;
 } __attribute__ ((packed));
 
 union IEEEtypes_ssparamset {
@@ -73,7 +96,7 @@
 struct ieeetypes_fhparamset {
 	u8 elementid;
 	u8 len;
-	u16 dwelltime;
+	__le16 dwelltime;
 	u8 hopset;
 	u8 hoppattern;
 	u8 hopindex;
@@ -92,8 +115,8 @@
 
 struct ieeetypes_assocrsp {
 	struct ieeetypes_capinfo capability;
-	u16 statuscode;
-	u16 aid;
+	__le16 statuscode;
+	__le16 aid;
 	u8 iebuffer[1];
 } __attribute__ ((packed));
 
@@ -138,8 +161,8 @@
 
 /** TLV related data structures*/
 struct mrvlietypesheader {
-	u16 type;
-	u16 len;
+	__le16 type;
+	__le16 len;
 } __attribute__ ((packed));
 
 struct mrvlietypes_data {
@@ -164,17 +187,23 @@
 } __attribute__ ((packed));
 
 struct chanscanmode {
+#ifdef __BIG_ENDIAN_BITFIELD
+	u8 reserved_2_7:6;
+	u8 disablechanfilt:1;
+	u8 passivescan:1;
+#else
 	u8 passivescan:1;
 	u8 disablechanfilt:1;
 	u8 reserved_2_7:6;
+#endif
 } __attribute__ ((packed));
 
 struct chanscanparamset {
 	u8 radiotype;
 	u8 channumber;
 	struct chanscanmode chanscanmode;
-	u16 minscantime;
-	u16 maxscantime;
+	__le16 minscantime;
+	__le16 maxscantime;
 } __attribute__ ((packed));
 
 struct mrvlietypes_chanlistparamset {
@@ -185,12 +214,12 @@
 struct cfparamset {
 	u8 cfpcnt;
 	u8 cfpperiod;
-	u16 cfpmaxduration;
-	u16 cfpdurationremaining;
+	__le16 cfpmaxduration;
+	__le16 cfpdurationremaining;
 } __attribute__ ((packed));
 
 struct ibssparamset {
-	u16 atimwindow;
+	__le16 atimwindow;
 } __attribute__ ((packed));
 
 struct mrvlietypes_ssparamset {
@@ -202,7 +231,7 @@
 } __attribute__ ((packed));
 
 struct fhparamset {
-	u16 dwelltime;
+	__le16 dwelltime;
 	u8 hopset;
 	u8 hoppattern;
 	u8 hopindex;
@@ -263,17 +292,17 @@
 
 struct mrvlietypes_numprobes {
 	struct mrvlietypesheader header;
-	u16 numprobes;
+	__le16 numprobes;
 } __attribute__ ((packed));
 
 struct mrvlietypes_bcastprobe {
 	struct mrvlietypesheader header;
-	u16 bcastprobe;
+	__le16 bcastprobe;
 } __attribute__ ((packed));
 
 struct mrvlietypes_numssidprobe {
 	struct mrvlietypesheader header;
-	u16 numssidprobe;
+	__le16 numssidprobe;
 } __attribute__ ((packed));
 
 struct led_pin {
diff --git a/drivers/net/wireless/libertas/wext.c b/drivers/net/wireless/libertas/wext.c
index 69f52b6..8939251 100644
--- a/drivers/net/wireless/libertas/wext.c
+++ b/drivers/net/wireless/libertas/wext.c
@@ -22,6 +22,14 @@
 
 
 /**
+ * the rates supported by the card
+ */
+static u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
+    { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
+      0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
+};
+
+/**
  *  @brief Convert mw value to dbm value
  *
  *  @param mw	   the value of mw
@@ -102,8 +110,8 @@
 	}
 
 	if (!cfp && channel)
-		lbs_pr_debug(1, "libertas_find_cfp_by_band_and_channel(): cannot find "
-		       "cfp by band %d & channel %d\n", band, channel);
+		lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find "
+		       "cfp by band %d / channel %d\n", band, channel);
 
 	return cfp;
 }
@@ -143,113 +151,12 @@
 	}
 
 	if (!cfp && freq)
-		lbs_pr_debug(1, "find_cfp_by_band_and_freql(): cannot find cfp by "
-		       "band %d & freq %d\n", band, freq);
+		lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
+		       "band %d / freq %d\n", band, freq);
 
 	return cfp;
 }
 
-static int updatecurrentchannel(wlan_private * priv)
-{
-	int ret;
-
-	/*
-	 ** the channel in f/w could be out of sync, get the current channel
-	 */
-	ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
-				    cmd_opt_802_11_rf_channel_get,
-				    cmd_option_waitforrsp, 0, NULL);
-
-	lbs_pr_debug(1, "Current channel = %d\n",
-	       priv->adapter->curbssparams.channel);
-
-	return ret;
-}
-
-static int setcurrentchannel(wlan_private * priv, int channel)
-{
-	lbs_pr_debug(1, "Set channel = %d\n", channel);
-
-	/*
-	 **  Current channel is not set to adhocchannel requested, set channel
-	 */
-	return (libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
-				      cmd_opt_802_11_rf_channel_set,
-				      cmd_option_waitforrsp, 0, &channel));
-}
-
-static int changeadhocchannel(wlan_private * priv, int channel)
-{
-	int ret = 0;
-	wlan_adapter *adapter = priv->adapter;
-
-	adapter->adhocchannel = channel;
-
-	updatecurrentchannel(priv);
-
-	if (adapter->curbssparams.channel == adapter->adhocchannel) {
-		/* adhocchannel is set to the current channel already */
-		LEAVE();
-		return 0;
-	}
-
-	lbs_pr_debug(1, "Updating channel from %d to %d\n",
-	       adapter->curbssparams.channel, adapter->adhocchannel);
-
-	setcurrentchannel(priv, adapter->adhocchannel);
-
-	updatecurrentchannel(priv);
-
-	if (adapter->curbssparams.channel != adapter->adhocchannel) {
-		lbs_pr_debug(1, "failed to updated channel to %d, channel = %d\n",
-		       adapter->adhocchannel, adapter->curbssparams.channel);
-		LEAVE();
-		return -1;
-	}
-
-	if (adapter->connect_status == libertas_connected) {
-		int i;
-		struct WLAN_802_11_SSID curadhocssid;
-
-		lbs_pr_debug(1, "channel Changed while in an IBSS\n");
-
-		/* Copy the current ssid */
-		memcpy(&curadhocssid, &adapter->curbssparams.ssid,
-		       sizeof(struct WLAN_802_11_SSID));
-
-		/* Exit Adhoc mode */
-		lbs_pr_debug(1, "In changeadhocchannel(): Sending Adhoc Stop\n");
-		ret = libertas_stop_adhoc_network(priv);
-
-		if (ret) {
-			LEAVE();
-			return ret;
-		}
-		/* Scan for the network, do not save previous results.  Stale
-		 *   scan data will cause us to join a non-existant adhoc network
-		 */
-		libertas_send_specific_SSID_scan(priv, &curadhocssid, 0);
-
-		// find out the BSSID that matches the current SSID
-		i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
-				   IW_MODE_ADHOC);
-
-		if (i >= 0) {
-			lbs_pr_debug(1, "SSID found at %d in List,"
-			       "so join\n", i);
-			libertas_join_adhoc_network(priv, &adapter->scantable[i]);
-		} else {
-			// else send START command
-			lbs_pr_debug(1, "SSID not found in list, "
-			       "so creating adhoc with ssid = %s\n",
-			       curadhocssid.ssid);
-			libertas_start_adhoc_network(priv, &curadhocssid);
-		}		// end of else (START command)
-	}
-
-	LEAVE();
-	return 0;
-}
 
 /**
  *  @brief Set Radio On/OFF
@@ -263,10 +170,10 @@
 	int ret = 0;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (adapter->radioon != option) {
-		lbs_pr_debug(1, "Switching %s the Radio\n", option ? "On" : "Off");
+		lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
 		adapter->radioon = option;
 
 		ret = libertas_prepare_and_send_command(priv,
@@ -275,7 +182,7 @@
 					    cmd_option_waitforrsp, 0, NULL);
 	}
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -312,15 +219,15 @@
 {
 	int k = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (adapter->connect_status != libertas_connected) {
 		if (adapter->mode == IW_MODE_INFRA) {
-			lbs_pr_debug(1, "Infra\n");
+			lbs_deb_wext("infra\n");
 			k = copyrates(rates, k, libertas_supported_rates,
 				      sizeof(libertas_supported_rates));
 		} else {
-			lbs_pr_debug(1, "Adhoc G\n");
+			lbs_deb_wext("Adhoc G\n");
 			k = copyrates(rates, k, libertas_adhoc_rates_g,
 				      sizeof(libertas_adhoc_rates_g));
 		}
@@ -329,8 +236,7 @@
 			      adapter->curbssparams.numofrates);
 	}
 
-	LEAVE();
-
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", k);
 	return k;
 }
 
@@ -342,7 +248,7 @@
 	char mrvl[6] = { "MRVL-" };
 	int cnt;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	strcpy(cwrq, mrvl);
 
@@ -360,8 +266,7 @@
 	}
 	*cwrq = '\0';
 
-	LEAVE();
-
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -372,14 +277,14 @@
 	wlan_adapter *adapter = priv->adapter;
 	struct chan_freq_power *cfp;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
 					   adapter->curbssparams.channel);
 
 	if (!cfp) {
 		if (adapter->curbssparams.channel)
-			lbs_pr_debug(1, "Invalid channel=%d\n",
+			lbs_deb_wext("invalid channel %d\n",
 			       adapter->curbssparams.channel);
 		return -EINVAL;
 	}
@@ -387,9 +292,8 @@
 	fwrq->m = (long)cfp->freq * 100000;
 	fwrq->e = 1;
 
-	lbs_pr_debug(1, "freq=%u\n", fwrq->m);
-
-	LEAVE();
+	lbs_deb_wext("freq %u\n", fwrq->m);
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -399,7 +303,7 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (adapter->connect_status == libertas_connected) {
 		memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
@@ -408,7 +312,7 @@
 	}
 	awrq->sa_family = ARPHRD_ETHER;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -418,7 +322,7 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	/*
 	 * Check the size of the string
@@ -433,7 +337,7 @@
 	memcpy(adapter->nodename, extra, dwrq->length);
 	mutex_unlock(&adapter->lock);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -443,7 +347,7 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	/*
 	 * Get the Nick Name saved
@@ -464,19 +368,43 @@
 	 */
 	dwrq->length = strlen(extra) + 1;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
+static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
+			 struct iw_point *dwrq, char *extra)
+{
+	wlan_private *priv = dev->priv;
+	wlan_adapter *adapter = priv->adapter;
+
+	lbs_deb_enter(LBS_DEB_WEXT);
+
+	/* Use nickname to indicate that mesh is on */
+
+	if (adapter->connect_status == libertas_connected) {
+		strncpy(extra, "Mesh", 12);
+		extra[12] = '\0';
+		dwrq->length = strlen(extra) + 1;
+	}
+
+	else {
+		extra[0] = '\0';
+		dwrq->length = 1 ;
+	}
+
+	lbs_deb_leave(LBS_DEB_WEXT);
+	return 0;
+}
 static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
 			struct iw_param *vwrq, char *extra)
 {
 	int ret = 0;
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
-	int rthr = vwrq->value;
+	u32 rthr = vwrq->value;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (vwrq->disabled) {
 		adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
@@ -490,7 +418,7 @@
 				    cmd_act_set, cmd_option_waitforrsp,
 				    OID_802_11_RTS_THRESHOLD, &rthr);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -501,35 +429,34 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	adapter->rtsthsd = 0;
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
 				    cmd_act_get, cmd_option_waitforrsp,
 				    OID_802_11_RTS_THRESHOLD, NULL);
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
+	if (ret)
+		goto out;
 
 	vwrq->value = adapter->rtsthsd;
 	vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
 			  || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
 	vwrq->fixed = 1;
 
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
 			 struct iw_param *vwrq, char *extra)
 {
 	int ret = 0;
-	int fthr = vwrq->value;
+	u32 fthr = vwrq->value;
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (vwrq->disabled) {
 		adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
@@ -543,7 +470,8 @@
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
 				    cmd_act_set, cmd_option_waitforrsp,
 				    OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
-	LEAVE();
+
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -554,24 +482,23 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	adapter->fragthsd = 0;
 	ret = libertas_prepare_and_send_command(priv,
 				    cmd_802_11_snmp_mib,
 				    cmd_act_get, cmd_option_waitforrsp,
 				    OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
+	if (ret)
+		goto out;
 
 	vwrq->value = adapter->fragthsd;
 	vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
 			  || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
 	vwrq->fixed = 1;
 
-	LEAVE();
+out:
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -581,11 +508,23 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	*uwrq = adapter->mode;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
+	return 0;
+}
+
+static int mesh_wlan_get_mode(struct net_device *dev,
+		              struct iw_request_info *info, u32 * uwrq,
+			      char *extra)
+{
+	lbs_deb_enter(LBS_DEB_WEXT);
+
+	*uwrq = IW_MODE_REPEAT ;
+
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -597,19 +536,17 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	ret = libertas_prepare_and_send_command(priv,
 				    cmd_802_11_rf_tx_power,
 				    cmd_act_tx_power_opt_get,
 				    cmd_option_waitforrsp, 0, NULL);
 
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
+	if (ret)
+		goto out;
 
-	lbs_pr_debug(1, "TXPOWER GET %d dbm.\n", adapter->txpowerlevel);
+	lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
 	vwrq->value = adapter->txpowerlevel;
 	vwrq->fixed = 1;
 	if (adapter->radioon) {
@@ -619,8 +556,9 @@
 		vwrq->disabled = 1;
 	}
 
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
@@ -630,7 +568,7 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (vwrq->flags == IW_RETRY_LIMIT) {
 		/* The MAC has a 4-bit Total_Tx_Count register
@@ -648,16 +586,15 @@
 					    cmd_option_waitforrsp,
 					    OID_802_11_TX_RETRYCOUNT, NULL);
 
-		if (ret) {
-			LEAVE();
-			return ret;
-		}
+		if (ret)
+			goto out;
 	} else {
 		return -EOPNOTSUPP;
 	}
 
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
@@ -667,16 +604,16 @@
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
+
 	adapter->txretrycount = 0;
 	ret = libertas_prepare_and_send_command(priv,
 				    cmd_802_11_snmp_mib,
 				    cmd_act_get, cmd_option_waitforrsp,
 				    OID_802_11_TX_RETRYCOUNT, NULL);
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
+	if (ret)
+		goto out;
+
 	vwrq->disabled = 0;
 	if (!vwrq->flags) {
 		vwrq->flags = IW_RETRY_LIMIT;
@@ -684,8 +621,9 @@
 		vwrq->value = adapter->txretrycount - 1;
 	}
 
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 static inline void sort_channels(struct iw_freq *freq, int num)
@@ -739,7 +677,7 @@
 
 	u8 flag = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	dwrq->length = sizeof(struct iw_range);
 	memset(range, 0, sizeof(struct iw_range));
@@ -755,7 +693,7 @@
 		range->bitrate[i] = (rates[i] & 0x7f) * 500000;
 	}
 	range->num_bitrates = i;
-	lbs_pr_debug(1, "IW_MAX_BITRATES=%d num_bitrates=%d\n", IW_MAX_BITRATES,
+	lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
 	       range->num_bitrates);
 
 	range->num_frequency = 0;
@@ -768,18 +706,17 @@
 		    &adapter->parsed_region_chan;
 
 		if (parsed_region_chan == NULL) {
-			lbs_pr_debug(1, "11D:parsed_region_chan is NULL\n");
-			LEAVE();
-			return 0;
+			lbs_deb_wext("11d: parsed_region_chan is NULL\n");
+			goto out;
 		}
 		band = parsed_region_chan->band;
-		lbs_pr_debug(1, "band=%d NoOfChan=%d\n", band,
+		lbs_deb_wext("band %d, nr_char %d\n", band,
 		       parsed_region_chan->nr_chan);
 
 		for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
 		     && (i < parsed_region_chan->nr_chan); i++) {
 			chan_no = parsed_region_chan->chanpwr[i].chan;
-			lbs_pr_debug(1, "chan_no=%d\n", chan_no);
+			lbs_deb_wext("chan_no %d\n", chan_no);
 			range->freq[range->num_frequency].i = (long)chan_no;
 			range->freq[range->num_frequency].m =
 			    (long)libertas_chan_2_freq(chan_no, band) * 100000;
@@ -808,7 +745,7 @@
 		}
 	}
 
-	lbs_pr_debug(1, "IW_MAX_FREQUENCIES=%d num_frequency=%d\n",
+	lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
 	       IW_MAX_FREQUENCIES, range->num_frequency);
 
 	range->num_channels = range->num_frequency;
@@ -903,7 +840,8 @@
 		                  | IW_ENC_CAPA_CIPHER_CCMP;
 	}
 
-	LEAVE();
+out:
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -913,7 +851,7 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	/* PS is currently supported only in Infrastructure mode
 	 * Remove this check if it is to be supported in IBSS mode also
@@ -929,11 +867,11 @@
 	}
 
 	if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
-		lbs_pr_debug(1,
-		       "Setting power timeout command is not supported\n");
+		lbs_deb_wext(
+		       "setting power timeout is not supported\n");
 		return -EINVAL;
 	} else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
-		lbs_pr_debug(1, "Setting power period command is not supported\n");
+		lbs_deb_wext("setting power period not supported\n");
 		return -EINVAL;
 	}
 
@@ -947,7 +885,7 @@
 		libertas_ps_sleep(priv, cmd_option_waitforrsp);
 	}
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -958,19 +896,20 @@
 	wlan_adapter *adapter = priv->adapter;
 	int mode;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	mode = adapter->psmode;
 
 	if ((vwrq->disabled = (mode == wlan802_11powermodecam))
-	    || adapter->connect_status == libertas_disconnected) {
-		LEAVE();
-		return 0;
+	    || adapter->connect_status == libertas_disconnected)
+	{
+		goto out;
 	}
 
 	vwrq->value = 0;
 
-	LEAVE();
+out:
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -1063,6 +1002,16 @@
 	 IW_PRIV_TYPE_CHAR | 128,
 	 IW_PRIV_TYPE_CHAR | 128,
 	 "bt_list"},
+	{
+	 WLAN_SUBCMD_BT_SET_INVERT,
+	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
+	 IW_PRIV_TYPE_NONE,
+	 "bt_set_invert"},
+	{
+	 WLAN_SUBCMD_BT_GET_INVERT,
+	 IW_PRIV_TYPE_NONE,
+	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
+	 "bt_get_invert"},
 	/* FWT Management */
 	{
 	 WLAN_SUBCMD_FWT_ADD,
@@ -1125,7 +1074,7 @@
 	u8 rssi;
 	u32 tx_retries;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	priv->wstats.status = adapter->mode;
 
@@ -1145,8 +1094,8 @@
 		    CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
 	}
 
-	lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
-	lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
+	lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
+	lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
 
 	rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
 	if (rssi < 15)
@@ -1166,7 +1115,7 @@
 	/* Quality by TX errors */
 	priv->wstats.discard.retries = priv->stats.tx_errors;
 
-	tx_retries = adapter->logmsg.retry;
+	tx_retries = le16_to_cpu(adapter->logmsg.retry);
 
 	if (tx_retries > 75)
 		tx_qual = (90 - tx_retries) * POOR / 15;
@@ -1182,10 +1131,10 @@
 		    (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
 	quality = min(quality, tx_qual);
 
-	priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
-	priv->wstats.discard.fragment = adapter->logmsg.fcserror;
+	priv->wstats.discard.code = le16_to_cpu(adapter->logmsg.wepundecryptable);
+	priv->wstats.discard.fragment = le16_to_cpu(adapter->logmsg.rxfrag);
 	priv->wstats.discard.retries = tx_retries;
-	priv->wstats.discard.misc = adapter->logmsg.ackfailure;
+	priv->wstats.discard.misc = le16_to_cpu(adapter->logmsg.ackfailure);
 
 	/* Calculate quality */
 	priv->wstats.qual.qual = max(quality, (u32)100);
@@ -1209,7 +1158,7 @@
 		    IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
 	}
 
-	LEAVE ();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return &priv->wstats;
 
 
@@ -1218,81 +1167,59 @@
 static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
 		  struct iw_freq *fwrq, char *extra)
 {
-	int ret = 0;
+	int ret = -EINVAL;
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
-	int rc = -EINPROGRESS;	/* Call commit handler */
 	struct chan_freq_power *cfp;
+	struct assoc_request * assoc_req;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
-	/*
-	 * If setting by frequency, convert to a channel
-	 */
+	mutex_lock(&adapter->lock);
+	assoc_req = wlan_get_association_request(adapter);
+	if (!assoc_req) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	/* If setting by frequency, convert to a channel */
 	if (fwrq->e == 1) {
-
 		long f = fwrq->m / 100000;
-		int c = 0;
 
 		cfp = find_cfp_by_band_and_freq(adapter, 0, f);
 		if (!cfp) {
-			lbs_pr_debug(1, "Invalid freq=%ld\n", f);
-			return -EINVAL;
+			lbs_deb_wext("invalid freq %ld\n", f);
+			goto out;
 		}
 
-		c = (int)cfp->channel;
-
-		if (c < 0)
-			return -EINVAL;
-
 		fwrq->e = 0;
-		fwrq->m = c;
+		fwrq->m = (int) cfp->channel;
 	}
 
-	/*
-	 * Setting by channel number
-	 */
+	/* Setting by channel number */
 	if (fwrq->m > 1000 || fwrq->e > 0) {
-		rc = -EOPNOTSUPP;
-	} else {
-		int channel = fwrq->m;
-
-		cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel);
-		if (!cfp) {
-			rc = -EINVAL;
-		} else {
-			if (adapter->mode == IW_MODE_ADHOC) {
-				rc = changeadhocchannel(priv, channel);
-				/*  If station is WEP enabled, send the
-				 *  command to set WEP in firmware
-				 */
-				if (adapter->secinfo.wep_enabled) {
-					lbs_pr_debug(1, "set_freq: WEP enabled\n");
-					ret = libertas_prepare_and_send_command(priv,
-								    cmd_802_11_set_wep,
-								    cmd_act_add,
-								    cmd_option_waitforrsp,
-								    0,
-								    NULL);
-
-					if (ret) {
-						LEAVE();
-						return ret;
-					}
-
-					adapter->currentpacketfilter |=
-					    cmd_act_mac_wep_enable;
-
-					libertas_set_mac_packet_filter(priv);
-				}
-			} else {
-				rc = -EOPNOTSUPP;
-			}
-		}
+		goto out;
 	}
 
-	LEAVE();
-	return rc;
+	cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
+	if (!cfp) {
+		goto out;
+	}
+
+	assoc_req->channel = fwrq->m;
+	ret = 0;
+
+out:
+	if (ret == 0) {
+		set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
+		wlan_postpone_association_work(priv);
+	} else {
+		wlan_cancel_association_work(priv);
+	}
+	mutex_unlock(&adapter->lock);
+
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 /**
@@ -1338,9 +1265,9 @@
 	u8 rates[WLAN_SUPPORTED_RATES];
 	u8 *rate;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
-	lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
+	lbs_deb_wext("vwrq->value %d\n", vwrq->value);
 
 	if (vwrq->value == -1) {
 		action = cmd_act_set_tx_auto;	// Auto
@@ -1357,15 +1284,15 @@
 		get_active_data_rates(adapter, rates);
 		rate = rates;
 		while (*rate) {
-			lbs_pr_debug(1, "Rate=0x%X  Wanted=0x%X\n", *rate,
+			lbs_deb_wext("rate=0x%X, wanted data_rate 0x%X\n", *rate,
 			       data_rate);
 			if ((*rate & 0x7f) == (data_rate & 0x7f))
 				break;
 			rate++;
 		}
 		if (!*rate) {
-			lbs_pr_alert( "The fixed data rate 0x%X is out "
-			       "of range.\n", data_rate);
+			lbs_pr_alert("fixed data rate 0x%X out "
+			       "of range\n", data_rate);
 			return -EINVAL;
 		}
 
@@ -1377,7 +1304,7 @@
 	ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
 				    action, cmd_option_waitforrsp, 0, NULL);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -1387,7 +1314,7 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (adapter->is_datarate_auto) {
 		vwrq->fixed = 0;
@@ -1397,7 +1324,7 @@
 
 	vwrq->value = adapter->datarate * 500000;
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -1409,12 +1336,12 @@
 	wlan_adapter *adapter = priv->adapter;
 	struct assoc_request * assoc_req;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (   (*uwrq != IW_MODE_ADHOC)
 	    && (*uwrq != IW_MODE_INFRA)
 	    && (*uwrq != IW_MODE_AUTO)) {
-		lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq);
+		lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
 		ret = -EINVAL;
 		goto out;
 	}
@@ -1428,12 +1355,12 @@
 		assoc_req->mode = *uwrq;
 		set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
 		wlan_postpone_association_work(priv);
-		lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq);
+		lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
 	}
 	mutex_unlock(&adapter->lock);
 
 out:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -1455,9 +1382,9 @@
 	wlan_adapter *adapter = priv->adapter;
 	int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
-	lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
+	lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
 	       dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
 
 	dwrq->flags = 0;
@@ -1513,13 +1440,13 @@
 
 	dwrq->flags |= IW_ENCODE_NOKEY;
 
-	lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
+	lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
 	       extra[0], extra[1], extra[2],
 	       extra[3], extra[4], extra[5], dwrq->length);
 
-	lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
+	lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -1539,20 +1466,21 @@
 			    u16 index,
 			    int set_tx_key)
 {
+	int ret = 0;
 	struct WLAN_802_11_KEY *pkey;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	/* Paranoid validation of key index */
 	if (index > 3) {
-		LEAVE();
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out;
 	}
 
 	/* validate max key length */
 	if (key_length > KEY_LEN_WEP_104) {
-		LEAVE();
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out;
 	}
 
 	pkey = &assoc_req->wep_keys[index];
@@ -1570,17 +1498,18 @@
 	if (set_tx_key) {
 		/* Ensure the chosen key is valid */
 		if (!pkey->len) {
-			lbs_pr_debug(1, "key not set, so cannot enable it\n");
-			LEAVE();
-			return -EINVAL;
+			lbs_deb_wext("key not set, so cannot enable it\n");
+			ret = -EINVAL;
+			goto out;
 		}
 		assoc_req->wep_tx_keyidx = index;
 	}
 
 	assoc_req->secinfo.wep_enabled = 1;
 
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 static int validate_key_index(u16 def_index, u16 raw_index,
@@ -1605,6 +1534,8 @@
 {
 	int i;
 
+	lbs_deb_enter(LBS_DEB_WEXT);
+
 	/* Set Open System auth mode */
 	assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
 
@@ -1615,6 +1546,27 @@
 
 	set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
 	set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
+
+	lbs_deb_leave(LBS_DEB_WEXT);
+}
+
+static void disable_wpa(struct assoc_request *assoc_req)
+{
+	lbs_deb_enter(LBS_DEB_WEXT);
+
+	memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct WLAN_802_11_KEY));
+	assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
+	set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
+
+	memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct WLAN_802_11_KEY));
+	assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
+	set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
+
+	assoc_req->secinfo.WPAenabled = 0;
+	assoc_req->secinfo.WPA2enabled = 0;
+	set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
+
+	lbs_deb_leave(LBS_DEB_WEXT);
 }
 
 /**
@@ -1636,7 +1588,7 @@
 	struct assoc_request * assoc_req;
 	u16 is_default = 0, index = 0, set_tx_key = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	mutex_lock(&adapter->lock);
 	assoc_req = wlan_get_association_request(adapter);
@@ -1647,6 +1599,7 @@
 
 	if (dwrq->flags & IW_ENCODE_DISABLED) {
 		disable_wep (assoc_req);
+		disable_wpa (assoc_req);
 		goto out;
 	}
 
@@ -1688,7 +1641,7 @@
 	}
 	mutex_unlock(&adapter->lock);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -1712,7 +1665,7 @@
 	struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
 	int index, max_key_len;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	max_key_len = dwrq->length - sizeof(*ext);
 	if (max_key_len < 0)
@@ -1748,6 +1701,7 @@
 		if (   adapter->secinfo.wep_enabled
 		    && !adapter->secinfo.WPAenabled
 		    && !adapter->secinfo.WPA2enabled) {
+			/* WEP */
 			ext->alg = IW_ENCODE_ALG_WEP;
 			ext->key_len = adapter->wep_keys[index].len;
 			key = &adapter->wep_keys[index].key[0];
@@ -1755,8 +1709,27 @@
 		           && (adapter->secinfo.WPAenabled ||
 		               adapter->secinfo.WPA2enabled)) {
 			/* WPA */
-			ext->alg = IW_ENCODE_ALG_TKIP;
-			ext->key_len = 0;
+			struct WLAN_802_11_KEY * pkey = NULL;
+
+			if (   adapter->wpa_mcast_key.len
+			    && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
+				pkey = &adapter->wpa_mcast_key;
+			else if (   adapter->wpa_unicast_key.len
+			         && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
+				pkey = &adapter->wpa_unicast_key;
+
+			if (pkey) {
+				if (pkey->type == KEY_TYPE_ID_AES) {
+					ext->alg = IW_ENCODE_ALG_CCMP;
+				} else {
+					ext->alg = IW_ENCODE_ALG_TKIP;
+				}
+				ext->key_len = pkey->len;
+				key = &pkey->key[0];
+			} else {
+				ext->alg = IW_ENCODE_ALG_TKIP;
+				ext->key_len = 0;
+			}
 		} else {
 			goto out;
 		}
@@ -1775,7 +1748,7 @@
 	ret = 0;
 
 out:
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -1800,7 +1773,7 @@
 	int alg = ext->alg;
 	struct assoc_request * assoc_req;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	mutex_lock(&adapter->lock);
 	assoc_req = wlan_get_association_request(adapter);
@@ -1811,6 +1784,7 @@
 
 	if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
 		disable_wep (assoc_req);
+		disable_wpa (assoc_req);
 	} else if (alg == IW_ENCODE_ALG_WEP) {
 		u16 is_default = 0, index, set_tx_key = 0;
 
@@ -1846,7 +1820,6 @@
 			set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
 		if (set_tx_key)
 			set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
-
 	} else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
 		struct WLAN_802_11_KEY * pkey;
 
@@ -1855,36 +1828,43 @@
 			&& (ext->key_len != KEY_LEN_WPA_TKIP))
 		    || ((alg == IW_ENCODE_ALG_CCMP)
 		        && (ext->key_len != KEY_LEN_WPA_AES))) {
-				lbs_pr_debug(1, "Invalid size %d for key of alg"
-				       "type %d.\n",
+				lbs_deb_wext("invalid size %d for key of alg"
+				       "type %d\n",
 				       ext->key_len,
 				       alg);
 				ret = -EINVAL;
 				goto out;
 		}
 
-		if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
+		if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
 			pkey = &assoc_req->wpa_mcast_key;
-		else
+			set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
+		} else {
 			pkey = &assoc_req->wpa_unicast_key;
+			set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
+		}
 
 		memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
 		memcpy(pkey->key, ext->key, ext->key_len);
 		pkey->len = ext->key_len;
-		pkey->flags = KEY_INFO_WPA_ENABLED;
+		if (pkey->len)
+			pkey->flags |= KEY_INFO_WPA_ENABLED;
 
+		/* Do this after zeroing key structure */
 		if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
 			pkey->flags |= KEY_INFO_WPA_MCAST;
-			set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
 		} else {
 			pkey->flags |= KEY_INFO_WPA_UNICAST;
-			set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
 		}
 
-		if (alg == IW_ENCODE_ALG_TKIP)
+		if (alg == IW_ENCODE_ALG_TKIP) {
 			pkey->type = KEY_TYPE_ID_TKIP;
-		else if (alg == IW_ENCODE_ALG_CCMP)
+		} else if (alg == IW_ENCODE_ALG_CCMP) {
 			pkey->type = KEY_TYPE_ID_AES;
+		} else {
+			ret = -EINVAL;
+			goto out;
+		}
 
 		/* If WPA isn't enabled yet, do that now */
 		if (   assoc_req->secinfo.WPAenabled == 0
@@ -1905,7 +1885,7 @@
 	}
 	mutex_unlock(&adapter->lock);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -1920,7 +1900,7 @@
 	int ret = 0;
 	struct assoc_request * assoc_req;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	mutex_lock(&adapter->lock);
 	assoc_req = wlan_get_association_request(adapter);
@@ -1952,7 +1932,7 @@
 	}
 	mutex_unlock(&adapter->lock);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -1961,27 +1941,28 @@
 			  struct iw_point *dwrq,
 			  char *extra)
 {
+	int ret = 0;
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (adapter->wpa_ie_len == 0) {
 		dwrq->length = 0;
-		LEAVE();
-		return 0;
+		goto out;
 	}
 
 	if (dwrq->length < adapter->wpa_ie_len) {
-		LEAVE();
-		return -E2BIG;
+		ret = -E2BIG;
+		goto out;
 	}
 
 	dwrq->length = adapter->wpa_ie_len;
 	memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
 
-	LEAVE();
-	return 0;
+out:
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 
@@ -1996,7 +1977,7 @@
 	int ret = 0;
 	int updated = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	mutex_lock(&adapter->lock);
 	assoc_req = wlan_get_association_request(adapter);
@@ -2010,6 +1991,7 @@
 	case IW_AUTH_CIPHER_PAIRWISE:
 	case IW_AUTH_CIPHER_GROUP:
 	case IW_AUTH_KEY_MGMT:
+	case IW_AUTH_DROP_UNENCRYPTED:
 		/*
 		 * libertas does not use these parameters
 		 */
@@ -2019,6 +2001,7 @@
 		if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
 			assoc_req->secinfo.WPAenabled = 0;
 			assoc_req->secinfo.WPA2enabled = 0;
+			disable_wpa (assoc_req);
 		}
 		if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
 			assoc_req->secinfo.WPAenabled = 1;
@@ -2033,17 +2016,6 @@
 		updated = 1;
 		break;
 
-	case IW_AUTH_DROP_UNENCRYPTED:
-		if (dwrq->value) {
-			adapter->currentpacketfilter |=
-			    cmd_act_mac_strict_protection_enable;
-		} else {
-			adapter->currentpacketfilter &=
-			    ~cmd_act_mac_strict_protection_enable;
-		}
-		updated = 1;
-		break;
-
 	case IW_AUTH_80211_AUTH_ALG:
 		if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
 			assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
@@ -2069,6 +2041,7 @@
 		} else {
 			assoc_req->secinfo.WPAenabled = 0;
 			assoc_req->secinfo.WPA2enabled = 0;
+			disable_wpa (assoc_req);
 		}
 		updated = 1;
 		break;
@@ -2088,7 +2061,7 @@
 	}
 	mutex_unlock(&adapter->lock);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -2097,10 +2070,11 @@
 			 struct iw_param *dwrq,
 			 char *extra)
 {
+	int ret = 0;
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	switch (dwrq->flags & IW_AUTH_INDEX) {
 	case IW_AUTH_WPA_VERSION:
@@ -2113,13 +2087,6 @@
 			dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
 		break;
 
-	case IW_AUTH_DROP_UNENCRYPTED:
-		dwrq->value = 0;
-		if (adapter->currentpacketfilter &
-		    cmd_act_mac_strict_protection_enable)
-			dwrq->value = 1;
-		break;
-
 	case IW_AUTH_80211_AUTH_ALG:
 		dwrq->value = adapter->secinfo.auth_mode;
 		break;
@@ -2130,12 +2097,11 @@
 		break;
 
 	default:
-		LEAVE();
-		return -EOPNOTSUPP;
+		ret = -EOPNOTSUPP;
 	}
 
-	LEAVE();
-	return 0;
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+	return ret;
 }
 
 
@@ -2148,7 +2114,7 @@
 
 	u16 dbm;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (vwrq->disabled) {
 		wlan_radio_ioctl(priv, RADIO_OFF);
@@ -2169,14 +2135,14 @@
 	if (vwrq->fixed == 0)
 		dbm = 0xffff;
 
-	lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
+	lbs_deb_wext("txpower set %d dbm\n", dbm);
 
 	ret = libertas_prepare_and_send_command(priv,
 				    cmd_802_11_rf_tx_power,
 				    cmd_act_tx_power_opt_set_low,
 				    cmd_option_waitforrsp, 0, (void *)&dbm);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -2186,7 +2152,8 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
+
 	/*
 	 * Note : if dwrq->flags != 0, we should get the relevant SSID from
 	 * the SSID list...
@@ -2196,12 +2163,12 @@
 	 * Get the current SSID
 	 */
 	if (adapter->connect_status == libertas_connected) {
-		memcpy(extra, adapter->curbssparams.ssid.ssid,
-		       adapter->curbssparams.ssid.ssidlength);
-		extra[adapter->curbssparams.ssid.ssidlength] = '\0';
+		memcpy(extra, adapter->curbssparams.ssid,
+		       adapter->curbssparams.ssid_len);
+		extra[adapter->curbssparams.ssid_len] = '\0';
 	} else {
 		memset(extra, 0, 32);
-		extra[adapter->curbssparams.ssid.ssidlength] = '\0';
+		extra[adapter->curbssparams.ssid_len] = '\0';
 	}
 	/*
 	 * If none, we may want to get the one that was set
@@ -2209,14 +2176,14 @@
 
 	/* To make the driver backward compatible with WPA supplicant v0.2.4 */
 	if (dwrq->length == 32)	/* check with WPA supplicant buffer size */
-		dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
+		dwrq->length = min_t(size_t, adapter->curbssparams.ssid_len,
 				   IW_ESSID_MAX_SIZE);
 	else
-		dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
+		dwrq->length = adapter->curbssparams.ssid_len + 1;
 
 	dwrq->flags = 1;	/* active */
 
-	LEAVE();
+	lbs_deb_leave(LBS_DEB_WEXT);
 	return 0;
 }
 
@@ -2226,38 +2193,43 @@
 	wlan_private *priv = dev->priv;
 	wlan_adapter *adapter = priv->adapter;
 	int ret = 0;
-	struct WLAN_802_11_SSID ssid;
+	u8 ssid[IW_ESSID_MAX_SIZE];
+	u8 ssid_len = 0;
 	struct assoc_request * assoc_req;
-	int ssid_len = dwrq->length;
+	int in_ssid_len = dwrq->length;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	/*
 	 * WE-20 and earlier NULL pad the end of the SSID and increment
 	 * SSID length so it can be used like a string.  WE-21 and later don't,
 	 * but some userspace tools aren't able to cope with the change.
 	 */
-	if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
-		ssid_len--;
+	if ((in_ssid_len > 0) && (extra[in_ssid_len - 1] == '\0'))
+		in_ssid_len--;
 
 	/* Check the size of the string */
-	if (ssid_len > IW_ESSID_MAX_SIZE) {
+	if (in_ssid_len > IW_ESSID_MAX_SIZE) {
 		ret = -E2BIG;
 		goto out;
 	}
 
-	memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
+	memset(&ssid, 0, sizeof(ssid));
 
-	if (!dwrq->flags || !ssid_len) {
+	if (!dwrq->flags || !in_ssid_len) {
 		/* "any" SSID requested; leave SSID blank */
 	} else {
 		/* Specific SSID requested */
-		memcpy(&ssid.ssid, extra, ssid_len);
-		ssid.ssidlength = ssid_len;
+		memcpy(&ssid, extra, in_ssid_len);
+		ssid_len = in_ssid_len;
 	}
 
-	lbs_pr_debug(1, "Requested new SSID = %s\n",
-	       (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
+	if (!ssid_len) {
+		lbs_deb_wext("requested any SSID\n");
+	} else {
+		lbs_deb_wext("requested SSID '%s'\n",
+		             escape_essid(ssid, ssid_len));
+	}
 
 out:
 	mutex_lock(&adapter->lock);
@@ -2268,7 +2240,8 @@
 			ret = -ENOMEM;
 		} else {
 			/* Copy the SSID to the association request */
-			memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
+			memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
+			assoc_req->ssid_len = ssid_len;
 			set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
 			wlan_postpone_association_work(priv);
 		}
@@ -2281,7 +2254,7 @@
 
 	mutex_unlock(&adapter->lock);
 
-	LEAVE();
+	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
 	return ret;
 }
 
@@ -2302,12 +2275,12 @@
 	struct assoc_request * assoc_req;
 	int ret = 0;
 
-	ENTER();
+	lbs_deb_enter(LBS_DEB_WEXT);
 
 	if (awrq->sa_family != ARPHRD_ETHER)
 		return -EINVAL;
 
-	lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
+	lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
 
 	mutex_lock(&adapter->lock);
 
@@ -2330,22 +2303,23 @@
 
 void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
 {
-	union {
-		u32 l;
-		u8 c[4];
-	} ver;
 	char fwver[32];
 
 	mutex_lock(&adapter->lock);
-	ver.l = adapter->fwreleasenumber;
-	mutex_unlock(&adapter->lock);
 
-	if (ver.c[3] == 0)
-		sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
+	if (adapter->fwreleasenumber[3] == 0)
+		sprintf(fwver, "%u.%u.%u",
+			adapter->fwreleasenumber[2],
+			adapter->fwreleasenumber[1],
+			adapter->fwreleasenumber[0]);
 	else
 		sprintf(fwver, "%u.%u.%u.p%u",
-			ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
+			adapter->fwreleasenumber[2],
+			adapter->fwreleasenumber[1],
+			adapter->fwreleasenumber[0],
+			adapter->fwreleasenumber[3]);
 
+	mutex_unlock(&adapter->lock);
 	snprintf(fwversion, maxlen, fwver);
 }
 
@@ -2411,6 +2385,63 @@
 	(iw_handler) NULL,		/* SIOCSIWPMKSA */
 };
 
+static const iw_handler mesh_wlan_handler[] = {
+	(iw_handler) NULL,	/* SIOCSIWCOMMIT */
+	(iw_handler) wlan_get_name,	/* SIOCGIWNAME */
+	(iw_handler) NULL,	/* SIOCSIWNWID */
+	(iw_handler) NULL,	/* SIOCGIWNWID */
+	(iw_handler) wlan_set_freq,	/* SIOCSIWFREQ */
+	(iw_handler) wlan_get_freq,	/* SIOCGIWFREQ */
+	(iw_handler) NULL,		/* SIOCSIWMODE */
+	(iw_handler) mesh_wlan_get_mode,	/* SIOCGIWMODE */
+	(iw_handler) NULL,	/* SIOCSIWSENS */
+	(iw_handler) NULL,	/* SIOCGIWSENS */
+	(iw_handler) NULL,	/* SIOCSIWRANGE */
+	(iw_handler) wlan_get_range,	/* SIOCGIWRANGE */
+	(iw_handler) NULL,	/* SIOCSIWPRIV */
+	(iw_handler) NULL,	/* SIOCGIWPRIV */
+	(iw_handler) NULL,	/* SIOCSIWSTATS */
+	(iw_handler) NULL,	/* SIOCGIWSTATS */
+	iw_handler_set_spy,	/* SIOCSIWSPY */
+	iw_handler_get_spy,	/* SIOCGIWSPY */
+	iw_handler_set_thrspy,	/* SIOCSIWTHRSPY */
+	iw_handler_get_thrspy,	/* SIOCGIWTHRSPY */
+	(iw_handler) NULL,	/* SIOCSIWAP */
+	(iw_handler) NULL,	/* SIOCGIWAP */
+	(iw_handler) NULL,	/* SIOCSIWMLME */
+	(iw_handler) NULL,	/* SIOCGIWAPLIST - deprecated */
+	(iw_handler) libertas_set_scan,	/* SIOCSIWSCAN */
+	(iw_handler) libertas_get_scan,	/* SIOCGIWSCAN */
+	(iw_handler) NULL,		/* SIOCSIWESSID */
+	(iw_handler) NULL,		/* SIOCGIWESSID */
+	(iw_handler) NULL,		/* SIOCSIWNICKN */
+	(iw_handler) mesh_get_nick,	/* SIOCGIWNICKN */
+	(iw_handler) NULL,	/* -- hole -- */
+	(iw_handler) NULL,	/* -- hole -- */
+	(iw_handler) wlan_set_rate,	/* SIOCSIWRATE */
+	(iw_handler) wlan_get_rate,	/* SIOCGIWRATE */
+	(iw_handler) wlan_set_rts,	/* SIOCSIWRTS */
+	(iw_handler) wlan_get_rts,	/* SIOCGIWRTS */
+	(iw_handler) wlan_set_frag,	/* SIOCSIWFRAG */
+	(iw_handler) wlan_get_frag,	/* SIOCGIWFRAG */
+	(iw_handler) wlan_set_txpow,	/* SIOCSIWTXPOW */
+	(iw_handler) wlan_get_txpow,	/* SIOCGIWTXPOW */
+	(iw_handler) wlan_set_retry,	/* SIOCSIWRETRY */
+	(iw_handler) wlan_get_retry,	/* SIOCGIWRETRY */
+	(iw_handler) wlan_set_encode,	/* SIOCSIWENCODE */
+	(iw_handler) wlan_get_encode,	/* SIOCGIWENCODE */
+	(iw_handler) wlan_set_power,	/* SIOCSIWPOWER */
+	(iw_handler) wlan_get_power,	/* SIOCGIWPOWER */
+	(iw_handler) NULL,	/* -- hole -- */
+	(iw_handler) NULL,	/* -- hole -- */
+	(iw_handler) wlan_set_genie,	/* SIOCSIWGENIE */
+	(iw_handler) wlan_get_genie,	/* SIOCGIWGENIE */
+	(iw_handler) wlan_set_auth,	/* SIOCSIWAUTH */
+	(iw_handler) wlan_get_auth,	/* SIOCGIWAUTH */
+	(iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
+	(iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
+	(iw_handler) NULL,		/* SIOCSIWPMKSA */
+};
 struct iw_handler_def libertas_handler_def = {
 	.num_standard	= sizeof(wlan_handler) / sizeof(iw_handler),
 	.num_private	= sizeof(wlan_private_handler) / sizeof(iw_handler),
@@ -2421,3 +2452,14 @@
 	.private_args	= (struct iw_priv_args *)wlan_private_args,
 	.get_wireless_stats = wlan_get_wireless_stats,
 };
+
+struct iw_handler_def mesh_handler_def = {
+	.num_standard	= sizeof(mesh_wlan_handler) / sizeof(iw_handler),
+	.num_private	= sizeof(wlan_private_handler) / sizeof(iw_handler),
+	.num_private_args = sizeof(wlan_private_args) /
+		sizeof(struct iw_priv_args),
+	.standard	= (iw_handler *) mesh_wlan_handler,
+	.private	= (iw_handler *) wlan_private_handler,
+	.private_args	= (struct iw_priv_args *)wlan_private_args,
+	.get_wireless_stats = wlan_get_wireless_stats,
+};
diff --git a/drivers/net/wireless/libertas/wext.h b/drivers/net/wireless/libertas/wext.h
index 15cfaaf..d555056 100644
--- a/drivers/net/wireless/libertas/wext.h
+++ b/drivers/net/wireless/libertas/wext.h
@@ -20,21 +20,23 @@
 #define WLAN_SUBCMD_FWT_CLEANUP			15
 #define WLAN_SUBCMD_FWT_TIME			16
 #define WLAN_SUBCMD_MESH_GET_TTL		17
+#define WLAN_SUBCMD_BT_GET_INVERT		18
 
 #define WLAN_SETONEINT_GETNONE		(WLANIOCTL + 24)
 #define WLANSETREGION				8
 #define WLAN_SUBCMD_MESH_SET_TTL		18
+#define WLAN_SUBCMD_BT_SET_INVERT		19
 
 #define WLAN_SET128CHAR_GET128CHAR	(WLANIOCTL + 25)
 #define WLAN_SUBCMD_BT_ADD			18
 #define WLAN_SUBCMD_BT_DEL   			19
 #define WLAN_SUBCMD_BT_LIST			20
-#define WLAN_SUBCMD_FWT_ADD				21
-#define WLAN_SUBCMD_FWT_DEL   		22
-#define WLAN_SUBCMD_FWT_LOOKUP		23
-#define WLAN_SUBCMD_FWT_LIST_NEIGHBOR			24
+#define WLAN_SUBCMD_FWT_ADD			21
+#define WLAN_SUBCMD_FWT_DEL   			22
+#define WLAN_SUBCMD_FWT_LOOKUP			23
+#define WLAN_SUBCMD_FWT_LIST_NEIGHBOR		24
 #define WLAN_SUBCMD_FWT_LIST			25
-#define WLAN_SUBCMD_FWT_LIST_ROUTE			26
+#define WLAN_SUBCMD_FWT_LIST_ROUTE		26
 
 #define WLAN_SET_GET_SIXTEEN_INT       (WLANIOCTL + 29)
 #define WLAN_LED_GPIO_CTRL			5
@@ -56,6 +58,7 @@
 };
 
 extern struct iw_handler_def libertas_handler_def;
+extern struct iw_handler_def mesh_handler_def;
 int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int i);
 int wlan_radio_ioctl(wlan_private * priv, u8 option);
 
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 894fdb9..b3c4dbf 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -32,6 +32,7 @@
 */
 
 #include <linux/types.h>
+#include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/spinlock.h>
@@ -292,7 +293,6 @@
 #define PDIR_INDEX(iovp)    ((iovp)>>IOVP_SHIFT)
 #define MKIOVP(pdir_idx)    ((long)(pdir_idx) << IOVP_SHIFT)
 #define MKIOVA(iovp,offset) (dma_addr_t)((long)iovp | (long)offset)
-#define ROUNDUP(x,y) ((x + ((y)-1)) & ~((y)-1))
 
 /*
 ** Don't worry about the 150% average search length on a miss.
@@ -668,7 +668,7 @@
 	size_t saved_byte_cnt;
 
 	/* round up to nearest page size */
-	saved_byte_cnt = byte_cnt = ROUNDUP(byte_cnt, IOVP_SIZE);
+	saved_byte_cnt = byte_cnt = ALIGN(byte_cnt, IOVP_SIZE);
 
 	while(byte_cnt > 0) {
 		/* invalidate one page at a time */
@@ -751,7 +751,7 @@
 	offset = ((unsigned long) addr) & ~IOVP_MASK;
 
 	/* round up to nearest IOVP_SIZE */
-	size = ROUNDUP(size + offset, IOVP_SIZE);
+	size = ALIGN(size + offset, IOVP_SIZE);
 	spin_lock_irqsave(&ioc->res_lock, flags);
 
 #ifdef CCIO_MAP_STATS
@@ -814,7 +814,7 @@
 
 	iova ^= offset;        /* clear offset bits */
 	size += offset;
-	size = ROUNDUP(size, IOVP_SIZE);
+	size = ALIGN(size, IOVP_SIZE);
 
 	spin_lock_irqsave(&ioc->res_lock, flags);
 
@@ -1227,7 +1227,7 @@
 #endif /* 0 */
 
 /* We *can't* support JAVA (T600). Venture there at your own risk. */
-static struct parisc_device_id ccio_tbl[] = {
+static const struct parisc_device_id ccio_tbl[] = {
 	{ HPHW_IOA, HVERSION_REV_ANY_ID, U2_IOA_RUNWAY, 0xb }, /* U2 */
 	{ HPHW_IOA, HVERSION_REV_ANY_ID, UTURN_IOA_RUNWAY, 0xb }, /* UTurn */
 	{ 0, }
@@ -1370,7 +1370,7 @@
 	}
 }
 
-static void
+static void __init
 ccio_init_resource(struct resource *res, char *name, void __iomem *ioaddr)
 {
 	int result;
@@ -1537,7 +1537,7 @@
  * If so, initialize the chip and tell other partners in crime they
  * have work to do.
  */
-static int ccio_probe(struct parisc_device *dev)
+static int __init ccio_probe(struct parisc_device *dev)
 {
 	int i;
 	struct ioc *ioc, **ioc_p = &ioc_list;
diff --git a/drivers/parisc/eisa.c b/drivers/parisc/eisa.c
index 309076b..771cef5 100644
--- a/drivers/parisc/eisa.c
+++ b/drivers/parisc/eisa.c
@@ -307,7 +307,7 @@
 
 #define is_mongoose(dev) (dev->id.sversion == 0x00076)
 
-static int __devinit eisa_probe(struct parisc_device *dev)
+static int __init eisa_probe(struct parisc_device *dev)
 {
 	int i, result;
 
@@ -387,7 +387,7 @@
 	return 0;
 }
 
-static struct parisc_device_id eisa_tbl[] = {
+static const struct parisc_device_id eisa_tbl[] = {
 	{ HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00076 }, /* Mongoose */
 	{ HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00090 }, /* Wax EISA */
 	{ 0, }
diff --git a/drivers/parisc/iommu-helpers.h b/drivers/parisc/iommu-helpers.h
index 38d9e1a..0a1f99a 100644
--- a/drivers/parisc/iommu-helpers.h
+++ b/drivers/parisc/iommu-helpers.h
@@ -138,7 +138,7 @@
 			** exceed DMA_CHUNK_SIZE if we coalesce the
 			** next entry.
 			*/   
-			if(unlikely(ROUNDUP(dma_len + dma_offset + startsg->length,
+			if(unlikely(ALIGN(dma_len + dma_offset + startsg->length,
 					    IOVP_SIZE) > DMA_CHUNK_SIZE))
 				break;
 
@@ -158,7 +158,7 @@
 		** Allocate space for DMA stream.
 		*/
 		sg_dma_len(contig_sg) = dma_len;
-		dma_len = ROUNDUP(dma_len + dma_offset, IOVP_SIZE);
+		dma_len = ALIGN(dma_len + dma_offset, IOVP_SIZE);
 		sg_dma_address(contig_sg) =
 			PIDE_FLAG 
 			| (iommu_alloc_range(ioc, dma_len) << IOVP_SHIFT)
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 815e445..924ef06 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -1067,7 +1067,7 @@
 			error = subsys_create_file(&stable_subsys, attr);
 	
 	/* register the paths subsys as a subsystem of stable subsys */
-	kset_set_kset_s(&paths_subsys, stable_subsys);
+	kobj_set_kset_s(&paths_subsys, stable_subsys);
 	if ((rc = subsystem_register(&paths_subsys)))
 		goto fail_subsysreg;
 
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index 6dedbde..90cca5e 100644
--- a/drivers/parisc/power.c
+++ b/drivers/parisc/power.c
@@ -41,6 +41,7 @@
 #include <linux/reboot.h>
 #include <linux/sched.h>
 #include <linux/kthread.h>
+#include <linux/pm.h>
 
 #include <asm/pdc.h>
 #include <asm/io.h>
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index 322957a..d044c48 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -113,8 +113,6 @@
 MODULE_PARM_DESC(sba_reserve_agpgart, "Reserve half of IO pdir as AGPGART");
 #endif
 
-#define ROUNDUP(x,y) ((x + ((y)-1)) & ~((y)-1))
-
 
 /************************************
 ** SBA register read and write support
@@ -352,7 +350,7 @@
 		** SBA HW features in the unmap path.
 		*/
 		unsigned long o = 1 << get_order(bits_wanted << PAGE_SHIFT);
-		uint bitshiftcnt = ROUNDUP(ioc->res_bitshift, o);
+		uint bitshiftcnt = ALIGN(ioc->res_bitshift, o);
 		unsigned long mask;
 
 		if (bitshiftcnt >= BITS_PER_LONG) {
@@ -779,7 +777,7 @@
 	offset = iova & ~IOVP_MASK;
 	iova ^= offset;        /* clear offset bits */
 	size += offset;
-	size = ROUNDUP(size, IOVP_SIZE);
+	size = ALIGN(size, IOVP_SIZE);
 
 	spin_lock_irqsave(&ioc->res_lock, flags);
 
diff --git a/drivers/parisc/superio.c b/drivers/parisc/superio.c
index 1fd97f7..a708c32 100644
--- a/drivers/parisc/superio.c
+++ b/drivers/parisc/superio.c
@@ -389,7 +389,7 @@
 	return local_irq;
 }
 
-static void __devinit superio_serial_init(void)
+static void __init superio_serial_init(void)
 {
 #ifdef CONFIG_SERIAL_8250
 	int retval;
@@ -423,7 +423,7 @@
 }
 
 
-static void __devinit superio_parport_init(void)
+static void __init superio_parport_init(void)
 {
 #ifdef CONFIG_PARPORT_PC
 	if (!parport_pc_probe_port(sio_dev.pp_base,
@@ -450,7 +450,7 @@
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87415, superio_fixup_pci);
 
 
-static int __devinit
+static int __init
 superio_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
 	struct superio_device *sio = &sio_dev;
@@ -485,7 +485,7 @@
 	return -ENODEV;
 }
 
-static struct pci_device_id superio_tbl[] = {
+static const struct pci_device_id superio_tbl[] = {
 	{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87560_LIO) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87560_USB) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87415) },
diff --git a/drivers/parport/parport_gsc.c b/drivers/parport/parport_gsc.c
index 17bf993..43652ba 100644
--- a/drivers/parport/parport_gsc.c
+++ b/drivers/parport/parport_gsc.c
@@ -350,7 +350,7 @@
 
 #define PARPORT_GSC_OFFSET 0x800
 
-static int __initdata parport_count;
+static int __devinitdata parport_count;
 
 static int __devinit parport_init_chip(struct parisc_device *dev)
 {
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index ec71061..71caf2d 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -2033,6 +2033,7 @@
 			starget_for_each_device(tp->starget, NULL,
 						esp_clear_hold);
 	}
+	esp->flags &= ~ESP_FLAG_RESETTING;
 }
 
 /* Runs under host->lock */
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 8263f75..bb90df8 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -463,7 +463,7 @@
 
 static int idescsi_expiry(ide_drive_t *drive)
 {
-	idescsi_scsi_t *scsi = drive->driver_data;
+	idescsi_scsi_t *scsi = drive_to_idescsi(drive);
 	idescsi_pc_t   *pc   = scsi->pc;
 
 #if IDESCSI_DEBUG_LOG
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 787dc71..22569bd 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -185,6 +185,7 @@
 		uart->port.icount.brk++;
 		if (uart_handle_break(&uart->port))
 			goto ignore_char;
+		status &= ~(PE | FE);
 	}
 	if (status & PE)
 		uart->port.icount.parity++;
@@ -341,6 +342,7 @@
 		uart->port.icount.brk++;
 		if (uart_handle_break(&uart->port))
 			goto dma_ignore_char;
+		status &= ~(PE | FE);
 	}
 	if (status & PE)
 		uart->port.icount.parity++;
@@ -517,6 +519,14 @@
  */
 static void bfin_serial_break_ctl(struct uart_port *port, int break_state)
 {
+	struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
+	u16 lcr = UART_GET_LCR(uart);
+	if (break_state)
+		lcr |= SB;
+	else
+		lcr &= ~SB;
+	UART_PUT_LCR(uart, lcr);
+	SSYNC();
 }
 
 static int bfin_serial_startup(struct uart_port *port)
@@ -625,11 +635,12 @@
 
 	if (termios->c_cflag & CSTOPB)
 		lcr |= STB;
-	if (termios->c_cflag & PARENB) {
+	if (termios->c_cflag & PARENB)
 		lcr |= PEN;
-		if (!(termios->c_cflag & PARODD))
-			lcr |= EPS;
-	}
+	if (!(termios->c_cflag & PARODD))
+		lcr |= EPS;
+	if (termios->c_cflag & CMSPAR)
+		lcr |= STP;
 
 	port->read_status_mask = OE;
 	if (termios->c_iflag & INPCK)
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index 7d2d9ec..48587c2 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -582,14 +582,19 @@
 	dev_dbg(&drv_data->pdev->dev, "in dma_irq_handler\n");
 	clear_dma_irqstat(CH_SPI);
 
+	/* Wait for DMA to complete */
+	while (get_dma_curr_irqstat(CH_SPI) & DMA_RUN)
+		continue;
+
 	/*
-	 * wait for the last transaction shifted out.  yes, these two
-	 * while loops are supposed to be the same (see the HRM).
+	 * wait for the last transaction shifted out.  HRM states:
+	 * at this point there may still be data in the SPI DMA FIFO waiting
+	 * to be transmitted ... software needs to poll TXS in the SPI_STAT
+	 * register until it goes low for 2 successive reads
 	 */
 	if (drv_data->tx != NULL) {
-		while (bfin_read_SPI_STAT() & TXS)
-			continue;
-		while (bfin_read_SPI_STAT() & TXS)
+		while ((bfin_read_SPI_STAT() & TXS) ||
+		       (bfin_read_SPI_STAT() & TXS))
 			continue;
 	}
 
@@ -1082,7 +1087,7 @@
  */
 static void cleanup(struct spi_device *spi)
 {
-	struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
+	struct chip_data *chip = spi_get_ctldata(spi);
 
 	kfree(chip);
 }
diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
index 717b360..870017d 100644
--- a/drivers/video/console/sticore.c
+++ b/drivers/video/console/sticore.c
@@ -240,7 +240,7 @@
 	flush_icache_range(from, from+len);
 }
 
-void __init
+void __devinit
 sti_rom_copy(unsigned long base, unsigned long count, void *dest)
 {
 	unsigned long dest_len = count;
@@ -269,7 +269,7 @@
 static char default_sti_path[21] __read_mostly;
 
 #ifndef MODULE
-static int __init sti_setup(char *str)
+static int __devinit sti_setup(char *str)
 {
 	if (str)
 		strlcpy (default_sti_path, str, sizeof (default_sti_path));
@@ -288,12 +288,12 @@
 
 
 
-static char __initdata	*font_name[MAX_STI_ROMS] = { "VGA8x16", };
-static int __initdata	font_index[MAX_STI_ROMS], 
-			font_height[MAX_STI_ROMS],
-			font_width[MAX_STI_ROMS];
+static char __devinitdata	*font_name[MAX_STI_ROMS] = { "VGA8x16", };
+static int __devinitdata	font_index[MAX_STI_ROMS],
+				font_height[MAX_STI_ROMS],
+				font_width[MAX_STI_ROMS];
 #ifndef MODULE
-static int __init sti_font_setup(char *str)
+static int __devinit sti_font_setup(char *str)
 {
 	char *x;
 	int i = 0;
@@ -346,7 +346,7 @@
 
 
 	
-static void __init
+static void __devinit
 sti_dump_globcfg(struct sti_glob_cfg *glob_cfg, unsigned int sti_mem_request)
 {
 	struct sti_glob_cfg_ext *cfg;
@@ -386,7 +386,7 @@
 		cfg->sti_mem_addr, sti_mem_request));
 }
 
-static void __init
+static void __devinit
 sti_dump_outptr(struct sti_struct *sti)
 {
 	DPRINTK((KERN_INFO
@@ -400,7 +400,7 @@
 		 sti->outptr.attributes));
 }
 
-static int __init
+static int __devinit
 sti_init_glob_cfg(struct sti_struct *sti,
 	    unsigned long rom_address, unsigned long hpa)
 {
@@ -482,7 +482,7 @@
 }
 
 #ifdef CONFIG_FB
-struct sti_cooked_font * __init
+struct sti_cooked_font * __devinit
 sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
 {
 	const struct font_desc *fbfont;
@@ -538,14 +538,14 @@
 	return cooked_font;
 }
 #else
-struct sti_cooked_font * __init
+struct sti_cooked_font * __devinit
 sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
 {
 	return NULL;
 }
 #endif
 
-struct sti_cooked_font * __init
+struct sti_cooked_font * __devinit
 sti_select_font(struct sti_cooked_rom *rom,
 	    int (*search_font_fnc) (struct sti_cooked_rom *,int,int) )
 {
@@ -572,7 +572,7 @@
 }
 
 
-static void __init 
+static void __devinit
 sti_dump_rom(struct sti_rom *rom)
 {
 	printk(KERN_INFO "    id %04x-%04x, conforms to spec rev. %d.%02x\n",
@@ -590,7 +590,7 @@
 }
 
 
-static int __init 
+static int __devinit
 sti_cook_fonts(struct sti_cooked_rom *cooked_rom,
 			struct sti_rom *raw_rom)
 {
@@ -625,7 +625,7 @@
 }
 
 
-static int __init 
+static int __devinit
 sti_search_font(struct sti_cooked_rom *rom, int height, int width)
 {
 	struct sti_cooked_font *font;
@@ -642,7 +642,7 @@
 #define BMODE_RELOCATE(offset)		offset = (offset) / 4;
 #define BMODE_LAST_ADDR_OFFS		0x50
 
-static void * __init
+static void * __devinit
 sti_bmode_font_raw(struct sti_cooked_font *f)
 {
 	unsigned char *n, *p, *q;
@@ -660,7 +660,7 @@
 	return n + 3;
 }
 
-static void __init
+static void __devinit
 sti_bmode_rom_copy(unsigned long base, unsigned long count, void *dest)
 {
 	unsigned long dest_len = count;
@@ -675,7 +675,7 @@
 	sti_flush(dest_start, dest_len);
 }
 
-static struct sti_rom * __init
+static struct sti_rom * __devinit
 sti_get_bmode_rom (unsigned long address)
 {
 	struct sti_rom *raw;
@@ -711,7 +711,7 @@
 	return raw;
 }
 
-struct sti_rom * __init
+struct sti_rom * __devinit
 sti_get_wmode_rom (unsigned long address)
 {
 	struct sti_rom *raw;
@@ -727,7 +727,7 @@
 	return raw;
 }
 
-int __init
+int __devinit
 sti_read_rom(int wordmode, struct sti_struct *sti, unsigned long address)
 {
 	struct sti_cooked_rom *cooked;
@@ -783,7 +783,7 @@
 	return 0;
 }
 
-static struct sti_struct * __init
+static struct sti_struct * __devinit
 sti_try_rom_generic(unsigned long address, unsigned long hpa, struct pci_dev *pd)
 {
 	struct sti_struct *sti;
@@ -898,7 +898,7 @@
 	return NULL;
 }
 
-static void __init sticore_check_for_default_sti(struct sti_struct *sti, char *path)
+static void __devinit sticore_check_for_default_sti(struct sti_struct *sti, char *path)
 {
 	if (strcmp (path, default_sti_path) == 0)
 		default_sti = sti;
@@ -909,7 +909,7 @@
  * in the additional address field addr[1] while on
  * older Systems the PDC stores it in page0->proc_sti 
  */
-static int __init sticore_pa_init(struct parisc_device *dev)
+static int __devinit sticore_pa_init(struct parisc_device *dev)
 {
 	char pa_path[21];
 	struct sti_struct *sti = NULL;
@@ -1015,7 +1015,7 @@
 
 static int sticore_initialized __read_mostly;
 
-static void __init sti_init_roms(void)
+static void __devinit sti_init_roms(void)
 {
 	if (sticore_initialized)
 		return;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 9804c0c..cc5efc1 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -655,10 +655,9 @@
 static struct file_system_type fuseblk_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "fuseblk",
-	.fs_flags	= FS_HAS_SUBTYPE,
 	.get_sb		= fuse_get_sb_blk,
 	.kill_sb	= kill_block_super,
-	.fs_flags	= FS_REQUIRES_DEV,
+	.fs_flags	= FS_REQUIRES_DEV | FS_HAS_SUBTYPE,
 };
 
 static inline int register_fuseblk(void)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index aa083dd..e6b46b3 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -736,15 +736,13 @@
 			can_do_mlock());
 }
 
-struct file *hugetlb_zero_setup(size_t size)
+struct file *hugetlb_file_setup(const char *name, size_t size)
 {
 	int error = -ENOMEM;
 	struct file *file;
 	struct inode *inode;
 	struct dentry *dentry, *root;
 	struct qstr quick_string;
-	char buf[16];
-	static atomic_t counter;
 
 	if (!hugetlbfs_vfsmount)
 		return ERR_PTR(-ENOENT);
@@ -756,8 +754,7 @@
 		return ERR_PTR(-ENOMEM);
 
 	root = hugetlbfs_vfsmount->mnt_root;
-	snprintf(buf, 16, "%u", atomic_inc_return(&counter));
-	quick_string.name = buf;
+	quick_string.name = name;
 	quick_string.len = strlen(quick_string.name);
 	quick_string.hash = 0;
 	dentry = d_alloc(root, &quick_string);
diff --git a/fs/splice.c b/fs/splice.c
index cb21136..e7d7080 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -176,6 +176,7 @@
 static ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
 			      struct splice_pipe_desc *spd)
 {
+	unsigned int spd_pages = spd->nr_pages;
 	int ret, do_wakeup, page_nr;
 
 	ret = 0;
@@ -244,17 +245,18 @@
 		pipe->waiting_writers--;
 	}
 
-	if (pipe->inode)
+	if (pipe->inode) {
 		mutex_unlock(&pipe->inode->i_mutex);
 
-	if (do_wakeup) {
-		smp_mb();
-		if (waitqueue_active(&pipe->wait))
-			wake_up_interruptible(&pipe->wait);
-		kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
+		if (do_wakeup) {
+			smp_mb();
+			if (waitqueue_active(&pipe->wait))
+				wake_up_interruptible(&pipe->wait);
+			kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
+		}
 	}
 
-	while (page_nr < spd->nr_pages)
+	while (page_nr < spd_pages)
 		page_cache_release(spd->pages[page_nr++]);
 
 	return ret;
@@ -811,7 +813,10 @@
 
 	ret = __splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_file);
 	if (ret > 0) {
+		unsigned long nr_pages;
+
 		*ppos += ret;
+		nr_pages = (ret + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
 
 		/*
 		 * If file or inode is SYNC and we actually wrote some data,
@@ -824,7 +829,7 @@
 			if (err)
 				ret = err;
 		}
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited_nr(mapping, nr_pages);
 	}
 
 	return ret;
@@ -863,7 +868,10 @@
 
 	ret = splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_file);
 	if (ret > 0) {
+		unsigned long nr_pages;
+
 		*ppos += ret;
+		nr_pages = (ret + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
 
 		/*
 		 * If file or inode is SYNC and we actually wrote some data,
@@ -878,7 +886,7 @@
 			if (err)
 				ret = err;
 		}
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited_nr(mapping, nr_pages);
 	}
 
 	return ret;
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 85a6686..c4342a0 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -13,14 +13,26 @@
 #include "sysfs.h"
 
 DECLARE_RWSEM(sysfs_rename_sem);
+spinlock_t sysfs_lock = SPIN_LOCK_UNLOCKED;
 
 static void sysfs_d_iput(struct dentry * dentry, struct inode * inode)
 {
 	struct sysfs_dirent * sd = dentry->d_fsdata;
 
 	if (sd) {
-		BUG_ON(sd->s_dentry != dentry);
-		sd->s_dentry = NULL;
+		/* sd->s_dentry is protected with sysfs_lock.  This
+		 * allows sysfs_drop_dentry() to dereference it.
+		 */
+		spin_lock(&sysfs_lock);
+
+		/* The dentry might have been deleted or another
+		 * lookup could have happened updating sd->s_dentry to
+		 * point the new dentry.  Ignore if it isn't pointing
+		 * to this dentry.
+		 */
+		if (sd->s_dentry == dentry)
+			sd->s_dentry = NULL;
+		spin_unlock(&sysfs_lock);
 		sysfs_put(sd);
 	}
 	iput(inode);
@@ -30,6 +42,14 @@
 	.d_iput		= sysfs_d_iput,
 };
 
+static unsigned int sysfs_inode_counter;
+ino_t sysfs_get_inum(void)
+{
+	if (unlikely(sysfs_inode_counter < 3))
+		sysfs_inode_counter = 3;
+	return sysfs_inode_counter++;
+}
+
 /*
  * Allocates a new sysfs_dirent and links it to the parent sysfs_dirent
  */
@@ -41,6 +61,7 @@
 	if (!sd)
 		return NULL;
 
+	sd->s_ino = sysfs_get_inum();
 	atomic_set(&sd->s_count, 1);
 	atomic_set(&sd->s_event, 1);
 	INIT_LIST_HEAD(&sd->s_children);
@@ -238,7 +259,10 @@
         }
 
 	dentry->d_fsdata = sysfs_get(sd);
+	/* protect sd->s_dentry against sysfs_d_iput */
+	spin_lock(&sysfs_lock);
 	sd->s_dentry = dentry;
+	spin_unlock(&sysfs_lock);
 	error = sysfs_create(dentry, (attr->mode & S_IALLUGO) | S_IFREG, init);
 	if (error) {
 		sysfs_put(sd);
@@ -260,7 +284,10 @@
 	int err = 0;
 
 	dentry->d_fsdata = sysfs_get(sd);
+	/* protect sd->s_dentry against sysfs_d_iput */
+	spin_lock(&sysfs_lock);
 	sd->s_dentry = dentry;
+	spin_unlock(&sysfs_lock);
 	err = sysfs_create(dentry, S_IFLNK|S_IRWXUGO, init_symlink);
 	if (!err) {
 		dentry->d_op = &sysfs_dentry_ops;
@@ -509,7 +536,7 @@
 
 	switch (i) {
 		case 0:
-			ino = dentry->d_inode->i_ino;
+			ino = parent_sd->s_ino;
 			if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
 				break;
 			filp->f_pos++;
@@ -538,10 +565,7 @@
 
 				name = sysfs_get_name(next);
 				len = strlen(name);
-				if (next->s_dentry)
-					ino = next->s_dentry->d_inode->i_ino;
-				else
-					ino = iunique(sysfs_sb, 2);
+				ino = next->s_ino;
 
 				if (filldir(dirent, name, len, filp->f_pos, ino,
 						 dt_type(next)) < 0)
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index bdd30e7..5266eec 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -141,6 +141,7 @@
 		inode->i_mapping->a_ops = &sysfs_aops;
 		inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
 		inode->i_op = &sysfs_inode_operations;
+		inode->i_ino = sd->s_ino;
 		lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key);
 
 		if (sd->s_iattr) {
@@ -245,13 +246,27 @@
  */
 void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
 {
-	struct dentry * dentry = sd->s_dentry;
+	struct dentry *dentry = NULL;
 	struct inode *inode;
 
+	/* We're not holding a reference to ->s_dentry dentry but the
+	 * field will stay valid as long as sysfs_lock is held.
+	 */
+	spin_lock(&sysfs_lock);
+	spin_lock(&dcache_lock);
+
+	/* dget dentry if it's still alive */
+	if (sd->s_dentry && sd->s_dentry->d_inode)
+		dentry = dget_locked(sd->s_dentry);
+
+	spin_unlock(&dcache_lock);
+	spin_unlock(&sysfs_lock);
+
+	/* drop dentry */
 	if (dentry) {
 		spin_lock(&dcache_lock);
 		spin_lock(&dentry->d_lock);
-		if (!(d_unhashed(dentry) && dentry->d_inode)) {
+		if (!d_unhashed(dentry) && dentry->d_inode) {
 			inode = dentry->d_inode;
 			spin_lock(&inode->i_lock);
 			__iget(inode);
@@ -267,6 +282,8 @@
 			spin_unlock(&dentry->d_lock);
 			spin_unlock(&dcache_lock);
 		}
+
+		dput(dentry);
 	}
 }
 
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 23a48a3..00ab912 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -33,6 +33,7 @@
 	.s_element	= NULL,
 	.s_type		= SYSFS_ROOT,
 	.s_iattr	= NULL,
+	.s_ino		= 1,
 };
 
 static void sysfs_clear_inode(struct inode *inode)
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index a77c57e..502c949 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -5,6 +5,7 @@
 	void 			* s_element;
 	int			s_type;
 	umode_t			s_mode;
+	ino_t			s_ino;
 	struct dentry		* s_dentry;
 	struct iattr		* s_iattr;
 	atomic_t		s_event;
@@ -32,6 +33,7 @@
 extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent);
 extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
 
+extern spinlock_t sysfs_lock;
 extern struct rw_semaphore sysfs_rename_sem;
 extern struct super_block * sysfs_sb;
 extern const struct file_operations sysfs_dir_operations;
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 1f01294..bf7de0b 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -100,14 +100,23 @@
 	clear_inode(inode);
 }
 
+/*
+ * If we are going to release inode from memory, we discard preallocation and
+ * truncate last inode extent to proper length. We could use drop_inode() but
+ * it's called under inode_lock and thus we cannot mark inode dirty there.  We
+ * use clear_inode() but we have to make sure to write inode as it's not written
+ * automatically.
+ */
 void udf_clear_inode(struct inode *inode)
 {
 	if (!(inode->i_sb->s_flags & MS_RDONLY)) {
 		lock_kernel();
+		/* Discard preallocation for directories, symlinks, etc. */
 		udf_discard_prealloc(inode);
+		udf_truncate_tail_extent(inode);
 		unlock_kernel();
+		write_inode_now(inode, 1);
 	}
-
 	kfree(UDF_I_DATA(inode));
 	UDF_I_DATA(inode) = NULL;
 }
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c
index 77975ae..60d2776 100644
--- a/fs/udf/truncate.c
+++ b/fs/udf/truncate.c
@@ -61,7 +61,11 @@
 	}
 }
 
-void udf_discard_prealloc(struct inode * inode)
+/*
+ * Truncate the last extent to match i_size. This function assumes
+ * that preallocation extent is already truncated.
+ */
+void udf_truncate_tail_extent(struct inode *inode)
 {
 	struct extent_position epos = { NULL, 0, {0, 0}};
 	kernel_lb_addr eloc;
@@ -71,6 +75,62 @@
 	int adsize;
 
 	if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
+	    inode->i_size == UDF_I_LENEXTENTS(inode))
+		return;
+	/* Are we going to delete the file anyway? */
+	if (inode->i_nlink == 0)
+		return;
+
+	if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+		adsize = sizeof(short_ad);
+	else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+		adsize = sizeof(long_ad);
+	else
+		BUG();
+
+	/* Find the last extent in the file */
+	while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1)
+	{
+		etype = netype;
+		lbcount += elen;
+		if (lbcount > inode->i_size) {
+			if (lbcount - inode->i_size >= inode->i_sb->s_blocksize)
+				printk(KERN_WARNING
+				       "udf_truncate_tail_extent(): Too long "
+				       "extent after EOF in inode %u: i_size: "
+				       "%Ld lbcount: %Ld extent %u+%u\n",
+				       (unsigned)inode->i_ino,
+				       (long long)inode->i_size,
+				       (long long)lbcount,
+				       (unsigned)eloc.logicalBlockNum,
+				       (unsigned)elen);
+			nelen = elen - (lbcount - inode->i_size);
+			epos.offset -= adsize;
+			extent_trunc(inode, &epos, eloc, etype, elen, nelen);
+			epos.offset += adsize;
+			if (udf_next_aext(inode, &epos, &eloc, &elen, 1) != -1)
+				printk(KERN_ERR "udf_truncate_tail_extent(): "
+				       "Extent after EOF in inode %u.\n",
+				       (unsigned)inode->i_ino);
+			break;
+		}
+	}
+	/* This inode entry is in-memory only and thus we don't have to mark
+	 * the inode dirty */
+	UDF_I_LENEXTENTS(inode) = inode->i_size;
+	brelse(epos.bh);
+}
+
+void udf_discard_prealloc(struct inode *inode)
+{
+	struct extent_position epos = { NULL, 0, {0, 0}};
+	kernel_lb_addr eloc;
+	uint32_t elen;
+	uint64_t lbcount = 0;
+	int8_t etype = -1, netype;
+	int adsize;
+
+	if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
 		inode->i_size == UDF_I_LENEXTENTS(inode))
 		return;
 
@@ -84,31 +144,18 @@
 	epos.block = UDF_I_LOCATION(inode);
 
 	/* Find the last extent in the file */
-	while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1)
-	{
+	while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
 		etype = netype;
 		lbcount += elen;
-		if (lbcount > inode->i_size && lbcount - elen < inode->i_size)
-		{
-			WARN_ON(lbcount - inode->i_size >= inode->i_sb->s_blocksize);
-			nelen = elen - (lbcount - inode->i_size);
-			epos.offset -= adsize;
-			extent_trunc(inode, &epos, eloc, etype, elen, nelen);
-			epos.offset += adsize;
-			lbcount = inode->i_size;
-		}
 	}
 	if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
 		epos.offset -= adsize;
 		lbcount -= elen;
 		extent_trunc(inode, &epos, eloc, etype, elen, 0);
-		if (!epos.bh)
-		{
+		if (!epos.bh) {
 			UDF_I_LENALLOC(inode) = epos.offset - udf_file_entry_alloc_offset(inode);
 			mark_inode_dirty(inode);
-		}
-		else
-		{
+		} else {
 			struct allocExtDesc *aed = (struct allocExtDesc *)(epos.bh->b_data);
 			aed->lengthAllocDescs = cpu_to_le32(epos.offset - sizeof(struct allocExtDesc));
 			if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
@@ -118,9 +165,9 @@
 			mark_buffer_dirty_inode(epos.bh, inode);
 		}
 	}
+	/* This inode entry is in-memory only and thus we don't have to mark
+	 * the inode dirty */
 	UDF_I_LENEXTENTS(inode) = lbcount;
-
-	WARN_ON(lbcount != inode->i_size);
 	brelse(epos.bh);
 }
 
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index 67ded28..f581f2f 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -146,6 +146,7 @@
 extern struct inode * udf_new_inode (struct inode *, int, int *);
 
 /* truncate.c */
+extern void udf_truncate_tail_extent(struct inode *);
 extern void udf_discard_prealloc(struct inode *);
 extern void udf_truncate_extents(struct inode *);
 
diff --git a/include/asm-arm/arch-s3c2410/anubis-cpld.h b/include/asm-arm/arch-s3c2410/anubis-cpld.h
index dcebf6d..168b93f 100644
--- a/include/asm-arm/arch-s3c2410/anubis-cpld.h
+++ b/include/asm-arm/arch-s3c2410/anubis-cpld.h
@@ -18,4 +18,8 @@
 
 #define ANUBIS_CTRL1_NANDSEL		(0x3)
 
+/* IDREG - revision */
+
+#define ANUBIS_IDREG_REVMASK		(0x7)
+
 #endif /* __ASM_ARCH_ANUBISCPLD_H */
diff --git a/include/asm-arm/arch-s3c2410/anubis-map.h b/include/asm-arm/arch-s3c2410/anubis-map.h
index ab076de..830d114 100644
--- a/include/asm-arm/arch-s3c2410/anubis-map.h
+++ b/include/asm-arm/arch-s3c2410/anubis-map.h
@@ -27,14 +27,8 @@
 #define ANUBIS_VA_CTRL1	    ANUBIS_IOADDR(0x00000000)	 /* 0x01800000 */
 #define ANUBIS_PA_CTRL1	    (ANUBIS_PA_CPLD)
 
-#define ANUBIS_VA_CTRL2	    ANUBIS_IOADDR(0x00100000)	 /* 0x01900000 */
-#define ANUBIS_PA_CTRL2	    (ANUBIS_PA_CPLD)
-
-#define ANUBIS_VA_CTRL3	    ANUBIS_IOADDR(0x00200000)	 /* 0x01A00000 */
-#define ANUBIS_PA_CTRL3	    (ANUBIS_PA_CPLD)
-
-#define ANUBIS_VA_CTRL4	    ANUBIS_IOADDR(0x00300000)	 /* 0x01B00000 */
-#define ANUBIS_PA_CTRL4	    (ANUBIS_PA_CPLD)
+#define ANUBIS_VA_IDREG	    ANUBIS_IOADDR(0x00300000)	 /* 0x01B00000 */
+#define ANUBIS_PA_IDREG	    (ANUBIS_PA_CPLD + (3<<23))
 
 #define ANUBIS_IDEPRI	    ANUBIS_IOADDR(0x01000000)
 #define ANUBIS_IDEPRIAUX    ANUBIS_IOADDR(0x01100000)
diff --git a/include/asm-arm/arch-s3c2410/osiris-cpld.h b/include/asm-arm/arch-s3c2410/osiris-cpld.h
index 3b64984..229ab23 100644
--- a/include/asm-arm/arch-s3c2410/osiris-cpld.h
+++ b/include/asm-arm/arch-s3c2410/osiris-cpld.h
@@ -1,6 +1,6 @@
 /* linux/include/asm-arm/arch-s3c2410/osiris-cpld.h
  *
- * Copyright (c) 2005 Simtec Electronics
+ * Copyright 2005 Simtec Electronics
  *	http://www.simtec.co.uk/products/
  *	Ben Dooks <ben@simtec.co.uk>
  *
@@ -14,12 +14,17 @@
 #ifndef __ASM_ARCH_OSIRISCPLD_H
 #define __ASM_ARCH_OSIRISCPLD_H
 
-/* CTRL1 - NAND WP control */
+/* CTRL0 - NAND WP control */
 
-#define OSIRIS_CTRL1_NANDSEL		(0x3)
-#define OSIRIS_CTRL1_BOOT_INT		(1<<3)
-#define OSIRIS_CTRL1_PCMCIA		(1<<4)
-#define OSIRIS_CTRL1_PCMCIA_nWAIT	(1<<6)
-#define OSIRIS_CTRL1_PCMCIA_nIOIS16	(1<<7)
+#define OSIRIS_CTRL0_NANDSEL		(0x3)
+#define OSIRIS_CTRL0_BOOT_INT		(1<<3)
+#define OSIRIS_CTRL0_PCMCIA		(1<<4)
+#define OSIRIS_CTRL0_FIX8		(1<<5)
+#define OSIRIS_CTRL0_PCMCIA_nWAIT	(1<<6)
+#define OSIRIS_CTRL0_PCMCIA_nIOIS16	(1<<7)
+
+#define OSIRIS_CTRL1_FIX8		(1<<0)
+
+#define OSIRIS_ID_REVMASK		(0x7)
 
 #endif /* __ASM_ARCH_OSIRISCPLD_H */
diff --git a/include/asm-arm/arch-s3c2410/osiris-map.h b/include/asm-arm/arch-s3c2410/osiris-map.h
index a14164d..b5c74d2 100644
--- a/include/asm-arm/arch-s3c2410/osiris-map.h
+++ b/include/asm-arm/arch-s3c2410/osiris-map.h
@@ -24,16 +24,19 @@
 
 /* we put the CPLD registers next, to get them out of the way */
 
-#define OSIRIS_VA_CTRL1	    OSIRIS_IOADDR(0x00000000)
-#define OSIRIS_PA_CTRL1	    (OSIRIS_PA_CPLD)
+#define OSIRIS_VA_CTRL0		OSIRIS_IOADDR(0x00000000)
+#define OSIRIS_PA_CTRL0		(OSIRIS_PA_CPLD)
 
-#define OSIRIS_VA_CTRL2	    OSIRIS_IOADDR(0x00100000)
-#define OSIRIS_PA_CTRL2	    (OSIRIS_PA_CPLD + (1<<23))
+#define OSIRIS_VA_CTRL1		OSIRIS_IOADDR(0x00100000)
+#define OSIRIS_PA_CTRL1		(OSIRIS_PA_CPLD + (1<<23))
 
-#define OSIRIS_VA_CTRL3	    OSIRIS_IOADDR(0x00200000)
-#define OSIRIS_PA_CTRL3	    (OSIRIS_PA_CPLD + (2<<23))
+#define OSIRIS_VA_CTRL2		OSIRIS_IOADDR(0x00200000)
+#define OSIRIS_PA_CTRL2		(OSIRIS_PA_CPLD + (2<<23))
 
-#define OSIRIS_VA_CTRL4	    OSIRIS_IOADDR(0x00300000)
-#define OSIRIS_PA_CTRL4	    (OSIRIS_PA_CPLD + (3<<23))
+#define OSIRIS_VA_CTRL3		OSIRIS_IOADDR(0x00300000)
+#define OSIRIS_PA_CTRL3		(OSIRIS_PA_CPLD + (2<<23))
+
+#define OSIRIS_VA_IDREG		OSIRIS_IOADDR(0x00700000)
+#define OSIRIS_PA_IDREG		(OSIRIS_PA_CPLD + (7<<23))
 
 #endif /* __ASM_ARCH_OSIRISMAP_H */
diff --git a/include/asm-arm/linkage.h b/include/asm-arm/linkage.h
index dbe4b4e..5a25632 100644
--- a/include/asm-arm/linkage.h
+++ b/include/asm-arm/linkage.h
@@ -4,4 +4,8 @@
 #define __ALIGN .align 0
 #define __ALIGN_STR ".align 0"
 
+#define ENDPROC(name) \
+  .type name, %function; \
+  END(name)
+
 #endif
diff --git a/include/asm-avr32/arch-at32ap/gpio.h b/include/asm-avr32/arch-at32ap/gpio.h
index 80a21aa..af7f953 100644
--- a/include/asm-avr32/arch-at32ap/gpio.h
+++ b/include/asm-avr32/arch-at32ap/gpio.h
@@ -14,6 +14,8 @@
 int gpio_get_value(unsigned int gpio);
 void gpio_set_value(unsigned int gpio, int value);
 
+#include <asm-generic/gpio.h>		/* cansleep wrappers */
+
 static inline int gpio_to_irq(unsigned int gpio)
 {
 	return gpio + GPIO_IRQ_BASE;
diff --git a/include/asm-avr32/cache.h b/include/asm-avr32/cache.h
index dabb955..d3cf35a 100644
--- a/include/asm-avr32/cache.h
+++ b/include/asm-avr32/cache.h
@@ -4,6 +4,15 @@
 #define L1_CACHE_SHIFT 5
 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
 
+/*
+ * Memory returned by kmalloc() may be used for DMA, so we must make
+ * sure that all such allocations are cache aligned. Otherwise,
+ * unrelated code may cause parts of the buffer to be read into the
+ * cache before the transfer is done, causing old data to be seen by
+ * the CPU.
+ */
+#define ARCH_KMALLOC_MINALIGN	L1_CACHE_BYTES
+
 #ifndef __ASSEMBLER__
 struct cache_info {
 	unsigned int ways;
diff --git a/include/asm-blackfin/blackfin.h b/include/asm-blackfin/blackfin.h
index 14e58de..db3b615 100644
--- a/include/asm-blackfin/blackfin.h
+++ b/include/asm-blackfin/blackfin.h
@@ -6,7 +6,11 @@
 #ifndef _BLACKFIN_H_
 #define _BLACKFIN_H_
 
-#include <asm/macros.h>
+#define LO(con32) ((con32) & 0xFFFF)
+#define lo(con32) ((con32) & 0xFFFF)
+#define HI(con32) (((con32) >> 16) & 0xFFFF)
+#define hi(con32) (((con32) >> 16) & 0xFFFF)
+
 #include <asm/mach/blackfin.h>
 #include <asm/bfin-global.h>
 
diff --git a/include/asm-blackfin/gpio.h b/include/asm-blackfin/gpio.h
index aa0d550..d98d77a 100644
--- a/include/asm-blackfin/gpio.h
+++ b/include/asm-blackfin/gpio.h
@@ -332,6 +332,7 @@
 	unsigned short inen;
 
 	unsigned short fer;
+	unsigned short reserved;
 };
 #endif /*CONFIG_PM*/
 
diff --git a/include/asm-blackfin/mach-common/def_LPBlackfin.h b/include/asm-blackfin/mach-common/def_LPBlackfin.h
index 7610352..be1ece8 100644
--- a/include/asm-blackfin/mach-common/def_LPBlackfin.h
+++ b/include/asm-blackfin/mach-common/def_LPBlackfin.h
@@ -42,6 +42,12 @@
 
 #if defined(ANOMALY_05000198)
 
+#define bfin_read8(addr) ({ unsigned char __v; \
+		__asm__ __volatile__ ("NOP;\n\t" \
+			"%0 = b[%1] (z);\n\t" \
+			: "=d"(__v) : "a"(addr)); \
+		__v; })
+
 #define bfin_read16(addr) ({ unsigned __v; \
                        __asm__ __volatile__ ("NOP;\n\t"\
 	         			     			"%0 = w[%1] (z);\n\t"\
@@ -52,6 +58,11 @@
                                             "%0 = [%1];\n\t"\
   : "=d"(__v) : "a"(addr)); __v; })
 
+#define bfin_write8(addr, val) ({ \
+		__asm__ __volatile__ ("NOP;\n\t" \
+			"b[%0] = %1;\n\t" \
+			: : "a"(addr), "d"(val) : "memory");})
+
 #define bfin_write16(addr,val) ({\
                       __asm__ __volatile__ ("NOP;\n\t"\
                                             "w[%0] = %1;\n\t"\
@@ -64,6 +75,12 @@
 
 #else
 
+#define bfin_read8(addr) ({ unsigned char __v; \
+		__asm__ __volatile__ ( \
+			"%0 = b[%1] (z);\n\t" \
+			:"=d"(__v) : "a"(addr)); \
+		__v; })
+
 #define bfin_read16(addr) ({ unsigned __v; \
                        __asm__ __volatile__ (\
 	         			     			"%0 = w[%1] (z);\n\t"\
@@ -74,6 +91,11 @@
                                             "%0 = [%1];\n\t"\
   : "=d"(__v) : "a"(addr)); __v; })
 
+#define bfin_write8(addr, val) ({ \
+		__asm__ __volatile__ ( \
+			"b[%0] = %1; \n\t" \
+			::"a"(addr), "d"(val) : "memory");})
+
 #define bfin_write16(addr,val) ({\
                       __asm__ __volatile__ (\
                                             "w[%0] = %1;\n\t"\
diff --git a/include/asm-blackfin/macros.h b/include/asm-blackfin/macros.h
index c0c04a2..e69de29 100644
--- a/include/asm-blackfin/macros.h
+++ b/include/asm-blackfin/macros.h
@@ -1,95 +0,0 @@
-/************************************************************************
- *
- * macros.h
- *
- * (c) Copyright 2001-2003 Analog Devices, Inc.  All rights reserved.
- *
- ************************************************************************/
-
-/* Defines various assembly macros. */
-
-#ifndef _MACROS_H
-#define _MACROS_H
-
-#define LO(con32) ((con32) & 0xFFFF)
-#define lo(con32) ((con32) & 0xFFFF)
-#define HI(con32) (((con32) >> 16) & 0xFFFF)
-#define hi(con32) (((con32) >> 16) & 0xFFFF)
-
-/*
- * Set the corresponding bits in a System Register (SR);
- * All bits set in "mask" will be set in the system register
- * specified by "sys_reg" bitset_SR(sys_reg, mask), where
- * sys_reg is the system register and mask are the bits to be set.
- */
-#define bitset_SR(sys_reg, mask)\
-		[--SP] = (R7:6);\
-		r7 = sys_reg;\
-		r6.l = (mask) & 0xffff;\
-		r6.h = (mask) >> 16;\
-		r7 = r7 | r6;\
-		sys_reg = r7;\
-		csync;\
-		(R7:6) = [SP++]
-
-/*
- * Clear the corresponding bits in a System Register (SR);
- * All bits set in "mask" will be cleared in the SR
- * specified by "sys_reg" bitclr_SR(sys_reg, mask), where
- * sys_reg is the SR and mask are the bits to be cleared.
- */
-#define bitclr_SR(sys_reg, mask)\
-		[--SP] = (R7:6);\
-		r7 = sys_reg;\
-		r7 =~ r7;\
-		r6.l = (mask) & 0xffff;\
-		r6.h = (mask) >> 16;\
-		r7 = r7 | r6;\
-		r7 =~ r7;\
-		sys_reg = r7;\
-		csync;\
-		(R7:6) = [SP++]
-
-/*
- * Set the corresponding bits in a Memory Mapped Register (MMR);
- * All bits set in "mask" will be set in the MMR specified by "mmr_reg"
- * bitset_MMR(mmr_reg, mask), where mmr_reg is the MMR and mask are
- * the bits to be set.
- */
-#define bitset_MMR(mmr_reg, mask)\
-		[--SP] = (R7:6);\
-		[--SP] = P5;\
-		p5.l = mmr_reg & 0xffff;\
-		p5.h = mmr_reg >> 16;\
-		r7 = [p5];\
-		r6.l = (mask) & 0xffff;\
-		r6.h = (mask) >> 16;\
-		r7 = r7 | r6;\
-		[p5] = r7;\
-		csync;\
-		p5 = [SP++];\
-		(R7:6) = [SP++]
-
-/*
- * Clear the corresponding bits in a Memory Mapped Register (MMR);
- * All bits set in "mask" will be cleared in the MMR specified by "mmr_reg"
- * bitclr_MMRreg(mmr_reg, mask), where sys_reg is the MMR and mask are
- * the bits to be cleared.
- */
-#define bitclr_MMR(mmr_reg, mask)\
-		[--SP] = (R7:6);\
-		[--SP] = P5;\
-		p5.l = mmr_reg & 0xffff;\
-		p5.h = mmr_reg >> 16;\
-		r7 = [p5];\
-		r7 =~ r7;\
-		r6.l = (mask) & 0xffff;\
-		r6.h = (mask) >> 16;\
-		r7 = r7 | r6;\
-		r7 =~ r7;\
-		[p5] = r7;\
-		csync;\
-		p5 = [SP++];\
-		(R7:6) = [SP++]
-
-#endif				/* _MACROS_H */
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index dc8f99e..7d7bcf9 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -27,13 +27,20 @@
  * Largely same as above, but only sets the access flags (dirty,
  * accessed, and writable). Furthermore, we know it always gets set
  * to a "more permissive" setting, which allows most architectures
- * to optimize this.
+ * to optimize this. We return whether the PTE actually changed, which
+ * in turn instructs the caller to do things like update__mmu_cache.
+ * This used to be done in the caller, but sparc needs minor faults to
+ * force that call on sun4c so we changed this macro slightly
  */
 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-do {				  					  \
-	set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry);	  \
-	flush_tlb_page(__vma, __address);				  \
-} while (0)
+({									  \
+	int __changed = !pte_same(*(__ptep), __entry);			  \
+	if (__changed) {						  \
+		set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
+		flush_tlb_page(__vma, __address);			  \
+	}								  \
+	__changed;							  \
+})
 #endif
 
 #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
diff --git a/include/asm-i386/pgtable.h b/include/asm-i386/pgtable.h
index 2394589..628fa77 100644
--- a/include/asm-i386/pgtable.h
+++ b/include/asm-i386/pgtable.h
@@ -285,32 +285,36 @@
  */
 #define  __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 #define ptep_set_access_flags(vma, address, ptep, entry, dirty)		\
-do {									\
-	if (dirty) {							\
+({									\
+	int __changed = !pte_same(*(ptep), entry);			\
+	if (__changed && dirty) {					\
 		(ptep)->pte_low = (entry).pte_low;			\
 		pte_update_defer((vma)->vm_mm, (address), (ptep));	\
 		flush_tlb_page(vma, address);				\
 	}								\
-} while (0)
+	__changed;							\
+})
 
 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
 #define ptep_test_and_clear_dirty(vma, addr, ptep) ({			\
-	int ret = 0;							\
-	if (pte_dirty(*ptep))						\
-		ret = test_and_clear_bit(_PAGE_BIT_DIRTY, &ptep->pte_low); \
-	if (ret)							\
-		pte_update_defer(vma->vm_mm, addr, ptep);		\
-	ret;								\
+	int __ret = 0;							\
+	if (pte_dirty(*(ptep)))						\
+		__ret = test_and_clear_bit(_PAGE_BIT_DIRTY,		\
+						&(ptep)->pte_low);	\
+	if (__ret)							\
+		pte_update((vma)->vm_mm, addr, ptep);			\
+	__ret;								\
 })
 
 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
 #define ptep_test_and_clear_young(vma, addr, ptep) ({			\
-	int ret = 0;							\
-	if (pte_young(*ptep))						\
-		ret = test_and_clear_bit(_PAGE_BIT_ACCESSED, &ptep->pte_low); \
-	if (ret)							\
-		pte_update_defer(vma->vm_mm, addr, ptep);		\
-	ret;								\
+	int __ret = 0;							\
+	if (pte_young(*(ptep)))						\
+		__ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,		\
+						&(ptep)->pte_low);	\
+	if (__ret)							\
+		pte_update((vma)->vm_mm, addr, ptep);			\
+	__ret;								\
 })
 
 /*
diff --git a/include/asm-ia64/pgtable.h b/include/asm-ia64/pgtable.h
index 670b706..6580f31 100644
--- a/include/asm-ia64/pgtable.h
+++ b/include/asm-ia64/pgtable.h
@@ -533,16 +533,23 @@
  * daccess_bit in ivt.S).
  */
 #ifdef CONFIG_SMP
-# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable)	\
-do {											\
-	if (__safely_writable) {							\
-		set_pte(__ptep, __entry);						\
-		flush_tlb_page(__vma, __addr);						\
-	}										\
-} while (0)
+# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable) \
+({									\
+	int __changed = !pte_same(*(__ptep), __entry);			\
+	if (__changed && __safely_writable) {				\
+		set_pte(__ptep, __entry);				\
+		flush_tlb_page(__vma, __addr);				\
+	}								\
+	__changed;							\
+})
 #else
-# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable)	\
-	ptep_establish(__vma, __addr, __ptep, __entry)
+# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable) \
+({									\
+	int __changed = !pte_same(*(__ptep), __entry);			\
+	if (__changed)							\
+		ptep_establish(__vma, __addr, __ptep, __entry);		\
+	__changed;							\
+})
 #endif
 
 #  ifdef CONFIG_VIRTUAL_MEM_MAP
diff --git a/include/asm-mips/mips-boards/generic.h b/include/asm-mips/mips-boards/generic.h
index b98f165..c8ebcc3 100644
--- a/include/asm-mips/mips-boards/generic.h
+++ b/include/asm-mips/mips-boards/generic.h
@@ -73,12 +73,28 @@
  *  CoreEMUL with   Bonito   System Controller is treated like a Core20K
  *  CoreEMUL with SOC-it 101 System Controller is treated like a CoreMSC
  */
-#define MIPS_REVISION_CORID_CORE_EMUL_BON  0x63
-#define MIPS_REVISION_CORID_CORE_EMUL_MSC  0x65
+#define MIPS_REVISION_CORID_CORE_EMUL_BON  -1
+#define MIPS_REVISION_CORID_CORE_EMUL_MSC  -2
 
 #define MIPS_REVISION_CORID (((*(volatile u32 *)ioremap(MIPS_REVISION_REG, 4)) >> 10) & 0x3f)
 
-extern unsigned int mips_revision_corid;
+extern int mips_revision_corid;
+
+#define MIPS_REVISION_SCON_OTHER	   0
+#define MIPS_REVISION_SCON_SOCITSC	   1
+#define MIPS_REVISION_SCON_SOCITSCP	   2
+
+/* Artificial SCON defines for MIPS_REVISION_SCON_OTHER */
+#define MIPS_REVISION_SCON_UNKNOWN	   -1
+#define MIPS_REVISION_SCON_GT64120	   -2
+#define MIPS_REVISION_SCON_BONITO	   -3
+#define MIPS_REVISION_SCON_BRTL		   -4
+#define MIPS_REVISION_SCON_SOCIT	   -5
+#define MIPS_REVISION_SCON_ROCIT	   -6
+
+#define MIPS_REVISION_SCONID (((*(volatile u32 *)ioremap(MIPS_REVISION_REG, 4)) >> 24) & 0xff)
+
+extern int mips_revision_sconid;
 
 #ifdef CONFIG_PCI
 extern void mips_pcibios_init(void);
diff --git a/include/asm-mips/mips-boards/msc01_pci.h b/include/asm-mips/mips-boards/msc01_pci.h
index 8eaefb8..e036b7d 100644
--- a/include/asm-mips/mips-boards/msc01_pci.h
+++ b/include/asm-mips/mips-boards/msc01_pci.h
@@ -208,6 +208,7 @@
  * latter, they should be moved elsewhere.
  */
 #define MIPS_MSC01_PCI_REG_BASE		0x1bd00000
+#define MIPS_SOCITSC_PCI_REG_BASE	0x1ff10000
 
 extern unsigned long _pcictrl_msc;
 
diff --git a/include/asm-parisc/hardware.h b/include/asm-parisc/hardware.h
index 76d880d..4e96268 100644
--- a/include/asm-parisc/hardware.h
+++ b/include/asm-parisc/hardware.h
@@ -31,10 +31,11 @@
 	pcxw	= 8, /* pa8500		pa 2.0  */
 	pcxw_	= 9, /* pa8600	(w+)	pa 2.0  */
 	pcxw2	= 10, /* pa8700		pa 2.0  */
-	mako	= 11  /* pa8800		pa 2.0  */
+	mako	= 11, /* pa8800		pa 2.0  */
+	mako2	= 12  /* pa8900		pa 2.0  */
 };
 
-extern char *cpu_name_version[][2]; /* mapping from enum cpu_type to strings */
+extern const char * const cpu_name_version[][2]; /* mapping from enum cpu_type to strings */
 
 struct parisc_driver;
 
diff --git a/include/asm-parisc/linkage.h b/include/asm-parisc/linkage.h
index 7a09d91..ad8cd0d 100644
--- a/include/asm-parisc/linkage.h
+++ b/include/asm-parisc/linkage.h
@@ -8,8 +8,10 @@
 
 /*
  * In parisc assembly a semicolon marks a comment while a
- * exclamation mark is used to seperate independend lines.
+ * exclamation mark is used to seperate independent lines.
  */
+#ifdef __ASSEMBLY__
+
 #define ENTRY(name) \
 	.export name !\
 	ALIGN !\
@@ -24,5 +26,6 @@
 	END(name)
 #endif
 
+#endif /* __ASSEMBLY__ */
 
 #endif  /* __ASM_PARISC_LINKAGE_H */
diff --git a/include/asm-parisc/processor.h b/include/asm-parisc/processor.h
index d2f3967..6b294fb 100644
--- a/include/asm-parisc/processor.h
+++ b/include/asm-parisc/processor.h
@@ -69,8 +69,8 @@
 		char   sys_model_name[81]; /* PDC-ROM returnes this model name */
 	} pdc;
 
-	char		*cpu_name;	/* e.g. "PA7300LC (PCX-L2)" */
-	char		*family_name;	/* e.g. "1.1e" */
+	const char	*cpu_name;	/* e.g. "PA7300LC (PCX-L2)" */
+	const char	*family_name;	/* e.g. "1.1e" */
 };
 
 
@@ -334,8 +334,8 @@
 static inline int parisc_requires_coherency(void)
 {
 #ifdef CONFIG_PA8X00
-	/* FIXME: also pa8900 - when we see one */
-	return boot_cpu_data.cpu_type == mako;
+	return (boot_cpu_data.cpu_type == mako) ||
+		(boot_cpu_data.cpu_type == mako2);
 #else
 	return 0;
 #endif
diff --git a/include/asm-parisc/unistd.h b/include/asm-parisc/unistd.h
index 2f7c408..f74099b 100644
--- a/include/asm-parisc/unistd.h
+++ b/include/asm-parisc/unistd.h
@@ -792,8 +792,19 @@
 #define __NR_epoll_pwait	(__NR_Linux + 297)
 #define __NR_statfs64		(__NR_Linux + 298)
 #define __NR_fstatfs64		(__NR_Linux + 299)
+#define __NR_kexec_load		(__NR_Linux + 300)
+#define __NR_utimensat		(__NR_Linux + 301)
+#define __NR_signalfd		(__NR_Linux + 302)
+#define __NR_timerfd		(__NR_Linux + 303)
+#define __NR_eventfd		(__NR_Linux + 304)
 
-#define __NR_Linux_syscalls     (__NR_fstatfs64 + 1)
+#define __NR_Linux_syscalls	(__NR_eventfd + 1)
+
+
+#define __IGNORE_select		/* newselect */
+#define __IGNORE_fadvise64	/* fadvise64_64 */
+#define __IGNORE_utimes		/* utime */
+
 
 #define HPUX_GATEWAY_ADDR       0xC0000004
 #define LINUX_GATEWAY_ADDR      0x100
diff --git a/include/asm-powerpc/pgtable-ppc32.h b/include/asm-powerpc/pgtable-ppc32.h
index c863bdb..7fb730c 100644
--- a/include/asm-powerpc/pgtable-ppc32.h
+++ b/include/asm-powerpc/pgtable-ppc32.h
@@ -673,10 +673,14 @@
 }
 
 #define  ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-	do {								   \
-		__ptep_set_access_flags(__ptep, __entry, __dirty);	   \
-		flush_tlb_page_nohash(__vma, __address);	       	   \
-	} while(0)
+({									   \
+	int __changed = !pte_same(*(__ptep), __entry);			   \
+	if (__changed) {						   \
+		__ptep_set_access_flags(__ptep, __entry, __dirty);    	   \
+		flush_tlb_page_nohash(__vma, __address);		   \
+	}								   \
+	__changed;							   \
+})
 
 /*
  * Macro to mark a page protection value as "uncacheable".
diff --git a/include/asm-powerpc/pgtable-ppc64.h b/include/asm-powerpc/pgtable-ppc64.h
index 704c4e6..3cfd98f 100644
--- a/include/asm-powerpc/pgtable-ppc64.h
+++ b/include/asm-powerpc/pgtable-ppc64.h
@@ -413,10 +413,14 @@
 	:"cc");
 }
 #define  ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-	do {								   \
-		__ptep_set_access_flags(__ptep, __entry, __dirty);	   \
-		flush_tlb_page_nohash(__vma, __address);	       	   \
-	} while(0)
+({									   \
+	int __changed = !pte_same(*(__ptep), __entry);			   \
+	if (__changed) {						   \
+		__ptep_set_access_flags(__ptep, __entry, __dirty);    	   \
+		flush_tlb_page_nohash(__vma, __address);		   \
+	}								   \
+	__changed;							   \
+})
 
 /*
  * Macro to mark a page protection value as "uncacheable".
diff --git a/include/asm-ppc/pgtable.h b/include/asm-ppc/pgtable.h
index bed452d..9d0ce9f 100644
--- a/include/asm-ppc/pgtable.h
+++ b/include/asm-ppc/pgtable.h
@@ -694,10 +694,14 @@
 }
 
 #define  ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-	do {								   \
-		__ptep_set_access_flags(__ptep, __entry, __dirty);	   \
-		flush_tlb_page_nohash(__vma, __address);	       	   \
-	} while(0)
+({									   \
+	int __changed = !pte_same(*(__ptep), __entry);			   \
+	if (__changed) {						   \
+		__ptep_set_access_flags(__ptep, __entry, __dirty);    	   \
+		flush_tlb_page_nohash(__vma, __address);		   \
+	}								   \
+	__changed;							   \
+})
 
 /*
  * Macro to mark a page protection value as "uncacheable".
diff --git a/include/asm-s390/pgtable.h b/include/asm-s390/pgtable.h
index 8fe8d42..0a307bb2 100644
--- a/include/asm-s390/pgtable.h
+++ b/include/asm-s390/pgtable.h
@@ -744,7 +744,12 @@
 }
 
 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-	ptep_establish(__vma, __address, __ptep, __entry)
+({									  \
+	int __changed = !pte_same(*(__ptep), __entry);			  \
+	if (__changed)							  \
+		ptep_establish(__vma, __address, __ptep, __entry);	  \
+	__changed;							  \
+})
 
 /*
  * Test and clear dirty bit in storage key.
diff --git a/include/asm-sparc/pgtable.h b/include/asm-sparc/pgtable.h
index 4f0a5ba..59229ae 100644
--- a/include/asm-sparc/pgtable.h
+++ b/include/asm-sparc/pgtable.h
@@ -446,6 +446,17 @@
 #define GET_IOSPACE(pfn)		(pfn >> (BITS_PER_LONG - 4))
 #define GET_PFN(pfn)			(pfn & 0x0fffffffUL)
 
+#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
+#define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
+({									  \
+	int __changed = !pte_same(*(__ptep), __entry);			  \
+	if (__changed) {						  \
+		set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
+		flush_tlb_page(__vma, __address);			  \
+	}								  \
+	(sparc_cpu_model == sun4c) || __changed;			  \
+})
+
 #include <asm-generic/pgtable.h>
 
 #endif /* !(__ASSEMBLY__) */
diff --git a/include/asm-sparc64/dma-mapping.h b/include/asm-sparc64/dma-mapping.h
index 4e21c2f..c58ec16 100644
--- a/include/asm-sparc64/dma-mapping.h
+++ b/include/asm-sparc64/dma-mapping.h
@@ -15,8 +15,7 @@
 static inline int
 dma_supported(struct device *dev, u64 mask)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	return pci_dma_supported(to_pci_dev(dev), mask);
 }
@@ -24,8 +23,7 @@
 static inline int
 dma_set_mask(struct device *dev, u64 dma_mask)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
 }
@@ -34,8 +32,7 @@
 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
 		   gfp_t flag)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	return pci_iommu_ops->alloc_consistent(to_pci_dev(dev), size, dma_handle, flag);
 }
@@ -44,8 +41,7 @@
 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
 		    dma_addr_t dma_handle)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
 }
@@ -54,8 +50,7 @@
 dma_map_single(struct device *dev, void *cpu_addr, size_t size,
 	       enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
 }
@@ -64,8 +59,7 @@
 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
 		 enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
 }
@@ -75,8 +69,7 @@
 	     unsigned long offset, size_t size,
 	     enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
 }
@@ -85,8 +78,7 @@
 dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
 	       enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
 }
@@ -95,8 +87,7 @@
 dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 	   enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
 }
@@ -105,8 +96,7 @@
 dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
 	     enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
 }
@@ -115,8 +105,7 @@
 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
 			enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
 				    size, (int)direction);
@@ -126,8 +115,7 @@
 dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
 			   enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
 				       size, (int)direction);
@@ -137,8 +125,7 @@
 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
 		    enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg, nelems, (int)direction);
 }
@@ -147,8 +134,7 @@
 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
 		       enum dma_data_direction direction)
 {
-	BUG_ON(dev->bus != &pci_bus_type &&
-	       dev->bus != &ebus_bus_type);
+	BUG_ON(dev->bus != &pci_bus_type);
 
 	pci_dma_sync_sg_for_device(to_pci_dev(dev), sg, nelems, (int)direction);
 }
diff --git a/include/asm-sparc64/hypervisor.h b/include/asm-sparc64/hypervisor.h
index 5c2f9d4..db2130a 100644
--- a/include/asm-sparc64/hypervisor.h
+++ b/include/asm-sparc64/hypervisor.h
@@ -2615,8 +2615,9 @@
 /* ldc_revoke()
  * TRAP:	HV_FAST_TRAP
  * FUNCTION:	HV_FAST_LDC_REVOKE
- * ARG0:	cookie
- * ARG1:	ldc_mtable_entry cookie
+ * ARG0:	channel ID
+ * ARG1:	cookie
+ * ARG2:	ldc_mtable_entry cookie
  * RET0:	status
  */
 #define HV_FAST_LDC_REVOKE		0xef
@@ -2663,7 +2664,8 @@
 				     unsigned long *ra,
 				     unsigned long *perm);
 extern unsigned long sun4v_ldc_unmap(unsigned long ra);
-extern unsigned long sun4v_ldc_revoke(unsigned long cookie,
+extern unsigned long sun4v_ldc_revoke(unsigned long channel,
+				      unsigned long cookie,
 				      unsigned long mte_cookie);
 #endif
 
diff --git a/include/asm-sparc64/irq.h b/include/asm-sparc64/irq.h
index 5d233b4..90781e3 100644
--- a/include/asm-sparc64/irq.h
+++ b/include/asm-sparc64/irq.h
@@ -46,6 +46,7 @@
 #define irq_canonicalize(irq)	(irq)
 extern unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap);
 extern unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino);
+extern unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino);
 extern unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
 				    unsigned int msi_devino_start,
 				    unsigned int msi_devino_end);
diff --git a/include/asm-sparc64/parport.h b/include/asm-sparc64/parport.h
index 6340a52..23cc63f 100644
--- a/include/asm-sparc64/parport.h
+++ b/include/asm-sparc64/parport.h
@@ -145,7 +145,7 @@
 			 */
 			if (parport_pc_probe_port(base, base + 0x400,
 						  child->irq, PARPORT_DMA_NOFIFO,
-						  child->bus->self))
+						  &child->bus->self->dev))
 				count++;
 		}
 	}
@@ -199,7 +199,8 @@
 
 				if (parport_pc_probe_port(base, base + 0x400,
 							  edev->irqs[0],
-							  count, ebus->self))
+							  count,
+							  &ebus->self->dev))
 					count++;
 			}
 		}
diff --git a/include/asm-um/a.out.h b/include/asm-um/a.out.h
index 50cee7b..7016b89 100644
--- a/include/asm-um/a.out.h
+++ b/include/asm-um/a.out.h
@@ -5,6 +5,7 @@
 #include "choose-mode.h"
 
 #undef STACK_TOP
+#undef STACK_TOP_MAX
 
 extern unsigned long stacksizelim;
 
diff --git a/include/asm-x86_64/pgtable.h b/include/asm-x86_64/pgtable.h
index 08b9831..0a71e0b 100644
--- a/include/asm-x86_64/pgtable.h
+++ b/include/asm-x86_64/pgtable.h
@@ -395,12 +395,14 @@
  * bit at the same time. */
 #define  __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-	do {								  \
-		if (__dirty) {						  \
-			set_pte(__ptep, __entry);			  \
-			flush_tlb_page(__vma, __address);		  \
-		}							  \
-	} while (0)
+({									  \
+	int __changed = !pte_same(*(__ptep), __entry);			  \
+	if (__changed && __dirty) {					  \
+		set_pte(__ptep, __entry);			  	  \
+		flush_tlb_page(__vma, __address);		  	  \
+	}								  \
+	__changed;							  \
+})
 
 /* Encode and de-code a swap entry */
 #define __swp_type(x)			(((x).val >> 1) & 0x3f)
diff --git a/include/linux/futex.h b/include/linux/futex.h
index 899fc7f..9965035 100644
--- a/include/linux/futex.h
+++ b/include/linux/futex.h
@@ -17,7 +17,6 @@
 #define FUTEX_LOCK_PI		6
 #define FUTEX_UNLOCK_PI		7
 #define FUTEX_TRYLOCK_PI	8
-#define FUTEX_CMP_REQUEUE_PI	9
 
 #define FUTEX_PRIVATE_FLAG	128
 #define FUTEX_CMD_MASK		~FUTEX_PRIVATE_FLAG
@@ -98,14 +97,9 @@
 #define FUTEX_OWNER_DIED	0x40000000
 
 /*
- * Some processes have been requeued on this PI-futex
- */
-#define FUTEX_WAITER_REQUEUED	0x20000000
-
-/*
  * The rest of the robust-futex field is for the TID:
  */
-#define FUTEX_TID_MASK		0x0fffffff
+#define FUTEX_TID_MASK		0x3fffffff
 
 /*
  * This limit protects against a deliberately circular list.
@@ -139,7 +133,6 @@
 #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */
 
 union futex_key {
-	u32 __user *uaddr;
 	struct {
 		unsigned long pgoff;
 		struct inode *inode;
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index b4570b6..2c13715 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -163,7 +163,7 @@
 
 extern const struct file_operations hugetlbfs_file_operations;
 extern struct vm_operations_struct hugetlb_vm_ops;
-struct file *hugetlb_zero_setup(size_t);
+struct file *hugetlb_file_setup(const char *name, size_t);
 int hugetlb_get_quota(struct address_space *mapping);
 void hugetlb_put_quota(struct address_space *mapping);
 
@@ -185,7 +185,7 @@
 
 #define is_file_hugepages(file)		0
 #define set_file_hugepages(file)	BUG()
-#define hugetlb_zero_setup(size)	ERR_PTR(-ENOSYS)
+#define hugetlb_file_setup(name,size)	ERR_PTR(-ENOSYS)
 
 #endif /* !CONFIG_HUGETLBFS */
 
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index c762954..2b139f6 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -261,6 +261,18 @@
 
 #endif
 
+/**
+ * ktime_equal - Compares two ktime_t variables to see if they are equal
+ * @cmp1:	comparable1
+ * @cmp2:	comparable2
+ *
+ * Compare two ktime_t variables, returns 1 if equal
+ */
+static inline int ktime_equal(const ktime_t cmp1, const ktime_t cmp2)
+{
+	return cmp1.tv64 == cmp2.tv64;
+}
+
 static inline s64 ktime_to_us(const ktime_t kt)
 {
 	struct timeval tv = ktime_to_timeval(kt);
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index e7367c7..6f0b2f7 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1579,6 +1579,10 @@
 	return ktime_sub(ktime_get_real(), t);
 }
 
+static inline ktime_t net_invalid_timestamp(void)
+{
+	return ktime_set(0, 0);
+}
 
 extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len);
 extern __sum16 __skb_checksum_complete(struct sk_buff *skb);
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index a0ad374..6207a3d 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -28,7 +28,7 @@
 	int size;		/* The size of an object including meta data */
 	int objsize;		/* The size of an object without meta data */
 	int offset;		/* Free pointer offset. */
-	unsigned int order;
+	int order;
 
 	/*
 	 * Avoid an extra cache line for UP, SMP and for the node local to
@@ -56,7 +56,13 @@
 /*
  * Kmalloc subsystem.
  */
-#define KMALLOC_SHIFT_LOW 3
+#if defined(ARCH_KMALLOC_MINALIGN) && ARCH_KMALLOC_MINALIGN > 8
+#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN
+#else
+#define KMALLOC_MIN_SIZE 8
+#endif
+
+#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE)
 
 /*
  * We keep the general caches in an array of slab caches that are used for
@@ -76,6 +82,9 @@
 	if (size > KMALLOC_MAX_SIZE)
 		return -1;
 
+	if (size <= KMALLOC_MIN_SIZE)
+		return KMALLOC_SHIFT_LOW;
+
 	if (size > 64 && size <= 96)
 		return 1;
 	if (size > 128 && size <= 192)
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index b6bedc3..1be5ea0 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -341,9 +341,14 @@
  * chip transactions together.
  *
  * (ii) When the transfer is the last one in the message, the chip may
- * stay selected until the next transfer.  This is purely a performance
- * hint; the controller driver may need to select a different device
- * for the next message.
+ * stay selected until the next transfer.  On multi-device SPI busses
+ * with nothing blocking messages going to other devices, this is just
+ * a performance hint; starting a message to another device deselects
+ * this one.  But in other cases, this can be used to ensure correctness.
+ * Some devices need protocol transactions to be built from a series of
+ * spi_message submissions, where the content of one message is determined
+ * by the results of previous messages and where the whole transaction
+ * ends when the chipselect goes intactive.
  *
  * The code that submits an spi_message (and its spi_transfers)
  * to the lower layers is responsible for managing its memory.
@@ -480,14 +485,15 @@
 /**
  * spi_setup - setup SPI mode and clock rate
  * @spi: the device whose settings are being modified
- * Context: can sleep
+ * Context: can sleep, and no requests are queued to the device
  *
  * SPI protocol drivers may need to update the transfer mode if the
- * device doesn't work with the mode 0 default.  They may likewise need
+ * device doesn't work with its default.  They may likewise need
  * to update clock rates or word sizes from initial values.  This function
  * changes those settings, and must be called from a context that can sleep.
- * The changes take effect the next time the device is selected and data
- * is transferred to or from it.
+ * Except for SPI_CS_HIGH, which takes effect immediately, the changes take
+ * effect the next time the device is selected and data is transferred to
+ * or from it.  When this function returns, the spi device is deselected.
  *
  * Note that this call will fail if the protocol driver specifies an option
  * that the underlying controller or its driver does not support.  For
diff --git a/include/net/irda/irlap.h b/include/net/irda/irlap.h
index f0248fb..a3d370e 100644
--- a/include/net/irda/irlap.h
+++ b/include/net/irda/irlap.h
@@ -289,4 +289,21 @@
 	self->disconnect_pending = FALSE;
 }
 
+/*
+ * Function irlap_next_state (self, state)
+ *
+ *    Switches state and provides debug information
+ *
+ */
+static inline void irlap_next_state(struct irlap_cb *self, IRLAP_STATE state)
+{
+	/*
+	if (!self || self->magic != LAP_MAGIC)
+		return;
+
+	IRDA_DEBUG(4, "next LAP state = %s\n", irlap_state[state]);
+	*/
+	self->state = state;
+}
+
 #endif
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index dda72bf..16baef4 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -503,6 +503,13 @@
 	return frag;
 }
 
+static inline void sctp_assoc_pending_pmtu(struct sctp_association *asoc)
+{
+
+	sctp_assoc_sync_pmtu(asoc);
+	asoc->pmtu_pending = 0;
+}
+
 /* Walk through a list of TLV parameters.  Don't trust the
  * individual parameter lengths and instead depend on
  * the chunk length to indicate when to stop.  Make sure
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 5e81984..ee4559b 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -912,6 +912,9 @@
 	 */
 	__u16 pathmaxrxt;
 
+	/* is the Path MTU update pending on this tranport */
+	__u8 pmtu_pending;
+
 	/* PMTU	      : The current known path MTU.  */
 	__u32 pathmtu;
 
@@ -1006,6 +1009,7 @@
 void sctp_transport_lower_cwnd(struct sctp_transport *, sctp_lower_cwnd_t);
 unsigned long sctp_transport_timeout(struct sctp_transport *);
 void sctp_transport_reset(struct sctp_transport *);
+void sctp_transport_update_pmtu(struct sctp_transport *, u32);
 
 
 /* This is the structure we use to queue packets as they come into
@@ -1565,6 +1569,9 @@
 	 */
 	__u16 pathmaxrxt;
 
+	/* Flag that path mtu update is pending */
+	__u8   pmtu_pending;
+
 	/* Association : The smallest PMTU discovered for all of the
 	 * PMTU	       : peer's transport addresses.
 	 */
diff --git a/ipc/shm.c b/ipc/shm.c
index 4fefbad..0852f20 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -254,8 +254,10 @@
 
 	if (sfd->vm_ops->get_policy)
 		pol = sfd->vm_ops->get_policy(vma, addr);
-	else
+	else if (vma->vm_policy)
 		pol = vma->vm_policy;
+	else
+		pol = current->mempolicy;
 	return pol;
 }
 #endif
@@ -364,9 +366,10 @@
 		return error;
 	}
 
+	sprintf (name, "SYSV%08x", key);
 	if (shmflg & SHM_HUGETLB) {
-		/* hugetlb_zero_setup takes care of mlock user accounting */
-		file = hugetlb_zero_setup(size);
+		/* hugetlb_file_setup takes care of mlock user accounting */
+		file = hugetlb_file_setup(name, size);
 		shp->mlock_user = current->user;
 	} else {
 		int acctflag = VM_ACCOUNT;
@@ -377,7 +380,6 @@
 		if  ((shmflg & SHM_NORESERVE) &&
 				sysctl_overcommit_memory != OVERCOMMIT_NEVER)
 			acctflag = 0;
-		sprintf (name, "SYSV%08x", key);
 		file = shmem_file_setup(name, size, acctflag);
 	}
 	error = PTR_ERR(file);
@@ -397,6 +399,11 @@
 	shp->shm_nattch = 0;
 	shp->id = shm_buildid(ns, id, shp->shm_perm.seq);
 	shp->shm_file = file;
+	/*
+	 * shmid gets reported as "inode#" in /proc/pid/maps.
+	 * proc-ps tools use this. Changing this will break them.
+	 */
+	file->f_dentry->d_inode->i_ino = shp->id;
 
 	ns->shm_tot += numpages;
 	shm_unlock(shp);
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index f57854b..4c49188 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1682,9 +1682,9 @@
 
 	do_each_thread(g, p) {
 		if (p->cpuset == cs) {
-			pidarray[n++] = p->pid;
 			if (unlikely(n == npids))
 				goto array_full;
+			pidarray[n++] = p->pid;
 		}
 	} while_each_thread(g, p);
 
diff --git a/kernel/futex.c b/kernel/futex.c
index 3b7f771..df248f5 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -56,12 +56,6 @@
 
 #include "rtmutex_common.h"
 
-#ifdef CONFIG_DEBUG_RT_MUTEXES
-# include "rtmutex-debug.h"
-#else
-# include "rtmutex.h"
-#endif
-
 #define FUTEX_HASHBITS (CONFIG_BASE_SMALL ? 4 : 8)
 
 /*
@@ -111,12 +105,6 @@
 	/* Optional priority inheritance state: */
 	struct futex_pi_state *pi_state;
 	struct task_struct *task;
-
-	/*
-	 * This waiter is used in case of requeue from a
-	 * normal futex to a PI-futex
-	 */
-	struct rt_mutex_waiter waiter;
 };
 
 /*
@@ -216,9 +204,6 @@
 	if (unlikely((vma->vm_flags & (VM_IO|VM_READ)) != VM_READ))
 		return (vma->vm_flags & VM_IO) ? -EPERM : -EACCES;
 
-	/* Save the user address in the ley */
-	key->uaddr = uaddr;
-
 	/*
 	 * Private mappings are handled in a simple way.
 	 *
@@ -636,8 +621,6 @@
 		int ret = 0;
 
 		newval = FUTEX_WAITERS | new_owner->pid;
-		/* Keep the FUTEX_WAITER_REQUEUED flag if it was set */
-		newval |= (uval & FUTEX_WAITER_REQUEUED);
 
 		pagefault_disable();
 		curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval);
@@ -750,259 +733,6 @@
 }
 
 /*
- * Called from futex_requeue_pi.
- * Set FUTEX_WAITERS and FUTEX_WAITER_REQUEUED flags on the
- * PI-futex value; search its associated pi_state if an owner exist
- * or create a new one without owner.
- */
-static inline int
-lookup_pi_state_for_requeue(u32 __user *uaddr, struct futex_hash_bucket *hb,
-			    union futex_key *key,
-			    struct futex_pi_state **pi_state)
-{
-	u32 curval, uval, newval;
-
-retry:
-	/*
-	 * We can't handle a fault cleanly because we can't
-	 * release the locks here. Simply return the fault.
-	 */
-	if (get_futex_value_locked(&curval, uaddr))
-		return -EFAULT;
-
-	/* set the flags FUTEX_WAITERS and FUTEX_WAITER_REQUEUED */
-	if ((curval & (FUTEX_WAITERS | FUTEX_WAITER_REQUEUED))
-	    != (FUTEX_WAITERS | FUTEX_WAITER_REQUEUED)) {
-		/*
-		 * No waiters yet, we prepare the futex to have some waiters.
-		 */
-
-		uval = curval;
-		newval = uval | FUTEX_WAITERS | FUTEX_WAITER_REQUEUED;
-
-		pagefault_disable();
-		curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval);
-		pagefault_enable();
-
-		if (unlikely(curval == -EFAULT))
-			return -EFAULT;
-		if (unlikely(curval != uval))
-			goto retry;
-	}
-
-	if (!(curval & FUTEX_TID_MASK)
-	    || lookup_pi_state(curval, hb, key, pi_state)) {
-		/* the futex has no owner (yet) or the lookup failed:
-		   allocate one pi_state without owner */
-
-		*pi_state = alloc_pi_state();
-
-		/* Already stores the key: */
-		(*pi_state)->key = *key;
-
-		/* init the mutex without owner */
-		__rt_mutex_init(&(*pi_state)->pi_mutex, NULL);
-	}
-
-	return 0;
-}
-
-/*
- * Keep the first nr_wake waiter from futex1, wake up one,
- * and requeue the next nr_requeue waiters following hashed on
- * one physical page to another physical page (PI-futex uaddr2)
- */
-static int futex_requeue_pi(u32 __user *uaddr1,
-			    struct rw_semaphore *fshared,
-			    u32 __user *uaddr2,
-			    int nr_wake, int nr_requeue, u32 *cmpval)
-{
-	union futex_key key1, key2;
-	struct futex_hash_bucket *hb1, *hb2;
-	struct plist_head *head1;
-	struct futex_q *this, *next;
-	struct futex_pi_state *pi_state2 = NULL;
-	struct rt_mutex_waiter *waiter, *top_waiter = NULL;
-	struct rt_mutex *lock2 = NULL;
-	int ret, drop_count = 0;
-
-	if (refill_pi_state_cache())
-		return -ENOMEM;
-
-retry:
-	/*
-	 * First take all the futex related locks:
-	 */
-	if (fshared)
-		down_read(fshared);
-
-	ret = get_futex_key(uaddr1, fshared, &key1);
-	if (unlikely(ret != 0))
-		goto out;
-	ret = get_futex_key(uaddr2, fshared, &key2);
-	if (unlikely(ret != 0))
-		goto out;
-
-	hb1 = hash_futex(&key1);
-	hb2 = hash_futex(&key2);
-
-	double_lock_hb(hb1, hb2);
-
-	if (likely(cmpval != NULL)) {
-		u32 curval;
-
-		ret = get_futex_value_locked(&curval, uaddr1);
-
-		if (unlikely(ret)) {
-			spin_unlock(&hb1->lock);
-			if (hb1 != hb2)
-				spin_unlock(&hb2->lock);
-
-			/*
-			 * If we would have faulted, release mmap_sem, fault
-			 * it in and start all over again.
-			 */
-			if (fshared)
-				up_read(fshared);
-
-			ret = get_user(curval, uaddr1);
-
-			if (!ret)
-				goto retry;
-
-			return ret;
-		}
-		if (curval != *cmpval) {
-			ret = -EAGAIN;
-			goto out_unlock;
-		}
-	}
-
-	head1 = &hb1->chain;
-	plist_for_each_entry_safe(this, next, head1, list) {
-		if (!match_futex (&this->key, &key1))
-			continue;
-		if (++ret <= nr_wake) {
-			wake_futex(this);
-		} else {
-			/*
-			 * FIRST: get and set the pi_state
-			 */
-			if (!pi_state2) {
-				int s;
-				/* do this only the first time we requeue someone */
-				s = lookup_pi_state_for_requeue(uaddr2, hb2,
-								&key2, &pi_state2);
-				if (s) {
-					ret = s;
-					goto out_unlock;
-				}
-
-				lock2 = &pi_state2->pi_mutex;
-				spin_lock(&lock2->wait_lock);
-
-				/* Save the top waiter of the wait_list */
-				if (rt_mutex_has_waiters(lock2))
-					top_waiter = rt_mutex_top_waiter(lock2);
-			} else
-				atomic_inc(&pi_state2->refcount);
-
-
-			this->pi_state = pi_state2;
-
-			/*
-			 * SECOND: requeue futex_q to the correct hashbucket
-			 */
-
-			/*
-			 * If key1 and key2 hash to the same bucket, no need to
-			 * requeue.
-			 */
-			if (likely(head1 != &hb2->chain)) {
-				plist_del(&this->list, &hb1->chain);
-				plist_add(&this->list, &hb2->chain);
-				this->lock_ptr = &hb2->lock;
-#ifdef CONFIG_DEBUG_PI_LIST
-				this->list.plist.lock = &hb2->lock;
-#endif
-			}
-			this->key = key2;
-			get_futex_key_refs(&key2);
-			drop_count++;
-
-
-			/*
-			 * THIRD: queue it to lock2
-			 */
-			spin_lock_irq(&this->task->pi_lock);
-			waiter = &this->waiter;
-			waiter->task = this->task;
-			waiter->lock = lock2;
-			plist_node_init(&waiter->list_entry, this->task->prio);
-			plist_node_init(&waiter->pi_list_entry, this->task->prio);
-			plist_add(&waiter->list_entry, &lock2->wait_list);
-			this->task->pi_blocked_on = waiter;
-			spin_unlock_irq(&this->task->pi_lock);
-
-			if (ret - nr_wake >= nr_requeue)
-				break;
-		}
-	}
-
-	/* If we've requeued some tasks and the top_waiter of the rt_mutex
-	   has changed, we must adjust the priority of the owner, if any */
-	if (drop_count) {
-		struct task_struct *owner = rt_mutex_owner(lock2);
-		if (owner &&
-		    (top_waiter != (waiter = rt_mutex_top_waiter(lock2)))) {
-			int chain_walk = 0;
-
-			spin_lock_irq(&owner->pi_lock);
-			if (top_waiter)
-				plist_del(&top_waiter->pi_list_entry, &owner->pi_waiters);
-			else
-				/*
-				 * There was no waiters before the requeue,
-				 * the flag must be updated
-				 */
-				mark_rt_mutex_waiters(lock2);
-
-			plist_add(&waiter->pi_list_entry, &owner->pi_waiters);
-			__rt_mutex_adjust_prio(owner);
-			if (owner->pi_blocked_on) {
-				chain_walk = 1;
-				get_task_struct(owner);
-			}
-
-			spin_unlock_irq(&owner->pi_lock);
-			spin_unlock(&lock2->wait_lock);
-
-			if (chain_walk)
-				rt_mutex_adjust_prio_chain(owner, 0, lock2, NULL,
-							   current);
-		} else {
-			/* No owner or the top_waiter does not change */
-			mark_rt_mutex_waiters(lock2);
-			spin_unlock(&lock2->wait_lock);
-		}
-	}
-
-out_unlock:
-	spin_unlock(&hb1->lock);
-	if (hb1 != hb2)
-		spin_unlock(&hb2->lock);
-
-	/* drop_futex_key_refs() must be called outside the spinlocks. */
-	while (--drop_count >= 0)
-		drop_futex_key_refs(&key1);
-
-out:
-	if (fshared)
-		up_read(fshared);
-	return ret;
-}
-
-/*
  * Wake up all waiters hashed on the physical page that is mapped
  * to this virtual address:
  */
@@ -1384,7 +1114,6 @@
 
 	while (!ret) {
 		newval = (uval & FUTEX_OWNER_DIED) | newtid;
-		newval |= (uval & FUTEX_WAITER_REQUEUED);
 
 		pagefault_disable();
 		curval = futex_atomic_cmpxchg_inatomic(uaddr,
@@ -1416,7 +1145,7 @@
 	struct futex_q q;
 	u32 uval;
 	int ret;
-	struct hrtimer_sleeper t, *to = NULL;
+	struct hrtimer_sleeper t;
 	int rem = 0;
 
 	q.pi_state = NULL;
@@ -1472,14 +1201,6 @@
 	if (uval != val)
 		goto out_unlock_release_sem;
 
-	/*
-	 * This rt_mutex_waiter structure is prepared here and will
-	 * be used only if this task is requeued from a normal futex to
-	 * a PI-futex with futex_requeue_pi.
-	 */
-	debug_rt_mutex_init_waiter(&q.waiter);
-	q.waiter.task = NULL;
-
 	/* Only actually queue if *uaddr contained val.  */
 	__queue_me(&q, hb);
 
@@ -1510,7 +1231,6 @@
 		if (!abs_time)
 			schedule();
 		else {
-			to = &t;
 			hrtimer_init(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
 			hrtimer_init_sleeper(&t, current);
 			t.timer.expires = *abs_time;
@@ -1538,67 +1258,6 @@
 	 * we are the only user of it.
 	 */
 
-	if (q.pi_state) {
-		/*
-		 * We were woken but have been requeued on a PI-futex.
-		 * We have to complete the lock acquisition by taking
-		 * the rtmutex.
-		 */
-
-		struct rt_mutex *lock = &q.pi_state->pi_mutex;
-
-		spin_lock(&lock->wait_lock);
-		if (unlikely(q.waiter.task)) {
-			remove_waiter(lock, &q.waiter);
-		}
-		spin_unlock(&lock->wait_lock);
-
-		if (rem)
-			ret = -ETIMEDOUT;
-		else
-			ret = rt_mutex_timed_lock(lock, to, 1);
-
-		if (fshared)
-			down_read(fshared);
-		spin_lock(q.lock_ptr);
-
-		/*
-		 * Got the lock. We might not be the anticipated owner if we
-		 * did a lock-steal - fix up the PI-state in that case.
-		 */
-		if (!ret && q.pi_state->owner != curr) {
-			/*
-			 * We MUST play with the futex we were requeued on,
-			 * NOT the current futex.
-			 * We can retrieve it from the key of the pi_state
-			 */
-			uaddr = q.pi_state->key.uaddr;
-
-			ret = fixup_pi_state_owner(uaddr, &q, curr);
-		} else {
-			/*
-			 * Catch the rare case, where the lock was released
-			 * when we were on the way back before we locked
-			 * the hash bucket.
-			 */
-			if (ret && q.pi_state->owner == curr) {
-				if (rt_mutex_trylock(&q.pi_state->pi_mutex))
-					ret = 0;
-			}
-		}
-
-		/* Unqueue and drop the lock */
-		unqueue_me_pi(&q);
-		if (fshared)
-			up_read(fshared);
-
-		debug_rt_mutex_free_waiter(&q.waiter);
-
-		return ret;
-	}
-
-	debug_rt_mutex_free_waiter(&q.waiter);
-
 	/* If we were woken (and unqueued), we succeeded, whatever. */
 	if (!unqueue_me(&q))
 		return 0;
@@ -1648,51 +1307,6 @@
 }
 
 
-static void set_pi_futex_owner(struct futex_hash_bucket *hb,
-			       union futex_key *key, struct task_struct *p)
-{
-	struct plist_head *head;
-	struct futex_q *this, *next;
-	struct futex_pi_state *pi_state = NULL;
-	struct rt_mutex *lock;
-
-	/* Search a waiter that should already exists */
-
-	head = &hb->chain;
-
-	plist_for_each_entry_safe(this, next, head, list) {
-		if (match_futex (&this->key, key)) {
-			pi_state = this->pi_state;
-			break;
-		}
-	}
-
-	BUG_ON(!pi_state);
-
-	/* set p as pi_state's owner */
-	lock = &pi_state->pi_mutex;
-
-	spin_lock(&lock->wait_lock);
-	spin_lock_irq(&p->pi_lock);
-
-	list_add(&pi_state->list, &p->pi_state_list);
-	pi_state->owner = p;
-
-
-	/* set p as pi_mutex's owner */
-	debug_rt_mutex_proxy_lock(lock, p);
-	WARN_ON(rt_mutex_owner(lock));
-	rt_mutex_set_owner(lock, p, 0);
-	rt_mutex_deadlock_account_lock(lock, p);
-
-	plist_add(&rt_mutex_top_waiter(lock)->pi_list_entry,
-		  &p->pi_waiters);
-	__rt_mutex_adjust_prio(p);
-
-	spin_unlock_irq(&p->pi_lock);
-	spin_unlock(&lock->wait_lock);
-}
-
 /*
  * Userspace tried a 0 -> TID atomic transition of the futex value
  * and failed. The kernel side here does the whole locking operation:
@@ -1753,8 +1367,7 @@
 	 * situation and we return success to user space.
 	 */
 	if (unlikely((curval & FUTEX_TID_MASK) == current->pid)) {
-		if (!(curval & FUTEX_WAITER_REQUEUED))
-			ret = -EDEADLK;
+		ret = -EDEADLK;
 		goto out_unlock_release_sem;
 	}
 
@@ -1774,14 +1387,14 @@
 
 	/*
 	 * There are two cases, where a futex might have no owner (the
-	 * owner TID is 0): OWNER_DIED or REQUEUE. We take over the
-	 * futex in this case. We also do an unconditional take over,
-	 * when the owner of the futex died.
+	 * owner TID is 0): OWNER_DIED. We take over the futex in this
+	 * case. We also do an unconditional take over, when the owner
+	 * of the futex died.
 	 *
 	 * This is safe as we are protected by the hash bucket lock !
 	 */
 	if (unlikely(ownerdied || !(curval & FUTEX_TID_MASK))) {
-		/* Keep the OWNER_DIED and REQUEUE bits */
+		/* Keep the OWNER_DIED bit */
 		newval = (curval & ~FUTEX_TID_MASK) | current->pid;
 		ownerdied = 0;
 		lock_taken = 1;
@@ -1797,14 +1410,10 @@
 		goto retry_locked;
 
 	/*
-	 * We took the lock due to requeue or owner died take over.
+	 * We took the lock due to owner died take over.
 	 */
-	if (unlikely(lock_taken)) {
-		/* For requeue we need to fixup the pi_futex */
-		if (curval & FUTEX_WAITER_REQUEUED)
-			set_pi_futex_owner(hb, &q.key, curr);
+	if (unlikely(lock_taken))
 		goto out_unlock_release_sem;
-	}
 
 	/*
 	 * We dont have the lock. Look up the PI state (or create it if
@@ -2289,8 +1898,6 @@
 		 * userspace.
 		 */
 		mval = (uval & FUTEX_WAITERS) | FUTEX_OWNER_DIED;
-		/* Also keep the FUTEX_WAITER_REQUEUED flag if set */
-		mval |= (uval & FUTEX_WAITER_REQUEUED);
 		nval = futex_atomic_cmpxchg_inatomic(uaddr, uval, mval);
 
 		if (nval == -EFAULT)
@@ -2427,9 +2034,6 @@
 	case FUTEX_TRYLOCK_PI:
 		ret = futex_lock_pi(uaddr, fshared, 0, timeout, 1);
 		break;
-	case FUTEX_CMP_REQUEUE_PI:
-		ret = futex_requeue_pi(uaddr, fshared, uaddr2, val, val2, &val3);
-		break;
 	default:
 		ret = -ENOSYS;
 	}
@@ -2460,8 +2064,7 @@
 	/*
 	 * requeue parameter in 'utime' if cmd == FUTEX_REQUEUE.
 	 */
-	if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE
-	    || cmd == FUTEX_CMP_REQUEUE_PI)
+	if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE)
 		val2 = (u32) (unsigned long) utime;
 
 	return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
index 2747894..f792136 100644
--- a/kernel/futex_compat.c
+++ b/kernel/futex_compat.c
@@ -157,8 +157,7 @@
 			t = ktime_add(ktime_get(), t);
 		tp = &t;
 	}
-	if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE
-	    || cmd == FUTEX_CMP_REQUEUE_PI)
+	if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE)
 		val2 = (int) (unsigned long) utime;
 
 	return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 24d7d78..d65305b 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -99,6 +99,8 @@
 	ssize_t res;
 
 	data = filp->private_data;
+	if (!data->ready)
+		return -ENODATA;
 	res = snapshot_read_next(&data->handle, count);
 	if (res > 0) {
 		if (copy_to_user(buf, data_of(data->handle), res))
@@ -245,7 +247,7 @@
 		break;
 
 	case SNAPSHOT_UNFREEZE:
-		if (!data->frozen)
+		if (!data->frozen || data->ready)
 			break;
 		mutex_lock(&pm_mutex);
 		thaw_processes();
diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
index a6fbb41..17d28ce 100644
--- a/kernel/rtmutex.c
+++ b/kernel/rtmutex.c
@@ -56,7 +56,7 @@
  * state.
  */
 
-void
+static void
 rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner,
 		   unsigned long mask)
 {
@@ -81,6 +81,29 @@
 }
 
 /*
+ * We can speed up the acquire/release, if the architecture
+ * supports cmpxchg and if there's no debugging state to be set up
+ */
+#if defined(__HAVE_ARCH_CMPXCHG) && !defined(CONFIG_DEBUG_RT_MUTEXES)
+# define rt_mutex_cmpxchg(l,c,n)	(cmpxchg(&l->owner, c, n) == c)
+static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
+{
+	unsigned long owner, *p = (unsigned long *) &lock->owner;
+
+	do {
+		owner = *p;
+	} while (cmpxchg(p, owner, owner | RT_MUTEX_HAS_WAITERS) != owner);
+}
+#else
+# define rt_mutex_cmpxchg(l,c,n)	(0)
+static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
+{
+	lock->owner = (struct task_struct *)
+			((unsigned long)lock->owner | RT_MUTEX_HAS_WAITERS);
+}
+#endif
+
+/*
  * Calculate task priority from the waiter list priority
  *
  * Return task->normal_prio when the waiter list is empty or when
@@ -100,7 +123,7 @@
  *
  * This can be both boosting and unboosting. task->pi_lock must be held.
  */
-void __rt_mutex_adjust_prio(struct task_struct *task)
+static void __rt_mutex_adjust_prio(struct task_struct *task)
 {
 	int prio = rt_mutex_getprio(task);
 
@@ -136,11 +159,11 @@
  * Decreases task's usage by one - may thus free the task.
  * Returns 0 or -EDEADLK.
  */
-int rt_mutex_adjust_prio_chain(struct task_struct *task,
-			       int deadlock_detect,
-			       struct rt_mutex *orig_lock,
-			       struct rt_mutex_waiter *orig_waiter,
-			       struct task_struct *top_task)
+static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+				      int deadlock_detect,
+				      struct rt_mutex *orig_lock,
+				      struct rt_mutex_waiter *orig_waiter,
+				      struct task_struct *top_task)
 {
 	struct rt_mutex *lock;
 	struct rt_mutex_waiter *waiter, *top_waiter = orig_waiter;
@@ -514,8 +537,8 @@
  *
  * Must be called with lock->wait_lock held
  */
-void remove_waiter(struct rt_mutex *lock,
-		   struct rt_mutex_waiter *waiter)
+static void remove_waiter(struct rt_mutex *lock,
+			  struct rt_mutex_waiter *waiter)
 {
 	int first = (waiter == rt_mutex_top_waiter(lock));
 	struct task_struct *owner = rt_mutex_owner(lock);
diff --git a/kernel/rtmutex_common.h b/kernel/rtmutex_common.h
index 242ec7e..9c75856 100644
--- a/kernel/rtmutex_common.h
+++ b/kernel/rtmutex_common.h
@@ -113,29 +113,6 @@
 }
 
 /*
- * We can speed up the acquire/release, if the architecture
- * supports cmpxchg and if there's no debugging state to be set up
- */
-#if defined(__HAVE_ARCH_CMPXCHG) && !defined(CONFIG_DEBUG_RT_MUTEXES)
-# define rt_mutex_cmpxchg(l,c,n)	(cmpxchg(&l->owner, c, n) == c)
-static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
-{
-	unsigned long owner, *p = (unsigned long *) &lock->owner;
-
-	do {
-		owner = *p;
-	} while (cmpxchg(p, owner, owner | RT_MUTEX_HAS_WAITERS) != owner);
-}
-#else
-# define rt_mutex_cmpxchg(l,c,n)	(0)
-static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
-{
-	lock->owner = (struct task_struct *)
-			((unsigned long)lock->owner | RT_MUTEX_HAS_WAITERS);
-}
-#endif
-
-/*
  * PI-futex support (proxy locking functions, etc.):
  */
 extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
@@ -143,15 +120,4 @@
 				       struct task_struct *proxy_owner);
 extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
 				  struct task_struct *proxy_owner);
-
-extern void rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner,
-			       unsigned long mask);
-extern void __rt_mutex_adjust_prio(struct task_struct *task);
-extern int rt_mutex_adjust_prio_chain(struct task_struct *task,
-				      int deadlock_detect,
-				      struct rt_mutex *orig_lock,
-				      struct rt_mutex_waiter *orig_waiter,
-				      struct task_struct *top_task);
-extern void remove_waiter(struct rt_mutex *lock,
-			  struct rt_mutex_waiter *waiter);
 #endif
diff --git a/kernel/sched.c b/kernel/sched.c
index 13cdab3..a747591 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1159,21 +1159,72 @@
 {
 	unsigned long flags;
 	struct rq *rq;
-	int preempted;
+	struct prio_array *array;
+	int running;
 
 repeat:
-	rq = task_rq_lock(p, &flags);
-	/* Must be off runqueue entirely, not preempted. */
-	if (unlikely(p->array || task_running(rq, p))) {
-		/* If it's preempted, we yield.  It could be a while. */
-		preempted = !task_running(rq, p);
-		task_rq_unlock(rq, &flags);
+	/*
+	 * We do the initial early heuristics without holding
+	 * any task-queue locks at all. We'll only try to get
+	 * the runqueue lock when things look like they will
+	 * work out!
+	 */
+	rq = task_rq(p);
+
+	/*
+	 * If the task is actively running on another CPU
+	 * still, just relax and busy-wait without holding
+	 * any locks.
+	 *
+	 * NOTE! Since we don't hold any locks, it's not
+	 * even sure that "rq" stays as the right runqueue!
+	 * But we don't care, since "task_running()" will
+	 * return false if the runqueue has changed and p
+	 * is actually now running somewhere else!
+	 */
+	while (task_running(rq, p))
 		cpu_relax();
-		if (preempted)
-			yield();
+
+	/*
+	 * Ok, time to look more closely! We need the rq
+	 * lock now, to be *sure*. If we're wrong, we'll
+	 * just go back and repeat.
+	 */
+	rq = task_rq_lock(p, &flags);
+	running = task_running(rq, p);
+	array = p->array;
+	task_rq_unlock(rq, &flags);
+
+	/*
+	 * Was it really running after all now that we
+	 * checked with the proper locks actually held?
+	 *
+	 * Oops. Go back and try again..
+	 */
+	if (unlikely(running)) {
+		cpu_relax();
 		goto repeat;
 	}
-	task_rq_unlock(rq, &flags);
+
+	/*
+	 * It's not enough that it's not actively running,
+	 * it must be off the runqueue _entirely_, and not
+	 * preempted!
+	 *
+	 * So if it wa still runnable (but just not actively
+	 * running right now), it's preempted, and we should
+	 * yield - it could be a while.
+	 */
+	if (unlikely(array)) {
+		yield();
+		goto repeat;
+	}
+
+	/*
+	 * Ahh, all good. It wasn't running, and it wasn't
+	 * runnable, which means that it will never become
+	 * running in the future either. We're all done!
+	 */
 }
 
 /***
@@ -7071,12 +7122,13 @@
 void normalize_rt_tasks(void)
 {
 	struct prio_array *array;
-	struct task_struct *p;
+	struct task_struct *g, *p;
 	unsigned long flags;
 	struct rq *rq;
 
 	read_lock_irq(&tasklist_lock);
-	for_each_process(p) {
+
+	do_each_thread(g, p) {
 		if (!rt_task(p))
 			continue;
 
@@ -7094,7 +7146,8 @@
 
 		__task_rq_unlock(rq);
 		spin_unlock_irqrestore(&p->pi_lock, flags);
-	}
+	} while_each_thread(g, p);
+
 	read_unlock_irq(&tasklist_lock);
 }
 
diff --git a/kernel/signal.c b/kernel/signal.c
index fe590e0..f940560 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -363,7 +363,13 @@
  */
 int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
 {
-	int signr = __dequeue_signal(&tsk->pending, mask, info);
+	int signr = 0;
+
+	/* We only dequeue private signals from ourselves, we don't let
+	 * signalfd steal them
+	 */
+	if (tsk == current)
+		signr = __dequeue_signal(&tsk->pending, mask, info);
 	if (!signr) {
 		signr = __dequeue_signal(&tsk->signal->shared_pending,
 					 mask, info);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index eb7180d..a45d1f0 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -326,9 +326,10 @@
 	pte_t entry;
 
 	entry = pte_mkwrite(pte_mkdirty(*ptep));
-	ptep_set_access_flags(vma, address, ptep, entry, 1);
-	update_mmu_cache(vma, address, entry);
-	lazy_mmu_prot_update(entry);
+	if (ptep_set_access_flags(vma, address, ptep, entry, 1)) {
+		update_mmu_cache(vma, address, entry);
+		lazy_mmu_prot_update(entry);
+	}
 }
 
 
diff --git a/mm/memory.c b/mm/memory.c
index cb94488..f64cbf9 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1691,9 +1691,10 @@
 		flush_cache_page(vma, address, pte_pfn(orig_pte));
 		entry = pte_mkyoung(orig_pte);
 		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
-		ptep_set_access_flags(vma, address, page_table, entry, 1);
-		update_mmu_cache(vma, address, entry);
-		lazy_mmu_prot_update(entry);
+		if (ptep_set_access_flags(vma, address, page_table, entry,1)) {
+			update_mmu_cache(vma, address, entry);
+			lazy_mmu_prot_update(entry);
+		}
 		ret |= VM_FAULT_WRITE;
 		goto unlock;
 	}
@@ -2525,10 +2526,9 @@
 		pte_t *pte, pmd_t *pmd, int write_access)
 {
 	pte_t entry;
-	pte_t old_entry;
 	spinlock_t *ptl;
 
-	old_entry = entry = *pte;
+	entry = *pte;
 	if (!pte_present(entry)) {
 		if (pte_none(entry)) {
 			if (vma->vm_ops) {
@@ -2561,8 +2561,7 @@
 		entry = pte_mkdirty(entry);
 	}
 	entry = pte_mkyoung(entry);
-	if (!pte_same(old_entry, entry)) {
-		ptep_set_access_flags(vma, address, pte, entry, write_access);
+	if (ptep_set_access_flags(vma, address, pte, entry, write_access)) {
 		update_mmu_cache(vma, address, entry);
 		lazy_mmu_prot_update(entry);
 	} else {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index bd8e335..05ace44 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1968,7 +1968,7 @@
 	memmap_init_zone((size), (nid), (zone), (start_pfn), MEMMAP_EARLY)
 #endif
 
-static int __cpuinit zone_batchsize(struct zone *zone)
+static int __devinit zone_batchsize(struct zone *zone)
 {
 	int batch;
 
diff --git a/mm/slub.c b/mm/slub.c
index c9ab688..fa28b16 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2436,6 +2436,7 @@
 void __init kmem_cache_init(void)
 {
 	int i;
+	int caches = 0;
 
 #ifdef CONFIG_NUMA
 	/*
@@ -2446,20 +2447,29 @@
 	create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
 		sizeof(struct kmem_cache_node), GFP_KERNEL);
 	kmalloc_caches[0].refcount = -1;
+	caches++;
 #endif
 
 	/* Able to allocate the per node structures */
 	slab_state = PARTIAL;
 
 	/* Caches that are not of the two-to-the-power-of size */
-	create_kmalloc_cache(&kmalloc_caches[1],
+	if (KMALLOC_MIN_SIZE <= 64) {
+		create_kmalloc_cache(&kmalloc_caches[1],
 				"kmalloc-96", 96, GFP_KERNEL);
-	create_kmalloc_cache(&kmalloc_caches[2],
+		caches++;
+	}
+	if (KMALLOC_MIN_SIZE <= 128) {
+		create_kmalloc_cache(&kmalloc_caches[2],
 				"kmalloc-192", 192, GFP_KERNEL);
+		caches++;
+	}
 
-	for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++)
+	for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
 		create_kmalloc_cache(&kmalloc_caches[i],
 			"kmalloc", 1 << i, GFP_KERNEL);
+		caches++;
+	}
 
 	slab_state = UP;
 
@@ -2476,8 +2486,8 @@
 				nr_cpu_ids * sizeof(struct page *);
 
 	printk(KERN_INFO "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
-		" Processors=%d, Nodes=%d\n",
-		KMALLOC_SHIFT_HIGH, cache_line_size(),
+		" CPUs=%d, Nodes=%d\n",
+		caches, cache_line_size(),
 		slub_min_order, slub_max_order, slub_min_objects,
 		nr_cpu_ids, nr_node_ids);
 }
@@ -2867,7 +2877,7 @@
 
 	order = get_order(sizeof(struct location) * max);
 
-	l = (void *)__get_free_pages(GFP_KERNEL, order);
+	l = (void *)__get_free_pages(GFP_ATOMIC, order);
 
 	if (!l)
 		return 0;
diff --git a/net/ipv4/tcp_bic.c b/net/ipv4/tcp_bic.c
index 281c9f9..dd9ef65 100644
--- a/net/ipv4/tcp_bic.c
+++ b/net/ipv4/tcp_bic.c
@@ -29,7 +29,7 @@
 static int max_increment = 16;
 static int low_window = 14;
 static int beta = 819;		/* = 819/1024 (BICTCP_BETA_SCALE) */
-static int initial_ssthresh = 100;
+static int initial_ssthresh;
 static int smooth_part = 20;
 
 module_param(fast_convergence, int, 0644);
diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c
index 1422448..ebfaac2 100644
--- a/net/ipv4/tcp_cubic.c
+++ b/net/ipv4/tcp_cubic.c
@@ -29,7 +29,7 @@
 static int fast_convergence __read_mostly = 1;
 static int max_increment __read_mostly = 16;
 static int beta __read_mostly = 819;	/* = 819/1024 (BICTCP_BETA_SCALE) */
-static int initial_ssthresh __read_mostly = 100;
+static int initial_ssthresh __read_mostly;
 static int bic_scale __read_mostly = 41;
 static int tcp_friendliness __read_mostly = 1;
 
diff --git a/net/ipv4/tcp_illinois.c b/net/ipv4/tcp_illinois.c
index 4adc47c..b2b2256 100644
--- a/net/ipv4/tcp_illinois.c
+++ b/net/ipv4/tcp_illinois.c
@@ -90,6 +90,9 @@
 
 	ca->acked = pkts_acked;
 
+	if (ktime_equal(last, net_invalid_timestamp()))
+		return;
+
 	rtt = ktime_to_us(net_timedelta(last));
 
 	/* ignore bogus values, this prevents wraparound in alpha math */
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 74683d8..69f9f1e 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -953,7 +953,7 @@
 	int prior_fackets;
 	u32 lost_retrans = 0;
 	int flag = 0;
-	int dup_sack = 0;
+	int found_dup_sack = 0;
 	int cached_fack_count;
 	int i;
 	int first_sack_index;
@@ -964,20 +964,20 @@
 
 	/* Check for D-SACK. */
 	if (before(ntohl(sp[0].start_seq), TCP_SKB_CB(ack_skb)->ack_seq)) {
-		dup_sack = 1;
+		found_dup_sack = 1;
 		tp->rx_opt.sack_ok |= 4;
 		NET_INC_STATS_BH(LINUX_MIB_TCPDSACKRECV);
 	} else if (num_sacks > 1 &&
 			!after(ntohl(sp[0].end_seq), ntohl(sp[1].end_seq)) &&
 			!before(ntohl(sp[0].start_seq), ntohl(sp[1].start_seq))) {
-		dup_sack = 1;
+		found_dup_sack = 1;
 		tp->rx_opt.sack_ok |= 4;
 		NET_INC_STATS_BH(LINUX_MIB_TCPDSACKOFORECV);
 	}
 
 	/* D-SACK for already forgotten data...
 	 * Do dumb counting. */
-	if (dup_sack &&
+	if (found_dup_sack &&
 			!after(ntohl(sp[0].end_seq), prior_snd_una) &&
 			after(ntohl(sp[0].end_seq), tp->undo_marker))
 		tp->undo_retrans--;
@@ -1058,6 +1058,7 @@
 		__u32 start_seq = ntohl(sp->start_seq);
 		__u32 end_seq = ntohl(sp->end_seq);
 		int fack_count;
+		int dup_sack = (found_dup_sack && (i == first_sack_index));
 
 		skb = cached_skb;
 		fack_count = cached_fack_count;
@@ -2037,7 +2038,7 @@
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 
-	tp->left_out = tp->sacked_out;
+	tcp_sync_left_out(tp);
 
 	if (tp->retrans_out == 0)
 		tp->retrans_stamp = 0;
@@ -2409,7 +2410,7 @@
 	int acked = 0;
 	int prior_packets = tp->packets_out;
 	__s32 seq_rtt = -1;
-	ktime_t last_ackt = ktime_set(0,0);
+	ktime_t last_ackt = net_invalid_timestamp();
 
 	while ((skb = tcp_write_queue_head(sk)) &&
 	       skb != tcp_send_head(sk)) {
@@ -2487,6 +2488,10 @@
 		tcp_ack_update_rtt(sk, acked, seq_rtt);
 		tcp_ack_packets_out(sk);
 
+		/* Is the ACK triggering packet unambiguous? */
+		if (acked & FLAG_RETRANS_DATA_ACKED)
+			last_ackt = net_invalid_timestamp();
+
 		if (ca_ops->pkts_acked)
 			ca_ops->pkts_acked(sk, pkts_acked, last_ackt);
 	}
@@ -2932,6 +2937,7 @@
 					   opt_rx->sack_ok) {
 						TCP_SKB_CB(skb)->sacked = (ptr - 2) - (unsigned char *)th;
 					}
+					break;
 #ifdef CONFIG_TCP_MD5SIG
 				case TCPOPT_MD5SIG:
 					/*
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 97e294e..354721d 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -878,6 +878,7 @@
 				kfree(newkey);
 				return -ENOMEM;
 			}
+			sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
 		}
 		if (tcp_alloc_md5sig_pool() == NULL) {
 			kfree(newkey);
@@ -1007,7 +1008,7 @@
 			return -EINVAL;
 
 		tp->md5sig_info = p;
-
+		sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
 	}
 
 	newkey = kmemdup(cmd.tcpm_key, cmd.tcpm_keylen, GFP_KERNEL);
diff --git a/net/ipv4/tcp_lp.c b/net/ipv4/tcp_lp.c
index 43294ad..e49836c 100644
--- a/net/ipv4/tcp_lp.c
+++ b/net/ipv4/tcp_lp.c
@@ -266,7 +266,8 @@
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct lp *lp = inet_csk_ca(sk);
 
-	tcp_lp_rtt_sample(sk,  ktime_to_us(net_timedelta(last)));
+	if (!ktime_equal(last, net_invalid_timestamp()))
+		tcp_lp_rtt_sample(sk,  ktime_to_us(net_timedelta(last)));
 
 	/* calc inference */
 	if (tcp_time_stamp > tp->rx_opt.rcv_tsecr)
diff --git a/net/ipv4/tcp_vegas.c b/net/ipv4/tcp_vegas.c
index 73e19cf..e218a51 100644
--- a/net/ipv4/tcp_vegas.c
+++ b/net/ipv4/tcp_vegas.c
@@ -117,6 +117,9 @@
 	struct vegas *vegas = inet_csk_ca(sk);
 	u32 vrtt;
 
+	if (ktime_equal(last, net_invalid_timestamp()))
+		return;
+
 	/* Never allow zero rtt or baseRTT */
 	vrtt = ktime_to_us(net_timedelta(last)) + 1;
 
diff --git a/net/ipv4/tcp_veno.c b/net/ipv4/tcp_veno.c
index 9edb340..ec854cc 100644
--- a/net/ipv4/tcp_veno.c
+++ b/net/ipv4/tcp_veno.c
@@ -74,6 +74,9 @@
 	struct veno *veno = inet_csk_ca(sk);
 	u32 vrtt;
 
+	if (ktime_equal(last, net_invalid_timestamp()))
+		return;
+
 	/* Never allow zero rtt or baseRTT */
 	vrtt = ktime_to_us(net_timedelta(last)) + 1;
 
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 5a5f8bd..f96ed76 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2154,6 +2154,15 @@
 
 	ASSERT_RTNL();
 
+	if ((dev->type != ARPHRD_ETHER) &&
+	    (dev->type != ARPHRD_FDDI) &&
+	    (dev->type != ARPHRD_IEEE802_TR) &&
+	    (dev->type != ARPHRD_ARCNET) &&
+	    (dev->type != ARPHRD_INFINIBAND)) {
+		/* Alas, we support only Ethernet autoconfiguration. */
+		return;
+	}
+
 	idev = addrconf_add_dev(dev);
 	if (idev == NULL)
 		return;
@@ -2241,36 +2250,16 @@
 	ip6_tnl_add_linklocal(idev);
 }
 
-static int ipv6_hwtype(struct net_device *dev)
-{
-	if ((dev->type == ARPHRD_ETHER) ||
-	    (dev->type == ARPHRD_LOOPBACK) ||
-	    (dev->type == ARPHRD_SIT) ||
-	    (dev->type == ARPHRD_TUNNEL6) ||
-	    (dev->type == ARPHRD_FDDI) ||
-	    (dev->type == ARPHRD_IEEE802_TR) ||
-	    (dev->type == ARPHRD_ARCNET) ||
-	    (dev->type == ARPHRD_INFINIBAND))
-		return 1;
-
-	return 0;
-}
-
 static int addrconf_notify(struct notifier_block *this, unsigned long event,
 			   void * data)
 {
 	struct net_device *dev = (struct net_device *) data;
-	struct inet6_dev *idev;
+	struct inet6_dev *idev = __in6_dev_get(dev);
 	int run_pending = 0;
 
-	if (!ipv6_hwtype(dev))
-		return NOTIFY_OK;
-
-	idev = __in6_dev_get(dev);
-
 	switch(event) {
 	case NETDEV_REGISTER:
-		if (!idev) {
+		if (!idev && dev->mtu >= IPV6_MIN_MTU) {
 			idev = ipv6_add_dev(dev);
 			if (!idev)
 				printk(KERN_WARNING "IPv6: add_dev failed for %s\n",
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 4f06a51..193d9d6 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -590,6 +590,7 @@
 				kfree(newkey);
 				return -ENOMEM;
 			}
+			sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
 		}
 		tcp_alloc_md5sig_pool();
 		if (tp->md5sig_info->alloced6 == tp->md5sig_info->entries6) {
@@ -724,6 +725,7 @@
 			return -ENOMEM;
 
 		tp->md5sig_info = p;
+		sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
 	}
 
 	newkey = kmemdup(cmd.tcpm_key, cmd.tcpm_keylen, GFP_KERNEL);
diff --git a/net/irda/irlap_event.c b/net/irda/irlap_event.c
index 0b02073..a8b8873 100644
--- a/net/irda/irlap_event.c
+++ b/net/irda/irlap_event.c
@@ -317,23 +317,6 @@
 }
 
 /*
- * Function irlap_next_state (self, state)
- *
- *    Switches state and provides debug information
- *
- */
-static inline void irlap_next_state(struct irlap_cb *self, IRLAP_STATE state)
-{
-	/*
-	if (!self || self->magic != LAP_MAGIC)
-		return;
-
-	IRDA_DEBUG(4, "next LAP state = %s\n", irlap_state[state]);
-	*/
-	self->state = state;
-}
-
-/*
  * Function irlap_state_ndm (event, skb, frame)
  *
  *    NDM (Normal Disconnected Mode) state
@@ -1086,7 +1069,6 @@
 			} else {
 				/* Final packet of window */
 				irlap_send_data_primary_poll(self, skb);
-				irlap_next_state(self, LAP_NRM_P);
 
 				/*
 				 * Make sure state machine does not try to send
@@ -1436,14 +1418,14 @@
 		 */
 		self->remote_busy = FALSE;
 
+		/* Stop final timer */
+		del_timer(&self->final_timer);
+
 		/*
 		 *  Nr as expected?
 		 */
 		ret = irlap_validate_nr_received(self, info->nr);
 		if (ret == NR_EXPECTED) {
-			/* Stop final timer */
-			del_timer(&self->final_timer);
-
 			/* Update Nr received */
 			irlap_update_nr_received(self, info->nr);
 
@@ -1475,14 +1457,12 @@
 
 			/* Resend rejected frames */
 			irlap_resend_rejected_frames(self, CMD_FRAME);
-
-			/* Final timer ??? Jean II */
+			irlap_start_final_timer(self, self->final_timeout * 2);
 
 			irlap_next_state(self, LAP_NRM_P);
 		} else if (ret == NR_INVALID) {
 			IRDA_DEBUG(1, "%s(), Received RR with "
 				   "invalid nr !\n", __FUNCTION__);
-			del_timer(&self->final_timer);
 
 			irlap_next_state(self, LAP_RESET_WAIT);
 
diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
index 3c5a68e..3013c49 100644
--- a/net/irda/irlap_frame.c
+++ b/net/irda/irlap_frame.c
@@ -798,16 +798,19 @@
 		self->vs = (self->vs + 1) % 8;
 		self->ack_required = FALSE;
 
+		irlap_next_state(self, LAP_NRM_P);
 		irlap_send_i_frame(self, tx_skb, CMD_FRAME);
 	} else {
 		IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __FUNCTION__);
 
 		if (self->ack_required) {
 			irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
+			irlap_next_state(self, LAP_NRM_P);
 			irlap_send_rr_frame(self, CMD_FRAME);
 			self->ack_required = FALSE;
 		} else {
 			skb->data[1] |= PF_BIT;
+			irlap_next_state(self, LAP_NRM_P);
 			irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
 		}
 	}
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index bb6c0fe..476c848 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -112,7 +112,7 @@
 		      local->wep_iv & 0xffffff);
 DEBUGFS_READONLY_FILE(tx_power_reduction, 20, "%d.%d dBm",
 		      local->hw.conf.tx_power_reduction / 10,
-		      local->hw.conf.tx_power_reduction & 10);
+		      local->hw.conf.tx_power_reduction % 10);
 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
 		      local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
 
diff --git a/net/mac80211/ieee80211_sta.c b/net/mac80211/ieee80211_sta.c
index 9f30ae4..91b545c 100644
--- a/net/mac80211/ieee80211_sta.c
+++ b/net/mac80211/ieee80211_sta.c
@@ -2592,11 +2592,17 @@
 
 	read_lock(&local->sub_if_lock);
 	list_for_each_entry(sdata, &local->sub_if_list, list) {
+
+		/* No need to wake the master device. */
+		if (sdata->dev == local->mdev)
+			continue;
+
 		if (sdata->type == IEEE80211_IF_TYPE_STA) {
 			if (sdata->u.sta.associated)
 				ieee80211_send_nullfunc(local, sdata, 0);
 			ieee80211_sta_timer((unsigned long)sdata);
 		}
+
 		netif_wake_queue(sdata->dev);
 	}
 	read_unlock(&local->sub_if_lock);
@@ -2738,6 +2744,12 @@
 
 	read_lock(&local->sub_if_lock);
 	list_for_each_entry(sdata, &local->sub_if_list, list) {
+
+		/* Don't stop the master interface, otherwise we can't transmit
+		 * probes! */
+		if (sdata->dev == local->mdev)
+			continue;
+
 		netif_stop_queue(sdata->dev);
 		if (sdata->type == IEEE80211_IF_TYPE_STA &&
 		    sdata->u.sta.associated)
diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
index 43cb3e0..482750e 100644
--- a/net/rxrpc/ar-connection.c
+++ b/net/rxrpc/ar-connection.c
@@ -211,7 +211,7 @@
 		conn->header_size = sizeof(struct rxrpc_header);
 	}
 
-	_leave(" = %p{%d}", conn, conn->debug_id);
+	_leave(" = %p{%d}", conn, conn ? conn->debug_id : 0);
 	return conn;
 }
 
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index df94e3c..498edb0 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -1231,6 +1231,10 @@
 	/* Get the lowest pmtu of all the transports. */
 	list_for_each(pos, &asoc->peer.transport_addr_list) {
 		t = list_entry(pos, struct sctp_transport, transports);
+		if (t->pmtu_pending && t->dst) {
+			sctp_transport_update_pmtu(t, dst_mtu(t->dst));
+			t->pmtu_pending = 0;
+		}
 		if (!pmtu || (t->pathmtu < pmtu))
 			pmtu = t->pathmtu;
 	}
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 885109f..d57ff7f 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -367,24 +367,18 @@
 void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
 			   struct sctp_transport *t, __u32 pmtu)
 {
-	if (sock_owned_by_user(sk) || !t || (t->pathmtu == pmtu))
+	if (!t || (t->pathmtu == pmtu))
 		return;
 
+	if (sock_owned_by_user(sk)) {
+		asoc->pmtu_pending = 1;
+		t->pmtu_pending = 1;
+		return;
+	}
+
 	if (t->param_flags & SPP_PMTUD_ENABLE) {
-		if (unlikely(pmtu < SCTP_DEFAULT_MINSEGMENT)) {
-			printk(KERN_WARNING "%s: Reported pmtu %d too low, "
-			       "using default minimum of %d\n",
-			       __FUNCTION__, pmtu,
-			       SCTP_DEFAULT_MINSEGMENT);
-			/* Use default minimum segment size and disable
-			 * pmtu discovery on this transport.
-			 */
-			t->pathmtu = SCTP_DEFAULT_MINSEGMENT;
-			t->param_flags = (t->param_flags & ~SPP_PMTUD) |
-				SPP_PMTUD_DISABLE;
-		} else {
-			t->pathmtu = pmtu;
-		}
+		/* Update transports view of the MTU */
+		sctp_transport_update_pmtu(t, pmtu);
 
 		/* Update association pmtu. */
 		sctp_assoc_sync_pmtu(asoc);
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 4dcdabf..6edaaa0 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -333,12 +333,19 @@
 	if (!sp->pf->bind_verify(sp, addr))
 		return -EADDRNOTAVAIL;
 
-	/* We must either be unbound, or bind to the same port.  */
-	if (bp->port && (snum != bp->port)) {
-		SCTP_DEBUG_PRINTK("sctp_do_bind:"
+	/* We must either be unbound, or bind to the same port.
+	 * It's OK to allow 0 ports if we are already bound.
+	 * We'll just inhert an already bound port in this case
+	 */
+	if (bp->port) {
+		if (!snum)
+			snum = bp->port;
+		else if (snum != bp->port) {
+			SCTP_DEBUG_PRINTK("sctp_do_bind:"
 				  " New port %d does not match existing port "
 				  "%d.\n", snum, bp->port);
-		return -EINVAL;
+			return -EINVAL;
+		}
 	}
 
 	if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
@@ -1655,6 +1662,9 @@
 		goto out_free;
 	}
 
+	if (asoc->pmtu_pending)
+		sctp_assoc_pending_pmtu(asoc);
+
 	/* If fragmentation is disabled and the message length exceeds the
 	 * association fragmentation point, return EMSGSIZE.  The I-D
 	 * does not specify what this error is, but this looks like
@@ -3550,6 +3560,7 @@
 	struct sock *sk = asoc->base.sk;
 	struct socket *sock;
 	struct inet_sock *inetsk;
+	struct sctp_af *af;
 	int err = 0;
 
 	/* An association cannot be branched off from an already peeled-off
@@ -3571,8 +3582,9 @@
 	/* Make peeled-off sockets more like 1-1 accepted sockets.
 	 * Set the daddr and initialize id to something more random
 	 */
+	af = sctp_get_af_specific(asoc->peer.primary_addr.sa.sa_family);
+	af->to_sk_daddr(&asoc->peer.primary_addr, sk);
 	inetsk = inet_sk(sock->sk);
-	inetsk->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;
 	inetsk->id = asoc->next_tsn ^ jiffies;
 
 	*sockp = sock;
@@ -4343,11 +4355,12 @@
 		err = -EFAULT;
 		goto error;
 	}
-	if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num))
-		return -EFAULT;
+	if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) {
+		err = -EFAULT;
+		goto error;
+	}
 	if (put_user(bytes_copied, optlen))
-		return -EFAULT;
-
+		err = -EFAULT;
 error:
 	kfree(addrs);
 	return err;
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index 961df27..5f467c9 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -241,6 +241,45 @@
 		transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT;
 }
 
+/* this is a complete rip-off from __sk_dst_check
+ * the cookie is always 0 since this is how it's used in the
+ * pmtu code
+ */
+static struct dst_entry *sctp_transport_dst_check(struct sctp_transport *t)
+{
+	struct dst_entry *dst = t->dst;
+
+	if (dst && dst->obsolete && dst->ops->check(dst, 0) == NULL) {
+		dst_release(t->dst);
+		t->dst = NULL;
+		return NULL;
+	}
+
+	return dst;
+}
+
+void sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu)
+{
+	struct dst_entry *dst;
+
+	if (unlikely(pmtu < SCTP_DEFAULT_MINSEGMENT)) {
+		printk(KERN_WARNING "%s: Reported pmtu %d too low, "
+		       "using default minimum of %d\n",
+		       __FUNCTION__, pmtu,
+		       SCTP_DEFAULT_MINSEGMENT);
+		/* Use default minimum segment size and disable
+		 * pmtu discovery on this transport.
+		 */
+		t->pathmtu = SCTP_DEFAULT_MINSEGMENT;
+	} else {
+		t->pathmtu = pmtu;
+	}
+
+	dst = sctp_transport_dst_check(t);
+	if (dst)
+		dst->ops->update_pmtu(dst, pmtu);
+}
+
 /* Caches the dst entry and source address for a transport's destination
  * address.
  */
diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c
index 3ebae14..88aaacd 100644
--- a/net/wireless/sysfs.c
+++ b/net/wireless/sysfs.c
@@ -33,7 +33,7 @@
 			      struct device_attribute *attr,
 			      char *buf)
 {
-	char *addr = dev_to_rdev(dev)->wiphy.perm_addr;
+	unsigned char *addr = dev_to_rdev(dev)->wiphy.perm_addr;
 
 	return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
 		       addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 8e5610d..3645e98 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1052,6 +1052,7 @@
 		".plt",  /* seen on ARCH=um build on x86_64. Harmless */
 		"__ftr_fixup",		/* powerpc cpu feature fixup */
 		"__fw_ftr_fixup",	/* powerpc firmware feature fixup */
+		".cranges",	/* used by sh64 */
 		NULL
 	};
 	/* Start of section names */
@@ -1132,6 +1133,7 @@
 		".fixup",
 		".smp_locks",
 		".plt",  /* seen on ARCH=um build on x86_64. Harmless */
+		".cranges",	/* used by sh64 */
 		NULL
 	};
 	/* Start of section names */