From 76cf0a078ac1f59e8377ab313e94c1bf921893ea Mon Sep 17 00:00:00 2001
From: moonman <moonman.ca@gmail.com>
Date: Thu, 30 Apr 2015 18:49:05 +0000
Subject: [PATCH] core/linux-kirkwood-dt to 4.0.1-1

---
 core/linux-kirkwood-dt/PKGBUILD               | 45 ++++++++++---------
 .../linux-kirkwood-dt.install                 |  2 +-
 core/linux-kirkwood-dt/pci-e_fix.patch        | 43 ++++++++++++++++++
 3 files changed, 69 insertions(+), 21 deletions(-)
 create mode 100644 core/linux-kirkwood-dt/pci-e_fix.patch

diff --git a/core/linux-kirkwood-dt/PKGBUILD b/core/linux-kirkwood-dt/PKGBUILD
index 76e965744..707cd5d8e 100644
--- a/core/linux-kirkwood-dt/PKGBUILD
+++ b/core/linux-kirkwood-dt/PKGBUILD
@@ -6,18 +6,18 @@ buildarch=2
 pkgbase=linux-kirkwood-dt
 _kernelname=${pkgbase#linux}
 _desc="Marvell Kirkwood DT"
-pkgver=4.0
+pkgver=4.0.1
 pkgrel=1
 cryptodev_commit=5054d20d45571cc85339351fde52f872eeb82206
 bfqver=v7r7
 
 ### BFQ patch kernel version
-# bfqkern=${pkgver:0:4}
-bfqkern=3.19
+bfqkern=${pkgver:0:3}
+# bfqkern=3.19
 
 ### AUFS branch name
-# aufsbranch="aufs${pkgver:0:4}"
-aufsbranch="aufs3.x-rcN"
+aufsbranch="aufs${pkgver:0:3}"
+# aufsbranch="aufs4.x-rcN"
 
 arch=('arm')
 url="http://www.kernel.org/"
@@ -30,46 +30,51 @@ source=("https://kernel.org/pub/linux/kernel/v4.x/linux-${pkgver}.tar.xz"
         'archlinuxarm.patch'
         'usb-add-reset-resume-quirk-for-several-webcams.patch'
 	'0001-disable-mv643xx_eth-TSO.patch'
-        "git://git.code.sf.net/p/aufs/aufs3-standalone#branch=${aufsbranch}"
+        "git+https://github.com/sfjro/aufs4-standalone.git#branch=${aufsbranch}"
         "cryptodev-${cryptodev_commit}.tar.gz::https://github.com/cryptodev-linux/cryptodev-linux/archive/${cryptodev_commit}.tar.gz"
         "ftp://teambelgium.net/bfq/patches/${bfqkern}.0-${bfqver}/0001-block-cgroups-kconfig-build-bits-for-BFQ-${bfqver}-${bfqkern}.patch"
         "ftp://teambelgium.net/bfq/patches/${bfqkern}.0-${bfqver}/0002-block-introduce-the-BFQ-${bfqver}-I-O-sched-for-${bfqkern}.patch"
         "ftp://teambelgium.net/bfq/patches/${bfqkern}.0-${bfqver}/0003-block-bfq-add-Early-Queue-Merge-EQM-to-BFQ-${bfqver}-for-${bfqkern}.0.patch"
         'goflexhome_fdt.patch'
         'pogoplugv4_fdt.patch'
-        'nsa325_fdt.patch')
+        'nsa325_fdt.patch'
+        'pci-e_fix.patch')
 
-md5sums=('a86916bd12798220da9eb4a1eec3616d'
+md5sums=('ea7fc80310be8a5b43b2c6dfa5c4169f'
          'a9722a79fd7b242848d07e25ecb5638f'
          'ed6ea949989ccfd47e35349856a4fd27'
          '9b5a265440abf57d2052838f31486a3a'
          '09d44b9f07abfaeaf4f688ee52034786'
          'SKIP'
          '8f81b86fffb53ab49d1e48f86383deea'
-         'b548a53e1c07209770dd1acb51dc1ae5'
-         '55446f2cfb5466d868088b6a938adf03'
-         'dc11bd25031e98d003d8b027d79c812c'
+         '1131b4cb838e1e5d6b927a98bcb72ba5'
+         '3ede74f476399e72ddcd35c3b58dcf81'
+         'a5d87e551f6456a32b519c4896cdbcfd'
          'ce1975f40c48ec1b08dd09447ab043ca'
          '7efecf23dbebc1ee2e2ccb527c8579c0'
-         '864fe1862e6cee4f6e213c0caf0338fa')
+         '864fe1862e6cee4f6e213c0caf0338fa'
+         '38adb1741da21b699263019f4ed33430')
 
 prepare() {
   cd "${srcdir}/linux-${pkgver}"
 
-msg2 "Copying aufs3 patches into the kernel source tree"
-  cp -ru "${srcdir}/aufs3-standalone/"{Documentation,fs} "${srcdir}/linux-${pkgver}/"
-  cp -ru "${srcdir}/aufs3-standalone/include/uapi/linux/aufs_type.h" "${srcdir}/linux-${pkgver}/include/"{linux/,uapi/linux/}
+msg2 "Copying aufs patches into the kernel source tree"
+  cp -ru "${srcdir}/aufs4-standalone/"{Documentation,fs} "${srcdir}/linux-${pkgver}/"
+  cp -ru "${srcdir}/aufs4-standalone/include/uapi/linux/aufs_type.h" "${srcdir}/linux-${pkgver}/include/"{linux/,uapi/linux/}
 
-msg2 "Applying aufs3 patches"
-  patch -Np1 -i ../aufs3-standalone/aufs3-kbuild.patch
-  patch -Np1 -i ../aufs3-standalone/aufs3-base.patch
-  patch -Np1 -i ../aufs3-standalone/aufs3-mmap.patch
-  patch -Np1 -i ../aufs3-standalone/aufs3-standalone.patch
+msg2 "Applying aufs patches"
+  patch -Np1 -i ../aufs4-standalone/aufs4-kbuild.patch
+  patch -Np1 -i ../aufs4-standalone/aufs4-base.patch
+  patch -Np1 -i ../aufs4-standalone/aufs4-mmap.patch
+  patch -Np1 -i ../aufs4-standalone/aufs4-standalone.patch
 
 msg2 "Disable buggy TCP segmentation offload implementation"
 msg2 "http://archlinuxarm.org/forum/viewtopic.php?f=9&t=7692"
   patch -Np1 -i ${srcdir}/0001-disable-mv643xx_eth-TSO.patch
 
+msg2 "Fix PCI-E problems. Remove when this patch makes it to upstream"
+  patch -p1 -i ${srcdir}/pci-e_fix.patch
+
 msg2 "Add the USB_QUIRK_RESET_RESUME for several webcams"
   # FS#26528
   patch -Np1 -i "${srcdir}/usb-add-reset-resume-quirk-for-several-webcams.patch"
diff --git a/core/linux-kirkwood-dt/linux-kirkwood-dt.install b/core/linux-kirkwood-dt/linux-kirkwood-dt.install
index 3675494a6..4abff246c 100644
--- a/core/linux-kirkwood-dt/linux-kirkwood-dt.install
+++ b/core/linux-kirkwood-dt/linux-kirkwood-dt.install
@@ -2,7 +2,7 @@
 # arg 2:  the old package version
 
 KERNEL_NAME=-kirkwood-dt
-KERNEL_VERSION=3.18.6-2-ARCH
+KERNEL_VERSION=4.0.1-1-ARCH
 
 post_install () {
   # updating module dependencies
diff --git a/core/linux-kirkwood-dt/pci-e_fix.patch b/core/linux-kirkwood-dt/pci-e_fix.patch
new file mode 100644
index 000000000..73ead4800
--- /dev/null
+++ b/core/linux-kirkwood-dt/pci-e_fix.patch
@@ -0,0 +1,43 @@
+Commit a0b5cd4ac2d6 ("bus: mvebu-mbus: use automatic I/O
+synchronization barriers") enabled the usage of automatic I/O
+synchronization barriers by enabling bit WIN_CTRL_SYNCBARRIER in the
+control registers of MBus windows, but on non io-coherent platforms
+(orion5x, kirkwood and dove) the WIN_CTRL_SYNCBARRIER bit in
+the window control register is either reserved (all windows except 6
+and 7) or enables read-only protection (windows 6 and 7).
+
+Signed-off-by: Nicolas Schichan <nschichan@xxxxxxxxxx>
+Reviewed-by: Thomas Petazzoni <thomas.petazzoni@xxxxxxxxxxxxxxxxxx>
+Cc: <stable@xxxxxxxxxxxxxxx> # v4.0+
+Fixes: a0b5cd4ac2d6 ("bus: mvebu-mbus: use automatic I/O synchronization barriers")
+
+---
+ drivers/bus/mvebu-mbus.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c
+index fb9ec62..7fa4510 100644
+--- a/drivers/bus/mvebu-mbus.c
++++ b/drivers/bus/mvebu-mbus.c
+@@ -70,6 +70,7 @@
+  */
+ #define WIN_CTRL_OFF		0x0000
+ #define   WIN_CTRL_ENABLE       BIT(0)
++/* Only on HW I/O coherency capable platforms */
+ #define   WIN_CTRL_SYNCBARRIER  BIT(1)
+ #define   WIN_CTRL_TGT_MASK     0xf0
+ #define   WIN_CTRL_TGT_SHIFT    4
+@@ -323,8 +324,9 @@ static int mvebu_mbus_setup_window(struct mvebu_mbus_state *mbus,
+ 	ctrl = ((size - 1) & WIN_CTRL_SIZE_MASK) |
+ 		(attr << WIN_CTRL_ATTR_SHIFT)    |
+ 		(target << WIN_CTRL_TGT_SHIFT)   |
+-		WIN_CTRL_SYNCBARRIER             |
+ 		WIN_CTRL_ENABLE;
++	if (mbus->hw_io_coherency)
++		ctrl |= WIN_CTRL_SYNCBARRIER;
+ 
+ 	writel(base & WIN_BASE_LOW, addr + WIN_BASE_OFF);
+ 	writel(ctrl, addr + WIN_CTRL_OFF);
+-- 
+1.9.1
+