Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 10 Jul 2013 01:24:39 +0000 (18:24 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 10 Jul 2013 01:24:39 +0000 (18:24 -0700)
Pull networking updates from David Miller:
 "This is a re-do of the net-next pull request for the current merge
  window.  The only difference from the one I made the other day is that
  this has Eliezer's interface renames and the timeout handling changes
  made based upon your feedback, as well as a few bug fixes that have
  trickeled in.

  Highlights:

   1) Low latency device polling, eliminating the cost of interrupt
      handling and context switches.  Allows direct polling of a network
      device from socket operations, such as recvmsg() and poll().

      Currently ixgbe, mlx4, and bnx2x support this feature.

      Full high level description, performance numbers, and design in
      commit 0a4db187a999 ("Merge branch 'll_poll'")

      From Eliezer Tamir.

   2) With the routing cache removed, ip_check_mc_rcu() gets exercised
      more than ever before in the case where we have lots of multicast
      addresses.  Use a hash table instead of a simple linked list, from
      Eric Dumazet.

   3) Add driver for Atheros CQA98xx 802.11ac wireless devices, from
      Bartosz Markowski, Janusz Dziedzic, Kalle Valo, Marek Kwaczynski,
      Marek Puzyniak, Michal Kazior, and Sujith Manoharan.

   4) Support reporting the TUN device persist flag to userspace, from
      Pavel Emelyanov.

   5) Allow controlling network device VF link state using netlink, from
      Rony Efraim.

   6) Support GRE tunneling in openvswitch, from Pravin B Shelar.

   7) Adjust SOCK_MIN_RCVBUF and SOCK_MIN_SNDBUF for modern times, from
      Daniel Borkmann and Eric Dumazet.

   8) Allow controlling of TCP quickack behavior on a per-route basis,
      from Cong Wang.

   9) Several bug fixes and improvements to vxlan from Stephen
      Hemminger, Pravin B Shelar, and Mike Rapoport.  In particular,
      support receiving on multiple UDP ports.

  10) Major cleanups, particular in the area of debugging and cookie
      lifetime handline, to the SCTP protocol code.  From Daniel
      Borkmann.

  11) Allow packets to cross network namespaces when traversing tunnel
      devices.  From Nicolas Dichtel.

  12) Allow monitoring netlink traffic via AF_PACKET sockets, in a
      manner akin to how we monitor real network traffic via ptype_all.
      From Daniel Borkmann.

  13) Several bug fixes and improvements for the new alx device driver,
      from Johannes Berg.

  14) Fix scalability issues in the netem packet scheduler's time queue,
      by using an rbtree.  From Eric Dumazet.

  15) Several bug fixes in TCP loss recovery handling, from Yuchung
      Cheng.

  16) Add support for GSO segmentation of MPLS packets, from Simon
      Horman.

  17) Make network notifiers have a real data type for the opaque
      pointer that's passed into them.  Use this to properly handle
      network device flag changes in arp_netdev_event().  From Jiri
      Pirko and Timo Teräs.

  18) Convert several drivers over to module_pci_driver(), from Peter
      Huewe.

  19) tcp_fixup_rcvbuf() can loop 500 times over loopback, just use a
      O(1) calculation instead.  From Eric Dumazet.

  20) Support setting of explicit tunnel peer addresses in ipv6, just
      like ipv4.  From Nicolas Dichtel.

  21) Protect x86 BPF JIT against spraying attacks, from Eric Dumazet.

  22) Prevent a single high rate flow from overruning an individual cpu
      during RX packet processing via selective flow shedding.  From
      Willem de Bruijn.

  23) Don't use spinlocks in TCP md5 signing fast paths, from Eric
      Dumazet.

  24) Don't just drop GSO packets which are above the TBF scheduler's
      burst limit, chop them up so they are in-bounds instead.  Also
      from Eric Dumazet.

  25) VLAN offloads are missed when configured on top of a bridge, fix
      from Vlad Yasevich.

  26) Support IPV6 in ping sockets.  From Lorenzo Colitti.

  27) Receive flow steering targets should be updated at poll() time
      too, from David Majnemer.

  28) Fix several corner case regressions in PMTU/redirect handling due
      to the routing cache removal, from Timo Teräs.

  29) We have to be mindful of ipv4 mapped ipv6 sockets in
      upd_v6_push_pending_frames().  From Hannes Frederic Sowa.

  30) Fix L2TP sequence number handling bugs, from James Chapman."

* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1214 commits)
  drivers/net: caif: fix wrong rtnl_is_locked() usage
  drivers/net: enic: release rtnl_lock on error-path
  vhost-net: fix use-after-free in vhost_net_flush
  net: mv643xx_eth: do not use port number as platform device id
  net: sctp: confirm route during forward progress
  virtio_net: fix race in RX VQ processing
  virtio: support unlocked queue poll
  net/cadence/macb: fix bug/typo in extracting gem_irq_read_clear bit
  Documentation: Fix references to defunct linux-net@vger.kernel.org
  net/fs: change busy poll time accounting
  net: rename low latency sockets functions to busy poll
  bridge: fix some kernel warning in multicast timer
  sfc: Fix memory leak when discarding scattered packets
  sit: fix tunnel update via netlink
  dt:net:stmmac: Add dt specific phy reset callback support.
  dt:net:stmmac: Add support to dwmac version 3.610 and 3.710
  dt:net:stmmac: Allocate platform data only if its NULL.
  net:stmmac: fix memleak in the open method
  ipv6: rt6_check_neigh should successfully verify neigh if no NUD information are available
  net: ipv6: fix wrong ping_v6_sendmsg return value
  ...

50 files changed:
1  2 
Documentation/devicetree/bindings/vendor-prefixes.txt
Documentation/networking/netlink_mmap.txt
Documentation/sysctl/net.txt
MAINTAINERS
arch/arm/boot/dts/am335x-bone.dts
arch/arm/boot/dts/am335x-evm.dts
arch/arm/boot/dts/am335x-evmsk.dts
arch/arm/boot/dts/sun4i-a10-cubieboard.dts
arch/arm/boot/dts/sun4i-a10.dtsi
arch/arm/configs/omap2plus_defconfig
arch/arm/mach-imx/Kconfig
arch/arm/mach-mxs/Kconfig
arch/arm/mach-mxs/mach-mxs.c
arch/arm/mach-shmobile/board-armadillo800eva.c
arch/arm/mach-shmobile/clock-r8a7740.c
arch/arm/mach-shmobile/clock-r8a7778.c
arch/arm/mach-shmobile/clock-r8a7779.c
arch/cris/arch-v32/drivers/Kconfig
arch/powerpc/Kconfig
drivers/net/ethernet/ibm/ehea/ehea_main.c
drivers/net/ethernet/intel/igb/e1000_phy.c
drivers/net/ethernet/mellanox/mlx4/main.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
drivers/net/ethernet/ti/cpsw.c
drivers/net/ethernet/ti/davinci_mdio.c
drivers/net/netconsole.c
drivers/net/phy/phy.c
drivers/net/wireless/ath/ath9k/Kconfig
drivers/net/wireless/ipw2x00/ipw2200.c
drivers/net/wireless/rt2x00/rt2x00dev.c
drivers/net/wireless/rtlwifi/base.c
drivers/nfc/pn533.c
drivers/s390/net/qeth_core_main.c
drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
drivers/scsi/libiscsi_tcp.c
drivers/staging/csr/netdev.c
drivers/staging/rtl8192u/r8192U_core.c
drivers/staging/silicom/bpctl_mod.c
drivers/virtio/virtio_ring.c
fs/select.c
include/linux/ktime.h
include/linux/sched.h
include/linux/virtio.h
lib/vsprintf.c
net/Kconfig
net/bluetooth/hci_core.c
net/bluetooth/hidp/core.c
net/core/netpoll.c
net/ipv4/inet_fragment.c
net/mac80211/main.c

@@@ -18,6 -18,7 +18,7 @@@ chrp  Common Hardware Reference Platfor
  cirrus        Cirrus Logic, Inc.
  cortina       Cortina Systems, Inc.
  dallas        Maxim Integrated Products (formerly Dallas Semiconductor)
+ davicom       DAVICOM Semiconductor, Inc.
  denx  Denx Software Engineering
  emmicro       EM Microelectronic
  epson Seiko Epson Corp.
@@@ -31,7 -32,6 +32,7 @@@ idt   Integrated Device Technologies, Inc
  img   Imagination Technologies Ltd.
  intercontrol  Inter Control Group
  linux Linux-specific binding
 +lsi   LSI Corp. (LSI Logic)
  marvell       Marvell Technology Group Ltd.
  maxim Maxim Integrated Products
  mosaixtech    Mosaix Technologies, Inc.
@@@ -58,10 -58,8 +59,10 @@@ snps        Synopsys, Inc
  st    STMicroelectronics
  ste   ST-Ericsson
  stericsson    ST-Ericsson
 +toumaz        Toumaz
  ti    Texas Instruments
  toshiba       Toshiba Corporation
 +v3    V3 Semiconductor
  via   VIA Technologies, Inc.
  wlf   Wolfson Microelectronics
  wm    Wondermedia Technologies, Inc.
@@@ -113,8 -113,8 +113,8 @@@ Some parameters are constrained, specif
  
  - nm_frame_nr must equal the actual number of frames as specified above.
  
 -When the kernel can't allocate phsyically continuous memory for a ring block,
 +When the kernel can't allocate physically continuous memory for a ring block,
- it will fall back to use physically discontinous memory. This might affect
+ it will fall back to use physically discontinuous memory. This might affect
  performance negatively, in order to avoid this the nm_frame_size parameter
  should be chosen to be as small as possible for the required frame size and
  the number of blocks should be increased instead.
@@@ -274,9 -274,9 +274,9 @@@ This example assumes some ring paramete
                        /* Get next frame header */
                        hdr = rx_ring + frame_offset;
  
-                       if (hdr->nm_status == NL_MMAP_STATUS_VALID)
+                       if (hdr->nm_status == NL_MMAP_STATUS_VALID) {
                                /* Regular memory mapped frame */
-                               nlh = (void *hdr) + NL_MMAP_HDRLEN;
+                               nlh = (void *)hdr + NL_MMAP_HDRLEN;
                                len = hdr->nm_len;
  
                                /* Release empty message immediately. May happen
@@@ -1,4 -1,4 +1,4 @@@
 -Documentation for /proc/sys/net/*     kernel version 2.4.0-test11-pre4
 +Documentation for /proc/sys/net/*
        (c) 1999                Terrehon Bowden <terrehon@pacbell.net>
                                Bodo Bauer <bb@ricochet.net>
        (c) 2000                Jorge Nerin <comandante@zaralinux.com>
@@@ -9,10 -9,10 +9,10 @@@ For general info and legal blurb, pleas
  ==============================================================
  
  This file contains the documentation for the sysctl files in
 -/proc/sys/net and is valid for Linux kernel version 2.4.0-test11-pre4.
 +/proc/sys/net
  
  The interface  to  the  networking  parts  of  the  kernel  is  located  in
 -/proc/sys/net. The following table shows all possible subdirectories.You may
 +/proc/sys/net. The following table shows all possible subdirectories.  You may
  see only some of them, depending on your kernel's configuration.
  
  
@@@ -26,7 -26,7 +26,7 @@@ Table : Subdirectories in /proc/sys/ne
   ipv4      IP version 4        x25        X.25 protocol
   ipx       IPX                 token-ring IBM token ring
   bridge    Bridging            decnet     DEC net
-  ipv6      IP version 6
+  ipv6      IP version 6        tipc       TIPC
  ..............................................................................
  
  1. /proc/sys/net/core - Network core options
@@@ -50,6 -50,29 +50,29 @@@ The maximum number of packets that kern
  it's a Per-CPU variable.
  Default: 64
  
+ low_latency_read
+ ----------------
+ Low latency busy poll timeout for socket reads. (needs CONFIG_NET_LL_RX_POLL)
+ Approximate time in us to busy loop waiting for packets on the device queue.
+ This sets the default value of the SO_LL socket option.
+ Can be set or overridden per socket by setting socket option SO_LL, which is
+ the preferred method of enabling.
+ If you need to enable the feature globally via sysctl, a value of 50 is recommended.
+ Will increase power usage.
+ Default: 0 (off)
+ low_latency_poll
+ ----------------
+ Low latency busy poll timeout for poll and select. (needs CONFIG_NET_LL_RX_POLL)
+ Approximate time in us to busy loop waiting for events.
+ Recommended value depends on the number of sockets you poll on.
+ For several sockets 50, for several hundreds 100.
+ For more than that you probably want to use epoll.
+ Note that only sockets with SO_LL set will be busy polled, so you want to either
+ selectively set SO_LL on those sockets or set sysctl.net.low_latency_read globally.
+ Will increase power usage.
+ Default: 0 (off)
  rmem_default
  ------------
  
@@@ -93,8 -116,7 +116,7 @@@ netdev_budge
  
  Maximum number of packets taken from all interfaces in one polling cycle (NAPI
  poll). In one polling cycle interfaces which are registered to polling are
- probed in a round-robin manner. The limit of packets in one such probe can be
- set per-device via sysfs class/net/<device>/weight .
+ probed in a round-robin manner.
  
  netdev_max_backlog
  ------------------
@@@ -201,3 -223,18 +223,18 @@@ IPX
  The /proc/net/ipx_route  table  holds  a list of IPX routes. For each route it
  gives the  destination  network, the router node (or Directly) and the network
  address of the router (or Connected) for internal networks.
+ 6. TIPC
+ -------------------------------------------------------
+ The TIPC protocol now has a tunable for the receive memory, similar to the
+ tcp_rmem - i.e. a vector of 3 INTEGERs: (min, default, max)
+     # cat /proc/sys/net/tipc/tipc_rmem
+     4252725 34021800        68043600
+     #
+ The max value is set to CONN_OVERLOAD_LIMIT, and the default and min values
+ are scaled (shifted) versions of that same value.  Note that the min value
+ is not at this point in time used in any meaningful way, but the triplet is
+ preserved in order to be consistent with things like tcp_rmem.
diff --combined MAINTAINERS
@@@ -180,11 -180,6 +180,11 @@@ T:       git git://git.kernel.org/pub/scm/lin
  S:    Maintained
  F:    Documentation/filesystems/9p.txt
  F:    fs/9p/
 +F:    net/9p/
 +F:    include/net/9p/
 +F:    include/uapi/linux/virtio_9p.h
 +F:    include/trace/events/9p.h
 +
  
  A8293 MEDIA DRIVER
  M:    Antti Palosaari <crope@iki.fi>
@@@ -247,11 -242,6 +247,11 @@@ F:       drivers/acpi
  F:    drivers/pnp/pnpacpi/
  F:    include/linux/acpi.h
  F:    include/acpi/
 +F:    Documentation/acpi
 +F:    Documentation/ABI/testing/sysfs-bus-acpi
 +F:    drivers/pci/*acpi*
 +F:    drivers/pci/*/*acpi*
 +F:    drivers/pci/*/*/*acpi*
  
  ACPI FAN DRIVER
  M:    Zhang Rui <rui.zhang@intel.com>
@@@ -807,7 -797,6 +807,7 @@@ F: arch/arm/mach-gemini
  ARM/CSR SIRFPRIMA2 MACHINE SUPPORT
  M:    Barry Song <baohua.song@csr.com>
  L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/baohua/linux.git
  S:    Maintained
  F:    arch/arm/mach-prima2/
  F:    drivers/dma/sirf-dma.c
@@@ -1146,7 -1135,6 +1146,7 @@@ L:      linux-samsung-soc@vger.kernel.org (m
  S:    Maintained
  F:    arch/arm/mach-s5p*/
  F:    arch/arm/mach-exynos*/
 +N:    exynos
  
  ARM/SAMSUNG MOBILE MACHINE SUPPORT
  M:    Kyungmin Park <kyungmin.park@samsung.com>
@@@ -1213,15 -1201,6 +1213,15 @@@ M:    Dinh Nguyen <dinguyen@altera.com
  S:    Maintained
  F:    drivers/clk/socfpga/
  
 +ARM/STI ARCHITECTURE
 +M:    Srinivas Kandagatla <srinivas.kandagatla@st.com>
 +M:    Stuart Menefy <stuart.menefy@st.com>
 +L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 +L:    kernel@stlinux.com
 +W:    http://www.stlinux.com
 +S:    Maintained
 +F:    arch/arm/mach-sti/
 +
  ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT
  M:    Lennert Buytenhek <kernel@wantstofly.org>
  L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@@ -1306,7 -1285,6 +1306,7 @@@ S:      Maintaine
  F:    arch/arm/mach-vt8500/
  F:    drivers/clocksource/vt8500_timer.c
  F:    drivers/gpio/gpio-vt8500.c
 +F:    drivers/i2c/busses/i2c-wmt.c
  F:    drivers/mmc/host/wmt-sdmmc.c
  F:    drivers/pwm/pwm-vt8500.c
  F:    drivers/rtc/rtc-vt8500.c
@@@ -1331,7 -1309,6 +1331,7 @@@ W:      http://wiki.xilinx.co
  T:    git git://git.xilinx.com/linux-xlnx.git
  S:    Supported
  F:    arch/arm/mach-zynq/
 +F:    drivers/cpuidle/cpuidle-zynq.c
  
  ARM64 PORT (AARCH64 ARCHITECTURE)
  M:    Catalin Marinas <catalin.marinas@arm.com>
@@@ -1623,7 -1600,6 +1623,7 @@@ F:      drivers/net/wireless/b43legacy
  
  BACKLIGHT CLASS/SUBSYSTEM
  M:    Richard Purdie <rpurdie@rpsys.net>
 +M:    Jingoo Han <jg1.han@samsung.com>
  S:    Maintained
  F:    drivers/video/backlight/
  F:    include/linux/backlight.h
@@@ -1882,13 -1858,6 +1882,13 @@@ S:    Odd fixe
  F:    Documentation/video4linux/bttv/
  F:    drivers/media/pci/bt8xx/bttv*
  
 +BUSLOGIC SCSI DRIVER
 +M:    Khalid Aziz <khalid@gonehiking.org>
 +L:    linux-scsi@vger.kernel.org
 +S:    Maintained
 +F:    drivers/scsi/BusLogic.*
 +F:    drivers/scsi/FlashPoint.*
 +
  C-MEDIA CMI8788 DRIVER
  M:    Clemens Ladisch <clemens@ladisch.de>
  L:    alsa-devel@alsa-project.org (moderated for non-subscribers)
@@@ -2151,10 -2120,9 +2151,10 @@@ M:    Mike Turquette <mturquette@linaro.or
  L:    linux-arm-kernel@lists.infradead.org (same as CLK API & CLKDEV)
  T:    git git://git.linaro.org/people/mturquette/linux.git
  S:    Maintained
 -F:    drivers/clk/clk.c
 -F:    drivers/clk/clk-*
 +F:    drivers/clk/
 +X:    drivers/clk/clkdev.c
  F:    include/linux/clk-pr*
 +F:    include/linux/clk/
  
  COMMON INTERNET FILE SYSTEM (CIFS)
  M:    Steve French <sfrench@samba.org>
@@@ -2247,8 -2215,7 +2247,8 @@@ M:      Viresh Kumar <viresh.kumar@linaro.or
  L:    cpufreq@vger.kernel.org
  L:    linux-pm@vger.kernel.org
  S:    Maintained
 -T:    git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
 +T:    git git://git.linaro.org/people/vireshk/linux.git (For ARM Updates)
  F:    drivers/cpufreq/
  F:    include/linux/cpufreq.h
  
@@@ -2332,6 -2299,11 +2332,11 @@@ M:    Jaya Kumar <jayakumar.alsa@gmail.com
  S:    Maintained
  F:    sound/pci/cs5535audio/
  
+ CW1200 WLAN driver
+ M:     Solomon Peachy <pizza@shaftnet.org>
+ S:     Maintained
+ F:     drivers/net/wireless/cw1200/
  CX18 VIDEO4LINUX DRIVER
  M:    Andy Walls <awalls@md.metrocast.net>
  L:    ivtv-devel@ivtvdriver.org (moderated for non-subscribers)
@@@ -2549,7 -2521,7 +2554,7 @@@ F:      drivers/usb/dwc3
  DEVICE FREQUENCY (DEVFREQ)
  M:    MyungJoo Ham <myungjoo.ham@samsung.com>
  M:    Kyungmin Park <kyungmin.park@samsung.com>
 -L:    linux-kernel@vger.kernel.org
 +L:    linux-pm@vger.kernel.org
  S:    Maintained
  F:    drivers/devfreq/
  
@@@ -2730,14 -2702,12 +2735,14 @@@ F:   include/drm/exynos
  F:    include/uapi/drm/exynos*
  
  DRM DRIVERS FOR NVIDIA TEGRA
 -M:    Thierry Reding <thierry.reding@avionic-design.de>
 +M:    Thierry Reding <thierry.reding@gmail.com>
 +M:    Terje Bergström <tbergstrom@nvidia.com>
  L:    dri-devel@lists.freedesktop.org
  L:    linux-tegra@vger.kernel.org
 -T:    git git://gitorious.org/thierryreding/linux.git
 +T:    git git://anongit.freedesktop.org/tegra/linux.git
  S:    Maintained
 -F:    drivers/gpu/drm/tegra/
 +F:    drivers/gpu/host1x/
 +F:    include/uapi/drm/tegra_drm.h
  F:    Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt
  
  DSBR100 USB FM RADIO DRIVER
@@@ -3138,13 -3108,6 +3143,13 @@@ M:    Maxim Levitsky <maximlevitsky@gmail.
  S:    Maintained
  F:    drivers/media/rc/ene_ir.*
  
 +ENHANCED ERROR HANDLING (EEH)
 +M:    Gavin Shan <shangw@linux.vnet.ibm.com>
 +L:    linuxppc-dev@lists.ozlabs.org
 +S:    Supported
 +F:    Documentation/powerpc/eeh-pci-error-recovery.txt
 +F:    arch/powerpc/kernel/eeh*.c
 +
  EPSON S1D13XXX FRAMEBUFFER DRIVER
  M:    Kristoffer Ericson <kristoffer.ericson@gmail.com>
  S:    Maintained
@@@ -3351,15 -3314,6 +3356,15 @@@ T:    git git://git.kernel.org/pub/scm/lin
  S:    Odd fixes
  F:    drivers/block/floppy.c
  
 +FMC SUBSYSTEM
 +M:    Alessandro Rubini <rubini@gnudd.com>
 +W:    http://www.ohwr.org/projects/fmc-bus
 +S:    Supported
 +F:    drivers/fmc/
 +F:    include/linux/fmc*.h
 +F:    include/linux/ipmi-fru.h
 +K:    fmc_d.*register
 +
  FPU EMULATOR
  M:    Bill Metzenthen <billm@melbpc.org.au>
  W:    http://floatingpoint.sourceforge.net/emulator/index.html
@@@ -3618,7 -3572,6 +3623,7 @@@ GPIO SUBSYSTE
  M:    Grant Likely <grant.likely@linaro.org>
  M:    Linus Walleij <linus.walleij@linaro.org>
  S:    Maintained
 +L:    linux-gpio@vger.kernel.org
  T:    git git://git.secretlab.ca/git/linux-2.6.git
  F:    Documentation/gpio.txt
  F:    drivers/gpio/
@@@ -4031,8 -3984,7 +4036,8 @@@ S:      Maintaine
  F:    arch/ia64/
  
  IBM Power in-Nest Crypto Acceleration
 -M:    Kent Yoder <key@linux.vnet.ibm.com>
 +M:    Marcelo Henrique Cerri <mhcerri@linux.vnet.ibm.com>
 +M:    Fionnuala Gunter <fin@linux.vnet.ibm.com>
  L:    linux-crypto@vger.kernel.org
  S:    Supported
  F:    drivers/crypto/nx/
@@@ -4161,7 -4113,6 +4166,7 @@@ F:      drivers/ipack
  
  INTEGRITY MEASUREMENT ARCHITECTURE (IMA)
  M:    Mimi Zohar <zohar@us.ibm.com>
 +M:    Dmitry Kasatkin <d.kasatkin@samsung.com>
  S:    Supported
  F:    security/integrity/ima/
  
@@@ -4631,7 -4582,7 +4636,7 @@@ F:      fs/jbd2
  F:    include/linux/jbd2.h
  
  JSM Neo PCI based serial card
 -M:    Lucas Tavares <lucaskt@linux.vnet.ibm.com>
 +M:    Thadeu Lima de Souza Cascardo <cascardo@linux.vnet.ibm.com>
  L:    linux-serial@vger.kernel.org
  S:    Maintained
  F:    drivers/tty/serial/jsm/
@@@ -4765,23 -4716,14 +4770,23 @@@ F:   arch/s390/kvm
  F:    drivers/s390/kvm/
  
  KERNEL VIRTUAL MACHINE (KVM) FOR ARM
 -M:    Christoffer Dall <cdall@cs.columbia.edu>
 +M:    Christoffer Dall <christoffer.dall@linaro.org>
  L:    kvmarm@lists.cs.columbia.edu
  W:    http://systems.cs.columbia.edu/projects/kvm-arm
 -S:    Maintained
 +S:    Supported
  F:    arch/arm/include/uapi/asm/kvm*
  F:    arch/arm/include/asm/kvm*
  F:    arch/arm/kvm/
  
 +KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)
 +M:    Marc Zyngier <marc.zyngier@arm.com>
 +L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 +L:    kvmarm@lists.cs.columbia.edu
 +S:    Maintained
 +F:    arch/arm64/include/uapi/asm/kvm*
 +F:    arch/arm64/include/asm/kvm*
 +F:    arch/arm64/kvm/
 +
  KEXEC
  M:    Eric Biederman <ebiederm@xmission.com>
  W:    http://kernel.org/pub/linux/utils/kernel/kexec/
@@@ -5997,10 -5939,8 +6002,10 @@@ M:    Willem Riede <osst@riede.org
  L:    osst-users@lists.sourceforge.net
  L:    linux-scsi@vger.kernel.org
  S:    Maintained
 -F:    drivers/scsi/osst*
 -F:    drivers/scsi/st*
 +F:    Documentation/scsi/osst.txt
 +F:    drivers/scsi/osst.*
 +F:    drivers/scsi/osst_*.h
 +F:    drivers/scsi/st.h
  
  OPENCORES I2C BUS DRIVER
  M:    Peter Korsgaard <jacmet@sunsite.dk>
@@@ -6214,6 -6154,7 +6219,6 @@@ M:      Linas Vepstas <linasvepstas@gmail.co
  L:    linux-pci@vger.kernel.org
  S:    Supported
  F:    Documentation/PCI/pci-error-recovery.txt
 -F:    Documentation/powerpc/eeh-pci-error-recovery.txt
  
  PCI SUBSYSTEM
  M:    Bjorn Helgaas <bhelgaas@google.com>
@@@ -6329,16 -6270,6 +6334,16 @@@ L:    linux-arm-kernel@lists.infradead.or
  S:    Maintained
  F:    drivers/pinctrl/pinctrl-at91.c
  
 +PIN CONTROLLER - SAMSUNG
 +M:    Tomasz Figa <t.figa@samsung.com>
 +M:    Thomas Abraham <thomas.abraham@linaro.org>
 +L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 +L:    linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
 +S:    Maintained
 +F:    drivers/pinctrl/pinctrl-exynos.*
 +F:    drivers/pinctrl/pinctrl-s3c*
 +F:    drivers/pinctrl/pinctrl-samsung.*
 +
  PIN CONTROLLER - ST SPEAR
  M:    Viresh Kumar <viresh.linux@gmail.com>
  L:    spear-devel@list.st.com
@@@ -7064,7 -6995,8 +7069,7 @@@ SYNOPSYS DESIGNWARE DMAC DRIVE
  M:    Viresh Kumar <viresh.linux@gmail.com>
  S:    Maintained
  F:    include/linux/dw_dmac.h
 -F:    drivers/dma/dw_dmac_regs.h
 -F:    drivers/dma/dw_dmac.c
 +F:    drivers/dma/dw/
  
  SYNOPSYS DESIGNWARE MMC/SD/SDIO DRIVER
  M:    Seungwon Jeon <tgih.jun@samsung.com>
@@@ -7156,8 -7088,7 +7161,8 @@@ M:      Kai Mäkisara <Kai.Makisara@kolumbus
  L:    linux-scsi@vger.kernel.org
  S:    Maintained
  F:    Documentation/scsi/st.txt
 -F:    drivers/scsi/st*
 +F:    drivers/scsi/st.*
 +F:    drivers/scsi/st_*.h
  
  SCTP PROTOCOL
  M:    Vlad Yasevich <vyasevich@gmail.com>
@@@ -7741,7 -7672,6 +7746,7 @@@ STABLE BRANC
  M:    Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  L:    stable@vger.kernel.org
  S:    Supported
 +F:    Documentation/stable_kernel_rules.txt
  
  STAGING SUBSYSTEM
  M:    Greg Kroah-Hartman <gregkh@linuxfoundation.org>
@@@ -7858,7 -7788,7 +7863,7 @@@ F:      drivers/staging/media/solo6x10
  STAGING - SPEAKUP CONSOLE SPEECH DRIVER
  M:    William Hubbs <w.d.hubbs@gmail.com>
  M:    Chris Brannon <chris@the-brannons.com>
 -M:    Kirk Reiser <kirk@braille.uwo.ca>
 +M:    Kirk Reiser <kirk@reisers.ca>
  M:    Samuel Thibault <samuel.thibault@ens-lyon.org>
  L:    speakup@braille.uwo.ca
  W:    http://www.linux-speakup.org/
@@@ -8315,8 -8245,7 +8320,8 @@@ S:      Odd fixe
  F:    drivers/media/usb/tm6000/
  
  TPM DEVICE DRIVER
 -M:    Kent Yoder <key@linux.vnet.ibm.com>
 +M:    Leonidas Da Silva Barbosa <leosilva@linux.vnet.ibm.com>
 +M:    Ashley Lai <ashley@ashleylai.com>
  M:    Rajiv Andrade <mail@srajiv.net>
  W:    http://tpmdd.sourceforge.net
  M:    Marcel Selhorst <tpmdd@selhorst.net>
@@@ -9190,13 -9119,6 +9195,13 @@@ S:    Supporte
  F:    arch/arm/xen/
  F:    arch/arm/include/asm/xen/
  
 +XEN HYPERVISOR ARM64
 +M:    Stefano Stabellini <stefano.stabellini@eu.citrix.com>
 +L:    xen-devel@lists.xensource.com (moderated for non-subscribers)
 +S:    Supported
 +F:    arch/arm64/xen/
 +F:    arch/arm64/include/asm/xen/
 +
  XEN NETWORK BACKEND DRIVER
  M:    Ian Campbell <ian.campbell@citrix.com>
  L:    xen-devel@lists.xensource.com (moderated for non-subscribers)
@@@ -9270,13 -9192,6 +9275,13 @@@ F:    Documentation/networking/z8530drv.tx
  F:    drivers/net/hamradio/*scc.c
  F:    drivers/net/hamradio/z8530.h
  
 +ZBUD COMPRESSED PAGE ALLOCATOR
 +M:    Seth Jennings <sjenning@linux.vnet.ibm.com>
 +L:    linux-mm@kvack.org
 +S:    Maintained
 +F:    mm/zbud.c
 +F:    include/linux/zbud.h
 +
  ZD1211RW WIRELESS DRIVER
  M:    Daniel Drake <dsd@gentoo.org>
  M:    Ulrich Kunitz <kune@deine-taler.de>
@@@ -9299,12 -9214,6 +9304,12 @@@ M:    "Maciej W. Rozycki" <macro@linux-mip
  S:    Maintained
  F:    drivers/tty/serial/zs.*
  
 +ZSWAP COMPRESSED SWAP CACHING
 +M:    Seth Jennings <sjenning@linux.vnet.ibm.com>
 +L:    linux-mm@kvack.org
 +S:    Maintained
 +F:    mm/zswap.c
 +
  THE REST
  M:    Linus Torvalds <torvalds@linux-foundation.org>
  L:    linux-kernel@vger.kernel.org
@@@ -7,7 -7,7 +7,7 @@@
   */
  /dts-v1/;
  
 -/include/ "am33xx.dtsi"
 +#include "am33xx.dtsi"
  
  / {
        model = "TI AM335x BeagleBone";
  
        am33xx_pinmux: pinmux@44e10800 {
                pinctrl-names = "default";
 -              pinctrl-0 = <&user_leds_s0>;
 +              pinctrl-0 = <&clkout2_pin>;
  
                user_leds_s0: user_leds_s0 {
                        pinctrl-single,pins = <
 -                              0x54 0x7        /* gpmc_a5.gpio1_21, OUTPUT | MODE7 */
 -                              0x58 0x17       /* gpmc_a6.gpio1_22, OUTPUT_PULLUP | MODE7 */
 -                              0x5c 0x7        /* gpmc_a7.gpio1_23, OUTPUT | MODE7 */
 -                              0x60 0x17       /* gpmc_a8.gpio1_24, OUTPUT_PULLUP | MODE7 */
 +                              0x54 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_a5.gpio1_21 */
 +                              0x58 (PIN_OUTPUT_PULLUP | MUX_MODE7)    /* gpmc_a6.gpio1_22 */
 +                              0x5c (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_a7.gpio1_23 */
 +                              0x60 (PIN_OUTPUT_PULLUP | MUX_MODE7)    /* gpmc_a8.gpio1_24 */
 +                      >;
 +              };
 +
 +              i2c0_pins: pinmux_i2c0_pins {
 +                      pinctrl-single,pins = <
 +                              0x188 (PIN_INPUT_PULLUP | MUX_MODE0)    /* i2c0_sda.i2c0_sda */
 +                              0x18c (PIN_INPUT_PULLUP | MUX_MODE0)    /* i2c0_scl.i2c0_scl */
 +                      >;
 +              };
 +
 +              uart0_pins: pinmux_uart0_pins {
 +                      pinctrl-single,pins = <
 +                              0x170 (PIN_INPUT_PULLUP | MUX_MODE0)    /* uart0_rxd.uart0_rxd */
 +                              0x174 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* uart0_txd.uart0_txd */
 +                      >;
 +              };
 +
 +              clkout2_pin: pinmux_clkout2_pin {
 +                      pinctrl-single,pins = <
 +                              0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3) /* xdma_event_intr1.clkout2 */
 +                      >;
 +              };
 +
 +              cpsw_default: cpsw_default {
 +                      pinctrl-single,pins = <
 +                              /* Slave 1 */
 +                              0x110 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_rxerr.mii1_rxerr */
 +                              0x114 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mii1_txen.mii1_txen */
 +                              0x118 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_rxdv.mii1_rxdv */
 +                              0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mii1_txd3.mii1_txd3 */
 +                              0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mii1_txd2.mii1_txd2 */
 +                              0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mii1_txd1.mii1_txd1 */
 +                              0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mii1_txd0.mii1_txd0 */
 +                              0x12c (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_txclk.mii1_txclk */
 +                              0x130 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_rxclk.mii1_rxclk */
 +                              0x134 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_rxd3.mii1_rxd3 */
 +                              0x138 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_rxd2.mii1_rxd2 */
 +                              0x13c (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_rxd1.mii1_rxd1 */
 +                              0x140 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mii1_rxd0.mii1_rxd0 */
 +                      >;
 +              };
 +
 +              cpsw_sleep: cpsw_sleep {
 +                      pinctrl-single,pins = <
 +                              /* Slave 1 reset value */
 +                              0x110 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x114 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x118 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x11c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x120 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x124 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x128 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x12c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x130 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x134 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x138 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                      >;
 +              };
 +
 +              davinci_mdio_default: davinci_mdio_default {
 +                      pinctrl-single,pins = <
 +                              /* MDIO */
 +                              0x148 (PIN_INPUT_PULLUP | SLEWCTRL_FAST | MUX_MODE0)    /* mdio_data.mdio_data */
 +                              0x14c (PIN_OUTPUT_PULLUP | MUX_MODE0)                   /* mdio_clk.mdio_clk */
 +                      >;
 +              };
 +
 +              davinci_mdio_sleep: davinci_mdio_sleep {
 +                      pinctrl-single,pins = <
 +                              /* MDIO reset value */
 +                              0x148 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x14c (PIN_INPUT_PULLDOWN | MUX_MODE7)
                        >;
                };
        };
  
        ocp {
 -              uart1: serial@44e09000 {
 +              uart0: serial@44e09000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&uart0_pins>;
 +
                        status = "okay";
                };
  
                i2c0: i2c@44e0b000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&i2c0_pins>;
 +
                        status = "okay";
                        clock-frequency = <400000>;
  
        };
  
        leds {
 +              pinctrl-names = "default";
 +              pinctrl-0 = <&user_leds_s0>;
 +
                compatible = "gpio-leds";
  
                led@2 {
                        label = "beaglebone:green:heartbeat";
 -                      gpios = <&gpio1 21 0>;
 +                      gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;
                        linux,default-trigger = "heartbeat";
                        default-state = "off";
                };
  
                led@3 {
                        label = "beaglebone:green:mmc0";
 -                      gpios = <&gpio1 22 0>;
 +                      gpios = <&gpio1 22 GPIO_ACTIVE_HIGH>;
                        linux,default-trigger = "mmc0";
                        default-state = "off";
                };
  
                led@4 {
                        label = "beaglebone:green:usr2";
 -                      gpios = <&gpio1 23 0>;
 +                      gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>;
                        default-state = "off";
                };
  
                led@5 {
                        label = "beaglebone:green:usr3";
 -                      gpios = <&gpio1 24 0>;
 +                      gpios = <&gpio1 24 GPIO_ACTIVE_HIGH>;
                        default-state = "off";
                };
        };
  
  &cpsw_emac0 {
        phy_id = <&davinci_mdio>, <0>;
+       phy-mode = "mii";
  };
  
  &cpsw_emac1 {
        phy_id = <&davinci_mdio>, <1>;
+       phy-mode = "mii";
  };
 +
 +&mac {
 +      pinctrl-names = "default", "sleep";
 +      pinctrl-0 = <&cpsw_default>;
 +      pinctrl-1 = <&cpsw_sleep>;
 +
 +};
 +
 +&davinci_mdio {
 +      pinctrl-names = "default", "sleep";
 +      pinctrl-0 = <&davinci_mdio_default>;
 +      pinctrl-1 = <&davinci_mdio_sleep>;
 +};
@@@ -7,7 -7,7 +7,7 @@@
   */
  /dts-v1/;
  
 -/include/ "am33xx.dtsi"
 +#include "am33xx.dtsi"
  
  / {
        model = "TI AM335x EVM";
  
        am33xx_pinmux: pinmux@44e10800 {
                pinctrl-names = "default";
 -              pinctrl-0 = <&matrix_keypad_s0 &volume_keys_s0>;
 +              pinctrl-0 = <&matrix_keypad_s0 &volume_keys_s0 &clkout2_pin>;
  
                matrix_keypad_s0: matrix_keypad_s0 {
                        pinctrl-single,pins = <
 -                              0x54 0x7        /* gpmc_a5.gpio1_21, OUTPUT | MODE7 */
 -                              0x58 0x7        /* gpmc_a6.gpio1_22, OUTPUT | MODE7 */
 -                              0x64 0x27       /* gpmc_a9.gpio1_25, INPUT | MODE7 */
 -                              0x68 0x27       /* gpmc_a10.gpio1_26, INPUT | MODE7 */
 -                              0x6c 0x27       /* gpmc_a11.gpio1_27, INPUT | MODE7 */
 +                              0x54 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_a5.gpio1_21 */
 +                              0x58 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_a6.gpio1_22 */
 +                              0x64 (PIN_INPUT_PULLDOWN | MUX_MODE7)   /* gpmc_a9.gpio1_25 */
 +                              0x68 (PIN_INPUT_PULLDOWN | MUX_MODE7)   /* gpmc_a10.gpio1_26 */
 +                              0x6c (PIN_INPUT_PULLDOWN | MUX_MODE7)   /* gpmc_a11.gpio1_27 */
                        >;
                };
  
                volume_keys_s0: volume_keys_s0 {
                        pinctrl-single,pins = <
 -                              0x150 0x27      /* spi0_sclk.gpio0_2, INPUT | MODE7 */
 -                              0x154 0x27      /* spi0_d0.gpio0_3, INPUT | MODE7 */
 +                              0x150 (PIN_INPUT_PULLDOWN | MUX_MODE7)  /* spi0_sclk.gpio0_2 */
 +                              0x154 (PIN_INPUT_PULLDOWN | MUX_MODE7)  /* spi0_d0.gpio0_3 */
 +                      >;
 +              };
 +
 +              i2c0_pins: pinmux_i2c0_pins {
 +                      pinctrl-single,pins = <
 +                              0x188 (PIN_INPUT_PULLUP | MUX_MODE0)    /* i2c0_sda.i2c0_sda */
 +                              0x18c (PIN_INPUT_PULLUP | MUX_MODE0)    /* i2c0_scl.i2c0_scl */
 +                      >;
 +              };
 +
 +              i2c1_pins: pinmux_i2c1_pins {
 +                      pinctrl-single,pins = <
 +                              0x158 (PIN_INPUT_PULLUP | MUX_MODE2)    /* spi0_d1.i2c1_sda */
 +                              0x15c (PIN_INPUT_PULLUP | MUX_MODE2)    /* spi0_cs0.i2c1_scl */
 +                      >;
 +              };
 +
 +              uart0_pins: pinmux_uart0_pins {
 +                      pinctrl-single,pins = <
 +                              0x170 (PIN_INPUT_PULLUP | MUX_MODE0)    /* uart0_rxd.uart0_rxd */
 +                              0x174 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* uart0_txd.uart0_txd */
 +                      >;
 +              };
 +
 +              clkout2_pin: pinmux_clkout2_pin {
 +                      pinctrl-single,pins = <
 +                              0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3) /* xdma_event_intr1.clkout2 */
 +                      >;
 +              };
 +
 +              nandflash_pins_s0: nandflash_pins_s0 {
 +                      pinctrl-single,pins = <
 +                              0x0 (PIN_INPUT_PULLUP | MUX_MODE0)      /* gpmc_ad0.gpmc_ad0 */
 +                              0x4 (PIN_INPUT_PULLUP | MUX_MODE0)      /* gpmc_ad1.gpmc_ad1 */
 +                              0x8 (PIN_INPUT_PULLUP | MUX_MODE0)      /* gpmc_ad2.gpmc_ad2 */
 +                              0xc (PIN_INPUT_PULLUP | MUX_MODE0)      /* gpmc_ad3.gpmc_ad3 */
 +                              0x10 (PIN_INPUT_PULLUP | MUX_MODE0)     /* gpmc_ad4.gpmc_ad4 */
 +                              0x14 (PIN_INPUT_PULLUP | MUX_MODE0)     /* gpmc_ad5.gpmc_ad5 */
 +                              0x18 (PIN_INPUT_PULLUP | MUX_MODE0)     /* gpmc_ad6.gpmc_ad6 */
 +                              0x1c (PIN_INPUT_PULLUP | MUX_MODE0)     /* gpmc_ad7.gpmc_ad7 */
 +                              0x70 (PIN_INPUT_PULLUP | MUX_MODE0)     /* gpmc_wait0.gpmc_wait0 */
 +                              0x74 (PIN_INPUT_PULLUP | MUX_MODE7)     /* gpmc_wpn.gpio0_30 */
 +                              0x7c (PIN_OUTPUT | MUX_MODE0)           /* gpmc_csn0.gpmc_csn0  */
 +                              0x90 (PIN_OUTPUT | MUX_MODE0)           /* gpmc_advn_ale.gpmc_advn_ale */
 +                              0x94 (PIN_OUTPUT | MUX_MODE0)           /* gpmc_oen_ren.gpmc_oen_ren */
 +                              0x98 (PIN_OUTPUT | MUX_MODE0)           /* gpmc_wen.gpmc_wen */
 +                              0x9c (PIN_OUTPUT | MUX_MODE0)           /* gpmc_be0n_cle.gpmc_be0n_cle */
 +                      >;
 +              };
 +
 +              ecap0_pins: backlight_pins {
 +                      pinctrl-single,pins = <
 +                              0x164 0x0       /* eCAP0_in_PWM0_out.eCAP0_in_PWM0_out MODE0 */
 +                      >;
 +              };
 +
 +              cpsw_default: cpsw_default {
 +                      pinctrl-single,pins = <
 +                              /* Slave 1 */
 +                              0x114 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txen.rgmii1_tctl */
 +                              0x118 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxdv.rgmii1_rctl */
 +                              0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd3.rgmii1_td3 */
 +                              0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd2.rgmii1_td2 */
 +                              0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd1.rgmii1_td1 */
 +                              0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd0.rgmii1_td0 */
 +                              0x12c (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txclk.rgmii1_tclk */
 +                              0x130 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxclk.rgmii1_rclk */
 +                              0x134 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd3.rgmii1_rd3 */
 +                              0x138 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd2.rgmii1_rd2 */
 +                              0x13c (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd1.rgmii1_rd1 */
 +                              0x140 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd0.rgmii1_rd0 */
 +                      >;
 +              };
 +
 +              cpsw_sleep: cpsw_sleep {
 +                      pinctrl-single,pins = <
 +                              /* Slave 1 reset value */
 +                              0x114 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x118 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x11c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x120 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x124 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x128 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x12c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x130 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x134 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x138 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                      >;
 +              };
 +
 +              davinci_mdio_default: davinci_mdio_default {
 +                      pinctrl-single,pins = <
 +                              /* MDIO */
 +                              0x148 (PIN_INPUT_PULLUP | SLEWCTRL_FAST | MUX_MODE0)    /* mdio_data.mdio_data */
 +                              0x14c (PIN_OUTPUT_PULLUP | MUX_MODE0)                   /* mdio_clk.mdio_clk */
 +                      >;
 +              };
 +
 +              davinci_mdio_sleep: davinci_mdio_sleep {
 +                      pinctrl-single,pins = <
 +                              /* MDIO reset value */
 +                              0x148 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x14c (PIN_INPUT_PULLDOWN | MUX_MODE7)
                        >;
                };
        };
  
        ocp {
 -              uart1: serial@44e09000 {
 +              uart0: serial@44e09000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&uart0_pins>;
 +
                        status = "okay";
                };
  
                i2c0: i2c@44e0b000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&i2c0_pins>;
 +
                        status = "okay";
                        clock-frequency = <400000>;
  
                };
  
                i2c1: i2c@4802a000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&i2c1_pins>;
 +
                        status = "okay";
                        clock-frequency = <100000>;
  
                                reg = <0x48>;
                        };
                };
 +
 +              elm: elm@48080000 {
 +                      status = "okay";
 +              };
 +
 +              epwmss0: epwmss@48300000 {
 +                      status = "okay";
 +
 +                      ecap0: ecap@48300100 {
 +                              status = "okay";
 +                              pinctrl-names = "default";
 +                              pinctrl-0 = <&ecap0_pins>;
 +                      };
 +              };
 +
 +              gpmc: gpmc@50000000 {
 +                      status = "okay";
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&nandflash_pins_s0>;
 +                      ranges = <0 0 0x08000000 0x10000000>;   /* CS0: NAND */
 +                      nand@0,0 {
 +                              reg = <0 0 0>; /* CS0, offset 0 */
 +                              nand-bus-width = <8>;
 +                              ti,nand-ecc-opt = "bch8";
 +                              gpmc,device-nand = "true";
 +                              gpmc,device-width = <1>;
 +                              gpmc,sync-clk-ps = <0>;
 +                              gpmc,cs-on-ns = <0>;
 +                              gpmc,cs-rd-off-ns = <44>;
 +                              gpmc,cs-wr-off-ns = <44>;
 +                              gpmc,adv-on-ns = <6>;
 +                              gpmc,adv-rd-off-ns = <34>;
 +                              gpmc,adv-wr-off-ns = <44>;
 +                              gpmc,we-on-ns = <0>;
 +                              gpmc,we-off-ns = <40>;
 +                              gpmc,oe-on-ns = <0>;
 +                              gpmc,oe-off-ns = <54>;
 +                              gpmc,access-ns = <64>;
 +                              gpmc,rd-cycle-ns = <82>;
 +                              gpmc,wr-cycle-ns = <82>;
 +                              gpmc,wait-on-read = "true";
 +                              gpmc,wait-on-write = "true";
 +                              gpmc,bus-turnaround-ns = <0>;
 +                              gpmc,cycle2cycle-delay-ns = <0>;
 +                              gpmc,clk-activation-ns = <0>;
 +                              gpmc,wait-monitoring-ns = <0>;
 +                              gpmc,wr-access-ns = <40>;
 +                              gpmc,wr-data-mux-bus-ns = <0>;
 +
 +                              #address-cells = <1>;
 +                              #size-cells = <1>;
 +                              elm_id = <&elm>;
 +
 +                              /* MTD partition table */
 +                              partition@0 {
 +                                      label = "SPL1";
 +                                      reg = <0x00000000 0x000020000>;
 +                              };
 +
 +                              partition@1 {
 +                                      label = "SPL2";
 +                                      reg = <0x00020000 0x00020000>;
 +                              };
 +
 +                              partition@2 {
 +                                      label = "SPL3";
 +                                      reg = <0x00040000 0x00020000>;
 +                              };
 +
 +                              partition@3 {
 +                                      label = "SPL4";
 +                                      reg = <0x00060000 0x00020000>;
 +                              };
 +
 +                              partition@4 {
 +                                      label = "U-boot";
 +                                      reg = <0x00080000 0x001e0000>;
 +                              };
 +
 +                              partition@5 {
 +                                      label = "environment";
 +                                      reg = <0x00260000 0x00020000>;
 +                              };
 +
 +                              partition@6 {
 +                                      label = "Kernel";
 +                                      reg = <0x00280000 0x00500000>;
 +                              };
 +
 +                              partition@7 {
 +                                      label = "File-System";
 +                                      reg = <0x00780000 0x0F880000>;
 +                              };
 +                      };
 +              };
        };
  
        vbat: fixedregulator@0 {
                debounce-delay-ms = <5>;
                col-scan-delay-us = <2>;
  
 -              row-gpios = <&gpio1 25 0        /* Bank1, pin25 */
 -                           &gpio1 26 0        /* Bank1, pin26 */
 -                           &gpio1 27 0>;      /* Bank1, pin27 */
 +              row-gpios = <&gpio1 25 GPIO_ACTIVE_HIGH         /* Bank1, pin25 */
 +                           &gpio1 26 GPIO_ACTIVE_HIGH         /* Bank1, pin26 */
 +                           &gpio1 27 GPIO_ACTIVE_HIGH>;       /* Bank1, pin27 */
  
 -              col-gpios = <&gpio1 21 0        /* Bank1, pin21 */
 -                           &gpio1 22 0>;      /* Bank1, pin22 */
 +              col-gpios = <&gpio1 21 GPIO_ACTIVE_HIGH         /* Bank1, pin21 */
 +                           &gpio1 22 GPIO_ACTIVE_HIGH>;       /* Bank1, pin22 */
  
                linux,keymap = <0x0000008b      /* MENU */
                                0x0100009e      /* BACK */
                switch@9 {
                        label = "volume-up";
                        linux,code = <115>;
 -                      gpios = <&gpio0 2 1>;
 +                      gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
                        gpio-key,wakeup;
                };
  
                switch@10 {
                        label = "volume-down";
                        linux,code = <114>;
 -                      gpios = <&gpio0 3 1>;
 +                      gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
                        gpio-key,wakeup;
                };
        };
 +
 +      backlight {
 +              compatible = "pwm-backlight";
 +              pwms = <&ecap0 0 50000 0>;
 +              brightness-levels = <0 51 53 56 62 75 101 152 255>;
 +              default-brightness-level = <8>;
 +      };
  };
  
 -/include/ "tps65910.dtsi"
 +#include "tps65910.dtsi"
  
  &tps {
        vcc1-supply = <&vbat>;
        };
  };
  
 +&mac {
 +      pinctrl-names = "default", "sleep";
 +      pinctrl-0 = <&cpsw_default>;
 +      pinctrl-1 = <&cpsw_sleep>;
 +};
 +
 +&davinci_mdio {
 +      pinctrl-names = "default", "sleep";
 +      pinctrl-0 = <&davinci_mdio_default>;
 +      pinctrl-1 = <&davinci_mdio_sleep>;
 +};
 +
  &cpsw_emac0 {
        phy_id = <&davinci_mdio>, <0>;
+       phy-mode = "rgmii-txid";
  };
  
  &cpsw_emac1 {
        phy_id = <&davinci_mdio>, <1>;
+       phy-mode = "rgmii-txid";
  };
@@@ -13,7 -13,7 +13,7 @@@
  
  /dts-v1/;
  
 -/include/ "am33xx.dtsi"
 +#include "am33xx.dtsi"
  
  / {
        model = "TI AM335x EVM-SK";
  
        am33xx_pinmux: pinmux@44e10800 {
                pinctrl-names = "default";
 -              pinctrl-0 = <&user_leds_s0 &gpio_keys_s0>;
 +              pinctrl-0 = <&gpio_keys_s0 &clkout2_pin>;
  
                user_leds_s0: user_leds_s0 {
                        pinctrl-single,pins = <
 -                              0x10 0x7        /* gpmc_ad4.gpio1_4, OUTPUT | MODE7 */
 -                              0x14 0x7        /* gpmc_ad5.gpio1_5, OUTPUT | MODE7 */
 -                              0x18 0x7        /* gpmc_ad6.gpio1_6, OUTPUT | MODE7 */
 -                              0x1c 0x7        /* gpmc_ad7.gpio1_7, OUTPUT | MODE7 */
 +                              0x10 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_ad4.gpio1_4 */
 +                              0x14 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_ad5.gpio1_5 */
 +                              0x18 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_ad6.gpio1_6 */
 +                              0x1c (PIN_OUTPUT_PULLDOWN | MUX_MODE7)  /* gpmc_ad7.gpio1_7 */
                        >;
                };
  
                gpio_keys_s0: gpio_keys_s0 {
                        pinctrl-single,pins = <
 -                              0x94 0x27       /* gpmc_oen_ren.gpio2_3, INPUT | MODE7 */
 -                              0x90 0x27       /* gpmc_advn_ale.gpio2_2, INPUT | MODE7 */
 -                              0x70 0x27       /* gpmc_wait0.gpio0_30, INPUT | MODE7 */
 -                              0x9c 0x27       /* gpmc_ben0_cle.gpio2_5, INPUT | MODE7 */
 +                              0x94 (PIN_INPUT_PULLDOWN | MUX_MODE7)   /* gpmc_oen_ren.gpio2_3 */
 +                              0x90 (PIN_INPUT_PULLDOWN | MUX_MODE7)   /* gpmc_advn_ale.gpio2_2 */
 +                              0x70 (PIN_INPUT_PULLDOWN | MUX_MODE7)   /* gpmc_wait0.gpio0_30 */
 +                              0x9c (PIN_INPUT_PULLDOWN | MUX_MODE7)   /* gpmc_ben0_cle.gpio2_5 */
 +                      >;
 +              };
 +
 +              i2c0_pins: pinmux_i2c0_pins {
 +                      pinctrl-single,pins = <
 +                              0x188 (PIN_INPUT_PULLUP | MUX_MODE0)    /* i2c0_sda.i2c0_sda */
 +                              0x18c (PIN_INPUT_PULLUP | MUX_MODE0)    /* i2c0_scl.i2c0_scl */
 +                      >;
 +              };
 +
 +              uart0_pins: pinmux_uart0_pins {
 +                      pinctrl-single,pins = <
 +                              0x170 (PIN_INPUT_PULLUP | MUX_MODE0)    /* uart0_rxd.uart0_rxd */
 +                              0x174 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)         /* uart0_txd.uart0_txd */
 +                      >;
 +              };
 +
 +              clkout2_pin: pinmux_clkout2_pin {
 +                      pinctrl-single,pins = <
 +                              0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3)         /* xdma_event_intr1.clkout2 */
 +                      >;
 +              };
 +
 +              ecap2_pins: backlight_pins {
 +                      pinctrl-single,pins = <
 +                              0x19c 0x4       /* mcasp0_ahclkr.ecap2_in_pwm2_out MODE4 */
 +                      >;
 +              };
 +
 +              cpsw_default: cpsw_default {
 +                      pinctrl-single,pins = <
 +                              /* Slave 1 */
 +                              0x114 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txen.rgmii1_tctl */
 +                              0x118 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxdv.rgmii1_rctl */
 +                              0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd3.rgmii1_td3 */
 +                              0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd2.rgmii1_td2 */
 +                              0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd1.rgmii1_td1 */
 +                              0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txd0.rgmii1_td0 */
 +                              0x12c (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mii1_txclk.rgmii1_tclk */
 +                              0x130 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxclk.rgmii1_rclk */
 +                              0x134 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd3.rgmii1_rd3 */
 +                              0x138 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd2.rgmii1_rd2 */
 +                              0x13c (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd1.rgmii1_rd1 */
 +                              0x140 (PIN_INPUT_PULLDOWN | MUX_MODE2)  /* mii1_rxd0.rgmii1_rd0 */
 +
 +                              /* Slave 2 */
 +                              0x40 (PIN_OUTPUT_PULLDOWN | MUX_MODE2)  /* gpmc_a0.rgmii2_tctl */
 +                              0x44 (PIN_INPUT_PULLDOWN | MUX_MODE2)   /* gpmc_a1.rgmii2_rctl */
 +                              0x48 (PIN_OUTPUT_PULLDOWN | MUX_MODE2)  /* gpmc_a2.rgmii2_td3 */
 +                              0x4c (PIN_OUTPUT_PULLDOWN | MUX_MODE2)  /* gpmc_a3.rgmii2_td2 */
 +                              0x50 (PIN_OUTPUT_PULLDOWN | MUX_MODE2)  /* gpmc_a4.rgmii2_td1 */
 +                              0x54 (PIN_OUTPUT_PULLDOWN | MUX_MODE2)  /* gpmc_a5.rgmii2_td0 */
 +                              0x58 (PIN_OUTPUT_PULLDOWN | MUX_MODE2)  /* gpmc_a6.rgmii2_tclk */
 +                              0x5c (PIN_INPUT_PULLDOWN | MUX_MODE2)   /* gpmc_a7.rgmii2_rclk */
 +                              0x60 (PIN_INPUT_PULLDOWN | MUX_MODE2)   /* gpmc_a8.rgmii2_rd3 */
 +                              0x64 (PIN_INPUT_PULLDOWN | MUX_MODE2)   /* gpmc_a9.rgmii2_rd2 */
 +                              0x68 (PIN_INPUT_PULLDOWN | MUX_MODE2)   /* gpmc_a10.rgmii2_rd1 */
 +                              0x6c (PIN_INPUT_PULLDOWN | MUX_MODE2)   /* gpmc_a11.rgmii2_rd0 */
 +                      >;
 +              };
 +
 +              cpsw_sleep: cpsw_sleep {
 +                      pinctrl-single,pins = <
 +                              /* Slave 1 reset value */
 +                              0x114 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x118 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x11c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x120 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x124 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x128 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x12c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x130 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x134 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x138 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +
 +                              /* Slave 2 reset value*/
 +                              0x40 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x44 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x48 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x4c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x50 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x54 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x58 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x5c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x60 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x64 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x68 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x6c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                      >;
 +              };
 +
 +              davinci_mdio_default: davinci_mdio_default {
 +                      pinctrl-single,pins = <
 +                              /* MDIO */
 +                              0x148 (PIN_INPUT_PULLUP | SLEWCTRL_FAST | MUX_MODE0)    /* mdio_data.mdio_data */
 +                              0x14c (PIN_OUTPUT_PULLUP | MUX_MODE0)                   /* mdio_clk.mdio_clk */
 +                      >;
 +              };
 +
 +              davinci_mdio_sleep: davinci_mdio_sleep {
 +                      pinctrl-single,pins = <
 +                              /* MDIO reset value */
 +                              0x148 (PIN_INPUT_PULLDOWN | MUX_MODE7)
 +                              0x14c (PIN_INPUT_PULLDOWN | MUX_MODE7)
                        >;
                };
        };
  
        ocp {
 -              uart1: serial@44e09000 {
 +              uart0: serial@44e09000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&uart0_pins>;
 +
                        status = "okay";
                };
  
                i2c0: i2c@44e0b000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&i2c0_pins>;
 +
                        status = "okay";
                        clock-frequency = <400000>;
  
                                st,max-limit-z = <750>;
                        };
                };
 +
 +              epwmss2: epwmss@48304000 {
 +                      status = "okay";
 +
 +                      ecap2: ecap@48304100 {
 +                              status = "okay";
 +                              pinctrl-names = "default";
 +                              pinctrl-0 = <&ecap2_pins>;
 +                      };
 +              };
        };
  
        vbat: fixedregulator@0 {
        };
  
        leds {
 +              pinctrl-names = "default";
 +              pinctrl-0 = <&user_leds_s0>;
 +
                compatible = "gpio-leds";
  
                led@1 {
                        label = "evmsk:green:usr0";
 -                      gpios = <&gpio1 4 0>;
 +                      gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>;
                        default-state = "off";
                };
  
                led@2 {
                        label = "evmsk:green:usr1";
 -                      gpios = <&gpio1 5 0>;
 +                      gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>;
                        default-state = "off";
                };
  
                led@3 {
                        label = "evmsk:green:mmc0";
 -                      gpios = <&gpio1 6 0>;
 +                      gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
                        linux,default-trigger = "mmc0";
                        default-state = "off";
                };
  
                led@4 {
                        label = "evmsk:green:heartbeat";
 -                      gpios = <&gpio1 7 0>;
 +                      gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
                        linux,default-trigger = "heartbeat";
                        default-state = "off";
                };
                switch@1 {
                        label = "button0";
                        linux,code = <0x100>;
 -                      gpios = <&gpio2 3 0>;
 +                      gpios = <&gpio2 3 GPIO_ACTIVE_HIGH>;
                };
  
                switch@2 {
                        label = "button1";
                        linux,code = <0x101>;
 -                      gpios = <&gpio2 2 0>;
 +                      gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>;
                };
  
                switch@3 {
                        label = "button2";
                        linux,code = <0x102>;
 -                      gpios = <&gpio0 30 0>;
 +                      gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>;
                        gpio-key,wakeup;
                };
  
                switch@4 {
                        label = "button3";
                        linux,code = <0x103>;
 -                      gpios = <&gpio2 5 0>;
 +                      gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
                };
        };
 +
 +      backlight {
 +              compatible = "pwm-backlight";
 +              pwms = <&ecap2 0 50000 1>;
 +              brightness-levels = <0 58 61 66 75 90 125 170 255>;
 +              default-brightness-level = <8>;
 +      };
  };
  
 -/include/ "tps65910.dtsi"
 +#include "tps65910.dtsi"
  
  &tps {
        vcc1-supply = <&vbat>;
        };
  };
  
 +&mac {
 +      pinctrl-names = "default", "sleep";
 +      pinctrl-0 = <&cpsw_default>;
 +      pinctrl-1 = <&cpsw_sleep>;
 +};
 +
 +&davinci_mdio {
 +      pinctrl-names = "default", "sleep";
 +      pinctrl-0 = <&davinci_mdio_default>;
 +      pinctrl-1 = <&davinci_mdio_sleep>;
 +};
++
+ &cpsw_emac0 {
+       phy_id = <&davinci_mdio>, <0>;
+       phy-mode = "rgmii-txid";
+ };
+ &cpsw_emac1 {
+       phy_id = <&davinci_mdio>, <1>;
+       phy-mode = "rgmii-txid";
+ };
        };
  
        soc@01c20000 {
+               emac: ethernet@01c0b000 {
+                       pinctrl-names = "default";
+                       pinctrl-0 = <&emac_pins_a>;
+                       phy = <&phy1>;
+                       status = "okay";
+               };
+               mdio@01c0b080 {
+                       status = "okay";
+                       phy1: ethernet-phy@1 {
+                               reg = <1>;
+                       };
+               };
                pinctrl@01c20800 {
                        led_pins_cubieboard: led_pins@0 {
                                allwinner,pins = "PH20", "PH21";
                        pinctrl-0 = <&uart0_pins_a>;
                        status = "okay";
                };
 +
 +              i2c0: i2c@01c2ac00 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&i2c0_pins_a>;
 +                      status = "okay";
 +              };
 +
 +              i2c1: i2c@01c2b000 {
 +                      pinctrl-names = "default";
 +                      pinctrl-0 = <&i2c1_pins_a>;
 +                      status = "okay";
 +              };
        };
  
        leds {
        interrupt-parent = <&intc>;
  
        cpus {
 +              #address-cells = <1>;
 +              #size-cells = <0>;
                cpu@0 {
 +                      device_type = "cpu";
                        compatible = "arm,cortex-a8";
 +                      reg = <0x0>;
                };
        };
  
                reg = <0x01c20000 0x300000>;
                ranges;
  
+               emac: ethernet@01c0b000 {
+                       compatible = "allwinner,sun4i-emac";
+                       reg = <0x01c0b000 0x1000>;
+                       interrupts = <55>;
+                       clocks = <&ahb_gates 17>;
+                       status = "disabled";
+               };
+               mdio@01c0b080 {
+                       compatible = "allwinner,sun4i-mdio";
+                       reg = <0x01c0b080 0x14>;
+                       status = "disabled";
+                       #address-cells = <1>;
+                       #size-cells = <0>;
+               };
                intc: interrupt-controller@01c20400 {
                        compatible = "allwinner,sun4i-ic";
                        reg = <0x01c20400 0x400>;
                pio: pinctrl@01c20800 {
                        compatible = "allwinner,sun4i-a10-pinctrl";
                        reg = <0x01c20800 0x400>;
 +                      interrupts = <28>;
                        clocks = <&apb0_gates 5>;
                        gpio-controller;
 +                      interrupt-controller;
                        #address-cells = <1>;
                        #size-cells = <0>;
                        #gpio-cells = <3>;
                                allwinner,pull = <0>;
                        };
  
 +                      i2c0_pins_a: i2c0@0 {
 +                              allwinner,pins = "PB0", "PB1";
 +                              allwinner,function = "i2c0";
 +                              allwinner,drive = <0>;
 +                              allwinner,pull = <0>;
 +                      };
 +
 +                      i2c1_pins_a: i2c1@0 {
 +                              allwinner,pins = "PB18", "PB19";
 +                              allwinner,function = "i2c1";
 +                              allwinner,drive = <0>;
 +                              allwinner,pull = <0>;
 +                      };
 +
 +                      i2c2_pins_a: i2c2@0 {
 +                              allwinner,pins = "PB20", "PB21";
 +                              allwinner,function = "i2c2";
 +                              allwinner,drive = <0>;
 +                              allwinner,pull = <0>;
 +                      };
++
+                       emac_pins_a: emac0@0 {
+                               allwinner,pins = "PA0", "PA1", "PA2",
+                                               "PA3", "PA4", "PA5", "PA6",
+                                               "PA7", "PA8", "PA9", "PA10",
+                                               "PA11", "PA12", "PA13", "PA14",
+                                               "PA15", "PA16";
+                               allwinner,function = "emac";
+                               allwinner,drive = <0>;
+                               allwinner,pull = <0>;
+                       };
                };
  
                timer@01c20c00 {
                        clocks = <&apb1_gates 23>;
                        status = "disabled";
                };
 +
 +              i2c0: i2c@01c2ac00 {
 +                      compatible = "allwinner,sun4i-i2c";
 +                      reg = <0x01c2ac00 0x400>;
 +                      interrupts = <7>;
 +                      clocks = <&apb1_gates 0>;
 +                      clock-frequency = <100000>;
 +                      status = "disabled";
 +              };
 +
 +              i2c1: i2c@01c2b000 {
 +                      compatible = "allwinner,sun4i-i2c";
 +                      reg = <0x01c2b000 0x400>;
 +                      interrupts = <8>;
 +                      clocks = <&apb1_gates 1>;
 +                      clock-frequency = <100000>;
 +                      status = "disabled";
 +              };
 +
 +              i2c2: i2c@01c2b400 {
 +                      compatible = "allwinner,sun4i-i2c";
 +                      reg = <0x01c2b400 0x400>;
 +                      interrupts = <9>;
 +                      clocks = <&apb1_gates 2>;
 +                      clock-frequency = <100000>;
 +                      status = "disabled";
 +              };
        };
  };
@@@ -210,8 -210,6 +210,8 @@@ CONFIG_USB_WDM=
  CONFIG_USB_STORAGE=y
  CONFIG_USB_LIBUSUAL=y
  CONFIG_USB_TEST=y
 +CONFIG_USB_PHY=y
 +CONFIG_NOP_USB_XCEIV=y
  CONFIG_USB_GADGET=y
  CONFIG_USB_GADGET_DEBUG=y
  CONFIG_USB_GADGET_DEBUG_FILES=y
@@@ -286,3 -284,4 +286,4 @@@ CONFIG_SOC_OMAP5=
  CONFIG_TI_DAVINCI_MDIO=y
  CONFIG_TI_DAVINCI_CPDMA=y
  CONFIG_TI_CPSW=y
+ CONFIG_AT803X_PHY=y
@@@ -56,6 -56,9 +56,6 @@@ config MXC_USE_EPI
          uses the same clocks as the GPT. Anyway, on some systems the GPT
          may be in use for other purposes.
  
 -config MXC_ULPI
 -      bool
 -
  config ARCH_HAS_RNGA
        bool
  
@@@ -108,7 -111,6 +108,6 @@@ config SOC_IMX2
        select ARCH_MXC_IOMUX_V3
        select COMMON_CLK
        select CPU_ARM926T
-       select HAVE_CAN_FLEXCAN if CAN
        select MXC_AVIC
  
  config SOC_IMX27
@@@ -134,7 -136,6 +133,6 @@@ config SOC_IMX3
        select ARCH_MXC_IOMUX_V3
        select COMMON_CLK
        select CPU_V6K
-       select HAVE_CAN_FLEXCAN if CAN
        select HAVE_EPIT
        select MXC_AVIC
        select SMP_ON_UP if SMP
@@@ -173,7 -174,6 +171,7 @@@ config ARCH_MX1AD
  config MACH_SCB9328
        bool "Synertronixx scb9328"
        select IMX_HAVE_PLATFORM_IMX_UART
 +      select SOC_IMX1
        help
          Say Y here if you are using a Synertronixx scb9328 board
  
@@@ -231,7 -231,7 +229,7 @@@ config MACH_EUKREA_CPUIMX25S
        select IMX_HAVE_PLATFORM_MXC_EHCI
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX25
  
  choice
@@@ -282,7 -282,7 +280,7 @@@ config MACH_PCM03
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_MXC_W1
        select IMX_HAVE_PLATFORM_SPI_IMX
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX27
        help
          Include support for phyCORE-i.MX27 (aka pcm038) platform. This
@@@ -312,7 -312,7 +310,7 @@@ config MACH_CPUIMX2
        select IMX_HAVE_PLATFORM_MXC_EHCI
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_MXC_W1
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX27
        help
          Include support for Eukrea CPUIMX27 platform. This includes
@@@ -367,7 -367,7 +365,7 @@@ config MACH_MX27_3D
        select IMX_HAVE_PLATFORM_MXC_MMC
        select IMX_HAVE_PLATFORM_SPI_IMX
        select MXC_DEBUG_BOARD
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX27
        help
          Include support for MX27PDK platform. This includes specific
@@@ -412,7 -412,7 +410,7 @@@ config MACH_PCA10
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_MXC_W1
        select IMX_HAVE_PLATFORM_SPI_IMX
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX27
        help
          Include support for phyCARD-s (aka pca100) platform. This
@@@ -479,7 -479,7 +477,7 @@@ config MACH_MX31LILL
        select IMX_HAVE_PLATFORM_MXC_EHCI
        select IMX_HAVE_PLATFORM_MXC_MMC
        select IMX_HAVE_PLATFORM_SPI_IMX
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX31
        help
          Include support for mx31 based LILLY1131 modules. This includes
@@@ -495,7 -495,7 +493,7 @@@ config MACH_MX31LIT
        select IMX_HAVE_PLATFORM_MXC_RTC
        select IMX_HAVE_PLATFORM_SPI_IMX
        select LEDS_GPIO_REGISTER
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX31
        help
          Include support for MX31 LITEKIT platform. This includes specific
@@@ -512,7 -512,7 +510,7 @@@ config MACH_PCM03
        select IMX_HAVE_PLATFORM_MXC_MMC
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_MXC_W1
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX31
        help
          Include support for Phytec pcm037 platform. This includes
@@@ -542,7 -542,7 +540,7 @@@ config MACH_MX31_3D
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_SPI_IMX
        select MXC_DEBUG_BOARD
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX31
        help
          Include support for MX31PDK (3DS) platform. This includes specific
@@@ -569,7 -569,7 +567,7 @@@ config MACH_MX31MOBOAR
        select IMX_HAVE_PLATFORM_MXC_MMC
        select IMX_HAVE_PLATFORM_SPI_IMX
        select LEDS_GPIO_REGISTER
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX31
        help
          Include support for mx31moboard platform. This includes specific
@@@ -593,7 -593,7 +591,7 @@@ config MACH_ARMADILLO5X
        select IMX_HAVE_PLATFORM_MXC_EHCI
        select IMX_HAVE_PLATFORM_MXC_MMC
        select IMX_HAVE_PLATFORM_MXC_NAND
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX31
        help
          Include support for Atmark Armadillo-500 platform. This includes
@@@ -637,7 -637,7 +635,7 @@@ config MACH_PCM04
        select IMX_HAVE_PLATFORM_MXC_EHCI
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX35
        help
          Include support for Phytec pcm043 platform. This includes
@@@ -671,7 -671,7 +669,7 @@@ config MACH_EUKREA_CPUIMX35S
        select IMX_HAVE_PLATFORM_MXC_EHCI
        select IMX_HAVE_PLATFORM_MXC_NAND
        select IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
 -      select MXC_ULPI if USB_ULPI
 +      select USB_ULPI_VIEWPORT if USB_ULPI
        select SOC_IMX35
        help
          Include support for Eukrea CPUIMX35 platform. This includes
@@@ -774,7 -774,6 +772,6 @@@ comment "Device tree only
  
  config        SOC_IMX53
        bool "i.MX53 support"
-       select HAVE_CAN_FLEXCAN if CAN
        select HAVE_IMX_SRC
        select IMX_HAVE_PLATFORM_IMX2_WDT
        select PINCTRL
@@@ -797,7 -796,6 +794,6 @@@ config SOC_IMX6
        select CPU_V7
        select HAVE_ARM_SCU if SMP
        select HAVE_ARM_TWD if LOCAL_TIMERS
-       select HAVE_CAN_FLEXCAN if CAN
        select HAVE_IMX_ANATOP
        select HAVE_IMX_GPC
        select HAVE_IMX_MMDC
        help
          This enables support for Freescale i.MX6 Quad processor.
  
 +config SOC_IMX6SL
 +      bool "i.MX6 SoloLite support"
 +      select ARM_ERRATA_754322
 +      select ARM_ERRATA_775420
 +      select ARM_GIC
 +      select CPU_V7
 +      select HAVE_IMX_ANATOP
 +      select HAVE_IMX_GPC
 +      select HAVE_IMX_MMDC
 +      select HAVE_IMX_SRC
 +      select MFD_SYSCON
 +      select PINCTRL
 +      select PINCTRL_IMX6SL
 +      select PL310_ERRATA_588369 if CACHE_PL310
 +      select PL310_ERRATA_727915 if CACHE_PL310
 +      select PL310_ERRATA_769419 if CACHE_PL310
 +
 +      help
 +        This enables support for Freescale i.MX6 SoloLite processor.
 +
 +config SOC_VF610
 +      bool "Vybrid Family VF610 support"
 +      select CPU_V7
 +      select ARM_GIC
 +      select CLKSRC_OF
 +      select PINCTRL
 +      select PINCTRL_VF610
 +      select VF_PIT_TIMER
 +      select PL310_ERRATA_588369 if CACHE_PL310
 +      select PL310_ERRATA_727915 if CACHE_PL310
 +      select PL310_ERRATA_769419 if CACHE_PL310
 +
 +      help
 +        This enable support for Freescale Vybrid VF610 processor.
 +
  endif
  
  source "arch/arm/mach-imx/devices/Kconfig"
@@@ -3,6 -3,7 +3,6 @@@ config SOC_IMX2
        select ARM_AMBA
        select ARM_CPU_SUSPEND if PM
        select CPU_ARM926T
 -      select HAVE_PWM
        select PINCTRL_IMX23
  
  config SOC_IMX28
@@@ -10,7 -11,7 +10,6 @@@
        select ARM_AMBA
        select ARM_CPU_SUSPEND if PM
        select CPU_ARM926T
-       select HAVE_CAN_FLEXCAN if CAN
 -      select HAVE_PWM
        select PINCTRL_IMX28
  
  config ARCH_MXS
@@@ -23,7 -24,6 +22,7 @@@
        select GENERIC_CLOCKEVENTS
        select HAVE_CLK_PREPARE
        select PINCTRL
 +      select SOC_BUS
        select SOC_IMX23
        select SOC_IMX28
        select STMP_DEVICE
  #include <linux/clk/mxs.h>
  #include <linux/clkdev.h>
  #include <linux/clocksource.h>
- #include <linux/can/platform/flexcan.h>
  #include <linux/delay.h>
  #include <linux/err.h>
  #include <linux/gpio.h>
  #include <linux/init.h>
 -#include <linux/irqchip.h>
  #include <linux/irqchip/mxs.h>
 +#include <linux/reboot.h>
  #include <linux/micrel_phy.h>
  #include <linux/of_address.h>
  #include <linux/of_platform.h>
  #include <linux/phy.h>
  #include <linux/pinctrl/consumer.h>
 +#include <linux/sys_soc.h>
  #include <asm/mach/arch.h>
  #include <asm/mach/map.h>
  #include <asm/mach/time.h>
  #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0               0x2
  #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR1               0x3
  
 +#define HW_DIGCTL_CHIPID      0x310
 +#define HW_DIGCTL_CHIPID_MASK (0xffff << 16)
 +#define HW_DIGCTL_REV_MASK    0xff
 +#define HW_DIGCTL_CHIPID_MX23 (0x3780 << 16)
 +#define HW_DIGCTL_CHIPID_MX28 (0x2800 << 16)
 +
 +#define MXS_CHIP_REVISION_1_0 0x10
 +#define MXS_CHIP_REVISION_1_1 0x11
 +#define MXS_CHIP_REVISION_1_2 0x12
 +#define MXS_CHIP_REVISION_1_3 0x13
 +#define MXS_CHIP_REVISION_1_4 0x14
 +#define MXS_CHIP_REV_UNKNOWN  0xff
 +
  #define MXS_GPIO_NR(bank, nr) ((bank) * 32 + (nr))
  
  #define MXS_SET_ADDR          0x4
  #define MXS_CLR_ADDR          0x8
  #define MXS_TOG_ADDR          0xc
  
 +static u32 chipid;
 +static u32 socid;
 +
  static inline void __mxs_setl(u32 mask, void __iomem *reg)
  {
        __raw_writel(mask, reg + MXS_SET_ADDR);
@@@ -77,41 -59,6 +76,6 @@@ static inline void __mxs_togl(u32 mask
        __raw_writel(mask, reg + MXS_TOG_ADDR);
  }
  
- /*
-  * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers
-  */
- #define MX28EVK_FLEXCAN_SWITCH        MXS_GPIO_NR(2, 13)
- static int flexcan0_en, flexcan1_en;
- static void mx28evk_flexcan_switch(void)
- {
-       if (flexcan0_en || flexcan1_en)
-               gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1);
-       else
-               gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0);
- }
- static void mx28evk_flexcan0_switch(int enable)
- {
-       flexcan0_en = enable;
-       mx28evk_flexcan_switch();
- }
- static void mx28evk_flexcan1_switch(int enable)
- {
-       flexcan1_en = enable;
-       mx28evk_flexcan_switch();
- }
- static struct flexcan_platform_data flexcan_pdata[2];
- static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = {
-       OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80032000, NULL, &flexcan_pdata[0]),
-       OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80034000, NULL, &flexcan_pdata[1]),
-       { /* sentinel */ }
- };
  #define OCOTP_WORD_OFFSET             0x20
  #define OCOTP_WORD_COUNT              0x20
  
@@@ -271,15 -218,6 +235,6 @@@ static void __init imx28_evk_init(void
        mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0);
  }
  
- static void __init imx28_evk_post_init(void)
- {
-       if (!gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT,
-                             "flexcan-switch")) {
-               flexcan_pdata[0].transceiver_switch = mx28evk_flexcan0_switch;
-               flexcan_pdata[1].transceiver_switch = mx28evk_flexcan1_switch;
-       }
- }
  static int apx4devkit_phy_fixup(struct phy_device *phy)
  {
        phy->dev_flags |= MICREL_PHY_50MHZ_CLK;
@@@ -369,129 -307,32 +324,126 @@@ static void __init tx28_post_init(void
        pinctrl_put(pctl);
  }
  
 -static void __init cfa10049_init(void)
 +static void __init crystalfontz_init(void)
  {
        update_fec_mac_prop(OUI_CRYSTALFONTZ);
  }
  
 -static void __init cfa10037_init(void)
 +static const char __init *mxs_get_soc_id(void)
  {
 -      update_fec_mac_prop(OUI_CRYSTALFONTZ);
 +      struct device_node *np;
 +      void __iomem *digctl_base;
 +
 +      np = of_find_compatible_node(NULL, NULL, "fsl,imx23-digctl");
 +      digctl_base = of_iomap(np, 0);
 +      WARN_ON(!digctl_base);
 +
 +      chipid = readl(digctl_base + HW_DIGCTL_CHIPID);
 +      socid = chipid & HW_DIGCTL_CHIPID_MASK;
 +
 +      iounmap(digctl_base);
 +      of_node_put(np);
 +
 +      switch (socid) {
 +      case HW_DIGCTL_CHIPID_MX23:
 +              return "i.MX23";
 +      case HW_DIGCTL_CHIPID_MX28:
 +              return "i.MX28";
 +      default:
 +              return "Unknown";
 +      }
 +}
 +
 +static u32 __init mxs_get_cpu_rev(void)
 +{
 +      u32 rev = chipid & HW_DIGCTL_REV_MASK;
 +
 +      switch (socid) {
 +      case HW_DIGCTL_CHIPID_MX23:
 +              switch (rev) {
 +              case 0x0:
 +                      return MXS_CHIP_REVISION_1_0;
 +              case 0x1:
 +                      return MXS_CHIP_REVISION_1_1;
 +              case 0x2:
 +                      return MXS_CHIP_REVISION_1_2;
 +              case 0x3:
 +                      return MXS_CHIP_REVISION_1_3;
 +              case 0x4:
 +                      return MXS_CHIP_REVISION_1_4;
 +              default:
 +                      return MXS_CHIP_REV_UNKNOWN;
 +              }
 +      case HW_DIGCTL_CHIPID_MX28:
 +              switch (rev) {
 +              case 0x0:
 +                      return MXS_CHIP_REVISION_1_1;
 +              case 0x1:
 +                      return MXS_CHIP_REVISION_1_2;
 +              default:
 +                      return MXS_CHIP_REV_UNKNOWN;
 +              }
 +      default:
 +              return MXS_CHIP_REV_UNKNOWN;
 +      }
 +}
 +
 +static const char __init *mxs_get_revision(void)
 +{
 +      u32 rev = mxs_get_cpu_rev();
 +
 +      if (rev != MXS_CHIP_REV_UNKNOWN)
 +              return kasprintf(GFP_KERNEL, "TO%d.%d", (rev >> 4) & 0xf,
 +                              rev & 0xf);
 +      else
 +              return kasprintf(GFP_KERNEL, "%s", "Unknown");
  }
  
  static void __init mxs_machine_init(void)
  {
 +      struct device_node *root;
 +      struct device *parent;
 +      struct soc_device *soc_dev;
 +      struct soc_device_attribute *soc_dev_attr;
 +      int ret;
 +
 +      soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
 +      if (!soc_dev_attr)
 +              return;
 +
 +      root = of_find_node_by_path("/");
 +      ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
 +      if (ret)
 +              return;
 +
 +      soc_dev_attr->family = "Freescale MXS Family";
 +      soc_dev_attr->soc_id = mxs_get_soc_id();
 +      soc_dev_attr->revision = mxs_get_revision();
 +
 +      soc_dev = soc_device_register(soc_dev_attr);
 +      if (IS_ERR(soc_dev)) {
 +              kfree(soc_dev_attr->revision);
 +              kfree(soc_dev_attr);
 +              return;
 +      }
 +
 +      parent = soc_device_to_device(soc_dev);
 +
        if (of_machine_is_compatible("fsl,imx28-evk"))
                imx28_evk_init();
        else if (of_machine_is_compatible("bluegiga,apx4devkit"))
                apx4devkit_init();
 -      else if (of_machine_is_compatible("crystalfontz,cfa10037"))
 -              cfa10037_init();
 -      else if (of_machine_is_compatible("crystalfontz,cfa10049"))
 -              cfa10049_init();
 +      else if (of_machine_is_compatible("crystalfontz,cfa10037") ||
 +               of_machine_is_compatible("crystalfontz,cfa10049") ||
 +               of_machine_is_compatible("crystalfontz,cfa10055") ||
 +               of_machine_is_compatible("crystalfontz,cfa10057"))
 +              crystalfontz_init();
  
        of_platform_populate(NULL, of_default_bus_match_table,
-                            mxs_auxdata_lookup, parent);
 -                           NULL, NULL);
++                           NULL, parent);
  
        if (of_machine_is_compatible("karo,tx28"))
                tx28_post_init();
-       if (of_machine_is_compatible("fsl,imx28-evk"))
-               imx28_evk_post_init();
  }
  
  #define MX23_CLKCTRL_RESET_OFFSET     0x120
  /*
   * Reset the system. It is called by machine_restart().
   */
 -static void mxs_restart(char mode, const char *cmd)
 +static void mxs_restart(enum reboot_mode mode, const char *cmd)
  {
        struct device_node *np;
        void __iomem *reset_addr;
@@@ -545,6 -386,8 +497,6 @@@ static const char *mxs_dt_compat[] __in
  };
  
  DT_MACHINE_START(MXS, "Freescale MXS (Device Tree)")
 -      .map_io         = debug_ll_io_init,
 -      .init_irq       = irqchip_init,
        .handle_irq     = icoll_handle_irq,
        .init_time      = mxs_timer_init,
        .init_machine   = mxs_machine_init,
@@@ -42,7 -42,6 +42,7 @@@
  #include <linux/mmc/sh_mmcif.h>
  #include <linux/mmc/sh_mobile_sdhi.h>
  #include <linux/i2c-gpio.h>
 +#include <linux/reboot.h>
  #include <mach/common.h>
  #include <mach/irqs.h>
  #include <mach/r8a7740.h>
@@@ -378,7 -377,7 +378,7 @@@ static struct resource sh_eth_resources
  };
  
  static struct platform_device sh_eth_device = {
-       .name = "sh-eth",
+       .name = "r8a7740-gether",
        .id = -1,
        .dev = {
                .platform_data = &sh_eth_platdata,
@@@ -585,7 -584,7 +585,7 @@@ static struct regulator_init_data vcc_s
  static struct fixed_voltage_config vcc_sdhi0_info = {
        .supply_name = "SDHI0 Vcc",
        .microvolts = 3300000,
 -      .gpio = GPIO_PORT75,
 +      .gpio = 75,
        .enable_high = 1,
        .init_data = &vcc_sdhi0_init_data,
  };
@@@ -616,7 -615,7 +616,7 @@@ static struct regulator_init_data vccq_
  };
  
  static struct gpio vccq_sdhi0_gpios[] = {
 -      {GPIO_PORT17, GPIOF_OUT_INIT_LOW, "vccq-sdhi0" },
 +      {17, GPIOF_OUT_INIT_LOW, "vccq-sdhi0" },
  };
  
  static struct gpio_regulator_state vccq_sdhi0_states[] = {
  static struct gpio_regulator_config vccq_sdhi0_info = {
        .supply_name = "vqmmc",
  
 -      .enable_gpio = GPIO_PORT74,
 +      .enable_gpio = 74,
        .enable_high = 1,
        .enabled_at_boot = 0,
  
@@@ -665,7 -664,7 +665,7 @@@ static struct regulator_init_data vcc_s
  static struct fixed_voltage_config vcc_sdhi1_info = {
        .supply_name = "SDHI1 Vcc",
        .microvolts = 3300000,
 -      .gpio = GPIO_PORT16,
 +      .gpio = 16,
        .enable_high = 1,
        .init_data = &vcc_sdhi1_init_data,
  };
@@@ -694,7 -693,7 +694,7 @@@ static struct sh_mobile_sdhi_info sdhi0
        .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
                          MMC_CAP_POWER_OFF_CARD,
        .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_USE_GPIO_CD,
 -      .cd_gpio        = GPIO_PORT167,
 +      .cd_gpio        = 167,
  };
  
  static struct resource sdhi0_resources[] = {
@@@ -737,7 -736,7 +737,7 @@@ static struct sh_mobile_sdhi_info sdhi1
                          MMC_CAP_POWER_OFF_CARD,
        .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_USE_GPIO_CD,
        /* Port72 cannot generate IRQs, will be used in polling mode. */
 -      .cd_gpio        = GPIO_PORT72,
 +      .cd_gpio        = 72,
  };
  
  static struct resource sdhi1_resources[] = {
@@@ -1047,35 -1046,6 +1047,35 @@@ static struct platform_device *eva_devi
  };
  
  static const struct pinctrl_map eva_pinctrl_map[] = {
 +      /* CEU0 */
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-r8a7740",
 +                                "ceu0_data_0_7", "ceu0"),
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-r8a7740",
 +                                "ceu0_clk_0", "ceu0"),
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-r8a7740",
 +                                "ceu0_sync", "ceu0"),
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-r8a7740",
 +                                "ceu0_field", "ceu0"),
 +      /* FSIA */
 +      PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-r8a7740",
 +                                "fsia_sclk_in", "fsia"),
 +      PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-r8a7740",
 +                                "fsia_mclk_out", "fsia"),
 +      PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-r8a7740",
 +                                "fsia_data_in_1", "fsia"),
 +      PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-r8a7740",
 +                                "fsia_data_out_0", "fsia"),
 +      /* FSIB */
 +      PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.1", "pfc-r8a7740",
 +                                "fsib_mclk_in", "fsib"),
 +      /* GETHER */
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh-eth", "pfc-r8a7740",
 +                                "gether_mii", "gether"),
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh-eth", "pfc-r8a7740",
 +                                "gether_int", "gether"),
 +      /* HDMI */
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh-mobile-hdmi", "pfc-r8a7740",
 +                                "hdmi", "hdmi"),
        /* LCD0 */
        PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-r8a7740",
                                  "lcd0_data24_0", "lcd0"),
                                  "mmc0_data8_1", "mmc0"),
        PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-r8a7740",
                                  "mmc0_ctrl_1", "mmc0"),
 +      /* SCIFA1 */
 +      PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.1", "pfc-r8a7740",
 +                                "scifa1_data", "scifa1"),
        /* SDHI0 */
        PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7740",
                                  "sdhi0_data4", "sdhi0"),
                                  "sdhi0_ctrl", "sdhi0"),
        PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7740",
                                  "sdhi0_wp", "sdhi0"),
 +      /* ST1232 */
 +      PIN_MAP_MUX_GROUP_DEFAULT("0-0055", "pfc-r8a7740",
 +                                "intc_irq10", "intc"),
 +      /* USBHS */
 +      PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-r8a7740",
 +                                "intc_irq7_1", "intc"),
  };
  
  static void __init eva_clock_init(void)
@@@ -1158,14 -1119,40 +1158,14 @@@ static void __init eva_init(void
        r8a7740_pinmux_init();
        r8a7740_meram_workaround();
  
 -      /* SCIFA1 */
 -      gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
 -      gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
 -
        /* LCDC0 */
 -      gpio_request(GPIO_FN_LCDC0_SELECT,      NULL);
 -
        gpio_request_one(61, GPIOF_OUT_INIT_HIGH, NULL); /* LCDDON */
        gpio_request_one(202, GPIOF_OUT_INIT_LOW, NULL); /* LCD0_LED_CONT */
  
        /* Touchscreen */
 -      gpio_request(GPIO_FN_IRQ10,     NULL); /* TP_INT */
 +      gpio_request_one(166, GPIOF_OUT_INIT_HIGH, NULL); /* TP_RST_B */
  
        /* GETHER */
 -      gpio_request(GPIO_FN_ET_CRS,            NULL);
 -      gpio_request(GPIO_FN_ET_MDC,            NULL);
 -      gpio_request(GPIO_FN_ET_MDIO,           NULL);
 -      gpio_request(GPIO_FN_ET_TX_ER,          NULL);
 -      gpio_request(GPIO_FN_ET_RX_ER,          NULL);
 -      gpio_request(GPIO_FN_ET_ERXD0,          NULL);
 -      gpio_request(GPIO_FN_ET_ERXD1,          NULL);
 -      gpio_request(GPIO_FN_ET_ERXD2,          NULL);
 -      gpio_request(GPIO_FN_ET_ERXD3,          NULL);
 -      gpio_request(GPIO_FN_ET_TX_CLK,         NULL);
 -      gpio_request(GPIO_FN_ET_TX_EN,          NULL);
 -      gpio_request(GPIO_FN_ET_ETXD0,          NULL);
 -      gpio_request(GPIO_FN_ET_ETXD1,          NULL);
 -      gpio_request(GPIO_FN_ET_ETXD2,          NULL);
 -      gpio_request(GPIO_FN_ET_ETXD3,          NULL);
 -      gpio_request(GPIO_FN_ET_PHY_INT,        NULL);
 -      gpio_request(GPIO_FN_ET_COL,            NULL);
 -      gpio_request(GPIO_FN_ET_RX_DV,          NULL);
 -      gpio_request(GPIO_FN_ET_RX_CLK,         NULL);
 -
        gpio_request_one(18, GPIOF_OUT_INIT_HIGH, NULL); /* PHY_RST */
  
        /* USB */
        } else {
                /* USB Func */
                /*
 -               * A1 chip has 2 IRQ7 pin and it was controled by MSEL register.
 -               * OTOH, usbhs interrupt needs its value (HI/LOW) to decide
 -               * USB connection/disconnection (usbhsf_get_vbus()).
 -               * This means we needs to select GPIO_FN_IRQ7_PORT209 first,
 -               * and select GPIO 209 here
 +               * The USBHS interrupt handlers needs to read the IRQ pin value
 +               * (HI/LOW) to diffentiate USB connection and disconnection
 +               * events (usbhsf_get_vbus()). We thus need to select both the
 +               * intc_irq7_1 pin group and GPIO 209 here.
                 */
 -              gpio_request(GPIO_FN_IRQ7_PORT209, NULL);
                gpio_request_one(209, GPIOF_IN, NULL);
  
                platform_device_register(&usbhsf_device);
                usb = &usbhsf_device;
        }
  
 -      /* CEU0 */
 -      gpio_request(GPIO_FN_VIO0_D7,           NULL);
 -      gpio_request(GPIO_FN_VIO0_D6,           NULL);
 -      gpio_request(GPIO_FN_VIO0_D5,           NULL);
 -      gpio_request(GPIO_FN_VIO0_D4,           NULL);
 -      gpio_request(GPIO_FN_VIO0_D3,           NULL);
 -      gpio_request(GPIO_FN_VIO0_D2,           NULL);
 -      gpio_request(GPIO_FN_VIO0_D1,           NULL);
 -      gpio_request(GPIO_FN_VIO0_D0,           NULL);
 -      gpio_request(GPIO_FN_VIO0_CLK,          NULL);
 -      gpio_request(GPIO_FN_VIO0_HD,           NULL);
 -      gpio_request(GPIO_FN_VIO0_VD,           NULL);
 -      gpio_request(GPIO_FN_VIO0_FIELD,        NULL);
 -      gpio_request(GPIO_FN_VIO_CKO,           NULL);
 -
        /* CON1/CON15 Camera */
        gpio_request_one(173, GPIOF_OUT_INIT_LOW, NULL);  /* STANDBY */
        gpio_request_one(172, GPIOF_OUT_INIT_HIGH, NULL); /* RST */
        gpio_request_one(158, GPIOF_OUT_INIT_LOW, NULL);  /* CAM_PON */
  
        /* FSI-WM8978 */
 -      gpio_request(GPIO_FN_FSIAIBT,           NULL);
 -      gpio_request(GPIO_FN_FSIAILR,           NULL);
 -      gpio_request(GPIO_FN_FSIAOMC,           NULL);
 -      gpio_request(GPIO_FN_FSIAOSLD,          NULL);
 -      gpio_request(GPIO_FN_FSIAISLD_PORT5,    NULL);
 -
        gpio_request(7, NULL);
        gpio_request(8, NULL);
        gpio_direction_none(GPIO_PORT7CR); /* FSIAOBT needs no direction */
        gpio_direction_none(GPIO_PORT8CR); /* FSIAOLR needs no direction */
  
 -      /* FSI-HDMI */
 -      gpio_request(GPIO_FN_FSIBCK,            NULL);
 -
 -      /* HDMI */
 -      gpio_request(GPIO_FN_HDMI_HPD,          NULL);
 -      gpio_request(GPIO_FN_HDMI_CEC,          NULL);
 -
        /*
         * CAUTION
         *
@@@ -1260,7 -1277,7 +1260,7 @@@ static void __init eva_add_early_device
  }
  
  #define RESCNT2 IOMEM(0xe6188020)
 -static void eva_restart(char mode, const char *cmd)
 +static void eva_restart(enum reboot_mode mode, const char *cmd)
  {
        /* Do soft power on reset */
        writel((1 << 31), RESCNT2);
@@@ -266,7 -266,7 +266,7 @@@ static struct clk fsiack_clk = 
  static struct clk fsibck_clk = {
  };
  
 -struct clk *main_clks[] = {
 +static struct clk *main_clks[] = {
        &extalr_clk,
        &extal1_clk,
        &extal2_clk,
@@@ -317,7 -317,7 +317,7 @@@ enum 
        DIV4_NR
  };
  
 -struct clk div4_clks[DIV4_NR] = {
 +static struct clk div4_clks[DIV4_NR] = {
        [DIV4_I]        = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 20, 0x6fff, CLK_ENABLE_ON_INIT),
        [DIV4_ZG]       = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 16, 0x6fff, CLK_ENABLE_ON_INIT),
        [DIV4_B]        = SH_CLK_DIV4(&pllc1_clk, FRQCRA,  8, 0x6fff, CLK_ENABLE_ON_INIT),
@@@ -461,7 -461,7 +461,7 @@@ enum 
  
        MSTP329, MSTP328, MSTP323, MSTP320,
        MSTP314, MSTP313, MSTP312,
 -      MSTP309,
 +      MSTP309, MSTP304,
  
        MSTP416, MSTP415, MSTP407, MSTP406,
  
@@@ -499,7 -499,6 +499,7 @@@ static struct clk mstp_clks[MSTP_NR] = 
        [MSTP313] = SH_CLK_MSTP32(&div4_clks[DIV4_HP],  SMSTPCR3, 13, 0), /* SDHI1 */
        [MSTP312] = SH_CLK_MSTP32(&div4_clks[DIV4_HP],  SMSTPCR3, 12, 0), /* MMC */
        [MSTP309] = SH_CLK_MSTP32(&div4_clks[DIV4_HP],  SMSTPCR3,  9, 0), /* GEther */
 +      [MSTP304] = SH_CLK_MSTP32(&div4_clks[DIV4_CP],  SMSTPCR3,  4, 0), /* TPU0 */
  
        [MSTP416] = SH_CLK_MSTP32(&div4_clks[DIV4_HP],  SMSTPCR4, 16, 0), /* USBHOST */
        [MSTP415] = SH_CLK_MSTP32(&div4_clks[DIV4_HP],  SMSTPCR4, 15, 0), /* SDHI2 */
@@@ -552,7 -551,6 +552,7 @@@ static struct clk_lookup lookups[] = 
        CLKDEV_DEV_ID("sh_tmu.4",               &mstp_clks[MSTP111]),
        CLKDEV_DEV_ID("sh_tmu.5",               &mstp_clks[MSTP111]),
        CLKDEV_DEV_ID("i2c-sh_mobile.0",        &mstp_clks[MSTP116]),
 +      CLKDEV_DEV_ID("fff20000.i2c",           &mstp_clks[MSTP116]),
        CLKDEV_DEV_ID("sh_mobile_lcdc_fb.1",    &mstp_clks[MSTP117]),
        CLKDEV_DEV_ID("sh_tmu.0",               &mstp_clks[MSTP125]),
        CLKDEV_DEV_ID("sh_tmu.1",               &mstp_clks[MSTP125]),
        CLKDEV_DEV_ID("sh_cmt.10",              &mstp_clks[MSTP329]),
        CLKDEV_DEV_ID("sh_fsi2",                &mstp_clks[MSTP328]),
        CLKDEV_DEV_ID("i2c-sh_mobile.1",        &mstp_clks[MSTP323]),
 +      CLKDEV_DEV_ID("e6c20000.i2c",           &mstp_clks[MSTP323]),
        CLKDEV_DEV_ID("renesas_usbhs",          &mstp_clks[MSTP320]),
        CLKDEV_DEV_ID("sh_mobile_sdhi.0",       &mstp_clks[MSTP314]),
        CLKDEV_DEV_ID("e6850000.sdhi",          &mstp_clks[MSTP314]),
        CLKDEV_DEV_ID("e6860000.sdhi",          &mstp_clks[MSTP313]),
        CLKDEV_DEV_ID("sh_mmcif",               &mstp_clks[MSTP312]),
        CLKDEV_DEV_ID("e6bd0000.mmcif",         &mstp_clks[MSTP312]),
-       CLKDEV_DEV_ID("sh-eth",                 &mstp_clks[MSTP309]),
+       CLKDEV_DEV_ID("r8a7740-gether",         &mstp_clks[MSTP309]),
 +      CLKDEV_DEV_ID("e9a00000.sh-eth",        &mstp_clks[MSTP309]),
 +      CLKDEV_DEV_ID("renesas_tpu_pwm",        &mstp_clks[MSTP304]),
  
        CLKDEV_DEV_ID("sh_mobile_sdhi.2",       &mstp_clks[MSTP415]),
        CLKDEV_DEV_ID("e6870000.sdhi",          &mstp_clks[MSTP415]),
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
 +/*
 + *     MD      MD      MD      MD       PLLA   PLLB    EXTAL   clki    clkz
 + *     19      18      12      11                      (HMz)   (MHz)   (MHz)
 + *----------------------------------------------------------------------------
 + *     1       0       0       0       x21     x21     38.00   800     800
 + *     1       0       0       1       x24     x24     33.33   800     800
 + *     1       0       1       0       x28     x28     28.50   800     800
 + *     1       0       1       1       x32     x32     25.00   800     800
 + *     1       1       0       1       x24     x21     33.33   800     700
 + *     1       1       1       0       x28     x21     28.50   800     600
 + *     1       1       1       1       x32     x24     25.00   800     600
 + */
 +
  #include <linux/io.h>
  #include <linux/sh_clk.h>
  #include <linux/clkdev.h>
 +#include <mach/clock.h>
  #include <mach/common.h>
  
  #define MSTPCR0               IOMEM(0xffc80030)
@@@ -51,9 -37,6 +51,9 @@@
  #define MSTPCR4               IOMEM(0xffc80050)
  #define MSTPCR5               IOMEM(0xffc80054)
  #define MSTPCR6               IOMEM(0xffc80058)
 +#define MODEMR                0xFFCC0020
 +
 +#define MD(nr)        BIT(nr)
  
  /* ioremap() through clock mapping mandatory to avoid
   * collision with ARM coherent DMA virtual memory range.
@@@ -64,94 -47,37 +64,94 @@@ static struct clk_mapping cpg_mapping 
        .len    = 0x80,
  };
  
 -static struct clk clkp = {
 -      .rate   = 62500000, /* FIXME: shortcut */
 -      .flags  = CLK_ENABLE_ON_INIT,
 +static struct clk extal_clk = {
 +      /* .rate will be updated on r8a7778_clock_init() */
        .mapping = &cpg_mapping,
  };
  
 +/*
 + * clock ratio of these clock will be updated
 + * on r8a7778_clock_init()
 + */
 +SH_FIXED_RATIO_CLK_SET(plla_clk,      extal_clk, 1, 1);
 +SH_FIXED_RATIO_CLK_SET(pllb_clk,      extal_clk, 1, 1);
 +SH_FIXED_RATIO_CLK_SET(i_clk,         plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(s_clk,         plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(s1_clk,                plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(s3_clk,                plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(s4_clk,                plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(b_clk,         plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(out_clk,               plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(p_clk,         plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(g_clk,         plla_clk,  1, 1);
 +SH_FIXED_RATIO_CLK_SET(z_clk,         pllb_clk,  1, 1);
 +
  static struct clk *main_clks[] = {
 -      &clkp,
 +      &extal_clk,
 +      &plla_clk,
 +      &pllb_clk,
 +      &i_clk,
 +      &s_clk,
 +      &s1_clk,
 +      &s3_clk,
 +      &s4_clk,
 +      &b_clk,
 +      &out_clk,
 +      &p_clk,
 +      &g_clk,
 +      &z_clk,
  };
  
  enum {
 +      MSTP331,
 +      MSTP323, MSTP322, MSTP321,
        MSTP114,
 -      MSTP026, MSTP025, MSTP024, MSTP023, MSTP022, MSTP021,
 +      MSTP100,
 +      MSTP030,
 +      MSTP029, MSTP028, MSTP027, MSTP026, MSTP025, MSTP024, MSTP023, MSTP022, MSTP021,
        MSTP016, MSTP015,
 +      MSTP007,
        MSTP_NR };
  
  static struct clk mstp_clks[MSTP_NR] = {
 -      [MSTP114] = SH_CLK_MSTP32(&clkp, MSTPCR1, 14, 0), /* Ether */
 -      [MSTP026] = SH_CLK_MSTP32(&clkp, MSTPCR0, 26, 0), /* SCIF0 */
 -      [MSTP025] = SH_CLK_MSTP32(&clkp, MSTPCR0, 25, 0), /* SCIF1 */
 -      [MSTP024] = SH_CLK_MSTP32(&clkp, MSTPCR0, 24, 0), /* SCIF2 */
 -      [MSTP023] = SH_CLK_MSTP32(&clkp, MSTPCR0, 23, 0), /* SCIF3 */
 -      [MSTP022] = SH_CLK_MSTP32(&clkp, MSTPCR0, 22, 0), /* SCIF4 */
 -      [MSTP021] = SH_CLK_MSTP32(&clkp, MSTPCR0, 21, 0), /* SCIF5 */
 -      [MSTP016] = SH_CLK_MSTP32(&clkp, MSTPCR0, 16, 0), /* TMU0 */
 -      [MSTP015] = SH_CLK_MSTP32(&clkp, MSTPCR0, 15, 0), /* TMU1 */
 +      [MSTP331] = SH_CLK_MSTP32(&s4_clk, MSTPCR3, 31, 0), /* MMC */
 +      [MSTP323] = SH_CLK_MSTP32(&p_clk, MSTPCR3, 23, 0), /* SDHI0 */
 +      [MSTP322] = SH_CLK_MSTP32(&p_clk, MSTPCR3, 22, 0), /* SDHI1 */
 +      [MSTP321] = SH_CLK_MSTP32(&p_clk, MSTPCR3, 21, 0), /* SDHI2 */
 +      [MSTP114] = SH_CLK_MSTP32(&p_clk, MSTPCR1, 14, 0), /* Ether */
 +      [MSTP100] = SH_CLK_MSTP32(&p_clk, MSTPCR1,  0, 0), /* USB0/1 */
 +      [MSTP030] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 30, 0), /* I2C0 */
 +      [MSTP029] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 29, 0), /* I2C1 */
 +      [MSTP028] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 28, 0), /* I2C2 */
 +      [MSTP027] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 27, 0), /* I2C3 */
 +      [MSTP026] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 26, 0), /* SCIF0 */
 +      [MSTP025] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 25, 0), /* SCIF1 */
 +      [MSTP024] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 24, 0), /* SCIF2 */
 +      [MSTP023] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 23, 0), /* SCIF3 */
 +      [MSTP022] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 22, 0), /* SCIF4 */
 +      [MSTP021] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 21, 0), /* SCIF5 */
 +      [MSTP016] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 16, 0), /* TMU0 */
 +      [MSTP015] = SH_CLK_MSTP32(&p_clk, MSTPCR0, 15, 0), /* TMU1 */
 +      [MSTP007] = SH_CLK_MSTP32(&p_clk, MSTPCR0,  7, 0), /* HSPI */
  };
  
  static struct clk_lookup lookups[] = {
 +      /* main */
 +      CLKDEV_CON_ID("shyway_clk",     &s_clk),
 +      CLKDEV_CON_ID("peripheral_clk", &p_clk),
 +
        /* MSTP32 clocks */
-       CLKDEV_DEV_ID("sh-eth", &mstp_clks[MSTP114]), /* Ether */
 +      CLKDEV_DEV_ID("sh_mmcif", &mstp_clks[MSTP331]), /* MMC */
 +      CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP323]), /* SDHI0 */
 +      CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP322]), /* SDHI1 */
 +      CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP321]), /* SDHI2 */
+       CLKDEV_DEV_ID("r8a777x-ether", &mstp_clks[MSTP114]), /* Ether */
 +      CLKDEV_DEV_ID("ehci-platform", &mstp_clks[MSTP100]), /* USB EHCI port0/1 */
 +      CLKDEV_DEV_ID("ohci-platform", &mstp_clks[MSTP100]), /* USB OHCI port0/1 */
 +      CLKDEV_DEV_ID("i2c-rcar.0", &mstp_clks[MSTP030]), /* I2C0 */
 +      CLKDEV_DEV_ID("i2c-rcar.1", &mstp_clks[MSTP029]), /* I2C1 */
 +      CLKDEV_DEV_ID("i2c-rcar.2", &mstp_clks[MSTP028]), /* I2C2 */
 +      CLKDEV_DEV_ID("i2c-rcar.3", &mstp_clks[MSTP027]), /* I2C3 */
        CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP026]), /* SCIF0 */
        CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP025]), /* SCIF1 */
        CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP024]), /* SCIF2 */
        CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP021]), /* SCIF6 */
        CLKDEV_DEV_ID("sh_tmu.0", &mstp_clks[MSTP016]), /* TMU00 */
        CLKDEV_DEV_ID("sh_tmu.1", &mstp_clks[MSTP015]), /* TMU01 */
 +      CLKDEV_DEV_ID("sh-hspi.0", &mstp_clks[MSTP007]), /* HSPI0 */
 +      CLKDEV_DEV_ID("sh-hspi.1", &mstp_clks[MSTP007]), /* HSPI1 */
 +      CLKDEV_DEV_ID("sh-hspi.2", &mstp_clks[MSTP007]), /* HSPI2 */
  };
  
  void __init r8a7778_clock_init(void)
  {
 +      void __iomem *modemr = ioremap_nocache(MODEMR, PAGE_SIZE);
 +      u32 mode;
        int k, ret = 0;
  
 +      BUG_ON(!modemr);
 +      mode = ioread32(modemr);
 +      iounmap(modemr);
 +
 +      switch (mode & (MD(19) | MD(18) | MD(12) | MD(11))) {
 +      case MD(19):
 +              extal_clk.rate = 38000000;
 +              SH_CLK_SET_RATIO(&plla_clk_ratio,       21, 1);
 +              SH_CLK_SET_RATIO(&pllb_clk_ratio,       21, 1);
 +              break;
 +      case MD(19) | MD(11):
 +              extal_clk.rate = 33333333;
 +              SH_CLK_SET_RATIO(&plla_clk_ratio,       24, 1);
 +              SH_CLK_SET_RATIO(&pllb_clk_ratio,       24, 1);
 +              break;
 +      case MD(19) | MD(12):
 +              extal_clk.rate = 28500000;
 +              SH_CLK_SET_RATIO(&plla_clk_ratio,       28, 1);
 +              SH_CLK_SET_RATIO(&pllb_clk_ratio,       28, 1);
 +              break;
 +      case MD(19) | MD(12) | MD(11):
 +              extal_clk.rate = 25000000;
 +              SH_CLK_SET_RATIO(&plla_clk_ratio,       32, 1);
 +              SH_CLK_SET_RATIO(&pllb_clk_ratio,       32, 1);
 +              break;
 +      case MD(19) | MD(18) | MD(11):
 +              extal_clk.rate = 33333333;
 +              SH_CLK_SET_RATIO(&plla_clk_ratio,       24, 1);
 +              SH_CLK_SET_RATIO(&pllb_clk_ratio,       21, 1);
 +              break;
 +      case MD(19) | MD(18) | MD(12):
 +              extal_clk.rate = 28500000;
 +              SH_CLK_SET_RATIO(&plla_clk_ratio,       28, 1);
 +              SH_CLK_SET_RATIO(&pllb_clk_ratio,       21, 1);
 +              break;
 +      case MD(19) | MD(18) | MD(12) | MD(11):
 +              extal_clk.rate = 25000000;
 +              SH_CLK_SET_RATIO(&plla_clk_ratio,       32, 1);
 +              SH_CLK_SET_RATIO(&pllb_clk_ratio,       24, 1);
 +              break;
 +      default:
 +              BUG();
 +      }
 +
 +      if (mode & MD(1)) {
 +              SH_CLK_SET_RATIO(&i_clk_ratio,  1, 1);
 +              SH_CLK_SET_RATIO(&s_clk_ratio,  1, 3);
 +              SH_CLK_SET_RATIO(&s1_clk_ratio, 1, 6);
 +              SH_CLK_SET_RATIO(&s3_clk_ratio, 1, 4);
 +              SH_CLK_SET_RATIO(&s4_clk_ratio, 1, 8);
 +              SH_CLK_SET_RATIO(&p_clk_ratio,  1, 12);
 +              SH_CLK_SET_RATIO(&g_clk_ratio,  1, 12);
 +              if (mode & MD(2)) {
 +                      SH_CLK_SET_RATIO(&b_clk_ratio,          1, 18);
 +                      SH_CLK_SET_RATIO(&out_clk_ratio,        1, 18);
 +              } else {
 +                      SH_CLK_SET_RATIO(&b_clk_ratio,          1, 12);
 +                      SH_CLK_SET_RATIO(&out_clk_ratio,        1, 12);
 +              }
 +      } else {
 +              SH_CLK_SET_RATIO(&i_clk_ratio,  1, 1);
 +              SH_CLK_SET_RATIO(&s_clk_ratio,  1, 4);
 +              SH_CLK_SET_RATIO(&s1_clk_ratio, 1, 8);
 +              SH_CLK_SET_RATIO(&s3_clk_ratio, 1, 4);
 +              SH_CLK_SET_RATIO(&s4_clk_ratio, 1, 8);
 +              SH_CLK_SET_RATIO(&p_clk_ratio,  1, 16);
 +              SH_CLK_SET_RATIO(&g_clk_ratio,  1, 12);
 +              if (mode & MD(2)) {
 +                      SH_CLK_SET_RATIO(&b_clk_ratio,          1, 16);
 +                      SH_CLK_SET_RATIO(&out_clk_ratio,        1, 16);
 +              } else {
 +                      SH_CLK_SET_RATIO(&b_clk_ratio,          1, 12);
 +                      SH_CLK_SET_RATIO(&out_clk_ratio,        1, 12);
 +              }
 +      }
 +
        for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
                ret = clk_register(main_clks[k]);
  
@@@ -112,7 -112,7 +112,7 @@@ static struct clk *main_clks[] = 
  };
  
  enum { MSTP323, MSTP322, MSTP321, MSTP320,
 -      MSTP115, MSTP114,
 +      MSTP116, MSTP115, MSTP114,
        MSTP103, MSTP101, MSTP100,
        MSTP030,
        MSTP029, MSTP028, MSTP027, MSTP026, MSTP025, MSTP024, MSTP023, MSTP022, MSTP021,
@@@ -125,7 -125,6 +125,7 @@@ static struct clk mstp_clks[MSTP_NR] = 
        [MSTP322] = SH_CLK_MSTP32(&clkp_clk, MSTPCR3, 22, 0), /* SDHI1 */
        [MSTP321] = SH_CLK_MSTP32(&clkp_clk, MSTPCR3, 21, 0), /* SDHI2 */
        [MSTP320] = SH_CLK_MSTP32(&clkp_clk, MSTPCR3, 20, 0), /* SDHI3 */
 +      [MSTP116] = SH_CLK_MSTP32(&clkp_clk, MSTPCR1, 16, 0), /* PCIe */
        [MSTP115] = SH_CLK_MSTP32(&clkp_clk, MSTPCR1, 15, 0), /* SATA */
        [MSTP114] = SH_CLK_MSTP32(&clkp_clk, MSTPCR1, 14, 0), /* Ether */
        [MSTP103] = SH_CLK_MSTP32(&clks_clk, MSTPCR1,  3, 0), /* DU */
@@@ -162,10 -161,9 +162,10 @@@ static struct clk_lookup lookups[] = 
        CLKDEV_CON_ID("peripheral_clk", &clkp_clk),
  
        /* MSTP32 clocks */
 +      CLKDEV_DEV_ID("rcar-pcie", &mstp_clks[MSTP116]), /* PCIe */
        CLKDEV_DEV_ID("sata_rcar", &mstp_clks[MSTP115]), /* SATA */
        CLKDEV_DEV_ID("fc600000.sata", &mstp_clks[MSTP115]), /* SATA w/DT */
-       CLKDEV_DEV_ID("sh-eth", &mstp_clks[MSTP114]), /* Ether */
+       CLKDEV_DEV_ID("r8a777x-ether", &mstp_clks[MSTP114]), /* Ether */
        CLKDEV_DEV_ID("ehci-platform.1", &mstp_clks[MSTP101]), /* USB EHCI port2 */
        CLKDEV_DEV_ID("ohci-platform.1", &mstp_clks[MSTP101]), /* USB OHCI port2 */
        CLKDEV_DEV_ID("ehci-platform.0", &mstp_clks[MSTP100]), /* USB EHCI port0/1 */
@@@ -2,9 -2,7 +2,7 @@@ if ETRAX_ARCH_V3
  
  config ETRAX_ETHERNET
        bool "Ethernet support"
-       depends on ETRAX_ARCH_V32
-       select ETHERNET
-       select NET_CORE
+       depends on ETRAX_ARCH_V32 && NETDEVICES
        select MII
        help
          This option enables the ETRAX FS built-in 10/100Mbit Ethernet
@@@ -617,6 -615,7 +615,6 @@@ config ETRAX_PV_CHANGEABLE_BIT
  config ETRAX_CARDBUS
          bool "Cardbus support"
          depends on ETRAX_ARCH_V32
 -        select HOTPLUG
          help
         Enabled the ETRAX Cardbus driver.
  
@@@ -640,6 -639,8 +638,6 @@@ config ETRAX_STREAMCOPRO
          This option enables a driver for the stream co-processor
          for cryptographic operations.
  
 -source drivers/mmc/Kconfig
 -
  config ETRAX_MMC_IOP
        tristate "MMC/SD host driver using IO-processor"
        depends on ETRAX_ARCH_V32 && MMC
@@@ -831,4 -832,9 +829,4 @@@ config ETRAX_SPI_MMC_WP_GPIO_PI
          The pin to use for the SD/MMC write-protect signal for a memory
          card.  If defined as " " (space), the card is considered writable.
  
 -# Avoid choices causing non-working configs by conditionalizing the inclusion.
 -if ETRAX_SPI_MMC
 -source drivers/spi/Kconfig
 -endif
 -
  endif
diff --combined arch/powerpc/Kconfig
@@@ -138,7 -138,6 +138,7 @@@ config PP
        select ARCH_USE_BUILTIN_BSWAP
        select OLD_SIGSUSPEND
        select OLD_SIGACTION if PPC32
 +      select HAVE_DEBUG_STACKOVERFLOW
  
  config EARLY_PRINTK
        bool
@@@ -299,7 -298,7 +299,7 @@@ config HUGETLB_PAGE_SIZE_VARIABL
  
  config MATH_EMULATION
        bool "Math emulation"
 -      depends on 4xx || 8xx || E200 || PPC_MPC832x || E500
 +      depends on 4xx || 8xx || PPC_MPC832x || BOOKE
        ---help---
          Some PowerPC chips designed for embedded applications do not have
          a floating-point unit and therefore do not implement the
          unit, which will allow programs that use floating-point
          instructions to run.
  
 +        This is also useful to emulate missing (optional) instructions
 +        such as fsqrt on cores that do have an FPU but do not implement
 +        them (such as Freescale BookE).
 +
  config PPC_TRANSACTIONAL_MEM
         bool "Transactional Memory support for POWERPC"
         depends on PPC_BOOK3S_64
         ---help---
           Support user-mode Transactional Memory on POWERPC.
  
 -config 8XX_MINIMAL_FPEMU
 -      bool "Minimal math emulation for 8xx"
 -      depends on 8xx && !MATH_EMULATION
 -      help
 -        Older arch/ppc kernels still emulated a few floating point
 -        instructions such as load and store, even when full math
 -        emulation is disabled.  Say "Y" here if you want to preserve
 -        this behavior.
 -
 -        It is recommended that you build a soft-float userspace instead.
 -
  config IOMMU_HELPER
        def_bool PPC64
  
@@@ -335,7 -341,7 +335,7 @@@ config SWIOTL
  
  config HOTPLUG_CPU
        bool "Support for enabling/disabling CPUs"
 -      depends on SMP && HOTPLUG && (PPC_PSERIES || \
 +      depends on SMP && (PPC_PSERIES || \
        PPC_PMAC || PPC_POWERNV || (PPC_85xx && !PPC_E500MC))
        ---help---
          Say Y here to be able to disable and re-enable individual
@@@ -668,7 -674,6 +668,6 @@@ config SBU
  
  config FSL_SOC
        bool
-       select HAVE_CAN_FLEXCAN if NET && CAN
  
  config FSL_PCI
        bool
@@@ -98,7 -98,8 +98,7 @@@ static struct ehea_fw_handle_array ehea
  static struct ehea_bcmc_reg_array ehea_bcmc_regs;
  
  
 -static int ehea_probe_adapter(struct platform_device *dev,
 -                            const struct of_device_id *id);
 +static int ehea_probe_adapter(struct platform_device *dev);
  
  static int ehea_remove(struct platform_device *dev);
  
@@@ -111,7 -112,7 +111,7 @@@ static struct of_device_id ehea_device_
  };
  MODULE_DEVICE_TABLE(of, ehea_device_table);
  
 -static struct of_platform_driver ehea_driver = {
 +static struct platform_driver ehea_driver = {
        .driver = {
                .name = "ehea",
                .owner = THIS_MODULE,
@@@ -3250,7 -3251,8 +3250,7 @@@ static void ehea_remove_device_sysfs(st
        device_remove_file(&dev->dev, &dev_attr_remove_port);
  }
  
 -static int ehea_probe_adapter(struct platform_device *dev,
 -                            const struct of_device_id *id)
 +static int ehea_probe_adapter(struct platform_device *dev)
  {
        struct ehea_adapter *adapter;
        const u64 *adapter_handle;
  
        adapter->pd = EHEA_PD_ID;
  
-       dev_set_drvdata(&dev->dev, adapter);
+       platform_set_drvdata(dev, adapter);
  
  
        /* initialize adapter and ports */
@@@ -3358,7 -3360,7 +3358,7 @@@ out
  
  static int ehea_remove(struct platform_device *dev)
  {
-       struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
+       struct ehea_adapter *adapter = platform_get_drvdata(dev);
        int i;
  
        for (i = 0; i < EHEA_MAX_PORTS; i++)
@@@ -340,6 -340,130 +340,130 @@@ s32 igb_write_phy_reg_i2c(struct e1000_
        return 0;
  }
  
+ /**
+  *  igb_read_sfp_data_byte - Reads SFP module data.
+  *  @hw: pointer to the HW structure
+  *  @offset: byte location offset to be read
+  *  @data: read data buffer pointer
+  *
+  *  Reads one byte from SFP module data stored
+  *  in SFP resided EEPROM memory or SFP diagnostic area.
+  *  Function should be called with
+  *  E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
+  *  E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
+  *  access
+  **/
+ s32 igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
+ {
+       u32 i = 0;
+       u32 i2ccmd = 0;
+       u32 data_local = 0;
+       if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
+               hw_dbg("I2CCMD command address exceeds upper limit\n");
+               return -E1000_ERR_PHY;
+       }
+       /* Set up Op-code, EEPROM Address,in the I2CCMD
+        * register. The MAC will take care of interfacing with the
+        * EEPROM to retrieve the desired data.
+        */
+       i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
+                 E1000_I2CCMD_OPCODE_READ);
+       wr32(E1000_I2CCMD, i2ccmd);
+       /* Poll the ready bit to see if the I2C read completed */
+       for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
+               udelay(50);
+               data_local = rd32(E1000_I2CCMD);
+               if (data_local & E1000_I2CCMD_READY)
+                       break;
+       }
+       if (!(data_local & E1000_I2CCMD_READY)) {
+               hw_dbg("I2CCMD Read did not complete\n");
+               return -E1000_ERR_PHY;
+       }
+       if (data_local & E1000_I2CCMD_ERROR) {
+               hw_dbg("I2CCMD Error bit set\n");
+               return -E1000_ERR_PHY;
+       }
+       *data = (u8) data_local & 0xFF;
+       return 0;
+ }
+ /**
+  *  e1000_write_sfp_data_byte - Writes SFP module data.
+  *  @hw: pointer to the HW structure
+  *  @offset: byte location offset to write to
+  *  @data: data to write
+  *
+  *  Writes one byte to SFP module data stored
+  *  in SFP resided EEPROM memory or SFP diagnostic area.
+  *  Function should be called with
+  *  E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
+  *  E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
+  *  access
+  **/
+ s32 e1000_write_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 data)
+ {
+       u32 i = 0;
+       u32 i2ccmd = 0;
+       u32 data_local = 0;
+       if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
+               hw_dbg("I2CCMD command address exceeds upper limit\n");
+               return -E1000_ERR_PHY;
+       }
+       /* The programming interface is 16 bits wide
+        * so we need to read the whole word first
+        * then update appropriate byte lane and write
+        * the updated word back.
+        */
+       /* Set up Op-code, EEPROM Address,in the I2CCMD
+        * register. The MAC will take care of interfacing
+        * with an EEPROM to write the data given.
+        */
+       i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
+                 E1000_I2CCMD_OPCODE_READ);
+       /* Set a command to read single word */
+       wr32(E1000_I2CCMD, i2ccmd);
+       for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
+               udelay(50);
+               /* Poll the ready bit to see if lastly
+                * launched I2C operation completed
+                */
+               i2ccmd = rd32(E1000_I2CCMD);
+               if (i2ccmd & E1000_I2CCMD_READY) {
+                       /* Check if this is READ or WRITE phase */
+                       if ((i2ccmd & E1000_I2CCMD_OPCODE_READ) ==
+                           E1000_I2CCMD_OPCODE_READ) {
+                               /* Write the selected byte
+                                * lane and update whole word
+                                */
+                               data_local = i2ccmd & 0xFF00;
+                               data_local |= data;
+                               i2ccmd = ((offset <<
+                                       E1000_I2CCMD_REG_ADDR_SHIFT) |
+                                       E1000_I2CCMD_OPCODE_WRITE | data_local);
+                               wr32(E1000_I2CCMD, i2ccmd);
+                       } else {
+                               break;
+                       }
+               }
+       }
+       if (!(i2ccmd & E1000_I2CCMD_READY)) {
+               hw_dbg("I2CCMD Write did not complete\n");
+               return -E1000_ERR_PHY;
+       }
+       if (i2ccmd & E1000_I2CCMD_ERROR) {
+               hw_dbg("I2CCMD Error bit set\n");
+               return -E1000_ERR_PHY;
+       }
+       return 0;
+ }
  /**
   *  igb_read_phy_reg_igp - Read igp PHY register
   *  @hw: pointer to the HW structure
@@@ -2014,7 -2138,7 +2138,7 @@@ out
   *  Verify the reset block is not blocking us from resetting.  Acquire
   *  semaphore (if necessary) and read/set/write the device control reset
   *  bit in the PHY.  Wait the appropriate delay time for the device to
 - *  reset and relase the semaphore (if necessary).
 + *  reset and release the semaphore (if necessary).
   **/
  s32 igb_phy_hw_reset(struct e1000_hw *hw)
  {
@@@ -98,7 -98,7 +98,7 @@@ MODULE_PARM_DESC(log_num_mgm_entry_size
  static bool enable_64b_cqe_eqe;
  module_param(enable_64b_cqe_eqe, bool, 0444);
  MODULE_PARM_DESC(enable_64b_cqe_eqe,
 -               "Enable 64 byte CQEs/EQEs when the the FW supports this");
 +               "Enable 64 byte CQEs/EQEs when the FW supports this");
  
  #define HCA_GLOBAL_CAP_MASK            0
  
@@@ -842,11 -842,11 +842,11 @@@ static ssize_t set_port_ib_mtu(struct d
                return -EINVAL;
        }
  
-       err = sscanf(buf, "%d", &mtu);
-       if (err > 0)
+       err = kstrtoint(buf, 0, &mtu);
+       if (!err)
                ibta_mtu = int_to_ibta_mtu(mtu);
  
-       if (err <= 0 || ibta_mtu < 0) {
+       if (err || ibta_mtu < 0) {
                mlx4_err(mdev, "%s is invalid IBTA mtu\n", buf);
                return -EINVAL;
        }
@@@ -2080,6 -2080,11 +2080,11 @@@ static int __mlx4_init_one(struct pci_d
                       num_vfs, MLX4_MAX_NUM_VF);
                return -EINVAL;
        }
+       if (num_vfs < 0) {
+               pr_err("num_vfs module parameter cannot be negative\n");
+               return -EINVAL;
+       }
        /*
         * Check for BARs.
         */
@@@ -35,6 -35,7 +35,7 @@@ static void qlcnic_sriov_vf_cancel_fw_w
  static void qlcnic_sriov_cleanup_transaction(struct qlcnic_bc_trans *);
  static int qlcnic_sriov_vf_mbx_op(struct qlcnic_adapter *,
                                  struct qlcnic_cmd_args *);
+ static void qlcnic_sriov_process_bc_cmd(struct work_struct *);
  
  static struct qlcnic_hardware_ops qlcnic_sriov_vf_hw_ops = {
        .read_crb                       = qlcnic_83xx_read_crb,
@@@ -75,6 -76,8 +76,8 @@@ static struct qlcnic_nic_template qlcni
        .cancel_idc_work        = qlcnic_sriov_vf_cancel_fw_work,
        .napi_add               = qlcnic_83xx_napi_add,
        .napi_del               = qlcnic_83xx_napi_del,
+       .shutdown               = qlcnic_sriov_vf_shutdown,
+       .resume                 = qlcnic_sriov_vf_resume,
        .config_ipaddr          = qlcnic_83xx_config_ipaddr,
        .clear_legacy_intr      = qlcnic_83xx_clear_legacy_intr,
  };
@@@ -179,6 -182,8 +182,8 @@@ int qlcnic_sriov_init(struct qlcnic_ada
                spin_lock_init(&vf->rcv_pend.lock);
                init_completion(&vf->ch_free_cmpl);
  
+               INIT_WORK(&vf->trans_work, qlcnic_sriov_process_bc_cmd);
                if (qlcnic_sriov_pf_check(adapter)) {
                        vp = kzalloc(sizeof(struct qlcnic_vport), GFP_KERNEL);
                        if (!vp) {
                        }
                        sriov->vf_info[i].vp = vp;
                        vp->max_tx_bw = MAX_BW;
+                       vp->spoofchk = true;
                        random_ether_addr(vp->mac);
                        dev_info(&adapter->pdev->dev,
                                 "MAC Address %pM is configured for VF %d\n",
@@@ -652,6 -658,8 +658,8 @@@ int qlcnic_sriov_vf_init(struct qlcnic_
        if (qlcnic_read_mac_addr(adapter))
                dev_warn(&adapter->pdev->dev, "failed to read mac addr\n");
  
+       INIT_DELAYED_WORK(&adapter->idc_aen_work, qlcnic_83xx_idc_aen_work);
        clear_bit(__QLCNIC_RESETTING, &adapter->state);
        return 0;
  }
@@@ -864,7 -872,6 +872,6 @@@ static void qlcnic_sriov_schedule_bc_cm
            vf->adapter->need_fw_reset)
                return;
  
-       INIT_WORK(&vf->trans_work, func);
        queue_work(sriov->bc.bc_trans_wq, &vf->trans_work);
  }
  
@@@ -1675,7 -1682,7 +1682,7 @@@ static int qlcnic_sriov_vf_handle_dev_r
                        qlcnic_sriov_vf_attach(adapter);
                        adapter->fw_fail_cnt = 0;
                        dev_info(dev,
 -                               "%s: Reinitalization of VF 0x%x done after FW reset\n",
 +                               "%s: Reinitialization of VF 0x%x done after FW reset\n",
                                 __func__, func);
                } else {
                        dev_err(dev,
@@@ -1949,3 -1956,54 +1956,54 @@@ static void qlcnic_sriov_vf_free_mac_li
                kfree(cur);
        }
  }
+ int qlcnic_sriov_vf_shutdown(struct pci_dev *pdev)
+ {
+       struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
+       struct net_device *netdev = adapter->netdev;
+       int retval;
+       netif_device_detach(netdev);
+       qlcnic_cancel_idc_work(adapter);
+       if (netif_running(netdev))
+               qlcnic_down(adapter, netdev);
+       qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_TERM);
+       qlcnic_sriov_cfg_bc_intr(adapter, 0);
+       qlcnic_83xx_disable_mbx_intr(adapter);
+       cancel_delayed_work_sync(&adapter->idc_aen_work);
+       retval = pci_save_state(pdev);
+       if (retval)
+               return retval;
+       return 0;
+ }
+ int qlcnic_sriov_vf_resume(struct qlcnic_adapter *adapter)
+ {
+       struct qlc_83xx_idc *idc = &adapter->ahw->idc;
+       struct net_device *netdev = adapter->netdev;
+       int err;
+       set_bit(QLC_83XX_MODULE_LOADED, &idc->status);
+       qlcnic_83xx_enable_mbx_intrpt(adapter);
+       err = qlcnic_sriov_cfg_bc_intr(adapter, 1);
+       if (err)
+               return err;
+       err = qlcnic_sriov_channel_cfg_cmd(adapter, QLCNIC_BC_CMD_CHANNEL_INIT);
+       if (!err) {
+               if (netif_running(netdev)) {
+                       err = qlcnic_up(adapter, netdev);
+                       if (!err)
+                               qlcnic_restore_indev_addr(netdev, NETDEV_UP);
+               }
+       }
+       netif_device_attach(netdev);
+       qlcnic_schedule_work(adapter, qlcnic_sriov_vf_poll_dev_state,
+                            idc->delay);
+       return err;
+ }
@@@ -35,7 -35,6 +35,7 @@@
  #include <linux/if_vlan.h>
  
  #include <linux/platform_data/cpsw.h>
 +#include <linux/pinctrl/consumer.h>
  
  #include "cpsw_ale.h"
  #include "cpts.h"
@@@ -1555,6 -1554,8 +1555,8 @@@ static int cpsw_probe_dt(struct cpsw_pl
                if (mac_addr)
                        memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN);
  
+               slave_data->phy_if = of_get_phy_mode(slave_node);
                if (data->dual_emac) {
                        if (of_property_read_u32(slave_node, "dual_emac_res_vlan",
                                                 &prop)) {
@@@ -1690,9 -1691,6 +1692,9 @@@ static int cpsw_probe(struct platform_d
         */
        pm_runtime_enable(&pdev->dev);
  
 +      /* Select default pin state */
 +      pinctrl_pm_select_default_state(&pdev->dev);
 +
        if (cpsw_probe_dt(&priv->data, pdev)) {
                pr_err("cpsw: platform data missing\n");
                ret = -ENODEV;
  
        if (is_valid_ether_addr(data->slave_data[0].mac_addr)) {
                memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN);
-               pr_info("Detected MACID = %pM", priv->mac_addr);
+               pr_info("Detected MACID = %pM\n", priv->mac_addr);
        } else {
                eth_random_addr(priv->mac_addr);
-               pr_info("Random MACID = %pM", priv->mac_addr);
+               pr_info("Random MACID = %pM\n", priv->mac_addr);
        }
  
        memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
@@@ -1944,7 -1942,6 +1946,6 @@@ static int cpsw_remove(struct platform_
        struct cpsw_priv *priv = netdev_priv(ndev);
        int i;
  
-       platform_set_drvdata(pdev, NULL);
        if (priv->data.dual_emac)
                unregister_netdev(cpsw_get_slave_ndev(priv, 1));
        unregister_netdev(ndev);
@@@ -1985,9 -1982,6 +1986,9 @@@ static int cpsw_suspend(struct device *
        soft_reset("sliver 1", &priv->slaves[1].sliver->soft_reset);
        pm_runtime_put_sync(&pdev->dev);
  
 +      /* Select sleep pin state */
 +      pinctrl_pm_select_sleep_state(&pdev->dev);
 +
        return 0;
  }
  
@@@ -1997,10 -1991,6 +1998,10 @@@ static int cpsw_resume(struct device *d
        struct net_device       *ndev = platform_get_drvdata(pdev);
  
        pm_runtime_get_sync(&pdev->dev);
 +
 +      /* Select default pin state */
 +      pinctrl_pm_select_default_state(&pdev->dev);
 +
        if (netif_running(ndev))
                cpsw_ndo_open(ndev);
        return 0;
@@@ -38,7 -38,6 +38,7 @@@
  #include <linux/davinci_emac.h>
  #include <linux/of.h>
  #include <linux/of_device.h>
 +#include <linux/pinctrl/consumer.h>
  
  /*
   * This timeout definition is a worst-case ultra defensive measure against
@@@ -292,6 -291,7 +292,7 @@@ static int davinci_mdio_write(struct mi
        return 0;
  }
  
+ #if IS_ENABLED(CONFIG_OF)
  static int davinci_mdio_probe_dt(struct mdio_platform_data *data,
                         struct platform_device *pdev)
  {
  
        return 0;
  }
+ #endif
  
  static int davinci_mdio_probe(struct platform_device *pdev)
  {
        data->bus->parent       = dev;
        data->bus->priv         = data;
  
 +      /* Select default pin state */
 +      pinctrl_pm_select_default_state(&pdev->dev);
 +
        pm_runtime_enable(&pdev->dev);
        pm_runtime_get_sync(&pdev->dev);
        data->clk = clk_get(&pdev->dev, "fck");
@@@ -457,9 -454,6 +458,9 @@@ static int davinci_mdio_suspend(struct 
        spin_unlock(&data->lock);
        pm_runtime_put_sync(data->dev);
  
 +      /* Select sleep pin state */
 +      pinctrl_pm_select_sleep_state(dev);
 +
        return 0;
  }
  
@@@ -467,9 -461,6 +468,9 @@@ static int davinci_mdio_resume(struct d
  {
        struct davinci_mdio_data *data = dev_get_drvdata(dev);
  
 +      /* Select default pin state */
 +      pinctrl_pm_select_default_state(dev);
 +
        pm_runtime_get_sync(data->dev);
  
        spin_lock(&data->lock);
@@@ -487,11 -478,13 +488,13 @@@ static const struct dev_pm_ops davinci_
        .resume_early   = davinci_mdio_resume,
  };
  
+ #if IS_ENABLED(CONFIG_OF)
  static const struct of_device_id davinci_mdio_of_mtable[] = {
        { .compatible = "ti,davinci_mdio", },
        { /* sentinel */ },
  };
  MODULE_DEVICE_TABLE(of, davinci_mdio_of_mtable);
+ #endif
  
  static struct platform_driver davinci_mdio_driver = {
        .driver = {
diff --combined drivers/net/netconsole.c
@@@ -40,7 -40,6 +40,7 @@@
  #include <linux/slab.h>
  #include <linux/console.h>
  #include <linux/moduleparam.h>
 +#include <linux/kernel.h>
  #include <linux/string.h>
  #include <linux/netpoll.h>
  #include <linux/inet.h>
@@@ -654,12 -653,11 +654,11 @@@ static struct configfs_subsystem netcon
  
  /* Handle network interface device notifications */
  static int netconsole_netdev_event(struct notifier_block *this,
-                                  unsigned long event,
-                                  void *ptr)
+                                  unsigned long event, void *ptr)
  {
        unsigned long flags;
        struct netconsole_target *nt;
-       struct net_device *dev = ptr;
+       struct net_device *dev = netdev_notifier_info_to_dev(ptr);
        bool stopped = false;
  
        if (!(event == NETDEV_CHANGENAME || event == NETDEV_UNREGISTER ||
diff --combined drivers/net/phy/phy.c
@@@ -294,7 -294,8 +294,8 @@@ int phy_ethtool_gset(struct phy_device 
        cmd->duplex = phydev->duplex;
        cmd->port = PORT_MII;
        cmd->phy_address = phydev->addr;
-       cmd->transceiver = XCVR_EXTERNAL;
+       cmd->transceiver = phy_is_internal(phydev) ?
+               XCVR_INTERNAL : XCVR_EXTERNAL;
        cmd->autoneg = phydev->autoneg;
  
        return 0;
@@@ -419,8 -420,6 +420,6 @@@ out_unlock
  EXPORT_SYMBOL(phy_start_aneg);
  
  
- static void phy_change(struct work_struct *work);
  /**
   * phy_start_machine - start PHY state machine tracking
   * @phydev: the phy_device struct
@@@ -439,7 -438,7 +438,7 @@@ void phy_start_machine(struct phy_devic
  {
        phydev->adjust_state = handler;
  
 -      schedule_delayed_work(&phydev->state_queue, HZ);
 +      queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, HZ);
  }
  
  /**
@@@ -500,7 -499,7 +499,7 @@@ static irqreturn_t phy_interrupt(int ir
        disable_irq_nosync(irq);
        atomic_inc(&phydev->irq_disable);
  
 -      schedule_work(&phydev->phy_queue);
 +      queue_work(system_power_efficient_wq, &phydev->phy_queue);
  
        return IRQ_HANDLED;
  }
@@@ -565,8 -564,6 +564,6 @@@ int phy_start_interrupts(struct phy_dev
  {
        int err = 0;
  
-       INIT_WORK(&phydev->phy_queue, phy_change);
        atomic_set(&phydev->irq_disable, 0);
        if (request_irq(phydev->irq, phy_interrupt,
                                IRQF_SHARED,
@@@ -623,7 -620,7 +620,7 @@@ EXPORT_SYMBOL(phy_stop_interrupts)
   * phy_change - Scheduled by the phy_interrupt/timer to handle PHY changes
   * @work: work_struct that describes the work to be done
   */
static void phy_change(struct work_struct *work)
+ void phy_change(struct work_struct *work)
  {
        int err;
        struct phy_device *phydev =
  
        /* reschedule state queue work to run as soon as possible */
        cancel_delayed_work_sync(&phydev->state_queue);
 -      schedule_delayed_work(&phydev->state_queue, 0);
 +      queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, 0);
  
        return;
  
@@@ -682,7 -679,7 +679,7 @@@ void phy_stop(struct phy_device *phydev
        if (PHY_HALTED == phydev->state)
                goto out_unlock;
  
-       if (phydev->irq != PHY_POLL) {
+       if (phy_interrupt_is_valid(phydev)) {
                /* Disable PHY Interrupts */
                phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
  
@@@ -828,8 -825,9 +825,9 @@@ void phy_state_machine(struct work_stru
                        break;
                case PHY_RUNNING:
                        /* Only register a CHANGE if we are
-                        * polling */
-                       if (PHY_POLL == phydev->irq)
+                        * polling or ignoring interrupts
+                        */
+                       if (!phy_interrupt_is_valid(phydev))
                                phydev->state = PHY_CHANGELINK;
                        break;
                case PHY_CHANGELINK:
  
                        phydev->adjust_link(phydev->attached_dev);
  
-                       if (PHY_POLL != phydev->irq)
+                       if (phy_interrupt_is_valid(phydev))
                                err = phy_config_interrupt(phydev,
                                                PHY_INTERRUPT_ENABLED);
                        break;
        if (err < 0)
                phy_error(phydev);
  
 -      schedule_delayed_work(&phydev->state_queue, PHY_STATE_TIME * HZ);
 +      queue_delayed_work(system_power_efficient_wq, &phydev->state_queue,
 +                      PHY_STATE_TIME * HZ);
  }
  
+ void phy_mac_interrupt(struct phy_device *phydev, int new_link)
+ {
+       cancel_work_sync(&phydev->phy_queue);
+       phydev->link = new_link;
+       schedule_work(&phydev->phy_queue);
+ }
+ EXPORT_SYMBOL(phy_mac_interrupt);
  static inline void mmd_phy_indirect(struct mii_bus *bus, int prtad, int devad,
                                    int addr)
  {
@@@ -28,7 -28,7 +28,7 @@@ config ATH9
          Atheros IEEE 802.11n AR5008, AR9001 and AR9002 family
          of chipsets. For a specific list of supported external
          cards, laptops that already ship with these cards and
 -        APs that come with these cards refer to to ath9k wiki
 +        APs that come with these cards refer to ath9k wiki
          products page:
  
          http://wireless.kernel.org/en/users/Drivers/ath9k/products
@@@ -84,14 -84,6 +84,6 @@@ config ATH9K_DFS_CERTIFIE
          developed. At this point enabling this option won't do anything
          except increase code size.
  
- config ATH9K_MAC_DEBUG
-       bool "Atheros MAC statistics"
-       depends on ATH9K_DEBUGFS
-       default y
-       ---help---
-         This option enables collection of statistics for Rx/Tx status
-         data and some other MAC related statistics
  config ATH9K_LEGACY_RATE_CONTROL
        bool "Atheros ath9k rate control"
        depends on ATH9K
@@@ -3548,6 -3548,7 +3548,7 @@@ static int ipw_load(struct ipw_priv *pr
                ipw_rx_queue_reset(priv, priv->rxq);
        if (!priv->rxq) {
                IPW_ERROR("Unable to initialize Rx queue\n");
+               rc = -ENOMEM;
                goto error;
        }
  
@@@ -8256,7 -8257,7 +8257,7 @@@ static  int is_duplicate_packet(struct 
                        u8 *mac = header->addr2;
                        int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
  
 -                      __list_for_each(p, &priv->ibss_mac_hash[index]) {
 +                      list_for_each(p, &priv->ibss_mac_hash[index]) {
                                entry =
                                    list_entry(p, struct ipw_ibss_seq, list);
                                if (!memcmp(entry->mac, mac, ETH_ALEN))
@@@ -334,7 -334,7 +334,7 @@@ void rt2x00lib_txdone(struct queue_entr
        /*
         * Remove the extra tx headroom from the skb.
         */
-       skb_pull(entry->skb, rt2x00dev->ops->extra_tx_headroom);
+       skb_pull(entry->skb, rt2x00dev->extra_tx_headroom);
  
        /*
         * Signal that the TX descriptor is no longer in the skb.
@@@ -1049,7 -1049,7 +1049,7 @@@ static int rt2x00lib_probe_hw(struct rt
         */
        rt2x00dev->hw->extra_tx_headroom =
                max_t(unsigned int, IEEE80211_TX_STATUS_HEADROOM,
-                     rt2x00dev->ops->extra_tx_headroom);
+                     rt2x00dev->extra_tx_headroom);
  
        /*
         * Take TX headroom required for alignment into account.
                 */
                int kfifo_size =
                        roundup_pow_of_two(rt2x00dev->ops->tx_queues *
-                                          rt2x00dev->ops->tx->entry_num *
+                                          rt2x00dev->tx->limit *
                                           sizeof(u32));
  
                status = kfifo_alloc(&rt2x00dev->txstatus_fifo, kfifo_size,
@@@ -1256,6 -1256,17 +1256,17 @@@ static inline void rt2x00lib_set_if_com
        rt2x00dev->hw->wiphy->n_iface_combinations = 1;
  }
  
+ static unsigned int rt2x00dev_extra_tx_headroom(struct rt2x00_dev *rt2x00dev)
+ {
+       if (WARN_ON(!rt2x00dev->tx))
+               return 0;
+       if (rt2x00_is_usb(rt2x00dev))
+               return rt2x00dev->tx[0].winfo_size + rt2x00dev->tx[0].desc_size;
+       return rt2x00dev->tx[0].winfo_size;
+ }
  /*
   * driver allocation handlers.
   */
@@@ -1300,28 -1311,11 +1311,11 @@@ int rt2x00lib_probe_dev(struct rt2x00_d
        rt2x00dev->hw->wiphy->addr_mask[ETH_ALEN - 1] =
                (rt2x00dev->ops->max_ap_intf - 1);
  
-       /*
-        * Determine which operating modes are supported, all modes
-        * which require beaconing, depend on the availability of
-        * beacon entries.
-        */
-       rt2x00dev->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
-       if (rt2x00dev->ops->bcn->entry_num > 0)
-               rt2x00dev->hw->wiphy->interface_modes |=
-                   BIT(NL80211_IFTYPE_ADHOC) |
-                   BIT(NL80211_IFTYPE_AP) |
- #ifdef CONFIG_MAC80211_MESH
-                   BIT(NL80211_IFTYPE_MESH_POINT) |
- #endif
-                   BIT(NL80211_IFTYPE_WDS);
-       rt2x00dev->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
        /*
         * Initialize work.
         */
        rt2x00dev->workqueue =
 -          alloc_ordered_workqueue(wiphy_name(rt2x00dev->hw->wiphy), 0);
 +          alloc_ordered_workqueue("%s", 0, wiphy_name(rt2x00dev->hw->wiphy));
        if (!rt2x00dev->workqueue) {
                retval = -ENOMEM;
                goto exit;
        if (retval)
                goto exit;
  
+       /* Cache TX headroom value */
+       rt2x00dev->extra_tx_headroom = rt2x00dev_extra_tx_headroom(rt2x00dev);
+       /*
+        * Determine which operating modes are supported, all modes
+        * which require beaconing, depend on the availability of
+        * beacon entries.
+        */
+       rt2x00dev->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
+       if (rt2x00dev->bcn->limit > 0)
+               rt2x00dev->hw->wiphy->interface_modes |=
+                   BIT(NL80211_IFTYPE_ADHOC) |
+                   BIT(NL80211_IFTYPE_AP) |
+ #ifdef CONFIG_MAC80211_MESH
+                   BIT(NL80211_IFTYPE_MESH_POINT) |
+ #endif
+                   BIT(NL80211_IFTYPE_WDS);
+       rt2x00dev->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
        /*
         * Initialize ieee80211 structure.
         */
@@@ -380,7 -380,7 +380,7 @@@ static void _rtl_init_deferred_work(str
  
        /* <2> work queue */
        rtlpriv->works.hw = hw;
 -      rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0);
 +      rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
        INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
                          (void *)rtl_watchdog_wq_callback);
        INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
@@@ -1817,7 -1817,7 +1817,7 @@@ static ssize_t rtl_store_debug_level(st
        unsigned long val;
        int ret;
  
-       ret = strict_strtoul(buf, 0, &val);
+       ret = kstrtoul(buf, 0, &val);
        if (ret) {
                printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf);
        } else {
diff --combined drivers/nfc/pn533.c
@@@ -258,7 -258,7 +258,7 @@@ static const struct pn533_poll_modulati
                                .opcode = PN533_FELICA_OPC_SENSF_REQ,
                                .sc = PN533_FELICA_SENSF_SC_ALL,
                                .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE,
-                               .tsn = 0,
+                               .tsn = 0x03,
                        },
                },
                .len = 7,
                                .opcode = PN533_FELICA_OPC_SENSF_REQ,
                                .sc = PN533_FELICA_SENSF_SC_ALL,
                                .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE,
-                               .tsn = 0,
+                               .tsn = 0x03,
                        },
                 },
                .len = 7,
@@@ -1235,7 -1235,7 +1235,7 @@@ static int pn533_target_found_type_a(st
  struct pn533_target_felica {
        u8 pol_res;
        u8 opcode;
-       u8 nfcid2[8];
+       u8 nfcid2[NFC_NFCID2_MAXSIZE];
        u8 pad[8];
        /* optional */
        u8 syst_code[];
@@@ -1275,6 -1275,9 +1275,9 @@@ static int pn533_target_found_felica(st
        memcpy(nfc_tgt->sensf_res, &tgt_felica->opcode, 9);
        nfc_tgt->sensf_res_len = 9;
  
+       memcpy(nfc_tgt->nfcid2, tgt_felica->nfcid2, NFC_NFCID2_MAXSIZE);
+       nfc_tgt->nfcid2_len = NFC_NFCID2_MAXSIZE;
        return 0;
  }
  
@@@ -1697,7 -1700,7 +1700,7 @@@ static int pn533_poll_complete(struct p
                goto done;
  
        if (!dev->poll_mod_count) {
 -              nfc_dev_dbg(&dev->interface->dev, "Polling has been stoped.");
 +              nfc_dev_dbg(&dev->interface->dev, "Polling has been stopped.");
                goto done;
        }
  
@@@ -2084,6 -2087,9 +2087,9 @@@ static int pn533_dep_link_up(struct nfc
        if (comm_mode == NFC_COMM_PASSIVE)
                skb_len += PASSIVE_DATA_LEN;
  
+       if (target && target->nfcid2_len)
+               skb_len += NFC_NFCID3_MAXSIZE;
        skb = pn533_alloc_skb(dev, skb_len);
        if (!skb)
                return -ENOMEM;
                *next |= 1;
        }
  
+       if (target && target->nfcid2_len) {
+               memcpy(skb_put(skb, NFC_NFCID3_MAXSIZE), target->nfcid2,
+                      target->nfcid2_len);
+               *next |= 2;
+       }
        if (gb != NULL && gb_len > 0) {
                memcpy(skb_put(skb, gb_len), gb, gb_len);
                *next |= 4; /* We have some Gi */
@@@ -2489,7 -2501,7 +2501,7 @@@ static void pn533_acr122_poweron_rdr_re
  
        nfc_dev_dbg(&urb->dev->dev, "%s", __func__);
  
-       print_hex_dump(KERN_ERR, "ACR122 RX: ", DUMP_PREFIX_NONE, 16, 1,
+       print_hex_dump_debug("ACR122 RX: ", DUMP_PREFIX_NONE, 16, 1,
                       urb->transfer_buffer, urb->transfer_buffer_length,
                       false);
  
@@@ -2520,7 -2532,7 +2532,7 @@@ static int pn533_acr122_poweron_rdr(str
        dev->out_urb->transfer_buffer = cmd;
        dev->out_urb->transfer_buffer_length = sizeof(cmd);
  
-       print_hex_dump(KERN_ERR, "ACR122 TX: ", DUMP_PREFIX_NONE, 16, 1,
+       print_hex_dump_debug("ACR122 TX: ", DUMP_PREFIX_NONE, 16, 1,
                       cmd, sizeof(cmd), false);
  
        rc = usb_submit_urb(dev->out_urb, GFP_KERNEL);
@@@ -2774,17 -2786,18 +2786,18 @@@ static int pn533_probe(struct usb_inter
                goto destroy_wq;
  
        nfc_dev_info(&dev->interface->dev,
-                    "NXP PN533 firmware ver %d.%d now attached",
-                    fw_ver.ver, fw_ver.rev);
+                    "NXP PN5%02X firmware ver %d.%d now attached",
+                    fw_ver.ic, fw_ver.ver, fw_ver.rev);
  
  
        dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols,
-                                          NFC_SE_NONE,
                                           dev->ops->tx_header_len +
                                           PN533_CMD_DATAEXCH_HEAD_LEN,
                                           dev->ops->tx_tail_len);
-       if (!dev->nfc_dev)
+       if (!dev->nfc_dev) {
+               rc = -ENOMEM;
                goto destroy_wq;
+       }
  
        nfc_set_parent_dev(dev->nfc_dev, &interface->dev);
        nfc_set_drvdata(dev->nfc_dev, dev);
@@@ -1282,8 -1282,10 +1282,10 @@@ static void qeth_free_qdio_buffers(stru
  
        qeth_free_cq(card);
        cancel_delayed_work_sync(&card->buffer_reclaim_work);
-       for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
-               dev_kfree_skb_any(card->qdio.in_q->bufs[j].rx_skb);
+       for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
+               if (card->qdio.in_q->bufs[j].rx_skb)
+                       dev_kfree_skb_any(card->qdio.in_q->bufs[j].rx_skb);
+       }
        kfree(card->qdio.in_q);
        card->qdio.in_q = NULL;
        /* inbound buffer pool */
@@@ -1729,14 -1731,14 +1731,14 @@@ static void qeth_configure_blkt_default
        QETH_DBF_TEXT(SETUP, 2, "cfgblkt");
  
        if (prcd[74] == 0xF0 && prcd[75] == 0xF0 &&
-           (prcd[76] == 0xF5 || prcd[76] == 0xF6)) {
-               card->info.blkt.time_total = 250;
-               card->info.blkt.inter_packet = 5;
-               card->info.blkt.inter_packet_jumbo = 15;
-       } else {
+           prcd[76] >= 0xF1 && prcd[76] <= 0xF4) {
                card->info.blkt.time_total = 0;
                card->info.blkt.inter_packet = 0;
                card->info.blkt.inter_packet_jumbo = 0;
+       } else {
+               card->info.blkt.time_total = 250;
+               card->info.blkt.inter_packet = 5;
+               card->info.blkt.inter_packet_jumbo = 15;
        }
  }
  
@@@ -2198,11 -2200,11 +2200,11 @@@ static inline int qeth_get_initial_mtu_
                case QETH_LINK_TYPE_LANE_TR:
                        return 2000;
                default:
-                       return 1492;
+                       return card->options.layer2 ? 1500 : 1492;
                }
        case QETH_CARD_TYPE_OSM:
        case QETH_CARD_TYPE_OSX:
-               return 1492;
+               return card->options.layer2 ? 1500 : 1492;
        default:
                return 1500;
        }
@@@ -2275,9 -2277,10 +2277,10 @@@ static int qeth_ulp_enable_cb(struct qe
                card->info.max_mtu = mtu;
                card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
        } else {
-               card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
                card->info.max_mtu = *(__u16 *)QETH_ULP_ENABLE_RESP_MAX_MTU(
                        iob->data);
+               card->info.initial_mtu = min(card->info.max_mtu,
+                                       qeth_get_initial_mtu_for_card(card));
                card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
        }
  
@@@ -5705,7 -5708,7 +5708,7 @@@ static int __init qeth_core_init(void
        if (rc)
                goto out_err;
        qeth_core_root_dev = root_device_register("qeth");
 -      rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0;
 +      rc = PTR_RET(qeth_core_root_dev);
        if (rc)
                goto register_err;
        qeth_core_header_cache = kmem_cache_create("qeth_hdr",
@@@ -20,7 -20,6 +20,7 @@@
  #include <net/dst.h>
  #include <linux/netdevice.h>
  
 +#include "t4_regs.h"
  #include "t4_msg.h"
  #include "cxgb4.h"
  #include "cxgb4_uld.h"
@@@ -33,12 -32,13 +33,12 @@@ static unsigned int dbg_level
  #include "../libcxgbi.h"
  
  #define       DRV_MODULE_NAME         "cxgb4i"
 -#define DRV_MODULE_DESC               "Chelsio T4 iSCSI Driver"
 -#define       DRV_MODULE_VERSION      "0.9.1"
 -#define       DRV_MODULE_RELDATE      "Aug. 2010"
 +#define DRV_MODULE_DESC               "Chelsio T4/T5 iSCSI Driver"
 +#define       DRV_MODULE_VERSION      "0.9.4"
  
  static char version[] =
        DRV_MODULE_DESC " " DRV_MODULE_NAME
 -      " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
 +      " v" DRV_MODULE_VERSION "\n";
  
  MODULE_AUTHOR("Chelsio Communications, Inc.");
  MODULE_DESCRIPTION(DRV_MODULE_DESC);
@@@ -175,56 -175,10 +175,56 @@@ static inline int is_ofld_imm(const str
                        sizeof(struct fw_ofld_tx_data_wr));
  }
  
 +
 +#define VLAN_NONE 0xfff
 +#define FILTER_SEL_VLAN_NONE 0xffff
 +#define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
 +#define FILTER_SEL_WIDTH_VIN_P_FC \
 +      (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
 +#define FILTER_SEL_WIDTH_TAG_P_FC \
 +      (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
 +#define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
 +
 +static unsigned int select_ntuple(struct cxgbi_device *cdev,
 +                              struct l2t_entry *l2t)
 +{
 +      struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
 +      unsigned int ntuple = 0;
 +      u32 viid;
 +
 +      switch (lldi->filt_mode) {
 +
 +      /* default filter mode */
 +      case HW_TPL_FR_MT_PR_IV_P_FC:
 +              if (l2t->vlan == VLAN_NONE)
 +                      ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
 +              else {
 +                      ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
 +                      ntuple |= 1 << FILTER_SEL_WIDTH_VLD_TAG_P_FC;
 +              }
 +              ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
 +                        FILTER_SEL_WIDTH_VLD_TAG_P_FC;
 +              break;
 +      case HW_TPL_FR_MT_PR_OV_P_FC: {
 +              viid = cxgb4_port_viid(l2t->neigh->dev);
 +
 +              ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
 +              ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
 +              ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
 +              ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
 +                        FILTER_SEL_WIDTH_VLD_TAG_P_FC;
 +              break;
 +      }
 +      default:
 +              break;
 +      }
 +      return ntuple;
 +}
 +
  static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
                                struct l2t_entry *e)
  {
 -      struct cpl_act_open_req *req;
 +      struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
        int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
        unsigned long long opt0;
        unsigned int opt2;
                RCV_BUFSIZ(cxgb4i_rcv_win >> 10);
        opt2 = RX_CHANNEL(0) |
                RSS_QUEUE_VALID |
 -              (1 << 20) | (1 << 22) |
 +              (1 << 20) |
                RSS_QUEUE(csk->rss_qid);
  
 -      set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
 -      req = (struct cpl_act_open_req *)skb->head;
 +      if (is_t4(lldi->adapter_type)) {
 +              struct cpl_act_open_req *req =
 +                              (struct cpl_act_open_req *)skb->head;
 +
 +              req = (struct cpl_act_open_req *)skb->head;
  
 -      INIT_TP_WR(req, 0);
 -      OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
 +              INIT_TP_WR(req, 0);
 +              OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
                                        qid_atid));
 -      req->local_port = csk->saddr.sin_port;
 -      req->peer_port = csk->daddr.sin_port;
 -      req->local_ip = csk->saddr.sin_addr.s_addr;
 -      req->peer_ip = csk->daddr.sin_addr.s_addr;
 -      req->opt0 = cpu_to_be64(opt0);
 -      req->params = 0;
 -      req->opt2 = cpu_to_be32(opt2);
 +              req->local_port = csk->saddr.sin_port;
 +              req->peer_port = csk->daddr.sin_port;
 +              req->local_ip = csk->saddr.sin_addr.s_addr;
 +              req->peer_ip = csk->daddr.sin_addr.s_addr;
 +              req->opt0 = cpu_to_be64(opt0);
 +              req->params = cpu_to_be32(select_ntuple(csk->cdev, csk->l2t));
 +              opt2 |= 1 << 22;
 +              req->opt2 = cpu_to_be32(opt2);
  
 -      log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
 -              "csk 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
 -              csk, &req->local_ip, ntohs(req->local_port),
 -              &req->peer_ip, ntohs(req->peer_port),
 -              csk->atid, csk->rss_qid);
 +              log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
 +                      "csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
 +                      csk, &req->local_ip, ntohs(req->local_port),
 +                      &req->peer_ip, ntohs(req->peer_port),
 +                      csk->atid, csk->rss_qid);
 +      } else {
 +              struct cpl_t5_act_open_req *req =
 +                              (struct cpl_t5_act_open_req *)skb->head;
 +
 +              req = (struct cpl_t5_act_open_req *)skb->head;
  
 +              INIT_TP_WR(req, 0);
 +              OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
 +                                      qid_atid));
 +              req->local_port = csk->saddr.sin_port;
 +              req->peer_port = csk->daddr.sin_port;
 +              req->local_ip = csk->saddr.sin_addr.s_addr;
 +              req->peer_ip = csk->daddr.sin_addr.s_addr;
 +              req->opt0 = cpu_to_be64(opt0);
 +              req->params = cpu_to_be32(select_ntuple(csk->cdev, csk->l2t));
 +              opt2 |= 1 << 31;
 +              req->opt2 = cpu_to_be32(opt2);
 +
 +              log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
 +                      "csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
 +                      csk, &req->local_ip, ntohs(req->local_port),
 +                      &req->peer_ip, ntohs(req->peer_port),
 +                      csk->atid, csk->rss_qid);
 +      }
 +
 +      set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
        cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  }
  
@@@ -433,7 -358,7 +433,7 @@@ static inline unsigned int calc_tx_flit
                return DIV_ROUND_UP(skb->len, 8);
        flits = skb_transport_offset(skb) / 8;
        cnt = skb_shinfo(skb)->nr_frags;
-       if (skb->tail != skb->transport_header)
+       if (skb_tail_pointer(skb) != skb_transport_header(skb))
                cnt++;
        return flits + sgl_len(cnt);
  }
@@@ -707,7 -632,6 +707,7 @@@ static void csk_act_open_retry_timer(un
  {
        struct sk_buff *skb;
        struct cxgbi_sock *csk = (struct cxgbi_sock *)data;
 +      struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
  
        log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
                "csk 0x%p,%u,0x%lx,%u.\n",
  
        cxgbi_sock_get(csk);
        spin_lock_bh(&csk->lock);
 -      skb = alloc_wr(sizeof(struct cpl_act_open_req), 0, GFP_ATOMIC);
 +      skb = alloc_wr(is_t4(lldi->adapter_type) ?
 +                              sizeof(struct cpl_act_open_req) :
 +                              sizeof(struct cpl_t5_act_open_req),
 +                      0, GFP_ATOMIC);
        if (!skb)
                cxgbi_sock_fail_act_open(csk, -ENOMEM);
        else {
@@@ -950,7 -871,7 +950,7 @@@ static void do_rx_iscsi_hdr(struct cxgb
  
        if (!csk->skb_ulp_lhdr) {
                unsigned char *bhs;
 -              unsigned int hlen, dlen;
 +              unsigned int hlen, dlen, plen;
  
                log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
                        "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
                hlen = ntohs(cpl->len);
                dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
  
 -              if ((hlen + dlen) != ISCSI_PDU_LEN(pdu_len_ddp) - 40) {
 +              plen = ISCSI_PDU_LEN(pdu_len_ddp);
 +              if (is_t4(lldi->adapter_type))
 +                      plen -= 40;
 +
 +              if ((hlen + dlen) != plen) {
                        pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
                                "mismatch %u != %u + %u, seq 0x%x.\n",
 -                              csk->tid, ISCSI_PDU_LEN(pdu_len_ddp) - 40,
 -                              hlen, dlen, cxgbi_skcb_tcp_seq(skb));
 +                              csk->tid, plen, hlen, dlen,
 +                              cxgbi_skcb_tcp_seq(skb));
                        goto abort_conn;
                }
  
@@@ -1237,10 -1154,7 +1237,10 @@@ static int init_act_open(struct cxgbi_s
        }
        cxgbi_sock_get(csk);
  
 -      skb = alloc_wr(sizeof(struct cpl_act_open_req), 0, GFP_KERNEL);
 +      skb = alloc_wr(is_t4(lldi->adapter_type) ?
 +                              sizeof(struct cpl_act_open_req) :
 +                              sizeof(struct cpl_t5_act_open_req),
 +                      0, GFP_ATOMIC);
        if (!skb)
                goto rel_resource;
        skb->sk = (struct sock *)csk;
@@@ -1279,8 -1193,6 +1279,8 @@@ rel_resource
        return -EINVAL;
  }
  
 +#define CPL_ISCSI_DATA                0xB2
 +#define CPL_RX_ISCSI_DDP      0x49
  cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
        [CPL_ACT_ESTABLISH] = do_act_establish,
        [CPL_ACT_OPEN_RPL] = do_act_open_rpl,
        [CPL_CLOSE_CON_RPL] = do_close_con_rpl,
        [CPL_FW4_ACK] = do_fw4_ack,
        [CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
 +      [CPL_ISCSI_DATA] = do_rx_iscsi_hdr,
        [CPL_SET_TCB_RPL] = do_set_tcb_rpl,
        [CPL_RX_DATA_DDP] = do_rx_data_ddp,
 +      [CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
  };
  
  int cxgb4i_ofld_init(struct cxgbi_device *cdev)
   * functions to program the pagepod in h/w
   */
  #define ULPMEM_IDATA_MAX_NPPODS       4 /* 256/PPOD_SIZE */
 -static inline void ulp_mem_io_set_hdr(struct ulp_mem_io *req,
 +static inline void ulp_mem_io_set_hdr(struct cxgb4_lld_info *lldi,
 +                              struct ulp_mem_io *req,
                                unsigned int wr_len, unsigned int dlen,
                                unsigned int pm_addr)
  {
        struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
  
        INIT_ULPTX_WR(req, wr_len, 0, 0);
 -      req->cmd = htonl(ULPTX_CMD(ULP_TX_MEM_WRITE) | (1 << 23));
 +      if (is_t4(lldi->adapter_type))
 +              req->cmd = htonl(ULPTX_CMD(ULP_TX_MEM_WRITE) |
 +                                      (ULP_MEMIO_ORDER(1)));
 +      else
 +              req->cmd = htonl(ULPTX_CMD(ULP_TX_MEM_WRITE) |
 +                                      (V_T5_ULP_MEMIO_IMM(1)));
        req->dlen = htonl(ULP_MEMIO_DATA_LEN(dlen >> 5));
        req->lock_addr = htonl(ULP_MEMIO_ADDR(pm_addr >> 5));
        req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
@@@ -1353,7 -1257,6 +1353,7 @@@ static int ddp_ppod_write_idata(struct 
                                unsigned int gl_pidx)
  {
        struct cxgbi_ddp_info *ddp = cdev->ddp;
 +      struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
        struct sk_buff *skb;
        struct ulp_mem_io *req;
        struct ulptx_idata *idata;
        req = (struct ulp_mem_io *)skb->head;
        set_queue(skb, CPL_PRIORITY_CONTROL, NULL);
  
 -      ulp_mem_io_set_hdr(req, wr_len, dlen, pm_addr);
 +      ulp_mem_io_set_hdr(lldi, req, wr_len, dlen, pm_addr);
        idata = (struct ulptx_idata *)(req + 1);
        ppod = (struct cxgbi_pagepod *)(idata + 1);
  
@@@ -558,7 -558,7 +558,7 @@@ static int iscsi_tcp_r2t_rsp(struct isc
        if (!rc) {
                iscsi_conn_printk(KERN_ERR, conn, "Could not allocate R2T. "
                                  "Target has sent more R2Ts than it "
 -                                "negotiated for or driver has has leaked.\n");
 +                                "negotiated for or driver has leaked.\n");
                return ISCSI_ERR_PROTO;
        }
  
@@@ -906,7 -906,6 +906,6 @@@ int iscsi_tcp_recv_skb(struct iscsi_con
                        ISCSI_DBG_TCP(conn, "no more data avail. Consumed %d\n",
                                      consumed);
                        *status = ISCSI_TCP_SKB_DONE;
-                       skb_abort_seq_read(&seq);
                        goto skb_done;
                }
                BUG_ON(segment->copied >= segment->size);
@@@ -754,7 -754,7 +754,7 @@@ get_packet_priority(unifi_priv_t *priv
          case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
              {
                  CsrWifiRouterCtrlStaInfo_t * dstStaInfo =
 -                    CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,ehdr->h_dest, interfacePriv->InterfaceTag);
 +                    CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, ehdr->h_dest, interfacePriv->InterfaceTag);
                  unifi_trace(priv, UDBG4, "mode is AP \n");
                  if (!(ehdr->h_dest[0] & 0x01) && dstStaInfo && dstStaInfo->wmmOrQosEnabled) {
                      /* If packet is not Broadcast/multicast */
@@@ -1011,7 -1011,7 +1011,7 @@@ skb_80211_to_ether(unifi_priv_t *priv, 
  #endif
  
      if(skb== NULL || daddr == NULL || saddr == NULL){
 -        unifi_error(priv,"skb_80211_to_ether: PBC fail\n");
 +        unifi_error(priv, "skb_80211_to_ether: PBC fail\n");
          return 1;
      }
  
@@@ -1198,7 -1198,7 +1198,7 @@@ int prepare_and_add_macheader(unifi_pri
      u8 bQosNull = false;
  
      if (skb == NULL) {
 -        unifi_error(priv,"prepare_and_add_macheader: Invalid SKB reference\n");
 +        unifi_error(priv, "prepare_and_add_macheader: Invalid SKB reference\n");
          return -1;
      }
  
              macHeaderLengthInBytes -= ETH_ALEN;
              break;
          default:
 -            unifi_error(priv,"Unknown direction =%d : Not handled now\n",direction);
 +            unifi_error(priv, "Unknown direction =%d : Not handled now\n", direction);
              return -1;
      }
      /* 2 bytes of frame control field, appended by firmware */
@@@ -1569,8 -1569,8 +1569,8 @@@ send_ma_pkt_request(unifi_priv_t *priv
      memcpy(peerAddress.a, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
  
      unifi_trace(priv, UDBG5, "RA[0]=%x, RA[1]=%x, RA[2]=%x, RA[3]=%x, RA[4]=%x, RA[5]=%x\n",
 -                peerAddress.a[0],peerAddress.a[1], peerAddress.a[2], peerAddress.a[3],
 -                peerAddress.a[4],peerAddress.a[5]);
 +                peerAddress.a[0], peerAddress.a[1], peerAddress.a[2], peerAddress.a[3],
 +                peerAddress.a[4], peerAddress.a[5]);
  
  
      if ((proto == ETH_P_PAE)
@@@ -1865,10 -1865,10 +1865,10 @@@ unifi_pause_xmit(void *ospriv, unifi_Tr
  
  #ifdef CSR_SUPPORT_SME
      if(queue<=3) {
 -        routerStartBuffering(priv,queue);
 -        unifi_trace(priv,UDBG2,"Start buffering %d\n", queue);
 +        routerStartBuffering(priv, queue);
 +        unifi_trace(priv, UDBG2, "Start buffering %d\n", queue);
       } else {
 -        routerStartBuffering(priv,0);
 +        routerStartBuffering(priv, 0);
          unifi_error(priv, "Start buffering %d defaulting to 0\n", queue);
       }
  #endif
@@@ -1893,11 -1893,11 +1893,11 @@@ unifi_restart_xmit(void *ospriv, unifi_
  
  #ifdef CSR_SUPPORT_SME
      if(queue <=3) {
 -        routerStopBuffering(priv,queue);
 -        uf_send_buffered_frames(priv,queue);
 +        routerStopBuffering(priv, queue);
 +        uf_send_buffered_frames(priv, queue);
      } else {
 -        routerStopBuffering(priv,0);
 -        uf_send_buffered_frames(priv,0);
 +        routerStopBuffering(priv, 0);
 +        uf_send_buffered_frames(priv, 0);
      }
  #endif
  } /* unifi_restart_xmit() */
@@@ -2102,14 -2102,14 +2102,14 @@@ uf_resume_data_plane(unifi_priv_t *priv
              netif_tx_schedule_all(priv->netdev[interfaceTag]);
          }
  #endif
 -        uf_process_rx_pending_queue(priv, queue, peer_address, 1,interfaceTag);
 +        uf_process_rx_pending_queue(priv, queue, peer_address, 1, interfaceTag);
      }
  } /* uf_resume_data_plane() */
  
  
 -void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue, CsrWifiMacAddress peer_address,u16 interfaceTag)
 +void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue, CsrWifiMacAddress peer_address, u16 interfaceTag)
  {
 -    uf_process_rx_pending_queue(priv, queue, peer_address, 0,interfaceTag);
 +    uf_process_rx_pending_queue(priv, queue, peer_address, 0, interfaceTag);
  
  } /* uf_free_pending_rx_packets() */
  
@@@ -2153,7 -2153,7 +2153,7 @@@ unifi_rx(unifi_priv_t *priv, CSR_SIGNA
      if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
      {
          unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
 -        unifi_net_data_free(priv,&bulkdata->d[0]);
 +        unifi_net_data_free(priv, &bulkdata->d[0]);
          return;
      }
  
  
      if (bulkdata->d[0].data_length == 0) {
          unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__);
 -        unifi_net_data_free(priv,&bulkdata->d[0]);
 +        unifi_net_data_free(priv, &bulkdata->d[0]);
          return;
      }
  
      toDs = (skb->data[1] & 0x01) ? 1 : 0;
      fromDs = (skb->data[1] & 0x02) ? 1 : 0;
  
 -    memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);/* Address1 or 3 */
 -    memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN); /* Address2, 3 or 4 */
 +    memcpy(da, (skb->data+4+toDs*12), ETH_ALEN);/* Address1 or 3 */
 +    memcpy(sa, (skb->data+10+fromDs*(6+toDs*8)), ETH_ALEN); /* Address2, 3 or 4 */
  
  
      pData = &bulkdata->d[0];
  
      dataFrameType =((frameControl & 0x00f0) >> 4);
      unifi_trace(priv, UDBG6,
 -                "%s: Receive Data Frame Type %d \n", __FUNCTION__,dataFrameType);
 +                "%s: Receive Data Frame Type %d \n", __FUNCTION__, dataFrameType);
  
      switch(dataFrameType)
      {
  
          /* AP/P2PGO specific handling here */
          CsrWifiRouterCtrlStaInfo_t * srcStaInfo =
 -            CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag);
 +            CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, sa, interfaceTag);
  
          /* Defensive check only; Source address is already checked in
          process_ma_packet_ind and we should have a valid source address here */
           if(srcStaInfo == NULL) {
              CsrWifiMacAddress peerMacAddress;
              /* Unknown data PDU */
 -            memcpy(peerMacAddress.a,sa,ETH_ALEN);
 +            memcpy(peerMacAddress.a, sa, ETH_ALEN);
              unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__,
 -            sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
 -            CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
 +            sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
 +            CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress);
              unifi_net_data_free(priv, &bulkdata->d[0]);
              return;
          }
          if (port_action != CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN) {
              /* Drop the packet and return */
              CsrWifiMacAddress peerMacAddress;
 -            memcpy(peerMacAddress.a,sa,ETH_ALEN);
 +            memcpy(peerMacAddress.a, sa, ETH_ALEN);
              unifi_trace(priv, UDBG3, "%s: Port is not open: unexpected frame from peer = %x:%x:%x:%x:%x:%x\n",
 -                        __FUNCTION__, sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
 +                        __FUNCTION__, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
  
 -            CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
 +            CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress);
              interfacePriv->stats.rx_dropped++;
              unifi_net_data_free(priv, &bulkdata->d[0]);
              unifi_notice(priv, "%s: Dropping packet, proto=0x%04x, %s port\n", __FUNCTION__,
          {
              return;
          }
 -        unifi_trace(priv, UDBG5, "unifi_rx: no specific AP handling process as normal frame, MAC Header len %d\n",macHeaderLengthInBytes);
 +        unifi_trace(priv, UDBG5, "unifi_rx: no specific AP handling process as normal frame, MAC Header len %d\n", macHeaderLengthInBytes);
          /* Remove the MAC header for subsequent conversion */
          skb_pull(skb, macHeaderLengthInBytes);
          pData->os_data_ptr = skb->data;
@@@ -2422,7 -2422,7 +2422,7 @@@ static void process_ma_packet_cfm(unifi
      if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
         interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
  
 -        uf_process_ma_pkt_cfm_for_ap(priv,interfaceTag,pkt_cfm);
 +        uf_process_ma_pkt_cfm_for_ap(priv, interfaceTag, pkt_cfm);
      } else if (interfacePriv->m4_sent && (pkt_cfm->HostTag == interfacePriv->m4_hostTag)) {
          /* Check if this is a confirm for EAPOL M4 frame and we need to send transmistted ind*/
          CsrResult result = pkt_cfm->TransmissionStatus == CSR_TX_SUCCESSFUL?CSR_RESULT_SUCCESS:CSR_RESULT_FAILURE;
@@@ -2486,7 -2486,7 +2486,7 @@@ static void process_ma_packet_ind(unifi
      if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
      {
          unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
 -        unifi_net_data_free(priv,&bulkdata->d[0]);
 +        unifi_net_data_free(priv, &bulkdata->d[0]);
          return;
      }
  
  
      if (bulkdata->d[0].data_length == 0) {
          unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__);
 -        unifi_net_data_free(priv,&bulkdata->d[0]);
 +        unifi_net_data_free(priv, &bulkdata->d[0]);
          return;
      }
      /* For monitor mode we need to pass this indication to the registered application
      /* MIC failure is already taken care of so no need to send the PDUs which are not successfully received in non-monitor mode*/
      if(pkt_ind->ReceptionStatus != CSR_RX_SUCCESS)
      {
 -        unifi_warning(priv, "%s: MA-PACKET indication with status = %d\n",__FUNCTION__, pkt_ind->ReceptionStatus);
 -        unifi_net_data_free(priv,&bulkdata->d[0]);
 +        unifi_warning(priv, "%s: MA-PACKET indication with status = %d\n", __FUNCTION__, pkt_ind->ReceptionStatus);
 +        unifi_net_data_free(priv, &bulkdata->d[0]);
          return;
      }
  
      toDs = (skb->data[1] & 0x01) ? 1 : 0;
      fromDs = (skb->data[1] & 0x02) ? 1 : 0;
  
 -    memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);/* Address1 or 3 */
 -    memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN); /* Address2, 3 or 4 */
 +    memcpy(da, (skb->data+4+toDs*12), ETH_ALEN);/* Address1 or 3 */
 +    memcpy(sa, (skb->data+10+fromDs*(6+toDs*8)), ETH_ALEN); /* Address2, 3 or 4 */
  
      /* Find the BSSID, which will be used to match the BA session */
      if (toDs && fromDs)
      frameControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr);
      frameType = ((frameControl & 0x000C) >> 2);
  
 -    unifi_trace(priv, UDBG3, "Rx Frame Type: %d sn: %d\n",frameType,
 +    unifi_trace(priv, UDBG3, "Rx Frame Type: %d sn: %d\n", frameType,
           (le16_to_cpu(*((u16*)(bulkdata->d[0].os_data_ptr + IEEE802_11_SEQUENCE_CONTROL_OFFSET))) >> 4) & 0xfff);
      if(frameType == IEEE802_11_FRAMETYPE_CONTROL){
  #ifdef CSR_SUPPORT_SME
              u8 pmBit = (frameControl & 0x1000)?0x01:0x00;
              unifi_trace(priv, UDBG6, "%s: Received PS-POLL Frame\n", __FUNCTION__);
  
 -            uf_process_ps_poll(priv,sa,da,pmBit,interfaceTag);
 +            uf_process_ps_poll(priv, sa, da, pmBit, interfaceTag);
          }
          else {
              unifi_warning(priv, "%s: Non PS-POLL control frame is received\n", __FUNCTION__);
          }
  #endif
 -        unifi_net_data_free(priv,&bulkdata->d[0]);
 +        unifi_net_data_free(priv, &bulkdata->d[0]);
          return;
      }
      if(frameType != IEEE802_11_FRAMETYPE_DATA) {
 -        unifi_warning(priv, "%s: Non control Non Data frame is received\n",__FUNCTION__);
 -        unifi_net_data_free(priv,&bulkdata->d[0]);
 +        unifi_warning(priv, "%s: Non control Non Data frame is received\n", __FUNCTION__);
 +        unifi_net_data_free(priv, &bulkdata->d[0]);
          return;
      }
  
      if((interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP) ||
         (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO)){
  
 -        srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag);
 +        srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, sa, interfaceTag);
  
          if(srcStaInfo == NULL) {
              CsrWifiMacAddress peerMacAddress;
              /* Unknown data PDU */
 -            memcpy(peerMacAddress.a,sa,ETH_ALEN);
 +            memcpy(peerMacAddress.a, sa, ETH_ALEN);
              unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__,
 -            sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
 -            CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
 +            sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
 +            CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress);
              unifi_net_data_free(priv, &bulkdata->d[0]);
              return;
          }
          */
  
          pmBit = (frameControl & 0x1000)?0x01:0x00;
 -        powerSaveChanged = uf_process_pm_bit_for_peer(priv,srcStaInfo,pmBit,interfaceTag);
 +        powerSaveChanged = uf_process_pm_bit_for_peer(priv, srcStaInfo, pmBit, interfaceTag);
  
          /* Update station last activity time */
          srcStaInfo->activity_flag = TRUE;
                  else{
                      qosControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr + 24);
                  }
 -                unifi_trace(priv, UDBG5, "%s: Check if U-APSD operations are triggered for qosControl: 0x%x\n",__FUNCTION__,qosControl);
 -                uf_process_wmm_deliver_ac_uapsd(priv,srcStaInfo,qosControl,interfaceTag);
 +                unifi_trace(priv, UDBG5, "%s: Check if U-APSD operations are triggered for qosControl: 0x%x\n", __FUNCTION__, qosControl);
 +                uf_process_wmm_deliver_ac_uapsd(priv, srcStaInfo, qosControl, interfaceTag);
              }
          }
      }
@@@ -2891,7 -2891,7 +2891,7 @@@ void uf_net_get_name(struct net_device 
   */
  static int
  uf_netdev_event(struct notifier_block *notif, unsigned long event, void* ptr) {
-     struct net_device *netdev = ptr;
+     struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
      netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(netdev);
      unifi_priv_t *priv = NULL;
      static const CsrWifiMacAddress broadcast_address = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
              interfacePriv->connected = UnifiConnected;
              interfacePriv->wait_netdev_change = FALSE;
              /* Note: passing the broadcast address here will allow anyone to attempt to join our adhoc network */
 -            uf_process_rx_pending_queue(priv, UF_UNCONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag);
 -            uf_process_rx_pending_queue(priv, UF_CONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag);
 +            uf_process_rx_pending_queue(priv, UF_UNCONTROLLED_PORT_Q, broadcast_address, 1, interfacePriv->InterfaceTag);
 +            uf_process_rx_pending_queue(priv, UF_CONTROLLED_PORT_Q, broadcast_address, 1, interfacePriv->InterfaceTag);
          }
          break;
  
   */
  
  #ifndef CONFIG_FORCE_HARD_FLOAT
 -double __floatsidf (int i) { return i; }
 -unsigned int __fixunsdfsi (double d) { return d; }
 -double __adddf3(double a, double b) { return a+b; }
 -double __addsf3(float a, float b) { return a+b; }
 -double __subdf3(double a, double b) { return a-b; }
 -double __extendsfdf2(float a) {return a;}
 +double __floatsidf(int i)
 +{
 +      return i;
 +}
 +
 +unsigned int __fixunsdfsi(double d)
 +{
 +      return d;
 +}
 +
 +double __adddf3(double a, double b)
 +{
 +      return a+b;
 +}
 +
 +double __addsf3(float a, float b)
 +{
 +      return a+b;
 +}
 +
 +double __subdf3(double a, double b)
 +{
 +      return a-b;
 +}
 +
 +double __extendsfdf2(float a)
 +{
 +      return a;
 +}
  #endif
  
  #undef LOOP_TEST
@@@ -91,6 -68,7 +91,6 @@@
  #include "r819xU_phyreg.h"
  #include "r819xU_cmdpkt.h"
  #include "r8192U_dm.h"
 -//#include "r8192xU_phyreg.h"
  #include <linux/usb.h>
  #include <linux/slab.h>
  #include <linux/proc_fs.h>
  
  #include "dot11d.h"
  //set here to open your trace code. //WB
 -u32 rt_global_debug_component = \
 -                      //      COMP_INIT       |
 -//                            COMP_DBG        |
 -                      //      COMP_EPROM      |
 -//                            COMP_PHY        |
 -                      //      COMP_RF         |
 -//                            COMP_FIRMWARE   |
 -//                            COMP_CH         |
 -                      //      COMP_POWER_TRACKING |
 -//                            COMP_RATE       |
 -                      //      COMP_TXAGC      |
 -              //              COMP_TRACE      |
 -                              COMP_DOWN       |
 -              //              COMP_RECV       |
 -              //              COMP_SWBW       |
 +u32 rt_global_debug_component = COMP_DOWN     |
                                COMP_SEC        |
 -      //                      COMP_RESET      |
 -              //              COMP_SEND       |
 -                      //      COMP_EVENTS     |
 -                              COMP_ERR ; //always open err flags on
 +                              COMP_ERR; //always open err flags on
  
  #define TOTAL_CAM_ENTRY 32
  #define CAM_CONTENT_COUNT 8
@@@ -135,22 -130,24 +135,22 @@@ MODULE_VERSION("V 1.1")
  MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
  MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
  
 -static charifname = "wlan%d";
 +static char *ifname = "wlan%d";
  static int hwwep = 1;  //default use hw. set 0 to use software security
  static int channels = 0x3fff;
  
  
  
 -module_param(ifname, charp, S_IRUGO|S_IWUSR );
 -//module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
 -module_param(hwwep,int, S_IRUGO|S_IWUSR);
 -module_param(channels,int, S_IRUGO|S_IWUSR);
 +module_param(ifname, charp, S_IRUGO|S_IWUSR);
 +module_param(hwwep, int, S_IRUGO|S_IWUSR);
 +module_param(channels, int, S_IRUGO|S_IWUSR);
  
 -MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default");
 -//MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
 -MODULE_PARM_DESC(hwwep," Try to use hardware security support. ");
 -MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
 +MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
 +MODULE_PARM_DESC(hwwep, " Try to use hardware security support. ");
 +MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");
  
  static int rtl8192_usb_probe(struct usb_interface *intf,
 -                       const struct usb_device_id *id);
 +                           const struct usb_device_id *id);
  static void rtl8192_usb_disconnect(struct usb_interface *intf);
  
  
@@@ -172,7 -169,7 +172,7 @@@ static struct usb_driver rtl8192_usb_dr
  typedef struct _CHANNEL_LIST {
        u8      Channel[32];
        u8      Len;
 -}CHANNEL_LIST, *PCHANNEL_LIST;
 +} CHANNEL_LIST, *PCHANNEL_LIST;
  
  static CHANNEL_LIST ChannelPlan[] = {
        {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24},             //FCC
        {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14}                                 //For Global Domain. 1-11:active scan, 12-14 passive scan. //+YJ, 080626
  };
  
 -static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_privpriv)
 +static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
  {
 -      int i, max_chan=-1, min_chan=-1;
 -      struct ieee80211_device* ieee = priv->ieee80211;
 -      switch (channel_plan)
 -      {
 +      int i, max_chan = -1, min_chan = -1;
 +      struct ieee80211_device *ieee = priv->ieee80211;
 +      switch (channel_plan) {
        case COUNTRY_CODE_FCC:
        case COUNTRY_CODE_IC:
        case COUNTRY_CODE_ETSI:
        case COUNTRY_CODE_MKK1:
        case COUNTRY_CODE_ISRAEL:
        case COUNTRY_CODE_TELEC:
 -      case COUNTRY_CODE_MIC:  
 +      case COUNTRY_CODE_MIC:
                Dot11d_Init(ieee);
                ieee->bGlobalDomain = false;
                //actually 8225 & 8256 rf chips only support B,G,24N mode
                if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) {
                        min_chan = 1;
                        max_chan = 14;
 -              }
 -              else {
 -                      RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__);
 +              } else {
 +                      RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __func__);
                }
                if (ChannelPlan[channel_plan].Len != 0) {
                        // Clear old channel map
                        memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
                        // Set new channel map
 -                      for (i=0;i<ChannelPlan[channel_plan].Len;i++) {
 +                      for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
                                if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
                                        break;
                                GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
                Dot11d_Reset(ieee);
                ieee->bGlobalDomain = true;
                break;
 -      
 +
        default:
                break;
        }
  }
  
  
 -#define               rx_hal_is_cck_rate(_pdrvinfo)\
 -                      (_pdrvinfo->RxRate == DESC90_RATE1M ||\
 -                      _pdrvinfo->RxRate == DESC90_RATE2M ||\
 -                      _pdrvinfo->RxRate == DESC90_RATE5_5M ||\
 -                      _pdrvinfo->RxRate == DESC90_RATE11M) &&\
 -                      !_pdrvinfo->RxHT\
  
  
  void CamResetAllEntry(struct net_device *dev)
        //2004/02/11  In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA associate to AP.
        // However, ResetKey is called on OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest
        // In this condition, Cam can not be reset because upper layer will not set this static key again.
 -      //if(Adapter->EncAlgorithm == WEP_Encryption)
 -      //      return;
 -//debug
 -      //DbgPrint("========================================\n");
 -      //DbgPrint("                            Call ResetAllEntry                                              \n");
 -      //DbgPrint("========================================\n\n");
        ulcommand |= BIT31|BIT30;
        write_nic_dword(dev, RWCAM, ulcommand);
  
  void write_cam(struct net_device *dev, u8 addr, u32 data)
  {
        write_nic_dword(dev, WCAMI, data);
 -      write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff) );
 +      write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff));
  }
  
  u32 read_cam(struct net_device *dev, u8 addr)
  {
 -      write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff) );
 -      return read_nic_dword(dev, 0xa8);
 +      u32 data;
 +
 +      write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff));
 +      read_nic_dword(dev, 0xa8, &data);
 +      return data;
  }
  
  void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 -                             RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 -                             indx|0xfe00, 0, &data, 1, HZ / 2);
 +                               RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 +                               indx|0xfe00, 0, &data, 1, HZ / 2);
  
        if (status < 0)
 -      {
 -              printk("write_nic_byte_E TimeOut! status:%d\n", status);
 -      }
 +              netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n", status);
  }
  
 -u8 read_nic_byte_E(struct net_device *dev, int indx)
 +int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
  {
        int status;
 -      u8 data;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
 -                             RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 -                             indx|0xfe00, 0, &data, 1, HZ / 2);
 +                               RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 +                               indx|0xfe00, 0, data, 1, HZ / 2);
  
 -      if (status < 0)
 -      {
 -              printk("read_nic_byte_E TimeOut! status:%d\n", status);
 +      if (status < 0) {
 +              netdev_err(dev, "%s failure status: %d\n", __func__, status);
 +              return status;
        }
  
 -      return data;
 +      return 0;
  }
  //as 92U has extend page from 4 to 16, so modify functions below.
  void write_nic_byte(struct net_device *dev, int indx, u8 data)
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 -                             RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 -                             (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
 +                               RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 +                               (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
  
        if (status < 0)
 -      {
 -              printk("write_nic_byte TimeOut! status:%d\n", status);
 -      }
 +              netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
  
  
  }
@@@ -324,11 -337,13 +324,11 @@@ void write_nic_word(struct net_device *
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 -                             RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 -                             (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 2, HZ / 2);
 +                               RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 +                               (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 2, HZ / 2);
  
        if (status < 0)
 -      {
 -              printk("write_nic_word TimeOut! status:%d\n", status);
 -      }
 +              netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
  
  }
  
@@@ -342,92 -357,98 +342,92 @@@ void write_nic_dword(struct net_device 
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 -                             RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 -                             (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 4, HZ / 2);
 +                               RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 +                               (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 4, HZ / 2);
  
  
        if (status < 0)
 -      {
 -              printk("write_nic_dword TimeOut! status:%d\n", status);
 -      }
 +              netdev_err(dev, "write_nic_dword TimeOut! status: %d\n", status);
  
  }
  
  
  
 -u8 read_nic_byte(struct net_device *dev, int indx)
 +int read_nic_byte(struct net_device *dev, int indx, u8 *data)
  {
 -      u8 data;
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
 -                             RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 -                             (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
 +                               RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 +                               (indx&0xff)|0xff00, (indx>>8)&0x0f, data, 1, HZ / 2);
  
 -      if (status < 0)
 -      {
 -              printk("read_nic_byte TimeOut! status:%d\n", status);
 +      if (status < 0) {
 +              netdev_err(dev, "%s failure status: %d\n", __func__, status);
 +              return status;
        }
  
 -      return data;
 +      return 0;
  }
  
  
  
 -u16 read_nic_word(struct net_device *dev, int indx)
 +int read_nic_word(struct net_device *dev, int indx, u16 *data)
  {
 -      u16 data;
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
 -                                     RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 -                                     (indx&0xff)|0xff00, (indx>>8)&0x0f,
 -                                                      &data, 2, HZ / 2);
 +                               RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 +                               (indx&0xff)|0xff00, (indx>>8)&0x0f,
 +                               data, 2, HZ / 2);
  
 -      if (status < 0)
 -              printk("read_nic_word TimeOut! status:%d\n", status);
 +      if (status < 0) {
 +              netdev_err(dev, "%s failure status: %d\n", __func__, status);
 +              return status;
 +      }
  
 -      return data;
 +      return 0;
  }
  
 -u16 read_nic_word_E(struct net_device *dev, int indx)
 +int read_nic_word_E(struct net_device *dev, int indx, u16 *data)
  {
 -      u16 data;
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
 -                             RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 -                                     indx|0xfe00, 0, &data, 2, HZ / 2);
 +                               RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 +                               indx|0xfe00, 0, data, 2, HZ / 2);
  
 -      if (status < 0)
 -              printk("read_nic_word TimeOut! status:%d\n", status);
 +      if (status < 0) {
 +              netdev_err(dev, "%s failure status: %d\n", __func__, status);
 +              return status;
 +      }
  
 -      return data;
 +      return 0;
  }
  
 -u32 read_nic_dword(struct net_device *dev, int indx)
 +int read_nic_dword(struct net_device *dev, int indx, u32 *data)
  {
 -      u32 data;
        int status;
 -      /* int result; */
  
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
  
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
 -                                     RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 -                                      (indx&0xff)|0xff00, (indx>>8)&0x0f,
 -                                                      &data, 4, HZ / 2);
 -      /* if(0 != result) {
 -       *      printk(KERN_WARNING "read size of data = %d\, date = %d\n",
 -       *                                                       result, data);
 -       * }
 -       */
 +                               RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
 +                               (indx&0xff)|0xff00, (indx>>8)&0x0f,
 +                               data, 4, HZ / 2);
  
 -      if (status < 0)
 -              printk("read_nic_dword TimeOut! status:%d\n", status);
 +      if (status < 0) {
 +              netdev_err(dev, "%s failure status: %d\n", __func__, status);
 +              return status;
 +      }
  
 -      return data;
 +      return 0;
  }
  
  /* u8 read_phy_cck(struct net_device *dev, u8 adr); */
@@@ -441,7 -462,9 +441,7 @@@ inline void force_pci_posting(struct ne
  
  static struct net_device_stats *rtl8192_stats(struct net_device *dev);
  void rtl8192_commit(struct net_device *dev);
 -/* void rtl8192_restart(struct net_device *dev); */
  void rtl8192_restart(struct work_struct *work);
 -/* void rtl8192_rq_tx_ack(struct work_struct *work); */
  void watch_dog_timer_callback(unsigned long data);
  
  /****************************************************************************
@@@ -472,38 -495,40 +472,38 @@@ static int proc_get_stats_ap(struct seq
  static int proc_get_registers(struct seq_file *m, void *v)
  {
        struct net_device *dev = m->private;
 -      int i,n, max = 0xff;
 +      int i, n, max = 0xff;
 +      u8 byte_rd;
  
        seq_puts(m, "\n####################page 0##################\n ");
  
 -      for (n=0;n<=max;) {
 -              //printk( "\nD: %2x> ", n);
 -              seq_printf(m, "\nD:  %2x > ",n);
 -
 -              for (i=0;i<16 && n<=max;i++,n++)
 -                      seq_printf(m, "%2x ",read_nic_byte(dev,0x000|n));
 +      for (n = 0; n <= max;) {
 +              seq_printf(m, "\nD:  %2x > ", n);
  
 -              //      printk("%2x ",read_nic_byte(dev,n));
 +              for (i = 0; i < 16 && n <= max; i++, n++) {
 +                      read_nic_byte(dev, 0x000|n, &byte_rd);
 +                      seq_printf(m, "%2x ", byte_rd);
 +              }
        }
  
        seq_puts(m, "\n####################page 1##################\n ");
 -      for (n=0;n<=max;) {
 -              //printk( "\nD: %2x> ", n);
 -              seq_printf(m, "\nD:  %2x > ",n);
 -
 -              for (i=0;i<16 && n<=max;i++,n++)
 -                      seq_printf(m, "%2x ",read_nic_byte(dev,0x100|n));
 +      for (n = 0; n <= max;) {
 +              seq_printf(m, "\nD:  %2x > ", n);
  
 -              //      printk("%2x ",read_nic_byte(dev,n));
 +              for (i = 0; i < 16 && n <= max; i++, n++) {
 +                      read_nic_byte(dev, 0x100|n, &byte_rd);
 +                      seq_printf(m, "%2x ", byte_rd);
 +              }
        }
  
        seq_puts(m, "\n####################page 3##################\n ");
 -      for (n=0;n<=max;) {
 -              //printk( "\nD: %2x> ", n);
 -              seq_printf(m, "\nD:  %2x > ",n);
 -
 -              for(i=0;i<16 && n<=max;i++,n++)
 -                      seq_printf(m, "%2x ",read_nic_byte(dev,0x300|n));
 +      for (n = 0; n <= max;) {
 +              seq_printf(m, "\nD:  %2x > ", n);
  
 -              //      printk("%2x ",read_nic_byte(dev,n));
 +              for (i = 0; i < 16 && n <= max; i++, n++) {
 +                      read_nic_byte(dev, 0x300|n, &byte_rd);
 +                      seq_printf(m, "%2x ", byte_rd);
 +              }
        }
  
        seq_putc(m, '\n');
@@@ -516,54 -541,64 +516,54 @@@ static int proc_get_stats_tx(struct seq
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  
        seq_printf(m,
 -              "TX VI priority ok int: %lu\n"
 -              "TX VI priority error int: %lu\n"
 -              "TX VO priority ok int: %lu\n"
 -              "TX VO priority error int: %lu\n"
 -              "TX BE priority ok int: %lu\n"
 -              "TX BE priority error int: %lu\n"
 -              "TX BK priority ok int: %lu\n"
 -              "TX BK priority error int: %lu\n"
 -              "TX MANAGE priority ok int: %lu\n"
 -              "TX MANAGE priority error int: %lu\n"
 -              "TX BEACON priority ok int: %lu\n"
 -              "TX BEACON priority error int: %lu\n"
 -//            "TX high priority ok int: %lu\n"
 -//            "TX high priority failed error int: %lu\n"
 -              "TX queue resume: %lu\n"
 -              "TX queue stopped?: %d\n"
 -              "TX fifo overflow: %lu\n"
 -//            "TX beacon: %lu\n"
 -              "TX VI queue: %d\n"
 -              "TX VO queue: %d\n"
 -              "TX BE queue: %d\n"
 -              "TX BK queue: %d\n"
 -//            "TX HW queue: %d\n"
 -              "TX VI dropped: %lu\n"
 -              "TX VO dropped: %lu\n"
 -              "TX BE dropped: %lu\n"
 -              "TX BK dropped: %lu\n"
 -              "TX total data packets %lu\n",
 -//            "TX beacon aborted: %lu\n",
 -              priv->stats.txviokint,
 -              priv->stats.txvierr,
 -              priv->stats.txvookint,
 -              priv->stats.txvoerr,
 -              priv->stats.txbeokint,
 -              priv->stats.txbeerr,
 -              priv->stats.txbkokint,
 -              priv->stats.txbkerr,
 -              priv->stats.txmanageokint,
 -              priv->stats.txmanageerr,
 -              priv->stats.txbeaconokint,
 -              priv->stats.txbeaconerr,
 -//            priv->stats.txhpokint,
 -//            priv->stats.txhperr,
 -              priv->stats.txresumed,
 -              netif_queue_stopped(dev),
 -              priv->stats.txoverflow,
 -//            priv->stats.txbeacon,
 -              atomic_read(&(priv->tx_pending[VI_PRIORITY])),
 -              atomic_read(&(priv->tx_pending[VO_PRIORITY])),
 -              atomic_read(&(priv->tx_pending[BE_PRIORITY])),
 -              atomic_read(&(priv->tx_pending[BK_PRIORITY])),
 -//            read_nic_byte(dev, TXFIFOCOUNT),
 -              priv->stats.txvidrop,
 -              priv->stats.txvodrop,
 -              priv->stats.txbedrop,
 -              priv->stats.txbkdrop,
 -              priv->stats.txdatapkt
 -//            priv->stats.txbeaconerr
 +                 "TX VI priority ok int: %lu\n"
 +                 "TX VI priority error int: %lu\n"
 +                 "TX VO priority ok int: %lu\n"
 +                 "TX VO priority error int: %lu\n"
 +                 "TX BE priority ok int: %lu\n"
 +                 "TX BE priority error int: %lu\n"
 +                 "TX BK priority ok int: %lu\n"
 +                 "TX BK priority error int: %lu\n"
 +                 "TX MANAGE priority ok int: %lu\n"
 +                 "TX MANAGE priority error int: %lu\n"
 +                 "TX BEACON priority ok int: %lu\n"
 +                 "TX BEACON priority error int: %lu\n"
 +                 "TX queue resume: %lu\n"
 +                 "TX queue stopped?: %d\n"
 +                 "TX fifo overflow: %lu\n"
 +                 "TX VI queue: %d\n"
 +                 "TX VO queue: %d\n"
 +                 "TX BE queue: %d\n"
 +                 "TX BK queue: %d\n"
 +                 "TX VI dropped: %lu\n"
 +                 "TX VO dropped: %lu\n"
 +                 "TX BE dropped: %lu\n"
 +                 "TX BK dropped: %lu\n"
 +                 "TX total data packets %lu\n",
 +                 priv->stats.txviokint,
 +                 priv->stats.txvierr,
 +                 priv->stats.txvookint,
 +                 priv->stats.txvoerr,
 +                 priv->stats.txbeokint,
 +                 priv->stats.txbeerr,
 +                 priv->stats.txbkokint,
 +                 priv->stats.txbkerr,
 +                 priv->stats.txmanageokint,
 +                 priv->stats.txmanageerr,
 +                 priv->stats.txbeaconokint,
 +                 priv->stats.txbeaconerr,
 +                 priv->stats.txresumed,
 +                 netif_queue_stopped(dev),
 +                 priv->stats.txoverflow,
 +                 atomic_read(&(priv->tx_pending[VI_PRIORITY])),
 +                 atomic_read(&(priv->tx_pending[VO_PRIORITY])),
 +                 atomic_read(&(priv->tx_pending[BE_PRIORITY])),
 +                 atomic_read(&(priv->tx_pending[BK_PRIORITY])),
 +                 priv->stats.txvidrop,
 +                 priv->stats.txvodrop,
 +                 priv->stats.txbedrop,
 +                 priv->stats.txbkdrop,
 +                 priv->stats.txdatapkt
                );
  
        return 0;
@@@ -575,12 -610,12 +575,12 @@@ static int proc_get_stats_rx(struct seq
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  
        seq_printf(m,
 -              "RX packets: %lu\n"
 -              "RX urb status error: %lu\n"
 -              "RX invalid urb error: %lu\n",
 -              priv->stats.rxoktotal,
 -              priv->stats.rxstaterr,
 -              priv->stats.rxurberr);
 +                 "RX packets: %lu\n"
 +                 "RX urb status error: %lu\n"
 +                 "RX invalid urb error: %lu\n",
 +                 priv->stats.rxoktotal,
 +                 priv->stats.rxstaterr,
 +                 priv->stats.rxurberr);
  
        return 0;
  }
@@@ -665,7 -700,27 +665,7 @@@ void rtl8192_proc_remove_one(struct net
     -----------------------------MISC STUFF-------------------------
  *****************************************************************************/
  
 -/* this is only for debugging */
 -void print_buffer(u32 *buffer, int len)
 -{
 -      int i;
 -      u8 *buf =(u8*)buffer;
 -
 -      printk("ASCII BUFFER DUMP (len: %x):\n",len);
 -
 -      for(i=0;i<len;i++)
 -              printk("%c",buf[i]);
 -
 -      printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
 -
 -      for(i=0;i<len;i++)
 -              printk("%x",buf[i]);
 -
 -      printk("\n");
 -}
 -
 -//short check_nic_enough_desc(struct net_device *dev, priority_t priority)
 -short check_nic_enough_desc(struct net_device *dev,int queue_index)
 +short check_nic_enough_desc(struct net_device *dev, int queue_index)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        int used = atomic_read(&priv->tx_pending[queue_index]);
  void tx_timeout(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      //rtl8192_commit(dev);
  
        schedule_work(&priv->reset_wq);
 -      //DMESG("TXTIMEOUT");
  }
  
  
  void dump_eprom(struct net_device *dev)
  {
        int i;
 -      for(i=0; i<63; i++)
 -              RT_TRACE(COMP_EPROM, "EEPROM addr %x : %x", i, eprom_read(dev,i));
 +      for (i = 0; i < 63; i++)
 +              RT_TRACE(COMP_EPROM, "EEPROM addr %x : %x", i, eprom_read(dev, i));
  }
  
 -/* this is only for debug */
 -void rtl8192_dump_reg(struct net_device *dev)
 -{
 -      int i;
 -      int n;
 -      int max=0x1ff;
 -
 -      RT_TRACE(COMP_PHY, "Dumping NIC register map");
 -
 -      for(n=0;n<=max;)
 -      {
 -              printk( "\nD: %2x> ", n);
 -              for(i=0;i<16 && n<=max;i++,n++)
 -                      printk("%2x ",read_nic_byte(dev,n));
 -      }
 -      printk("\n");
 -}
  
  /****************************************************************************
        ------------------------------HW STUFF---------------------------
  *****************************************************************************/
  
  
 -void rtl8192_set_mode(struct net_device *dev,int mode)
 +void rtl8192_set_mode(struct net_device *dev, int mode)
  {
        u8 ecmd;
 -      ecmd=read_nic_byte(dev, EPROM_CMD);
 -      ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
 -      ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
 -      ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
 -      ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
 +      read_nic_byte(dev, EPROM_CMD, &ecmd);
 +      ecmd = ecmd & ~EPROM_CMD_OPERATING_MODE_MASK;
 +      ecmd = ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
 +      ecmd = ecmd & ~EPROM_CS_BIT;
 +      ecmd = ecmd & ~EPROM_CK_BIT;
        write_nic_byte(dev, EPROM_CMD, ecmd);
  }
  
@@@ -712,15 -786,15 +712,15 @@@ void rtl8192_update_msr(struct net_devi
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8 msr;
  
 -      msr  = read_nic_byte(dev, MSR);
 -      msr &= ~ MSR_LINK_MASK;
 +      read_nic_byte(dev, MSR, &msr);
 +      msr &= ~MSR_LINK_MASK;
  
        /* do not change in link_state != WLAN_LINK_ASSOCIATED.
         * msr must be updated if the state is ASSOCIATING.
         * this is intentional and make sense for ad-hoc and
         * master (see the create BSS/IBSS func)
         */
 -      if (priv->ieee80211->state == IEEE80211_LINKED){
 +      if (priv->ieee80211->state == IEEE80211_LINKED) {
  
                if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
                        msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
                else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
                        msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
  
 -      }else
 +      } else {
                msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
 +      }
  
        write_nic_byte(dev, MSR, msr);
  }
  
 -void rtl8192_set_chan(struct net_device *dev,short ch)
 +void rtl8192_set_chan(struct net_device *dev, short ch)
  {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 -//    u32 tx;
 -      RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __FUNCTION__, ch);
 -      priv->chan=ch;
 +      RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
 +      priv->chan = ch;
  
        /* this hack should avoid frame TX during channel setting*/
  
 -
 -//    tx = read_nic_dword(dev,TX_CONF);
 -//    tx &= ~TX_LOOPBACK_MASK;
 -
  #ifndef LOOP_TEST
 -//    write_nic_dword(dev,TX_CONF, tx |( TX_LOOPBACK_MAC<<TX_LOOPBACK_SHIFT));
 -
        //need to implement rf set channel here WB
  
        if (priv->rf_set_chan)
 -      priv->rf_set_chan(dev,priv->chan);
 +              priv->rf_set_chan(dev, priv->chan);
        mdelay(10);
 -//    write_nic_dword(dev,TX_CONF,tx | (TX_LOOPBACK_NONE<<TX_LOOPBACK_SHIFT));
  #endif
  }
  
  static void rtl8192_rx_isr(struct urb *urb);
 -//static void rtl8192_rx_isr(struct urb *rx_urb);
  
  u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
  {
        else
  #endif
                return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
 -                              + pstats->RxBufShift);
 +                      + pstats->RxBufShift);
  
  }
 -static int rtl8192_rx_initiate(struct net_device*dev)
 +static int rtl8192_rx_initiate(struct net_device *dev)
  {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct urb *entry;
                        kfree_skb(skb);
                        break;
                }
 -//            printk("nomal packet IN request!\n");
                usb_fill_bulk_urb(entry, priv->udev,
                                  usb_rcvbulkpipe(priv->udev, 3), skb_tail_pointer(skb),
                                  RX_URB_SIZE, rtl8192_rx_isr, skb);
  
        /* command packet rx procedure */
        while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB + 3) {
 -//            printk("command packet IN request!\n");
 -              skb = __dev_alloc_skb(RX_URB_SIZE ,GFP_KERNEL);
 +              skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
                if (!skb)
                        break;
                entry = usb_alloc_urb(0, GFP_KERNEL);
                info = (struct rtl8192_rx_info *) skb->cb;
                info->urb = entry;
                info->dev = dev;
 -                 info->out_pipe = 9; //denote rx cmd packet queue
 +              info->out_pipe = 9; //denote rx cmd packet queue
                skb_queue_tail(&priv->rx_queue, skb);
                usb_submit_urb(entry, GFP_KERNEL);
        }
@@@ -825,47 -909,64 +825,47 @@@ void rtl8192_set_rxconf(struct net_devi
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        u32 rxconf;
  
 -      rxconf=read_nic_dword(dev,RCR);
 -      rxconf = rxconf &MAC_FILTER_MASK;
 +      read_nic_dword(dev, RCR, &rxconf);
 +      rxconf = rxconf & ~MAC_FILTER_MASK;
        rxconf = rxconf | RCR_AMF;
        rxconf = rxconf | RCR_ADF;
        rxconf = rxconf | RCR_AB;
        rxconf = rxconf | RCR_AM;
 -      //rxconf = rxconf | RCR_ACF;
  
 -      if (dev->flags & IFF_PROMISC) {DMESG ("NIC in promisc mode");}
 +      if (dev->flags & IFF_PROMISC)
 +              DMESG("NIC in promisc mode");
  
 -      if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
 -         dev->flags & IFF_PROMISC){
 +      if (priv->ieee80211->iw_mode == IW_MODE_MONITOR ||
 +          dev->flags & IFF_PROMISC) {
                rxconf = rxconf | RCR_AAP;
 -      } /*else if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
 -              rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
 -              rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
 -      }*/else{
 +      } else {
                rxconf = rxconf | RCR_APM;
                rxconf = rxconf | RCR_CBSSID;
        }
  
  
 -      if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
 +      if (priv->ieee80211->iw_mode == IW_MODE_MONITOR) {
                rxconf = rxconf | RCR_AICV;
                rxconf = rxconf | RCR_APWRMGT;
        }
  
 -      ifpriv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
 +      if (priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
                rxconf = rxconf | RCR_ACRC32;
  
  
 -      rxconf = rxconf &RX_FIFO_THRESHOLD_MASK;
 +      rxconf = rxconf & ~RX_FIFO_THRESHOLD_MASK;
        rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
 -      rxconf = rxconf &MAX_RX_DMA_MASK;
 +      rxconf = rxconf & ~MAX_RX_DMA_MASK;
        rxconf = rxconf | ((u32)7<<RCR_MXDMA_OFFSET);
  
 -//    rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
        rxconf = rxconf | RCR_ONLYERLPKT;
  
 -//    rxconf = rxconf &~ RCR_CS_MASK;
 -//    rxconf = rxconf | (1<<RCR_CS_SHIFT);
 -
        write_nic_dword(dev, RCR, rxconf);
 -
 -      #ifdef DEBUG_RX
 -      DMESG("rxconf: %x %x",rxconf ,read_nic_dword(dev,RCR));
 -      #endif
  }
  //wait to be removed
  void rtl8192_rx_enable(struct net_device *dev)
  {
 -      //u8 cmd;
 -
 -      //struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 -
        rtl8192_rx_initiate(dev);
 -
 -//    rtl8192_set_rxconf(dev);
  }
  
  
@@@ -882,8 -983,9 +882,8 @@@ void rtl8192_rtx_disable(struct net_dev
        struct sk_buff *skb;
        struct rtl8192_rx_info *info;
  
 -      cmd=read_nic_byte(dev,CMDR);
 -      write_nic_byte(dev, CMDR, cmd &~ \
 -              (CR_TE|CR_RE));
 +      read_nic_byte(dev, CMDR, &cmd);
 +      write_nic_byte(dev, CMDR, cmd & ~(CR_TE|CR_RE));
        force_pci_posting(dev);
        mdelay(10);
  
                kfree_skb(skb);
        }
  
 -      if (skb_queue_len(&priv->skb_queue)) {
 -              printk(KERN_WARNING "skb_queue not empty\n");
 -      }
 +      if (skb_queue_len(&priv->skb_queue))
 +              netdev_warn(dev, "skb_queue not empty\n");
  
        skb_queue_purge(&priv->skb_queue);
        return;
@@@ -911,40 -1014,40 +911,40 @@@ int alloc_tx_beacon_desc_ring(struct ne
  
  inline u16 ieeerate2rtlrate(int rate)
  {
 -      switch(rate){
 +      switch (rate) {
        case 10:
 -      return 0;
 +              return 0;
        case 20:
 -      return 1;
 +              return 1;
        case 55:
 -      return 2;
 +              return 2;
        case 110:
 -      return 3;
 +              return 3;
        case 60:
 -      return 4;
 +              return 4;
        case 90:
 -      return 5;
 +              return 5;
        case 120:
 -      return 6;
 +              return 6;
        case 180:
 -      return 7;
 +              return 7;
        case 240:
 -      return 8;
 +              return 8;
        case 360:
 -      return 9;
 +              return 9;
        case 480:
 -      return 10;
 +              return 10;
        case 540:
 -      return 11;
 +              return 11;
        default:
 -      return 3;
 +              return 3;
  
        }
  }
 -static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
 +static u16 rtl_rate[] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
  inline u16 rtl8192_rate2rate(short rate)
  {
 -      if (rate >11) return 0;
 +      if (rate > 11) return 0;
        return rtl_rate[rate];
  }
  
@@@ -958,13 -1061,14 +958,13 @@@ static void rtl8192_rx_isr(struct urb *
        struct r8192_priv *priv = ieee80211_priv(dev);
        int out_pipe = info->out_pipe;
        int err;
 -      if(!priv->up)
 +      if (!priv->up)
                return;
        if (unlikely(urb->status)) {
                info->urb = NULL;
                priv->stats.rxstaterr++;
                priv->ieee80211->stats.rx_errors++;
                usb_free_urb(urb);
 -      //      printk("%s():rx status err\n",__FUNCTION__);
                return;
        }
        skb_unlink(skb, &priv->rx_queue);
        skb = dev_alloc_skb(RX_URB_SIZE);
        if (unlikely(!skb)) {
                usb_free_urb(urb);
 -              printk("%s():can,t alloc skb\n",__FUNCTION__);
 +              netdev_err(dev, "%s(): can't alloc skb\n", __func__);
                /* TODO check rx queue length and refill *somewhere* */
                return;
        }
  
        usb_fill_bulk_urb(urb, priv->udev,
 -                      usb_rcvbulkpipe(priv->udev, out_pipe), skb_tail_pointer(skb),
 -                      RX_URB_SIZE, rtl8192_rx_isr, skb);
 +                        usb_rcvbulkpipe(priv->udev, out_pipe), skb_tail_pointer(skb),
 +                        RX_URB_SIZE, rtl8192_rx_isr, skb);
  
        info = (struct rtl8192_rx_info *) skb->cb;
        info->urb = urb;
        urb->context = skb;
        skb_queue_tail(&priv->rx_queue, skb);
        err = usb_submit_urb(urb, GFP_ATOMIC);
 -      if(err && err != EPERM)
 -              printk("can not submit rxurb, err is %x,URB status is %x\n",err,urb->status);
 +      if (err && err != EPERM)
 +              netdev_err(dev, "can not submit rxurb, err is %x, URB status is %x\n", err, urb->status);
  }
  
 -u32
 -rtl819xusb_rx_command_packet(
 -      struct net_device *dev,
 -      struct ieee80211_rx_stats *pstats
 -      )
 +u32 rtl819xusb_rx_command_packet(struct net_device *dev,
 +                               struct ieee80211_rx_stats *pstats)
  {
        u32     status;
  
 -      //RT_TRACE(COMP_RECV, DBG_TRACE, ("---> RxCommandPacketHandle819xUsb()\n"));
 -
        status = cmpk_message_handle_rx(dev, pstats);
        if (status)
 -      {
                DMESG("rxcommandpackethandle819xusb: It is a command packet\n");
 -      }
 -      else
 -      {
 -              //RT_TRACE(COMP_RECV, DBG_TRACE, ("RxCommandPacketHandle819xUsb: It is not a command packet\n"));
 -      }
  
 -      //RT_TRACE(COMP_RECV, DBG_TRACE, ("<--- RxCommandPacketHandle819xUsb()\n"));
        return status;
  }
  
@@@ -1034,17 -1150,24 +1034,17 @@@ void rtl8192_hard_data_xmit(struct sk_b
        u8 queue_index = tcb_desc->queue_index;
  
        /* shall not be referred by command packet */
 -      assert(queue_index != TXCMD_QUEUE);
 +      RTL8192U_ASSERT(queue_index != TXCMD_QUEUE);
  
 -      spin_lock_irqsave(&priv->tx_lock,flags);
 +      spin_lock_irqsave(&priv->tx_lock, flags);
  
 -      memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
 -//    tcb_desc->RATRIndex = 7;
 -//    tcb_desc->bTxDisableRateFallBack = 1;
 -//    tcb_desc->bTxUseDriverAssingedRate = 1;
 +      memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
        tcb_desc->bTxEnableFwCalcDur = 1;
        skb_push(skb, priv->ieee80211->tx_headroom);
        ret = rtl8192_tx(dev, skb);
  
 -      //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
 -      //priv->ieee80211->stats.tx_packets++;
 +      spin_unlock_irqrestore(&priv->tx_lock, flags);
  
 -      spin_unlock_irqrestore(&priv->tx_lock,flags);
 -
 -//    return ret;
        return;
  }
  
   * If the ring is full packet are dropped (for data frame the queue
   * is stopped before this can happen).
   */
 -int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
 +int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        int ret;
        u8 queue_index = tcb_desc->queue_index;
  
  
 -      spin_lock_irqsave(&priv->tx_lock,flags);
 +      spin_lock_irqsave(&priv->tx_lock, flags);
  
 -      memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
 -      if(queue_index == TXCMD_QUEUE) {
 +      memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
 +      if (queue_index == TXCMD_QUEUE) {
                skb_push(skb, USB_HWDESC_HEADER_LEN);
                rtl819xU_tx_cmd(dev, skb);
                ret = 1;
 -              spin_unlock_irqrestore(&priv->tx_lock,flags);
 +              spin_unlock_irqrestore(&priv->tx_lock, flags);
                return ret;
        } else {
                skb_push(skb, priv->ieee80211->tx_headroom);
                ret = rtl8192_tx(dev, skb);
        }
  
 -      spin_unlock_irqrestore(&priv->tx_lock,flags);
 +      spin_unlock_irqrestore(&priv->tx_lock, flags);
  
        return ret;
  }
@@@ -1088,7 -1211,7 +1088,7 @@@ void rtl8192_try_wake_queue(struct net_
  u16 DrvAggr_PaddingAdd(struct net_device *dev, struct sk_buff *skb)
  {
        u16     PaddingNum =  256 - ((skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES) % 256);
 -      return  (PaddingNum&0xff);
 +      return  PaddingNum & 0xff;
  }
  
  u8 MRateToHwRate8190Pci(u8 rate);
@@@ -1116,7 -1239,7 +1116,7 @@@ struct sk_buff *DrvAggr_Aggregation(str
        /* Get the total aggregation length including the padding space and
         * sub frame header.
         */
 -      for(i = 1; i < pSendList->nr_drv_agg_frames; i++) {
 +      for (i = 1; i < pSendList->nr_drv_agg_frames; i++) {
                TotalLength += DrvAggr_PaddingAdd(dev, skb);
                skb = pSendList->tx_agg_frames[i];
                TotalLength += (skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
        memset(agg_skb->data, 0, agg_skb->len);
        skb_reserve(agg_skb, ieee->tx_headroom);
  
 -//    RT_DEBUG_DATA(COMP_SEND, skb->cb, sizeof(skb->cb));
        /* reserve info for first subframe Tx descriptor to be set in the tx function */
        skb = pSendList->tx_agg_frames[0];
        tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
        tcb_desc->drv_agg_enable = 1;
        tcb_desc->pkt_size = skb->len;
        tcb_desc->DrvAggrNum = pSendList->nr_drv_agg_frames;
 -      printk("DrvAggNum = %d\n", tcb_desc->DrvAggrNum);
 -//    RT_DEBUG_DATA(COMP_SEND, skb->cb, sizeof(skb->cb));
 -//    printk("========>skb->data ======> \n");
 -//    RT_DEBUG_DATA(COMP_SEND, skb->data, skb->len);
 +      netdev_dbg(dev, "DrvAggNum = %d\n", tcb_desc->DrvAggrNum);
        memcpy(agg_skb->cb, skb->cb, sizeof(skb->cb));
 -      memcpy(skb_put(agg_skb,skb->len),skb->data,skb->len);
 +      memcpy(skb_put(agg_skb, skb->len), skb->data, skb->len);
  
 -      for(i = 1; i < pSendList->nr_drv_agg_frames; i++) {
 +      for (i = 1; i < pSendList->nr_drv_agg_frames; i++) {
                /* push the next sub frame to be 256 byte aline */
 -              skb_put(agg_skb,DrvAggr_PaddingAdd(dev,skb));
 +              skb_put(agg_skb, DrvAggr_PaddingAdd(dev, skb));
  
                /* Subframe drv Tx descriptor and firmware info setting */
                skb = pSendList->tx_agg_frames[i];
                tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
-               tx_agg_desc = (tx_desc_819x_usb_aggr_subframe *)agg_skb->tail;
-               tx_fwinfo = (tx_fwinfo_819x_usb *)(agg_skb->tail + sizeof(tx_desc_819x_usb_aggr_subframe));
+               tx_agg_desc = (tx_desc_819x_usb_aggr_subframe *)skb_tail_pointer(agg_skb);
+               tx_fwinfo = (tx_fwinfo_819x_usb *)(skb_tail_pointer(agg_skb) + sizeof(tx_desc_819x_usb_aggr_subframe));
  
 -              memset(tx_fwinfo,0,sizeof(tx_fwinfo_819x_usb));
 +              memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
                /* DWORD 0 */
 -              tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80)?1:0;
 +              tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
                tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
                tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
                tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
 -              if(tcb_desc->bAMPDUEnable) {//AMPDU enabled
 +              if (tcb_desc->bAMPDUEnable) {//AMPDU enabled
                        tx_fwinfo->AllowAggregation = 1;
                        /* DWORD 1 */
                        tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
                }
  
                /* Protection mode related */
 -              tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable)?1:0;
 -              tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable)?1:0;
 -              tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC)?1:0;
 -              tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80)?1:0;
 +              tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
 +              tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
 +              tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
 +              tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
                tx_fwinfo->RtsRate =  MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
 -              tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT==0)?(tcb_desc->RTSSC):0;
 -              tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT==1)?((tcb_desc->bRTSBW)?1:0):0;
 -              tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):\
 -                                    (tcb_desc->bRTSUseShortGI?1:0);
 +              tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
 +              tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
 +              tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
 +                                    (tcb_desc->bRTSUseShortGI ? 1 : 0);
  
                /* Set Bandwidth and sub-channel settings. */
 -              if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
 -              {
 -                      if(tcb_desc->bPacketBW) {
 +              if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
 +                      if (tcb_desc->bPacketBW) {
                                tx_fwinfo->TxBandwidth = 1;
                                tx_fwinfo->TxSubCarrier = 0;    //By SD3's Jerry suggestion, use duplicated mode
                        } else {
                /* Fill Tx descriptor */
                memset(tx_agg_desc, 0, sizeof(tx_desc_819x_usb_aggr_subframe));
                /* DWORD 0 */
 -              //tx_agg_desc->LINIP = 0;
 -              //tx_agg_desc->CmdInit = 1;
                tx_agg_desc->Offset =  sizeof(tx_fwinfo_819x_usb) + 8;
                /* already raw data, need not to subtract header length */
                tx_agg_desc->PktSize = skb->len & 0xffff;
  
                /*DWORD 1*/
 -              tx_agg_desc->SecCAMID= 0;
 +              tx_agg_desc->SecCAMID = 0;
                tx_agg_desc->RATid = tcb_desc->RATRIndex;
 -              {
 -                      //MPDUOverhead = 0;
 -                      tx_agg_desc->NoEnc = 1;
 -              }
 +              tx_agg_desc->NoEnc = 1;
                tx_agg_desc->SecType = 0x0;
  
                if (tcb_desc->bHwSec) {
 -                      switch (priv->ieee80211->pairwise_key_type)
 -                      {
 -                              case KEY_TYPE_WEP40:
 -                              case KEY_TYPE_WEP104:
 -                                      tx_agg_desc->SecType = 0x1;
 -                                      tx_agg_desc->NoEnc = 0;
 -                                      break;
 -                              case KEY_TYPE_TKIP:
 -                                      tx_agg_desc->SecType = 0x2;
 -                                      tx_agg_desc->NoEnc = 0;
 -                                      break;
 -                              case KEY_TYPE_CCMP:
 -                                      tx_agg_desc->SecType = 0x3;
 -                                      tx_agg_desc->NoEnc = 0;
 -                                      break;
 -                              case KEY_TYPE_NA:
 -                                      tx_agg_desc->SecType = 0x0;
 -                                      tx_agg_desc->NoEnc = 1;
 -                                      break;
 +                      switch (priv->ieee80211->pairwise_key_type) {
 +                      case KEY_TYPE_WEP40:
 +                      case KEY_TYPE_WEP104:
 +                              tx_agg_desc->SecType = 0x1;
 +                              tx_agg_desc->NoEnc = 0;
 +                              break;
 +                      case KEY_TYPE_TKIP:
 +                              tx_agg_desc->SecType = 0x2;
 +                              tx_agg_desc->NoEnc = 0;
 +                              break;
 +                      case KEY_TYPE_CCMP:
 +                              tx_agg_desc->SecType = 0x3;
 +                              tx_agg_desc->NoEnc = 0;
 +                              break;
 +                      case KEY_TYPE_NA:
 +                              tx_agg_desc->SecType = 0x0;
 +                              tx_agg_desc->NoEnc = 1;
 +                              break;
                        }
                }
  
  
                //DWORD 2
                /* According windows driver, it seems that there no need to fill this field */
 -              //tx_agg_desc->TxBufferSize= (u32)(skb->len - USB_HWDESC_HEADER_LEN);
  
                /* to fill next packet */
 -              skb_put(agg_skb,TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
 -              memcpy(skb_put(agg_skb,skb->len),skb->data,skb->len);
 +              skb_put(agg_skb, TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
 +              memcpy(skb_put(agg_skb, skb->len), skb->data, skb->len);
        }
  
 -      for(i = 0; i < pSendList->nr_drv_agg_frames; i++) {
 +      for (i = 0; i < pSendList->nr_drv_agg_frames; i++)
                dev_kfree_skb_any(pSendList->tx_agg_frames[i]);
 -      }
  
        return agg_skb;
  }
        If no proper TCB is found to do aggregation, SendList will only contain the input TCB.
  */
  u8 DrvAggr_GetAggregatibleList(struct net_device *dev, struct sk_buff *skb,
 -              struct ieee80211_drv_agg_txb *pSendList)
 +                             struct ieee80211_drv_agg_txb *pSendList)
  {
        struct ieee80211_device *ieee = netdev_priv(dev);
        PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
  
        do {
                pSendList->tx_agg_frames[pSendList->nr_drv_agg_frames++] = skb;
 -              if(pSendList->nr_drv_agg_frames >= nMaxAggrNum) {
 +              if (pSendList->nr_drv_agg_frames >= nMaxAggrNum)
                        break;
 -              }
  
 -      } while((skb = skb_dequeue(&ieee->skb_drv_aggQ[QueueID])));
 +      } while ((skb = skb_dequeue(&ieee->skb_drv_aggQ[QueueID])));
  
        RT_TRACE(COMP_AMSDU, "DrvAggr_GetAggregatibleList, nAggrTcbNum = %d \n", pSendList->nr_drv_agg_frames);
        return pSendList->nr_drv_agg_frames;
  
  static void rtl8192_tx_isr(struct urb *tx_urb)
  {
 -      struct sk_buff *skb = (struct sk_buff*)tx_urb->context;
 +      struct sk_buff *skb = (struct sk_buff *)tx_urb->context;
        struct net_device *dev = NULL;
        struct r8192_priv *priv = NULL;
        cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
        u8  queue_index = tcb_desc->queue_index;
 -//    bool bToSend0Byte;
 -//    u16 BufLen = skb->len;
  
 -      memcpy(&dev,(struct net_device*)(skb->cb),sizeof(struct net_device*));
 +      memcpy(&dev, (struct net_device *)(skb->cb), sizeof(struct net_device *));
        priv = ieee80211_priv(dev);
  
 -      if(tcb_desc->queue_index != TXCMD_QUEUE) {
 -              if(tx_urb->status == 0) {
 +      if (tcb_desc->queue_index != TXCMD_QUEUE) {
 +              if (tx_urb->status == 0) {
                        dev->trans_start = jiffies;
 -                      // Act as station mode, destination shall be unicast address.
 -                      //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
 -                      //priv->ieee80211->stats.tx_packets++;
                        priv->stats.txoktotal++;
                        priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
                        priv->stats.txbytesunicast += (skb->len - priv->ieee80211->tx_headroom);
                } else {
                        priv->ieee80211->stats.tx_errors++;
 -                      //priv->stats.txmanageerr++;
                        /* TODO */
                }
        }
  
        /* free skb and tx_urb */
 -      if(skb != NULL) {
 +      if (skb != NULL) {
                dev_kfree_skb_any(skb);
                usb_free_urb(tx_urb);
                atomic_dec(&priv->tx_pending[queue_index]);
        }
  
 -      {
 -              //
 -              // Handle HW Beacon:
 -              // We had transfer our beacon frame to host controller at this moment.
 -              //
 -              //
 -              // Caution:
 -              // Handling the wait queue of command packets.
 -              // For Tx command packets, we must not do TCB fragment because it is not handled right now.
 -              // We must cut the packets to match the size of TX_CMD_PKT before we send it.
 -              //
 +      //
 +      // Handle HW Beacon:
 +      // We had transfer our beacon frame to host controller at this moment.
 +      //
 +      //
 +      // Caution:
 +      // Handling the wait queue of command packets.
 +      // For Tx command packets, we must not do TCB fragment because it is not handled right now.
 +      // We must cut the packets to match the size of TX_CMD_PKT before we send it.
 +      //
  
 -              /* Handle MPDU in wait queue. */
 -              if(queue_index != BEACON_QUEUE) {
 -                      /* Don't send data frame during scanning.*/
 -                      if((skb_queue_len(&priv->ieee80211->skb_waitQ[queue_index]) != 0)&&\
 -                                      (!(priv->ieee80211->queue_stop))) {
 -                              if(NULL != (skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]))))
 -                                      priv->ieee80211->softmac_hard_start_xmit(skb, dev);
 +      /* Handle MPDU in wait queue. */
 +      if (queue_index != BEACON_QUEUE) {
 +              /* Don't send data frame during scanning.*/
 +              if ((skb_queue_len(&priv->ieee80211->skb_waitQ[queue_index]) != 0) &&
 +                  (!(priv->ieee80211->queue_stop))) {
 +                      if (NULL != (skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]))))
 +                              priv->ieee80211->softmac_hard_start_xmit(skb, dev);
  
 -                              return; //modified by david to avoid further processing AMSDU
 -                      }
 +                      return; //modified by david to avoid further processing AMSDU
 +              }
  #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
 -                      else if ((skb_queue_len(&priv->ieee80211->skb_drv_aggQ[queue_index])!= 0)&&\
 -                              (!(priv->ieee80211->queue_stop))) {
 -                              // Tx Driver Aggregation process
 -                              /* The driver will aggregation the packets according to the following stats
 -                               * 1. check whether there's tx irq available, for it's a completion return
 -                               *    function, it should contain enough tx irq;
 -                               * 2. check packet type;
 -                               * 3. initialize sendlist, check whether the to-be send packet no greater than 1
 -                               * 4. aggregates the packets, and fill firmware info and tx desc into it, etc.
 -                               * 5. check whether the packet could be sent, otherwise just insert into wait head
 -                               * */
 -                              skb = skb_dequeue(&priv->ieee80211->skb_drv_aggQ[queue_index]);
 -                              if(!check_nic_enough_desc(dev, queue_index)) {
 -                                      skb_queue_head(&(priv->ieee80211->skb_drv_aggQ[queue_index]), skb);
 -                                      return;
 -                              }
 +              else if ((skb_queue_len(&priv->ieee80211->skb_drv_aggQ[queue_index]) != 0) &&
 +                       (!(priv->ieee80211->queue_stop))) {
 +                      // Tx Driver Aggregation process
 +                      /* The driver will aggregation the packets according to the following stats
 +                       * 1. check whether there's tx irq available, for it's a completion return
 +                       *    function, it should contain enough tx irq;
 +                       * 2. check packet type;
 +                       * 3. initialize sendlist, check whether the to-be send packet no greater than 1
 +                       * 4. aggregates the packets, and fill firmware info and tx desc into it, etc.
 +                       * 5. check whether the packet could be sent, otherwise just insert into wait head
 +                       * */
 +                      skb = skb_dequeue(&priv->ieee80211->skb_drv_aggQ[queue_index]);
 +                      if (!check_nic_enough_desc(dev, queue_index)) {
 +                              skb_queue_head(&(priv->ieee80211->skb_drv_aggQ[queue_index]), skb);
 +                              return;
 +                      }
 +
 +                      /*TODO*/
 +                      {
 +                              struct ieee80211_drv_agg_txb SendList;
 +
 +                              memset(&SendList, 0, sizeof(struct ieee80211_drv_agg_txb));
 +                              if (DrvAggr_GetAggregatibleList(dev, skb, &SendList) > 1) {
 +                                      skb = DrvAggr_Aggregation(dev, &SendList);
  
 -                              {
 -                                      /*TODO*/
 -                                      /*
 -                                      u8* pHeader = skb->data;
 -
 -                                      if(IsMgntQosData(pHeader) ||
 -                                          IsMgntQData_Ack(pHeader) ||
 -                                          IsMgntQData_Poll(pHeader) ||
 -                                          IsMgntQData_Poll_Ack(pHeader)
 -                                        )
 -                                      */
 -                                      {
 -                                              struct ieee80211_drv_agg_txb SendList;
 -
 -                                              memset(&SendList, 0, sizeof(struct ieee80211_drv_agg_txb));
 -                                              if(DrvAggr_GetAggregatibleList(dev, skb, &SendList) > 1) {
 -                                                      skb = DrvAggr_Aggregation(dev, &SendList);
 -
 -                                              }
 -                                      }
 -                                      priv->ieee80211->softmac_hard_start_xmit(skb, dev);
                                }
                        }
 -#endif
 +                      priv->ieee80211->softmac_hard_start_xmit(skb, dev);
                }
 +#endif
        }
  
  }
@@@ -1363,67 -1519,72 +1363,67 @@@ void rtl8192_beacon_stop(struct net_dev
        u8 msr, msrm, msr2;
        struct r8192_priv *priv = ieee80211_priv(dev);
  
 -      msr  = read_nic_byte(dev, MSR);
 +      read_nic_byte(dev, MSR, &msr);
        msrm = msr & MSR_LINK_MASK;
        msr2 = msr & ~MSR_LINK_MASK;
  
 -      if(NIC_8192U == priv->card_8192) {
 +      if (NIC_8192U == priv->card_8192)
                usb_kill_urb(priv->rx_urb[MAX_RX_URB]);
 -      }
        if ((msrm == (MSR_LINK_ADHOC<<MSR_LINK_SHIFT) ||
 -              (msrm == (MSR_LINK_MASTER<<MSR_LINK_SHIFT)))){
 +          (msrm == (MSR_LINK_MASTER<<MSR_LINK_SHIFT)))) {
                write_nic_byte(dev, MSR, msr2 | MSR_LINK_NONE);
                write_nic_byte(dev, MSR, msr);
        }
  }
  
 -void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
 -{
 -       struct r8192_priv *priv = ieee80211_priv(dev);
 -       struct ieee80211_network *net;
 -       u8 i=0, basic_rate = 0;
 -       net = & priv->ieee80211->current_network;
 -
 -       for (i=0; i<net->rates_len; i++)
 -       {
 -               basic_rate = net->rates[i]&0x7f;
 -               switch(basic_rate)
 -               {
 -                       case MGN_1M:   *rate_config |= RRSR_1M;        break;
 -                       case MGN_2M:   *rate_config |= RRSR_2M;        break;
 -                       case MGN_5_5M: *rate_config |= RRSR_5_5M;      break;
 -                       case MGN_11M:  *rate_config |= RRSR_11M;       break;
 -                       case MGN_6M:   *rate_config |= RRSR_6M;        break;
 -                       case MGN_9M:   *rate_config |= RRSR_9M;        break;
 -                       case MGN_12M:  *rate_config |= RRSR_12M;       break;
 -                       case MGN_18M:  *rate_config |= RRSR_18M;       break;
 -                       case MGN_24M:  *rate_config |= RRSR_24M;       break;
 -                       case MGN_36M:  *rate_config |= RRSR_36M;       break;
 -                       case MGN_48M:  *rate_config |= RRSR_48M;       break;
 -                       case MGN_54M:  *rate_config |= RRSR_54M;       break;
 -               }
 -       }
 -       for (i=0; i<net->rates_ex_len; i++)
 -       {
 -               basic_rate = net->rates_ex[i]&0x7f;
 -               switch(basic_rate)
 -               {
 -                       case MGN_1M:   *rate_config |= RRSR_1M;        break;
 -                       case MGN_2M:   *rate_config |= RRSR_2M;        break;
 -                       case MGN_5_5M: *rate_config |= RRSR_5_5M;      break;
 -                       case MGN_11M:  *rate_config |= RRSR_11M;       break;
 -                       case MGN_6M:   *rate_config |= RRSR_6M;        break;
 -                       case MGN_9M:   *rate_config |= RRSR_9M;        break;
 -                       case MGN_12M:  *rate_config |= RRSR_12M;       break;
 -                       case MGN_18M:  *rate_config |= RRSR_18M;       break;
 -                       case MGN_24M:  *rate_config |= RRSR_24M;       break;
 -                       case MGN_36M:  *rate_config |= RRSR_36M;       break;
 -                       case MGN_48M:  *rate_config |= RRSR_48M;       break;
 -                       case MGN_54M:  *rate_config |= RRSR_54M;       break;
 -               }
 -       }
 +void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
 +{
 +      struct r8192_priv *priv = ieee80211_priv(dev);
 +      struct ieee80211_network *net;
 +      u8 i = 0, basic_rate = 0;
 +      net = &priv->ieee80211->current_network;
 +
 +      for (i = 0; i < net->rates_len; i++) {
 +              basic_rate = net->rates[i]&0x7f;
 +              switch (basic_rate) {
 +              case MGN_1M:    *rate_config |= RRSR_1M;        break;
 +              case MGN_2M:    *rate_config |= RRSR_2M;        break;
 +              case MGN_5_5M:  *rate_config |= RRSR_5_5M;      break;
 +              case MGN_11M:   *rate_config |= RRSR_11M;       break;
 +              case MGN_6M:    *rate_config |= RRSR_6M;        break;
 +              case MGN_9M:    *rate_config |= RRSR_9M;        break;
 +              case MGN_12M:   *rate_config |= RRSR_12M;       break;
 +              case MGN_18M:   *rate_config |= RRSR_18M;       break;
 +              case MGN_24M:   *rate_config |= RRSR_24M;       break;
 +              case MGN_36M:   *rate_config |= RRSR_36M;       break;
 +              case MGN_48M:   *rate_config |= RRSR_48M;       break;
 +              case MGN_54M:   *rate_config |= RRSR_54M;       break;
 +              }
 +      }
 +      for (i = 0; i < net->rates_ex_len; i++) {
 +              basic_rate = net->rates_ex[i]&0x7f;
 +              switch (basic_rate) {
 +              case MGN_1M:    *rate_config |= RRSR_1M;        break;
 +              case MGN_2M:    *rate_config |= RRSR_2M;        break;
 +              case MGN_5_5M:  *rate_config |= RRSR_5_5M;      break;
 +              case MGN_11M:   *rate_config |= RRSR_11M;       break;
 +              case MGN_6M:    *rate_config |= RRSR_6M;        break;
 +              case MGN_9M:    *rate_config |= RRSR_9M;        break;
 +              case MGN_12M:   *rate_config |= RRSR_12M;       break;
 +              case MGN_18M:   *rate_config |= RRSR_18M;       break;
 +              case MGN_24M:   *rate_config |= RRSR_24M;       break;
 +              case MGN_36M:   *rate_config |= RRSR_36M;       break;
 +              case MGN_48M:   *rate_config |= RRSR_48M;       break;
 +              case MGN_54M:   *rate_config |= RRSR_54M;       break;
 +              }
 +      }
  }
  
  
  #define SHORT_SLOT_TIME 9
  #define NON_SHORT_SLOT_TIME 20
  
 -void rtl8192_update_cap(struct net_devicedev, u16 cap)
 +void rtl8192_update_cap(struct net_device *dev, u16 cap)
  {
        u32 tmp = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
                tmp |= BRSR_AckShortPmb;
        write_nic_dword(dev, RRSR, tmp);
  
 -      if (net->mode & (IEEE_G|IEEE_N_24G))
 -      {
 +      if (net->mode & (IEEE_G|IEEE_N_24G)) {
                u8 slot_time = 0;
 -              if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
 -              {//short slot time
 +              if ((cap & WLAN_CAPABILITY_SHORT_SLOT) && (!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime)) //short slot time
                        slot_time = SHORT_SLOT_TIME;
 -              }
                else //long slot time
                        slot_time = NON_SHORT_SLOT_TIME;
                priv->slot_time = slot_time;
@@@ -1452,26 -1616,31 +1452,26 @@@ void rtl8192_net_update(struct net_devi
        struct ieee80211_network *net;
        u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
        u16 rate_config = 0;
 -      net = & priv->ieee80211->current_network;
 +      net = &priv->ieee80211->current_network;
  
        rtl8192_config_rate(dev, &rate_config);
        priv->basic_rate = rate_config &= 0x15f;
  
 -      write_nic_dword(dev,BSSIDR,((u32*)net->bssid)[0]);
 -      write_nic_word(dev,BSSIDR+4,((u16*)net->bssid)[2]);
 -      //for(i=0;i<ETH_ALEN;i++)
 -      //      write_nic_byte(dev,BSSID+i,net->bssid[i]);
 +      write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]);
 +      write_nic_word(dev, BSSIDR+4, ((u16 *)net->bssid)[2]);
  
        rtl8192_update_msr(dev);
 -//    rtl8192_update_cap(dev, net->capability);
 -      if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 -      {
 -      write_nic_word(dev, ATIMWND, 2);
 -      write_nic_word(dev, BCN_DMATIME, 1023);
 -      write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
 -//    write_nic_word(dev, BcnIntTime, 100);
 -      write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
 -      write_nic_byte(dev, BCN_ERR_THRESH, 100);
 +      if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
 +              write_nic_word(dev, ATIMWND, 2);
 +              write_nic_word(dev, BCN_DMATIME, 1023);
 +              write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
 +              write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
 +              write_nic_byte(dev, BCN_ERR_THRESH, 100);
                BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
 -      // TODO: BcnIFS may required to be changed on ASIC
 +              // TODO: BcnIFS may required to be changed on ASIC
                BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
  
 -      write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
 +              write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
        }
  
  
  
  //temporary hw beacon is not used any more.
  //open it when necessary
 -void rtl819xusb_beacon_tx(struct net_device *dev,u16  tx_rate)
 +void rtl819xusb_beacon_tx(struct net_device *dev, u16  tx_rate)
  {
  
  }
  inline u8 rtl8192_IsWirelessBMode(u16 rate)
  {
 -      if( ((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220) )
 +      if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
                return 1;
        else return 0;
  }
  
  u16 N_DBPSOfRate(u16 DataRate);
  
 -u16 ComputeTxTime(
 -      u16             FrameLength,
 -      u16             DataRate,
 -      u8              bManagementFrame,
 -      u8              bShortPreamble
 -)
 +u16 ComputeTxTime(u16 FrameLength, u16 DataRate, u8 bManagementFrame,
 +                u8 bShortPreamble)
  {
        u16     FrameTime;
        u16     N_DBPS;
        u16     Ceiling;
  
 -      if( rtl8192_IsWirelessBMode(DataRate) )
 -      {
 -              if( bManagementFrame || !bShortPreamble || DataRate == 10 )
 -              {       // long preamble
 +      if (rtl8192_IsWirelessBMode(DataRate)) {
 +              if (bManagementFrame || !bShortPreamble || DataRate == 10) // long preamble
                        FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
 -              }
 -              else
 -              {       // Short preamble
 +              else // Short preamble
                        FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
 -              }
 -              if( ( FrameLength*8 % (DataRate/10) ) != 0 ) //Get the Ceilling
 -                              FrameTime ++;
 +              if ((FrameLength*8 % (DataRate/10)) != 0) //Get the Ceilling
 +                      FrameTime++;
        } else {        //802.11g DSSS-OFDM PLCP length field calculation.
                N_DBPS = N_DBPSOfRate(DataRate);
                Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
 -                              + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
 +                      + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
                FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
        }
        return FrameTime;
  
  u16 N_DBPSOfRate(u16 DataRate)
  {
 -       u16 N_DBPS = 24;
 +      u16 N_DBPS = 24;
  
 -       switch(DataRate)
 -       {
 -       case 60:
 -        N_DBPS = 24;
 -        break;
 +      switch (DataRate) {
 +      case 60:
 +              N_DBPS = 24;
 +              break;
  
 -       case 90:
 -        N_DBPS = 36;
 -        break;
 +      case 90:
 +              N_DBPS = 36;
 +              break;
  
 -       case 120:
 -        N_DBPS = 48;
 -        break;
 +      case 120:
 +              N_DBPS = 48;
 +              break;
  
 -       case 180:
 -        N_DBPS = 72;
 -        break;
 +      case 180:
 +              N_DBPS = 72;
 +              break;
  
 -       case 240:
 -        N_DBPS = 96;
 -        break;
 +      case 240:
 +              N_DBPS = 96;
 +              break;
  
 -       case 360:
 -        N_DBPS = 144;
 -        break;
 +      case 360:
 +              N_DBPS = 144;
 +              break;
  
 -       case 480:
 -        N_DBPS = 192;
 -        break;
 +      case 480:
 +              N_DBPS = 192;
 +              break;
  
 -       case 540:
 -        N_DBPS = 216;
 -        break;
 +      case 540:
 +              N_DBPS = 216;
 +              break;
  
 -       default:
 -        break;
 -       }
 +      default:
 +              break;
 +      }
  
 -       return N_DBPS;
 +      return N_DBPS;
  }
  
  void rtl819xU_cmd_isr(struct urb *tx_cmd_urb, struct pt_regs *regs)
        usb_free_urb(tx_cmd_urb);
  }
  
 -unsigned int txqueue2outpipe(struct r8192_priv* priv,unsigned int tx_queue) {
 -
 -      if(tx_queue >= 9)
 -      {
 -              RT_TRACE(COMP_ERR,"%s():Unknown queue ID!!!\n",__FUNCTION__);
 +unsigned int txqueue2outpipe(struct r8192_priv *priv, unsigned int tx_queue)
 +{
 +      if (tx_queue >= 9) {
 +              RT_TRACE(COMP_ERR, "%s():Unknown queue ID!!!\n", __func__);
                return 0x04;
        }
        return priv->txqueue_to_outpipemap[tx_queue];
  short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      //u8                    *tx;
        int                     status;
        struct urb              *tx_urb;
 -      //int                   urb_buf_len;
        unsigned int            idx_pipe;
        tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
        cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
        u8 queue_index = tcb_desc->queue_index;
  
 -      //printk("\n %s::queue_index = %d\n",__FUNCTION__, queue_index);
        atomic_inc(&priv->tx_pending[queue_index]);
 -      tx_urb = usb_alloc_urb(0,GFP_ATOMIC);
 -      if(!tx_urb){
 +      tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
 +      if (!tx_urb) {
                dev_kfree_skb(skb);
                return -ENOMEM;
        }
        //----------------------------------------------------------------------------
        // Get index to out pipe from specified QueueID.
  #ifndef USE_ONE_PIPE
 -      idx_pipe = txqueue2outpipe(priv,queue_index);
 +      idx_pipe = txqueue2outpipe(priv, queue_index);
  #else
        idx_pipe = 0x04;
  #endif
  #ifdef JOHN_DUMP_TXDESC
        int i;
 -      printk("<Tx descriptor>--rate %x---",rate);
 +      printk("<Tx descriptor>--rate %x---", rate);
        for (i = 0; i < 8; i++)
                printk("%8x ", tx[i]);
        printk("\n");
  #endif
 -      usb_fill_bulk_urb(tx_urb,priv->udev, usb_sndbulkpipe(priv->udev,idx_pipe), \
 -                      skb->data, skb->len, rtl8192_tx_isr, skb);
 +      usb_fill_bulk_urb(tx_urb, priv->udev, usb_sndbulkpipe(priv->udev, idx_pipe),
 +                        skb->data, skb->len, rtl8192_tx_isr, skb);
  
        status = usb_submit_urb(tx_urb, GFP_ATOMIC);
  
 -      if (!status){
 +      if (!status) {
                return 0;
 -      }else{
 -              DMESGE("Error TX CMD URB, error %d",
 -                              status);
 +      } else {
 +              DMESGE("Error TX CMD URB, error %d", status);
                return -1;
        }
  }
@@@ -1640,21 -1824,21 +1640,21 @@@ u8 MapHwQueueToFirmwareQueue(u8 QueueID
  {
        u8 QueueSelect = 0x0;       //defualt set to
  
 -      switch(QueueID) {
 +      switch (QueueID) {
        case BE_QUEUE:
 -              QueueSelect = QSLT_BE;  //or QSelect = pTcb->priority;
 +              QueueSelect = QSLT_BE;
                break;
  
        case BK_QUEUE:
 -              QueueSelect = QSLT_BK;  //or QSelect = pTcb->priority;
 +              QueueSelect = QSLT_BK;
                break;
  
        case VO_QUEUE:
 -              QueueSelect = QSLT_VO;  //or QSelect = pTcb->priority;
 +              QueueSelect = QSLT_VO;
                break;
  
        case VI_QUEUE:
 -              QueueSelect = QSLT_VI;  //or QSelect = pTcb->priority;
 +              QueueSelect = QSLT_VI;
                break;
        case MGNT_QUEUE:
                QueueSelect = QSLT_MGNT;
  
                // TODO: 2006.10.30 mark other queue selection until we verify it is OK
                // TODO: Remove Assertions
 -//#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502)
        case TXCMD_QUEUE:
                QueueSelect = QSLT_CMD;
                break;
 -//#endif
        case HIGH_QUEUE:
                QueueSelect = QSLT_HIGH;
                break;
@@@ -1684,7 -1870,7 +1684,7 @@@ u8 MRateToHwRate8190Pci(u8 rate
  {
        u8  ret = DESC90_RATE1M;
  
 -      switch(rate) {
 +      switch (rate) {
        case MGN_1M:    ret = DESC90_RATE1M;    break;
        case MGN_2M:    ret = DESC90_RATE2M;    break;
        case MGN_5_5M:  ret = DESC90_RATE5_5M;  break;
@@@ -1727,9 -1913,9 +1727,9 @@@ u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_
  {
        u8   tmp_Short;
  
 -      tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0);
 +      tmp_Short = (TxHT == 1) ? ((tcb_desc->bUseShortGI) ? 1 : 0) : ((tcb_desc->bUseShortPreamble) ? 1 : 0);
  
 -      if(TxHT==1 && TxRate != DESC90_RATEMCS15)
 +      if (TxHT == 1 && TxRate != DESC90_RATEMCS15)
                tmp_Short = 0;
  
        return tmp_Short;
@@@ -1745,7 -1931,7 +1745,7 @@@ static void tx_zero_isr(struct urb *tx_
   * skb->cb will contain all the following information,
   * priority, morefrag, rate, &dev.
   * */
 -short rtl8192_tx(struct net_device *dev, struct sk_buffskb)
 +short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
        int pend;
        int status;
        struct urb *tx_urb = NULL, *tx_urb_zero = NULL;
 -      //int urb_len;
        unsigned int idx_pipe;
 -//    RT_DEBUG_DATA(COMP_SEND, tcb_desc, sizeof(cb_desc));
 -//    printk("=============> %s\n", __FUNCTION__);
        pend = atomic_read(&priv->tx_pending[tcb_desc->queue_index]);
        /* we are locked here so the two atomic_read and inc are executed
         * without interleaves
         * !!! For debug purpose
         */
 -      if( pend > MAX_TX_URB){
 -              printk("To discard skb packet!\n");
 +      if (pend > MAX_TX_URB) {
 +              netdev_dbg(dev, "To discard skb packet!\n");
                dev_kfree_skb_any(skb);
                return -1;
        }
  
 -      tx_urb = usb_alloc_urb(0,GFP_ATOMIC);
 -      if(!tx_urb){
 +      tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
 +      if (!tx_urb) {
                dev_kfree_skb_any(skb);
                return -ENOMEM;
        }
  
        /* Fill Tx firmware info */
 -      memset(tx_fwinfo,0,sizeof(tx_fwinfo_819x_usb));
 +      memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
        /* DWORD 0 */
 -      tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80)?1:0;
 +      tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
        tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
        tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
        tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
 -      if(tcb_desc->bAMPDUEnable) {//AMPDU enabled
 +      if (tcb_desc->bAMPDUEnable) {//AMPDU enabled
                tx_fwinfo->AllowAggregation = 1;
                /* DWORD 1 */
                tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
        }
  
        /* Protection mode related */
 -      tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable)?1:0;
 -      tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable)?1:0;
 -      tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC)?1:0;
 -      tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80)?1:0;
 +      tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
 +      tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
 +      tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
 +      tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
        tx_fwinfo->RtsRate =  MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
 -      tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT==0)?(tcb_desc->RTSSC):0;
 -      tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT==1)?((tcb_desc->bRTSBW)?1:0):0;
 -      tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):\
 -                              (tcb_desc->bRTSUseShortGI?1:0);
 +      tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
 +      tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
 +      tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
 +                            (tcb_desc->bRTSUseShortGI ? 1 : 0);
  
        /* Set Bandwidth and sub-channel settings. */
 -      if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
 -      {
 -              if(tcb_desc->bPacketBW) {
 +      if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
 +              if (tcb_desc->bPacketBW) {
                        tx_fwinfo->TxBandwidth = 1;
                        tx_fwinfo->TxSubCarrier = 0;    //By SD3's Jerry suggestion, use duplicated mode
                } else {
  
  #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
        if (tcb_desc->drv_agg_enable)
 -      {
                tx_fwinfo->Tx_INFO_RSVD = (tcb_desc->DrvAggrNum & 0x1f) << 1;
 -      }
  #endif
        /* Fill Tx descriptor */
        memset(tx_desc, 0, sizeof(tx_desc_819x_usb));
        tx_desc->Offset =  sizeof(tx_fwinfo_819x_usb) + 8;
  
  #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
 -      if (tcb_desc->drv_agg_enable) {
 +      if (tcb_desc->drv_agg_enable)
                tx_desc->PktSize = tcb_desc->pkt_size;
 -      else
 +      else
  #endif
        {
                tx_desc->PktSize = (skb->len - TX_PACKET_SHIFT_BYTES) & 0xffff;
        }
  
        /*DWORD 1*/
 -      tx_desc->SecCAMID= 0;
 +      tx_desc->SecCAMID = 0;
        tx_desc->RATid = tcb_desc->RATRIndex;
 -      {
 -              //MPDUOverhead = 0;
 -              tx_desc->NoEnc = 1;
 -      }
 +      tx_desc->NoEnc = 1;
        tx_desc->SecType = 0x0;
 -              if (tcb_desc->bHwSec)
 -                      {
 -                              switch (priv->ieee80211->pairwise_key_type)
 -                              {
 -                                      case KEY_TYPE_WEP40:
 -                                      case KEY_TYPE_WEP104:
 -                                               tx_desc->SecType = 0x1;
 -                                               tx_desc->NoEnc = 0;
 -                                               break;
 -                                      case KEY_TYPE_TKIP:
 -                                               tx_desc->SecType = 0x2;
 -                                               tx_desc->NoEnc = 0;
 -                                               break;
 -                                      case KEY_TYPE_CCMP:
 -                                               tx_desc->SecType = 0x3;
 -                                               tx_desc->NoEnc = 0;
 -                                               break;
 -                                      case KEY_TYPE_NA:
 -                                               tx_desc->SecType = 0x0;
 -                                               tx_desc->NoEnc = 1;
 -                                               break;
 -                              }
 -                      }
 +      if (tcb_desc->bHwSec) {
 +              switch (priv->ieee80211->pairwise_key_type) {
 +              case KEY_TYPE_WEP40:
 +              case KEY_TYPE_WEP104:
 +                      tx_desc->SecType = 0x1;
 +                      tx_desc->NoEnc = 0;
 +                      break;
 +              case KEY_TYPE_TKIP:
 +                      tx_desc->SecType = 0x2;
 +                      tx_desc->NoEnc = 0;
 +                      break;
 +              case KEY_TYPE_CCMP:
 +                      tx_desc->SecType = 0x3;
 +                      tx_desc->NoEnc = 0;
 +                      break;
 +              case KEY_TYPE_NA:
 +                      tx_desc->SecType = 0x0;
 +                      tx_desc->NoEnc = 1;
 +                      break;
 +              }
 +      }
  
        tx_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
        tx_desc->TxFWInfoSize =  sizeof(tx_fwinfo_819x_usb);
        }
        /* Get index to out pipe from specified QueueID */
  #ifndef USE_ONE_PIPE
 -      idx_pipe = txqueue2outpipe(priv,tcb_desc->queue_index);
 +      idx_pipe = txqueue2outpipe(priv, tcb_desc->queue_index);
  #else
        idx_pipe = 0x5;
  #endif
  
 -      //RT_DEBUG_DATA(COMP_SEND,tx_fwinfo,sizeof(tx_fwinfo_819x_usb));
 -      //RT_DEBUG_DATA(COMP_SEND,tx_desc,sizeof(tx_desc_819x_usb));
 -
        /* To submit bulk urb */
 -      usb_fill_bulk_urb(tx_urb,udev,
 -                      usb_sndbulkpipe(udev,idx_pipe), skb->data,
 -                      skb->len, rtl8192_tx_isr, skb);
 +      usb_fill_bulk_urb(tx_urb, udev,
 +                        usb_sndbulkpipe(udev, idx_pipe), skb->data,
 +                        skb->len, rtl8192_tx_isr, skb);
  
        status = usb_submit_urb(tx_urb, GFP_ATOMIC);
 -      if (!status){
 -//we need to send 0 byte packet whenever 512N bytes/64N(HIGN SPEED/NORMAL SPEED) bytes packet has been transmitted. Otherwise, it will be halt to wait for another packet. WB. 2008.08.27
 +      if (!status) {
 +              //we need to send 0 byte packet whenever 512N bytes/64N(HIGN SPEED/NORMAL SPEED) bytes packet has been transmitted. Otherwise, it will be halt to wait for another packet. WB. 2008.08.27
                bool bSend0Byte = false;
                u8 zero = 0;
 -              if(udev->speed == USB_SPEED_HIGH)
 -              {
 +              if (udev->speed == USB_SPEED_HIGH) {
                        if (skb->len > 0 && skb->len % 512 == 0)
                                bSend0Byte = true;
 -              }
 -              else
 -              {
 +              } else {
                        if (skb->len > 0 && skb->len % 64 == 0)
                                bSend0Byte = true;
                }
 -              if (bSend0Byte)
 -              {
 -                      tx_urb_zero = usb_alloc_urb(0,GFP_ATOMIC);
 -                      if(!tx_urb_zero){
 +              if (bSend0Byte) {
 +                      tx_urb_zero = usb_alloc_urb(0, GFP_ATOMIC);
 +                      if (!tx_urb_zero) {
                                RT_TRACE(COMP_ERR, "can't alloc urb for zero byte\n");
                                return -ENOMEM;
                        }
 -                      usb_fill_bulk_urb(tx_urb_zero,udev,
 -                                      usb_sndbulkpipe(udev,idx_pipe), &zero,
 -                                      0, tx_zero_isr, dev);
 +                      usb_fill_bulk_urb(tx_urb_zero, udev,
 +                                        usb_sndbulkpipe(udev, idx_pipe), &zero,
 +                                        0, tx_zero_isr, dev);
                        status = usb_submit_urb(tx_urb_zero, GFP_ATOMIC);
 -                      if (status){
 -                      RT_TRACE(COMP_ERR, "Error TX URB for zero byte %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status);
 -                      return -1;
 +                      if (status) {
 +                              RT_TRACE(COMP_ERR, "Error TX URB for zero byte %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status);
 +                              return -1;
                        }
                }
                dev->trans_start = jiffies;
                return 0;
        } else {
                RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
 -                              status);
 +                       status);
                return -1;
        }
  }
@@@ -1939,14 -2143,14 +1939,14 @@@ short rtl8192_usb_initendpoints(struct 
        struct r8192_priv *priv = ieee80211_priv(dev);
  
        priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB+1),
 -                              GFP_KERNEL);
 +                             GFP_KERNEL);
        if (priv->rx_urb == NULL)
                return -ENOMEM;
  
  #ifndef JACKSON_NEW_RX
 -      for(i=0;i<(MAX_RX_URB+1);i++){
 +      for (i = 0; i < (MAX_RX_URB+1); i++) {
  
 -              priv->rx_urb[i] = usb_alloc_urb(0,GFP_KERNEL);
 +              priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
  
                priv->rx_urb[i]->transfer_buffer = kmalloc(RX_URB_SIZE, GFP_KERNEL);
  
  #endif
  
  #ifdef THOMAS_BEACON
 -{
 -      long align = 0;
 -      void *oldaddr, *newaddr;
 -
 -      priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL);
 -      priv->oldaddr = kmalloc(16, GFP_KERNEL);
 -      oldaddr = priv->oldaddr;
 -      align = ((long)oldaddr) & 3;
 -      if (align) {
 -              newaddr = oldaddr + 4 - align;
 -              priv->rx_urb[16]->transfer_buffer_length = 16 - 4 + align;
 -      } else {
 -              newaddr = oldaddr;
 -              priv->rx_urb[16]->transfer_buffer_length = 16;
 +      {
 +              long align = 0;
 +              void *oldaddr, *newaddr;
 +
 +              priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL);
 +              priv->oldaddr = kmalloc(16, GFP_KERNEL);
 +              oldaddr = priv->oldaddr;
 +              align = ((long)oldaddr) & 3;
 +              if (align) {
 +                      newaddr = oldaddr + 4 - align;
 +                      priv->rx_urb[16]->transfer_buffer_length = 16 - 4 + align;
 +              } else {
 +                      newaddr = oldaddr;
 +                      priv->rx_urb[16]->transfer_buffer_length = 16;
 +              }
 +              priv->rx_urb[16]->transfer_buffer = newaddr;
        }
 -      priv->rx_urb[16]->transfer_buffer = newaddr;
 -}
  #endif
  
 -      memset(priv->rx_urb, 0, sizeof(struct urb*) * MAX_RX_URB);
 +      memset(priv->rx_urb, 0, sizeof(struct urb *) * MAX_RX_URB);
        priv->pp_rxskb = kcalloc(MAX_RX_URB, sizeof(struct sk_buff *),
                                 GFP_KERNEL);
        if (!priv->pp_rxskb) {
                return -ENOMEM;
        }
  
 -      printk("End of initendpoints\n");
 +      netdev_dbg(dev, "End of initendpoints\n");
        return 0;
  
  }
@@@ -1997,8 -2201,8 +1997,8 @@@ void rtl8192_usb_deleteendpoints(struc
        int i;
        struct r8192_priv *priv = ieee80211_priv(dev);
  
 -      if(priv->rx_urb){
 -              for(i=0;i<(MAX_RX_URB+1);i++){
 +      if (priv->rx_urb) {
 +              for (i = 0; i < (MAX_RX_URB+1); i++) {
                        usb_kill_urb(priv->rx_urb[i]);
                        usb_free_urb(priv->rx_urb[i]);
                }
@@@ -2020,8 -2224,8 +2020,8 @@@ void rtl8192_usb_deleteendpoints(struc
  
  #ifndef JACKSON_NEW_RX
  
 -      if(priv->rx_urb){
 -              for(i=0;i<(MAX_RX_URB+1);i++){
 +      if (priv->rx_urb) {
 +              for (i = 0; i < (MAX_RX_URB+1); i++) {
                        usb_kill_urb(priv->rx_urb[i]);
                        kfree(priv->rx_urb[i]->transfer_buffer);
                        usb_free_urb(priv->rx_urb[i]);
  }
  #endif
  
 -extern void rtl8192_update_ratr_table(struct net_devicedev);
 +extern void rtl8192_update_ratr_table(struct net_device *dev);
  void rtl8192_link_change(struct net_device *dev)
  {
 -//    int i;
 -
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      struct ieee80211_device* ieee = priv->ieee80211;
 -      //write_nic_word(dev, BCN_INTR_ITV, net->beacon_interval);
 -      if (ieee->state == IEEE80211_LINKED)
 -      {
 +      struct ieee80211_device *ieee = priv->ieee80211;
 +      if (ieee->state == IEEE80211_LINKED) {
                rtl8192_net_update(dev);
                rtl8192_update_ratr_table(dev);
                //add this as in pure N mode, wep encryption will use software way, but there is no chance to set this as wep will not set group key in wext. WB.2008.07.08
                if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
 -              EnableHWSecurityConfig8192(dev);
 +                      EnableHWSecurityConfig8192(dev);
        }
        /*update timing params*/
 -//    RT_TRACE(COMP_CH, "========>%s(), chan:%d\n", __FUNCTION__, priv->chan);
 -//    rtl8192_set_chan(dev, priv->chan);
 -       if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
 -      {
 +      if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
                u32 reg = 0;
 -              reg = read_nic_dword(dev, RCR);
 +              read_nic_dword(dev, RCR, &reg);
                if (priv->ieee80211->state == IEEE80211_LINKED)
                        priv->ReceiveConfig = reg |= RCR_CBSSID;
                else
                        priv->ReceiveConfig = reg &= ~RCR_CBSSID;
                write_nic_dword(dev, RCR, reg);
        }
 -
 -//    rtl8192_set_rxconf(dev);
  }
  
  static struct ieee80211_qos_parameters def_qos_parameters = {
 -      {3,3,3,3},/* cw_min */
 -      {7,7,7,7},/* cw_max */
 -      {2,2,2,2},/* aifs */
 -      {0,0,0,0},/* flags */
 -      {0,0,0,0} /* tx_op_limit */
 +      {3, 3, 3, 3},/* cw_min */
 +      {7, 7, 7, 7},/* cw_max */
 +      {2, 2, 2, 2},/* aifs */
 +      {0, 0, 0, 0},/* flags */
 +      {0, 0, 0, 0} /* tx_op_limit */
  };
  
  
 -void rtl8192_update_beacon(struct work_struct * work)
 +void rtl8192_update_beacon(struct work_struct *work)
  {
        struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
        struct net_device *dev = priv->ieee80211->dev;
 -      struct ieee80211_deviceieee = priv->ieee80211;
 -      struct ieee80211_networknet = &ieee->current_network;
 +      struct ieee80211_device *ieee = priv->ieee80211;
 +      struct ieee80211_network *net = &ieee->current_network;
  
        if (ieee->pHTInfo->bCurrentHTSupport)
                HTUpdateSelfAndPeerSetting(ieee, net);
  /*
  * background support to run QoS activate functionality
  */
 -int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO};
 -void rtl8192_qos_activate(struct work_struct * work)
 +int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI, EDCAPARA_VO};
 +void rtl8192_qos_activate(struct work_struct *work)
  {
        struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
        struct net_device *dev = priv->ieee80211->dev;
        struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
        u8 mode = priv->ieee80211->current_network.mode;
 -      //u32 size = sizeof(struct ieee80211_qos_parameters);
        u8  u1bAIFS;
        u32 u4bAcParam;
        int i;
        if (priv == NULL)
                return;
  
 -       mutex_lock(&priv->mutex);
 -      if(priv->ieee80211->state != IEEE80211_LINKED)
 +      mutex_lock(&priv->mutex);
 +      if (priv->ieee80211->state != IEEE80211_LINKED)
                goto success;
 -      RT_TRACE(COMP_QOS,"qos active process with associate response received\n");
 +      RT_TRACE(COMP_QOS, "qos active process with associate response received\n");
        /* It better set slot time at first */
        /* For we just support b/g mode at present, let the slot time at 9/20 selection */
        /* update the ac parameter to related registers */
 -      for(i = 0; i <  QOS_QUEUE_NUM; i++) {
 +      for (i = 0; i <  QOS_QUEUE_NUM; i++) {
                //Mode G/A: slotTimeTimer = 9; Mode B: 20
 -              u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
 +              u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
                u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
 -                              (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
 -                              (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
 -                              ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
 +                            (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
 +                            (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
 +                            ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
  
                write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
 -              //write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
        }
  
  success:
 -       mutex_unlock(&priv->mutex);
 +      mutex_unlock(&priv->mutex);
  }
  
  static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
 -              int active_network,
 -              struct ieee80211_network *network)
 +                                           int active_network,
 +                                           struct ieee80211_network *network)
  {
        int ret = 0;
        u32 size = sizeof(struct ieee80211_qos_parameters);
  
 -      if(priv->ieee80211->state !=IEEE80211_LINKED)
 +      if (priv->ieee80211->state != IEEE80211_LINKED)
                return ret;
  
        if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
  
        if (network->flags & NETWORK_HAS_QOS_MASK) {
                if (active_network &&
 -                              (network->flags & NETWORK_HAS_QOS_PARAMETERS))
 +                  (network->flags & NETWORK_HAS_QOS_PARAMETERS))
                        network->qos_data.active = network->qos_data.supported;
  
                if ((network->qos_data.active == 1) && (active_network == 1) &&
 -                              (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
 -                              (network->qos_data.old_param_count !=
 -                               network->qos_data.param_count)) {
 +                  (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
 +                  (network->qos_data.old_param_count !=
 +                   network->qos_data.param_count)) {
                        network->qos_data.old_param_count =
                                network->qos_data.param_count;
                        queue_work(priv->priv_wq, &priv->qos_activate);
 -                      RT_TRACE (COMP_QOS, "QoS parameters change call "
 -                                      "qos_activate\n");
 +                      RT_TRACE(COMP_QOS, "QoS parameters change call "
 +                               "qos_activate\n");
                }
        } else {
 -              memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
 +              memcpy(&priv->ieee80211->current_network.qos_data.parameters,
                       &def_qos_parameters, size);
  
                if ((network->qos_data.active == 1) && (active_network == 1)) {
  }
  
  /* handle and manage frame from beacon and probe response */
 -static int rtl8192_handle_beacon(struct net_device * dev,
 -                            struct ieee80211_beacon * beacon,
 -                            struct ieee80211_network * network)
 +static int rtl8192_handle_beacon(struct net_device *dev,
 +                               struct ieee80211_beacon *beacon,
 +                               struct ieee80211_network *network)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
  
 -      rtl8192_qos_handle_probe_response(priv,1,network);
 +      rtl8192_qos_handle_probe_response(priv, 1, network);
        queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
        return 0;
  
  * setting
  */
  static int rtl8192_qos_association_resp(struct r8192_priv *priv,
 -                                  struct ieee80211_network *network)
 +                                      struct ieee80211_network *network)
  {
        int ret = 0;
        unsigned long flags;
        if ((priv == NULL) || (network == NULL))
                return ret;
  
 -      if(priv->ieee80211->state !=IEEE80211_LINKED)
 +      if (priv->ieee80211->state != IEEE80211_LINKED)
                return ret;
  
        if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
                return ret;
  
        spin_lock_irqsave(&priv->ieee80211->lock, flags);
 -      if(network->flags & NETWORK_HAS_QOS_PARAMETERS) {
 -              memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
 -                       &network->qos_data.parameters,\
 -                      sizeof(struct ieee80211_qos_parameters));
 +      if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
 +              memcpy(&priv->ieee80211->current_network.qos_data.parameters,
 +                     &network->qos_data.parameters,
 +                     sizeof(struct ieee80211_qos_parameters));
                priv->ieee80211->current_network.qos_data.active = 1;
 -               {
 -                      set_qos_param = 1;
 -                      /* update qos parameter for current network */
 -                      priv->ieee80211->current_network.qos_data.old_param_count = \
 -                               priv->ieee80211->current_network.qos_data.param_count;
 -                      priv->ieee80211->current_network.qos_data.param_count = \
 -                               network->qos_data.param_count;
 -              }
 +              set_qos_param = 1;
 +              /* update qos parameter for current network */
 +              priv->ieee80211->current_network.qos_data.old_param_count =
 +                      priv->ieee80211->current_network.qos_data.param_count;
 +              priv->ieee80211->current_network.qos_data.param_count =
 +                      network->qos_data.param_count;
        } else {
 -              memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
 +              memcpy(&priv->ieee80211->current_network.qos_data.parameters,
                       &def_qos_parameters, size);
                priv->ieee80211->current_network.qos_data.active = 0;
                priv->ieee80211->current_network.qos_data.supported = 0;
  
        spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
  
 -      RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n",__FUNCTION__,network->flags ,priv->ieee80211->current_network.qos_data.active);
 +      RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__, network->flags, priv->ieee80211->current_network.qos_data.active);
        if (set_qos_param == 1)
                queue_work(priv->priv_wq, &priv->qos_activate);
  
  
  
  static int rtl8192_handle_assoc_response(struct net_device *dev,
 -                                   struct ieee80211_assoc_response_frame *resp,
 -                                   struct ieee80211_network *network)
 +                                       struct ieee80211_assoc_response_frame *resp,
 +                                       struct ieee80211_network *network)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        rtl8192_qos_association_resp(priv, network);
  }
  
  
 -void rtl8192_update_ratr_table(struct net_device* dev)
 -      //      POCTET_STRING   posLegacyRate,
 -      //      u8*                     pMcsRate)
 -      //      PRT_WLAN_STA    pEntry)
 +void rtl8192_update_ratr_table(struct net_device *dev)
  {
 -      struct r8192_priv* priv = ieee80211_priv(dev);
 -      struct ieee80211_device* ieee = priv->ieee80211;
 -      u8* pMcsRate = ieee->dot11HTOperationalRateSet;
 -      //struct ieee80211_network *net = &ieee->current_network;
 +      struct r8192_priv *priv = ieee80211_priv(dev);
 +      struct ieee80211_device *ieee = priv->ieee80211;
 +      u8 *pMcsRate = ieee->dot11HTOperationalRateSet;
        u32 ratr_value = 0;
        u8 rate_index = 0;
 -      rtl8192_config_rate(dev, (u16*)(&ratr_value));
 -      ratr_value |= (*(u16*)(pMcsRate)) << 12;
 -//    switch (net->mode)
 -      switch (ieee->mode)
 -      {
 -              case IEEE_A:
 -                      ratr_value &= 0x00000FF0;
 -                      break;
 -              case IEEE_B:
 -                      ratr_value &= 0x0000000F;
 -                      break;
 -              case IEEE_G:
 -                      ratr_value &= 0x00000FF7;
 -                      break;
 -              case IEEE_N_24G:
 -              case IEEE_N_5G:
 -                      if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC
 -                              ratr_value &= 0x0007F007;
 -                      else{
 -                              if (priv->rf_type == RF_1T2R)
 -                                      ratr_value &= 0x000FF007;
 -                              else
 -                                      ratr_value &= 0x0F81F007;
 -                      }
 -                      break;
 -              default:
 -                      break;
 +      rtl8192_config_rate(dev, (u16 *)(&ratr_value));
 +      ratr_value |= (*(u16 *)(pMcsRate)) << 12;
 +      switch (ieee->mode) {
 +      case IEEE_A:
 +              ratr_value &= 0x00000FF0;
 +              break;
 +      case IEEE_B:
 +              ratr_value &= 0x0000000F;
 +              break;
 +      case IEEE_G:
 +              ratr_value &= 0x00000FF7;
 +              break;
 +      case IEEE_N_24G:
 +      case IEEE_N_5G:
 +              if (ieee->pHTInfo->PeerMimoPs == 0) {//MIMO_PS_STATIC
 +                      ratr_value &= 0x0007F007;
 +              } else {
 +                      if (priv->rf_type == RF_1T2R)
 +                              ratr_value &= 0x000FF007;
 +                      else
 +                              ratr_value &= 0x0F81F007;
 +              }
 +              break;
 +      default:
 +              break;
        }
        ratr_value &= 0x0FFFFFFF;
 -      if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){
 +      if (ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz)
                ratr_value |= 0x80000000;
 -      }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){
 +      else if (!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz)
                ratr_value |= 0x80000000;
 -      }
        write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
        write_nic_byte(dev, UFWP, 1);
  }
  
 -static u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
 +static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
  static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
 -bool GetNmodeSupportBySecCfg8192(struct net_device*dev)
 +bool GetNmodeSupportBySecCfg8192(struct net_device *dev)
  {
 -      struct r8192_privpriv = ieee80211_priv(dev);
 -      struct ieee80211_deviceieee = priv->ieee80211;
 -      struct ieee80211_network * network = &ieee->current_network;
 -      int wpa_ie_len= ieee->wpa_ie_len;
 -      struct ieee80211_crypt_datacrypt;
 +      struct r8192_priv *priv = ieee80211_priv(dev);
 +      struct ieee80211_device *ieee = priv->ieee80211;
 +      struct ieee80211_network *network = &ieee->current_network;
 +      int wpa_ie_len = ieee->wpa_ie_len;
 +      struct ieee80211_crypt_data *crypt;
        int encrypt;
  
        crypt = ieee->crypt[ieee->tx_keyidx];
        //we use connecting AP's capability instead of only security config on our driver to distinguish whether it should use N mode or G mode
 -      encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name,"WEP")));
 +      encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name, "WEP")));
  
        /* simply judge  */
 -      if(encrypt && (wpa_ie_len == 0)) {
 +      if (encrypt && (wpa_ie_len == 0)) {
                /* wep encryption, no N mode setting */
                return false;
 -//    } else if((wpa_ie_len != 0)&&(memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) {
 -      } else if((wpa_ie_len != 0)) {
 +      } else if ((wpa_ie_len != 0)) {
                /* parse pairwise key type */
 -              //if((pairwisekey = WEP40)||(pairwisekey = WEP104)||(pairwisekey = TKIP))
 -              if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) || ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4))))
 +              if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) || ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
                        return true;
                else
                        return false;
        return true;
  }
  
 -bool GetHalfNmodeSupportByAPs819xUsb(struct net_devicedev)
 +bool GetHalfNmodeSupportByAPs819xUsb(struct net_device *dev)
  {
        bool                    Reval;
 -      struct r8192_privpriv = ieee80211_priv(dev);
 -      struct ieee80211_deviceieee = priv->ieee80211;
 +      struct r8192_priv *priv = ieee80211_priv(dev);
 +      struct ieee80211_device *ieee = priv->ieee80211;
  
 -      if(ieee->bHalfWirelessN24GMode == true)
 +      if (ieee->bHalfWirelessN24GMode == true)
                Reval = true;
        else
                Reval =  false;
        return Reval;
  }
  
 -void rtl8192_refresh_supportrate(struct r8192_privpriv)
 +void rtl8192_refresh_supportrate(struct r8192_priv *priv)
  {
 -      struct ieee80211_deviceieee = priv->ieee80211;
 +      struct ieee80211_device *ieee = priv->ieee80211;
        //we do not consider set support rate for ABG mode, only HT MCS rate is set here.
        if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
 -      {
                memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
 -              //RT_DEBUG_DATA(COMP_INIT, ieee->RegHTSuppRateSet, 16);
 -              //RT_DEBUG_DATA(COMP_INIT, ieee->Regdot11HTOperationalRateSet, 16);
 -      }
        else
                memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
        return;
  }
  
 -u8 rtl8192_getSupportedWireleeMode(struct net_device*dev)
 +u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8 ret = 0;
 -      switch(priv->rf_chip)
 -      {
 -              case RF_8225:
 -              case RF_8256:
 -              case RF_PSEUDO_11N:
 -                      ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
 -                      break;
 -              case RF_8258:
 -                      ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
 -                      break;
 -              default:
 -                      ret = WIRELESS_MODE_B;
 -                      break;
 +      switch (priv->rf_chip) {
 +      case RF_8225:
 +      case RF_8256:
 +      case RF_PSEUDO_11N:
 +              ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
 +              break;
 +      case RF_8258:
 +              ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
 +              break;
 +      default:
 +              ret = WIRELESS_MODE_B;
 +              break;
        }
        return ret;
  }
 -void rtl8192_SetWirelessMode(struct net_devicedev, u8 wireless_mode)
 +void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
  
 -      if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0))
 -      {
 -              if(bSupportMode & WIRELESS_MODE_N_24G)
 -              {
 +      if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode) == 0)) {
 +              if (bSupportMode & WIRELESS_MODE_N_24G) {
                        wireless_mode = WIRELESS_MODE_N_24G;
 -              }
 -              else if(bSupportMode & WIRELESS_MODE_N_5G)
 -              {
 +              } else if (bSupportMode & WIRELESS_MODE_N_5G) {
                        wireless_mode = WIRELESS_MODE_N_5G;
 -              }
 -              else if((bSupportMode & WIRELESS_MODE_A))
 -              {
 +              } else if ((bSupportMode & WIRELESS_MODE_A)) {
                        wireless_mode = WIRELESS_MODE_A;
 -              }
 -              else if((bSupportMode & WIRELESS_MODE_G))
 -              {
 +              } else if ((bSupportMode & WIRELESS_MODE_G)) {
                        wireless_mode = WIRELESS_MODE_G;
 -              }
 -              else if((bSupportMode & WIRELESS_MODE_B))
 -              {
 +              } else if ((bSupportMode & WIRELESS_MODE_B)) {
                        wireless_mode = WIRELESS_MODE_B;
 -              }
 -              else{
 -                      RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode);
 +              } else {
 +                      RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __func__, bSupportMode);
                        wireless_mode = WIRELESS_MODE_B;
                }
        }
  #ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we should wait for FPGA
 -      ActUpdateChannelAccessSetting( pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting );
 +      ActUpdateChannelAccessSetting(pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting);
  #endif
        priv->ieee80211->mode = wireless_mode;
  
  
  }
  //init priv variables here. only non_zero value should be initialized here.
 -static void rtl8192_init_priv_variable(struct net_devicedev)
 +static void rtl8192_init_priv_variable(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8 i;
        priv->chan = 1; //set to channel 1
        priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
        priv->ieee80211->iw_mode = IW_MODE_INFRA;
 -      priv->ieee80211->ieee_up=0;
 +      priv->ieee80211->ieee_up = 0;
        priv->retry_rts = DEFAULT_RETRY_RTS;
        priv->retry_data = DEFAULT_RETRY_DATA;
        priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
        priv->ieee80211->rate = 110; //11 mbps
        priv->ieee80211->short_slot = 1;
 -      priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
 +      priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
        priv->CckPwEnl = 6;
        //for silent reset
        priv->IrpPendingCount = 1;
        priv->ieee80211->softmac_features  = IEEE_SOFTMAC_SCAN |
                IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
                IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
 -              IEEE_SOFTMAC_BEACONS;//added by amy 080604 //|  //IEEE_SOFTMAC_SINGLE_QUEUE;
 +              IEEE_SOFTMAC_BEACONS;//added by amy 080604
  
        priv->ieee80211->active_scan = 1;
        priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
        priv->ieee80211->host_encrypt = 1;
        priv->ieee80211->host_decrypt = 1;
 -      priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604
 -      priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604
 +      priv->ieee80211->start_send_beacons = NULL; //-by amy 080604
 +      priv->ieee80211->stop_send_beacons = NULL;  //-by amy 080604
        priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
        priv->ieee80211->set_chan = rtl8192_set_chan;
        priv->ieee80211->link_change = rtl8192_link_change;
        priv->ieee80211->qos_support = 1;
  
        //added by WB
 -//    priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl;
        priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
        priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
        priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
        priv->ieee80211->InitialGainHandler = InitialGain819xUsb;
        priv->card_type = USB;
  #ifdef TO_DO_LIST
 -      if(Adapter->bInHctTest)
 -      {
 +      if (Adapter->bInHctTest) {
                pHalData->ShortRetryLimit = 7;
                pHalData->LongRetryLimit = 7;
        }
  #endif
 -      {
 -              priv->ShortRetryLimit = 0x30;
 -              priv->LongRetryLimit = 0x30;
 -      }
 +      priv->ShortRetryLimit = 0x30;
 +      priv->LongRetryLimit = 0x30;
        priv->EarlyRxThreshold = 7;
        priv->enable_gpio0 = 0;
        priv->TransmitConfig =
 -      //      TCR_DurProcMode |       //for RTL8185B, duration setting by HW
 -      //?     TCR_DISReqQsize |
                (TCR_MXDMA_2048<<TCR_MXDMA_OFFSET)|  // Max DMA Burst Size per Tx DMA Burst, 7: reserved.
                (priv->ShortRetryLimit<<TCR_SRL_OFFSET)|        // Short retry limit
                (priv->LongRetryLimit<<TCR_LRL_OFFSET) |        // Long retry limit
 -              (false ? TCR_SAT: 0);   // FALSE: HW provides PLCP length and LENGEXT, TRUE: SW provides them
 +              (false ? TCR_SAT : 0);  // FALSE: HW provides PLCP length and LENGEXT, TRUE: SW provides them
  #ifdef TO_DO_LIST
 -      if(Adapter->bInHctTest)
 +      if (Adapter->bInHctTest)
                pHalData->ReceiveConfig =       pHalData->CSMethod |
 -                                              RCR_AMF | RCR_ADF |     //RCR_AAP |     //accept management/data
 +                                              RCR_AMF | RCR_ADF |     //accept management/data
                                                //guangan200710
                                                RCR_ACF |       //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
                                                RCR_AB | RCR_AM | RCR_APM |             //accept BC/MC/UC
                                                RCR_AICV | RCR_ACRC32 |                 //accept ICV/CRC error packet
                                                ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
                                                (pHalData->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
 -                                              (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt:0);
 +                                              (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt : 0);
        else
  
  #endif
                RCR_AMF | RCR_ADF |             //accept management/data
                RCR_ACF |                       //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
                RCR_AB | RCR_AM | RCR_APM |     //accept BC/MC/UC
 -              //RCR_AICV | RCR_ACRC32 |       //accept ICV/CRC error packet
                ((u32)7<<RCR_MXDMA_OFFSET)| // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
                (priv->EarlyRxThreshold<<RX_FIFO_THRESHOLD_SHIFT) | // Rx FIFO Threshold, 7: No Rx threshold.
 -              (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0);
 +              (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT : 0);
  
        priv->AcmControl = 0;
        priv->pFirmware = kzalloc(sizeof(rt_firmware), GFP_KERNEL);
        skb_queue_head_init(&priv->skb_queue);
  
        /* Tx related queue */
 -      for(i = 0; i < MAX_QUEUE_SIZE; i++) {
 -              skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]);
 -      }
 -      for(i = 0; i < MAX_QUEUE_SIZE; i++) {
 -              skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]);
 -      }
 -      for(i = 0; i < MAX_QUEUE_SIZE; i++) {
 -              skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ [i]);
 -      }
 +      for (i = 0; i < MAX_QUEUE_SIZE; i++)
 +              skb_queue_head_init(&priv->ieee80211->skb_waitQ[i]);
 +      for (i = 0; i < MAX_QUEUE_SIZE; i++)
 +              skb_queue_head_init(&priv->ieee80211->skb_aggQ[i]);
 +      for (i = 0; i < MAX_QUEUE_SIZE; i++)
 +              skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ[i]);
        priv->rf_set_chan = rtl8192_phy_SwChnl;
  }
  
  //init lock here
 -static void rtl8192_init_priv_lock(struct r8192_privpriv)
 +static void rtl8192_init_priv_lock(struct r8192_priv *priv)
  {
        spin_lock_init(&priv->tx_lock);
        spin_lock_init(&priv->irq_lock);//added by thomas
 -      //spin_lock_init(&priv->rf_lock);
 -      sema_init(&priv->wx_sem,1);
 -      sema_init(&priv->rf_sem,1);
 +      sema_init(&priv->wx_sem, 1);
 +      sema_init(&priv->rf_sem, 1);
        mutex_init(&priv->mutex);
  }
  
@@@ -2530,7 -2783,7 +2530,7 @@@ extern  void    rtl819x_watchdog_wqcall
  void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
  //init tasklet and wait_queue here. only 2.6 above kernel is considered
  #define DRV_NAME "wlan0"
 -static void rtl8192_init_priv_task(struct net_devicedev)
 +static void rtl8192_init_priv_task(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
  
  
        INIT_WORK(&priv->reset_wq, rtl8192_restart);
  
 -      //INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog);
        INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
        INIT_DELAYED_WORK(&priv->txpower_tracking_wq,  dm_txpower_trackingcallback);
 -//    INIT_DELAYED_WORK(&priv->gpio_change_rf_wq,  dm_gpio_change_rf_callback);
        INIT_DELAYED_WORK(&priv->rfpath_check_wq,  dm_rf_pathcheck_workitemcallback);
        INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
        INIT_DELAYED_WORK(&priv->initialgain_operate_wq, InitialGainOperateWorkItemCallBack);
 -      //INIT_WORK(&priv->SwChnlWorkItem,  rtl8192_SwChnl_WorkItem);
 -      //INIT_WORK(&priv->SetBWModeWorkItem,  rtl8192_SetBWModeWorkItem);
        INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
  
        tasklet_init(&priv->irq_rx_tasklet,
 -           (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
 -           (unsigned long)priv);
 +                   (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
 +                   (unsigned long)priv);
  }
  
 -static void rtl8192_get_eeprom_size(struct net_devicedev)
 +static void rtl8192_get_eeprom_size(struct net_device *dev)
  {
        u16 curCR = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      RT_TRACE(COMP_EPROM, "===========>%s()\n", __FUNCTION__);
 -      curCR = read_nic_word_E(dev,EPROM_CMD);
 +      RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
 +      read_nic_word_E(dev, EPROM_CMD, &curCR);
        RT_TRACE(COMP_EPROM, "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
        //whether need I consider BIT5?
        priv->epromtype = (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
 -      RT_TRACE(COMP_EPROM, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype);
 +      RT_TRACE(COMP_EPROM, "<===========%s(), epromtype:%d\n", __func__, priv->epromtype);
  }
  
  //used to swap endian. as ntohl & htonl are not necessary to swap endian, so use this instead.
 -static inline u16 endian_swap(u16data)
 +static inline u16 endian_swap(u16 *data)
  {
        u16 tmp = *data;
        *data = (tmp >> 8) | (tmp << 8);
        return *data;
  }
 -static void rtl8192_read_eeprom_info(struct net_devicedev)
 +static void rtl8192_read_eeprom_info(struct net_device *dev)
  {
        u16 wEPROM_ID = 0;
        u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
        u8 bLoad_From_EEPOM = false;
        struct r8192_priv *priv = ieee80211_priv(dev);
        u16 tmpValue = 0;
 -      RT_TRACE(COMP_EPROM, "===========>%s()\n", __FUNCTION__);
 +      int i;
 +      RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
        wEPROM_ID = eprom_read(dev, 0); //first read EEPROM ID out;
        RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
  
 -      if (wEPROM_ID != RTL8190_EEPROM_ID)
 -      {
 +      if (wEPROM_ID != RTL8190_EEPROM_ID) {
                RT_TRACE(COMP_ERR, "EEPROM ID is invalid(is 0x%x(should be 0x%x)\n", wEPROM_ID, RTL8190_EEPROM_ID);
 -      }
 -      else
 +      } else {
                bLoad_From_EEPOM = true;
 +      }
  
 -      if (bLoad_From_EEPOM)
 -      {
 +      if (bLoad_From_EEPOM) {
                tmpValue = eprom_read(dev, (EEPROM_VID>>1));
                priv->eeprom_vid = endian_swap(&tmpValue);
                priv->eeprom_pid = eprom_read(dev, (EEPROM_PID>>1));
                tmpValue = eprom_read(dev, (EEPROM_ChannelPlan>>1));
 -              priv->eeprom_ChannelPlan =((tmpValue&0xff00)>>8);
 +              priv->eeprom_ChannelPlan = ((tmpValue&0xff00)>>8);
                priv->btxpowerdata_readfromEEPORM = true;
                priv->eeprom_CustomerID = eprom_read(dev, (EEPROM_Customer_ID>>1)) >>8;
 -      }
 -      else
 -      {
 +      } else {
                priv->eeprom_vid = 0;
                priv->eeprom_pid = 0;
                priv->card_8192_version = VERSION_819xU_B;
        RT_TRACE(COMP_EPROM, "vid:0x%4x, pid:0x%4x, CustomID:0x%2x, ChanPlan:0x%x\n", priv->eeprom_vid, priv->eeprom_pid, priv->eeprom_CustomerID, priv->eeprom_ChannelPlan);
        //set channelplan from eeprom
        priv->ChannelPlan = priv->eeprom_ChannelPlan;
 -      if (bLoad_From_EEPOM)
 -      {
 +      if (bLoad_From_EEPOM) {
                int i;
 -              for (i=0; i<6; i+=2)
 -              {
 +              for (i = 0; i < 6; i += 2) {
                        u16 tmp = 0;
                        tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i)>>1));
 -                      *(u16*)(&dev->dev_addr[i]) = tmp;
 +                      *(u16 *)(&dev->dev_addr[i]) = tmp;
                }
 -      }
 -      else
 -      {
 +      } else {
                memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
                //should I set IDR0 here?
        }
        priv->rf_type = RTL819X_DEFAULT_RF_TYPE; //default 1T2R
        priv->rf_chip = RF_8256;
  
 -      if (priv->card_8192_version == (u8)VERSION_819xU_A)
 -      {
 +      if (priv->card_8192_version == (u8)VERSION_819xU_A) {
                //read Tx power gain offset of legacy OFDM to HT rate
                if (bLoad_From_EEPOM)
                        priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff>>1))&0xff00) >> 8;
                else
                        priv->EEPROM_Def_Ver = 1;
                RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
 -              if (priv->EEPROM_Def_Ver == 0) //old eeprom definition
 -              {
 +              if (priv->EEPROM_Def_Ver == 0) { //old eeprom definition
                        int i;
                        if (bLoad_From_EEPOM)
                                priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK>>1))&0xff) >> 8;
                        else
                                priv->EEPROMTxPowerLevelCCK = 0x10;
                        RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
 -                      for (i=0; i<3; i++)
 -                      {
 -                              if (bLoad_From_EEPOM)
 -                              {
 +                      for (i = 0; i < 3; i++) {
 +                              if (bLoad_From_EEPOM) {
                                        tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G+i)>>1);
                                        if (((EEPROM_TxPwIndex_OFDM_24G+i) % 2) == 0)
                                                tmpValue = tmpValue & 0x00ff;
                                        else
                                                tmpValue = (tmpValue & 0xff00) >> 8;
 -                              }
 -                              else
 +                              } else {
                                        tmpValue = 0x10;
 +                              }
                                priv->EEPROMTxPowerLevelOFDM24G[i] = (u8) tmpValue;
                                RT_TRACE(COMP_EPROM, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK);
                        }
 -              }//end if EEPROM_DEF_VER == 0
 -              else if (priv->EEPROM_Def_Ver == 1)
 -              {
 -                      if (bLoad_From_EEPOM)
 -                      {
 +              } else if (priv->EEPROM_Def_Ver == 1) {
 +                      if (bLoad_From_EEPOM) {
                                tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1>>1));
                                tmpValue = (tmpValue & 0xff00) >> 8;
 -                      }
 -                      else
 +                      } else {
                                tmpValue = 0x10;
 +                      }
                        priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
  
                        if (bLoad_From_EEPOM)
                                tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2)>>1);
                        else
                                tmpValue = 0x1010;
 -                      *((u16*)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
 +                      *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
                        if (bLoad_From_EEPOM)
                                tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1>>1));
                        else
                                tmpValue = 0x1010;
 -                      *((u16*)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
 +                      *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
                        if (bLoad_From_EEPOM)
                                tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1+2)>>1);
                        else
  
                //update HAL variables
                //
 -              {
 -                      int i;
 -                      for (i=0; i<14; i++)
 -                      {
 -                              if (i<=3)
 -                                      priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
 -                              else if (i>=4 && i<=9)
 -                                      priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[1];
 -                              else
 -                                      priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[2];
 -                      }
 +              for (i = 0; i < 14; i++) {
 +                      if (i <= 3)
 +                              priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
 +                      else if (i >= 4 && i <= 9)
 +                              priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[1];
 +                      else
 +                              priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[2];
 +              }
  
 -                      for (i=0; i<14; i++)
 -                      {
 -                              if (priv->EEPROM_Def_Ver == 0)
 -                              {
 -                                      if (i<=3)
 -                                              priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[0] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
 -                                      else if (i>=4 && i<=9)
 -                                              priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK;
 -                                      else
 -                                              priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[2] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
 -                              }
 -                              else if (priv->EEPROM_Def_Ver == 1)
 -                              {
 -                                      if (i<=3)
 -                                              priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[0];
 -                                      else if (i>=4 && i<=9)
 -                                              priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[1];
 -                                      else
 -                                              priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[2];
 -                              }
 +              for (i = 0; i < 14; i++) {
 +                      if (priv->EEPROM_Def_Ver == 0) {
 +                              if (i <= 3)
 +                                      priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[0] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
 +                              else if (i >= 4 && i <= 9)
 +                                      priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK;
 +                              else
 +                                      priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[2] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
 +                      } else if (priv->EEPROM_Def_Ver == 1) {
 +                              if (i <= 3)
 +                                      priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[0];
 +                              else if (i >= 4 && i <= 9)
 +                                      priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[1];
 +                              else
 +                                      priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[2];
                        }
 -              }//end update HAL variables
 +              }
                priv->TxPowerDiff = priv->EEPROMPwDiff;
 -// Antenna B gain offset to antenna A, bit0~3
 +              // Antenna B gain offset to antenna A, bit0~3
                priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
                // Antenna C gain offset to antenna A, bit4~7
                priv->AntennaTxPwDiff[1] = ((priv->EEPROMTxPowerDiff & 0xf0)>>4);
                priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
        }//end if VersionID == VERSION_819xU_A
  
 -//added by vivi, for dlink led, 20080416
 -      switch(priv->eeprom_CustomerID)
 -      {
 -              case EEPROM_CID_RUNTOP:
 -                      priv->CustomerID = RT_CID_819x_RUNTOP;
 -                      break;
 +      //added by vivi, for dlink led, 20080416
 +      switch (priv->eeprom_CustomerID) {
 +      case EEPROM_CID_RUNTOP:
 +              priv->CustomerID = RT_CID_819x_RUNTOP;
 +              break;
  
 -              case EEPROM_CID_DLINK:
 -                      priv->CustomerID = RT_CID_DLINK;
 -                      break;
 +      case EEPROM_CID_DLINK:
 +              priv->CustomerID = RT_CID_DLINK;
 +              break;
  
 -              default:
 -                      priv->CustomerID = RT_CID_DEFAULT;
 -                      break;
 +      default:
 +              priv->CustomerID = RT_CID_DEFAULT;
 +              break;
  
        }
  
 -      switch(priv->CustomerID)
 -      {
 -              case RT_CID_819x_RUNTOP:
 -                      priv->LedStrategy = SW_LED_MODE2;
 -                      break;
 +      switch (priv->CustomerID) {
 +      case RT_CID_819x_RUNTOP:
 +              priv->LedStrategy = SW_LED_MODE2;
 +              break;
  
 -              case RT_CID_DLINK:
 -                      priv->LedStrategy = SW_LED_MODE4;
 -                      break;
 +      case RT_CID_DLINK:
 +              priv->LedStrategy = SW_LED_MODE4;
 +              break;
  
 -              default:
 -                      priv->LedStrategy = SW_LED_MODE0;
 -                      break;
 +      default:
 +              priv->LedStrategy = SW_LED_MODE0;
 +              break;
  
        }
  
  
 -      if(priv->rf_type == RF_1T2R)
 -      {
 +      if (priv->rf_type == RF_1T2R) {
                RT_TRACE(COMP_EPROM, "\n1T2R config\n");
 -      }
 -      else
 -      {
 +      } else {
                RT_TRACE(COMP_EPROM, "\n2T4R config\n");
        }
  
        init_rate_adaptive(dev);
        //we need init DIG RATR table here again.
  
 -      RT_TRACE(COMP_EPROM, "<===========%s()\n", __FUNCTION__);
 +      RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__);
        return;
  }
  
 -short rtl8192_get_channel_map(struct net_device * dev)
 +short rtl8192_get_channel_map(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      if(priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN){
 -              printk("rtl8180_init:Error channel plan! Set to default.\n");
 -              priv->ChannelPlan= 0;
 +      if (priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN) {
 +              netdev_err(dev, "rtl8180_init: Error channel plan! Set to default.\n");
 +              priv->ChannelPlan = 0;
        }
 -      RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
 +      RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
  
        rtl819x_set_channel_map(priv->ChannelPlan, priv);
        return 0;
@@@ -2804,18 -3088,24 +2804,18 @@@ short rtl8192_init(struct net_device *d
  
        struct r8192_priv *priv = ieee80211_priv(dev);
  
 -      memset(&(priv->stats),0,sizeof(struct Stats));
 -      memset(priv->txqueue_to_outpipemap,0,9);
 +      memset(&(priv->stats), 0, sizeof(struct Stats));
 +      memset(priv->txqueue_to_outpipemap, 0, 9);
  #ifdef PIPE12
        {
 -              int i=0;
 -              u8 queuetopipe[]={3,2,1,0,4,8,7,6,5};
 -              memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
 -/*            for(i=0;i<9;i++)
 -                      printk("%d ",priv->txqueue_to_outpipemap[i]);
 -              printk("\n");*/
 +              int i = 0;
 +              u8 queuetopipe[] = {3, 2, 1, 0, 4, 8, 7, 6, 5};
 +              memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
        }
  #else
        {
 -              u8 queuetopipe[]={3,2,1,0,4,4,0,4,4};
 -              memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
 -/*            for(i=0;i<9;i++)
 -                      printk("%d ",priv->txqueue_to_outpipemap[i]);
 -              printk("\n");*/
 +              u8 queuetopipe[] = {3, 2, 1, 0, 4, 4, 0, 4, 4};
 +              memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
        }
  #endif
        rtl8192_init_priv_variable(dev);
        init_timer(&priv->watch_dog_timer);
        priv->watch_dog_timer.data = (unsigned long)dev;
        priv->watch_dog_timer.function = watch_dog_timer_callback;
 -      if(rtl8192_usb_initendpoints(dev)!=0){
 +      if (rtl8192_usb_initendpoints(dev) != 0) {
                DMESG("Endopoints initialization failed");
                return -ENOMEM;
        }
  
 -      //rtl8192_adapter_start(dev);
  #ifdef DEBUG_EPROM
        dump_eprom(dev);
  #endif
   *  return:  none
   *  notice:  This part need to modified according to the rate set we filtered
   * ****************************************************************************/
 -void rtl8192_hwconfig(struct net_devicedev)
 +void rtl8192_hwconfig(struct net_device *dev)
  {
        u32 regRATR = 0, regRRSR = 0;
        u8 regBwOpMode = 0, regTmp = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
 +      u32 ratr_value = 0;
  
 -// Set RRSR, RATR, and BW_OPMODE registers
 +      // Set RRSR, RATR, and BW_OPMODE registers
        //
 -      switch(priv->ieee80211->mode)
 -      {
 +      switch (priv->ieee80211->mode) {
        case WIRELESS_MODE_B:
                regBwOpMode = BW_OPMODE_20MHZ;
                regRATR = RATE_ALL_CCK;
                break;
        case WIRELESS_MODE_AUTO:
  #ifdef TO_DO_LIST
 -              if (Adapter->bInHctTest)
 -              {
 -                  regBwOpMode = BW_OPMODE_20MHZ;
 -                  regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
 -                  regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
 +              if (Adapter->bInHctTest) {
 +                      regBwOpMode = BW_OPMODE_20MHZ;
 +                      regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
 +                      regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                }
                else
  #endif
                {
 -                  regBwOpMode = BW_OPMODE_20MHZ;
 -                  regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
 -                  regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
 +                      regBwOpMode = BW_OPMODE_20MHZ;
 +                      regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
 +                      regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                }
                break;
        case WIRELESS_MODE_N_24G:
                // It support CCK rate by default.
                // CCK rate will be filtered out only when associated AP does not support it.
                regBwOpMode = BW_OPMODE_20MHZ;
 -                      regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
 -                      regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
 +              regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
 +              regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                break;
        case WIRELESS_MODE_N_5G:
                regBwOpMode = BW_OPMODE_5G;
        }
  
        write_nic_byte(dev, BW_OPMODE, regBwOpMode);
 -      {
 -              u32 ratr_value = 0;
 -              ratr_value = regRATR;
 -              if (priv->rf_type == RF_1T2R)
 -              {
 -                      ratr_value &= ~(RATE_ALL_OFDM_2SS);
 -              }
 -              write_nic_dword(dev, RATR0, ratr_value);
 -              write_nic_byte(dev, UFWP, 1);
 -      }
 -      regTmp = read_nic_byte(dev, 0x313);
 +      ratr_value = regRATR;
 +      if (priv->rf_type == RF_1T2R)
 +              ratr_value &= ~(RATE_ALL_OFDM_2SS);
 +      write_nic_dword(dev, RATR0, ratr_value);
 +      write_nic_byte(dev, UFWP, 1);
 +      read_nic_byte(dev, 0x313, &regTmp);
        regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
        write_nic_dword(dev, RRSR, regRRSR);
  
        // Set Retry Limit here
        //
        write_nic_word(dev, RETRY_LIMIT,
 -                      priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT | \
 -                      priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
 +                     priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
 +                     priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
        // Set Contention Window here
  
        // Set Tx AGC
@@@ -2935,9 -3232,7 +2935,9 @@@ bool rtl8192_adapter_start(struct net_d
        struct r8192_priv *priv = ieee80211_priv(dev);
        u32 dwRegRead = 0;
        bool init_status = true;
 -      RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__);
 +      u8 SECR_value = 0x0;
 +      u8 tmp;
 +      RT_TRACE(COMP_INIT, "====>%s()\n", __func__);
        priv->Rf_Mode = RF_OP_By_SW_3wire;
        //for ASIC power on sequence
        write_nic_byte_E(dev, 0x5f, 0x80);
        write_nic_byte_E(dev, 0x5e, 0x80);
        write_nic_byte(dev, 0x17, 0x37);
        mdelay(10);
 -//#ifdef TO_DO_LIST
        priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
        //config CPUReset Register
        //Firmware Reset or not?
 -      dwRegRead = read_nic_dword(dev, CPU_GEN);
 +      read_nic_dword(dev, CPU_GEN, &dwRegRead);
        if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
                dwRegRead |= CPU_GEN_SYSTEM_RESET; //do nothing here?
        else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
                dwRegRead |= CPU_GEN_FIRMWARE_RESET;
        else
 -              RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__,   priv->pFirmware->firmware_status);
 +              RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __func__,   priv->pFirmware->firmware_status);
  
        write_nic_dword(dev, CPU_GEN, dwRegRead);
 -      //mdelay(30);
        //config BB.
        rtl8192_BBConfig(dev);
  
        //Loopback mode or not
        priv->LoopbackMode = RTL819xU_NO_LOOPBACK;
 -//    priv->LoopbackMode = RTL819xU_MAC_LOOPBACK;
  
 -      dwRegRead = read_nic_dword(dev, CPU_GEN);
 +      read_nic_dword(dev, CPU_GEN, &dwRegRead);
        if (priv->LoopbackMode == RTL819xU_NO_LOOPBACK)
                dwRegRead = ((dwRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET);
        else if (priv->LoopbackMode == RTL819xU_MAC_LOOPBACK)
                dwRegRead |= CPU_CCK_LOOPBACK;
        else
 -              RT_TRACE(COMP_ERR, "Serious error in %s(): wrong loopback mode setting(%d)\n", __FUNCTION__,  priv->LoopbackMode);
 +              RT_TRACE(COMP_ERR, "Serious error in %s(): wrong loopback mode setting(%d)\n", __func__,  priv->LoopbackMode);
  
        write_nic_dword(dev, CPU_GEN, dwRegRead);
  
        udelay(500);
  
        //xiong add for new bitfile:usb suspend reset pin set to 1. //do we need?
 -      write_nic_byte_E(dev, 0x5f, (read_nic_byte_E(dev, 0x5f)|0x20));
 +      read_nic_byte_E(dev, 0x5f, &tmp);
 +      write_nic_byte_E(dev, 0x5f, tmp|0x20);
  
        //Set Hardware
        rtl8192_hwconfig(dev);
        write_nic_byte(dev, CMDR, CR_RE|CR_TE);
  
        //set IDR0 here
 -      write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
 -      write_nic_word(dev, MAC4, ((u16*)(dev->dev_addr + 4))[0]);
 +      write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
 +      write_nic_word(dev, MAC4, ((u16 *)(dev->dev_addr + 4))[0]);
  
        //set RCR
        write_nic_dword(dev, RCR, priv->ReceiveConfig);
  
        //Initialize Number of Reserved Pages in Firmware Queue
 -      write_nic_dword(dev, RQPN1,  NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |\
 -                                              NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT | \
 -                                              NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT | \
 -                                              NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
 -      write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |\
 -                                              NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
 -      write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW| \
 -                                              NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT
 -//                                            | NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT
 -                                              );
 +      write_nic_dword(dev, RQPN1,  NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
 +                      NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
 +                      NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
 +                      NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
 +      write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |
 +                      NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
 +      write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
 +                      NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT);
        write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
  
        //Set AckTimeout
        // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
        write_nic_byte(dev, ACK_TIMEOUT, 0x30);
  
 -//    RT_TRACE(COMP_INIT, "%s():priv->ResetProgress is %d\n", __FUNCTION__,priv->ResetProgress);
 -      if(priv->ResetProgress == RESET_TYPE_NORESET)
 -      rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
 -      if(priv->ResetProgress == RESET_TYPE_NORESET){
 -      CamResetAllEntry(dev);
 -      {
 -              u8 SECR_value = 0x0;
 +      if (priv->ResetProgress == RESET_TYPE_NORESET)
 +              rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
 +      if (priv->ResetProgress == RESET_TYPE_NORESET) {
 +              CamResetAllEntry(dev);
                SECR_value |= SCR_TxEncEnable;
                SECR_value |= SCR_RxDecEnable;
                SECR_value |= SCR_NoSKMC;
                write_nic_byte(dev, SECR, SECR_value);
        }
 -      }
  
        //Beacon related
        write_nic_word(dev, ATIMWND, 2);
        write_nic_word(dev, BCN_INTERVAL, 100);
  
 -      {
  #define DEFAULT_EDCA 0x005e4332
 +      {
                int i;
 -              for (i=0; i<QOS_QUEUE_NUM; i++)
 -              write_nic_dword(dev, WDCAPARA_ADD[i], DEFAULT_EDCA);
 +              for (i = 0; i < QOS_QUEUE_NUM; i++)
 +                      write_nic_dword(dev, WDCAPARA_ADD[i], DEFAULT_EDCA);
        }
  #ifdef USB_RX_AGGREGATION_SUPPORT
        //3 For usb rx firmware aggregation control
 -      if(priv->ResetProgress == RESET_TYPE_NORESET)
 -      {
 +      if (priv->ResetProgress == RESET_TYPE_NORESET) {
                u32 ulValue;
                PRT_HIGH_THROUGHPUT     pHTInfo = priv->ieee80211->pHTInfo;
                ulValue = (pHTInfo->UsbRxFwAggrEn<<24) | (pHTInfo->UsbRxFwAggrPageNum<<16) |
 -                                      (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
 +                        (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
                /*
                 * If usb rx firmware aggregation is enabled,
                 * when anyone of three threshold conditions above is reached,
  
        rtl8192_phy_configmac(dev);
  
 -      if (priv->card_8192_version == (u8) VERSION_819xU_A)
 -      {
 +      if (priv->card_8192_version == (u8) VERSION_819xU_A) {
                rtl8192_phy_getTxPower(dev);
                rtl8192_phy_setTxPower(dev, priv->chan);
        }
  
        //Firmware download
        init_status = init_firmware(dev);
 -      if(!init_status)
 -      {
 -              RT_TRACE(COMP_ERR,"ERR!!! %s(): Firmware download is failed\n", __FUNCTION__);
 +      if (!init_status) {
 +              RT_TRACE(COMP_ERR, "ERR!!! %s(): Firmware download is failed\n", __func__);
                return init_status;
        }
 -      RT_TRACE(COMP_INIT, "%s():after firmware download\n", __FUNCTION__);
 +      RT_TRACE(COMP_INIT, "%s():after firmware download\n", __func__);
        //
  #ifdef TO_DO_LIST
 -if(Adapter->ResetProgress == RESET_TYPE_NORESET)
 -      {
 -              if(pMgntInfo->RegRfOff == TRUE)
 -              { // User disable RF via registry.
 +      if (Adapter->ResetProgress == RESET_TYPE_NORESET) {
 +              if (pMgntInfo->RegRfOff == TRUE) { // User disable RF via registry.
                        RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
                        MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
                        // Those actions will be discard in MgntActSet_RF_State because of the same state
 -                      for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
 +                      for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
                                PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
 -              }
 -              else if(pMgntInfo->RfOffReason > RF_CHANGE_BY_PS)
 -              { // H/W or S/W RF OFF before sleep.
 +              } else if (pMgntInfo->RfOffReason > RF_CHANGE_BY_PS) { // H/W or S/W RF OFF before sleep.
                        RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n", pMgntInfo->RfOffReason));
                        MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
 -              }
 -              else
 -              {
 +              } else {
                        pHalData->eRFPowerState = eRfOn;
                        pMgntInfo->RfOffReason = 0;
                        RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): RF is on ----------\n"));
                }
 -      }
 -      else
 -      {
 -              if(pHalData->eRFPowerState == eRfOff)
 -              {
 +      } else {
 +              if (pHalData->eRFPowerState == eRfOff) {
                        MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
                        // Those actions will be discard in MgntActSet_RF_State because of the same state
 -                      for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
 +                      for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
                                PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
                }
        }
  #endif
        //config RF.
 -      if(priv->ResetProgress == RESET_TYPE_NORESET){
 -      rtl8192_phy_RFConfig(dev);
 -      RT_TRACE(COMP_INIT, "%s():after phy RF config\n", __FUNCTION__);
 +      if (priv->ResetProgress == RESET_TYPE_NORESET) {
 +              rtl8192_phy_RFConfig(dev);
 +              RT_TRACE(COMP_INIT, "%s():after phy RF config\n", __func__);
        }
  
  
 -      if(priv->ieee80211->FwRWRF)
 +      if (priv->ieee80211->FwRWRF)
                // We can force firmware to do RF-R/W
                priv->Rf_Mode = RF_OP_By_FW;
        else
        rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
        rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
  
 -      if(priv->ResetProgress == RESET_TYPE_NORESET)
 -      {
 +      if (priv->ResetProgress == RESET_TYPE_NORESET) {
                //if D or C cut
 -              u8 tmpvalue = read_nic_byte(dev, 0x301);
 -              if(tmpvalue ==0x03)
 -              {
 +              u8 tmpvalue;
 +              read_nic_byte(dev, 0x301, &tmpvalue);
 +              if (tmpvalue == 0x03) {
                        priv->bDcut = TRUE;
                        RT_TRACE(COMP_POWER_TRACKING, "D-cut\n");
 -              }
 -              else
 -              {
 +              } else {
                        priv->bDcut = FALSE;
                        RT_TRACE(COMP_POWER_TRACKING, "C-cut\n");
                }
                dm_initialize_txpower_tracking(dev);
  
 -              if(priv->bDcut == TRUE)
 -              {
 +              if (priv->bDcut == TRUE) {
                        u32 i, TempCCk;
 -                      u32 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
 -              //      u32 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
 -                      for(i = 0; i<TxBBGainTableLength; i++)
 -                      {
 -                              if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
 -                              {
 -                                      priv->rfa_txpowertrackingindex= (u8)i;
 -                                      priv->rfa_txpowertrackingindex_real= (u8)i;
 -                                      priv->rfa_txpowertracking_default= priv->rfa_txpowertrackingindex;
 +                      u32 tmpRegA = rtl8192_QueryBBReg(dev, rOFDM0_XATxIQImbalance, bMaskDWord);
 +                      for (i = 0; i < TxBBGainTableLength; i++) {
 +                              if (tmpRegA == priv->txbbgain_table[i].txbbgain_value) {
 +                                      priv->rfa_txpowertrackingindex = (u8)i;
 +                                      priv->rfa_txpowertrackingindex_real = (u8)i;
 +                                      priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
                                        break;
                                }
                        }
  
                        TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
  
 -                      for(i=0 ; i<CCKTxBBGainTableLength ; i++)
 -                      {
 +                      for (i = 0; i < CCKTxBBGainTableLength; i++) {
  
 -                              if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
 -                              {
 -                                      priv->cck_present_attentuation_20Mdefault=(u8) i;
 +                              if (TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) {
 +                                      priv->cck_present_attentuation_20Mdefault = (u8) i;
                                        break;
                                }
                        }
 -                      priv->cck_present_attentuation_40Mdefault= 0;
 -                      priv->cck_present_attentuation_difference= 0;
 +                      priv->cck_present_attentuation_40Mdefault = 0;
 +                      priv->cck_present_attentuation_difference = 0;
                        priv->cck_present_attentuation = priv->cck_present_attentuation_20Mdefault;
  
 -      //              pMgntInfo->bTXPowerTracking = FALSE;//TEMPLY DISABLE
                }
        }
        write_nic_byte(dev, 0x87, 0x0);
@@@ -3167,14 -3492,16 +3167,14 @@@ static struct net_device_stats *rtl8192
        return &priv->ieee80211->stats;
  }
  
 -bool
 -HalTxCheckStuck819xUsb(
 -      struct net_device *dev
 -      )
 +bool HalTxCheckStuck819xUsb(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      u16             RegTxCounter = read_nic_word(dev, 0x128);
 +      u16             RegTxCounter;
        bool            bStuck = FALSE;
 -      RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
 -      if(priv->TxCounter==RegTxCounter)
 +      read_nic_word(dev, 0x128, &RegTxCounter);
 +      RT_TRACE(COMP_RESET, "%s():RegTxCounter is %d,TxCounter is %d\n", __func__, RegTxCounter, priv->TxCounter);
 +      if (priv->TxCounter == RegTxCounter)
                bStuck = TRUE;
  
        priv->TxCounter = RegTxCounter;
  *     <Assumption: RT_TX_SPINLOCK is acquired.>
  *     First added: 2006.11.19 by emily
  */
 -RESET_TYPE
 -TxCheckStuck(struct net_device *dev)
 +RESET_TYPE TxCheckStuck(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8                      QueueID;
 -//    PRT_TCB                 pTcb;
 -//    u8                      ResetThreshold;
        bool                    bCheckFwTxCnt = false;
 -      //unsigned long flags;
  
        //
        // Decide such threshold according to current power save mode
        //
  
 -//     RT_TRACE(COMP_RESET, " ==> TxCheckStuck()\n");
 -//         PlatformAcquireSpinLock(Adapter, RT_TX_SPINLOCK);
 -//         spin_lock_irqsave(&priv->ieee80211->lock,flags);
 -           for (QueueID = 0; QueueID<=BEACON_QUEUE;QueueID ++)
 -           {
 -                      if(QueueID == TXCMD_QUEUE)
 -                       continue;
 +      for (QueueID = 0; QueueID <= BEACON_QUEUE; QueueID++) {
 +              if (QueueID == TXCMD_QUEUE)
 +                      continue;
  #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
 -                      if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0))
 +              if ((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0))
  #else
 -                      if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0)  && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
 +              if ((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0)  && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
  #endif
                                continue;
  
 -                   bCheckFwTxCnt = true;
 -           }
 -//         PlatformReleaseSpinLock(Adapter, RT_TX_SPINLOCK);
 -//    spin_unlock_irqrestore(&priv->ieee80211->lock,flags);
 -//    RT_TRACE(COMP_RESET,"bCheckFwTxCnt is %d\n",bCheckFwTxCnt);
 -      if(bCheckFwTxCnt)
 -      {
 -              if(HalTxCheckStuck819xUsb(dev))
 -              {
 +              bCheckFwTxCnt = true;
 +      }
 +      if (bCheckFwTxCnt) {
 +              if (HalTxCheckStuck819xUsb(dev)) {
                        RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
                        return RESET_TYPE_SILENT;
                }
        return RESET_TYPE_NORESET;
  }
  
 -bool
 -HalRxCheckStuck819xUsb(struct net_device *dev)
 +bool HalRxCheckStuck819xUsb(struct net_device *dev)
  {
 -      u16     RegRxCounter = read_nic_word(dev, 0x130);
 +      u16     RegRxCounter;
        struct r8192_priv *priv = ieee80211_priv(dev);
        bool bStuck = FALSE;
        static u8       rx_chk_cnt;
 -      RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter);
 +      read_nic_word(dev, 0x130, &RegRxCounter);
 +      RT_TRACE(COMP_RESET, "%s(): RegRxCounter is %d,RxCounter is %d\n", __func__, RegRxCounter, priv->RxCounter);
        // If rssi is small, we should check rx for long time because of bad rx.
        // or maybe it will continuous silent reset every 2 seconds.
        rx_chk_cnt++;
 -      if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5))
 -      {
 +      if (priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5)) {
                rx_chk_cnt = 0; //high rssi, check rx stuck right now.
 -      }
 -      else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
 -              ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) ||
 -              (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) )
 -      {
 -              if(rx_chk_cnt < 2)
 -              {
 +      } else if (priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
 +                 ((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_40M) ||
 +                  (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_20M))) {
 +              if (rx_chk_cnt < 2)
                        return bStuck;
 -              }
                else
 -              {
                        rx_chk_cnt = 0;
 -              }
 -      }
 -      else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) ||
 -              (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) &&
 -              priv->undecorated_smoothed_pwdb >= VeryLowRSSI)
 -      {
 -              if(rx_chk_cnt < 4)
 -              {
 -                      //DbgPrint("RSSI < %d && RSSI >= %d, no check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
 +      } else if (((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_40M) ||
 +                  (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_20M)) &&
 +                   priv->undecorated_smoothed_pwdb >= VeryLowRSSI) {
 +              if (rx_chk_cnt < 4)
                        return bStuck;
 -              }
                else
 -              {
                        rx_chk_cnt = 0;
 -                      //DbgPrint("RSSI < %d && RSSI >= %d, check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
 -              }
 -      }
 -      else
 -      {
 -              if(rx_chk_cnt < 8)
 -              {
 -                      //DbgPrint("RSSI <= %d, no check this time \n", VeryLowRSSI);
 +      } else {
 +              if (rx_chk_cnt < 8)
                        return bStuck;
 -              }
                else
 -              {
                        rx_chk_cnt = 0;
 -                      //DbgPrint("RSSI <= %d, check this time \n", VeryLowRSSI);
 -              }
        }
  
 -      if(priv->RxCounter==RegRxCounter)
 +      if (priv->RxCounter == RegRxCounter)
                bStuck = TRUE;
  
        priv->RxCounter = RegRxCounter;
        return bStuck;
  }
  
 -RESET_TYPE
 -RxCheckStuck(struct net_device *dev)
 +RESET_TYPE RxCheckStuck(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      //int                     i;
        bool        bRxCheck = FALSE;
  
 -//       RT_TRACE(COMP_RESET," ==> RxCheckStuck()\n");
 -      //PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
 -
 -       if(priv->IrpPendingCount > 1)
 +      if (priv->IrpPendingCount > 1)
                bRxCheck = TRUE;
 -       //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
  
 -//       RT_TRACE(COMP_RESET,"bRxCheck is %d \n",bRxCheck);
 -      if(bRxCheck)
 -      {
 -              if(HalRxCheckStuck819xUsb(dev))
 -              {
 +      if (bRxCheck) {
 +              if (HalRxCheckStuck819xUsb(dev)) {
                        RT_TRACE(COMP_RESET, "RxStuck Condition\n");
                        return RESET_TYPE_SILENT;
                }
  *
  *     8185 and 8185b does not implement this function. This is added by Emily at 2006.11.24
  */
 -RESET_TYPE
 -rtl819x_ifcheck_resetornot(struct net_device *dev)
 +RESET_TYPE rtl819x_ifcheck_resetornot(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        RESET_TYPE      TxResetType = RESET_TYPE_NORESET;
        rfState = priv->ieee80211->eRFPowerState;
  
        TxResetType = TxCheckStuck(dev);
 -      if( rfState != eRfOff ||
 -              /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/
 -              (priv->ieee80211->iw_mode != IW_MODE_ADHOC))
 -      {
 +      if (rfState != eRfOff ||
 +          (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) {
                // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
                // in turned off state. Driver should check whether Rx stuck and do silent reset. And
                // if driver is in firmware download failure status, driver should initialize RF in the following
                // set, STA cannot hear any packet at all. Emily, 2008.04.12
                RxResetType = RxCheckStuck(dev);
        }
 -      if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
 +      if (TxResetType == RESET_TYPE_NORMAL || RxResetType == RESET_TYPE_NORMAL) {
                return RESET_TYPE_NORMAL;
 -      else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT){
 -              RT_TRACE(COMP_RESET,"%s():silent reset\n",__FUNCTION__);
 +      } else if (TxResetType == RESET_TYPE_SILENT || RxResetType == RESET_TYPE_SILENT) {
 +              RT_TRACE(COMP_RESET, "%s():silent reset\n", __func__);
                return RESET_TYPE_SILENT;
 -      }
 -      else
 +      } else {
                return RESET_TYPE_NORESET;
 +      }
  
  }
  
 -void rtl8192_cancel_deferred_work(struct r8192_privpriv);
 +void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
  int _rtl8192_up(struct net_device *dev);
  int rtl8192_close(struct net_device *dev);
  
  
  
 -void
 -CamRestoreAllEntry(   struct net_device *dev)
 +void CamRestoreAllEntry(struct net_device *dev)
  {
        u8 EntryId = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      u8*     MacAddr = priv->ieee80211->current_network.bssid;
 +      u8      *MacAddr = priv->ieee80211->current_network.bssid;
  
        static u8       CAM_CONST_ADDR[4][6] = {
                {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
                {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
                {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
 -              {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
 -      static u8       CAM_CONST_BROAD[] =
 -              {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 +              {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} };
 +      static u8       CAM_CONST_BROAD[] = {
 +              0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  
        RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
  
  
 -      if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)||
 -          (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104))
 -      {
 +      if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40) ||
 +          (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104)) {
  
 -              for(EntryId=0; EntryId<4; EntryId++)
 -              {
 -                      {
 -                              MacAddr = CAM_CONST_ADDR[EntryId];
 -                              setKey(dev,
 -                                              EntryId ,
 -                                              EntryId,
 -                                              priv->ieee80211->pairwise_key_type,
 -                                              MacAddr,
 -                                              0,
 -                                              NULL);
 -                      }
 +              for (EntryId = 0; EntryId < 4; EntryId++) {
 +                      MacAddr = CAM_CONST_ADDR[EntryId];
 +                      setKey(dev, EntryId, EntryId,
 +                             priv->ieee80211->pairwise_key_type,
 +                             MacAddr, 0, NULL);
                }
  
 -      }
 -      else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP)
 -      {
 +      } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP) {
  
 -              {
 -                      if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 -                              setKey(dev,
 -                                              4,
 -                                              0,
 -                                              priv->ieee80211->pairwise_key_type,
 -                                              (u8*)dev->dev_addr,
 -                                              0,
 -                                              NULL);
 -                      else
 -                              setKey(dev,
 -                                              4,
 -                                              0,
 -                                              priv->ieee80211->pairwise_key_type,
 -                                              MacAddr,
 -                                              0,
 -                                              NULL);
 -              }
 -      }
 -      else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)
 -      {
 +              if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 +                      setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
 +                             (u8 *)dev->dev_addr, 0, NULL);
 +              else
 +                      setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
 +                             MacAddr, 0, NULL);
 +      } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP) {
  
 -              {
 -                      if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 -                              setKey(dev,
 -                                              4,
 -                                              0,
 -                                              priv->ieee80211->pairwise_key_type,
 -                                              (u8*)dev->dev_addr,
 -                                              0,
 -                                              NULL);
 -                      else
 -                              setKey(dev,
 -                                              4,
 -                                              0,
 -                                              priv->ieee80211->pairwise_key_type,
 -                                              MacAddr,
 -                                              0,
 -                                              NULL);
 -              }
 +              if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 +                      setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
 +                             (u8 *)dev->dev_addr, 0, NULL);
 +              else
 +                      setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
 +                             MacAddr, 0, NULL);
        }
  
  
  
 -      if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP)
 -      {
 +      if (priv->ieee80211->group_key_type == KEY_TYPE_TKIP) {
                MacAddr = CAM_CONST_BROAD;
 -              for(EntryId=1 ; EntryId<4 ; EntryId++)
 -              {
 -                      {
 -                              setKey(dev,
 -                                              EntryId,
 -                                              EntryId,
 -                                              priv->ieee80211->group_key_type,
 -                                              MacAddr,
 -                                              0,
 -                                              NULL);
 -                      }
 +              for (EntryId = 1; EntryId < 4; EntryId++) {
 +                      setKey(dev, EntryId, EntryId,
 +                             priv->ieee80211->group_key_type,
 +                             MacAddr, 0, NULL);
                }
 -              if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 -                              setKey(dev,
 -                                              0,
 -                                              0,
 -                                              priv->ieee80211->group_key_type,
 -                                              CAM_CONST_ADDR[0],
 -                                              0,
 -                                              NULL);
 -      }
 -      else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP)
 -      {
 +              if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 +                      setKey(dev, 0, 0, priv->ieee80211->group_key_type,
 +                             CAM_CONST_ADDR[0], 0, NULL);
 +      } else if (priv->ieee80211->group_key_type == KEY_TYPE_CCMP) {
                MacAddr = CAM_CONST_BROAD;
 -              for(EntryId=1; EntryId<4 ; EntryId++)
 -              {
 -                      {
 -                              setKey(dev,
 -                                              EntryId ,
 -                                              EntryId,
 -                                              priv->ieee80211->group_key_type,
 -                                              MacAddr,
 -                                              0,
 -                                              NULL);
 -                      }
 +              for (EntryId = 1; EntryId < 4; EntryId++) {
 +                      setKey(dev, EntryId, EntryId,
 +                             priv->ieee80211->group_key_type,
 +                             MacAddr, 0, NULL);
                }
  
 -              if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 -                              setKey(dev,
 -                                              0 ,
 -                                              0,
 -                                              priv->ieee80211->group_key_type,
 -                                              CAM_CONST_ADDR[0],
 -                                              0,
 -                                              NULL);
 +              if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 +                      setKey(dev, 0, 0, priv->ieee80211->group_key_type,
 +                             CAM_CONST_ADDR[0], 0, NULL);
        }
  }
  //////////////////////////////////////////////////////////////
  // The method checking Tx/Rx stuck of this function is supported by FW,
  // which reports Tx and Rx counter to register 0x128 and 0x130.
  //////////////////////////////////////////////////////////////
 -void
 -rtl819x_ifsilentreset(struct net_device *dev)
 +void rtl819x_ifsilentreset(struct net_device *dev)
  {
 -      //OCTET_STRING asocpdu;
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8      reset_times = 0;
        int reset_status = 0;
        // 2007.07.20. If we need to check CCK stop, please uncomment this line.
        //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
  
 -      if(priv->ResetProgress==RESET_TYPE_NORESET)
 -      {
 +      if (priv->ResetProgress == RESET_TYPE_NORESET) {
  RESET_START:
  
 -              RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
 +              RT_TRACE(COMP_RESET, "=========>Reset progress!! \n");
  
                // Set the variable for reset.
                priv->ResetProgress = RESET_TYPE_SILENT;
 -//            rtl8192_close(dev);
                down(&priv->wx_sem);
 -              if(priv->up == 0)
 -              {
 -                      RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__);
 +              if (priv->up == 0) {
 +                      RT_TRACE(COMP_ERR, "%s():the driver is not up! return\n", __func__);
                        up(&priv->wx_sem);
 -                      return ;
 +                      return;
                }
                priv->up = 0;
 -              RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__);
 -//            if(!netif_queue_stopped(dev))
 -//                    netif_stop_queue(dev);
 +              RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n", __func__);
  
                rtl8192_rtx_disable(dev);
                rtl8192_cancel_deferred_work(priv);
                del_timer_sync(&priv->watch_dog_timer);
  
                ieee->sync_scan_hurryup = 1;
 -              if(ieee->state == IEEE80211_LINKED)
 -              {
 +              if (ieee->state == IEEE80211_LINKED) {
                        down(&ieee->wx_sem);
 -                      printk("ieee->state is IEEE80211_LINKED\n");
 +                      netdev_dbg(dev, "ieee->state is IEEE80211_LINKED\n");
                        ieee80211_stop_send_beacons(priv->ieee80211);
                        del_timer_sync(&ieee->associate_timer);
                        cancel_delayed_work(&ieee->associate_retry_wq);
                        ieee80211_stop_scan(ieee);
                        netif_carrier_off(dev);
                        up(&ieee->wx_sem);
 +              } else {
 +                      netdev_dbg(dev, "ieee->state is NOT LINKED\n");
 +                      ieee80211_softmac_stop_protocol(priv->ieee80211);
                }
 -              else{
 -                      printk("ieee->state is NOT LINKED\n");
 -                      ieee80211_softmac_stop_protocol(priv->ieee80211);                       }
                up(&priv->wx_sem);
 -              RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
 -      //rtl8192_irq_disable(dev);
 -              RT_TRACE(COMP_RESET,"%s():===========>start up the driver\n",__FUNCTION__);
 +              RT_TRACE(COMP_RESET, "%s():<==========down process is finished\n", __func__);
 +              RT_TRACE(COMP_RESET, "%s():===========>start up the driver\n", __func__);
                reset_status = _rtl8192_up(dev);
  
 -              RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
 -              if(reset_status == -EAGAIN)
 -              {
 -                      if(reset_times < 3)
 -                      {
 +              RT_TRACE(COMP_RESET, "%s():<===========up process is finished\n", __func__);
 +              if (reset_status == -EAGAIN) {
 +                      if (reset_times < 3) {
                                reset_times++;
                                goto RESET_START;
 -                      }
 -                      else
 -                      {
 -                              RT_TRACE(COMP_ERR," ERR!!! %s():  Reset Failed!!\n", __FUNCTION__);
 +                      } else {
 +                              RT_TRACE(COMP_ERR, " ERR!!! %s():  Reset Failed!!\n", __func__);
                        }
                }
                ieee->is_silent_reset = 1;
                EnableHWSecurityConfig8192(dev);
 -              if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
 -              {
 +              if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
                        ieee->set_chan(ieee->dev, ieee->current_network.channel);
  
                        queue_work(ieee->wq, &ieee->associate_complete_wq);
  
 -              }
 -              else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC)
 -              {
 +              } else if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC) {
                        ieee->set_chan(ieee->dev, ieee->current_network.channel);
                        ieee->link_change(ieee->dev);
  
 -              //      notify_wx_assoc_event(ieee);
 -
                        ieee80211_start_send_beacons(ieee);
  
                        if (ieee->data_hard_resume)
                priv->ResetProgress = RESET_TYPE_NORESET;
                priv->reset_count++;
  
 -              priv->bForcedSilentReset =false;
 +              priv->bForcedSilentReset = false;
                priv->bResetInProgress = false;
  
                // For test --> force write UFWP.
        }
  }
  
 -void CAM_read_entry(
 -      struct net_device *dev,
 -      u32                     iIndex
 -)
 +void CAM_read_entry(struct net_device *dev, u32 iIndex)
  {
 -      u32 target_command=0;
 -       u32 target_content=0;
 -       u8 entry_i=0;
 -       u32 ulStatus;
 -      s32 i=100;
 -//    printk("=======>start read CAM\n");
 -      for(entry_i=0;entry_i<CAM_CONTENT_COUNT;entry_i++)
 -      {
 -      // polling bit, and No Write enable, and address
 -              target_command= entry_i+CAM_CONTENT_COUNT*iIndex;
 -              target_command= target_command | BIT31;
 +      u32 target_command = 0;
 +      u32 target_content = 0;
 +      u8 entry_i = 0;
 +      u32 ulStatus;
 +      s32 i = 100;
 +      for (entry_i = 0; entry_i < CAM_CONTENT_COUNT; entry_i++) {
 +              // polling bit, and No Write enable, and address
 +              target_command = entry_i+CAM_CONTENT_COUNT*iIndex;
 +              target_command = target_command | BIT31;
  
 -      //Check polling bit is clear
 -//    mdelay(1);
 -              while((i--)>=0)
 -              {
 -                      ulStatus = read_nic_dword(dev, RWCAM);
 -                      if(ulStatus & BIT31){
 +              //Check polling bit is clear
 +              while ((i--) >= 0) {
 +                      read_nic_dword(dev, RWCAM, &ulStatus);
 +                      if (ulStatus & BIT31)
                                continue;
 -                      }
 -                      else{
 +                      else
                                break;
 -                      }
                }
                write_nic_dword(dev, RWCAM, target_command);
 -              RT_TRACE(COMP_SEC,"CAM_read_entry(): WRITE A0: %x \n",target_command);
 -       //     printk("CAM_read_entry(): WRITE A0: %lx \n",target_command);
 -              target_content = read_nic_dword(dev, RCAMO);
 -              RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A8: %x \n",target_content);
 -       //     printk("CAM_read_entry(): WRITE A8: %lx \n",target_content);
 +              RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A0: %x \n", target_command);
 +              read_nic_dword(dev, RCAMO, &target_content);
 +              RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A8: %x \n", target_content);
        }
        printk("\n");
  }
  
 -void rtl819x_update_rxcounts(
 -      struct r8192_priv *priv,
 -      u32* TotalRxBcnNum,
 -      u32* TotalRxDataNum
 -)
 +void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
 +                           u32 *TotalRxDataNum)
  {
        u16                     SlotIndex;
        u8                      i;
        SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
        priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
        priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
 -      for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){
 +      for (i = 0; i < priv->ieee80211->LinkDetectInfo.SlotNum; i++) {
                *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
                *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
        }
  }
  
  
 -extern        void    rtl819x_watchdog_wqcallback(struct work_struct *work)
 +extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
  {
 -      struct delayed_work *dwork = container_of(work,struct delayed_work,work);
 -       struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq);
 -       struct net_device *dev = priv->ieee80211->dev;
 -      struct ieee80211_deviceieee = priv->ieee80211;
 +      struct delayed_work *dwork = container_of(work, struct delayed_work, work);
 +      struct r8192_priv *priv = container_of(dwork, struct r8192_priv, watch_dog_wq);
 +      struct net_device *dev = priv->ieee80211->dev;
 +      struct ieee80211_device *ieee = priv->ieee80211;
        RESET_TYPE      ResetType = RESET_TYPE_NORESET;
        static u8       check_reset_cnt;
        bool bBusyTraffic = false;
 +      u32     TotalRxBcnNum = 0;
 +      u32     TotalRxDataNum = 0;
  
 -      if(!priv->up)
 +      if (!priv->up)
                return;
        hal_dm_watchdog(dev);
  
 -      {//to get busy traffic condition
 -              if(ieee->state == IEEE80211_LINKED)
 -              {
 -                      if(     ieee->LinkDetectInfo.NumRxOkInPeriod> 666 ||
 -                              ieee->LinkDetectInfo.NumTxOkInPeriod> 666 ) {
 -                              bBusyTraffic = true;
 -                      }
 -                      ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
 -                      ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
 -                      ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
 +      //to get busy traffic condition
 +      if (ieee->state == IEEE80211_LINKED) {
 +              if (ieee->LinkDetectInfo.NumRxOkInPeriod > 666 ||
 +                  ieee->LinkDetectInfo.NumTxOkInPeriod > 666 ) {
 +                      bBusyTraffic = true;
                }
 +              ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
 +              ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
 +              ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
        }
        //added by amy for AP roaming
 -      {
 -              if(priv->ieee80211->state == IEEE80211_LINKED && priv->ieee80211->iw_mode == IW_MODE_INFRA)
 -              {
 -                      u32     TotalRxBcnNum = 0;
 -                      u32     TotalRxDataNum = 0;
 +      if (priv->ieee80211->state == IEEE80211_LINKED && priv->ieee80211->iw_mode == IW_MODE_INFRA) {
  
 -                      rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
 -                      if((TotalRxBcnNum+TotalRxDataNum) == 0)
 -                      {
 -                              #ifdef TODO
 -                              if(rfState == eRfOff)
 -                                      RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__);
 -                              #endif
 -                              printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__);
 -                      //      Dot11d_Reset(dev);
 -                              priv->ieee80211->state = IEEE80211_ASSOCIATING;
 -                              notify_wx_assoc_event(priv->ieee80211);
 -                              RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid);
 -                              priv->ieee80211->link_change(dev);
 -                              queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
 +              rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
 +              if ((TotalRxBcnNum+TotalRxDataNum) == 0) {
 +#ifdef TODO
 +                      if (rfState == eRfOff)
 +                              RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
 +#endif
 +                      netdev_dbg(dev, "===>%s(): AP is power off, connect another one\n", __func__);
 +                      priv->ieee80211->state = IEEE80211_ASSOCIATING;
 +                      notify_wx_assoc_event(priv->ieee80211);
 +                      RemovePeerTS(priv->ieee80211, priv->ieee80211->current_network.bssid);
 +                      priv->ieee80211->link_change(dev);
 +                      queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
  
 -                      }
                }
 -              priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod=0;
 -              priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod=0;
        }
 -//    CAM_read_entry(dev,4);
 +      priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod = 0;
 +      priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod = 0;
        //check if reset the driver
 -      if(check_reset_cnt++ >= 3)
 -      {
 +      if (check_reset_cnt++ >= 3) {
                ResetType = rtl819x_ifcheck_resetornot(dev);
                check_reset_cnt = 3;
 -              //DbgPrint("Start to check silent reset\n");
        }
 -      //      RT_TRACE(COMP_RESET,"%s():priv->force_reset is %d,priv->ResetProgress is %d, priv->bForcedSilentReset is %d,priv->bDisableNormalResetCheck is %d,ResetType is %d\n",__FUNCTION__,priv->force_reset,priv->ResetProgress,priv->bForcedSilentReset,priv->bDisableNormalResetCheck,ResetType);
 -      if( (priv->force_reset) || (priv->ResetProgress==RESET_TYPE_NORESET &&
 -              (priv->bForcedSilentReset ||
 -              (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT)))) // This is control by OID set in Pomelo
 -      {
 -              RT_TRACE(COMP_RESET,"%s():priv->force_reset is %d,priv->ResetProgress is %d, priv->bForcedSilentReset is %d,priv->bDisableNormalResetCheck is %d,ResetType is %d\n",__FUNCTION__,priv->force_reset,priv->ResetProgress,priv->bForcedSilentReset,priv->bDisableNormalResetCheck,ResetType);
 +      if ((priv->force_reset) || (priv->ResetProgress == RESET_TYPE_NORESET &&
 +          (priv->bForcedSilentReset ||
 +          (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_SILENT)))) { // This is control by OID set in Pomelo
 +              RT_TRACE(COMP_RESET, "%s():priv->force_reset is %d,priv->ResetProgress is %d, priv->bForcedSilentReset is %d,priv->bDisableNormalResetCheck is %d,ResetType is %d\n", __func__, priv->force_reset, priv->ResetProgress, priv->bForcedSilentReset, priv->bDisableNormalResetCheck, ResetType);
                rtl819x_ifsilentreset(dev);
        }
        priv->force_reset = false;
  void watch_dog_timer_callback(unsigned long data)
  {
        struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
 -      //printk("===============>watch_dog timer\n");
 -      queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq, 0);
 +      queue_delayed_work(priv->priv_wq, &priv->watch_dog_wq, 0);
        mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
  }
  int _rtl8192_up(struct net_device *dev)
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      //int i;
        int init_status = 0;
 -      priv->up=1;
 -      priv->ieee80211->ieee_up=1;
 +      priv->up = 1;
 +      priv->ieee80211->ieee_up = 1;
        RT_TRACE(COMP_INIT, "Bringing up iface");
        init_status = rtl8192_adapter_start(dev);
 -      if(!init_status)
 -      {
 -              RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization failed!\n", __FUNCTION__);
 -              priv->up=priv->ieee80211->ieee_up = 0;
 +      if (!init_status) {
 +              RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization failed!\n", __func__);
 +              priv->up = priv->ieee80211->ieee_up = 0;
                return -EAGAIN;
        }
        RT_TRACE(COMP_INIT, "start adapter finished\n");
        rtl8192_rx_enable(dev);
 -//    rtl8192_tx_enable(dev);
 -      if(priv->ieee80211->state != IEEE80211_LINKED)
 -      ieee80211_softmac_start_protocol(priv->ieee80211);
 +      if (priv->ieee80211->state != IEEE80211_LINKED)
 +              ieee80211_softmac_start_protocol(priv->ieee80211);
        ieee80211_reset_queue(priv->ieee80211);
        watch_dog_timer_callback((unsigned long) dev);
 -      if(!netif_queue_stopped(dev))
 +      if (!netif_queue_stopped(dev))
                netif_start_queue(dev);
        else
                netif_wake_queue(dev);
@@@ -3685,35 -4172,40 +3685,35 @@@ int rtl8192_down(struct net_device *dev
  
        if (priv->up == 0) return -1;
  
 -      priv->up=0;
 +      priv->up = 0;
        priv->ieee80211->ieee_up = 0;
 -      RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__);
 -/* FIXME */
 +      RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
 +      /* FIXME */
        if (!netif_queue_stopped(dev))
                netif_stop_queue(dev);
  
        rtl8192_rtx_disable(dev);
 -      //rtl8192_irq_disable(dev);
  
 - /* Tx related queue release */
 -      for(i = 0; i < MAX_QUEUE_SIZE; i++) {
 -              skb_queue_purge(&priv->ieee80211->skb_waitQ [i]);
 -      }
 -      for(i = 0; i < MAX_QUEUE_SIZE; i++) {
 -              skb_queue_purge(&priv->ieee80211->skb_aggQ [i]);
 -      }
 +      /* Tx related queue release */
 +      for (i = 0; i < MAX_QUEUE_SIZE; i++)
 +              skb_queue_purge(&priv->ieee80211->skb_waitQ[i]);
 +      for (i = 0; i < MAX_QUEUE_SIZE; i++)
 +              skb_queue_purge(&priv->ieee80211->skb_aggQ[i]);
  
 -      for(i = 0; i < MAX_QUEUE_SIZE; i++) {
 -              skb_queue_purge(&priv->ieee80211->skb_drv_aggQ [i]);
 -      }
 +      for (i = 0; i < MAX_QUEUE_SIZE; i++)
 +              skb_queue_purge(&priv->ieee80211->skb_drv_aggQ[i]);
  
        //as cancel_delayed_work will del work->timer, so if work is not defined as struct delayed_work, it will corrupt
 -//    flush_scheduled_work();
        rtl8192_cancel_deferred_work(priv);
        deinit_hal_dm(dev);
        del_timer_sync(&priv->watch_dog_timer);
  
  
        ieee80211_softmac_stop_protocol(priv->ieee80211);
 -      memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list));
 -      RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__);
 +      memset(&priv->ieee80211->current_network, 0, offsetof(struct ieee80211_network, list));
 +      RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
  
 -              return 0;
 +      return 0;
  }
  
  
@@@ -3721,19 -4213,27 +3721,19 @@@ void rtl8192_commit(struct net_device *
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
        int reset_status = 0;
 -      //u8 reset_times = 0;
 -      if (priv->up == 0) return ;
 +      if (priv->up == 0) return;
        priv->up = 0;
  
        rtl8192_cancel_deferred_work(priv);
        del_timer_sync(&priv->watch_dog_timer);
 -      //cancel_delayed_work(&priv->SwChnlWorkItem);
  
        ieee80211_softmac_stop_protocol(priv->ieee80211);
  
 -      //rtl8192_irq_disable(dev);
        rtl8192_rtx_disable(dev);
        reset_status = _rtl8192_up(dev);
  
  }
  
 -/*
 -void rtl8192_restart(struct net_device *dev)
 -{
 -      struct r8192_priv *priv = ieee80211_priv(dev);
 -*/
  void rtl8192_restart(struct work_struct *work)
  {
        struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
@@@ -3751,13 -4251,19 +3751,13 @@@ static void r8192_set_multicast(struct 
        struct r8192_priv *priv = ieee80211_priv(dev);
        short promisc;
  
 -      //down(&priv->wx_sem);
 -
        /* FIXME FIXME */
  
 -      promisc = (dev->flags & IFF_PROMISC) ? 1:0;
 +      promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
  
        if (promisc != priv->promisc)
 -      //      rtl8192_commit(dev);
  
 -      priv->promisc = promisc;
 -
 -      //schedule_work(&priv->reset_wq);
 -      //up(&priv->wx_sem);
 +              priv->promisc = promisc;
  }
  
  
@@@ -3781,90 -4287,99 +3781,90 @@@ int rtl8192_ioctl(struct net_device *de
  {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct iwreq *wrq = (struct iwreq *)rq;
 -      int ret=-1;
 +      int ret = -1;
        struct ieee80211_device *ieee = priv->ieee80211;
        u32 key[4];
 -      u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
 +      u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
        struct iw_point *p = &wrq->u.data;
 -      struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer;
 +      struct ieee_param *ipw = NULL;
  
        down(&priv->wx_sem);
  
  
 -     if (p->length < sizeof(struct ieee_param) || !p->pointer){
 -           ret = -EINVAL;
 -           goto out;
 +      if (p->length < sizeof(struct ieee_param) || !p->pointer) {
 +              ret = -EINVAL;
 +              goto out;
        }
  
 -     ipw = kmalloc(p->length, GFP_KERNEL);
 -     if (ipw == NULL){
 -           ret = -ENOMEM;
 -           goto out;
 -     }
 -     if (copy_from_user(ipw, p->pointer, p->length)) {
 +      ipw = kmalloc(p->length, GFP_KERNEL);
 +      if (ipw == NULL) {
 +              ret = -ENOMEM;
 +              goto out;
 +      }
 +      if (copy_from_user(ipw, p->pointer, p->length)) {
                kfree(ipw);
 -          ret = -EFAULT;
 -          goto out;
 +              ret = -EFAULT;
 +              goto out;
        }
  
        switch (cmd) {
        case RTL_IOCTL_WPA_SUPPLICANT:
 -      //parse here for HW security
 -              if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
 -              {
 -                      if (ipw->u.crypt.set_tx)
 -                      {
 -                              if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
 +              //parse here for HW security
 +              if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
 +                      if (ipw->u.crypt.set_tx) {
 +                              if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
                                        ieee->pairwise_key_type = KEY_TYPE_CCMP;
 -                              else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
 +                              } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
                                        ieee->pairwise_key_type = KEY_TYPE_TKIP;
 -                              else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
 -                              {
 +                              } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
                                        if (ipw->u.crypt.key_len == 13)
                                                ieee->pairwise_key_type = KEY_TYPE_WEP104;
                                        else if (ipw->u.crypt.key_len == 5)
                                                ieee->pairwise_key_type = KEY_TYPE_WEP40;
 -                              }
 -                              else
 +                              } else {
                                        ieee->pairwise_key_type = KEY_TYPE_NA;
 +                              }
  
 -                              if (ieee->pairwise_key_type)
 -                              {
 -                                      memcpy((u8*)key, ipw->u.crypt.key, 16);
 +                              if (ieee->pairwise_key_type) {
 +                                      memcpy((u8 *)key, ipw->u.crypt.key, 16);
                                        EnableHWSecurityConfig8192(dev);
 -                              //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
 -                              //added by WB.
 -                                      setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
 +                                      //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
 +                                      //added by WB.
 +                                      setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
                                        if (ieee->auth_mode != 2)
 -                                      setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
 +                                              setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
                                }
 -                      }
 -                      else //if (ipw->u.crypt.idx) //group key use idx > 0
 -                      {
 -                              memcpy((u8*)key, ipw->u.crypt.key, 16);
 -                              if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
 -                                      ieee->group_key_type= KEY_TYPE_CCMP;
 -                              else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
 +                      } else {
 +                              memcpy((u8 *)key, ipw->u.crypt.key, 16);
 +                              if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
 +                                      ieee->group_key_type = KEY_TYPE_CCMP;
 +                              } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
                                        ieee->group_key_type = KEY_TYPE_TKIP;
 -                              else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
 -                              {
 +                              } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
                                        if (ipw->u.crypt.key_len == 13)
                                                ieee->group_key_type = KEY_TYPE_WEP104;
                                        else if (ipw->u.crypt.key_len == 5)
                                                ieee->group_key_type = KEY_TYPE_WEP40;
 -                              }
 -                              else
 +                              } else {
                                        ieee->group_key_type = KEY_TYPE_NA;
 +                              }
  
 -                              if (ieee->group_key_type)
 -                              {
 -                                              setKey( dev,
 -                                                      ipw->u.crypt.idx,
 -                                                      ipw->u.crypt.idx,               //KeyIndex
 -                                                      ieee->group_key_type,   //KeyType
 -                                                      broadcast_addr, //MacAddr
 -                                                      0,              //DefaultKey
 -                                                      key);           //KeyContent
 +                              if (ieee->group_key_type) {
 +                                      setKey(dev, ipw->u.crypt.idx,
 +                                             ipw->u.crypt.idx,                //KeyIndex
 +                                             ieee->group_key_type,    //KeyType
 +                                             broadcast_addr,  //MacAddr
 +                                             0,               //DefaultKey
 +                                             key);            //KeyContent
                                }
                        }
                }
  #ifdef JOHN_HWSEC_DEBUG
                //john's test 0711
                printk("@@ wrq->u pointer = ");
 -              for(i=0;i<wrq->u.data.length;i++){
 -                      if(i%10==0) printk("\n");
 -                      printk( "%8x|", ((u32*)wrq->u.data.pointer)[i] );
 +              for (i = 0; i < wrq->u.data.length; i++) {
 +                      if (i%10 == 0) printk("\n");
 +                      printk("%8x|", ((u32 *)wrq->u.data.pointer)[i]);
                }
                printk("\n");
  #endif /*JOHN_HWSEC_DEBUG*/
@@@ -3886,8 -4401,8 +3886,8 @@@ u8 HwRateToMRate90(bool bIsHT, u8 rate
  {
        u8  ret_rate = 0xff;
  
 -      if(!bIsHT) {
 -              switch(rate) {
 +      if (!bIsHT) {
 +              switch (rate) {
                case DESC90_RATE1M:   ret_rate = MGN_1M;         break;
                case DESC90_RATE2M:   ret_rate = MGN_2M;         break;
                case DESC90_RATE5_5M: ret_rate = MGN_5_5M;       break;
                }
  
        } else {
 -              switch(rate) {
 +              switch (rate) {
                case DESC90_RATEMCS0:   ret_rate = MGN_MCS0;    break;
                case DESC90_RATEMCS1:   ret_rate = MGN_MCS1;    break;
                case DESC90_RATEMCS2:   ret_rate = MGN_MCS2;    break;
  
                default:
                        ret_rate = 0xff;
 -                      RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT);
 +                      RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
                        break;
                }
        }
   * Return:
   *               None
   */
 -void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats)
 +void UpdateRxPktTimeStamp8190(struct net_device *dev, struct ieee80211_rx_stats *stats)
  {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  
 -      if(stats->bIsAMPDU && !stats->bFirstMPDU) {
 +      if (stats->bIsAMPDU && !stats->bFirstMPDU) {
                stats->mac_time[0] = priv->LastRxDescTSFLow;
                stats->mac_time[1] = priv->LastRxDescTSFHigh;
        } else {
  
  //by amy 080606
  
 -long rtl819x_translate_todbm(u8 signal_strength_index )// 0-100 index.
 +long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
  {
        long    signal_power; // in dBm.
  
      be a local static. Otherwise, it may increase when we return from S3/S4. The
      value will be kept in memory or disk. Declare the value in the adaptor
      and it will be reinitialized when returned from S3/S4. */
 -void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats)
 +void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer, struct ieee80211_rx_stats *pprevious_stats, struct ieee80211_rx_stats *pcurrent_stats)
  {
        bool bcheck = false;
        u8      rfpath;
        u32     nspatial_stream, tmp_val;
 -      //u8    i;
        static u32 slide_rssi_index, slide_rssi_statistics;
        static u32 slide_evm_index, slide_evm_statistics;
        static u32 last_rssi, last_evm;
        static u32 last_beacon_adc_pwdb;
  
        struct ieee80211_hdr_3addr *hdr;
 -      u16 sc ;
 -      unsigned int frag,seq;
 +      u16 sc;
 +      unsigned int frag, seq;
        hdr = (struct ieee80211_hdr_3addr *)buffer;
        sc = le16_to_cpu(hdr->seq_ctl);
        frag = WLAN_GET_SEQ_FRAG(sc);
        //
        // Check whether we should take the previous packet into accounting
        //
 -      if(!pprevious_stats->bIsAMPDU)
 -      {
 +      if (!pprevious_stats->bIsAMPDU) {
                // if previous packet is not aggregated packet
                bcheck = true;
        }
  
 -      if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
 -      {
 +      if (slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
                slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
                last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
                priv->stats.slide_rssi_total -= last_rssi;
        priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
  
        priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
 -      if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
 +      if (slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
                slide_rssi_index = 0;
  
        // <1> Showed on UI for user, in dbm
        //
        // If the previous packet does not match the criteria, neglect it
        //
 -      if(!pprevious_stats->bPacketMatchBSSID)
 -      {
 -              if(!pprevious_stats->bToSelfBA)
 +      if (!pprevious_stats->bPacketMatchBSSID) {
 +              if (!pprevious_stats->bToSelfBA)
                        return;
        }
  
 -      if(!bcheck)
 +      if (!bcheck)
                return;
  
  
  
        // <2> Showed on UI for engineering
        // hardware does not provide rssi information for each rf path in CCK
 -      if(!pprevious_stats->bIsCCK && (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA))
 -      {
 -              for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++)
 -              {
 -                   if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
 -                               continue;
 +      if (!pprevious_stats->bIsCCK && (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA)) {
 +              for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++) {
 +                      if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
 +                              continue;
  
                        //Fixed by Jacken 2008-03-20
 -                      if(priv->stats.rx_rssi_percentage[rfpath] == 0)
 -                      {
 +                      if (priv->stats.rx_rssi_percentage[rfpath] == 0)
                                priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
 -                              //DbgPrint("MIMO RSSI initialize \n");
 -                      }
 -                      if(pprevious_stats->RxMIMOSignalStrength[rfpath]  > priv->stats.rx_rssi_percentage[rfpath])
 -                      {
 +                      if (pprevious_stats->RxMIMOSignalStrength[rfpath]  > priv->stats.rx_rssi_percentage[rfpath]) {
                                priv->stats.rx_rssi_percentage[rfpath] =
 -                                      ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
 -                                      (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
 +                                      ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
 +                                       (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
                                priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath]  + 1;
 -                      }
 -                      else
 -                      {
 +                      } else {
                                priv->stats.rx_rssi_percentage[rfpath] =
 -                                      ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
 -                                      (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
 +                                      ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
 +                                       (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
                        }
 -                      RT_TRACE(COMP_DBG,"priv->stats.rx_rssi_percentage[rfPath]  = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] );
 +                      RT_TRACE(COMP_DBG, "priv->stats.rx_rssi_percentage[rfPath]  = %d \n", priv->stats.rx_rssi_percentage[rfpath]);
                }
        }
  
        // Check PWDB.
        //
        RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
 -                              pprevious_stats->bIsCCK? "CCK": "OFDM",
 -                              pprevious_stats->RxPWDBAll);
 +               pprevious_stats->bIsCCK ? "CCK" : "OFDM",
 +               pprevious_stats->RxPWDBAll);
  
 -      if(pprevious_stats->bPacketBeacon)
 -      {
 -/* record the beacon pwdb to the sliding window. */
 -              if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX)
 -              {
 +      if (pprevious_stats->bPacketBeacon) {
 +              /* record the beacon pwdb to the sliding window. */
 +              if (slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX) {
                        slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
                        last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
                        priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
 -                      //DbgPrint("slide_beacon_adc_pwdb_index = %d, last_beacon_adc_pwdb = %d, Adapter->RxStats.Slide_Beacon_Total = %d\n",
 -                      //      slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total);
                }
                priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
                priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
 -              //DbgPrint("slide_beacon_adc_pwdb_index = %d, pPreviousRfd->Status.RxPWDBAll = %d\n", slide_beacon_adc_pwdb_index, pPreviousRfd->Status.RxPWDBAll);
                slide_beacon_adc_pwdb_index++;
 -              if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
 +              if (slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
                        slide_beacon_adc_pwdb_index = 0;
                pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
 -              if(pprevious_stats->RxPWDBAll >= 3)
 +              if (pprevious_stats->RxPWDBAll >= 3)
                        pprevious_stats->RxPWDBAll -= 3;
        }
  
        RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
 -                              pprevious_stats->bIsCCK? "CCK": "OFDM",
 -                              pprevious_stats->RxPWDBAll);
 +               pprevious_stats->bIsCCK ? "CCK" : "OFDM",
 +               pprevious_stats->RxPWDBAll);
  
  
 -      if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
 -      {
 -              if(priv->undecorated_smoothed_pwdb < 0) // initialize
 -              {
 +      if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
 +              if (priv->undecorated_smoothed_pwdb < 0)        // initialize
                        priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
 -                      //DbgPrint("First pwdb initialize \n");
 -              }
 -              if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb)
 -              {
 +              if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) {
                        priv->undecorated_smoothed_pwdb =
 -                                      ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
 -                                      (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
 +                              (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
 +                               (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
                        priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
 -              }
 -              else
 -              {
 +              } else {
                        priv->undecorated_smoothed_pwdb =
 -                                      ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
 -                                      (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
 +                              (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
 +                               (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
                }
  
        }
        // Check EVM
        //
        /* record the general EVM to the sliding window. */
 -      if(pprevious_stats->SignalQuality == 0)
 -      {
 -      }
 -      else
 -      {
 -              if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){
 -                      if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){
 +      if (pprevious_stats->SignalQuality) {
 +              if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
 +                      if (slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
                                slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
                                last_evm = priv->stats.slide_evm[slide_evm_index];
                                priv->stats.slide_evm_total -= last_evm;
                        priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
  
                        priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
 -                      if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
 +                      if (slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
                                slide_evm_index = 0;
  
                        // <1> Showed on UI for user, in percentage.
                }
  
                // <2> Showed on UI for engineering
 -              if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
 -              {
 -                      for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream
 -                      {
 -                              if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1)
 -                              {
 -                                      if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
 -                                      {
 +              if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
 +                      for (nspatial_stream = 0; nspatial_stream < 2; nspatial_stream++) { // 2 spatial stream
 +                              if (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1) {
 +                                      if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
                                                priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
 -                                      }
                                        priv->stats.rx_evm_percentage[nspatial_stream] =
 -                                              ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
 -                                              (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
 +                                              ((priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
 +                                               (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
                                }
                        }
                }
   *    05/26/2008      amy             Create Version 0 porting from windows code.
   *
   *---------------------------------------------------------------------------*/
 -static u8 rtl819x_query_rxpwrpercentage(
 -      char            antpower
 -      )
 +static u8 rtl819x_query_rxpwrpercentage(char antpower)
  {
        if ((antpower <= -100) || (antpower >= 20))
 -      {
                return  0;
 -      }
        else if (antpower >= 0)
 -      {
                return  100;
 -      }
        else
 -      {
 -              return  (100+antpower);
 -      }
 +              return  100 + antpower;
  
  }     /* QueryRxPwrPercentage */
  
 -static u8
 -rtl819x_evm_dbtopercentage(
 -    char value
 -    )
 +static u8 rtl819x_evm_dbtopercentage(char value)
  {
 -    char ret_val;
 +      char ret_val;
  
 -    ret_val = value;
 +      ret_val = value;
  
 -    if(ret_val >= 0)
 -      ret_val = 0;
 -    if(ret_val <= -33)
 -      ret_val = -33;
 -    ret_val = 0 - ret_val;
 -    ret_val*=3;
 -      if(ret_val == 99)
 +      if (ret_val >= 0)
 +              ret_val = 0;
 +      if (ret_val <= -33)
 +              ret_val = -33;
 +      ret_val = 0 - ret_val;
 +      ret_val *= 3;
 +      if (ret_val == 99)
                ret_val = 100;
 -    return(ret_val);
 +      return ret_val;
  }
  //
  //    Description:
  //    We want good-looking for signal strength/quality
  //    2007/7/19 01:09, by cosa.
  //
 -long
 -rtl819x_signal_scale_mapping(
 -      long currsig
 -      )
 +long rtl819x_signal_scale_mapping(long currsig)
  {
        long retsig;
  
        // Step 1. Scale mapping.
 -      if(currsig >= 61 && currsig <= 100)
 -      {
 +      if (currsig >= 61 && currsig <= 100)
                retsig = 90 + ((currsig - 60) / 4);
 -      }
 -      else if(currsig >= 41 && currsig <= 60)
 -      {
 +      else if (currsig >= 41 && currsig <= 60)
                retsig = 78 + ((currsig - 40) / 2);
 -      }
 -      else if(currsig >= 31 && currsig <= 40)
 -      {
 +      else if (currsig >= 31 && currsig <= 40)
                retsig = 66 + (currsig - 30);
 -      }
 -      else if(currsig >= 21 && currsig <= 30)
 -      {
 +      else if (currsig >= 21 && currsig <= 30)
                retsig = 54 + (currsig - 20);
 -      }
 -      else if(currsig >= 5 && currsig <= 20)
 -      {
 +      else if (currsig >= 5 && currsig <= 20)
                retsig = 42 + (((currsig - 5) * 2) / 3);
 -      }
 -      else if(currsig == 4)
 -      {
 +      else if (currsig == 4)
                retsig = 36;
 -      }
 -      else if(currsig == 3)
 -      {
 +      else if (currsig == 3)
                retsig = 27;
 -      }
 -      else if(currsig == 2)
 -      {
 +      else if (currsig == 2)
                retsig = 18;
 -      }
 -      else if(currsig == 1)
 -      {
 +      else if (currsig == 1)
                retsig = 9;
 -      }
        else
 -      {
                retsig = currsig;
 -      }
  
        return retsig;
  }
  
 -static void rtl8192_query_rxphystatus(
 -      struct r8192_priv * priv,
 -      struct ieee80211_rx_stats * pstats,
 -      rx_drvinfo_819x_usb  * pdrvinfo,
 -      struct ieee80211_rx_stats * precord_stats,
 -      bool bpacket_match_bssid,
 -      bool bpacket_toself,
 -      bool bPacketBeacon,
 -      bool bToSelfBA
 -      )
 -{
 -      //PRT_RFD_STATUS                pRtRfdStatus = &(pRfd->Status);
 -      phy_sts_ofdm_819xusb_t* pofdm_buf;
 -      phy_sts_cck_819xusb_t   *       pcck_buf;
 -      phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc;
 +static inline bool rx_hal_is_cck_rate(struct rx_drvinfo_819x_usb *pdrvinfo)
 +{
 +      if (pdrvinfo->RxHT)
 +              return false;
 +
 +      switch (pdrvinfo->RxRate) {
 +      case DESC90_RATE1M:
 +      case DESC90_RATE2M:
 +      case DESC90_RATE5_5M:
 +      case DESC90_RATE11M:
 +              return true;
 +      default:
 +              return false;
 +      }
 +}
 +
 +static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
 +                                    struct ieee80211_rx_stats *pstats,
 +                                    rx_drvinfo_819x_usb  *pdrvinfo,
 +                                    struct ieee80211_rx_stats *precord_stats,
 +                                    bool bpacket_match_bssid,
 +                                    bool bpacket_toself,
 +                                    bool bPacketBeacon,
 +                                    bool bToSelfBA)
 +{
 +      phy_sts_ofdm_819xusb_t *pofdm_buf;
 +      phy_sts_cck_819xusb_t   *pcck_buf;
 +      phy_ofdm_rx_status_rxsc_sgien_exintfflag *prxsc;
        u8                              *prxpkt;
        u8                              i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
 -      char                            rx_pwr[4], rx_pwr_all=0;
 -      //long                          rx_avg_pwr = 0;
 +      char                            rx_pwr[4], rx_pwr_all = 0;
        char                            rx_snrX, rx_evmX;
        u8                              evm, pwdb_all;
 -      u32                             RSSI, total_rssi=0;//, total_evm=0;
 -//    long                            signal_strength_index = 0;
 -      u8                              is_cck_rate=0;
 +      u32                             RSSI, total_rssi = 0;
 +      u8                              is_cck_rate = 0;
        u8                              rf_rx_num = 0;
 +      u8                              sq;
  
  
        priv->stats.numqry_phystatus++;
        memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
        pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
        pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
 -      pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo);
 +      pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;
        pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
        pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
  
 -      prxpkt = (u8*)pdrvinfo;
 +      prxpkt = (u8 *)pdrvinfo;
  
        /* Move pointer to the 16th bytes. Phy status start address. */
        prxpkt += sizeof(rx_drvinfo_819x_usb);
        precord_stats->RxMIMOSignalQuality[0] = -1;
        precord_stats->RxMIMOSignalQuality[1] = -1;
  
 -      if(is_cck_rate)
 -      {
 +      if (is_cck_rate) {
                //
                // (1)Hardware does not provide RSSI for CCK
                //
                //
                // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
                //
 -              u8 report;//, cck_agc_rpt;
 +              u8 report;
  
                priv->stats.numqry_phystatusCCK++;
  
 -              if(!priv->bCckHighPower)
 -              {
 +              if (!priv->bCckHighPower) {
                        report = pcck_buf->cck_agc_rpt & 0xc0;
                        report = report>>6;
 -                      switch(report)
 -                      {
 +                      switch (report) {
                                //Fixed by Jacken from Bryant 2008-03-20
                                //Original value is -38 , -26 , -14 , -2
                                //Fixed value is -35 , -23 , -11 , 6
 -                              case 0x3:
 -                                      rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
 -                                      break;
 -                              case 0x2:
 -                                      rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
 -                                      break;
 -                              case 0x1:
 -                                      rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
 -                                      break;
 -                              case 0x0:
 -                                      rx_pwr_all = 6 - (pcck_buf->cck_agc_rpt & 0x3e);
 -                                      break;
 +                      case 0x3:
 +                              rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
 +                              break;
 +                      case 0x2:
 +                              rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
 +                              break;
 +                      case 0x1:
 +                              rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
 +                              break;
 +                      case 0x0:
 +                              rx_pwr_all = 6 - (pcck_buf->cck_agc_rpt & 0x3e);
 +                              break;
                        }
 -              }
 -              else
 -              {
 +              } else {
                        report = pcck_buf->cck_agc_rpt & 0x60;
                        report = report>>5;
 -                      switch(report)
 -                      {
 -                              case 0x3:
 -                                      rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
 -                                      break;
 -                              case 0x2:
 -                                      rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
 -                                      break;
 -                              case 0x1:
 -                                      rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
 -                                      break;
 -                              case 0x0:
 -                                      rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
 -                                      break;
 +                      switch (report) {
 +                      case 0x3:
 +                              rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
 +                              break;
 +                      case 0x2:
 +                              rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
 +                              break;
 +                      case 0x1:
 +                              rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
 +                              break;
 +                      case 0x0:
 +                              rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
 +                              break;
                        }
                }
  
                //
                // (3) Get Signal Quality (EVM)
                //
 -              //if(bpacket_match_bssid)
 -              {
 -                      u8      sq;
  
 -                      if(pstats->RxPWDBAll > 40)
 -                      {
 -                              sq = 100;
 -                      }else
 -                      {
 -                              sq = pcck_buf->sq_rpt;
 +              if (pstats->RxPWDBAll > 40) {
 +                      sq = 100;
 +              } else {
 +                      sq = pcck_buf->sq_rpt;
  
 -                              if(pcck_buf->sq_rpt > 64)
 -                                      sq = 0;
 -                              else if (pcck_buf->sq_rpt < 20)
 -                                      sq = 100;
 -                              else
 -                                      sq = ((64-sq) * 100) / 44;
 -                      }
 -                      pstats->SignalQuality = precord_stats->SignalQuality = sq;
 -                      pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
 -                      pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
 +                      if (pcck_buf->sq_rpt > 64)
 +                              sq = 0;
 +                      else if (pcck_buf->sq_rpt < 20)
 +                              sq = 100;
 +                      else
 +                              sq = ((64-sq) * 100) / 44;
                }
 -      }
 -      else
 -      {
 +              pstats->SignalQuality = precord_stats->SignalQuality = sq;
 +              pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
 +              pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
 +
 +      } else {
                priv->stats.numqry_phystatusHT++;
                //
                // (1)Get RSSI for HT rate
                //
 -              for(i=RF90_PATH_A; i<priv->NumTotalRFPath; i++)
 -              {
 +              for (i = RF90_PATH_A; i < priv->NumTotalRFPath; i++) {
                        // 2008/01/30 MH we will judge RF RX path now.
                        if (priv->brfpath_rxenable[i])
                                rf_rx_num++;
                        else
                                continue;
  
 -              if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, i))
 +                      if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, i))
                                continue;
  
                        //Fixed by Jacken from Bryant 2008-03-20
                        //Get Rx snr value in DB
                        tmp_rxsnr =     pofdm_buf->rxsnr_X[i];
                        rx_snrX = (char)(tmp_rxsnr);
 -                      //rx_snrX >>= 1;
                        rx_snrX /= 2;
                        priv->stats.rxSNRdB[i] = (long)rx_snrX;
  
                        total_rssi += RSSI;
  
                        /* Record Signal Strength for next packet */
 -                      //if(bpacket_match_bssid)
 -                      {
 -                              pstats->RxMIMOSignalStrength[i] =(u8) RSSI;
 -                              precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI;
 -                      }
 +                      pstats->RxMIMOSignalStrength[i] = (u8) RSSI;
 +                      precord_stats->RxMIMOSignalStrength[i] = (u8) RSSI;
                }
  
  
                //
                //Fixed by Jacken from Bryant 2008-03-20
                //Original value is 106
 -              rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106;
 +              rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1)& 0x7f) -106;
                pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
  
                pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
                //
                // (3)EVM of HT rate
                //
 -              if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 &&
 -                      pdrvinfo->RxRate<=DESC90_RATEMCS15)
 +              if (pdrvinfo->RxHT && pdrvinfo->RxRate >= DESC90_RATEMCS8 &&
 +                  pdrvinfo->RxRate <= DESC90_RATEMCS15)
                        max_spatial_stream = 2; //both spatial stream make sense
                else
                        max_spatial_stream = 1; //only spatial stream 1 makes sense
  
 -              for(i=0; i<max_spatial_stream; i++)
 -              {
 +              for (i = 0; i < max_spatial_stream; i++) {
                        tmp_rxevm =     pofdm_buf->rxevm_X[i];
                        rx_evmX = (char)(tmp_rxevm);
  
                        rx_evmX /= 2;   //dbm
  
                        evm = rtl819x_evm_dbtopercentage(rx_evmX);
 -                      //if(bpacket_match_bssid)
 -                      {
 -                              if(i==0) // Fill value in RFD, Get the first spatial stream only
 -                                      pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
 -                              pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
 -                      }
 +                      if (i == 0) // Fill value in RFD, Get the first spatial stream only
 +                              pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
 +                      pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
                }
  
  
                /* record rx statistics for debug */
                rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
                prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
 -              if(pdrvinfo->BW)        //40M channel
 +              if (pdrvinfo->BW)       //40M channel
                        priv->stats.received_bwtype[1+prxsc->rxsc]++;
                else                            //20M channel
                        priv->stats.received_bwtype[0]++;
  
        //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
        //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
 -      if(is_cck_rate)
 -      {
 -              pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL;
 -
 -      }
 -      else
 -      {
 -              //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u8)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u8)(total_rssi/=RF90_PATH_MAX);
 +      if (is_cck_rate) {
 +              pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));
 +      } else {
                // We can judge RX path number now.
                if (rf_rx_num != 0)
 -                      pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num)));
 +                      pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi /= rf_rx_num)));
        }
  }     /* QueryRxPhyStatus8190Pci */
  
 -void
 -rtl8192_record_rxdesc_forlateruse(
 -      struct ieee80211_rx_stats *     psrc_stats,
 -      struct ieee80211_rx_stats *     ptarget_stats
 -)
 +void rtl8192_record_rxdesc_forlateruse(struct ieee80211_rx_stats *psrc_stats,
 +                                     struct ieee80211_rx_stats *ptarget_stats)
  {
        ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
        ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
  
  
  void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
 -                                 struct ieee80211_rx_stats * pstats,
 +                                 struct ieee80211_rx_stats *pstats,
                                   rx_drvinfo_819x_usb  *pdrvinfo)
  {
        // TODO: We must only check packet for current MAC address. Not finish
        rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
 -      struct net_device *dev=info->dev;
 +      struct net_device *dev = info->dev;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        bool bpacket_match_bssid, bpacket_toself;
 -      bool bPacketBeacon=FALSE, bToSelfBA=FALSE;
 +      bool bPacketBeacon = FALSE, bToSelfBA = FALSE;
        static struct ieee80211_rx_stats  previous_stats;
        struct ieee80211_hdr_3addr *hdr;//by amy
 -       u16 fc,type;
 +      u16 fc, type;
  
        // Get Signal Quality for only RX data queue (but not command queue)
  
 -      u8* tmp_buf;
 -      //u16 tmp_buf_len = 0;
 +      u8 *tmp_buf;
        u8  *praddr;
  
        /* Get MAC frame start address. */
 -      tmp_buf = (u8*)skb->data;// + get_rxpacket_shiftbytes_819xusb(pstats);
 +      tmp_buf = (u8 *)skb->data;
  
        hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
        fc = le16_to_cpu(hdr->frame_ctl);
  
        /* Check if the received packet is acceptable. */
        bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
 -                                                      (eqMacAddr(priv->ieee80211->current_network.bssid,  (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
 -                                                               && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV));
 +                             (eqMacAddr(priv->ieee80211->current_network.bssid,  (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3))
 +                             && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV));
        bpacket_toself =  bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
  
 -              if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON)
 -              {
 -                      bPacketBeacon = true;
 -                      //DbgPrint("Beacon 2, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
 -              }
 -              if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK)
 -              {
 -                      if((eqMacAddr(praddr,dev->dev_addr)))
 -                              bToSelfBA = true;
 -                              //DbgPrint("BlockAck, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
 -              }
 +      if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON)
 +              bPacketBeacon = true;
 +      if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) {
 +              if ((eqMacAddr(praddr, dev->dev_addr)))
 +                      bToSelfBA = true;
 +      }
  
  
  
 -      if(bpacket_match_bssid)
 -      {
 +      if (bpacket_match_bssid)
                priv->stats.numpacket_matchbssid++;
 -      }
 -      if(bpacket_toself){
 +      if (bpacket_toself)
                priv->stats.numpacket_toself++;
 -      }
        //
        // Process PHY information for previous packet (RSSI/PWDB/EVM)
        //
        // Because phy information is contained in the last packet of AMPDU only, so driver
        // should process phy information of previous packet
        rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
 -      rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats, bpacket_match_bssid,bpacket_toself,bPacketBeacon,bToSelfBA);
 +      rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats, bpacket_match_bssid, bpacket_toself, bPacketBeacon, bToSelfBA);
        rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
  
  }
  * Return:
  *             None
  */
 -void
 -UpdateReceivedRateHistogramStatistics8190(
 -      struct net_device *dev,
 -      struct ieee80211_rx_stats *stats
 -      )
 +void UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
 +                                             struct ieee80211_rx_stats *stats)
  {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 -      u32 rcvType=1;   //0: Total, 1:OK, 2:CRC, 3:ICV
 +      u32 rcvType = 1;   //0: Total, 1:OK, 2:CRC, 3:ICV
        u32 rateIndex;
        u32 preamble_guardinterval;  //1: short preamble/GI, 0: long preamble/GI
  
  
 -      if(stats->bCRC)
 -      rcvType = 2;
 -      else if(stats->bICV)
 -      rcvType = 3;
 +      if (stats->bCRC)
 +              rcvType = 2;
 +      else if (stats->bICV)
 +              rcvType = 3;
  
 -      if(stats->bShortPreamble)
 -      preamble_guardinterval = 1;// short
 +      if (stats->bShortPreamble)
 +              preamble_guardinterval = 1;// short
        else
 -      preamble_guardinterval = 0;// long
 +              preamble_guardinterval = 0;// long
  
 -      switch(stats->rate)
 -      {
 +      switch (stats->rate) {
                //
                // CCK rate
                //
 -              case MGN_1M:    rateIndex = 0;  break;
 -              case MGN_2M:    rateIndex = 1;  break;
 -              case MGN_5_5M:  rateIndex = 2;  break;
 -              case MGN_11M:   rateIndex = 3;  break;
 +      case MGN_1M:    rateIndex = 0;  break;
 +      case MGN_2M:    rateIndex = 1;  break;
 +      case MGN_5_5M:  rateIndex = 2;  break;
 +      case MGN_11M:   rateIndex = 3;  break;
                //
                // Legacy OFDM rate
                //
 -              case MGN_6M:    rateIndex = 4;  break;
 -              case MGN_9M:    rateIndex = 5;  break;
 -              case MGN_12M:   rateIndex = 6;  break;
 -              case MGN_18M:   rateIndex = 7;  break;
 -              case MGN_24M:   rateIndex = 8;  break;
 -              case MGN_36M:   rateIndex = 9;  break;
 -              case MGN_48M:   rateIndex = 10; break;
 -              case MGN_54M:   rateIndex = 11; break;
 +      case MGN_6M:    rateIndex = 4;  break;
 +      case MGN_9M:    rateIndex = 5;  break;
 +      case MGN_12M:   rateIndex = 6;  break;
 +      case MGN_18M:   rateIndex = 7;  break;
 +      case MGN_24M:   rateIndex = 8;  break;
 +      case MGN_36M:   rateIndex = 9;  break;
 +      case MGN_48M:   rateIndex = 10; break;
 +      case MGN_54M:   rateIndex = 11; break;
                //
                // 11n High throughput rate
                //
 -              case MGN_MCS0:  rateIndex = 12; break;
 -              case MGN_MCS1:  rateIndex = 13; break;
 -              case MGN_MCS2:  rateIndex = 14; break;
 -              case MGN_MCS3:  rateIndex = 15; break;
 -              case MGN_MCS4:  rateIndex = 16; break;
 -              case MGN_MCS5:  rateIndex = 17; break;
 -              case MGN_MCS6:  rateIndex = 18; break;
 -              case MGN_MCS7:  rateIndex = 19; break;
 -              case MGN_MCS8:  rateIndex = 20; break;
 -              case MGN_MCS9:  rateIndex = 21; break;
 -              case MGN_MCS10: rateIndex = 22; break;
 -              case MGN_MCS11: rateIndex = 23; break;
 -              case MGN_MCS12: rateIndex = 24; break;
 -              case MGN_MCS13: rateIndex = 25; break;
 -              case MGN_MCS14: rateIndex = 26; break;
 -              case MGN_MCS15: rateIndex = 27; break;
 -              default:        rateIndex = 28; break;
 -      }
 -    priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
 -    priv->stats.received_rate_histogram[0][rateIndex]++; //total
 -    priv->stats.received_rate_histogram[rcvType][rateIndex]++;
 +      case MGN_MCS0:  rateIndex = 12; break;
 +      case MGN_MCS1:  rateIndex = 13; break;
 +      case MGN_MCS2:  rateIndex = 14; break;
 +      case MGN_MCS3:  rateIndex = 15; break;
 +      case MGN_MCS4:  rateIndex = 16; break;
 +      case MGN_MCS5:  rateIndex = 17; break;
 +      case MGN_MCS6:  rateIndex = 18; break;
 +      case MGN_MCS7:  rateIndex = 19; break;
 +      case MGN_MCS8:  rateIndex = 20; break;
 +      case MGN_MCS9:  rateIndex = 21; break;
 +      case MGN_MCS10: rateIndex = 22; break;
 +      case MGN_MCS11: rateIndex = 23; break;
 +      case MGN_MCS12: rateIndex = 24; break;
 +      case MGN_MCS13: rateIndex = 25; break;
 +      case MGN_MCS14: rateIndex = 26; break;
 +      case MGN_MCS15: rateIndex = 27; break;
 +      default:        rateIndex = 28; break;
 +      }
 +      priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
 +      priv->stats.received_rate_histogram[0][rateIndex]++; //total
 +      priv->stats.received_rate_histogram[rcvType][rateIndex]++;
  }
  
  
  void query_rxdesc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats, bool bIsRxAggrSubframe)
  {
        rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
 -      struct net_device *dev=info->dev;
 +      struct net_device *dev = info->dev;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 -      //rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
        rx_drvinfo_819x_usb  *driver_info = NULL;
  
        //
        //Get Rx Descriptor Information
        //
  #ifdef USB_RX_AGGREGATION_SUPPORT
 -      if (bIsRxAggrSubframe)
 -      {
 +      if (bIsRxAggrSubframe) {
                rx_desc_819x_usb_aggr_subframe *desc = (rx_desc_819x_usb_aggr_subframe *)skb->data;
 -              stats->Length = desc->Length ;
 +              stats->Length = desc->Length;
                stats->RxDrvInfoSize = desc->RxDrvInfoSize;
                stats->RxBufShift = 0; //RxBufShift = 2 in RxDesc, but usb didn't shift bytes in fact.
                stats->bICV = desc->ICV;
  
                stats->Length = desc->Length;
                stats->RxDrvInfoSize = desc->RxDrvInfoSize;
 -              stats->RxBufShift = 0;//desc->Shift&0x03;
 +              stats->RxBufShift = 0;
                stats->bICV = desc->ICV;
                stats->bCRC = desc->CRC32;
                stats->bHwError = stats->bCRC|stats->bICV;
                stats->Decrypted = !desc->SWDec;
        }
  
 -      if((priv->ieee80211->pHTInfo->bCurrentHTSupport == true) && (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
 -      {
 +      if ((priv->ieee80211->pHTInfo->bCurrentHTSupport == true) && (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
                stats->bHwError = false;
 -      }
        else
 -      {
                stats->bHwError = stats->bCRC|stats->bICV;
 -      }
  
 -      if(stats->Length < 24 || stats->Length > MAX_8192U_RX_SIZE)
 +      if (stats->Length < 24 || stats->Length > MAX_8192U_RX_SIZE)
                stats->bHwError |= 1;
        //
        //Get Driver Info
        // TODO: Need to verify it on FGPA platform
        //Driver info are written to the RxBuffer following rx desc
        if (stats->RxDrvInfoSize != 0) {
 -              driver_info = (rx_drvinfo_819x_usb *)(skb->data + sizeof(rx_desc_819x_usb) + \
 -                              stats->RxBufShift);
 +              driver_info = (rx_drvinfo_819x_usb *)(skb->data + sizeof(rx_desc_819x_usb) +
 +                                                    stats->RxBufShift);
                /* unit: 0.5M */
                /* TODO */
 -              if(!stats->bHwError){
 +              if (!stats->bHwError) {
                        u8      ret_rate;
                        ret_rate = HwRateToMRate90(driver_info->RxHT, driver_info->RxRate);
 -                      if(ret_rate == 0xff)
 -                      {
 +                      if (ret_rate == 0xff) {
                                // Abnormal Case: Receive CRC OK packet with Rx descriptor indicating non supported rate.
                                // Special Error Handling here, 2008.05.16, by Emily
  
                                stats->bHwError = 1;
                                stats->rate = MGN_1M;   //Set 1M rate by default
 -                      }else
 -                      {
 +                      } else {
                                stats->rate = ret_rate;
                        }
 -              }
 -              else
 +              } else {
                        stats->rate = 0x02;
 +              }
  
                stats->bShortPreamble = driver_info->SPLCP;
  
  
                UpdateReceivedRateHistogramStatistics8190(dev, stats);
  
 -              stats->bIsAMPDU = (driver_info->PartAggr==1);
 -              stats->bFirstMPDU = (driver_info->PartAggr==1) && (driver_info->FirstAGGR==1);
 +              stats->bIsAMPDU = (driver_info->PartAggr == 1);
 +              stats->bFirstMPDU = (driver_info->PartAggr == 1) && (driver_info->FirstAGGR == 1);
                stats->TimeStampLow = driver_info->TSFL;
                // xiong mask it, 070514
 -              //pRfd->Status.TimeStampHigh = PlatformEFIORead4Byte(Adapter, TSFR+4);
 -              // stats->TimeStampHigh = read_nic_dword(dev,  TSFR+4);
  
                UpdateRxPktTimeStamp8190(dev, stats);
  
                //
                // Rx A-MPDU
                //
 -              if(driver_info->FirstAGGR==1 || driver_info->PartAggr == 1)
 +              if (driver_info->FirstAGGR == 1 || driver_info->PartAggr == 1)
                        RT_TRACE(COMP_RXDESC, "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
 -                                      driver_info->FirstAGGR, driver_info->PartAggr);
 +                               driver_info->FirstAGGR, driver_info->PartAggr);
  
        }
  
 -      skb_pull(skb,sizeof(rx_desc_819x_usb));
 +      skb_pull(skb, sizeof(rx_desc_819x_usb));
        //
        // Get Total offset of MPDU Frame Body
        //
 -      if((stats->RxBufShift + stats->RxDrvInfoSize) > 0) {
 +      if ((stats->RxBufShift + stats->RxDrvInfoSize) > 0) {
                stats->bShift = 1;
 -              skb_pull(skb,stats->RxBufShift + stats->RxDrvInfoSize);
 +              skb_pull(skb, stats->RxBufShift + stats->RxDrvInfoSize);
        }
  
  #ifdef USB_RX_AGGREGATION_SUPPORT
        /* for the rx aggregated sub frame, the redundant space truly contained in the packet */
 -      if(bIsRxAggrSubframe) {
 +      if (bIsRxAggrSubframe)
                skb_pull(skb, 8);
 -      }
  #endif
        /* for debug 2008.5.29 */
  
        //added by vivi, for MP, 20080108
        stats->RxIs40MHzPacket = driver_info->BW;
 -      if(stats->RxDrvInfoSize != 0)
 +      if (stats->RxDrvInfoSize != 0)
                TranslateRxSignalStuff819xUsb(skb, stats, driver_info);
  
  }
@@@ -4735,18 -5359,19 +4735,18 @@@ u32 GetRxPacketShiftBytes819xUsb(struc
        else
  #endif
                return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize
 -                              + Status->RxBufShift);
 +                      + Status->RxBufShift);
  }
  
 -void rtl8192_rx_nomal(struct sk_buffskb)
 +void rtl8192_rx_nomal(struct sk_buff *skb)
  {
        rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
 -      struct net_device *dev=info->dev;
 +      struct net_device *dev = info->dev;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct ieee80211_rx_stats stats = {
                .signal = 0,
                .noise = -98,
                .rate = 0,
 -              //      .mac_time = jiffies,
                .freq = IEEE80211_24GHZ_BAND,
        };
        u32 rx_pkt_len = 0;
  #endif
  
        /* 20 is for ps-poll */
 -      if((skb->len >=(20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
 +      if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
  #ifdef USB_RX_AGGREGATION_SUPPORT
                TempByte = *(skb->data + sizeof(rx_desc_819x_usb));
  #endif
  #ifdef USB_RX_AGGREGATION_SUPPORT
                if (TempByte & BIT0) {
                        agg_skb = skb;
 -                      //TotalLength = agg_skb->len - 4; /*sCrcLng*/
                        TotalLength = stats.Length - 4; /*sCrcLng*/
 -                      //RT_TRACE(COMP_RECV, "%s:first aggregated packet!Length=%d\n",__FUNCTION__,TotalLength);
                        /* though the head pointer has passed this position  */
                        TempDWord = *(u32 *)(agg_skb->data - 4);
                        PacketLength = (u16)(TempDWord & 0x3FFF); /*sCrcLng*/
                        skb = dev_alloc_skb(PacketLength);
 -                      memcpy(skb_put(skb,PacketLength),agg_skb->data,PacketLength);
 +                      memcpy(skb_put(skb, PacketLength), agg_skb->data, PacketLength);
                        PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, false);
                }
  #endif
                rx_pkt_len = skb->len;
                ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
                unicast_packet = false;
 -              if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
 +              if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
                        //TODO
 -              }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
 +              } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
                        //TODO
 -              }else {
 +              } else {
                        /* unicast packet */
                        unicast_packet = true;
                }
  
 -              if(!ieee80211_rx(priv->ieee80211,skb, &stats)) {
 +              if (!ieee80211_rx(priv->ieee80211, skb, &stats)) {
                        dev_kfree_skb_any(skb);
                } else {
                        priv->stats.rxoktotal++;
 -                      if(unicast_packet) {
 +                      if (unicast_packet)
                                priv->stats.rxbytesunicast += rx_pkt_len;
 -                      }
                }
  #ifdef USB_RX_AGGREGATION_SUPPORT
                testing = 1;
 -              // (PipeIndex == 0) && (TempByte & BIT0) => TotalLength > 0.
                if (TotalLength > 0) {
                        PacketOccupiedLendth = PacketLength + (PacketShiftBytes + 8);
                        if ((PacketOccupiedLendth & 0xFF) != 0)
                        else
                                agg_skb->len = 0;
  
 -                      while (agg_skb->len>=GetRxPacketShiftBytes819xUsb(&stats, true)) {
 +                      while (agg_skb->len >= GetRxPacketShiftBytes819xUsb(&stats, true)) {
                                u8 tmpCRC = 0, tmpICV = 0;
 -                              //RT_TRACE(COMP_RECV,"%s:aggred pkt,total_len = %d\n",__FUNCTION__,agg_skb->len);
                                RxDescr = (rx_desc_819x_usb_aggr_subframe *)(agg_skb->data);
                                tmpCRC = RxDescr->CRC32;
                                tmpICV = RxDescr->ICV;
                                query_rxdesc_status(agg_skb, &stats, true);
                                PacketLength = stats.Length;
  
 -                              if(PacketLength > agg_skb->len) {
 +                              if (PacketLength > agg_skb->len)
                                        break;
 -                              }
                                /* Process the MPDU received */
                                skb = dev_alloc_skb(PacketLength);
 -                              memcpy(skb_put(skb,PacketLength),agg_skb->data, PacketLength);
 +                              memcpy(skb_put(skb, PacketLength), agg_skb->data, PacketLength);
                                skb_trim(skb, skb->len - 4/*sCrcLng*/);
  
                                rx_pkt_len = skb->len;
                                ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
                                unicast_packet = false;
 -                              if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
 +                              if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
                                        //TODO
 -                              }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
 +                              } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
                                        //TODO
 -                              }else {
 +                              } else {
                                        /* unicast packet */
                                        unicast_packet = true;
                                }
 -                              if(!ieee80211_rx(priv->ieee80211,skb, &stats)) {
 +                              if (!ieee80211_rx(priv->ieee80211, skb, &stats)) {
                                        dev_kfree_skb_any(skb);
                                } else {
                                        priv->stats.rxoktotal++;
 -                                      if(unicast_packet) {
 +                                      if (unicast_packet)
                                                priv->stats.rxbytesunicast += rx_pkt_len;
 -                                      }
                                }
                                /* should trim the packet which has been copied to target skb */
                                skb_pull(agg_skb, PacketLength);
  #endif
        } else {
                priv->stats.rxurberr++;
 -              printk("actual_length:%d\n", skb->len);
 +              netdev_dbg(dev, "actual_length: %d\n", skb->len);
                dev_kfree_skb_any(skb);
        }
  
  }
  
 -void
 -rtl819xusb_process_received_packet(
 -      struct net_device *dev,
 -      struct ieee80211_rx_stats *pstats
 -      )
 +void rtl819xusb_process_received_packet(struct net_device *dev,
 +                                      struct ieee80211_rx_stats *pstats)
  {
 -//    bool bfreerfd=false, bqueued=false;
 -      u8*     frame;
 -      u16     frame_len=0;
 +      u8      *frame;
 +      u16     frame_len = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
 -//    u8                      index = 0;
 -//    u8                      TID = 0;
 -      //u16                   seqnum = 0;
 -      //PRX_TS_RECORD pts = NULL;
  
        // Get shifted bytes of Starting address of 802.11 header. 2006.09.28, by Emily
        //porting by amy 080508
        frame = pstats->virtual_address;
        frame_len = pstats->packetlength;
  #ifdef TODO   // by amy about HCT
 -      if(!Adapter->bInHctTest)
 +      if (!Adapter->bInHctTest)
                CountRxErrStatistics(Adapter, pRfd);
  #endif
 -      {
 -      #ifdef ENABLE_PS  //by amy for adding ps function in future
 -              RT_RF_POWER_STATE rtState;
 -              // When RF is off, we should not count the packet for hw/sw synchronize
 -              // reason, ie. there may be a duration while sw switch is changed and hw
 -              // switch is being changed. 2006.12.04, by shien chang.
 -              Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (u8* )(&rtState));
 -              if (rtState == eRfOff)
 -              {
 -                      return;
 -              }
 -      #endif
 +#ifdef ENABLE_PS  //by amy for adding ps function in future
 +      RT_RF_POWER_STATE rtState;
 +      // When RF is off, we should not count the packet for hw/sw synchronize
 +      // reason, ie. there may be a duration while sw switch is changed and hw
 +      // switch is being changed. 2006.12.04, by shien chang.
 +      Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (u8 *)(&rtState));
 +      if (rtState == eRfOff)
 +              return;
 +#endif
        priv->stats.rxframgment++;
  
 -      }
  #ifdef TODO
        RmMonitorSignalStrength(Adapter, pRfd);
  #endif
        /* 2007/01/16 MH Add RX command packet handle here. */
        /* 2007/03/01 MH We have to release RFD and return if rx pkt is cmd pkt. */
        if (rtl819xusb_rx_command_packet(dev, pstats))
 -      {
                return;
 -      }
  
  #ifdef SW_CRC_CHECK
        SwCrcCheck();
  
  void query_rx_cmdpkt_desc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats)
  {
 -//    rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
 -//    struct net_device *dev=info->dev;
 -//    struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
 -//    rx_drvinfo_819x_usb  *driver_info;
  
        //
        //Get Rx Descriptor Information
        //
 -      stats->virtual_address = (u8*)skb->data;
 +      stats->virtual_address = (u8 *)skb->data;
        stats->Length = desc->Length;
        stats->RxDrvInfoSize = 0;
        stats->RxBufShift = 0;
@@@ -4952,17 -5602,21 +4952,17 @@@ void rtl8192_rx_cmd(struct sk_buff *skb
  {
        struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
        struct net_device *dev = info->dev;
 -      //int ret;
 -//    struct urb *rx_urb = info->urb;
        /* TODO */
        struct ieee80211_rx_stats stats = {
                .signal = 0,
                .noise = -98,
                .rate = 0,
 -              //      .mac_time = jiffies,
                .freq = IEEE80211_24GHZ_BAND,
        };
  
 -      if((skb->len >=(20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE))
 -      {
 +      if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
  
 -              query_rx_cmdpkt_desc_status(skb,&stats);
 +              query_rx_cmdpkt_desc_status(skb, &stats);
                // this is to be done by amy 080508     prfd->queue_id = 1;
  
  
                //  Process the command packet received.
                //
  
 -              rtl819xusb_process_received_packet(dev,&stats);
 +              rtl819xusb_process_received_packet(dev, &stats);
  
                dev_kfree_skb_any(skb);
        }
@@@ -4986,21 -5640,22 +4986,21 @@@ void rtl8192_irq_rx_tasklet(struct r819
                switch (info->out_pipe) {
                /* Nomal packet pipe */
                case 3:
 -                      //RT_TRACE(COMP_RECV, "normal in-pipe index(%d)\n",info->out_pipe);
                        priv->IrpPendingCount--;
                        rtl8192_rx_nomal(skb);
                        break;
  
 -                      /* Command packet pipe */
 +              /* Command packet pipe */
                case 9:
 -                      RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",\
 -                                      info->out_pipe);
 +                      RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",
 +                               info->out_pipe);
  
                        rtl8192_rx_cmd(skb);
                        break;
  
                default: /* should never get here! */
 -                      RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",\
 -                                      info->out_pipe);
 +                      RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",
 +                               info->out_pipe);
                        dev_kfree_skb(skb);
                        break;
  
@@@ -5027,10 -5682,11 +5027,10 @@@ static const struct net_device_ops rtl8
  *****************************************************************************/
  
  static int rtl8192_usb_probe(struct usb_interface *intf,
 -                       const struct usb_device_id *id)
 +                           const struct usb_device_id *id)
  {
 -//    unsigned long ioaddr = 0;
        struct net_device *dev = NULL;
 -      struct r8192_priv *priv= NULL;
 +      struct r8192_priv *priv = NULL;
        struct usb_device *udev = interface_to_usbdev(intf);
        int ret;
        RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
        SET_NETDEV_DEV(dev, &intf->dev);
        priv = ieee80211_priv(dev);
        priv->ieee80211 = netdev_priv(dev);
 -      priv->udev=udev;
 +      priv->udev = udev;
  
        dev->netdev_ops = &rtl8192_netdev_ops;
  
 -       //DMESG("Oops: i'm coming\n");
  #if WIRELESS_EXT >= 12
  #if WIRELESS_EXT < 17
        dev->get_wireless_stats = r8192_get_wireless_stats;
  #endif
        dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
  #endif
 -      dev->type=ARPHRD_ETHER;
 +      dev->type = ARPHRD_ETHER;
  
        dev->watchdog_timeo = HZ*3;     //modified by john, 0805
  
 -      if (dev_alloc_name(dev, ifname) < 0){
 +      if (dev_alloc_name(dev, ifname) < 0) {
                RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
                ifname = "wlan%d";
                dev_alloc_name(dev, ifname);
        }
  
        RT_TRACE(COMP_INIT, "Driver probe completed1\n");
 -      if(rtl8192_init(dev)!=0){
 +      if (rtl8192_init(dev) != 0) {
                RT_TRACE(COMP_ERR, "Initialization failed");
                ret = -ENODEV;
                goto fail;
        if (ret)
                goto fail2;
  
 -      RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name);
 +      RT_TRACE(COMP_INIT, "dev name=======> %s\n", dev->name);
        rtl8192_proc_init_one(dev);
  
  
@@@ -5098,13 -5755,16 +5098,13 @@@ fail
  }
  
  //detach all the work and timer structure declared or inititialize in r8192U_init function.
 -void rtl8192_cancel_deferred_work(struct r8192_privpriv)
 +void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
  {
  
        cancel_work_sync(&priv->reset_wq);
        cancel_delayed_work(&priv->watch_dog_wq);
        cancel_delayed_work(&priv->update_beacon_wq);
        cancel_work_sync(&priv->qos_activate);
 -      //cancel_work_sync(&priv->SetBWModeWorkItem);
 -      //cancel_work_sync(&priv->SwChnlWorkItem);
 -
  }
  
  
@@@ -5113,18 -5773,22 +5113,18 @@@ static void rtl8192_usb_disconnect(stru
        struct net_device *dev = usb_get_intfdata(intf);
  
        struct r8192_priv *priv = ieee80211_priv(dev);
 -      if(dev){
 +      if (dev) {
  
                unregister_netdev(dev);
  
                RT_TRACE(COMP_DOWN, "=============>wlan driver to be removed\n");
                rtl8192_proc_remove_one(dev);
  
 -                      rtl8192_down(dev);
 +              rtl8192_down(dev);
                kfree(priv->pFirmware);
                priv->pFirmware = NULL;
 -      //      priv->rf_close(dev);
 -//            rtl8192_SetRFPowerState(dev, eRfOff);
                rtl8192_usb_deleteendpoints(dev);
                destroy_workqueue(priv->priv_wq);
 -              //rtl8192_irq_disable(dev);
 -              //rtl8192_reset(dev);
                mdelay(10);
  
        }
@@@ -5151,36 -5815,38 +5151,36 @@@ static int __init rtl8192_usb_module_in
  #ifdef CONFIG_IEEE80211_DEBUG
        ret = ieee80211_debug_init();
        if (ret) {
 -              printk(KERN_ERR "ieee80211_debug_init() failed %d\n", ret);
 +              pr_err("ieee80211_debug_init() failed %d\n", ret);
                return ret;
        }
  #endif
        ret = ieee80211_crypto_init();
        if (ret) {
 -              printk(KERN_ERR "ieee80211_crypto_init() failed %d\n", ret);
 +              pr_err("ieee80211_crypto_init() failed %d\n", ret);
                return ret;
        }
  
        ret = ieee80211_crypto_tkip_init();
        if (ret) {
 -              printk(KERN_ERR "ieee80211_crypto_tkip_init() failed %d\n",
 -                      ret);
 +              pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret);
                return ret;
        }
  
        ret = ieee80211_crypto_ccmp_init();
        if (ret) {
 -              printk(KERN_ERR "ieee80211_crypto_ccmp_init() failed %d\n",
 -                      ret);
 +              pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret);
                return ret;
        }
  
        ret = ieee80211_crypto_wep_init();
        if (ret) {
 -              printk(KERN_ERR "ieee80211_crypto_wep_init() failed %d\n", ret);
 +              pr_err("ieee80211_crypto_wep_init() failed %d\n", ret);
                return ret;
        }
  
 -      printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n");
 -      printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n");
 +      pr_info("\nLinux kernel driver for RTL8192 based WLAN cards\n");
 +      pr_info("Copyright (c) 2007-2008, Realsil Wlan\n");
        RT_TRACE(COMP_INIT, "Initializing module");
        RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
        rtl8192_proc_module_init();
@@@ -5193,6 -5859,7 +5193,6 @@@ static void __exit rtl8192_usb_module_e
        usb_deregister(&rtl8192_usb_driver);
  
        RT_TRACE(COMP_DOWN, "Exiting");
 -//    rtl8192_proc_module_remove();
  }
  
  
@@@ -5202,11 -5869,11 +5202,11 @@@ void rtl8192_try_wake_queue(struct net_
        short enough_desc;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  
 -      spin_lock_irqsave(&priv->tx_lock,flags);
 -      enough_desc = check_nic_enough_desc(dev,pri);
 -      spin_unlock_irqrestore(&priv->tx_lock,flags);
 +      spin_lock_irqsave(&priv->tx_lock, flags);
 +      enough_desc = check_nic_enough_desc(dev, pri);
 +      spin_unlock_irqrestore(&priv->tx_lock, flags);
  
 -      if(enough_desc)
 +      if (enough_desc)
                ieee80211_wake_queue(priv->ieee80211);
  }
  
@@@ -5214,32 -5881,43 +5214,32 @@@ void EnableHWSecurityConfig8192(struct 
  {
        u8 SECR_value = 0x0;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 -       struct ieee80211_device* ieee = priv->ieee80211;
 +      struct ieee80211_device *ieee = priv->ieee80211;
        SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
 -      if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2))
 -      {
 +      if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2)) {
                SECR_value |= SCR_RxUseDK;
                SECR_value |= SCR_TxUseDK;
 -      }
 -      else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP)))
 -      {
 +      } else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP))) {
                SECR_value |= SCR_RxUseDK;
                SECR_value |= SCR_TxUseDK;
        }
        //add HWSec active enable here.
 -//default using hwsec. when peer AP is in N mode only and pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates it), use software security. when peer AP is in b,g,n mode mixed and pairwise_key_type is none_aes, use g mode hw security. WB on 2008.7.4
 +      //default using hwsec. when peer AP is in N mode only and pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates it), use software security. when peer AP is in b,g,n mode mixed and pairwise_key_type is none_aes, use g mode hw security. WB on 2008.7.4
  
        ieee->hwsec_active = 1;
  
 -      if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep)//!ieee->hwsec_support) //add hwsec_support flag to totol control hw_sec on/off
 -      {
 +      if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep) { //add hwsec_support flag to totol control hw_sec on/off
                ieee->hwsec_active = 0;
                SECR_value &= ~SCR_RxDecEnable;
        }
 -      RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__, \
 -                      ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
 -      {
 -              write_nic_byte(dev, SECR,  SECR_value);//SECR_value |  SCR_UseDK );
 -      }
 +      RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __func__,
 +               ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
 +      write_nic_byte(dev, SECR,  SECR_value);
  }
  
  
 -void setKey(  struct net_device *dev,
 -              u8 EntryNo,
 -              u8 KeyIndex,
 -              u16 KeyType,
 -              u8 *MacAddr,
 -              u8 DefaultKey,
 -              u32 *KeyContent )
 +void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
 +          u8 *MacAddr, u8 DefaultKey, u32 *KeyContent)
  {
        u32 TargetCommand = 0;
        u32 TargetContent = 0;
        if (EntryNo >= TOTAL_CAM_ENTRY)
                RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
  
 -      RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev,EntryNo, KeyIndex, KeyType, MacAddr);
 +      RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev, EntryNo, KeyIndex, KeyType, MacAddr);
  
        if (DefaultKey)
                usConfig |= BIT15 | (KeyType<<2);
        else
                usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
 -//    usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex;
  
  
 -      for(i=0 ; i<CAM_CONTENT_COUNT; i++){
 +      for (i = 0; i < CAM_CONTENT_COUNT; i++) {
                TargetCommand  = i+CAM_CONTENT_COUNT*EntryNo;
                TargetCommand |= BIT31|BIT16;
  
 -              if(i==0){//MAC|Config
 +              if (i == 0) { //MAC|Config
                        TargetContent = (u32)(*(MacAddr+0)) << 16|
                                        (u32)(*(MacAddr+1)) << 24|
                                        (u32)usConfig;
  
                        write_nic_dword(dev, WCAMI, TargetContent);
                        write_nic_dword(dev, RWCAM, TargetCommand);
 -      //              printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo));
 -              }
 -              else if(i==1){//MAC
 +              } else if (i == 1) { //MAC
                        TargetContent = (u32)(*(MacAddr+2))      |
                                        (u32)(*(MacAddr+3)) <<  8|
                                        (u32)(*(MacAddr+4)) << 16|
                                        (u32)(*(MacAddr+5)) << 24;
                        write_nic_dword(dev, WCAMI, TargetContent);
                        write_nic_dword(dev, RWCAM, TargetCommand);
 -              }
 -              else {
 +              } else {
                        //Key Material
 -                      if(KeyContent !=NULL){
 -                      write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)) );
 -                      write_nic_dword(dev, RWCAM, TargetCommand);
 +                      if (KeyContent != NULL) {
 +                              write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)));
 +                              write_nic_dword(dev, RWCAM, TargetCommand);
 +                      }
                }
        }
 -      }
  
  }
  
@@@ -35,7 -35,7 +35,7 @@@
  #define BP_MOD_DESCR "Silicom Bypass-SD Control driver"
  #define BP_SYNC_FLAG 1
  
 -static int major_num = 0;
 +static int major_num;
  
  MODULE_AUTHOR("Anna Lukin, annal@silicom.co.il");
  MODULE_LICENSE("GPL");
@@@ -43,16 -43,21 +43,16 @@@ MODULE_DESCRIPTION(BP_MOD_DESCR)
  MODULE_VERSION(BP_MOD_VER);
  spinlock_t bpvm_lock;
  
 -#define lock_bpctl()                                  \
 -if (down_interruptible(&bpctl_sema)) {                        \
 -      return -ERESTARTSYS;                            \
 -}                                                     \
 -
 -#define unlock_bpctl()                                        \
 +#define unlock_bpctl()                                        \
        up(&bpctl_sema);
  
  /* Media Types */
 -typedef enum {
 -      bp_copper = 0,
 -      bp_fiber,
 -      bp_cx4,
 -      bp_none,
 -} bp_media_type;
 +enum bp_media_type {
 +      BP_COPPER = 0,
 +      BP_FIBER,
 +      BP_CX4,
 +      BP_NONE,
 +};
  
  struct bypass_pfs_sd {
        char dir_name[32];
@@@ -84,7 -89,7 +84,7 @@@ typedef struct _bpctl_dev 
        uint32_t reset_time;
        uint8_t bp_status_un;
        atomic_t wdt_busy;
 -      bp_media_type media_type;
 +      enum bp_media_type media_type;
        int bp_tpl_flag;
        struct timer_list bp_tpl_timer;
        spinlock_t bypass_wr_lock;
  static bpctl_dev_t *bpctl_dev_arr;
  
  static struct semaphore bpctl_sema;
 -static int device_num = 0;
 +static int device_num;
  
  static int get_dev_idx(int ifindex);
  static bpctl_dev_t *get_master_port_fn(bpctl_dev_t *pbpctl_dev);
@@@ -128,8 -133,8 +128,8 @@@ static unsigned long str_to_hex(char *p
  static int bp_device_event(struct notifier_block *unused,
                           unsigned long event, void *ptr)
  {
-       struct net_device *dev = ptr;
+       struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 -      static bpctl_dev_t *pbpctl_dev = NULL, *pbpctl_dev_m = NULL;
 +      static bpctl_dev_t *pbpctl_dev, *pbpctl_dev_m;
        int dev_num = 0, ret = 0, ret_d = 0, time_left = 0;
        /* printk("BP_PROC_SUPPORT event =%d %s %d\n", event,dev->name, dev->ifindex ); */
        /* return NOTIFY_DONE; */
                        memcpy(&cbuf, drvinfo.bus_info, 32);
                        buf = &cbuf[0];
  
 -                      while (*buf++ != ':') ;
 +                      while (*buf++ != ':')
 +                              ;
                        for (i = 0; i < 10; i++, buf++) {
                                if (*buf == ':')
                                        break;
@@@ -302,8 -306,7 +302,8 @@@ static void write_pulse(bpctl_dev_t *pb
                ctrl = BP10G_READ_REG(pbpctl_dev, ESDP);
  
        if (pbpctl_dev->bp_10g9) {
 -              if (!(pbpctl_dev_c = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_c = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_c)
                        return;
                ctrl = BP10G_READ_REG(pbpctl_dev_c, ESDP);
        }
@@@ -603,8 -606,7 +603,8 @@@ static int read_pulse(bpctl_dev_t *pbpc
        if (pbpctl_dev->bp_540)
                ctrl = BP10G_READ_REG(pbpctl_dev, ESDP);
        if (pbpctl_dev->bp_10g9) {
 -              if (!(pbpctl_dev_c = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_c = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_c)
                        return -1;
                ctrl = BP10G_READ_REG(pbpctl_dev_c, ESDP);
        }
                                         BP10G_MDIO_DATA_OUT));
  
                }
 -              if (pbpctl_dev->bp_10g9) {
 -                      ctrl_ext = BP10G_READ_REG(pbpctl_dev, I2CCTL);
  
 -              } else if ((pbpctl_dev->bp_fiber5) || (pbpctl_dev->bp_i80)) {
 +              if (pbpctl_dev->bp_10g9)
 +                      ctrl_ext = BP10G_READ_REG(pbpctl_dev, I2CCTL);
 +              else if ((pbpctl_dev->bp_fiber5) || (pbpctl_dev->bp_i80))
                        ctrl_ext = BPCTL_READ_REG(pbpctl_dev, CTRL);
 -              } else if (pbpctl_dev->bp_540) {
 +              else if (pbpctl_dev->bp_540)
                        ctrl_ext = BP10G_READ_REG(pbpctl_dev, ESDP);
 -              else if (pbpctl_dev->bp_10gb)
 +              else if (pbpctl_dev->bp_10gb)
                        ctrl_ext = BP10GB_READ_REG(pbpctl_dev, MISC_REG_SPIO);
 -
                else if (!pbpctl_dev->bp_10g)
                        ctrl_ext = BPCTL_READ_REG(pbpctl_dev, CTRL_EXT);
                else
@@@ -772,8 -775,7 +772,8 @@@ static void write_reg(bpctl_dev_t *pbpc
        bpctl_dev_t *pbpctl_dev_c = NULL;
        unsigned long flags;
        if (pbpctl_dev->bp_10g9) {
 -              if (!(pbpctl_dev_c = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_c = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_c)
                        return;
        }
        if ((pbpctl_dev->wdt_status == WDT_STATUS_EN) &&
@@@ -951,8 -953,7 +951,8 @@@ static int read_reg(bpctl_dev_t *pbpctl
        atomic_set(&pbpctl_dev->wdt_busy, 1);
  #endif
        if (pbpctl_dev->bp_10g9) {
 -              if (!(pbpctl_dev_c = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_c = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_c)
                        return -1;
        }
  
@@@ -1223,8 -1224,7 +1223,8 @@@ static int wdt_pulse(bpctl_dev_t *pbpct
                return -1;
  #endif
        if (pbpctl_dev->bp_10g9) {
 -              if (!(pbpctl_dev_c = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_c = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_c)
                        return -1;
        }
  
                                (ctrl_ext &
                                 ~(BP10G_MCLK_DATA_OUT | BP10G_MDIO_DATA_OUT)));
        }
 -      if ((pbpctl_dev->wdt_status == WDT_STATUS_EN)   /*&&
 -                                                         (pbpctl_dev->bp_ext_ver<PXG4BPFI_VER) */ )
 +      if ((pbpctl_dev->wdt_status == WDT_STATUS_EN))
 +              /*&& (pbpctl_dev->bp_ext_ver<PXG4BPFI_VER) */
                pbpctl_dev->bypass_wdt_on_time = jiffies;
  #ifdef BP_SYNC_FLAG
        spin_unlock_irqrestore(&pbpctl_dev->bypass_wr_lock, flags);
@@@ -1744,8 -1744,7 +1744,8 @@@ static int write_data_int(bpctl_dev_t *
  {
        bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -      if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +      pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +      if (!pbpctl_dev_b)
                return -1;
        atomic_set(&pbpctl_dev->wdt_busy, 1);
        write_data_port_int(pbpctl_dev, value & 0x3);
@@@ -1921,10 -1920,13 +1921,10 @@@ int disc_port_on(bpctl_dev_t *pbpctl_de
                return BP_NOT_CAP;
  
        if (pbpctl_dev_m->bp_caps_ex & DISC_PORT_CAP_EX) {
 -              if (is_bypass_fn(pbpctl_dev) == 1) {
 -
 +              if (is_bypass_fn(pbpctl_dev) == 1)
                        write_data(pbpctl_dev_m, TX_DISA);
 -              } else {
 -
 +              else
                        write_data(pbpctl_dev_m, TX_DISB);
 -              }
  
                msec_delay_bp(LATCH_DELAY);
  
@@@ -1963,8 -1965,7 +1963,8 @@@ int tpl_hw_on(bpctl_dev_t *pbpctl_dev
        int ret = 0, ctrl = 0;
        bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -      if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +      pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +      if (!pbpctl_dev_b)
                return BP_NOT_CAP;
  
        if (pbpctl_dev->bp_caps_ex & TPL2_CAP_EX) {
@@@ -1991,8 -1992,7 +1991,8 @@@ int tpl_hw_off(bpctl_dev_t *pbpctl_dev
        int ret = 0, ctrl = 0;
        bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -      if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +      pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +      if (!pbpctl_dev_b)
                return BP_NOT_CAP;
        if (pbpctl_dev->bp_caps_ex & TPL2_CAP_EX) {
                cmnd_on(pbpctl_dev);
@@@ -2017,9 -2017,9 +2017,9 @@@ int wdt_off(bpctl_dev_t *pbpctl_dev
        int ret = BP_NOT_CAP;
  
        if (pbpctl_dev->bp_caps & WD_CTL_CAP) {
 -              if (INTEL_IF_SERIES(pbpctl_dev->subdevice)) {
 +              if (INTEL_IF_SERIES(pbpctl_dev->subdevice))
                        bypass_off(pbpctl_dev);
 -              else if (pbpctl_dev->bp_ext_ver >= PXG2BPI_VER)
 +              else if (pbpctl_dev->bp_ext_ver >= PXG2BPI_VER)
                        write_data(pbpctl_dev, WDT_OFF);
                else
                        data_pulse(pbpctl_dev, WDT_OFF);
@@@ -2150,14 -2150,12 +2150,14 @@@ static void bp75_release_phy(bpctl_dev_
  {
        u16 mask = BPCTLI_SWFW_PHY0_SM;
        u32 swfw_sync;
 +      s32 ret_val;
  
        if ((pbpctl_dev->func == 1) || (pbpctl_dev->func == 3))
                mask = BPCTLI_SWFW_PHY1_SM;
  
 -      while (bp75_get_hw_semaphore_generic(pbpctl_dev) != 0) ;
 -      /* Empty */
 +      do
 +              ret_val = bp75_get_hw_semaphore_generic(pbpctl_dev);
 +      while (ret_val != 0);
  
        swfw_sync = BPCTL_READ_REG(pbpctl_dev, SW_FW_SYNC);
        swfw_sync &= ~mask;
@@@ -2406,10 -2404,12 +2406,10 @@@ static int set_tx(bpctl_dev_t *pbpctl_d
                        }
  
                }
 -              if (pbpctl_dev->bp_fiber5) {
 +              if (pbpctl_dev->bp_fiber5)
                        ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL_EXT);
 -
 -              } else if (pbpctl_dev->bp_10gb)
 +              else if (pbpctl_dev->bp_10gb)
                        ctrl = BP10GB_READ_REG(pbpctl_dev, MISC_REG_GPIO);
 -
                else if (!pbpctl_dev->bp_10g)
                        ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL);
                else
@@@ -3237,10 -3237,8 +3237,10 @@@ int bypass_from_last_read(bpctl_dev_t *
        uint32_t ctrl_ext = 0;
        bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -      if ((pbpctl_dev->bp_caps & SW_CTL_CAP)
 -          && (pbpctl_dev_b = get_status_port_fn(pbpctl_dev))) {
 +      if (pbpctl_dev->bp_caps & SW_CTL_CAP) {
 +              pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_b)
 +                      return BP_NOT_CAP;
                ctrl_ext = BPCTL_READ_REG(pbpctl_dev_b, CTRL_EXT);
                BPCTL_BP_WRITE_REG(pbpctl_dev_b, CTRL_EXT,
                                   (ctrl_ext & ~BPCTLI_CTRL_EXT_SDP7_DIR));
@@@ -3256,10 -3254,9 +3256,10 @@@ int bypass_status_clear(bpctl_dev_t *pb
  {
        bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -      if ((pbpctl_dev->bp_caps & SW_CTL_CAP)
 -          && (pbpctl_dev_b = get_status_port_fn(pbpctl_dev))) {
 -
 +      if (pbpctl_dev->bp_caps & SW_CTL_CAP) {
 +              pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_b)
 +                      return BP_NOT_CAP;
                send_bypass_clear_pulse(pbpctl_dev_b, 1);
                return 0;
        } else
@@@ -3332,8 -3329,7 +3332,8 @@@ static int bypass_status(bpctl_dev_t *p
  
                bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -              if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_b)
                        return BP_NOT_CAP;
  
                if (INTEL_IF_SERIES(pbpctl_dev->subdevice)) {
                                         BP10G_SDP7_DATA_IN) != 0 ? 0 : 1);
                        }
  
 -              } else if (pbpctl_dev->media_type == bp_copper) {
 +              } else if (pbpctl_dev->media_type == BP_COPPER) {
  
                        return (((BPCTL_READ_REG(pbpctl_dev_b, CTRL)) &
                                 BPCTLI_CTRL_SWDPIN1) != 0 ? 1 : 0);
@@@ -3621,8 -3617,7 +3621,8 @@@ int tap_status(bpctl_dev_t *pbpctl_dev
        if (pbpctl_dev->bp_caps & TAP_CAP) {
                bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -              if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_b)
                        return BP_NOT_CAP;
  
                if (pbpctl_dev->bp_ext_ver >= 0x8) {
                                         BP10G_SDP6_DATA_IN) != 0 ? 0 : 1);
                        }
  
 -              } else if (pbpctl_dev->media_type == bp_copper)
 +              } else if (pbpctl_dev->media_type == BP_COPPER)
                        return (((BPCTL_READ_REG(pbpctl_dev, CTRL)) &
                                 BPCTLI_CTRL_SWDPIN0) != 0 ? 1 : 0);
                else {
@@@ -3718,8 -3713,7 +3718,8 @@@ int disc_off_status(bpctl_dev_t *pbpctl
        u32 ctrl_ext = 0;
  
        if (pbpctl_dev->bp_caps & DISC_CAP) {
 -              if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +              pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +              if (!pbpctl_dev_b)
                        return BP_NOT_CAP;
                if (DISCF_IF_SERIES(pbpctl_dev->subdevice))
                        return ((((read_reg(pbpctl_dev, STATUS_DISC_REG_ADDR)) &
                                 BP10G_SDP2_DATA) != 0 ? 1 : 0);
  
                }
 -              if (pbpctl_dev->media_type == bp_copper) {
 +              if (pbpctl_dev->media_type == BP_COPPER) {
  
  #if 0
                        return ((((read_reg(pbpctl_dev, STATUS_DISC_REG_ADDR)) &
@@@ -3800,10 -3794,11 +3800,10 @@@ static int disc_status(bpctl_dev_t *pbp
  {
        int ctrl = 0;
        if (pbpctl_dev->bp_caps & DISC_CAP) {
 -
 -              if ((ctrl = disc_off_status(pbpctl_dev)) < 0)
 +              ctrl = disc_off_status(pbpctl_dev);
 +              if (ctrl < 0)
                        return ctrl;
                return ((ctrl == 0) ? 1 : 0);
 -
        }
        return BP_NOT_CAP;
  }
@@@ -3916,8 -3911,7 +3916,8 @@@ int tpl_hw_status(bpctl_dev_t *pbpctl_d
  {
        bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -      if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +      pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +      if (!pbpctl_dev_b)
                return BP_NOT_CAP;
  
        if (TPL_IF_SERIES(pbpctl_dev->subdevice))
@@@ -4027,41 -4021,42 +4027,41 @@@ void bypass_caps_init(bpctl_dev_t *pbpc
        }
  #endif
        if ((pbpctl_dev->bp_fiber5) || (pbpctl_dev->bp_10g9)) {
 -              pbpctl_dev->media_type = bp_fiber;
 +              pbpctl_dev->media_type = BP_FIBER;
        } else if (pbpctl_dev->bp_10gb) {
                if (BP10GB_CX4_SERIES(pbpctl_dev->subdevice))
 -                      pbpctl_dev->media_type = bp_cx4;
 +                      pbpctl_dev->media_type = BP_CX4;
                else
 -                      pbpctl_dev->media_type = bp_fiber;
 +                      pbpctl_dev->media_type = BP_FIBER;
  
        }
  
        else if (pbpctl_dev->bp_540)
 -              pbpctl_dev->media_type = bp_none;
 +              pbpctl_dev->media_type = BP_NONE;
        else if (!pbpctl_dev->bp_10g) {
  
                ctrl_ext = BPCTL_READ_REG(pbpctl_dev, CTRL_EXT);
                if ((ctrl_ext & BPCTLI_CTRL_EXT_LINK_MODE_MASK) == 0x0)
 -                      pbpctl_dev->media_type = bp_copper;
 +                      pbpctl_dev->media_type = BP_COPPER;
                else
 -                      pbpctl_dev->media_type = bp_fiber;
 +                      pbpctl_dev->media_type = BP_FIBER;
  
        } else {
                if (BP10G_CX4_SERIES(pbpctl_dev->subdevice))
 -                      pbpctl_dev->media_type = bp_cx4;
 +                      pbpctl_dev->media_type = BP_CX4;
                else
 -                      pbpctl_dev->media_type = bp_fiber;
 +                      pbpctl_dev->media_type = BP_FIBER;
        }
  
        if (is_bypass_fn(pbpctl_dev)) {
  
                pbpctl_dev->bp_caps |= BP_PWOFF_ON_CAP;
 -              if (pbpctl_dev->media_type == bp_fiber)
 +              if (pbpctl_dev->media_type == BP_FIBER)
                        pbpctl_dev->bp_caps |=
                            (TX_CTL_CAP | TX_STATUS_CAP | TPL_CAP);
  
 -              if (TPL_IF_SERIES(pbpctl_dev->subdevice)) {
 +              if (TPL_IF_SERIES(pbpctl_dev->subdevice))
                        pbpctl_dev->bp_caps |= TPL_CAP;
 -              }
  
                if (INTEL_IF_SERIES(pbpctl_dev->subdevice)) {
                        pbpctl_dev->bp_caps |=
        if (PEG5_IF_SERIES(pbpctl_dev->subdevice))
                pbpctl_dev->bp_caps |= (TX_CTL_CAP | TX_STATUS_CAP);
  
 -      if (BP10GB_IF_SERIES(pbpctl_dev->subdevice)) {
 +      if (BP10GB_IF_SERIES(pbpctl_dev->subdevice))
                pbpctl_dev->bp_caps &= ~(TX_CTL_CAP | TX_STATUS_CAP);
 -      }
 +
        pbpctl_dev_m = get_master_port_fn(pbpctl_dev);
        if (pbpctl_dev_m != NULL) {
                int cap_reg = 0;
  
  int bypass_off_init(bpctl_dev_t *pbpctl_dev)
  {
 -      int ret = 0;
 -
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      int ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        if (INTEL_IF_SERIES(pbpctl_dev->subdevice))
                return dis_bypass_cap(pbpctl_dev);
@@@ -4331,13 -4327,14 +4331,13 @@@ int set_bypass_wd_auto(bpctl_dev_t *pbp
  
  int get_bypass_wd_auto(bpctl_dev_t *pbpctl_dev)
  {
 -
 -      if (pbpctl_dev->bp_caps & WD_CTL_CAP) {
 +      if (pbpctl_dev->bp_caps & WD_CTL_CAP)
                return pbpctl_dev->reset_time;
 -      }
 +
        return BP_NOT_CAP;
  }
  
 -#ifdef  BP_SELF_TEST
 +#ifdef BP_SELF_TEST
  
  int set_bp_self_test(bpctl_dev_t *pbpctl_dev, unsigned int param)
  {
@@@ -4406,8 -4403,7 +4406,8 @@@ int set_bypass_fn(bpctl_dev_t *pbpctl_d
  
        if (!(pbpctl_dev->bp_caps & BP_CAP))
                return BP_NOT_CAP;
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        if (!bypass_mode)
                ret = bypass_off(pbpctl_dev);
@@@ -4439,8 -4435,7 +4439,8 @@@ int set_dis_bypass_fn(bpctl_dev_t *pbpc
  
        if (!(pbpctl_dev->bp_caps & BP_DIS_CAP))
                return BP_NOT_CAP;
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        if (dis_param)
                ret = dis_bypass_cap(pbpctl_dev);
@@@ -4466,8 -4461,7 +4466,8 @@@ int set_bypass_pwoff_fn(bpctl_dev_t *pb
  
        if (!(pbpctl_dev->bp_caps & BP_PWOFF_CTL_CAP))
                return BP_NOT_CAP;
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        if (bypass_mode)
                ret = bypass_state_pwroff(pbpctl_dev);
@@@ -4493,8 -4487,7 +4493,8 @@@ int set_bypass_pwup_fn(bpctl_dev_t *pbp
  
        if (!(pbpctl_dev->bp_caps & BP_PWUP_CTL_CAP))
                return BP_NOT_CAP;
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        if (bypass_mode)
                ret = bypass_state_pwron(pbpctl_dev);
@@@ -4521,8 -4514,7 +4521,8 @@@ int set_bypass_wd_fn(bpctl_dev_t *pbpct
        if (!(pbpctl_dev->bp_caps & WD_CTL_CAP))
                return BP_NOT_CAP;
  
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        if (!timeout)
                ret = wdt_off(pbpctl_dev);
@@@ -4591,8 -4583,7 +4591,8 @@@ int set_std_nic_fn(bpctl_dev_t *pbpctl_
        if (!(pbpctl_dev->bp_caps & STD_NIC_CAP))
                return BP_NOT_CAP;
  
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        if (nic_mode)
                ret = std_nic_on(pbpctl_dev);
@@@ -4658,8 -4649,7 +4658,8 @@@ int get_tap_pwup_fn(bpctl_dev_t *pbpctl
        if (!pbpctl_dev)
                return -1;
  
 -      if ((ret = default_pwron_tap_status(pbpctl_dev)) < 0)
 +      ret = default_pwron_tap_status(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        return ((ret == 0) ? 1 : 0);
  }
@@@ -4834,8 -4824,7 +4834,8 @@@ int get_disc_port_pwup_fn(bpctl_dev_t *
        if (!pbpctl_dev)
                return -1;
  
 -      if ((ret = default_pwron_disc_port_status(pbpctl_dev)) < 0)
 +      ret = default_pwron_disc_port_status(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        return ((ret == 0) ? 1 : 0);
  }
@@@ -4862,8 -4851,7 +4862,8 @@@ int reset_cont_fn(bpctl_dev_t *pbpctl_d
        if (!pbpctl_dev)
                return -1;
  
 -      if ((ret = cmnd_on(pbpctl_dev)) < 0)
 +      ret = cmnd_on(pbpctl_dev);
 +      if (ret < 0)
                return ret;
        return reset_cont(pbpctl_dev);
  }
@@@ -4879,10 -4867,8 +4879,10 @@@ int set_tx_fn(bpctl_dev_t *pbpctl_dev, 
            (pbpctl_dev->bp_caps & SW_CTL_CAP)) {
                if ((pbpctl_dev->bp_tpl_flag))
                        return BP_NOT_CAP;
 -      } else if ((pbpctl_dev_b = get_master_port_fn(pbpctl_dev))) {
 -              if ((pbpctl_dev_b->bp_caps & TPL_CAP) &&
 +      } else {
 +              pbpctl_dev_b = get_master_port_fn(pbpctl_dev);
 +              if (pbpctl_dev_b &&
 +                  (pbpctl_dev_b->bp_caps & TPL_CAP) &&
                    (pbpctl_dev_b->bp_tpl_flag))
                        return BP_NOT_CAP;
        }
@@@ -4998,10 -4984,8 +4998,10 @@@ int get_tx_fn(bpctl_dev_t *pbpctl_dev
            (pbpctl_dev->bp_caps & SW_CTL_CAP)) {
                if ((pbpctl_dev->bp_tpl_flag))
                        return BP_NOT_CAP;
 -      } else if ((pbpctl_dev_b = get_master_port_fn(pbpctl_dev))) {
 -              if ((pbpctl_dev_b->bp_caps & TPL_CAP) &&
 +      } else {
 +              pbpctl_dev_b = get_master_port_fn(pbpctl_dev);
 +              if (pbpctl_dev_b &&
 +                  (pbpctl_dev_b->bp_caps & TPL_CAP) &&
                    (pbpctl_dev_b->bp_tpl_flag))
                        return BP_NOT_CAP;
        }
@@@ -5025,7 -5009,7 +5025,7 @@@ static int get_bypass_link_status(bpctl
        if (!pbpctl_dev)
                return -1;
  
 -      if (pbpctl_dev->media_type == bp_fiber)
 +      if (pbpctl_dev->media_type == BP_FIBER)
                return ((BPCTL_READ_REG(pbpctl_dev, CTRL) &
                         BPCTLI_CTRL_SWDPIN1));
        else
@@@ -5040,8 -5024,7 +5040,8 @@@ static void bp_tpl_timer_fn(unsigned lo
        uint32_t link1, link2;
        bpctl_dev_t *pbpctl_dev_b = NULL;
  
 -      if (!(pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +      pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +      if (!pbpctl_dev_b)
                return;
  
        if (!pbpctl_dev->bp_tpl_flag) {
  
        link2 = get_bypass_link_status(pbpctl_dev_b);
        if ((link1) && (tx_status(pbpctl_dev))) {
 -              if ((!link2) && (tx_status(pbpctl_dev_b))) {
 +              if ((!link2) && (tx_status(pbpctl_dev_b)))
                        set_tx(pbpctl_dev, 0);
 -              } else if (!tx_status(pbpctl_dev_b)) {
 +              else if (!tx_status(pbpctl_dev_b))
                        set_tx(pbpctl_dev_b, 1);
 -              }
        } else if ((!link1) && (tx_status(pbpctl_dev))) {
 -              if ((link2) && (tx_status(pbpctl_dev_b))) {
 +              if ((link2) && (tx_status(pbpctl_dev_b)))
                        set_tx(pbpctl_dev_b, 0);
 -              }
        } else if ((link1) && (!tx_status(pbpctl_dev))) {
 -              if ((link2) && (tx_status(pbpctl_dev_b))) {
 +              if ((link2) && (tx_status(pbpctl_dev_b)))
                        set_tx(pbpctl_dev, 1);
 -              }
        } else if ((!link1) && (!tx_status(pbpctl_dev))) {
 -              if ((link2) && (tx_status(pbpctl_dev_b))) {
 +              if ((link2) && (tx_status(pbpctl_dev_b)))
                        set_tx(pbpctl_dev, 1);
 -              }
        }
  
        mod_timer(&pbpctl_dev->bp_tpl_timer, jiffies + BP_LINK_MON_DELAY * HZ);
@@@ -5124,9 -5111,9 +5124,9 @@@ int get_bypass_tpl_auto(bpctl_dev_t *pb
  {
        if (!pbpctl_dev)
                return -1;
 -      if (pbpctl_dev->bp_caps & TPL_CAP) {
 +      if (pbpctl_dev->bp_caps & TPL_CAP)
                return pbpctl_dev->bp_tpl_flag;
 -      }
 +
        return BP_NOT_CAP;
  }
  
@@@ -5141,8 -5128,7 +5141,8 @@@ int set_tpl_fn(bpctl_dev_t *pbpctl_dev
  
        if (pbpctl_dev->bp_caps & TPL_CAP) {
                if (tpl_mode) {
 -                      if ((pbpctl_dev_b = get_status_port_fn(pbpctl_dev)))
 +                      pbpctl_dev_b = get_status_port_fn(pbpctl_dev);
 +                      if (pbpctl_dev_b)
                                set_tx(pbpctl_dev_b, 1);
                        set_tx(pbpctl_dev, 1);
                }
@@@ -5359,8 -5345,7 +5359,8 @@@ static void if_scan_init(void
                memcpy(&cbuf, drvinfo.bus_info, 32);
                buf = &cbuf[0];
  
 -              while (*buf++ != ':') ;
 +              while (*buf++ != ':')
 +                      ;
                for (i = 0; i < 10; i++, buf++) {
                        if (*buf == ':')
                                break;
@@@ -5409,8 -5394,7 +5409,8 @@@ static long device_ioctl(struct file *f
        static bpctl_dev_t *pbpctl_dev;
  
        /* lock_kernel(); */
 -      lock_bpctl();
 +      if (down_interruptible(&bpctl_sema))
 +              return -ERESTARTSYS;
        /* local_irq_save(flags); */
        /* if(!spin_trylock_irqsave(&bpvm_lock)){
           local_irq_restore(flags);
                return -1;
        }
  
 -/*            preempt_disable();
 +/*    preempt_disable();
        rcu_read_lock();
 -              spin_lock_irqsave(&bpvm_lock, flags);
 +      spin_lock_irqsave(&bpvm_lock, flags);
  */
        if ((bpctl_cmd.in_param[5]) ||
            (bpctl_cmd.in_param[6]) || (bpctl_cmd.in_param[7]))
@@@ -5803,7 -5787,7 +5803,7 @@@ static const struct file_operations Fop
  };
  
  #ifndef PCI_DEVICE
 -#define PCI_DEVICE(vend,dev) \
 +#define PCI_DEVICE(vend, dev) \
        .vendor = (vend), .device = (dev), \
        .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
  #endif
  #define SILICOM_E1000BP_ETHERNET_DEVICE(device_id) {\
        PCI_DEVICE(SILICOM_VID, device_id)}
  
 -typedef enum {
 +enum board_type {
        PXG2BPFI,
        PXG2BPFIL,
        PXG2BPFILX,
        PE310G4BPi9SR,
        PE310G4BPi9LR,
        PE210G2BPi40,
 -} board_t;
 +};
  
  typedef struct _bpmod_info_t {
        unsigned int vendor;
@@@ -6645,7 -6629,7 +6645,7 @@@ static void find_fw(bpctl_dev_t *dev
                            ioremap(mmio_start, mmio_len);
  
                        dev->bp_fw_ver = bypass_fw_ver(dev);
 -                      if (dev-> bp_fw_ver == 0xa8)
 +                      if (dev->bp_fw_ver == 0xa8)
                                break;
                }
        }
@@@ -6724,8 -6708,7 +6724,8 @@@ static int init_one(bpctl_dev_t *dev, b
                        reset_cont(dev);
        }
  #ifdef BP_SELF_TEST
 -      if ((dev->bp_tx_data = kzalloc(BPTEST_DATA_LEN, GFP_KERNEL))) {
 +      dev->bp_tx_data = kzalloc(BPTEST_DATA_LEN, GFP_KERNEL);
 +      if (dev->bp_tx_data) {
                memset(dev->bp_tx_data, 0xff, 6);
                memset(dev->bp_tx_data + 6, 0x0, 1);
                memset(dev->bp_tx_data + 7, 0xaa, 5);
@@@ -6895,69 -6878,59 +6895,69 @@@ int is_bypass_sd(int ifindex
  {
        return is_bypass(get_dev_idx_p(ifindex));
  }
 +EXPORT_SYMBOL(is_bypass_sd);
  
  int set_bypass_sd(int ifindex, int bypass_mode)
  {
  
        return set_bypass_fn(get_dev_idx_p(ifindex), bypass_mode);
  }
 +EXPORT_SYMBOL(set_bypass_sd);
  
  int get_bypass_sd(int ifindex)
  {
  
        return get_bypass_fn(get_dev_idx_p(ifindex));
  }
 +EXPORT_SYMBOL(get_bypass_sd);
  
  int get_bypass_change_sd(int ifindex)
  {
  
        return get_bypass_change_fn(get_dev_idx_p(ifindex));
  }
 +EXPORT_SYMBOL(get_bypass_change_sd);
  
  int set_dis_bypass_sd(int ifindex, int dis_param)
  {
        return set_dis_bypass_fn(get_dev_idx_p(ifindex), dis_param);
  }
 +EXPORT_SYMBOL(set_dis_bypass_sd);
  
  int get_dis_bypass_sd(int ifindex)
  {
  
        return get_dis_bypass_fn(get_dev_idx_p(ifindex));
  }
 +EXPORT_SYMBOL(get_dis_bypass_sd);
  
  int set_bypass_pwoff_sd(int ifindex, int bypass_mode)
  {
        return set_bypass_pwoff_fn(get_dev_idx_p(ifindex), bypass_mode);
  
  }
 +EXPORT_SYMBOL(set_bypass_pwoff_sd);
  
  int get_bypass_pwoff_sd(int ifindex)
  {
        return get_bypass_pwoff_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_bypass_pwoff_sd);
  
  int set_bypass_pwup_sd(int ifindex, int bypass_mode)
  {
        return set_bypass_pwup_fn(get_dev_idx_p(ifindex), bypass_mode);
  
  }
 +EXPORT_SYMBOL(set_bypass_pwup_sd);
  
  int get_bypass_pwup_sd(int ifindex)
  {
        return get_bypass_pwup_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_bypass_pwup_sd);
  
  int set_bypass_wd_sd(int if_index, int ms_timeout, int *ms_timeout_set)
  {
        *ms_timeout_set = set_bypass_wd_fn(get_dev_idx_p(if_index), ms_timeout);
        return 0;
  }
 +EXPORT_SYMBOL(set_bypass_wd_sd);
  
  int get_bypass_wd_sd(int ifindex, int *timeout)
  {
        return get_bypass_wd_fn(get_dev_idx_p(ifindex), timeout);
  
  }
 +EXPORT_SYMBOL(get_bypass_wd_sd);
  
  int get_wd_expire_time_sd(int ifindex, int *time_left)
  {
        return get_wd_expire_time_fn(get_dev_idx_p(ifindex), time_left);
  }
 +EXPORT_SYMBOL(get_wd_expire_time_sd);
  
  int reset_bypass_wd_timer_sd(int ifindex)
  {
        return reset_bypass_wd_timer_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(reset_bypass_wd_timer_sd);
  
  int get_wd_set_caps_sd(int ifindex)
  {
        return get_wd_set_caps_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_wd_set_caps_sd);
  
  int set_std_nic_sd(int ifindex, int nic_mode)
  {
        return set_std_nic_fn(get_dev_idx_p(ifindex), nic_mode);
  
  }
 +EXPORT_SYMBOL(set_std_nic_sd);
  
  int get_std_nic_sd(int ifindex)
  {
        return get_std_nic_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_std_nic_sd);
  
  int set_tap_sd(int ifindex, int tap_mode)
  {
        return set_tap_fn(get_dev_idx_p(ifindex), tap_mode);
  
  }
 +EXPORT_SYMBOL(set_tap_sd);
  
  int get_tap_sd(int ifindex)
  {
        return get_tap_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_tap_sd);
  
  int set_tap_pwup_sd(int ifindex, int tap_mode)
  {
        return set_tap_pwup_fn(get_dev_idx_p(ifindex), tap_mode);
  
  }
 +EXPORT_SYMBOL(set_tap_pwup_sd);
  
  int get_tap_pwup_sd(int ifindex)
  {
        return get_tap_pwup_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_tap_pwup_sd);
  
  int get_tap_change_sd(int ifindex)
  {
        return get_tap_change_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_tap_change_sd);
  
  int set_dis_tap_sd(int ifindex, int dis_param)
  {
        return set_dis_tap_fn(get_dev_idx_p(ifindex), dis_param);
  
  }
 +EXPORT_SYMBOL(set_dis_tap_sd);
  
  int get_dis_tap_sd(int ifindex)
  {
        return get_dis_tap_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_dis_tap_sd);
  
  int set_bp_disc_sd(int ifindex, int disc_mode)
  {
        return set_disc_fn(get_dev_idx_p(ifindex), disc_mode);
  
  }
 +EXPORT_SYMBOL(set_bp_disc_sd);
  
  int get_bp_disc_sd(int ifindex)
  {
        return get_disc_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_bp_disc_sd);
  
  int set_bp_disc_pwup_sd(int ifindex, int disc_mode)
  {
        return set_disc_pwup_fn(get_dev_idx_p(ifindex), disc_mode);
  
  }
 +EXPORT_SYMBOL(set_bp_disc_pwup_sd);
  
  int get_bp_disc_pwup_sd(int ifindex)
  {
        return get_disc_pwup_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_bp_disc_pwup_sd);
  
  int get_bp_disc_change_sd(int ifindex)
  {
        return get_disc_change_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_bp_disc_change_sd);
  
  int set_bp_dis_disc_sd(int ifindex, int dis_param)
  {
        return set_dis_disc_fn(get_dev_idx_p(ifindex), dis_param);
  
  }
 +EXPORT_SYMBOL(set_bp_dis_disc_sd);
  
  int get_bp_dis_disc_sd(int ifindex)
  {
        return get_dis_disc_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_bp_dis_disc_sd);
  
  int get_wd_exp_mode_sd(int ifindex)
  {
        return get_wd_exp_mode_fn(get_dev_idx_p(ifindex));
  }
 +EXPORT_SYMBOL(get_wd_exp_mode_sd);
  
  int set_wd_exp_mode_sd(int ifindex, int param)
  {
        return set_wd_exp_mode_fn(get_dev_idx_p(ifindex), param);
  
  }
 +EXPORT_SYMBOL(set_wd_exp_mode_sd);
  
  int reset_cont_sd(int ifindex)
  {
@@@ -7131,41 -7081,35 +7131,41 @@@ int set_tx_sd(int ifindex, int tx_state
        return set_tx_fn(get_dev_idx_p(ifindex), tx_state);
  
  }
 +EXPORT_SYMBOL(set_tx_sd);
  
  int set_tpl_sd(int ifindex, int tpl_state)
  {
        return set_tpl_fn(get_dev_idx_p(ifindex), tpl_state);
  
  }
 +EXPORT_SYMBOL(set_tpl_sd);
  
  int set_bp_hw_reset_sd(int ifindex, int status)
  {
        return set_bp_hw_reset_fn(get_dev_idx_p(ifindex), status);
  
  }
 +EXPORT_SYMBOL(set_bp_hw_reset_sd);
  
  int set_wd_autoreset_sd(int ifindex, int param)
  {
        return set_wd_autoreset_fn(get_dev_idx_p(ifindex), param);
  
  }
 +EXPORT_SYMBOL(set_wd_autoreset_sd);
  
  int get_wd_autoreset_sd(int ifindex)
  {
        return get_wd_autoreset_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_wd_autoreset_sd);
  
  int get_bypass_caps_sd(int ifindex)
  {
        return get_bypass_caps_fn(get_dev_idx_p(ifindex));
  }
 +EXPORT_SYMBOL(get_bypass_caps_sd);
  
  int get_bypass_slave_sd(int ifindex)
  {
        return -1;
  
  }
 +EXPORT_SYMBOL(get_bypass_slave_sd);
  
  int get_tx_sd(int ifindex)
  {
        return get_tx_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_tx_sd);
  
  int get_tpl_sd(int ifindex)
  {
        return get_tpl_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_tpl_sd);
  
  int get_bp_hw_reset_sd(int ifindex)
  {
        return get_bp_hw_reset_fn(get_dev_idx_p(ifindex));
  
  }
 +EXPORT_SYMBOL(get_bp_hw_reset_sd);
  
  int get_bypass_info_sd(int ifindex, struct bp_info *bp_info)
  {
        return get_bypass_info_fn(get_dev_idx_p(ifindex), bp_info->prod_name, &bp_info->fw_ver);
  }
 +EXPORT_SYMBOL(get_bypass_info_sd);
  
  int bp_if_scan_sd(void)
  {
        if_scan_init();
        return 0;
  }
 -
 -EXPORT_SYMBOL_NOVERS(is_bypass_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_slave_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_caps_sd);
 -EXPORT_SYMBOL_NOVERS(get_wd_set_caps_sd);
 -EXPORT_SYMBOL_NOVERS(set_bypass_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_change_sd);
 -EXPORT_SYMBOL_NOVERS(set_dis_bypass_sd);
 -EXPORT_SYMBOL_NOVERS(get_dis_bypass_sd);
 -EXPORT_SYMBOL_NOVERS(set_bypass_pwoff_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_pwoff_sd);
 -EXPORT_SYMBOL_NOVERS(set_bypass_pwup_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_pwup_sd);
 -EXPORT_SYMBOL_NOVERS(set_bypass_wd_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_wd_sd);
 -EXPORT_SYMBOL_NOVERS(get_wd_expire_time_sd);
 -EXPORT_SYMBOL_NOVERS(reset_bypass_wd_timer_sd);
 -EXPORT_SYMBOL_NOVERS(set_std_nic_sd);
 -EXPORT_SYMBOL_NOVERS(get_std_nic_sd);
 -EXPORT_SYMBOL_NOVERS(set_tx_sd);
 -EXPORT_SYMBOL_NOVERS(get_tx_sd);
 -EXPORT_SYMBOL_NOVERS(set_tpl_sd);
 -EXPORT_SYMBOL_NOVERS(get_tpl_sd);
 -EXPORT_SYMBOL_NOVERS(set_bp_hw_reset_sd);
 -EXPORT_SYMBOL_NOVERS(get_bp_hw_reset_sd);
 -EXPORT_SYMBOL_NOVERS(set_tap_sd);
 -EXPORT_SYMBOL_NOVERS(get_tap_sd);
 -EXPORT_SYMBOL_NOVERS(get_tap_change_sd);
 -EXPORT_SYMBOL_NOVERS(set_dis_tap_sd);
 -EXPORT_SYMBOL_NOVERS(get_dis_tap_sd);
 -EXPORT_SYMBOL_NOVERS(set_tap_pwup_sd);
 -EXPORT_SYMBOL_NOVERS(get_tap_pwup_sd);
 -EXPORT_SYMBOL_NOVERS(set_wd_exp_mode_sd);
 -EXPORT_SYMBOL_NOVERS(get_wd_exp_mode_sd);
 -EXPORT_SYMBOL_NOVERS(set_wd_autoreset_sd);
 -EXPORT_SYMBOL_NOVERS(get_wd_autoreset_sd);
 -EXPORT_SYMBOL_NOVERS(set_bp_disc_sd);
 -EXPORT_SYMBOL_NOVERS(get_bp_disc_sd);
 -EXPORT_SYMBOL_NOVERS(get_bp_disc_change_sd);
 -EXPORT_SYMBOL_NOVERS(set_bp_dis_disc_sd);
 -EXPORT_SYMBOL_NOVERS(get_bp_dis_disc_sd);
 -EXPORT_SYMBOL_NOVERS(set_bp_disc_pwup_sd);
 -EXPORT_SYMBOL_NOVERS(get_bp_disc_pwup_sd);
 -EXPORT_SYMBOL_NOVERS(get_bypass_info_sd);
 -EXPORT_SYMBOL_NOVERS(bp_if_scan_sd);
 +EXPORT_SYMBOL(bp_if_scan_sd);
  
  #define BP_PROC_DIR "bypass"
  
@@@ -7279,7 -7263,7 +7279,7 @@@ static int show_bypass_slave(struct seq
        if (!slave)
                slave = dev;
        if (!slave)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (slave->ndev)
                seq_printf(m, "%s\n", slave->ndev->name);
        return 0;
@@@ -7291,7 -7275,7 +7291,7 @@@ static int show_bypass_caps(struct seq_
        bpctl_dev_t *dev = m->private;
        int ret = get_bypass_caps_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "-1\n");
 +              seq_puts(m, "-1\n");
        else
                seq_printf(m, "0x%x\n", ret);
        return 0;
@@@ -7303,7 -7287,7 +7303,7 @@@ static int show_wd_set_caps(struct seq_
        bpctl_dev_t *dev = m->private;
        int ret = get_wd_set_caps_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "-1\n");
 +              seq_puts(m, "-1\n");
        else
                seq_printf(m, "0x%x\n", ret);
        return 0;
@@@ -7349,11 -7333,11 +7349,11 @@@ static int show_bypass(struct seq_file 
        bpctl_dev_t *dev = m->private;
        int ret = get_bypass_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        return 0;
  }
  RW_FOPS(bypass)
@@@ -7373,11 -7357,11 +7373,11 @@@ static int show_tap(struct seq_file *m
        bpctl_dev_t *dev = m->private;
        int ret = get_tap_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        return 0;
  }
  RW_FOPS(tap)
@@@ -7397,11 -7381,11 +7397,11 @@@ static int show_disc(struct seq_file *m
        bpctl_dev_t *dev = m->private;
        int ret = get_disc_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        return 0;
  }
  RW_FOPS(disc)
@@@ -7411,11 -7395,11 +7411,11 @@@ static int show_bypass_change(struct se
        bpctl_dev_t *dev = m->private;
        int ret = get_bypass_change_fn(dev);
        if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        return 0;
  }
  RO_FOPS(bypass_change)
@@@ -7425,11 -7409,11 +7425,11 @@@ static int show_tap_change(struct seq_f
        bpctl_dev_t *dev = m->private;
        int ret = get_tap_change_fn(dev);
        if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        return 0;
  }
  RO_FOPS(tap_change)
@@@ -7439,11 -7423,11 +7439,11 @@@ static int show_disc_change(struct seq_
        bpctl_dev_t *dev = m->private;
        int ret = get_disc_change_fn(dev);
        if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        return 0;
  }
  RO_FOPS(disc_change)
@@@ -7466,11 -7450,11 +7466,11 @@@ static int show_bypass_wd(struct seq_fi
  
        ret = get_bypass_wd_fn(dev, &timeout);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m,  "fail\n");
 +              seq_puts(m,  "fail\n");
        else if (timeout == -1)
 -              seq_printf(m,  "unknown\n");
 +              seq_puts(m,  "unknown\n");
        else if (timeout == 0)
 -              seq_printf(m,  "disable\n");
 +              seq_puts(m,  "disable\n");
        else
                seq_printf(m, "%d\n", timeout);
        return 0;
@@@ -7483,11 -7467,11 +7483,11 @@@ static int show_wd_expire_time(struct s
        int ret = 0, timeout = 0;
        ret = get_wd_expire_time_fn(dev, &timeout);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (timeout == -1)
 -              seq_printf(m, "expire\n");
 +              seq_puts(m, "expire\n");
        else if (timeout == 0)
 -              seq_printf(m, "disable\n");
 +              seq_puts(m, "disable\n");
        else
                seq_printf(m, "%d\n", timeout);
        return 0;
@@@ -7510,11 -7494,11 +7510,11 @@@ static int show_tpl(struct seq_file *m
        bpctl_dev_t *dev = m->private;
        int ret = get_tpl_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        return 0;
  }
  RW_FOPS(tpl)
@@@ -7536,11 -7520,11 +7536,11 @@@ static int show_wait_at_pwup(struct seq
        bpctl_dev_t *dev = m->private;
        int ret = get_bp_wait_at_pwup_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        return 0;
  }
  RW_FOPS(wait_at_pwup)
@@@ -7561,11 -7545,11 +7561,11 @@@ static int show_hw_reset(struct seq_fil
        bpctl_dev_t *dev = m->private;
        int ret = get_bp_hw_reset_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 1)
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        return 0;
  }
  RW_FOPS(hw_reset)
@@@ -7577,11 -7561,11 +7577,11 @@@ static int show_reset_bypass_wd(struct 
        bpctl_dev_t *dev = m->private;
        int ret = reset_bypass_wd_timer_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "disable\n");
 +              seq_puts(m, "disable\n");
        else if (ret == 1)
 -              seq_printf(m, "success\n");
 +              seq_puts(m, "success\n");
        return 0;
  }
  RO_FOPS(reset_bypass_wd)
@@@ -7601,11 -7585,11 +7601,11 @@@ static int show_dis_bypass(struct seq_f
        bpctl_dev_t *dev = m->private;
        int ret = get_dis_bypass_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(dis_bypass)
@@@ -7625,11 -7609,11 +7625,11 @@@ static int show_dis_tap(struct seq_fil
        bpctl_dev_t *dev = m->private;
        int ret = get_dis_tap_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(dis_tap)
@@@ -7649,11 -7633,11 +7649,11 @@@ static int show_dis_disc(struct seq_fil
        bpctl_dev_t *dev = m->private;
        int ret = get_dis_disc_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(dis_disc)
@@@ -7673,11 -7657,11 +7673,11 @@@ static int show_bypass_pwup(struct seq_
        bpctl_dev_t *dev = m->private;
        int ret = get_bypass_pwup_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(bypass_pwup)
@@@ -7697,11 -7681,11 +7697,11 @@@ static int show_bypass_pwoff(struct seq
        bpctl_dev_t *dev = m->private;
        int ret = get_bypass_pwoff_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(bypass_pwoff)
@@@ -7721,11 -7705,11 +7721,11 @@@ static int show_tap_pwup(struct seq_fil
        bpctl_dev_t *dev = m->private;
        int ret = get_tap_pwup_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(tap_pwup)
@@@ -7745,11 -7729,11 +7745,11 @@@ static int show_disc_pwup(struct seq_fi
        bpctl_dev_t *dev = m->private;
        int ret = get_disc_pwup_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(disc_pwup)
@@@ -7769,11 -7753,11 +7769,11 @@@ static int show_std_nic(struct seq_fil
        bpctl_dev_t *dev = m->private;
        int ret = get_std_nic_fn(dev);
        if (ret == BP_NOT_CAP)
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        else if (ret == 0)
 -              seq_printf(m, "off\n");
 +              seq_puts(m, "off\n");
        else
 -              seq_printf(m, "on\n");
 +              seq_puts(m, "on\n");
        return 0;
  }
  RW_FOPS(std_nic)
@@@ -7811,13 -7795,13 +7811,13 @@@ static int show_wd_exp_mode(struct seq_
        bpctl_dev_t *dev = m->private;
        int ret = get_wd_exp_mode_fn(dev);
        if (ret == 1)
 -              seq_printf(m, "tap\n");
 +              seq_puts(m, "tap\n");
        else if (ret == 0)
 -              seq_printf(m, "bypass\n");
 +              seq_puts(m, "bypass\n");
        else if (ret == 2)
 -              seq_printf(m, "disc\n");
 +              seq_puts(m, "disc\n");
        else
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        return 0;
  }
  RW_FOPS(wd_exp_mode)
@@@ -7839,7 -7823,7 +7839,7 @@@ static int show_wd_autoreset(struct seq
        if (ret >= 0)
                seq_printf(m, "%d\n", ret);
        else
 -              seq_printf(m, "fail\n");
 +              seq_puts(m, "fail\n");
        return 0;
  }
  RW_FOPS(wd_autoreset)
  int bypass_proc_create_dev_sd(bpctl_dev_t *pbp_device_block)
  {
        struct bypass_pfs_sd *current_pfs = &(pbp_device_block->bypass_pfs_set);
 -      static struct proc_dir_entry *procfs_dir = NULL;
 +      static struct proc_dir_entry *procfs_dir;
        int ret = 0;
  
        if (!pbp_device_block->ndev)
        }
        current_pfs->bypass_entry = procfs_dir;
  
 -#define ENTRY(x) ret |= procfs_add(#x, &x##_ops, pbp_device_block)
 +#define ENTRY(x) (ret |= procfs_add(#x, &x##_ops, pbp_device_block))
 +
        ENTRY(bypass_info);
        if (pbp_device_block->bp_caps & SW_CTL_CAP) {
                /* Create set param proc's */
@@@ -295,6 -295,37 +295,6 @@@ add_head
        return 0;
  }
  
 -/**
 - * virtqueue_add_buf - expose buffer to other end
 - * @vq: the struct virtqueue we're talking about.
 - * @sg: the description of the buffer(s).
 - * @out_num: the number of sg readable by other side
 - * @in_num: the number of sg which are writable (after readable ones)
 - * @data: the token identifying the buffer.
 - * @gfp: how to do memory allocations (if necessary).
 - *
 - * Caller must ensure we don't call this with other virtqueue operations
 - * at the same time (except where noted).
 - *
 - * Returns zero or a negative error (ie. ENOSPC, ENOMEM).
 - */
 -int virtqueue_add_buf(struct virtqueue *_vq,
 -                    struct scatterlist sg[],
 -                    unsigned int out,
 -                    unsigned int in,
 -                    void *data,
 -                    gfp_t gfp)
 -{
 -      struct scatterlist *sgs[2];
 -
 -      sgs[0] = sg;
 -      sgs[1] = sg + out;
 -
 -      return virtqueue_add(_vq, sgs, sg_next_arr,
 -                           out, in, out ? 1 : 0, in ? 1 : 0, data, gfp);
 -}
 -EXPORT_SYMBOL_GPL(virtqueue_add_buf);
 -
  /**
   * virtqueue_add_sgs - expose buffers to other end
   * @vq: the struct virtqueue we're talking about.
@@@ -442,7 -473,7 +442,7 @@@ EXPORT_SYMBOL_GPL(virtqueue_notify)
   * virtqueue_kick - update after add_buf
   * @vq: the struct virtqueue
   *
 - * After one or more virtqueue_add_buf calls, invoke this to kick
 + * After one or more virtqueue_add_* calls, invoke this to kick
   * the other side.
   *
   * Caller must ensure we don't call this with other virtqueue
@@@ -499,7 -530,7 +499,7 @@@ static inline bool more_used(const stru
   * operations at the same time (except where noted).
   *
   * Returns NULL if there are no used buffers, or the "data" token
 - * handed to virtqueue_add_buf().
 + * handed to virtqueue_add_*().
   */
  void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
  {
@@@ -576,19 -607,21 +576,21 @@@ void virtqueue_disable_cb(struct virtqu
  EXPORT_SYMBOL_GPL(virtqueue_disable_cb);
  
  /**
-  * virtqueue_enable_cb - restart callbacks after disable_cb.
+  * virtqueue_enable_cb_prepare - restart callbacks after disable_cb
   * @vq: the struct virtqueue we're talking about.
   *
-  * This re-enables callbacks; it returns "false" if there are pending
-  * buffers in the queue, to detect a possible race between the driver
-  * checking for more work, and enabling callbacks.
+  * This re-enables callbacks; it returns current queue state
+  * in an opaque unsigned value. This value should be later tested by
+  * virtqueue_poll, to detect a possible race between the driver checking for
+  * more work, and enabling callbacks.
   *
   * Caller must ensure we don't call this with other virtqueue
   * operations at the same time (except where noted).
   */
bool virtqueue_enable_cb(struct virtqueue *_vq)
unsigned virtqueue_enable_cb_prepare(struct virtqueue *_vq)
  {
        struct vring_virtqueue *vq = to_vvq(_vq);
+       u16 last_used_idx;
  
        START_USE(vq);
  
         * either clear the flags bit or point the event index at the next
         * entry. Always do both to keep code simple. */
        vq->vring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT;
-       vring_used_event(&vq->vring) = vq->last_used_idx;
+       vring_used_event(&vq->vring) = last_used_idx = vq->last_used_idx;
+       END_USE(vq);
+       return last_used_idx;
+ }
+ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_prepare);
+ /**
+  * virtqueue_poll - query pending used buffers
+  * @vq: the struct virtqueue we're talking about.
+  * @last_used_idx: virtqueue state (from call to virtqueue_enable_cb_prepare).
+  *
+  * Returns "true" if there are pending used buffers in the queue.
+  *
+  * This does not need to be serialized.
+  */
+ bool virtqueue_poll(struct virtqueue *_vq, unsigned last_used_idx)
+ {
+       struct vring_virtqueue *vq = to_vvq(_vq);
        virtio_mb(vq->weak_barriers);
-       if (unlikely(more_used(vq))) {
-               END_USE(vq);
-               return false;
-       }
+       return (u16)last_used_idx != vq->vring.used->idx;
+ }
+ EXPORT_SYMBOL_GPL(virtqueue_poll);
  
-       END_USE(vq);
-       return true;
+ /**
+  * virtqueue_enable_cb - restart callbacks after disable_cb.
+  * @vq: the struct virtqueue we're talking about.
+  *
+  * This re-enables callbacks; it returns "false" if there are pending
+  * buffers in the queue, to detect a possible race between the driver
+  * checking for more work, and enabling callbacks.
+  *
+  * Caller must ensure we don't call this with other virtqueue
+  * operations at the same time (except where noted).
+  */
+ bool virtqueue_enable_cb(struct virtqueue *_vq)
+ {
+       unsigned last_used_idx = virtqueue_enable_cb_prepare(_vq);
+       return !virtqueue_poll(_vq, last_used_idx);
  }
  EXPORT_SYMBOL_GPL(virtqueue_enable_cb);
  
@@@ -654,7 -717,7 +686,7 @@@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_d
   * virtqueue_detach_unused_buf - detach first unused buffer
   * @vq: the struct virtqueue we're talking about.
   *
 - * Returns NULL or the "data" token handed to virtqueue_add_buf().
 + * Returns NULL or the "data" token handed to virtqueue_add_*().
   * This is not valid on an active queue; it is useful only for device
   * shutdown.
   */
diff --combined fs/select.c
@@@ -27,7 -27,7 +27,8 @@@
  #include <linux/rcupdate.h>
  #include <linux/hrtimer.h>
  #include <linux/sched/rt.h>
 +#include <linux/freezer.h>
+ #include <net/ll_poll.h>
  
  #include <asm/uaccess.h>
  
@@@ -237,8 -237,7 +238,8 @@@ int poll_schedule_timeout(struct poll_w
  
        set_current_state(state);
        if (!pwq->triggered)
 -              rc = schedule_hrtimeout_range(expires, slack, HRTIMER_MODE_ABS);
 +              rc = freezable_schedule_hrtimeout_range(expires, slack,
 +                                                      HRTIMER_MODE_ABS);
        __set_current_state(TASK_RUNNING);
  
        /*
@@@ -386,9 -385,10 +387,10 @@@ get_max
  #define POLLEX_SET (POLLPRI)
  
  static inline void wait_key_set(poll_table *wait, unsigned long in,
-                               unsigned long out, unsigned long bit)
+                               unsigned long out, unsigned long bit,
+                               unsigned int ll_flag)
  {
-       wait->_key = POLLEX_SET;
+       wait->_key = POLLEX_SET | ll_flag;
        if (in & bit)
                wait->_key |= POLLIN_SET;
        if (out & bit)
@@@ -402,6 -402,8 +404,8 @@@ int do_select(int n, fd_set_bits *fds, 
        poll_table *wait;
        int retval, i, timed_out = 0;
        unsigned long slack = 0;
+       unsigned int busy_flag = net_busy_loop_on() ? POLL_BUSY_LOOP : 0;
+       unsigned long busy_end = 0;
  
        rcu_read_lock();
        retval = max_select_fd(n, fds);
        retval = 0;
        for (;;) {
                unsigned long *rinp, *routp, *rexp, *inp, *outp, *exp;
+               bool can_busy_loop = false;
  
                inp = fds->in; outp = fds->out; exp = fds->ex;
                rinp = fds->res_in; routp = fds->res_out; rexp = fds->res_ex;
                                        f_op = f.file->f_op;
                                        mask = DEFAULT_POLLMASK;
                                        if (f_op && f_op->poll) {
-                                               wait_key_set(wait, in, out, bit);
+                                               wait_key_set(wait, in, out,
+                                                            bit, busy_flag);
                                                mask = (*f_op->poll)(f.file, wait);
                                        }
                                        fdput(f);
                                                retval++;
                                                wait->_qproc = NULL;
                                        }
+                                       /* got something, stop busy polling */
+                                       if (retval) {
+                                               can_busy_loop = false;
+                                               busy_flag = 0;
+                                       /*
+                                        * only remember a returned
+                                        * POLL_BUSY_LOOP if we asked for it
+                                        */
+                                       } else if (busy_flag & mask)
+                                               can_busy_loop = true;
                                }
                        }
                        if (res_in)
                        break;
                }
  
+               /* only if found POLL_BUSY_LOOP sockets && not out of time */
+               if (can_busy_loop && !need_resched()) {
+                       if (!busy_end) {
+                               busy_end = busy_loop_end_time();
+                               continue;
+                       }
+                       if (!busy_loop_timeout(busy_end))
+                               continue;
+               }
+               busy_flag = 0;
                /*
                 * If this is the first loop and we have a timeout
                 * given, then we convert to ktime_t and set the to
@@@ -719,7 -746,9 +748,9 @@@ struct poll_list 
   * pwait poll_table will be used by the fd-provided poll handler for waiting,
   * if pwait->_qproc is non-NULL.
   */
- static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait)
+ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait,
+                                    bool *can_busy_poll,
+                                    unsigned int busy_flag)
  {
        unsigned int mask;
        int fd;
                        mask = DEFAULT_POLLMASK;
                        if (f.file->f_op && f.file->f_op->poll) {
                                pwait->_key = pollfd->events|POLLERR|POLLHUP;
+                               pwait->_key |= busy_flag;
                                mask = f.file->f_op->poll(f.file, pwait);
+                               if (mask & busy_flag)
+                                       *can_busy_poll = true;
                        }
                        /* Mask out unneeded events. */
                        mask &= pollfd->events | POLLERR | POLLHUP;
@@@ -752,6 -784,8 +786,8 @@@ static int do_poll(unsigned int nfds,  
        ktime_t expire, *to = NULL;
        int timed_out = 0, count = 0;
        unsigned long slack = 0;
+       unsigned int busy_flag = net_busy_loop_on() ? POLL_BUSY_LOOP : 0;
+       unsigned long busy_end = 0;
  
        /* Optimise the no-wait case */
        if (end_time && !end_time->tv_sec && !end_time->tv_nsec) {
  
        for (;;) {
                struct poll_list *walk;
+               bool can_busy_loop = false;
  
                for (walk = list; walk != NULL; walk = walk->next) {
                        struct pollfd * pfd, * pfd_end;
                                 * this. They'll get immediately deregistered
                                 * when we break out and return.
                                 */
-                               if (do_pollfd(pfd, pt)) {
+                               if (do_pollfd(pfd, pt, &can_busy_loop,
+                                             busy_flag)) {
                                        count++;
                                        pt->_qproc = NULL;
+                                       /* found something, stop busy polling */
+                                       busy_flag = 0;
+                                       can_busy_loop = false;
                                }
                        }
                }
                if (count || timed_out)
                        break;
  
+               /* only if found POLL_BUSY_LOOP sockets && not out of time */
+               if (can_busy_loop && !need_resched()) {
+                       if (!busy_end) {
+                               busy_end = busy_loop_end_time();
+                               continue;
+                       }
+                       if (!busy_loop_timeout(busy_end))
+                               continue;
+               }
+               busy_flag = 0;
                /*
                 * If this is the first loop and we have a timeout
                 * given, then we convert to ktime_t and set the to
diff --combined include/linux/ktime.h
@@@ -229,8 -229,7 +229,8 @@@ static inline ktime_t timespec_to_ktime
  static inline ktime_t timeval_to_ktime(const struct timeval tv)
  {
        return (ktime_t) { .tv = { .sec = (s32)tv.tv_sec,
 -                                 .nsec = (s32)tv.tv_usec * 1000 } };
 +                                 .nsec = (s32)(tv.tv_usec *
 +                                               NSEC_PER_USEC) } };
  }
  
  /**
@@@ -321,12 -320,17 +321,17 @@@ static inline s64 ktime_us_delta(const 
  
  static inline ktime_t ktime_add_us(const ktime_t kt, const u64 usec)
  {
 -      return ktime_add_ns(kt, usec * 1000);
 +      return ktime_add_ns(kt, usec * NSEC_PER_USEC);
  }
  
+ static inline ktime_t ktime_add_ms(const ktime_t kt, const u64 msec)
+ {
+       return ktime_add_ns(kt, msec * NSEC_PER_MSEC);
+ }
  static inline ktime_t ktime_sub_us(const ktime_t kt, const u64 usec)
  {
 -      return ktime_sub_ns(kt, usec * 1000);
 +      return ktime_sub_ns(kt, usec * NSEC_PER_USEC);
  }
  
  extern ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs);
   *
   * Returns true if there was a successful conversion, false if kt was 0.
   */
 -static inline bool ktime_to_timespec_cond(const ktime_t kt, struct timespec *ts)
 +static inline __must_check bool ktime_to_timespec_cond(const ktime_t kt,
 +                                                     struct timespec *ts)
  {
        if (kt.tv64) {
                *ts = ktime_to_timespec(kt);
@@@ -368,7 -371,15 +373,15 @@@ extern void ktime_get_ts(struct timespe
  static inline ktime_t ns_to_ktime(u64 ns)
  {
        static const ktime_t ktime_zero = { .tv64 = 0 };
        return ktime_add_ns(ktime_zero, ns);
  }
  
+ static inline ktime_t ms_to_ktime(u64 ms)
+ {
+       static const ktime_t ktime_zero = { .tv64 = 0 };
+       return ktime_add_ms(ktime_zero, ms);
+ }
  #endif
diff --combined include/linux/sched.h
@@@ -924,7 -924,7 +924,7 @@@ struct load_weight 
  struct sched_avg {
        /*
         * These sums represent an infinite geometric series and so are bound
 -       * above by 1024/(1-y).  Thus we only need a u32 to store them for for all
 +       * above by 1024/(1-y).  Thus we only need a u32 to store them for all
         * choices of y < 1-2^(-32)*1024.
         */
        u32 runnable_avg_sum, runnable_avg_period;
@@@ -994,7 -994,12 +994,7 @@@ struct sched_entity 
        struct cfs_rq           *my_q;
  #endif
  
 -/*
 - * Load-tracking only depends on SMP, FAIR_GROUP_SCHED dependency below may be
 - * removed when useful for applications beyond shares distribution (e.g.
 - * load-balance).
 - */
 -#if defined(CONFIG_SMP) && defined(CONFIG_FAIR_GROUP_SCHED)
 +#ifdef CONFIG_SMP
        /* Per-entity load-tracking */
        struct sched_avg        avg;
  #endif
@@@ -1401,6 -1406,9 +1401,6 @@@ struct task_struct 
        } memcg_batch;
        unsigned int memcg_kmem_skip_account;
  #endif
 -#ifdef CONFIG_HAVE_HW_BREAKPOINT
 -      atomic_t ptrace_bp_refcnt;
 -#endif
  #ifdef CONFIG_UPROBES
        struct uprobe_task *utask;
  #endif
@@@ -1947,6 -1955,8 +1947,6 @@@ extern struct task_struct *find_task_by
  extern struct task_struct *find_task_by_pid_ns(pid_t nr,
                struct pid_namespace *ns);
  
 -extern void __set_special_pids(struct pid *pid);
 -
  /* per-UID process charging. */
  extern struct user_struct * alloc_uid(kuid_t);
  static inline struct user_struct *get_uid(struct user_struct *u)
@@@ -2434,6 -2444,15 +2434,15 @@@ extern int __cond_resched_softirq(void)
        __cond_resched_softirq();                                       \
  })
  
+ static inline void cond_resched_rcu(void)
+ {
+ #if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
+       rcu_read_unlock();
+       cond_resched();
+       rcu_read_lock();
+ #endif
+ }
  /*
   * Does a critical section need to be broken due to another
   * task waiting?: (technically does not depend on CONFIG_PREEMPT,
diff --combined include/linux/virtio.h
@@@ -34,6 -34,13 +34,6 @@@ struct virtqueue 
        void *priv;
  };
  
 -int virtqueue_add_buf(struct virtqueue *vq,
 -                    struct scatterlist sg[],
 -                    unsigned int out_num,
 -                    unsigned int in_num,
 -                    void *data,
 -                    gfp_t gfp);
 -
  int virtqueue_add_outbuf(struct virtqueue *vq,
                         struct scatterlist sg[], unsigned int num,
                         void *data,
@@@ -63,6 -70,10 +63,10 @@@ void virtqueue_disable_cb(struct virtqu
  
  bool virtqueue_enable_cb(struct virtqueue *vq);
  
+ unsigned virtqueue_enable_cb_prepare(struct virtqueue *vq);
+ bool virtqueue_poll(struct virtqueue *vq, unsigned);
  bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
  
  void *virtqueue_detach_unused_buf(struct virtqueue *vq);
diff --combined lib/vsprintf.c
@@@ -670,7 -670,7 +670,7 @@@ static noinline_for_stac
  char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
                 const char *fmt)
  {
 -      int i, len = 1;         /* if we pass '%ph[CDN]', field witdh remains
 +      int i, len = 1;         /* if we pass '%ph[CDN]', field width remains
                                   negative value, fallback to the default */
        char separator;
  
@@@ -922,6 -922,103 +922,103 @@@ char *ip4_addr_string(char *buf, char *
        return string(buf, end, ip4_addr, spec);
  }
  
+ static noinline_for_stack
+ char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa,
+                        struct printf_spec spec, const char *fmt)
+ {
+       bool have_p = false, have_s = false, have_f = false, have_c = false;
+       char ip6_addr[sizeof("[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255]") +
+                     sizeof(":12345") + sizeof("/123456789") +
+                     sizeof("%1234567890")];
+       char *p = ip6_addr, *pend = ip6_addr + sizeof(ip6_addr);
+       const u8 *addr = (const u8 *) &sa->sin6_addr;
+       char fmt6[2] = { fmt[0], '6' };
+       u8 off = 0;
+       fmt++;
+       while (isalpha(*++fmt)) {
+               switch (*fmt) {
+               case 'p':
+                       have_p = true;
+                       break;
+               case 'f':
+                       have_f = true;
+                       break;
+               case 's':
+                       have_s = true;
+                       break;
+               case 'c':
+                       have_c = true;
+                       break;
+               }
+       }
+       if (have_p || have_s || have_f) {
+               *p = '[';
+               off = 1;
+       }
+       if (fmt6[0] == 'I' && have_c)
+               p = ip6_compressed_string(ip6_addr + off, addr);
+       else
+               p = ip6_string(ip6_addr + off, addr, fmt6);
+       if (have_p || have_s || have_f)
+               *p++ = ']';
+       if (have_p) {
+               *p++ = ':';
+               p = number(p, pend, ntohs(sa->sin6_port), spec);
+       }
+       if (have_f) {
+               *p++ = '/';
+               p = number(p, pend, ntohl(sa->sin6_flowinfo &
+                                         IPV6_FLOWINFO_MASK), spec);
+       }
+       if (have_s) {
+               *p++ = '%';
+               p = number(p, pend, sa->sin6_scope_id, spec);
+       }
+       *p = '\0';
+       return string(buf, end, ip6_addr, spec);
+ }
+ static noinline_for_stack
+ char *ip4_addr_string_sa(char *buf, char *end, const struct sockaddr_in *sa,
+                        struct printf_spec spec, const char *fmt)
+ {
+       bool have_p = false;
+       char *p, ip4_addr[sizeof("255.255.255.255") + sizeof(":12345")];
+       char *pend = ip4_addr + sizeof(ip4_addr);
+       const u8 *addr = (const u8 *) &sa->sin_addr.s_addr;
+       char fmt4[3] = { fmt[0], '4', 0 };
+       fmt++;
+       while (isalpha(*++fmt)) {
+               switch (*fmt) {
+               case 'p':
+                       have_p = true;
+                       break;
+               case 'h':
+               case 'l':
+               case 'n':
+               case 'b':
+                       fmt4[2] = *fmt;
+                       break;
+               }
+       }
+       p = ip4_string(ip4_addr, addr, fmt4);
+       if (have_p) {
+               *p++ = ':';
+               p = number(p, pend, ntohs(sa->sin_port), spec);
+       }
+       *p = '\0';
+       return string(buf, end, ip4_addr, spec);
+ }
  static noinline_for_stack
  char *uuid_string(char *buf, char *end, const u8 *addr,
                  struct printf_spec spec, const char *fmt)
@@@ -1007,11 -1104,17 +1104,17 @@@ int kptr_restrict __read_mostly
   * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
   *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
   *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
+  *       [S][pfs]
+  *       Generic IPv4/IPv6 address (struct sockaddr *) that falls back to
+  *       [4] or [6] and is able to print port [p], flowinfo [f], scope [s]
   * - 'i' [46] for 'raw' IPv4/IPv6 addresses
   *       IPv6 omits the colons (01020304...0f)
   *       IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
-  * - '[Ii]4[hnbl]' IPv4 addresses in host, network, big or little endian order
-  * - 'I6c' for IPv6 addresses printed as specified by
+  *       [S][pfs]
+  *       Generic IPv4/IPv6 address (struct sockaddr *) that falls back to
+  *       [4] or [6] and is able to print port [p], flowinfo [f], scope [s]
+  * - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order
+  * - 'I[6S]c' for IPv6 addresses printed as specified by
   *       http://tools.ietf.org/html/rfc5952
   * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
   *       "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@@@ -1093,6 -1196,21 +1196,21 @@@ char *pointer(const char *fmt, char *bu
                        return ip6_addr_string(buf, end, ptr, spec, fmt);
                case '4':
                        return ip4_addr_string(buf, end, ptr, spec, fmt);
+               case 'S': {
+                       const union {
+                               struct sockaddr         raw;
+                               struct sockaddr_in      v4;
+                               struct sockaddr_in6     v6;
+                       } *sa = ptr;
+                       switch (sa->raw.sa_family) {
+                       case AF_INET:
+                               return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt);
+                       case AF_INET6:
+                               return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt);
+                       default:
+                               return string(buf, end, "(invalid address)", spec);
+                       }}
                }
                break;
        case 'U':
@@@ -1370,6 -1488,8 +1488,8 @@@ qualifier
   * %pI6 print an IPv6 address with colons
   * %pi6 print an IPv6 address without colons
   * %pI6c print an IPv6 address as specified by RFC 5952
+  * %pIS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address
+  * %piS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address
   * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
   *   case.
   * %*ph[CDN] a variable-length hex string with a separator (supports up to 64
diff --combined net/Kconfig
@@@ -5,7 -5,6 +5,7 @@@
  menuconfig NET
        bool "Networking support"
        select NLATTR
 +      select GENERIC_NET_UTILS
        ---help---
          Unless you really know what you are doing, you should say Y here.
          The reason is that some programs need kernel networking support even
@@@ -219,6 -218,7 +219,7 @@@ source "net/batman-adv/Kconfig
  source "net/openvswitch/Kconfig"
  source "net/vmw_vsock/Kconfig"
  source "net/netlink/Kconfig"
+ source "net/mpls/Kconfig"
  
  config RPS
        boolean
@@@ -243,6 -243,10 +244,10 @@@ config NETPRIO_CGROU
          Cgroup subsystem for use in assigning processes to network priorities on
          a per-interface basis
  
+ config NET_LL_RX_POLL
+       boolean
+       default y
  config BQL
        boolean
        depends on SYSFS
@@@ -260,6 -264,18 +265,18 @@@ config BPF_JI
          packet sniffing (libpcap/tcpdump). Note : Admin should enable
          this feature changing /proc/sys/net/core/bpf_jit_enable
  
+ config NET_FLOW_LIMIT
+       boolean
+       depends on RPS
+       default y
+       ---help---
+         The network stack has to drop packets when a receive processing CPU's
+         backlog reaches netdev_max_backlog. If a few out of many active flows
+         generate the vast majority of load, drop their traffic earlier to
+         maintain capacity for the other flows. This feature provides servers
+         with many clients some protection against DoS by a single (spoofed)
+         flow that greatly exceeds average workload.
  menu "Network testing"
  
  config NET_PKTGEN
diff --combined net/bluetooth/hci_core.c
@@@ -597,7 -597,15 +597,15 @@@ static void hci_init3_req(struct hci_re
        struct hci_dev *hdev = req->hdev;
        u8 p;
  
-       /* Only send HCI_Delete_Stored_Link_Key if it is supported */
+       /* Some Broadcom based Bluetooth controllers do not support the
+        * Delete Stored Link Key command. They are clearly indicating its
+        * absence in the bit mask of supported commands.
+        *
+        * Check the supported commands and only if the the command is marked
+        * as supported send it. If not supported assume that the controller
+        * does not have actual support for stored link keys which makes this
+        * command redundant anyway.
+          */
        if (hdev->commands[6] & 0x80) {
                struct hci_cp_delete_stored_link_key cp;
  
@@@ -751,7 -759,7 +759,7 @@@ void hci_discovery_set_state(struct hci
        hdev->discovery.state = state;
  }
  
static void inquiry_cache_flush(struct hci_dev *hdev)
void hci_inquiry_cache_flush(struct hci_dev *hdev)
  {
        struct discovery_state *cache = &hdev->discovery;
        struct inquiry_entry *p, *n;
@@@ -964,7 -972,7 +972,7 @@@ int hci_inquiry(void __user *arg
        hci_dev_lock(hdev);
        if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX ||
            inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) {
-               inquiry_cache_flush(hdev);
+               hci_inquiry_cache_flush(hdev);
                do_inquiry = 1;
        }
        hci_dev_unlock(hdev);
@@@ -1201,8 -1209,6 +1209,6 @@@ static int hci_dev_do_close(struct hci_
  {
        BT_DBG("%s %p", hdev->name, hdev);
  
-       cancel_work_sync(&hdev->le_scan);
        cancel_delayed_work(&hdev->power_off);
  
        hci_req_cancel(hdev, ENODEV);
        cancel_delayed_work_sync(&hdev->le_scan_disable);
  
        hci_dev_lock(hdev);
-       inquiry_cache_flush(hdev);
+       hci_inquiry_cache_flush(hdev);
        hci_conn_hash_flush(hdev);
        hci_dev_unlock(hdev);
  
@@@ -1331,7 -1337,7 +1337,7 @@@ int hci_dev_reset(__u16 dev
        skb_queue_purge(&hdev->cmd_q);
  
        hci_dev_lock(hdev);
-       inquiry_cache_flush(hdev);
+       hci_inquiry_cache_flush(hdev);
        hci_conn_hash_flush(hdev);
        hci_dev_unlock(hdev);
  
@@@ -1991,80 -1997,59 +1997,59 @@@ int hci_blacklist_del(struct hci_dev *h
        return mgmt_device_unblocked(hdev, bdaddr, type);
  }
  
- static void le_scan_param_req(struct hci_request *req, unsigned long opt)
+ static void inquiry_complete(struct hci_dev *hdev, u8 status)
  {
-       struct le_scan_params *param =  (struct le_scan_params *) opt;
-       struct hci_cp_le_set_scan_param cp;
-       memset(&cp, 0, sizeof(cp));
-       cp.type = param->type;
-       cp.interval = cpu_to_le16(param->interval);
-       cp.window = cpu_to_le16(param->window);
+       if (status) {
+               BT_ERR("Failed to start inquiry: status %d", status);
  
-       hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(cp), &cp);
- }
- static void le_scan_enable_req(struct hci_request *req, unsigned long opt)
- {
-       struct hci_cp_le_set_scan_enable cp;
-       memset(&cp, 0, sizeof(cp));
-       cp.enable = LE_SCAN_ENABLE;
-       cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
-       hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
+               hci_dev_lock(hdev);
+               hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+               hci_dev_unlock(hdev);
+               return;
+       }
  }
  
- static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
-                         u16 window, int timeout)
+ static void le_scan_disable_work_complete(struct hci_dev *hdev, u8 status)
  {
-       long timeo = msecs_to_jiffies(3000);
-       struct le_scan_params param;
+       /* General inquiry access code (GIAC) */
+       u8 lap[3] = { 0x33, 0x8b, 0x9e };
+       struct hci_request req;
+       struct hci_cp_inquiry cp;
        int err;
  
-       BT_DBG("%s", hdev->name);
-       if (test_bit(HCI_LE_SCAN, &hdev->dev_flags))
-               return -EINPROGRESS;
-       param.type = type;
-       param.interval = interval;
-       param.window = window;
-       hci_req_lock(hdev);
-       err = __hci_req_sync(hdev, le_scan_param_req, (unsigned long) &param,
-                            timeo);
-       if (!err)
-               err = __hci_req_sync(hdev, le_scan_enable_req, 0, timeo);
-       hci_req_unlock(hdev);
+       if (status) {
+               BT_ERR("Failed to disable LE scanning: status %d", status);
+               return;
+       }
  
-       if (err < 0)
-               return err;
+       switch (hdev->discovery.type) {
+       case DISCOV_TYPE_LE:
+               hci_dev_lock(hdev);
+               hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+               hci_dev_unlock(hdev);
+               break;
  
-       queue_delayed_work(hdev->workqueue, &hdev->le_scan_disable,
-                          timeout);
+       case DISCOV_TYPE_INTERLEAVED:
+               hci_req_init(&req, hdev);
  
-       return 0;
- }
+               memset(&cp, 0, sizeof(cp));
+               memcpy(&cp.lap, lap, sizeof(cp.lap));
+               cp.length = DISCOV_INTERLEAVED_INQUIRY_LEN;
+               hci_req_add(&req, HCI_OP_INQUIRY, sizeof(cp), &cp);
  
- int hci_cancel_le_scan(struct hci_dev *hdev)
- {
-       BT_DBG("%s", hdev->name);
+               hci_dev_lock(hdev);
  
-       if (!test_bit(HCI_LE_SCAN, &hdev->dev_flags))
-               return -EALREADY;
+               hci_inquiry_cache_flush(hdev);
  
-       if (cancel_delayed_work(&hdev->le_scan_disable)) {
-               struct hci_cp_le_set_scan_enable cp;
+               err = hci_req_run(&req, inquiry_complete);
+               if (err) {
+                       BT_ERR("Inquiry request failed: err %d", err);
+                       hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+               }
  
-               /* Send HCI command to disable LE Scan */
-               memset(&cp, 0, sizeof(cp));
-               hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
+               hci_dev_unlock(hdev);
+               break;
        }
-       return 0;
  }
  
  static void le_scan_disable_work(struct work_struct *work)
        struct hci_dev *hdev = container_of(work, struct hci_dev,
                                            le_scan_disable.work);
        struct hci_cp_le_set_scan_enable cp;
+       struct hci_request req;
+       int err;
  
        BT_DBG("%s", hdev->name);
  
-       memset(&cp, 0, sizeof(cp));
-       hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
- }
- static void le_scan_work(struct work_struct *work)
- {
-       struct hci_dev *hdev = container_of(work, struct hci_dev, le_scan);
-       struct le_scan_params *param = &hdev->le_scan_params;
+       hci_req_init(&req, hdev);
  
-       BT_DBG("%s", hdev->name);
+       memset(&cp, 0, sizeof(cp));
+       cp.enable = LE_SCAN_DISABLE;
+       hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
  
-       hci_do_le_scan(hdev, param->type, param->interval, param->window,
-                      param->timeout);
- }
- int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
-               int timeout)
- {
-       struct le_scan_params *param = &hdev->le_scan_params;
-       BT_DBG("%s", hdev->name);
-       if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags))
-               return -ENOTSUPP;
-       if (work_busy(&hdev->le_scan))
-               return -EINPROGRESS;
-       param->type = type;
-       param->interval = interval;
-       param->window = window;
-       param->timeout = timeout;
-       queue_work(system_long_wq, &hdev->le_scan);
-       return 0;
+       err = hci_req_run(&req, le_scan_disable_work_complete);
+       if (err)
+               BT_ERR("Disable LE scanning request failed: err %d", err);
  }
  
  /* Alloc HCI device */
@@@ -2148,7 -2107,6 +2107,6 @@@ struct hci_dev *hci_alloc_dev(void
        INIT_WORK(&hdev->cmd_work, hci_cmd_work);
        INIT_WORK(&hdev->tx_work, hci_tx_work);
        INIT_WORK(&hdev->power_on, hci_power_on);
-       INIT_WORK(&hdev->le_scan, le_scan_work);
  
        INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
        INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);
@@@ -2211,15 -2169,16 +2169,15 @@@ int hci_register_dev(struct hci_dev *hd
        list_add(&hdev->list, &hci_dev_list);
        write_unlock(&hci_dev_list_lock);
  
 -      hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
 -                                        WQ_MEM_RECLAIM, 1);
 +      hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
 +                                        WQ_MEM_RECLAIM, 1, hdev->name);
        if (!hdev->workqueue) {
                error = -ENOMEM;
                goto err;
        }
  
 -      hdev->req_workqueue = alloc_workqueue(hdev->name,
 -                                            WQ_HIGHPRI | WQ_UNBOUND |
 -                                            WQ_MEM_RECLAIM, 1);
 +      hdev->req_workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
 +                                            WQ_MEM_RECLAIM, 1, hdev->name);
        if (!hdev->req_workqueue) {
                destroy_workqueue(hdev->workqueue);
                error = -ENOMEM;
@@@ -3550,36 -3509,6 +3508,6 @@@ static void hci_cmd_work(struct work_st
        }
  }
  
- int hci_do_inquiry(struct hci_dev *hdev, u8 length)
- {
-       /* General inquiry access code (GIAC) */
-       u8 lap[3] = { 0x33, 0x8b, 0x9e };
-       struct hci_cp_inquiry cp;
-       BT_DBG("%s", hdev->name);
-       if (test_bit(HCI_INQUIRY, &hdev->flags))
-               return -EINPROGRESS;
-       inquiry_cache_flush(hdev);
-       memset(&cp, 0, sizeof(cp));
-       memcpy(&cp.lap, lap, sizeof(cp.lap));
-       cp.length  = length;
-       return hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp);
- }
- int hci_cancel_inquiry(struct hci_dev *hdev)
- {
-       BT_DBG("%s", hdev->name);
-       if (!test_bit(HCI_INQUIRY, &hdev->flags))
-               return -EALREADY;
-       return hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
- }
  u8 bdaddr_to_le(u8 bdaddr_type)
  {
        switch (bdaddr_type) {
@@@ -76,25 -76,19 +76,19 @@@ static void hidp_copy_session(struct hi
        ci->flags = session->flags;
        ci->state = BT_CONNECTED;
  
-       ci->vendor  = 0x0000;
-       ci->product = 0x0000;
-       ci->version = 0x0000;
        if (session->input) {
                ci->vendor  = session->input->id.vendor;
                ci->product = session->input->id.product;
                ci->version = session->input->id.version;
                if (session->input->name)
-                       strncpy(ci->name, session->input->name, 128);
+                       strlcpy(ci->name, session->input->name, 128);
                else
-                       strncpy(ci->name, "HID Boot Device", 128);
-       }
-       if (session->hid) {
+                       strlcpy(ci->name, "HID Boot Device", 128);
+       } else if (session->hid) {
                ci->vendor  = session->hid->vendor;
                ci->product = session->hid->product;
                ci->version = session->hid->version;
-               strncpy(ci->name, session->hid->name, 128);
+               strlcpy(ci->name, session->hid->name, 128);
        }
  }
  
@@@ -850,29 -844,6 +844,29 @@@ static void hidp_session_dev_del(struc
                input_unregister_device(session->input);
  }
  
 +/*
 + * Asynchronous device registration
 + * HID device drivers might want to perform I/O during initialization to
 + * detect device types. Therefore, call device registration in a separate
 + * worker so the HIDP thread can schedule I/O operations.
 + * Note that this must be called after the worker thread was initialized
 + * successfully. This will then add the devices and increase session state
 + * on success, otherwise it will terminate the session thread.
 + */
 +static void hidp_session_dev_work(struct work_struct *work)
 +{
 +      struct hidp_session *session = container_of(work,
 +                                                  struct hidp_session,
 +                                                  dev_init);
 +      int ret;
 +
 +      ret = hidp_session_dev_add(session);
 +      if (!ret)
 +              atomic_inc(&session->state);
 +      else
 +              hidp_session_terminate(session);
 +}
 +
  /*
   * Create new session object
   * Allocate session object, initialize static fields, copy input data into the
@@@ -920,7 -891,6 +914,7 @@@ static int hidp_session_new(struct hidp
        session->idle_to = req->idle_to;
  
        /* device management */
 +      INIT_WORK(&session->dev_init, hidp_session_dev_work);
        setup_timer(&session->timer, hidp_idle_timeout,
                    (unsigned long)session);
  
@@@ -1059,8 -1029,8 +1053,8 @@@ static void hidp_session_terminate(stru
   * Probe HIDP session
   * This is called from the l2cap_conn core when our l2cap_user object is bound
   * to the hci-connection. We get the session via the \user object and can now
 - * start the session thread, register the HID/input devices and link it into
 - * the global session list.
 + * start the session thread, link it into the global session list and
 + * schedule HID/input device registration.
   * The global session-list owns its own reference to the session object so you
   * can drop your own reference after registering the l2cap_user object.
   */
@@@ -1082,30 -1052,21 +1076,30 @@@ static int hidp_session_probe(struct l2
                goto out_unlock;
        }
  
 +      if (session->input) {
 +              ret = hidp_session_dev_add(session);
 +              if (ret)
 +                      goto out_unlock;
 +      }
 +
        ret = hidp_session_start_sync(session);
        if (ret)
 -              goto out_unlock;
 +              goto out_del;
  
 -      ret = hidp_session_dev_add(session);
 -      if (ret)
 -              goto out_stop;
 +      /* HID device registration is async to allow I/O during probe */
 +      if (session->input)
 +              atomic_inc(&session->state);
 +      else
 +              schedule_work(&session->dev_init);
  
        hidp_session_get(session);
        list_add(&session->list, &hidp_session_list);
        ret = 0;
        goto out_unlock;
  
 -out_stop:
 -      hidp_session_terminate(session);
 +out_del:
 +      if (session->input)
 +              hidp_session_dev_del(session);
  out_unlock:
        up_write(&hidp_session_sem);
        return ret;
@@@ -1135,12 -1096,7 +1129,12 @@@ static void hidp_session_remove(struct 
        down_write(&hidp_session_sem);
  
        hidp_session_terminate(session);
 -      hidp_session_dev_del(session);
 +
 +      cancel_work_sync(&session->dev_init);
 +      if (session->input ||
 +          atomic_read(&session->state) > HIDP_SESSION_PREPARING)
 +              hidp_session_dev_del(session);
 +
        list_del(&session->list);
  
        up_write(&hidp_session_sem);
diff --combined net/core/netpoll.c
@@@ -12,7 -12,6 +12,7 @@@
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  
  #include <linux/moduleparam.h>
 +#include <linux/kernel.h>
  #include <linux/netdevice.h>
  #include <linux/etherdevice.h>
  #include <linux/string.h>
@@@ -248,7 -247,7 +248,7 @@@ static void netpoll_poll_dev(struct net
        zap_completion_queue();
  }
  
int netpoll_rx_disable(struct net_device *dev)
void netpoll_rx_disable(struct net_device *dev)
  {
        struct netpoll_info *ni;
        int idx;
        if (ni)
                down(&ni->dev_lock);
        srcu_read_unlock(&netpoll_srcu, idx);
-       return 0;
  }
  EXPORT_SYMBOL(netpoll_rx_disable);
  
@@@ -691,25 -689,20 +690,20 @@@ static void netpoll_neigh_reply(struct 
                        send_skb->dev = skb->dev;
  
                        skb_reset_network_header(send_skb);
-                       skb_put(send_skb, sizeof(struct ipv6hdr));
-                       hdr = ipv6_hdr(send_skb);
+                       hdr = (struct ipv6hdr *) skb_put(send_skb, sizeof(struct ipv6hdr));
                        *(__be32*)hdr = htonl(0x60000000);
                        hdr->payload_len = htons(size);
                        hdr->nexthdr = IPPROTO_ICMPV6;
                        hdr->hop_limit = 255;
                        hdr->saddr = *saddr;
                        hdr->daddr = *daddr;
  
-                       send_skb->transport_header = send_skb->tail;
-                       skb_put(send_skb, size);
-                       icmp6h = (struct icmp6hdr *)skb_transport_header(skb);
+                       icmp6h = (struct icmp6hdr *) skb_put(send_skb, sizeof(struct icmp6hdr));
                        icmp6h->icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
                        icmp6h->icmp6_router = 0;
                        icmp6h->icmp6_solicited = 1;
-                       target = (struct in6_addr *)(skb_transport_header(send_skb) + sizeof(struct icmp6hdr));
+                       target = (struct in6_addr *) skb_put(send_skb, sizeof(struct in6_addr));
                        *target = msg->target;
                        icmp6h->icmp6_cksum = csum_ipv6_magic(saddr, daddr, size,
                                                              IPPROTO_ICMPV6,
diff --combined net/ipv4/inet_fragment.c
@@@ -93,7 -93,7 +93,7 @@@ void inet_frags_init(struct inet_frags 
        }
        rwlock_init(&f->lock);
  
 -      f->rnd = (u32) ((num_physpages ^ (num_physpages>>7)) ^
 +      f->rnd = (u32) ((totalram_pages ^ (totalram_pages >> 7)) ^
                                   (jiffies ^ (jiffies >> 6)));
  
        setup_timer(&f->secret_timer, inet_frag_secret_rebuild,
@@@ -247,8 -247,6 +247,6 @@@ static struct inet_frag_queue *inet_fra
  {
        struct inet_frag_bucket *hb;
        struct inet_frag_queue *qp;
- #ifdef CONFIG_SMP
- #endif
        unsigned int hash;
  
        read_lock(&f->lock); /* Protects against hash rebuild */
diff --combined net/mac80211/main.c
@@@ -331,7 -331,7 +331,7 @@@ static int ieee80211_ifa_changed(struc
                return NOTIFY_DONE;
  
        ifmgd = &sdata->u.mgd;
-       mutex_lock(&ifmgd->mtx);
+       sdata_lock(sdata);
  
        /* Copy the addresses to the bss_conf list */
        ifa = idev->ifa_list;
                ieee80211_bss_info_change_notify(sdata,
                                                 BSS_CHANGED_ARP_FILTER);
  
-       mutex_unlock(&ifmgd->mtx);
+       sdata_unlock(sdata);
  
        return NOTIFY_DONE;
  }
@@@ -686,8 -686,7 +686,7 @@@ int ieee80211_register_hw(struct ieee80
                return -EINVAL;
  
  #ifdef CONFIG_PM
-       if ((hw->wiphy->wowlan.flags || hw->wiphy->wowlan.n_patterns) &&
-           (!local->ops->suspend || !local->ops->resume))
+       if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
                return -EINVAL;
  #endif
  
                hw->queues = IEEE80211_MAX_QUEUES;
  
        local->workqueue =
 -              alloc_ordered_workqueue(wiphy_name(local->hw.wiphy), 0);
 +              alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
        if (!local->workqueue) {
                result = -ENOMEM;
                goto fail_workqueue;