2
0
Эх сурвалжийг харах

Merge remote-tracking branch 'upstream/master'

L. D. Pinney 7 жил өмнө
parent
commit
0282f99cc8
100 өөрчлөгдсөн 5611 нэмэгдсэн , 689 устгасан
  1. 2 2
      include/image-commands.mk
  2. 1 0
      include/image-legacy.mk
  3. 4 4
      include/image.mk
  4. 3 3
      include/kernel-version.mk
  5. 1 1
      include/prereq-build.mk
  6. 3 2
      include/toplevel.mk
  7. 1 1
      include/version.mk
  8. 1 1
      package/Makefile
  9. 5 3
      package/base-files/Makefile
  10. 2 5
      package/base-files/files/bin/config_generate
  11. 1 1
      package/base-files/files/etc/init.d/system
  12. 61 34
      package/base-files/files/lib/functions/network.sh
  13. 21 1
      package/base-files/files/lib/functions/uci-defaults.sh
  14. 4 1
      package/base-files/files/lib/preinit/10_indicate_preinit
  15. 1 1
      package/base-files/files/usr/lib/os-release
  16. 4 4
      package/base-files/image-config.in
  17. 3 4
      package/boot/uboot-ar71xx/Makefile
  18. 3 3
      package/boot/uboot-envtools/Makefile
  19. 47 40
      package/boot/uboot-envtools/files/ar71xx
  20. 1 1
      package/boot/uboot-envtools/files/imx6
  21. 2 3
      package/boot/uboot-envtools/files/ipq
  22. 8 8
      package/boot/uboot-envtools/files/kirkwood
  23. 3 3
      package/boot/uboot-envtools/files/lantiq
  24. 3 1
      package/boot/uboot-envtools/files/mvebu
  25. 3 3
      package/boot/uboot-envtools/files/oxnas
  26. 9 9
      package/boot/uboot-envtools/files/ramips
  27. 52 142
      package/boot/uboot-sunxi/Makefile
  28. 4 5
      package/boot/uboot-xburst/Makefile
  29. 65 0
      package/devel/binutils/patches/0001-Do-not-pass-host-compiler-sanitization-flags-on-to-l.patch
  30. 1258 0
      package/devel/binutils/patches/0002-When-building-target-binaries-ensure-that-the-warnin.patch
  31. 7 7
      package/kernel/linux/modules/crypto.mk
  32. 0 1
      package/kernel/linux/modules/netdevices.mk
  33. 2 2
      package/kernel/linux/modules/netfilter.mk
  34. 1 1
      package/kernel/linux/modules/sound.mk
  35. 2 2
      package/kernel/linux/modules/video.mk
  36. 6 4
      package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
  37. 3 3
      package/kernel/mac80211/files/lib/wifi/mac80211.sh
  38. 16 4
      package/kernel/mac80211/patches/020-01-rt2x00-avoid-introducing-a-USB-dependency-in-the-rt2.patch
  39. 61 0
      package/kernel/mac80211/patches/020-02-rt2x00usb-do-not-anchor-rx-and-tx-urb-s.patch
  40. 75 0
      package/kernel/mac80211/patches/020-03-rt2x00usb-fix-anchor-initialization.patch
  41. 28 0
      package/kernel/mac80211/patches/020-04-rt61pci-use-entry-directly.patch
  42. 181 0
      package/kernel/mac80211/patches/020-05-rt2x00-call-entry-directly-in-rt2x00_dump_frame.patch
  43. 59 0
      package/kernel/mac80211/patches/020-06-rt2x00-remove-queue_entry-from-skbdesc.patch
  44. 84 0
      package/kernel/mac80211/patches/020-07-rt2500usb-don-t-mark-register-accesses-as-inline.patch
  45. 94 0
      package/kernel/mac80211/patches/020-08-rt2x00-rt2800lib-move-rt2800_drv_data-declaration-in.patch
  46. 94 0
      package/kernel/mac80211/patches/020-09-rt2800-identify-station-based-on-status-WCID.patch
  47. 178 0
      package/kernel/mac80211/patches/020-10-rt2x00-separte-filling-tx-status-from-rt2x00lib_txdo.patch
  48. 88 0
      package/kernel/mac80211/patches/020-11-rt2x00-separte-clearing-entry-from-rt2x00lib_txdone.patch
  49. 92 0
      package/kernel/mac80211/patches/020-12-rt2x00-add-txdone-nomatch-function.patch
  50. 54 0
      package/kernel/mac80211/patches/020-13-rt2x00-fixup-fill_tx_status-for-nomatch-case.patch
  51. 191 0
      package/kernel/mac80211/patches/020-14-rt2x00-use-txdone_nomatch-on-rt2800usb.patch
  52. 88 0
      package/kernel/mac80211/patches/020-15-rt2800-status-based-rate-flags-for-nomatch-case.patch
  53. 43 0
      package/kernel/mac80211/patches/020-16-rt2800-use-TXOP_BACKOFF-for-probe-frames.patch
  54. 28 0
      package/kernel/mac80211/patches/020-17-rt2x00-fix-rt2x00debug_dump_frame-comment.patch
  55. 37 0
      package/kernel/mac80211/patches/020-18-rt2x00-fix-TX_PWR_CFG_4-register-definition.patch
  56. 2077 0
      package/kernel/mac80211/patches/020-19-rt2x00-add-support-for-MT7620.patch
  57. 54 0
      package/kernel/mac80211/patches/021-01-rt2800-fix-LNA-gain-assignment-for-MT7620.patch
  58. 34 0
      package/kernel/mac80211/patches/021-02-rt2800-do-VCO-calibration-after-programming-ALC.patch
  59. 50 0
      package/kernel/mac80211/patches/021-03-rt2800-fix-mt7620-vco-calibration-registers.patch
  60. 41 0
      package/kernel/mac80211/patches/021-04-rt2800-fix-mt7620-E2-channel-registers.patch
  61. 1 1
      package/kernel/mac80211/patches/030-rt2x00_options.patch
  62. 0 9
      package/kernel/mac80211/patches/040-brcmutil_option.patch
  63. 0 52
      package/kernel/mac80211/patches/318-0001-brcmfmac-check-brcmf_bus_get_memdump-result-for-erro.patch
  64. 0 38
      package/kernel/mac80211/patches/319-0002-brcmfmac-be-more-verbose-when-PSM-s-watchdog-fires.patch
  65. 0 44
      package/kernel/mac80211/patches/319-0003-brcmfmac-use-wiphy_read_of_freq_limits-to-respect-li.patch
  66. 0 43
      package/kernel/mac80211/patches/319-0004-brcmfmac-merge-two-brcmf_err-macros-into-one.patch
  67. 0 69
      package/kernel/mac80211/patches/319-0005-brcmfmac-switch-to-C-function-__brcmf_err-for-printi.patch
  68. 0 46
      package/kernel/mac80211/patches/319-0006-brcmfmac-merge-two-remaining-brcmf_err-macros.patch
  69. 47 0
      package/kernel/mac80211/patches/324-ath9k_hw-fix-channel-maximum-power-level-test.patch
  70. 29 0
      package/kernel/mac80211/patches/325-mac80211-unconditionally-start-new-netdev-queues-wit.patch
  71. 81 0
      package/kernel/mac80211/patches/327-mac80211-accept-key-reinstall-without-changing-anyth.patch
  72. 38 6
      package/kernel/mac80211/patches/402-ath_regd_optional.patch
  73. 2 2
      package/kernel/mac80211/patches/403-world_regd_fixup.patch
  74. 4 4
      package/kernel/mac80211/patches/406-ath_relax_default_regd.patch
  75. 4 4
      package/kernel/mac80211/patches/600-01-rt2x00-allow-to-build-rt2800soc-module-for-RT3883.patch
  76. 1 1
      package/kernel/mac80211/patches/600-02-rt2x00-rt2800lib-enable-support-for-RT3883.patch
  77. 2 2
      package/kernel/mac80211/patches/600-03-rt2x00-rt2800lib-add-rf_vals-for-RF3853.patch
  78. 2 2
      package/kernel/mac80211/patches/600-04-rt2x00-rt2800lib-enable-VCO-calibration-for-RF3853.patch
  79. 2 2
      package/kernel/mac80211/patches/600-05-rt2x00-rt2800lib-add-channel-configuration-function-.patch
  80. 1 1
      package/kernel/mac80211/patches/600-06-rt2x00-rt2800lib-enable-RF3853-support.patch
  81. 6 6
      package/kernel/mac80211/patches/600-07-rt2x00-rt2800lib-add-MAC-register-initialization-for.patch
  82. 2 2
      package/kernel/mac80211/patches/600-09-rt2x00-rt2800lib-add-BBP-register-initialization-for.patch
  83. 5 5
      package/kernel/mac80211/patches/600-10-rt2x00-rt2800lib-add-RFCSR-initialization-for-RT3883.patch
  84. 1 1
      package/kernel/mac80211/patches/600-11-rt2x00-rt2800lib-use-the-extended-EEPROM-map-for-RT3.patch
  85. 1 1
      package/kernel/mac80211/patches/600-12-rt2x00-rt2800lib-force-rf-type-to-RF3853-on-RT3883.patch
  86. 8 8
      package/kernel/mac80211/patches/600-13-rt2x00-rt2800lib-add-channel-configuration-code-for-.patch
  87. 1 1
      package/kernel/mac80211/patches/600-14-rt2x00-rt2800lib-fix-txpower_to_dev-function-for-RT3.patch
  88. 3 3
      package/kernel/mac80211/patches/600-15-rt2x00-rt2800lib-use-correct-txpower-calculation-fun.patch
  89. 2 2
      package/kernel/mac80211/patches/600-16-rt2x00-rt2800lib-hardcode-txmixer-gain-values-to-zer.patch
  90. 1 1
      package/kernel/mac80211/patches/600-17-rt2x00-rt2800lib-use-correct-RT-XWI-size-for-RT3883.patch
  91. 1 1
      package/kernel/mac80211/patches/600-18-rt2x00-rt2800lib-fix-antenna-configuration-for-RT388.patch
  92. 2 2
      package/kernel/mac80211/patches/600-19-rt2x00-rt2800lib-fix-LNA-gain-configuration-for-RT38.patch
  93. 3 3
      package/kernel/mac80211/patches/600-20-rt2x00-rt2800lib-fix-VGC-setup-for-RT3883.patch
  94. 3 3
      package/kernel/mac80211/patches/600-21-rt2x00-rt2800lib-fix-EEPROM-LNA-validation-for-RT388.patch
  95. 1 1
      package/kernel/mac80211/patches/600-22-rt2x00-rt2800lib-fix-txpower-compensation-for-RT3883.patch
  96. 1 1
      package/kernel/mac80211/patches/600-23-rt2x00-rt2800mmio-add-a-workaround-for-spurious-TX_F.patch
  97. 8 8
      package/kernel/mac80211/patches/602-rt2x00-introduce-rt2x00eeprom.patch
  98. 2 2
      package/kernel/mac80211/patches/606-rt2x00-allow_disabling_bands_through_platform_data.patch
  99. 1 1
      package/kernel/mac80211/patches/607-rt2x00-add_platform_data_mac_addr.patch
  100. 1 1
      package/kernel/mac80211/patches/608-rt2x00-allow_disabling_bands_through_dts.patch

+ 2 - 2
include/image-commands.mk

@@ -7,7 +7,7 @@ define Build/uImage
 	mkimage -A $(LINUX_KARCH) \
 		-O linux -T kernel \
 		-C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
-		-n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) LEDE Linux-$(LINUX_VERSION))' -d $@ $@.new
+		-n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) libreCMC Linux-$(LINUX_VERSION))' -d $@ $@.new
 	@mv $@.new $@
 endef
 
@@ -22,7 +22,7 @@ endef
 
 define Build/netgear-dni
 	$(STAGING_DIR_HOST)/bin/mkdniimg \
-		-B $(NETGEAR_BOARD_ID) -v LEDE.$(REVISION) \
+		-B $(NETGEAR_BOARD_ID) -v libreCMC.$(REVISION) \
 		$(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
 		-r "$(1)" \
 		-i $@ -o $@.new

+ 1 - 0
include/image-legacy.mk

@@ -48,6 +48,7 @@ endef
 ifdef TARGET_PER_DEVICE_ROOTFS
   define Image/Build/Profile/Filesystem
 	cp $(KDIR)/root.$(2)+pkg=$(3) $(KDIR)/root.$(2)
+	$(call Image/Build/$(2),$(2))
 	$(call Image/Build/Profile,$(1),$(2))
   endef
 else

+ 4 - 4
include/image.mk

@@ -137,7 +137,7 @@ endef
 
 define Image/BuildKernel/MkuImage
 	mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
-		-n '$(call toupper,$(ARCH)) LEDE Linux-$(LINUX_VERSION)' -d $(4) $(5)
+		-n '$(call toupper,$(ARCH)) libreCMC Linux-$(LINUX_VERSION)' -d $(4) $(5)
 endef
 
 define Image/BuildKernel/MkFIT
@@ -277,7 +277,7 @@ endif
 
 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
   define Image/Build/cpiogz
-	( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
+	( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
   endef
 endif
 
@@ -420,7 +420,7 @@ define Device/Build/initramfs
   $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
 	cp $$^ $$@
 
-  $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
+  $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
 	@rm -f $$@
 	$$(call concat_cmd,$$(KERNEL_INITRAMFS))
 endef
@@ -444,7 +444,7 @@ define Device/Build/kernel
     ifdef CONFIG_IB
       install: $$(KDIR_KERNEL_IMAGE)
     endif
-    $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
+    $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
 	@rm -f $$@
 	$$(call concat_cmd,$$(KERNEL))
 	$$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))

+ 3 - 3
include/kernel-version.mk

@@ -3,10 +3,10 @@
 LINUX_RELEASE?=1
 
 LINUX_VERSION-3.18 = .43
-LINUX_VERSION-4.4 = .52
+LINUX_VERSION-4.4 = .87
 
-LINUX_KERNEL_HASH-3.18.43 = f61362192b74424539f062a21aa7080f5d66fd8d4cfe2a38f33fab8889bf072c
-LINUX_KERNEL_HASH-4.4.52 = 0f1faafdae47da5f29e740ff655f91c2eb13c8cdfc4d039d903176bd56c2ecbb
+LINUX_KERNEL_HASH-3.18.43 = 1236e8123a6ce537d5029232560966feed054ae31776fe8481dd7d18cdd5492c
+LINUX_KERNEL_HASH-4.4.87 = f2e26505e3aecf622d4f4e1ede44b3b97a38739ad8b78ede14eb354f22d1387a
 
 ifdef KERNEL_PATCHVER
   LINUX_VERSION:=$(KERNEL_PATCHVER)$(strip $(LINUX_VERSION-$(KERNEL_PATCHVER)))

+ 1 - 1
include/prereq-build.mk

@@ -20,7 +20,7 @@ $(eval $(call TestHostCommand,working-make, \
 	$(MAKE) -v | grep -E 'Make (3\.8[1-9]|3\.9[0-9]|[4-9]\.)'))
 
 $(eval $(call TestHostCommand,case-sensitive-fs, \
-	LEDE can only be built on a case-sensitive filesystem, \
+	libreCMC can only be built on a case-sensitive filesystem, \
 	rm -f $(TMP_DIR)/test.*; touch $(TMP_DIR)/test.fs; \
 		test ! -f $(TMP_DIR)/test.FS))
 

+ 3 - 2
include/toplevel.mk

@@ -23,6 +23,7 @@ HOSTCC ?= $(CC)
 export REVISION
 export SOURCE_DATE_EPOCH
 export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
+export GIT_ASKPASS:=/bin/true
 export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
 
 # prevent perforce from messing with the patch utility
@@ -126,7 +127,7 @@ menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
 	if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
 		cp $(HOME)/.openwrt/defconfig .config; \
 	fi
-	$< Config.in
+	[ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; $< Config.in
 
 prepare_kernel_conf: .config FORCE
 
@@ -170,7 +171,7 @@ else
   DOWNLOAD_DIRS = package/download
 endif
 
-download: .config FORCE
+download: .config FORCE $(if $(wildcard $(TOPDIR)/staging_dir/host/bin/flock),,tools/flock/compile)
 	@+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
 
 clean dirclean: .config

+ 1 - 1
include/version.mk

@@ -31,7 +31,7 @@ qstrip_escape=$(subst ','\'',$(call qstrip,$(1)))
 sanitize = $(call tolower,$(subst _,-,$(subst $(space),-,$(1))))
 
 VERSION_NUMBER:=$(call qstrip_escape,$(CONFIG_VERSION_NUMBER))
-VERSION_NUMBER:=$(if $(VERSION_NUMBER),$(VERSION_NUMBER),v1.4)
+VERSION_NUMBER:=$(if $(VERSION_NUMBER),$(VERSION_NUMBER),v1.4.1)
 
 VERSION_CODE:=$(call qstrip_escape,$(CONFIG_VERSION_CODE))
 VERSION_CODE:=$(if $(VERSION_CODE),$(VERSION_CODE),$(REVISION))

+ 1 - 1
package/Makefile

@@ -56,7 +56,7 @@ $(curdir)/merge:
 $(curdir)/merge-index: $(curdir)/merge
 	(cd $(PACKAGE_DIR_ALL) && $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages; )
 
-$(curdir)/install: $(TMP_DIR)/.build $(curdir)/system/opkg/host/install $(curdir)/merge $(if $(CONFIG_TARGET_PER_DEVICE_ROOTFS),$(curdir)/merge-index)
+$(curdir)/install: $(TMP_DIR)/.build $(curdir)/system/opkg/host/compile $(curdir)/merge $(if $(CONFIG_TARGET_PER_DEVICE_ROOTFS),$(curdir)/merge-index)
 	- find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
 	rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
 	[ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp

+ 5 - 3
package/base-files/Makefile

@@ -11,14 +11,15 @@ include $(INCLUDE_DIR)/kernel.mk
 include $(INCLUDE_DIR)/version.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=172
+PKG_RELEASE:=173.1
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
 PKG_BUILD_DEPENDS:=usign/host
 PKG_LICENSE:=GPL-2.0
 
-PKG_CONFIG_DEPENDS := CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE
+# Extend depends from version.mk
+PKG_CONFIG_DEPENDS += CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE
 
 include $(INCLUDE_DIR)/package.mk
 
@@ -31,7 +32,7 @@ define Package/base-files
   SECTION:=base
   CATEGORY:=Base system
   DEPENDS:=+netifd +libc +procd +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:librecmc-keyring +fstools +fwtool
-  TITLE:=Base filesystem for libreCMC
+  TITLE:=Base filesystem for Lede
   URL:=http://openwrt.org/
   VERSION:=$(PKG_RELEASE)-$(REVISION)
 endef
@@ -137,6 +138,7 @@ define Package/base-files/install
 
 	mkdir -p $(1)/CONTROL
 	mkdir -p $(1)/dev
+	mkdir -p $(1)/etc/config
 	mkdir -p $(1)/etc/crontabs
 	mkdir -p $(1)/etc/rc.d
 	mkdir -p $(1)/overlay

+ 2 - 5
package/base-files/files/bin/config_generate

@@ -119,17 +119,14 @@ generate_network() {
 		;;
 
 		pppoe)
-			# fixup IPv6 slave interface
-			ifname="pppoe-$1"
-
 			uci -q batch <<-EOF
 				set network.$1.proto='pppoe'
 				set network.$1.username='username'
 				set network.$1.password='password'
-				set network.$1.ipv6='auto'
+				set network.$1.ipv6='1'
 				delete network.${1}6
 				set network.${1}6='interface'
-				set network.${1}6.ifname='$ifname'
+				set network.${1}6.ifname='@${1}'
 				set network.${1}6.proto='dhcpv6'
 			EOF
 		;;

+ 1 - 1
package/base-files/files/etc/init.d/system

@@ -7,7 +7,7 @@ USE_PROCD=1
 validate_system_section()
 {
 	uci_validate_section system system "${1}" \
-		'hostname:string:lede' \
+		'hostname:string:librecmc' \
 		'conloglevel:uinteger' \
 		'buffersize:uinteger' \
 		'timezone:string:UTC' \

+ 61 - 34
package/base-files/files/lib/functions/network.sh

@@ -29,18 +29,9 @@ network_get_ipaddr() {
 # 1: destination variable
 # 2: interface
 network_get_ipaddr6() {
-	local __addr
-
-	if __network_ifstatus "__addr" "$2" "['ipv6-address','ipv6-prefix-assignment'][0].address"; then
-		case "$__addr" in
-			*:)	export "$1=${__addr}1" ;;
-			*)	export "$1=${__addr}" ;;
-		esac
-		return 0
-	fi
-
-	unset $1
-	return 1
+	__network_ifstatus "$1" "$2" "['ipv6-address'][0].address" || \
+		__network_ifstatus "$1" "$2" "['ipv6-prefix-assignment'][0]['local-address'].address" || \
+		return 1
 }
 
 # determine first IPv4 subnet of given logical interface
@@ -54,7 +45,36 @@ network_get_subnet() {
 # 1: destination variable
 # 2: interface
 network_get_subnet6() {
-	__network_ifstatus "$1" "$2" "['ipv6-address'][0]['address','mask']" "/"
+	local __nets __addr
+
+	if network_get_subnets6 __nets "$2"; then
+		# Attempt to return first non-fe80::/10, non-fc::/7 range
+		for __addr in $__nets; do
+			case "$__addr" in fe[8ab]?:*|f[cd]??:*)
+				continue
+			esac
+			export "$1=$__addr"
+			return 0
+		done
+
+		# Attempt to return first non-fe80::/10 range
+		for __addr in $__nets; do
+			case "$__addr" in fe[8ab]?:*)
+				continue
+			esac
+			export "$1=$__addr"
+			return 0
+		done
+
+		# Return first item
+		for __addr in $__nets; do
+			export "$1=$__addr"
+			return 0
+		done
+	fi
+
+	unset "$1"
+	return 1
 }
 
 # determine first IPv6 prefix of given logical interface
@@ -78,14 +98,19 @@ network_get_ipaddrs6() {
 	local __addr
 	local __list=""
 
-	if __network_ifstatus "__addr" "$2" "['ipv6-address','ipv6-prefix-assignment'][*].address"; then
+	if __network_ifstatus "__addr" "$2" "['ipv6-address'][*].address"; then
 		for __addr in $__addr; do
-			case "$__addr" in
-				*:) __list="${__list:+$__list }${__addr}1" ;;
-				*)  __list="${__list:+$__list }${__addr}"  ;;
-			esac
+			__list="${__list:+$__list }${__addr}"
+		done
+	fi
+
+	if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address"; then
+		for __addr in $__addr; do
+			__list="${__list:+$__list }${__addr}"
 		done
+	fi
 
+	if [ -n "$__list" ]; then
 		export "$1=$__list"
 		return 0
 	fi
@@ -98,18 +123,13 @@ network_get_ipaddrs6() {
 # 1: destination variable
 # 2: interface
 network_get_ipaddrs_all() {
-	local __addr
-	local __list=""
+	local __addr __addr6
 
-	if __network_ifstatus "__addr" "$2" "['ipv4-address','ipv6-address','ipv6-prefix-assignment'][*].address"; then
-		for __addr in $__addr; do
-			case "$__addr" in
-				*:) __list="${__list:+$__list }${__addr}1" ;;
-				*)  __list="${__list:+$__list }${__addr}"  ;;
-			esac
-		done
+	network_get_ipaddrs __addr "$2"
+	network_get_ipaddrs6 __addr6 "$2"
 
-		export "$1=$__list"
+	if [ -n "$__addr" -o -n "$__addr6" ]; then
+		export "$1=${__addr:+$__addr }$__addr6"
 		return 0
 	fi
 
@@ -128,17 +148,24 @@ network_get_subnets() {
 # 1: destination variable
 # 2: interface
 network_get_subnets6() {
-	local __addr
+	local __addr __mask
 	local __list=""
 
-	if __network_ifstatus "__addr" "$2" "['ipv6-address','ipv6-prefix-assignment'][*]['address','mask']" "/ "; then
+	if __network_ifstatus "__addr" "$2" "['ipv6-address'][*]['address','mask']" "/ "; then
 		for __addr in $__addr; do
-			case "$__addr" in
-				*:/*) __list="${__list:+$__list }${__addr%/*}1/${__addr##*/}" ;;
-				*)    __list="${__list:+$__list }${__addr}"                   ;;
-			esac
+			__list="${__list:+$__list }${__addr}"
 		done
+	fi
+
+	if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address" && \
+	   __network_ifstatus "__mask" "$2" "['ipv6-prefix-assignment'][*].mask"; then
+		for __addr in $__addr; do
+			__list="${__list:+$__list }${__addr}/${__mask%% *}"
+			__mask="${__mask#* }"
+		done
+	fi
 
+	if [ -n "$__list" ]; then
 		export "$1=$__list"
 		return 0
 	fi

+ 21 - 1
package/base-files/files/lib/functions/uci-defaults.sh

@@ -35,7 +35,7 @@ _ucidef_set_interface() {
 	json_select_object "$name"
 	json_add_string ifname "$iface"
 
-	if ! json_is_a protocol string; then
+	if ! json_is_a protocol string || [ -n "$proto" ]; then
 		case "$proto" in
 			static|dhcp|none|pppoe) : ;;
 			*)
@@ -619,6 +619,26 @@ ucidef_add_gpio_switch() {
 	json_select ..
 }
 
+ucidef_set_hostname() {
+	local hostname="$1"
+
+	json_select_object system
+		json_add_string hostname "$hostname"
+	json_select ..
+}
+
+ucidef_set_ntpserver() {
+	local server
+
+	json_select_object system
+		json_select_array ntpserver
+			for server in "$@"; do
+				json_add_string "" "$server"
+			done
+		json_select ..
+	json_select ..
+}
+
 board_config_update() {
 	json_init
 	[ -f ${CFG} ] && json_load "$(cat ${CFG})"

+ 4 - 1
package/base-files/files/lib/preinit/10_indicate_preinit

@@ -96,6 +96,8 @@ preinit_config_board() {
 }
 
 preinit_ip() {
+	[ "$pi_preinit_no_failsafe" = "y" ] && return
+
 	# if the preinit interface isn't specified and ifname is set in
 	# preinit.arch use that interface
 	if [ -z "$pi_ifname" ]; then
@@ -107,6 +109,8 @@ preinit_ip() {
 	elif [ -d "/etc/board.d/" ]; then
 		preinit_config_board
 	fi
+
+	preinit_net_echo "Doing Lede Preinit\n"
 }
 
 preinit_ip_deconfig() {
@@ -146,7 +150,6 @@ preinit_echo() {
 }
 
 pi_indicate_preinit() {
-	preinit_net_echo "Doing Lede Preinit\n"
 	set_state preinit
 }
 

+ 1 - 1
package/base-files/files/usr/lib/os-release

@@ -1,7 +1,7 @@
 NAME="%D"
 VERSION="%V, %N"
 ID="%d"
-ID_LIKE="lede openwrt"
+ID_LIKE="librecmc openwrt"
 PRETTY_NAME="%D %N %V"
 VERSION_ID="%v"
 HOME_URL="%m"

+ 4 - 4
package/base-files/image-config.in

@@ -92,7 +92,7 @@ config TARGET_PREINIT_NETMASK
 config TARGET_PREINIT_BROADCAST
 	string
 	prompt "Broadcast address for preinit network messages" if PREINITOPT
-	default "192.168.1.255"
+	default "192.168.10.255"
 	help
 		Broadcast address to which to send preinit network messages, as
 		as failsafe messages
@@ -201,13 +201,13 @@ if VERSIONOPT
 			 %c .. Configured release revision code or value of %R, lowercase
 			 %N .. Release name, uppercase
 			 %n .. Release name, lowercase
-			 %D .. Distribution name or "Lede", uppercase
-			 %d .. Distribution name or "lede", lowercase
+			 %D .. Distribution name or "libreCMC", uppercase
+			 %d .. Distribution name or "librecmc", lowercase
 			 %T .. Target name
 			 %S .. Target/Subtarget name
 			 %A .. Package architecture
 			 %t .. Build taint flags, e.g. "no-all busybox"
-			 %M .. Manufacturer name or "Lede"
+			 %M .. Manufacturer name or "libreCMC"
 			 %P .. Product name or "Generic"
 			 %h .. Hardware revision or "v0"
 

+ 3 - 4
package/boot/uboot-ar71xx/Makefile

@@ -9,16 +9,15 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=u-boot
-PKG_VERSION:=2010.03-libre
+PKG_VERSION:=2010.03
 PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+PKG_HASH:=902d1b2c15787df55186fae4033685fb0c5a5a12755a08383e97c4a3e255925b
 PKG_SOURCE_URL:= \
-	https://librecmc.org/librecmc/downloads/sources/archive/v1.2.1/ \
+	http://mirror2.openwrt.org/sources \
 	ftp://ftp.denx.de/pub/u-boot
-
-PKG_MD5SUM:=526e01c8564ab8d1fd2c0e787a014b17
 PKG_TARGETS:=bin
 
 PKG_LICENSE:=GPL-2.0 GPL-2.0+

+ 3 - 3
package/boot/uboot-envtools/Makefile

@@ -9,15 +9,15 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=uboot-envtools
 PKG_DISTNAME:=u-boot
-PKG_VERSION:=2015.10-librecmc
+PKG_VERSION:=2015.10
 PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/u-boot-$(PKG_VERSION)
 PKG_SOURCE:=$(PKG_DISTNAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=\
-	https://librecmc.org/librecmc/downloads/sources/v1.3.4/ \
+	http://mirror2.openwrt.org/sources \
 	ftp://ftp.denx.de/pub/u-boot
-PKG_MD5SUM:=5e60d710ce19d2cd20c197ade9bbbc72
+PKG_HASH:=bdc68d5f9455ad933b059c735d983f2c8b6b552dafb062e5ff1444f623021955
 
 PKG_BUILD_DEPENDS:=+fstools
 

+ 47 - 40
package/boot/uboot-envtools/files/ar71xx

@@ -14,53 +14,60 @@ touch /etc/config/ubootenv
 board=$(ar71xx_board_name)
 
 case "$board" in
-alfa-ap120c | \
-all0258n | \
-ap90q | \
-cap324 | \
-cap4200ag | \
-carambola2 | \
-cpe830 | \
-cpe870 | \
-cr3000 | \
-cr5000 | \
-eap300v2 | \
-gl-ar300m | \
-hornet-ub | \
-hornet-ub-x2 | \
-jwap230 | \
-mr1750 | \
-mr1750v2 | \
-mr600 | \
-mr600v2 | \
-mr900 | \
-mr900v2 | \
-nbg6716 | \
-om5p-an | \
-om5p-ac | \
-om5p-acv2 | \
-om5p | \
-tube2h | \
-wndr3700)
+a40|\
+a60|\
+alfa-ap120c|\
+all0258n|\
+ap121f|\
+ap90q|\
+cap324|\
+cap4200ag|\
+carambola2|\
+cpe830|\
+cpe870|\
+cr3000|\
+cr5000|\
+eap300v2|\
+gl-ar300m|\
+hornet-ub|\
+hornet-ub-x2|\
+jwap230|\
+mr1750|\
+mr1750v2|\
+mr600|\
+mr600v2|\
+mr900|\
+mr900v2|\
+nbg6716|\
+om5p|\
+om5p-ac|\
+om5p-acv2|\
+om5p-an|\
+sr3200|\
+tube2h|\
+wndr3700|\
+xd3200)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
 	;;
-alfa-ap96 | \
-all0315n | \
-om2p | \
-om2pv2 | \
-om2p-hs | \
-om2p-hsv2 | \
-om2p-hsv3 | \
-om2p-lc)
+alfa-ap96|\
+all0315n|\
+om2p|\
+om2p-hs|\
+om2p-hsv2|\
+om2p-hsv3|\
+om2p-hsv4|\
+om2p-lc|\
+om2pv2|\
+om2pv4)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000"
 	;;
-dr531)
-	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0xf800" "0x10000"
-	;;
-dap-2695-a1 | \
+dap-2695-a1|\
 wzr-hp-ag300h)
 	ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000"
 	;;
+dr531)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0xf800" "0x10000"
+	;;
 qihoo-c301)
 	ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x10000" "0x10000"
 	;;

+ 1 - 1
package/boot/uboot-envtools/files/imx6

@@ -25,7 +25,7 @@ case "$board" in
 		ubootenv_add_uci_config /dev/mmcblk0 0xd1400 0x20000 0x20000
 	fi
 	;;
-"wandboard")
+wandboard)
 	ubootenv_add_uci_config "/dev/mmcblk0" "0x60000" "0x2000" "0x2000"
 	;;
 esac

+ 2 - 3
package/boot/uboot-envtools/files/ipq

@@ -13,12 +13,11 @@ touch /etc/config/ubootenv
 
 board=$(ipq806x_board_name)
 
-
 case "$board" in
-"ea8500")
+ea8500)
 	ubootenv_add_uci_config "/dev/mtd10" "0x0" "0x20000" "0x20000"
 	;;
-"nbg6817")
+nbg6817)
 	ubootenv_add_uci_config "/dev/mtdblock9" "0x0" "0x10000" "0x10000"
 	;;
 esac

+ 8 - 8
package/boot/uboot-envtools/files/kirkwood

@@ -14,16 +14,16 @@ touch /etc/config/ubootenv
 board=$(kirkwood_board_name)
 
 case "$board" in
-"dockstar" | \
-"guruplug-server-plus" | \
-"ib62x0" | \
-"linksys-viper" | \
-"pogo_e02" | \
-"sheevaplug" | \
-"sheevaplug-esata" )
+dockstar|\
+guruplug-server-plus|\
+ib62x0|\
+linksys-viper|\
+pogo_e02|\
+sheevaplug|\
+sheevaplug-esata)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
 	;;
-"linksys-audi")
+linksys-audi)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000"
 	;;
 esac

+ 3 - 3
package/boot/uboot-envtools/files/lantiq

@@ -14,15 +14,15 @@ touch /etc/config/ubootenv
 board=$(lantiq_board_name)
 
 case "$board" in
-GIGASX76X)
-	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
-	;;
 BTHOMEHUBV2B)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
 	;;
 BTHOMEHUBV3A)
 	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x4000" "0x4000" "1"
 	;;
+GIGASX76X)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
+	;;
 P2812HNUF1)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x2000" "0x20000" "1"
 	;;

+ 3 - 1
package/boot/uboot-envtools/files/mvebu

@@ -15,7 +15,9 @@ touch /etc/config/ubootenv
 board=$(mvebu_board_name)
 
 case "$board" in
-armada-385-linksys-caiman|armada-385-linksys-cobra|armada-385-linksys-shelby)
+armada-385-linksys-caiman|\
+armada-385-linksys-cobra|\
+armada-385-linksys-shelby)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x40000"
 	;;
 armada-385-linksys-rango)

+ 3 - 3
package/boot/uboot-envtools/files/oxnas

@@ -14,9 +14,9 @@ touch /etc/config/ubootenv
 board=$(oxnas_board_name)
 
 case "$board" in
-akitio | \
-stg212 | \
-kd20)
+akitio|\
+kd20|\
+stg212)
 	ubootenv_add_uci_config "/dev/ubi0_0" "0x0" "0x4000" "0x1F000" "1"
 	ubootenv_add_uci_config "/dev/ubi0_1" "0x0" "0x4000" "0x1F000" "1"
 	;;

+ 9 - 9
package/boot/uboot-envtools/files/ramips

@@ -14,18 +14,18 @@ touch /etc/config/ubootenv
 board=$(ramips_board_name)
 
 case "$board" in
-all0239-3g | \
-all0256n | \
+all0239-3g|\
+all0256n|\
 all5002)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
 	;;
-linkits7688 | \
-linkits7688d | \
-wsr-600 | \
-wsr-1166 | \
-br6425 | \
-miwifi-nano | \
-sk-wb8 | \
+br-6425|\
+linkits7688|\
+linkits7688d|\
+miwifi-nano|\
+sk-wb8|\
+wsr-1166|\
+wsr-600|\
 zbt-wg2626)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
 	;;

+ 52 - 142
package/boot/uboot-sunxi/Makefile

@@ -1,5 +1,6 @@
 #
 # Copyright (C) 2013-2016 OpenWrt.org
+# Copyright (C) 2017 Yousong Zhou
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -11,178 +12,87 @@ include $(INCLUDE_DIR)/kernel.mk
 PKG_NAME:=u-boot
 PKG_VERSION:=2016.03
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
-PKG_SOURCE_URL:= \
-	http://mirror2.openwrt.org/sources \
-	ftp://ftp.denx.de/pub/u-boot
-
-PKG_MD5SUM:=973c1d896be751321cc3aafa564f64b2
-
-PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
-
+PKG_SOURCE_URL:=ftp://ftp.denx.de/pub/u-boot
+PKG_HASH:=e49337262ecac44dbdeac140f2c6ebd1eba345e0162b0464172e7f05583ed7bb
+PKG_MAINTAINER:=Zoltan HERPAI <wigyori@uid0.hu>
 PKG_LICENSE:=GPL-2.0 GPL-2.0+
 PKG_LICENSE_FILES:=Licenses/README
 
-include $(INCLUDE_DIR)/package.mk
-
-define uboot/Default
-  TITLE:=
-  CONFIG:=
-  IMAGE:=
-endef
-
-define uboot/A10-OLinuXino-Lime
-  TITLE:=U-Boot for the A10 OLinuXino LIME
-endef
-
-define uboot/A13-OLinuXino
-  TITLE:=U-Boot for the A13 OlinuXino
-endef
-
-define uboot/A20-OLinuXino-Lime
-  TITLE:=U-Boot for the A20 OLinuXino LIME
-endef
-
-define uboot/A20-OLinuXino_MICRO
-  TITLE:=U-Boot for A20 OLinuXino MICRO
-endef
+PKG_BUILD_PARALLEL:=1
 
-define uboot/Bananapi
-  TITLE:=U-Boot for Bananapi
-endef
-
-define uboot/Bananapro
-  TITLE:=U-Boot for Bananapro
-endef
-
-define uboot/Cubieboard
-  TITLE:=U-Boot for Cubieboard
-endef
-
-define uboot/Cubieboard2
-  TITLE:=U-Boot for Cubieboard2
-endef
-
-define uboot/Cubietruck
-  TITLE:=U-Boot for Cubietruck
-endef
-
-define uboot/Hummingbird_A31
-  TITLE:=U-Boot for the Hummingbird A31 board
-endef
+PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
 
-define uboot/Mele_M9
-  TITLE:=U-Boot for the Mele M9 (A31)
-endef
+include $(INCLUDE_DIR)/package.mk
 
-define uboot/OLIMEX_A13_SOM
-  TITLE:=U-Boot for the Olimex A13 SOM
+define Package/uboot/template
+define Package/uboot-sunxi-$(1)
+  SECTION:=boot
+  CATEGORY:=Boot Loaders
+  DEPENDS:=@TARGET_sunxi
+  TITLE:=U-Boot for $(2)
+  URL:=http://www.denx.de/wiki/U-Boot
+  VARIANT:=$(1)
 endef
 
-define uboot/Linksprite_pcDuino
-  TITLE:=U-Boot for Linksprite pcDuino
-endef  
-
-define uboot/Linksprite_pcDuino3
-  TITLE:=U-Boot for Linksprite pcDuino3
-endef  
-
-define uboot/Lamobo_R1
-  TITLE:=U-Boot for Lamobo R1
+define Package/uboot-sunxi-$(1)/install
+	$(CP) $(PKG_BUILD_DIR)/u-boot-sunxi-with-spl.bin \
+		$(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-u-boot-with-spl.bin
+	mkimage -C none -A arm -T script -d uEnv-$(if $(3),$(3),default).txt \
+		$(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-boot.scr
 endef
 
-define uboot/pangolin
-  TITLE:=U-Boot for Theobroma A31-yQ7 devboard
-endef
+UBOOT_SUNXI_PACKAGES += uboot-sunxi-$(1)
 
-define uboot/orangepi_plus
-  TITLE:=U-Boot for Orange Pi Plus (H3)
 endef
 
-UBOOTS:= \
-	A10-OLinuXino-Lime \
-	A13-OLinuXino \
-	A20-OLinuXino-Lime \
-	A20-OLinuXino_MICRO \
-	Bananapi \
-	Bananapro \
-	Cubieboard \
-	Cubieboard2 \
-	Cubietruck \
-	Hummingbird_A31 \
-	Mele_M9 \
-	OLIMEX_A13_SOM \
-	Linksprite_pcDuino \
-	Linksprite_pcDuino3 \
-	Lamobo_R1 \
-	orangepi_plus \
-	pangolin
+$(eval $(call Package/uboot/template,A10-OLinuXino-Lime,the A10 OLinuXino LIME))
+$(eval $(call Package/uboot/template,A13-OLinuXino,the A13 OlinuXino))
+$(eval $(call Package/uboot/template,A20-OLinuXino-Lime,the A20 OLinuXino LIME))
+$(eval $(call Package/uboot/template,A20-OLinuXino_MICRO,A20 OLinuXino MICRO))
+$(eval $(call Package/uboot/template,Bananapi,Bananapi))
+$(eval $(call Package/uboot/template,Bananapro,Bananapro))
+$(eval $(call Package/uboot/template,Cubieboard,Cubieboard))
+$(eval $(call Package/uboot/template,Cubieboard2,Cubieboard2))
+$(eval $(call Package/uboot/template,Cubietruck,Cubietruck))
+$(eval $(call Package/uboot/template,Hummingbird_A31,the Hummingbird A31 board))
+$(eval $(call Package/uboot/template,Mele_M9,the Mele M9 (A31)))
+$(eval $(call Package/uboot/template,OLIMEX_A13_SOM,the Olimex A13 SOM))
+$(eval $(call Package/uboot/template,Linksprite_pcDuino,Linksprite pcDuino))
+$(eval $(call Package/uboot/template,Linksprite_pcDuino3,Linksprite pcDuino3))
+$(eval $(call Package/uboot/template,Lamobo_R1,Lamobo R1))
+$(eval $(call Package/uboot/template,orangepi_plus,Orange Pi Plus (H3)))
+$(eval $(call Package/uboot/template,pangolin,Theobroma A31-yQ7 devboard,pangolin))
 
-define Package/uboot/template
-define Package/uboot-sunxi-$(1)
+define Package/uboot-sunxi-all
   SECTION:=boot
   CATEGORY:=Boot Loaders
   DEPENDS:=@TARGET_sunxi
-  TITLE:=$(2)
+  TITLE:=Meta package for selecting all variants of uboot-sunxi
   URL:=http://www.denx.de/wiki/U-Boot
-  VARIANT:=$(1)
-  MAINTAINER:=Zoltan HERPAI <wigyori@uid0.hu>
-endef
-endef
-
-define BuildUBootPackage
-	$(eval $(uboot/Default))
-	$(eval $(uboot/$(1)))
-	$(call Package/uboot/template,$(1),$(TITLE))
+  DEPENDS:=$(patsubst %,+%,$(UBOOT_SUNXI_PACKAGES))
 endef
 
 ifdef BUILD_VARIANT
-$(eval $(call uboot/$(BUILD_VARIANT)))
-UBOOT_CONFIG:=$(if $(CONFIG),$(CONFIG),$(BUILD_VARIANT))
-UBOOT_IMAGE:=$(if $(IMAGE),$(IMAGE),openwrt-$(BOARD)-$(BUILD_VARIANT)-u-boot.bin)
-endif
-
-# check if any specialized uEnv bootconfig is required
-ifeq ($(UBOOT_CONFIG),pangolin)
-	UENV:=pangolin
-else
-	UENV:=default
-endif
-
 define Build/Configure
-	$(MAKE) -C $(PKG_BUILD_DIR) \
-		USE_PRIVATE_LIBGCC=yes $(UBOOT_CONFIG)_defconfig
+	+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
+		USE_PRIVATE_LIBGCC=yes $(BUILD_VARIANT)_defconfig
 endef
 
 define Build/Compile
-	$(MAKE) -C $(PKG_BUILD_DIR) \
+	+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
 		CROSS_COMPILE=$(TARGET_CROSS) \
 		DTCDIR=$(LINUX_DIR)/scripts/dtc/
 endef
-
-define Package/uboot/install/default
-	$(CP) $(PKG_BUILD_DIR)/u-boot.bin \
-		$(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-u-boot.bin
-	$(CP) $(PKG_BUILD_DIR)/spl/sunxi-spl.bin \
-		$(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-spl.bin
-	$(CP) $(PKG_BUILD_DIR)/u-boot-sunxi-with-spl.bin \
-		$(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-u-boot-with-spl.bin
-	$(CP) uEnv-$(UENV).txt \
-		$(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-uEnv.txt
-	mkimage -C none -A arm -T script -d $(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-uEnv.txt \
-		$(KERNEL_BUILD_DIR)/uboot-$(BOARD)-$(1)-boot.scr
+else	# BUILD_VARIANT
+define Build/Prepare
 endef
-
-define Package/uboot/install/template
-define Package/uboot-sunxi-$(1)/install
-	$(call Package/uboot/install/default,$(2))
+define Build/Configure
 endef
+define Build/Compile
 endef
+endif	# BUILD_VARIANT
 
-$(foreach u,$(UBOOTS), \
-	$(eval $(call Package/uboot/install/template,$(u),$(u))) \
-)
-
-$(foreach u,$(UBOOTS), \
-	$(eval $(call BuildUBootPackage,$(u))) \
-	$(eval $(call BuildPackage,uboot-sunxi-$(u))) \
+$(foreach pkg,$(UBOOT_SUNXI_PACKAGES), \
+  $(eval $(call BuildPackage,$(pkg))) \
 )
+$(eval $(call BuildPackage,uboot-sunxi-all))

+ 4 - 5
package/boot/uboot-xburst/Makefile

@@ -9,16 +9,15 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=u-boot
-PKG_VERSION:=2012.10-rc2-libre
+PKG_VERSION:=2012.10-rc2
 PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:= \
-	https://librecmc.org/librecmc/downloads/sources/archive/ \
-
-
-PKG_MD5SUM:=ffd6e3795d221bc43c70bed97c919f70
+	http://mirror2.openwrt.org/sources \
+	ftp://ftp.denx.de/pub/u-boot
+PKG_HASH:=6d094cafa7ecea8b671fbdcd21130b6a4f5744fc47dd263e101ed5d3629dffd4
 PKG_TARGETS:=bin
 
 PKG_LICENSE:=GPL-2.0 GPL-2.0+

+ 65 - 0
package/devel/binutils/patches/0001-Do-not-pass-host-compiler-sanitization-flags-on-to-l.patch

@@ -0,0 +1,65 @@
+From 183eb37e25d903ccd68cc2d8f8a37e75872c03d2 Mon Sep 17 00:00:00 2001
+From: Nick Clifton <nickc@redhat.com>
+Date: Tue, 6 Sep 2016 17:35:35 +0100
+Subject: [PATCH 1/2] Do not pass host compiler sanitization flags on to linker
+ testsuite.
+
+	* Makefile.am (CFLAGS_FOR_TARGET): Define as a copy of CFLAGS but
+	without any sanitization options.
+	(CXXFLAGS_FOR_TARGET): Define as a copy of CXXFLAGS but	without
+	any sanitization options.
+	(check-DEJAGNU): Pass CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET
+	as CFLAGS and CXXFLAGS respectively.
+---
+ ld/Makefile.am | 8 ++++++--
+ ld/Makefile.in | 8 ++++++--
+ 2 files changed, 12 insertions(+), 4 deletions(-)
+
+--- a/ld/Makefile.am
++++ b/ld/Makefile.am
+@@ -136,6 +136,10 @@ CXX_FOR_TARGET = ` \
+     fi; \
+   fi`
+ 
++# Strip out sanitization options as we want to test building binaries without any extra paraphernalia
++CFLAGS_FOR_TARGET = `echo $(CFLAGS) | sed -e 's/-fsanitize=address//g' -e 's/-fsanitize=undefined//g'`
++CXXFLAGS_FOR_TARGET = `echo $(CXXFLAGS) | sed -e 's/-fsanitize=address//g' -e 's/-fsanitize=undefined//g'`
++
+ transform = s/^ld-new$$/$(installed_linker)/;@program_transform_name@
+ bin_PROGRAMS = ld-new
+ info_TEXINFOS = ld.texinfo
+@@ -2075,8 +2079,8 @@ check-DEJAGNU: site.exp
+ 	runtest=$(RUNTEST); \
+ 	if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
+ 	  $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
+-		CC="$(CC_FOR_TARGET)" CFLAGS="$(CFLAGS)" \
+-		CXX="$(CXX_FOR_TARGET)" CXXFLAGS="$(CXXFLAGS)" \
++		CC="$(CC_FOR_TARGET)" CFLAGS="$(CFLAGS_FOR_TARGET)" \
++		CXX="$(CXX_FOR_TARGET)" CXXFLAGS="$(CXXFLAGS_FOR_TARGET)" \
+ 		CC_FOR_HOST="$(CC)" CFLAGS_FOR_HOST="$(CFLAGS)" \
+ 		OFILES="$(OFILES)" BFDLIB="$(TESTBFDLIB)" \
+ 		LIBIBERTY="$(LIBIBERTY) $(LIBINTL)" LIBS="$(LIBS)" \
+--- a/ld/Makefile.in
++++ b/ld/Makefile.in
+@@ -507,6 +507,10 @@ CXX_FOR_TARGET = ` \
+     fi; \
+   fi`
+ 
++
++# Strip out sanitization options as they require special host libraries.
++CFLAGS_FOR_TARGET = `echo $(CFLAGS) | sed -e 's/-fsanitize=address//g' -e 's/-fsanitize=undefined//g'`
++CXXFLAGS_FOR_TARGET = `echo $(CXXFLAGS) | sed -e 's/-fsanitize=address//g' -e 's/-fsanitize=undefined//g'`
+ info_TEXINFOS = ld.texinfo
+ ld_TEXINFOS = configdoc.texi
+ noinst_TEXINFOS = ldint.texinfo
+@@ -3644,8 +3648,8 @@ check-DEJAGNU: site.exp
+ 	runtest=$(RUNTEST); \
+ 	if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
+ 	  $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
+-		CC="$(CC_FOR_TARGET)" CFLAGS="$(CFLAGS)" \
+-		CXX="$(CXX_FOR_TARGET)" CXXFLAGS="$(CXXFLAGS)" \
++		CC="$(CC_FOR_TARGET)" CFLAGS="$(CFLAGS_FOR_TARGET)" \
++		CXX="$(CXX_FOR_TARGET)" CXXFLAGS="$(CXXFLAGS_FOR_TARGET)" \
+ 		CC_FOR_HOST="$(CC)" CFLAGS_FOR_HOST="$(CFLAGS)" \
+ 		OFILES="$(OFILES)" BFDLIB="$(TESTBFDLIB)" \
+ 		LIBIBERTY="$(LIBIBERTY) $(LIBINTL)" LIBS="$(LIBS)" \

+ 1258 - 0
package/devel/binutils/patches/0002-When-building-target-binaries-ensure-that-the-warnin.patch

@@ -0,0 +1,1258 @@
+From b8ff24c72174effd5c5527866313982e28507275 Mon Sep 17 00:00:00 2001
+From: Vlad Zakharov <vzakhar@synopsys.com>
+Date: Mon, 26 Sep 2016 16:36:08 +0100
+Subject: [PATCH 2/2] When building target binaries, ensure that the warning
+ flags selected for the command line match the target compiler.
+
+bfd	* warning.m4 (AC_EGREP_CPP_FOR_BUILD): Introduce macro
+	to verify CC_FOR_BUILD compiler.
+	(AM_BINUTILS_WARNINGS): Introduce ac_cpp_for_build variable
+	and add CC_FOR_BUILD compiler checks.
+	* Makefile.in: Regenerate.
+	* configure: Likewise.
+	* doc/Makefile.in: Likewise.
+
+binutils	* Makefile.am: Replace AM_CLFAGS with AM_CFLAGS_FOR_BUILD
+	when building with CC_FOR_BUILD compiler.
+	* Makefile.in: Regenerate.
+	* configure: Likewise.
+	* doc/Makefile.in: Likewise.
+
+gas	* Makefile.in: Regenerate.
+	* configure: Likewise.
+	* doc/Makefile.in: Likewise.
+
+gold	* Makefile.in: Regenerate.
+	* configure: Likewise.
+	* testsuite/Makefile.in: Likewise.
+
+gprof	* Makefile.in: Regenerate.
+	* configure: Likewise.
+
+ld	* Makefile.in: Regenerate.
+	* configure: Likewise.
+
+opcodes	* Makefile.in: Regenerate.
+	* configure: Likewise.
+---
+ bfd/Makefile.in            |  1 +
+ bfd/configure              | 56 +++++++++++++++++++++++++++++++++++++++++-----
+ bfd/doc/Makefile.in        |  1 +
+ bfd/warning.m4             | 47 ++++++++++++++++++++++++++++++++++----
+ binutils/Makefile.am       | 10 +++++----
+ binutils/Makefile.in       | 10 +++++----
+ binutils/configure         | 56 +++++++++++++++++++++++++++++++++++++++++-----
+ binutils/doc/Makefile.in   |  1 +
+ gas/Makefile.in            |  1 +
+ gas/configure              | 56 +++++++++++++++++++++++++++++++++++++++++-----
+ gas/doc/Makefile.in        |  1 +
+ gold/Makefile.in           |  5 +++--
+ gold/configure             | 52 ++++++++++++++++++++++++++++++++++++++----
+ gold/testsuite/Makefile.in |  1 +
+ gprof/Makefile.in          |  1 +
+ gprof/configure            | 56 +++++++++++++++++++++++++++++++++++++++++-----
+ ld/Makefile.in             |  3 ++-
+ ld/configure               | 56 +++++++++++++++++++++++++++++++++++++++++-----
+ opcodes/Makefile.in        |  1 +
+ opcodes/configure          | 56 +++++++++++++++++++++++++++++++++++++++++-----
+ 20 files changed, 416 insertions(+), 55 deletions(-)
+
+--- a/bfd/Makefile.in
++++ b/bfd/Makefile.in
+@@ -288,6 +288,7 @@ TDEFINES = @TDEFINES@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ abs_builddir = @abs_builddir@
+--- a/bfd/configure
++++ b/bfd/configure
+@@ -659,6 +659,7 @@ MAINTAINER_MODE_FALSE
+ MAINTAINER_MODE_TRUE
+ WARN_WRITE_STRINGS
+ NO_WERROR
++WARN_CFLAGS_FOR_BUILD
+ WARN_CFLAGS
+ REPORT_BUGS_TEXI
+ REPORT_BUGS_TO
+@@ -11427,7 +11428,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11430 "configure"
++#line 11431 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11533,7 +11534,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11536 "configure"
++#line 11537 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -12240,8 +12241,12 @@ fi
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -12286,6 +12291,36 @@ fi
+ rm -f conftest*
+ 
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
++fi
++rm -f conftest*
++
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
++fi
++rm -f conftest*
++
++
+ # Check whether --enable-werror was given.
+ if test "${enable_werror+set}" = set; then :
+   enableval=$enable_werror; case "${enableval}" in
+@@ -12301,6 +12336,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -12314,25 +12350,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ # Check whether --enable-build-warnings was given.
+ if test "${enable_build_warnings+set}" = set; then :
+   enableval=$enable_build_warnings; case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w"
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac
+ fi
+ 
+@@ -12343,6 +12386,7 @@ fi
+ 
+ 
+ 
++
+ 
+ 
+ 
+--- a/bfd/doc/Makefile.in
++++ b/bfd/doc/Makefile.in
+@@ -248,6 +248,7 @@ TDEFINES = @TDEFINES@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ abs_builddir = @abs_builddir@
+--- a/bfd/warning.m4
++++ b/bfd/warning.m4
+@@ -17,12 +17,34 @@ dnl along with this program; see the fil
+ dnl <http://www.gnu.org/licenses/>.
+ dnl
+ 
++# AC_EGREP_CPP_FOR_BUILD(PATTERN, PROGRAM,
++#              [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
++# ------------------------------------------------------
++AC_DEFUN([AC_EGREP_CPP_FOR_BUILD],
++[AC_LANG_PREPROC_REQUIRE()dnl
++AC_REQUIRE([AC_PROG_EGREP])dnl
++AC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])])
++AS_IF([dnl eval is necessary to expand ac_cpp.
++dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
++(eval "$ac_cpp_for_build conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
++dnl Quote $1 to prevent m4 from eating character classes
++  $EGREP "[$1]" >/dev/null 2>&1],
++  [$3],
++  [$4])
++rm -f conftest*
++])# AC_EGREP_CPP_FOR_BUILD
++
++
+ AC_DEFUN([AM_BINUTILS_WARNINGS],[
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ AC_EGREP_CPP([^[0-3]$],[__GNUC__],,GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wshadow")
+@@ -34,6 +56,14 @@ AC_EGREP_CPP([^[0-4]$],[__GNUC__],,GCC_W
+ WARN_WRITE_STRINGS=""
+ AC_EGREP_CPP([^[0-3]$],[__GNUC__],,WARN_WRITE_STRINGS="-Wwrite-strings")
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++AC_EGREP_CPP_FOR_BUILD([^[0-3]$],[__GNUC__],,GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow")
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++AC_EGREP_CPP_FOR_BUILD([^[0-4]$],[__GNUC__],,GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144")
++
+ AC_ARG_ENABLE(werror,
+   [  --enable-werror         treat compile warnings as errors],
+   [case "${enableval}" in
+@@ -47,6 +77,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -60,25 +91,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ AC_ARG_ENABLE(build-warnings,
+ [  --enable-build-warnings enable build-time compiler warnings],
+ [case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}" 
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w" 
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac])
+ 
+ if test x"$silent" != x"yes" && test x"$WARN_CFLAGS" != x""; then
+@@ -86,6 +124,7 @@ if test x"$silent" != x"yes" && test x"$
+ fi
+ 
+ AC_SUBST(WARN_CFLAGS)
++AC_SUBST(WARN_CFLAGS_FOR_BUILD)
+ AC_SUBST(NO_WERROR)
+      AC_SUBST(WARN_WRITE_STRINGS)
+ ])
+--- a/binutils/Makefile.am
++++ b/binutils/Makefile.am
+@@ -47,8 +47,10 @@ ZLIB = @zlibdir@ -lz
+ ZLIBINC = @zlibinc@
+ 
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ NO_WERROR = @NO_WERROR@
+ AM_CFLAGS = $(WARN_CFLAGS) $(ZLIBINC)
++AM_CFLAGS_FOR_BUILD = $(WARN_CFLAGS_FOR_BUILD) $(ZLIBINC)
+ LIBICONV = @LIBICONV@
+ 
+ # these two are almost the same program
+@@ -305,17 +307,17 @@ sysinfo$(EXEEXT_FOR_BUILD): sysinfo.@OBJ
+ 	$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ sysinfo.@OBJEXT@ syslex_wrap.@OBJEXT@
+ 
+ syslex_wrap.@OBJEXT@: syslex_wrap.c syslex.c sysinfo.h config.h
+-	$(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex_wrap.c
++	$(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex_wrap.c
+ 
+ sysinfo.@OBJEXT@: sysinfo.c
+ 	if [ -r sysinfo.c ]; then \
+-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
++	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
+ 	else \
+-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
++	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
+ 	fi
+ 
+ bin2c$(EXEEXT_FOR_BUILD): bin2c.c
+-	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
++	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
+ 
+ embedspu: embedspu.sh Makefile
+ 	awk '/^program_transform_name=/ {print "program_transform_name=\"$(program_transform_name)\""; next} {print}' < $< > $@
+--- a/binutils/Makefile.in
++++ b/binutils/Makefile.in
+@@ -401,6 +401,7 @@ STRIP = @STRIP@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ YACC = `if [ -f ../bison/bison ]; then echo ../bison/bison -y -L$(srcdir)/../bison/; else echo @YACC@; fi`
+@@ -478,6 +479,7 @@ am__skipyacc =
+ ZLIB = @zlibdir@ -lz
+ ZLIBINC = @zlibinc@
+ AM_CFLAGS = $(WARN_CFLAGS) $(ZLIBINC)
++AM_CFLAGS_FOR_BUILD = $(WARN_CFLAGS_FOR_BUILD) $(ZLIBINC)
+ 
+ # these two are almost the same program
+ AR_PROG = ar
+@@ -1370,17 +1372,17 @@ sysinfo$(EXEEXT_FOR_BUILD): sysinfo.@OBJ
+ 	$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ sysinfo.@OBJEXT@ syslex_wrap.@OBJEXT@
+ 
+ syslex_wrap.@OBJEXT@: syslex_wrap.c syslex.c sysinfo.h config.h
+-	$(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex_wrap.c
++	$(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex_wrap.c
+ 
+ sysinfo.@OBJEXT@: sysinfo.c
+ 	if [ -r sysinfo.c ]; then \
+-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
++	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
+ 	else \
+-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
++	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
+ 	fi
+ 
+ bin2c$(EXEEXT_FOR_BUILD): bin2c.c
+-	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
++	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
+ 
+ embedspu: embedspu.sh Makefile
+ 	awk '/^program_transform_name=/ {print "program_transform_name=\"$(program_transform_name)\""; next} {print}' < $< > $@
+--- a/binutils/configure
++++ b/binutils/configure
+@@ -652,6 +652,7 @@ YFLAGS
+ YACC
+ WARN_WRITE_STRINGS
+ NO_WERROR
++WARN_CFLAGS_FOR_BUILD
+ WARN_CFLAGS
+ OTOOL64
+ OTOOL
+@@ -11225,7 +11226,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11228 "configure"
++#line 11229 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11331,7 +11332,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11334 "configure"
++#line 11335 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11945,8 +11946,12 @@ _ACEOF
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -11991,6 +11996,36 @@ fi
+ rm -f conftest*
+ 
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
++fi
++rm -f conftest*
++
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
++fi
++rm -f conftest*
++
++
+ # Check whether --enable-werror was given.
+ if test "${enable_werror+set}" = set; then :
+   enableval=$enable_werror; case "${enableval}" in
+@@ -12006,6 +12041,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -12019,25 +12055,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ # Check whether --enable-build-warnings was given.
+ if test "${enable_build_warnings+set}" = set; then :
+   enableval=$enable_build_warnings; case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w"
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac
+ fi
+ 
+@@ -12048,6 +12091,7 @@ fi
+ 
+ 
+ 
++
+ 
+ 
+ 
+--- a/binutils/doc/Makefile.in
++++ b/binutils/doc/Makefile.in
+@@ -249,6 +249,7 @@ STRIP = @STRIP@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ YACC = @YACC@
+--- a/gas/Makefile.in
++++ b/gas/Makefile.in
+@@ -255,6 +255,7 @@ STRIP = @STRIP@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@ @WARN_WRITE_STRINGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ YACC = `if [ -f ../bison/bison ] ; then echo ../bison/bison -y -L../bison/bison ; else echo @YACC@ ; fi`
+--- a/gas/configure
++++ b/gas/configure
+@@ -642,6 +642,7 @@ cgen_cpu_prefix
+ GDBINIT
+ WARN_WRITE_STRINGS
+ NO_WERROR
++WARN_CFLAGS_FOR_BUILD
+ WARN_CFLAGS
+ OTOOL64
+ OTOOL
+@@ -10985,7 +10986,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10988 "configure"
++#line 10989 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11091,7 +11092,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11094 "configure"
++#line 11095 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11721,8 +11722,12 @@ using_cgen=no
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -11767,6 +11772,36 @@ fi
+ rm -f conftest*
+ 
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
++fi
++rm -f conftest*
++
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
++fi
++rm -f conftest*
++
++
+ # Check whether --enable-werror was given.
+ if test "${enable_werror+set}" = set; then :
+   enableval=$enable_werror; case "${enableval}" in
+@@ -11782,6 +11817,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -11795,25 +11831,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ # Check whether --enable-build-warnings was given.
+ if test "${enable_build_warnings+set}" = set; then :
+   enableval=$enable_build_warnings; case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w"
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac
+ fi
+ 
+@@ -11824,6 +11867,7 @@ fi
+ 
+ 
+ 
++
+ 
+ 
+ 
+--- a/gas/doc/Makefile.in
++++ b/gas/doc/Makefile.in
+@@ -230,6 +230,7 @@ STRIP = @STRIP@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ YACC = @YACC@
+--- a/gold/Makefile.in
++++ b/gold/Makefile.in
+@@ -87,8 +87,8 @@ subdir = .
+ DIST_COMMON = NEWS README ChangeLog $(srcdir)/Makefile.in \
+ 	$(srcdir)/Makefile.am $(top_srcdir)/configure \
+ 	$(am__configure_deps) $(srcdir)/config.in \
+-	$(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in \
+-	ftruncate.c pread.c mremap.c ffsll.c yyscript.h yyscript.c \
++	$(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in ffsll.c \
++	mremap.c ftruncate.c pread.c yyscript.h yyscript.c \
+ 	$(srcdir)/../depcomp $(srcdir)/../ylwrap
+ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
+@@ -409,6 +409,7 @@ TARGETOBJS = @TARGETOBJS@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_CXXFLAGS = @WARN_CXXFLAGS@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+--- a/gold/configure
++++ b/gold/configure
+@@ -609,6 +609,7 @@ GOLD_LDFLAGS
+ WARN_CXXFLAGS
+ WARN_WRITE_STRINGS
+ NO_WERROR
++WARN_CFLAGS_FOR_BUILD
+ WARN_CFLAGS
+ IFUNC_STATIC_FALSE
+ IFUNC_STATIC_TRUE
+@@ -6723,8 +6724,12 @@ fi
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -6769,6 +6774,36 @@ fi
+ rm -f conftest*
+ 
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
++fi
++rm -f conftest*
++
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
++fi
++rm -f conftest*
++
++
+ # Check whether --enable-werror was given.
+ if test "${enable_werror+set}" = set; then :
+   enableval=$enable_werror; case "${enableval}" in
+@@ -6784,6 +6819,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -6797,25 +6833,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ # Check whether --enable-build-warnings was given.
+ if test "${enable_build_warnings+set}" = set; then :
+   enableval=$enable_build_warnings; case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w"
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac
+ fi
+ 
+@@ -6826,6 +6869,7 @@ fi
+ 
+ 
+ 
++
+ 
+ 
+ 
+--- a/gold/testsuite/Makefile.in
++++ b/gold/testsuite/Makefile.in
+@@ -2568,6 +2568,7 @@ TARGETOBJS = @TARGETOBJS@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_CXXFLAGS = @WARN_CXXFLAGS@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+--- a/gprof/Makefile.in
++++ b/gprof/Makefile.in
+@@ -267,6 +267,7 @@ STRIP = @STRIP@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ abs_builddir = @abs_builddir@
+--- a/gprof/configure
++++ b/gprof/configure
+@@ -604,6 +604,7 @@ LTLIBOBJS
+ LIBOBJS
+ WARN_WRITE_STRINGS
+ NO_WERROR
++WARN_CFLAGS_FOR_BUILD
+ WARN_CFLAGS
+ GENINSRC_NEVER_FALSE
+ GENINSRC_NEVER_TRUE
+@@ -10901,7 +10902,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10904 "configure"
++#line 10905 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11007,7 +11008,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11010 "configure"
++#line 11011 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -12101,8 +12102,12 @@ fi
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -12147,6 +12152,36 @@ fi
+ rm -f conftest*
+ 
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
++fi
++rm -f conftest*
++
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
++fi
++rm -f conftest*
++
++
+ # Check whether --enable-werror was given.
+ if test "${enable_werror+set}" = set; then :
+   enableval=$enable_werror; case "${enableval}" in
+@@ -12162,6 +12197,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -12175,25 +12211,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ # Check whether --enable-build-warnings was given.
+ if test "${enable_build_warnings+set}" = set; then :
+   enableval=$enable_build_warnings; case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w"
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac
+ fi
+ 
+@@ -12204,6 +12247,7 @@ fi
+ 
+ 
+ 
++
+ 
+ 
+ 
+--- a/ld/Makefile.in
++++ b/ld/Makefile.in
+@@ -354,6 +354,7 @@ TESTBFDLIB = @TESTBFDLIB@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ YACC = `if [ -f ../bison/bison ]; then echo ../bison/bison -y -L$(srcdir)/../bison/; else echo @YACC@; fi`
+@@ -508,7 +509,7 @@ CXX_FOR_TARGET = ` \
+   fi`
+ 
+ 
+-# Strip out sanitization options as they require special host libraries.
++# Strip out sanitization options as we want to test building binaries without any extra paraphernalia
+ CFLAGS_FOR_TARGET = `echo $(CFLAGS) | sed -e 's/-fsanitize=address//g' -e 's/-fsanitize=undefined//g'`
+ CXXFLAGS_FOR_TARGET = `echo $(CXXFLAGS) | sed -e 's/-fsanitize=address//g' -e 's/-fsanitize=undefined//g'`
+ info_TEXINFOS = ld.texinfo
+--- a/ld/configure
++++ b/ld/configure
+@@ -646,6 +646,7 @@ LIBINTL
+ USE_NLS
+ WARN_WRITE_STRINGS
+ NO_WERROR
++WARN_CFLAGS_FOR_BUILD
+ WARN_CFLAGS
+ installed_linker
+ install_as_default
+@@ -11723,7 +11724,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11726 "configure"
++#line 11727 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11829,7 +11830,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11832 "configure"
++#line 11833 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -15558,8 +15559,12 @@ fi
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -15604,6 +15609,36 @@ fi
+ rm -f conftest*
+ 
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
++fi
++rm -f conftest*
++
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
++fi
++rm -f conftest*
++
++
+ # Check whether --enable-werror was given.
+ if test "${enable_werror+set}" = set; then :
+   enableval=$enable_werror; case "${enableval}" in
+@@ -15619,6 +15654,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -15632,25 +15668,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ # Check whether --enable-build-warnings was given.
+ if test "${enable_build_warnings+set}" = set; then :
+   enableval=$enable_build_warnings; case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w"
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac
+ fi
+ 
+@@ -15661,6 +15704,7 @@ fi
+ 
+ 
+ 
++
+ 
+ 
+ 
+--- a/opcodes/Makefile.in
++++ b/opcodes/Makefile.in
+@@ -267,6 +267,7 @@ STRIP = @STRIP@
+ USE_NLS = @USE_NLS@
+ VERSION = @VERSION@
+ WARN_CFLAGS = @WARN_CFLAGS@
++WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
+ WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
+ XGETTEXT = @XGETTEXT@
+ abs_builddir = @abs_builddir@
+--- a/opcodes/configure
++++ b/opcodes/configure
+@@ -643,6 +643,7 @@ MAINTAINER_MODE_TRUE
+ NO_WMISSING_FIELD_INITIALIZERS
+ WARN_WRITE_STRINGS
+ NO_WERROR
++WARN_CFLAGS_FOR_BUILD
+ WARN_CFLAGS
+ OTOOL64
+ OTOOL
+@@ -11150,7 +11151,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11153 "configure"
++#line 11154 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11256,7 +11257,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11259 "configure"
++#line 11260 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11508,8 +11509,12 @@ fi
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+ 
++# Set acp_cpp_for_build variable
++ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
++
+ # Default set of GCC warnings to enable.
+ GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
++GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ 
+ # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -11554,6 +11559,36 @@ fi
+ rm -f conftest*
+ 
+ 
++# Verify CC_FOR_BUILD to be compatible with waring flags
++
++# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
++fi
++rm -f conftest*
++
++
++# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++__GNUC__
++_ACEOF
++if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
++  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
++
++else
++  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
++fi
++rm -f conftest*
++
++
+ # Check whether --enable-werror was given.
+ if test "${enable_werror+set}" = set; then :
+   enableval=$enable_werror; case "${enableval}" in
+@@ -11569,6 +11604,7 @@ case "${host}" in
+   *-*-mingw32*)
+     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
++      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
+     fi
+     ;;
+   *) ;;
+@@ -11582,25 +11618,32 @@ fi
+ NO_WERROR=
+ if test "${ERROR_ON_WARNING}" = yes ; then
+     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
++    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
+     NO_WERROR="-Wno-error"
+ fi
+ 
+ if test "${GCC}" = yes ; then
+   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
+ fi
+ 
+ # Check whether --enable-build-warnings was given.
+ if test "${enable_build_warnings+set}" = set; then :
+   enableval=$enable_build_warnings; case "${enableval}" in
+-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
++  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
+   no)	if test "${GCC}" = yes ; then
+ 	  WARN_CFLAGS="-w"
++      WARN_CFLAGS_FOR_BUILD="-w"
+ 	fi;;
+   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
++        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
++        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
+   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
+-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
+-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
++        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
++        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
++  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
++        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
+ esac
+ fi
+ 
+@@ -11611,6 +11654,7 @@ fi
+ 
+ 
+ 
++
+ 
+ 
+ ac_ext=c

+ 7 - 7
package/kernel/linux/modules/crypto.mk

@@ -436,7 +436,7 @@ endef
 
 define KernelPackage/crypto-md5/octeon
   FILES+=$(LINUX_DIR)/arch/mips/cavium-octeon/crypto/octeon-md5.ko
-  AUTOLOAD:=$(call AutoLoad,09,octeon-md5)
+  AUTOLOAD+=$(call AutoLoad,09,octeon-md5)
 endef
 
 $(eval $(call KernelPackage,crypto-md5))
@@ -468,12 +468,12 @@ endef
 
 define KernelPackage/crypto-sha1/octeon
   FILES+=$(LINUX_DIR)/arch/mips/cavium-octeon/crypto/octeon-sha1.ko
-  AUTOLOAD:=$(call AutoLoad,09,octeon-sha1)
+  AUTOLOAD+=$(call AutoLoad,09,octeon-sha1)
 endef
 
 define KernelPackage/crypto-sha1/x86/64
   FILES+=$(LINUX_DIR)/arch/x86/crypto/sha1-ssse3.ko
-  AUTOLOAD:=$(call AutoLoad,09,sha1-ssse3)
+  AUTOLOAD+=$(call AutoLoad,09,sha1-ssse3)
 endef
 
 $(eval $(call KernelPackage,crypto-sha1))
@@ -493,12 +493,12 @@ endef
 
 define KernelPackage/crypto-sha256/octeon
   FILES+=$(LINUX_DIR)/arch/mips/cavium-octeon/crypto/octeon-sha256.ko
-  AUTOLOAD:=$(call AutoLoad,09,octeon-sha256)
+  AUTOLOAD+=$(call AutoLoad,09,octeon-sha256)
 endef
 
 define KernelPackage/crypto-sha256/x86/64
   FILES+=$(LINUX_DIR)/arch/x86/crypto/sha256-ssse3.ko
-  AUTOLOAD:=$(call AutoLoad,09,sha256-ssse3)
+  AUTOLOAD+=$(call AutoLoad,09,sha256-ssse3)
 endef
 
 $(eval $(call KernelPackage,crypto-sha256))
@@ -518,12 +518,12 @@ endef
 
 define KernelPackage/crypto-sha512/octeon
   FILES+=$(LINUX_DIR)/arch/mips/cavium-octeon/crypto/octeon-sha512.ko
-  AUTOLOAD:=$(call AutoLoad,09,octeon-sha512)
+  AUTOLOAD+=$(call AutoLoad,09,octeon-sha512)
 endef
 
 define KernelPackage/crypto-sha512/x86/64
   FILES+=$(LINUX_DIR)/arch/x86/crypto/sha512-ssse3.ko
-  AUTOLOAD:=$(call AutoLoad,09,sha512-ssse3)
+  AUTOLOAD+=$(call AutoLoad,09,sha512-ssse3)
 endef
 
 $(eval $(call KernelPackage,crypto-sha512))

+ 0 - 1
package/kernel/linux/modules/netdevices.mk

@@ -446,7 +446,6 @@ endef
 
 $(eval $(call KernelPackage,ne2k-pci))
 
-
 define KernelPackage/e1000
   SUBMENU:=$(NETWORK_DEVICES_MENU)
   TITLE:=Intel(R) PRO/1000 PCI cards kernel support

+ 2 - 2
package/kernel/linux/modules/netfilter.mk

@@ -360,8 +360,6 @@ define KernelPackage/nf-nathelper/description
  Default Netfilter (IPv4) Conntrack and NAT helpers
  Includes:
  - ftp
- - irc
- - tftp
 endef
 
 $(eval $(call KernelPackage,nf-nathelper))
@@ -381,11 +379,13 @@ define KernelPackage/nf-nathelper-extra/description
  Includes:
  - amanda
  - h323
+ - irc
  - mms
  - pptp
  - proto_gre
  - sip
  - snmp_basic
+ - tftp
  - broadcast
 endef
 

+ 1 - 1
package/kernel/linux/modules/sound.mk

@@ -67,7 +67,7 @@ define KernelPackage/sound-core/uml
   FILES:= \
 	$(LINUX_DIR)/sound/soundcore.ko \
 	$(LINUX_DIR)/arch/um/drivers/hostaudio.ko
-  AUTOLOAD:=$(call AutoLoad,30,soundcore hostaudio)
+  AUTOLOAD+=$(call AutoLoad,30,soundcore hostaudio)
 endef
 
 define KernelPackage/sound-core/description

+ 2 - 2
package/kernel/linux/modules/video.mk

@@ -47,7 +47,7 @@ define KernelPackage/backlight-pwm
 	AUTOLOAD:=$(call AutoProbe,video pwm_bl)
 endef
 
-define KernelPackage/backlight/backlight-pwm
+define KernelPackage/backlight-pwm/description
 	Kernel module for PWM based Backlight support.
 endef
 
@@ -72,7 +72,7 @@ endef
 
 define KernelPackage/fb/x86
   FILES+=$(LINUX_DIR)/arch/x86/video/fbdev.ko
-  AUTOLOAD:=$(call AutoLoad,06,fbdev fb)
+  AUTOLOAD+=$(call AutoLoad,06,fbdev fb)
 endef
 
 $(eval $(call KernelPackage,fb))

+ 6 - 4
package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh

@@ -268,7 +268,7 @@ mac80211_hostapd_setup_base() {
 			vht_max_mpdu_hw=11454
 		[ "$vht_max_mpdu_hw" != 3895 ] && \
 			vht_capab="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
-			
+
 		# maximum A-MPDU length exponent
 		vht_max_a_mpdu_len_exp_hw=0
 		[ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \
@@ -566,7 +566,7 @@ mac80211_setup_adhoc() {
 	[ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
 
 	iw dev "$ifname" ibss join "$ssid" $freq $ibss_htmode fixed-freq $bssid \
-		${beacon_int:+beacon-interval $beacon_int} \
+		beacon-interval $beacon_int \
 		${brstr:+basic-rates $brstr} \
 		${mcval:+mcast-rate $mcval} \
 		${keyspec:+keys $keyspec}
@@ -646,7 +646,9 @@ mac80211_setup_vif() {
 				esac
 
 				freq="$(get_freq "$phy" "$channel")"
-				iw dev "$ifname" mesh join "$mesh_id" freq $freq $mesh_htmode ${mcval:+mcast-rate $mcval}
+				iw dev "$ifname" mesh join "$mesh_id" freq $freq $mesh_htmode \
+					${mcval:+mcast-rate $mcval} \
+					beacon-interval $beacon_int
 			fi
 
 			for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
@@ -698,7 +700,7 @@ drv_mac80211_setup() {
 		country chanbw distance \
 		txpower antenna_gain \
 		rxantenna txantenna \
-		frag rts beacon_int htmode
+		frag rts beacon_int:100 htmode
 	json_get_values basic_rate_list basic_rate
 	json_select ..
 

+ 3 - 3
package/kernel/mac80211/files/lib/wifi/mac80211.sh

@@ -92,7 +92,7 @@ detect_mac80211() {
 			htmode="VHT80"
 		}
 
-		[ -n $htmode ] && ht_capab="set wireless.radio${devidx}.htmode=$htmode"
+		[ -n "$htmode" ] && ht_capab="set wireless.radio${devidx}.htmode=$htmode"
 
 		if [ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${dev} ]; then
 			path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
@@ -123,8 +123,8 @@ detect_mac80211() {
 			set wireless.default_radio${devidx}.network=lan
 			set wireless.default_radio${devidx}.mode=ap
 			set wireless.default_radio${devidx}.ssid=libreCMC
-			set wireless.default_radio${devidx}.encryption=psk
-			set wireless.default_radio${devidx}.key=librecmc
+                        set wireless.default_radio${devidx}.encryption=psk
+                        set wireless.default_radio${devidx}.key=librecmc
 EOF
 		uci -q commit wireless
 

+ 16 - 4
package/kernel/mac80211/patches/317-rt2x00-avoid-introducing-a-USB-dependency-in-the-rt2.patch → package/kernel/mac80211/patches/020-01-rt2x00-avoid-introducing-a-USB-dependency-in-the-rt2.patch

@@ -1,6 +1,7 @@
+From 6232c17438ed01f43665197db5a98a4a4f77ef47 Mon Sep 17 00:00:00 2001
 From: Stanislaw Gruszka <sgruszka@redhat.com>
 Date: Thu, 2 Feb 2017 10:57:40 +0100
-Subject: [PATCH] rt2x00: avoid introducing a USB dependency in the
+Subject: [PATCH 01/19] rt2x00: avoid introducing a USB dependency in the
  rt2x00lib module
 
 As reported by Felix:
@@ -16,11 +17,17 @@ Cc: Vishal Thanki <vishalthanki@gmail.com>
 Reported-by: Felix Fietkau <nbd@nbd.name>
 Fixes: 8b4c0009313f ("rt2x00usb: Use usb anchor to manage URB")
 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
 ---
+ drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 23 ++++++++---------------
+ drivers/net/wireless/ralink/rt2x00/rt2x00usb.c |  5 +++++
+ 2 files changed, 13 insertions(+), 15 deletions(-)
 
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+index 8fcbc8dc94c1..4b08007f93f7 100644
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
-@@ -1436,21 +1436,6 @@ void rt2x00lib_remove_dev(struct rt2x00_
+@@ -1436,21 +1436,6 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
  	cancel_work_sync(&rt2x00dev->intf_work);
  	cancel_delayed_work_sync(&rt2x00dev->autowakeup_work);
  	cancel_work_sync(&rt2x00dev->sleep_work);
@@ -42,7 +49,7 @@ Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
  
  	/*
  	 * Kill the tx status tasklet.
-@@ -1466,6 +1451,14 @@ void rt2x00lib_remove_dev(struct rt2x00_
+@@ -1466,6 +1451,14 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
  	 */
  	rt2x00lib_uninitialize(rt2x00dev);
  
@@ -57,9 +64,11 @@ Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
  	/*
  	 * Free extra components
  	 */
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+index 838ca58d2dd6..5a2bf9f63cd7 100644
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
-@@ -744,6 +744,11 @@ void rt2x00usb_uninitialize(struct rt2x0
+@@ -744,6 +744,11 @@ void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev)
  {
  	struct data_queue *queue;
  
@@ -71,3 +80,6 @@ Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
  	queue_for_each(rt2x00dev, queue)
  		rt2x00usb_free_entries(queue);
  }
+-- 
+2.12.1
+

+ 61 - 0
package/kernel/mac80211/patches/020-02-rt2x00usb-do-not-anchor-rx-and-tx-urb-s.patch

@@ -0,0 +1,61 @@
+From 93c7018ec16bb83399dd4db61c361a6d6aba0d5a Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 8 Feb 2017 12:18:09 +0100
+Subject: [PATCH 02/19] rt2x00usb: do not anchor rx and tx urb's
+
+We might kill TX or RX urb during rt2x00usb_flush_entry(), what can
+cause anchor list corruption like shown below:
+
+[ 2074.035633] WARNING: CPU: 2 PID: 14480 at lib/list_debug.c:33 __list_add+0xac/0xc0
+[ 2074.035634] list_add corruption. prev->next should be next (ffff88020f362c28), but was dead000000000100. (prev=ffff8801d161bb70).
+<snip>
+[ 2074.035670] Call Trace:
+[ 2074.035672]  [<ffffffff813bde47>] dump_stack+0x63/0x8c
+[ 2074.035674]  [<ffffffff810a2231>] __warn+0xd1/0xf0
+[ 2074.035676]  [<ffffffff810a22af>] warn_slowpath_fmt+0x5f/0x80
+[ 2074.035678]  [<ffffffffa073855d>] ? rt2x00usb_register_write_lock+0x3d/0x60 [rt2800usb]
+[ 2074.035679]  [<ffffffff813dbe4c>] __list_add+0xac/0xc0
+[ 2074.035681]  [<ffffffff81591c6c>] usb_anchor_urb+0x4c/0xa0
+[ 2074.035683]  [<ffffffffa07322af>] rt2x00usb_kick_rx_entry+0xaf/0x100 [rt2x00usb]
+[ 2074.035684]  [<ffffffffa0732322>] rt2x00usb_clear_entry+0x22/0x30 [rt2x00usb]
+
+To fix do not anchor TX and RX urb's, it is not needed as during
+shutdown we kill those urbs in rt2x00usb_free_entries().
+
+Cc: Vishal Thanki <vishalthanki@gmail.com>
+Fixes: 8b4c0009313f ("rt2x00usb: Use usb anchor to manage URB")
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 4 ----
+ 1 file changed, 4 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+index 5a2bf9f63cd7..fe13dd07cc2a 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+@@ -319,10 +319,8 @@ static bool rt2x00usb_kick_tx_entry(struct queue_entry *entry, void *data)
+ 			  entry->skb->data, length,
+ 			  rt2x00usb_interrupt_txdone, entry);
+ 
+-	usb_anchor_urb(entry_priv->urb, rt2x00dev->anchor);
+ 	status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
+ 	if (status) {
+-		usb_unanchor_urb(entry_priv->urb);
+ 		if (status == -ENODEV)
+ 			clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
+ 		set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
+@@ -410,10 +408,8 @@ static bool rt2x00usb_kick_rx_entry(struct queue_entry *entry, void *data)
+ 			  entry->skb->data, entry->skb->len,
+ 			  rt2x00usb_interrupt_rxdone, entry);
+ 
+-	usb_anchor_urb(entry_priv->urb, rt2x00dev->anchor);
+ 	status = usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
+ 	if (status) {
+-		usb_unanchor_urb(entry_priv->urb);
+ 		if (status == -ENODEV)
+ 			clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
+ 		set_bit(ENTRY_DATA_IO_FAILED, &entry->flags);
+-- 
+2.12.1
+

+ 75 - 0
package/kernel/mac80211/patches/020-03-rt2x00usb-fix-anchor-initialization.patch

@@ -0,0 +1,75 @@
+From 0488a6121dfe6cbd44de15ea3627913b7549a1e9 Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 8 Feb 2017 12:18:10 +0100
+Subject: [PATCH 03/19] rt2x00usb: fix anchor initialization
+
+If device fail to initialize we can OOPS in rt2x00lib_remove_dev(), due
+to using uninitialized usb_anchor structure:
+
+[  855.435820] ieee80211 phy3: rt2x00usb_vendor_request: Error - Vendor Request 0x07 failed for offset 0x1000 with error -19
+[  855.435826] ieee80211 phy3: rt2800_probe_rt: Error - Invalid RT chipset 0x0000, rev 0000 detected
+[  855.435829] ieee80211 phy3: rt2x00lib_probe_dev: Error - Failed to allocate device
+[  855.435845] BUG: unable to handle kernel NULL pointer dereference at 0000000000000028
+[  855.435900] IP: _raw_spin_lock_irq+0xd/0x30
+[  855.435926] PGD 0
+[  855.435953] Oops: 0002 [#1] SMP
+<snip>
+[  855.437011] Call Trace:
+[  855.437029]  ? usb_kill_anchored_urbs+0x27/0xc0
+[  855.437061]  rt2x00lib_remove_dev+0x190/0x1c0 [rt2x00lib]
+[  855.437097]  rt2x00lib_probe_dev+0x246/0x7a0 [rt2x00lib]
+[  855.437149]  ? ieee80211_roc_setup+0x9e/0xd0 [mac80211]
+[  855.437183]  ? __kmalloc+0x1af/0x1f0
+[  855.437207]  ? rt2x00usb_probe+0x13d/0xc50 [rt2x00usb]
+[  855.437240]  rt2x00usb_probe+0x155/0xc50 [rt2x00usb]
+[  855.437273]  rt2800usb_probe+0x15/0x20 [rt2800usb]
+[  855.437304]  usb_probe_interface+0x159/0x2d0
+[  855.437333]  driver_probe_device+0x2bb/0x460
+
+Patch changes initialization sequence to fix the problem.
+
+Cc: Vishal Thanki <vishalthanki@gmail.com>
+Fixes: 8b4c0009313f ("rt2x00usb: Use usb anchor to manage URB")
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 13 ++++++++-----
+ 1 file changed, 8 insertions(+), 5 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+index fe13dd07cc2a..c696f0ad6a68 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+@@ -825,10 +825,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
+ 	if (retval)
+ 		goto exit_free_device;
+ 
+-	retval = rt2x00lib_probe_dev(rt2x00dev);
+-	if (retval)
+-		goto exit_free_reg;
+-
+ 	rt2x00dev->anchor = devm_kmalloc(&usb_dev->dev,
+ 					sizeof(struct usb_anchor),
+ 					GFP_KERNEL);
+@@ -836,10 +832,17 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
+ 		retval = -ENOMEM;
+ 		goto exit_free_reg;
+ 	}
+-
+ 	init_usb_anchor(rt2x00dev->anchor);
++
++	retval = rt2x00lib_probe_dev(rt2x00dev);
++	if (retval)
++		goto exit_free_anchor;
++
+ 	return 0;
+ 
++exit_free_anchor:
++	usb_kill_anchored_urbs(rt2x00dev->anchor);
++
+ exit_free_reg:
+ 	rt2x00usb_free_reg(rt2x00dev);
+ 
+-- 
+2.12.1
+

+ 28 - 0
package/kernel/mac80211/patches/020-04-rt61pci-use-entry-directly.patch

@@ -0,0 +1,28 @@
+From 80a97eae304631f57ff8560f87c0b18b95321443 Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 8 Feb 2017 13:51:29 +0100
+Subject: [PATCH 04/19] rt61pci: use entry directly
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt61pci.c | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt61pci.c b/drivers/net/wireless/ralink/rt2x00/rt61pci.c
+index 5306a3b2622d..8adb5f3abe15 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt61pci.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt61pci.c
+@@ -1903,8 +1903,7 @@ static void rt61pci_write_tx_desc(struct queue_entry *entry,
+ 
+ 	rt2x00_desc_read(txd, 5, &word);
+ 	rt2x00_set_field32(&word, TXD_W5_PID_TYPE, entry->queue->qid);
+-	rt2x00_set_field32(&word, TXD_W5_PID_SUBTYPE,
+-			   skbdesc->entry->entry_idx);
++	rt2x00_set_field32(&word, TXD_W5_PID_SUBTYPE, entry->entry_idx);
+ 	rt2x00_set_field32(&word, TXD_W5_TX_POWER,
+ 			   TXPOWER_TO_DEV(entry->queue->rt2x00dev->tx_power));
+ 	rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
+-- 
+2.12.1
+

+ 181 - 0
package/kernel/mac80211/patches/020-05-rt2x00-call-entry-directly-in-rt2x00_dump_frame.patch

@@ -0,0 +1,181 @@
+From 2ceb813798e1fd33e71a574771828c0f298e077b Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 8 Feb 2017 13:51:30 +0100
+Subject: [PATCH 05/19] rt2x00: call entry directly in rt2x00_dump_frame
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2400pci.c   | 2 +-
+ drivers/net/wireless/ralink/rt2x00/rt2500pci.c   | 2 +-
+ drivers/net/wireless/ralink/rt2x00/rt2500usb.c   | 2 +-
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c   | 2 +-
+ drivers/net/wireless/ralink/rt2x00/rt2x00.h      | 4 ++--
+ drivers/net/wireless/ralink/rt2x00/rt2x00debug.c | 7 ++++---
+ drivers/net/wireless/ralink/rt2x00/rt2x00dev.c   | 4 ++--
+ drivers/net/wireless/ralink/rt2x00/rt2x00queue.c | 2 +-
+ drivers/net/wireless/ralink/rt2x00/rt61pci.c     | 2 +-
+ drivers/net/wireless/ralink/rt2x00/rt73usb.c     | 2 +-
+ 10 files changed, 15 insertions(+), 14 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2400pci.c b/drivers/net/wireless/ralink/rt2x00/rt2400pci.c
+index 085c5b423bdf..19874439ac40 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2400pci.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2400pci.c
+@@ -1200,7 +1200,7 @@ static void rt2400pci_write_beacon(struct queue_entry *entry,
+ 	/*
+ 	 * Dump beacon to userspace through debugfs.
+ 	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry);
+ out:
+ 	/*
+ 	 * Enable beaconing again.
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2500pci.c b/drivers/net/wireless/ralink/rt2x00/rt2500pci.c
+index 9832fd50c793..791434de8052 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2500pci.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2500pci.c
+@@ -1349,7 +1349,7 @@ static void rt2500pci_write_beacon(struct queue_entry *entry,
+ 	/*
+ 	 * Dump beacon to userspace through debugfs.
+ 	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry);
+ out:
+ 	/*
+ 	 * Enable beaconing again.
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2500usb.c b/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
+index cd3ab5a9e98d..62357465fe29 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
+@@ -1170,7 +1170,7 @@ static void rt2500usb_write_beacon(struct queue_entry *entry,
+ 	/*
+ 	 * Dump beacon to userspace through debugfs.
+ 	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry);
+ 
+ 	/*
+ 	 * USB devices cannot blindly pass the skb->len as the
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 572cdea4ca25..8223a1520316 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -1014,7 +1014,7 @@ void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
+ 	/*
+ 	 * Dump beacon to userspace through debugfs.
+ 	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry);
+ 
+ 	/*
+ 	 * Write entire beacon with TXWI and padding to register.
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+index ea299c4e7ada..26869b3bef45 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+@@ -1400,11 +1400,11 @@ void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
+  */
+ #ifdef CPTCFG_RT2X00_LIB_DEBUGFS
+ void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
+-			    enum rt2x00_dump_type type, struct sk_buff *skb);
++			    enum rt2x00_dump_type type, struct queue_entry *entry);
+ #else
+ static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
+ 					  enum rt2x00_dump_type type,
+-					  struct sk_buff *skb)
++					  struct queue_entry *entry)
+ {
+ }
+ #endif /* CPTCFG_RT2X00_LIB_DEBUGFS */
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00debug.c b/drivers/net/wireless/ralink/rt2x00/rt2x00debug.c
+index 72ae530e4a3b..964aefdc11f0 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00debug.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00debug.c
+@@ -157,9 +157,10 @@ void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
+ }
+ 
+ void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
+-			    enum rt2x00_dump_type type, struct sk_buff *skb)
++			    enum rt2x00_dump_type type, struct queue_entry *entry)
+ {
+ 	struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
++	struct sk_buff *skb = entry->skb;
+ 	struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
+ 	struct sk_buff *skbcopy;
+ 	struct rt2x00dump_hdr *dump_hdr;
+@@ -196,8 +197,8 @@ void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
+ 	dump_hdr->chip_rf = cpu_to_le16(rt2x00dev->chip.rf);
+ 	dump_hdr->chip_rev = cpu_to_le16(rt2x00dev->chip.rev);
+ 	dump_hdr->type = cpu_to_le16(type);
+-	dump_hdr->queue_index = skbdesc->entry->queue->qid;
+-	dump_hdr->entry_index = skbdesc->entry->entry_idx;
++	dump_hdr->queue_index = entry->queue->qid;
++	dump_hdr->entry_index = entry->entry_idx;
+ 	dump_hdr->timestamp_sec = cpu_to_le32(timestamp.tv_sec);
+ 	dump_hdr->timestamp_usec = cpu_to_le32(timestamp.tv_usec);
+ 
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+index 4b08007f93f7..dd6678109b7e 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+@@ -363,7 +363,7 @@ void rt2x00lib_txdone(struct queue_entry *entry,
+ 	 * Send frame to debugfs immediately, after this call is completed
+ 	 * we are going to overwrite the skb->cb array.
+ 	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry);
+ 
+ 	/*
+ 	 * Determine if the frame has been successfully transmitted and
+@@ -772,7 +772,7 @@ void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp)
+ 	 */
+ 	rt2x00link_update_stats(rt2x00dev, entry->skb, &rxdesc);
+ 	rt2x00debug_update_crypto(rt2x00dev, &rxdesc);
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry);
+ 
+ 	/*
+ 	 * Initialize RX status information, and send frame
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+index b2364d378774..380daf4e1b8d 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+@@ -544,7 +544,7 @@ static void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
+ 	 * All processing on the frame has been completed, this means
+ 	 * it is now ready to be dumped to userspace through debugfs.
+ 	 */
+-	rt2x00debug_dump_frame(queue->rt2x00dev, DUMP_FRAME_TX, entry->skb);
++	rt2x00debug_dump_frame(queue->rt2x00dev, DUMP_FRAME_TX, entry);
+ }
+ 
+ static void rt2x00queue_kick_tx_queue(struct data_queue *queue,
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt61pci.c b/drivers/net/wireless/ralink/rt2x00/rt61pci.c
+index 8adb5f3abe15..973d418b8113 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt61pci.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt61pci.c
+@@ -1988,7 +1988,7 @@ static void rt61pci_write_beacon(struct queue_entry *entry,
+ 	/*
+ 	 * Dump beacon to userspace through debugfs.
+ 	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry);
+ 
+ 	/*
+ 	 * Write entire beacon with descriptor and padding to register.
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt73usb.c b/drivers/net/wireless/ralink/rt2x00/rt73usb.c
+index 1a29c4d205a5..bb8d307a789f 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt73usb.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt73usb.c
+@@ -1557,7 +1557,7 @@ static void rt73usb_write_beacon(struct queue_entry *entry,
+ 	/*
+ 	 * Dump beacon to userspace through debugfs.
+ 	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry);
+ 
+ 	/*
+ 	 * Write entire beacon with descriptor and padding to register.
+-- 
+2.12.1
+

+ 59 - 0
package/kernel/mac80211/patches/020-06-rt2x00-remove-queue_entry-from-skbdesc.patch

@@ -0,0 +1,59 @@
+From cf81db30a6edcca791b1bfa5348a162471121d11 Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 8 Feb 2017 13:51:31 +0100
+Subject: [PATCH 06/19] rt2x00: remove queue_entry from skbdesc
+
+queue_entry field of skbdesc is not read any more, remove it to allow
+skbdesc contain other data.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00queue.c | 3 ---
+ drivers/net/wireless/ralink/rt2x00/rt2x00queue.h | 2 --
+ 2 files changed, 5 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+index 380daf4e1b8d..e1660b92b20c 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+@@ -83,7 +83,6 @@ struct sk_buff *rt2x00queue_alloc_rxskb(struct queue_entry *entry, gfp_t gfp)
+ 	 */
+ 	skbdesc = get_skb_frame_desc(skb);
+ 	memset(skbdesc, 0, sizeof(*skbdesc));
+-	skbdesc->entry = entry;
+ 
+ 	if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_DMA)) {
+ 		dma_addr_t skb_dma;
+@@ -689,7 +688,6 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
+ 		goto out;
+ 	}
+ 
+-	skbdesc->entry = entry;
+ 	entry->skb = skb;
+ 
+ 	/*
+@@ -774,7 +772,6 @@ int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
+ 	 */
+ 	skbdesc = get_skb_frame_desc(intf->beacon->skb);
+ 	memset(skbdesc, 0, sizeof(*skbdesc));
+-	skbdesc->entry = intf->beacon;
+ 
+ 	/*
+ 	 * Send beacon to hardware.
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
+index 2233b911a1d7..22d18818e850 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
+@@ -116,8 +116,6 @@ struct skb_frame_desc {
+ 	__le32 iv[2];
+ 
+ 	dma_addr_t skb_dma;
+-
+-	struct queue_entry *entry;
+ };
+ 
+ /**
+-- 
+2.12.1
+

+ 84 - 0
package/kernel/mac80211/patches/020-07-rt2500usb-don-t-mark-register-accesses-as-inline.patch

@@ -0,0 +1,84 @@
+From 7272416609126e8910b7f0d0e3dba008aa87830c Mon Sep 17 00:00:00 2001
+From: Arnd Bergmann <arnd@arndb.de>
+Date: Tue, 14 Feb 2017 22:28:33 +0100
+Subject: [PATCH 07/19] rt2500usb: don't mark register accesses as inline
+
+When CONFIG_KASAN is set, we get a rather large stack here:
+
+drivers/net/wireless/ralink/rt2x00/rt2500usb.c: In function 'rt2500usb_set_device_state':
+drivers/net/wireless/ralink/rt2x00/rt2500usb.c:1074:1: error: the frame size of 3032 bytes is larger than 100 bytes [-Werror=frame-larger-than=]
+
+If we don't force those functions to be inline, the compiler can figure this
+out better itself and not inline the functions when doing so would be harmful,
+reducing the stack size to a merge 256 bytes.
+
+Note that there is another problem that manifests in this driver, as a result
+of the typecheck() macro causing even larger stack frames.
+
+Signed-off-by: Arnd Bergmann <arnd@arndb.de>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2500usb.c | 19 +++++--------------
+ 1 file changed, 5 insertions(+), 14 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2500usb.c b/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
+index 62357465fe29..0d2670a56c4c 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
+@@ -55,7 +55,7 @@ MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
+  * If the csr_mutex is already held then the _lock variants must
+  * be used instead.
+  */
+-static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
++static void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
+ 					   const unsigned int offset,
+ 					   u16 *value)
+ {
+@@ -66,7 +66,7 @@ static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
+ 	*value = le16_to_cpu(reg);
+ }
+ 
+-static inline void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
++static void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
+ 						const unsigned int offset,
+ 						u16 *value)
+ {
+@@ -77,16 +77,7 @@ static inline void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
+ 	*value = le16_to_cpu(reg);
+ }
+ 
+-static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
+-						const unsigned int offset,
+-						void *value, const u16 length)
+-{
+-	rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
+-				      USB_VENDOR_REQUEST_IN, offset,
+-				      value, length);
+-}
+-
+-static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
++static void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
+ 					    const unsigned int offset,
+ 					    u16 value)
+ {
+@@ -96,7 +87,7 @@ static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
+ 				      &reg, sizeof(reg));
+ }
+ 
+-static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
++static void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
+ 						 const unsigned int offset,
+ 						 u16 value)
+ {
+@@ -106,7 +97,7 @@ static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
+ 				       &reg, sizeof(reg), REGISTER_TIMEOUT);
+ }
+ 
+-static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
++static void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
+ 						 const unsigned int offset,
+ 						 void *value, const u16 length)
+ {
+-- 
+2.12.1
+

+ 94 - 0
package/kernel/mac80211/patches/020-08-rt2x00-rt2800lib-move-rt2800_drv_data-declaration-in.patch

@@ -0,0 +1,94 @@
+From 96609f366c6f792421e1939c5c834abbe24eb88a Mon Sep 17 00:00:00 2001
+From: Gabor Juhos <juhosg@openwrt.org>
+Date: Wed, 15 Feb 2017 10:25:04 +0100
+Subject: [PATCH 08/19] rt2x00: rt2800lib: move rt2800_drv_data declaration
+ into rt2800lib.h
+
+The rt2800_drv_data structure contains driver specific
+information. Move the declaration into the rt2800lib.h
+header which is a more logical place for it. Also fix
+the comment style to avoid checkpatch warning.
+
+The patch contains no functional changes, it is in
+preparation for the next patch.
+
+Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800.h    | 25 -------------------------
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.h | 23 +++++++++++++++++++++++
+ 2 files changed, 23 insertions(+), 25 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800.h b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+index 256496bfbafb..0e7051d8132f 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+@@ -2987,29 +2987,4 @@ enum rt2800_eeprom_word {
+  */
+ #define BCN_TBTT_OFFSET 64
+ 
+-/*
+- * Hardware has 255 WCID table entries. First 32 entries are reserved for
+- * shared keys. Since parts of the pairwise key table might be shared with
+- * the beacon frame buffers 6 & 7 we could only use the first 222 entries.
+- */
+-#define WCID_START	33
+-#define WCID_END	222
+-#define STA_IDS_SIZE	(WCID_END - WCID_START + 2)
+-
+-/*
+- * RT2800 driver data structure
+- */
+-struct rt2800_drv_data {
+-	u8 calibration_bw20;
+-	u8 calibration_bw40;
+-	u8 bbp25;
+-	u8 bbp26;
+-	u8 txmixer_gain_24g;
+-	u8 txmixer_gain_5g;
+-	u8 max_psdu;
+-	unsigned int tbtt_tick;
+-	unsigned int ampdu_factor_cnt[4];
+-	DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
+-};
+-
+ #endif /* RT2800_H */
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+index 0a8b4df665fe..8e1ae138c3f1 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+@@ -20,6 +20,29 @@
+ #ifndef RT2800LIB_H
+ #define RT2800LIB_H
+ 
++/*
++ * Hardware has 255 WCID table entries. First 32 entries are reserved for
++ * shared keys. Since parts of the pairwise key table might be shared with
++ * the beacon frame buffers 6 & 7 we could only use the first 222 entries.
++ */
++#define WCID_START	33
++#define WCID_END	222
++#define STA_IDS_SIZE	(WCID_END - WCID_START + 2)
++
++/* RT2800 driver data structure */
++struct rt2800_drv_data {
++	u8 calibration_bw20;
++	u8 calibration_bw40;
++	u8 bbp25;
++	u8 bbp26;
++	u8 txmixer_gain_24g;
++	u8 txmixer_gain_5g;
++	u8 max_psdu;
++	unsigned int tbtt_tick;
++	unsigned int ampdu_factor_cnt[4];
++	DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
++};
++
+ struct rt2800_ops {
+ 	void (*register_read)(struct rt2x00_dev *rt2x00dev,
+ 			      const unsigned int offset, u32 *value);
+-- 
+2.12.1
+

+ 94 - 0
package/kernel/mac80211/patches/020-09-rt2800-identify-station-based-on-status-WCID.patch

@@ -0,0 +1,94 @@
+From a13d985f26f6df07d5c5c0e190477628e236babc Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:05 +0100
+Subject: [PATCH 09/19] rt2800: identify station based on status WCID
+
+Add framework to identify sta based on tx status WCID. This is currently
+not used, will start be utilized in the future patch.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c   | 5 +++++
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.h   | 1 +
+ drivers/net/wireless/ralink/rt2x00/rt2x00queue.h | 3 ++-
+ 3 files changed, 8 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 8223a1520316..46405cce35e0 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -855,11 +855,13 @@ EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
+ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
+ {
+ 	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
++	struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
+ 	struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
+ 	struct txdone_entry_desc txdesc;
+ 	u32 word;
+ 	u16 mcs, real_mcs;
+ 	int aggr, ampdu;
++	int wcid;
+ 
+ 	/*
+ 	 * Obtain the status about this packet.
+@@ -872,6 +874,7 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
+ 
+ 	real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
+ 	aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE);
++	wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
+ 
+ 	/*
+ 	 * If a frame was meant to be sent as a single non-aggregated MPDU
+@@ -1468,6 +1471,7 @@ int rt2800_sta_add(struct rt2x00_dev *rt2x00dev, struct ieee80211_vif *vif,
+ 		return 0;
+ 
+ 	__set_bit(wcid - WCID_START, drv_data->sta_ids);
++	drv_data->wcid_to_sta[wcid - WCID_START] = sta;
+ 
+ 	/*
+ 	 * Clean up WCID attributes and write STA address to the device.
+@@ -1498,6 +1502,7 @@ int rt2800_sta_remove(struct rt2x00_dev *rt2x00dev, struct ieee80211_sta *sta)
+ 	 * get renewed when the WCID is reused.
+ 	 */
+ 	rt2800_config_wcid(rt2x00dev, NULL, wcid);
++	drv_data->wcid_to_sta[wcid - WCID_START] = NULL;
+ 	__clear_bit(wcid - WCID_START, drv_data->sta_ids);
+ 
+ 	return 0;
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+index 8e1ae138c3f1..6811d677a6e7 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+@@ -41,6 +41,7 @@ struct rt2800_drv_data {
+ 	unsigned int tbtt_tick;
+ 	unsigned int ampdu_factor_cnt[4];
+ 	DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
++	struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
+ };
+ 
+ struct rt2800_ops {
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
+index 22d18818e850..9b297fce4692 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
+@@ -102,7 +102,7 @@ enum skb_frame_desc_flags {
+  *	of the scope of the skb->data pointer.
+  * @iv: IV/EIV data used during encryption/decryption.
+  * @skb_dma: (PCI-only) the DMA address associated with the sk buffer.
+- * @entry: The entry to which this sk buffer belongs.
++ * @sta: The station where sk buffer was sent.
+  */
+ struct skb_frame_desc {
+ 	u8 flags;
+@@ -116,6 +116,7 @@ struct skb_frame_desc {
+ 	__le32 iv[2];
+ 
+ 	dma_addr_t skb_dma;
++	struct ieee80211_sta *sta;
+ };
+ 
+ /**
+-- 
+2.12.1
+

+ 178 - 0
package/kernel/mac80211/patches/020-10-rt2x00-separte-filling-tx-status-from-rt2x00lib_txdo.patch

@@ -0,0 +1,178 @@
+From 5edb05afebba8f488a30db29550e55c42eea6d6a Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:06 +0100
+Subject: [PATCH 10/19] rt2x00: separte filling tx status from rt2x00lib_txdone
+
+This makes rt2x00lib_txdone a bit simpler and will allow to reuse code
+in different variant of txdone which I'm preparing.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 141 +++++++++++++------------
+ 1 file changed, 76 insertions(+), 65 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+index dd6678109b7e..b5d90fefc96b 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+@@ -313,73 +313,14 @@ static inline int rt2x00lib_txdone_bar_status(struct queue_entry *entry)
+ 	return ret;
+ }
+ 
+-void rt2x00lib_txdone(struct queue_entry *entry,
+-		      struct txdone_entry_desc *txdesc)
++static void rt2x00lib_fill_tx_status(struct rt2x00_dev *rt2x00dev,
++				     struct ieee80211_tx_info *tx_info,
++				     struct skb_frame_desc *skbdesc,
++				     struct txdone_entry_desc *txdesc,
++				     bool success)
+ {
+-	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
+-	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
+-	struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
+-	unsigned int header_length, i;
+ 	u8 rate_idx, rate_flags, retry_rates;
+-	u8 skbdesc_flags = skbdesc->flags;
+-	bool success;
+-
+-	/*
+-	 * Unmap the skb.
+-	 */
+-	rt2x00queue_unmap_skb(entry);
+-
+-	/*
+-	 * Remove the extra tx headroom from the skb.
+-	 */
+-	skb_pull(entry->skb, rt2x00dev->extra_tx_headroom);
+-
+-	/*
+-	 * Signal that the TX descriptor is no longer in the skb.
+-	 */
+-	skbdesc->flags &= ~SKBDESC_DESC_IN_SKB;
+-
+-	/*
+-	 * Determine the length of 802.11 header.
+-	 */
+-	header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
+-
+-	/*
+-	 * Remove L2 padding which was added during
+-	 */
+-	if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_L2PAD))
+-		rt2x00queue_remove_l2pad(entry->skb, header_length);
+-
+-	/*
+-	 * If the IV/EIV data was stripped from the frame before it was
+-	 * passed to the hardware, we should now reinsert it again because
+-	 * mac80211 will expect the same data to be present it the
+-	 * frame as it was passed to us.
+-	 */
+-	if (rt2x00_has_cap_hw_crypto(rt2x00dev))
+-		rt2x00crypto_tx_insert_iv(entry->skb, header_length);
+-
+-	/*
+-	 * Send frame to debugfs immediately, after this call is completed
+-	 * we are going to overwrite the skb->cb array.
+-	 */
+-	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry);
+-
+-	/*
+-	 * Determine if the frame has been successfully transmitted and
+-	 * remove BARs from our check list while checking for their
+-	 * TX status.
+-	 */
+-	success =
+-	    rt2x00lib_txdone_bar_status(entry) ||
+-	    test_bit(TXDONE_SUCCESS, &txdesc->flags) ||
+-	    test_bit(TXDONE_UNKNOWN, &txdesc->flags);
+-
+-	/*
+-	 * Update TX statistics.
+-	 */
+-	rt2x00dev->link.qual.tx_success += success;
+-	rt2x00dev->link.qual.tx_failed += !success;
++	int i;
+ 
+ 	rate_idx = skbdesc->tx_rate_idx;
+ 	rate_flags = skbdesc->tx_rate_flags;
+@@ -448,6 +389,76 @@ void rt2x00lib_txdone(struct queue_entry *entry,
+ 		else
+ 			rt2x00dev->low_level_stats.dot11RTSFailureCount++;
+ 	}
++}
++
++void rt2x00lib_txdone(struct queue_entry *entry,
++		      struct txdone_entry_desc *txdesc)
++{
++	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
++	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
++	struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
++	u8 skbdesc_flags = skbdesc->flags;
++	unsigned int header_length;
++	bool success;
++
++	/*
++	 * Unmap the skb.
++	 */
++	rt2x00queue_unmap_skb(entry);
++
++	/*
++	 * Remove the extra tx headroom from the skb.
++	 */
++	skb_pull(entry->skb, rt2x00dev->extra_tx_headroom);
++
++	/*
++	 * Signal that the TX descriptor is no longer in the skb.
++	 */
++	skbdesc->flags &= ~SKBDESC_DESC_IN_SKB;
++
++	/*
++	 * Determine the length of 802.11 header.
++	 */
++	header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
++
++	/*
++	 * Remove L2 padding which was added during
++	 */
++	if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_L2PAD))
++		rt2x00queue_remove_l2pad(entry->skb, header_length);
++
++	/*
++	 * If the IV/EIV data was stripped from the frame before it was
++	 * passed to the hardware, we should now reinsert it again because
++	 * mac80211 will expect the same data to be present it the
++	 * frame as it was passed to us.
++	 */
++	if (rt2x00_has_cap_hw_crypto(rt2x00dev))
++		rt2x00crypto_tx_insert_iv(entry->skb, header_length);
++
++	/*
++	 * Send frame to debugfs immediately, after this call is completed
++	 * we are going to overwrite the skb->cb array.
++	 */
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry);
++
++	/*
++	 * Determine if the frame has been successfully transmitted and
++	 * remove BARs from our check list while checking for their
++	 * TX status.
++	 */
++	success =
++	    rt2x00lib_txdone_bar_status(entry) ||
++	    test_bit(TXDONE_SUCCESS, &txdesc->flags) ||
++	    test_bit(TXDONE_UNKNOWN, &txdesc->flags);
++
++	/*
++	 * Update TX statistics.
++	 */
++	rt2x00dev->link.qual.tx_success += success;
++	rt2x00dev->link.qual.tx_failed += !success;
++
++	rt2x00lib_fill_tx_status(rt2x00dev, tx_info, skbdesc, txdesc, success);
+ 
+ 	/*
+ 	 * Only send the status report to mac80211 when it's a frame
+-- 
+2.12.1
+

+ 88 - 0
package/kernel/mac80211/patches/020-11-rt2x00-separte-clearing-entry-from-rt2x00lib_txdone.patch

@@ -0,0 +1,88 @@
+From 56646adf9cd60b488ddc5633a2d9aa1f30efa5db Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:07 +0100
+Subject: [PATCH 11/19] rt2x00: separte clearing entry from rt2x00lib_txdone
+
+This makes rt2x00lib_txdone a bit simpler and will allow to reuse
+code in different variant of txdone which I'm preparing.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 51 +++++++++++++++-----------
+ 1 file changed, 29 insertions(+), 22 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+index b5d90fefc96b..03b368ac9cb6 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+@@ -391,6 +391,32 @@ static void rt2x00lib_fill_tx_status(struct rt2x00_dev *rt2x00dev,
+ 	}
+ }
+ 
++static void rt2x00lib_clear_entry(struct rt2x00_dev *rt2x00dev,
++				  struct queue_entry *entry)
++{
++	/*
++	 * Make this entry available for reuse.
++	 */
++	entry->skb = NULL;
++	entry->flags = 0;
++
++	rt2x00dev->ops->lib->clear_entry(entry);
++
++	rt2x00queue_index_inc(entry, Q_INDEX_DONE);
++
++	/*
++	 * If the data queue was below the threshold before the txdone
++	 * handler we must make sure the packet queue in the mac80211 stack
++	 * is reenabled when the txdone handler has finished. This has to be
++	 * serialized with rt2x00mac_tx(), otherwise we can wake up queue
++	 * before it was stopped.
++	 */
++	spin_lock_bh(&entry->queue->tx_lock);
++	if (!rt2x00queue_threshold(entry->queue))
++		rt2x00queue_unpause_queue(entry->queue);
++	spin_unlock_bh(&entry->queue->tx_lock);
++}
++
+ void rt2x00lib_txdone(struct queue_entry *entry,
+ 		      struct txdone_entry_desc *txdesc)
+ {
+@@ -471,30 +497,11 @@ void rt2x00lib_txdone(struct queue_entry *entry,
+ 			ieee80211_tx_status(rt2x00dev->hw, entry->skb);
+ 		else
+ 			ieee80211_tx_status_ni(rt2x00dev->hw, entry->skb);
+-	} else
++	} else {
+ 		dev_kfree_skb_any(entry->skb);
++	}
+ 
+-	/*
+-	 * Make this entry available for reuse.
+-	 */
+-	entry->skb = NULL;
+-	entry->flags = 0;
+-
+-	rt2x00dev->ops->lib->clear_entry(entry);
+-
+-	rt2x00queue_index_inc(entry, Q_INDEX_DONE);
+-
+-	/*
+-	 * If the data queue was below the threshold before the txdone
+-	 * handler we must make sure the packet queue in the mac80211 stack
+-	 * is reenabled when the txdone handler has finished. This has to be
+-	 * serialized with rt2x00mac_tx(), otherwise we can wake up queue
+-	 * before it was stopped.
+-	 */
+-	spin_lock_bh(&entry->queue->tx_lock);
+-	if (!rt2x00queue_threshold(entry->queue))
+-		rt2x00queue_unpause_queue(entry->queue);
+-	spin_unlock_bh(&entry->queue->tx_lock);
++	rt2x00lib_clear_entry(rt2x00dev, entry);
+ }
+ EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
+ 
+-- 
+2.12.1
+

+ 92 - 0
package/kernel/mac80211/patches/020-12-rt2x00-add-txdone-nomatch-function.patch

@@ -0,0 +1,92 @@
+From a09305d052166cb489402a63a5d275e954e0b923 Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:08 +0100
+Subject: [PATCH 12/19] rt2x00: add txdone nomatch function
+
+This txdone nomatch function will be used when we get status from the HW,
+but we could not match it with any sent skb.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00.h    |  2 ++
+ drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 50 ++++++++++++++++++++++++++
+ 2 files changed, 52 insertions(+)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+index 340787894c69..91ba10fdf732 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+@@ -1425,6 +1425,8 @@ void rt2x00lib_dmastart(struct queue_entry *entry);
+ void rt2x00lib_dmadone(struct queue_entry *entry);
+ void rt2x00lib_txdone(struct queue_entry *entry,
+ 		      struct txdone_entry_desc *txdesc);
++void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
++			      struct txdone_entry_desc *txdesc);
+ void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
+ void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp);
+ 
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+index 03b368ac9cb6..90fc259fb5bc 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+@@ -417,6 +417,56 @@ static void rt2x00lib_clear_entry(struct rt2x00_dev *rt2x00dev,
+ 	spin_unlock_bh(&entry->queue->tx_lock);
+ }
+ 
++void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
++			      struct txdone_entry_desc *txdesc)
++{
++	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
++	struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
++	struct ieee80211_tx_info txinfo = {};
++	bool success;
++
++	/*
++	 * Unmap the skb.
++	 */
++	rt2x00queue_unmap_skb(entry);
++
++	/*
++	 * Signal that the TX descriptor is no longer in the skb.
++	 */
++	skbdesc->flags &= ~SKBDESC_DESC_IN_SKB;
++
++	/*
++	 * Send frame to debugfs immediately, after this call is completed
++	 * we are going to overwrite the skb->cb array.
++	 */
++	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry);
++
++	/*
++	 * Determine if the frame has been successfully transmitted and
++	 * remove BARs from our check list while checking for their
++	 * TX status.
++	 */
++	success =
++	    rt2x00lib_txdone_bar_status(entry) ||
++	    test_bit(TXDONE_SUCCESS, &txdesc->flags);
++
++	if (!test_bit(TXDONE_UNKNOWN, &txdesc->flags)) {
++		/*
++		 * Update TX statistics.
++		 */
++		rt2x00dev->link.qual.tx_success += success;
++		rt2x00dev->link.qual.tx_failed += !success;
++
++		rt2x00lib_fill_tx_status(rt2x00dev, &txinfo, skbdesc, txdesc,
++					 success);
++		ieee80211_tx_status_noskb(rt2x00dev->hw, skbdesc->sta, &txinfo);
++	}
++
++	dev_kfree_skb_any(entry->skb);
++	rt2x00lib_clear_entry(rt2x00dev, entry);
++}
++EXPORT_SYMBOL_GPL(rt2x00lib_txdone_nomatch);
++
+ void rt2x00lib_txdone(struct queue_entry *entry,
+ 		      struct txdone_entry_desc *txdesc)
+ {
+-- 
+2.12.1
+

+ 54 - 0
package/kernel/mac80211/patches/020-13-rt2x00-fixup-fill_tx_status-for-nomatch-case.patch

@@ -0,0 +1,54 @@
+From ec80ad70d778af7665992672896633ebd3b02ac8 Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:09 +0100
+Subject: [PATCH 13/19] rt2x00: fixup fill_tx_status for nomatch case
+
+Add bits rt2x00lib_fill_tx_status() when filling status in nomatch
+case and hopefully do not break the function for existing cases.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00dev.c   | 6 +++++-
+ drivers/net/wireless/ralink/rt2x00/rt2x00queue.h | 1 +
+ 2 files changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+index 90fc259fb5bc..e95d2aad3b3f 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+@@ -357,6 +357,9 @@ static void rt2x00lib_fill_tx_status(struct rt2x00_dev *rt2x00dev,
+ 	if (i < (IEEE80211_TX_MAX_RATES - 1))
+ 		tx_info->status.rates[i].idx = -1; /* terminate */
+ 
++	if (test_bit(TXDONE_NO_ACK_REQ, &txdesc->flags))
++		tx_info->flags |= IEEE80211_TX_CTL_NO_ACK;
++
+ 	if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {
+ 		if (success)
+ 			tx_info->flags |= IEEE80211_TX_STAT_ACK;
+@@ -375,7 +378,8 @@ static void rt2x00lib_fill_tx_status(struct rt2x00_dev *rt2x00dev,
+ 	 */
+ 	if (test_bit(TXDONE_AMPDU, &txdesc->flags) ||
+ 	    tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
+-		tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
++		tx_info->flags |= IEEE80211_TX_STAT_AMPDU |
++				  IEEE80211_TX_CTL_AMPDU;
+ 		tx_info->status.ampdu_len = 1;
+ 		tx_info->status.ampdu_ack_len = success ? 1 : 0;
+ 
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
+index 9b297fce4692..c78fb8c8838a 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
+@@ -215,6 +215,7 @@ enum txdone_entry_desc_flags {
+ 	TXDONE_FAILURE,
+ 	TXDONE_EXCESSIVE_RETRY,
+ 	TXDONE_AMPDU,
++	TXDONE_NO_ACK_REQ,
+ };
+ 
+ /**
+-- 
+2.12.1
+

+ 191 - 0
package/kernel/mac80211/patches/020-14-rt2x00-use-txdone_nomatch-on-rt2800usb.patch

@@ -0,0 +1,191 @@
+From 293dff78ee058ec1e0b90e05a803c512b6a2097f Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:10 +0100
+Subject: [PATCH 14/19] rt2x00: use txdone_nomatch on rt2800usb
+
+If we do not match skb entry, provide tx status via nomatch procedure.
+
+Currently in that case we do rt2x00lib_txdone_noinfo(TXDONE_NOINFO),
+which actually assume that entry->skb was posted without retries and
+provide rate saved in skb desc as successful. Patch changed that to
+rate read from TX_STAT_FIFO, however still do not provide correct
+number of retries.
+
+On SoC/PCI devices we keep providing status via standard txdone
+procedure, no change in those devices, though we should thing about it.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c  | 31 ++++++++++++++++++++-----
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.h  |  3 ++-
+ drivers/net/wireless/ralink/rt2x00/rt2800mmio.c |  2 +-
+ drivers/net/wireless/ralink/rt2x00/rt2800usb.c  | 18 ++++++--------
+ 4 files changed, 35 insertions(+), 19 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 46405cce35e0..4a7bec708a13 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -852,7 +852,8 @@ void rt2800_process_rxwi(struct queue_entry *entry,
+ }
+ EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
+ 
+-void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
++void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
++			 bool match)
+ {
+ 	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
+ 	struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
+@@ -860,8 +861,7 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
+ 	struct txdone_entry_desc txdesc;
+ 	u32 word;
+ 	u16 mcs, real_mcs;
+-	int aggr, ampdu;
+-	int wcid;
++	int aggr, ampdu, wcid, ack_req;
+ 
+ 	/*
+ 	 * Obtain the status about this packet.
+@@ -875,6 +875,7 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
+ 	real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
+ 	aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE);
+ 	wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
++	ack_req	= rt2x00_get_field32(status, TX_STA_FIFO_TX_ACK_REQUIRED);
+ 
+ 	/*
+ 	 * If a frame was meant to be sent as a single non-aggregated MPDU
+@@ -891,8 +892,12 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
+ 	 * Hence, replace the requested rate with the real tx rate to not
+ 	 * confuse the rate control algortihm by providing clearly wrong
+ 	 * data.
+-	 */
+-	if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) {
++	 *
++	 * FIXME: if we do not find matching entry, we tell that frame was
++	 * posted without any retries. We need to find a way to fix that
++	 * and provide retry count.
++ 	 */
++	if (unlikely((aggr == 1 && ampdu == 0 && real_mcs != mcs)) || !match) {
+ 		skbdesc->tx_rate_idx = real_mcs;
+ 		mcs = real_mcs;
+ 	}
+@@ -900,6 +905,9 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
+ 	if (aggr == 1 || ampdu == 1)
+ 		__set_bit(TXDONE_AMPDU, &txdesc.flags);
+ 
++	if (!ack_req)
++		__set_bit(TXDONE_NO_ACK_REQ, &txdesc.flags);
++
+ 	/*
+ 	 * Ralink has a retry mechanism using a global fallback
+ 	 * table. We setup this fallback table to try the immediate
+@@ -931,7 +939,18 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
+ 	if (txdesc.retry)
+ 		__set_bit(TXDONE_FALLBACK, &txdesc.flags);
+ 
+-	rt2x00lib_txdone(entry, &txdesc);
++	if (!match) {
++		/* RCU assures non-null sta will not be freed by mac80211. */
++		rcu_read_lock();
++		if (likely(wcid >= WCID_START && wcid <= WCID_END))
++			skbdesc->sta = drv_data->wcid_to_sta[wcid - WCID_START];
++		else
++			skbdesc->sta = NULL;
++		rt2x00lib_txdone_nomatch(entry, &txdesc);
++		rcu_read_unlock();
++	} else {
++		rt2x00lib_txdone(entry, &txdesc);
++	}
+ }
+ EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
+ 
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+index 6811d677a6e7..d9ef260d542a 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+@@ -191,7 +191,8 @@ void rt2800_write_tx_data(struct queue_entry *entry,
+ 			  struct txentry_desc *txdesc);
+ void rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *txdesc);
+ 
+-void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32* txwi);
++void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
++			 bool match);
+ 
+ void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
+ void rt2800_clear_beacon(struct queue_entry *entry);
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
+index de4790b41be7..3ab3b5323897 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800mmio.c
+@@ -239,7 +239,7 @@ static bool rt2800mmio_txdone_release_entries(struct queue_entry *entry,
+ {
+ 	if (test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
+ 		rt2800_txdone_entry(entry, entry->status,
+-				    rt2800mmio_get_txwi(entry));
++				    rt2800mmio_get_txwi(entry), true);
+ 		return false;
+ 	}
+ 
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
+index 205a7b8ac8a7..f11e3f532a84 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
+@@ -501,8 +501,7 @@ static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
+ /*
+  * TX control handlers
+  */
+-static enum txdone_entry_desc_flags
+-rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
++static bool rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
+ {
+ 	__le32 *txwi;
+ 	u32 word;
+@@ -515,7 +514,7 @@ rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
+ 	 * frame.
+ 	 */
+ 	if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
+-		return TXDONE_FAILURE;
++		return false;
+ 
+ 	wcid	= rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
+ 	ack	= rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
+@@ -537,10 +536,10 @@ rt2800usb_txdone_entry_check(struct queue_entry *entry, u32 reg)
+ 		rt2x00_dbg(entry->queue->rt2x00dev,
+ 			   "TX status report missed for queue %d entry %d\n",
+ 			   entry->queue->qid, entry->entry_idx);
+-		return TXDONE_UNKNOWN;
++		return false;
+ 	}
+ 
+-	return TXDONE_SUCCESS;
++	return true;
+ }
+ 
+ static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
+@@ -549,7 +548,7 @@ static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
+ 	struct queue_entry *entry;
+ 	u32 reg;
+ 	u8 qid;
+-	enum txdone_entry_desc_flags done_status;
++	bool match;
+ 
+ 	while (kfifo_get(&rt2x00dev->txstatus_fifo, &reg)) {
+ 		/*
+@@ -574,11 +573,8 @@ static void rt2800usb_txdone(struct rt2x00_dev *rt2x00dev)
+ 			break;
+ 		}
+ 
+-		done_status = rt2800usb_txdone_entry_check(entry, reg);
+-		if (likely(done_status == TXDONE_SUCCESS))
+-			rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry));
+-		else
+-			rt2x00lib_txdone_noinfo(entry, done_status);
++		match = rt2800usb_txdone_entry_check(entry, reg);
++		rt2800_txdone_entry(entry, reg, rt2800usb_get_txwi(entry), match);
+ 	}
+ }
+ 
+-- 
+2.12.1
+

+ 88 - 0
package/kernel/mac80211/patches/020-15-rt2800-status-based-rate-flags-for-nomatch-case.patch

@@ -0,0 +1,88 @@
+From 9d7a7a4d2b02bcd30fb5fe4270278212353cc332 Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:11 +0100
+Subject: [PATCH 15/19] rt2800: status based rate flags for nomatch case
+
+We use skb_desc->tx_rate_flags from entry as rate[].flags even if
+skb does not match status. Patch corrects flags and also fixes
+mcs for legacy rates.
+
+rt2800_rate_from_status() is based on Felix's mt76
+mt76x2_mac_process_tx_rate() function.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800.h    |  2 ++
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 35 +++++++++++++++++++++++++-
+ 2 files changed, 36 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800.h b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+index 0e7051d8132f..480b08601785 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+@@ -1760,6 +1760,8 @@
+ #define TX_STA_FIFO_WCID		FIELD32(0x0000ff00)
+ #define TX_STA_FIFO_SUCCESS_RATE	FIELD32(0xffff0000)
+ #define TX_STA_FIFO_MCS			FIELD32(0x007f0000)
++#define TX_STA_FIFO_BW			FIELD32(0x00800000)
++#define TX_STA_FIFO_SGI			FIELD32(0x01000000)
+ #define TX_STA_FIFO_PHYMODE		FIELD32(0xc0000000)
+ 
+ /*
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 4a7bec708a13..8d00c599e47a 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -852,6 +852,39 @@ void rt2800_process_rxwi(struct queue_entry *entry,
+ }
+ EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
+ 
++static void rt2800_rate_from_status(struct skb_frame_desc *skbdesc,
++				    u32 status, enum nl80211_band band)
++{
++	u8 flags = 0;
++	u8 idx = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
++
++	switch (rt2x00_get_field32(status, TX_STA_FIFO_PHYMODE)) {
++	case RATE_MODE_HT_GREENFIELD:
++		flags |= IEEE80211_TX_RC_GREEN_FIELD;
++		/* fall through */
++	case RATE_MODE_HT_MIX:
++		flags |= IEEE80211_TX_RC_MCS;
++		break;
++	case RATE_MODE_OFDM:
++		if (band == NL80211_BAND_2GHZ)
++			idx += 4;
++		break;
++	case RATE_MODE_CCK:
++		if (idx >= 8)
++			idx -= 8;
++		break;
++	}
++
++	if (rt2x00_get_field32(status, TX_STA_FIFO_BW))
++		flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
++
++	if (rt2x00_get_field32(status, TX_STA_FIFO_SGI))
++		flags |= IEEE80211_TX_RC_SHORT_GI;
++
++	skbdesc->tx_rate_idx = idx;
++	skbdesc->tx_rate_flags = flags;
++}
++
+ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
+ 			 bool match)
+ {
+@@ -898,7 +931,7 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
+ 	 * and provide retry count.
+  	 */
+ 	if (unlikely((aggr == 1 && ampdu == 0 && real_mcs != mcs)) || !match) {
+-		skbdesc->tx_rate_idx = real_mcs;
++		rt2800_rate_from_status(skbdesc, status, rt2x00dev->curr_band);
+ 		mcs = real_mcs;
+ 	}
+ 
+-- 
+2.12.1
+

+ 43 - 0
package/kernel/mac80211/patches/020-16-rt2800-use-TXOP_BACKOFF-for-probe-frames.patch

@@ -0,0 +1,43 @@
+From fb47ada8dc3c30c8e7b415da155742b49536c61e Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:12 +0100
+Subject: [PATCH 16/19] rt2800: use TXOP_BACKOFF for probe frames
+
+Even if we do not set AMPDU bit in TXWI, device still can aggregate
+frame and send it with rate not corresponding to requested. That mean
+we can do not sent probe frames with requested rate. To prevent that
+use TXOP_BACKOFF for probe frames.
+
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00queue.c | 7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+index e1660b92b20c..a2c1ca5c76d1 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+@@ -372,15 +372,16 @@ static void rt2x00queue_create_tx_descriptor_ht(struct rt2x00_dev *rt2x00dev,
+ 
+ 	/*
+ 	 * Determine IFS values
+-	 * - Use TXOP_BACKOFF for management frames except beacons
++	 * - Use TXOP_BACKOFF for probe and management frames except beacons
+ 	 * - Use TXOP_SIFS for fragment bursts
+ 	 * - Use TXOP_HTTXOP for everything else
+ 	 *
+ 	 * Note: rt2800 devices won't use CTS protection (if used)
+ 	 * for frames not transmitted with TXOP_HTTXOP
+ 	 */
+-	if (ieee80211_is_mgmt(hdr->frame_control) &&
+-	    !ieee80211_is_beacon(hdr->frame_control))
++	if ((ieee80211_is_mgmt(hdr->frame_control) &&
++	     !ieee80211_is_beacon(hdr->frame_control)) ||
++	    (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE))
+ 		txdesc->u.ht.txop = TXOP_BACKOFF;
+ 	else if (!(tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT))
+ 		txdesc->u.ht.txop = TXOP_SIFS;
+-- 
+2.12.1
+

+ 28 - 0
package/kernel/mac80211/patches/020-17-rt2x00-fix-rt2x00debug_dump_frame-comment.patch

@@ -0,0 +1,28 @@
+From dd35cc0896faff5ed9d22eac9ea4a1920e2eec0c Mon Sep 17 00:00:00 2001
+From: Stanislaw Gruszka <sgruszka@redhat.com>
+Date: Wed, 15 Feb 2017 10:25:13 +0100
+Subject: [PATCH 17/19] rt2x00: fix rt2x00debug_dump_frame comment
+
+Reported-by: Jeroen Roovers <jer@airfi.aero>
+Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2x00.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+index 91ba10fdf732..ce340bfd71a0 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+@@ -1396,7 +1396,7 @@ void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
+  * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
+  * @rt2x00dev: Pointer to &struct rt2x00_dev.
+  * @type: The type of frame that is being dumped.
+- * @skb: The skb containing the frame to be dumped.
++ * @entry: The queue entry containing the frame to be dumped.
+  */
+ #ifdef CPTCFG_RT2X00_LIB_DEBUGFS
+ void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
+-- 
+2.12.1
+

+ 37 - 0
package/kernel/mac80211/patches/020-18-rt2x00-fix-TX_PWR_CFG_4-register-definition.patch

@@ -0,0 +1,37 @@
+From 5ce33b603063f36272fcfb1b4a5fde69f46eca88 Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Thu, 9 Mar 2017 00:54:22 +0100
+Subject: [PATCH 18/19] rt2x00: fix TX_PWR_CFG_4 register definition
+
+Some of the macros used to describe the TX_PWR_CFG_4 register accidentally
+refer to TX_PWR_CFG_3, probably a copy&paste error. Fix that.
+
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800.h | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800.h b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+index 480b08601785..fd1dbd956bad 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+@@ -1171,10 +1171,10 @@
+ #define TX_PWR_CFG_4_UKNOWN7		FIELD32(0x00000f00)
+ #define TX_PWR_CFG_4_UKNOWN8		FIELD32(0x0000f000)
+ /* bits for 3T devices */
+-#define TX_PWR_CFG_3_STBC4_CH0		FIELD32(0x0000000f)
+-#define TX_PWR_CFG_3_STBC4_CH1		FIELD32(0x000000f0)
+-#define TX_PWR_CFG_3_STBC6_CH0		FIELD32(0x00000f00)
+-#define TX_PWR_CFG_3_STBC6_CH1		FIELD32(0x0000f000)
++#define TX_PWR_CFG_4_STBC4_CH0		FIELD32(0x0000000f)
++#define TX_PWR_CFG_4_STBC4_CH1		FIELD32(0x000000f0)
++#define TX_PWR_CFG_4_STBC6_CH0		FIELD32(0x00000f00)
++#define TX_PWR_CFG_4_STBC6_CH1		FIELD32(0x0000f000)
+ 
+ /*
+  * TX_PIN_CFG:
+-- 
+2.12.1
+

+ 2077 - 0
package/kernel/mac80211/patches/020-19-rt2x00-add-support-for-MT7620.patch

@@ -0,0 +1,2077 @@
+From 41977e86c984fcdddb454a3d7887de5d47b5f530 Mon Sep 17 00:00:00 2001
+From: Roman Yeryomin <roman@advem.lv>
+Date: Tue, 21 Mar 2017 00:43:00 +0100
+Subject: [PATCH 19/19] rt2x00: add support for MT7620
+
+Basic support for MT7620 built-in wireless radio was added to
+OpenWrt in r41441. It has seen some heavy cleaning and refactoring
+since in order to match the Kernel's code quality standards.
+
+Signed-off-by: Roman Yeryomin <roman@advem.lv>
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/ralink/rt2x00/Kconfig     |    2 +-
+ drivers/net/wireless/ralink/rt2x00/rt2800.h    |  177 +++
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 1421 +++++++++++++++++++++++-
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.h |    4 +
+ drivers/net/wireless/ralink/rt2x00/rt2x00.h    |    1 +
+ 5 files changed, 1578 insertions(+), 27 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/Kconfig b/drivers/net/wireless/ralink/rt2x00/Kconfig
+index de62f5dcb62f..a1d1cfe214d2 100644
+--- a/drivers/net/wireless/ralink/rt2x00/Kconfig
++++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
+@@ -210,7 +210,7 @@ endif
+ config RT2800SOC
+ 	tristate "Ralink WiSoC support"
+ 	depends on m
+-	depends on SOC_RT288X || SOC_RT305X
++	depends on SOC_RT288X || SOC_RT305X || SOC_MT7620
+ 	select RT2X00_LIB_SOC
+ 	select RT2X00_LIB_MMIO
+ 	select RT2X00_LIB_CRYPTO
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800.h b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+index fd1dbd956bad..6a8c93fb6a43 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800.h
+@@ -79,6 +79,7 @@
+ #define RF5372				0x5372
+ #define RF5390				0x5390
+ #define RF5392				0x5392
++#define RF7620				0x7620
+ 
+ /*
+  * Chipset revisions.
+@@ -639,6 +640,24 @@
+ #define RF_CSR_CFG_BUSY			FIELD32(0x00020000)
+ 
+ /*
++ * MT7620 RF registers (reversed order)
++ */
++#define RF_CSR_CFG_DATA_MT7620		FIELD32(0x0000ff00)
++#define RF_CSR_CFG_REGNUM_MT7620	FIELD32(0x03ff0000)
++#define RF_CSR_CFG_WRITE_MT7620		FIELD32(0x00000010)
++#define RF_CSR_CFG_BUSY_MT7620		FIELD32(0x00000001)
++
++/* undocumented registers for calibration of new MAC */
++#define RF_CONTROL0			0x0518
++#define RF_BYPASS0			0x051c
++#define RF_CONTROL1			0x0520
++#define RF_BYPASS1			0x0524
++#define RF_CONTROL2			0x0528
++#define RF_BYPASS2			0x052c
++#define RF_CONTROL3			0x0530
++#define RF_BYPASS3			0x0534
++
++/*
+  * EFUSE_CSR: RT30x0 EEPROM
+  */
+ #define EFUSE_CTRL			0x0580
+@@ -1022,6 +1041,16 @@
+ #define AUTOWAKEUP_CFG_AUTOWAKE		FIELD32(0x00008000)
+ 
+ /*
++ * MIMO_PS_CFG: MIMO Power-save Configuration
++ */
++#define MIMO_PS_CFG			0x1210
++#define MIMO_PS_CFG_MMPS_BB_EN		FIELD32(0x00000001)
++#define MIMO_PS_CFG_MMPS_RX_ANT_NUM	FIELD32(0x00000006)
++#define MIMO_PS_CFG_MMPS_RF_EN		FIELD32(0x00000008)
++#define MIMO_PS_CFG_RX_STBY_POL		FIELD32(0x00000010)
++#define MIMO_PS_CFG_RX_RX_STBY0		FIELD32(0x00000020)
++
++/*
+  * EDCA_AC0_CFG:
+  */
+ #define EDCA_AC0_CFG			0x1300
+@@ -1095,6 +1124,12 @@
+ #define TX_PWR_CFG_0_OFDM6_CH1		FIELD32(0x00f00000)
+ #define TX_PWR_CFG_0_OFDM12_CH0		FIELD32(0x0f000000)
+ #define TX_PWR_CFG_0_OFDM12_CH1		FIELD32(0xf0000000)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_0B_1MBS_2MBS		FIELD32(0x000000ff)
++#define TX_PWR_CFG_0B_5MBS_11MBS		FIELD32(0x0000ff00)
++#define TX_PWR_CFG_0B_6MBS_9MBS		FIELD32(0x00ff0000)
++#define TX_PWR_CFG_0B_12MBS_18MBS	FIELD32(0xff000000)
++
+ 
+ /*
+  * TX_PWR_CFG_1:
+@@ -1117,6 +1152,11 @@
+ #define TX_PWR_CFG_1_MCS0_CH1		FIELD32(0x00f00000)
+ #define TX_PWR_CFG_1_MCS2_CH0		FIELD32(0x0f000000)
+ #define TX_PWR_CFG_1_MCS2_CH1		FIELD32(0xf0000000)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_1B_24MBS_36MBS	FIELD32(0x000000ff)
++#define TX_PWR_CFG_1B_48MBS		FIELD32(0x0000ff00)
++#define TX_PWR_CFG_1B_MCS0_MCS1		FIELD32(0x00ff0000)
++#define TX_PWR_CFG_1B_MCS2_MCS3		FIELD32(0xff000000)
+ 
+ /*
+  * TX_PWR_CFG_2:
+@@ -1139,6 +1179,11 @@
+ #define TX_PWR_CFG_2_MCS8_CH1		FIELD32(0x00f00000)
+ #define TX_PWR_CFG_2_MCS10_CH0		FIELD32(0x0f000000)
+ #define TX_PWR_CFG_2_MCS10_CH1		FIELD32(0xf0000000)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_2B_MCS4_MCS5		FIELD32(0x000000ff)
++#define TX_PWR_CFG_2B_MCS6_MCS7		FIELD32(0x0000ff00)
++#define TX_PWR_CFG_2B_MCS8_MCS9		FIELD32(0x00ff0000)
++#define TX_PWR_CFG_2B_MCS10_MCS11	FIELD32(0xff000000)
+ 
+ /*
+  * TX_PWR_CFG_3:
+@@ -1161,6 +1206,11 @@
+ #define TX_PWR_CFG_3_STBC0_CH1		FIELD32(0x00f00000)
+ #define TX_PWR_CFG_3_STBC2_CH0		FIELD32(0x0f000000)
+ #define TX_PWR_CFG_3_STBC2_CH1		FIELD32(0xf0000000)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_3B_MCS12_MCS13	FIELD32(0x000000ff)
++#define TX_PWR_CFG_3B_MCS14		FIELD32(0x0000ff00)
++#define TX_PWR_CFG_3B_STBC_MCS0_MCS1	FIELD32(0x00ff0000)
++#define TX_PWR_CFG_3B_STBC_MCS2_MSC3	FIELD32(0xff000000)
+ 
+ /*
+  * TX_PWR_CFG_4:
+@@ -1175,6 +1225,9 @@
+ #define TX_PWR_CFG_4_STBC4_CH1		FIELD32(0x000000f0)
+ #define TX_PWR_CFG_4_STBC6_CH0		FIELD32(0x00000f00)
+ #define TX_PWR_CFG_4_STBC6_CH1		FIELD32(0x0000f000)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_4B_STBC_MCS4_MCS5	FIELD32(0x000000ff)
++#define TX_PWR_CFG_4B_STBC_MCS6		FIELD32(0x0000ff00)
+ 
+ /*
+  * TX_PIN_CFG:
+@@ -1201,6 +1254,8 @@
+ #define TX_PIN_CFG_RFTR_POL		FIELD32(0x00020000)
+ #define TX_PIN_CFG_TRSW_EN		FIELD32(0x00040000)
+ #define TX_PIN_CFG_TRSW_POL		FIELD32(0x00080000)
++#define TX_PIN_CFG_RFRX_EN		FIELD32(0x00100000)
++#define TX_PIN_CFG_RFRX_POL		FIELD32(0x00200000)
+ #define TX_PIN_CFG_PA_PE_A2_EN		FIELD32(0x01000000)
+ #define TX_PIN_CFG_PA_PE_G2_EN		FIELD32(0x02000000)
+ #define TX_PIN_CFG_PA_PE_A2_POL		FIELD32(0x04000000)
+@@ -1547,6 +1602,95 @@
+ #define TX_PWR_CFG_4_EXT_STBC4_CH2	FIELD32(0x0000000f)
+ #define TX_PWR_CFG_4_EXT_STBC6_CH2	FIELD32(0x00000f00)
+ 
++/* TXn_RF_GAIN_CORRECT: RF Gain Correction for each RF_ALC[3:2]
++ * Unit: 0.1 dB, Range: -3.2 dB to 3.1 dB
++ */
++#define TX0_RF_GAIN_CORRECT		0x13a0
++#define TX0_RF_GAIN_CORRECT_GAIN_CORR_0	FIELD32(0x0000003f)
++#define TX0_RF_GAIN_CORRECT_GAIN_CORR_1	FIELD32(0x00003f00)
++#define TX0_RF_GAIN_CORRECT_GAIN_CORR_2	FIELD32(0x003f0000)
++#define TX0_RF_GAIN_CORRECT_GAIN_CORR_3	FIELD32(0x3f000000)
++
++#define TX1_RF_GAIN_CORRECT		0x13a4
++#define TX1_RF_GAIN_CORRECT_GAIN_CORR_0	FIELD32(0x0000003f)
++#define TX1_RF_GAIN_CORRECT_GAIN_CORR_1	FIELD32(0x00003f00)
++#define TX1_RF_GAIN_CORRECT_GAIN_CORR_2	FIELD32(0x003f0000)
++#define TX1_RF_GAIN_CORRECT_GAIN_CORR_3	FIELD32(0x3f000000)
++
++/* TXn_RF_GAIN_ATTEN: TXn RF Gain Attenuation Level
++ * Format: 7-bit, signed value
++ * Unit: 0.5 dB, Range: -20 dB to -5 dB
++ */
++#define TX0_RF_GAIN_ATTEN		0x13a8
++#define TX0_RF_GAIN_ATTEN_LEVEL_0	FIELD32(0x0000007f)
++#define TX0_RF_GAIN_ATTEN_LEVEL_1	FIELD32(0x00007f00)
++#define TX0_RF_GAIN_ATTEN_LEVEL_2	FIELD32(0x007f0000)
++#define TX0_RF_GAIN_ATTEN_LEVEL_3	FIELD32(0x7f000000)
++#define TX1_RF_GAIN_ATTEN		0x13ac
++#define TX1_RF_GAIN_ATTEN_LEVEL_0	FIELD32(0x0000007f)
++#define TX1_RF_GAIN_ATTEN_LEVEL_1	FIELD32(0x00007f00)
++#define TX1_RF_GAIN_ATTEN_LEVEL_2	FIELD32(0x007f0000)
++#define TX1_RF_GAIN_ATTEN_LEVEL_3	FIELD32(0x7f000000)
++
++/* TX_ALC_CFG_0: TX Automatic Level Control Configuration 0
++ * TX_ALC_LIMIT_n: TXn upper limit
++ * TX_ALC_CH_INIT_n: TXn channel initial transmission gain
++ * Unit: 0.5 dB, Range: 0 to 23.5 dB
++ */
++#define TX_ALC_CFG_0			0x13b0
++#define TX_ALC_CFG_0_CH_INIT_0		FIELD32(0x0000003f)
++#define TX_ALC_CFG_0_CH_INIT_1		FIELD32(0x00003f00)
++#define TX_ALC_CFG_0_LIMIT_0		FIELD32(0x003f0000)
++#define TX_ALC_CFG_0_LIMIT_1		FIELD32(0x3f000000)
++
++/* TX_ALC_CFG_1: TX Automatic Level Control Configuration 1
++ * TX_TEMP_COMP:      TX Power Temperature Compensation
++ *                    Unit: 0.5 dB, Range: -10 dB to 10 dB
++ * TXn_GAIN_FINE:     TXn Gain Fine Adjustment
++ *                    Unit: 0.1 dB, Range: -0.8 dB to 0.7 dB
++ * RF_TOS_DLY:        Sets the RF_TOS_EN assertion delay after
++ *                    deassertion of PA_PE.
++ *                    Unit: 0.25 usec
++ * TXn_RF_GAIN_ATTEN: TXn RF gain attentuation selector
++ * RF_TOS_TIMEOUT:    time-out value for RF_TOS_ENABLE
++ *                    deassertion if RF_TOS_DONE is missing.
++ *                    Unit: 0.25 usec
++ * RF_TOS_ENABLE:     TX offset calibration enable
++ * ROS_BUSY_EN:       RX offset calibration busy enable
++ */
++#define TX_ALC_CFG_1			0x13b4
++#define TX_ALC_CFG_1_TX_TEMP_COMP	FIELD32(0x0000003f)
++#define TX_ALC_CFG_1_TX0_GAIN_FINE	FIELD32(0x00000f00)
++#define TX_ALC_CFG_1_TX1_GAIN_FINE	FIELD32(0x0000f000)
++#define TX_ALC_CFG_1_RF_TOS_DLY		FIELD32(0x00070000)
++#define TX_ALC_CFG_1_TX0_RF_GAIN_ATTEN	FIELD32(0x00300000)
++#define TX_ALC_CFG_1_TX1_RF_GAIN_ATTEN	FIELD32(0x00c00000)
++#define TX_ALC_CFG_1_RF_TOS_TIMEOUT	FIELD32(0x3f000000)
++#define TX_ALC_CFG_1_RF_TOS_ENABLE	FIELD32(0x40000000)
++#define TX_ALC_CFG_1_ROS_BUSY_EN	FIELD32(0x80000000)
++
++/* TXn_BB_GAIN_ATTEN: TXn RF Gain Attenuation Level
++ * Format: 5-bit signed values
++ * Unit: 0.5 dB, Range: -8 dB to 7 dB
++ */
++#define TX0_BB_GAIN_ATTEN		0x13c0
++#define TX0_BB_GAIN_ATTEN_LEVEL_0	FIELD32(0x0000001f)
++#define TX0_BB_GAIN_ATTEN_LEVEL_1	FIELD32(0x00001f00)
++#define TX0_BB_GAIN_ATTEN_LEVEL_2	FIELD32(0x001f0000)
++#define TX0_BB_GAIN_ATTEN_LEVEL_3	FIELD32(0x1f000000)
++#define TX1_BB_GAIN_ATTEN		0x13c4
++#define TX1_BB_GAIN_ATTEN_LEVEL_0	FIELD32(0x0000001f)
++#define TX1_BB_GAIN_ATTEN_LEVEL_1	FIELD32(0x00001f00)
++#define TX1_BB_GAIN_ATTEN_LEVEL_2	FIELD32(0x001f0000)
++#define TX1_BB_GAIN_ATTEN_LEVEL_3	FIELD32(0x1f000000)
++
++/* TX_ALC_VGA3: TX Automatic Level Correction Variable Gain Amplifier 3 */
++#define TX_ALC_VGA3			0x13c8
++#define TX_ALC_VGA3_TX0_ALC_VGA3	FIELD32(0x0000001f)
++#define TX_ALC_VGA3_TX1_ALC_VGA3	FIELD32(0x00001f00)
++#define TX_ALC_VGA3_TX0_ALC_VGA2	FIELD32(0x001f0000)
++#define TX_ALC_VGA3_TX1_ALC_VGA2	FIELD32(0x1f000000)
++
+ /* TX_PWR_CFG_7 */
+ #define TX_PWR_CFG_7			0x13d4
+ #define TX_PWR_CFG_7_OFDM54_CH0		FIELD32(0x0000000f)
+@@ -1555,6 +1699,10 @@
+ #define TX_PWR_CFG_7_MCS7_CH0		FIELD32(0x000f0000)
+ #define TX_PWR_CFG_7_MCS7_CH1		FIELD32(0x00f00000)
+ #define TX_PWR_CFG_7_MCS7_CH2		FIELD32(0x0f000000)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_7B_54MBS		FIELD32(0x000000ff)
++#define TX_PWR_CFG_7B_MCS7		FIELD32(0x00ff0000)
++
+ 
+ /* TX_PWR_CFG_8 */
+ #define TX_PWR_CFG_8			0x13d8
+@@ -1564,12 +1712,17 @@
+ #define TX_PWR_CFG_8_MCS23_CH0		FIELD32(0x000f0000)
+ #define TX_PWR_CFG_8_MCS23_CH1		FIELD32(0x00f00000)
+ #define TX_PWR_CFG_8_MCS23_CH2		FIELD32(0x0f000000)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_8B_MCS15		FIELD32(0x000000ff)
++
+ 
+ /* TX_PWR_CFG_9 */
+ #define TX_PWR_CFG_9			0x13dc
+ #define TX_PWR_CFG_9_STBC7_CH0		FIELD32(0x0000000f)
+ #define TX_PWR_CFG_9_STBC7_CH1		FIELD32(0x000000f0)
+ #define TX_PWR_CFG_9_STBC7_CH2		FIELD32(0x00000f00)
++/* bits for new 2T devices */
++#define TX_PWR_CFG_9B_STBC_MCS7		FIELD32(0x000000ff)
+ 
+ /*
+  * RX_FILTER_CFG: RX configuration register.
+@@ -2137,11 +2290,14 @@ struct mac_iveiv_entry {
+ #define RFCSR1_TX1_PD			FIELD8(0x20)
+ #define RFCSR1_RX2_PD			FIELD8(0x40)
+ #define RFCSR1_TX2_PD			FIELD8(0x80)
++#define RFCSR1_TX2_EN_MT7620		FIELD8(0x02)
+ 
+ /*
+  * RFCSR 2:
+  */
+ #define RFCSR2_RESCAL_EN		FIELD8(0x80)
++#define RFCSR2_RX2_EN_MT7620		FIELD8(0x02)
++#define RFCSR2_TX2_EN_MT7620		FIELD8(0x20)
+ 
+ /*
+  * RFCSR 3:
+@@ -2160,6 +2316,12 @@ struct mac_iveiv_entry {
+ #define RFCSR3_BIT5			FIELD8(0x20)
+ 
+ /*
++ * RFCSR 4:
++ * VCOCAL_EN used by MT7620
++ */
++#define RFCSR4_VCOCAL_EN		FIELD8(0x80)
++
++/*
+  * FRCSR 5:
+  */
+ #define RFCSR5_R1			FIELD8(0x0c)
+@@ -2214,6 +2376,7 @@ struct mac_iveiv_entry {
+  */
+ #define RFCSR13_TX_POWER		FIELD8(0x1f)
+ #define RFCSR13_DR0			FIELD8(0xe0)
++#define RFCSR13_RDIV_MT7620		FIELD8(0x03)
+ 
+ /*
+  * RFCSR 15:
+@@ -2224,6 +2387,8 @@ struct mac_iveiv_entry {
+  * RFCSR 16:
+  */
+ #define RFCSR16_TXMIXER_GAIN		FIELD8(0x07)
++#define RFCSR16_RF_PLL_FREQ_SEL_MT7620	FIELD8(0x0F)
++#define RFCSR16_SDM_MODE_MT7620		FIELD8(0xE0)
+ 
+ /*
+  * RFCSR 17:
+@@ -2236,6 +2401,8 @@ struct mac_iveiv_entry {
+ /* RFCSR 18 */
+ #define RFCSR18_XO_TUNE_BYPASS		FIELD8(0x40)
+ 
++/* RFCSR 19 */
++#define RFCSR19_K			FIELD8(0x03)
+ 
+ /*
+  * RFCSR 20:
+@@ -2246,11 +2413,14 @@ struct mac_iveiv_entry {
+  * RFCSR 21:
+  */
+ #define RFCSR21_RX_LO2_EN		FIELD8(0x08)
++#define RFCSR21_BIT1			FIELD8(0x01)
++#define RFCSR21_BIT8			FIELD8(0x80)
+ 
+ /*
+  * RFCSR 22:
+  */
+ #define RFCSR22_BASEBAND_LOOPBACK	FIELD8(0x01)
++#define RFCSR22_FREQPLAN_D_MT7620	FIELD8(0x07)
+ 
+ /*
+  * RFCSR 23:
+@@ -2273,6 +2443,11 @@ struct mac_iveiv_entry {
+ #define RFCSR27_R4			FIELD8(0x40)
+ 
+ /*
++ * RFCSR 28:
++ */
++#define RFCSR28_CH11_HT40		FIELD8(0x04)
++
++/*
+  * RFCSR 29:
+  */
+ #define RFCSR29_ADC6_TEST		FIELD8(0x01)
+@@ -2333,6 +2508,7 @@ struct mac_iveiv_entry {
+  */
+ #define RFCSR42_BIT1			FIELD8(0x01)
+ #define RFCSR42_BIT4			FIELD8(0x08)
++#define RFCSR42_TX2_EN_MT7620		FIELD8(0x40)
+ 
+ /*
+  * RFCSR 49:
+@@ -2435,6 +2611,7 @@ enum rt2800_eeprom_word {
+ 	EEPROM_TSSI_BOUND_BG5,
+ 	EEPROM_TXPOWER_A1,
+ 	EEPROM_TXPOWER_A2,
++	EEPROM_TXPOWER_INIT,
+ 	EEPROM_TSSI_BOUND_A1,
+ 	EEPROM_TSSI_BOUND_A2,
+ 	EEPROM_TSSI_BOUND_A3,
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 8d00c599e47a..201b12ed90c6 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -59,6 +59,9 @@
+ 	rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
+ #define WAIT_FOR_RFCSR(__dev, __reg) \
+ 	rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
++#define WAIT_FOR_RFCSR_MT7620(__dev, __reg) \
++	rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY_MT7620, \
++			    (__reg))
+ #define WAIT_FOR_RF(__dev, __reg) \
+ 	rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
+ #define WAIT_FOR_MCU(__dev, __reg) \
+@@ -150,19 +153,56 @@ static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
+ 	 * Wait until the RFCSR becomes available, afterwards we
+ 	 * can safely write the new data into the register.
+ 	 */
+-	if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
+-		reg = 0;
+-		rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
+-		rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
+-		rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
+-		rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
++	switch (rt2x00dev->chip.rt) {
++	case RT6352:
++		if (WAIT_FOR_RFCSR_MT7620(rt2x00dev, &reg)) {
++			reg = 0;
++			rt2x00_set_field32(&reg, RF_CSR_CFG_DATA_MT7620, value);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM_MT7620,
++					   word);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE_MT7620, 1);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY_MT7620, 1);
++
++			rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
++		}
++		break;
+ 
+-		rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
++	default:
++		if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
++			reg = 0;
++			rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
++
++			rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
++		}
++		break;
+ 	}
+ 
+ 	mutex_unlock(&rt2x00dev->csr_mutex);
+ }
+ 
++static void rt2800_rfcsr_write_bank(struct rt2x00_dev *rt2x00dev, const u8 bank,
++				    const unsigned int reg, const u8 value)
++{
++	rt2800_rfcsr_write(rt2x00dev, (reg | (bank << 6)), value);
++}
++
++static void rt2800_rfcsr_write_chanreg(struct rt2x00_dev *rt2x00dev,
++				       const unsigned int reg, const u8 value)
++{
++	rt2800_rfcsr_write_bank(rt2x00dev, 4, reg, value);
++	rt2800_rfcsr_write_bank(rt2x00dev, 6, reg, value);
++}
++
++static void rt2800_rfcsr_write_dccal(struct rt2x00_dev *rt2x00dev,
++				     const unsigned int reg, const u8 value)
++{
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, reg, value);
++	rt2800_rfcsr_write_bank(rt2x00dev, 7, reg, value);
++}
++
+ static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
+ 			      const unsigned int word, u8 *value)
+ {
+@@ -178,22 +218,48 @@ static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
+ 	 * doesn't become available in time, reg will be 0xffffffff
+ 	 * which means we return 0xff to the caller.
+ 	 */
+-	if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
+-		reg = 0;
+-		rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
+-		rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
+-		rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
++	switch (rt2x00dev->chip.rt) {
++	case RT6352:
++		if (WAIT_FOR_RFCSR_MT7620(rt2x00dev, &reg)) {
++			reg = 0;
++			rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM_MT7620,
++					   word);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE_MT7620, 0);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY_MT7620, 1);
+ 
+-		rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
++			rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
+ 
+-		WAIT_FOR_RFCSR(rt2x00dev, &reg);
+-	}
++			WAIT_FOR_RFCSR_MT7620(rt2x00dev, &reg);
++		}
+ 
+-	*value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
++		*value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA_MT7620);
++		break;
++
++	default:
++		if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
++			reg = 0;
++			rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
++			rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
++
++			rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
++
++			WAIT_FOR_RFCSR(rt2x00dev, &reg);
++		}
++
++		*value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
++		break;
++	}
+ 
+ 	mutex_unlock(&rt2x00dev->csr_mutex);
+ }
+ 
++static void rt2800_rfcsr_read_bank(struct rt2x00_dev *rt2x00dev, const u8 bank,
++				   const unsigned int reg, u8 *value)
++{
++	rt2800_rfcsr_read(rt2x00dev, (reg | (bank << 6)), value);
++}
++
+ static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
+ 			    const unsigned int word, const u32 value)
+ {
+@@ -250,6 +316,7 @@ static const unsigned int rt2800_eeprom_map[EEPROM_WORD_COUNT] = {
+ 	[EEPROM_TSSI_BOUND_BG5]		= 0x003b,
+ 	[EEPROM_TXPOWER_A1]		= 0x003c,
+ 	[EEPROM_TXPOWER_A2]		= 0x0053,
++	[EEPROM_TXPOWER_INIT]		= 0x0068,
+ 	[EEPROM_TSSI_BOUND_A1]		= 0x006a,
+ 	[EEPROM_TSSI_BOUND_A2]		= 0x006b,
+ 	[EEPROM_TSSI_BOUND_A3]		= 0x006c,
+@@ -524,6 +591,7 @@ void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
+ 		break;
+ 
+ 	case RT5592:
++	case RT6352:
+ 		*txwi_size = TXWI_DESC_SIZE_5WORDS;
+ 		*rxwi_size = RXWI_DESC_SIZE_6WORDS;
+ 		break;
+@@ -2810,7 +2878,8 @@ static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
+ 				rt2800_rfcsr_write(rt2x00dev, 59,
+ 						   r59_nonbt_rev[idx]);
+ 			} else if (rt2x00_rt(rt2x00dev, RT5390) ||
+-				   rt2x00_rt(rt2x00dev, RT5392)) {
++				   rt2x00_rt(rt2x00dev, RT5392) ||
++				   rt2x00_rt(rt2x00dev, RT6352)) {
+ 				static const char r59_non_bt[] = {0x8f, 0x8f,
+ 					0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
+ 					0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
+@@ -3104,6 +3173,242 @@ static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
+ 	rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F);
+ }
+ 
++static void rt2800_config_channel_rf7620(struct rt2x00_dev *rt2x00dev,
++					 struct ieee80211_conf *conf,
++					 struct rf_channel *rf,
++					 struct channel_info *info)
++{
++	struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
++	u8 rx_agc_fc, tx_agc_fc;
++	u8 rfcsr;
++
++	/* Frequeny plan setting */
++	/* Rdiv setting (set 0x03 if Xtal==20)
++	 * R13[1:0]
++	 */
++	rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR13_RDIV_MT7620,
++			  rt2800_clk_is_20mhz(rt2x00dev) ? 3 : 0);
++	rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
++
++	/* N setting
++	 * R20[7:0] in rf->rf1
++	 * R21[0] always 0
++	 */
++	rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr);
++	rfcsr = (rf->rf1 & 0x00ff);
++	rt2800_rfcsr_write(rt2x00dev, 20, rfcsr);
++
++	rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR21_BIT1, 0);
++	rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
++
++	/* K setting (always 0)
++	 * R16[3:0] (RF PLL freq selection)
++	 */
++	rt2800_rfcsr_read(rt2x00dev, 16, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR16_RF_PLL_FREQ_SEL_MT7620, 0);
++	rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
++
++	/* D setting (always 0)
++	 * R22[2:0] (D=15, R22[2:0]=<111>)
++	 */
++	rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR22_FREQPLAN_D_MT7620, 0);
++	rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
++
++	/* Ksd setting
++	 * Ksd: R17<7:0> in rf->rf2
++	 *      R18<7:0> in rf->rf3
++	 *      R19<1:0> in rf->rf4
++	 */
++	rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
++	rfcsr = rf->rf2;
++	rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
++
++	rt2800_rfcsr_read(rt2x00dev, 18, &rfcsr);
++	rfcsr = rf->rf3;
++	rt2800_rfcsr_write(rt2x00dev, 18, rfcsr);
++
++	rt2800_rfcsr_read(rt2x00dev, 19, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR19_K, rf->rf4);
++	rt2800_rfcsr_write(rt2x00dev, 19, rfcsr);
++
++	/* Default: XO=20MHz , SDM mode */
++	rt2800_rfcsr_read(rt2x00dev, 16, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR16_SDM_MODE_MT7620, 0x80);
++	rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
++
++	rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR21_BIT8, 1);
++	rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
++
++	rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR1_TX2_EN_MT7620,
++			  rt2x00dev->default_ant.tx_chain_num != 1);
++	rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
++
++	rt2800_rfcsr_read(rt2x00dev, 2, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR2_TX2_EN_MT7620,
++			  rt2x00dev->default_ant.tx_chain_num != 1);
++	rt2x00_set_field8(&rfcsr, RFCSR2_RX2_EN_MT7620,
++			  rt2x00dev->default_ant.rx_chain_num != 1);
++	rt2800_rfcsr_write(rt2x00dev, 2, rfcsr);
++
++	rt2800_rfcsr_read(rt2x00dev, 42, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR42_TX2_EN_MT7620,
++			  rt2x00dev->default_ant.tx_chain_num != 1);
++	rt2800_rfcsr_write(rt2x00dev, 42, rfcsr);
++
++	/* RF for DC Cal BW */
++	if (conf_is_ht40(conf)) {
++		rt2800_rfcsr_write_dccal(rt2x00dev, 6, 0x10);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 7, 0x10);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 8, 0x04);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x10);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x10);
++	} else {
++		rt2800_rfcsr_write_dccal(rt2x00dev, 6, 0x20);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 7, 0x20);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 8, 0x00);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x20);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x20);
++	}
++
++	if (conf_is_ht40(conf)) {
++		rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x08);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x08);
++	} else {
++		rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x28);
++		rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x28);
++	}
++
++	rt2800_rfcsr_read(rt2x00dev, 28, &rfcsr);
++	rt2x00_set_field8(&rfcsr, RFCSR28_CH11_HT40,
++			  conf_is_ht40(conf) && (rf->channel == 11));
++	rt2800_rfcsr_write(rt2x00dev, 28, rfcsr);
++
++	if (!test_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags)) {
++		if (conf_is_ht40(conf)) {
++			rx_agc_fc = drv_data->rx_calibration_bw40;
++			tx_agc_fc = drv_data->tx_calibration_bw40;
++		} else {
++			rx_agc_fc = drv_data->rx_calibration_bw20;
++			tx_agc_fc = drv_data->tx_calibration_bw20;
++		}
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 6, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= rx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, rfcsr);
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 7, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= rx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, rfcsr);
++		rt2800_rfcsr_read_bank(rt2x00dev, 7, 6, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= rx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 7, 6, rfcsr);
++		rt2800_rfcsr_read_bank(rt2x00dev, 7, 7, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= rx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 7, 7, rfcsr);
++
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 58, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= tx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, rfcsr);
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 59, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= tx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, rfcsr);
++		rt2800_rfcsr_read_bank(rt2x00dev, 7, 58, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= tx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 7, 58, rfcsr);
++		rt2800_rfcsr_read_bank(rt2x00dev, 7, 59, &rfcsr);
++		rfcsr &= (~0x3F);
++		rfcsr |= tx_agc_fc;
++		rt2800_rfcsr_write_bank(rt2x00dev, 7, 59, rfcsr);
++	}
++}
++
++static void rt2800_config_alc(struct rt2x00_dev *rt2x00dev,
++			      struct ieee80211_channel *chan,
++			      int power_level) {
++	u16 eeprom, target_power, max_power;
++	u32 mac_sys_ctrl, mac_status;
++	u32 reg;
++	u8 bbp;
++	int i;
++
++	/* hardware unit is 0.5dBm, limited to 23.5dBm */
++	power_level *= 2;
++	if (power_level > 0x2f)
++		power_level = 0x2f;
++
++	max_power = chan->max_power * 2;
++	if (max_power > 0x2f)
++		max_power = 0x2f;
++
++	rt2800_register_read(rt2x00dev, TX_ALC_CFG_0, &reg);
++	rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_0, power_level);
++	rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_1, power_level);
++	rt2x00_set_field32(&reg, TX_ALC_CFG_0_LIMIT_0, max_power);
++	rt2x00_set_field32(&reg, TX_ALC_CFG_0_LIMIT_1, max_power);
++
++	rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
++	if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_INTERNAL_TX_ALC)) {
++		/* init base power by eeprom target power */
++		rt2800_eeprom_read(rt2x00dev, EEPROM_TXPOWER_INIT,
++				   &target_power);
++		rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_0, target_power);
++		rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_1, target_power);
++	}
++	rt2800_register_write(rt2x00dev, TX_ALC_CFG_0, reg);
++
++	rt2800_register_read(rt2x00dev, TX_ALC_CFG_1, &reg);
++	rt2x00_set_field32(&reg, TX_ALC_CFG_1_TX_TEMP_COMP, 0);
++	rt2800_register_write(rt2x00dev, TX_ALC_CFG_1, reg);
++
++	/* Save MAC SYS CTRL registers */
++	rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &mac_sys_ctrl);
++	/* Disable Tx/Rx */
++	rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
++	/* Check MAC Tx/Rx idle */
++	for (i = 0; i < 10000; i++) {
++		rt2800_register_read(rt2x00dev, MAC_STATUS_CFG,
++				     &mac_status);
++		if (mac_status & 0x3)
++			usleep_range(50, 200);
++		else
++			break;
++	}
++
++	if (i == 10000)
++		rt2x00_warn(rt2x00dev, "Wait MAC Status to MAX !!!\n");
++
++	if (chan->center_freq > 2457) {
++		rt2800_bbp_read(rt2x00dev, 30, &bbp);
++		bbp = 0x40;
++		rt2800_bbp_write(rt2x00dev, 30, bbp);
++		rt2800_rfcsr_write(rt2x00dev, 39, 0);
++		if (rt2x00_has_cap_external_lna_bg(rt2x00dev))
++			rt2800_rfcsr_write(rt2x00dev, 42, 0xfb);
++		else
++			rt2800_rfcsr_write(rt2x00dev, 42, 0x7b);
++	} else {
++		rt2800_bbp_read(rt2x00dev, 30, &bbp);
++		bbp = 0x1f;
++		rt2800_bbp_write(rt2x00dev, 30, bbp);
++		rt2800_rfcsr_write(rt2x00dev, 39, 0x80);
++		if (rt2x00_has_cap_external_lna_bg(rt2x00dev))
++			rt2800_rfcsr_write(rt2x00dev, 42, 0xdb);
++		else
++			rt2800_rfcsr_write(rt2x00dev, 42, 0x5b);
++	}
++	rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, mac_sys_ctrl);
++}
++
+ static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev,
+ 					   const unsigned int word,
+ 					   const u8 value)
+@@ -3228,7 +3533,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 				  struct channel_info *info)
+ {
+ 	u32 reg;
+-	unsigned int tx_pin;
++	u32 tx_pin;
+ 	u8 bbp, rfcsr;
+ 
+ 	info->default_power1 = rt2800_txpower_to_dev(rt2x00dev, rf->channel,
+@@ -3273,6 +3578,9 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 	case RF5592:
+ 		rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info);
+ 		break;
++	case RF7620:
++		rt2800_config_channel_rf7620(rt2x00dev, conf, rf, info);
++		break;
+ 	default:
+ 		rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
+ 	}
+@@ -3347,7 +3655,8 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 
+ 	if (rf->channel <= 14) {
+ 		if (!rt2x00_rt(rt2x00dev, RT5390) &&
+-		    !rt2x00_rt(rt2x00dev, RT5392)) {
++		    !rt2x00_rt(rt2x00dev, RT5392) &&
++		    !rt2x00_rt(rt2x00dev, RT6352)) {
+ 			if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
+ 				rt2800_bbp_write(rt2x00dev, 82, 0x62);
+ 				rt2800_bbp_write(rt2x00dev, 75, 0x46);
+@@ -3367,7 +3676,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 			rt2800_bbp_write(rt2x00dev, 82, 0x94);
+ 		else if (rt2x00_rt(rt2x00dev, RT3593))
+ 			rt2800_bbp_write(rt2x00dev, 82, 0x82);
+-		else
++		else if (!rt2x00_rt(rt2x00dev, RT6352))
+ 			rt2800_bbp_write(rt2x00dev, 82, 0xf2);
+ 
+ 		if (rt2x00_rt(rt2x00dev, RT3593))
+@@ -3388,7 +3697,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 	if (rt2x00_rt(rt2x00dev, RT3572))
+ 		rt2800_rfcsr_write(rt2x00dev, 8, 0);
+ 
+-	tx_pin = 0;
++	rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
+ 
+ 	switch (rt2x00dev->default_ant.tx_chain_num) {
+ 	case 3:
+@@ -3437,6 +3746,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 
+ 	rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
+ 	rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
++	rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFRX_EN, 1); /* mt7620 */
+ 
+ 	rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
+ 
+@@ -3495,7 +3805,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 		usleep_range(1000, 1500);
+ 	}
+ 
+-	if (rt2x00_rt(rt2x00dev, RT5592)) {
++	if (rt2x00_rt(rt2x00dev, RT5592) || rt2x00_rt(rt2x00dev, RT6352)) {
+ 		rt2800_bbp_write(rt2x00dev, 195, 141);
+ 		rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a);
+ 
+@@ -4182,6 +4492,128 @@ static void rt2800_config_txpower_rt3593(struct rt2x00_dev *rt2x00dev,
+ 			   (unsigned long) regs[i]);
+ }
+ 
++static void rt2800_config_txpower_rt6352(struct rt2x00_dev *rt2x00dev,
++					 struct ieee80211_channel *chan,
++					 int power_level)
++{
++	u32 reg, pwreg;
++	u16 eeprom;
++	u32 data, gdata;
++	u8 t, i;
++	enum nl80211_band band = chan->band;
++	int delta;
++
++	/* Warn user if bw_comp is set in EEPROM */
++	delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
++
++	if (delta)
++		rt2x00_warn(rt2x00dev, "ignoring EEPROM HT40 power delta: %d\n",
++			    delta);
++
++	/* populate TX_PWR_CFG_0 up to TX_PWR_CFG_4 from EEPROM for HT20, limit
++	 * value to 0x3f and replace 0x20 by 0x21 as this is what the vendor
++	 * driver does as well, though it looks kinda wrong.
++	 * Maybe some misunderstanding of what a signed 8-bit value is? Maybe
++	 * the hardware has a problem handling 0x20, and as the code initially
++	 * used a fixed offset between HT20 and HT40 rates they had to work-
++	 * around that issue and most likely just forgot about it later on.
++	 * Maybe we should use rt2800_get_txpower_bw_comp() here as well,
++	 * however, the corresponding EEPROM value is not respected by the
++	 * vendor driver, so maybe this is rather being taken care of the
++	 * TXALC and the driver doesn't need to handle it...?
++	 * Though this is all very awkward, just do as they did, as that's what
++	 * board vendors expected when they populated the EEPROM...
++	 */
++	for (i = 0; i < 5; i++) {
++		rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
++					      i * 2, &eeprom);
++
++		data = eeprom;
++
++		t = eeprom & 0x3f;
++		if (t == 32)
++			t++;
++
++		gdata = t;
++
++		t = (eeprom & 0x3f00) >> 8;
++		if (t == 32)
++			t++;
++
++		gdata |= (t << 8);
++
++		rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
++					      (i * 2) + 1, &eeprom);
++
++		t = eeprom & 0x3f;
++		if (t == 32)
++			t++;
++
++		gdata |= (t << 16);
++
++		t = (eeprom & 0x3f00) >> 8;
++		if (t == 32)
++			t++;
++
++		gdata |= (t << 24);
++		data |= (eeprom << 16);
++
++		if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) {
++			/* HT20 */
++			if (data != 0xffffffff)
++				rt2800_register_write(rt2x00dev,
++						      TX_PWR_CFG_0 + (i * 4),
++						      data);
++		} else {
++			/* HT40 */
++			if (gdata != 0xffffffff)
++				rt2800_register_write(rt2x00dev,
++						      TX_PWR_CFG_0 + (i * 4),
++						      gdata);
++		}
++	}
++
++	/* Aparently Ralink ran out of space in the BYRATE calibration section
++	 * of the EERPOM which is copied to the corresponding TX_PWR_CFG_x
++	 * registers. As recent 2T chips use 8-bit instead of 4-bit values for
++	 * power-offsets more space would be needed. Ralink decided to keep the
++	 * EEPROM layout untouched and rather have some shared values covering
++	 * multiple bitrates.
++	 * Populate the registers not covered by the EEPROM in the same way the
++	 * vendor driver does.
++	 */
++
++	/* For OFDM 54MBS use value from OFDM 48MBS */
++	pwreg = 0;
++	rt2800_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
++	t = rt2x00_get_field32(reg, TX_PWR_CFG_1B_48MBS);
++	rt2x00_set_field32(&pwreg, TX_PWR_CFG_7B_54MBS, t);
++
++	/* For MCS 7 use value from MCS 6 */
++	rt2800_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
++	t = rt2x00_get_field32(reg, TX_PWR_CFG_2B_MCS6_MCS7);
++	rt2x00_set_field32(&pwreg, TX_PWR_CFG_7B_MCS7, t);
++	rt2800_register_write(rt2x00dev, TX_PWR_CFG_7, pwreg);
++
++	/* For MCS 15 use value from MCS 14 */
++	pwreg = 0;
++	rt2800_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
++	t = rt2x00_get_field32(reg, TX_PWR_CFG_3B_MCS14);
++	rt2x00_set_field32(&pwreg, TX_PWR_CFG_8B_MCS15, t);
++	rt2800_register_write(rt2x00dev, TX_PWR_CFG_8, pwreg);
++
++	/* For STBC MCS 7 use value from STBC MCS 6 */
++	pwreg = 0;
++	rt2800_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
++	t = rt2x00_get_field32(reg, TX_PWR_CFG_4B_STBC_MCS6);
++	rt2x00_set_field32(&pwreg, TX_PWR_CFG_9B_STBC_MCS7, t);
++	rt2800_register_write(rt2x00dev, TX_PWR_CFG_9, pwreg);
++
++	rt2800_config_alc(rt2x00dev, chan, power_level);
++
++	/* TODO: temperature compensation code! */
++}
++
+ /*
+  * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and
+  * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values,
+@@ -4378,6 +4810,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
+ {
+ 	if (rt2x00_rt(rt2x00dev, RT3593))
+ 		rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level);
++	else if (rt2x00_rt(rt2x00dev, RT6352))
++		rt2800_config_txpower_rt6352(rt2x00dev, chan, power_level);
+ 	else
+ 		rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level);
+ }
+@@ -4393,6 +4827,7 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
+ {
+ 	u32	tx_pin;
+ 	u8	rfcsr;
++	unsigned long min_sleep = 0;
+ 
+ 	/*
+ 	 * A voltage-controlled oscillator(VCO) is an electronic oscillator
+@@ -4431,6 +4866,15 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
+ 		rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
+ 		rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
+ 		rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
++		min_sleep = 1000;
++		break;
++	case RF7620:
++		rt2800_rfcsr_write(rt2x00dev, 5, 0x40);
++		rt2800_rfcsr_write(rt2x00dev, 4, 0x0C);
++		rt2800_rfcsr_read(rt2x00dev, 4, &rfcsr);
++		rt2x00_set_field8(&rfcsr, RFCSR4_VCOCAL_EN, 1);
++		rt2800_rfcsr_write(rt2x00dev, 4, rfcsr);
++		min_sleep = 2000;
+ 		break;
+ 	default:
+ 		WARN_ONCE(1, "Not supported RF chipet %x for VCO recalibration",
+@@ -4438,7 +4882,8 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
+ 		return;
+ 	}
+ 
+-	usleep_range(1000, 1500);
++	if (min_sleep > 0)
++		usleep_range(min_sleep, min_sleep * 2);
+ 
+ 	rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
+ 	if (rt2x00dev->rf_channel <= 14) {
+@@ -4470,6 +4915,42 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
+ 	}
+ 	rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
+ 
++	if (rt2x00_rt(rt2x00dev, RT6352)) {
++		if (rt2x00dev->default_ant.tx_chain_num == 1) {
++			rt2800_bbp_write(rt2x00dev, 91, 0x07);
++			rt2800_bbp_write(rt2x00dev, 95, 0x1A);
++			rt2800_bbp_write(rt2x00dev, 195, 128);
++			rt2800_bbp_write(rt2x00dev, 196, 0xA0);
++			rt2800_bbp_write(rt2x00dev, 195, 170);
++			rt2800_bbp_write(rt2x00dev, 196, 0x12);
++			rt2800_bbp_write(rt2x00dev, 195, 171);
++			rt2800_bbp_write(rt2x00dev, 196, 0x10);
++		} else {
++			rt2800_bbp_write(rt2x00dev, 91, 0x06);
++			rt2800_bbp_write(rt2x00dev, 95, 0x9A);
++			rt2800_bbp_write(rt2x00dev, 195, 128);
++			rt2800_bbp_write(rt2x00dev, 196, 0xE0);
++			rt2800_bbp_write(rt2x00dev, 195, 170);
++			rt2800_bbp_write(rt2x00dev, 196, 0x30);
++			rt2800_bbp_write(rt2x00dev, 195, 171);
++			rt2800_bbp_write(rt2x00dev, 196, 0x30);
++		}
++
++		if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
++			rt2800_bbp_write(rt2x00dev, 75, 0x60);
++			rt2800_bbp_write(rt2x00dev, 76, 0x44);
++			rt2800_bbp_write(rt2x00dev, 79, 0x1C);
++			rt2800_bbp_write(rt2x00dev, 80, 0x0C);
++			rt2800_bbp_write(rt2x00dev, 82, 0xB6);
++		}
++
++		/* On 11A, We should delay and wait RF/BBP to be stable
++		 * and the appropriate time should be 1000 micro seconds
++		 * 2005/06/05 - On 11G, we also need this delay time.
++		 * Otherwise it's difficult to pass the WHQL.
++		 */
++		usleep_range(1000, 1500);
++	}
+ }
+ EXPORT_SYMBOL_GPL(rt2800_vco_calibration);
+ 
+@@ -4568,7 +5049,8 @@ static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
+ 		    rt2x00_rt(rt2x00dev, RT3593) ||
+ 		    rt2x00_rt(rt2x00dev, RT5390) ||
+ 		    rt2x00_rt(rt2x00dev, RT5392) ||
+-		    rt2x00_rt(rt2x00dev, RT5592))
++		    rt2x00_rt(rt2x00dev, RT5592) ||
++		    rt2x00_rt(rt2x00dev, RT6352))
+ 			vgc = 0x1c + (2 * rt2x00dev->lna_gain);
+ 		else
+ 			vgc = 0x2e + rt2x00dev->lna_gain;
+@@ -4795,7 +5277,8 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
+ 					      0x00000000);
+ 		}
+ 	} else if (rt2x00_rt(rt2x00dev, RT5390) ||
+-		   rt2x00_rt(rt2x00dev, RT5392)) {
++		   rt2x00_rt(rt2x00dev, RT5392) ||
++		   rt2x00_rt(rt2x00dev, RT6352)) {
+ 		rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
+ 		rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
+ 		rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
+@@ -4805,6 +5288,24 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
+ 		rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
+ 	} else if (rt2x00_rt(rt2x00dev, RT5350)) {
+ 		rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
++	} else if (rt2x00_rt(rt2x00dev, RT6352)) {
++		rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000401);
++		rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x000C0000);
++		rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
++		rt2800_register_write(rt2x00dev, MIMO_PS_CFG, 0x00000002);
++		rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0x00150F0F);
++		rt2800_register_write(rt2x00dev, TX_ALC_VGA3, 0x06060606);
++		rt2800_register_write(rt2x00dev, TX0_BB_GAIN_ATTEN, 0x0);
++		rt2800_register_write(rt2x00dev, TX1_BB_GAIN_ATTEN, 0x0);
++		rt2800_register_write(rt2x00dev, TX0_RF_GAIN_ATTEN, 0x6C6C666C);
++		rt2800_register_write(rt2x00dev, TX1_RF_GAIN_ATTEN, 0x6C6C666C);
++		rt2800_register_write(rt2x00dev, TX0_RF_GAIN_CORRECT,
++				      0x3630363A);
++		rt2800_register_write(rt2x00dev, TX1_RF_GAIN_CORRECT,
++				      0x3630363A);
++		rt2800_register_read(rt2x00dev, TX_ALC_CFG_1, &reg);
++		rt2x00_set_field32(&reg, TX_ALC_CFG_1_ROS_BUSY_EN, 0);
++		rt2800_register_write(rt2x00dev, TX_ALC_CFG_1, reg);
+ 	} else {
+ 		rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
+ 		rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
+@@ -5786,6 +6287,231 @@ static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev)
+ 		rt2800_bbp_write(rt2x00dev, 103, 0xc0);
+ }
+ 
++static void rt2800_bbp_glrt_write(struct rt2x00_dev *rt2x00dev,
++				  const u8 reg, const u8 value)
++{
++	rt2800_bbp_write(rt2x00dev, 195, reg);
++	rt2800_bbp_write(rt2x00dev, 196, value);
++}
++
++static void rt2800_bbp_dcoc_write(struct rt2x00_dev *rt2x00dev,
++				  const u8 reg, const u8 value)
++{
++	rt2800_bbp_write(rt2x00dev, 158, reg);
++	rt2800_bbp_write(rt2x00dev, 159, value);
++}
++
++static void rt2800_bbp_dcoc_read(struct rt2x00_dev *rt2x00dev,
++				 const u8 reg, u8 *value)
++{
++	rt2800_bbp_write(rt2x00dev, 158, reg);
++	rt2800_bbp_read(rt2x00dev, 159, value);
++}
++
++static void rt2800_init_bbp_6352(struct rt2x00_dev *rt2x00dev)
++{
++	u8 bbp;
++
++	/* Apply Maximum Likelihood Detection (MLD) for 2 stream case */
++	rt2800_bbp_read(rt2x00dev, 105, &bbp);
++	rt2x00_set_field8(&bbp, BBP105_MLD,
++			  rt2x00dev->default_ant.rx_chain_num == 2);
++	rt2800_bbp_write(rt2x00dev, 105, bbp);
++
++	/* Avoid data loss and CRC errors */
++	rt2800_bbp4_mac_if_ctrl(rt2x00dev);
++
++	/* Fix I/Q swap issue */
++	rt2800_bbp_read(rt2x00dev, 1, &bbp);
++	bbp |= 0x04;
++	rt2800_bbp_write(rt2x00dev, 1, bbp);
++
++	/* BBP for G band */
++	rt2800_bbp_write(rt2x00dev, 3, 0x08);
++	rt2800_bbp_write(rt2x00dev, 4, 0x00); /* rt2800_bbp4_mac_if_ctrl? */
++	rt2800_bbp_write(rt2x00dev, 6, 0x08);
++	rt2800_bbp_write(rt2x00dev, 14, 0x09);
++	rt2800_bbp_write(rt2x00dev, 15, 0xFF);
++	rt2800_bbp_write(rt2x00dev, 16, 0x01);
++	rt2800_bbp_write(rt2x00dev, 20, 0x06);
++	rt2800_bbp_write(rt2x00dev, 21, 0x00);
++	rt2800_bbp_write(rt2x00dev, 22, 0x00);
++	rt2800_bbp_write(rt2x00dev, 27, 0x00);
++	rt2800_bbp_write(rt2x00dev, 28, 0x00);
++	rt2800_bbp_write(rt2x00dev, 30, 0x00);
++	rt2800_bbp_write(rt2x00dev, 31, 0x48);
++	rt2800_bbp_write(rt2x00dev, 47, 0x40);
++	rt2800_bbp_write(rt2x00dev, 62, 0x00);
++	rt2800_bbp_write(rt2x00dev, 63, 0x00);
++	rt2800_bbp_write(rt2x00dev, 64, 0x00);
++	rt2800_bbp_write(rt2x00dev, 65, 0x2C);
++	rt2800_bbp_write(rt2x00dev, 66, 0x1C);
++	rt2800_bbp_write(rt2x00dev, 67, 0x20);
++	rt2800_bbp_write(rt2x00dev, 68, 0xDD);
++	rt2800_bbp_write(rt2x00dev, 69, 0x10);
++	rt2800_bbp_write(rt2x00dev, 70, 0x05);
++	rt2800_bbp_write(rt2x00dev, 73, 0x18);
++	rt2800_bbp_write(rt2x00dev, 74, 0x0F);
++	rt2800_bbp_write(rt2x00dev, 75, 0x60);
++	rt2800_bbp_write(rt2x00dev, 76, 0x44);
++	rt2800_bbp_write(rt2x00dev, 77, 0x59);
++	rt2800_bbp_write(rt2x00dev, 78, 0x1E);
++	rt2800_bbp_write(rt2x00dev, 79, 0x1C);
++	rt2800_bbp_write(rt2x00dev, 80, 0x0C);
++	rt2800_bbp_write(rt2x00dev, 81, 0x3A);
++	rt2800_bbp_write(rt2x00dev, 82, 0xB6);
++	rt2800_bbp_write(rt2x00dev, 83, 0x9A);
++	rt2800_bbp_write(rt2x00dev, 84, 0x9A);
++	rt2800_bbp_write(rt2x00dev, 86, 0x38);
++	rt2800_bbp_write(rt2x00dev, 88, 0x90);
++	rt2800_bbp_write(rt2x00dev, 91, 0x04);
++	rt2800_bbp_write(rt2x00dev, 92, 0x02);
++	rt2800_bbp_write(rt2x00dev, 95, 0x9A);
++	rt2800_bbp_write(rt2x00dev, 96, 0x00);
++	rt2800_bbp_write(rt2x00dev, 103, 0xC0);
++	rt2800_bbp_write(rt2x00dev, 104, 0x92);
++	/* FIXME BBP105 owerwrite */
++	rt2800_bbp_write(rt2x00dev, 105, 0x3C);
++	rt2800_bbp_write(rt2x00dev, 106, 0x12);
++	rt2800_bbp_write(rt2x00dev, 109, 0x00);
++	rt2800_bbp_write(rt2x00dev, 134, 0x10);
++	rt2800_bbp_write(rt2x00dev, 135, 0xA6);
++	rt2800_bbp_write(rt2x00dev, 137, 0x04);
++	rt2800_bbp_write(rt2x00dev, 142, 0x30);
++	rt2800_bbp_write(rt2x00dev, 143, 0xF7);
++	rt2800_bbp_write(rt2x00dev, 160, 0xEC);
++	rt2800_bbp_write(rt2x00dev, 161, 0xC4);
++	rt2800_bbp_write(rt2x00dev, 162, 0x77);
++	rt2800_bbp_write(rt2x00dev, 163, 0xF9);
++	rt2800_bbp_write(rt2x00dev, 164, 0x00);
++	rt2800_bbp_write(rt2x00dev, 165, 0x00);
++	rt2800_bbp_write(rt2x00dev, 186, 0x00);
++	rt2800_bbp_write(rt2x00dev, 187, 0x00);
++	rt2800_bbp_write(rt2x00dev, 188, 0x00);
++	rt2800_bbp_write(rt2x00dev, 186, 0x00);
++	rt2800_bbp_write(rt2x00dev, 187, 0x01);
++	rt2800_bbp_write(rt2x00dev, 188, 0x00);
++	rt2800_bbp_write(rt2x00dev, 189, 0x00);
++
++	rt2800_bbp_write(rt2x00dev, 91, 0x06);
++	rt2800_bbp_write(rt2x00dev, 92, 0x04);
++	rt2800_bbp_write(rt2x00dev, 93, 0x54);
++	rt2800_bbp_write(rt2x00dev, 99, 0x50);
++	rt2800_bbp_write(rt2x00dev, 148, 0x84);
++	rt2800_bbp_write(rt2x00dev, 167, 0x80);
++	rt2800_bbp_write(rt2x00dev, 178, 0xFF);
++	rt2800_bbp_write(rt2x00dev, 106, 0x13);
++
++	/* BBP for G band GLRT function (BBP_128 ~ BBP_221) */
++	rt2800_bbp_glrt_write(rt2x00dev, 0, 0x00);
++	rt2800_bbp_glrt_write(rt2x00dev, 1, 0x14);
++	rt2800_bbp_glrt_write(rt2x00dev, 2, 0x20);
++	rt2800_bbp_glrt_write(rt2x00dev, 3, 0x0A);
++	rt2800_bbp_glrt_write(rt2x00dev, 10, 0x16);
++	rt2800_bbp_glrt_write(rt2x00dev, 11, 0x06);
++	rt2800_bbp_glrt_write(rt2x00dev, 12, 0x02);
++	rt2800_bbp_glrt_write(rt2x00dev, 13, 0x07);
++	rt2800_bbp_glrt_write(rt2x00dev, 14, 0x05);
++	rt2800_bbp_glrt_write(rt2x00dev, 15, 0x09);
++	rt2800_bbp_glrt_write(rt2x00dev, 16, 0x20);
++	rt2800_bbp_glrt_write(rt2x00dev, 17, 0x08);
++	rt2800_bbp_glrt_write(rt2x00dev, 18, 0x4A);
++	rt2800_bbp_glrt_write(rt2x00dev, 19, 0x00);
++	rt2800_bbp_glrt_write(rt2x00dev, 20, 0x00);
++	rt2800_bbp_glrt_write(rt2x00dev, 128, 0xE0);
++	rt2800_bbp_glrt_write(rt2x00dev, 129, 0x1F);
++	rt2800_bbp_glrt_write(rt2x00dev, 130, 0x4F);
++	rt2800_bbp_glrt_write(rt2x00dev, 131, 0x32);
++	rt2800_bbp_glrt_write(rt2x00dev, 132, 0x08);
++	rt2800_bbp_glrt_write(rt2x00dev, 133, 0x28);
++	rt2800_bbp_glrt_write(rt2x00dev, 134, 0x19);
++	rt2800_bbp_glrt_write(rt2x00dev, 135, 0x0A);
++	rt2800_bbp_glrt_write(rt2x00dev, 138, 0x16);
++	rt2800_bbp_glrt_write(rt2x00dev, 139, 0x10);
++	rt2800_bbp_glrt_write(rt2x00dev, 140, 0x10);
++	rt2800_bbp_glrt_write(rt2x00dev, 141, 0x1A);
++	rt2800_bbp_glrt_write(rt2x00dev, 142, 0x36);
++	rt2800_bbp_glrt_write(rt2x00dev, 143, 0x2C);
++	rt2800_bbp_glrt_write(rt2x00dev, 144, 0x26);
++	rt2800_bbp_glrt_write(rt2x00dev, 145, 0x24);
++	rt2800_bbp_glrt_write(rt2x00dev, 146, 0x42);
++	rt2800_bbp_glrt_write(rt2x00dev, 147, 0x40);
++	rt2800_bbp_glrt_write(rt2x00dev, 148, 0x30);
++	rt2800_bbp_glrt_write(rt2x00dev, 149, 0x29);
++	rt2800_bbp_glrt_write(rt2x00dev, 150, 0x4C);
++	rt2800_bbp_glrt_write(rt2x00dev, 151, 0x46);
++	rt2800_bbp_glrt_write(rt2x00dev, 152, 0x3D);
++	rt2800_bbp_glrt_write(rt2x00dev, 153, 0x40);
++	rt2800_bbp_glrt_write(rt2x00dev, 154, 0x3E);
++	rt2800_bbp_glrt_write(rt2x00dev, 155, 0x38);
++	rt2800_bbp_glrt_write(rt2x00dev, 156, 0x3D);
++	rt2800_bbp_glrt_write(rt2x00dev, 157, 0x2F);
++	rt2800_bbp_glrt_write(rt2x00dev, 158, 0x3C);
++	rt2800_bbp_glrt_write(rt2x00dev, 159, 0x34);
++	rt2800_bbp_glrt_write(rt2x00dev, 160, 0x2C);
++	rt2800_bbp_glrt_write(rt2x00dev, 161, 0x2F);
++	rt2800_bbp_glrt_write(rt2x00dev, 162, 0x3C);
++	rt2800_bbp_glrt_write(rt2x00dev, 163, 0x35);
++	rt2800_bbp_glrt_write(rt2x00dev, 164, 0x2E);
++	rt2800_bbp_glrt_write(rt2x00dev, 165, 0x2F);
++	rt2800_bbp_glrt_write(rt2x00dev, 166, 0x49);
++	rt2800_bbp_glrt_write(rt2x00dev, 167, 0x41);
++	rt2800_bbp_glrt_write(rt2x00dev, 168, 0x36);
++	rt2800_bbp_glrt_write(rt2x00dev, 169, 0x39);
++	rt2800_bbp_glrt_write(rt2x00dev, 170, 0x30);
++	rt2800_bbp_glrt_write(rt2x00dev, 171, 0x30);
++	rt2800_bbp_glrt_write(rt2x00dev, 172, 0x0E);
++	rt2800_bbp_glrt_write(rt2x00dev, 173, 0x0D);
++	rt2800_bbp_glrt_write(rt2x00dev, 174, 0x28);
++	rt2800_bbp_glrt_write(rt2x00dev, 175, 0x21);
++	rt2800_bbp_glrt_write(rt2x00dev, 176, 0x1C);
++	rt2800_bbp_glrt_write(rt2x00dev, 177, 0x16);
++	rt2800_bbp_glrt_write(rt2x00dev, 178, 0x50);
++	rt2800_bbp_glrt_write(rt2x00dev, 179, 0x4A);
++	rt2800_bbp_glrt_write(rt2x00dev, 180, 0x43);
++	rt2800_bbp_glrt_write(rt2x00dev, 181, 0x50);
++	rt2800_bbp_glrt_write(rt2x00dev, 182, 0x10);
++	rt2800_bbp_glrt_write(rt2x00dev, 183, 0x10);
++	rt2800_bbp_glrt_write(rt2x00dev, 184, 0x10);
++	rt2800_bbp_glrt_write(rt2x00dev, 185, 0x10);
++	rt2800_bbp_glrt_write(rt2x00dev, 200, 0x7D);
++	rt2800_bbp_glrt_write(rt2x00dev, 201, 0x14);
++	rt2800_bbp_glrt_write(rt2x00dev, 202, 0x32);
++	rt2800_bbp_glrt_write(rt2x00dev, 203, 0x2C);
++	rt2800_bbp_glrt_write(rt2x00dev, 204, 0x36);
++	rt2800_bbp_glrt_write(rt2x00dev, 205, 0x4C);
++	rt2800_bbp_glrt_write(rt2x00dev, 206, 0x43);
++	rt2800_bbp_glrt_write(rt2x00dev, 207, 0x2C);
++	rt2800_bbp_glrt_write(rt2x00dev, 208, 0x2E);
++	rt2800_bbp_glrt_write(rt2x00dev, 209, 0x36);
++	rt2800_bbp_glrt_write(rt2x00dev, 210, 0x30);
++	rt2800_bbp_glrt_write(rt2x00dev, 211, 0x6E);
++
++	/* BBP for G band DCOC function */
++	rt2800_bbp_dcoc_write(rt2x00dev, 140, 0x0C);
++	rt2800_bbp_dcoc_write(rt2x00dev, 141, 0x00);
++	rt2800_bbp_dcoc_write(rt2x00dev, 142, 0x10);
++	rt2800_bbp_dcoc_write(rt2x00dev, 143, 0x10);
++	rt2800_bbp_dcoc_write(rt2x00dev, 144, 0x10);
++	rt2800_bbp_dcoc_write(rt2x00dev, 145, 0x10);
++	rt2800_bbp_dcoc_write(rt2x00dev, 146, 0x08);
++	rt2800_bbp_dcoc_write(rt2x00dev, 147, 0x40);
++	rt2800_bbp_dcoc_write(rt2x00dev, 148, 0x04);
++	rt2800_bbp_dcoc_write(rt2x00dev, 149, 0x04);
++	rt2800_bbp_dcoc_write(rt2x00dev, 150, 0x08);
++	rt2800_bbp_dcoc_write(rt2x00dev, 151, 0x08);
++	rt2800_bbp_dcoc_write(rt2x00dev, 152, 0x03);
++	rt2800_bbp_dcoc_write(rt2x00dev, 153, 0x03);
++	rt2800_bbp_dcoc_write(rt2x00dev, 154, 0x03);
++	rt2800_bbp_dcoc_write(rt2x00dev, 155, 0x02);
++	rt2800_bbp_dcoc_write(rt2x00dev, 156, 0x40);
++	rt2800_bbp_dcoc_write(rt2x00dev, 157, 0x40);
++	rt2800_bbp_dcoc_write(rt2x00dev, 158, 0x64);
++	rt2800_bbp_dcoc_write(rt2x00dev, 159, 0x64);
++
++	rt2800_bbp4_mac_if_ctrl(rt2x00dev);
++}
++
+ static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
+ {
+ 	unsigned int i;
+@@ -5830,6 +6556,9 @@ static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
+ 	case RT5592:
+ 		rt2800_init_bbp_5592(rt2x00dev);
+ 		return;
++	case RT6352:
++		rt2800_init_bbp_6352(rt2x00dev);
++		break;
+ 	}
+ 
+ 	for (i = 0; i < EEPROM_BBP_SIZE; i++) {
+@@ -6901,6 +7630,615 @@ static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev)
+ 	rt2800_led_open_drain_enable(rt2x00dev);
+ }
+ 
++static void rt2800_bbp_core_soft_reset(struct rt2x00_dev *rt2x00dev,
++				       bool set_bw, bool is_ht40)
++{
++	u8 bbp_val;
++
++	rt2800_bbp_read(rt2x00dev, 21, &bbp_val);
++	bbp_val |= 0x1;
++	rt2800_bbp_write(rt2x00dev, 21, bbp_val);
++	usleep_range(100, 200);
++
++	if (set_bw) {
++		rt2800_bbp_read(rt2x00dev, 4, &bbp_val);
++		rt2x00_set_field8(&bbp_val, BBP4_BANDWIDTH, 2 * is_ht40);
++		rt2800_bbp_write(rt2x00dev, 4, bbp_val);
++		usleep_range(100, 200);
++	}
++
++	rt2800_bbp_read(rt2x00dev, 21, &bbp_val);
++	bbp_val &= (~0x1);
++	rt2800_bbp_write(rt2x00dev, 21, bbp_val);
++	usleep_range(100, 200);
++}
++
++static int rt2800_rf_lp_config(struct rt2x00_dev *rt2x00dev, bool btxcal)
++{
++	u8 rf_val;
++
++	if (btxcal)
++		rt2800_register_write(rt2x00dev, RF_CONTROL0, 0x04);
++	else
++		rt2800_register_write(rt2x00dev, RF_CONTROL0, 0x02);
++
++	rt2800_register_write(rt2x00dev, RF_BYPASS0, 0x06);
++
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 17, &rf_val);
++	rf_val |= 0x80;
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 17, rf_val);
++
++	if (btxcal) {
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 18, 0xC1);
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 19, 0x20);
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 20, 0x02);
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 3, &rf_val);
++		rf_val &= (~0x3F);
++		rf_val |= 0x3F;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 3, rf_val);
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 4, &rf_val);
++		rf_val &= (~0x3F);
++		rf_val |= 0x3F;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 4, rf_val);
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 5, 0x31);
++	} else {
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 18, 0xF1);
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 19, 0x18);
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 20, 0x02);
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 3, &rf_val);
++		rf_val &= (~0x3F);
++		rf_val |= 0x34;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 3, rf_val);
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 4, &rf_val);
++		rf_val &= (~0x3F);
++		rf_val |= 0x34;
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 4, rf_val);
++	}
++
++	return 0;
++}
++
++static char rt2800_lp_tx_filter_bw_cal(struct rt2x00_dev *rt2x00dev)
++{
++	unsigned int cnt;
++	u8 bbp_val;
++	char cal_val;
++
++	rt2800_bbp_dcoc_write(rt2x00dev, 0, 0x82);
++
++	cnt = 0;
++	do {
++		usleep_range(500, 2000);
++		rt2800_bbp_read(rt2x00dev, 159, &bbp_val);
++		if (bbp_val == 0x02 || cnt == 20)
++			break;
++
++		cnt++;
++	} while (cnt < 20);
++
++	rt2800_bbp_dcoc_read(rt2x00dev, 0x39, &bbp_val);
++	cal_val = bbp_val & 0x7F;
++	if (cal_val >= 0x40)
++		cal_val -= 128;
++
++	return cal_val;
++}
++
++static void rt2800_bw_filter_calibration(struct rt2x00_dev *rt2x00dev,
++					 bool btxcal)
++{
++	struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
++	u8 tx_agc_fc = 0, rx_agc_fc = 0, cmm_agc_fc;
++	u8 filter_target;
++	u8 tx_filter_target_20m = 0x09, tx_filter_target_40m = 0x02;
++	u8 rx_filter_target_20m = 0x27, rx_filter_target_40m = 0x31;
++	int loop = 0, is_ht40, cnt;
++	u8 bbp_val, rf_val;
++	char cal_r32_init, cal_r32_val, cal_diff;
++	u8 saverfb5r00, saverfb5r01, saverfb5r03, saverfb5r04, saverfb5r05;
++	u8 saverfb5r06, saverfb5r07;
++	u8 saverfb5r08, saverfb5r17, saverfb5r18, saverfb5r19, saverfb5r20;
++	u8 saverfb5r37, saverfb5r38, saverfb5r39, saverfb5r40, saverfb5r41;
++	u8 saverfb5r42, saverfb5r43, saverfb5r44, saverfb5r45, saverfb5r46;
++	u8 saverfb5r58, saverfb5r59;
++	u8 savebbp159r0, savebbp159r2, savebbpr23;
++	u32 MAC_RF_CONTROL0, MAC_RF_BYPASS0;
++
++	/* Save MAC registers */
++	rt2800_register_read(rt2x00dev, RF_CONTROL0, &MAC_RF_CONTROL0);
++	rt2800_register_read(rt2x00dev, RF_BYPASS0, &MAC_RF_BYPASS0);
++
++	/* save BBP registers */
++	rt2800_bbp_read(rt2x00dev, 23, &savebbpr23);
++
++	rt2800_bbp_dcoc_read(rt2x00dev, 0, &savebbp159r0);
++	rt2800_bbp_dcoc_read(rt2x00dev, 2, &savebbp159r2);
++
++	/* Save RF registers */
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 0, &saverfb5r00);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 1, &saverfb5r01);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 3, &saverfb5r03);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 4, &saverfb5r04);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 5, &saverfb5r05);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 6, &saverfb5r06);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 7, &saverfb5r07);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 8, &saverfb5r08);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 17, &saverfb5r17);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 18, &saverfb5r18);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 19, &saverfb5r19);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 20, &saverfb5r20);
++
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 37, &saverfb5r37);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 38, &saverfb5r38);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 39, &saverfb5r39);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 40, &saverfb5r40);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 41, &saverfb5r41);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 42, &saverfb5r42);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 43, &saverfb5r43);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 44, &saverfb5r44);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 45, &saverfb5r45);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 46, &saverfb5r46);
++
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 58, &saverfb5r58);
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 59, &saverfb5r59);
++
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 0, &rf_val);
++	rf_val |= 0x3;
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 0, rf_val);
++
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 1, &rf_val);
++	rf_val |= 0x1;
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 1, rf_val);
++
++	cnt = 0;
++	do {
++		usleep_range(500, 2000);
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 1, &rf_val);
++		if (((rf_val & 0x1) == 0x00) || (cnt == 40))
++			break;
++		cnt++;
++	} while (cnt < 40);
++
++	rt2800_rfcsr_read_bank(rt2x00dev, 5, 0, &rf_val);
++	rf_val &= (~0x3);
++	rf_val |= 0x1;
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 0, rf_val);
++
++	/* I-3 */
++	rt2800_bbp_read(rt2x00dev, 23, &bbp_val);
++	bbp_val &= (~0x1F);
++	bbp_val |= 0x10;
++	rt2800_bbp_write(rt2x00dev, 23, bbp_val);
++
++	do {
++		/* I-4,5,6,7,8,9 */
++		if (loop == 0) {
++			is_ht40 = false;
++
++			if (btxcal)
++				filter_target = tx_filter_target_20m;
++			else
++				filter_target = rx_filter_target_20m;
++		} else {
++			is_ht40 = true;
++
++			if (btxcal)
++				filter_target = tx_filter_target_40m;
++			else
++				filter_target = rx_filter_target_40m;
++		}
++
++		rt2800_rfcsr_read_bank(rt2x00dev, 5, 8, &rf_val);
++		rf_val &= (~0x04);
++		if (loop == 1)
++			rf_val |= 0x4;
++
++		rt2800_rfcsr_write_bank(rt2x00dev, 5, 8, rf_val);
++
++		rt2800_bbp_core_soft_reset(rt2x00dev, true, is_ht40);
++
++		rt2800_rf_lp_config(rt2x00dev, btxcal);
++		if (btxcal) {
++			tx_agc_fc = 0;
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 58, &rf_val);
++			rf_val &= (~0x7F);
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, rf_val);
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 59, &rf_val);
++			rf_val &= (~0x7F);
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, rf_val);
++		} else {
++			rx_agc_fc = 0;
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 6, &rf_val);
++			rf_val &= (~0x7F);
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, rf_val);
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 7, &rf_val);
++			rf_val &= (~0x7F);
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, rf_val);
++		}
++
++		usleep_range(1000, 2000);
++
++		rt2800_bbp_dcoc_read(rt2x00dev, 2, &bbp_val);
++		bbp_val &= (~0x6);
++		rt2800_bbp_dcoc_write(rt2x00dev, 2, bbp_val);
++
++		rt2800_bbp_core_soft_reset(rt2x00dev, false, is_ht40);
++
++		cal_r32_init = rt2800_lp_tx_filter_bw_cal(rt2x00dev);
++
++		rt2800_bbp_dcoc_read(rt2x00dev, 2, &bbp_val);
++		bbp_val |= 0x6;
++		rt2800_bbp_dcoc_write(rt2x00dev, 2, bbp_val);
++do_cal:
++		if (btxcal) {
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 58, &rf_val);
++			rf_val &= (~0x7F);
++			rf_val |= tx_agc_fc;
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, rf_val);
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 59, &rf_val);
++			rf_val &= (~0x7F);
++			rf_val |= tx_agc_fc;
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, rf_val);
++		} else {
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 6, &rf_val);
++			rf_val &= (~0x7F);
++			rf_val |= rx_agc_fc;
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, rf_val);
++			rt2800_rfcsr_read_bank(rt2x00dev, 5, 7, &rf_val);
++			rf_val &= (~0x7F);
++			rf_val |= rx_agc_fc;
++			rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, rf_val);
++		}
++
++		usleep_range(500, 1000);
++
++		rt2800_bbp_core_soft_reset(rt2x00dev, false, is_ht40);
++
++		cal_r32_val = rt2800_lp_tx_filter_bw_cal(rt2x00dev);
++
++		cal_diff = cal_r32_init - cal_r32_val;
++
++		if (btxcal)
++			cmm_agc_fc = tx_agc_fc;
++		else
++			cmm_agc_fc = rx_agc_fc;
++
++		if (((cal_diff > filter_target) && (cmm_agc_fc == 0)) ||
++		    ((cal_diff < filter_target) && (cmm_agc_fc == 0x3f))) {
++			if (btxcal)
++				tx_agc_fc = 0;
++			else
++				rx_agc_fc = 0;
++		} else if ((cal_diff <= filter_target) && (cmm_agc_fc < 0x3f)) {
++			if (btxcal)
++				tx_agc_fc++;
++			else
++				rx_agc_fc++;
++			goto do_cal;
++		}
++
++		if (btxcal) {
++			if (loop == 0)
++				drv_data->tx_calibration_bw20 = tx_agc_fc;
++			else
++				drv_data->tx_calibration_bw40 = tx_agc_fc;
++		} else {
++			if (loop == 0)
++				drv_data->rx_calibration_bw20 = rx_agc_fc;
++			else
++				drv_data->rx_calibration_bw40 = rx_agc_fc;
++		}
++
++		loop++;
++	} while (loop <= 1);
++
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 0, saverfb5r00);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 1, saverfb5r01);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 3, saverfb5r03);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 4, saverfb5r04);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 5, saverfb5r05);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, saverfb5r06);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, saverfb5r07);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 8, saverfb5r08);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 17, saverfb5r17);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 18, saverfb5r18);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 19, saverfb5r19);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 20, saverfb5r20);
++
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 37, saverfb5r37);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 38, saverfb5r38);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 39, saverfb5r39);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 40, saverfb5r40);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 41, saverfb5r41);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 42, saverfb5r42);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 43, saverfb5r43);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 44, saverfb5r44);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 45, saverfb5r45);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 46, saverfb5r46);
++
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, saverfb5r58);
++	rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, saverfb5r59);
++
++	rt2800_bbp_write(rt2x00dev, 23, savebbpr23);
++
++	rt2800_bbp_dcoc_write(rt2x00dev, 0, savebbp159r0);
++	rt2800_bbp_dcoc_write(rt2x00dev, 2, savebbp159r2);
++
++	rt2800_bbp_read(rt2x00dev, 4, &bbp_val);
++	rt2x00_set_field8(&bbp_val, BBP4_BANDWIDTH,
++			  2 * test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags));
++	rt2800_bbp_write(rt2x00dev, 4, bbp_val);
++
++	rt2800_register_write(rt2x00dev, RF_CONTROL0, MAC_RF_CONTROL0);
++	rt2800_register_write(rt2x00dev, RF_BYPASS0, MAC_RF_BYPASS0);
++}
++
++static void rt2800_init_rfcsr_6352(struct rt2x00_dev *rt2x00dev)
++{
++	/* Initialize RF central register to default value */
++	rt2800_rfcsr_write(rt2x00dev, 0, 0x02);
++	rt2800_rfcsr_write(rt2x00dev, 1, 0x03);
++	rt2800_rfcsr_write(rt2x00dev, 2, 0x33);
++	rt2800_rfcsr_write(rt2x00dev, 3, 0xFF);
++	rt2800_rfcsr_write(rt2x00dev, 4, 0x0C);
++	rt2800_rfcsr_write(rt2x00dev, 5, 0x40);
++	rt2800_rfcsr_write(rt2x00dev, 6, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 8, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 9, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 10, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 11, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 12, rt2x00dev->freq_offset);
++	rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 14, 0x40);
++	rt2800_rfcsr_write(rt2x00dev, 15, 0x22);
++	rt2800_rfcsr_write(rt2x00dev, 16, 0x4C);
++	rt2800_rfcsr_write(rt2x00dev, 17, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 18, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 20, 0xA0);
++	rt2800_rfcsr_write(rt2x00dev, 21, 0x12);
++	rt2800_rfcsr_write(rt2x00dev, 22, 0x07);
++	rt2800_rfcsr_write(rt2x00dev, 23, 0x13);
++	rt2800_rfcsr_write(rt2x00dev, 24, 0xFE);
++	rt2800_rfcsr_write(rt2x00dev, 25, 0x24);
++	rt2800_rfcsr_write(rt2x00dev, 26, 0x7A);
++	rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 29, 0x05);
++	rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 32, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 34, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 35, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 37, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 38, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 39, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 40, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 41, 0xD0);
++	rt2800_rfcsr_write(rt2x00dev, 42, 0x5B);
++	rt2800_rfcsr_write(rt2x00dev, 43, 0x00);
++
++	rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
++	if (rt2800_clk_is_20mhz(rt2x00dev))
++		rt2800_rfcsr_write(rt2x00dev, 13, 0x03);
++	else
++		rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 14, 0x7C);
++	rt2800_rfcsr_write(rt2x00dev, 16, 0x80);
++	rt2800_rfcsr_write(rt2x00dev, 17, 0x99);
++	rt2800_rfcsr_write(rt2x00dev, 18, 0x99);
++	rt2800_rfcsr_write(rt2x00dev, 19, 0x09);
++	rt2800_rfcsr_write(rt2x00dev, 20, 0x50);
++	rt2800_rfcsr_write(rt2x00dev, 21, 0xB0);
++	rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 23, 0x06);
++	rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 25, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 26, 0x5D);
++	rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
++	rt2800_rfcsr_write(rt2x00dev, 28, 0x61);
++	rt2800_rfcsr_write(rt2x00dev, 29, 0xB5);
++	rt2800_rfcsr_write(rt2x00dev, 43, 0x02);
++
++	rt2800_rfcsr_write(rt2x00dev, 28, 0x62);
++	rt2800_rfcsr_write(rt2x00dev, 29, 0xAD);
++	rt2800_rfcsr_write(rt2x00dev, 39, 0x80);
++
++	/* Initialize RF channel register to default value */
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 0, 0x03);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 1, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 2, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 3, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 4, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 5, 0x08);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 6, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 7, 0x51);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 8, 0x53);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 9, 0x16);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 10, 0x61);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 11, 0x53);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 12, 0x22);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 13, 0x3D);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x06);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 15, 0x13);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 16, 0x22);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 17, 0x27);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 18, 0x02);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 19, 0xA7);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 20, 0x01);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 21, 0x52);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 22, 0x80);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 23, 0xB3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 24, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 25, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 26, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 27, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 28, 0x5C);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 29, 0x6B);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 30, 0x6B);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 31, 0x31);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 32, 0x5D);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 33, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 34, 0xE6);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 35, 0x55);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 36, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 37, 0xBB);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 38, 0xB3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 39, 0xB3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 40, 0x03);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 41, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 42, 0x00);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0xB3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xD3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xD5);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 46, 0x07);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x68);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 48, 0xEF);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 49, 0x1C);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 54, 0x07);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0xA8);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 56, 0x85);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 57, 0x10);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 58, 0x07);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 59, 0x6A);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 60, 0x85);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 61, 0x10);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 62, 0x1C);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 63, 0x00);
++
++	rt2800_rfcsr_write_bank(rt2x00dev, 6, 45, 0xC5);
++
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 9, 0x47);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 10, 0x71);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 11, 0x33);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x0E);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 17, 0x23);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 19, 0xA4);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 20, 0x02);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 21, 0x12);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 28, 0x1C);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 29, 0xEB);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 32, 0x7D);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 34, 0xD6);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 36, 0x08);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 38, 0xB4);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0xD3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xB3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xD5);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 46, 0x27);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x69);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 48, 0xFF);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 54, 0x20);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x66);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 56, 0xFF);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 57, 0x1C);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 58, 0x20);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 59, 0x6B);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 60, 0xF7);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 61, 0x09);
++
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 10, 0x51);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x06);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 19, 0xA7);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 28, 0x2C);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x64);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 8, 0x51);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 9, 0x36);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 11, 0x53);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x16);
++
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x6C);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 48, 0xFC);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 49, 0x1F);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 54, 0x27);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x66);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 59, 0x6B);
++
++	/* Initialize RF channel register for DRQFN */
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0xD3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xE3);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xE5);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x28);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x68);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 56, 0xF7);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 58, 0x02);
++	rt2800_rfcsr_write_chanreg(rt2x00dev, 60, 0xC7);
++
++	/* Initialize RF DC calibration register to default value */
++	rt2800_rfcsr_write_dccal(rt2x00dev, 0, 0x47);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 1, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 2, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 3, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 4, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 5, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 6, 0x10);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 7, 0x10);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 8, 0x04);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 9, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 10, 0x07);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 11, 0x01);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 12, 0x07);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 13, 0x07);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 14, 0x07);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 15, 0x20);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 16, 0x22);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 17, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 18, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 19, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 20, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 21, 0xF1);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 22, 0x11);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 23, 0x02);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 24, 0x41);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 25, 0x20);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 26, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 27, 0xD7);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 28, 0xA2);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 29, 0x20);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 30, 0x49);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 31, 0x20);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 32, 0x04);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 33, 0xF1);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 34, 0xA1);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 35, 0x01);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 41, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 42, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 43, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 44, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 45, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 46, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 47, 0x3E);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 48, 0x3D);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 49, 0x3E);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 50, 0x3D);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 51, 0x3E);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 52, 0x3D);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 53, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 54, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 55, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 56, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 57, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x10);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x10);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 60, 0x0A);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 61, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 62, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 63, 0x00);
++
++	rt2800_rfcsr_write_dccal(rt2x00dev, 3, 0x08);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 4, 0x04);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 5, 0x20);
++
++	rt2800_rfcsr_write_dccal(rt2x00dev, 5, 0x00);
++	rt2800_rfcsr_write_dccal(rt2x00dev, 17, 0x7C);
++
++	rt2800_bw_filter_calibration(rt2x00dev, true);
++	rt2800_bw_filter_calibration(rt2x00dev, false);
++}
++
+ static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
+ {
+ 	if (rt2800_is_305x_soc(rt2x00dev)) {
+@@ -6941,6 +8279,9 @@ static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
+ 	case RT5592:
+ 		rt2800_init_rfcsr_5592(rt2x00dev);
+ 		break;
++	case RT6352:
++		rt2800_init_rfcsr_6352(rt2x00dev);
++		break;
+ 	}
+ }
+ 
+@@ -7307,7 +8648,8 @@ static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
+ 	 */
+ 	if (rt2x00_rt(rt2x00dev, RT3290) ||
+ 	    rt2x00_rt(rt2x00dev, RT5390) ||
+-	    rt2x00_rt(rt2x00dev, RT5392))
++	    rt2x00_rt(rt2x00dev, RT5392) ||
++	    rt2x00_rt(rt2x00dev, RT6352))
+ 		rt2800_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf);
+ 	else if (rt2x00_rt(rt2x00dev, RT3352))
+ 		rf = RF3322;
+@@ -7339,6 +8681,7 @@ static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
+ 	case RF5390:
+ 	case RF5392:
+ 	case RF5592:
++	case RF7620:
+ 		break;
+ 	default:
+ 		rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n",
+@@ -7746,6 +9089,23 @@ static const struct rf_channel rf_vals_5592_xtal40[] = {
+ 	{196, 83, 0, 12, 1},
+ };
+ 
++static const struct rf_channel rf_vals_7620[] = {
++	{1, 0x50, 0x99, 0x99, 1},
++	{2, 0x50, 0x44, 0x44, 2},
++	{3, 0x50, 0xEE, 0xEE, 2},
++	{4, 0x50, 0x99, 0x99, 3},
++	{5, 0x51, 0x44, 0x44, 0},
++	{6, 0x51, 0xEE, 0xEE, 0},
++	{7, 0x51, 0x99, 0x99, 1},
++	{8, 0x51, 0x44, 0x44, 2},
++	{9, 0x51, 0xEE, 0xEE, 2},
++	{10, 0x51, 0x99, 0x99, 3},
++	{11, 0x52, 0x44, 0x44, 0},
++	{12, 0x52, 0xEE, 0xEE, 0},
++	{13, 0x52, 0x99, 0x99, 1},
++	{14, 0x52, 0x33, 0x33, 3},
++};
++
+ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
+ {
+ 	struct hw_mode_spec *spec = &rt2x00dev->spec;
+@@ -7849,6 +9209,11 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
+ 			spec->channels = rf_vals_3x;
+ 		break;
+ 
++	case RF7620:
++		spec->num_channels = ARRAY_SIZE(rf_vals_7620);
++		spec->channels = rf_vals_7620;
++		break;
++
+ 	case RF3052:
+ 	case RF3053:
+ 		spec->num_channels = ARRAY_SIZE(rf_vals_3x);
+@@ -7980,6 +9345,7 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
+ 	case RF5390:
+ 	case RF5392:
+ 	case RF5592:
++	case RF7620:
+ 		__set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags);
+ 		break;
+ 	}
+@@ -8024,6 +9390,9 @@ static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev)
+ 		return -ENODEV;
+ 	}
+ 
++	if (rt == RT5390 && rt2x00_is_soc(rt2x00dev))
++		rt = RT6352;
++
+ 	rt2x00_set_rt(rt2x00dev, rt, rev);
+ 
+ 	return 0;
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+index d9ef260d542a..f357531d9488 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+@@ -33,6 +33,10 @@
+ struct rt2800_drv_data {
+ 	u8 calibration_bw20;
+ 	u8 calibration_bw40;
++	char rx_calibration_bw20;
++	char rx_calibration_bw40;
++	char tx_calibration_bw20;
++	char tx_calibration_bw40;
+ 	u8 bbp25;
+ 	u8 bbp26;
+ 	u8 txmixer_gain_24g;
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+index ce340bfd71a0..8fdd2f9726ee 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
++++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+@@ -174,6 +174,7 @@ struct rt2x00_chip {
+ #define RT5390		0x5390  /* 2.4GHz */
+ #define RT5392		0x5392  /* 2.4GHz */
+ #define RT5592		0x5592
++#define RT6352		0x6352  /* WSOC 2.4GHz */
+ 
+ 	u16 rf;
+ 	u16 rev;
+-- 
+2.12.1
+

+ 54 - 0
package/kernel/mac80211/patches/021-01-rt2800-fix-LNA-gain-assignment-for-MT7620.patch

@@ -0,0 +1,54 @@
+From 0109238d62a99ea779a7e28e21868118e7b8d69d Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Mon, 10 Apr 2017 14:28:14 +0200
+Subject: [PATCH 1/2] rt2800: fix LNA gain assignment for MT7620
+To: Stanislaw Gruszka <sgruszka@redhat.com>
+Cc: Helmut Schaa <helmut.schaa@googlemail.com>,
+    linux-wireless@vger.kernel.org,
+    Kalle Valo <kvalo@codeaurora.org>
+
+The base value used for MT7620 differs from Rt5392 which resulted in
+quite bad RX signal quality. Fix this by using the correct base value as
+well as the LNA calibration values for HT20.
+
+Reported-by: Tom Psyborg <pozega.tomislav@gmail.com>
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 18 ++++++++++++++++--
+ 1 file changed, 16 insertions(+), 2 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index ba06ac2d876d..7135519a638c 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -3806,11 +3806,25 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
+ 	}
+ 
+ 	if (rt2x00_rt(rt2x00dev, RT5592) || rt2x00_rt(rt2x00dev, RT6352)) {
++		reg = 0x10;
++		if (!conf_is_ht40(conf)) {
++			if (rt2x00_rt(rt2x00dev, RT6352) &&
++			    rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
++				reg |= 0x5;
++			} else {
++				reg |= 0xa;
++			}
++		}
+ 		rt2800_bbp_write(rt2x00dev, 195, 141);
+-		rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a);
++		rt2800_bbp_write(rt2x00dev, 196, reg);
+ 
+ 		/* AGC init */
+-		reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2 * rt2x00dev->lna_gain;
++		if (rt2x00_rt(rt2x00dev, RT6352))
++			reg = 0x04;
++		else
++			reg = rf->channel <= 14 ? 0x1c : 0x24;
++
++		reg += 2 * rt2x00dev->lna_gain;
+ 		rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
+ 
+ 		rt2800_iq_calibrate(rt2x00dev, rf->channel);
+-- 
+2.12.2
+

+ 34 - 0
package/kernel/mac80211/patches/021-02-rt2800-do-VCO-calibration-after-programming-ALC.patch

@@ -0,0 +1,34 @@
+From feb608c7986c14bab153f31f8e96f251072e6578 Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Mon, 10 Apr 2017 15:33:20 +0200
+Subject: [PATCH 2/2] rt2800: do VCO calibration after programming ALC
+To: Stanislaw Gruszka <sgruszka@redhat.com>
+Cc: Helmut Schaa <helmut.schaa@googlemail.com>,
+    linux-wireless@vger.kernel.org,
+    Kalle Valo <kvalo@codeaurora.org>
+
+Scanning fails if we don't do VCO calibration every time.
+The vendor driver duplicates the VCO calibration function into the
+channel switching logic, we can do the same with less duplication.
+
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 7135519a638c..870bf315f98b 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -3407,6 +3407,8 @@ static void rt2800_config_alc(struct rt2x00_dev *rt2x00dev,
+ 			rt2800_rfcsr_write(rt2x00dev, 42, 0x5b);
+ 	}
+ 	rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, mac_sys_ctrl);
++
++	rt2800_vco_calibration(rt2x00dev);
+ }
+ 
+ static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev,
+-- 
+2.12.2
+

+ 50 - 0
package/kernel/mac80211/patches/021-03-rt2800-fix-mt7620-vco-calibration-registers.patch

@@ -0,0 +1,50 @@
+From 02c452f317b4a4d06c433c294e66896a389731c1 Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Tue, 18 Apr 2017 11:09:53 +0200
+Subject: [PATCH] rt2800: fix mt7620 vco calibration registers
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+To: Stanislaw Gruszka <sgruszka@redhat.com>
+Cc: Helmut Schaa <helmut.schaa@googlemail.com>,
+    linux-wireless@vger.kernel.org,
+    Kalle Valo <kvalo@codeaurora.org>,
+    Tom Psyborg <pozega.tomislav@gmail.com>
+
+Use register values from init LNA function instead of the ones from
+restore LNA function. Apply register values based on rx path
+configuration.
+
+Signed-off-by: Tomislav Požega <pozega.tomislav@gmail.com>
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 870bf315f98b..86cffee6876a 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -4932,7 +4932,7 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
+ 	rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
+ 
+ 	if (rt2x00_rt(rt2x00dev, RT6352)) {
+-		if (rt2x00dev->default_ant.tx_chain_num == 1) {
++		if (rt2x00dev->default_ant.rx_chain_num == 1) {
+ 			rt2800_bbp_write(rt2x00dev, 91, 0x07);
+ 			rt2800_bbp_write(rt2x00dev, 95, 0x1A);
+ 			rt2800_bbp_write(rt2x00dev, 195, 128);
+@@ -4953,8 +4953,8 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
+ 		}
+ 
+ 		if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
+-			rt2800_bbp_write(rt2x00dev, 75, 0x60);
+-			rt2800_bbp_write(rt2x00dev, 76, 0x44);
++			rt2800_bbp_write(rt2x00dev, 75, 0x68);
++			rt2800_bbp_write(rt2x00dev, 76, 0x4C);
+ 			rt2800_bbp_write(rt2x00dev, 79, 0x1C);
+ 			rt2800_bbp_write(rt2x00dev, 80, 0x0C);
+ 			rt2800_bbp_write(rt2x00dev, 82, 0xB6);
+-- 
+2.12.2
+

+ 41 - 0
package/kernel/mac80211/patches/021-04-rt2800-fix-mt7620-E2-channel-registers.patch

@@ -0,0 +1,41 @@
+From c426cb0ed15ee12dfdc8c53ddd1449ac617023cf Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Tue, 18 Apr 2017 11:45:37 +0200
+Subject: [PATCH] rt2800: fix mt7620 E2 channel registers
+To: Stanislaw Gruszka <sgruszka@redhat.com>
+Cc: Helmut Schaa <helmut.schaa@googlemail.com>,
+    linux-wireless@vger.kernel.org,
+    Kalle Valo <kvalo@codeaurora.org>,
+    Tom Psyborg <pozega.tomislav@gmail.com>
+
+From: Tomislav Požega <pozega.tomislav@gmail.com>
+
+update RF register 47 and 54 values according to vendor driver
+
+Signed-off-by: Tomislav Požega <pozega.tomislav@gmail.com>
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+---
+ drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+index 86cffee6876a..8585cdc3de53 100644
+--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
++++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+@@ -8145,9 +8145,11 @@ static void rt2800_init_rfcsr_6352(struct rt2x00_dev *rt2x00dev)
+ 	rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xB3);
+ 	rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xD5);
+ 	rt2800_rfcsr_write_chanreg(rt2x00dev, 46, 0x27);
+-	rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x69);
++	rt2800_rfcsr_write_bank(rt2x00dev, 4, 47, 0x67);
++	rt2800_rfcsr_write_bank(rt2x00dev, 6, 47, 0x69);
+ 	rt2800_rfcsr_write_chanreg(rt2x00dev, 48, 0xFF);
+-	rt2800_rfcsr_write_chanreg(rt2x00dev, 54, 0x20);
++	rt2800_rfcsr_write_bank(rt2x00dev, 4, 54, 0x27);
++	rt2800_rfcsr_write_bank(rt2x00dev, 6, 54, 0x20);
+ 	rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x66);
+ 	rt2800_rfcsr_write_chanreg(rt2x00dev, 56, 0xFF);
+ 	rt2800_rfcsr_write_chanreg(rt2x00dev, 57, 0x1C);
+-- 
+2.12.2
+

+ 1 - 1
package/kernel/mac80211/patches/030-rt2x00_options.patch

@@ -29,7 +29,7 @@
  config RT2X00_LIB_SOC
 -	tristate
 +	tristate "RT2x00 SoC support"
-+	depends on SOC_RT288X || SOC_RT305X
++	depends on SOC_RT288X || SOC_RT305X || SOC_MT7620
  	depends on m
  	select RT2X00_LIB
  

+ 0 - 9
package/kernel/mac80211/patches/040-brcmutil_option.patch

@@ -1,9 +0,0 @@
---- a/drivers/net/wireless/broadcom/brcm80211/Kconfig
-+++ b/drivers/net/wireless/broadcom/brcm80211/Kconfig
-@@ -1,5 +1,5 @@
- config BRCMUTIL
--	tristate
-+	tristate "Broadcom 802.11 driver utility functions"
- 	depends on m
- 
- config BRCMSMAC

+ 0 - 52
package/kernel/mac80211/patches/318-0001-brcmfmac-check-brcmf_bus_get_memdump-result-for-erro.patch

@@ -1,52 +0,0 @@
-From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
-Date: Mon, 30 Jan 2017 16:09:51 +0100
-Subject: [PATCH] brcmfmac: check brcmf_bus_get_memdump result for error
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-This method may be unsupported (see: USB bus) or may just fail (see:
-SDIO bus).
-While at it rework logic in brcmf_sdio_bus_get_memdump function to avoid
-too many conditional code nesting levels.
-
-Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
-Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
-Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
----
-
---- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c
-+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c
-@@ -32,16 +32,25 @@ static int brcmf_debug_create_memdump(st
- {
- 	void *dump;
- 	size_t ramsize;
-+	int err;
- 
- 	ramsize = brcmf_bus_get_ramsize(bus);
--	if (ramsize) {
--		dump = vzalloc(len + ramsize);
--		if (!dump)
--			return -ENOMEM;
--		memcpy(dump, data, len);
--		brcmf_bus_get_memdump(bus, dump + len, ramsize);
--		dev_coredumpv(bus->dev, dump, len + ramsize, GFP_KERNEL);
-+	if (!ramsize)
-+		return -ENOTSUPP;
-+
-+	dump = vzalloc(len + ramsize);
-+	if (!dump)
-+		return -ENOMEM;
-+
-+	memcpy(dump, data, len);
-+	err = brcmf_bus_get_memdump(bus, dump + len, ramsize);
-+	if (err) {
-+		vfree(dump);
-+		return err;
- 	}
-+
-+	dev_coredumpv(bus->dev, dump, len + ramsize, GFP_KERNEL);
-+
- 	return 0;
- }
- 

+ 0 - 38
package/kernel/mac80211/patches/319-0002-brcmfmac-be-more-verbose-when-PSM-s-watchdog-fires.patch

@@ -1,38 +0,0 @@
-From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
-Date: Mon, 30 Jan 2017 16:09:52 +0100
-Subject: [PATCH] brcmfmac: be more verbose when PSM's watchdog fires
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-It's important to inform user so he knows things went wrong. He may also
-want to get memory dump for further debugging purposes.
-
-Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
-Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
-Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
----
-
---- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c
-+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c
-@@ -58,10 +58,18 @@ static int brcmf_debug_psm_watchdog_noti
- 					   const struct brcmf_event_msg *evtmsg,
- 					   void *data)
- {
-+	int err;
-+
- 	brcmf_dbg(TRACE, "enter: bsscfgidx=%d\n", ifp->bsscfgidx);
- 
--	return brcmf_debug_create_memdump(ifp->drvr->bus_if, data,
--					  evtmsg->datalen);
-+	brcmf_err("PSM's watchdog has fired!\n");
-+
-+	err = brcmf_debug_create_memdump(ifp->drvr->bus_if, data,
-+					 evtmsg->datalen);
-+	if (err)
-+		brcmf_err("Failed to get memory dump, %d\n", err);
-+
-+	return err;
- }
- 
- void brcmf_debugfs_init(void)

+ 0 - 44
package/kernel/mac80211/patches/319-0003-brcmfmac-use-wiphy_read_of_freq_limits-to-respect-li.patch

@@ -1,44 +0,0 @@
-From 0f83ff69735651cc7a3d150466a5257ff829b62b Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
-Date: Tue, 17 Jan 2017 23:35:50 +0100
-Subject: [PATCH] brcmfmac: use wiphy_read_of_freq_limits to respect limits
- from DT
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-This new helper reads extra frequency limits specified in DT and
-disables unavailable chanels. This is useful for devices (like home
-routers) with chipsets limited e.g. by board design.
-
-In order to respect info read from DT we simply need to check for
-IEEE80211_CHAN_DISABLED bit when constructing channel info.
-
-Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
-Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
----
- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 6 ++++++
- 1 file changed, 6 insertions(+)
-
---- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
-+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
-@@ -5908,6 +5908,9 @@ static int brcmf_construct_chaninfo(stru
- 			continue;
- 		}
- 
-+		if (channel->orig_flags & IEEE80211_CHAN_DISABLED)
-+			continue;
-+
- 		/* assuming the chanspecs order is HT20,
- 		 * HT40 upper, HT40 lower, and VHT80.
- 		 */
-@@ -6509,6 +6512,9 @@ static int brcmf_setup_wiphy(struct wiph
- 			wiphy->bands[NL80211_BAND_5GHZ] = band;
- 		}
- 	}
-+
-+	wiphy_read_of_freq_limits(wiphy);
-+
- 	return 0;
- }
- 

+ 0 - 43
package/kernel/mac80211/patches/319-0004-brcmfmac-merge-two-brcmf_err-macros-into-one.patch

@@ -1,43 +0,0 @@
-From 9587a01a7ead9efc5032c16e0d9668de58be1186 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
-Date: Thu, 2 Feb 2017 22:33:13 +0100
-Subject: [PATCH] brcmfmac: merge two brcmf_err macros into one
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-This allows simplifying the code by adding a simple IS_ENABLED check for
-CONFIG_BRCMDB symbol.
-
-Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
-Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
-Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
----
- drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h | 8 ++------
- 1 file changed, 2 insertions(+), 6 deletions(-)
-
---- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h
-+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h
-@@ -45,20 +45,16 @@
- #undef pr_fmt
- #define pr_fmt(fmt)		KBUILD_MODNAME ": " fmt
- 
-+#ifndef CPTCFG_BRCM_TRACING
- /* Macro for error messages. net_ratelimit() is used when driver
-  * debugging is not selected. When debugging the driver error
-  * messages are as important as other tracing or even more so.
-  */
--#ifndef CPTCFG_BRCM_TRACING
--#ifdef CPTCFG_BRCMDBG
--#define brcmf_err(fmt, ...)	pr_err("%s: " fmt, __func__, ##__VA_ARGS__)
--#else
- #define brcmf_err(fmt, ...)						\
- 	do {								\
--		if (net_ratelimit())					\
-+		if (IS_ENABLED(CPTCFG_BRCMDBG) || net_ratelimit())	\
- 			pr_err("%s: " fmt, __func__, ##__VA_ARGS__);	\
- 	} while (0)
--#endif
- #else
- __printf(2, 3)
- void __brcmf_err(const char *func, const char *fmt, ...);

+ 0 - 69
package/kernel/mac80211/patches/319-0005-brcmfmac-switch-to-C-function-__brcmf_err-for-printi.patch

@@ -1,69 +0,0 @@
-From 087fa712a00685dac4bcc64b7c3dc8ae6bee8026 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
-Date: Thu, 2 Feb 2017 22:33:14 +0100
-Subject: [PATCH] brcmfmac: switch to C function (__brcmf_err) for printing
- errors
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-This will allow extending code and using more detailed messages e.g.
-with the help of dev_err.
-
-Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
-Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
-Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
----
- .../net/wireless/broadcom/brcm80211/brcmfmac/common.c    | 16 ++++++++++++++++
- drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h |  6 +++---
- 2 files changed, 19 insertions(+), 3 deletions(-)
-
---- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
-+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
-@@ -218,6 +218,22 @@ done:
- 	return err;
- }
- 
-+#ifndef CPTCFG_BRCM_TRACING
-+void __brcmf_err(const char *func, const char *fmt, ...)
-+{
-+	struct va_format vaf;
-+	va_list args;
-+
-+	va_start(args, fmt);
-+
-+	vaf.fmt = fmt;
-+	vaf.va = &args;
-+	pr_err("%s: %pV", func, &vaf);
-+
-+	va_end(args);
-+}
-+#endif
-+
- #if defined(CPTCFG_BRCM_TRACING) || defined(CPTCFG_BRCMDBG)
- void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
- {
---- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h
-+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h
-@@ -45,6 +45,8 @@
- #undef pr_fmt
- #define pr_fmt(fmt)		KBUILD_MODNAME ": " fmt
- 
-+__printf(2, 3)
-+void __brcmf_err(const char *func, const char *fmt, ...);
- #ifndef CPTCFG_BRCM_TRACING
- /* Macro for error messages. net_ratelimit() is used when driver
-  * debugging is not selected. When debugging the driver error
-@@ -53,11 +55,9 @@
- #define brcmf_err(fmt, ...)						\
- 	do {								\
- 		if (IS_ENABLED(CPTCFG_BRCMDBG) || net_ratelimit())	\
--			pr_err("%s: " fmt, __func__, ##__VA_ARGS__);	\
-+			__brcmf_err(__func__, fmt, ##__VA_ARGS__);	\
- 	} while (0)
- #else
--__printf(2, 3)
--void __brcmf_err(const char *func, const char *fmt, ...);
- #define brcmf_err(fmt, ...) \
- 	__brcmf_err(__func__, fmt, ##__VA_ARGS__)
- #endif

+ 0 - 46
package/kernel/mac80211/patches/319-0006-brcmfmac-merge-two-remaining-brcmf_err-macros.patch

@@ -1,46 +0,0 @@
-From d0630555650a394cf5743268820511f527a561a5 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
-Date: Thu, 2 Feb 2017 22:33:15 +0100
-Subject: [PATCH] brcmfmac: merge two remaining brcmf_err macros
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-Now we always have __brcmf_err function we can do perfectly fine with
-just one macro.
-
-Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
-Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
-Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
----
- drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h | 14 +++++---------
- 1 file changed, 5 insertions(+), 9 deletions(-)
-
---- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h
-+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h
-@@ -47,20 +47,16 @@
- 
- __printf(2, 3)
- void __brcmf_err(const char *func, const char *fmt, ...);
--#ifndef CPTCFG_BRCM_TRACING
--/* Macro for error messages. net_ratelimit() is used when driver
-- * debugging is not selected. When debugging the driver error
-- * messages are as important as other tracing or even more so.
-+/* Macro for error messages. When debugging / tracing the driver all error
-+ * messages are important to us.
-  */
- #define brcmf_err(fmt, ...)						\
- 	do {								\
--		if (IS_ENABLED(CPTCFG_BRCMDBG) || net_ratelimit())	\
-+		if (IS_ENABLED(CPTCFG_BRCMDBG) ||			\
-+		    IS_ENABLED(CPTCFG_BRCM_TRACING) ||			\
-+		    net_ratelimit())					\
- 			__brcmf_err(__func__, fmt, ##__VA_ARGS__);	\
- 	} while (0)
--#else
--#define brcmf_err(fmt, ...) \
--	__brcmf_err(__func__, fmt, ##__VA_ARGS__)
--#endif
- 
- #if defined(DEBUG) || defined(CPTCFG_BRCM_TRACING)
- __printf(3, 4)

+ 47 - 0
package/kernel/mac80211/patches/324-ath9k_hw-fix-channel-maximum-power-level-test.patch

@@ -0,0 +1,47 @@
+From: Felix Fietkau <nbd@nbd.name>
+Date: Wed, 22 Mar 2017 20:37:04 +0100
+Subject: [PATCH] ath9k_hw: fix channel maximum power level test
+
+The tx power applied by set_txpower is limited by the CTL (conformance
+test limit) entries in the EEPROM. These can change based on the user
+configured regulatory domain.
+Depending on the EEPROM data this can cause the tx power to become too
+limited, if the original regdomain CTLs impose lowr limits than the CTLs
+of the user configured regdomain.
+
+To fix this issue, set the initial channel limits without any CTL
+restrictions and only apply the CTL at run time when setting the channel
+and the real tx power.
+
+Cc: stable@vger.kernel.org
+Signed-off-by: Felix Fietkau <nbd@nbd.name>
+---
+
+--- a/drivers/net/wireless/ath/ath9k/hw.c
++++ b/drivers/net/wireless/ath/ath9k/hw.c
+@@ -2937,10 +2937,14 @@ void ath9k_hw_apply_txpower(struct ath_h
+ 	struct ieee80211_channel *channel;
+ 	int chan_pwr, new_pwr, max_gain;
+ 	int ant_gain, ant_reduction = 0;
++	u16 ctl = NO_CTL;
+ 
+ 	if (!chan)
+ 		return;
+ 
++	if (!test)
++		ctl = ath9k_regd_get_ctl(reg, chan);
++
+ 	channel = chan->chan;
+ 	chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
+ 	new_pwr = min_t(int, chan_pwr, reg->power_limit);
+@@ -2950,9 +2954,7 @@ void ath9k_hw_apply_txpower(struct ath_h
+ 	if (ant_gain > max_gain)
+ 		ant_reduction = ant_gain - max_gain;
+ 
+-	ah->eep_ops->set_txpower(ah, chan,
+-				 ath9k_regd_get_ctl(reg, chan),
+-				 ant_reduction, new_pwr, test);
++	ah->eep_ops->set_txpower(ah, chan, ctl, ant_reduction, new_pwr, test);
+ }
+ 
+ void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)

+ 29 - 0
package/kernel/mac80211/patches/325-mac80211-unconditionally-start-new-netdev-queues-wit.patch

@@ -0,0 +1,29 @@
+From: Johannes Berg <johannes.berg@intel.com>
+Date: Wed, 29 Mar 2017 14:15:24 +0200
+Subject: [PATCH] mac80211: unconditionally start new netdev queues with iTXQ
+ support
+
+When internal mac80211 TXQs aren't supported, netdev queues must
+always started out started even when driver queues are stopped
+while the interface is added. This is necessary because with the
+internal TXQ support netdev queues are never stopped and packet
+scheduling/dropping is done in mac80211.
+
+Cc: stable@vger.kernel.org # 4.9+
+Fixes: 80a83cfc434b1 ("mac80211: skip netdev queue control with software queuing")
+Reported-and-tested-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Signed-off-by: Johannes Berg <johannes.berg@intel.com>
+---
+
+--- a/net/mac80211/iface.c
++++ b/net/mac80211/iface.c
+@@ -727,7 +727,8 @@ int ieee80211_do_open(struct wireless_de
+ 	ieee80211_recalc_ps(local);
+ 
+ 	if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
+-	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
++	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
++	    local->ops->wake_tx_queue) {
+ 		/* XXX: for AP_VLAN, actually track AP queues */
+ 		netif_tx_start_all_queues(dev);
+ 	} else if (dev) {

+ 81 - 0
package/kernel/mac80211/patches/327-mac80211-accept-key-reinstall-without-changing-anyth.patch

@@ -0,0 +1,81 @@
+From fdf7cb4185b60c68e1a75e61691c4afdc15dea0e Mon Sep 17 00:00:00 2001
+From: Johannes Berg <johannes.berg@intel.com>
+Date: Tue, 5 Sep 2017 14:54:54 +0200
+Subject: [PATCH] mac80211: accept key reinstall without changing anything
+
+When a key is reinstalled we can reset the replay counters
+etc. which can lead to nonce reuse and/or replay detection
+being impossible, breaking security properties, as described
+in the "KRACK attacks".
+
+In particular, CVE-2017-13080 applies to GTK rekeying that
+happened in firmware while the host is in D3, with the second
+part of the attack being done after the host wakes up. In
+this case, the wpa_supplicant mitigation isn't sufficient
+since wpa_supplicant doesn't know the GTK material.
+
+In case this happens, simply silently accept the new key
+coming from userspace but don't take any action on it since
+it's the same key; this keeps the PN replay counters intact.
+
+Signed-off-by: Johannes Berg <johannes.berg@intel.com>
+---
+ net/mac80211/key.c | 21 +++++++++++++++++----
+ 1 file changed, 17 insertions(+), 4 deletions(-)
+
+diff --git a/net/mac80211/key.c b/net/mac80211/key.c
+index a98fc2b5e0dc..ae995c8480db 100644
+--- a/net/mac80211/key.c
++++ b/net/mac80211/key.c
+@@ -4,7 +4,7 @@
+  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
+  * Copyright 2007-2008	Johannes Berg <johannes@sipsolutions.net>
+  * Copyright 2013-2014  Intel Mobile Communications GmbH
+- * Copyright 2015	Intel Deutschland GmbH
++ * Copyright 2015-2017	Intel Deutschland GmbH
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+@@ -620,9 +620,6 @@ int ieee80211_key_link(struct ieee80211_key *key,
+ 
+ 	pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
+ 	idx = key->conf.keyidx;
+-	key->local = sdata->local;
+-	key->sdata = sdata;
+-	key->sta = sta;
+ 
+ 	mutex_lock(&sdata->local->key_mtx);
+ 
+@@ -633,6 +630,21 @@ int ieee80211_key_link(struct ieee80211_key *key,
+ 	else
+ 		old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
+ 
++	/*
++	 * Silently accept key re-installation without really installing the
++	 * new version of the key to avoid nonce reuse or replay issues.
++	 */
++	if (old_key && key->conf.keylen == old_key->conf.keylen &&
++	    !memcmp(key->conf.key, old_key->conf.key, key->conf.keylen)) {
++		ieee80211_key_free_unused(key);
++		ret = 0;
++		goto out;
++	}
++
++	key->local = sdata->local;
++	key->sdata = sdata;
++	key->sta = sta;
++
+ 	increment_tailroom_need_count(sdata);
+ 
+ 	ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
+@@ -648,6 +660,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
+ 		ret = 0;
+ 	}
+ 
++ out:
+ 	mutex_unlock(&sdata->local->key_mtx);
+ 
+ 	return ret;
+-- 
+2.13.6
+

+ 38 - 6
package/kernel/mac80211/patches/402-ath_regd_optional.patch

@@ -1,6 +1,14 @@
 --- a/drivers/net/wireless/ath/regd.c
 +++ b/drivers/net/wireless/ath/regd.c
-@@ -116,6 +116,9 @@ static const struct ieee80211_regdomain
+@@ -24,6 +24,7 @@
+ #include "regd_common.h"
+ 
+ static int __ath_regd_init(struct ath_regulatory *reg);
++static struct reg_dmn_pair_mapping *ath_get_regpair(int regdmn);
+ 
+ /*
+  * This is a set of common rules used by our world regulatory domains.
+@@ -116,6 +117,9 @@ static const struct ieee80211_regdomain
  
  static bool dynamic_country_user_possible(struct ath_regulatory *reg)
  {
@@ -10,7 +18,7 @@
  	if (IS_ENABLED(CPTCFG_ATH_REG_DYNAMIC_USER_CERT_TESTING))
  		return true;
  
-@@ -188,6 +191,8 @@ static bool dynamic_country_user_possibl
+@@ -188,6 +192,8 @@ static bool dynamic_country_user_possibl
  
  static bool ath_reg_dyn_country_user_allow(struct ath_regulatory *reg)
  {
@@ -19,7 +27,7 @@
  	if (!IS_ENABLED(CPTCFG_ATH_REG_DYNAMIC_USER_REG_HINTS))
  		return false;
  	if (!dynamic_country_user_possible(reg))
-@@ -341,6 +346,9 @@ ath_reg_apply_beaconing_flags(struct wip
+@@ -341,6 +347,9 @@ ath_reg_apply_beaconing_flags(struct wip
  	struct ieee80211_channel *ch;
  	unsigned int i;
  
@@ -29,7 +37,7 @@
  	for (band = 0; band < NUM_NL80211_BANDS; band++) {
  		if (!wiphy->bands[band])
  			continue;
-@@ -374,6 +382,9 @@ ath_reg_apply_ir_flags(struct wiphy *wip
+@@ -374,6 +383,9 @@ ath_reg_apply_ir_flags(struct wiphy *wip
  {
  	struct ieee80211_supported_band *sband;
  
@@ -39,7 +47,7 @@
  	sband = wiphy->bands[NL80211_BAND_2GHZ];
  	if (!sband)
  		return;
-@@ -402,6 +413,9 @@ static void ath_reg_apply_radar_flags(st
+@@ -402,6 +414,9 @@ static void ath_reg_apply_radar_flags(st
  	struct ieee80211_channel *ch;
  	unsigned int i;
  
@@ -49,7 +57,19 @@
  	if (!wiphy->bands[NL80211_BAND_5GHZ])
  		return;
  
-@@ -634,6 +648,10 @@ ath_regd_init_wiphy(struct ath_regulator
+@@ -539,6 +554,11 @@ void ath_reg_notifier_apply(struct wiphy
+ 		ath_reg_dyn_country(wiphy, reg, request);
+ 		break;
+ 	}
++
++	/* Prevent broken CTLs from being applied */
++	if (IS_ENABLED(CPTCFG_ATH_USER_REGD) &&
++	    reg->regpair != common->reg_world_copy.regpair)
++		reg->regpair = ath_get_regpair(WOR0_WORLD);
+ }
+ EXPORT_SYMBOL(ath_reg_notifier_apply);
+ 
+@@ -634,6 +654,10 @@ ath_regd_init_wiphy(struct ath_regulator
  	const struct ieee80211_regdomain *regd;
  
  	wiphy->reg_notifier = reg_notifier;
@@ -60,6 +80,18 @@
  	wiphy->regulatory_flags |= REGULATORY_STRICT_REG |
  				   REGULATORY_CUSTOM_REG;
  
+@@ -762,10 +786,7 @@ ath_regd_init(struct ath_regulatory *reg
+ 	if (r)
+ 		return r;
+ 
+-	if (ath_is_world_regd(reg))
+-		memcpy(&common->reg_world_copy, reg,
+-		       sizeof(struct ath_regulatory));
+-
++	memcpy(&common->reg_world_copy, reg, sizeof(struct ath_regulatory));
+ 	ath_regd_init_wiphy(reg, wiphy, reg_notifier);
+ 
+ 	return 0;
 --- a/drivers/net/wireless/ath/Kconfig
 +++ b/drivers/net/wireless/ath/Kconfig
 @@ -23,6 +23,9 @@ config WLAN_VENDOR_ATH

+ 2 - 2
package/kernel/mac80211/patches/403-world_regd_fixup.patch

@@ -1,6 +1,6 @@
 --- a/drivers/net/wireless/ath/regd.c
 +++ b/drivers/net/wireless/ath/regd.c
-@@ -43,7 +43,8 @@ static int __ath_regd_init(struct ath_re
+@@ -44,7 +44,8 @@ static struct reg_dmn_pair_mapping *ath_
  					 NL80211_RRF_NO_OFDM)
  
  /* We allow IBSS on these on a case by case basis by regulatory domain */
@@ -10,7 +10,7 @@
  					 NL80211_RRF_NO_IR)
  #define ATH9K_5GHZ_5470_5850	REG_RULE(5470-10, 5850+10, 80, 0, 30,\
  					 NL80211_RRF_NO_IR)
-@@ -61,57 +62,56 @@ static int __ath_regd_init(struct ath_re
+@@ -62,57 +63,56 @@ static struct reg_dmn_pair_mapping *ath_
  #define ATH9K_5GHZ_NO_MIDBAND	ATH9K_5GHZ_5150_5350, \
  				ATH9K_5GHZ_5725_5850
  

+ 4 - 4
package/kernel/mac80211/patches/406-ath_relax_default_regd.patch

@@ -1,6 +1,6 @@
 --- a/drivers/net/wireless/ath/regd.c
 +++ b/drivers/net/wireless/ath/regd.c
-@@ -114,6 +114,16 @@ static const struct ieee80211_regdomain
+@@ -115,6 +115,16 @@ static const struct ieee80211_regdomain
  	)
  };
  
@@ -17,7 +17,7 @@
  static bool dynamic_country_user_possible(struct ath_regulatory *reg)
  {
  	if (IS_ENABLED(CPTCFG_ATH_USER_REGD))
-@@ -122,6 +132,9 @@ static bool dynamic_country_user_possibl
+@@ -123,6 +133,9 @@ static bool dynamic_country_user_possibl
  	if (IS_ENABLED(CPTCFG_ATH_REG_DYNAMIC_USER_CERT_TESTING))
  		return true;
  
@@ -27,7 +27,7 @@
  	switch (reg->country_code) {
  	case CTRY_UNITED_STATES:
  	case CTRY_JAPAN1:
-@@ -207,11 +220,6 @@ static inline bool is_wwr_sku(u16 regd)
+@@ -208,11 +221,6 @@ static inline bool is_wwr_sku(u16 regd)
  		(regd == WORLD));
  }
  
@@ -39,7 +39,7 @@
  bool ath_is_world_regd(struct ath_regulatory *reg)
  {
  	return is_wwr_sku(ath_regd_get_eepromRD(reg));
-@@ -652,6 +660,9 @@ ath_regd_init_wiphy(struct ath_regulator
+@@ -658,6 +666,9 @@ ath_regd_init_wiphy(struct ath_regulator
  	if (IS_ENABLED(CPTCFG_ATH_USER_REGD))
  		return 0;
  

+ 4 - 4
package/kernel/mac80211/patches/600-01-rt2x00-allow-to-build-rt2800soc-module-for-RT3883.patch

@@ -14,8 +14,8 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  config RT2800SOC
  	tristate "Ralink WiSoC support"
  	depends on m
--	depends on SOC_RT288X || SOC_RT305X
-+	depends on SOC_RT288X || SOC_RT305X || SOC_RT3883
+-	depends on SOC_RT288X || SOC_RT305X || SOC_MT7620
++	depends on SOC_RT288X || SOC_RT305X || SOC_RT3883 || SOC_MT7620
  	select RT2X00_LIB_SOC
  	select RT2X00_LIB_MMIO
  	select RT2X00_LIB_CRYPTO
@@ -23,8 +23,8 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  
  config RT2X00_LIB_SOC
  	tristate "RT2x00 SoC support"
--	depends on SOC_RT288X || SOC_RT305X
-+	depends on SOC_RT288X || SOC_RT305X || SOC_RT3883
+-	depends on SOC_RT288X || SOC_RT305X || SOC_MT7620
++	depends on SOC_RT288X || SOC_RT305X || SOC_RT3883 || SOC_MT7620
  	depends on m
  	select RT2X00_LIB
  

+ 1 - 1
package/kernel/mac80211/patches/600-02-rt2x00-rt2800lib-enable-support-for-RT3883.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -7956,6 +7956,7 @@ static int rt2800_probe_rt(struct rt2x00
+@@ -9379,6 +9379,7 @@ static int rt2800_probe_rt(struct rt2x00
  	case RT3390:
  	case RT3572:
  	case RT3593:

+ 2 - 2
package/kernel/mac80211/patches/600-03-rt2x00-rt2800lib-add-rf_vals-for-RF3853.patch

@@ -31,7 +31,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  #define RF5362				0x5362
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -7557,6 +7557,66 @@ static const struct rf_channel rf_vals_3
+@@ -8957,6 +8957,66 @@ static const struct rf_channel rf_vals_3
  	{14,   0xF0,	 2,  0x18},
  };
  
@@ -98,7 +98,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  static const struct rf_channel rf_vals_5592_xtal20[] = {
  	/* Channel, N, K, mod, R */
  	{1, 482, 4, 10, 3},
-@@ -7798,6 +7858,11 @@ static int rt2800_probe_hw_mode(struct r
+@@ -9220,6 +9280,11 @@ static int rt2800_probe_hw_mode(struct r
  		spec->channels = rf_vals_3x;
  		break;
  

+ 2 - 2
package/kernel/mac80211/patches/600-04-rt2x00-rt2800lib-enable-VCO-calibration-for-RF3853.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -4363,6 +4363,7 @@ void rt2800_vco_calibration(struct rt2x0
+@@ -4855,6 +4855,7 @@ void rt2800_vco_calibration(struct rt2x0
  	case RF3053:
  	case RF3070:
  	case RF3290:
@@ -18,7 +18,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  	case RF5350:
  	case RF5360:
  	case RF5362:
-@@ -7980,6 +7981,7 @@ static int rt2800_probe_hw_mode(struct r
+@@ -9402,6 +9403,7 @@ static int rt2800_probe_hw_mode(struct r
  	case RF3053:
  	case RF3070:
  	case RF3290:

+ 2 - 2
package/kernel/mac80211/patches/600-05-rt2x00-rt2800lib-add-channel-configuration-function-.patch

@@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -2584,6 +2584,211 @@ static void rt2800_config_channel_rf3053
+@@ -2709,6 +2709,211 @@ static void rt2800_config_channel_rf3053
  	}
  }
  
@@ -223,7 +223,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  #define POWER_BOUND		0x27
  #define POWER_BOUND_5G		0x2b
  
-@@ -3203,6 +3408,9 @@ static void rt2800_config_channel(struct
+@@ -3565,6 +3770,9 @@ static void rt2800_config_channel(struct
  	case RF3322:
  		rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
  		break;

+ 1 - 1
package/kernel/mac80211/patches/600-06-rt2x00-rt2800lib-enable-RF3853-support.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -7483,6 +7483,7 @@ static int rt2800_init_eeprom(struct rt2
+@@ -8882,6 +8882,7 @@ static int rt2800_init_eeprom(struct rt2
  	case RF3290:
  	case RF3320:
  	case RF3322:

+ 6 - 6
package/kernel/mac80211/patches/600-07-rt2x00-rt2800lib-add-MAC-register-initialization-for.patch

@@ -12,8 +12,8 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800.h
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800.h
-@@ -1574,6 +1574,20 @@
- #define TX_PWR_CFG_9_STBC7_CH2		FIELD32(0x00000f00)
+@@ -1727,6 +1727,20 @@
+ #define TX_PWR_CFG_9B_STBC_MCS7		FIELD32(0x000000ff)
  
  /*
 + * TX_TXBF_CFG:
@@ -35,7 +35,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  #define RX_FILTER_CFG			0x1400
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -4946,6 +4946,12 @@ static int rt2800_init_registers(struct
+@@ -5485,6 +5485,12 @@ static int rt2800_init_registers(struct
  			rt2800_register_write(rt2x00dev, TX_SW_CFG2,
  					      0x00000000);
  		}
@@ -46,9 +46,9 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 +		rt2800_register_write(rt2x00dev, TX_TXBF_CFG_0, 0x8000fc21);
 +		rt2800_register_write(rt2x00dev, TX_TXBF_CFG_3, 0x00009c40);
  	} else if (rt2x00_rt(rt2x00dev, RT5390) ||
- 		   rt2x00_rt(rt2x00dev, RT5392)) {
- 		rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
-@@ -5140,6 +5146,11 @@ static int rt2800_init_registers(struct
+ 		   rt2x00_rt(rt2x00dev, RT5392) ||
+ 		   rt2x00_rt(rt2x00dev, RT6352)) {
+@@ -5698,6 +5704,11 @@ static int rt2800_init_registers(struct
  	reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002;
  	rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg);
  

+ 2 - 2
package/kernel/mac80211/patches/600-09-rt2x00-rt2800lib-add-BBP-register-initialization-for.patch

@@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -5767,6 +5767,47 @@ static void rt2800_init_bbp_3593(struct
+@@ -6325,6 +6325,47 @@ static void rt2800_init_bbp_3593(struct
  		rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  }
  
@@ -59,7 +59,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
  {
  	int ant, div_mode;
-@@ -5986,6 +6027,9 @@ static void rt2800_init_bbp(struct rt2x0
+@@ -6769,6 +6810,9 @@ static void rt2800_init_bbp(struct rt2x0
  	case RT3593:
  		rt2800_init_bbp_3593(rt2x00dev);
  		return;

+ 5 - 5
package/kernel/mac80211/patches/600-10-rt2x00-rt2800lib-add-RFCSR-initialization-for-RT3883.patch

@@ -11,17 +11,17 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800.h
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800.h
-@@ -2155,6 +2155,7 @@ struct mac_iveiv_entry {
+@@ -2311,6 +2311,7 @@ struct mac_iveiv_entry {
  /*
   * RFCSR 2:
   */
 +#define RFCSR2_RESCAL_BP		FIELD8(0x40)
  #define RFCSR2_RESCAL_EN		FIELD8(0x80)
- 
- /*
+ #define RFCSR2_RX2_EN_MT7620		FIELD8(0x02)
+ #define RFCSR2_TX2_EN_MT7620		FIELD8(0x20)
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -6899,6 +6899,144 @@ static void rt2800_init_rfcsr_5350(struc
+@@ -7685,6 +7685,144 @@ static void rt2800_init_rfcsr_5350(struc
  	rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
  }
  
@@ -166,7 +166,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev)
  {
  	rt2800_rf_init_calibration(rt2x00dev, 2);
-@@ -7130,6 +7268,9 @@ static void rt2800_init_rfcsr(struct rt2
+@@ -8525,6 +8663,9 @@ static void rt2800_init_rfcsr(struct rt2
  	case RT3390:
  		rt2800_init_rfcsr_3390(rt2x00dev);
  		break;

+ 1 - 1
package/kernel/mac80211/patches/600-11-rt2x00-rt2800lib-use-the-extended-EEPROM-map-for-RT3.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -309,7 +309,8 @@ static unsigned int rt2800_eeprom_word_i
+@@ -376,7 +376,8 @@ static unsigned int rt2800_eeprom_word_i
  		      wiphy_name(rt2x00dev->hw->wiphy), word))
  		return 0;
  

+ 1 - 1
package/kernel/mac80211/patches/600-12-rt2x00-rt2800lib-force-rf-type-to-RF3853-on-RT3883.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -7660,6 +7660,8 @@ static int rt2800_init_eeprom(struct rt2
+@@ -9059,6 +9059,8 @@ static int rt2800_init_eeprom(struct rt2
  		rt2800_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf);
  	else if (rt2x00_rt(rt2x00dev, RT3352))
  		rf = RF3322;

+ 8 - 8
package/kernel/mac80211/patches/600-13-rt2x00-rt2800lib-add-channel-configuration-code-for-.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -3371,6 +3371,36 @@ static char rt2800_txpower_to_dev(struct
+@@ -3733,6 +3733,36 @@ static char rt2800_txpower_to_dev(struct
  		return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
  }
  
@@ -47,7 +47,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
  				  struct ieee80211_conf *conf,
  				  struct rf_channel *rf,
-@@ -3389,6 +3419,12 @@ static void rt2800_config_channel(struct
+@@ -3751,6 +3781,12 @@ static void rt2800_config_channel(struct
  			rt2800_txpower_to_dev(rt2x00dev, rf->channel,
  					      info->default_power3);
  
@@ -60,7 +60,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  	switch (rt2x00dev->chip.rf) {
  	case RF2020:
  	case RF3020:
-@@ -3490,6 +3526,15 @@ static void rt2800_config_channel(struct
+@@ -3855,6 +3891,15 @@ static void rt2800_config_channel(struct
  		rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
  		rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
  		rt2800_bbp_write(rt2x00dev, 77, 0x98);
@@ -76,15 +76,15 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  	} else {
  		rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
  		rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
-@@ -3502,6 +3547,7 @@ static void rt2800_config_channel(struct
- 		    !rt2x00_rt(rt2x00dev, RT5392)) {
+@@ -3868,6 +3913,7 @@ static void rt2800_config_channel(struct
+ 		    !rt2x00_rt(rt2x00dev, RT6352)) {
  			if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
  				rt2800_bbp_write(rt2x00dev, 82, 0x62);
 +				rt2800_bbp_write(rt2x00dev, 82, 0x62);
  				rt2800_bbp_write(rt2x00dev, 75, 0x46);
  			} else {
  				if (rt2x00_rt(rt2x00dev, RT3593))
-@@ -3510,19 +3556,22 @@ static void rt2800_config_channel(struct
+@@ -3876,19 +3922,22 @@ static void rt2800_config_channel(struct
  					rt2800_bbp_write(rt2x00dev, 82, 0x84);
  				rt2800_bbp_write(rt2x00dev, 75, 0x50);
  			}
@@ -101,7 +101,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 +		else if (rt2x00_rt(rt2x00dev, RT3593) ||
 +			 rt2x00_rt(rt2x00dev, RT3883))
  			rt2800_bbp_write(rt2x00dev, 82, 0x82);
- 		else
+ 		else if (!rt2x00_rt(rt2x00dev, RT6352))
  			rt2800_bbp_write(rt2x00dev, 82, 0xf2);
  
 -		if (rt2x00_rt(rt2x00dev, RT3593))
@@ -110,7 +110,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  			rt2800_bbp_write(rt2x00dev, 83, 0x9a);
  
  		if (rt2x00_has_cap_external_lna_a(rt2x00dev))
-@@ -3644,6 +3693,23 @@ static void rt2800_config_channel(struct
+@@ -4011,6 +4060,23 @@ static void rt2800_config_channel(struct
  
  		rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
  

+ 1 - 1
package/kernel/mac80211/patches/600-14-rt2x00-rt2800lib-fix-txpower_to_dev-function-for-RT3.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -3358,13 +3358,15 @@ static char rt2800_txpower_to_dev(struct
+@@ -3720,13 +3720,15 @@ static char rt2800_txpower_to_dev(struct
  				  unsigned int channel,
  				  char txpower)
  {

+ 3 - 3
package/kernel/mac80211/patches/600-15-rt2x00-rt2800lib-use-correct-txpower-calculation-fun.patch

@@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -4596,7 +4596,8 @@ static void rt2800_config_txpower(struct
+@@ -5085,7 +5085,8 @@ static void rt2800_config_txpower(struct
  				  struct ieee80211_channel *chan,
  				  int power_level)
  {
@@ -19,5 +19,5 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 +	if (rt2x00_rt(rt2x00dev, RT3593) ||
 +	    rt2x00_rt(rt2x00dev, RT3883))
  		rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level);
- 	else
- 		rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level);
+ 	else if (rt2x00_rt(rt2x00dev, RT6352))
+ 		rt2800_config_txpower_rt6352(rt2x00dev, chan, power_level);

+ 2 - 2
package/kernel/mac80211/patches/600-16-rt2x00-rt2800lib-hardcode-txmixer-gain-values-to-zer.patch

@@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -7543,7 +7543,8 @@ static u8 rt2800_get_txmixer_gain_24g(st
+@@ -8941,7 +8941,8 @@ static u8 rt2800_get_txmixer_gain_24g(st
  {
  	u16 word;
  
@@ -21,7 +21,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  		return 0;
  
  	rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &word);
-@@ -7557,7 +7558,8 @@ static u8 rt2800_get_txmixer_gain_5g(str
+@@ -8955,7 +8956,8 @@ static u8 rt2800_get_txmixer_gain_5g(str
  {
  	u16 word;
  

+ 1 - 1
package/kernel/mac80211/patches/600-17-rt2x00-rt2800lib-use-correct-RT-XWI-size-for-RT3883.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -520,6 +520,7 @@ void rt2800_get_txwi_rxwi_size(struct rt
+@@ -587,6 +587,7 @@ void rt2800_get_txwi_rxwi_size(struct rt
  {
  	switch (rt2x00dev->chip.rt) {
  	case RT3593:

+ 1 - 1
package/kernel/mac80211/patches/600-18-rt2x00-rt2800lib-fix-antenna-configuration-for-RT388.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -1888,7 +1888,8 @@ void rt2800_config_ant(struct rt2x00_dev
+@@ -2013,7 +2013,8 @@ void rt2800_config_ant(struct rt2x00_dev
  	rt2800_bbp_write(rt2x00dev, 3, r3);
  	rt2800_bbp_write(rt2x00dev, 1, r1);
  

+ 2 - 2
package/kernel/mac80211/patches/600-19-rt2x00-rt2800lib-fix-LNA-gain-configuration-for-RT38.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -1911,7 +1911,8 @@ static void rt2800_config_lna_gain(struc
+@@ -2036,7 +2036,8 @@ static void rt2800_config_lna_gain(struc
  		rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  		lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
  	} else if (libconf->rf.channel <= 128) {
@@ -20,7 +20,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  			rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &eeprom);
  			lna_gain = rt2x00_get_field16(eeprom,
  						      EEPROM_EXT_LNA2_A1);
-@@ -1921,7 +1922,8 @@ static void rt2800_config_lna_gain(struc
+@@ -2046,7 +2047,8 @@ static void rt2800_config_lna_gain(struc
  						      EEPROM_RSSI_BG2_LNA_A1);
  		}
  	} else {

+ 3 - 3
package/kernel/mac80211/patches/600-20-rt2x00-rt2800lib-fix-VGC-setup-for-RT3883.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -4799,7 +4799,8 @@ static u8 rt2800_get_default_vgc(struct
+@@ -5338,7 +5338,8 @@ static u8 rt2800_get_default_vgc(struct
  		else
  			vgc = 0x2e + rt2x00dev->lna_gain;
  	} else { /* 5GHZ band */
@@ -20,7 +20,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  			vgc = 0x20 + (rt2x00dev->lna_gain * 5) / 3;
  		else if (rt2x00_rt(rt2x00dev, RT5592))
  			vgc = 0x24 + (2 * rt2x00dev->lna_gain);
-@@ -4819,7 +4820,8 @@ static inline void rt2800_set_vgc(struct
+@@ -5358,7 +5359,8 @@ static inline void rt2800_set_vgc(struct
  {
  	if (qual->vgc_level != vgc_level) {
  		if (rt2x00_rt(rt2x00dev, RT3572) ||
@@ -30,7 +30,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  			rt2800_bbp_write_with_rx_chain(rt2x00dev, 66,
  						       vgc_level);
  		} else if (rt2x00_rt(rt2x00dev, RT5592)) {
-@@ -4866,6 +4868,11 @@ void rt2800_link_tuner(struct rt2x00_dev
+@@ -5405,6 +5407,11 @@ void rt2800_link_tuner(struct rt2x00_dev
  		}
  		break;
  

+ 3 - 3
package/kernel/mac80211/patches/600-21-rt2x00-rt2800lib-fix-EEPROM-LNA-validation-for-RT388.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -7676,7 +7676,8 @@ static int rt2800_validate_eeprom(struct
+@@ -9074,7 +9074,8 @@ static int rt2800_validate_eeprom(struct
  	rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
  	if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
  		rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
@@ -20,7 +20,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  		if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
  		    rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
  			rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
-@@ -7696,7 +7697,8 @@ static int rt2800_validate_eeprom(struct
+@@ -9094,7 +9095,8 @@ static int rt2800_validate_eeprom(struct
  	rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
  	if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
  		rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
@@ -30,7 +30,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  		if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
  		    rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
  			rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
-@@ -7704,7 +7706,8 @@ static int rt2800_validate_eeprom(struct
+@@ -9102,7 +9104,8 @@ static int rt2800_validate_eeprom(struct
  	}
  	rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
  

+ 1 - 1
package/kernel/mac80211/patches/600-22-rt2x00-rt2800lib-fix-txpower-compensation-for-RT3883.patch

@@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
-@@ -3965,6 +3965,9 @@ static u8 rt2800_compensate_txpower(stru
+@@ -4332,6 +4332,9 @@ static u8 rt2800_compensate_txpower(stru
  	if (rt2x00_rt(rt2x00dev, RT3593))
  		return min_t(u8, txpower, 0xc);
  

+ 1 - 1
package/kernel/mac80211/patches/600-23-rt2x00-rt2800mmio-add-a-workaround-for-spurious-TX_F.patch

@@ -122,7 +122,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  		 */
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
-@@ -999,6 +999,11 @@ struct rt2x00_dev {
+@@ -1000,6 +1000,11 @@ struct rt2x00_dev {
  	int rf_channel;
  
  	/*

+ 8 - 8
package/kernel/mac80211/patches/602-rt2x00-introduce-rt2x00eeprom.patch

@@ -48,16 +48,16 @@
  obj-$(CPTCFG_RT2X00_LIB_MMIO)		+= rt2x00mmio.o
 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
-@@ -20,6 +20,8 @@
- #ifndef RT2800LIB_H
- #define RT2800LIB_H
+@@ -48,6 +48,8 @@ struct rt2800_drv_data {
+ 	struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
+ };
  
 +#include "rt2800.h"
 +
  struct rt2800_ops {
  	void (*register_read)(struct rt2x00_dev *rt2x00dev,
  			      const unsigned int offset, u32 *value);
-@@ -119,6 +121,15 @@ static inline int rt2800_read_eeprom(str
+@@ -147,6 +149,15 @@ static inline int rt2800_read_eeprom(str
  {
  	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  
@@ -105,7 +105,7 @@
  	.drv_init_registers	= rt2800mmio_init_registers,
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
-@@ -701,6 +701,7 @@ enum rt2x00_capability_flags {
+@@ -702,6 +702,7 @@ enum rt2x00_capability_flags {
  	REQUIRE_HT_TX_DESC,
  	REQUIRE_PS_AUTOWAKE,
  	REQUIRE_DELAYED_RFKILL,
@@ -113,7 +113,7 @@
  
  	/*
  	 * Capabilities
-@@ -976,6 +977,11 @@ struct rt2x00_dev {
+@@ -977,6 +978,11 @@ struct rt2x00_dev {
  	const struct firmware *fw;
  
  	/*
@@ -127,7 +127,7 @@
  	DECLARE_KFIFO_PTR(txstatus_fifo, u32);
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
-@@ -1346,6 +1346,10 @@ int rt2x00lib_probe_dev(struct rt2x00_de
+@@ -1418,6 +1418,10 @@ int rt2x00lib_probe_dev(struct rt2x00_de
  	INIT_DELAYED_WORK(&rt2x00dev->autowakeup_work, rt2x00lib_autowakeup);
  	INIT_WORK(&rt2x00dev->sleep_work, rt2x00lib_sleep);
  
@@ -138,7 +138,7 @@
  	/*
  	 * Let the driver probe the device to detect the capabilities.
  	 */
-@@ -1484,6 +1488,11 @@ void rt2x00lib_remove_dev(struct rt2x00_
+@@ -1556,6 +1560,11 @@ void rt2x00lib_remove_dev(struct rt2x00_
  	 * Free the driver data.
  	 */
  	kfree(rt2x00dev->drv_data);

+ 2 - 2
package/kernel/mac80211/patches/606-rt2x00-allow_disabling_bands_through_platform_data.patch

@@ -12,7 +12,7 @@
  #endif /* _RT2X00_PLATFORM_H */
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
-@@ -951,6 +951,22 @@ static int rt2x00lib_probe_hw_modes(stru
+@@ -1023,6 +1023,22 @@ static int rt2x00lib_probe_hw_modes(stru
  	unsigned int num_rates;
  	unsigned int i;
  
@@ -37,7 +37,7 @@
  		num_rates += 4;
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
-@@ -408,6 +408,7 @@ struct hw_mode_spec {
+@@ -409,6 +409,7 @@ struct hw_mode_spec {
  	unsigned int supported_bands;
  #define SUPPORT_BAND_2GHZ	0x00000001
  #define SUPPORT_BAND_5GHZ	0x00000002

+ 1 - 1
package/kernel/mac80211/patches/607-rt2x00-add_platform_data_mac_addr.patch

@@ -1,6 +1,6 @@
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
-@@ -929,8 +929,13 @@ static void rt2x00lib_rate(struct ieee80
+@@ -1001,8 +1001,13 @@ static void rt2x00lib_rate(struct ieee80
  
  void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr)
  {

+ 1 - 1
package/kernel/mac80211/patches/608-rt2x00-allow_disabling_bands_through_dts.patch

@@ -1,6 +1,6 @@
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
-@@ -955,6 +955,16 @@ static int rt2x00lib_probe_hw_modes(stru
+@@ -1027,6 +1027,16 @@ static int rt2x00lib_probe_hw_modes(stru
  	struct ieee80211_rate *rates;
  	unsigned int num_rates;
  	unsigned int i;

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно